DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQP_GB_PSI_FUNCTIONS

Source


1 PACKAGE BODY PQP_GB_PSI_FUNCTIONS AS
2 --  /* $Header: pqpgbpsifunc.pkb 120.18.12010000.15 2008/09/01 13:12:06 jvaradra ship $ */
3 
4 --
5 --
6 -- Exceptions
7 hr_application_error exception;
8 pragma exception_init (hr_application_error, -20001);
9 
10 
11 g_sth_single VARCHAR2(10);  -- For Bug 7010282
12 
13 
14 FUNCTION get_time
15 RETURN NUMBER
16 IS
17 
18   t NUMBER;
19 
20  BEGIN
21 
22    SELECT TO_CHAR(SYSDATE,'SSSSS') INTO t FROM dual;
23 
24    return t;
25 
26 END get_time;
27 
28 
29 -- ----------------------------------------------------------------------------
30 -- |--------------------------------< check_debug >---------------------------------|
31 -- ----------------------------------------------------------------------------
32 
33 FUNCTION check_debug
34     (p_business_group_id IN     VARCHAR2 -- context
35  )
36 RETURN boolean
37 IS
38 
39  l_proc_name           VARCHAR2(61):=
40   g_proc_name||'check_debug';
41 
42  l_config_value        pqp_utilities.t_config_values;
43  l_return              VARCHAR2(20);
44  l_debug_enable_mode   fnd_concurrent_requests.argument3%type;
45  l_process_parameters  csr_debug_enable_mode%rowtype;
46  l_parent_process_parameters  csr_debug_enable_mode%rowtype;
47 
48 --
49 BEGIN
50 
51 --
52 
53   IF g_debug_flag IS NULL
54   THEN
55   --
56     OPEN csr_debug_enable_mode;
57     FETCH csr_debug_enable_mode INTO l_process_parameters;
58 
59       IF csr_debug_enable_mode%NOTFOUND
60       THEN
61 
62         OPEN csr_debug_enable_mode_parent;
63         FETCH csr_debug_enable_mode_parent INTO l_parent_process_parameters;
64           IF csr_debug_enable_mode_parent%NOTFOUND
65           THEN
66 
67             g_debug := FALSE;
68           ELSE
69             IF l_parent_process_parameters.argument3 = '3DBG'
70             THEN
71 
72               g_debug := TRUE;
73               g_debug_flag := 'Y';
74 
75             ELSE
76 
77               g_debug := FALSE;
78               g_debug_flag := 'N';
79             END IF;
80           END IF;
81         CLOSE csr_debug_enable_mode_parent;
82 
83       ELSE -- IF csr_debug_enable_mode%NOTFOUND
84         IF l_process_parameters.argument3 = '3DBG'
85         THEN
86           g_debug := TRUE;
87           g_debug_flag := 'Y';
88 
89         ELSE
90           g_debug := FALSE;
91           g_debug_flag := 'N';
92 
93         END IF;
94         -- also, save the params for future use
95         g_extract_type := l_process_parameters.argument5;
96         g_dfn_name     := l_process_parameters.argument6;
97 
98       END IF;
99     CLOSE csr_debug_enable_mode;
100 
101     IF g_debug = TRUE THEN
102       -- fetch configuration value for paypoint
103       -- debug('Fetching configuration value for debug flag  ...', 20);
104       pqp_utilities.get_config_type_values
105            ( p_configuration_type   => 'PQP_GB_PENSERVER_DEFINITION'
106             ,p_business_group_id    => p_business_group_id
107             ,p_legislation_code     => NULL
108             ,p_tab_config_values    => l_config_value
109            );
110 
111       IF l_config_value.COUNT > 0 -- config value found
112       THEN
113         g_debug_flag := l_config_value(l_config_value.FIRST).pcv_information1;
114         --
115         IF g_debug_flag = 'Y' THEN
116           g_debug :=  TRUE;
117         ELSE
118           g_debug :=  FALSE;
119         END IF;
120         --
121       ELSE
122         g_debug_flag := 'N';
123         g_debug :=  FALSE;
124       END IF;
125     END IF;
126   --
127   END IF;
128 
129   return g_debug;
130 
131 END check_debug;
132 
133 
134 -- ----------------------------------------------------------------------------
135 -- |--------------------------------< debug >---------------------------------|
136 -- ----------------------------------------------------------------------------
137 
138    PROCEDURE DEBUG (p_trace_message IN VARCHAR2, p_trace_location IN NUMBER)
139    IS
140 
141 --
142    BEGIN
143       --
144 
145       pqp_utilities.DEBUG (
146          p_trace_message               => p_trace_message
147         ,p_trace_location              => p_trace_location
148       );
149    --
150    END DEBUG;
151 
152 
153 -- This procedure is used for debug purposes
154     -- debug_enter checks the debug flag and sets the trace on/off
155     --
156     -- ----------------------------------------------------------------------------
157     -- |----------------------------< debug_enter >-------------------------------|
158     -- ----------------------------------------------------------------------------
159 
160        PROCEDURE debug_enter (p_proc_name IN VARCHAR2, p_trace_on IN VARCHAR2)
161        IS
162        BEGIN
163           --
164           IF g_debug THEN
165             IF pqp_utilities.g_nested_level = 0 THEN
166               hr_utility.trace_on(NULL, 'REQID'); -- Pipe name REQIDnnnnn
167             END IF;
168             pqp_utilities.debug_enter (
169               p_proc_name                   => p_proc_name
170              ,p_trace_on                    => p_trace_on
171            );
172           END IF;
173           --
174 
175        END debug_enter;
176 
177 
178     -- This procedure is used for debug purposes
179     --
180     -- ----------------------------------------------------------------------------
181     -- |----------------------------< debug_exit >--------------------------------|
182     -- ----------------------------------------------------------------------------
183 
184        PROCEDURE debug_exit (p_proc_name IN VARCHAR2, p_trace_off IN VARCHAR2)
185        IS
186        BEGIN
187           --
188           IF g_debug THEN
189             pqp_utilities.debug_exit (
190               p_proc_name                   => p_proc_name
191              ,p_trace_off                    => p_trace_off
192            );
193 
194            IF pqp_utilities.g_nested_level = 0 THEN
195               hr_utility.trace_off;
196            END IF;
197           END IF;
198           --
199        END debug_exit;
200 
201 
202 -- This procedure is used for debug purposes
203 --
204 -- ----------------------------------------------------------------------------
205 -- |----------------------------< debug_others >------------------------------|
206 -- ----------------------------------------------------------------------------
207 
208    PROCEDURE debug_others (p_proc_name IN VARCHAR2, p_proc_step IN NUMBER)
209    IS
210    BEGIN
211       --
212       pqp_utilities.debug_others (
213          p_proc_name                   => p_proc_name
214         ,p_proc_step                   => p_proc_step
215       );
216    --
217    END debug_others;
218 
219 
220 -- ----------------------------------------------------------------------------
221 -- |------------------------< GET_CURRENT_EXTRACT_PERSON >---------------------|
222 -- ----------------------------------------------------------------------------
223 
224 --  GET_CURRENT_EXTRACT_PERSON
225 --
226 --    Returns the ext_rslt_id for the current extract process
227 --    if one is running, else returns -1
228 --
229   FUNCTION get_current_extract_person
230     (p_assignment_id NUMBER  -- context
231     )
232   RETURN NUMBER
233   IS
234     l_person_id  NUMBER;
235   BEGIN
236     SELECT person_id
237     INTO   l_person_id
238     FROM   per_all_assignments_f
239     WHERE  assignment_id = p_assignment_id
240       AND  ROWNUM < 2;
241     RETURN l_person_id;
242   EXCEPTION
243     WHEN NO_DATA_FOUND THEN
244       RETURN NULL;
245   END;
246 --
247 
248 -- ----------------------------------------------------------------------------
249 -- |------------------------< GET_CURRENT_EXTRACT_RESULT >-----------------------|
250 -- ----------------------------------------------------------------------------
251 
252 --
253 --  GET_CURRENT_EXTRACT_RESULT
254 --
255 --    Returns the person id associated with the given assignment.
256 --    If none is found,it returns NULL. This may arise if the
257 --    user calls this from a header/trailer record, where
258 --    a dummy context of assignment_id = -1 is passed.
259 --
260 --
261   FUNCTION get_current_extract_result
262     RETURN NUMBER
263   IS
264      e_extract_process_not_running EXCEPTION;
265      PRAGMA EXCEPTION_INIT(e_extract_process_not_running,-8002);
266      l_ext_rslt_id  NUMBER;
267   --
268   BEGIN
269   --
270 --    SELECT ben_ext_rslt_s.CURRVAL
271 --    INTO   l_ext_rslt_id
272 --    FROM   DUAL;
273 
274     l_ext_rslt_id := ben_ext_thread.g_ext_rslt_id;
275 
276     RETURN l_ext_rslt_id;
277   --
278   EXCEPTION
279     WHEN e_extract_process_not_running THEN
280       RETURN -1;
281   END;
282 
283 
284 
285 -- ----------------------------------------------------------------------------
286 -- |---------------------------< is_alphanumeric >--------------------|
287 -- ----------------------------------------------------------------------------
288 function is_alphanumeric
289   (p_string                in varchar2
290   ) Return Boolean is
291 --
292   l_proc_name   varchar2(72) := g_proc_name||'is_alphanumeric';
293 
294 begin
295 --
296   debug_enter(l_proc_name);
297 
298   IF
299     TRIM(TRANSLATE(p_string,'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '
300     ,'                                                              _'))
301   IS NULL
302 
303   THEN
304     debug('true');
305     debug_exit(l_proc_name);
306     return true;
307   ELSE
308     debug('false');
309     debug_exit(l_proc_name);
310     return false;
311   END IF;
312   EXCEPTION
313     WHEN others THEN
314         IF SQLCODE <> hr_utility.hr_error_number
315         THEN
316             debug_others (l_proc_name, 10);
317             IF g_debug
318             THEN
319               DEBUG (   'Leaving: '
320                      || l_proc_name, -999);
321              END IF;
322              fnd_message.raise_error;
323          ELSE
324              RAISE;
325          END IF;
326 
327   --
328 end is_alphanumeric;
329 
330 -- ----------------------------------------------------------------------------
331 -- |---------------------------< is_alphanumeric_space_allowed >--------------------|
332 -- ----------------------------------------------------------------------------
333 function is_alphanumeric_space_allowed
334   (p_string                in varchar2
335   ) Return Boolean is
336 --
337   l_proc_name   varchar2(72) := g_proc_name||'is_alphanumeric';
338 
339 begin
340 --
341   debug_enter(l_proc_name);
342 
343   IF
344     TRIM(TRANSLATE(p_string,'0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '
345     ,'                                                               '))
346   IS NULL
347 
348   THEN
349     debug('true');
350     debug_exit(l_proc_name);
351     return true;
352   ELSE
353     debug('false');
354     debug_exit(l_proc_name);
355     return false;
356   END IF;
357   EXCEPTION
358     WHEN others THEN
359         IF SQLCODE <> hr_utility.hr_error_number
360         THEN
361             debug_others (l_proc_name, 10);
362             IF g_debug
363             THEN
364               DEBUG (   'Leaving: '
365                      || l_proc_name, -999);
366              END IF;
367              fnd_message.raise_error;
368          ELSE
369              RAISE;
370          END IF;
371 
372   --
373 end is_alphanumeric_space_allowed;
374 -- ----------------------------------------------------------------------------
375 -- |---------------------------< is_numeric >--------------------|
376 -- ----------------------------------------------------------------------------
377 function is_numeric
378   (p_string                in varchar2
379   ) Return Boolean is
380 --
381   l_proc_name   varchar2(72) := g_proc_name||'is_numeric';
382 
383 begin
384 --
385   debug_enter(l_proc_name);
386 
387   IF
388     TRIM(TRANSLATE(p_string,'0123456789'
389     ,'          '))
390   IS NULL
391 
392   THEN
393     debug('true');
394     debug_exit(l_proc_name);
395     return true;
396   ELSE
397     debug('false');
398     debug_exit(l_proc_name);
399     return false;
400   END IF;
401   EXCEPTION
402     WHEN others THEN
403         IF SQLCODE <> hr_utility.hr_error_number
404         THEN
405             debug_others (l_proc_name, 10);
406             IF g_debug
407             THEN
408               DEBUG (   'Leaving: '
409                      || l_proc_name, -999);
410              END IF;
411              fnd_message.raise_error;
412          ELSE
413              RAISE;
414          END IF;
415 
416   --
417 end is_numeric;
418 
419 
420 
421 -- =============================================================================
422 -- This procedure gets the bonus codes information from pay_element_type_extra_info
423 -- if bonus code is alphanumeric then information is passed to the output file
424 -- else to the log file
425 -- =============================================================================
426   PROCEDURE get_bonus_codes
427                           (p_business_group_id IN VARCHAR2
428                                       ,p_from_date         IN DATE
429                                   ,p_to_date           IN DATE) IS
430 
431   l_column_separator       VARCHAR2(10) := ' , ';
432   l_pay_point              VARCHAR2(10);
433   l_filler1                CHAR(16):=' ';
434   l_filler2                CHAR(86):=' ';
435   l_bonus_codes            t_bonus_codes;
436   l_bonus_index            NUMBER:=0;
437   l_alphanum_code          VARCHAR2(200);
438   l_proc_name              VARCHAR2(200):= g_proc_name || 'get_bonus_codes';
439 
440   BEGIN
441 
442   debug_enter(l_proc_name);
443 
444   -- get paypoint value for business group id passed
445   l_pay_point := paypoint(p_business_group_id);
446 
447     debug ('l_pay_point:'||l_pay_point);
448 
449 
450     IF l_pay_point = ''
451        or
452        NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> l_pay_point)
453     THEN
454       -- Raise error as Paypoint is unknown(E)
455       hr_utility.set_message(805, 'BEN_94453_INV_PAYPOINT');
456       fnd_file.put_line(fnd_file.LOG
457                           , RPAD('Error', 30) || ': ' || hr_utility.get_message);
458       fnd_file.put_line(fnd_file.LOG, ' ');
459     END IF;
460 
461 
462   -- Pass context as PQP_GB_PENSERV_BONUS_INFO to get the bonus codes information
463   FOR  l_bonus_rec IN csr_get_extra_bonus_info
464                         (p_from_date         => p_from_date
465                                     ,p_to_date           => p_to_date)
466   LOOP
467 
468      debug ('l_bonus_rec.code:'||l_bonus_rec.code);
469      -- set error code to null
470      l_alphanum_code := NULL;
471 
472      IF l_bonus_rec.code IS NULL THEN
473        l_alphanum_code := 'NULL';
474      ELSIF NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> l_bonus_rec.code) THEN
475        -- raise error against this element/code
476        l_alphanum_code := l_bonus_rec.code;
477      END IF;
478 
479      IF l_alphanum_code IS NOT NULL THEN
480        --
481              fnd_file.put_line(fnd_file.LOG,
482                                 RPAD(nvl(l_pay_point,' '),6,' ') ||
483                                 RPAD(nvl(l_bonus_rec.code,' '),4,' ') ||
484                                 RPAD(nvl(l_bonus_rec.description,' '),34,' ') ||
485                                 RPAD(nvl(l_bonus_rec.pension_flag,' '),1,' ') ||
486                                 RPAD(nvl(l_bonus_rec.industrial_flag,' '),1,' ') ||
487                                 RPAD(l_filler1,16,' ') ||
488                                 RPAD(nvl(l_bonus_rec.basic_pay_reckonable,' '),1,' ') ||
489                                 RPAD(nvl(l_bonus_rec.pre_75_reckonable,' '),1,' ') ||
490                                 RPAD(l_filler2,86,' '));
491        --
492           -- Raise error as Special characters are not permitted in the allowance code(E)
493           hr_utility.set_message(805, 'BEN_94458_PEN_SPCL_CHAR_CHK');
494           fnd_file.put_line(fnd_file.LOG
495                                , RPAD('Error', 30) || ': ' || hr_utility.get_message);
496 
497           fnd_file.put_line(fnd_file.log, 'INTERFACE : Bonus');
498 
499           fnd_file.put_line(fnd_file.log, 'ELEMENT : '||  l_bonus_rec.element_name);
500 
501           fnd_file.put_line(fnd_file.log, 'BONUS CODE : '||  l_alphanum_code);
502           fnd_file.put_line(fnd_file.log, ' ');
503           fnd_file.put_line(fnd_file.log, ' ');
504        --
505 
506      --
507      ELSE
508      --
509        -- increase the counter
510        l_bonus_index := l_bonus_index +1;
511        l_bonus_codes(l_bonus_index).pay_point            :=RPAD(nvl(l_pay_point,' '),6,' ');
512        l_bonus_codes(l_bonus_index).bonus_code           :=RPAD(nvl(l_bonus_rec.code,' '),4,' ');
513        l_bonus_codes(l_bonus_index).bonus_descr          :=RPAD(nvl(l_bonus_rec.description,' '),34,' ');
514        l_bonus_codes(l_bonus_index).pension_flag         :=RPAD(nvl(l_bonus_rec.pension_flag,' '),1,' ');
515        l_bonus_codes(l_bonus_index).industrial_flag      :=RPAD(nvl(l_bonus_rec.industrial_flag,' '),1,' ');
516        l_bonus_codes(l_bonus_index).filler1              :=RPAD(l_filler1,16,' ');
517        l_bonus_codes(l_bonus_index).basic_pay_reckonable :=RPAD(nvl(l_bonus_rec.basic_pay_reckonable,' '),1,' ');
518        l_bonus_codes(l_bonus_index).pre_75_reckonable    :=RPAD(nvl(l_bonus_rec.pre_75_reckonable,' '),1,' ');
519        l_bonus_codes(l_bonus_index).filler2              :=RPAD(l_filler2,86,' ');
520      --
521      END IF;
522 
523   END LOOP;
524 
525   IF l_bonus_codes.COUNT > 0
526   THEN
527     -- insert correct bonus information into output file
528     FOR l_bonus_index IN l_bonus_codes.FIRST..l_bonus_codes.LAST
529     LOOP
530 
531            fnd_file.put_line(fnd_file.output,
532                              l_bonus_codes(l_bonus_index).pay_point ||
533                              l_bonus_codes(l_bonus_index).bonus_code ||
534                              l_bonus_codes(l_bonus_index).bonus_descr ||
535                              l_bonus_codes(l_bonus_index).pension_flag ||
536                              l_bonus_codes(l_bonus_index).industrial_flag ||
537                              l_bonus_codes(l_bonus_index).filler1 ||
538                              l_bonus_codes(l_bonus_index).basic_pay_reckonable ||
539                              l_bonus_codes(l_bonus_index).pre_75_reckonable ||
540                              l_bonus_codes(l_bonus_index).filler2 );
541 
542     END LOOP;
543   END IF;
544 
545   debug_exit(l_proc_name);
546 
547  EXCEPTION
548       WHEN OTHERS  THEN
549        debug_exit(' Error  in '||l_proc_name);
550            RAISE;
551 
552  END get_bonus_codes;
553 
554 -- =============================================================================
555 -- This procedure gets allowance code information from pay_element_type_extra_info
556 -- if allowance code is alphanumeric then information is passed to the output file
557 -- else to the log file.
558 -- =============================================================================
559  PROCEDURE get_allowance_codes
560            (p_business_group_id IN VARCHAR2
561                        ,p_from_date         IN DATE
562                    ,p_to_date           IN DATE) IS
563 
564   l_column_separator          VARCHAR2(10) := ' , ';
565   l_pay_point                 VARCHAR2(10);
566   l_filler1                   CHAR(16)     :=' ';
567   l_filler2                   CHAR(79)     :=' ';
568   l_allowance_codes           t_allowance_codes;
569   l_allowance_index           NUMBER       :=0;
570   l_alphanum_code             VARCHAR2(200);
571   l_proc_name                 VARCHAR2(200):= g_proc_name || 'get_allowance_codes';
572 
573   BEGIN
574 
575     debug_enter(l_proc_name);
576     debug('Entering get_allowance_codes');
577 
578   -- get paypoint value for business group id passed
579   l_pay_point := paypoint(p_business_group_id);
580   debug ('l_pay_point:'||l_pay_point);
581 
582     IF l_pay_point = ''
583        or
584        NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> l_pay_point)
585     THEN
586        -- Raise error as Paypoint is unknown(E)
587        hr_utility.set_message(805, 'BEN_94453_INV_PAYPOINT');
588        fnd_file.put_line(fnd_file.LOG
589                           , RPAD('Error', 30) || ': ' || hr_utility.get_message);
590        fnd_file.put_line(fnd_file.LOG, ' ');
591     END IF;
592   --Pass context as PQP_GB_PENSERV_ALLOWANCE_INFO to get the allowance codes information
593   FOR  l_allowance_rec IN csr_get_extra_allow_info
594                         (p_from_date         => p_from_date
595                                     ,p_to_date           => p_to_date)
596   LOOP
597 
598        debug ('l_allowance_rec.code:'||l_allowance_rec.code);
599        -- set error code to null
600        l_alphanum_code := NULL;
601 
602        IF l_allowance_rec.code IS NULL THEN
603          l_alphanum_code := 'NULL';
604        ELSIF NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> l_allowance_rec.code) THEN
605          -- raise error against this element/code
606          l_alphanum_code := l_allowance_rec.code;
607        END IF;
608 
609        IF l_alphanum_code IS NOT NULL THEN
610        --
611              fnd_file.put_line(fnd_file.LOG,
612                                 RPAD(nvl(l_pay_point,' '),6,' ') ||
613                                 RPAD(nvl(l_allowance_rec.code,' '),10,' ') ||
614                                 RPAD(nvl(l_allowance_rec.description,' '),34,' ') ||
615                                 RPAD(nvl(l_allowance_rec.pension_flag,' '),1,' ') ||
616                                 RPAD(nvl(l_allowance_rec.industrial_flag,' '),1,' ') ||
617                                 RPAD(nvl(l_allowance_rec.spread_bonus_flag,' '),1,' ') ||
618                                 RPAD(l_filler1,16,' ') ||
619                                 RPAD(nvl(l_allowance_rec.basic_pay_reckonable,' '),1,' ') ||
620                                 RPAD(nvl(l_allowance_rec.pre_75_reckonable,' '),1,' ') ||
621                                 RPAD(l_filler2,79,' '));
622        --
623           -- Raise error as Special characters are not permitted in the allowance code(E)
624           hr_utility.set_message(805, 'BEN_94458_PEN_SPCL_CHAR_CHK');
625           fnd_file.put_line(fnd_file.LOG
626                                , RPAD('Error', 30) || ': ' || hr_utility.get_message);
627 
628           fnd_file.put_line(fnd_file.log, 'INTERFACE : Allowance');
629 
630           fnd_file.put_line(fnd_file.log, 'ELEMENT : '||  l_allowance_rec.element_name);
631 
632           fnd_file.put_line(fnd_file.log, 'ALLOWANCE CODE : '||  l_alphanum_code);
633           fnd_file.put_line(fnd_file.log, ' ');
634           fnd_file.put_line(fnd_file.log, ' ');
635        --
636        ELSE
637        --
638          -- increase the counter
639          l_allowance_index := l_allowance_index + 1;
640          l_allowance_codes(l_allowance_index).pay_point           :=RPAD(nvl(l_pay_point,' '),6,' ');
641          l_allowance_codes(l_allowance_index).allowance_code      :=RPAD(nvl(l_allowance_rec.code,' '),10,' ');
642          l_allowance_codes(l_allowance_index).allowance_descr     :=RPAD(nvl(l_allowance_rec.description,' '),34,' ');
643          l_allowance_codes(l_allowance_index).pension_flag        :=RPAD(nvl(l_allowance_rec.pension_flag,' '),1,' ');
644          l_allowance_codes(l_allowance_index).industrial_flag     :=RPAD(nvl(l_allowance_rec.industrial_flag,' '),1,' ');
645          l_allowance_codes(l_allowance_index).spread_bonus_flag   :=RPAD(nvl(l_allowance_rec.spread_bonus_flag,' '),1,' ');
646          l_allowance_codes(l_allowance_index).filler1             :=RPAD(l_filler1,16,' ');
647          l_allowance_codes(l_allowance_index).basic_pay_reckonable:=RPAD(nvl(l_allowance_rec.basic_pay_reckonable,' '),1,' ');
648          l_allowance_codes(l_allowance_index).pre_75_reckonable   :=RPAD(nvl(l_allowance_rec.pre_75_reckonable,' '),1,' ');
649          l_allowance_codes(l_allowance_index).filler2             :=RPAD(l_filler2,79,' ');
650        --
651        END IF;
652 
653   END LOOP;
654   debug ('Before writing into file');
655 
656   IF l_allowance_codes.COUNT > 0
657   THEN
658     -- insert correct allowance information into output file
659     FOR l_allowance_index IN l_allowance_codes.FIRST..l_allowance_codes.LAST
660     LOOP
661 
662          fnd_file.put_line(fnd_file.output,
663                            l_allowance_codes(l_allowance_index).pay_point ||
664                            l_allowance_codes(l_allowance_index).allowance_code ||
665                            l_allowance_codes(l_allowance_index).allowance_descr ||
666                            l_allowance_codes(l_allowance_index).pension_flag ||
667                            l_allowance_codes(l_allowance_index).industrial_flag ||
668                            l_allowance_codes(l_allowance_index).spread_bonus_flag ||
669                            l_allowance_codes(l_allowance_index).filler1 ||
670                            l_allowance_codes(l_allowance_index).basic_pay_reckonable ||
671                            l_allowance_codes(l_allowance_index).pre_75_reckonable ||
672                            l_allowance_codes(l_allowance_index).filler2 );
673 
674     END LOOP;
675   END IF;
676  debug_exit(l_proc_name);
677 
678  EXCEPTION
679       WHEN OTHERS  THEN
680       debug_exit(' Error  in '||l_proc_name);
681       RAISE;
682  END get_allowance_codes;
683 
684 
685 
686 -- Function returns extract result id for a given request id
687 --
688 -- ----------------------------------------------------------------------------
689 -- |----------------------------< get_ext_rslt_frm_req >----------------------|
690 -- ----------------------------------------------------------------------------
691 
692 FUNCTION get_ext_rslt_frm_req (p_request_id        IN NUMBER
693                               ,p_business_group_id IN NUMBER
694                               )
695   RETURN NUMBER IS
696 --
697   CURSOR csr_get_ext_rslt_id
698   IS
699   SELECT ext_rslt_id
700     FROM ben_ext_rslt
701    WHERE request_id = p_request_id
702      AND business_group_id = p_business_group_id;
703 
704   l_ext_rslt_id  NUMBER;
705   l_proc_name    VARCHAR2 (80) := g_proc_name
706                                  || 'get_ext_rslt_frm_req';
707   l_proc_step    NUMBER;
708 
709 --
710 BEGIN
711   --
712   IF g_debug
713   THEN
714      l_proc_step                := 10;
715      DEBUG (   'Entering: '
716             || l_proc_name, l_proc_step);
717   END IF;
718 
719   OPEN csr_get_ext_rslt_id;
720   FETCH csr_get_ext_rslt_id INTO l_ext_rslt_id;
721 
722   IF csr_get_ext_rslt_id%NOTFOUND THEN
723      fnd_message.set_name ('BEN', 'BEN_91873_EXT_NOT_FOUND');
724      fnd_file.put_line(fnd_file.log, 'Error: '
725                                     || fnd_message.get);
726      fnd_file.put_line(fnd_file.log, ' ');
727      CLOSE csr_get_ext_rslt_id;
728      fnd_message.raise_error;
729   END IF; -- End if of row not found check ...
730   CLOSE csr_get_ext_rslt_id;
731 
732   IF g_debug
733   THEN
734      DEBUG (   'Extract Result ID: '
735             || TO_CHAR(l_ext_rslt_id));
736      l_proc_step                := 20;
737      DEBUG (   'Leaving: '
738             || l_proc_name, l_proc_step);
739   END IF;
740 
741   RETURN l_ext_rslt_id;
742 
743 END get_ext_rslt_frm_req;
744 --
745 
746 
747 
748 -- =============================================================================
749 -- Build_Metadata_Ext_Names
750 -- =============================================================================
751 
752 PROCEDURE Build_Metadata_Ext_Names  IS
753   l_proc_name    VARCHAR2(120):=  g_proc_name||'Build_Metadata_Ext_Names';
754 BEGIN
755   debug_enter(l_proc_name);
756 
757 /*
758 1  BASIC DATA              -- DONE
759 2  ADDRESS                 -- DONE
760 3  SERVICE HISTORY         -- DONE
761 4  PART-TIME HOURS HISTORY
762 5  SHORT-TIME HOURS HISTORY - Single Records
763 6  SHORT-TIME HOURS HISTORY - Accumulated Records
764 7  SALARY HISTORY          -- DONE
765 8  ALLOWANCE HISTORY
766 9  BONUS HISTORY
767 10 EARNINGS HISTORY        -- DONE
768 11 WPS CONTRIBUTION RATE HISTORY
769 */
770 
771   ---define Penserver Cutover extract names and codes
772   g_cutover_ext_names(1).extract_name       :='PQP GB PenServer Cutover Interface - Basic Data';
773   g_cutover_ext_names(1).extract_code       :='BDI';
774   g_cutover_ext_names(2).extract_name       :='PQP GB PenServer Cutover Interface - Address';
775   g_cutover_ext_names(2).extract_code       :='ADI';
776   g_cutover_ext_names(3).extract_name       :='PQP GB PenServer Cutover Interface - Service History';
777   g_cutover_ext_names(3).extract_code       :='SVI';
778   g_cutover_ext_names(4).extract_name       :='PQP GB PenServer Cutover Interface - Part Time Hours History';
779   g_cutover_ext_names(4).extract_code       :='PTH';
780   g_cutover_ext_names(5).extract_name       :=' ';
781   g_cutover_ext_names(5).extract_code       :=' ';
782   g_cutover_ext_names(6).extract_name       :=' ';
783   g_cutover_ext_names(6).extract_code       :=' ';
784   g_cutover_ext_names(7).extract_name       :='PQP GB PenServer Cutover Interface - Salary History';
785   g_cutover_ext_names(7).extract_code       :='SDI';
786   g_cutover_ext_names(8).extract_name       :='PQP GB PenServer Cutover Interface - Allowance History';
787   g_cutover_ext_names(8).extract_code       :='AHI';
788   g_cutover_ext_names(9).extract_name       :='PQP GB PenServer Cutover Interface - Bonus History';
789   g_cutover_ext_names(9).extract_code       :='BHI';
790   g_cutover_ext_names(10).extract_name      :='PQP GB PenServer Standard Interface - Earnings History';
791   g_cutover_ext_names(10).extract_code      :='EDI';
792   g_cutover_ext_names(11).extract_name      :='PQP GB PenServer Cutover Interface - WPS History';
793   g_cutover_ext_names(11).extract_code      :='WPS';
794 
795 
796   ---define Penserver Periodic extract names and codes
797   g_periodic_ext_names(1).extract_name       :='PQP GB PenServer Periodic Changes Interface - Basic Data';
798   g_periodic_ext_names(1).extract_code       :='BDI';
799   g_periodic_ext_names(2).extract_name       :='PQP GB PenServer Periodic Changes Interface - Address';
800   g_periodic_ext_names(2).extract_code       :='ADI';
801   g_periodic_ext_names(3).extract_name       :='PQP GB PenServer Periodic Changes Interface - Service History';
802   g_periodic_ext_names(3).extract_code       :='SVI';
803   g_periodic_ext_names(4).extract_name       :='PQP GB PenServer Periodic Changes Interface - Part Time Hours History';
804   g_periodic_ext_names(4).extract_code       :='PTH';
805   -- For Bug 7010282
806   IF g_sth_single = 'EXCLUDE'
807   THEN
808      g_periodic_ext_names(5).extract_name       :=' ';
809      g_periodic_ext_names(5).extract_code       :=' ';
810   ELSE
811      g_periodic_ext_names(5).extract_name       :='PQP GB PenServer Periodic Changes Interface - Short Time Hours History (Single Records)';
812      g_periodic_ext_names(5).extract_code       :='STS';
813   END IF;
814   g_periodic_ext_names(6).extract_name       :='PQP GB PenServer Periodic Changes Interface - Short Time Hours History (Accumulated Records)';
815   g_periodic_ext_names(6).extract_code       :='STA';
816   g_periodic_ext_names(7).extract_name       :='PQP GB PenServer Periodic Changes Interface - Salary History';
817   g_periodic_ext_names(7).extract_code       :='SDI';
818   g_periodic_ext_names(8).extract_name       :='PQP GB PenServer Periodic Changes Interface - Allowance History';
819   g_periodic_ext_names(8).extract_code       :='AHI';
820   g_periodic_ext_names(9).extract_name       :='PQP GB PenServer Periodic Changes Interface - Bonus History';
821   g_periodic_ext_names(9).extract_code       :='BHI';
822   g_periodic_ext_names(10).extract_name      :='PQP GB PenServer Standard Interface - Earnings History';
823   g_periodic_ext_names(10).extract_code      :='EDI';
824   g_periodic_ext_names(11).extract_name      :='PQP GB PenServer Periodic Interface - WPS History';
825   g_periodic_ext_names(11).extract_code      :='WPS';
826 
827 
828   ---define Penserver Codes extract names
829   g_code_ext_names(1).extract_name   :='PQP GB PenServer Standard Interface - Grade Codes';
830   g_code_ext_names(1).extract_code   :='GCI';
831   g_code_ext_names(2).extract_name   :='PQP GB PenServer Standard Interface - Location Codes';
832   g_code_ext_names(2).extract_code   :='LCI';
833   g_code_ext_names(3).extract_name   :='PQP GB PenServer Standard Interface- Allowance Codes';
834   g_code_ext_names(3).extract_code   :='ACI';
835   g_code_ext_names(4).extract_name   :='PQP GB PenServer Standard Interface- Bonus Codes';
836   g_code_ext_names(4).extract_code   :='BCI';
837 
838 
839   debug_exit(l_proc_name);
840 
841 END  Build_Metadata_Ext_Names;
842 
843 
844 -- =============================================================================
845 -- ~ PQP_Penserver_Extract: This is called by the conc. program
846 -- ~ to run cutover Penserver extracts and is basically a
847 -- ~ wrapper around the benefits conc. program Extract Process.
848 -- =============================================================================
849 
850 PROCEDURE PQP_Penserver_Extract
851            (errbuf                        OUT NOCOPY  VARCHAR2
852            ,retcode                       OUT NOCOPY  VARCHAR2
853            ,p_benefit_action_id           IN     NUMBER
854            ,p_business_group_id           IN     NUMBER
855                ,p_execution_mode              IN     VARCHAR2 -- 1GEN/3DBG/2SET/1REP
856            ,p_execution_mode_type         IN     VARCHAR2
857            ,p_extract_type                IN     VARCHAR2 -- 3CUT/1PED/2CODE
858            ,p_dfn_name                    IN     VARCHAR2 -- 1ALL/BDI/ADI/SDI/EDI/ACI/BCI/GCI/LCI
859            ,p_start_date                  IN     VARCHAR2
860            ,p_eff_date                    IN     VARCHAR2
861            ,p_submit_request_y_n          IN     VARCHAR2 default 'N'
862            ,p_concurrent_request_id       IN     NUMBER DEFAULT NULL
863            ,p_year_end_close              IN     VARCHAR2 default 'N'  -- /* Nuvos Changes */
864            ,p_short_time_hours_single     IN     VARCHAR2 default 'INCLUDE'  -- For Bug 7010282
865            ) IS
866 
867   l_ext_dfn_id        ben_ext_dfn.ext_dfn_id%TYPE;
868   l_proc_name         VARCHAR2(61):=  g_proc_name||'PQP_Penserver_Extract';
869   l_errbuff           VARCHAR2(3000);
870   l_retcode           NUMBER;
871   l_extract_name      ben_ext_dfn.name%TYPE;
872   l_extract_shortname VARCHAR2(80);
873   l_extract_count     NUMBER;
874 
875   l_request_id        fnd_concurrent_requests.request_id%TYPE;
876   l_index             fnd_concurrent_requests.request_id%TYPE;
877 
878   l_wait_success      BOOLEAN := FALSE;
879   l_effective_date    DATE;
880   l_cutover_date      DATE;
881   l_rolling_window_length NUMBER;
882 
883   l_config_value      pqp_utilities.t_config_values;
884 
885   -- Concurrent program
886   l_phase             VARCHAR2(80);
887   l_status            VARCHAR2(80);
888   l_dev_phase         VARCHAR2(80);
889   l_dev_status        VARCHAR2(80);
890   l_message           VARCHAR2(80);
891   l_err_msg           fnd_new_messages.message_text%TYPE;
892   PROGRAM_FAILURE     CONSTANT NUMBER := 2 ;
893   PROGRAM_SUCCESS     CONSTANT NUMBER := 0 ;
894 
895   -- to store extract names and codes
896   l_ext_names          t_ext_dfn_names;
897   l_eff_date           VARCHAR2(40);
898   l_eff_start_date     VARCHAR2(40);
899   l_threads            NUMBER;
900   l_chunk_size         NUMBER;
901   l_max_errors_allowed NUMBER;
902 
903    -- For 115.81
904 
905   l_penserv_mode       VARCHAR2(1);
906 
907 
908 BEGIN
909 
910 --***************************************
911 -- IMP!! -- remove this later
912 -- g_debug := TRUE;
913 --***************************************
914 
915 --    fnd_file.put_line(fnd_file.log, l_proc_name || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
916     fnd_file.put_line(fnd_file.log, l_proc_name || ' : ' || get_time);
917 
918     IF (p_submit_request_y_n = 'N') THEN
919       fnd_file.put_line(fnd_file.log, 'First call to ' || l_proc_name );
920     ELSE
921       fnd_file.put_line(fnd_file.log, 'Second call to ' || l_proc_name );
922     END IF;
923 
924 
925     -- 115.60
926     -- there are cases when some common functions dont get business_group_id
927     -- as a paramater. In such cases, this variable shall be referenced
928     g_business_group_id_backup := p_business_group_id;
929 
930     -- store extract type and name in global
931     g_extract_type := p_extract_type;
932     g_dfn_name     := p_dfn_name;
933     g_sth_single   := p_short_time_hours_single;   -- Bug 7010282
934 
935 
936     --115.87: Bug 7291713
937     /*
938     --115.85
939     g_bas_eff_date := p_eff_date;
940     */
941 
942     -- check for enabling trace
943     IF p_execution_mode = '3DBG'
944     THEN
945       g_debug           :=  pqp_gb_psi_functions.check_debug(p_business_group_id);
946     END IF;
947 
948     debug_enter(l_proc_name);
949     --Maintaining all Penserver extracts in record,so that
950     --if at all there will be any name change ,we can modify only this
951     Build_Metadata_Ext_Names;
952     -- Checking the p_extract_type to decide which extract type to process
953 
954     debug('p_business_group_id :' || p_business_group_id);
955     debug('p_execution_mode :' || p_execution_mode);
956     debug('p_extract_type :' || p_extract_type);
957     debug('p_dfn_name :' || p_dfn_name);
958     debug('p_start_date :' || p_start_date);
959     debug('p_eff_date :' || p_eff_date);
960     debug('p_submit_request_y_n :' || p_submit_request_y_n);
961 
962     --Now set interface name
963     -- BDI/ADI/SDI/EDI
964     -- GCI/LCI/ACI/BCI
965 
966       -- check for 3CUT/1PED/2CODE
967       -- and store in l_ext_names for later use
968       IF p_extract_type = '3CUT' THEN
969         l_ext_names := g_cutover_ext_names;
970       ELSIF p_extract_type = '1PED' THEN
971         l_ext_names := g_periodic_ext_names;
972       ELSE
973         l_ext_names := g_code_ext_names;
974       END IF;
975 
976     -- Added for serial mode run
977     -- in ALL mode and multi-thread
978     benutils.get_parameter
979       (p_business_group_id => p_business_group_id
980       ,p_batch_exe_cd => 'BENXTRCT'
981       ,p_threads => l_threads
982       ,p_chunk_size => l_chunk_size
983       ,p_max_errors => l_max_errors_allowed);
984 
985     -- Check if this is the parent thread call
986     -- if = N => this is parent -> launch child threads for the extracts
987     -- if = Y => this is not parent
988     IF p_submit_request_y_n = 'N' and p_execution_mode <> '2SET' THEN
989 
990       debug('p_submit_request_y_n is N !',20);
991 
992       IF p_dfn_name <> '1ALL' THEN -- single extract submission case
993         -- find the short name of the dfn_code
994         -- this is the meaning of the lookup code
995         l_extract_shortname := HR_GENERAL.DECODE_LOOKUP
996                              (p_lookup_type   =>  'PQP_GB_PENSERVER_INTERFACES'
997                              ,p_lookup_code   =>  p_dfn_name
998                              );
999 
1000         debug('l_extract_shortname :' || l_extract_shortname,30);
1001         -- append cutover/periodic to names
1002         -- codes already have 'code' attached to their name
1003         IF p_extract_type = '3CUT' THEN
1004           l_extract_shortname := l_extract_shortname||' - '||'Cutover';
1005         ELSIF p_extract_type = '1PED' THEN
1006           l_extract_shortname := l_extract_shortname||' - '||'Periodic';
1007         END IF;
1008 
1009         IF p_execution_mode = '1REP' THEN
1010           l_extract_shortname := 'Reprocess'||' - '||l_extract_shortname;
1011         END IF;
1012 
1013         debug('l_extract_shortname (appended) :' || l_extract_shortname,30);
1014 
1015         debug('p_dfn_name != 1ALL !',20);
1016         -- Submit the process again, this time with 'Y'
1017         debug('now launching : '|| l_extract_shortname, 25);
1018 
1019         l_request_id :=
1020                     fnd_request.submit_request
1021                           (application => 'PQP'
1022                           ,program     => 'PQPGBPENSERVER'
1023                           ,description => l_extract_shortname
1024                           ,sub_request => FALSE -- TRUE, still not decide on this one
1025                           ,argument1   => NULL -- benefit_action_id
1026                           ,argument2   => p_business_group_id
1027                           ,argument3   => p_execution_mode
1028                           ,argument4   => p_execution_mode_type
1029                           ,argument5   => p_extract_type
1030                           ,argument6   => p_dfn_name
1031                           ,argument7   => p_start_date
1032                           ,argument8   => p_eff_date
1033                           ,argument9   => 'Y'
1034                           ,argument10   => p_concurrent_request_id
1035                                   ,argument11  => p_year_end_close         -- For Nuvos changes
1036                                       ,argument12  => p_short_time_hours_single  -- -- For Bug 7010282
1037                           );
1038 
1039          -- check for process submit error
1040          IF l_request_id = 0 THEN
1041 
1042            fnd_message.set_name('PQP', 'PQP_230228_PSI_EXT_SUBMIT_ERR');
1043            fnd_message.set_token('EXTNAME',g_ext_dtls(1).extract_name);
1044            l_err_msg := fnd_message.get;
1045            errbuf := l_err_msg;
1046            fnd_file.put_line(fnd_file.log, l_err_msg);
1047            l_err_msg := NULL;
1048          END IF;
1049 
1050          COMMIT;
1051          -- now search for extract name in this collection
1052          -- and store in global collection
1053          -- we are basically storing extract_name, request_id
1054          FOR j in 1..l_ext_names.count
1055          LOOP
1056            IF l_ext_names(j).extract_code = p_dfn_name
1057            THEN
1058              -- store the details in a global collection
1059              g_ext_dtls(j).extract_name     := l_ext_names(j).extract_name;
1060              g_ext_dtls(j).extract_code     := l_ext_names(j).extract_code;
1061              g_ext_dtls(j).short_name       := l_extract_shortname;
1062              g_ext_dtls(j).request_id       := l_request_id;
1063              /*
1064              g_ext_dtls(j).extract_rslt_id  := get_ext_rslt_frm_req
1065                            (p_request_id        => l_request_id
1066                            ,p_business_group_id => p_business_group_id
1067                            );
1068              */
1069            ELSE
1070              g_ext_dtls(j).extract_name := NULL;
1071            END IF;
1072          END LOOP;
1073 
1074          debug('Launched : '|| l_extract_shortname, 30);
1075          --
1076 
1077 
1078       ELSE -- submit all extract threads
1079 
1080         debug('p_dfn_name = 1ALL !',20);
1081 
1082         -- = ALL => submit all processes
1083         FOR i in 1..l_ext_names.count
1084         LOOP
1085 
1086            -- check for presence in lookup
1087            -- find the short name of the dfn_code
1088            l_extract_shortname := HR_GENERAL.DECODE_LOOKUP
1089                              (p_lookup_type   =>  'PQP_GB_PENSERVER_INTERFACES'
1090                              ,p_lookup_code   =>  l_ext_names(i).extract_code
1091                              );
1092 
1093            debug('l_extract_shortname :' || l_extract_shortname,30);
1094 
1095            -- submit the new process only if present in lookup
1096            IF  l_extract_shortname IS NOT NULL -- if present in lookup, then submit
1097            THEN
1098              -- append cutover/periodic to names
1099              IF p_extract_type = '3CUT' THEN
1100                l_extract_shortname := l_extract_shortname||' - '||'Cutover';
1101              ELSIF p_extract_type = '1PED' THEN
1102                l_extract_shortname := l_extract_shortname||' - '||'Periodic';
1103              END IF;
1104 
1105              debug('l_extract_shortname (appended) :' || l_extract_shortname,40);
1106              debug('now launching : '|| l_extract_shortname, 45);
1107 
1108              l_request_id :=
1109                       fnd_request.submit_request
1110                                 (application => 'PQP'
1111                                 ,program     => 'PQPGBPENSERVER'
1112                                 ,description => l_extract_shortname
1113                                 ,sub_request => FALSE -- TRUE, still not decide on this one
1114                                 ,argument1   => NULL -- benefit_action_id
1115                                 ,argument2   => p_business_group_id
1116                                 ,argument3   => p_execution_mode -- is already canonical
1117                                 ,argument4   => p_execution_mode_type
1118                                 ,argument5   => p_extract_type
1119                                 ,argument6   => l_ext_names(i).extract_code
1120                                 ,argument7   => p_start_date
1121                                 ,argument8   => p_eff_date
1122                                 ,argument9   => 'Y'
1123                                 ,argument10   => p_concurrent_request_id
1124                                          ,argument11  => p_year_end_close  -- Nuvos Changes
1125                                  ,argument12  => p_short_time_hours_single  -- -- For Bug 7010282
1126                                 );
1127 
1128              -- check for process submit error
1129              IF l_request_id = 0 THEN
1130 
1131                fnd_message.set_name('PQP', 'PQP_230228_PSI_EXT_SUBMIT_ERR');
1132                fnd_message.set_token('EXTNAME',l_ext_names(i).extract_name);
1133                l_err_msg := fnd_message.get;
1134                errbuf := l_err_msg;
1135                fnd_file.put_line(fnd_file.log, l_err_msg);
1136                l_err_msg := NULL;
1137                EXIT;
1138              END IF;
1139 
1140              COMMIT;
1141              -- store extract details in the collection
1142              g_ext_dtls(i).extract_name     := l_ext_names(i).extract_name;
1143              g_ext_dtls(i).extract_code     := l_ext_names(i).extract_code;
1144              g_ext_dtls(i).short_name       := l_extract_shortname;
1145              g_ext_dtls(i).request_id       := l_request_id;
1146 
1147              -- fnd_file.put_line(fnd_file.log, 'Request ID: ' ||l_request_id || ' Extract Name: '|| l_ext_names(i).extract_name);
1148 
1149              /*
1150              g_ext_dtls(i).extract_rslt_id  := get_ext_rslt_frm_req
1151                            (p_request_id        => l_request_id
1152                            ,p_business_group_id => p_business_group_id
1153                            );
1154              */
1155              debug('Launched : '|| l_extract_shortname, 50);
1156 
1157 
1158 
1159              IF l_threads <> 1 THEN
1160                l_wait_success := fnd_concurrent.wait_for_request
1161                                    (request_id => l_request_id
1162                                    ,interval   => (g_wait_interval - 30)
1163                                    ,max_wait   => g_max_wait
1164                                    ,phase      => l_phase          -- OUT
1165                                    ,status     => l_status         -- OUT
1166                                    ,dev_phase  => l_dev_phase      -- OUT
1167                                    ,dev_status => l_dev_status     -- OUT
1168                                    ,message    => l_message        -- OUT
1169                                    );
1170 
1171                -- Do some error checking here
1172                IF (NOT l_wait_success
1173                   )
1174                   OR
1175                   (l_dev_phase = 'COMPLETE' AND l_dev_status <> 'NORMAL'
1176                   ) THEN
1177 
1178                  fnd_file.put_line(fnd_file.log, l_message);
1179 
1180                  fnd_message.set_name('PQP', 'PQP_230229_PSI_EXT_EXEC_ERR');
1181                  fnd_message.set_token('EXTNAME',l_ext_names(i).extract_name);
1182                  l_err_msg := fnd_message.get;
1183                  errbuf := l_err_msg;
1184                  fnd_file.put_line(fnd_file.log, l_err_msg);
1185                  l_retcode := PROGRAM_FAILURE ;
1186                  l_err_msg:= NULL;
1187 --                 EXIT;
1188 
1189                END IF; -- (l_dev_phase = 'COMPLETE'
1190 
1191              END IF; -- l_threads <> 1 check ...
1192 
1193            ELSE -- l_extract_shortname IS NOT NULL
1194              g_ext_dtls(i).extract_name := NULL;
1195            END IF; -- l_extract short name is NULL check ...
1196         END LOOP; -- FOR i in 1..g_cutover_ext_names.count
1197 
1198       END IF; -- IF p_dfn_name <> '1ALL' THEN
1199 
1200       -------------- wait for child processes to end
1201       -- parent to wait till all child process end
1202       -- parent to error if any child fails
1203 
1204       -- dump data for debugging
1205       FOR i in 1..g_ext_dtls.count
1206       LOOP
1207         debug('g_ext_dtls('||i||').extract_name :' || g_ext_dtls(i).extract_name);
1208         debug('g_ext_dtls('||i||').extract_code : ' || g_ext_dtls(i).extract_code);
1209         debug('g_ext_dtls('||i||').short_name : ' || g_ext_dtls(i).short_name);
1210         debug('g_ext_dtls('||i||').request_id : ' || g_ext_dtls(i).request_id);
1211       END LOOP;
1212 
1213 
1214       l_index := g_ext_dtls.FIRST;
1215 
1216       -- start browsing thru collection of child thread details
1217       debug('start browsing thru collection of child thread details',60);
1218 
1219       WHILE l_index IS NOT NULL AND (p_dfn_name <> '1ALL' OR
1220                                      (p_dfn_name = '1ALL' AND l_threads = 1))
1221       LOOP
1222         IF g_ext_dtls(l_index).extract_name IS NOT NULL
1223         THEN
1224 
1225           l_wait_success := fnd_concurrent.wait_for_request
1226                               (request_id => g_ext_dtls(l_index).request_id
1227                               ,interval   => (g_wait_interval - 30)
1228                               ,max_wait   => g_max_wait
1229                               ,phase      => l_phase          -- OUT
1230                               ,status     => l_status         -- OUT
1231                               ,dev_phase  => l_dev_phase      -- OUT
1232                               ,dev_status => l_dev_status     -- OUT
1233                               ,message    => l_message        -- OUT
1234                               );
1235 
1236           -- Do some error checking here
1237           IF (NOT l_wait_success
1238              )
1239              OR
1240              (l_dev_phase = 'COMPLETE' AND l_dev_status <> 'NORMAL'
1241              ) THEN
1242 
1243             fnd_file.put_line(fnd_file.log, l_message);
1244 
1245             fnd_message.set_name('PQP', 'PQP_230229_PSI_EXT_EXEC_ERR');
1246             fnd_message.set_token('EXTNAME',g_ext_dtls(l_index).extract_name);
1247             l_err_msg := fnd_message.get;
1248             errbuf := l_err_msg;
1249             fnd_file.put_line(fnd_file.log, l_err_msg);
1250             l_retcode := PROGRAM_FAILURE ;
1251             l_err_msg:= NULL;
1252 --            EXIT;
1253           END IF; -- (l_dev_phase = 'COMPLETE'
1254 
1255 --            fnd_file.put_line(fnd_file.log, 'Completed the extract' || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
1256             fnd_file.put_line(fnd_file.log, 'Completed the extract' || ' : ' || get_time);
1257 
1258             debug('Completed Request ID :'||
1259                             to_char(g_ext_dtls(l_index).request_id), 160);
1260         END IF;
1261 
1262         l_index := g_ext_dtls.NEXT(l_index);
1263 
1264       END LOOP; --     WHILE l_index IS NOT NULL
1265 
1266       ---------------------------------------
1267       -- All extracts have been launched --
1268       -- now launch control totals
1269       ---------------------------------------
1270 
1271       debug('p_extract_type : ' || p_extract_type);
1272       -- now launch control total thread and then wait for it to finish
1273       IF p_extract_type <> '2CODE' THEN -- IF code files, then dont need to
1274         debug('now launch control total thread and then wait for it to finish ',70);
1275         -- fetch rslt_ids from request_ids
1276         FOR i in 1..g_ext_dtls.count
1277         LOOP
1278           IF g_ext_dtls(i).request_id IS NOT NULL
1279           THEN
1280             g_ext_dtls(i).extract_rslt_id  := get_ext_rslt_frm_req
1281                         (p_request_id        => g_ext_dtls(i).request_id
1282                         ,p_business_group_id => p_business_group_id
1283                         );
1284           END IF;
1285         END LOOP;
1286 
1287         /* The Claybrook order
1288         1  BASIC DATA              -- DONE
1289         2  ADDRESS                 -- DONE
1290         3  SERVICE HISTORY         -- DONE
1291         4  PART-TIME HOURS HISTORY
1292         5  SHORT-TIME HOURS HISTORY - Single Records
1293         6  SHORT-TIME HOURS HISTORY - Accumulated Records
1294         7  SALARY HISTORY          -- DONE
1295         8  ALLOWANCE HISTORY
1296         9  BONUS HISTORY
1297         10 EARNINGS HISTORY        -- DONE
1298         11 WPS CONTRIBUTION RATE HISTORY
1299         */
1300 
1301         /* In control totals
1302         1 Basic Data                                -- 1
1303         2 Address                                   -- 2
1304         3 Service                                   -- 3
1305         4 Salary                                    -- 7
1306         5 Earnings                                  -- 10
1307         6 Allowance                                 -- 8
1308         7 Bonus                                     -- 9
1309         8 WPS                                       -- 11
1310         9 Part-time hours                           -- 4
1311         10 Short-time hours Single records          -- 5
1312         11 Short-time hours Accumulated records     -- 6
1313         */
1314 
1315         --**************
1316         --
1317         -- We need to match the order for correct processing, as the order in code is different
1318         -- from that in control totals.
1319         --
1320         --**************
1321         debug('Submitting control totals ... ',80);
1322         l_request_id :=
1323                       fnd_request.submit_request
1324                                 (application => 'PQP'
1325                                 ,program     => 'PQPPENTTL'
1326                                 ,description => ''
1327                                 ,sub_request => FALSE -- TRUE, still not decide on this one
1328                                 ,argument1   => p_extract_type -- NULL
1329                                 ,argument2   => NULL
1330                                 ,argument3   => NULL
1331                                 ,argument4   => g_ext_dtls(1).extract_rslt_id
1332                                 ,argument5   => g_ext_dtls(2).extract_rslt_id
1333                                 ,argument6   => g_ext_dtls(3).extract_rslt_id
1334                                 ,argument7   => g_ext_dtls(7).extract_rslt_id
1335                                 ,argument8   => g_ext_dtls(10).extract_rslt_id
1336                                 ,argument9   => g_ext_dtls(8).extract_rslt_id
1337                                 ,argument10  => g_ext_dtls(9).extract_rslt_id
1338                                 ,argument11  => g_ext_dtls(11).extract_rslt_id
1339                                 ,argument12  => g_ext_dtls(4).extract_rslt_id
1340                                 ,argument13  => g_ext_dtls(5).extract_rslt_id
1341                                 ,argument14  => g_ext_dtls(6).extract_rslt_id
1342                                 ,argument15  => p_business_group_id
1343                                 ,argument16  => p_year_end_close  -- Nuvos Changes
1344                                 );
1345 
1346         -- check for process submit error
1347         IF l_request_id = 0 THEN
1348 
1349           fnd_message.set_name('PQP', 'PQP_230228_PSI_EXT_SUBMIT_ERR');
1350           fnd_message.set_token('EXTNAME','PenServer Control Totals Process');
1351           l_err_msg := fnd_message.get;
1352           errbuf := l_err_msg;
1353           fnd_file.put_line(fnd_file.log, l_err_msg);
1354           l_err_msg := NULL;
1355         END IF;
1356 
1357         COMMIT;
1358 
1359       -- now wait for control totals to finish
1360         l_wait_success := fnd_concurrent.wait_for_request
1361                             (request_id => l_request_id
1362                             ,interval   => (g_wait_interval - 30)
1363                             ,max_wait   => g_max_wait
1364                             ,phase      => l_phase          -- OUT
1365                             ,status     => l_status         -- OUT
1366                             ,dev_phase  => l_dev_phase      -- OUT
1367                             ,dev_status => l_dev_status     -- OUT
1368                             ,message    => l_message        -- OUT
1369                             );
1370 
1371         -- Do some error checking here
1372         IF (NOT l_wait_success
1373            )
1374            OR
1375            (l_dev_phase = 'COMPLETE' AND l_dev_status <> 'NORMAL'
1376            ) THEN
1377 
1378           fnd_file.put_line(fnd_file.log, l_message);
1379 
1380           fnd_message.set_name('PQP', 'PQP_230229_PSI_EXT_EXEC_ERR');
1381           fnd_message.set_token('EXTNAME','PenServer Control Totals');
1382           l_err_msg := fnd_message.get;
1383           errbuf := l_err_msg;
1384           fnd_file.put_line(fnd_file.log, l_err_msg);
1385           l_retcode := PROGRAM_FAILURE ;
1386           l_err_msg:= NULL;
1387 
1388         END IF; -- (l_dev_phase = 'COMPLETE'
1389       END IF;
1390       debug('Completed Request ID :'|| to_char(l_request_id), 160);
1391 
1392       -------------------------
1393 
1394       -- Check the return code for any failure
1395       IF l_retcode = PROGRAM_FAILURE THEN
1396 
1397           debug('Program Failure, erroring.', 170);
1398 
1399           retcode := l_retcode;
1400           fnd_message.raise_error;
1401           RETURN;
1402       END IF;
1403 
1404       -- Write a summary in the log file
1405       fnd_file.put_line(fnd_file.log, '----------------------------------------------------------------------   ');
1406       fnd_file.put_line(fnd_file.log, '**********************************************************************   ');
1407       fnd_file.put_line(fnd_file.log, ' ');
1408       fnd_file.put_line(fnd_file.log, 'PenServer Interface Process completed successfully.');
1409       fnd_file.put_line(fnd_file.log, ' ');
1410       fnd_file.put_line(fnd_file.log, '                                             Extract Name                                         Request Id    ');
1411       fnd_file.put_line(fnd_file.log, '---------------------------------------------------------------------------------------------    ------------   ');
1412 
1413 
1414       l_extract_count := 0;
1415       l_index         := g_ext_dtls.FIRST;
1416 
1417       WHILE l_index IS NOT NULL
1418       LOOP
1419 
1420         IF g_ext_dtls(l_index).extract_name IS NOT NULL
1421         THEN
1422           fnd_file.put(fnd_file.log, rpad(g_ext_dtls(l_index).extract_name, 100));
1423           fnd_file.put_line(fnd_file.log, rpad(g_ext_dtls(l_index).request_id, 15));
1424 
1425           l_extract_count := l_extract_count + 1;
1426         END IF;
1427 
1428         l_index := g_ext_dtls.NEXT(l_index);
1429 
1430       END LOOP; --     WHILE l_index IS NOT NULL
1431 
1432       fnd_file.put_line(fnd_file.log, 'Total Extracts processed :' ||to_char(l_extract_count));
1433       fnd_file.put_line(fnd_file.log, ' ');
1434 
1435       fnd_file.put_line(fnd_file.log, ' ');
1436       fnd_file.put_line(fnd_file.log, '**********************************************************************   ');
1437       fnd_file.put_line(fnd_file.log, '----------------------------------------------------------------------   ');
1438 
1439 
1440     -- the follwoing ELSE is for the case when this process is NOT a parent
1441     -- it is in fact one of the threads launched by Penserver Interface Process
1442     -- to launch individual extract processes
1443     ELSE -- IF p_submit_request_y_n = 'N' THEN
1444 
1445         -- This is a child thread, prepare to submit extract processes
1446         l_eff_date       := p_eff_date;
1447 
1448         debug('substr(p_eff_date,1,10) : '|| substr(p_eff_date,1,10));
1449         debug('l_eff_date :' || l_eff_date);
1450 
1451       --***************************
1452       -- fetch configuration value for cutover date
1453       debug('Fetching configuration value for cutover date ...', 40);
1454       pqp_utilities.get_config_type_values
1455                    ( p_configuration_type   => 'PQP_GB_PENSERVER_PAYPOINT_INFO' --'PQP_GB_PENSERVER_CUTOVER_DATE'
1456                                 ,p_business_group_id    => p_business_group_id
1457                                 ,p_legislation_code     => NULL
1458                                 ,p_tab_config_values    => l_config_value
1459                      );
1460 
1461       IF l_config_value.COUNT > 0 -- config value found
1462       THEN
1463         l_cutover_date := to_date(substr(l_config_value(l_config_value.FIRST).pcv_information2,1,10),'YYYY/MM/DD HH24:MI:SS');
1464       ELSE
1465         l_cutover_date := NULL;
1466       END IF;
1467 
1468       -- fetch Effective rolling date window length
1469       debug('Fetching Effective rolling date window length ...', 40);
1470       pqp_utilities.get_config_type_values
1471                    ( p_configuration_type   => 'PQP_GB_PENSERVER_DEFINITION'
1472                                 ,p_business_group_id    => p_business_group_id
1473                                 ,p_legislation_code     => NULL
1474                                 ,p_tab_config_values    => l_config_value
1475                      );
1476 
1477       IF l_config_value.COUNT > 0 -- config value found
1478       THEN
1479         IF l_rolling_window_length < 1
1480         THEN
1481           l_rolling_window_length := 6;
1482         ELSE
1483           l_rolling_window_length :=
1484             fnd_number.canonical_to_number(l_config_value(l_config_value.FIRST).pcv_information2);
1485         END IF;
1486 
1487         -- performance fix : 1
1488         g_reference_extract := l_config_value(l_config_value.FIRST).pcv_information3;
1489 
1490       ELSE
1491         l_rolling_window_length := 6;
1492 
1493         -- performance fix : 1
1494         g_reference_extract := 'BASIC';
1495       END IF;
1496 
1497 
1498       debug('l_rolling_window_length : '|| l_rolling_window_length);
1499       -- effective date window restrictions
1500       -- if effective start date < cutover date, pick cutover date for window start
1501       IF  l_cutover_date IS NOT NULL and
1502         (add_months(to_date(p_eff_date,'YYYY/MM/DD HH24:MI:SS'),(-1 * l_rolling_window_length))) < l_cutover_date
1503       THEN
1504         l_eff_start_date := to_char(l_cutover_date,'YYYY/MM/DD HH24:MI:SS');
1505       ELSE
1506         l_eff_start_date :=
1507             to_char(add_months(to_date(p_eff_date,'YYYY/MM/DD HH24:MI:SS'),(-1 * l_rolling_window_length)),'YYYY/MM/DD HH24:MI:SS');
1508       END IF;
1509 
1510       IF p_dfn_name not in ('STA','STS') THEN
1511         l_eff_start_date :=
1512             to_char(to_date(l_eff_start_date,'YYYY/MM/DD HH24:MI:SS')+1,'YYYY/MM/DD HH24:MI:SS');
1513       END IF;
1514 
1515       debug('After add_months/cutover date check : l_eff_start_date :' || l_eff_start_date);
1516 
1517       -- set the start date of the range to '00:00:00'
1518       -- and set the end date of the range to '23:59:59'
1519         --l_eff_start_date := TO_CHAR(l_eff_start_date,'YYYY/MM/DD');
1520         --l_eff_date       := TO_CHAR(l_eff_date,'YYYY/MM/DD')||' 23:59:59';
1521         debug('setting start date to 00:00:00 and end date to 23:59:59');
1522         l_eff_start_date := substr(l_eff_start_date,1,10)|| ' 00:00:00';
1523         l_eff_date := substr(l_eff_date,1,10)|| ' 23:59:59';
1524 
1525         debug('l_eff_start_date :' || l_eff_start_date);
1526         debug('l_eff_date :' || l_eff_date);
1527       --
1528 
1529       --***************************
1530 
1531         -- Call the actual benefit extract process with the effective date as
1532         -- the extract end date along with the ext def. id and business group id.
1533 
1534         IF p_dfn_name = 'ACI' THEN --Allowance Codes Interface
1535            debug('p_dfn_name = ACI !',30);
1536            get_allowance_codes
1537                   (p_business_group_id  => p_business_group_id
1538                   ,p_from_date          => to_date(l_eff_start_date,'YYYY/MM/DD HH24:MI:SS')
1539                   ,p_to_date            => to_date(l_eff_date,'YYYY/MM/DD HH24:MI:SS'));
1540         ELSIF p_dfn_name ='BCI' THEN --Bonus Codes Interface
1541            debug('p_dfn_name = BCI !',30);
1542            get_bonus_codes
1543                   (p_business_group_id  => p_business_group_id
1544                   ,p_from_date          => to_date(l_eff_start_date,'YYYY/MM/DD HH24:MI:SS')
1545                   ,p_to_date            => to_date(l_eff_date,'YYYY/MM/DD HH24:MI:SS'));
1546         ELSE
1547           -- submit the extract
1548 
1549           -- now search for extract name in this collection
1550           FOR i in 1..l_ext_names.count
1551           LOOP
1552             IF l_ext_names(i).extract_code = p_dfn_name
1553             THEN
1554               l_extract_name := l_ext_names(i).extract_name;
1555               EXIT;
1556             END IF;
1557           END LOOP;
1558 
1559           debug('will now find ext_dfn_id and submit extract');
1560           debug('p_extract_type : ' || p_extract_type );
1561           debug('p_dfn_name : ' || p_dfn_name );
1562 
1563           --
1564            --p_benefit_action_id
1565            --p_business_group_id
1566                --p_execution_mode
1567            --p_execution_mode_type
1568            --p_extract_type
1569            --p_dfn_name
1570            --p_start_date
1571            --p_eff_date
1572            --p_submit_request_y_n
1573            --p_concurrent_request_id
1574           --
1575 
1576           -- find ext_dfn_id
1577           OPEN csr_ext_dfn_id(c_extract_name => l_extract_name);
1578           FETCH csr_ext_dfn_id INTO l_ext_dfn_id;
1579           CLOSE csr_ext_dfn_id;
1580 
1581 
1582           -- Start 115.77.11511.3
1583          OPEN csr_get_run_date(c_ext_dfn_id         => l_ext_dfn_id
1584                               ,c_business_group_id  => g_business_group_id_backup);
1585          FETCH csr_get_run_date INTO g_last_app_date,g_output_name;
1586          CLOSE csr_get_run_date;
1587 
1588          debug('g_last_approved_date : ' || g_last_app_date );
1589          debug('g_output_name : ' || g_output_name );
1590          -- End 115.77.11511.3
1591 
1592 
1593           IF l_ext_dfn_id IS NOT NULL THEN
1594 
1595             IF p_execution_mode = '1REP'
1596             THEN
1597               ben_ext_thread.restart
1598                   (errbuf                    => l_errbuff
1599                   ,retcode                   => l_retcode
1600                   ,p_ext_dfn_id              => l_ext_dfn_id
1601                   ,p_concurrent_request_id   => p_concurrent_request_id
1602                   );
1603             ELSE
1604 
1605 
1606 --              fnd_file.put_line(fnd_file.log, 'calling ben_process' || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
1607               fnd_file.put_line(fnd_file.log, 'calling ben_process' || ' : ' || get_time);
1608 
1609               IF p_extract_type <> '1PED' -- cutover/code extract (full profile)
1610               THEN
1611                 ben_ext_thread.process
1612                    (errbuf                     => l_errbuff
1613                    ,retcode                    => l_retcode
1614                    ,p_benefit_action_id        => NULL
1615                    ,p_ext_dfn_id               => l_ext_dfn_id
1616                    ,p_effective_date           => l_eff_date
1617                    ,p_business_group_id        => p_business_group_id
1618                    ,p_penserv_date             => g_last_app_date        --for Bug 7358374
1619                    );
1620               ELSE -- (is = '1PED') -- periodic type
1621 
1622             -- Start 115.81
1623              -- start 115.84 7165575
1624               -- Modifed for 115.85
1625                IF  p_dfn_name = 'ADI'
1626                THEN
1627                   l_penserv_mode   := 'A' ;
1628                ELSE
1629                   l_penserv_mode   := 'Y';
1630                END IF;
1631                 -- End 115.84
1632             -- End 115.81
1633 
1634             debug('p_dfn_name : ' || p_dfn_name );
1635             debug('l_penserv_mode : ' || l_penserv_mode );
1636 
1637                 ben_ext_thread.process
1638                    (errbuf                     => l_errbuff
1639                    ,retcode                    => l_retcode
1640                    ,p_benefit_action_id        => NULL
1641                    ,p_ext_dfn_id               => l_ext_dfn_id
1642                    ,p_effective_date           => l_eff_date
1643                    ,p_business_group_id        => p_business_group_id
1644                    ,p_eff_start_date           => l_eff_start_date
1645                    ,p_eff_end_date             => l_eff_date
1646                    ,p_penserv_date             => g_last_app_date
1647                    ,p_penserv_mode             => l_penserv_mode
1648                    --,p_act_start_date           => hr_api.g_sot
1649                    --,p_act_end_date             => l_eff_date
1650                    );
1651               END IF; -- p_extract_type <> '1PED'
1652             END IF; -- p_execution_mode = '1REP'
1653           END IF; -- l_ext_dfn_id IS NOT NULL
1654         END IF; -- IF p_dfn_name = 'ACI' THEN
1655 
1656     END IF; -- IF p_submit_request_y_n = 'N'
1657 
1658  debug_exit(l_proc_name);
1659 EXCEPTION
1660   WHEN OTHERS THEN
1661     debug_exit(' Error  in '||l_proc_name);
1662     RAISE;
1663 END PQP_Penserver_Extract;
1664 
1665 
1666 
1667 -- =============================================================================
1668 -- This procedure gets control totals information
1669 -- =============================================================================
1670 PROCEDURE Get_Penserver_CntrlTtl_Process
1671            (errbuf                OUT NOCOPY  VARCHAR2
1672            ,retcode               OUT NOCOPY  VARCHAR2
1673            ,p_extract_type        IN     VARCHAR2 DEFAULT NULL
1674            ,p_parent_request_id       IN     NUMBER DEFAULT NULL
1675            ,p_parent_selected     IN     VARCHAR2 DEFAULT NULL
1676            ,p_ext_bdi_rslt_id     IN     NUMBER DEFAULT NULL
1677            ,p_ext_adi_rslt_id     IN     NUMBER DEFAULT NULL
1678                ,p_ext_sehi_rslt_id    IN     NUMBER DEFAULT NULL
1679            ,p_ext_sahi_rslt_id    IN     NUMBER DEFAULT NULL
1680            ,p_ext_ehi_rslt_id     IN     NUMBER DEFAULT NULL
1681            ,p_ext_ahi_rslt_id     IN     NUMBER DEFAULT NULL
1682                ,p_ext_bhi_rslt_id     IN     NUMBER DEFAULT NULL
1683            ,p_ext_wps_rslt_id     IN     NUMBER DEFAULT NULL
1684            ,p_ext_pthi_rslt_id    IN     NUMBER DEFAULT NULL
1685            ,p_ext_sthi_rslt_id    IN     NUMBER DEFAULT NULL
1686            ,p_ext_sthai_rslt_id   IN     NUMBER DEFAULT NULL
1687            ,p_business_group_id   IN     NUMBER
1688            ,p_year_end_close      IN     VARCHAR2 DEFAULT 'N'   -- For Nuvos Changes
1689            ) IS
1690 
1691 
1692 CURSOR csr_get_ttl_rslt(c_ext_rslt_id    IN Number) IS
1693   SELECT val_01,val_02,val_03,val_04,val_05
1694     FROM ben_ext_rslt_dtl dtl
1695         ,ben_ext_rcd     rcd
1696    WHERE dtl.ext_rslt_id = c_ext_rslt_id
1697      AND dtl.ext_rcd_id  = rcd.ext_rcd_id
1698      AND rcd.rcd_type_cd = 'T';
1699 
1700 CURSOR csr_get_rsltid (c_get_rsltid IN number) IS
1701 SELECT req.request_id  req_id
1702         ,bba.pl_id             rslt_id
1703         ,bba.pgm_id      ext_dfn_id
1704         ,argument3     Execution_Mode
1705         ,argument5     Extract_Type
1706         ,argument6     Interface_File
1707           ,argument8     Extract_eff_date        --- For Nuvos
1708             ,request_date      req_date
1709     FROM  fnd_concurrent_requests req, ben_benefit_actions bba
1710     WHERE parent_request_id = c_get_rsltid
1711       AND bba.request_id = req.request_id
1712       AND bba.business_group_id = p_business_group_id;
1713 
1714 
1715   -- For Nuvos
1716 
1717   CURSOR csr_get_eff_date (c_ext_rslt_id IN number) IS
1718   SELECT argument8     Extract_eff_date        --- For Nuvos
1719     FROM fnd_concurrent_requests req ,ben_ext_rslt ben
1720    where req.request_id = ben.request_id
1721      and ben.ext_rslt_id = c_ext_rslt_id
1722      and ben.business_group_id = p_business_group_id;
1723 
1724    -- For Nuvos Earnings
1725 
1726   CURSOR csr_get_ern_ttl_rslt(c_ext_rslt_id    IN Number) IS
1727    SELECT  val_01 payhcnt,
1728           nvl(val_03,0) + nvl(val_04,0) pearntot,
1729           nvl(val_02,0) + nvl(val_05,0) + nvl(val_06,0) + nvl(val_07,0) + nvl(val_08,0) + nvl(val_09,0) + nvl(val_10,0) + nvl(val_11,0) + nvl(val_12,0) pdedstot
1730     FROM ben_ext_rslt_dtl dtl
1731         ,ben_ext_rcd     rcd
1732    WHERE dtl.ext_rslt_id = c_ext_rslt_id
1733      AND dtl.ext_rcd_id  = rcd.ext_rcd_id
1734      AND rcd.rcd_type_cd = 'T';
1735 
1736 
1737 
1738   l_ext_bdi_rslt_id        NUMBER;
1739   l_ext_adi_rslt_id        NUMBER;
1740   l_ext_sehi_rslt_id       NUMBER;
1741   l_ext_sahi_rslt_id       NUMBER;
1742   l_ext_ehi_rslt_id        NUMBER;
1743   l_ext_ahi_rslt_id        NUMBER;
1744   l_ext_bhi_rslt_id        NUMBER;
1745   l_ext_wps_rslt_id        NUMBER;
1746   l_ext_pthi_rslt_id       NUMBER;
1747   l_ext_sthi_rslt_id       NUMBER;
1748   l_ext_sthai_rslt_id      NUMBER;
1749   l_ext_date               DATE;
1750 
1751   l_total_amount            NUMBER;
1752 
1753 
1754   l_pay_point              VARCHAR2(15);
1755   l_column_separator       VARCHAR2(10):= ' , ';
1756   l_cntrl_tot              t_cntrl_tot;
1757   l_Basic_Data_Cnt         VARCHAR2(10);
1758   l_Service_Hist_Cnt       VARCHAR2(10);
1759   l_Salary_Hist_Cnt        VARCHAR2(10);
1760   l_Sal_hist_Nat_Pay_Cnt   VARCHAR2(16);
1761   l_Address_Data_Cnt       VARCHAR2(10);
1762   l_Earning_Hist_Cnt       VARCHAR2(10);
1763   l_Earning_Tot_Cnt        VARCHAR2(16);
1764   l_Bonus_Hist_Cnt         VARCHAR2(10);
1765   l_Bonus_Tot_Cnt          VARCHAR2(16);
1766   l_STA_Hist_Cnt           VARCHAR2(10);
1767   l_STA_Tot_AdjHrs_Cnt     VARCHAR2(16);
1768   l_STS_Hist_Cnt           VARCHAR2(10);
1769   l_STS_Tot_AdjHrs_Cnt     VARCHAR2(16);
1770   l_WPS_Hist_Cnt           VARCHAR2(10);
1771   l_WPS_Tot_Cnt            VARCHAR2(16);
1772   l_Allowance_Hist_Cnt     VARCHAR2(10);
1773   l_Allowance_Tot_Cnt      VARCHAR2(16);
1774   l_PTH_Hist_Cnt            VARCHAR2(10);
1775   l_Tot_Part_Time_Hours_Cnt VARCHAR2(16);
1776 
1777   -- For Nuvos
1778   l_Pay_Hist_Cnt            VARCHAR2(10);
1779   l_Pay_Tot_EARN_Cnt        VARCHAR2(16);
1780   l_Pay_Tot_DEDS_Cnt        VARCHAR2(16);
1781 
1782 
1783 
1784   l_proc_name              VARCHAR2(200):= g_proc_name || 'Get_Penserver_CntrlTtl_Process';
1785 
1786   l_get_ttl_rslt           csr_get_ttl_rslt%ROWTYPE;   -- to fetch from the cursor.
1787   l_get_rsltid             csr_get_rsltid%ROWTYPE;
1788   l_ext_dfn_id             NUMBER;
1789   l_run_date               DATE;
1790   l_year_close             VARCHAR2(4);    -- For Nuvos
1791   l_per_end_date           DATE;           -- For Nuvos
1792   l_eff_date_arg8          VARCHAR2(30);   -- For Nuvos
1793   l_get_ern_ttl_rslt           csr_get_ern_ttl_rslt%ROWTYPE;  -- For Nuvos
1794 
1795 
1796 BEGIN
1797 
1798 
1799   hr_utility.set_location('p_ext_ehi_rslt_id: ' || p_ext_ehi_rslt_id, 10);
1800   -- check for enabling trace
1801   g_debug         :=  pqp_gb_psi_functions.check_debug(p_business_group_id);
1802 
1803   l_ext_bdi_rslt_id   :=         p_ext_bdi_rslt_id;
1804   l_ext_adi_rslt_id   :=         p_ext_adi_rslt_id;
1805   l_ext_sehi_rslt_id  :=         p_ext_sehi_rslt_id;
1806   l_ext_sahi_rslt_id  :=         p_ext_sahi_rslt_id;
1807   l_ext_ehi_rslt_id   :=         p_ext_ehi_rslt_id;
1808   l_ext_ahi_rslt_id   :=         p_ext_ahi_rslt_id;
1809   l_ext_bhi_rslt_id   :=         p_ext_bhi_rslt_id;
1810   l_ext_wps_rslt_id   :=         p_ext_wps_rslt_id;
1811   l_ext_pthi_rslt_id  :=         p_ext_pthi_rslt_id;
1812   l_ext_sthi_rslt_id  :=         p_ext_sthi_rslt_id;
1813   l_ext_sthai_rslt_id :=         p_ext_sthai_rslt_id;
1814   l_ext_date          :=         sysdate;
1815 
1816   debug_enter(l_proc_name);
1817 
1818   Build_Metadata_Ext_Names;
1819 
1820   -- get paypoint value for business group id passed
1821   l_pay_point := paypoint(p_business_group_id);
1822   debug ('l_pay_point:'||l_pay_point);
1823 
1824   IF l_pay_point = ''
1825      or
1826      NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> l_pay_point)
1827   THEN
1828     -- Raise error as Paypoint is unknown(E)
1829     hr_utility.set_message(805, 'BEN_94453_INV_PAYPOINT');
1830     fnd_file.put_line(fnd_file.LOG
1831                          , RPAD('Error', 30) || ': ' || hr_utility.get_message);
1832     fnd_file.put_line(fnd_file.LOG, ' ');
1833   END IF;
1834 
1835 
1836   debug('p_parent_request_id ' || p_parent_request_id, 20);
1837   -- If parent request id is supplied instead of individual result ids.
1838 
1839   IF p_parent_request_id IS NOT NULL THEN
1840       OPEN csr_get_rsltid(c_get_rsltid=>p_parent_request_id);
1841       LOOP
1842           FETCH csr_get_rsltid INTO l_get_rsltid;
1843           EXIT WHEN csr_get_rsltid%NOTFOUND;
1844             l_ext_date := l_get_rsltid.req_date;
1845               l_per_end_date := fnd_date.canonical_to_date(l_get_rsltid.Extract_eff_date);  -- For Nuvos change
1846             hr_utility.set_location('l_per_end_date: ' || l_per_end_date, 10);
1847             IF l_get_rsltid.Interface_File = g_periodic_ext_names(1).extract_code THEN
1848                l_ext_bdi_rslt_id  := l_get_rsltid.rslt_id;  -- dbms_output.put_line(l_ext_bdi_rslt_id);
1849                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 20);
1850             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(2).extract_code THEN
1851                l_ext_adi_rslt_id  := l_get_rsltid.rslt_id;  -- dbms_output.put_line(l_ext_adi_rslt_id);
1852                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 30);
1853             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(3).extract_code THEN
1854                l_ext_sehi_rslt_id  := l_get_rsltid.rslt_id; -- dbms_output.put_line(l_ext_sehi_rslt_id);
1855                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 40);
1856             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(4).extract_code THEN
1857                l_ext_pthi_rslt_id  := l_get_rsltid.rslt_id;
1858                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 50);
1859             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(5).extract_code THEN
1860                l_ext_sthi_rslt_id  := l_get_rsltid.rslt_id;
1861                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 60);
1862             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(6).extract_code THEN
1863                l_ext_sthai_rslt_id := l_get_rsltid.rslt_id;
1864                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 70);
1865             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(7).extract_code THEN
1866                l_ext_sahi_rslt_id  := l_get_rsltid.rslt_id; -- dbms_output.put_line(l_ext_sahi_rslt_id);
1867                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 80);
1868             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(8).extract_code THEN
1869                l_ext_ahi_rslt_id   := l_get_rsltid.rslt_id;
1870                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 90);
1871             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(9).extract_code THEN
1872                l_ext_bhi_rslt_id   := l_get_rsltid.rslt_id;
1873                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 100);
1874             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(10).extract_code THEN
1875                l_ext_ehi_rslt_id   := l_get_rsltid.rslt_id; -- dbms_output.put_line(l_ext_ehi_rslt_id);
1876                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 110);
1877             ELSIF l_get_rsltid.Interface_File = g_periodic_ext_names(11).extract_code THEN
1878                l_ext_wps_rslt_id   := l_get_rsltid.rslt_id;
1879                debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 120);
1880             END IF;
1881       END LOOP;
1882 
1883 
1884     CLOSE csr_get_rsltid;
1885 
1886   debug('l_get_rsltid.rslt_id '|| l_get_rsltid.rslt_id, 125);
1887   END IF;
1888 
1889   hr_utility.set_location('l_ext_ehi_rslt_id: ' || l_ext_ehi_rslt_id, 30);
1890   --Basic Data interface Count
1891   IF l_ext_bdi_rslt_id IS NOT NULL THEN
1892     OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_bdi_rslt_id);
1893     FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
1894       IF csr_get_ttl_rslt%NOTFOUND
1895       THEN
1896         l_Basic_Data_Cnt := RPAD(' ',10,' ');
1897       ELSE
1898         l_Basic_Data_Cnt :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
1899       END IF;
1900     CLOSE csr_get_ttl_rslt;
1901 
1902     -- For Nuvos
1903     OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_bdi_rslt_id);
1904     FETCH csr_get_eff_date into l_eff_date_arg8;
1905        IF csr_get_eff_date%NOTFOUND
1906        THEN
1907           l_per_end_date := sysdate;
1908        ELSE
1909           l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
1910        END IF;
1911     CLOSE csr_get_eff_date;
1912   ELSE
1913     l_Basic_Data_Cnt := RPAD(' ',10,' ');
1914   END IF;
1915 
1916 
1917   --Address data interface Count
1918 
1919   IF l_ext_adi_rslt_id IS NOT NULL THEN
1920     OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_adi_rslt_id);
1921     FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
1922       IF csr_get_ttl_rslt%NOTFOUND
1923       THEN
1924         l_Address_Data_Cnt := RPAD(' ',10,' ');
1925       ELSE
1926         l_Address_Data_Cnt :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_03),'0999999999')));
1927       END IF;
1928     CLOSE csr_get_ttl_rslt;
1929      -- For Nuvos
1930     OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_adi_rslt_id);
1931     FETCH csr_get_eff_date into l_eff_date_arg8;
1932        IF csr_get_eff_date%NOTFOUND
1933        THEN
1934           l_per_end_date := sysdate;
1935        ELSE
1936           l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
1937        END IF;
1938     CLOSE csr_get_eff_date;
1939   ELSE
1940     l_Address_Data_Cnt := RPAD(' ',10,' ');
1941   END IF;
1942 
1943 
1944  --Salary History interface Count
1945 
1946  IF l_ext_sahi_rslt_id IS NOT NULL THEN
1947    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_sahi_rslt_id);
1948    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
1949      IF csr_get_ttl_rslt%NOTFOUND
1950      THEN
1951        l_Salary_Hist_Cnt      := RPAD(' ',10,' ');
1952        l_Sal_hist_Nat_Pay_Cnt := RPAD(' ',16,' ');
1953      ELSE
1954        --
1955        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
1956          l_Salary_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
1957        ELSE
1958          l_Salary_Hist_Cnt      := RPAD(' ',10,' ');
1959        END IF;
1960        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
1961 
1962           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ttl_rslt.val_02);
1963           IF l_total_amount < 0 THEN
1964               l_Sal_hist_Nat_Pay_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
1965           ELSE
1966               l_Sal_hist_Nat_Pay_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
1967           END IF;
1968 
1969        ELSE
1970          l_Sal_hist_Nat_Pay_Cnt := RPAD(' ',16,' ');
1971        END IF;
1972        --
1973      END IF;
1974    CLOSE csr_get_ttl_rslt;
1975    -- For Nuvos
1976    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_sahi_rslt_id);
1977    FETCH csr_get_eff_date into l_eff_date_arg8;
1978       IF csr_get_eff_date%NOTFOUND
1979       THEN
1980         l_per_end_date := sysdate;
1981       ELSE
1982          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
1983       END IF;
1984    CLOSE csr_get_eff_date;
1985 
1986  ELSE
1987    l_Salary_Hist_Cnt      := RPAD(' ',10,' ');
1988    l_Sal_hist_Nat_Pay_Cnt := RPAD(' ',16,' ');
1989  END IF;
1990 
1991  debug(l_Salary_Hist_Cnt);
1992  debug(l_Sal_hist_Nat_Pay_Cnt);
1993  debug(l_ext_sahi_rslt_id);
1994 
1995 
1996  --Service History interface Count
1997  IF l_ext_sehi_rslt_id IS NOT NULL THEN
1998    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_sehi_rslt_id);
1999    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2000      IF csr_get_ttl_rslt%NOTFOUND
2001      THEN
2002        l_Service_Hist_Cnt := RPAD(' ',10,' ');
2003      ELSE
2004        l_Service_Hist_Cnt :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2005      END IF;
2006    CLOSE csr_get_ttl_rslt;
2007    -- For Nuvos
2008    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_sehi_rslt_id);
2009    FETCH csr_get_eff_date into l_eff_date_arg8;
2010       IF csr_get_eff_date%NOTFOUND
2011       THEN
2012         l_per_end_date := sysdate;
2013       ELSE
2014          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2015       END IF;
2016    CLOSE csr_get_eff_date;
2017  ELSE
2018    l_Service_Hist_Cnt := RPAD(' ',10,' ');
2019  END IF;
2020  debug(l_Service_Hist_Cnt);
2021  debug(l_ext_sehi_rslt_id);
2022 
2023  /*--Earning History interface Count
2024     -- commented for nuvos changes
2025  IF l_ext_ehi_rslt_id IS NOT NULL THEN
2026    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_ehi_rslt_id);
2027    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2028      IF csr_get_ttl_rslt%NOTFOUND
2029      THEN
2030        l_Earning_Hist_Cnt      := RPAD(' ',10,' ');
2031        l_Earning_Tot_Cnt       := RPAD(' ',16,' ');
2032      ELSE
2033        --
2034        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2035          l_Earning_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2036        ELSE
2037          l_Earning_Hist_Cnt      := RPAD(' ',10,' ');
2038        END IF;
2039        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2040 
2041           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ttl_rslt.val_02);
2042           IF l_total_amount < 0 THEN
2043               l_Earning_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2044           ELSE
2045               l_Earning_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2046           END IF;
2047 
2048             -- l_Earning_Tot_Cnt      :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2049        ELSE
2050          l_Earning_Tot_Cnt       := RPAD(' ',16,' ');
2051        END IF;
2052        --
2053      END IF;
2054    CLOSE csr_get_ttl_rslt;
2055 
2056    -- For Nuvos
2057    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_ehi_rslt_id);
2058    FETCH csr_get_eff_date into l_eff_date_arg8;
2059       IF csr_get_eff_date%NOTFOUND
2060       THEN
2061         l_per_end_date := sysdate;
2062       ELSE
2063          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2064       END IF;
2065    CLOSE csr_get_eff_date;
2066    hr_utility.set_location('l_per_end_date: '||l_per_end_date,64);
2067  ELSE
2068    l_Earning_Hist_Cnt      := RPAD(' ',10,' ');
2069    l_Earning_Tot_Cnt       := RPAD(' ',16,' ');
2070  END IF;
2071 
2072    debug(l_Earning_Hist_Cnt);
2073    debug(l_Earning_Tot_Cnt);
2074    debug(l_ext_ehi_rslt_id);  */
2075 
2076    --Earning History interface Count
2077  IF l_ext_ehi_rslt_id IS NOT NULL THEN
2078    OPEN csr_get_ern_ttl_rslt(c_ext_rslt_id => l_ext_ehi_rslt_id);
2079    FETCH csr_get_ern_ttl_rslt INTO l_get_ern_ttl_rslt;
2080      IF csr_get_ern_ttl_rslt%NOTFOUND
2081      THEN
2082        l_Pay_Hist_Cnt          := RPAD(' ',10,' ');
2083        l_Pay_Tot_EARN_Cnt      := RPAD(' ',16,' ');
2084        l_Pay_Tot_DEDS_Cnt      := RPAD(' ',16,' ');
2085      ELSE
2086        --
2087        IF l_get_ern_ttl_rslt.payhcnt IS NOT NULL THEN
2088          l_Pay_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ern_ttl_rslt.payhcnt),'0999999999')));
2089        ELSE
2090          l_Pay_Hist_Cnt      := RPAD(' ',10,' ');
2091        END IF;
2092        IF l_get_ern_ttl_rslt.pearntot IS NOT NULL THEN
2093 
2094           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ern_ttl_rslt.pearntot);
2095           IF l_total_amount < 0 THEN
2096               l_Pay_Tot_EARN_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2097           ELSE
2098               l_Pay_Tot_EARN_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2099           END IF;
2100 
2101             -- l_Earning_Tot_Cnt      :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2102        ELSE
2103          l_Pay_Tot_EARN_Cnt       := RPAD(' ',16,' ');
2104        END IF;
2105        IF l_get_ern_ttl_rslt.pdedstot IS NOT NULL THEN
2106 
2107           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ern_ttl_rslt.pdedstot);
2108           IF l_total_amount < 0 THEN
2109               l_Pay_Tot_DEDS_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2110           ELSE
2111               l_Pay_Tot_DEDS_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2112           END IF;
2113 
2114             -- l_Earning_Tot_Cnt      :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2115        ELSE
2116          l_Pay_Tot_DEDS_Cnt       := RPAD(' ',16,' ');
2117        END IF;
2118        --
2119      END IF;
2120    CLOSE csr_get_ern_ttl_rslt;
2121 
2122    -- For Nuvos
2123    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_ehi_rslt_id);
2124    FETCH csr_get_eff_date into l_eff_date_arg8;
2125       IF csr_get_eff_date%NOTFOUND
2126       THEN
2127         l_per_end_date := sysdate;
2128       ELSE
2129        hr_utility.set_location('l_eff_date_arg8'|| l_eff_date_arg8,31);
2130          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2131       END IF;
2132    CLOSE csr_get_eff_date;
2133    hr_utility.set_location('l_per_end_date: '||l_per_end_date,64);
2134  ELSE
2135    l_Pay_Hist_Cnt      := RPAD(' ',10,' ');
2136    l_Pay_Tot_EARN_Cnt       := RPAD(' ',16,' ');
2137    l_Pay_Tot_DEDS_Cnt       := RPAD(' ',16,' ');
2138  END IF;
2139 
2140    debug(l_Pay_Hist_Cnt);
2141    debug(l_Pay_Tot_EARN_Cnt);
2142    debug(l_Pay_Tot_DEDS_Cnt);
2143    debug(l_ext_ehi_rslt_id);
2144 
2145 
2146   --Bonus History interface Count
2147 
2148  IF l_ext_bhi_rslt_id IS NOT NULL THEN
2149    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_bhi_rslt_id);
2150    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2151      IF csr_get_ttl_rslt%NOTFOUND
2152      THEN
2153        l_Bonus_Hist_Cnt      := RPAD(' ',10,' ');
2154        l_Bonus_Tot_Cnt := RPAD(' ',16,' ');
2155      ELSE
2156        --
2157        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2158          l_Bonus_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2159        ELSE
2160          l_Bonus_Hist_Cnt      := RPAD(' ',10,' ');
2161        END IF;
2162        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2163 
2164           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ttl_rslt.val_02);
2165           IF l_total_amount < 0 THEN
2166               l_Bonus_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2167           ELSE
2168               l_Bonus_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2169           END IF;
2170 
2171           -- l_Bonus_Tot_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2172        ELSE
2173          l_Bonus_Tot_Cnt := RPAD(' ',16,' ');
2174        END IF;
2175        --
2176      END IF;
2177    CLOSE csr_get_ttl_rslt;
2178    -- For Nuvos
2179    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_bhi_rslt_id);
2180    FETCH csr_get_eff_date into l_eff_date_arg8;
2181       IF csr_get_eff_date%NOTFOUND
2182       THEN
2183         l_per_end_date := sysdate;
2184       ELSE
2185          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2186       END IF;
2187    CLOSE csr_get_eff_date;
2188 
2189  ELSE
2190    l_Bonus_Hist_Cnt      := RPAD(' ',10,' ');
2191    l_Bonus_Tot_Cnt := RPAD(' ',16,' ');
2192  END IF;
2193 
2194  debug(l_Bonus_Hist_Cnt);
2195  debug(l_Bonus_Tot_Cnt);
2196  debug(l_ext_bhi_rslt_id);
2197 
2198  --WPS History interface Count
2199 
2200  IF l_ext_wps_rslt_id IS NOT NULL THEN
2201    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_wps_rslt_id);
2202    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2203      IF csr_get_ttl_rslt%NOTFOUND
2204      THEN
2205        l_WPS_Hist_Cnt      := RPAD(' ',10,' ');
2206        l_WPS_Tot_Cnt := RPAD(' ',16,' ');
2207      ELSE
2208        --
2209        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2210          l_WPS_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2211        ELSE
2212          l_WPS_Hist_Cnt      := RPAD(' ',10,' ');
2213        END IF;
2214        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2215 
2216           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ttl_rslt.val_02);
2217           IF l_total_amount < 0 THEN
2218               l_WPS_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2219           ELSE
2220               l_WPS_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2221           END IF;
2222 
2223           -- l_WPS_Tot_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2224        ELSE
2225          l_WPS_Tot_Cnt := RPAD(' ',16,' ');
2226        END IF;
2227        --
2228      END IF;
2229    CLOSE csr_get_ttl_rslt;
2230   -- For Nuvos
2231    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_wps_rslt_id);
2232    FETCH csr_get_eff_date into l_eff_date_arg8;
2233       IF csr_get_eff_date%NOTFOUND
2234       THEN
2235         l_per_end_date := sysdate;
2236       ELSE
2237          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2238       END IF;
2239    CLOSE csr_get_eff_date;
2240 
2241  ELSE
2242    l_WPS_Hist_Cnt      := RPAD(' ',10,' ');
2243    l_WPS_Tot_Cnt := RPAD(' ',16,' ');
2244  END IF;
2245 
2246  debug(l_WPS_Hist_Cnt);
2247  debug(l_WPS_Tot_Cnt);
2248  debug(l_ext_wps_rslt_id);
2249 
2250  --Short-Time Hours ( Accumulated ) History interface Count
2251 
2252  IF l_ext_sthai_rslt_id IS NOT NULL THEN
2253    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_sthai_rslt_id);
2254    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2255      IF csr_get_ttl_rslt%NOTFOUND
2256      THEN
2257        l_STA_Hist_Cnt      := RPAD(' ',10,' ');
2258        l_STA_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2259      ELSE
2260        --
2261        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2262          l_STA_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2263        ELSE
2264          l_STA_Hist_Cnt      := RPAD(' ',10,' ');
2265        END IF;
2266        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2267          l_STA_Tot_AdjHrs_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'S099999999999D99')));
2268        ELSE
2269          l_STA_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2270        END IF;
2271        --
2272      END IF;
2273    CLOSE csr_get_ttl_rslt;
2274   -- For Nuvos
2275    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_sthai_rslt_id);
2276    FETCH csr_get_eff_date into l_eff_date_arg8;
2277       IF csr_get_eff_date%NOTFOUND
2278       THEN
2279         l_per_end_date := sysdate;
2280       ELSE
2281          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2282       END IF;
2283    CLOSE csr_get_eff_date;
2284 
2285  ELSE
2286    l_STA_Hist_Cnt      := RPAD(' ',10,' ');
2287    l_STA_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2288  END IF;
2289 
2290  debug(l_STA_Hist_Cnt);
2291  debug(l_STA_Tot_AdjHrs_Cnt);
2292  debug(l_ext_sthai_rslt_id);
2293 
2294  --Short-Time Hours ( Single ) History interface Count
2295 
2296  IF l_ext_sthi_rslt_id IS NOT NULL THEN
2297    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_sthi_rslt_id);
2298    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2299      IF csr_get_ttl_rslt%NOTFOUND
2300      THEN
2301        l_STS_Hist_Cnt      := RPAD(' ',10,' ');
2302        l_STS_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2303      ELSE
2304        --
2305        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2306          l_STS_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2307        ELSE
2308          l_STS_Hist_Cnt      := RPAD(' ',10,' ');
2309        END IF;
2310        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2311          l_STS_Tot_AdjHrs_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'S099999999999D99')));
2312        ELSE
2313          l_STS_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2314        END IF;
2315        --
2316      END IF;
2317    CLOSE csr_get_ttl_rslt;
2318   -- For Nuvos
2319    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_sthi_rslt_id);
2320    FETCH csr_get_eff_date into l_eff_date_arg8;
2321       IF csr_get_eff_date%NOTFOUND
2322       THEN
2323         l_per_end_date := sysdate;
2324       ELSE
2325          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2326       END IF;
2327    CLOSE csr_get_eff_date;
2328 
2329  ELSE
2330    l_STS_Hist_Cnt      := RPAD(' ',10,' ');
2331    l_STS_Tot_AdjHrs_Cnt := RPAD(' ',16,' ');
2332  END IF;
2333 
2334  debug(l_STS_Hist_Cnt);
2335  debug(l_STS_Tot_AdjHrs_Cnt);
2336  debug(l_ext_sthi_rslt_id);
2337 
2338  --Allowance History interface Count
2339 
2340  IF l_ext_ahi_rslt_id IS NOT NULL THEN
2341    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_ahi_rslt_id);
2342    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2343      IF csr_get_ttl_rslt%NOTFOUND
2344      THEN
2345        l_Allowance_Hist_Cnt      := RPAD(' ',10,' ');
2346        l_Allowance_Tot_Cnt := RPAD(' ',16,' ');
2347      ELSE
2348        --
2349        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2350          l_Allowance_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2351        ELSE
2352          l_Allowance_Hist_Cnt      := RPAD(' ',10,' ');
2353        END IF;
2354        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2355 
2356           l_total_amount  :=  fnd_number.canonical_to_number(l_get_ttl_rslt.val_02);
2357           IF l_total_amount < 0 THEN
2358               l_Allowance_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'S099999999999.99')));
2359           ELSE
2360               l_Allowance_Tot_Cnt:=rtrim(ltrim(to_char(l_total_amount,'0999999999999.99')));
2361           END IF;
2362 
2363           -- l_Allowance_Tot_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'0999999999999.99')));
2364        ELSE
2365          l_Allowance_Tot_Cnt := RPAD(' ',16,' ');
2366        END IF;
2367        --
2368      END IF;
2369    CLOSE csr_get_ttl_rslt;
2370   -- For Nuvos
2371    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_ahi_rslt_id);
2372    FETCH csr_get_eff_date into l_eff_date_arg8;
2373       IF csr_get_eff_date%NOTFOUND
2374       THEN
2375         l_per_end_date := sysdate;
2376       ELSE
2377          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2378       END IF;
2379    CLOSE csr_get_eff_date;
2380 
2381  ELSE
2382    l_Allowance_Hist_Cnt      := RPAD(' ',10,' ');
2383    l_Allowance_Tot_Cnt := RPAD(' ',16,' ');
2384  END IF;
2385 
2386  debug(l_Allowance_Hist_Cnt);
2387  debug(l_Allowance_Tot_Cnt);
2388  debug(l_ext_ahi_rslt_id);
2389 
2390 
2391 --Part-Time Hours ( Single ) History interface Count
2392 
2393  IF l_ext_pthi_rslt_id IS NOT NULL THEN
2394    OPEN csr_get_ttl_rslt(c_ext_rslt_id => l_ext_pthi_rslt_id);
2395    FETCH csr_get_ttl_rslt INTO l_get_ttl_rslt;
2396      IF csr_get_ttl_rslt%NOTFOUND
2397      THEN
2398        l_PTH_Hist_Cnt          := RPAD(' ',10,' ');
2399        l_Tot_Part_Time_Hours_Cnt := RPAD(' ',16,' ');
2400      ELSE
2401        --
2402        IF l_get_ttl_rslt.val_01 IS NOT NULL THEN
2403          l_PTH_Hist_Cnt     :=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_01),'0999999999')));
2404        ELSE
2405          l_PTH_Hist_Cnt      := RPAD(' ',10,' ');
2406        END IF;
2407        IF l_get_ttl_rslt.val_02 IS NOT NULL THEN
2408          l_Tot_Part_Time_Hours_Cnt:=rtrim(ltrim(to_char(fnd_number.canonical_to_number(l_get_ttl_rslt.val_02),'S099999999999D99')));
2409        ELSE
2410          l_Tot_Part_Time_Hours_Cnt := RPAD(' ',16,' ');
2411        END IF;
2412        --
2413      END IF;
2414    CLOSE csr_get_ttl_rslt;
2415    -- For Nuvos
2416    OPEN csr_get_eff_date(c_ext_rslt_id => l_ext_pthi_rslt_id);
2417    FETCH csr_get_eff_date into l_eff_date_arg8;
2418       IF csr_get_eff_date%NOTFOUND
2419       THEN
2420         l_per_end_date := sysdate;
2421       ELSE
2422          l_per_end_date := fnd_date.canonical_to_date(l_eff_date_arg8);
2423       END IF;
2424    CLOSE csr_get_eff_date;
2425 
2426  ELSE
2427    l_PTH_Hist_Cnt      := RPAD(' ',10,' ');
2428    l_Tot_Part_Time_Hours_Cnt := RPAD(' ',16,' ');
2429  END IF;
2430 
2431  debug(l_PTH_Hist_Cnt);
2432  debug(l_Tot_Part_Time_Hours_Cnt);
2433  debug(l_ext_pthi_rslt_id);
2434 
2435 
2436 -----------
2437 
2438      OPEN csr_ext_dfn_id(c_extract_name => 'PQP GB PenServer Periodic Changes Interface - Basic Data');
2439      FETCH csr_ext_dfn_id INTO l_ext_dfn_id;
2440      CLOSE csr_ext_dfn_id;
2441 
2442      -- Get the run date
2443      OPEN csr_get_run_date(c_ext_dfn_id         => l_ext_dfn_id
2444                           ,c_business_group_id  => p_business_group_id);
2445      FETCH csr_get_run_date INTO l_run_date,g_output_name;
2446      CLOSE csr_get_run_date;
2447 
2448 
2449    IF p_extract_type = '3CUT' THEN
2450      l_cntrl_tot(1).seq_num := '001';
2451    ELSE
2452      IF g_output_name IS NULL THEN
2453        l_cntrl_tot(1).seq_num := '002';
2454      ELSE
2455        IF p_parent_request_id IS NULL THEN
2456          l_cntrl_tot(1).seq_num := rtrim(ltrim(to_char(fnd_number.canonical_to_number(substr(g_output_name,INSTR(g_output_name,'.')+1))+1,'099')));
2457        ELSE
2458          l_cntrl_tot(1).seq_num := rtrim(ltrim(to_char(fnd_number.canonical_to_number(substr(g_output_name,INSTR(g_output_name,'.')+1)),'099')));
2459        END IF;
2460      END IF;
2461    END IF;
2462 
2463 ------------
2464  hr_utility.set_location('l_year_close1: ' || l_year_close , 11);
2465  hr_utility.set_location('p_year_end_close: ' || p_year_end_close , 11);
2466 
2467 /* For Nuvps */
2468    IF p_year_end_close = 'Yes'
2469    THEN
2470 
2471        IF l_per_end_date between to_date('01-04-'||to_char(l_per_end_date,'YYYY'),'DD-MM-YYYY') and to_date('31-12-'||to_char(l_per_end_date,'YYYY'),'DD-MM-YYYY')
2472       THEN
2473          l_year_close := to_number(to_char(l_per_end_date,'yyyy'));
2474 
2475       ELSE
2476 
2477          l_year_close := to_number(to_char(l_per_end_date,'yyyy')) -1;
2478 
2479       END IF;
2480    ELSE
2481       l_year_close := RPAD(' ' ,4,' ');
2482 
2483    END IF;
2484 
2485    l_per_end_date := last_day(l_per_end_date);
2486    hr_utility.set_location('l_per_end_date: ' || l_per_end_date, 20);
2487    hr_utility.set_location('l_year_close6: ' || l_year_close , 11);
2488 
2489    l_Earning_Hist_Cnt      := RPAD(' ',10,' ');
2490    l_Earning_Tot_Cnt       := RPAD(' ',16,' ');
2491 
2492 
2493 
2494           l_cntrl_tot(1).pay_point                       :=RPAD(nvl(l_pay_point,' ') ,6,' ');
2495           l_cntrl_tot(1).file_extract_date               :=to_char(l_ext_date, 'DD/MM/YYYY HH24:MI');
2496         --Not done
2497           -- l_cntrl_tot(1).seq_num                         :=RPAD(' ',3,' ');
2498         --This one is related to Basic Data interface
2499           l_cntrl_tot(1).basic_cnt                       :=l_Basic_Data_Cnt;
2500         --This one is related to Service History interface
2501           l_cntrl_tot(1).serv_hist_cnt                   :=l_Service_Hist_Cnt;
2502         --These two are related to Salary History interface
2503           l_cntrl_tot(1).sal_hist_cnt                    :=l_Salary_Hist_Cnt;
2504           l_cntrl_tot(1).sal_hist_tot_national_pay       :=l_Sal_hist_Nat_Pay_Cnt;
2505     --This one is related to Address data interface
2506           l_cntrl_tot(1).addr_data_tot_rec               :=l_Address_Data_Cnt;
2507        --These two are related to Earnings History interface,Which is not done for this QA drop
2508           l_cntrl_tot(1).earn_hist_cnt                   :=l_Earning_Hist_Cnt;
2509           l_cntrl_tot(1).earn_hist_tot_WPS               :=l_Earning_Tot_Cnt;
2510 
2511     --All below fields are not either supported or building for this drop,so hardcoded the values
2512 
2513         --These two are related to Allowance History interface
2514           l_cntrl_tot(1).allw_hist_rec_cnt               :=l_Allowance_Hist_Cnt;
2515           l_cntrl_tot(1).allw_hist_tot_allw_rate         :=l_Allowance_Tot_Cnt;
2516         --These two are related to Bonus History interface
2517           l_cntrl_tot(1).bonus_hist_rec_cnt              := l_Bonus_Hist_Cnt;
2518           l_cntrl_tot(1).bonus_hist_tot_bonus_amt        := l_Bonus_Tot_Cnt;
2519         --These two are related to WPS Contributions History interface
2520           l_cntrl_tot(1).WPS_contrbt_hist_rec_cnt        := l_WPS_Hist_Cnt;
2521           l_cntrl_tot(1).WPS_contrbt_hist_tot_perc       := l_WPS_Tot_Cnt;
2522         --This left blank ,because we are  not building AVC History interface
2523           l_cntrl_tot(1).AVC_hist_rec_cnt                :=RPAD(' ' ,10,' ');
2524           l_cntrl_tot(1).EECONT_tot                      :=RPAD(' ' ,16,' ');
2525         --This left blank ,because we are  not building Transfer in and other benefits interface.
2526           l_cntrl_tot(1).other_benef_rec_cnt             :=RPAD(' ' ,10,' ');
2527           l_cntrl_tot(1).PUP_tot                         :=RPAD(' ' ,16,' ');
2528         --These two are related to Part-time Hours History interface,Which is not done for this QA drop
2529           l_cntrl_tot(1).prt_tm_hr_hist_rec_cnt          :=l_PTH_Hist_Cnt;
2530           l_cntrl_tot(1).prt_tm_hr_hist_tot_pthrs        :=l_Tot_Part_Time_Hours_Cnt;
2531         --These two are related to Short-time Hours History (Single record)
2532           l_cntrl_tot(1).srt_tm_hr_hist_sing_rec_cnt     := l_STS_Hist_Cnt;
2533           l_cntrl_tot(1).srt_tm_hr_hist_sing_tot_hr_var  := l_STS_Tot_AdjHrs_Cnt;
2534         --These two are related to Short-time Hours History (Accumulated record)
2535           l_cntrl_tot(1).srt_tm_hr_hist_accu_rec_cnt     := l_STA_Hist_Cnt;
2536           l_cntrl_tot(1).srt_tm_hr_hist_accu_tot_hr_var  := l_STA_Tot_AdjHrs_Cnt;
2537         --This left blank ,because we are  not building Dated Event Details interface
2538           l_cntrl_tot(1).event_det_tot_rec               :=RPAD(' ' ,10,' ');
2539           l_cntrl_tot(1).event_det_tot_amt               :=RPAD(' ' ,16,' ');
2540         --This left blank ,because we are  not building Remarks interface interface
2541           l_cntrl_tot(1).remarks_interface_tot_rec       :=RPAD(' ' ,10,' ');
2542         --This left blank ,because we are  not building Beneficiary Details interface
2543           l_cntrl_tot(1).benef_det_tot_rec               :=RPAD(' ' ,10,' ');
2544        -- Nuvos Pay file
2545           l_cntrl_tot(1).pay_hist_cnt                   :=l_Pay_Hist_Cnt;
2546           l_cntrl_tot(1).pay_hist_tot_EARN              :=l_Pay_Tot_EARN_Cnt;
2547           l_cntrl_tot(1).pay_hist_tot_DEDS              :=l_Pay_Tot_DEDS_Cnt;
2548          -- For Nuvos
2549           l_cntrl_tot(1).year_end_close                  :=l_year_close;
2550           l_cntrl_tot(1).pay_per_end_date                :=substr(to_char(l_per_end_date, 'DD/MM/YYYY HH24:MI'),1,10);
2551 
2552 
2553       /*  --These two are related to Earnings History interface,Which is not done for this QA drop
2554           l_cntrl_tot(1).earn_hist_cnt                   :=rtrim(ltrim(to_char(0, '0999999999')));
2555           l_cntrl_tot(1).earn_hist_tot_WPS               :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2556         --These two are related to Allowance History interface,Which is not done for this QA drop
2557           l_cntrl_tot(1).allw_hist_rec_cnt               :=rtrim(ltrim(to_char(0, '0999999999')));
2558           l_cntrl_tot(1).allw_hist_tot_allw_rate         :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2559         --These two are related to Allowance History interface,Which is not done for this QA drop
2560           l_cntrl_tot(1).bonus_hist_rec_cnt              :=rtrim(ltrim(to_char(0, '0999999999')));
2561           l_cntrl_tot(1).bonus_hist_tot_bonus_amt        :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2562         --These two are related to WPS Contributions History interface,Which is not done for this QA drop
2563           l_cntrl_tot(1).WPS_contrbt_hist_rec_cnt        :=rtrim(ltrim(to_char(0, '0999999999')));
2564           l_cntrl_tot(1).WPS_contrbt_hist_tot_perc       :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2565         --This left blank ,because we are  not building AVC History interface
2566           l_cntrl_tot(1).AVC_hist_rec_cnt                :=rtrim(ltrim(to_char(0, '0999999999')));
2567           l_cntrl_tot(1).EECONT_tot                      :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2568         --This left blank ,because we are  not building Transfer in and other benefits interface.
2569           l_cntrl_tot(1).other_benef_rec_cnt             :=rtrim(ltrim(to_char(0, '0999999999')));
2570           l_cntrl_tot(1).PUP_tot                         :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2571         --These two are related to Part-time Hours History interface,Which is not done for this QA drop
2572           l_cntrl_tot(1).prt_tm_hr_hist_rec_cnt          :=rtrim(ltrim(to_char(0, '0999999999')));
2573           l_cntrl_tot(1).prt_tm_hr_hist_tot_pthrs    :=rtrim(ltrim(to_char(0, '0999999999999999')));
2574         --These two are related to Short-time Hours History (Single record),Which is not done for this QA drop
2575           l_cntrl_tot(1).srt_tm_hr_hist_sing_rec_cnt     :=rtrim(ltrim(to_char(0, '0999999999')));
2576           l_cntrl_tot(1).srt_tm_hr_hist_sing_tot_hr_var  :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2577         --These two are related to Short-time Hours History (Accumulated record),Which is not done for this QA drop
2578           l_cntrl_tot(1).srt_tm_hr_hist_accu_rec_cnt     :=rtrim(ltrim(to_char(0, '0999999999')));
2579           l_cntrl_tot(1).srt_tm_hr_hist_accu_tot_hr_var  :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2580         --This left blank ,because we are  not building Dated Event Details interface
2581           l_cntrl_tot(1).event_det_tot_rec               :=rtrim(ltrim(to_char(0, '0999999999')));
2582           l_cntrl_tot(1).event_det_tot_amt               :=rtrim(ltrim(to_char(0, '0999999999999999V99')));
2583         --This left blank ,because we are  not building Remarks interface interface
2584           l_cntrl_tot(1).remarks_interface_tot_rec       :=rtrim(ltrim(to_char(0, '0999999999')));
2585         --This left blank ,because we are  not building Beneficiary Details interface
2586           l_cntrl_tot(1).benef_det_tot_rec               :=rtrim(ltrim(to_char(0, '0999999999'))); */
2587 
2588   debug ('Before writing into file');
2589   -- insert control totals information into output file
2590         fnd_file.put_line(fnd_file.output,
2591                          l_cntrl_tot(1).pay_point ||
2592                          l_cntrl_tot(1).file_extract_date ||
2593                          l_cntrl_tot(1).seq_num ||
2594                          l_cntrl_tot(1).basic_cnt ||
2595                          l_cntrl_tot(1).serv_hist_cnt ||
2596                          l_cntrl_tot(1).earn_hist_cnt ||
2597                          l_cntrl_tot(1).earn_hist_tot_WPS ||
2598                          l_cntrl_tot(1).sal_hist_cnt ||
2599                          l_cntrl_tot(1).sal_hist_tot_national_pay ||
2600                          l_cntrl_tot(1).allw_hist_rec_cnt ||
2601                          l_cntrl_tot(1).allw_hist_tot_allw_rate ||
2602                          l_cntrl_tot(1).bonus_hist_rec_cnt ||
2603                          l_cntrl_tot(1).bonus_hist_tot_bonus_amt ||
2604                          l_cntrl_tot(1).WPS_contrbt_hist_rec_cnt ||
2605                          l_cntrl_tot(1).WPS_contrbt_hist_tot_perc ||
2606                          l_cntrl_tot(1).AVC_hist_rec_cnt ||
2607                          l_cntrl_tot(1).EECONT_tot ||
2608                          l_cntrl_tot(1).other_benef_rec_cnt ||
2609                          l_cntrl_tot(1).PUP_tot ||
2610                          l_cntrl_tot(1).prt_tm_hr_hist_rec_cnt ||
2611                          l_cntrl_tot(1).prt_tm_hr_hist_tot_pthrs ||
2612                          l_cntrl_tot(1).srt_tm_hr_hist_sing_rec_cnt ||
2613                          l_cntrl_tot(1).srt_tm_hr_hist_sing_tot_hr_var ||
2614                          l_cntrl_tot(1).srt_tm_hr_hist_accu_rec_cnt ||
2615                          l_cntrl_tot(1).srt_tm_hr_hist_accu_tot_hr_var ||
2616                          l_cntrl_tot(1).event_det_tot_rec ||
2617                          l_cntrl_tot(1).event_det_tot_amt ||
2618                          l_cntrl_tot(1).remarks_interface_tot_rec ||
2619                          l_cntrl_tot(1).addr_data_tot_rec ||
2620                          l_cntrl_tot(1).benef_det_tot_rec ||
2621                          l_cntrl_tot(1).pay_hist_cnt ||
2622                          l_cntrl_tot(1).pay_hist_tot_EARN ||
2623                          l_cntrl_tot(1).pay_hist_tot_DEDS ||
2624                                l_cntrl_tot(1).year_end_close ||       -- for nuvos
2625                                l_cntrl_tot(1).pay_per_end_date);
2626 
2627 
2628         debug(' file content : ' || l_cntrl_tot(1).pay_point ||
2629                          l_cntrl_tot(1).file_extract_date ||
2630                          l_cntrl_tot(1).seq_num ||
2631                          l_cntrl_tot(1).basic_cnt ||
2632                          l_cntrl_tot(1).serv_hist_cnt ||
2633                          l_cntrl_tot(1).earn_hist_cnt ||
2634                          l_cntrl_tot(1).earn_hist_tot_WPS ||
2635                          l_cntrl_tot(1).sal_hist_cnt ||
2636                          l_cntrl_tot(1).sal_hist_tot_national_pay ||
2637                          l_cntrl_tot(1).allw_hist_rec_cnt ||
2638                          l_cntrl_tot(1).allw_hist_tot_allw_rate ||
2639                          l_cntrl_tot(1).bonus_hist_rec_cnt ||
2640                          l_cntrl_tot(1).bonus_hist_tot_bonus_amt ||
2641                          l_cntrl_tot(1).WPS_contrbt_hist_rec_cnt ||
2642                          l_cntrl_tot(1).WPS_contrbt_hist_tot_perc ||
2643                          l_cntrl_tot(1).AVC_hist_rec_cnt ||
2644                          l_cntrl_tot(1).EECONT_tot ||
2645                          l_cntrl_tot(1).other_benef_rec_cnt ||
2646                          l_cntrl_tot(1).PUP_tot ||
2647                          l_cntrl_tot(1).prt_tm_hr_hist_rec_cnt ||
2648                          l_cntrl_tot(1).prt_tm_hr_hist_tot_pthrs ||
2649                          l_cntrl_tot(1).srt_tm_hr_hist_sing_rec_cnt ||
2650                          l_cntrl_tot(1).srt_tm_hr_hist_sing_tot_hr_var ||
2651                          l_cntrl_tot(1).srt_tm_hr_hist_accu_rec_cnt ||
2652                          l_cntrl_tot(1).srt_tm_hr_hist_accu_tot_hr_var ||
2653                          l_cntrl_tot(1).event_det_tot_rec ||
2654                          l_cntrl_tot(1).event_det_tot_amt ||
2655                          l_cntrl_tot(1).remarks_interface_tot_rec ||
2656                          l_cntrl_tot(1).addr_data_tot_rec ||
2657                          l_cntrl_tot(1).benef_det_tot_rec ||
2658                          l_cntrl_tot(1).pay_hist_cnt ||
2659                          l_cntrl_tot(1).pay_hist_tot_EARN ||
2660                          l_cntrl_tot(1).pay_hist_tot_DEDS ||
2661                          l_cntrl_tot(1).year_end_close ||    -- for nuvos
2662                          l_cntrl_tot(1).pay_per_end_date);
2663 
2664 
2665  debug_exit(l_proc_name);
2666  EXCEPTION
2667       WHEN OTHERS  THEN
2668       debug_exit(' Error  in '||l_proc_name);
2669       RAISE;
2670   END Get_Penserver_CntrlTtl_Process;
2671 
2672 -- ----------------------------------------------------------------------------
2673 -- |--------------------------------< employer_code >-------------------------|
2674 -- ----------------------------------------------------------------------------
2675 
2676   FUNCTION employer_code
2677       (p_business_group_id       NUMBER
2678       ,p_effective_date          DATE
2679       ,p_assignment_id           NUMBER
2680       ) RETURN VARCHAR2
2681   IS
2682      -- Cursor to get assignment details
2683      CURSOR csr_get_org_id(c_basic_date DATE)
2684      IS
2685      SELECT organization_id
2686        FROM per_all_assignments_f
2687       WHERE assignment_id = p_assignment_id
2688         AND c_basic_date BETWEEN effective_start_date
2689                                  AND effective_end_date;
2690 
2691      -- Cursor to get employer code
2692      CURSOR csr_get_emp_code (c_organization_id NUMBER)
2693      IS
2694      SELECT org_information1
2695        FROM hr_organization_information
2696       WHERE organization_id = c_organization_id
2697         AND org_information_context = 'PQP_GB_PENSERV_REPORTING_INFO';
2698 
2699      l_proc_name           VARCHAR2(61):=
2700      g_proc_name||'employer_code';
2701 
2702     l_org_id       NUMBER;
2703     l_employer_code hr_organization_information.org_information1%TYPE;
2704     l_value        NUMBER;
2705     --115.85
2706     l_basic_date   DATE;
2707 
2708     --115.87/115.88:Bug 7291713: Start
2709     CURSOR csr_get_bas_ext_dfn_id
2710     IS
2711       SELECT ext_dfn_id
2712       FROM BEN_EXT_DFN
2713       WHERE name = 'PQP GB PenServer Periodic Changes Interface - Basic Data'
2714       AND legislation_code ='GB';
2715 
2716     CURSOR csr_get_max_asg_end_date
2717     IS
2718       SELECT max(effective_end_date)
2719       FROM per_all_assignments_f
2720       WHERE assignment_id = p_assignment_id;
2721 
2722     l_max_asg_end_date  DATE;
2723     l_bas_ext_dfn_id    NUMBER;
2724     --115.87/115.88:Bug 7291713: Stop
2725 
2726   BEGIN
2727   --
2728     debug_enter(l_proc_name);
2729   -- 115.85
2730 
2731   --115.88:Bug 7291713: Start
2732     OPEN csr_get_bas_ext_dfn_id;
2733     FETCH csr_get_bas_ext_dfn_id INTO l_bas_ext_dfn_id;
2734     CLOSE csr_get_bas_ext_dfn_id;
2735 
2736     debug('l_bas_ext_dfn_id: '|| l_bas_ext_dfn_id);
2737     debug('ben_ext_thread.g_ext_dfn_id: '|| ben_ext_thread.g_ext_dfn_id);
2738 
2739     IF l_bas_ext_dfn_id = ben_ext_thread.g_ext_dfn_id
2740   --115.88:Bug 7291713: Stop
2741     THEN
2742 
2743        --115.87:Bug 7291713: Start
2744        OPEN csr_get_max_asg_end_date;
2745        FETCH csr_get_max_asg_end_date INTO l_max_asg_end_date;
2746        CLOSE csr_get_max_asg_end_date;
2747 
2748        debug('ben_ext_person.g_effective_date: '|| ben_ext_person.g_effective_date);
2749 
2750        IF l_max_asg_end_date < ben_ext_person.g_effective_date
2751        THEN
2752            l_basic_date := l_max_asg_end_date;
2753        ELSE
2754             l_basic_date := ben_ext_person.g_effective_date;
2755        END IF;
2756     --115.87:Bug 7291713: Stop
2757 
2758     ELSE --g_dfn_name <> 'BDI'
2759        l_basic_date := p_effective_date;
2760     END IF;
2761 
2762     debug('g_dfn_name : '|| g_dfn_name);
2763     debug('l_basic_date : '|| l_basic_date);
2764 
2765     OPEN csr_get_org_id(l_basic_date);
2766     FETCH csr_get_org_id INTO l_org_id;
2767     CLOSE csr_get_org_id;
2768 
2769     -- If employer code exists for this organization
2770     -- return it from collection otherwise fetch and
2771     -- store in the collection
2772     IF g_employer_code.EXISTS(l_org_id) THEN
2773       l_employer_code := g_employer_code(l_org_id);
2774     ELSE
2775       l_employer_code := NULL;
2776       OPEN csr_get_emp_code(l_org_id);
2777       FETCH csr_get_emp_code INTO l_employer_code;
2778       IF csr_get_emp_code%NOTFOUND OR
2779          l_employer_code IS NULL
2780       THEN
2781         -- store error
2782         l_value := raise_extract_error
2783                      (p_error_number        =>    92369
2784                      ,p_error_text          =>    'BEN_92369_EXT_PSI_NO_EMP_CODE'
2785                      );
2786       ELSE -- employer code information found
2787         g_employer_code(l_org_id) := l_employer_code;
2788       END IF;
2789       CLOSE csr_get_emp_code;
2790     END IF; -- End if of code exists in collection check ...
2791 
2792     debug('Employer Code: '|| l_employer_code);
2793     debug_exit(l_proc_name);
2794 
2795     RETURN l_employer_code;
2796 
2797   EXCEPTION
2798     WHEN others THEN
2799         IF SQLCODE <> hr_utility.hr_error_number
2800         THEN
2801             debug_others (l_proc_name, 10);
2802             IF g_debug
2803             THEN
2804               DEBUG (   'Leaving: '
2805                      || l_proc_name, -999);
2806              END IF;
2807              fnd_message.raise_error;
2808          ELSE
2809              RAISE;
2810          END IF;
2811 
2812   END employer_code;
2813 
2814 
2815 
2816 -- ----------------------------------------------------------------------------
2817 -- |--------------------------------< altkey >--------------------------------|
2818 -- ----------------------------------------------------------------------------
2819 
2820   FUNCTION altkey
2821     --(p_assignment_number IN     VARCHAR2 -- context
2822     --,p_paypoint          IN     VARCHAR2 -- context
2823     --)
2824     RETURN VARCHAR2
2825   IS
2826     l_proc_name           VARCHAR2(61):=
2827      g_proc_name||'altkey';
2828 
2829     l_return       VARCHAR2(20);
2830     CURSOR csr_get_assignment_number
2831     IS
2832         SELECT assignment_number
2833         FROM per_all_assignments_f
2834         WHERE assignment_id = g_assignment_id
2835         AND g_effective_date BETWEEN effective_start_date
2836                              AND effective_end_date;
2837 
2838   BEGIN
2839   --
2840     debug_enter(l_proc_name);
2841     debug('g_paypoint : '||g_paypoint,10);
2842     debug('g_assignment_number : '||g_assignment_number,20);
2843 
2844     -- added by kkarri
2845     -- g_assignment_number will be set in basic criteria
2846     -- but for bonus history the basic criteria will be called
2847     -- for claim date. When a claim date is invalid, assignment_number
2848     -- will remain null.
2849     IF g_assignment_number IS NULL THEN
2850         DEBUG('assignment_number NOT FOUND',30);
2851         DEBUG('g_effective_date'||g_effective_date,30);
2852         OPEN csr_get_assignment_number;
2853         FETCH csr_get_assignment_number INTO g_assignment_number;
2854         CLOSE csr_get_assignment_number;
2855 
2856         g_assignment_number := TRIM(REPLACE(g_assignment_number,'-',''));
2857 
2858         debug('g_assignment_number : '||g_assignment_number,30);
2859     END IF;
2860 
2861     l_return := g_paypoint || g_assignment_number;
2862     debug('l_return : '||l_return,30);
2863     debug_exit(l_proc_name);
2864 
2865     RETURN l_return;
2866 
2867   EXCEPTION
2868     WHEN others THEN
2869         IF SQLCODE <> hr_utility.hr_error_number
2870         THEN
2871             debug_others (l_proc_name, 10);
2872             IF g_debug
2873             THEN
2874               DEBUG (   'Leaving: '
2875                      || l_proc_name, -999);
2876              END IF;
2877              fnd_message.raise_error;
2878          ELSE
2879              RAISE;
2880          END IF;
2881 
2882   END altkey;
2883 
2884 
2885 
2886 -- ----------------------------------------------------------------------------
2887 -- |--------------------------------< paypoint >--------------------------------|
2888 -- ----------------------------------------------------------------------------
2889 
2890   FUNCTION paypoint
2891     (p_business_group_id IN     VARCHAR2 -- context
2892     )
2893     RETURN VARCHAR2
2894   IS
2895     l_proc_name           VARCHAR2(61):=
2896      g_proc_name||'paypoint';
2897 
2898     l_config_value        pqp_utilities.t_config_values;
2899     l_return              VARCHAR2(20);
2900 
2901   BEGIN
2902   --
2903     debug_enter(l_proc_name);
2904 
2905 
2906     IF g_paypoint IS NULL -- 115.58 (4)
2907     THEN
2908       -- fetch configuration value for paypoint
2909       debug('Fetching configuration value for paypoint ...', 20);
2910         pqp_utilities.get_config_type_values
2911              ( p_configuration_type   => 'PQP_GB_PENSERVER_PAYPOINT_INFO'
2912               ,p_business_group_id    => p_business_group_id
2913               ,p_legislation_code     => NULL
2914               ,p_tab_config_values    => l_config_value
2915              );
2916 
2917       IF l_config_value.COUNT > 0 -- config value found
2918       THEN
2919         g_paypoint := l_config_value(l_config_value.FIRST).pcv_information1;
2920 
2921       ELSE
2922       -- ERR store error
2923 
2924         g_paypoint := '';
2925       END IF;
2926 
2927     END IF;
2928 
2929     debug_exit(l_proc_name);
2930 
2931     RETURN g_paypoint;
2932 
2933   EXCEPTION
2934     WHEN others THEN
2935         IF SQLCODE <> hr_utility.hr_error_number
2936         THEN
2937             debug_others (l_proc_name, 10);
2938             IF g_debug
2939             THEN
2940               DEBUG (   'Leaving: '
2941                      || l_proc_name, -999);
2942              END IF;
2943              fnd_message.raise_error;
2944          ELSE
2945              RAISE;
2946          END IF;
2947 
2948   END paypoint;
2949 
2950 
2951 
2952 
2953 /*
2954 
2955 -- ----------------------------------------------------------------------------
2956 -- |------------------------< exclude_errored_people >-------------------------------|
2957 -- ----------------------------------------------------------------------------
2958 -- procedure to mark errored persons as 'U' (unprocessed)
2959 
2960 
2961 Procedure exclude_errored_people
2962           (p_business_group_id in number
2963           ) Is
2964 
2965   l_conc_reqest_id      Number(20);
2966   l_exists              Varchar2(2);
2967 
2968   l_proc_name           VARCHAR2(61):=
2969      g_proc_name||'exclude_errored_people';
2970 
2971    l_ben_params             csr_ben%ROWTYPE;
2972 
2973 
2974    cursor csr_err_per_action_id
2975       (c_benefit_action_id IN NUMBER
2976       ,c_ext_rslt_id       IN NUMBER)
2977 
2978    IS
2979    select person_action_id
2980     from ben_person_actions bpa
2981    Where bpa.benefit_action_id = c_benefit_action_id
2982      and EXISTS
2983               ( SELECT ers.PERSON_ID
2984      FROM BEN_EXT_RSLT_ERR ers
2985      WHERE ers.person_id = bpa.person_id
2986         AND ers.EXT_RSLT_ID= c_ext_rslt_id
2987         AND typ_cd = 'E');
2988 
2989 
2990 Begin
2991 
2992 debug_enter(l_proc_name);
2993 
2994 
2995    OPEN csr_ben (c_ext_dfn_id        => Ben_Ext_Thread.g_ext_dfn_id
2996                 ,c_ext_rslt_id       => Ben_Ext_Thread.g_ext_rslt_id
2997                 ,c_business_group_id => p_business_group_id);
2998    Fetch csr_ben Into l_ben_params;
2999    CLOSE csr_ben;
3000 
3001    debug('l_ben_params.benefit_action_id :' || l_ben_params.benefit_action_id);
3002 
3003 
3004   Update ben_person_actions bpa
3005      Set bpa.action_status_cd = 'U'
3006    Where bpa.benefit_action_id = l_ben_params.benefit_action_id -- 3629 -- p_benefit_action_id
3007      and bpa.person_id  -- = p_person_id;
3008             IN ( SELECT PERSON_ID
3009      FROM BEN_EXT_RSLT_ERR
3010      WHERE EXT_RSLT_ID= Ben_Ext_Thread.g_ext_rslt_id -- 2891 -- c_ext_rslt_id
3011         AND typ_cd = 'E');
3012 
3013   Update ben_batch_ranges bbr
3014     set bbr.range_status_cd = 'E'
3015   Where bbr.benefit_action_id = l_ben_params.benefit_action_id
3016     AND EXISTS(
3017       Select 1 -- distinct(bere.person_id)
3018         From ben_person_actions bpa, BEN_EXT_RSLT_ERR bere
3019       Where bpa.benefit_action_id = l_ben_params.benefit_action_id
3020         AND bbr.benefit_action_id = bpa.benefit_action_id
3021         AND (bpa.person_action_id Between
3022              bbr.starting_person_action_id And bbr.ending_person_action_id)
3023         And bpa.person_id = bere.person_id
3024         AND bere.EXT_RSLT_ID= Ben_Ext_Thread.g_ext_rslt_id
3025         AND bere.typ_cd = 'E');
3026 
3027   debug_exit(l_proc_name);
3028 
3029   EXCEPTION
3030   WHEN others THEN
3031       IF SQLCODE <> hr_utility.hr_error_number
3032       THEN
3033           debug_others (l_proc_name, 10);
3034           IF g_debug
3035           THEN
3036             DEBUG (   'Leaving: '
3037                    || l_proc_name, -999);
3038            END IF;
3039            fnd_message.raise_error;
3040        ELSE
3041            RAISE;
3042        END IF;
3043 End exclude_errored_people;
3044 
3045 */
3046 
3047 --
3048 -- modified as part of 115.58 (1)
3049 --
3050 -- ----------------------------------------------------------------------------
3051 -- |------------------------< exclude_errored_people >-------------------------------|
3052 -- ----------------------------------------------------------------------------
3053 -- procedure to mark errored persons as 'U' (unprocessed)
3054 
3055 
3056 Procedure exclude_errored_people
3057           (p_business_group_id in number
3058           ) Is
3059 
3060   l_conc_reqest_id      Number(20);
3061   l_exists              Varchar2(2);
3062 
3063   l_proc_name           VARCHAR2(61):=
3064      g_proc_name||'exclude_errored_people';
3065 
3066   CURSOR csr_err_person_id
3067         (p_ext_rslt_id       IN NUMBER)
3068   IS
3069   SELECT distinct(ers.PERSON_ID)
3070    FROM BEN_EXT_RSLT_ERR ers
3071    WHERE ers.EXT_RSLT_ID = p_ext_rslt_id
3072       AND typ_cd = 'E';
3073 
3074   CURSOR csr_range_id
3075          (p_person_action_id  IN NUMBER
3076          ,p_benefit_action_id IN NUMBER
3077          )
3078   IS
3079     SELECT bbr.range_id
3080     FROM ben_batch_ranges bbr
3081     WHERE bbr.benefit_action_id = p_benefit_action_id
3082       AND p_person_action_id Between
3083               bbr.starting_person_action_id And bbr.ending_person_action_id;
3084 
3085   TYPE t_number IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3086   l_person_collection         t_number;
3087   l_RangeId_collection        t_number;
3088   l_per_action_id_collection  t_number;
3089 
3090   l_range_id  NUMBER;
3091   l_itr       NUMBER;
3092   i           NUMBER;
3093 
3094   l_ben_params             csr_ben%ROWTYPE;
3095 
3096 Begin
3097 
3098   debug_enter(l_proc_name);
3099 
3100 
3101    OPEN csr_ben (c_ext_dfn_id        => Ben_Ext_Thread.g_ext_dfn_id
3102                 ,c_ext_rslt_id       => Ben_Ext_Thread.g_ext_rslt_id
3103                 ,c_business_group_id => p_business_group_id);
3104    Fetch csr_ben Into l_ben_params;
3105    CLOSE csr_ben;
3106 
3107    debug('l_ben_params.benefit_action_id :' || l_ben_params.benefit_action_id);
3108 
3109 
3110      -- (1) fetch all person_ids which have errored
3111      OPEN csr_err_person_id(p_ext_rslt_id => Ben_Ext_Thread.g_ext_rslt_id);
3112      FETCH csr_err_person_id BULK COLLECT INTO l_person_collection;
3113      CLOSE csr_err_person_id;
3114 
3115      debug('Step 1 Completed');
3116 
3117 
3118      -- (2) update using FORALL and bulk collect all person_action_id
3119      FORALL i in 1..l_person_collection.COUNT
3120        Update ben_person_actions bpa
3121          Set bpa.action_status_cd = 'U'
3122        Where bpa.benefit_action_id = l_ben_params.benefit_action_id
3123          and bpa.person_id = l_person_collection(i)
3124        RETURNING person_action_id BULK COLLECT INTO l_per_action_id_collection;
3125 
3126      debug('Step 2 Completed');
3127      debug('l_per_action_id_collection.COUNT : ' || l_per_action_id_collection.COUNT);
3128 
3129 
3130      -- (3) run thru the PL/SQL collection and populate a range_id collection
3131      IF l_per_action_id_collection.COUNT > 0
3132      THEN
3133 
3134        FOR l_index IN l_per_action_id_collection.FIRST..l_per_action_id_collection.LAST
3135        LOOP
3136 
3137          OPEN csr_range_id
3138               (p_person_action_id  => l_per_action_id_collection(l_index)
3139               ,p_benefit_action_id => l_ben_params.benefit_action_id
3140               );
3141          FETCH csr_range_id INTO l_range_id;
3142          CLOSE csr_range_id;
3143 
3144          IF NOT l_RangeId_collection.EXISTS(l_range_id) THEN
3145             l_RangeID_collection(l_range_id) := l_range_id;
3146          END IF;
3147        END LOOP;
3148      END IF; -- l_per_action_id_collection.COUNT > 0
3149 
3150      debug('Step 3 Completed');
3151      debug('l_RangeID_collection.COUNT : ' || l_RangeID_collection.COUNT);
3152 
3153 
3154      -- (4) now use the range Id collection to update the batch ranges
3155      FOR i IN 1..l_RangeID_collection.COUNT
3156      LOOP
3157 
3158        IF i=1 THEN
3159          l_itr :=l_RangeID_collection.FIRST;
3160        ELSE
3161          l_itr :=l_RangeID_collection.NEXT(l_itr);
3162        END IF;
3163 
3164          Update ben_batch_ranges bbr
3165             set bbr.range_status_cd = 'E'
3166           Where bbr.range_id = l_RangeID_collection(l_itr);
3167 
3168      END LOOP;
3169 
3170     debug('Step 4 Completed');
3171 
3172 
3173   debug_exit(l_proc_name);
3174 
3175   EXCEPTION
3176   WHEN others THEN
3177       IF SQLCODE <> hr_utility.hr_error_number
3178       THEN
3179           debug_others (l_proc_name, 10);
3180           IF g_debug
3181           THEN
3182             DEBUG (   'Leaving: '
3183                    || l_proc_name, -999);
3184            END IF;
3185            fnd_message.raise_error;
3186        ELSE
3187            RAISE;
3188        END IF;
3189 End exclude_errored_people;
3190 
3191 
3192 
3193 
3194 -- ----------------------------------------------------------------------------
3195 -- |------------------------< common_post_process >-------------------------------|
3196 -- ----------------------------------------------------------------------------
3197 -- procedure to mark errored persons as 'U' (unprocessed)
3198 
3199 
3200 Procedure common_post_process
3201           (p_business_group_id in number
3202           ) Is
3203 
3204 
3205   l_proc_name           VARCHAR2(61):=
3206      g_proc_name||'common_post_process';
3207 
3208   CURSOR csr_dfn_code
3209   IS
3210   Select output_name
3211   from ben_ext_dfn
3212   where ext_dfn_id = ben_ext_thread.g_ext_dfn_id;
3213 
3214   l_extract_code        csr_dfn_code%rowtype;
3215   l_file_name           VARCHAR2(100);
3216   l_run_date            DATE;
3217   l_business_group_id   NUMBER := NULL;
3218 
3219 Begin
3220 
3221   debug_enter(l_proc_name);
3222 
3223 --    fnd_file.put_line(fnd_file.log, l_proc_name || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
3224     fnd_file.put_line(fnd_file.log, l_proc_name || ' : ' || get_time);
3225 
3226     -- 115.60
3227     -- this happens when persons are rejected at the system extract level
3228     -- in such cases, set_shared_globals doesnt get called, and the globals
3229     -- need to be set here
3230     IF p_business_group_id IS NULL
3231     THEN
3232       l_business_group_id := g_business_group_id_backup;
3233     ELSE
3234       l_business_group_id := p_business_group_id;
3235     END IF;
3236 
3237     -- set paypoint if not found
3238     debug('g_paypoint :' || g_paypoint);
3239     IF g_paypoint IS NULL
3240     THEN
3241       g_paypoint := paypoint(l_business_group_id);
3242       debug('g_paypoint :' || g_paypoint);
3243     END IF;
3244 
3245     -- function call to exclude errored people
3246     exclude_errored_people(l_business_group_id);
3247 
3248     debug('g_extract_type : ' || g_extract_type);
3249     debug('g_output_name : ' || g_output_name);
3250     debug('g_sequence_number : ' || g_sequence_number);
3251 
3252 
3253     -- Get the output file name
3254     OPEN csr_get_run_date(c_ext_dfn_id         => ben_ext_thread.g_ext_dfn_id
3255                          ,c_business_group_id  => l_business_group_id);
3256     FETCH csr_get_run_date INTO l_run_date,g_output_name;
3257     CLOSE csr_get_run_date;
3258 
3259 
3260     IF g_extract_type = '3CUT' THEN
3261       g_sequence_number := '001';
3262     ELSE
3263       IF g_output_name IS NULL THEN
3264         g_sequence_number := '002';
3265       ELSE
3266         g_sequence_number := rtrim(ltrim(to_char(fnd_number.canonical_to_number(substr(g_output_name,INSTR(g_output_name,'.')+1))+1,'099')));
3267       END IF;
3268     END IF;
3269 
3270     debug('g_extract_type : ' || g_extract_type);
3271     debug('g_output_name : ' || g_output_name);
3272     debug('g_sequence_number : ' || g_sequence_number);
3273 
3274     OPEN csr_dfn_code;
3275     FETCH csr_dfn_code INTO l_extract_code;
3276     CLOSE csr_dfn_code;
3277 
3278     debug('l_extract_code.output_name :' || l_extract_code.output_name);
3279 
3280 
3281     l_file_name := l_extract_code.output_name || g_paypoint || '.' || g_sequence_number;
3282 
3283     debug('l_file_name :' || l_file_name );
3284 
3285     update ben_ext_rslt
3286     SET output_name = l_file_name
3287     WHERE business_group_id = l_business_group_id
3288       AND ext_rslt_id = ben_ext_thread.g_ext_rslt_id;
3289 
3290   debug_exit(l_proc_name);
3291 
3292 --  fnd_file.put_line(fnd_file.log, 'Done : ' || l_proc_name || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
3293   fnd_file.put_line(fnd_file.log, 'Done : ' || l_proc_name || ' : ' || get_time);
3294 
3295   EXCEPTION
3296   WHEN others THEN
3297       IF SQLCODE <> hr_utility.hr_error_number
3298       THEN
3299           debug_others (l_proc_name, 10);
3300           IF g_debug
3301           THEN
3302             DEBUG (   'Leaving: '
3303                    || l_proc_name, -999);
3304            END IF;
3305            fnd_message.raise_error;
3306        ELSE
3307            RAISE;
3308        END IF;
3309 End common_post_process;
3310 
3311 --
3312 --
3313 -- ----------------------------------------------------------------------------
3314 -- |------------------------< raise_extract_warning >-----------------------|
3315 -- ----------------------------------------------------------------------------
3316 
3317 
3318 --
3319 --    RAISE_EXTRACT_WARNING
3320 --
3321 --    "Smart" warning function.
3322 --    When called from the Rule of a extract detail data element
3323 --    it logs a warning in the ben_ext_rslt_err table against
3324 --    the person being processed (or as specified by context of
3325 --    assignment id ). It prefixes all warning messages with a
3326 --    string "Warning raised in data element "||element_name
3327 --    This allows the same Rule to be called from different data
3328 --    elements.
3329 --
3330 --    usage example.
3331 --
3332 --    RAISE_EXTRACT_WARNING("No initials were found.")
3333 --
3334 --    RRTURNCODE  MEANING
3335 --    -1          Cannot raise warning against a header/trailer
3336 --                record. System Extract does not allow it.
3337 --
3338 --    -2          No current extract process was found.
3339 --
3340 --    -3          No person was found.A Warning in System Extract
3341 --                is always raised against a person.
3342 --
3343 
3344   FUNCTION raise_extract_warning
3345     (p_assignment_id     IN     NUMBER    DEFAULT g_assignment_id     -- context
3346     ,p_error_text        IN     VARCHAR2
3347     ,p_error_number      IN     NUMBER    DEFAULT NULL
3348     ,p_token1            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3349     ,p_token2            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3350     ,p_token3            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3351     ,p_token4            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3352     ) RETURN NUMBER
3353   IS
3354 
3355     l_proc_name           VARCHAR2(61):=
3356      g_proc_name||'raise_extract_warning';
3357 
3358      l_ext_rslt_id   NUMBER;
3359      l_person_id     NUMBER;
3360      l_error_text    VARCHAR2(2000);
3361      l_return_value  NUMBER:= 0;
3362   BEGIN
3363   --
3364 
3365     debug_enter(l_proc_name);
3366 
3367       l_ext_rslt_id:= get_current_extract_result;
3368 
3369       IF l_ext_rslt_id <> -1 THEN
3370       --
3371 
3372 
3373         If p_error_number is null Then
3374 
3375           l_error_text:= 'Warning raised in data element '||
3376                            ben_ext_fmt.g_elmt_name||'. '||
3377                          p_error_text;
3378         --if no message token is defined then egt the message from
3379         --ben_ext_fmt.
3380         Elsif p_token1 is null Then
3381 
3382           ben_ext_thread.g_err_num  := p_error_number;
3383           ben_ext_thread.g_err_name := p_error_text;
3384           l_error_text :=
3385             ben_ext_fmt.get_error_msg(fnd_number.canonical_to_number(substr(p_error_text, 5, 5)),
3386               p_error_text,ben_ext_fmt.g_elmt_name);
3387 
3388         -- if any token is defined than replace the tokens in the message.
3389         -- and get the message text from fnd_messages.
3390         Elsif p_token1 is not null Then
3391 
3392         -- set the Tokens in the warning message and then
3393         -- get the warning message from fnd_messages.
3394 
3395           ben_ext_thread.g_err_num  := p_error_number;
3396           ben_ext_thread.g_err_name := p_error_text;
3397 
3398           fnd_message.set_name('BEN',p_error_text);
3399           fnd_message.set_token('TOKEN1',p_token1);
3400           debug('token1 : '||p_token1);
3401           -- this is based on the logic that tokens are passed in order
3402           -- i.e. when 3 tokens are to be used, it will be passed as token1,
3403           -- token2 and token3. Hence, if we find token2 as NULL, we conclude
3404           -- that token3 and token4 are not present.
3405           if p_token2 is not null Then
3406             debug('token2 : '||p_token2);
3407             fnd_message.set_token('TOKEN2',p_token2);
3408             if p_token3 is not null Then
3409               debug('token3 : '||p_token3);
3410               fnd_message.set_token('TOKEN3',p_token3);
3411               if p_token4 is not null Then
3412                 debug('token4 : '||p_token4);
3413                 fnd_message.set_token('TOKEN4',p_token4);
3414               end if;
3415             end if;
3416           end if;
3417 
3418           l_error_text := fnd_message.get ;
3419 
3420         End If;
3421 
3422 
3423         -- for setup related warnings, assignment_id is NULL
3424         -- so raise these warnings independent of person
3425         IF p_assignment_id < 0 -- IS NULL
3426         THEN
3427           --l_person_id := -1; --p_assignment_id ; -- independent of person
3428           l_person_id := p_assignment_id ; -- independent of person
3429         ELSE -- DE related warning
3430           l_person_id:= NVL(get_current_extract_person(p_assignment_id)
3431                        ,ben_ext_person.g_person_id);
3432         END IF;
3433         debug('l_person_id : '||l_person_id, 99);
3434 
3435         IF l_person_id IS NOT NULL THEN
3436         --
3437           ben_ext_util.write_err
3438             (p_err_num           => p_error_number
3439             ,p_err_name          => l_error_text
3440             ,p_typ_cd            => 'W'
3441             ,p_person_id         => l_person_id
3442             ,p_request_id        => fnd_global.conc_request_id
3443             ,p_business_group_id => fnd_global.per_business_group_id
3444             ,p_ext_rslt_id       => get_current_extract_result
3445             );
3446           l_return_value:= 0;  /* All Well ! */
3447         --
3448         ELSE
3449         --
3450           l_return_value:= -3; /* Person not found  */
3451         --
3452         END IF;
3453       --
3454       ELSE
3455       --
3456         l_return_value:= -2; /* No current extract process was found */
3457       --
3458       END IF;
3459 
3460      debug_exit(l_proc_name);
3461   --
3462   RETURN l_return_value;
3463   EXCEPTION
3464     WHEN others THEN
3465         IF SQLCODE <> hr_utility.hr_error_number
3466         THEN
3467             debug_others (l_proc_name, 10);
3468             IF g_debug
3469             THEN
3470               DEBUG (   'Leaving: '
3471                      || l_proc_name, -999);
3472              END IF;
3473              fnd_message.raise_error;
3474          ELSE
3475              RAISE;
3476          END IF;
3477 
3478   END raise_extract_warning;
3479 
3480 
3481 -- ----------------------------------------------------------------------------
3482 -- |------------------------< raise_extract_error >-----------------------|
3483 -- ----------------------------------------------------------------------------
3484 
3485   FUNCTION raise_extract_error
3486     (p_business_group_id IN     NUMBER    DEFAULT g_business_group_id -- context
3487     ,p_assignment_id     IN     NUMBER    DEFAULT g_assignment_id     -- context
3488     ,p_error_text        IN     VARCHAR2
3489     ,p_error_number      IN     NUMBER    DEFAULT NULL
3490     ,p_token1            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3491     ,p_token2            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3492     ,p_token3            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3493     ,p_token4            IN     VARCHAR2  DEFAULT NULL  --added to pass tokens to messages.
3494     ) RETURN NUMBER
3495   IS
3496 
3497       l_proc_name           VARCHAR2(61):=
3498      g_proc_name||'raise_extract_error';
3499 
3500      l_ext_rslt_id   NUMBER;
3501      l_person_id     NUMBER;
3502      l_error_text    VARCHAR2(2000);
3503      l_error_message VARCHAR2(2000);
3504      l_return_value  NUMBER:= 0;
3505      l_err_typ_cd    VARCHAR2(1) := NULL;
3506 
3507   BEGIN
3508 
3509   debug_enter(l_proc_name);
3510   --
3511     IF p_business_group_id is not null THEN
3512     --
3513       debug('p_business_group_id is not null');
3514       l_ext_rslt_id:= get_current_extract_result;
3515       IF l_ext_rslt_id <> -1 THEN
3516       --
3517 
3518         If p_error_number is null Then
3519 
3520           l_error_text:= 'Error raised in data element '||
3521                           NVL(ben_ext_person.g_elmt_name,ben_ext_fmt.g_elmt_name)||'. '||
3522                          p_error_text;
3523 
3524 
3525             Elsif p_token1 is null Then
3526 
3527           debug('p_token1 is null');
3528           ben_ext_thread.g_err_num  := p_error_number;
3529           ben_ext_thread.g_err_name := p_error_text;
3530           l_error_text :=
3531             ben_ext_fmt.get_error_msg(fnd_number.canonical_to_number(substr(p_error_text, 5, 5)),
3532               p_error_text,ben_ext_fmt.g_elmt_name);
3533 
3534         -- if any token is defined than replace the tokens in the message.
3535         -- and get the message text from fnd_messages.
3536         Elsif p_token1 is not null Then
3537 
3538         -- set the Tokens in the warning message and then
3539         -- get the warning message from fnd_messages.
3540 
3541           ben_ext_thread.g_err_num  := p_error_number;
3542           ben_ext_thread.g_err_name := p_error_text;
3543 
3544           fnd_message.set_name('BEN',p_error_text);
3545           fnd_message.set_token('TOKEN1',p_token1);
3546 
3547           if p_token2 is not null Then
3548             debug('token2 : '||p_token2);
3549             fnd_message.set_token('TOKEN2',p_token2);
3550             if p_token3 is not null Then
3551               debug('token3 : '||p_token3);
3552               fnd_message.set_token('TOKEN3',p_token3);
3553               if p_token4 is not null Then
3554                 debug('token4 : '||p_token4);
3555                 fnd_message.set_token('TOKEN4',p_token4);
3556               end if;
3557             end if;
3558           end if;
3559 
3560           l_error_text := fnd_message.get ;
3561 
3562         End If; -- End if of error number is null check ...
3563 
3564         -- for setup related errors, assignment_id is NULL
3565         -- so raise these errors independent of person
3566         IF p_assignment_id < 0 -- IS NULL (setup error)
3567         THEN
3568           --l_person_id := -1; --p_assignment_id ; -- independent of person
3569           l_person_id  := p_assignment_id ; -- independent of person
3570           -- 115.10
3571           l_err_typ_cd := 'F'; -- all setup errors are fatal
3572         ELSE -- DE related error
3573           l_person_id  := NVL(get_current_extract_person(p_assignment_id)
3574                           ,ben_ext_person.g_person_id);
3575           -- 115.10
3576           l_err_typ_cd := 'E'; -- all data element related errors are 'E'
3577         END IF;
3578         debug('l_person_id : '||l_person_id, 99);
3579 
3580           ben_ext_util.write_err
3581             (p_err_num           => p_error_number
3582             ,p_err_name          => l_error_text
3583             ,p_typ_cd            => l_err_typ_cd -- 'F'
3584             ,p_person_id         => l_person_id
3585             ,p_request_id        => fnd_global.conc_request_id
3586             ,p_business_group_id => p_business_group_id
3587             ,p_ext_rslt_id       => get_current_extract_result
3588             );
3589 
3590           --commit;
3591 
3592           --raise ben_ext_thread.g_job_failure_error;
3593           l_return_value:= 0;  /* All Well ! */
3594       --
3595       ELSE
3596       --
3597         l_return_value:= -2; /* No current extract process was found */
3598       --
3599       END IF;
3600     --
3601     ELSE
3602     --
3603       l_return_value := -1; /* Cannot raise warnings against header/trailers */
3604     --
3605     END IF;
3606   --
3607 
3608   debug_exit(l_proc_name);
3609 
3610   RETURN l_return_value;
3611     EXCEPTION
3612     WHEN others THEN
3613         IF SQLCODE <> hr_utility.hr_error_number
3614         THEN
3615             debug_others (l_proc_name, 10);
3616             IF g_debug
3617             THEN
3618               DEBUG (   'Leaving: '
3619                      || l_proc_name, -999);
3620              END IF;
3621              fnd_message.raise_error;
3622          ELSE
3623              RAISE;
3624          END IF;
3625 
3626   END raise_extract_error;
3627 
3628 
3629 -- ----------------------------------------------------------------------------
3630 -- |------------------------< store_extract_exceptions >-----------------------|
3631 -- ----------------------------------------------------------------------------
3632 
3633   PROCEDURE store_extract_exceptions
3634            (-- pass <interface_name> / 'DE' to indicate
3635             -- the level at which error/warning has been raised
3636             -- (1) <interface_name> (eg BASIC_DATA) = interface setup exceptions
3637             -- (2) DE = person/data element level
3638             p_extract_type        IN VARCHAR2 -- <interface_name>/'DE'
3639            ,p_error_number        IN NUMBER
3640            ,p_error_text          IN VARCHAR2
3641            ,p_token1              IN VARCHAR2 DEFAULT NULL
3642            ,p_token2              IN VARCHAR2 DEFAULT NULL
3643            ,p_token3              IN VARCHAR2 DEFAULT NULL
3644            ,p_token4              IN VARCHAR2 DEFAULT NULL
3645            ,p_error_warning_flag  IN VARCHAR2 -- E (error) / W (warning)
3646            )
3647   IS
3648   --
3649     l_proc_name           VARCHAR2(61):=
3650      g_proc_name||'store_extract_exceptions';
3651 
3652     l_error_index               NUMBER;
3653     l_warning_index             NUMBER;
3654 
3655   --
3656   BEGIN
3657 
3658   debug_enter(l_proc_name);
3659 
3660   l_error_index := 0;
3661   l_warning_index := 0;
3662 
3663   debug('g_errors.COUNT : '|| g_errors.COUNT);
3664   debug('g_warnings.COUNT : '|| g_warnings.COUNT);
3665 
3666 
3667   IF   p_error_warning_flag = 'e'
3668     OR p_error_warning_flag = 'E'
3669   THEN -- enter a new record in errors table
3670     l_error_index           := g_errors.COUNT;
3671 
3672     g_errors(l_error_index + 1).extract_type  := p_extract_type;
3673     g_errors(l_error_index + 1).error_number  := p_error_number;
3674     g_errors(l_error_index + 1).error_text    := p_error_text;
3675     g_errors(l_error_index + 1).token1        := p_token1;
3676     g_errors(l_error_index + 1).token2        := p_token2;
3677     g_errors(l_error_index + 1).token3        := p_token3;
3678     g_errors(l_error_index + 1).token4        := p_token4;
3679 
3680     -- assignment_id need to be set for DE level errors
3681     IF p_extract_type = 'DE' THEN
3682       g_errors(l_error_index + 1).assignment_id := g_assignment_id;
3683     ELSE
3684        --g_errors(l_error_index + 1).assignment_id := NULL;
3685        g_errors(l_error_index + 1).assignment_id := -(l_error_index+1);
3686     END IF;
3687 
3688     -- store extract result ID for cases of multiple parallel extracts run
3689     g_errors(l_error_index + 1).ext_rslt_id     := ben_ext_thread.g_ext_rslt_id;
3690 
3691     -- debug
3692     --=================================
3693     debug('g_errors('||(l_error_index + 1)||').extract_type : '|| g_errors(l_error_index + 1).extract_type);
3694     debug('g_errors('||(l_error_index + 1)||').error_number : '|| g_errors(l_error_index + 1).error_number);
3695     debug('g_errors('||(l_error_index + 1)||').error_text : '|| g_errors(l_error_index + 1).error_text);
3696     debug('g_errors('||(l_error_index + 1)||').token1 : '|| g_errors(l_error_index + 1).token1);
3697     debug('g_errors('||(l_error_index + 1)||').token2 : '|| g_errors(l_error_index + 1).token2);
3698     debug('g_errors('||(l_error_index + 1)||').token3 : '|| g_errors(l_error_index + 1).token3);
3699     debug('g_errors('||(l_error_index + 1)||').token4 : '|| g_errors(l_error_index + 1).token4);
3700     debug('g_errors('||(l_error_index + 1)||').assignment_id : '|| g_errors(l_error_index + 1).assignment_id);
3701     debug('g_errors('||(l_error_index + 1)||').ext_rslt_id : '|| g_errors(l_error_index + 1).ext_rslt_id);
3702     --=================================
3703 
3704   ELSE -- enter a new record in the warnings table
3705 
3706     l_warning_index           := g_warnings.COUNT;
3707 
3708     g_warnings(l_warning_index + 1).extract_type := p_extract_type;
3709     g_warnings(l_warning_index + 1).error_number := p_error_number;
3710     g_warnings(l_warning_index + 1).error_text   := p_error_text;
3711     g_warnings(l_warning_index + 1).token1       := p_token1;
3712     g_warnings(l_warning_index + 1).token2       := p_token2;
3713     g_warnings(l_warning_index + 1).token3       := p_token3;
3714     g_warnings(l_warning_index + 1).token4       := p_token4;
3715 
3716     -- assignment_id need to be set for DE level errors
3717     IF p_extract_type = 'DE' THEN
3718       g_warnings(l_warning_index + 1).assignment_id := g_assignment_id;
3719     ELSE
3720       --g_warnings(l_warning_index + 1).assignment_id := NULL;
3721       g_warnings(l_warning_index + 1).assignment_id :=  -(l_warning_index+1);
3722     END IF;
3723 
3724     -- store extract result ID for cases of multiple parallel extracts run
3725     g_warnings(l_warning_index + 1).ext_rslt_id     := ben_ext_thread.g_ext_rslt_id;
3726 
3727 
3728     -- debug
3729     --=================================
3730     debug('g_warnings('||(l_warning_index + 1)||').extract_type : '|| g_warnings(l_warning_index + 1).extract_type);
3731     debug('g_warnings('||(l_warning_index + 1)||').error_number : '|| g_warnings(l_warning_index + 1).error_number);
3732     debug('g_warnings('||(l_warning_index + 1)||').error_text : '|| g_warnings(l_warning_index + 1).error_text);
3733     debug('g_warnings('||(l_warning_index + 1)||').token1 : '|| g_warnings(l_warning_index + 1).token1);
3734     debug('g_warnings('||(l_warning_index + 1)||').token2 : '|| g_warnings(l_warning_index + 1).token2);
3735     debug('g_warnings('||(l_warning_index + 1)||').token3 : '|| g_warnings(l_warning_index + 1).token3);
3736     debug('g_warnings('||(l_warning_index + 1)||').token4 : '|| g_warnings(l_warning_index + 1).token4);
3737     debug('g_warnings('||(l_warning_index + 1)||').assignment_id : '|| g_warnings(l_warning_index + 1).assignment_id);
3738     debug('g_warnings('||(l_warning_index + 1)||').ext_rslt_id : '|| g_warnings(l_warning_index + 1).ext_rslt_id);
3739     --=================================
3740 
3741   END IF;
3742 
3743   --
3744 
3745   debug_exit(l_proc_name);
3746 
3747   EXCEPTION
3748     WHEN others THEN
3749         IF SQLCODE <> hr_utility.hr_error_number
3750         THEN
3751             debug_others (l_proc_name, 10);
3752             IF g_debug
3753             THEN
3754               DEBUG (   'Leaving: '
3755                      || l_proc_name, -999);
3756              END IF;
3757              fnd_message.raise_error;
3758          ELSE
3759              RAISE;
3760          END IF;
3761 
3762   END store_extract_exceptions;
3763 
3764 
3765 
3766 -- ----------------------------------------------------------------------------
3767 -- |------------------------< raise_extract_exceptions >-----------------------|
3768 -- ----------------------------------------------------------------------------
3769 
3770 -- (1) pass <interface_name> as parameter to raise setup related errors/warnings that were
3771 -- stored during set_shared_globals and set_extract_globals
3772 -- (2) Dont pass any parameter,data element level errors/warnings will be raised
3773   PROCEDURE raise_extract_exceptions
3774            (p_extract_type        IN VARCHAR2 DEFAULT 'DE'
3775            )
3776   IS
3777   --
3778     l_proc_name           VARCHAR2(61):=
3779      g_proc_name||'raise_extract_exceptions';
3780 
3781     l_index               NUMBER;
3782     l_value               NUMBER;
3783     l_fatal_error_flag    VARCHAR2(1) := 'N';
3784   --
3785   BEGIN
3786 
3787   debug_enter(l_proc_name);
3788 
3789   l_index := 0;
3790 
3791   -- this flag is to track whether one of the errors raised were a fatal error
3792   l_fatal_error_flag := 'N';
3793 
3794   FOR i IN 1..g_errors.COUNT
3795   LOOP
3796 
3797     -- IF error_type = DE and g_errors has assignment_id, raise
3798     -- OR
3799     -- IF error_type = SETUP and g_errors doesnt have assignment_id, raise
3800     -- all DE errors will have g_error.assignment_id,
3801     -- all setup errors will have g_error.assignment_id = NULL
3802     debug('This is the loop for raising errors - ',20);
3803 
3804 
3805     -- setting the index
3806     IF i=1 THEN
3807       l_index:=g_errors.FIRST;
3808     ELSE
3809       l_index:=g_errors.NEXT(l_index);
3810     END IF;
3811 
3812     debug('l_index : ' || l_index,25);
3813       -- debug
3814       --=================================
3815       debug('g_errors('||(l_index)||').extract_type : '|| g_errors(l_index).extract_type);
3816       debug('g_errors('||(l_index)||').error_number : '|| g_errors(l_index).error_number);
3817       debug('g_errors('||(l_index)||').error_text : '|| g_errors(l_index).error_text);
3818       debug('g_errors('||(l_index)||').token1 : '|| g_errors(l_index).token1);
3819       debug('g_errors('||(l_index)||').token2 : '|| g_errors(l_index).token2);
3820       debug('g_errors('||(l_index)||').token3 : '|| g_errors(l_index).token3);
3821       debug('g_errors('||(l_index)||').token4 : '|| g_errors(l_index).token4);
3822       debug('g_errors('||(l_index)||').assignment_id : '|| g_errors(l_index).assignment_id);
3823       debug('g_errors('||(l_index)||').ext_rslt_id : '|| g_errors(l_index).ext_rslt_id);
3824       --=================================
3825 
3826     -- check error type
3827     IF (
3828         (p_extract_type = 'DE'
3829         and
3830         g_errors(l_index).assignment_id  > 0 -- IS NOT NULL
3831         )
3832         or
3833         (p_extract_type <> 'DE'
3834         and
3835         g_errors(l_index).assignment_id  < 0 --  IS NULL
3836         )
3837        )
3838        and
3839         g_errors(l_index).ext_rslt_id = ben_ext_thread.g_ext_rslt_id
3840 
3841 
3842     THEN
3843       debug('This error qualified to be raised - ',30);
3844 
3845       l_value:=
3846         raise_extract_error
3847           (p_business_group_id => g_business_group_id
3848           ,p_assignment_id     => g_errors(l_index).assignment_id
3849           ,p_error_text        => g_errors(l_index).error_text
3850           ,p_error_number      => g_errors(l_index).error_number
3851           ,p_token1            => g_errors(l_index).token1
3852           ,p_token2            => g_errors(l_index).token2
3853           ,p_token3            => g_errors(l_index).token3
3854           ,p_token4            => g_errors(l_index).token4
3855           );
3856 
3857       -- delete this record as this error has already been reported above
3858       g_errors.DELETE(l_index);
3859 
3860       -- setting flag to error out extract in case the error
3861       -- raised was of setup type
3862       IF p_extract_type <> 'DE' and l_fatal_error_flag = 'N'
3863       THEN
3864         l_fatal_error_flag := 'Y';
3865       END IF;
3866 
3867     ELSE
3868       debug('This error was NOT raised - ',30);
3869       debug('p_extract_type : ' || p_extract_type);
3870       debug('g_errors('||l_index||').assignment_id : ' || g_errors(l_index).assignment_id);
3871 
3872     END IF;
3873   END LOOP;
3874 
3875 
3876   FOR i IN 1..g_warnings.COUNT
3877   LOOP
3878     -- IF error_type = DE and g_errors has assignment_id, raise
3879     -- OR
3880     -- IF error_type = SETUP and g_errors doesnt have assignment_id, raise
3881     -- all DE errors will have g_error.assignment_id,
3882     -- all setup errors will have g_error.assignment_id = NULL
3883 
3884     debug('This is the loop for raising warnings - ',20);
3885 
3886 
3887     -- setting the index
3888     IF i=1 THEN
3889       l_index:=g_warnings.FIRST;
3890     ELSE
3891       l_index:=g_warnings.NEXT(l_index);
3892     END IF;
3893 
3894     -- debug
3895     --=================================
3896     debug('g_warnings('||(l_index)||').extract_type : '|| g_warnings(l_index).extract_type);
3897     debug('g_warnings('||(l_index)||').error_number : '|| g_warnings(l_index).error_number);
3898     debug('g_warnings('||(l_index)||').error_text : '|| g_warnings(l_index).error_text);
3899     debug('g_warnings('||(l_index)||').token1 : '|| g_warnings(l_index).token1);
3900     debug('g_warnings('||(l_index)||').token2 : '|| g_warnings(l_index).token2);
3901     debug('g_warnings('||(l_index)||').token3 : '|| g_warnings(l_index).token3);
3902     debug('g_warnings('||(l_index)||').token4 : '|| g_warnings(l_index).token4);
3903     debug('g_warnings('||(l_index)||').assignment_id : '|| g_warnings(l_index).assignment_id);
3904     debug('g_warnings('||(l_index)||').ext_rslt_id : '|| g_warnings(l_index).ext_rslt_id);
3905     --=================================
3906 
3907     -- check warning type
3908     IF (
3909         (p_extract_type = 'DE'
3910         and
3911         g_warnings(l_index).assignment_id  > 0 -- IS NOT NULL
3912         )
3913         or
3914         (p_extract_type <> 'DE'
3915         and
3916         g_warnings(l_index).assignment_id  < 0 -- IS NULL
3917         )
3918        )
3919        and
3920         g_warnings(l_index).ext_rslt_id = ben_ext_thread.g_ext_rslt_id
3921 
3922     THEN
3923       debug('This warning qualified to be raised - ',30);
3924 
3925       l_value:=
3926         raise_extract_warning
3927           (p_assignment_id     => g_warnings(l_index).assignment_id
3928           ,p_error_text        => g_warnings(l_index).error_text
3929           ,p_error_number      => g_warnings(l_index).error_number
3930           ,p_token1            => g_warnings(l_index).token1
3931           ,p_token2            => g_warnings(l_index).token2
3932           ,p_token3            => g_warnings(l_index).token3
3933           ,p_token4            => g_warnings(l_index).token4
3934           );
3935 
3936         -- delete this record as this warning has already been reported above
3937         g_warnings.DELETE(l_index);
3938 
3939     ELSE
3940       debug('This warning was NOT raised - ',30);
3941     END IF;
3942 
3943   END LOOP;
3944 
3945 
3946   -- fail extract if fatal errors were there
3947   IF l_fatal_error_flag = 'Y'
3948   THEN
3949     commit;
3950 
3951     raise ben_ext_thread.g_job_failure_error;
3952   END IF;
3953 
3954   debug_exit(l_proc_name);
3955 
3956   EXCEPTION
3957     WHEN others THEN
3958         IF SQLCODE <> hr_utility.hr_error_number
3959         THEN
3960             debug_others (l_proc_name, 10);
3961             IF g_debug
3962             THEN
3963               DEBUG (   'Leaving: '
3964                      || l_proc_name, -999);
3965              END IF;
3966              fnd_message.raise_error;
3967          ELSE
3968              RAISE;
3969          END IF;
3970 
3971   END raise_extract_exceptions;
3972 
3973 
3974 -- ----------------------------------------------------------------------------
3975 -- |------------------------< set_shared_globals >-----------------------------------|
3976 -- ----------------------------------------------------------------------------
3977   PROCEDURE set_shared_globals
3978     (p_business_group_id        IN      NUMBER
3979     ,p_paypoint                 OUT NOCOPY VARCHAR2
3980     ,p_cutover_date             OUT NOCOPY VARCHAR2
3981     ,p_ext_dfn_id               OUT NOCOPY NUMBER
3982     )
3983   IS
3984   --
3985     l_proc_name           VARCHAR2(61):=
3986      g_proc_name||'set_shared_globals';
3987 
3988 
3989     l_paypoint                VARCHAR2(5)   := NULL;
3990     l_cutover_date            DATE;
3991     l_ext_dfn_id              NUMBER;
3992     l_config_value            pqp_utilities.t_config_values;
3993   --
3994   BEGIN
3995 
3996 
3997   g_debug         :=  pqp_gb_psi_functions.check_debug(p_business_group_id);
3998 
3999   debug_enter(l_proc_name);
4000 
4001 --  fnd_file.put_line(fnd_file.log, l_proc_name || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
4002   fnd_file.put_line(fnd_file.log, l_proc_name || ' : ' || get_time);
4003 
4004 
4005     debug('Entering set_shared_globals ...',10);
4006     debug ('p_business_group_id:'||p_business_group_id);
4007 
4008     g_business_group_id := p_business_group_id;
4009 
4010 
4011     -- paypoint
4012     p_paypoint := paypoint(p_business_group_id);
4013     debug('p_paypoint : ' || p_paypoint, 30);
4014     -- check if paypoint is present or valid
4015     IF p_paypoint = ''
4016        or
4017        p_paypoint IS NULL
4018        or
4019        NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> p_paypoint)
4020     THEN
4021       -- error
4022       PQP_GB_PSI_FUNCTIONS.store_extract_exceptions
4023                    (p_extract_type        =>    'Pay Point'
4024                    ,p_error_number        =>    94453
4025                    ,p_error_text          =>    'BEN_94453_INV_PAYPOINT'
4026                    ,p_error_warning_flag  =>    'E'
4027                    );
4028     END IF;
4029 
4030     -- fetch configuration value for cutover date
4031     debug('Fetching configuration value for cutover date ...', 40);
4032       pqp_utilities.get_config_type_values
4033                    ( p_configuration_type   => 'PQP_GB_PENSERVER_PAYPOINT_INFO' --'PQP_GB_PENSERVER_CUTOVER_DATE'
4034                                 ,p_business_group_id    => p_business_group_id
4035                                 ,p_legislation_code     => NULL
4036                                 ,p_tab_config_values    => l_config_value
4037                      );
4038       --ERR : no configuration value found ???
4039       --debug('ERROR!!! : no configuration value found for cutover date', 50);
4040       IF l_config_value.COUNT > 0 -- config value found
4041       THEN
4042         p_cutover_date := to_date(substr(l_config_value(l_config_value.FIRST).pcv_information2,1,10),'YYYY/MM/DD');
4043         debug('p_cutover_date : ' || p_cutover_date, 50);
4044       ELSE
4045         p_cutover_date := NULL;
4046       END IF;
4047 
4048       -- store in a global
4049       g_cutover_date := p_cutover_date;
4050 
4051     -- extract definition ID
4052       p_ext_dfn_id := ben_ext_thread.g_ext_dfn_id;
4053       debug('p_ext_dfn_id : ' || p_ext_dfn_id, 60);
4054 
4055 
4056     -- fetch configuration value for employment type mapping
4057     debug('Fetching configuration value for employment type mapping ...', 65);
4058 
4059       pqp_utilities.get_config_type_values
4060              ( p_configuration_type   => 'PQP_GB_PENSERVER_EMPLYMT_TYPE'
4061               ,p_business_group_id    => p_business_group_id
4062               ,p_legislation_code     => NULL
4063               ,p_tab_config_values    => g_assign_category_mapping --caching in global
4064                                                                    -- for future use
4065              );
4066       debug('g_assign_category_mapping has been populated !',66);
4067 
4068 
4069       -- fetch configuration value for pension scheme mapping
4070       debug('Fetching configuration value for pension scheme mapping ...', 65);
4071 
4072       pqp_utilities.get_config_type_values
4073              ( p_configuration_type   => 'PQP_GB_PENSERV_SCHEME_MAP_INFO'
4074               ,p_business_group_id    => p_business_group_id
4075               ,p_legislation_code     => NULL
4076               ,p_tab_config_values    => g_pension_scheme_mapping --caching in global
4077                                                                   -- for future use
4078              );
4079       debug('g_pension_scheme_mapping has been populated !',66);
4080 
4081 
4082   debug('Exiting set_shared_globals ...',70);
4083   debug_exit(l_proc_name);
4084 
4085   EXCEPTION
4086     WHEN others THEN
4087         IF SQLCODE <> hr_utility.hr_error_number
4088         THEN
4089             debug_others (l_proc_name, 10);
4090             IF g_debug
4091             THEN
4092               DEBUG (   'Leaving: '
4093                      || l_proc_name, -999);
4094              END IF;
4095              fnd_message.raise_error;
4096          ELSE
4097              RAISE;
4098          END IF;
4099 
4100   END set_shared_globals;
4101 
4102 
4103 --
4104 -- modified as part of 115.58 (5)
4105 --
4106 -- ----------------------------------------------------------------------------
4107 -- |------------------------< check_employee_pension_scheme >-------------------|
4108 -- ----------------------------------------------------------------------------
4109 FUNCTION check_employee_pension_scheme
4110       (p_business_group_id       IN NUMBER
4111       ,p_effective_date          IN DATE
4112       ,p_assignment_id           IN NUMBER
4113       ,p_psi_pension_scheme      IN VARCHAR2
4114       ,p_pension_element_type_id OUT NOCOPY NUMBER
4115       )  RETURN VARCHAR2 -- Y or N
4116 IS
4117   --
4118 
4119     l_proc_name           VARCHAR2(61):=
4120      g_proc_name||'check_employee_pension_scheme';
4121 
4122     l_return              VARCHAR2(1) := 'N';
4123     l_config_value        pqp_utilities.t_config_values;
4124     l_index               NUMBER;
4125     l_element_type_id     NUMBER := NULL;
4126 
4127 BEGIN
4128   debug_enter(l_proc_name);
4129     debug ('p_business_group_id:'||p_business_group_id);
4130     debug ('p_effective_date:'||p_effective_date);
4131     debug ('p_assignment_id:'||p_assignment_id);
4132 
4133       -- search thru the mapping for this assignment category
4134       FOR i IN 1..g_pension_scheme_mapping.COUNT
4135       LOOP
4136 
4137         IF i=1 THEN -- finding next index
4138           l_index:=g_pension_scheme_mapping.FIRST;
4139         ELSE
4140           l_index:=g_pension_scheme_mapping.NEXT(l_index);
4141         END IF;
4142 
4143         debug('g_pension_scheme_mapping('||l_index||').pcv_information1 : '
4144                       || g_pension_scheme_mapping(l_index).pcv_information1);
4145         debug('g_pension_scheme_mapping('||l_index||').pcv_information2 : '
4146                       || g_pension_scheme_mapping(l_index).pcv_information2);
4147 
4148         -- start comparing
4149         --IF g_pension_scheme_mapping(l_index).pcv_information2 = 'PARTNER' -- match found!!
4150         IF g_pension_scheme_mapping(l_index).pcv_information2 = p_psi_pension_scheme -- match found!!
4151         THEN
4152           l_element_type_id := g_pension_scheme_mapping(l_index).pcv_information1;
4153 
4154           debug('l_element_type_id : '|| l_element_type_id,65);
4155           debug('g_pension_scheme_mapping('||l_index||').pcv_information1 : '
4156                       || g_pension_scheme_mapping(l_index).pcv_information1,66);
4157           debug('g_pension_scheme_mapping('||l_index||').pcv_information2 : '
4158                       || g_pension_scheme_mapping(l_index).pcv_information2,66);
4159 
4160           debug('match found! Need to check presence on assignment ',67);
4161 
4162             -- now check for presence of this element_type_id on assignment
4163             debug('now checking for scheme membership for '||p_psi_pension_scheme||'...',70);
4164             -- open cursor
4165             OPEN csr_partnership_scheme_flag
4166                  (p_business_group_id  => p_business_group_id
4167                  ,p_effective_date     => p_effective_date
4168                  ,p_assignment_id      => p_assignment_id
4169                  ,p_element_type_id    => l_element_type_id
4170                  );
4171             FETCH csr_partnership_scheme_flag into l_return;
4172                   IF csr_partnership_scheme_flag%FOUND THEN
4173                     l_return := 'Y';
4174                     debug('l_return : ' || l_return,75);
4175                     CLOSE csr_partnership_scheme_flag;
4176                     EXIT; -- match found, exit the FOR loop
4177                   ELSE
4178                     l_return := 'N';
4179                     debug('l_return : ' || l_return,76);
4180                   END IF;
4181             CLOSE csr_partnership_scheme_flag;
4182             --
4183 
4184         ELSE
4185           -- ERR - no matching employment category
4186           debug('Not a match !!',70);
4187         END IF;
4188 
4189       END LOOP; -- end of FOR loop
4190 
4191 
4192     -- out parameter of this pension scheme
4193     p_pension_element_type_id := l_element_type_id;
4194 
4195     debug_exit(l_proc_name);
4196   return l_return;
4197 
4198   EXCEPTION
4199     WHEN others THEN
4200         IF SQLCODE <> hr_utility.hr_error_number
4201         THEN
4202             debug_others (l_proc_name, 10);
4203             IF g_debug
4204             THEN
4205               DEBUG (   'Leaving: '
4206                      || l_proc_name, -999);
4207              END IF;
4208              fnd_message.raise_error;
4209          ELSE
4210              RAISE;
4211          END IF;
4212 
4213 END check_employee_pension_scheme;
4214 
4215 
4216 -- ----------------------------------------------------------------------------
4217 -- |------------------------< check_employee_eligibility >-------------------|
4218 -- ----------------------------------------------------------------------------
4219 FUNCTION check_employee_eligibility
4220               (p_business_group_id       IN NUMBER
4221               ,p_assignment_id           IN NUMBER
4222               ,p_effective_date          IN DATE
4223               ,p_chg_value               OUT NOCOPY VARCHAR2 -- the scheme name entered.
4224               )  RETURN VARCHAR2 -- Y or N
4225 IS
4226   --
4227     l_proc_name  VARCHAR2(61):= g_proc_name||'check_employee_eligibility';
4228     l_return              VARCHAR2(1) := 'Y';
4229     l_config_values         PQP_UTILITIES.t_config_values;
4230 
4231     l_query   VARCHAR2(1000);
4232     TYPE base_table_ref_csr_typ IS REF CURSOR;
4233     c_base_table        base_table_ref_csr_typ;
4234 
4235 BEGIN
4236   debug_enter(l_proc_name);
4237   debug('p_business_group_id: '||p_business_group_id,10);
4238   debug('p_effective_date: '||p_effective_date,10);
4239   debug('p_assignment_id: '||p_assignment_id,10);
4240 
4241   IF g_asg_membership_col IS NULL THEN
4242       -- fetch the value if g_asg_membership_col is null
4243       debug('Fetch the column name for the first time.',30);
4244       PQP_UTILITIES.get_config_type_values(
4245                      p_configuration_type   =>    'PQP_GB_PENSERVER_ELIGBLTY_CONF'
4246                     ,p_business_group_id    =>    g_business_group_id
4247                     ,p_legislation_code     =>    g_legislation_code
4248                     ,p_tab_config_values    =>    l_config_values
4249                   );
4250       IF l_config_values.COUNT > 0 THEN
4251           g_asg_membership_context  :=  l_config_values(l_config_values.FIRST).pcv_information1;
4252           g_asg_membership_col      :=  l_config_values(l_config_values.FIRST).pcv_information2;
4253       ELSE
4254           -- no configuration value
4255           -- riase errorr
4256           debug('ERROR: No configuration for the eligibility column',20);
4257           store_extract_exceptions
4258                  (p_extract_type        =>    'Employee Eligibility'
4259                  ,p_error_number        =>    93917
4260                  ,p_error_text          =>    'BEN_93917_NO_PEN_ELIGBLTY_CONF'
4261                  ,p_error_warning_flag  =>    'E'
4262                  );
4263       END IF;
4264   END IF;
4265 
4266   IF g_asg_membership_col IS NOT NULL THEN
4267       debug('g_asg_membership_col: '||g_asg_membership_col,40);
4268       /*l_query :=  'select '||g_asg_membership_col||'
4269                    from per_all_assignments_f '||
4270                    'where business_group_id = '||p_business_group_id||' '||
4271                    'and assignment_id = '||p_assignment_id||' '||
4272                    'and ASS_ATTRIBUTE_CATEGORY = '||''''||g_asg_membership_context||''''||
4273                    'and to_date('||''''||TO_CHAR(p_effective_date,'dd/mm/yyyy')||''''||
4274                    ',''dd/mm/yyyy'')'||' between effective_start_date '||
4275                                          'and effective_end_date';*/
4276          /* commented to use bind variable instead of parameter */
4277      /* l_query :=   'select '||g_asg_membership_col||' '||
4278                    'from per_all_assignments_f '||' '||
4279                    'where business_group_id = '||p_business_group_id||' '||
4280                    'and assignment_id = '||p_assignment_id||' ';
4281       IF g_asg_membership_context <> 'Global Data Elements' THEN
4282             l_query := l_query||
4283                   'and ASS_ATTRIBUTE_CATEGORY = '''||g_asg_membership_context||''' ';
4284       END IF;
4285 
4286       l_query := l_query||
4287                 'and to_date('||''''||TO_CHAR(p_effective_date,'dd/mm/yyyy')||''''||
4288                 ',''dd/mm/yyyy'')'||' between effective_start_date '||
4289                                    'and effective_end_date';
4290       debug('l_query: '||l_query,30);
4291       -- fetch the value of from the column name
4292       OPEN c_base_table FOR l_query; */
4293 
4294        l_query :=  'select '||g_asg_membership_col||' '||'from per_all_assignments_f '||' '||
4295                    'where business_group_id = :p_business_group_id '||
4296                    'and assignment_id = :p_assignment_id '||
4297                    'and :p_effective_date between effective_start_date and effective_end_date ';
4298 
4299       IF g_asg_membership_context <> 'Global Data Elements'
4300       THEN
4301         l_query := l_query || ' and ASS_ATTRIBUTE_CATEGORY = :g_asg_membership_context';
4302       END IF;
4303 
4304       IF g_asg_membership_context <> 'Global Data Elements'
4305       THEN
4306 
4307          OPEN c_base_table FOR l_query using p_business_group_id,p_assignment_id,p_effective_date,g_asg_membership_context;
4308 
4309       ELSE
4310 
4311          OPEN c_base_table FOR l_query using p_business_group_id,p_assignment_id,p_effective_date;
4312 
4313       END IF;
4314 
4315       FETCH c_base_table INTO p_chg_value;
4316       CLOSE c_base_table;
4317       debug('l_assg_membership_value: '||p_chg_value,30);
4318 
4319       IF p_chg_value IS NULL THEN
4320           l_return  :=  'N';
4321           debug('l_return: '||l_return,40);
4322       END IF;
4323   END IF;
4324 
4325 
4326 
4327   debug('l_return: '||l_return,10);
4328   debug_exit(l_proc_name);
4329   return l_return;
4330 
4331   EXCEPTION
4332     WHEN others THEN
4333         IF SQLCODE <> hr_utility.hr_error_number
4334         THEN
4335             debug_others (l_proc_name, 10);
4336             IF g_debug
4337             THEN
4338               DEBUG (   'Leaving: '
4339                      || l_proc_name, -999);
4340              END IF;
4341              fnd_message.raise_error;
4342          ELSE
4343              RAISE;
4344          END IF;
4345 
4346 END check_employee_eligibility;
4347 
4348 -- ----------------------------------------------------------------------------
4349 -- |------------------------< chk_penserver_basic_criteria >-------------------|
4350 -- ----------------------------------------------------------------------------
4351   FUNCTION chk_penserver_basic_criteria
4352     (p_business_group_id        IN      NUMBER
4353     ,p_effective_date           IN      DATE
4354     ,p_assignment_id            IN      NUMBER
4355     ,p_person_dtl               OUT NOCOPY per_all_people_f%rowtype
4356     ,p_assignment_dtl           OUT NOCOPY per_all_assignments_f%rowtype
4357     ) RETURN VARCHAR2 -- Y or N
4358   IS
4359 
4360   --
4361 
4362     l_proc_name           VARCHAR2(61):=
4363      g_proc_name||'chk_penserver_basic_criteria';
4364 
4365     l_inclusion_flag            VARCHAR2(1) := 'Y';
4366     l_assignment_category       VARCHAR2(30):= NULL;
4367     l_last_hire_date_indicator  VARCHAR2(1) := NULL;
4368     l_person_id                 NUMBER;
4369 
4370     l_person_dtl                per_all_people_f%rowtype;
4371     l_assignment_dtl            per_all_assignments_f%rowtype;
4372     i                           NUMBER;
4373     l_index                     NUMBER;
4374     l_value                     NUMBER;
4375     l_pension_element_type_id   NUMBER;
4376 
4377 
4378   --
4379 
4380   BEGIN
4381 
4382   debug_enter(l_proc_name);
4383 
4384   IF (g_count = 0) THEN
4385 --    fnd_file.put_line(fnd_file.log, l_proc_name || to_char(SYSDATE,'dd-Mon-yyyy hh:mm:ss am'));
4386     fnd_file.put_line(fnd_file.log, l_proc_name || ' : ' || get_time);
4387     g_count := 1;
4388   END IF;
4389 
4390 
4391 
4392     debug ('p_business_group_id:'||p_business_group_id);
4393     debug ('p_effective_date:'||p_effective_date);
4394     debug ('p_assignment_id:'||p_assignment_id);
4395 
4396     debug ('g_extract_type:'||g_extract_type);
4397     debug ('g_dfn_name:'||g_dfn_name);
4398 
4399 --for PF
4400     IF (g_prev_assignment_id = p_assignment_id
4401         AND
4402         g_prev_effective_date = p_effective_date)
4403     THEN
4404       l_inclusion_flag := g_prev_inclusion_flag;
4405       p_assignment_dtl := g_assignment_dtl;
4406       p_person_dtl     := g_person_dtl;
4407 
4408       return l_inclusion_flag;
4409     END IF;
4410 --for PF
4411 
4412 
4413     -- 115.60
4414     -- for cutover extracts and basic data
4415     -- pick person only till actual termination date
4416     IF g_extract_type = '3CUT'
4417        OR
4418        g_dfn_name = 'BDI'
4419     THEN
4420       -- open cursor to store assignment details
4421       open csr_get_assignment_dtl_cut
4422                (
4423                 p_business_group_id  => p_business_group_id -- IN
4424                ,p_effective_date     => p_effective_date    -- IN
4425                ,p_assignment_id      => p_assignment_id     -- IN
4426                );
4427       fetch csr_get_assignment_dtl_cut into l_assignment_dtl;
4428         IF csr_get_assignment_dtl_cut%FOUND THEN
4429           debug('storing assignment details ...', 15);
4430           p_assignment_dtl := l_assignment_dtl;
4431 
4432           ---- Bugfix 6196433
4433           IF g_dfn_name = 'BDI' THEN
4434             g_assignment_dtl := l_assignment_dtl;  --location fix
4435           END IF;
4436 
4437         ELSE
4438           --ERR : no assignment details found
4439           debug('Assignment did not qualify !!', 20);
4440           p_assignment_dtl := NULL;
4441           l_inclusion_flag := 'N';
4442         END IF;
4443       close csr_get_assignment_dtl_cut;
4444 
4445     ELSE -- ='1PED' : periodic interfaces
4446          -- pick person till final close date
4447 
4448       -- open cursor to store assignment details
4449       open csr_get_assignment_dtl_per
4450                (
4451                 p_business_group_id  => p_business_group_id -- IN
4452                ,p_effective_date     => p_effective_date    -- IN
4453                ,p_assignment_id      => p_assignment_id     -- IN
4454                );
4455       fetch csr_get_assignment_dtl_per into l_assignment_dtl;
4456         IF csr_get_assignment_dtl_per%FOUND THEN
4457           debug('storing assignment details ...', 21);
4458           p_assignment_dtl := l_assignment_dtl;
4459 
4460           g_assignment_dtl := l_assignment_dtl;      -- for PF
4461 
4462 
4463         ELSE
4464           --ERR : no assignment details found
4465           debug('Assignment did not qualify !!', 22);
4466           p_assignment_dtl := NULL;
4467           l_inclusion_flag := 'N';
4468         END IF;
4469       close csr_get_assignment_dtl_per;
4470     END IF;
4471 
4472 
4473       IF g_assignment_id IS NULL
4474            OR p_assignment_id <> nvl(g_assignment_id,0) THEN
4475            -- set assignment globals
4476            g_retro_event_date_reported  :=  FALSE;
4477       END IF;
4478           -- store globals
4479           g_assignment_id := p_assignment_id;
4480 
4481       -- remove all occurences of '-'
4482       g_assignment_number := TRIM(REPLACE(l_assignment_dtl.assignment_number,'-',''));
4483       debug('g_assignment_number : ' || g_assignment_number , 25);
4484       -- check altkey size <= 12 and alphanumeric check
4485       -- anshghos : 115.9
4486       IF ( length(g_assignment_number) + length(g_paypoint)) > 12
4487       THEN
4488         -- store error
4489         l_value := raise_extract_error
4490                      (p_error_number        =>    94454
4491                      ,p_error_text          =>    'BEN_94454_INV_ASSIGNMENT_NUM'
4492                      -- 115.11 : invalid assignment_number passed as token
4493                      ,p_token1              =>    g_assignment_number
4494                      );
4495       END IF;
4496 
4497       IF NOT PQP_GB_PSI_FUNCTIONS.is_alphanumeric(p_string=> g_assignment_number)
4498       THEN
4499         -- store error
4500         l_value := raise_extract_error
4501                      (p_error_number        =>    94467
4502                      ,p_error_text          =>    'BEN_94467_INV_ASSIGNMENT_NUM'
4503                      -- 115.11 : invalid assignment_number passed as token
4504                      ,p_token1              =>    g_assignment_number
4505                      );
4506       END IF;
4507 
4508         -- 115.11 (anshghos) : person no longer excluded for invalid altkey
4509         -- truncating assignment number so that altkey is 12 characters
4510           g_assignment_number := substr(g_assignment_number,1,(12-length(g_paypoint)));
4511 
4512     debug('l_inclusion_flag : '|| l_inclusion_flag,25);
4513 
4514 
4515     IF l_inclusion_flag <> 'N' -- not yet ruled out
4516     THEN
4517       -- open cursor to store person details
4518       open csr_get_person_dtl
4519                (
4520                 p_business_group_id  => p_business_group_id         -- IN
4521                ,p_effective_date     => p_effective_date            -- IN
4522                ,p_person_id          => l_assignment_dtl.person_id  -- IN
4523                );
4524       fetch csr_get_person_dtl into l_person_dtl;
4525         IF csr_get_person_dtl%FOUND THEN
4526           debug('storing person details ...', 20);
4527           p_person_dtl := l_person_dtl;
4528 
4529           g_person_dtl := l_person_dtl;               -- for PF
4530 
4531         ELSE
4532           --ERR : no assignment details found
4533           debug('ERROR!!! : no person details fetched for the person id', 30);
4534           p_person_dtl := NULL;
4535           l_inclusion_flag := 'N';
4536 
4537 
4538         -- ERR raised for this person
4539         -- store error
4540         l_value := raise_extract_error
4541                      (p_error_number        =>    94455
4542                      ,p_error_text          =>    'BEN_94455_PERSON_DTLS_MISSING'
4543                      );
4544 
4545         END IF;
4546       close csr_get_person_dtl;
4547     END IF;
4548 
4549     debug('l_inclusion_flag : '|| l_inclusion_flag,35);
4550 
4551 
4552     -- assignment and person details are available
4553     -- employee_type = 'E', category IS NOT NULL
4554 
4555     IF l_inclusion_flag <> 'N' -- => assignment/person details were found
4556     THEN
4557       debug('l_inclusion_flag : '|| l_inclusion_flag,60);
4558 
4559       -- search thru the mapping for this assignment category
4560       FOR i IN 1..g_assign_category_mapping.COUNT
4561       LOOP
4562 
4563         IF i=1 THEN -- finding next index
4564         l_index:=g_assign_category_mapping.FIRST;
4565         ELSE
4566         l_index:=g_assign_category_mapping.NEXT(l_index);
4567         END IF;
4568 
4569         debug('g_assign_category_mapping('||l_index||').pcv_information1 : '
4570                       || g_assign_category_mapping(l_index).pcv_information1);
4571         debug('g_assign_category_mapping('||l_index||').pcv_information2 : '
4572                       || g_assign_category_mapping(l_index).pcv_information2);
4573 
4574         -- start comparing
4575         IF l_assignment_dtl.employment_category =
4576            g_assign_category_mapping(l_index).pcv_information1 -- match found!!
4577         THEN
4578           l_assignment_category := g_assign_category_mapping(l_index).pcv_information2;
4579 
4580           debug('l_assignment_category : '|| l_assignment_category,65);
4581           debug('g_assign_category_mapping('||l_index||').pcv_information2 : '
4582                       || g_assign_category_mapping(l_index).pcv_information2,66);
4583           debug('match found, exiting FOR loop!',67);
4584 
4585           EXIT; -- match found, exit the FOR loop
4586         ELSE
4587           -- ERR - no matching employment category
4588           debug('Not a match !!',70);
4589         END IF;
4590 
4591       END LOOP; -- end of FOR loop
4592 
4593       -- match not found after looping thru
4594       IF l_assignment_category IS NULL
4595       THEN
4596         debug('No match was found, this category type doesnt exist in config value mapping!!',75);
4597 
4598         l_inclusion_flag := 'N';
4599       ELSE -- assignment category match found - casual or regular
4600 
4601         debug('employment category mapping has been found :'||l_assignment_category,90);
4602 
4603         -- 1) if permanent (regular) or fixed term  employee, report
4604         --115.70 5897563
4605         IF l_assignment_category in ('REGULAR','FIXED') THEN
4606           debug('employee is '||l_assignment_category||' , inclusion = Y',110);
4607           l_inclusion_flag := 'Y';
4608         ELSE -- not regular, is casual
4609         -- 2) check if person employed for more than 3 months
4610 
4611           debug('employee is CASUAL, further checks ...',120);
4612 
4613           --
4614           /*
4615           debug('Fetching last_hire_date_indicator  ...', 130);
4616           OPEN  csr_last_hire_date_indicator
4617                    (
4618                     p_business_group_id  => p_business_group_id     -- IN
4619                    ,p_effective_date     => p_effective_date        -- IN
4620                    ,p_person_id          => l_person_dtl.person_id  -- IN
4621                    );
4622           FETCH csr_last_hire_date_indicator into l_last_hire_date_indicator;
4623             IF csr_last_hire_date_indicator%NOTFOUND THEN
4624               debug('last hire date < 3 months old',140);
4625               l_inclusion_flag := 'N'; -- cursor empty as last hire date = within 3 months
4626             ELSE
4627               -- further check pension scheme, in case its partner, 'Y' else 'N'
4628               l_inclusion_flag := check_employee_pension_scheme -- Y/N last hire date > 3 months older
4629                                   (p_business_group_id  => p_business_group_id
4630                                   ,p_effective_date     => p_effective_date
4631                                   ,p_assignment_id      => p_assignment_id
4632                                   ,p_psi_pension_scheme => 'PARTNER'
4633                                   ,p_pension_element_type_id => l_pension_element_type_id
4634                                   );
4635               --
4636             END IF;
4637           CLOSE csr_last_hire_date_indicator;
4638           */
4639 
4640             -- 115.60
4641             -- the check for 3 months of service for part timers has been removed
4642             -- direct check for partnership scheme for part timers
4643 
4644             debug('Check if employee is in PARTNERship scheme...', 130);
4645             l_inclusion_flag := check_employee_pension_scheme -- Y/N last hire date > 3 months older
4646                                 (p_business_group_id  => p_business_group_id
4647                                 ,p_effective_date     => p_effective_date
4648                                 ,p_assignment_id      => p_assignment_id
4649                                 ,p_psi_pension_scheme => 'PARTNER'
4650                                 ,p_pension_element_type_id => l_pension_element_type_id
4651                                 );
4652          --Bug 6770167 begin
4653            IF l_inclusion_flag = 'N'
4654            THEN
4655             l_inclusion_flag := check_employee_pension_scheme -- Y/N last hire date > 3 months older
4656                                 (p_business_group_id  => p_business_group_id
4657                                 ,p_effective_date     => p_effective_date
4658                                 ,p_assignment_id      => p_assignment_id
4659                                 ,p_psi_pension_scheme => 'NUVOS'
4660                                 ,p_pension_element_type_id => l_pension_element_type_id
4661                                  );
4662             END IF;
4663             --Bug 6770167 End
4664 
4665         END IF; -- IF l_assignment_category = 'REGULAR' THEN
4666 
4667       END IF; -- IF l_assignment_category IS NULL
4668     END IF; -- IF l_inclusion_flag <> 'N' -- => assignment/person details were found
4669 
4670     IF l_inclusion_flag <> 'N' THEN
4671          l_inclusion_flag :=  check_employee_eligibility
4672                                   (p_business_group_id   =>   p_business_group_id
4673                                   ,p_assignment_id       =>   p_assignment_id
4674                                   ,p_effective_date      =>   p_effective_date
4675                                   ,p_chg_value           =>   g_pension_scheme
4676                                   );
4677     END IF;
4678 
4679     debug('l_inclusion_flag (final) : ' || l_inclusion_flag,150);
4680     debug_exit(l_proc_name);
4681                                                           -- for PF
4682 
4683       g_prev_assignment_id := p_assignment_id;
4684 
4685       g_prev_effective_date := p_effective_date;
4686       g_prev_inclusion_flag := l_inclusion_flag;
4687 
4688 
4689   return l_inclusion_flag;
4690 
4691   EXCEPTION
4692     WHEN others THEN
4693         IF SQLCODE <> hr_utility.hr_error_number
4694         THEN
4695             debug_others (l_proc_name, 10);
4696             IF g_debug
4697             THEN
4698               DEBUG (   'Leaving: '
4699                      || l_proc_name, -999);
4700              END IF;
4701              fnd_message.raise_error;
4702          ELSE
4703              RAISE;
4704          END IF;
4705 
4706   END chk_penserver_basic_criteria;
4707 
4708   ----
4709     FUNCTION is_curr_last_event RETURN BOOLEAN
4710     IS
4711         l_proc varchar2(72) := g_proc_name||'.is_curr_last_event';
4712         l_prev_event_dtl_rec    ben_ext_person.t_detailed_output_tab_rec;
4713         l_flag                  VARCHAR2(1);
4714         l_curr_idx   NUMBER;
4715         l_next_event_dtl_rec  ben_ext_person.t_detailed_output_tab_rec;
4716         l_curr_event_dtl_rec  ben_ext_person.t_detailed_output_tab_rec;
4717         l_return     BOOLEAN;
4718     BEGIN
4719       debug_enter(l_proc);
4720       l_curr_idx  :=  ben_ext_person.g_chg_pay_evt_index;
4721 
4722       IF l_curr_idx = ben_ext_person.g_pay_proc_evt_tab.COUNT
4723         OR l_curr_idx = ben_ext_person.g_pay_proc_evt_tab.COUNT - 1 THEN
4724           IF l_curr_idx = ben_ext_person.g_pay_proc_evt_tab.COUNT - 1 THEN
4725              -- if the current is last-1 event. check for duplicate row.
4726              debug('the current is last-1 event.',30);
4727              l_curr_event_dtl_rec :=  ben_ext_person.g_pay_proc_evt_tab(l_curr_idx);
4728              l_next_event_dtl_rec :=  ben_ext_person.g_pay_proc_evt_tab(l_curr_idx+1);
4729              l_next_event_dtl_rec.change_mode  :=  l_curr_event_dtl_rec.change_mode;
4730              l_flag  :=  'Y';
4731               IF l_curr_event_dtl_rec.dated_table_id <>   l_next_event_dtl_rec.dated_table_id THEN
4732                   l_flag  :=  'N';
4733               ELSIF l_curr_event_dtl_rec.datetracked_event <>   l_next_event_dtl_rec.datetracked_event THEN
4734                   l_flag  :=  'N';
4735               ELSIF l_curr_event_dtl_rec.update_type <>   l_next_event_dtl_rec.update_type THEN
4736                   l_flag  :=  'N';
4737               ELSIF l_curr_event_dtl_rec.surrogate_key <>   l_next_event_dtl_rec.surrogate_key THEN
4738                   l_flag  :=  'N';
4739               ELSIF l_curr_event_dtl_rec.column_name <>   l_next_event_dtl_rec.column_name THEN
4740                   l_flag  :=  'N';
4741               ELSIF l_curr_event_dtl_rec.effective_date <>   l_next_event_dtl_rec.effective_date THEN
4742                   l_flag  :=  'N';
4743               ELSIF l_curr_event_dtl_rec.old_value <>   l_next_event_dtl_rec.old_value THEN
4744                   l_flag  :=  'N';
4745               ELSIF l_curr_event_dtl_rec.new_value <>   l_next_event_dtl_rec.new_value THEN
4746                   l_flag  :=  'N';
4747               ELSIF l_curr_event_dtl_rec.change_values <>   l_next_event_dtl_rec.change_values THEN
4748                   l_flag  :=  'N';
4749               ELSIF l_curr_event_dtl_rec.proration_type <>   l_next_event_dtl_rec.proration_type THEN
4750                   l_flag  :=  'N';
4751               ELSIF l_curr_event_dtl_rec.event_group_id <>   l_next_event_dtl_rec.event_group_id THEN
4752                   l_flag  :=  'N';
4753              ELSIF l_curr_event_dtl_rec.actual_date <>   l_next_event_dtl_rec.actual_date THEN
4754                   l_flag  :=  'N';
4755               END IF;
4756               IF l_flag = 'N' THEN
4757                   debug('the next event is not the same as the curr one.');
4758                   l_return := FALSE;
4759               ELSE
4760                   debug('the next event is the same as the curr one.');
4761                   l_return := TRUE;
4762               END IF;
4763           ELSE
4764              debug('Current event is the last one',30);
4765              l_return := TRUE;
4766           END IF;
4767       ELSE
4768           debug('Current event is NOT the last one',30);
4769           l_return := FALSE;
4770       END IF;
4771 
4772 
4773       debug_exit(l_proc);
4774       RETURN l_return;
4775     END is_curr_last_event;
4776     ----
4777 -- This function returns the last approved run date for
4778 -- periodic changes
4779 -- ----------------------------------------------------------------------------
4780 -- |----------------------------< get_last_run_date >-------------------------|
4781 -- ----------------------------------------------------------------------------
4782    FUNCTION get_last_run_date
4783                 (p_run_from_cutover_date IN VARCHAR2 -- Bugfix 4969368
4784                 )
4785      RETURN DATE
4786    IS
4787      --
4788 
4789      /*
4790      -- Cursor to fetch the last successful approved run date
4791      CURSOR csr_get_run_date
4792      IS
4793      SELECT MAX(eff_dt)
4794        FROM ben_ext_rslt
4795       WHERE ext_dfn_id = ben_ext_thread.g_ext_dfn_id
4796         AND business_group_id = g_business_group_id
4797         AND ext_stat_cd = 'A';
4798      */
4799 
4800      l_proc_name VARCHAR2(80) := g_proc_name || 'get_last_run_date';
4801      l_proc_step PLS_INTEGER;
4802      l_run_date  DATE;
4803      l_config_value   PQP_UTILITIES.t_config_values;
4804 
4805      l_reference_extract  VARCHAr2(30);
4806      l_ext_dfn_id     NUMBER;
4807      --
4808    BEGIN
4809      --
4810      IF g_debug
4811      THEN
4812        l_proc_step := 10;
4813        debug_enter(l_proc_name, l_proc_step);
4814      END IF;
4815 
4816       /*
4817       -- fetch reference extract name
4818       debug('Fetching Effective rolling date window length ...', 40);
4819       pqp_utilities.get_config_type_values
4820                    ( p_configuration_type   => 'PQP_GB_PENSERVER_DEFINITION'
4821                                 ,p_business_group_id    => g_business_group_id
4822                                 ,p_legislation_code     => NULL
4823                                 ,p_tab_config_values    => l_config_value
4824                      );
4825 
4826       IF l_config_value.COUNT > 0 -- config value found
4827       THEN
4828         l_reference_extract := l_config_value(l_config_value.FIRST).pcv_information3;
4829       ELSE
4830         l_reference_extract := 'BASIC';
4831       END IF;
4832 
4833       */
4834 
4835       -- performance fix : 1
4836       IF g_reference_extract = 'BASIC' THEN
4837         OPEN csr_ext_dfn_id(c_extract_name => 'PQP GB PenServer Periodic Changes Interface - Basic Data');
4838         FETCH csr_ext_dfn_id INTO l_ext_dfn_id;
4839         CLOSE csr_ext_dfn_id;
4840       ELSE
4841         l_ext_dfn_id := ben_ext_thread.g_ext_dfn_id;
4842       END IF;
4843 
4844 
4845      -- Get the run date
4846      OPEN csr_get_run_date(c_ext_dfn_id         => l_ext_dfn_id
4847                           ,c_business_group_id  => g_business_group_id);
4848      FETCH csr_get_run_date INTO l_run_date,g_output_name;
4849      CLOSE csr_get_run_date;
4850 
4851      IF g_debug
4852      THEN
4853        debug('l_run_date: '||TO_CHAR(l_run_date, 'DD/MON/YYYY'));
4854      END IF;
4855 
4856      -- Set the run date to cutover date only if this is a
4857      -- first run
4858      -- Bugfix 4969368: Setting run date to cutover date if
4859      --  current interfaces needs to run from cutover date
4860      --  rather than cutover date +1
4861      --  Currently only short time hours needs to do this
4862      IF l_run_date IS NULL THEN
4863        -- This is the first run, using cutover date
4864        IF p_run_from_cutover_date = 'Y' THEN
4865          -- Set the run date to be cutover date
4866          l_run_date    := g_cutover_date;
4867        ELSE
4868          l_run_date    := g_cutover_date + 1;
4869        END IF;
4870        --
4871      ELSE
4872        -- Bugfix 4969368: Moved +1 logic up here for bugfix
4873        -- This is not the first run
4874        l_run_date := l_run_date + 1;
4875      END IF; -- End if of l_run_date is null check ...
4876 
4877      -- When this is the first run and the cutover date is not
4878      -- present default the dates to pension year start date
4879      IF l_run_date IS NULL
4880      THEN
4881         l_run_date    :=
4882            TO_DATE(
4883               '01-04-' || TO_CHAR(ben_ext_person.g_effective_date, 'YYYY')
4884              ,'DD-MM-YYYY'
4885            );
4886         IF l_run_date > ben_ext_person.g_effective_date
4887         THEN
4888            l_run_date    := ADD_MONTHS(l_run_date, -12);
4889         END IF;
4890      -- Bugfix 4969368: Moving this logic of run_date +1 above
4891      -- to cater for short time hours which should run from
4892      -- cutover date always
4893      --ELSE -- run date is not null
4894      --  l_run_date := l_run_date + 1;
4895      END IF; -- End if of run date is null check ..
4896 
4897      IF g_debug
4898      THEN
4899        l_proc_step := 20;
4900        debug('l_run_date: '||TO_CHAR(l_run_date, 'DD/MON/YYYY'));
4901        debug_exit(l_proc_name);
4902      END IF;
4903 
4904      RETURN l_run_date;
4905    EXCEPTION
4906      WHEN others THEN
4907          IF SQLCODE <> hr_utility.hr_error_number
4908          THEN
4909              debug_others (l_proc_name, l_proc_step);
4910              IF g_debug
4911              THEN
4912                DEBUG (   'Leaving: '
4913                       || l_proc_name, -999);
4914               END IF;
4915               fnd_message.raise_error;
4916           ELSE
4917               RAISE;
4918           END IF;
4919    END get_last_run_date;
4920 
4921    -- ----------------------------------------------------------------------------
4922     -- |---------------------< is_curr_evt_processed >---------------------|
4923     -- ----------------------------------------------------------------------------
4924    FUNCTION is_curr_evt_processed RETURN BOOLEAN
4925     IS
4926         l_proc varchar2(72) := g_proc_name||'is_curr_evt_processed';
4927         l_prev_event_dtl_rec    ben_ext_person.t_detailed_output_tab_rec;
4928         l_flag                  VARCHAR2(1);
4929     BEGIN
4930       debug_enter(l_proc);
4931 
4932       IF g_prev_event_dtl_rec.dated_table_id IS NOT NULL THEN
4933           l_prev_event_dtl_rec  :=  ben_ext_person.g_pay_proc_evt_tab(ben_ext_person.g_chg_pay_evt_index);
4934           l_prev_event_dtl_rec.change_mode  :=  g_prev_event_dtl_rec.change_mode;
4935           l_flag  :=  'Y';
4936           IF l_prev_event_dtl_rec.dated_table_id <>   g_prev_event_dtl_rec.dated_table_id THEN
4937               l_flag  :=  'N';
4938           ELSIF l_prev_event_dtl_rec.datetracked_event <>   g_prev_event_dtl_rec.datetracked_event THEN
4939               l_flag  :=  'N';
4940           ELSIF l_prev_event_dtl_rec.update_type <>   g_prev_event_dtl_rec.update_type THEN
4941               l_flag  :=  'N';
4942           ELSIF l_prev_event_dtl_rec.surrogate_key <>   g_prev_event_dtl_rec.surrogate_key THEN
4943               l_flag  :=  'N';
4944           ELSIF l_prev_event_dtl_rec.column_name <>   g_prev_event_dtl_rec.column_name THEN
4945               l_flag  :=  'N';
4946           ELSIF l_prev_event_dtl_rec.effective_date <>   g_prev_event_dtl_rec.effective_date THEN
4947               l_flag  :=  'N';
4948           ELSIF l_prev_event_dtl_rec.old_value <>   g_prev_event_dtl_rec.old_value THEN
4949               l_flag  :=  'N';
4950           ELSIF l_prev_event_dtl_rec.new_value <>   g_prev_event_dtl_rec.new_value THEN
4951               l_flag  :=  'N';
4952           ELSIF l_prev_event_dtl_rec.change_values <>   g_prev_event_dtl_rec.change_values THEN
4953               l_flag  :=  'N';
4954           ELSIF l_prev_event_dtl_rec.proration_type <>   g_prev_event_dtl_rec.proration_type THEN
4955               l_flag  :=  'N';
4956           ELSIF l_prev_event_dtl_rec.event_group_id <>   g_prev_event_dtl_rec.event_group_id THEN
4957               l_flag  :=  'N';
4958          ELSIF l_prev_event_dtl_rec.actual_date <>   g_prev_event_dtl_rec.actual_date THEN
4959               l_flag  :=  'N';
4960           END IF;
4961 
4962           IF l_flag = 'Y' THEN
4963               debug('Event already processed',30);
4964               debug_exit(l_proc);
4965               RETURN TRUE;
4966           ELSE
4967               g_prev_event_dtl_rec  :=  ben_ext_person.g_pay_proc_evt_tab(ben_ext_person.g_chg_pay_evt_index);
4968           END IF;
4969       ELSE
4970           debug('First event');
4971           g_prev_event_dtl_rec  :=  ben_ext_person.g_pay_proc_evt_tab(ben_ext_person.g_chg_pay_evt_index);
4972       END IF;
4973 
4974       debug_exit(l_proc);
4975       RETURN FALSE;
4976     END is_curr_evt_processed;
4977     ----
4978 -- This function evaluates whether an event should be included in the current
4979 -- report or not based on the effectiveness and application date logic
4980 -- ----------------------------------------------------------------------------
4981 -- |----------------------------< include_event >-----------------------------|
4982 -- ----------------------------------------------------------------------------
4983    FUNCTION include_event (
4984      p_actual_date IN DATE
4985     ,p_effective_date IN DATE
4986     ,p_run_from_cutover_date IN VARCHAR2 -- Bugfix 4969368
4987     )
4988     RETURN VARCHAR2
4989   IS
4990     --
4991     l_proc_name VARCHAR2(80) := g_proc_name || 'include_event';
4992     l_proc_step PLS_INTEGER;
4993     l_return    VARCHAR2(10);
4994     l_chg_date  DATE;
4995     l_chg_table VARCHAR2(80);
4996     l_chg_type VARCHAR2(10);
4997     --
4998   BEGIN
4999     --
5000     IF g_debug
5001     THEN
5002       l_proc_step := 10;
5003       debug_enter(l_proc_name);
5004       debug('p_actual_date: '||TO_CHAR(p_actual_date, 'DD/MON/YYYY'));
5005       debug('p_effective_date: '||TO_CHAR(p_effective_date, 'DD/MON/YYYY'));
5006     END IF;
5007 
5008     IF g_effective_start_date IS NULL
5009     THEN
5010       -- populate the effective dates
5011       g_effective_start_date :=
5012         get_last_run_date(p_run_from_cutover_date => p_run_from_cutover_date -- Bugfix 4969368
5013                          );
5014       g_effective_end_date := ben_ext_person.g_effective_date;
5015     END IF;
5016 
5017     IF g_debug
5018     THEN
5019       l_proc_step := 20;
5020       debug(l_proc_name, l_proc_step);
5021       debug('g_effective_start_date: '||TO_CHAR(g_effective_start_date, 'DD/MON/YYYY'));
5022       debug('g_effective_end_date: '||TO_CHAR(g_effective_end_date, 'DD/MON/YYYY'));
5023     END IF;
5024 
5025     IF NVL(g_person_id, hr_api.g_number) <> ben_ext_person.g_person_id
5026     THEN
5027       g_person_id := ben_ext_person.g_person_id;
5028       g_min_eff_date_exists := 'N';
5029       debug('NVL(g_person_id, hr_api.g_number) <> ben_ext_person.g_person_id',20);
5030     END IF;
5031 
5032       -- set the start date of the range to '00:00:00'
5033       -- and set the end date of the range to '23:59:59'
5034         g_effective_start_date :=
5035           fnd_date.canonical_to_date(TO_CHAR(g_effective_start_date,'YYYY/MM/DD'));
5036         g_effective_end_date   :=
5037           fnd_date.canonical_to_date((TO_CHAR(g_effective_end_date,'YYYY/MM/DD')||'23:59:59'));
5038 
5039         IF g_debug
5040         THEN
5041           debug('g_effective_start_date: '||g_effective_start_date,25);
5042           debug('g_effective_end_date: '||g_effective_end_date,25);
5043         END IF;
5044 
5045       --
5046     l_return := 'Y';
5047 
5048     -- Check whether the actual date is between last run date and extract effective
5049     -- date or we have already found the earliest effective date or
5050     -- the effective date is within the run date range and the actual date
5051     -- is not in the future
5052 
5053     IF l_return <> 'N' AND NOT is_curr_evt_processed THEN
5054         --
5055         l_return := 'N';
5056 
5057         IF    (p_actual_date BETWEEN g_effective_start_date AND g_effective_end_date
5058                 AND
5059                p_effective_date <= g_effective_end_date  -- bug fix 4944134
5060               )
5061            OR (
5062                    (
5063                        g_min_eff_date_exists = 'Y'
5064                     OR p_effective_date BETWEEN g_effective_start_date
5065                                             AND g_effective_end_date
5066                    )
5067                AND p_actual_date <= g_effective_end_date
5068               )
5069         THEN
5070           debug('Inside the Then ... ',30);
5071                IF g_min_eff_date_exists = 'N' AND
5072                   NOT p_effective_date BETWEEN g_effective_start_date
5073                                            AND g_effective_end_date
5074                THEN
5075                  debug('g_min_eff_date_exists = N and p_effective_date is not between '||
5076                      'g_eff start and end dates',40);
5077                  debug('g_assignment_id : '||g_assignment_id,50);
5078 
5079                  g_min_effective_date(g_assignment_id) := p_effective_date;
5080                  g_min_eff_date_exists := 'Y';
5081 
5082 
5083                  IF g_debug
5084                  THEN
5085 
5086                    l_proc_step := 30;
5087                    debug(l_proc_name, l_proc_step);
5088                    IF g_min_effective_date.EXISTS(g_assignment_id) THEN
5089 
5090                      debug(
5091                            'g_min_effective_date('
5092                         || g_assignment_id
5093                         || '): '
5094                         || TO_CHAR(g_min_effective_date(g_assignment_id), 'DD/MON/YYYY')
5095                      );
5096                    ELSE
5097                      debug('g_min_effective_date.(g_assignment_id) doesnt Exist!',60);
5098                      debug('g_assignment_id : '|| g_assignment_id,70);
5099                    END IF;
5100                    debug('g_min_eff_date_exists: '||g_min_eff_date_exists);
5101 
5102                  END IF;
5103                END IF;
5104 
5105                l_return := 'Y';
5106         END IF; -- End if of actual date check ...
5107     ELSE
5108         debug('the current event is already processed');
5109         l_return := 'N';
5110     END IF;
5111 
5112     -- reject all purge events on element entries
5113         l_chg_type            :=  ben_ext_person.g_chg_update_type;
5114         l_chg_table           :=  ben_ext_person.g_chg_pay_table;
5115         l_chg_date            :=  ben_ext_person.g_chg_eff_dt;
5116 
5117         IF l_chg_table = 'PAY_ELEMENT_ENTRIES_F'
5118             AND l_chg_type = 'P'
5119         THEN
5120             debug('Current event is a Purge on element entries',20);
5121             debug('This event will be rejected.',20);
5122             l_return := 'N';
5123         END IF;
5124     ----------
5125 
5126     IF g_debug
5127     THEN
5128       l_proc_step := 40;
5129       debug('l_return: '||l_return);
5130       debug_exit(l_proc_name);
5131     END IF;
5132 
5133     RETURN l_return;
5134    EXCEPTION
5135      WHEN others THEN
5136          IF SQLCODE <> hr_utility.hr_error_number
5137          THEN
5138              debug_others (l_proc_name, l_proc_step);
5139              IF g_debug
5140              THEN
5141                DEBUG (   'Leaving: '
5142                       || l_proc_name, -999);
5143               END IF;
5144               fnd_message.raise_error;
5145           ELSE
5146               RAISE;
5147           END IF;
5148    END include_event;
5149 
5150 
5151 -- This procedure will be used in the future to add any new logic for
5152 -- retro event processing
5153 -- ----------------------------------------------------------------------------
5154 -- |----------------------------< process_retro_event >-----------------------|
5155 -- ----------------------------------------------------------------------------
5156    PROCEDURE process_retro_event
5157               (
5158               p_include   VARCHAR2  DEFAULT 'Y'
5159               )
5160    IS
5161       --
5162       l_proc_name   VARCHAR2(80) := g_proc_name || 'process_retro_event';
5163       l_proc_step   PLS_INTEGER;
5164       l_value       NUMBER;
5165    --
5166    BEGIN
5167       --
5168       IF g_debug
5169       THEN
5170          l_proc_step    := 10;
5171          debug_enter(l_proc_name);
5172       END IF;
5173 
5174       -- At the moment check for presence of any retro events and raise a
5175       -- suitable warning message
5176       IF g_min_effective_date.EXISTS(g_assignment_id)
5177       THEN
5178          IF g_debug
5179          THEN
5180             DEBUG('Raise Warning Message: Retro Event Exists');
5181             DEBUG(
5182                   'g_min_effective_date('
5183                || g_assignment_id
5184                || '): '
5185                || g_min_effective_date(g_assignment_id)
5186             );
5187          END IF;
5188 
5189          -- retro event exists
5190          l_value    :=
5191             raise_extract_warning(
5192                p_error_text        => 'BEN_94482_EXT_PSI_OVR_EVNT_WRN'
5193               ,p_error_number      => 94482
5194               ,p_token1 => fnd_date.date_to_displaydt(g_min_effective_date(g_assignment_id))
5195             );
5196 
5197 
5198           IF NOT g_retro_event_date_reported THEN
5199               -- if the retro event date is not reported in the DE
5200               -- if p_include is 'N' check if this is the last event.
5201               debug('Retro event date is not reported',20);
5202               IF p_include = 'N' THEN
5203                   IF is_curr_last_event() THEN
5204                       -- raise data error
5205                       debug('Raise an error as the delete event could not be reported',30);
5206                       debug('Current event is the last event, g_retro_event_date_reported is rest to true.',30);
5207                       l_value    :=
5208                                     raise_extract_error(
5209                                        p_error_text        => 'BEN_94540_FIRST_RETRO_DATE'
5210                                       ,p_error_number      => 94540
5211                                       ,p_token1 => fnd_date.date_to_displaydt(g_min_effective_date(g_assignment_id))
5212                                     );
5213                       g_retro_event_date_reported :=  TRUE;
5214                   END IF;
5215               ELSE
5216                   debug('Delete date should be reported in the current row: '||g_min_effective_date(g_assignment_id),20);
5217               END IF;
5218           ELSE
5219               -- clear the retro_event_date global value, so that the DE reports a null value.
5220               debug('retro event date is already reported.',20);
5221 
5222           END IF; --IF NOT g_retro_event_date_reported
5223 
5224       END IF; -- End if of min effective date exists check ...
5225       IF g_debug
5226       THEN
5227          l_proc_step    := 20;
5228          debug_exit(l_proc_name);
5229       END IF;
5230    EXCEPTION
5231       WHEN OTHERS
5232       THEN
5233          IF SQLCODE <> hr_utility.hr_error_number
5234          THEN
5235             debug_others(l_proc_name, l_proc_step);
5236 
5237             IF g_debug
5238             THEN
5239                DEBUG('Leaving: ' || l_proc_name, -999);
5240             END IF;
5241 
5242             fnd_message.raise_error;
5243          ELSE
5244             RAISE;
5245          END IF;
5246    END process_retro_event;
5247 -- ----------------------------------------------------------------------------
5248     -- |--------------------------< get_dated_table_name >-------------------------|
5249     --  Description:
5250     -- ----------------------------------------------------------------------------
5251     FUNCTION get_dated_table_name
5252                 (
5253                 p_dated_table_id    NUMBER
5254                 )RETURN VARCHAR2
5255     IS
5256         l_table_name        VARCHAR2(80);
5257         CURSOR csr_dated_table_name
5258         IS
5259             SELECT table_name
5260             FROM pay_dated_tables
5261             WHERE dated_table_id = p_dated_table_id;
5262     BEGIN
5263         IF NOT g_dated_tables.exists(p_dated_table_id) THEN
5264             OPEN csr_dated_table_name;
5265             FETCH csr_dated_table_name INTO l_table_name;
5266             CLOSE csr_dated_table_name;
5267             g_dated_tables(p_dated_table_id)  :=  l_table_name;
5268         END IF;
5269 
5270         return g_dated_tables(p_dated_table_id);
5271     END get_dated_table_name;
5272 
5273 
5274    -- ----------------------------------------------------------------------------
5275     -- |----------------------< chk_is_employee_a_leaver >--------------------------|
5276     --  Description:  This is to check if the assignment is ending on the effective date
5277     --                  p_leaver_date will be the value of the assignment leaver date.
5278     -- ----------------------------------------------------------------------------
5279     FUNCTION chk_is_employee_a_leaver
5280                 (
5281                 p_assignment_id     NUMBER
5282                 ,p_effective_date   DATE
5283                 ,p_leaver_date      OUT NOCOPY DATE
5284                 ) RETURN VARCHAR2
5285     IS
5286         l_proc varchar2(72) := g_proc_name||'chk_is_employee_a_leaver';
5287         l_leaver  VARCHAR2(1) := 'N';
5288         l_pay_assg_status   VARCHAR2(20);
5289         CURSOR csr_asg_details_up -- effective first then future rows
5290                    (p_assignment_id     NUMBER
5291                    ,p_effective_date    DATE  DEFAULT NULL
5292                    )
5293         IS
5294            SELECT asg.person_id                          person_id
5295                 ,asg.assignment_id                      assignment_id
5296                 ,asg.business_group_id                  business_group_id
5297                 ,asg.effective_start_date               start_date
5298                 ,asg.effective_end_date                 effective_end_date
5299                 ,asg.creation_date                      creation_date
5300                 ,asg.assignment_status_type_id          status_type_id
5301                 ,'                              '       status_type
5302             FROM per_all_assignments_f asg
5303 
5304            WHERE asg.assignment_id = p_assignment_id
5305              AND (( p_effective_date BETWEEN asg.effective_start_date
5306                                           AND asg.effective_end_date )
5307                   OR
5308                    ( asg.effective_start_date = p_effective_date + 1 ) -- modified for 115.68
5309                  )
5310            ORDER BY asg.effective_start_date ASC; -- effective first then future rows
5311 
5312         CURSOR csr_assignment_status
5313                   (
5314                   p_assignment_status_type_id NUMBER
5315                   )
5316         IS
5317              SELECT DECODE(pay_system_status,'D','DO NOT PROCESS','P','PROCESS')
5318                     ,per_system_status
5319              FROM per_assignment_status_types
5320              WHERE ASSIGNMENT_STATUS_TYPE_ID = p_assignment_status_type_id
5321              AND  primary_flag = 'P';
5322 
5323         l_asg_details          csr_asg_details_up%ROWTYPE;
5324         l_next_asg_details     csr_asg_details_up%ROWTYPE;
5325     BEGIN
5326         debug_enter(l_proc);
5327 
5328         OPEN csr_asg_details_up
5329                 (p_assignment_id
5330                 ,p_effective_date - 1
5331                 );
5332         FETCH csr_asg_details_up INTO l_asg_details;
5333         IF csr_asg_details_up%FOUND THEN
5334                debug('Inside IF , found ASG record',30);
5335                -- Get the per_system_status for the assignment_status_type_id
5336                OPEN csr_assignment_status(l_asg_details.status_type_id);
5337                FETCH csr_assignment_status INTO l_pay_assg_status,l_asg_details.status_type;
5338                CLOSE csr_assignment_status;
5339 
5340                debug('l_asg_details.status_type: '||l_asg_details.status_type,20);
5341                debug('l_asg_details.effective_start_date: '||l_asg_details.start_date,20);
5342                debug('l_asg_details.effective_end_date: '||l_asg_details.effective_end_date,20);
5343 
5344                -- Get the next assignment and compare status type
5345                FETCH csr_asg_details_up INTO l_next_asg_details;
5346                OPEN csr_assignment_status(l_next_asg_details.status_type_id);
5347                FETCH csr_assignment_status INTO l_pay_assg_status,l_next_asg_details.status_type;
5348                CLOSE csr_assignment_status;
5349 
5350                debug('After second fetch',40);
5351                debug('l_next_asg_details.status_type: '||l_next_asg_details.status_type,20);
5352                debug('l_next_asg_details.effective_start_date: '||l_next_asg_details.start_date,20);
5353                debug('l_next_asg_details.effective_end_date: '||l_next_asg_details.effective_end_date,20);
5354                 IF (csr_asg_details_up%FOUND
5355                     AND
5356                     l_asg_details.status_type <> l_next_asg_details.status_type
5357                     AND
5358                     l_next_asg_details.status_type IN ('TERM_ASSIGN','SUSP_ASSIGN','END')
5359                    )
5360                    OR
5361                    -- No future rows found
5362                    (csr_asg_details_up%NOTFOUND
5363                     AND
5364                     -- But the current assignment has been suspended or is Active
5365                     -- Added Active as a bugfix as END Employment does not change status
5366                     -- when the termination happens on the last day of the payroll period
5367 
5368                     --l_asg_details.status_type IN ('SUSP_ASSIGN','ACTIVE_ASSIGN')
5369                      l_asg_details.effective_end_date = p_effective_date
5370                    )
5371                    THEN
5372 
5373                   -- Assignment has been terminated/suspended/ended
5374                   l_leaver := 'Y';
5375                   p_leaver_date := l_asg_details.effective_end_date;
5376 
5377                   debug('Assignment is a leaver',50);
5378 
5379               END IF; -- csr_asg_details_up%FOUND THEN
5380         END IF; -- IF csr_asg_details_up%FOUND
5381 
5382         IF csr_asg_details_up%ISOPEN THEN
5383           CLOSE csr_asg_details_up;
5384         END IF;
5385 
5386         debug_exit(l_proc);
5387         return l_leaver;
5388     EXCEPTION
5389            WHEN others THEN
5390                IF SQLCODE <> hr_utility.hr_error_number
5391                THEN
5392                    debug_others (l_proc, 10);
5393                    IF g_debug
5394                    THEN
5395                      DEBUG (   'Leaving: '
5396                             || l_proc, -999);
5397                     END IF;
5398                     fnd_message.raise_error;
5399                 ELSE
5400                     RAISE;
5401                 END IF;
5402     END chk_is_employee_a_leaver;
5403     ------
5404 
5405 
5406     -- ----------------------------------------------------------------------------
5407     -- |-----------------------< is_proper_claim_date >--------------------------|
5408     -- Description:
5409     -- ----------------------------------------------------------------------------
5410     FUNCTION is_proper_claim_date
5411                 (
5412                 p_claim_date        IN DATE
5413                 ,p_element_name     IN VARCHAR2
5414                 ,p_element_entry_id IN NUMBER
5415                 ,p_assg_start_date  IN DATE
5416                 )RETURN BOOLEAN
5417     IS
5418         l_proc varchar2(72) := g_proc_name||'is_proper_claim_date';
5419         l_temp    NUMBER;
5420         l_return  BOOLEAN;
5421         l_include   VARCHAR2(10)  :=  'Y';
5422         l_assignment_status_type_id NUMBER;
5423         l_pay_assg_status   VARCHAR2(20);
5424         l_per_assg_status   per_assignment_status_types.per_system_status%TYPE;
5425         l_curr_person_dtls             per_all_people_f%ROWTYPE;
5426                 -- this contains the person details on effective date
5427 
5428         l_curr_assg_dtls               per_all_assignments_f%ROWTYPE;
5429                 -- this contains the person details on effective date
5430         CURSOR csr_assignment_status
5431                       (
5432                       p_assignment_status_type_id NUMBER
5433                       )
5434             IS
5435                  SELECT DECODE(pay_system_status,'D','DO NOT PROCESS','P','PROCESS')
5436                         ,per_system_status
5437                  FROM per_assignment_status_types
5438                  WHERE ASSIGNMENT_STATUS_TYPE_ID = p_assignment_status_type_id
5439                  AND  primary_flag = 'P';
5440 
5441     BEGIN -- is_future_claim
5442         debug_enter(l_proc);
5443         IF g_debug THEN
5444             debug('Inputs are: ',10);
5445             debug('p_claim_date: '||p_claim_date,10);
5446             debug('p_element_name: '||p_element_name,10);
5447             debug('p_element_entry_id: '||p_element_entry_id,10);
5448             debug('p_assg_start_date: '||p_assg_start_date,10);
5449 
5450             debug('g_effective_start_date: '||PQP_GB_PSI_FUNCTIONS.g_effective_start_date);
5451             debug('g_effective_end_date: '||PQP_GB_PSI_FUNCTIONS.g_effective_end_date);
5452         END IF;
5453 
5454 
5455         IF p_claim_date < p_assg_start_date THEN
5456             -- claim date is before the start date of the person
5457             debug('ERROR: Future Claim Date: '||ben_ext_person.g_chg_surrogate_key);
5458             l_temp :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
5459                                (p_error_number        =>    94513
5460                                ,p_error_text          =>    'BEN_94513_EARLY_CLAIM_DATE'
5461                                ,p_token1              =>    p_claim_date
5462                                ,p_token2              =>    SUBSTR(p_element_name
5463                                                                      ||'('||p_element_entry_id||')',1,80)
5464                                );
5465 
5466             debug('Returning FALSE',20);
5467             debug_exit(l_proc);
5468             RETURN FALSE;
5469 
5470         END IF; --IF p_claim_date > PQP_GB_PSI_FUNCTIONS.g_effective_end_date THEN
5471 
5472         IF p_claim_date > PQP_GB_PSI_FUNCTIONS.g_effective_end_date THEN
5473 
5474             debug('ERROR: Future Claim Date: '||ben_ext_person.g_chg_surrogate_key);
5475             l_temp :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
5476                                (p_error_number        =>    94512
5477                                ,p_error_text          =>    'BEN_94512_FUTURE_CLAIM_DATE'
5478                                ,p_token1              =>    p_claim_date
5479                                ,p_token2              =>    SUBSTR(p_element_name
5480                                                                      ||'('||p_element_entry_id||')',1,80)
5481                                );
5482 
5483             debug('Returning FALSE',20);
5484             debug_exit(l_proc);
5485             RETURN FALSE;
5486 
5487         END IF;
5488 
5489         l_assignment_status_type_id :=  l_curr_assg_dtls.assignment_status_type_id;
5490         OPEN csr_assignment_status(l_assignment_status_type_id);
5491         FETCH csr_assignment_status INTO l_pay_assg_status,l_per_assg_status;
5492         CLOSE csr_assignment_status;
5493 
5494         debug('l_assignment_status_type_id: '||l_assignment_status_type_id,20);
5495         debug('l_pay_assg_status: '||l_pay_assg_status,20);
5496         debug('l_per_assg_status: '||l_per_assg_status,20);
5497         IF l_pay_assg_status = 'DO NOT PROCESS'
5498           OR l_per_assg_status IN ('TERM_ASSIGN','SUSP_ASSIGN','END') THEN
5499 
5500             debug('ERROR: Assignment does not qualify on the claim date');
5501             l_temp :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
5502                                (p_error_number        =>    94539
5503                                ,p_error_text          =>    'BEN_94539_ASG_TERM_CLAIM_DATE'
5504                                ,p_token1              =>    p_claim_date
5505                                ,p_token2              =>    SUBSTR(p_element_name
5506                                                                  ||'('||p_element_entry_id||')',1,80)
5507                                );
5508             l_include :=  'N';
5509         ELSE
5510             debug('Assignment status is a valid one.',30);
5511             l_include :=  'Y';
5512         END IF;
5513 
5514         IF l_include <> 'N' THEN
5515 
5516               l_include :=  PQP_GB_PSI_FUNCTIONS.chk_penserver_basic_criteria
5517                                 (p_business_group_id        =>  g_business_group_id
5518                                 ,p_effective_date           =>  p_claim_date
5519                                 ,p_assignment_id            =>  g_assignment_id
5520                                 ,p_person_dtl               =>  l_curr_person_dtls
5521                                 ,p_assignment_dtl           =>  l_curr_assg_dtls
5522                                 );
5523 
5524               IF l_include = 'N' THEN
5525                     debug('ERROR: Assignment does not qualify on the claim date');
5526                     l_temp :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
5527                                      (p_error_number        =>    94542
5528                                      ,p_error_text          =>    'BEN_94542_ASG_INV_CLAIM_DATE'
5529                                      ,p_token1              =>    p_claim_date
5530                                      ,p_token2              =>    SUBSTR(p_element_name
5531                                                                            ||'('||p_element_entry_id||')',1,80)
5532                                      );
5533                     l_include :=  'N';
5534 
5535               END IF;
5536 
5537         END IF;
5538         IF l_include =  'N' THEN
5539            l_return :=  FALSE;
5540            debug('Returning FALSE',20);
5541         ELSE
5542            l_return :=  TRUE;
5543            debug('Returning TRUE',20);
5544         END IF;
5545 
5546         debug_exit(l_proc);
5547         RETURN l_return;
5548     EXCEPTION
5549            WHEN others THEN
5550                IF SQLCODE <> hr_utility.hr_error_number
5551                THEN
5552                    debug_others (l_proc, 10);
5553                    IF g_debug
5554                    THEN
5555                      DEBUG (   'Leaving: '
5556                             || l_proc, -999);
5557                     END IF;
5558                     fnd_message.raise_error;
5559                 ELSE
5560                     RAISE;
5561                 END IF;
5562     END is_proper_claim_date;
5563 
5564 
5565 
5566 -- ----------------------------------------------------------------------------
5567 -- |------------------------< get_elements_of_info_type >----------------------|
5568 -- ----------------------------------------------------------------------------
5569 PROCEDURE get_elements_of_info_type
5570       (p_information_type         IN VARCHAR2
5571       ,p_input_value              IN VARCHAR2 DEFAULT 'PAY VALUE'
5572       ,p_input_value_mandatory_yn IN VARCHAR2 DEFAULT 'Y'
5573       )
5574 IS
5575   --
5576     l_proc_name           VARCHAR2(61):=
5577      g_proc_name||'get_elements_of_info_type';
5578 
5579 
5580 BEGIN
5581   debug_enter(l_proc_name);
5582   debug ('p_information_type:'||p_information_type);
5583 
5584   IF p_input_value_mandatory_yn = 'Y'
5585   THEN
5586 
5587     FOR l_elements_rec in csr_get_elements_of_info_type
5588                           (c_information_type => p_information_type
5589                           ,c_input_value      => p_input_value
5590                           )
5591     LOOP
5592 
5593       IF l_elements_rec.element_type_id IS NOT NULL
5594       THEN
5595         debug('element_type_id : '||l_elements_rec.element_type_id);
5596         debug('element_name : '||l_elements_rec.element_name);
5597         debug('input_value_id : '||l_elements_rec.input_value_id);
5598         debug('processing_type : '||l_elements_rec.processing_type);
5599         debug('eei_information1 : '||l_elements_rec.eei_information1);
5600         debug('eei_information2 : '||l_elements_rec.eei_information2);
5601         debug('eei_information3 : '||l_elements_rec.eei_information3);
5602         debug('eei_information4 : '||l_elements_rec.eei_information4);
5603         debug('eei_information5 : '||l_elements_rec.eei_information5);
5604         debug('eei_information6 : '||l_elements_rec.eei_information6);
5605         debug('eei_information7 : '||l_elements_rec.eei_information7);
5606         debug('eei_information8 : '||l_elements_rec.eei_information8);
5607         debug('eei_information9 : '||l_elements_rec.eei_information9);
5608         debug('eei_information10 : '||l_elements_rec.eei_information10);
5609         debug('retro_summ_ele_id : '||l_elements_rec.retro_summ_ele_id);
5610 
5611         g_elements_of_info_type(l_elements_rec.element_type_id) := l_elements_rec;
5612       END IF;
5613 
5614     END LOOP;
5615   ELSE
5616     FOR l_elements_rec_no_inp_val in csr_ele_info_type_no_inp_val
5617                                       (c_information_type => p_information_type
5618                                       )
5619     LOOP
5620 
5621       IF l_elements_rec_no_inp_val.element_type_id IS NOT NULL
5622       THEN
5623         debug('element_type_id : '||l_elements_rec_no_inp_val.element_type_id);
5624         debug('element_name : '||l_elements_rec_no_inp_val.element_name);
5625         debug('processing_type : '||l_elements_rec_no_inp_val.processing_type);
5626         debug('eei_information1 : '||l_elements_rec_no_inp_val.eei_information1);
5627         debug('eei_information2 : '||l_elements_rec_no_inp_val.eei_information2);
5628         debug('eei_information3 : '||l_elements_rec_no_inp_val.eei_information3);
5629         debug('eei_information4 : '||l_elements_rec_no_inp_val.eei_information4);
5630         debug('eei_information5 : '||l_elements_rec_no_inp_val.eei_information5);
5631         debug('eei_information6 : '||l_elements_rec_no_inp_val.eei_information6);
5632         debug('eei_information7 : '||l_elements_rec_no_inp_val.eei_information7);
5633         debug('eei_information8 : '||l_elements_rec_no_inp_val.eei_information8);
5634         debug('eei_information9 : '||l_elements_rec_no_inp_val.eei_information9);
5635         debug('eei_information10 : '||l_elements_rec_no_inp_val.eei_information10);
5636         debug('retro_summ_ele_id : '||l_elements_rec_no_inp_val.retro_summ_ele_id);
5637 
5638         g_elements_of_info_type(l_elements_rec_no_inp_val.element_type_id) := l_elements_rec_no_inp_val;
5639       END IF;
5640 
5641     END LOOP;
5642   END IF;
5643 
5644   debug_exit(l_proc_name);
5645 
5646   EXCEPTION
5647     WHEN others THEN
5648         IF SQLCODE <> hr_utility.hr_error_number
5649         THEN
5650             debug_others (l_proc_name, 10);
5651             IF g_debug
5652             THEN
5653               DEBUG (   'Leaving: '
5654                      || l_proc_name, -999);
5655              END IF;
5656              fnd_message.raise_error;
5657          ELSE
5658              RAISE;
5659          END IF;
5660 
5661 END get_elements_of_info_type;
5662 
5663 
5664 
5665 -- ----------------------------------------------------------------------------
5666 -- |------------------------< check_if_element_qualifies >----------------------|
5667 -- ----------------------------------------------------------------------------
5668 PROCEDURE check_if_element_qualifies
5669       (p_element_entry_id                  IN  NUMBER
5670       ,p_element_type_id                   OUT NOCOPY NUMBER
5671       ,p_include                           OUT NOCOPY VARCHAR2 -- Y/N
5672       ,p_extract_type                      IN  VARCHAR2 DEFAULT 'PERIODIC'
5673       ,p_element_type_id_from_crit         IN  NUMBER DEFAULT NULL
5674       )
5675 IS
5676   --
5677     l_proc_name           VARCHAR2(61):=
5678      g_proc_name||'check_if_element_qualifies';
5679 
5680     l_element_type_id     NUMBER;
5681 
5682 BEGIN
5683   debug_enter(l_proc_name);
5684   debug ('p_element_entry_id:'||p_element_entry_id);
5685 
5686   -- check if this element_entry_id has been processed earlier
5687   -- if yes, return data from global collection
5688   IF g_elements_processed.EXISTS(p_element_entry_id)
5689   THEN
5690     debug('found p_element_entry_id in g_elements_processed',10);
5691 
5692     p_element_type_id :=
5693       g_elements_processed(p_element_entry_id).element_type_id;
5694 
5695     /*
5696     -- if cutover, then dont process the same element twice
5697     -- hence send inclusion flag as 'N' if found in collection
5698     IF    p_extract_type = 'CUTOVER'
5699     THEN
5700       p_include := 'N';
5701     ELSE
5702       p_include :=
5703         g_elements_processed(p_element_entry_id).inclusion_flag;
5704     END IF;
5705     */
5706 
5707     p_include :=
5708       g_elements_processed(p_element_entry_id).inclusion_flag;
5709 
5710     g_curr_element_type_id  := p_element_type_id;
5711     g_curr_element_entry_id := p_element_entry_id;
5712 
5713     debug('g_curr_element_type_id : '||g_curr_element_type_id, 20);
5714     debug('g_curr_element_entry_id : '||g_curr_element_entry_id, 30);
5715 
5716 
5717   ELSE -- 1st time processing, not found in g_elements_processed
5718 
5719     -- if CUTOVER, implies that this has been called from Payroll_Rule
5720     -- and element_type_id has been passed as p_element_type_id_from_crit
5721     --
5722     debug('first time processing ...');
5723     debug('p_extract_type :' || p_extract_type, 20);
5724     debug('p_element_type_id_from_crit :' || p_element_type_id_from_crit, 30);
5725 
5726     IF   p_extract_type = 'CUTOVER' -- from cutover rule : element repeating
5727       OR p_element_type_id_from_crit IS NOT NULL -- from periodic rule : element repeating
5728     THEN
5729       p_element_type_id := p_element_type_id_from_crit;
5730     ELSE -- PERIODIC run : person repeating
5731 
5732       OPEN csr_get_element_type_id
5733            (c_element_entry_id => p_element_entry_id
5734            );
5735       FETCH csr_get_element_type_id INTO l_element_type_id;
5736         IF csr_get_element_type_id%NOTFOUND
5737         THEN
5738           debug('element_type_id not found', 40);
5739           p_element_type_id := -1; -- returning -1 when not found
5740           p_include         := 'N';
5741         ELSE
5742           p_element_type_id := l_element_type_id;
5743           debug('l_element_type_id : ' || l_element_type_id, 50);
5744         END IF; -- csr_get_element_type_id%NOTFOUND
5745       CLOSE csr_get_element_type_id;
5746 
5747     END IF;
5748     --
5749 
5750     -- now check if this element_type_id exists in the global collection
5751     IF g_elements_of_info_type.EXISTS(p_element_type_id)
5752     THEN
5753       p_include       := 'Y';
5754     ELSE
5755       p_include       := 'N';
5756     END IF;
5757     debug('p_include : ' || p_include, 60);
5758 
5759     -- store in a collection for future use in the beginning IF statement
5760     g_elements_processed(p_element_entry_id).element_type_id := p_element_type_id;
5761     g_elements_processed(p_element_entry_id).inclusion_flag := p_include;
5762 
5763     g_curr_element_type_id := p_element_type_id;
5764     g_curr_element_entry_id := p_element_entry_id;
5765 
5766     debug('g_curr_element_type_id : '||g_curr_element_type_id, 70);
5767     debug('g_curr_element_entry_id : '||g_curr_element_entry_id, 80);
5768 
5769   END IF; -- g_elements_processed.EXISTS(p_element_entry_id)
5770 
5771 
5772   debug_exit(l_proc_name);
5773   EXCEPTION
5774     WHEN others THEN
5775         IF SQLCODE <> hr_utility.hr_error_number
5776         THEN
5777             debug_others (l_proc_name, 10);
5778             IF g_debug
5779             THEN
5780               DEBUG (   'Leaving: '
5781                      || l_proc_name, -999);
5782              END IF;
5783              fnd_message.raise_error;
5784          ELSE
5785              RAISE;
5786          END IF;
5787 
5788 END check_if_element_qualifies;
5789 
5790 
5791 
5792 
5793 -- ----------------------------------------------------------------------------
5794 -- |------------------------< calc_payment_by_run_rslt >----------------------|
5795 -- ----------------------------------------------------------------------------
5796 -- to return the run result value for the assignment
5797 
5798 FUNCTION calc_payment_by_run_rslt
5799       (p_assignment_id    IN NUMBER
5800   ,p_element_entry_id IN NUMBER
5801   ,p_element_type_id  IN NUMBER
5802   ,p_date_earned      IN DATE
5803   )  RETURN NUMBER
5804 IS
5805 
5806   l_proc_name           VARCHAR2(61):=
5807      g_proc_name||'calc_payment_by_run_rslt';
5808 
5809 
5810   l_asg_act_id         NUMBER := NULL;
5811   l_retro_asg_act_id NUMBER := NULL;
5812 
5813   l_run_result_value NUMBER := NULL;
5814   l_retro_run_result_value NUMBER := 0;
5815   l_run_result_id    NUMBER;
5816 
5817   l_element_type_id  NUMBER;
5818   l_input_value_id   NUMBER;
5819 
5820   l_retro_element_type_id NUMBER;
5821 
5822   -- cursor to find retro_element_type_id
5823   CURSOR csr_get_retro_ele_type_id
5824   IS
5825   select retro_summ_ele_id
5826     from pay_element_types_f
5827    where element_type_id = p_element_type_id
5828    and rownum=1;
5829 
5830 
5831 BEGIN
5832   debug_enter(l_proc_name);
5833 
5834     debug('p_assignment_id :' || p_assignment_id);
5835     debug('p_element_entry_id :'||p_element_entry_id);
5836     debug('p_element_type_id :'||p_element_type_id);
5837     debug('p_date_earned :' || p_date_earned);
5838 
5839 
5840     -- Step 1) get assignment action id
5841     OPEN csr_get_asg_act_id
5842            ( p_assignment_id   => p_assignment_id
5843             ,p_date_earned     => p_date_earned
5844            );
5845     LOOP -- 115.60 : loop thru all assignment actions
5846 
5847       FETCH csr_get_asg_act_id INTO l_asg_act_id;
5848       EXIT WHEN csr_get_asg_act_id%NOTFOUND;
5849 
5850         debug('l_asg_act_id : '||l_asg_act_id, 15);
5851         debug('call csr_get_run_result_value for this assignment action id ...',17);
5852 
5853         -- Step 2) find run_results for this assignment_action, element entry and input value
5854         OPEN csr_get_run_result_value
5855             (p_element_entry_id => p_element_entry_id -- p_element_type_id
5856             ,p_input_value_id   =>
5857                 g_elements_of_info_type(p_element_type_id).input_value_id
5858             ,p_asg_act_id       => l_asg_act_id
5859             );
5860         FETCH csr_get_run_result_value INTO l_run_result_value, l_run_result_id;
5861           IF csr_get_run_result_value%FOUND
5862           THEN
5863             debug('l_run_result_value found....',20);
5864             debug('l_run_result_value : '||l_run_result_value);
5865             CLOSE csr_get_run_result_value;
5866             EXIT; -- if the run result was found in this assignment_action_id,
5867                   -- then exit
5868                   -- else go for next assignment_action_id
5869           END IF;
5870           debug('l_run_result_value not found yet',25);
5871         CLOSE csr_get_run_result_value;
5872 
5873     END LOOP;
5874     CLOSE csr_get_asg_act_id;
5875 
5876     --
5877     -- added as part of 115.58 (3)
5878     --
5879     -- BLOCK for retro payments
5880 
5881     -- 1) find if this element has a retro element
5882     IF g_elements_of_info_type(p_element_type_id).retro_summ_ele_id IS NOT NULL
5883     THEN -- retro element is attached to this element
5884 
5885       debug('this main element has a retro element ',40);
5886 
5887       l_retro_element_type_id :=
5888           g_elements_of_info_type(p_element_type_id).retro_summ_ele_id;
5889       debug('l_retro_element_type_id :' || l_retro_element_type_id,50);
5890 
5891       -- 2) retro element has been found for this main element,
5892       --    now find retro assignment action id
5893 
5894       OPEN csr_get_asg_act_id_retro
5895              ( p_assignment_id   => p_assignment_id
5896               ,p_date_earned     => p_date_earned
5897              );
5898       LOOP
5899         FETCH csr_get_asg_act_id_retro INTO l_retro_asg_act_id;
5900         EXIT WHEN csr_get_asg_act_id_retro%NOTFOUND;
5901 
5902           debug('l_retro_asg_act_id : '||l_retro_asg_act_id, 35);
5903 
5904           -- 3) now find and add retro payments which were earned in this month
5905           FOR l_retro_run_results IN csr_get_retro_run_value
5906                                      (p_assignment_action_id => l_retro_asg_act_id
5907                                      ,p_effective_date       => ben_ext_person.g_effective_date
5908                                      )
5909           LOOP
5910             debug('input_value_id : '|| l_retro_run_results.input_value_id,60);
5911             debug('result_value : '|| l_retro_run_results.result_value);
5912             debug('effective_date : '|| l_retro_run_results.effective_date);
5913             debug('element_entry_id : '|| l_retro_run_results.element_entry_id);
5914             debug('element_type_id : '|| l_retro_run_results.element_type_id);
5915             debug('effective_start_date : '|| l_retro_run_results.effective_start_date);
5916             debug('effective_end_date : '|| l_retro_run_results.effective_end_date);
5917             debug('Element source_id : '|| l_retro_run_results.ee_source_id);
5918             debug('Run Result source_id : '|| l_retro_run_results.rr_source_id);
5919             debug('status : '|| l_retro_run_results.status);
5920             debug('source_type : '|| l_retro_run_results.source_type);
5921 
5922 
5923             IF l_retro_run_results.result_value IS NOT NULL
5924               and l_retro_run_results.element_type_id = l_retro_element_type_id
5925               and l_retro_run_results.ee_source_id = l_run_result_id
5926             THEN -- run result is not empty
5927                  -- and element_type_id of retro element = retro_summ_ele_id of main element
5928               -- 3) add all retro values of this element and this payroll period
5929               l_retro_run_result_value :=
5930                 l_retro_run_result_value + l_retro_run_results.result_value;
5931 
5932               debug('l_retro_run_result_value : '|| l_retro_run_result_value);
5933             END IF;
5934           END LOOP;
5935 
5936       END LOOP; -- OPEN csr_get_asg_act_id_retro
5937       CLOSE csr_get_asg_act_id_retro;
5938 
5939     END IF; -- IF g_elements_of_info_type(p_element_type_id).retro_summ_ele_id IS NOT NULL
5940 
5941 
5942     debug('l_run_result_value : ' || l_run_result_value,70);
5943     debug('l_retro_run_result_value : ' || l_retro_run_result_value,80);
5944     -- add the run results and retro results
5945     IF l_run_result_value IS NOT NULL
5946       OR l_retro_run_result_value IS NOT NULL
5947     THEN
5948       l_run_result_value := nvl(l_run_result_value,0) + nvl(l_retro_run_result_value,0);
5949     END IF;
5950 
5951     debug('l_run_result_value : ' || l_run_result_value,90);
5952 
5953   debug_exit(l_proc_name);
5954 
5955   return l_run_result_value;
5956 
5957   EXCEPTION
5958     WHEN others THEN
5959         IF SQLCODE <> hr_utility.hr_error_number
5960         THEN
5961             debug_others (l_proc_name, 10);
5962             IF g_debug
5963             THEN
5964               DEBUG (   'Leaving: '
5965                      || l_proc_name, -999);
5966              END IF;
5967              fnd_message.raise_error;
5968          ELSE
5969              RAISE;
5970          END IF;
5971 
5972 END calc_payment_by_run_rslt;
5973 
5974 
5975 -- ----------------------------------------------------------------------------
5976 -- |------------------------< get_element_payment >---------------------------|
5977 -- ----------------------------------------------------------------------------
5978 
5979 FUNCTION get_element_payment
5980       (p_assignment_id      IN NUMBER
5981   ,p_element_entry_id   IN NUMBER
5982   ,p_element_type_id    IN NUMBER
5983   ,p_effective_date     IN DATE
5984   )  RETURN NUMBER
5985 IS
5986 
5987 
5988   l_proc_name           VARCHAR2(61):=
5989      g_proc_name||'get_element_payment';
5990 
5991   l_date_earned   DATE;
5992   l_payment       NUMBER := NULL;
5993 
5994 BEGIN
5995 
5996   debug_enter(l_proc_name);
5997   debug('p_assignment_id :' || p_assignment_id) ;
5998   debug('p_effective_date :' ||to_char(p_effective_date,'DD/MM/YYYY')) ;
5999 
6000     OPEN csr_get_next_payroll_date
6001            ( p_assignment_id    => p_assignment_id
6002             ,p_effective_date   => p_effective_date
6003             );
6004     FETCH csr_get_next_payroll_date INTO l_date_earned;
6005 
6006       IF csr_get_next_payroll_date%FOUND THEN
6007 
6008         debug('l_date_earned :' ||to_char(l_date_earned,'DD/MM/YYYY')) ;
6009         l_payment := calc_payment_by_run_rslt
6010                          ( p_assignment_id    => p_assignment_id
6011                           ,p_element_entry_id => p_element_entry_id
6012                           ,p_element_type_id  => p_element_type_id
6013                           ,p_date_earned      => l_date_earned
6014                           );
6015         debug('l_payment :' || l_payment);
6016 
6017       ELSE
6018         debug('csr_get_next_payroll_date not found') ;
6019         --l_payment := 0;
6020       END IF;
6021 
6022     CLOSE csr_get_next_payroll_date;
6023 
6024   debug_exit(l_proc_name);
6025   return l_payment;
6026 
6027   EXCEPTION
6028     WHEN others THEN
6029         IF SQLCODE <> hr_utility.hr_error_number
6030         THEN
6031             debug_others (l_proc_name, 10);
6032             IF g_debug
6033             THEN
6034               DEBUG (   'Leaving: '
6035                      || l_proc_name, -999);
6036              END IF;
6037              fnd_message.raise_error;
6038          ELSE
6039              RAISE;
6040          END IF;
6041 
6042 END get_element_payment;
6043 
6044 
6045 
6046 -- ----------------------------------------------------------------------------
6047 -- |------------------------< get_value_from_balance >----------------------|
6048 -- ----------------------------------------------------------------------------
6049 -- to return the balance value of an assignment, date earned, element entry
6050 FUNCTION get_value_from_balance
6051       (p_assignment_id    IN NUMBER
6052   ,p_element_entry_id IN NUMBER
6053   ,p_balance_type_id  IN NUMBER
6054   ,p_date_earned      IN DATE
6055   ,p_asg_act_id       OUT NOCOPY NUMBER
6056   ,p_retro_asg_act_id OUT NOCOPY NUMBER
6057   )  RETURN NUMBER
6058 IS
6059 
6060   l_proc_name           VARCHAR2(61):=
6061      g_proc_name||'get_value_from_balance';
6062 
6063   l_asg_act_id          NUMBER := NULL;
6064   l_source_asg_act_id NUMBER := NULL;
6065   l_balance_value NUMBER := NULL;
6066 
6067 BEGIN
6068 
6069   debug_enter(l_proc_name);
6070 
6071     -- Step 1) get assignment action id
6072     OPEN csr_get_all_asg_act_id
6073            ( p_assignment_id   => p_assignment_id
6074             ,p_date_earned     => p_date_earned
6075             ,p_element_entry_id => p_element_entry_id
6076            );
6077     LOOP -- loop thru all assignment actions
6078 
6079       FETCH csr_get_all_asg_act_id INTO l_asg_act_id, l_source_asg_act_id;
6080       EXIT WHEN csr_get_all_asg_act_id%NOTFOUND;
6081 
6082         debug('l_asg_act_id : '||l_asg_act_id, 15);
6083         debug('l_source_asg_act_id : '||l_source_asg_act_id, 16);
6084         debug('call hr_gbbal.calc_element_ptd_bal for this assignment action id ...',17);
6085 
6086         -- Step 2) fetch from balance for this assignment_action and element entry
6087         l_balance_value :=
6088              hr_gbbal.calc_element_ptd_bal(p_assignment_action_id => l_asg_act_id
6089                                           ,p_balance_type_id      => p_balance_type_id
6090                                           ,p_source_id                => p_element_entry_id);
6091 
6092 
6093         IF l_balance_value IS NOT NULL
6094         THEN
6095 
6096           debug('l_balance_value found....',20);
6097           debug('l_balance_value : '||l_balance_value,21);
6098           debug('l_asg_act_id : '||l_asg_act_id, 22);
6099           debug('l_source_asg_act_id : '||l_source_asg_act_id, 23);
6100           p_asg_act_id       := l_asg_act_id;
6101           p_retro_asg_act_id := l_source_asg_act_id;
6102 
6103           EXIT; -- if the run result was found in this assignment_action_id,
6104                 -- then exit
6105                 -- else go for next assignment_action_id
6106         END IF;
6107         debug('l_balance_value not found yet',25);
6108 
6109     END LOOP;
6110     CLOSE csr_get_all_asg_act_id;
6111 
6112   debug_exit(l_proc_name);
6113 
6114   return l_balance_value;
6115 
6116   EXCEPTION
6117     WHEN others THEN
6118         IF SQLCODE <> hr_utility.hr_error_number
6119         THEN
6120             debug_others (l_proc_name, 10);
6121             IF g_debug
6122             THEN
6123               DEBUG (   'Leaving: '
6124                      || l_proc_name, -999);
6125              END IF;
6126              fnd_message.raise_error;
6127          ELSE
6128              RAISE;
6129          END IF;
6130 
6131 END get_value_from_balance;
6132 
6133 
6134 
6135 -- ----------------------------------------------------------------------------
6136 -- |------------------------< calc_payment_from_balance >----------------------|
6137 -- ----------------------------------------------------------------------------
6138 -- to return the run result value for the assignment
6139 
6140 FUNCTION calc_payment_from_balance
6141       (p_assignment_id    IN NUMBER
6142   ,p_element_entry_id IN NUMBER
6143   ,p_element_type_id  IN NUMBER
6144   ,p_balance_type_id  IN NUMBER
6145   ,p_date_earned      IN DATE
6146   )  RETURN NUMBER
6147 IS
6148 
6149   l_proc_name           VARCHAR2(61):=
6150      g_proc_name||'calc_payment_from_balance';
6151 
6152 
6153   l_asg_act_id          NUMBER := NULL;
6154   l_retro_asg_act_id  NUMBER := NULL;
6155   l_number            NUMBER := NULL;
6156 
6157   l_balance_ele_value         NUMBER := NULL;
6158   l_retro_balance_ele_value   NUMBER := NULL;
6159   l_total_retro_bal_ele_value NUMBER := 0;
6160 
6161 
6162   l_run_results_dtls csr_run_rslt_indirect_ele%rowtype;
6163   l_retro_ele        csr_retro_ele%rowtype;
6164 
6165   -- cursor to find retro_element_type_id
6166   CURSOR csr_get_retro_ele_type_id
6167   IS
6168   select retro_summ_ele_id
6169     from pay_element_types_f
6170    where element_type_id = p_element_type_id
6171    and rownum=1;
6172 
6173 
6174 BEGIN
6175   debug_enter(l_proc_name);
6176 
6177     debug('p_assignment_id :' || p_assignment_id);
6178     debug('p_element_entry_id :'||p_element_entry_id);
6179     debug('p_element_type_id :'||p_element_type_id);
6180     debug('p_date_earned :' || p_date_earned);
6181 
6182     -- get the balance value for this element and its indirects
6183     l_balance_ele_value := get_value_from_balance
6184                               (p_assignment_id    => p_assignment_id
6185                               ,p_element_entry_id => p_element_entry_id
6186                               ,p_balance_type_id  => p_balance_type_id
6187                               ,p_date_earned      => p_date_earned
6188                               ,p_asg_act_id       => l_asg_act_id -- OUT
6189                               ,p_retro_asg_act_id => l_retro_asg_act_id -- OUT
6190                               );
6191 
6192 
6193     --
6194     -- BLOCK for retro payments
6195     --
6196 
6197     -- Step 1) get data from pay_run_results
6198     --         for this element_entry_id and assignment action
6199     -- Note : l_asg_act_id is the assignment_action which had returned
6200     -- the balance value in the call above
6201     IF l_asg_act_id IS NOT NULL
6202      and
6203        l_retro_asg_act_id IS NOT NULL
6204     THEN
6205 
6206       -- get run_result details for this element entry and its indirect elements
6207       OPEN csr_run_rslt_indirect_ele
6208          (p_source_id      => p_element_entry_id
6209          ,p_asg_act_id     => l_asg_act_id
6210          );
6211       LOOP -- loop thru all the run_result_ids
6212         FETCH csr_run_rslt_indirect_ele INTO l_run_results_dtls;
6213         EXIT WHEN csr_run_rslt_indirect_ele%NOTFOUND;
6214 
6215           debug('l_run_results_dtls.run_result_id : '||l_run_results_dtls.run_result_id, 30);
6216           debug('ELEMENT_TYPE_ID      : '||l_run_results_dtls.run_result_id, 30);
6217           debug('ASSIGNMENT_ACTION_ID : '||l_run_results_dtls.assignment_action_id, 30);
6218           debug('ENTRY_TYPE           : '||l_run_results_dtls.entry_type, 30);
6219           debug('SOURCE_ID            : '||l_run_results_dtls.source_id, 30);
6220           debug('SOURCE_TYPE          : '||l_run_results_dtls.source_type, 30);
6221           debug('STATUS               : '||l_run_results_dtls.status, 30);
6222           debug('ELEMENT_ENTRY_ID     : '||l_run_results_dtls.element_entry_id, 30);
6223 
6224           debug('l_run_results_dtls.run_result_id : ' || l_run_results_dtls.run_result_id);
6225           debug('l_retro_asg_act_id : ' || l_retro_asg_act_id );
6226           debug('ben_ext_person.g_effective_date : ' || ben_ext_person.g_effective_date );
6227 
6228           -- fetch retro elements using this main elements run_result_id
6229           OPEN csr_retro_ele
6230                  (p_assignment_id        => p_assignment_id
6231                  ,p_source_id            => l_run_results_dtls.run_result_id
6232                  ,p_source_asg_action_id => l_retro_asg_act_id
6233                  ,p_effective_date       => ben_ext_person.g_effective_date -- p_date_earned
6234                  );
6235           LOOP -- loop thru all the retro elements returned
6236             FETCH csr_retro_ele INTO l_retro_ele;
6237             EXIT WHEN csr_retro_ele%NOTFOUND;
6238 
6239               debug('l_retro_ele.element_entry_id : '||l_retro_ele.element_entry_id, 40);
6240               debug('effective_start_date         : '||l_retro_ele.effective_start_date, 40);
6241               debug('effective_end_date           : '||l_retro_ele.effective_end_date, 40);
6242               debug('source_id                    : '||l_retro_ele.source_id, 40);
6243               debug('source_asg_action_id         : '||l_retro_ele.source_asg_action_id, 40);
6244               debug('source_start_date            : '||l_retro_ele.source_start_date, 40);
6245               debug('source_end_date              : '||l_retro_ele.source_end_date, 40);
6246               debug('element_type_id              : '||l_retro_ele.element_type_id, 40);
6247               debug('p_assignment_id              : '||p_assignment_id, 40);
6248 
6249               -- get the balance value for this element and its indirects
6250               l_retro_balance_ele_value := get_value_from_balance
6251                                             (p_assignment_id        => p_assignment_id
6252                                             ,p_element_entry_id => l_retro_ele.element_entry_id
6253                                             ,p_balance_type_id  => p_balance_type_id
6254                                             ,p_date_earned      => l_retro_ele.effective_end_date
6255                                             ,p_asg_act_id       => l_number -- OUT
6256                                             ,p_retro_asg_act_id => l_number -- OUT
6257                                             );
6258               IF l_retro_balance_ele_value IS NOT NULL
6259               THEN
6260                 -- add all retro values of each element returned as retro elements.
6261                 -- All retro elements pertaining to the main element's run_Result_id need
6262                 -- to be summed up
6263                 l_total_retro_bal_ele_value :=
6264                     l_total_retro_bal_ele_value + l_retro_balance_ele_value;
6265               END IF;
6266 
6267               debug('l_total_retro_bal_ele_value : '||l_total_retro_bal_ele_value, 40);
6268           END LOOP;
6269           CLOSE csr_retro_ele;
6270           --
6271       END LOOP;
6272       CLOSE csr_run_rslt_indirect_ele;
6273 
6274     END IF; -- l_asg_act_id IS NOT NULL
6275 
6276     debug('l_balance_ele_value : ' || l_balance_ele_value,50);
6277     debug('l_total_retro_bal_ele_value : ' || l_total_retro_bal_ele_value,60);
6278 
6279     -- add the element balance value and the retro value
6280     IF l_balance_ele_value IS NOT NULL
6281       OR
6282        l_total_retro_bal_ele_value IS NOT NULL
6283     THEN
6284       l_balance_ele_value := nvl(l_balance_ele_value,0) + nvl(l_total_retro_bal_ele_value,0);
6285     END IF;
6286 
6287 
6288     debug('l_balance_ele_value : ' || l_balance_ele_value,70);
6289 
6290   debug_exit(l_proc_name);
6291 
6292   return l_balance_ele_value;
6293 
6294   EXCEPTION
6295     WHEN others THEN
6296         IF SQLCODE <> hr_utility.hr_error_number
6297         THEN
6298             debug_others (l_proc_name, 10);
6299             IF g_debug
6300             THEN
6301               DEBUG (   'Leaving: '
6302                      || l_proc_name, -999);
6303              END IF;
6304              fnd_message.raise_error;
6305          ELSE
6306              RAISE;
6307          END IF;
6308 
6309 END calc_payment_from_balance;
6310 
6311 
6312 
6313 -- ----------------------------------------------------------------------------
6314 -- |------------------------< get_element_payment_balance >--------------------|
6315 -- ----------------------------------------------------------------------------
6316 
6317 FUNCTION get_element_payment_balance
6318       (p_assignment_id      IN NUMBER
6319   ,p_element_entry_id   IN NUMBER
6320   ,p_element_type_id    IN NUMBER
6321   ,p_balance_type_id    IN NUMBER
6322   ,p_effective_date     IN DATE
6323   )  RETURN NUMBER
6324 IS
6325 
6326 
6327   l_proc_name           VARCHAR2(61):=
6328      g_proc_name||'get_element_payment_balance';
6329 
6330   l_date_earned   DATE;
6331   l_payment       NUMBER := NULL;
6332 
6333 BEGIN
6334 
6335   debug_enter(l_proc_name);
6336   debug('p_assignment_id :' || p_assignment_id) ;
6337   debug('p_effective_date :' ||to_char(p_effective_date,'DD/MM/YYYY')) ;
6338 
6339     OPEN csr_get_next_payroll_date
6340            ( p_assignment_id    => p_assignment_id
6341             ,p_effective_date   => p_effective_date
6342             );
6343     FETCH csr_get_next_payroll_date INTO l_date_earned;
6344 
6345       IF csr_get_next_payroll_date%FOUND THEN
6346 
6347         debug('l_date_earned :' ||to_char(l_date_earned,'DD/MM/YYYY')) ;
6348         l_payment := calc_payment_from_balance
6349                          ( p_assignment_id    => p_assignment_id
6350                           ,p_element_entry_id => p_element_entry_id
6351                           ,p_element_type_id  => p_element_type_id
6352                           ,p_balance_type_id  => p_balance_type_id
6353                           ,p_date_earned      => l_date_earned
6354                           );
6355         debug('l_payment :' || l_payment);
6356 
6357       ELSE
6358         debug('csr_get_next_payroll_date not found') ;
6359         --l_payment := 0;
6360       END IF;
6361 
6362     CLOSE csr_get_next_payroll_date;
6363 
6364   debug_exit(l_proc_name);
6365   return l_payment;
6366 
6367   EXCEPTION
6368     WHEN others THEN
6369         IF SQLCODE <> hr_utility.hr_error_number
6370         THEN
6371             debug_others (l_proc_name, 10);
6372             IF g_debug
6373             THEN
6374               DEBUG (   'Leaving: '
6375                      || l_proc_name, -999);
6376              END IF;
6377              fnd_message.raise_error;
6378          ELSE
6379              RAISE;
6380          END IF;
6381 
6382 END get_element_payment_balance;
6383 
6384 
6385 
6386 
6387 
6388 
6389 
6390 
6391 
6392 
6393 -- ----------------------------------------------------------------------------
6394 -- |--------------------< ele_entry_inp_val_cut_crit >----------------------|
6395 -- Description:
6396 -- ----------------------------------------------------------------------------
6397 FUNCTION ele_entry_inp_val_cut_crit
6398             (
6399               p_ext_pay_input_value   IN VARCHAR2
6400              ,p_ext_pay_element_type  IN VARCHAR2
6401              ,p_ext_pay_element_entry IN VARCHAR2
6402              ,p_output                OUT NOCOPY VARCHAR2
6403             )RETURN VARCHAR2
6404 IS
6405 
6406   l_proc_name           VARCHAR2(61):=
6407      g_proc_name||'ele_entry_inp_val_cut_crit';
6408 
6409     l_include  varchar2(1) :=  'Y';
6410     l_curr_evt_index        NUMBER;
6411     l_input_value_id        NUMBER;
6412     l_element_type_id       NUMBER;
6413     l_return                NUMBER;
6414 BEGIN
6415   debug_enter(l_proc_name);
6416 
6417   debug('p_ext_pay_input_value :'|| p_ext_pay_input_value);
6418   debug('p_ext_pay_element_type :'|| p_ext_pay_element_type);
6419   debug('p_ext_pay_element_entry :'|| p_ext_pay_element_entry);
6420 
6421 
6422   check_if_element_qualifies
6423       (p_element_entry_id           => p_ext_pay_element_entry -- IN  NUMBER
6424       ,p_element_type_id            => l_element_type_id  -- OUT NOCOPY NUMBER
6425       ,p_include                    => p_output -- OUT NOCOPY VARCHAR2 -- Y/N
6426       ,p_extract_type               => 'CUTOVER' -- IN  VARCHAR2 DEFAULT 'PERIODIC'
6427       ,p_element_type_id_from_crit  => p_ext_pay_element_type  -- IN  NUMBER DEFAULT NULL
6428       );
6429 
6430   IF p_output = 'Y' THEN
6431     IF g_elements_of_info_type(g_curr_element_type_id).eei_information4 <> 'Y' THEN
6432          debug('ERROR: Not a Pensionable Allowance, will not be processed.');
6433          l_return :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
6434                       (p_error_number        =>    94528
6435                       ,p_error_text          =>    'BEN_94528_NOT_PEN_ALLOWANCE'
6436                       ,p_token1              =>
6437                            g_elements_of_info_type(g_curr_element_type_id).element_name
6438                       );
6439          debug('Returning N ..');
6440          p_output := 'N';
6441 
6442     --ELSE
6443     --    debug('Is a Pensionable Allowance');
6444         -- check for dupliate bonus types
6445     --    chk_dup_bon_types();
6446     END IF;
6447   END IF;
6448 
6449   debug_exit(l_proc_name);
6450   RETURN p_output;
6451 
6452   EXCEPTION
6453     WHEN others THEN
6454         IF SQLCODE <> hr_utility.hr_error_number
6455         THEN
6456             debug_others (l_proc_name, 10);
6457             IF g_debug
6458             THEN
6459               DEBUG (   'Leaving: '
6460                      || l_proc_name, -999);
6461              END IF;
6462              fnd_message.raise_error;
6463          ELSE
6464              RAISE;
6465          END IF;
6466 
6467 END ele_entry_inp_val_cut_crit;
6468 
6469 
6470 
6471 -- ----------------------------------------------------------------------------
6472 -- |--------------------< ele_entry_inp_val_per_crit >----------------------|
6473 -- Description:
6474 -- ----------------------------------------------------------------------------
6475 FUNCTION ele_entry_inp_val_per_crit
6476             (
6477               p_ext_pay_input_value   IN VARCHAR2
6478              ,p_ext_pay_element_type  IN VARCHAR2
6479              ,p_ext_pay_element_entry IN VARCHAR2
6480              ,p_output                OUT NOCOPY VARCHAR2
6481             )RETURN VARCHAR2
6482 IS
6483 
6484   l_proc_name           VARCHAR2(61):=
6485      g_proc_name||'ele_entry_inp_val_per_crit';
6486 
6487 
6488     CURSOR csr_get_element_entry_id
6489             (p_element_entry_value_id    IN NUMBER
6490             )
6491      IS
6492             SELECT element_entry_id
6493             FROM PAY_ELEMENT_ENTRY_VALUES_F
6494             WHERE element_entry_value_id =p_element_entry_value_id
6495             AND ROWNUM=1;
6496 
6497 
6498     l_include             varchar2(1) :=  'Y';
6499     l_curr_evt_index      NUMBER;
6500     l_input_value_id      NUMBER;
6501     l_element_type_id     NUMBER;
6502     l_element_entry_id    NUMBER;
6503     l_index               NUMBER;
6504     l_return              NUMBER;
6505 
6506     l_chg_table_id        NUMBER;
6507     l_chg_column_name     VARCHAR2(30);
6508     l_chg_table           VARCHAR2(30);
6509     l_chg_type            VARCHAR2(10);
6510     l_chg_date            DATE;
6511     l_chg_surrogate_key   NUMBER;
6512     l_update_type         VARCHAR2(5);
6513 
6514     l_chg_of_element_yn   VARCHAR2(1);
6515     l_report_all          VARCHAR2(1);
6516     l_is_terminated       VARCHAR2(1) := 'N';
6517     l_is_spread_bonus_yn  VARCHAR2(1) := NULL;
6518     l_claim_date          VARCHAR2(60);
6519 
6520 BEGIN
6521   debug_enter(l_proc_name);
6522 
6523   debug('p_ext_pay_input_value :'|| p_ext_pay_input_value);
6524   debug('p_ext_pay_element_type :'|| p_ext_pay_element_type);
6525   debug('p_ext_pay_element_entry :'|| p_ext_pay_element_entry);
6526 
6527 /*
6528 PQP_GB_PSI_ASSIGNMENT_STATUS - yes
6529 PQP_GB_PSI_FTE_VALUE - no
6530 PQP_GB_PSI_NEW_HIRE - will go into today_sal_start
6531 PQP_GB_PSI_SAL_CONTRACT - no
6532 PQP_GB_PSI_ALL_ELEMENT_ENTRIES
6533 -- PQP_GB_PSI_SAL_GRADE
6534 PQP_GB_PSI_EMP_TERMINATIONS - yes
6535 */
6536   l_index := ben_ext_person.g_chg_pay_evt_index;
6537 
6538   debug('l_index :'|| l_index,20);
6539 
6540   l_chg_type            :=  g_pay_proc_evt_tab(l_index).update_type;
6541     debug('l_chg_type : ' || l_chg_type);
6542   l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
6543     debug('l_chg_table_id :' || l_chg_table_id);
6544   l_chg_table           :=  get_dated_table_name(l_chg_table_id);
6545     debug('l_chg_table : ' || l_chg_table);
6546   l_chg_date            :=  g_pay_proc_evt_tab(l_index).effective_date;
6547     debug('l_chg_date : ' || l_chg_date);
6548   l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
6549     debug('l_chg_column_name : ' || l_chg_column_name);
6550   l_chg_surrogate_key :=  ben_ext_person.g_chg_surrogate_key;
6551     debug('l_chg_surrogate_key : ' || l_chg_surrogate_key);
6552 
6553 
6554 
6555 
6556   IF   l_chg_table <> 'PAY_ELEMENT_ENTRIES_F'
6557     AND l_chg_table <> 'PAY_ELEMENT_ENTRY_VALUES_F'
6558     -- OR (l_chg_table = 'PAY_ELEMENT_ENTRIES_F' AND l_chg_type = 'E')
6559   THEN
6560     l_chg_of_element_yn := 'N'; -- event not of element type
6561   ELSE
6562     l_chg_of_element_yn := 'Y';
6563   END IF;
6564 
6565 
6566 
6567     IF is_today_sal_start() = 'Y' THEN -- salary start => report all elements
6568       --g_is_terminated := 'N'; -- change termination status to N
6569       l_is_terminated := 'N'; -- change termination status to N
6570       l_report_all    := 'Y';
6571     ELSIF is_today_sal_end() = 'Y' THEN -- salary end => report all
6572       -- g_is_terminated := 'Y'; -- change termination status to 'Y'
6573       l_is_terminated := 'Y'; -- change termination status to 'Y'
6574       l_report_all    := 'Y';
6575     ELSIF ( l_chg_table = 'PER_ALL_ASSIGNMENTS_F'
6576       AND l_chg_column_name = 'ASSIGNMENT_STATUS_TYPE_ID') THEN
6577 
6578         -- if the event is on assignment_status_type_id
6579         -- reject the event
6580         debug('Salary not Started or Ended Today');
6581         debug('l_chg_table: '||l_chg_table, 15);
6582         debug('l_chg_column_name: '||l_chg_column_name, 20);
6583         debug('Not a valid event, will not be processed',25);
6584         p_output := 'N';
6585         debug_exit(l_proc_name);
6586         RETURN p_output;
6587 
6588     ELSIF l_chg_of_element_yn = 'N' THEN -- event not of element_entries/value type => report all
6589       l_is_terminated := NULL;
6590       l_report_all := 'Y';
6591     ELSE -- event of element type, report for that element
6592       l_is_terminated := NULL;
6593       l_report_all := 'N';
6594     END IF;
6595     --
6596     debug('l_is_terminated : ' || l_is_terminated,20);
6597     debug('l_report_all :' || l_report_all, 30);
6598 
6599 
6600   IF   g_is_terminated = 'N'
6601     OR l_is_terminated = 'Y'
6602     OR (l_is_terminated = 'N' AND l_report_all = 'Y') -- Added as part of 115.58 (3)
6603 
6604   THEN
6605       --
6606 /*    IF   is_today_sal_start() = 'Y' -- salary start => report all elements
6607       OR is_today_sal_end () = 'Y'  -- salary end => report all
6608       OR l_chg_of_element_yn = 'N' -- event not of element_entries/value type => report all
6609 */
6610 
6611     -- check for element end
6612     IF l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
6613         AND l_chg_type = 'E' THEN
6614         debug(' element end event ',25);
6615         g_allowance_has_end_dated := 'Y';
6616     ELSE
6617         g_allowance_has_end_dated := 'N';
6618     END IF;
6619 
6620 
6621     IF l_report_all = 'Y'
6622     THEN
6623       check_if_element_qualifies
6624           (p_element_entry_id           => p_ext_pay_element_entry -- IN  NUMBER
6625           ,p_element_type_id            => l_element_type_id  -- OUT NOCOPY NUMBER
6626           ,p_include                    => p_output -- OUT NOCOPY VARCHAR2 -- Y/N
6627           ,p_extract_type               => 'CUTOVER' -- IN  VARCHAR2 DEFAULT 'PERIODIC'
6628           ,p_element_type_id_from_crit  => p_ext_pay_element_type  -- IN  NUMBER DEFAULT NULL
6629           );
6630     ELSE
6631 
6632           IF    l_chg_table  <> 'PAY_ELEMENT_ENTRIES_F'
6633             AND l_chg_type = 'I' THEN
6634 
6635                 debug('Not a valid event, will not be processed',30);
6636                 p_output := 'N';
6637                 debug_exit(l_proc_name);
6638                 RETURN p_output;
6639           END IF;
6640 
6641 
6642         -- if correction, implies that it is on screen entry value
6643         -- on pay_element_entry_values_f and the surrogate key is
6644         -- not element_entry_id, but rather element_entry_value_id
6645         IF l_chg_type = 'C'
6646         THEN
6647           debug('correction event');
6648           OPEN csr_get_element_entry_id
6649                 (p_element_entry_value_id => l_chg_surrogate_key
6650                 );
6651           FETCH csr_get_element_entry_id into l_element_entry_id;
6652              IF csr_get_element_entry_id%NOTFOUND
6653              THEN
6654                debug('element entry id not found for this correction event',40);
6655                p_output := 'N';
6656                l_element_entry_id := NULL;
6657              END IF;
6658           CLOSE csr_get_element_entry_id;
6659         ELSE
6660           debug('not a correction event',50);
6661           l_element_entry_id := l_chg_surrogate_key;
6662         END IF;
6663 
6664         IF    l_element_entry_id IS NOT NULL
6665           AND p_ext_pay_element_entry = l_element_entry_id
6666         THEN
6667           check_if_element_qualifies
6668               (p_element_entry_id           => p_ext_pay_element_entry -- IN  NUMBER
6669               ,p_element_type_id            => l_element_type_id  -- OUT NOCOPY NUMBER
6670               ,p_include                    => p_output -- OUT NOCOPY VARCHAR2 -- Y/N
6671               ,p_extract_type               => 'PERIODIC' -- IN  VARCHAR2 DEFAULT 'PERIODIC'
6672               ,p_element_type_id_from_crit  => p_ext_pay_element_type  -- IN  NUMBER DEFAULT NULL
6673               );
6674         END IF;
6675 
6676     END IF;
6677 
6678 
6679   ELSIF g_elements_of_info_type.EXISTS(p_ext_pay_element_type) THEN -- this is in the terminated state
6680                                                                     -- but it exists in collection
6681     debug('this is in the terminated state, but it exists in collection',70);
6682     l_is_spread_bonus_yn  -- get spread bonus flag
6683         :=  g_elements_of_info_type(p_ext_pay_element_type).eei_information6;
6684 
6685     IF l_is_spread_bonus_yn IS NULL
6686     THEN
6687       l_is_spread_bonus_yn := 'N';
6688     END IF;
6689     debug('l_is_spread_bonus_yn :'|| l_is_spread_bonus_yn,80);
6690 
6691     debug('now fetch the claim date for this element',75);
6692 
6693     IF l_is_spread_bonus_yn = 'Y' THEN
6694         OPEN PQP_GB_PSI_ALLOWANCE_HISTORY.csr_get_entry_value
6695            (c_effective_date    => g_effective_date
6696            ,c_element_entry_id  => p_ext_pay_element_entry
6697            ,c_input_value       => 'CLAIM DATE' -- DEFAULT 'PAY VALUE'
6698            );
6699         FETCH PQP_GB_PSI_ALLOWANCE_HISTORY.csr_get_entry_value INTO l_claim_date;
6700           IF PQP_GB_PSI_ALLOWANCE_HISTORY.csr_get_entry_value%NOTFOUND
6701             OR l_claim_date IS NULL
6702           THEN
6703             l_return :=  raise_extract_error
6704                    (p_error_number        =>    94532
6705                    ,p_error_text          =>    'BEN_94532_NO_ENTRY_VALUE'
6706                    ,p_token1              =>
6707                         g_elements_of_info_type(p_ext_pay_element_type).element_name
6708                         || '(Spread Bonus)'
6709                    ,p_token2              => 'CLAIM DATE'
6710                    ,p_token3              => to_char(g_effective_date,'DD/MM/YYYY')
6711                    );
6712 
6713             p_output := 'N';
6714           ELSE
6715             IF is_proper_claim_date -- function to check valid claim date
6716                         (p_claim_date       => fnd_date.canonical_to_date(l_claim_date)
6717                         ,p_element_name     => g_elements_of_info_type(p_ext_pay_element_type).element_name
6718                         ,p_element_entry_id => p_ext_pay_element_entry
6719                         ,p_assg_start_date  => PQP_GB_PSI_ALLOWANCE_HISTORY.g_assg_start_date
6720                         )
6721             THEN
6722               g_curr_element_type_id := p_ext_pay_element_type;
6723               g_curr_element_entry_id := p_ext_pay_element_entry;
6724 
6725               p_output := 'Y'; -- this element is spread_bonus and valid claim date
6726               debug('this element is spread_bonus and valid claim date',90);
6727             ELSE
6728               p_output := 'N'; -- either not a spread bonus, or claim date didnt qualify
6729               debug('either not a spread bonus, or claim date didnt qualify',110);
6730             END IF;
6731           END IF;
6732         CLOSE PQP_GB_PSI_ALLOWANCE_HISTORY.csr_get_entry_value;
6733 
6734     END IF;
6735 
6736   ELSE -- IF g_is_terminated = 'N' and not a spread bonus
6737     p_output := 'N'; -- reject as assignment is in ternminated state
6738     debug('p_output : '|| p_output, 120);
6739   END IF; -- IF g_is_terminated = 'N'
6740 
6741 
6742     -- check for pensionable flag
6743     debug('now checking for pensionable flag status ',130);
6744     IF p_output = 'Y' THEN
6745       IF g_elements_of_info_type(g_curr_element_type_id).eei_information4 <> 'Y' THEN
6746          debug('ERROR: Not a Pensionable Allowance, will not be processed.',60);
6747          l_return := raise_extract_error
6748                       (p_error_number        =>    94528
6749                       ,p_error_text          =>    'BEN_94528_NOT_PEN_ALLOWANCE'
6750                       ,p_token1              =>
6751                            g_elements_of_info_type(g_curr_element_type_id).element_name
6752                       );
6753          debug('Returning N ..');
6754          p_output := 'N';
6755 
6756       END IF;
6757     END IF;
6758 
6759 
6760 
6761   IF l_is_terminated IS NOT NULL
6762   THEN
6763     g_is_terminated := l_is_terminated;
6764   END IF;
6765 
6766 
6767   debug_exit(l_proc_name);
6768   RETURN p_output;
6769 
6770   EXCEPTION
6771     WHEN others THEN
6772         IF SQLCODE <> hr_utility.hr_error_number
6773         THEN
6774             debug_others (l_proc_name, 10);
6775             IF g_debug
6776             THEN
6777               DEBUG (   'Leaving: '
6778                      || l_proc_name, -999);
6779              END IF;
6780              fnd_message.raise_error;
6781          ELSE
6782              RAISE;
6783          END IF;
6784 
6785 END ele_entry_inp_val_per_crit;
6786 
6787 
6788     -- ----------------------------------------------------------------------------
6789     -- |--------------------------< is_today_sal_end >-----------------------------|
6790     --  Description: This Procedure is to check if salary is ending on the current
6791     --                processing date.
6792     --                Salary is considered to be terminatied if assignment status
6793     --                  is changed to one with 'No Payroll process'
6794     -- ----------------------------------------------------------------------------
6795     FUNCTION is_today_sal_end RETURN VARCHAR2
6796     IS
6797         l_proc varchar2(72) := g_proc_name||'.is_today_sal_end';
6798         l_chg_column_name           VARCHAR2(30);
6799         l_chg_table                 VARCHAR2(30);
6800         l_chg_table_id              NUMBER;
6801         l_assignment_status_type_id NUMBER;
6802         l_chg_date                  DATE;
6803         l_update_type               VARCHAR2(10);
6804         l_salary_ended              VARCHAR2(1);
6805         l_index                     NUMBER;
6806         l_elements_exist            VARCHAR2(1);
6807         l_assignment_status         VARCHAR2(20);
6808         l_per_assg_status           VARCHAR2(80);
6809         l_leaver_date               DATE;
6810     BEGIN
6811         debug_enter(l_proc);
6812         debug('g_effective_date: '||g_effective_date);
6813         debug('g_salary_end_date: '||g_salary_end_date);
6814 
6815         IF g_salary_end_date = (g_effective_date - 1) THEN
6816             -- current date has been process by another event
6817             --  and today is set as end date previously.
6818             g_salary_ended_today := 'Y';
6819 
6820             debug('Returning Y'||10);
6821             debug_exit(l_proc);
6822             RETURN 'Y';
6823         END IF;
6824 
6825         l_index := ben_ext_person.g_chg_pay_evt_index;
6826         LOOP
6827             l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
6828             l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
6829             l_chg_date            :=  g_pay_proc_evt_tab(l_index).effective_date;
6830             l_update_type         :=  g_pay_proc_evt_tab(l_index).update_type;
6831 
6832             l_chg_table           :=  get_dated_table_name(l_chg_table_id);
6833 
6834             IF g_effective_date < l_chg_date THEN
6835               debug('finished processing all the events on g_effective_date');
6836               EXIT;
6837             END IF;
6838 
6839             -- check for changes on assignment status
6840             IF l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
6841                 AND  (l_chg_column_name  = 'ASSIGNMENT_STATUS_TYPE_ID'
6842                       OR l_update_type  =  'E')  THEN
6843 
6844                   IF PQP_GB_PSI_FUNCTIONS.chk_is_employee_a_leaver
6845                         (
6846                         p_assignment_id     =>  g_assignment_id
6847                         ,p_effective_date   =>  l_chg_date
6848                         ,p_leaver_date      =>  l_leaver_date
6849                         ) = 'Y' THEN
6850 
6851                          -- set today as salary end date.
6852                          debug('l_leaver_date: '||l_leaver_date,20);
6853                         g_salary_end_date := l_leaver_date;
6854                         g_salary_ended_today := 'Y';
6855 
6856                         debug('Returning Y');
6857                         debug_exit(l_proc);
6858                         RETURN 'Y';
6859 
6860                   END IF;
6861 
6862                   l_assignment_status_type_id :=  g_pay_proc_evt_tab(l_index).new_value;
6863                   OPEN csr_assignment_status(l_assignment_status_type_id);
6864                   FETCH csr_assignment_status INTO l_assignment_status,l_per_assg_status;
6865                   CLOSE csr_assignment_status;
6866                   IF l_assignment_status <> 'PROCESS' THEN
6867 
6868                         debug('Returning Y as assignemnt status is changed to: '||l_assignment_status);
6869                         -- set today as salary end date.
6870                         g_salary_end_date := g_effective_date-1;
6871                         g_salary_ended_today := 'Y';
6872 
6873                         debug('Returning Y');
6874                         debug_exit(l_proc);
6875                         RETURN 'Y';
6876 
6877                   END IF; --IF l_assignment_status <> 'PROCESS'
6878 
6879             END IF;--IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
6880 
6881             -- looping condition
6882             IF l_index = g_pay_proc_evt_tab.LAST THEN
6883                 EXIT;
6884             ELSE
6885                 l_index := g_pay_proc_evt_tab.NEXT(l_index);
6886             END IF; --IF l_index = g_pay_proc_evt_tab.LAST
6887 
6888         END LOOP; -- LOOP
6889 
6890         g_salary_ended_today := 'N';
6891         debug('Returning N');
6892         debug_exit(l_proc);
6893         return 'N';
6894     END is_today_sal_end;
6895     ---
6896     -- ----------------------------------------------------------------------------
6897     -- |--------------------------< is_curr_sal_end >-----------------------------|
6898     --  Description: This Procedure is to check if salary is ending on the current
6899     --                processing event.
6900     -- ----------------------------------------------------------------------------
6901     FUNCTION is_curr_sal_end RETURN VARCHAR2
6902     IS
6903         l_proc varchar2(72) := g_proc_name||'.is_curr_sal_end';
6904         l_chg_column_name VARCHAR2(30);
6905         l_chg_table   VARCHAR2(30);
6906         l_assignment_status_type_id NUMBER;
6907     BEGIN
6908         debug_enter(l_proc);
6909         l_chg_column_name := ben_ext_person.g_chg_pay_column;
6910         l_chg_table       := ben_ext_person.g_chg_pay_table;
6911 
6912         -- check for changes on assignment status
6913         IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
6914             AND  l_chg_column_name  = 'ASSIGNMENT_STATUS_TYPE_ID')  THEN
6915 
6916               debug('Returning Y for the event on assignment_status_type_id');
6917               debug_exit(l_proc);
6918               RETURN 'Y';
6919 
6920         END IF; --IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
6921 
6922         debug('Returning N');
6923         debug_exit(l_proc);
6924         return 'N';
6925     END is_curr_sal_end;
6926     ---
6927     -- ----------------------------------------------------------------------------
6928     -- |--------------------------< is_today_sal_start >--------------------------|
6929     -- ----------------------------------------------------------------------------
6930     FUNCTION is_today_sal_start RETURN VARCHAR2
6931     IS
6932         l_proc varchar2(72) := g_proc_name||'.is_today_sal_start';
6933         l_chg_column_name   VARCHAR2(30);
6934         l_chg_table         VARCHAR2(30);
6935         l_chg_table_id      NUMBER;
6936         l_assignment_status_type_id NUMBER;
6937         l_salary_ended      VARCHAR2(1);
6938         l_elements_exist    VARCHAR2(1);
6939         l_index             NUMBER;
6940         l_assignment_status VARCHAR2(20);
6941         l_per_assg_status   VARCHAR2(80);
6942         l_update_type     VARCHAR2(10);
6943 
6944     BEGIN
6945         debug_enter(l_proc);
6946 
6947         l_index := ben_ext_person.g_chg_pay_evt_index;
6948         LOOP
6949             l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
6950             l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
6951             l_chg_table           :=  get_dated_table_name(l_chg_table_id);
6952             l_update_type         :=  g_pay_proc_evt_tab(l_index).update_type;
6953 
6954             debug('g_effective_date :' || g_effective_date, 009);
6955 
6956             IF g_effective_date < g_pay_proc_evt_tab(l_index).effective_date THEN
6957               debug('finished processing all the events on g_effective_date',30);
6958               EXIT;
6959             END IF; --IF g_effective_date
6960 
6961             -- check for changes on assignment status
6962             IF l_chg_table  = 'PER_ALL_ASSIGNMENTS_F' THEN
6963 
6964                 IF l_chg_column_name  = 'ASSIGNMENT_STATUS_TYPE_ID'  THEN
6965 
6966                   l_assignment_status_type_id :=  g_pay_proc_evt_tab(l_index).new_value;
6967                   debug('l_assignment_status_type_id: '||l_assignment_status_type_id,40);
6968                   OPEN csr_assignment_status(l_assignment_status_type_id);
6969                   FETCH csr_assignment_status INTO l_assignment_status,l_per_assg_status;
6970                   CLOSE csr_assignment_status;
6971                   debug('l_assignment_status: '||l_assignment_status);
6972                   debug('l_per_assg_status: '||l_per_assg_status);
6973                   IF l_assignment_status = 'PROCESS'
6974                   AND l_per_assg_status NOT IN ('TERM_ASSIGN','SUSP_ASSIGN','END') THEN
6975 
6976                           debug('Returning Y as assignemnt status is : '||l_assignment_status,50);
6977                           g_salary_ended_today := 'N';
6978                           debug_exit(l_proc);
6979                           RETURN 'Y';
6980 
6981                   ELSE
6982                           debug('Returning N as assignemnt status is : '||l_assignment_status,50);
6983                           debug_exit(l_proc);
6984                           RETURN 'N';
6985 
6986                   END IF; -- IF l_assignment_status <> 'PROCESS'
6987                ELSIF  l_update_type = 'I' THEN
6988                     debug('Returning Y , Insert event on assignments ',40);
6989                     g_salary_ended_today := 'N';
6990                     debug_exit(l_proc);
6991                     RETURN 'Y';
6992                END IF;
6993 
6994             END IF; --IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
6995 
6996 
6997             -- looping condition
6998             IF l_index = g_pay_proc_evt_tab.LAST THEN
6999                 EXIT;
7000             ELSE
7001                 l_index := g_pay_proc_evt_tab.NEXT(l_index);
7002             END IF;--IF l_index = g_pay_proc_evt_tab.LAST
7003 
7004         END LOOP; -- LOOP
7005 
7006         debug('Returning N');
7007         debug_exit(l_proc);
7008         return 'N';
7009     END is_today_sal_start;
7010     ---
7011     ---
7012     -- ----------------------------------------------------------------------------
7013     -- |--------------------------< is_today_sal_ele_end >-----------------------------|
7014     --  Description: This Procedure is to check if salary element ending on the current
7015     --                processing date.
7016     -- ----------------------------------------------------------------------------
7017     FUNCTION is_today_sal_ele_end  RETURN VARCHAR2
7018     IS
7019         l_proc varchar2(72) := g_proc_name||'.is_today_sal_ele_end';
7020         l_sal_ele_end VARCHAR2(1) := 'N';
7021         l_index           NUMBER;
7022         l_chg_table_id        NUMBER;
7023         l_chg_column_name VARCHAR2(30);
7024         l_chg_table       VARCHAR2(30);
7025         l_chg_type        VARCHAR2(10);
7026         l_chg_date        DATE;
7027         l_chg_surrogate_key NUMBER;
7028         l_is_fte_abv      VARCHAR2(1);
7029     BEGIN
7030         debug_enter(l_proc);
7031         debug('g_effective_date: '||g_effective_date);
7032         debug('g_salary_ele_end_date: '||g_salary_ele_end_date);
7033         debug('g_non_salary_ele_end_date: '||g_non_salary_ele_end_date);
7034 
7035         IF g_salary_ele_end_date = g_effective_date THEN
7036             -- if current event date is already processed
7037             debug('g_sal_chg_event_exists: '||g_sal_chg_event_exists);
7038             debug('Returning: Y');
7039             debug_exit(l_proc);
7040             return 'Y';
7041         END IF;
7042 
7043         IF g_non_salary_ele_end_date = g_effective_date THEN
7044             -- if current event date is already processed
7045             debug('g_sal_chg_event_exists: '||g_sal_chg_event_exists);
7046             debug('Returning: N');
7047             debug_exit(l_proc);
7048             return 'N';
7049         END IF;
7050 
7051         -- reset g_sal_chg_event_exists
7052         g_sal_chg_event_exists  :=  'N';
7053 
7054         l_index := ben_ext_person.g_chg_pay_evt_index;
7055         LOOP
7056             l_chg_type            :=  g_pay_proc_evt_tab(l_index).update_type;
7057             l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
7058             l_chg_table           :=  get_dated_table_name(l_chg_table_id);
7059             l_chg_date            :=  g_pay_proc_evt_tab(l_index).effective_date;
7060             l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
7061 
7062             debug('l_chg_date: '||l_chg_date);
7063             debug('l_chg_table: '||l_chg_table);
7064             debug('l_chg_column_name: '||l_chg_column_name);
7065             debug('l_chg_type: '||l_chg_type);
7066 
7067             IF g_effective_date < g_pay_proc_evt_tab(l_index).effective_date THEN
7068               debug('finished processing all the events on g_effective_date');
7069               EXIT;
7070             END IF; --IF g_effective_date
7071             debug('l_chg_table: '||l_chg_table||'  l_chg_type: '||l_chg_type);
7072 
7073             -- check for salary element end
7074             IF l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7075                 AND l_chg_type = 'E' THEN
7076                 debug('Salary element end event ');
7077                 g_salary_ele_end_date := g_effective_date;
7078                 l_sal_ele_end := 'Y';
7079             END IF;
7080 
7081             IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7082                 AND  (l_chg_column_name  IN ('GRADE_ID','NORMAL_HOURS') OR l_chg_type = 'I'))
7083                OR (l_chg_table  = 'PQP_ASSIGNMENT_ATTRIBUTES_F'
7084                 AND  (l_chg_column_name  = 'CONTRACT_TYPE' OR l_chg_type = 'I'))
7085                OR (l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7086                 AND  l_chg_type  <> 'E')
7087                OR (l_chg_table  = 'PAY_ELEMENT_ENTRY_VALUES_F') THEN
7088 
7089                     g_sal_chg_event_exists  := 'Y';
7090 
7091             END IF; --IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7092 
7093             IF (l_chg_table  = 'PER_ASSIGNMENT_BUDGET_VALUES_F'
7094                 AND  (l_chg_column_name  = 'VALUE' OR l_chg_type = 'I' )) THEN
7095 
7096                     l_chg_surrogate_key   :=  g_pay_proc_evt_tab(l_index).surrogate_key;
7097                     debug('l_chg_surrogate_key: '||l_chg_surrogate_key);
7098                     OPEN csr_is_fte_abv
7099                               (
7100                               p_assignment_budget_value_id  =>  l_chg_surrogate_key
7101                               );
7102                     FETCH csr_is_fte_abv INTO l_is_fte_abv;
7103                     CLOSE csr_is_fte_abv;
7104                     debug('l_is_fte_abv: '||l_is_fte_abv);
7105                     IF NVL(l_is_fte_abv,' ') = 'Y' THEN
7106                           debug('Change on FTE Value');
7107                           g_sal_chg_event_exists  := 'Y';
7108 
7109                     END IF;
7110 
7111             END IF;
7112             -- looping condition
7113             IF l_index = g_pay_proc_evt_tab.LAST THEN
7114                 EXIT;
7115             ELSE
7116                 l_index := g_pay_proc_evt_tab.NEXT(l_index);
7117             END IF;
7118         END LOOP; -- LOOP
7119 
7120         IF l_sal_ele_end = 'N' THEN
7121           -- current date does not have a sal ele end event
7122           g_non_salary_ele_end_date := g_effective_date;
7123         END IF;
7124 
7125         debug('g_sal_chg_event_exists: '||g_sal_chg_event_exists);
7126         debug('Returning: '||l_sal_ele_end);
7127         debug_exit(l_proc);
7128         return l_sal_ele_end;
7129     END is_today_sal_ele_end;
7130     ---
7131     -- ----------------------------------------------------------------------------
7132     -- |------------------------< is_curr_sal_ele_end >---------------------------|
7133     --  Description:  This procedure is to check whether the current event is a
7134     --                  salary element end event.
7135     -- ----------------------------------------------------------------------------
7136     FUNCTION is_curr_sal_ele_end RETURN VARCHAR2
7137     IS
7138         l_proc varchar2(72) := g_proc_name||'.is_curr_sal_ele_end';
7139         l_chg_table   VARCHAR2(30);
7140         l_chg_type    VARCHAR2(10);
7141     BEGIN
7142         debug_enter(l_proc);
7143         l_chg_type        := ben_ext_person.g_chg_update_type;
7144         l_chg_table       := ben_ext_person.g_chg_pay_table;
7145         debug('l_chg_table: '||l_chg_table||'  l_chg_type: '||l_chg_type);
7146 
7147         IF l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7148                 AND l_chg_type = 'E' THEN
7149 
7150             debug('Returning Y ');
7151             debug_exit(l_proc);
7152             RETURN 'Y';
7153 
7154         END IF; --IF l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7155 
7156         debug('Returning N ');
7157         debug_exit(l_proc);
7158         RETURN 'N';
7159     END is_curr_sal_ele_end;
7160     ---
7161     ---
7162     -- ----------------------------------------------------------------------------
7163     -- |--------------------------< is_next_sal_end >--------------------------|
7164     -- ----------------------------------------------------------------------------
7165     FUNCTION is_next_sal_end
7166                   (
7167                   p_end_date   OUT NOCOPY DATE
7168                   )RETURN VARCHAR2
7169     IS
7170         l_proc varchar2(72) := g_proc_name||'.is_next_sal_end';
7171         l_next_event_date       DATE;
7172         l_assignment_status_type_id NUMBER;
7173         l_index           NUMBER;
7174         l_chg_column_name VARCHAR2(30);
7175         l_chg_table       VARCHAR2(30);
7176         l_chg_table_id    NUMBER;
7177         l_chg_date        DATE;
7178         l_leaver_date     DATE;
7179         l_update_type     VARCHAR2(10);
7180         l_sal_ele_end_evt_exist VARCHAR2(1) :=  'Y';
7181         l_other_event_exist     VARCHAR2(1) :=  'N';
7182         l_is_fte_abv            VARCHAR2(1);
7183         l_chg_surrogate_key     NUMBER;
7184         l_assignment_status     VARCHAR2(20);
7185         l_per_assg_status       VARCHAR2(80);
7186         l_return                VARCHAR2(1) :=  'N';
7187     BEGIN
7188         debug_enter(l_proc);
7189         p_end_date  :=  NULL;
7190         -- loop till the next event date
7191         l_index := ben_ext_person.g_chg_pay_evt_index;
7192         LOOP
7193             l_update_type         :=  g_pay_proc_evt_tab(l_index).update_type;
7194             l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
7195             l_chg_table           :=  get_dated_table_name(l_chg_table_id);
7196             l_chg_date            :=  g_pay_proc_evt_tab(l_index).effective_date;
7197 
7198             IF g_effective_date < l_chg_date THEN
7199               debug('finished processing all the events on g_effective_date');
7200               EXIT;
7201             END IF; --IF g_effective_date
7202             debug('l_chg_date: '||l_chg_date);
7203 
7204             -- looping condition
7205             IF l_index = g_pay_proc_evt_tab.LAST THEN
7206                 EXIT;
7207             ELSE
7208                 l_index := g_pay_proc_evt_tab.NEXT(l_index);
7209             END IF;
7210         END LOOP;
7211 
7212         -- loop for next event date
7213         IF l_chg_date > g_effective_date THEN
7214             l_next_event_date   :=    l_chg_date;
7215             debug('Looping through the events on next event date');
7216             LOOP
7217                 l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
7218                 l_update_type         :=  g_pay_proc_evt_tab(l_index).update_type;
7219                 l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
7220 
7221                 l_chg_table           :=  get_dated_table_name(l_chg_table_id);
7222                 l_chg_date            :=  g_pay_proc_evt_tab(l_index).effective_date;
7223 
7224                 -- looping condition
7225                 IF l_next_event_date < l_chg_date THEN
7226                   debug('finished processing all the events on g_effective_date');
7227                   EXIT;
7228                 END IF; --IF g_effective_date
7229 
7230                 debug('l_chg_table: '||l_chg_table||'  l_chg_date: '||l_chg_date||
7231                       '   l_update_type: '||l_update_type||'  l_chg_column_name: '||l_chg_column_name);
7232 
7233                 IF l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7234                 AND  (l_chg_column_name  = 'ASSIGNMENT_STATUS_TYPE_ID'
7235                       OR l_update_type  =  'E')  THEN
7236 
7237                       IF PQP_GB_PSI_FUNCTIONS.chk_is_employee_a_leaver
7238                             (
7239                             p_assignment_id     =>  g_assignment_id
7240                             ,p_effective_date   =>  l_chg_date
7241                             ,p_leaver_date      =>  l_leaver_date
7242                             ) = 'Y' THEN
7243 
7244                              -- set today as salary end date.
7245                              debug('l_leaver_date: '||l_leaver_date,20);
7246                             g_salary_end_date := l_leaver_date;
7247                             p_end_date        := l_leaver_date;
7248                             debug('Returning Y');
7249                             debug_exit(l_proc);
7250                             RETURN 'Y';
7251 
7252                       END IF;
7253 
7254                       l_assignment_status_type_id :=  g_pay_proc_evt_tab(l_index).new_value;
7255                       OPEN csr_assignment_status(l_assignment_status_type_id);
7256                       FETCH csr_assignment_status INTO l_assignment_status,l_per_assg_status;
7257                       CLOSE csr_assignment_status;
7258                       IF l_assignment_status <> 'PROCESS' THEN
7259 
7260                             debug('Returning Y as assignemnt status is changed to: '||l_assignment_status);
7261                             -- set today as salary end date.
7262                             g_salary_end_date := l_chg_date-1;
7263                             p_end_date        := l_chg_date-1;
7264                             debug('Returning Y');
7265                             debug_exit(l_proc);
7266                             RETURN 'Y';
7267 
7268                       END IF; --IF l_assignment_status <> 'PROCESS'
7269                 ELSIF l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7270                       AND l_update_type  =  'E' THEN
7271                       -- if there is a element entry end.
7272                       l_sal_ele_end_evt_exist :=  'Y';
7273 
7274                 ELSIF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7275                     AND  (l_chg_column_name  IN ('GRADE_ID','NORMAL_HOURS') OR l_update_type = 'I'))
7276                    OR (l_chg_table  = 'PQP_ASSIGNMENT_ATTRIBUTES_F'
7277                     AND  (l_chg_column_name  = 'CONTRACT_TYPE' OR l_update_type = 'I'))
7278                    OR (l_chg_table  = 'PAY_ELEMENT_ENTRY_VALUES_F') THEN
7279 
7280                         l_other_event_exist := 'Y';
7281 
7282                 ELSIF (l_chg_table  = 'PER_ASSIGNMENT_BUDGET_VALUES_F'
7283                     AND  (l_chg_column_name  = 'VALUE' OR l_update_type = 'I' )) THEN
7284 
7285                         l_chg_surrogate_key   :=  ben_ext_person.g_chg_surrogate_key;
7286                         debug('l_chg_surrogate_key: '||l_chg_surrogate_key);
7287                         OPEN csr_is_fte_abv
7288                                   (
7289                                   p_assignment_budget_value_id  =>  l_chg_surrogate_key
7290                                   );
7291                         FETCH csr_is_fte_abv INTO l_is_fte_abv;
7292                         CLOSE csr_is_fte_abv;
7293 
7294                         IF l_is_fte_abv IS NOT NULL
7295                             AND l_is_fte_abv = 'Y' THEN
7296 
7297                               l_other_event_exist := 'Y';
7298 
7299                         END IF;--IF l_is_fte_abv IS NOT NULL
7300 
7301                 END IF;--IF l_chg_table  =
7302 
7303                 -- looping condition
7304                 IF l_index = g_pay_proc_evt_tab.LAST THEN
7305                     EXIT;
7306                 ELSE
7307                     l_index := g_pay_proc_evt_tab.NEXT(l_index);
7308                 END IF;--IF l_index = g_pay_proc_evt_tab.LAST
7309 
7310             END LOOP;
7311 
7312         END IF;--IF l_chg_date > g_effective_date
7313 
7314         IF l_sal_ele_end_evt_exist  =   'Y'
7315             AND   l_other_event_exist = 'N' THEN
7316         -- if on the next event date, there is a salary element end
7317         --    and there are no other salary change events, we have to check on the next event date + 1.
7318         --    if this next event date + 1 is a salary end event, this date should be reported as end date
7319         --    on the current event date.
7320               IF l_chg_date = (l_next_event_date + 1)  THEN
7321                   -- if the next event is on the very next day
7322                   -- then check employee is a leaver on that date
7323                   l_chg_table_id        :=  g_pay_proc_evt_tab(l_index).dated_table_id;
7324                   l_update_type         :=  g_pay_proc_evt_tab(l_index).update_type;
7325                   l_chg_column_name     :=  g_pay_proc_evt_tab(l_index).column_name;
7326 
7327                   IF l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7328                     AND  (l_chg_column_name  = 'ASSIGNMENT_STATUS_TYPE_ID'
7329                           OR l_update_type  =  'E')  THEN
7330 
7331                           IF PQP_GB_PSI_FUNCTIONS.chk_is_employee_a_leaver
7332                                 (
7333                                 p_assignment_id     =>  g_assignment_id
7334                                 ,p_effective_date   =>  l_chg_date
7335                                 ,p_leaver_date      =>  l_leaver_date
7336                                 ) = 'Y' THEN
7337 
7338                                  -- set today as salary end date.
7339                                  debug('l_leaver_date: '||l_leaver_date,20);
7340                                 g_salary_end_date := l_leaver_date;
7341                                 p_end_date        := l_leaver_date;
7342                                 debug('Returning Y');
7343                                 debug_exit(l_proc);
7344                                 RETURN 'Y';
7345 
7346                           END IF;
7347 
7348                           l_assignment_status_type_id :=  g_pay_proc_evt_tab(l_index).new_value;
7349                           OPEN csr_assignment_status(l_assignment_status_type_id);
7350                           FETCH csr_assignment_status INTO l_assignment_status,l_per_assg_status;
7351                           CLOSE csr_assignment_status;
7352                           IF l_assignment_status <> 'PROCESS' THEN
7353 
7354                                 debug('Returning Y as assignemnt status is changed to: '||l_assignment_status);
7355                                 -- set today as salary end date.
7356                                 g_salary_end_date := l_chg_date-1;
7357                                 p_end_date        := l_chg_date-1;
7358                                 debug('Returning Y');
7359                                 debug_exit(l_proc);
7360                                 RETURN 'Y';
7361 
7362                           END IF; --IF l_assignment_status <> 'PROCESS'
7363 
7364                     END IF; -- IF l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7365 
7366               END IF; -- IF l_chg_date = (l_next_event_date + 1)
7367 
7368         END IF; --IF l_sal_ele_end_evt_exist  =   'Y'
7369 
7370 
7371         debug('p_end_date: '||p_end_date);
7372         debug_exit(l_proc);
7373         RETURN l_return;
7374     END is_next_sal_end;
7375     ---
7376     -- ----------------------------------------------------------------------------
7377     -- |--------------------------< is_curr_sal_change_event >--------------------------|
7378     -- ----------------------------------------------------------------------------
7379     FUNCTION is_curr_sal_change_event RETURN VARCHAR2
7380     IS
7381 
7382      --For Bug 7013325: Added cursor to fetch mapped DFF segment
7383        CURSOR csr_get_configured_dff_segment(c_business_group_id NUMBER)
7384        IS
7385          SELECT trim(nvl(pcv_information3,'NULLCOLUMN'))
7386          FROM pqp_configuration_values
7387          WHERE pcv_information_category='PQP_GB_PENSERVER_ELIGBLTY_CONF'
7388          AND business_group_id = c_business_group_id;
7389 
7390 
7391       l_proc varchar2(72) := g_proc_name||'.is_curr_sal_change_event';
7392         l_next_event_date       DATE;
7393         l_next_pay_event_rec  ben_ext_person.t_detailed_output_tab_rec;
7394         l_chg_column_name VARCHAR2(30);
7395         l_chg_table       VARCHAR2(30);
7396         l_chg_type        VARCHAR2(10);
7397         l_chg_date        DATE;
7398         l_chg_surrogate_key NUMBER;
7399         l_is_fte_abv      VARCHAR2(1);
7400      --For Bug 7013325: Added Variable
7401        l_configured_dff_segment  VARCHAR2(30);
7402 
7403     BEGIN
7404         debug_enter(l_proc);
7405 
7406         l_chg_type            :=  ben_ext_person.g_chg_update_type;
7407         l_chg_table           :=  ben_ext_person.g_chg_pay_table;
7408         l_chg_date            :=  ben_ext_person.g_chg_eff_dt;
7409         l_chg_column_name     :=  ben_ext_person.g_chg_pay_column;
7410 
7411         debug('l_chg_table: '||l_chg_table);
7412         debug('l_chg_date: '||l_chg_date);
7413         debug('l_chg_type: '||l_chg_type);
7414         debug('l_chg_column_name: '||l_chg_column_name);
7415 
7416       --For Bug 7013325
7417       OPEN csr_get_configured_dff_segment(g_business_group_id);
7418         FETCH csr_get_configured_dff_segment INTO l_configured_dff_segment;
7419         CLOSE csr_get_configured_dff_segment;
7420 
7421         IF(l_configured_dff_segment='NULLCOLUMN')
7422         THEN
7423             debug('Customer specific DFF Segment not mapped on configuration page');
7424             debug('Refer to bug 7013325 for setup details');
7425         ELSE
7426             debug('l_configured_dff_segment: '||l_configured_dff_segment);
7427             debug('g_business_group_id: '||g_business_group_id);
7428         END IF;
7429       --For Bug 7013325
7430 
7431 
7432     --For Bug 5998108: Added new column EMPLOYMENT_CATEGORY
7433     --For bug 7013325: Added new column l_configured_dff_segment
7434         IF (l_chg_table  = 'PAY_ELEMENT_ENTRIES_F'
7435             AND  l_chg_type  <> 'E')
7436            OR (l_chg_table  = 'PAY_ELEMENT_ENTRY_VALUES_F')
7437            OR (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7438             AND  (l_chg_column_name  IN ('GRADE_ID','NORMAL_HOURS','EMPLOYMENT_CATEGORY',l_configured_dff_segment) OR l_chg_type = 'I'))
7439            OR (l_chg_table  = 'PQP_ASSIGNMENT_ATTRIBUTES_F'
7440             AND  (l_chg_column_name  = 'CONTRACT_TYPE' OR l_chg_type = 'I'))THEN
7441 
7442                 debug('Returning Y');
7443                 debug_exit(l_proc);
7444                 RETURN 'Y';
7445 
7446         END IF; --IF (l_chg_table  = 'PER_ALL_ASSIGNMENTS_F'
7447 
7448         IF (l_chg_table  = 'PER_ASSIGNMENT_BUDGET_VALUES_F'
7449             AND  (l_chg_column_name  = 'VALUE' OR l_chg_type = 'I' )) THEN
7450 
7451                 l_chg_surrogate_key   :=  ben_ext_person.g_chg_surrogate_key;
7452                 debug('l_chg_surrogate_key: '||l_chg_surrogate_key);
7453                 OPEN csr_is_fte_abv
7454                           (
7455                           p_assignment_budget_value_id  =>  l_chg_surrogate_key
7456                           );
7457                 FETCH csr_is_fte_abv INTO l_is_fte_abv;
7458                 CLOSE csr_is_fte_abv;
7459 
7460                 IF l_is_fte_abv IS NOT NULL
7461                     AND l_is_fte_abv = 'Y' THEN
7462 
7463                       debug('Returning Y');
7464                       debug_exit(l_proc);
7465                       RETURN 'Y';
7466 
7467                 END IF;
7468 
7469         END IF;
7470         debug('Returning N');
7471         debug_exit(l_proc);
7472         RETURN 'N';
7473     END is_curr_sal_change_event;
7474     ---
7475     -- ----------------------------------------------------------------------------
7476     -- |---------------------< get_start_end_date >------------------------|
7477     -- ----------------------------------------------------------------------------
7478     FUNCTION get_start_end_date
7479                 (
7480                 p_assignment_id         NUMBER
7481                 ,p_business_group_id    NUMBER
7482                 ,p_effective_date       DATE
7483                 ,p_start_date           OUT NOCOPY DATE
7484                 ,p_end_date             OUT NOCOPY DATE
7485                 )RETURN NUMBER
7486     IS
7487         l_proc varchar2(72) := g_proc_name||'.get_start_end_date';
7488         l_temp_date       DATE;
7489         l_error           NUMBER;
7490         l_return          VARCHAR2(10);
7491     BEGIN --get_start_end_date
7492         debug_enter(l_proc);
7493 
7494         IF g_effective_date <> p_effective_date THEN
7495             -- reset globals for every new date
7496             g_salary_ele_end_date          := c_highest_date;
7497             g_non_salary_ele_end_date      := c_highest_date;
7498             g_sal_chg_event_exists         := 'N';
7499         END IF;
7500 
7501         g_effective_date := p_effective_date;
7502 
7503         IF g_salary_ended = 'Y' AND is_today_sal_start() = 'Y' THEN
7504             p_start_date  :=  g_effective_date;
7505             l_return  :=  is_next_sal_end
7506                             (
7507                             p_end_date  =>  g_salary_end_date
7508                             );
7509             IF g_salary_end_date IS NULL THEN
7510                 g_salary_ended    := 'N';
7511                 g_salary_started  := 'Y';
7512             END IF;
7513             p_end_date    :=  g_salary_end_date;
7514             debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7515             debug_exit(l_proc);
7516             RETURN 0;
7517         END IF;
7518 
7519         -- Check if the current event is salary end event.
7520         IF is_today_sal_end() = 'Y' THEN
7521           /*IF  is_curr_sal_end() = 'Y' THEN
7522                 p_start_date  :=  NULL;
7523                 g_salary_end_date    :=  NULL;
7524                 debug('p_start_date: '||p_start_date||'   g_salary_end_date: '||g_salary_end_date);
7525           ELSE
7526                 p_start_date  :=  g_effective_date;
7527                 g_salary_end_date    :=  g_effective_date;
7528                 debug('p_start_date: '||p_start_date||'   g_salary_end_date: '||g_salary_end_date);
7529           END IF;*/
7530           p_start_date  :=  NULL;
7531           g_salary_end_date    :=  NULL;
7532           g_salary_ended    := 'Y';
7533           g_salary_started  := 'N';
7534           p_end_date    :=  g_salary_end_date;
7535           debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7536           debug_exit(l_proc);
7537           RETURN 0;
7538         END IF;
7539 
7540         IF g_salary_started = 'Y' THEN
7541 
7542             IF is_today_sal_ele_end = 'Y' THEN
7543                 IF is_curr_sal_ele_end  = 'Y' THEN
7544                       debug('g_sal_chg_event_exists: '||g_sal_chg_event_exists);
7545                       IF g_sal_chg_event_exists = 'Y' THEN
7546                           p_start_date  :=  g_effective_date;
7547                           g_salary_end_date    :=  NULL;
7548 
7549                       ELSE
7550                           p_start_date  :=  g_effective_date+1;
7551                           l_return  :=  is_next_sal_end
7552                                           (
7553                                           p_end_date  =>  g_salary_end_date
7554                                           );
7555                       END IF;
7556 
7557                 ELSE
7558                       p_start_date  :=  g_effective_date+1;
7559                       l_return  :=  is_next_sal_end
7560                                           (
7561                                           p_end_date  =>  g_salary_end_date
7562                                           );
7563 
7564 
7565                 END IF; --IF is_curr_sal_ele_end()  = 'Y'
7566                 p_end_date    :=  g_salary_end_date;
7567                 debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7568                 debug_exit(l_proc);
7569                 RETURN 0;
7570             END IF; -- IF is_today_sal_ele_end() = 'Y'
7571 
7572             IF is_curr_sal_change_event()  = 'Y' THEN
7573                 p_start_date  :=  g_effective_date;
7574                 l_return  :=  is_next_sal_end
7575                                     (
7576                                     p_end_date  =>  g_salary_end_date
7577                                     );
7578             ELSE
7579                 p_start_date  :=  NULL;
7580                 g_salary_end_date    :=  NULL;
7581             END IF;--IF is_curr_sal_change_event()  = 'Y'
7582             p_end_date    :=  g_salary_end_date;
7583             debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7584             debug_exit(l_proc);
7585             return 0;
7586 
7587         ELSE -- IF g_salary_started = 'Y'
7588             p_start_date  :=  NULL;
7589             g_salary_end_date    :=  NULL;
7590             p_end_date    :=  g_salary_end_date;
7591             debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7592             debug_exit(l_proc);
7593             RETURN 0;
7594         END IF; -- IF g_salary_started = 'Y'
7595 
7596         p_end_date    :=  g_salary_end_date;
7597         debug('p_start_date: '||p_start_date||'   p_end_date: '||p_end_date);
7598         debug_exit(l_proc);
7599         RETURN 0;
7600     END get_start_end_date;
7601     ---
7602     -- ----------------------------------------------------------------------------
7603     -- |-------------------------< get_contract_type >-----------------------------|
7604     -- ----------------------------------------------------------------------------
7605     FUNCTION get_contract_type
7606                 (
7607                 p_assignment_id          NUMBER
7608                 ,p_business_group_id     NUMBER
7609                 ,p_effective_date        IN DATE
7610                 ,p_contract_type         OUT NOCOPY VARCHAR2
7611                 ) RETURN NUMBER
7612     IS
7613         l_proc varchar2(72) := g_proc_name||'.get_contract_type';
7614         l_contract_type pqp_assignment_attributes_f.contract_type%type;
7615         l_work_pattern  pqp_assignment_attributes_f.work_pattern%type;
7616         l_period_divisor    VARCHAR2(10);
7617         l_error_msg         VARCHAR2(100);
7618         l_err_no            NUMBER;
7619         l_error             NUMBER;
7620     BEGIN
7621         debug_enter(l_proc);
7622         /* Currently for all MOD employees the contract type will be 'M'*/
7623         p_contract_type  :=  'M';
7624 
7625         /* The following code should be uncommented if contract type will
7626             not be a hard-coded value*/
7627 
7628         /*IF g_penserver_contract_type IS NOT NULL
7629           AND g_contract_type_effective_date  =  p_effective_date THEN
7630               p_contract_type  :=  g_penserver_contract_type;
7631         ELSE
7632             OPEN csr_get_contract_type
7633                     (
7634                     p_effective_date  =>  p_effective_date
7635                     );
7636             FETCH csr_get_contract_type INTO l_contract_type;
7637             CLOSE csr_get_contract_type;
7638 
7639             IF l_contract_type IS NULL THEN
7640                 -- Raise warning that the contract type is missing
7641                 debug('WARNING: Contract type for the person is missing',20);
7642                 l_error :=  PQP_GB_PSI_FUNCTIONS.raise_extract_warning
7643                                (p_error_number        =>    94441
7644                                ,p_error_text          =>    'BEN_94441_NO_CONTRACT_TYPE'
7645                                ,p_token1              =>    to_char(g_effective_date,'dd-MON-yyyy')
7646                                );
7647             ELSE
7648                 debug('l_contract_type: '||l_contract_type,20);
7649                 l_err_no := pqp_utilities.pqp_gb_get_table_value(
7650                               p_business_group_id         =>    p_business_group_id
7651                              ,p_effective_date            =>    p_effective_date
7652                              ,p_table_name                =>    'PQP_CONTRACT_TYPES'
7653                              ,p_column_name               =>    'PenServer Contract Type'
7654                              ,p_row_name                  =>    l_contract_type
7655                              ,p_value                     =>    p_contract_type
7656                              ,p_error_msg                 =>    l_error_msg
7657                              ,p_refresh_cache             =>    'N'
7658                             );
7659                 IF p_output IS NULL THEN
7660                     -- raise warning that the PenServer Contract Type is missing in the UDT PQP_CONTRACT_TYPES for the contract
7661                     debug('WARNING: PenServer Contract Type is missing in the'||
7662                                 'UDT PQP_CONTRACT_TYPES for the contract: '||l_contract_type,20);
7663                     l_error :=  PQP_GB_PSI_FUNCTIONS.raise_extract_warning
7664                                (p_error_number        =>    94442
7665                                ,p_error_text          =>    'BEN_94442_NO_PEN_CONTRACT_TYPE'
7666                                ,p_token1              =>    to_char(g_effective_date,'dd-MON-yyyy')
7667                                );
7668                 ELSE
7669                     p_output := upper(p_output);
7670                     g_contract_type                 :=  l_contract_type;
7671                     g_penserver_contract_type       :=  p_contract_type;
7672                     g_contract_type_effective_date  :=  p_effective_date;
7673                 END IF; -- IF p_output IS NULL
7674             END IF; -- IF l_contract_type IS NULL
7675         END IF; -- IF g_penserver_contract_type IS NOT NULL*/
7676 
7677         debug('PenServer Contract Type: '||p_contract_type);
7678         debug_exit(l_proc);
7679         return l_error;
7680     END get_contract_type;
7681     ---
7682     ----------------------------------------------------------------------------
7683     -- |------------------------< get_element_attribution >--------------------------|
7684     -- ----------------------------------------------------------------------------
7685     PROCEDURE get_element_attribution
7686               (
7687               p_element_name      VARCHAR2
7688               ,p_ele_attribution  OUT NOCOPY  r_ele_attribution
7689               )
7690     IS
7691           l_proc varchar2(72) := g_proc_name||'get_element_attribution';
7692           l_element_type_id   NUMBER;
7693           l_ele_attribution   r_ele_attribution;
7694 
7695           CURSOR csr_get_ele_type_id
7696           IS
7697              SELECT element_type_id
7698              FROM pay_element_types_f
7699              WHERE element_name = p_element_name
7700              AND rownum=1;
7701 
7702           CURSOR csr_get_ele_attribution
7703                      (
7704                      p_element_type_id    NUMBER
7705                      )
7706           IS
7707              SELECT pei.eei_information1  from_time_dimension
7708                     ,pei.eei_information2  pay_source_value
7709                     ,pei.eei_information3  qualifier
7710                     ,pei.eei_information4  fte
7711                     ,pei.eei_information5  termtime
7712                     ,pei.eei_information7  calc_type
7713                     ,pei.eei_information8  calc_value
7714                     ,pei.eei_information9  input_value
7715                     ,NVL(pei.eei_information10
7716                         ,decode(pei.eei_information2,'IV','Y','N')) link_to_assign
7717                     ,NVL(pei.eei_information12,'Y') term_time_yes_no  -- ! be careful
7718                     ,NVL(pei.eei_information13,'N') sum_multiple_entries_yn
7719                     ,NVL(pei.eei_information14,'N') lookup_input_values_yn
7720                     ,pei.eei_information16 column_name_source_type
7721                     ,pei.eei_information17 column_name_source_name
7722                     ,pei.eei_information18 row_name_source_type
7723                     ,pei.eei_information19 row_name_source_name
7724               FROM -- pay_element_types_f pet
7725                     pay_element_type_extra_info pei
7726               WHERE pei.element_type_id = p_element_type_id
7727               AND pei.information_type = 'PQP_UK_ELEMENT_ATTRIBUTION';
7728     BEGIN
7729           debug_enter(l_proc);
7730 
7731           OPEN csr_get_ele_type_id;
7732           FETCH csr_get_ele_type_id INTO l_element_type_id;
7733           CLOSE csr_get_ele_type_id;
7734 
7735           debug('l_element_type_id: '||l_element_type_id);
7736 
7737           IF g_ele_attribution.exists(l_element_type_id) THEN
7738               debug('Element attribution is already fetched for this element: '||p_element_name);
7739               p_ele_attribution :=  g_ele_attribution(l_element_type_id);
7740           ELSE
7741               debug('Fetch the Element attribution for this element: '||p_element_name);
7742               OPEN csr_get_ele_attribution(l_element_type_id);
7743               FETCH csr_get_ele_attribution INTO l_ele_attribution;
7744               IF csr_get_ele_attribution%FOUND THEN
7745                   g_ele_attribution(l_element_type_id)  :=  l_ele_attribution;
7746                   p_ele_attribution   :=    l_ele_attribution;
7747               END IF;
7748               CLOSE csr_get_ele_attribution;
7749           END IF;
7750 
7751           debug_exit(l_proc);
7752     END get_element_attribution;
7753     ------------------------------------------------------------------------------
7754     --|-------------------------< get_notional_pay >-----------------------|
7755     -- ----------------------------------------------------------------------------
7756     FUNCTION get_notional_pay
7757                 (
7758                 p_assignment_id       IN NUMBER
7759                 ,p_business_group_id  IN NUMBER
7760                 ,p_effective_date  IN DATE
7761                 ,p_name            IN VARCHAR2
7762                 ,p_rt_element      IN VARCHAR2
7763                 ,p_rate            IN OUT NOCOPY NUMBER
7764                 ,p_custom_function IN VARCHAR2
7765                 ,p_allowance_code   IN VARCHAR2
7766                 ,p_allowance_pet_id IN NUMBER
7767                 ) RETURN NUMBER
7768     IS
7769         l_proc varchar2(72) := g_proc_name||'.get_notional_pay';
7770         l_contract_type           VARCHAR2(1);
7771         l_to_time_dim             VARCHAR2(1);
7772         l_basic_sal_rate          VARCHAR2(80);
7773         l_err_no                  NUMBER;
7774         l_err_msg                 VARCHAR2(100);
7775         l_assignment_category     VARCHAR2(20);
7776         l_fte                     VARCHAR2(1) := 'Y';
7777         l_notional_pay            NUMBER;
7778         l_error                   NUMBER;
7779         l_sqlstr                  VARCHAR2(2000);
7780         l_user_rate               NUMBER  :=  0;
7781         l_ele_attribution         r_ele_attribution;
7782         l_fte_value               NUMBER;
7783     BEGIN
7784         debug_enter(l_proc);
7785 
7786         debug('Parameters: ');
7787         debug('p_business_group_id:' || p_business_group_id,10);
7788         debug('p_assignment_id:' || p_assignment_id,10);
7789         debug('p_effective_date:' || p_effective_date,10);
7790         debug('p_name:' || p_name,10);
7791         debug('p_rt_element:' || p_rt_element,10);
7792         -- get contract type
7793         l_error :=  get_contract_type
7794                        (
7795                        p_assignment_id          =>    p_assignment_id
7796                        ,p_business_group_id     =>    p_business_group_id
7797                        ,p_effective_date        =>    p_effective_date
7798                        ,p_contract_type         =>    l_contract_type
7799                        );
7800         IF l_contract_type IS NOT NULL THEN
7801             -- depending on the contract type the to-time-dimension is decided
7802             IF l_contract_type = '5' OR l_contract_type = '6' THEN
7803                 l_to_time_dim := 'W';
7804             ELSE
7805                 l_to_time_dim := 'A';
7806             END IF;
7807 
7808             debug('l_to_time_dim:' || l_to_time_dim,10);
7809 
7810 
7811             l_err_no  :=  pqp_rates_history_calc.rates_history
7812                                 (p_assignment_id             =>   p_assignment_id
7813                                 ,p_calculation_date          =>   p_effective_date
7814                                 ,p_name                      =>   p_name
7815                                 ,p_rt_element                =>   p_rt_element
7816                                 ,p_to_time_dim               =>   l_to_time_dim
7817                                 ,p_rate                      =>   l_notional_pay
7818                                 ,p_error_message             =>   l_err_msg
7819                                 --,p_contract_type             =>   g_contract_type
7820                                 --,p_contract_type_usage       =>   'OVERRIDE'
7821                                 );
7822 
7823             if l_err_no <> -1 then
7824 
7825                 -- 115.60
7826                 IF p_rt_element = 'E' THEN
7827                     -- for element mode call check for the FTE attribution
7828                     --  and reverse it.
7829                     get_element_attribution
7830                           (
7831                           p_element_name      =>    p_name
7832                           ,p_ele_attribution  =>    l_ele_attribution
7833                           );
7834                    IF l_ele_attribution.fte <> 'N' THEN
7835                       --if fte attribution is other than 'N'
7836                       -- fetch the FTE value of that date and reverse
7837                       --    the fte value in the notional pay value;
7838                       l_fte_value :=  get_fte_value
7839                                         (
7840                                         p_assignment_id   =>  g_assignment_id
7841                                         ,p_effective_date =>  p_effective_date
7842                                         );
7843                      debug('l_fte_value: '||l_fte_value);
7844                      IF l_fte_value > 0 THEN
7845                         -- fte value is returned as -1 when the value is not there.
7846                         l_notional_pay :=  l_notional_pay/nvl(l_fte_value,1);
7847                      END IF;
7848                    END IF;
7849                 END IF;
7850                 -- get the user notional pay value
7851                 IF p_custom_function IS NOT NULL THEN
7852                     BEGIN
7853                         -- build the call to the user function.
7854                         l_sqlstr    :=
7855                                'BEGIN '
7856                             || p_custom_function
7857                             || '( :assignment_id,:business_group_id,:effective_date,'
7858                             || ':source_name,:source_qualifier,:to_time_dim,:notional_rate,:allowance_code,'
7859                             || ':allowance_pet_id,:user_rate);'
7860                             || 'END;';
7861 
7862                         IF g_debug
7863                         THEN
7864                            debug('l_sqlstr: ' || l_sqlstr);
7865                         END IF;
7866 
7867                         EXECUTE IMMEDIATE l_sqlstr
7868                            USING              p_assignment_id
7869                                         ,     p_business_group_id
7870                                         ,     p_effective_date
7871                                         ,     p_name                -- name of the element or rate type
7872                                         ,     p_rt_element          -- 'R' / 'E'
7873                                         ,     l_to_time_dim         -- 'W' / 'A'
7874                                         ,     l_notional_pay        -- Historic Rates values
7875                                         ,     p_allowance_code
7876                                         ,     p_allowance_pet_id
7877                                         ,OUT    l_user_rate;          -- value returned by the user function
7878 
7879                         p_rate          :=  NVL(l_user_rate,0);
7880                     EXCEPTION
7881                       WHEN others THEN
7882                          IF SQLCODE <> hr_utility.hr_error_number
7883                          THEN
7884                              debug_others (l_proc, 10);
7885                              IF g_debug
7886                              THEN
7887                                DEBUG (   'Leaving: '
7888                                       || l_proc, -999);
7889                               END IF;
7890                               debug('ERROR: Error Raised during calculation of Notional Pay',20);
7891                               l_error :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
7892                                                (p_error_number        =>    94541
7893                                                ,p_error_text          =>    'BEN_94541_ERR_USR_NOTIONAL_PAY'
7894                                                ,p_token1              =>    p_custom_function
7895                                                );
7896                           ELSE
7897                               RAISE;
7898                           END IF;
7899                     END;
7900                 ELSE
7901                     debug('Without using the callout fucntion.',30);
7902                     p_rate          :=  NVL(l_notional_pay,0);
7903                 END IF; --IF p_custom_function IS NOT NULL THEN
7904             else
7905                 debug('ERROR: Error Raised during calculation of Notional Pay',20);
7906                 l_error :=  PQP_GB_PSI_FUNCTIONS.raise_extract_error
7907                                    (p_error_number        =>    94456
7908                                    ,p_error_text          =>    'BEN_94456_ERR_NOTIONAL_PAY'
7909                                    ,p_token1              =>    SUBSTR(l_err_msg,1,30)
7910                                    );
7911                 p_rate          :=  0;
7912             end if; --if l_err_no <> -1
7913 
7914         END IF; --IF l_contract_type IS NOT NULL
7915 
7916         debug('Notional Pay: '||p_rate,10);
7917         debug_exit(l_proc);
7918         return 0;
7919     END get_notional_pay;
7920     ---
7921     ----------------------------------------------------------------------------
7922     -- |------------------------< get_fte_value >--------------------------|
7923     -- ----------------------------------------------------------------------------
7924     FUNCTION get_fte_value
7925               (
7926               p_assignment_id   NUMBER
7927               ,p_effective_date  DATE
7928               )RETURN NUMBER
7929     IS
7930         l_proc varchar2(72) := g_proc_name||'.get_fte_value';
7931         l_fte_value NUMBER;
7932         CURSOR csr_get_fte_value
7933         IS
7934           SELECT value
7935           FROM PER_ASSIGNMENT_BUDGET_VALUES_F
7936           WHERE assignment_id = p_assignment_id
7937           AND UNIT = 'FTE'
7938           AND p_effective_date between effective_start_date
7939                           AND effective_end_date;
7940     BEGIN
7941         debug_enter(l_proc);
7942         OPEN csr_get_fte_value;
7943         FETCH csr_get_fte_value INTO l_fte_value;
7944         CLOSE csr_get_fte_value;
7945         IF l_fte_value IS NOT NULL THEN
7946           return l_fte_value;
7947         END IF;
7948         return -1;
7949         debug_exit(l_proc);
7950     END get_fte_value;
7951     ---
7952     -- ----------------------------------------------------------------------------
7953     -- |------------------------< get_actual_pay >--------------------------|
7954     -- ----------------------------------------------------------------------------
7955     FUNCTION get_actual_pay
7956                 (
7957                 p_assignment_id   IN NUMBER
7958                 ,p_notional_pay   IN NUMBER
7959                 ,p_effective_date IN DATE
7960                 ,p_output         OUT NOCOPY VARCHAR2
7961                 )RETURN NUMBER
7962     IS
7963         l_proc varchar2(72) := g_proc_name||'.get_actual_pay';
7964         l_assignment_category     VARCHAR2(20);
7965         l_fte_value               NUMBER;
7966         l_error                   NUMBER;
7967     BEGIN
7968       debug_enter(l_proc);
7969       l_fte_value :=  get_fte_value(p_assignment_id,p_effective_date);
7970       IF l_fte_value <> -1 THEN
7971         debug('Par-time employee.. FTE value is less than 1',10);
7972         IF l_fte_value < 1 THEN
7973             p_output  :=  (p_notional_pay * l_fte_value);
7974             debug('Actual pay: '||to_char(p_output),20);
7975         END IF;
7976       ELSE
7977         -- data error.
7978         debug('Data Error: FTE value for the person is missing on: '||to_char(g_effective_date,'dd/mm/yyyy'),20);
7979         l_error :=  PQP_GB_PSI_FUNCTIONS.raise_extract_warning
7980                        (p_error_number        =>    94449
7981                        ,p_error_text          =>    'BEN_94449_NO_FTE_VALUE'
7982                        ,p_token1              =>    to_char(g_effective_date,'dd-MON-yyyy')
7983                        );
7984       END IF;
7985       debug_exit(l_proc);
7986       return 0;
7987     END get_actual_pay;
7988     ---
7989     -- ----------------------------------------------------------------------------
7990     -- |------------------------< init_st_end_date_glob --------------------------|
7991     -- ----------------------------------------------------------------------------
7992     PROCEDURE init_st_end_date_glob
7993     IS
7994         l_proc varchar2(72) := g_proc_name||'.init_st_end_date_glob';
7995     BEGIN
7996       debug_enter(l_proc);
7997 
7998       -- reset assignment level globals
7999       g_pay_proc_evt_tab             :=  ben_ext_person.g_pay_proc_evt_tab;
8000       g_salary_ended                 := 'N';
8001       g_salary_started               := 'Y';
8002       g_salary_ele_end_date          := c_highest_date;
8003       g_non_salary_ele_end_date      := c_highest_date;
8004       g_sal_chg_event_exists         := 'N';
8005       g_salary_end_date              := NULL;
8006       g_is_terminated                := 'N';
8007       g_salary_ended_today           := 'N';
8008       g_allowance_has_end_dated      := 'N';
8009 
8010       debug_exit(l_proc);
8011     END init_st_end_date_glob;
8012     ---
8013     ---
8014     -- ----------------------------------------------------------------------------
8015     -- |-------------------< get_first_retro_event_date --------------------------|
8016     -- ----------------------------------------------------------------------------
8017     FUNCTION get_first_retro_event_date
8018                 (
8019                 p_assignment_id    IN  NUMBER
8020                 ,p_retro_event_date OUT NOCOPY DATE
8021                 )RETURN NUMBER
8022     IS
8023           l_proc varchar2(72) := g_proc_name||'get_first_retro_event_date';
8024     BEGIN
8025           debug_enter(l_proc);
8026 
8027         IF  g_min_effective_date.EXISTS(p_assignment_id)
8028         THEN
8029           debug('g_min_effective_date(g_assignment_id): '||g_min_effective_date(p_assignment_id),20);
8030           p_retro_event_date  :=  g_min_effective_date(p_assignment_id);
8031 
8032           g_retro_event_date_reported :=  TRUE;
8033 
8034           debug('p_retro_event_date: '||p_retro_event_date,10);
8035         END IF;
8036 
8037         debug_exit(l_proc);
8038         RETURN 0;
8039     END get_first_retro_event_date;
8040     ---
8041 
8042     ---
8043     -- ----------------------------------------------------------------------------
8044     -- |------------------------< get_rate_usr_func_name >--------------------------|
8045     -- ----------------------------------------------------------------------------
8046     PROCEDURE get_rate_usr_func_name
8047                 (
8048                 p_business_group_id   NUMBER
8049                 ,p_legislation_code   VARCHAR2
8050                 ,p_interface_name     VARCHAR2    -- expected to be SALARY / ALLOWANCE
8051                 ,p_rate_name          OUT NOCOPY VARCHAR2
8052                 ,p_rate_code          OUT NOCOPY VARCHAR2
8053                 ,p_usr_rate_function  OUT NOCOPY VARCHAR2
8054                 ,p_sal_ele_fte_attr   OUT NOCOPY VARCHAR2 -- 115.60
8055                 )
8056     IS
8057           c_seeded_basic_sal_rate_name   CONSTANT VARCHAR2(80) := 'PenServer Pensionable Salary';
8058           c_seeded_basic_sal_rate_code   CONSTANT VARCHAR2(80) := 'PEN_SALARY';
8059           l_rate_code          VARCHAR2(80);
8060           l_rate_name          VARCHAR2(80);
8061           l_config_value   PQP_UTILITIES.t_config_values;
8062           l_proc varchar2(72) := g_proc_name||'get_rate_usr_func_name';
8063           l_itr NUMBER;
8064     BEGIN
8065           debug_enter(l_proc);
8066 
8067           debug('p_business_group_id: '||p_business_group_id,10);
8068           debug('p_legislation_code: '||p_legislation_code,10);
8069           debug('p_interface_name: '||p_interface_name,10);
8070 
8071 
8072           PQP_UTILITIES.get_config_type_values(
8073                              p_configuration_type   =>    'PQP_GB_PENSERVER_RATE_TYPES'
8074                             ,p_business_group_id    =>    p_business_group_id
8075                             ,p_legislation_code     =>    p_legislation_code
8076                             ,p_tab_config_values    =>    l_config_value
8077                           );
8078           IF l_config_value.COUNT > 0 THEN
8079               FOR i in 1..l_config_value.COUNT
8080               LOOP
8081                   IF i = 1 THEN
8082                       l_itr := l_config_value.FIRST;
8083                   ELSE
8084                       l_itr := l_config_value.NEXT(l_itr);
8085                   END IF;
8086                   IF p_interface_name = 'SALARY' AND l_config_value(l_itr).pcv_information1 = 'BAS_SALARY' THEN
8087                       p_rate_code          :=  l_config_value(l_itr).pcv_information2;
8088                       p_usr_rate_function  :=  l_config_value(l_itr).pcv_information3;
8089                       p_sal_ele_fte_attr   :=  l_config_value(l_itr).pcv_information4;
8090                       EXIT;
8091                   ELSIF p_interface_name = 'ALLOWANCE' AND l_config_value(l_itr).pcv_information1 = 'ALLOWANCE' THEN
8092                       --p_rate_code           :=  l_config_value(l_itr).pcv_information2;
8093                       p_usr_rate_function  :=  l_config_value(l_itr).pcv_information3;
8094                       EXIT;
8095                   END IF;
8096               END LOOP;
8097           END IF;
8098 
8099           IF p_rate_code IS NOT NULL THEN
8100               p_rate_name :=  HR_GENERAL.DECODE_LOOKUP
8101                                             (
8102                                             p_lookup_type   =>  'PQP_RATE_TYPE'
8103                                             ,p_lookup_code  =>  p_rate_code
8104                                             );
8105 
8106           END IF;
8107 
8108           debug('p_rate_name: '||p_rate_name);
8109           debug('p_rate_code: '||p_rate_code);
8110           debug('p_usr_rate_function: '||p_usr_rate_function);
8111           debug('p_sal_ele_fte_attr: '||p_sal_ele_fte_attr);
8112           debug_exit(l_proc);
8113     END get_rate_usr_func_name;
8114     ---
8115 
8116 END PQP_GB_PSI_FUNCTIONS;