DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_09000_AAD_S_000015_PKG

Source


1 PACKAGE BODY XLA_09000_AAD_S_000015_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_09000_AAD_S_000015_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Price Protection Default Accrual                       |
14 |      Code    : PP_DEFAULT_ACCRUAL                                     |
15 |      Owner   : PRODUCT                                                |
16 |      Version :                                                        |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 30-03-2009 at 05:03:03 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_09000_AAD_S_000015_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_09000_AAD_S_000015_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_09000_AAD_S_000015_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_09000_AAD_S_000015_PKG.GetMeaning');
228 END GetMeaning;
229 --
230 
231 ---------------------------------------
232 --
233 -- PRIVATE FUNCTION
234 --         Description_1
235 --
236 ---------------------------------------
237 FUNCTION Description_1 (
238   p_application_id      IN NUMBER
239 , p_ae_header_id        IN NUMBER DEFAULT NULL 
240 --Transaction Number
241  , p_source_1            IN VARCHAR2
242 --Claim Number
243  , p_source_2            IN VARCHAR2
244 --Item Number
245  , p_source_3            IN VARCHAR2
246 )
247 RETURN VARCHAR2
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_ledger_language       VARCHAR2(30)   ;
255 l_source                VARCHAR2(1996) ;
256 l_description           VARCHAR2(2000) ;
257 l_log_module            VARCHAR2(240)  ;
258 BEGIN
259 IF g_log_enabled THEN
260       l_log_module := C_DEFAULT_MODULE||'.Description_1';
261 END IF;
262 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
263       trace
264          (p_msg      => 'BEGIN of Description_1'
265          ,p_level    => C_LEVEL_PROCEDURE
266          ,p_module   => l_log_module);
267 END IF;
268 
269 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
270 l_component_type        := 'AMB_DESCRIPTION';
271 l_component_code        := 'CLAIM_SETTLEMENT';
272 l_component_type_code   := 'S';
273 l_component_appl_id     :=  9000;
274 l_amb_context_code      := 'DEFAULT';
275 l_source                := NULL;
276 l_description           := NULL;
277 
278 
279  
280  IF 
281 l_ledger_language = 'US' THEN
282     l_description :=  SUBSTR(CONCAT(l_description,'Price Protection Txn Number-'),1,2000);
283     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
284  END IF;   
285   l_source := SUBSTR(p_source_1,1,1996);
286   IF l_source IS NOT NULL THEN
287     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
288     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
289   END IF;  
290  IF 
291 l_ledger_language = 'US' THEN
292     l_description :=  SUBSTR(CONCAT(l_description,'Claim Number-'),1,2000);
293     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
294  END IF;   
295   l_source := SUBSTR(p_source_2,1,1996);
296   IF l_source IS NOT NULL THEN
297     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
298     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
299   END IF;  
300  IF 
301 l_ledger_language = 'US' THEN
302     l_description :=  SUBSTR(CONCAT(l_description,'Item-'),1,2000);
303     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
304  END IF;   
305   l_source := SUBSTR(p_source_3,1,1996);
306   IF l_source IS NOT NULL THEN
307     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
308     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
309   END IF; 
310  l_description := SUBSTR(l_description,1,1996);
311   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
312         trace
313            (p_msg      => 'END of Description_1'
314            ,p_level    => C_LEVEL_PROCEDURE
315            ,p_module   => l_log_module);
316 
317   END IF;
318   RETURN l_description;
319 
320 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
321       trace
322          (p_msg      => 'END of Description_1'
323          ,p_level    => C_LEVEL_PROCEDURE
324          ,p_module   => l_log_module);
325 END IF;
326 RETURN NULL;
327 EXCEPTION
328   WHEN VALUE_ERROR THEN
329      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
330             trace
331                (p_msg      => 'ERROR: '||sqlerrm
332                ,p_level    => C_LEVEL_EXCEPTION
333                ,p_module   => l_log_module);
334      END IF;
335      RAISE;
336  WHEN xla_exceptions_pkg.application_exception THEN
337       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
338       trace
339          (p_msg      => 'ERROR: '||sqlerrm
340          ,p_level    => C_LEVEL_EXCEPTION
341          ,p_module   => l_log_module);
342       END IF;
343       RAISE;
344  WHEN OTHERS THEN
345        xla_exceptions_pkg.raise_message
346            (p_location => 'XLA_09000_AAD_S_000015_PKG.Description_1');
347 END Description_1;
348 
349 ---------------------------------------
350 --
351 -- PRIVATE FUNCTION
352 --         Description_2
353 --
354 ---------------------------------------
355 FUNCTION Description_2 (
356   p_application_id      IN NUMBER
357 , p_ae_header_id        IN NUMBER DEFAULT NULL 
358 --Transaction Number
359  , p_source_1            IN VARCHAR2
360 --Item Number
361  , p_source_3            IN VARCHAR2
362 )
366 l_component_code        VARCHAR2(30)   ;
363 RETURN VARCHAR2
364 IS
365 l_component_type        VARCHAR2(80)   ;
367 l_component_type_code   VARCHAR2(1)    ;
368 l_component_appl_id     INTEGER        ;
369 l_amb_context_code      VARCHAR2(30)   ;
370 l_ledger_language       VARCHAR2(30)   ;
371 l_source                VARCHAR2(1996) ;
372 l_description           VARCHAR2(2000) ;
373 l_log_module            VARCHAR2(240)  ;
374 BEGIN
375 IF g_log_enabled THEN
376       l_log_module := C_DEFAULT_MODULE||'.Description_2';
377 END IF;
378 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
379       trace
380          (p_msg      => 'BEGIN of Description_2'
381          ,p_level    => C_LEVEL_PROCEDURE
382          ,p_module   => l_log_module);
383 END IF;
384 
385 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
386 l_component_type        := 'AMB_DESCRIPTION';
387 l_component_code        := 'COST_UPDATE';
388 l_component_type_code   := 'S';
389 l_component_appl_id     :=  9000;
390 l_amb_context_code      := 'DEFAULT';
391 l_source                := NULL;
392 l_description           := NULL;
393 
394 
395  
396  IF 
397 l_ledger_language = 'US' THEN
398     l_description :=  SUBSTR(CONCAT(l_description,'Price Protection Txn Number-'),1,2000);
399     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
400  END IF;   
401   l_source := SUBSTR(p_source_1,1,1996);
402   IF l_source IS NOT NULL THEN
403     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
404     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
405   END IF;  
406  IF 
407 l_ledger_language = 'US' THEN
408     l_description :=  SUBSTR(CONCAT(l_description,'Item-'),1,2000);
409     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
410  END IF;   
411   l_source := SUBSTR(p_source_3,1,1996);
412   IF l_source IS NOT NULL THEN
413     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
414     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
415   END IF; 
416  l_description := SUBSTR(l_description,1,1996);
417   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
418         trace
419            (p_msg      => 'END of Description_2'
420            ,p_level    => C_LEVEL_PROCEDURE
421            ,p_module   => l_log_module);
422 
423   END IF;
424   RETURN l_description;
425 
426 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
427       trace
428          (p_msg      => 'END of Description_2'
429          ,p_level    => C_LEVEL_PROCEDURE
430          ,p_module   => l_log_module);
431 END IF;
432 RETURN NULL;
433 EXCEPTION
434   WHEN VALUE_ERROR THEN
435      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
436             trace
437                (p_msg      => 'ERROR: '||sqlerrm
438                ,p_level    => C_LEVEL_EXCEPTION
439                ,p_module   => l_log_module);
440      END IF;
441      RAISE;
442  WHEN xla_exceptions_pkg.application_exception THEN
443       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
444       trace
445          (p_msg      => 'ERROR: '||sqlerrm
446          ,p_level    => C_LEVEL_EXCEPTION
447          ,p_module   => l_log_module);
448       END IF;
449       RAISE;
450  WHEN OTHERS THEN
451        xla_exceptions_pkg.raise_message
452            (p_location => 'XLA_09000_AAD_S_000015_PKG.Description_2');
453 END Description_2;
454 
455 ---------------------------------------
456 --
457 -- PRIVATE FUNCTION
458 --         AcctDerRule_3
459 --
460 ---------------------------------------
461 FUNCTION AcctDerRule_3 (
462   p_application_id              IN NUMBER
463 , p_ae_header_id                IN NUMBER
464 , p_side                        IN VARCHAR2 
465 --Price Protection Standard Accrual Account
466  , p_source_4            IN NUMBER
467 , x_transaction_coa_id         OUT NOCOPY NUMBER
468 , x_accounting_coa_id          OUT NOCOPY NUMBER
469 , x_value_type_code            OUT NOCOPY VARCHAR2
470 )
471 RETURN NUMBER
472 IS
473 l_component_type       VARCHAR2(80)  ;
474 l_component_code       VARCHAR2(30)  ;
475 l_component_type_code  VARCHAR2(1)   ;
476 l_component_appl_id    INTEGER       ;
477 l_amb_context_code     VARCHAR2(30)  ;
478 l_log_module           VARCHAR2(240) ;
479 l_output_value         NUMBER        ;
480 BEGIN
481 IF g_log_enabled THEN
482       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_3';
483 END IF;
484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
485       trace
486          (p_msg      => 'BEGIN of AcctDerRule_3'
487          ,p_level    => C_LEVEL_PROCEDURE
488          ,p_module   => l_log_module);
489 END IF;
490 --
491 l_component_type         := 'AMB_ADR';
492 l_component_code         := 'STD_ACCRUAL';
493 l_component_type_code    := 'S';
494 l_component_appl_id      :=  9000;
495 l_amb_context_code       := 'DEFAULT';
496 x_transaction_coa_id     :=  null;
497 x_accounting_coa_id      :=  null;
498 --
499 
500  --
501   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
502       trace
503          (p_msg      => 'END of AcctDerRule_3'
504          ,p_level    => C_LEVEL_PROCEDURE
505          ,p_module   => l_log_module);
506   END IF;
507   x_value_type_code := 'S';
511 --
508   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_4));
509   RETURN l_output_value;
510 
512 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
513       trace
514          (p_msg      => 'END of AcctDerRule_3(invalid)'
515          ,p_level    => C_LEVEL_PROCEDURE
516          ,p_module   => l_log_module);
517 END IF;
518 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
519 x_value_type_code := null;
520 l_output_value    := null;
521 xla_accounting_err_pkg.build_message
522                  (p_appli_s_name            => 'XLA'
523                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
524                  ,p_token_1                 => 'COMPONENT_NAME'
525                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
526                                                             l_component_type
527                                                           , l_component_code
528                                                           , l_component_type_code
529                                                           , l_component_appl_id
530                                                           , l_amb_context_code
531                                                           )
532                  ,p_token_2                 => 'OWNER'
533                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
534                                                         'XLA_OWNER_TYPE'
535                                                         ,l_component_type_code
536                                                         )
537                  ,p_token_3                 => 'PAD_NAME'
538                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
539                  ,p_token_4                 => 'PAD_OWNER'
540                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
541                                                         'XLA_OWNER_TYPE'
542                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
543                                                         )
544                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
545                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
546                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
547                  ,p_ae_header_id            => NULL
548 );
549 RETURN l_output_value;
550 EXCEPTION
551   WHEN xla_exceptions_pkg.application_exception THEN
552       RAISE;
553   WHEN OTHERS THEN
554        xla_exceptions_pkg.raise_message
555            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctDerRule_3');
556 END AcctDerRule_3;
557 --
558 
559 ---------------------------------------
560 --
561 -- PRIVATE FUNCTION
562 --         AcctDerRule_4
563 --
564 ---------------------------------------
565 FUNCTION AcctDerRule_4 (
566   p_application_id              IN NUMBER
567 , p_ae_header_id                IN NUMBER
568 , p_side                        IN VARCHAR2 
569 --Price Protection Vendor AP Clearing Account
570  , p_source_5            IN NUMBER
571 , x_transaction_coa_id         OUT NOCOPY NUMBER
572 , x_accounting_coa_id          OUT NOCOPY NUMBER
573 , x_value_type_code            OUT NOCOPY VARCHAR2
574 )
575 RETURN NUMBER
576 IS
577 l_component_type       VARCHAR2(80)  ;
578 l_component_code       VARCHAR2(30)  ;
579 l_component_type_code  VARCHAR2(1)   ;
580 l_component_appl_id    INTEGER       ;
581 l_amb_context_code     VARCHAR2(30)  ;
582 l_log_module           VARCHAR2(240) ;
583 l_output_value         NUMBER        ;
584 BEGIN
585 IF g_log_enabled THEN
586       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_4';
587 END IF;
588 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
589       trace
590          (p_msg      => 'BEGIN of AcctDerRule_4'
591          ,p_level    => C_LEVEL_PROCEDURE
592          ,p_module   => l_log_module);
593 END IF;
594 --
595 l_component_type         := 'AMB_ADR';
596 l_component_code         := 'STD_AP_CLRNG';
597 l_component_type_code    := 'S';
598 l_component_appl_id      :=  9000;
599 l_amb_context_code       := 'DEFAULT';
600 x_transaction_coa_id     :=  null;
601 x_accounting_coa_id      :=  null;
602 --
603 
604  --
605   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
606       trace
607          (p_msg      => 'END of AcctDerRule_4'
608          ,p_level    => C_LEVEL_PROCEDURE
609          ,p_module   => l_log_module);
610   END IF;
611   x_value_type_code := 'S';
612   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_5));
613   RETURN l_output_value;
614 
615 --
616 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
617       trace
618          (p_msg      => 'END of AcctDerRule_4(invalid)'
619          ,p_level    => C_LEVEL_PROCEDURE
620          ,p_module   => l_log_module);
621 END IF;
622 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
623 x_value_type_code := null;
624 l_output_value    := null;
625 xla_accounting_err_pkg.build_message
626                  (p_appli_s_name            => 'XLA'
627                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
631                                                           , l_component_code
628                  ,p_token_1                 => 'COMPONENT_NAME'
629                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
630                                                             l_component_type
632                                                           , l_component_type_code
633                                                           , l_component_appl_id
634                                                           , l_amb_context_code
635                                                           )
636                  ,p_token_2                 => 'OWNER'
637                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
638                                                         'XLA_OWNER_TYPE'
639                                                         ,l_component_type_code
640                                                         )
641                  ,p_token_3                 => 'PAD_NAME'
642                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
643                  ,p_token_4                 => 'PAD_OWNER'
644                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
645                                                         'XLA_OWNER_TYPE'
646                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
647                                                         )
648                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
649                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
650                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
651                  ,p_ae_header_id            => NULL
652 );
653 RETURN l_output_value;
654 EXCEPTION
655   WHEN xla_exceptions_pkg.application_exception THEN
656       RAISE;
657   WHEN OTHERS THEN
658        xla_exceptions_pkg.raise_message
659            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctDerRule_4');
660 END AcctDerRule_4;
661 --
662 
663 ---------------------------------------
664 --
665 -- PRIVATE FUNCTION
666 --         AcctDerRule_5
667 --
668 ---------------------------------------
669 FUNCTION AcctDerRule_5 (
670   p_application_id              IN NUMBER
671 , p_ae_header_id                IN NUMBER
672 , p_side                        IN VARCHAR2 
673 --Price Protection Receivables Clearing Account
674  , p_source_6            IN NUMBER
675 , x_transaction_coa_id         OUT NOCOPY NUMBER
676 , x_accounting_coa_id          OUT NOCOPY NUMBER
677 , x_value_type_code            OUT NOCOPY VARCHAR2
678 )
679 RETURN NUMBER
680 IS
681 l_component_type       VARCHAR2(80)  ;
682 l_component_code       VARCHAR2(30)  ;
683 l_component_type_code  VARCHAR2(1)   ;
684 l_component_appl_id    INTEGER       ;
685 l_amb_context_code     VARCHAR2(30)  ;
686 l_log_module           VARCHAR2(240) ;
687 l_output_value         NUMBER        ;
688 BEGIN
689 IF g_log_enabled THEN
690       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_5';
691 END IF;
692 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
693       trace
694          (p_msg      => 'BEGIN of AcctDerRule_5'
695          ,p_level    => C_LEVEL_PROCEDURE
696          ,p_module   => l_log_module);
697 END IF;
698 --
699 l_component_type         := 'AMB_ADR';
700 l_component_code         := 'STD_AR_CLRNG';
701 l_component_type_code    := 'S';
702 l_component_appl_id      :=  9000;
703 l_amb_context_code       := 'DEFAULT';
704 x_transaction_coa_id     :=  null;
705 x_accounting_coa_id      :=  null;
706 --
707 
708  --
709   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
710       trace
711          (p_msg      => 'END of AcctDerRule_5'
712          ,p_level    => C_LEVEL_PROCEDURE
713          ,p_module   => l_log_module);
714   END IF;
715   x_value_type_code := 'S';
716   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_6));
717   RETURN l_output_value;
718 
719 --
720 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
721       trace
722          (p_msg      => 'END of AcctDerRule_5(invalid)'
723          ,p_level    => C_LEVEL_PROCEDURE
724          ,p_module   => l_log_module);
725 END IF;
726 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
727 x_value_type_code := null;
728 l_output_value    := null;
729 xla_accounting_err_pkg.build_message
730                  (p_appli_s_name            => 'XLA'
731                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
732                  ,p_token_1                 => 'COMPONENT_NAME'
733                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
734                                                             l_component_type
735                                                           , l_component_code
736                                                           , l_component_type_code
737                                                           , l_component_appl_id
738                                                           , l_amb_context_code
739                                                           )
740                  ,p_token_2                 => 'OWNER'
741                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
745                  ,p_token_3                 => 'PAD_NAME'
742                                                         'XLA_OWNER_TYPE'
743                                                         ,l_component_type_code
744                                                         )
746                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
747                  ,p_token_4                 => 'PAD_OWNER'
748                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
749                                                         'XLA_OWNER_TYPE'
750                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
751                                                         )
752                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
753                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
754                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
755                  ,p_ae_header_id            => NULL
756 );
757 RETURN l_output_value;
758 EXCEPTION
759   WHEN xla_exceptions_pkg.application_exception THEN
760       RAISE;
761   WHEN OTHERS THEN
762        xla_exceptions_pkg.raise_message
763            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctDerRule_5');
764 END AcctDerRule_5;
765 --
766 
767 ---------------------------------------
768 --
769 -- PRIVATE FUNCTION
770 --         AcctDerRule_6
771 --
772 ---------------------------------------
773 FUNCTION AcctDerRule_6 (
774   p_application_id              IN NUMBER
775 , p_ae_header_id                IN NUMBER
776 , p_side                        IN VARCHAR2 
777 --Price Protection Contra Liability Account
778  , p_source_7            IN NUMBER
779 , x_transaction_coa_id         OUT NOCOPY NUMBER
780 , x_accounting_coa_id          OUT NOCOPY NUMBER
781 , x_value_type_code            OUT NOCOPY VARCHAR2
782 )
783 RETURN NUMBER
784 IS
785 l_component_type       VARCHAR2(80)  ;
786 l_component_code       VARCHAR2(30)  ;
787 l_component_type_code  VARCHAR2(1)   ;
788 l_component_appl_id    INTEGER       ;
789 l_amb_context_code     VARCHAR2(30)  ;
790 l_log_module           VARCHAR2(240) ;
791 l_output_value         NUMBER        ;
792 BEGIN
793 IF g_log_enabled THEN
794       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_6';
795 END IF;
796 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
797       trace
798          (p_msg      => 'BEGIN of AcctDerRule_6'
799          ,p_level    => C_LEVEL_PROCEDURE
800          ,p_module   => l_log_module);
801 END IF;
802 --
803 l_component_type         := 'AMB_ADR';
804 l_component_code         := 'STD_CONTRA_LIAB';
805 l_component_type_code    := 'S';
806 l_component_appl_id      :=  9000;
807 l_amb_context_code       := 'DEFAULT';
808 x_transaction_coa_id     :=  null;
809 x_accounting_coa_id      :=  null;
810 --
811 
812  --
813   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
814       trace
815          (p_msg      => 'END of AcctDerRule_6'
816          ,p_level    => C_LEVEL_PROCEDURE
817          ,p_module   => l_log_module);
818   END IF;
819   x_value_type_code := 'S';
820   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_7));
821   RETURN l_output_value;
822 
823 --
824 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
825       trace
826          (p_msg      => 'END of AcctDerRule_6(invalid)'
827          ,p_level    => C_LEVEL_PROCEDURE
828          ,p_module   => l_log_module);
829 END IF;
830 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
831 x_value_type_code := null;
832 l_output_value    := null;
833 xla_accounting_err_pkg.build_message
834                  (p_appli_s_name            => 'XLA'
835                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
836                  ,p_token_1                 => 'COMPONENT_NAME'
837                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
838                                                             l_component_type
839                                                           , l_component_code
840                                                           , l_component_type_code
841                                                           , l_component_appl_id
842                                                           , l_amb_context_code
843                                                           )
844                  ,p_token_2                 => 'OWNER'
845                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
846                                                         'XLA_OWNER_TYPE'
847                                                         ,l_component_type_code
848                                                         )
849                  ,p_token_3                 => 'PAD_NAME'
850                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
851                  ,p_token_4                 => 'PAD_OWNER'
852                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
853                                                         'XLA_OWNER_TYPE'
854                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
858                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
855                                                         )
856                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
857                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
859                  ,p_ae_header_id            => NULL
860 );
861 RETURN l_output_value;
862 EXCEPTION
863   WHEN xla_exceptions_pkg.application_exception THEN
864       RAISE;
865   WHEN OTHERS THEN
866        xla_exceptions_pkg.raise_message
867            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctDerRule_6');
868 END AcctDerRule_6;
869 --
870 
871 ---------------------------------------
872 --
873 -- PRIVATE FUNCTION
874 --         AcctDerRule_7
875 --
876 ---------------------------------------
877 FUNCTION AcctDerRule_7 (
878   p_application_id              IN NUMBER
879 , p_ae_header_id                IN NUMBER
880 , p_side                        IN VARCHAR2 
881 --Price Protection Standard Cost Adjustment Account
882  , p_source_8            IN NUMBER
883 , x_transaction_coa_id         OUT NOCOPY NUMBER
884 , x_accounting_coa_id          OUT NOCOPY NUMBER
885 , x_value_type_code            OUT NOCOPY VARCHAR2
886 )
887 RETURN NUMBER
888 IS
889 l_component_type       VARCHAR2(80)  ;
890 l_component_code       VARCHAR2(30)  ;
891 l_component_type_code  VARCHAR2(1)   ;
892 l_component_appl_id    INTEGER       ;
893 l_amb_context_code     VARCHAR2(30)  ;
894 l_log_module           VARCHAR2(240) ;
895 l_output_value         NUMBER        ;
896 BEGIN
897 IF g_log_enabled THEN
898       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_7';
899 END IF;
900 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
901       trace
902          (p_msg      => 'BEGIN of AcctDerRule_7'
903          ,p_level    => C_LEVEL_PROCEDURE
904          ,p_module   => l_log_module);
905 END IF;
906 --
907 l_component_type         := 'AMB_ADR';
908 l_component_code         := 'STD_COST_ADJUSTMENT';
909 l_component_type_code    := 'S';
910 l_component_appl_id      :=  9000;
911 l_amb_context_code       := 'DEFAULT';
912 x_transaction_coa_id     :=  null;
913 x_accounting_coa_id      :=  null;
914 --
915 
916  --
917   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
918       trace
919          (p_msg      => 'END of AcctDerRule_7'
920          ,p_level    => C_LEVEL_PROCEDURE
921          ,p_module   => l_log_module);
922   END IF;
923   x_value_type_code := 'S';
924   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_8));
925   RETURN l_output_value;
926 
927 --
928 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
929       trace
930          (p_msg      => 'END of AcctDerRule_7(invalid)'
931          ,p_level    => C_LEVEL_PROCEDURE
932          ,p_module   => l_log_module);
933 END IF;
934 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
935 x_value_type_code := null;
936 l_output_value    := null;
937 xla_accounting_err_pkg.build_message
938                  (p_appli_s_name            => 'XLA'
939                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
940                  ,p_token_1                 => 'COMPONENT_NAME'
941                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
942                                                             l_component_type
943                                                           , l_component_code
944                                                           , l_component_type_code
945                                                           , l_component_appl_id
946                                                           , l_amb_context_code
947                                                           )
948                  ,p_token_2                 => 'OWNER'
949                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
950                                                         'XLA_OWNER_TYPE'
951                                                         ,l_component_type_code
952                                                         )
953                  ,p_token_3                 => 'PAD_NAME'
954                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
955                  ,p_token_4                 => 'PAD_OWNER'
956                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
957                                                         'XLA_OWNER_TYPE'
958                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
959                                                         )
960                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
961                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
962                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
963                  ,p_ae_header_id            => NULL
964 );
965 RETURN l_output_value;
966 EXCEPTION
967   WHEN xla_exceptions_pkg.application_exception THEN
968       RAISE;
969   WHEN OTHERS THEN
970        xla_exceptions_pkg.raise_message
971            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctDerRule_7');
972 END AcctDerRule_7;
973 --
974 
978 --         AcctLineType_8
975 ---------------------------------------
976 --
977 -- PRIVATE FUNCTION
979 --
980 ---------------------------------------
981 PROCEDURE AcctLineType_8 (
982   p_application_id        IN NUMBER
983  ,p_event_id              IN NUMBER
984  ,p_calculate_acctd_flag  IN VARCHAR2
985  ,p_calculate_g_l_flag    IN VARCHAR2
986  ,p_actual_flag           IN OUT VARCHAR2
987  ,p_balance_type_code     OUT VARCHAR2
988  ,p_gain_or_loss_ref      OUT VARCHAR2
989  
990 --Transaction Number
991  , p_source_1            IN VARCHAR2
992 --Item Number
993  , p_source_3            IN VARCHAR2
994 --Price Protection Standard Accrual Account
995  , p_source_4            IN NUMBER
996 --Distribution Identifier
997  , p_source_9            IN NUMBER
998 --Distribution Type
999  , p_source_10            IN VARCHAR2
1000 --Entered Amount
1001  , p_source_11            IN NUMBER
1002 --Transaction Currency Code
1003  , p_source_12            IN VARCHAR2
1004 --Accounted Amount
1005  , p_source_13            IN NUMBER
1006 )
1007 IS
1008 
1009 l_component_type              VARCHAR2(80);
1010 l_component_code              VARCHAR2(30);
1011 l_component_type_code         VARCHAR2(1);
1012 l_component_appl_id           INTEGER;
1013 l_amb_context_code            VARCHAR2(30);
1014 l_entity_code                 VARCHAR2(30);
1015 l_event_class_code            VARCHAR2(30);
1016 l_ae_header_id                NUMBER;
1017 l_event_type_code             VARCHAR2(30);
1018 l_line_definition_code        VARCHAR2(30);
1019 l_line_definition_owner_code  VARCHAR2(1);
1020 --
1021 -- adr variables
1022 l_segment                     VARCHAR2(30);
1023 l_ccid                        NUMBER;
1024 l_adr_transaction_coa_id      NUMBER;
1025 l_adr_accounting_coa_id       NUMBER;
1026 l_adr_flexfield_segment_code  VARCHAR2(30);
1027 l_adr_flex_value_set_id       NUMBER;
1028 l_adr_value_type_code         VARCHAR2(30);
1029 l_adr_value_combination_id    NUMBER;
1030 l_adr_value_segment_code      VARCHAR2(30);
1031 
1032 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1033 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1034 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1035 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1036 
1037 -- 4262811 Variables ------------------------------------------------------------------------------------------
1038 l_entered_amt_idx             NUMBER;
1039 l_accted_amt_idx              NUMBER;
1040 l_acc_rev_flag                VARCHAR2(1);
1041 l_accrual_line_num            NUMBER;
1042 l_tmp_amt                     NUMBER;
1043 l_acc_rev_natural_side_code   VARCHAR2(1);
1044 
1045 l_num_entries                 NUMBER;
1046 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1047 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1048 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1049 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1050 l_recog_line_1                NUMBER;
1051 l_recog_line_2                NUMBER;
1052 
1053 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1054 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1055 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1056 
1057 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1058 
1059 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1060 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1061 
1062 ---------------------------------------------------------------------------------------------------------------
1063 
1064 
1065 --
1066 -- bulk performance
1067 --
1068 l_balance_type_code           VARCHAR2(1);
1069 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1070 l_log_module                  VARCHAR2(240);
1071 
1072 --
1073 -- Upgrade strategy
1074 --
1075 l_actual_upg_option           VARCHAR2(1);
1076 l_enc_upg_option           VARCHAR2(1);
1077 
1078 --
1079 BEGIN
1080 --
1081 IF g_log_enabled THEN
1082       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_8';
1083 END IF;
1084 --
1085 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1086 
1087       trace
1088          (p_msg      => 'BEGIN of AcctLineType_8'
1089          ,p_level    => C_LEVEL_PROCEDURE
1090          ,p_module   => l_log_module);
1091 
1092 END IF;
1093 --
1094 l_component_type             := 'AMB_JLT';
1095 l_component_code             := 'COST_UPDT_ACCRUAL';
1096 l_component_type_code        := 'S';
1097 l_component_appl_id          :=  9000;
1098 l_amb_context_code           := 'DEFAULT';
1099 l_entity_code                := 'COST_UPDATE';
1100 l_event_class_code           := 'COST_UPDATE';
1101 l_event_type_code            := 'COST_UPDATE_ALL';
1102 l_line_definition_owner_code := 'S';
1103 l_line_definition_code       := 'COST_UPDATE';
1104 --
1105 l_balance_type_code          := 'A';
1106 l_segment                     := NULL;
1107 l_ccid                        := NULL;
1108 l_adr_transaction_coa_id      := NULL;
1109 l_adr_accounting_coa_id       := NULL;
1110 l_adr_flexfield_segment_code  := NULL;
1111 l_adr_flex_value_set_id       := NULL;
1115 
1112 l_adr_value_type_code         := NULL;
1113 l_adr_value_combination_id    := NULL;
1114 l_adr_value_segment_code      := NULL;
1116 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1117 l_bflow_class_code           := '';    -- 4219869 Business Flow
1118 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1119 l_budgetary_control_flag     := 'N';
1120 
1121 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1122 l_bflow_applied_to_amt       := NULL; -- 5132302
1123 l_entered_amt_idx            := NULL;          -- 4262811
1124 l_accted_amt_idx             := NULL;          -- 4262811
1125 l_acc_rev_flag               := NULL;          -- 4262811
1126 l_accrual_line_num           := NULL;          -- 4262811
1127 l_tmp_amt                    := NULL;          -- 4262811
1128 --
1129  
1130 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1131     l_balance_type_code <> 'B' THEN
1132 
1133    --
1134    XLA_AE_LINES_PKG.SetNewLine;
1135 
1136    p_balance_type_code          := l_balance_type_code;
1137    -- set the flag so later we will know whether the gain loss line needs to be created
1138    
1139    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1140      p_actual_flag :='A';
1141    END IF;
1142 
1143    --
1144    -- bulk performance
1145    --
1146    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1147                                       p_header_num   => 0); -- 4262811
1148    --
1149    -- set accounting line options
1150    --
1151    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1152            p_natural_side_code          => 'D'
1153          , p_gain_or_loss_flag          => 'N'
1154          , p_gl_transfer_mode_code      => 'S'
1155          , p_acct_entry_type_code       => 'A'
1156          , p_switch_side_flag           => 'Y'
1157          , p_merge_duplicate_code       => 'A'
1158          );
1159    --
1160    l_acc_rev_natural_side_code := 'C';  -- 4262811
1161    -- 
1162    --
1163    -- set accounting line type info
1164    --
1165    xla_ae_lines_pkg.SetAcctLineType
1166       (p_component_type             => l_component_type
1167       ,p_event_type_code            => l_event_type_code
1168       ,p_line_definition_owner_code => l_line_definition_owner_code
1169       ,p_line_definition_code       => l_line_definition_code
1170       ,p_accounting_line_code       => l_component_code
1171       ,p_accounting_line_type_code  => l_component_type_code
1172       ,p_accounting_line_appl_id    => l_component_appl_id
1173       ,p_amb_context_code           => l_amb_context_code
1174       ,p_entity_code                => l_entity_code
1175       ,p_event_class_code           => l_event_class_code);
1176    --
1177    -- set accounting class
1178    --
1179    xla_ae_lines_pkg.SetAcctClass(
1180            p_accounting_class_code  => 'CLAIM_SETTLE'
1181          , p_ae_header_id           => l_ae_header_id
1182          );
1183 
1184    --
1185    -- set rounding class
1186    --
1187    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1188                       'CLAIM_SETTLE';
1189 
1190    --
1191    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1192    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1193    --
1194    -- bulk performance
1195    --
1196    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1197 
1198    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1199       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1200 
1201    -- 4955764
1202    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1203       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1204 
1205    -- 4458381 Public Sector Enh
1206    
1207    --
1208    -- set accounting attributes for the line type
1209    --
1210    l_entered_amt_idx := 3;
1211    l_accted_amt_idx  := 5;
1212    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1213    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1214    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
1215    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1216    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
1217    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1218    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
1219    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1220    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
1221    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
1222    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
1223 
1224    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1225    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1226 
1227    ---------------------------------------------------------------------------------------------------------------
1228    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1232    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1229    ---------------------------------------------------------------------------------------------------------------
1230    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1231 
1233    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1234 
1235    IF xla_accounting_cache_pkg.GetValueChar
1236          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1237          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1238    AND l_bflow_method_code = 'PRIOR_ENTRY'
1239 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1240    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1241          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1242        )
1243    THEN
1244          xla_ae_lines_pkg.BflowUpgEntry
1245            (p_business_method_code    => l_bflow_method_code
1246            ,p_business_class_code     => l_bflow_class_code
1247            ,p_balance_type            => l_balance_type_code);
1248    ELSE
1249       NULL;
1250 -- No business flow processing for business flow method of NONE.
1251    END IF;
1252 
1253    --
1254    -- call analytical criteria
1255    --
1256    
1257    --
1258    -- call description
1259    --
1260    
1261 xla_ae_lines_pkg.SetLineDescription(
1262    p_ae_header_id => l_ae_header_id
1263   ,p_description  => Description_2 (
1264      p_application_id         => p_application_id
1265    , p_ae_header_id           => l_ae_header_id 
1266 , p_source_1 => p_source_1
1267 , p_source_3 => p_source_3
1268    )
1269 );
1270 
1271 
1272    --
1273    -- call ADRs
1274    -- Bug 4922099
1275    --
1276    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1277         (NVL(l_actual_upg_option, 'N') = 'O') OR
1278         (NVL(l_enc_upg_option, 'N') = 'O')
1279       )
1280    THEN
1281    NULL;
1282    --
1283    --
1284    
1285   l_ccid := AcctDerRule_3(
1286            p_application_id           => p_application_id
1287          , p_ae_header_id             => l_ae_header_id 
1288 , p_source_4 => p_source_4
1289          , x_transaction_coa_id       => l_adr_transaction_coa_id
1290          , x_accounting_coa_id        => l_adr_accounting_coa_id
1291          , x_value_type_code          => l_adr_value_type_code
1292          , p_side                     => 'NA'
1293    );
1294 
1295    xla_ae_lines_pkg.set_ccid(
1296     p_code_combination_id          => l_ccid
1297   , p_value_type_code              => l_adr_value_type_code
1298   , p_transaction_coa_id           => l_adr_transaction_coa_id
1299   , p_accounting_coa_id            => l_adr_accounting_coa_id
1300   , p_adr_code                     => 'STD_ACCRUAL'
1301   , p_adr_type_code                => 'S'
1302   , p_component_type               => l_component_type
1303   , p_component_code               => l_component_code
1304   , p_component_type_code          => l_component_type_code
1305   , p_component_appl_id            => l_component_appl_id
1306   , p_amb_context_code             => l_amb_context_code
1307   , p_side                         => 'NA'
1308   );
1309 
1310 
1311    --
1312    --
1313    END IF;
1314    --
1315    -- Bug 4922099
1316    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1317           (NVL(l_enc_upg_option, 'N') = 'O')
1318         ) AND
1319         (l_bflow_method_code = 'PRIOR_ENTRY')
1320       )
1321    THEN
1322       IF
1323       --
1324       1 = 2
1325       --
1326       THEN
1327       xla_accounting_err_pkg.build_message
1328                                     (p_appli_s_name            => 'XLA'
1329                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1330                                     ,p_token_1                 => 'LINE_NUMBER'
1331                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1332                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1333                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1334                                                                              l_component_type
1335                                                                             ,l_component_code
1336                                                                             ,l_component_type_code
1337                                                                             ,l_component_appl_id
1338                                                                             ,l_amb_context_code
1339                                                                             ,l_entity_code
1340                                                                             ,l_event_class_code
1341                                                                            )
1342                                     ,p_token_3                 => 'OWNER'
1343                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1344                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1348                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1345                                                                           ,p_lookup_code    => l_component_type_code
1346                                                                          )
1347                                     ,p_token_4                 => 'PRODUCT_NAME'
1349                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1350                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1351                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1352                                     ,p_ae_header_id            =>  NULL
1353                                        );
1354 
1355         IF (C_LEVEL_ERROR>= g_log_level) THEN
1356                  trace
1357                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1358                       ,p_level    => C_LEVEL_ERROR
1359                       ,p_module   => l_log_module);
1360         END IF;
1361       END IF;
1362    END IF;
1363    --
1364    --
1365    ------------------------------------------------------------------------------------------------
1366    -- 4219869 Business Flow
1367    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1368    -- Prior Entry.  Currently, the following code is always generated.
1369    ------------------------------------------------------------------------------------------------
1370    XLA_AE_LINES_PKG.ValidateCurrentLine;
1371 
1372    ------------------------------------------------------------------------------------
1373    -- 4219869 Business Flow
1374    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1375    ------------------------------------------------------------------------------------
1376    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1377 
1378    ----------------------------------------------------------------------------------
1379    -- 4219869 Business Flow
1380    -- Update journal entry status -- Need to generate this within IF <condition>
1381    ----------------------------------------------------------------------------------
1382    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1383          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1384          ,p_balance_type_code => l_balance_type_code
1385          );
1386 
1387    -------------------------------------------------------------------------------------------
1388    -- 4262811 - Generate the Accrual Reversal lines
1389    -------------------------------------------------------------------------------------------
1390    BEGIN
1391       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1392                               (g_array_event(p_event_id).array_value_num('header_index'));
1393       IF l_acc_rev_flag IS NULL THEN
1394          l_acc_rev_flag := 'N';
1395       END IF;
1396    EXCEPTION
1397       WHEN OTHERS THEN
1398          l_acc_rev_flag := 'N';
1399    END;
1400    --
1401    IF (l_acc_rev_flag = 'Y') THEN
1402 
1403        -- 4645092  ------------------------------------------------------------------------------
1404        -- To allow MPA report to determine if it should generate report process
1405        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1406        ------------------------------------------------------------------------------------------
1407 
1408        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1409        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1410    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
1411    -- call ADRs
1412    -- Bug 4922099
1413    --
1414    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1415         (NVL(l_actual_upg_option, 'N') = 'O') OR
1416         (NVL(l_enc_upg_option, 'N') = 'O')
1417       )
1418    THEN
1419    NULL;
1420    --
1421    --
1422    
1423   l_ccid := AcctDerRule_3(
1424            p_application_id           => p_application_id
1425          , p_ae_header_id             => l_ae_header_id 
1426 , p_source_4 => p_source_4
1427          , x_transaction_coa_id       => l_adr_transaction_coa_id
1428          , x_accounting_coa_id        => l_adr_accounting_coa_id
1429          , x_value_type_code          => l_adr_value_type_code
1430          , p_side                     => 'NA'
1431    );
1432 
1433    xla_ae_lines_pkg.set_ccid(
1434     p_code_combination_id          => l_ccid
1435   , p_value_type_code              => l_adr_value_type_code
1436   , p_transaction_coa_id           => l_adr_transaction_coa_id
1437   , p_accounting_coa_id            => l_adr_accounting_coa_id
1438   , p_adr_code                     => 'STD_ACCRUAL'
1439   , p_adr_type_code                => 'S'
1440   , p_component_type               => l_component_type
1441   , p_component_code               => l_component_code
1442   , p_component_type_code          => l_component_type_code
1443   , p_component_appl_id            => l_component_appl_id
1444   , p_amb_context_code             => l_amb_context_code
1445   , p_side                         => 'NA'
1446   );
1447 
1448 
1449    --
1450    --
1451    END IF;
1452 
1453        --
1454        -- Update the line information that should be overwritten
1455        --
1459 
1456        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1457                                          p_header_num   => 1);
1458        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1460        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1461 
1462        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1463           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1464        END IF;
1465 
1466       --
1467       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1468       --
1469       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1470           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1471       ELSE
1472           ---------------------------------------------------------------------------------------------------
1473           -- 4262811a Switch Sign
1474           ---------------------------------------------------------------------------------------------------
1475           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1476           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1477                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1478           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1479                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1480           -- 5132302
1481           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1482                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1483 
1484       END IF;
1485 
1486       -- 4955764
1487       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1488       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1489 
1490 
1491       XLA_AE_LINES_PKG.ValidateCurrentLine;
1492       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1493 
1494       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1495                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1496                ,p_balance_type_code => l_balance_type_code);
1497 
1498    END IF;
1499 
1500    -----------------------------------------------------------------------------------------
1501    -- 4262811 Multiperiod Accounting
1502    -----------------------------------------------------------------------------------------
1503      -- No MPA option is assigned.
1504 
1505 
1506 END IF;
1507 --
1508 
1509 --
1510 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1511    trace
1512       (p_msg      => 'END of AcctLineType_8'
1513       ,p_level    => C_LEVEL_PROCEDURE
1514       ,p_module   => l_log_module);
1515 END IF;
1516 --
1517 EXCEPTION
1518   WHEN xla_exceptions_pkg.application_exception THEN
1519       RAISE;
1520   WHEN OTHERS THEN
1521        xla_exceptions_pkg.raise_message
1522            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_8');
1523 END AcctLineType_8;
1524 --
1525 
1526 ---------------------------------------
1527 --
1528 -- PRIVATE FUNCTION
1529 --         AcctLineType_9
1530 --
1531 ---------------------------------------
1532 PROCEDURE AcctLineType_9 (
1533   p_application_id        IN NUMBER
1534  ,p_event_id              IN NUMBER
1535  ,p_calculate_acctd_flag  IN VARCHAR2
1536  ,p_calculate_g_l_flag    IN VARCHAR2
1537  ,p_actual_flag           IN OUT VARCHAR2
1538  ,p_balance_type_code     OUT VARCHAR2
1539  ,p_gain_or_loss_ref      OUT VARCHAR2
1540  
1541 --Price Protection Standard Cost Adjustment Account
1542  , p_source_8            IN NUMBER
1543 --Distribution Identifier
1544  , p_source_9            IN NUMBER
1545 --Distribution Type
1546  , p_source_10            IN VARCHAR2
1547 --Entered Amount
1548  , p_source_11            IN NUMBER
1549 --Transaction Currency Code
1550  , p_source_12            IN VARCHAR2
1551 --Accounted Amount
1552  , p_source_13            IN NUMBER
1553 )
1554 IS
1555 
1556 l_component_type              VARCHAR2(80);
1557 l_component_code              VARCHAR2(30);
1558 l_component_type_code         VARCHAR2(1);
1559 l_component_appl_id           INTEGER;
1560 l_amb_context_code            VARCHAR2(30);
1561 l_entity_code                 VARCHAR2(30);
1562 l_event_class_code            VARCHAR2(30);
1563 l_ae_header_id                NUMBER;
1564 l_event_type_code             VARCHAR2(30);
1565 l_line_definition_code        VARCHAR2(30);
1566 l_line_definition_owner_code  VARCHAR2(1);
1567 --
1568 -- adr variables
1569 l_segment                     VARCHAR2(30);
1570 l_ccid                        NUMBER;
1571 l_adr_transaction_coa_id      NUMBER;
1572 l_adr_accounting_coa_id       NUMBER;
1573 l_adr_flexfield_segment_code  VARCHAR2(30);
1574 l_adr_flex_value_set_id       NUMBER;
1575 l_adr_value_type_code         VARCHAR2(30);
1576 l_adr_value_combination_id    NUMBER;
1577 l_adr_value_segment_code      VARCHAR2(30);
1578 
1582 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1579 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1580 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1581 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1583 
1584 -- 4262811 Variables ------------------------------------------------------------------------------------------
1585 l_entered_amt_idx             NUMBER;
1586 l_accted_amt_idx              NUMBER;
1587 l_acc_rev_flag                VARCHAR2(1);
1588 l_accrual_line_num            NUMBER;
1589 l_tmp_amt                     NUMBER;
1590 l_acc_rev_natural_side_code   VARCHAR2(1);
1591 
1592 l_num_entries                 NUMBER;
1593 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1594 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1595 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1596 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1597 l_recog_line_1                NUMBER;
1598 l_recog_line_2                NUMBER;
1599 
1600 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1601 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1602 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1603 
1604 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1605 
1606 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1607 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1608 
1609 ---------------------------------------------------------------------------------------------------------------
1610 
1611 
1612 --
1613 -- bulk performance
1614 --
1615 l_balance_type_code           VARCHAR2(1);
1616 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1617 l_log_module                  VARCHAR2(240);
1618 
1619 --
1620 -- Upgrade strategy
1621 --
1622 l_actual_upg_option           VARCHAR2(1);
1623 l_enc_upg_option           VARCHAR2(1);
1624 
1625 --
1626 BEGIN
1627 --
1628 IF g_log_enabled THEN
1629       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_9';
1630 END IF;
1631 --
1632 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1633 
1634       trace
1635          (p_msg      => 'BEGIN of AcctLineType_9'
1636          ,p_level    => C_LEVEL_PROCEDURE
1637          ,p_module   => l_log_module);
1638 
1639 END IF;
1640 --
1641 l_component_type             := 'AMB_JLT';
1642 l_component_code             := 'COST_UPDT_ADJ';
1643 l_component_type_code        := 'S';
1644 l_component_appl_id          :=  9000;
1645 l_amb_context_code           := 'DEFAULT';
1646 l_entity_code                := 'COST_UPDATE';
1647 l_event_class_code           := 'COST_UPDATE';
1648 l_event_type_code            := 'COST_UPDATE_ALL';
1649 l_line_definition_owner_code := 'S';
1650 l_line_definition_code       := 'COST_UPDATE';
1651 --
1652 l_balance_type_code          := 'A';
1653 l_segment                     := NULL;
1654 l_ccid                        := NULL;
1655 l_adr_transaction_coa_id      := NULL;
1656 l_adr_accounting_coa_id       := NULL;
1657 l_adr_flexfield_segment_code  := NULL;
1658 l_adr_flex_value_set_id       := NULL;
1659 l_adr_value_type_code         := NULL;
1660 l_adr_value_combination_id    := NULL;
1661 l_adr_value_segment_code      := NULL;
1662 
1663 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1664 l_bflow_class_code           := '';    -- 4219869 Business Flow
1665 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1666 l_budgetary_control_flag     := 'N';
1667 
1668 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1669 l_bflow_applied_to_amt       := NULL; -- 5132302
1670 l_entered_amt_idx            := NULL;          -- 4262811
1671 l_accted_amt_idx             := NULL;          -- 4262811
1672 l_acc_rev_flag               := NULL;          -- 4262811
1673 l_accrual_line_num           := NULL;          -- 4262811
1674 l_tmp_amt                    := NULL;          -- 4262811
1675 --
1676  
1677 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1678     l_balance_type_code <> 'B' THEN
1679 
1680    --
1681    XLA_AE_LINES_PKG.SetNewLine;
1682 
1683    p_balance_type_code          := l_balance_type_code;
1684    -- set the flag so later we will know whether the gain loss line needs to be created
1685    
1686    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1687      p_actual_flag :='A';
1688    END IF;
1689 
1690    --
1691    -- bulk performance
1692    --
1693    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1694                                       p_header_num   => 0); -- 4262811
1695    --
1696    -- set accounting line options
1697    --
1698    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1699            p_natural_side_code          => 'C'
1700          , p_gain_or_loss_flag          => 'N'
1701          , p_gl_transfer_mode_code      => 'S'
1702          , p_acct_entry_type_code       => 'A'
1703          , p_switch_side_flag           => 'Y'
1704          , p_merge_duplicate_code       => 'A'
1705          );
1706    --
1707    l_acc_rev_natural_side_code := 'D';  -- 4262811
1708    -- 
1712    xla_ae_lines_pkg.SetAcctLineType
1709    --
1710    -- set accounting line type info
1711    --
1713       (p_component_type             => l_component_type
1714       ,p_event_type_code            => l_event_type_code
1715       ,p_line_definition_owner_code => l_line_definition_owner_code
1716       ,p_line_definition_code       => l_line_definition_code
1717       ,p_accounting_line_code       => l_component_code
1718       ,p_accounting_line_type_code  => l_component_type_code
1719       ,p_accounting_line_appl_id    => l_component_appl_id
1720       ,p_amb_context_code           => l_amb_context_code
1721       ,p_entity_code                => l_entity_code
1722       ,p_event_class_code           => l_event_class_code);
1723    --
1724    -- set accounting class
1725    --
1726    xla_ae_lines_pkg.SetAcctClass(
1727            p_accounting_class_code  => 'COST_UPDATE_ADJUSTMENT'
1728          , p_ae_header_id           => l_ae_header_id
1729          );
1730 
1731    --
1732    -- set rounding class
1733    --
1734    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1735                       'COST_UPDATE_ADJUSTMENT';
1736 
1737    --
1738    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1739    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1740    --
1741    -- bulk performance
1742    --
1743    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1744 
1745    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1746       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1747 
1748    -- 4955764
1749    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1750       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1751 
1752    -- 4458381 Public Sector Enh
1753    
1754    --
1755    -- set accounting attributes for the line type
1756    --
1757    l_entered_amt_idx := 3;
1758    l_accted_amt_idx  := 5;
1759    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1760    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1761    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
1762    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1763    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
1764    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1765    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
1766    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1767    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
1768    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
1769    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
1770 
1771    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1772    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1773 
1774    ---------------------------------------------------------------------------------------------------------------
1775    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1776    ---------------------------------------------------------------------------------------------------------------
1777    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1778 
1779    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1780    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1781 
1782    IF xla_accounting_cache_pkg.GetValueChar
1783          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1784          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1785    AND l_bflow_method_code = 'PRIOR_ENTRY'
1786 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1787    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1788          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1789        )
1790    THEN
1791          xla_ae_lines_pkg.BflowUpgEntry
1792            (p_business_method_code    => l_bflow_method_code
1793            ,p_business_class_code     => l_bflow_class_code
1794            ,p_balance_type            => l_balance_type_code);
1795    ELSE
1796       NULL;
1797 -- No business flow processing for business flow method of NONE.
1798    END IF;
1799 
1800    --
1801    -- call analytical criteria
1802    --
1803    
1804    --
1805    -- call description
1806    --
1807    -- No description or it is inherited.
1808    --
1809    -- call ADRs
1810    -- Bug 4922099
1811    --
1812    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1813         (NVL(l_actual_upg_option, 'N') = 'O') OR
1814         (NVL(l_enc_upg_option, 'N') = 'O')
1815       )
1816    THEN
1817    NULL;
1818    --
1819    --
1820    
1821   l_ccid := AcctDerRule_7(
1822            p_application_id           => p_application_id
1823          , p_ae_header_id             => l_ae_header_id 
1824 , p_source_8 => p_source_8
1825          , x_transaction_coa_id       => l_adr_transaction_coa_id
1826          , x_accounting_coa_id        => l_adr_accounting_coa_id
1830 
1827          , x_value_type_code          => l_adr_value_type_code
1828          , p_side                     => 'NA'
1829    );
1831    xla_ae_lines_pkg.set_ccid(
1832     p_code_combination_id          => l_ccid
1833   , p_value_type_code              => l_adr_value_type_code
1834   , p_transaction_coa_id           => l_adr_transaction_coa_id
1835   , p_accounting_coa_id            => l_adr_accounting_coa_id
1836   , p_adr_code                     => 'STD_COST_ADJUSTMENT'
1837   , p_adr_type_code                => 'S'
1838   , p_component_type               => l_component_type
1839   , p_component_code               => l_component_code
1840   , p_component_type_code          => l_component_type_code
1841   , p_component_appl_id            => l_component_appl_id
1842   , p_amb_context_code             => l_amb_context_code
1843   , p_side                         => 'NA'
1844   );
1845 
1846 
1847    --
1848    --
1849    END IF;
1850    --
1851    -- Bug 4922099
1852    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1853           (NVL(l_enc_upg_option, 'N') = 'O')
1854         ) AND
1855         (l_bflow_method_code = 'PRIOR_ENTRY')
1856       )
1857    THEN
1858       IF
1859       --
1860       1 = 2
1861       --
1862       THEN
1863       xla_accounting_err_pkg.build_message
1864                                     (p_appli_s_name            => 'XLA'
1865                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1866                                     ,p_token_1                 => 'LINE_NUMBER'
1867                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1868                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1869                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1870                                                                              l_component_type
1871                                                                             ,l_component_code
1872                                                                             ,l_component_type_code
1873                                                                             ,l_component_appl_id
1874                                                                             ,l_amb_context_code
1875                                                                             ,l_entity_code
1876                                                                             ,l_event_class_code
1877                                                                            )
1878                                     ,p_token_3                 => 'OWNER'
1879                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1880                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1881                                                                           ,p_lookup_code    => l_component_type_code
1882                                                                          )
1883                                     ,p_token_4                 => 'PRODUCT_NAME'
1884                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1885                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1886                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1887                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1888                                     ,p_ae_header_id            =>  NULL
1889                                        );
1890 
1891         IF (C_LEVEL_ERROR>= g_log_level) THEN
1892                  trace
1893                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1894                       ,p_level    => C_LEVEL_ERROR
1895                       ,p_module   => l_log_module);
1896         END IF;
1897       END IF;
1898    END IF;
1899    --
1900    --
1901    ------------------------------------------------------------------------------------------------
1902    -- 4219869 Business Flow
1903    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1904    -- Prior Entry.  Currently, the following code is always generated.
1905    ------------------------------------------------------------------------------------------------
1906    XLA_AE_LINES_PKG.ValidateCurrentLine;
1907 
1908    ------------------------------------------------------------------------------------
1909    -- 4219869 Business Flow
1910    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1911    ------------------------------------------------------------------------------------
1912    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1913 
1914    ----------------------------------------------------------------------------------
1915    -- 4219869 Business Flow
1916    -- Update journal entry status -- Need to generate this within IF <condition>
1917    ----------------------------------------------------------------------------------
1918    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1919          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1920          ,p_balance_type_code => l_balance_type_code
1921          );
1922 
1923    -------------------------------------------------------------------------------------------
1924    -- 4262811 - Generate the Accrual Reversal lines
1928                               (g_array_event(p_event_id).array_value_num('header_index'));
1925    -------------------------------------------------------------------------------------------
1926    BEGIN
1927       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1929       IF l_acc_rev_flag IS NULL THEN
1930          l_acc_rev_flag := 'N';
1931       END IF;
1932    EXCEPTION
1933       WHEN OTHERS THEN
1934          l_acc_rev_flag := 'N';
1935    END;
1936    --
1937    IF (l_acc_rev_flag = 'Y') THEN
1938 
1939        -- 4645092  ------------------------------------------------------------------------------
1940        -- To allow MPA report to determine if it should generate report process
1941        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1942        ------------------------------------------------------------------------------------------
1943 
1944        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1945        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1946    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
1947    -- call ADRs
1948    -- Bug 4922099
1949    --
1950    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1951         (NVL(l_actual_upg_option, 'N') = 'O') OR
1952         (NVL(l_enc_upg_option, 'N') = 'O')
1953       )
1954    THEN
1955    NULL;
1956    --
1957    --
1958    
1959   l_ccid := AcctDerRule_7(
1960            p_application_id           => p_application_id
1961          , p_ae_header_id             => l_ae_header_id 
1962 , p_source_8 => p_source_8
1963          , x_transaction_coa_id       => l_adr_transaction_coa_id
1964          , x_accounting_coa_id        => l_adr_accounting_coa_id
1965          , x_value_type_code          => l_adr_value_type_code
1966          , p_side                     => 'NA'
1967    );
1968 
1969    xla_ae_lines_pkg.set_ccid(
1970     p_code_combination_id          => l_ccid
1971   , p_value_type_code              => l_adr_value_type_code
1972   , p_transaction_coa_id           => l_adr_transaction_coa_id
1973   , p_accounting_coa_id            => l_adr_accounting_coa_id
1974   , p_adr_code                     => 'STD_COST_ADJUSTMENT'
1975   , p_adr_type_code                => 'S'
1976   , p_component_type               => l_component_type
1977   , p_component_code               => l_component_code
1978   , p_component_type_code          => l_component_type_code
1979   , p_component_appl_id            => l_component_appl_id
1980   , p_amb_context_code             => l_amb_context_code
1981   , p_side                         => 'NA'
1982   );
1983 
1984 
1985    --
1986    --
1987    END IF;
1988 
1989        --
1990        -- Update the line information that should be overwritten
1991        --
1992        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1993                                          p_header_num   => 1);
1994        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1995 
1996        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1997 
1998        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1999           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2000        END IF;
2001 
2002       --
2003       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2004       --
2005       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2006           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2007       ELSE
2008           ---------------------------------------------------------------------------------------------------
2009           -- 4262811a Switch Sign
2010           ---------------------------------------------------------------------------------------------------
2011           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2012           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2013                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2014           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2015                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2016           -- 5132302
2017           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2018                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2019 
2020       END IF;
2021 
2022       -- 4955764
2023       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2024       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2025 
2026 
2027       XLA_AE_LINES_PKG.ValidateCurrentLine;
2028       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2029 
2030       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2031                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2032                ,p_balance_type_code => l_balance_type_code);
2033 
2034    END IF;
2035 
2036    -----------------------------------------------------------------------------------------
2037    -- 4262811 Multiperiod Accounting
2041 
2038    -----------------------------------------------------------------------------------------
2039      -- No MPA option is assigned.
2040 
2042 END IF;
2043 --
2044 
2045 --
2046 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2047    trace
2048       (p_msg      => 'END of AcctLineType_9'
2049       ,p_level    => C_LEVEL_PROCEDURE
2050       ,p_module   => l_log_module);
2051 END IF;
2052 --
2053 EXCEPTION
2054   WHEN xla_exceptions_pkg.application_exception THEN
2055       RAISE;
2056   WHEN OTHERS THEN
2057        xla_exceptions_pkg.raise_message
2058            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_9');
2059 END AcctLineType_9;
2060 --
2061 
2062 ---------------------------------------
2063 --
2064 -- PRIVATE FUNCTION
2065 --         AcctLineType_10
2066 --
2067 ---------------------------------------
2068 PROCEDURE AcctLineType_10 (
2069   p_application_id        IN NUMBER
2070  ,p_event_id              IN NUMBER
2071  ,p_calculate_acctd_flag  IN VARCHAR2
2072  ,p_calculate_g_l_flag    IN VARCHAR2
2073  ,p_actual_flag           IN OUT VARCHAR2
2074  ,p_balance_type_code     OUT VARCHAR2
2075  ,p_gain_or_loss_ref      OUT VARCHAR2
2076  
2077 --Transaction Number
2078  , p_source_1            IN VARCHAR2
2079 --Claim Number
2080  , p_source_2            IN VARCHAR2
2081 --Item Number
2082  , p_source_3            IN VARCHAR2
2083 --Price Protection Receivables Clearing Account
2084  , p_source_6            IN NUMBER
2085 --Distribution Identifier
2086  , p_source_9            IN NUMBER
2087 --Distribution Type
2088  , p_source_10            IN VARCHAR2
2089 --Entered Amount
2090  , p_source_11            IN NUMBER
2091 --Transaction Currency Code
2092  , p_source_12            IN VARCHAR2
2093 --Accounted Amount
2094  , p_source_13            IN NUMBER
2095 --Party Identifier
2096  , p_source_14            IN NUMBER
2097 --Party Site Identifier
2098  , p_source_15            IN NUMBER
2099 --Party Type
2100  , p_source_16            IN VARCHAR2
2101 )
2102 IS
2103 
2104 l_component_type              VARCHAR2(80);
2105 l_component_code              VARCHAR2(30);
2106 l_component_type_code         VARCHAR2(1);
2107 l_component_appl_id           INTEGER;
2108 l_amb_context_code            VARCHAR2(30);
2109 l_entity_code                 VARCHAR2(30);
2110 l_event_class_code            VARCHAR2(30);
2111 l_ae_header_id                NUMBER;
2112 l_event_type_code             VARCHAR2(30);
2113 l_line_definition_code        VARCHAR2(30);
2114 l_line_definition_owner_code  VARCHAR2(1);
2115 --
2116 -- adr variables
2117 l_segment                     VARCHAR2(30);
2118 l_ccid                        NUMBER;
2119 l_adr_transaction_coa_id      NUMBER;
2120 l_adr_accounting_coa_id       NUMBER;
2121 l_adr_flexfield_segment_code  VARCHAR2(30);
2122 l_adr_flex_value_set_id       NUMBER;
2123 l_adr_value_type_code         VARCHAR2(30);
2124 l_adr_value_combination_id    NUMBER;
2125 l_adr_value_segment_code      VARCHAR2(30);
2126 
2127 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2128 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2129 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2130 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2131 
2132 -- 4262811 Variables ------------------------------------------------------------------------------------------
2133 l_entered_amt_idx             NUMBER;
2134 l_accted_amt_idx              NUMBER;
2135 l_acc_rev_flag                VARCHAR2(1);
2136 l_accrual_line_num            NUMBER;
2137 l_tmp_amt                     NUMBER;
2138 l_acc_rev_natural_side_code   VARCHAR2(1);
2139 
2140 l_num_entries                 NUMBER;
2141 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2142 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2143 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2144 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2145 l_recog_line_1                NUMBER;
2146 l_recog_line_2                NUMBER;
2147 
2148 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2149 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2150 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2151 
2152 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2153 
2154 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2155 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2156 
2157 ---------------------------------------------------------------------------------------------------------------
2158 
2159 
2160 --
2161 -- bulk performance
2162 --
2163 l_balance_type_code           VARCHAR2(1);
2164 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2165 l_log_module                  VARCHAR2(240);
2166 
2167 --
2168 -- Upgrade strategy
2169 --
2170 l_actual_upg_option           VARCHAR2(1);
2171 l_enc_upg_option           VARCHAR2(1);
2172 
2173 --
2174 BEGIN
2175 --
2176 IF g_log_enabled THEN
2180 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2177       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_10';
2178 END IF;
2179 --
2181 
2182       trace
2183          (p_msg      => 'BEGIN of AcctLineType_10'
2184          ,p_level    => C_LEVEL_PROCEDURE
2185          ,p_module   => l_log_module);
2186 
2187 END IF;
2188 --
2189 l_component_type             := 'AMB_JLT';
2190 l_component_code             := 'CUST_CLAIM_AR_CLEARING';
2191 l_component_type_code        := 'S';
2192 l_component_appl_id          :=  9000;
2193 l_amb_context_code           := 'DEFAULT';
2194 l_entity_code                := 'CLAIM_SETTLEMENT';
2195 l_event_class_code           := 'CLAIM_SETTLEMENT';
2196 l_event_type_code            := 'CUST_CLAIM';
2197 l_line_definition_owner_code := 'S';
2198 l_line_definition_code       := 'CUST_CLAIM';
2199 --
2200 l_balance_type_code          := 'A';
2201 l_segment                     := NULL;
2202 l_ccid                        := NULL;
2203 l_adr_transaction_coa_id      := NULL;
2204 l_adr_accounting_coa_id       := NULL;
2205 l_adr_flexfield_segment_code  := NULL;
2206 l_adr_flex_value_set_id       := NULL;
2207 l_adr_value_type_code         := NULL;
2208 l_adr_value_combination_id    := NULL;
2209 l_adr_value_segment_code      := NULL;
2210 
2211 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2212 l_bflow_class_code           := '';    -- 4219869 Business Flow
2213 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2214 l_budgetary_control_flag     := 'N';
2215 
2216 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2217 l_bflow_applied_to_amt       := NULL; -- 5132302
2218 l_entered_amt_idx            := NULL;          -- 4262811
2219 l_accted_amt_idx             := NULL;          -- 4262811
2220 l_acc_rev_flag               := NULL;          -- 4262811
2221 l_accrual_line_num           := NULL;          -- 4262811
2222 l_tmp_amt                    := NULL;          -- 4262811
2223 --
2224  
2225 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2226     l_balance_type_code <> 'B' THEN
2227 
2228    --
2229    XLA_AE_LINES_PKG.SetNewLine;
2230 
2231    p_balance_type_code          := l_balance_type_code;
2232    -- set the flag so later we will know whether the gain loss line needs to be created
2233    
2234    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2235      p_actual_flag :='A';
2236    END IF;
2237 
2238    --
2239    -- bulk performance
2240    --
2241    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2242                                       p_header_num   => 0); -- 4262811
2243    --
2244    -- set accounting line options
2245    --
2246    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2247            p_natural_side_code          => 'C'
2248          , p_gain_or_loss_flag          => 'N'
2249          , p_gl_transfer_mode_code      => 'S'
2250          , p_acct_entry_type_code       => 'A'
2251          , p_switch_side_flag           => 'N'
2252          , p_merge_duplicate_code       => 'W'
2253          );
2254    --
2255    l_acc_rev_natural_side_code := 'D';  -- 4262811
2256    -- 
2257    --
2258    -- set accounting line type info
2259    --
2260    xla_ae_lines_pkg.SetAcctLineType
2261       (p_component_type             => l_component_type
2262       ,p_event_type_code            => l_event_type_code
2263       ,p_line_definition_owner_code => l_line_definition_owner_code
2264       ,p_line_definition_code       => l_line_definition_code
2265       ,p_accounting_line_code       => l_component_code
2266       ,p_accounting_line_type_code  => l_component_type_code
2267       ,p_accounting_line_appl_id    => l_component_appl_id
2268       ,p_amb_context_code           => l_amb_context_code
2269       ,p_entity_code                => l_entity_code
2270       ,p_event_class_code           => l_event_class_code);
2271    --
2272    -- set accounting class
2273    --
2274    xla_ae_lines_pkg.SetAcctClass(
2275            p_accounting_class_code  => 'CLEARING'
2276          , p_ae_header_id           => l_ae_header_id
2277          );
2278 
2279    --
2280    -- set rounding class
2281    --
2282    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2283                       'CLEARING';
2284 
2285    --
2286    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2287    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2288    --
2289    -- bulk performance
2290    --
2291    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2292 
2293    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2294       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2295 
2296    -- 4955764
2297    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2298       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2299 
2300    -- 4458381 Public Sector Enh
2301    
2302    --
2303    -- set accounting attributes for the line type
2307    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2304    --
2305    l_entered_amt_idx := 3;
2306    l_accted_amt_idx  := 5;
2308    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2309    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
2310    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2311    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
2312    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2313    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
2314    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2315    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
2316    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
2317    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
2318    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
2319    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2320    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
2321    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
2322    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
2323    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
2324 
2325    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2326    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2327 
2328    ---------------------------------------------------------------------------------------------------------------
2329    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2330    ---------------------------------------------------------------------------------------------------------------
2331    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2332 
2333    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2334    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2335 
2336    IF xla_accounting_cache_pkg.GetValueChar
2337          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2338          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2339    AND l_bflow_method_code = 'PRIOR_ENTRY'
2340 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2341    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2342          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2343        )
2344    THEN
2345          xla_ae_lines_pkg.BflowUpgEntry
2346            (p_business_method_code    => l_bflow_method_code
2347            ,p_business_class_code     => l_bflow_class_code
2348            ,p_balance_type            => l_balance_type_code);
2349    ELSE
2350       NULL;
2351 -- No business flow processing for business flow method of NONE.
2352    END IF;
2353 
2354    --
2355    -- call analytical criteria
2356    --
2357    
2358    --
2359    -- call description
2360    --
2361    
2362 xla_ae_lines_pkg.SetLineDescription(
2363    p_ae_header_id => l_ae_header_id
2364   ,p_description  => Description_1 (
2365      p_application_id         => p_application_id
2366    , p_ae_header_id           => l_ae_header_id 
2367 , p_source_1 => p_source_1
2368 , p_source_2 => p_source_2
2369 , p_source_3 => p_source_3
2370    )
2371 );
2372 
2373 
2374    --
2375    -- call ADRs
2376    -- Bug 4922099
2377    --
2378    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2379         (NVL(l_actual_upg_option, 'N') = 'O') OR
2380         (NVL(l_enc_upg_option, 'N') = 'O')
2381       )
2382    THEN
2383    NULL;
2384    --
2385    --
2386    
2387   l_ccid := AcctDerRule_5(
2388            p_application_id           => p_application_id
2389          , p_ae_header_id             => l_ae_header_id 
2390 , p_source_6 => p_source_6
2391          , x_transaction_coa_id       => l_adr_transaction_coa_id
2392          , x_accounting_coa_id        => l_adr_accounting_coa_id
2393          , x_value_type_code          => l_adr_value_type_code
2394          , p_side                     => 'NA'
2395    );
2396 
2397    xla_ae_lines_pkg.set_ccid(
2398     p_code_combination_id          => l_ccid
2399   , p_value_type_code              => l_adr_value_type_code
2400   , p_transaction_coa_id           => l_adr_transaction_coa_id
2401   , p_accounting_coa_id            => l_adr_accounting_coa_id
2402   , p_adr_code                     => 'STD_AR_CLRNG'
2403   , p_adr_type_code                => 'S'
2404   , p_component_type               => l_component_type
2405   , p_component_code               => l_component_code
2406   , p_component_type_code          => l_component_type_code
2407   , p_component_appl_id            => l_component_appl_id
2408   , p_amb_context_code             => l_amb_context_code
2409   , p_side                         => 'NA'
2410   );
2411 
2412 
2413    --
2414    --
2415    END IF;
2416    --
2417    -- Bug 4922099
2418    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2419           (NVL(l_enc_upg_option, 'N') = 'O')
2420         ) AND
2421         (l_bflow_method_code = 'PRIOR_ENTRY')
2422       )
2423    THEN
2424       IF
2425       --
2426       1 = 2
2427       --
2428       THEN
2429       xla_accounting_err_pkg.build_message
2430                                     (p_appli_s_name            => 'XLA'
2434                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2431                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2432                                     ,p_token_1                 => 'LINE_NUMBER'
2433                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2435                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2436                                                                              l_component_type
2437                                                                             ,l_component_code
2438                                                                             ,l_component_type_code
2439                                                                             ,l_component_appl_id
2440                                                                             ,l_amb_context_code
2441                                                                             ,l_entity_code
2442                                                                             ,l_event_class_code
2443                                                                            )
2444                                     ,p_token_3                 => 'OWNER'
2445                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2446                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2447                                                                           ,p_lookup_code    => l_component_type_code
2448                                                                          )
2449                                     ,p_token_4                 => 'PRODUCT_NAME'
2450                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2451                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
2452                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
2453                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
2454                                     ,p_ae_header_id            =>  NULL
2455                                        );
2456 
2457         IF (C_LEVEL_ERROR>= g_log_level) THEN
2458                  trace
2459                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2460                       ,p_level    => C_LEVEL_ERROR
2461                       ,p_module   => l_log_module);
2462         END IF;
2463       END IF;
2464    END IF;
2465    --
2466    --
2467    ------------------------------------------------------------------------------------------------
2468    -- 4219869 Business Flow
2469    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
2470    -- Prior Entry.  Currently, the following code is always generated.
2471    ------------------------------------------------------------------------------------------------
2472    XLA_AE_LINES_PKG.ValidateCurrentLine;
2473 
2474    ------------------------------------------------------------------------------------
2475    -- 4219869 Business Flow
2476    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
2477    ------------------------------------------------------------------------------------
2478    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2479 
2480    ----------------------------------------------------------------------------------
2481    -- 4219869 Business Flow
2482    -- Update journal entry status -- Need to generate this within IF <condition>
2483    ----------------------------------------------------------------------------------
2484    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2485          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
2486          ,p_balance_type_code => l_balance_type_code
2487          );
2488 
2489    -------------------------------------------------------------------------------------------
2490    -- 4262811 - Generate the Accrual Reversal lines
2491    -------------------------------------------------------------------------------------------
2492    BEGIN
2493       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
2494                               (g_array_event(p_event_id).array_value_num('header_index'));
2495       IF l_acc_rev_flag IS NULL THEN
2496          l_acc_rev_flag := 'N';
2497       END IF;
2498    EXCEPTION
2499       WHEN OTHERS THEN
2500          l_acc_rev_flag := 'N';
2501    END;
2502    --
2503    IF (l_acc_rev_flag = 'Y') THEN
2504 
2505        -- 4645092  ------------------------------------------------------------------------------
2506        -- To allow MPA report to determine if it should generate report process
2507        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
2508        ------------------------------------------------------------------------------------------
2509 
2510        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
2511        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
2512    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
2513    -- call ADRs
2514    -- Bug 4922099
2515    --
2516    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2517         (NVL(l_actual_upg_option, 'N') = 'O') OR
2518         (NVL(l_enc_upg_option, 'N') = 'O')
2519       )
2520    THEN
2521    NULL;
2525   l_ccid := AcctDerRule_5(
2522    --
2523    --
2524    
2526            p_application_id           => p_application_id
2527          , p_ae_header_id             => l_ae_header_id 
2528 , p_source_6 => p_source_6
2529          , x_transaction_coa_id       => l_adr_transaction_coa_id
2530          , x_accounting_coa_id        => l_adr_accounting_coa_id
2531          , x_value_type_code          => l_adr_value_type_code
2532          , p_side                     => 'NA'
2533    );
2534 
2535    xla_ae_lines_pkg.set_ccid(
2536     p_code_combination_id          => l_ccid
2537   , p_value_type_code              => l_adr_value_type_code
2538   , p_transaction_coa_id           => l_adr_transaction_coa_id
2539   , p_accounting_coa_id            => l_adr_accounting_coa_id
2540   , p_adr_code                     => 'STD_AR_CLRNG'
2541   , p_adr_type_code                => 'S'
2542   , p_component_type               => l_component_type
2543   , p_component_code               => l_component_code
2544   , p_component_type_code          => l_component_type_code
2545   , p_component_appl_id            => l_component_appl_id
2546   , p_amb_context_code             => l_amb_context_code
2547   , p_side                         => 'NA'
2548   );
2549 
2550 
2551    --
2552    --
2553    END IF;
2554 
2555        --
2556        -- Update the line information that should be overwritten
2557        --
2558        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
2559                                          p_header_num   => 1);
2560        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
2561 
2562        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
2563 
2564        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
2565           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
2566        END IF;
2567 
2568       --
2569       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
2570       --
2571       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
2572           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
2573       ELSE
2574           ---------------------------------------------------------------------------------------------------
2575           -- 4262811a Switch Sign
2576           ---------------------------------------------------------------------------------------------------
2577           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
2578           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2579                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2580           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
2581                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2582           -- 5132302
2583           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
2584                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
2585 
2586       END IF;
2587 
2588       -- 4955764
2589       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2590       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
2591 
2592 
2593       XLA_AE_LINES_PKG.ValidateCurrentLine;
2594       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
2595 
2596       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
2597                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
2598                ,p_balance_type_code => l_balance_type_code);
2599 
2600    END IF;
2601 
2602    -----------------------------------------------------------------------------------------
2603    -- 4262811 Multiperiod Accounting
2604    -----------------------------------------------------------------------------------------
2605      -- No MPA option is assigned.
2606 
2607 
2608 END IF;
2609 --
2610 
2611 --
2612 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2613    trace
2614       (p_msg      => 'END of AcctLineType_10'
2615       ,p_level    => C_LEVEL_PROCEDURE
2616       ,p_module   => l_log_module);
2617 END IF;
2618 --
2619 EXCEPTION
2620   WHEN xla_exceptions_pkg.application_exception THEN
2621       RAISE;
2622   WHEN OTHERS THEN
2623        xla_exceptions_pkg.raise_message
2624            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_10');
2625 END AcctLineType_10;
2626 --
2627 
2628 ---------------------------------------
2629 --
2630 -- PRIVATE FUNCTION
2631 --         AcctLineType_11
2632 --
2633 ---------------------------------------
2634 PROCEDURE AcctLineType_11 (
2635   p_application_id        IN NUMBER
2636  ,p_event_id              IN NUMBER
2637  ,p_calculate_acctd_flag  IN VARCHAR2
2638  ,p_calculate_g_l_flag    IN VARCHAR2
2639  ,p_actual_flag           IN OUT VARCHAR2
2640  ,p_balance_type_code     OUT VARCHAR2
2641  ,p_gain_or_loss_ref      OUT VARCHAR2
2642  
2643 --Price Protection Contra Liability Account
2644  , p_source_7            IN NUMBER
2645 --Distribution Identifier
2649 --Entered Amount
2646  , p_source_9            IN NUMBER
2647 --Distribution Type
2648  , p_source_10            IN VARCHAR2
2650  , p_source_11            IN NUMBER
2651 --Transaction Currency Code
2652  , p_source_12            IN VARCHAR2
2653 --Accounted Amount
2654  , p_source_13            IN NUMBER
2655 --Party Identifier
2656  , p_source_14            IN NUMBER
2657 --Party Site Identifier
2658  , p_source_15            IN NUMBER
2659 --Party Type
2660  , p_source_16            IN VARCHAR2
2661 )
2662 IS
2663 
2664 l_component_type              VARCHAR2(80);
2665 l_component_code              VARCHAR2(30);
2666 l_component_type_code         VARCHAR2(1);
2667 l_component_appl_id           INTEGER;
2668 l_amb_context_code            VARCHAR2(30);
2669 l_entity_code                 VARCHAR2(30);
2670 l_event_class_code            VARCHAR2(30);
2671 l_ae_header_id                NUMBER;
2672 l_event_type_code             VARCHAR2(30);
2673 l_line_definition_code        VARCHAR2(30);
2674 l_line_definition_owner_code  VARCHAR2(1);
2675 --
2676 -- adr variables
2677 l_segment                     VARCHAR2(30);
2678 l_ccid                        NUMBER;
2679 l_adr_transaction_coa_id      NUMBER;
2680 l_adr_accounting_coa_id       NUMBER;
2681 l_adr_flexfield_segment_code  VARCHAR2(30);
2682 l_adr_flex_value_set_id       NUMBER;
2683 l_adr_value_type_code         VARCHAR2(30);
2684 l_adr_value_combination_id    NUMBER;
2685 l_adr_value_segment_code      VARCHAR2(30);
2686 
2687 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
2688 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
2689 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
2690 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
2691 
2692 -- 4262811 Variables ------------------------------------------------------------------------------------------
2693 l_entered_amt_idx             NUMBER;
2694 l_accted_amt_idx              NUMBER;
2695 l_acc_rev_flag                VARCHAR2(1);
2696 l_accrual_line_num            NUMBER;
2697 l_tmp_amt                     NUMBER;
2698 l_acc_rev_natural_side_code   VARCHAR2(1);
2699 
2700 l_num_entries                 NUMBER;
2701 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
2702 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
2703 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
2704 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
2705 l_recog_line_1                NUMBER;
2706 l_recog_line_2                NUMBER;
2707 
2708 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
2709 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
2710 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
2711 
2712 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
2713 
2714 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
2715 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
2716 
2717 ---------------------------------------------------------------------------------------------------------------
2718 
2719 
2720 --
2721 -- bulk performance
2722 --
2723 l_balance_type_code           VARCHAR2(1);
2724 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
2725 l_log_module                  VARCHAR2(240);
2726 
2727 --
2728 -- Upgrade strategy
2729 --
2730 l_actual_upg_option           VARCHAR2(1);
2731 l_enc_upg_option           VARCHAR2(1);
2732 
2733 --
2734 BEGIN
2735 --
2736 IF g_log_enabled THEN
2737       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_11';
2738 END IF;
2739 --
2740 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2741 
2742       trace
2743          (p_msg      => 'BEGIN of AcctLineType_11'
2744          ,p_level    => C_LEVEL_PROCEDURE
2745          ,p_module   => l_log_module);
2746 
2747 END IF;
2748 --
2749 l_component_type             := 'AMB_JLT';
2750 l_component_code             := 'CUST_CLAIM_CONTRA_LIAB';
2751 l_component_type_code        := 'S';
2752 l_component_appl_id          :=  9000;
2753 l_amb_context_code           := 'DEFAULT';
2754 l_entity_code                := 'CLAIM_SETTLEMENT';
2755 l_event_class_code           := 'CLAIM_SETTLEMENT';
2756 l_event_type_code            := 'CUST_CLAIM';
2757 l_line_definition_owner_code := 'S';
2758 l_line_definition_code       := 'CUST_CLAIM';
2759 --
2760 l_balance_type_code          := 'A';
2761 l_segment                     := NULL;
2762 l_ccid                        := NULL;
2763 l_adr_transaction_coa_id      := NULL;
2764 l_adr_accounting_coa_id       := NULL;
2765 l_adr_flexfield_segment_code  := NULL;
2766 l_adr_flex_value_set_id       := NULL;
2767 l_adr_value_type_code         := NULL;
2768 l_adr_value_combination_id    := NULL;
2769 l_adr_value_segment_code      := NULL;
2770 
2771 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
2772 l_bflow_class_code           := '';    -- 4219869 Business Flow
2773 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
2774 l_budgetary_control_flag     := 'N';
2775 
2776 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
2780 l_acc_rev_flag               := NULL;          -- 4262811
2777 l_bflow_applied_to_amt       := NULL; -- 5132302
2778 l_entered_amt_idx            := NULL;          -- 4262811
2779 l_accted_amt_idx             := NULL;          -- 4262811
2781 l_accrual_line_num           := NULL;          -- 4262811
2782 l_tmp_amt                    := NULL;          -- 4262811
2783 --
2784  
2785 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
2786     l_balance_type_code <> 'B' THEN
2787 
2788    --
2789    XLA_AE_LINES_PKG.SetNewLine;
2790 
2791    p_balance_type_code          := l_balance_type_code;
2792    -- set the flag so later we will know whether the gain loss line needs to be created
2793    
2794    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
2795      p_actual_flag :='A';
2796    END IF;
2797 
2798    --
2799    -- bulk performance
2800    --
2801    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
2802                                       p_header_num   => 0); -- 4262811
2803    --
2804    -- set accounting line options
2805    --
2806    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
2807            p_natural_side_code          => 'D'
2808          , p_gain_or_loss_flag          => 'N'
2809          , p_gl_transfer_mode_code      => 'S'
2810          , p_acct_entry_type_code       => 'A'
2811          , p_switch_side_flag           => 'N'
2812          , p_merge_duplicate_code       => 'W'
2813          );
2814    --
2815    l_acc_rev_natural_side_code := 'C';  -- 4262811
2816    -- 
2817    --
2818    -- set accounting line type info
2819    --
2820    xla_ae_lines_pkg.SetAcctLineType
2821       (p_component_type             => l_component_type
2822       ,p_event_type_code            => l_event_type_code
2823       ,p_line_definition_owner_code => l_line_definition_owner_code
2824       ,p_line_definition_code       => l_line_definition_code
2825       ,p_accounting_line_code       => l_component_code
2826       ,p_accounting_line_type_code  => l_component_type_code
2827       ,p_accounting_line_appl_id    => l_component_appl_id
2828       ,p_amb_context_code           => l_amb_context_code
2829       ,p_entity_code                => l_entity_code
2830       ,p_event_class_code           => l_event_class_code);
2831    --
2832    -- set accounting class
2833    --
2834    xla_ae_lines_pkg.SetAcctClass(
2835            p_accounting_class_code  => 'LIABILITY'
2836          , p_ae_header_id           => l_ae_header_id
2837          );
2838 
2839    --
2840    -- set rounding class
2841    --
2842    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
2843                       'LIABILITY';
2844 
2845    --
2846    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
2847    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
2848    --
2849    -- bulk performance
2850    --
2851    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
2852 
2853    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
2854       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
2855 
2856    -- 4955764
2857    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
2858       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
2859 
2860    -- 4458381 Public Sector Enh
2861    
2862    --
2863    -- set accounting attributes for the line type
2864    --
2865    l_entered_amt_idx := 3;
2866    l_accted_amt_idx  := 5;
2867    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
2868    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
2869    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
2870    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
2871    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
2872    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
2873    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
2874    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
2875    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
2876    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
2877    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
2878    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
2879    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
2880    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
2881    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
2882    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
2883    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
2884 
2885    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
2886    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
2887 
2888    ---------------------------------------------------------------------------------------------------------------
2889    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
2890    ---------------------------------------------------------------------------------------------------------------
2891    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
2892 
2896    IF xla_accounting_cache_pkg.GetValueChar
2893    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2894    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
2895 
2897          (p_source_code         => 'LEDGER_CATEGORY_CODE'
2898          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
2899    AND l_bflow_method_code = 'PRIOR_ENTRY'
2900 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
2901    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
2902          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
2903        )
2904    THEN
2905          xla_ae_lines_pkg.BflowUpgEntry
2906            (p_business_method_code    => l_bflow_method_code
2907            ,p_business_class_code     => l_bflow_class_code
2908            ,p_balance_type            => l_balance_type_code);
2909    ELSE
2910       NULL;
2911 -- No business flow processing for business flow method of NONE.
2912    END IF;
2913 
2914    --
2915    -- call analytical criteria
2916    --
2917    
2918    --
2919    -- call description
2920    --
2921    -- No description or it is inherited.
2922    --
2923    -- call ADRs
2924    -- Bug 4922099
2925    --
2926    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
2927         (NVL(l_actual_upg_option, 'N') = 'O') OR
2928         (NVL(l_enc_upg_option, 'N') = 'O')
2929       )
2930    THEN
2931    NULL;
2932    --
2933    --
2934    
2935   l_ccid := AcctDerRule_6(
2936            p_application_id           => p_application_id
2937          , p_ae_header_id             => l_ae_header_id 
2938 , p_source_7 => p_source_7
2939          , x_transaction_coa_id       => l_adr_transaction_coa_id
2940          , x_accounting_coa_id        => l_adr_accounting_coa_id
2941          , x_value_type_code          => l_adr_value_type_code
2942          , p_side                     => 'NA'
2943    );
2944 
2945    xla_ae_lines_pkg.set_ccid(
2946     p_code_combination_id          => l_ccid
2947   , p_value_type_code              => l_adr_value_type_code
2948   , p_transaction_coa_id           => l_adr_transaction_coa_id
2949   , p_accounting_coa_id            => l_adr_accounting_coa_id
2950   , p_adr_code                     => 'STD_CONTRA_LIAB'
2951   , p_adr_type_code                => 'S'
2952   , p_component_type               => l_component_type
2953   , p_component_code               => l_component_code
2954   , p_component_type_code          => l_component_type_code
2955   , p_component_appl_id            => l_component_appl_id
2956   , p_amb_context_code             => l_amb_context_code
2957   , p_side                         => 'NA'
2958   );
2959 
2960 
2961    --
2962    --
2963    END IF;
2964    --
2965    -- Bug 4922099
2966    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
2967           (NVL(l_enc_upg_option, 'N') = 'O')
2968         ) AND
2969         (l_bflow_method_code = 'PRIOR_ENTRY')
2970       )
2971    THEN
2972       IF
2973       --
2974       1 = 2
2975       --
2976       THEN
2977       xla_accounting_err_pkg.build_message
2978                                     (p_appli_s_name            => 'XLA'
2979                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
2980                                     ,p_token_1                 => 'LINE_NUMBER'
2981                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
2982                                     ,p_token_2                 => 'LINE_TYPE_NAME'
2983                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
2984                                                                              l_component_type
2985                                                                             ,l_component_code
2986                                                                             ,l_component_type_code
2987                                                                             ,l_component_appl_id
2988                                                                             ,l_amb_context_code
2989                                                                             ,l_entity_code
2990                                                                             ,l_event_class_code
2991                                                                            )
2992                                     ,p_token_3                 => 'OWNER'
2993                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
2994                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
2995                                                                           ,p_lookup_code    => l_component_type_code
2996                                                                          )
2997                                     ,p_token_4                 => 'PRODUCT_NAME'
2998                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
2999                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3000                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3001                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3005         IF (C_LEVEL_ERROR>= g_log_level) THEN
3002                                     ,p_ae_header_id            =>  NULL
3003                                        );
3004 
3006                  trace
3007                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3008                       ,p_level    => C_LEVEL_ERROR
3009                       ,p_module   => l_log_module);
3010         END IF;
3011       END IF;
3012    END IF;
3013    --
3014    --
3015    ------------------------------------------------------------------------------------------------
3016    -- 4219869 Business Flow
3017    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3018    -- Prior Entry.  Currently, the following code is always generated.
3019    ------------------------------------------------------------------------------------------------
3020    XLA_AE_LINES_PKG.ValidateCurrentLine;
3021 
3022    ------------------------------------------------------------------------------------
3023    -- 4219869 Business Flow
3024    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3025    ------------------------------------------------------------------------------------
3026    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3027 
3028    ----------------------------------------------------------------------------------
3029    -- 4219869 Business Flow
3030    -- Update journal entry status -- Need to generate this within IF <condition>
3031    ----------------------------------------------------------------------------------
3032    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3033          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3034          ,p_balance_type_code => l_balance_type_code
3035          );
3036 
3037    -------------------------------------------------------------------------------------------
3038    -- 4262811 - Generate the Accrual Reversal lines
3039    -------------------------------------------------------------------------------------------
3040    BEGIN
3041       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3042                               (g_array_event(p_event_id).array_value_num('header_index'));
3043       IF l_acc_rev_flag IS NULL THEN
3044          l_acc_rev_flag := 'N';
3045       END IF;
3046    EXCEPTION
3047       WHEN OTHERS THEN
3048          l_acc_rev_flag := 'N';
3049    END;
3050    --
3051    IF (l_acc_rev_flag = 'Y') THEN
3052 
3053        -- 4645092  ------------------------------------------------------------------------------
3054        -- To allow MPA report to determine if it should generate report process
3055        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3056        ------------------------------------------------------------------------------------------
3057 
3058        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3059        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3060    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
3061    -- call ADRs
3062    -- Bug 4922099
3063    --
3064    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3065         (NVL(l_actual_upg_option, 'N') = 'O') OR
3066         (NVL(l_enc_upg_option, 'N') = 'O')
3067       )
3068    THEN
3069    NULL;
3070    --
3071    --
3072    
3073   l_ccid := AcctDerRule_6(
3074            p_application_id           => p_application_id
3075          , p_ae_header_id             => l_ae_header_id 
3076 , p_source_7 => p_source_7
3077          , x_transaction_coa_id       => l_adr_transaction_coa_id
3078          , x_accounting_coa_id        => l_adr_accounting_coa_id
3079          , x_value_type_code          => l_adr_value_type_code
3080          , p_side                     => 'NA'
3081    );
3082 
3083    xla_ae_lines_pkg.set_ccid(
3084     p_code_combination_id          => l_ccid
3085   , p_value_type_code              => l_adr_value_type_code
3086   , p_transaction_coa_id           => l_adr_transaction_coa_id
3087   , p_accounting_coa_id            => l_adr_accounting_coa_id
3088   , p_adr_code                     => 'STD_CONTRA_LIAB'
3089   , p_adr_type_code                => 'S'
3090   , p_component_type               => l_component_type
3091   , p_component_code               => l_component_code
3092   , p_component_type_code          => l_component_type_code
3093   , p_component_appl_id            => l_component_appl_id
3094   , p_amb_context_code             => l_amb_context_code
3095   , p_side                         => 'NA'
3096   );
3097 
3098 
3099    --
3100    --
3101    END IF;
3102 
3103        --
3104        -- Update the line information that should be overwritten
3105        --
3106        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3107                                          p_header_num   => 1);
3108        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3109 
3110        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3111 
3112        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3113           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3114        END IF;
3115 
3116       --
3117       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3121       ELSE
3118       --
3119       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3120           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3122           ---------------------------------------------------------------------------------------------------
3123           -- 4262811a Switch Sign
3124           ---------------------------------------------------------------------------------------------------
3125           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3126           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3127                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3128           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3129                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3130           -- 5132302
3131           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3132                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3133 
3134       END IF;
3135 
3136       -- 4955764
3137       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3138       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3139 
3140 
3141       XLA_AE_LINES_PKG.ValidateCurrentLine;
3142       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3143 
3144       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3145                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3146                ,p_balance_type_code => l_balance_type_code);
3147 
3148    END IF;
3149 
3150    -----------------------------------------------------------------------------------------
3151    -- 4262811 Multiperiod Accounting
3152    -----------------------------------------------------------------------------------------
3153      -- No MPA option is assigned.
3154 
3155 
3156 END IF;
3157 --
3158 
3159 --
3160 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3161    trace
3162       (p_msg      => 'END of AcctLineType_11'
3163       ,p_level    => C_LEVEL_PROCEDURE
3164       ,p_module   => l_log_module);
3165 END IF;
3166 --
3167 EXCEPTION
3168   WHEN xla_exceptions_pkg.application_exception THEN
3169       RAISE;
3170   WHEN OTHERS THEN
3171        xla_exceptions_pkg.raise_message
3172            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_11');
3173 END AcctLineType_11;
3174 --
3175 
3176 ---------------------------------------
3177 --
3178 -- PRIVATE FUNCTION
3179 --         AcctLineType_12
3180 --
3181 ---------------------------------------
3182 PROCEDURE AcctLineType_12 (
3183   p_application_id        IN NUMBER
3184  ,p_event_id              IN NUMBER
3185  ,p_calculate_acctd_flag  IN VARCHAR2
3186  ,p_calculate_g_l_flag    IN VARCHAR2
3187  ,p_actual_flag           IN OUT VARCHAR2
3188  ,p_balance_type_code     OUT VARCHAR2
3189  ,p_gain_or_loss_ref      OUT VARCHAR2
3190  
3191 --Price Protection Vendor AP Clearing Account
3192  , p_source_5            IN NUMBER
3193 --Distribution Identifier
3194  , p_source_9            IN NUMBER
3195 --Distribution Type
3196  , p_source_10            IN VARCHAR2
3197 --Entered Amount
3198  , p_source_11            IN NUMBER
3199 --Transaction Currency Code
3200  , p_source_12            IN VARCHAR2
3201 --Accounted Amount
3202  , p_source_13            IN NUMBER
3203 --Party Identifier
3204  , p_source_14            IN NUMBER
3205 --Party Site Identifier
3206  , p_source_15            IN NUMBER
3207 --Party Type
3208  , p_source_16            IN VARCHAR2
3209 )
3210 IS
3211 
3212 l_component_type              VARCHAR2(80);
3213 l_component_code              VARCHAR2(30);
3214 l_component_type_code         VARCHAR2(1);
3215 l_component_appl_id           INTEGER;
3216 l_amb_context_code            VARCHAR2(30);
3217 l_entity_code                 VARCHAR2(30);
3218 l_event_class_code            VARCHAR2(30);
3219 l_ae_header_id                NUMBER;
3220 l_event_type_code             VARCHAR2(30);
3221 l_line_definition_code        VARCHAR2(30);
3222 l_line_definition_owner_code  VARCHAR2(1);
3223 --
3224 -- adr variables
3225 l_segment                     VARCHAR2(30);
3226 l_ccid                        NUMBER;
3227 l_adr_transaction_coa_id      NUMBER;
3228 l_adr_accounting_coa_id       NUMBER;
3229 l_adr_flexfield_segment_code  VARCHAR2(30);
3230 l_adr_flex_value_set_id       NUMBER;
3231 l_adr_value_type_code         VARCHAR2(30);
3232 l_adr_value_combination_id    NUMBER;
3233 l_adr_value_segment_code      VARCHAR2(30);
3234 
3235 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3236 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3237 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3238 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3239 
3243 l_acc_rev_flag                VARCHAR2(1);
3240 -- 4262811 Variables ------------------------------------------------------------------------------------------
3241 l_entered_amt_idx             NUMBER;
3242 l_accted_amt_idx              NUMBER;
3244 l_accrual_line_num            NUMBER;
3245 l_tmp_amt                     NUMBER;
3246 l_acc_rev_natural_side_code   VARCHAR2(1);
3247 
3248 l_num_entries                 NUMBER;
3249 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3250 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3251 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3252 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3253 l_recog_line_1                NUMBER;
3254 l_recog_line_2                NUMBER;
3255 
3256 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3257 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3258 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3259 
3260 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3261 
3262 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3263 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3264 
3265 ---------------------------------------------------------------------------------------------------------------
3266 
3267 
3268 --
3269 -- bulk performance
3270 --
3271 l_balance_type_code           VARCHAR2(1);
3272 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3273 l_log_module                  VARCHAR2(240);
3274 
3275 --
3276 -- Upgrade strategy
3277 --
3278 l_actual_upg_option           VARCHAR2(1);
3279 l_enc_upg_option           VARCHAR2(1);
3280 
3281 --
3282 BEGIN
3283 --
3284 IF g_log_enabled THEN
3285       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_12';
3286 END IF;
3287 --
3288 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3289 
3290       trace
3291          (p_msg      => 'BEGIN of AcctLineType_12'
3292          ,p_level    => C_LEVEL_PROCEDURE
3293          ,p_module   => l_log_module);
3294 
3295 END IF;
3296 --
3297 l_component_type             := 'AMB_JLT';
3298 l_component_code             := 'SUP_CUST_CLAIM_AP_CLEARING';
3299 l_component_type_code        := 'S';
3300 l_component_appl_id          :=  9000;
3301 l_amb_context_code           := 'DEFAULT';
3302 l_entity_code                := 'CLAIM_SETTLEMENT';
3303 l_event_class_code           := 'CLAIM_SETTLEMENT';
3304 l_event_type_code            := 'SUPPLIER_CUST_CLAIM';
3305 l_line_definition_owner_code := 'S';
3306 l_line_definition_code       := 'SUPPLIER_CUST_CLAIM';
3307 --
3308 l_balance_type_code          := 'A';
3309 l_segment                     := NULL;
3310 l_ccid                        := NULL;
3311 l_adr_transaction_coa_id      := NULL;
3312 l_adr_accounting_coa_id       := NULL;
3313 l_adr_flexfield_segment_code  := NULL;
3314 l_adr_flex_value_set_id       := NULL;
3315 l_adr_value_type_code         := NULL;
3316 l_adr_value_combination_id    := NULL;
3317 l_adr_value_segment_code      := NULL;
3318 
3319 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3320 l_bflow_class_code           := '';    -- 4219869 Business Flow
3321 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3322 l_budgetary_control_flag     := 'N';
3323 
3324 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3325 l_bflow_applied_to_amt       := NULL; -- 5132302
3326 l_entered_amt_idx            := NULL;          -- 4262811
3327 l_accted_amt_idx             := NULL;          -- 4262811
3328 l_acc_rev_flag               := NULL;          -- 4262811
3329 l_accrual_line_num           := NULL;          -- 4262811
3330 l_tmp_amt                    := NULL;          -- 4262811
3331 --
3332  
3333 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3334     l_balance_type_code <> 'B' THEN
3335 
3336    --
3337    XLA_AE_LINES_PKG.SetNewLine;
3338 
3339    p_balance_type_code          := l_balance_type_code;
3340    -- set the flag so later we will know whether the gain loss line needs to be created
3341    
3342    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3343      p_actual_flag :='A';
3344    END IF;
3345 
3346    --
3347    -- bulk performance
3348    --
3349    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3350                                       p_header_num   => 0); -- 4262811
3351    --
3352    -- set accounting line options
3353    --
3354    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3355            p_natural_side_code          => 'D'
3356          , p_gain_or_loss_flag          => 'N'
3357          , p_gl_transfer_mode_code      => 'S'
3358          , p_acct_entry_type_code       => 'A'
3359          , p_switch_side_flag           => 'N'
3360          , p_merge_duplicate_code       => 'W'
3361          );
3362    --
3363    l_acc_rev_natural_side_code := 'C';  -- 4262811
3364    -- 
3365    --
3366    -- set accounting line type info
3367    --
3368    xla_ae_lines_pkg.SetAcctLineType
3369       (p_component_type             => l_component_type
3370       ,p_event_type_code            => l_event_type_code
3374       ,p_accounting_line_type_code  => l_component_type_code
3371       ,p_line_definition_owner_code => l_line_definition_owner_code
3372       ,p_line_definition_code       => l_line_definition_code
3373       ,p_accounting_line_code       => l_component_code
3375       ,p_accounting_line_appl_id    => l_component_appl_id
3376       ,p_amb_context_code           => l_amb_context_code
3377       ,p_entity_code                => l_entity_code
3378       ,p_event_class_code           => l_event_class_code);
3379    --
3380    -- set accounting class
3381    --
3382    xla_ae_lines_pkg.SetAcctClass(
3383            p_accounting_class_code  => 'CLEARING'
3384          , p_ae_header_id           => l_ae_header_id
3385          );
3386 
3387    --
3388    -- set rounding class
3389    --
3390    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3391                       'CLEARING';
3392 
3393    --
3394    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3395    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3396    --
3397    -- bulk performance
3398    --
3399    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3400 
3401    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3402       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3403 
3404    -- 4955764
3405    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3406       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3407 
3408    -- 4458381 Public Sector Enh
3409    
3410    --
3411    -- set accounting attributes for the line type
3412    --
3413    l_entered_amt_idx := 3;
3414    l_accted_amt_idx  := 5;
3415    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3416    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3417    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
3418    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3419    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
3420    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3421    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
3422    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3423    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
3424    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
3425    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
3426    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
3427    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3428    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
3429    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
3430    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
3431    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
3432 
3433    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3434    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3435 
3436    ---------------------------------------------------------------------------------------------------------------
3437    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3438    ---------------------------------------------------------------------------------------------------------------
3439    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3440 
3441    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3442    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3443 
3444    IF xla_accounting_cache_pkg.GetValueChar
3445          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3446          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3447    AND l_bflow_method_code = 'PRIOR_ENTRY'
3448 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3449    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3450          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3451        )
3452    THEN
3453          xla_ae_lines_pkg.BflowUpgEntry
3454            (p_business_method_code    => l_bflow_method_code
3455            ,p_business_class_code     => l_bflow_class_code
3456            ,p_balance_type            => l_balance_type_code);
3457    ELSE
3458       NULL;
3459 -- No business flow processing for business flow method of NONE.
3460    END IF;
3461 
3462    --
3463    -- call analytical criteria
3464    --
3465    
3466    --
3467    -- call description
3468    --
3469    -- No description or it is inherited.
3470    --
3471    -- call ADRs
3472    -- Bug 4922099
3473    --
3474    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3475         (NVL(l_actual_upg_option, 'N') = 'O') OR
3476         (NVL(l_enc_upg_option, 'N') = 'O')
3477       )
3478    THEN
3479    NULL;
3480    --
3481    --
3482    
3483   l_ccid := AcctDerRule_4(
3484            p_application_id           => p_application_id
3485          , p_ae_header_id             => l_ae_header_id 
3486 , p_source_5 => p_source_5
3490          , p_side                     => 'NA'
3487          , x_transaction_coa_id       => l_adr_transaction_coa_id
3488          , x_accounting_coa_id        => l_adr_accounting_coa_id
3489          , x_value_type_code          => l_adr_value_type_code
3491    );
3492 
3493    xla_ae_lines_pkg.set_ccid(
3494     p_code_combination_id          => l_ccid
3495   , p_value_type_code              => l_adr_value_type_code
3496   , p_transaction_coa_id           => l_adr_transaction_coa_id
3497   , p_accounting_coa_id            => l_adr_accounting_coa_id
3498   , p_adr_code                     => 'STD_AP_CLRNG'
3499   , p_adr_type_code                => 'S'
3500   , p_component_type               => l_component_type
3501   , p_component_code               => l_component_code
3502   , p_component_type_code          => l_component_type_code
3503   , p_component_appl_id            => l_component_appl_id
3504   , p_amb_context_code             => l_amb_context_code
3505   , p_side                         => 'NA'
3506   );
3507 
3508 
3509    --
3510    --
3511    END IF;
3512    --
3513    -- Bug 4922099
3514    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
3515           (NVL(l_enc_upg_option, 'N') = 'O')
3516         ) AND
3517         (l_bflow_method_code = 'PRIOR_ENTRY')
3518       )
3519    THEN
3520       IF
3521       --
3522       1 = 2
3523       --
3524       THEN
3525       xla_accounting_err_pkg.build_message
3526                                     (p_appli_s_name            => 'XLA'
3527                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3528                                     ,p_token_1                 => 'LINE_NUMBER'
3529                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
3530                                     ,p_token_2                 => 'LINE_TYPE_NAME'
3531                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
3532                                                                              l_component_type
3533                                                                             ,l_component_code
3534                                                                             ,l_component_type_code
3535                                                                             ,l_component_appl_id
3536                                                                             ,l_amb_context_code
3537                                                                             ,l_entity_code
3538                                                                             ,l_event_class_code
3539                                                                            )
3540                                     ,p_token_3                 => 'OWNER'
3541                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
3542                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
3543                                                                           ,p_lookup_code    => l_component_type_code
3544                                                                          )
3545                                     ,p_token_4                 => 'PRODUCT_NAME'
3546                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
3547                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
3548                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
3549                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
3550                                     ,p_ae_header_id            =>  NULL
3551                                        );
3552 
3553         IF (C_LEVEL_ERROR>= g_log_level) THEN
3554                  trace
3555                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
3556                       ,p_level    => C_LEVEL_ERROR
3557                       ,p_module   => l_log_module);
3558         END IF;
3559       END IF;
3560    END IF;
3561    --
3562    --
3563    ------------------------------------------------------------------------------------------------
3564    -- 4219869 Business Flow
3565    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
3566    -- Prior Entry.  Currently, the following code is always generated.
3567    ------------------------------------------------------------------------------------------------
3568    XLA_AE_LINES_PKG.ValidateCurrentLine;
3569 
3570    ------------------------------------------------------------------------------------
3571    -- 4219869 Business Flow
3572    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
3573    ------------------------------------------------------------------------------------
3574    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3575 
3576    ----------------------------------------------------------------------------------
3577    -- 4219869 Business Flow
3578    -- Update journal entry status -- Need to generate this within IF <condition>
3579    ----------------------------------------------------------------------------------
3580    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3581          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
3582          ,p_balance_type_code => l_balance_type_code
3583          );
3584 
3585    -------------------------------------------------------------------------------------------
3589       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
3586    -- 4262811 - Generate the Accrual Reversal lines
3587    -------------------------------------------------------------------------------------------
3588    BEGIN
3590                               (g_array_event(p_event_id).array_value_num('header_index'));
3591       IF l_acc_rev_flag IS NULL THEN
3592          l_acc_rev_flag := 'N';
3593       END IF;
3594    EXCEPTION
3595       WHEN OTHERS THEN
3596          l_acc_rev_flag := 'N';
3597    END;
3598    --
3599    IF (l_acc_rev_flag = 'Y') THEN
3600 
3601        -- 4645092  ------------------------------------------------------------------------------
3602        -- To allow MPA report to determine if it should generate report process
3603        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
3604        ------------------------------------------------------------------------------------------
3605 
3606        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
3607        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
3608    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
3609    -- call ADRs
3610    -- Bug 4922099
3611    --
3612    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
3613         (NVL(l_actual_upg_option, 'N') = 'O') OR
3614         (NVL(l_enc_upg_option, 'N') = 'O')
3615       )
3616    THEN
3617    NULL;
3618    --
3619    --
3620    
3621   l_ccid := AcctDerRule_4(
3622            p_application_id           => p_application_id
3623          , p_ae_header_id             => l_ae_header_id 
3624 , p_source_5 => p_source_5
3625          , x_transaction_coa_id       => l_adr_transaction_coa_id
3626          , x_accounting_coa_id        => l_adr_accounting_coa_id
3627          , x_value_type_code          => l_adr_value_type_code
3628          , p_side                     => 'NA'
3629    );
3630 
3631    xla_ae_lines_pkg.set_ccid(
3632     p_code_combination_id          => l_ccid
3633   , p_value_type_code              => l_adr_value_type_code
3634   , p_transaction_coa_id           => l_adr_transaction_coa_id
3635   , p_accounting_coa_id            => l_adr_accounting_coa_id
3636   , p_adr_code                     => 'STD_AP_CLRNG'
3637   , p_adr_type_code                => 'S'
3638   , p_component_type               => l_component_type
3639   , p_component_code               => l_component_code
3640   , p_component_type_code          => l_component_type_code
3641   , p_component_appl_id            => l_component_appl_id
3642   , p_amb_context_code             => l_amb_context_code
3643   , p_side                         => 'NA'
3644   );
3645 
3646 
3647    --
3648    --
3649    END IF;
3650 
3651        --
3652        -- Update the line information that should be overwritten
3653        --
3654        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
3655                                          p_header_num   => 1);
3656        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
3657 
3658        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
3659 
3660        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
3661           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
3662        END IF;
3663 
3664       --
3665       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
3666       --
3667       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
3668           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
3669       ELSE
3670           ---------------------------------------------------------------------------------------------------
3671           -- 4262811a Switch Sign
3672           ---------------------------------------------------------------------------------------------------
3673           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
3674           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3675                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3676           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
3677                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3678           -- 5132302
3679           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
3680                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
3681 
3682       END IF;
3683 
3684       -- 4955764
3685       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3686       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
3687 
3688 
3689       XLA_AE_LINES_PKG.ValidateCurrentLine;
3690       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
3691 
3692       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
3693                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
3694                ,p_balance_type_code => l_balance_type_code);
3695 
3696    END IF;
3700    -----------------------------------------------------------------------------------------
3697 
3698    -----------------------------------------------------------------------------------------
3699    -- 4262811 Multiperiod Accounting
3701      -- No MPA option is assigned.
3702 
3703 
3704 END IF;
3705 --
3706 
3707 --
3708 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3709    trace
3710       (p_msg      => 'END of AcctLineType_12'
3711       ,p_level    => C_LEVEL_PROCEDURE
3712       ,p_module   => l_log_module);
3713 END IF;
3714 --
3715 EXCEPTION
3716   WHEN xla_exceptions_pkg.application_exception THEN
3717       RAISE;
3718   WHEN OTHERS THEN
3719        xla_exceptions_pkg.raise_message
3720            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_12');
3721 END AcctLineType_12;
3722 --
3723 
3724 ---------------------------------------
3725 --
3726 -- PRIVATE FUNCTION
3727 --         AcctLineType_13
3728 --
3729 ---------------------------------------
3730 PROCEDURE AcctLineType_13 (
3731   p_application_id        IN NUMBER
3732  ,p_event_id              IN NUMBER
3733  ,p_calculate_acctd_flag  IN VARCHAR2
3734  ,p_calculate_g_l_flag    IN VARCHAR2
3735  ,p_actual_flag           IN OUT VARCHAR2
3736  ,p_balance_type_code     OUT VARCHAR2
3737  ,p_gain_or_loss_ref      OUT VARCHAR2
3738  
3739 --Price Protection Contra Liability Account
3740  , p_source_7            IN NUMBER
3741 --Distribution Identifier
3742  , p_source_9            IN NUMBER
3743 --Distribution Type
3744  , p_source_10            IN VARCHAR2
3745 --Entered Amount
3746  , p_source_11            IN NUMBER
3747 --Transaction Currency Code
3748  , p_source_12            IN VARCHAR2
3749 --Accounted Amount
3750  , p_source_13            IN NUMBER
3751 --Party Identifier
3752  , p_source_14            IN NUMBER
3753 --Party Site Identifier
3754  , p_source_15            IN NUMBER
3755 --Party Type
3756  , p_source_16            IN VARCHAR2
3757 )
3758 IS
3759 
3760 l_component_type              VARCHAR2(80);
3761 l_component_code              VARCHAR2(30);
3762 l_component_type_code         VARCHAR2(1);
3763 l_component_appl_id           INTEGER;
3764 l_amb_context_code            VARCHAR2(30);
3765 l_entity_code                 VARCHAR2(30);
3766 l_event_class_code            VARCHAR2(30);
3767 l_ae_header_id                NUMBER;
3768 l_event_type_code             VARCHAR2(30);
3769 l_line_definition_code        VARCHAR2(30);
3770 l_line_definition_owner_code  VARCHAR2(1);
3771 --
3772 -- adr variables
3773 l_segment                     VARCHAR2(30);
3774 l_ccid                        NUMBER;
3775 l_adr_transaction_coa_id      NUMBER;
3776 l_adr_accounting_coa_id       NUMBER;
3777 l_adr_flexfield_segment_code  VARCHAR2(30);
3778 l_adr_flex_value_set_id       NUMBER;
3779 l_adr_value_type_code         VARCHAR2(30);
3780 l_adr_value_combination_id    NUMBER;
3781 l_adr_value_segment_code      VARCHAR2(30);
3782 
3783 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
3784 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
3785 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
3786 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
3787 
3788 -- 4262811 Variables ------------------------------------------------------------------------------------------
3789 l_entered_amt_idx             NUMBER;
3790 l_accted_amt_idx              NUMBER;
3791 l_acc_rev_flag                VARCHAR2(1);
3792 l_accrual_line_num            NUMBER;
3793 l_tmp_amt                     NUMBER;
3794 l_acc_rev_natural_side_code   VARCHAR2(1);
3795 
3796 l_num_entries                 NUMBER;
3797 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
3798 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
3799 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
3800 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
3801 l_recog_line_1                NUMBER;
3802 l_recog_line_2                NUMBER;
3803 
3804 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
3805 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
3806 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
3807 
3808 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
3809 
3810 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
3811 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
3812 
3813 ---------------------------------------------------------------------------------------------------------------
3814 
3815 
3816 --
3817 -- bulk performance
3818 --
3819 l_balance_type_code           VARCHAR2(1);
3820 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
3821 l_log_module                  VARCHAR2(240);
3822 
3823 --
3824 -- Upgrade strategy
3825 --
3826 l_actual_upg_option           VARCHAR2(1);
3827 l_enc_upg_option           VARCHAR2(1);
3828 
3829 --
3830 BEGIN
3831 --
3832 IF g_log_enabled THEN
3833       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_13';
3834 END IF;
3835 --
3836 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3837 
3838       trace
3842 
3839          (p_msg      => 'BEGIN of AcctLineType_13'
3840          ,p_level    => C_LEVEL_PROCEDURE
3841          ,p_module   => l_log_module);
3843 END IF;
3844 --
3845 l_component_type             := 'AMB_JLT';
3846 l_component_code             := 'SUP_CUST_CLAIM_CONTRA_LIAB';
3847 l_component_type_code        := 'S';
3848 l_component_appl_id          :=  9000;
3849 l_amb_context_code           := 'DEFAULT';
3850 l_entity_code                := 'CLAIM_SETTLEMENT';
3851 l_event_class_code           := 'CLAIM_SETTLEMENT';
3852 l_event_type_code            := 'SUPPLIER_CUST_CLAIM';
3853 l_line_definition_owner_code := 'S';
3854 l_line_definition_code       := 'SUPPLIER_CUST_CLAIM';
3855 --
3856 l_balance_type_code          := 'A';
3857 l_segment                     := NULL;
3858 l_ccid                        := NULL;
3859 l_adr_transaction_coa_id      := NULL;
3860 l_adr_accounting_coa_id       := NULL;
3861 l_adr_flexfield_segment_code  := NULL;
3862 l_adr_flex_value_set_id       := NULL;
3863 l_adr_value_type_code         := NULL;
3864 l_adr_value_combination_id    := NULL;
3865 l_adr_value_segment_code      := NULL;
3866 
3867 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
3868 l_bflow_class_code           := '';    -- 4219869 Business Flow
3869 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
3870 l_budgetary_control_flag     := 'N';
3871 
3872 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
3873 l_bflow_applied_to_amt       := NULL; -- 5132302
3874 l_entered_amt_idx            := NULL;          -- 4262811
3875 l_accted_amt_idx             := NULL;          -- 4262811
3876 l_acc_rev_flag               := NULL;          -- 4262811
3877 l_accrual_line_num           := NULL;          -- 4262811
3878 l_tmp_amt                    := NULL;          -- 4262811
3879 --
3880  
3881 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
3882     l_balance_type_code <> 'B' THEN
3883 
3884    --
3885    XLA_AE_LINES_PKG.SetNewLine;
3886 
3887    p_balance_type_code          := l_balance_type_code;
3888    -- set the flag so later we will know whether the gain loss line needs to be created
3889    
3890    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
3891      p_actual_flag :='A';
3892    END IF;
3893 
3894    --
3895    -- bulk performance
3896    --
3897    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
3898                                       p_header_num   => 0); -- 4262811
3899    --
3900    -- set accounting line options
3901    --
3902    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
3903            p_natural_side_code          => 'C'
3904          , p_gain_or_loss_flag          => 'N'
3905          , p_gl_transfer_mode_code      => 'S'
3906          , p_acct_entry_type_code       => 'A'
3907          , p_switch_side_flag           => 'N'
3908          , p_merge_duplicate_code       => 'W'
3909          );
3910    --
3911    l_acc_rev_natural_side_code := 'D';  -- 4262811
3912    -- 
3913    --
3914    -- set accounting line type info
3915    --
3916    xla_ae_lines_pkg.SetAcctLineType
3917       (p_component_type             => l_component_type
3918       ,p_event_type_code            => l_event_type_code
3919       ,p_line_definition_owner_code => l_line_definition_owner_code
3920       ,p_line_definition_code       => l_line_definition_code
3921       ,p_accounting_line_code       => l_component_code
3922       ,p_accounting_line_type_code  => l_component_type_code
3923       ,p_accounting_line_appl_id    => l_component_appl_id
3924       ,p_amb_context_code           => l_amb_context_code
3925       ,p_entity_code                => l_entity_code
3926       ,p_event_class_code           => l_event_class_code);
3927    --
3928    -- set accounting class
3929    --
3930    xla_ae_lines_pkg.SetAcctClass(
3931            p_accounting_class_code  => 'LIABILITY'
3932          , p_ae_header_id           => l_ae_header_id
3933          );
3934 
3935    --
3936    -- set rounding class
3937    --
3938    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
3939                       'LIABILITY';
3940 
3941    --
3942    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
3943    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
3944    --
3945    -- bulk performance
3946    --
3947    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
3948 
3949    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
3950       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
3951 
3952    -- 4955764
3953    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
3954       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
3955 
3956    -- 4458381 Public Sector Enh
3957    
3958    --
3959    -- set accounting attributes for the line type
3960    --
3961    l_entered_amt_idx := 3;
3962    l_accted_amt_idx  := 5;
3963    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
3964    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
3965    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
3969    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
3966    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
3967    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
3968    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
3970    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
3971    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
3972    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
3973    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
3974    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
3975    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
3976    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
3977    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
3978    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
3979    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
3980 
3981    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
3982    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
3983 
3984    ---------------------------------------------------------------------------------------------------------------
3985    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
3986    ---------------------------------------------------------------------------------------------------------------
3987    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
3988 
3989    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3990    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
3991 
3992    IF xla_accounting_cache_pkg.GetValueChar
3993          (p_source_code         => 'LEDGER_CATEGORY_CODE'
3994          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
3995    AND l_bflow_method_code = 'PRIOR_ENTRY'
3996 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
3997    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
3998          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
3999        )
4000    THEN
4001          xla_ae_lines_pkg.BflowUpgEntry
4002            (p_business_method_code    => l_bflow_method_code
4003            ,p_business_class_code     => l_bflow_class_code
4004            ,p_balance_type            => l_balance_type_code);
4005    ELSE
4006       NULL;
4007 -- No business flow processing for business flow method of NONE.
4008    END IF;
4009 
4010    --
4011    -- call analytical criteria
4012    --
4013    
4014    --
4015    -- call description
4016    --
4017    -- No description or it is inherited.
4018    --
4019    -- call ADRs
4020    -- Bug 4922099
4021    --
4022    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4023         (NVL(l_actual_upg_option, 'N') = 'O') OR
4024         (NVL(l_enc_upg_option, 'N') = 'O')
4025       )
4026    THEN
4027    NULL;
4028    --
4029    --
4030    
4031   l_ccid := AcctDerRule_6(
4032            p_application_id           => p_application_id
4033          , p_ae_header_id             => l_ae_header_id 
4034 , p_source_7 => p_source_7
4035          , x_transaction_coa_id       => l_adr_transaction_coa_id
4036          , x_accounting_coa_id        => l_adr_accounting_coa_id
4037          , x_value_type_code          => l_adr_value_type_code
4038          , p_side                     => 'NA'
4039    );
4040 
4041    xla_ae_lines_pkg.set_ccid(
4042     p_code_combination_id          => l_ccid
4043   , p_value_type_code              => l_adr_value_type_code
4044   , p_transaction_coa_id           => l_adr_transaction_coa_id
4045   , p_accounting_coa_id            => l_adr_accounting_coa_id
4046   , p_adr_code                     => 'STD_CONTRA_LIAB'
4047   , p_adr_type_code                => 'S'
4048   , p_component_type               => l_component_type
4049   , p_component_code               => l_component_code
4050   , p_component_type_code          => l_component_type_code
4051   , p_component_appl_id            => l_component_appl_id
4052   , p_amb_context_code             => l_amb_context_code
4053   , p_side                         => 'NA'
4054   );
4055 
4056 
4057    --
4058    --
4059    END IF;
4060    --
4061    -- Bug 4922099
4062    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4063           (NVL(l_enc_upg_option, 'N') = 'O')
4064         ) AND
4065         (l_bflow_method_code = 'PRIOR_ENTRY')
4066       )
4067    THEN
4068       IF
4069       --
4070       1 = 2
4071       --
4072       THEN
4073       xla_accounting_err_pkg.build_message
4074                                     (p_appli_s_name            => 'XLA'
4075                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4076                                     ,p_token_1                 => 'LINE_NUMBER'
4077                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4078                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4079                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4080                                                                              l_component_type
4084                                                                             ,l_amb_context_code
4081                                                                             ,l_component_code
4082                                                                             ,l_component_type_code
4083                                                                             ,l_component_appl_id
4085                                                                             ,l_entity_code
4086                                                                             ,l_event_class_code
4087                                                                            )
4088                                     ,p_token_3                 => 'OWNER'
4089                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4090                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4091                                                                           ,p_lookup_code    => l_component_type_code
4092                                                                          )
4093                                     ,p_token_4                 => 'PRODUCT_NAME'
4094                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4095                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4096                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4097                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4098                                     ,p_ae_header_id            =>  NULL
4099                                        );
4100 
4101         IF (C_LEVEL_ERROR>= g_log_level) THEN
4102                  trace
4103                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4104                       ,p_level    => C_LEVEL_ERROR
4105                       ,p_module   => l_log_module);
4106         END IF;
4107       END IF;
4108    END IF;
4109    --
4110    --
4111    ------------------------------------------------------------------------------------------------
4112    -- 4219869 Business Flow
4113    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4114    -- Prior Entry.  Currently, the following code is always generated.
4115    ------------------------------------------------------------------------------------------------
4116    XLA_AE_LINES_PKG.ValidateCurrentLine;
4117 
4118    ------------------------------------------------------------------------------------
4119    -- 4219869 Business Flow
4120    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4121    ------------------------------------------------------------------------------------
4122    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4123 
4124    ----------------------------------------------------------------------------------
4125    -- 4219869 Business Flow
4126    -- Update journal entry status -- Need to generate this within IF <condition>
4127    ----------------------------------------------------------------------------------
4128    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4129          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4130          ,p_balance_type_code => l_balance_type_code
4131          );
4132 
4133    -------------------------------------------------------------------------------------------
4134    -- 4262811 - Generate the Accrual Reversal lines
4135    -------------------------------------------------------------------------------------------
4136    BEGIN
4137       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4138                               (g_array_event(p_event_id).array_value_num('header_index'));
4139       IF l_acc_rev_flag IS NULL THEN
4140          l_acc_rev_flag := 'N';
4141       END IF;
4142    EXCEPTION
4143       WHEN OTHERS THEN
4144          l_acc_rev_flag := 'N';
4145    END;
4146    --
4147    IF (l_acc_rev_flag = 'Y') THEN
4148 
4149        -- 4645092  ------------------------------------------------------------------------------
4150        -- To allow MPA report to determine if it should generate report process
4151        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4152        ------------------------------------------------------------------------------------------
4153 
4154        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4155        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4156    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4157    -- call ADRs
4158    -- Bug 4922099
4159    --
4160    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4161         (NVL(l_actual_upg_option, 'N') = 'O') OR
4162         (NVL(l_enc_upg_option, 'N') = 'O')
4163       )
4164    THEN
4165    NULL;
4166    --
4167    --
4168    
4169   l_ccid := AcctDerRule_6(
4170            p_application_id           => p_application_id
4171          , p_ae_header_id             => l_ae_header_id 
4172 , p_source_7 => p_source_7
4173          , x_transaction_coa_id       => l_adr_transaction_coa_id
4174          , x_accounting_coa_id        => l_adr_accounting_coa_id
4175          , x_value_type_code          => l_adr_value_type_code
4176          , p_side                     => 'NA'
4177    );
4178 
4179    xla_ae_lines_pkg.set_ccid(
4180     p_code_combination_id          => l_ccid
4184   , p_adr_code                     => 'STD_CONTRA_LIAB'
4181   , p_value_type_code              => l_adr_value_type_code
4182   , p_transaction_coa_id           => l_adr_transaction_coa_id
4183   , p_accounting_coa_id            => l_adr_accounting_coa_id
4185   , p_adr_type_code                => 'S'
4186   , p_component_type               => l_component_type
4187   , p_component_code               => l_component_code
4188   , p_component_type_code          => l_component_type_code
4189   , p_component_appl_id            => l_component_appl_id
4190   , p_amb_context_code             => l_amb_context_code
4191   , p_side                         => 'NA'
4192   );
4193 
4194 
4195    --
4196    --
4197    END IF;
4198 
4199        --
4200        -- Update the line information that should be overwritten
4201        --
4202        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4203                                          p_header_num   => 1);
4204        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4205 
4206        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4207 
4208        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4209           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4210        END IF;
4211 
4212       --
4213       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4214       --
4215       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4216           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4217       ELSE
4218           ---------------------------------------------------------------------------------------------------
4219           -- 4262811a Switch Sign
4220           ---------------------------------------------------------------------------------------------------
4221           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4222           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4223                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4224           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4225                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4226           -- 5132302
4227           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4228                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4229 
4230       END IF;
4231 
4232       -- 4955764
4233       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4234       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4235 
4236 
4237       XLA_AE_LINES_PKG.ValidateCurrentLine;
4238       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4239 
4240       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4241                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4242                ,p_balance_type_code => l_balance_type_code);
4243 
4244    END IF;
4245 
4246    -----------------------------------------------------------------------------------------
4247    -- 4262811 Multiperiod Accounting
4248    -----------------------------------------------------------------------------------------
4249      -- No MPA option is assigned.
4250 
4251 
4252 END IF;
4253 --
4254 
4255 --
4256 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4257    trace
4258       (p_msg      => 'END of AcctLineType_13'
4259       ,p_level    => C_LEVEL_PROCEDURE
4260       ,p_module   => l_log_module);
4261 END IF;
4262 --
4263 EXCEPTION
4264   WHEN xla_exceptions_pkg.application_exception THEN
4265       RAISE;
4266   WHEN OTHERS THEN
4267        xla_exceptions_pkg.raise_message
4268            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_13');
4269 END AcctLineType_13;
4270 --
4271 
4272 ---------------------------------------
4273 --
4274 -- PRIVATE FUNCTION
4275 --         AcctLineType_14
4276 --
4277 ---------------------------------------
4278 PROCEDURE AcctLineType_14 (
4279   p_application_id        IN NUMBER
4280  ,p_event_id              IN NUMBER
4281  ,p_calculate_acctd_flag  IN VARCHAR2
4282  ,p_calculate_g_l_flag    IN VARCHAR2
4283  ,p_actual_flag           IN OUT VARCHAR2
4284  ,p_balance_type_code     OUT VARCHAR2
4285  ,p_gain_or_loss_ref      OUT VARCHAR2
4286  
4287 --Transaction Number
4288  , p_source_1            IN VARCHAR2
4289 --Claim Number
4290  , p_source_2            IN VARCHAR2
4291 --Item Number
4292  , p_source_3            IN VARCHAR2
4293 --Price Protection Standard Accrual Account
4294  , p_source_4            IN NUMBER
4295 --Distribution Identifier
4296  , p_source_9            IN NUMBER
4297 --Distribution Type
4298  , p_source_10            IN VARCHAR2
4299 --Entered Amount
4300  , p_source_11            IN NUMBER
4301 --Transaction Currency Code
4302  , p_source_12            IN VARCHAR2
4303 --Accounted Amount
4304  , p_source_13            IN NUMBER
4305 --Party Identifier
4306  , p_source_14            IN NUMBER
4307 --Party Site Identifier
4311 )
4308  , p_source_15            IN NUMBER
4309 --Party Type
4310  , p_source_16            IN VARCHAR2
4312 IS
4313 
4314 l_component_type              VARCHAR2(80);
4315 l_component_code              VARCHAR2(30);
4316 l_component_type_code         VARCHAR2(1);
4317 l_component_appl_id           INTEGER;
4318 l_amb_context_code            VARCHAR2(30);
4319 l_entity_code                 VARCHAR2(30);
4320 l_event_class_code            VARCHAR2(30);
4321 l_ae_header_id                NUMBER;
4322 l_event_type_code             VARCHAR2(30);
4323 l_line_definition_code        VARCHAR2(30);
4324 l_line_definition_owner_code  VARCHAR2(1);
4325 --
4326 -- adr variables
4327 l_segment                     VARCHAR2(30);
4328 l_ccid                        NUMBER;
4329 l_adr_transaction_coa_id      NUMBER;
4330 l_adr_accounting_coa_id       NUMBER;
4331 l_adr_flexfield_segment_code  VARCHAR2(30);
4332 l_adr_flex_value_set_id       NUMBER;
4333 l_adr_value_type_code         VARCHAR2(30);
4334 l_adr_value_combination_id    NUMBER;
4335 l_adr_value_segment_code      VARCHAR2(30);
4336 
4337 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4338 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4339 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4340 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4341 
4342 -- 4262811 Variables ------------------------------------------------------------------------------------------
4343 l_entered_amt_idx             NUMBER;
4344 l_accted_amt_idx              NUMBER;
4345 l_acc_rev_flag                VARCHAR2(1);
4346 l_accrual_line_num            NUMBER;
4347 l_tmp_amt                     NUMBER;
4348 l_acc_rev_natural_side_code   VARCHAR2(1);
4349 
4350 l_num_entries                 NUMBER;
4351 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4352 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4353 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4354 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4355 l_recog_line_1                NUMBER;
4356 l_recog_line_2                NUMBER;
4357 
4358 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4359 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4360 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4361 
4362 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4363 
4364 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4365 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4366 
4367 ---------------------------------------------------------------------------------------------------------------
4368 
4369 
4370 --
4371 -- bulk performance
4372 --
4373 l_balance_type_code           VARCHAR2(1);
4374 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4375 l_log_module                  VARCHAR2(240);
4376 
4377 --
4378 -- Upgrade strategy
4379 --
4380 l_actual_upg_option           VARCHAR2(1);
4381 l_enc_upg_option           VARCHAR2(1);
4382 
4383 --
4384 BEGIN
4385 --
4386 IF g_log_enabled THEN
4387       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_14';
4388 END IF;
4389 --
4390 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4391 
4392       trace
4393          (p_msg      => 'BEGIN of AcctLineType_14'
4394          ,p_level    => C_LEVEL_PROCEDURE
4395          ,p_module   => l_log_module);
4396 
4397 END IF;
4398 --
4399 l_component_type             := 'AMB_JLT';
4400 l_component_code             := 'SUP_DSTR_CLAIM_ACCRUAL';
4401 l_component_type_code        := 'S';
4402 l_component_appl_id          :=  9000;
4403 l_amb_context_code           := 'DEFAULT';
4404 l_entity_code                := 'CLAIM_SETTLEMENT';
4405 l_event_class_code           := 'CLAIM_SETTLEMENT';
4406 l_event_type_code            := 'SUPPLIER_DSTR_CLAIM';
4407 l_line_definition_owner_code := 'S';
4408 l_line_definition_code       := 'SUPPLIER_DSTR_CLAIM';
4409 --
4410 l_balance_type_code          := 'A';
4411 l_segment                     := NULL;
4412 l_ccid                        := NULL;
4413 l_adr_transaction_coa_id      := NULL;
4414 l_adr_accounting_coa_id       := NULL;
4415 l_adr_flexfield_segment_code  := NULL;
4416 l_adr_flex_value_set_id       := NULL;
4417 l_adr_value_type_code         := NULL;
4418 l_adr_value_combination_id    := NULL;
4419 l_adr_value_segment_code      := NULL;
4420 
4421 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4422 l_bflow_class_code           := '';    -- 4219869 Business Flow
4423 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4424 l_budgetary_control_flag     := 'N';
4425 
4426 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4427 l_bflow_applied_to_amt       := NULL; -- 5132302
4428 l_entered_amt_idx            := NULL;          -- 4262811
4429 l_accted_amt_idx             := NULL;          -- 4262811
4430 l_acc_rev_flag               := NULL;          -- 4262811
4431 l_accrual_line_num           := NULL;          -- 4262811
4432 l_tmp_amt                    := NULL;          -- 4262811
4433 --
4434  
4435 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4436     l_balance_type_code <> 'B' THEN
4440 
4437 
4438    --
4439    XLA_AE_LINES_PKG.SetNewLine;
4441    p_balance_type_code          := l_balance_type_code;
4442    -- set the flag so later we will know whether the gain loss line needs to be created
4443    
4444    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
4445      p_actual_flag :='A';
4446    END IF;
4447 
4448    --
4449    -- bulk performance
4450    --
4451    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
4452                                       p_header_num   => 0); -- 4262811
4453    --
4454    -- set accounting line options
4455    --
4456    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
4457            p_natural_side_code          => 'C'
4458          , p_gain_or_loss_flag          => 'N'
4459          , p_gl_transfer_mode_code      => 'S'
4460          , p_acct_entry_type_code       => 'A'
4461          , p_switch_side_flag           => 'N'
4462          , p_merge_duplicate_code       => 'W'
4463          );
4464    --
4465    l_acc_rev_natural_side_code := 'D';  -- 4262811
4466    -- 
4467    --
4468    -- set accounting line type info
4469    --
4470    xla_ae_lines_pkg.SetAcctLineType
4471       (p_component_type             => l_component_type
4472       ,p_event_type_code            => l_event_type_code
4473       ,p_line_definition_owner_code => l_line_definition_owner_code
4474       ,p_line_definition_code       => l_line_definition_code
4475       ,p_accounting_line_code       => l_component_code
4476       ,p_accounting_line_type_code  => l_component_type_code
4477       ,p_accounting_line_appl_id    => l_component_appl_id
4478       ,p_amb_context_code           => l_amb_context_code
4479       ,p_entity_code                => l_entity_code
4480       ,p_event_class_code           => l_event_class_code);
4481    --
4482    -- set accounting class
4483    --
4484    xla_ae_lines_pkg.SetAcctClass(
4485            p_accounting_class_code  => 'CLAIM_SETTLE'
4486          , p_ae_header_id           => l_ae_header_id
4487          );
4488 
4489    --
4490    -- set rounding class
4491    --
4492    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
4493                       'CLAIM_SETTLE';
4494 
4495    --
4496    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
4497    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
4498    --
4499    -- bulk performance
4500    --
4501    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
4502 
4503    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
4504       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
4505 
4506    -- 4955764
4507    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4508       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
4509 
4510    -- 4458381 Public Sector Enh
4511    
4512    --
4513    -- set accounting attributes for the line type
4514    --
4515    l_entered_amt_idx := 3;
4516    l_accted_amt_idx  := 5;
4517    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
4518    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
4519    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
4520    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
4521    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
4522    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
4523    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
4524    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
4525    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
4526    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
4527    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
4528    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
4529    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
4530    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
4531    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
4532    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
4533    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
4534 
4535    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
4536    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
4537 
4538    ---------------------------------------------------------------------------------------------------------------
4539    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
4540    ---------------------------------------------------------------------------------------------------------------
4541    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
4542 
4543    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4544    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
4545 
4546    IF xla_accounting_cache_pkg.GetValueChar
4547          (p_source_code         => 'LEDGER_CATEGORY_CODE'
4548          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
4549    AND l_bflow_method_code = 'PRIOR_ENTRY'
4553        )
4550 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
4551    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
4552          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
4554    THEN
4555          xla_ae_lines_pkg.BflowUpgEntry
4556            (p_business_method_code    => l_bflow_method_code
4557            ,p_business_class_code     => l_bflow_class_code
4558            ,p_balance_type            => l_balance_type_code);
4559    ELSE
4560       NULL;
4561 -- No business flow processing for business flow method of NONE.
4562    END IF;
4563 
4564    --
4565    -- call analytical criteria
4566    --
4567    
4568    --
4569    -- call description
4570    --
4571    
4572 xla_ae_lines_pkg.SetLineDescription(
4573    p_ae_header_id => l_ae_header_id
4574   ,p_description  => Description_1 (
4575      p_application_id         => p_application_id
4576    , p_ae_header_id           => l_ae_header_id 
4577 , p_source_1 => p_source_1
4578 , p_source_2 => p_source_2
4579 , p_source_3 => p_source_3
4580    )
4581 );
4582 
4583 
4584    --
4585    -- call ADRs
4586    -- Bug 4922099
4587    --
4588    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4589         (NVL(l_actual_upg_option, 'N') = 'O') OR
4590         (NVL(l_enc_upg_option, 'N') = 'O')
4591       )
4592    THEN
4593    NULL;
4594    --
4595    --
4596    
4597   l_ccid := AcctDerRule_3(
4598            p_application_id           => p_application_id
4599          , p_ae_header_id             => l_ae_header_id 
4600 , p_source_4 => p_source_4
4601          , x_transaction_coa_id       => l_adr_transaction_coa_id
4602          , x_accounting_coa_id        => l_adr_accounting_coa_id
4603          , x_value_type_code          => l_adr_value_type_code
4604          , p_side                     => 'NA'
4605    );
4606 
4607    xla_ae_lines_pkg.set_ccid(
4608     p_code_combination_id          => l_ccid
4609   , p_value_type_code              => l_adr_value_type_code
4610   , p_transaction_coa_id           => l_adr_transaction_coa_id
4611   , p_accounting_coa_id            => l_adr_accounting_coa_id
4612   , p_adr_code                     => 'STD_ACCRUAL'
4613   , p_adr_type_code                => 'S'
4614   , p_component_type               => l_component_type
4615   , p_component_code               => l_component_code
4616   , p_component_type_code          => l_component_type_code
4617   , p_component_appl_id            => l_component_appl_id
4618   , p_amb_context_code             => l_amb_context_code
4619   , p_side                         => 'NA'
4620   );
4621 
4622 
4623    --
4624    --
4625    END IF;
4626    --
4627    -- Bug 4922099
4628    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
4629           (NVL(l_enc_upg_option, 'N') = 'O')
4630         ) AND
4631         (l_bflow_method_code = 'PRIOR_ENTRY')
4632       )
4633    THEN
4634       IF
4635       --
4636       1 = 2
4637       --
4638       THEN
4639       xla_accounting_err_pkg.build_message
4640                                     (p_appli_s_name            => 'XLA'
4641                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4642                                     ,p_token_1                 => 'LINE_NUMBER'
4643                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
4644                                     ,p_token_2                 => 'LINE_TYPE_NAME'
4645                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
4646                                                                              l_component_type
4647                                                                             ,l_component_code
4648                                                                             ,l_component_type_code
4649                                                                             ,l_component_appl_id
4650                                                                             ,l_amb_context_code
4651                                                                             ,l_entity_code
4652                                                                             ,l_event_class_code
4653                                                                            )
4654                                     ,p_token_3                 => 'OWNER'
4655                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
4656                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
4657                                                                           ,p_lookup_code    => l_component_type_code
4658                                                                          )
4659                                     ,p_token_4                 => 'PRODUCT_NAME'
4660                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
4661                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
4662                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
4663                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
4664                                     ,p_ae_header_id            =>  NULL
4665                                        );
4666 
4670                       ,p_level    => C_LEVEL_ERROR
4667         IF (C_LEVEL_ERROR>= g_log_level) THEN
4668                  trace
4669                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
4671                       ,p_module   => l_log_module);
4672         END IF;
4673       END IF;
4674    END IF;
4675    --
4676    --
4677    ------------------------------------------------------------------------------------------------
4678    -- 4219869 Business Flow
4679    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
4680    -- Prior Entry.  Currently, the following code is always generated.
4681    ------------------------------------------------------------------------------------------------
4682    XLA_AE_LINES_PKG.ValidateCurrentLine;
4683 
4684    ------------------------------------------------------------------------------------
4685    -- 4219869 Business Flow
4686    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
4687    ------------------------------------------------------------------------------------
4688    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4689 
4690    ----------------------------------------------------------------------------------
4691    -- 4219869 Business Flow
4692    -- Update journal entry status -- Need to generate this within IF <condition>
4693    ----------------------------------------------------------------------------------
4694    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4695          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
4696          ,p_balance_type_code => l_balance_type_code
4697          );
4698 
4699    -------------------------------------------------------------------------------------------
4700    -- 4262811 - Generate the Accrual Reversal lines
4701    -------------------------------------------------------------------------------------------
4702    BEGIN
4703       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
4704                               (g_array_event(p_event_id).array_value_num('header_index'));
4705       IF l_acc_rev_flag IS NULL THEN
4706          l_acc_rev_flag := 'N';
4707       END IF;
4708    EXCEPTION
4709       WHEN OTHERS THEN
4710          l_acc_rev_flag := 'N';
4711    END;
4712    --
4713    IF (l_acc_rev_flag = 'Y') THEN
4714 
4715        -- 4645092  ------------------------------------------------------------------------------
4716        -- To allow MPA report to determine if it should generate report process
4717        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
4718        ------------------------------------------------------------------------------------------
4719 
4720        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
4721        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
4722    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
4723    -- call ADRs
4724    -- Bug 4922099
4725    --
4726    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
4727         (NVL(l_actual_upg_option, 'N') = 'O') OR
4728         (NVL(l_enc_upg_option, 'N') = 'O')
4729       )
4730    THEN
4731    NULL;
4732    --
4733    --
4734    
4735   l_ccid := AcctDerRule_3(
4736            p_application_id           => p_application_id
4737          , p_ae_header_id             => l_ae_header_id 
4738 , p_source_4 => p_source_4
4739          , x_transaction_coa_id       => l_adr_transaction_coa_id
4740          , x_accounting_coa_id        => l_adr_accounting_coa_id
4741          , x_value_type_code          => l_adr_value_type_code
4742          , p_side                     => 'NA'
4743    );
4744 
4745    xla_ae_lines_pkg.set_ccid(
4746     p_code_combination_id          => l_ccid
4747   , p_value_type_code              => l_adr_value_type_code
4748   , p_transaction_coa_id           => l_adr_transaction_coa_id
4749   , p_accounting_coa_id            => l_adr_accounting_coa_id
4750   , p_adr_code                     => 'STD_ACCRUAL'
4751   , p_adr_type_code                => 'S'
4752   , p_component_type               => l_component_type
4753   , p_component_code               => l_component_code
4754   , p_component_type_code          => l_component_type_code
4755   , p_component_appl_id            => l_component_appl_id
4756   , p_amb_context_code             => l_amb_context_code
4757   , p_side                         => 'NA'
4758   );
4759 
4760 
4761    --
4762    --
4763    END IF;
4764 
4765        --
4766        -- Update the line information that should be overwritten
4767        --
4768        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
4769                                          p_header_num   => 1);
4770        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
4771 
4772        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
4773 
4774        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
4775           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
4776        END IF;
4777 
4778       --
4779       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
4780       --
4781       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
4782           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
4783       ELSE
4787           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
4784           ---------------------------------------------------------------------------------------------------
4785           -- 4262811a Switch Sign
4786           ---------------------------------------------------------------------------------------------------
4788           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4789                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4790           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
4791                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4792           -- 5132302
4793           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
4794                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
4795 
4796       END IF;
4797 
4798       -- 4955764
4799       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
4800       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
4801 
4802 
4803       XLA_AE_LINES_PKG.ValidateCurrentLine;
4804       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
4805 
4806       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
4807                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
4808                ,p_balance_type_code => l_balance_type_code);
4809 
4810    END IF;
4811 
4812    -----------------------------------------------------------------------------------------
4813    -- 4262811 Multiperiod Accounting
4814    -----------------------------------------------------------------------------------------
4815      -- No MPA option is assigned.
4816 
4817 
4818 END IF;
4819 --
4820 
4821 --
4822 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4823    trace
4824       (p_msg      => 'END of AcctLineType_14'
4825       ,p_level    => C_LEVEL_PROCEDURE
4826       ,p_module   => l_log_module);
4827 END IF;
4828 --
4829 EXCEPTION
4830   WHEN xla_exceptions_pkg.application_exception THEN
4831       RAISE;
4832   WHEN OTHERS THEN
4833        xla_exceptions_pkg.raise_message
4834            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_14');
4835 END AcctLineType_14;
4836 --
4837 
4838 ---------------------------------------
4839 --
4840 -- PRIVATE FUNCTION
4841 --         AcctLineType_15
4842 --
4843 ---------------------------------------
4844 PROCEDURE AcctLineType_15 (
4845   p_application_id        IN NUMBER
4846  ,p_event_id              IN NUMBER
4847  ,p_calculate_acctd_flag  IN VARCHAR2
4848  ,p_calculate_g_l_flag    IN VARCHAR2
4849  ,p_actual_flag           IN OUT VARCHAR2
4850  ,p_balance_type_code     OUT VARCHAR2
4851  ,p_gain_or_loss_ref      OUT VARCHAR2
4852  
4853 --Price Protection Vendor AP Clearing Account
4854  , p_source_5            IN NUMBER
4855 --Distribution Identifier
4856  , p_source_9            IN NUMBER
4857 --Distribution Type
4858  , p_source_10            IN VARCHAR2
4859 --Entered Amount
4860  , p_source_11            IN NUMBER
4861 --Transaction Currency Code
4862  , p_source_12            IN VARCHAR2
4863 --Accounted Amount
4864  , p_source_13            IN NUMBER
4865 --Party Identifier
4866  , p_source_14            IN NUMBER
4867 --Party Site Identifier
4868  , p_source_15            IN NUMBER
4869 --Party Type
4870  , p_source_16            IN VARCHAR2
4871 )
4872 IS
4873 
4874 l_component_type              VARCHAR2(80);
4875 l_component_code              VARCHAR2(30);
4876 l_component_type_code         VARCHAR2(1);
4877 l_component_appl_id           INTEGER;
4878 l_amb_context_code            VARCHAR2(30);
4879 l_entity_code                 VARCHAR2(30);
4880 l_event_class_code            VARCHAR2(30);
4881 l_ae_header_id                NUMBER;
4882 l_event_type_code             VARCHAR2(30);
4883 l_line_definition_code        VARCHAR2(30);
4884 l_line_definition_owner_code  VARCHAR2(1);
4885 --
4886 -- adr variables
4887 l_segment                     VARCHAR2(30);
4888 l_ccid                        NUMBER;
4889 l_adr_transaction_coa_id      NUMBER;
4890 l_adr_accounting_coa_id       NUMBER;
4891 l_adr_flexfield_segment_code  VARCHAR2(30);
4892 l_adr_flex_value_set_id       NUMBER;
4893 l_adr_value_type_code         VARCHAR2(30);
4894 l_adr_value_combination_id    NUMBER;
4895 l_adr_value_segment_code      VARCHAR2(30);
4896 
4897 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
4898 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
4899 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
4900 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
4901 
4902 -- 4262811 Variables ------------------------------------------------------------------------------------------
4903 l_entered_amt_idx             NUMBER;
4904 l_accted_amt_idx              NUMBER;
4905 l_acc_rev_flag                VARCHAR2(1);
4906 l_accrual_line_num            NUMBER;
4907 l_tmp_amt                     NUMBER;
4908 l_acc_rev_natural_side_code   VARCHAR2(1);
4909 
4910 l_num_entries                 NUMBER;
4911 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
4915 l_recog_line_1                NUMBER;
4912 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
4913 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
4914 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
4916 l_recog_line_2                NUMBER;
4917 
4918 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
4919 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
4920 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
4921 
4922 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
4923 
4924 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
4925 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
4926 
4927 ---------------------------------------------------------------------------------------------------------------
4928 
4929 
4930 --
4931 -- bulk performance
4932 --
4933 l_balance_type_code           VARCHAR2(1);
4934 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
4935 l_log_module                  VARCHAR2(240);
4936 
4937 --
4938 -- Upgrade strategy
4939 --
4940 l_actual_upg_option           VARCHAR2(1);
4941 l_enc_upg_option           VARCHAR2(1);
4942 
4943 --
4944 BEGIN
4945 --
4946 IF g_log_enabled THEN
4947       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_15';
4948 END IF;
4949 --
4950 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
4951 
4952       trace
4953          (p_msg      => 'BEGIN of AcctLineType_15'
4954          ,p_level    => C_LEVEL_PROCEDURE
4955          ,p_module   => l_log_module);
4956 
4957 END IF;
4958 --
4959 l_component_type             := 'AMB_JLT';
4960 l_component_code             := 'SUP_DSTR_CLAIM_AP_CLEARING';
4961 l_component_type_code        := 'S';
4962 l_component_appl_id          :=  9000;
4963 l_amb_context_code           := 'DEFAULT';
4964 l_entity_code                := 'CLAIM_SETTLEMENT';
4965 l_event_class_code           := 'CLAIM_SETTLEMENT';
4966 l_event_type_code            := 'SUPPLIER_DSTR_CLAIM';
4967 l_line_definition_owner_code := 'S';
4968 l_line_definition_code       := 'SUPPLIER_DSTR_CLAIM';
4969 --
4970 l_balance_type_code          := 'A';
4971 l_segment                     := NULL;
4972 l_ccid                        := NULL;
4973 l_adr_transaction_coa_id      := NULL;
4974 l_adr_accounting_coa_id       := NULL;
4975 l_adr_flexfield_segment_code  := NULL;
4976 l_adr_flex_value_set_id       := NULL;
4977 l_adr_value_type_code         := NULL;
4978 l_adr_value_combination_id    := NULL;
4979 l_adr_value_segment_code      := NULL;
4980 
4981 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
4982 l_bflow_class_code           := '';    -- 4219869 Business Flow
4983 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
4984 l_budgetary_control_flag     := 'N';
4985 
4986 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
4987 l_bflow_applied_to_amt       := NULL; -- 5132302
4988 l_entered_amt_idx            := NULL;          -- 4262811
4989 l_accted_amt_idx             := NULL;          -- 4262811
4990 l_acc_rev_flag               := NULL;          -- 4262811
4991 l_accrual_line_num           := NULL;          -- 4262811
4992 l_tmp_amt                    := NULL;          -- 4262811
4993 --
4994  
4995 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
4996     l_balance_type_code <> 'B' THEN
4997 
4998    --
4999    XLA_AE_LINES_PKG.SetNewLine;
5000 
5001    p_balance_type_code          := l_balance_type_code;
5002    -- set the flag so later we will know whether the gain loss line needs to be created
5003    
5004    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5005      p_actual_flag :='A';
5006    END IF;
5007 
5008    --
5009    -- bulk performance
5010    --
5011    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5012                                       p_header_num   => 0); -- 4262811
5013    --
5014    -- set accounting line options
5015    --
5016    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5017            p_natural_side_code          => 'D'
5018          , p_gain_or_loss_flag          => 'N'
5019          , p_gl_transfer_mode_code      => 'S'
5020          , p_acct_entry_type_code       => 'A'
5021          , p_switch_side_flag           => 'N'
5022          , p_merge_duplicate_code       => 'W'
5023          );
5024    --
5025    l_acc_rev_natural_side_code := 'C';  -- 4262811
5026    -- 
5027    --
5028    -- set accounting line type info
5029    --
5030    xla_ae_lines_pkg.SetAcctLineType
5031       (p_component_type             => l_component_type
5032       ,p_event_type_code            => l_event_type_code
5033       ,p_line_definition_owner_code => l_line_definition_owner_code
5034       ,p_line_definition_code       => l_line_definition_code
5035       ,p_accounting_line_code       => l_component_code
5036       ,p_accounting_line_type_code  => l_component_type_code
5037       ,p_accounting_line_appl_id    => l_component_appl_id
5038       ,p_amb_context_code           => l_amb_context_code
5039       ,p_entity_code                => l_entity_code
5040       ,p_event_class_code           => l_event_class_code);
5041    --
5045            p_accounting_class_code  => 'CLEARING'
5042    -- set accounting class
5043    --
5044    xla_ae_lines_pkg.SetAcctClass(
5046          , p_ae_header_id           => l_ae_header_id
5047          );
5048 
5049    --
5050    -- set rounding class
5051    --
5052    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5053                       'CLEARING';
5054 
5055    --
5056    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5057    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5058    --
5059    -- bulk performance
5060    --
5061    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5062 
5063    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5064       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5065 
5066    -- 4955764
5067    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5068       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5069 
5070    -- 4458381 Public Sector Enh
5071    
5072    --
5073    -- set accounting attributes for the line type
5074    --
5075    l_entered_amt_idx := 3;
5076    l_accted_amt_idx  := 5;
5077    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5078    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5079    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
5080    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5081    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
5082    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5083    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
5084    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5085    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
5086    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
5087    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
5088    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
5089    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
5090    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
5091    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
5092    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
5093    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
5094 
5095    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5096    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5097 
5098    ---------------------------------------------------------------------------------------------------------------
5099    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5100    ---------------------------------------------------------------------------------------------------------------
5101    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5102 
5103    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5104    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5105 
5106    IF xla_accounting_cache_pkg.GetValueChar
5107          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5108          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5109    AND l_bflow_method_code = 'PRIOR_ENTRY'
5110 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5111    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5112          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5113        )
5114    THEN
5115          xla_ae_lines_pkg.BflowUpgEntry
5116            (p_business_method_code    => l_bflow_method_code
5117            ,p_business_class_code     => l_bflow_class_code
5118            ,p_balance_type            => l_balance_type_code);
5119    ELSE
5120       NULL;
5121 -- No business flow processing for business flow method of NONE.
5122    END IF;
5123 
5124    --
5125    -- call analytical criteria
5126    --
5127    
5128    --
5129    -- call description
5130    --
5131    -- No description or it is inherited.
5132    --
5133    -- call ADRs
5134    -- Bug 4922099
5135    --
5136    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5137         (NVL(l_actual_upg_option, 'N') = 'O') OR
5138         (NVL(l_enc_upg_option, 'N') = 'O')
5139       )
5140    THEN
5141    NULL;
5142    --
5143    --
5144    
5145   l_ccid := AcctDerRule_4(
5146            p_application_id           => p_application_id
5147          , p_ae_header_id             => l_ae_header_id 
5148 , p_source_5 => p_source_5
5149          , x_transaction_coa_id       => l_adr_transaction_coa_id
5150          , x_accounting_coa_id        => l_adr_accounting_coa_id
5151          , x_value_type_code          => l_adr_value_type_code
5152          , p_side                     => 'NA'
5153    );
5154 
5155    xla_ae_lines_pkg.set_ccid(
5156     p_code_combination_id          => l_ccid
5157   , p_value_type_code              => l_adr_value_type_code
5158   , p_transaction_coa_id           => l_adr_transaction_coa_id
5159   , p_accounting_coa_id            => l_adr_accounting_coa_id
5163   , p_component_code               => l_component_code
5160   , p_adr_code                     => 'STD_AP_CLRNG'
5161   , p_adr_type_code                => 'S'
5162   , p_component_type               => l_component_type
5164   , p_component_type_code          => l_component_type_code
5165   , p_component_appl_id            => l_component_appl_id
5166   , p_amb_context_code             => l_amb_context_code
5167   , p_side                         => 'NA'
5168   );
5169 
5170 
5171    --
5172    --
5173    END IF;
5174    --
5175    -- Bug 4922099
5176    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5177           (NVL(l_enc_upg_option, 'N') = 'O')
5178         ) AND
5179         (l_bflow_method_code = 'PRIOR_ENTRY')
5180       )
5181    THEN
5182       IF
5183       --
5184       1 = 2
5185       --
5186       THEN
5187       xla_accounting_err_pkg.build_message
5188                                     (p_appli_s_name            => 'XLA'
5189                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5190                                     ,p_token_1                 => 'LINE_NUMBER'
5191                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5192                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5193                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5194                                                                              l_component_type
5195                                                                             ,l_component_code
5196                                                                             ,l_component_type_code
5197                                                                             ,l_component_appl_id
5198                                                                             ,l_amb_context_code
5199                                                                             ,l_entity_code
5200                                                                             ,l_event_class_code
5201                                                                            )
5202                                     ,p_token_3                 => 'OWNER'
5203                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5204                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5205                                                                           ,p_lookup_code    => l_component_type_code
5206                                                                          )
5207                                     ,p_token_4                 => 'PRODUCT_NAME'
5208                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5209                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5210                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5211                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5212                                     ,p_ae_header_id            =>  NULL
5213                                        );
5214 
5215         IF (C_LEVEL_ERROR>= g_log_level) THEN
5216                  trace
5217                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5218                       ,p_level    => C_LEVEL_ERROR
5219                       ,p_module   => l_log_module);
5220         END IF;
5221       END IF;
5222    END IF;
5223    --
5224    --
5225    ------------------------------------------------------------------------------------------------
5226    -- 4219869 Business Flow
5227    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5228    -- Prior Entry.  Currently, the following code is always generated.
5229    ------------------------------------------------------------------------------------------------
5230    XLA_AE_LINES_PKG.ValidateCurrentLine;
5231 
5232    ------------------------------------------------------------------------------------
5233    -- 4219869 Business Flow
5234    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5235    ------------------------------------------------------------------------------------
5236    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5237 
5238    ----------------------------------------------------------------------------------
5239    -- 4219869 Business Flow
5240    -- Update journal entry status -- Need to generate this within IF <condition>
5241    ----------------------------------------------------------------------------------
5242    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5243          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5244          ,p_balance_type_code => l_balance_type_code
5245          );
5246 
5247    -------------------------------------------------------------------------------------------
5248    -- 4262811 - Generate the Accrual Reversal lines
5249    -------------------------------------------------------------------------------------------
5250    BEGIN
5251       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5252                               (g_array_event(p_event_id).array_value_num('header_index'));
5253       IF l_acc_rev_flag IS NULL THEN
5254          l_acc_rev_flag := 'N';
5255       END IF;
5256    EXCEPTION
5257       WHEN OTHERS THEN
5258          l_acc_rev_flag := 'N';
5259    END;
5260    --
5264        -- To allow MPA report to determine if it should generate report process
5261    IF (l_acc_rev_flag = 'Y') THEN
5262 
5263        -- 4645092  ------------------------------------------------------------------------------
5265        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5266        ------------------------------------------------------------------------------------------
5267 
5268        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5269        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5270    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5271    -- call ADRs
5272    -- Bug 4922099
5273    --
5274    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5275         (NVL(l_actual_upg_option, 'N') = 'O') OR
5276         (NVL(l_enc_upg_option, 'N') = 'O')
5277       )
5278    THEN
5279    NULL;
5280    --
5281    --
5282    
5283   l_ccid := AcctDerRule_4(
5284            p_application_id           => p_application_id
5285          , p_ae_header_id             => l_ae_header_id 
5286 , p_source_5 => p_source_5
5287          , x_transaction_coa_id       => l_adr_transaction_coa_id
5288          , x_accounting_coa_id        => l_adr_accounting_coa_id
5289          , x_value_type_code          => l_adr_value_type_code
5290          , p_side                     => 'NA'
5291    );
5292 
5293    xla_ae_lines_pkg.set_ccid(
5294     p_code_combination_id          => l_ccid
5295   , p_value_type_code              => l_adr_value_type_code
5296   , p_transaction_coa_id           => l_adr_transaction_coa_id
5297   , p_accounting_coa_id            => l_adr_accounting_coa_id
5298   , p_adr_code                     => 'STD_AP_CLRNG'
5299   , p_adr_type_code                => 'S'
5300   , p_component_type               => l_component_type
5301   , p_component_code               => l_component_code
5302   , p_component_type_code          => l_component_type_code
5303   , p_component_appl_id            => l_component_appl_id
5304   , p_amb_context_code             => l_amb_context_code
5305   , p_side                         => 'NA'
5306   );
5307 
5308 
5309    --
5310    --
5311    END IF;
5312 
5313        --
5314        -- Update the line information that should be overwritten
5315        --
5316        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5317                                          p_header_num   => 1);
5318        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5319 
5320        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5321 
5322        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5323           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5324        END IF;
5325 
5326       --
5327       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5328       --
5329       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5330           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5331       ELSE
5332           ---------------------------------------------------------------------------------------------------
5333           -- 4262811a Switch Sign
5334           ---------------------------------------------------------------------------------------------------
5335           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5336           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5337                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5338           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5339                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5340           -- 5132302
5341           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5342                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5343 
5344       END IF;
5345 
5346       -- 4955764
5347       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5348       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5349 
5350 
5351       XLA_AE_LINES_PKG.ValidateCurrentLine;
5352       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5353 
5354       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5355                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5356                ,p_balance_type_code => l_balance_type_code);
5357 
5358    END IF;
5359 
5360    -----------------------------------------------------------------------------------------
5361    -- 4262811 Multiperiod Accounting
5362    -----------------------------------------------------------------------------------------
5363      -- No MPA option is assigned.
5364 
5365 
5366 END IF;
5367 --
5368 
5369 --
5370 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5371    trace
5372       (p_msg      => 'END of AcctLineType_15'
5373       ,p_level    => C_LEVEL_PROCEDURE
5374       ,p_module   => l_log_module);
5375 END IF;
5376 --
5377 EXCEPTION
5378   WHEN xla_exceptions_pkg.application_exception THEN
5382            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_15');
5379       RAISE;
5380   WHEN OTHERS THEN
5381        xla_exceptions_pkg.raise_message
5383 END AcctLineType_15;
5384 --
5385 
5386 ---------------------------------------
5387 --
5388 -- PRIVATE FUNCTION
5389 --         AcctLineType_16
5390 --
5391 ---------------------------------------
5392 PROCEDURE AcctLineType_16 (
5393   p_application_id        IN NUMBER
5394  ,p_event_id              IN NUMBER
5395  ,p_calculate_acctd_flag  IN VARCHAR2
5396  ,p_calculate_g_l_flag    IN VARCHAR2
5397  ,p_actual_flag           IN OUT VARCHAR2
5398  ,p_balance_type_code     OUT VARCHAR2
5399  ,p_gain_or_loss_ref      OUT VARCHAR2
5400  
5401 --Price Protection Vendor AP Clearing Account
5402  , p_source_5            IN NUMBER
5403 --Distribution Identifier
5404  , p_source_9            IN NUMBER
5405 --Distribution Type
5406  , p_source_10            IN VARCHAR2
5407 --Entered Amount
5408  , p_source_11            IN NUMBER
5409 --Transaction Currency Code
5410  , p_source_12            IN VARCHAR2
5411 --Accounted Amount
5412  , p_source_13            IN NUMBER
5413 --Party Identifier
5414  , p_source_14            IN NUMBER
5415 --Party Site Identifier
5416  , p_source_15            IN NUMBER
5417 --Party Type
5418  , p_source_16            IN VARCHAR2
5419 )
5420 IS
5421 
5422 l_component_type              VARCHAR2(80);
5423 l_component_code              VARCHAR2(30);
5424 l_component_type_code         VARCHAR2(1);
5425 l_component_appl_id           INTEGER;
5426 l_amb_context_code            VARCHAR2(30);
5427 l_entity_code                 VARCHAR2(30);
5428 l_event_class_code            VARCHAR2(30);
5429 l_ae_header_id                NUMBER;
5430 l_event_type_code             VARCHAR2(30);
5431 l_line_definition_code        VARCHAR2(30);
5432 l_line_definition_owner_code  VARCHAR2(1);
5433 --
5434 -- adr variables
5435 l_segment                     VARCHAR2(30);
5436 l_ccid                        NUMBER;
5437 l_adr_transaction_coa_id      NUMBER;
5438 l_adr_accounting_coa_id       NUMBER;
5439 l_adr_flexfield_segment_code  VARCHAR2(30);
5440 l_adr_flex_value_set_id       NUMBER;
5441 l_adr_value_type_code         VARCHAR2(30);
5442 l_adr_value_combination_id    NUMBER;
5443 l_adr_value_segment_code      VARCHAR2(30);
5444 
5445 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
5446 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
5447 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
5448 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
5449 
5450 -- 4262811 Variables ------------------------------------------------------------------------------------------
5451 l_entered_amt_idx             NUMBER;
5452 l_accted_amt_idx              NUMBER;
5453 l_acc_rev_flag                VARCHAR2(1);
5454 l_accrual_line_num            NUMBER;
5455 l_tmp_amt                     NUMBER;
5456 l_acc_rev_natural_side_code   VARCHAR2(1);
5457 
5458 l_num_entries                 NUMBER;
5459 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
5460 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
5461 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
5462 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
5463 l_recog_line_1                NUMBER;
5464 l_recog_line_2                NUMBER;
5465 
5466 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
5467 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
5468 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
5469 
5470 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
5471 
5472 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
5473 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
5474 
5475 ---------------------------------------------------------------------------------------------------------------
5476 
5477 
5478 --
5479 -- bulk performance
5480 --
5481 l_balance_type_code           VARCHAR2(1);
5482 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
5483 l_log_module                  VARCHAR2(240);
5484 
5485 --
5486 -- Upgrade strategy
5487 --
5488 l_actual_upg_option           VARCHAR2(1);
5489 l_enc_upg_option           VARCHAR2(1);
5490 
5491 --
5492 BEGIN
5493 --
5494 IF g_log_enabled THEN
5495       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_16';
5496 END IF;
5497 --
5498 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5499 
5500       trace
5501          (p_msg      => 'BEGIN of AcctLineType_16'
5502          ,p_level    => C_LEVEL_PROCEDURE
5503          ,p_module   => l_log_module);
5504 
5505 END IF;
5506 --
5507 l_component_type             := 'AMB_JLT';
5508 l_component_code             := 'SUP_DSTR_CLAIM_AP_INC_CLEARING';
5509 l_component_type_code        := 'S';
5510 l_component_appl_id          :=  9000;
5511 l_amb_context_code           := 'DEFAULT';
5512 l_entity_code                := 'CLAIM_SETTLEMENT';
5513 l_event_class_code           := 'CLAIM_SETTLEMENT';
5514 l_event_type_code            := 'SUPPLIER_DSTR_INC_CLAIM';
5518 l_balance_type_code          := 'A';
5515 l_line_definition_owner_code := 'S';
5516 l_line_definition_code       := 'SUPPLIER_DSTR_INC_CLAIM';
5517 --
5519 l_segment                     := NULL;
5520 l_ccid                        := NULL;
5521 l_adr_transaction_coa_id      := NULL;
5522 l_adr_accounting_coa_id       := NULL;
5523 l_adr_flexfield_segment_code  := NULL;
5524 l_adr_flex_value_set_id       := NULL;
5525 l_adr_value_type_code         := NULL;
5526 l_adr_value_combination_id    := NULL;
5527 l_adr_value_segment_code      := NULL;
5528 
5529 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
5530 l_bflow_class_code           := '';    -- 4219869 Business Flow
5531 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
5532 l_budgetary_control_flag     := 'N';
5533 
5534 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
5535 l_bflow_applied_to_amt       := NULL; -- 5132302
5536 l_entered_amt_idx            := NULL;          -- 4262811
5537 l_accted_amt_idx             := NULL;          -- 4262811
5538 l_acc_rev_flag               := NULL;          -- 4262811
5539 l_accrual_line_num           := NULL;          -- 4262811
5540 l_tmp_amt                    := NULL;          -- 4262811
5541 --
5542  
5543 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
5544     l_balance_type_code <> 'B' THEN
5545 
5546    --
5547    XLA_AE_LINES_PKG.SetNewLine;
5548 
5549    p_balance_type_code          := l_balance_type_code;
5550    -- set the flag so later we will know whether the gain loss line needs to be created
5551    
5552    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
5553      p_actual_flag :='A';
5554    END IF;
5555 
5556    --
5557    -- bulk performance
5558    --
5559    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
5560                                       p_header_num   => 0); -- 4262811
5561    --
5562    -- set accounting line options
5563    --
5564    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
5565            p_natural_side_code          => 'C'
5566          , p_gain_or_loss_flag          => 'N'
5567          , p_gl_transfer_mode_code      => 'S'
5568          , p_acct_entry_type_code       => 'A'
5569          , p_switch_side_flag           => 'N'
5570          , p_merge_duplicate_code       => 'W'
5571          );
5572    --
5573    l_acc_rev_natural_side_code := 'D';  -- 4262811
5574    -- 
5575    --
5576    -- set accounting line type info
5577    --
5578    xla_ae_lines_pkg.SetAcctLineType
5579       (p_component_type             => l_component_type
5580       ,p_event_type_code            => l_event_type_code
5581       ,p_line_definition_owner_code => l_line_definition_owner_code
5582       ,p_line_definition_code       => l_line_definition_code
5583       ,p_accounting_line_code       => l_component_code
5584       ,p_accounting_line_type_code  => l_component_type_code
5585       ,p_accounting_line_appl_id    => l_component_appl_id
5586       ,p_amb_context_code           => l_amb_context_code
5587       ,p_entity_code                => l_entity_code
5588       ,p_event_class_code           => l_event_class_code);
5589    --
5590    -- set accounting class
5591    --
5592    xla_ae_lines_pkg.SetAcctClass(
5593            p_accounting_class_code  => 'CLEARING'
5594          , p_ae_header_id           => l_ae_header_id
5595          );
5596 
5597    --
5598    -- set rounding class
5599    --
5600    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
5601                       'CLEARING';
5602 
5603    --
5604    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
5605    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
5606    --
5607    -- bulk performance
5608    --
5609    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
5610 
5611    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
5612       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
5613 
5614    -- 4955764
5615    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5616       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
5617 
5618    -- 4458381 Public Sector Enh
5619    
5620    --
5621    -- set accounting attributes for the line type
5622    --
5623    l_entered_amt_idx := 3;
5624    l_accted_amt_idx  := 5;
5625    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
5626    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
5627    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
5628    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
5629    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
5630    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
5631    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
5632    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
5633    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
5634    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
5635    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
5636    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
5640    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
5637    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
5638    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
5639    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
5641    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
5642 
5643    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
5644    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
5645 
5646    ---------------------------------------------------------------------------------------------------------------
5647    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
5648    ---------------------------------------------------------------------------------------------------------------
5649    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
5650 
5651    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5652    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
5653 
5654    IF xla_accounting_cache_pkg.GetValueChar
5655          (p_source_code         => 'LEDGER_CATEGORY_CODE'
5656          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
5657    AND l_bflow_method_code = 'PRIOR_ENTRY'
5658 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
5659    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
5660          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
5661        )
5662    THEN
5663          xla_ae_lines_pkg.BflowUpgEntry
5664            (p_business_method_code    => l_bflow_method_code
5665            ,p_business_class_code     => l_bflow_class_code
5666            ,p_balance_type            => l_balance_type_code);
5667    ELSE
5668       NULL;
5669 -- No business flow processing for business flow method of NONE.
5670    END IF;
5671 
5672    --
5673    -- call analytical criteria
5674    --
5675    
5676    --
5677    -- call description
5678    --
5679    -- No description or it is inherited.
5680    --
5681    -- call ADRs
5682    -- Bug 4922099
5683    --
5684    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5685         (NVL(l_actual_upg_option, 'N') = 'O') OR
5686         (NVL(l_enc_upg_option, 'N') = 'O')
5687       )
5688    THEN
5689    NULL;
5690    --
5691    --
5692    
5693   l_ccid := AcctDerRule_4(
5694            p_application_id           => p_application_id
5695          , p_ae_header_id             => l_ae_header_id 
5696 , p_source_5 => p_source_5
5697          , x_transaction_coa_id       => l_adr_transaction_coa_id
5698          , x_accounting_coa_id        => l_adr_accounting_coa_id
5699          , x_value_type_code          => l_adr_value_type_code
5700          , p_side                     => 'NA'
5701    );
5702 
5703    xla_ae_lines_pkg.set_ccid(
5704     p_code_combination_id          => l_ccid
5705   , p_value_type_code              => l_adr_value_type_code
5706   , p_transaction_coa_id           => l_adr_transaction_coa_id
5707   , p_accounting_coa_id            => l_adr_accounting_coa_id
5708   , p_adr_code                     => 'STD_AP_CLRNG'
5709   , p_adr_type_code                => 'S'
5710   , p_component_type               => l_component_type
5711   , p_component_code               => l_component_code
5712   , p_component_type_code          => l_component_type_code
5713   , p_component_appl_id            => l_component_appl_id
5714   , p_amb_context_code             => l_amb_context_code
5715   , p_side                         => 'NA'
5716   );
5717 
5718 
5719    --
5720    --
5721    END IF;
5722    --
5723    -- Bug 4922099
5724    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
5725           (NVL(l_enc_upg_option, 'N') = 'O')
5726         ) AND
5727         (l_bflow_method_code = 'PRIOR_ENTRY')
5728       )
5729    THEN
5730       IF
5731       --
5732       1 = 2
5733       --
5734       THEN
5735       xla_accounting_err_pkg.build_message
5736                                     (p_appli_s_name            => 'XLA'
5737                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5738                                     ,p_token_1                 => 'LINE_NUMBER'
5739                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
5740                                     ,p_token_2                 => 'LINE_TYPE_NAME'
5741                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
5742                                                                              l_component_type
5743                                                                             ,l_component_code
5744                                                                             ,l_component_type_code
5745                                                                             ,l_component_appl_id
5746                                                                             ,l_amb_context_code
5747                                                                             ,l_entity_code
5748                                                                             ,l_event_class_code
5749                                                                            )
5750                                     ,p_token_3                 => 'OWNER'
5751                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
5755                                     ,p_token_4                 => 'PRODUCT_NAME'
5752                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
5753                                                                           ,p_lookup_code    => l_component_type_code
5754                                                                          )
5756                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
5757                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
5758                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
5759                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
5760                                     ,p_ae_header_id            =>  NULL
5761                                        );
5762 
5763         IF (C_LEVEL_ERROR>= g_log_level) THEN
5764                  trace
5765                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
5766                       ,p_level    => C_LEVEL_ERROR
5767                       ,p_module   => l_log_module);
5768         END IF;
5769       END IF;
5770    END IF;
5771    --
5772    --
5773    ------------------------------------------------------------------------------------------------
5774    -- 4219869 Business Flow
5775    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
5776    -- Prior Entry.  Currently, the following code is always generated.
5777    ------------------------------------------------------------------------------------------------
5778    XLA_AE_LINES_PKG.ValidateCurrentLine;
5779 
5780    ------------------------------------------------------------------------------------
5781    -- 4219869 Business Flow
5782    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
5783    ------------------------------------------------------------------------------------
5784    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5785 
5786    ----------------------------------------------------------------------------------
5787    -- 4219869 Business Flow
5788    -- Update journal entry status -- Need to generate this within IF <condition>
5789    ----------------------------------------------------------------------------------
5790    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5791          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
5792          ,p_balance_type_code => l_balance_type_code
5793          );
5794 
5795    -------------------------------------------------------------------------------------------
5796    -- 4262811 - Generate the Accrual Reversal lines
5797    -------------------------------------------------------------------------------------------
5798    BEGIN
5799       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
5800                               (g_array_event(p_event_id).array_value_num('header_index'));
5801       IF l_acc_rev_flag IS NULL THEN
5802          l_acc_rev_flag := 'N';
5803       END IF;
5804    EXCEPTION
5805       WHEN OTHERS THEN
5806          l_acc_rev_flag := 'N';
5807    END;
5808    --
5809    IF (l_acc_rev_flag = 'Y') THEN
5810 
5811        -- 4645092  ------------------------------------------------------------------------------
5812        -- To allow MPA report to determine if it should generate report process
5813        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
5814        ------------------------------------------------------------------------------------------
5815 
5816        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
5817        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
5818    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
5819    -- call ADRs
5820    -- Bug 4922099
5821    --
5822    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
5823         (NVL(l_actual_upg_option, 'N') = 'O') OR
5824         (NVL(l_enc_upg_option, 'N') = 'O')
5825       )
5826    THEN
5827    NULL;
5828    --
5829    --
5830    
5831   l_ccid := AcctDerRule_4(
5832            p_application_id           => p_application_id
5833          , p_ae_header_id             => l_ae_header_id 
5834 , p_source_5 => p_source_5
5835          , x_transaction_coa_id       => l_adr_transaction_coa_id
5836          , x_accounting_coa_id        => l_adr_accounting_coa_id
5837          , x_value_type_code          => l_adr_value_type_code
5838          , p_side                     => 'NA'
5839    );
5840 
5841    xla_ae_lines_pkg.set_ccid(
5842     p_code_combination_id          => l_ccid
5843   , p_value_type_code              => l_adr_value_type_code
5844   , p_transaction_coa_id           => l_adr_transaction_coa_id
5845   , p_accounting_coa_id            => l_adr_accounting_coa_id
5846   , p_adr_code                     => 'STD_AP_CLRNG'
5847   , p_adr_type_code                => 'S'
5848   , p_component_type               => l_component_type
5849   , p_component_code               => l_component_code
5850   , p_component_type_code          => l_component_type_code
5851   , p_component_appl_id            => l_component_appl_id
5852   , p_amb_context_code             => l_amb_context_code
5853   , p_side                         => 'NA'
5854   );
5855 
5856 
5857    --
5858    --
5859    END IF;
5860 
5861        --
5865                                          p_header_num   => 1);
5862        -- Update the line information that should be overwritten
5863        --
5864        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
5866        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
5867 
5868        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
5869 
5870        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
5871           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
5872        END IF;
5873 
5874       --
5875       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
5876       --
5877       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
5878           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
5879       ELSE
5880           ---------------------------------------------------------------------------------------------------
5881           -- 4262811a Switch Sign
5882           ---------------------------------------------------------------------------------------------------
5883           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
5884           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5885                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5886           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
5887                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5888           -- 5132302
5889           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
5890                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
5891 
5892       END IF;
5893 
5894       -- 4955764
5895       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
5896       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
5897 
5898 
5899       XLA_AE_LINES_PKG.ValidateCurrentLine;
5900       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
5901 
5902       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
5903                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
5904                ,p_balance_type_code => l_balance_type_code);
5905 
5906    END IF;
5907 
5908    -----------------------------------------------------------------------------------------
5909    -- 4262811 Multiperiod Accounting
5910    -----------------------------------------------------------------------------------------
5911      -- No MPA option is assigned.
5912 
5913 
5914 END IF;
5915 --
5916 
5917 --
5918 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
5919    trace
5920       (p_msg      => 'END of AcctLineType_16'
5921       ,p_level    => C_LEVEL_PROCEDURE
5922       ,p_module   => l_log_module);
5923 END IF;
5924 --
5925 EXCEPTION
5926   WHEN xla_exceptions_pkg.application_exception THEN
5927       RAISE;
5928   WHEN OTHERS THEN
5929        xla_exceptions_pkg.raise_message
5930            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_16');
5931 END AcctLineType_16;
5932 --
5933 
5934 ---------------------------------------
5935 --
5936 -- PRIVATE FUNCTION
5937 --         AcctLineType_17
5938 --
5939 ---------------------------------------
5940 PROCEDURE AcctLineType_17 (
5941   p_application_id        IN NUMBER
5942  ,p_event_id              IN NUMBER
5943  ,p_calculate_acctd_flag  IN VARCHAR2
5944  ,p_calculate_g_l_flag    IN VARCHAR2
5945  ,p_actual_flag           IN OUT VARCHAR2
5946  ,p_balance_type_code     OUT VARCHAR2
5947  ,p_gain_or_loss_ref      OUT VARCHAR2
5948  
5949 --Transaction Number
5950  , p_source_1            IN VARCHAR2
5951 --Claim Number
5952  , p_source_2            IN VARCHAR2
5953 --Item Number
5954  , p_source_3            IN VARCHAR2
5955 --Price Protection Standard Accrual Account
5956  , p_source_4            IN NUMBER
5957 --Distribution Identifier
5958  , p_source_9            IN NUMBER
5959 --Distribution Type
5960  , p_source_10            IN VARCHAR2
5961 --Entered Amount
5962  , p_source_11            IN NUMBER
5963 --Transaction Currency Code
5964  , p_source_12            IN VARCHAR2
5965 --Accounted Amount
5966  , p_source_13            IN NUMBER
5967 --Party Identifier
5968  , p_source_14            IN NUMBER
5969 --Party Site Identifier
5970  , p_source_15            IN NUMBER
5971 --Party Type
5972  , p_source_16            IN VARCHAR2
5973 )
5974 IS
5975 
5976 l_component_type              VARCHAR2(80);
5977 l_component_code              VARCHAR2(30);
5978 l_component_type_code         VARCHAR2(1);
5979 l_component_appl_id           INTEGER;
5980 l_amb_context_code            VARCHAR2(30);
5981 l_entity_code                 VARCHAR2(30);
5982 l_event_class_code            VARCHAR2(30);
5983 l_ae_header_id                NUMBER;
5984 l_event_type_code             VARCHAR2(30);
5985 l_line_definition_code        VARCHAR2(30);
5986 l_line_definition_owner_code  VARCHAR2(1);
5987 --
5991 l_adr_transaction_coa_id      NUMBER;
5988 -- adr variables
5989 l_segment                     VARCHAR2(30);
5990 l_ccid                        NUMBER;
5992 l_adr_accounting_coa_id       NUMBER;
5993 l_adr_flexfield_segment_code  VARCHAR2(30);
5994 l_adr_flex_value_set_id       NUMBER;
5995 l_adr_value_type_code         VARCHAR2(30);
5996 l_adr_value_combination_id    NUMBER;
5997 l_adr_value_segment_code      VARCHAR2(30);
5998 
5999 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
6000 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
6001 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
6002 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
6003 
6004 -- 4262811 Variables ------------------------------------------------------------------------------------------
6005 l_entered_amt_idx             NUMBER;
6006 l_accted_amt_idx              NUMBER;
6007 l_acc_rev_flag                VARCHAR2(1);
6008 l_accrual_line_num            NUMBER;
6009 l_tmp_amt                     NUMBER;
6010 l_acc_rev_natural_side_code   VARCHAR2(1);
6011 
6012 l_num_entries                 NUMBER;
6013 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
6014 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
6015 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
6016 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
6017 l_recog_line_1                NUMBER;
6018 l_recog_line_2                NUMBER;
6019 
6020 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
6021 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
6022 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
6023 
6024 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
6025 
6026 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
6027 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
6028 
6029 ---------------------------------------------------------------------------------------------------------------
6030 
6031 
6032 --
6033 -- bulk performance
6034 --
6035 l_balance_type_code           VARCHAR2(1);
6036 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
6037 l_log_module                  VARCHAR2(240);
6038 
6039 --
6040 -- Upgrade strategy
6041 --
6042 l_actual_upg_option           VARCHAR2(1);
6043 l_enc_upg_option           VARCHAR2(1);
6044 
6045 --
6046 BEGIN
6047 --
6048 IF g_log_enabled THEN
6049       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_17';
6050 END IF;
6051 --
6052 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6053 
6054       trace
6055          (p_msg      => 'BEGIN of AcctLineType_17'
6056          ,p_level    => C_LEVEL_PROCEDURE
6057          ,p_module   => l_log_module);
6058 
6059 END IF;
6060 --
6061 l_component_type             := 'AMB_JLT';
6062 l_component_code             := 'SUP_DSTR_CLAIM_INC_ACCRUAL';
6063 l_component_type_code        := 'S';
6064 l_component_appl_id          :=  9000;
6065 l_amb_context_code           := 'DEFAULT';
6066 l_entity_code                := 'CLAIM_SETTLEMENT';
6067 l_event_class_code           := 'CLAIM_SETTLEMENT';
6068 l_event_type_code            := 'SUPPLIER_DSTR_INC_CLAIM';
6069 l_line_definition_owner_code := 'S';
6070 l_line_definition_code       := 'SUPPLIER_DSTR_INC_CLAIM';
6071 --
6072 l_balance_type_code          := 'A';
6073 l_segment                     := NULL;
6074 l_ccid                        := NULL;
6075 l_adr_transaction_coa_id      := NULL;
6076 l_adr_accounting_coa_id       := NULL;
6077 l_adr_flexfield_segment_code  := NULL;
6078 l_adr_flex_value_set_id       := NULL;
6079 l_adr_value_type_code         := NULL;
6080 l_adr_value_combination_id    := NULL;
6081 l_adr_value_segment_code      := NULL;
6082 
6083 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
6084 l_bflow_class_code           := '';    -- 4219869 Business Flow
6085 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
6086 l_budgetary_control_flag     := 'N';
6087 
6088 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
6089 l_bflow_applied_to_amt       := NULL; -- 5132302
6090 l_entered_amt_idx            := NULL;          -- 4262811
6091 l_accted_amt_idx             := NULL;          -- 4262811
6092 l_acc_rev_flag               := NULL;          -- 4262811
6093 l_accrual_line_num           := NULL;          -- 4262811
6094 l_tmp_amt                    := NULL;          -- 4262811
6095 --
6096  
6097 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
6098     l_balance_type_code <> 'B' THEN
6099 
6100    --
6101    XLA_AE_LINES_PKG.SetNewLine;
6102 
6103    p_balance_type_code          := l_balance_type_code;
6104    -- set the flag so later we will know whether the gain loss line needs to be created
6105    
6106    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
6107      p_actual_flag :='A';
6108    END IF;
6109 
6110    --
6111    -- bulk performance
6112    --
6113    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
6114                                       p_header_num   => 0); -- 4262811
6115    --
6116    -- set accounting line options
6117    --
6121          , p_gl_transfer_mode_code      => 'S'
6118    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
6119            p_natural_side_code          => 'D'
6120          , p_gain_or_loss_flag          => 'N'
6122          , p_acct_entry_type_code       => 'A'
6123          , p_switch_side_flag           => 'N'
6124          , p_merge_duplicate_code       => 'W'
6125          );
6126    --
6127    l_acc_rev_natural_side_code := 'C';  -- 4262811
6128    -- 
6129    --
6130    -- set accounting line type info
6131    --
6132    xla_ae_lines_pkg.SetAcctLineType
6133       (p_component_type             => l_component_type
6134       ,p_event_type_code            => l_event_type_code
6135       ,p_line_definition_owner_code => l_line_definition_owner_code
6136       ,p_line_definition_code       => l_line_definition_code
6137       ,p_accounting_line_code       => l_component_code
6138       ,p_accounting_line_type_code  => l_component_type_code
6139       ,p_accounting_line_appl_id    => l_component_appl_id
6140       ,p_amb_context_code           => l_amb_context_code
6141       ,p_entity_code                => l_entity_code
6142       ,p_event_class_code           => l_event_class_code);
6143    --
6144    -- set accounting class
6145    --
6146    xla_ae_lines_pkg.SetAcctClass(
6147            p_accounting_class_code  => 'CLAIM_SETTLE'
6148          , p_ae_header_id           => l_ae_header_id
6149          );
6150 
6151    --
6152    -- set rounding class
6153    --
6154    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
6155                       'CLAIM_SETTLE';
6156 
6157    --
6158    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
6159    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
6160    --
6161    -- bulk performance
6162    --
6163    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
6164 
6165    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
6166       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
6167 
6168    -- 4955764
6169    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6170       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
6171 
6172    -- 4458381 Public Sector Enh
6173    
6174    --
6175    -- set accounting attributes for the line type
6176    --
6177    l_entered_amt_idx := 3;
6178    l_accted_amt_idx  := 5;
6179    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
6180    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
6181    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_9);
6182    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
6183    l_rec_acct_attrs.array_char_value(2)  := p_source_10;
6184    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
6185    l_rec_acct_attrs.array_num_value(3)  := p_source_11;
6186    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
6187    l_rec_acct_attrs.array_char_value(4)  := p_source_12;
6188    l_rec_acct_attrs.array_acct_attr_code(5) := 'LEDGER_AMOUNT';
6189    l_rec_acct_attrs.array_num_value(5)  := p_source_13;
6190    l_rec_acct_attrs.array_acct_attr_code(6) := 'PARTY_ID';
6191    l_rec_acct_attrs.array_num_value(6)  := p_source_14;
6192    l_rec_acct_attrs.array_acct_attr_code(7) := 'PARTY_SITE_ID';
6193    l_rec_acct_attrs.array_num_value(7)  := p_source_15;
6194    l_rec_acct_attrs.array_acct_attr_code(8) := 'PARTY_TYPE';
6195    l_rec_acct_attrs.array_char_value(8)  := p_source_16;
6196 
6197    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
6198    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
6199 
6200    ---------------------------------------------------------------------------------------------------------------
6201    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
6202    ---------------------------------------------------------------------------------------------------------------
6203    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
6204 
6205    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6206    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
6207 
6208    IF xla_accounting_cache_pkg.GetValueChar
6209          (p_source_code         => 'LEDGER_CATEGORY_CODE'
6210          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
6211    AND l_bflow_method_code = 'PRIOR_ENTRY'
6212 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
6213    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
6214          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
6215        )
6216    THEN
6217          xla_ae_lines_pkg.BflowUpgEntry
6218            (p_business_method_code    => l_bflow_method_code
6219            ,p_business_class_code     => l_bflow_class_code
6220            ,p_balance_type            => l_balance_type_code);
6221    ELSE
6222       NULL;
6223 -- No business flow processing for business flow method of NONE.
6224    END IF;
6225 
6226    --
6227    -- call analytical criteria
6228    --
6229    
6230    --
6231    -- call description
6232    --
6233    
6237      p_application_id         => p_application_id
6234 xla_ae_lines_pkg.SetLineDescription(
6235    p_ae_header_id => l_ae_header_id
6236   ,p_description  => Description_1 (
6238    , p_ae_header_id           => l_ae_header_id 
6239 , p_source_1 => p_source_1
6240 , p_source_2 => p_source_2
6241 , p_source_3 => p_source_3
6242    )
6243 );
6244 
6245 
6246    --
6247    -- call ADRs
6248    -- Bug 4922099
6249    --
6250    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6251         (NVL(l_actual_upg_option, 'N') = 'O') OR
6252         (NVL(l_enc_upg_option, 'N') = 'O')
6253       )
6254    THEN
6255    NULL;
6256    --
6257    --
6258    
6259   l_ccid := AcctDerRule_3(
6260            p_application_id           => p_application_id
6261          , p_ae_header_id             => l_ae_header_id 
6262 , p_source_4 => p_source_4
6263          , x_transaction_coa_id       => l_adr_transaction_coa_id
6264          , x_accounting_coa_id        => l_adr_accounting_coa_id
6265          , x_value_type_code          => l_adr_value_type_code
6266          , p_side                     => 'NA'
6267    );
6268 
6269    xla_ae_lines_pkg.set_ccid(
6270     p_code_combination_id          => l_ccid
6271   , p_value_type_code              => l_adr_value_type_code
6272   , p_transaction_coa_id           => l_adr_transaction_coa_id
6273   , p_accounting_coa_id            => l_adr_accounting_coa_id
6274   , p_adr_code                     => 'STD_ACCRUAL'
6275   , p_adr_type_code                => 'S'
6276   , p_component_type               => l_component_type
6277   , p_component_code               => l_component_code
6278   , p_component_type_code          => l_component_type_code
6279   , p_component_appl_id            => l_component_appl_id
6280   , p_amb_context_code             => l_amb_context_code
6281   , p_side                         => 'NA'
6282   );
6283 
6284 
6285    --
6286    --
6287    END IF;
6288    --
6289    -- Bug 4922099
6290    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
6291           (NVL(l_enc_upg_option, 'N') = 'O')
6292         ) AND
6293         (l_bflow_method_code = 'PRIOR_ENTRY')
6294       )
6295    THEN
6296       IF
6297       --
6298       1 = 2
6299       --
6300       THEN
6301       xla_accounting_err_pkg.build_message
6302                                     (p_appli_s_name            => 'XLA'
6303                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6304                                     ,p_token_1                 => 'LINE_NUMBER'
6305                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
6306                                     ,p_token_2                 => 'LINE_TYPE_NAME'
6307                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
6308                                                                              l_component_type
6309                                                                             ,l_component_code
6310                                                                             ,l_component_type_code
6311                                                                             ,l_component_appl_id
6312                                                                             ,l_amb_context_code
6313                                                                             ,l_entity_code
6314                                                                             ,l_event_class_code
6315                                                                            )
6316                                     ,p_token_3                 => 'OWNER'
6317                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
6318                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
6319                                                                           ,p_lookup_code    => l_component_type_code
6320                                                                          )
6321                                     ,p_token_4                 => 'PRODUCT_NAME'
6322                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
6323                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
6324                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
6325                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
6326                                     ,p_ae_header_id            =>  NULL
6327                                        );
6328 
6329         IF (C_LEVEL_ERROR>= g_log_level) THEN
6330                  trace
6331                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
6332                       ,p_level    => C_LEVEL_ERROR
6333                       ,p_module   => l_log_module);
6334         END IF;
6335       END IF;
6336    END IF;
6337    --
6338    --
6339    ------------------------------------------------------------------------------------------------
6340    -- 4219869 Business Flow
6341    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
6342    -- Prior Entry.  Currently, the following code is always generated.
6343    ------------------------------------------------------------------------------------------------
6344    XLA_AE_LINES_PKG.ValidateCurrentLine;
6345 
6349    ------------------------------------------------------------------------------------
6346    ------------------------------------------------------------------------------------
6347    -- 4219869 Business Flow
6348    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
6350    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6351 
6352    ----------------------------------------------------------------------------------
6353    -- 4219869 Business Flow
6354    -- Update journal entry status -- Need to generate this within IF <condition>
6355    ----------------------------------------------------------------------------------
6356    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6357          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
6358          ,p_balance_type_code => l_balance_type_code
6359          );
6360 
6361    -------------------------------------------------------------------------------------------
6362    -- 4262811 - Generate the Accrual Reversal lines
6363    -------------------------------------------------------------------------------------------
6364    BEGIN
6365       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
6366                               (g_array_event(p_event_id).array_value_num('header_index'));
6367       IF l_acc_rev_flag IS NULL THEN
6368          l_acc_rev_flag := 'N';
6369       END IF;
6370    EXCEPTION
6371       WHEN OTHERS THEN
6372          l_acc_rev_flag := 'N';
6373    END;
6374    --
6375    IF (l_acc_rev_flag = 'Y') THEN
6376 
6377        -- 4645092  ------------------------------------------------------------------------------
6378        -- To allow MPA report to determine if it should generate report process
6379        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
6380        ------------------------------------------------------------------------------------------
6381 
6382        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
6383        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
6384    -- added call to set_ccid to execute mapping  for secondary accrual reversal entries bug 7444204
6385    -- call ADRs
6386    -- Bug 4922099
6387    --
6388    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
6389         (NVL(l_actual_upg_option, 'N') = 'O') OR
6390         (NVL(l_enc_upg_option, 'N') = 'O')
6391       )
6392    THEN
6393    NULL;
6394    --
6395    --
6396    
6397   l_ccid := AcctDerRule_3(
6398            p_application_id           => p_application_id
6399          , p_ae_header_id             => l_ae_header_id 
6400 , p_source_4 => p_source_4
6401          , x_transaction_coa_id       => l_adr_transaction_coa_id
6402          , x_accounting_coa_id        => l_adr_accounting_coa_id
6403          , x_value_type_code          => l_adr_value_type_code
6404          , p_side                     => 'NA'
6405    );
6406 
6407    xla_ae_lines_pkg.set_ccid(
6408     p_code_combination_id          => l_ccid
6409   , p_value_type_code              => l_adr_value_type_code
6410   , p_transaction_coa_id           => l_adr_transaction_coa_id
6411   , p_accounting_coa_id            => l_adr_accounting_coa_id
6412   , p_adr_code                     => 'STD_ACCRUAL'
6413   , p_adr_type_code                => 'S'
6414   , p_component_type               => l_component_type
6415   , p_component_code               => l_component_code
6416   , p_component_type_code          => l_component_type_code
6417   , p_component_appl_id            => l_component_appl_id
6418   , p_amb_context_code             => l_amb_context_code
6419   , p_side                         => 'NA'
6420   );
6421 
6422 
6423    --
6424    --
6425    END IF;
6426 
6427        --
6428        -- Update the line information that should be overwritten
6429        --
6430        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
6431                                          p_header_num   => 1);
6432        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
6433 
6434        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
6435 
6436        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
6437           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
6438        END IF;
6439 
6440       --
6441       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
6442       --
6443       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
6444           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
6445       ELSE
6446           ---------------------------------------------------------------------------------------------------
6447           -- 4262811a Switch Sign
6448           ---------------------------------------------------------------------------------------------------
6449           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
6450           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6451                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6452           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
6453                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6457 
6454           -- 5132302
6455           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
6456                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
6458       END IF;
6459 
6460       -- 4955764
6461       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
6462       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
6463 
6464 
6465       XLA_AE_LINES_PKG.ValidateCurrentLine;
6466       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
6467 
6468       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
6469                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
6470                ,p_balance_type_code => l_balance_type_code);
6471 
6472    END IF;
6473 
6474    -----------------------------------------------------------------------------------------
6475    -- 4262811 Multiperiod Accounting
6476    -----------------------------------------------------------------------------------------
6477      -- No MPA option is assigned.
6478 
6479 
6480 END IF;
6481 --
6482 
6483 --
6484 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6485    trace
6486       (p_msg      => 'END of AcctLineType_17'
6487       ,p_level    => C_LEVEL_PROCEDURE
6488       ,p_module   => l_log_module);
6489 END IF;
6490 --
6491 EXCEPTION
6492   WHEN xla_exceptions_pkg.application_exception THEN
6493       RAISE;
6494   WHEN OTHERS THEN
6495        xla_exceptions_pkg.raise_message
6496            (p_location => 'XLA_09000_AAD_S_000015_PKG.AcctLineType_17');
6497 END AcctLineType_17;
6498 --
6499 
6500 ---------------------------------------
6501 --
6502 -- PRIVATE PROCEDURE
6503 --         insert_sources_18
6504 --
6505 ----------------------------------------
6506 --
6507 PROCEDURE insert_sources_18(
6508                                 p_target_ledger_id       IN NUMBER
6509                               , p_language               IN VARCHAR2
6510                               , p_sla_ledger_id          IN NUMBER
6511                               , p_pad_start_date         IN DATE
6512                               , p_pad_end_date           IN DATE
6513                          )
6514 IS
6515 
6516 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'COST_UPDATE_ALL';
6517 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'COST_UPDATE';
6518 p_apps_owner                   VARCHAR2(30);
6519 l_log_module                   VARCHAR2(240);
6520 BEGIN
6521 IF g_log_enabled THEN
6522       l_log_module := C_DEFAULT_MODULE||'.insert_sources_18';
6523 END IF;
6524 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6525 
6526       trace
6527          (p_msg      => 'BEGIN of insert_sources_18'
6528          ,p_level    => C_LEVEL_PROCEDURE
6529          ,p_module   => l_log_module);
6530 
6531 END IF;
6532 
6533 -- select APPS owner
6534 SELECT oracle_username
6535   INTO p_apps_owner
6536   FROM fnd_oracle_userid
6537  WHERE read_only_flag = 'U'
6538 ;
6539 
6540 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6541       trace
6542          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
6543                         ' - p_language = '||p_language||
6544                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
6545                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
6546                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
6547                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
6548          ,p_level    => C_LEVEL_STATEMENT
6549          ,p_module   => l_log_module);
6550 END IF;
6551 
6552 
6553 --
6554 INSERT INTO xla_diag_sources --hdr2
6555 (
6556         event_id
6557       , ledger_id
6558       , sla_ledger_id
6559       , description_language
6560       , object_name
6561       , object_type_code
6562       , line_number
6563       , source_application_id
6564       , source_type_code
6565       , source_code
6566       , source_value
6567       , source_meaning
6568       , created_by
6569       , creation_date
6570       , last_update_date
6571       , last_updated_by
6572       , last_update_login
6573       , program_update_date
6574       , program_application_id
6575       , program_id
6576       , request_id
6577 )
6578 SELECT
6579         event_id
6580       , p_target_ledger_id
6581       , p_sla_ledger_id
6582       , p_language
6583       , object_name
6584       , object_type_code
6585       , line_number
6586       , source_application_id
6587       , source_type_code
6588       , source_code
6589       , SUBSTR(source_value ,1,1996)
6590       , SUBSTR(source_meaning ,1,200)
6591       , xla_environment_pkg.g_Usr_Id
6592       , TRUNC(SYSDATE)
6593       , TRUNC(SYSDATE)
6594       , xla_environment_pkg.g_Usr_Id
6595       , xla_environment_pkg.g_Login_Id
6596       , TRUNC(SYSDATE)
6597       , xla_environment_pkg.g_Prog_Appl_Id
6598       , xla_environment_pkg.g_Prog_Id
6599       , xla_environment_pkg.g_Req_Id
6600   FROM (
6601        SELECT xet.event_id                  event_id
6602             , 0                          line_number
6603             , CASE r
6607                 WHEN 4 THEN 'DPP_XLA_INV_HEADERS_V' 
6604                WHEN 1 THEN 'DPP_XLA_INV_HEADERS_V' 
6605                 WHEN 2 THEN 'DPP_XLA_INV_HEADERS_V' 
6606                 WHEN 3 THEN 'DPP_XLA_INV_HEADERS_V' 
6608                 WHEN 5 THEN 'DPP_XLA_INV_HEADERS_V' 
6609                 
6610                ELSE null
6611               END                           object_name
6612             , CASE r
6613                 WHEN 1 THEN 'HEADER' 
6614                 WHEN 2 THEN 'HEADER' 
6615                 WHEN 3 THEN 'HEADER' 
6616                 WHEN 4 THEN 'HEADER' 
6617                 WHEN 5 THEN 'HEADER' 
6618                 
6619                 ELSE null
6620               END                           object_type_code
6621             , CASE r
6622                 WHEN 1 THEN '9000' 
6623                 WHEN 2 THEN '9000' 
6624                 WHEN 3 THEN '9000' 
6625                 WHEN 4 THEN '9000' 
6626                 WHEN 5 THEN '9000' 
6627                 
6628                 ELSE null
6629               END                           source_application_id
6630             , 'S'             source_type_code
6631             , CASE r
6632                 WHEN 1 THEN 'PP_TXN_NUMBER' 
6633                 WHEN 2 THEN 'PP_ACCRUAL_CCID' 
6634                 WHEN 3 THEN 'PP_COST_ADJ_CCID' 
6635                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
6636                 WHEN 5 THEN 'TRANSFER_TO_GL_INDICATOR' 
6637                 
6638                 ELSE null
6639               END                           source_code
6640             , CASE r
6641                 WHEN 1 THEN TO_CHAR(h1.PP_TXN_NUMBER)
6642                 WHEN 2 THEN TO_CHAR(h1.PP_ACCRUAL_CCID)
6643                 WHEN 3 THEN TO_CHAR(h1.PP_COST_ADJ_CCID)
6644                 WHEN 4 THEN TO_CHAR(h1.DISTRIBUTION_TYPE)
6645                 WHEN 5 THEN TO_CHAR(h1.TRANSFER_TO_GL_INDICATOR)
6646                 
6647                 ELSE null
6648               END                           source_value
6649             , null              source_meaning
6650          FROM xla_events_gt     xet  
6651       , DPP_XLA_INV_HEADERS_V  h1
6652              ,(select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
6653          WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
6654            AND xet.event_class_code = C_EVENT_CLASS_CODE
6655               AND h1.event_id = xet.event_id
6656 
6657 )
6658 ;
6659 --
6660 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6661 
6662       trace
6663          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
6664          ,p_level    => C_LEVEL_STATEMENT
6665          ,p_module   => l_log_module);
6666 
6667 END IF;
6668 --
6669 
6670 
6671 
6672 --
6673 INSERT INTO xla_diag_sources  --line2
6674 (
6675         event_id
6676       , ledger_id
6677       , sla_ledger_id
6678       , description_language
6679       , object_name
6680       , object_type_code
6681       , line_number
6682       , source_application_id
6683       , source_type_code
6684       , source_code
6685       , source_value
6686       , source_meaning
6687       , created_by
6688       , creation_date
6689       , last_update_date
6690       , last_updated_by
6691       , last_update_login
6692       , program_update_date
6693       , program_application_id
6694       , program_id
6695       , request_id
6696 )
6697 SELECT  event_id
6698       , p_target_ledger_id
6699       , p_sla_ledger_id
6700       , p_language
6701       , object_name
6702       , object_type_code
6703       , line_number
6704       , source_application_id
6705       , source_type_code
6706       , source_code
6707       , SUBSTR(source_value,1,1996)
6708       , SUBSTR(source_meaning ,1,200)
6709       , xla_environment_pkg.g_Usr_Id
6710       , TRUNC(SYSDATE)
6711       , TRUNC(SYSDATE)
6712       , xla_environment_pkg.g_Usr_Id
6713       , xla_environment_pkg.g_Login_Id
6714       , TRUNC(SYSDATE)
6715       , xla_environment_pkg.g_Prog_Appl_Id
6716       , xla_environment_pkg.g_Prog_Id
6717       , xla_environment_pkg.g_Req_Id
6718   FROM (
6719        SELECT xet.event_id                  event_id
6720             , l2.line_number                 line_number
6721             , CASE r
6722                WHEN 1 THEN 'DPP_XLA_INV_LINES_V' 
6723                 WHEN 2 THEN 'DPP_XLA_INV_LINES_V' 
6724                 WHEN 3 THEN 'DPP_XLA_INV_LINES_V' 
6725                 WHEN 4 THEN 'DPP_XLA_INV_LINES_V' 
6726                 WHEN 5 THEN 'DPP_XLA_INV_LINES_V' 
6727                 
6728                ELSE null
6729               END                           object_name
6730             , CASE r
6731                 WHEN 1 THEN 'LINE' 
6732                 WHEN 2 THEN 'LINE' 
6733                 WHEN 3 THEN 'LINE' 
6734                 WHEN 4 THEN 'LINE' 
6735                 WHEN 5 THEN 'LINE' 
6736                 
6737                 ELSE null
6738               END                           object_type_code
6739             , CASE r
6740                 WHEN 1 THEN '9000' 
6741                 WHEN 2 THEN '9000' 
6742                 WHEN 3 THEN '9000' 
6743                 WHEN 4 THEN '9000' 
6744                 WHEN 5 THEN '9000' 
6745                 
6746                 ELSE null
6747               END                           source_application_id
6751                 WHEN 2 THEN 'DISTRIBUTION_IDENTIFIER' 
6748             , 'S'             source_type_code
6749             , CASE r
6750                 WHEN 1 THEN 'ITEM_NUMBER' 
6752                 WHEN 3 THEN 'ENTERED_AMOUNT' 
6753                 WHEN 4 THEN 'CURRENCY_CODE' 
6754                 WHEN 5 THEN 'ACCOUNTED_AMOUNT' 
6755                 
6756                 ELSE null
6757               END                           source_code
6758             , CASE r
6759                 WHEN 1 THEN TO_CHAR(l2.ITEM_NUMBER)
6760                 WHEN 2 THEN TO_CHAR(l2.DISTRIBUTION_IDENTIFIER)
6761                 WHEN 3 THEN TO_CHAR(l2.ENTERED_AMOUNT)
6762                 WHEN 4 THEN TO_CHAR(l2.CURRENCY_CODE)
6763                 WHEN 5 THEN TO_CHAR(l2.ACCOUNTED_AMOUNT)
6764                 
6765                 ELSE null
6766               END                           source_value
6767             , null              source_meaning
6768          FROM  xla_events_gt     xet  
6769         , DPP_XLA_INV_LINES_V  l2
6770             , (select rownum r from all_objects where rownum <= 5 and owner = p_apps_owner)
6771         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
6772           AND xet.event_class_code = C_EVENT_CLASS_CODE
6773             AND l2.event_id          = xet.event_id
6774 
6775 )
6776 ;
6777 --
6778 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
6779 
6780       trace
6781          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
6782          ,p_level    => C_LEVEL_STATEMENT
6783          ,p_module   => l_log_module);
6784 
6785 END IF;
6786 
6787 
6788 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
6789       trace
6790          (p_msg      => 'END of insert_sources_18'
6791          ,p_level    => C_LEVEL_PROCEDURE
6792          ,p_module   => l_log_module);
6793 END IF;
6794 EXCEPTION
6795   WHEN xla_exceptions_pkg.application_exception THEN
6796       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6797             trace
6798                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
6799                ,p_level    => C_LEVEL_EXCEPTION
6800                ,p_module   => l_log_module);
6801       END IF;
6802       RAISE;
6803   WHEN OTHERS THEN
6804       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
6805             trace
6806                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
6807                ,p_level    => C_LEVEL_EXCEPTION
6808                ,p_module   => l_log_module);
6809        END IF;
6810        xla_exceptions_pkg.raise_message
6811            (p_location => 'XLA_09000_AAD_S_000015_PKG.insert_sources_18');
6812 END insert_sources_18;
6813 --
6814 
6815 ---------------------------------------
6816 --
6817 -- PRIVATE FUNCTION
6818 --         EventClass_18
6819 --
6820 ----------------------------------------
6821 --
6822 FUNCTION EventClass_18
6823        (p_application_id         IN NUMBER
6824        ,p_base_ledger_id         IN NUMBER
6825        ,p_target_ledger_id       IN NUMBER
6826        ,p_language               IN VARCHAR2
6827        ,p_currency_code          IN VARCHAR2
6828        ,p_sla_ledger_id          IN NUMBER
6829        ,p_pad_start_date         IN DATE
6830        ,p_pad_end_date           IN DATE
6831        ,p_primary_ledger_id      IN NUMBER)
6832 RETURN BOOLEAN IS
6833 --
6834 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'COST_UPDATE_ALL';
6835 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'COST_UPDATE';
6836 
6837 l_calculate_acctd_flag   VARCHAR2(1) :='N';
6838 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
6839 --
6840 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6841 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6842 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6843 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6844 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6845 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6846 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6847 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6848 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6849 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6850 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6851 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6852 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6853 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
6854 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6855 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6856 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6857 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
6858 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6859 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6860 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6861 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
6862 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
6863 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
6867 l_event_id                             NUMBER;
6864 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
6865 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
6866 
6868 l_previous_event_id                    NUMBER;
6869 l_first_event_id                       NUMBER;
6870 l_last_event_id                        NUMBER;
6871 
6872 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
6873 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
6874 --
6875 --
6876 l_result                    BOOLEAN := TRUE;
6877 l_rows                      NUMBER  := 1000;
6878 l_event_type_name           VARCHAR2(80) := 'All';
6879 l_event_class_name          VARCHAR2(80) := 'Cost Update';
6880 l_description               VARCHAR2(4000);
6881 l_transaction_reversal      NUMBER;
6882 l_ae_header_id              NUMBER;
6883 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
6884 l_log_module                VARCHAR2(240);
6885 --
6886 l_acct_reversal_source      VARCHAR2(30);
6887 l_trx_reversal_source       VARCHAR2(30);
6888 
6889 l_continue_with_lines       BOOLEAN := TRUE;
6890 --
6891 l_acc_rev_gl_date_source    DATE;                      -- 4262811
6892 --
6893 type t_array_event_id is table of number index by binary_integer;
6894 
6895 l_rec_array_event                    t_rec_array_event;
6896 l_null_rec_array_event               t_rec_array_event;
6897 l_array_ae_header_id                 xla_number_array_type;
6898 l_actual_flag                        VARCHAR2(1) := NULL;
6899 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
6900 l_balance_type_code                  VARCHAR2(1) :=NULL;
6901 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
6902 
6903 --
6904 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
6905 --
6906 
6907 TYPE t_array_source_1 IS TABLE OF DPP_XLA_INV_HEADERS_V.PP_TXN_NUMBER%TYPE INDEX BY BINARY_INTEGER;
6908 TYPE t_array_source_4 IS TABLE OF DPP_XLA_INV_HEADERS_V.PP_ACCRUAL_CCID%TYPE INDEX BY BINARY_INTEGER;
6909 TYPE t_array_source_8 IS TABLE OF DPP_XLA_INV_HEADERS_V.PP_COST_ADJ_CCID%TYPE INDEX BY BINARY_INTEGER;
6910 TYPE t_array_source_10 IS TABLE OF DPP_XLA_INV_HEADERS_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
6911 TYPE t_array_source_18 IS TABLE OF DPP_XLA_INV_HEADERS_V.TRANSFER_TO_GL_INDICATOR%TYPE INDEX BY BINARY_INTEGER;
6912 
6913 TYPE t_array_source_3 IS TABLE OF DPP_XLA_INV_LINES_V.ITEM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
6914 TYPE t_array_source_9 IS TABLE OF DPP_XLA_INV_LINES_V.DISTRIBUTION_IDENTIFIER%TYPE INDEX BY BINARY_INTEGER;
6915 TYPE t_array_source_11 IS TABLE OF DPP_XLA_INV_LINES_V.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
6916 TYPE t_array_source_12 IS TABLE OF DPP_XLA_INV_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
6917 TYPE t_array_source_13 IS TABLE OF DPP_XLA_INV_LINES_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
6918 
6919 l_array_source_1              t_array_source_1;
6920 l_array_source_4              t_array_source_4;
6921 l_array_source_8              t_array_source_8;
6922 l_array_source_10              t_array_source_10;
6923 l_array_source_18              t_array_source_18;
6924 
6925 l_array_source_3      t_array_source_3;
6926 l_array_source_9      t_array_source_9;
6927 l_array_source_11      t_array_source_11;
6928 l_array_source_12      t_array_source_12;
6929 l_array_source_13      t_array_source_13;
6930 
6931 --
6932 CURSOR header_cur
6933 IS
6934 SELECT /*+ leading(xet) cardinality(xet,1) */
6935 -- Event Class Code: COST_UPDATE
6936     xet.entity_id
6937    ,xet.legal_entity_id
6938    ,xet.entity_code
6939    ,xet.transaction_number
6940    ,xet.event_id
6941    ,xet.event_class_code
6942    ,xet.event_type_code
6943    ,xet.event_number
6944    ,xet.event_date
6945    ,xet.transaction_date
6946    ,xet.reference_num_1
6947    ,xet.reference_num_2
6948    ,xet.reference_num_3
6949    ,xet.reference_num_4
6950    ,xet.reference_char_1
6951    ,xet.reference_char_2
6952    ,xet.reference_char_3
6953    ,xet.reference_char_4
6954    ,xet.reference_date_1
6955    ,xet.reference_date_2
6956    ,xet.reference_date_3
6957    ,xet.reference_date_4
6958    ,xet.event_created_by
6959    ,xet.budgetary_control_flag 
6960   , h1.PP_TXN_NUMBER    source_1
6961   , h1.PP_ACCRUAL_CCID    source_4
6962   , h1.PP_COST_ADJ_CCID    source_8
6963   , h1.DISTRIBUTION_TYPE    source_10
6964   , h1.TRANSFER_TO_GL_INDICATOR    source_18
6965   FROM xla_events_gt     xet 
6966   , DPP_XLA_INV_HEADERS_V  h1
6967  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
6968    and xet.event_class_code = C_EVENT_CLASS_CODE
6969    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
6970 
6971  ORDER BY event_id
6972 ;
6973 
6974 
6975 --
6976 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
6977 IS
6978 SELECT  /*+ leading(xet) cardinality(xet,1) */
6979 -- Event Class Code: COST_UPDATE
6980     xet.entity_id
6981    ,xet.legal_entity_id
6982    ,xet.entity_code
6983    ,xet.transaction_number
6984    ,xet.event_id
6985    ,xet.event_class_code
6986    ,xet.event_type_code
6987    ,xet.event_number
6988    ,xet.event_date
6989    ,xet.transaction_date
6990    ,xet.reference_num_1
6991    ,xet.reference_num_2
6992    ,xet.reference_num_3
6996    ,xet.reference_char_3
6993    ,xet.reference_num_4
6994    ,xet.reference_char_1
6995    ,xet.reference_char_2
6997    ,xet.reference_char_4
6998    ,xet.reference_date_1
6999    ,xet.reference_date_2
7000    ,xet.reference_date_3
7001    ,xet.reference_date_4
7002    ,xet.event_created_by
7003    ,xet.budgetary_control_flag
7004  , l2.LINE_NUMBER  
7005   , l2.ITEM_NUMBER    source_3
7006   , l2.DISTRIBUTION_IDENTIFIER    source_9
7007   , l2.ENTERED_AMOUNT    source_11
7008   , l2.CURRENCY_CODE    source_12
7009   , l2.ACCOUNTED_AMOUNT    source_13
7010   FROM xla_events_gt     xet 
7011   , DPP_XLA_INV_LINES_V  l2
7012  WHERE xet.event_id between x_first_event_id and x_last_event_id
7013    and xet.event_date between p_pad_start_date and p_pad_end_date
7014    and xet.event_class_code = C_EVENT_CLASS_CODE
7015    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
7016 ;
7017 
7018 --
7019 BEGIN
7020 IF g_log_enabled THEN
7021    l_log_module := C_DEFAULT_MODULE||'.EventClass_18';
7022 END IF;
7023 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7024    trace
7025       (p_msg      => 'BEGIN of EventClass_18'
7026       ,p_level    => C_LEVEL_PROCEDURE
7027       ,p_module   => l_log_module);
7028 END IF;
7029 
7030 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7031    trace
7032       (p_msg      => 'p_application_id = '||p_application_id||
7033                      ' - p_base_ledger_id = '||p_base_ledger_id||
7034                      ' - p_target_ledger_id  = '||p_target_ledger_id||
7035                      ' - p_language = '||p_language||
7036                      ' - p_currency_code = '||p_currency_code||
7037                      ' - p_sla_ledger_id = '||p_sla_ledger_id
7038       ,p_level    => C_LEVEL_STATEMENT
7039       ,p_module   => l_log_module);
7040 END IF;
7041 --
7042 -- initialze arrays
7043 --
7044 g_array_event.DELETE;
7045 l_rec_array_event := l_null_rec_array_event;
7046 --
7047 --------------------------------------
7048 -- 4262811 Initialze MPA Line Number
7049 --------------------------------------
7050 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
7051 
7052 --
7053 
7054 --
7055 OPEN header_cur;
7056 --
7057 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7058    trace
7059    (p_msg      => 'SQL - FETCH header_cur'
7060    ,p_level    => C_LEVEL_STATEMENT
7061    ,p_module   => l_log_module);
7062 END IF;
7063 --
7064 LOOP
7065 FETCH header_cur BULK COLLECT INTO
7066         l_array_entity_id
7067       , l_array_legal_entity_id
7068       , l_array_entity_code
7069       , l_array_transaction_num
7070       , l_array_event_id
7071       , l_array_class_code
7072       , l_array_event_type
7073       , l_array_event_number
7074       , l_array_event_date
7075       , l_array_transaction_date
7076       , l_array_reference_num_1
7077       , l_array_reference_num_2
7078       , l_array_reference_num_3
7079       , l_array_reference_num_4
7080       , l_array_reference_char_1
7081       , l_array_reference_char_2
7082       , l_array_reference_char_3
7083       , l_array_reference_char_4
7084       , l_array_reference_date_1
7085       , l_array_reference_date_2
7086       , l_array_reference_date_3
7087       , l_array_reference_date_4
7088       , l_array_event_created_by
7089       , l_array_budgetary_control_flag 
7090       , l_array_source_1
7091       , l_array_source_4
7092       , l_array_source_8
7093       , l_array_source_10
7094       , l_array_source_18
7095       LIMIT l_rows;
7096 --
7097 IF (C_LEVEL_EVENT >= g_log_level) THEN
7098    trace
7099    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
7100    ,p_level    => C_LEVEL_EVENT
7101    ,p_module   => l_log_module);
7102 END IF;
7103 --
7104 EXIT WHEN l_array_entity_id.COUNT = 0;
7105 
7106 -- initialize arrays
7107 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
7108 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
7109 
7110 --
7111 -- Bug 4458708
7112 --
7113 XLA_AE_LINES_PKG.g_LineNumber := 0;
7114 
7115 
7116 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
7117 g_last_hdr_idx := l_array_event_id.LAST;
7118 --
7119 -- loop for the headers. Each iteration is for each header extract row
7120 -- fetched in header cursor
7121 --
7122 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
7123 
7124 --
7125 -- set event info as cache for other routines to refer event attributes
7126 --
7127 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
7128    (p_application_id           => p_application_id
7129    ,p_primary_ledger_id        => p_primary_ledger_id
7130    ,p_base_ledger_id           => p_base_ledger_id
7131    ,p_target_ledger_id         => p_target_ledger_id
7132    ,p_entity_id                => l_array_entity_id(hdr_idx)
7133    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
7134    ,p_entity_code              => l_array_entity_code(hdr_idx)
7135    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
7136    ,p_event_id                 => l_array_event_id(hdr_idx)
7137    ,p_event_class_code         => l_array_class_code(hdr_idx)
7138    ,p_event_type_code          => l_array_event_type(hdr_idx)
7142    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
7139    ,p_event_number             => l_array_event_number(hdr_idx)
7140    ,p_event_date               => l_array_event_date(hdr_idx)
7141    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
7143    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
7144    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
7145    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
7146    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
7147    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
7148    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
7149    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
7150    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
7151    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
7152    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
7153    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
7154    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
7155    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
7156 
7157 --
7158 -- set the status of entry to C_VALID (0)
7159 --
7160 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
7161 
7162 --
7163 -- initialize a row for ae header
7164 --
7165 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
7166 
7167 l_event_id := l_array_event_id(hdr_idx);
7168 
7169 --
7170 -- storing the hdr_idx for event. May be used by line cursor.
7171 --
7172 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
7173 
7174 --
7175 -- store sources from header extract. This can be improved to
7176 -- store only those sources from header extract that may be used in lines
7177 --
7178 
7179 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
7180 g_array_event(l_event_id).array_value_num('source_4') := l_array_source_4(hdr_idx);
7181 g_array_event(l_event_id).array_value_num('source_8') := l_array_source_8(hdr_idx);
7182 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
7183 g_array_event(l_event_id).array_value_char('source_18') := l_array_source_18(hdr_idx);
7184 
7185 --
7186 -- initilaize the status of ae headers for diffrent balance types
7187 -- the status is initialised to C_NOT_CREATED (2)
7188 --
7189 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
7190 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
7191 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
7192 
7193 --
7194 -- call api to validate and store accounting attributes for header
7195 --
7196 
7197 ------------------------------------------------------------
7198 -- Accrual Reversal : to get date for Standard Source (NONE)
7199 ------------------------------------------------------------
7200 l_acc_rev_gl_date_source := NULL;
7201 
7202      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
7203       l_rec_acct_attrs.array_date_value(1) := 
7204 xla_ae_sources_pkg.GetSystemSourceDate(
7205    p_source_code           => 'XLA_TRANSACTION_DATE'
7206  , p_source_type_code      => 'Y'
7207  , p_source_application_id =>  602
7208 );
7209      l_rec_acct_attrs.array_acct_attr_code(2)   := 'GL_TRANSFER_FLAG';
7210       l_rec_acct_attrs.array_char_value(2) := g_array_event(l_event_id).array_value_char('source_18');
7211 
7212 
7213 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
7214 
7215 XLA_AE_HEADER_PKG.SetJeCategoryName;
7216 
7217 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
7218 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
7219 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
7220 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
7221 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
7222 
7223 
7224 -- No header level analytical criteria
7225 
7226 --
7227 --accounting attribute enhancement, bug 3612931
7228 --
7229 l_trx_reversal_source := SUBSTR(NULL, 1,30);
7230 
7231 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
7232    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
7233 
7234    xla_accounting_err_pkg.build_message
7235       (p_appli_s_name            => 'XLA'
7236       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
7237       ,p_token_1                 => 'ACCT_ATTR_NAME'
7238       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
7239       ,p_token_2                 => 'PRODUCT_NAME'
7240       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
7241       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
7242       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
7243       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
7244 
7245 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
7246    --
7247    -- following sets the accounting attributes needed to reverse
7248    -- accounting for a distributeion
7249    --
7250    xla_ae_lines_pkg.SetTrxReversalAttrs
7251       (p_event_id              => l_event_id
7255 END IF;
7252       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
7253       ,p_trx_reversal_source   => l_trx_reversal_source);
7254 
7256 
7257 
7258 ----------------------------------------------------------------
7259 -- 4262811 -  update the header statuses to invalid in need be
7260 ----------------------------------------------------------------
7261 --
7262 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
7263 
7264 
7265   -----------------------------------------------
7266   -- No accrual reversal for the event class/type
7267   -----------------------------------------------
7268 ----------------------------------------------------------------
7269 
7270 --
7271 -- this ends the header loop iteration for one bulk fetch
7272 --
7273 END LOOP;
7274 
7275 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
7276 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
7277 
7278 --
7279 -- insert dummy rows into lines gt table that were created due to
7280 -- transaction reversals
7281 --
7282 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
7283    l_result := XLA_AE_LINES_PKG.InsertLines;
7284 END IF;
7285 
7286 --
7287 -- reset the temp_line_num for each set of events fetched from header
7288 -- cursor rather than doing it for each new event in line cursor
7289 -- Bug 3939231
7290 --
7291 xla_ae_lines_pkg.g_temp_line_num := 0;
7292 
7293 
7294 
7295 --
7296 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
7297 --
7298 --
7299 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7300 
7301       trace
7302          (p_msg      => 'SQL - FETCH line_cur'
7303          ,p_level    => C_LEVEL_STATEMENT
7304          ,p_module   => l_log_module);
7305 
7306 END IF;
7307 --
7308 --
7309 LOOP
7310   --
7311   FETCH line_cur BULK COLLECT INTO
7312         l_array_entity_id
7313       , l_array_legal_entity_id
7314       , l_array_entity_code
7315       , l_array_transaction_num
7316       , l_array_event_id
7317       , l_array_class_code
7318       , l_array_event_type
7319       , l_array_event_number
7320       , l_array_event_date
7321       , l_array_transaction_date
7322       , l_array_reference_num_1
7323       , l_array_reference_num_2
7324       , l_array_reference_num_3
7325       , l_array_reference_num_4
7326       , l_array_reference_char_1
7327       , l_array_reference_char_2
7328       , l_array_reference_char_3
7329       , l_array_reference_char_4
7330       , l_array_reference_date_1
7331       , l_array_reference_date_2
7332       , l_array_reference_date_3
7333       , l_array_reference_date_4
7334       , l_array_event_created_by
7335       , l_array_budgetary_control_flag
7336       , l_array_extract_line_num 
7337       , l_array_source_3
7338       , l_array_source_9
7339       , l_array_source_11
7340       , l_array_source_12
7341       , l_array_source_13
7342       LIMIT l_rows;
7343 
7344   --
7345   IF (C_LEVEL_EVENT >= g_log_level) THEN
7346             trace
7347                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
7348                ,p_level    => C_LEVEL_EVENT
7349                ,p_module   => l_log_module);
7350   END IF;
7351   --
7352   EXIT WHEN l_array_entity_id.count = 0;
7353 
7354   XLA_AE_LINES_PKG.g_rec_lines := null;
7355 
7356 --
7357 -- Bug 4458708
7358 --
7359 XLA_AE_LINES_PKG.g_LineNumber := 0;
7360 --
7361 --
7362 
7363 FOR Idx IN 1..l_array_event_id.count LOOP
7364    --
7365    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
7366    --
7367    l_event_id := l_array_event_id(idx);  -- 5648433
7368 
7369    --
7370    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
7371    --
7372 
7373    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
7374              (g_array_event(l_event_id).array_value_num('header_index'))
7375          ,'N'
7376          ) <> 'Y'
7377    THEN
7378       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7379          trace
7380             (p_msg      => 'Trancaction revesal option is not Y '
7381             ,p_level    => C_LEVEL_STATEMENT
7382             ,p_module   => l_log_module);
7383       END IF;
7384 
7385 --
7386 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
7387 --
7388 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
7389 --
7390 -- set event info as cache for other routines to refer event attributes
7391 --
7392 
7393 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
7394    l_previous_event_id := l_event_id;
7395 
7396    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
7397       (p_application_id           => p_application_id
7398       ,p_primary_ledger_id        => p_primary_ledger_id
7399       ,p_base_ledger_id           => p_base_ledger_id
7400       ,p_target_ledger_id         => p_target_ledger_id
7401       ,p_entity_id                => l_array_entity_id(Idx)
7402       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
7403       ,p_entity_code              => l_array_entity_code(Idx)
7407       ,p_event_type_code          => l_array_event_type(Idx)
7404       ,p_transaction_num          => l_array_transaction_num(Idx)
7405       ,p_event_id                 => l_array_event_id(Idx)
7406       ,p_event_class_code         => l_array_class_code(Idx)
7408       ,p_event_number             => l_array_event_number(Idx)
7409       ,p_event_date               => l_array_event_date(Idx)
7410       ,p_transaction_date         => l_array_transaction_date(Idx)
7411       ,p_reference_num_1          => l_array_reference_num_1(Idx)
7412       ,p_reference_num_2          => l_array_reference_num_2(Idx)
7413       ,p_reference_num_3          => l_array_reference_num_3(Idx)
7414       ,p_reference_num_4          => l_array_reference_num_4(Idx)
7415       ,p_reference_char_1         => l_array_reference_char_1(Idx)
7416       ,p_reference_char_2         => l_array_reference_char_2(Idx)
7417       ,p_reference_char_3         => l_array_reference_char_3(Idx)
7418       ,p_reference_char_4         => l_array_reference_char_4(Idx)
7419       ,p_reference_date_1         => l_array_reference_date_1(Idx)
7420       ,p_reference_date_2         => l_array_reference_date_2(Idx)
7421       ,p_reference_date_3         => l_array_reference_date_3(Idx)
7422       ,p_reference_date_4         => l_array_reference_date_4(Idx)
7423       ,p_event_created_by         => l_array_event_created_by(Idx)
7424       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
7425        --
7426 END IF;
7427 
7428 
7429 
7430 --
7431 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
7432 
7433 l_acct_reversal_source := SUBSTR(NULL, 1,30);
7434 
7435 IF l_continue_with_lines THEN
7436    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
7437       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
7438 
7439       xla_accounting_err_pkg.build_message
7440          (p_appli_s_name            => 'XLA'
7441          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
7442          ,p_token_1                 => 'LINE_NUMBER'
7443          ,p_value_1                 => l_array_extract_line_num(Idx)
7444          ,p_token_2                 => 'PRODUCT_NAME'
7445          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
7446          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
7447          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
7448          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
7449 
7450    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
7451       --
7452       -- following sets the accounting attributes needed to reverse
7453       -- accounting for a distributeion
7454       --
7455 
7456       --
7457       -- 5217187
7458       --
7459       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
7460       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
7461                                        g_array_event(l_event_id).array_value_num('header_index'));
7462       --
7463       --
7464 
7465       -- No reversal code generated
7466 
7467       xla_ae_lines_pkg.SetAcctReversalAttrs
7468          (p_event_id             => l_event_id
7469          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
7470          ,p_calculate_acctd_flag => l_calculate_acctd_flag
7471          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
7472    END IF;
7473 
7474    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
7475        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
7476 
7477 --
7478 AcctLineType_8 (
7479  p_application_id  => p_application_id
7480  ,p_event_id     => l_event_id
7481  ,p_calculate_acctd_flag => l_calculate_acctd_flag
7482  ,p_calculate_g_l_flag => l_calculate_g_l_flag
7483  ,p_actual_flag => l_actual_flag
7484  ,p_balance_type_code => l_balance_type_code
7485  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
7486  
7487  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
7488  , p_source_3 => l_array_source_3(Idx)
7489  , p_source_4 => g_array_event(l_event_id).array_value_num('source_4')
7490  , p_source_9 => l_array_source_9(Idx)
7491  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
7492  , p_source_11 => l_array_source_11(Idx)
7493  , p_source_12 => l_array_source_12(Idx)
7494  , p_source_13 => l_array_source_13(Idx)
7495  );
7496 If(l_balance_type_code = 'A') THEN
7497   l_actual_gain_loss_ref := l_gain_or_loss_ref;
7498 END IF;
7499 
7500 --
7501 
7502 
7503 --
7504 AcctLineType_9 (
7505  p_application_id  => p_application_id
7506  ,p_event_id     => l_event_id
7507  ,p_calculate_acctd_flag => l_calculate_acctd_flag
7508  ,p_calculate_g_l_flag => l_calculate_g_l_flag
7509  ,p_actual_flag => l_actual_flag
7510  ,p_balance_type_code => l_balance_type_code
7511  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
7512  
7513  , p_source_8 => g_array_event(l_event_id).array_value_num('source_8')
7514  , p_source_9 => l_array_source_9(Idx)
7515  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
7516  , p_source_11 => l_array_source_11(Idx)
7517  , p_source_12 => l_array_source_12(Idx)
7518  , p_source_13 => l_array_source_13(Idx)
7519  );
7520 If(l_balance_type_code = 'A') THEN
7521   l_actual_gain_loss_ref := l_gain_or_loss_ref;
7522 END IF;
7523 
7527       -- or secondary ledger that has different currency with primary
7524 --
7525 
7526       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
7528       -- or alc that is calculated by sla
7529       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
7530             (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'))
7531 
7532 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
7533 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
7534           AND (l_actual_flag = 'A')) THEN
7535         XLA_AE_LINES_PKG.CreateGainOrLossLines(
7536           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
7537          ,p_application_id   => p_application_id
7538          ,p_amb_context_code => 'DEFAULT'
7539          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
7540          ,p_event_class_code => C_EVENT_CLASS_CODE
7541          ,p_event_type_code  => C_EVENT_TYPE_CODE
7542          
7543          ,p_gain_ccid        => -1
7544          ,p_loss_ccid        => -1
7545 
7546          ,p_actual_flag      => l_actual_flag
7547          ,p_enc_flag         => null
7548          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
7549          ,p_enc_g_l_ref      => null
7550          );
7551       END IF;
7552    END IF;
7553 END IF;
7554 
7555    ELSE
7556       --
7557       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
7558       --
7559       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7560          trace
7561             (p_msg      => 'Trancaction revesal option is Y'
7562             ,p_level    => C_LEVEL_STATEMENT
7563             ,p_module   => l_log_module);
7564       END IF;
7565    END IF;
7566 
7567 END LOOP;
7568 l_result := XLA_AE_LINES_PKG.InsertLines ;
7569 end loop;
7570 close line_cur;
7571 
7572 
7573 --
7574 -- insert headers into xla_ae_headers_gt table
7575 --
7576 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
7577 
7578 -- insert into errors table here.
7579 
7580 END LOOP;
7581 
7582 --
7583 -- 4865292
7584 --
7585 -- Compare g_hdr_extract_count with event count in
7586 -- CreateHeadersAndLines.
7587 --
7588 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
7589 
7590 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7591    trace (p_msg     => '# rows extracted from header extract objects '
7592                     || ' (running total): '
7593                     || g_hdr_extract_count
7594          ,p_level   => C_LEVEL_STATEMENT
7595          ,p_module  => l_log_module);
7596 END IF;
7597 
7598 CLOSE header_cur;
7599 --
7600 
7601 --
7602 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7603    trace
7604       (p_msg      => 'END of EventClass_18'
7605       ,p_level    => C_LEVEL_PROCEDURE
7606       ,p_module   => l_log_module);
7607 END IF;
7608 --
7609 RETURN l_result;
7610 EXCEPTION
7611 WHEN xla_exceptions_pkg.application_exception THEN
7612    
7613 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
7614 
7615    
7616 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
7617 
7618    RAISE;
7619 
7620 WHEN NO_DATA_FOUND THEN
7621 
7622 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
7623 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
7624 
7625 FOR header_record IN header_cur
7626 LOOP
7627     l_array_header_events(header_record.event_id) := header_record.event_id;
7628 END LOOP;
7629 
7630 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
7631 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
7632 
7633 fnd_file.put_line(fnd_file.LOG, '                    ');
7634 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
7635 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
7636 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
7637 
7638 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
7639 LOOP
7640 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
7641 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
7642         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
7643 	END IF;
7644 END LOOP;
7645 
7646 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
7647 fnd_file.put_line(fnd_file.LOG, '                    ');
7648 
7649 
7650 xla_exceptions_pkg.raise_message
7651       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventClass_18');
7652 
7653 
7654 WHEN OTHERS THEN
7655    xla_exceptions_pkg.raise_message
7656       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventClass_18');
7657 END EventClass_18;
7658 --
7659 
7660 ---------------------------------------
7661 --
7662 -- PRIVATE PROCEDURE
7663 --         insert_sources_19
7664 --
7665 ----------------------------------------
7666 --
7667 PROCEDURE insert_sources_19(
7671                               , p_pad_start_date         IN DATE
7668                                 p_target_ledger_id       IN NUMBER
7669                               , p_language               IN VARCHAR2
7670                               , p_sla_ledger_id          IN NUMBER
7672                               , p_pad_end_date           IN DATE
7673                          )
7674 IS
7675 
7676 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CUST_CLAIM';
7677 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
7678 p_apps_owner                   VARCHAR2(30);
7679 l_log_module                   VARCHAR2(240);
7680 BEGIN
7681 IF g_log_enabled THEN
7682       l_log_module := C_DEFAULT_MODULE||'.insert_sources_19';
7683 END IF;
7684 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7685 
7686       trace
7687          (p_msg      => 'BEGIN of insert_sources_19'
7688          ,p_level    => C_LEVEL_PROCEDURE
7689          ,p_module   => l_log_module);
7690 
7691 END IF;
7692 
7693 -- select APPS owner
7694 SELECT oracle_username
7695   INTO p_apps_owner
7696   FROM fnd_oracle_userid
7697  WHERE read_only_flag = 'U'
7698 ;
7699 
7700 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7701       trace
7702          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
7703                         ' - p_language = '||p_language||
7704                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
7705                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
7706                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
7707                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
7708          ,p_level    => C_LEVEL_STATEMENT
7709          ,p_module   => l_log_module);
7710 END IF;
7711 
7712 
7713 --
7714 INSERT INTO xla_diag_sources --hdr1
7715 (
7716         event_id
7717       , ledger_id
7718       , sla_ledger_id
7719       , description_language
7720       , object_name
7721       , object_type_code
7722       , line_number
7723       , source_application_id
7724       , source_type_code
7725       , source_code
7726       , source_value
7727       , source_meaning
7728       , created_by
7729       , creation_date
7730       , last_update_date
7731       , last_updated_by
7732       , last_update_login
7733       , program_update_date
7734       , program_application_id
7735       , program_id
7736       , request_id
7737 )
7738 SELECT
7739         event_id
7740       , p_target_ledger_id
7741       , p_sla_ledger_id
7742       , p_language
7743       , object_name
7744       , object_type_code
7745       , line_number
7746       , source_application_id
7747       , source_type_code
7748       , source_code
7749       , SUBSTR(source_value ,1,1996)
7750       , SUBSTR(source_meaning,1,200)
7751       , xla_environment_pkg.g_Usr_Id
7752       , TRUNC(SYSDATE)
7753       , TRUNC(SYSDATE)
7754       , xla_environment_pkg.g_Usr_Id
7755       , xla_environment_pkg.g_Login_Id
7756       , TRUNC(SYSDATE)
7757       , xla_environment_pkg.g_Prog_Appl_Id
7758       , xla_environment_pkg.g_Prog_Id
7759       , xla_environment_pkg.g_Req_Id
7760   FROM (
7761        SELECT xet.event_id                  event_id
7762             , 0                             line_number
7763             , CASE r
7764                WHEN 1 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7765                 WHEN 2 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7766                 WHEN 3 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7767                 WHEN 4 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7768                 WHEN 5 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7769                 WHEN 6 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7770                 WHEN 7 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
7771                 
7772                ELSE null
7773               END                           object_name
7774             , CASE r
7775                 WHEN 1 THEN 'HEADER' 
7776                 WHEN 2 THEN 'HEADER' 
7777                 WHEN 3 THEN 'HEADER' 
7778                 WHEN 4 THEN 'HEADER' 
7779                 WHEN 5 THEN 'HEADER' 
7780                 WHEN 6 THEN 'HEADER' 
7781                 WHEN 7 THEN 'HEADER' 
7782                 
7783                 ELSE null
7784               END                           object_type_code
7785             , CASE r
7786                 WHEN 1 THEN '9000' 
7787                 WHEN 2 THEN '9000' 
7788                 WHEN 3 THEN '9000' 
7789                 WHEN 4 THEN '9000' 
7790                 WHEN 5 THEN '9000' 
7791                 WHEN 6 THEN '9000' 
7792                 WHEN 7 THEN '9000' 
7793                 
7794                 ELSE null
7795               END                           source_application_id
7796             , 'S'             source_type_code
7797             , CASE r
7798                 WHEN 1 THEN 'PP_TXN_NUMBER' 
7799                 WHEN 2 THEN 'PP_AR_CLEARING_CCID' 
7800                 WHEN 3 THEN 'PP_CONTRA_LIAB_CCID' 
7801                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
7802                 WHEN 5 THEN 'PARTY_ID' 
7803                 WHEN 6 THEN 'PARTY_SITE_ID' 
7804                 WHEN 7 THEN 'PARTY_TYPE' 
7805                 
7806                 ELSE null
7807               END                           source_code
7808             , CASE r
7809                 WHEN 1 THEN TO_CHAR(h1.PP_TXN_NUMBER)
7810                 WHEN 2 THEN TO_CHAR(h1.PP_AR_CLEARING_CCID)
7814                 WHEN 6 THEN TO_CHAR(h1.PARTY_SITE_ID)
7811                 WHEN 3 THEN TO_CHAR(h1.PP_CONTRA_LIAB_CCID)
7812                 WHEN 4 THEN TO_CHAR(h1.DISTRIBUTION_TYPE)
7813                 WHEN 5 THEN TO_CHAR(h1.PARTY_ID)
7815                 WHEN 7 THEN TO_CHAR(h1.PARTY_TYPE)
7816                 
7817                 ELSE null
7818               END                           source_value
7819             , null              source_meaning
7820         FROM xla_events_gt     xet  
7821       , DPP_XLA_CLAIM_HEADERS_V  h1
7822             ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
7823        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
7824          AND xet.event_type_code = C_EVENT_TYPE_CODE
7825             AND h1.event_id = xet.event_id
7826 
7827 )
7828 ;
7829 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7830 
7831       trace
7832          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
7833          ,p_level    => C_LEVEL_STATEMENT
7834          ,p_module   => l_log_module);
7835 
7836 END IF;
7837 --
7838 
7839 
7840 
7841 --
7842 INSERT INTO xla_diag_sources --line1
7843 (
7844         event_id
7845       , ledger_id
7846       , sla_ledger_id
7847       , description_language
7848       , object_name
7849       , object_type_code
7850       , line_number
7851       , source_application_id
7852       , source_type_code
7853       , source_code
7854       , source_value
7855       , source_meaning
7856       , created_by
7857       , creation_date
7858       , last_update_date
7859       , last_updated_by
7860       , last_update_login
7861       , program_update_date
7862       , program_application_id
7863       , program_id
7864       , request_id
7865 )
7866 SELECT  event_id
7867       , p_target_ledger_id
7868       , p_sla_ledger_id
7869       , p_language
7870       , object_name
7871       , object_type_code
7872       , line_number
7873       , source_application_id
7874       , source_type_code
7875       , source_code
7876       , SUBSTR(source_value,1,1996)
7877       , SUBSTR(source_meaning,1,200)
7878       , xla_environment_pkg.g_Usr_Id
7879       , TRUNC(SYSDATE)
7880       , TRUNC(SYSDATE)
7881       , xla_environment_pkg.g_Usr_Id
7882       , xla_environment_pkg.g_Login_Id
7883       , TRUNC(SYSDATE)
7884       , xla_environment_pkg.g_Prog_Appl_Id
7885       , xla_environment_pkg.g_Prog_Id
7886       , xla_environment_pkg.g_Req_Id
7887   FROM (
7888        SELECT xet.event_id                  event_id
7889             , l2.line_number                 line_number
7890             , CASE r
7891                WHEN 1 THEN 'DPP_XLA_CLAIM_LINES_V' 
7892                 WHEN 2 THEN 'DPP_XLA_CLAIM_LINES_V' 
7893                 WHEN 3 THEN 'DPP_XLA_CLAIM_LINES_V' 
7894                 WHEN 4 THEN 'DPP_XLA_CLAIM_LINES_V' 
7895                 WHEN 5 THEN 'DPP_XLA_CLAIM_LINES_V' 
7896                 WHEN 6 THEN 'DPP_XLA_CLAIM_LINES_V' 
7897                 
7898                ELSE null
7899               END                           object_name
7900             , CASE r
7901                 WHEN 1 THEN 'LINE' 
7902                 WHEN 2 THEN 'LINE' 
7903                 WHEN 3 THEN 'LINE' 
7904                 WHEN 4 THEN 'LINE' 
7905                 WHEN 5 THEN 'LINE' 
7906                 WHEN 6 THEN 'LINE' 
7907                 
7908                 ELSE null
7909               END                           object_type_code
7910             , CASE r
7911                 WHEN 1 THEN '9000' 
7912                 WHEN 2 THEN '9000' 
7913                 WHEN 3 THEN '9000' 
7914                 WHEN 4 THEN '9000' 
7915                 WHEN 5 THEN '9000' 
7916                 WHEN 6 THEN '9000' 
7917                 
7918                 ELSE null
7919               END                           source_application_id
7920             , 'S'             source_type_code
7921             , CASE r
7922                 WHEN 1 THEN 'CLAIM_NUMBER' 
7923                 WHEN 2 THEN 'ITEM_NUMBER' 
7924                 WHEN 3 THEN 'DISTRIBUTION_IDENTIFIER' 
7925                 WHEN 4 THEN 'ENTERED_AMOUNT' 
7926                 WHEN 5 THEN 'CURRENCY_CODE' 
7927                 WHEN 6 THEN 'ACCOUNTED_AMOUNT' 
7928                 
7929                 ELSE null
7930               END                           source_code
7931             , CASE r
7932                 WHEN 1 THEN TO_CHAR(l2.CLAIM_NUMBER)
7933                 WHEN 2 THEN TO_CHAR(l2.ITEM_NUMBER)
7934                 WHEN 3 THEN TO_CHAR(l2.DISTRIBUTION_IDENTIFIER)
7935                 WHEN 4 THEN TO_CHAR(l2.ENTERED_AMOUNT)
7936                 WHEN 5 THEN TO_CHAR(l2.CURRENCY_CODE)
7937                 WHEN 6 THEN TO_CHAR(l2.ACCOUNTED_AMOUNT)
7938                 
7939                 ELSE null
7940               END                           source_value
7941             , null              source_meaning
7942          FROM  xla_events_gt     xet  
7943         , DPP_XLA_CLAIM_LINES_V  l2
7944             ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
7945         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
7946           AND xet.event_type_code = C_EVENT_TYPE_CODE
7947             AND l2.event_id          = xet.event_id
7948 
7949 )
7950 ;
7954       trace
7951 --
7952 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
7953 
7955          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
7956          ,p_level    => C_LEVEL_STATEMENT
7957          ,p_module   => l_log_module);
7958 
7959 END IF;
7960 
7961 
7962 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
7963       trace
7964          (p_msg      => 'END of insert_sources_19'
7965          ,p_level    => C_LEVEL_PROCEDURE
7966          ,p_module   => l_log_module);
7967 END IF;
7968 EXCEPTION
7969   WHEN xla_exceptions_pkg.application_exception THEN
7970       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7971             trace
7972                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
7973                ,p_level    => C_LEVEL_EXCEPTION
7974                ,p_module   => l_log_module);
7975       END IF;
7976       RAISE;
7977   WHEN OTHERS THEN
7978       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
7979             trace
7980                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
7981                ,p_level    => C_LEVEL_EXCEPTION
7982                ,p_module   => l_log_module);
7983        END IF;
7984        xla_exceptions_pkg.raise_message
7985            (p_location => 'XLA_09000_AAD_S_000015_PKG.insert_sources_19');
7986 END insert_sources_19;
7987 --
7988 
7989 ---------------------------------------
7990 --
7991 -- PRIVATE FUNCTION
7992 --         EventType_19
7993 --
7994 ----------------------------------------
7995 --
7996 FUNCTION EventType_19
7997        (p_application_id         IN NUMBER
7998        ,p_base_ledger_id         IN NUMBER
7999        ,p_target_ledger_id       IN NUMBER
8000        ,p_language               IN VARCHAR2
8001        ,p_currency_code          IN VARCHAR2
8002        ,p_sla_ledger_id          IN NUMBER
8003        ,p_pad_start_date         IN DATE
8004        ,p_pad_end_date           IN DATE
8005        ,p_primary_ledger_id      IN NUMBER)
8006 RETURN BOOLEAN IS
8007 --
8008 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'CUST_CLAIM';
8009 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
8010 
8011 l_calculate_acctd_flag   VARCHAR2(1) :='N';
8012 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
8013 --
8014 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8015 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8016 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8017 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8018 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8019 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8020 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8021 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8022 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8023 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8024 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8025 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8026 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8027 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
8028 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8029 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8030 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8031 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
8032 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8033 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8034 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8035 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
8036 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
8037 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
8038 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
8039 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
8040 
8041 l_event_id                             NUMBER;
8042 l_previous_event_id                    NUMBER;
8043 l_first_event_id                       NUMBER;
8044 l_last_event_id                        NUMBER;
8045 
8046 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
8047 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
8048 --
8049 --
8050 l_result                    BOOLEAN := TRUE;
8051 l_rows                      NUMBER  := 1000;
8052 l_event_type_name           VARCHAR2(80) := 'Customer Claim to Distributor';
8053 l_event_class_name          VARCHAR2(80) := 'Claim Settlement';
8054 l_description               VARCHAR2(4000);
8055 l_transaction_reversal      NUMBER;
8056 l_ae_header_id              NUMBER;
8057 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
8058 l_log_module                VARCHAR2(240);
8059 --
8060 l_acct_reversal_source      VARCHAR2(30);
8061 l_trx_reversal_source       VARCHAR2(30);
8062 
8063 l_continue_with_lines       BOOLEAN := TRUE;
8064 --
8065 l_acc_rev_gl_date_source    DATE;                      -- 4262811
8066 --
8070 l_null_rec_array_event               t_rec_array_event;
8067 type t_array_event_id is table of number index by binary_integer;
8068 
8069 l_rec_array_event                    t_rec_array_event;
8071 l_array_ae_header_id                 xla_number_array_type;
8072 l_actual_flag                        VARCHAR2(1) := NULL;
8073 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
8074 l_balance_type_code                  VARCHAR2(1) :=NULL;
8075 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
8076 
8077 --
8078 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
8079 --
8080 
8081 TYPE t_array_source_1 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_TXN_NUMBER%TYPE INDEX BY BINARY_INTEGER;
8082 TYPE t_array_source_6 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_AR_CLEARING_CCID%TYPE INDEX BY BINARY_INTEGER;
8083 TYPE t_array_source_7 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_CONTRA_LIAB_CCID%TYPE INDEX BY BINARY_INTEGER;
8084 TYPE t_array_source_10 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
8085 TYPE t_array_source_14 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
8086 TYPE t_array_source_15 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
8087 TYPE t_array_source_16 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
8088 
8089 TYPE t_array_source_2 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CLAIM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
8090 TYPE t_array_source_3 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ITEM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
8091 TYPE t_array_source_9 IS TABLE OF DPP_XLA_CLAIM_LINES_V.DISTRIBUTION_IDENTIFIER%TYPE INDEX BY BINARY_INTEGER;
8092 TYPE t_array_source_11 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
8093 TYPE t_array_source_12 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
8094 TYPE t_array_source_13 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
8095 
8096 l_array_source_1              t_array_source_1;
8097 l_array_source_6              t_array_source_6;
8098 l_array_source_7              t_array_source_7;
8099 l_array_source_10              t_array_source_10;
8100 l_array_source_14              t_array_source_14;
8101 l_array_source_15              t_array_source_15;
8102 l_array_source_16              t_array_source_16;
8103 
8104 l_array_source_2      t_array_source_2;
8105 l_array_source_3      t_array_source_3;
8106 l_array_source_9      t_array_source_9;
8107 l_array_source_11      t_array_source_11;
8108 l_array_source_12      t_array_source_12;
8109 l_array_source_13      t_array_source_13;
8110 
8111 --
8112 CURSOR header_cur
8113 IS
8114 SELECT /*+ leading(xet) cardinality(xet,1) */
8115 -- Event Type Code: CUST_CLAIM
8116 -- Event Class Code: CLAIM_SETTLEMENT
8117     xet.entity_id
8118   , xet.legal_entity_id
8119   , xet.entity_code
8120   , xet.transaction_number
8121   , xet.event_id
8122   , xet.event_class_code
8123   , xet.event_type_code
8124   , xet.event_number
8125   , xet.event_date
8126   , xet.transaction_date
8127   , xet.reference_num_1
8128   , xet.reference_num_2
8129   , xet.reference_num_3
8130   , xet.reference_num_4
8131   , xet.reference_char_1
8132   , xet.reference_char_2
8133   , xet.reference_char_3
8134   , xet.reference_char_4
8135   , xet.reference_date_1
8136   , xet.reference_date_2
8137   , xet.reference_date_3
8138   , xet.reference_date_4
8139   , xet.event_created_by
8140   , xet.budgetary_control_flag 
8141   , h1.PP_TXN_NUMBER    source_1
8142   , h1.PP_AR_CLEARING_CCID    source_6
8143   , h1.PP_CONTRA_LIAB_CCID    source_7
8144   , h1.DISTRIBUTION_TYPE    source_10
8145   , h1.PARTY_ID    source_14
8146   , h1.PARTY_SITE_ID    source_15
8147   , h1.PARTY_TYPE    source_16
8148   FROM xla_events_gt     xet 
8149   , DPP_XLA_CLAIM_HEADERS_V  h1
8150  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
8151    and xet.event_type_code = C_EVENT_TYPE_CODE
8152    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
8153 
8154  ORDER BY event_id
8155 ;
8156 
8157 
8158 --
8159 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
8160 IS
8161 SELECT /*+ leading(xet) cardinality(xet,1) */
8162 -- Event Type Code: CUST_CLAIM
8163 -- Event Class Code: CLAIM_SETTLEMENT
8164     xet.entity_id
8165    ,xet.legal_entity_id
8166    ,xet.entity_code
8167    ,xet.transaction_number
8168    ,xet.event_id
8169    ,xet.event_class_code
8170    ,xet.event_type_code
8171    ,xet.event_number
8172    ,xet.event_date
8173    ,xet.transaction_date
8174    ,xet.reference_num_1
8175    ,xet.reference_num_2
8176    ,xet.reference_num_3
8177    ,xet.reference_num_4
8178    ,xet.reference_char_1
8179    ,xet.reference_char_2
8180    ,xet.reference_char_3
8181    ,xet.reference_char_4
8182    ,xet.reference_date_1
8183    ,xet.reference_date_2
8184    ,xet.reference_date_3
8185    ,xet.reference_date_4
8186    ,xet.event_created_by
8187    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
8188   , l2.CLAIM_NUMBER    source_2
8189   , l2.ITEM_NUMBER    source_3
8190   , l2.DISTRIBUTION_IDENTIFIER    source_9
8191   , l2.ENTERED_AMOUNT    source_11
8192   , l2.CURRENCY_CODE    source_12
8193   , l2.ACCOUNTED_AMOUNT    source_13
8194   FROM xla_events_gt     xet 
8195   , DPP_XLA_CLAIM_LINES_V  l2
8199    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
8196  WHERE xet.event_id between x_first_event_id and x_last_event_id
8197    and xet.event_date between p_pad_start_date and p_pad_end_date
8198    and xet.event_type_code = C_EVENT_TYPE_CODE
8200 ;
8201 
8202 --
8203 BEGIN
8204 IF g_log_enabled THEN
8205    l_log_module := C_DEFAULT_MODULE||'.EventType_19';
8206 END IF;
8207 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8208    trace
8209       (p_msg      => 'BEGIN of EventType_19'
8210       ,p_level    => C_LEVEL_PROCEDURE
8211       ,p_module   => l_log_module);
8212 END IF;
8213 
8214 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8215    trace
8216       (p_msg      => 'p_application_id = '||p_application_id||
8217                      ' - p_base_ledger_id = '||p_base_ledger_id||
8218                      ' - p_target_ledger_id  = '||p_target_ledger_id||
8219                      ' - p_language = '||p_language||
8220                      ' - p_currency_code = '||p_currency_code||
8221                      ' - p_sla_ledger_id = '||p_sla_ledger_id
8222       ,p_level    => C_LEVEL_STATEMENT
8223       ,p_module   => l_log_module);
8224 END IF;
8225 --
8226 -- initialze arrays
8227 --
8228 g_array_event.DELETE;
8229 l_rec_array_event := l_null_rec_array_event;
8230 --
8231 --------------------------------------
8232 -- 4262811 Initialze MPA Line Number
8233 --------------------------------------
8234 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
8235 
8236 --
8237 
8238 --
8239 OPEN header_cur;
8240 --
8241 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8242    trace
8243    (p_msg      => 'SQL - FETCH header_cur'
8244    ,p_level    => C_LEVEL_STATEMENT
8245    ,p_module   => l_log_module);
8246 END IF;
8247 --
8248 LOOP
8249 FETCH header_cur BULK COLLECT INTO
8250         l_array_entity_id
8251       , l_array_legal_entity_id
8252       , l_array_entity_code
8253       , l_array_transaction_num
8254       , l_array_event_id
8255       , l_array_class_code
8256       , l_array_event_type
8257       , l_array_event_number
8258       , l_array_event_date
8259       , l_array_transaction_date
8260       , l_array_reference_num_1
8261       , l_array_reference_num_2
8262       , l_array_reference_num_3
8263       , l_array_reference_num_4
8264       , l_array_reference_char_1
8265       , l_array_reference_char_2
8266       , l_array_reference_char_3
8267       , l_array_reference_char_4
8268       , l_array_reference_date_1
8269       , l_array_reference_date_2
8270       , l_array_reference_date_3
8271       , l_array_reference_date_4
8272       , l_array_event_created_by
8273       , l_array_budgetary_control_flag 
8274       , l_array_source_1
8275       , l_array_source_6
8276       , l_array_source_7
8277       , l_array_source_10
8278       , l_array_source_14
8279       , l_array_source_15
8280       , l_array_source_16
8281       LIMIT l_rows;
8282 --
8283 IF (C_LEVEL_EVENT >= g_log_level) THEN
8284    trace
8285    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
8286    ,p_level    => C_LEVEL_EVENT
8287    ,p_module   => l_log_module);
8288 END IF;
8289 --
8290 EXIT WHEN l_array_entity_id.COUNT = 0;
8291 
8292 -- initialize arrays
8293 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
8294 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
8295 
8296 --
8297 -- Bug 4458708
8298 --
8299 XLA_AE_LINES_PKG.g_LineNumber := 0;
8300 
8301 
8302 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
8303 g_last_hdr_idx := l_array_event_id.LAST;
8304 --
8305 -- loop for the headers. Each iteration is for each header extract row
8306 -- fetched in header cursor
8307 --
8308 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
8309 
8310 --
8311 -- set event info as cache for other routines to refer event attributes
8312 --
8313 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
8314    (p_application_id           => p_application_id
8315    ,p_primary_ledger_id        => p_primary_ledger_id
8316    ,p_base_ledger_id           => p_base_ledger_id
8317    ,p_target_ledger_id         => p_target_ledger_id
8318    ,p_entity_id                => l_array_entity_id(hdr_idx)
8319    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
8320    ,p_entity_code              => l_array_entity_code(hdr_idx)
8321    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
8322    ,p_event_id                 => l_array_event_id(hdr_idx)
8323    ,p_event_class_code         => l_array_class_code(hdr_idx)
8324    ,p_event_type_code          => l_array_event_type(hdr_idx)
8325    ,p_event_number             => l_array_event_number(hdr_idx)
8326    ,p_event_date               => l_array_event_date(hdr_idx)
8327    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
8328    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
8329    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
8330    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
8331    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
8332    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
8333    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
8334    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
8338    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
8335    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
8336    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
8337    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
8339    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
8340    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
8341    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
8342 
8343 --
8344 -- set the status of entry to C_VALID (0)
8345 --
8346 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
8347 
8348 --
8349 -- initialize a row for ae header
8350 --
8351 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
8352 
8353 l_event_id := l_array_event_id(hdr_idx);
8354 
8355 --
8356 -- storing the hdr_idx for event. May be used by line cursor.
8357 --
8358 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
8359 
8360 --
8361 -- store sources from header extract. This can be improved to
8362 -- store only those sources from header extract that may be used in lines
8363 --
8364 
8365 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
8366 g_array_event(l_event_id).array_value_num('source_6') := l_array_source_6(hdr_idx);
8367 g_array_event(l_event_id).array_value_num('source_7') := l_array_source_7(hdr_idx);
8368 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
8369 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
8370 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
8371 g_array_event(l_event_id).array_value_char('source_16') := l_array_source_16(hdr_idx);
8372 
8373 --
8374 -- initilaize the status of ae headers for diffrent balance types
8375 -- the status is initialised to C_NOT_CREATED (2)
8376 --
8377 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8378 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8379 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
8380 
8381 --
8382 -- call api to validate and store accounting attributes for header
8383 --
8384 
8385 ------------------------------------------------------------
8386 -- Accrual Reversal : to get date for Standard Source (NONE)
8387 ------------------------------------------------------------
8388 l_acc_rev_gl_date_source := NULL;
8389 
8390      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
8391       l_rec_acct_attrs.array_date_value(1) := 
8392 xla_ae_sources_pkg.GetSystemSourceDate(
8393    p_source_code           => 'XLA_TRANSACTION_DATE'
8394  , p_source_type_code      => 'Y'
8395  , p_source_application_id =>  602
8396 );
8397 
8398 
8399 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
8400 
8401 XLA_AE_HEADER_PKG.SetJeCategoryName;
8402 
8403 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
8404 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
8405 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
8406 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
8407 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
8408 
8409 
8410 -- No header level analytical criteria
8411 
8412 --
8413 --accounting attribute enhancement, bug 3612931
8414 --
8415 l_trx_reversal_source := SUBSTR(NULL, 1,30);
8416 
8417 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
8418    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
8419 
8420    xla_accounting_err_pkg.build_message
8421       (p_appli_s_name            => 'XLA'
8422       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
8423       ,p_token_1                 => 'ACCT_ATTR_NAME'
8424       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
8425       ,p_token_2                 => 'PRODUCT_NAME'
8426       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
8427       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
8428       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
8429       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
8430 
8431 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
8432    --
8433    -- following sets the accounting attributes needed to reverse
8434    -- accounting for a distributeion
8435    --
8436    xla_ae_lines_pkg.SetTrxReversalAttrs
8437       (p_event_id              => l_event_id
8438       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
8439       ,p_trx_reversal_source   => l_trx_reversal_source);
8440 
8441 END IF;
8442 
8443 
8444 ----------------------------------------------------------------
8445 -- 4262811 -  update the header statuses to invalid in need be
8446 ----------------------------------------------------------------
8447 --
8448 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
8449 
8450 
8451   -----------------------------------------------
8452   -- No accrual reversal for the event class/type
8456 --
8453   -----------------------------------------------
8454 ----------------------------------------------------------------
8455 
8457 -- this ends the header loop iteration for one bulk fetch
8458 --
8459 END LOOP;
8460 
8461 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
8462 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
8463 
8464 --
8465 -- insert dummy rows into lines gt table that were created due to
8466 -- transaction reversals
8467 --
8468 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
8469    l_result := XLA_AE_LINES_PKG.InsertLines;
8470 END IF;
8471 
8472 --
8473 -- reset the temp_line_num for each set of events fetched from header
8474 -- cursor rather than doing it for each new event in line cursor
8475 -- Bug 3939231
8476 --
8477 xla_ae_lines_pkg.g_temp_line_num := 0;
8478 
8479 
8480 
8481 --
8482 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
8483 --
8484 --
8485 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8486 
8487       trace
8488          (p_msg      => 'SQL - FETCH line_cur'
8489          ,p_level    => C_LEVEL_STATEMENT
8490          ,p_module   => l_log_module);
8491 
8492 END IF;
8493 --
8494 --
8495 LOOP
8496   --
8497   FETCH line_cur BULK COLLECT INTO
8498         l_array_entity_id
8499       , l_array_legal_entity_id
8500       , l_array_entity_code
8501       , l_array_transaction_num
8502       , l_array_event_id
8503       , l_array_class_code
8504       , l_array_event_type
8505       , l_array_event_number
8506       , l_array_event_date
8507       , l_array_transaction_date
8508       , l_array_reference_num_1
8509       , l_array_reference_num_2
8510       , l_array_reference_num_3
8511       , l_array_reference_num_4
8512       , l_array_reference_char_1
8513       , l_array_reference_char_2
8514       , l_array_reference_char_3
8515       , l_array_reference_char_4
8516       , l_array_reference_date_1
8517       , l_array_reference_date_2
8518       , l_array_reference_date_3
8519       , l_array_reference_date_4
8520       , l_array_event_created_by
8521       , l_array_budgetary_control_flag
8522       , l_array_extract_line_num 
8523       , l_array_source_2
8524       , l_array_source_3
8525       , l_array_source_9
8526       , l_array_source_11
8527       , l_array_source_12
8528       , l_array_source_13
8529       LIMIT l_rows;
8530 
8531   --
8532   IF (C_LEVEL_EVENT >= g_log_level) THEN
8533             trace
8534                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
8535                ,p_level    => C_LEVEL_EVENT
8536                ,p_module   => l_log_module);
8537   END IF;
8538   --
8539   EXIT WHEN l_array_entity_id.count = 0;
8540 
8541   XLA_AE_LINES_PKG.g_rec_lines := null;
8542 
8543 --
8544 -- Bug 4458708
8545 --
8546 XLA_AE_LINES_PKG.g_LineNumber := 0;
8547 --
8548 --
8549 
8550 FOR Idx IN 1..l_array_event_id.count LOOP
8551    --
8552    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
8553    --
8554    l_event_id := l_array_event_id(idx);  -- 5648433
8555 
8556    --
8557    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
8558    --
8559 
8560    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
8561              (g_array_event(l_event_id).array_value_num('header_index'))
8562          ,'N'
8563          ) <> 'Y'
8564    THEN
8565       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8566          trace
8567             (p_msg      => 'Trancaction revesal option is not Y '
8568             ,p_level    => C_LEVEL_STATEMENT
8569             ,p_module   => l_log_module);
8570       END IF;
8571 
8572 --
8573 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
8574 --
8575 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
8576 --
8577 -- set event info as cache for other routines to refer event attributes
8578 --
8579 
8580 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
8581    l_previous_event_id := l_event_id;
8582 
8583    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
8584       (p_application_id           => p_application_id
8585       ,p_primary_ledger_id        => p_primary_ledger_id
8586       ,p_base_ledger_id           => p_base_ledger_id
8587       ,p_target_ledger_id         => p_target_ledger_id
8588       ,p_entity_id                => l_array_entity_id(Idx)
8589       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
8590       ,p_entity_code              => l_array_entity_code(Idx)
8591       ,p_transaction_num          => l_array_transaction_num(Idx)
8592       ,p_event_id                 => l_array_event_id(Idx)
8593       ,p_event_class_code         => l_array_class_code(Idx)
8594       ,p_event_type_code          => l_array_event_type(Idx)
8595       ,p_event_number             => l_array_event_number(Idx)
8596       ,p_event_date               => l_array_event_date(Idx)
8597       ,p_transaction_date         => l_array_transaction_date(Idx)
8598       ,p_reference_num_1          => l_array_reference_num_1(Idx)
8599       ,p_reference_num_2          => l_array_reference_num_2(Idx)
8603       ,p_reference_char_2         => l_array_reference_char_2(Idx)
8600       ,p_reference_num_3          => l_array_reference_num_3(Idx)
8601       ,p_reference_num_4          => l_array_reference_num_4(Idx)
8602       ,p_reference_char_1         => l_array_reference_char_1(Idx)
8604       ,p_reference_char_3         => l_array_reference_char_3(Idx)
8605       ,p_reference_char_4         => l_array_reference_char_4(Idx)
8606       ,p_reference_date_1         => l_array_reference_date_1(Idx)
8607       ,p_reference_date_2         => l_array_reference_date_2(Idx)
8608       ,p_reference_date_3         => l_array_reference_date_3(Idx)
8609       ,p_reference_date_4         => l_array_reference_date_4(Idx)
8610       ,p_event_created_by         => l_array_event_created_by(Idx)
8611       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
8612        --
8613 END IF;
8614 
8615 
8616 
8617 --
8618 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
8619 
8620 l_acct_reversal_source := SUBSTR(NULL, 1,30);
8621 
8622 IF l_continue_with_lines THEN
8623    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
8624       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
8625 
8626       xla_accounting_err_pkg.build_message
8627          (p_appli_s_name            => 'XLA'
8628          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
8629          ,p_token_1                 => 'LINE_NUMBER'
8630          ,p_value_1                 => l_array_extract_line_num(Idx)
8631          ,p_token_2                 => 'PRODUCT_NAME'
8632          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
8633          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
8634          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
8635          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
8636 
8637    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
8638       --
8639       -- following sets the accounting attributes needed to reverse
8640       -- accounting for a distributeion
8641       --
8642 
8643       --
8644       -- 5217187
8645       --
8646       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
8647       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
8648                                        g_array_event(l_event_id).array_value_num('header_index'));
8649       --
8650       --
8651 
8652       -- No reversal code generated
8653 
8654       xla_ae_lines_pkg.SetAcctReversalAttrs
8655          (p_event_id             => l_event_id
8656          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
8657          ,p_calculate_acctd_flag => l_calculate_acctd_flag
8658          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
8659    END IF;
8660 
8661    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
8662        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
8663 
8664 --
8665 AcctLineType_10 (
8666  p_application_id  => p_application_id
8667  ,p_event_id     => l_event_id
8668  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8669  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8670  ,p_actual_flag => l_actual_flag
8671  ,p_balance_type_code => l_balance_type_code
8672  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8673  
8674  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
8675  , p_source_2 => l_array_source_2(Idx)
8676  , p_source_3 => l_array_source_3(Idx)
8677  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
8678  , p_source_9 => l_array_source_9(Idx)
8679  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
8680  , p_source_11 => l_array_source_11(Idx)
8681  , p_source_12 => l_array_source_12(Idx)
8682  , p_source_13 => l_array_source_13(Idx)
8683  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
8684  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
8685  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
8686  );
8687 If(l_balance_type_code = 'A') THEN
8688   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8689 END IF;
8690 
8691 --
8692 
8693 
8694 --
8695 AcctLineType_11 (
8696  p_application_id  => p_application_id
8697  ,p_event_id     => l_event_id
8698  ,p_calculate_acctd_flag => l_calculate_acctd_flag
8699  ,p_calculate_g_l_flag => l_calculate_g_l_flag
8700  ,p_actual_flag => l_actual_flag
8701  ,p_balance_type_code => l_balance_type_code
8702  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
8703  
8704  , p_source_7 => g_array_event(l_event_id).array_value_num('source_7')
8705  , p_source_9 => l_array_source_9(Idx)
8706  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
8707  , p_source_11 => l_array_source_11(Idx)
8708  , p_source_12 => l_array_source_12(Idx)
8709  , p_source_13 => l_array_source_13(Idx)
8710  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
8711  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
8712  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
8713  );
8714 If(l_balance_type_code = 'A') THEN
8715   l_actual_gain_loss_ref := l_gain_or_loss_ref;
8716 END IF;
8717 
8718 --
8719 
8723       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
8720       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
8721       -- or secondary ledger that has different currency with primary
8722       -- or alc that is calculated by sla
8724             (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'))
8725 
8726 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
8727 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
8728           AND (l_actual_flag = 'A')) THEN
8729         XLA_AE_LINES_PKG.CreateGainOrLossLines(
8730           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
8731          ,p_application_id   => p_application_id
8732          ,p_amb_context_code => 'DEFAULT'
8733          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
8734          ,p_event_class_code => C_EVENT_CLASS_CODE
8735          ,p_event_type_code  => C_EVENT_TYPE_CODE
8736          
8737          ,p_gain_ccid        => -1
8738          ,p_loss_ccid        => -1
8739 
8740          ,p_actual_flag      => l_actual_flag
8741          ,p_enc_flag         => null
8742          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
8743          ,p_enc_g_l_ref      => null
8744          );
8745       END IF;
8746    END IF;
8747 END IF;
8748 
8749    ELSE
8750       --
8751       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
8752       --
8753       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8754          trace
8755             (p_msg      => 'Trancaction revesal option is Y'
8756             ,p_level    => C_LEVEL_STATEMENT
8757             ,p_module   => l_log_module);
8758       END IF;
8759    END IF;
8760 
8761 END LOOP;
8762 l_result := XLA_AE_LINES_PKG.InsertLines ;
8763 end loop;
8764 close line_cur;
8765 
8766 
8767 --
8768 -- insert headers into xla_ae_headers_gt table
8769 --
8770 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
8771 
8772 -- insert into errors table here.
8773 
8774 END LOOP;
8775 
8776 --
8777 -- 4865292
8778 --
8779 -- Compare g_hdr_extract_count with event count in
8780 -- CreateHeadersAndLines.
8781 --
8782 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
8783 
8784 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8785    trace (p_msg     => '# rows extracted from header extract objects '
8786                     || ' (running total): '
8787                     || g_hdr_extract_count
8788          ,p_level   => C_LEVEL_STATEMENT
8789          ,p_module  => l_log_module);
8790 END IF;
8791 
8792 CLOSE header_cur;
8793 --
8794 
8795 --
8796 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8797    trace
8798       (p_msg      => 'END of EventType_19'
8799       ,p_level    => C_LEVEL_PROCEDURE
8800       ,p_module   => l_log_module);
8801 END IF;
8802 --
8803 RETURN l_result;
8804 EXCEPTION
8805 WHEN xla_exceptions_pkg.application_exception THEN
8806    
8807 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
8808 
8809    
8810 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
8811 
8812    RAISE;
8813 
8814 WHEN NO_DATA_FOUND THEN
8815 
8816 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
8817 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
8818 
8819 FOR header_record IN header_cur
8820 LOOP
8821     l_array_header_events(header_record.event_id) := header_record.event_id;
8822 END LOOP;
8823 
8824 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
8825 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
8826 
8827 fnd_file.put_line(fnd_file.LOG, '                    ');
8828 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
8829 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
8830 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
8831 
8832 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
8833 LOOP
8834 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
8835 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
8836         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
8837 	END IF;
8838 END LOOP;
8839 
8840 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
8841 fnd_file.put_line(fnd_file.LOG, '                    ');
8842 
8843 
8844 xla_exceptions_pkg.raise_message
8845       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_19');
8846 
8847 
8848 WHEN OTHERS THEN
8849    xla_exceptions_pkg.raise_message
8850       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_19');
8851 END EventType_19;
8852 --
8853 
8854 ---------------------------------------
8855 --
8856 -- PRIVATE PROCEDURE
8857 --         insert_sources_20
8858 --
8859 ----------------------------------------
8863                               , p_language               IN VARCHAR2
8860 --
8861 PROCEDURE insert_sources_20(
8862                                 p_target_ledger_id       IN NUMBER
8864                               , p_sla_ledger_id          IN NUMBER
8865                               , p_pad_start_date         IN DATE
8866                               , p_pad_end_date           IN DATE
8867                          )
8868 IS
8869 
8870 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_CUST_CLAIM';
8871 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
8872 p_apps_owner                   VARCHAR2(30);
8873 l_log_module                   VARCHAR2(240);
8874 BEGIN
8875 IF g_log_enabled THEN
8876       l_log_module := C_DEFAULT_MODULE||'.insert_sources_20';
8877 END IF;
8878 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
8879 
8880       trace
8881          (p_msg      => 'BEGIN of insert_sources_20'
8882          ,p_level    => C_LEVEL_PROCEDURE
8883          ,p_module   => l_log_module);
8884 
8885 END IF;
8886 
8887 -- select APPS owner
8888 SELECT oracle_username
8889   INTO p_apps_owner
8890   FROM fnd_oracle_userid
8891  WHERE read_only_flag = 'U'
8892 ;
8893 
8894 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
8895       trace
8896          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
8897                         ' - p_language = '||p_language||
8898                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
8899                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
8900                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
8901                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
8902          ,p_level    => C_LEVEL_STATEMENT
8903          ,p_module   => l_log_module);
8904 END IF;
8905 
8906 
8907 --
8908 INSERT INTO xla_diag_sources --hdr1
8909 (
8910         event_id
8911       , ledger_id
8912       , sla_ledger_id
8913       , description_language
8914       , object_name
8915       , object_type_code
8916       , line_number
8917       , source_application_id
8918       , source_type_code
8919       , source_code
8920       , source_value
8921       , source_meaning
8922       , created_by
8923       , creation_date
8924       , last_update_date
8925       , last_updated_by
8926       , last_update_login
8927       , program_update_date
8928       , program_application_id
8929       , program_id
8930       , request_id
8931 )
8932 SELECT
8933         event_id
8934       , p_target_ledger_id
8935       , p_sla_ledger_id
8936       , p_language
8937       , object_name
8938       , object_type_code
8939       , line_number
8940       , source_application_id
8941       , source_type_code
8942       , source_code
8943       , SUBSTR(source_value ,1,1996)
8944       , SUBSTR(source_meaning,1,200)
8945       , xla_environment_pkg.g_Usr_Id
8946       , TRUNC(SYSDATE)
8947       , TRUNC(SYSDATE)
8948       , xla_environment_pkg.g_Usr_Id
8949       , xla_environment_pkg.g_Login_Id
8950       , TRUNC(SYSDATE)
8951       , xla_environment_pkg.g_Prog_Appl_Id
8952       , xla_environment_pkg.g_Prog_Id
8953       , xla_environment_pkg.g_Req_Id
8954   FROM (
8955        SELECT xet.event_id                  event_id
8956             , 0                             line_number
8957             , CASE r
8958                WHEN 1 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8959                 WHEN 2 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8960                 WHEN 3 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8961                 WHEN 4 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8962                 WHEN 5 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8963                 WHEN 6 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
8964                 
8965                ELSE null
8966               END                           object_name
8967             , CASE r
8968                 WHEN 1 THEN 'HEADER' 
8969                 WHEN 2 THEN 'HEADER' 
8970                 WHEN 3 THEN 'HEADER' 
8971                 WHEN 4 THEN 'HEADER' 
8972                 WHEN 5 THEN 'HEADER' 
8973                 WHEN 6 THEN 'HEADER' 
8974                 
8975                 ELSE null
8976               END                           object_type_code
8977             , CASE r
8978                 WHEN 1 THEN '9000' 
8979                 WHEN 2 THEN '9000' 
8980                 WHEN 3 THEN '9000' 
8981                 WHEN 4 THEN '9000' 
8982                 WHEN 5 THEN '9000' 
8983                 WHEN 6 THEN '9000' 
8984                 
8985                 ELSE null
8986               END                           source_application_id
8987             , 'S'             source_type_code
8988             , CASE r
8989                 WHEN 1 THEN 'PP_AP_CLEARING_CCID' 
8990                 WHEN 2 THEN 'PP_CONTRA_LIAB_CCID' 
8991                 WHEN 3 THEN 'DISTRIBUTION_TYPE' 
8992                 WHEN 4 THEN 'PARTY_ID' 
8993                 WHEN 5 THEN 'PARTY_SITE_ID' 
8994                 WHEN 6 THEN 'PARTY_TYPE' 
8995                 
8996                 ELSE null
8997               END                           source_code
8998             , CASE r
8999                 WHEN 1 THEN TO_CHAR(h1.PP_AP_CLEARING_CCID)
9000                 WHEN 2 THEN TO_CHAR(h1.PP_CONTRA_LIAB_CCID)
9001                 WHEN 3 THEN TO_CHAR(h1.DISTRIBUTION_TYPE)
9002                 WHEN 4 THEN TO_CHAR(h1.PARTY_ID)
9003                 WHEN 5 THEN TO_CHAR(h1.PARTY_SITE_ID)
9004                 WHEN 6 THEN TO_CHAR(h1.PARTY_TYPE)
9005                 
9006                 ELSE null
9007               END                           source_value
9008             , null              source_meaning
9009         FROM xla_events_gt     xet  
9010       , DPP_XLA_CLAIM_HEADERS_V  h1
9011             ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
9012        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
9013          AND xet.event_type_code = C_EVENT_TYPE_CODE
9014             AND h1.event_id = xet.event_id
9015 
9016 )
9017 ;
9018 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9019 
9020       trace
9021          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
9022          ,p_level    => C_LEVEL_STATEMENT
9023          ,p_module   => l_log_module);
9024 
9025 END IF;
9026 --
9027 
9028 
9029 
9030 --
9031 INSERT INTO xla_diag_sources --line1
9032 (
9033         event_id
9034       , ledger_id
9035       , sla_ledger_id
9036       , description_language
9037       , object_name
9038       , object_type_code
9039       , line_number
9040       , source_application_id
9041       , source_type_code
9042       , source_code
9043       , source_value
9044       , source_meaning
9045       , created_by
9046       , creation_date
9047       , last_update_date
9048       , last_updated_by
9049       , last_update_login
9050       , program_update_date
9051       , program_application_id
9052       , program_id
9053       , request_id
9054 )
9055 SELECT  event_id
9056       , p_target_ledger_id
9057       , p_sla_ledger_id
9058       , p_language
9059       , object_name
9060       , object_type_code
9061       , line_number
9062       , source_application_id
9063       , source_type_code
9064       , source_code
9065       , SUBSTR(source_value,1,1996)
9066       , SUBSTR(source_meaning,1,200)
9067       , xla_environment_pkg.g_Usr_Id
9068       , TRUNC(SYSDATE)
9069       , TRUNC(SYSDATE)
9070       , xla_environment_pkg.g_Usr_Id
9071       , xla_environment_pkg.g_Login_Id
9072       , TRUNC(SYSDATE)
9073       , xla_environment_pkg.g_Prog_Appl_Id
9074       , xla_environment_pkg.g_Prog_Id
9075       , xla_environment_pkg.g_Req_Id
9076   FROM (
9077        SELECT xet.event_id                  event_id
9078             , l2.line_number                 line_number
9079             , CASE r
9080                WHEN 1 THEN 'DPP_XLA_CLAIM_LINES_V' 
9081                 WHEN 2 THEN 'DPP_XLA_CLAIM_LINES_V' 
9082                 WHEN 3 THEN 'DPP_XLA_CLAIM_LINES_V' 
9083                 WHEN 4 THEN 'DPP_XLA_CLAIM_LINES_V' 
9084                 
9085                ELSE null
9086               END                           object_name
9087             , CASE r
9088                 WHEN 1 THEN 'LINE' 
9089                 WHEN 2 THEN 'LINE' 
9090                 WHEN 3 THEN 'LINE' 
9091                 WHEN 4 THEN 'LINE' 
9092                 
9093                 ELSE null
9094               END                           object_type_code
9095             , CASE r
9096                 WHEN 1 THEN '9000' 
9097                 WHEN 2 THEN '9000' 
9098                 WHEN 3 THEN '9000' 
9099                 WHEN 4 THEN '9000' 
9100                 
9101                 ELSE null
9102               END                           source_application_id
9103             , 'S'             source_type_code
9107                 WHEN 3 THEN 'CURRENCY_CODE' 
9104             , CASE r
9105                 WHEN 1 THEN 'DISTRIBUTION_IDENTIFIER' 
9106                 WHEN 2 THEN 'ENTERED_AMOUNT' 
9108                 WHEN 4 THEN 'ACCOUNTED_AMOUNT' 
9109                 
9110                 ELSE null
9111               END                           source_code
9112             , CASE r
9113                 WHEN 1 THEN TO_CHAR(l2.DISTRIBUTION_IDENTIFIER)
9114                 WHEN 2 THEN TO_CHAR(l2.ENTERED_AMOUNT)
9115                 WHEN 3 THEN TO_CHAR(l2.CURRENCY_CODE)
9116                 WHEN 4 THEN TO_CHAR(l2.ACCOUNTED_AMOUNT)
9117                 
9118                 ELSE null
9119               END                           source_value
9120             , null              source_meaning
9121          FROM  xla_events_gt     xet  
9122         , DPP_XLA_CLAIM_LINES_V  l2
9123             ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
9124         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
9125           AND xet.event_type_code = C_EVENT_TYPE_CODE
9126             AND l2.event_id          = xet.event_id
9127 
9128 )
9129 ;
9130 --
9131 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9132 
9133       trace
9134          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
9135          ,p_level    => C_LEVEL_STATEMENT
9136          ,p_module   => l_log_module);
9137 
9138 END IF;
9139 
9140 
9141 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9142       trace
9143          (p_msg      => 'END of insert_sources_20'
9144          ,p_level    => C_LEVEL_PROCEDURE
9145          ,p_module   => l_log_module);
9146 END IF;
9147 EXCEPTION
9148   WHEN xla_exceptions_pkg.application_exception THEN
9149       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9150             trace
9151                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
9152                ,p_level    => C_LEVEL_EXCEPTION
9153                ,p_module   => l_log_module);
9154       END IF;
9155       RAISE;
9156   WHEN OTHERS THEN
9157       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
9158             trace
9159                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
9160                ,p_level    => C_LEVEL_EXCEPTION
9161                ,p_module   => l_log_module);
9162        END IF;
9163        xla_exceptions_pkg.raise_message
9164            (p_location => 'XLA_09000_AAD_S_000015_PKG.insert_sources_20');
9165 END insert_sources_20;
9166 --
9167 
9168 ---------------------------------------
9169 --
9170 -- PRIVATE FUNCTION
9171 --         EventType_20
9172 --
9173 ----------------------------------------
9174 --
9175 FUNCTION EventType_20
9176        (p_application_id         IN NUMBER
9177        ,p_base_ledger_id         IN NUMBER
9178        ,p_target_ledger_id       IN NUMBER
9179        ,p_language               IN VARCHAR2
9180        ,p_currency_code          IN VARCHAR2
9181        ,p_sla_ledger_id          IN NUMBER
9182        ,p_pad_start_date         IN DATE
9183        ,p_pad_end_date           IN DATE
9184        ,p_primary_ledger_id      IN NUMBER)
9185 RETURN BOOLEAN IS
9186 --
9187 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_CUST_CLAIM';
9188 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
9189 
9190 l_calculate_acctd_flag   VARCHAR2(1) :='N';
9191 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
9192 --
9193 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9194 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9195 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9196 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9197 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9198 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9199 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9200 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9201 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9202 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9203 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9204 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9205 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9206 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
9207 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9208 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9209 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9210 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
9211 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9212 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9213 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9214 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
9215 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
9216 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
9217 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
9218 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
9219 
9220 l_event_id                             NUMBER;
9221 l_previous_event_id                    NUMBER;
9222 l_first_event_id                       NUMBER;
9223 l_last_event_id                        NUMBER;
9224 
9225 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
9226 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
9227 --
9228 --
9229 l_result                    BOOLEAN := TRUE;
9230 l_rows                      NUMBER  := 1000;
9231 l_event_type_name           VARCHAR2(80) := 'Customer Claim to Supplier for Inventory on hand';
9232 l_event_class_name          VARCHAR2(80) := 'Claim Settlement';
9233 l_description               VARCHAR2(4000);
9234 l_transaction_reversal      NUMBER;
9235 l_ae_header_id              NUMBER;
9236 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
9237 l_log_module                VARCHAR2(240);
9238 --
9239 l_acct_reversal_source      VARCHAR2(30);
9240 l_trx_reversal_source       VARCHAR2(30);
9241 
9242 l_continue_with_lines       BOOLEAN := TRUE;
9243 --
9244 l_acc_rev_gl_date_source    DATE;                      -- 4262811
9245 --
9246 type t_array_event_id is table of number index by binary_integer;
9247 
9248 l_rec_array_event                    t_rec_array_event;
9249 l_null_rec_array_event               t_rec_array_event;
9250 l_array_ae_header_id                 xla_number_array_type;
9251 l_actual_flag                        VARCHAR2(1) := NULL;
9252 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
9253 l_balance_type_code                  VARCHAR2(1) :=NULL;
9254 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
9255 
9256 --
9257 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
9258 --
9259 
9260 TYPE t_array_source_5 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_AP_CLEARING_CCID%TYPE INDEX BY BINARY_INTEGER;
9261 TYPE t_array_source_7 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_CONTRA_LIAB_CCID%TYPE INDEX BY BINARY_INTEGER;
9262 TYPE t_array_source_10 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
9263 TYPE t_array_source_14 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
9264 TYPE t_array_source_15 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
9265 TYPE t_array_source_16 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
9266 
9267 TYPE t_array_source_9 IS TABLE OF DPP_XLA_CLAIM_LINES_V.DISTRIBUTION_IDENTIFIER%TYPE INDEX BY BINARY_INTEGER;
9268 TYPE t_array_source_11 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
9269 TYPE t_array_source_12 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
9270 TYPE t_array_source_13 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
9271 
9272 l_array_source_5              t_array_source_5;
9273 l_array_source_7              t_array_source_7;
9274 l_array_source_10              t_array_source_10;
9275 l_array_source_14              t_array_source_14;
9276 l_array_source_15              t_array_source_15;
9280 l_array_source_11      t_array_source_11;
9277 l_array_source_16              t_array_source_16;
9278 
9279 l_array_source_9      t_array_source_9;
9281 l_array_source_12      t_array_source_12;
9282 l_array_source_13      t_array_source_13;
9283 
9284 --
9285 CURSOR header_cur
9286 IS
9287 SELECT /*+ leading(xet) cardinality(xet,1) */
9288 -- Event Type Code: SUPPLIER_CUST_CLAIM
9289 -- Event Class Code: CLAIM_SETTLEMENT
9290     xet.entity_id
9291   , xet.legal_entity_id
9292   , xet.entity_code
9293   , xet.transaction_number
9294   , xet.event_id
9295   , xet.event_class_code
9296   , xet.event_type_code
9297   , xet.event_number
9298   , xet.event_date
9299   , xet.transaction_date
9300   , xet.reference_num_1
9301   , xet.reference_num_2
9302   , xet.reference_num_3
9303   , xet.reference_num_4
9304   , xet.reference_char_1
9305   , xet.reference_char_2
9306   , xet.reference_char_3
9307   , xet.reference_char_4
9308   , xet.reference_date_1
9309   , xet.reference_date_2
9310   , xet.reference_date_3
9311   , xet.reference_date_4
9312   , xet.event_created_by
9313   , xet.budgetary_control_flag 
9314   , h1.PP_AP_CLEARING_CCID    source_5
9315   , h1.PP_CONTRA_LIAB_CCID    source_7
9316   , h1.DISTRIBUTION_TYPE    source_10
9317   , h1.PARTY_ID    source_14
9318   , h1.PARTY_SITE_ID    source_15
9319   , h1.PARTY_TYPE    source_16
9320   FROM xla_events_gt     xet 
9321   , DPP_XLA_CLAIM_HEADERS_V  h1
9322  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
9323    and xet.event_type_code = C_EVENT_TYPE_CODE
9324    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
9325 
9326  ORDER BY event_id
9327 ;
9328 
9329 
9330 --
9331 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
9332 IS
9333 SELECT /*+ leading(xet) cardinality(xet,1) */
9334 -- Event Type Code: SUPPLIER_CUST_CLAIM
9335 -- Event Class Code: CLAIM_SETTLEMENT
9336     xet.entity_id
9337    ,xet.legal_entity_id
9338    ,xet.entity_code
9339    ,xet.transaction_number
9340    ,xet.event_id
9341    ,xet.event_class_code
9342    ,xet.event_type_code
9343    ,xet.event_number
9344    ,xet.event_date
9345    ,xet.transaction_date
9346    ,xet.reference_num_1
9347    ,xet.reference_num_2
9348    ,xet.reference_num_3
9349    ,xet.reference_num_4
9350    ,xet.reference_char_1
9351    ,xet.reference_char_2
9352    ,xet.reference_char_3
9353    ,xet.reference_char_4
9354    ,xet.reference_date_1
9355    ,xet.reference_date_2
9356    ,xet.reference_date_3
9357    ,xet.reference_date_4
9358    ,xet.event_created_by
9359    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
9360   , l2.DISTRIBUTION_IDENTIFIER    source_9
9361   , l2.ENTERED_AMOUNT    source_11
9362   , l2.CURRENCY_CODE    source_12
9363   , l2.ACCOUNTED_AMOUNT    source_13
9364   FROM xla_events_gt     xet 
9365   , DPP_XLA_CLAIM_LINES_V  l2
9366  WHERE xet.event_id between x_first_event_id and x_last_event_id
9367    and xet.event_date between p_pad_start_date and p_pad_end_date
9368    and xet.event_type_code = C_EVENT_TYPE_CODE
9372 --
9369    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
9370 ;
9371 
9373 BEGIN
9374 IF g_log_enabled THEN
9375    l_log_module := C_DEFAULT_MODULE||'.EventType_20';
9376 END IF;
9377 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9378    trace
9379       (p_msg      => 'BEGIN of EventType_20'
9380       ,p_level    => C_LEVEL_PROCEDURE
9381       ,p_module   => l_log_module);
9382 END IF;
9383 
9384 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9385    trace
9386       (p_msg      => 'p_application_id = '||p_application_id||
9387                      ' - p_base_ledger_id = '||p_base_ledger_id||
9388                      ' - p_target_ledger_id  = '||p_target_ledger_id||
9389                      ' - p_language = '||p_language||
9390                      ' - p_currency_code = '||p_currency_code||
9391                      ' - p_sla_ledger_id = '||p_sla_ledger_id
9392       ,p_level    => C_LEVEL_STATEMENT
9393       ,p_module   => l_log_module);
9394 END IF;
9395 --
9396 -- initialze arrays
9397 --
9398 g_array_event.DELETE;
9399 l_rec_array_event := l_null_rec_array_event;
9400 --
9401 --------------------------------------
9402 -- 4262811 Initialze MPA Line Number
9403 --------------------------------------
9404 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
9405 
9406 --
9407 
9408 --
9409 OPEN header_cur;
9410 --
9411 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9412    trace
9413    (p_msg      => 'SQL - FETCH header_cur'
9414    ,p_level    => C_LEVEL_STATEMENT
9415    ,p_module   => l_log_module);
9416 END IF;
9417 --
9418 LOOP
9419 FETCH header_cur BULK COLLECT INTO
9420         l_array_entity_id
9421       , l_array_legal_entity_id
9422       , l_array_entity_code
9423       , l_array_transaction_num
9424       , l_array_event_id
9425       , l_array_class_code
9426       , l_array_event_type
9427       , l_array_event_number
9428       , l_array_event_date
9429       , l_array_transaction_date
9430       , l_array_reference_num_1
9431       , l_array_reference_num_2
9432       , l_array_reference_num_3
9433       , l_array_reference_num_4
9434       , l_array_reference_char_1
9435       , l_array_reference_char_2
9436       , l_array_reference_char_3
9437       , l_array_reference_char_4
9438       , l_array_reference_date_1
9439       , l_array_reference_date_2
9440       , l_array_reference_date_3
9441       , l_array_reference_date_4
9442       , l_array_event_created_by
9443       , l_array_budgetary_control_flag 
9444       , l_array_source_5
9445       , l_array_source_7
9446       , l_array_source_10
9447       , l_array_source_14
9448       , l_array_source_15
9449       , l_array_source_16
9450       LIMIT l_rows;
9451 --
9452 IF (C_LEVEL_EVENT >= g_log_level) THEN
9453    trace
9454    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
9455    ,p_level    => C_LEVEL_EVENT
9456    ,p_module   => l_log_module);
9457 END IF;
9458 --
9459 EXIT WHEN l_array_entity_id.COUNT = 0;
9460 
9461 -- initialize arrays
9462 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
9463 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
9464 
9465 --
9466 -- Bug 4458708
9467 --
9468 XLA_AE_LINES_PKG.g_LineNumber := 0;
9469 
9470 
9471 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
9472 g_last_hdr_idx := l_array_event_id.LAST;
9473 --
9474 -- loop for the headers. Each iteration is for each header extract row
9475 -- fetched in header cursor
9476 --
9477 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
9478 
9479 --
9480 -- set event info as cache for other routines to refer event attributes
9481 --
9482 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
9483    (p_application_id           => p_application_id
9484    ,p_primary_ledger_id        => p_primary_ledger_id
9485    ,p_base_ledger_id           => p_base_ledger_id
9486    ,p_target_ledger_id         => p_target_ledger_id
9487    ,p_entity_id                => l_array_entity_id(hdr_idx)
9488    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
9489    ,p_entity_code              => l_array_entity_code(hdr_idx)
9490    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
9491    ,p_event_id                 => l_array_event_id(hdr_idx)
9492    ,p_event_class_code         => l_array_class_code(hdr_idx)
9493    ,p_event_type_code          => l_array_event_type(hdr_idx)
9494    ,p_event_number             => l_array_event_number(hdr_idx)
9495    ,p_event_date               => l_array_event_date(hdr_idx)
9496    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
9497    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
9498    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
9499    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
9500    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
9501    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
9502    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
9503    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
9504    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
9505    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
9506    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
9507    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
9508    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
9509    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
9510    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
9511 
9512 --
9513 -- set the status of entry to C_VALID (0)
9514 --
9515 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
9516 
9517 --
9518 -- initialize a row for ae header
9519 --
9520 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
9521 
9522 l_event_id := l_array_event_id(hdr_idx);
9523 
9524 --
9525 -- storing the hdr_idx for event. May be used by line cursor.
9526 --
9527 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
9528 
9529 --
9530 -- store sources from header extract. This can be improved to
9531 -- store only those sources from header extract that may be used in lines
9532 --
9533 
9534 g_array_event(l_event_id).array_value_num('source_5') := l_array_source_5(hdr_idx);
9535 g_array_event(l_event_id).array_value_num('source_7') := l_array_source_7(hdr_idx);
9536 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
9537 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
9538 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
9539 g_array_event(l_event_id).array_value_char('source_16') := l_array_source_16(hdr_idx);
9540 
9541 --
9542 -- initilaize the status of ae headers for diffrent balance types
9543 -- the status is initialised to C_NOT_CREATED (2)
9544 --
9545 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9546 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9547 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
9548 
9549 --
9550 -- call api to validate and store accounting attributes for header
9551 --
9552 
9553 ------------------------------------------------------------
9554 -- Accrual Reversal : to get date for Standard Source (NONE)
9555 ------------------------------------------------------------
9556 l_acc_rev_gl_date_source := NULL;
9557 
9558      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
9559       l_rec_acct_attrs.array_date_value(1) := 
9560 xla_ae_sources_pkg.GetSystemSourceDate(
9561    p_source_code           => 'XLA_TRANSACTION_DATE'
9562  , p_source_type_code      => 'Y'
9563  , p_source_application_id =>  602
9564 );
9565 
9566 
9567 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
9568 
9569 XLA_AE_HEADER_PKG.SetJeCategoryName;
9570 
9571 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
9572 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
9573 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
9574 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
9575 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
9576 
9577 
9578 -- No header level analytical criteria
9579 
9580 --
9581 --accounting attribute enhancement, bug 3612931
9582 --
9583 l_trx_reversal_source := SUBSTR(NULL, 1,30);
9584 
9585 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
9586    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
9587 
9588    xla_accounting_err_pkg.build_message
9592       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
9589       (p_appli_s_name            => 'XLA'
9590       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
9591       ,p_token_1                 => 'ACCT_ATTR_NAME'
9593       ,p_token_2                 => 'PRODUCT_NAME'
9594       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
9595       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
9596       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
9600    --
9597       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
9598 
9599 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
9601    -- following sets the accounting attributes needed to reverse
9602    -- accounting for a distributeion
9603    --
9604    xla_ae_lines_pkg.SetTrxReversalAttrs
9605       (p_event_id              => l_event_id
9606       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
9607       ,p_trx_reversal_source   => l_trx_reversal_source);
9608 
9609 END IF;
9610 
9611 
9612 ----------------------------------------------------------------
9613 -- 4262811 -  update the header statuses to invalid in need be
9614 ----------------------------------------------------------------
9615 --
9616 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
9617 
9618 
9619   -----------------------------------------------
9620   -- No accrual reversal for the event class/type
9621   -----------------------------------------------
9622 ----------------------------------------------------------------
9623 
9624 --
9625 -- this ends the header loop iteration for one bulk fetch
9626 --
9627 END LOOP;
9628 
9629 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
9630 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
9631 
9632 --
9633 -- insert dummy rows into lines gt table that were created due to
9634 -- transaction reversals
9635 --
9636 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
9637    l_result := XLA_AE_LINES_PKG.InsertLines;
9638 END IF;
9639 
9640 --
9641 -- reset the temp_line_num for each set of events fetched from header
9642 -- cursor rather than doing it for each new event in line cursor
9643 -- Bug 3939231
9644 --
9645 xla_ae_lines_pkg.g_temp_line_num := 0;
9646 
9647 
9648 
9649 --
9650 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
9651 --
9652 --
9653 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9654 
9655       trace
9656          (p_msg      => 'SQL - FETCH line_cur'
9657          ,p_level    => C_LEVEL_STATEMENT
9658          ,p_module   => l_log_module);
9659 
9660 END IF;
9661 --
9662 --
9663 LOOP
9664   --
9665   FETCH line_cur BULK COLLECT INTO
9666         l_array_entity_id
9667       , l_array_legal_entity_id
9668       , l_array_entity_code
9672       , l_array_event_type
9669       , l_array_transaction_num
9670       , l_array_event_id
9671       , l_array_class_code
9673       , l_array_event_number
9674       , l_array_event_date
9675       , l_array_transaction_date
9676       , l_array_reference_num_1
9677       , l_array_reference_num_2
9678       , l_array_reference_num_3
9679       , l_array_reference_num_4
9680       , l_array_reference_char_1
9681       , l_array_reference_char_2
9682       , l_array_reference_char_3
9683       , l_array_reference_char_4
9684       , l_array_reference_date_1
9685       , l_array_reference_date_2
9686       , l_array_reference_date_3
9687       , l_array_reference_date_4
9688       , l_array_event_created_by
9689       , l_array_budgetary_control_flag
9690       , l_array_extract_line_num 
9691       , l_array_source_9
9692       , l_array_source_11
9693       , l_array_source_12
9694       , l_array_source_13
9695       LIMIT l_rows;
9696 
9700                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
9697   --
9698   IF (C_LEVEL_EVENT >= g_log_level) THEN
9699             trace
9701                ,p_level    => C_LEVEL_EVENT
9705   EXIT WHEN l_array_entity_id.count = 0;
9702                ,p_module   => l_log_module);
9703   END IF;
9704   --
9706 
9707   XLA_AE_LINES_PKG.g_rec_lines := null;
9708 
9709 --
9710 -- Bug 4458708
9711 --
9712 XLA_AE_LINES_PKG.g_LineNumber := 0;
9713 --
9714 --
9715 
9716 FOR Idx IN 1..l_array_event_id.count LOOP
9717    --
9718    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
9719    --
9720    l_event_id := l_array_event_id(idx);  -- 5648433
9721 
9722    --
9723    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
9724    --
9725 
9726    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
9727              (g_array_event(l_event_id).array_value_num('header_index'))
9728          ,'N'
9729          ) <> 'Y'
9730    THEN
9731       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9732          trace
9733             (p_msg      => 'Trancaction revesal option is not Y '
9734             ,p_level    => C_LEVEL_STATEMENT
9735             ,p_module   => l_log_module);
9736       END IF;
9737 
9738 --
9742 --
9739 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
9740 --
9741 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
9743 -- set event info as cache for other routines to refer event attributes
9744 --
9745 
9746 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
9747    l_previous_event_id := l_event_id;
9748 
9749    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
9750       (p_application_id           => p_application_id
9751       ,p_primary_ledger_id        => p_primary_ledger_id
9752       ,p_base_ledger_id           => p_base_ledger_id
9753       ,p_target_ledger_id         => p_target_ledger_id
9754       ,p_entity_id                => l_array_entity_id(Idx)
9755       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
9756       ,p_entity_code              => l_array_entity_code(Idx)
9757       ,p_transaction_num          => l_array_transaction_num(Idx)
9758       ,p_event_id                 => l_array_event_id(Idx)
9759       ,p_event_class_code         => l_array_class_code(Idx)
9760       ,p_event_type_code          => l_array_event_type(Idx)
9761       ,p_event_number             => l_array_event_number(Idx)
9762       ,p_event_date               => l_array_event_date(Idx)
9763       ,p_transaction_date         => l_array_transaction_date(Idx)
9764       ,p_reference_num_1          => l_array_reference_num_1(Idx)
9765       ,p_reference_num_2          => l_array_reference_num_2(Idx)
9766       ,p_reference_num_3          => l_array_reference_num_3(Idx)
9767       ,p_reference_num_4          => l_array_reference_num_4(Idx)
9768       ,p_reference_char_1         => l_array_reference_char_1(Idx)
9769       ,p_reference_char_2         => l_array_reference_char_2(Idx)
9770       ,p_reference_char_3         => l_array_reference_char_3(Idx)
9771       ,p_reference_char_4         => l_array_reference_char_4(Idx)
9772       ,p_reference_date_1         => l_array_reference_date_1(Idx)
9773       ,p_reference_date_2         => l_array_reference_date_2(Idx)
9774       ,p_reference_date_3         => l_array_reference_date_3(Idx)
9775       ,p_reference_date_4         => l_array_reference_date_4(Idx)
9779 END IF;
9776       ,p_event_created_by         => l_array_event_created_by(Idx)
9777       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
9778        --
9780 
9781 
9782 
9783 --
9784 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
9785 
9786 l_acct_reversal_source := SUBSTR(NULL, 1,30);
9787 
9788 IF l_continue_with_lines THEN
9789    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
9790       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
9791 
9792       xla_accounting_err_pkg.build_message
9793          (p_appli_s_name            => 'XLA'
9794          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
9795          ,p_token_1                 => 'LINE_NUMBER'
9796          ,p_value_1                 => l_array_extract_line_num(Idx)
9797          ,p_token_2                 => 'PRODUCT_NAME'
9798          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
9799          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
9800          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
9804       --
9801          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
9802 
9803    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
9805       -- following sets the accounting attributes needed to reverse
9806       -- accounting for a distributeion
9807       --
9808 
9809       --
9810       -- 5217187
9811       --
9812       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
9813       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
9814                                        g_array_event(l_event_id).array_value_num('header_index'));
9815       --
9816       --
9817 
9818       -- No reversal code generated
9819 
9820       xla_ae_lines_pkg.SetAcctReversalAttrs
9821          (p_event_id             => l_event_id
9822          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
9823          ,p_calculate_acctd_flag => l_calculate_acctd_flag
9824          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
9825    END IF;
9826 
9827    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
9828        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
9829 
9830 --
9831 AcctLineType_12 (
9832  p_application_id  => p_application_id
9833  ,p_event_id     => l_event_id
9834  ,p_calculate_acctd_flag => l_calculate_acctd_flag
9835  ,p_calculate_g_l_flag => l_calculate_g_l_flag
9836  ,p_actual_flag => l_actual_flag
9837  ,p_balance_type_code => l_balance_type_code
9838  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
9839  
9840  , p_source_5 => g_array_event(l_event_id).array_value_num('source_5')
9841  , p_source_9 => l_array_source_9(Idx)
9845  , p_source_13 => l_array_source_13(Idx)
9842  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
9843  , p_source_11 => l_array_source_11(Idx)
9844  , p_source_12 => l_array_source_12(Idx)
9846  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
9847  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
9851   l_actual_gain_loss_ref := l_gain_or_loss_ref;
9848  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
9849  );
9850 If(l_balance_type_code = 'A') THEN
9852 END IF;
9853 
9854 --
9855 
9856 
9857 --
9858 AcctLineType_13 (
9859  p_application_id  => p_application_id
9860  ,p_event_id     => l_event_id
9861  ,p_calculate_acctd_flag => l_calculate_acctd_flag
9862  ,p_calculate_g_l_flag => l_calculate_g_l_flag
9863  ,p_actual_flag => l_actual_flag
9864  ,p_balance_type_code => l_balance_type_code
9865  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
9866  
9867  , p_source_7 => g_array_event(l_event_id).array_value_num('source_7')
9868  , p_source_9 => l_array_source_9(Idx)
9869  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
9870  , p_source_11 => l_array_source_11(Idx)
9871  , p_source_12 => l_array_source_12(Idx)
9872  , p_source_13 => l_array_source_13(Idx)
9873  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
9874  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
9875  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
9876  );
9877 If(l_balance_type_code = 'A') THEN
9878   l_actual_gain_loss_ref := l_gain_or_loss_ref;
9879 END IF;
9880 
9881 --
9882 
9883       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
9884       -- or secondary ledger that has different currency with primary
9885       -- or alc that is calculated by sla
9886       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
9887             (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'))
9888 
9889 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
9890 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
9891           AND (l_actual_flag = 'A')) THEN
9892         XLA_AE_LINES_PKG.CreateGainOrLossLines(
9893           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
9894          ,p_application_id   => p_application_id
9895          ,p_amb_context_code => 'DEFAULT'
9896          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
9897          ,p_event_class_code => C_EVENT_CLASS_CODE
9898          ,p_event_type_code  => C_EVENT_TYPE_CODE
9899          
9900          ,p_gain_ccid        => -1
9901          ,p_loss_ccid        => -1
9902 
9903          ,p_actual_flag      => l_actual_flag
9904          ,p_enc_flag         => null
9905          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
9906          ,p_enc_g_l_ref      => null
9907          );
9908       END IF;
9909    END IF;
9910 END IF;
9911 
9912    ELSE
9913       --
9914       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
9915       --
9919             ,p_level    => C_LEVEL_STATEMENT
9916       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9917          trace
9918             (p_msg      => 'Trancaction revesal option is Y'
9920             ,p_module   => l_log_module);
9921       END IF;
9922    END IF;
9923 
9924 END LOOP;
9925 l_result := XLA_AE_LINES_PKG.InsertLines ;
9926 end loop;
9927 close line_cur;
9928 
9929 
9930 --
9931 -- insert headers into xla_ae_headers_gt table
9932 --
9933 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
9934 
9935 -- insert into errors table here.
9936 
9937 END LOOP;
9938 
9939 --
9940 -- 4865292
9941 --
9942 -- Compare g_hdr_extract_count with event count in
9943 -- CreateHeadersAndLines.
9944 --
9945 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
9946 
9947 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
9948    trace (p_msg     => '# rows extracted from header extract objects '
9949                     || ' (running total): '
9950                     || g_hdr_extract_count
9951          ,p_level   => C_LEVEL_STATEMENT
9952          ,p_module  => l_log_module);
9953 END IF;
9954 
9955 CLOSE header_cur;
9956 --
9957 
9958 --
9959 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
9960    trace
9961       (p_msg      => 'END of EventType_20'
9962       ,p_level    => C_LEVEL_PROCEDURE
9963       ,p_module   => l_log_module);
9964 END IF;
9965 --
9966 RETURN l_result;
9967 EXCEPTION
9968 WHEN xla_exceptions_pkg.application_exception THEN
9969    
9970 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
9971 
9972    
9973 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
9974 
9975    RAISE;
9976 
9977 WHEN NO_DATA_FOUND THEN
9978 
9979 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
9980 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
9981 
9982 FOR header_record IN header_cur
9983 LOOP
9984     l_array_header_events(header_record.event_id) := header_record.event_id;
9985 END LOOP;
9986 
9990 fnd_file.put_line(fnd_file.LOG, '                    ');
9987 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
9988 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
9989 
9991 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
9992 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
9993 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
9994 
9995 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
9996 LOOP
9997 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
9998 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
9999         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
10000 	END IF;
10001 END LOOP;
10002 
10003 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
10004 fnd_file.put_line(fnd_file.LOG, '                    ');
10005 
10006 
10007 xla_exceptions_pkg.raise_message
10008       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_20');
10009 
10010 
10011 WHEN OTHERS THEN
10012    xla_exceptions_pkg.raise_message
10013       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_20');
10014 END EventType_20;
10015 --
10016 
10017 ---------------------------------------
10018 --
10019 -- PRIVATE PROCEDURE
10020 --         insert_sources_21
10021 --
10022 ----------------------------------------
10023 --
10024 PROCEDURE insert_sources_21(
10025                                 p_target_ledger_id       IN NUMBER
10026                               , p_language               IN VARCHAR2
10027                               , p_sla_ledger_id          IN NUMBER
10028                               , p_pad_start_date         IN DATE
10032 
10029                               , p_pad_end_date           IN DATE
10030                          )
10031 IS
10033 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_DSTR_CLAIM';
10034 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
10035 p_apps_owner                   VARCHAR2(30);
10036 l_log_module                   VARCHAR2(240);
10037 BEGIN
10038 IF g_log_enabled THEN
10039       l_log_module := C_DEFAULT_MODULE||'.insert_sources_21';
10040 END IF;
10041 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10042 
10043       trace
10044          (p_msg      => 'BEGIN of insert_sources_21'
10045          ,p_level    => C_LEVEL_PROCEDURE
10046          ,p_module   => l_log_module);
10047 
10048 END IF;
10049 
10050 -- select APPS owner
10051 SELECT oracle_username
10052   INTO p_apps_owner
10053   FROM fnd_oracle_userid
10054  WHERE read_only_flag = 'U'
10055 ;
10056 
10057 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10058       trace
10059          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
10060                         ' - p_language = '||p_language||
10064                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
10061                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
10062                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
10063                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
10065          ,p_level    => C_LEVEL_STATEMENT
10066          ,p_module   => l_log_module);
10067 END IF;
10068 
10069 
10070 --
10071 INSERT INTO xla_diag_sources --hdr1
10072 (
10073         event_id
10074       , ledger_id
10075       , sla_ledger_id
10076       , description_language
10077       , object_name
10078       , object_type_code
10079       , line_number
10080       , source_application_id
10081       , source_type_code
10082       , source_code
10083       , source_value
10084       , source_meaning
10085       , created_by
10086       , creation_date
10087       , last_update_date
10088       , last_updated_by
10089       , last_update_login
10090       , program_update_date
10091       , program_application_id
10092       , program_id
10093       , request_id
10094 )
10095 SELECT
10096         event_id
10097       , p_target_ledger_id
10098       , p_sla_ledger_id
10099       , p_language
10100       , object_name
10101       , object_type_code
10102       , line_number
10103       , source_application_id
10104       , source_type_code
10105       , source_code
10106       , SUBSTR(source_value ,1,1996)
10107       , SUBSTR(source_meaning,1,200)
10108       , xla_environment_pkg.g_Usr_Id
10109       , TRUNC(SYSDATE)
10110       , TRUNC(SYSDATE)
10111       , xla_environment_pkg.g_Usr_Id
10112       , xla_environment_pkg.g_Login_Id
10113       , TRUNC(SYSDATE)
10114       , xla_environment_pkg.g_Prog_Appl_Id
10115       , xla_environment_pkg.g_Prog_Id
10116       , xla_environment_pkg.g_Req_Id
10117   FROM (
10118        SELECT xet.event_id                  event_id
10119             , 0                             line_number
10120             , CASE r
10121                WHEN 1 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10122                 WHEN 2 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10123                 WHEN 3 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10127                 WHEN 7 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10124                 WHEN 4 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10125                 WHEN 5 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10126                 WHEN 6 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
10128                 
10129                ELSE null
10130               END                           object_name
10131             , CASE r
10132                 WHEN 1 THEN 'HEADER' 
10133                 WHEN 2 THEN 'HEADER' 
10134                 WHEN 3 THEN 'HEADER' 
10135                 WHEN 4 THEN 'HEADER' 
10136                 WHEN 5 THEN 'HEADER' 
10137                 WHEN 6 THEN 'HEADER' 
10138                 WHEN 7 THEN 'HEADER' 
10139                 
10140                 ELSE null
10141               END                           object_type_code
10142             , CASE r
10143                 WHEN 1 THEN '9000' 
10144                 WHEN 2 THEN '9000' 
10145                 WHEN 3 THEN '9000' 
10146                 WHEN 4 THEN '9000' 
10147                 WHEN 5 THEN '9000' 
10148                 WHEN 6 THEN '9000' 
10149                 WHEN 7 THEN '9000' 
10150                 
10151                 ELSE null
10152               END                           source_application_id
10153             , 'S'             source_type_code
10157                 WHEN 3 THEN 'PP_AP_CLEARING_CCID' 
10154             , CASE r
10155                 WHEN 1 THEN 'PP_TXN_NUMBER' 
10156                 WHEN 2 THEN 'PP_ACCRUAL_CCID' 
10158                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
10159                 WHEN 5 THEN 'PARTY_ID' 
10160                 WHEN 6 THEN 'PARTY_SITE_ID' 
10161                 WHEN 7 THEN 'PARTY_TYPE' 
10162                 
10163                 ELSE null
10164               END                           source_code
10165             , CASE r
10166                 WHEN 1 THEN TO_CHAR(h1.PP_TXN_NUMBER)
10167                 WHEN 2 THEN TO_CHAR(h1.PP_ACCRUAL_CCID)
10168                 WHEN 3 THEN TO_CHAR(h1.PP_AP_CLEARING_CCID)
10169                 WHEN 4 THEN TO_CHAR(h1.DISTRIBUTION_TYPE)
10170                 WHEN 5 THEN TO_CHAR(h1.PARTY_ID)
10171                 WHEN 6 THEN TO_CHAR(h1.PARTY_SITE_ID)
10172                 WHEN 7 THEN TO_CHAR(h1.PARTY_TYPE)
10173                 
10174                 ELSE null
10175               END                           source_value
10176             , null              source_meaning
10177         FROM xla_events_gt     xet  
10178       , DPP_XLA_CLAIM_HEADERS_V  h1
10179             ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
10180        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
10181          AND xet.event_type_code = C_EVENT_TYPE_CODE
10182             AND h1.event_id = xet.event_id
10183 
10184 )
10185 ;
10186 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10187 
10188       trace
10189          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
10190          ,p_level    => C_LEVEL_STATEMENT
10191          ,p_module   => l_log_module);
10192 
10193 END IF;
10194 --
10195 
10196 
10197 
10198 --
10199 INSERT INTO xla_diag_sources --line1
10200 (
10201         event_id
10202       , ledger_id
10203       , sla_ledger_id
10204       , description_language
10205       , object_name
10206       , object_type_code
10207       , line_number
10208       , source_application_id
10212       , source_meaning
10209       , source_type_code
10210       , source_code
10211       , source_value
10213       , created_by
10214       , creation_date
10215       , last_update_date
10216       , last_updated_by
10217       , last_update_login
10218       , program_update_date
10219       , program_application_id
10220       , program_id
10221       , request_id
10222 )
10223 SELECT  event_id
10224       , p_target_ledger_id
10225       , p_sla_ledger_id
10226       , p_language
10227       , object_name
10228       , object_type_code
10229       , line_number
10230       , source_application_id
10231       , source_type_code
10232       , source_code
10233       , SUBSTR(source_value,1,1996)
10234       , SUBSTR(source_meaning,1,200)
10235       , xla_environment_pkg.g_Usr_Id
10236       , TRUNC(SYSDATE)
10237       , TRUNC(SYSDATE)
10238       , xla_environment_pkg.g_Usr_Id
10239       , xla_environment_pkg.g_Login_Id
10240       , TRUNC(SYSDATE)
10241       , xla_environment_pkg.g_Prog_Appl_Id
10242       , xla_environment_pkg.g_Prog_Id
10243       , xla_environment_pkg.g_Req_Id
10244   FROM (
10245        SELECT xet.event_id                  event_id
10246             , l2.line_number                 line_number
10247             , CASE r
10248                WHEN 1 THEN 'DPP_XLA_CLAIM_LINES_V' 
10249                 WHEN 2 THEN 'DPP_XLA_CLAIM_LINES_V' 
10250                 WHEN 3 THEN 'DPP_XLA_CLAIM_LINES_V' 
10251                 WHEN 4 THEN 'DPP_XLA_CLAIM_LINES_V' 
10252                 WHEN 5 THEN 'DPP_XLA_CLAIM_LINES_V' 
10253                 WHEN 6 THEN 'DPP_XLA_CLAIM_LINES_V' 
10254                 
10255                ELSE null
10256               END                           object_name
10257             , CASE r
10258                 WHEN 1 THEN 'LINE' 
10259                 WHEN 2 THEN 'LINE' 
10260                 WHEN 3 THEN 'LINE' 
10261                 WHEN 4 THEN 'LINE' 
10262                 WHEN 5 THEN 'LINE' 
10263                 WHEN 6 THEN 'LINE' 
10264                 
10265                 ELSE null
10266               END                           object_type_code
10267             , CASE r
10268                 WHEN 1 THEN '9000' 
10269                 WHEN 2 THEN '9000' 
10270                 WHEN 3 THEN '9000' 
10271                 WHEN 4 THEN '9000' 
10272                 WHEN 5 THEN '9000' 
10273                 WHEN 6 THEN '9000' 
10274                 
10275                 ELSE null
10276               END                           source_application_id
10277             , 'S'             source_type_code
10278             , CASE r
10279                 WHEN 1 THEN 'CLAIM_NUMBER' 
10280                 WHEN 2 THEN 'ITEM_NUMBER' 
10281                 WHEN 3 THEN 'DISTRIBUTION_IDENTIFIER' 
10282                 WHEN 4 THEN 'ENTERED_AMOUNT' 
10283                 WHEN 5 THEN 'CURRENCY_CODE' 
10284                 WHEN 6 THEN 'ACCOUNTED_AMOUNT' 
10285                 
10286                 ELSE null
10287               END                           source_code
10288             , CASE r
10289                 WHEN 1 THEN TO_CHAR(l2.CLAIM_NUMBER)
10290                 WHEN 2 THEN TO_CHAR(l2.ITEM_NUMBER)
10291                 WHEN 3 THEN TO_CHAR(l2.DISTRIBUTION_IDENTIFIER)
10292                 WHEN 4 THEN TO_CHAR(l2.ENTERED_AMOUNT)
10293                 WHEN 5 THEN TO_CHAR(l2.CURRENCY_CODE)
10294                 WHEN 6 THEN TO_CHAR(l2.ACCOUNTED_AMOUNT)
10295                 
10296                 ELSE null
10297               END                           source_value
10298             , null              source_meaning
10299          FROM  xla_events_gt     xet  
10300         , DPP_XLA_CLAIM_LINES_V  l2
10301             ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
10302         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
10303           AND xet.event_type_code = C_EVENT_TYPE_CODE
10304             AND l2.event_id          = xet.event_id
10305 
10306 )
10307 ;
10308 --
10309 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10310 
10311       trace
10312          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
10313          ,p_level    => C_LEVEL_STATEMENT
10314          ,p_module   => l_log_module);
10315 
10316 END IF;
10317 
10318 
10319 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10320       trace
10321          (p_msg      => 'END of insert_sources_21'
10322          ,p_level    => C_LEVEL_PROCEDURE
10323          ,p_module   => l_log_module);
10324 END IF;
10325 EXCEPTION
10326   WHEN xla_exceptions_pkg.application_exception THEN
10327       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10328             trace
10329                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
10330                ,p_level    => C_LEVEL_EXCEPTION
10331                ,p_module   => l_log_module);
10332       END IF;
10333       RAISE;
10334   WHEN OTHERS THEN
10335       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
10336             trace
10337                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
10338                ,p_level    => C_LEVEL_EXCEPTION
10339                ,p_module   => l_log_module);
10340        END IF;
10341        xla_exceptions_pkg.raise_message
10342            (p_location => 'XLA_09000_AAD_S_000015_PKG.insert_sources_21');
10343 END insert_sources_21;
10344 --
10345 
10346 ---------------------------------------
10347 --
10348 -- PRIVATE FUNCTION
10349 --         EventType_21
10350 --
10351 ----------------------------------------
10352 --
10353 FUNCTION EventType_21
10354        (p_application_id         IN NUMBER
10355        ,p_base_ledger_id         IN NUMBER
10356        ,p_target_ledger_id       IN NUMBER
10360        ,p_pad_start_date         IN DATE
10357        ,p_language               IN VARCHAR2
10358        ,p_currency_code          IN VARCHAR2
10359        ,p_sla_ledger_id          IN NUMBER
10361        ,p_pad_end_date           IN DATE
10362        ,p_primary_ledger_id      IN NUMBER)
10363 RETURN BOOLEAN IS
10364 --
10365 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_DSTR_CLAIM';
10366 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
10367 
10368 l_calculate_acctd_flag   VARCHAR2(1) :='N';
10369 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
10370 --
10371 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10372 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10373 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10374 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10375 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10376 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10377 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10378 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10379 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10380 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10381 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10382 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10383 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10384 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
10385 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10386 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10387 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10388 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
10389 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10390 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10391 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10392 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
10393 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
10394 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
10395 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
10396 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
10397 
10398 l_event_id                             NUMBER;
10399 l_previous_event_id                    NUMBER;
10400 l_first_event_id                       NUMBER;
10401 l_last_event_id                        NUMBER;
10402 
10403 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
10404 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
10405 --
10406 --
10407 l_result                    BOOLEAN := TRUE;
10408 l_rows                      NUMBER  := 1000;
10409 l_event_type_name           VARCHAR2(80) := 'Distributor Claim to Supplier for Inventory on hand for Price Decrease';
10410 l_event_class_name          VARCHAR2(80) := 'Claim Settlement';
10411 l_description               VARCHAR2(4000);
10412 l_transaction_reversal      NUMBER;
10413 l_ae_header_id              NUMBER;
10414 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
10415 l_log_module                VARCHAR2(240);
10416 --
10417 l_acct_reversal_source      VARCHAR2(30);
10418 l_trx_reversal_source       VARCHAR2(30);
10419 
10420 l_continue_with_lines       BOOLEAN := TRUE;
10421 --
10422 l_acc_rev_gl_date_source    DATE;                      -- 4262811
10423 --
10424 type t_array_event_id is table of number index by binary_integer;
10425 
10426 l_rec_array_event                    t_rec_array_event;
10427 l_null_rec_array_event               t_rec_array_event;
10428 l_array_ae_header_id                 xla_number_array_type;
10429 l_actual_flag                        VARCHAR2(1) := NULL;
10430 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
10431 l_balance_type_code                  VARCHAR2(1) :=NULL;
10432 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
10433 
10434 --
10435 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
10436 --
10437 
10438 TYPE t_array_source_1 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_TXN_NUMBER%TYPE INDEX BY BINARY_INTEGER;
10439 TYPE t_array_source_4 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_ACCRUAL_CCID%TYPE INDEX BY BINARY_INTEGER;
10440 TYPE t_array_source_5 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_AP_CLEARING_CCID%TYPE INDEX BY BINARY_INTEGER;
10441 TYPE t_array_source_10 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
10442 TYPE t_array_source_14 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
10443 TYPE t_array_source_15 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
10444 TYPE t_array_source_16 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
10445 
10446 TYPE t_array_source_2 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CLAIM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
10447 TYPE t_array_source_3 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ITEM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
10448 TYPE t_array_source_9 IS TABLE OF DPP_XLA_CLAIM_LINES_V.DISTRIBUTION_IDENTIFIER%TYPE INDEX BY BINARY_INTEGER;
10449 TYPE t_array_source_11 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
10450 TYPE t_array_source_12 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
10451 TYPE t_array_source_13 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
10452 
10453 l_array_source_1              t_array_source_1;
10454 l_array_source_4              t_array_source_4;
10455 l_array_source_5              t_array_source_5;
10459 l_array_source_16              t_array_source_16;
10456 l_array_source_10              t_array_source_10;
10457 l_array_source_14              t_array_source_14;
10458 l_array_source_15              t_array_source_15;
10460 
10461 l_array_source_2      t_array_source_2;
10462 l_array_source_3      t_array_source_3;
10463 l_array_source_9      t_array_source_9;
10464 l_array_source_11      t_array_source_11;
10465 l_array_source_12      t_array_source_12;
10466 l_array_source_13      t_array_source_13;
10467 
10468 --
10469 CURSOR header_cur
10470 IS
10471 SELECT /*+ leading(xet) cardinality(xet,1) */
10472 -- Event Type Code: SUPPLIER_DSTR_CLAIM
10473 -- Event Class Code: CLAIM_SETTLEMENT
10474     xet.entity_id
10475   , xet.legal_entity_id
10476   , xet.entity_code
10477   , xet.transaction_number
10478   , xet.event_id
10479   , xet.event_class_code
10480   , xet.event_type_code
10481   , xet.event_number
10482   , xet.event_date
10483   , xet.transaction_date
10484   , xet.reference_num_1
10485   , xet.reference_num_2
10486   , xet.reference_num_3
10487   , xet.reference_num_4
10488   , xet.reference_char_1
10489   , xet.reference_char_2
10490   , xet.reference_char_3
10491   , xet.reference_char_4
10492   , xet.reference_date_1
10493   , xet.reference_date_2
10494   , xet.reference_date_3
10495   , xet.reference_date_4
10496   , xet.event_created_by
10497   , xet.budgetary_control_flag 
10498   , h1.PP_TXN_NUMBER    source_1
10499   , h1.PP_ACCRUAL_CCID    source_4
10500   , h1.PP_AP_CLEARING_CCID    source_5
10501   , h1.DISTRIBUTION_TYPE    source_10
10502   , h1.PARTY_ID    source_14
10503   , h1.PARTY_SITE_ID    source_15
10504   , h1.PARTY_TYPE    source_16
10505   FROM xla_events_gt     xet 
10506   , DPP_XLA_CLAIM_HEADERS_V  h1
10507  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
10508    and xet.event_type_code = C_EVENT_TYPE_CODE
10509    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
10510 
10511  ORDER BY event_id
10512 ;
10513 
10514 
10515 --
10516 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
10517 IS
10518 SELECT /*+ leading(xet) cardinality(xet,1) */
10519 -- Event Type Code: SUPPLIER_DSTR_CLAIM
10520 -- Event Class Code: CLAIM_SETTLEMENT
10521     xet.entity_id
10522    ,xet.legal_entity_id
10523    ,xet.entity_code
10524    ,xet.transaction_number
10525    ,xet.event_id
10526    ,xet.event_class_code
10527    ,xet.event_type_code
10528    ,xet.event_number
10529    ,xet.event_date
10530    ,xet.transaction_date
10531    ,xet.reference_num_1
10532    ,xet.reference_num_2
10533    ,xet.reference_num_3
10534    ,xet.reference_num_4
10535    ,xet.reference_char_1
10536    ,xet.reference_char_2
10537    ,xet.reference_char_3
10538    ,xet.reference_char_4
10539    ,xet.reference_date_1
10540    ,xet.reference_date_2
10541    ,xet.reference_date_3
10542    ,xet.reference_date_4
10543    ,xet.event_created_by
10544    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
10545   , l2.CLAIM_NUMBER    source_2
10546   , l2.ITEM_NUMBER    source_3
10547   , l2.DISTRIBUTION_IDENTIFIER    source_9
10548   , l2.ENTERED_AMOUNT    source_11
10549   , l2.CURRENCY_CODE    source_12
10550   , l2.ACCOUNTED_AMOUNT    source_13
10551   FROM xla_events_gt     xet 
10552   , DPP_XLA_CLAIM_LINES_V  l2
10553  WHERE xet.event_id between x_first_event_id and x_last_event_id
10554    and xet.event_date between p_pad_start_date and p_pad_end_date
10555    and xet.event_type_code = C_EVENT_TYPE_CODE
10556    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
10557 ;
10558 
10559 --
10560 BEGIN
10561 IF g_log_enabled THEN
10562    l_log_module := C_DEFAULT_MODULE||'.EventType_21';
10563 END IF;
10564 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
10565    trace
10566       (p_msg      => 'BEGIN of EventType_21'
10567       ,p_level    => C_LEVEL_PROCEDURE
10568       ,p_module   => l_log_module);
10569 END IF;
10570 
10571 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10572    trace
10573       (p_msg      => 'p_application_id = '||p_application_id||
10574                      ' - p_base_ledger_id = '||p_base_ledger_id||
10575                      ' - p_target_ledger_id  = '||p_target_ledger_id||
10576                      ' - p_language = '||p_language||
10577                      ' - p_currency_code = '||p_currency_code||
10578                      ' - p_sla_ledger_id = '||p_sla_ledger_id
10579       ,p_level    => C_LEVEL_STATEMENT
10580       ,p_module   => l_log_module);
10581 END IF;
10582 --
10583 -- initialze arrays
10584 --
10585 g_array_event.DELETE;
10586 l_rec_array_event := l_null_rec_array_event;
10587 --
10588 --------------------------------------
10589 -- 4262811 Initialze MPA Line Number
10590 --------------------------------------
10591 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
10592 
10593 --
10594 
10595 --
10596 OPEN header_cur;
10597 --
10598 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10599    trace
10600    (p_msg      => 'SQL - FETCH header_cur'
10601    ,p_level    => C_LEVEL_STATEMENT
10602    ,p_module   => l_log_module);
10603 END IF;
10604 --
10605 LOOP
10606 FETCH header_cur BULK COLLECT INTO
10607         l_array_entity_id
10608       , l_array_legal_entity_id
10609       , l_array_entity_code
10610       , l_array_transaction_num
10611       , l_array_event_id
10612       , l_array_class_code
10613       , l_array_event_type
10614       , l_array_event_number
10615       , l_array_event_date
10616       , l_array_transaction_date
10617       , l_array_reference_num_1
10618       , l_array_reference_num_2
10619       , l_array_reference_num_3
10623       , l_array_reference_char_3
10620       , l_array_reference_num_4
10621       , l_array_reference_char_1
10622       , l_array_reference_char_2
10624       , l_array_reference_char_4
10625       , l_array_reference_date_1
10626       , l_array_reference_date_2
10627       , l_array_reference_date_3
10628       , l_array_reference_date_4
10629       , l_array_event_created_by
10630       , l_array_budgetary_control_flag 
10631       , l_array_source_1
10632       , l_array_source_4
10633       , l_array_source_5
10634       , l_array_source_10
10635       , l_array_source_14
10636       , l_array_source_15
10637       , l_array_source_16
10638       LIMIT l_rows;
10639 --
10640 IF (C_LEVEL_EVENT >= g_log_level) THEN
10641    trace
10642    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
10643    ,p_level    => C_LEVEL_EVENT
10644    ,p_module   => l_log_module);
10645 END IF;
10646 --
10647 EXIT WHEN l_array_entity_id.COUNT = 0;
10648 
10649 -- initialize arrays
10650 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
10651 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
10652 
10653 --
10654 -- Bug 4458708
10655 --
10656 XLA_AE_LINES_PKG.g_LineNumber := 0;
10657 
10658 
10659 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
10660 g_last_hdr_idx := l_array_event_id.LAST;
10661 --
10662 -- loop for the headers. Each iteration is for each header extract row
10663 -- fetched in header cursor
10664 --
10665 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
10666 
10667 --
10668 -- set event info as cache for other routines to refer event attributes
10669 --
10670 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
10671    (p_application_id           => p_application_id
10672    ,p_primary_ledger_id        => p_primary_ledger_id
10673    ,p_base_ledger_id           => p_base_ledger_id
10674    ,p_target_ledger_id         => p_target_ledger_id
10675    ,p_entity_id                => l_array_entity_id(hdr_idx)
10676    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
10677    ,p_entity_code              => l_array_entity_code(hdr_idx)
10678    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
10679    ,p_event_id                 => l_array_event_id(hdr_idx)
10680    ,p_event_class_code         => l_array_class_code(hdr_idx)
10681    ,p_event_type_code          => l_array_event_type(hdr_idx)
10682    ,p_event_number             => l_array_event_number(hdr_idx)
10683    ,p_event_date               => l_array_event_date(hdr_idx)
10684    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
10685    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
10686    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
10687    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
10688    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
10689    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
10690    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
10691    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
10692    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
10693    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
10694    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
10695    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
10696    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
10697    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
10698    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
10699 
10700 --
10701 -- set the status of entry to C_VALID (0)
10702 --
10703 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
10704 
10705 --
10706 -- initialize a row for ae header
10707 --
10708 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
10709 
10710 l_event_id := l_array_event_id(hdr_idx);
10711 
10712 --
10713 -- storing the hdr_idx for event. May be used by line cursor.
10714 --
10715 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
10716 
10717 --
10718 -- store sources from header extract. This can be improved to
10719 -- store only those sources from header extract that may be used in lines
10720 --
10721 
10722 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
10723 g_array_event(l_event_id).array_value_num('source_4') := l_array_source_4(hdr_idx);
10724 g_array_event(l_event_id).array_value_num('source_5') := l_array_source_5(hdr_idx);
10725 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
10726 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
10727 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
10728 g_array_event(l_event_id).array_value_char('source_16') := l_array_source_16(hdr_idx);
10729 
10730 --
10731 -- initilaize the status of ae headers for diffrent balance types
10732 -- the status is initialised to C_NOT_CREATED (2)
10733 --
10734 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10735 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10736 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
10737 
10738 --
10739 -- call api to validate and store accounting attributes for header
10740 --
10741 
10742 ------------------------------------------------------------
10743 -- Accrual Reversal : to get date for Standard Source (NONE)
10744 ------------------------------------------------------------
10745 l_acc_rev_gl_date_source := NULL;
10746 
10747      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
10751  , p_source_type_code      => 'Y'
10748       l_rec_acct_attrs.array_date_value(1) := 
10749 xla_ae_sources_pkg.GetSystemSourceDate(
10750    p_source_code           => 'XLA_TRANSACTION_DATE'
10752  , p_source_application_id =>  602
10753 );
10754 
10755 
10756 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
10757 
10758 XLA_AE_HEADER_PKG.SetJeCategoryName;
10759 
10760 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
10761 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
10762 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
10763 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
10764 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
10765 
10766 
10767 -- No header level analytical criteria
10768 
10769 --
10770 --accounting attribute enhancement, bug 3612931
10771 --
10772 l_trx_reversal_source := SUBSTR(NULL, 1,30);
10773 
10774 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
10775    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
10776 
10777    xla_accounting_err_pkg.build_message
10778       (p_appli_s_name            => 'XLA'
10779       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
10780       ,p_token_1                 => 'ACCT_ATTR_NAME'
10781       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
10782       ,p_token_2                 => 'PRODUCT_NAME'
10783       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
10784       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
10785       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
10786       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
10787 
10788 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
10789    --
10790    -- following sets the accounting attributes needed to reverse
10791    -- accounting for a distributeion
10792    --
10793    xla_ae_lines_pkg.SetTrxReversalAttrs
10794       (p_event_id              => l_event_id
10795       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
10796       ,p_trx_reversal_source   => l_trx_reversal_source);
10797 
10798 END IF;
10799 
10800 
10801 ----------------------------------------------------------------
10802 -- 4262811 -  update the header statuses to invalid in need be
10803 ----------------------------------------------------------------
10804 --
10805 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
10806 
10807 
10808   -----------------------------------------------
10809   -- No accrual reversal for the event class/type
10810   -----------------------------------------------
10811 ----------------------------------------------------------------
10812 
10813 --
10814 -- this ends the header loop iteration for one bulk fetch
10815 --
10816 END LOOP;
10817 
10818 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
10819 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
10820 
10821 --
10822 -- insert dummy rows into lines gt table that were created due to
10823 -- transaction reversals
10824 --
10825 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
10826    l_result := XLA_AE_LINES_PKG.InsertLines;
10827 END IF;
10828 
10829 --
10830 -- reset the temp_line_num for each set of events fetched from header
10831 -- cursor rather than doing it for each new event in line cursor
10832 -- Bug 3939231
10833 --
10834 xla_ae_lines_pkg.g_temp_line_num := 0;
10835 
10836 
10837 
10838 --
10839 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
10840 --
10841 --
10842 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10843 
10844       trace
10845          (p_msg      => 'SQL - FETCH line_cur'
10846          ,p_level    => C_LEVEL_STATEMENT
10847          ,p_module   => l_log_module);
10848 
10849 END IF;
10850 --
10851 --
10852 LOOP
10853   --
10854   FETCH line_cur BULK COLLECT INTO
10855         l_array_entity_id
10856       , l_array_legal_entity_id
10857       , l_array_entity_code
10858       , l_array_transaction_num
10859       , l_array_event_id
10860       , l_array_class_code
10861       , l_array_event_type
10862       , l_array_event_number
10863       , l_array_event_date
10864       , l_array_transaction_date
10865       , l_array_reference_num_1
10866       , l_array_reference_num_2
10867       , l_array_reference_num_3
10868       , l_array_reference_num_4
10869       , l_array_reference_char_1
10870       , l_array_reference_char_2
10871       , l_array_reference_char_3
10872       , l_array_reference_char_4
10873       , l_array_reference_date_1
10874       , l_array_reference_date_2
10875       , l_array_reference_date_3
10876       , l_array_reference_date_4
10877       , l_array_event_created_by
10878       , l_array_budgetary_control_flag
10879       , l_array_extract_line_num 
10880       , l_array_source_2
10881       , l_array_source_3
10882       , l_array_source_9
10883       , l_array_source_11
10884       , l_array_source_12
10885       , l_array_source_13
10886       LIMIT l_rows;
10887 
10888   --
10889   IF (C_LEVEL_EVENT >= g_log_level) THEN
10890             trace
10891                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
10892                ,p_level    => C_LEVEL_EVENT
10893                ,p_module   => l_log_module);
10894   END IF;
10895   --
10899 
10896   EXIT WHEN l_array_entity_id.count = 0;
10897 
10898   XLA_AE_LINES_PKG.g_rec_lines := null;
10900 --
10901 -- Bug 4458708
10902 --
10903 XLA_AE_LINES_PKG.g_LineNumber := 0;
10904 --
10905 --
10906 
10907 FOR Idx IN 1..l_array_event_id.count LOOP
10908    --
10909    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
10910    --
10911    l_event_id := l_array_event_id(idx);  -- 5648433
10912 
10913    --
10914    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
10915    --
10916 
10917    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
10918              (g_array_event(l_event_id).array_value_num('header_index'))
10919          ,'N'
10920          ) <> 'Y'
10921    THEN
10922       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
10923          trace
10924             (p_msg      => 'Trancaction revesal option is not Y '
10925             ,p_level    => C_LEVEL_STATEMENT
10926             ,p_module   => l_log_module);
10927       END IF;
10928 
10929 --
10930 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
10931 --
10932 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
10933 --
10934 -- set event info as cache for other routines to refer event attributes
10935 --
10936 
10937 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
10938    l_previous_event_id := l_event_id;
10939 
10940    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
10941       (p_application_id           => p_application_id
10942       ,p_primary_ledger_id        => p_primary_ledger_id
10943       ,p_base_ledger_id           => p_base_ledger_id
10944       ,p_target_ledger_id         => p_target_ledger_id
10945       ,p_entity_id                => l_array_entity_id(Idx)
10946       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
10947       ,p_entity_code              => l_array_entity_code(Idx)
10948       ,p_transaction_num          => l_array_transaction_num(Idx)
10949       ,p_event_id                 => l_array_event_id(Idx)
10950       ,p_event_class_code         => l_array_class_code(Idx)
10951       ,p_event_type_code          => l_array_event_type(Idx)
10952       ,p_event_number             => l_array_event_number(Idx)
10953       ,p_event_date               => l_array_event_date(Idx)
10954       ,p_transaction_date         => l_array_transaction_date(Idx)
10955       ,p_reference_num_1          => l_array_reference_num_1(Idx)
10956       ,p_reference_num_2          => l_array_reference_num_2(Idx)
10957       ,p_reference_num_3          => l_array_reference_num_3(Idx)
10958       ,p_reference_num_4          => l_array_reference_num_4(Idx)
10959       ,p_reference_char_1         => l_array_reference_char_1(Idx)
10960       ,p_reference_char_2         => l_array_reference_char_2(Idx)
10961       ,p_reference_char_3         => l_array_reference_char_3(Idx)
10962       ,p_reference_char_4         => l_array_reference_char_4(Idx)
10963       ,p_reference_date_1         => l_array_reference_date_1(Idx)
10964       ,p_reference_date_2         => l_array_reference_date_2(Idx)
10965       ,p_reference_date_3         => l_array_reference_date_3(Idx)
10966       ,p_reference_date_4         => l_array_reference_date_4(Idx)
10967       ,p_event_created_by         => l_array_event_created_by(Idx)
10968       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
10969        --
10970 END IF;
10971 
10972 
10973 
10974 --
10975 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
10976 
10977 l_acct_reversal_source := SUBSTR(NULL, 1,30);
10978 
10979 IF l_continue_with_lines THEN
10980    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
10981       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
10982 
10983       xla_accounting_err_pkg.build_message
10984          (p_appli_s_name            => 'XLA'
10985          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
10986          ,p_token_1                 => 'LINE_NUMBER'
10987          ,p_value_1                 => l_array_extract_line_num(Idx)
10988          ,p_token_2                 => 'PRODUCT_NAME'
10989          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
10990          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
10991          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
10992          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
10993 
10994    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
10995       --
10996       -- following sets the accounting attributes needed to reverse
10997       -- accounting for a distributeion
10998       --
10999 
11000       --
11001       -- 5217187
11002       --
11003       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
11004       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
11005                                        g_array_event(l_event_id).array_value_num('header_index'));
11006       --
11007       --
11008 
11009       -- No reversal code generated
11010 
11011       xla_ae_lines_pkg.SetAcctReversalAttrs
11012          (p_event_id             => l_event_id
11013          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
11014          ,p_calculate_acctd_flag => l_calculate_acctd_flag
11015          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
11016    END IF;
11017 
11018    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
11019        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
11020 
11021 --
11022 AcctLineType_14 (
11023  p_application_id  => p_application_id
11024  ,p_event_id     => l_event_id
11025  ,p_calculate_acctd_flag => l_calculate_acctd_flag
11026  ,p_calculate_g_l_flag => l_calculate_g_l_flag
11030  
11027  ,p_actual_flag => l_actual_flag
11028  ,p_balance_type_code => l_balance_type_code
11029  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
11031  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
11032  , p_source_2 => l_array_source_2(Idx)
11033  , p_source_3 => l_array_source_3(Idx)
11034  , p_source_4 => g_array_event(l_event_id).array_value_num('source_4')
11035  , p_source_9 => l_array_source_9(Idx)
11036  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
11037  , p_source_11 => l_array_source_11(Idx)
11038  , p_source_12 => l_array_source_12(Idx)
11039  , p_source_13 => l_array_source_13(Idx)
11040  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
11041  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
11042  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
11043  );
11044 If(l_balance_type_code = 'A') THEN
11045   l_actual_gain_loss_ref := l_gain_or_loss_ref;
11046 END IF;
11047 
11048 --
11049 
11050 
11051 --
11052 AcctLineType_15 (
11053  p_application_id  => p_application_id
11054  ,p_event_id     => l_event_id
11055  ,p_calculate_acctd_flag => l_calculate_acctd_flag
11056  ,p_calculate_g_l_flag => l_calculate_g_l_flag
11057  ,p_actual_flag => l_actual_flag
11058  ,p_balance_type_code => l_balance_type_code
11059  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
11060  
11061  , p_source_5 => g_array_event(l_event_id).array_value_num('source_5')
11062  , p_source_9 => l_array_source_9(Idx)
11063  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
11064  , p_source_11 => l_array_source_11(Idx)
11065  , p_source_12 => l_array_source_12(Idx)
11066  , p_source_13 => l_array_source_13(Idx)
11067  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
11068  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
11069  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
11070  );
11071 If(l_balance_type_code = 'A') THEN
11072   l_actual_gain_loss_ref := l_gain_or_loss_ref;
11073 END IF;
11074 
11075 --
11076 
11077       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
11078       -- or secondary ledger that has different currency with primary
11079       -- or alc that is calculated by sla
11080       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
11081             (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'))
11082 
11083 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
11084 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
11085           AND (l_actual_flag = 'A')) THEN
11086         XLA_AE_LINES_PKG.CreateGainOrLossLines(
11087           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
11088          ,p_application_id   => p_application_id
11089          ,p_amb_context_code => 'DEFAULT'
11090          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
11091          ,p_event_class_code => C_EVENT_CLASS_CODE
11092          ,p_event_type_code  => C_EVENT_TYPE_CODE
11093          
11094          ,p_gain_ccid        => -1
11095          ,p_loss_ccid        => -1
11096 
11097          ,p_actual_flag      => l_actual_flag
11098          ,p_enc_flag         => null
11099          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
11100          ,p_enc_g_l_ref      => null
11101          );
11102       END IF;
11103    END IF;
11104 END IF;
11105 
11106    ELSE
11107       --
11108       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
11109       --
11110       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11111          trace
11112             (p_msg      => 'Trancaction revesal option is Y'
11113             ,p_level    => C_LEVEL_STATEMENT
11114             ,p_module   => l_log_module);
11115       END IF;
11116    END IF;
11117 
11118 END LOOP;
11119 l_result := XLA_AE_LINES_PKG.InsertLines ;
11120 end loop;
11121 close line_cur;
11122 
11123 
11124 --
11125 -- insert headers into xla_ae_headers_gt table
11126 --
11127 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
11128 
11129 -- insert into errors table here.
11130 
11131 END LOOP;
11132 
11133 --
11134 -- 4865292
11135 --
11136 -- Compare g_hdr_extract_count with event count in
11137 -- CreateHeadersAndLines.
11138 --
11139 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
11140 
11141 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11142    trace (p_msg     => '# rows extracted from header extract objects '
11143                     || ' (running total): '
11144                     || g_hdr_extract_count
11145          ,p_level   => C_LEVEL_STATEMENT
11146          ,p_module  => l_log_module);
11147 END IF;
11148 
11149 CLOSE header_cur;
11150 --
11151 
11152 --
11153 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11154    trace
11155       (p_msg      => 'END of EventType_21'
11156       ,p_level    => C_LEVEL_PROCEDURE
11157       ,p_module   => l_log_module);
11158 END IF;
11159 --
11160 RETURN l_result;
11161 EXCEPTION
11162 WHEN xla_exceptions_pkg.application_exception THEN
11163    
11164 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
11165 
11166    
11167 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
11168 
11169    RAISE;
11170 
11171 WHEN NO_DATA_FOUND THEN
11172 
11173 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
11174 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
11175 
11176 FOR header_record IN header_cur
11177 LOOP
11181 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
11178     l_array_header_events(header_record.event_id) := header_record.event_id;
11179 END LOOP;
11180 
11182 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
11183 
11184 fnd_file.put_line(fnd_file.LOG, '                    ');
11185 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
11186 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
11187 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
11188 
11189 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
11190 LOOP
11191 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
11192 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
11193         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
11194 	END IF;
11195 END LOOP;
11196 
11197 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
11198 fnd_file.put_line(fnd_file.LOG, '                    ');
11199 
11200 
11201 xla_exceptions_pkg.raise_message
11202       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_21');
11203 
11204 
11205 WHEN OTHERS THEN
11206    xla_exceptions_pkg.raise_message
11207       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_21');
11208 END EventType_21;
11209 --
11210 
11211 ---------------------------------------
11212 --
11213 -- PRIVATE PROCEDURE
11214 --         insert_sources_22
11215 --
11216 ----------------------------------------
11217 --
11218 PROCEDURE insert_sources_22(
11219                                 p_target_ledger_id       IN NUMBER
11220                               , p_language               IN VARCHAR2
11221                               , p_sla_ledger_id          IN NUMBER
11222                               , p_pad_start_date         IN DATE
11223                               , p_pad_end_date           IN DATE
11224                          )
11225 IS
11226 
11227 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_DSTR_INC_CLAIM';
11228 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
11229 p_apps_owner                   VARCHAR2(30);
11230 l_log_module                   VARCHAR2(240);
11231 BEGIN
11232 IF g_log_enabled THEN
11233       l_log_module := C_DEFAULT_MODULE||'.insert_sources_22';
11234 END IF;
11235 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11236 
11237       trace
11238          (p_msg      => 'BEGIN of insert_sources_22'
11239          ,p_level    => C_LEVEL_PROCEDURE
11240          ,p_module   => l_log_module);
11241 
11242 END IF;
11243 
11244 -- select APPS owner
11245 SELECT oracle_username
11246   INTO p_apps_owner
11247   FROM fnd_oracle_userid
11248  WHERE read_only_flag = 'U'
11249 ;
11250 
11251 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11252       trace
11253          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
11254                         ' - p_language = '||p_language||
11255                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
11256                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
11257                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
11258                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
11259          ,p_level    => C_LEVEL_STATEMENT
11260          ,p_module   => l_log_module);
11261 END IF;
11262 
11263 
11264 --
11265 INSERT INTO xla_diag_sources --hdr1
11266 (
11267         event_id
11268       , ledger_id
11269       , sla_ledger_id
11270       , description_language
11271       , object_name
11272       , object_type_code
11273       , line_number
11274       , source_application_id
11275       , source_type_code
11276       , source_code
11277       , source_value
11278       , source_meaning
11279       , created_by
11280       , creation_date
11281       , last_update_date
11282       , last_updated_by
11283       , last_update_login
11284       , program_update_date
11285       , program_application_id
11286       , program_id
11287       , request_id
11288 )
11289 SELECT
11290         event_id
11291       , p_target_ledger_id
11292       , p_sla_ledger_id
11293       , p_language
11294       , object_name
11295       , object_type_code
11296       , line_number
11297       , source_application_id
11298       , source_type_code
11299       , source_code
11300       , SUBSTR(source_value ,1,1996)
11301       , SUBSTR(source_meaning,1,200)
11302       , xla_environment_pkg.g_Usr_Id
11303       , TRUNC(SYSDATE)
11304       , TRUNC(SYSDATE)
11305       , xla_environment_pkg.g_Usr_Id
11306       , xla_environment_pkg.g_Login_Id
11307       , TRUNC(SYSDATE)
11308       , xla_environment_pkg.g_Prog_Appl_Id
11309       , xla_environment_pkg.g_Prog_Id
11310       , xla_environment_pkg.g_Req_Id
11311   FROM (
11312        SELECT xet.event_id                  event_id
11313             , 0                             line_number
11314             , CASE r
11315                WHEN 1 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11316                 WHEN 2 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11317                 WHEN 3 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11318                 WHEN 4 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11319                 WHEN 5 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11320                 WHEN 6 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11321                 WHEN 7 THEN 'DPP_XLA_CLAIM_HEADERS_V' 
11322                 
11323                ELSE null
11324               END                           object_name
11325             , CASE r
11329                 WHEN 4 THEN 'HEADER' 
11326                 WHEN 1 THEN 'HEADER' 
11327                 WHEN 2 THEN 'HEADER' 
11328                 WHEN 3 THEN 'HEADER' 
11330                 WHEN 5 THEN 'HEADER' 
11331                 WHEN 6 THEN 'HEADER' 
11332                 WHEN 7 THEN 'HEADER' 
11333                 
11334                 ELSE null
11335               END                           object_type_code
11336             , CASE r
11337                 WHEN 1 THEN '9000' 
11338                 WHEN 2 THEN '9000' 
11339                 WHEN 3 THEN '9000' 
11340                 WHEN 4 THEN '9000' 
11341                 WHEN 5 THEN '9000' 
11342                 WHEN 6 THEN '9000' 
11343                 WHEN 7 THEN '9000' 
11344                 
11345                 ELSE null
11346               END                           source_application_id
11347             , 'S'             source_type_code
11348             , CASE r
11349                 WHEN 1 THEN 'PP_TXN_NUMBER' 
11350                 WHEN 2 THEN 'PP_ACCRUAL_CCID' 
11351                 WHEN 3 THEN 'PP_AP_CLEARING_CCID' 
11352                 WHEN 4 THEN 'DISTRIBUTION_TYPE' 
11353                 WHEN 5 THEN 'PARTY_ID' 
11354                 WHEN 6 THEN 'PARTY_SITE_ID' 
11355                 WHEN 7 THEN 'PARTY_TYPE' 
11356                 
11357                 ELSE null
11358               END                           source_code
11359             , CASE r
11360                 WHEN 1 THEN TO_CHAR(h1.PP_TXN_NUMBER)
11361                 WHEN 2 THEN TO_CHAR(h1.PP_ACCRUAL_CCID)
11362                 WHEN 3 THEN TO_CHAR(h1.PP_AP_CLEARING_CCID)
11363                 WHEN 4 THEN TO_CHAR(h1.DISTRIBUTION_TYPE)
11364                 WHEN 5 THEN TO_CHAR(h1.PARTY_ID)
11365                 WHEN 6 THEN TO_CHAR(h1.PARTY_SITE_ID)
11366                 WHEN 7 THEN TO_CHAR(h1.PARTY_TYPE)
11367                 
11368                 ELSE null
11369               END                           source_value
11370             , null              source_meaning
11371         FROM xla_events_gt     xet  
11372       , DPP_XLA_CLAIM_HEADERS_V  h1
11373             ,(select rownum r from all_objects where rownum <= 7 and owner = p_apps_owner)
11374        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
11375          AND xet.event_type_code = C_EVENT_TYPE_CODE
11376             AND h1.event_id = xet.event_id
11377 
11378 )
11379 ;
11380 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11381 
11382       trace
11383          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
11384          ,p_level    => C_LEVEL_STATEMENT
11385          ,p_module   => l_log_module);
11386 
11387 END IF;
11388 --
11389 
11390 
11391 
11392 --
11393 INSERT INTO xla_diag_sources --line1
11394 (
11395         event_id
11396       , ledger_id
11397       , sla_ledger_id
11398       , description_language
11399       , object_name
11400       , object_type_code
11401       , line_number
11402       , source_application_id
11403       , source_type_code
11404       , source_code
11405       , source_value
11406       , source_meaning
11407       , created_by
11408       , creation_date
11409       , last_update_date
11410       , last_updated_by
11411       , last_update_login
11412       , program_update_date
11413       , program_application_id
11414       , program_id
11415       , request_id
11416 )
11417 SELECT  event_id
11418       , p_target_ledger_id
11419       , p_sla_ledger_id
11420       , p_language
11421       , object_name
11422       , object_type_code
11423       , line_number
11424       , source_application_id
11425       , source_type_code
11426       , source_code
11427       , SUBSTR(source_value,1,1996)
11428       , SUBSTR(source_meaning,1,200)
11429       , xla_environment_pkg.g_Usr_Id
11430       , TRUNC(SYSDATE)
11431       , TRUNC(SYSDATE)
11432       , xla_environment_pkg.g_Usr_Id
11433       , xla_environment_pkg.g_Login_Id
11434       , TRUNC(SYSDATE)
11435       , xla_environment_pkg.g_Prog_Appl_Id
11436       , xla_environment_pkg.g_Prog_Id
11437       , xla_environment_pkg.g_Req_Id
11438   FROM (
11439        SELECT xet.event_id                  event_id
11440             , l2.line_number                 line_number
11441             , CASE r
11442                WHEN 1 THEN 'DPP_XLA_CLAIM_LINES_V' 
11443                 WHEN 2 THEN 'DPP_XLA_CLAIM_LINES_V' 
11444                 WHEN 3 THEN 'DPP_XLA_CLAIM_LINES_V' 
11445                 WHEN 4 THEN 'DPP_XLA_CLAIM_LINES_V' 
11446                 WHEN 5 THEN 'DPP_XLA_CLAIM_LINES_V' 
11447                 WHEN 6 THEN 'DPP_XLA_CLAIM_LINES_V' 
11448                 
11449                ELSE null
11450               END                           object_name
11451             , CASE r
11452                 WHEN 1 THEN 'LINE' 
11453                 WHEN 2 THEN 'LINE' 
11454                 WHEN 3 THEN 'LINE' 
11455                 WHEN 4 THEN 'LINE' 
11456                 WHEN 5 THEN 'LINE' 
11457                 WHEN 6 THEN 'LINE' 
11458                 
11459                 ELSE null
11460               END                           object_type_code
11461             , CASE r
11462                 WHEN 1 THEN '9000' 
11463                 WHEN 2 THEN '9000' 
11464                 WHEN 3 THEN '9000' 
11465                 WHEN 4 THEN '9000' 
11466                 WHEN 5 THEN '9000' 
11467                 WHEN 6 THEN '9000' 
11468                 
11469                 ELSE null
11470               END                           source_application_id
11471             , 'S'             source_type_code
11472             , CASE r
11473                 WHEN 1 THEN 'CLAIM_NUMBER' 
11474                 WHEN 2 THEN 'ITEM_NUMBER' 
11478                 WHEN 6 THEN 'ACCOUNTED_AMOUNT' 
11475                 WHEN 3 THEN 'DISTRIBUTION_IDENTIFIER' 
11476                 WHEN 4 THEN 'ENTERED_AMOUNT' 
11477                 WHEN 5 THEN 'CURRENCY_CODE' 
11479                 
11480                 ELSE null
11481               END                           source_code
11482             , CASE r
11483                 WHEN 1 THEN TO_CHAR(l2.CLAIM_NUMBER)
11484                 WHEN 2 THEN TO_CHAR(l2.ITEM_NUMBER)
11485                 WHEN 3 THEN TO_CHAR(l2.DISTRIBUTION_IDENTIFIER)
11486                 WHEN 4 THEN TO_CHAR(l2.ENTERED_AMOUNT)
11487                 WHEN 5 THEN TO_CHAR(l2.CURRENCY_CODE)
11488                 WHEN 6 THEN TO_CHAR(l2.ACCOUNTED_AMOUNT)
11489                 
11490                 ELSE null
11491               END                           source_value
11492             , null              source_meaning
11493          FROM  xla_events_gt     xet  
11494         , DPP_XLA_CLAIM_LINES_V  l2
11495             ,(select rownum r from all_objects where rownum <= 6 and owner = p_apps_owner)
11496         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
11497           AND xet.event_type_code = C_EVENT_TYPE_CODE
11498             AND l2.event_id          = xet.event_id
11499 
11500 )
11501 ;
11502 --
11503 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11504 
11505       trace
11506          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
11507          ,p_level    => C_LEVEL_STATEMENT
11508          ,p_module   => l_log_module);
11509 
11510 END IF;
11511 
11512 
11513 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11514       trace
11515          (p_msg      => 'END of insert_sources_22'
11516          ,p_level    => C_LEVEL_PROCEDURE
11517          ,p_module   => l_log_module);
11518 END IF;
11519 EXCEPTION
11520   WHEN xla_exceptions_pkg.application_exception THEN
11521       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11522             trace
11523                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
11524                ,p_level    => C_LEVEL_EXCEPTION
11525                ,p_module   => l_log_module);
11526       END IF;
11527       RAISE;
11528   WHEN OTHERS THEN
11529       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
11530             trace
11531                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
11532                ,p_level    => C_LEVEL_EXCEPTION
11533                ,p_module   => l_log_module);
11534        END IF;
11535        xla_exceptions_pkg.raise_message
11536            (p_location => 'XLA_09000_AAD_S_000015_PKG.insert_sources_22');
11537 END insert_sources_22;
11538 --
11539 
11540 ---------------------------------------
11541 --
11542 -- PRIVATE FUNCTION
11543 --         EventType_22
11544 --
11545 ----------------------------------------
11546 --
11547 FUNCTION EventType_22
11548        (p_application_id         IN NUMBER
11549        ,p_base_ledger_id         IN NUMBER
11550        ,p_target_ledger_id       IN NUMBER
11551        ,p_language               IN VARCHAR2
11552        ,p_currency_code          IN VARCHAR2
11553        ,p_sla_ledger_id          IN NUMBER
11554        ,p_pad_start_date         IN DATE
11555        ,p_pad_end_date           IN DATE
11556        ,p_primary_ledger_id      IN NUMBER)
11557 RETURN BOOLEAN IS
11558 --
11559 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'SUPPLIER_DSTR_INC_CLAIM';
11560 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'CLAIM_SETTLEMENT';
11561 
11562 l_calculate_acctd_flag   VARCHAR2(1) :='N';
11563 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
11564 --
11565 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11566 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11567 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11568 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11569 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11570 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11571 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11572 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11573 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11574 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11575 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11576 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11577 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11578 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
11579 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11580 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11581 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11582 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
11583 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11584 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11585 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11586 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
11587 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
11588 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
11589 l_array_header_events                  XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
11590 l_array_duplicate_checker              XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;  --added
11591 
11592 l_event_id                             NUMBER;
11593 l_previous_event_id                    NUMBER;
11594 l_first_event_id                       NUMBER;
11595 l_last_event_id                        NUMBER;
11596 
11600 --
11597 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
11598 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
11599 --
11601 l_result                    BOOLEAN := TRUE;
11602 l_rows                      NUMBER  := 1000;
11603 l_event_type_name           VARCHAR2(80) := 'Distributor Claim to Supplier for Inventory on hand for Price Increase';
11604 l_event_class_name          VARCHAR2(80) := 'Claim Settlement';
11605 l_description               VARCHAR2(4000);
11606 l_transaction_reversal      NUMBER;
11607 l_ae_header_id              NUMBER;
11608 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
11609 l_log_module                VARCHAR2(240);
11610 --
11611 l_acct_reversal_source      VARCHAR2(30);
11612 l_trx_reversal_source       VARCHAR2(30);
11613 
11614 l_continue_with_lines       BOOLEAN := TRUE;
11615 --
11616 l_acc_rev_gl_date_source    DATE;                      -- 4262811
11617 --
11618 type t_array_event_id is table of number index by binary_integer;
11619 
11620 l_rec_array_event                    t_rec_array_event;
11621 l_null_rec_array_event               t_rec_array_event;
11622 l_array_ae_header_id                 xla_number_array_type;
11623 l_actual_flag                        VARCHAR2(1) := NULL;
11624 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
11625 l_balance_type_code                  VARCHAR2(1) :=NULL;
11626 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
11627 
11628 --
11629 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
11630 --
11631 
11632 TYPE t_array_source_1 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_TXN_NUMBER%TYPE INDEX BY BINARY_INTEGER;
11633 TYPE t_array_source_4 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_ACCRUAL_CCID%TYPE INDEX BY BINARY_INTEGER;
11634 TYPE t_array_source_5 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PP_AP_CLEARING_CCID%TYPE INDEX BY BINARY_INTEGER;
11635 TYPE t_array_source_10 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.DISTRIBUTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
11636 TYPE t_array_source_14 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_ID%TYPE INDEX BY BINARY_INTEGER;
11637 TYPE t_array_source_15 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_SITE_ID%TYPE INDEX BY BINARY_INTEGER;
11638 TYPE t_array_source_16 IS TABLE OF DPP_XLA_CLAIM_HEADERS_V.PARTY_TYPE%TYPE INDEX BY BINARY_INTEGER;
11639 
11640 TYPE t_array_source_2 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CLAIM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
11641 TYPE t_array_source_3 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ITEM_NUMBER%TYPE INDEX BY BINARY_INTEGER;
11642 TYPE t_array_source_9 IS TABLE OF DPP_XLA_CLAIM_LINES_V.DISTRIBUTION_IDENTIFIER%TYPE INDEX BY BINARY_INTEGER;
11643 TYPE t_array_source_11 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ENTERED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
11644 TYPE t_array_source_12 IS TABLE OF DPP_XLA_CLAIM_LINES_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
11645 TYPE t_array_source_13 IS TABLE OF DPP_XLA_CLAIM_LINES_V.ACCOUNTED_AMOUNT%TYPE INDEX BY BINARY_INTEGER;
11646 
11647 l_array_source_1              t_array_source_1;
11648 l_array_source_4              t_array_source_4;
11649 l_array_source_5              t_array_source_5;
11650 l_array_source_10              t_array_source_10;
11651 l_array_source_14              t_array_source_14;
11652 l_array_source_15              t_array_source_15;
11653 l_array_source_16              t_array_source_16;
11654 
11655 l_array_source_2      t_array_source_2;
11656 l_array_source_3      t_array_source_3;
11657 l_array_source_9      t_array_source_9;
11658 l_array_source_11      t_array_source_11;
11659 l_array_source_12      t_array_source_12;
11660 l_array_source_13      t_array_source_13;
11661 
11662 --
11663 CURSOR header_cur
11664 IS
11665 SELECT /*+ leading(xet) cardinality(xet,1) */
11666 -- Event Type Code: SUPPLIER_DSTR_INC_CLAIM
11667 -- Event Class Code: CLAIM_SETTLEMENT
11668     xet.entity_id
11669   , xet.legal_entity_id
11670   , xet.entity_code
11671   , xet.transaction_number
11672   , xet.event_id
11673   , xet.event_class_code
11674   , xet.event_type_code
11675   , xet.event_number
11676   , xet.event_date
11677   , xet.transaction_date
11678   , xet.reference_num_1
11679   , xet.reference_num_2
11680   , xet.reference_num_3
11681   , xet.reference_num_4
11682   , xet.reference_char_1
11683   , xet.reference_char_2
11684   , xet.reference_char_3
11685   , xet.reference_char_4
11686   , xet.reference_date_1
11687   , xet.reference_date_2
11688   , xet.reference_date_3
11689   , xet.reference_date_4
11690   , xet.event_created_by
11691   , xet.budgetary_control_flag 
11692   , h1.PP_TXN_NUMBER    source_1
11693   , h1.PP_ACCRUAL_CCID    source_4
11694   , h1.PP_AP_CLEARING_CCID    source_5
11695   , h1.DISTRIBUTION_TYPE    source_10
11696   , h1.PARTY_ID    source_14
11697   , h1.PARTY_SITE_ID    source_15
11698   , h1.PARTY_TYPE    source_16
11699   FROM xla_events_gt     xet 
11700   , DPP_XLA_CLAIM_HEADERS_V  h1
11701  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
11702    and xet.event_type_code = C_EVENT_TYPE_CODE
11703    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
11704 
11705  ORDER BY event_id
11706 ;
11707 
11708 
11709 --
11710 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
11711 IS
11712 SELECT /*+ leading(xet) cardinality(xet,1) */
11713 -- Event Type Code: SUPPLIER_DSTR_INC_CLAIM
11714 -- Event Class Code: CLAIM_SETTLEMENT
11715     xet.entity_id
11716    ,xet.legal_entity_id
11717    ,xet.entity_code
11718    ,xet.transaction_number
11719    ,xet.event_id
11720    ,xet.event_class_code
11721    ,xet.event_type_code
11722    ,xet.event_number
11723    ,xet.event_date
11724    ,xet.transaction_date
11725    ,xet.reference_num_1
11726    ,xet.reference_num_2
11727    ,xet.reference_num_3
11728    ,xet.reference_num_4
11729    ,xet.reference_char_1
11733    ,xet.reference_date_1
11730    ,xet.reference_char_2
11731    ,xet.reference_char_3
11732    ,xet.reference_char_4
11734    ,xet.reference_date_2
11735    ,xet.reference_date_3
11736    ,xet.reference_date_4
11737    ,xet.event_created_by
11738    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
11739   , l2.CLAIM_NUMBER    source_2
11740   , l2.ITEM_NUMBER    source_3
11741   , l2.DISTRIBUTION_IDENTIFIER    source_9
11742   , l2.ENTERED_AMOUNT    source_11
11743   , l2.CURRENCY_CODE    source_12
11744   , l2.ACCOUNTED_AMOUNT    source_13
11745   FROM xla_events_gt     xet 
11746   , DPP_XLA_CLAIM_LINES_V  l2
11747  WHERE xet.event_id between x_first_event_id and x_last_event_id
11748    and xet.event_date between p_pad_start_date and p_pad_end_date
11749    and xet.event_type_code = C_EVENT_TYPE_CODE
11750    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
11751 ;
11752 
11753 --
11754 BEGIN
11755 IF g_log_enabled THEN
11756    l_log_module := C_DEFAULT_MODULE||'.EventType_22';
11757 END IF;
11758 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
11759    trace
11760       (p_msg      => 'BEGIN of EventType_22'
11761       ,p_level    => C_LEVEL_PROCEDURE
11762       ,p_module   => l_log_module);
11763 END IF;
11764 
11765 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11766    trace
11767       (p_msg      => 'p_application_id = '||p_application_id||
11768                      ' - p_base_ledger_id = '||p_base_ledger_id||
11769                      ' - p_target_ledger_id  = '||p_target_ledger_id||
11770                      ' - p_language = '||p_language||
11771                      ' - p_currency_code = '||p_currency_code||
11772                      ' - p_sla_ledger_id = '||p_sla_ledger_id
11773       ,p_level    => C_LEVEL_STATEMENT
11774       ,p_module   => l_log_module);
11775 END IF;
11776 --
11777 -- initialze arrays
11778 --
11779 g_array_event.DELETE;
11780 l_rec_array_event := l_null_rec_array_event;
11781 --
11782 --------------------------------------
11783 -- 4262811 Initialze MPA Line Number
11784 --------------------------------------
11785 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
11786 
11787 --
11788 
11789 --
11790 OPEN header_cur;
11791 --
11792 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
11793    trace
11794    (p_msg      => 'SQL - FETCH header_cur'
11795    ,p_level    => C_LEVEL_STATEMENT
11796    ,p_module   => l_log_module);
11797 END IF;
11798 --
11799 LOOP
11800 FETCH header_cur BULK COLLECT INTO
11801         l_array_entity_id
11802       , l_array_legal_entity_id
11803       , l_array_entity_code
11804       , l_array_transaction_num
11805       , l_array_event_id
11806       , l_array_class_code
11807       , l_array_event_type
11808       , l_array_event_number
11809       , l_array_event_date
11810       , l_array_transaction_date
11811       , l_array_reference_num_1
11812       , l_array_reference_num_2
11813       , l_array_reference_num_3
11814       , l_array_reference_num_4
11815       , l_array_reference_char_1
11816       , l_array_reference_char_2
11817       , l_array_reference_char_3
11818       , l_array_reference_char_4
11819       , l_array_reference_date_1
11820       , l_array_reference_date_2
11821       , l_array_reference_date_3
11822       , l_array_reference_date_4
11823       , l_array_event_created_by
11824       , l_array_budgetary_control_flag 
11825       , l_array_source_1
11826       , l_array_source_4
11827       , l_array_source_5
11828       , l_array_source_10
11829       , l_array_source_14
11830       , l_array_source_15
11831       , l_array_source_16
11832       LIMIT l_rows;
11833 --
11834 IF (C_LEVEL_EVENT >= g_log_level) THEN
11835    trace
11836    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
11837    ,p_level    => C_LEVEL_EVENT
11838    ,p_module   => l_log_module);
11839 END IF;
11840 --
11841 EXIT WHEN l_array_entity_id.COUNT = 0;
11842 
11843 -- initialize arrays
11844 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
11845 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
11846 
11847 --
11848 -- Bug 4458708
11849 --
11850 XLA_AE_LINES_PKG.g_LineNumber := 0;
11851 
11852 
11853 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
11854 g_last_hdr_idx := l_array_event_id.LAST;
11855 --
11856 -- loop for the headers. Each iteration is for each header extract row
11857 -- fetched in header cursor
11858 --
11859 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
11860 
11861 --
11862 -- set event info as cache for other routines to refer event attributes
11863 --
11864 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
11865    (p_application_id           => p_application_id
11866    ,p_primary_ledger_id        => p_primary_ledger_id
11867    ,p_base_ledger_id           => p_base_ledger_id
11868    ,p_target_ledger_id         => p_target_ledger_id
11869    ,p_entity_id                => l_array_entity_id(hdr_idx)
11870    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
11871    ,p_entity_code              => l_array_entity_code(hdr_idx)
11872    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
11873    ,p_event_id                 => l_array_event_id(hdr_idx)
11874    ,p_event_class_code         => l_array_class_code(hdr_idx)
11875    ,p_event_type_code          => l_array_event_type(hdr_idx)
11876    ,p_event_number             => l_array_event_number(hdr_idx)
11877    ,p_event_date               => l_array_event_date(hdr_idx)
11878    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
11879    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
11880    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
11884    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
11881    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
11882    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
11883    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
11885    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
11886    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
11887    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
11888    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
11889    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
11890    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
11891    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
11892    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
11893 
11894 --
11895 -- set the status of entry to C_VALID (0)
11896 --
11897 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
11898 
11899 --
11900 -- initialize a row for ae header
11901 --
11902 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
11903 
11904 l_event_id := l_array_event_id(hdr_idx);
11905 
11906 --
11907 -- storing the hdr_idx for event. May be used by line cursor.
11908 --
11909 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
11910 
11911 --
11912 -- store sources from header extract. This can be improved to
11913 -- store only those sources from header extract that may be used in lines
11914 --
11915 
11916 g_array_event(l_event_id).array_value_char('source_1') := l_array_source_1(hdr_idx);
11917 g_array_event(l_event_id).array_value_num('source_4') := l_array_source_4(hdr_idx);
11918 g_array_event(l_event_id).array_value_num('source_5') := l_array_source_5(hdr_idx);
11919 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
11920 g_array_event(l_event_id).array_value_num('source_14') := l_array_source_14(hdr_idx);
11921 g_array_event(l_event_id).array_value_num('source_15') := l_array_source_15(hdr_idx);
11922 g_array_event(l_event_id).array_value_char('source_16') := l_array_source_16(hdr_idx);
11923 
11924 --
11925 -- initilaize the status of ae headers for diffrent balance types
11926 -- the status is initialised to C_NOT_CREATED (2)
11927 --
11928 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
11929 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
11930 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
11931 
11932 --
11933 -- call api to validate and store accounting attributes for header
11934 --
11935 
11936 ------------------------------------------------------------
11937 -- Accrual Reversal : to get date for Standard Source (NONE)
11938 ------------------------------------------------------------
11939 l_acc_rev_gl_date_source := NULL;
11940 
11941      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
11942       l_rec_acct_attrs.array_date_value(1) := 
11943 xla_ae_sources_pkg.GetSystemSourceDate(
11944    p_source_code           => 'XLA_TRANSACTION_DATE'
11945  , p_source_type_code      => 'Y'
11946  , p_source_application_id =>  602
11947 );
11948 
11949 
11950 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
11951 
11952 XLA_AE_HEADER_PKG.SetJeCategoryName;
11953 
11954 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
11955 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
11956 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
11957 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
11958 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
11959 
11960 
11961 -- No header level analytical criteria
11962 
11963 --
11964 --accounting attribute enhancement, bug 3612931
11965 --
11966 l_trx_reversal_source := SUBSTR(NULL, 1,30);
11967 
11968 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
11969    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
11970 
11971    xla_accounting_err_pkg.build_message
11972       (p_appli_s_name            => 'XLA'
11973       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
11974       ,p_token_1                 => 'ACCT_ATTR_NAME'
11975       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
11976       ,p_token_2                 => 'PRODUCT_NAME'
11977       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
11978       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
11979       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
11980       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
11981 
11982 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
11983    --
11984    -- following sets the accounting attributes needed to reverse
11985    -- accounting for a distributeion
11986    --
11987    xla_ae_lines_pkg.SetTrxReversalAttrs
11988       (p_event_id              => l_event_id
11989       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
11990       ,p_trx_reversal_source   => l_trx_reversal_source);
11991 
11992 END IF;
11993 
11994 
11995 ----------------------------------------------------------------
11996 -- 4262811 -  update the header statuses to invalid in need be
11997 ----------------------------------------------------------------
11998 --
11999 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
12000 
12001 
12002   -----------------------------------------------
12006 
12003   -- No accrual reversal for the event class/type
12004   -----------------------------------------------
12005 ----------------------------------------------------------------
12007 --
12008 -- this ends the header loop iteration for one bulk fetch
12009 --
12010 END LOOP;
12011 
12012 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
12013 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
12014 
12015 --
12016 -- insert dummy rows into lines gt table that were created due to
12017 -- transaction reversals
12018 --
12019 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
12020    l_result := XLA_AE_LINES_PKG.InsertLines;
12021 END IF;
12022 
12023 --
12024 -- reset the temp_line_num for each set of events fetched from header
12025 -- cursor rather than doing it for each new event in line cursor
12026 -- Bug 3939231
12027 --
12028 xla_ae_lines_pkg.g_temp_line_num := 0;
12029 
12030 
12031 
12032 --
12033 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
12034 --
12035 --
12036 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12037 
12038       trace
12039          (p_msg      => 'SQL - FETCH line_cur'
12040          ,p_level    => C_LEVEL_STATEMENT
12041          ,p_module   => l_log_module);
12042 
12043 END IF;
12044 --
12045 --
12046 LOOP
12047   --
12048   FETCH line_cur BULK COLLECT INTO
12049         l_array_entity_id
12050       , l_array_legal_entity_id
12051       , l_array_entity_code
12052       , l_array_transaction_num
12053       , l_array_event_id
12054       , l_array_class_code
12055       , l_array_event_type
12056       , l_array_event_number
12057       , l_array_event_date
12058       , l_array_transaction_date
12059       , l_array_reference_num_1
12060       , l_array_reference_num_2
12061       , l_array_reference_num_3
12062       , l_array_reference_num_4
12063       , l_array_reference_char_1
12064       , l_array_reference_char_2
12065       , l_array_reference_char_3
12066       , l_array_reference_char_4
12067       , l_array_reference_date_1
12068       , l_array_reference_date_2
12069       , l_array_reference_date_3
12070       , l_array_reference_date_4
12071       , l_array_event_created_by
12072       , l_array_budgetary_control_flag
12073       , l_array_extract_line_num 
12074       , l_array_source_2
12075       , l_array_source_3
12076       , l_array_source_9
12077       , l_array_source_11
12078       , l_array_source_12
12079       , l_array_source_13
12080       LIMIT l_rows;
12081 
12082   --
12083   IF (C_LEVEL_EVENT >= g_log_level) THEN
12084             trace
12085                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
12086                ,p_level    => C_LEVEL_EVENT
12087                ,p_module   => l_log_module);
12088   END IF;
12089   --
12090   EXIT WHEN l_array_entity_id.count = 0;
12091 
12092   XLA_AE_LINES_PKG.g_rec_lines := null;
12093 
12094 --
12095 -- Bug 4458708
12096 --
12097 XLA_AE_LINES_PKG.g_LineNumber := 0;
12098 --
12099 --
12100 
12101 FOR Idx IN 1..l_array_event_id.count LOOP
12102    --
12103    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
12104    --
12105    l_event_id := l_array_event_id(idx);  -- 5648433
12106 
12107    --
12108    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
12109    --
12110 
12111    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
12112              (g_array_event(l_event_id).array_value_num('header_index'))
12113          ,'N'
12114          ) <> 'Y'
12115    THEN
12116       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12117          trace
12118             (p_msg      => 'Trancaction revesal option is not Y '
12119             ,p_level    => C_LEVEL_STATEMENT
12120             ,p_module   => l_log_module);
12121       END IF;
12122 
12123 --
12124 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
12125 --
12126 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
12127 --
12128 -- set event info as cache for other routines to refer event attributes
12129 --
12130 
12131 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
12132    l_previous_event_id := l_event_id;
12133 
12134    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
12135       (p_application_id           => p_application_id
12136       ,p_primary_ledger_id        => p_primary_ledger_id
12137       ,p_base_ledger_id           => p_base_ledger_id
12138       ,p_target_ledger_id         => p_target_ledger_id
12139       ,p_entity_id                => l_array_entity_id(Idx)
12140       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
12141       ,p_entity_code              => l_array_entity_code(Idx)
12142       ,p_transaction_num          => l_array_transaction_num(Idx)
12143       ,p_event_id                 => l_array_event_id(Idx)
12144       ,p_event_class_code         => l_array_class_code(Idx)
12145       ,p_event_type_code          => l_array_event_type(Idx)
12146       ,p_event_number             => l_array_event_number(Idx)
12147       ,p_event_date               => l_array_event_date(Idx)
12148       ,p_transaction_date         => l_array_transaction_date(Idx)
12149       ,p_reference_num_1          => l_array_reference_num_1(Idx)
12150       ,p_reference_num_2          => l_array_reference_num_2(Idx)
12151       ,p_reference_num_3          => l_array_reference_num_3(Idx)
12152       ,p_reference_num_4          => l_array_reference_num_4(Idx)
12153       ,p_reference_char_1         => l_array_reference_char_1(Idx)
12154       ,p_reference_char_2         => l_array_reference_char_2(Idx)
12158       ,p_reference_date_2         => l_array_reference_date_2(Idx)
12155       ,p_reference_char_3         => l_array_reference_char_3(Idx)
12156       ,p_reference_char_4         => l_array_reference_char_4(Idx)
12157       ,p_reference_date_1         => l_array_reference_date_1(Idx)
12159       ,p_reference_date_3         => l_array_reference_date_3(Idx)
12160       ,p_reference_date_4         => l_array_reference_date_4(Idx)
12161       ,p_event_created_by         => l_array_event_created_by(Idx)
12162       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
12163        --
12164 END IF;
12165 
12166 
12167 
12168 --
12169 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
12170 
12171 l_acct_reversal_source := SUBSTR(NULL, 1,30);
12172 
12173 IF l_continue_with_lines THEN
12174    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
12175       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
12176 
12177       xla_accounting_err_pkg.build_message
12178          (p_appli_s_name            => 'XLA'
12179          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
12180          ,p_token_1                 => 'LINE_NUMBER'
12181          ,p_value_1                 => l_array_extract_line_num(Idx)
12182          ,p_token_2                 => 'PRODUCT_NAME'
12183          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
12184          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
12185          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
12186          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
12187 
12188    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
12189       --
12190       -- following sets the accounting attributes needed to reverse
12191       -- accounting for a distributeion
12192       --
12193 
12194       --
12195       -- 5217187
12196       --
12197       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
12198       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
12199                                        g_array_event(l_event_id).array_value_num('header_index'));
12200       --
12201       --
12202 
12203       -- No reversal code generated
12204 
12205       xla_ae_lines_pkg.SetAcctReversalAttrs
12206          (p_event_id             => l_event_id
12207          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
12208          ,p_calculate_acctd_flag => l_calculate_acctd_flag
12209          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
12210    END IF;
12211 
12212    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
12213        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
12214 
12215 --
12216 AcctLineType_16 (
12217  p_application_id  => p_application_id
12218  ,p_event_id     => l_event_id
12219  ,p_calculate_acctd_flag => l_calculate_acctd_flag
12220  ,p_calculate_g_l_flag => l_calculate_g_l_flag
12221  ,p_actual_flag => l_actual_flag
12222  ,p_balance_type_code => l_balance_type_code
12223  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
12224  
12225  , p_source_5 => g_array_event(l_event_id).array_value_num('source_5')
12226  , p_source_9 => l_array_source_9(Idx)
12227  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
12228  , p_source_11 => l_array_source_11(Idx)
12229  , p_source_12 => l_array_source_12(Idx)
12230  , p_source_13 => l_array_source_13(Idx)
12231  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
12232  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
12233  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
12234  );
12235 If(l_balance_type_code = 'A') THEN
12236   l_actual_gain_loss_ref := l_gain_or_loss_ref;
12237 END IF;
12238 
12239 --
12240 
12241 
12242 --
12243 AcctLineType_17 (
12244  p_application_id  => p_application_id
12245  ,p_event_id     => l_event_id
12246  ,p_calculate_acctd_flag => l_calculate_acctd_flag
12247  ,p_calculate_g_l_flag => l_calculate_g_l_flag
12248  ,p_actual_flag => l_actual_flag
12249  ,p_balance_type_code => l_balance_type_code
12250  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
12251  
12252  , p_source_1 => g_array_event(l_event_id).array_value_char('source_1')
12253  , p_source_2 => l_array_source_2(Idx)
12254  , p_source_3 => l_array_source_3(Idx)
12255  , p_source_4 => g_array_event(l_event_id).array_value_num('source_4')
12256  , p_source_9 => l_array_source_9(Idx)
12257  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
12258  , p_source_11 => l_array_source_11(Idx)
12259  , p_source_12 => l_array_source_12(Idx)
12260  , p_source_13 => l_array_source_13(Idx)
12261  , p_source_14 => g_array_event(l_event_id).array_value_num('source_14')
12262  , p_source_15 => g_array_event(l_event_id).array_value_num('source_15')
12263  , p_source_16 => g_array_event(l_event_id).array_value_char('source_16')
12264  );
12265 If(l_balance_type_code = 'A') THEN
12266   l_actual_gain_loss_ref := l_gain_or_loss_ref;
12267 END IF;
12268 
12269 --
12270 
12271       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
12272       -- or secondary ledger that has different currency with primary
12273       -- or alc that is calculated by sla
12274       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
12275             (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'))
12276 
12277 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
12278 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
12279           AND (l_actual_flag = 'A')) THEN
12283          ,p_amb_context_code => 'DEFAULT'
12280         XLA_AE_LINES_PKG.CreateGainOrLossLines(
12281           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
12282          ,p_application_id   => p_application_id
12284          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
12285          ,p_event_class_code => C_EVENT_CLASS_CODE
12286          ,p_event_type_code  => C_EVENT_TYPE_CODE
12287          
12288          ,p_gain_ccid        => -1
12289          ,p_loss_ccid        => -1
12290 
12291          ,p_actual_flag      => l_actual_flag
12292          ,p_enc_flag         => null
12293          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
12294          ,p_enc_g_l_ref      => null
12295          );
12296       END IF;
12297    END IF;
12298 END IF;
12299 
12300    ELSE
12301       --
12302       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
12303       --
12304       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12305          trace
12306             (p_msg      => 'Trancaction revesal option is Y'
12307             ,p_level    => C_LEVEL_STATEMENT
12308             ,p_module   => l_log_module);
12309       END IF;
12310    END IF;
12311 
12312 END LOOP;
12313 l_result := XLA_AE_LINES_PKG.InsertLines ;
12314 end loop;
12315 close line_cur;
12316 
12317 
12318 --
12319 -- insert headers into xla_ae_headers_gt table
12320 --
12321 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
12322 
12323 -- insert into errors table here.
12324 
12325 END LOOP;
12326 
12327 --
12328 -- 4865292
12329 --
12330 -- Compare g_hdr_extract_count with event count in
12331 -- CreateHeadersAndLines.
12332 --
12333 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
12334 
12335 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12336    trace (p_msg     => '# rows extracted from header extract objects '
12337                     || ' (running total): '
12338                     || g_hdr_extract_count
12339          ,p_level   => C_LEVEL_STATEMENT
12340          ,p_module  => l_log_module);
12341 END IF;
12342 
12343 CLOSE header_cur;
12344 --
12345 
12346 --
12347 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12348    trace
12349       (p_msg      => 'END of EventType_22'
12350       ,p_level    => C_LEVEL_PROCEDURE
12351       ,p_module   => l_log_module);
12352 END IF;
12353 --
12354 RETURN l_result;
12355 EXCEPTION
12356 WHEN xla_exceptions_pkg.application_exception THEN
12357    
12358 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
12359 
12360    
12361 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
12362 
12363    RAISE;
12364 
12365 WHEN NO_DATA_FOUND THEN
12366 
12367 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
12368 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
12369 
12370 FOR header_record IN header_cur
12371 LOOP
12372     l_array_header_events(header_record.event_id) := header_record.event_id;
12373 END LOOP;
12374 
12375 l_first_event_id := l_array_header_events(l_array_header_events.FIRST);
12376 l_last_event_id := l_array_header_events(l_array_header_events.LAST);
12377 
12378 fnd_file.put_line(fnd_file.LOG, '                    ');
12379 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
12380 fnd_file.put_line(fnd_file.LOG, 'EVENT CLASS CODE = ' || C_EVENT_CLASS_CODE );
12381 fnd_file.put_line(fnd_file.LOG, 'The following events are present in the line extract but MISSING in the header extract: ');
12382 
12383 FOR line_record IN line_cur(l_first_event_id, l_last_event_id)
12384 LOOP
12385 	IF (NOT l_array_header_events.EXISTS(line_record.event_id))  AND (NOT l_array_duplicate_checker.EXISTS(line_record.event_id)) THEN
12386 	fnd_file.put_line(fnd_file.log, 'Event_id = ' || line_record.event_id);
12387         l_array_duplicate_checker(line_record.event_id) := line_record.event_id;
12388 	END IF;
12389 END LOOP;
12390 
12391 fnd_file.put_line(fnd_file.LOG, '***************************************************************************');
12392 fnd_file.put_line(fnd_file.LOG, '                    ');
12393 
12394 
12395 xla_exceptions_pkg.raise_message
12396       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_22');
12397 
12398 
12399 WHEN OTHERS THEN
12400    xla_exceptions_pkg.raise_message
12401       (p_location => 'XLA_09000_AAD_S_000015_PKG.EventType_22');
12402 END EventType_22;
12403 --
12404 
12405 --
12406 --+============================================+
12407 --|                                            |
12408 --|  PRIVATE FUNCTION                          |
12409 --|                                            |
12410 --+============================================+
12411 --
12412 FUNCTION CreateHeadersAndLines
12413        (p_application_id         IN NUMBER
12414        ,p_base_ledger_id         IN NUMBER
12415        ,p_target_ledger_id       IN NUMBER
12416        ,p_pad_start_date         IN DATE
12417        ,p_pad_end_date           IN DATE
12418        ,p_primary_ledger_id      IN NUMBER)
12419 RETURN BOOLEAN IS
12420 l_created                   BOOLEAN:=FALSE;
12421 l_event_id                  NUMBER;
12422 l_event_date                DATE;
12423 l_language                  VARCHAR2(30);
12424 l_currency_code             VARCHAR2(30);
12425 l_sla_ledger_id             NUMBER;
12426 l_log_module                VARCHAR2(240);
12427 
12428 BEGIN
12429 --
12430 IF g_log_enabled THEN
12431    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
12432 END IF;
12433 --
12434 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12435    trace
12436       (p_msg      => 'BEGIN of CreateHeadersAndLines'
12440 
12437       ,p_level    => C_LEVEL_PROCEDURE
12438       ,p_module   => l_log_module);
12439 END IF;
12441 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
12442 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
12443 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
12444 
12445 --
12446 -- initialize array of lines with NULL
12447 --
12448 xla_ae_lines_pkg.SetNullLine;
12449 
12450 --
12451 -- initialize header extract count -- Bug 4865292
12452 --
12453 g_hdr_extract_count:= 0;
12454 
12455 
12456 l_created := EventClass_18(
12457    p_application_id         => p_application_id
12458  , p_base_ledger_id         => p_base_ledger_id
12459  , p_target_ledger_id       => p_target_ledger_id
12460  , p_language               => l_language
12461  , p_currency_code          => l_currency_code
12462  , p_sla_ledger_id          => l_sla_ledger_id
12463  , p_pad_start_date         => p_pad_start_date
12464  , p_pad_end_date           => p_pad_end_date
12465  , p_primary_ledger_id      => p_primary_ledger_id
12466 );
12467 
12468 
12469 
12470      IF ( g_diagnostics_mode ='Y' ) THEN
12471 
12472          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12473           trace
12474               (p_msg      => 'CALL Transaction Objects Diagnostics'
12475               ,p_level    => C_LEVEL_STATEMENT
12476               ,p_module   => l_log_module);
12477 
12478          END IF;
12479 
12480          insert_sources_18(
12481                           p_target_ledger_id => p_target_ledger_id
12482                         , p_language         => l_language
12483                         , p_sla_ledger_id    => l_sla_ledger_id
12484                         , p_pad_start_date   => p_pad_start_date
12485                         , p_pad_end_date     => p_pad_end_date
12486                           );
12487 
12488      END IF;
12489 
12490  l_created :=  EventType_19(
12491    p_application_id         => p_application_id
12492  , p_base_ledger_id         => p_base_ledger_id
12493  , p_target_ledger_id       => p_target_ledger_id
12494  , p_language               => l_language
12495  , p_currency_code          => l_currency_code
12496  , p_sla_ledger_id          => l_sla_ledger_id
12497  , p_pad_start_date         => p_pad_start_date
12498  , p_pad_end_date           => p_pad_end_date
12499  , p_primary_ledger_id      => p_primary_ledger_id
12500 );
12501 
12502 
12503 
12504      IF ( g_diagnostics_mode ='Y' ) THEN
12505 
12506          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12507           trace
12508               (p_msg      => 'CALL Transaction Objects Diagnostics'
12509               ,p_level    => C_LEVEL_STATEMENT
12510               ,p_module   => l_log_module);
12511 
12512          END IF;
12513 
12514          insert_sources_19(
12515                           p_target_ledger_id => p_target_ledger_id
12516                         , p_language         => l_language
12517                         , p_sla_ledger_id    => l_sla_ledger_id
12518                         , p_pad_start_date   => p_pad_start_date
12519                         , p_pad_end_date     => p_pad_end_date
12520                           );
12521 
12522      END IF;
12523 
12524  l_created :=  EventType_20(
12525    p_application_id         => p_application_id
12526  , p_base_ledger_id         => p_base_ledger_id
12527  , p_target_ledger_id       => p_target_ledger_id
12528  , p_language               => l_language
12529  , p_currency_code          => l_currency_code
12530  , p_sla_ledger_id          => l_sla_ledger_id
12531  , p_pad_start_date         => p_pad_start_date
12532  , p_pad_end_date           => p_pad_end_date
12533  , p_primary_ledger_id      => p_primary_ledger_id
12534 );
12535 
12536 
12537 
12538      IF ( g_diagnostics_mode ='Y' ) THEN
12539 
12540          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12541           trace
12542               (p_msg      => 'CALL Transaction Objects Diagnostics'
12543               ,p_level    => C_LEVEL_STATEMENT
12544               ,p_module   => l_log_module);
12545 
12546          END IF;
12547 
12548          insert_sources_20(
12549                           p_target_ledger_id => p_target_ledger_id
12550                         , p_language         => l_language
12551                         , p_sla_ledger_id    => l_sla_ledger_id
12552                         , p_pad_start_date   => p_pad_start_date
12553                         , p_pad_end_date     => p_pad_end_date
12554                           );
12555 
12556      END IF;
12557 
12558  l_created :=  EventType_21(
12559    p_application_id         => p_application_id
12560  , p_base_ledger_id         => p_base_ledger_id
12561  , p_target_ledger_id       => p_target_ledger_id
12562  , p_language               => l_language
12563  , p_currency_code          => l_currency_code
12564  , p_sla_ledger_id          => l_sla_ledger_id
12565  , p_pad_start_date         => p_pad_start_date
12566  , p_pad_end_date           => p_pad_end_date
12567  , p_primary_ledger_id      => p_primary_ledger_id
12568 );
12569 
12570 
12571 
12572      IF ( g_diagnostics_mode ='Y' ) THEN
12573 
12574          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12575           trace
12576               (p_msg      => 'CALL Transaction Objects Diagnostics'
12577               ,p_level    => C_LEVEL_STATEMENT
12578               ,p_module   => l_log_module);
12579 
12580          END IF;
12581 
12582          insert_sources_21(
12583                           p_target_ledger_id => p_target_ledger_id
12584                         , p_language         => l_language
12585                         , p_sla_ledger_id    => l_sla_ledger_id
12589 
12586                         , p_pad_start_date   => p_pad_start_date
12587                         , p_pad_end_date     => p_pad_end_date
12588                           );
12590      END IF;
12591 
12592  l_created :=  EventType_22(
12593    p_application_id         => p_application_id
12594  , p_base_ledger_id         => p_base_ledger_id
12595  , p_target_ledger_id       => p_target_ledger_id
12596  , p_language               => l_language
12597  , p_currency_code          => l_currency_code
12598  , p_sla_ledger_id          => l_sla_ledger_id
12599  , p_pad_start_date         => p_pad_start_date
12600  , p_pad_end_date           => p_pad_end_date
12601  , p_primary_ledger_id      => p_primary_ledger_id
12602 );
12603 
12604 
12605 
12606      IF ( g_diagnostics_mode ='Y' ) THEN
12607 
12608          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12609           trace
12610               (p_msg      => 'CALL Transaction Objects Diagnostics'
12611               ,p_level    => C_LEVEL_STATEMENT
12612               ,p_module   => l_log_module);
12613 
12614          END IF;
12615 
12616          insert_sources_22(
12617                           p_target_ledger_id => p_target_ledger_id
12618                         , p_language         => l_language
12619                         , p_sla_ledger_id    => l_sla_ledger_id
12620                         , p_pad_start_date   => p_pad_start_date
12621                         , p_pad_end_date     => p_pad_end_date
12622                           );
12623 
12624      END IF;
12625 
12626 
12627  --
12628  -- Bug 4865292
12629  -- When the number of events and that of header extract do not match,
12630  -- set the no header extract flag to indicate there are some issues
12631  -- in header extract.
12632  --
12633  -- Event count context is set in xla_accounting_pkg.unit_processor.
12634  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
12635  -- to report it as a general error.
12636  --
12637  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
12638  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
12639 
12640      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12641         trace
12642           (p_msg      => '# of extracted headers and events does not match'
12643           ,p_level    => C_LEVEL_STATEMENT
12644           ,p_module   => l_log_module);
12645 
12646         trace
12647           (p_msg      => '# of extracted headers: '
12648                          ||g_hdr_extract_count
12649           ,p_level    => C_LEVEL_STATEMENT
12650           ,p_module   => l_log_module);
12651 
12652         trace
12653           (p_msg      => '# of events in xla_events_gt: '
12654                          ||xla_context_pkg.get_event_count_context
12655           ,p_level    => C_LEVEL_STATEMENT
12656           ,p_module   => l_log_module);
12657 
12658         trace
12659           (p_msg      => 'Event No Header Extract Context: '
12660                          ||xla_context_pkg.get_event_nohdr_context
12661           ,p_level    => C_LEVEL_STATEMENT
12662           ,p_module   => l_log_module);
12663 
12664      END IF;
12665 
12666 
12667      xla_context_pkg.set_event_nohdr_context
12668        (p_nohdr_extract_flag => 'Y'
12669        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
12670 
12671      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12672         trace
12673           (p_msg      => 'No Header Extract Flag is set to Y'
12674           ,p_level    => C_LEVEL_STATEMENT
12675           ,p_module   => l_log_module);
12676      END IF;
12677 
12678  END IF;
12679 
12680 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12681    trace
12682       (p_msg      => 'END of CreateHeadersAndLines'
12683       ,p_level    => C_LEVEL_PROCEDURE
12684       ,p_module   => l_log_module);
12685 END IF;
12686 
12687 RETURN l_created;
12688 EXCEPTION
12689 WHEN xla_exceptions_pkg.application_exception THEN
12690    RAISE;
12691 WHEN OTHERS THEN
12692    xla_exceptions_pkg.raise_message
12693       (p_location => 'XLA_09000_AAD_S_000015_PKG.CreateHeadersAndLines');
12694 END CreateHeadersAndLines;
12695 --
12696 --
12697 
12698 --
12699 --+============================================+
12700 --|                                            |
12701 --|  PUBLIC FUNCTION                           |
12702 --|                                            |
12703 --+============================================+
12704 --
12705 FUNCTION CreateJournalEntries
12706        (p_application_id         IN NUMBER
12707        ,p_base_ledger_id         IN NUMBER
12708        ,p_pad_start_date         IN DATE
12709        ,p_pad_end_date           IN DATE
12710        ,p_primary_ledger_id      IN NUMBER)
12711 RETURN NUMBER IS
12712 l_log_module                   VARCHAR2(240);
12713 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
12714 l_temp_result                  BOOLEAN;
12715 l_result                       NUMBER;
12716 BEGIN
12717 --
12718 IF g_log_enabled THEN
12719    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
12720 END IF;
12721 --
12722 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12723    trace
12724       (p_msg      => 'BEGIN of CreateJournalEntries'||
12725                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
12726       ,p_level    => C_LEVEL_PROCEDURE
12727       ,p_module   => l_log_module);
12728 
12729 END IF;
12730 
12731 --
12732 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
12733 
12734 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
12735    trace
12736       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
12737       ,p_level    => C_LEVEL_STATEMENT
12738       ,p_module   => l_log_module);
12739 END IF;
12740 --
12741 xla_ae_journal_entry_pkg.SetProductAcctDefinition
12742    (p_product_rule_code      => 'PP_DEFAULT_ACCRUAL'
12743    ,p_product_rule_type_code => 'S'
12744    ,p_product_rule_version   => ''
12745    ,p_product_rule_name      => 'Price Protection Default Accrual'
12746    ,p_amb_context_code       => 'DEFAULT'
12747    );
12748 
12749 l_array_ledgers :=
12750    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
12751       (p_base_ledger_id  => p_base_ledger_id);
12752 
12753 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
12754    l_temp_result :=
12755       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
12756          (p_application_id           => p_application_id
12757          ,p_base_ledger_id           => p_base_ledger_id
12758          ,p_target_ledger_id         => l_array_ledgers(Idx)
12759          ,p_primary_ledger_id        => p_primary_ledger_id
12760          ,p_pad_start_date           => p_pad_start_date
12761          ,p_pad_end_date             => p_pad_end_date);
12762 
12763    l_temp_result :=
12764       l_temp_result AND
12765       CreateHeadersAndLines
12766          (p_application_id             => p_application_id
12767          ,p_base_ledger_id             => p_base_ledger_id
12768          ,p_target_ledger_id           => l_array_ledgers(Idx)
12769          ,p_pad_start_date             => p_pad_start_date
12770          ,p_pad_end_date               => p_pad_end_date
12771          ,p_primary_ledger_id          => p_primary_ledger_id
12772          );
12773 END LOOP;
12774 
12775 
12776 IF (g_diagnostics_mode = 'Y' AND
12777     C_LEVEL_UNEXPECTED >= g_log_level AND
12778     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
12779 
12780    xla_accounting_dump_pkg.acctg_event_extract_log(
12781     p_application_id  => p_application_id
12782     ,p_request_id     => xla_environment_pkg.g_Req_Id
12783    );
12784 
12785 END IF;
12786 
12787 CASE l_temp_result
12788   WHEN TRUE THEN l_result := 0;
12789   ELSE l_result := 2;
12790 END CASE;
12791 
12792 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12793    trace
12794       (p_msg      => 'return value. = '||TO_CHAR(l_result)
12795       ,p_level    => C_LEVEL_PROCEDURE
12796       ,p_module   => l_log_module);
12797    trace
12798       (p_msg      => 'END of CreateJournalEntries '
12799       ,p_level    => C_LEVEL_PROCEDURE
12800       ,p_module   => l_log_module);
12801 END IF;
12802 
12803 RETURN l_result;
12804 EXCEPTION
12805 WHEN xla_exceptions_pkg.application_exception THEN
12806    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12807    trace
12808       (p_msg      => 'ERROR. = '||sqlerrm
12809       ,p_level    => C_LEVEL_PROCEDURE
12810       ,p_module   => l_log_module);
12811    END IF;
12812    RAISE;
12813 WHEN OTHERS THEN
12814    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
12815    trace
12816       (p_msg      => 'ERROR. = '||sqlerrm
12817       ,p_level    => C_LEVEL_PROCEDURE
12818       ,p_module   => l_log_module);
12819    END IF;
12820    xla_exceptions_pkg.raise_message
12821       (p_location => 'XLA_09000_AAD_S_000015_PKG.CreateJournalEntries');
12822 END CreateJournalEntries;
12823 --
12824 --=============================================================================
12825 --
12826 --
12827 --
12828 --
12829 --
12830 --
12831 --
12832 --
12833 --
12834 --
12835 --
12836 --
12837 --
12838 --
12839 --
12840 --
12841 --
12842 --
12843 --
12844 --
12845 --
12846 --
12847 --=============================================================================
12848 --=============================================================================
12849 --          *********** Initialization routine **********
12850 --=============================================================================
12851 
12852 BEGIN
12853    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
12854    g_log_enabled    := fnd_log.test
12855                           (log_level  => g_log_level
12856                           ,module     => C_DEFAULT_MODULE);
12857 
12858    IF NOT g_log_enabled  THEN
12859       g_log_level := C_LEVEL_LOG_DISABLED;
12860    END IF;
12861 --
12862 END XLA_09000_AAD_S_000015_PKG;
12863 --