DBA Data[Home] [Help]

PACKAGE BODY: APPS.XLA_00801_AAD_S_000003_PKG

Source


1 PACKAGE BODY XLA_00801_AAD_S_000003_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_00801_AAD_S_000003_PKG                                        |
10 |                                                                       |
11 | DESCRIPTION                                                           |
12 |     Package generated From Product Accounting Definition              |
13 |      Name    : Payroll Costs                                          |
14 |      Code    : PAYROLL COSTS                                          |
15 |      Owner   : PRODUCT                                                |
16 |      Version : 1                                                      |
17 |      AMB Context Code: DEFAULT                                        |
18 | HISTORY                                                               |
19 |     Generated at 04-01-2007 at 02:01:52 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_00801_AAD_S_000003_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_00801_AAD_S_000003_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_00801_AAD_S_000003_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_00801_AAD_S_000003_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 --Sign of Cost
241  , p_source_1            IN VARCHAR2
242 )
243 RETURN VARCHAR2
244 IS
245 l_component_type        VARCHAR2(80)   ;
246 l_component_code        VARCHAR2(30)   ;
247 l_component_type_code   VARCHAR2(1)    ;
248 l_component_appl_id     INTEGER        ;
249 l_amb_context_code      VARCHAR2(30)   ;
250 l_ledger_language       VARCHAR2(30)   ;
251 l_source                VARCHAR2(1996) ;
252 l_description           VARCHAR2(2000) ;
253 l_log_module            VARCHAR2(240)  ;
254 BEGIN
255 IF g_log_enabled THEN
256       l_log_module := C_DEFAULT_MODULE||'.Description_1';
257 END IF;
258 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
259       trace
260          (p_msg      => 'BEGIN of Description_1'
261          ,p_level    => C_LEVEL_PROCEDURE
262          ,p_module   => l_log_module);
263 END IF;
264 
265 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
266 l_component_type        := 'AMB_DESCRIPTION';
267 l_component_code        := 'CREDIT PAYMENT COST LINE';
268 l_component_type_code   := 'S';
269 l_component_appl_id     :=  801;
270 l_amb_context_code      := 'DEFAULT';
271 l_source                := NULL;
272 l_description           := NULL;
273 
274 
275  IF NVL(p_source_1,'
276 ')  =  'C' AND 
277 NVL(
278 xla_ae_sources_pkg.GetSystemSourceChar(
279    p_source_code           => 'XLA_EVENT_TYPE_CODE'
280  , p_source_type_code      => 'Y'
281  , p_source_application_id =>  602
282 ),'
283 ')  =  'PAYMENT_COST'
284  THEN 
285  
286  IF 
287 l_ledger_language = 'US' THEN
288     l_description :=  SUBSTR(CONCAT(l_description,'Credit payment cost'),1,2000);
289     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
290  END IF; 
291  l_description := SUBSTR(l_description,1,1996);
292   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
293         trace
294            (p_msg      => 'END of Description_1'
295            ,p_level    => C_LEVEL_PROCEDURE
296            ,p_module   => l_log_module);
297 
298   END IF;
299   RETURN l_description;
300 
301  END IF;
302 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
303       trace
304          (p_msg      => 'END of Description_1'
305          ,p_level    => C_LEVEL_PROCEDURE
306          ,p_module   => l_log_module);
307 END IF;
308 RETURN NULL;
309 EXCEPTION
310   WHEN VALUE_ERROR THEN
311      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
312             trace
313                (p_msg      => 'ERROR: '||sqlerrm
314                ,p_level    => C_LEVEL_EXCEPTION
315                ,p_module   => l_log_module);
316      END IF;
317      RAISE;
318  WHEN xla_exceptions_pkg.application_exception THEN
322          ,p_level    => C_LEVEL_EXCEPTION
319       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
320       trace
321          (p_msg      => 'ERROR: '||sqlerrm
323          ,p_module   => l_log_module);
324       END IF;
325       RAISE;
326  WHEN OTHERS THEN
327        xla_exceptions_pkg.raise_message
328            (p_location => 'XLA_00801_AAD_S_000003_PKG.Description_1');
329 END Description_1;
330 
331 ---------------------------------------
332 --
333 -- PRIVATE FUNCTION
334 --         Description_2
335 --
336 ---------------------------------------
337 FUNCTION Description_2 (
338   p_application_id      IN NUMBER
339 , p_ae_header_id        IN NUMBER DEFAULT NULL 
340 --Sign of Cost
341  , p_source_1            IN VARCHAR2
342 )
343 RETURN VARCHAR2
344 IS
345 l_component_type        VARCHAR2(80)   ;
346 l_component_code        VARCHAR2(30)   ;
347 l_component_type_code   VARCHAR2(1)    ;
348 l_component_appl_id     INTEGER        ;
349 l_amb_context_code      VARCHAR2(30)   ;
350 l_ledger_language       VARCHAR2(30)   ;
351 l_source                VARCHAR2(1996) ;
352 l_description           VARCHAR2(2000) ;
353 l_log_module            VARCHAR2(240)  ;
354 BEGIN
355 IF g_log_enabled THEN
356       l_log_module := C_DEFAULT_MODULE||'.Description_2';
357 END IF;
358 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
359       trace
360          (p_msg      => 'BEGIN of Description_2'
361          ,p_level    => C_LEVEL_PROCEDURE
362          ,p_module   => l_log_module);
363 END IF;
364 
365 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
366 l_component_type        := 'AMB_DESCRIPTION';
367 l_component_code        := 'DEBIT PAYMENT COST LINE';
368 l_component_type_code   := 'S';
369 l_component_appl_id     :=  801;
370 l_amb_context_code      := 'DEFAULT';
371 l_source                := NULL;
372 l_description           := NULL;
373 
374 
375  IF NVL(p_source_1,'
376 ')  =  'D' AND 
377 NVL(
378 xla_ae_sources_pkg.GetSystemSourceChar(
379    p_source_code           => 'XLA_EVENT_TYPE_CODE'
380  , p_source_type_code      => 'Y'
381  , p_source_application_id =>  602
382 ),'
383 ')  =  'PAYMENT_COST'
384  THEN 
385  
386  IF 
387 l_ledger_language = 'US' THEN
388     l_description :=  SUBSTR(CONCAT(l_description,'Debit payment cost'),1,2000);
389     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
390  END IF; 
391  l_description := SUBSTR(l_description,1,1996);
392   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
393         trace
394            (p_msg      => 'END of Description_2'
395            ,p_level    => C_LEVEL_PROCEDURE
396            ,p_module   => l_log_module);
397 
398   END IF;
399   RETURN l_description;
400 
401  END IF;
402 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
403       trace
404          (p_msg      => 'END of Description_2'
405          ,p_level    => C_LEVEL_PROCEDURE
406          ,p_module   => l_log_module);
407 END IF;
408 RETURN NULL;
409 EXCEPTION
410   WHEN VALUE_ERROR THEN
411      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
412             trace
413                (p_msg      => 'ERROR: '||sqlerrm
414                ,p_level    => C_LEVEL_EXCEPTION
415                ,p_module   => l_log_module);
416      END IF;
417      RAISE;
418  WHEN xla_exceptions_pkg.application_exception THEN
419       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
420       trace
421          (p_msg      => 'ERROR: '||sqlerrm
422          ,p_level    => C_LEVEL_EXCEPTION
423          ,p_module   => l_log_module);
424       END IF;
425       RAISE;
426  WHEN OTHERS THEN
427        xla_exceptions_pkg.raise_message
428            (p_location => 'XLA_00801_AAD_S_000003_PKG.Description_2');
429 END Description_2;
430 
431 ---------------------------------------
432 --
433 -- PRIVATE FUNCTION
434 --         Description_3
435 --
436 ---------------------------------------
437 FUNCTION Description_3 (
438   p_application_id      IN NUMBER
439 , p_ae_header_id        IN NUMBER DEFAULT NULL 
440 --Person Name
441  , p_source_3            IN VARCHAR2
442 )
443 RETURN VARCHAR2
444 IS
445 l_component_type        VARCHAR2(80)   ;
446 l_component_code        VARCHAR2(30)   ;
447 l_component_type_code   VARCHAR2(1)    ;
448 l_component_appl_id     INTEGER        ;
449 l_amb_context_code      VARCHAR2(30)   ;
450 l_ledger_language       VARCHAR2(30)   ;
451 l_source                VARCHAR2(1996) ;
452 l_description           VARCHAR2(2000) ;
453 l_log_module            VARCHAR2(240)  ;
454 BEGIN
455 IF g_log_enabled THEN
456       l_log_module := C_DEFAULT_MODULE||'.Description_3';
457 END IF;
458 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
459       trace
460          (p_msg      => 'BEGIN of Description_3'
461          ,p_level    => C_LEVEL_PROCEDURE
462          ,p_module   => l_log_module);
463 END IF;
464 
465 l_ledger_language       := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
466 l_component_type        := 'AMB_DESCRIPTION';
467 l_component_code        := 'PAYMENT COST HEADER';
468 l_component_type_code   := 'S';
469 l_component_appl_id     :=  801;
470 l_amb_context_code      := 'DEFAULT';
471 l_source                := NULL;
472 l_description           := NULL;
473 
474 
478  , p_source_type_code      => 'Y'
475  IF NVL(
476 xla_ae_sources_pkg.GetSystemSourceChar(
477    p_source_code           => 'XLA_EVENT_TYPE_CODE'
479  , p_source_application_id =>  602
480 ),'
481 ')  =  'PAYMENT_COST'
482  THEN 
483  
484  IF 
485 l_ledger_language = 'US' THEN
486     l_description :=  SUBSTR(CONCAT(l_description,'Payment Cost for'),1,2000);
487     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
488  END IF;   
489   l_source := SUBSTR(p_source_3,1,1996);
490   IF l_source IS NOT NULL THEN
491     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
492     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
493   END IF;  
494  IF 
495 l_ledger_language = 'US' THEN
496     l_description :=  SUBSTR(CONCAT(l_description,' on'),1,2000);
497     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000); 
498  END IF;   
499   l_source := SUBSTR(xla_ae_sources_pkg.DATE_TO_CHAR(
500 xla_ae_sources_pkg.GetSystemSourceDate(
501    p_source_code           => 'XLA_EVENT_DATE'
502  , p_source_type_code      => 'Y'
503  , p_source_application_id =>  602
504 ),
505                      xla_ae_journal_entry_pkg.g_cache_ledgers_info.nls_desc_language),1,1996);
506   IF l_source IS NOT NULL THEN
507     l_description :=  SUBSTR(CONCAT(l_description,l_source),1,2000);
508     l_description :=  SUBSTR(CONCAT(l_description,' '),1,2000);
509   END IF; 
510  l_description := SUBSTR(l_description,1,1996);
511   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
512         trace
513            (p_msg      => 'END of Description_3'
514            ,p_level    => C_LEVEL_PROCEDURE
515            ,p_module   => l_log_module);
516 
517   END IF;
518   RETURN l_description;
519 
520  END IF;
521 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
522       trace
523          (p_msg      => 'END of Description_3'
524          ,p_level    => C_LEVEL_PROCEDURE
525          ,p_module   => l_log_module);
526 END IF;
527 RETURN NULL;
528 EXCEPTION
529   WHEN VALUE_ERROR THEN
530      IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
531             trace
532                (p_msg      => 'ERROR: '||sqlerrm
533                ,p_level    => C_LEVEL_EXCEPTION
534                ,p_module   => l_log_module);
535      END IF;
536      RAISE;
537  WHEN xla_exceptions_pkg.application_exception THEN
538       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
539       trace
540          (p_msg      => 'ERROR: '||sqlerrm
541          ,p_level    => C_LEVEL_EXCEPTION
542          ,p_module   => l_log_module);
543       END IF;
544       RAISE;
545  WHEN OTHERS THEN
546        xla_exceptions_pkg.raise_message
547            (p_location => 'XLA_00801_AAD_S_000003_PKG.Description_3');
548 END Description_3;
549 
550 ---------------------------------------
551 --
552 -- PRIVATE FUNCTION
553 --         AcctDerRule_4
554 --
555 ---------------------------------------
556 FUNCTION AcctDerRule_4 (
557   p_application_id              IN NUMBER
558 , p_ae_header_id                IN NUMBER
559 , p_side                        IN VARCHAR2 
560 --Payment Cost GL Account Identifier
561  , p_source_5            IN NUMBER
562 , x_transaction_coa_id         OUT NOCOPY NUMBER
563 , x_accounting_coa_id          OUT NOCOPY NUMBER
564 , x_value_type_code            OUT NOCOPY VARCHAR2
565 )
566 RETURN NUMBER
567 IS
568 l_component_type       VARCHAR2(80)  ;
569 l_component_code       VARCHAR2(30)  ;
570 l_component_type_code  VARCHAR2(1)   ;
571 l_component_appl_id    INTEGER       ;
572 l_amb_context_code     VARCHAR2(30)  ;
573 l_log_module           VARCHAR2(240) ;
574 l_output_value         NUMBER        ;
575 BEGIN
576 IF g_log_enabled THEN
577       l_log_module := C_DEFAULT_MODULE||'.AcctDerRule_4';
578 END IF;
579 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
580       trace
581          (p_msg      => 'BEGIN of AcctDerRule_4'
582          ,p_level    => C_LEVEL_PROCEDURE
583          ,p_module   => l_log_module);
584 END IF;
585 --
586 l_component_type         := 'AMB_ADR';
587 l_component_code         := 'PAYROLL ACCOUNT KF RULE';
588 l_component_type_code    := 'S';
589 l_component_appl_id      :=  801;
590 l_amb_context_code       := 'DEFAULT';
591 x_transaction_coa_id     :=  null;
592 x_accounting_coa_id      :=  null;
593 --
594 
595  --
596   IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
597       trace
598          (p_msg      => 'END of AcctDerRule_4'
599          ,p_level    => C_LEVEL_PROCEDURE
600          ,p_module   => l_log_module);
601   END IF;
602   x_value_type_code := 'S';
603   l_output_value    := TO_NUMBER(TO_NUMBER(p_source_5));
604   RETURN l_output_value;
605 
606 --
607 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
608       trace
609          (p_msg      => 'END of AcctDerRule_4(invalid)'
610          ,p_level    => C_LEVEL_PROCEDURE
611          ,p_module   => l_log_module);
612 END IF;
613 xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
614 x_value_type_code := null;
615 l_output_value    := null;
616 xla_accounting_err_pkg.build_message
617                  (p_appli_s_name            => 'XLA'
618                  ,p_msg_name                => 'XLA_AP_INVALID_ADR'
619                  ,p_token_1                 => 'COMPONENT_NAME'
620                  ,p_value_1                 => xla_ae_sources_pkg.GetComponentName (
621                                                             l_component_type
622                                                           , l_component_code
623                                                           , l_component_type_code
624                                                           , l_component_appl_id
625                                                           , l_amb_context_code
626                                                           )
627                  ,p_token_2                 => 'OWNER'
628                  ,p_value_2                 => xla_lookups_pkg.get_meaning(
629                                                         'XLA_OWNER_TYPE'
630                                                         ,l_component_type_code
631                                                         )
632                  ,p_token_3                 => 'PAD_NAME'
633                  ,p_value_3                 => xla_ae_journal_entry_pkg.g_cache_pad.pad_session_name
634                  ,p_token_4                 => 'PAD_OWNER'
635                  ,p_value_4                 => xla_lookups_pkg.get_meaning(
636                                                         'XLA_OWNER_TYPE'
637                                                         ,xla_ae_journal_entry_pkg.g_cache_pad.product_rule_type_code
638                                                         )
639                  ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
640                  ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
641                  ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id
642                  ,p_ae_header_id            => NULL
643 );
644 RETURN l_output_value;
645 EXCEPTION
646   WHEN xla_exceptions_pkg.application_exception THEN
647       RAISE;
648   WHEN OTHERS THEN
649        xla_exceptions_pkg.raise_message
653 
650            (p_location => 'XLA_00801_AAD_S_000003_PKG.AcctDerRule_4');
651 END AcctDerRule_4;
652 --
654 ---------------------------------------
655 --
656 -- PRIVATE FUNCTION
657 --         AcctLineType_5
658 --
659 ---------------------------------------
660 PROCEDURE AcctLineType_5 (
661   p_application_id        IN NUMBER
662  ,p_event_id              IN NUMBER
663  ,p_calculate_acctd_flag  IN VARCHAR2
664  ,p_calculate_g_l_flag    IN VARCHAR2
665  ,p_actual_flag           IN OUT VARCHAR2
666  ,p_balance_type_code     OUT VARCHAR2
667  ,p_gain_or_loss_ref      OUT VARCHAR2
668  
669 --Sign of Cost
670  , p_source_1            IN VARCHAR2
671 --Payment Cost GL Account Identifier
672  , p_source_5            IN NUMBER
673 --Transaction Assignment Action Identifier
674  , p_source_6            IN NUMBER
675 --Cost Action Type
676  , p_source_7            IN VARCHAR2
677 --Cost Amount
678  , p_source_8            IN NUMBER
679 --Cost Currency Code
680  , p_source_9            IN VARCHAR2
681 --Cost Conversion Type
682  , p_source_10            IN VARCHAR2
683 )
684 IS
685 
686 l_component_type              VARCHAR2(80);
687 l_component_code              VARCHAR2(30);
688 l_component_type_code         VARCHAR2(1);
689 l_component_appl_id           INTEGER;
690 l_amb_context_code            VARCHAR2(30);
691 l_entity_code                 VARCHAR2(30);
692 l_event_class_code            VARCHAR2(30);
693 l_ae_header_id                NUMBER;
694 l_event_type_code             VARCHAR2(30);
695 l_line_definition_code        VARCHAR2(30);
696 l_line_definition_owner_code  VARCHAR2(1);
697 --
698 -- adr variables
699 l_segment                     VARCHAR2(30);
700 l_ccid                        NUMBER;
701 l_adr_transaction_coa_id      NUMBER;
702 l_adr_accounting_coa_id       NUMBER;
703 l_adr_flexfield_segment_code  VARCHAR2(30);
704 l_adr_flex_value_set_id       NUMBER;
705 l_adr_value_type_code         VARCHAR2(30);
706 l_adr_value_combination_id    NUMBER;
707 l_adr_value_segment_code      VARCHAR2(30);
708 
709 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
710 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
711 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
712 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
713 
714 -- 4262811 Variables ------------------------------------------------------------------------------------------
715 l_entered_amt_idx             NUMBER;
716 l_accted_amt_idx              NUMBER;
717 l_acc_rev_flag                VARCHAR2(1);
718 l_accrual_line_num            NUMBER;
719 l_tmp_amt                     NUMBER;
720 l_acc_rev_natural_side_code   VARCHAR2(1);
721 
722 l_num_entries                 NUMBER;
723 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
724 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
725 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
726 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
730 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
727 l_recog_line_1                NUMBER;
728 l_recog_line_2                NUMBER;
729 
731 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
732 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
733 
734 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
735 
736 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
737 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
738 
739 ---------------------------------------------------------------------------------------------------------------
740 
741 
742 --
743 -- bulk performance
744 --
745 l_balance_type_code           VARCHAR2(1);
746 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
747 l_log_module                  VARCHAR2(240);
748 
749 --
750 -- Upgrade strategy
751 --
752 l_actual_upg_option           VARCHAR2(1);
753 l_enc_upg_option           VARCHAR2(1);
754 
755 --
756 BEGIN
757 --
758 IF g_log_enabled THEN
759       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_5';
760 END IF;
761 --
762 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
763 
764       trace
765          (p_msg      => 'BEGIN of AcctLineType_5'
766          ,p_level    => C_LEVEL_PROCEDURE
767          ,p_module   => l_log_module);
768 
769 END IF;
770 --
771 l_component_type             := 'AMB_JLT';
772 l_component_code             := 'CREDIT PAYMENT COST';
773 l_component_type_code        := 'S';
774 l_component_appl_id          :=  801;
775 l_amb_context_code           := 'DEFAULT';
776 l_entity_code                := 'ASSIGNMENTS';
777 l_event_class_code           := 'PAYMENT_COSTS';
778 l_event_type_code            := 'PAYMENT_COST';
779 l_line_definition_owner_code := 'S';
780 l_line_definition_code       := 'PAYMENT COST';
781 --
782 l_balance_type_code          := 'A';
783 l_segment                     := NULL;
784 l_ccid                        := NULL;
785 l_adr_transaction_coa_id      := NULL;
786 l_adr_accounting_coa_id       := NULL;
787 l_adr_flexfield_segment_code  := NULL;
788 l_adr_flex_value_set_id       := NULL;
789 l_adr_value_type_code         := NULL;
790 l_adr_value_combination_id    := NULL;
791 l_adr_value_segment_code      := NULL;
792 
793 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
794 l_bflow_class_code           := '';    -- 4219869 Business Flow
795 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
796 l_budgetary_control_flag     := 'N';
797 
798 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
799 l_bflow_applied_to_amt       := NULL; -- 5132302
800 l_entered_amt_idx            := NULL;          -- 4262811
801 l_accted_amt_idx             := NULL;          -- 4262811
802 l_acc_rev_flag               := NULL;          -- 4262811
803 l_accrual_line_num           := NULL;          -- 4262811
804 l_tmp_amt                    := NULL;          -- 4262811
805 --
806  
807 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
808     l_balance_type_code <> 'B' THEN
809 IF NVL(p_source_1,'
810 ')  =  'C'
811  THEN 
812 
813    --
814    XLA_AE_LINES_PKG.SetNewLine;
815 
816    p_balance_type_code          := l_balance_type_code;
817    -- set the flag so later we will know whether the gain loss line needs to be created
818    
819    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
820      p_actual_flag :='A';
821    END IF;
822 
823    --
824    -- bulk performance
825    --
826    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
827                                       p_header_num   => 0); -- 4262811
828    --
829    -- set accounting line options
830    --
831    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
832            p_natural_side_code          => 'C'
836          , p_switch_side_flag           => 'Y'
833          , p_gain_or_loss_flag          => 'N'
834          , p_gl_transfer_mode_code      => 'S'
835          , p_acct_entry_type_code       => 'A'
837          , p_merge_duplicate_code       => 'W'
838          );
839    --
840    l_acc_rev_natural_side_code := 'D';  -- 4262811
841    -- 
842    --
843    -- set accounting line type info
844    --
845    xla_ae_lines_pkg.SetAcctLineType
846       (p_component_type             => l_component_type
847       ,p_event_type_code            => l_event_type_code
848       ,p_line_definition_owner_code => l_line_definition_owner_code
849       ,p_line_definition_code       => l_line_definition_code
850       ,p_accounting_line_code       => l_component_code
851       ,p_accounting_line_type_code  => l_component_type_code
852       ,p_accounting_line_appl_id    => l_component_appl_id
853       ,p_amb_context_code           => l_amb_context_code
854       ,p_entity_code                => l_entity_code
855       ,p_event_class_code           => l_event_class_code);
856    --
857    -- set accounting class
858    --
859    xla_ae_lines_pkg.SetAcctClass(
860            p_accounting_class_code  => 'COST'
861          , p_ae_header_id           => l_ae_header_id
862          );
863 
864    --
865    -- set rounding class
866    --
867    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
868                       'COST';
869 
870    --
871    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
872    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
873    --
874    -- bulk performance
875    --
876    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
877 
878    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
879       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
880 
881    -- 4955764
882    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
883       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
884 
885    -- 4458381 Public Sector Enh
886    
887    --
888    -- set accounting attributes for the line type
889    --
890    l_entered_amt_idx := 3;
891    l_accted_amt_idx  := NULL;
892    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
893    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
894    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_6);
895    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
896    l_rec_acct_attrs.array_char_value(2)  := p_source_7;
897    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
898    l_rec_acct_attrs.array_num_value(3)  := p_source_8;
899    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
900    l_rec_acct_attrs.array_char_value(4)  := p_source_9;
901    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_RATE_TYPE';
902    l_rec_acct_attrs.array_char_value(5)  := p_source_10;
903 
904    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
905    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
906 
907    ---------------------------------------------------------------------------------------------------------------
908    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
909    ---------------------------------------------------------------------------------------------------------------
910    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
911 
912    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
913    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
914 
915    IF xla_accounting_cache_pkg.GetValueChar
916          (p_source_code         => 'LEDGER_CATEGORY_CODE'
917          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
918    AND l_bflow_method_code = 'PRIOR_ENTRY'
919 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
920    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
921          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
922        )
923    THEN
924          xla_ae_lines_pkg.BflowUpgEntry
925            (p_business_method_code    => l_bflow_method_code
926            ,p_business_class_code     => l_bflow_class_code
927            ,p_balance_type            => l_balance_type_code);
928    ELSE
929       NULL;
930 -- No business flow processing for business flow method of NONE.
931    END IF;
932 
933    --
934    -- call description
935    --
936    
937 xla_ae_lines_pkg.SetLineDescription(
938    p_ae_header_id => l_ae_header_id
939   ,p_description  => Description_1 (
940      p_application_id         => p_application_id
941    , p_ae_header_id           => l_ae_header_id 
942 , p_source_1 => p_source_1
943    )
944 );
945 
946 
947    --
948    -- call ADRs
949    -- Bug 4922099
950    --
951    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
952         (NVL(l_actual_upg_option, 'N') = 'O') OR
953         (NVL(l_enc_upg_option, 'N') = 'O')
954       )
955    THEN
956    NULL;
957    --
958    --
959    
960   l_ccid := AcctDerRule_4(
961            p_application_id           => p_application_id
962          , p_ae_header_id             => l_ae_header_id 
963 , p_source_5 => p_source_5
964          , x_transaction_coa_id       => l_adr_transaction_coa_id
965          , x_accounting_coa_id        => l_adr_accounting_coa_id
966          , x_value_type_code          => l_adr_value_type_code
967          , p_side                     => 'NA'
968    );
969 
970    xla_ae_lines_pkg.set_ccid(
971     p_code_combination_id          => l_ccid
972   , p_value_type_code              => l_adr_value_type_code
973   , p_transaction_coa_id           => l_adr_transaction_coa_id
977   , p_component_type               => l_component_type
974   , p_accounting_coa_id            => l_adr_accounting_coa_id
975   , p_adr_code                     => 'PAYROLL ACCOUNT KF RULE'
976   , p_adr_type_code                => 'S'
978   , p_component_code               => l_component_code
979   , p_component_type_code          => l_component_type_code
980   , p_component_appl_id            => l_component_appl_id
981   , p_amb_context_code             => l_amb_context_code
982   , p_side                         => 'NA'
983   );
984 
985 
986    --
987    --
988    END IF;
989    --
990    -- Bug 4922099
991    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
992           (NVL(l_enc_upg_option, 'N') = 'O')
993         ) AND
994         (l_bflow_method_code = 'PRIOR_ENTRY')
995       )
996    THEN
997       IF
998       --
999       1 = 2
1000       --
1001       THEN
1002       xla_accounting_err_pkg.build_message
1003                                     (p_appli_s_name            => 'XLA'
1004                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1005                                     ,p_token_1                 => 'LINE_NUMBER'
1006                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1007                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1008                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1009                                                                              l_component_type
1010                                                                             ,l_component_code
1011                                                                             ,l_component_type_code
1012                                                                             ,l_component_appl_id
1013                                                                             ,l_amb_context_code
1014                                                                             ,l_entity_code
1015                                                                             ,l_event_class_code
1016                                                                            )
1017                                     ,p_token_3                 => 'OWNER'
1018                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1019                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1020                                                                           ,p_lookup_code    => l_component_type_code
1021                                                                          )
1022                                     ,p_token_4                 => 'PRODUCT_NAME'
1023                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1024                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1025                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1026                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1027                                     ,p_ae_header_id            =>  NULL
1031                  trace
1028                                        );
1029 
1030         IF (C_LEVEL_ERROR>= g_log_level) THEN
1032                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1033                       ,p_level    => C_LEVEL_ERROR
1034                       ,p_module   => l_log_module);
1035         END IF;
1036       END IF;
1037    END IF;
1038    --
1039    --
1040    ------------------------------------------------------------------------------------------------
1041    -- 4219869 Business Flow
1042    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1043    -- Prior Entry.  Currently, the following code is always generated.
1044    ------------------------------------------------------------------------------------------------
1045    XLA_AE_LINES_PKG.ValidateCurrentLine;
1046 
1047    ------------------------------------------------------------------------------------
1048    -- 4219869 Business Flow
1049    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1050    ------------------------------------------------------------------------------------
1051    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1052 
1053    ----------------------------------------------------------------------------------
1054    -- 4219869 Business Flow
1055    -- Update journal entry status -- Need to generate this within IF <condition>
1056    ----------------------------------------------------------------------------------
1057    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1058          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1059          ,p_balance_type_code => l_balance_type_code
1060          );
1061 
1062    -------------------------------------------------------------------------------------------
1063    -- 4262811 - Generate the Accrual Reversal lines
1064    -------------------------------------------------------------------------------------------
1065    BEGIN
1066       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1067                               (g_array_event(p_event_id).array_value_num('header_index'));
1068       IF l_acc_rev_flag IS NULL THEN
1069          l_acc_rev_flag := 'N';
1070       END IF;
1071    EXCEPTION
1072       WHEN OTHERS THEN
1073          l_acc_rev_flag := 'N';
1074    END;
1075    --
1076    IF (l_acc_rev_flag = 'Y') THEN
1077 
1078        -- 4645092  ------------------------------------------------------------------------------
1079        -- To allow MPA report to determine if it should generate report process
1080        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1081        ------------------------------------------------------------------------------------------
1082 
1083        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1084        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1085 
1086        --
1087        -- Update the line information that should be overwritten
1088        --
1089        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1090                                          p_header_num   => 1);
1091        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1092 
1093        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1094 
1095        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1096           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1097        END IF;
1098 
1099       --
1100       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1101       --
1102       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1103           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1104       ELSE
1105           ---------------------------------------------------------------------------------------------------
1106           -- 4262811a Switch Sign
1107           ---------------------------------------------------------------------------------------------------
1108           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1109           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1110                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1111           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1112                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1113           -- 5132302
1114           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1115                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1116 
1117       END IF;
1118 
1119       -- 4955764
1120       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1121       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1122 
1123 
1124       XLA_AE_LINES_PKG.ValidateCurrentLine;
1125       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1126 
1127       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1128                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1129                ,p_balance_type_code => l_balance_type_code);
1130 
1131    END IF;
1132 
1133    -----------------------------------------------------------------------------------------
1134    -- 4262811 Multiperiod Accounting
1135    -----------------------------------------------------------------------------------------
1136      -- No MPA option is assigned.
1137 
1138 
1139 END IF;
1140 END IF;
1141 --
1142 
1143 --
1147       ,p_level    => C_LEVEL_PROCEDURE
1144 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1145    trace
1146       (p_msg      => 'END of AcctLineType_5'
1148       ,p_module   => l_log_module);
1149 END IF;
1150 --
1151 EXCEPTION
1152   WHEN xla_exceptions_pkg.application_exception THEN
1153       RAISE;
1154   WHEN OTHERS THEN
1155        xla_exceptions_pkg.raise_message
1156            (p_location => 'XLA_00801_AAD_S_000003_PKG.AcctLineType_5');
1157 END AcctLineType_5;
1158 --
1159 
1160 ---------------------------------------
1161 --
1162 -- PRIVATE FUNCTION
1163 --         AcctLineType_6
1164 --
1165 ---------------------------------------
1166 PROCEDURE AcctLineType_6 (
1167   p_application_id        IN NUMBER
1168  ,p_event_id              IN NUMBER
1169  ,p_calculate_acctd_flag  IN VARCHAR2
1170  ,p_calculate_g_l_flag    IN VARCHAR2
1171  ,p_actual_flag           IN OUT VARCHAR2
1172  ,p_balance_type_code     OUT VARCHAR2
1173  ,p_gain_or_loss_ref      OUT VARCHAR2
1174  
1175 --Sign of Cost
1176  , p_source_1            IN VARCHAR2
1177 --Payment Cost GL Account Identifier
1178  , p_source_5            IN NUMBER
1179 --Transaction Assignment Action Identifier
1180  , p_source_6            IN NUMBER
1181 --Cost Action Type
1182  , p_source_7            IN VARCHAR2
1183 --Cost Amount
1184  , p_source_8            IN NUMBER
1185 --Cost Currency Code
1186  , p_source_9            IN VARCHAR2
1187 --Cost Conversion Type
1188  , p_source_10            IN VARCHAR2
1189 )
1190 IS
1191 
1192 l_component_type              VARCHAR2(80);
1193 l_component_code              VARCHAR2(30);
1194 l_component_type_code         VARCHAR2(1);
1195 l_component_appl_id           INTEGER;
1196 l_amb_context_code            VARCHAR2(30);
1197 l_entity_code                 VARCHAR2(30);
1198 l_event_class_code            VARCHAR2(30);
1199 l_ae_header_id                NUMBER;
1200 l_event_type_code             VARCHAR2(30);
1201 l_line_definition_code        VARCHAR2(30);
1202 l_line_definition_owner_code  VARCHAR2(1);
1203 --
1204 -- adr variables
1205 l_segment                     VARCHAR2(30);
1206 l_ccid                        NUMBER;
1207 l_adr_transaction_coa_id      NUMBER;
1208 l_adr_accounting_coa_id       NUMBER;
1209 l_adr_flexfield_segment_code  VARCHAR2(30);
1210 l_adr_flex_value_set_id       NUMBER;
1211 l_adr_value_type_code         VARCHAR2(30);
1212 l_adr_value_combination_id    NUMBER;
1213 l_adr_value_segment_code      VARCHAR2(30);
1214 
1215 l_bflow_method_code           VARCHAR2(30);  -- 4219869 Business Flow
1216 l_bflow_class_code            VARCHAR2(30);  -- 4219869 Business Flow
1217 l_inherit_desc_flag           VARCHAR2(1);   -- 4219869 Business Flow
1218 l_budgetary_control_flag      VARCHAR2(1);   -- 4458381 Public Sector Enh
1219 
1220 -- 4262811 Variables ------------------------------------------------------------------------------------------
1221 l_entered_amt_idx             NUMBER;
1222 l_accted_amt_idx              NUMBER;
1223 l_acc_rev_flag                VARCHAR2(1);
1224 l_accrual_line_num            NUMBER;
1225 l_tmp_amt                     NUMBER;
1226 l_acc_rev_natural_side_code   VARCHAR2(1);
1227 
1228 l_num_entries                 NUMBER;
1229 l_gl_dates                    xla_ae_journal_entry_pkg.t_array_date;
1230 l_accted_amts                 xla_ae_journal_entry_pkg.t_array_num;
1231 l_entered_amts                xla_ae_journal_entry_pkg.t_array_num;
1232 l_period_names                xla_ae_journal_entry_pkg.t_array_V15L;
1233 l_recog_line_1                NUMBER;
1234 l_recog_line_2                NUMBER;
1235 
1236 l_bflow_applied_to_amt_idx    NUMBER;                                -- 5132302
1237 l_bflow_applied_to_amt        NUMBER;                                -- 5132302
1238 l_bflow_applied_to_amts       xla_ae_journal_entry_pkg.t_array_num;  -- 5132302
1239 
1240 l_event_id                    NUMBER;  -- To handle MPA header Description: xla_ae_header_pkg.SetHdrDescription
1241 
1242 --l_rounding_ccy                VARCHAR2(15); -- To handle MPA rounding  4262811b
1243 l_same_currency               BOOLEAN;        -- To handle MPA rounding  4262811b
1244 
1245 ---------------------------------------------------------------------------------------------------------------
1246 
1247 
1248 --
1249 -- bulk performance
1250 --
1251 l_balance_type_code           VARCHAR2(1);
1252 l_rec_acct_attrs              XLA_AE_LINES_PKG.t_rec_acct_attrs;
1253 l_log_module                  VARCHAR2(240);
1254 
1258 l_actual_upg_option           VARCHAR2(1);
1255 --
1256 -- Upgrade strategy
1257 --
1259 l_enc_upg_option           VARCHAR2(1);
1260 
1261 --
1262 BEGIN
1263 --
1264 IF g_log_enabled THEN
1265       l_log_module := C_DEFAULT_MODULE||'.AcctLineType_6';
1266 END IF;
1267 --
1268 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1269 
1270       trace
1271          (p_msg      => 'BEGIN of AcctLineType_6'
1272          ,p_level    => C_LEVEL_PROCEDURE
1273          ,p_module   => l_log_module);
1274 
1275 END IF;
1276 --
1277 l_component_type             := 'AMB_JLT';
1278 l_component_code             := 'DEBIT PAYMENT COST';
1279 l_component_type_code        := 'S';
1280 l_component_appl_id          :=  801;
1281 l_amb_context_code           := 'DEFAULT';
1282 l_entity_code                := 'ASSIGNMENTS';
1283 l_event_class_code           := 'PAYMENT_COSTS';
1284 l_event_type_code            := 'PAYMENT_COST';
1285 l_line_definition_owner_code := 'S';
1286 l_line_definition_code       := 'PAYMENT COST';
1287 --
1288 l_balance_type_code          := 'A';
1289 l_segment                     := NULL;
1290 l_ccid                        := NULL;
1291 l_adr_transaction_coa_id      := NULL;
1292 l_adr_accounting_coa_id       := NULL;
1293 l_adr_flexfield_segment_code  := NULL;
1294 l_adr_flex_value_set_id       := NULL;
1295 l_adr_value_type_code         := NULL;
1296 l_adr_value_combination_id    := NULL;
1297 l_adr_value_segment_code      := NULL;
1298 
1299 l_bflow_method_code          := 'NONE';   -- 4219869 Business Flow
1300 l_bflow_class_code           := '';    -- 4219869 Business Flow
1301 l_inherit_desc_flag          := 'N';   -- 4219869 Business Flow
1302 l_budgetary_control_flag     := 'N';
1303 
1304 l_bflow_applied_to_amt_idx   := NULL; -- 5132302
1305 l_bflow_applied_to_amt       := NULL; -- 5132302
1306 l_entered_amt_idx            := NULL;          -- 4262811
1307 l_accted_amt_idx             := NULL;          -- 4262811
1308 l_acc_rev_flag               := NULL;          -- 4262811
1309 l_accrual_line_num           := NULL;          -- 4262811
1310 l_tmp_amt                    := NULL;          -- 4262811
1311 --
1312  
1313 IF XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id = XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id OR
1314     l_balance_type_code <> 'B' THEN
1315 IF NVL(p_source_1,'
1316 ')  =  'D'
1317  THEN 
1318 
1319    --
1320    XLA_AE_LINES_PKG.SetNewLine;
1321 
1322    p_balance_type_code          := l_balance_type_code;
1323    -- set the flag so later we will know whether the gain loss line needs to be created
1324    
1325    IF(l_balance_type_code = 'A' and p_actual_flag is null) THEN
1326      p_actual_flag :='A';
1327    END IF;
1328 
1329    --
1330    -- bulk performance
1331    --
1332    XLA_AE_LINES_PKG.set_ae_header_id (p_ae_header_id => p_event_id ,
1333                                       p_header_num   => 0); -- 4262811
1334    --
1335    -- set accounting line options
1336    --
1337    l_ae_header_id:= xla_ae_lines_pkg.SetAcctLineOption(
1338            p_natural_side_code          => 'D'
1339          , p_gain_or_loss_flag          => 'N'
1340          , p_gl_transfer_mode_code      => 'S'
1341          , p_acct_entry_type_code       => 'A'
1342          , p_switch_side_flag           => 'Y'
1343          , p_merge_duplicate_code       => 'W'
1344          );
1345    --
1346    l_acc_rev_natural_side_code := 'C';  -- 4262811
1347    -- 
1348    --
1349    -- set accounting line type info
1350    --
1351    xla_ae_lines_pkg.SetAcctLineType
1352       (p_component_type             => l_component_type
1353       ,p_event_type_code            => l_event_type_code
1354       ,p_line_definition_owner_code => l_line_definition_owner_code
1355       ,p_line_definition_code       => l_line_definition_code
1356       ,p_accounting_line_code       => l_component_code
1357       ,p_accounting_line_type_code  => l_component_type_code
1358       ,p_accounting_line_appl_id    => l_component_appl_id
1359       ,p_amb_context_code           => l_amb_context_code
1360       ,p_entity_code                => l_entity_code
1361       ,p_event_class_code           => l_event_class_code);
1362    --
1363    -- set accounting class
1364    --
1365    xla_ae_lines_pkg.SetAcctClass(
1366            p_accounting_class_code  => 'COST'
1367          , p_ae_header_id           => l_ae_header_id
1368          );
1369 
1370    --
1371    -- set rounding class
1372    --
1373    XLA_AE_LINES_PKG.g_rec_lines.array_rounding_class(XLA_AE_LINES_PKG.g_LineNumber) :=
1374                       'COST';
1375 
1376    --
1377    xla_ae_lines_pkg.g_rec_lines.array_calculate_acctd_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_acctd_flag;
1378    xla_ae_lines_pkg.g_rec_lines.array_calculate_g_l_flag(xla_ae_lines_pkg.g_LineNumber) := p_calculate_g_l_flag;
1379    --
1380    -- bulk performance
1381    --
1382    XLA_AE_LINES_PKG.g_rec_lines.array_balance_type_code(XLA_AE_LINES_PKG.g_LineNumber) := l_balance_type_code;
1383 
1384    XLA_AE_LINES_PKG.g_rec_lines.array_ledger_id(XLA_AE_LINES_PKG.g_LineNumber) :=
1385       XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id;
1386 
1387    -- 4955764
1388    XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1389       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('header_index'));
1390 
1391    -- 4458381 Public Sector Enh
1392    
1393    --
1394    -- set accounting attributes for the line type
1395    --
1396    l_entered_amt_idx := 3;
1397    l_accted_amt_idx  := NULL;
1398    l_bflow_applied_to_amt_idx  := NULL;  -- 5132302
1399    l_rec_acct_attrs.array_acct_attr_code(1) := 'DISTRIBUTION_IDENTIFIER_1';
1400    l_rec_acct_attrs.array_num_value(1)  :=  to_char(p_source_6);
1401    l_rec_acct_attrs.array_acct_attr_code(2) := 'DISTRIBUTION_TYPE';
1402    l_rec_acct_attrs.array_char_value(2)  := p_source_7;
1403    l_rec_acct_attrs.array_acct_attr_code(3) := 'ENTERED_CURRENCY_AMOUNT';
1404    l_rec_acct_attrs.array_num_value(3)  := p_source_8;
1405    l_rec_acct_attrs.array_acct_attr_code(4) := 'ENTERED_CURRENCY_CODE';
1406    l_rec_acct_attrs.array_char_value(4)  := p_source_9;
1407    l_rec_acct_attrs.array_acct_attr_code(5) := 'EXCHANGE_RATE_TYPE';
1408    l_rec_acct_attrs.array_char_value(5)  := p_source_10;
1409 
1410    XLA_AE_LINES_PKG.SetLineAcctAttrs(l_rec_acct_attrs);
1411    p_gain_or_loss_ref  := XLA_AE_LINES_PKG.g_rec_lines.array_gain_or_loss_ref(XLA_AE_LINES_PKG.g_LineNumber);
1412 
1413    ---------------------------------------------------------------------------------------------------------------
1414    -- 4336173 -- assign Business Flow Class (replace code in xla_ae_lines_pkg.Business_Flow_Validation)
1418    l_actual_upg_option  := XLA_AE_LINES_PKG.g_rec_lines.array_actual_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1415    ---------------------------------------------------------------------------------------------------------------
1416    XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := l_bflow_class_code;
1417 
1419    l_enc_upg_option     := XLA_AE_LINES_PKG.g_rec_lines.array_enc_upg_option(XLA_AE_LINES_PKG.g_LineNumber);
1420 
1421    IF xla_accounting_cache_pkg.GetValueChar
1422          (p_source_code         => 'LEDGER_CATEGORY_CODE'
1423          ,p_target_ledger_id    => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id) IN ('PRIMARY','ALC')
1424    AND l_bflow_method_code = 'PRIOR_ENTRY'
1425 --   AND (l_actual_upg_option = 'Y' OR l_enc_upg_option = 'Y') Bug 4922099
1426    AND ( (NVL(l_actual_upg_option, 'N') IN ('Y', 'O')) OR
1427          (NVL(l_enc_upg_option, 'N') IN ('Y', 'O'))
1428        )
1429    THEN
1430          xla_ae_lines_pkg.BflowUpgEntry
1431            (p_business_method_code    => l_bflow_method_code
1432            ,p_business_class_code     => l_bflow_class_code
1433            ,p_balance_type            => l_balance_type_code);
1434    ELSE
1435       NULL;
1436 -- No business flow processing for business flow method of NONE.
1437    END IF;
1438 
1439    --
1440    -- call description
1441    --
1442    
1443 xla_ae_lines_pkg.SetLineDescription(
1444    p_ae_header_id => l_ae_header_id
1445   ,p_description  => Description_2 (
1446      p_application_id         => p_application_id
1447    , p_ae_header_id           => l_ae_header_id 
1448 , p_source_1 => p_source_1
1449    )
1450 );
1451 
1452 
1453    --
1454    -- call ADRs
1455    -- Bug 4922099
1456    --
1457    IF ( (l_bflow_method_code <> 'PRIOR_ENTRY') OR
1458         (NVL(l_actual_upg_option, 'N') = 'O') OR
1459         (NVL(l_enc_upg_option, 'N') = 'O')
1460       )
1461    THEN
1462    NULL;
1463    --
1464    --
1465    
1466   l_ccid := AcctDerRule_4(
1467            p_application_id           => p_application_id
1468          , p_ae_header_id             => l_ae_header_id 
1469 , p_source_5 => p_source_5
1470          , x_transaction_coa_id       => l_adr_transaction_coa_id
1471          , x_accounting_coa_id        => l_adr_accounting_coa_id
1472          , x_value_type_code          => l_adr_value_type_code
1473          , p_side                     => 'NA'
1474    );
1475 
1476    xla_ae_lines_pkg.set_ccid(
1477     p_code_combination_id          => l_ccid
1478   , p_value_type_code              => l_adr_value_type_code
1479   , p_transaction_coa_id           => l_adr_transaction_coa_id
1480   , p_accounting_coa_id            => l_adr_accounting_coa_id
1481   , p_adr_code                     => 'PAYROLL ACCOUNT KF RULE'
1482   , p_adr_type_code                => 'S'
1483   , p_component_type               => l_component_type
1484   , p_component_code               => l_component_code
1485   , p_component_type_code          => l_component_type_code
1486   , p_component_appl_id            => l_component_appl_id
1487   , p_amb_context_code             => l_amb_context_code
1488   , p_side                         => 'NA'
1489   );
1490 
1491 
1492    --
1493    --
1494    END IF;
1495    --
1496    -- Bug 4922099
1500         (l_bflow_method_code = 'PRIOR_ENTRY')
1497    IF ( ( (NVL(l_actual_upg_option, 'N') = 'O') OR
1498           (NVL(l_enc_upg_option, 'N') = 'O')
1499         ) AND
1501       )
1502    THEN
1503       IF
1504       --
1505       1 = 2
1506       --
1507       THEN
1508       xla_accounting_err_pkg.build_message
1509                                     (p_appli_s_name            => 'XLA'
1510                                     ,p_msg_name                => 'XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1511                                     ,p_token_1                 => 'LINE_NUMBER'
1512                                     ,p_value_1                 => XLA_AE_LINES_PKG.g_LineNumber
1513                                     ,p_token_2                 => 'LINE_TYPE_NAME'
1514                                     ,p_value_2                 => XLA_AE_SOURCES_PKG.GetComponentName (
1515                                                                              l_component_type
1516                                                                             ,l_component_code
1517                                                                             ,l_component_type_code
1518                                                                             ,l_component_appl_id
1519                                                                             ,l_amb_context_code
1520                                                                             ,l_entity_code
1521                                                                             ,l_event_class_code
1522                                                                            )
1523                                     ,p_token_3                 => 'OWNER'
1524                                     ,p_value_3                 => xla_lookups_pkg.get_meaning(
1525                                                                           p_lookup_type     => 'XLA_OWNER_TYPE'
1526                                                                           ,p_lookup_code    => l_component_type_code
1527                                                                          )
1528                                     ,p_token_4                 => 'PRODUCT_NAME'
1529                                     ,p_value_4                 => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.application_name
1530                                     ,p_entity_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.entity_id
1531                                     ,p_event_id                => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.event_id
1532                                     ,p_ledger_id               => XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id
1533                                     ,p_ae_header_id            =>  NULL
1534                                        );
1535 
1536         IF (C_LEVEL_ERROR>= g_log_level) THEN
1537                  trace
1538                       (p_msg      => 'ERROR: XLA_UPG_OVERRIDE_ADR_UNDEFINED'
1539                       ,p_level    => C_LEVEL_ERROR
1540                       ,p_module   => l_log_module);
1541         END IF;
1542       END IF;
1543    END IF;
1544    --
1545    --
1546    ------------------------------------------------------------------------------------------------
1547    -- 4219869 Business Flow
1548    -- NOTE: XLA_AE_LINES_PKG.ValidateCurrentLine should NOT be generated if business flow method is
1549    -- Prior Entry.  Currently, the following code is always generated.
1550    ------------------------------------------------------------------------------------------------
1551    XLA_AE_LINES_PKG.ValidateCurrentLine;
1552 
1553    ------------------------------------------------------------------------------------
1554    -- 4219869 Business Flow
1555    -- Populated credit and debit amounts -- Need to generate this within IF <condition>
1556    ------------------------------------------------------------------------------------
1557    XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1558 
1559    ----------------------------------------------------------------------------------
1560    -- 4219869 Business Flow
1561    -- Update journal entry status -- Need to generate this within IF <condition>
1562    ----------------------------------------------------------------------------------
1563    XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1564          (p_hdr_idx => g_array_event(p_event_id).array_value_num('header_index')
1565          ,p_balance_type_code => l_balance_type_code
1566          );
1567 
1568    -------------------------------------------------------------------------------------------
1569    -- 4262811 - Generate the Accrual Reversal lines
1570    -------------------------------------------------------------------------------------------
1571    BEGIN
1572       l_acc_rev_flag := XLA_AE_HEADER_PKG.g_rec_header_new.array_accrual_reversal_flag
1573                               (g_array_event(p_event_id).array_value_num('header_index'));
1574       IF l_acc_rev_flag IS NULL THEN
1575          l_acc_rev_flag := 'N';
1576       END IF;
1577    EXCEPTION
1578       WHEN OTHERS THEN
1579          l_acc_rev_flag := 'N';
1580    END;
1581    --
1582    IF (l_acc_rev_flag = 'Y') THEN
1583 
1584        -- 4645092  ------------------------------------------------------------------------------
1585        -- To allow MPA report to determine if it should generate report process
1586        XLA_ACCOUNTING_PKG.g_mpa_accrual_exists := 'Y';
1587        ------------------------------------------------------------------------------------------
1588 
1589        l_accrual_line_num := XLA_AE_LINES_PKG.g_LineNumber;
1590        XLA_AE_LINES_PKG.CopyLineInfo(l_accrual_line_num);
1591 
1592        --
1593        -- Update the line information that should be overwritten
1594        --
1595        XLA_AE_LINES_PKG.set_ae_header_id(p_ae_header_id => p_event_id ,
1596                                          p_header_num   => 1);
1597        XLA_AE_LINES_PKG.g_rec_lines.array_header_num(XLA_AE_LINES_PKG.g_LineNumber)  :=1;
1598 
1602           XLA_AE_LINES_PKG.g_rec_lines.array_reversal_code(XLA_AE_LINES_PKG.g_LineNumber) := CONCAT('MPA_',l_bflow_method_code);
1599        XLA_AE_LINES_PKG.g_rec_lines.array_business_class_code(XLA_AE_LINES_PKG.g_LineNumber) := NULL; -- 4669271
1600 
1601        IF l_bflow_method_code <> 'NONE' THEN  -- 4655713b
1603        END IF;
1604 
1605       --
1606       -- Depending on the Reversal Method setup, do a switch side or changes sign for the amounts
1607       --
1608       IF (XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_reversal_option = 'SIDE') THEN
1609           XLA_AE_LINES_PKG.g_rec_lines.array_natural_side_code(XLA_AE_LINES_PKG.g_LineNumber) :=  l_acc_rev_natural_side_code;
1610       ELSE
1611           ---------------------------------------------------------------------------------------------------
1612           -- 4262811a Switch Sign
1613           ---------------------------------------------------------------------------------------------------
1614           XLA_AE_LINES_PKG.g_rec_lines.array_switch_side_flag(XLA_AE_LINES_PKG.g_LineNumber) := 'N';  -- 5052518
1615           XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1616                       XLA_AE_LINES_PKG.g_rec_lines.array_ledger_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1617           XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) :=
1618                       XLA_AE_LINES_PKG.g_rec_lines.array_entered_amount(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1619           -- 5132302
1620           XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) :=
1621                       XLA_AE_LINES_PKG.g_rec_lines.array_bflow_applied_to_amt(XLA_AE_LINES_PKG.g_LineNumber) * -1;
1622 
1623       END IF;
1624 
1625       -- 4955764
1626       XLA_AE_LINES_PKG.g_rec_lines.array_gl_date(XLA_AE_LINES_PKG.g_LineNumber) :=
1627       XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(g_array_event(p_event_id).array_value_num('acc_rev_header_index'));
1628 
1629 
1630       XLA_AE_LINES_PKG.ValidateCurrentLine;
1631       XLA_AE_LINES_PKG.SetDebitCreditAmounts;
1632 
1633       XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus
1634                (p_hdr_idx           => g_array_event(p_event_id).array_value_num('acc_rev_header_index')
1635                ,p_balance_type_code => l_balance_type_code);
1636 
1637    END IF;
1638 
1639    -----------------------------------------------------------------------------------------
1640    -- 4262811 Multiperiod Accounting
1641    -----------------------------------------------------------------------------------------
1642      -- No MPA option is assigned.
1643 
1644 
1645 END IF;
1646 END IF;
1647 --
1648 
1649 --
1650 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1651    trace
1652       (p_msg      => 'END of AcctLineType_6'
1653       ,p_level    => C_LEVEL_PROCEDURE
1654       ,p_module   => l_log_module);
1655 END IF;
1656 --
1657 EXCEPTION
1658   WHEN xla_exceptions_pkg.application_exception THEN
1659       RAISE;
1660   WHEN OTHERS THEN
1661        xla_exceptions_pkg.raise_message
1662            (p_location => 'XLA_00801_AAD_S_000003_PKG.AcctLineType_6');
1663 END AcctLineType_6;
1664 --
1665 
1666 ---------------------------------------
1667 --
1668 -- PRIVATE PROCEDURE
1669 --         insert_sources_7
1670 --
1671 ----------------------------------------
1672 --
1673 PROCEDURE insert_sources_7(
1674                                 p_target_ledger_id       IN NUMBER
1675                               , p_language               IN VARCHAR2
1676                               , p_sla_ledger_id          IN NUMBER
1677                               , p_pad_start_date         IN DATE
1678                               , p_pad_end_date           IN DATE
1679                          )
1680 IS
1681 
1682 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'PAYMENT_COST';
1683 C_EVENT_CLASS_CODE   CONSTANT  VARCHAR2(30) := 'PAYMENT_COSTS';
1684 p_apps_owner                   VARCHAR2(30);
1685 l_log_module                   VARCHAR2(240);
1686 BEGIN
1687 IF g_log_enabled THEN
1688       l_log_module := C_DEFAULT_MODULE||'.insert_sources_7';
1689 END IF;
1690 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1691 
1692       trace
1693          (p_msg      => 'BEGIN of insert_sources_7'
1694          ,p_level    => C_LEVEL_PROCEDURE
1695          ,p_module   => l_log_module);
1696 
1697 END IF;
1698 
1699 -- select APPS owner
1700 SELECT oracle_username
1701   INTO p_apps_owner
1705 
1702   FROM fnd_oracle_userid
1703  WHERE read_only_flag = 'U'
1704 ;
1706 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1707       trace
1708          (p_msg      => 'p_target_ledger_id = '||p_target_ledger_id||
1709                         ' - p_language = '||p_language||
1710                         ' - p_sla_ledger_id  = '||p_sla_ledger_id ||
1711                         ' - p_pad_start_date = '||TO_CHAR(p_pad_start_date)||
1712                         ' - p_pad_end_date = '||TO_CHAR(p_pad_end_date)||
1713                         ' - p_apps_owner = '||TO_CHAR(p_apps_owner)
1714          ,p_level    => C_LEVEL_STATEMENT
1715          ,p_module   => l_log_module);
1716 END IF;
1717 
1718 
1719 --
1720 INSERT INTO xla_diag_sources --hdr1
1721 (
1722         event_id
1723       , ledger_id
1724       , sla_ledger_id
1725       , description_language
1726       , object_name
1727       , object_type_code
1728       , line_number
1729       , source_application_id
1730       , source_type_code
1731       , source_code
1732       , source_value
1733       , source_meaning
1734       , created_by
1735       , creation_date
1736       , last_update_date
1737       , last_updated_by
1738       , last_update_login
1739       , program_update_date
1740       , program_application_id
1741       , program_id
1742       , request_id
1743 )
1744 SELECT
1745         event_id
1746       , p_target_ledger_id
1747       , p_sla_ledger_id
1748       , p_language
1749       , object_name
1750       , object_type_code
1751       , line_number
1752       , source_application_id
1753       , source_type_code
1754       , source_code
1755       , SUBSTR(source_value ,1,1996)
1756       , SUBSTR(source_meaning,1,200)
1757       , xla_environment_pkg.g_Usr_Id
1758       , TRUNC(SYSDATE)
1759       , TRUNC(SYSDATE)
1760       , xla_environment_pkg.g_Usr_Id
1761       , xla_environment_pkg.g_Login_Id
1762       , TRUNC(SYSDATE)
1763       , xla_environment_pkg.g_Prog_Appl_Id
1764       , xla_environment_pkg.g_Prog_Id
1765       , xla_environment_pkg.g_Req_Id
1766   FROM (
1767        SELECT xet.event_id                  event_id
1768             , 0                             line_number
1769             , CASE r
1770                WHEN 1 THEN 'PAY_XLA_EST_OR_PAYM_ACTIONS_V' 
1771                 WHEN 2 THEN 'PAY_XLA_EST_OR_PAYM_ACTIONS_V' 
1772                 WHEN 3 THEN 'PAY_XLA_EST_OR_PAYM_ACTIONS_V' 
1773                 WHEN 4 THEN 'PAY_XLA_EST_OR_PAYM_ACTIONS_V' 
1774                 
1775                ELSE null
1776               END                           object_name
1777             , CASE r
1778                 WHEN 1 THEN 'HEADER' 
1779                 WHEN 2 THEN 'HEADER' 
1780                 WHEN 3 THEN 'HEADER' 
1781                 WHEN 4 THEN 'HEADER' 
1782                 
1783                 ELSE null
1784               END                           object_type_code
1785             , CASE r
1786                 WHEN 1 THEN '801' 
1787                 WHEN 2 THEN '801' 
1788                 WHEN 3 THEN '801' 
1789                 WHEN 4 THEN '801' 
1790                 
1791                 ELSE null
1792               END                           source_application_id
1793             , 'S'             source_type_code
1794             , CASE r
1795                 WHEN 1 THEN 'PERSON_NAME' 
1796                 WHEN 2 THEN 'ASSIGNMENT_ACTION_ID' 
1797                 WHEN 3 THEN 'COST_ACTION_TYPE' 
1798                 WHEN 4 THEN 'CONVERSION_RATE_TYPE' 
1799                 
1800                 ELSE null
1801               END                           source_code
1802             , CASE r
1803                 WHEN 1 THEN TO_CHAR(h1.PERSON_NAME)
1804                 WHEN 2 THEN TO_CHAR(h1.ASSIGNMENT_ACTION_ID)
1805                 WHEN 3 THEN TO_CHAR(h1.COST_ACTION_TYPE)
1806                 WHEN 4 THEN TO_CHAR(h1.CONVERSION_RATE_TYPE)
1807                 
1808                 ELSE null
1809               END                           source_value
1810             , null              source_meaning
1811         FROM xla_events_gt     xet  
1812       , PAY_XLA_EST_OR_PAYM_ACTIONS_V  h1
1813             ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
1814        WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
1815          AND xet.event_type_code = C_EVENT_TYPE_CODE
1816             AND h1.event_id = xet.event_id
1817 
1818 )
1819 ;
1820 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1821 
1822       trace
1823          (p_msg      => 'number of header sources inserted = '||SQL%ROWCOUNT
1824          ,p_level    => C_LEVEL_STATEMENT
1825          ,p_module   => l_log_module);
1826 
1827 END IF;
1828 --
1829 
1830 
1831 
1832 --
1833 INSERT INTO xla_diag_sources --line1
1834 (
1835         event_id
1836       , ledger_id
1837       , sla_ledger_id
1838       , description_language
1839       , object_name
1840       , object_type_code
1841       , line_number
1842       , source_application_id
1843       , source_type_code
1844       , source_code
1845       , source_value
1846       , source_meaning
1847       , created_by
1848       , creation_date
1849       , last_update_date
1850       , last_updated_by
1851       , last_update_login
1852       , program_update_date
1853       , program_application_id
1854       , program_id
1855       , request_id
1856 )
1857 SELECT  event_id
1858       , p_target_ledger_id
1859       , p_sla_ledger_id
1860       , p_language
1861       , object_name
1862       , object_type_code
1863       , line_number
1864       , source_application_id
1865       , source_type_code
1866       , source_code
1867       , SUBSTR(source_value,1,1996)
1868       , SUBSTR(source_meaning,1,200)
1869       , xla_environment_pkg.g_Usr_Id
1870       , TRUNC(SYSDATE)
1871       , TRUNC(SYSDATE)
1872       , xla_environment_pkg.g_Usr_Id
1873       , xla_environment_pkg.g_Login_Id
1874       , TRUNC(SYSDATE)
1875       , xla_environment_pkg.g_Prog_Appl_Id
1876       , xla_environment_pkg.g_Prog_Id
1877       , xla_environment_pkg.g_Req_Id
1878   FROM (
1879        SELECT xet.event_id                  event_id
1880             , l2.line_number                 line_number
1881             , CASE r
1882                WHEN 1 THEN 'PAY_XLA_PAYMENT_COSTS_V' 
1883                 WHEN 2 THEN 'PAY_XLA_PAYMENT_COSTS_V' 
1884                 WHEN 3 THEN 'PAY_XLA_PAYMENT_COSTS_V' 
1885                 WHEN 4 THEN 'PAY_XLA_PAYMENT_COSTS_V' 
1886                 
1887                ELSE null
1888               END                           object_name
1892                 WHEN 3 THEN 'LINE' 
1889             , CASE r
1890                 WHEN 1 THEN 'LINE' 
1891                 WHEN 2 THEN 'LINE' 
1893                 WHEN 4 THEN 'LINE' 
1894                 
1895                 ELSE null
1896               END                           object_type_code
1897             , CASE r
1898                 WHEN 1 THEN '801' 
1899                 WHEN 2 THEN '801' 
1900                 WHEN 3 THEN '801' 
1901                 WHEN 4 THEN '801' 
1902                 
1903                 ELSE null
1904               END                           source_application_id
1905             , 'S'             source_type_code
1906             , CASE r
1907                 WHEN 1 THEN 'DEBIT_OR_CREDIT' 
1908                 WHEN 2 THEN 'ACCOUNT_ID' 
1909                 WHEN 3 THEN 'COSTED_VALUE' 
1910                 WHEN 4 THEN 'CURRENCY_CODE' 
1911                 
1912                 ELSE null
1913               END                           source_code
1914             , CASE r
1915                 WHEN 1 THEN TO_CHAR(l2.DEBIT_OR_CREDIT)
1916                 WHEN 2 THEN TO_CHAR(l2.ACCOUNT_ID)
1917                 WHEN 3 THEN TO_CHAR(l2.COSTED_VALUE)
1918                 WHEN 4 THEN TO_CHAR(l2.CURRENCY_CODE)
1919                 
1920                 ELSE null
1921               END                           source_value
1922             , null              source_meaning
1923          FROM  xla_events_gt     xet  
1924         , PAY_XLA_PAYMENT_COSTS_V  l2
1925             ,(select rownum r from all_objects where rownum <= 4 and owner = p_apps_owner)
1926         WHERE xet.event_date between p_pad_start_date AND p_pad_end_date
1927           AND xet.event_type_code = C_EVENT_TYPE_CODE
1928             AND l2.event_id          = xet.event_id
1929 
1930 )
1931 ;
1932 --
1933 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
1934 
1935       trace
1936          (p_msg      => 'number of line sources inserted = '||SQL%ROWCOUNT
1937          ,p_level    => C_LEVEL_STATEMENT
1938          ,p_module   => l_log_module);
1939 
1940 END IF;
1941 
1942 
1943 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
1944       trace
1945          (p_msg      => 'END of insert_sources_7'
1946          ,p_level    => C_LEVEL_PROCEDURE
1947          ,p_module   => l_log_module);
1948 END IF;
1949 EXCEPTION
1950   WHEN xla_exceptions_pkg.application_exception THEN
1951       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1952             trace
1953                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1954                ,p_level    => C_LEVEL_EXCEPTION
1955                ,p_module   => l_log_module);
1956       END IF;
1957       RAISE;
1958   WHEN OTHERS THEN
1959       IF (C_LEVEL_EXCEPTION >= g_log_level) THEN
1960             trace
1961                (p_msg      => 'ERROR: XLA_CMP_COMPILER_ERROR = '||sqlerrm
1962                ,p_level    => C_LEVEL_EXCEPTION
1963                ,p_module   => l_log_module);
1964        END IF;
1965        xla_exceptions_pkg.raise_message
1966            (p_location => 'XLA_00801_AAD_S_000003_PKG.insert_sources_7');
1967 END insert_sources_7;
1968 --
1969 
1970 ---------------------------------------
1971 --
1972 -- PRIVATE FUNCTION
1973 --         EventType_7
1974 --
1975 ----------------------------------------
1976 --
1977 FUNCTION EventType_7
1981        ,p_language               IN VARCHAR2
1978        (p_application_id         IN NUMBER
1979        ,p_base_ledger_id         IN NUMBER
1980        ,p_target_ledger_id       IN NUMBER
1982        ,p_currency_code          IN VARCHAR2
1983        ,p_sla_ledger_id          IN NUMBER
1984        ,p_pad_start_date         IN DATE
1985        ,p_pad_end_date           IN DATE
1986        ,p_primary_ledger_id      IN NUMBER)
1987 RETURN BOOLEAN IS
1988 --
1989 C_EVENT_TYPE_CODE    CONSTANT  VARCHAR2(30)  := 'PAYMENT_COST';
1990 C_EVENT_CLASS_CODE    CONSTANT  VARCHAR2(30) := 'PAYMENT_COSTS';
1991 
1992 l_calculate_acctd_flag   VARCHAR2(1) :='Y';
1993 l_calculate_g_l_flag     VARCHAR2(1) :='Y';
1994 --
1995 l_array_legal_entity_id                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
1996 l_array_entity_id                      XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
1997 l_array_entity_code                    XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
1998 l_array_transaction_num                XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
1999 l_array_event_id                       XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2000 l_array_class_code                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
2001 l_array_event_type                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
2002 l_array_event_number                   XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2003 l_array_event_date                     XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2004 l_array_transaction_date               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2005 l_array_reference_num_1                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2006 l_array_reference_num_2                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2007 l_array_reference_num_3                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2008 l_array_reference_num_4                XLA_AE_JOURNAL_ENTRY_PKG.t_array_Num;
2009 l_array_reference_char_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
2010 l_array_reference_char_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
2011 l_array_reference_char_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
2012 l_array_reference_char_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V240L;
2013 l_array_reference_date_1               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2014 l_array_reference_date_2               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2015 l_array_reference_date_3               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2016 l_array_reference_date_4               XLA_AE_JOURNAL_ENTRY_PKG.t_array_Date;
2017 l_array_event_created_by               XLA_AE_JOURNAL_ENTRY_PKG.t_array_V100L;
2018 l_array_budgetary_control_flag         XLA_AE_JOURNAL_ENTRY_PKG.t_array_V30L;
2019 
2020 l_event_id                             NUMBER;
2021 l_previous_event_id                    NUMBER;
2022 l_first_event_id                       NUMBER;
2023 l_last_event_id                        NUMBER;
2024 
2025 l_rec_acct_attrs                       XLA_AE_HEADER_PKG.t_rec_acct_attrs;
2026 l_rec_rev_acct_attrs                   XLA_AE_LINES_PKG.t_rec_acct_attrs;
2027 --
2028 --
2029 l_result                    BOOLEAN := TRUE;
2030 l_rows                      NUMBER  := 1000;
2031 l_event_type_name           VARCHAR2(80) := 'Payment Cost';
2032 l_event_class_name          VARCHAR2(80) := 'Payment Costs';
2033 l_description               VARCHAR2(4000);
2034 l_transaction_reversal      NUMBER;
2035 l_ae_header_id              NUMBER;
2036 l_array_extract_line_num    xla_ae_journal_entry_pkg.t_array_Num;
2037 l_log_module                VARCHAR2(240);
2038 --
2039 l_acct_reversal_source      VARCHAR2(30);
2040 l_trx_reversal_source       VARCHAR2(30);
2041 
2042 l_continue_with_lines       BOOLEAN := TRUE;
2043 --
2044 l_acc_rev_gl_date_source    DATE;                      -- 4262811
2045 --
2046 type t_array_event_id is table of number index by binary_integer;
2047 
2048 l_rec_array_event                    t_rec_array_event;
2049 l_null_rec_array_event               t_rec_array_event;
2050 l_array_ae_header_id                 xla_number_array_type;
2051 l_actual_flag                        VARCHAR2(1) := NULL;
2052 l_actual_gain_loss_ref               VARCHAR2(30) := '#####';
2053 l_balance_type_code                  VARCHAR2(1) :=NULL;
2054 l_gain_or_loss_ref                   VARCHAR2(30) :=NULL;
2055 
2056 --
2057 TYPE t_array_lookup_meaning IS TABLE OF fnd_lookup_values.meaning%TYPE INDEX BY BINARY_INTEGER;
2058 --
2059 
2060 TYPE t_array_source_3 IS TABLE OF PAY_XLA_EST_OR_PAYM_ACTIONS_V.PERSON_NAME%TYPE INDEX BY BINARY_INTEGER;
2061 TYPE t_array_source_6 IS TABLE OF PAY_XLA_EST_OR_PAYM_ACTIONS_V.ASSIGNMENT_ACTION_ID%TYPE INDEX BY BINARY_INTEGER;
2062 TYPE t_array_source_7 IS TABLE OF PAY_XLA_EST_OR_PAYM_ACTIONS_V.COST_ACTION_TYPE%TYPE INDEX BY BINARY_INTEGER;
2066 TYPE t_array_source_5 IS TABLE OF PAY_XLA_PAYMENT_COSTS_V.ACCOUNT_ID%TYPE INDEX BY BINARY_INTEGER;
2063 TYPE t_array_source_10 IS TABLE OF PAY_XLA_EST_OR_PAYM_ACTIONS_V.CONVERSION_RATE_TYPE%TYPE INDEX BY BINARY_INTEGER;
2064 
2065 TYPE t_array_source_1 IS TABLE OF PAY_XLA_PAYMENT_COSTS_V.DEBIT_OR_CREDIT%TYPE INDEX BY BINARY_INTEGER;
2067 TYPE t_array_source_8 IS TABLE OF PAY_XLA_PAYMENT_COSTS_V.COSTED_VALUE%TYPE INDEX BY BINARY_INTEGER;
2068 TYPE t_array_source_9 IS TABLE OF PAY_XLA_PAYMENT_COSTS_V.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
2069 
2070 l_array_source_3              t_array_source_3;
2071 l_array_source_6              t_array_source_6;
2072 l_array_source_7              t_array_source_7;
2073 l_array_source_10              t_array_source_10;
2074 
2075 l_array_source_1      t_array_source_1;
2076 l_array_source_5      t_array_source_5;
2077 l_array_source_8      t_array_source_8;
2078 l_array_source_9      t_array_source_9;
2079 
2080 --
2081 CURSOR header_cur
2082 IS
2083 SELECT /*+ leading(xet) cardinality(xet,1) */
2084 -- Event Type Code: PAYMENT_COST
2085 -- Event Class Code: PAYMENT_COSTS
2086     xet.entity_id
2087   , xet.legal_entity_id
2088   , xet.entity_code
2089   , xet.transaction_number
2090   , xet.event_id
2091   , xet.event_class_code
2092   , xet.event_type_code
2093   , xet.event_number
2094   , xet.event_date
2095   , xet.transaction_date
2096   , xet.reference_num_1
2097   , xet.reference_num_2
2098   , xet.reference_num_3
2099   , xet.reference_num_4
2100   , xet.reference_char_1
2101   , xet.reference_char_2
2102   , xet.reference_char_3
2103   , xet.reference_char_4
2104   , xet.reference_date_1
2105   , xet.reference_date_2
2106   , xet.reference_date_3
2107   , xet.reference_date_4
2108   , xet.event_created_by
2109   , xet.budgetary_control_flag 
2110   , h1.PERSON_NAME    source_3
2111   , h1.ASSIGNMENT_ACTION_ID    source_6
2112   , h1.COST_ACTION_TYPE    source_7
2113   , h1.CONVERSION_RATE_TYPE    source_10
2114   FROM xla_events_gt     xet 
2115   , PAY_XLA_EST_OR_PAYM_ACTIONS_V  h1
2116  WHERE xet.event_date between p_pad_start_date and p_pad_end_date
2117    and xet.event_type_code = C_EVENT_TYPE_CODE
2118    and xet.event_status_code <> 'N'  AND h1.event_id = xet.event_id
2119 
2120  ORDER BY event_id
2121 ;
2122 
2123 
2124 --
2125 CURSOR line_cur (x_first_event_id    in number, x_last_event_id    in number)
2126 IS
2127 SELECT /*+ leading(xet) cardinality(xet,1) */
2128 -- Event Type Code: PAYMENT_COST
2129 -- Event Class Code: PAYMENT_COSTS
2130     xet.entity_id
2131    ,xet.legal_entity_id
2132    ,xet.entity_code
2133    ,xet.transaction_number
2134    ,xet.event_id
2135    ,xet.event_class_code
2136    ,xet.event_type_code
2137    ,xet.event_number
2138    ,xet.event_date
2139    ,xet.transaction_date
2140    ,xet.reference_num_1
2141    ,xet.reference_num_2
2142    ,xet.reference_num_3
2143    ,xet.reference_num_4
2144    ,xet.reference_char_1
2145    ,xet.reference_char_2
2146    ,xet.reference_char_3
2147    ,xet.reference_char_4
2148    ,xet.reference_date_1
2149    ,xet.reference_date_2
2150    ,xet.reference_date_3
2151    ,xet.reference_date_4
2152    ,xet.event_created_by
2153    ,xet.budgetary_control_flag  , l2.LINE_NUMBER  
2154   , l2.DEBIT_OR_CREDIT    source_1
2155   , l2.ACCOUNT_ID    source_5
2156   , l2.COSTED_VALUE    source_8
2157   , l2.CURRENCY_CODE    source_9
2158   FROM xla_events_gt     xet 
2159   , PAY_XLA_PAYMENT_COSTS_V  l2
2160  WHERE xet.event_id between x_first_event_id and x_last_event_id
2161    and xet.event_date between p_pad_start_date and p_pad_end_date
2162    and xet.event_type_code = C_EVENT_TYPE_CODE
2163    and xet.event_status_code <> 'N'   AND l2.event_id      = xet.event_id
2164 ;
2165 
2166 --
2167 BEGIN
2168 IF g_log_enabled THEN
2169    l_log_module := C_DEFAULT_MODULE||'.EventType_7';
2170 END IF;
2171 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2172    trace
2173       (p_msg      => 'BEGIN of EventType_7'
2174       ,p_level    => C_LEVEL_PROCEDURE
2175       ,p_module   => l_log_module);
2176 END IF;
2177 
2178 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2179    trace
2180       (p_msg      => 'p_application_id = '||p_application_id||
2181                      ' - p_base_ledger_id = '||p_base_ledger_id||
2182                      ' - p_target_ledger_id  = '||p_target_ledger_id||
2183                      ' - p_language = '||p_language||
2184                      ' - p_currency_code = '||p_currency_code||
2185                      ' - p_sla_ledger_id = '||p_sla_ledger_id
2186       ,p_level    => C_LEVEL_STATEMENT
2187       ,p_module   => l_log_module);
2188 END IF;
2189 --
2190 -- initialze arrays
2191 --
2192 g_array_event.DELETE;
2193 l_rec_array_event := l_null_rec_array_event;
2194 --
2195 --------------------------------------
2196 -- 4262811 Initialze MPA Line Number
2197 --------------------------------------
2198 XLA_AE_HEADER_PKG.g_mpa_line_num := 0;
2199 
2200 --
2201 
2202 --
2203 OPEN header_cur;
2204 --
2205 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2206    trace
2207    (p_msg      => 'SQL - FETCH header_cur'
2208    ,p_level    => C_LEVEL_STATEMENT
2209    ,p_module   => l_log_module);
2210 END IF;
2211 --
2212 LOOP
2213 FETCH header_cur BULK COLLECT INTO
2214         l_array_entity_id
2215       , l_array_legal_entity_id
2216       , l_array_entity_code
2217       , l_array_transaction_num
2218       , l_array_event_id
2219       , l_array_class_code
2223       , l_array_transaction_date
2220       , l_array_event_type
2221       , l_array_event_number
2222       , l_array_event_date
2224       , l_array_reference_num_1
2225       , l_array_reference_num_2
2226       , l_array_reference_num_3
2227       , l_array_reference_num_4
2228       , l_array_reference_char_1
2229       , l_array_reference_char_2
2230       , l_array_reference_char_3
2231       , l_array_reference_char_4
2232       , l_array_reference_date_1
2233       , l_array_reference_date_2
2234       , l_array_reference_date_3
2235       , l_array_reference_date_4
2236       , l_array_event_created_by
2237       , l_array_budgetary_control_flag 
2238       , l_array_source_3
2239       , l_array_source_6
2240       , l_array_source_7
2241       , l_array_source_10
2242       LIMIT l_rows;
2243 --
2244 IF (C_LEVEL_EVENT >= g_log_level) THEN
2245    trace
2246    (p_msg      => '# rows extracted from header extract objects = '||TO_CHAR(header_cur%ROWCOUNT)
2247    ,p_level    => C_LEVEL_EVENT
2248    ,p_module   => l_log_module);
2249 END IF;
2250 --
2251 EXIT WHEN l_array_entity_id.COUNT = 0;
2252 
2253 -- initialize arrays
2254 XLA_AE_HEADER_PKG.g_rec_header_new        := NULL;
2255 XLA_AE_LINES_PKG.g_rec_lines              := NULL;
2256 
2257 --
2258 -- Bug 4458708
2259 --
2260 XLA_AE_LINES_PKG.g_LineNumber := 0;
2261 
2262 
2263 -- 4262811 - when creating Accrual Reversal or MPA, use g_last_hdr_idx to increment for next header id
2264 g_last_hdr_idx := l_array_event_id.LAST;
2265 --
2266 -- loop for the headers. Each iteration is for each header extract row
2267 -- fetched in header cursor
2268 --
2269 FOR hdr_idx IN l_array_event_id.FIRST .. l_array_event_id.LAST LOOP
2270 
2271 --
2272 -- set event info as cache for other routines to refer event attributes
2273 --
2274 XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
2275    (p_application_id           => p_application_id
2276    ,p_primary_ledger_id        => p_primary_ledger_id
2277    ,p_base_ledger_id           => p_base_ledger_id
2278    ,p_target_ledger_id         => p_target_ledger_id
2279    ,p_entity_id                => l_array_entity_id(hdr_idx)
2280    ,p_legal_entity_id          => l_array_legal_entity_id(hdr_idx)
2281    ,p_entity_code              => l_array_entity_code(hdr_idx)
2282    ,p_transaction_num          => l_array_transaction_num(hdr_idx)
2283    ,p_event_id                 => l_array_event_id(hdr_idx)
2284    ,p_event_class_code         => l_array_class_code(hdr_idx)
2285    ,p_event_type_code          => l_array_event_type(hdr_idx)
2286    ,p_event_number             => l_array_event_number(hdr_idx)
2287    ,p_event_date               => l_array_event_date(hdr_idx)
2288    ,p_transaction_date         => l_array_transaction_date(hdr_idx)
2289    ,p_reference_num_1          => l_array_reference_num_1(hdr_idx)
2290    ,p_reference_num_2          => l_array_reference_num_2(hdr_idx)
2291    ,p_reference_num_3          => l_array_reference_num_3(hdr_idx)
2292    ,p_reference_num_4          => l_array_reference_num_4(hdr_idx)
2293    ,p_reference_char_1         => l_array_reference_char_1(hdr_idx)
2294    ,p_reference_char_2         => l_array_reference_char_2(hdr_idx)
2295    ,p_reference_char_3         => l_array_reference_char_3(hdr_idx)
2296    ,p_reference_char_4         => l_array_reference_char_4(hdr_idx)
2297    ,p_reference_date_1         => l_array_reference_date_1(hdr_idx)
2298    ,p_reference_date_2         => l_array_reference_date_2(hdr_idx)
2299    ,p_reference_date_3         => l_array_reference_date_3(hdr_idx)
2300    ,p_reference_date_4         => l_array_reference_date_4(hdr_idx)
2301    ,p_event_created_by         => l_array_event_created_by(hdr_idx)
2302    ,p_budgetary_control_flag   => l_array_budgetary_control_flag(hdr_idx));
2303 
2304 --
2305 -- set the status of entry to C_VALID (0)
2306 --
2307 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status    := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
2308 
2309 --
2310 -- initialize a row for ae header
2311 --
2312 XLA_AE_HEADER_PKG.InitHeader(hdr_idx);
2313 
2314 l_event_id := l_array_event_id(hdr_idx);
2315 
2316 --
2317 -- storing the hdr_idx for event. May be used by line cursor.
2318 --
2319 g_array_event(l_event_id).array_value_num('header_index') := hdr_idx;
2320 
2321 --
2322 -- store sources from header extract. This can be improved to
2323 -- store only those sources from header extract that may be used in lines
2324 --
2325 
2326 g_array_event(l_event_id).array_value_char('source_3') := l_array_source_3(hdr_idx);
2327 g_array_event(l_event_id).array_value_num('source_6') := l_array_source_6(hdr_idx);
2328 g_array_event(l_event_id).array_value_char('source_7') := l_array_source_7(hdr_idx);
2329 g_array_event(l_event_id).array_value_char('source_10') := l_array_source_10(hdr_idx);
2330 
2331 --
2332 -- initilaize the status of ae headers for diffrent balance types
2333 -- the status is initialised to C_NOT_CREATED (2)
2334 --
2335 --g_array_event(l_event_id).array_value_num('actual_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
2336 --g_array_event(l_event_id).array_value_num('budget_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
2337 --g_array_event(l_event_id).array_value_num('encumbrance_je_status') := XLA_AE_JOURNAL_ENTRY_PKG.C_NOT_CREATED;
2338 
2339 --
2340 -- call api to validate and store accounting attributes for header
2341 --
2342 
2343 ------------------------------------------------------------
2344 -- Accrual Reversal : to get date for Standard Source (NONE)
2345 ------------------------------------------------------------
2346 l_acc_rev_gl_date_source := NULL;
2347 
2348      l_rec_acct_attrs.array_acct_attr_code(1)   := 'GL_DATE';
2349       l_rec_acct_attrs.array_date_value(1) := 
2350 xla_ae_sources_pkg.GetSystemSourceDate(
2351    p_source_code           => 'XLA_EVENT_DATE'
2352  , p_source_type_code      => 'Y'
2353  , p_source_application_id =>  602
2354 );
2355 
2356 
2357 XLA_AE_HEADER_PKG.SetHdrAcctAttrs(l_rec_acct_attrs);
2358 
2359 XLA_AE_HEADER_PKG.SetJeCategoryName;
2360 
2361 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_type_code(hdr_idx)  := l_array_event_type(hdr_idx);
2362 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_id(hdr_idx)         := l_array_event_id(hdr_idx);
2363 XLA_AE_HEADER_PKG.g_rec_header_new.array_entity_id(hdr_idx)        := l_array_entity_id(hdr_idx);
2364 XLA_AE_HEADER_PKG.g_rec_header_new.array_event_number(hdr_idx)     := l_array_event_number(hdr_idx);
2365 XLA_AE_HEADER_PKG.g_rec_header_new.array_target_ledger_id(hdr_idx) := p_target_ledger_id;
2366 
2367 
2368 --
2369 xla_ae_header_pkg.SetHdrDescription(
2370    p_description => Description_3 (
2371    p_application_id => p_application_id 
2372  , p_source_3 => g_array_event(l_event_id).array_value_char('source_3')
2373    )
2374 );
2375 --
2376 
2377 
2378 
2379 --
2380 --accounting attribute enhancement, bug 3612931
2381 --
2382 l_trx_reversal_source := SUBSTR(NULL, 1,30);
2383 
2384 IF NVL(l_trx_reversal_source, 'N') NOT IN ('N','Y') THEN
2385    xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2386 
2387    xla_accounting_err_pkg.build_message
2388       (p_appli_s_name            => 'XLA'
2389       ,p_msg_name                => 'XLA_AP_INVALID_HDR_ATTR'
2390       ,p_token_1                 => 'ACCT_ATTR_NAME'
2391       ,p_value_1                 => xla_ae_sources_pkg.GetAccountingSourceName('TRX_ACCT_REVERSAL_OPTION')
2392       ,p_token_2                 => 'PRODUCT_NAME'
2393       ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
2394       ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2395       ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2396       ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
2397 
2398 ELSIF NVL(l_trx_reversal_source, 'N') = 'Y' THEN
2399    --
2400    -- following sets the accounting attributes needed to reverse
2401    -- accounting for a distributeion
2402    --
2403    xla_ae_lines_pkg.SetTrxReversalAttrs
2404       (p_event_id              => l_event_id
2405       ,p_gl_date               => XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(hdr_idx)
2406       ,p_trx_reversal_source   => l_trx_reversal_source);
2407 
2408 END IF;
2409 
2410 
2411 ----------------------------------------------------------------
2412 -- 4262811 -  update the header statuses to invalid in need be
2413 ----------------------------------------------------------------
2414 --
2415 XLA_AE_JOURNAL_ENTRY_PKG.UpdateJournalEntryStatus (p_hdr_idx => hdr_idx);
2416 
2417 
2418   -----------------------------------------------
2419   -- No accrual reversal for the event class/type
2420   -----------------------------------------------
2421 ----------------------------------------------------------------
2422 
2423 --
2424 -- this ends the header loop iteration for one bulk fetch
2425 --
2426 END LOOP;
2427 
2428 l_first_event_id   := l_array_event_id(l_array_event_id.FIRST);
2429 l_last_event_id    := l_array_event_id(l_array_event_id.LAST);
2430 
2431 --
2432 -- insert dummy rows into lines gt table that were created due to
2433 -- transaction reversals
2434 --
2435 IF XLA_AE_LINES_PKG.g_rec_lines.array_ae_header_id.COUNT > 0 THEN
2436    l_result := XLA_AE_LINES_PKG.InsertLines;
2437 END IF;
2438 
2442 -- Bug 3939231
2439 --
2440 -- reset the temp_line_num for each set of events fetched from header
2441 -- cursor rather than doing it for each new event in line cursor
2443 --
2444 xla_ae_lines_pkg.g_temp_line_num := 0;
2445 
2446 
2447 
2448 --
2449 OPEN line_cur(x_first_event_id  => l_first_event_id, x_last_event_id  => l_last_event_id);
2450 --
2451 --
2452 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2453 
2454       trace
2455          (p_msg      => 'SQL - FETCH line_cur'
2456          ,p_level    => C_LEVEL_STATEMENT
2457          ,p_module   => l_log_module);
2458 
2459 END IF;
2460 --
2461 --
2462 LOOP
2463   --
2464   FETCH line_cur BULK COLLECT INTO
2465         l_array_entity_id
2466       , l_array_legal_entity_id
2467       , l_array_entity_code
2468       , l_array_transaction_num
2469       , l_array_event_id
2470       , l_array_class_code
2471       , l_array_event_type
2472       , l_array_event_number
2473       , l_array_event_date
2474       , l_array_transaction_date
2475       , l_array_reference_num_1
2476       , l_array_reference_num_2
2477       , l_array_reference_num_3
2478       , l_array_reference_num_4
2479       , l_array_reference_char_1
2480       , l_array_reference_char_2
2481       , l_array_reference_char_3
2482       , l_array_reference_char_4
2483       , l_array_reference_date_1
2484       , l_array_reference_date_2
2485       , l_array_reference_date_3
2486       , l_array_reference_date_4
2487       , l_array_event_created_by
2488       , l_array_budgetary_control_flag
2489       , l_array_extract_line_num 
2490       , l_array_source_1
2491       , l_array_source_5
2492       , l_array_source_8
2493       , l_array_source_9
2494       LIMIT l_rows;
2495 
2496   --
2497   IF (C_LEVEL_EVENT >= g_log_level) THEN
2498             trace
2499                (p_msg      => '# rows extracted from line extract objects = '||TO_CHAR(line_cur%ROWCOUNT)
2500                ,p_level    => C_LEVEL_EVENT
2501                ,p_module   => l_log_module);
2502   END IF;
2503   --
2504   EXIT WHEN l_array_entity_id.count = 0;
2505 
2506   XLA_AE_LINES_PKG.g_rec_lines := null;
2507 
2508 --
2509 -- Bug 4458708
2510 --
2511 XLA_AE_LINES_PKG.g_LineNumber := 0;
2512 --
2513 --
2514 
2515 FOR Idx IN 1..l_array_event_id.count LOOP
2516    --
2517    -- 5648433 (move l_event_id out of IF statement)  set l_event_id to be used inside IF condition
2518    --
2519    l_event_id := l_array_event_id(idx);  -- 5648433
2520 
2521    --
2522    -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
2523    --
2524 
2525    IF NVL(xla_ae_header_pkg.g_rec_header_new.array_trx_acct_reversal_option
2526              (g_array_event(l_event_id).array_value_num('header_index'))
2527          ,'N'
2528          ) <> 'Y'
2529    THEN
2530       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2531          trace
2532             (p_msg      => 'Trancaction revesal option is not Y '
2533             ,p_level    => C_LEVEL_STATEMENT
2534             ,p_module   => l_log_module);
2535       END IF;
2536 
2537 --
2538 -- set the XLA_AE_JOURNAL_ENTRY_PKG.g_global_status to C_VALID (0)
2539 --
2540 XLA_AE_JOURNAL_ENTRY_PKG.g_global_status := XLA_AE_JOURNAL_ENTRY_PKG.C_VALID;
2541 --
2542 -- set event info as cache for other routines to refer event attributes
2543 --
2544 
2545 IF l_event_id <> NVL(l_previous_event_id, -1) THEN
2546    l_previous_event_id := l_event_id;
2547 
2548    XLA_AE_JOURNAL_ENTRY_PKG.set_event_info
2549       (p_application_id           => p_application_id
2550       ,p_primary_ledger_id        => p_primary_ledger_id
2551       ,p_base_ledger_id           => p_base_ledger_id
2552       ,p_target_ledger_id         => p_target_ledger_id
2553       ,p_entity_id                => l_array_entity_id(Idx)
2554       ,p_legal_entity_id          => l_array_legal_entity_id(Idx)
2555       ,p_entity_code              => l_array_entity_code(Idx)
2556       ,p_transaction_num          => l_array_transaction_num(Idx)
2557       ,p_event_id                 => l_array_event_id(Idx)
2558       ,p_event_class_code         => l_array_class_code(Idx)
2559       ,p_event_type_code          => l_array_event_type(Idx)
2563       ,p_reference_num_1          => l_array_reference_num_1(Idx)
2560       ,p_event_number             => l_array_event_number(Idx)
2561       ,p_event_date               => l_array_event_date(Idx)
2562       ,p_transaction_date         => l_array_transaction_date(Idx)
2564       ,p_reference_num_2          => l_array_reference_num_2(Idx)
2565       ,p_reference_num_3          => l_array_reference_num_3(Idx)
2566       ,p_reference_num_4          => l_array_reference_num_4(Idx)
2567       ,p_reference_char_1         => l_array_reference_char_1(Idx)
2568       ,p_reference_char_2         => l_array_reference_char_2(Idx)
2569       ,p_reference_char_3         => l_array_reference_char_3(Idx)
2570       ,p_reference_char_4         => l_array_reference_char_4(Idx)
2571       ,p_reference_date_1         => l_array_reference_date_1(Idx)
2572       ,p_reference_date_2         => l_array_reference_date_2(Idx)
2573       ,p_reference_date_3         => l_array_reference_date_3(Idx)
2574       ,p_reference_date_4         => l_array_reference_date_4(Idx)
2575       ,p_event_created_by         => l_array_event_created_by(Idx)
2576       ,p_budgetary_control_flag   => l_array_budgetary_control_flag(Idx));
2577        --
2578 END IF;
2579 
2580 
2581 
2582 --
2583 xla_ae_lines_pkg.SetExtractLine(p_extract_line => l_array_extract_line_num(Idx));
2584 
2585 l_acct_reversal_source := SUBSTR(NULL, 1,30);
2586 
2587 IF l_continue_with_lines THEN
2588    IF NVL(l_acct_reversal_source, 'N') NOT IN ('N','Y','B') THEN
2589       xla_ae_journal_entry_pkg.g_global_status      :=  xla_ae_journal_entry_pkg.C_INVALID;
2590 
2591       xla_accounting_err_pkg.build_message
2592          (p_appli_s_name            => 'XLA'
2593          ,p_msg_name                => 'XLA_AP_INVALID_REVERSAL_OPTION'
2594          ,p_token_1                 => 'LINE_NUMBER'
2595          ,p_value_1                 => l_array_extract_line_num(Idx)
2596          ,p_token_2                 => 'PRODUCT_NAME'
2597          ,p_value_2                 => xla_ae_journal_entry_pkg.g_cache_event.application_name
2598          ,p_entity_id               => xla_ae_journal_entry_pkg.g_cache_event.entity_id
2599          ,p_event_id                => xla_ae_journal_entry_pkg.g_cache_event.event_id
2600          ,p_ledger_id               => xla_ae_journal_entry_pkg.g_cache_event.target_ledger_id);
2601 
2602    ELSIF NVL(l_acct_reversal_source, 'N') IN ('Y','B') THEN
2603       --
2604       -- following sets the accounting attributes needed to reverse
2605       -- accounting for a distributeion
2606       --
2607 
2608       --
2609       -- 5217187
2610       --
2611       l_rec_rev_acct_attrs.array_acct_attr_code(1):= 'GL_DATE';
2612       l_rec_rev_acct_attrs.array_date_value(1) := XLA_AE_HEADER_PKG.g_rec_header_new.array_gl_date(
2613                                        g_array_event(l_event_id).array_value_num('header_index'));
2614       --
2615       --
2616 
2617       -- No reversal code generated
2618 
2619       xla_ae_lines_pkg.SetAcctReversalAttrs
2620          (p_event_id             => l_event_id
2621          ,p_rec_acct_attrs       => l_rec_rev_acct_attrs
2622          ,p_calculate_acctd_flag => l_calculate_acctd_flag
2623          ,p_calculate_g_l_flag   => l_calculate_g_l_flag);
2624    END IF;
2625 
2626    IF NVL(l_acct_reversal_source, 'N') IN ('N','B') THEN
2627        l_actual_flag := NULL;  l_actual_gain_loss_ref := '#####';
2628 
2629 --
2630 AcctLineType_5 (
2631  p_application_id  => p_application_id
2632  ,p_event_id     => l_event_id
2633  ,p_calculate_acctd_flag => l_calculate_acctd_flag
2634  ,p_calculate_g_l_flag => l_calculate_g_l_flag
2635  ,p_actual_flag => l_actual_flag
2636  ,p_balance_type_code => l_balance_type_code
2637  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
2638  
2639  , p_source_1 => l_array_source_1(Idx)
2640  , p_source_5 => l_array_source_5(Idx)
2641  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
2642  , p_source_7 => g_array_event(l_event_id).array_value_char('source_7')
2643  , p_source_8 => l_array_source_8(Idx)
2644  , p_source_9 => l_array_source_9(Idx)
2645  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
2646  );
2647 If(l_balance_type_code = 'A') THEN
2648   l_actual_gain_loss_ref := l_gain_or_loss_ref;
2649 END IF;
2650 
2651 --
2652 
2653 
2654 --
2655 AcctLineType_6 (
2656  p_application_id  => p_application_id
2657  ,p_event_id     => l_event_id
2658  ,p_calculate_acctd_flag => l_calculate_acctd_flag
2659  ,p_calculate_g_l_flag => l_calculate_g_l_flag
2660  ,p_actual_flag => l_actual_flag
2661  ,p_balance_type_code => l_balance_type_code
2662  ,p_gain_or_loss_ref=> l_gain_or_loss_ref
2663  
2664  , p_source_1 => l_array_source_1(Idx)
2665  , p_source_5 => l_array_source_5(Idx)
2666  , p_source_6 => g_array_event(l_event_id).array_value_num('source_6')
2667  , p_source_7 => g_array_event(l_event_id).array_value_char('source_7')
2668  , p_source_8 => l_array_source_8(Idx)
2669  , p_source_9 => l_array_source_9(Idx)
2670  , p_source_10 => g_array_event(l_event_id).array_value_char('source_10')
2671  );
2672 If(l_balance_type_code = 'A') THEN
2673   l_actual_gain_loss_ref := l_gain_or_loss_ref;
2674 END IF;
2675 
2676 --
2677 
2678       -- only execute it if calculate g/l flag is yes, and primary or secondary ledger
2679       -- or secondary ledger that has different currency with primary
2680       -- or alc that is calculated by sla
2681       IF (((l_calculate_g_l_flag = 'Y' AND XLA_AE_JOURNAL_ENTRY_PKG.g_cache_ledgers_info.ledger_category_code <> 'ALC') or
2682             (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'))
2683 
2684 --      IF((l_calculate_g_l_flag='Y' or XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.target_ledger_id <>
2685 --                    XLA_AE_JOURNAL_ENTRY_PKG.g_cache_event.ledger_id)
2686           AND (l_actual_flag = 'A')) THEN
2687         XLA_AE_LINES_PKG.CreateGainOrLossLines(
2688           p_event_id         => xla_ae_journal_entry_pkg.g_cache_event.event_id
2689          ,p_application_id   => p_application_id
2690          ,p_amb_context_code => 'DEFAULT'
2691          ,p_entity_code      => xla_ae_journal_entry_pkg.g_cache_event.entity_code
2692          ,p_event_class_code => C_EVENT_CLASS_CODE
2693          ,p_event_type_code  => C_EVENT_TYPE_CODE
2694          
2695          ,p_gain_ccid        => -1
2696          ,p_loss_ccid        => -1
2697 
2698          ,p_actual_flag      => l_actual_flag
2699          ,p_enc_flag         => null
2700          ,p_actual_g_l_ref   => l_actual_gain_loss_ref
2701          ,p_enc_g_l_ref      => null
2702          );
2703       END IF;
2704    END IF;
2705 END IF;
2706 
2707    ELSE
2708       --
2709       -- Bug 4872078 - Do nothing if the event is meant for transaction reversal
2710       --
2711       IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2712          trace
2713             (p_msg      => 'Trancaction revesal option is Y'
2714             ,p_level    => C_LEVEL_STATEMENT
2715             ,p_module   => l_log_module);
2716       END IF;
2717    END IF;
2718 
2719 END LOOP;
2720 l_result := XLA_AE_LINES_PKG.InsertLines ;
2721 end loop;
2722 close line_cur;
2723 
2724 
2725 --
2729 
2726 -- insert headers into xla_ae_headers_gt table
2727 --
2728 l_result := XLA_AE_HEADER_PKG.InsertHeaders ;
2730 -- insert into errors table here.
2731 
2732 END LOOP;
2733 
2734 --
2735 -- 4865292
2736 --
2737 -- Compare g_hdr_extract_count with event count in
2738 -- CreateHeadersAndLines.
2739 --
2740 g_hdr_extract_count := g_hdr_extract_count + header_cur%ROWCOUNT;
2741 
2742 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2743    trace (p_msg     => '# rows extracted from header extract objects '
2744                     || ' (running total): '
2745                     || g_hdr_extract_count
2746          ,p_level   => C_LEVEL_STATEMENT
2747          ,p_module  => l_log_module);
2748 END IF;
2749 
2750 CLOSE header_cur;
2751 --
2752 
2753 --
2754 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2755    trace
2756       (p_msg      => 'END of EventType_7'
2757       ,p_level    => C_LEVEL_PROCEDURE
2758       ,p_module   => l_log_module);
2759 END IF;
2760 --
2761 RETURN l_result;
2762 EXCEPTION
2763 WHEN xla_exceptions_pkg.application_exception THEN
2764    
2765 IF header_cur%ISOPEN THEN CLOSE header_cur; END IF;
2766 
2767    
2768 IF line_cur%ISOPEN   THEN CLOSE line_cur;   END IF;
2769 
2770    RAISE;
2771 WHEN OTHERS THEN
2772    xla_exceptions_pkg.raise_message
2773       (p_location => 'XLA_00801_AAD_S_000003_PKG.EventType_7');
2774 END EventType_7;
2775 --
2776 
2777 --
2778 --+============================================+
2779 --|                                            |
2780 --|  PRIVATE FUNCTION                          |
2781 --|                                            |
2782 --+============================================+
2783 --
2784 FUNCTION CreateHeadersAndLines
2785        (p_application_id         IN NUMBER
2786        ,p_base_ledger_id         IN NUMBER
2787        ,p_target_ledger_id       IN NUMBER
2788        ,p_pad_start_date         IN DATE
2789        ,p_pad_end_date           IN DATE
2790        ,p_primary_ledger_id      IN NUMBER)
2791 RETURN BOOLEAN IS
2792 l_created                   BOOLEAN:=FALSE;
2793 l_event_id                  NUMBER;
2794 l_event_date                DATE;
2795 l_language                  VARCHAR2(30);
2796 l_currency_code             VARCHAR2(30);
2797 l_sla_ledger_id             NUMBER;
2798 l_log_module                VARCHAR2(240);
2799 
2800 BEGIN
2801 --
2802 IF g_log_enabled THEN
2803    l_log_module := C_DEFAULT_MODULE||'.CreateHeadersAndLines';
2804 END IF;
2805 --
2806 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2807    trace
2808       (p_msg      => 'BEGIN of CreateHeadersAndLines'
2809       ,p_level    => C_LEVEL_PROCEDURE
2810       ,p_module   => l_log_module);
2811 END IF;
2812 
2813 l_language         := xla_ae_journal_entry_pkg.g_cache_ledgers_info.description_language;
2814 l_currency_code    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.currency_code;
2815 l_sla_ledger_id    := xla_ae_journal_entry_pkg.g_cache_ledgers_info.sla_ledger_id;
2816 
2817 --
2818 -- initialize array of lines with NULL
2819 --
2820 xla_ae_lines_pkg.SetNullLine;
2821 
2822 --
2823 -- initialize header extract count -- Bug 4865292
2824 --
2825 g_hdr_extract_count:= 0;
2826 
2827 
2828  l_created :=  EventType_7(
2829    p_application_id         => p_application_id
2830  , p_base_ledger_id         => p_base_ledger_id
2831  , p_target_ledger_id       => p_target_ledger_id
2832  , p_language               => l_language
2833  , p_currency_code          => l_currency_code
2834  , p_sla_ledger_id          => l_sla_ledger_id
2835  , p_pad_start_date         => p_pad_start_date
2836  , p_pad_end_date           => p_pad_end_date
2837  , p_primary_ledger_id      => p_primary_ledger_id
2838 );
2839 
2840 
2841 
2842      IF ( g_diagnostics_mode ='Y' ) THEN
2843 
2844          IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2845           trace
2846               (p_msg      => 'CALL Transaction Objects Diagnostics'
2847               ,p_level    => C_LEVEL_STATEMENT
2848               ,p_module   => l_log_module);
2849 
2850          END IF;
2851 
2852          insert_sources_7(
2853                           p_target_ledger_id => p_target_ledger_id
2854                         , p_language         => l_language
2855                         , p_sla_ledger_id    => l_sla_ledger_id
2856                         , p_pad_start_date   => p_pad_start_date
2857                         , p_pad_end_date     => p_pad_end_date
2858                           );
2859 
2860      END IF;
2861 
2862 
2863  --
2864  -- Bug 4865292
2865  -- When the number of events and that of header extract do not match,
2866  -- set the no header extract flag to indicate there are some issues
2867  -- in header extract.
2868  --
2869  -- Event count context is set in xla_accounting_pkg.unit_processor.
2870  -- Build_Message for this error is called in xla_accounting_pkg.post_accounting
2871  -- to report it as a general error.
2872  --
2873  IF  xla_context_pkg.get_event_count_context <> g_hdr_extract_count
2874  AND xla_context_pkg.get_event_nohdr_context <> 'Y' THEN
2875 
2876      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2877         trace
2878           (p_msg      => '# of extracted headers and events does not match'
2879           ,p_level    => C_LEVEL_STATEMENT
2880           ,p_module   => l_log_module);
2881 
2882         trace
2883           (p_msg      => '# of extracted headers: '
2884                          ||g_hdr_extract_count
2885           ,p_level    => C_LEVEL_STATEMENT
2886           ,p_module   => l_log_module);
2887 
2888         trace
2889           (p_msg      => '# of events in xla_events_gt: '
2890                          ||xla_context_pkg.get_event_count_context
2891           ,p_level    => C_LEVEL_STATEMENT
2892           ,p_module   => l_log_module);
2893 
2894         trace
2895           (p_msg      => 'Event No Header Extract Context: '
2896                          ||xla_context_pkg.get_event_nohdr_context
2897           ,p_level    => C_LEVEL_STATEMENT
2898           ,p_module   => l_log_module);
2899 
2900      END IF;
2901 
2902 
2903      xla_context_pkg.set_event_nohdr_context
2904        (p_nohdr_extract_flag => 'Y'
2905        ,p_client_id => sys_context('USERENV','CLIENT_IDENTIFIER'));
2906 
2907      IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2908         trace
2909           (p_msg      => 'No Header Extract Flag is set to Y'
2910           ,p_level    => C_LEVEL_STATEMENT
2911           ,p_module   => l_log_module);
2912      END IF;
2913 
2914  END IF;
2915 
2916 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2917    trace
2918       (p_msg      => 'END of CreateHeadersAndLines'
2919       ,p_level    => C_LEVEL_PROCEDURE
2920       ,p_module   => l_log_module);
2921 END IF;
2922 
2923 RETURN l_created;
2924 EXCEPTION
2925 WHEN xla_exceptions_pkg.application_exception THEN
2926    RAISE;
2927 WHEN OTHERS THEN
2928    xla_exceptions_pkg.raise_message
2929       (p_location => 'XLA_00801_AAD_S_000003_PKG.CreateHeadersAndLines');
2930 END CreateHeadersAndLines;
2931 --
2932 --
2933 
2934 --
2935 --+============================================+
2936 --|                                            |
2937 --|  PUBLIC FUNCTION                           |
2938 --|                                            |
2939 --+============================================+
2940 --
2941 FUNCTION CreateJournalEntries
2942        (p_application_id         IN NUMBER
2943        ,p_base_ledger_id         IN NUMBER
2944        ,p_pad_start_date         IN DATE
2945        ,p_pad_end_date           IN DATE
2946        ,p_primary_ledger_id      IN NUMBER)
2947 RETURN NUMBER IS
2948 l_log_module                   VARCHAR2(240);
2949 l_array_ledgers                xla_accounting_cache_pkg.t_array_ledger_id;
2950 l_temp_result                  BOOLEAN;
2951 l_result                       NUMBER;
2952 BEGIN
2953 --
2954 IF g_log_enabled THEN
2955    l_log_module := C_DEFAULT_MODULE||'.CreateJournalEntries';
2956 END IF;
2957 --
2958 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
2959    trace
2960       (p_msg      => 'BEGIN of CreateJournalEntries'||
2961                      ' - p_base_ledger_id = '||TO_CHAR(p_base_ledger_id)
2962       ,p_level    => C_LEVEL_PROCEDURE
2963       ,p_module   => l_log_module);
2964 
2965 END IF;
2966 
2967 --
2968 g_diagnostics_mode:= xla_accounting_engine_pkg.g_diagnostics_mode;
2969 
2970 IF (C_LEVEL_STATEMENT >= g_log_level) THEN
2971    trace
2975 END IF;
2972       (p_msg      => 'g_diagnostics_mode = '||g_diagnostics_mode
2973       ,p_level    => C_LEVEL_STATEMENT
2974       ,p_module   => l_log_module);
2976 --
2977 xla_ae_journal_entry_pkg.SetProductAcctDefinition
2978    (p_product_rule_code      => 'PAYROLL COSTS'
2979    ,p_product_rule_type_code => 'S'
2980    ,p_product_rule_version   => '1'
2981    ,p_product_rule_name      => 'Payroll Costs'
2982    ,p_amb_context_code       => 'DEFAULT'
2983    );
2984 
2985 l_array_ledgers :=
2986    xla_ae_journal_entry_pkg.GetAlternateCurrencyLedger
2987       (p_base_ledger_id  => p_base_ledger_id);
2988 
2989 FOR Idx IN 1 .. l_array_ledgers.COUNT LOOP
2990    l_temp_result :=
2991       XLA_AE_JOURNAL_ENTRY_PKG.GetLedgersInfo
2992          (p_application_id           => p_application_id
2993          ,p_base_ledger_id           => p_base_ledger_id
2994          ,p_target_ledger_id         => l_array_ledgers(Idx)
2995          ,p_primary_ledger_id        => p_primary_ledger_id
2996          ,p_pad_start_date           => p_pad_start_date
2997          ,p_pad_end_date             => p_pad_end_date);
2998 
2999    l_temp_result :=
3000       l_temp_result AND
3001       CreateHeadersAndLines
3002          (p_application_id             => p_application_id
3003          ,p_base_ledger_id             => p_base_ledger_id
3004          ,p_target_ledger_id           => l_array_ledgers(Idx)
3005          ,p_pad_start_date             => p_pad_start_date
3006          ,p_pad_end_date               => p_pad_end_date
3007          ,p_primary_ledger_id          => p_primary_ledger_id
3008          );
3009 END LOOP;
3010 
3011 
3012 IF (g_diagnostics_mode = 'Y' AND
3013     C_LEVEL_UNEXPECTED >= g_log_level AND
3014     xla_environment_pkg.g_Req_Id IS NOT NULL ) THEN
3015 
3016    xla_accounting_dump_pkg.acctg_event_extract_log(
3017     p_application_id  => p_application_id
3018     ,p_request_id     => xla_environment_pkg.g_Req_Id
3019    );
3020 
3021 END IF;
3022 
3023 CASE l_temp_result
3024   WHEN TRUE THEN l_result := 0;
3025   ELSE l_result := 2;
3026 END CASE;
3027 
3028 IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3029    trace
3030       (p_msg      => 'return value. = '||TO_CHAR(l_result)
3031       ,p_level    => C_LEVEL_PROCEDURE
3032       ,p_module   => l_log_module);
3033    trace
3034       (p_msg      => 'END of CreateJournalEntries '
3035       ,p_level    => C_LEVEL_PROCEDURE
3036       ,p_module   => l_log_module);
3037 END IF;
3038 
3039 RETURN l_result;
3040 EXCEPTION
3041 WHEN xla_exceptions_pkg.application_exception THEN
3042    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3043    trace
3044       (p_msg      => 'ERROR. = '||sqlerrm
3045       ,p_level    => C_LEVEL_PROCEDURE
3046       ,p_module   => l_log_module);
3047    END IF;
3048    RAISE;
3049 WHEN OTHERS THEN
3050    IF (C_LEVEL_PROCEDURE >= g_log_level) THEN
3051    trace
3052       (p_msg      => 'ERROR. = '||sqlerrm
3053       ,p_level    => C_LEVEL_PROCEDURE
3054       ,p_module   => l_log_module);
3055    END IF;
3056    xla_exceptions_pkg.raise_message
3057       (p_location => 'XLA_00801_AAD_S_000003_PKG.CreateJournalEntries');
3058 END CreateJournalEntries;
3059 --
3060 --=============================================================================
3061 --
3062 --
3063 --
3064 --
3065 --
3066 --
3067 --
3068 --
3069 --
3070 --
3071 --
3072 --
3073 --
3074 --
3075 --
3076 --
3077 --
3078 --
3079 --
3080 --
3081 --
3082 --
3083 --=============================================================================
3084 --=============================================================================
3085 --          *********** Initialization routine **********
3086 --=============================================================================
3087 
3088 BEGIN
3089    g_log_level      := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
3090    g_log_enabled    := fnd_log.test
3091                           (log_level  => g_log_level
3092                           ,module     => C_DEFAULT_MODULE);
3093 
3094    IF NOT g_log_enabled  THEN
3095       g_log_level := C_LEVEL_LOG_DISABLED;
3096    END IF;
3097 --
3098 END XLA_00801_AAD_S_000003_PKG;
3099 --