DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQP_NL_PENSION_EXTRACTS

Source


1 PACKAGE BODY PQP_NL_PENSION_EXTRACTS AS
2 /* $Header: pqpnlpext.pkb 120.123.12010000.7 2008/09/04 05:58:24 rsahai ship $ */
3 
4 g_proc_name  VARCHAR2(200) :='PQP_NL_Pension_Extracts.';
5 g_debug      BOOLEAN       := hr_utility.debug_enabled;
6 
7 -- =============================================================================
8 -- Cursor to get the extract record id's for extract definition id
9 -- =============================================================================
10 CURSOR csr_ext_rcd_id_with_seq  IS
11    SELECT Decode(rin.seq_num,1,'00',
12                              2,'01',
13                              3,'02',
14                              4,'04',
15                              5,'05',
16                              7,'08',
17                              8,'09',
18                             10,'12',
19                             12,'20',
20                             14,'21',
21                             16,'22',
22                             17,'30',
23                             19,'31',
24                             21,'40',
25                             23,'41',
26                             26,'94',
27                             27,'95',
28                             28,'96',
29                             29,'97',
30                             30,'99',
31                             '~') rec_num,
32           rin.seq_num,
33           rin.hide_flag,
34           rcd.ext_rcd_id,
35           rcd.rcd_type_cd
36     FROM  ben_ext_rcd         rcd
37          ,ben_ext_rcd_in_file rin
38          ,ben_ext_dfn dfn
39    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
40      AND rin.ext_file_id  = dfn.ext_file_id
41      AND rin.ext_rcd_id   = rcd.ext_rcd_id
42      ORDER BY rin.seq_num;
43 
44 -- =============================================================================
45 -- Cursor to get the extract record id's for record sequence number
46 -- =============================================================================
47 CURSOR c_get_rcd_id(c_seq IN Number)  IS
48    SELECT rcd.ext_rcd_id
49     FROM  ben_ext_rcd         rcd
50          ,ben_ext_rcd_in_file rin
51          ,ben_ext_dfn dfn
52    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id -- The extract executing currently
53      AND rin.ext_file_id  = dfn.ext_file_id
54      AND rin.ext_rcd_id   = rcd.ext_rcd_id
55      AND rin.seq_num      = c_seq;
56 
57 
58 -- =============================================================================
59 -- Cursor to get assignment details
60 -- =============================================================================
61 CURSOR csr_assig (c_assignment_id     IN Number
62                  ,c_effective_date    IN Date
63                  ,c_business_group_id IN Number) IS
64 SELECT paf.person_id
65       ,paf.organization_id
66       ,paf.assignment_type
67       ,paf.effective_start_date
68       ,paf.effective_end_date
69       ,ast.user_status
70       ,Hr_General.decode_lookup
71         ('EMP_CAT',
72           paf.employment_category) employment_category
73       ,pps.date_start
74       ,pps.actual_termination_date
75       ,paf.payroll_id
76       ,'ER'
77       ,per.employee_number
78       ,paf.assignment_sequence
79       ,per.national_identifier
80       ,per.last_name
81       ,per.per_information1
82       ,per.pre_name_adjunct
83       ,per.sex
84       ,per.date_of_birth
85       ,'PLN'
86       ,'PIX'
87       ,per.per_information14
88       ,per.marital_status
89       ,paf.primary_flag
90   FROM per_all_assignments_f       paf,
91        per_all_people_f            per,
92        per_periods_of_service      pps,
93        per_assignment_status_types ast
94  WHERE paf.assignment_id             = c_assignment_id
95    AND paf.person_id                 = per.person_id
96    AND pps.period_of_service_id(+)       = paf.period_of_service_id
97    AND ast.assignment_status_type_id = paf.assignment_status_type_id
98    AND c_effective_date BETWEEN paf.effective_start_date
99                             AND paf.effective_end_date
100    AND c_effective_date BETWEEN per.effective_start_date
101                             AND per.effective_end_date
102    AND paf.business_group_id = c_business_group_id
103    AND per.business_group_id = c_business_group_id;
104 
105 -- =============================================================================
106 -- Cursor to get secondary asgs
107 -- =============================================================================
108 CURSOR csr_sec_assig (c_assignment_id     IN Number
109                      ,c_effective_date    IN Date
110                      ,c_business_group_id IN Number
111                      ,c_person_id         IN Number) IS
112 SELECT paf.organization_id
113       ,paf.payroll_id
114   FROM per_all_assignments_f       paf,
115        per_all_people_f            per
116  WHERE paf.assignment_id             <> c_assignment_id
117    AND paf.person_id                 = c_person_id
118    AND paf.person_id                 = per.person_id
119    AND c_effective_date BETWEEN paf.effective_start_date
120                             AND paf.effective_end_date
121    AND c_effective_date BETWEEN per.effective_start_date
122                             AND per.effective_end_date
123    AND paf.business_group_id = c_business_group_id
124    AND per.business_group_id = c_business_group_id;
125 
126 -- =============================================================================
127 -- Cursor to get the defined balance id for a given balance and dimension
128 -- =============================================================================
129 CURSOR csr_defined_bal (c_balance_name      IN Varchar2
130                        ,c_dimension_name    IN Varchar2
131                        ,c_business_group_id IN Number) IS
132  SELECT db.defined_balance_id
133    FROM pay_balance_types pbt
134        ,pay_defined_balances db
135        ,pay_balance_dimensions bd
136   WHERE pbt.balance_name        = c_balance_name
137     AND pbt.balance_type_id     = db.balance_type_id
138     AND bd.balance_dimension_id = db.balance_dimension_id
139     AND bd.dimension_name       = c_dimension_name
140     AND (pbt.business_group_id  = c_business_group_id OR
141          pbt.legislation_code   = g_legislation_code)
142     AND (db.business_group_id   = pbt.business_group_id OR
143          db.legislation_code    = g_legislation_code);
144 
145 -- =============================================================================
146 -- Cursor to get the defined balance id for a given balance and dimension
147 -- =============================================================================
148 CURSOR csr_defined_bal1 (c_balance_type_id   IN Number
149                        ,c_dimension_name    IN Varchar2
150                        ,c_business_group_id IN Number) IS
151  SELECT db.defined_balance_id
152    FROM pay_defined_balances db
153        ,pay_balance_dimensions bd
154   WHERE db.balance_type_id      = c_balance_type_id
155     AND bd.balance_dimension_id = db.balance_dimension_id
156     AND bd.dimension_name       = c_dimension_name
157     AND (db.business_group_id   = c_business_group_id OR
158          db.legislation_code    = g_legislation_code);
159 
160 -- =============================================================================
161 -- Cursor to get the ASG_RUN defined balance id for a given balance name
162 -- =============================================================================
163 CURSOR csr_asg_balid (c_balance_type_id         IN Number
164                      ,c_balance_dimension_id    IN Number
165                      ,c_business_group_id       IN Number) IS
166  SELECT db.defined_balance_id
167    FROM pay_defined_balances db
168   WHERE db.balance_type_id      = c_balance_type_id
169     AND db.balance_dimension_id = c_balance_dimension_id
170     AND (db.business_group_id   = c_business_group_id OR
171          db.legislation_code    = g_legislation_code);
172 
173 -- =============================================================================
174 -- Cursor to get all assig.actions for a given assig. within a date range
175 -- =============================================================================
176 CURSOR csr_asg_act (c_assignment_id IN Number
177                    ,c_payroll_id    IN Number
178                    ,c_con_set_id    IN Number
179                    ,c_start_date    IN Date
180                    ,c_end_date      IN Date
181                    ) IS
182   SELECT paa.assignment_action_id
183         ,ppa.effective_date
184         ,ppa.action_type
185         ,ppa.date_earned
186     FROM pay_assignment_actions paa
187         ,pay_payroll_actions    ppa
188    WHERE paa.assignment_id        = c_assignment_id
189      AND ppa.action_status        = 'C'
190      AND paa.action_status        = 'C'
191      AND ppa.action_type          IN ('Q','R')
192      AND paa.payroll_action_id    = ppa.payroll_action_id
193      AND ppa.payroll_id           = Nvl(c_payroll_id,ppa.payroll_id)
194      AND ppa.consolidation_set_id = Nvl(c_con_set_id,ppa.consolidation_set_id)
195      AND ppa.effective_date BETWEEN c_start_date
196                                 AND c_end_date
197      AND source_action_id IS NOT NULL
198      ORDER BY ppa.effective_date;
199 
200 l_asg_act csr_asg_act%ROWTYPE;
201 
202 -- =============================================================================
203 -- Cursor to get all assig.actions for a given assig. within a data range
204 -- =============================================================================
205 CURSOR csr_asg_act1 (c_assignment_id IN Number
206                    ,c_payroll_id    IN Number
207                    ,c_con_set_id    IN Number
208                    ,c_start_date    IN Date
209                    ,c_end_date      IN Date
210                    ) IS
211   SELECT max(paa.assignment_action_id)
212     FROM pay_assignment_actions paa
213         ,pay_payroll_actions    ppa
214    WHERE paa.assignment_id        = c_assignment_id
215      AND ppa.action_status        = 'C'
216      AND ppa.action_type          IN ('Q','R')
217      AND paa.action_status        = 'C'
218      AND paa.payroll_action_id    = ppa.payroll_action_id
219      AND ppa.payroll_id           = Nvl(c_payroll_id,ppa.payroll_id)
220      AND ppa.consolidation_set_id = Nvl(c_con_set_id,ppa.consolidation_set_id)
221      AND source_action_id IS NOT NULL
222      AND ppa.effective_date BETWEEN c_start_date
223                                 AND c_end_date;
224 
225 -- =============================================================================
226 -- Cursor to get all assig.actions for a given assig. within a data range
227 -- =============================================================================
228 CURSOR csr_asg_act_de (c_assignment_id IN Number
229                    ,c_start_de    IN Date
230                    ,c_end_de      IN Date
231                    ,c_bg_id       IN NUMBER
232 
233                    ) IS
234   SELECT max(paa.assignment_action_id)
235     FROM pay_assignment_actions paa
236         ,pay_payroll_actions    ppa
237    WHERE paa.assignment_id        = c_assignment_id
238      AND ppa.action_status        = 'C'
239      AND ppa.action_type          IN ('Q','R')
240      AND paa.action_status        = 'C'
241      AND paa.payroll_action_id    = ppa.payroll_action_id
242      AND source_action_id IS NOT NULL
243      AND ppa.date_earned BETWEEN c_start_de
244                                 AND c_end_de
245      AND ppa.effective_date BETWEEN g_extract_params(c_bg_id).extract_start_date
246                                 AND g_extract_params(c_bg_id).extract_end_date;
247 
248 -- =============================================================================
249 -- Cursor to get the extract record id
250 -- =============================================================================
251 CURSOR csr_ext_rcd_id(c_hide_flag	IN Varchar2
252 	             ,c_rcd_type_cd	IN Varchar2
253                       ) IS
254 SELECT rcd.ext_rcd_id
255   FROM  ben_ext_rcd         rcd
256        ,ben_ext_rcd_in_file rin
257        ,ben_ext_dfn dfn
258  WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id -- The extract
259    AND rin.ext_file_id  = dfn.ext_file_id
260    AND rin.hide_flag    = c_hide_flag     -- Y=Hidden, N=Not Hidden
261    AND rin.ext_rcd_id   = rcd.ext_rcd_id
262    AND rcd.rcd_type_cd  = c_rcd_type_cd;  -- D=Detail,H=Header,F=Footer
263 
264 -- =============================================================================
265 -- Cursor to get the extract record id for hidden and Not hidden records
266 -- =============================================================================
267 CURSOR csr_ext_rcd_id_hidden(c_rcd_type_cd	IN Varchar2) IS
268     SELECT rcd.ext_rcd_id
269     FROM  ben_ext_rcd         rcd
270          ,ben_ext_rcd_in_file rin
271          ,ben_ext_dfn dfn
272    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
273      AND rin.ext_file_id  = dfn.ext_file_id
274      AND rin.ext_rcd_id   = rcd.ext_rcd_id
275      AND rcd.rcd_type_cd  = c_rcd_type_cd
276      ORDER BY rin.seq_num;
277 
278 
279 -- =============================================================================
280 -- Cursor to get the extract result dtl record for a person id
281 -- =============================================================================
282 CURSOR csr_rslt_dtl(c_person_id      IN Number
283                    ,c_ext_rslt_id    IN Number
284                    ,c_ext_dtl_rcd_id IN Number ) IS
285    SELECT *
286      FROM ben_ext_rslt_dtl dtl
287     WHERE dtl.ext_rslt_id = c_ext_rslt_id
288       AND dtl.person_id   = c_person_id
289       AND dtl.ext_rcd_id  = c_ext_dtl_rcd_id;
290 
291 -- =============================================================================
292  -- Cursor to get the balance type id for a given name
293 -- =============================================================================
294    CURSOR csr_bal_typid (c_balance_name       IN Varchar2
295                         ,c_business_group_id  IN Number
296                         ,c_legislation_code   IN Varchar2) IS
297    SELECT pbt.balance_type_id
298      FROM pay_balance_types pbt
299     WHERE pbt.balance_name        = c_balance_name
300       AND (pbt.business_group_id  = c_business_group_id
301            OR
302            pbt.legislation_code   = c_legislation_code);
303 
304 -- ============================================================================
305 -- Cursor to get the Organization name
306 -- ============================================================================
307 CURSOR csr_org_name (c_org_id IN Number)IS
308 SELECT NAME
309   FROM hr_all_organization_units
310  WHERE organization_id = c_org_id;
311 
312 -- =============================================================================
313 -- Cursor to chk for other primary assig. within the extract date range.
314 -- =============================================================================
315 CURSOR csr_sec_assg
316         (c_primary_assignment_id IN per_all_assignments_f.assignment_id%TYPE
317         ,c_person_id		     IN per_all_people_f.person_id%TYPE
318         ,c_effective_date    	 IN Date
319         ,c_extract_start_date    IN Date
320         ,c_extract_end_date      IN Date ) IS
321   SELECT asg.person_id
322         ,asg.organization_id
323         ,asg.assignment_type
324         ,asg.effective_start_date
325         ,asg.effective_end_date
326         ,'NO'
327         ,asg.assignment_id
328     FROM per_all_assignments_f  asg
329    WHERE asg.person_id       = c_person_id
330      AND asg.assignment_id  <> c_primary_assignment_id
331      AND asg.assignment_type ='E'
332      AND (( c_effective_date  BETWEEN asg.effective_start_date
333                                   AND asg.effective_end_date
334            )
335           OR
336           ( asg.effective_end_date =
337            (SELECT Max(asx.effective_end_date)
338               FROM per_all_assignments_f asx
339              WHERE asx.assignment_id   = asg.assignment_id
340                AND asx.person_id       = c_person_id
341                AND asx.assignment_type = 'E'
342                AND ((asx.effective_end_date BETWEEN c_extract_start_date
343                                                 AND c_extract_end_date)
344                      OR
345                     (asx.effective_start_date BETWEEN c_extract_start_date
346                                                   AND c_extract_end_date)
347                    )
348             )
349            )
350          )
351    ORDER BY asg.effective_start_date ASC;
352 
353 -- ============================================================================
354 -- Cursor to get the valid element_type_id for record 09 (at BG Level)
355 -- ============================================================================
356 CURSOR c_rec_09_ele( c_bg_id          IN Number
357                     ,c_effective_date IN Date) IS
358 SELECT pet.element_type_id
359       ,pei.eei_information9||' Employee Pension Basis' bal_name
360       ,pei.eei_information12 sub_cat
361       ,Decode (pei.eei_information12,'AAOP','AP','IPBW_H','IH','IPBW_L','IL'
362               ,'FPB','FB','FPU_C','FO','OP') code
363       ,-1 defined_bal_id
364       ,pei.eei_information18 cy_retro_element_id
365       ,pei.eei_information19 py_retro_element_id
366       ,(SELECT retro_element_type_id
367 	  FROM pay_element_span_usages    pesu,
368 	       pay_retro_component_usages prcu
369          WHERE prcu.retro_component_usage_id = pesu.retro_component_usage_id
370            AND retro_component_id = ( SELECT retro_component_id
371 	                                FROM pay_retro_components
372                                        WHERE legislation_code = 'NL'
373                                          AND short_name     = 'Adjustment'
374                                          AND component_name = 'Adjustment')
375             AND creator_type = 'ET'
376             AND creator_id   = pet.element_type_id) py_cy_adj_retro_element_id
377  FROM pay_element_type_extra_info pei,
378       pay_element_types_f pet
379 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
380   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
381   -- AND c_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
382   --                              To_Date(pei.eei_information11,'DD/MM/RRRR')
383   AND c_effective_date BETWEEN pet.effective_start_date AND
384                                pet.effective_end_date
385   AND pet.element_type_id = pei.element_type_id
386   AND pet.business_group_id = c_bg_id
387   AND pei.EEI_INFORMATION12 IN ('OPNP','IPBW_H','IPBW_L','AAOP');
388 
389 -- ============================================================================
390 -- Cursor to get the valid element_type_id for record 31 (at BG Level)
391 -- ============================================================================
392 CURSOR c_rec_31_ele( c_bg_id          IN Number
393                     ,c_effective_date IN Date) IS
394 SELECT pet.element_type_id
395       ,pei.eei_information9||' Employee Pension Basis' bal_name
396       ,pei.eei_information12 sub_cat
397       ,'02' code
398       ,-1 defined_bal_id
399       ,pei.eei_information18 cy_retro_element_id
400       ,pei.eei_information19 py_retro_element_id
401  FROM pay_element_type_extra_info pei,
402       pay_element_types_f pet
403 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
404   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
405   AND c_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
406                                To_Date(pei.eei_information11,'DD/MM/RRRR')
407   AND c_effective_date BETWEEN pet.effective_start_date AND
408                                pet.effective_end_date
409   AND pet.element_type_id = pei.element_type_id
410   AND pet.business_group_id = c_bg_id
411   AND pei.EEI_INFORMATION12 IN ('IPAP');
412 
413 -- ============================================================================
414 -- Cursor to get the valid element_type_id for record 41 (at BG Level)
415 -- ============================================================================
416 CURSOR c_basis_rec_41_ele( c_bg_id          IN Number
417                     ,c_effective_date IN Date) IS
418 SELECT pet.element_type_id
419       ,pei.eei_information9||' Employee Pension Basis' bal_name
420       ,pei.eei_information12 sub_cat
421       ,'99' code
422       ,-1 defined_bal_id
423       ,pei.eei_information18 cy_retro_element_id
424       ,pei.eei_information19 py_retro_element_id
425  FROM pay_element_type_extra_info pei,
426       pay_element_types_f pet
427 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
428   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
429   AND c_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
430                                To_Date(pei.eei_information11,'DD/MM/RRRR')
431   AND c_effective_date BETWEEN pet.effective_start_date AND
432                                pet.effective_end_date
433   AND pet.element_type_id = pei.element_type_id
434   AND pet.business_group_id = c_bg_id
435   AND pei.EEI_INFORMATION12 IN ('FUR_S');
436 
437 --
438 -- Cursor to fetch any termination reversal related change event data
439 -- When a reversal of termination has happened, the period
440 -- of service should be open OR alternatively if the EE is terminated
441 -- in the future, the assignment should be active as of the effective date.
442 --
443 CURSOR c_get_revt_rows (p_business_group_id IN NUMBER
444                        ,p_effective_date    IN DATE
445                        ,p_assignment_id     IN NUMBER ) IS
446 SELECT old_val1,new_val1,ext_chg_evt_log_id
447   FROM ben_ext_chg_evt_log bec
448  WHERE chg_evt_cd            = 'DAT'
449    AND person_id             = g_person_id
450    AND bec.business_group_id = p_business_group_id
451    AND fnd_date.canonical_to_date(prmtr_09) BETWEEN
452        g_extract_params(p_business_group_id).extract_start_date
453    AND g_extract_params(p_business_group_id).extract_end_date
454    AND EXISTS(SELECT 1
455                 FROM per_periods_of_service pps
456                     ,per_all_assignments_f asg
457                WHERE pps.person_id            = g_person_id
458                  AND asg.assignment_id        = p_assignment_id
459                  AND asg.period_of_service_id = pps.period_of_service_id
460                  AND (pps.actual_termination_date IS NULL
461                       AND assignment_status_type_id IN
462                         (SELECT assignment_status_type_id
463                            FROM per_assignment_status_types
464                           WHERE per_system_status = 'ACTIVE_ASSIGN'
465                             AND active_flag       = 'Y'))
466                  AND p_effective_date BETWEEN effective_start_date
467                                           AND effective_end_date )
468 ORDER by bec.ext_chg_evt_log_id desc;
469 
470 --
471 -- Cursor to fetch the termination date of a terminated or
472 -- ended assignment.
473 --
474 CURSOR c_get_asg_term_date (p_business_group_id IN NUMBER
475                            ,p_effective_date    IN DATE
476                            ,p_assignment_id     IN NUMBER
477                            ,c_asg_seq_num       IN VARCHAR) IS
478 SELECT min(effective_start_date) - 1 term_date
479       ,period_of_service_id
480   FROM per_all_assignments_f asg
481  WHERE assignment_id = p_assignment_id
482    AND effective_start_date <= g_extract_params(p_business_group_id).extract_end_date
483    AND assignment_status_type_id IN (SELECT assignment_status_type_id
484                                        FROM per_assignment_status_types
485                                       WHERE per_system_status = 'TERM_ASSIGN'
486                                         AND active_flag = 'Y')
487 group by period_of_service_id
488  UNION
489 --
490 -- Get the dates for any ended assignments. Note that this is for sec
491 -- assignments only.
492 --
493 SELECT max(effective_end_date)
494       ,period_of_service_id
495   FROM per_all_assignments_f asg
496  WHERE assignment_id    = p_assignment_id
497    AND asg.primary_flag = 'N'
498    AND effective_end_date <= g_extract_params(p_business_group_id).extract_end_date
499    AND NOT EXISTS( SELECT 1
500                      FROM per_all_assignments_f  asg1
501                     WHERE asg1.assignment_id = p_assignment_id
502                       AND asg1.effective_start_date = asg.effective_end_date + 1
503                       AND asg.assignment_id = asg1.assignment_id )
504    AND NOT EXISTS( SELECT 1
505                      FROM per_all_assignments_f  asg1
506                     WHERE asg1.assignment_id = p_assignment_id
507                       AND asg1.effective_start_date < asg.effective_start_date
508                       AND asg.assignment_id = asg1.assignment_id
509                       AND asg1.assignment_status_type_id IN (SELECT assignment_status_type_id
510                                                           FROM per_assignment_status_types
511                                                        WHERE per_system_status = 'TERM_ASSIGN'
512                                                            AND active_flag = 'Y'))
513 group by period_of_service_id
514 ;
515 
516 --
517 -- Cursor to fetch any termination related change event data
518 -- from the ben ext log table
519 --
520 CURSOR c_get_term_rows (p_business_group_id IN NUMBER
521                        ,p_effective_date    IN DATE
522                        ,p_assignment_id     IN NUMBER
523                        ,c_asg_seq_num       IN VARCHAR) IS
524 SELECT old_val1
525       ,to_char(pps.actual_termination_date,'DD/MM/YYYY') term_date
526       ,ext_chg_evt_log_id
527       ,fnd_number.canonical_to_number(prmtr_01)
528  FROM ben_ext_chg_evt_log bec
529      ,per_periods_of_service pps
530      ,per_all_assignments_f asg
531 WHERE bec.chg_evt_cd  = 'AAT'
532   AND bec.person_id = g_person_id
533   AND bec.business_group_id = p_business_group_id
534   AND fnd_date.canonical_to_date(bec.prmtr_09)
535       BETWEEN g_extract_params(p_business_group_id).extract_start_date
536           AND g_extract_params(p_business_group_id).extract_end_date
537   AND pps.person_id = g_person_id
538   AND asg.assignment_id = p_assignment_id
539   AND asg.period_of_service_id = pps.period_of_service_id
540   AND pps.actual_termination_date IS NOT NULL
541   AND p_effective_date BETWEEN asg.effective_start_date
542                                          AND asg.effective_end_date
543 UNION
544 SELECT
545        NULL
546       ,term_date
547       ,9999999999 - rownum
548       ,period_of_service_id FROM (
549 SELECT NULL
550       ,to_char(effective_start_date - 1,'DD/MM/YYYY') term_date
551       ,9999999999
552       ,period_of_service_id
553  FROM per_all_assignments_f asg
554 WHERE assignment_id = p_assignment_id
555   AND assignment_status_type_id IN (SELECT assignment_status_type_id
556                                      FROM per_assignment_status_types
557                                     WHERE per_system_status = 'TERM_ASSIGN'
558                                       AND active_flag = 'Y')
559  AND effective_start_date BETWEEN
560           g_extract_params(p_business_group_id).extract_start_date
561       AND g_extract_params(p_business_group_id).extract_end_date
562  AND NOT EXISTS (  SELECT 1
563                      FROM ben_ext_chg_evt_log bec
564                     WHERE chg_evt_cd  = 'AAT'
565                       AND person_id = g_person_id
566                       AND bec.business_group_id = p_business_group_id
567                       AND fnd_date.canonical_to_date(prmtr_09)
568                           BETWEEN g_extract_params(p_business_group_id).extract_start_date
569                           AND g_extract_params(p_business_group_id).extract_end_date )
570    AND NOT EXISTS( SELECT 1
571                      FROM per_all_assignments_f  asg1
572                     WHERE assignment_id = p_assignment_id
573                       AND effective_start_date <
574                           g_extract_params(p_business_group_id).extract_start_date
575                       AND asg.assignment_id = asg1.assignment_id
576                       AND assignment_status_type_id IN (SELECT assignment_status_type_id
577                                                         FROM per_assignment_status_types
578                                                    WHERE per_system_status = 'TERM_ASSIGN'
579                                                            AND active_flag = 'Y'))
580   ORDER BY effective_start_date )
581  UNION
582 SELECT NULL
583       ,to_char(effective_end_date,'DD/MM/YYYY')
584       ,9999999999
585       ,period_of_service_id
586   FROM per_all_assignments_f asg
587  WHERE assignment_id = p_assignment_id
588    AND asg.primary_flag = 'N'
589    AND effective_end_date BETWEEN
590            g_extract_params(p_business_group_id).extract_start_date
591        AND g_extract_params(p_business_group_id).extract_end_date
592    AND NOT EXISTS( SELECT 1
593                      FROM per_all_assignments_f  asg1
594                     WHERE assignment_id = p_assignment_id
595                       AND effective_start_date = asg.effective_end_date + 1
596                       AND asg.assignment_id = asg1.assignment_id )
597    AND NOT EXISTS( SELECT 1
598                      FROM per_all_assignments_f  asg1
599                     WHERE assignment_id = p_assignment_id
600                       AND effective_start_date <
601                           g_extract_params(p_business_group_id).extract_start_date
602                       AND asg.assignment_id = asg1.assignment_id
603                       AND assignment_status_type_id IN (SELECT assignment_status_type_id
604                                                         FROM per_assignment_status_types
605                                                    WHERE per_system_status = 'TERM_ASSIGN'
606                                                            AND active_flag = 'Y'))
607   AND NOT EXISTS (  SELECT 1
608                      FROM ben_ext_chg_evt_log bec
609                     WHERE chg_evt_cd  = 'AAT'
610                       AND person_id = g_person_id
611                       AND bec.business_group_id = p_business_group_id
612                       AND fnd_date.canonical_to_date(prmtr_09)
613                           BETWEEN g_extract_params(p_business_group_id).extract_start_date
614                           AND g_extract_params(p_business_group_id).extract_end_date )
615 --
616 -- Reporting Retro Termination of sec asg
617 --
618 UNION
619 SELECT NULL
620      ,to_char(min(effective_start_date) - 1,'DD/MM/YYYY')
621      ,9999999999
622      ,period_of_service_id
623  FROM per_all_assignments_f asg
624 WHERE assignment_id = p_assignment_id
625   AND asg.primary_flag = 'N'
626   AND effective_start_date < g_extract_params(p_business_group_id).extract_start_date
627   AND assignment_status_type_id IN (SELECT assignment_status_type_id
628                                       FROM per_assignment_status_types
629                                      WHERE per_system_status = 'TERM_ASSIGN'
630                                        AND active_flag = 'Y')
631   AND NOT EXISTS( SELECT 1
632                     FROM ben_ext_rslt_dtl     dtl
633                         ,ben_ext_rslt         res
634                         ,ben_ext_rcd          rcd
635                         ,ben_ext_rcd_in_file  rin
636                         ,ben_ext_dfn          dfn
637                   WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
638                                              FROM pqp_extract_attributes
639                                             WHERE ext_dfn_type = 'NL_FPR')
640                    and dtl.person_id    = g_person_id
641                    and ext_stat_cd      = 'A'
642                    AND TRUNC(res.eff_dt)< g_extract_params(p_business_group_id).extract_start_date
643                    AND rin.ext_file_id  = dfn.ext_file_id
644                    AND rin.ext_rcd_id   = rcd.ext_rcd_id
645                    AND dfn.ext_dfn_id   = res.ext_dfn_id
646                    and dtl.ext_rslt_id  = res.ext_rslt_id
647                    AND dtl.ext_rcd_id   = rcd.ext_rcd_id
648                    AND rin.seq_num      = 5
649                    AND val_04           = c_asg_seq_num
650                    AND val_07           <> '00000000')
651 group by period_of_service_id
652 
653 ORDER by 3 desc;
654 
655 --
656 -- Cursor to get the current ptp.
657 -- this is also used to identify if an EE is a regular EE or
658 -- a declerant (hourly EE)
659 --
660 CURSOR c_cur_ptp (c_eff_dt IN DATE
661                  ,c_asg_id IN NUMBER) IS
662 SELECT LEAST(fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')),125) ptp
663   FROM per_assignments_f asg
664       ,hr_soft_coding_keyflex target
665 WHERE  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
666   AND  asg.assignment_id = c_asg_id
667   AND  target.enabled_flag = 'Y'
668   AND  trunc(c_eff_dt) BETWEEN asg.effective_start_date AND
669        asg.effective_end_date;
670 
671 TYPE t_basis_rec  IS TABLE OF c_rec_09_ele%ROWTYPE INDEX BY Binary_Integer;
672 TYPE t_basis_rec1 IS TABLE OF c_rec_31_ele%ROWTYPE INDEX BY Binary_Integer;
673 
674 l_rec_09       t_basis_rec;
675 l_rec_31       t_basis_rec1;
676 l_basis_rec_41 t_basis_rec1;
677 
678 l_09_counter         Number := 0;
679 l_31_counter         Number := 0;
680 l_41_basis_counter   Number := 0;
681 
682 TYPE r_basis_rec_values IS RECORD
683    (  basis_amount Number(9,2)
684      ,sign_code    Varchar2(1)
685      ,code         Varchar2(2)
686      ,processed    Varchar2(1)
687      ,pobj_flag    Varchar2(1)
688      ,date_earned  Varchar2(11) );
689 TYPE t_basis_rec_values IS TABLE OF r_basis_rec_values INDEX BY Binary_Integer;
690 l_rec_09_values       t_basis_rec_values;
691 l_rec_31_values       t_basis_rec_values;
692 l_rec_41_basis_values t_basis_rec_values;
693 
694 TYPE r_retro_ptpn IS RECORD
695    (  start_date  DATE
696      ,end_date    DATE
697      ,ptid        NUMBER );
698 TYPE t_retro_ptpn IS TABLE OF r_retro_ptpn INDEX BY Binary_Integer;
699 
700 TYPE r_retro_ptpn_kind IS RECORD
701    (  start_date  DATE
702      ,end_date    DATE
703      ,ptpn_kind   varchar2(3)
704      ,ptpn_val    NUMBER);
705 TYPE t_retro_ptpn_kind IS TABLE OF r_retro_ptpn_kind INDEX BY Binary_Integer;
706 
707 l_rec_09_disp        Varchar2(1) := 'N';
708 l_rec_05_disp        Varchar2(1) := 'N';
709 l_rec_31_disp        Varchar2(1) := 'N';
710 l_basis_rec_41_disp  Varchar2(1) := 'N';
711 
712 -- ============================================================================
713 -- Cursor to get the input value id for the pension basis input value
714 -- ============================================================================
715 CURSOR c_get_iv_id(c_element_type_id in number) IS
716 SELECT input_value_id
717   FROM pay_input_values_f
718 WHERE  element_type_id = c_element_type_id
719   AND  name = 'ABP Employee Pension Basis';
720 
721 l_basis_iv_id NUMBER;
722 
723 -- ============================================================================
724 -- Cursor to get the valid element_type_id for record 12 (at BG Level)
725 -- ============================================================================
726 CURSOR c_rec_12_ele( c_bg_id          IN Number
727                     ,c_effective_date IN Date
728                     ,c_asg_id         IN Number) IS
729 SELECT pei.eei_information12 sub_cat
730       ,pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id) date_earned
731       ,Decode (pei.eei_information12,'OPNP_65',5,'OPNP_W25',6,'OPNP_W50',7,
732                'VSG',9,'FPU_E',4,'FPU_R',2,'FPU_S',1,'FPU_T',3,'FPU_B',1
733               ,'PPP',11) code
734       ,sum(fnd_number.canonical_to_number(peev.screen_entry_value)) amount
735       ,pty.ee_contribution_bal_type_id
736       ,pty.er_contribution_bal_type_id
737  FROM pay_element_type_extra_info pei,
738       pay_element_types_f pet,
739       pay_element_entries_f peef,
740       pay_element_links_f pelf,
741       pay_element_entry_values_f peev,
742       pay_input_values_f         pivf,
743       pqp_pension_types_f        pty
744 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
745   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
746   AND c_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
747                                To_Date(pei.eei_information11,'DD/MM/RRRR')
748   AND c_effective_date BETWEEN pet.effective_start_date AND
749                                pet.effective_end_date
750   AND c_effective_date BETWEEN peef.effective_start_date AND
751                                peef.effective_end_date
752   AND c_effective_date BETWEEN pelf.effective_start_date AND
753                                pelf.effective_end_date
754   AND c_effective_date BETWEEN peev.effective_start_date AND
755                                peev.effective_end_date
756   AND c_effective_date BETWEEN pty.effective_start_date AND
757                                pty.effective_end_date
758   AND c_effective_date BETWEEN pivf.effective_start_date AND
759                                pivf.effective_end_date
760   AND (to_number(pei.eei_information18) = pet.element_type_id
761       OR to_number(pei.eei_information19) = pet.element_type_id
762       OR to_number(pei.eei_information20) = pet.element_type_id
763       OR to_number(pei.eei_information21) = pet.element_type_id
764       OR  pet.element_type_id IN (SELECT retro_element_type_id
765 	       FROM pay_element_span_usages    pesu,
766 		        pay_retro_component_usages prcu
767           WHERE prcu.retro_component_usage_id = pesu.retro_component_usage_id
768             AND retro_component_id = ( SELECT retro_component_id
769 			                             FROM pay_retro_components
770                                         WHERE legislation_code = 'NL'
771                                           AND short_name     = 'Adjustment'
772                                           AND component_name = 'Adjustment')
773 	        AND creator_type = 'ET'
774             AND (creator_id = pei.element_type_id OR
775                  creator_id IN (SELECT element_type_id
776                                 FROM pay_element_types_f pet1
777                                 WHERE pet1.element_name = pei.eei_information9 || ' ABP Employer Pension Contribution'
778                                 AND pet1.business_group_id = pet.business_group_id)))  )
779   AND pelf.element_type_id = pet.element_type_id
780   AND pivf.element_type_id = pet.element_type_id
781   AND pivf.name = 'Pay Value'
782   AND peef.element_link_id = pelf.element_link_id
783   AND peev.input_value_id = pivf.input_value_id
784   AND peev.element_entry_id = peef.element_entry_id
785   AND pet.business_group_id = c_bg_id
786   AND peef.assignment_id = c_asg_id
787   AND pei.EEI_INFORMATION12 IN ('OPNP_65','OPNP_W25','OPNP_W50','PPP','FPU_B',
788                                 'VSG','FPU_E','FPU_R','FPU_S','FPU_T')
789   AND pty.pension_type_id = to_number(pei.eei_information2)
790 GROUP BY pei.eei_information12,pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id)
791         ,pty.ee_contribution_bal_type_id,pty.er_contribution_bal_type_id
792 UNION
793 SELECT pension_sub_category sub_cat
794       ,c_effective_date date_earned
795       ,Decode (pension_sub_category,'OPNP_65',5,'OPNP_W25',6,'OPNP_W50',7,'PPP',11,
796                'VSG',9,'FPU_E',4,'FPU_R',2,'FPU_S',1,'FPU_T',3,'FPU_B',1) code
797       ,-999999 amount
798       ,ee_contribution_bal_type_id
799       ,er_contribution_bal_type_id
800   FROM pqp_pension_types_f pty
801 WHERE pension_sub_category IN ('OPNP_65','OPNP_W25','OPNP_W50','PPP',
802                                 'VSG','FPU_E','FPU_R','FPU_S','FPU_T','FPU_B')
803   AND business_group_id = c_bg_id
804   AND c_effective_date BETWEEN pty.effective_start_date AND
805                                pty.effective_end_date
806 GROUP BY pension_sub_category,c_effective_date
807         ,ee_contribution_bal_type_id
808         ,er_contribution_bal_type_id;
809 
810 -- ============================================================================
811 -- Cursor to get the valid element_type_id for record 41 (at BG Level)
812 -- ============================================================================
813 CURSOR c_contrib_rec_41_ele( c_bg_id          IN Number
814                     ,c_effective_date IN Date
815                     ,c_asg_id         IN Number) IS
816 SELECT pei.eei_information12 sub_cat
817       ,pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id) date_earned
818       ,9 code
819       ,sum(fnd_number.canonical_to_number(peev.screen_entry_value)) amount
820       ,pty.ee_contribution_bal_type_id
821       ,pty.er_contribution_bal_type_id
822  FROM pay_element_type_extra_info pei,
823       pay_element_types_f pet,
824       pay_element_entries_f peef,
825       pay_element_links_f pelf,
826       pay_element_entry_values_f peev,
827       pay_input_values_f         pivf,
828       pqp_pension_types_f        pty
829 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
830   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
831   AND c_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
832                                To_Date(pei.eei_information11,'DD/MM/RRRR')
833   AND c_effective_date BETWEEN pet.effective_start_date AND
834                                pet.effective_end_date
835   AND c_effective_date BETWEEN peef.effective_start_date AND
836                                peef.effective_end_date
837   AND c_effective_date BETWEEN pelf.effective_start_date AND
838                                pelf.effective_end_date
839   AND c_effective_date BETWEEN peev.effective_start_date AND
840                                peev.effective_end_date
841   AND c_effective_date BETWEEN pivf.effective_start_date AND
842                                pivf.effective_end_date
843   AND c_effective_date BETWEEN pty.effective_start_date AND
844                                pty.effective_end_date
845   AND (to_number(pei.eei_information18) = pet.element_type_id
846       OR to_number(pei.eei_information19) = pet.element_type_id
847       OR to_number(pei.eei_information20) = pet.element_type_id
848       OR to_number(pei.eei_information21) = pet.element_type_id)
849   AND pelf.element_type_id = pet.element_type_id
850   AND pivf.element_type_id = pet.element_type_id
851   AND pivf.name = 'Pay Value'
852   AND peef.element_link_id = pelf.element_link_id
853   AND peev.input_value_id = pivf.input_value_id
854   AND peev.element_entry_id = peef.element_entry_id
855   AND pet.business_group_id = c_bg_id
856   AND peef.assignment_id = c_asg_id
857   AND pei.EEI_INFORMATION12 IN ('FUR_S')
858   AND pty.pension_type_id = to_number(pei.eei_information2)
859 GROUP BY pei.eei_information12,pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id)
860         ,pty.ee_contribution_bal_type_id,pty.er_contribution_bal_type_id
861 UNION
862 SELECT pension_sub_category sub_cat
863       ,c_effective_date date_earned
864       ,9 code
865       ,-999999 amount
866       ,ee_contribution_bal_type_id
867       ,er_contribution_bal_type_id
868   FROM pqp_pension_types_f pty
869 WHERE pension_sub_category IN ('FUR_S')
870   AND business_group_id = c_bg_id
871   AND c_effective_date BETWEEN pty.effective_start_date AND
872                                pty.effective_end_date
873 GROUP BY pension_sub_category,c_effective_date
874         ,ee_contribution_bal_type_id,er_contribution_bal_type_id;
875 
876 TYPE t_rec_12 IS TABLE OF c_rec_12_ele%ROWTYPE INDEX BY Binary_Integer;
877 l_rec_12          t_rec_12;
878 l_contrib_rec_41  t_rec_12;
879 l_12_counter           Number := 0;
880 l_41_contrib_counter   Number := 0;
881 i_12           Number := 0;
882 i_41           Number := 0;
883 
884 TYPE r_rec_12_values IS RECORD
885    (contrib_amount Number(9,2)
886    ,date_earned    varchar2(11)
887    ,code           varchar2(2));
888 
889 TYPE t_rec_12_values IS TABLE OF r_rec_12_values INDEX BY Binary_Integer;
890 l_rec_12_values            t_rec_12_values;
891 l_rec_41_contrib_values    t_rec_12_values;
892 
893 l_rec_12_disp              Varchar2(1) := 'N';
894 l_contrib_rec_41_disp      Varchar2(1) := 'N';
895 l_rec12_amt        Number := 0;
896 l_rec41_amt        Number := 0;
897 
898 -- ============================================================================
899 -- Cursor to get the element entry ids for the Retro Pension Deduction elements
900 -- ============================================================================
901 CURSOR c_get_retro_entry(c_element_type_id in number
902                         ,c_assignment_action_id in number) IS
903 SELECT element_entry_id
904   FROM pay_run_results prr
905 WHERE  prr.assignment_action_id = c_assignment_action_id
906   AND  prr.element_type_id = c_element_type_id
907   ORDER BY element_entry_id;
908 
909 -- ============================================================================
910 -- Cursor to get the element entry ids for a given retro element type
911 -- ============================================================================
912 CURSOR c_get_retro_ele_entry(c_start_date in date
913                             ,c_end_date   in date
914                             ,c_assignment_id in number
915                             ,c_element_type_id in number) IS
916 SELECT element_entry_id
917 FROM   pay_run_results prr,
918        pay_payroll_actions ppa,
919        pay_assignment_actions paa
920 WHERE  paa.assignment_action_id = prr.assignment_action_id
921   AND  paa.payroll_action_id = ppa.payroll_action_id
922   AND  ppa.date_earned BETWEEN c_start_date
923   AND  c_end_date
924   AND  paa.assignment_id = c_assignment_id
925   AND  prr.element_type_id = c_element_type_id
926   ORDER BY element_entry_id;
927 
928 l_retro_ptp_entry c_get_retro_ele_entry%ROWTYPE;
929 
930 -- ============================================================================
931 -- Cursor to get the input value id  and element type id for the
932 -- given retro element and input value names
933 -- ============================================================================
934 CURSOR c_get_retro_ele(c_element_name in varchar2
935                       ,c_input_value_name in varchar2) IS
936 SELECT piv.input_value_id
937       ,pet.element_type_id
938 FROM   pay_input_values_f piv
939       ,pay_element_types_f pet
940 WHERE  piv.name = c_input_value_name
941  AND   piv.element_type_id = pet.element_type_id
942  AND   pet.element_name = c_element_name;
943 
944 -- ============================================================================
945 -- Cursor to get the entry value for the given element entry id and input value
946 -- (for all numeric input values)
947 -- ============================================================================
948 CURSOR c_get_retro_num_value(c_element_entry_id in number
949                             ,c_input_value_id   in number) IS
950 SELECT fnd_number.canonical_to_number(nvl(screen_entry_value,'0'))
951 FROM   pay_element_entry_values_f
952 WHERE  element_entry_id = c_element_entry_id
953  AND   input_value_id   = c_input_value_id;
954 
955 -- ============================================================================
956 -- Cursor to get the entry value for the given element entry id and input value
957 -- (for all text input values)
958 -- ============================================================================
959 CURSOR c_get_retro_txt_value(c_element_entry_id in number
960                             ,c_input_value_id   in number) IS
961 SELECT nvl(screen_entry_value,' ')
962 FROM   pay_element_entry_values_f
963 WHERE  element_entry_id = c_element_entry_id
964  AND   input_value_id   = c_input_value_id;
965 
966 -- ============================================================================
967 -- Cursor to check if a non-null entry exists for the retro part time percentage
968 -- ============================================================================
969 CURSOR c_retro_ptp_entry_exists(c_start_date in date
970                                ,c_end_date   in date
971                                ,c_assignment_id in number
972                                ,c_element_type_id in number
973                                ,c_input_value_id in number) IS
974 SELECT 1
975  FROM  pay_element_entry_values_f
976 WHERE  input_value_id = c_input_value_id
977   AND  screen_entry_value IS NOT NULL
978   AND  element_entry_id IN
979        (SELECT element_entry_id
980         FROM   pay_run_results prr,
981                pay_payroll_actions ppa,
982                pay_assignment_actions paa
983         WHERE  paa.assignment_action_id = prr.assignment_action_id
984           AND  paa.payroll_action_id = ppa.payroll_action_id
985           AND  ppa.date_earned BETWEEN c_start_date
986           AND  c_end_date
987           AND  paa.assignment_id = c_assignment_id
988           AND  prr.element_type_id = c_element_type_id
989        );
990 
991 l_retro_ptp_entry_exists c_retro_ptp_entry_exists%ROWTYPE;
992 
993 -- ============================================================================
994 -- Cursor to get the time period start and end dates for a retro element entry
995 -- ============================================================================
996 CURSOR c_get_retro_time_period(c_element_entry_id in number
997                               ,c_assignment_id    in number) IS
998 SELECT ptp.start_date,ptp.end_date
999 FROM   per_time_periods ptp
1000       ,per_all_assignments_f paa
1001 WHERE  paa.assignment_id = c_assignment_id
1002   AND  ptp.payroll_id = paa.payroll_id
1003   AND  pay_paywsmee_pkg.get_original_date_earned(c_element_entry_id)
1004   BETWEEN paa.effective_start_date
1005   AND  paa.effective_end_date
1006   AND  pay_paywsmee_pkg.get_original_date_earned(c_element_entry_id)
1007   BETWEEN ptp.start_date
1008   AND  ptp.end_date;
1009 
1010 -- ============================================================================
1011 -- Cursor to check for multiple changes to PTP in a period.
1012 -- Addition of the > 0 check is to report retro PTP for hourly EE's
1013 -- ============================================================================
1014 CURSOR c_get_count_ptp_changes(c_asg_id       in number
1015                               ,c_period_start in date
1016                               ,c_period_end   in date) IS
1017 SELECT COUNT(*)
1018   FROM per_assignments_f asg
1019       ,per_assignment_status_types past
1020       ,hr_soft_coding_keyflex target
1021 WHERE  asg.assignment_status_type_id = past.assignment_status_type_id
1022   AND  past.per_system_status = 'ACTIVE_ASSIGN'
1023   AND  asg.effective_start_date BETWEEN c_period_start
1024   AND  c_period_end
1025   AND  asg.assignment_id = c_asg_id
1026   AND  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
1027   AND  target.enabled_flag = 'Y'
1028   AND  fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')) > 0;
1029 
1030 -- ============================================================================
1031 -- Cursor to get the changes to the part time percentage in a retro period
1032 -- ============================================================================
1033 CURSOR c_get_ptp_changes(c_asg_id       in number
1034                         ,c_period_start in date
1035                         ,c_period_end   in date) IS
1036 SELECT asg.effective_start_date Start_Date
1037       ,asg.effective_end_date   End_Date
1038       ,fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')) ptp
1039   FROM per_assignments_f asg
1040       ,per_assignment_status_types past
1041       ,hr_soft_coding_keyflex target
1042 WHERE  asg.assignment_status_type_id = past.assignment_status_type_id
1043   AND  past.per_system_status = 'ACTIVE_ASSIGN'
1044   AND  asg.effective_start_date BETWEEN c_period_start
1045   AND  c_period_end
1046   AND  asg.assignment_id = c_asg_id
1047   AND  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
1048   AND  target.enabled_flag = 'Y';
1049 
1050 -- ============================================================================
1051 -- Cursor to get the retro ptp for ABP and SI
1052 -- ============================================================================
1053 CURSOR c_get_retro_ptp(c_asg_id         IN NUMBER
1054                       ,c_effective_date IN DATE
1055                       ,c_ele_type_id    IN NUMBER
1056                       ,c_input_val_id   IN NUMBER ) IS
1057 
1058 SELECT to_date('1/'||to_char(pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id),'MM/YYYY'),'DD/MM/YYYY') start_date
1059 ,add_months(to_date('1/'||to_char(pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id),'MM/YYYY'),'DD/MM/YYYY'),1) - 1 end_date
1060 ,fnd_number.canonical_to_number(peev.screen_entry_value) ptp
1061  FROM pay_element_entries_f       peef,
1062       pay_element_links_f         pelf,
1063       pay_element_entry_values_f  peev
1064 WHERE c_effective_date BETWEEN peef.effective_start_date AND
1065                                peef.effective_end_date
1066   AND c_effective_date BETWEEN pelf.effective_start_date AND
1067                                pelf.effective_end_date
1068   AND c_effective_date BETWEEN peev.effective_start_date AND
1069                                peev.effective_end_date
1070   AND peef.element_link_id  = pelf.element_link_id
1071   AND peev.element_entry_id = peef.element_entry_id
1072   AND pelf.element_type_id  = c_ele_type_id
1073   AND peev.input_value_id   = c_input_val_id
1074   AND peef.assignment_id    = c_asg_id
1075   AND peev.screen_entry_value IS NOT NULL
1076   order by start_date;
1077 
1078 -- ============================================================================
1079 -- Cursor to get the retro ptp for ABP and SI
1080 -- ============================================================================
1081 CURSOR c_ptp_chg_exist(c_asg_id         IN NUMBER
1082                       ,c_effective_date IN DATE
1083                       ,c_ele_type_id    IN NUMBER
1084                       ,c_input_val_id   IN NUMBER ) IS
1085 
1086 SELECT 1
1087  FROM pay_element_entries_f       peef,
1088       pay_element_links_f         pelf,
1089       pay_element_entry_values_f  peev
1090 WHERE c_effective_date BETWEEN peef.effective_start_date AND
1091                                peef.effective_end_date
1092   AND c_effective_date BETWEEN pelf.effective_start_date AND
1093                                pelf.effective_end_date
1094   AND c_effective_date BETWEEN peev.effective_start_date AND
1095                                peev.effective_end_date
1096   AND peef.element_link_id  = pelf.element_link_id
1097   AND peev.element_entry_id = peef.element_entry_id
1098   AND pelf.element_type_id  = c_ele_type_id
1099   AND peev.input_value_id   = c_input_val_id
1100   AND peef.assignment_id    = c_asg_id
1101   AND peev.screen_entry_value IS NOT NULL;
1102 
1103 l_ptp_chg_exist NUMBER;
1104 
1105 --6501898
1106 -- ============================================================================
1107 -- Cursor to get the non retro ptp for ABP for Hourly Employees
1108 -- ============================================================================
1109 CURSOR c_ptp_chg_hrly_exist(c_asg_id         IN NUMBER
1110                       ,c_effective_date IN DATE
1111                       ,c_ele_type_id    IN NUMBER
1112                       ,c_input_val_id   IN NUMBER ) IS
1113 
1114 SELECT to_date('1/'||to_char(ppa.date_earned,'MM/YYYY'),'DD/MM/YYYY') start_date
1115 ,add_months(to_date('1/'||to_char(ppa.date_earned,'MM/YYYY'),'DD/MM/YYYY'),1) - 1 end_date
1116 ,fnd_number.canonical_to_number(prrv.result_value) ptp, 'Y' Yes
1117  FROM pay_element_entries_f       peef,
1118       pay_element_links_f         pelf,
1119       pay_element_entry_values_f  peev,
1120       pay_run_results prr,
1121       pay_run_result_values prrv,
1122       pay_assignment_actions paa,
1123       pay_payroll_actions ppa
1124 WHERE ppa.date_earned BETWEEN peef.effective_start_date AND
1125                                peef.effective_end_date
1126   AND ppa.date_earned BETWEEN pelf.effective_start_date AND
1127                                pelf.effective_end_date
1128   AND ppa.date_earned BETWEEN peev.effective_start_date AND
1129                                peev.effective_end_date
1130   AND c_effective_date BETWEEN to_date('1/'||to_char(ppa.effective_date,'MM/YYYY'),'DD/MM/YYYY') AND
1131                                add_months(to_date('1/'||to_char(ppa.effective_date,'MM/YYYY'),'DD/MM/YYYY'),1) - 1
1132   AND peef.element_link_id  = pelf.element_link_id
1133   AND peev.element_entry_id = peef.element_entry_id
1134   AND prr.element_entry_id = peef.element_entry_id
1135   AND prr.element_type_id = pelf.element_type_id
1136   AND prrv.run_result_id = prr.run_result_id
1137   AND prrv.input_value_id = peev.input_value_id
1138   AND paa.payroll_action_id = ppa.payroll_action_id
1139   AND paa.assignment_action_id = prr.assignment_action_id
1140   AND pelf.element_type_id  = c_ele_type_id
1141   AND peev.input_value_id   = c_input_val_id
1142   AND peef.assignment_id    = c_asg_id
1143   AND fnd_number.canonical_to_number(prrv.result_value) > 0 ;
1144 
1145 l_ptp_chg_hrly_exist c_ptp_chg_hrly_exist%rowtype;
1146 --6501898
1147 
1148 -- ============================================================================
1149 -- Cursor to get the original date earned for a retro element entry
1150 -- ============================================================================
1151 CURSOR c_get_retro_date_earned(c_element_entry_id in number) IS
1152 SELECT substr(fnd_date.date_to_canonical(
1153        trunc(pay_paywsmee_pkg.get_original_date_earned(c_element_entry_id))
1154        ),1,10)
1155   FROM dual;
1156 
1157 TYPE r_rec_retro_ptp IS RECORD
1158   (start_date Date
1159   ,end_date   Date
1160   ,part_time_perc Number(9,2)
1161   ,vop            Number(5,2));
1162 
1163 TYPE t_rec_retro_ptp IS TABLE of r_rec_retro_ptp INDEX BY Binary_Integer;
1164 l_rec_05_retro_ptp   t_rec_retro_ptp;
1165 l_rec_20_retro_ptp   t_rec_retro_ptp;
1166 
1167 TYPE r_rec_retro_siw IS RECORD
1168   (date_earned varchar2(11)
1169   ,si_wages    Number(9,2)
1170   ,si_days     Number(5,2)
1171   ,si_type     varchar2(4));
1172 
1173 TYPE t_rec_retro_siw IS TABLE of r_rec_retro_siw INDEX BY Binary_Integer;
1174 l_rec_21_retro_siw   t_rec_retro_siw;
1175 l_rec_22_retro_siw   t_rec_retro_siw;
1176 
1177 l_si_days_sign         Varchar2(1) :=  ' ';
1178 l_si_wages_sign        Varchar2(1) :=  ' ';
1179 l_curr_si_type         Varchar2(5) :=  'NONE';
1180 l_curr_si_rec          Varchar2(5) :=  '21';
1181 l_wao_done             Varchar2(1) := 'N';
1182 l_si_type_dbal_id      Number;
1183 l_si_days_dbal_id      Number;
1184 l_si_reg_dbal_id       Number;
1185 l_pen_py_con_dbal_id   NUMBER;
1186 l_abp_ptp_ele_id       Number;
1187 l_abp_ptp_iv_id        Number;
1188 l_si_ptp_ele_id        Number;
1189 l_si_ptp_iv_id         Number;
1190 g_abp_processed_flag   NUMBER;
1191 g_new_hire_asg         NUMBER;
1192 g_hire_date            DATE;
1193 
1194 -- =============================================================================
1195 -- IsNumber: return TRUE if number else FALSE
1196 -- =============================================================================
1197 FUNCTION IsNumber (p_data_value IN Varchar2)
1198 RETURN Boolean  IS
1199  l_data_value Number;
1200 BEGIN
1201   l_data_value := Fnd_Number.Canonical_To_Number(Nvl(p_data_value,'0'));
1202   RETURN TRUE;
1203 EXCEPTION
1204   WHEN Value_Error THEN
1205    RETURN FALSE;
1206 END IsNumber;
1207 
1208 -- =============================================================================
1209 -- to_nl_date: Function to convert the date to the appropriate value
1210 -- since the ben logs contain dates in the NL Language -- 31-MEI-05
1211 -- 1-OKT-05 etc
1212 -- =============================================================================
1213 FUNCTION To_NL_Date (p_date_value  IN VARCHAR2,
1214                      p_date_format IN VARCHAR2)
1215 RETURN DATE IS
1216 
1217 BEGIN
1218 
1219    IF LENGTH(p_date_value) = 9 THEN
1220       RETURN TO_DATE(p_date_value,p_date_format,'NLS_DATE_LANGUAGE = ''DUTCH''');
1221    ELSE
1222       RETURN TO_DATE(p_date_value,p_date_format);
1223    END IF;
1224 
1225 EXCEPTION
1226    WHEN OTHERS THEN
1227    RETURN To_date(p_date_value,p_date_format,'NLS_DATE_LANGUAGE = ''AMERICAN''');
1228 
1229 END to_nl_date;
1230 
1231 -- =============================================================================
1232 -- ~ Pension_Extract_Process: This is called by the conc. program as is a
1233 -- ~ wrapper around the benefits conc. program Extract Process.
1234 -- =============================================================================
1235 PROCEDURE Pension_Extract_Process
1236            (errbuf                        OUT NOCOPY  Varchar2
1237            ,retcode                       OUT NOCOPY  Varchar2
1238            ,p_benefit_action_id           IN     Number
1239            ,p_ext_dfn_id                  IN     Number
1240            ,p_org_id                      IN     Number
1241            ,p_payroll_id                  IN     Number
1242            ,p_start_date                  IN     Varchar2
1243            ,p_end_date                    IN     Varchar2
1244            ,p_extract_rec_01              IN     VARCHAR2
1245            ,p_business_group_id           IN     Number
1246            ,p_consolidation_set           IN     Number
1247            ,p_ext_rslt_id                 IN     Number DEFAULT NULL
1248 ) IS
1249    l_errbuff          Varchar2(3000);
1250    l_retcode          Number;
1251    l_session_id       Number;
1252    l_proc_name        Varchar2(150) := g_proc_name ||'Pension_Extract_Process';
1253 
1254 BEGIN
1255      IF g_debug THEN
1256        Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1257      END If;
1258 
1259      g_conc_request_id := Fnd_Global.conc_request_id;
1260 
1261     IF p_end_date < p_start_date THEN
1262        Fnd_Message.set_name('PQP','PQP_230869_END_BEFORE_START');
1263        Fnd_Message.raise_error;
1264     END IF;
1265 
1266     SELECT Userenv('SESSIONID') INTO l_session_id FROM dual;
1267 
1268      -- Delete values from the temporary table
1269      DELETE FROM pay_us_rpt_totals
1270      WHERE organization_name = 'NL ABP Pension Extracts';
1271 
1272      --
1273      -- Insert into pay_us_rpt_totals so that we can refer to these parameters
1274      -- when we call the criteria formula for the pension extract.
1275      --
1276      IF g_debug THEN
1277         hr_utility.set_location('inserting into rpt totals : '||p_business_group_id,20);
1278      END IF;
1279 
1280      INSERT INTO pay_us_rpt_totals
1281      (session_id         -- Session id
1282      ,organization_name  -- Concurrent Program Name
1283      ,business_group_id  -- Business Group
1284      ,tax_unit_id        -- Concurrent Request Id
1285      ,value1             -- Extract Definition Id
1286      ,value2             -- Payroll Id
1287      ,value3             -- Consolidation Set
1288      ,value4             -- Organization Id
1289      ,value5             --
1290      ,value6             --
1291      ,attribute1         --
1292      ,attribute2         --
1293      ,attribute3         -- Extract Start Date
1294      ,attribute4         -- Extract End Date
1295      ,attribute5         -- Extract Record 01 Flag
1296      )
1297      VALUES
1298      (l_session_id
1299      ,'NL ABP Pension Extracts'
1300      ,p_business_group_id
1301      ,g_conc_request_id
1302      ,p_ext_dfn_id
1303      ,p_payroll_id
1304      ,p_consolidation_set
1305      ,p_org_id
1306      ,NULL
1307      ,NULL
1308      ,NULL
1309      ,NULL
1310      ,p_start_date
1311      ,p_end_date
1312      ,p_extract_rec_01
1313      );
1314 
1315      COMMIT;
1316 
1317      --
1318      -- Call the actual benefit extract process with the effective date as the
1319      -- extract end date along with the ext def. id and business group id.
1320      --
1321      IF g_debug THEN
1322         Hr_Utility.set_location('..Calling Benefit Ext Process'||l_proc_name, 6);
1323      END IF;
1324 
1325      Ben_Ext_Thread.process
1326        (errbuf                     => l_errbuff,
1327         retcode                    => l_retcode,
1328         p_benefit_action_id        => NULL,
1329         p_ext_dfn_id               => p_ext_dfn_id,
1330         p_effective_date           => p_end_date,
1331         p_business_group_id        => p_business_group_id);
1332 
1333      IF g_debug THEN
1334         Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
1335      END IF;
1336 
1337 EXCEPTION
1338      WHEN Others THEN
1339      Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1340      RAISE;
1341 END Pension_Extract_Process;
1342 
1343 -- ============================================================================
1344 -- ~ Update_Record_Values :
1345 -- ============================================================================
1346 PROCEDURE Update_Record_Values
1347            (p_ext_rcd_id            IN ben_ext_rcd.ext_rcd_id%TYPE
1348            ,p_ext_data_element_name IN ben_ext_data_elmt.NAME%TYPE
1349            ,p_data_element_value    IN ben_ext_rslt_dtl.val_01%TYPE
1350            ,p_data_ele_seqnum       IN Number
1351            ,p_ext_dtl_rec           IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE
1352             ) IS
1353    CURSOR csr_seqnum (c_ext_rcd_id            IN ben_ext_rcd.ext_rcd_id%TYPE
1354                      ,c_ext_data_element_name IN ben_ext_data_elmt.NAME%TYPE
1355                       ) IS
1356       SELECT der.ext_data_elmt_id,
1357              der.seq_num,
1358              ede.NAME
1359         FROM ben_ext_data_elmt_in_rcd der
1360              ,ben_ext_data_elmt        ede
1361        WHERE der.ext_rcd_id = c_ext_rcd_id
1362          AND ede.ext_data_elmt_id = der.ext_data_elmt_id
1363          AND ede.NAME             LIKE '%'|| c_ext_data_element_name
1364        ORDER BY seq_num;
1365 
1366    l_seqnum_rec        csr_seqnum%ROWTYPE;
1367    l_proc_name         Varchar2(150):= g_proc_name||'Update_Record_Values';
1368    l_ext_dtl_rec_nc    ben_ext_rslt_dtl%ROWTYPE;
1369 BEGIN
1370 
1371  IF g_debug THEN
1372     Hr_Utility.set_location('Entering :'||l_proc_name, 5);
1373  END IF;
1374  -- nocopy changes
1375  l_ext_dtl_rec_nc := p_ext_dtl_rec;
1376 
1377  IF p_data_ele_seqnum IS NULL THEN
1378     OPEN csr_seqnum ( c_ext_rcd_id            => p_ext_rcd_id
1379                      ,c_ext_data_element_name => p_ext_data_element_name);
1380     FETCH csr_seqnum INTO l_seqnum_rec;
1381     IF csr_seqnum%NOTFOUND THEN
1382        CLOSE csr_seqnum;
1383     ELSE
1384        CLOSE csr_seqnum;
1385     END IF;
1386  ELSE
1387     l_seqnum_rec.seq_num := p_data_ele_seqnum;
1388  END IF;
1389 
1390  IF l_seqnum_rec.seq_num = 1 THEN
1391     p_ext_dtl_rec.val_01 := p_data_element_value;
1392  ELSIF l_seqnum_rec.seq_num = 2 THEN
1393     p_ext_dtl_rec.val_02 := p_data_element_value;
1394  ELSIF l_seqnum_rec.seq_num = 3 THEN
1395     p_ext_dtl_rec.val_03 := p_data_element_value;
1396  ELSIF l_seqnum_rec.seq_num = 4 THEN
1397     p_ext_dtl_rec.val_04 := p_data_element_value;
1398  ELSIF l_seqnum_rec.seq_num = 5 THEN
1399     p_ext_dtl_rec.val_05 := p_data_element_value;
1400  ELSIF l_seqnum_rec.seq_num = 6 THEN
1401     p_ext_dtl_rec.val_06 := p_data_element_value;
1402  ELSIF l_seqnum_rec.seq_num = 7 THEN
1403     p_ext_dtl_rec.val_07 := p_data_element_value;
1404  ELSIF l_seqnum_rec.seq_num = 8 THEN
1405     p_ext_dtl_rec.val_08 := p_data_element_value;
1406  ELSIF l_seqnum_rec.seq_num = 9 THEN
1407     p_ext_dtl_rec.val_09 := p_data_element_value;
1408  ELSIF l_seqnum_rec.seq_num = 10 THEN
1409     p_ext_dtl_rec.val_10 := p_data_element_value;
1410  ELSIF l_seqnum_rec.seq_num = 11 THEN
1411     p_ext_dtl_rec.val_11 := p_data_element_value;
1412  ELSIF l_seqnum_rec.seq_num = 12 THEN
1413     p_ext_dtl_rec.val_12 := p_data_element_value;
1414  ELSIF l_seqnum_rec.seq_num = 13 THEN
1415     p_ext_dtl_rec.val_13 := p_data_element_value;
1416  ELSIF l_seqnum_rec.seq_num = 14 THEN
1417     p_ext_dtl_rec.val_14 := p_data_element_value;
1418  ELSIF l_seqnum_rec.seq_num = 15 THEN
1419     p_ext_dtl_rec.val_15 := p_data_element_value;
1420  ELSIF l_seqnum_rec.seq_num = 16 THEN
1421     p_ext_dtl_rec.val_16 := p_data_element_value;
1422  ELSIF l_seqnum_rec.seq_num = 17 THEN
1423     p_ext_dtl_rec.val_17 := p_data_element_value;
1424  ELSIF l_seqnum_rec.seq_num = 18 THEN
1425     p_ext_dtl_rec.val_18 := p_data_element_value;
1426  ELSIF l_seqnum_rec.seq_num = 19 THEN
1427     p_ext_dtl_rec.val_19 := p_data_element_value;
1428  ELSIF l_seqnum_rec.seq_num = 20 THEN
1429     p_ext_dtl_rec.val_20 := p_data_element_value;
1430  ELSIF l_seqnum_rec.seq_num = 21 THEN
1431     p_ext_dtl_rec.val_21 := p_data_element_value;
1432  ELSIF l_seqnum_rec.seq_num = 22 THEN
1433     p_ext_dtl_rec.val_22 := p_data_element_value;
1434  ELSIF l_seqnum_rec.seq_num = 23THEN
1435     p_ext_dtl_rec.val_23 := p_data_element_value;
1436  ELSIF l_seqnum_rec.seq_num = 24 THEN
1437     p_ext_dtl_rec.val_24 := p_data_element_value;
1438  ELSIF l_seqnum_rec.seq_num = 25 THEN
1439     p_ext_dtl_rec.val_25 := p_data_element_value;
1440  ELSIF l_seqnum_rec.seq_num = 26 THEN
1441     p_ext_dtl_rec.val_26 := p_data_element_value;
1442  ELSIF l_seqnum_rec.seq_num = 27 THEN
1443     p_ext_dtl_rec.val_27 := p_data_element_value;
1444  ELSIF l_seqnum_rec.seq_num = 28 THEN
1445     p_ext_dtl_rec.val_28 := p_data_element_value;
1446  ELSIF l_seqnum_rec.seq_num = 29 THEN
1447     p_ext_dtl_rec.val_29 := p_data_element_value;
1448  ELSIF l_seqnum_rec.seq_num = 30 THEN
1449     p_ext_dtl_rec.val_30 := p_data_element_value;
1450  ELSIF l_seqnum_rec.seq_num = 31 THEN
1451     p_ext_dtl_rec.val_31 := p_data_element_value;
1452  ELSIF l_seqnum_rec.seq_num = 32 THEN
1453     p_ext_dtl_rec.val_32 := p_data_element_value;
1454  ELSIF l_seqnum_rec.seq_num = 33 THEN
1455     p_ext_dtl_rec.val_33 := p_data_element_value;
1456  ELSIF l_seqnum_rec.seq_num = 34 THEN
1457     p_ext_dtl_rec.val_34 := p_data_element_value;
1458  ELSIF l_seqnum_rec.seq_num = 35 THEN
1459     p_ext_dtl_rec.val_35 := p_data_element_value;
1460  ELSIF l_seqnum_rec.seq_num = 36 THEN
1461     p_ext_dtl_rec.val_36 := p_data_element_value;
1462  ELSIF l_seqnum_rec.seq_num = 37 THEN
1463     p_ext_dtl_rec.val_37 := p_data_element_value;
1464  ELSIF l_seqnum_rec.seq_num = 38 THEN
1465     p_ext_dtl_rec.val_38 := p_data_element_value;
1466  ELSIF l_seqnum_rec.seq_num = 39 THEN
1467     p_ext_dtl_rec.val_39 := p_data_element_value;
1468  ELSIF l_seqnum_rec.seq_num = 40 THEN
1469     p_ext_dtl_rec.val_40 := p_data_element_value;
1470  ELSIF l_seqnum_rec.seq_num = 41 THEN
1471     p_ext_dtl_rec.val_41 := p_data_element_value;
1472  ELSIF l_seqnum_rec.seq_num = 42 THEN
1473     p_ext_dtl_rec.val_42 := p_data_element_value;
1474  ELSIF l_seqnum_rec.seq_num = 43 THEN
1475     p_ext_dtl_rec.val_43 := p_data_element_value;
1476  ELSIF l_seqnum_rec.seq_num = 44 THEN
1477     p_ext_dtl_rec.val_44 := p_data_element_value;
1478  ELSIF l_seqnum_rec.seq_num = 45 THEN
1479     p_ext_dtl_rec.val_45 := p_data_element_value;
1480  ELSIF l_seqnum_rec.seq_num = 46 THEN
1481     p_ext_dtl_rec.val_46 := p_data_element_value;
1482  ELSIF l_seqnum_rec.seq_num = 47 THEN
1483     p_ext_dtl_rec.val_47 := p_data_element_value;
1484  ELSIF l_seqnum_rec.seq_num = 48 THEN
1485     p_ext_dtl_rec.val_48 := p_data_element_value;
1486  ELSIF l_seqnum_rec.seq_num = 49 THEN
1487     p_ext_dtl_rec.val_49 := p_data_element_value;
1488  ELSIF l_seqnum_rec.seq_num = 50 THEN
1489     p_ext_dtl_rec.val_50 := p_data_element_value;
1490  ELSIF l_seqnum_rec.seq_num = 51 THEN
1491     p_ext_dtl_rec.val_51 := p_data_element_value;
1492  ELSIF l_seqnum_rec.seq_num = 52 THEN
1493     p_ext_dtl_rec.val_52 := p_data_element_value;
1494  ELSIF l_seqnum_rec.seq_num = 53 THEN
1495     p_ext_dtl_rec.val_53 := p_data_element_value;
1496  ELSIF l_seqnum_rec.seq_num = 54 THEN
1497     p_ext_dtl_rec.val_54 := p_data_element_value;
1498  ELSIF l_seqnum_rec.seq_num = 55 THEN
1499     p_ext_dtl_rec.val_55 := p_data_element_value;
1500  ELSIF l_seqnum_rec.seq_num = 56 THEN
1501     p_ext_dtl_rec.val_56 := p_data_element_value;
1502  ELSIF l_seqnum_rec.seq_num = 57 THEN
1503     p_ext_dtl_rec.val_57 := p_data_element_value;
1504  ELSIF l_seqnum_rec.seq_num = 58 THEN
1505     p_ext_dtl_rec.val_58 := p_data_element_value;
1506  ELSIF l_seqnum_rec.seq_num = 58 THEN
1507     p_ext_dtl_rec.val_58 := p_data_element_value;
1508  ELSIF l_seqnum_rec.seq_num = 59 THEN
1509     p_ext_dtl_rec.val_59 := p_data_element_value;
1510  ELSIF l_seqnum_rec.seq_num = 60 THEN
1511     p_ext_dtl_rec.val_60 := p_data_element_value;
1512  ELSIF l_seqnum_rec.seq_num = 61 THEN
1513     p_ext_dtl_rec.val_61 := p_data_element_value;
1514  ELSIF l_seqnum_rec.seq_num = 62 THEN
1515     p_ext_dtl_rec.val_62 := p_data_element_value;
1516  ELSIF l_seqnum_rec.seq_num = 63 THEN
1517     p_ext_dtl_rec.val_63 := p_data_element_value;
1518  ELSIF l_seqnum_rec.seq_num = 64 THEN
1519     p_ext_dtl_rec.val_64 := p_data_element_value;
1520  ELSIF l_seqnum_rec.seq_num = 65 THEN
1521     p_ext_dtl_rec.val_65 := p_data_element_value;
1522  ELSIF l_seqnum_rec.seq_num = 66 THEN
1523     p_ext_dtl_rec.val_66 := p_data_element_value;
1524  ELSIF l_seqnum_rec.seq_num = 67 THEN
1525     p_ext_dtl_rec.val_67 := p_data_element_value;
1526  ELSIF l_seqnum_rec.seq_num = 68 THEN
1527     p_ext_dtl_rec.val_68 := p_data_element_value;
1528  ELSIF l_seqnum_rec.seq_num = 69 THEN
1529     p_ext_dtl_rec.val_69 := p_data_element_value;
1530  ELSIF l_seqnum_rec.seq_num = 70 THEN
1531     p_ext_dtl_rec.val_70 := p_data_element_value;
1532  ELSIF l_seqnum_rec.seq_num = 71 THEN
1533     p_ext_dtl_rec.val_71 := p_data_element_value;
1534  ELSIF l_seqnum_rec.seq_num = 72 THEN
1535     p_ext_dtl_rec.val_72 := p_data_element_value;
1536  ELSIF l_seqnum_rec.seq_num = 73 THEN
1537     p_ext_dtl_rec.val_73 := p_data_element_value;
1538  ELSIF l_seqnum_rec.seq_num = 74 THEN
1539     p_ext_dtl_rec.val_74 := p_data_element_value;
1540  ELSIF l_seqnum_rec.seq_num = 75 THEN
1541     p_ext_dtl_rec.val_75 := p_data_element_value;
1542  END IF;
1543 
1544  IF g_debug THEN
1545     Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
1546  END IF;
1547 
1548  RETURN;
1549 EXCEPTION
1550   WHEN Others THEN
1551     -- nocopy changes
1552     p_ext_dtl_rec := l_ext_dtl_rec_nc;
1553     RAISE;
1554 
1555 END Update_Record_Values;
1556 
1557 -- ============================================================================
1558 -- ~ Ins_Rslt_Dtl : Inserts a record into the results detail record.
1559 -- ============================================================================
1560 PROCEDURE Ins_Rslt_Dtl(p_dtl_rec IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE) IS
1561 
1562 l_proc_name   Varchar2(150) := g_proc_name||'Ins_Rslt_Dtl';
1563 l_dtl_rec_nc  ben_ext_rslt_dtl%ROWTYPE;
1564 
1565 BEGIN -- ins_rslt_dtl
1566 
1567    IF g_debug THEN
1568       Hr_Utility.set_location('Entering :'||l_proc_name, 5);
1569    END IF;
1570   -- nocopy changes
1571   l_dtl_rec_nc := p_dtl_rec;
1572   -- Get the next sequence NUMBER to insert a record into the table
1573   SELECT ben_ext_rslt_dtl_s.NEXTVAL INTO p_dtl_rec.ext_rslt_dtl_id FROM dual;
1574 
1575   INSERT INTO ben_ext_rslt_dtl
1576   (EXT_RSLT_DTL_ID
1577   ,EXT_RSLT_ID
1578   ,BUSINESS_GROUP_ID
1579   ,EXT_RCD_ID
1580   ,PERSON_ID
1581   ,VAL_01
1582   ,VAL_02
1583   ,VAL_03
1584   ,VAL_04
1585   ,VAL_05
1586   ,VAL_06
1587   ,VAL_07
1588   ,VAL_08
1589   ,VAL_09
1590   ,VAL_10
1591   ,VAL_11
1592   ,VAL_12
1593   ,VAL_13
1594   ,VAL_14
1595   ,VAL_15
1596   ,VAL_16
1597   ,VAL_17
1598   ,VAL_19
1599   ,VAL_18
1600   ,VAL_20
1601   ,VAL_21
1602   ,VAL_22
1603   ,VAL_23
1604   ,VAL_24
1605   ,VAL_25
1606   ,VAL_26
1607   ,VAL_27
1608   ,VAL_28
1609   ,VAL_29
1610   ,VAL_30
1611   ,VAL_31
1612   ,VAL_32
1613   ,VAL_33
1614   ,VAL_34
1615   ,VAL_35
1616   ,VAL_36
1617   ,VAL_37
1618   ,VAL_38
1619   ,VAL_39
1620   ,VAL_40
1621   ,VAL_41
1622   ,VAL_42
1623   ,VAL_43
1624   ,VAL_44
1625   ,VAL_45
1626   ,VAL_46
1627   ,VAL_47
1628   ,VAL_48
1629   ,VAL_49
1630   ,VAL_50
1631   ,VAL_51
1632   ,VAL_52
1633   ,VAL_53
1634   ,VAL_54
1635   ,VAL_55
1636   ,VAL_56
1637   ,VAL_57
1638   ,VAL_58
1639   ,VAL_59
1640   ,VAL_60
1641   ,VAL_61
1642   ,VAL_62
1643   ,VAL_63
1644   ,VAL_64
1645   ,VAL_65
1646   ,VAL_66
1647   ,VAL_67
1648   ,VAL_68
1649   ,VAL_69
1650   ,VAL_70
1651   ,VAL_71
1652   ,VAL_72
1653   ,VAL_73
1654   ,VAL_74
1655   ,VAL_75
1656   ,CREATED_BY
1657   ,CREATION_DATE
1658   ,LAST_UPDATE_DATE
1659   ,LAST_UPDATED_BY
1660   ,LAST_UPDATE_LOGIN
1661   ,PROGRAM_APPLICATION_ID
1662   ,PROGRAM_ID
1663   ,PROGRAM_UPDATE_DATE
1664   ,REQUEST_ID
1665   ,OBJECT_VERSION_NUMBER
1666   ,PRMY_SORT_VAL
1667   ,SCND_SORT_VAL
1668   ,THRD_SORT_VAL
1669   ,TRANS_SEQ_NUM
1670   ,RCRD_SEQ_NUM
1671   )
1672   VALUES
1673   (p_dtl_rec.EXT_RSLT_DTL_ID
1674   ,p_dtl_rec.EXT_RSLT_ID
1675   ,p_dtl_rec.BUSINESS_GROUP_ID
1676   ,p_dtl_rec.EXT_RCD_ID
1677   ,p_dtl_rec.PERSON_ID
1678   ,p_dtl_rec.VAL_01
1679   ,p_dtl_rec.VAL_02
1680   ,p_dtl_rec.VAL_03
1681   ,p_dtl_rec.VAL_04
1682   ,p_dtl_rec.VAL_05
1683   ,p_dtl_rec.VAL_06
1684   ,p_dtl_rec.VAL_07
1685   ,p_dtl_rec.VAL_08
1686   ,p_dtl_rec.VAL_09
1687   ,p_dtl_rec.VAL_10
1688   ,p_dtl_rec.VAL_11
1689   ,p_dtl_rec.VAL_12
1690   ,p_dtl_rec.VAL_13
1691   ,p_dtl_rec.VAL_14
1692   ,p_dtl_rec.VAL_15
1693   ,p_dtl_rec.VAL_16
1694   ,p_dtl_rec.VAL_17
1695   ,p_dtl_rec.VAL_19
1696   ,p_dtl_rec.VAL_18
1697   ,p_dtl_rec.VAL_20
1698   ,p_dtl_rec.VAL_21
1699   ,p_dtl_rec.VAL_22
1700   ,p_dtl_rec.VAL_23
1701   ,p_dtl_rec.VAL_24
1702   ,p_dtl_rec.VAL_25
1703   ,p_dtl_rec.VAL_26
1704   ,p_dtl_rec.VAL_27
1705   ,p_dtl_rec.VAL_28
1706   ,p_dtl_rec.VAL_29
1707   ,p_dtl_rec.VAL_30
1708   ,p_dtl_rec.VAL_31
1709   ,p_dtl_rec.VAL_32
1710   ,p_dtl_rec.VAL_33
1711   ,p_dtl_rec.VAL_34
1712   ,p_dtl_rec.VAL_35
1713   ,p_dtl_rec.VAL_36
1714   ,p_dtl_rec.VAL_37
1715   ,p_dtl_rec.VAL_38
1716   ,p_dtl_rec.VAL_39
1717   ,p_dtl_rec.VAL_40
1718   ,p_dtl_rec.VAL_41
1719   ,p_dtl_rec.VAL_42
1720   ,p_dtl_rec.VAL_43
1721   ,p_dtl_rec.VAL_44
1722   ,p_dtl_rec.VAL_45
1723   ,p_dtl_rec.VAL_46
1724   ,p_dtl_rec.VAL_47
1725   ,p_dtl_rec.VAL_48
1726   ,p_dtl_rec.VAL_49
1727   ,p_dtl_rec.VAL_50
1728   ,p_dtl_rec.VAL_51
1729   ,p_dtl_rec.VAL_52
1730   ,p_dtl_rec.VAL_53
1731   ,p_dtl_rec.VAL_54
1732   ,p_dtl_rec.VAL_55
1733   ,p_dtl_rec.VAL_56
1734   ,p_dtl_rec.VAL_57
1735   ,p_dtl_rec.VAL_58
1736   ,p_dtl_rec.VAL_59
1737   ,p_dtl_rec.VAL_60
1738   ,p_dtl_rec.VAL_61
1739   ,p_dtl_rec.VAL_62
1740   ,p_dtl_rec.VAL_63
1741   ,p_dtl_rec.VAL_64
1742   ,p_dtl_rec.VAL_65
1743   ,p_dtl_rec.VAL_66
1744   ,p_dtl_rec.VAL_67
1745   ,p_dtl_rec.VAL_68
1746   ,p_dtl_rec.VAL_69
1747   ,p_dtl_rec.VAL_70
1748   ,p_dtl_rec.VAL_71
1749   ,p_dtl_rec.VAL_72
1750   ,p_dtl_rec.VAL_73
1751   ,p_dtl_rec.VAL_74
1752   ,p_dtl_rec.VAL_75
1753   ,p_dtl_rec.CREATED_BY
1754   ,p_dtl_rec.CREATION_DATE
1755   ,p_dtl_rec.LAST_UPDATE_DATE
1756   ,p_dtl_rec.LAST_UPDATED_BY
1757   ,p_dtl_rec.LAST_UPDATE_LOGIN
1758   ,p_dtl_rec.PROGRAM_APPLICATION_ID
1759   ,p_dtl_rec.PROGRAM_ID
1760   ,p_dtl_rec.PROGRAM_UPDATE_DATE
1761   ,p_dtl_rec.REQUEST_ID
1762   ,p_dtl_rec.OBJECT_VERSION_NUMBER
1763   ,p_dtl_rec.PRMY_SORT_VAL
1764   ,p_dtl_rec.SCND_SORT_VAL
1765   ,p_dtl_rec.THRD_SORT_VAL
1766   ,p_dtl_rec.TRANS_SEQ_NUM
1767   ,p_dtl_rec.RCRD_SEQ_NUM
1768   );
1769 
1770   IF g_debug THEN
1771      Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
1772   END IF;
1773 
1774   RETURN;
1775 
1776 EXCEPTION
1777   WHEN Others THEN
1778     Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
1779     p_dtl_rec := l_dtl_rec_nc;
1780     RAISE;
1781 END Ins_Rslt_Dtl;
1782 
1783 -- ============================================================================
1784 -- ~ Upd_Rslt_Dtl : Updates the primary assignment record in results detail table
1785 -- ============================================================================
1786 PROCEDURE Upd_Rslt_Dtl(p_dtl_rec IN ben_ext_rslt_dtl%ROWTYPE ) IS
1787 
1788 l_proc_name Varchar2(150):= g_proc_name||'upd_rslt_dtl';
1789 
1790 BEGIN -- Upd_Rslt_Dtl
1791   UPDATE ben_ext_rslt_dtl
1792   SET VAL_01                 = p_dtl_rec.VAL_01
1793      ,VAL_02                 = p_dtl_rec.VAL_02
1794      ,VAL_03                 = p_dtl_rec.VAL_03
1795      ,VAL_04                 = p_dtl_rec.VAL_04
1796      ,VAL_05                 = p_dtl_rec.VAL_05
1797      ,VAL_06                 = p_dtl_rec.VAL_06
1798      ,VAL_07                 = p_dtl_rec.VAL_07
1799      ,VAL_08                 = p_dtl_rec.VAL_08
1800      ,VAL_09                 = p_dtl_rec.VAL_09
1801      ,VAL_10                 = p_dtl_rec.VAL_10
1802      ,VAL_11                 = p_dtl_rec.VAL_11
1803      ,VAL_12                 = p_dtl_rec.VAL_12
1804      ,VAL_13                 = p_dtl_rec.VAL_13
1805      ,VAL_14                 = p_dtl_rec.VAL_14
1806      ,VAL_15                 = p_dtl_rec.VAL_15
1807      ,VAL_16                 = p_dtl_rec.VAL_16
1808      ,VAL_17                 = p_dtl_rec.VAL_17
1809      ,VAL_19                 = p_dtl_rec.VAL_19
1810      ,VAL_18                 = p_dtl_rec.VAL_18
1811      ,VAL_20                 = p_dtl_rec.VAL_20
1812      ,VAL_21                 = p_dtl_rec.VAL_21
1813      ,VAL_22                 = p_dtl_rec.VAL_22
1814      ,VAL_23                 = p_dtl_rec.VAL_23
1815      ,VAL_24                 = p_dtl_rec.VAL_24
1816      ,VAL_25                 = p_dtl_rec.VAL_25
1817      ,VAL_26                 = p_dtl_rec.VAL_26
1818      ,VAL_27                 = p_dtl_rec.VAL_27
1819      ,VAL_28                 = p_dtl_rec.VAL_28
1820      ,VAL_29                 = p_dtl_rec.VAL_29
1821      ,VAL_30                 = p_dtl_rec.VAL_30
1822      ,VAL_31                 = p_dtl_rec.VAL_31
1823      ,VAL_32                 = p_dtl_rec.VAL_32
1824      ,VAL_33                 = p_dtl_rec.VAL_33
1825      ,VAL_34                 = p_dtl_rec.VAL_34
1826      ,VAL_35                 = p_dtl_rec.VAL_35
1827      ,VAL_36                 = p_dtl_rec.VAL_36
1828      ,VAL_37                 = p_dtl_rec.VAL_37
1829      ,VAL_38                 = p_dtl_rec.VAL_38
1830      ,VAL_39                 = p_dtl_rec.VAL_39
1831      ,VAL_40                 = p_dtl_rec.VAL_40
1832      ,VAL_41                 = p_dtl_rec.VAL_41
1833      ,VAL_42                 = p_dtl_rec.VAL_42
1834      ,VAL_43                 = p_dtl_rec.VAL_43
1835      ,VAL_44                 = p_dtl_rec.VAL_44
1836      ,VAL_45                 = p_dtl_rec.VAL_45
1837      ,VAL_46                 = p_dtl_rec.VAL_46
1838      ,VAL_47                 = p_dtl_rec.VAL_47
1839      ,VAL_48                 = p_dtl_rec.VAL_48
1840      ,VAL_49                 = p_dtl_rec.VAL_49
1841      ,VAL_50                 = p_dtl_rec.VAL_50
1842      ,VAL_51                 = p_dtl_rec.VAL_51
1843      ,VAL_52                 = p_dtl_rec.VAL_52
1844      ,VAL_53                 = p_dtl_rec.VAL_53
1845      ,VAL_54                 = p_dtl_rec.VAL_54
1846      ,VAL_55                 = p_dtl_rec.VAL_55
1847      ,VAL_56                 = p_dtl_rec.VAL_56
1848      ,VAL_57                 = p_dtl_rec.VAL_57
1849      ,VAL_58                 = p_dtl_rec.VAL_58
1850      ,VAL_59                 = p_dtl_rec.VAL_59
1851      ,VAL_60                 = p_dtl_rec.VAL_60
1852      ,VAL_61                 = p_dtl_rec.VAL_61
1853      ,VAL_62                 = p_dtl_rec.VAL_62
1854      ,VAL_63                 = p_dtl_rec.VAL_63
1855      ,VAL_64                 = p_dtl_rec.VAL_64
1856      ,VAL_65                 = p_dtl_rec.VAL_65
1857      ,VAL_66                 = p_dtl_rec.VAL_66
1858      ,VAL_67                 = p_dtl_rec.VAL_67
1859      ,VAL_68                 = p_dtl_rec.VAL_68
1860      ,VAL_69                 = p_dtl_rec.VAL_69
1861      ,VAL_70                 = p_dtl_rec.VAL_70
1862      ,VAL_71                 = p_dtl_rec.VAL_71
1863      ,VAL_72                 = p_dtl_rec.VAL_72
1864      ,VAL_73                 = p_dtl_rec.VAL_73
1865      ,VAL_74                 = p_dtl_rec.VAL_74
1866      ,VAL_75                 = p_dtl_rec.VAL_75
1867      ,OBJECT_VERSION_NUMBER  = p_dtl_rec.OBJECT_VERSION_NUMBER
1868      ,THRD_SORT_VAL          = p_dtl_rec.THRD_SORT_VAL
1869      ,prmy_sort_val	     =p_dtl_rec.prmy_sort_val
1870   WHERE ext_rslt_dtl_id = p_dtl_rec.ext_rslt_dtl_id;
1871 
1872   RETURN;
1873 
1874 EXCEPTION
1875   WHEN Others THEN
1876      RAISE;
1877 END Upd_Rslt_Dtl;
1878 
1879 -- =============================================================================
1880 -- Process_Ext_Rslt_Dtl_Rec:
1881 -- =============================================================================
1882 PROCEDURE  Process_Ext_Rslt_Dtl_Rec
1883             (p_assignment_id    IN per_all_assignments.assignment_id%TYPE
1884             ,p_organization_id  IN per_all_assignments.organization_id%TYPE DEFAULT NULL
1885             ,p_effective_date   IN Date
1886             ,p_ext_dtl_rcd_id   IN ben_ext_rcd.ext_rcd_id%TYPE
1887             ,p_rslt_rec         IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE
1888             ,p_asgaction_no     IN Number  DEFAULT NULL
1889             ,p_error_message    OUT NOCOPY Varchar2) IS
1890 
1891  CURSOR csr_rule_ele
1892           (c_ext_rcd_id  IN ben_ext_data_elmt_in_rcd.ext_rcd_id%TYPE) IS
1893    SELECT  a.ext_data_elmt_in_rcd_id
1894           ,a.seq_num
1895           ,a.sprs_cd
1896           ,a.strt_pos
1897           ,a.dlmtr_val
1898           ,a.rqd_flag
1899           ,b.ext_data_elmt_id
1900           ,b.data_elmt_typ_cd
1901           ,b.data_elmt_rl
1902           ,b.NAME
1903           ,Hr_General.decode_lookup('BEN_EXT_FRMT_MASK', b.frmt_mask_cd) frmt_mask_cd
1904           ,b.frmt_mask_cd frmt_mask_lookup_cd
1905           ,b.string_val
1906           ,b.dflt_val
1907           ,b.max_length_num
1908           ,b.just_cd
1909      FROM  ben_ext_data_elmt           b,
1910            ben_ext_data_elmt_in_rcd    a
1911     WHERE  a.ext_data_elmt_id = b.ext_data_elmt_id
1912       AND  b.data_elmt_typ_cd = 'R'
1913       AND  a.ext_rcd_id       = c_ext_rcd_id
1914     --  AND  a.hide_flag        = 'N'
1915      ORDER BY a.seq_num;
1916 
1917    CURSOR csr_ff_type ( c_formula_type_id IN ff_formulas_f.formula_id%TYPE
1918                        ,c_effective_date     IN Date) IS
1919     SELECT formula_type_id
1920       FROM ff_formulas_f
1921      WHERE formula_id = c_formula_type_id
1922        AND c_effective_date BETWEEN effective_start_date
1923                                 AND effective_end_date;
1924 
1925    CURSOR c_get_org_id IS
1926    SELECT organization_id,business_group_id
1927      FROM per_all_assignments_f
1928    WHERE  assignment_id = p_assignment_id
1929      AND  business_group_id = g_business_group_id
1930      AND  p_effective_date BETWEEN effective_start_date
1931                                 AND effective_end_date;
1932 
1933 
1934 
1935   l_proc_name           Varchar2(150) := g_proc_name ||'Process_Ext_Rslt_Dtl_Rec';
1936   l_foumula_type_id     ff_formulas_f.formula_id%TYPE;
1937   l_outputs             Ff_Exec.outputs_t;
1938   l_ff_value            ben_ext_rslt_dtl.val_01%TYPE;
1939   l_ff_value_fmt        ben_ext_rslt_dtl.val_01%TYPE;
1940   l_org_id              per_all_assignments_f.organization_id%TYPE;
1941   l_bgid                per_all_assignments_f.business_group_id%TYPE;
1942 
1943 
1944 BEGIN
1945 
1946    IF g_debug THEN
1947       Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1948    END IF;
1949 
1950    OPEN c_get_org_id;
1951    FETCH c_get_org_id INTO l_org_id,l_bgid;
1952    CLOSE c_get_org_id;
1953 
1954 
1955   IF g_debug THEN
1956      Hr_Utility.set_location('p_ext_dtl_rcd_id: '||p_ext_dtl_rcd_id, 5);
1957      Hr_Utility.set_location('p_assignment_id: '||p_assignment_id, 5);
1958   END IF;
1959 
1960    FOR i IN  csr_rule_ele( c_ext_rcd_id => p_ext_dtl_rcd_id)
1961    LOOP
1962     OPEN  csr_ff_type(c_formula_type_id => i.data_elmt_rl
1963                      ,c_effective_date  => p_effective_date);
1964     FETCH csr_ff_type  INTO l_foumula_type_id;
1965     CLOSE csr_ff_type;
1966 
1967     IF g_debug THEN
1968       Hr_Utility.set_location('l_foumula_type_id: '||l_foumula_type_id, 5);
1969     END IF;
1970 
1971     IF l_foumula_type_id = -413 THEN -- person level rule
1972        l_outputs := Benutils.formula
1973                    (p_formula_id         => i.data_elmt_rl
1974                    ,p_effective_date     => p_effective_date
1975                    ,p_assignment_id      => p_assignment_id
1976                    ,p_organization_id    => l_org_id
1977                    ,p_business_group_id  => l_bgid
1978                    ,p_jurisdiction_code  => NULL
1979                    ,p_param1             => 'EXT_DFN_ID'
1980                    ,p_param1_value       => To_Char(Nvl(Ben_Ext_Thread.g_ext_dfn_id, -1))
1981                    ,p_param2             => 'EXT_RSLT_ID'
1982                    ,p_param2_value       => To_Char(Nvl(Ben_Ext_Thread.g_ext_rslt_id, -1))
1983                    );
1984         l_ff_value := l_outputs(l_outputs.FIRST).VALUE;
1985         BEGIN
1986           IF i.frmt_mask_lookup_cd IS NOT NULL AND
1987              l_ff_value IS NOT NULL THEN
1988              IF Substr(i.frmt_mask_lookup_cd,1,1) = 'N' THEN
1989              IF g_debug THEN
1990                Hr_Utility.set_location('..Applying NUMBER format mask
1991                                   :ben_ext_fmt.apply_format_mask',50);
1992              END IF;
1993                l_ff_value_fmt := Ben_Ext_Fmt.apply_format_mask(To_Number(l_ff_value), i.frmt_mask_cd);
1994                l_ff_value     := l_ff_value_fmt;
1995             ELSIF Substr(i.frmt_mask_lookup_cd,1,1) = 'D' THEN
1996                IF g_debug THEN
1997                Hr_Utility.set_location('..Applying Date format mask
1998                                         :ben_ext_fmt.apply_format_mask',55);
1999                END IF;
2000                l_ff_value_fmt := Ben_Ext_Fmt.apply_format_mask(Fnd_Date.canonical_to_date(l_ff_value),
2001                                                                i.frmt_mask_cd);
2002                l_ff_value     := l_ff_value_fmt;
2003             END IF;
2004           END  IF;
2005         EXCEPTION  -- incase l_ff_value is not valid for formatting, just don't format it.
2006             WHEN Others THEN
2007             NULL;
2008         END;
2009         Update_Record_Values (p_ext_rcd_id            => p_ext_dtl_rcd_id
2010                              ,p_ext_data_element_name => NULL
2011                              ,p_data_element_value    => l_ff_value
2012                              ,p_data_ele_seqnum       => i.seq_num
2013                              ,p_ext_dtl_rec           => p_rslt_rec);
2014      END IF;
2015    END LOOP; --For i in  csr_rule_ele
2016 
2017    p_rslt_rec.prmy_sort_val := p_assignment_id;
2018 
2019    Ins_Rslt_Dtl(p_dtl_rec => p_rslt_rec);
2020 
2021    IF g_debug THEN
2022       Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
2023    END IF;
2024 
2025 EXCEPTION
2026    WHEN Others THEN
2027     Hr_Utility.set_location('..error',85);
2028     Hr_Utility.set_location('SQL-ERRM :'||SQLERRM,87);
2029     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2030 END Process_Ext_Rslt_Dtl_Rec;
2031 
2032 -- ===============================================================================
2033 -- ~ Get_ConcProg_Information : Common function to get the concurrent program parameters
2034 -- ===============================================================================
2035 FUNCTION Get_ConcProg_Information
2036            (p_header_type IN Varchar2
2037            ,p_error_message OUT NOCOPY Varchar2) RETURN Varchar2 IS
2038 
2039 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_ConcProg_Information';
2040 l_return_value   Varchar2(1000);
2041 
2042 BEGIN
2043 
2044    IF g_debug THEN
2045       Hr_Utility.set_location('Entering: '||l_proc_name, 5);
2046    END IF;
2047 
2048    IF p_header_type = 'EXTRACT_NAME' THEN
2049         l_return_value := g_conc_prog_details(0).extract_name;
2050    ELSIF p_header_type = 'REPORT_OPTION' THEN
2051        l_return_value := g_conc_prog_details(0).reporting_options;
2052    ELSIF p_header_type = 'SELECTION_CRITERIA' THEN
2053        l_return_value := g_conc_prog_details(0).selection_criteria;
2054    ELSIF p_header_type = 'ELE_SET' THEN
2055        l_return_value := g_conc_prog_details(0).elementset;
2056    ELSIF p_header_type = 'ELE_NAME' THEN
2057        l_return_value := g_conc_prog_details(0).elementname;
2058    ELSIF p_header_type = 'BGN_DT_PAID' THEN
2059       l_return_value := g_conc_prog_details(0).beginningdt;
2060    ELSIF p_header_type = 'END_DT_PAID' THEN
2061          l_return_value := g_conc_prog_details(0).endingdt;
2062    ELSIF p_header_type = 'GRE' THEN
2063        l_return_value := g_conc_prog_details(0).grename;
2064    ELSIF p_header_type = 'PAYROLL_NAME' THEN
2065    IF g_debug THEN
2066       Hr_Utility.set_location('PAYROLL_NAME: '||g_conc_prog_details(0).payrollname, 5);
2067    END IF;
2068       l_return_value := g_conc_prog_details(0).payrollname;
2069    ELSIF p_header_type = 'CON_SET' THEN
2070       l_return_value := g_conc_prog_details(0).consolset;
2071       IF g_debug THEN
2072          Hr_Utility.set_location('CON_SET: '||l_return_value, 5);
2073       END IF;
2074    END IF;
2075    IF g_debug THEN
2076       Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
2077    END IF;
2078 
2079   RETURN l_return_value;
2080 EXCEPTION
2081   WHEN Others THEN
2082      p_error_message :='SQL-ERRM :'||SQLERRM;
2083      Hr_Utility.set_location('..Exception Others Raised at Get_ConcProg_Information'||p_error_message,40);
2084      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
2085      RETURN l_return_value;
2086 END Get_ConcProg_Information;
2087 
2088 -- =============================================================================
2089 -- ~ Get_Balance_Value: Gets the balance value for a given balance name for that
2090 -- ~ Assign.Id as of an effective date
2091 -- =============================================================================
2092 FUNCTION Get_Balance_Value_Eff_Dt
2093            (p_assignment_id       IN  NUMBER
2094            ,p_business_group_id   IN  NUMBER
2095            ,p_balance_name        IN  VARCHAR2
2096            ,p_error_message       OUT NOCOPY VARCHAR2
2097            ,p_start_date          IN  DATE
2098            ,p_end_date            IN  DATE)
2099 RETURN NUMBER IS
2100 
2101  l_defined_balance_id   pay_defined_balances.defined_balance_id%TYPE;
2102  l_balance_amount       NUMBER :=0;
2103  l_bal_total_amt        NUMBER :=0;
2104  l_dimension_name       VARCHAR2(100);
2105  i                      per_all_assignments_f.business_group_id%TYPE;
2106  l_legislation_code     per_business_groups.legislation_code%TYPE;
2107  l_balance_type_id      pay_balance_types.balance_type_id%TYPE;
2108  l_index                NUMBER;
2109 
2110 BEGIN
2111 
2112   i := p_business_group_id;
2113   IF g_debug THEN
2114      Hr_Utility.set_location('Entering Get_Balance_Value function:', 5);
2115   END IF;
2116    -- Check this balance already exists in record
2117    -- If it exists then get the balance type id
2118    FOR num IN 1..g_balance_detls.Count LOOP
2119      IF g_balance_detls(num).balance_name = p_balance_name  THEN
2120         l_balance_type_id    := g_balance_detls(num).balance_type_id;
2121         l_defined_balance_id := g_balance_detls(num).defined_balance_id;
2122         EXIT;
2123      END IF;
2124    END LOOP;
2125    -- Get the balance type id for a balance name ,if it does not exist in record
2126    IF l_balance_type_id IS NULL THEN
2127       OPEN csr_bal_typid (c_balance_name       => p_balance_name
2128                          ,c_business_group_id  => p_business_group_id
2129                          ,c_legislation_code   => g_legislation_code);
2130       FETCH csr_bal_typid INTO l_balance_type_id;
2131       CLOSE csr_bal_typid;
2132       -- Get the def. balance id for a given balance type id
2133       IF l_balance_type_id IS NOT NULL THEN
2134          OPEN  csr_asg_balid
2135                     (c_balance_type_id      => l_balance_type_id
2136                     ,c_balance_dimension_id => g_asgrun_dim_id
2137                     ,c_business_group_id    => p_business_group_id);
2138          FETCH csr_asg_balid INTO l_defined_balance_id;
2139          CLOSE csr_asg_balid;
2140       END IF;
2141       l_index := g_balance_detls.Count + 1;
2142       g_balance_detls(l_index).balance_name       := p_balance_name;
2143       g_balance_detls(l_index).balance_type_id    := l_balance_type_id;
2144       g_balance_detls(l_index).defined_balance_id := l_defined_balance_id;
2145    END IF;
2146 
2147   IF l_defined_balance_id IS NOT NULL THEN
2148    --Get the Assignment action ids for assignment Id
2149          FOR asgact_rec IN csr_asg_act
2150                    (c_assignment_id => p_assignment_id
2151                    ,c_payroll_id    => g_extract_params(i).payroll_id
2152                    ,c_con_set_id    => g_extract_params(i).con_set_id
2153                    ,c_start_date    => p_start_date
2154                    ,c_end_date      => p_end_date
2155                    )
2156          LOOP
2157             l_balance_amount := Pay_Balance_Pkg.get_value
2158                       (p_defined_balance_id   => l_defined_balance_id,
2159                        p_assignment_action_id => asgact_rec.assignment_action_id );
2160             l_bal_total_amt := l_bal_total_amt + Nvl(l_balance_amount,0);
2161          END LOOP; -- For Loop
2162      END IF;  -- If l_defined_balance_id
2163   RETURN l_bal_total_amt;
2164 
2165 EXCEPTION
2166    WHEN Others THEN
2167     p_error_message :='SQL-ERRM :'||SQLERRM;
2168     Hr_Utility.set_location('..'||p_error_message,85);
2169    Hr_Utility.set_location('Leaving Get_Balance_Value function:', 80);
2170     RETURN l_bal_total_amt;
2171 END Get_Balance_Value_Eff_Dt;
2172 
2173 -- =============================================================================
2174 -- ~ Get_Balance_Value: Gets the balance value for a given balance name for that
2175 -- ~ Assign.Id.
2176 -- =============================================================================
2177 FUNCTION Get_Balance_Value
2178            (p_assignment_id       IN  NUMBER
2179            ,p_business_group_id   IN  NUMBER
2180            ,p_balance_name        IN  VARCHAR2
2181            ,p_error_message       OUT NOCOPY VARCHAR2 )
2182 RETURN NUMBER IS
2183 
2184  l_bal_total_amt  NUMBER :=0;
2185  i                per_all_assignments_f.business_group_id%TYPE;
2186 
2187 BEGIN
2188 
2189   i := p_business_group_id;
2190 
2191   IF g_debug THEN
2192      Hr_Utility.set_location('Entering Get_Balance_Value function:', 5);
2193   END IF;
2194 
2195   l_bal_total_amt := Get_Balance_Value_Eff_Dt
2196            (p_assignment_id       => p_assignment_id
2197            ,p_business_group_id   => p_business_group_id
2198            ,p_balance_name        => p_balance_name
2199            ,p_error_message       => p_error_message
2200            ,p_start_date          => g_extract_params(i).extract_start_date
2201            ,p_end_date            => g_extract_params(i).extract_end_date
2202             );
2203 
2204   RETURN l_bal_total_amt;
2205 
2206 EXCEPTION
2207    WHEN Others THEN
2208       p_error_message :='SQL-ERRM :'||SQLERRM;
2209       Hr_Utility.set_location('..'||p_error_message,85);
2210       Hr_Utility.set_location('Leaving Get_Balance_Value function:', 80);
2211       RETURN l_bal_total_amt;
2212 END Get_Balance_Value;
2213 
2214 -- ====================================================================
2215 -- ~ Set_ConcProg_Parameter_Values : Used to get the conc program parameters
2216 --   values for passed ids and also setting the values into the global records
2217 -- ====================================================================
2218 PROCEDURE Set_ConcProg_Parameter_Values
2219            (p_ext_dfn_id                  IN     Number
2220            ,p_start_date                  IN     Varchar2
2221            ,p_end_date                    IN     Varchar2
2222            ,p_payroll_id                  IN     Number
2223            ,p_con_set                     IN     Number
2224            ,p_org_id                      IN     Number
2225            )  IS
2226 
2227    CURSOR csr_ext_name(c_ext_dfn_id  IN Number
2228                        )IS
2229       SELECT Substr(ed.NAME,1,240)
2230        FROM ben_ext_dfn ed
2231         WHERE ed.ext_dfn_id = p_ext_dfn_id;
2232 
2233     CURSOR csr_pay_name(c_payroll_id IN Number
2234 			,c_end_date        IN Date
2235          	        )IS
2236      	  SELECT pay.payroll_name
2237            FROM pay_payrolls_f pay
2238             WHERE pay.payroll_id = c_payroll_id
2239 	     AND c_end_date BETWEEN pay.effective_start_date
2240                                 AND pay.effective_end_date;
2241 
2242     CURSOR csr_con_set (c_con_set IN Number
2243      		       )IS
2244          SELECT con.consolidation_set_name
2245            FROM pay_consolidation_sets con
2246           WHERE con.consolidation_set_id = c_con_set;
2247 
2248 
2249    l_proc_name      Varchar2(150) := g_proc_name ||'Set_ConcProg_Parameter_Values';
2250    l_extract_name    ben_ext_dfn.NAME%TYPE;
2251    l_payroll_name    PAY_PAYROLLS_F.PAYROLL_NAME%TYPE ;
2252    l_con_set_name    PAY_CONSOLIDATION_SETS.CONSOLIDATION_SET_NAME%TYPE;
2253    l_org_name        hr_all_organization_units.NAME%TYPE;
2254 
2255 
2256 BEGIN
2257    IF g_debug THEN
2258       Hr_Utility.set_location('Entering: '||l_proc_name, 5);
2259    END IF;
2260 
2261           OPEN csr_ext_name( c_ext_dfn_id => p_ext_dfn_id);
2262          FETCH csr_ext_name INTO l_extract_name;
2263          CLOSE csr_ext_name;
2264 
2265       IF p_payroll_id IS NOT NULL THEN
2266          OPEN  csr_pay_name( c_payroll_id => p_payroll_id
2267                              ,c_end_date =>p_end_date
2268 	 	           );
2269          FETCH csr_pay_name INTO l_payroll_name;
2270          CLOSE csr_pay_name;
2271       END IF;
2272       IF p_con_set IS NOT NULL THEN
2273          OPEN  csr_con_set( c_con_set => p_con_set);
2274          FETCH csr_con_set INTO l_con_set_name;
2275          CLOSE csr_con_set;
2276       END IF;
2277 
2278       IF p_org_id IS NOT NULL THEN
2279          OPEN  csr_org_name( c_org_id => p_org_id);
2280          FETCH csr_org_name INTO l_org_name;
2281          CLOSE csr_org_name;
2282       END IF;
2283 
2284 
2285       --Setting the values
2286       g_conc_prog_details(0).extract_name   := l_extract_name;
2287       g_conc_prog_details(0).beginningdt    := p_start_date;
2288       g_conc_prog_details(0).endingdt	   	:= p_end_date;
2289       g_conc_prog_details(0).payrollname	:= l_payroll_name;
2290       g_conc_prog_details(0).consolset	   	:= l_con_set_name;
2291       g_conc_prog_details(0).orgname	   	:= l_org_name;
2292       g_conc_prog_details(0).orgid	   	:= p_org_id;
2293 
2294    IF g_debug THEN
2295       Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
2296    END IF;
2297 
2298 EXCEPTION
2299    WHEN Others THEN
2300     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2301 END Set_ConcProg_Parameter_Values;
2302 
2303 -- ====================================================================
2304 -- Function to check if RR exist for an ass act/element combination
2305 -- ====================================================================
2306 FUNCTION Chk_Rr_Exist (p_ass_act_id      IN NUMBER
2307                       ,p_element_type_id IN NUMBER ) RETURN BOOLEAN IS
2308 
2309 CURSOR c_ass_act IS
2310 SELECT 1
2311   FROM pay_run_results
2312  WHERE assignment_action_id = p_ass_act_id
2313    AND element_type_id      = p_element_type_id;
2314 
2315 l_dummy      NUMBER;
2316 l_proc_name  VARCHAR2(150) := g_proc_name ||'chk_rr_exist';
2317 
2318 BEGIN
2319 
2320 IF g_debug THEN
2321    hr_utility.set_location('Entering: '||l_proc_name,5);
2322    hr_utility.set_location('...Ass Act is : '||p_ass_act_id,10);
2323    hr_utility.set_location('...Element Type is : '||p_element_type_id,15);
2324 END IF;
2325 
2326 OPEN c_ass_act;
2327 FETCH c_ass_act INTO l_dummy;
2328 
2329    IF c_ass_act%FOUND THEN
2330       IF g_debug THEN
2331          hr_utility.set_location('...Run Results found : ',20);
2332          hr_utility.set_location('Leaving : '||l_proc_name,30);
2333       END IF;
2334       CLOSE c_ass_act;
2335       RETURN TRUE;
2336    ELSE
2337       IF g_debug THEN
2338          hr_utility.set_location('...Run Results not found : ',20);
2339          hr_utility.set_location('Leaving : '||l_proc_name,30);
2340       END IF;
2341       CLOSE c_ass_act;
2342       RETURN FALSE;
2343    END IF;
2344 
2345 END chk_rr_exist;
2346 
2347 --
2348 -- Function to check if there is a change in hire date
2349 --
2350 FUNCTION Chk_Chg_Hire_Dt (p_person_id         IN NUMBER
2351                          ,p_business_group_id IN NUMBER
2352                          ,p_old_hire_date     OUT NOCOPY DATE
2353                          ,p_new_hire_date     OUT NOCOPY DATE )
2354 RETURN NUMBER IS
2355 
2356 CURSOR c_hire_dt_chg(c_person_id  IN NUMBER) IS
2357 SELECT old_val1 old_date,
2358        new_val1 new_date
2359   FROM ben_ext_chg_evt_log
2360 WHERE  person_id = p_person_id
2361   AND  chg_evt_cd = 'COPOS'
2362   AND  fnd_date.canonical_to_date(prmtr_09)
2363        BETWEEN g_extract_params(p_business_group_id).extract_start_date AND
2364                g_extract_params(p_business_group_id).extract_end_date
2365 ORDER BY ext_chg_evt_log_id DESC;
2366 
2367 l_old_hire_can  ben_ext_chg_evt_log.old_val1%TYPE;
2368 l_new_hire_can  ben_ext_chg_evt_log.new_val1%TYPE;
2369 l_ret_val       NUMBER := 0;
2370 
2371 BEGIN
2372 
2373  OPEN c_hire_dt_chg(c_person_id  => p_person_id);
2374 FETCH c_hire_dt_chg INTO l_old_hire_can,l_new_hire_can;
2375    IF c_hire_dt_chg%NOTFOUND THEN
2376       p_new_hire_date := NULL;
2377       p_old_hire_date := NULL;
2378       l_ret_val       := 0;
2379    ELSIF c_hire_dt_chg%FOUND THEN
2380       p_new_hire_date := to_nl_date(l_new_hire_can,'DD-MM-RRRR');
2381       p_old_hire_date := to_nl_date(l_old_hire_can,'DD-MM-RRRR');
2382       l_ret_val       := 1;
2383    END IF;
2384 CLOSE c_hire_dt_chg;
2385 
2386 RETURN l_ret_val;
2387 
2388 END chk_chg_hire_dt;
2389 
2390 -- =============================================================================
2391 -- Get_Asg_Seq_Num:
2392 -- =============================================================================
2393 FUNCTION Get_Asg_Seq_Num
2394           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
2395           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
2396           ,p_effective_date     IN  Date
2397           ,p_error_message      OUT NOCOPY Varchar2
2398               ,p_data_element_value OUT NOCOPY Varchar2
2399           ) RETURN Number IS
2400 
2401   l_proc_name  Varchar2(150) := g_proc_name ||'Get_Asg_Seq_Num';
2402   l_asg_seq_num Varchar2(2);
2403 BEGIN
2404   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
2405   IF g_primary_assig.EXISTS(p_assignment_id) THEN
2406          l_asg_seq_num := g_primary_assig(p_assignment_id).asg_seq_num;
2407      IF To_Number(Nvl(l_asg_seq_num,'1')) < 10 THEN
2408                l_asg_seq_num := '0' ||Nvl(l_asg_seq_num,'1');
2409          END IF;
2410   END IF;
2411   p_data_element_value := Nvl(l_asg_seq_num,'01');
2412   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
2413   RETURN 0;
2414 
2415 EXCEPTION
2416    WHEN Others THEN
2417     p_error_message :='SQL-ERRM :'||SQLERRM;
2418     Hr_Utility.set_location('..'||p_error_message,85);
2419     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2420     RETURN -1;
2421 END Get_Asg_Seq_Num;
2422 
2423 --============================================================================
2424 -- Function to check if the assignment being processed has to be reported to
2425 -- ABP as a new hire assignment
2426 --============================================================================
2427 FUNCTION Chk_New_Hire_Asg
2428           (p_person_id         IN per_all_people_f.person_id%TYPE
2429           ,p_assignment_id     IN per_all_assignments_f.assignment_id%TYPE
2430           ,p_business_group_id IN NUMBER
2431           ,p_start_date        IN DATE
2432           ,p_end_date          IN DATE
2433           ,p_hire_date         OUT NOCOPY DATE
2434           ,p_error_message     OUT NOCOPY VARCHAR2)
2435 RETURN NUMBER IS
2436 --
2437 -- Cursor to derive the hire date of the EE assignment
2438 --
2439 CURSOR csr_hire_dt IS
2440 SELECT MIN(effective_start_date)
2441   FROM per_all_assignments_f
2442  WHERE assignment_id   = p_assignment_id
2443    AND assignment_type = 'E';
2444 
2445 --
2446 -- Cursor to check if New hire Record 05 is sent to ABP
2447 -- in an earlier run. If record 05 is sent, there is no need
2448 -- to send it again. This check is necessary for late hire
2449 -- EE assignments
2450 --
2451 CURSOR c_rec05_sent (c_asg_seq IN VARCHAR2) IS
2452 SELECT 1
2453   FROM ben_ext_rslt_dtl     dtl
2454       ,ben_ext_rslt         res
2455       ,ben_ext_rcd          rcd
2456       ,ben_ext_rcd_in_file  rin
2457       ,ben_ext_dfn          dfn
2458 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
2459                            FROM pqp_extract_attributes
2460                           WHERE ext_dfn_type = 'NL_FPR')
2461  AND val_05 <> '00000000' -- Ptpn St Date
2462  AND val_11 IS NOT NULL   -- Kind of Ptpn
2463  AND val_12 IS NOT NULL   -- Value of Ptpn
2464  AND val_16 IS NOT NULL   -- PTP
2465  AND val_04 = c_asg_seq
2466  AND dtl.person_id    = g_person_id
2467  AND ext_stat_cd      = 'A'
2468  AND TRUNC(res.eff_dt) < TRUNC(g_extract_params(p_business_group_id).extract_start_date)
2469  AND rin.ext_file_id  = dfn.ext_file_id
2470  AND rin.ext_rcd_id   = rcd.ext_rcd_id
2471  AND dfn.ext_dfn_id   = res.ext_dfn_id
2472  AND dtl.ext_rslt_id  = res.ext_rslt_id
2473  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
2474  AND rin.seq_num      = 5;
2475 
2476 l_proc_name    VARCHAR2(150) := g_proc_name ||'.chk_new_hire_asg';
2477 l_dummy        NUMBER;
2478 l_asg_seq      VARCHAR2(2);
2479 
2480 BEGIN
2481 
2482 hr_utility.set_location('Entering :        '||l_proc_name, 90);
2483 hr_utility.set_location('Assignment Id :   '||p_assignment_id, 90);
2484 hr_utility.set_location('p_start_date is : '||p_start_date, 90);
2485 hr_utility.set_location('p_end_date is :   '||p_end_date, 90);
2486 
2487 --
2488 -- Check if the EE assignment was hired in the current extract
2489 -- start and end dates
2490 --
2491 OPEN csr_hire_dt;
2492 FETCH csr_hire_dt INTO p_hire_date;
2493 CLOSE csr_hire_dt;
2494 
2495    l_dummy  :=  Get_Asg_Seq_Num(p_assignment_id
2496                                ,p_business_group_id
2497                                ,p_hire_date
2498                                ,p_error_message
2499                                ,l_asg_seq);
2500 
2501 hr_utility.set_location('p_hire_date is : '||p_hire_date, 90);
2502 
2503 IF p_hire_date BETWEEN p_start_date AND p_end_date THEN
2504    RETURN 1;
2505 END IF;
2506 
2507 --
2508 -- If the EE assignment was not hired between the extract
2509 -- start and end dates, check if New Hire Record 05 was reported
2510 -- to ABP earlier. If it was then do not report it again.
2511 -- If not report the EE as a new hire.
2512 -- This logic works for late hire EE assignments as well.
2513 --
2514 OPEN c_rec05_sent(l_asg_seq);
2515 FETCH c_rec05_sent INTO l_dummy;
2516 IF c_rec05_sent%NOTFOUND AND
2517        TRUNC(p_hire_date) > TO_DATE('31/12/2005','DD/MM/YYYY') THEN
2518    CLOSE c_rec05_sent;
2519 hr_utility.set_location('Rec 05 Not Sent : '||p_start_date, 90);
2520    RETURN 1;
2521 ELSE
2522    CLOSE c_rec05_sent;
2523 hr_utility.set_location('Rec 05 Sent : '||p_start_date, 90);
2524    RETURN 0;
2525 END IF;
2526 
2527 hr_utility.set_location('Leaving  : '||l_proc_name, 90);
2528 
2529 RETURN 0 ;
2530 
2531 EXCEPTION
2532 
2533 WHEN OTHERS THEN
2534    p_error_message :='SQL-ERRM :'||SQLERRM;
2535    Hr_Utility.set_location('..'||p_error_message,85);
2536    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2537    RETURN 0;
2538 
2539 END chk_new_hire_asg;
2540 
2541 --=============================================================================
2542 -- Function to get the age of a person given the effective date
2543 --=============================================================================
2544 FUNCTION Get_Age
2545          (p_assignment_id   IN  per_all_assignments_f.assignment_id%TYPE
2546          ,p_effective_date  IN  DATE)
2547 RETURN NUMBER IS
2548 
2549 CURSOR get_dob IS
2550 SELECT trunc(date_of_birth)
2551   FROM per_all_people_f per
2552       ,per_all_assignments_f paf
2553  WHERE per.person_id      = paf.person_id
2554    AND paf.assignment_id  = p_assignment_id
2555    AND p_effective_date BETWEEN per.effective_start_date
2556                             AND per.effective_end_date
2557    AND p_effective_date BETWEEN paf.effective_start_date
2558                             AND paf.effective_end_date;
2559 
2560 l_age NUMBER;
2561 l_dob DATE;
2562 
2563 BEGIN
2564 
2565 --
2566 --Fetch the date of birth
2567 --
2568 OPEN get_dob;
2569 FETCH get_dob INTO l_dob;
2570 CLOSE get_dob;
2571 
2572 l_dob := NVL(l_dob,p_effective_date);
2573 
2574 RETURN (TRUNC(MONTHS_BETWEEN(p_effective_date,l_dob)/12,2));
2575 
2576 END Get_Age;
2577 
2578 -- =============================================================================
2579 -- Get_Pen_Prin_Obj_Cd
2580 -- =============================================================================
2581 FUNCTION Get_Pri_Obj_Cd_Cur
2582 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2583   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2584   ,p_effective_date       IN  Date
2585   ,p_error_message        OUT NOCOPY Varchar2
2586   ,p_data_element_value   OUT NOCOPY Varchar2
2587 ) RETURN  Number IS
2588 
2589   CURSOR c_obj_cd IS
2590   SELECT Decode(aei_information5,'Y','J',' ') obj_cd
2591     FROM per_assignment_extra_info
2592    WHERE assignment_id = p_assignment_id
2593      AND information_type = 'NL_USZO_INFO'
2594      AND Trunc(p_effective_date) BETWEEN
2595          Fnd_Date.canonical_to_date(aei_information1)AND
2596          Nvl(Fnd_Date.canonical_to_date(aei_information2),
2597              To_Date('31/12/4712','DD/MM/YYYY'))
2598      AND ROWNUM = 1;
2599      -- Rownum clause has been added on purpose as it is possible that there
2600      -- are two valid rows in the system ( There are no checks in the ASG EIT)
2601      -- this is in case the user makes an error and has two valid rows
2602      -- at the same time.
2603 
2604 
2605 l_return_value   Number := 0;
2606 l_obj_cd         Varchar2(150);
2607 l_error_code     Varchar2(10);
2608 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Pen_Prin_Obj_Cd_Cur';
2609 
2610 BEGIN
2611 
2612   Hr_Utility.set_location(' Entering     ' || l_proc_name , 5);
2613     OPEN c_obj_cd;
2614      FETCH c_obj_cd INTO l_obj_cd;
2615         IF c_obj_cd%FOUND THEN
2616            CLOSE c_obj_cd;
2617            p_data_element_value := l_obj_cd;
2618         ELSE
2619            CLOSE c_obj_cd;
2620            p_data_element_value := ' ';
2621         END IF;
2622         l_return_value := 0;
2623 
2624   Hr_Utility.set_location(' Leaving      ' || l_proc_name , 30);
2625 
2626 RETURN l_return_value;
2627 
2628 EXCEPTION
2629   WHEN Others THEN
2630    p_error_message :='SQL-ERRM :'||SQLERRM;
2631    Hr_Utility.set_location('..'||p_error_message,85);
2632    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2633    RETURN -1 ;
2634 END Get_Pri_Obj_Cd_Cur;
2635 
2636 -- =============================================================================
2637 -- Get_Pen_Prin_Obj_Cd
2638 -- =============================================================================
2639 FUNCTION Get_Pri_Obj_Cd
2640 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2641   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2642   ,p_effective_date       IN  Date
2643   ,p_error_message        OUT NOCOPY Varchar2
2644   ,p_data_element_value   OUT NOCOPY Varchar2
2645 ) RETURN  Number IS
2646 
2647 
2648 l_return_value   Number := 0;
2649 l_obj_cd         Varchar2(150);
2650 l_error_code     Varchar2(10);
2651 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Pen_Prin_Obj_Cd';
2652 j                NUMBER;
2653 l_fetch_flag     VARCHAR2(1);
2654 l_ret_val        NUMBER;
2655 
2656 BEGIN
2657 
2658 Hr_Utility.set_location(' Entering      ' || l_proc_name , 30);
2659 
2660 IF l_rec_09_values.count > 0 THEN
2661    j := l_rec_09_values.FIRST;
2662    IF l_rec_09_values.EXISTS(j) THEN
2663       l_fetch_flag := NVL(l_rec_09_values(j).pobj_flag,'Y');
2664       l_rec_09_values.DELETE(j);
2665    END IF;
2666 END IF;
2667 
2668 l_ret_val := Get_Pri_Obj_Cd_Cur(p_assignment_id
2669 			    ,p_business_group_id
2670 			    ,p_effective_date
2671 			    ,p_error_message
2672 			    ,l_obj_cd);
2673 
2674 IF l_fetch_flag = 'N' THEN
2675 
2676    IF NVL(l_obj_cd,' ')    = 'J' THEN
2677       p_data_element_value := ' ';
2678    ELSIF NVL(l_obj_cd,' ') = ' ' THEN
2679       p_data_element_value := 'J';
2680    END IF;
2681 
2682    l_return_value := 0;
2683 
2684 ELSE
2685 
2686    p_data_element_value := l_obj_cd;
2687    l_return_value := 0;
2688 
2689 END IF;
2690 
2691 Hr_Utility.set_location(' Leaving      ' || l_proc_name , 30);
2692 
2693 
2694 RETURN l_return_value;
2695 
2696 EXCEPTION
2697   WHEN Others THEN
2698    p_error_message :='SQL-ERRM :'||SQLERRM;
2699    Hr_Utility.set_location('..'||p_error_message,85);
2700    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2701    RETURN -1 ;
2702 END Get_Pri_Obj_Cd;
2703 
2704 -- =============================================================================
2705 --This Procedure stores the child orgs and sub orgs which are employer themselves of
2706 --the organization passed as parameter(employers) in table employer_child_list
2707 -- =============================================================================
2708 PROCEDURE Set_Er_Children ( p_org_id IN hr_all_organization_units.organization_id%TYPE
2709                            ,p_business_group_id    IN per_all_assignments_f.business_group_id%TYPE
2710 			   ,p_effective_date       IN Date
2711                           )
2712 IS
2713 -- Cursor to Check if a org hierarchy is attached to the BG.
2714 -- If it is attached get the valid version as of the effective date.
2715 -- If a valid version is not found then do nothing.
2716    CURSOR c_get_org_hierarchy IS
2717    SELECT pos.org_structure_version_id
2718      FROM per_org_structure_versions_v pos,
2719           hr_organization_information hoi
2720     WHERE hoi.organization_id = p_business_group_id
2721       AND To_Number(hoi.org_information1) = pos.organization_structure_id
2722       AND Trunc(p_effective_date) BETWEEN date_from
2723                                       AND Nvl(date_to,Hr_Api.g_eot)
2724       AND hoi.org_information_context = 'NL_BG_INFO';
2725 
2726 --Cursor to fetch immediate children of org
2727 CURSOR csr_get_children(c_org_id hr_all_organization_units.organization_id%TYPE,
2728                       c_org_struct_ver_id per_org_structure_versions_v.org_structure_version_id%TYPE
2729                      ) IS
2730 SELECT os.organization_id_child
2731 FROM        (SELECT *
2732              FROM per_org_structure_elements a
2733             WHERE a.org_structure_version_id = c_org_struct_ver_id ) os
2734 WHERE os.organization_id_parent = c_org_id;
2735 
2736 
2737 --Cursor to check whether oganization is tax organization or not
2738 CURSOR csr_tax_org(c_org_id NUMBER) IS
2739 SELECT 'x'
2740 FROM hr_organization_information
2741 WHERE organization_id         = c_org_id
2742    AND org_information_context = 'NL_ORG_INFORMATION'
2743    AND org_information3 IS NOT NULL
2744    AND org_information4 IS NOT NULL;
2745 
2746 CURSOR csr_any_child_exists(c_org_id hr_all_organization_units.organization_id%TYPE,
2747                           c_org_struct_ver_id per_org_structure_versions_v.org_structure_version_id%TYPE
2748                      ) IS
2749 SELECT 'x'
2750 FROM        (SELECT *
2751              FROM per_org_structure_elements a
2752             WHERE a.org_structure_version_id = c_org_struct_ver_id ) os
2753 WHERE os.organization_id_parent = c_org_id;
2754 
2755 l_error_message  Varchar2(10);
2756 l_proc_name      Varchar2(150) := g_proc_name ||'Set_Er_Children';
2757 l_org_struct_ver_id per_org_structure_versions_v.org_structure_version_id%TYPE;
2758 l_tax_org_flag   varchar2(1);
2759 l_child_org_flag varchar2(1);
2760 BEGIN
2761 Hr_Utility.set_location(' Entering      ' || l_proc_name , 30);
2762 
2763 --Get the org_structure_version_id from the hierarchy atttached to BG
2764 OPEN c_get_org_hierarchy;
2765 FETCH c_get_org_hierarchy INTO l_org_struct_ver_id;
2766 CLOSE c_get_org_hierarchy;
2767 
2768 --Loop for all the immediate children orgs
2769   FOR temp_rec IN csr_get_children(p_org_id,l_org_struct_ver_id)
2770   LOOP
2771 --CASE 1: IF org is employer do nothing
2772      OPEN  csr_tax_org(temp_rec.organization_id_child );
2773      FETCH csr_tax_org INTO l_tax_org_flag;
2774      IF csr_tax_org%FOUND THEN
2775        CLOSE csr_tax_org;
2776 
2777      ELSE
2778        CLOSE csr_tax_org;
2779 
2780 
2781      OPEN csr_any_child_exists(temp_rec.organization_id_child,l_org_struct_ver_id);
2782      FETCH csr_any_child_exists INTO l_child_org_flag;
2783 
2784      --CASE 2: If org is non employer but has no child
2785      IF csr_any_child_exists%NOTFOUND THEN
2786         CLOSE csr_any_child_exists;
2787 	--Increase the group count
2788 	g_org_grp_list_cnt(g_er_index).org_grp_count:=g_org_grp_list_cnt(g_er_index).org_grp_count+1;
2789 
2790 	--Increase index
2791 	g_er_child_index:=g_er_child_index+1;
2792 
2793 	--add current org to the employer child table
2794 	g_employer_child_list(g_er_child_index).gre_org_id:=temp_rec.organization_id_child;
2795 
2796 
2797       ELSE
2798      --CASE 3:If org is a non employer and has child/children orgs
2799         CLOSE csr_any_child_exists;
2800 	--Increase the group count
2801 	g_org_grp_list_cnt(g_er_index).org_grp_count:=g_org_grp_list_cnt(g_er_index).org_grp_count+1;
2802 
2803 	--Increase index
2804 	g_er_child_index:=g_er_child_index+1;
2805 
2806 	--add current org to the employer child table
2807 	g_employer_child_list(g_er_child_index).gre_org_id:=temp_rec.organization_id_child;
2808 
2809 	--Make a recursive call
2810         Set_Er_Children(temp_rec.organization_id_child,p_business_group_id,p_effective_date);
2811       END IF;
2812    END IF;
2813 
2814   END LOOP;
2815 
2816 
2817 Hr_Utility.set_location(' Leaving     ' || l_proc_name , 100);
2818 EXCEPTION
2819   WHEN Others THEN
2820    l_error_message :='SQL-ERRM :'||SQLERRM;
2821    Hr_Utility.set_location('..'||l_error_message,85);
2822    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2823 END Set_Er_Children;
2824 
2825 --
2826 -- Function to check if ABP Pensions element is processed for the
2827 -- EE assignment. This also takes care of the EE assignment
2828 -- not attached to the payroll.
2829 --
2830 FUNCTION Chk_ABP_Processed
2831          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
2832          ,p_effective_date     IN  DATE
2833          ,p_business_group_id  IN NUMBER)
2834 RETURN NUMBER IS
2835 
2836 l_payroll_id NUMBER;
2837 l_abp_ee_xst NUMBER;
2838 l_proc_name  VARCHAR2(150) := g_proc_name ||'Chk_ABP_Processed';
2839 
2840 --
2841 -- Cursor to check if an Element Entry for ABP Pensions
2842 -- exists for the EE assignment
2843 --
2844 CURSOR c_abp_entry IS
2845 SELECT 1
2846  FROM pay_element_entries_f peef,
2847       pay_element_links_f   pelf
2848 WHERE p_effective_date BETWEEN peef.effective_start_date AND
2849                                peef.effective_end_date
2850   AND p_effective_date BETWEEN pelf.effective_start_date AND
2851                                pelf.effective_end_date
2852   AND peef.element_link_id  = pelf.element_link_id
2853   AND peef.assignment_id    = p_assignment_id
2854   AND pelf.element_type_id  =
2855         (SELECT element_type_id
2856            FROM pay_element_types_f
2857           WHERE element_name = 'ABP Pensions'
2858             AND TRUNC(g_extract_params(p_business_group_id).extract_start_date)
2859                 BETWEEN effective_start_date AND effective_end_date);
2860 
2861 --
2862 -- Cursor to check if the EE assignment is attached
2863 -- to a payroll
2864 --
2865 CURSOR c_pay_id IS
2866 SELECT payroll_id
2867   FROM per_all_assignments_f
2868  WHERE p_effective_date between effective_start_date AND
2869                                 effective_end_date
2870    AND assignment_id = p_assignment_id
2871    AND payroll_id IS NOT NULL;
2872 
2873 BEGIN
2874 
2875 IF g_debug THEN
2876    Hr_Utility.set_location('Entering:   '||l_proc_name,10);
2877    Hr_Utility.set_location('...Assignment Id is : '||p_assignment_id,11);
2878    Hr_Utility.set_location('...Eff Dt is : '||p_effective_date,12);
2879 END IF;
2880 
2881 l_payroll_id := NULL;
2882 l_abp_ee_xst := 0;
2883 
2884 FOR temp_rec in c_pay_id LOOP
2885    l_payroll_id := temp_rec.payroll_id;
2886 END LOOP;
2887 
2888 IF g_debug THEN
2889    Hr_Utility.set_location('...Checking if EE is part of payroll ',20);
2890    Hr_Utility.set_location('...Payroll id is '||NVL(l_payroll_id,-1),25);
2891 END IF;
2892 
2893 IF l_payroll_id IS NULL THEN
2894 
2895    IF g_debug THEN
2896       Hr_Utility.set_location('...EE is not part of payroll ',30);
2897       Hr_Utility.set_location('Leaving:   '||l_proc_name,90);
2898    END IF;
2899 
2900    RETURN 0;
2901 ELSE
2902 
2903    IF g_debug THEN
2904       Hr_Utility.set_location('...EE is part of payroll ',40);
2905    END IF;
2906 
2907    OPEN c_abp_entry;
2908    FETCH c_abp_entry INTO l_abp_ee_xst;
2909 
2910    IF c_abp_entry%FOUND THEN
2911 
2912       IF g_debug THEN
2913          Hr_Utility.set_location('...ABP is processed ',50);
2914          Hr_Utility.set_location('Leaving:   '||l_proc_name,90);
2915       END IF;
2916 
2917       CLOSE c_abp_entry;
2918       RETURN 1;
2919 
2920    ELSE
2921 
2922       IF g_debug THEN
2923          Hr_Utility.set_location('...ABP is not processed ',50);
2924          Hr_Utility.set_location('Leaving:   '||l_proc_name,90);
2925       END IF;
2926 
2927       CLOSE c_abp_entry;
2928       RETURN 0;
2929 
2930    END IF;
2931 
2932 END IF;
2933 
2934 END Chk_ABP_Processed;
2935 
2936 FUNCTION Get_Min_Date (p_hire_term_dt IN DATE ,
2937                        p_derived_date IN DATE)
2938 RETURN DATE IS
2939 
2940 BEGIN
2941 
2942 IF TO_CHAR(p_hire_term_dt,'MM/YYYY') = TO_CHAR(p_derived_date,'MM/YYYY') THEN
2943    --
2944    -- EE was hired or terminated in the same month as we are trying to report.
2945    --
2946    RETURN p_hire_term_dt;
2947 ELSE
2948    --
2949    -- EE was hired or terminatred in a different month
2950    --
2951    RETURN p_derived_date;
2952 END IF;
2953 
2954 END Get_Min_Date;
2955 
2956 --
2957 -- Function to check if a given assignment is terminated in the prev year (
2958 -- with reference to the extract start date).This function is necessary to
2959 -- supress Record 08 and 09 for EE assignments that are terminated in the
2960 -- previous years. Can be an issue for Secondary assignments where the primary
2961 -- assignment is still valid for reporting.
2962 -- Returns TRUE if asg is terminated in the prev year.
2963 -- P1 Bug Reference     -- 5852097
2964 -- P1 SR/TAR Reference  -- 6120992.992
2965 --
2966 FUNCTION Chk_Asg_Term_Py (p_assignment_id IN NUMBER,
2967                           p_ext_st        IN DATE)
2968 RETURN BOOLEAN IS
2969 
2970 l_asg_term_dt   DATE;
2971 l_proc_name     VARCHAR2(150) := g_proc_name ||'Chk_Asg_Term_Py';
2972 --
2973 -- Cursor to fetch the termination date of a terminated or
2974 -- ended assignment.
2975 --
2976 CURSOR c_get_term_date IS
2977 SELECT MIN(effective_start_date) - 1 term_date
2978   FROM per_all_assignments_f asg
2979  WHERE assignment_id = p_assignment_id
2980    AND assignment_status_type_id IN (SELECT assignment_status_type_id
2981                                        FROM per_assignment_status_types
2982                                       WHERE per_system_status = 'TERM_ASSIGN'
2983                                         AND active_flag = 'Y')
2984  UNION
2985 --
2986 -- Get the dates for any ended assignments. Note that this is for sec
2987 -- assignments only.
2988 --
2989 SELECT MAX(effective_end_date)
2990   FROM per_all_assignments_f asg
2991  WHERE assignment_id    = p_assignment_id
2992    AND asg.primary_flag = 'N'
2993    AND NOT EXISTS( SELECT 1
2994                      FROM per_all_assignments_f  asg1
2995                     WHERE asg1.assignment_id = p_assignment_id
2996                       AND asg1.effective_start_date = asg.effective_end_date + 1
2997                       AND asg.assignment_id = asg1.assignment_id )
2998    AND NOT EXISTS( SELECT 1
2999                      FROM per_all_assignments_f  asg1
3000                     WHERE asg1.assignment_id = p_assignment_id
3001                       AND asg1.effective_start_date < asg.effective_start_date
3002                       AND asg.assignment_id = asg1.assignment_id
3003                       AND asg1.assignment_status_type_id IN (SELECT assignment_status_type_id
3004                                                                FROM per_assignment_status_types
3005                                                               WHERE per_system_status = 'TERM_ASSIGN'
3006                                                                 AND active_flag = 'Y'))
3007 ;
3008 
3009 
3010 BEGIN
3011 
3012 IF g_debug THEN
3013    Hr_Utility.set_location('Entering                : '||l_proc_name,10);
3014    Hr_Utility.set_location('...Assignment Id is     : '||p_assignment_id,11);
3015    Hr_Utility.set_location('...Value of p_ext_st is : '||p_ext_st,12);
3016 END IF;
3017 
3018 OPEN c_get_term_date;
3019 FETCH c_get_term_date INTO l_asg_term_dt;
3020 
3021 IF c_get_term_date%NOTFOUND THEN
3022 
3023    IF g_debug THEN
3024       Hr_Utility.set_location('...Termination Date Not found : ',13);
3025       Hr_Utility.set_location('Leaving:   '||l_proc_name,17);
3026    END IF;
3027 
3028    CLOSE c_get_term_date;
3029    RETURN FALSE;
3030 
3031 ELSE
3032 
3033    CLOSE c_get_term_date;
3034 
3035    IF g_debug THEN
3036       Hr_Utility.set_location('...Termination Date found : ',14);
3037    END IF;
3038 
3039    IF TO_NUMBER(TO_CHAR(NVL(l_asg_term_dt,p_ext_st),'YYYY')) <
3040       TO_NUMBER(TO_CHAR(p_ext_st,'YYYY')) THEN
3041       IF g_debug THEN
3042          Hr_Utility.set_location('...Condition met return TRUE : ',15);
3043          Hr_Utility.set_location('Leaving:   '||l_proc_name,18);
3044       END IF;
3045       RETURN TRUE;
3046    ELSE
3047       IF g_debug THEN
3048          Hr_Utility.set_location('...Condition not met return FALSE : ',16);
3049          Hr_Utility.set_location('Leaving:   '||l_proc_name,19);
3050       END IF;
3051       RETURN FALSE;
3052    END IF;
3053 
3054 END IF;
3055 
3056 END chk_asg_term_py;
3057 
3058 
3059 FUNCTION Chk_Subcat_Disp (p_code      IN VARCHAR2
3060                          ,p_dt_earned IN DATE )
3061 --
3062 -- Function to check if IPH and IPL are to be displayed.
3063 -- From 2007 onwards only retro amounts for 2006 OR contributions
3064 -- for late hires are to be displayed for IPH and L
3065 --
3066 RETURN BOOLEAN IS
3067 
3068 BEGIN
3069 
3070 IF p_code IN ('IH','IL') AND p_dt_earned > TO_DATE('12/31/2006','MM/DD/YYYY') THEN
3071    RETURN FALSE;
3072 ELSE
3073    RETURN TRUE;
3074 END IF;
3075 
3076 END chk_subcat_disp;
3077 
3078 -- =============================================================================
3079 -- Function Chk_Asg_late_hire to check if an EE assignment is a late hire.
3080 -- For ABP Pensions, an EE assignment is considered as late hire if the
3081 -- EE crosses tax years. For e.g. hired in 2006 but the first payroll is run
3082 -- in 2007. During payroll processing, late hire indicator is stored in a
3083 -- balance -- ABP Late Hire. If the YTD value of this balance is <> 0 then the
3084 -- EE assignment is considered as a late hire.
3085 -- RETURNS TRUE if EE asg is late hire.
3086 -- =============================================================================
3087 FUNCTION Chk_Asg_Late_Hire (p_assignment_id     IN NUMBER
3088                            ,p_business_group_id IN NUMBER)
3089 
3090 RETURN BOOLEAN IS
3091 
3092 l_late_hire_ind   NUMBER;
3093 l_def_bal_id      NUMBER;
3094 l_proc_name       VARCHAR2(150) := g_proc_name ||'Chk_Asg_Late_Hire';
3095 
3096 BEGIN
3097 
3098 IF g_debug THEN
3099    Hr_Utility.set_location('Entering:   '||l_proc_name,10);
3100    Hr_Utility.set_location('...Assignment Id is : '||p_assignment_id,11);
3101 END IF;
3102 
3103 l_late_hire_ind := 0;
3104 l_def_bal_id    := -1;
3105 
3106 OPEN csr_defined_bal (c_balance_name      => 'ABP Late Hire'
3107                      ,c_dimension_name    => 'Assignment Year To Date'
3108                      ,c_business_group_id => p_business_group_id);
3109 FETCH csr_defined_bal INTO l_def_bal_id;
3110 
3111 IF csr_defined_bal%NOTFOUND THEN
3112    l_def_bal_id := -1;
3113 END IF;
3114 
3115 CLOSE csr_defined_bal;
3116 
3117 IF g_debug THEN
3118    Hr_Utility.set_location('...l_def_bal_id is : '||l_def_bal_id,12);
3119 END IF;
3120 
3121 IF l_def_bal_id <> -1 THEN
3122 --
3123 -- Derive the late hire indicator value from the balance
3124 --
3125 l_late_hire_ind := pay_balance_pkg.get_value( p_assignment_id      => p_assignment_id
3126                                              ,p_defined_balance_id => l_def_bal_id
3127                                              ,p_virtual_date       => g_extract_params(p_business_group_id).extract_end_date);
3128 END IF;
3129 
3130 IF g_debug THEN
3131    Hr_Utility.set_location('...l_late_hire_ind is : '||l_late_hire_ind,13);
3132 END IF;
3133 
3134 IF l_late_hire_ind <> 0 THEN
3135    RETURN TRUE;
3136 ELSE
3137    RETURN FALSE;
3138 END IF;
3139 
3140 IF g_debug THEN
3141    Hr_Utility.set_location('Leaving:   '||l_proc_name,10);
3142 END IF;
3143 
3144 EXCEPTION
3145 WHEN OTHERS THEN
3146    IF g_debug THEN
3147       Hr_Utility.set_location(' Exception occured:   '||l_proc_name,10);
3148    END IF;
3149    RETURN FALSE;
3150 END Chk_Asg_Late_Hire;
3151 
3152 --
3153 -- Procedure to populate all the PL/SQL tables for records
3154 -- with multiple rows
3155 --
3156 PROCEDURE Populate_Record_Structures
3157          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
3158          ,p_effective_date     IN  DATE
3159          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
3160          ,p_error_message      OUT NOCOPY VARCHAR2 ) IS
3161 
3162 --
3163 -- Cursor to get the Assignment Run level dimension id
3164 --
3165 CURSOR csr_asg_dimId IS
3166 SELECT balance_dimension_id
3167   FROM pay_balance_dimensions
3168  WHERE legislation_code = 'NL'
3169    AND database_item_suffix = '_ASG_RUN';
3170 
3171    -- Cursor to check if there is a change in hire date
3172    -- the change may be in the future or in the past
3173    -- with or without payroll runs
3174    CURSOR c_hire_dt_chg(c_person_id  IN NUMBER
3175                        ,c_start_date IN DATE
3176                        ,c_end_date   IN DATE) IS
3177    SELECT old_val1 old_date,
3178           new_val1 new_date
3179      FROM ben_ext_chg_evt_log
3180    WHERE  person_id = c_person_id
3181      AND  chg_evt_cd = 'COPOS'
3182      AND  fnd_date.canonical_to_date(prmtr_09) BETWEEN c_start_date AND c_end_date
3183    ORDER BY ext_chg_evt_log_id desc;
3184 
3185 CURSOR c_ptp_log_rows (c_start_date IN DATE
3186                       ,c_end_date   IN DATE
3187                       ,c_asg_st_dt  IN DATE
3188                       ,c_asg_ed_dt  IN DATE )IS
3189 SELECT assignment_id
3190       ,effective_start_date start_date
3191       ,effective_end_date end_date
3192       ,fnd_number.canonical_to_number(new_val1) ptp
3193   FROM per_all_assignments_f asg,
3194        ben_ext_chg_evt_log log
3195       ,per_assignment_status_types past
3196       ,hr_soft_coding_keyflex sck
3197  WHERE asg.assignment_id  = p_assignment_id
3198    AND asg.assignment_status_type_id = past.assignment_status_type_id
3199    AND sck.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
3200    AND past.per_system_status = 'ACTIVE_ASSIGN'
3201    AND log.person_id      = g_person_id
3202    AND log.chg_evt_cd     = 'COPTP'
3203    AND fnd_date.canonical_to_date(log.prmtr_09)
3204        BETWEEN c_start_date AND c_end_date
3205    AND asg.effective_start_date between c_asg_st_dt AND c_asg_ed_dt
3206    AND asg.soft_coding_keyflex_id = log.prmtr_02
3207    AND asg.assignment_id          = log.prmtr_01
3208    AND fnd_number.canonical_to_number(new_val1) =
3209        fnd_number.canonical_to_number(sck.segment29)
3210 order by effective_start_date;
3211 
3212 l_ptp_log_rows c_ptp_log_rows%ROWTYPE;
3213 
3214 CURSOR c_prior_hourly_ee_ptp
3215        (c_asg_id         IN NUMBER
3216        ,c_effective_date IN DATE
3217        ,c_orig_st_date   IN DATE
3218        ,c_orig_ed_date   IN DATE
3219        ,c_ele_type_id    IN NUMBER
3220        ,c_input_val_id   IN NUMBER ) IS
3221 SELECT NVL(sum(round(fnd_number.canonical_to_number(peev.screen_entry_value),2)),0) prior_ptp
3222  FROM pay_element_entries_f       peef,
3223       pay_element_links_f         pelf,
3224       pay_element_entry_values_f  peev
3225 WHERE peef.effective_start_date < c_effective_date
3226   AND c_effective_date BETWEEN pelf.effective_start_date AND
3227                                pelf.effective_end_date
3228   AND peev.effective_start_date < c_effective_date
3229   AND peef.element_link_id  = pelf.element_link_id
3230   AND peev.element_entry_id = peef.element_entry_id
3231   AND pelf.element_type_id  = c_ele_type_id
3232   AND peev.input_value_id   = c_input_val_id
3233   AND peef.assignment_id    = c_asg_id
3234   AND peev.screen_entry_value IS NOT NULL
3235   AND pay_paywsmee_pkg.get_original_date_earned(peef.element_entry_id)
3236   BETWEEN c_orig_st_date AND c_orig_ed_date;
3237 
3238 CURSOR c_sent_to_abp (c_eff_dt IN DATE) IS
3239 SELECT 1
3240   FROM ben_ext_rslt res
3241  WHERE ext_dfn_id IN (SELECT ext_dfn_id
3242                         FROM pqp_extract_attributes
3243                        WHERE ext_dfn_type = 'NL_FPR')
3244    AND ext_stat_cd = 'A'
3245    AND EXISTS ( SELECT 1 FROM ben_ext_rslt_dtl dtl
3246                  WHERE dtl.ext_rslt_id = res.ext_rslt_id
3247                    AND dtl.person_id   = g_person_id)
3248    AND trunc(res.eff_dt) = trunc(c_eff_dt)
3249 ORDER BY ext_rslt_id DESC;
3250 
3251 CURSOR c_09_abp_data (c_eff_dt IN DATE
3252                      ,c_pt_code IN VARCHAR2) IS
3253 SELECT fnd_number.canonical_to_number(val_06)/100 basis
3254   FROM ben_ext_rslt_dtl     dtl
3255       ,ben_ext_rslt         res
3256       ,ben_ext_rcd          rcd
3257       ,ben_ext_rcd_in_file  rin
3258       ,ben_ext_dfn          dfn
3259 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
3260                            FROM pqp_extract_attributes
3261                           WHERE ext_dfn_type = 'NL_FPR')
3262  and dtl.person_id    = g_person_id
3263  and ext_stat_cd      = 'A'
3264  AND TRUNC(res.eff_dt)= trunc(c_eff_dt)
3265  AND rin.ext_file_id  = dfn.ext_file_id
3266  AND rin.ext_rcd_id   = rcd.ext_rcd_id
3267  AND dfn.ext_dfn_id   = res.ext_dfn_id
3268  and dtl.ext_rslt_id  = res.ext_rslt_id
3269  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
3270  AND rin.seq_num      = 8
3271  AND val_05           = c_pt_code
3272  ORDER BY res.ext_rslt_id desc;
3273 
3274 CURSOR c_09_poj_abp_data (c_eff_dt  IN DATE
3275                          ,c_poj_cd  IN VARCHAR2) IS
3276 SELECT fnd_number.canonical_to_number(val_06)/100 basis
3277       ,TRUNC(res.eff_dt) eff_dt
3278       , val_05 code
3279   FROM ben_ext_rslt_dtl     dtl
3280       ,ben_ext_rslt         res
3281       ,ben_ext_rcd          rcd
3282       ,ben_ext_rcd_in_file  rin
3283       ,ben_ext_dfn          dfn
3284 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
3285                            FROM pqp_extract_attributes
3286                           WHERE ext_dfn_type = 'NL_FPR')
3287  and dtl.person_id    = g_person_id
3288  and ext_stat_cd      = 'A'
3289  AND TRUNC(res.eff_dt)< trunc(c_eff_dt)
3290  AND rin.ext_file_id  = dfn.ext_file_id
3291  AND rin.ext_rcd_id   = rcd.ext_rcd_id
3292  AND dfn.ext_dfn_id   = res.ext_dfn_id
3293  and dtl.ext_rslt_id  = res.ext_rslt_id
3294  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
3295  AND rin.seq_num      = 8
3296  AND val_08           = '0000'
3297  AND val_09           = '00'
3298  AND val_10           <> c_poj_cd
3299  ORDER BY res.ext_rslt_id desc;
3300 
3301 CURSOR c_09_poj_cor_abp_data (c_eff_dt  IN DATE
3302                              ,c_poj_cd  IN VARCHAR2) IS
3303 SELECT 1
3304   FROM ben_ext_rslt_dtl     dtl
3305       ,ben_ext_rslt         res
3306       ,ben_ext_rcd          rcd
3307       ,ben_ext_rcd_in_file  rin
3308       ,ben_ext_dfn          dfn
3309 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
3310                            FROM pqp_extract_attributes
3311                           WHERE ext_dfn_type = 'NL_FPR')
3312  and dtl.person_id    = g_person_id
3313  and ext_stat_cd      = 'A'
3314  AND TRUNC(res.eff_dt)> TRUNC(c_eff_dt)
3315  AND rin.ext_file_id  = dfn.ext_file_id
3316  AND rin.ext_rcd_id   = rcd.ext_rcd_id
3317  AND dfn.ext_dfn_id   = res.ext_dfn_id
3318  and dtl.ext_rslt_id  = res.ext_rslt_id
3319  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
3320  AND rin.seq_num      = 8
3321  AND val_08           = to_char(TRUNC(c_eff_dt),'YYYY')
3322  AND val_09           = to_char(TRUNC(c_eff_dt),'MM')
3323  AND val_10           = c_poj_cd -- current_code
3324  ORDER BY res.ext_rslt_id desc;
3325 
3326 CURSOR c_12_abp_data (c_eff_dt IN DATE
3327                      ,c_code   IN VARCHAR2) IS
3328 SELECT fnd_number.canonical_to_number(val_06)/100 amount
3329   FROM ben_ext_rslt_dtl     dtl
3330       ,ben_ext_rslt         res
3331       ,ben_ext_rcd          rcd
3332       ,ben_ext_rcd_in_file  rin
3333       ,ben_ext_dfn          dfn
3334 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
3335                            FROM pqp_extract_attributes
3336                           WHERE ext_dfn_type = 'NL_FPR')
3337  and dtl.person_id    = g_person_id
3338  and ext_stat_cd      = 'A'
3339  AND TRUNC(res.eff_dt)= trunc(c_eff_dt)
3340  AND rin.ext_file_id  = dfn.ext_file_id
3341  AND rin.ext_rcd_id   = rcd.ext_rcd_id
3342  AND dfn.ext_dfn_id   = res.ext_dfn_id
3343  AND dtl.ext_rslt_id  = res.ext_rslt_id
3344  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
3345  AND rin.seq_num      = 10
3346  AND val_05           = c_code
3347  AND val_08           = '0000'
3348  AND val_09           = '00'
3349  ORDER BY res.ext_rslt_id desc;
3350 
3351 CURSOR c_12_retro_abp_data (c_year  IN VARCHAR2
3352                      ,c_mon   IN VARCHAR2
3353                      ,c_eff_dt IN DATE
3354                      ,c_code   IN VARCHAR2) IS
3355 SELECT fnd_number.canonical_to_number(val_06)/100 amount
3356   FROM ben_ext_rslt_dtl     dtl
3357       ,ben_ext_rslt         res
3358       ,ben_ext_rcd          rcd
3359       ,ben_ext_rcd_in_file  rin
3360       ,ben_ext_dfn          dfn
3361 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
3362                            FROM pqp_extract_attributes
3363                           WHERE ext_dfn_type = 'NL_FPR')
3364  and dtl.person_id    = g_person_id
3365  and ext_stat_cd      = 'A'
3366  AND TRUNC(res.eff_dt)>= trunc(c_eff_dt)
3367  AND rin.ext_file_id  = dfn.ext_file_id
3368  AND rin.ext_rcd_id   = rcd.ext_rcd_id
3369  AND dfn.ext_dfn_id   = res.ext_dfn_id
3370  AND dtl.ext_rslt_id  = res.ext_rslt_id
3371  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
3372  AND rin.seq_num      = 10
3373  AND val_05           = c_code
3374  AND val_08           = c_year
3375  AND val_09           = c_mon
3376  ORDER BY res.ext_rslt_id desc;
3377 
3378 CURSOR c_current_ptp_chgs (c_min_st_dt IN DATE ) IS
3379 SELECT asg.assignment_id
3380       ,effective_start_date start_date
3381       ,effective_end_date end_date
3382       ,least(fnd_number.canonical_to_number(nvl(sck.segment29,100)),125) ptp
3383   FROM per_all_assignments_f asg
3384       ,per_assignment_status_types past
3385       ,hr_soft_coding_keyflex sck
3386  WHERE asg.assignment_id  = p_assignment_id
3387    AND asg.assignment_status_type_id = past.assignment_status_type_id
3388    AND sck.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
3389    AND past.per_system_status = 'ACTIVE_ASSIGN'
3390    AND asg.effective_start_date BETWEEN
3391            g_extract_params(p_business_group_id).extract_start_date
3392        AND g_extract_params(p_business_group_id).extract_end_date
3393    AND asg.effective_start_date >= c_min_st_dt
3394    ORDER BY effective_start_date;
3395 
3396 
3397 CURSOR c_get_min_st_dt IS
3398 SELECT effective_start_date
3399   FROM per_all_assignments_f asg
3400       ,per_assignment_status_types past
3401       ,hr_soft_coding_keyflex sck
3402  WHERE asg.assignment_id  = p_assignment_id
3403    AND asg.assignment_status_type_id = past.assignment_status_type_id
3404    AND sck.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
3405    AND past.per_system_status = 'ACTIVE_ASSIGN'
3406    AND asg.effective_start_date BETWEEN
3407            g_extract_params(p_business_group_id).extract_start_date
3408        AND g_extract_params(p_business_group_id).extract_end_date
3409    AND EXISTS (SELECT 1
3410                  FROM per_all_assignments_f asg1
3411                      ,per_assignment_status_types past1
3412                      ,hr_soft_coding_keyflex sck1
3413                 WHERE asg1.assignment_id = p_assignment_id
3414                   AND asg1.effective_end_date = asg.effective_start_date - 1
3415                   AND asg1.assignment_status_type_id = past1.assignment_status_type_id
3416                   AND sck1.soft_coding_keyflex_id = asg1.soft_coding_keyflex_id
3417                   AND past1.per_system_status = 'ACTIVE_ASSIGN'
3418                   AND fnd_number.canonical_to_number(nvl(sck.segment29,'100'))
3419                    <> fnd_number.canonical_to_number(nvl(sck1.segment29,'100'))
3420                 )
3421    ORDER BY effective_start_date;
3422 
3423 CURSOR c_get_hire_dt IS
3424 SELECT MIN(effective_start_date) hire_date
3425   FROM per_all_assignments_f asg
3426  WHERE assignment_id = p_assignment_id
3427    AND assignment_status_type_id IN (SELECT assignment_status_type_id
3428                                        FROM per_assignment_status_types
3429                                       WHERE per_system_status = 'ACTIVE_ASSIGN'
3430                                         AND active_flag = 'Y')
3431    AND assignment_type = 'E';
3432 
3433 CURSOR c_get_term_dt IS
3434 SELECT MIN(effective_start_date) - 1 term_date
3435   FROM per_all_assignments_f asg
3436  WHERE assignment_id = p_assignment_id
3437    AND assignment_status_type_id IN (SELECT assignment_status_type_id
3438                                        FROM per_assignment_status_types
3439                                       WHERE per_system_status = 'TERM_ASSIGN'
3440                                         AND active_flag = 'Y')
3441    AND assignment_type = 'E';
3442 
3443    -- =========================================
3444    -- ~ Local variables
3445    -- =========================================
3446    l_cur_ptp_min_st_dt      DATE;
3447    l_get_fp_nh              NUMBER;
3448    l_rec_12_amt_sent_prev_r NUMBER;
3449    l_sent_to_abp            NUMBER;
3450    l_rej_hf_ee              NUMBER;
3451    i                        per_all_assignments_f.business_group_id%TYPE;
3452    l_ele_type_id            pay_element_types_f.element_type_id%TYPE;
3453    l_prev_ele_type_id       pay_element_types_f.element_type_id%TYPE;
3454    l_proc_name          VARCHAR2(150) := g_proc_name ||'Populate_Record_Structures';
3455    l_assig_rec          csr_assig%ROWTYPE;
3456    l_Chg_Evt_Exists     Varchar2(2);
3457    l_effective_date     Date;
3458    l_org_hierarchy      NUMBER;
3459    j                    NUMBER := 0;
3460    k                    NUMBER := 0;
3461    l_rr_exists          NUMBER := 0;
3462    l_retro_ptp_value    NUMBER(9,2);
3463    l_basis_amount       NUMBER(9,2);
3464    l_retro_vop_value    NUMBER(5,2);
3465    l_retro_siw_value    NUMBER(9,2);
3466    l_retro_sid_value    NUMBER(9,2);
3467    l_retro_sit_value    varchar2(4);
3468    l_retro_period_start date;
3469    l_retro_period_end   date;
3470    l_retro_date_earned  varchar2(11);
3471    l_asg_act_id         NUMBER;
3472    l_def_bal_id         NUMBER;
3473    l_amount             NUMBER;
3474    l_context_id         NUMBER;
3475    l_si_type            varchar2(4);
3476    l_code               NUMBER;
3477    l_date               date := hr_api.g_eot;
3478    l_new_start          date;
3479    l_old_start          date;
3480    l_new_start_can      ben_ext_chg_evt_log.new_val1%TYPE;
3481    l_old_start_can      ben_ext_chg_evt_log.old_val1%TYPE;
3482    l_beg_new_st         date;
3483    l_end_new_st         date;
3484 
3485    l_get_count_ptp_changes  NUMBER := 0;
3486    l_ee_age_at_retro        NUMBER;
3487    l_retro_age_cal_dt       DATE;
3488    l_reg_09_age             NUMBER;
3489    l_reg_09_age_cal_dt      DATE;
3490    l_retro_ptp_term_asg     NUMBER;
3491    l_retro_ptp_row          NUMBER;
3492    l_loop_end_date          DATE;
3493    l_09_basis_amt_sent_prev NUMBER;
3494    l_rec_12_amt_sent_prev   NUMBER;
3495    l_gzz_asg_act_xst        NUMBER;
3496    l_gxx_code               VARCHAR2(2);
3497    l_poj_ret_val            NUMBER;
3498    l_poj_cd                 VARCHAR2(1);
3499    l_09_poj_cor_abp_data    NUMBER;
3500    l_er_index               NUMBER:=0;
3501    l_grp_index              NUMBER:=0;
3502    l_tax_org_flag           VARCHAR2(1);
3503    l_reversal_term          NUMBER := 0;
3504    l_normal_term            NUMBER := 0;
3505    l_old_date1_xx           ben_ext_chg_evt_log.old_val1%TYPE;
3506    l_new_date1_xx           ben_ext_chg_evt_log.new_val1%TYPE;
3507    l_old_date2_xx           ben_ext_chg_evt_log.old_val1%TYPE;
3508    l_new_date2_xx           ben_ext_chg_evt_log.new_val1%TYPE;
3509    l_term_log_id_xx         ben_ext_chg_evt_log.ext_chg_evt_log_id%TYPE;
3510    l_revt_log_id_xx         ben_ext_chg_evt_log.ext_chg_evt_log_id%TYPE;
3511    l_term_pos_id_XX         NUMBER;
3512    l_org_index              NUMBER;
3513    l_fp_hire_dt             DATE;
3514    l_fp_new_hire            NUMBER := 0 ;
3515    l_cur_ptp                NUMBER;
3516    l_hourly_ee_avg_ptp      NUMBER;
3517    l_hourly_ee_avg_ptp_prev NUMBER;
3518    l_prior_hourly_ee_ptp    NUMBER;
3519    l_ret_val_asg            NUMBER;
3520    l_seq_num                VARCHAR2(2);
3521    l_asg_hire_dt            DATE;
3522    l_asg_term_dt            DATE;
3523    l_sent_ptp               NUMBER;
3524    l_sent_end_dt            DATE;
3525    l_sent_st_dt             DATE;
3526 
3527 BEGIN
3528 
3529     --
3530     -- Initialise the count variables to 0
3531     --
3532     g_index_05             := 0;
3533     g_count_05             := 0;
3534     g_si_index             := 0;
3535     g_si_count             := 0;
3536     g_retro_ptp_count      := 0;
3537     g_retro_si_ptp_count   := 0;
3538     g_retro_21_count       := 0;
3539     g_retro_21_index       := 0;
3540     g_retro_22_count       := 0;
3541     g_retro_22_index       := 0;
3542     l_rec_05_disp          := 'N';
3543     g_retro_ptp_count      := 0;
3544     i                      := p_business_group_id;
3545     l_cur_ptp              := -1;
3546     l_hourly_ee_avg_ptp    := 0;
3547     l_hourly_ee_avg_ptp_prev := 0;
3548     l_prior_hourly_ee_ptp  := 0;
3549     g_abp_processed_flag   := 0;
3550     g_new_hire_asg         := 0;
3551     g_hire_date            := NULL;
3552 
3553       --
3554       -- Check if ABP Pensions is processed for the EE assignment.
3555       -- Set global flag
3556       --
3557       g_abp_processed_flag := Chk_ABP_Processed
3558          (p_assignment_id      => p_assignment_id
3559          ,p_effective_date     => p_effective_date
3560          ,p_business_group_id  => p_business_group_id);
3561 
3562       --
3563       -- Check if the EE asg is a new hire
3564       --
3565         g_new_hire_asg := chk_new_hire_asg
3566     (p_person_id         => g_person_id
3567     ,p_assignment_id     => p_assignment_id
3568     ,p_business_group_id => p_business_group_id
3569     ,p_start_date        => g_extract_params(p_business_group_id).extract_start_date
3570     ,p_end_date          => g_extract_params(p_business_group_id).extract_end_date
3571     ,p_hire_date         => g_hire_date
3572     ,p_error_message     => p_error_message);
3573 
3574 
3575       -- Get Assignment Run dimension Id as we will be using for
3576       -- calculating the amount
3577       OPEN  csr_asg_dimId;
3578       FETCH csr_asg_dimId INTO g_asgrun_dim_id;
3579       CLOSE csr_asg_dimId;
3580 
3581 
3582        --
3583        -- Get the defined balance id for the ABP contribution
3584        -- of the previous year. This is necessary to reduce the
3585        -- SI Income reported in Rec 21 and 22
3586        FOR temp_rec IN csr_defined_bal
3587               (c_balance_name      => 'Retro ABP EE Contribution Previous Year'
3588               ,c_dimension_name    => 'Assignment Period To Date'
3589               ,c_business_group_id => p_business_group_id)
3590        LOOP
3591            l_pen_py_con_dbal_id := temp_rec.defined_balance_id;
3592        END LOOP;
3593        ---
3594        ---
3595        ---
3596        --fetch the element type id and the input value id
3597        --for the ABP part time percentage element
3598        OPEN c_get_retro_ele('ABP Pensions Part Time Percentage'
3599                                ,'Part Time Percentage');
3600        --6501898
3601        --FETCH c_get_retro_ele INTO l_abp_ptp_iv_id,l_abp_ptp_ele_id;
3602        FETCH c_get_retro_ele INTO g_abp_ptp_iv_id,g_abp_ptp_ele_id;
3603        CLOSE c_get_retro_ele;
3604 
3605        --fetch the element type id and the input value id
3606        --for the ABP retro part time percentage element
3607        OPEN c_get_retro_ele('Retro ABP Pensions Part Time Percentage'
3608                                ,'Part Time Percentage');
3609        FETCH c_get_retro_ele INTO g_retro_ptp_iv_id,g_retro_ptp_element_id;
3610        CLOSE c_get_retro_ele;
3611 
3612        OPEN c_get_retro_ele('Retro ABP Pensions Part Time Percentage'
3613                                ,'Value Of Participation');
3614        FETCH c_get_retro_ele INTO g_retro_vop_iv_id,g_retro_ptp_element_id;
3615        CLOSE c_get_retro_ele;
3616 
3617        OPEN c_get_retro_ele('Retro ABP Pensions Part Time Percentage'
3618                                ,'Part Time Percentage');
3619        FETCH c_get_retro_ele INTO g_retro_pv_iv_id,g_retro_ptp_element_id;
3620        CLOSE c_get_retro_ele;
3621 
3622        -- Populate the PLSQL table with the elment type ids for record 09
3623        -- this is required only once . These are the valid schemes for
3624        -- IP IH AP and OP
3625 
3626        l_rec_09.DELETE;
3627 
3628        FOR temp_rec IN c_rec_09_ele
3629         ( c_bg_id          => p_business_group_id
3630          ,c_effective_date => g_extract_params(i).extract_end_date ) LOOP
3631            -- Increment the counter
3632            l_09_counter := l_09_counter + 1;
3633            -- Get the defined balance id
3634            l_rec_09(l_09_counter) := temp_rec;
3635            FOR temp_rec1 IN csr_defined_bal
3636               (c_balance_name      => l_rec_09(l_09_counter).bal_name
3637               ,c_dimension_name    => 'Assignment Run'
3638               ,c_business_group_id => p_business_group_id)
3639            LOOP
3640               l_rec_09(l_09_counter).defined_bal_id :=
3641                                        temp_rec1.defined_balance_id;
3642            END LOOP;
3643        END LOOP;
3644 
3645        -- Populate the PLSQL table with the elment type ids for record 31
3646        -- this is required only once . These are the valid schemes for
3647        -- IPAP
3648 
3649        l_rec_31.DELETE;
3650 
3651        FOR temp_rec IN c_rec_31_ele
3652         ( c_bg_id          => p_business_group_id
3653          ,c_effective_date => g_extract_params(i).extract_end_date ) LOOP
3654            -- Increment the counter
3655            l_31_counter := l_31_counter + 1;
3656            -- Get the defined balance id
3657            l_rec_31(l_31_counter) := temp_rec;
3658            FOR temp_rec1 IN csr_defined_bal
3659               (c_balance_name      => l_rec_31(l_31_counter).bal_name
3660               ,c_dimension_name    => 'Assignment Run'
3661               ,c_business_group_id => p_business_group_id)
3662            LOOP
3663               l_rec_31(l_31_counter).defined_bal_id :=
3664                                        temp_rec1.defined_balance_id;
3665            END LOOP;
3666        END LOOP;
3667 
3668        -- Populate the PLSQL table with the elment type ids for record 41
3669        -- this is required only once . These are the valid schemes for
3670        -- FUR_S
3671 
3672        l_basis_rec_41.DELETE;
3673 
3674        FOR temp_rec IN c_basis_rec_41_ele
3675         ( c_bg_id          => p_business_group_id
3676          ,c_effective_date => g_extract_params(i).extract_end_date ) LOOP
3677            -- Increment the counter
3678            l_41_basis_counter := l_41_basis_counter + 1;
3679            -- Get the defined balance id
3680            l_basis_rec_41(l_41_basis_counter) := temp_rec;
3681            FOR temp_rec1 IN csr_defined_bal
3682               (c_balance_name      => l_basis_rec_41(l_41_basis_counter).bal_name
3683               ,c_dimension_name    => 'Assignment Run'
3684               ,c_business_group_id => p_business_group_id)
3685            LOOP
3686               l_basis_rec_41(l_41_basis_counter).defined_bal_id :=
3687                                        temp_rec1.defined_balance_id;
3688            END LOOP;
3689        END LOOP;
3690 
3691 
3692    -- check to see if there is a change in the hire date for the
3693    -- person being processed. These have to be reported to ABP
3694    -- these are persons whose hire date has been updated to a date earlier
3695    -- than the current hire date or to a date in the future
3696    l_new_start := NULL;
3697    l_old_start := NULL;
3698 
3699    OPEN c_hire_dt_chg(c_person_id  => g_person_id
3700                      ,c_start_date => g_extract_params(i).extract_start_date
3701                      ,c_end_date   => g_extract_params(i).extract_end_date);
3702    FETCH c_hire_dt_chg INTO l_old_start_can,l_new_start_can;
3703    IF c_hire_dt_chg%NOTFOUND THEN
3704       l_new_start := NULL;
3705       l_old_start := NULL;
3706    ELSIF c_hire_dt_chg%FOUND THEN
3707       l_new_start := to_nl_date(l_new_start_can,'DD-MM-RRRR');
3708       l_old_start := to_nl_date(l_old_start_can,'DD-MM-RRRR');
3709    END IF;
3710    CLOSE c_hire_dt_chg;
3711 
3712     --If person is not retro hired then g_retro_hires record is null
3713     Hr_Utility.set_location('c_start_date'||g_extract_params(i).extract_start_date, 15);
3714     Hr_Utility.set_location('c_end_date'||g_extract_params(i).extract_end_date, 15);
3715     Hr_Utility.set_location('l_new_start'||l_new_start, 15);
3716     Hr_Utility.set_location('l_old_date'||l_old_start, 15);
3717 
3718 -- ============================================================================
3719 -- BEGIN Populate Record 05 Retro PTP change information
3720 -- ============================================================================
3721 -- Derive the current ptp to check if the EE is
3722 -- Hourly or a regular EE
3723 --
3724 FOR cur_ptp_rec IN c_cur_ptp(p_effective_date,p_assignment_id) LOOP
3725    l_cur_ptp := cur_ptp_rec.ptp;
3726 END LOOP;
3727 
3728 --
3729 -- Derive the hire and termination dates
3730 --
3731  OPEN c_get_hire_dt;
3732 FETCH c_get_hire_dt INTO l_asg_hire_dt;
3733 CLOSE c_get_hire_dt;
3734 
3735  OPEN c_get_term_dt;
3736 FETCH c_get_term_dt INTO l_asg_term_dt;
3737   IF c_get_term_dt%NOTFOUND THEN
3738      l_asg_term_dt := NULL;
3739   END IF;
3740 CLOSE c_get_term_dt;
3741 
3742 OPEN c_ptp_chg_exist (c_asg_id         => p_assignment_id
3743                      ,c_effective_date => g_extract_params(i).extract_start_date
3744                      ,c_ele_type_id    => g_retro_ptp_element_id
3745                      ,c_input_val_id   => g_retro_pv_iv_id);
3746 FETCH c_ptp_chg_exist INTO l_ptp_chg_exist;
3747 
3748 IF c_ptp_chg_exist%FOUND THEN
3749 
3750 
3751    IF l_cur_ptp <> 0 THEN -- Regular EE
3752 
3753    FOR retro_rec_05_period IN c_get_retro_ptp(c_asg_id   => p_assignment_id
3754                              ,c_effective_date => g_extract_params(i).extract_start_date
3755                              ,c_ele_type_id    => g_retro_ptp_element_id
3756                              ,c_input_val_id   => g_retro_pv_iv_id)
3757    LOOP
3758    --
3759    -- Part time percentage changes exist as retro entries have been created
3760    --
3761 
3762    OPEN c_ptp_log_rows(g_extract_params(i).extract_start_date,
3763                        g_extract_params(i).extract_end_date
3764                        ,retro_rec_05_period.start_date
3765                        ,retro_rec_05_period.end_date);
3766     --
3767     -- For regular EE get the data from the log rows
3768     --
3769     LOOP
3770        FETCH c_ptp_log_rows INTO l_ptp_log_rows;
3771 
3772        EXIT WHEN c_ptp_log_rows%NOTFOUND;
3773        hr_utility.set_location('....Inside the loop',20);
3774        IF g_retro_ptp_count > 0 THEN
3775             --
3776             -- Check if the ptp is the same and the dates are continuous
3777             --
3778             IF ( trunc(l_rec_05_retro_ptp(g_retro_ptp_count).end_date) + 1 =
3779                  trunc(l_ptp_log_rows.start_date) AND
3780                  l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc =
3781                  l_ptp_log_rows.ptp * 100 ) THEN
3782                l_rec_05_retro_ptp(g_retro_ptp_count).end_date       := l_ptp_log_rows.end_date;
3783                hr_utility.set_location('...Updated the date',20);
3784             ELSE
3785                g_retro_ptp_count := g_retro_ptp_count + 1;
3786                l_rec_05_retro_ptp(g_retro_ptp_count).start_date     := l_ptp_log_rows.start_date;
3787                l_rec_05_retro_ptp(g_retro_ptp_count).end_date       := l_ptp_log_rows.end_date;
3788                l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc := l_ptp_log_rows.ptp * 100;
3789             END IF;
3790          ELSIF g_retro_ptp_count = 0 THEN
3791             g_retro_ptp_count := g_retro_ptp_count + 1;
3792             l_rec_05_retro_ptp(g_retro_ptp_count).start_date     := l_ptp_log_rows.start_date;
3793             l_rec_05_retro_ptp(g_retro_ptp_count).end_date       := l_ptp_log_rows.end_date;
3794             l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc := l_ptp_log_rows.ptp * 100;
3795          END IF;
3796           hr_utility.set_location('...start_date'||l_rec_05_retro_ptp(g_retro_ptp_count).start_date,20);
3797           hr_utility.set_location('...end_date'||l_rec_05_retro_ptp(g_retro_ptp_count).end_date,20);
3798 
3799       END LOOP;
3800       CLOSE c_ptp_log_rows;
3801 
3802       END LOOP;
3803 
3804     ELSIF l_cur_ptp = 0 THEN -- Hourly EE
3805 
3806       FOR retro_rec_05 IN c_get_retro_ptp(c_asg_id   => p_assignment_id
3807                               ,c_effective_date => g_extract_params(i).extract_start_date
3808                               ,c_ele_type_id    => g_retro_ptp_element_id
3809                               ,c_input_val_id   => g_retro_pv_iv_id)
3810       LOOP
3811             hr_utility.set_location(' -- Inside the loop to fetch retro elements',-999);
3812             l_hourly_ee_avg_ptp_prev := 0;
3813             g_retro_ptp_count := g_retro_ptp_count + 1;
3814             l_rec_05_retro_ptp(g_retro_ptp_count).start_date
3815                  := get_min_date(l_asg_hire_dt,retro_rec_05.start_date);
3816             IF l_asg_term_dt IS NOT NULL THEN
3817                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
3818                     := get_min_date(l_asg_term_dt - 1,(retro_rec_05.end_date - 1));
3819             ELSE
3820                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
3821                     := retro_rec_05.end_date - 1;
3822             END IF;
3823 
3824             /*l_hourly_ee_avg_ptp_prev := Get_Balance_Value_Eff_Dt
3825               (p_assignment_id       => p_assignment_id
3826               ,p_business_group_id   => p_business_group_id
3827               ,p_balance_name        => 'ABP Average Part Time Percentage'
3828               ,p_error_message       => p_error_message
3829               ,p_start_date          => retro_rec_05.start_date
3830               ,p_end_date            => retro_rec_05.end_date);
3831 
3832             l_hourly_ee_avg_ptp_prev := round(NVL(l_hourly_ee_avg_ptp_prev,0),2); */
3833 
3834 
3835             --
3836             -- Derive the retro hourly ptp reported earlier to ABP
3837             --
3838             l_prior_hourly_ee_ptp := 0;
3839 
3840             OPEN c_prior_hourly_ee_ptp
3841                       (c_asg_id         => p_assignment_id
3842                       ,c_effective_date => g_extract_params(i).extract_start_date
3843                       ,c_orig_st_date   => retro_rec_05.start_date
3844                       ,c_orig_ed_date   => retro_rec_05.end_date
3845                       ,c_ele_type_id    => g_retro_ptp_element_id
3846                       ,c_input_val_id   => g_retro_pv_iv_id);
3847             FETCH c_prior_hourly_ee_ptp INTO l_prior_hourly_ee_ptp;
3848             CLOSE c_prior_hourly_ee_ptp;
3849 
3850             l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc :=
3851                 (retro_rec_05.ptp +
3852                  l_hourly_ee_avg_ptp_prev +
3853                  l_prior_hourly_ee_ptp) * 100;
3854 
3855 --7361997 If condition Added
3856 	IF (LEAST(retro_rec_05.end_date,nvl(l_asg_term_dt,retro_rec_05.end_date)) - GREATEST(l_asg_hire_dt,retro_rec_05.start_date)+1) > 0
3857 	THEN
3858 --Bug# 5973446
3859 		l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc :=
3860 		l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc *
3861 		(
3862 		((retro_rec_05.end_date - retro_rec_05.start_date)+1)
3863 		/
3864 		(LEAST(retro_rec_05.end_date,nvl(l_asg_term_dt,retro_rec_05.end_date)) -
3865 		 GREATEST(l_asg_hire_dt,retro_rec_05.start_date)+1)
3866 		);
3867 --Bug# 5973446
3868 	END IF;	--7361997
3869 
3870 	--7361970
3871 	l_rec_05_retro_ptp(g_retro_ptp_count).end_date := l_rec_05_retro_ptp(g_retro_ptp_count).end_date + 1;
3872 	--7361970
3873 		hr_utility.set_location(' -- Done populating PLSQL tbl',-999);
3874       END LOOP;
3875 
3876   END IF; -- Check for regular or hourly EE's
3877 
3878 END IF;
3879 
3880 CLOSE c_ptp_chg_exist;
3881 
3882 --6501898
3883 IF l_cur_ptp = 0 THEN
3884 hr_utility.set_location(' -- Inside the l_cur_ptp = 0',-999);
3885 
3886 OPEN c_ptp_chg_hrly_exist (c_asg_id         => p_assignment_id
3887                      ,c_effective_date => g_extract_params(i).extract_start_date
3888                      ,c_ele_type_id    => g_abp_ptp_ele_id
3889                      ,c_input_val_id   => g_abp_ptp_iv_id);
3890 
3891 FETCH c_ptp_chg_hrly_exist INTO l_ptp_chg_hrly_exist;
3892 CLOSE c_ptp_chg_hrly_exist;
3893 
3894 IF l_ptp_chg_hrly_exist.Yes = 'Y' THEN
3895 hr_utility.set_location(' -- Inside the if condition c_ptp_chg_hrly_exist FOUND ',-999);
3896 
3897       FOR non_retro_rec_05 IN c_ptp_chg_hrly_exist(c_asg_id   => p_assignment_id
3898                               ,c_effective_date => g_extract_params(i).extract_start_date
3899                               ,c_ele_type_id    => g_abp_ptp_ele_id
3900                               ,c_input_val_id   => g_abp_ptp_iv_id)
3901       LOOP
3902             hr_utility.set_location(' -- Inside the loop to fetch non retro elements',-999);
3903             hr_utility.set_location(' -- g_retro_ptp_count Before'||g_retro_ptp_count,-999);
3904             hr_utility.set_location(' -- p_assignment_id'||p_assignment_id,-999);
3905             hr_utility.set_location(' -- g_extract_params(i).extract_start_date'||g_extract_params(i).extract_start_date,-999);
3906             hr_utility.set_location(' -- g_abp_ptp_ele_id:'||g_abp_ptp_ele_id||' g_abp_ptp_iv_id:'||g_abp_ptp_iv_id,-999);
3907 
3908             g_retro_ptp_count := g_retro_ptp_count + 1;
3909             l_rec_05_retro_ptp(g_retro_ptp_count).start_date
3910                  := get_min_date(l_asg_hire_dt,non_retro_rec_05.start_date);
3911             IF l_asg_term_dt IS NOT NULL THEN
3912                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
3913                     := get_min_date(l_asg_term_dt - 1,(non_retro_rec_05.end_date - 1));
3914             ELSE
3915                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
3916                     := non_retro_rec_05.end_date - 1;
3917             END IF;
3918 
3919             hr_utility.set_location(' -- g_retro_ptp_count After'||g_retro_ptp_count,-999);
3920 
3921 
3922 /*
3923             --
3924             -- Derive the retro hourly ptp reported earlier to ABP
3925             --
3926             l_prior_hourly_ee_ptp := 0;
3927 
3928             OPEN c_prior_hourly_ee_ptp
3929                       (c_asg_id         => p_assignment_id
3930                       ,c_effective_date => g_extract_params(i).extract_start_date
3931                       ,c_orig_st_date   => retro_rec_05.start_date
3932                       ,c_orig_ed_date   => retro_rec_05.end_date
3933                       ,c_ele_type_id    => g_retro_ptp_element_id
3934                       ,c_input_val_id   => g_retro_pv_iv_id);
3935             FETCH c_prior_hourly_ee_ptp INTO l_prior_hourly_ee_ptp;
3936             CLOSE c_prior_hourly_ee_ptp;
3937 
3938             l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc :=
3939                 (retro_rec_05.ptp +
3940                  l_hourly_ee_avg_ptp_prev +
3941                  l_prior_hourly_ee_ptp) * 100;
3942 */
3943         l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc :=
3944         non_retro_rec_05.ptp * 100;
3945 
3946 --7361997 If condition Added
3947 	IF (LEAST(non_retro_rec_05.end_date,nvl(l_asg_term_dt,non_retro_rec_05.end_date)) - GREATEST(l_asg_hire_dt,non_retro_rec_05.start_date)+1) > 0
3948 	THEN
3949 --Bug# 5973446
3950 		l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc :=
3951 		l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc *
3952 		(
3953 		((non_retro_rec_05.end_date - non_retro_rec_05.start_date)+1)
3954 		/
3955 		(LEAST(non_retro_rec_05.end_date,nvl(l_asg_term_dt,non_retro_rec_05.end_date)) -
3956 		 GREATEST(l_asg_hire_dt,non_retro_rec_05.start_date)+1)
3957 		);
3958 --Bug# 5973446
3959 	END IF;	--7361997
3960 
3961 	--7361970
3962 	l_rec_05_retro_ptp(g_retro_ptp_count).end_date := l_rec_05_retro_ptp(g_retro_ptp_count).end_date + 1;
3963 	--7361970
3964 		hr_utility.set_location(' -- Done populating PLSQL tbl for non retro late hire',-999);
3965       END LOOP;
3966 
3967 END IF;
3968 --
3969 
3970 END IF;
3971 
3972 --6501898
3973 
3974 l_fp_new_hire := g_new_hire_asg;
3975 l_fp_hire_dt  := g_hire_date;
3976 
3977 
3978 IF l_fp_new_hire = 0 AND l_cur_ptp <> 0 THEN
3979 
3980 --
3981 -- Report part time percentage changes of the current period
3982 -- from the change event logs. Note that this is not the same
3983 -- period as the new hire. Not applicable for hourly EEs
3984 --
3985 
3986 OPEN c_get_min_st_dt;
3987 
3988 FETCH c_get_min_st_dt INTO l_cur_ptp_min_st_dt;
3989 
3990 IF c_get_min_st_dt%FOUND THEN
3991 
3992 
3993    OPEN c_current_ptp_chgs (l_cur_ptp_min_st_dt);
3994     --
3995     -- Get the data from the log rows
3996     --
3997     LOOP
3998        FETCH c_current_ptp_chgs INTO l_ptp_log_rows;
3999 
4000        EXIT WHEN c_current_ptp_chgs%NOTFOUND;
4001        hr_utility.set_location('....Inside the loop',20);
4002        IF g_retro_ptp_count > 0 THEN
4003             --
4004             -- Check if the ptp is the same and the dates are continuous
4005             --
4006             IF ( trunc(l_rec_05_retro_ptp(g_retro_ptp_count).end_date) + 1 =
4007                  trunc(l_ptp_log_rows.start_date) AND
4008                  l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc =
4009                  l_ptp_log_rows.ptp * 100 ) THEN
4010                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
4011                                := l_ptp_log_rows.end_date;
4012                hr_utility.set_location('...Updated the date',20);
4013             ELSE
4014                g_retro_ptp_count := g_retro_ptp_count + 1;
4015                l_rec_05_retro_ptp(g_retro_ptp_count).start_date
4016                              := l_ptp_log_rows.start_date;
4017                l_rec_05_retro_ptp(g_retro_ptp_count).end_date
4018                              := l_ptp_log_rows.end_date;
4019                l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc
4020                              := l_ptp_log_rows.ptp * 100;
4021             END IF;
4022          ELSIF g_retro_ptp_count = 0 THEN
4023             g_retro_ptp_count := g_retro_ptp_count + 1;
4024             l_rec_05_retro_ptp(g_retro_ptp_count).start_date
4025                              := l_ptp_log_rows.start_date;
4026             l_rec_05_retro_ptp(g_retro_ptp_count).end_date
4027                              := l_ptp_log_rows.end_date;
4028             l_rec_05_retro_ptp(g_retro_ptp_count).part_time_perc
4029                              := l_ptp_log_rows.ptp * 100;
4030          END IF;
4031           hr_utility.set_location('...start_date'
4032                        ||l_rec_05_retro_ptp(g_retro_ptp_count).start_date,20);
4033           hr_utility.set_location('...end_date'
4034                        ||l_rec_05_retro_ptp(g_retro_ptp_count).end_date,20);
4035 
4036       END LOOP;
4037       CLOSE c_current_ptp_chgs;
4038   END IF;
4039 CLOSE c_get_min_st_dt;
4040 
4041 END IF;
4042 
4043 -- ============================================================================
4044 -- END Populate Record 05 Retro PTP change information
4045 -- ============================================================================
4046 
4047 -- ============================================================================
4048 -- BEGIN Populate Record 09 details for Cur period,retro prev yr and cur yr
4049 -- ============================================================================
4050 IF l_rec_09.count > 0 THEN
4051    k := 1;
4052    FOR i IN l_rec_09.FIRST..l_rec_09.LAST
4053    LOOP
4054       l_rr_exists    := 0;
4055       hr_utility.set_location('...Current element : '
4056                    ||l_rec_09(i).element_type_id,10);
4057       hr_utility.set_location('..Assignment Id : '||p_assignment_id,12);
4058       hr_utility.set_location('..Payroll id : '
4059                    ||g_extract_params(p_business_group_id).payroll_id,13);
4060       hr_utility.set_location('..Start date : '
4061                    ||g_extract_params(p_business_group_id).extract_start_date,14);
4062       hr_utility.set_location('..End date :  '
4063                    ||g_extract_params(p_business_group_id).extract_end_date,15);
4064 
4065       FOR act_rec IN  csr_asg_act (
4066           c_assignment_id => p_assignment_id
4067          ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4068          ,c_con_set_id    => NULL
4069          ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
4070          ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date)
4071      LOOP
4072          hr_utility.set_location('..Asg act id : '||act_rec.assignment_action_id,20);
4073          --
4074          -- populate the PLSQL table with the retro basis entries
4075          -- and the start and end date of the corresponding retro paid period
4076          -- for ABP (record 09)
4077          --
4078          -- Previous Year Retro
4079          --
4080           FOR temp_rec IN c_get_retro_entry
4081              (c_element_type_id =>
4082                fnd_number.canonical_to_number(l_rec_09(i).py_retro_element_id)
4083              ,c_assignment_action_id => act_rec.assignment_action_id)
4084           LOOP
4085              hr_utility.set_location('..Found previous year retro entries',30);
4086              --
4087              -- Fetch the input value id for ABP Employee Pension Basis input value
4088              --
4089              OPEN c_get_iv_id(c_element_type_id =>
4090                      fnd_number.canonical_to_number(l_rec_09(i).py_retro_element_id));
4091              FETCH c_get_iv_id INTO l_basis_iv_id;
4092              CLOSE c_get_iv_id;
4093 
4094              --
4095              --fetch the pension basis retro value for this current
4096              --element entry id
4097              --
4098              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4099                                        ,c_input_value_id   => l_basis_iv_id);
4100              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4101              CLOSE c_get_retro_num_value;
4102 
4103    l_retro_age_cal_dt :=
4104                 fnd_date.canonical_to_date(substr(substr(
4105                          fnd_date.date_to_canonical(
4106                          pay_paywsmee_pkg.get_original_date_earned(
4107                          temp_rec.element_entry_id)),1,10),1,8)||'01');
4108 
4109 
4110              IF l_retro_ptp_value <> 0 AND chk_subcat_disp (l_rec_09(i).code
4111                                                ,l_retro_age_cal_dt) THEN
4112                 l_rec_09_values(k).basis_amount := l_retro_ptp_value;
4113                 l_rec_09_disp := 'Y';
4114                 l_rec_09_values(k).processed := 'N';
4115                 l_rec_09_values(k).code := l_rec_09(i).code;
4116                 l_rec_09_values(k).date_earned := ' ';
4117 
4118                 IF l_rec_09_values(k).basis_amount < 0 THEN
4119                    l_rec_09_values(k).sign_code := 'C';
4120                 END IF;
4121 
4122                 k := k + 1;
4123 
4124              END IF;
4125 
4126           END LOOP;
4127 
4128          --
4129          -- Current Year Retro
4130          --
4131          FOR temp_rec IN c_get_retro_entry
4132               (c_element_type_id => fnd_number.canonical_to_number(
4133                                     l_rec_09(i).cy_retro_element_id)
4134                ,c_assignment_action_id => act_rec.assignment_action_id)
4135          LOOP
4136             hr_utility.set_location('...Found current year retro entries',30);
4137             --
4138             -- Fetch the input value id for ABP Employee Pension Basis input value
4139             --
4140             OPEN c_get_iv_id(c_element_type_id =>
4141                    fnd_number.canonical_to_number(l_rec_09(i).cy_retro_element_id));
4142             FETCH c_get_iv_id INTO l_basis_iv_id;
4143             CLOSE c_get_iv_id;
4144 
4145              --
4146              -- Fetch the pension basis retro value for this current
4147              -- element entry id
4148              --
4149              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4150                                        ,c_input_value_id   => l_basis_iv_id);
4151              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4152              CLOSE c_get_retro_num_value;
4153 
4154 
4155              l_retro_age_cal_dt :=
4156                 fnd_date.canonical_to_date(substr(substr(
4157                          fnd_date.date_to_canonical(
4158                          pay_paywsmee_pkg.get_original_date_earned(
4159                          temp_rec.element_entry_id)),1,10),1,8)||'01');
4160 
4161              l_ee_age_at_retro := Get_Age(
4162                     p_assignment_id
4163                    ,trunc(l_retro_age_cal_dt)) ;
4164 
4165              hr_utility.set_location('...l_retro_age_cal_dt :'||l_retro_age_cal_dt,50);
4166              hr_utility.set_location('...l_ee_age_at_retro :'||l_ee_age_at_retro,50);
4167 
4168              IF l_ee_age_at_retro < 65 AND chk_subcat_disp (l_rec_09(i).code
4169                                                ,l_retro_age_cal_dt) THEN
4170              IF l_retro_ptp_value <> 0 THEN
4171                 l_rec_09_values(k).basis_amount := l_retro_ptp_value;
4172                 l_rec_09_disp := 'Y';
4173                 l_rec_09_values(k).processed := 'N';
4174                 l_rec_09_values(k).code := l_rec_09(i).code;
4175                 l_rec_09_values(k).date_earned := ' ';
4176 
4177                 hr_utility.set_location('GAA-- Date Earned used :'
4178                                         ||l_rec_09_values(k).date_earned,50);
4179 
4180                 IF l_rec_09_values(k).basis_amount < 0 THEN
4181                    l_rec_09_values(k).sign_code := 'C';
4182                 END IF;
4183 
4184                 k := k + 1;
4185 
4186              END IF;
4187 
4188             END IF; -- AGe
4189 
4190           END LOOP;
4191 
4192          --
4193          -- Adjustment Retro Entries
4194          --
4195          FOR temp_rec IN c_get_retro_entry
4196               (c_element_type_id =>  l_rec_09(i).py_cy_adj_retro_element_id
4197                ,c_assignment_action_id => act_rec.assignment_action_id)
4198          LOOP
4199             hr_utility.set_location('...Found Adjustment retro entries',30);
4200             --
4201             -- Fetch the input value id for ABP Employee Pension Basis input value
4202             --
4203             OPEN c_get_iv_id(c_element_type_id => l_rec_09(i).py_cy_adj_retro_element_id);
4204             FETCH c_get_iv_id INTO l_basis_iv_id;
4205             CLOSE c_get_iv_id;
4206 
4207              --
4208              -- Fetch the pension basis retro value for this current
4209              -- element entry id
4210              --
4211              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4212                                        ,c_input_value_id   => l_basis_iv_id);
4213              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4214              CLOSE c_get_retro_num_value;
4215 
4216 
4217              l_retro_age_cal_dt :=
4218                 fnd_date.canonical_to_date(substr(substr(
4219                          fnd_date.date_to_canonical(
4220                          pay_paywsmee_pkg.get_original_date_earned(
4221                          temp_rec.element_entry_id)),1,10),1,8)||'01');
4222 
4223              l_ee_age_at_retro := Get_Age(
4224                     p_assignment_id
4225                    ,trunc(l_retro_age_cal_dt)) ;
4226 
4227              hr_utility.set_location('...l_retro_age_cal_dt :'||l_retro_age_cal_dt,50);
4228              hr_utility.set_location('...l_ee_age_at_retro :'||l_ee_age_at_retro,50);
4229 
4230              IF l_ee_age_at_retro < 65 AND chk_subcat_disp (l_rec_09(i).code
4231                                                ,l_retro_age_cal_dt) THEN
4232              IF l_retro_ptp_value <> 0 THEN
4233                 l_rec_09_values(k).basis_amount := l_retro_ptp_value;
4234                 l_rec_09_disp := 'Y';
4235                 l_rec_09_values(k).processed := 'N';
4236                 l_rec_09_values(k).code := l_rec_09(i).code;
4237                 l_rec_09_values(k).date_earned := ' ';
4238 
4239                 hr_utility.set_location('GAA-- Date Earned used :'
4240                                         ||l_rec_09_values(k).date_earned,50);
4241 
4242                 IF l_rec_09_values(k).basis_amount < 0 THEN
4243                    l_rec_09_values(k).sign_code := 'C';
4244                 END IF;
4245 
4246                 k := k + 1;
4247 
4248              END IF;
4249 
4250             END IF; -- AGe
4251 
4252           END LOOP;
4253 
4254          l_reg_09_age_cal_dt := fnd_date.canonical_to_date(
4255                                 substr(substr(fnd_date.date_to_canonical(
4256                                 act_rec.date_earned),1,10),1,8)||'01');
4257 
4258          l_reg_09_age := Get_Age(p_assignment_id
4259                                 ,trunc(l_reg_09_age_cal_dt)) ;
4260 
4261      IF l_reg_09_age < 65  AND chk_subcat_disp (l_rec_09(i).code
4262                                                ,l_reg_09_age_cal_dt) THEN
4263 
4264         IF NOT chk_asg_term_py (p_assignment_id => p_assignment_id
4265                  ,p_ext_st        => g_extract_params(p_business_group_id).extract_start_date) THEN
4266 
4267         --
4268         -- Check if Run Results exist for this element/ass act
4269         --
4270         IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
4271                         ,p_element_type_id => l_rec_09(i).element_type_id ) THEN
4272            -- Call pay_balance_pkg
4273            hr_utility.set_location('Run results exist for current period',40);
4274 
4275            IF l_rec_09(i).defined_bal_id <> -1 THEN
4276 
4277               l_rec_09_values(k).basis_amount :=
4278                 Pay_Balance_Pkg.get_value
4279                 (p_defined_balance_id   => l_rec_09(i).defined_bal_id
4280                 ,p_assignment_action_id => act_rec.assignment_action_id);
4281               hr_utility.set_location('Defined bal id used :'
4282                                  ||l_rec_09(i).defined_bal_id,50);
4283               l_rec_09_disp := 'Y';
4284               l_rec_09_values(k).processed := 'N';
4285               l_rec_09_values(k).code := l_rec_09(i).code;
4286               l_rec_09_values(k).date_earned := ' ';
4287 
4288               IF l_rec_09_values(k).basis_amount < 0 THEN
4289                  l_rec_09_values(k).sign_code := 'C';
4290               END IF;
4291               k := k + 1;
4292            END IF;--end of defined bal check
4293 
4294         END IF;-- End of rr check
4295         END IF; -- Check asg term in prev year
4296       END IF; -- Age check
4297 
4298     END LOOP; -- Asg Acts
4299   END LOOP; -- Elements
4300 END IF;
4301 
4302 -- ============================================================================
4303 -- END Populate Record 09 details for Cur period,retro prev yr and cur yr
4304 -- ============================================================================
4305 
4306 --
4307 -- Populate the Record 09 PL SQL table with values from the
4308 -- previous runs if there has been a change in hire date
4309 -- Marker GXX
4310 --
4311 IF l_old_start IS NOT NULL AND l_new_start IS NOT NULL THEN
4312 --
4313 -- Hire Date is changed to the past
4314 --
4315 IF trunc(l_new_start) < trunc(l_old_start) THEN
4316 --
4317 -- Derive the beginning date
4318 --
4319 l_beg_new_st := fnd_date.canonical_to_date(to_char(l_new_start,'YYYY/MM')||'/01');
4320 --
4321 -- If the beginnind date is less then the current extract start
4322 -- Loop through the assignment actions to derive contrib amounts
4323 -- of that period
4324 --
4325 WHILE trunc(l_beg_new_st) < trunc(g_extract_params(p_business_group_id).extract_start_date)
4326    LOOP
4327    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
4328    --
4329    -- If Data has been sent to ABP , so not send it again
4330    --
4331    OPEN c_sent_to_abp(l_end_new_st);
4332    FETCH c_sent_to_abp INTO l_sent_to_abp;
4333    IF c_sent_to_abp%NOTFOUND THEN
4334       IF l_rec_09.count > 0 THEN
4335          FOR i IN l_rec_09.FIRST..l_rec_09.LAST
4336             LOOP
4337                l_rr_exists    := 0;
4338                hr_utility.set_location('current element : '||l_rec_09(i).element_type_id,10);
4339                hr_utility.set_location('asg id : '||p_assignment_id,12);
4340                hr_utility.set_location('start date :  ',14);
4341                hr_utility.set_location('end date :  ',15);
4342                FOR act_rec IN  csr_asg_act (
4343                                c_assignment_id => p_assignment_id
4344                               ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4345                               ,c_con_set_id    => NULL
4346                               ,c_start_date    => l_beg_new_st
4347                               ,c_end_date      => l_end_new_st)
4348                LOOP
4349 
4350                       l_reg_09_age_cal_dt := l_beg_new_st;
4351                       l_reg_09_age := Get_Age(p_assignment_id,trunc(l_reg_09_age_cal_dt)) ;
4352 
4353                       IF l_reg_09_age < 65 THEN
4354                       -- Check if Run Results exist for this element/ass act
4355                          IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
4356                                          ,p_element_type_id => l_rec_09(i).element_type_id ) THEN
4357                             -- Call pay_balance_pkg
4358                             hr_utility.set_location('run results exist for current period',40);
4359                             IF l_rec_09(i).defined_bal_id <> -1 THEN
4360                                l_rec_09_values(k).basis_amount :=
4361                                Pay_Balance_Pkg.get_value
4362                                    (p_defined_balance_id   => l_rec_09(i).defined_bal_id
4363                                    ,p_assignment_action_id => act_rec.assignment_action_id);
4364                                hr_utility.set_location('defined bal id used :'||l_rec_09(i).defined_bal_id,50);
4365                                l_rec_09_disp := 'Y';
4366                                l_rec_09_values(k).processed := 'N';
4367                                l_rec_09_values(k).code := l_rec_09(i).code;
4368                                l_rec_09_values(k).date_earned := ' ';
4369 
4370                                IF l_rec_09_values(k).basis_amount < 0 THEN
4371                                   l_rec_09_values(k).sign_code := 'C';
4372                                END IF;
4373                                k := k + 1;
4374                             END IF;-- Defined bal check
4375                          END IF;-- RR exist check
4376                       END IF; -- Age check
4377                END LOOP; -- Ass acts
4378           END LOOP; -- All elements for Rec 09
4379       END IF; -- Record 09 elements exist
4380    END IF; -- Data not sent to ABP
4381    CLOSE c_sent_to_abp;
4382    l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
4383 END LOOP; -- Loop through the months
4384 
4385 ELSIF trunc(l_new_start) > trunc(l_old_start) THEN
4386 
4387 --
4388 -- Derive the beginning date
4389 --
4390 l_beg_new_st    := fnd_date.canonical_to_date(to_char(l_old_start,'YYYY/MM')||'/01');
4391 l_loop_end_date := add_months(fnd_date.canonical_to_date(to_char(l_new_start,'YYYY/MM')||'/01'),1) - 1;
4392 l_loop_end_date := LEAST ( g_extract_params(p_business_group_id).extract_start_date -1
4393                            ,l_loop_end_date);
4394 -- GZZ
4395 --
4396 --
4397 -- Loop through the dates to derive data to be reported to ABP
4398 -- this might include ony the differences of that period or the entire amount
4399 -- for the month
4400 --
4401 WHILE trunc(l_beg_new_st) < l_loop_end_date
4402    LOOP
4403    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
4404    l_gzz_asg_act_xst := 0;
4405 
4406       IF l_rec_09.count > 0 THEN
4407          FOR i IN l_rec_09.FIRST..l_rec_09.LAST
4408             LOOP
4409                l_rr_exists    := 0;
4410                hr_utility.set_location('current element : '||l_rec_09(i).element_type_id,10);
4411                hr_utility.set_location('asg id : '||p_assignment_id,12);
4412                hr_utility.set_location('start date :  ',14);
4413                hr_utility.set_location('end date :  ',15);
4414                FOR act_rec IN  csr_asg_act (
4415                                c_assignment_id => p_assignment_id
4416                               ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4417                               ,c_con_set_id    => NULL
4418                               ,c_start_date    => l_beg_new_st
4419                               ,c_end_date      => l_end_new_st)
4420                LOOP
4421 
4422                       l_reg_09_age_cal_dt := l_beg_new_st;
4423                       l_reg_09_age := Get_Age(p_assignment_id,trunc(l_reg_09_age_cal_dt)) ;
4424 
4425                       IF l_reg_09_age < 65 THEN
4426                       -- Check if Run Results exist for this element/ass act
4427                          IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
4428                                          ,p_element_type_id => l_rec_09(i).element_type_id ) THEN
4429                             -- Call pay_balance_pkg
4430                             hr_utility.set_location('run results exist for current period',40);
4431                             IF l_rec_09(i).defined_bal_id <> -1 THEN
4432                                l_rec_09_values(k).basis_amount :=
4433                                Pay_Balance_Pkg.get_value
4434                                    (p_defined_balance_id   => l_rec_09(i).defined_bal_id
4435                                    ,p_assignment_action_id => act_rec.assignment_action_id);
4436                                hr_utility.set_location('defined bal id used :'||l_rec_09(i).defined_bal_id,50);
4437                                l_rec_09_disp := 'Y';
4438                                l_rec_09_values(k).processed := 'N';
4439                                l_rec_09_values(k).code := l_rec_09(i).code;
4440                                l_rec_09_values(k).date_earned :=
4441                                substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
4442 
4443                                OPEN c_09_abp_data (l_end_new_st,l_rec_09(i).code);
4444                                FETCH c_09_abp_data INTO l_09_basis_amt_sent_prev;
4445                                  IF c_09_abp_data%FOUND THEN
4446                                    l_rec_09_values(k).basis_amount := l_rec_09_values(k).basis_amount
4447                                                                     - l_09_basis_amt_sent_prev;
4448                                  END IF;
4449                                CLOSE c_09_abp_data;
4450 
4451                                IF l_rec_09_values(k).basis_amount < 0 THEN
4452                                   l_rec_09_values(k).sign_code := 'C';
4453                                END IF;
4454                                l_gzz_asg_act_xst := 1;
4455                                k := k + 1;
4456                             END IF;-- Defined bal check
4457                          END IF;-- RR exist check
4458 
4459                       END IF; -- Age check
4460                END LOOP; -- Ass acts
4461           END LOOP; -- All elements for Rec 09
4462       END IF; -- Record 09 elements exist
4463 
4464 
4465 IF l_rec_09.count > 0 AND l_gzz_asg_act_xst = 0 THEN
4466   FOR i IN l_rec_09.FIRST..l_rec_09.LAST
4467   LOOP
4468     OPEN c_09_abp_data (l_end_new_st,l_rec_09(i).code);
4469     FETCH c_09_abp_data INTO l_09_basis_amt_sent_prev;
4470        IF c_09_abp_data%FOUND THEN
4471         l_rec_09_values(k).basis_amount := -1 * l_09_basis_amt_sent_prev;
4472         l_rec_09_disp := 'Y';
4473         l_rec_09_values(k).processed := 'N';
4474         l_rec_09_values(k).code := l_rec_09(i).code;
4475         l_rec_09_values(k).date_earned :=
4476          substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
4477         IF l_rec_09_values(k).basis_amount < 0 THEN
4478            l_rec_09_values(k).sign_code := 'C';
4479        END IF;
4480        k := k+ 1;
4481       END IF;
4482       CLOSE c_09_abp_data;
4483    END LOOP;
4484 END IF;
4485 
4486    l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
4487 
4488   END LOOP; -- Loop through the months
4489 
4490 END IF; -- new start date < old start dt
4491 
4492 END IF; -- dates are not null
4493 
4494 -- ======================================================================
4495 -- Begin Principle Objection Code Changes
4496 -- ======================================================================
4497 
4498 --
4499 -- get the current Princ Obj Code
4500 --
4501 l_poj_ret_val := Get_Pri_Obj_Cd_Cur(p_assignment_id
4502                                ,p_business_group_id
4503                                ,p_effective_date
4504                                ,p_error_message
4505                                ,l_poj_cd);
4506 
4507 -- Populate record 09 values for the
4508 -- months in which the princlple obj code is
4509 -- different from the current value
4510 
4511 FOR l_09_poj_rec IN c_09_poj_abp_data ( g_extract_params(p_business_group_id).extract_end_date
4512                                        ,l_poj_cd)
4513 LOOP
4514 
4515    --
4516    -- Check to see if the corrected data has been sent to ABP.
4517    --
4518    l_09_poj_cor_abp_data := -1;
4519 
4520    OPEN c_09_poj_cor_abp_data ( l_09_poj_rec.eff_dt
4521                                ,l_poj_cd);
4522    FETCH c_09_poj_cor_abp_data INTO l_09_poj_cor_abp_data;
4523    CLOSE c_09_poj_cor_abp_data;
4524 
4525    IF l_09_poj_cor_abp_data = -1 THEN
4526       --
4527       -- Debit entries
4528       --
4529       l_rec_09_values(k).basis_amount := l_09_poj_rec.basis;
4530       l_rec_09_disp                   := 'Y';
4531       l_rec_09_values(k).processed    := 'N';
4532       l_rec_09_values(k).code         := l_09_poj_rec.code;
4533       l_rec_09_values(k).date_earned  :=
4534       substr(fnd_date.date_to_canonical(l_09_poj_rec.eff_dt),1,10);
4535 
4536       IF l_rec_09_values(k).basis_amount < 0 THEN
4537          l_rec_09_values(k).sign_code := 'C';
4538       END IF;
4539       k := k+ 1;
4540 
4541       --
4542       -- Credit entries
4543       --
4544       l_rec_09_values(k).basis_amount := -1 * l_09_poj_rec.basis;
4545       l_rec_09_disp                   := 'Y';
4546       l_rec_09_values(k).processed    := 'N';
4547       l_rec_09_values(k).code         := l_09_poj_rec.code;
4548       l_rec_09_values(k).date_earned  :=
4549       substr(fnd_date.date_to_canonical(l_09_poj_rec.eff_dt),1,10);
4550 
4551       IF l_rec_09_values(k).basis_amount < 0 THEN
4552          l_rec_09_values(k).sign_code := 'C';
4553       END IF;
4554       l_rec_09_values(k).pobj_flag := 'N';
4555       k := k+ 1;
4556 
4557    END IF;
4558 
4559 END LOOP;
4560 
4561 -- ======================================================================
4562 -- End Principle Objection Code Changes
4563 -- ======================================================================
4564 
4565 
4566 /* code commented out by vjhanak. The value of k is getting reset.
4567   need to use a different variable for the index.
4568   -- Get the pension basis balance for record 31
4569   IF l_rec_31.count > 0 THEN
4570     k := 1;
4571     FOR i IN l_rec_31.FIRST..l_rec_31.LAST
4572     LOOP
4573        l_rr_exists    := 0;
4574        FOR act_rec IN  csr_asg_act (
4575                   c_assignment_id => p_assignment_id
4576                  ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4577                  ,c_con_set_id    => NULL
4578                  ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
4579                  ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date)
4580        LOOP
4581           --populate the PLSQL table with the retro basis entries
4582           -- and the start and end date of the corresponding retro paid period
4583           --for ABP (record 31)
4584           FOR temp_rec IN c_get_retro_entry
4585                           (c_element_type_id => fnd_number.canonical_to_number(
4586                                                 l_rec_31(i).py_retro_element_id)
4587                           ,c_assignment_action_id => act_rec.assignment_action_id
4588                           )
4589           LOOP
4590              --fetch the input value id for ABP Employee Pension Basis input value
4591              OPEN c_get_iv_id(c_element_type_id => fnd_number.canonical_to_number(
4592                                                    l_rec_31(i).py_retro_element_id));
4593              FETCH c_get_iv_id INTO l_basis_iv_id;
4594              CLOSE c_get_iv_id;
4595 
4596              --fetch the pension basis retro value for this current
4597              --element entry id
4598              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4599                                        ,c_input_value_id   => l_basis_iv_id);
4600              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4601              CLOSE c_get_retro_num_value;
4602 
4603              IF l_retro_ptp_value <> 0 THEN
4604                 l_rec_31_values(k).basis_amount := l_retro_ptp_value;
4605                 l_rec_31_disp := 'Y';
4606                 l_rec_31_values(k).processed := 'N';
4607                 l_rec_31_values(k).code := l_rec_31(i).code;
4608                 l_rec_31_values(k).date_earned := substr(fnd_date.date_to_canonical(
4609                                                   pay_paywsmee_pkg.get_original_date_earned(
4610                                                   temp_rec.element_entry_id)
4611                                                   ),1,10);
4612 
4613                 IF l_rec_31_values(k).basis_amount < 0 THEN
4614                    l_rec_31_values(k).sign_code := 'C';
4615                 END IF;
4616                 k := k + 1;
4617              END IF;
4618 
4619           END LOOP;
4620 
4621           FOR temp_rec IN c_get_retro_entry
4622                           (c_element_type_id => fnd_number.canonical_to_number(
4623                                                 l_rec_31(i).cy_retro_element_id)
4624                           ,c_assignment_action_id => act_rec.assignment_action_id
4625                           )
4626           LOOP
4627              --fetch the input value id for ABP Employee Pension Basis input value
4628              OPEN c_get_iv_id(c_element_type_id => fnd_number.canonical_to_number(
4629                                                    l_rec_31(i).cy_retro_element_id));
4630              FETCH c_get_iv_id INTO l_basis_iv_id;
4631              CLOSE c_get_iv_id;
4632 
4633              --fetch the pension basis retro value for this current
4634              --element entry id
4635              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4636                                        ,c_input_value_id   => l_basis_iv_id);
4637              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4638              CLOSE c_get_retro_num_value;
4639 
4640              IF l_retro_ptp_value <> 0 THEN
4641                 l_rec_31_values(k).basis_amount := l_retro_ptp_value;
4642                 l_rec_31_disp := 'Y';
4643                 l_rec_31_values(k).processed := 'N';
4644                 l_rec_31_values(k).code := l_rec_31(i).code;
4645                 l_rec_31_values(k).date_earned := ' ';
4646                 l_rec_31_values(k).date_earned := substr(fnd_date.date_to_canonical(
4647                                                   pay_paywsmee_pkg.get_original_date_earned(
4648                                                   temp_rec.element_entry_id)
4649                                                   ),1,10);
4650 
4651                 IF l_rec_31_values(k).basis_amount < 0 THEN
4652                    l_rec_31_values(k).sign_code := 'C';
4653                 END IF;
4654                 k := k + 1;
4655              END IF;
4656 
4657           END LOOP;
4658 
4659           -- Check if Run Results exist for this element/ass act
4660           IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
4661                           ,p_element_type_id => l_rec_31(i).element_type_id ) THEN
4662              -- Call pay_balance_pkg
4663              IF l_rec_31(i).defined_bal_id <> -1 THEN
4664              l_rec_31_values(k).basis_amount :=
4665                       Pay_Balance_Pkg.get_value
4666                        (p_defined_balance_id   => l_rec_31(i).defined_bal_id
4667                        ,p_assignment_action_id => act_rec.assignment_action_id);
4668              l_rec_31_disp := 'Y';
4669              l_rec_31_values(k).processed := 'N';
4670              l_rec_31_values(k).code := l_rec_31(i).code;
4671              l_rec_31_values(k).date_earned := ' ';
4672 
4673                 IF l_rec_31_values(k).basis_amount < 0 THEN
4674                    l_rec_31_values(k).sign_code := 'C';
4675                 END IF;
4676              k := k + 1;
4677              END IF;
4678           END IF;
4679        END LOOP; -- Asg Acts
4680     END LOOP; -- Elements
4681   END IF;
4682 
4683    -- Get the pension basis balance for record 41
4684   IF l_basis_rec_41.count > 0 THEN
4685     k := 1;
4686     FOR i IN l_basis_rec_41.FIRST..l_basis_rec_41.LAST
4687     LOOP
4688        l_rr_exists    := 0;
4689        FOR act_rec IN  csr_asg_act (
4690                   c_assignment_id => p_assignment_id
4691                  ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4692                  ,c_con_set_id    => NULL
4693                  ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
4694                  ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date)
4695        LOOP
4696           --populate the PLSQL table with the retro basis entries
4697           -- and the start and end date of the corresponding retro paid period
4698           --for ABP (record 41)
4699           FOR temp_rec IN c_get_retro_entry
4700                           (c_element_type_id => fnd_number.canonical_to_number(
4701                                                 l_basis_rec_41(i).py_retro_element_id)
4702                           ,c_assignment_action_id => act_rec.assignment_action_id
4703                           )
4704           LOOP
4705              --fetch the input value id for ABP Employee Pension Basis input value
4706              OPEN c_get_iv_id(c_element_type_id => fnd_number.canonical_to_number(
4707                                                    l_basis_rec_41(i).py_retro_element_id));
4708              FETCH c_get_iv_id INTO l_basis_iv_id;
4709              CLOSE c_get_iv_id;
4710 
4711              --fetch the pension basis retro value for this current
4712              --element entry id
4713              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4714                                        ,c_input_value_id   => l_basis_iv_id);
4715              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4716              CLOSE c_get_retro_num_value;
4717 
4718              IF l_retro_ptp_value <> 0 THEN
4719                 l_rec_41_basis_values(k).basis_amount := l_retro_ptp_value;
4720                 l_basis_rec_41_disp := 'Y';
4721                 l_rec_41_basis_values(k).processed := 'N';
4722                 l_rec_41_basis_values(k).code := l_basis_rec_41(i).code;
4723                 l_rec_41_basis_values(k).date_earned := substr(fnd_date.date_to_canonical(
4724                                                   pay_paywsmee_pkg.get_original_date_earned(
4725                                                   temp_rec.element_entry_id)
4726                                                   ),1,10);
4727 
4728                 IF l_rec_41_basis_values(k).basis_amount < 0 THEN
4729                    l_rec_41_basis_values(k).sign_code := 'C';
4730                 END IF;
4731                 k := k + 1;
4732             END IF;
4733 
4734           END LOOP;
4735 
4736           FOR temp_rec IN c_get_retro_entry
4737                           (c_element_type_id => fnd_number.canonical_to_number(
4738                                                 l_basis_rec_41(i).cy_retro_element_id)
4739                           ,c_assignment_action_id => act_rec.assignment_action_id
4740                           )
4741           LOOP
4742              --fetch the input value id for ABP Employee Pension Basis input value
4743              OPEN c_get_iv_id(c_element_type_id => fnd_number.canonical_to_number(
4744                                                    l_basis_rec_41(i).cy_retro_element_id));
4745              FETCH c_get_iv_id INTO l_basis_iv_id;
4746              CLOSE c_get_iv_id;
4747 
4748              --fetch the pension basis retro value for this current
4749              --element entry id
4750              OPEN c_get_retro_num_value(c_element_entry_id => temp_rec.element_entry_id
4751                                        ,c_input_value_id   => l_basis_iv_id);
4752              FETCH c_get_retro_num_value INTO l_retro_ptp_value;
4753              CLOSE c_get_retro_num_value;
4754 
4755              IF l_retro_ptp_value <> 0 THEN
4756                 l_rec_41_basis_values(k).basis_amount := l_retro_ptp_value;
4757                 l_basis_rec_41_disp := 'Y';
4758                 l_rec_41_basis_values(k).processed := 'N';
4759                 l_rec_41_basis_values(k).code := l_basis_rec_41(i).code;
4760                 l_rec_41_basis_values(k).date_earned := ' ';
4761                 l_rec_41_basis_values(k).date_earned := substr(fnd_date.date_to_canonical(
4762                                                   pay_paywsmee_pkg.get_original_date_earned(
4763                                                   temp_rec.element_entry_id)
4764                                                   ),1,10);
4765 
4766                 IF l_rec_41_basis_values(k).basis_amount < 0 THEN
4767                    l_rec_41_basis_values(k).sign_code := 'C';
4768                 END IF;
4769                 k := k + 1;
4770              END IF;
4771 
4772           END LOOP;
4773 
4774           -- Check if Run Results exist for this element/ass act
4775           IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
4776                           ,p_element_type_id => l_basis_rec_41(i).element_type_id ) THEN
4777              -- Call pay_balance_pkg
4778              IF l_basis_rec_41(i).defined_bal_id <> -1 THEN
4779              l_rec_41_basis_values(k).basis_amount :=
4780                       Pay_Balance_Pkg.get_value
4781                        (p_defined_balance_id   => l_basis_rec_41(i).defined_bal_id
4782                        ,p_assignment_action_id => act_rec.assignment_action_id);
4783              l_basis_rec_41_disp := 'Y';
4784              l_rec_41_basis_values(k).processed := 'N';
4785              l_rec_41_basis_values(k).code := l_basis_rec_41(i).code;
4786              l_rec_41_basis_values(k).date_earned := ' ';
4787 
4788                 IF l_rec_41_basis_values(k).basis_amount < 0 THEN
4789                    l_rec_41_basis_values(k).sign_code := 'C';
4790                 END IF;
4791              k := k + 1;
4792              END IF;
4793           END IF;
4794        END LOOP; -- Asg Acts
4795     END LOOP; -- Elements
4796   END IF;
4797 
4798  code commented out by vjhanak. The value of k is getting reset.
4799   need to use a different variable for the index. */
4800 
4801   --first fetch the maximum assignment action id
4802   OPEN  csr_asg_act1 (
4803               c_assignment_id => p_assignment_id
4804              ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4805              ,c_con_set_id    => NULL
4806              ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
4807              ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date);
4808   FETCH csr_asg_act1 INTO l_asg_act_id;
4809   IF csr_asg_act1%FOUND THEN
4810   CLOSE csr_asg_act1;
4811   i_12 := 1;
4812 
4813   FOR rec12_act_rec IN  csr_asg_act (
4814                c_assignment_id => p_assignment_id
4815                ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4816                ,c_con_set_id    => NULL
4817                ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
4818                ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date)
4819   LOOP
4820 
4821   --loop through the retro and normal deduction amount rows
4822   FOR temp_rec IN c_rec_12_ele(c_bg_id => p_business_group_id
4823                           ,c_effective_date =>
4824                            g_extract_params(p_business_group_id).extract_end_date
4825                           ,c_asg_id => p_assignment_id
4826                           )
4827   LOOP
4828       hr_utility.set_location('chking asg : '||p_assignment_id,10);
4829       hr_utility.set_location('chking code : '||temp_rec.code,10);
4830      --if the amount is -999999 then fetch the balance value
4831      IF temp_rec.amount = -999999 THEN
4832         l_rec12_amt := 0;
4833         OPEN csr_defined_bal1(c_balance_type_id => temp_rec.ee_contribution_bal_type_id
4834                              ,c_dimension_name  => 'Assignment Run'
4835                              ,c_business_group_id => p_business_group_id
4836                              );
4837         FETCH csr_defined_bal1 INTO l_def_bal_id;
4838         IF csr_defined_bal1%FOUND THEN
4839            CLOSE csr_defined_bal1;
4840            l_rec12_amt := pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
4841                                                    ,p_assignment_action_id => rec12_act_rec.assignment_action_id
4842                                                    );
4843         ELSE
4844           CLOSE csr_defined_bal1;
4845         END IF;
4846 
4847         OPEN csr_defined_bal1(c_balance_type_id => temp_rec.er_contribution_bal_type_id
4848                              ,c_dimension_name  => 'Assignment Run'
4849                              ,c_business_group_id => p_business_group_id
4850                              );
4851         FETCH csr_defined_bal1 INTO l_def_bal_id;
4852         IF csr_defined_bal1%FOUND THEN
4853            CLOSE csr_defined_bal1;
4854            l_rec12_amt := l_rec12_amt +
4855                           pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
4856                                                    ,p_assignment_action_id => rec12_act_rec.assignment_action_id
4857                                                    );
4858         ELSE
4859           CLOSE csr_defined_bal1;
4860         END IF;
4861 
4862         hr_utility.set_location('chking amt : '||l_rec12_amt,10);
4863 
4864            IF l_rec12_amt <> 0 THEN
4865               l_rec_12_values(i_12).contrib_amount := l_rec12_amt;
4866               l_rec_12_values(i_12).date_earned    := ' ';
4867               l_rec_12_values(i_12).code           := temp_rec.code;
4868               i_12 := i_12 + 1;
4869               l_rec_12_disp := 'Y';
4870            END IF;
4871      ELSE
4872         IF temp_rec.amount <> 0 THEN
4873            l_rec_12_values(i_12).contrib_amount := temp_rec.amount;
4874            l_rec_12_values(i_12).date_earned    := ' ';
4875            l_rec_12_values(i_12).code           := temp_rec.code;
4876            i_12 := i_12 + 1;
4877            l_rec_12_disp := 'Y';
4878         END IF;
4879      END IF;
4880 hr_utility.set_location('asg : '||p_assignment_id,10);
4881 hr_utility.set_location('amt : '||temp_rec.amount,11);
4882 hr_utility.set_location('date : '||temp_rec.date_earned,11);
4883 hr_utility.set_location('cdoe : '||temp_rec.code,11);
4884   END LOOP;
4885   END LOOP;
4886 
4887   i_41 := 1;
4888   --loop through the retro and normal deduction amount rows
4889   FOR temp_rec IN c_contrib_rec_41_ele(c_bg_id => p_business_group_id
4890                           ,c_effective_date =>
4891                            g_extract_params(p_business_group_id).extract_end_date
4892                           ,c_asg_id => p_assignment_id
4893                           )
4894   LOOP
4895      --if the amount is -999999 then fetch the balance value
4896      IF temp_rec.amount = -999999 THEN
4897         l_rec41_amt := 0;
4898         OPEN csr_defined_bal1(c_balance_type_id => temp_rec.ee_contribution_bal_type_id
4899                              ,c_dimension_name  => 'Assignment Run'
4900                              ,c_business_group_id => p_business_group_id
4901                              );
4902         FETCH csr_defined_bal1 INTO l_def_bal_id;
4903         IF csr_defined_bal1%FOUND THEN
4904            CLOSE csr_defined_bal1;
4905            l_rec41_amt := pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
4906                                                    ,p_assignment_action_id => l_asg_act_id
4907                                                    );
4908         ELSE
4909           CLOSE csr_defined_bal1;
4910         END IF;
4911 
4912         OPEN csr_defined_bal1(c_balance_type_id => temp_rec.er_contribution_bal_type_id
4913                              ,c_dimension_name  => 'Assignment Run'
4914                              ,c_business_group_id => p_business_group_id
4915                              );
4916         FETCH csr_defined_bal1 INTO l_def_bal_id;
4917         IF csr_defined_bal1%FOUND THEN
4918            CLOSE csr_defined_bal1;
4919            l_rec41_amt := l_rec41_amt +
4920                           pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
4921                                                    ,p_assignment_action_id => l_asg_act_id
4922                                                    );
4923         ELSE
4924           CLOSE csr_defined_bal1;
4925         END IF;
4926         IF l_rec41_amt <> 0 THEN
4927            l_rec_41_contrib_values(i_41).contrib_amount := l_rec41_amt;
4928            l_rec_41_contrib_values(i_41).date_earned    := ' ';
4929            l_rec_41_contrib_values(i_41).code           := temp_rec.code;
4930            i_41 := i_41 + 1;
4931            l_contrib_rec_41_disp := 'Y';
4932         END IF;
4933      ELSE
4934         IF temp_rec.amount <> 0 THEN
4935            l_rec_41_contrib_values(i_41).contrib_amount := temp_rec.amount;
4936            l_rec_41_contrib_values(i_41).date_earned    := substr(fnd_date.date_to_canonical(
4937                                                    temp_rec.date_earned),1,10);
4938            l_rec_41_contrib_values(i_41).code           := temp_rec.code;
4939            i_41 := i_41 + 1;
4940            l_contrib_rec_41_disp := 'Y';
4941         END IF;
4942      END IF;
4943 hr_utility.set_location('amt : '||temp_rec.amount,11);
4944 hr_utility.set_location('date : '||temp_rec.date_earned,11);
4945 hr_utility.set_location('cdoe : '||temp_rec.code,11);
4946   END LOOP;
4947 
4948 ELSE
4949   CLOSE csr_asg_act1;
4950 END IF;
4951 -- ============================================================================
4952 -- BEGIN Populating Rec 12 for change in hire dates
4953 -- ============================================================================
4954 -- Populate the Record 12 PL SQL table with values from the
4955 -- previous runs if there has been a change in hire date
4956 --
4957 
4958 IF l_old_start IS NOT NULL AND l_new_start IS NOT NULL THEN
4959 --
4960 -- Hire Date is changed to the past
4961 --
4962 IF trunc(l_new_start) < trunc(l_old_start) THEN
4963 --
4964 -- Derive the beginning date
4965 --
4966 l_beg_new_st := fnd_date.canonical_to_date(to_char(l_new_start,'YYYY/MM')||'/01');
4967 --
4968 -- If the beginning date is less then the current extract start
4969 -- Loop through the assignment actions to derive contrib amounts
4970 -- of that period
4971 --
4972 WHILE trunc(l_beg_new_st) < trunc(g_extract_params(p_business_group_id).extract_start_date)
4973    LOOP
4974    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
4975    --
4976    -- If Data has been sent to ABP , so not send it again
4977    --
4978    OPEN c_sent_to_abp(l_end_new_st);
4979    FETCH c_sent_to_abp INTO l_sent_to_abp;
4980    IF c_sent_to_abp%NOTFOUND THEN
4981       --
4982       -- First fetch the maximum assignment action id
4983       --
4984       OPEN  csr_asg_act1 (
4985               c_assignment_id => p_assignment_id
4986              ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
4987              ,c_con_set_id    => NULL
4988              ,c_start_date    => l_beg_new_st
4989              ,c_end_date      => l_end_new_st );
4990       FETCH csr_asg_act1 INTO l_asg_act_id;
4991       IF csr_asg_act1%FOUND THEN
4992          --
4993          -- Loop through the retro and normal deduction amount rows
4994          --
4995          FOR temp_rec IN c_rec_12_ele(c_bg_id          => p_business_group_id
4996                                      ,c_effective_date => l_end_new_st
4997                                      ,c_asg_id         => p_assignment_id)
4998          LOOP
4999             hr_utility.set_location('chking asg : '||p_assignment_id,10);
5000             hr_utility.set_location('chking code : '||temp_rec.code,10);
5001             --if the amount is -999999 then fetch the balance value
5002             IF temp_rec.amount = -999999 THEN
5003                l_rec12_amt := 0;
5004                OPEN csr_defined_bal1(c_balance_type_id => temp_rec.ee_contribution_bal_type_id
5005                                        ,c_dimension_name  => 'Assignment Run'
5006                                        ,c_business_group_id => p_business_group_id);
5007                   FETCH csr_defined_bal1 INTO l_def_bal_id;
5008                      IF csr_defined_bal1%FOUND THEN
5009                         CLOSE csr_defined_bal1;
5010                         l_rec12_amt := pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5011                                                    ,p_assignment_action_id => l_asg_act_id);
5012                ELSE
5013                  CLOSE csr_defined_bal1;
5014                END IF;
5015 
5016             OPEN csr_defined_bal1(c_balance_type_id => temp_rec.er_contribution_bal_type_id
5017                              ,c_dimension_name  => 'Assignment Run'
5018                              ,c_business_group_id => p_business_group_id
5019                              );
5020             FETCH csr_defined_bal1 INTO l_def_bal_id;
5021                IF csr_defined_bal1%FOUND THEN
5022                   CLOSE csr_defined_bal1;
5023                   l_rec12_amt := l_rec12_amt +
5024                   pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5025                                            ,p_assignment_action_id => l_asg_act_id);
5026                ELSE
5027                  CLOSE csr_defined_bal1;
5028                END IF;
5029 
5030                hr_utility.set_location('chking amt : '||l_rec12_amt,10);
5031 
5032                   IF l_rec12_amt <> 0 THEN
5033                      l_rec_12_values(i_12).contrib_amount := l_rec12_amt;
5034                      l_rec_12_values(i_12).date_earned    := ' ';
5035                      l_rec_12_values(i_12).code           := temp_rec.code;
5036                      i_12 := i_12 + 1;
5037                      l_rec_12_disp := 'Y';
5038                   END IF;
5039             END IF; -- amount is -9999
5040   END LOOP;
5041 
5042 END IF; -- Ass acts are found
5043 CLOSE csr_asg_act1;
5044 
5045 END IF; -- Data not sent to ABP
5046 
5047 CLOSE c_sent_to_abp;
5048 l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
5049 
5050 END LOOP; -- Loop through the months
5051 
5052 ELSIF trunc(l_new_start) > trunc(l_old_start) THEN
5053 --
5054 -- Derive the beginning date
5055 --
5056 l_beg_new_st    := fnd_date.canonical_to_date(to_char(l_old_start,'YYYY/MM')||'/01');
5057 l_loop_end_date := add_months(fnd_date.canonical_to_date(to_char(l_new_start,'YYYY/MM')||'/01'),1) - 1;
5058 l_loop_end_date := LEAST ( g_extract_params(p_business_group_id).extract_start_date -1
5059                            ,l_loop_end_date);
5060 -- GZZ
5061 --
5062 --
5063 -- Loop through the dates to derive data to be reported to ABP
5064 -- this might include ony the differences of that period or the entire amount
5065 -- for the month
5066 --
5067 WHILE trunc(l_beg_new_st) < l_loop_end_date
5068    LOOP
5069    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
5070 hr_utility.set_location('l_beg_new_st is '||l_beg_new_st,10);
5071 hr_utility.set_location('l_end_new_st is '||l_end_new_st,10);
5072       --
5073       -- First fetch the maximum assignment action id
5074       --
5075       OPEN  csr_asg_act1 (
5076               c_assignment_id => p_assignment_id
5077              ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
5078              ,c_con_set_id    => NULL
5079              ,c_start_date    => l_beg_new_st
5080              ,c_end_date      => l_end_new_st );
5081       FETCH csr_asg_act1 INTO l_asg_act_id;
5082       CLOSE csr_asg_act1;
5083 
5084       IF l_asg_act_id IS NOT NULL THEN
5085          --
5086          -- Loop through the normal deduction amount rows
5087          --
5088          FOR temp_rec IN c_rec_12_ele(c_bg_id          => p_business_group_id
5089                                      ,c_effective_date => l_end_new_st
5090                                      ,c_asg_id         => p_assignment_id)
5091          LOOP
5092             hr_utility.set_location('chking asg : '||p_assignment_id,10);
5093             hr_utility.set_location('chking code : '||temp_rec.code,10);
5094             --if the amount is -999999 then fetch the balance value
5095             IF temp_rec.amount = -999999 THEN
5096                l_rec12_amt := 0;
5097                OPEN csr_defined_bal1(c_balance_type_id   => temp_rec.ee_contribution_bal_type_id
5098                                     ,c_dimension_name    => 'Assignment Run'
5099                                     ,c_business_group_id => p_business_group_id);
5100                   FETCH csr_defined_bal1 INTO l_def_bal_id;
5101                      IF csr_defined_bal1%FOUND THEN
5102                         CLOSE csr_defined_bal1;
5103                         l_rec12_amt := pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5104                                                    ,p_assignment_action_id => l_asg_act_id);
5105                ELSE
5106                  CLOSE csr_defined_bal1;
5107                END IF;
5108 
5109             OPEN csr_defined_bal1(c_balance_type_id => temp_rec.er_contribution_bal_type_id
5110                              ,c_dimension_name  => 'Assignment Run'
5111                              ,c_business_group_id => p_business_group_id
5112                              );
5113             FETCH csr_defined_bal1 INTO l_def_bal_id;
5114                IF csr_defined_bal1%FOUND THEN
5115                   CLOSE csr_defined_bal1;
5116                   l_rec12_amt := l_rec12_amt +
5117                   pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5118                                            ,p_assignment_action_id => l_asg_act_id);
5119                ELSE
5120                  CLOSE csr_defined_bal1;
5121                END IF;
5122 
5123                hr_utility.set_location('chking amt : '||l_rec12_amt,10);
5124 
5125                IF l_rec12_amt <> 0 THEN
5126                  l_rec_12_values(i_12).contrib_amount := l_rec12_amt;
5127                  l_rec_12_values(i_12).date_earned    := substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
5128                  l_rec_12_values(i_12).code           := temp_rec.code;
5129               IF length(temp_rec.code) = 1 THEN
5130                l_gxx_code := '0'||temp_rec.code;
5131               ELSE
5132               l_gxx_code := temp_rec.code;
5133               END IF;
5134 
5135                   OPEN c_12_abp_data (l_end_new_st,l_gxx_code);
5136                   FETCH c_12_abp_data INTO l_rec_12_amt_sent_prev;
5137                      IF c_12_abp_data%FOUND THEN
5138                         l_rec_12_values(i_12).contrib_amount := l_rec_12_values(i_12).contrib_amount
5139                                                               - l_rec_12_amt_sent_prev;
5140             hr_utility.set_location('l_rec_12_amt_sent_prev : '||l_rec_12_amt_sent_prev,10);
5141                      END IF;
5142                   CLOSE c_12_abp_data;
5143                   i_12 := i_12 + 1;
5144                   l_rec_12_disp := 'Y';
5145 
5146                END IF;
5147             END IF;
5148     END LOOP;
5149 
5150 ELSIF l_asg_act_id IS NULL THEN
5151 
5152 hr_utility.set_location('ass act is null fetching data freom sent is '||l_end_new_st,10);
5153    FOR temp_rec IN c_rec_12_ele(c_bg_id          => p_business_group_id
5154                                ,c_effective_date => l_end_new_st
5155                                ,c_asg_id         => p_assignment_id)
5156    LOOP
5157       hr_utility.set_location('chking asg : '||p_assignment_id,10);
5158       hr_utility.set_location('chking code : '||temp_rec.code,10);
5159       --if the amount is -999999 then fetch the balance value
5160       IF temp_rec.amount = -999999 THEN
5161       hr_utility.set_location('GXXXXX entrred the if condition for -9999: '||l_rec_12_amt_sent_prev,10);
5162       hr_utility.set_location('GXXXXX l_end_new_st : '||l_end_new_st,10);
5163       hr_utility.set_location('GXXXXX temp_rec.code : '||temp_rec.code,10);
5164               IF length(temp_rec.code) = 1 THEN
5165                l_gxx_code := '0'||temp_rec.code;
5166               ELSE
5167               l_gxx_code := temp_rec.code;
5168               END IF;
5169          OPEN c_12_abp_data (l_end_new_st,l_gxx_code);
5170          FETCH c_12_abp_data INTO l_rec_12_amt_sent_prev;
5171             IF c_12_abp_data%FOUND THEN
5172       hr_utility.set_location('GXXXXX the amount is  asg : '||l_rec_12_amt_sent_prev,10);
5173                l_rec_12_values(i_12).contrib_amount := -1 * l_rec_12_amt_sent_prev;
5174                l_rec_12_values(i_12).date_earned    := substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
5175                l_rec_12_values(i_12).code           := temp_rec.code;
5176                i_12 := i_12 + 1;
5177                l_rec_12_disp := 'Y';
5178            ELSE
5179                   OPEN c_12_retro_abp_data (to_char(l_end_new_st,'YYYY'),
5180                                             to_char(l_end_new_st,'MM'),
5181                                            l_end_new_st,l_gxx_code);
5182                   FETCH c_12_retro_abp_data INTO l_rec_12_amt_sent_prev_r;
5183                    IF c_12_retro_abp_data%FOUND THEN
5184                       l_rec_12_values(i_12).contrib_amount := -1 * l_rec_12_amt_sent_prev_r;
5185                       l_rec_12_values(i_12).date_earned    := substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
5186                       l_rec_12_values(i_12).code           := temp_rec.code;
5187                       i_12 := i_12 + 1;
5188                       l_rec_12_disp := 'Y';
5189                   END IF;
5190                   CLOSE c_12_retro_abp_data;
5191 
5192             END IF;
5193           CLOSE c_12_abp_data;
5194        END IF;
5195       END LOOP;
5196 
5197 END IF;
5198 
5199 
5200 l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
5201 
5202 END LOOP; -- Loop through the months
5203 
5204 END IF; -- new start date < old start dt
5205 END IF; -- dates are not null
5206 -- ============================================================================
5207 -- END Populating Rec 12 for change in hire dates
5208 -- ============================================================================
5209 
5210 -- ============================================================================
5211 -- BEGIN Populate Rec 09 and 12 for Termination Reversal
5212 -- ============================================================================
5213 
5214 l_reversal_term := 0;
5215 l_normal_term   := 0;
5216 
5217 l_ret_val_asg  :=  Get_Asg_Seq_Num(p_assignment_id
5218                                   ,p_business_group_id
5219                                   ,p_effective_date
5220                                   ,p_error_message
5221                                   ,l_seq_num);
5222 
5223 
5224 OPEN c_get_term_rows(p_business_group_id
5225                     ,p_effective_date
5226                     ,p_assignment_id
5227                     ,l_seq_num);
5228 FETCH c_get_term_rows INTO
5229                   l_old_date1_XX,
5230                   l_new_date1_XX
5231                  ,l_term_log_id_XX
5232                  ,l_term_pos_id_XX;
5233 
5234    IF c_get_term_rows%FOUND THEN
5235       hr_utility.set_location('....c_get_term_rows Found  : ',30);
5236       CLOSE c_get_term_rows;
5237 
5238          OPEN c_get_revt_rows (p_business_group_id
5239                               ,p_effective_date
5240                               ,p_assignment_id);
5241          FETCH c_get_revt_rows INTO l_old_date2_XX,l_new_date2_XX,l_revt_log_id_XX;
5242          IF c_get_revt_rows%FOUND THEN
5243             hr_utility.set_location('....c_get_revt_rows found : ',34);
5244             CLOSE c_get_revt_rows;
5245             IF l_term_log_id_XX > l_revt_log_id_XX THEN
5246                l_normal_term := 1;
5247             END IF;
5248          ELSE
5249             CLOSE c_get_revt_rows;
5250                hr_utility.set_location('....Regular values being fetched : ',38);
5251             l_normal_term := 1;
5252          END IF;
5253       ELSE
5254          CLOSE c_get_term_rows;
5255          OPEN c_get_revt_rows (p_business_group_id
5256                               ,p_effective_date
5257                               ,p_assignment_id);
5258          FETCH c_get_revt_rows INTO l_old_date2_XX,l_new_date2_XX,l_revt_log_id_XX;
5259          IF c_get_revt_rows%FOUND THEN
5260                hr_utility.set_location('....c_get_revt_rows Found: ',40);
5261             CLOSE c_get_revt_rows;
5262             l_reversal_term := 1;
5263          ELSE
5264             CLOSE c_get_revt_rows;
5265          END IF;
5266       END IF;
5267 
5268 IF l_reversal_term = 1 AND l_old_date2_XX IS NOT NULL THEN
5269 
5270 -------------------------------REcord 09 ----------------
5271 
5272 l_beg_new_st    := ADD_MONTHS(to_date(to_char(to_nl_date(l_old_date2_XX,'DD-MM-RR'),'YYYY/MM')||'01','YYYY/MM/DD'),1);
5273 l_loop_end_date := g_extract_params(p_business_group_id).extract_start_date ;
5274 -- GZZ
5275 --
5276 --
5277 -- Loop through the dates to derive data to be reported to ABP
5278 -- this might include ony the differences of that period or the entire amount
5279 -- for the month
5280 --
5281 WHILE trunc(l_beg_new_st) < l_loop_end_date
5282    LOOP
5283    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
5284    l_gzz_asg_act_xst := 0;
5285 
5286       OPEN c_sent_to_abp(l_end_new_st);
5287    FETCH c_sent_to_abp INTO l_sent_to_abp;
5288    IF c_sent_to_abp%NOTFOUND THEN
5289 
5290       IF l_rec_09.count > 0 THEN
5291          FOR i IN l_rec_09.FIRST..l_rec_09.LAST
5292             LOOP
5293                l_rr_exists    := 0;
5294                hr_utility.set_location('current element : '||l_rec_09(i).element_type_id,10);
5295                hr_utility.set_location('asg id : '||p_assignment_id,12);
5296                hr_utility.set_location('start date :  ',14);
5297                hr_utility.set_location('end date :  ',15);
5298                FOR act_rec IN  csr_asg_act (
5299                                c_assignment_id => p_assignment_id
5300                               ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
5301                               ,c_con_set_id    => NULL
5302                               ,c_start_date    => l_beg_new_st
5303                               ,c_end_date      => l_end_new_st)
5304                LOOP
5305 
5306                       l_reg_09_age_cal_dt := l_beg_new_st;
5307                       l_reg_09_age := Get_Age(p_assignment_id,trunc(l_reg_09_age_cal_dt)) ;
5308 
5309                       IF l_reg_09_age < 65 THEN
5310                       -- Check if Run Results exist for this element/ass act
5311                          IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
5312                                          ,p_element_type_id => l_rec_09(i).element_type_id ) THEN
5313                             -- Call pay_balance_pkg
5314                             hr_utility.set_location('run results exist for current period',40);
5315                             IF l_rec_09(i).defined_bal_id <> -1 THEN
5316                                l_rec_09_values(k).basis_amount :=
5317                                Pay_Balance_Pkg.get_value
5318                                    (p_defined_balance_id   => l_rec_09(i).defined_bal_id
5319                                    ,p_assignment_action_id => act_rec.assignment_action_id);
5320                                hr_utility.set_location('defined bal id used :'||l_rec_09(i).defined_bal_id,50);
5321                                l_rec_09_disp := 'Y';
5322                                l_rec_09_values(k).processed := 'N';
5323                                l_rec_09_values(k).code := l_rec_09(i).code;
5324                                l_rec_09_values(k).date_earned :=
5325                                substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
5326 
5327                                OPEN c_09_abp_data (l_end_new_st,l_rec_09(i).code);
5328                                FETCH c_09_abp_data INTO l_09_basis_amt_sent_prev;
5329                                  IF c_09_abp_data%FOUND THEN
5330                                    l_rec_09_values(k).basis_amount := l_rec_09_values(k).basis_amount
5331                                                                     - l_09_basis_amt_sent_prev;
5332                                  END IF;
5333                                CLOSE c_09_abp_data;
5334 
5335                                IF l_rec_09_values(k).basis_amount < 0 THEN
5336                                   l_rec_09_values(k).sign_code := 'C';
5337                                END IF;
5338                                l_gzz_asg_act_xst := 1;
5339                                k := k + 1;
5340                             END IF;-- Defined bal check
5341                          END IF;-- RR exist check
5342 
5343                       END IF; -- Age check
5344                END LOOP; -- Ass acts
5345           END LOOP; -- All elements for Rec 09
5346       END IF; -- Record 09 elements exist
5347    END IF;
5348    CLOSE c_sent_to_abp;
5349 
5350    l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
5351 
5352   END LOOP; -- Loop through the months
5353 
5354 
5355 ---------------------- REcord 09 -----------------------
5356 
5357 -- Record 12
5358 
5359 l_beg_new_st    := ADD_MONTHS(to_date(to_char(to_nl_date(l_old_date2_XX,'DD-MM-RR'),'YYYY/MM')||'01','YYYY/MM/DD'),1);
5360 l_loop_end_date := g_extract_params(p_business_group_id).extract_start_date -1;
5361 
5362 
5363 WHILE trunc(l_beg_new_st) < l_loop_end_date
5364    LOOP
5365    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
5366 hr_utility.set_location('l_beg_new_st is '||l_beg_new_st,10);
5367 hr_utility.set_location('l_end_new_st is '||l_end_new_st,10);
5368    OPEN c_sent_to_abp(l_end_new_st);
5369    FETCH c_sent_to_abp INTO l_sent_to_abp;
5370    IF c_sent_to_abp%NOTFOUND THEN
5371       --
5372       -- First fetch the maximum assignment action id
5373       --
5374       OPEN  csr_asg_act1 (
5375               c_assignment_id => p_assignment_id
5376              ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
5377              ,c_con_set_id    => NULL
5378              ,c_start_date    => l_beg_new_st
5379              ,c_end_date      => l_end_new_st );
5380       FETCH csr_asg_act1 INTO l_asg_act_id;
5381       CLOSE csr_asg_act1;
5382 
5383       IF l_asg_act_id IS NOT NULL THEN
5384          --
5385          -- Loop through the normal deduction amount rows
5386          --
5387          FOR temp_rec IN c_rec_12_ele(c_bg_id          => p_business_group_id
5388                                      ,c_effective_date => l_end_new_st
5389                                      ,c_asg_id         => p_assignment_id)
5390          LOOP
5391             hr_utility.set_location('chking asg : '||p_assignment_id,10);
5392             hr_utility.set_location('chking code : '||temp_rec.code,10);
5393             --if the amount is -999999 then fetch the balance value
5394             IF temp_rec.amount = -999999 THEN
5395                l_rec12_amt := 0;
5396                OPEN csr_defined_bal1(c_balance_type_id   => temp_rec.ee_contribution_bal_type_id
5397                                     ,c_dimension_name    => 'Assignment Run'
5398                                     ,c_business_group_id => p_business_group_id);
5399                   FETCH csr_defined_bal1 INTO l_def_bal_id;
5400                      IF csr_defined_bal1%FOUND THEN
5401                         CLOSE csr_defined_bal1;
5402                         l_rec12_amt := pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5403                                                    ,p_assignment_action_id => l_asg_act_id);
5404                ELSE
5405                  CLOSE csr_defined_bal1;
5406                END IF;
5407 
5408             OPEN csr_defined_bal1(c_balance_type_id => temp_rec.er_contribution_bal_type_id
5409                              ,c_dimension_name  => 'Assignment Run'
5410                              ,c_business_group_id => p_business_group_id
5411                              );
5412             FETCH csr_defined_bal1 INTO l_def_bal_id;
5413                IF csr_defined_bal1%FOUND THEN
5414                   CLOSE csr_defined_bal1;
5415                   l_rec12_amt := l_rec12_amt +
5416                   pay_balance_pkg.get_value(p_defined_balance_id => l_def_bal_id
5417                                            ,p_assignment_action_id => l_asg_act_id);
5418                ELSE
5419                  CLOSE csr_defined_bal1;
5420                END IF;
5421 
5422                hr_utility.set_location('chking amt : '||l_rec12_amt,10);
5423 
5424                IF l_rec12_amt <> 0 THEN
5425                  l_rec_12_values(i_12).contrib_amount := l_rec12_amt;
5426                  l_rec_12_values(i_12).date_earned    := substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
5427                  l_rec_12_values(i_12).code           := temp_rec.code;
5428                   i_12 := i_12 + 1;
5429                   l_rec_12_disp := 'Y';
5430 
5431                END IF;
5432             END IF;
5433     END LOOP;
5434 
5435 ELSIF l_asg_act_id IS NULL THEN
5436 
5437 NULL;
5438 
5439 END IF;
5440 
5441 END IF;
5442 CLOSE c_sent_to_abp;
5443 
5444 l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
5445 
5446 END LOOP; -- Loop through the months
5447 
5448 
5449 -- Record 12
5450 
5451 
5452 END IF; -- check for reversal
5453 
5454 -- ============================================================================
5455 -- END  Populate Rec 09 and 12 for Termination Reversal
5456 -- ============================================================================
5457 
5458 END Populate_Record_Structures;
5459 
5460 
5461 -- =============================================================================
5462 -- Pension_Criteria_Full_Profile: The Main extract criteria that would be used
5463 -- for the pension extract. This function decides the assignments that need
5464 -- to be processed. The assignments that need not be processed are rejected
5465 -- here. The criteria is to filter the assignments based on the org hierarchy .
5466 -- =============================================================================
5467 FUNCTION Pension_Criteria_Full_Profile
5468            (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
5469            ,p_effective_date     IN  DATE
5470            ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
5471            ,p_warning_message    OUT NOCOPY VARCHAR2
5472            ,p_error_message      OUT NOCOPY VARCHAR2
5473 ) RETURN VARCHAR2 IS
5474 --
5475 -- Cursor to get the extract definition type
5476 --
5477 CURSOR csr_ext_attr (c_ext_dfn_id IN ben_ext_rslt.ext_dfn_id%TYPE) IS
5478 SELECT ext_dfn_type
5479   FROM pqp_extract_attributes
5480  WHERE ext_dfn_id = c_ext_dfn_id;
5481 --
5482 -- Based on result id and Ext. Dfn Id, get the con. request id
5483 --
5484 CURSOR csr_req_id (c_ext_rslt_id       IN ben_ext_rslt.ext_rslt_id%TYPE
5485                   ,c_ext_dfn_id        IN ben_ext_rslt.ext_dfn_id%TYPE
5486                   ,c_business_group_id IN ben_ext_rslt.business_group_id%TYPE) IS
5487 SELECT request_id
5488   FROM ben_ext_rslt
5489  WHERE ext_rslt_id       = c_ext_rslt_id
5490    AND ext_dfn_id        = c_ext_dfn_id
5491    AND business_group_id = c_business_group_id;
5492 --
5493 -- Get the Conc. requests params based on the request id fetched
5494 --
5495 CURSOR csr_ext_params (c_request_id        IN Number
5496                       ,c_ext_dfn_id        IN Number
5497                       ,c_business_group_id IN Number) IS
5498 SELECT session_id         -- Session id
5499       ,organization_name  -- Concurrent Program Name
5500       ,business_group_id  -- Business Group
5501       ,tax_unit_id        -- Concurrent Request Id
5502       ,value1             -- Extract Definition Id
5503       ,value2             -- Payroll Id
5504       ,value3             -- Consolidation Set
5505       ,value4             -- Organization Id
5506       ,value5             --
5507       ,value6             --
5508       ,attribute1         --
5509       ,attribute2         --
5510       ,attribute3         -- Extract Start Date
5511       ,attribute4         -- Extract End Date
5512       ,attribute5         -- Extract Record 01 Flag
5513  FROM pay_us_rpt_totals
5514 WHERE tax_unit_id       = c_request_id
5515   AND value1            = c_ext_dfn_id
5516   AND business_group_id = c_business_group_id;
5517 --
5518 -- Get the Legislation Code and Curreny Code
5519 --
5520 CURSOR csr_leg_code (c_business_group_id IN Number) IS
5521 SELECT pbg.legislation_code
5522       ,pbg.currency_code
5523   FROM per_business_groups_perf   pbg
5524  WHERE pbg.business_group_id = c_business_group_id;
5525 --
5526 -- Cursor to Check if a org hierarchy is attached to the BG.
5527 -- If it is attached get the valid version as of the effective date.
5528 -- If a valid version is not found then do nothing.
5529 CURSOR c_get_org_hierarchy IS
5530 SELECT pos.org_structure_version_id
5531   FROM per_org_structure_versions_v pos,
5532        hr_organization_information hoi
5533  WHERE hoi.organization_id = p_business_group_id
5534    AND To_Number(hoi.org_information1) = pos.organization_structure_id
5535    AND Trunc(p_effective_date) BETWEEN date_from
5536                                    AND Nvl(date_to,Hr_Api.g_eot)
5537    AND hoi.org_information_context = 'NL_BG_INFO';
5538 --
5539 -- Cursor to get the list of orgs from the hierarchy if one exists.
5540 --
5541 CURSOR c_get_children ( c_org_str_ver_id IN Number
5542                        ,c_org_id         IN Number) IS
5543 SELECT os.organization_id_child
5544   FROM (SELECT *
5545           FROM per_org_structure_elements a
5546          WHERE a.org_structure_version_id = c_org_str_ver_id ) os
5547 START WITH os.organization_id_parent = c_org_id
5548 CONNECT BY os.organization_id_parent = PRIOR os.organization_id_child;
5549 --
5550 -- Cursor to check whether oganization is tax organization or not
5551 --
5552 CURSOR csr_tax_org(c_org_id NUMBER) IS
5553 SELECT 'x'
5554   FROM hr_organization_information
5555  WHERE organization_id         = c_org_id
5556    AND org_information_context = 'NL_ORG_INFORMATION'
5557    AND org_information3 IS NOT NULL
5558    AND org_information4 IS NOT NULL;
5559 --
5560 -- Cursor to store the record ids in a PL/SQL table to be used while
5561 -- processing the sec. and terminated assignments
5562 --
5563 CURSOR csr_rcd_ids IS
5564 SELECT Decode(rin.seq_num,1,'00',
5565                           2,'01',
5566                           3,'02',
5567                           4,'04',
5568                           5,'05',
5569                           7,'08',
5570                           8,'09',
5571                           10,'12',
5572                           12,'20',
5573                           14,'21',
5574                           16,'22',
5575                           17,'30',
5576                           19,'31',
5577                           21,'40',
5578                           23,'41',
5579                           24,'41h',
5580                           26,'94',
5581                           27,'95',
5582                           28,'96',
5583                           29,'97',
5584                           30,'99',
5585                           '~') rec_num,
5586        rin.seq_num,
5587        rin.hide_flag,
5588        rcd.ext_rcd_id,
5589        rcd.rcd_type_cd
5590  FROM  ben_ext_rcd         rcd
5591       ,ben_ext_rcd_in_file rin
5592       ,ben_ext_dfn dfn
5593 WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
5594   AND rin.ext_file_id  = dfn.ext_file_id
5595   AND rin.ext_rcd_id   = rcd.ext_rcd_id
5596 ORDER BY rin.seq_num;
5597 
5598 CURSOR c_rej_hf_ee (c_per_id IN NUMBER)IS
5599 SELECT 1
5600   FROM per_periods_of_service
5601  WHERE PERSON_ID = c_per_id
5602    AND TRUNC(actual_termination_date) =
5603        TRUNC(date_start)
5604    AND NOT EXISTS(SELECT 1
5605                     FROM PER_PERIODS_OF_SERVICE
5606                    WHERE person_id = c_per_id
5607                      AND TRUNC(date_start) >
5608                   TRUNC(g_extract_params(p_business_group_id).extract_start_date));
5609 
5610 CURSOR c_rej_old_ee  (c_ass_id IN NUMBER
5611                      ,c_eff_dt IN DATE ) IS
5612 SELECT 1
5613   FROM per_periods_of_service pps
5614       ,per_all_assignments_f asg
5615  WHERE asg.assignment_id = c_ass_id
5616    AND c_eff_dt BETWEEN asg.effective_start_date AND asg.effective_end_date
5617    AND asg.period_of_service_id = pps.period_of_service_id
5618    AND pps.actual_termination_date IS NOT NULL
5619    AND pps.final_process_date IS NOT NULL
5620    AND pps.final_process_date <
5621        TRUNC(g_extract_params(p_business_group_id).extract_start_date);
5622 
5623 -- =========================================
5624 -- ~ Local variables
5625 -- =========================================
5626 l_rej_hf_ee          NUMBER;
5627 l_rej_old_ee         NUMBER;
5628 l_ext_params         csr_ext_params%ROWTYPE;
5629 l_conc_reqest_id     ben_ext_rslt.request_id%TYPE;
5630 l_ext_dfn_type       pqp_extract_attributes.ext_dfn_type%TYPE;
5631 i                    per_all_assignments_f.business_group_id%TYPE;
5632 l_ext_rslt_id        ben_ext_rslt.ext_rslt_id%TYPE;
5633 l_ext_dfn_id         ben_ext_dfn.ext_dfn_id%TYPE;
5634 l_return_value       Varchar2(2) :='N';
5635 l_proc_name          Varchar2(150) := g_proc_name ||'Pension_Criteria_Full_Profile';
5636 l_assig_rec          csr_assig%ROWTYPE;
5637 l_effective_date     Date;
5638 l_org_hierarchy      Number;
5639 l_tax_org_flag       VARCHAR2(1);
5640 l_grp_index          NUMBER:=0;
5641 l_org_index          NUMBER;
5642 
5643 BEGIN
5644 
5645 Hr_Utility.set_location('Entering: '||l_proc_name, 5);
5646 i := p_business_group_id;
5647 l_ext_rslt_id := Ben_Ext_Thread.g_ext_rslt_id;
5648 l_ext_dfn_id  := Ben_Ext_Thread.g_ext_dfn_id;
5649 
5650    IF NOT g_extract_params.EXISTS(i) THEN
5651       Hr_Utility.set_location('..Exract Params PL/SQL not populated ', 7);
5652       -- Get the extract type, Changes extract or Full Profile
5653       OPEN  csr_ext_attr(c_ext_dfn_id=> l_ext_dfn_id);
5654       FETCH csr_ext_attr INTO l_ext_dfn_type;
5655       CLOSE csr_ext_attr;
5656       Hr_Utility.set_location('..After cursor csr_ext_attr',9);
5657       -- Get the Conc. request id to get the params
5658       OPEN  csr_req_id(c_ext_rslt_id       => l_ext_rslt_id
5659                       ,c_ext_dfn_id        => l_ext_dfn_id
5660                       ,c_business_group_id => p_business_group_id);
5661       FETCH csr_req_id INTO l_conc_reqest_id;
5662       CLOSE csr_req_id;
5663       Hr_Utility.set_location('..After Conc.Request id cursor csr_req_id',11);
5664       -- Get the params. based on the conc. request id.
5665       OPEN  csr_ext_params (c_request_id        => l_conc_reqest_id
5666                            ,c_ext_dfn_id        => l_ext_dfn_id
5667                            ,c_business_group_id => p_business_group_id);
5668       FETCH csr_ext_params INTO l_ext_params;
5669       CLOSE csr_ext_params;
5670       -- Store the params. in a PL/SQL table record
5671       g_extract_params(i).session_id          := l_ext_params.session_id;
5672       g_extract_params(i).ext_dfn_type        := l_ext_dfn_type;
5673       g_extract_params(i).business_group_id   := l_ext_params.business_group_id;
5674       g_extract_params(i).concurrent_req_id   := l_ext_params.tax_unit_id;
5675       g_extract_params(i).ext_dfn_id          := l_ext_params.value1;
5676       g_extract_params(i).payroll_id          := l_ext_params.value2;
5677       g_extract_params(i).con_set_id          := l_ext_params.value3;
5678       g_extract_params(i).org_id              := l_ext_params.value4;
5679       g_extract_params(i).extract_start_date  :=
5680           Fnd_Date.canonical_to_date(l_ext_params.attribute3);
5681       g_extract_params(i).extract_end_date    :=
5682           Fnd_Date.canonical_to_date(l_ext_params.attribute4);
5683       g_extract_params(i).extract_rec_01      := l_ext_params.attribute5;
5684 
5685       OPEN csr_leg_code (c_business_group_id => p_business_group_id);
5686       FETCH csr_leg_code INTO g_extract_params(i).legislation_code,
5687                               g_extract_params(i).currency_code;
5688       CLOSE csr_leg_code;
5689       g_legislation_code  := g_extract_params(i).legislation_code;
5690       g_business_group_id := p_business_group_id;
5691       Hr_Utility.set_location('..Stored the extract parameters in PL/SQL table', 15);
5692 
5693       -- Set the meaning for concurrent program parameters
5694 	  Set_ConcProg_Parameter_Values
5695        (p_ext_dfn_id          => g_extract_params(i).ext_dfn_id
5696        ,p_start_date          => g_extract_params(i).extract_start_date
5697        ,p_end_date            => g_extract_params(i).extract_end_date
5698        ,p_payroll_id          => g_extract_params(i).payroll_id
5699        ,p_con_set             => g_extract_params(i).con_set_id
5700        ,p_org_id              => g_extract_params(i).org_id
5701         );
5702       Hr_Utility.set_location('..Stored the Conc. Program parameters', 17);
5703       -- Store all record ids in a PL/SQL tbl
5704       FOR rcd_rec IN csr_rcd_ids
5705       LOOP
5706           g_ext_rcds(rcd_rec.ext_rcd_id) := rcd_rec;
5707       END LOOP;
5708       -- Add the current org to the org table.
5709        g_org_list(g_extract_params(i).org_id).org_id
5710                           := g_extract_params(i).org_id;
5711       -- Check if a hierarchy is attached.
5712       OPEN c_get_org_hierarchy ;
5713       FETCH c_get_org_hierarchy INTO l_org_hierarchy;
5714       IF c_get_org_hierarchy%FOUND THEN
5715          CLOSE c_get_org_hierarchy;
5716          -- Get the children of the Org for which extract is being run
5717          -- based on the hierarchy obtained above.
5718          FOR temp_rec IN c_get_children
5719                          (c_org_str_ver_id => l_org_hierarchy
5720                          ,c_org_id         => g_extract_params(i).org_id)
5721          LOOP
5722            g_org_list(temp_rec.organization_id_child).org_id
5723                            := temp_rec.organization_id_child;
5724          END LOOP;
5725        ELSE
5726           CLOSE c_get_org_hierarchy;
5727        END IF;
5728 
5729  --------------------------------------------------------------------
5730   --From the org list select the employers
5731   l_org_index:=g_org_list.FIRST;
5732   WHILE l_org_index IS NOT NULL
5733   LOOP
5734   --Check if org is employer or not
5735     OPEN csr_tax_org(g_org_list(l_org_index).org_id);
5736     FETCH csr_tax_org INTO l_tax_org_flag;
5737     --If employer then add org in employer list
5738      IF csr_tax_org%FOUND THEN
5739          g_employer_list(g_org_list(l_org_index).org_id).gre_org_id:=g_org_list(l_org_index).org_id;
5740          Hr_Utility.set_location('Employer '||l_org_index||g_employer_list(g_org_list(l_org_index).org_id).gre_org_id, 10);
5741      END IF;
5742           CLOSE csr_tax_org;
5743           l_org_index:=g_org_list.NEXT(l_org_index);
5744    END LOOP;
5745 
5746   ---------------------------------------------------------------------
5747     g_er_index:=g_employer_list.FIRST;
5748     l_grp_index:=0;
5749     --For each employer store all the child orgs which are not employers
5750     --This include sub orgs also
5751     WHILE g_er_index IS NOT NULL
5752     LOOP
5753     --Initialize the index values
5754     g_er_child_index := l_grp_index * 1000;
5755     g_org_grp_list_cnt(g_er_index).org_grp_count:=0;
5756 
5757      --Add employer first before adding its child orgs
5758      --First increase the org group count
5759      g_org_grp_list_cnt(g_er_index).org_grp_count:=
5760              g_org_grp_list_cnt(g_er_index).org_grp_count+1;
5761 
5762      --add current org/employer to the employer child table
5763      g_employer_child_list(g_er_child_index).gre_org_id:=
5764          g_employer_list(g_er_index).gre_org_id;
5765 
5766      --Create Group for this employer
5767      Set_Er_Children(g_employer_list(g_er_index).gre_org_id
5768                      ,p_business_group_id
5769                      ,p_effective_date);
5770 
5771      --Next Employer
5772      g_er_index:=g_employer_list.NEXT(g_er_index);
5773      l_grp_index:=l_grp_index+1;
5774     END LOOP;
5775 
5776    END IF;
5777 
5778    -- Get the person id for the assignment and store it in a global
5779    -- variable
5780    g_person_id:= Nvl(get_current_extract_person(p_assignment_id),
5781                     Ben_Ext_Person.g_person_id);
5782 
5783    -- Derive the effective date
5784    l_effective_date := Least(g_extract_params(i).extract_end_date,
5785                              p_effective_date);
5786 
5787    Hr_Utility.set_location('..Processing Assig Id  : '||p_assignment_id, 17);
5788    Hr_Utility.set_location('..Processing Person Id : '||g_person_id, 17);
5789    Hr_Utility.set_location('..Processing Eff.Date  : '||p_effective_date, 17);
5790    -- Get the list of employers (HR Orgs) in the current hierarchy.
5791    -- Store this value in a PL/SQL Table.
5792    -- Check if the assignments need to be processed. Assignments are
5793    -- processed if
5794    -- 1. The organization of the person assignment exists in the
5795    --    org list derived above.
5796    -- 2. If the primary assignment does not satisfy point 1 then check if
5797    --    the secondary assignments satisfy point 1
5798    -- 3. If the assignment passed is a Benefits assignment
5799 
5800    --
5801    -- Full Profile Extracts fetches all EE's . Reject EE's that need
5802    -- not be processed at all. For E.g. if an EE's Final Close Date is
5803    -- in Jan 2004 and the extract start date is Jan 2006, there is no
5804    -- need to process this EE as no reporting needs to be done
5805    -- Also payroll cannot be processed so there are no retro changes
5806    --
5807    OPEN c_rej_old_ee (p_assignment_id
5808                      ,l_effective_date);
5809    FETCH c_rej_old_ee INTO l_rej_old_ee;
5810    IF c_rej_old_ee%FOUND THEN
5811       l_return_value := 'N';
5812       CLOSE c_rej_old_ee;
5813       RETURN l_return_value;
5814    ELSE
5815       CLOSE c_rej_old_ee;
5816    END IF;
5817 
5818    -- Check if the assignements passed by BEN are in the org list
5819    OPEN csr_assig (c_assignment_id     => p_assignment_id
5820                   ,c_effective_date    => l_effective_date
5821                   ,c_business_group_id => p_business_group_id);
5822    FETCH csr_assig INTO l_assig_rec;
5823    CLOSE csr_assig;
5824    -- Check for Benefits assignment first.
5825    IF l_assig_rec.assignment_type = 'B' THEN
5826        --
5827    -- Added to reject EE's that are hired and fired on the same day
5828    --
5829    OPEN c_rej_hf_ee(g_person_id);
5830    FETCH c_rej_hf_ee INTO l_rej_hf_ee;
5831       IF c_rej_hf_ee%FOUND THEN
5832          l_return_value := 'N';
5833       ELSE
5834          l_return_value := 'Y';
5835       END IF;
5836    CLOSE c_rej_hf_ee;
5837 
5838    -- Check for EE Assignment
5839    ELSIF l_assig_rec.assignment_type = 'E' THEN
5840       l_return_value := 'N';
5841 
5842       -- Check if the asg org_id is in the list of orgs, Also Check if the
5843 	  -- value of payroll_id on the ASG is the same as the param Payroll id.
5844 
5845       IF g_org_list.EXISTS(l_assig_rec.organization_id) AND
5846          ( g_extract_params(i).payroll_id IS NULL OR
5847            l_assig_rec.payroll_id =
5848 		             g_extract_params(i).payroll_id )         THEN
5849          --
5850          -- Added to reject EE's that are hired and fired on the same day
5851          --
5852          OPEN c_rej_hf_ee(g_person_id);
5853          FETCH c_rej_hf_ee INTO l_rej_hf_ee;
5854          IF c_rej_hf_ee%FOUND THEN
5855             l_return_value := 'N';
5856          ELSE
5857             l_return_value := 'Y';
5858          END IF;
5859          CLOSE c_rej_hf_ee;
5860       END IF;
5861     END IF;
5862 
5863    -- Check if any secondary assignments exist and need to be picked up
5864    IF l_return_value = 'N' AND l_assig_rec.primary_flag = 'Y' THEN
5865 
5866       FOR temp_rec IN csr_sec_assig (c_assignment_id     => p_assignment_id
5867                                     ,c_effective_date    => l_effective_date
5868                                     ,c_business_group_id => p_business_group_id
5869                                     ,c_person_id         => g_person_id)
5870       -- For all sec asg's
5871       LOOP
5872          IF g_org_list.EXISTS(temp_rec.organization_id) AND
5873             ( g_extract_params(i).payroll_id IS NULL OR
5874               temp_rec.payroll_id = g_extract_params(i).payroll_id) THEN
5875          --
5876          -- Added to reject EE's that are hired and fired on the same day
5877          --
5878          OPEN c_rej_hf_ee(g_person_id);
5879          FETCH c_rej_hf_ee INTO l_rej_hf_ee;
5880          IF c_rej_hf_ee%FOUND THEN
5881             l_return_value := 'N';
5882          ELSE
5883             l_return_value := 'Y';
5884          END IF;
5885          CLOSE c_rej_hf_ee;
5886             EXIT;
5887          END IF;
5888       END LOOP;
5889 
5890     END IF;
5891 
5892    -- Added to maintain global asg data
5893    IF l_return_value = 'Y' THEN
5894       g_primary_assig(p_assignment_id) :=  l_assig_rec;
5895 
5896       OPEN csr_asg_act(p_assignment_id
5897                       ,null
5898                       ,null
5899                       ,g_extract_params(p_business_group_id).extract_start_date
5900                       ,g_extract_params(p_business_group_id).extract_end_date
5901                       );
5902       FETCH csr_asg_act INTO l_asg_act;
5903       IF csr_asg_act%FOUND THEN
5904          CLOSE csr_asg_act;
5905       ELSE
5906          CLOSE csr_asg_act;
5907          p_error_message := 'Payroll or QuickPay is not processed for this assignment.';
5908       END IF;
5909       Hr_Utility.set_location('..Valid Assig Id : '||p_assignment_id, 79);
5910 
5911       IF l_assig_rec.primary_flag = 'Y' THEN
5912          --
5913          -- Populate the PL/SQL structures with data like contribution
5914          -- basis , ptp changes etc
5915          --
5916          Populate_Record_Structures
5917                (p_assignment_id      => p_assignment_id
5918                ,p_effective_date     => p_effective_date
5919                ,p_business_group_id  => p_business_group_id
5920                ,p_error_message      => p_error_message );
5921 
5922       END IF;
5923 
5924 
5925 END IF; -- if l_return_value = 'Y'
5926 
5927     Hr_Utility.set_location('l_return_value : '||l_return_value, 79);
5928     Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
5929     RETURN l_return_value;
5930 
5931 END Pension_Criteria_Full_Profile;
5932 
5933 -- =============================================================================
5934 -- Check_Addl_Assigs: Check if the person has any secondary active assigs within
5935 -- the extract date range, then check the criteria and store it in PL/SQL table.
5936 -- =============================================================================
5937 FUNCTION Check_Addl_Assigs
5938            (p_assignment_id       IN         Number
5939            ,p_business_group_id   IN         Number
5940            ,p_effective_date      IN         Date
5941            ,p_error_message       OUT NOCOPY Varchar2
5942            ) RETURN Varchar2 IS
5943 
5944    l_return_value         Varchar2(50);
5945    i                      per_all_assignments_f.business_group_id%TYPE;
5946    l_proc_name            Varchar2(150) := g_proc_name ||'Check_Addl_Assigs';
5947    l_sec_assg_rec         csr_sec_assg%ROWTYPE;
5948    l_effective_date       Date;
5949    l_criteria_value       Varchar2(2);
5950    l_warning_message      Varchar2(2000);
5951    l_error_message        Varchar2(2000);
5952    l_asg_type             per_all_assignments_f.assignment_type%TYPE;
5953    l_person_id            per_all_people_f.person_id%TYPE;
5954    l_assignment_id        per_all_assignments_f.assignment_id%TYPE;
5955 BEGIN
5956    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
5957    i := p_business_group_id;
5958 
5959    IF NOT g_primary_assig.EXISTS(p_assignment_id) THEN
5960      l_return_value := 'NOTFOUND';
5961      Hr_Utility.set_location('..Not a Valid assignment: '||p_assignment_id, 6);
5962      RETURN l_return_value;
5963    ELSIF g_primary_assig(p_assignment_id).assignment_type IN ('B','E') THEN
5964      Hr_Utility.set_location('..Valid Assignment Type B : '||p_assignment_id, 6);
5965      l_person_id := g_primary_assig(p_assignment_id).person_id;
5966      l_asg_type  := g_primary_assig(p_assignment_id).assignment_type;
5967      -- Check if there are any other assignments which might be active within the
5968      -- specified extract date range
5969      FOR sec_asg_rec IN  csr_sec_assg
5970          (c_primary_assignment_id => p_assignment_id
5971          ,c_person_id		      => g_primary_assig(p_assignment_id).person_id
5972          ,c_effective_date    	  => g_extract_params(i).extract_end_date
5973          ,c_extract_start_date    => g_extract_params(i).extract_start_date
5974          ,c_extract_end_date      => g_extract_params(i).extract_end_date)
5975      LOOP
5976        l_sec_assg_rec   := sec_asg_rec;
5977        l_criteria_value := 'N';
5978        l_effective_date := Least(g_extract_params(i).extract_end_date,
5979                                  l_sec_assg_rec.effective_end_date);
5980        Hr_Utility.set_location('..Checking for assignment id: '||
5981 	                             l_sec_assg_rec.assignment_id, 7);
5982        Hr_Utility.set_location('..p_effective_date : '||l_effective_date, 7);
5983        -- Call the main criteria function for this assignment to check if its a
5984        -- valid assignment that can be reported based on the criteria specified.
5985        l_criteria_value := Pension_Criteria_Full_Profile
5986                           (p_assignment_id        => l_sec_assg_rec.assignment_id
5987                           ,p_effective_date       => l_effective_date
5988                           ,p_business_group_id    => p_business_group_id
5989                           ,p_warning_message      => l_warning_message
5990                           ,p_error_message        => l_error_message
5991                            );
5992        IF l_criteria_value ='Y' THEN
5993 		     l_return_value := 'FOUND';
5994    		  END IF;
5995      END LOOP; -- FOR sec_asg_rec
5996    END IF;
5997    Hr_Utility.set_location('..Assignment Count : '||g_primary_assig.Count, 7);
5998    Hr_Utility.set_location('..l_person_id : '||l_person_id, 7);
5999    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6000    RETURN l_return_value;
6001 EXCEPTION
6002    WHEN Others THEN
6003     p_error_message :='SQL-ERRM :'||SQLERRM;
6004     Hr_Utility.set_location('..'||p_error_message,85);
6005     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6006     RETURN l_return_value;
6007 END Check_Addl_Assigs;
6008 
6009 -- ====================================================================
6010 -- Raise_Extract_Warning:
6011 --    When called from the Rule of a extract detail data element
6012 --    it logs a warning in the ben_ext_rslt_err table against
6013 --    the person being processed (or as specified by context of
6014 --    assignment id ). It prefixes all warning messages with a
6015 --    string "Warning raised in data element "||element_name
6016 --    This allows the same Rule to be called from different data
6017 --    elements. Usage example.
6018 --    RAISE_EXTRACT_WARNING("No initials were found.")
6019 --    RRTURNCODE  MEANING
6020 --    -1          Cannot raise warning against a header/trailer
6021 --                record. System Extract does not allow it.
6022 --    -2          No current extract process was found.
6023 --    -3          No person was found.A Warning in System Extract
6024 --                is always raised against a person.
6025 -- ====================================================================
6026 FUNCTION Raise_Extract_Warning
6027          (p_assignment_id     IN     Number -- context
6028          ,p_error_text        IN     Varchar2
6029          ,p_error_NUMBER      IN     Number DEFAULT NULL
6030           ) RETURN Number IS
6031   l_ext_rslt_id   Number;
6032   l_person_id     Number;
6033   l_error_text    Varchar2(2000);
6034   l_return_value  Number:= 0;
6035 BEGIN
6036   --
6037     IF p_assignment_id <> -1 THEN
6038       l_ext_rslt_id:= get_current_extract_result;
6039       IF l_ext_rslt_id <> -1 THEN
6040         IF p_error_NUMBER IS NULL THEN
6041           l_error_text:= 'Warning raised in data element '||
6042                           Nvl(Ben_Ext_Person.g_elmt_name
6043                              ,Ben_Ext_Fmt.g_elmt_name)||'. '||
6044                           p_error_text;
6045         ELSE
6046           Ben_Ext_Thread.g_err_num  := p_error_NUMBER;
6047           Ben_Ext_Thread.g_err_name := p_error_text;
6048           l_error_text :=
6049             Ben_Ext_Fmt.get_error_msg(To_Number(Substr(p_error_text, 5, 5)),
6050               p_error_text,Nvl(Ben_Ext_Person.g_elmt_name,Ben_Ext_Fmt.g_elmt_name) );
6051 
6052         END IF;
6053         l_person_id:= Nvl(get_current_extract_person(p_assignment_id)
6054                        ,Ben_Ext_Person.g_person_id);
6055 
6056         IF l_person_id IS NOT NULL THEN
6057         --
6058           Ben_Ext_Util.write_err
6059             (p_err_num           => p_error_NUMBER
6060             ,p_err_name          => l_error_text
6061             ,p_typ_cd            => 'W'
6062             ,p_person_id         => l_person_id
6063             ,p_request_id        => Fnd_Global.conc_request_id
6064             ,p_business_group_id => Fnd_Global.per_business_group_id
6065             ,p_ext_rslt_id       => get_current_extract_result
6066             );
6067           l_return_value:= 0;
6068         ELSE
6069           l_return_value:= -3;
6070         END IF;
6071       ELSE
6072       --
6073         l_return_value:= -2; /* No current extract process was found */
6074       --
6075       END IF;
6076     --
6077     ELSE
6078     --
6079       l_return_value := -1; /* Cannot raise warnings against header/trailers */
6080     --
6081     END IF;
6082   --
6083   RETURN l_return_value;
6084 END Raise_Extract_Warning;
6085 
6086 -- ====================================================================
6087 -- Get_Current_Extract_Result:
6088 --    Returns the person id associated with the given assignment.
6089 --    If none is found,it returns NULL. This may arise if the
6090 --    user calls this from a header/trailer record, where
6091 --    a dummy context of assignment_id = -1 is passed.
6092 -- ====================================================================
6093 FUNCTION Get_Current_Extract_Result
6094     RETURN Number  IS
6095 
6096   e_extract_process_not_running EXCEPTION;
6097   PRAGMA EXCEPTION_INIT(e_extract_process_not_running,-8002);
6098   l_ext_rslt_id  Number;
6099 
6100 BEGIN
6101 
6102   l_ext_rslt_id := Ben_Ext_Thread.g_ext_rslt_id;
6103   RETURN l_ext_rslt_id;
6104 
6105 EXCEPTION
6106   WHEN e_extract_process_not_running THEN
6107    RETURN -1;
6108 
6109 END Get_Current_Extract_Result;
6110 
6111 -- ====================================================================
6112 -- Get_Current_Extract_Person:
6113 -- Returns the ext_rslt_id for the current extract process
6114 -- if one is running, else returns -1
6115 -- ====================================================================
6116 FUNCTION Get_Current_Extract_Person
6117           (p_assignment_id IN NUMBER )
6118 RETURN NUMBER IS
6119 
6120  l_person_id  NUMBER;
6121 
6122 BEGIN
6123 
6124   SELECT person_id
6125     INTO l_person_id
6126     FROM per_all_assignments_f
6127    WHERE assignment_id = p_assignment_id
6128      AND ROWNUM < 2;
6129 
6130 RETURN l_person_id;
6131 
6132 EXCEPTION
6133    WHEN NO_DATA_FOUND THEN
6134       RETURN NULL;
6135 
6136 END Get_Current_Extract_Person;
6137 
6138 --============================================================================
6139 --Function to derive the code for person detail changes
6140 --============================================================================
6141 FUNCTION Get_Change_CD_PER
6142          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6143          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6144          ,p_effective_date     IN  DATE
6145          ,p_error_message      OUT NOCOPY VARCHAR2
6146          ,p_data_element_value OUT NOCOPY VARCHAR2)
6147 RETURN NUMBER IS
6148 
6149 l_proc_name       VARCHAR2(150) := g_proc_name ||'Get_Change_CD_PER';
6150 l_new_hire        NUMBER;
6151 l_hire_dt         DATE;
6152 
6153 BEGIN
6154 
6155 hr_utility.set_location('Entering:   '||l_proc_name, 5);
6156 
6157 p_data_element_value := ' ';
6158 --
6159 -- Check if the EE assignment is a new hire
6160 --
6161 l_new_hire := g_new_hire_asg;
6162 l_hire_dt := g_hire_date;
6163 
6164 
6165 IF l_new_hire = 1 THEN
6166    p_data_element_value := ' ';
6167 ELSE
6168    p_data_element_value := 'W';
6169 END IF;
6170 
6171 hr_utility.set_location('p_data_element_value:   '||p_data_element_value, 5);
6172 hr_utility.set_location('Leaving:   '||l_proc_name, 5);
6173 
6174 RETURN 0 ;
6175 
6176 EXCEPTION
6177 
6178    WHEN OTHERS THEN
6179     p_error_message :='SQL-ERRM :'||SQLERRM;
6180     Hr_Utility.set_location('..'||p_error_message,85);
6181     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6182     RETURN -1;
6183 
6184 END GET_CHANGE_CD_PER;
6185 
6186 --============================================================================
6187 --GET_PERSON_INITIALS
6188 --============================================================================
6189 FUNCTION Get_Person_Initials
6190          ( p_assignment_id      IN Number
6191           ,p_business_group_id  IN Number
6192           ,p_date_earned        IN Date
6193           ,p_error_message      OUT NOCOPY Varchar2
6194           ,p_data_element_value OUT NOCOPY Varchar2
6195          ) RETURN Number IS
6196 
6197     CURSOR cur_get_initials(c_person_id   IN Number,
6198                             c_date_earned IN Date) IS
6199     SELECT Substr(replace(per_information1,'.',NULL),0,5)
6200       FROM per_all_people_f
6201      WHERE person_id         = c_person_id
6202        AND business_group_id = p_business_group_id
6203        AND c_date_earned BETWEEN effective_start_date
6204                              AND effective_end_date;
6205 
6206     l_initials     Varchar2(5);
6207     l_proc_name    Varchar2(150) := g_proc_name ||'Get_Person_Initials';
6208     l_return_value Number :=0;
6209 
6210 BEGIN
6211 
6212     Hr_Utility.set_location('Entering: '||l_proc_name, 5);
6213 
6214     OPEN cur_get_initials(g_person_id,p_date_earned);
6215        FETCH cur_get_initials INTO l_initials;
6216     CLOSE cur_get_initials;
6217 
6218     p_data_element_value := l_initials;
6219     Hr_Utility.set_location('Leaving: '||l_proc_name, 10);
6220     RETURN l_return_value;
6221 
6222 EXCEPTION
6223    WHEN Others THEN
6224     p_error_message :='SQL-ERRM :'||SQLERRM;
6225     Hr_Utility.set_location('..'||p_error_message,7);
6226     Hr_Utility.set_location('Leaving: '||l_proc_name, 9);
6227     l_return_value := -1;
6228     RETURN l_return_value;
6229 END Get_Person_Initials;
6230 
6231 -- =============================================================================
6232 -- Get_Partner_Last_Name:
6233 -- =============================================================================
6234 FUNCTION Get_Partner_Last_Name
6235  	      (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6236           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6237           ,p_effective_date       IN  Date
6238           ,p_error_message        OUT NOCOPY Varchar2
6239 	      ,p_data_element_value   OUT NOCOPY Varchar2
6240            ) RETURN Number IS
6241 
6242 CURSOR cur_last_partner_name
6243         (c_person_id IN Number
6244    	    ,c_date_earned IN Date) IS
6245 SELECT last_name
6246   FROM per_all_people_f
6247  WHERE person_id IN
6248  ( SELECT contact_person_id
6249      FROM per_contact_relationships
6250     WHERE person_id = c_person_id
6251       AND business_group_id = p_business_group_id
6252       AND contact_type      IN ('S','D')
6253       AND c_date_earned
6254             BETWEEN Nvl(date_start,
6255                         g_extract_params(p_business_group_id).extract_start_date )
6256                 AND Nvl(date_end,
6257                         g_extract_params(p_business_group_id).extract_end_date)
6258  )
6259  AND business_group_id = p_business_group_id
6260  AND c_date_earned BETWEEN effective_start_date
6261                        AND effective_end_date;
6262 
6263 l_last_partner_name  per_all_people_f.last_name%TYPE;
6264 l_proc_name          Varchar2(150) := g_proc_name ||'Get_Partner_Last_Name';
6265 l_return_value       Number :=-1;
6266 
6267 BEGIN
6268     Hr_Utility.set_location('Entering: '||l_proc_name, 5);
6269 
6270     OPEN cur_last_partner_name(g_person_id,p_effective_date);
6271       FETCH cur_last_partner_name INTO l_last_partner_name;
6272     CLOSE cur_last_partner_name;
6273 
6274     p_data_element_value := Upper(l_last_partner_name);
6275 
6276     Hr_Utility.set_location('Leaving: '||l_proc_name, 10);
6277     l_return_value :=0;
6278 
6279     RETURN l_return_value;
6280 
6281 EXCEPTION
6282    WHEN Others THEN
6283     p_error_message :='SQL-ERRM :'||SQLERRM;
6284     Hr_Utility.set_location('..'||p_error_message,7);
6285     Hr_Utility.set_location('Leaving: '||l_proc_name, 9);
6286     RETURN l_return_value;
6287 END Get_Partner_Last_Name;
6288 
6289 -- =============================================================================
6290 -- Get_Gender:
6291 -- =============================================================================
6292 FUNCTION Get_Gender
6293           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6294           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6295           ,p_effective_date     IN  Date
6296           ,p_error_message      OUT NOCOPY Varchar2
6297           ,p_data_element_value OUT NOCOPY Varchar2
6298           ) RETURN Number IS
6299 CURSOR cur_get_gender(c_date_earned       IN Date
6300                      ,c_business_group_id IN Number) IS
6301 SELECT Decode(sex,'F','V','M') gender
6302   FROM per_all_people_f
6303  WHERE person_id         = g_person_id
6304    AND business_group_id = c_business_group_id
6305    AND c_date_earned BETWEEN effective_start_date
6306                          AND effective_end_date;
6307 
6308  l_proc_name Varchar2(150) := g_proc_name ||'Get_Gender';
6309  l_gender    Varchar2(2);
6310  l_return_value   Number;
6311 
6312 BEGIN
6313    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6314    OPEN  cur_get_gender(p_effective_date,p_business_group_id);
6315    FETCH cur_get_gender INTO l_gender;
6316    CLOSE cur_get_gender;
6317    p_data_element_value := l_gender;
6318 
6319    Hr_Utility.set_location('p_data_element_value:'||p_data_element_value, 5);
6320    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6321 
6322    l_return_value := 0;
6323    RETURN l_return_value;
6324 
6325 EXCEPTION
6326    WHEN Others THEN
6327     p_error_message :='SQL-ERRM :'||SQLERRM;
6328     Hr_Utility.set_location('..'||p_error_message,85);
6329     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6330     l_return_value := -1;
6331     RETURN l_return_value;
6332 END Get_Gender;
6333 
6334 -- =============================================================================
6335 -- Get_Partner_Prefix:
6336 -- =============================================================================
6337 FUNCTION Get_Partner_Prefix
6338            (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6339            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6340            ,p_effective_date       IN  Date
6341            ,p_error_message        OUT NOCOPY Varchar2
6342            ,p_data_element_value   OUT NOCOPY Varchar2
6343            ) RETURN Number IS
6344 
6345 CURSOR cur_partner_prefix
6346         (c_date_earned IN Date) IS
6347  SELECT pre_name_adjunct
6348    FROM per_all_people_f
6349   WHERE person_id IN
6350   (SELECT contact_person_id
6351      FROM per_contact_relationships
6352      WHERE person_id         = g_person_id
6353        AND business_group_id = p_business_group_id
6354        AND contact_type      IN('S','D')
6355        AND c_date_earned
6356            BETWEEN Nvl(date_start,
6357                        g_extract_params(p_business_group_id).extract_start_date )
6358                AND Nvl(date_end,
6359                        g_extract_params(p_business_group_id).extract_end_date)
6360 
6361   )
6362   AND business_group_id = p_business_group_id
6363   AND c_date_earned BETWEEN effective_start_date
6364                         AND effective_end_date;
6365 
6366  l_proc_name Varchar2(150) := g_proc_name ||'Get_Partner_Prefix';
6367  l_partner_prefix  Varchar2(30);
6368  l_return_value   Number;
6369 
6370 
6371 BEGIN
6372    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6373    OPEN  cur_partner_prefix(p_effective_date);
6374    FETCH cur_partner_prefix INTO l_partner_prefix;
6375    CLOSE cur_partner_prefix;
6376 
6377    p_data_element_value := Upper(l_partner_prefix);
6378    Hr_Utility.set_location('p_data_element_value:'||p_data_element_value, 5);
6379    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6380    l_return_value := 0;
6381    RETURN l_return_value;
6382 EXCEPTION
6383    WHEN Others THEN
6384     p_error_message :='SQL-ERRM :'||SQLERRM;
6385     Hr_Utility.set_location('..'||p_error_message,85);
6386     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6387     l_return_value := -1;
6388     RETURN l_return_value;
6389 END Get_Partner_Prefix;
6390 
6391 -- =============================================================================
6392 -- Get_Add_Fem_EE:
6393 -- =============================================================================
6394 FUNCTION Get_Add_Fem_EE
6395           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6396           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6397           ,p_effective_date       IN  Date
6398           ,p_error_message        OUT NOCOPY Varchar2
6399           ,p_data_element_value   OUT NOCOPY Varchar2) RETURN Number IS
6400 
6401 CURSOR cur_add_fem IS
6402  SELECT per_information13
6403    FROM per_all_people_f
6404   WHERE person_id = g_person_id
6405     AND p_effective_date BETWEEN
6406         effective_start_date AND effective_end_date
6407     AND business_group_id = p_business_group_id
6408     AND per_information_category = 'NL';
6409 
6410 
6411  l_proc_name     Varchar2(150) := g_proc_name ||'Get_Add_Fem_EE';
6412 
6413 BEGIN
6414    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6415    p_data_element_value := ' ';
6416    FOR temp_rec IN cur_add_fem
6417       LOOP
6418          p_data_element_value := temp_rec.per_information13;
6419       END LOOP;
6420    Hr_Utility.set_location('p_data_element_value:'||p_data_element_value, 5);
6421    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6422 
6423    RETURN 0;
6424 
6425 EXCEPTION
6426    WHEN Others THEN
6427     p_error_message :='SQL-ERRM :'||SQLERRM;
6428     Hr_Utility.set_location('..'||p_error_message,85);
6429     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6430     RETURN -1 ;
6431 END Get_Add_Fem_EE;
6432 
6433 -- =============================================================================
6434 -- Get_EE_Num:
6435 -- =============================================================================
6436 FUNCTION Get_EE_Num
6437           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6438           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6439           ,p_effective_date     IN  Date
6440           ,p_error_message      OUT NOCOPY Varchar2
6441 	      ,p_data_element_value OUT NOCOPY Varchar2
6442           ) RETURN Number IS
6443 
6444   l_proc_name  Varchar2(150) := g_proc_name ||'Get_EE_Num';
6445   l_per_ee_num per_all_people_f.employee_number%TYPE;
6446 BEGIN
6447   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6448   IF g_primary_assig.EXISTS(p_assignment_id) THEN
6449 	 l_per_ee_num := g_primary_assig(p_assignment_id).ee_num;
6450   END IF;
6451   p_data_element_value := Nvl(l_per_ee_num,'000000000000000');
6452   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6453   RETURN 0;
6454 
6455 EXCEPTION
6456    WHEN Others THEN
6457     p_error_message :='SQL-ERRM :'||SQLERRM;
6458     Hr_Utility.set_location('..'||p_error_message,85);
6459     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6460     RETURN -1;
6461 END Get_EE_Num;
6462 
6463 -- =============================================================================
6464 -- Get_Old_Asg_Seq_Num:
6465 -- =============================================================================
6466 FUNCTION Get_Old_Asg_Seq_Num
6467           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6468           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6469           ,p_effective_date     IN  DATE
6470           ,p_error_message      OUT NOCOPY VARCHAR2
6471           ,p_data_element_value OUT NOCOPY VARCHAR2
6472           ) RETURN NUMBER IS
6473 
6474   CURSOR c_get_old_num IS
6475   SELECT NVL(lpad(aei_information2,2,'0'),'00') old_num
6476     FROM per_assignment_extra_info
6477    WHERE assignment_id    = p_assignment_id
6478      AND information_type = 'PQP_NL_ABP_OLD_EE_INFO';
6479 
6480   l_proc_name         VARCHAR2(150) := g_proc_name ||'Get_Old_Asg_Seq_Num';
6481   l_old_asg_seq_num   VARCHAR2(2);
6482 
6483 BEGIN
6484 
6485   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6486 
6487    OPEN c_get_old_num;
6488   FETCH c_get_old_num INTO l_old_asg_seq_num;
6489   CLOSE c_get_old_num;
6490 
6491   p_data_element_value := UPPER(Nvl(l_old_asg_seq_num,'00'));
6492 
6493   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6494 
6495   RETURN 0;
6496 
6497 EXCEPTION
6498    WHEN Others THEN
6499     p_error_message :='SQL-ERRM :'||SQLERRM;
6500     Hr_Utility.set_location('..'||p_error_message,85);
6501     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6502     RETURN -1;
6503 END Get_Old_Asg_Seq_Num;
6504 
6505 -- =============================================================================
6506 -- Get_ABP_ER_Num
6507 -- =============================================================================
6508 FUNCTION Get_ABP_ER_Num
6509          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6510          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6511          ,p_effective_date     IN  Date
6512          ,p_fetch_code         IN  Varchar2
6513          ,p_error_message      OUT NOCOPY Varchar2
6514          ,p_data_element_value OUT NOCOPY Varchar2
6515           ) RETURN NUMBER IS
6516 
6517 --
6518 -- Cursor to find the named hierarchy associated with the BG
6519 --
6520 CURSOR c_find_named_hierarchy IS
6521 SELECT org_information1
6522   FROM hr_organization_information
6523  WHERE organization_id = p_business_group_id
6524    AND org_information_context = 'NL_BG_INFO';
6525 
6526 --
6527 -- Cursor to find the valid version id for the particular named hierarchy
6528 --
6529 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id IN NUMBER) IS
6530 SELECT org_structure_version_id
6531   FROM per_org_structure_versions_v
6532  WHERE organization_structure_id = c_hierarchy_id
6533    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN date_from
6534    AND nvl(date_to,hr_api.g_eot);
6535 
6536 --
6537 -- Cursor to find the valid version id for a particular business group
6538 --
6539 CURSOR c_find_ver_frm_bg IS
6540 SELECT org_structure_version_id
6541   FROM per_org_structure_versions_v
6542  WHERE business_group_id = p_business_group_id
6543    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN date_from
6544    AND nvl( date_to,hr_api.g_eot);
6545 --
6546 -- Cursor to find the parent id from the org id
6547 --
6548 CURSOR c_find_parent_id(c_org_id in number
6549                        ,c_version_id in number) IS
6550 SELECT organization_id_parent
6551   FROM per_org_structure_elements
6552  WHERE organization_id_child    = c_org_id
6553    AND org_structure_version_id = c_version_id
6554    AND business_group_id        = p_business_group_id;
6555 
6556 --
6557 -- Cursor to fetch ABP employer number
6558 --
6559 CURSOR csr_get_er_num(c_org_id IN Number) IS
6560 SELECT UPPER(nvl(lpad(org_information4,7,'0'),'0000000')) old_num
6561       ,SUBSTR(NVL(org_information2,'-1'),0,7) new_num
6562   FROM hr_organization_information
6563  WHERE org_information_context = 'PQP_ABP_PROVIDER'
6564    AND organization_id = c_org_id;
6565 
6566 --
6567 -- Cursor to fetch the organization of the EE Asg.
6568 --
6569 CURSOR csr_get_org_id IS
6570 SELECT organization_id
6571   FROM per_all_assignments_f
6572  WHERE assignment_id = p_assignment_id
6573    AND business_group_id = p_business_group_id
6574    ORDER BY effective_end_date DESC;
6575 
6576 l_old_er_num        ben_ext_chg_evt_log.old_val1%TYPE := '-1';
6577 l_new_er_num        hr_organization_information.org_information2%TYPE := '-1';
6578 l_org_info_id       hr_organization_information.org_information_id%TYPE;
6579 l_version_id        per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
6580 l_proc_name         VARCHAR2(150) := g_proc_name ||'Get_ABP_ER_Num';
6581 l_ret_val           NUMBER := -1;
6582 l_org_id            NUMBER;
6583 l_named_hierarchy   NUMBER;
6584 l_loop_again        NUMBER;
6585 
6586 
6587 BEGIN
6588 
6589 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6590 
6591 OPEN csr_get_org_id;
6592 FETCH csr_get_org_id  INTO l_org_id;
6593 CLOSE csr_get_org_id ;
6594 
6595 Hr_Utility.set_location('l_org_id: '||l_org_id, 5);
6596 
6597 --
6598 -- Fetch the values for old and new ER nums
6599 --
6600 OPEN csr_get_er_num(l_org_id);
6601 FETCH csr_get_er_num INTO l_old_er_num,l_new_er_num;
6602    --
6603    --
6604    --
6605    IF  csr_get_er_num%FOUND THEN
6606       --
6607       -- Depending on the fetch code,return the correct value
6608       --
6609       IF p_fetch_code = 'OLD' THEN
6610          p_data_element_value := l_old_er_num;
6611          l_ret_val := 0;
6612       ELSIF p_fetch_code = 'NEW' THEN
6613          p_data_element_value := l_new_er_num;
6614          l_ret_val := 0;
6615       END IF;
6616 
6617       CLOSE csr_get_er_num;
6618       RETURN l_ret_val;
6619       --
6620    ELSE
6621       --
6622       CLOSE csr_get_er_num;
6623       --
6624       -- Value not found at this org level,traverse up the
6625       -- org hierarchy to find a value at the parent level
6626       --
6627       hr_utility.set_location('....No value found at HR org level,searching up the tree',40);
6628       --
6629       -- Check to see if a named hierarchy exists for the BG
6630       --
6631       OPEN c_find_named_hierarchy;
6632       FETCH c_find_named_hierarchy INTO l_named_hierarchy;
6633       --
6634       -- If a named hiearchy is found, find the valid version on that date
6635       --
6636       IF c_find_named_hierarchy%FOUND THEN
6637          CLOSE c_find_named_hierarchy;
6638          --
6639          -- Find the valid version on that date
6640          --
6641          OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
6642          FETCH c_find_ver_frm_hierarchy INTO l_version_id;
6643          --
6644          -- If no valid version is found, try to get it from the BG
6645          --
6646          IF c_find_ver_frm_hierarchy%NOTFOUND THEN
6647             CLOSE c_find_ver_frm_hierarchy;
6648             --
6649             -- Find the valid version id from the BG
6650             --
6651          OPEN c_find_ver_frm_bg;
6652          FETCH c_find_ver_frm_bg INTO l_version_id;
6653          CLOSE c_find_ver_frm_bg;
6654       --
6655       -- Else a valid version has been found for the named hierarchy
6656       --
6657       ELSE
6658          CLOSE c_find_ver_frm_hierarchy;
6659       END IF; -- end of if no valid version found
6660    --
6661    -- Else find the valid version from BG
6662    --
6663    ELSE
6664       CLOSE c_find_named_hierarchy;
6665       --
6666       -- Find the version number from the BG
6667       --
6668       OPEN c_find_ver_frm_bg;
6669       FETCH c_find_ver_frm_bg INTO l_version_id;
6670       CLOSE c_find_ver_frm_bg;
6671    END IF; -- end of if named hierarchy found
6672 
6673    hr_utility.set_location('  l_version_id '||l_version_id,50);
6674 
6675    IF l_version_id IS NULL THEN
6676       --
6677       -- No hierarchy has been defined, so return 00000
6678       --
6679       hr_utility.set_location('No hierarchy found,hence returning 0',60);
6680       hr_utility.set_location('Leaving get_abp_er_num',65);
6681       p_data_element_value := '';
6682       RETURN 0;
6683    END IF;
6684    --
6685    -- Loop through the org hierarchy to find the values
6686    -- at this org level or its parents
6687    --
6688    l_loop_again := 1;
6689    WHILE (l_loop_again = 1)
6690    LOOP
6691       --
6692       -- Find the parent of this org
6693       --
6694       OPEN c_find_parent_id(l_org_id,l_version_id);
6695       FETCH c_find_parent_id INTO l_org_id;
6696       IF c_find_parent_id%FOUND THEN
6697          hr_utility.set_location('searching at parent : '||l_org_id,70);
6698          CLOSE c_find_parent_id;
6699          OPEN csr_get_er_num(l_org_id);
6700          FETCH csr_get_er_num INTO l_old_er_num,l_new_er_num;
6701          IF csr_get_er_num%FOUND THEN
6702             CLOSE csr_get_er_num;
6703             l_loop_again := 0;
6704          --
6705          -- Depending on the fetch code,return the correct value
6706          --
6707          IF p_fetch_code = 'OLD' THEN
6708             p_data_element_value := l_old_er_num;
6709             l_ret_val := 0;
6710          ELSIF p_fetch_code = 'NEW' THEN
6711             p_data_element_value := l_new_er_num;
6712             l_ret_val := 0;
6713          END IF;
6714 
6715          RETURN l_ret_val;
6716 
6717          ELSE
6718             CLOSE csr_get_er_num;
6719          END IF;
6720 
6721       ELSE
6722          --
6723          -- No parent found, so return 0
6724          --
6725          CLOSE c_find_parent_id;
6726          hr_utility.set_location('no parents found,returning 0',90);
6727          p_data_element_value := '';
6728          l_loop_again := 0;
6729          l_ret_val := 0;
6730       END IF;
6731    END LOOP;
6732 END IF;
6733 
6734    Hr_Utility.set_location('....Old ER Num        : '||l_old_er_num,10);
6735    Hr_Utility.set_location('....New ER Num        : '||l_new_er_num,15);
6736    Hr_Utility.set_location('...p_data_element_value '||p_data_element_value,20);
6737    Hr_Utility.set_location('...p_error_message      '||p_error_message,25);
6738    Hr_Utility.set_location('...l_ret_val            '||l_ret_val ,30);
6739    Hr_Utility.set_location(' Leaving:               '||l_proc_name,50);
6740 
6741    RETURN l_ret_val;
6742 
6743 EXCEPTION
6744    WHEN OTHERS THEN
6745       p_error_message :='SQL-ERRM :'||SQLERRM;
6746       Hr_Utility.set_location('..'||p_error_message,85);
6747       Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6748       RETURN l_ret_val;
6749 END GET_ABP_ER_NUM;
6750 
6751 -- =============================================================================
6752 -- Get_Old_Ee_Num
6753 -- =============================================================================
6754 FUNCTION Get_Old_Ee_Num
6755           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6756           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6757           ,p_effective_date       IN  DATE
6758           ,p_error_message        OUT NOCOPY VARCHAR2
6759           ,p_data_element_value   OUT NOCOPY VARCHAR2
6760           ) RETURN NUMBER IS
6761 
6762 --
6763 -- Cursor to fetch the old employee number
6764 --
6765 CURSOR csr_get_old_ee_num IS
6766 SELECT NVL(lpad(aei_information1,15,'0'),'000000000000000') old_num
6767   FROM per_assignment_extra_info
6768  WHERE assignment_id    = p_assignment_id
6769    AND information_type = 'PQP_NL_ABP_OLD_EE_INFO';
6770 
6771 l_old_ee_num  VARCHAR2(30) ;
6772 l_proc_name   VARCHAR2(150) := g_proc_name ||'Get_Old_Ee_Num';
6773 l_ret_val     NUMBER := 0;
6774 
6775 
6776 BEGIN
6777    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6778 
6779    --
6780    -- get the values for old EE num
6781    --
6782    OPEN csr_get_old_ee_num;
6783    FETCH csr_get_old_ee_num INTO l_old_ee_num;
6784    CLOSE csr_get_old_ee_num;
6785 
6786    p_data_element_value := UPPER(NVL(l_old_ee_num,'000000000000000'));
6787 
6788    l_ret_val := 0;
6789 
6790    Hr_Utility.set_location(' p_data_element_value     ' || p_data_element_value , 20);
6791    Hr_Utility.set_location('Leaving:   '||l_proc_name, 50);
6792 
6793    RETURN l_ret_val;
6794 
6795 EXCEPTION
6796 
6797   WHEN Others THEN
6798     p_error_message :='SQL-ERRM :'||SQLERRM;
6799     Hr_Utility.set_location('..'||p_error_message,85);
6800     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6801     RETURN -1;
6802 
6803 END GET_OLD_EE_NUM;
6804 
6805 --============================================================================
6806 -- Get the code for change in address for the EE
6807 --============================================================================
6808 FUNCTION Get_Change_CD_Addr
6809         (p_assignment_id       IN  per_all_assignments_f.assignment_id%TYPE
6810         ,p_business_group_id   IN  per_all_assignments_f.business_group_id%TYPE
6811         ,p_effective_date      IN  DATE
6812         ,p_error_message       OUT NOCOPY VARCHAR2
6813         ,p_data_element_value  OUT NOCOPY VARCHAR2)
6814 RETURN Number IS
6815 
6816 l_proc_name       VARCHAR2(150) := g_proc_name ||'Get_Change_CD_Addr';
6817 l_new_hire        NUMBER;
6818 l_hire_dt         DATE;
6819 
6820 BEGIN
6821 
6822 hr_utility.set_location('Entering:   '||l_proc_name, 5);
6823 
6824 p_data_element_value := ' ';
6825 
6826 --
6827 -- Check if the EE assignment is a new hire
6828 --
6829 l_new_hire := g_new_hire_asg;
6830 l_hire_dt := g_hire_date;
6831 
6832 IF l_new_hire = 1 THEN
6833    p_data_element_value := ' ';
6834 ELSE
6835    p_data_element_value := 'W';
6836 END IF;
6837 
6838 hr_utility.set_location('p_data_element_value:   '||p_data_element_value, 5);
6839 hr_utility.set_location('Leaving:   '||l_proc_name, 5);
6840 
6841 RETURN 0 ;
6842 
6843 EXCEPTION
6844    WHEN OTHERS THEN
6845     p_error_message :='SQL-ERRM :'||SQLERRM;
6846     hr_utility.set_location('..'||p_error_message,85);
6847     hr_utility.set_location('Leaving: '||l_proc_name, 90);
6848     RETURN -1 ;
6849 END Get_Change_CD_Addr;
6850 
6851 -- =============================================================================
6852 -- Get_Street
6853 -- =============================================================================
6854 FUNCTION Get_Street
6855          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6856          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6857          ,p_effective_date       IN  Date
6858          ,p_error_message        OUT NOCOPY Varchar2
6859          ,p_data_element_value   OUT NOCOPY Varchar2
6860           ) RETURN Number IS
6861 
6862 
6863 CURSOR cur_get_street(c_person_id IN Number) IS
6864 SELECT region_1
6865   FROM per_addresses_v
6866  WHERE person_id = c_person_id
6867    AND p_effective_date BETWEEN date_from
6868    AND Nvl(date_to,Hr_Api.g_eot)
6869    AND primary_flag = 'Y'
6870    AND style = 'NL'
6871 UNION
6872 SELECT address_line1
6873   FROM per_addresses_v
6874  WHERE person_id = c_person_id
6875    AND p_effective_date BETWEEN date_from
6876    AND Nvl(date_to,Hr_Api.g_eot)
6877    AND primary_flag = 'Y'
6878    AND style = 'NL_GLB';
6879 
6880 l_street     per_addresses_v.region_1%TYPE;
6881 l_proc_name Varchar2(150) := g_proc_name ||'Get_Street';
6882 
6883 BEGIN
6884    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6885 
6886    OPEN cur_get_street(g_person_id);
6887    FETCH cur_get_street INTO l_street;
6888    CLOSE cur_get_street;
6889 
6890    p_data_element_value := Upper(l_street);
6891    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6892    RETURN 0;
6893 
6894 EXCEPTION
6895    WHEN Others THEN
6896     p_error_message :='SQL-ERRM :'||SQLERRM;
6897     Hr_Utility.set_location('..'||p_error_message,85);
6898     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6899     RETURN -1;
6900 END Get_Street;
6901 
6902 -- =============================================================================
6903 -- Get_House_Num
6904 -- =============================================================================
6905 FUNCTION Get_House_Num
6906          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6907          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6908          ,p_effective_date       IN  Date
6909          ,p_error_message        OUT NOCOPY Varchar2
6910          ,p_data_element_value   OUT NOCOPY Varchar2
6911           ) RETURN Number IS
6912 
6913 CURSOR cur_get_house_num(c_person_id IN Number) IS
6914 SELECT add_information13
6915   FROM per_addresses_v
6916  WHERE person_id = c_person_id
6917   AND  p_effective_date BETWEEN date_from
6918   AND  Nvl(date_to,Hr_Api.g_eot)
6919   AND style = 'NL'
6920   AND  primary_flag = 'Y'
6921 UNION
6922 SELECT address_line2
6923   FROM per_addresses_v
6924  WHERE person_id = c_person_id
6925   AND  p_effective_date BETWEEN date_from
6926   AND  Nvl(date_to,Hr_Api.g_eot)
6927   AND style = 'NL_GLB'
6928   AND  primary_flag = 'Y';
6929 
6930 l_house_num    per_addresses_v.address_line1%TYPE;
6931 l_proc_name    Varchar2(150) := g_proc_name ||'Get_House_Num';
6932 l_ret_val      Number := -1;
6933 
6934 BEGIN
6935 
6936    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6937 
6938    OPEN cur_get_house_num(g_person_id);
6939    FETCH cur_get_house_num INTO l_house_num;
6940    CLOSE cur_get_house_num;
6941 
6942    p_data_element_value := Upper(l_house_num);
6943    l_ret_val :=0;
6944 
6945    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6946    RETURN l_ret_val;
6947 
6948 EXCEPTION
6949    WHEN Others THEN
6950     p_error_message :='SQL-ERRM :'||SQLERRM;
6951     Hr_Utility.set_location('..'||p_error_message,85);
6952     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6953     RETURN l_ret_val;
6954 END Get_House_Num;
6955 
6956 -- =============================================================================
6957 -- Get_Addnl_House_Num
6958 -- =============================================================================
6959 FUNCTION Get_Addnl_House_Num
6960          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
6961          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
6962          ,p_effective_date       IN  Date
6963          ,p_error_message        OUT NOCOPY Varchar2
6964          ,p_data_element_value   OUT NOCOPY Varchar2
6965          ) RETURN Number IS
6966 
6967 
6968 CURSOR cur_get_addl_house_num(c_person_id IN Number) IS
6969 SELECT add_information14
6970   FROM per_addresses_v
6971  WHERE person_id = c_person_id
6972   AND  p_effective_date BETWEEN date_from
6973   AND  Nvl(date_to,Hr_Api.g_eot)
6974   AND  primary_flag = 'Y'
6975   AND  style = 'NL'
6976 UNION
6977 SELECT address_line3
6978   FROM per_addresses_v
6979  WHERE person_id = c_person_id
6980   AND  p_effective_date BETWEEN date_from
6981   AND  Nvl(date_to,Hr_Api.g_eot)
6982   AND  primary_flag = 'Y'
6983   AND  style = 'NL_GLB';
6984 
6985 l_addl_house_num    per_addresses_v.address_line1%TYPE;
6986 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Addnl_House_Num';
6987 l_ret_val      Number := -1;
6988 
6989 BEGIN
6990 
6991    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6992 
6993    OPEN cur_get_addl_house_num(g_person_id);
6994    FETCH cur_get_addl_house_num INTO l_addl_house_num;
6995    CLOSE cur_get_addl_house_num;
6996 
6997    p_data_element_value := Upper(l_addl_house_num);
6998    l_ret_val :=0;
6999 
7000    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
7001    RETURN l_ret_val;
7002 
7003 EXCEPTION
7004    WHEN Others THEN
7005     p_error_message :='SQL-ERRM :'||SQLERRM;
7006     Hr_Utility.set_location('..'||p_error_message,85);
7007     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7008     RETURN l_ret_val;
7009 END Get_Addnl_House_Num;
7010 
7011 -- =============================================================================
7012 -- Get_Postal_Code
7013 -- =============================================================================
7014 FUNCTION Get_Postal_Code
7015          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7016          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7017          ,p_effective_date       IN  Date
7018          ,p_error_message        OUT NOCOPY Varchar2
7019          ,p_data_element_value   OUT NOCOPY Varchar2
7020           ) RETURN Number IS
7021 
7022 
7023 CURSOR cur_get_postal_code(c_person_id IN Number) IS
7024 SELECT postal_code
7025   FROM per_addresses_v
7026  WHERE person_id = c_person_id
7027    AND p_effective_date BETWEEN date_from
7028    AND Nvl(date_to,Hr_Api.g_eot)
7029    AND  style IN ('NL','NL_GLB')
7030    AND primary_flag = 'Y';
7031 
7032 l_postal_code   per_addresses_v.postal_code%TYPE;
7033 l_postal_code1  per_addresses_v.postal_code%TYPE;
7034 temp_str       varchar2(1);
7035 i              Number := 0;
7036 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Postal_Code';
7037 l_ret_val      Number := -1;
7038 
7039 BEGIN
7040    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
7041    OPEN cur_get_postal_code(g_person_id);
7042    FETCH cur_get_postal_code INTO l_postal_code;
7043    IF cur_get_postal_code%FOUND THEN
7044       CLOSE cur_get_postal_code;
7045       IF l_postal_code IS NOT NULL THEN
7046          FOR i in 1..length(l_postal_code)
7047             LOOP
7048                SELECT substr(l_postal_code,i,1) INTO temp_str from dual;
7049                IF temp_str <> ' ' THEN
7050                   l_postal_code1 := l_postal_code1||temp_str;
7051                END IF;
7052             END LOOP;
7053       END IF;
7054       p_data_element_value := Upper(substr(l_postal_code1,0,6));
7055    ELSE
7056      CLOSE cur_get_postal_code;
7057      p_data_element_value := '';
7058    END IF;
7059    l_ret_val :=0;
7060    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
7061    RETURN l_ret_val;
7062 
7063 EXCEPTION
7064    WHEN Others THEN
7065     p_error_message :='SQL-ERRM :'||SQLERRM;
7066     Hr_Utility.set_location('..'||p_error_message,85);
7067     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7068     RETURN l_ret_val;
7069 END Get_Postal_Code;
7070 
7071 -- =============================================================================
7072 -- Get_City
7073 -- =============================================================================
7074 FUNCTION Get_City
7075          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7076          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7077          ,p_effective_date       IN  Date
7078          ,p_error_message        OUT NOCOPY Varchar2
7079          ,p_data_element_value   OUT NOCOPY Varchar2
7080           ) RETURN Number IS
7081 
7082 
7083 CURSOR cur_get_city(c_person_id IN Number) IS
7084 SELECT town_or_city
7085   FROM per_addresses_v
7086  WHERE person_id = c_person_id
7087    AND p_effective_date BETWEEN date_from
7088    AND Nvl(date_to,Hr_Api.g_eot)
7089    AND style IN ('NL','NL_GLB')
7090    AND primary_flag = 'Y';
7091 
7092 CURSOR cur_get_foreign_coun(c_person_id IN Number) IS
7093 SELECT Decode(country,'NL','N',country) code
7094       ,d_country
7095   FROM per_addresses_v
7096  WHERE person_id = c_person_id
7097   AND  p_effective_date BETWEEN date_from
7098   AND  Nvl(date_to,Hr_Api.g_eot)
7099   AND  style IN ('NL','NL_GLB')
7100   AND  primary_flag = 'Y';
7101 
7102 
7103 CURSOR c_city (p_lookup_code IN VARCHAR2) IS
7104 SELECT meaning
7105   FROM hr_lookups
7106  WHERE lookup_type = 'HR_NL_CITY'
7107    AND lookup_code = p_lookup_code;
7108 
7109 
7110 l_city         per_addresses_v.town_or_city%TYPE;
7111 l_city_name    hr_lookups.meaning%TYPE;
7112 l_country      per_addresses_v.d_country%TYPE;
7113 l_code         per_addresses_v.country%TYPE;
7114 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Postal_Code';
7115 l_ret_val      Number := -1;
7116 
7117 BEGIN
7118    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
7119 
7120    OPEN cur_get_city(g_person_id);
7121    FETCH cur_get_city INTO l_city;
7122    CLOSE cur_get_city;
7123 
7124    OPEN cur_get_foreign_coun(g_person_id);
7125    FETCH cur_get_foreign_coun INTO l_code,l_country;
7126    CLOSE cur_get_foreign_coun;
7127 
7128    IF l_city IS NOT NULL THEN
7129      FOR c_city_rec IN c_city (l_city) LOOP
7130         l_city_name := c_city_rec.meaning;
7131      END LOOP;
7132    END IF;
7133 
7134    l_city_name := nvl(l_city_name,l_city);
7135 
7136    IF l_code <> 'N' THEN
7137       p_data_element_value := Upper(l_city_name)||' '||Upper(l_country);
7138    ELSE
7139       p_data_element_value := Upper(l_city_name);
7140    END IF;
7141 
7142    l_ret_val :=0;
7143 
7144    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
7145    RETURN l_ret_val;
7146 
7147 EXCEPTION
7148    WHEN Others THEN
7149     p_error_message :='SQL-ERRM :'||SQLERRM;
7150     Hr_Utility.set_location('..'||p_error_message,85);
7151     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7152     RETURN l_ret_val;
7153 END Get_City;
7154 
7155 -- =============================================================================
7156 -- Get_Foreign_Country
7157 -- =============================================================================
7158 FUNCTION Get_Foreign_Country
7159          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7160          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7161          ,p_effective_date       IN  Date
7162          ,p_error_message        OUT NOCOPY Varchar2
7163          ,p_data_element_value   OUT NOCOPY Varchar2
7164          ) RETURN Number IS
7165 
7166 CURSOR cur_get_foreign_coun(c_person_id IN Number) IS
7167 SELECT Decode(country,'NL',' ','J')
7168   FROM per_addresses_v
7169  WHERE person_id = c_person_id
7170   AND  p_effective_date BETWEEN date_from
7171   AND  Nvl(date_to,Hr_Api.g_eot)
7172   AND  style IN ('NL','NL_GLB')
7173   AND  primary_flag = 'Y';
7174 
7175 l_country      per_addresses_v.d_country%TYPE;
7176 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Foreign_Country';
7177 l_ret_val      Number := 0;
7178 
7179 BEGIN
7180    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
7181    OPEN cur_get_foreign_coun(g_person_id);
7182    FETCH cur_get_foreign_coun INTO l_country;
7183    CLOSE cur_get_foreign_coun;
7184 
7185    p_data_element_value := l_country;
7186    l_ret_val :=0;
7187    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
7188    RETURN l_ret_val;
7189 
7190 EXCEPTION
7191    WHEN Others THEN
7192     p_error_message :='SQL-ERRM :'||SQLERRM;
7193     Hr_Utility.set_location('..'||p_error_message,85);
7194     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7195     RETURN -1 ;
7196 END Get_Foreign_Country;
7197 
7198 -- =============================================================================
7199 -- Get_Marital_Status
7200 -- =============================================================================
7201 FUNCTION Get_Marital_Status
7202          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7203          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7204          ,p_effective_date       IN  Date
7205          ,p_error_message        OUT NOCOPY Varchar2
7206          ,p_data_element_value   OUT NOCOPY Varchar2
7207           ) RETURN Number IS
7208 
7209 CURSOR cur_get_marital_status(c_person_id IN Number) IS
7210 SELECT DECODE(marital_status, 'S',1,
7211                               'M',2,
7212                               'D',3,
7213                               'W',4,
7214                               'DP',0,
7215                                'L',3,
7216                               'BE_LIV_TOG',1,
7217                               'REG_PART',1,
7218                               'BE_WID_PENS',4,
7219                                NULL) ms_code
7220   FROM per_all_people_f
7221  WHERE person_id = c_person_id
7222    AND business_group_id = p_business_group_id
7223    AND p_effective_date BETWEEN effective_start_date
7224                             AND effective_end_date;
7225 
7226 CURSOR cur_get_foreign_coun(c_person_id IN Number) IS
7227 SELECT DECODE(country,'NL','N','J')
7228   FROM per_addresses_v
7229  WHERE person_id = c_person_id
7230   AND  p_effective_date BETWEEN date_from
7231   AND  NVL(date_to,hr_api.g_eot)
7232   AND  style IN('NL','NL_GLB')
7233   AND  primary_flag = 'Y';
7234 
7235 l_marital_status   per_all_people_f.marital_status%TYPE;
7236 l_native           VARCHAR2(1)   := 'N';
7237 l_proc_name        VARCHAR2(150) := g_proc_name ||'Get_Marital_Status';
7238 l_ret_val          NUMBER        := -1;
7239 
7240 BEGIN
7241    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
7242 
7243    OPEN cur_get_foreign_coun(g_person_id);
7244    FETCH cur_get_foreign_coun INTO l_native;
7245    CLOSE cur_get_foreign_coun;
7246 
7247    IF l_native = 'J' THEN
7248       OPEN cur_get_marital_status(g_person_id);
7249       FETCH cur_get_marital_status INTO l_marital_status;
7250       CLOSE cur_get_marital_status;
7251       p_data_element_value := l_marital_status;
7252    ELSE
7253       p_data_element_value := ' ';
7254    END IF;
7255 
7256    l_ret_val :=0;
7257    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
7258 
7259    RETURN l_ret_val;
7260 
7261  EXCEPTION
7262    WHEN Others THEN
7263     p_error_message :='SQL-ERRM :'||SQLERRM;
7264     Hr_Utility.set_location('..'||p_error_message,85);
7265     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7266     RETURN l_ret_val;
7267 END Get_Marital_Status;
7268 
7269 -- =============================================================================
7270 -- Get_Pension_Salary -- Function to derive pension salary value for Record 08
7271 -- =============================================================================
7272 FUNCTION Get_Pension_Salary
7273 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7274   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7275   ,p_effective_date       IN  DATE
7276   ,p_balance_name         IN  pay_balance_types.balance_name%TYPE
7277   ,p_asg_act              IN  NUMBER
7278   ,p_error_message        OUT NOCOPY VARCHAR2
7279   ,p_data_element_value   OUT NOCOPY VARCHAR2)
7280 RETURN  NUMBER IS
7281 --
7282 -- Cursor to get the override ABP Pension Salary
7283 --
7284 CURSOR c_get_override_salary IS
7285 SELECT NVL(aei_information6,'0') ,
7286        TRUNC(fnd_date.canonical_to_date(aei_information1))
7287   FROM per_assignment_extra_info
7288  WHERE assignment_id            = p_assignment_id
7289    AND information_type         = 'NL_ABP_PAR_INFO'
7290    AND aei_information_category = 'NL_ABP_PAR_INFO'
7291    AND p_effective_date BETWEEN
7292            TRUNC(fnd_date.canonical_to_date(aei_information1))
7293        AND TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),hr_api.g_eot))
7294    AND aei_information6 IS NOT NULL;
7295 
7296  l_ret_val               NUMBER := 0;
7297  l_asg_action_id         pay_assignment_actions.assignment_action_id%TYPE;
7298  l_bal_exists            NUMBER;
7299  l_balance_id            pay_balance_types.balance_type_id%TYPE;
7300  l_balance_amount        NUMBER := 0;
7301  l_override_value        ben_ext_chg_evt_log.new_val1%TYPE;
7302  l_proc_name             VARCHAR2(150) := g_proc_name ||'Get_Pension_Salary';
7303  l_eff_dt                DATE;
7304  l_dim_name              VARCHAR2(100);
7305 
7306 BEGIN
7307 
7308 Hr_Utility.set_location(' Entering          ' || l_proc_name,5);
7309 Hr_Utility.set_location(' p_assignment_id   ' || p_assignment_id,6);
7310 Hr_Utility.set_location(' p_balance_name    ' || p_balance_name,7);
7311 Hr_Utility.set_location(' p_effective_date  ' || p_effective_date,7);
7312 Hr_Utility.set_location(' p_asg_act         ' || p_asg_act,7);
7313 
7314 --
7315 -- Fetch the overridden value if there is any override at the ASG EIT
7316 --
7317 OPEN c_get_override_salary;
7318 FETCH c_get_override_salary INTO l_override_value,l_eff_dt;
7319 IF c_get_override_salary%FOUND THEN
7320    CLOSE c_get_override_salary;
7321    hr_utility.set_location(' Found Override at ASG Level ', 25);
7322    p_data_element_value := l_override_value;
7323    RETURN 0;
7324 ELSE
7325    CLOSE c_get_override_salary;
7326 END IF;
7327 --
7328 -- Check if the EE assignment is a late hire. Use appropriate dimension
7329 -- if the EE is a late hire. Normal ASG_YTD otherwise.
7330 --
7331 IF Chk_Asg_Late_Hire (p_assignment_id     => p_assignment_id
7332                      ,p_business_group_id => p_business_group_id) THEN
7333    l_dim_name := 'NL Assignment ABP Year To Date Dimension';
7334     hr_utility.set_location(' Asg is late hire ', 25);
7335 ELSE
7336    l_dim_name := 'Assignment Year To Date';
7337    hr_utility.set_location(' Asg is not a late hire ', 25);
7338 END IF;
7339 
7340 OPEN  csr_defined_bal(p_balance_name
7341                      ,l_dim_name
7342                      ,p_business_group_id);
7343 FETCH csr_defined_bal INTO l_balance_id;
7344 CLOSE csr_defined_bal;
7345 
7346 Hr_Utility.set_location(' l_balance_id     ' || l_balance_id , 15);
7347 
7348 IF l_balance_id IS NOT NULL THEN
7349 
7350   IF p_asg_act <> - 1 THEN
7351         l_balance_amount := Pay_Balance_Pkg.get_value
7352                             (p_defined_balance_id  => l_balance_id
7353                             ,p_assignment_action_id => p_asg_act);
7354          Hr_Utility.set_location(' l_balance_amount     ' || l_balance_amount , 25);
7355          l_balance_amount := NVL(l_balance_amount,0);
7356          p_data_element_value :=
7357                       Fnd_Number.number_to_canonical(l_balance_amount);
7358          l_ret_val := 0;
7359   ELSIF p_asg_act = - 1 THEN
7360 
7361        Hr_Utility.set_location(' l_asg_action_id     ' || l_asg_action_id , 20);
7362        Hr_Utility.set_location(' l_eff_dt      ' || l_eff_dt , 22);
7363        OPEN  csr_asg_act1 (
7364               c_assignment_id => p_assignment_id
7365              ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
7366              ,c_con_set_id    => NULL
7367              ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
7368              ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date);
7369        FETCH csr_asg_act1 INTO l_asg_action_id;
7370       CLOSE csr_asg_act1;
7371 
7372      IF l_asg_action_id IS NOT NULL THEN
7373         l_balance_amount := Pay_Balance_Pkg.get_value
7374                             (p_defined_balance_id  => l_balance_id
7375                             ,p_assignment_action_id => l_asg_action_id);
7376          Hr_Utility.set_location(' l_balance_amount     ' || l_balance_amount , 25);
7377          l_balance_amount := NVL(l_balance_amount,0);
7378          p_data_element_value :=
7379                       Fnd_Number.number_to_canonical(l_balance_amount);
7380          l_ret_val := 0;
7381       END IF;
7382 
7383    END IF;
7384 END IF;
7385 
7386 Hr_Utility.set_location(' p_data_element_value     ' || p_data_element_value , 30);
7387 Hr_Utility.set_location(' l_ret_val     ' || l_ret_val , 40);
7388 Hr_Utility.set_location(' Leaving      ' || l_proc_name , 50);
7389 
7390 RETURN l_ret_val;
7391 
7392 EXCEPTION WHEN Others THEN
7393    p_error_message :='SQL-ERRM :'||SQLERRM;
7394    Hr_Utility.set_location('..'||p_error_message,85);
7395    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7396    RETURN l_ret_val;
7397 
7398 END Get_Pension_Salary;
7399 
7400 -- =============================================================================
7401 -- Get_Contribution_Amount for Record 12/41
7402 -- =============================================================================
7403 FUNCTION Get_Contribution_Amount(
7404    p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7405   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7406   ,p_effective_date       IN  Date
7407   ,p_record_number        IN  Number
7408   ,p_error_message        OUT NOCOPY Varchar2
7409   ,p_data_element_value   OUT NOCOPY Varchar2) RETURN  Number IS
7410 
7411  l_proc_name Varchar2(150) := g_proc_name ||'Get_Contribution_Amount';
7412  j           Number;
7413 
7414 BEGIN
7415 
7416 Hr_Utility.set_location(' Entering ' || l_proc_name , 10);
7417 IF p_record_number = 12 THEN
7418  IF l_rec_12_values.count > 0 THEN
7419    j := l_rec_12_values.FIRST;
7420    IF l_rec_12_values.EXISTS(j) THEN
7421       p_data_element_value
7422          := Fnd_Number.number_to_canonical(l_rec_12_values(j).contrib_amount);
7423    END IF;
7424  END IF;
7425 ELSIF p_record_number = 41 THEN
7426  IF l_rec_41_contrib_values.count > 0 THEN
7427    j := l_rec_41_contrib_values.FIRST;
7428    IF l_rec_41_contrib_values.EXISTS(j) THEN
7429       p_data_element_value
7430          := Fnd_Number.number_to_canonical(l_rec_41_contrib_values(j).contrib_amount);
7431    END IF;
7432  END IF;
7433 END IF;
7434   RETURN 0;
7435 
7436 Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7437 EXCEPTION
7438   WHEN Others THEN
7439   p_error_message :='SQL-ERRM :'||SQLERRM;
7440   Hr_Utility.set_location('..'||p_error_message,85);
7441   Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7442   RETURN -1 ;
7443 END Get_Contribution_Amount;
7444 
7445 -- =============================================================================
7446 -- Get_Sub_Cat_12 for Record 12
7447 -- This Function gets the sub categories
7448 -- =============================================================================
7449 
7450 FUNCTION Get_Sub_Cat_12
7451 ( p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7452  ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7453  ,p_effective_date       IN  Date
7454  ,p_error_message        OUT NOCOPY Varchar2
7455  ,p_data_element_value   OUT NOCOPY Varchar2
7456 ) RETURN  Number IS
7457 
7458  l_proc_name             Varchar2(150) := g_proc_name ||'Get_Sub_Cat_12';
7459  j Number;
7460 
7461 BEGIN
7462    Hr_Utility.set_location(' Entering ' || l_proc_name , 10);
7463  IF l_rec_12_values.count > 0 THEN
7464    j := l_rec_12_values.FIRST;
7465    p_data_element_value := lpad(l_rec_12_values(j).code,2,'0');
7466  END IF;
7467 
7468    RETURN 0;
7469 
7470    Hr_Utility.set_location(' Leaving  ' || l_proc_name , 80);
7471 
7472 EXCEPTION
7473 WHEN Others THEN
7474    p_error_message :='SQL-ERRM :'||SQLERRM;
7475    Hr_Utility.set_location('..'||p_error_message,85);
7476    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7477    RETURN -1;
7478 END Get_Sub_Cat_12;
7479 
7480 -- =============================================================================
7481 -- Get_Pension_Start_Year
7482 -- =============================================================================
7483 FUNCTION Get_Pension_Start_Year
7484 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7485   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7486   ,p_effective_date       IN  DATE
7487   ,p_start_date           IN  DATE
7488   ,p_end_date             IN  DATE
7489   ,p_error_message        OUT NOCOPY VARCHAR2
7490   ,p_data_element_value   OUT NOCOPY VARCHAR2
7491 ) RETURN  NUMBER IS
7492 
7493 CURSOR cur_get_asg_start_date(c_assign_id IN NUMBER) IS
7494 SELECT MIN(asg.effective_start_date)
7495   FROM per_assignments_f asg,per_assignment_status_types past
7496  WHERE asg.assignment_status_type_id = past.assignment_status_type_id
7497    AND past.per_system_status = 'ACTIVE_ASSIGN'
7498    AND asg.assignment_id = c_assign_id;
7499 
7500 CURSOR cur_get_yr(c_effective_dt IN Date) IS
7501 SELECT fnd_date.canonical_to_date(TO_CHAR(c_effective_dt,'YYYY')||'/01/01')
7502   FROM dual ;
7503 --
7504 -- Cursor to check if there are any changes in the pension salary
7505 --
7506 CURSOR c_get_override_start_date IS
7507 SELECT fnd_date.canonical_to_date(prmtr_02)
7508   FROM ben_ext_chg_evt_log
7509  WHERE person_id = g_person_id
7510    AND Fnd_Number.canonical_to_number(prmtr_01) = p_assignment_id
7511    AND chg_eff_dt BETWEEN p_start_date AND p_end_date
7512    AND chg_evt_cd = 'COAPS'
7513    AND ext_chg_evt_log_id =
7514        (SELECT Max(ext_chg_evt_log_id)
7515           FROM ben_ext_chg_evt_log
7516          WHERE person_id = g_person_id
7517            AND Fnd_Number.canonical_to_number(prmtr_01) = p_assignment_id
7518            AND chg_eff_dt BETWEEN p_start_date AND p_end_date
7519            AND chg_evt_cd = 'COAPS');
7520 
7521 l_ret_val             NUMBER := -1;
7522 l_start_date_yr       DATE;
7523 l_assign_start_dt     DATE;
7524 l_proc_name           VARCHAR2(150) := g_proc_name ||'Get_Pension_Start_Year';
7525 l_return              NUMBER(1);
7526 l_pension_type_id     NUMBER(10);
7527 l_pen_part_start_dt   DATE;
7528 
7529 BEGIN
7530 
7531 Hr_Utility.set_location(' Entering     ' || l_proc_name , 5);
7532 Hr_Utility.set_location(' p_assignment_id     ' || p_assignment_id , 6);
7533 
7534  OPEN cur_get_yr(p_effective_date);
7535 FETCH cur_get_yr INTO l_start_date_yr;
7536 CLOSE cur_get_yr;
7537 
7538  OPEN cur_get_asg_start_date(p_assignment_id);
7539 FETCH cur_get_asg_start_date INTO l_assign_start_dt;
7540 CLOSE cur_get_asg_start_date;
7541 
7542  OPEN  c_get_override_start_date;
7543 FETCH c_get_override_start_date INTO l_pen_part_start_dt;
7544 
7545    IF c_get_override_start_date%FOUND THEN
7546       CLOSE c_get_override_start_date;
7547       Hr_Utility.set_location(' l_pen_part_start_dt     ' || l_pen_part_start_dt , 10);
7548       Hr_Utility.set_location('l_start_date_yr'||l_start_date_yr , 40);
7549 
7550       IF (l_pen_part_start_dt IS NOT NULL AND l_start_date_yr IS NOT NULL) THEN
7551 
7552          IF ( l_pen_part_start_dt > l_start_date_yr  ) THEN
7553             p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7554                                    (l_pen_part_start_dt,'YYYYMMDD');
7555          ELSE
7556             p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7557                                    (l_start_date_yr,'YYYYMMDD');
7558          END IF;
7559          Hr_Utility.set_location('p_data_element_value'||p_data_element_value,50);
7560          l_ret_val := 0;
7561       END IF;
7562 
7563    ELSE
7564       CLOSE c_get_override_start_date;
7565          IF (l_assign_start_dt IS NOT NULL AND l_start_date_yr IS NOT NULL) THEN
7566 
7567             IF ( l_assign_start_dt > l_start_date_yr  ) THEN
7568                p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7569                                        (l_assign_start_dt,'YYYYMMDD');
7570             ELSE
7571                p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7572                                       (l_start_date_yr,'YYYYMMDD');
7573             END IF;
7574             l_ret_val := 0;
7575 
7576          END IF;
7577    END IF;
7578 
7579 Hr_Utility.set_location(' l_ret_val     ' || l_ret_val , 60);
7580 Hr_Utility.set_location(' p_data_element_value'||p_data_element_value , 70);
7581 Hr_Utility.set_location(' Leaving:      '||l_proc_name, 80);
7582 
7583 RETURN l_ret_val ;
7584 
7585 EXCEPTION
7586 WHEN OTHERS THEN
7587    p_error_message :='SQL-ERRM :'||SQLERRM;
7588    Hr_Utility.set_location('..'||p_error_message,85);
7589    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7590    RETURN l_ret_val;
7591 END Get_Pension_Start_Year;
7592 
7593 
7594 FUNCTION Get_Pension_Basis_Year
7595 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7596   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7597   ,p_effective_date       IN  Date
7598   ,p_record_number        IN  Number
7599   ,p_error_message        OUT NOCOPY Varchar2
7600   ,p_data_element_value   OUT NOCOPY Varchar2
7601 ) RETURN  Number IS
7602 
7603 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Pension_Basis_Year';
7604 j number;
7605 
7606 BEGIN
7607 
7608   Hr_Utility.set_location(' Entering     ' || l_proc_name , 05);
7609   IF p_record_number = 9 THEN
7610    IF l_rec_09_values.count > 0 THEN
7611      j := l_rec_09_values.FIRST;
7612      IF l_rec_09_values.EXISTS(j) THEN
7613         p_data_element_value := l_rec_09_values(j).date_earned;
7614      END IF;
7615    END IF;
7616   ELSIF p_record_number = 31 THEN
7617    IF l_rec_31_values.count > 0 THEN
7618      j := l_rec_31_values.FIRST;
7619      IF l_rec_31_values.EXISTS(j) THEN
7620         p_data_element_value := l_rec_31_values(j).date_earned;
7621      END IF;
7622    END IF;
7623   ELSIF p_record_number = 41 THEN
7624    IF l_rec_41_basis_values.count > 0 THEN
7625      j := l_rec_41_basis_values.FIRST;
7626      IF l_rec_41_basis_values.EXISTS(j) THEN
7627         p_data_element_value := l_rec_41_basis_values(j).date_earned;
7628      END IF;
7629    END IF;
7630   END IF;
7631 
7632   IF p_data_element_value <> ' ' THEN
7633      p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7634                           (Fnd_Date.canonical_to_date(p_data_element_value),
7635                             'YYYY');
7636   ELSE
7637      p_data_element_value := '0000';
7638   END IF;
7639   Hr_Utility.set_location(' Leaving      ' || l_proc_name , 25);
7640 
7641 RETURN 0;
7642 
7643 EXCEPTION
7644    WHEN Others THEN
7645    p_error_message :='SQL-ERRM :'||SQLERRM;
7646    Hr_Utility.set_location('..'||p_error_message,85);
7647    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7648    RETURN -1;
7649 END Get_Pension_Basis_Year;
7650 
7651 FUNCTION Get_Month_Contribution_Base
7652 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7653   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7654   ,p_effective_date       IN  Date
7655   ,p_record_number        IN  Number
7656   ,p_error_message        OUT NOCOPY Varchar2
7657   ,p_data_element_value   OUT NOCOPY Varchar2
7658 ) RETURN  Number IS
7659 
7660 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Month_Contribution_Base';
7661 j number;
7662 
7663 BEGIN
7664 
7665    Hr_Utility.set_location(' Entering     ' || l_proc_name , 05);
7666    IF p_record_number = 9 THEN
7667     IF l_rec_09_values.count > 0 THEN
7668       j := l_rec_09_values.FIRST;
7669       IF l_rec_09_values.EXISTS(j) THEN
7670          p_data_element_value := l_rec_09_values(j).date_earned;
7671       END IF;
7672     END IF;
7673    ELSIF p_record_number = 31 THEN
7674     IF l_rec_31_values.count > 0 THEN
7675       j := l_rec_31_values.FIRST;
7676       IF l_rec_31_values.EXISTS(j) THEN
7677          p_data_element_value := l_rec_31_values(j).date_earned;
7678          l_rec_31_values.DELETE(j);
7679       END IF;
7680     END IF;
7681    ELSIF p_record_number = 41 THEN
7682     IF l_rec_41_basis_values.count > 0 THEN
7683       j := l_rec_41_basis_values.FIRST;
7684       IF l_rec_41_basis_values.EXISTS(j) THEN
7685          p_data_element_value := l_rec_41_basis_values(j).date_earned;
7686          l_rec_41_basis_values.DELETE(j);
7687       END IF;
7688     END IF;
7689    END IF;
7690 
7691    IF p_data_element_value <> ' ' THEN
7692       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7693                             (Fnd_Date.canonical_to_date(p_data_element_value),
7694                              'MM');
7695    ELSE
7696       p_data_element_value := '00';
7697    END IF;
7698    Hr_Utility.set_location(' Leaving      ' || l_proc_name , 25);
7699 
7700 RETURN 0;
7701 
7702 EXCEPTION
7703    WHEN Others THEN
7704    p_error_message :='SQL-ERRM :'||SQLERRM;
7705    Hr_Utility.set_location('..'||p_error_message,85);
7706    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7707    RETURN -1;
7708 
7709 END Get_Month_Contribution_Base;
7710 
7711 FUNCTION Get_Year_Contribution_Amt
7712 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7713   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7714   ,p_effective_date       IN  Date
7715   ,p_record_number        IN  Number
7716   ,p_error_message        OUT NOCOPY Varchar2
7717   ,p_data_element_value   OUT NOCOPY Varchar2
7718 ) RETURN  Number IS
7719 
7720 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Year_Contribution_Amt';
7721 j number;
7722 
7723 BEGIN
7724 
7725   Hr_Utility.set_location(' Entering     ' || l_proc_name , 05);
7726 IF p_record_number = 12 THEN
7727   IF l_rec_12_values.count > 0 THEN
7728    j := l_rec_12_values.FIRST;
7729    IF l_rec_12_values.EXISTS(j) THEN
7730      p_data_element_value := l_rec_12_values(j).date_earned;
7731      IF p_data_element_value <> ' ' THEN
7732         p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7733                              (Fnd_Date.canonical_to_date(p_data_element_value),
7734                                'YYYY');
7735      ELSE
7736         p_data_element_value := '0000';
7737      END IF;
7738    END IF;
7739  END IF;
7740 ELSIF p_record_number = 41 THEN
7741   IF l_rec_41_contrib_values.count > 0 THEN
7742    j := l_rec_41_contrib_values.FIRST;
7743    IF l_rec_41_contrib_values.EXISTS(j) THEN
7744      p_data_element_value := l_rec_41_contrib_values(j).date_earned;
7745      IF p_data_element_value <> ' ' THEN
7746         p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7747                              (Fnd_Date.canonical_to_date(p_data_element_value),
7748                                'YYYY');
7749      ELSE
7750         p_data_element_value := '0000';
7751      END IF;
7752    END IF;
7753  END IF;
7754 END IF;
7755   Hr_Utility.set_location(' Leaving      ' || l_proc_name , 25);
7756 
7757 RETURN 0;
7758 
7759 EXCEPTION
7760    WHEN Others THEN
7761    p_error_message :='SQL-ERRM :'||SQLERRM;
7762    Hr_Utility.set_location('..'||p_error_message,85);
7763    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7764    RETURN -1;
7765 END Get_Year_Contribution_Amt;
7766 
7767 FUNCTION Get_Month_Contribution_Amt
7768 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
7769   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
7770   ,p_effective_date       IN  Date
7771   ,p_record_number        IN  Number
7772   ,p_error_message        OUT NOCOPY Varchar2
7773   ,p_data_element_value   OUT NOCOPY Varchar2
7774 ) RETURN  Number IS
7775 
7776 l_proc_name      Varchar2(150) := g_proc_name ||'Get_Month_Contribution_Amt';
7777 j number;
7778 
7779 BEGIN
7780 
7781    Hr_Utility.set_location(' Entering     ' || l_proc_name , 05);
7782 IF p_record_number = 12 THEN
7783  IF l_rec_12_values.count > 0 THEN
7784    j := l_rec_12_values.FIRST;
7785    IF l_rec_12_values.EXISTS(j) THEN
7786      p_data_element_value := l_rec_12_values(j).date_earned;
7787      IF p_data_element_value <> ' ' THEN
7788         p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7789                               (Fnd_Date.canonical_to_date(p_data_element_value),
7790                                'MM');
7791      ELSE
7792         p_data_element_value := '00';
7793      END IF;
7794      l_rec_12_values.DELETE(j);
7795    END IF;
7796  END IF;
7797 ELSIF p_record_number = 41 THEN
7798  IF l_rec_41_contrib_values.count > 0 THEN
7799    j := l_rec_41_contrib_values.FIRST;
7800    IF l_rec_41_contrib_values.EXISTS(j) THEN
7801      p_data_element_value := l_rec_41_contrib_values(j).date_earned;
7802      IF p_data_element_value <> ' ' THEN
7803         p_data_element_value := Ben_Ext_Fmt.apply_format_mask
7804                               (Fnd_Date.canonical_to_date(p_data_element_value),
7805                                'MM');
7806      ELSE
7807         p_data_element_value := '00';
7808      END IF;
7809      l_rec_41_contrib_values.DELETE(j);
7810    END IF;
7811  END IF;
7812 END IF;
7813    Hr_Utility.set_location(' Leaving      ' || l_proc_name , 25);
7814 
7815 RETURN 0;
7816 
7817 EXCEPTION
7818    WHEN Others THEN
7819    p_error_message :='SQL-ERRM :'||SQLERRM;
7820    Hr_Utility.set_location('..'||p_error_message,85);
7821    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7822    RETURN -1;
7823 
7824 END Get_Month_Contribution_Amt;
7825 
7826 --============================================================================
7827 -- Function to derive the display criteria for Record 01
7828 --============================================================================
7829 FUNCTION Record01_Display_Criteria
7830          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
7831          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
7832          ,p_effective_date     IN  DATE
7833          ,p_error_message      OUT NOCOPY VARCHAR2
7834          ,p_data_element_value OUT NOCOPY VARCHAR2)
7835 RETURN NUMBER IS
7836 
7837 CURSOR c_data_entered IS
7838 SELECT 1
7839   FROM per_assignment_extra_info
7840  WHERE assignment_id    = p_assignment_id
7841    AND information_type = 'PQP_NL_ABP_OLD_EE_INFO';
7842 
7843 l_proc_name      VARCHAR2(150) := g_proc_name ||'Record01_Display_Criteria';
7844 l_return_value   NUMBER := -1;
7845 l_data_ent       NUMBER :=  0;
7846 
7847 BEGIN
7848 
7849 hr_utility.set_location('Entering...'||l_proc_name,10);
7850 --
7851 -- Check if the assignment is attached to a payroll
7852 -- Check if ABP Pensions is processed
7853 --
7854 IF g_abp_processed_flag = 0 THEN
7855    p_data_element_value := 'N';
7856    RETURN 0;
7857 END IF;
7858 
7859 --
7860 -- Check if the user has entered the old EE details
7861 -- for this assignment. If the details are not
7862 -- entered, this is a new hire employee and the
7863 -- record does not have to be displayed
7864 --
7865 hr_utility.set_location('....Checking old EE info entry',50);
7866 
7867 OPEN c_data_entered;
7868 FETCH c_data_entered INTO l_data_ent;
7869 IF c_data_entered%FOUND THEN
7870    l_data_ent := 1;
7871    hr_utility.set_location('....c_data_entered %FOUND',60);
7872 ELSIF c_data_entered%NOTFOUND THEN
7873    hr_utility.set_location('....c_data_entered %NOTFOUND',70);
7874    l_data_ent := 0;
7875 END IF;
7876 CLOSE c_data_entered;
7877 
7878 hr_utility.set_location('....After Checking old EE entry',80);
7879 hr_utility.set_location('....Value of l_data_ent is --  '||l_data_ent,90);
7880 
7881 IF NVL(g_extract_params(p_business_group_id).extract_rec_01,'N') = 'Y'
7882    AND l_data_ent = 1 THEN
7883    p_data_element_value := 'Y';
7884 ELSE
7885    p_data_element_value := 'N';
7886 END IF;
7887 
7888 hr_utility.set_location('....Value of p_data_element_value is '
7889                          ||p_data_element_value,100);
7890 hr_utility.set_location('Leaving: '||l_proc_name,110);
7891 
7892 l_return_value := 0;
7893 
7894 RETURN l_return_value;
7895 
7896 EXCEPTION
7897 WHEN OTHERS THEN
7898    p_error_message :='SQL-ERRM :'||SQLERRM;
7899    p_data_element_value := 'N';
7900    hr_utility.set_location('..WHEN OTHERS EXCEPTION ',120);
7901    hr_utility.set_location('..'||p_error_message,130);
7902    hr_utility.set_location('Leaving: '||l_proc_name,140);
7903    RETURN l_return_value;
7904 
7905 END Record01_Display_Criteria;
7906 
7907 --============================================================================
7908 -- Record02_Display_Criteria
7909 --============================================================================
7910 FUNCTION Record02_Display_Criteria
7911          (p_assignment_id       IN  per_all_assignments_f.assignment_id%TYPE
7912          ,p_business_group_id   IN  per_all_assignments_f.business_group_id%TYPE
7913          ,p_effective_date      IN  Date
7914          ,p_error_message       OUT NOCOPY Varchar2
7915          ,p_data_element_value  OUT NOCOPY Varchar2
7916           ) RETURN Number IS
7917 --
7918 -- Cursor to check if other changes are done like Last Name, Gender etc
7919 --
7920 CURSOR csr_chk_log(c_person_id         IN Number
7921                   ,c_business_group_id IN Number
7922                   ,c_ext_start_date    IN Date
7923                   ,c_ext_end_date      IN Date ) IS
7924 SELECT 'x'
7925   FROM ben_ext_chg_evt_log
7926  WHERE person_id         = c_person_id
7927    AND business_group_id = c_business_group_id
7928    AND chg_evt_cd IN ('COLN','COSS','COUN','COG','CODB')
7929    AND fnd_date.canonical_to_date(prmtr_09)
7930        BETWEEN c_ext_start_date AND c_ext_end_date;
7931 --
7932 -- Cursor to fetch the partner's person id
7933 --
7934 CURSOR c_get_partner IS
7935 SELECT contact_person_id
7936   FROM per_contact_relationships
7937  WHERE person_id = g_person_id
7938    AND p_effective_date BETWEEN date_start
7939    AND Nvl(date_end,Hr_Api.g_eot)
7940    AND contact_type IN ('S','D')
7941    AND business_group_id = p_business_group_id;
7942 
7943 --
7944 -- Cursor to check if partner last name or prefix has changed
7945 --
7946 CURSOR c_chk_partner_log (c_person_id IN Number) IS
7947 SELECT 'X'
7948   FROM ben_ext_chg_evt_log
7949  WHERE person_id = c_person_id
7950    AND business_group_id = p_business_group_id
7951    AND chg_evt_cd IN ('COUN','COLN','CCFN')
7952    AND fnd_date.canonical_to_date(prmtr_09) BETWEEN g_extract_params(p_business_group_id).extract_start_date
7953    AND g_extract_params(p_business_group_id).extract_end_date;
7954 
7955 --
7956 -- Cursor to check if Rec 02 was sent to ABP previously
7957 -- for this assignment. If not sent then trigger a send
7958 --
7959 CURSOR c_rec_02_sent(c_asg_seq_no  IN VARCHAR2 ) IS
7960 SELECT 1
7961   FROM ben_ext_rslt_dtl     dtl
7962       ,ben_ext_rslt         res
7963       ,ben_ext_rcd          rcd
7964       ,ben_ext_rcd_in_file  rin
7965       ,ben_ext_dfn          dfn
7966 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
7967                            FROM pqp_extract_attributes
7968                           WHERE ext_dfn_type = 'NL_FPR')
7969  AND dtl.person_id    = g_person_id
7970  AND ext_stat_cd      = 'A'
7971  AND TRUNC(res.eff_dt) <
7972      TRUNC(g_extract_params(p_business_group_id).extract_start_date)
7973  AND rin.ext_file_id  = dfn.ext_file_id
7974  AND rin.ext_rcd_id   = rcd.ext_rcd_id
7975  AND dfn.ext_dfn_id   = res.ext_dfn_id
7976  and dtl.ext_rslt_id  = res.ext_rslt_id
7977  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
7978  AND dtl.val_04       = c_asg_seq_no
7979  AND rin.seq_num      = 3;
7980 
7981    l_chg_evt_exists  VARCHAR2(2);
7982    l_rows_exist      NUMBER := 0;
7983    l_return_value    NUMBER := -1;
7984    l_new_hire        NUMBER := 0;
7985    l_partner_id      per_contact_relationships.contact_person_id%TYPE;
7986    l_proc_name       VARCHAR2(150) := g_proc_name ||'Record02_Display_Criteria';
7987    l_hire_dt         DATE;
7988    l_chk_hire_dt_chg NUMBER := 0;
7989    l_old_hire_date   DATE;
7990    l_new_hire_date   DATE;
7991    l_ret_val_asg     NUMBER;
7992    l_seq_num         VARCHAR2(2);
7993    l_rec_02_sent     NUMBER;
7994 
7995 BEGIN
7996 
7997 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
7998 --
7999 -- Check if the assignment is attached to a payroll
8000 -- Check if ABP Pensions is processed for the asg
8001 --
8002 IF g_abp_processed_flag = 0 THEN
8003    p_data_element_value := 'N';
8004    RETURN 0;
8005 END IF;
8006 
8007 --
8008 -- Check if the EE assignment is a new hire and to be reported.
8009 --
8010 l_new_hire := g_new_hire_asg;
8011 l_hire_dt := g_hire_date;
8012 
8013 IF l_new_hire = 1 THEN
8014    p_data_element_value := 'Y';
8015    RETURN 0;
8016 ELSE
8017    p_data_element_value := 'N';
8018 END IF;
8019 
8020 --
8021 -- Check for other changes to personal data when it is not a new hire
8022 --
8023 OPEN csr_chk_log
8024      (c_person_id         => g_person_id
8025      ,c_business_group_id => p_business_group_id
8026      ,c_ext_start_date    => g_extract_params(p_business_group_id).extract_start_date
8027      ,c_ext_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8028 
8029 FETCH csr_chk_log INTO l_Chg_Evt_Exists;
8030 
8031 IF csr_chk_log%FOUND THEN
8032    p_data_element_value := 'Y';
8033    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
8034    CLOSE csr_chk_log;
8035    RETURN 0;
8036 ELSE
8037    p_data_element_value := 'N';
8038    CLOSE csr_chk_log;
8039 END IF;
8040 
8041 --
8042 -- Check for changes to spouses name
8043 --
8044 OPEN c_get_partner;
8045 FETCH c_get_partner INTO l_partner_id;
8046 IF c_get_partner%FOUND THEN
8047    CLOSE c_get_partner;
8048    OPEN c_chk_partner_log(l_partner_id);
8049    FETCH c_chk_partner_log INTO l_Chg_Evt_Exists;
8050    IF c_chk_partner_log%FOUND THEN
8051       p_data_element_value := 'Y';
8052       CLOSE c_chk_partner_log;
8053       RETURN 0;
8054     ELSE
8055        p_data_element_value := 'N';
8056        CLOSE c_chk_partner_log;
8057     END IF;
8058 ELSE
8059    CLOSE c_get_partner;
8060    p_data_element_value := 'N';
8061 END IF;
8062 
8063 l_chk_hire_dt_chg := chk_chg_hire_dt
8064                      (p_person_id          => g_person_id
8065                      ,p_business_group_id  => p_business_group_id
8066                      ,p_old_hire_date      => l_old_hire_date
8067                      ,p_new_hire_date      => l_new_hire_date );
8068 
8069 IF l_chk_hire_dt_chg = 1 THEN
8070 
8071    l_ret_val_asg  :=  Get_Asg_Seq_Num(p_assignment_id
8072                                      ,p_business_group_id
8073                                      ,p_effective_date
8074                                      ,p_error_message
8075                                      ,l_seq_num);
8076    OPEN c_rec_02_sent(l_seq_num);
8077    FETCH c_rec_02_sent INTO l_rec_02_sent;
8078    IF c_rec_02_sent%NOTFOUND THEN
8079       CLOSE c_rec_02_sent ;
8080       p_data_element_value := 'Y';
8081       RETURN 0;
8082    ELSIF c_rec_02_sent%FOUND THEN
8083       CLOSE c_rec_02_sent ;
8084       p_data_element_value := 'N';
8085    END IF;
8086 
8087 ELSE
8088    p_data_element_value := 'N';
8089 END IF;
8090 
8091 hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
8092 
8093 l_return_value := 0;
8094 RETURN l_return_value;
8095 
8096 EXCEPTION
8097 
8098 WHEN OTHERS THEN
8099    p_error_message :='SQL-ERRM :'||SQLERRM;
8100    p_data_element_value := 'N';
8101    Hr_Utility.set_location('..'||p_error_message,85);
8102    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
8103    RETURN l_return_value;
8104 
8105 END Record02_Display_Criteria;
8106 
8107 --============================================================================
8108 -- Function to derive the display criteria for Record 04
8109 --============================================================================
8110 FUNCTION Record04_Display_Criteria
8111         (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
8112         ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
8113         ,p_effective_date       IN  DATE
8114         ,p_error_message        OUT NOCOPY VARCHAR2
8115         ,p_data_element_value   OUT NOCOPY VARCHAR2)
8116 
8117 RETURN NUMBER IS
8118 --
8119 -- Cursor to check if rows exists for change of Marital Status
8120 --
8121 CURSOR csr_chk_log_com (c_person_id         IN NUMBER
8122                        ,c_business_group_id IN NUMBER
8123                        ,c_ext_start_date    IN DATE
8124                        ,c_ext_end_date      IN DATE ) IS
8125 SELECT 'x'
8126   FROM ben_ext_chg_evt_log
8127  WHERE person_id         = c_person_id
8128    AND business_group_id = c_business_group_id
8129    AND chg_evt_cd = 'COM'
8130    AND fnd_date.canonical_to_date(prmtr_09)
8131        BETWEEN c_ext_start_date AND c_ext_end_date;
8132 --
8133 -- Cursor to check if the country of residence is a foreign ( non NL ) country
8134 --
8135 CURSOR cur_get_foreign_coun(c_person_id IN Number) IS
8136 SELECT DECODE(country,'NL','N','J')
8137   FROM per_addresses_v
8138  WHERE person_id = c_person_id
8139    AND p_effective_date BETWEEN date_from
8140    AND NVL(date_to,hr_api.g_eot)
8141    AND style IN('NL','NL_GLB')
8142    AND primary_flag = 'Y';
8143 
8144 --
8145 -- Cursor to check if Rec 04 was sent to ABP previously
8146 -- for this assignment. If not sent then trigger a send
8147 --
8148 CURSOR c_rec_04_sent(c_asg_seq_no  IN VARCHAR2 ) IS
8149 SELECT 1
8150   FROM ben_ext_rslt_dtl     dtl
8151       ,ben_ext_rslt         res
8152       ,ben_ext_rcd          rcd
8153       ,ben_ext_rcd_in_file  rin
8154       ,ben_ext_dfn          dfn
8155 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
8156                            FROM pqp_extract_attributes
8157                           WHERE ext_dfn_type = 'NL_FPR')
8158  AND dtl.person_id    = g_person_id
8159  AND ext_stat_cd      = 'A'
8160  AND TRUNC(res.eff_dt) <
8161      TRUNC(g_extract_params(p_business_group_id).extract_start_date)
8162  AND rin.ext_file_id  = dfn.ext_file_id
8163  AND rin.ext_rcd_id   = rcd.ext_rcd_id
8164  AND dfn.ext_dfn_id   = res.ext_dfn_id
8165  and dtl.ext_rslt_id  = res.ext_rslt_id
8166  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
8167  AND dtl.val_04       = c_asg_seq_no
8168  AND rin.seq_num      = 4;
8169 
8170 --
8171 -- Cursor to check of there are address changes to the
8172 -- curent EE address in an Non NL country. If this is
8173 -- true return Y
8174 --
8175 CURSOR c_non_nl_chg (c_person_id         IN NUMBER
8176                     ,c_business_group_id IN NUMBER
8177                     ,c_ext_start_date    IN DATE
8178                     ,c_ext_end_date      IN DATE ) IS
8179 SELECT 1
8180   FROM per_addresses_v padr
8181  WHERE person_id = c_person_id
8182    -- if the current primary address is not in NL
8183    AND p_effective_date BETWEEN date_from AND NVL(date_to,hr_api.g_eot)
8184    AND primary_flag = 'Y'
8185    AND country <> 'NL'
8186    AND EXISTS  (SELECT 1
8187                   -- exists change in address event logs
8188                   -- for the primary address
8189                   FROM ben_ext_chg_evt_log  log
8190                  WHERE padr.person_id  = log.person_id
8191                    AND chg_evt_cd      = 'COPR'
8192                    AND padr.address_id = log.prmtr_01
8193                    AND fnd_date.canonical_to_date(prmtr_09)
8194                        BETWEEN c_ext_start_date AND c_ext_end_date);
8195 
8196 --
8197 -- Cursor to check if the address changed from Non NL Country to NL
8198 -- If True return Y
8199 --
8200 CURSOR c_to_nl_chg (c_person_id         IN NUMBER
8201                    ,c_business_group_id IN NUMBER
8202                    ,c_ext_start_date    IN DATE
8203                    ,c_ext_end_date      IN DATE ) IS
8204 SELECT 1
8205   FROM per_addresses_v padr
8206  WHERE person_id = c_person_id
8207    -- if the current primary address is in NL
8208    AND p_effective_date BETWEEN date_from AND NVL(date_to,hr_api.g_eot)
8209    AND primary_flag = 'Y'
8210    AND country = 'NL'
8211    AND EXISTS  (SELECT 1
8212                   -- exists change in address event logs
8213                   -- for the primary address
8214                   FROM ben_ext_chg_evt_log  log
8215                  WHERE padr.person_id  = log.person_id
8216                    AND chg_evt_cd      = 'COPR'
8217                    AND padr.address_id = log.prmtr_01
8218                    -- there is a change in primary address
8219                    AND log.prmtr_02 IS NOT NULL
8220                    AND fnd_date.canonical_to_date(prmtr_09)
8221                        BETWEEN c_ext_start_date AND c_ext_end_date
8222                    AND EXISTS (SELECT 1
8223                                  FROM per_addresses_v adr
8224                                 WHERE adr.person_id  = log.person_id
8225                                   AND adr.address_id = to_number(log.prmtr_02)
8226                                   -- old address was not in NL
8227                                   AND country <> 'NL'));
8228 --
8229 -- Cursor to check if there is a change in country
8230 -- for the current address. Changes from NL to Non NL and Vice
8231 -- versa must be reported to ABP. If true return Y
8232 --
8233 CURSOR c_cntry_chg (c_person_id         IN NUMBER
8234                    ,c_business_group_id IN NUMBER
8235                    ,c_ext_start_date    IN DATE
8236                    ,c_ext_end_date      IN DATE ) IS
8237 SELECT TO_NUMBER(prmtr_01) addr_id,new_val1 country
8238   FROM ben_ext_chg_evt_log log
8239  WHERE person_id  = c_person_id
8240    AND chg_evt_cd = 'COCN'
8241    AND fnd_date.canonical_to_date(prmtr_09)
8242        BETWEEN c_ext_start_date AND c_ext_end_date
8243    ORDER BY ext_chg_evt_log_id DESC;
8244 
8245 --
8246 -- Cursor to check if the change of country code is for the current address
8247 --
8248 CURSOR c_get_cc (c_code    IN VARCHAR2
8249                 ,c_addr_id IN NUMBER) IS
8250 SELECT 1
8251   FROM per_addresses_v padr
8252  WHERE person_id = g_person_id
8253    AND p_effective_date BETWEEN date_from AND NVL(date_to,hr_api.g_eot)
8254    AND address_id = c_addr_id
8255    AND primary_flag = 'Y'
8256    AND country = c_code;
8257 
8258 l_cc_code          VARCHAR2(2);
8259 l_chg_addr_id      NUMBER;
8260 l_cc_changed       NUMBER;
8261 l_chg_evt_exists   VARCHAR2(2);
8262 l_foreign_country  VARCHAR2(1);
8263 l_new_hire         NUMBER := 0;
8264 l_rows_exist       NUMBER := 0;
8265 l_return_value     NUMBER := -1;
8266 l_proc_name        VARCHAR2(150) := g_proc_name ||'Record04_Display_Criteria';
8267 l_hire_dt          DATE;
8268 l_chk_hire_dt_chg  NUMBER := 0;
8269 l_old_hire_date    DATE;
8270 l_new_hire_date    DATE;
8271 l_ret_val_asg      NUMBER;
8272 l_seq_num          VARCHAR2(2);
8273 l_rec_04_sent      NUMBER;
8274 
8275 BEGIN
8276 
8277 IF g_debug THEN
8278    Hr_Utility.set_location('Entering:   '||l_proc_name,10);
8279    Hr_Utility.set_location('... Checking if EE is a New Hire ',20);
8280 END IF;
8281 --
8282 -- Check if the assignment is attached to a payroll
8283 -- Check if ABP Pensions is processed
8284 --
8285 IF g_abp_processed_flag = 0 THEN
8286    p_data_element_value := 'N';
8287    RETURN 0;
8288 END IF;
8289 
8290 --
8291 -- Check if the EE assignment is a new hire and needs to be reported.
8292 --
8293 l_new_hire := g_new_hire_asg;
8294 l_hire_dt := g_hire_date;
8295 
8296 IF l_new_hire = 1 THEN
8297    p_data_element_value := 'Y';
8298    IF g_debug THEN
8299       Hr_Utility.set_location('... EE is a New Hire ',30);
8300    END IF;
8301    RETURN 0;
8302 ELSE
8303    p_data_element_value := 'N';
8304    IF g_debug THEN
8305       Hr_Utility.set_location('... EE is not a New Hire ',40);
8306    END IF;
8307 END IF;
8308 
8309 --
8310 --Checking the ben event log for any foreign address changes
8311 --
8312 IF g_debug THEN
8313    Hr_Utility.set_location('... Checking for Foreign Address Changes ',50);
8314 END IF;
8315 
8316 OPEN c_non_nl_chg
8317    (c_person_id         => g_person_id
8318    ,c_business_group_id => p_business_group_id
8319    ,c_ext_start_date    => g_extract_params(p_business_group_id).extract_start_date
8320    ,c_ext_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8321 
8322 FETCH c_non_nl_chg INTO l_chg_evt_exists;
8323 
8324 IF c_non_nl_chg%FOUND THEN
8325    p_data_element_value := 'Y';
8326    IF g_debug THEN
8327       Hr_Utility.set_location('...Foreign Address Changes Found',60);
8328    END IF;
8329    CLOSE c_non_nl_chg;
8330    RETURN 0;
8331 ELSE
8332    p_data_element_value := 'N';
8333    IF g_debug THEN
8334       Hr_Utility.set_location('...Foreign Address Changes Not Found',70);
8335    END IF;
8336    CLOSE c_non_nl_chg;
8337 END IF;
8338 
8339 
8340 --
8341 --Checking the ben event log for any changes from Foreign Country to NL
8342 --
8343 IF g_debug THEN
8344    Hr_Utility.set_location('... Checking for Changes from a foreign Country to NL ',50);
8345 END IF;
8346 
8347 OPEN c_to_nl_chg
8348    (c_person_id         => g_person_id
8349    ,c_business_group_id => p_business_group_id
8350    ,c_ext_start_date    => g_extract_params(p_business_group_id).extract_start_date
8351    ,c_ext_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8352 
8353 FETCH c_to_nl_chg INTO l_chg_evt_exists;
8354 
8355 IF c_to_nl_chg%FOUND THEN
8356    p_data_element_value := 'Y';
8357    IF g_debug THEN
8358       Hr_Utility.set_location('...EE Moved to NL',60);
8359    END IF;
8360    CLOSE c_to_nl_chg;
8361    RETURN 0;
8362 ELSE
8363    p_data_element_value := 'N';
8364    IF g_debug THEN
8365       Hr_Utility.set_location('...EE Did not move to NL',70);
8366    END IF;
8367    CLOSE c_to_nl_chg;
8368 END IF;
8369 
8370 IF g_debug THEN
8371    Hr_Utility.set_location('... Checking for Country Code Changes ',50);
8372 END IF;
8373 
8374 OPEN c_cntry_chg
8375    (c_person_id         => g_person_id
8376    ,c_business_group_id => p_business_group_id
8377    ,c_ext_start_date    => g_extract_params(p_business_group_id).extract_start_date
8378    ,c_ext_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8379 
8380 FETCH c_cntry_chg INTO l_chg_addr_id,l_cc_code;
8381 
8382 IF c_cntry_chg%FOUND THEN
8383    IF g_debug THEN
8384       Hr_Utility.set_location('...Country Code Changes Found',60);
8385    END IF;
8386    CLOSE c_cntry_chg;
8387    --
8388    -- Check if the change was made for the current address
8389    --
8390    OPEN c_get_cc (l_cc_code,l_chg_addr_id);
8391    FETCH c_get_cc INTO l_cc_changed;
8392    IF c_get_cc%FOUND THEN
8393       p_data_element_value := 'Y';
8394       CLOSE c_get_cc;
8395       RETURN 0;
8396    ELSE
8397       p_data_element_value := 'N';
8398       CLOSE c_get_cc;
8399    END IF;
8400 ELSE
8401    p_data_element_value := 'N';
8402    IF g_debug THEN
8403       Hr_Utility.set_location('...Country Code Changes Not Found',70);
8404    END IF;
8405    CLOSE c_cntry_chg;
8406 END IF;
8407 
8408 --
8409 -- Checking the ben event log for marital status changes
8410 -- Marital status changes are to be reported only if the EE resides
8411 -- in a foreign country
8412 --
8413 IF g_debug THEN
8414    Hr_Utility.set_location('... Checking for Marital Status Changes ',90);
8415 END IF;
8416 
8417  OPEN cur_get_foreign_coun(g_person_id);
8418 FETCH cur_get_foreign_coun INTO l_foreign_country;
8419 CLOSE cur_get_foreign_coun;
8420 
8421 IF g_debug THEN
8422    Hr_Utility.set_location('...Value of l_foreign_country is ',80);
8423 END IF;
8424 
8425 OPEN csr_chk_log_com
8426    (c_person_id         => g_person_id
8427    ,c_business_group_id => p_business_group_id
8428    ,c_ext_start_date    => g_extract_params(p_business_group_id).extract_start_date
8429    ,c_ext_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8430 
8431 FETCH csr_chk_log_com INTO l_Chg_Evt_Exists;
8432 
8433 IF csr_chk_log_com%FOUND AND l_foreign_country = 'J' THEN
8434    p_data_element_value := 'Y';
8435    IF g_debug THEN
8436       Hr_Utility.set_location('...Marital Status Changes Found',100);
8437       Hr_Utility.set_location('...EE Resides in a Foreign Country',100);
8438    END IF;
8439    CLOSE csr_chk_log_com;
8440    RETURN 0;
8441 ELSE
8442    p_data_element_value := 'N';
8443    IF g_debug THEN
8444       Hr_Utility.set_location('...Marital Status Changes Not Found',110);
8445       Hr_Utility.set_location('...Alternatively EE Resides in NL',110);
8446    END IF;
8447    CLOSE csr_chk_log_com;
8448 END IF;
8449 
8450 --
8451 -- Check to see if the EE is a late hire and if Record 04
8452 -- has never been reported to ABP earlier.
8453 -- in such cases the Record has to be sent to ABP as this is the
8454 -- first time the EE is picked up for reporting.
8455 --
8456 l_chk_hire_dt_chg := chk_chg_hire_dt
8457                      (p_person_id          => g_person_id
8458                      ,p_business_group_id  => p_business_group_id
8459                      ,p_old_hire_date      => l_old_hire_date
8460                      ,p_new_hire_date      => l_new_hire_date );
8461 
8462 IF l_chk_hire_dt_chg = 1 THEN
8463 
8464 IF g_debug THEN
8465    Hr_Utility.set_location('...EE is a late Hire ',120);
8466 END IF;
8467 
8468    l_ret_val_asg  :=  Get_Asg_Seq_Num(p_assignment_id
8469                                      ,p_business_group_id
8470                                      ,p_effective_date
8471                                      ,p_error_message
8472                                      ,l_seq_num);
8473    OPEN c_rec_04_sent(l_seq_num);
8474    FETCH c_rec_04_sent INTO l_rec_04_sent;
8475    IF c_rec_04_sent%NOTFOUND THEN
8476       CLOSE c_rec_04_sent ;
8477       p_data_element_value := 'Y';
8478       IF g_debug THEN
8479          Hr_Utility.set_location('...EE Record 04 never sent to ABP ',130);
8480       END IF;
8481       RETURN 0;
8482    ELSIF c_rec_04_sent%FOUND THEN
8483       CLOSE c_rec_04_sent ;
8484       IF g_debug THEN
8485          Hr_Utility.set_location('...EE Record 04 sent to ABP earlier',140);
8486       END IF;
8487       p_data_element_value := 'N';
8488    END IF;
8489 
8490 ELSE
8491    IF g_debug THEN
8492       Hr_Utility.set_location('...EE is a not a late Hire ',150);
8493    END IF;
8494    p_data_element_value := 'N';
8495 END IF;
8496 
8497 IF g_debug THEN
8498    Hr_Utility.set_location('... Value of p_data_element_value is '
8499                                          ||p_data_element_value,160);
8500    Hr_Utility.set_location('Leaving:   '||l_proc_name, 170);
8501 END IF;
8502 
8503 l_return_value := 0;
8504 
8505 RETURN l_return_value;
8506 
8507 EXCEPTION
8508    WHEN OTHERS THEN
8509     p_error_message :='SQL-ERRM :'||SQLERRM;
8510     p_data_element_value := 'N';
8511     Hr_Utility.set_location('... WHEN OTHERS EXCEPTION',180);
8512     Hr_Utility.set_location('..'||p_error_message,190);
8513     Hr_Utility.set_location('Leaving: '||l_proc_name,200);
8514     RETURN l_return_value;
8515 END Record04_Display_Criteria;
8516 
8517 --============================================================================
8518 -- Function to derive the display criteria for Record 08
8519 --============================================================================
8520 FUNCTION Record08_Display_Criteria
8521         (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
8522         ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
8523         ,p_effective_date       IN  DATE
8524         ,p_error_message        OUT NOCOPY VARCHAR2
8525         ,p_data_element_value   OUT NOCOPY VARCHAR2)
8526 RETURN NUMBER IS
8527 
8528 --
8529 -- Cursor to check if there are any changes in the ABP Pension Salary
8530 --
8531 CURSOR c_get_override_salary IS
8532 SELECT fnd_number.canonical_to_number(nvl(new_val1,'0'))
8533   FROM ben_ext_chg_evt_log
8534  WHERE person_id = g_person_id
8535    AND fnd_number.canonical_to_number(prmtr_01) = p_assignment_id
8536    AND chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
8537                       AND g_extract_params(p_business_group_id).extract_end_date
8538    AND chg_evt_cd = 'COAPS'
8539    AND ext_chg_evt_log_id =
8540        (SELECT MAX(ext_chg_evt_log_id)
8541           FROM ben_ext_chg_evt_log
8542          WHERE person_id = g_person_id
8543            AND fnd_number.canonical_to_number(prmtr_01) = p_assignment_id
8544            AND chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
8545                               AND g_extract_params(p_business_group_id).extract_end_date
8546            AND chg_evt_cd = 'COAPS');
8547 
8548 --
8549 -- Cursor to fetch the month for the effective date
8550 --
8551 CURSOR c_get_month IS
8552 SELECT TO_CHAR(p_effective_date,'MM')
8553   FROM dual;
8554 --
8555 -- Cursor to check if Rec 08 was sent to ABP in the current year.
8556 -- fot this assignment . If not sent then trigger a send
8557 --
8558 CURSOR c_rec_08_sent(c_start_of_yr IN DATE
8559                      ,c_asg_seq_no  IN VARCHAR2 ) IS
8560 SELECT 1
8561   FROM ben_ext_rslt_dtl     dtl
8562       ,ben_ext_rslt         res
8563       ,ben_ext_rcd          rcd
8564       ,ben_ext_rcd_in_file  rin
8565       ,ben_ext_dfn          dfn
8566 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
8567                            FROM pqp_extract_attributes
8568                           WHERE ext_dfn_type = 'NL_FPR')
8569  and dtl.person_id    = g_person_id
8570  and ext_stat_cd      = 'A'
8571  AND TRUNC(res.eff_dt) BETWEEN  c_start_of_yr
8572      AND TRUNC(g_extract_params(p_business_group_id).extract_start_date) - 1
8573  AND rin.ext_file_id  = dfn.ext_file_id
8574  AND rin.ext_rcd_id   = rcd.ext_rcd_id
8575  AND dfn.ext_dfn_id   = res.ext_dfn_id
8576  and dtl.ext_rslt_id  = res.ext_rslt_id
8577  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
8578  AND dtl.val_04       = c_asg_seq_no
8579  AND rin.seq_num      = 7;
8580 
8581 l_override_exists  NUMBER;
8582 l_month            VARCHAR2(2);
8583 l_chg_evt_exists   VARCHAR2(2);
8584 l_return_value     NUMBER := -1;
8585 l_new_hire         NUMBER := 0;
8586 l_balance_amount   NUMBER := 0;
8587 l_override_value   NUMBER := 0;
8588 l_person_id        per_all_people_f.person_id%TYPE;
8589 l_asg_action_id    pay_assignment_actions.assignment_action_id%TYPE;
8590 l_balance_id       pay_balance_types.balance_type_id%TYPE;
8591 l_proc_name        VARCHAR2(150) := g_proc_name ||'Record08_Display_Criteria';
8592 l_hire_dt          DATE;
8593 l_08_sent          NUMBER;
8594 l_ret_val_asg      NUMBER;
8595 l_seq_num          VARCHAR2(2);
8596 
8597 BEGIN
8598 
8599 Hr_Utility.set_location('Entering:   '||l_proc_name,10);
8600 
8601 --
8602 -- Check if the assignment is attached to a payroll
8603 -- Check if ABP Pensions is processed
8604 --
8605 IF g_abp_processed_flag = 0 THEN
8606    p_data_element_value := 'N';
8607    RETURN 0;
8608 END IF;
8609 
8610 --
8611 -- Check if the EE assignment is terminated in the prev year.
8612 -- do not display Record 08 in that case.
8613 --
8614 IF chk_asg_term_py (p_assignment_id => p_assignment_id
8615                    ,p_ext_st        => g_extract_params(p_business_group_id).extract_start_date) THEN
8616    p_data_element_value := 'N';
8617    RETURN 0;
8618 END IF;
8619 
8620 Hr_Utility.set_location('...Deriving def bal id ',20);
8621 
8622 OPEN  csr_defined_bal('ABP Pension Salary'
8623                      ,'Assignment Year To Date'
8624                      ,p_business_group_id);
8625 FETCH csr_defined_bal INTO l_balance_id;
8626 CLOSE csr_defined_bal;
8627 
8628 Hr_Utility.set_location('... Value of def bal id is'||l_balance_id,30);
8629 Hr_Utility.set_location('...Deriving ass act id ',40);
8630 
8631 IF l_balance_id IS NOT NULL THEN
8632 
8633    OPEN csr_asg_act1 (
8634         c_assignment_id => p_assignment_id
8635        ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
8636        ,c_con_set_id    => NULL
8637        ,c_start_date    => g_extract_params(p_business_group_id).extract_start_date
8638        ,c_end_date      => g_extract_params(p_business_group_id).extract_end_date);
8639    FETCH csr_asg_act1 INTO l_asg_action_id;
8640    Hr_Utility.set_location('... Value of ass act id is'||l_asg_action_id,45);
8641    CLOSE csr_asg_act1;
8642 
8643    IF l_asg_action_id IS NOT NULL THEN
8644       Hr_Utility.set_location('...Deriving balance value ',50);
8645       l_balance_amount := pay_balance_pkg.get_value
8646                           (p_defined_balance_id   => l_balance_id
8647                           ,p_assignment_action_id => l_asg_action_id);
8648       Hr_Utility.set_location('...Value of l_balance_amount is:'
8649                                ||l_balance_amount, 25);
8650       l_balance_amount := NVL(l_balance_amount,0);
8651    END IF;
8652 
8653 END IF;
8654 
8655 Hr_Utility.set_location('...Checking of Ext is running for Jan ',60);
8656 --
8657 -- Check to see if the extract is being run for JAN,
8658 -- If it is JAN, we need to report the pension salary
8659 --
8660  OPEN c_get_month;
8661 FETCH c_get_month INTO l_month;
8662 CLOSE c_get_month;
8663 
8664 IF l_month = '01' AND NVL(l_balance_amount,0) <> 0 THEN
8665    Hr_Utility.set_location('...Ext is running for Jan ',70);
8666    p_data_element_value := 'Y';
8667    RETURN 0;
8668 ELSE
8669    Hr_Utility.set_location('...Ext is not running for Jan ',80);
8670    p_data_element_value := 'N';
8671 END IF;
8672 
8673 --
8674 -- Fetch the overridden value if there is any override changes in
8675 -- the ASG EIT
8676 --
8677 Hr_Utility.set_location('...Checking for ABP Pension Salary Override ',90);
8678 
8679  OPEN c_get_override_salary;
8680 FETCH c_get_override_salary INTO l_override_value;
8681 IF c_get_override_salary%FOUND THEN
8682    CLOSE c_get_override_salary;
8683    IF nvl(l_override_value,0) <> 0 THEN
8684       p_data_element_value := 'Y';
8685       Hr_Utility.set_location('...ABP Pension Salary Override Found ',100);
8686       RETURN 0;
8687    ELSE
8688       Hr_Utility.set_location('...ABP Pension Salary Override Not Found ',110);
8689       p_data_element_value := 'N';
8690    END IF;
8691 ELSE
8692    CLOSE c_get_override_salary;
8693 END IF;
8694 
8695 --
8696 -- Check if the EE assignment is a new hire and needs to be reported.
8697 --
8698 Hr_Utility.set_location('... Checking if EE is a New Hire ',20);
8699 
8700 l_new_hire := g_new_hire_asg;
8701 l_hire_dt  := g_hire_date;
8702 
8703 IF l_new_hire = 1 AND NVL(l_balance_amount,0) <> 0 THEN
8704    p_data_element_value := 'Y';
8705    Hr_Utility.set_location('... EE is a New Hire ',120);
8706    RETURN 0;
8707 ELSE
8708    p_data_element_value := 'N';
8709    Hr_Utility.set_location('... EE is not a New Hire ',130);
8710 END IF;
8711 
8712    l_ret_val_asg  := Get_Asg_Seq_Num(p_assignment_id
8713                                      ,p_business_group_id
8714                                      ,p_effective_date
8715                                      ,p_error_message
8716                                      ,l_seq_num);
8717 
8718 
8719 OPEN c_rec_08_sent( to_date('01/01/'||to_char(p_effective_date,'YYYY'),'DD/MM/YYYY')
8720                    ,l_seq_num);
8721 FETCH c_rec_08_sent INTO l_08_sent;
8722 IF c_rec_08_sent%NOTFOUND AND NVL(l_balance_amount,0) <> 0 THEN
8723    p_data_element_value := 'Y';
8724    Hr_Utility.set_location('... Data never sent  ',120);
8725    CLOSE c_rec_08_sent;
8726    RETURN 0;
8727 ELSE
8728    CLOSE c_rec_08_sent;
8729    p_data_element_value := 'N';
8730    Hr_Utility.set_location('... Data Was sent ',130);
8731 END IF;
8732 
8733 hr_utility.set_location('Leaving:   '||l_proc_name,140);
8734 l_return_value := 0;
8735 
8736 RETURN l_return_value;
8737 
8738 EXCEPTION
8739    WHEN OTHERS THEN
8740     p_error_message :='SQL-ERRM :'||SQLERRM;
8741     p_data_element_value := 'N';
8742     Hr_Utility.set_location('...WHEN OTHERS EXCEPTION',150);
8743     Hr_Utility.set_location('..'||p_error_message,160);
8744     Hr_Utility.set_location('Leaving: '||l_proc_name,170);
8745     RETURN l_return_value;
8746 END Record08_Display_Criteria;
8747 
8748 --=============================================================================
8749 -- Function to derive the display criteria for Record 09
8750 --=============================================================================
8751 FUNCTION Record09_Display_Criteria
8752         (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
8753         ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
8754         ,p_effective_date     IN  DATE
8755         ,p_error_message      OUT NOCOPY VARCHAR2
8756         ,p_data_element_value OUT NOCOPY VARCHAR2)
8757 RETURN NUMBER IS
8758 
8759 l_proc_name   VARCHAR2(150) := g_proc_name ||'Record09_Display_Criteria';
8760 
8761 BEGIN
8762 
8763 Hr_Utility.set_location('Entering:   '||l_proc_name,10);
8764 --
8765 -- Derive the value of Record 09 display criteria based on the
8766 -- value set to the global variable in full profile criteria
8767 --
8768 IF l_rec_09_disp = 'Y' THEN
8769    p_data_element_value := 'Y';
8770 ELSE
8771    p_data_element_value := 'N';
8772 END IF;
8773 
8774 Hr_Utility.set_location('Value of p_data_element_value is : '
8775                                                  ||p_data_element_value,20);
8776 Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
8777 
8778 RETURN 0;
8779 
8780 END Record09_Display_Criteria;
8781 
8782 --=============================================================================
8783 -- Function to check if Record12 needs to be displayed
8784 --=============================================================================
8785 FUNCTION Record12_Display_Criteria
8786         (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
8787         ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
8788         ,p_effective_date     IN  DATE
8789         ,p_error_message      OUT NOCOPY VARCHAR2
8790         ,p_data_element_value OUT NOCOPY VARCHAR2)
8791 RETURN NUMBER IS
8792 
8793 l_proc_name   VARCHAR2(150) := g_proc_name ||'Record12_Display_Criteria';
8794 
8795 BEGIN
8796 Hr_Utility.set_location('Entering :   '||l_proc_name,10);
8797 --
8798 -- Derive the value of Record 12 display criteria based on the
8799 -- value set to the global variable in full profile criteria
8800 --
8801 IF l_rec_12_disp = 'Y' THEN
8802    p_data_element_value := 'Y';
8803 ELSE
8804    p_data_element_value := 'N';
8805 END IF;
8806 
8807 Hr_Utility.set_location('Value of p_data_element_value is: '
8808                                        ||p_data_element_value,20);
8809 Hr_Utility.set_location('Leaving:   '||l_proc_name,30);
8810 
8811 RETURN 0;
8812 
8813 END Record12_Display_Criteria;
8814 
8815 --=============================================================================
8816 -- Function to derive the display criteria for Record 20
8817 --=============================================================================
8818 FUNCTION Record20_Display_Criteria
8819         (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
8820         ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
8821         ,p_effective_date     IN  DATE
8822         ,p_error_message      OUT NOCOPY VARCHAR2
8823         ,p_data_element_value OUT NOCOPY VARCHAR2)
8824 RETURN NUMBER IS
8825 
8826 BEGIN
8827 
8828 --
8829 -- All SI records are obselete and are not reported to ABP
8830 -- so there is no need to display them
8831 --
8832 p_data_element_value := 'N';
8833 
8834 RETURN 0;
8835 
8836 END Record20_Display_Criteria;
8837 
8838 --============================================================================
8839 -- Function to derive the display criteria for Record 21
8840 --============================================================================
8841 FUNCTION Record21_Display_Criteria
8842        (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
8843        ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
8844        ,p_effective_date       IN  DATE
8845        ,p_error_message        OUT NOCOPY VARCHAR2
8846        ,p_data_element_value   OUT NOCOPY VARCHAR2)
8847 RETURN NUMBER IS
8848 
8849 BEGIN
8850 --
8851 -- All SI records are obselete and are not reported to ABP
8852 -- so there is no need to display them
8853 --
8854 
8855 p_data_element_value := 'N';
8856 
8857 RETURN 0;
8858 
8859 END Record21_Display_Criteria;
8860 
8861 --============================================================================
8862 -- Function to derive the display criteria for Record 22
8863 --============================================================================
8864 FUNCTION Record22_Display_Criteria
8865        (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
8866        ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
8867        ,p_effective_date       IN  DATE
8868        ,p_error_message        OUT NOCOPY VARCHAR2
8869        ,p_data_element_value   OUT NOCOPY VARCHAR2)
8870 RETURN NUMBER IS
8871 
8872 BEGIN
8873 --
8874 -- The SI records are obselete and are not reported to ABP
8875 -- so there is no need to display them
8876 --
8877 
8878 p_data_element_value := 'N';
8879 
8880 RETURN 0;
8881 
8882 END Record22_Display_Criteria;
8883 
8884 --============================================================================
8885 -- Function to derive the display criteria for Record 05
8886 --============================================================================
8887 FUNCTION Record05_Display_Criteria
8888      ( p_assignment_id         IN per_all_assignments_f.assignment_id%TYPE
8889       ,p_business_group_id     IN per_all_assignments_f.business_group_id%TYPE
8890       ,p_effective_date        IN DATE
8891       ,p_error_message        OUT NOCOPY VARCHAR2
8892       ,p_data_element_value   OUT NOCOPY VARCHAR2)
8893 RETURN NUMBER IS
8894 
8895 l_return_value NUMBER        := 0;
8896 l_proc_name    VARCHAR2(150) := 'Record05_Display_Criteria';
8897 
8898 BEGIN
8899 
8900 Hr_Utility.set_location('Entering:   '||l_proc_name, 10);
8901 
8902 --
8903 -- Always display record 05 as this causes issues with the
8904 -- secondary assignments. Unnecessary records are later deleted as part of
8905 -- the extract post process
8906 --
8907 
8908 p_data_element_value := 'Y';
8909 
8910 Hr_Utility.set_location('... The data element value is : '
8911                                            ||p_data_element_value,20);
8912 
8913 Hr_Utility.set_location('Leaving:   '||l_proc_name, 30);
8914 
8915 l_return_value := 0;
8916 
8917 RETURN l_return_value;
8918 
8919 EXCEPTION
8920    WHEN OTHERS THEN
8921     p_error_message :='SQL-ERRM :'||SQLERRM;
8922     Hr_Utility.set_location('...WHEN OTHERS EXCEPTION',40);
8923     p_data_element_value := 'N';
8924     Hr_Utility.set_location('...'||p_error_message,50);
8925     Hr_Utility.set_location('Leaving: '||l_proc_name,60);
8926     l_return_value := 1;
8927     RETURN l_return_value;
8928 
8929 END Record05_Display_Criteria;
8930 
8931 --============================================================================
8932 --This is used to decide the Record40_30 hide  or show
8933 --============================================================================
8934 FUNCTION Record30_40_Display_Criteria
8935           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
8936            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
8937            ,p_effective_date       IN  Date
8938            ,p_sub_cat              IN  Varchar2
8939            ,p_error_message        OUT NOCOPY Varchar2
8940 	   ,p_data_element_value   OUT NOCOPY Varchar2
8941           ) RETURN Number IS
8942 
8943 --cursor to check if ASG EIT rows exist
8944 CURSOR c_asg_rows_exist IS
8945 SELECT 1
8946   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
8947 WHERE  chg_evt_cd = 'COAPPD'
8948   AND  prmtr_01 = 'ASG'
8949   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
8950   AND  pty.pension_sub_category = p_sub_cat
8951   AND  prmtr_03 = 'Y'
8952   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
8953   AND  person_id = (SELECT person_id
8954                       FROM per_all_assignments_f
8955                     WHERE  assignment_id = p_assignment_id
8956                       AND  p_effective_date BETWEEN effective_start_date
8957                       AND  effective_end_date
8958                    )
8959   AND  bec.business_group_id = p_business_group_id;
8960 
8961 --cursor to check if ORG EIT rows exist
8962 CURSOR c_org_rows_exist(c_org_id IN Number) IS
8963 SELECT 1
8964   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
8965 WHERE  chg_evt_cd = 'COAPPD'
8966   AND  prmtr_01 = 'ORG'
8967   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
8968   AND  pty.pension_sub_category = p_sub_cat
8969   AND  prmtr_03 = 'Y'
8970   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
8971   AND  bec.business_group_id = p_business_group_id;
8972 
8973 --cursor to get the ASG EIT log rows
8974 CURSOR c_get_asg_rows IS
8975 SELECT 1
8976   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
8977 WHERE  chg_evt_cd = 'COAPPD'
8978   AND  prmtr_01 = 'ASG'
8979   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
8980   AND  prmtr_03 = 'Y'
8981   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
8982   AND  pty.pension_sub_category = p_sub_cat
8983   AND  person_id = (SELECT person_id
8984                       FROM per_all_assignments_f
8985                     WHERE  assignment_id = p_assignment_id
8986                      AND   p_effective_date BETWEEN effective_start_date
8987                      AND   effective_end_date
8988                    )
8989   AND  bec.business_group_id = p_business_group_id
8990   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
8991   AND  g_extract_params(p_business_group_id).extract_end_date
8992 ORDER BY ext_chg_evt_log_id;
8993 
8994 --cursor to get the ORG EIT log rows
8995 CURSOR c_get_org_rows(c_org_id IN Number,c_hire_date IN Date) IS
8996 SELECT 1
8997   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
8998 WHERE  chg_evt_cd = 'COAPPD'
8999   AND  prmtr_01 = 'ORG'
9000   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
9001   AND  prmtr_03 = 'Y'
9002   AND  pty.pension_sub_category = p_sub_cat
9003   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
9004   AND  bec.business_group_id = p_business_group_id
9005   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
9006   AND  g_extract_params(p_business_group_id).extract_end_date
9007   AND  chg_eff_dt >= c_hire_date
9008 ORDER BY ext_chg_evt_log_id;
9009 
9010 --Cursor to find the named hierarchy associated with the BG
9011 CURSOR c_find_named_hierarchy IS
9012 SELECT org_information1
9013  FROM hr_organization_information
9014 WHERE organization_id = p_business_group_id
9015  AND org_information_context = 'NL_BG_INFO';
9016 
9017 --Cursor to find the valid version id for the particular named hierarchy
9018 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id IN Number) IS
9019 SELECT ORG_STRUCTURE_VERSION_ID
9020   FROM per_org_structure_versions_v
9021 WHERE organization_structure_id = c_hierarchy_id
9022   AND p_effective_date BETWEEN date_from
9023   AND Nvl(date_to,Hr_Api.g_eot);
9024 
9025 --Cursor to find the valid version id for a particular business group
9026 CURSOR c_find_ver_frm_bg IS
9027 SELECT ORG_STRUCTURE_VERSION_ID
9028   FROM per_org_structure_versions_v
9029 WHERE business_group_id = p_business_group_id
9030   AND p_effective_date BETWEEN date_from
9031   AND Nvl( date_to,Hr_Api.g_eot);
9032 
9033 --Cursor to find the parent id from the org id
9034 CURSOR c_find_parent_id(c_org_id IN Number
9035                        ,c_version_id IN Number) IS
9036 SELECT organization_id_parent
9037   FROM per_org_structure_elements
9038   WHERE organization_id_child = c_org_id
9039     AND org_structure_version_id = c_version_id
9040     AND business_group_id = p_business_group_id;
9041 
9042 --cursor to find the org id for the current asg
9043 CURSOR c_find_org_id IS
9044 SELECT organization_id
9045   FROM per_all_assignments_f
9046 WHERE  assignment_id = p_assignment_id
9047   AND  p_effective_date BETWEEN effective_start_date
9048   AND  effective_end_date;
9049 
9050 -- Cursor to get the hire date of the person
9051 CURSOR c_hire_dt IS
9052 SELECT max(date_start)
9053  FROM  per_all_assignments_f asg
9054       ,per_periods_of_service pps
9055  WHERE pps.person_id     = asg.person_id
9056    AND asg.assignment_id = p_assignment_id
9057    AND pps.business_group_id = p_business_group_id
9058    AND date_start <= p_effective_date;
9059 
9060 --cursor to check if run results exist for any FUR/IPAP Pension Types for this assignment
9061 CURSOR c_run_results_exist IS
9062 SELECT pty.pension_type_id
9063 FROM   pay_run_results prr,
9064        pay_payroll_actions ppa,
9065        pay_assignment_actions paa,
9066        pay_element_type_extra_info pei,
9067        pqp_pension_types_f pty
9068 WHERE  paa.assignment_action_id = prr.assignment_action_id
9069   AND  paa.payroll_action_id = ppa.payroll_action_id
9070   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
9071   AND  g_extract_params(p_business_group_id).extract_end_date
9072   AND  paa.assignment_id = p_assignment_id
9073   AND  pei.element_type_id = prr.element_type_id
9074   AND  pei.information_type = 'PQP_NL_ABP_DEDUCTION'
9075   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
9076   AND  pei.eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
9077   AND  pty.pension_sub_category = p_sub_cat;
9078 
9079 
9080 l_proc_name       Varchar2(150) := 'Record40_30_Disp_Criteria';
9081 l_return_value    Number := -1;
9082 l_named_hierarchy       Number;
9083 l_version_id            per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
9084 l_rows_exist   Number := 0;
9085 l_asg_rows_exist  Number;
9086 l_org_rows_exist  Number;
9087 l_org_id           Number;
9088 l_loop_again       Number;
9089 l_age              Number;
9090 l_hire_date Date;
9091 l_pt    Number;
9092 l_hired  Number := 0;
9093 
9094 BEGIN
9095    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
9096    Hr_Utility.set_location('sub category : '||p_sub_cat,10);
9097 
9098    OPEN c_hire_dt;
9099    FETCH c_hire_dt INTO l_hire_date;
9100    CLOSE c_hire_dt;
9101    IF l_hire_date BETWEEN g_extract_params(p_business_group_id).extract_start_date
9102      AND g_extract_params(p_business_group_id).extract_end_date THEN
9103      l_hired := 1;
9104    END IF;
9105 
9106    OPEN c_asg_rows_exist;
9107    FETCH c_asg_rows_exist INTO l_asg_rows_exist;
9108    IF c_asg_rows_exist%FOUND THEN
9109       CLOSE c_asg_rows_exist;
9110       Hr_Utility.set_location('found rows at the assignment eit level',15);
9111       OPEN c_get_asg_rows;
9112       FETCH c_get_asg_rows INTO l_rows_exist;
9113       CLOSE c_get_asg_rows;
9114    ELSE
9115       CLOSE c_asg_rows_exist;
9116       --go up the org hierarchy to find the rows at some org eit level
9117       -- find the org the assignment is attached to
9118       OPEN c_find_org_id;
9119       FETCH c_find_org_id INTO l_org_id;
9120       CLOSE c_find_org_id;
9121 
9122       --first chk to see if a named hierarchy exists for the BG
9123       OPEN c_find_named_hierarchy;
9124       FETCH c_find_named_hierarchy INTO l_named_hierarchy;
9125       -- if a named hiearchy is found , find the valid version on that date
9126       IF c_find_named_hierarchy%FOUND THEN
9127          CLOSE c_find_named_hierarchy;
9128          -- now find the valid version on that date
9129          OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
9130          FETCH c_find_ver_frm_hierarchy INTO l_version_id;
9131          --if no valid version is found, try to get it frm the BG
9132          IF c_find_ver_frm_hierarchy%NOTFOUND THEN
9133             CLOSE c_find_ver_frm_hierarchy;
9134             -- find the valid version id from the BG
9135             OPEN c_find_ver_frm_bg;
9136             FETCH c_find_ver_frm_bg INTO l_version_id;
9137             CLOSE c_find_ver_frm_bg;
9138          -- else a valid version has been found for the named hierarchy
9139          ELSE
9140             CLOSE c_find_ver_frm_hierarchy;
9141          END IF; --end of if no valid version found
9142       -- else find the valid version from BG
9143       ELSE
9144          CLOSE c_find_named_hierarchy;
9145          --now find the version number from the BG
9146          OPEN c_find_ver_frm_bg;
9147          FETCH c_find_ver_frm_bg INTO l_version_id;
9148          CLOSE c_find_ver_frm_bg;
9149       END IF; -- end of if named hierarchy found
9150 
9151       -- loop through the org hierarchy to find the participation start date at
9152       -- this org level or its parents
9153       l_loop_again := 1;
9154       WHILE (l_loop_again = 1)
9155 
9156       LOOP
9157       Hr_Utility.set_location('searching at org level : '||l_org_id,25);
9158       OPEN c_org_rows_exist(l_org_id);
9159       FETCH c_org_rows_exist INTO l_org_rows_exist;
9160       IF c_org_rows_exist%FOUND THEN
9161          CLOSE c_org_rows_exist;
9162          OPEN c_get_org_rows(l_org_id,l_hire_date);
9163          FETCH c_get_org_rows INTO l_rows_exist;
9164          CLOSE c_get_org_rows;
9165          l_loop_again := 0;
9166       ELSE
9167          --search at the parent level next
9168          CLOSE c_org_rows_exist;
9169          OPEN c_find_parent_id(l_org_id,l_version_id);
9170          FETCH c_find_parent_id INTO l_org_id;
9171          IF c_find_parent_id%NOTFOUND THEN
9172             l_loop_again := 0;
9173             CLOSE c_find_parent_id;
9174          ELSE
9175             CLOSE c_find_parent_id;
9176          END IF;
9177       END IF;
9178      END LOOP;
9179 END IF;
9180 IF l_rows_exist <> 1 THEN
9181    IF l_hired = 1 THEN
9182       --chk if there is any run result
9183      OPEN c_run_results_exist;
9184      FETCH c_run_results_exist INTO l_pt;
9185      IF c_run_results_exist%FOUND THEN
9186         l_rows_exist := 1;
9187         CLOSE c_run_results_exist;
9188      ELSE
9189         CLOSE c_run_results_exist;
9190      END IF;
9191   END IF;
9192 END IF;
9193 Hr_Utility.set_location('rows exist : '||l_rows_exist,30);
9194 IF l_rows_exist = 1 THEN
9195    IF p_sub_cat = 'IPAP' THEN
9196       p_data_element_value := 'Y';
9197       l_return_value := 0;
9198    ELSIF p_sub_cat = 'FUR_S' THEN
9199       --for fur now check to see if the person needs to be reported, this is if he is
9200       --<= 65 years old
9201       l_age := Get_Age(p_assignment_id
9202                    ,p_effective_date);
9203       IF l_age <= 65 THEN
9204          p_data_element_value := 'Y';
9205          l_return_value := 0;
9206       ELSE
9207          p_data_element_value := 'N';
9208          l_return_value := 0;
9209       END IF;
9210    END IF;
9211 ELSE
9212    p_data_element_value := 'N';
9213    l_return_value := 0;
9214 END IF;
9215 Hr_Utility.set_location('data element value : '||p_data_element_value,35);
9216 Hr_Utility.set_location('Leaving:   '||l_proc_name, 40);
9217 RETURN l_return_value;
9218 EXCEPTION
9219    WHEN Others THEN
9220     p_error_message :='SQL-ERRM :'||SQLERRM;
9221     p_data_element_value := 'N';
9222     Hr_Utility.set_location('..'||p_error_message,85);
9223     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
9224     l_return_value := 1;
9225     RETURN l_return_value;
9226 END Record30_40_Display_Criteria;
9227 
9228 --============================================================================
9229 --This is used to decide the Record41_31 hide  or show
9230 --============================================================================
9231 FUNCTION Record31_41_Display_Criteria
9232           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
9233            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
9234            ,p_effective_date       IN  Date
9235            ,p_record_number        IN  Number
9236            ,p_error_message        OUT NOCOPY Varchar2
9237 	   ,p_data_element_value   OUT NOCOPY Varchar2
9238           ) RETURN Number IS
9239 
9240 l_proc_name             Varchar2(130) := 'Record31_41_Display_Criteria';
9241 l_return_value          Number := 1;
9242 l_age                   Number;
9243 
9244 BEGIN
9245 Hr_Utility.set_location('Entering   -------- : '||l_proc_name,10);
9246 IF p_record_number = 31 THEN
9247    IF l_rec_31_disp = 'Y' THEN
9248       p_data_element_value := 'Y';
9249       l_return_value := 0;
9250    ELSE
9251       p_data_element_value := 'N';
9252       l_return_value := 0;
9253    END IF;
9254 ELSIF p_record_number = 41 THEN
9255       --now check to see if the person needs to be reported, this is if he is
9256       --<= 65 years old
9257    l_age := Get_Age(p_assignment_id
9258                    ,p_effective_date);
9259    IF l_age <= 65 THEN
9260       IF g_fur_contrib_kind = 'A' THEN
9261          IF l_basis_rec_41_disp = 'Y' THEN
9262             p_data_element_value := 'Y';
9263          ELSE
9264             p_data_element_value := 'N';
9265          END IF;
9266          l_return_value := 0;
9267       ELSE
9268          IF l_contrib_rec_41_disp = 'Y' THEN
9269             p_data_element_value := 'Y';
9270          ELSE
9271             p_data_element_value := 'N';
9272          END IF;
9273          l_return_value := 0;
9274       END IF;
9275    ELSE
9276       p_data_element_value := 'N';
9277       l_return_value := 0;
9278    END IF;
9279 END IF;
9280 
9281 RETURN l_return_value ;
9282 
9283 EXCEPTION
9284    WHEN Others THEN
9285     p_error_message :='SQL-ERRM :'||SQLERRM;
9286     p_data_element_value := 'N';
9287     Hr_Utility.set_location('..'||p_error_message,85);
9288     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
9289     l_return_value := 1;
9290     RETURN l_return_value;
9291 END Record31_41_Display_Criteria;
9292 
9293 --============================================================================
9294 --This is used to derive the participation end date in the case , when enrollment has
9295 --come from the ORG EIT on a start of employment
9296 --============================================================================
9297 FUNCTION Get_Participation_End
9298          (p_assignment_id  IN per_all_assignments_f.assignment_id%TYPE
9299          ,p_business_group_id IN per_all_assignments_f.business_group_id%TYPE
9300          ,p_pension_type_id IN pqp_pension_types_f.pension_type_id%TYPE
9301          ,p_date_earned     IN Date
9302          ,p_end_date        OUT NOCOPY Date
9303          ) RETURN Number IS
9304 
9305 l_org_id hr_all_organization_units.organization_id%TYPE;
9306 l_ret_value Number := 0; --return
9307 l_org_info_id hr_organization_information.org_information_id%TYPE;
9308 l_named_hierarchy       Number;
9309 l_version_id            per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
9310 l_loop_again Number;
9311 l_is_org_info_valid Varchar2(1);
9312 
9313 --Cursor to find the org id from the assignment id
9314 CURSOR c_find_org_id IS
9315 SELECT organization_id
9316   FROM per_all_assignments_f
9317 WHERE assignment_id = p_assignment_id
9318   AND Trunc(p_date_earned) BETWEEN effective_start_date AND effective_end_date
9319   AND business_group_id = p_business_group_id;
9320 
9321 --Cursor to find the named hierarchy associated with the BG
9322 CURSOR c_find_named_hierarchy IS
9323 SELECT org_information1
9324  FROM hr_organization_information
9325 WHERE organization_id = p_business_group_id
9326  AND org_information_context = 'NL_BG_INFO';
9327 
9328 --Cursor to find the valid version id for the particular named hierarchy
9329 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id IN Number) IS
9330 SELECT ORG_STRUCTURE_VERSION_ID
9331   FROM per_org_structure_versions_v
9332 WHERE organization_structure_id = c_hierarchy_id
9333   AND p_date_earned BETWEEN date_from
9334   AND Nvl(date_to,Hr_Api.g_eot);
9335 
9336 --Cursor to find the valid version id for a particular business group
9337 CURSOR c_find_ver_frm_bg IS
9338 SELECT ORG_STRUCTURE_VERSION_ID
9339   FROM per_org_structure_versions_v
9340 WHERE business_group_id = p_business_group_id
9341   AND p_date_earned BETWEEN date_from
9342   AND Nvl( date_to,Hr_Api.g_eot);
9343 
9344 --Cursor to find the parent id from the org id
9345 CURSOR c_find_parent_id(c_org_id IN Number
9346                        ,c_version_id IN Number) IS
9347 SELECT organization_id_parent
9348   FROM per_org_structure_elements
9349   WHERE organization_id_child = c_org_id
9350     AND org_structure_version_id = c_version_id
9351     AND business_group_id = p_business_group_id;
9352 
9353 --Cursor to find if there is any information record at the org level
9354 --if so return the org info id
9355 CURSOR c_get_valid_org_info(c_org_id IN hr_all_organization_units.organization_id%TYPE) IS
9356    SELECT hoi.org_information_id
9357      FROM hr_organization_information hoi
9358      WHERE hoi.org_information_context      = 'PQP_NL_ABP_PT'
9359        AND hoi.org_information3             = To_Char(p_pension_type_id)
9360        AND NVL(hoi.org_information7,'Y')    = 'Y'
9361        AND hoi.organization_id              = c_org_id;
9362 
9363 --Cursor to find the participation end date from org level information
9364 CURSOR c_get_org_info(c_org_id IN hr_organization_information.organization_id%TYPE) IS
9365 SELECT Fnd_Date.canonical_to_date(Nvl(hoi.org_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)))
9366   FROM hr_organization_information hoi
9367      WHERE hoi.org_information_context      = 'PQP_NL_ABP_PT'
9368        AND hoi.org_information3             = To_Char(p_pension_type_id)
9369        AND hoi.org_information6             = 'Y'
9370        AND NVL(hoi.org_information7,'Y')    = 'Y'
9371        AND hoi.organization_id              = c_org_id
9372        AND p_date_earned BETWEEN Fnd_Date.canonical_to_date(hoi.org_information1)
9373        AND  Fnd_Date.canonical_to_date(Nvl(hoi.org_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)));
9374 
9375 BEGIN
9376         -- find the org the assignment is attached to
9377         OPEN c_find_org_id;
9378         FETCH c_find_org_id INTO l_org_id;
9379         CLOSE c_find_org_id;
9380 
9381         --first chk to see if a named hierarchy exists for the BG
9382         OPEN c_find_named_hierarchy;
9383         FETCH c_find_named_hierarchy INTO l_named_hierarchy;
9384         -- if a named hiearchy is found , find the valid version on that date
9385         IF c_find_named_hierarchy%FOUND THEN
9386            CLOSE c_find_named_hierarchy;
9387            -- now find the valid version on that date
9388            OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
9389            FETCH c_find_ver_frm_hierarchy INTO l_version_id;
9390              --if no valid version is found, try to get it frm the BG
9391              IF c_find_ver_frm_hierarchy%NOTFOUND THEN
9392                 CLOSE c_find_ver_frm_hierarchy;
9393                 -- find the valid version id from the BG
9394                 OPEN c_find_ver_frm_bg;
9395                 FETCH c_find_ver_frm_bg INTO l_version_id;
9396                 CLOSE c_find_ver_frm_bg;
9397              -- else a valid version has been found for the named hierarchy
9398              ELSE
9399                 CLOSE c_find_ver_frm_hierarchy;
9400              END IF; --end of if no valid version found
9401         -- else find the valid version from BG
9402         ELSE
9403            CLOSE c_find_named_hierarchy;
9404            --now find the version number from the BG
9405            OPEN c_find_ver_frm_bg;
9406            FETCH c_find_ver_frm_bg INTO l_version_id;
9407            CLOSE c_find_ver_frm_bg;
9408         END IF; -- end of if named hierarchy found
9409 
9410         -- loop through the org hierarchy to find the participation end date at
9411         -- this org level or its parents
9412         l_loop_again := 1;
9413         WHILE (l_loop_again = 1)
9414 
9415         LOOP
9416            -- if any org info row is found for this particular org id
9417            -- for a pension type with the given pension type id
9418            -- then return that org info id
9419 	   OPEN c_get_valid_org_info(l_org_id);
9420 	   FETCH c_get_valid_org_info INTO l_org_info_id;
9421 	   IF c_get_valid_org_info%FOUND THEN
9422               Hr_Utility.set_location('found row @ org info level'||l_org_id,20);
9423               l_loop_again := 0;
9424               CLOSE c_get_valid_org_info;
9425 	      -- fetch the participation end date from the org info row
9426               OPEN c_get_org_info(l_org_id);
9427               FETCH c_get_org_info INTO p_end_date;
9428               IF c_get_org_info%FOUND THEN
9429 	         l_ret_value  := 0;
9430                  l_loop_again := 0;
9431                  CLOSE c_get_org_info;
9432               ELSE
9433 	         l_ret_value        := 1;
9434                  l_loop_again       := 0;
9435                  CLOSE c_get_org_info;
9436               END IF;
9437 
9438 	   ELSE -- search at the parent level of the current org
9439 	      CLOSE c_get_valid_org_info;
9440               -- fetch the parent of this org and loop again
9441 	      OPEN c_find_parent_id(l_org_id,l_version_id);
9442 	      FETCH c_find_parent_id INTO l_org_id;
9443 	      IF c_find_parent_id%NOTFOUND THEN -- the topmost org has been reached
9444 	         CLOSE c_find_parent_id;
9445 	         l_ret_value        := 1;
9446                  l_loop_again       := 0;
9447 	      ELSE
9448 	         CLOSE c_find_parent_id;
9449 	      END IF;
9450            END IF;
9451         END LOOP;
9452  RETURN l_ret_value;
9453 
9454  END Get_Participation_End;
9455 
9456 --============================================================================
9457 --This is used to derive the participation start and end dates and the old start and
9458 --end dates in case of an update for FUR Pensions
9459 --============================================================================
9460 FUNCTION Get_Fur_Participation_Dates
9461           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
9462            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
9463            ,p_fetch_code           IN  Varchar2
9464            ,p_effective_date       IN  Date
9465            ,p_error_message        OUT NOCOPY Varchar2
9466 	   ,p_data_element_value   OUT NOCOPY Varchar2
9467           ) RETURN Number IS
9468 
9469 --cursor to check if ASG EIT rows exist
9470 CURSOR c_asg_rows_exist IS
9471 SELECT 1
9472   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
9473 WHERE  chg_evt_cd = 'COAPPD'
9474   AND  prmtr_01 = 'ASG'
9475   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
9476   AND  pty.pension_sub_category = 'FUR_S'
9477   AND  prmtr_03 = 'Y'
9478   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
9479   AND  person_id = (SELECT person_id
9480                       FROM per_all_assignments_f
9481                     WHERE  assignment_id = p_assignment_id
9482                       AND  p_effective_date BETWEEN effective_start_date
9483                       AND  effective_end_date
9484                    )
9485   AND  bec.business_group_id = p_business_group_id;
9486 
9487 --cursor to check if ORG EIT rows exist
9488 CURSOR c_org_rows_exist(c_org_id IN Number) IS
9489 SELECT 1
9490   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
9491 WHERE  chg_evt_cd = 'COAPPD'
9492   AND  prmtr_01 = 'ORG'
9493   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
9494   AND  pty.pension_sub_category = 'FUR_S'
9495   AND  prmtr_03 = 'Y'
9496   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
9497   AND  bec.business_group_id = p_business_group_id;
9498 
9499 --cursor to get the old and new start and end dates from the ASG EIT
9500 CURSOR c_get_asg_rows IS
9501 SELECT old_val1,new_val1,old_val2,new_val2
9502   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
9503 WHERE  chg_evt_cd = 'COAPPD'
9504   AND  prmtr_01 = 'ASG'
9505   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
9506   AND  prmtr_03 = 'Y'
9507   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
9508   AND  pty.pension_sub_category = 'FUR_S'
9509   AND  person_id = (SELECT person_id
9510                       FROM per_all_assignments_f
9511                     WHERE  assignment_id = p_assignment_id
9512                       AND  p_effective_date BETWEEN effective_start_date
9513                       AND  effective_end_date
9514                    )
9515   AND  bec.business_group_id = p_business_group_id
9516   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
9517   AND  g_extract_params(p_business_group_id).extract_end_date
9518 ORDER BY ext_chg_evt_log_id;
9519 
9520 --cursor to get the old and new start and end dates from the  ORG EIT
9521 CURSOR c_get_org_rows(c_org_id IN Number,c_hire_date IN Date) IS
9522 SELECT old_val1,new_val1,old_val2,new_val2
9523   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
9524 WHERE  chg_evt_cd = 'COAPPD'
9525   AND  prmtr_01 = 'ORG'
9526   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
9527   AND  prmtr_03 = 'Y'
9528   AND  pty.pension_sub_category = 'FUR_S'
9529   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
9530   AND  bec.business_group_id = p_business_group_id
9531   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
9532   AND  g_extract_params(p_business_group_id).extract_end_date
9533   AND  chg_eff_dt >= c_hire_date
9534 ORDER BY ext_chg_evt_log_id;
9535 
9536 --Cursor to find the named hierarchy associated with the BG
9537 CURSOR c_find_named_hierarchy IS
9538 SELECT org_information1
9539  FROM hr_organization_information
9540 WHERE organization_id = p_business_group_id
9541  AND org_information_context = 'NL_BG_INFO';
9542 
9543 --Cursor to find the valid version id for the particular named hierarchy
9544 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id IN Number) IS
9545 SELECT ORG_STRUCTURE_VERSION_ID
9546   FROM per_org_structure_versions_v
9547 WHERE organization_structure_id = c_hierarchy_id
9548   AND p_effective_date BETWEEN date_from
9549   AND Nvl(date_to,Hr_Api.g_eot);
9550 
9551 --Cursor to find the valid version id for a particular business group
9552 CURSOR c_find_ver_frm_bg IS
9553 SELECT ORG_STRUCTURE_VERSION_ID
9554   FROM per_org_structure_versions_v
9555 WHERE business_group_id = p_business_group_id
9556   AND p_effective_date BETWEEN date_from
9557   AND Nvl( date_to,Hr_Api.g_eot);
9558 
9559 --Cursor to find the parent id from the org id
9560 CURSOR c_find_parent_id(c_org_id IN Number
9561                        ,c_version_id IN Number) IS
9562 SELECT organization_id_parent
9563   FROM per_org_structure_elements
9564   WHERE organization_id_child = c_org_id
9565     AND org_structure_version_id = c_version_id
9566     AND business_group_id = p_business_group_id;
9567 
9568 --cursor to find the org id for the current asg
9569 CURSOR c_find_org_id IS
9570 SELECT organization_id
9571   FROM per_all_assignments_f
9572 WHERE  assignment_id = p_assignment_id
9573   AND  p_effective_date BETWEEN effective_start_date
9574   AND  effective_end_date;
9575 
9576 -- Cursor to get the hire date of the person
9577 CURSOR c_hire_dt IS
9578 SELECT max(date_start)
9579  FROM  per_all_assignments_f asg
9580       ,per_periods_of_service pps
9581  WHERE pps.person_id     = asg.person_id
9582    AND asg.assignment_id = p_assignment_id
9583    AND pps.business_group_id = p_business_group_id
9584    AND date_start <= p_effective_date;
9585 
9586 --cursor to check if run results exist for any FUR Pension Types for this assignment
9587 CURSOR c_run_results_exist IS
9588 SELECT pty.pension_type_id
9589 FROM   pay_run_results prr,
9590        pay_payroll_actions ppa,
9591        pay_assignment_actions paa,
9592        pay_element_type_extra_info pei,
9593        pqp_pension_types_f pty
9594 WHERE  paa.assignment_action_id = prr.assignment_action_id
9595   AND  paa.payroll_action_id = ppa.payroll_action_id
9596   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
9597   AND  g_extract_params(p_business_group_id).extract_end_date
9598   AND  paa.assignment_id = p_assignment_id
9599   AND  pei.element_type_id = prr.element_type_id
9600   AND  pei.information_type = 'PQP_NL_ABP_DEDUCTION'
9601   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
9602   AND  pei.eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
9603   AND  pty.pension_sub_category = 'FUR_S';
9604 
9605 l_proc_name       Varchar2(150) := g_proc_name ||'get_fur_participation_dates';
9606 l_return_value    Number := -1;
9607 l_named_hierarchy       Number;
9608 l_version_id            per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
9609 l_asg_rows_exist   Number;
9610 l_org_rows_exist   Number;
9611 l_org_id           Number;
9612 i                  Number := 0;
9613 l_loop_again       Number;
9614 l_hire_date        Date;
9615 l_hired            Number := 0;
9616 l_ret_val          Number;
9617 l_end_date         Date;
9618 
9619 
9620 BEGIN
9621    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
9622    --check the index and the code and calculate the value accordingly
9623    Hr_Utility.set_location('value of g_index : '||g_index_fur,7);
9624    Hr_Utility.set_location('value of fetch code : '||p_fetch_code ,10);
9625    IF g_index_fur = 0 AND p_fetch_code = 'NEW_ST' THEN
9626       g_count_fur := 0;
9627 
9628       OPEN c_hire_dt;
9629       FETCH c_hire_dt INTO l_hire_date;
9630       CLOSE c_hire_dt;
9631       IF l_hire_date BETWEEN g_extract_params(p_business_group_id).extract_start_date
9632         AND g_extract_params(p_business_group_id).extract_end_date THEN
9633         l_hired := 1;
9634       END IF;
9635 
9636       OPEN c_asg_rows_exist;
9637       FETCH c_asg_rows_exist INTO l_asg_rows_exist;
9638       IF c_asg_rows_exist%FOUND THEN
9639          CLOSE c_asg_rows_exist;
9640          Hr_Utility.set_location('found rows at the assignment eit level',15);
9641          --now fetch the rows from the log table
9642          FOR asg_rec IN c_get_asg_rows
9643          LOOP
9644 
9645             IF asg_rec.old_val1 IS NOT NULL THEN
9646                IF asg_rec.old_val1 <> asg_rec.new_val1 THEN
9647                   g_fur_dates(i).old_start := asg_rec.old_val1;
9648                   g_fur_dates(i).new_start := asg_rec.new_val1;
9649                ELSE
9650                   g_fur_dates(i).old_start := '';
9651                   g_fur_dates(i).new_start := asg_rec.new_val1;
9652                END IF;
9653             ELSIF asg_rec.new_val1 IS NOT NULL THEN
9654                g_fur_dates(i).old_start := '';
9655                g_fur_dates(i).new_start := asg_rec.new_val1;
9656             ELSE
9657                g_fur_dates(i).old_start := '';
9658                g_fur_dates(i).new_start := '';
9659             END IF;
9660 
9661             IF asg_rec.old_val2 IS NOT NULL THEN
9662                IF asg_rec.old_val2 <> asg_rec.new_val2 THEN
9663                   g_fur_dates(i).old_end := asg_rec.old_val2;
9664                   g_fur_dates(i).new_end  := asg_rec.new_val2;
9665                ELSE
9666                   g_fur_dates(i).old_end := '';
9667                   g_fur_dates(i).new_end  := asg_rec.new_val2;
9668                END IF;
9669             ELSIF asg_rec.new_val2 IS NOT NULL THEN
9670                g_fur_dates(i).old_end := '';
9671                g_fur_dates(i).new_end := asg_rec.new_val2;
9672             ELSE
9673                g_fur_dates(i).old_end := '';
9674                g_fur_dates(i).new_end := '';
9675             END IF;
9676 
9677             i := i + 1;
9678          END LOOP; -- FOR asg_rec IN c_get_asg_rows
9679          g_count_fur := i;
9680          Hr_Utility.set_location('count of rows : '||g_count_fur,20);
9681       ELSE
9682       CLOSE c_asg_rows_exist;
9683       --go up the org hierarchy to find the rows at some org eit level
9684       -- find the org the assignment is attached to
9685       OPEN c_find_org_id;
9686       FETCH c_find_org_id INTO l_org_id;
9687       CLOSE c_find_org_id;
9688 
9689       --first chk to see if a named hierarchy exists for the BG
9690       OPEN c_find_named_hierarchy;
9691       FETCH c_find_named_hierarchy INTO l_named_hierarchy;
9692       -- if a named hiearchy is found , find the valid version on that date
9693       IF c_find_named_hierarchy%FOUND THEN
9694          CLOSE c_find_named_hierarchy;
9695          -- now find the valid version on that date
9696          OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
9697          FETCH c_find_ver_frm_hierarchy INTO l_version_id;
9698          --if no valid version is found, try to get it frm the BG
9699          IF c_find_ver_frm_hierarchy%NOTFOUND THEN
9700             CLOSE c_find_ver_frm_hierarchy;
9701             -- find the valid version id from the BG
9702             OPEN c_find_ver_frm_bg;
9703             FETCH c_find_ver_frm_bg INTO l_version_id;
9704             CLOSE c_find_ver_frm_bg;
9705          -- else a valid version has been found for the named hierarchy
9706          ELSE
9707             CLOSE c_find_ver_frm_hierarchy;
9708          END IF; --end of if no valid version found
9709       -- else find the valid version from BG
9710       ELSE
9711          CLOSE c_find_named_hierarchy;
9712          --now find the version number from the BG
9713          OPEN c_find_ver_frm_bg;
9714          FETCH c_find_ver_frm_bg INTO l_version_id;
9715          CLOSE c_find_ver_frm_bg;
9716       END IF; -- end of if named hierarchy found
9717 
9718       -- loop through the org hierarchy to find the participation start date at
9719       -- this org level or its parents
9720       l_loop_again := 1;
9721       WHILE (l_loop_again = 1)
9722 
9723       LOOP
9724       Hr_Utility.set_location('searching at org level : '||l_org_id,25);
9725       OPEN c_org_rows_exist(l_org_id);
9726       FETCH c_org_rows_exist INTO l_org_rows_exist;
9727       IF c_org_rows_exist%FOUND THEN
9728          CLOSE c_org_rows_exist;
9729          FOR org_rec IN c_get_org_rows(l_org_id,l_hire_date)
9730          LOOP
9731            IF org_rec.old_val1 IS NOT NULL THEN
9732               IF org_rec.old_val1 <> org_rec.new_val1 THEN
9733                  g_fur_dates(i).old_start := org_rec.old_val1;
9734                  g_fur_dates(i).new_start := org_rec.new_val1;
9735               ELSE
9736                  g_fur_dates(i).old_start := '';
9737                  g_fur_dates(i).new_start := org_rec.new_val1;
9738               END IF;
9739            ELSIF org_rec.new_val1 IS NOT NULL THEN
9740               g_fur_dates(i).old_start := '';
9741               g_fur_dates(i).new_start := org_rec.new_val1;
9742            ELSE
9743               g_fur_dates(i).old_start := '';
9744               g_fur_dates(i).new_start := '';
9745            END IF;
9746            IF org_rec.old_val2 IS NOT NULL THEN
9747               IF org_rec.old_val2 <> org_rec.new_val2 THEN
9748                  g_fur_dates(i).old_end := org_rec.old_val2;
9749                  g_fur_dates(i).new_end := org_rec.new_val2;
9750               ELSE
9751                  g_fur_dates(i).old_end := '';
9752                  g_fur_dates(i).new_end := org_rec.new_val2;
9753               END IF;
9754            ELSIF org_rec.new_val2 IS NOT NULL THEN
9755               g_fur_dates(i).old_end := '';
9756               g_fur_dates(i).new_end := org_rec.new_val2;
9757            ELSE
9758               g_fur_dates(i).old_end := '';
9759               g_fur_dates(i).new_end := '';
9760            END IF;
9761            IF l_hired = 1 THEN
9762              Hr_Utility.set_location('hire date : '||l_hire_date,99);
9763              Hr_Utility.set_location('new date : '||g_fur_dates(i).new_start,100);
9764              Hr_Utility.set_location('greater date : '||Fnd_Date.date_to_canonical(Greatest(
9765                                               l_hire_date,Fnd_Date.canonical_to_date(g_fur_dates(i).new_start))),101);
9766               IF g_fur_dates(i).new_start IS NOT NULL THEN
9767                 Hr_Utility.set_location('chking the new start date',102);
9768                  g_fur_dates(i).new_start := Fnd_Date.date_to_canonical(Greatest(
9769                                              l_hire_date,Fnd_Date.canonical_to_date(g_fur_dates(i).new_start)));
9770                 Hr_Utility.set_location('new start date is : '||g_fur_dates(i).new_start,103);
9771               END IF;
9772               IF g_fur_dates(i).old_start IS NOT NULL THEN
9773                  g_fur_dates(i).old_start := Fnd_Date.date_to_canonical(Greatest(
9774                                               l_hire_date,Fnd_Date.canonical_to_date(g_fur_dates(i).old_start)));
9775               END IF;
9776            END IF;
9777            IF g_fur_dates(i).new_start = g_fur_dates(i).old_start THEN
9778               g_fur_dates(i).old_start := '';
9779            END IF;
9780            i := i + 1;
9781          END LOOP;
9782          g_count_fur := i;
9783          Hr_Utility.set_location('value for g count : '||g_count_fur,30);
9784          l_loop_again := 0;
9785       ELSE
9786          --search at the parent level next
9787          CLOSE c_org_rows_exist;
9788          OPEN c_find_parent_id(l_org_id,l_version_id);
9789          FETCH c_find_parent_id INTO l_org_id;
9790          IF c_find_parent_id%NOTFOUND THEN
9791             l_loop_again := 0;
9792             CLOSE c_find_parent_id;
9793          ELSE
9794             CLOSE c_find_parent_id;
9795          END IF;
9796       END IF;
9797      END LOOP;
9798    END IF;
9799 --if no changes have occured,check if participation has occured due to employement start
9800 --if so , fire a row for record 40
9801 IF g_count_fur = 0 THEN
9802    i := 0;
9803    IF l_hired = 1 THEN
9804       --chk if there is any run result
9805       FOR c_rec IN c_run_results_exist
9806       LOOP
9807         g_fur_dates(i).new_start := Fnd_Date.date_to_canonical(l_hire_date);
9808         g_fur_dates(i).old_start := '';
9809         --get the end date corresponding to this enrollment
9810         l_ret_val := Get_Participation_End
9811                      (p_assignment_id => p_assignment_id
9812                      ,p_business_group_id => p_business_group_id
9813                      ,p_pension_type_id   => c_rec.pension_type_id
9814                      ,p_date_earned       => p_effective_date
9815                      ,p_end_date          => l_end_date
9816                      );
9817         IF l_ret_val = 0 THEN
9818            IF l_end_date = hr_api.g_eot THEN
9819               g_fur_dates(i).new_end := '';
9820            ELSE
9821               g_fur_dates(i).new_end := Fnd_Date.date_to_canonical(l_end_date) ;
9822            END IF;
9823         ELSE
9824            g_fur_dates(i).new_end := '';
9825         END IF;
9826         g_fur_dates(i).old_end := '';
9827         i := i+1;
9828       END LOOP;
9829      g_count_fur := i;
9830    END IF;
9831 END IF;
9832 END IF;
9833 
9834 IF g_count_fur > 0 THEN
9835    Hr_Utility.set_location('old st date : '||g_fur_dates(g_index_fur).old_start,40);
9836    Hr_Utility.set_location('new st date : '||g_fur_dates(g_index_fur).new_start,45);
9837    Hr_Utility.set_location('old ed date : '||g_fur_dates(g_index_fur).old_end,50);
9838    Hr_Utility.set_location('new ed date : '||g_fur_dates(g_index_fur).new_end,55);
9839    l_return_value := 0;
9840    --depending on the fetch code ,set the data element value
9841    IF p_fetch_code = 'NEW_ST' THEN
9842       p_data_element_value := g_fur_dates(g_index_fur).new_start;
9843    ELSIF p_fetch_code = 'OLD_ST' THEN
9844       p_data_element_value := g_fur_dates(g_index_fur).old_start;
9845    ELSIF p_fetch_code = 'NEW_ED' THEN
9846       p_data_element_value := g_fur_dates(g_index_fur).new_end;
9847    ELSIF p_fetch_code = 'OLD_ED' THEN
9848       p_data_element_value := g_fur_dates(g_index_fur).old_end;
9849    END IF;
9850 
9851 --   p_data_element_value := substr(p_data_element_value,1,10);
9852    p_data_element_value := Ben_Ext_Fmt.apply_format_mask
9853                            (Fnd_Date.canonical_to_date(p_data_element_value),
9854                             'YYYYMMDD');
9855 
9856 ELSE
9857    p_data_element_value := '';
9858    l_return_value := 0;
9859 END IF;
9860 
9861 Hr_Utility.set_location('p_data_element_value:   '||p_data_element_value, 70);
9862 Hr_Utility.set_location('Leaving:   '||l_proc_name, 80);
9863 
9864 l_return_value :=0;
9865 RETURN l_return_value;
9866 EXCEPTION
9867    WHEN Others THEN
9868     p_error_message :='SQL-ERRM :'||SQLERRM;
9869     Hr_Utility.set_location('..'||p_error_message,85);
9870     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
9871     RETURN l_return_value;
9872 END get_fur_participation_dates;
9873 
9874 --============================================================================
9875 -- This function returns the kind of contribution for PPP Pensions
9876 -- for a particular effective date.
9877 --============================================================================
9878 FUNCTION Get_PPP_Kind
9879          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
9880          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
9881          ,p_effective_date       IN  DATE
9882          ,p_current              IN  VARCHAR2
9883          ,p_error_message        OUT NOCOPY VARCHAR2
9884          ,p_data_element_value   OUT NOCOPY VARCHAR2
9885          ) RETURN NUMBER IS
9886 
9887 l_proc_name   VARCHAR2(30) := 'Get_PPP_Kind';
9888 l_ppp_flag    VARCHAR2(1)  := ' ';
9889 l_org_id      NUMBER;
9890 l_rr_exist    NUMBER;
9891 l_asg_exist NUMBER;
9892 
9893 CURSOR c_ppp_org IS
9894 SELECT organization_id
9895   FROM per_all_assignments_f
9896  WHERE assignment_id = p_assignment_id
9897    AND TRUNC(p_effective_date) BETWEEN effective_start_date
9898                                    AND effective_end_date;
9899 
9900 --
9901 -- Cursor for ASG participation in PPP
9902 --
9903 CURSOR c_ppp_asg IS
9904 SELECT 1
9905   FROM ben_ext_chg_evt_log bec
9906  WHERE chg_evt_cd = 'COAPPD'
9907    AND prmtr_01 = 'ASG'
9908    AND prmtr_04 = 'PPP'
9909    AND prmtr_03 = 'Y'
9910    AND fnd_number.canonical_to_number(prmtr_10) = p_assignment_id
9911 --   AND chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
9912 --   AND g_extract_params(p_business_group_id).extract_end_date
9913    AND bec.business_group_id = p_business_group_id;
9914 
9915 CURSOR c_ppp_asg1 IS
9916 SELECT 1
9917   FROM per_assignment_extra_info paei,
9918        pqp_pension_types_f pty
9919  WHERE paei.information_type         = 'NL_ABP_PI'
9920    AND paei.aei_information_category = 'NL_ABP_PI'
9921    AND paei.assignment_id            = p_assignment_id
9922    AND fnd_number.canonical_to_number(NVL(aei_information3,-1)) = pty.pension_type_id
9923    AND p_effective_date BETWEEN pty.effective_start_date and pty.effective_end_date
9924    AND  pty.pension_sub_category IN ('PPP')
9925    AND p_effective_date between fnd_date.canonical_to_date(paei.aei_information1)
9926    AND fnd_date.canonical_to_date(NVL(paei.aei_information2,
9927                                       fnd_date.date_to_canonical(hr_api.g_eot)));
9928 
9929 /* Cursor changed for 6670714
9930 CURSOR c_rr_cur IS
9931 SELECT 1
9932   FROM pay_run_results prr,
9933        pay_payroll_actions ppa,
9934        pay_assignment_actions paa,
9935        pay_element_type_extra_info pei,
9936        pqp_pension_types_f pty
9937 WHERE  paa.assignment_action_id = prr.assignment_action_id
9938   AND  paa.payroll_action_id    = ppa.payroll_action_id
9939   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
9940                            AND g_extract_params(p_business_group_id).extract_end_date
9941   AND  paa.assignment_id            = p_assignment_id
9942   AND  pei.element_type_id          = prr.element_type_id
9943   AND  pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
9944   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
9945   AND  pei.eei_information2         = Fnd_Number.number_to_canonical(pty.pension_type_id)
9946   AND  pty.pension_sub_category     = 'PPP';*/
9947 
9948 CURSOR c_rr_cur IS
9949 SELECT  1
9950 FROM per_all_assignments_f paf,
9951      hr_organization_information hoi,
9952      pqp_pension_types_f pty,
9953      pay_all_payrolls_f ppf
9954 WHERE paf.assignment_id = p_assignment_id
9955 AND p_effective_date BETWEEN paf.effective_start_date AND paf.effective_end_date
9956 AND paf.payroll_id = ppf.payroll_id
9957 AND ppf.prl_information_category = 'NL'
9958 AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
9959 AND (paf.organization_id = hoi.organization_id
9960      OR
9961      (fnd_number.canonical_to_number(ppf.prl_information1) = hoi.organization_id
9962       AND NOT EXISTS (SELECT 1
9963                       FROM hr_organization_information hoi1
9964                      WHERE hoi1.org_information_context      = 'PQP_NL_ABP_PT'
9965                        AND hoi1.org_information3             = TO_CHAR(pty.pension_type_id)
9966                        AND hoi1.organization_id = paf.organization_id
9967                        AND (   NVL(hoi1.org_information6,'N')= 'N'
9968                             OR NVL(hoi1.org_information7,'N')= 'N')
9969                         AND p_effective_date BETWEEN fnd_date.canonical_to_date(hoi1.org_information1)
9970                         AND fnd_date.canonical_to_date(NVL(hoi1.org_information2,
9971                             fnd_date.date_to_canonical(hr_api.g_eot))))
9972      ))
9973 AND hoi.org_information_context      = 'PQP_NL_ABP_PT'
9974 AND hoi.org_information3             = TO_CHAR(pty.pension_type_id)
9975 AND p_effective_date BETWEEN pty.effective_start_date AND pty.effective_end_date
9976 AND  pty.pension_sub_category IN ('PPP')
9977 AND NVL(hoi.org_information6,'N')    = 'Y'
9978 AND NVL(hoi.org_information7,'N')    = 'Y'
9979 AND p_effective_date BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
9980                          AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
9981                              fnd_date.date_to_canonical(hr_api.g_eot)));
9982 
9983 
9984 BEGIN
9985    Hr_Utility.set_location('Entering ------ : '||l_proc_name,10);
9986    --
9987    -- Check if the value being fetched is the current one(for the extract date range).
9988    --
9989    IF p_current = 'Y' THEN
9990       Hr_Utility.set_location('... Current PPP Flag derived',15);
9991       OPEN c_ppp_asg1;
9992       FETCH c_ppp_asg1 INTO l_asg_exist;
9993       IF c_ppp_asg1%FOUND THEN
9994       Hr_Utility.set_location('... Current PPP Flag derived',16);
9995         l_ppp_flag := '1';
9996       ELSE
9997         OPEN c_rr_cur;
9998         FETCH c_rr_cur INTO l_rr_exist;
9999         IF c_rr_cur%FOUND THEN
10000            l_ppp_flag := '1';
10001            Hr_Utility.set_location('... RR exist value is 1',20);
10002         ELSE
10003            l_ppp_flag := '0';
10004            Hr_Utility.set_location('... RR do not exist value is 0',30);
10005         END IF;
10006         CLOSE c_rr_cur;
10007    END IF;
10008 CLOSE c_ppp_asg1;
10009 END IF;
10010 
10011    FOR ppp_org_rec IN c_ppp_org
10012    LOOP
10013       l_org_id := ppp_org_rec.organization_id;
10014    END LOOP;
10015    Hr_Utility.set_location('...Org Id for the Asg: '||l_org_id,20);
10016 
10017    p_data_element_value := l_ppp_flag;
10018    Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
10019 RETURN 0;
10020 
10021 EXCEPTION
10022    WHEN Others THEN
10023     p_error_message :='SQL-ERRM :'||SQLERRM;
10024     p_data_element_value := ' ';
10025     Hr_Utility.set_location('..'||p_error_message,10);
10026     Hr_Utility.set_location('Leaving:-------- '||l_proc_name,20);
10027     RETURN -1;
10028 
10029 END Get_PPP_Kind;
10030 
10031 --============================================================================
10032 --This function returns the kind of contribution for FPU Pensions
10033 --
10034 -- Logic behind the code
10035 --
10036 /*
10037 Individual Schemes               Code
10038 =============================    ======
10039 No Participation                  G
10040 FPU Standard (End 31-DEC-03)      S
10041 FPU Extra                         C
10042 FPU Raise                         A
10043 FPU Total                         B
10044 FPU Base                          S
10045 FPU Composition                   S
10046 
10047 Multiple FPU                      Code
10048 ===========================       ======
10049 FPU Base + Composition            S
10050 FPU Base or Composition + Extra   C
10051 FPU Base or Composition + Raise   A
10052 FPU Base or Composition + Total   B */
10053 
10054 -- Please Note : Legislative rules do not allow any other combination
10055 --============================================================================
10056 FUNCTION Get_Fpu_Kind
10057           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10058           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10059           ,p_effective_date       IN  Date
10060           ,p_error_message        OUT NOCOPY Varchar2
10061           ,p_data_element_value   OUT NOCOPY Varchar2
10062           ) RETURN NUMBER IS
10063 
10064 l_proc_name         VARCHAR2(30) := 'Get_Fpu_Kind';
10065 l_kind_of_contrib   VARCHAR2(1)  := 'G';
10066 
10067 /* Cursor changed for 6670714
10068 CURSOR c_fpu_rr_cur IS
10069 SELECT  decode (pty.pension_sub_category,'FPU_B','S'
10070         ,'FPU_C','S'
10071         ,'FPU_E','C'
10072         ,'FPU_R','A'
10073         ,'FPU_S','S'
10074         ,'FPU_T' ,'B') fpu_code
10075   FROM pay_run_results prr,
10076        pay_payroll_actions ppa,
10077        pay_assignment_actions paa,
10078        pay_element_type_extra_info pei,
10079        pqp_pension_types_f pty
10080 WHERE  paa.assignment_action_id = prr.assignment_action_id
10081   AND  paa.payroll_action_id    = ppa.payroll_action_id
10082   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
10083                            AND g_extract_params(p_business_group_id).extract_end_date
10084   AND  paa.assignment_id            = p_assignment_id
10085   AND  pei.element_type_id          = prr.element_type_id
10086   AND  pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
10087   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
10088   AND  pei.eei_information2         = Fnd_Number.number_to_canonical(pty.pension_type_id)
10089   AND  pty.pension_sub_category IN ('FPU_B',
10090                                     'FPU_E',
10091                                     'FPU_R',
10092                                     'FPU_S',
10093                                     'FPU_T');*/
10094 
10095 CURSOR c_fpu_rr_cur IS
10096 SELECT  DISTINCT DECODE (pty.pension_sub_category,'FPU_B','S'
10097         ,'FPU_C','S'
10098         ,'FPU_E','C'
10099         ,'FPU_R','A'
10100         ,'FPU_S','S'
10101         ,'FPU_T' ,'B') fpu_code
10102 FROM per_all_assignments_f paf,
10103      hr_organization_information hoi,
10104      pqp_pension_types_f pty,
10105      pay_all_payrolls_f ppf
10106 WHERE paf.assignment_id = p_assignment_id
10107 AND p_effective_date BETWEEN paf.effective_start_date AND paf.effective_end_date
10108 AND paf.payroll_id = ppf.payroll_id
10109 AND ppf.prl_information_category = 'NL'
10110 AND p_effective_date BETWEEN ppf.effective_start_date AND ppf.effective_end_date
10111 AND (paf.organization_id = hoi.organization_id
10112      OR
10113      (fnd_number.canonical_to_number(ppf.prl_information1) = hoi.organization_id
10114       AND NOT EXISTS (SELECT 1
10115                       FROM hr_organization_information hoi1
10116                      WHERE hoi1.org_information_context      = 'PQP_NL_ABP_PT'
10117                        AND hoi1.org_information3             = TO_CHAR(pty.pension_type_id)
10118                        AND hoi1.organization_id = paf.organization_id
10119                        AND (   NVL(hoi1.org_information6,'N')= 'N'
10120                             OR NVL(hoi1.org_information7,'N')= 'N')
10121                         AND p_effective_date BETWEEN fnd_date.canonical_to_date(hoi1.org_information1)
10122                         AND fnd_date.canonical_to_date(NVL(hoi1.org_information2,
10123                             fnd_date.date_to_canonical(hr_api.g_eot))))
10124      ))
10125 AND hoi.org_information_context      = 'PQP_NL_ABP_PT'
10126 AND hoi.org_information3             = TO_CHAR(pty.pension_type_id)
10127 AND p_effective_date BETWEEN pty.effective_start_date AND pty.effective_end_date
10128 AND  pty.pension_sub_category IN ('FPU_B',
10129                                     'FPU_E',
10130                                     'FPU_R',
10131                                     'FPU_S',
10132                                     'FPU_T')
10133 AND NVL(hoi.org_information6,'N')    = 'Y'
10134 AND NVL(hoi.org_information7,'N')    = 'Y'
10135 AND p_effective_date BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
10136                          AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
10137                              fnd_date.date_to_canonical(hr_api.g_eot)))
10138 AND NOT EXISTS (SELECT 1
10139                    FROM per_assignment_extra_info paei1
10140                    WHERE paei1.information_type='NL_ABP_RI'
10141                    AND paei1.aei_information_category='NL_ABP_RI'
10142                    AND paei1.assignment_id = p_assignment_id
10143                    AND paei1.aei_information3 = 'G'
10144                    AND p_effective_date BETWEEN fnd_date.canonical_to_date(paei1.aei_information1)
10145                    AND fnd_date.canonical_to_date(NVL(paei1.aei_information2,
10146                                       fnd_date.date_to_canonical(hr_api.g_eot))));
10147 
10148 CURSOR c_fpu_asg IS
10149 SELECT DISTINCT DECODE (pty.pension_sub_category,'FPU_B','S'
10150         ,'FPU_C','S'
10151         ,'FPU_E','C'
10152         ,'FPU_R','A'
10153         ,'FPU_S','S'
10154         ,'FPU_T' ,'B') fpu_code
10155   FROM per_assignment_extra_info paei,
10156        pqp_pension_types_f pty
10157  WHERE paei.information_type         = 'NL_ABP_PI'
10158    AND paei.aei_information_category = 'NL_ABP_PI'
10159    AND paei.assignment_id            = p_assignment_id
10160    AND fnd_number.canonical_to_number(NVL(aei_information3,-1)) = pty.pension_type_id
10161    AND p_effective_date BETWEEN pty.effective_start_date and pty.effective_end_date
10162    AND  pty.pension_sub_category IN ('FPU_B',
10163                                     'FPU_E',
10164                                     'FPU_R',
10165                                     'FPU_S',
10166                                     'FPU_T')
10167    AND p_effective_date between fnd_date.canonical_to_date(paei.aei_information1)
10168    AND fnd_date.canonical_to_date(NVL(paei.aei_information2,
10169                                       fnd_date.date_to_canonical(hr_api.g_eot)))
10170    AND NOT EXISTS (SELECT 1
10171                    FROM per_assignment_extra_info paei1
10172                    WHERE paei1.information_type='NL_ABP_RI'
10173                    AND paei1.aei_information_category='NL_ABP_RI'
10174                    AND paei1.assignment_id = p_assignment_id
10175                    AND paei1.aei_information3 = 'G'
10176                    AND p_effective_date BETWEEN fnd_date.canonical_to_date(paei1.aei_information1)
10177                    AND fnd_date.canonical_to_date(NVL(paei1.aei_information2,
10178                                       fnd_date.date_to_canonical(hr_api.g_eot))));
10179 
10180 BEGIN
10181 
10182 Hr_Utility.set_location('Entering ------ : '||l_proc_name,5);
10183 
10184 FOR fpu_rec IN c_fpu_asg
10185    LOOP
10186       IF l_kind_of_contrib = 'G' THEN
10187          l_kind_of_contrib := fpu_rec.fpu_code;
10188       ELSIF l_kind_of_contrib NOT IN ('A','B','C') THEN
10189          l_kind_of_contrib := fpu_rec.fpu_code;
10190       END IF;
10191    END LOOP;
10192 IF l_kind_of_contrib = 'G' THEN
10193 FOR fpu_rec IN c_fpu_rr_cur
10194    LOOP
10195       IF l_kind_of_contrib = 'G' THEN
10196          l_kind_of_contrib := fpu_rec.fpu_code;
10197       ELSIF l_kind_of_contrib NOT IN ('A','B','C') THEN
10198          l_kind_of_contrib := fpu_rec.fpu_code;
10199       END IF;
10200    END LOOP;
10201 END IF;
10202 
10203    Hr_Utility.set_location('...Kind of FPU : '||l_kind_of_contrib,10);
10204 
10205    p_data_element_value := l_kind_of_contrib;
10206 
10207    Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
10208 
10209 RETURN 0;
10210 
10211 EXCEPTION
10212    WHEN OTHERS THEN
10213     p_error_message :='SQL-ERRM :'||SQLERRM;
10214     Hr_Utility.set_location('..'||p_error_message,15);
10215     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
10216     RETURN -1;
10217 
10218 END Get_Fpu_Kind;
10219 
10220 --============================================================================
10221 --This function returns the kind of contribution for OPNP Pensions, from the ASG EIT
10222 --============================================================================
10223 FUNCTION Get_Opnp_Kind
10224           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10225           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10226           ,p_effective_date       IN  Date
10227           ,p_error_message        OUT NOCOPY Varchar2
10228           ,p_data_element_value   OUT NOCOPY Varchar2
10229           ) RETURN Number IS
10230 
10231 l_proc_name Varchar2(30) := 'Get_Opnp_Kind';
10232 l_kind_of_contrib Varchar2(1) := 'G';
10233 
10234 --cursor to fetch the contribution kind from the ASG EIT
10235 CURSOR c_get_contrib_kind IS
10236 SELECT Substr(Nvl(aei_information4,'G'),0,1)
10237   FROM per_assignment_extra_info
10238 WHERE  assignment_id = p_assignment_id
10239   AND  p_effective_date BETWEEN Fnd_Date.canonical_to_date(aei_information1)
10240   AND  Fnd_Date.canonical_to_date(Nvl(aei_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)))
10241   AND  aei_information_category = 'NL_ABP_RI'
10242   AND  information_type = 'NL_ABP_RI';
10243 
10244 BEGIN
10245 
10246 Hr_Utility.set_location('Entering ------ : '||l_proc_name,5);
10247 OPEN c_get_contrib_kind;
10248 FETCH c_get_contrib_kind INTO l_kind_of_contrib;
10249 CLOSE c_get_contrib_kind;
10250 Hr_Utility.set_location('value of kind of opnp : '||l_kind_of_contrib,10);
10251 p_data_element_value := l_kind_of_contrib;
10252 RETURN 0;
10253 
10254 EXCEPTION
10255    WHEN Others THEN
10256     p_error_message :='SQL-ERRM :'||SQLERRM;
10257     Hr_Utility.set_location('..'||p_error_message,15);
10258     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
10259     RETURN -1;
10260 
10261 END Get_Opnp_Kind;
10262 
10263 -- ============================================================================
10264 -- Function to get the retro participation of a particular sub category
10265 -- this function currently returns the start and end date of retro
10266 -- participation.
10267 -- ============================================================================
10268 FUNCTION Get_Retro_Kind_Of_Ptpn
10269           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10270           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10271           ,p_effective_date       IN  DATE
10272           ,p_retro_kind_ptpn      OUT NOCOPY t_retro_ptpn_kind
10273           ,p_error_message        OUT NOCOPY VARCHAR2
10274           ) RETURN NUMBER IS
10275 
10276 CURSOR c_asg_kind_info  IS
10277 SELECT fnd_date.canonical_to_date(aei_information1) start_dt
10278       ,fnd_date.canonical_to_date(NVL(aei_information2,'4712/12/31 00:00:00')) end_dt
10279       ,aei_information4 kind
10280       ,LEAST(fnd_number.canonical_to_number(aei_information5),1) * 100 value
10281  FROM per_assignment_extra_info paei
10282 WHERE paei.assignment_id = p_assignment_id
10283   AND aei_information4 IS NOT NULL
10284   AND paei.information_type = 'NL_ABP_PAR_INFO'
10285   AND fnd_date.canonical_to_date(aei_information1)
10286       BETWEEN   g_extract_params(p_business_group_id).extract_start_date
10287                AND   g_extract_params(p_business_group_id).extract_end_date
10288   AND  NOT EXISTS ( SELECT 1
10289                       FROM per_assignment_extra_info paei1
10290                      WHERE paei1.assignment_id = p_assignment_id
10291                        AND paei1.information_type = 'NL_ABP_PAR_INFO'
10292                        AND fnd_date.canonical_to_date(paei1.aei_information1) <
10293                           g_extract_params(p_business_group_id).extract_start_date
10294                        AND paei1.aei_information4 IS NOT NULL
10295                        and paei1.aei_information4 = paei.aei_information4
10296                        AND fnd_date.canonical_to_date(NVL(paei1.aei_information2,'4712/12/31 00:00:00')) =
10297                            fnd_date.canonical_to_date(NVL(paei.aei_information1,'4712/12/31 00:00:00')) - 1
10298                    )
10299 UNION
10300 SELECT fnd_date.canonical_to_date(aei_information1) start_dt
10301       ,fnd_date.canonical_to_date(NVL(aei_information2,'4712/12/31 00:00:00')) end_dt
10302       ,aei_information4 kind
10303       ,LEAST(fnd_number.canonical_to_number(aei_information5),1) * 100 value
10304  FROM per_assignment_extra_info paei
10305 WHERE paei.assignment_id = p_assignment_id
10306  AND aei_information4 IS NOT NULL
10307    AND paei.information_type = 'NL_ABP_PAR_INFO'
10308   AND fnd_date.canonical_to_date(aei_information1)
10309       <   g_extract_params(p_business_group_id).extract_start_date
10310   AND EXISTS ( SELECT 1 FROM
10311               ben_ext_chg_evt_log blog
10312               WHERE blog.person_id = g_person_id
10313                 AND blog.chg_evt_cd = 'COAPKOP'
10314                 AND blog.prmtr_10 = paei.assignment_id
10315                 AND fnd_number.canonical_to_number(blog.prmtr_03) = paei.assignment_extra_info_id
10316                 AND fnd_date.canonical_to_date(blog.prmtr_09) BETWEEN
10317                      g_extract_params(p_business_group_id).extract_start_date
10318                AND   g_extract_params(p_business_group_id).extract_end_date)
10319 ORDER BY start_dt;
10320 
10321 CURSOR c_chk_ptpn_continues (c_end_date  IN DATE
10322                             ,c_ptpn_kind IN VARCHAR2) IS
10323 SELECT 1
10324   FROM per_assignment_extra_info paei
10325  WHERE paei.assignment_id = p_assignment_id
10326    AND aei_information4 = c_ptpn_kind
10327    AND aei_information4 is not null
10328    AND paei.information_type = 'NL_ABP_PAR_INFO'
10329    AND fnd_date.canonical_to_date(aei_information1) = c_end_date + 1;
10330 
10331 l_subcat           VARCHAR2(100);
10332 i                  NUMBER := 0;
10333 x                  NUMBER := 0;
10334 l_dummy            NUMBER;
10335 
10336 BEGIN
10337 
10338 --
10339 -- Derive all the start and end dates of participation for
10340 -- the retro period and current period
10341 --
10342 FOR l_asg_info_rec IN c_asg_kind_info
10343 LOOP
10344    IF i = 0 THEN
10345       --
10346       -- Create the row for the first time
10347       --
10348       i:= i + 1;
10349       p_retro_kind_ptpn(i).start_date := l_asg_info_rec.start_dt;
10350       p_retro_kind_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10351       p_retro_kind_ptpn(i).ptpn_kind  := l_asg_info_rec.kind;
10352       p_retro_kind_ptpn(i).ptpn_val   := l_asg_info_rec.value;
10353    ELSE
10354       --
10355       -- Create the row only if the dates are not continuous
10356       --
10357       IF l_asg_info_rec.start_dt <> p_retro_kind_ptpn(i).end_date + 1 AND
10358          l_asg_info_rec.kind     <> p_retro_kind_ptpn(i).ptpn_kind THEN
10359          i:= i + 1;
10360          p_retro_kind_ptpn(i).start_date := l_asg_info_rec.start_dt;
10361          p_retro_kind_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10362          p_retro_kind_ptpn(i).ptpn_kind  := l_asg_info_rec.kind;
10363          p_retro_kind_ptpn(i).ptpn_val   := l_asg_info_rec.value;
10364       ELSE
10365          p_retro_kind_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10366       END IF;
10367    END IF;
10368 END LOOP; -- For the changes to dates in the assignment
10369 
10370 IF p_retro_kind_ptpn.COUNT > 0 THEN
10371 x := p_retro_kind_ptpn.LAST;
10372  OPEN c_chk_ptpn_continues (p_retro_kind_ptpn(x).end_date,p_retro_kind_ptpn(x).ptpn_kind);
10373 FETCH c_chk_ptpn_continues INTO l_dummy;
10374 IF c_chk_ptpn_continues%FOUND THEN
10375    p_retro_kind_ptpn(x).end_date := NULL;
10376 END IF;
10377 CLOSE c_chk_ptpn_continues;
10378 END IF;
10379 
10380 RETURN 0;
10381 
10382 END Get_Retro_Kind_Of_Ptpn;
10383 
10384 -- ============================================================================
10385 -- Function to get the retro participation of a particular sub category
10386 -- this function currently returns the start and end date of retro
10387 -- participation.
10388 -- ============================================================================
10389 FUNCTION Get_Retro_Participation
10390           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10391           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10392           ,p_sub_cat              IN  VARCHAR2
10393           ,p_effective_date       IN  DATE
10394           ,p_retro_ptpn           OUT NOCOPY t_retro_ptpn
10395           ,p_error_message        OUT NOCOPY VARCHAR2
10396           ) RETURN NUMBER IS
10397 
10398 CURSOR c_ele_cur IS
10399 SELECT pet.element_type_id   base_ele
10400       ,pei.eei_information12 sub_cat
10401       ,pei.eei_information18 cy_retro_ele
10402       ,pei.eei_information19 py_retro_ele
10403       ,pei.eei_information2 pt_id
10404  FROM pay_element_type_extra_info pei,
10405       pay_element_types_f pet
10406 WHERE pei.information_type         = 'PQP_NL_ABP_DEDUCTION'
10407   AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
10408   AND p_effective_date BETWEEN To_Date(pei.eei_information10,'DD/MM/RRRR') AND
10409                                To_Date(pei.eei_information11,'DD/MM/RRRR')
10410   AND p_effective_date BETWEEN pet.effective_start_date AND
10411                                pet.effective_end_date
10412   AND pet.element_type_id = pei.element_type_id
10413   AND pet.business_group_id = p_business_group_id
10414   AND pei.EEI_INFORMATION12 = p_sub_cat;
10415 
10416 CURSOR c_asg_info ( c_pt_id    IN NUMBER) IS
10417 SELECT fnd_date.canonical_to_date(aei_information1) start_dt
10418       ,fnd_date.canonical_to_date(NVL(aei_information2,'4712/12/31 00:00:00')) end_dt
10419  FROM per_assignment_extra_info paei
10420 WHERE paei.assignment_id = p_assignment_id
10421   AND fnd_number.canonical_to_number(aei_information3) = c_pt_id
10422   AND paei.information_type = 'NL_ABP_PI'
10423   AND fnd_date.canonical_to_date(aei_information1)
10424       BETWEEN  g_extract_params(p_business_group_id).extract_start_date
10425                AND   g_extract_params(p_business_group_id).extract_end_date
10426   AND  NOT EXISTS ( SELECT 1
10427                       FROM per_assignment_extra_info paei1
10428                      WHERE paei1.assignment_id = p_assignment_id
10429                        AND paei1.information_type = 'NL_ABP_PI'
10430                        AND fnd_date.canonical_to_date(paei1.aei_information1) <
10431                            g_extract_params(p_business_group_id).extract_start_date
10432                        AND fnd_number.canonical_to_number(paei1.aei_information3) = c_pt_id
10433                        AND fnd_date.canonical_to_date(NVL(paei1.aei_information2,'4712/12/31 00:00:00')) =
10434                            fnd_date.canonical_to_date(NVL(paei.aei_information1,'4712/12/31 00:00:00')) -1
10435                    )
10436 UNION
10437 SELECT fnd_date.canonical_to_date(aei_information1) start_dt
10438       ,fnd_date.canonical_to_date(NVL(aei_information2,'4712/12/31 00:00:00')) end_dt
10439  FROM per_assignment_extra_info paei
10440 WHERE paei.assignment_id = p_assignment_id
10441   AND fnd_number.canonical_to_number(aei_information3) = c_pt_id
10442   AND paei.information_type = 'NL_ABP_PI'
10443   AND fnd_date.canonical_to_date(aei_information1)
10444       < g_extract_params(p_business_group_id).extract_start_date
10445   AND EXISTS ( SELECT 1 FROM
10446               ben_ext_chg_evt_log blog
10447               WHERE blog.person_id = g_person_id
10448                 AND blog.chg_evt_cd = 'COAPP'
10449                 AND blog.prmtr_10 = paei.assignment_id
10450                 AND fnd_number.canonical_to_number(blog.prmtr_03) = paei.assignment_extra_info_id
10451                 AND fnd_date.canonical_to_date(blog.prmtr_09) BETWEEN
10452                 g_extract_params(p_business_group_id).extract_start_date
10453                AND   g_extract_params(p_business_group_id).extract_end_date)
10454 ORDER BY start_dt ;
10455 
10456 CURSOR c_chk_ptpn_continues (c_end_date IN DATE,
10457                              c_pt_id    IN NUMBER) IS
10458 SELECT 1
10459   FROM per_assignment_extra_info paei
10460  WHERE paei.assignment_id = p_assignment_id
10461    AND fnd_number.canonical_to_number(aei_information3) = c_pt_id
10462    AND paei.information_type = 'NL_ABP_PI'
10463    AND fnd_date.canonical_to_date(aei_information1) = c_end_date + 1;
10464 
10465 l_subcat           VARCHAR2(100);
10466 i                  NUMBER := 0;
10467 x                  NUMBER := 0;
10468 l_ass_act_absent   NUMBER;
10469 l_pt_id            NUMBER;
10470 l_dummy            NUMBER;
10471 
10472 BEGIN
10473 
10474 --
10475 -- For the elements created for the Sub Category
10476 --
10477 FOR l_ele_rec IN c_ele_cur
10478 LOOP
10479          --
10480          -- Derive all the start and end dates of participation for
10481          -- the retro period and current period it is possible that there is no end of
10482          -- participation. It is possible that the user has entered retro
10483          -- participation for two separate dates
10484          --
10485          FOR l_asg_info_rec IN c_asg_info (l_ele_rec.pt_id )
10486          LOOP
10487             l_pt_id := l_ele_rec.pt_id;
10488             IF i = 0 THEN
10489                --
10490                -- Create the row for the first time
10491                --
10492                i:= i + 1;
10493                p_retro_ptpn(i).start_date := l_asg_info_rec.start_dt;
10494                p_retro_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10495                p_retro_ptpn(i).ptid       := l_ele_rec.pt_id;
10496             ELSE
10497                --
10498                -- Create the row only if the dates are not continuous
10499                --
10500                IF l_asg_info_rec.start_dt <> p_retro_ptpn(i).end_date + 1 THEN
10501                   i:= i + 1;
10502                   p_retro_ptpn(i).start_date := l_asg_info_rec.start_dt;
10503                   p_retro_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10504                   p_retro_ptpn(i).ptid       := l_ele_rec.pt_id;
10505                ELSE
10506                   p_retro_ptpn(i).end_date   := l_asg_info_rec.end_dt;
10507                END IF;
10508             END IF;
10509          END LOOP; -- For the changes to dates in the assignment
10510 END LOOP; -- For each of the elements in the sub category
10511 
10512 IF p_retro_ptpn.COUNT > 0 THEN
10513 x := p_retro_ptpn.LAST;
10514  OPEN c_chk_ptpn_continues (p_retro_ptpn(x).end_date,l_pt_id);
10515 FETCH c_chk_ptpn_continues INTO l_dummy;
10516 IF c_chk_ptpn_continues%FOUND THEN
10517    p_retro_ptpn(x).end_date := NULL;
10518 END IF;
10519 CLOSE c_chk_ptpn_continues;
10520 END IF;
10521 
10522 RETURN 0;
10523 
10524 END Get_Retro_Participation;
10525 
10526 
10527 /*PROCEDURE Populate_Term_Rev_Data
10528               (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10529               ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10530               ,p_end_date             IN  DATE
10531               ,p_start_date           IN  DATE
10532               ,p_error_message        OUT NOCOPY VARCHAR2
10533               ) IS
10534 BEGIN
10535 
10536 
10537 --
10538 -- Derive the beginning date
10539 --
10540 l_beg_new_st    := p_start_date;
10541 l_loop_end_date := p_end_date;
10542 l_loop_end_date := LEAST ( g_extract_params(p_business_group_id).extract_start_date -1
10543                            ,l_loop_end_date);
10544 -- GZZ
10545 --
10546 --
10547 -- Loop through the dates to derive data to be reported to ABP
10548 -- this might include ony the differences of that period or the entire amount
10549 -- for the month
10550 --
10551 WHILE trunc(l_beg_new_st) < l_loop_end_date
10552    LOOP
10553    l_end_new_st := add_months(trunc(l_beg_new_st),1) -1;
10554    l_gzz_asg_act_xst := 0;
10555 
10556       IF l_rec_09.count > 0 THEN
10557          FOR i IN l_rec_09.FIRST..l_rec_09.LAST
10558             LOOP
10559                l_rr_exists    := 0;
10560                hr_utility.set_location('current element : '||l_rec_09(i).element_type_id,10);
10561                hr_utility.set_location('asg id : '||p_assignment_id,12);
10562                hr_utility.set_location('start date :  ',14);
10563                hr_utility.set_location('end date :  ',15);
10564                FOR act_rec IN  csr_asg_act (
10565                                c_assignment_id => p_assignment_id
10566                               ,c_payroll_id    => g_extract_params(p_business_group_id).payroll_id
10567                               ,c_con_set_id    => NULL
10568                               ,c_start_date    => l_beg_new_st
10569                               ,c_end_date      => l_end_new_st)
10570                LOOP
10571 
10572                       l_reg_09_age_cal_dt := l_beg_new_st;
10573                       l_reg_09_age := Get_Age(p_assignment_id,trunc(l_reg_09_age_cal_dt)) ;
10574 
10575                       IF l_reg_09_age < 65 THEN
10576                       -- Check if Run Results exist for this element/ass act
10577                          IF chk_rr_exist (p_ass_act_id      => act_rec.assignment_action_id
10578                                          ,p_element_type_id => l_rec_09(i).element_type_id ) THEN
10579                             -- Call pay_balance_pkg
10580                             hr_utility.set_location('run results exist for current period',40);
10581                             IF l_rec_09(i).defined_bal_id <> -1 THEN
10582                                l_rec_09_values(k).basis_amount :=
10583                                Pay_Balance_Pkg.get_value
10584                                    (p_defined_balance_id   => l_rec_09(i).defined_bal_id
10585                                    ,p_assignment_action_id => act_rec.assignment_action_id);
10586                                hr_utility.set_location('defined bal id used :'||l_rec_09(i).defined_bal_id,50);
10587                                l_rec_09_disp := 'Y';
10588                                l_rec_09_values(k).processed := 'N';
10589                                l_rec_09_values(k).code := l_rec_09(i).code;
10590                                l_rec_09_values(k).date_earned :=
10591                                substr(fnd_date.date_to_canonical(l_end_new_st),1,10);
10592 
10593                                OPEN c_09_abp_data (l_end_new_st,l_rec_09(i).code);
10594                                FETCH c_09_abp_data INTO l_09_basis_amt_sent_prev;
10595                                  IF c_09_abp_data%FOUND THEN
10596                                    l_rec_09_values(k).basis_amount := l_rec_09_values(k).basis_amount
10597                                                                     - l_09_basis_amt_sent_prev;
10598                                  END IF;
10599                                CLOSE c_09_abp_data;
10600 
10601                                IF l_rec_09_values(k).basis_amount < 0 THEN
10602                                   l_rec_09_values(k).sign_code := 'C';
10603                                END IF;
10604                                l_gzz_asg_act_xst := 1;
10605                                k := k + 1;
10606                             END IF;-- Defined bal check
10607                          END IF;-- RR exist check
10608 
10609                       END IF; -- Age check
10610                END LOOP; -- Ass acts
10611           END LOOP; -- All elements for Rec 09
10612       END IF; -- Record 09 elements exist
10613 
10614    l_beg_new_st := ADD_MONTHS(l_beg_new_st,1);
10615 
10616   END LOOP; -- Loop through the months
10617 
10618 END Populate_Term_Rev_Data;
10619 */
10620 
10621 --============================================================================
10622 -- Record 05 Reporting
10623 -- This record is used to report the following incidents for FPU OPNP and PPP
10624 -- New Hire/Participation Start
10625 -- Participation End
10626 -- Retro changes
10627 -- Termination/ participation end
10628 -- Political leave
10629 --============================================================================
10630 FUNCTION Get_Rec05_Participation
10631           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
10632           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
10633           ,p_fetch_code           IN  VARCHAR2
10634           ,p_effective_date       IN  DATE
10635           ,p_error_message        OUT NOCOPY VARCHAR2
10636           ,p_data_element_value   OUT NOCOPY VARCHAR2)
10637 RETURN NUMBER IS
10638 --
10639 -- Cursor to find the org id for the current asg
10640 --
10641 CURSOR c_find_org_id IS
10642 SELECT organization_id
10643   FROM per_all_assignments_f
10644  WHERE assignment_id = p_assignment_id
10645    AND p_effective_date BETWEEN effective_start_date
10646                             AND effective_end_date;
10647 --
10648 -- Cursor to fetch the kind and value of participation from the ASG EIT
10649 --
10650 CURSOR c_get_participation_detl IS
10651 SELECT Nvl(aei_information4,'WNE') kind,
10652        LEAST(Nvl(fnd_number.canonical_to_number(aei_information5),1),1) VALUE
10653   FROM per_assignment_extra_info
10654  WHERE  information_type = 'NL_ABP_PAR_INFO'
10655    AND  aei_information_category = 'NL_ABP_PAR_INFO'
10656    AND  assignment_id = p_assignment_id
10657    AND  p_effective_date BETWEEN Fnd_Date.canonical_to_date(aei_information1)
10658                              AND Fnd_Date.canonical_to_date(Nvl(aei_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)));
10659 --
10660 -- Cursor to get the hire date of the person
10661 --
10662 CURSOR c_hire_dt IS
10663 SELECT max(date_start)
10664   FROM per_all_assignments_f asg
10665       ,per_periods_of_service pps
10666  WHERE pps.person_id     = asg.person_id
10667    AND asg.assignment_id = p_assignment_id
10668    AND pps.business_group_id = p_business_group_id
10669    AND date_start <= p_effective_date;
10670 
10671 --
10672 -- Cursor to check if run results exist for any FPU/OPNP Pension Types
10673 -- for this assignment
10674 --
10675 CURSOR c_run_results_exist IS
10676 SELECT pty.pension_type_id
10677       ,pty.pension_sub_category sub_cat
10678   FROM pay_run_results prr,
10679        pay_payroll_actions ppa,
10680        pay_assignment_actions paa,
10681        pay_element_type_extra_info pei,
10682        pqp_pension_types_f pty
10683  WHERE paa.assignment_action_id = prr.assignment_action_id
10684    AND paa.payroll_action_id = ppa.payroll_action_id
10685    AND ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
10686    AND g_extract_params(p_business_group_id).extract_end_date
10687    AND paa.assignment_id = p_assignment_id
10688    AND pei.element_type_id = prr.element_type_id
10689    AND pei.information_type = 'PQP_NL_ABP_DEDUCTION'
10690    AND pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
10691    AND pei.eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
10692    AND (pty.pension_sub_category LIKE 'FPU%'
10693        OR pty.pension_sub_category LIKE 'OPNP%'
10694        OR pty.pension_sub_category = 'PPP');
10695 
10696 --
10697 -- Cursor to fetch the termination reason
10698 -- from the ben ext log table
10699 --
10700 
10701 -- Bug# 6506736
10702 CURSOR c_get_end_reason IS
10703 SELECT /*decode(nvl(leaving_reason ,'A'),'D','I','A') term_reas*/
10704 	 decode(nvl(leaving_reason ,'A'),'D','I','B','B','A') term_reas
10705   FROM per_periods_of_service pps,
10706        per_all_assignments_f asg
10707  WHERE asg.period_of_service_id = pps.period_of_service_id
10708    AND assignment_id = p_assignment_id
10709    AND p_effective_date between effective_start_date and
10710                                 effective_end_date ;
10711 
10712 
10713 CURSOR c_hire_ptp_chg (c_asg_id    IN NUMBER) IS
10714 SELECT asg.effective_start_date Start_Date
10715       ,asg.effective_end_date   End_Date
10716       ,fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')) ptp
10717   FROM per_assignments_f asg
10718       ,hr_soft_coding_keyflex target
10719       ,per_assignment_status_types past
10720 WHERE target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
10721   AND asg.assignment_id = c_asg_id
10722   AND target.enabled_flag = 'Y'
10723   AND asg.assignment_status_type_id = past.assignment_status_type_id
10724   AND past.per_system_status = 'ACTIVE_ASSIGN'
10725   AND asg.effective_start_date BETWEEN
10726       trunc(g_extract_params(p_business_group_id).extract_start_date)
10727   AND trunc(g_extract_params(p_business_group_id).extract_end_date)
10728   ORDER BY START_DATE;
10729 
10730 l_hire_ptp_chg c_hire_ptp_chg%ROWTYPE;
10731 
10732 CURSOR c_hf_pos_cur (c_pos_id IN NUMBER)IS
10733 SELECT TRUNC(date_start)
10734   FROM per_periods_of_service
10735  WHERE period_of_service_id = c_pos_id
10736    AND TRUNC(date_start) = trunc(actual_termination_date);
10737 
10738 CURSOR c_prev_term_dt (c_asg_seq_no  IN VARCHAR2 ) IS
10739 SELECT dtl.val_07,
10740        DECODE(dtl.val_09,' ','A')
10741   FROM ben_ext_rslt_dtl     dtl
10742       ,ben_ext_rslt         res
10743       ,ben_ext_rcd          rcd
10744       ,ben_ext_rcd_in_file  rin
10745       ,ben_ext_dfn          dfn
10746 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
10747                            FROM pqp_extract_attributes
10748                           WHERE ext_dfn_type = 'NL_FPR')
10749  and dtl.person_id    = g_person_id
10750  and ext_stat_cd      = 'A'
10751  AND TRUNC(res.eff_dt) < TRUNC(g_extract_params(p_business_group_id).extract_start_date)
10752  AND rin.ext_file_id  = dfn.ext_file_id
10753  AND rin.ext_rcd_id   = rcd.ext_rcd_id
10754  AND dfn.ext_dfn_id   = res.ext_dfn_id
10755  and dtl.ext_rslt_id  = res.ext_rslt_id
10756  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
10757  AND rin.seq_num      = 5
10758  AND NVL(dtl.val_07,'X') <> '00000000'
10759  AND dtl.val_04 = c_asg_seq_no
10760  order by ext_rslt_dtl_id desc;
10761 
10762  CURSOR c_prev_term_rev (c_asg_seq_no   IN VARCHAR2
10763                         ,c_in_term_date IN VARCHAR2) IS
10764 SELECT 1
10765   FROM ben_ext_rslt_dtl     dtl
10766       ,ben_ext_rslt         res
10767       ,ben_ext_rcd          rcd
10768       ,ben_ext_rcd_in_file  rin
10769       ,ben_ext_dfn          dfn
10770 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
10771                            FROM pqp_extract_attributes
10772                           WHERE ext_dfn_type = 'NL_FPR')
10773  and dtl.person_id    = g_person_id
10774  and ext_stat_cd      = 'A'
10775  AND TRUNC(res.eff_dt) < TRUNC(g_extract_params(p_business_group_id).extract_start_date)
10776  AND rin.ext_file_id  = dfn.ext_file_id
10777  AND rin.ext_rcd_id   = rcd.ext_rcd_id
10778  AND dfn.ext_dfn_id   = res.ext_dfn_id
10779  and dtl.ext_rslt_id  = res.ext_rslt_id
10780  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
10781  AND rin.seq_num      = 5
10782  AND NVL(dtl.val_05,'X') = '00000000'
10783  AND NVL(dtl.val_06,'X') = '00000000'
10784  AND NVL(dtl.val_07,'X') = '00000000'
10785  AND NVL(dtl.val_08,'X') = c_in_term_date
10786  AND dtl.val_04 = c_asg_seq_no
10787  order by ext_rslt_dtl_id desc;
10788 
10789 -- Cursor to check if there is a change in hire date
10790 -- the change may be in the future or in the past
10791 -- with or without payroll runs
10792 CURSOR c_hire_dt_chg(c_person_id  IN NUMBER
10793                     ,c_start_date IN DATE
10794                     ,c_end_date   IN DATE) IS
10795 SELECT old_val1 old_date,
10796        new_val1 new_date
10797   FROM ben_ext_chg_evt_log
10798 WHERE  person_id = c_person_id
10799   AND  chg_evt_cd = 'COPOS'
10800   AND  fnd_date.canonical_to_date(prmtr_09) BETWEEN c_start_date AND c_end_date
10801 ORDER BY ext_chg_evt_log_id desc;
10802 
10803 CURSOR c_chk_ptpn_continues (c_end_date IN DATE,
10804                              c_pt_id    IN NUMBER) IS
10805 SELECT 1
10806   FROM per_assignment_extra_info paei
10807  WHERE paei.assignment_id = p_assignment_id
10808    AND fnd_number.canonical_to_number(aei_information3) = c_pt_id
10809    AND paei.information_type = 'NL_ABP_PI'
10810    AND fnd_date.canonical_to_date(aei_information1) = c_end_date + 1;
10811 
10812 CURSOR c_chk_ptpn_continues_kind (c_end_date  IN DATE
10813                             ,c_ptpn_kind IN VARCHAR2) IS
10814 SELECT 1
10815   FROM per_assignment_extra_info paei
10816  WHERE paei.assignment_id = p_assignment_id
10817    AND aei_information4 = c_ptpn_kind
10818    AND aei_information4 is not null
10819    AND paei.information_type = 'NL_ABP_PAR_INFO'
10820    AND fnd_date.canonical_to_date(aei_information1) = c_end_date + 1;
10821 
10822 CURSOR c_rec05_sub_cat IS
10823 SELECT lookup_code sub_cat, DECODE(lookup_code,'PPP','1'
10824                                    ,'OPNP','G'
10825                                    ,'OPNP_65','A'
10826                                    ,'OPNP_AOW','G'
10827                                    ,'OPNP_W25','B'
10828                                    ,'OPNP_W50','C'
10829                                    ,'FPU_B','S'
10830                                    ,'FPU_E','C'
10831                                    ,'FPU_R','A'
10832                                    ,'FPU_S','S'
10833                                    ,'FPU_T','B'
10834                                    ,' ')  code
10835   FROM fnd_lookup_values
10836  WHERE lookup_type = 'PQP_PENSION_SUB_CATEGORY'
10837    AND lookup_code IN ('PPP','OPNP','OPNP_65','OPNP_AOW'
10838                       ,'OPNP_W25','OPNP_W50','FPU_B','FPU_E'
10839                       ,'FPU_R','FPU_S','FPU_T')
10840   AND NVL(enabled_flag,'N') = 'Y'
10841   AND language = 'US';
10842 
10843 CURSOR c_rec05_sent IS
10844 SELECT 1
10845   FROM ben_ext_rslt_dtl     dtl
10846       ,ben_ext_rslt         res
10847       ,ben_ext_rcd          rcd
10848       ,ben_ext_rcd_in_file  rin
10849       ,ben_ext_dfn          dfn
10850 WHERE dfn.ext_dfn_id IN (SELECT ext_dfn_id
10851                            FROM pqp_extract_attributes
10852                           WHERE ext_dfn_type = 'NL_FPR')
10853  and dtl.person_id    = g_person_id
10854  and ext_stat_cd      = 'A'
10855  AND TRUNC(res.eff_dt) < TRUNC(g_extract_params(p_business_group_id).extract_start_date)
10856  AND rin.ext_file_id  = dfn.ext_file_id
10857  AND rin.ext_rcd_id   = rcd.ext_rcd_id
10858  AND dfn.ext_dfn_id   = res.ext_dfn_id
10859  and dtl.ext_rslt_id  = res.ext_rslt_id
10860  AND dtl.ext_rcd_id   = rcd.ext_rcd_id
10861  AND rin.seq_num      = 5;
10862 
10863 CURSOR c_copos_ptp_chg (c_asg_id    IN NUMBER
10864                        ,c_eff_date  IN DATE ) IS
10865 SELECT fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')) ptp
10866   FROM per_assignments_f asg
10867       ,hr_soft_coding_keyflex target
10868       ,per_assignment_status_types past
10869 WHERE  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
10870   AND  asg.assignment_id = c_asg_id
10871   AND  target.enabled_flag = 'Y'
10872   AND  asg.assignment_status_type_id = past.assignment_status_type_id
10873   AND  past.per_system_status = 'ACTIVE_ASSIGN'
10874   AND  trunc(c_eff_date) BETWEEN asg.effective_start_date AND
10875        asg.effective_end_date
10876   order by asg.effective_start_date;
10877 
10878 CURSOR c_pay_id IS
10879 SELECT payroll_id
10880   FROM per_all_assignments_f
10881  WHERE assignment_id = p_assignment_id
10882    AND p_effective_date BETWEEN effective_start_date AND
10883                                 effective_end_date;
10884 
10885 --6501898
10886 --Commented for 6959318
10887 /*CURSOR c_get_term_dt IS
10888 SELECT MIN(effective_start_date) - 1 term_date
10889   FROM per_all_assignments_f asg
10890  WHERE assignment_id = p_assignment_id
10891    AND assignment_status_type_id IN (SELECT assignment_status_type_id
10892                                        FROM per_assignment_status_types
10893                                       WHERE per_system_status = 'TERM_ASSIGN'
10894                                         AND active_flag = 'Y')
10895    AND assignment_type = 'E';*/
10896 
10897 l_chg_eff_dt           ben_ext_chg_evt_log.chg_eff_dt%TYPE;
10898 l_chg_evt_cd           ben_ext_chg_evt_log.chg_evt_cd%TYPE;
10899 l_active_assg          NUMBER;
10900 l_rec05_sent           NUMBER;
10901 l_prior_ptp            NUMBER;
10902 l_dummy                NUMBER;
10903 l_hf_pos_dt            DATE;
10904 l_proc_name            VARCHAR2(150) := g_proc_name ||'get_rec05_participation';
10905 l_return_value         NUMBER := -1;
10906 l_named_hierarchy      NUMBER;
10907 l_version_id
10908    per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
10909 l_asg_rows_exist       NUMBER;
10910 l_org_rows_exist       NUMBER;
10911 l_kind                 VARCHAR2(30) := 'WNE';
10912 l_value                VARCHAR2(30) := '100';
10913 l_value_num            NUMBER;
10914 l_old_date1            ben_ext_chg_evt_log.old_val1%TYPE;
10915 l_new_date1            ben_ext_chg_evt_log.new_val1%TYPE;
10916 l_old_date2            ben_ext_chg_evt_log.old_val1%TYPE;
10917 l_new_date2            ben_ext_chg_evt_log.new_val1%TYPE;
10918 l_term_log_id          ben_ext_chg_evt_log.ext_chg_evt_log_id%TYPE;
10919 l_revt_log_id          ben_ext_chg_evt_log.ext_chg_evt_log_id%TYPE;
10920 l_reason               VARCHAR2(1);
10921 l_old_term_reason      VARCHAR2(1);
10922 l_org_id               NUMBER;
10923 l_ppp_start            ben_ext_chg_evt_log.new_val1%TYPE;
10924 l_ppp_end              ben_ext_chg_evt_log.new_val2%TYPE;
10925 l_ppp_found            NUMBER := 0;
10926 l_ppp_kind             VARCHAR2(1) := ' ';
10927 l_ppp_ret              NUMBER;
10928 l_ppp_err              VARCHAR2(1000);
10929 i                      NUMBER := 0;
10930 l_loop_again           NUMBER;
10931 l_flag                 NUMBER := 0;
10932 l_hire_date            DATE;
10933 l_pt_id                NUMBER;
10934 l_end_date             DATE;
10935 l_hired                NUMBER := 0;
10936 l_ret_val              NUMBER;
10937 l_ret_val1             NUMBER;
10938 l_hire_date1           DATE;
10939 l_retro_ptp_index      NUMBER;
10940 l_ptp                  NUMBER(9,2);
10941 l_partn_rows_exist     NUMBER := 0;
10942 l_term_rows_exist      NUMBER := 0;
10943 l_age                  NUMBER;
10944 l_old_hire             DATE;
10945 l_new_hire             DATE;
10946 l_retro_hired          NUMBER := 0;
10947 l_fpu_ret_val          NUMBER;
10948 l_ptp_row_ins          NUMBER := 0;
10949 l_abp_pen_rr           NUMBER;
10950 l_payroll_id           NUMBER;
10951 l_new_hire_row         NUMBER;
10952 l_terminated_row       NUMBER;
10953 l_term_pos_id          NUMBER;
10954 l_opnp_ret_val         NUMBER;
10955 l_prev_term_dt         VARCHAR2(8);
10956 l_old_hire_dt          DATE;
10957 l_new_hire_dt          DATE;
10958 l_old_hire_dt_can      ben_ext_chg_evt_log.old_val1%TYPE;
10959 l_new_hire_dt_can      ben_ext_chg_evt_log.new_val1%TYPE;
10960 l_out_retro_ptpn       t_retro_ptpn;
10961 l_out_retro_ptpn_kind  t_retro_ptpn_kind;
10962 l_ge_retro_ptpn        NUMBER;
10963 l_ge_retro_ptpn_kind   NUMBER;
10964 l_ret_index_05         NUMBER;
10965 l_ret_index_05_kind    NUMBER;
10966 w                      NUMBER;
10967 l_kind_change_exists   NUMBER;
10968 l_copos_xst            NUMBER;
10969 l_copos_ptp            NUMBER;
10970 l_new_hire_ee_chk      NUMBER := 0;
10971 l_ret_val_asg          NUMBER;
10972 l_seq_num              VARCHAR2(2);
10973 l_asg_termination_dt   DATE;
10974 l_prev_term_rev        NUMBER;
10975 --6501898
10976 l_hrly_ptp_rec       c_ptp_chg_hrly_exist%ROWTYPE;
10977 l_asg_term_dt DATE;
10978 
10979 BEGIN
10980 
10981 Hr_Utility.set_location('Entering:------'||l_proc_name, 2);
10982 Hr_Utility.set_location('....Value of assignment id  : '||p_assignment_id,4);
10983 Hr_Utility.set_location('....Value of g_index        : '||g_index_05,6);
10984 Hr_Utility.set_location('....Value of g_count        : '||g_count_05,8);
10985 Hr_Utility.set_location('....Value of fetch code     : '||p_fetch_code ,10);
10986 
10987 --
10988 -- Derive the age of the employee
10989 --
10990 l_age := Get_Age(p_assignment_id,p_effective_date);
10991 
10992 Hr_Utility.set_location('....Value of l_age : '||l_age ,12);
10993 
10994 IF     g_index_05 = 0
10995    AND p_fetch_code = 'NEW_ST'
10996    AND g_abp_processed_flag = 1 THEN
10997 
10998 Hr_Utility.set_location('....Populating the PLSQL Table for the first time : ',12);
10999 
11000 g_count_05 := 0;
11001 l_rec_05_disp := 'N';
11002 
11003 OPEN c_get_participation_detl;
11004 FETCH c_get_participation_detl INTO l_kind,l_value;
11005 IF c_get_participation_detl%FOUND THEN
11006    CLOSE c_get_participation_detl;
11007 ELSE
11008    CLOSE c_get_participation_detl;
11009    l_kind := 'WNE';
11010    l_value := '1';
11011 END IF;
11012 
11013 l_value_num := fnd_number.canonical_to_number(l_value);
11014 l_value_num := l_value_num * 100;
11015 l_value     := fnd_number.number_to_canonical(l_value_num);
11016 
11017 Hr_Utility.set_location('....Value of l_value : '||l_value ,14);
11018 Hr_Utility.set_location('....Value of l_kind : '||l_kind ,16);
11019 
11020 --
11021 -- Check if the EE assignment is a new hire and to be reported.
11022 --
11023 IF g_new_hire_asg = 1 THEN
11024    l_hired := 1;
11025 ELSE
11026    l_hired := 0;
11027 END IF;
11028 
11029 l_hire_date := g_hire_date;
11030 
11031 IF l_hired = 1 THEN
11032 --
11033 -- Derive the part time percentage to be reported for a new hire
11034 --
11035 OPEN c_cur_ptp (l_hire_date,p_assignment_id);
11036 
11037    FETCH c_cur_ptp INTO l_ptp;
11038       IF c_cur_ptp%FOUND THEN
11039          l_ptp := l_ptp * 100;
11040          hr_utility.set_location('....Found PTP : '||l_ptp,28);
11041       ELSE
11042          l_ptp := 0;
11043          hr_utility.set_location('....Did not find PTP : '||l_ptp,28);
11044       END IF;
11045    CLOSE c_cur_ptp;
11046 
11047    -- 6501898 : For declarant new hires, check if PTP is entered in the current period
11048    -- through an Hours element
11049   /* Commented for Bug 6959318
11050    IF l_ptp = 0 THEN
11051        --
11052        OPEN c_get_retro_ele('ABP Pensions Part Time Percentage'
11053                                ,'Part Time Percentage');
11054        FETCH c_get_retro_ele INTO g_abp_ptp_iv_id,g_abp_ptp_ele_id;
11055        CLOSE c_get_retro_ele;
11056        --
11057        OPEN c_ptp_chg_hrly_exist (c_asg_id         => p_assignment_id
11058                      ,c_effective_date => l_hire_date
11059                      ,c_ele_type_id    => g_abp_ptp_ele_id
11060                      ,c_input_val_id   => g_abp_ptp_iv_id);
11061 
11062        FETCH c_ptp_chg_hrly_exist INTO l_hrly_ptp_rec;
11063        --
11064        IF c_ptp_chg_hrly_exist%FOUND THEN
11065          OPEN c_get_term_dt;
11066          FETCH c_get_term_dt INTO l_asg_term_dt;
11067          IF c_get_term_dt%NOTFOUND THEN
11068             l_asg_term_dt := NULL;
11069          END IF;
11070          CLOSE c_get_term_dt;
11071          l_ptp := l_hrly_ptp_rec.ptp * 100;
11072          --Bug# 5973446
11073 		 l_ptp :=
11074 		 l_ptp *
11075 		 (
11076 		 ((l_hrly_ptp_rec.end_date - l_hrly_ptp_rec.start_date)+1)
11077 		 /
11078 		 (LEAST(l_hrly_ptp_rec.end_date,nvl(l_asg_term_dt,l_hrly_ptp_rec.end_date)) -
11079 		  GREATEST(l_hire_date,l_hrly_ptp_rec.start_date)+1)
11080 		 );
11081          --Bug# 5973446
11082        ELSE
11083          l_ptp := 0;
11084        END IF;
11085        --
11086        CLOSE c_ptp_chg_hrly_exist;
11087        --
11088    END IF;*/
11089    -- End of 6501898
11090 
11091 hr_utility.set_location('....Value of PTP is  : '||l_ptp,28);
11092 
11093 END IF;
11094 
11095 Hr_Utility.set_location('....New hire flag is l_hired : '||l_hired ,18);
11096 
11097 -- ==========================================================================
11098 -- BEGIN NEW HIRE PARTICIPATION REPORTING SECTION
11099 -- ==========================================================================
11100 IF l_hired = 1 THEN
11101 
11102 OPEN c_pay_id;
11103 FETCH c_pay_id INTO l_payroll_id;
11104 CLOSE c_pay_id;
11105 
11106    IF g_abp_processed_flag = 1 THEN
11107    --
11108    -- ABP Pensions has been processed on new hire. Create a new hire row
11109    --
11110    g_rec05_rows(i).new_start      := Fnd_Date.date_to_canonical(l_hire_date);
11111    g_rec05_rows(i).dt_chg         := NULL;
11112    g_rec05_rows(i).old_start      := NULL;
11113    g_rec05_rows(i).end_reason     := NULL;
11114    g_rec05_rows(i).eddt_chg       := NULL;
11115    g_rec05_rows(i).end_reason     := ' ';
11116    g_rec05_rows(i).old_end        := NULL;
11117    g_rec05_rows(i).new_end        := NULL;
11118    g_rec05_rows(i).partn_kind     := l_kind;
11119    g_rec05_rows(i).partn_value    := l_value;
11120    g_rec05_rows(i).part_time_perc := l_ptp;
11121 
11122    l_ppp_ret := Get_PPP_Kind
11123                 (p_assignment_id        => p_assignment_id
11124                 ,p_business_group_id    => p_business_group_id
11125                 ,p_effective_date       => p_effective_date
11126                 ,p_current              => 'Y'
11127                 ,p_error_message        => l_ppp_err
11128                 ,p_data_element_value   => g_rec05_rows(i).ppp_kind );
11129 
11130    IF l_ppp_ret <> 0 THEN
11131       g_rec05_rows(i).ppp_kind := '0';
11132    END IF;
11133 
11134    l_fpu_ret_val  := Get_FPU_Kind
11135                       (p_assignment_id
11136                       ,p_business_group_id
11137                       ,p_effective_date
11138                       ,p_error_message
11139                       ,g_rec05_rows(i).fpu_kind);
11140 
11141    l_opnp_ret_val := Get_OPNP_Kind
11142                        ( p_assignment_id
11143                         ,p_business_group_id
11144                         ,p_effective_date
11145                         ,p_error_message
11146                         ,g_rec05_rows(i).opnp_kind);
11147 
11148    l_new_hire_row := i;
11149    i := i + 1;
11150    g_count_05 := i;
11151 
11152    END IF; -- Check if ABP is processed
11153 
11154 END IF; -- Check for New hire
11155 
11156 -- ==========================================================================
11157 -- END NEW HIRE PARTICIPATION REPORTING SECTION
11158 -- ==========================================================================
11159 
11160 -- ==========================================================================
11161 -- BEGIN RETRO HIRE CHECK SECTION
11162 -- ==========================================================================
11163 l_copos_xst := 0;
11164 
11165 OPEN c_hire_dt_chg(c_person_id  => g_person_id
11166                   ,c_start_date => g_extract_params(p_business_group_id).extract_start_date
11167                   ,c_end_date   => g_extract_params(p_business_group_id).extract_end_date);
11168 FETCH c_hire_dt_chg INTO l_old_hire_dt_can,l_new_hire_dt_can;
11169 
11170 IF c_hire_dt_chg%FOUND THEN
11171       l_old_hire_dt := to_nl_date(l_old_hire_dt_can,'DD-MM-RRRR');
11172       l_new_hire_dt := to_nl_date(l_new_hire_dt_can,'DD-MM-RRRR');
11173 
11174     l_copos_xst   := 1;
11175 
11176    IF l_hired = 1 THEN
11177       --
11178       -- Update the existing row for reporting the change
11179       --
11180       g_rec05_rows(l_new_hire_row).old_start := Fnd_Date.date_to_canonical(l_hire_date);
11181       g_rec05_rows(l_new_hire_row).new_start := fnd_date.date_to_canonical(l_new_hire_dt);
11182 
11183       OPEN c_copos_ptp_chg (c_asg_id     => p_assignment_id
11184                            ,c_eff_date   => trunc(l_new_hire_dt));
11185       FETCH c_copos_ptp_chg INTO l_copos_ptp;
11186       CLOSE c_copos_ptp_chg;
11187       IF l_copos_ptp IS NOT NULL THEN
11188          g_rec05_rows(l_new_hire_row).part_time_perc := l_copos_ptp * 100 ;
11189       END IF;
11190 
11191    ELSIF l_hired = 0 THEN
11192       --
11193       -- Create a new Record 05 for reporting the change in hire dt
11194       --
11195       g_rec05_rows(i).new_end        := NULL;
11196       g_rec05_rows(i).old_end        := NULL;
11197       g_rec05_rows(i).new_start      := Fnd_Date.date_to_canonical(l_new_hire_dt);
11198       g_rec05_rows(i).old_start      := Fnd_Date.date_to_canonical(l_old_hire_dt);
11199       g_rec05_rows(i).partn_kind     := NULL;
11200       g_rec05_rows(i).partn_value    := '   ';
11201       g_rec05_rows(i).part_time_perc := NULL;
11202       g_rec05_rows(i).dt_chg         := NULL;
11203       g_rec05_rows(i).eddt_chg       := NULL;
11204       g_rec05_rows(i).end_reason     := ' ';
11205       g_rec05_rows(i).ppp_kind       := ' ';
11206       g_rec05_rows(i).fpu_kind       := ' ';
11207       g_rec05_rows(i).opnp_kind      := ' ';
11208       g_rec05_rows(i).pos_id         := NULL;
11209       i := i + 1;
11210       g_count_05 := i;
11211       --
11212    END IF;
11213 
11214    OPEN c_rec05_sent;
11215    FETCH c_rec05_sent INTO l_rec05_sent;
11216    IF c_rec05_sent%NOTFOUND THEN
11217       -- record 05 was not sent earlier
11218       g_rec05_rows(i-1).old_start      := NULL;
11219    END IF;
11220    CLOSE c_rec05_sent;
11221 
11222 END IF;
11223 CLOSE c_hire_dt_chg;
11224 
11225 -- ==========================================================================
11226 -- END RETRO HIRE CHECK SECTION
11227 -- ==========================================================================
11228 
11229 -- ==========================================================================
11230 -- BEGIN RETRO CHANGE IN PART TIME PERCENTAGE SECTION
11231 -- ==========================================================================
11232 -- Reporting Retro changes to part time percentage
11233 -- This section contains Record 05 Rows that appear due to change
11234 -- in part time percentage in the prior periods
11235 -- Sections 1,2,3,4 Should be filled with appropriate values
11236 -- Sections 5,6,7 and 8 should contain 00000000
11237 -- Sections 9,11,12,13,14,15 should contain white spaces
11238 -- Section 10 should contain the part time percentage change effective st dt
11239 -- Section 17 should contain the part time percentage change effective ed dt
11240 -- Section 16 should contain the part time percentage.
11241 --
11242 IF g_retro_ptp_count > 0 THEN
11243 
11244    hr_utility.set_location('....Found retro entries for PTP elements: ',24);
11245    hr_utility.set_location('....Value of g_retro_ptp_count is : '||g_retro_ptp_count,22);
11246 
11247    FOR l_retro_ptp_index IN 1..g_retro_ptp_count
11248       LOOP
11249       hr_utility.set_location('....Looping through retro PTP entries : '||i,24);
11250       g_rec05_rows(i).partn_kind  := '   ';
11251       g_rec05_rows(i).partn_value := '   ';
11252       g_rec05_rows(i).end_reason  := ' ';
11253       g_rec05_rows(i).ppp_kind    := ' ';
11254       g_rec05_rows(i).fpu_kind    := ' ';
11255       g_rec05_rows(i).opnp_kind   := ' ';
11256       g_rec05_rows(i).old_start   := NULL;
11257       g_rec05_rows(i).old_end     := NULL;
11258       g_rec05_rows(i).new_start   := NULL;
11259       g_rec05_rows(i).new_end     := NULL;
11260       g_rec05_rows(i).dt_chg      := fnd_date.date_to_canonical
11261                                      (l_rec_05_retro_ptp(l_retro_ptp_index).start_date);
11262       hr_utility.set_location('....Change date st : '||g_rec05_rows(i).dt_chg,24);
11263       IF l_rec_05_retro_ptp(l_retro_ptp_index).end_date >=
11264          trunc(g_extract_params(p_business_group_id).extract_end_date) THEN
11265          g_rec05_rows(i).eddt_chg    := NULL;
11266       ELSE
11267          g_rec05_rows(i).eddt_chg    := fnd_date.date_to_canonical(l_rec_05_retro_ptp(l_retro_ptp_index).end_date);
11268       END IF;
11269       hr_utility.set_location('....Change date End : '||g_rec05_rows(i).eddt_chg,24);
11270       g_rec05_rows(i).part_time_perc := l_rec_05_retro_ptp(l_retro_ptp_index).part_time_perc;
11271       hr_utility.set_location('....Changed PTP : '||g_rec05_rows(i).part_time_perc,24);
11272 
11273       i := i + 1;
11274 
11275       END LOOP;
11276       g_count_05 := i;
11277       l_partn_rows_exist := 1;
11278       l_rec_05_retro_ptp.DELETE;
11279 
11280 END IF; -- Check if there are retro ptp chanegs to be reported
11281 
11282 hr_utility.set_location('....Completed Rec 05 Retro PTP Changes : ',24);
11283 -- ==========================================================================
11284 -- END RETRO CHANGE IN PART TIME PERCENTAGE SECTION
11285 -- ==========================================================================
11286 
11287 -- ==========================================================================
11288 -- BEGIN TERMINATION AND REVERSAL OF TERMINATION SECTION
11289 -- ==========================================================================
11290 l_terminated_row := -1;
11291 
11292 l_ret_val_asg  :=  Get_Asg_Seq_Num(p_assignment_id
11293                                   ,p_business_group_id
11294                                   ,p_effective_date
11295                                   ,p_error_message
11296                                   ,l_seq_num);
11297 
11298 
11299 OPEN c_get_asg_term_date (p_business_group_id
11300                          ,p_effective_date
11301                          ,p_assignment_id
11302                          ,l_seq_num);
11303 FETCH c_get_asg_term_date INTO l_asg_termination_dt,l_term_pos_id;
11304 
11305 IF c_get_asg_term_date%FOUND THEN
11306    --
11307    -- Termination Date was found for the assignment
11308    --
11309    --
11310    -- Derive the termination reason
11311    --
11312 
11313    OPEN c_get_end_reason;
11314    FETCH c_get_end_reason INTO l_reason;
11315    IF c_get_end_reason%NOTFOUND THEN
11316       l_reason := 'A';
11317    END IF;
11318    CLOSE c_get_end_reason;
11319 
11320    OPEN c_prev_term_dt(l_seq_num) ;
11321    FETCH c_prev_term_dt INTO l_prev_term_dt,l_old_term_reason;
11322    IF c_prev_term_dt%NOTFOUND THEN
11323       --
11324       -- Termination was never reported to ABP Report it now.
11325       --
11326       g_rec05_rows(i).new_end        := NVL(fnd_date.date_to_canonical(
11327                                         l_asg_termination_dt),'');
11328       g_rec05_rows(i).old_end        := NULL;
11329       g_rec05_rows(i).new_start      := '';
11330       g_rec05_rows(i).old_start      := '';
11331       g_rec05_rows(i).partn_kind     := NULL;
11332       g_rec05_rows(i).partn_value    := '   ';
11333       g_rec05_rows(i).part_time_perc := NULL;
11334       g_rec05_rows(i).ppp_kind       := ' ';
11335       g_rec05_rows(i).fpu_kind       := ' ';
11336       g_rec05_rows(i).opnp_kind      := ' ';
11337       g_rec05_rows(i).dt_chg         := '';
11338       g_rec05_rows(i).eddt_chg       := '';
11339       g_rec05_rows(i).end_reason     := l_reason;
11340       g_rec05_rows(i).pos_id         := l_term_pos_id;
11341       l_terminated_row               := i;
11342       i := i + 1;
11343       g_count_05 := i;
11344       l_term_rows_exist := 1;
11345    ELSIF c_prev_term_dt%FOUND AND TRUNC(fnd_date.canonical_to_date(l_prev_term_dt))
11346                                   <> TRUNC(l_asg_termination_dt) + 1
11347             THEN
11348       --
11349       -- Termination date has changed from the prev reported value.
11350       -- Report the old and new dates
11351       --
11352       g_rec05_rows(i).new_end        := nvl(fnd_date.date_to_canonical(
11353                                         l_asg_termination_dt),'');
11354       OPEN c_prev_term_rev(l_seq_num,l_prev_term_dt);
11355       FETCH c_prev_term_rev INTO l_prev_term_rev;
11356       IF c_prev_term_rev%NOTFOUND THEN
11357          g_rec05_rows(i).old_end        := fnd_date.date_to_canonical(
11358                                         fnd_date.canonical_to_date(l_prev_term_dt) - 1);
11359       ELSE
11360          g_rec05_rows(i).old_end        := NULL;
11361       END IF;
11362       g_rec05_rows(i).new_start      := '';
11363       g_rec05_rows(i).old_start      := '';
11364       g_rec05_rows(i).partn_kind     := NULL;
11365       g_rec05_rows(i).partn_value    := '   ';
11366       g_rec05_rows(i).part_time_perc := NULL;
11367       g_rec05_rows(i).ppp_kind       := ' ';
11368       g_rec05_rows(i).fpu_kind       := ' ';
11369       g_rec05_rows(i).opnp_kind      := ' ';
11370       g_rec05_rows(i).dt_chg         := '';
11371       g_rec05_rows(i).eddt_chg       := '';
11372       IF l_reason <> NVL(l_old_term_reason,'A') THEN
11373          g_rec05_rows(i).end_reason     := l_reason;
11374       ELSE
11375          g_rec05_rows(i).end_reason     := ' ';
11376       END IF;
11377       g_rec05_rows(i).pos_id         := l_term_pos_id;
11378       l_terminated_row               := i;
11379       i := i + 1;
11380       g_count_05 := i;
11381       l_term_rows_exist := 1;
11382 
11383    END IF;
11384 
11385    CLOSE c_prev_term_dt;
11386 
11387 ELSIF c_get_asg_term_date%NOTFOUND THEN
11388 
11389    OPEN c_prev_term_dt(l_seq_num) ;
11390    FETCH c_prev_term_dt INTO l_prev_term_dt,l_old_term_reason;
11391    IF c_prev_term_dt%FOUND THEN
11392       --
11393       -- Ensure that term reversal was not reported earlier
11394       --
11395       OPEN c_prev_term_rev(l_seq_num,l_prev_term_dt);
11396       FETCH c_prev_term_rev INTO l_prev_term_rev;
11397       IF c_prev_term_rev%NOTFOUND THEN
11398          --
11399          -- Termination reversal was never reported to ABP Report it now.
11400          --
11401          g_rec05_rows(i).new_end        := NULL;
11402          g_rec05_rows(i).old_end        := fnd_date.date_to_canonical(
11403                                            fnd_date.canonical_to_date(l_prev_term_dt) - 1);
11404          g_rec05_rows(i).new_start      := '';
11405          g_rec05_rows(i).old_start      := '';
11406          g_rec05_rows(i).partn_kind     := NULL;
11407          g_rec05_rows(i).partn_value    := '   ';
11408          g_rec05_rows(i).part_time_perc := NULL;
11409          g_rec05_rows(i).ppp_kind       := ' ';
11410          g_rec05_rows(i).fpu_kind       := ' ';
11411          g_rec05_rows(i).opnp_kind      := ' ';
11412          g_rec05_rows(i).dt_chg         := '';
11413          g_rec05_rows(i).eddt_chg       := '';
11414          g_rec05_rows(i).end_reason     := ' ';
11415          g_rec05_rows(i).pos_id         := NULL;
11416          i := i + 1;
11417          g_count_05 := i;
11418       END IF;
11419          CLOSE c_prev_term_rev;
11420     END IF;
11421     CLOSE c_prev_term_dt;
11422 
11423 END IF;
11424 
11425  CLOSE c_get_asg_term_date;
11426 
11427 
11428 IF l_hired = 1 AND l_terminated_row <> -1 THEN
11429    --
11430    -- Termination has happened in the same month as the hire.
11431    -- Record 05 should not be reported twice. It should be reported only once
11432    -- Update the new hire row and delete the termination row.
11433    --
11434    g_rec05_rows(l_new_hire_row).new_end :=
11435                          g_rec05_rows(l_terminated_row).new_end;
11436    g_rec05_rows(l_new_hire_row).end_reason :=
11437                          g_rec05_rows(l_terminated_row).end_reason;
11438    g_rec05_rows.DELETE(l_terminated_row);
11439    g_count_05 := g_count_05 - 1 ;
11440 
11441 END IF;
11442 
11443 IF l_hired = 0 AND l_terminated_row <> -1 THEN
11444    IF g_rec05_rows(l_terminated_row).pos_id IS NOT NULL THEN
11445    OPEN c_hf_pos_cur(g_rec05_rows(l_terminated_row).pos_id);
11446    FETCH c_hf_pos_cur INTO l_hf_pos_dt;
11447       IF c_hf_pos_cur%FOUND THEN
11448          g_rec05_rows(l_terminated_row).new_start      := NULL;
11449          g_rec05_rows(l_terminated_row).dt_chg         := NULL;
11450          g_rec05_rows(l_terminated_row).old_start      := fnd_date.date_to_canonical(l_hf_pos_dt);
11451          g_rec05_rows(l_terminated_row).end_reason     := NULL;
11452          g_rec05_rows(l_terminated_row).eddt_chg       := NULL;
11453          g_rec05_rows(l_terminated_row).end_reason     := NULL;
11454          g_rec05_rows(l_terminated_row).old_end        := NULL;
11455          g_rec05_rows(l_terminated_row).new_end        := NULL;
11456          g_rec05_rows(l_terminated_row).partn_kind     := NULL;
11457          g_rec05_rows(l_terminated_row).partn_value    := '   ';
11458          g_rec05_rows(l_terminated_row).part_time_perc := NULL;
11459          g_rec05_rows(l_terminated_row).ppp_kind       := ' ';
11460          g_rec05_rows(l_terminated_row).fpu_kind       := ' ';
11461          g_rec05_rows(l_terminated_row).opnp_kind      := ' ';
11462          g_rec05_rows(l_terminated_row).end_reason     := ' ';
11463       END IF;
11464    END IF;
11465 END IF;
11466 
11467 -- ==========================================================================
11468 -- END TERMINATION AND REVERSAL OF TERMINATION SECTION
11469 -- ==========================================================================
11470 l_kind_change_exists := 0;
11471 
11472 IF l_hired = 0 THEN
11473 
11474 l_ge_retro_ptpn_kind := Get_Retro_Kind_Of_Ptpn
11475           (p_assignment_id        => p_assignment_id
11476           ,p_business_group_id    => p_business_group_id
11477           ,p_effective_date       => p_effective_date
11478           ,p_retro_kind_ptpn      => l_out_retro_ptpn_kind
11479           ,p_error_message        => p_error_message);
11480 IF l_out_retro_ptpn_kind.COUNT > 0 THEN
11481 
11482 l_ret_index_05_kind := l_out_retro_ptpn_kind.LAST;
11483 FOR w IN 1..l_ret_index_05_kind LOOP
11484    IF l_out_retro_ptpn_kind.EXISTS(w) THEN
11485        g_rec05_rows(i).new_end        := NULL;
11486        g_rec05_rows(i).old_end        := NULL;
11487        g_rec05_rows(i).new_start      := NULL;
11488        g_rec05_rows(i).old_start      := NULL;
11489        g_rec05_rows(i).partn_kind     := l_out_retro_ptpn_kind(w).ptpn_kind;
11490        g_rec05_rows(i).partn_value    := l_out_retro_ptpn_kind(w).ptpn_val;
11491        g_rec05_rows(i).part_time_perc := NULL;
11492        g_rec05_rows(i).fpu_kind       := ' ';
11493        g_rec05_rows(i).opnp_kind      := ' ';
11494        g_rec05_rows(i).ppp_kind       := ' ';
11495        g_rec05_rows(i).dt_chg         := fnd_date.date_to_canonical(l_out_retro_ptpn_kind(w).start_date);
11496        IF fnd_date.date_to_canonical(TRUNC(l_out_retro_ptpn_kind(w).end_date)) =
11497           '4712/12/31 00:00:00' THEN
11498         g_rec05_rows(i).eddt_chg := NULL;
11499 
11500        ELSE
11501 
11502         OPEN c_chk_ptpn_continues_kind ( l_out_retro_ptpn_kind(w).end_date
11503                                         ,l_out_retro_ptpn_kind(w).ptpn_kind);
11504           FETCH c_chk_ptpn_continues_kind INTO l_dummy;
11505              IF c_chk_ptpn_continues_kind%NOTFOUND THEN
11506                 g_rec05_rows(i).eddt_chg := fnd_date.date_to_canonical(l_out_retro_ptpn_kind(w).end_date);
11507              ELSE
11508                 g_rec05_rows(i).eddt_chg := NULL;
11509              END IF;
11510           CLOSE c_chk_ptpn_continues_kind;
11511         END IF;
11512 
11513        g_rec05_rows(i).end_reason     := '';
11514        l_kind_change_exists := 1;
11515 
11516        i := i + 1;
11517        g_count_05 := i;
11518    END IF;
11519 END LOOP;
11520 
11521 l_out_retro_ptpn_kind.DELETE;
11522 
11523 END IF;
11524 
11525 END IF; -- New Hire check
11526 
11527 -- ==========================================================================
11528 -- BEGIN RETRO ORG AND ASG PARTICIPATION SECTION
11529 -- ==========================================================================
11530 IF l_copos_xst = 0 THEN
11531 
11532 IF l_hired = 0 AND l_kind_change_exists = 0 THEN
11533 
11534 FOR l_rec05_sub_cat IN c_rec05_sub_cat LOOP
11535 
11536 l_ge_retro_ptpn := Get_Retro_Participation
11537           (p_assignment_id        => p_assignment_id
11538           ,p_business_group_id    => p_business_group_id
11539           ,p_sub_cat              => l_rec05_sub_cat.sub_cat
11540           ,p_effective_date       => p_effective_date
11541           ,p_retro_ptpn           => l_out_retro_ptpn
11542           ,p_error_message        => p_error_message);
11543 IF l_out_retro_ptpn.COUNT > 0 THEN
11544 
11545 l_ret_index_05 := l_out_retro_ptpn.LAST;
11546 FOR w IN 1..l_ret_index_05 LOOP
11547    IF l_out_retro_ptpn.EXISTS(w) THEN
11548        g_rec05_rows(i).new_end        := NULL;
11549        g_rec05_rows(i).old_end        := NULL;
11550        g_rec05_rows(i).new_start      := NULL;
11551        g_rec05_rows(i).old_start      := NULL;
11552        g_rec05_rows(i).partn_kind     := NULL;
11553        g_rec05_rows(i).partn_value    := '   ';
11554        g_rec05_rows(i).part_time_perc := NULL;
11555 
11556        IF l_rec05_sub_cat.sub_cat LIKE 'PPP%' THEN
11557           g_rec05_rows(i).ppp_kind       := l_rec05_sub_cat.code;
11558           g_rec05_rows(i).fpu_kind       := ' ';
11559           g_rec05_rows(i).opnp_kind      := ' ';
11560        ELSIF l_rec05_sub_cat.sub_cat LIKE 'FPU%' THEN
11561           g_rec05_rows(i).ppp_kind       := ' ';
11562           g_rec05_rows(i).fpu_kind       := l_rec05_sub_cat.code;
11563           g_rec05_rows(i).opnp_kind      := ' ';
11564        ELSIF l_rec05_sub_cat.sub_cat LIKE 'OPNP%' THEN
11565           g_rec05_rows(i).ppp_kind       := ' ';
11566           g_rec05_rows(i).fpu_kind       := ' ';
11567           g_rec05_rows(i).opnp_kind      := l_rec05_sub_cat.code;
11568        END IF;
11569 
11570        g_rec05_rows(i).dt_chg         := fnd_date.date_to_canonical(l_out_retro_ptpn(w).start_date);
11571        IF fnd_date.date_to_canonical(TRUNC(l_out_retro_ptpn(w).end_date)) =
11572           '4712/12/31 00:00:00' THEN
11573         g_rec05_rows(i).eddt_chg := NULL;
11574 
11575        ELSE
11576 
11577         OPEN c_chk_ptpn_continues ( l_out_retro_ptpn(w).end_date
11578                                    ,l_out_retro_ptpn(w).ptid);
11579           FETCH c_chk_ptpn_continues INTO l_dummy;
11580              IF c_chk_ptpn_continues%NOTFOUND THEN
11581                 g_rec05_rows(i).eddt_chg := fnd_date.date_to_canonical(l_out_retro_ptpn(w).end_date);
11582              ELSE
11583                 g_rec05_rows(i).eddt_chg := NULL;
11584              END IF;
11585           CLOSE c_chk_ptpn_continues;
11586         END IF;
11587 
11588        g_rec05_rows(i).end_reason     := '';
11589 
11590        i := i + 1;
11591        g_count_05 := i;
11592    END IF;
11593 END LOOP;
11594 
11595 l_out_retro_ptpn.DELETE;
11596 
11597 END IF;
11598 
11599 END LOOP;
11600 
11601 END IF; -- New Hire check
11602 
11603 END IF;
11604 
11605 -- ==========================================================================
11606 -- END RETRO ORG AND ASG PARTICIPATION SECTION
11607 -- ==========================================================================
11608 
11609 -- ============================================================================
11610 -- BEGIN Section to add part time percentage change rows if there are changes
11611 -- in the month of hire
11612 -- ============================================================================
11613 IF l_copos_xst = 1 THEN
11614 l_hire_date := l_new_hire_dt;
11615 END IF;
11616 
11617 IF l_hired = 1 THEN
11618 
11619 l_prior_ptp := g_rec05_rows(l_new_hire_row).part_time_perc/100;
11620 
11621    FOR hire_ptp_rec IN c_hire_ptp_chg (p_assignment_id) LOOP
11622 
11623       IF hire_ptp_rec.start_date > l_hire_date THEN
11624          hr_utility.set_location('....Start Date > Hire Date  : ',24);
11625 
11626          IF hire_ptp_rec.ptp <> l_prior_ptp THEN
11627             hr_utility.set_location('....Inserting Rec 05 as PTP has changed : ',24);
11628             g_rec05_rows(i).partn_kind  := '   ';
11629             g_rec05_rows(i).partn_value := '   ';
11630             g_rec05_rows(i).end_reason  := ' ';
11631             g_rec05_rows(i).ppp_kind    := ' ';
11632             g_rec05_rows(i).opnp_kind   := ' ';
11633             g_rec05_rows(i).fpu_kind    := ' ';
11634             g_rec05_rows(i).old_start   := NULL;
11635             g_rec05_rows(i).old_end     := NULL;
11636             g_rec05_rows(i).new_start   := NULL;
11637             g_rec05_rows(i).new_end     := NULL;
11638             g_rec05_rows(i).dt_chg      := fnd_date.date_to_canonical
11639                                           (hire_ptp_rec.start_date);
11640             hr_utility.set_location('....Start Date is : '||hire_ptp_rec.start_date,24);
11641             hr_utility.set_location('....End Date is   : '||hire_ptp_rec.end_date,24);
11642 
11643             IF hire_ptp_rec.end_date >=
11644                trunc(g_extract_params(p_business_group_id).extract_end_date) THEN
11645                g_rec05_rows(i).eddt_chg    := NULL;
11646             ELSE
11647                g_rec05_rows(i).eddt_chg    := fnd_date.date_to_canonical
11648                                               (hire_ptp_rec.end_date);
11649             END IF;
11650 
11651             hr_utility.set_location('....PTP is : '||hire_ptp_rec.ptp,24);
11652             g_rec05_rows(i).part_time_perc := hire_ptp_rec.ptp * 100;
11653             i := i + 1;
11654             g_count_05 := i;
11655             l_ptp_row_ins := 1;
11656             hr_utility.set_location('....Value of i is : '||i,24);
11657             hr_utility.set_location('....Value of g_count_05 is : '||g_count_05,24);
11658 
11659          ELSIF hire_ptp_rec.ptp = l_prior_ptp AND l_ptp_row_ins = 1 THEN
11660             -- Assign the new end date to the prior row
11661             hr_utility.set_location('....Inside the IF condition to update the end date: ',24);
11662             hr_utility.set_location('....Ed Dt is : '||hire_ptp_rec.end_date,24);
11663 
11664             IF hire_ptp_rec.end_date >=
11665                trunc(g_extract_params(p_business_group_id).extract_end_date) THEN
11666                g_rec05_rows(i-1).eddt_chg := NULL;
11667             ELSE
11668                g_rec05_rows(i-1).eddt_chg := fnd_date.date_to_canonical
11669                                            (hire_ptp_rec.end_date);
11670             END IF;
11671 
11672          END IF;
11673 
11674       END IF;
11675       l_prior_ptp := hire_ptp_rec.ptp;
11676       hr_utility.set_location('....Value of l_prior_ptp is : '||l_prior_ptp,24);
11677 
11678    END LOOP;
11679 
11680 END IF; -- Check if the EE is a new hire
11681 -- ============================================================================
11682 -- END Section to add part time percentage change rows if there are changes
11683 -- in the month of hire
11684 -- ============================================================================
11685 
11686 END IF;
11687 
11688 IF g_count_05 > 0 THEN
11689 
11690    l_rec_05_disp := 'Y';
11691    Hr_Utility.set_location('----Old start date is         : '||g_rec05_rows(g_index_05).old_start,88);
11692    Hr_Utility.set_location('----New start date is         : '||g_rec05_rows(g_index_05).new_start,90);
11693    Hr_Utility.set_location('----Old end date is           : '||g_rec05_rows(g_index_05).old_end,92);
11694    Hr_Utility.set_location('----New end date is           : '||g_rec05_rows(g_index_05).new_end,94);
11695    Hr_Utility.set_location('----Kind of participation is  : '||g_rec05_rows(g_index_05).partn_kind,96);
11696    Hr_Utility.set_location('----Value of participation is : '||g_rec05_rows(g_index_05).partn_value,98);
11697    Hr_Utility.set_location('----Change start date is      : '||g_rec05_rows(g_index_05).dt_chg,100);
11698    Hr_Utility.set_location('----Change end date is        : '||g_rec05_rows(g_index_05).eddt_chg,102);
11699    Hr_Utility.set_location('----End reason is             : '||g_rec05_rows(g_index_05).end_reason,104);
11700    Hr_Utility.set_location('----Part Time Percent is      : '||g_rec05_rows(g_index_05).part_time_perc,106);
11701 
11702    l_return_value := 0;
11703 
11704    --
11705    -- Depending on the fetch code, set the data element value
11706    --
11707    IF p_fetch_code = 'NEW_ST' THEN
11708       p_data_element_value := g_rec05_rows(g_index_05).new_start;
11709       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11710                            (Fnd_Date.canonical_to_date(p_data_element_value),
11711                             'YYYYMMDD');
11712    ELSIF p_fetch_code = 'OLD_ST' THEN
11713       p_data_element_value := g_rec05_rows(g_index_05).old_start;
11714       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11715                            (Fnd_Date.canonical_to_date(p_data_element_value),
11716                             'YYYYMMDD');
11717    ELSIF p_fetch_code = 'NEW_ED' THEN
11718       IF g_rec05_rows(g_index_05).new_end IS NOT NULL THEN
11719          g_rec05_rows(g_index_05).new_end :=
11720          fnd_date.date_to_canonical(fnd_date.canonical_to_date(g_rec05_rows(g_index_05).new_end) + 1);
11721       END IF;
11722       p_data_element_value := g_rec05_rows(g_index_05).new_end;
11723       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11724                            (Fnd_Date.canonical_to_date(p_data_element_value),
11725                             'YYYYMMDD');
11726    ELSIF p_fetch_code = 'OLD_ED' THEN
11727       IF g_rec05_rows(g_index_05).old_end IS NOT NULL THEN
11728          g_rec05_rows(g_index_05).old_end :=
11729          fnd_date.date_to_canonical(fnd_date.canonical_to_date(g_rec05_rows(g_index_05).old_end) + 1);
11730       END IF;
11731       p_data_element_value := g_rec05_rows(g_index_05).old_end;
11732       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11733                            (Fnd_Date.canonical_to_date(p_data_element_value),
11734                             'YYYYMMDD');
11735    ELSIF p_fetch_code = 'P_KIND' THEN
11736          p_data_element_value := g_rec05_rows(g_index_05).partn_kind;
11737    ELSIF p_fetch_code = 'P_VALUE' THEN
11738       IF g_rec05_rows(g_index_05).partn_kind = 'WVP' THEN
11739          hr_utility.set_location('.... political leave',110);
11740          p_data_element_value := '0';
11741       ELSIF l_age >= 65 THEN
11742          hr_utility.set_location('....age => 65 ',110);
11743          IF g_rec05_rows(g_index_05).partn_value <> '   ' THEN
11744             p_data_element_value := '0';
11745          ELSE
11746             p_data_element_value := '   ';
11747          END IF;
11748       ELSE
11749          p_data_element_value := g_rec05_rows(g_index_05).partn_value;
11750          hr_utility.set_location('....age < 65 and not on political leave',112);
11751       END IF;
11752    ELSIF p_fetch_code = 'DT_CHG' THEN
11753       p_data_element_value := g_rec05_rows(g_index_05).dt_chg;
11754       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11755                            (Fnd_Date.canonical_to_date(p_data_element_value),
11756                             'YYYYMMDD');
11757     ELSIF p_fetch_code = 'EDDT_CHG' THEN
11758 
11759       IF g_rec05_rows(g_index_05).eddt_chg IS NOT NULL THEN
11760       IF fnd_date.canonical_to_date(g_rec05_rows(g_index_05).eddt_chg) >
11761          trunc(g_extract_params(p_business_group_id).extract_end_date) THEN
11762          g_rec05_rows(g_index_05).eddt_chg := NULL;
11763       END IF;
11764       END IF;
11765 
11766       IF g_rec05_rows(g_index_05).eddt_chg IS NOT NULL THEN
11767       g_rec05_rows(g_index_05).eddt_chg :=
11768          fnd_date.date_to_canonical(fnd_date.canonical_to_date(g_rec05_rows(g_index_05).eddt_chg) + 1);
11769       END IF;
11770       p_data_element_value := g_rec05_rows(g_index_05).eddt_chg;
11771       p_data_element_value := Ben_Ext_Fmt.apply_format_mask
11772                            (Fnd_Date.canonical_to_date(p_data_element_value),
11773                             'YYYYMMDD');
11774    ELSIF p_fetch_code = 'END_REASON' THEN
11775       p_data_element_value := g_rec05_rows(g_index_05).end_reason;
11776    ELSIF p_fetch_code = 'PPP_KIND' THEN
11777       IF (g_rec05_rows(g_index_05).new_start IS NOT NULL AND
11778             NVL(g_rec05_rows(g_index_05).ppp_kind,0) = 0) THEN
11779          p_data_element_value := ' ';
11780       ELSE
11781          p_data_element_value := g_rec05_rows(g_index_05).ppp_kind;
11782       END IF;
11783    ELSIF p_fetch_code = 'FPU_KIND' THEN
11784          p_data_element_value := g_rec05_rows(g_index_05).fpu_kind;
11785    ELSIF p_fetch_code = 'OPNP_KIND' THEN
11786          p_data_element_value := g_rec05_rows(g_index_05).opnp_kind;
11787    ELSIF p_fetch_code = 'PART_TIME_PERC' THEN
11788       IF g_rec05_rows(g_index_05).part_time_perc IS NULL THEN
11789          p_data_element_value := '     ';
11790       ELSE
11791          p_data_element_value := fnd_number.number_to_canonical
11792                               (g_rec05_rows(g_index_05).part_time_perc);
11793       END IF;
11794    END IF;
11795 
11796 ELSE
11797    p_data_element_value := '';
11798    l_rec_05_disp := 'N';
11799    l_return_value := 0;
11800 END IF;
11801 
11802 Hr_Utility.set_location('....Final value of p_data_element_value is : '||p_data_element_value, 114);
11803 Hr_Utility.set_location('Leaving:   '||l_proc_name, 116);
11804 Hr_Utility.set_location(' ', 118);
11805 l_return_value :=0;
11806 
11807 RETURN l_return_value;
11808 EXCEPTION
11809    WHEN Others THEN
11810     p_error_message :='SQL-ERRM :'||SQLERRM;
11811     Hr_Utility.set_location('..'||p_error_message,85);
11812     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
11813     RETURN l_return_value;
11814 END Get_Rec05_Participation;
11815 
11816 --============================================================================
11817 --This is used to derive the participation start and end dates and the old start and
11818 --end dates in case of an update for IPAP Pensions
11819 --============================================================================
11820 FUNCTION Get_Ipap_Participation_Dates
11821           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
11822            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
11823            ,p_fetch_code           IN  Varchar2
11824            ,p_effective_date       IN  Date
11825            ,p_error_message        OUT NOCOPY Varchar2
11826 	   ,p_data_element_value   OUT NOCOPY Varchar2
11827           ) RETURN Number IS
11828 
11829 --cursor to check if ASG EIT rows exist
11830 CURSOR c_asg_rows_exist IS
11831 SELECT 1
11832   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
11833 WHERE  chg_evt_cd = 'COAPPD'
11834   AND  prmtr_01 = 'ASG'
11835   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
11836   AND  pty.pension_sub_category = 'IPAP'
11837   AND  prmtr_03 = 'Y'
11838   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
11839   AND  person_id = (SELECT person_id
11840                       FROM per_all_assignments_f
11841                     WHERE  assignment_id = p_assignment_id
11842                       AND  p_effective_date BETWEEN effective_start_date
11843                       AND  effective_end_date
11844                    )
11845   AND  bec.business_group_id = p_business_group_id;
11846 
11847 --cursor to check if ORG EIT rows exist
11848 CURSOR c_org_rows_exist(c_org_id IN Number) IS
11849 SELECT 1
11850   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
11851 WHERE  chg_evt_cd = 'COAPPD'
11852   AND  prmtr_01 = 'ORG'
11853   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
11854   AND  pty.pension_sub_category = 'IPAP'
11855   AND  prmtr_03 = 'Y'
11856   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
11857   AND  bec.business_group_id = p_business_group_id;
11858 
11859 --cursor to get the old and new start and end dates from the ASG EIT
11860 CURSOR c_get_asg_rows IS
11861 SELECT old_val1,new_val1,old_val2,new_val2
11862   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
11863 WHERE  chg_evt_cd = 'COAPPD'
11864   AND  prmtr_01 = 'ASG'
11865   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
11866   AND  prmtr_03 = 'Y'
11867   AND  Fnd_Number.canonical_to_number(prmtr_10) = p_assignment_id
11868   AND  pty.pension_sub_category = 'IPAP'
11869   AND  person_id = (SELECT person_id
11870                       FROM per_all_assignments_f
11871                     WHERE  assignment_id = p_assignment_id
11872                       AND  p_effective_date BETWEEN effective_start_date
11873                       AND  effective_end_date
11874                    )
11875   AND  bec.business_group_id = p_business_group_id
11876   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
11877   AND  g_extract_params(p_business_group_id).extract_end_date
11878 ORDER BY ext_chg_evt_log_id;
11879 
11880 --cursor to get the old and new start and end dates from the  ORG EIT
11881 CURSOR c_get_org_rows(c_org_id IN Number,c_hire_date IN Date) IS
11882 SELECT old_val1,new_val1,old_val2,new_val2
11883   FROM ben_ext_chg_evt_log bec,pqp_pension_types_f pty
11884 WHERE  chg_evt_cd = 'COAPPD'
11885   AND  prmtr_01 = 'ORG'
11886   AND  Fnd_Number.canonical_to_number(prmtr_02) = pty.pension_type_id
11887   AND  prmtr_03 = 'Y'
11888   AND  pty.pension_sub_category = 'IPAP'
11889   AND  Fnd_Number.canonical_to_number(prmtr_04) = c_org_id
11890   AND  bec.business_group_id = p_business_group_id
11891   AND  chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
11892   AND  g_extract_params(p_business_group_id).extract_end_date
11893   AND  chg_eff_dt >= c_hire_date
11894 ORDER BY ext_chg_evt_log_id;
11895 
11896 --Cursor to find the named hierarchy associated with the BG
11897 CURSOR c_find_named_hierarchy IS
11898 SELECT org_information1
11899  FROM hr_organization_information
11900 WHERE organization_id = p_business_group_id
11901  AND org_information_context = 'NL_BG_INFO';
11902 
11903 --Cursor to find the valid version id for the particular named hierarchy
11904 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id IN Number) IS
11905 SELECT ORG_STRUCTURE_VERSION_ID
11906   FROM per_org_structure_versions_v
11907 WHERE organization_structure_id = c_hierarchy_id
11908   AND p_effective_date BETWEEN date_from
11909   AND Nvl(date_to,Hr_Api.g_eot);
11910 
11911 --Cursor to find the valid version id for a particular business group
11912 CURSOR c_find_ver_frm_bg IS
11913 SELECT ORG_STRUCTURE_VERSION_ID
11914   FROM per_org_structure_versions_v
11915 WHERE business_group_id = p_business_group_id
11916   AND p_effective_date BETWEEN date_from
11917   AND Nvl( date_to,Hr_Api.g_eot);
11918 
11919 --Cursor to find the parent id from the org id
11920 CURSOR c_find_parent_id(c_org_id IN Number
11921                        ,c_version_id IN Number) IS
11922 SELECT organization_id_parent
11923   FROM per_org_structure_elements
11924   WHERE organization_id_child = c_org_id
11925     AND org_structure_version_id = c_version_id
11926     AND business_group_id = p_business_group_id;
11927 
11928 --cursor to find the org id for the current asg
11929 CURSOR c_find_org_id IS
11930 SELECT organization_id
11931   FROM per_all_assignments_f
11932 WHERE  assignment_id = p_assignment_id
11933   AND  p_effective_date BETWEEN effective_start_date
11934   AND  effective_end_date;
11935 
11936 -- Cursor to get the hire date of the person
11937 CURSOR c_hire_dt IS
11938 SELECT max(date_start)
11939  FROM  per_all_assignments_f asg
11940       ,per_periods_of_service pps
11941  WHERE pps.person_id     = asg.person_id
11942    AND asg.assignment_id = p_assignment_id
11943    AND pps.business_group_id = p_business_group_id
11944    AND date_start <= p_effective_date;
11945 
11946 --cursor to check if run results exist for any IPAP Pension Types for this assignment
11947 CURSOR c_run_results_exist IS
11948 SELECT pty.pension_type_id
11949 FROM   pay_run_results prr,
11950        pay_payroll_actions ppa,
11951        pay_assignment_actions paa,
11952        pay_element_type_extra_info pei,
11953        pqp_pension_types_f pty
11954 WHERE  paa.assignment_action_id = prr.assignment_action_id
11955   AND  paa.payroll_action_id = ppa.payroll_action_id
11956   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
11957   AND  g_extract_params(p_business_group_id).extract_end_date
11958   AND  paa.assignment_id = p_assignment_id
11959   AND  pei.element_type_id = prr.element_type_id
11960   AND  pei.information_type = 'PQP_NL_ABP_DEDUCTION'
11961   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
11962   AND  pei.eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
11963   AND  pty.pension_sub_category = 'IPAP';
11964 
11965 l_proc_name       Varchar2(150) := g_proc_name ||'get_ipap_participation_dates';
11966 l_return_value    Number := -1;
11967 l_named_hierarchy       Number;
11968 l_version_id            per_org_structure_versions_v.org_structure_version_id%TYPE  DEFAULT NULL;
11969 l_asg_rows_exist   Number;
11970 l_org_rows_exist   Number;
11971 l_org_id           Number;
11972 i                  Number  := 0;
11973 l_loop_again       Number;
11974 l_hire_date        Date;
11975 l_hired            Number := 0;
11976 l_ret_val          Number;
11977 l_end_date         Date;
11978 
11979 
11980 BEGIN
11981    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
11982    --check the index and the code and calculate the value accordingly
11983    Hr_Utility.set_location('value of g_index : '||g_index_ipap,7);
11984    Hr_Utility.set_location('value of fetch code : '||p_fetch_code ,10);
11985    IF g_index_ipap = 0 AND p_fetch_code = 'NEW_ST' THEN
11986       g_count_ipap := 0;
11987 
11988       OPEN c_hire_dt;
11989       FETCH c_hire_dt INTO l_hire_date;
11990       CLOSE c_hire_dt;
11991       IF l_hire_date BETWEEN g_extract_params(p_business_group_id).extract_start_date
11992         AND g_extract_params(p_business_group_id).extract_end_date THEN
11993          l_hired := 1;
11994       END IF;
11995 
11996       OPEN c_asg_rows_exist;
11997       FETCH c_asg_rows_exist INTO l_asg_rows_exist;
11998       IF c_asg_rows_exist%FOUND THEN
11999          CLOSE c_asg_rows_exist;
12000          Hr_Utility.set_location('found rows at the assignment eit level',15);
12001          --now fetch the rows from the log table
12002          FOR asg_rec IN c_get_asg_rows
12003          LOOP
12004             IF asg_rec.old_val1 IS NOT NULL THEN
12005                IF asg_rec.old_val1 <> asg_rec.new_val1 THEN
12006                   g_ipap_dates(i).old_start := asg_rec.old_val1;
12007                   g_ipap_dates(i).new_start := asg_rec.new_val1;
12008                ELSE
12009                   g_ipap_dates(i).old_start := '';
12010                   g_ipap_dates(i).new_start := asg_rec.new_val1;
12011                END IF;
12012             ELSIF asg_rec.new_val1 IS NOT NULL THEN
12013                g_ipap_dates(i).old_start := '';
12014                g_ipap_dates(i).new_start := asg_rec.new_val1;
12015             ELSE
12016                g_ipap_dates(i).old_start := '';
12017                g_ipap_dates(i).new_start := '';
12018             END IF;
12019             IF asg_rec.old_val2 IS NOT NULL THEN
12020                IF asg_rec.old_val2 <> asg_rec.new_val2 THEN
12021                   g_ipap_dates(i).old_end := asg_rec.old_val2;
12022                   g_ipap_dates(i).new_end  := asg_rec.new_val2;
12023                ELSE
12024                   g_ipap_dates(i).old_end := '';
12025                   g_ipap_dates(i).new_end  := asg_rec.new_val2;
12026                END IF;
12027             ELSIF asg_rec.new_val2 IS NOT NULL THEN
12028                g_ipap_dates(i).old_end := '';
12029                g_ipap_dates(i).new_end := asg_rec.new_val2;
12030             ELSE
12031                g_ipap_dates(i).old_end := '';
12032                g_ipap_dates(i).new_end := '';
12033             END IF;
12034             i := i + 1;
12035          END LOOP;
12036          g_count_ipap := i;
12037          Hr_Utility.set_location('count of rows : '||g_count_ipap,20);
12038       ELSE
12039       CLOSE c_asg_rows_exist;
12040       --go up the org hierarchy to find the rows at some org eit level
12041       -- find the org the assignment is attached to
12042       OPEN c_find_org_id;
12043       FETCH c_find_org_id INTO l_org_id;
12044       CLOSE c_find_org_id;
12045 
12046       --first chk to see if a named hierarchy exists for the BG
12047       OPEN c_find_named_hierarchy;
12048       FETCH c_find_named_hierarchy INTO l_named_hierarchy;
12049       -- if a named hiearchy is found , find the valid version on that date
12050       IF c_find_named_hierarchy%FOUND THEN
12051          CLOSE c_find_named_hierarchy;
12052          -- now find the valid version on that date
12053          OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
12054          FETCH c_find_ver_frm_hierarchy INTO l_version_id;
12055          --if no valid version is found, try to get it frm the BG
12056          IF c_find_ver_frm_hierarchy%NOTFOUND THEN
12057             CLOSE c_find_ver_frm_hierarchy;
12058             -- find the valid version id from the BG
12059             OPEN c_find_ver_frm_bg;
12060             FETCH c_find_ver_frm_bg INTO l_version_id;
12061             CLOSE c_find_ver_frm_bg;
12062          -- else a valid version has been found for the named hierarchy
12063          ELSE
12064             CLOSE c_find_ver_frm_hierarchy;
12065          END IF; --end of if no valid version found
12066       -- else find the valid version from BG
12067       ELSE
12068          CLOSE c_find_named_hierarchy;
12069          --now find the version number from the BG
12070          OPEN c_find_ver_frm_bg;
12071          FETCH c_find_ver_frm_bg INTO l_version_id;
12072          CLOSE c_find_ver_frm_bg;
12073       END IF; -- end of if named hierarchy found
12074 
12075       -- loop through the org hierarchy to find the participation start date at
12076       -- this org level or its parents
12077       l_loop_again := 1;
12078       WHILE (l_loop_again = 1)
12079 
12080       LOOP
12081       Hr_Utility.set_location('searching at org level : '||l_org_id,25);
12082       OPEN c_org_rows_exist(l_org_id);
12083       FETCH c_org_rows_exist INTO l_org_rows_exist;
12084       IF c_org_rows_exist%FOUND THEN
12085          CLOSE c_org_rows_exist;
12086          FOR org_rec IN c_get_org_rows(l_org_id,l_hire_date)
12087          LOOP
12088            IF org_rec.old_val1 IS NOT NULL THEN
12089               IF org_rec.old_val1 <> org_rec.new_val1 THEN
12090                  g_ipap_dates(i).old_start := org_rec.old_val1;
12091                  g_ipap_dates(i).new_start := org_rec.new_val1;
12092               ELSE
12093                  g_ipap_dates(i).old_start := '';
12094                  g_ipap_dates(i).new_start := org_rec.new_val1;
12095               END IF;
12096            ELSIF org_rec.new_val1 IS NOT NULL THEN
12097               g_ipap_dates(i).old_start := '';
12098               g_ipap_dates(i).new_start := org_rec.new_val1;
12099            ELSE
12100               g_ipap_dates(i).old_start := '';
12101               g_ipap_dates(i).new_start := '';
12102            END IF;
12103            IF org_rec.old_val2 IS NOT NULL THEN
12104               IF org_rec.old_val2 <> org_rec.new_val2 THEN
12105                  g_ipap_dates(i).old_end := org_rec.old_val2;
12106                  g_ipap_dates(i).new_end := org_rec.new_val2;
12107               ELSE
12108                  g_ipap_dates(i).old_end := '';
12109                  g_ipap_dates(i).new_end := org_rec.new_val2;
12110               END IF;
12111            ELSIF org_rec.new_val2 IS NOT NULL THEN
12112               g_ipap_dates(i).old_end := '';
12113               g_ipap_dates(i).new_end := org_rec.new_val2;
12114            ELSE
12115               g_ipap_dates(i).old_end := '';
12116               g_ipap_dates(i).new_end := '';
12117            END IF;
12118            IF l_hired = 1 THEN
12119              Hr_Utility.set_location('hire date : '||l_hire_date,99);
12120              Hr_Utility.set_location('new date : '||g_ipap_dates(i).new_start,100);
12121              Hr_Utility.set_location('greater date : '||Fnd_Date.date_to_canonical(Greatest(
12122                                               l_hire_date,Fnd_Date.canonical_to_date(g_ipap_dates(i).new_start))),101);
12123               IF g_ipap_dates(i).new_start IS NOT NULL THEN
12124                 Hr_Utility.set_location('chking the new start date',102);
12125                  g_ipap_dates(i).new_start := Fnd_Date.date_to_canonical(Greatest(
12126                                              l_hire_date,Fnd_Date.canonical_to_date(g_ipap_dates(i).new_start)));
12127                 Hr_Utility.set_location('new start date is : '||g_ipap_dates(i).new_start,103);
12128               END IF;
12129               IF g_ipap_dates(i).old_start IS NOT NULL THEN
12130                  g_ipap_dates(i).old_start := Fnd_Date.date_to_canonical(Greatest(
12131                                               l_hire_date,Fnd_Date.canonical_to_date(g_ipap_dates(i).old_start)));
12132               END IF;
12133            END IF;
12134            IF g_ipap_dates(i).new_start = g_ipap_dates(i).old_start THEN
12135               g_ipap_dates(i).old_start := '';
12136            END IF;
12137 
12138            i := i + 1;
12139          END LOOP;
12140          g_count_ipap := i;
12141          Hr_Utility.set_location('value for g count : '||g_count_ipap,30);
12142          l_loop_again := 0;
12143       ELSE
12144          --search at the parent level next
12145          CLOSE c_org_rows_exist;
12146          OPEN c_find_parent_id(l_org_id,l_version_id);
12147          FETCH c_find_parent_id INTO l_org_id;
12148          IF c_find_parent_id%NOTFOUND THEN
12149             l_loop_again := 0;
12150             CLOSE c_find_parent_id;
12151          ELSE
12152             CLOSE c_find_parent_id;
12153          END IF;
12154       END IF;
12155      END LOOP;
12156    END IF;
12157 --if no changes have occured,check if participation has occured due to employement start
12158 --if so , fire a row for record 30
12159 IF g_count_ipap = 0 THEN
12160    i := 0;
12161    IF l_hired = 1 THEN
12162       --chk if there is any run result
12163       FOR c_rec IN c_run_results_exist
12164       LOOP
12165         g_ipap_dates(i).new_start := Fnd_Date.date_to_canonical(l_hire_date);
12166         g_ipap_dates(i).old_start := '';
12167         --get the end date corresponding to this enrollment
12168         l_ret_val := Get_Participation_End
12169                      (p_assignment_id => p_assignment_id
12170                      ,p_business_group_id => p_business_group_id
12171                      ,p_pension_type_id   => c_rec.pension_type_id
12172                      ,p_date_earned       => p_effective_date
12173                      ,p_end_date          => l_end_date
12174                      );
12175         IF l_ret_val = 0 THEN
12176            IF l_end_date = hr_api.g_eot THEN
12177               g_ipap_dates(i).new_end := '';
12178            ELSE
12179               g_ipap_dates(i).new_end := Fnd_Date.date_to_canonical(l_end_date) ;
12180            END IF;
12181         ELSE
12182            g_ipap_dates(i).new_end := '';
12183         END IF;
12184         g_ipap_dates(i).old_end := '';
12185         i := i+1;
12186        END LOOP;
12187        g_count_ipap := i;
12188   END IF;
12189 END IF;
12190 END IF;
12191 
12192 IF g_count_ipap > 0 THEN
12193    Hr_Utility.set_location('old st date : '||g_ipap_dates(g_index_ipap).old_start,40);
12194    Hr_Utility.set_location('new st date : '||g_ipap_dates(g_index_ipap).new_start,45);
12195    Hr_Utility.set_location('old ed date : '||g_ipap_dates(g_index_ipap).old_end,50);
12196    Hr_Utility.set_location('new ed date : '||g_ipap_dates(g_index_ipap).new_end,55);
12197    l_return_value := 0;
12198    --depending on the fetch code ,set the data element value
12199    IF p_fetch_code = 'NEW_ST' THEN
12200       p_data_element_value := g_ipap_dates(g_index_ipap).new_start;
12201    ELSIF p_fetch_code = 'OLD_ST' THEN
12202       p_data_element_value := g_ipap_dates(g_index_ipap).old_start;
12203    ELSIF p_fetch_code = 'NEW_ED' THEN
12204       p_data_element_value := g_ipap_dates(g_index_ipap).new_end;
12205    ELSIF p_fetch_code = 'OLD_ED' THEN
12206       p_data_element_value := g_ipap_dates(g_index_ipap).old_end;
12207    END IF;
12208 
12209 --   p_data_element_value := substr(p_data_element_value,1,10);
12210    p_data_element_value := Ben_Ext_Fmt.apply_format_mask
12211                            (Fnd_Date.canonical_to_date(p_data_element_value),
12212                             'YYYYMMDD');
12213 
12214 ELSE
12215    p_data_element_value := '';
12216    l_return_value := 1;
12217 END IF;
12218 
12219 Hr_Utility.set_location('p_data_element_value:   '||p_data_element_value, 70);
12220 Hr_Utility.set_location('Leaving:   '||l_proc_name, 80);
12221 
12222 l_return_value :=0;
12223 RETURN l_return_value;
12224 EXCEPTION
12225    WHEN Others THEN
12226     p_error_message :='SQL-ERRM :'||SQLERRM;
12227     Hr_Utility.set_location('..'||p_error_message,85);
12228     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
12229     RETURN l_return_value;
12230 END get_ipap_participation_dates;
12231 
12232 -- =============================================================================
12233 -- Chk_If_Req_ToExtract: For a given assignment check to see the record needs to
12234 -- be extracted or not.
12235 -- =============================================================================
12236 FUNCTION Chk_If_Req_ToExtract
12237           (p_assignment_id     IN Number
12238           ,p_business_group_id IN Number
12239           ,p_person_id         IN Number
12240           ,p_effective_date    IN Date
12241           ,p_record_num        IN Varchar2
12242           ,p_error_message     OUT NOCOPY Varchar2) RETURN Varchar2 IS
12243 
12244    l_proc_name          Varchar2(150) := g_proc_name ||'Chk_If_Req_ToExtract';
12245    l_return_value       Number :=0;
12246    l_data_element_value Varchar2(2);
12247 
12248 BEGIN
12249    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
12250    Hr_Utility.set_location('..p_record_num : '||p_record_num , 6);
12251    IF p_record_num = '01' THEN
12252      l_return_value := Record01_Display_Criteria
12253                        (p_assignment_id      => p_assignment_id
12254                        ,p_business_group_id  => p_business_group_id
12255                        ,p_effective_date     => p_effective_date
12256                        ,p_error_message      => p_error_message
12257                        ,p_data_element_value => l_data_element_value
12258                         );
12259    ELSIF p_record_num = '02' THEN
12260      l_return_value := Record02_Display_Criteria
12261                         (p_assignment_id      => p_assignment_id
12262                		    ,p_business_group_id  => p_business_group_id
12263                		    ,p_effective_date     => p_effective_date
12264                		    ,p_error_message      => p_error_message
12265                		    ,p_data_element_value => l_data_element_value
12266                         );
12267    ELSIF p_record_num = '04' THEN
12268      l_return_value :=  Record04_Display_Criteria
12269                         (p_assignment_id      => p_assignment_id
12270                		    ,p_business_group_id  => p_business_group_id
12271                		    ,p_effective_date     => p_effective_date
12272                		    ,p_error_message      => p_error_message
12273                		    ,p_data_element_value => l_data_element_value
12274                         );
12275    ELSIF p_record_num = '05' THEN
12276      l_return_value :=  Record05_Display_Criteria
12277                         (p_assignment_id      => p_assignment_id
12278                		    ,p_business_group_id  => p_business_group_id
12279                		    ,p_effective_date     => p_effective_date
12280                		    ,p_error_message      => p_error_message
12281                		    ,p_data_element_value => l_data_element_value
12282                         );
12283 
12284    ELSIF p_record_num = '08' THEN
12285      l_return_value :=  Record08_Display_Criteria
12286                         (p_assignment_id      => p_assignment_id
12287                		    ,p_business_group_id  => p_business_group_id
12288                		    ,p_effective_date     => p_effective_date
12289                		    ,p_error_message      => p_error_message
12290                		    ,p_data_element_value => l_data_element_value
12291                         );
12292 
12293    ELSIF p_record_num = '30' THEN
12294           l_return_value := Record30_40_Display_Criteria(p_assignment_id
12295 			    ,p_business_group_id
12296 			    ,p_effective_date
12297                            ,'IPAP'
12298 			    ,p_error_message
12299 			    ,l_data_element_value);
12300 
12301   ELSIF p_record_num = '31' THEN
12302           l_return_value := Record31_41_Display_Criteria(p_assignment_id
12303 			    ,p_business_group_id
12304 			    ,p_effective_date
12305                             ,31
12306 			    ,p_error_message
12307 			    ,l_data_element_value);
12308 
12309    ELSIF p_record_num = '40' THEN
12310           l_return_value := Record30_40_Display_Criteria
12311                             (p_assignment_id
12312 			    ,p_business_group_id
12313 			    ,p_effective_date
12314                             ,'FUR_S'
12315 			    ,p_error_message
12316 			    ,l_data_element_value);
12317 
12318   ELSIF p_record_num = '41' THEN
12319           l_return_value := Record31_41_Display_Criteria(p_assignment_id
12320 			    ,p_business_group_id
12321 			    ,p_effective_date
12322                              ,41
12323 			    ,p_error_message
12324 			    ,l_data_element_value);
12325    ELSIF p_record_num = '21' THEN
12326      l_return_value :=  Record21_Display_Criteria
12327                         (p_assignment_id      => p_assignment_id
12328                		    ,p_business_group_id  => p_business_group_id
12329                		    ,p_effective_date     => p_effective_date
12330                		    ,p_error_message      => p_error_message
12331                		    ,p_data_element_value => l_data_element_value
12332                         );
12333   ELSIF p_record_num = '09' THEN
12334      l_return_value :=  Record09_Display_Criteria
12335                         (p_assignment_id      => p_assignment_id
12336                		    ,p_business_group_id  => p_business_group_id
12337                		    ,p_effective_date     => p_effective_date
12338                		    ,p_error_message      => p_error_message
12339                		    ,p_data_element_value => l_data_element_value
12340                         );
12341   ELSIF p_record_num = '12' THEN
12342      l_return_value :=  Record12_Display_Criteria
12343                         (p_assignment_id      => p_assignment_id
12344                		    ,p_business_group_id  => p_business_group_id
12345                		    ,p_effective_date     => p_effective_date
12346                		    ,p_error_message      => p_error_message
12347                		    ,p_data_element_value => l_data_element_value
12348                         );
12349   ELSIF p_record_num = '20' THEN
12350      l_return_value :=  Record20_Display_Criteria
12351                         (p_assignment_id      => p_assignment_id
12352                		    ,p_business_group_id  => p_business_group_id
12353                		    ,p_effective_date     => p_effective_date
12354                		    ,p_error_message      => p_error_message
12355                		    ,p_data_element_value => l_data_element_value
12356                         );
12357   ELSIF p_record_num = '22' THEN
12358      l_return_value :=  Record22_Display_Criteria
12359                         (p_assignment_id      => p_assignment_id
12360                		    ,p_business_group_id  => p_business_group_id
12361                		    ,p_effective_date     => p_effective_date
12362                		    ,p_error_message      => p_error_message
12363                		    ,p_data_element_value => l_data_element_value
12364                         );
12365   ELSIF p_record_num = '41h' THEN
12366      l_data_element_value := 'Y';
12367 
12368    ELSE
12369      l_data_element_value := 'N';
12370    END IF;
12371    Hr_Utility.set_location('..l_data_element_value: '||l_data_element_value,45);
12372    Hr_Utility.set_location('Leaving: '||l_proc_name, 50);
12373    RETURN l_data_element_value;
12374 EXCEPTION
12375    WHEN Others THEN
12376     p_error_message :='SQL-ERRM :'||SQLERRM;
12377     Hr_Utility.set_location('..'||p_error_message,85);
12378     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
12379     RETURN l_return_value;
12380 
12381 END Chk_If_Req_ToExtract;
12382 
12383 --============================================================================
12384 --This is used to check if there are any more rows for Record 05 and insert
12385 --those records forcibly
12386 --============================================================================
12387 FUNCTION Process_Mult_Rec05
12388            (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
12389            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
12390            ,p_effective_date       IN  Date
12391            ,p_error_message        OUT NOCOPY Varchar2
12392            ,p_data_element_value   OUT NOCOPY Varchar2
12393           ) RETURN Number IS
12394 
12395 l_main_rec         csr_rslt_dtl%ROWTYPE;
12396 l_new_rec          csr_rslt_dtl%ROWTYPE;
12397 l_return_value     Number := 1;
12398 l_rcd_id           Number;
12399 l_mutli_assig      Varchar2(50);
12400 l_asg_type         per_all_assignments_f.assignment_type%TYPE;
12401 l_person_id        per_all_people_f.person_id%TYPE;
12402 l_assignment_id    per_all_assignments_f.assignment_id%TYPE;
12403 l_effective_date   Date;
12404 
12405 BEGIN
12406    --fetch the record id from the sequence number
12407    OPEN c_get_rcd_id(5);
12408    FETCH c_get_rcd_id INTO l_rcd_id;
12409    CLOSE c_get_rcd_id;
12410 
12411    --first fetch the data from the result detail record
12412    OPEN csr_rslt_dtl(c_person_id  =>  g_person_id
12413                     ,c_ext_rslt_id => Ben_Ext_Thread.g_ext_rslt_id
12414                     ,c_ext_dtl_rcd_id => l_rcd_id
12415                     );
12416 
12417    FETCH csr_rslt_dtl INTO l_main_rec;
12418    CLOSE csr_rslt_dtl;
12419 
12420    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
12421    l_new_rec := l_main_rec;
12422 
12423    --This is multiple categories process for first Assignment
12424   WHILE(g_index_05 < g_count_05)
12425    LOOP
12426       IF g_index_05 <> 0 THEN
12427          Process_Ext_Rslt_Dtl_Rec
12428          (p_assignment_id => p_assignment_id
12429          ,p_organization_id => NULL
12430          ,p_effective_date => p_effective_date
12431          ,p_ext_dtl_rcd_id => l_rcd_id
12432          ,p_rslt_rec       => l_main_rec
12433          ,p_asgaction_no   => NULL
12434          ,p_error_message => p_error_message
12435          );
12436       END IF;
12437       g_index_05 := g_index_05 + 1;
12438    END LOOP;
12439    g_index_05 := 0;
12440    g_count_05 := 0;
12441    p_data_element_value := '';
12442    l_rec_05_disp := 'N';
12443    l_return_value := 0;
12444 
12445    RETURN l_return_value;
12446 
12447 EXCEPTION
12448    WHEN Others THEN
12449     p_error_message :='SQL-ERRM :'||SQLERRM;
12450     Hr_Utility.set_location('..'||p_error_message,85);
12451     RETURN l_return_value;
12452 END Process_Mult_Rec05;
12453 
12454 --=============================================================================
12455 -- Process Multiple Record 08. This is necessary for late hires
12456 -- and for change in hire date to the past (ABP Certification only test case).
12457 --=============================================================================
12458 FUNCTION Process_Mult_Rec08
12459 (  p_assignment_id        IN per_all_assignments_f.assignment_id%TYPE
12460   ,p_business_group_id    IN per_all_assignments_f.business_group_id%TYPE
12461   ,p_effective_date       IN  DATE
12462   ,p_error_message        OUT NOCOPY VARCHAR2
12463   ,p_data_element_value   OUT NOCOPY VARCHAR2
12464 ) RETURN  NUMBER IS
12465 
12466 CURSOR c_hire_dt_chg(c_person_id  IN NUMBER
12467                     ,c_start_date IN DATE
12468                     ,c_end_date   IN DATE) IS
12469 SELECT old_val1 old_date,
12470        new_val1 new_date
12471   FROM ben_ext_chg_evt_log
12472  WHERE person_id = c_person_id
12473    AND chg_evt_cd = 'COPOS'
12474    AND fnd_date.canonical_to_date(prmtr_09) BETWEEN c_start_date AND c_end_date
12475 ORDER BY ext_chg_evt_log_id desc;
12476 
12477 CURSOR or_pen_sal ( c_nh_date IN DATE) IS
12478 SELECT 1
12479   FROM per_assignment_extra_info
12480  WHERE assignment_id = p_assignment_id
12481    AND aei_information_category = 'NL_ABP_PAR_INFO'
12482    AND information_type = 'NL_ABP_PAR_INFO'
12483    AND trunc(c_nh_date) BETWEEN fnd_date.canonical_to_date(aei_information1)
12484                             AND fnd_date.canonical_to_date(nvl(aei_information2,
12485        fnd_date.date_to_canonical(hr_api.g_eot)))
12486   AND  aei_information6 IS NOT NULL;
12487 
12488 CURSOR c_get_override_salary (c_start IN DATE, c_end IN DATE) IS
12489 SELECT fnd_number.canonical_to_number(nvl(new_val1,'0'))
12490        ,fnd_date.canonical_to_date(prmtr_02)
12491   FROM ben_ext_chg_evt_log
12492  WHERE person_id = g_person_id
12493    AND fnd_number.canonical_to_number(prmtr_01) = p_assignment_id
12494    AND chg_eff_dt BETWEEN g_extract_params(p_business_group_id).extract_start_date
12495                       AND g_extract_params(p_business_group_id).extract_end_date
12496    AND chg_evt_cd = 'COAPS'
12497    AND fnd_number.canonical_to_number(nvl(new_val1,'0')) <> 0
12498    AND fnd_date.canonical_to_date(prmtr_02) BETWEEN c_start and c_end;
12499 
12500 l_ret_val          NUMBER := 0;
12501 l_proc_name        VARCHAR2(150) := g_proc_name ||'Process_Mult_Rec08';
12502 l_rcd_id           NUMBER;
12503 l_index            NUMBER;
12504 l_old_hire_dt      DATE;
12505 l_new_hire_dt      DATE;
12506 l_or_pen_sal       NUMBER;
12507 l_ext_rslt_dtl_id  NUMBER;
12508 l_main_rec         csr_rslt_dtl%ROWTYPE;
12509 l_new_rec          csr_rslt_dtl%ROWTYPE;
12510 l_old_date_can     ben_ext_chg_evt_log.old_val1%TYPE;
12511 l_new_date_can     ben_ext_chg_evt_log.new_val1%TYPE;
12512 l_asg_action_id    pay_assignment_actions.assignment_action_id%TYPE;
12513 l_pension_sal_char VARCHAR2(15);
12514 l_pension_yr_char  VARCHAR2(15);
12515 l_get_ps_val       NUMBER;
12516 l_get_yr_val       NUMBER;
12517 l_max_de           DATE;
12518 l_de_asg_act       NUMBER;
12519 l_start_de         DATE;
12520 l_end_de           DATE;
12521 l_lh_or_pen_sal    NUMBER;
12522 l_lh_or_date       DATE;
12523 l_override_lh      BOOLEAN;
12524 l_ret_val_asg      NUMBER;
12525 l_seq_num          VARCHAR2(2);
12526 
12527 BEGIN
12528 
12529 Hr_Utility.set_location(' Entering     ' || l_proc_name , 10);
12530 --
12531 -- Create Record 08 for an EE assignment if the assignment
12532 -- is a late hire across years. For e.g. hired in 2006 but
12533 -- the first payroll is processed in 2007
12534 --
12535 
12536 IF Chk_Asg_Late_Hire (p_assignment_id     => p_assignment_id
12537                      ,p_business_group_id => p_business_group_id) THEN
12538    --
12539    -- EE assignment is a late hire. Insert a record 08 for the prev year.
12540    --
12541 
12542    OPEN c_get_rcd_id(7);
12543    FETCH c_get_rcd_id INTO l_rcd_id;
12544    CLOSE c_get_rcd_id;
12545 
12546    OPEN csr_rslt_dtl(c_person_id      => g_person_id
12547                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
12548                     ,c_ext_dtl_rcd_id => l_rcd_id);
12549    FETCH csr_rslt_dtl INTO l_main_rec;
12550    CLOSE csr_rslt_dtl;
12551 
12552    l_start_de := TO_DATE('01/01/'||TO_CHAR(TO_NUMBER(TO_CHAR(g_extract_params(p_business_group_id).extract_start_date,'YYYY')) - 1),'DD/MM/YYYY');
12553    l_end_de   := TO_DATE('31/12/'||TO_CHAR(TO_NUMBER(TO_CHAR(g_extract_params(p_business_group_id).extract_start_date,'YYYY')) - 1),'DD/MM/YYYY');
12554    l_de_asg_act := -1;
12555 
12556     OPEN csr_asg_act_de (c_assignment_id => p_assignment_id
12557                         ,c_start_de      => l_start_de
12558                         ,c_end_de        => l_end_de
12559                         ,c_bg_id         => p_business_group_id);
12560     FETCH csr_asg_act_de INTO l_de_asg_act;
12561     CLOSE csr_asg_act_de;
12562 
12563     --
12564     -- Check if any override pension salary is entered
12565     --
12566     l_override_lh := FALSE;
12567 
12568     OPEN c_get_override_salary(l_start_de,l_end_de);
12569     FETCH c_get_override_salary INTO l_lh_or_pen_sal,l_lh_or_date;
12570        IF c_get_override_salary%FOUND THEN
12571           l_override_lh := TRUE;
12572        ELSE
12573           l_override_lh := FALSE;
12574        END IF;
12575     CLOSE c_get_override_salary;
12576 
12577     IF l_de_asg_act <> - 1 OR  l_override_lh THEN
12578     --
12579     -- Derive the date for which we are attempting to get pension salary.
12580     --
12581 
12582     IF l_de_asg_act <> - 1 THEN
12583 
12584     SELECT date_earned
12585       INTO l_max_de
12586       FROM pay_payroll_actions ppa,
12587            pay_assignment_actions paa
12588      WHERE ppa.payroll_action_id = paa.payroll_action_id
12589        AND paa.assignment_action_id =l_de_asg_act;
12590    --
12591    -- Derive the pension salary
12592    --
12593 
12594     l_get_ps_val := Get_Pension_Salary(p_assignment_id
12595 			    ,p_business_group_id
12596 			    ,LAST_DAY(l_max_de)
12597                 ,'ABP Pension Salary'
12598                 ,l_de_asg_act
12599 			    ,p_error_message
12600 			    ,l_pension_sal_char);
12601 
12602      IF IsNumber(l_pension_sal_char) THEN
12603         l_pension_sal_char := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
12604                                      (Nvl(l_pension_sal_char,'0')))
12605                      		            ,'0999999V99'));
12606      END IF;
12607 
12608       l_get_yr_val := Get_Pension_Start_Year(p_assignment_id
12609 			    ,p_business_group_id
12610 			    ,LAST_DAY(l_max_de)
12611 			    ,l_start_de
12612 			    ,l_end_de
12613 			    ,p_error_message
12614 			    ,l_pension_yr_char);
12615 
12616   ELSE
12617 
12618      IF IsNumber(l_lh_or_pen_sal) THEN
12619         l_pension_sal_char := Trim(To_Char(ABS(Nvl(l_lh_or_pen_sal,0))
12620                      		            ,'0999999V99'));
12621      END IF;
12622 
12623      l_pension_yr_char := Ben_Ext_Fmt.apply_format_mask
12624                                    (l_lh_or_date,'YYYYMMDD');
12625 
12626   END IF;
12627 
12628      l_ret_val_asg  :=  Get_Asg_Seq_Num(p_assignment_id
12629                                   ,p_business_group_id
12630                                   ,p_effective_date
12631                                   ,p_error_message
12632                                   ,l_seq_num);
12633 
12634    SELECT ben_ext_rslt_dtl_s.NEXTVAL INTO l_ext_rslt_dtl_id FROM dual;
12635 
12636    INSERT INTO ben_ext_rslt_dtl
12637            ( EXT_RSLT_DTL_ID
12638             ,EXT_RSLT_ID
12639             ,BUSINESS_GROUP_ID
12640             ,EXT_RCD_ID
12641             ,PERSON_ID
12642             ,VAL_01
12643             ,VAL_02
12644             ,VAL_03
12645             ,VAL_04
12646             ,VAL_05
12647             ,VAL_06
12648             ,VAL_07
12649             ,VAL_08
12650             ,VAL_09
12651             ,VAL_10
12652             ,VAL_25
12653             ,VAL_26
12654             ,VAL_70
12655             ,CREATED_BY
12656             ,CREATION_DATE
12657             ,LAST_UPDATE_DATE
12658             ,LAST_UPDATED_BY
12659             ,LAST_UPDATE_LOGIN
12660             ,PROGRAM_APPLICATION_ID
12661             ,PROGRAM_ID
12662             ,PROGRAM_UPDATE_DATE
12663             ,REQUEST_ID
12664             ,OBJECT_VERSION_NUMBER
12665             ,PRMY_SORT_VAL
12666             ,SCND_SORT_VAL
12667             ,THRD_SORT_VAL
12668             ,TRANS_SEQ_NUM
12669             ,RCRD_SEQ_NUM)
12670     VALUES(  l_ext_rslt_dtl_id
12671             ,l_main_rec.EXT_RSLT_ID
12672             ,l_main_rec.BUSINESS_GROUP_ID
12673             ,l_main_rec.EXT_RCD_ID
12674             ,l_main_rec.PERSON_ID
12675             ,l_main_rec.VAL_01
12676             ,l_main_rec.VAL_02
12677             ,l_main_rec.VAL_03
12678             ,l_seq_num
12679             ,l_pension_sal_char
12680             ,l_main_rec.VAL_06
12681             ,l_pension_yr_char
12682             ,l_main_rec.VAL_08
12683             ,l_main_rec.VAL_09
12684             ,l_main_rec.VAL_10
12685             ,l_main_rec.VAL_25
12686             ,l_main_rec.VAL_26
12687             ,l_main_rec.VAL_70
12688             ,l_main_rec.CREATED_BY
12689             ,l_main_rec.CREATION_DATE
12690             ,l_main_rec.LAST_UPDATE_DATE
12691             ,l_main_rec.LAST_UPDATED_BY
12692             ,l_main_rec.LAST_UPDATE_LOGIN
12693             ,l_main_rec.PROGRAM_APPLICATION_ID
12694             ,l_main_rec.PROGRAM_ID
12695             ,l_main_rec.PROGRAM_UPDATE_DATE
12696             ,l_main_rec.REQUEST_ID
12697             ,l_main_rec.OBJECT_VERSION_NUMBER
12698             ,l_main_rec.PRMY_SORT_VAL
12699             ,l_main_rec.SCND_SORT_VAL
12700             ,l_main_rec.THRD_SORT_VAL
12701             ,l_main_rec.TRANS_SEQ_NUM
12702             ,l_main_rec.RCRD_SEQ_NUM);
12703         END IF; -- Check l_de_asg_act <> -1
12704 
12705 END IF;
12706 
12707 --
12708 -- Insert a Record 08 if the change of hire date is in the past
12709 --
12710 OPEN c_hire_dt_chg(c_person_id  => g_person_id
12711                   ,c_start_date => g_extract_params(p_business_group_id).extract_start_date
12712                   ,c_end_date   => g_extract_params(p_business_group_id).extract_end_date);
12713 FETCH c_hire_dt_chg INTO l_old_date_can,l_new_date_can;
12714    IF c_hire_dt_chg%FOUND THEN
12715       l_old_hire_dt := to_nl_date(l_old_date_can,'DD-MM-RRRR');
12716       l_new_hire_dt := to_nl_date(l_new_date_can,'DD-MM-RRRR');
12717       Hr_Utility.set_location(' Change in hire date found   ' || l_proc_name , 10);
12718 
12719       IF to_number(to_char(l_new_hire_dt,'YYYY'))
12720        < to_number(to_char(l_old_hire_dt,'YYYY')) THEN
12721         Hr_Utility.set_location(' Years are different      ' || l_proc_name , 10);
12722 
12723        OPEN or_pen_sal (l_new_hire_dt);
12724        FETCH or_pen_sal INTO l_or_pen_sal;
12725        IF or_pen_sal%FOUND THEN
12726           Hr_Utility.set_location(' Pension sal found are diff   ' || l_proc_name , 10);
12727           OPEN c_get_rcd_id(7);
12728           FETCH c_get_rcd_id INTO l_rcd_id;
12729           CLOSE c_get_rcd_id;
12730 
12731           OPEN csr_rslt_dtl(c_person_id      => g_person_id
12732                            ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
12733                            ,c_ext_dtl_rcd_id => l_rcd_id);
12734           FETCH csr_rslt_dtl INTO l_main_rec;
12735           CLOSE csr_rslt_dtl;
12736 
12737           SELECT ben_ext_rslt_dtl_s.NEXTVAL INTO l_ext_rslt_dtl_id FROM dual;
12738 
12739           INSERT INTO ben_ext_rslt_dtl
12740            ( EXT_RSLT_DTL_ID
12741             ,EXT_RSLT_ID
12742             ,BUSINESS_GROUP_ID
12743             ,EXT_RCD_ID
12744             ,PERSON_ID
12745             ,VAL_01
12746             ,VAL_02
12747             ,VAL_03
12748             ,VAL_04
12749             ,VAL_05
12750             ,VAL_06
12751             ,VAL_07
12752             ,VAL_08
12753             ,VAL_09
12754             ,VAL_10
12755             ,VAL_25
12756             ,VAL_26
12757             ,VAL_70
12758             ,CREATED_BY
12759             ,CREATION_DATE
12760             ,LAST_UPDATE_DATE
12761             ,LAST_UPDATED_BY
12762             ,LAST_UPDATE_LOGIN
12763             ,PROGRAM_APPLICATION_ID
12764             ,PROGRAM_ID
12765             ,PROGRAM_UPDATE_DATE
12766             ,REQUEST_ID
12767             ,OBJECT_VERSION_NUMBER
12768             ,PRMY_SORT_VAL
12769             ,SCND_SORT_VAL
12770             ,THRD_SORT_VAL
12771             ,TRANS_SEQ_NUM
12772             ,RCRD_SEQ_NUM)
12773           VALUES(  l_ext_rslt_dtl_id
12774             ,l_main_rec.EXT_RSLT_ID
12775             ,l_main_rec.BUSINESS_GROUP_ID
12776             ,l_main_rec.EXT_RCD_ID
12777             ,l_main_rec.PERSON_ID
12778             ,l_main_rec.VAL_01
12779             ,l_main_rec.VAL_02
12780             ,l_main_rec.VAL_03
12781             ,l_main_rec.VAL_04
12782             ,l_main_rec.VAL_05
12783             ,l_main_rec.VAL_06
12784             ,to_char(l_new_hire_dt,'YYYYMMDD')
12785             ,l_main_rec.VAL_08
12786             ,l_main_rec.VAL_09
12787             ,l_main_rec.VAL_10
12788             ,l_main_rec.VAL_25
12789             ,l_main_rec.VAL_26
12790             ,l_main_rec.VAL_70
12791             ,l_main_rec.CREATED_BY
12792             ,l_main_rec.CREATION_DATE
12793             ,l_main_rec.LAST_UPDATE_DATE
12794             ,l_main_rec.LAST_UPDATED_BY
12795             ,l_main_rec.LAST_UPDATE_LOGIN
12796             ,l_main_rec.PROGRAM_APPLICATION_ID
12797             ,l_main_rec.PROGRAM_ID
12798             ,l_main_rec.PROGRAM_UPDATE_DATE
12799             ,l_main_rec.REQUEST_ID
12800             ,l_main_rec.OBJECT_VERSION_NUMBER
12801             ,l_main_rec.PRMY_SORT_VAL
12802             ,l_main_rec.SCND_SORT_VAL
12803             ,l_main_rec.THRD_SORT_VAL
12804             ,l_main_rec.TRANS_SEQ_NUM
12805             ,l_main_rec.RCRD_SEQ_NUM);
12806        END IF;
12807        CLOSE or_pen_sal;
12808        END IF;
12809    END IF;
12810 
12811 CLOSE c_hire_dt_chg;
12812 
12813    Hr_Utility.set_location(' Leaving     '||l_proc_name , 15);
12814 
12815 RETURN l_ret_val;
12816 
12817 EXCEPTION
12818    WHEN Others THEN
12819    p_error_message :='SQL-ERRM :'||SQLERRM;
12820    Hr_Utility.set_location('..'||p_error_message,85);
12821    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
12822    RETURN -1;
12823 END Process_Mult_Rec08;
12824 
12825 -- =============================================================================
12826 -- Process Multiple SubCategories for record 09
12827 -- =============================================================================
12828 FUNCTION Process_Mult_Rec09
12829 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
12830   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
12831   ,p_effective_date       IN  Date
12832   ,p_error_message        OUT NOCOPY Varchar2
12833   ,p_data_element_value   OUT NOCOPY Varchar2
12834 ) RETURN  Number IS
12835 
12836    l_ret_val        Number := 0;
12837    l_asg_action_id  pay_assignment_actions.assignment_action_id%TYPE;
12838    l_proc_name      Varchar2(150) := g_proc_name ||'Process_Mult_Rec09';
12839    l_rcd_id         Number;
12840    l_index          Number;
12841    l_main_rec       csr_rslt_dtl%ROWTYPE;
12842    l_new_rec        csr_rslt_dtl%ROWTYPE;
12843 
12844 BEGIN
12845    Hr_Utility.set_location(' Entering     ' || l_proc_name , 10);
12846 
12847    IF l_rec_09_values.Count > 0 THEN
12848 
12849    --Fetch the record id from the sequence number
12850    OPEN c_get_rcd_id(8);
12851    FETCH c_get_rcd_id INTO l_rcd_id;
12852    CLOSE c_get_rcd_id;
12853 
12854    OPEN csr_rslt_dtl(c_person_id      => g_person_id
12855                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
12856                     ,c_ext_dtl_rcd_id => l_rcd_id
12857                    );
12858    FETCH csr_rslt_dtl INTO l_main_rec;
12859    CLOSE csr_rslt_dtl;
12860 
12861    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
12862    l_new_rec := l_main_rec;
12863 
12864    l_index := l_rec_09_values.LAST;
12865 
12866    FOR i IN 1..l_index
12867    LOOP
12868       IF l_rec_09_values.EXISTS(i) THEN
12869          Process_Ext_Rslt_Dtl_Rec
12870            (p_assignment_id    => p_assignment_id
12871            ,p_effective_date   => p_effective_date
12872            ,p_ext_dtl_rcd_id   => l_rcd_id
12873            ,p_rslt_rec         => l_main_rec
12874            ,p_error_message    => p_error_message
12875            );
12876        END IF;
12877    END LOOP;
12878 
12879    END IF;
12880    l_rec_09_disp := 'N';
12881    l_ret_val := 0;
12882 
12883    Hr_Utility.set_location(' Leaving      '||l_proc_name , 15);
12884 
12885 RETURN l_ret_val;
12886 EXCEPTION
12887    WHEN Others THEN
12888    p_error_message :='SQL-ERRM :'||SQLERRM;
12889    Hr_Utility.set_location('..'||p_error_message,85);
12890    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
12891    RETURN -1;
12892 END Process_Mult_Rec09;
12893 
12894 -- =============================================================================
12895 -- Process Multiple SubCategories for Record 12
12896 -- =============================================================================
12897 FUNCTION Process_Mult_Rec12
12898 (
12899    p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
12900   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
12901   ,p_effective_date       IN  Date
12902   ,p_error_message        OUT NOCOPY Varchar2
12903   ,p_data_element_value   OUT NOCOPY Varchar2
12904 ) RETURN  Number IS
12905 
12906     l_ret_val        Number := 0;
12907     l_asg_action_id  pay_assignment_actions.assignment_action_id%TYPE;
12908     l_proc_name      Varchar2(150) := g_proc_name ||'Process_Mult_Rec12';
12909     l_rcd_id         Number;
12910     l_index          Number;
12911     i                Number;
12912     l_main_rec       csr_rslt_dtl%ROWTYPE;
12913     l_new_rec        csr_rslt_dtl%ROWTYPE;
12914 
12915 BEGIN
12916 
12917     Hr_Utility.set_location(' Entering     ' || l_proc_name , 10);
12918     hr_utility.set_location('asg : '||p_assignment_id||'count : '||l_rec_12_values.Count,12);
12919 
12920    IF l_rec_12_values.Count > 0 THEN
12921    --fetch the record id from the sequence number
12922    OPEN c_get_rcd_id(10);
12923    FETCH c_get_rcd_id INTO l_rcd_id;
12924    CLOSE c_get_rcd_id;
12925 
12926    OPEN csr_rslt_dtl(c_person_id      => g_person_id
12927                      ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
12928                      ,c_ext_dtl_rcd_id => l_rcd_id
12929                     );
12930 
12931     FETCH csr_rslt_dtl INTO l_main_rec;
12932 
12933     CLOSE csr_rslt_dtl;
12934 
12935     l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
12936     l_new_rec := l_main_rec;
12937     l_index := l_rec_12_values.LAST;
12938        FOR i IN 1..l_index
12939        LOOP
12940           hr_utility.set_location('counts : '||i||'----'||l_index,15);
12941           IF l_rec_12_values.EXISTS(i) THEN
12942              Process_Ext_Rslt_Dtl_Rec
12943                (p_assignment_id    => p_assignment_id
12944                ,p_effective_date   => p_effective_date
12945                ,p_ext_dtl_rcd_id   => l_rcd_id
12946                ,p_rslt_rec         => l_main_rec
12947                ,p_error_message    => p_error_message
12948                );
12949            END IF;
12950        END LOOP;
12951 
12952        END IF;
12953        l_rec_12_disp := 'N';
12954        l_ret_val := 0;
12955 
12956    Hr_Utility.set_location(' Leaving      '||l_proc_name , 15);
12957 
12958 RETURN l_ret_val;
12959 
12960 EXCEPTION
12961 WHEN Others THEN
12962    p_error_message :='SQL-ERRM :'||SQLERRM;
12963    Hr_Utility.set_location('..'||p_error_message,85);
12964    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
12965    RETURN l_ret_val;
12966 END Process_Mult_Rec12;
12967 
12968 --============================================================================
12969 --This is used to check if there are any more rows for SI participation and insert
12970 --those records forcibly
12971 --============================================================================
12972 FUNCTION Process_Mult_Rec20
12973           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
12974           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
12975           ,p_effective_date       IN  Date
12976           ,p_error_message        OUT NOCOPY Varchar2
12977 	      ,p_data_element_value   OUT NOCOPY Varchar2
12978           ) RETURN Number IS
12979 
12980 l_return_value  Number := 0;
12981 
12982 BEGIN
12983    p_data_element_value := '';
12984    l_return_value := 0;
12985    RETURN l_return_value;
12986 EXCEPTION
12987    WHEN Others THEN
12988     p_error_message :='SQL-ERRM :'||SQLERRM;
12989     Hr_Utility.set_location('..'||p_error_message,85);
12990     RETURN l_return_value;
12991 END Process_Mult_Rec20;
12992 
12993 ---------------------------------------------------------------------------
12994 FUNCTION Process_Mult_Rec21
12995                (p_assignment_id       IN Number
12996                ,p_business_group_id   IN Number
12997                ,p_effective_date      IN Date
12998                ,p_error_message       IN OUT NOCOPY Varchar2 )
12999 RETURN Number IS
13000 
13001 l_return_value     Number := 0;
13002 l_proc_name        Varchar2(80) := 'Process_Mult_Rec21';
13003 
13004 BEGIN
13005 
13006   RETURN 0;
13007 
13008 EXCEPTION
13009    WHEN Others THEN
13010     p_error_message :='SQL-ERRM :'||SQLERRM;
13011     Hr_Utility.set_location('..'||p_error_message,85);
13012     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 15);
13013     RETURN -1;
13014 END Process_Mult_Rec21;
13015 
13016 ---------------------------------------------------------------------------
13017 FUNCTION Process_Mult_Rec22
13018                (p_assignment_id       IN Number
13019                ,p_business_group_id   IN Number
13020                ,p_effective_date      IN Date
13021                ,p_error_message       IN OUT NOCOPY Varchar2 )
13022 RETURN Number IS
13023 
13024 l_return_value     Number := 0;
13025 l_proc_name        Varchar2(80) := 'Process_Mult_Rec22';
13026 
13027 BEGIN
13028   Hr_Utility.set_location('Entering: '||l_proc_name, 15);
13029   RETURN 0;
13030   Hr_Utility.set_location('Leaving: '||l_proc_name, 15);
13031 
13032 EXCEPTION
13033    WHEN Others THEN
13034     p_error_message :='SQL-ERRM :'||SQLERRM;
13035     Hr_Utility.set_location('..'||p_error_message,85);
13036     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 15);
13037     RETURN -1;
13038 END Process_Mult_Rec22;
13039 
13040 --============================================================================
13041 --This is used to check if there are any more rows for IPAP participation and insert
13042 --those records forcibly
13043 --============================================================================
13044 FUNCTION Process_Mult_Rec30
13045           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13046            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13047            ,p_effective_date       IN  Date
13048            ,p_error_message        OUT NOCOPY Varchar2
13049            ,p_data_element_value   OUT NOCOPY Varchar2
13050           ) RETURN Number IS
13051 
13052 l_main_rec csr_rslt_dtl%ROWTYPE;
13053 l_new_rec  csr_rslt_dtl%ROWTYPE;
13054 l_return_value Number := 1;
13055 l_rcd_id Number;
13056 
13057 BEGIN
13058    --fetch the record id from the sequence number
13059    OPEN c_get_rcd_id(17);
13060    FETCH c_get_rcd_id INTO l_rcd_id;
13061    CLOSE c_get_rcd_id;
13062 
13063    --first fetch the data from the result detail record
13064    OPEN csr_rslt_dtl(c_person_id  =>  g_person_id
13065                     ,c_ext_rslt_id => Ben_Ext_Thread.g_ext_rslt_id
13066                     ,c_ext_dtl_rcd_id => l_rcd_id
13067                     );
13068 
13069    FETCH csr_rslt_dtl INTO l_main_rec;
13070    CLOSE csr_rslt_dtl;
13071 
13072    l_new_rec := l_main_rec;
13073 
13074    WHILE(g_index_ipap < g_count_ipap)
13075    LOOP
13076       IF g_index_ipap <> 0 THEN
13077          Process_Ext_Rslt_Dtl_Rec
13078          (p_assignment_id => p_assignment_id
13079          ,p_organization_id => NULL
13080          ,p_effective_date => p_effective_date
13081          ,p_ext_dtl_rcd_id => l_rcd_id
13082          ,p_rslt_rec       => l_main_rec
13083          ,p_asgaction_no   => NULL
13084          ,p_error_message => p_error_message
13085          );
13086       END IF;
13087       g_index_ipap := g_index_ipap + 1;
13088    END LOOP;
13089    g_index_ipap := 0;
13090    p_data_element_value := '';
13091    l_return_value := 0;
13092    RETURN l_return_value;
13093 EXCEPTION
13094    WHEN Others THEN
13095     p_error_message :='SQL-ERRM :'||SQLERRM;
13096     Hr_Utility.set_location('..'||p_error_message,85);
13097 --    hr_utility.set_location('Leaving: '||l_proc_name, 90);
13098     RETURN l_return_value;
13099 END Process_Mult_Rec30;
13100 
13101 --=============================================================================
13102 -- This is used to check if there are any additional rows for rec 31
13103 -- This is for future use.
13104 --=============================================================================
13105 FUNCTION Process_Mult_Rec31
13106           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13107           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13108           ,p_effective_date       IN  Date
13109           ,p_error_message        OUT NOCOPY Varchar2
13110           ,p_data_element_value   OUT NOCOPY Varchar2
13111            ) RETURN Number IS
13112 
13113    l_ret_val        Number := 0;
13114    l_asg_action_id  pay_assignment_actions.assignment_action_id%TYPE;
13115    l_proc_name      Varchar2(150) := g_proc_name ||'Process_Mult_Rec31';
13116    l_rcd_id         Number;
13117    l_index          Number;
13118    l_main_rec       csr_rslt_dtl%ROWTYPE;
13119    l_new_rec        csr_rslt_dtl%ROWTYPE;
13120 
13121 BEGIN
13122 
13123    IF l_rec_31_values.Count > 0 THEN
13124 
13125    --Fetch the record id from the sequence number
13126    OPEN c_get_rcd_id(19);
13127    FETCH c_get_rcd_id INTO l_rcd_id;
13128    CLOSE c_get_rcd_id;
13129 
13130    OPEN csr_rslt_dtl(c_person_id      => g_person_id
13131                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
13132                     ,c_ext_dtl_rcd_id => l_rcd_id
13133                    );
13134    FETCH csr_rslt_dtl INTO l_main_rec;
13135    CLOSE csr_rslt_dtl;
13136 
13137    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
13138    l_new_rec := l_main_rec;
13139 
13140    l_index := l_rec_31_values.LAST;
13141 
13142    FOR i IN 1..l_index
13143    LOOP
13144       IF l_rec_31_values.EXISTS(i) THEN
13145          Process_Ext_Rslt_Dtl_Rec
13146            (p_assignment_id    => p_assignment_id
13147            ,p_effective_date   => p_effective_date
13148            ,p_ext_dtl_rcd_id   => l_rcd_id
13149            ,p_rslt_rec         => l_main_rec
13150            ,p_error_message    => p_error_message
13151            );
13152        END IF;
13153    END LOOP;
13154 
13155    END IF;
13156    l_rec_31_disp := 'N';
13157    l_ret_val := 0;
13158 
13159    Hr_Utility.set_location(' Leaving      '||l_proc_name , 15);
13160 
13161 RETURN l_ret_val;
13162 
13163 END Process_Mult_Rec31;
13164 
13165 --============================================================================
13166 -- This is used to check if there are any more rows for FUR participation and
13167 -- insert those records forcibly
13168 --=============================================================================
13169 FUNCTION Process_Mult_Rec40
13170           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13171            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13172            ,p_effective_date       IN  Date
13173            ,p_error_message        OUT NOCOPY Varchar2
13174 	   ,p_data_element_value   OUT NOCOPY Varchar2
13175           ) RETURN Number IS
13176 
13177 l_main_rec csr_rslt_dtl%ROWTYPE;
13178 l_new_rec  csr_rslt_dtl%ROWTYPE;
13179 l_return_value Number := 1;
13180 l_rcd_id Number;
13181 
13182 BEGIN
13183 
13184 
13185    --fetch the record id from the sequence number
13186    OPEN c_get_rcd_id(21);
13187    FETCH c_get_rcd_id INTO l_rcd_id;
13188    CLOSE c_get_rcd_id;
13189 
13190    --first fetch the data from the result detail record
13191    OPEN csr_rslt_dtl(c_person_id  =>  g_person_id
13192                     ,c_ext_rslt_id => Ben_Ext_Thread.g_ext_rslt_id
13193                     ,c_ext_dtl_rcd_id => l_rcd_id
13194                     );
13195 
13196    FETCH csr_rslt_dtl INTO l_main_rec;
13197    CLOSE csr_rslt_dtl;
13198 
13199    l_new_rec := l_main_rec;
13200 
13201    WHILE(g_index_fur < g_count_fur)
13202    LOOP
13203       IF g_index_fur <> 0 THEN
13204          Process_Ext_Rslt_Dtl_Rec
13205          (p_assignment_id => p_assignment_id
13206          ,p_organization_id => NULL
13207          ,p_effective_date => p_effective_date
13208          ,p_ext_dtl_rcd_id => l_rcd_id
13209          ,p_rslt_rec       => l_main_rec
13210          ,p_asgaction_no   => NULL
13211          ,p_error_message => p_error_message
13212          );
13213       END IF;
13214       g_index_fur := g_index_fur + 1;
13215    END LOOP;
13216    g_index_fur := 0;
13217    p_data_element_value := '';
13218 
13219 /*       l_return_value := Process_Mult_Rec21
13220                (p_assignment_id       => p_assignment_id
13221                ,p_business_group_id   => p_business_group_id
13222                ,p_effective_date      => p_effective_date
13223                ,p_error_message       => p_error_message
13224                 );*/
13225    l_return_value := 0;
13226    RETURN l_return_value;
13227 EXCEPTION
13228    WHEN Others THEN
13229     p_error_message :='SQL-ERRM :'||SQLERRM;
13230     Hr_Utility.set_location('..'||p_error_message,85);
13231 --    hr_utility.set_location('Leaving: '||l_proc_name, 90);
13232     RETURN l_return_value;
13233 END Process_Mult_Rec40;
13234 
13235 --=============================================================================
13236 -- This is used to check if there are any additional rows for rec 41
13237 -- This is for future use.
13238 --=============================================================================
13239 FUNCTION Process_Mult_Rec41
13240           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13241           ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13242           ,p_effective_date       IN  Date
13243           ,p_error_message        OUT NOCOPY Varchar2
13244           ,p_data_element_value   OUT NOCOPY Varchar2
13245            ) RETURN Number IS
13246 
13247    l_ret_val        Number := 0;
13248    l_asg_action_id  pay_assignment_actions.assignment_action_id%TYPE;
13249    l_proc_name      Varchar2(150) := g_proc_name ||'Process_Mult_Rec41';
13250    l_rcd_id         Number;
13251    l_index          Number;
13252    l_main_rec       csr_rslt_dtl%ROWTYPE;
13253    l_new_rec        csr_rslt_dtl%ROWTYPE;
13254 
13255 BEGIN
13256 
13257 IF g_fur_contrib_kind = 'A' THEN
13258 
13259    IF l_rec_41_basis_values.Count > 0 THEN
13260 
13261    --Fetch the record id from the sequence number
13262    OPEN c_get_rcd_id(23);
13263    FETCH c_get_rcd_id INTO l_rcd_id;
13264    CLOSE c_get_rcd_id;
13265 
13266    OPEN csr_rslt_dtl(c_person_id      => g_person_id
13267                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
13268                     ,c_ext_dtl_rcd_id => l_rcd_id
13269                    );
13270    FETCH csr_rslt_dtl INTO l_main_rec;
13271    CLOSE csr_rslt_dtl;
13272 
13273    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
13274    l_new_rec := l_main_rec;
13275 
13276    l_index := l_rec_41_basis_values.LAST;
13277 
13278    FOR i IN 1..l_index
13279    LOOP
13280       IF l_rec_41_basis_values.EXISTS(i) THEN
13281          Process_Ext_Rslt_Dtl_Rec
13282            (p_assignment_id    => p_assignment_id
13283            ,p_effective_date   => p_effective_date
13284            ,p_ext_dtl_rcd_id   => l_rcd_id
13285            ,p_rslt_rec         => l_main_rec
13286            ,p_error_message    => p_error_message
13287            );
13288        END IF;
13289    END LOOP;
13290 
13291    END IF;
13292    l_basis_rec_41_disp := 'N';
13293    l_ret_val := 0;
13294 
13295 ELSIF g_fur_contrib_kind = 'D' THEN
13296 
13297    IF l_rec_41_contrib_values.Count > 0 THEN
13298 
13299    --Fetch the record id from the sequence number
13300    OPEN c_get_rcd_id(23);
13301    FETCH c_get_rcd_id INTO l_rcd_id;
13302    CLOSE c_get_rcd_id;
13303 
13304    OPEN csr_rslt_dtl(c_person_id      => g_person_id
13305                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
13306                     ,c_ext_dtl_rcd_id => l_rcd_id
13307                    );
13308    FETCH csr_rslt_dtl INTO l_main_rec;
13309    CLOSE csr_rslt_dtl;
13310 
13311    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
13312    l_new_rec := l_main_rec;
13313 
13314    l_index := l_rec_41_contrib_values.LAST;
13315 
13316    FOR i IN 1..l_index
13317    LOOP
13318       IF l_rec_41_contrib_values.EXISTS(i) THEN
13319          Process_Ext_Rslt_Dtl_Rec
13320            (p_assignment_id    => p_assignment_id
13321            ,p_effective_date   => p_effective_date
13322            ,p_ext_dtl_rcd_id   => l_rcd_id
13323            ,p_rslt_rec         => l_main_rec
13324            ,p_error_message    => p_error_message
13325            );
13326        END IF;
13327    END LOOP;
13328 
13329    END IF;
13330    l_contrib_rec_41_disp := 'N';
13331    l_ret_val := 0;
13332 
13333 END IF;
13334 
13335    Hr_Utility.set_location(' Leaving      '||l_proc_name , 15);
13336 
13337 RETURN l_ret_val;
13338 
13339 END Process_Mult_Rec41;
13340 
13341 --============================================================================
13342 --Function to return the contribution amount towards FUR Pensions
13343 --============================================================================
13344 FUNCTION Get_FUR_Contribution_Amt
13345           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13346            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13347            ,p_effective_date       IN  Date
13348            ,p_error_message        OUT NOCOPY Varchar2
13349 	   ,p_data_element_value   OUT NOCOPY Varchar2
13350           ) RETURN Number IS
13351 
13352 --cursor to check if run results exist for any FUR Pension Types for this assignment
13353 --in this period
13354 CURSOR c_run_results_exist IS
13355 SELECT paa.assignment_action_id
13356    FROM  pay_payroll_actions ppa,pay_assignment_actions paa
13357 WHERE  paa.payroll_action_id = ppa.payroll_action_id
13358    AND ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
13359    AND g_extract_params(p_business_group_id).extract_end_date
13360    AND paa.assignment_id = p_assignment_id
13361    AND paa.assignment_action_id IN
13362        (SELECT assignment_action_id
13363           FROM pay_run_results
13364         WHERE  element_type_id IN
13365                (SELECT element_type_id
13366                   FROM pay_element_type_extra_info,pqp_pension_types_f pty
13367                 WHERE  information_type = 'PQP_NL_ABP_DEDUCTION'
13368                   AND  eei_information_category = 'PQP_NL_ABP_DEDUCTION'
13369                   AND  eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
13370                   AND  pty.pension_sub_category = 'FUR_S'
13371                )
13372        );
13373 
13374 l_asg_act_id   Number;
13375 l_defined_balance_id Number;
13376 l_proc Varchar2(30) := 'get_fur_contribution_amt';
13377 
13378 
13379 BEGIN
13380 
13381 --find the defined balance id for the FUR Standard EE Contribution for the _ASG_PTD dimension
13382 Hr_Utility.set_location('Entering : '||l_proc,10);
13383 OPEN csr_defined_bal(c_balance_name => 'FUR Standard EE Contribution'
13384                     ,c_dimension_name => 'Assignment Period To Date'
13385                     ,c_business_group_id => p_business_group_id
13386                     );
13387 FETCH csr_defined_bal INTO l_defined_balance_id;
13388 IF csr_defined_bal%FOUND THEN
13389    CLOSE csr_defined_bal;
13390    Hr_Utility.set_location('found defined balance id : '||l_defined_balance_id,20);
13391    --Find the assignment action of the payroll run if any FUR Pensions has been processed and
13392    --if the date earned for that payroll run , is between the extract start and end dates
13393    OPEN c_run_results_exist;
13394    FETCH c_run_results_exist INTO l_asg_act_id;
13395    IF c_run_results_exist%FOUND THEN
13396       --assignment action id has been found, now find the value for the EE contribution
13397       --from the dimension _ASG_PTD
13398       CLOSE c_run_results_exist;
13399       Hr_Utility.set_location('found asg action id : '||l_asg_act_id,30);
13400       --from the assignment action id,and defined balance id fetched above , find the balance value
13401       p_data_element_value := Fnd_Number.number_to_canonical(
13402                               Pay_Balance_Pkg.get_value(p_defined_balance_id => l_defined_balance_id
13403                                                        ,p_assignment_action_id => l_asg_act_id
13404                                                        ));
13405       Hr_Utility.set_location('found value for the contribution as : '||p_data_element_value,40);
13406       g_fur_contribution := Fnd_Number.canonical_to_number(p_data_element_value);
13407       RETURN 0;
13408    ELSE
13409       CLOSE c_run_results_exist;
13410       Hr_Utility.set_location('could not find the asg action id',50);
13411       p_data_element_value := '';
13412       p_error_message := 'Could not find a value for the Contribution amount towards FUR Pensions.';
13413       RETURN 1;
13414    END IF;
13415 ELSE
13416    CLOSE csr_defined_bal;
13417    Hr_Utility.set_location('could not find the defined balance id',60);
13418    p_data_element_value := '';
13419    p_error_message := 'Could not find the defined balance id for the contribution balance.';
13420    RETURN 1;
13421 END IF;
13422 
13423 EXCEPTION
13424    WHEN Others THEN
13425     p_error_message :='SQL-ERRM :'||SQLERRM;
13426     Hr_Utility.set_location('..'||p_error_message,70);
13427     RETURN 1;
13428 END get_fur_contribution_amt;
13429 
13430 --============================================================================
13431 --Function to return the contribution basis towards FUR/IPAP Pensions
13432 --============================================================================
13433 FUNCTION Get_Contribution_Basis
13434           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13435            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13436            ,p_effective_date       IN  Date
13437            ,p_sub_cat              IN  Varchar2
13438            ,p_error_message        OUT NOCOPY Varchar2
13439 	   ,p_data_element_value   OUT NOCOPY Varchar2
13440           ) RETURN Number IS
13441 
13442 --cursor to check if run results exist for any FUR/IPAP Pension Types for this assignment
13443 --in this period,and if so fetch the Scheme Prefix so that the basis balance name can be constructed
13444 CURSOR c_run_results_exist IS
13445 SELECT prr.assignment_action_id,
13446        pei.eei_information9
13447 FROM   pay_run_results prr,
13448        pay_payroll_actions ppa,
13449        pay_assignment_actions paa,
13450        pay_element_type_extra_info pei,
13451        pqp_pension_types_f pty
13452 WHERE  paa.assignment_action_id = prr.assignment_action_id
13453   AND  paa.payroll_action_id = ppa.payroll_action_id
13454   AND  ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
13455   AND  g_extract_params(p_business_group_id).extract_end_date
13456   AND  paa.assignment_id = p_assignment_id
13457   AND  pei.element_type_id = prr.element_type_id
13458   AND  pei.information_type = 'PQP_NL_ABP_DEDUCTION'
13459   AND  pei.eei_information_category = 'PQP_NL_ABP_DEDUCTION'
13460   AND  pei.eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
13461   AND  pty.pension_sub_category = p_sub_cat;
13462 
13463 l_asg_act_id   Number;
13464 l_scheme_prefix Varchar2(150);
13465 l_defined_balance_id Number;
13466 l_proc Varchar2(30) := 'get_contribution_basis';
13467 
13468 
13469 BEGIN
13470 
13471 Hr_Utility.set_location('sub category is : '||p_sub_cat,10);
13472 OPEN c_run_results_exist;
13473 FETCH c_run_results_exist INTO l_asg_act_id,l_scheme_prefix;
13474 IF c_run_results_exist%FOUND THEN
13475    CLOSE c_run_results_exist;
13476    --find the defined balance id for the Pension Basis balance for the _ASG_RUN dimension
13477    Hr_Utility.set_location('Entering : '||l_proc,10);
13478    Hr_Utility.set_location('asg act id : '||l_asg_act_id,15);
13479    Hr_Utility.set_location('scheme prefix : '||l_scheme_prefix,20);
13480    OPEN csr_defined_bal(c_balance_name => l_scheme_prefix||' Employee Pension Basis'
13481                        ,c_dimension_name => 'Assignment Run'
13482                        ,c_business_group_id => p_business_group_id
13483                        );
13484    FETCH csr_defined_bal INTO l_defined_balance_id;
13485    IF csr_defined_bal%FOUND THEN
13486       CLOSE csr_defined_bal;
13487       Hr_Utility.set_location('found defined balance id : '||l_defined_balance_id,20);
13488       --from the assignment action id,and defined balance id fetched above , find the balance value
13489       p_data_element_value := Fnd_Number.number_to_canonical(
13490                               Pay_Balance_Pkg.get_value(p_defined_balance_id => l_defined_balance_id
13491                                                        ,p_assignment_action_id => l_asg_act_id
13492                                                        ));
13493       Hr_Utility.set_location('found value for the contribution as : '||p_data_element_value,40);
13494       IF p_sub_cat = 'FUR_S' THEN
13495          g_fur_contribution := Fnd_Number.canonical_to_number(p_data_element_value);
13496          RETURN 0;
13497       ELSIF p_sub_cat = 'IPAP' THEN
13498          g_ipap_contribution := Fnd_Number.canonical_to_number(p_data_element_value);
13499          RETURN 0;
13500       END IF;
13501    ELSE
13502       CLOSE csr_defined_bal;
13503       Hr_Utility.set_location('could not find the defined balance id',60);
13504       p_data_element_value := '';
13505       p_error_message := 'Could not find the defined balance id for the contribution balance.';
13506       RETURN 1;
13507    END IF;
13508 ELSE
13509    CLOSE c_run_results_exist;
13510    Hr_Utility.set_location('Employee does not contribute towards pensions ',65);
13511    p_data_element_value := '';
13512    p_error_message := 'Could not find run results.';
13513    RETURN 1;
13514 END IF;
13515 
13516 EXCEPTION
13517    WHEN Others THEN
13518     p_error_message :='SQL-ERRM :'||SQLERRM;
13519     Hr_Utility.set_location('..'||p_error_message,70);
13520     RETURN 1;
13521 END get_contribution_basis;
13522 
13523 -- =============================================================================
13524 -- Get_Basis_Amt for Record 09/31/41
13525 -- This Function returns the Basis Contribution amount for any sub cats in
13526 -- rec 09/31/41 that the ee might have paid for .
13527 -- =============================================================================
13528 FUNCTION Get_Basis_Amt
13529   (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13530   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13531   ,p_effective_date       IN  Date
13532   ,p_record_number        IN  Number
13533   ,p_error_message        OUT NOCOPY Varchar2
13534   ,p_data_element_value   OUT NOCOPY Varchar2)
13535 RETURN Number IS
13536 
13537    l_proc_name Varchar2(150) := g_proc_name ||'Get_Basis_Amt';
13538    j           Number ;
13539 
13540 BEGIN
13541 
13542 Hr_Utility.set_location(' Entering : ' || l_proc_name , 10);
13543    IF p_record_number = 9 THEN
13544     IF l_rec_09_values.count > 0 THEN
13545       j := l_rec_09_values.FIRST;
13546       IF l_rec_09_values.EXISTS(j) THEN
13547          p_data_element_value :=
13548              Fnd_Number.number_to_canonical(l_rec_09_values(j).basis_amount);
13549       END IF;
13550     END IF;
13551    ELSIF p_record_number = 31 THEN
13552     IF l_rec_31_values.count > 0 THEN
13553       j := l_rec_31_values.FIRST;
13554       IF l_rec_31_values.EXISTS(j) THEN
13555          p_data_element_value :=
13556              Fnd_Number.number_to_canonical(l_rec_31_values(j).basis_amount);
13557       END IF;
13558     END IF;
13559    ELSIF p_record_number = 41 THEN
13560     IF l_rec_41_basis_values.count > 0 THEN
13561       j := l_rec_41_basis_values.FIRST;
13562       IF l_rec_41_basis_values.EXISTS(j) THEN
13563          p_data_element_value :=
13564              Fnd_Number.number_to_canonical(l_rec_41_basis_values(j).basis_amount);
13565       END IF;
13566     END IF;
13567    END IF;
13568 
13569 Hr_Utility.set_location(' Leaving : ' || l_proc_name , 80);
13570 
13571 RETURN 0 ;
13572 
13573 EXCEPTION
13574     WHEN Others THEN
13575     p_error_message :='SQL-ERRM :'||SQLERRM;
13576     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
13577     RETURN -1 ;
13578 END Get_Basis_Amt;
13579 
13580 -- =============================================================================
13581 -- Get_Sub_Cat_09 for Record 09
13582 -- This Function gets the sub categories for rec 09
13583 -- =============================================================================
13584 FUNCTION Get_Sub_Cat_09
13585 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13586   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13587   ,p_effective_date       IN  Date
13588   ,p_error_message        OUT NOCOPY Varchar2
13589   ,p_data_element_value   OUT NOCOPY Varchar2)
13590 RETURN  Number IS
13591 
13592    l_proc_name Varchar2(150) := g_proc_name ||'Get_Sub_Cat_09';
13593    j           Number ;
13594 
13595 BEGIN
13596 
13597 Hr_Utility.set_location(' Entering : ' || l_proc_name , 10);
13598   IF l_rec_09_values.count > 0 THEN
13599    j := l_rec_09_values.FIRST;
13600    IF l_rec_09_values.EXISTS(j) THEN
13601      p_data_element_value := l_rec_09_values(j).code;
13602    END IF;
13603  END IF;
13604 
13605 Hr_Utility.set_location(' Leaving : ' || l_proc_name , 80);
13606 
13607 RETURN 0 ;
13608 
13609 EXCEPTION
13610     WHEN Others THEN
13611     p_error_message :='SQL-ERRM :'||SQLERRM;
13612     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
13613     RETURN -1 ;
13614 END Get_Sub_Cat_09;
13615 
13616 -- =============================================================================
13617 -- Get_Basis_Amt_Code for Record 09/31/41
13618 -- This Function gets sign for basis amount in rec 09/31/41
13619 -- =============================================================================
13620 FUNCTION Get_Basis_Amt_Code
13621 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13622   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13623   ,p_effective_date       IN  Date
13624   ,p_record_number        IN  Number
13625   ,p_error_message        OUT NOCOPY Varchar2
13626   ,p_data_element_value   OUT NOCOPY Varchar2)
13627 RETURN  Number IS
13628 
13629    l_proc_name Varchar2(150) := g_proc_name ||'Get_Basis_Amt_Code';
13630    j           Number ;
13631 
13632 BEGIN
13633 
13634 Hr_Utility.set_location(' Entering : ' || l_proc_name , 10);
13635    IF p_record_number = 9 THEN
13636     IF l_rec_09_values.count > 0 THEN
13637       j := l_rec_09_values.FIRST;
13638       IF l_rec_09_values.EXISTS(j) THEN
13639          p_data_element_value := l_rec_09_values(j).sign_code;
13640       END IF;
13641     END IF;
13642    ELSIF p_record_number = 31 THEN
13643     IF l_rec_31_values.count > 0 THEN
13644       j := l_rec_31_values.FIRST;
13645       IF l_rec_31_values.EXISTS(j) THEN
13646          p_data_element_value := l_rec_31_values(j).sign_code;
13647       END IF;
13648     END IF;
13649    ELSIF p_record_number = 41 THEN
13650     IF l_rec_41_basis_values.count > 0 THEN
13651       j := l_rec_41_basis_values.FIRST;
13652       IF l_rec_41_basis_values.EXISTS(j) THEN
13653          p_data_element_value := l_rec_41_basis_values(j).sign_code;
13654       END IF;
13655     END IF;
13656    END IF;
13657 
13658 Hr_Utility.set_location(' Leaving : ' || l_proc_name , 80);
13659 
13660 RETURN 0 ;
13661 
13662 EXCEPTION
13663     WHEN Others THEN
13664     p_error_message :='SQL-ERRM :'||SQLERRM;
13665     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
13666     RETURN -1 ;
13667 END Get_Basis_Amt_Code;
13668 
13669 -- =============================================================================
13670 -- Get_Contrib_Amt_Code for Record 12/41
13671 -- This Function gets sign for contrib amount in rec 12/41
13672 -- =============================================================================
13673 FUNCTION Get_Contrib_Amt_Code
13674 (  p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13675   ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13676   ,p_effective_date       IN  Date
13677   ,p_record_number        IN  Number
13678   ,p_error_message        OUT NOCOPY Varchar2
13679   ,p_data_element_value   OUT NOCOPY Varchar2)
13680 RETURN  Number IS
13681 
13682    l_proc_name Varchar2(150) := g_proc_name ||'Get_Contrib_Amt_Code';
13683    j           Number ;
13684 
13685 BEGIN
13686 
13687 Hr_Utility.set_location(' Entering : ' || l_proc_name , 10);
13688 IF p_record_number = 12 THEN
13689  IF l_rec_12_values.count > 0 THEN
13690    j := l_rec_12_values.FIRST;
13691    IF l_rec_12_values.EXISTS(j) THEN
13692       IF l_rec_12_values(j).contrib_amount < 0 THEN
13693         p_data_element_value := 'C';
13694       ELSE
13695         p_data_element_value := ' ';
13696       END IF;
13697    END IF;
13698  END IF;
13699 ELSIF p_record_number = 41 THEN
13700  IF l_rec_41_contrib_values.count > 0 THEN
13701    j := l_rec_41_contrib_values.FIRST;
13702    IF l_rec_41_contrib_values.EXISTS(j) THEN
13703       IF l_rec_41_contrib_values(j).contrib_amount < 0 THEN
13704         p_data_element_value := 'C';
13705       ELSE
13706         p_data_element_value := ' ';
13707       END IF;
13708    END IF;
13709  END IF;
13710 END IF;
13711 
13712 Hr_Utility.set_location(' Leaving : ' || l_proc_name , 80);
13713 
13714 RETURN 0 ;
13715 
13716 EXCEPTION
13717     WHEN Others THEN
13718     p_error_message :='SQL-ERRM :'||SQLERRM;
13719     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
13720     RETURN -1 ;
13721 END Get_Contrib_Amt_Code;
13722 
13723 
13724 --============================================================================
13725 --Function to return the contribution amount towards IPAP Pensions
13726 --============================================================================
13727 FUNCTION Get_IPAP_Contribution_Amt
13728           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13729            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13730            ,p_effective_date       IN  Date
13731            ,p_error_message        OUT NOCOPY Varchar2
13732 	   ,p_data_element_value   OUT NOCOPY Varchar2
13733           ) RETURN Number IS
13734 
13735 --cursor to check if run results exist for any IPAP Pension Types for this assignment
13736 --in this period
13737 CURSOR c_run_results_exist IS
13738 SELECT paa.assignment_action_id
13739    FROM  pay_payroll_actions ppa,pay_assignment_actions paa
13740 WHERE  paa.payroll_action_id = ppa.payroll_action_id
13741    AND ppa.date_earned BETWEEN g_extract_params(p_business_group_id).extract_start_date
13742    AND g_extract_params(p_business_group_id).extract_end_date
13743    AND paa.assignment_id = p_assignment_id
13744    AND paa.assignment_action_id IN
13745        (SELECT assignment_action_id
13746           FROM pay_run_results
13747         WHERE  element_type_id IN
13748                (SELECT element_type_id
13749                   FROM pay_element_type_extra_info,pqp_pension_types_f pty
13750                 WHERE  information_type = 'PQP_NL_ABP_DEDUCTION'
13751                   AND  eei_information_category = 'PQP_NL_ABP_DEDUCTION'
13752                   AND  eei_information2 = Fnd_Number.number_to_canonical(pty.pension_type_id)
13753                   AND  pty.pension_sub_category = 'IPAP'
13754                )
13755        );
13756 
13757 l_asg_act_id   Number;
13758 l_defined_balance_id Number;
13759 l_proc Varchar2(30) := 'get_ipap_contribution_amt';
13760 
13761 BEGIN
13762 
13763 --find the defined balance id for the IPAP Standard EE Contribution for the _ASG_PTD dimension
13764 Hr_Utility.set_location('Entering : '||l_proc,10);
13765 OPEN csr_defined_bal(c_balance_name => 'IPAP EE Contribution'
13766                     ,c_dimension_name => 'Assignment Period To Date'
13767                     ,c_business_group_id => p_business_group_id
13768                     );
13769 FETCH csr_defined_bal INTO l_defined_balance_id;
13770 IF csr_defined_bal%FOUND THEN
13771    CLOSE csr_defined_bal;
13772    Hr_Utility.set_location('found defined balance id : '||l_defined_balance_id,20);
13773    --Find the assignment action of the payroll run if any IPAP Pensions has been processed and
13774    --if the date earned for that payroll run , is between the extract start and end dates
13775    OPEN c_run_results_exist;
13776    FETCH c_run_results_exist INTO l_asg_act_id;
13777    IF c_run_results_exist%FOUND THEN
13778       --assignment action id has been found, now find the value for the EE contribution
13779       --from the dimension _ASG_PTD
13780       CLOSE c_run_results_exist;
13781       Hr_Utility.set_location('found asg action id : '||l_asg_act_id,30);
13782       --from the assignment action id,and defined balance id fetched above , find the balance value
13783       p_data_element_value := Fnd_Number.number_to_canonical(
13784                               Pay_Balance_Pkg.get_value(p_defined_balance_id => l_defined_balance_id
13785                                                        ,p_assignment_action_id => l_asg_act_id
13786                                                        ));
13787       Hr_Utility.set_location('found value for the contribution as : '||p_data_element_value,40);
13788       g_ipap_contribution := Fnd_Number.canonical_to_number(p_data_element_value);
13789       RETURN 0;
13790    ELSE
13791       CLOSE c_run_results_exist;
13792       Hr_Utility.set_location('could not find the asg action id',50);
13793       p_data_element_value := '';
13794       p_error_message := 'Could not find a value for the Contribution amount towards IPAP Pensions.';
13795       RETURN 1;
13796    END IF;
13797 ELSE
13798    CLOSE csr_defined_bal;
13799    Hr_Utility.set_location('could not find the defined balance id',60);
13800    p_data_element_value := '';
13801    p_error_message := 'Could not find the defined balance id for the contribution balance.';
13802    RETURN 1;
13803 END IF;
13804 
13805 EXCEPTION
13806    WHEN Others THEN
13807     p_error_message :='SQL-ERRM :'||SQLERRM;
13808     Hr_Utility.set_location('..'||p_error_message,70);
13809     RETURN 1;
13810 END get_ipap_contribution_amt;
13811 
13812 --============================================================================
13813 --This function returns the code to indicate whether the basis/contribution is positive
13814 --or negative
13815 --============================================================================
13816 FUNCTION Get_Amt_Code
13817           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13818            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13819            ,p_effective_date       IN  Date
13820            ,p_sub_cat              IN  Varchar2
13821            ,p_error_message        OUT NOCOPY Varchar2
13822 	   ,p_data_element_value   OUT NOCOPY Varchar2
13823           ) RETURN Number IS
13824 
13825 l_proc_name Varchar2(30) := 'Get_Amt_Code';
13826 
13827 BEGIN
13828 
13829 Hr_Utility.set_location('Entering : -----------'||l_proc_name,5);
13830 IF p_sub_cat = 'FUR_S' THEN
13831    IF g_fur_contribution >= 0 THEN
13832       p_data_element_value := ' ';
13833       RETURN 0;
13834    ELSE
13835       p_data_element_value := 'C';
13836       RETURN 0;
13837    END IF;
13838 ELSIF p_sub_cat = 'IPAP' THEN
13839    IF g_ipap_contribution >= 0 THEN
13840       p_data_element_value := ' ';
13841       RETURN 0;
13842    ELSE
13843       p_data_element_value := 'C';
13844       RETURN 0;
13845    END IF;
13846 END IF;
13847 
13848 EXCEPTION
13849    WHEN Others THEN
13850     p_error_message :='SQL-ERRM :'||SQLERRM;
13851     Hr_Utility.set_location('..'||p_error_message,10);
13852     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 15);
13853     RETURN -1;
13854 
13855 END Get_Amt_Code;
13856 
13857 --============================================================================
13858 --This function returns the month of contribution
13859 --============================================================================
13860 FUNCTION Get_Amt_Month
13861           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13862            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13863            ,p_effective_date       IN  Date
13864            ,p_error_message        OUT NOCOPY Varchar2
13865 	   ,p_data_element_value   OUT NOCOPY Varchar2
13866           ) RETURN Number IS
13867 
13868 l_proc_name Varchar2(30) := 'Get_Amt_Month';
13869 l_month Varchar2(4);
13870 
13871 --cursor to fetch the month from the effective date
13872 CURSOR c_get_amt_month IS
13873 SELECT To_Char(p_effective_date,'MM')
13874   FROM dual;
13875 
13876 BEGIN
13877 Hr_Utility.set_location('Entering:-------- '||l_proc_name, 5);
13878 OPEN c_get_amt_month;
13879 FETCH c_get_amt_month INTO l_month;
13880 CLOSE c_get_amt_month;
13881 Hr_Utility.set_location('month of amt is : '||l_month,7);
13882 p_data_element_value := l_month;
13883 RETURN 0;
13884 
13885 EXCEPTION
13886    WHEN Others THEN
13887     p_error_message :='SQL-ERRM :'||SQLERRM;
13888     Hr_Utility.set_location('..'||p_error_message,10);
13889     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 15);
13890     RETURN -1;
13891 
13892 END Get_Amt_Month;
13893 
13894 --============================================================================
13895 --This function returns the year of contribution
13896 --============================================================================
13897 FUNCTION Get_Amt_Year
13898          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13899          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13900          ,p_effective_date       IN  DATE
13901          ,p_error_message        OUT NOCOPY VARCHAR2
13902          ,p_data_element_value   OUT NOCOPY VARCHAR2)
13903 RETURN NUMBER IS
13904 
13905 l_proc_name VARCHAR2(30) := 'Get_Amt_Year';
13906 l_year      VARCHAR2(8);
13907 
13908 --
13909 --Cursor to fetch the year from the effective date
13910 --
13911 CURSOR c_get_amt_year IS
13912 SELECT TO_CHAR(p_effective_date,'YYYY')
13913   FROM dual;
13914 
13915 BEGIN
13916 
13917 hr_utility.set_location('Entering :------- '||l_proc_name,5);
13918 
13919 OPEN c_get_amt_year;
13920 FETCH c_get_amt_year INTO l_year;
13921 CLOSE c_get_amt_year;
13922 
13923 p_data_element_value := l_year;
13924 
13925 hr_utility.set_location('Year is :------- '||l_year,10);
13926 hr_utility.set_location('Leaving :------- '||l_proc_name,15);
13927 
13928 RETURN 0;
13929 
13930 EXCEPTION
13931 WHEN OTHERS THEN
13932   p_error_message :='SQL-ERRM :'||SQLERRM;
13933   hr_utility.set_location('..ERROR'||p_error_message,10);
13934   hr_utility.set_location('Leaving:-------- '||l_proc_name, 15);
13935   RETURN -1;
13936 
13937 END Get_Amt_Year;
13938 
13939 --============================================================================
13940 --This function returns the kind of contribution for FUR Pensions, from the ASG EIT
13941 --============================================================================
13942 FUNCTION Get_Fur_Contribution_Kind
13943           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13944            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13945            ,p_effective_date       IN  Date
13946            ,p_error_message        OUT NOCOPY Varchar2
13947 	   ,p_data_element_value   OUT NOCOPY Varchar2
13948           ) RETURN Number IS
13949 
13950 l_proc_name Varchar2(30) := 'Get_Fur_Contribution_Kind';
13951 l_kind_of_contrib Varchar2(1) := 'D';
13952 
13953 --cursor to fetch the contribution kind from the ASG EIT
13954 CURSOR c_get_contrib_kind IS
13955 SELECT Substr(Nvl(aei_information7,'D'),0,1)
13956   FROM per_assignment_extra_info
13957 WHERE  assignment_id = p_assignment_id
13958   AND  p_effective_date BETWEEN Fnd_Date.canonical_to_date(aei_information1)
13959   AND  Fnd_Date.canonical_to_date(Nvl(aei_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)))
13960   AND  aei_information_category = 'NL_ABP_RI'
13961   AND  information_type = 'NL_ABP_RI';
13962 
13963 BEGIN
13964 
13965 Hr_Utility.set_location('Entering ------ : '||l_proc_name,5);
13966 OPEN c_get_contrib_kind;
13967 FETCH c_get_contrib_kind INTO l_kind_of_contrib;
13968 IF c_get_contrib_kind%FOUND THEN
13969    CLOSE c_get_contrib_kind;
13970 ELSE
13971    CLOSE c_get_contrib_kind;
13972    l_kind_of_contrib := 'D';
13973 END IF;
13974 
13975 Hr_Utility.set_location('value of kind of contribution : '||l_kind_of_contrib,10);
13976 p_data_element_value := l_kind_of_contrib;
13977 g_fur_contrib_kind := l_kind_of_contrib;
13978 RETURN 0;
13979 
13980 EXCEPTION
13981    WHEN Others THEN
13982     p_error_message :='SQL-ERRM :'||SQLERRM;
13983     Hr_Utility.set_location('..'||p_error_message,15);
13984     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
13985     RETURN -1;
13986 
13987 END Get_Fur_Contribution_Kind;
13988 
13989 --=============================================================================
13990 --Function to return the kind of insurance between IPAP and ANW
13991 --=============================================================================
13992 FUNCTION Get_Ins_Cd_Anw_Ipap
13993       (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
13994       ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
13995       ,p_effective_date       IN  Date
13996       ,p_error_message        OUT NOCOPY Varchar2
13997       ,p_data_element_value   OUT NOCOPY Varchar2
13998       ) RETURN Number IS
13999 
14000 l_proc_name Varchar2(30) := 'Get_Ins_Cd_Anw_Ipap';
14001 j number;
14002 
14003 BEGIN
14004    Hr_Utility.set_location('Entering    : '||l_proc_name,10);
14005 
14006    j := l_rec_31_values.FIRST;
14007    IF l_rec_31_values.EXISTS(j) THEN
14008       p_data_element_value := l_rec_31_values(j).code;
14009       g_ins_cd_anw_ipap    := l_rec_31_values(j).code;
14010    END IF;
14011    Hr_Utility.set_location('Leaving : '||l_proc_name,20);
14012    RETURN 0;
14013 
14014 EXCEPTION
14015    WHEN Others THEN
14016    p_error_message :='SQL-ERRM :'||SQLERRM;
14017    Hr_Utility.set_location('..'||p_error_message,15);
14018    Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
14019    RETURN -1;
14020 END Get_Ins_Cd_Anw_Ipap;
14021 
14022 --============================================================================
14023 --Function to return the type of insurance between IPAP and ANW
14024 --depending on the kind of insurance
14025 --============================================================================
14026 FUNCTION Get_Ins_Typ_Anw_Ipap
14027           (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
14028            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
14029            ,p_effective_date       IN  Date
14030            ,p_error_message        OUT NOCOPY Varchar2
14031 	   ,p_data_element_value   OUT NOCOPY Varchar2
14032           ) RETURN Number IS
14033 
14034 --cursor to fetch the insurance type data from the assignment EIT
14035 CURSOR c_get_ins_type IS
14036 SELECT Substr(Nvl(aei_information5,'01'),0,2),Substr(Nvl(aei_information6,'01'),0,2)
14037   FROM per_assignment_extra_info
14038 WHERE  assignment_id = p_assignment_id
14039   AND  aei_information_category = 'NL_ABP_RI'
14040   AND  information_type = 'NL_ABP_RI'
14041   AND  p_effective_date BETWEEN Fnd_Date.canonical_to_date(aei_information1)
14042   AND  Fnd_Date.canonical_to_date(Nvl(aei_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)));
14043 
14044 l_proc_name Varchar2(30) := 'Get_Ins_Typ_Anw_Ipap';
14045 l_anw_type   Varchar2(2) := '01';
14046 l_ipap_type  Varchar2(2) := '01';
14047 
14048 BEGIN
14049 
14050 Hr_Utility.set_location('Entering    : '||l_proc_name,10);
14051 OPEN c_get_ins_type;
14052 FETCH c_get_ins_type INTO l_anw_type,l_ipap_type;
14053 CLOSE c_get_ins_type;
14054 Hr_Utility.set_location('anw ins type : '||l_anw_type,15);
14055 Hr_Utility.set_location('ipap ins type : '||l_ipap_type,17);
14056 Hr_Utility.set_location('ins cd   : '||g_ins_cd_anw_ipap,19);
14057 
14058 IF g_ins_cd_anw_ipap = '01' THEN
14059    p_data_element_value := l_anw_type;
14060 ELSIF g_ins_cd_anw_ipap = '02' THEN
14061    p_data_element_value := l_ipap_type;
14062 END IF;
14063 RETURN 0;
14064 
14065 Hr_Utility.set_location('leaving --------------: '||l_proc_name,20);
14066 
14067 EXCEPTION
14068    WHEN Others THEN
14069     p_error_message :='SQL-ERRM :'||SQLERRM;
14070     Hr_Utility.set_location('..'||p_error_message,15);
14071     Hr_Utility.set_location('Leaving:-------- '||l_proc_name, 20);
14072     RETURN -1;
14073 
14074 END Get_Ins_Typ_Anw_Ipap;
14075 
14076 --function to return the incidental worker status
14077 FUNCTION Get_Incidental_Worker
14078          (p_assignment_id   IN Number
14079          ,p_business_group_id IN Number
14080          ,p_effective_date    IN Date
14081          ,p_error_message      OUT NOCOPY Varchar2
14082          ,p_data_element_value OUT NOCOPY Varchar2
14083          ) RETURN Number IS
14084 
14085 --cursor to fetch the incidental worker status from the ASG EIT
14086 CURSOR c_get_incidental_wrkr IS
14087 SELECT Nvl(aei_information3,'0')
14088   FROM per_assignment_extra_info
14089 WHERE  information_type = 'NL_USZO_INFO'
14090   AND  aei_information_category = 'NL_USZO_INFO'
14091   AND  assignment_id = p_assignment_id
14092   AND  p_effective_date BETWEEN Fnd_Date.canonical_to_date(aei_information1)
14093   AND  Fnd_Date.canonical_to_date(Nvl(aei_information2,Fnd_Date.date_to_canonical(Hr_Api.g_eot)))
14094   AND  ROWNUM = 1;
14095 
14096 l_incidental_worker  Varchar2(1) := '0';
14097 
14098 BEGIN
14099    OPEN c_get_incidental_wrkr;
14100    FETCH c_get_incidental_wrkr INTO l_incidental_worker;
14101    IF c_get_incidental_wrkr%FOUND THEN
14102       p_data_element_value := l_incidental_worker;
14103       CLOSE c_get_incidental_wrkr;
14104    ELSE
14105       CLOSE c_get_incidental_wrkr;
14106       p_data_element_value := '0';
14107    END IF;
14108    RETURN 0;
14109 
14110 EXCEPTION
14111    WHEN Others THEN
14112     p_error_message :='SQL-ERRM :'||SQLERRM;
14113     p_data_element_value := '';
14114     RETURN -1;
14115 
14116 END Get_Incidental_Worker;
14117 
14118 --function to get the kind of employment from the UDT
14119 FUNCTION Get_Employment_Kind
14120          (p_assignment_id  IN  Number
14121          ,p_business_group_id IN Number
14122          ,p_effective_date    IN Date
14123          ,p_error_message     OUT NOCOPY Varchar2
14124          ,p_data_element_value OUT NOCOPY Varchar2
14125          ) RETURN Number IS
14126 
14127 --cursor to fetch the kind of employment code
14128 --from the soft coding key flex
14129 CURSOR c_get_emp_code IS
14130 SELECT scl.SEGMENT2||scl.SEGMENT3
14131   FROM per_all_assignments_f asg
14132       ,hr_soft_coding_keyflex scl
14133 WHERE asg.assignment_id = p_assignment_id
14134   AND p_effective_date BETWEEN asg.effective_start_date
14135   AND asg.effective_end_date
14136   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
14137 
14138 l_emp_code Varchar2(120);
14139 l_emp_kind Varchar2(1);
14140 l_proc_name Varchar2(150) := 'Get_Employment_Kind';
14141 
14142 BEGIN
14143 
14144 Hr_Utility.set_location('Entering : '||l_proc_name,10);
14145 --first fetch the employment code from the soft coding keyflex
14146 OPEN c_get_emp_code;
14147 FETCH c_get_emp_code INTO l_emp_code;
14148 IF c_get_emp_code%FOUND THEN
14149    CLOSE c_get_emp_code;
14150    Hr_Utility.set_location('found the code as : '||l_emp_code,20);
14151    --now from the employment code,fetch the udt data for the value (as 1,2,3 etc)
14152    l_emp_kind := Hruserdt.get_table_value
14153                          (p_bus_group_id      => p_business_group_id
14154                          ,p_table_name        => 'NL_EMP_SUB_TYPE_CIB_KOA'
14155                          ,p_col_name          => 'USZO_KOA'
14156                          ,p_row_value         => l_emp_code
14157                          ,p_effective_date    => p_effective_date
14158                          );
14159 
14160    IF l_emp_kind IS NOT NULL THEN
14161       Hr_Utility.set_location('employment kind is : '||l_emp_kind,30);
14162       p_data_element_value := l_emp_kind;
14163    ELSE
14164       p_data_element_value := '';
14165    END IF;
14166 ELSE
14167    CLOSE c_get_emp_code;
14168    p_data_element_value := '';
14169 END IF;
14170 Hr_Utility.set_location('data element value is : '||p_data_element_value,40);
14171 Hr_Utility.set_location('Leaving : '||l_proc_name,50);
14172 RETURN 0;
14173 
14174 EXCEPTION
14175 
14176 WHEN NO_DATA_FOUND THEN
14177 p_data_element_value := '';
14178 RETURN 0;
14179 
14180 WHEN Others THEN
14181 p_error_message := SQLERRM;
14182 Hr_Utility.set_location('error message : '||SQLERRM,10);
14183 Hr_Utility.set_location('Leaving : '||l_proc_name,50);
14184 p_data_element_value := '';
14185 RETURN 1;
14186 
14187 END Get_Employment_Kind;
14188 
14189 -- ================================================================================
14190 -- Change_Date : The effective date for EE and ER Number changes
14191 -- ================================================================================
14192 
14193 FUNCTION Get_Change_Date
14194          (p_assignment_id      IN  NUMBER
14195          ,p_business_group_id  IN  NUMBER
14196          ,p_effective_date     IN  DATE
14197          ,p_error_message      OUT NOCOPY VARCHAR2
14198          ,p_data_element_value OUT NOCOPY VARCHAR2
14199          ) RETURN NUMBER IS
14200 
14201 CURSOR csr_get_dt (c_assignment_id   IN NUMBER) IS
14202 SELECT fnd_date.canonical_to_date(aei_information3)
14203   FROM per_assignment_extra_info
14204  WHERE assignment_id    = p_assignment_id
14205    AND information_type = 'PQP_NL_ABP_OLD_EE_INFO';
14206 
14207 l_return_value   NUMBER        := -1;
14208 l_proc_name      VARCHAR2(150) := 'Get_Change_Date';
14209 l_eff_dt         DATE;
14210 
14211 
14212 BEGIN
14213 
14214 Hr_Utility.set_location('Entering : '||l_proc_name,10);
14215 
14216 OPEN csr_get_dt(p_assignment_id);
14217    FETCH csr_get_dt INTO l_eff_dt;
14218 CLOSE csr_get_dt;
14219 
14220 p_data_element_value := Upper(nvl(TO_CHAR(l_eff_dt,'YYYYMMDD'),'00000000'));
14221 
14222 l_return_value := 0 ;
14223 
14224 Hr_Utility.set_location('l_return_value :       '||l_return_value,30);
14225 Hr_Utility.set_location('p_data_element_value : '||p_data_element_value,40);
14226 Hr_Utility.set_location('Leaving :              '||l_proc_name,50);
14227 
14228 RETURN l_return_value;
14229 
14230 END Get_Change_Date;
14231 
14232 -- ================================================================================
14233 -- ~ Sort_Id_Generator : It is concatenated with ernum+empNumber+record.
14234 -- ================================================================================
14235 FUNCTION Sort_Id_Generator
14236            (p_assignment_id       IN         Number
14237            ,p_business_group_id   IN         Number
14238            ,p_effective_date      IN         Date
14239 	   ,p_generator_record    IN         Varchar2
14240            ,p_error_message       OUT NOCOPY Varchar2
14241    	   ,p_data_element_value   OUT NOCOPY Varchar2
14242           ) RETURN Number IS
14243 
14244   l_temp_sort_id    Varchar2(50);
14245   l_proc_name       Varchar2(150) := g_proc_name ||'Sort_Id_Generator';
14246   l_employee_number per_all_people_f.Employee_number%TYPE;
14247   l_temp_person_id  per_all_people_f.Employee_number%TYPE;
14248    l_return_value    Number := -1;
14249   l_employer_number Number;
14250   l_asg_seq_num     Varchar2(2);
14251 
14252 BEGIN
14253   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
14254   -- Get the orgId for assigntment ID
14255   l_return_value := Get_ABP_ER_Num(p_assignment_id
14256                                  ,p_business_group_id
14257        			         ,p_effective_date
14258                                  ,'NEW'
14259 				 ,p_error_message
14260 				 ,p_data_element_value);
14261   l_employer_number := Nvl(p_data_element_value,9999999);
14262   l_employer_number := p_data_element_value;
14263   p_data_element_value :='';
14264 
14265   IF g_primary_assig.EXISTS(p_assignment_id) THEN
14266      l_employee_number := substr(g_primary_assig(p_assignment_id).ee_num,2);
14267   END IF;
14268 
14269    Hr_Utility.set_location('l_employee_number:   '||l_employee_number, 5);
14270    l_employer_number := Lpad(l_employer_number,9,0);
14271    l_employee_number :=	Lpad(l_employee_number,10,0);
14272    l_asg_seq_num     := g_primary_assig(p_assignment_id).asg_seq_num;
14273    IF To_Number(Nvl(l_asg_seq_num,'1')) < 10 THEN
14274 	  l_asg_seq_num := '0' ||Nvl(l_asg_seq_num,'1');
14275    END IF;
14276 
14277    p_data_element_value :=  l_employer_number ||
14278                             l_employee_number ||
14279 							l_asg_seq_num     ||
14280 							p_generator_record;
14281 
14282    Hr_Utility.set_location('p_data_element_value:   '||p_data_element_value, 5);
14283    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
14284    l_return_value := 0;
14285 
14286   RETURN l_return_value;
14287 EXCEPTION
14288    WHEN Others THEN
14289     p_error_message :='SQL-ERRM :'||SQLERRM;
14290     Hr_Utility.set_location('..'||p_error_message,85);
14291     RETURN l_return_value;
14292 END Sort_Id_Generator;
14293 
14294 -- =============================================================================
14295 -- Org_Id_DataElement
14296 -- =============================================================================
14297 
14298 FUNCTION Org_Id_DataElement
14299            (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
14300            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
14301            ,p_effective_date       IN  Date
14302            ,p_error_message        OUT NOCOPY Varchar2
14303 	   ,p_data_element_value   OUT NOCOPY Varchar2
14304           ) RETURN Number IS
14305 
14306   l_temp_sort_org              Varchar2(50);
14307   l_proc_name       Varchar2(150) := g_proc_name ||'Sort_Id_Generator';
14308   l_return_value    Number := -1;
14309 
14310 
14311 BEGIN
14312   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
14313 
14314    -- rpinjala
14315   IF g_primary_assig.EXISTS(p_assignment_id) THEN
14316      p_data_element_value := g_primary_assig(p_assignment_id).organization_id;
14317   END IF;
14318 
14319   l_return_value := 0;
14320   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
14321   RETURN l_return_value;
14322 EXCEPTION
14323    WHEN Others THEN
14324     p_error_message :='SQL-ERRM :'||SQLERRM;
14325     Hr_Utility.set_location('..'||p_error_message,85);
14326     RETURN l_return_value;
14327 END Org_Id_DataElement;
14328 
14329 -- =============================================================================
14330 -- Create_Addl_Assignments:
14331 -- =============================================================================
14332 PROCEDURE Create_Addl_Assignments
14333           (p_assignment_id     IN Number
14334           ,p_business_group_id IN Number
14335           ,p_person_id         IN Number
14336           ,p_no_asg_action     IN OUT NOCOPY Number
14337           ,p_error_message     OUT NOCOPY Varchar2)IS
14338 
14339    l_ele_type_id         pay_element_types_f.element_type_id%TYPE;
14340    l_prev_ele_type_id    pay_element_types_f.element_type_id%TYPE;
14341    l_valid_action        Varchar2(2);
14342    i                     per_all_assignments_f.business_group_id%TYPE;
14343    l_ext_dfn_type        pqp_extract_attributes.ext_dfn_type%TYPE;
14344    l_proc_name           Varchar2(150) := g_proc_name ||'Create_Addl_Assignments';
14345    l_assignment_id       per_all_assignments_f.assignment_id%TYPE;
14346    l_organization_id     per_all_assignments_f.organization_id%TYPE;
14347    l_business_group_id   per_all_assignments_f.business_group_id%TYPE;
14348    l_main_rec            csr_rslt_dtl%ROWTYPE;
14349    l_new_rec             csr_rslt_dtl%ROWTYPE;
14350    l_effective_date      Date;
14351    l_ext_rcd_id          ben_ext_rcd.ext_rcd_id%TYPE;
14352    l_record_num          Varchar2(20);
14353    l_return_value        Varchar2(2);
14354    l_last_name           per_all_people_f.last_name%TYPE;
14355    l_dob                 VARCHAR2(8);
14356    l_prefix              per_all_people_f.pre_name_adjunct%TYPE;
14357    l_national_ident      per_all_people_f.national_identifier%TYPE;
14358 
14359 CURSOR cur_per_info IS
14360 SELECT national_identifier
14361       ,UPPER(last_name)
14362       ,UPPER(pre_name_adjunct)
14363       ,TO_CHAR(date_of_birth,'YYYYMMDD')
14364  FROM per_all_people_f
14365 WHERE person_id = p_person_id
14366   AND g_extract_params(p_business_group_id).extract_end_date
14367       BETWEEN effective_start_date AND effective_end_date ;
14368 
14369 BEGIN
14370    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
14371    i := p_business_group_id;
14372 
14373    FOR csr_rcd_rec IN csr_ext_rcd_id_hidden
14374                        (c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
14375    LOOP
14376       l_ext_rcd_id := csr_rcd_rec.ext_rcd_id;
14377 
14378      Hr_Utility.set_location('l_ext_rcd_id: '||l_ext_rcd_id, 5);
14379 
14380     --These are single processing reoords
14381     IF g_ext_rcds(l_ext_rcd_id).record_number  IN
14382       ('01','02','04','05','08','09','12','20',
14383        '21','22','30','31','40','41','41h')      THEN
14384 	    l_record_num := g_ext_rcds(l_ext_rcd_id).record_number;
14385         OPEN csr_rslt_dtl
14386                (c_person_id      => p_person_id
14387                ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
14388                ,c_ext_dtl_rcd_id => l_ext_rcd_id
14389                 );
14390         FETCH csr_rslt_dtl INTO l_main_rec;
14391 
14392         IF csr_rslt_dtl%NOTFOUND THEN
14393            -- The primary assignment does not have a valid record
14394            -- force the creation of the record based on the person information
14395            OPEN cur_per_info;
14396            FETCH cur_per_info INTO l_national_ident,l_last_name,l_prefix,l_dob;
14397            CLOSE cur_per_info;
14398 
14399            l_main_rec := NULL;
14400            l_main_rec.ext_rslt_id       := ben_ext_thread.g_ext_rslt_id;
14401            l_main_rec.business_group_id := p_business_group_id;
14402            l_main_rec.ext_rcd_id        := l_ext_rcd_id;
14403            l_main_rec.person_id         := p_person_id;
14404            l_main_rec.val_01            := l_record_num;
14405 
14406            IF l_record_num = '04' THEN
14407             l_main_rec.val_05 := l_national_ident;
14408            END IF;
14409 
14410            IF l_record_num = '02' THEN
14411             l_main_rec.val_05 := l_national_ident;
14412             l_main_rec.val_07 := l_last_name;
14413             l_main_rec.val_09 := l_prefix;
14414             l_main_rec.val_11 := l_dob;
14415            END IF;
14416 
14417            l_main_rec.ext_per_bg_id       := p_business_group_id;
14418            l_main_rec.request_id          := fnd_global.conc_request_id;
14419            l_main_rec.program_id          := fnd_global.conc_program_id;
14420            l_main_rec.program_update_date := SYSDATE;
14421            l_main_rec.scnd_sort_val       := 0;
14422            l_main_rec.thrd_sort_val       := 0;
14423            l_main_rec.trans_seq_num       := 1;
14424            l_main_rec.rcrd_seq_num        := 1;
14425 
14426         END IF;
14427 
14428         CLOSE csr_rslt_dtl;
14429 
14430         l_main_rec.object_version_NUMBER
14431                             := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
14432         l_new_rec           := l_main_rec;
14433         l_assignment_id     := p_assignment_id;
14434         l_organization_id   := g_primary_assig(p_assignment_id).organization_id;
14435         l_business_group_id := p_business_group_id;
14436         l_effective_date    := Least(g_extract_params(i).extract_end_date,
14437                                      g_primary_assig(p_assignment_id).effective_end_date);
14438         l_return_value := Chk_If_Req_ToExtract
14439                           (p_assignment_id     => l_assignment_id
14440                           ,p_business_group_id => l_business_group_id
14441                           ,p_person_id         => p_person_id
14442                           ,p_effective_date    => l_effective_date
14443                           ,p_record_num        => l_record_num
14444                           ,p_error_message     => p_error_message);
14445 		IF l_return_value = 'Y' THEN
14446            -- Re-Process the person level rule based data-element for the record
14447            -- along with appropiate effective date and assignment id
14448            Process_Ext_Rslt_Dtl_Rec
14449             (p_assignment_id    => l_assignment_id
14450             ,p_organization_id  => l_organization_id
14451             ,p_effective_date   => l_effective_date
14452             ,p_ext_dtl_rcd_id   => l_ext_rcd_id
14453             ,p_rslt_rec         => l_main_rec
14454             ,p_asgaction_no     => p_no_asg_action
14455             ,p_error_message    => p_error_message);
14456 	    END IF; -- 	IF l_return_value = 'Y'
14457      END IF;
14458    END LOOP;
14459 
14460    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
14461 END Create_Addl_Assignments;
14462 
14463 -- =============================================================================
14464 -- Process_Addl_Assigs: Process all the assigs in the PL/SQL table for the
14465 -- person and create the records accordingly.
14466 -- =============================================================================
14467 FUNCTION Process_Addl_Assigs
14468            (p_assignment_id       IN         Number
14469            ,p_business_group_id   IN         Number
14470            ,p_effective_date      IN         Date
14471            ,p_error_message       OUT NOCOPY Varchar2
14472            ) RETURN Number IS
14473 
14474    l_return_value         Number;
14475    i                      per_all_assignments_f.business_group_id%TYPE;
14476    l_ele_type_id          pay_element_types_f.element_type_id%TYPE;
14477    l_prev_ele_type_id     pay_element_types_f.element_type_id%TYPE;
14478    l_valid_action         Varchar2(2);
14479    l_no_asg_action        Number(5) := 0;
14480    l_proc_name            Varchar2(150) := g_proc_name ||'Process_Addl_Assigs';
14481    l_sec_assg_rec         csr_sec_assg%ROWTYPE;
14482    l_effective_date       Date;
14483    l_criteria_value       Varchar2(2);
14484    l_warning_message      Varchar2(2000);
14485    l_error_message        Varchar2(2000);
14486    l_asg_type             per_all_assignments_f.assignment_type%TYPE;
14487    l_main_rec             csr_rslt_dtl%ROWTYPE;
14488    l_person_id            per_all_people_f.person_id%TYPE;
14489    l_assignment_id        per_all_assignments_f.assignment_id%TYPE;
14490    l_mutli_assig          Varchar2(150);
14491 BEGIN
14492 
14493    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
14494 
14495    l_mutli_assig := Check_Addl_Assigs
14496                      (p_assignment_id       => p_assignment_id
14497                      ,p_business_group_id   => p_business_group_id
14498                      ,p_effective_date      => p_effective_date
14499                      ,p_error_message       => p_error_message
14500                       );
14501 
14502    i := p_business_group_id;
14503    IF g_primary_assig.EXISTS(p_assignment_id) THEN
14504      l_person_id := g_primary_assig(p_assignment_id).person_id;
14505      l_asg_type  := g_primary_assig(p_assignment_id).assignment_type;
14506    END IF;
14507    -- For each assignment for this person id check if additional rows need to be
14508    -- created and re-calculate the person level based fast-formulas.
14509    l_assignment_id := g_primary_assig.FIRST;
14510    WHILE l_assignment_id IS NOT NULL
14511    LOOP
14512     Hr_Utility.set_location('..Checking for assignment : '||l_assignment_id, 7);
14513     IF g_primary_assig(l_assignment_id).person_id = l_person_id AND
14514 	   l_assignment_id <> p_assignment_id                       AND
14515        g_primary_assig(l_assignment_id).Assignment_Type = 'E' THEN
14516 
14517        Hr_Utility.set_location('..Valid Assignment : '||l_assignment_id, 8);
14518        Hr_Utility.set_location('..l_no_asg_action  : '||l_no_asg_action, 8);
14519 
14520          l_rec_09_values.delete;
14521 
14522        	 Populate_Record_Structures
14523          (p_assignment_id      => l_assignment_id
14524          ,p_effective_date     => LEAST(g_extract_params(i).extract_end_date,
14525                                         g_primary_assig(l_assignment_id).effective_end_date)
14526          ,p_business_group_id  => p_business_group_id
14527          ,p_error_message      => p_error_message );
14528 
14529        Create_Addl_Assignments
14530          (p_assignment_id     => l_assignment_id
14531          ,p_business_group_id => p_business_group_id
14532          ,p_person_id         => l_person_id
14533          ,p_no_asg_action     => l_no_asg_action
14534          ,p_error_message     => l_error_message
14535           );
14536        l_no_asg_action := l_no_asg_action + 1;
14537     END IF;
14538     l_assignment_id  := g_primary_assig.NEXT(l_assignment_id);
14539 
14540    END LOOP;
14541    IF l_asg_type = 'B' AND l_no_asg_action = 0 THEN
14542       -- =================================================================
14543       -- This mean that the extract created a row for the benefit's assig.
14544       -- record and that person does not have any employee assig. record
14545       -- within the extract date range specified.
14546       -- =================================================================
14547       FOR csr_rcd_rec IN csr_ext_rcd_id
14548                           (c_hide_flag   => 'N' -- N=No Y=Yes
14549    	                      ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
14550       -- Loop through each detail record for the extract
14551       LOOP
14552           OPEN csr_rslt_dtl
14553                 (c_person_id      => l_person_id
14554                 ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
14555                 ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id
14556                  );
14557           FETCH csr_rslt_dtl INTO l_main_rec;
14558           WHILE csr_rslt_dtl%FOUND
14559           LOOP
14560              -- Delete for each detail record for the person
14561              DELETE ben_ext_rslt_dtl
14562               WHERE ext_rslt_dtl_id = l_main_rec.ext_rslt_dtl_id
14563                 AND person_id       = l_person_id;
14564              FETCH csr_rslt_dtl INTO l_main_rec;
14565 
14566           END LOOP; -- While csr_rslt_dtl%FOUND
14567           CLOSE csr_rslt_dtl;
14568       END LOOP; -- FOR csr_rcd_rec
14569    END IF;
14570    -- Delete all the hidden Records for the person
14571    FOR csr_rcd_rec IN csr_ext_rcd_id
14572                       (c_hide_flag   => 'Y' -- N=No Y=Yes
14573                       ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
14574    -- Loop through each detail record for the extract
14575    LOOP
14576     OPEN csr_rslt_dtl
14577           (c_person_id      => l_person_id
14578           ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
14579           ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id
14580            );
14581     FETCH csr_rslt_dtl INTO l_main_rec;
14582     WHILE csr_rslt_dtl%FOUND
14583     LOOP
14584        -- Delete for each detail record for the person
14585        DELETE ben_ext_rslt_dtl
14586         WHERE ext_rslt_dtl_id = l_main_rec.ext_rslt_dtl_id
14587           AND person_id       = l_person_id;
14588        FETCH csr_rslt_dtl INTO l_main_rec;
14589     END LOOP; -- While csr_rslt_dtl%FOUND
14590     CLOSE csr_rslt_dtl;
14591    END LOOP; -- FOR csr_rcd_rec
14592 
14593    -- Once the sec. record has been taken care of all the asg actions
14594    -- remove it from the PL/SQL table.
14595    l_assignment_id := g_primary_assig.FIRST;
14596    WHILE l_assignment_id IS NOT NULL
14597    LOOP
14598     IF g_primary_assig(l_assignment_id).person_id = l_person_id THEN
14599        g_primary_assig.DELETE(l_assignment_id);
14600     END IF;
14601     l_assignment_id  := g_primary_assig.NEXT(l_assignment_id);
14602    END LOOP;
14603 
14604    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
14605    RETURN 0;
14606 
14607 EXCEPTION
14608    WHEN Others THEN
14609     p_error_message :='SQL-ERRM :'||SQLERRM;
14610     Hr_Utility.set_location('..'||p_error_message,85);
14611     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
14612     RETURN -1;
14613 END Process_Addl_Assigs;
14614 
14615 FUNCTION Process_Retro_Hire
14616            (p_assignment_id       IN         Number
14617            ,p_business_group_id   IN         Number
14618            ,p_effective_date      IN         Date
14619            ,p_error_message       OUT NOCOPY Varchar2
14620            ) RETURN Number IS
14621 
14622 BEGIN
14623 
14624 IF g_retro_hires.count > 0 THEN
14625    g_retro_hires.DELETE;
14626 END IF;
14627 
14628 RETURN 0;
14629 
14630 EXCEPTION
14631    WHEN Others THEN
14632     p_error_message :='SQL-ERRM :'||SQLERRM;
14633     Hr_Utility.set_location('..'||p_error_message,85);
14634     RETURN -1;
14635 END Process_Retro_Hire;
14636 
14637 -- =============================================================================
14638 -- Process_Mult_Records: For a given assignment multiple records are created for
14639 -- Records 05, 09, 12, 20, 21, 30, 31, 40 and 41. Addl. rows for the record are
14640 -- provided it satisfies the functional requirements for each record i.e. the
14641 -- record display criteria.
14642 -- =============================================================================
14643 FUNCTION Process_Mult_Records
14644            (p_assignment_id       IN         Number
14645            ,p_business_group_id   IN         Number
14646            ,p_effective_date      IN         Date
14647            ,p_error_message       OUT NOCOPY Varchar2
14648            )
14649 RETURN Number IS
14650   l_proc_name          Varchar2(150) := g_proc_name ||'Process_Mult_Records';
14651   l_data_element_value Varchar2(150);
14652   l_error_message      Varchar2(2000);
14653   l_error_flag         Boolean;
14654   l_ret_val            Number := 0;
14655 
14656 BEGIN
14657    Hr_Utility.set_location('Entering: '||l_proc_name, 4);
14658 
14659    -- Process Multiple Records for Record 05
14660    BEGIN
14661    l_ret_val := Process_Mult_Rec05
14662                 (p_assignment_id      => p_assignment_id
14663 	            ,p_business_group_id  => p_business_group_id
14664          		,p_effective_date     => p_effective_date
14665          		,p_error_message      => p_error_message
14666          		,p_data_element_value => l_data_element_value);
14667       g_rec05_rows.delete;
14668    Hr_Utility.set_location('..Processed Multi Recds for 05 : '||l_proc_name, 5);
14669    EXCEPTION
14670      WHEN Others THEN
14671       Hr_Utility.set_location('..Error in Multi Recds for 05 : '||l_proc_name, 5);
14672       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14673       l_error_flag    := TRUE;
14674    END;
14675    IF l_ret_val <> 0 THEN
14676       l_error_message := 'Error in Process Multi Record 05 for '||
14677                          'Assignment Id :'||p_assignment_id;
14678       l_error_flag    := TRUE;
14679    END IF;
14680 
14681 BEGIN
14682 
14683    l_ret_val := Process_Mult_Rec08
14684                 (p_assignment_id      => p_assignment_id
14685                 ,p_business_group_id  => p_business_group_id
14686                 ,p_effective_date     => p_effective_date
14687       		,p_error_message      => p_error_message
14688        		,p_data_element_value => l_data_element_value);
14689    Hr_Utility.set_location('..Processed Multi Recds for 08 : '||l_proc_name, 9);
14690    EXCEPTION
14691       WHEN Others THEN
14692       Hr_Utility.set_location('..Error in Multi Recds for 08 : '||l_proc_name, 9);
14693       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14694       l_error_flag    := TRUE;
14695    END;
14696    IF l_ret_val <> 0 THEN
14697       l_error_message := 'Error in Process Multi Record 08 for '||
14698                          'Assignment Id :'||p_assignment_id;
14699       l_error_flag    := TRUE;
14700    END IF;
14701 
14702    -- Process Multiple Records for Record 09
14703    BEGIN
14704    l_ret_val := Process_Mult_Rec09
14705                 (p_assignment_id      => p_assignment_id
14706                 ,p_business_group_id  => p_business_group_id
14707                 ,p_effective_date     => p_effective_date
14708        		,p_error_message      => p_error_message
14709        		,p_data_element_value => l_data_element_value);
14710    l_rec_09_values.delete;
14711 
14712    Hr_Utility.set_location('..Processed Multi Recds for 09 : '||l_proc_name, 9);
14713    EXCEPTION
14714       WHEN Others THEN
14715       Hr_Utility.set_location('..Error in Multi Recds for 09 : '||l_proc_name, 9);
14716       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14717       l_error_flag    := TRUE;
14718    END;
14719    IF l_ret_val <> 0 THEN
14720       l_error_message := l_error_message ||
14721                          'Error in Processing Multi Record 09 for '||
14722                          'Assignment Id :'||p_assignment_id ;
14723       l_error_flag    := TRUE;
14724    END IF;
14725 
14726    -- Process Multiple Records for Record 12
14727    BEGIN
14728    l_ret_val := Process_Mult_Rec12
14729                 (p_assignment_id      => p_assignment_id
14730                 ,p_business_group_id  => p_business_group_id
14731                 ,p_effective_date     => p_effective_date
14732       		,p_error_message      => p_error_message
14733        		,p_data_element_value => l_data_element_value);
14734    l_rec_12_values.delete;
14735    Hr_Utility.set_location('..Processed Multi Recds for 12 : '||l_proc_name, 12);
14736    EXCEPTION
14737       WHEN Others THEN
14738       Hr_Utility.set_location('..Error in Multi Recds for 12 : '||l_proc_name, 12);
14739       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14740       l_error_flag    := TRUE;
14741    END;
14742    IF l_ret_val <> 0 THEN
14743       l_error_message := l_error_message ||
14744                          'Error in Processing Multi Record 12 for '||
14745                          'Assignment Id :'||p_assignment_id ;
14746       l_error_flag    := TRUE;
14747    END IF;
14748 
14749    -- Process Multiple Records for Record 30
14750    BEGIN
14751    l_ret_val := Process_Mult_Rec30
14752                 (p_assignment_id      => p_assignment_id
14753                 ,p_business_group_id  => p_business_group_id
14754                 ,p_effective_date     => p_effective_date
14755                 ,p_error_message      => p_error_message
14756                 ,p_data_element_value => l_data_element_value);
14757    Hr_Utility.set_location('..Processed Multi Recds for 30 : '||l_proc_name, 30);
14758    EXCEPTION
14759       WHEN Others THEN
14760       Hr_Utility.set_location('..Error in Multi Recds for 30 : '||l_proc_name, 30);
14761       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14762       l_error_flag    := TRUE;
14763    END;
14764    IF l_ret_val <> 0 THEN
14765       l_error_message := l_error_message ||
14766                          'Error in Processing Multi Record 30 for '||
14767                          'Assignment Id :'||p_assignment_id ;
14768       l_error_flag    := TRUE;
14769    END IF;
14770 
14771    -- Process Multiple Records for Record 31
14772    BEGIN
14773    l_ret_val := Process_Mult_Rec31
14774                 (p_assignment_id      => p_assignment_id
14775                 ,p_business_group_id  => p_business_group_id
14776                 ,p_effective_date     => p_effective_date
14777                 ,p_error_message      => p_error_message
14778                 ,p_data_element_value => l_data_element_value);
14779    Hr_Utility.set_location('..Processed Multi Recds for 31 : '||l_proc_name, 31);
14780    EXCEPTION
14781       WHEN Others THEN
14782       Hr_Utility.set_location('..Error in Multi Recds for 31 : '||l_proc_name, 31);
14783       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14784       l_error_flag    := TRUE;
14785    END;
14786    IF l_ret_val <> 0 THEN
14787       l_error_message := l_error_message ||
14788                          'Error in Processing Multi Record 31 for '||
14789                          'Assignment Id :'||p_assignment_id ;
14790       l_error_flag    := TRUE;
14791    END IF;
14792 
14793    -- Process Multiple Records for Record 40
14794    BEGIN
14795    l_ret_val := Process_Mult_Rec40
14796                 (p_assignment_id      => p_assignment_id
14797 	               ,p_business_group_id  => p_business_group_id
14798          		     ,p_effective_date     => p_effective_date
14799          		     ,p_error_message      => p_error_message
14800          		     ,p_data_element_value => l_data_element_value);
14801    Hr_Utility.set_location('..Processed Multi Recds for 40 : '||l_proc_name, 40);
14802    EXCEPTION
14803       WHEN Others THEN
14804       Hr_Utility.set_location('..Error in Multi Recds for 40 : '||l_proc_name, 40);
14805       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14806       l_error_flag    := TRUE;
14807    END;
14808    IF l_ret_val <> 0 THEN
14809       l_error_message := l_error_message ||
14810                          'Error in Processing Multi Record 40 for '||
14811                          'Assignment Id :'||p_assignment_id ;
14812       l_error_flag    := TRUE;
14813    END IF;
14814 
14815    -- Process Multiple Records for Record 41
14816    BEGIN
14817    l_ret_val := Process_Mult_Rec41
14818                 (p_assignment_id      => p_assignment_id
14819 	         	     ,p_business_group_id  => p_business_group_id
14820          		     ,p_effective_date     => p_effective_date
14821          	      ,p_error_message      => p_error_message
14822          	      ,p_data_element_value => l_data_element_value);
14823    Hr_Utility.set_location('..Processed Multi Recds for 41 : '||l_proc_name, 41);
14824    EXCEPTION
14825       WHEN Others THEN
14826       Hr_Utility.set_location('..Error in Multi Recds for 41 : '||l_proc_name, 41);
14827       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
14828       l_error_flag    := TRUE;
14829    END;
14830    IF l_ret_val <> 0 THEN
14831       l_error_message := l_error_message ||
14832                          'Error in Processing Multi Record 41 for '||
14833                          'Assignment Id :'||p_assignment_id ;
14834       l_error_flag    := TRUE;
14835    END IF;
14836 
14837    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
14838    IF  l_error_flag THEN
14839        p_error_message := l_error_message;
14840        RETURN -1;
14841    ELSE
14842        RETURN 0;
14843    END IF;
14844 
14845 EXCEPTION
14846    WHEN Others THEN
14847     p_error_message :='SQL-ERRM :'||SQLERRM;
14848     Hr_Utility.set_location('..'||p_error_message,85);
14849     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
14850     RETURN -1;
14851 
14852 END Process_Mult_Records;
14853 
14854 -- =============================================================================
14855 -- PQP_NL_GET_DATA_ELEMENT_VALUE
14856 -- This function is used for all rule based data elements
14857 -- =============================================================================
14858 
14859 FUNCTION PQP_NL_Get_Data_Element_Value
14860  (  p_assignment_id      IN Number
14861    ,p_business_group_id  IN Number
14862    ,p_date_earned        IN Date
14863    ,p_data_element_cd    IN Varchar2
14864    ,p_error_message      OUT NOCOPY Varchar2
14865    ,p_data_element_value OUT NOCOPY Varchar2
14866  ) RETURN Number IS
14867 
14868 l_ret_val    Number;
14869 l_debug      Boolean;
14870 l_proc_name  Varchar2(150) := g_proc_name ||'PQP_NL_Get_Data_Element_Value';
14871 
14872 BEGIN
14873 
14874 l_ret_val := 0;
14875 
14876    Hr_Utility.set_location(' Entering :      ' || l_proc_name , 5);
14877    Hr_Utility.set_location(' p_assignment_id ' || p_assignment_id , 10);
14878    Hr_Utility.set_location(' p_bg_id is      ' || p_business_group_id ,15);
14879    Hr_Utility.set_location(' p_date_earned   ' || p_date_earned,20 );
14880    Hr_Utility.set_location(' p_data_ele_cd   ' || p_data_element_cd ,25);
14881    Hr_Utility.set_location(' g_person_id     ' || g_person_id , 30);
14882 
14883 IF (p_data_element_cd = 'ABP_ER_NUM') THEN
14884 
14885     l_ret_val := Get_ABP_ER_Num(p_assignment_id
14886                                ,p_business_group_id
14887                                ,p_date_earned
14888                                ,'NEW'
14889                                ,p_error_message
14890                                ,p_data_element_value);
14891     IF IsNumber(p_data_element_value) THEN
14892        p_data_element_value := Trim(To_Char(Fnd_Number.Canonical_To_Number
14893                                        (Nvl(p_data_element_value,'0'))
14894                        		            ,'0999999'));
14895     END IF;
14896 
14897 ELSIF (p_data_element_cd = 'PROCESS_MULTIPLE_REC41') THEN
14898     l_ret_val := Process_Mult_Records
14899                  (p_assignment_id       => p_assignment_id
14900                  ,p_business_group_id   => p_business_group_id
14901                  ,p_effective_date      => p_date_earned
14902                  ,p_error_message       => p_error_message
14903                   );
14904     p_data_element_value := 'PROCESSED';
14905 
14906 ELSIF (p_data_element_cd = 'EE_NUM') THEN
14907 
14908  l_ret_val := Get_EE_Num(p_assignment_id       => p_assignment_id
14909                         ,p_business_group_id   => p_business_group_id
14910                         ,p_effective_date      => p_date_earned
14911                         ,p_error_message       => p_error_message
14912                         ,p_data_element_value  => p_data_element_value);
14913 
14914 ELSIF (p_data_element_cd = 'OLD_ABP_ER_NUM') THEN
14915 
14916        l_ret_val := Get_ABP_ER_Num(p_assignment_id
14917                                   ,p_business_group_id
14918                                   ,p_date_earned
14919                                   ,'OLD'
14920                                   ,p_error_message
14921                                   ,p_data_element_value);
14922 
14923     IF p_data_element_value IS NOT NULL THEN
14924        IF IsNumber(p_data_element_value) THEN
14925           p_data_element_value := Trim(To_Char(Fnd_Number.Canonical_To_Number
14926                                           (p_data_element_value)
14927                           		            ,'0999999'));
14928        END IF;
14929     ELSE
14930        p_data_element_value := '0000000';
14931     END IF;
14932 
14933 ELSIF (p_data_element_cd = 'ASG_SEQ_NUM') THEN
14934 
14935        l_ret_val := Get_Asg_Seq_Num(p_assignment_id
14936                                    ,p_business_group_id
14937                                    ,p_date_earned
14938                                    ,p_error_message
14939                                    ,p_data_element_value);
14940 
14941 ELSIF (p_data_element_cd = 'OLD_ASG_SEQ_NUM') THEN
14942 
14943        l_ret_val := Get_Old_Asg_Seq_Num(p_assignment_id
14944                                    ,p_business_group_id
14945                                    ,p_date_earned
14946                                    ,p_error_message
14947                                    ,p_data_element_value);
14948 
14949 ELSIF (p_data_element_cd = 'OLD_EE_NUM') THEN
14950 
14951        l_ret_val := Get_Old_Ee_Num(p_assignment_id
14952                                    ,p_business_group_id
14953                                    ,p_date_earned
14954                                    ,p_error_message
14955                                    ,p_data_element_value);
14956 
14957 ELSIF (p_data_element_cd = 'PERSON_INITIALS') THEN
14958 
14959  l_ret_val := Get_Person_Initials(p_assignment_id
14960                                  ,p_business_group_id
14961                                  ,p_date_earned
14962                                  ,p_error_message
14963                                  ,p_data_element_value);
14964 
14965 ELSIF (p_data_element_cd = 'PARTNER_LAST_NAME') THEN
14966 
14967  l_ret_val := Get_Partner_Last_Name(p_assignment_id
14968                                    ,p_business_group_id
14969                                    ,p_date_earned
14970                                    ,p_error_message
14971                                    ,p_data_element_value);
14972 
14973 ELSIF (p_data_element_cd = 'GENDER') THEN
14974 
14975  l_ret_val := Get_Gender(p_assignment_id
14976                         ,p_business_group_id
14977                         ,p_date_earned
14978                         ,p_error_message
14979                         ,p_data_element_value);
14980 
14981 ELSIF (p_data_element_cd = 'CHANGE_CD_PER') THEN
14982 
14983 l_ret_val := GET_CHANGE_CD_PER(p_assignment_id
14984 				,p_business_group_id
14985 				,p_date_earned
14986 				,p_error_message
14987 				,p_data_element_value);
14988 
14989 ELSIF (p_data_element_cd = 'PARTNER_PREFIX') THEN
14990 
14991 l_ret_val := Get_Partner_Prefix(p_assignment_id
14992 				,p_business_group_id
14993 				,p_date_earned
14994 				,p_error_message
14995 				,p_data_element_value);
14996 
14997 ELSIF (p_data_element_cd = 'CHANGE_CD_ADDR') THEN
14998 
14999  l_ret_val := Get_Change_CD_Addr(p_assignment_id
15000 				,p_business_group_id
15001 				,p_date_earned
15002 				,p_error_message
15003 				,p_data_element_value);
15004 
15005 ELSIF (p_data_element_cd = 'STREET') THEN
15006 
15007        l_ret_val := Get_Street(p_assignment_id
15008 			    ,p_business_group_id
15009 			    ,p_date_earned
15010 			    ,p_error_message
15011 			    ,p_data_element_value);
15012 
15013 ELSIF (p_data_element_cd = 'HOUSE_NUM') THEN
15014 
15015        l_ret_val := Get_House_Num(p_assignment_id
15016 			    ,p_business_group_id
15017 			    ,p_date_earned
15018 			    ,p_error_message
15019 			    ,p_data_element_value);
15020 
15021 ELSIF (p_data_element_cd = 'ADDNL_HOUSE_NUM') THEN
15022 
15023 	 l_ret_val := Get_Addnl_House_Num(p_assignment_id
15024 			    ,p_business_group_id
15025 			    ,p_date_earned
15026 			    ,p_error_message
15027 			    ,p_data_element_value);
15028 
15029 ELSIF (p_data_element_cd = 'POSTAL_CODE') THEN
15030 
15031 	 l_ret_val := Get_Postal_Code(p_assignment_id
15032 			    ,p_business_group_id
15033 			    ,p_date_earned
15034 			    ,p_error_message
15035 			    ,p_data_element_value);
15036 
15037 ELSIF (p_data_element_cd = 'CITY') THEN
15038 
15039 	 l_ret_val := Get_City(p_assignment_id
15040 			    ,p_business_group_id
15041 			    ,p_date_earned
15042 			    ,p_error_message
15043 			    ,p_data_element_value);
15044 
15045 
15046 ELSIF (p_data_element_cd = 'FOREIGN_COUNTRY') THEN
15047 
15048 	 l_ret_val := Get_Foreign_Country(p_assignment_id
15049 			    ,p_business_group_id
15050 			    ,p_date_earned
15051 			    ,p_error_message
15052 			    ,p_data_element_value);
15053 
15054 ELSIF (p_data_element_cd = 'MARITAL_STATUS') THEN
15055 
15056 	 l_ret_val := Get_Marital_Status(p_assignment_id
15057 			    ,p_business_group_id
15058 			    ,p_date_earned
15059 			    ,p_error_message
15060 			    ,p_data_element_value);
15061 
15062 ELSIF (p_data_element_cd = 'PROCESS_MULTIPLE_ASSIGS') THEN
15063 
15064   l_ret_val := Process_Addl_Assigs
15065                (p_assignment_id       => p_assignment_id
15066                ,p_business_group_id   => p_business_group_id
15067                ,p_effective_date      => p_date_earned
15068                ,p_error_message       => p_error_message
15069                 );
15070   p_data_element_value := 'PROCESSED';
15071 
15072 ELSIF (p_data_element_cd = 'PROCESS_RETRO_HIRE') THEN
15073 
15074   l_ret_val := Process_Retro_Hire
15075                (p_assignment_id       => p_assignment_id
15076                ,p_business_group_id   => p_business_group_id
15077                ,p_effective_date      => p_date_earned
15078                ,p_error_message       => p_error_message
15079                 );
15080   p_data_element_value := 'PROCESSED';
15081 
15082 ELSIF (p_data_element_cd = 'CUMULATIVE_REP') THEN
15083    p_data_element_value := '  ';
15084 
15085 ELSIF (p_data_element_cd = 'R01_DISPLAY_CRITERIA') THEN
15086 
15087 	 l_ret_val := Record01_Display_Criteria(p_assignment_id
15088 			    ,p_business_group_id
15089 			    ,p_date_earned
15090 			    ,p_error_message
15091 			    ,p_data_element_value);
15092 
15093 ELSIF (p_data_element_cd = 'R02_DISPLAY_CRITERIA') THEN
15094 
15095 	 l_ret_val := Record02_Display_Criteria(p_assignment_id
15096 			    ,p_business_group_id
15097 			    ,p_date_earned
15098 			    ,p_error_message
15099 			    ,p_data_element_value);
15100 
15101 ELSIF (p_data_element_cd = 'R04_DISPLAY_CRITERIA') THEN
15102 
15103 	 l_ret_val := Record04_Display_Criteria(p_assignment_id
15104 			    ,p_business_group_id
15105 			    ,p_date_earned
15106 			    ,p_error_message
15107 			    ,p_data_element_value);
15108 
15109 ELSIF (p_data_element_cd = 'R05_DISPLAY_CRITERIA') THEN
15110 
15111 	 l_ret_val := Record05_Display_Criteria(p_assignment_id
15112 			    ,p_business_group_id
15113 			    ,p_date_earned
15114 			    ,p_error_message
15115 			    ,p_data_element_value);
15116 
15117 ELSIF (p_data_element_cd = 'R21_DISPLAY_CRITERIA') THEN
15118 
15119 	 l_ret_val := Record21_Display_Criteria(p_assignment_id
15120 			    ,p_business_group_id
15121 			    ,p_date_earned
15122 			    ,p_error_message
15123 			    ,p_data_element_value);
15124 
15125 ELSIF (p_data_element_cd = 'R22_DISPLAY_CRITERIA') THEN
15126 
15127 	 l_ret_val := Record22_Display_Criteria(p_assignment_id
15128 			    ,p_business_group_id
15129 			    ,p_date_earned
15130 			    ,p_error_message
15131 			    ,p_data_element_value);
15132 
15133 ELSIF (p_data_element_cd = 'R09_DISPLAY_CRITERIA') THEN
15134 	 l_ret_val := Record09_Display_Criteria(p_assignment_id
15135 			    ,p_business_group_id
15136 			    ,p_date_earned
15137 			    ,p_error_message
15138 			    ,p_data_element_value);
15139 
15140 ELSIF (p_data_element_cd = 'R12_DISPLAY_CRITERIA') THEN
15141 	 l_ret_val := Record12_Display_Criteria(p_assignment_id
15142 			    ,p_business_group_id
15143 			    ,p_date_earned
15144 			    ,p_error_message
15145 			    ,p_data_element_value);
15146 
15147 ELSIF (p_data_element_cd = 'R20_DISPLAY_CRITERIA') THEN
15148 	 l_ret_val := Record20_Display_Criteria(p_assignment_id
15149 			    ,p_business_group_id
15150 			    ,p_date_earned
15151 			    ,p_error_message
15152 			    ,p_data_element_value);
15153 
15154 ELSIF (p_data_element_cd = 'R40_DISPLAY_CRITERIA') THEN
15155 
15156 	 l_ret_val := Record30_40_Display_Criteria(p_assignment_id
15157 			    ,p_business_group_id
15158 			    ,p_date_earned
15159                 ,'FUR_S'
15160 			    ,p_error_message
15161 			    ,p_data_element_value);
15162 
15163 ELSIF (p_data_element_cd = 'R41_DISPLAY_CRITERIA') THEN
15164 
15165 	 l_ret_val := Record31_41_Display_Criteria(p_assignment_id
15166 			    ,p_business_group_id
15167 			    ,p_date_earned
15168                             ,41
15169 			    ,p_error_message
15170 			    ,p_data_element_value);
15171 
15172 ELSIF (p_data_element_cd = 'R30_DISPLAY_CRITERIA') THEN
15173 
15174 	 l_ret_val := Record30_40_Display_Criteria(p_assignment_id
15175 			    ,p_business_group_id
15176 			    ,p_date_earned
15177                 ,'IPAP'
15178 			    ,p_error_message
15179 			    ,p_data_element_value);
15180 
15181 ELSIF (p_data_element_cd = 'R31_DISPLAY_CRITERIA') THEN
15182 	 l_ret_val := Record31_41_Display_Criteria(p_assignment_id
15183 			    ,p_business_group_id
15184 			    ,p_date_earned
15185                             ,31
15186 			    ,p_error_message
15187 			    ,p_data_element_value);
15188 
15189 ELSIF (p_data_element_cd = 'PENSION_SALARY') THEN
15190 
15191 	 l_ret_val := Get_Pension_Salary(p_assignment_id
15192                             ,p_business_group_id
15193                             ,p_date_earned
15194                             ,'ABP Pension Salary'
15195                             , -1
15196                             ,p_error_message
15197                             ,p_data_element_value);
15198 
15199   IF IsNumber(p_data_element_value) THEN
15200      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
15201                                      (Nvl(p_data_element_value,'0')))
15202                      		            ,'0999999V99'));
15203   END IF;
15204 
15205 ELSIF (p_data_element_cd = 'SI_WAGES_TYPE') THEN
15206    -- Obselete SI data element
15207    p_data_element_value := NULL;
15208 
15209 ELSIF (p_data_element_cd = 'PEN_START_YEAR') THEN
15210 
15211   l_ret_val := Get_Pension_Start_Year(p_assignment_id
15212 			    ,p_business_group_id
15213 			    ,p_date_earned
15214 			    ,g_extract_params(p_business_group_id).extract_start_date
15215 			    ,g_extract_params(p_business_group_id).extract_end_date
15216 			    ,p_error_message
15217 			    ,p_data_element_value);
15218 
15219 ELSIF (p_data_element_cd = 'PEN_CONTRIBUTION_AMT_CD') THEN
15220 
15221   l_ret_val := Get_Contrib_Amt_Code(p_assignment_id
15222 			    ,p_business_group_id
15223 			    ,p_date_earned
15224                             ,12
15225 			    ,p_error_message
15226 			    ,p_data_element_value);
15227 
15228 
15229 ELSIF (p_data_element_cd = 'R08_DISPLAY_CRITERIA') THEN
15230 
15231 	 l_ret_val := Record08_Display_Criteria(p_assignment_id
15232 			    ,p_business_group_id
15233 			    ,p_date_earned
15234 			    ,p_error_message
15235 			    ,p_data_element_value);
15236 
15237 
15238 ELSIF (p_data_element_cd = 'PEXT_BASIS_CONTRIBUTION') THEN
15239 
15240 l_ret_val := Get_Sub_Cat_09(p_assignment_id
15241 			    ,p_business_group_id
15242 			    ,p_date_earned
15243 			    ,p_error_message
15244 			    ,p_data_element_value);
15245 
15246 ELSIF (p_data_element_cd = 'PEN_BASIS_AMT_CD') THEN
15247 
15248 l_ret_val := Get_Basis_Amt_Code(p_assignment_id
15249 			    ,p_business_group_id
15250 			    ,p_date_earned
15251                             ,9
15252 			    ,p_error_message
15253 			    ,p_data_element_value);
15254 
15255 ELSIF (p_data_element_cd = 'AMT_CD') THEN
15256 
15257 l_ret_val := Get_Basis_Amt_Code(p_assignment_id
15258 			    ,p_business_group_id
15259 			    ,p_date_earned
15260                             ,31
15261 			    ,p_error_message
15262 			    ,p_data_element_value);
15263 
15264 ELSIF (p_data_element_cd = 'PRINCIPAL_OBJN_CD') THEN
15265 
15266 l_ret_val := Get_Pri_Obj_Cd(p_assignment_id
15267 			    ,p_business_group_id
15268 			    ,p_date_earned
15269 			    ,p_error_message
15270 			    ,p_data_element_value);
15271 
15272 
15273 ELSIF (p_data_element_cd = 'ABP_PENSION_BASIS') THEN
15274 
15275 l_ret_val := Get_Basis_Amt(p_assignment_id
15276 			    ,p_business_group_id
15277 			    ,p_date_earned
15278                             ,9
15279 			    ,p_error_message
15280 			    ,p_data_element_value);
15281 
15282   IF IsNumber(p_data_element_value) THEN
15283      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
15284                                      (Nvl(p_data_element_value,'0')))
15285                      		            ,'0999999V99'));
15286   END IF;
15287 
15288 
15289 ELSIF (p_data_element_cd = 'PENSION_BASIS_YEAR') THEN
15290 
15291 l_ret_val := Get_Pension_Basis_Year(p_assignment_id
15292 			    ,p_business_group_id
15293                  	    ,p_date_earned
15294                             ,9
15295 			    ,p_error_message
15296 			    ,p_data_element_value);
15297 
15298    IF p_data_element_value IS NULL THEN
15299       p_data_element_value := '0000';
15300    END IF;
15301 
15302 ELSIF (p_data_element_cd = 'MONTH_CONTRIBUTION_BASE') THEN
15303 
15304 l_ret_val := Get_Month_Contribution_Base(p_assignment_id
15305 			    ,p_business_group_id
15306                  	    ,p_date_earned
15307                             ,9
15308 			    ,p_error_message
15309 			    ,p_data_element_value);
15310 
15311    IF p_data_element_value IS NULL THEN
15312       p_data_element_value := '00';
15313    END IF;
15314 
15315 ELSIF (p_data_element_cd = 'IPAP_CONTRIBUTION_AMT_YEAR') THEN
15316 
15317 l_ret_val := Get_Pension_Basis_Year(p_assignment_id
15318 			    ,p_business_group_id
15319                  	    ,p_date_earned
15320                             ,31
15321 			    ,p_error_message
15322 			    ,p_data_element_value);
15323 
15324 ELSIF (p_data_element_cd = 'IPAP_CONTRIBUTION_AMT_MONTH') THEN
15325 
15326 l_ret_val := Get_Month_Contribution_Base(p_assignment_id
15327 			    ,p_business_group_id
15328                  	    ,p_date_earned
15329                             ,31
15330 			    ,p_error_message
15331 			    ,p_data_element_value);
15332 
15333 ELSIF (p_data_element_cd = 'PRINCIPAL_SI_OBJ_CD') THEN
15334 
15335    p_data_element_value := ' ';
15336 
15337 ELSIF (p_data_element_cd = 'PROCESS_MUL_SUB_CAT_09') THEN
15338 
15339 l_ret_val := Process_Mult_Rec09
15340                 (p_assignment_id
15341 			    ,p_business_group_id
15342 			    ,p_date_earned
15343 			    ,p_error_message
15344 			    ,p_data_element_value);
15345 
15346 
15347 ELSIF (p_data_element_cd = 'CONTRIBUTION_AMOUNT') THEN
15348 
15349   l_ret_val := Get_Sub_Cat_12(p_assignment_id
15350 			    ,p_business_group_id
15351 			    ,p_date_earned
15352 			    ,p_error_message
15353 			    ,p_data_element_value);
15354 
15355 
15356 ELSIF (p_data_element_cd = 'ABP_DEDN_AMT') THEN
15357 
15358 l_ret_val := Get_Contribution_Amount(p_assignment_id
15359 			    ,p_business_group_id
15360 			    ,p_date_earned
15361                             ,12
15362 			    ,p_error_message
15363 			    ,p_data_element_value);
15364 
15365   IF IsNumber(p_data_element_value) THEN
15366      p_data_element_value :=Trim( To_Char(ABS(Fnd_Number.Canonical_To_Number
15367                                      (Nvl(p_data_element_value,'0')))
15368                      		            ,'0999999V99'));
15369   END IF;
15370 
15371 ELSIF (p_data_element_cd = 'SORT_ID_R01') THEN
15372 
15373 l_ret_val := Sort_Id_Generator(p_assignment_id
15374 			    ,p_business_group_id
15375 			    ,p_date_earned
15376 			    ,'01'
15377 			    ,p_error_message
15378 			    ,p_data_element_value);
15379 
15380 ELSIF (p_data_element_cd = 'SORT_ID_R02') THEN
15381 
15382 l_ret_val := Sort_Id_Generator(p_assignment_id
15383 			    ,p_business_group_id
15384 			    ,p_date_earned
15385 			    ,'02'
15386 			    ,p_error_message
15387 			    ,p_data_element_value);
15388 
15389 ELSIF (p_data_element_cd = 'SORT_ID_R04') THEN
15390 
15391 l_ret_val := Sort_Id_Generator(p_assignment_id
15392 			    ,p_business_group_id
15393 			    ,p_date_earned
15394 			    ,'04'
15395 			    ,p_error_message
15396 			    ,p_data_element_value);
15397 
15398 ELSIF (p_data_element_cd = 'SORT_ID_R05') THEN
15399 
15400 l_ret_val := Sort_Id_Generator(p_assignment_id
15401 			    ,p_business_group_id
15402 			    ,p_date_earned
15403 			    ,'05'
15404 			    ,p_error_message
15405 			    ,p_data_element_value);
15406 
15407 ELSIF (p_data_element_cd = 'SORT_ID_R08') THEN
15408 
15409 l_ret_val := Sort_Id_Generator(p_assignment_id
15410 			    ,p_business_group_id
15411 			    ,p_date_earned
15412 			    ,'08'
15413 			    ,p_error_message
15414 			    ,p_data_element_value);
15415 
15416 ELSIF (p_data_element_cd = 'SORT_ID_R09') THEN
15417 
15418 l_ret_val := Sort_Id_Generator(p_assignment_id
15419 			    ,p_business_group_id
15420 			    ,p_date_earned
15421 			    ,'09'
15422 			    ,p_error_message
15423 			    ,p_data_element_value);
15424 
15425 ELSIF (p_data_element_cd = 'SORT_ID_R12') THEN
15426 
15427 l_ret_val := Sort_Id_Generator(p_assignment_id
15428 			    ,p_business_group_id
15429 			    ,p_date_earned
15430 			    ,'12'
15431 			    ,p_error_message
15432 			    ,p_data_element_value);
15433 
15434 ELSIF (p_data_element_cd = 'SORT_ID_R20') THEN
15435 
15436 l_ret_val := Sort_Id_Generator(p_assignment_id
15437 			    ,p_business_group_id
15438 			    ,p_date_earned
15439 			    ,'20'
15440 			    ,p_error_message
15441 			    ,p_data_element_value);
15442 
15443 
15444 ELSIF (p_data_element_cd = 'SORT_ID_R21') THEN
15445 
15446 l_ret_val := Sort_Id_Generator(p_assignment_id
15447 			    ,p_business_group_id
15448 			    ,p_date_earned
15449 			    ,'21'
15450 			    ,p_error_message
15451 			    ,p_data_element_value);
15452 
15453 ELSIF (p_data_element_cd = 'SORT_ID_R22') THEN
15454 
15455 l_ret_val := Sort_Id_Generator(p_assignment_id
15456 			    ,p_business_group_id
15457 			    ,p_date_earned
15458 			    ,'22'
15459 			    ,p_error_message
15460 			    ,p_data_element_value);
15461 
15462 ELSIF (p_data_element_cd = 'SORT_ID_R22') THEN
15463 
15464 l_ret_val := Sort_Id_Generator(p_assignment_id
15465 			    ,p_business_group_id
15466 			    ,p_date_earned
15467 			    ,'22'
15468 			    ,p_error_message
15469 			    ,p_data_element_value);
15470 
15471 ELSIF (p_data_element_cd = 'SORT_ID_R30') THEN
15472 
15473 l_ret_val := Sort_Id_Generator(p_assignment_id
15474 			    ,p_business_group_id
15475 			    ,p_date_earned
15476 			    ,'30'
15477 			    ,p_error_message
15478 			    ,p_data_element_value);
15479 
15480 ELSIF (p_data_element_cd = 'SORT_ID_R31') THEN
15481 
15482 l_ret_val := Sort_Id_Generator(p_assignment_id
15483 			    ,p_business_group_id
15484 			    ,p_date_earned
15485 			    ,'31'
15486 			    ,p_error_message
15487 			    ,p_data_element_value);
15488 
15489 ELSIF (p_data_element_cd = 'SORT_ID_R40') THEN
15490 
15491 l_ret_val := Sort_Id_Generator(p_assignment_id
15492 			    ,p_business_group_id
15493 			    ,p_date_earned
15494 			    ,'40'
15495 			    ,p_error_message
15496 			    ,p_data_element_value);
15497 
15498 ELSIF (p_data_element_cd = 'SORT_ID_R41') THEN
15499 
15500 l_ret_val := Sort_Id_Generator(p_assignment_id
15501 			    ,p_business_group_id
15502 			    ,p_date_earned
15503 			    ,'41'
15504 			    ,p_error_message
15505 			    ,p_data_element_value);
15506 
15507 ELSIF (p_data_element_cd = 'HIDE_ORG_ID') THEN
15508 
15509 l_ret_val := Org_Id_DataElement(p_assignment_id
15510 			    ,p_business_group_id
15511 			    ,p_date_earned
15512 			    ,p_error_message
15513 			    ,p_data_element_value);
15514 
15515 ELSIF (p_data_element_cd = 'PENSION_BASIS') THEN
15516 
15517 l_ret_val := Get_Fur_Contribution_Kind(p_assignment_id
15518 			              ,p_business_group_id
15519 			              ,p_date_earned
15520 			              ,p_error_message
15521 			              ,p_data_element_value);
15522 
15523 ELSIF (p_data_element_cd = 'ADD_FEM_EMP') THEN
15524 
15525 l_ret_val := Get_Add_Fem_EE(p_assignment_id
15526                            ,p_business_group_id
15527                            ,p_date_earned
15528                            ,p_error_message
15529                            ,p_data_element_value);
15530 
15531 
15532 ELSIF (p_data_element_cd = 'ANW_IPAP_AMT') THEN
15533 
15534 l_ret_val := Get_Basis_Amt(p_assignment_id
15535 			    ,p_business_group_id
15536 			    ,p_date_earned
15537                             ,31
15538 			    ,p_error_message
15539 			    ,p_data_element_value);
15540 
15541   IF IsNumber(p_data_element_value) THEN
15542      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
15543                                      (Nvl(p_data_element_value,'0')))
15544                      		            ,'0999999V99'));
15545   END IF;
15546 
15547 ELSIF (p_data_element_cd = 'FUR_AMT') THEN
15548 
15549 IF g_fur_contrib_kind = 'A' THEN
15550 
15551   l_ret_val := Get_Basis_Amt(p_assignment_id
15552 			    ,p_business_group_id
15553 			    ,p_date_earned
15554                             ,41
15555 			    ,p_error_message
15556 			    ,p_data_element_value);
15557 
15558   IF IsNumber(p_data_element_value) THEN
15559      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
15560                                      (Nvl(p_data_element_value,'0')))
15561                      		            ,'0999999V99'));
15562   END IF;
15563 
15564 ELSIF g_fur_contrib_kind = 'D' THEN
15565 
15566 l_ret_val := Get_Contribution_Amount(p_assignment_id
15567 			    ,p_business_group_id
15568 			    ,p_date_earned
15569                             ,41
15570 			    ,p_error_message
15571 			    ,p_data_element_value);
15572 
15573   IF IsNumber(p_data_element_value) THEN
15574      p_data_element_value :=Trim( To_Char(ABS(Fnd_Number.Canonical_To_Number
15575                                      (Nvl(p_data_element_value,'0')))
15576                      		            ,'0999999V99'));
15577   END IF;
15578 
15579 END IF;
15580 
15581 ELSIF (p_data_element_cd = 'FUR_SI_WAGES_AMT_CD') THEN
15582 
15583 IF g_fur_contrib_kind = 'A' THEN
15584 
15585   l_ret_val := Get_Basis_Amt_Code(p_assignment_id
15586 			    ,p_business_group_id
15587 			    ,p_date_earned
15588                             ,41
15589 			    ,p_error_message
15590 			    ,p_data_element_value);
15591 ELSIF g_fur_contrib_kind = 'D' THEN
15592 
15593   l_ret_val := Get_Contrib_Amt_Code(p_assignment_id
15594 			    ,p_business_group_id
15595 			    ,p_date_earned
15596                             ,41
15597 			    ,p_error_message
15598 			    ,p_data_element_value);
15599 
15600 END IF;
15601 
15602 ELSIF (p_data_element_cd = 'FUR_CONTRIBUTION_AMT_MONTH') THEN
15603 
15604 IF g_fur_contrib_kind = 'A' THEN
15605 
15606   l_ret_val := Get_Month_Contribution_Base(p_assignment_id
15607 			    ,p_business_group_id
15608                  	    ,p_date_earned
15609                             ,41
15610 			    ,p_error_message
15611 			    ,p_data_element_value);
15612 ELSIF g_fur_contrib_kind = 'D' THEN
15613 
15614   l_ret_val := Get_Month_Contribution_Amt(p_assignment_id
15615 			    ,p_business_group_id
15616                  	    ,p_date_earned
15617                             ,41
15618 			    ,p_error_message
15619 			    ,p_data_element_value);
15620 
15621 END IF;
15622 
15623 ELSIF (p_data_element_cd = 'FUR_CONTRIBUTION_AMT_YEAR') THEN
15624 
15625 IF g_fur_contrib_kind = 'A' THEN
15626 
15627   l_ret_val := Get_Pension_Basis_Year(p_assignment_id
15628 			    ,p_business_group_id
15629                  	    ,p_date_earned
15630                             ,41
15631 			    ,p_error_message
15632 			    ,p_data_element_value);
15633 ELSIF g_fur_contrib_kind = 'D' THEN
15634 
15635   l_ret_val := Get_Year_Contribution_Amt(p_assignment_id
15636 			    ,p_business_group_id
15637                  	    ,p_date_earned
15638                             ,41
15639 			    ,p_error_message
15640 			    ,p_data_element_value);
15641 
15642 END IF;
15643 
15644 ELSIF (p_data_element_cd = 'CHANGE_DATE') THEN
15645 
15646      l_ret_val :=  Get_Change_Date
15647                    (p_assignment_id
15648                    ,p_business_group_id
15649                    ,p_date_earned
15650                    ,p_error_message
15651                    ,p_data_element_value);
15652 
15653 ELSIF (p_data_element_cd = 'WAO_CONTRIBUTION_CD') THEN
15654    --
15655    -- Obselete SI Data Element
15656    --
15657    p_data_element_value := ' ';
15658 
15659 ELSIF (p_data_element_cd = 'DISCOUNT_AGH') THEN
15660    --
15661    -- Obselete SI Data Element
15662    --
15663    p_data_element_value   := ' ';
15664 
15665 ELSIF (p_data_element_cd = 'SI_WAGES') THEN
15666 
15667    l_curr_si_rec := '21';
15668    -- Obselete SI data element
15669    p_data_element_value := NULL;
15670 
15671 ELSIF (p_data_element_cd = 'SI_WAGES_PMT_CD') THEN
15672    p_data_element_value := ' ';
15673 
15674 ELSIF (p_data_element_cd = 'CHANGE_DATE_PARTICIPATION_VALUE') THEN
15675 
15676  l_ret_val := Get_rec05_Participation
15677                 (p_assignment_id
15678                 ,p_business_group_id
15679                 ,'DT_CHG'
15680 	        ,p_date_earned
15681                 ,p_error_message
15682                 ,p_data_element_value);
15683 
15684    IF p_data_element_value IS NULL THEN
15685       p_data_element_value := '00000000';
15686    END IF;
15687 
15688 ELSIF (p_data_element_cd = 'PARTICIPATION_END_DT') THEN
15689 
15690 l_ret_val := Get_rec05_Participation
15691                 (p_assignment_id
15692 			    ,p_business_group_id
15693                 ,'EDDT_CHG'
15694 			    ,p_date_earned
15695 			    ,p_error_message
15696 			    ,p_data_element_value);
15697 
15698    IF p_data_element_value IS NULL THEN
15699       p_data_element_value := '00000000';
15700    END IF;
15701 
15702 ELSIF (p_data_element_cd = 'NEW_INSURANCE_END_DT') THEN
15703 
15704 l_ret_val := Get_Ipap_Participation_Dates
15705                 (p_assignment_id
15706 			    ,p_business_group_id
15707                 ,'NEW_ED'
15708 			    ,p_date_earned
15709 			    ,p_error_message
15710 			    ,p_data_element_value);
15711 
15712 ELSIF (p_data_element_cd = 'OLD_INSURANCE_END_DT') THEN
15713 
15714 l_ret_val := Get_Ipap_Participation_Dates
15715                 (p_assignment_id
15716 			    ,p_business_group_id
15717                 ,'OLD_ED'
15718 			    ,p_date_earned
15719 			    ,p_error_message
15720 			    ,p_data_element_value);
15721 
15722 ELSIF (p_data_element_cd = 'OLD_INSURANCE_FUR_END_DT') THEN
15723 
15724 l_ret_val := Get_Fur_Participation_Dates
15725                 (p_assignment_id
15726 			    ,p_business_group_id
15727                 ,'OLD_ED'
15728 			    ,p_date_earned
15729 			    ,p_error_message
15730 			    ,p_data_element_value);
15731 
15732 ELSIF (p_data_element_cd = 'NEW_FUR_INS_END_DT') THEN
15733 
15734 l_ret_val := Get_Fur_Participation_Dates
15735                 (p_assignment_id
15736 			    ,p_business_group_id
15737                 ,'NEW_ED'
15738 			    ,p_date_earned
15739 			    ,p_error_message
15740 			    ,p_data_element_value);
15741 
15742 ELSIF (p_data_element_cd = 'NEW_PARTICIPATION_END_DT') THEN
15743 
15744 l_ret_val := Get_rec05_Participation
15745             (p_assignment_id
15746 	    ,p_business_group_id
15747             ,'NEW_ED'
15748 	    ,p_date_earned
15749 	    ,p_error_message
15750 	    ,p_data_element_value);
15751 
15752 IF p_data_element_value IS NULL THEN
15753    p_data_element_value := '00000000';
15754 END IF;
15755 
15756 ELSIF (p_data_element_cd = 'OLD_PARTICIPATION_END_DT') THEN
15757 
15758 l_ret_val := Get_rec05_Participation
15759                (p_assignment_id
15760                ,p_business_group_id
15761                ,'OLD_ED'
15762                ,p_date_earned
15763 	       ,p_error_message
15764                ,p_data_element_value);
15765 
15766 IF p_data_element_value IS NULL THEN
15767    p_data_element_value := '00000000';
15768 END IF;
15769 
15770 ELSIF (p_data_element_cd = 'ASG_ST_DT_NEW') THEN
15771    -- Obselete SI Data Element
15772    p_data_element_value := '00000000';
15773 
15774 ELSIF (p_data_element_cd = 'ASG_START_DATE_OLD') THEN
15775    -- Obselete SI Data Element
15776    p_data_element_value := '00000000';
15777 
15778 ELSIF (p_data_element_cd = 'ASG_END_DATE_OLD') THEN
15779    -- Obselete SI Data Element
15780    p_data_element_value := '00000000';
15781 
15782 ELSIF (p_data_element_cd = 'ASG_END_DT_NEW') THEN
15783    -- Obselete SI Data Element
15784    p_data_element_value := '00000000';
15785 
15786 ELSIF (p_data_element_cd = 'SI_END_DT') THEN
15787    -- Obselete SI Data Element
15788    p_data_element_value := '00000000';
15789 
15790 ELSIF (p_data_element_cd = 'ASG_TYPE_CODE') THEN
15791   l_ret_val := Get_Employment_Kind
15792                (p_assignment_id
15793 	       ,p_business_group_id
15794                 ,p_date_earned
15795 	       ,p_error_message
15796 	      ,p_data_element_value);
15797 
15798 ELSIF (p_data_element_cd = 'INCIDENTAL_WORKER') THEN
15799   l_ret_val := Get_Incidental_Worker
15800                (p_assignment_id
15801 	       ,p_business_group_id
15802                 ,p_date_earned
15803 	       ,p_error_message
15804 	      ,p_data_element_value);
15805 
15806 ELSIF (p_data_element_cd = 'WAO_INSURED_CD') THEN
15807    -- Obselete SI data element
15808    p_data_element_value := NULL;
15809 
15810 ELSIF (p_data_element_cd = 'WW_INSURED_CD') THEN
15811    -- Obselete SI data element
15812    p_data_element_value := NULL;
15813 
15814 ELSIF (p_data_element_cd = 'ZFW_INSURED_CD') THEN
15815    -- Obselete SI data element
15816    p_data_element_value := NULL;
15817 
15818 ELSIF (p_data_element_cd = 'ZW_INSURED_CD') THEN
15819    -- Obselete SI data element
15820    p_data_element_value := NULL;
15821 
15822 ELSIF (p_data_element_cd = 'INSURANCE_TYPE') THEN
15823  l_ret_val := Get_Ins_Typ_Anw_Ipap
15824                 (p_assignment_id
15825 			    ,p_business_group_id
15826 			    ,p_date_earned
15827 			    ,p_error_message
15828 			    ,p_data_element_value);
15829 
15830 ELSIF (p_data_element_cd = 'FPU_CONTRIBUTION') THEN
15831 
15832  l_ret_val := Get_rec05_Participation
15833                 (p_assignment_id
15834                 ,p_business_group_id
15835                 ,'FPU_KIND'
15836 	        ,p_date_earned
15837                 ,p_error_message
15838                 ,p_data_element_value);
15839 
15840 ELSIF (p_data_element_cd = 'PPP_PARTICIPATION') THEN
15841 
15842  l_ret_val := Get_rec05_Participation
15843                 (p_assignment_id
15844                 ,p_business_group_id
15845                 ,'PPP_KIND'
15846 	        ,p_date_earned
15847                 ,p_error_message
15848                 ,p_data_element_value);
15849 
15850 ELSIF (p_data_element_cd = 'INSURANCE_CD_ANW_IPAP') THEN
15851 
15852 l_ret_val := Get_Ins_Cd_Anw_Ipap
15853                 (p_assignment_id
15854 			    ,p_business_group_id
15855 			    ,p_date_earned
15856 			    ,p_error_message
15857 			    ,p_data_element_value);
15858 
15859 ELSIF (p_data_element_cd = 'OPNP_INDIVIDUAL_CD') THEN
15860 
15861  l_ret_val := Get_rec05_Participation
15862                 (p_assignment_id
15863                 ,p_business_group_id
15864                 ,'OPNP_KIND'
15865 	        ,p_date_earned
15866                 ,p_error_message
15867                 ,p_data_element_value);
15868 
15869 
15870 ELSIF (p_data_element_cd = 'PARTICIPATION_CD') THEN
15871 
15872 l_ret_val := Get_rec05_Participation
15873                 (p_assignment_id
15874 			    ,p_business_group_id
15875                 ,'P_KIND'
15876 			    ,p_date_earned
15877 			    ,p_error_message
15878 			    ,p_data_element_value);
15879 
15880 ELSIF (p_data_element_cd = 'MONTH_CONTRIBUTION_AMT') THEN
15881 l_ret_val := Get_Month_Contribution_Amt(p_assignment_id
15882 			    ,p_business_group_id
15883                  	    ,p_date_earned
15884                             ,12
15885 			    ,p_error_message
15886 			    ,p_data_element_value);
15887 
15888 IF p_data_element_value IS NULL THEN
15889       p_data_element_value := '00';
15890    END IF;
15891 
15892 ELSIF (p_data_element_cd = 'MONTH_SI_WAGES') THEN
15893   -- Obselete SI data element
15894   p_data_element_value := NULL;
15895 
15896 ELSIF (p_data_element_cd = 'SI_WAGES_AMT_CD') THEN
15897   -- Obselete SI data element
15898   p_data_element_value := NULL;
15899 
15900 ELSIF (p_data_element_cd = 'SI_DAYS_CD') THEN
15901 
15902    -- Obselete SI Data element
15903    p_data_element_value := NULL;
15904 
15905 
15906 ELSIF (p_data_element_cd = 'PART_TIME_FACTOR_4') THEN
15907 
15908 l_ret_val := Get_rec05_Participation
15909                 (p_assignment_id
15910 	        ,p_business_group_id
15911                 ,'PART_TIME_PERC'
15912 	        ,p_date_earned
15913 	        ,p_error_message
15914 	        ,p_data_element_value);
15915 
15916   IF IsNumber(p_data_element_value) THEN
15917      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
15918                                      (p_data_element_value))
15919                      		            ,'09999'));
15920   END IF;
15921 
15922 ELSIF (p_data_element_cd = 'PART_TIME_FACTOR_5') THEN
15923 
15924    p_data_element_value := '0';
15925 
15926 ELSIF (p_data_element_cd = 'SI_WAGE_PAYMENT_PERIOD') THEN
15927    -- Obselete data element
15928    p_data_element_value := '00';
15929 
15930 ELSIF (p_data_element_cd = 'PARTICIPATION_END_REASON') THEN
15931 l_ret_val := Get_rec05_Participation
15932                (p_assignment_id
15933                ,p_business_group_id
15934                ,'END_REASON'
15935                ,p_date_earned
15936                ,p_error_message
15937                ,p_data_element_value);
15938 
15939 ELSIF (p_data_element_cd = 'DISCOUNT_BASE_WAO') THEN
15940    -- Obselete data element
15941    p_data_element_value := NULL;
15942 
15943 ELSIF (p_data_element_cd = 'PARTICIP_ST_DT_ANW_IPAP') THEN
15944 
15945 l_ret_val := Get_Ipap_Participation_Dates
15946              (p_assignment_id
15947              ,p_business_group_id
15948              ,'NEW_ST'
15949 			 ,p_date_earned
15950 			 ,p_error_message
15951 			 ,p_data_element_value);
15952 
15953 ELSIF (p_data_element_cd = 'PARTICIP_ST_DT_FUR') THEN
15954 
15955 l_ret_val := Get_Fur_Participation_Dates
15956                 (p_assignment_id
15957 			    ,p_business_group_id
15958                 ,'NEW_ST'
15959 			    ,p_date_earned
15960 			    ,p_error_message
15961 			    ,p_data_element_value);
15962 
15963 ELSIF (p_data_element_cd = 'PARTICIP_ST_DT_OLD_FUR') THEN
15964    l_ret_val := Get_Fur_Participation_Dates
15965                (p_assignment_id
15966                ,p_business_group_id
15967                ,'OLD_ST'
15968                ,p_date_earned
15969                ,p_error_message
15970                ,p_data_element_value);
15971 
15972 ELSIF (p_data_element_cd = 'WAGES_SOCIAL_INS') THEN
15973 
15974    l_curr_si_rec := '22';
15975    -- Obselete SI data element
15976    p_data_element_value := NULL;
15977 
15978 ELSIF (p_data_element_cd = 'SI_DAYS') THEN
15979   -- Obselete SI data element
15980   p_data_element_value := NULL ;
15981 
15982 ELSIF (p_data_element_cd = 'PARTICIP_ST_DT_OLD_ANW_IPAP') THEN
15983 
15984 l_ret_val := Get_Ipap_Participation_Dates
15985                (p_assignment_id
15986                ,p_business_group_id
15987                ,'OLD_ST'
15988                ,p_date_earned
15989                ,p_error_message
15990                ,p_data_element_value);
15991 
15992 ELSIF (p_data_element_cd = 'NEW_PARTICIPATION_ST_DT') THEN
15993 
15994 l_ret_val := Get_rec05_Participation
15995                (p_assignment_id
15996                ,p_business_group_id
15997                ,'NEW_ST'
15998                ,p_date_earned
15999                ,p_error_message
16000                ,p_data_element_value);
16001 
16002 IF p_data_element_value IS NULL THEN
16003    p_data_element_value := '00000000';
16004 END IF;
16005 
16006 ELSIF (p_data_element_cd = 'OLD_PARTICIPATION_ST_DT') THEN
16007 
16008 l_ret_val := Get_rec05_Participation
16009                (p_assignment_id
16010                ,p_business_group_id
16011                ,'OLD_ST'
16012                ,p_date_earned
16013                ,p_error_message
16014                ,p_data_element_value);
16015 
16016 IF p_data_element_value IS NULL THEN
16017    p_data_element_value := '00000000';
16018 END IF;
16019 
16020 
16021 
16022 ELSIF (p_data_element_cd = 'SI_START_DATE') THEN
16023    -- Obselete SI Data Element
16024    p_data_element_value := '00000000';
16025 
16026 ELSIF (p_data_element_cd = 'PARTICIPATION_VALUE') THEN
16027 
16028 l_ret_val := Get_rec05_Participation
16029                (p_assignment_id
16030                ,p_business_group_id
16031                ,'P_VALUE'
16032                ,p_date_earned
16033                ,p_error_message
16034                ,p_data_element_value);
16035 
16036   IF IsNumber(p_data_element_value) THEN
16037      p_data_element_value := Trim(To_Char(ABS(Fnd_Number.Canonical_To_Number
16038                                      (Nvl(p_data_element_value,'0')))
16039                      		            ,'099'));
16040   END IF;
16041 
16042 ELSIF (p_data_element_cd = 'SI_WAGES_PAYMENT_YEAR') THEN
16043    -- Obselete SI data element
16044    p_data_element_value := '0000';
16045 
16046 ELSIF (p_data_element_cd = 'CONTRIBUTION_AMT_YEAR') THEN
16047 
16048 l_ret_val := Get_Year_Contribution_Amt(p_assignment_id
16049 			    ,p_business_group_id
16050                  	    ,p_date_earned
16051                             ,12
16052 			    ,p_error_message
16053 			    ,p_data_element_value);
16054 
16055 IF p_data_element_value IS NULL THEN
16056       p_data_element_value := '0000';
16057    END IF;
16058 
16059 ELSIF (p_data_element_cd = 'SI_WAGES_YEAR') THEN
16060    -- Obselete data element
16061    p_data_element_value := '0000';
16062 
16063 ELSIF (p_data_element_cd = 'TERM_REASON') THEN
16064    -- Obselete SI Data Element
16065    p_data_element_value := '';
16066 
16067 END IF;
16068 
16069    p_data_element_value := Upper(p_data_element_value);
16070 
16071 RETURN l_ret_val;
16072 
16073 EXCEPTION
16074    WHEN Others THEN
16075    p_error_message :='SQL-ERRM :'||SQLERRM;
16076    Hr_Utility.set_location('..'||p_error_message,85);
16077    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
16078    RETURN l_ret_val;
16079 END PQP_NL_GET_DATA_ELEMENT_VALUE;
16080 
16081 -- ===============================================================================
16082 -- ~ Get_Header_EMR_Number : Common function to get the Header Information
16083 -- ===============================================================================
16084 FUNCTION Get_Header_EMR_Number
16085          (p_org_id         IN NUMBER
16086 	 ,p_effective_date IN DATE
16087          ) RETURN VARCHAR2 IS
16088 
16089 --
16090 -- Cursor to get the ER number from the org level.
16091 --
16092 CURSOR csr_get_new_er_num(c_org_id         IN NUMBER
16093                          ,c_effective_date IN DATE) IS
16094 SELECT SUBSTR(NVL(org_information2,'-1'),0,7)
16095   FROM hr_organization_information
16096  WHERE org_information_context = 'PQP_ABP_PROVIDER'
16097    AND organization_id         = c_org_id;
16098 
16099 l_proc_name    VARCHAR2(150) := g_proc_name ||'.Get_Header_EMR_Number';
16100 l_new_er_num   VARCHAR(7)    := '0';
16101 
16102 BEGIN
16103 
16104    hr_utility.set_location('Entering: '||l_proc_name, 5);
16105 
16106     OPEN csr_get_new_er_num(p_org_id,p_effective_date);
16107    FETCH csr_get_new_er_num INTO l_new_er_num;
16108    CLOSE csr_get_new_er_num;
16109 
16110    hr_utility.set_location('Leaving: '||l_proc_name, 45);
16111 
16112   RETURN l_new_er_num;
16113 
16114 EXCEPTION
16115   WHEN Others THEN
16116      hr_utility.set_location('Exception Others Raised at Get_Header_Information',40);
16117      hr_utility.set_location('Leaving: '||l_proc_name, 45);
16118      RETURN -1;
16119 END Get_Header_EMR_Number;
16120 
16121 -- ===============================================================================
16122 -- ~ Get_Header_Submit_Code : Function to get the submitter identification code
16123 -- ===============================================================================
16124 FUNCTION Get_Header_Submit_Code
16125            (p_org_id IN Number
16126            ) RETURN Varchar2 IS
16127 
16128 
16129  CURSOR csr_get_submit_code IS
16130 SELECT Substr(org_information3,0,4)
16131   FROM hr_organization_information
16132 WHERE org_information_context = 'PQP_ABP_PROVIDER'
16133   AND organization_id = p_org_id;
16134 
16135 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Header_Submit_Code';
16136 l_submit_code Varchar(4)  := '';
16137 BEGIN
16138    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
16139 
16140    OPEN csr_get_submit_code;
16141    FETCH csr_get_submit_code INTO l_submit_code;
16142    CLOSE csr_get_submit_code;
16143 
16144    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16145   RETURN l_submit_code;
16146 EXCEPTION
16147   WHEN Others THEN
16148      Hr_Utility.set_location('Exception Others Raised at Get_Submitter_code',40);
16149      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16150      RETURN -1;
16151 END Get_Header_Submit_Code;
16152 
16153 -- ===============================================================================
16154 -- ~ Get_Header_Information : Common function to get the Header Information
16155 -- ===============================================================================
16156 FUNCTION Get_Header_Information
16157            (p_header_type IN Varchar2
16158            ,p_error_message OUT NOCOPY Varchar2) RETURN Varchar2 IS
16159 
16160 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Header_Information';
16161 l_return_value   Varchar2(1000);
16162 l_new_er_num Varchar(4);
16163 
16164 
16165 BEGIN
16166 
16167    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
16168    IF p_header_type = 'HEADER_FILE_SUB_PERIOD' THEN
16169         l_return_value :=  To_Char(Fnd_Date.canonical_to_date(Fnd_Date.date_to_canonical(g_conc_prog_details(0).beginningdt)),'YYYYMM');
16170    ELSIF p_header_type = 'HEADER_SUB_IDEN' THEN
16171        l_return_value := g_conc_prog_details(0).orgname;
16172    ELSIF p_header_type = 'HEADER_EMR_REG_NUM' THEN
16173        l_new_er_num :=Get_Header_Submit_Code(g_conc_prog_details(0).orgid);
16174        l_return_value := l_new_er_num;
16175        IF IsNumber(l_return_value) THEN
16176           l_return_value := Trim(To_Char(Fnd_Number.Canonical_To_Number
16177 		                             (Nvl(l_return_value,'0'))
16178 		                           ,'0999'));
16179        END IF;
16180 
16181    END IF;
16182 
16183    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16184 
16185   RETURN l_return_value;
16186 EXCEPTION
16187   WHEN Others THEN
16188      p_error_message :='SQL-ERRM :'||SQLERRM;
16189      Hr_Utility.set_location('..Exception Others Raised at Get_Header_Information'||p_error_message,40);
16190      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16191      RETURN l_return_value;
16192 END Get_Header_Information;
16193 
16194 
16195 -- ===============================================================================
16196 -- ~ Get_Trailer_Amount_Sign : This is used to decide the sgn
16197 -- ===============================================================================
16198 FUNCTION Get_Trailer_Amount_Sign
16199            (p_amount IN Number
16200            ) RETURN Varchar2 IS
16201 
16202  CURSOR csr_get_sign(c_amount	  IN Number) IS
16203     SELECT Sign(c_amount)
16204     FROM  dual;
16205 
16206 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Trailer_Amount_Sign';
16207 l_sing_number   Number  := 0;
16208 l_temp          Number;
16209 
16210 BEGIN
16211    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
16212    IF p_amount IS NOT NULL THEN
16213       OPEN csr_get_sign(p_amount);
16214       FETCH csr_get_sign INTO l_temp;
16215       CLOSE csr_get_sign;
16216       IF l_temp = -1 THEN
16217 	RETURN 'C';
16218       ELSE
16219 	 RETURN ' ';
16220       END IF;
16221     END IF;
16222    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16223   RETURN ' ';
16224 EXCEPTION
16225   WHEN Others THEN
16226      Hr_Utility.set_location('Exception Others Raised at Get_Header_Information',40);
16227      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16228      RETURN ' ';
16229 END Get_Trailer_Amount_Sign;
16230 
16231 -- ===============================================================================
16232 -- ~ Get_All_Records_Count : This is used to calculate the record count
16233 -- ===============================================================================
16234 FUNCTION Get_All_Records_Count
16235          (p_rcd_1  IN NUMBER
16236          ,p_rcd_2  IN NUMBER
16237          ,p_emr_id IN NUMBER) RETURN NUMBER IS
16238 
16239  CURSOR csr_get_a_record_count(c_recordid_1 IN NUMBER
16240                               ,c_recordid_2 IN NUMBER
16241                               ,c_emr_id     IN NUMBER ) IS
16242    SELECT Count(dtl.ext_rslt_dtl_id)
16243      FROM ben_ext_rslt_dtl dtl
16244     WHERE dtl.ext_rslt_id = ben_ext_thread.g_ext_rslt_id
16245       AND ext_rcd_id NOT IN(c_recordid_1,c_recordid_2)
16246       AND val_25 = c_emr_id;
16247 
16248 l_proc_name    VARCHAR2(150) := g_proc_name ||'.Get_All_Records_Count';
16249 l_record_count NUMBER        := 0;
16250 
16251 BEGIN
16252 
16253 Hr_Utility.set_location('Entering: '||l_proc_name, 5);
16254 
16255  OPEN csr_get_a_record_count(p_rcd_1,p_rcd_2,p_emr_id);
16256 FETCH csr_get_a_record_count INTO l_record_count;
16257 CLOSE csr_get_a_record_count;
16258 
16259 Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16260 
16261 RETURN l_record_count;
16262 
16263 EXCEPTION
16264 WHEN OTHERS THEN
16265    Hr_Utility.set_location('Exception Others Raised at Get_Header_Information',40);
16266    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16267    RETURN -1;
16268 END Get_All_Records_Count;
16269 
16270 -- ===============================================================================
16271 -- ~ Get_Trailer_Record_Count : This is used to calculate the record count
16272 -- ===============================================================================
16273 FUNCTION Get_Trailer_Record_Count
16274            (p_rcd_1 IN Number
16275 	   ,p_rcd_2 IN Number
16276 	   ,p_rcd_3 IN Number
16277 	   ,p_emr_id IN Number
16278            ) RETURN Number IS
16279 
16280  CURSOR csr_get_record_count(c_recordid_1 IN Number
16281                             ,c_recordid_2 IN Number
16282 			    ,c_recordid_3 IN Number
16283 			    ,c_emr_id IN Number ) IS
16284    SELECT Count(dtl.ext_rslt_dtl_id)
16285      FROM ben_ext_rslt_dtl dtl
16286     WHERE dtl.ext_rslt_id = Ben_Ext_Thread.g_ext_rslt_id
16287      AND ext_rcd_id IN(c_recordid_1,c_recordid_2,c_recordid_3)
16288      AND val_25=c_emr_id;
16289 
16290 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Trailer_Record_Count';
16291 l_record_count Number  := 0;
16292 BEGIN
16293    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
16294    OPEN csr_get_record_count(p_rcd_1,p_rcd_2,p_rcd_3,p_emr_id);
16295    FETCH csr_get_record_count INTO l_record_count;
16296    CLOSE csr_get_record_count;
16297    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16298   RETURN l_record_count;
16299 EXCEPTION
16300   WHEN Others THEN
16301      Hr_Utility.set_location('Exception Others Raised at Get_Trailer_Record_Count',40);
16302      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
16303      RETURN -1;
16304 END Get_Trailer_Record_Count;
16305 
16306 -- ================================================================================
16307 -- ~ Sort_Post_Process : Post process logic
16308 -- ================================================================================
16309 FUNCTION Sort_Post_Process
16310           (p_business_group_id  ben_ext_rslt_dtl.business_group_id%TYPE
16311           )RETURN Number IS
16312 
16313 CURSOR csr_get_rslt(c_org_id         IN Varchar2
16314                    ,c_ext_rslt_id    IN Number ) IS
16315 SELECT DISTINCT(val_26) val_26
16316      FROM ben_ext_rslt_dtl dtl
16317     WHERE dtl.ext_rslt_id = c_ext_rslt_id
16318       AND val_25= c_org_id
16319       ORDER BY val_26 ASC ;
16320 
16321 CURSOR csr_get_rslt1(c_ext_rslt_id    IN Number ) IS
16322 SELECT val_25,val_26
16323      FROM ben_ext_rslt_dtl dtl
16324     WHERE dtl.ext_rslt_id = c_ext_rslt_id
16325       ORDER BY val_26 ASC ;
16326 
16327 CURSOR csr_rslt_dtl_sort(c_val_26         IN Varchar2
16328                         ,c_ext_rslt_id    IN Number ) IS
16329    SELECT *
16330      FROM ben_ext_rslt_dtl dtl
16331     WHERE dtl.ext_rslt_id = c_ext_rslt_id
16332     --  AND dtl.person_id   = c_person_id
16333       AND dtl.val_26      =c_val_26;
16334 
16335 
16336 
16337 CURSOR csr_get_header_rslt(c_ext_rslt_id    IN Number
16338    		          ,c_ext_dtl_rcd_id IN Number ) IS
16339    SELECT *
16340      FROM ben_ext_rslt_dtl dtl
16341     WHERE dtl.ext_rslt_id = c_ext_rslt_id
16342       AND ext_rcd_id= c_ext_dtl_rcd_id;
16343 
16344 
16345 CURSOR csr_get_trailer_rslt(c_ext_rslt_id    IN Number
16346 		           ,c_ext_dtl_rcd_id IN Number ) IS
16347 SELECT *
16348      FROM ben_ext_rslt_dtl dtl
16349     WHERE dtl.ext_rslt_id = c_ext_rslt_id
16350       AND ext_rcd_id= c_ext_dtl_rcd_id;
16351 
16352 -- Cursor to get the person existence flag
16353 CURSOR csr_get_person_exist(c_org_id IN Number) IS
16354 SELECT 'x'
16355   FROM  ben_ext_rslt_dtl
16356   WHERE ext_rslt_id=Ben_Ext_Thread.g_ext_rslt_id
16357   AND   val_25=c_org_id;
16358 
16359 --
16360 -- Cursor to get the record id for Rec 05
16361 --
16362  CURSOR csr_rcd_05_id IS
16363  SELECT rcd.ext_rcd_id,rin.seq_num
16364    FROM ben_ext_rcd         rcd
16365        ,ben_ext_rcd_in_file rin
16366        ,ben_ext_dfn dfn
16367   WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
16368     AND rin.ext_file_id  = dfn.ext_file_id
16369     AND rin.ext_rcd_id   = rcd.ext_rcd_id
16370     AND rin.seq_num = 5;
16371 
16372 --
16373 -- Cursor to get the records 05 rows that need to be deleted.
16374 --
16375 CURSOR csr_rec05_del (p_ext_rcd_id IN NUMBER) IS
16376 SELECT ext_rslt_dtl_id
16377   FROM ben_ext_rslt_dtl
16378  WHERE ext_rslt_id = Ben_Ext_Thread.g_ext_rslt_id
16379    AND ext_rcd_id = p_ext_rcd_id
16380    AND val_05 = '00000000'
16381    AND val_06 = '00000000'
16382    AND val_07 = '00000000'
16383    AND val_08 = '00000000'
16384    AND val_10 = '00000000'
16385    AND val_17 = '00000000'
16386    AND business_group_id = p_business_group_id;
16387 
16388 l_ext_dtl_rcd_id    ben_ext_rcd.ext_rcd_id%TYPE;
16389 l_ext_main_rcd_id   ben_ext_rcd.ext_rcd_id%TYPE;
16390 l_proc_name         Varchar2(150):=  g_proc_name||'Sort_Post_Process';
16391 l_return_value      Number := 0; --0= Sucess, -1=Error	;
16392 l_tmp_person_id     Number;
16393 l_tmp_org_id        Number;
16394 l_first_flag        Number  :=0;
16395 l_org_pram_id       hr_all_organization_units.organization_id%TYPE;
16396 l_temp_org_pram_id  hr_all_organization_units.organization_id%TYPE;
16397 l_org_detl          g_org_list%TYPE;
16398 l_org_index         Number :=1;
16399 l_global_contribution Number :=0;
16400 l_first_person_id   Number;
16401 l_main_rec          csr_rslt_dtl_sort%ROWTYPE;
16402 l_new_rec           csr_rslt_dtl_sort%ROWTYPE;
16403 l_header_main_rec   csr_get_header_rslt%ROWTYPE;
16404 l_header_new_rec    csr_get_header_rslt%ROWTYPE;
16405 l_trailer_main_rec  csr_get_trailer_rslt%ROWTYPE;
16406 l_trailer_new_rec   csr_get_trailer_rslt%ROWTYPE;
16407 sort_val            Number :=1;
16408 l_sort_val          Varchar2(15);
16409 l_org_count         Number :=0;
16410 l_header_er_num     Varchar2(4);
16411 l_trailer_er_num    Varchar2(7);
16412 l_org_name          hr_all_organization_units.NAME%TYPE;
16413 l_CodeA_R96_Contri  Number :=0;
16414 l_CodeD_R96_Contri  Number :=0;
16415 l_record96_count    Number :=0;
16416 l_record96_rcd_id   Number;
16417 l_R95_Contri        Number := 0;
16418 l_record95_count    Number := 0;
16419 l_R97_Contri        Number := 0;
16420 l_record97_count    Number := 0;
16421 l_R94_WA_Contri     Number := 0;
16422 l_R94_UF_Contri     Number := 0;
16423 l_R94_ZF_Contri     Number := 0;
16424 l_R94_SI_Contri     Number := 0;
16425 l_record94_count    Number := 0;
16426 l_R99_Yearly_Amount Number := 0;
16427 l_R99_OPNP_Contri   Number := 0;
16428 l_R99_IPbw_H_Contri Number := 0;
16429 l_R99_IPbw_L_Contri Number := 0;
16430 l_R99_Fpu_B_Contri  Number := 0;
16431 l_R99_Fpu_C_Contri  Number := 0;
16432 l_record99_count    Number := 0;
16433 l_00_inserted       Number := 0;
16434 l_insert_trailer    Number := 1;
16435 l_first_trailer_flag  Number :=0;
16436 l_Person_Exists  Varchar2(2);
16437 i Number := 0;
16438 l_R00_rslt_dtl_id  Number;
16439 l_R94_rslt_dtl_id  Number;
16440 l_R95_rslt_dtl_id  Number;
16441 l_R96_rslt_dtl_id  Number;
16442 l_R97_rslt_dtl_id  Number;
16443 l_R99_rslt_dtl_id  Number;
16444 l_ext_rslt_dtl_id  Number;
16445 l_count            Number := 0;
16446 l_employer_count   Number := 0;
16447 l_er_index         Number := 0;
16448 l_org_grp_index    Number := 0;
16449 l_group_org_index  Number := 0;
16450 l_employer_index   Number := 0;
16451 
16452 
16453 BEGIN
16454   Hr_Utility.set_location('Entering :---------'||l_proc_name, 5);
16455    -- Delete all the hidden Records
16456    FOR csr_rcd_rec IN csr_ext_rcd_id
16457                       (c_hide_flag   => 'Y' -- N=No Y=Yes
16458                       ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
16459    -- Loop through each detail record for the extract
16460    LOOP
16461        -- Delete all detail records for the record
16462        DELETE ben_ext_rslt_dtl
16463         WHERE ext_rcd_id        = csr_rcd_rec.ext_rcd_id
16464           AND ext_rslt_id       = Ben_Ext_Thread.g_ext_rslt_id
16465           AND business_group_id = p_business_group_id;
16466    END LOOP; -- FOR csr_rcd_rec
16467 
16468    --
16469    -- Delete all the Record 05's that are not necessary.
16470    --
16471    FOR csr_rcd_05_id_rec IN csr_rcd_05_id
16472    LOOP
16473       FOR csr_rec05_del_rec IN csr_rec05_del (csr_rcd_05_id_rec.ext_rcd_id)
16474       LOOP
16475          DELETE ben_ext_rslt_dtl
16476          WHERE ext_rslt_dtl_id = csr_rec05_del_rec.ext_rslt_dtl_id;
16477       END LOOP; -- FOR csr_rcd_05_id
16478    END LOOP; -- For csr_rec05_del
16479 
16480       -- All orgs,fill up the temp. table with the org ids in order of
16481       --the sort value
16482       FOR val IN csr_get_rslt1
16483                 (c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id )
16484       LOOP
16485          hr_utility.set_location('val 26 : '||val.val_26,10);
16486          IF g_org_list.EXISTS(val.val_25) THEN
16487             IF NOT g_ord_details1.EXISTS(val.val_25) THEN
16488                hr_utility.set_location('l_org_index : '||l_org_index,20);
16489                hr_utility.set_location('org : '||val.val_25,30);
16490                g_ord_details(l_org_index).gre_org_id := val.val_25;
16491                g_ord_details1(to_number(val.val_25)).gre_org_id := val.val_25;
16492                l_org_index := l_org_index + 1;
16493             END IF;
16494           END IF;
16495       END LOOP;
16496       -- Maintaining recordIds with record numbers in plsql table
16497        FOR rcd_dtls IN 	csr_ext_rcd_id_with_seq()
16498        LOOP
16499            IF rcd_dtls.hide_flag = 'N' THEN
16500               g_rcd_dtls(To_Number(rcd_dtls.rec_num)).ext_rcd_id := rcd_dtls.ext_rcd_id;
16501 	   END IF;
16502        END LOOP;
16503 
16504        l_org_count := g_ord_details.Count;
16505 
16506        --fetch the extract result id for the trailer records
16507        --these are ids for the records created automatically by
16508        --benefits, and they will be deleted in the end after we
16509        --create our own trailer records for each org based on these
16510        FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16511                                         ,c_rcd_type_cd => 'T')-- T-Trailer
16512        LOOP
16513 	  OPEN csr_get_trailer_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
16514                                    ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
16515   	  FETCH csr_get_trailer_rslt INTO l_trailer_main_rec;
16516 	  CLOSE csr_get_trailer_rslt;
16517           IF g_rcd_dtls(94).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16518              l_R94_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
16519           ELSIF g_rcd_dtls(95).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16520              l_R95_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
16521           ELSIF g_rcd_dtls(96).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16522              l_R96_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
16523           ELSIF g_rcd_dtls(97).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16524              l_R97_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
16525           ELSIF g_rcd_dtls(99).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16526              l_R99_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
16527           END IF;
16528        END LOOP;
16529 
16530        --find the dtl record id for the header record
16531        --since records need to be sorted by employer number, the default
16532        --header record created by benefits needs to be deleted later
16533        FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16534                                         ,c_rcd_type_cd => 'H')-- H-Header
16535        LOOP
16536 	  OPEN csr_get_header_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
16537                                    ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
16538   	  FETCH csr_get_header_rslt INTO l_header_main_rec;
16539 	  CLOSE csr_get_header_rslt;
16540           IF g_rcd_dtls(00).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16541              l_R00_rslt_dtl_id := l_header_main_rec.ext_rslt_dtl_id;
16542           END IF;
16543        END LOOP;
16544 
16545      	-- If there are no emps for next org in list of org
16546 	-- then no need to create the header
16547 	 /*OPEN csr_get_person_exist(g_conc_prog_details(0).orgid);
16548 	 FETCH csr_get_person_exist INTO l_Person_Exists;
16549 	 CLOSE csr_get_person_exist;
16550 	 IF l_Person_Exists = 'x' THEN*/
16551 
16552 	   --Loop through Header records
16553 	   FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16554                                                     ,c_rcd_type_cd => 'H')-- H-Header
16555 	   LOOP
16556   	       OPEN csr_get_header_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
16557  	                               ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
16558 	       FETCH csr_get_header_rslt INTO l_header_main_rec;
16559  	       CLOSE csr_get_header_rslt;
16560 	       l_header_new_rec :=  l_header_main_rec;
16561 	       l_sort_val := Lpad(sort_val,15,0);
16562 	       l_header_new_rec.prmy_sort_val := l_sort_val;
16563 	       --Updating the employer name and employer number
16564 	       l_header_er_num :=Get_Header_Submit_Code(g_conc_prog_details(0).orgid);
16565 
16566                 IF IsNumber(l_header_er_num) THEN
16567                           l_header_er_num := Trim(To_Char(Fnd_Number.Canonical_To_Number
16568                                             (Nvl(l_header_er_num,'0'))
16569 	                                     ,'0999'));
16570 
16571                 END IF;
16572 
16573 		OPEN  csr_org_name( c_org_id => g_conc_prog_details(0).orgid);
16574                 FETCH csr_org_name INTO l_org_name;
16575                 CLOSE csr_org_name;
16576 		l_header_new_rec.val_07 := l_org_name;
16577 		l_header_new_rec.val_08 := l_header_er_num;
16578 		l_header_new_rec.object_version_NUMBER :=  Nvl(l_header_new_rec.object_version_NUMBER,0) + 1;
16579 		sort_val :=sort_val+1;
16580 
16581                  -- Insert the header record only once for each extract
16582 		 IF l_00_inserted=0 THEN
16583 		      Ins_Rslt_Dtl(p_dtl_rec => l_header_new_rec);
16584                       l_00_inserted:=1;
16585                  END IF;
16586 	--	 l_Person_Exists := 'y';
16587 	    END LOOP;
16588 	  -- END IF;
16589 
16590 
16591       -- loop through all employers
16592       l_employer_count:=g_employer_list.COUNT;
16593       l_employer_index:=g_employer_list.FIRST;
16594       l_er_index:=0;
16595        Hr_Utility.set_location('l_employer_count --'||l_employer_count,20);
16596       WHILE l_employer_index IS NOT NULL
16597       LOOP
16598          --l_count Keeps track of total number of trailor records added per group
16599          l_count:=0;
16600 
16601          l_org_grp_index:=0;
16602 	-- for all orgs in the groups
16603 	 Hr_Utility.set_location('Grp count '||g_org_grp_list_cnt(l_employer_index).org_grp_count ,23);
16604         FOR l_org_count IN 1..g_org_grp_list_cnt(l_employer_index).org_grp_count
16605 	LOOP
16606 
16607 	 l_group_org_index:=l_er_index * 1000 + l_org_grp_index;
16608 	 Hr_Utility.set_location('Current Org Id:---------'||g_employer_child_list(l_group_org_index).gre_org_id, 25);
16609            -- Get all rows/persons for this orgid
16610        	   FOR val IN csr_get_rslt
16611 		     (c_org_id         => g_employer_child_list(l_group_org_index).gre_org_id
16612 		     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id )
16613 	   LOOP
16614 	          --Hr_Utility.set_location('val'||val.EXT_RSLT_DTL_ID ,26);
16615 		  -- Get the individual row using sortid key
16616 		  -- So we will get only one record related data per person
16617  	          FOR ind_dtl IN csr_rslt_dtl_sort
16618 		      (c_val_26		=> val.val_26
16619 		      ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
16620 		      )
16621 		  LOOP
16622 		    l_main_rec :=  ind_dtl;
16623 		    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
16624   		    l_new_rec := l_main_rec;
16625 		    l_sort_val:= Lpad(sort_val,15,0);
16626 		    l_new_rec.prmy_sort_val := l_sort_val;
16627 		    sort_val :=sort_val+1;
16628  		    Upd_Rslt_Dtl(p_dtl_rec => l_new_rec);
16629 
16630 		   -- Totaling Record 94  Processing
16631 		      -- Rrecord 21
16632 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(21).ext_rcd_id AND
16633 		        l_new_rec.val_01  = '21'
16634 		     THEN
16635 		       -- Checking SI Wages Type is WA,UF or ZF	(Seq 06)
16636 		       --Then getting the value of SI Wages ABP USZO(Seq 08)
16637 			 IF l_new_rec.val_06 ='WA'THEN
16638                           IF nvl(l_new_rec.val_09,' ') = 'C' THEN
16639 			     l_R94_WA_Contri:=l_R94_WA_Contri-Nvl(To_Number(l_new_rec.val_08),0);
16640                           ELSE
16641 			     l_R94_WA_Contri:=l_R94_WA_Contri+Nvl(To_Number(l_new_rec.val_08),0);
16642                           END IF;
16643 			 ELSIF l_new_rec.val_06 ='UF'THEN
16644                           IF nvl(l_new_rec.val_09,' ') = 'C' THEN
16645 			     l_R94_UF_Contri:=l_R94_UF_Contri-Nvl(To_Number(l_new_rec.val_08),0);
16646                           ELSE
16647 			     l_R94_UF_Contri:=l_R94_UF_Contri+Nvl(To_Number(l_new_rec.val_08),0);
16648                           END IF;
16649 			 ELSIF l_new_rec.val_06 ='ZF'THEN
16650                           IF nvl(l_new_rec.val_09,' ') = 'C' THEN
16651 			     l_R94_ZF_Contri:=l_R94_ZF_Contri-Nvl(To_Number(l_new_rec.val_08),0);
16652                           ELSE
16653 			     l_R94_ZF_Contri:=l_R94_ZF_Contri+Nvl(To_Number(l_new_rec.val_08),0);
16654                           END IF;
16655 			 END IF;
16656 		     END IF;
16657 		     -- Record 22
16658 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(22).ext_rcd_id AND
16659 		        l_new_rec.val_01  = '22'
16660 		     THEN
16661 			 --Getting the value of Social Insurance Wages ABP USZO(Seq 07)
16662                        IF nvl(l_new_rec.val_08,' ') = 'C' THEN
16663 			 l_R94_SI_Contri:=l_R94_SI_Contri-Nvl(To_Number(l_new_rec.val_07),0);
16664                        ELSE
16665 			 l_R94_SI_Contri:=l_R94_SI_Contri+Nvl(To_Number(l_new_rec.val_07),0);
16666                        END IF;
16667 		     END IF;
16668     		   -- End of Record 94
16669 
16670 		   -- Totaling Record 95 Processing
16671 		     -- Record 31
16672 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(31).ext_rcd_id AND
16673 		        l_new_rec.val_01  = '31'
16674 		     THEN
16675                        IF nvl(l_new_rec.val_08,' ') = 'C' THEN
16676  		           l_R95_Contri:=l_R95_Contri-Nvl(To_Number(l_new_rec.val_07),0);
16677                        ELSE
16678  		           l_R95_Contri:=l_R95_Contri+Nvl(To_Number(l_new_rec.val_07),0);
16679                        END IF;
16680 		     END IF;
16681 		   -- End of Record 95
16682 
16683 		    -- Totaling Record 96 Processing
16684 		     -- Record 41
16685 		    IF 	l_new_rec.ext_rcd_id = g_rcd_dtls(41).ext_rcd_id  AND
16686 		        l_new_rec.val_01  = '41'
16687 		    THEN
16688 		        IF l_new_rec.val_06 ='D' THEN
16689                          IF nvl(l_new_rec.val_08,' ') = 'C' THEN
16690  		           l_CodeD_R96_Contri:=l_CodeD_R96_Contri-Nvl(To_Number(l_new_rec.val_07),0);
16691                          ELSE
16692  		           l_CodeD_R96_Contri:=l_CodeD_R96_Contri+Nvl(To_Number(l_new_rec.val_07),0);
16693                          END IF;
16694 		        ELSIF l_new_rec.val_06 ='A'  THEN
16695                          IF nvl(l_new_rec.val_08,' ') = 'C' THEN
16696 		           l_CodeA_R96_Contri :=l_CodeA_R96_Contri-Nvl(To_Number(l_new_rec.val_07),0);
16697                          ELSE
16698 		           l_CodeA_R96_Contri :=l_CodeA_R96_Contri+Nvl(To_Number(l_new_rec.val_07),0);
16699                          END IF;
16700 		        END IF;
16701 		     END IF;
16702 		   --End of Record 96
16703 
16704    		   -- Totaling Record 97 Processing
16705 		     -- Record 12
16706 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(12).ext_rcd_id AND
16707 		        l_new_rec.val_01  = '12'
16708 		     THEN
16709                         IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16710  		           l_R97_Contri:=l_R97_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16711                         ELSE
16712  		           l_R97_Contri:=l_R97_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16713                         END IF;
16714 		     END IF;
16715 		   -- End of Record 97
16716 
16717 		   -- Totaling Record 99 Processing
16718 		     -- Record8
16719 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(8).ext_rcd_id  AND
16720 		        l_new_rec.val_01  = '08'
16721 		     THEN
16722 			 -- Calculating Pension Salary ABP USZO(seq05)
16723                          Hr_Utility.set_location('inside 99 prcesssing' ,26);
16724                          --Hr_Utility.set_location('val'||val.EXT_RSLT_DTL_ID,26);
16725    		         Hr_Utility.set_location('l_R99_Yearly_Amount :'||To_Number(l_new_rec.val_05),12);
16726 			 l_R99_Yearly_Amount := l_R99_Yearly_Amount+Nvl(To_Number(l_new_rec.val_05),0);
16727 		     END IF;
16728 		     -- Record9
16729 		     IF l_new_rec.ext_rcd_id = g_rcd_dtls(9).ext_rcd_id AND
16730 			l_new_rec.val_01  = '09'
16731 		     THEN
16732 		        --Check the record9 Basis Contribution (seq 05)
16733 			--then calculate seq 6 value (ABP Pension Basis Contribution ABP USZO)
16734 			 IF l_new_rec.val_05 = 'OP' THEN
16735                           IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16736 			     l_R99_OPNP_Contri := l_R99_OPNP_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16737                           ELSE
16738 			     l_R99_OPNP_Contri := l_R99_OPNP_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16739                           END IF;
16740 			     -- IPBW_H code is 06
16741 			 ELSIF l_new_rec.val_05 IN('IH','AP') THEN
16742                           IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16743 			     l_R99_IPbw_H_Contri :=  l_R99_IPbw_H_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16744                           ELSE
16745 			     l_R99_IPbw_H_Contri :=  l_R99_IPbw_H_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16746                           END IF;
16747 			     -- IPBW_L code is 07
16748 			 ELSIF l_new_rec.val_05 = 'IL'  THEN
16749                           IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16750                              l_R99_IPbw_L_Contri :=  l_R99_IPbw_L_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16751                           ELSE
16752                              l_R99_IPbw_L_Contri :=  l_R99_IPbw_L_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16753                           END IF;
16754 			 ELSIF l_new_rec.val_05 = 'FB'  THEN
16755                           IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16756                              l_R99_Fpu_B_Contri :=  l_R99_Fpu_B_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16757                           ELSE
16758                              l_R99_Fpu_B_Contri :=  l_R99_Fpu_B_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16759                           END IF;
16760 			 ELSIF l_new_rec.val_05 = 'FO'  THEN
16761                           IF nvl(l_new_rec.val_07,' ') = 'C' THEN
16762                              l_R99_Fpu_C_Contri :=  l_R99_Fpu_C_Contri-Nvl(To_Number(l_new_rec.val_06),0);
16763                           ELSE
16764                              l_R99_Fpu_C_Contri :=  l_R99_Fpu_C_Contri+Nvl(To_Number(l_new_rec.val_06),0);
16765                           END IF;
16766 			 END IF;
16767 		     END IF;
16768 		   --End of 99 Processing
16769 		  END LOOP ; --individual close
16770 	  END LOOP;--End of val result loop
16771 
16772             --Get the record count for 20,21 and 22
16773             l_record94_count:=l_record94_count + Get_Trailer_Record_Count(g_rcd_dtls(20).ext_rcd_id
16774 			                                            ,g_rcd_dtls(21).ext_rcd_id
16775 								    ,g_rcd_dtls(22).ext_rcd_id
16776 								    ,g_employer_child_list(l_group_org_index).gre_org_id);
16777 
16778 
16779             --Get the record count for 30 and 31
16780             l_record95_count:=l_record95_count + Get_Trailer_Record_Count(g_rcd_dtls(30).ext_rcd_id
16781 	                                              ,g_rcd_dtls(31).ext_rcd_id
16782 	   					      ,NULL
16783 						      ,g_employer_child_list(l_group_org_index).gre_org_id);
16784 
16785             --Get the record count for 40 and 41
16786   	    l_record96_count:=l_record96_count + Get_Trailer_Record_Count(g_rcd_dtls(40).ext_rcd_id
16787 	                                              ,g_rcd_dtls(41).ext_rcd_id
16788 	   					      ,NULL
16789 						      ,g_employer_child_list(l_group_org_index).gre_org_id);
16790 
16791             --Get the record count for 12
16792   	    l_record97_count:=l_record97_count + Get_Trailer_Record_Count(g_rcd_dtls(12).ext_rcd_id
16793 	                                              ,NULL
16794 	  					      ,NULL
16795 						      ,g_employer_child_list(l_group_org_index).gre_org_id);
16796             Hr_Utility.set_location('l_record99_count --'||l_record99_count,20);
16797             Hr_Utility.set_location('g_employer_child_list(l_group_org_index).gre_org_id --'||g_employer_child_list(l_group_org_index).gre_org_id,20);
16798             l_record99_count:=l_record99_count + Get_All_Records_Count(g_rcd_dtls(0).ext_rcd_id
16799 			                            ,g_rcd_dtls(99).ext_rcd_id
16800 				                    ,g_employer_child_list(l_group_org_index).gre_org_id);
16801 
16802 
16803 	    l_org_grp_index:=l_org_grp_index+1;
16804        END LOOP; --End of Org Sub grouping
16805 
16806 		   --Loop through trailer records
16807 		   FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16808                                                     ,c_rcd_type_cd => 'T')-- T-Trailer
16809                    LOOP
16810                        l_insert_trailer := 1;
16811 		       OPEN csr_get_trailer_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
16812                                                 ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
16813   		       FETCH csr_get_trailer_rslt INTO l_trailer_main_rec;
16814 		       CLOSE csr_get_trailer_rslt;
16815 		       l_trailer_new_rec :=  l_trailer_main_rec;
16816 
16817 		       -- Start of trailer record94
16818 		       IF g_rcd_dtls(94).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16819 
16820 
16821 		           l_trailer_new_rec.val_04 :=  Trim(To_Char(l_record94_count,'0999999'));--records count
16822 			   l_trailer_new_rec.val_05 :=  Trim(To_Char(ABS(l_R94_WA_Contri),'09999999999'));
16823 			   l_trailer_new_rec.val_06 := Get_Trailer_Amount_Sign(l_R94_WA_Contri);    --Amount Code
16824 			   l_trailer_new_rec.val_07 :=  Trim(To_Char(ABS(l_R94_UF_Contri),'09999999999'));
16825 			   l_trailer_new_rec.val_08 := Get_Trailer_Amount_Sign(l_R94_UF_Contri);    --Amount Code
16826 			   l_trailer_new_rec.val_09 :=Trim(To_Char(ABS(l_R94_ZF_Contri),'09999999999'));
16827 			   l_trailer_new_rec.val_10 := Get_Trailer_Amount_Sign(l_R94_ZF_Contri);    --Amount Code
16828 			   l_trailer_new_rec.val_11  :=Trim(To_Char(ABS(l_R94_SI_Contri),'0999999999999'));
16829 			   l_trailer_new_rec.val_12 := Get_Trailer_Amount_Sign(l_R94_SI_Contri);    --Amount Code
16830 
16831                            --force an insert of this trailer record only if the count is > 0
16832                            IF l_record94_count > 0 THEN
16833                               l_insert_trailer := 1;
16834                               l_count := l_count + 1;
16835                            ELSE
16836                               l_insert_trailer := 0;
16837                            END IF;
16838 
16839 		       END IF;
16840 		       -- End of record 94
16841 
16842 		       -- Start of trailer record95
16843 		       IF g_rcd_dtls(95).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16844 
16845 		           l_trailer_new_rec.val_04 := Trim(To_Char(l_record95_count,'0999999'));
16846 			   --l_trailer_new_rec.val_05 :=  Lpad(Ben_Ext_Fmt.apply_format_mask(To_Number(l_R95_Contri),'9999999999999V99'),10,0);
16847 			   l_trailer_new_rec.val_05 := Trim(To_Char(ABS(l_R95_Contri),'09999999999'));
16848 			   l_trailer_new_rec.val_06 := Get_Trailer_Amount_Sign(l_R95_Contri);
16849 
16850                            --force an insert of this trailer record only if the count is > 0
16851                            IF l_record95_count > 0 THEN
16852                               l_insert_trailer := 1;
16853                               l_count := l_count + 1;
16854                            ELSE
16855                               l_insert_trailer := 0;
16856                            END IF;
16857 
16858 		       END IF;
16859 
16860 		       -- Start of trailer record96
16861 		       l_record96_rcd_id := g_rcd_dtls(96).ext_rcd_id;
16862 		       IF l_record96_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16863 
16864 		           l_trailer_new_rec.val_04 := Trim(To_Char(l_record96_count,'0999999'));
16865 			   l_trailer_new_rec.val_05 :=  Trim(To_Char(ABS(l_CodeA_R96_Contri),'09999999999'));
16866 			   l_trailer_new_rec.val_06 := Get_Trailer_Amount_Sign(l_CodeA_R96_Contri);
16867 			   l_trailer_new_rec.val_07 :=	 Trim(To_Char(ABS(l_CodeD_R96_Contri),'09999999999'));
16868 			   l_trailer_new_rec.val_08 := Get_Trailer_Amount_Sign(l_CodeD_R96_Contri);
16869 
16870                            --force an insert of this trailer record only if the count is > 0
16871                            IF l_record96_count > 0 THEN
16872                               l_insert_trailer := 1;
16873                               l_count := l_count + 1;
16874                            ELSE
16875                               l_insert_trailer := 0;
16876                            END IF;
16877 
16878 		       END IF;
16879 
16880 		       -- Start of trailer record97
16881 		       IF g_rcd_dtls(97).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16882 
16883 		           l_trailer_new_rec.val_04 := Trim(To_Char(l_record97_count,'0999999'));
16884 			   l_trailer_new_rec.val_05 :=	Trim(To_Char(ABS(l_R97_Contri),'09999999999'));
16885 			   l_trailer_new_rec.val_06 := Get_Trailer_Amount_Sign(l_R97_Contri);
16886 
16887                            --force an insert of this trailer record only if the count is > 0
16888                            IF l_record97_count > 0 THEN
16889                               l_insert_trailer := 1;
16890                               l_count := l_count + 1;
16891                            ELSE
16892                               l_insert_trailer := 0;
16893                            END IF;
16894 
16895 		       END IF;
16896 
16897 		       -- Start of trailer record99
16898 		       IF g_rcd_dtls(99).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16899 			   --All Records count exclusive record 00 and record 99
16900 			   l_count := l_count +l_record99_count;
16901 
16902                            l_trailer_new_rec.val_04 := Trim(To_Char(l_count,'0999999'));
16903 			   l_trailer_new_rec.val_05 :=	 Trim(To_Char(ABS(l_R99_Yearly_Amount),'09999999999'));
16904 			   l_trailer_new_rec.val_06 := Get_Trailer_Amount_Sign(l_R99_Yearly_Amount);
16905 			   l_trailer_new_rec.val_07 :=	 Trim(To_Char(ABS(l_R99_OPNP_Contri),'09999999999'));
16906 			   l_trailer_new_rec.val_08 := Get_Trailer_Amount_Sign(l_R99_OPNP_Contri);
16907 			   l_trailer_new_rec.val_09 :=	 Trim(To_Char(ABS(l_R99_IPbw_H_Contri),'09999999999'));
16908 			   l_trailer_new_rec.val_10 := Get_Trailer_Amount_Sign(l_R99_IPbw_H_Contri);
16909 			   l_trailer_new_rec.val_11 :=	 Trim(To_Char(ABS(l_R99_IPbw_L_Contri),'09999999999'));
16910 			   l_trailer_new_rec.val_12 := Get_Trailer_Amount_Sign(l_R99_IPbw_L_Contri);
16911 			   l_trailer_new_rec.val_17 :=	 Trim(To_Char(ABS(l_R99_Fpu_B_Contri),'09999999999'));
16912 			   l_trailer_new_rec.val_18 := Get_Trailer_Amount_Sign(l_R99_Fpu_B_Contri);
16913 			   l_trailer_new_rec.val_19 :=	 Trim(To_Char(ABS(l_R99_Fpu_C_Contri),'09999999999'));
16914 			   l_trailer_new_rec.val_20 := Get_Trailer_Amount_Sign(l_R99_Fpu_C_Contri);
16915 			   l_trailer_new_rec.val_13 :=	Trim(To_Char(0,'09999999999'));
16916 			   l_trailer_new_rec.val_15 :=	Trim(To_Char(0,'09999999999'));
16917 			   l_trailer_new_rec.val_23 :=	Trim(To_Char(0,'09999999999'));
16918 
16919 		       END IF;
16920 		       --Updating the current ER Num
16921 		       l_trailer_er_num  :=Get_Header_EMR_Number(g_employer_list(l_employer_index).gre_org_id,g_conc_prog_details(0).endingdt);
16922 
16923                        IF IsNumber(l_trailer_er_num) THEN
16924                                    l_trailer_er_num := Trim(To_Char(Fnd_Number.Canonical_To_Number
16925 		                             (Nvl(l_trailer_er_num,'0'))
16926 		                           ,'0999999'));
16927                        END IF;
16928 
16929 		       l_trailer_new_rec.val_02 := l_trailer_er_num;
16930 		       l_sort_val := Lpad(sort_val,15,0);
16931 		       l_trailer_new_rec.prmy_sort_val := l_sort_val;
16932 		       l_trailer_new_rec.object_version_NUMBER :=  Nvl(l_trailer_new_rec.object_version_NUMBER,0) + 1;
16933 		       sort_val :=sort_val+1;
16934 
16935 		       --Inserting new ones
16936                        IF l_insert_trailer = 1 THEN
16937 		          Ins_Rslt_Dtl(p_dtl_rec => l_trailer_new_rec);
16938                        END IF;
16939 		   END LOOP;
16940 
16941 	       --Intialize to zero
16942 	       l_R94_WA_Contri    := 0;
16943                l_R94_UF_Contri    := 0;
16944                l_R94_ZF_Contri    := 0;
16945                l_R94_SI_Contri    := 0;
16946 	       l_R95_Contri       := 0;
16947 	       l_CodeD_R96_Contri := 0;
16948 	       l_CodeA_R96_Contri := 0;
16949 	       l_R97_Contri       := 0;
16950 	       l_R99_Yearly_Amount:= 0;
16951                l_R99_OPNP_Contri  := 0;
16952                l_R99_IPbw_H_Contri:= 0;
16953                l_R99_IPbw_L_Contri:= 0;
16954                l_R99_Fpu_B_Contri := 0;
16955                l_R99_Fpu_C_Contri := 0;
16956 	       l_record94_count   := 0;
16957 	       l_record95_count   := 0;
16958 	       l_record96_count   := 0;
16959 	       l_record97_count   := 0;
16960 	       l_record99_count   := 0;
16961 
16962                --next employer index
16963 	       l_er_index:=l_er_index+1;
16964 	       l_employer_index:=g_employer_list.NEXT(l_employer_index);
16965       END LOOP;	 --End of Employers loop
16966 --fetch the result id to delete the extract result
16967 --trailer records created by benefits
16968 FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16969                                  ,c_rcd_type_cd => 'T')-- T-Trailer
16970 LOOP
16971   IF g_rcd_dtls(94).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16972      l_ext_rslt_dtl_id := l_R94_rslt_dtl_id;
16973   ELSIF g_rcd_dtls(95).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16974      l_ext_rslt_dtl_id := l_R95_rslt_dtl_id;
16975   ELSIF g_rcd_dtls(96).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16976      l_ext_rslt_dtl_id := l_R96_rslt_dtl_id;
16977   ELSIF g_rcd_dtls(97).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16978      l_ext_rslt_dtl_id := l_R97_rslt_dtl_id;
16979   ELSIF g_rcd_dtls(99).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16980      l_ext_rslt_dtl_id := l_R99_rslt_dtl_id;
16981   END IF;
16982 
16983   DELETE
16984     FROM ben_ext_rslt_dtl dtl
16985   WHERE dtl.ext_rslt_id  = Ben_Ext_Thread.g_ext_rslt_id
16986     AND dtl.ext_rcd_id    = csr_rcd_rec.ext_rcd_id
16987     AND dtl.ext_rslt_dtl_id = l_ext_rslt_dtl_id
16988     AND business_group_id = p_business_group_id;
16989 
16990 END LOOP;
16991 
16992 FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
16993                                  ,c_rcd_type_cd => 'H')-- H-Header
16994 LOOP
16995   IF g_rcd_dtls(00).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
16996      l_ext_rslt_dtl_id := l_R00_rslt_dtl_id;
16997   END IF;
16998 
16999   DELETE
17000     FROM ben_ext_rslt_dtl dtl
17001   WHERE dtl.ext_rslt_id  = Ben_Ext_Thread.g_ext_rslt_id
17002     AND dtl.ext_rcd_id    = csr_rcd_rec.ext_rcd_id
17003     AND dtl.ext_rslt_dtl_id = l_ext_rslt_dtl_id
17004     AND business_group_id = p_business_group_id;
17005 
17006 END LOOP;
17007 
17008   Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
17009   RETURN l_return_value;
17010 
17011 EXCEPTION
17012   WHEN Others THEN
17013    Hr_Utility.set_location('..Exception when others raised..', 20);
17014    Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
17015    RETURN -1;
17016 END Sort_Post_Process;
17017 
17018 END Pqp_Nl_Pension_Extracts;