DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQP_NL_PGGM_PENSION_EXTRACTS

Source


1 PACKAGE BODY PQP_NL_PGGM_PENSION_EXTRACTS AS
2 /* $Header: pqpnlpggmpext.pkb 120.0.12000000.14 2007/04/18 20:48:12 rrajaman noship $ */
3 
4 g_proc_name  Varchar2(200) :='PQP_NL_PGGM_Pension_Extracts.';
5 
6 -- =============================================================================
7 -- Cursor to get the extract record id's for extract definition id
8 -- =============================================================================
9 CURSOR csr_ext_rcd_id_with_seq  IS
10    SELECT Decode(rin.seq_num,1,'000',
11                              2,'010',
12                              3,'020',
13                              4,'030',
14                              5,'040',
15                              6,'060',
16                              7,'070',
17                              8,'080',
18                              9,'081',
19                             12,'999',
20                             '~') rec_num,
21           rin.seq_num,
22           rin.hide_flag,
23           rcd.ext_rcd_id,
24           rcd.rcd_type_cd
25     FROM  ben_ext_rcd         rcd
26          ,ben_ext_rcd_in_file rin
27          ,ben_ext_dfn dfn
28    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
29      AND rin.ext_file_id  = dfn.ext_file_id
30      AND rin.ext_rcd_id   = rcd.ext_rcd_id
31      ORDER BY rin.seq_num;
32 
33 -- =============================================================================
34 -- Cursor to get assignment details
35 -- =============================================================================
36 CURSOR csr_assig (c_assignment_id     IN Number
37                  ,c_effective_date    IN Date
38                  ,c_business_group_id IN Number) IS
39 SELECT paf.person_id
40       ,paf.organization_id
41       ,paf.assignment_type
42       ,paf.effective_start_date
43       ,paf.effective_end_date
44       ,ast.user_status
45       ,Hr_General.decode_lookup
46         ('EMP_CAT',
47           paf.employment_category) employment_category
48       ,pps.date_start
49       ,pps.actual_termination_date
50       ,paf.payroll_id
51       ,'ER'
52       ,per.employee_number
53       ,paf.assignment_sequence
54       ,per.national_identifier
55       ,per.last_name
56       ,per.per_information1
57       ,per.pre_name_adjunct
58       ,per.sex
59       ,per.date_of_birth
60       ,'PLN'
61       ,'PIX'
62       ,per.per_information14
63       ,per.marital_status
64       ,paf.primary_flag
65   FROM per_all_assignments_f       paf,
66        per_all_people_f            per,
67        per_periods_of_service      pps,
68        per_assignment_status_types ast
69  WHERE paf.assignment_id             = c_assignment_id
70    AND paf.person_id                 = per.person_id
71    AND pps.period_of_service_id(+)       = paf.period_of_service_id
72    AND ast.assignment_status_type_id = paf.assignment_status_type_id
73    AND c_effective_date BETWEEN paf.effective_start_date
74                             AND paf.effective_end_date
75    AND c_effective_date BETWEEN per.effective_start_date
76                             AND per.effective_end_date
77    AND paf.business_group_id = c_business_group_id
78    AND per.business_group_id = c_business_group_id;
79 -- =============================================================================
80 -- Based on result id and Ext. Dfn Id, get the con. request id
81 -- =============================================================================
82 CURSOR csr_req_id (c_ext_rslt_id       IN ben_ext_rslt.ext_rslt_id%TYPE
83                    ,c_ext_dfn_id        IN ben_ext_rslt.ext_dfn_id%TYPE
84                    ,c_business_group_id IN ben_ext_rslt.business_group_id%TYPE) IS
85 SELECT request_id
86   FROM ben_ext_rslt
87  WHERE ext_rslt_id       = c_ext_rslt_id
88    AND ext_dfn_id        = c_ext_dfn_id
89    AND business_group_id = c_business_group_id;
90 
91 -- =============================================================================
92 -- Check whether assignment is primary or secondary
93 -- =============================================================================
94 CURSOR csr_chk_primary_asg(c_assignment_id NUMBER, c_effective_date DATE) IS
95 SELECT 'x'
96   FROM per_all_assignments_f
97  WHERE assignment_id = c_assignment_id
98    AND primary_flag= 'Y'
99    AND c_effective_date BETWEEN effective_start_date AND effective_end_date;
100 
101 -- =============================================================================
102 -- Cursor to get secondary asgsignments  details
103 -- =============================================================================
104 
105 CURSOR csr_sec_assig (c_assignment_id     IN Number
106                      ,c_effective_date    IN Date
107                      ,c_business_group_id IN Number
108                      ,c_person_id         IN Number) IS
109 SELECT paf.organization_id
110       ,paf.payroll_id
111   FROM per_all_assignments_f       paf,
112        per_all_people_f            per
113  WHERE paf.assignment_id             <> c_assignment_id
114    AND paf.person_id                 = c_person_id
115    AND paf.person_id                 = per.person_id
116    AND c_effective_date BETWEEN paf.effective_start_date
117                             AND paf.effective_end_date
118    AND c_effective_date BETWEEN per.effective_start_date
119                             AND per.effective_end_date
120    AND paf.business_group_id = c_business_group_id
121    AND per.business_group_id = c_business_group_id;
122 
123 -- =============================================================================
124 -- Cursor to get the extract record id's for record sequence number
125 -- =============================================================================
126 CURSOR c_get_rcd_id(c_seq IN Number)  IS
127    SELECT rcd.ext_rcd_id
128     FROM  ben_ext_rcd         rcd
129          ,ben_ext_rcd_in_file rin
130          ,ben_ext_dfn dfn
131    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id -- The extract executing currently
132      AND rin.ext_file_id  = dfn.ext_file_id
133      AND rin.ext_rcd_id   = rcd.ext_rcd_id
134      AND rin.seq_num      = c_seq;
135 
136 -- =============================================================================
137 -- Cursor to get the extract record id
138 -- =============================================================================
139 CURSOR csr_ext_rcd_id (c_hide_flag   IN Varchar2
140                       ,c_rcd_type_cd IN Varchar2
141                       ) IS
142    SELECT rcd.ext_rcd_id
143     FROM  ben_ext_rcd         rcd
144          ,ben_ext_rcd_in_file rin
145          ,ben_ext_dfn dfn
146    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id -- The extract
147      AND rin.ext_file_id  = dfn.ext_file_id
148      AND rin.hide_flag    = c_hide_flag     -- Y=Hidden, N=Not Hidden
149      AND rin.ext_rcd_id   = rcd.ext_rcd_id
150      AND rcd.rcd_type_cd  = c_rcd_type_cd;  -- D=Detail,H=Header,F=Footer
151 
152 -- =============================================================================
153 -- Cursor to get the extract record id for hidden and Not hidden records
154 -- =============================================================================
155 CURSOR csr_ext_rcd_id_hidden(c_rcd_type_cd IN Varchar2) IS
156     SELECT rcd.ext_rcd_id
157     FROM  ben_ext_rcd         rcd
158          ,ben_ext_rcd_in_file rin
159          ,ben_ext_dfn dfn
160    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
161      AND rin.ext_file_id  = dfn.ext_file_id
162      AND rin.ext_rcd_id   = rcd.ext_rcd_id
163      AND rcd.rcd_type_cd  = c_rcd_type_cd
164      ORDER BY rin.seq_num;
165 -- ============================================================================
166 -- Cursor to get the Organization name
167 -- ============================================================================
168   CURSOR csr_org_name (c_org_id IN Number
169      		       )IS
170   SELECT NAME
171     FROM hr_all_organization_units
172    WHERE organization_id = c_org_id;
173 -- =============================================================================
174 -- Cursor to chk for other primary assig. within the extract date range.
175 -- =============================================================================
176 CURSOR csr_sec_assg
177         (c_primary_assignment_id IN per_all_assignments_f.assignment_id%TYPE
178         ,c_person_id             IN per_all_people_f.person_id%TYPE
179         ,c_effective_date        IN Date
180         ,c_extract_start_date    IN Date
181         ,c_extract_end_date      IN Date ) IS
182   SELECT asg.person_id
183         ,asg.organization_id
184         ,asg.assignment_type
185         ,asg.effective_start_date
186         ,asg.effective_end_date
187         ,'NO'
188         ,asg.assignment_id
189     FROM per_all_assignments_f  asg
190    WHERE asg.person_id       = c_person_id
191      AND asg.assignment_id  <> c_primary_assignment_id
192      AND asg.assignment_type ='E'
193      AND (( c_effective_date  BETWEEN asg.effective_start_date
194                                   AND asg.effective_end_date
195            )
196           OR
197           ( asg.effective_end_date =
198            (SELECT Max(asx.effective_end_date)
199               FROM per_all_assignments_f asx
200              WHERE asx.assignment_id   = asg.assignment_id
201                AND asx.person_id       = c_person_id
202                AND asx.assignment_type = 'E'
203                AND ((asx.effective_end_date BETWEEN c_extract_start_date
204                                                 AND c_extract_end_date)
205                      OR
206                     (asx.effective_start_date BETWEEN c_extract_start_date
207                                                   AND c_extract_end_date)
208                    )
209             )
210            )
211          )
212    ORDER BY asg.effective_start_date ASC;
213 -- =============================================================================
214 -- Cursor to get the extract result dtl record for a person id
215 -- =============================================================================
216 CURSOR csr_rslt_dtl(c_person_id      IN Number
217                    ,c_ext_rslt_id    IN Number
218                    ,c_ext_dtl_rcd_id IN Number ) IS
219    SELECT *
220      FROM ben_ext_rslt_dtl dtl
221     WHERE dtl.ext_rslt_id = c_ext_rslt_id
222       AND dtl.person_id   = c_person_id
223       AND dtl.ext_rcd_id  = c_ext_dtl_rcd_id;
224 -- =============================================================================
225 -- Cursor to get all assig.actions for a given assig. within a data range
226 -- =============================================================================
227 CURSOR csr_asg_act (c_assignment_id IN Number
228                    ,c_payroll_id    IN Number
229                    ,c_con_set_id    IN Number
230                    ,c_start_date    IN Date
231                    ,c_end_date      IN Date
232                    ) IS
233   SELECT paa.assignment_action_id
234         ,ppa.effective_date
235         ,ppa.action_type
236     FROM pay_assignment_actions paa
237         ,pay_payroll_actions    ppa
238    WHERE paa.assignment_id        = c_assignment_id
239      AND paa.payroll_action_id    = ppa.payroll_action_id
240      AND paa.source_action_id     IS NULL
241      AND ppa.action_status        = 'C'
242      AND paa.action_status        = 'C'
243      AND ppa.action_type IN ('B','L','O','Q','R')
244      AND ppa.payroll_id           = Nvl(c_payroll_id,ppa.payroll_id)
245      AND ppa.consolidation_set_id = Nvl(c_con_set_id,ppa.consolidation_set_id)
246      AND ppa.effective_date BETWEEN c_start_date
247                                 AND c_end_date
248      ORDER BY ppa.effective_date;
249 
250 l_asg_act csr_asg_act%ROWTYPE;
251 
252 -- =============================================================================
253 --Cursor to fetch Start date of a year
254 -- =============================================================================
255 CURSOR c_get_period_start_date ( c_year           IN VARCHAR2
256                                 ,c_assignment_id  IN NUMBER
257                                 ,c_date_earned    IN DATE )
258 IS
259 SELECT NVL(min(PTP.start_date),to_date('0101'||c_year,'DDMMYYYY'))
260  FROM  per_time_periods PTP
261        ,per_all_assignments_f PAA
262  WHERE PAA.assignment_id = c_assignment_id
263    AND PTP.payroll_id = PAA.payroll_id
264    AND (c_date_earned between PAA.effective_start_date and PAA.effective_end_date)
265    AND (substr(PTP.period_name,4,4)=c_year
266     OR substr(PTP.period_name,3,4)=c_year);
267 
268 -- =============================================================================
269 --Cursor to fetch End date of a year
270 -- =============================================================================
271 CURSOR c_get_period_end_date ( c_year IN VARCHAR2
272                               ,c_assignment_id  IN NUMBER
273                               ,c_date_earned    IN DATE )
274 IS
275 SELECT NVL(max(PTP.end_date),to_date('3112'||c_year,'DDMMYYYY'))
276  FROM   per_time_periods PTP
277       , per_all_assignments_f PAA
278  WHERE PAA.assignment_id = c_assignment_id
279    AND PTP.payroll_id = PAA.payroll_id
280    AND (c_date_earned between PAA.effective_start_date and PAA.effective_end_date)
281    AND (substr(PTP.period_name,4,4)=c_year
282     OR substr(PTP.period_name,3,4)=c_year);
283 
284 -- =============================================================================
285 --Cursor to get number of pay periods in a year
286 -- =============================================================================
287 CURSOR c_get_num_periods_per_year(c_assignment_id IN NUMBER
288                                   ,c_date_earned IN DATE)  IS
289 SELECT NVL(TPTYPE.number_per_fiscal_year,12)
290 FROM   per_all_assignments_f    PAA
291 ,      per_time_periods       TPERIOD
292 ,      per_time_period_types  TPTYPE
293 WHERE  PAA.assignment_id      = c_assignment_id
294   AND  TPERIOD.payroll_id     = PAA.payroll_id
295   AND  ( c_date_earned between PAA.effective_start_date and PAA.effective_end_date)
296   AND  ( c_date_earned between TPERIOD.start_date       and TPERIOD.end_date )
297   AND  TPTYPE.period_type      = TPERIOD.period_type;
298 
299 -- ====================================================================
300 -- ~ Set_ConcProg_Parameter_Values : Used to get the conc program parameters
301 --   values for passed ids and also setting the values into the global records
302 -- ====================================================================
303 PROCEDURE Set_ConcProg_Parameter_Values
304            (p_ext_dfn_id                  IN     Number
305            ,p_start_date                  IN     Varchar2
306            ,p_end_date                    IN     Varchar2
307            ,p_payroll_id                  IN     Number
308            ,p_con_set                     IN     Number
309            ,p_org_id                      IN     Number
310            )  IS
311 
312    CURSOR csr_ext_name(c_ext_dfn_id  IN Number
313                        )IS
314    SELECT Substr(ed.NAME,1,240)
315      FROM ben_ext_dfn ed
316     WHERE ed.ext_dfn_id = p_ext_dfn_id;
317 
318    CURSOR csr_pay_name(c_payroll_id IN Number
319                       ,c_end_date   IN Date
320                  )IS
321    SELECT pay.payroll_name
322      FROM pay_payrolls_f pay
323     WHERE pay.payroll_id = c_payroll_id
324       AND c_end_date BETWEEN pay.effective_start_date
325       AND pay.effective_end_date;
326 
327    CURSOR csr_con_set (c_con_set IN Number
328                       )IS
329    SELECT con.consolidation_set_name
330      FROM pay_consolidation_sets con
331     WHERE con.consolidation_set_id = c_con_set;
332 
333    l_proc_name      Varchar2(150) := g_proc_name ||'Set_ConcProg_Parameter_Values';
334    l_extract_name    ben_ext_dfn.NAME%TYPE;
335    l_payroll_name    PAY_PAYROLLS_F.PAYROLL_NAME%TYPE ;
336    l_con_set_name    PAY_CONSOLIDATION_SETS.CONSOLIDATION_SET_NAME%TYPE;
337    l_org_name        hr_all_organization_units.NAME%TYPE;
338 
339 BEGIN
340       Hr_Utility.set_location('Entering: '||l_proc_name, 5);
341 
342       OPEN csr_ext_name( c_ext_dfn_id => p_ext_dfn_id);
343       FETCH csr_ext_name INTO l_extract_name;
344       CLOSE csr_ext_name;
345 
346       IF p_payroll_id IS NOT NULL THEN
347          OPEN  csr_pay_name( c_payroll_id => p_payroll_id
348                              ,c_end_date =>p_end_date
349 	 	           );
350          FETCH csr_pay_name INTO l_payroll_name;
351          CLOSE csr_pay_name;
352       END IF;
353 
354       IF p_con_set IS NOT NULL THEN
355          OPEN  csr_con_set( c_con_set => p_con_set);
356          FETCH csr_con_set INTO l_con_set_name;
357          CLOSE csr_con_set;
358       END IF;
359 
360       IF p_org_id IS NOT NULL THEN
361          OPEN  csr_org_name( c_org_id => p_org_id);
362          FETCH csr_org_name INTO l_org_name;
363          CLOSE csr_org_name;
364       END IF;
365 
366       -- Add code for extract type.............................................Code Required here
367       --Setting the values
368       g_conc_prog_details(0).extract_name   := l_extract_name;
369       g_conc_prog_details(0).beginningdt    := p_start_date;
370       g_conc_prog_details(0).endingdt       := p_end_date;
371       g_conc_prog_details(0).payrollname    := l_payroll_name;
372       g_conc_prog_details(0).consolset      := l_con_set_name;
373       g_conc_prog_details(0).orgname        := l_org_name;
374       g_conc_prog_details(0).orgid          := p_org_id;
375 
376    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
377 EXCEPTION
378    WHEN Others THEN
379     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
380 END Set_ConcProg_Parameter_Values;
381 -- ====================================================================
382 -- Get_Current_Extract_Result:
383 --    Returns the person id associated with the given assignment.
384 --    If none is found,it returns NULL. This may arise if the
385 --    user calls this from a header/trailer record, where
386 --    a dummy context of assignment_id = -1 is passed.
387 -- ====================================================================
388 FUNCTION Get_Current_Extract_Result
389     RETURN Number  IS
390   e_extract_process_not_running EXCEPTION;
391   PRAGMA EXCEPTION_INIT(e_extract_process_not_running,-8002);
392   l_ext_rslt_id  Number;
393 BEGIN
394   l_ext_rslt_id := Ben_Ext_Thread.g_ext_rslt_id;
395   RETURN l_ext_rslt_id;
396 EXCEPTION
397   WHEN e_extract_process_not_running THEN
398    RETURN -1;
399 END Get_Current_Extract_Result;
400 
401 -- ====================================================================
402 -- Get_Current_Extract_Person:
403 --    Returns the person_id for the current extract process
404 --    if one is running, else returns -1
405 -- ====================================================================
406 FUNCTION Get_Current_Extract_Person
407           (p_assignment_id IN Number )
408           RETURN Number IS
409  l_person_id  Number;
410 BEGIN
411   SELECT person_id
412     INTO l_person_id
413     FROM per_all_assignments_f
414    WHERE assignment_id = p_assignment_id
415      AND ROWNUM < 2;
416     RETURN l_person_id;
417   EXCEPTION
418     WHEN No_Data_Found THEN
419       RETURN NULL;
420 END Get_Current_Extract_Person ;
421 
422 -- =============================================================================
423 -- IsNumber: return TRUE if number else FALSE
424 -- =============================================================================
425 FUNCTION IsNumber (p_data_value IN Varchar2)
426 RETURN Boolean  IS
427  l_data_value Number;
428 BEGIN
429   l_data_value := Fnd_Number.Canonical_To_Number(Nvl(p_data_value,'0'));
430   RETURN TRUE;
431 EXCEPTION
432   WHEN Value_Error THEN
433    RETURN FALSE;
434 END IsNumber;
435 
436 -- =============================================================================
437 -- Get the correct year for the effective date
438 -- =============================================================================
439 FUNCTION Get_Year(p_assignment_id NUMBER
440                  ,p_effective_start_date DATE
441 		 ,p_effective_end_date DATE )
442 RETURN NUMBER IS
443 
444 --CURSOR to extract the year from the date irrespective of payroll period type
445 CURSOR c_get_year (c_assignment_id NUMBER, c_effective_date DATE)
446 IS
447 SELECT
448 decode(
449         trunc( to_number(PTP.period_num)/10),
450                              0,substr(PTP.period_name,3,4),
451 			     1,substr(PTP.period_name,4,4)
452       )
453  FROM   per_time_periods PTP
454       ,per_all_assignments_f PAA
455  WHERE PAA.assignment_id = c_assignment_id
456  AND   PTP.payroll_id = PAA.payroll_id
457  AND ( c_effective_date between PTP.start_date and PTP.end_date );
458 
459 l_proc_name         Varchar2(150):= g_proc_name||'Get_Year';
460 l_start_date_year   NUMBER;
461 l_end_date_year     NUMBER;
462 l_year              NUMBER;
463 
464 BEGIN
465  Hr_Utility.set_location('Entering :'||l_proc_name, 5);
466  --Extract the correct year from the start date and end date
467   l_start_date_year:=to_number(to_char(p_effective_start_date,'YYYY'));
468   l_end_date_year  :=to_number(to_char(p_effective_end_date,'YYYY'));
469   IF ( l_start_date_year = l_end_date_year) THEN
470        l_year := l_start_date_year;
471   ELSE --Not a calendar month payroll
472       OPEN c_get_year(p_assignment_id,p_effective_start_date);
473       Hr_Utility.set_location('p_assignment_id :'||p_assignment_id, 5);
474       Hr_Utility.set_location('p_effective_start_date :'||p_effective_start_date, 6);
475       FETCH c_get_year INTO l_year;
476       IF c_get_year%NOTFOUND THEN
477        Hr_Utility.set_location('cursor not found', 6);
478        l_year := to_number(to_char(p_effective_start_date,'YYYY'));
479       END IF;
480       CLOSE c_get_year;
481   END IF;
482  Hr_Utility.set_location('Leaving :'||l_proc_name, 100);
483  RETURN l_year;
484 
485 EXCEPTION
486  WHEN OTHERS THEN
487    Hr_Utility.set_location('Exception occurred at :'||l_proc_name, 120);
488    RETURN -1;
489 END Get_Year;
490 
491 -- ============================================================================
492 -- ~ Update_Record_Values :
493 -- ============================================================================
494 PROCEDURE Update_Record_Values
495            (p_ext_rcd_id            IN ben_ext_rcd.ext_rcd_id%TYPE
496            ,p_ext_data_element_name IN ben_ext_data_elmt.NAME%TYPE
497            ,p_data_element_value    IN ben_ext_rslt_dtl.val_01%TYPE
498            ,p_data_ele_seqnum       IN Number
499            ,p_ext_dtl_rec           IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE
500             ) IS
501    CURSOR csr_seqnum (c_ext_rcd_id            IN ben_ext_rcd.ext_rcd_id%TYPE
502                      ,c_ext_data_element_name IN ben_ext_data_elmt.NAME%TYPE
503                       ) IS
504       SELECT der.ext_data_elmt_id,
505              der.seq_num,
506              ede.NAME
507         FROM ben_ext_data_elmt_in_rcd der
508              ,ben_ext_data_elmt        ede
509        WHERE der.ext_rcd_id = c_ext_rcd_id
510          AND ede.ext_data_elmt_id = der.ext_data_elmt_id
511          AND ede.NAME             LIKE '%'|| c_ext_data_element_name
512        ORDER BY seq_num;
513 
514    l_seqnum_rec        csr_seqnum%ROWTYPE;
515    l_proc_name         Varchar2(150):= g_proc_name||'Update_Record_Values';
516    l_ext_dtl_rec_nc    ben_ext_rslt_dtl%ROWTYPE;
517 BEGIN
518 
519  Hr_Utility.set_location('Entering :'||l_proc_name, 5);
520  -- nocopy changes
521  l_ext_dtl_rec_nc := p_ext_dtl_rec;
522 
523  IF p_data_ele_seqnum IS NULL THEN
524     OPEN csr_seqnum ( c_ext_rcd_id            => p_ext_rcd_id
525                      ,c_ext_data_element_name => p_ext_data_element_name);
526     FETCH csr_seqnum INTO l_seqnum_rec;
527     IF csr_seqnum%NOTFOUND THEN
528        CLOSE csr_seqnum;
529     ELSE
530        CLOSE csr_seqnum;
531     END IF;
532  ELSE
533     l_seqnum_rec.seq_num := p_data_ele_seqnum;
534  END IF;
535 
536  IF l_seqnum_rec.seq_num = 1 THEN
537     p_ext_dtl_rec.val_01 := p_data_element_value;
538  ELSIF l_seqnum_rec.seq_num = 2 THEN
539     p_ext_dtl_rec.val_02 := p_data_element_value;
540  ELSIF l_seqnum_rec.seq_num = 3 THEN
541     p_ext_dtl_rec.val_03 := p_data_element_value;
542  ELSIF l_seqnum_rec.seq_num = 4 THEN
543     p_ext_dtl_rec.val_04 := p_data_element_value;
544  ELSIF l_seqnum_rec.seq_num = 5 THEN
545     p_ext_dtl_rec.val_05 := p_data_element_value;
546  ELSIF l_seqnum_rec.seq_num = 6 THEN
547     p_ext_dtl_rec.val_06 := p_data_element_value;
548  ELSIF l_seqnum_rec.seq_num = 7 THEN
549     p_ext_dtl_rec.val_07 := p_data_element_value;
550  ELSIF l_seqnum_rec.seq_num = 8 THEN
551     p_ext_dtl_rec.val_08 := p_data_element_value;
552  ELSIF l_seqnum_rec.seq_num = 9 THEN
553     p_ext_dtl_rec.val_09 := p_data_element_value;
554  ELSIF l_seqnum_rec.seq_num = 10 THEN
555     p_ext_dtl_rec.val_10 := p_data_element_value;
556  ELSIF l_seqnum_rec.seq_num = 11 THEN
557     p_ext_dtl_rec.val_11 := p_data_element_value;
558  ELSIF l_seqnum_rec.seq_num = 12 THEN
559     p_ext_dtl_rec.val_12 := p_data_element_value;
560  ELSIF l_seqnum_rec.seq_num = 13 THEN
561     p_ext_dtl_rec.val_13 := p_data_element_value;
562  ELSIF l_seqnum_rec.seq_num = 14 THEN
563     p_ext_dtl_rec.val_14 := p_data_element_value;
564  ELSIF l_seqnum_rec.seq_num = 15 THEN
565     p_ext_dtl_rec.val_15 := p_data_element_value;
566  ELSIF l_seqnum_rec.seq_num = 16 THEN
567     p_ext_dtl_rec.val_16 := p_data_element_value;
568  ELSIF l_seqnum_rec.seq_num = 17 THEN
569     p_ext_dtl_rec.val_17 := p_data_element_value;
570  ELSIF l_seqnum_rec.seq_num = 18 THEN
571     p_ext_dtl_rec.val_18 := p_data_element_value;
572  ELSIF l_seqnum_rec.seq_num = 19 THEN
573     p_ext_dtl_rec.val_19 := p_data_element_value;
574  ELSIF l_seqnum_rec.seq_num = 20 THEN
575     p_ext_dtl_rec.val_20 := p_data_element_value;
576  ELSIF l_seqnum_rec.seq_num = 21 THEN
577     p_ext_dtl_rec.val_21 := p_data_element_value;
578  ELSIF l_seqnum_rec.seq_num = 22 THEN
579     p_ext_dtl_rec.val_22 := p_data_element_value;
580  ELSIF l_seqnum_rec.seq_num = 23THEN
581     p_ext_dtl_rec.val_23 := p_data_element_value;
582  ELSIF l_seqnum_rec.seq_num = 24 THEN
583     p_ext_dtl_rec.val_24 := p_data_element_value;
584  ELSIF l_seqnum_rec.seq_num = 25 THEN
585     p_ext_dtl_rec.val_25 := p_data_element_value;
586  ELSIF l_seqnum_rec.seq_num = 26 THEN
587     p_ext_dtl_rec.val_26 := p_data_element_value;
588  ELSIF l_seqnum_rec.seq_num = 27 THEN
589     p_ext_dtl_rec.val_27 := p_data_element_value;
590  ELSIF l_seqnum_rec.seq_num = 28 THEN
591     p_ext_dtl_rec.val_28 := p_data_element_value;
592  ELSIF l_seqnum_rec.seq_num = 29 THEN
593     p_ext_dtl_rec.val_29 := p_data_element_value;
594  ELSIF l_seqnum_rec.seq_num = 30 THEN
595     p_ext_dtl_rec.val_30 := p_data_element_value;
596  ELSIF l_seqnum_rec.seq_num = 31 THEN
597     p_ext_dtl_rec.val_31 := p_data_element_value;
598  ELSIF l_seqnum_rec.seq_num = 32 THEN
599     p_ext_dtl_rec.val_32 := p_data_element_value;
600  ELSIF l_seqnum_rec.seq_num = 33 THEN
601     p_ext_dtl_rec.val_33 := p_data_element_value;
602  ELSIF l_seqnum_rec.seq_num = 34 THEN
603     p_ext_dtl_rec.val_34 := p_data_element_value;
604  ELSIF l_seqnum_rec.seq_num = 35 THEN
605     p_ext_dtl_rec.val_35 := p_data_element_value;
606  ELSIF l_seqnum_rec.seq_num = 36 THEN
607     p_ext_dtl_rec.val_36 := p_data_element_value;
608  ELSIF l_seqnum_rec.seq_num = 37 THEN
609     p_ext_dtl_rec.val_37 := p_data_element_value;
610  ELSIF l_seqnum_rec.seq_num = 38 THEN
611     p_ext_dtl_rec.val_38 := p_data_element_value;
612  ELSIF l_seqnum_rec.seq_num = 39 THEN
613     p_ext_dtl_rec.val_39 := p_data_element_value;
614  ELSIF l_seqnum_rec.seq_num = 40 THEN
615     p_ext_dtl_rec.val_40 := p_data_element_value;
616  ELSIF l_seqnum_rec.seq_num = 41 THEN
617     p_ext_dtl_rec.val_41 := p_data_element_value;
618  ELSIF l_seqnum_rec.seq_num = 42 THEN
619     p_ext_dtl_rec.val_42 := p_data_element_value;
620  ELSIF l_seqnum_rec.seq_num = 43 THEN
621     p_ext_dtl_rec.val_43 := p_data_element_value;
622  ELSIF l_seqnum_rec.seq_num = 44 THEN
623     p_ext_dtl_rec.val_44 := p_data_element_value;
624  ELSIF l_seqnum_rec.seq_num = 45 THEN
625     p_ext_dtl_rec.val_45 := p_data_element_value;
626  ELSIF l_seqnum_rec.seq_num = 46 THEN
627     p_ext_dtl_rec.val_46 := p_data_element_value;
628  ELSIF l_seqnum_rec.seq_num = 47 THEN
629     p_ext_dtl_rec.val_47 := p_data_element_value;
630  ELSIF l_seqnum_rec.seq_num = 48 THEN
631     p_ext_dtl_rec.val_48 := p_data_element_value;
632  ELSIF l_seqnum_rec.seq_num = 49 THEN
633     p_ext_dtl_rec.val_49 := p_data_element_value;
634  ELSIF l_seqnum_rec.seq_num = 50 THEN
635     p_ext_dtl_rec.val_50 := p_data_element_value;
636  ELSIF l_seqnum_rec.seq_num = 51 THEN
637     p_ext_dtl_rec.val_51 := p_data_element_value;
638  ELSIF l_seqnum_rec.seq_num = 52 THEN
639     p_ext_dtl_rec.val_52 := p_data_element_value;
640  ELSIF l_seqnum_rec.seq_num = 53 THEN
641     p_ext_dtl_rec.val_53 := p_data_element_value;
642  ELSIF l_seqnum_rec.seq_num = 54 THEN
643     p_ext_dtl_rec.val_54 := p_data_element_value;
644  ELSIF l_seqnum_rec.seq_num = 55 THEN
645     p_ext_dtl_rec.val_55 := p_data_element_value;
646  ELSIF l_seqnum_rec.seq_num = 56 THEN
647     p_ext_dtl_rec.val_56 := p_data_element_value;
648  ELSIF l_seqnum_rec.seq_num = 57 THEN
649     p_ext_dtl_rec.val_57 := p_data_element_value;
650  ELSIF l_seqnum_rec.seq_num = 58 THEN
651     p_ext_dtl_rec.val_58 := p_data_element_value;
652  ELSIF l_seqnum_rec.seq_num = 58 THEN
653     p_ext_dtl_rec.val_58 := p_data_element_value;
654  ELSIF l_seqnum_rec.seq_num = 59 THEN
655     p_ext_dtl_rec.val_59 := p_data_element_value;
656  ELSIF l_seqnum_rec.seq_num = 60 THEN
657     p_ext_dtl_rec.val_60 := p_data_element_value;
658  ELSIF l_seqnum_rec.seq_num = 61 THEN
659     p_ext_dtl_rec.val_61 := p_data_element_value;
660  ELSIF l_seqnum_rec.seq_num = 62 THEN
661     p_ext_dtl_rec.val_62 := p_data_element_value;
662  ELSIF l_seqnum_rec.seq_num = 63 THEN
663     p_ext_dtl_rec.val_63 := p_data_element_value;
664  ELSIF l_seqnum_rec.seq_num = 64 THEN
665     p_ext_dtl_rec.val_64 := p_data_element_value;
666  ELSIF l_seqnum_rec.seq_num = 65 THEN
667     p_ext_dtl_rec.val_65 := p_data_element_value;
668  ELSIF l_seqnum_rec.seq_num = 66 THEN
669     p_ext_dtl_rec.val_66 := p_data_element_value;
670  ELSIF l_seqnum_rec.seq_num = 67 THEN
671     p_ext_dtl_rec.val_67 := p_data_element_value;
672  ELSIF l_seqnum_rec.seq_num = 68 THEN
673     p_ext_dtl_rec.val_68 := p_data_element_value;
674  ELSIF l_seqnum_rec.seq_num = 69 THEN
675     p_ext_dtl_rec.val_69 := p_data_element_value;
676  ELSIF l_seqnum_rec.seq_num = 70 THEN
677     p_ext_dtl_rec.val_70 := p_data_element_value;
678  ELSIF l_seqnum_rec.seq_num = 71 THEN
679     p_ext_dtl_rec.val_71 := p_data_element_value;
680  ELSIF l_seqnum_rec.seq_num = 72 THEN
681     p_ext_dtl_rec.val_72 := p_data_element_value;
682  ELSIF l_seqnum_rec.seq_num = 73 THEN
683     p_ext_dtl_rec.val_73 := p_data_element_value;
684  ELSIF l_seqnum_rec.seq_num = 74 THEN
685     p_ext_dtl_rec.val_74 := p_data_element_value;
686  ELSIF l_seqnum_rec.seq_num = 75 THEN
687     p_ext_dtl_rec.val_75 := p_data_element_value;
688  END IF;
689  Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
690  RETURN;
691 EXCEPTION
692   WHEN Others THEN
693     -- nocopy changes
694     p_ext_dtl_rec := l_ext_dtl_rec_nc;
695     RAISE;
696 
697 END Update_Record_Values;
698 
699 -- ============================================================================
700 -- ~ Ins_Rslt_Dtl : Inserts a record into the results detail record.
701 -- ============================================================================
702 PROCEDURE Ins_Rslt_Dtl(p_dtl_rec IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE) IS
703 
704 l_proc_name   Varchar2(150) := g_proc_name||'Ins_Rslt_Dtl';
705 l_dtl_rec_nc  ben_ext_rslt_dtl%ROWTYPE;
706 
707 BEGIN -- ins_rslt_dtl
708 --hr_utility.trace_on(null,'rk');
709   Hr_Utility.set_location('Entering :'||l_proc_name, 5);
710   -- nocopy changes
711   l_dtl_rec_nc := p_dtl_rec;
712   -- Get the next sequence NUMBER to insert a record into the table
713   SELECT ben_ext_rslt_dtl_s .NEXTVAL INTO p_dtl_rec.ext_rslt_dtl_id FROM dual;
714 hr_utility.set_location(p_dtl_rec.EXT_RSLT_DTL_ID,10);
715 hr_utility.set_location(p_dtl_rec.EXT_RSLT_ID,10);
716 hr_utility.set_location(p_dtl_rec.BUSINESS_GROUP_ID,10);
717 hr_utility.set_location(p_dtl_rec.EXT_RCD_ID,10);
718 hr_utility.set_location(p_dtl_rec.PERSON_ID,10);
719 hr_utility.set_location(p_dtl_rec.VAL_01,10);
720 hr_utility.set_location(p_dtl_rec.VAL_02,10);
721 hr_utility.set_location(p_dtl_rec.VAL_03,10);
722 hr_utility.set_location(p_dtl_rec.VAL_04,10);
723 hr_utility.set_location(p_dtl_rec.VAL_05,10);
724 hr_utility.set_location(p_dtl_rec.VAL_06,10);
725 hr_utility.set_location(p_dtl_rec.VAL_07,10);
726 hr_utility.set_location(p_dtl_rec.VAL_08,10);
727 hr_utility.set_location(p_dtl_rec.VAL_09,10);
728 hr_utility.set_location(p_dtl_rec.VAL_10,10);
729 hr_utility.set_location(p_dtl_rec.VAL_11,10);
730 hr_utility.set_location(p_dtl_rec.VAL_12,10);
731 hr_utility.set_location(p_dtl_rec.VAL_13,10);
732 hr_utility.set_location(p_dtl_rec.VAL_14,10);
733 hr_utility.set_location(p_dtl_rec.VAL_15,10);
734 hr_utility.set_location(p_dtl_rec.VAL_16,10);
735 hr_utility.set_location(p_dtl_rec.VAL_17,10);
736 hr_utility.set_location(p_dtl_rec.VAL_19,10);
737 hr_utility.set_location(p_dtl_rec.VAL_18,10);
738 hr_utility.set_location(p_dtl_rec.VAL_20,10);
739 hr_utility.set_location(p_dtl_rec.VAL_21,10);
740 hr_utility.set_location(p_dtl_rec.VAL_22,10);
741 hr_utility.set_location(p_dtl_rec.VAL_23,10);
742 hr_utility.set_location(p_dtl_rec.VAL_24,10);
743 hr_utility.set_location(p_dtl_rec.VAL_25,10);
744 hr_utility.set_location(p_dtl_rec.VAL_26,10);
745 hr_utility.set_location(p_dtl_rec.VAL_27,10);
746 hr_utility.set_location(p_dtl_rec.VAL_28,10);
747 hr_utility.set_location(p_dtl_rec.VAL_29,10);
748 hr_utility.set_location(p_dtl_rec.VAL_30,10);
749 hr_utility.set_location(p_dtl_rec.VAL_31,10);
750 hr_utility.set_location(p_dtl_rec.VAL_32,10);
751 hr_utility.set_location(p_dtl_rec.VAL_33,10);
752 hr_utility.set_location(p_dtl_rec.VAL_34,10);
753 hr_utility.set_location(p_dtl_rec.VAL_35,10);
754 hr_utility.set_location(p_dtl_rec.VAL_36,10);
755 hr_utility.set_location(p_dtl_rec.VAL_37,10);
756 hr_utility.set_location(p_dtl_rec.VAL_38,10);
757 hr_utility.set_location(p_dtl_rec.VAL_39,10);
758 hr_utility.set_location(p_dtl_rec.VAL_40,10);
759 hr_utility.set_location(p_dtl_rec.VAL_41,10);
760 hr_utility.set_location(p_dtl_rec.VAL_42,10);
761 hr_utility.set_location(p_dtl_rec.VAL_43,10);
762 hr_utility.set_location(p_dtl_rec.VAL_44,10);
763 hr_utility.set_location(p_dtl_rec.VAL_45,10);
764 hr_utility.set_location(p_dtl_rec.VAL_46,10);
765 hr_utility.set_location(p_dtl_rec.VAL_47,10);
766 hr_utility.set_location(p_dtl_rec.VAL_48,10);
767 hr_utility.set_location(p_dtl_rec.VAL_49,10);
768 hr_utility.set_location(p_dtl_rec.VAL_50,10);
769 hr_utility.set_location(p_dtl_rec.VAL_51,10);
770 hr_utility.set_location(p_dtl_rec.VAL_52,10);
771 hr_utility.set_location(p_dtl_rec.VAL_53,10);
772 hr_utility.set_location(p_dtl_rec.VAL_54,10);
773 hr_utility.set_location(p_dtl_rec.VAL_55,10);
774 hr_utility.set_location(p_dtl_rec.VAL_56,10);
775 hr_utility.set_location(p_dtl_rec.VAL_57,10);
776 hr_utility.set_location(p_dtl_rec.VAL_58,10);
777 hr_utility.set_location(p_dtl_rec.VAL_59,10);
778 hr_utility.set_location(p_dtl_rec.VAL_60,10);
779 hr_utility.set_location(p_dtl_rec.VAL_61,10);
780 hr_utility.set_location(p_dtl_rec.VAL_62,10);
781 hr_utility.set_location(p_dtl_rec.VAL_63,10);
782 hr_utility.set_location(p_dtl_rec.VAL_64,10);
783 hr_utility.set_location(p_dtl_rec.VAL_65,10);
784 hr_utility.set_location(p_dtl_rec.VAL_66,10);
785 hr_utility.set_location(p_dtl_rec.VAL_67,10);
786 hr_utility.set_location(p_dtl_rec.VAL_68,10);
787 hr_utility.set_location(p_dtl_rec.VAL_69,10);
788 hr_utility.set_location(p_dtl_rec.VAL_70,10);
789 hr_utility.set_location(p_dtl_rec.VAL_71,10);
790 hr_utility.set_location(p_dtl_rec.VAL_72,10);
791 hr_utility.set_location(p_dtl_rec.VAL_73,10);
792 hr_utility.set_location(p_dtl_rec.VAL_74,10);
793 hr_utility.set_location(p_dtl_rec.VAL_75,10);
794 hr_utility.set_location(p_dtl_rec.CREATED_BY,10);
795 hr_utility.set_location(p_dtl_rec.CREATION_DATE,10);
796 hr_utility.set_location(p_dtl_rec.LAST_UPDATE_DATE,10);
797 hr_utility .set_location(p_dtl_rec.LAST_UPDATED_BY,10);
798 hr_utility.set_location(p_dtl_rec.LAST_UPDATE_LOGIN,10);
799 hr_utility.set_location(p_dtl_rec.PROGRAM_APPLICATION_ID,10);
800 hr_utility.set_location(p_dtl_rec.PROGRAM_ID,10);
801 hr_utility.set_location(p_dtl_rec.PROGRAM_UPDATE_DATE,10);
802 hr_utility.set_location(p_dtl_rec.REQUEST_ID,10);
803 hr_utility.set_location(p_dtl_rec.OBJECT_VERSION_NUMBER,10);
804 hr_utility.set_location(p_dtl_rec.PRMY_SORT_VAL,10);
805 hr_utility.set_location(p_dtl_rec.SCND_SORT_VAL,10);
806 hr_utility.set_location(p_dtl_rec.THRD_SORT_VAL,10);
807 hr_utility.set_location(p_dtl_rec.TRANS_SEQ_NUM,10);
808 hr_utility.set_location(p_dtl_rec.RCRD_SEQ_NUM,10);
809   INSERT INTO ben_ext_rslt_dtl
810   (EXT_RSLT_DTL_ID
811   ,EXT_RSLT_ID
812   ,BUSINESS_GROUP_ID
813   ,EXT_RCD_ID
814   ,PERSON_ID
815   ,VAL_01
816   ,VAL_02
817   ,VAL_03
818   ,VAL_04
819   ,VAL_05
820   ,VAL_06
821   ,VAL_07
822   ,VAL_08
823   ,VAL_09
824   ,VAL_10
825   ,VAL_11
826   ,VAL_12
827   ,VAL_13
828   ,VAL_14
829   ,VAL_15
830   ,VAL_16
831   ,VAL_17
832   ,VAL_19
833   ,VAL_18
834   ,VAL_20
835   ,VAL_21
836   ,VAL_22
837   ,VAL_23
838   ,VAL_24
839   ,VAL_25
840   ,VAL_26
841   ,VAL_27
842   ,VAL_28
843   ,VAL_29
844   ,VAL_30
845   ,VAL_31
846   ,VAL_32
847   ,VAL_33
848   ,VAL_34
849   ,VAL_35
850   ,VAL_36
851   ,VAL_37
852   ,VAL_38
853   ,VAL_39
854   ,VAL_40
855   ,VAL_41
856   ,VAL_42
857   ,VAL_43
858   ,VAL_44
859   ,VAL_45
860   ,VAL_46
861   ,VAL_47
862   ,VAL_48
863   ,VAL_49
864   ,VAL_50
865   ,VAL_51
866   ,VAL_52
867   ,VAL_53
868   ,VAL_54
869   ,VAL_55
870   ,VAL_56
871   ,VAL_57
872   ,VAL_58
873   ,VAL_59
874   ,VAL_60
875   ,VAL_61
876   ,VAL_62
877   ,VAL_63
878   ,VAL_64
879   ,VAL_65
880   ,VAL_66
881   ,VAL_67
882   ,VAL_68
883   ,VAL_69
884   ,VAL_70
885   ,VAL_71
886   ,VAL_72
887   ,VAL_73
888   ,VAL_74
889   ,VAL_75
890   ,CREATED_BY
891   ,CREATION_DATE
892   ,LAST_UPDATE_DATE
893   ,LAST_UPDATED_BY
894   ,LAST_UPDATE_LOGIN
895   ,PROGRAM_APPLICATION_ID
896   ,PROGRAM_ID
897   ,PROGRAM_UPDATE_DATE
898   ,REQUEST_ID
899   ,OBJECT_VERSION_NUMBER
900   ,PRMY_SORT_VAL
901   ,SCND_SORT_VAL
902   ,THRD_SORT_VAL
903   ,TRANS_SEQ_NUM
904   ,RCRD_SEQ_NUM
905   )
906   VALUES
907   ( p_dtl_rec.EXT_RSLT_DTL_ID
908   , p_dtl_rec.EXT_RSLT_ID
909   , p_dtl_rec.BUSINESS_GROUP_ID
910   , p_dtl_rec.EXT_RCD_ID
911   , p_dtl_rec.PERSON_ID
912   ,p_dtl_rec.VAL_01
913   ,p_dtl_rec.VAL_02
914   ,p_dtl_rec.VAL_03
915   ,p_dtl_rec.VAL_04
916   ,p_dtl_rec.VAL_05
917   ,p_dtl_rec.VAL_06
918   ,p_dtl_rec.VAL_07
919   ,p_dtl_rec.VAL_08
920   ,p_dtl_rec.VAL_09
921   ,p_dtl_rec.VAL_10
922   ,p_dtl_rec.VAL_11
923   ,p_dtl_rec.VAL_12
924   ,p_dtl_rec.VAL_13
925   ,p_dtl_rec.VAL_14
926   ,p_dtl_rec.VAL_15
927   ,p_dtl_rec.VAL_16
928   ,p_dtl_rec.VAL_17
929   ,p_dtl_rec.VAL_19
930   ,p_dtl_rec.VAL_18
931   ,p_dtl_rec.VAL_20
932   ,p_dtl_rec.VAL_21
933   ,p_dtl_rec.VAL_22
934   ,p_dtl_rec.VAL_23
935   ,p_dtl_rec.VAL_24
936   ,p_dtl_rec.VAL_25
937   ,p_dtl_rec.VAL_26
938   ,p_dtl_rec.VAL_27
939   ,p_dtl_rec.VAL_28
940   ,p_dtl_rec.VAL_29
941   ,p_dtl_rec.VAL_30
942   ,p_dtl_rec.VAL_31
943   ,p_dtl_rec.VAL_32
944   ,p_dtl_rec.VAL_33
945   ,p_dtl_rec.VAL_34
946   ,p_dtl_rec.VAL_35
947   ,p_dtl_rec.VAL_36
948   ,p_dtl_rec.VAL_37
949   ,p_dtl_rec.VAL_38
950   ,p_dtl_rec.VAL_39
951   ,p_dtl_rec.VAL_40
952   ,p_dtl_rec.VAL_41
953   ,p_dtl_rec.VAL_42
954   ,p_dtl_rec.VAL_43
955   ,p_dtl_rec.VAL_44
956   ,p_dtl_rec.VAL_45
957   ,p_dtl_rec.VAL_46
958   ,p_dtl_rec.VAL_47
959   ,p_dtl_rec.VAL_48
960   ,p_dtl_rec.VAL_49
961   ,p_dtl_rec.VAL_50
962   ,p_dtl_rec.VAL_51
963   ,p_dtl_rec.VAL_52
964   ,p_dtl_rec.VAL_53
965   ,p_dtl_rec.VAL_54
966   ,p_dtl_rec.VAL_55
967   ,p_dtl_rec.VAL_56
968   ,p_dtl_rec.VAL_57
969   ,p_dtl_rec.VAL_58
970   ,p_dtl_rec.VAL_59
971   ,p_dtl_rec.VAL_60
972   ,p_dtl_rec.VAL_61
973   ,p_dtl_rec.VAL_62
974   ,p_dtl_rec.VAL_63
975   ,p_dtl_rec.VAL_64
976   ,p_dtl_rec.VAL_65
977   ,p_dtl_rec.VAL_66
978   ,p_dtl_rec.VAL_67
979   ,p_dtl_rec.VAL_68
980   ,p_dtl_rec.VAL_69
981   ,p_dtl_rec.VAL_70
982   ,p_dtl_rec.VAL_71
983   ,p_dtl_rec.VAL_72
984   ,p_dtl_rec.VAL_73
985   ,p_dtl_rec.VAL_74
986   ,p_dtl_rec.VAL_75
987   ,p_dtl_rec.CREATED_BY
988   ,p_dtl_rec.CREATION_DATE
989   ,p_dtl_rec.LAST_UPDATE_DATE
990   ,p_dtl_rec.LAST_UPDATED_BY
991   ,p_dtl_rec.LAST_UPDATE_LOGIN
992   ,p_dtl_rec.PROGRAM_APPLICATION_ID
993   ,p_dtl_rec.PROGRAM_ID
994   ,p_dtl_rec.PROGRAM_UPDATE_DATE
995   ,p_dtl_rec.REQUEST_ID
996   ,p_dtl_rec.OBJECT_VERSION_NUMBER
997   ,p_dtl_rec.PRMY_SORT_VAL
998   ,p_dtl_rec.SCND_SORT_VAL
999   ,p_dtl_rec.THRD_SORT_VAL
1000   ,p_dtl_rec.TRANS_SEQ_NUM
1001   ,p_dtl_rec.RCRD_SEQ_NUM
1002   );
1003   Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
1004  -- hr_utility.trace_off;
1005   RETURN;
1006 
1007 EXCEPTION
1008   WHEN Others THEN
1009     Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
1010     p_dtl_rec := l_dtl_rec_nc;
1011     RAISE;
1012 END Ins_Rslt_Dtl;
1013 
1014 -- ============================================================================
1015 -- ~ Upd_Rslt_Dtl : Updates the primary assignment record in results detail table
1016 -- ============================================================================
1017 PROCEDURE Upd_Rslt_Dtl(p_dtl_rec IN ben_ext_rslt_dtl %ROWTYPE ) IS
1018 
1019 l_proc_name Varchar2(150):= g_proc_name||'upd_rslt_dtl';
1020 
1021 BEGIN -- Upd_Rslt_Dtl
1022   UPDATE ben_ext_rslt_dtl
1023   SET VAL_01                 = p_dtl_rec.VAL_01
1024      ,VAL_02                 = p_dtl_rec.VAL_02
1025      ,VAL_03                 = p_dtl_rec.VAL_03
1026      ,VAL_04                 = p_dtl_rec.VAL_04
1027      ,VAL_05                 = p_dtl_rec.VAL_05
1028      ,VAL_06                 = p_dtl_rec.VAL_06
1029      ,VAL_07                 = p_dtl_rec.VAL_07
1030      ,VAL_08                 = p_dtl_rec.VAL_08
1031      ,VAL_09                 = p_dtl_rec.VAL_09
1032      ,VAL_10                 = p_dtl_rec.VAL_10
1033      ,VAL_11                 = p_dtl_rec.VAL_11
1034      ,VAL_12                 = p_dtl_rec.VAL_12
1035      ,VAL_13                 = p_dtl_rec.VAL_13
1036      ,VAL_14                 = p_dtl_rec.VAL_14
1037      ,VAL_15                 = p_dtl_rec.VAL_15
1038      ,VAL_16                 = p_dtl_rec.VAL_16
1039      ,VAL_17                 = p_dtl_rec.VAL_17
1040      ,VAL_19                 = p_dtl_rec.VAL_19
1041      ,VAL_18                 = p_dtl_rec.VAL_18
1042      ,VAL_20                 = p_dtl_rec.VAL_20
1043      ,VAL_21                 = p_dtl_rec.VAL_21
1044      ,VAL_22                 = p_dtl_rec.VAL_22
1045      ,VAL_23                 = p_dtl_rec.VAL_23
1046      ,VAL_24                 = p_dtl_rec.VAL_24
1047      ,VAL_25                 = p_dtl_rec.VAL_25
1048      ,VAL_26                 = p_dtl_rec.VAL_26
1049      ,VAL_27                 = p_dtl_rec.VAL_27
1050      ,VAL_28                 = p_dtl_rec.VAL_28
1051      ,VAL_29                 = p_dtl_rec.VAL_29
1052      ,VAL_30                 = p_dtl_rec.VAL_30
1053      ,VAL_31                 = p_dtl_rec.VAL_31
1054      ,VAL_32                 = p_dtl_rec.VAL_32
1055      ,VAL_33                 = p_dtl_rec.VAL_33
1056      ,VAL_34                 = p_dtl_rec.VAL_34
1057      ,VAL_35                 = p_dtl_rec.VAL_35
1058      ,VAL_36                 = p_dtl_rec.VAL_36
1059      ,VAL_37                 = p_dtl_rec.VAL_37
1060      ,VAL_38                 = p_dtl_rec.VAL_38
1061      ,VAL_39                 = p_dtl_rec.VAL_39
1062      ,VAL_40                 = p_dtl_rec.VAL_40
1063      ,VAL_41                 = p_dtl_rec.VAL_41
1064      ,VAL_42                 = p_dtl_rec.VAL_42
1065      ,VAL_43                 = p_dtl_rec.VAL_43
1066      ,VAL_44                 = p_dtl_rec.VAL_44
1067      ,VAL_45                 = p_dtl_rec.VAL_45
1068      ,VAL_46                 = p_dtl_rec.VAL_46
1069      ,VAL_47                 = p_dtl_rec.VAL_47
1070      ,VAL_48                 = p_dtl_rec.VAL_48
1071      ,VAL_49                 = p_dtl_rec.VAL_49
1072      ,VAL_50                 = p_dtl_rec.VAL_50
1073      ,VAL_51                 = p_dtl_rec.VAL_51
1074      ,VAL_52                 = p_dtl_rec.VAL_52
1075      ,VAL_53                 = p_dtl_rec.VAL_53
1076      ,VAL_54                 = p_dtl_rec.VAL_54
1077      ,VAL_55                 = p_dtl_rec.VAL_55
1078      ,VAL_56                 = p_dtl_rec.VAL_56
1079      ,VAL_57                 = p_dtl_rec.VAL_57
1080      ,VAL_58                 = p_dtl_rec.VAL_58
1081      ,VAL_59                 = p_dtl_rec.VAL_59
1082      ,VAL_60                 = p_dtl_rec.VAL_60
1083      ,VAL_61                 = p_dtl_rec.VAL_61
1084      ,VAL_62                 = p_dtl_rec.VAL_62
1085      ,VAL_63                 = p_dtl_rec.VAL_63
1086      ,VAL_64                 = p_dtl_rec.VAL_64
1087      ,VAL_65                 = p_dtl_rec.VAL_65
1088      ,VAL_66                 = p_dtl_rec.VAL_66
1089      ,VAL_67                 = p_dtl_rec.VAL_67
1090      ,VAL_68                 = p_dtl_rec.VAL_68
1091      ,VAL_69                 = p_dtl_rec.VAL_69
1092      ,VAL_70                 = p_dtl_rec.VAL_70
1093      ,VAL_71                 = p_dtl_rec.VAL_71
1094      ,VAL_72                 = p_dtl_rec.VAL_72
1095      ,VAL_73                 = p_dtl_rec.VAL_73
1096      ,VAL_74                 = p_dtl_rec.VAL_74
1097      ,VAL_75                 = p_dtl_rec.VAL_75
1098      ,OBJECT_VERSION_NUMBER  = p_dtl_rec.OBJECT_VERSION_NUMBER
1099      ,THRD_SORT_VAL          = p_dtl_rec.THRD_SORT_VAL
1100      ,prmy_sort_val          =p_dtl_rec.prmy_sort_val
1101   WHERE ext_rslt_dtl_id = p_dtl_rec.ext_rslt_dtl_id;
1102 
1103   RETURN;
1104 
1105 EXCEPTION
1106   WHEN Others THEN
1107      RAISE;
1108 END Upd_Rslt_Dtl;
1109 
1110 -- ===============================================================================
1111 -- ~ Get_Balance_Value
1112 -- ===============================================================================
1113 FUNCTION Get_Balance_Value ( p_assignment_id         IN Number  ,
1114                              p_business_group_id     IN Number  ,
1115                              p_balance_name          IN VARCHAR2,
1116                              p_dimension_name        IN VARCHAR2,
1117                              p_start_date            IN DATE    ,
1118                              p_end_date              IN DATE
1119      			    )
1120 RETURN NUMBER IS
1121 
1122 CURSOR csr_get_def_bal_type_id(c_balance_name VARCHAR2,c_dimension_name VARCHAR2)  IS
1123 SELECT defined_balance_id
1124 FROM  pay_defined_balances pdb,
1125       pay_balance_types pbt,
1126       pay_balance_dimensions pbd
1127 WHERE pbt.balance_name =c_balance_name
1128   AND pbd.legislation_code='NL'
1129   AND pbd.DIMENSION_NAME=c_dimension_name
1130   AND pdb.balance_type_id = pbt.balance_type_id
1131   AND pdb.balance_dimension_id = pbd.balance_dimension_id;
1132 
1133 l_proc_name           Varchar2(150) :=g_proc_name || 'Get_Balance_Value';
1134 l_def_bal_type_id NUMBER:=0;
1135 l_balance_amount  NUMBER:=0;
1136 l_bal_total_amt   NUMBER:=0;
1137 asgact_rec        csr_asg_act%ROWTYPE;
1138 BEGIN
1139 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
1140 
1141 OPEN csr_get_def_bal_type_id(p_balance_name,p_dimension_name);
1142 FETCH csr_get_def_bal_type_id INTO l_def_bal_type_id;
1143 CLOSE csr_get_def_bal_type_id;
1144 Hr_Utility.set_location(' l_def_bal_type_id '   ||l_def_bal_type_id,15);
1145   IF l_def_bal_type_id IS NOT NULL THEN
1146   --Get the Assignment action ids for this assignment
1147         OPEN csr_asg_act(c_assignment_id => p_assignment_id
1148                    ,c_payroll_id    => g_extract_params (p_business_group_id).payroll_id
1149                    ,c_con_set_id    => g_extract_params (p_business_group_id).con_set_id
1150                    ,c_start_date    => p_start_date
1151                    ,c_end_date      => p_end_date
1152                    );
1153          LOOP
1154             FETCH csr_asg_act INTO asgact_rec;
1155             EXIT WHEN csr_asg_act%NOTFOUND;
1156             l_balance_amount := Pay_Balance_Pkg.get_value
1157                       (p_defined_balance_id   => l_def_bal_type_id,
1158                        p_assignment_action_id => asgact_rec.assignment_action_id );
1159             l_bal_total_amt := l_bal_total_amt + Nvl(l_balance_amount,0);
1160             Hr_Utility.set_location(' l_balance_amount '  ||l_balance_amount,25);
1161             Hr_Utility.set_location(' l_bal_total_amt  '   ||l_bal_total_amt,25);
1162          END LOOP; -- For Loop
1163          CLOSE csr_asg_act;
1164     END IF;  -- If l_def_bal_type_id
1165 
1166 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
1167 RETURN l_bal_total_amt;
1168 
1169 EXCEPTION
1170    WHEN OTHERS THEN
1171       --p_error_message :='SQL-ERRM :'||SQLERRM;
1172       CLOSE csr_asg_act;
1173       Hr_Utility.set_location('..'||'SQL-ERRM :'||SQLERRM,30);
1174       Hr_Utility.set_location('Exception Occured Leaving: '||l_proc_name,40);
1175       RETURN 0;
1176 END Get_Balance_Value;
1177 
1178 -- ===============================================================================
1179 -- ~ Get_Start_Date_PTP : function to get the Start Date of paticiaption
1180 --  which is taken as Start date of PGGM GEN Info element entry for that assignment
1181 -- ===============================================================================
1182 FUNCTION Get_Start_Date_PTP
1183                  (  p_assignment_id       IN Number
1184                    ,p_business_group_id   IN Number
1185                    ,p_date_earned         IN DATE
1186                    ,p_error_message       OUT NOCOPY VARCHAR2
1187                    ,p_data_element_value  OUT NOCOPY VARCHAR2
1188                  )
1189 RETURN NUMBER IS
1190 CURSOR csr_get_st_dt_of_ptp(c_asg_id IN Number,c_date_earned IN Date) IS
1191 SELECT to_char(pee.effective_start_date,'YYYYMMDD')
1192   FROM pay_element_types_f pet, pay_element_entries_f pee
1193  WHERE pet.element_name like 'PGGM Pensions General Information'
1194    AND pee.element_type_id =pet.element_type_id
1195    AND pee.assignment_id=c_asg_id
1196    AND pee.effective_start_date <= g_extract_params(p_business_group_id).extract_end_date;
1197 
1198 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Start_Date_PTP';
1199 l_ret_val      Number:=0;
1200 l_st_dt_of_ptp varchar2(8);
1201 --
1202 BEGIN
1203  Hr_Utility.set_location('Entering:   '||l_proc_name, 10);
1204  OPEN csr_get_st_dt_of_ptp(p_assignment_id,p_date_earned);
1205  FETCH csr_get_st_dt_of_ptp INTO l_st_dt_of_ptp;
1206  Hr_Utility.set_location('l_st_dt_of_ptp:   '||l_st_dt_of_ptp, 20);
1207  IF (csr_get_st_dt_of_ptp%FOUND) THEN
1208     p_data_element_value:=l_st_dt_of_ptp;
1209     l_ret_val:=0;
1210  END IF;
1211  Hr_Utility.set_location('p_data_element_value:   '||p_data_element_value, 30);
1212  CLOSE csr_get_st_dt_of_ptp;
1213  Hr_Utility.set_location('Leaving:   '||l_proc_name, 60);
1214 RETURN l_ret_val;
1215 EXCEPTION
1216    WHEN Others THEN
1217     p_error_message :='SQL-ERRM :'||SQLERRM;
1218     Hr_Utility.set_location('..'||p_error_message,85);
1219     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1220     RETURN -1;
1221 END Get_Start_Date_PTP;
1222 
1223 -- ===============================================================================
1224 --Get a string of Zeros of required length
1225 -- ===============================================================================
1226 FUNCTION Get_Zeros_String(Num NUMBER)
1227 RETURN varchar2 IS
1228 zeros    varchar2(250):='';
1229 BEGIN
1230 
1231       FOR i IN 0..Num-1
1232       LOOP
1233        zeros:=zeros||'0';
1234       END LOOP;
1235       RETURN zeros;
1236 
1237 END Get_Zeros_String;
1238 
1239 -- =============================================================================
1240 -- Process_Ext_Rslt_Dtl_Rec:
1241 -- =============================================================================
1242 PROCEDURE  Process_Ext_Rslt_Dtl_Rec
1243             (p_assignment_id    IN per_all_assignments.assignment_id%TYPE
1244             ,p_organization_id  IN per_all_assignments.organization_id%TYPE DEFAULT NULL
1245             ,p_effective_date   IN Date
1246             ,p_ext_dtl_rcd_id   IN ben_ext_rcd.ext_rcd_id%TYPE
1247             ,p_rslt_rec         IN OUT NOCOPY ben_ext_rslt_dtl%ROWTYPE
1248             ,p_asgaction_no     IN Number  DEFAULT NULL
1249             ,p_error_message    OUT NOCOPY Varchar2) IS
1250 
1251  CURSOR csr_rule_ele
1252           (c_ext_rcd_id  IN ben_ext_data_elmt_in_rcd.ext_rcd_id%TYPE) IS
1253    SELECT  a.ext_data_elmt_in_rcd_id
1254           ,a.seq_num
1255           ,a.sprs_cd
1256           ,a.strt_pos
1257           ,a.dlmtr_val
1258           ,a.rqd_flag
1259           ,b.ext_data_elmt_id
1260           ,b.data_elmt_typ_cd
1261           ,b.data_elmt_rl
1262           ,b.NAME
1263           ,Hr_General.decode_lookup('BEN_EXT_FRMT_MASK', b.frmt_mask_cd) frmt_mask_cd
1264           ,b.frmt_mask_cd frmt_mask_lookup_cd
1265           ,b.string_val
1266           ,b.dflt_val
1267           ,b.max_length_num
1268           ,b.just_cd
1269      FROM  ben_ext_data_elmt           b,
1270            ben_ext_data_elmt_in_rcd    a
1271     WHERE  a.ext_data_elmt_id = b.ext_data_elmt_id
1272       AND  b.data_elmt_typ_cd = 'R'
1273       AND  a.ext_rcd_id       = c_ext_rcd_id
1274       --  AND  a.hide_flag        = 'N'
1275      ORDER BY a.seq_num;
1276 
1277    CURSOR csr_ff_type ( c_formula_type_id IN ff_formulas_f.formula_id%TYPE
1278                        ,c_effective_date     IN Date) IS
1279     SELECT formula_type_id
1280       FROM ff_formulas_f
1281      WHERE formula_id = c_formula_type_id
1282        AND c_effective_date BETWEEN effective_start_date
1283                                 AND effective_end_date;
1284 
1285    CURSOR c_get_org_id IS
1286    SELECT organization_id,business_group_id
1287      FROM per_all_assignments_f
1288    WHERE  assignment_id = p_assignment_id
1289      AND  business_group_id = g_business_group_id
1290      AND  p_effective_date BETWEEN effective_start_date
1291                                 AND effective_end_date;
1292 
1293 
1294 
1295   l_proc_name           Varchar2(150) := g_proc_name ||'Process_Ext_Rslt_Dtl_Rec';
1296   l_formula_type_id     ff_formulas_f.formula_id%TYPE;
1297   l_outputs             Ff_Exec.outputs_t;
1298   l_ff_value            ben_ext_rslt_dtl.val_01%TYPE;
1299   l_ff_value_fmt        ben_ext_rslt_dtl.val_01%TYPE;
1300   l_org_id              per_all_assignments_f.organization_id%TYPE;
1301   l_bgid                per_all_assignments_f.business_group_id%TYPE;
1302 
1303 
1304 BEGIN
1305    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1306    OPEN c_get_org_id;
1307    FETCH c_get_org_id INTO l_org_id,l_bgid;
1308    CLOSE c_get_org_id;
1309    Hr_Utility.set_location('p_ext_dtl_rcd_id: '||p_ext_dtl_rcd_id , 5);
1310    Hr_Utility .set_location('p_assignment_id: '||p_assignment_id, 5);
1311    FOR i IN  csr_rule_ele( c_ext_rcd_id => p_ext_dtl_rcd_id )
1312    LOOP
1313     OPEN  csr_ff_type (c_formula_type_id => i.data_elmt_rl
1314                      ,c_effective_date  => p_effective_date);
1315     FETCH csr_ff_type  INTO l_formula_type_id ;
1316     CLOSE csr_ff_type;
1317     Hr_Utility.set_location('l_formula_type_id: '||l_formula_type_id, 5);
1318 
1319     IF l_formula_type_id = -413 THEN -- person level rule
1320        l_outputs :=  Benutils.formula
1321                    (p_formula_id         => i.data_elmt_rl
1322                    ,p_effective_date     => p_effective_date
1323                    ,p_assignment_id      => p_assignment_id
1324                    ,p_organization_id    => p_organization_id
1325                    ,p_business_group_id  => g_business_group_id
1326                    ,p_jurisdiction_code  => null
1327                    ,p_param1             => 'EXT_DFN_ID'
1328                    ,p_param1_value       => to_char(nvl(ben_ext_thread.g_ext_dfn_id, -1))
1329                    ,p_param2             => 'EXT_RSLT_ID'
1330                    ,p_param2_value       => to_char(nvl(ben_ext_thread.g_ext_rslt_id, -1))
1331                    ,p_param3             => 'EXT_PERSON_ID'
1332                    ,p_param3_value       => to_char(nvl(ben_ext_person.g_person_id, -1))
1333                    ,p_param4             => 'EXT_PROCESS_BUSINESS_GROUP'
1334                    ,p_param4_value       =>  to_char(g_business_group_id)
1335                    ,p_param5             => 'EXT_USER_VALUE'
1336                    ,p_param5_value       =>  i.String_Val
1337                    );
1338         l_ff_value := l_outputs(l_outputs.FIRST).VALUE;
1339         BEGIN
1340           IF i.frmt_mask_lookup_cd IS NOT NULL AND
1341              l_ff_value IS NOT NULL THEN
1342              IF Substr(i.frmt_mask_lookup_cd,1,1) = 'N' THEN
1343                Hr_Utility.set_location('..Applying NUMBER format mask  :ben_ext_fmt.apply_format_mask'   ,50);
1344                l_ff_value_fmt := Ben_Ext_Fmt .apply_format_mask (To_Number(l_ff_value), i.frmt_mask_cd);
1345                l_ff_value     := l_ff_value_fmt;
1346             ELSIF Substr(i.frmt_mask_lookup_cd,1,1) = 'D' THEN
1347                Hr_Utility.set_location('..Applying Date format mask :ben_ext_fmt.apply_format_mask'   ,55);
1348                l_ff_value_fmt := Ben_Ext_Fmt .apply_format_mask (Fnd_Date.canonical_to_date(l_ff_value),
1349                                                                i.frmt_mask_cd);
1350                l_ff_value     := l_ff_value_fmt;
1351             END IF;
1352           END  IF;
1353         EXCEPTION  -- incase l_ff_value is not valid for formatting, just don't format it.
1354             WHEN Others THEN
1355             NULL;
1356         END;
1357         Update_Record_Values (p_ext_rcd_id            => p_ext_dtl_rcd_id
1358                              ,p_ext_data_element_name => NULL
1359                              ,p_data_element_value    => l_ff_value
1360                              ,p_data_ele_seqnum       => i.seq_num
1361                              ,p_ext_dtl_rec           => p_rslt_rec);
1362     END IF;
1363    END LOOP; --For i in  csr_rule_ele
1364    p_rslt_rec.prmy_sort_val := p_assignment_id;
1365    Ins_Rslt_Dtl(p_dtl_rec => p_rslt_rec);
1366    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
1367 EXCEPTION
1368    WHEN Others THEN
1369     Hr_Utility.set_location('..error',85);
1370     Hr_Utility.set_location('SQL-ERRM :'||SQLERRM,87);
1371     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1372 END Process_Ext_Rslt_Dtl_Rec;
1373 
1374 -- =============================================================================
1375 -- Check_Addl_Assigs: Check if the person has any secondary active assigs within
1376 -- the extract date range, then check the criteria and store it in PL/SQL table.
1377 -- =============================================================================
1378 FUNCTION Check_Addl_Assigs
1379            (p_assignment_id       IN         Number
1380            ,p_business_group_id   IN         Number
1381            ,p_effective_date      IN         Date
1382            ,p_error_message       OUT NOCOPY Varchar2
1383            ) RETURN Varchar2 IS
1384 
1385    l_return_value         Varchar2(50);
1386    bg_id                      per_all_assignments_f.business_group_id%TYPE;
1387    l_proc_name            Varchar2(150) := g_proc_name ||'Check_Addl_Assigs';
1388    l_sec_assg_rec         csr_sec_assg%ROWTYPE;
1389    l_effective_date       Date;
1390    l_criteria_value       Varchar2(2);
1391    l_warning_message      Varchar2(2000);
1392    l_error_message        Varchar2(2000);
1393    l_asg_type             per_all_assignments_f.assignment_type%TYPE;
1394    l_person_id            per_all_people_f.person_id%TYPE;
1395    l_assignment_id        per_all_assignments_f.assignment_id%TYPE;
1396 BEGIN
1397    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1398    bg_id := p_business_group_id;
1399 
1400    IF NOT g_primary_assig.EXISTS(p_assignment_id) THEN
1401      l_return_value := 'NOTFOUND';
1402      Hr_Utility.set_location('..Not a Valid assignment: '||p_assignment_id, 6);
1403      RETURN l_return_value;
1404    ELSIF g_primary_assig (p_assignment_id).assignment_type IN ('B','E') THEN
1405      Hr_Utility.set_location('..Valid Assignment Type B : '||p_assignment_id, 6);
1406      l_person_id := g_primary_assig (p_assignment_id).person_id;
1407      l_asg_type  := g_primary_assig (p_assignment_id).assignment_type;
1408      -- Check if there are any other assignments which might be active within the
1409      -- specified extract date range
1410      FOR sec_asg_rec IN  csr_sec_assg
1411          (c_primary_assignment_id=> p_assignment_id
1412          ,c_person_id => g_primary_assig (p_assignment_id).person_id
1413          ,c_effective_date     => g_extract_params (bg_id).extract_end_date
1414          ,c_extract_start_date   => g_extract_params(bg_id).extract_start_date
1415          ,c_extract_end_date     => g_extract_params(bg_id).extract_end_date)
1416      LOOP
1417        l_sec_assg_rec   := sec_asg_rec;
1418        l_criteria_value := 'N';
1419        l_effective_date := Least(g_extract_params (bg_id).extract_end_date,
1420                                  l_sec_assg_rec.effective_end_date);
1421        Hr_Utility.set_location('..Checking for assignment id: '||
1422                              l_sec_assg_rec.assignment_id, 7);
1423        Hr_Utility.set_location('..p_effective_date : '||l_effective_date, 7);
1424        -- Call the main criteria function for this assignment to check if its a
1425        -- valid assignment that can be reported based on the criteria specified.
1426        --Note that this function adds the assignment id in its PL SQL table
1427        l_criteria_value := Pension_Criteria_Full_Profile
1428                           (p_assignment_id        => l_sec_assg_rec.assignment_id
1429                           ,p_effective_date       => l_effective_date
1430                           ,p_business_group_id    => p_business_group_id
1431                           ,p_warning_message      => l_warning_message
1432                           ,p_error_message        => l_error_message
1433                            );
1434        IF l_criteria_value ='Y' THEN
1435      l_return_value := 'FOUND';
1436    END IF;
1437      END LOOP; -- FOR sec_asg_rec
1438    END IF;
1439    Hr_Utility.set_location('..Assignment Count : '||g_primary_assig.Count, 7);
1440    Hr_Utility.set_location('..l_person_id : '||l_person_id, 7);
1441    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1442    RETURN l_return_value;
1443 EXCEPTION
1444    WHEN Others THEN
1445     p_error_message :='SQL-ERRM :'||SQLERRM;
1446     Hr_Utility.set_location('..'||p_error_message,85);
1447     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1448     RETURN l_return_value;
1449 END Check_Addl_Assigs;
1450 
1451 -- =============================================================================
1452 -- Create_Addl_Assignments:
1453 -- =============================================================================
1454 PROCEDURE Create_Addl_Assignments
1455           (p_assignment_id     IN Number
1456           ,p_business_group_id IN Number
1457           ,p_person_id         IN Number
1458           ,p_no_asg_action     IN OUT NOCOPY Number
1459           ,p_error_message     OUT NOCOPY Varchar2)IS
1460 
1461    l_ele_type_id         pay_element_types_f.element_type_id %TYPE;
1462    l_prev_ele_type_id    pay_element_types_f.element_type_id %TYPE;
1463    l_valid_action        Varchar2(2);
1464    bg_id                     per_all_assignments_f.business_group_id%TYPE;
1465    l_ext_dfn_type        pqp_extract_attributes.ext_dfn_type  %TYPE;
1466    l_proc_name           Varchar2(150) := g_proc_name ||'Create_Addl_Assignments';
1467    l_assignment_id       per_all_assignments_f.assignment_id%TYPE;
1468    l_organization_id     per_all_assignments_f.organization_id%TYPE;
1469    l_business_group_id   per_all_assignments_f.business_group_id%TYPE;
1470    l_main_rec            csr_rslt_dtl%ROWTYPE;
1471    l_new_rec             csr_rslt_dtl%ROWTYPE;
1472    l_effective_date      Date;
1473    l_ext_rcd_id          ben_ext_rcd.ext_rcd_id %TYPE;
1474    l_record_num          Varchar2(20);
1475    l_return_value        Varchar2(2);
1476    l_conc_reqest_id      NUMBER;
1477    l_ext_rslt_id         NUMBER;
1478    l_ext_dfn_id          NUMBER;
1479 
1480 BEGIN
1481    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1482    bg_id := p_business_group_id;
1483    l_ext_rslt_id := Ben_Ext_Thread.g_ext_rslt_id;
1484    l_ext_dfn_id  := Ben_Ext_Thread.g_ext_dfn_id;
1485 
1486    -- Get the Conc. request id
1487    OPEN  csr_req_id(c_ext_rslt_id       => l_ext_rslt_id
1488                     ,c_ext_dfn_id        => l_ext_dfn_id
1489                     ,c_business_group_id => p_business_group_id);
1490    FETCH csr_req_id INTO l_conc_reqest_id;
1491    CLOSE csr_req_id;
1492 
1493    FOR csr_rcd_rec IN csr_ext_rcd_id_hidden
1494                        (c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
1495    LOOP
1496       l_ext_rcd_id := csr_rcd_rec.ext_rcd_id;
1497 
1498      Hr_Utility.set_location('l_ext_rcd_id: '||l_ext_rcd_id, 5);
1499 
1500     --These are single processing reCords
1501     IF g_ext_rcds(l_ext_rcd_id ).record_number  IN
1502       ('010','10h','020','030','040','060','070','080','081')THEN
1503         l_record_num := g_ext_rcds(l_ext_rcd_id).record_number;
1504         Hr_Utility.set_location('l_record_num: '||l_record_num, 5);
1505         OPEN csr_rslt_dtl
1506                (c_person_id      => p_person_id
1507                ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
1508                ,c_ext_dtl_rcd_id => l_ext_rcd_id
1509                 );
1510         FETCH csr_rslt_dtl INTO l_main_rec;
1511         l_new_rec :=NULL;
1512         IF csr_rslt_dtl%NOTFOUND THEN
1513             l_new_rec.EXT_RSLT_ID:=Ben_Ext_Thread.g_ext_rslt_id;
1514             l_new_rec.BUSINESS_GROUP_ID:=bg_id;
1515             l_new_rec.EXT_RCD_ID:=l_ext_rcd_id;
1516             l_new_rec.PERSON_ID :=p_person_id;
1517             l_new_rec.val_01    :=l_record_num;
1518             l_new_rec.val_03    :='0000000000';
1519             l_new_rec.val_04    := g_per_details(g_person_id).national_identifier;
1520             l_new_rec.val_07    :='0';
1521             l_new_rec.val_08    := g_per_details(g_person_id).date_of_birth;
1522             l_new_rec.val_10    := g_per_details(g_person_id).last_name;
1523             l_new_rec.val_11    := g_per_details(g_person_id).prefix;
1524             l_new_rec.REQUEST_ID:= l_conc_reqest_id;
1525             IF l_record_num = '010' THEN
1526                 l_new_rec.val_17    :=Get_Zeros_String(26);
1527                 l_new_rec.val_30    :=Get_Zeros_String(30);
1528             ELSE
1529              IF l_record_num = '020' THEN
1530                l_new_rec.val_18    :=Get_Zeros_String(135);
1531              ELSE
1532                IF l_record_num = '030' THEN
1533                  l_new_rec.val_17    :=Get_Zeros_String(147);
1534                ELSE
1535                  IF l_record_num = '040' THEN
1536                     l_new_rec.val_20    :=Get_Zeros_String(109);
1537                  ELSE
1538                     IF l_record_num = '060' THEN
1539                         l_new_rec.val_17    :=Get_Zeros_String(2);
1540                         l_new_rec.val_20    :=Get_Zeros_String(124);
1541                     ELSE
1542                         IF l_record_num = '070' THEN
1543                            l_new_rec.val_16    :=Get_Zeros_String(155);
1544                         ELSE
1545                            IF l_record_num = '080' THEN
1546                              l_new_rec.val_17    :=Get_Zeros_String(150);
1547                            ELSE
1548                               IF l_record_num = '081' THEN
1549                                      l_new_rec.val_17    :=Get_Zeros_String(147);
1550                                END IF;
1551                            END IF;
1552                         END IF;
1553                     END IF;
1554                  END IF;
1555                END IF;
1556              END IF;
1557             END IF;
1558         ELSE
1559            l_new_rec:= l_main_rec;
1560         END IF;
1561         CLOSE csr_rslt_dtl;
1562 
1563         l_main_rec.object_version_NUMBER
1564                             := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
1565 
1566         l_assignment_id     := p_assignment_id;
1567         l_organization_id   := g_primary_assig(p_assignment_id).organization_id;
1568         l_business_group_id := p_business_group_id;
1569         l_effective_date    := Least(g_extract_params(bg_id).extract_end_date ,
1570                                      g_primary_assig (p_assignment_id).effective_end_date);
1571         Hr_Utility.set_location('l_record_num: '||l_record_num, 25);
1572         l_return_value := Chk_If_Req_To_Extract
1573                           (p_assignment_id     => l_assignment_id
1574                           ,p_business_group_id => l_business_group_id
1575                           ,p_effective_date    => l_effective_date
1576                           ,p_record_num        => l_record_num
1577                           ,p_error_message     => p_error_message);
1578         Hr_Utility.set_location('l_return_value: '||l_return_value, 25);
1579         IF l_return_value = 'Y' THEN
1580            -- Re-Process the person level rule based data-element for the record
1581            -- along with appropiate effective date and assignment id
1582            Process_Ext_Rslt_Dtl_Rec
1583             (p_assignment_id    => l_assignment_id
1584             ,p_organization_id  => l_organization_id
1585             ,p_effective_date   => l_effective_date
1586             ,p_ext_dtl_rcd_id   => l_ext_rcd_id
1587             ,p_rslt_rec         => l_new_rec
1588             ,p_asgaction_no     => p_no_asg_action
1589             ,p_error_message    => p_error_message);
1590         END IF; -- IF l_return_value = 'Y'
1591     END IF;
1592    END LOOP;
1593 
1594    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
1595 END Create_Addl_Assignments;
1596 
1597 -- =============================================================================
1598 -- Process_Addl_Assigs: Process all the assigs in the PL/SQL table for the
1599 -- person and create the records accordingly.
1600 -- =============================================================================
1601 FUNCTION Process_Addl_Assigs
1602            (p_assignment_id       IN         Number
1603            ,p_business_group_id   IN         Number
1604            ,p_effective_date      IN         Date
1605            ,p_error_message       OUT NOCOPY Varchar2
1606            ) RETURN Number IS
1607 
1608    l_return_value         Number;
1609    bg_id                  per_all_assignments_f.business_group_id%TYPE;
1610    l_ele_type_id          pay_element_types_f.element_type_id %TYPE;
1611    l_prev_ele_type_id     pay_element_types_f.element_type_id  %TYPE;
1612    l_valid_action         Varchar2(2);
1613    l_no_asg_action        Number(5) := 0;
1614    l_proc_name            Varchar2(150) := g_proc_name ||'Process_Addl_Assigs';
1615    l_sec_assg_rec         csr_sec_assg%ROWTYPE;
1616    l_effective_date       Date;
1617    l_criteria_value       Varchar2(2);
1618    l_warning_message      Varchar2(2000);
1619    l_error_message        Varchar2(2000);
1620    l_asg_type             per_all_assignments_f.assignment_type %TYPE;
1621    l_main_rec             csr_rslt_dtl%ROWTYPE;
1622    l_person_id            per_all_people_f.person_id%TYPE;
1623    l_assignment_id        per_all_assignments_f.assignment_id%TYPE;
1624    l_mutli_assig          Varchar2(150);
1625 BEGIN
1626 
1627    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1628 
1629    l_mutli_assig := Check_Addl_Assigs
1630                      (p_assignment_id       => p_assignment_id
1631                      ,p_business_group_id   => p_business_group_id
1632                      ,p_effective_date      => p_effective_date
1633                      ,p_error_message       => p_error_message
1634                       );
1635 
1636    bg_id := p_business_group_id;
1637    IF g_primary_assig.EXISTS(p_assignment_id) THEN
1638      l_person_id := g_primary_assig (p_assignment_id).person_id;
1639      l_asg_type  := g_primary_assig (p_assignment_id).assignment_type;
1640    END IF;
1641    -- For each assignment for this person id check if additional rows need to be
1642    -- created and re-calculate the person level based fast-formulas.
1643    l_assignment_id := g_primary_assig.FIRST;
1644    WHILE l_assignment_id IS NOT NULL
1645    LOOP
1646     Hr_Utility.set_location('..Checking for assignment : '||l_assignment_id, 7);
1647     IF g_primary_assig (l_assignment_id).person_id = l_person_id AND
1648        l_assignment_id <> p_assignment_id                           AND
1649        g_primary_assig (l_assignment_id).Assignment_Type = 'E' THEN
1650 
1651        Hr_Utility.set_location('..Valid Assignment : '||l_assignment_id, 8);
1652        Hr_Utility.set_location('..l_no_asg_action  : '||l_no_asg_action, 8);
1653 
1654        Create_Addl_Assignments
1655          (p_assignment_id     => l_assignment_id
1656          ,p_business_group_id => p_business_group_id
1657          ,p_person_id         => l_person_id
1658          ,p_no_asg_action     => l_no_asg_action
1659          ,p_error_message     => l_error_message
1660           );
1661        l_no_asg_action := l_no_asg_action + 1;
1662     END IF;
1663     l_assignment_id  := g_primary_assig.NEXT(l_assignment_id);
1664 
1665    END LOOP;
1666    IF l_asg_type = 'B' AND l_no_asg_action = 0 THEN
1667       -- =================================================================
1668       -- This mean that the extract created a row for the benefit's assig.
1669       -- record and that person does not have any assig. record
1670       -- within the extract date range specified.
1671       -- =================================================================
1672       FOR csr_rcd_rec IN csr_ext_rcd_id
1673                           (c_hide_flag   => 'N' -- N=No Y=Yes
1674                          ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
1675       -- Loop through each detail record for the extract
1676       LOOP
1677           OPEN csr_rslt_dtl
1678                 (c_person_id      => l_person_id
1679                 ,c_ext_rslt_id    => Ben_Ext_Thread .g_ext_rslt_id
1680                 ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id
1681                  );
1682           FETCH csr_rslt_dtl INTO l_main_rec;
1683           WHILE csr_rslt_dtl%FOUND
1684           LOOP
1685              -- Delete for each detail record for the person
1686              DELETE ben_ext_rslt_dtl
1687               WHERE ext_rslt_dtl_id = l_main_rec.ext_rslt_dtl_id
1688                 AND person_id       = l_person_id;
1689              FETCH csr_rslt_dtl INTO l_main_rec;
1690 
1691           END LOOP; -- While csr_rslt_dtl%FOUND
1692           CLOSE csr_rslt_dtl;
1693       END LOOP; -- FOR csr_rcd_rec
1694    END IF;
1695    -- Delete all the hidden Records for the person
1696    FOR csr_rcd_rec IN csr_ext_rcd_id
1697                       (c_hide_flag   => 'Y' -- N=No Y=Yes
1698                       ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
1699    -- Loop through each detail record for the extract
1700    LOOP
1701     OPEN csr_rslt_dtl
1702           (c_person_id      => l_person_id
1703           ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
1704           ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id
1705            );
1706     FETCH csr_rslt_dtl INTO l_main_rec;
1707     WHILE csr_rslt_dtl%FOUND
1708     LOOP
1709        -- Delete for each detail record for the person
1710        DELETE ben_ext_rslt_dtl
1711         WHERE ext_rslt_dtl_id = l_main_rec.ext_rslt_dtl_id
1712           AND person_id       = l_person_id;
1713        FETCH csr_rslt_dtl INTO l_main_rec;
1714     END LOOP; -- While csr_rslt_dtl%FOUND
1715     CLOSE csr_rslt_dtl;
1716    END LOOP; -- FOR csr_rcd_rec
1717 
1718    -- Once the sec. record has been taken care of all the asg actions
1719    -- remove it from the PL/SQL table.
1720    l_assignment_id := g_primary_assig .FIRST;
1721    WHILE l_assignment_id IS NOT NULL
1722    LOOP
1723     IF g_primary_assig (l_assignment_id).person_id = l_person_id THEN
1724        g_primary_assig.DELETE(l_assignment_id);
1725     END IF;
1726     l_assignment_id  := g_primary_assig .NEXT(l_assignment_id);
1727    END LOOP;
1728 
1729    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
1730    RETURN 0;
1731 
1732 EXCEPTION
1733    WHEN Others THEN
1734     p_error_message :='SQL-ERRM :'||SQLERRM;
1735     Hr_Utility.set_location('..'||p_error_message,85);
1736     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1737     RETURN -1;
1738 END Process_Addl_Assigs;
1739 -- ===============================================================================
1740 -- ~ Get_Country_Code : Function to get the Country Code
1741 -- ===============================================================================
1742 FUNCTION Get_Country_Code
1743                  (  p_assignment_id      IN NUMBER
1744                    ,p_business_group_id  IN NUMBER
1745                    ,p_date_earned        IN DATE
1746                    ,p_error_message      OUT NOCOPY VARCHAR2
1747                    ,p_data_element_value OUT NOCOPY VARCHAR2
1748                   )
1749  RETURN NUMBER IS
1750 -- cursor to fetch country code stored in Address DDF for a person (Add_Attibute1)
1751  CURSOR csr_get_country_code(c_business_group_id NUMBER) IS
1752      SELECT hrl1.lookup_code
1753        FROM  per_addresses p_addr, hr_lookups hrl1
1754       WHERE p_addr.person_id = g_person_id
1755         AND hrl1.lookup_type='PQP_NL_STUCON_CODE_MAPPING'
1756         AND hrl1.meaning = p_addr.country
1757         AND g_extract_params(c_business_group_id).extract_end_date >= p_addr.date_from;
1758 
1759  l_proc_name  Varchar2(150) := g_proc_name ||'Get_Country_Code';
1760  l_ret_val number:=0;
1761  l_country_code varchar2(5);
1762 BEGIN
1763   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
1764 
1765   OPEN csr_get_country_code(p_business_group_id);
1766   FETCH csr_get_country_code INTO l_country_code;
1767   IF csr_get_country_code%FOUND THEN
1768      p_data_element_value:=l_country_code;
1769      l_ret_val := 0;
1770   END IF;
1771   Hr_Utility.set_location('l_country_code:   '||l_country_code, 30);
1772   CLOSE csr_get_country_code;
1773   Hr_Utility.set_location('Leaving:   '||l_proc_name, 60);
1774 RETURN l_ret_val;
1775 EXCEPTION
1776    WHEN Others THEN
1777     p_error_message :='SQL-ERRM :'||SQLERRM;
1778     Hr_Utility.set_location('..'||p_error_message,85);
1779     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1780     RETURN 1;
1781 END Get_Country_Code;
1782 
1783 -- =============================================================================
1784 -- ~ Pension_Extract_Process: This is called by the conc. program and this is a
1785 -- ~ wrapper around the benefits conc. program Extract Process.
1786 -- =============================================================================
1787 PROCEDURE Pension_Extract_Process
1788            (errbuf                        OUT NOCOPY  Varchar2
1789            ,retcode                       OUT NOCOPY  Varchar2
1790            ,p_benefit_action_id           IN     Number
1791            ,p_ext_dfn_id                  IN     Number
1792            ,p_org_id                      IN     Number
1793            ,p_payroll_id                  IN     Number
1794            ,p_start_date                  IN     Varchar2
1795            ,p_end_date                    IN     Varchar2
1796            ,p_extract_type                IN     VARCHAR2
1797            ,p_business_group_id           IN     Number
1798            ,p_consolidation_set           IN     Number
1799            ,p_ext_rslt_id                 IN     Number DEFAULT NULL
1800 ) IS
1801    l_errbuff          Varchar2(3000);
1802    l_retcode          Number;
1803    l_session_id       Number;
1804    l_proc_name        Varchar2(150) := g_proc_name ||'Pension_Extract_Process';
1805 
1806 BEGIN
1807 
1808      Hr_Utility.set_location('Entering: '||l_proc_name, 5);
1809      g_conc_request_id := Fnd_Global.conc_request_id;
1810 
1811     IF p_end_date < p_start_date THEN
1812        Fnd_Message.set_name('PQP','PQP_230869_END_BEFORE_START');
1813        Fnd_Message.raise_error;
1814     END IF;
1815 
1816     SELECT Userenv('SESSIONID') INTO l_session_id FROM dual;
1817 
1818      -- Delete values from the temporary table
1819      DELETE FROM pay_us_rpt_totals
1820      WHERE organization_name = 'NL PGGM Pension Extracts';
1821 
1822      --
1823      -- Insert into pay_us_rpt_totals so that we can refer to these parameters
1824      -- when we call the criteria formula for the pension extract.
1825      --
1826 hr_utility.set_location('inserting into rpt totals : '||p_business_group_id,20);
1827      INSERT INTO pay_us_rpt_totals
1828      (session_id         -- Session id
1829      ,organization_name  -- Concurrent Program Name
1830      ,business_group_id  -- Business Group
1831      ,tax_unit_id        -- Concurrent Request Id
1832      ,value1             -- Extract Definition Id
1833      ,value2             -- Payroll Id
1834      ,value3             -- Consolidation Set
1835      ,value4             -- Organization Id
1836      ,value5             --
1837      ,value6             --
1838      ,attribute1         --
1839      ,attribute2         --
1840      ,attribute3         -- Extract Start Date
1841      ,attribute4         -- Extract End Date
1842      ,attribute5         -- Type of Extract
1843      )
1844      VALUES
1845      (l_session_id
1846      ,'NL PGGM Pension Extracts'
1847      ,p_business_group_id
1848      ,g_conc_request_id
1849      ,p_ext_dfn_id
1850      ,p_payroll_id
1851      ,p_consolidation_set
1852      ,p_org_id
1853      ,NULL
1854      ,NULL
1855      ,NULL
1856      ,NULL
1857      ,p_start_date
1858      ,p_end_date
1859      ,p_extract_type
1860      );
1861      COMMIT;
1862      --
1863      -- Call the actual benefit extract process with the effective date as the
1864      -- extract end date along with the ext def. id and business group id.
1865      --
1866      Hr_Utility.set_location('..Calling Benefit Ext Process'||l_proc_name, 6);
1867      Ben_Ext_Thread.process
1868        (errbuf                     => l_errbuff,
1869         retcode                    => l_retcode,
1870         p_benefit_action_id        => NULL,
1871         p_ext_dfn_id               => p_ext_dfn_id,
1872         p_effective_date           => p_end_date,
1873         p_business_group_id        => p_business_group_id);
1874 
1875      Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
1876 
1877 --hr_utility.trace_off;
1878 EXCEPTION
1879      WHEN Others THEN
1880      Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
1881      RAISE;
1882 END Pension_Extract_Process;
1883 
1884 -- =============================================================================
1885 -- Pension_Criteria_Full_Profile: The Main extract criteria that would be used
1886 -- for the pension extract. This function decides the assignments that need
1887 -- to be processed. The assignments that need not be processed are rejected
1888 -- here. The criteria is to filter the assignments based on the org hierarchy
1889 -- (only child organizations which are non-tax organizations are taken in account).
1890 -- =============================================================================
1891 
1892 FUNCTION Pension_Criteria_Full_Profile
1893            (p_assignment_id        IN per_all_assignments_f.assignment_id%TYPE
1894            ,p_effective_date       IN Date
1895            ,p_business_group_id    IN per_all_assignments_f.business_group_id%TYPE
1896            ,p_warning_message      OUT NOCOPY Varchar2
1897            ,p_error_message        OUT NOCOPY Varchar2
1898             ) RETURN Varchar2 IS
1899    -- =========================================
1900    -- ~ Type Of Extract(Full or Change)
1901    -- =========================================
1902    CURSOR csr_ext_attr (c_ext_dfn_id IN ben_ext_rslt.ext_dfn_id%TYPE) IS
1903       SELECT ext_dfn_type
1904         FROM pqp_extract_attributes
1905        WHERE ext_dfn_id = c_ext_dfn_id;
1906 
1907    -- Get the Conc. requests params based on the request id fetched
1908    CURSOR csr_ext_params (c_request_id        IN Number
1909                          ,c_ext_dfn_id        IN Number
1910                          ,c_business_group_id IN Number) IS
1911     SELECT   session_id         -- Session id
1912             ,organization_name  -- Concurrent Program Name
1913             ,business_group_id  -- Business Group
1914             ,tax_unit_id        -- Concurrent Request Id
1915             ,value1             -- Extract Definition Id
1916             ,value2             -- Payroll Id
1917             ,value3             -- Consolidation Set
1918             ,value4             -- Organization Id
1919             ,value5             --
1920             ,value6             --
1921             ,attribute1         --
1922             ,attribute2         --
1923             ,attribute3         -- Extract Start Date
1924             ,attribute4         -- Extract End Date
1925             ,attribute5         -- Type of Extract
1926         FROM pay_us_rpt_totals
1927        WHERE tax_unit_id       = c_request_id
1928          AND value1            = c_ext_dfn_id
1929          AND business_group_id = c_business_group_id;
1930 
1931    -- Get the Assignment Run level dimension id
1932    CURSOR csr_asg_dimId IS
1933       SELECT balance_dimension_id
1934         FROM pay_balance_dimensions
1935        WHERE legislation_code = 'NL'
1936          AND database_item_suffix = '_ASG_RUN';
1937 
1938    -- Get the Legislation Code and Curreny Code
1939    CURSOR csr_leg_code (c_business_group_id IN Number) IS
1940       SELECT pbg.legislation_code
1941             ,pbg.currency_code
1942         FROM per_business_groups_perf   pbg
1943        WHERE pbg.business_group_id = c_business_group_id;
1944 
1945    -- Cursor to Check if a org hierarchy is attached to the BG.
1946    -- If it is attached get the valid version as of the effective date.
1947    -- If a valid version is not found then do nothing.
1948    CURSOR c_get_org_hierarchy IS
1949    SELECT pos.org_structure_version_id
1950      FROM per_org_structure_versions_v pos,
1951           hr_organization_information hoi
1952     WHERE hoi.organization_id = p_business_group_id
1953       AND To_Number(hoi.org_information1) = pos.organization_structure_id
1954       AND Trunc(p_effective_date) BETWEEN date_from
1955                                       AND Nvl(date_to,Hr_Api.g_eot)
1956       AND hoi.org_information_context = 'NL_BG_INFO';
1957 
1958    -- Cursor to get the list of child orgs from the hierarchy if one exists.
1959    CURSOR c_get_children ( c_org_str_ver_id IN Number
1960                           ,c_org_id         IN Number) IS
1961    SELECT os.organization_id_child
1962      FROM (SELECT *
1963              FROM per_org_structure_elements a
1964             WHERE a.org_structure_version_id = c_org_str_ver_id ) os
1965      START WITH os.organization_id_parent = c_org_id
1966      CONNECT BY os.organization_id_parent = PRIOR os.organization_id_child;
1967 
1968    -- Cursor to store the record ids in a PL/SQL table to be used while
1969    -- processing the sec. and terminated assignments
1970    CURSOR csr_rcd_ids IS
1971    SELECT Decode(rin.seq_num,1,'000',
1972                              2,'010',
1973                              3,'020',
1974                              4,'030',
1975                              5,'040',
1976                              6,'060',
1977                              7,'070',
1978                              8,'080',
1979                              9,'081',
1980                              10,'10h',
1981                              12,'999',
1982                             '~') rec_num,
1983           rin.seq_num,
1984           rin.hide_flag,
1985           rcd.ext_rcd_id,
1986           rcd.rcd_type_cd
1987     FROM  ben_ext_rcd         rcd
1988          ,ben_ext_rcd_in_file rin
1989          ,ben_ext_dfn dfn
1990    WHERE dfn.ext_dfn_id   = Ben_Ext_Thread.g_ext_dfn_id
1991      AND rin.ext_file_id  = dfn.ext_file_id
1992      AND rin.ext_rcd_id   = rcd.ext_rcd_id
1993      ORDER BY rin.seq_num;
1994 
1995 --Cursor to check whether oganization is tax organization or not
1996 CURSOR csr_tax_org(c_org_id NUMBER) IS
1997 SELECT 'x'
1998   FROM hr_organization_information
1999  WHERE organization_id         = c_org_id
2000    AND org_information_context = 'NL_ORG_INFORMATION'
2001    AND org_information3 IS NOT NULL
2002    AND org_information4 IS NOT NULL;
2003 
2004 --Cursor to fetch the PGGM employer number from
2005 --org information context
2006 CURSOR csr_get_pggm_er_num(c_org_id IN Number) IS
2007 SELECT SUBSTR(NVL(org_information5,'000000'),1,6)
2008   FROM hr_organization_information
2009  WHERE org_information_context = 'PQP_NL_PGGM_INFO'
2010    AND organization_id = c_org_id;
2011 
2012 --Cursor to check the PTP in the Std Conditions tab
2013 --Pick ptp value from Std conditions at asg level
2014 CURSOR csr_get_ptp_std_cond(c_assignment_id NUMBER,bg_id NUMBER) IS
2015 SELECT fnd_number.canonical_to_number(NVL(scl.SEGMENT29,'0')) pt_perc,
2016        asg.effective_start_date, asg.effective_end_date
2017  FROM  per_assignments_f asg
2018       ,hr_soft_coding_keyflex scl
2019 WHERE  asg.assignment_id = c_assignment_id
2020   AND  scl.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
2021   AND  asg.effective_start_date BETWEEN g_extract_params(bg_id).extract_start_date
2022        AND g_extract_params(p_business_group_id).extract_end_date;
2023 
2024 --Cursor to check the previous PTP in the Std Conditions tab
2025 CURSOR csr_get_prev_ptp_std_cond(c_asg_id NUMBER,c_date DATE) IS
2026 SELECT fnd_number.canonical_to_number(NVL(scl.SEGMENT29,'0')) pt_perc
2027 FROM   per_all_assignments_f asg
2028       ,hr_soft_coding_keyflex scl
2029 WHERE asg.assignment_id = c_asg_id
2030   AND (c_date - 1 BETWEEN asg.effective_start_date
2031       AND asg.effective_end_date)
2032   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
2033 
2034 ------Cursor to check whether there is any change in part time percentage
2035 CURSOR csr_chk_curr_ptp_ele(c_asg_id NUMBER,bg_id NUMBER) IS
2036 SELECT peev.element_entry_value_id,
2037 peev.screen_entry_value,peev.effective_start_date,peev.effective_end_date
2038 FROM
2039 pay_element_types_f pet,
2040 pay_input_values_f piv,
2041 pay_element_entries_f pee,
2042 pay_element_entry_values_f peev
2043 WHERE
2044   pet.element_name = 'PGGM Pensions Part Time Percentage'
2045   and piv.name ='Part Time Percentage'
2046   and piv.element_type_id=pet.element_type_id
2047   and pee.element_type_id=pet.element_type_id
2048   and pee.assignment_id =c_asg_id
2049   and (g_extract_params(bg_id).extract_start_date between pee.effective_start_date
2050        and pee.effective_end_date)
2051   and peev.element_entry_id=pee.element_entry_id
2052   and peev.input_value_id=piv.input_value_id
2053   and (peev.effective_start_date between g_extract_params(bg_id).extract_start_date
2054   and g_extract_params(bg_id).extract_end_date);
2055 
2056 
2057 ------Cursor to check whether there is any retrospective change in part time percentage
2058 CURSOR csr_chk_retro_ptp_ele(c_asg_id NUMBER,bg_id NUMBER) IS
2059 SELECT peev.element_entry_value_id,
2060 peev.screen_entry_value,pee.source_start_date
2061 FROM
2062 pay_element_types_f pet,
2063 pay_input_values_f piv,
2064 pay_element_entries_f pee,
2065 pay_element_entry_values_f peev
2066 WHERE
2067   pet.element_name = 'Retro PGGM Pensions Part Time Percentage'
2068   and piv.name ='Part Time Percentage'
2069   and piv.element_type_id=pet.element_type_id
2070   and pee.element_type_id=pet.element_type_id
2071   and pee.assignment_id =c_asg_id
2072   and (g_extract_params(bg_id).extract_start_date between pee.effective_start_date
2073        and pee.effective_end_date)
2074   and peev.element_entry_id=pee.element_entry_id
2075   and peev.input_value_id=piv.input_value_id
2076   and peev.screen_entry_value is not null
2077   order by pee.source_start_date;
2078 
2079 -------Cursor to check whether there is any change in incidental worker code
2080 CURSOR csr_chk_inci_code_ele(c_asg_id NUMBER,bg_id NUMBER) IS
2081 SELECT Decode(scl.SEGMENT1,'Y','0','1') segment1, asg.effective_start_date,asg.effective_end_date
2082 FROM   per_all_assignments_f asg
2083       ,hr_soft_coding_keyflex scl
2084 WHERE asg.assignment_id = c_asg_id
2085   AND (asg.effective_start_date BETWEEN g_extract_params(bg_id).extract_start_date
2086   AND g_extract_params(p_business_group_id).extract_end_date)
2087   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
2088 
2089 ------Cursor to pick all retrospective changes in incidental worker code in the current period
2090 ------in a sorted order
2091 CURSOR csr_chk_retro_inci_code_ele(c_asg_id NUMBER,bg_id NUMBER) IS
2092 SELECT peev.screen_entry_value,pee.source_start_date
2093 FROM
2094 pay_element_types_f pet,
2095 pay_input_values_f piv,
2096 pay_element_entries_f pee,
2097 pay_element_entry_values_f peev
2098 WHERE
2099   ( pet.element_name = 'Retro PGGM Pensions General Information'
2100     OR pet.element_name = 'Retro PGGM Pensions General Information Previous Year')
2101   and piv.name ='Incidental Worker'
2102   and piv.element_type_id=pet.element_type_id
2103   and pee.element_type_id=pet.element_type_id
2104   and pee.assignment_id =c_asg_id
2105   and (g_extract_params(bg_id).extract_start_date between pee.effective_start_date
2106        and pee.effective_end_date)
2107   and peev.element_entry_id=pee.element_entry_id
2108   and peev.input_value_id=piv.input_value_id
2109   ORDER by pee.source_start_date;
2110 
2111 --Cursor to check whether Pension Salary Current Year Retro Changes exists or not
2112 -- and fetch the difference in pension salary
2113 CURSOR csr_get_060_curr_retro_val(c_asg_id Number,c_eff_date Date) IS
2114 Select peev.screen_entry_value,pee.element_entry_id
2115 from pay_element_entries_f  pee,
2116      pay_input_values_f    piv,
2117      pay_element_types_f   pet,
2118      pay_element_entry_values_f peev
2119 where
2120    pet.element_name ='Retro PGGM Pensions General Information'
2121  AND piv.name = 'Annual Pension Salary'
2122  AND piv.element_type_id=pet.element_type_id
2123  AND pee.assignment_id=c_asg_id
2124  AND pee.element_type_id =pet.element_type_id
2125  AND  (c_eff_date between pee.effective_start_date
2126                 and pee.effective_end_date)
2127  AND peev.element_entry_id=pee.element_entry_id
2128  AND peev.input_value_id=piv.input_value_id
2129  AND ( c_eff_date between peev.effective_start_date
2130        and peev.effective_end_date)
2131  AND peev.screen_entry_value is not null;
2132 
2133 
2134 --Cursor to check whether Pension Salary Previous Year Retro Changes exists or not
2135 -- and fetch the difference in pension salary
2136 CURSOR csr_get_060_prev_retro_val(c_asg_id Number,c_eff_date Date) IS
2137 Select peev.screen_entry_value,pee.element_entry_id
2138 from pay_element_entries_f  pee,
2139      pay_input_values_f    piv,
2140      pay_element_types_f   pet,
2141      pay_element_entry_values_f peev
2142 where
2143  pet.element_name ='Retro PGGM Pensions General Information Previous Year'
2144  AND piv.name = 'Annual Pension Salary'
2145  AND piv.element_type_id=pet.element_type_id
2146  AND pee.assignment_id=c_asg_id
2147  AND pee.element_type_id =pet.element_type_id
2148  AND  (c_eff_date between pee.effective_start_date
2149                 and pee.effective_end_date)
2150  AND peev.element_entry_id=pee.element_entry_id
2151  AND peev.input_value_id=piv.input_value_id
2152  AND ( c_eff_date between peev.effective_start_date
2153        and peev.effective_end_date)
2154  AND peev.screen_entry_value is not null;
2155 
2156 --Cursor to check whether Pension Salary Retro Changes exists or not
2157 --and fetch the orginal date earned
2158 CURSOR csr_get_060_curr_retro_date(c_asg_id Number,c_eff_date Date) IS
2159 Select to_char(pee.source_start_date,'YYYYMMDD') source_start_date ,pee.element_entry_id
2160 from pay_element_entries_f  pee,
2161      pay_element_types_f   pet
2162 where
2163     pet.element_name ='Retro PGGM Pensions General Information'
2164  AND pee.assignment_id=c_asg_id
2165  AND pee.element_type_id =pet.element_type_id
2166  AND  (c_eff_date between pee.effective_start_date
2167                 and pee.effective_end_date);
2168 
2169 --Cursor to check whether Pension Salary Retro Changes exists or not
2170 --and fetch the orginal date earned
2171 CURSOR csr_get_060_prev_retro_date(c_asg_id Number,c_eff_date Date) IS
2172 Select to_char(pee.source_start_date,'YYYYMMDD') source_start_date ,pee.element_entry_id
2173 from pay_element_entries_f  pee,
2174      pay_element_types_f   pet
2175 where
2176  pet.element_name ='Retro PGGM Pensions General Information Previous Year'
2177  AND pee.assignment_id=c_asg_id
2178  AND pee.element_type_id =pet.element_type_id
2179  AND  (c_eff_date between pee.effective_start_date
2180                 and pee.effective_end_date);
2181 
2182 ------Cursor to check whether there is any change in part time percentage
2183 CURSOR csr_chk_prev_ptp_ele(c_asg_id NUMBER,bg_id NUMBER,c_date DATE) IS
2184 SELECT peev.screen_entry_value
2185 FROM
2186 pay_element_types_f pet,
2187 pay_input_values_f piv,
2188 pay_element_entries_f pee,
2189 pay_element_entry_values_f peev
2190 WHERE
2191   pet.element_name = 'PGGM Pensions Part Time Percentage'
2192   and piv.name ='Part Time Percentage'
2193   and piv.element_type_id=pet.element_type_id
2194   and pee.element_type_id=pet.element_type_id
2195   and pee.assignment_id =c_asg_id
2196   and ((c_date -1) between pee.effective_start_date
2197        and pee.effective_end_date)
2198   and peev.element_entry_id=pee.element_entry_id
2199   and peev.input_value_id=piv.input_value_id
2200   and((c_date-1)  between peev.effective_start_date
2201        and peev.effective_end_date);
2202 
2203 
2204 -------Cursor to check whether there is any change in incidental worker code
2205 CURSOR csr_chk_inci_code_chg_ele(c_asg_id NUMBER,bg_id NUMBER,c_date DATE) IS
2206 SELECT Decode(scl.SEGMENT1,'Y','0','1') segment1
2207 FROM   per_all_assignments_f asg
2208       ,hr_soft_coding_keyflex scl
2209 WHERE asg.assignment_id = c_asg_id
2210   AND (c_date - 1 BETWEEN asg.effective_start_date
2211   AND asg.effective_end_date)
2212   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
2213 
2214 Cursor csr_retro_pggm_gen_info_iwc IS
2215 Select 'x'
2216 from pay_element_entries_f  pee,
2217      pay_input_values_f    piv,
2218      pay_element_types_f   pet,
2219      pay_element_entry_values_f peev
2220 where
2221 (    pet.element_name ='Retro PGGM Pensions General Information'
2222  OR  pet.element_name ='Retro PGGM Pensions General Information Previous Year')
2223  AND piv.name = 'Annual Pension Salary'
2224  AND piv.element_type_id=pet.element_type_id
2225  AND pee.assignment_id=p_assignment_id
2226  AND pee.element_type_id =pet.element_type_id
2227  AND  (p_effective_date between pee.effective_start_date
2228                 AND pee.effective_end_date )
2229  AND peev.element_entry_id=pee.element_entry_id
2230  AND peev.input_value_id=piv.input_value_id
2231  AND ( p_effective_date between peev.effective_start_date
2232                 AND peev.effective_end_date )
2233  AND peev.screen_entry_value is  null;
2234 
2235 ---Cursor to check whether there is any change in definitive part time percentage retrospectievly
2236 --Record 081 triggering condition
2237 CURSOR  csr_get_081_retro_values(c_asg_id NUMBER,bg_id NUMBER,c_date DATE) IS
2238 SELECT distinct to_char(pee.source_start_date,'YYYY') year_of_change
2239 FROM
2240 pay_element_types_f     pet,
2241 pay_input_values_f      piv,
2242 pay_element_entries_f   pee,
2243 pay_element_entry_values_f peev
2244 WHERE
2245   pet.element_name = 'Retro PGGM Pensions Part Time Percentage'
2246   AND ( piv.name = 'Extra Hours'
2247         OR piv.name = 'Hours Worked'
2248 OR piv.name = 'Total Hours' )
2249   and pee.element_type_id=pet.element_type_id
2250   and pee.assignment_id =c_asg_id
2251   and ( pee.effective_start_date  between g_extract_params(bg_id).extract_start_date
2252           and g_extract_params(bg_id).extract_end_date)
2253   and pee.source_start_date < c_date
2254   AND peev.element_entry_id=pee.element_entry_id
2255   AND peev.input_value_id=piv.input_value_id
2256   AND peev.screen_entry_value is not null
2257   order by year_of_change;
2258 
2259    -- =========================================
2260    -- ~ Local variables
2261    -- =========================================
2262    l_ext_params         csr_ext_params%ROWTYPE;
2263    l_conc_reqest_id     ben_ext_rslt.request_id%TYPE;
2264    l_ext_dfn_type       pqp_extract_attributes.ext_dfn_type%TYPE;
2265    bg_id                per_all_assignments_f.business_group_id%TYPE;
2266    l_ext_rslt_id        ben_ext_rslt.ext_rslt_id%TYPE;
2267    l_ext_dfn_id         ben_ext_dfn.ext_dfn_id%TYPE;
2268    l_return_value       Varchar2(2) :='N';
2269    l_valid_action       Varchar2(2);
2270    l_ele_type_id        pay_element_types_f.element_type_id%TYPE;
2271    l_prev_ele_type_id   pay_element_types_f.element_type_id%TYPE;
2272    l_proc_name          Varchar2(150) := g_proc_name ||'Pension_Criteria_Full_Profile';
2273    l_assig_rec          csr_assig%ROWTYPE;
2274    l_Chg_Evt_Exists     Varchar2(2);
2275    l_effective_date     Date;
2276    l_org_hierarchy      Number;
2277    l_ret_val            Number:=0;
2278    l_rr_exists          number := 0;
2279    l_basis_amount       number(9,2);
2280    l_asg_act_id         number;
2281    l_def_bal_id         number;
2282    l_amount             number;
2283    l_context_id         number;
2284    l_code               number;
2285    l_date               date := hr_api.g_eot;
2286    l_ptp_start_date     DATE;
2287    l_new_start          date;
2288    l_old_start          date;
2289    l_tax_org_flag       varchar2(1);
2290    l_get_count_ptp_changes NUMBER := 0;
2291    l_pay_year           NUMBER;
2292    l_pay_mon            NUMBER;
2293    l_pay_day            NUMBER;
2294    l_pay_start_date     DATE;
2295    l_pay_end_date       DATE;
2296    l_index              NUMBER;
2297    loop_index           NUMBER:=0;
2298    l_temp_rec080_01    csr_chk_curr_ptp_ele%ROWTYPE;
2299    l_temp_rec080_02    csr_chk_retro_ptp_ele%ROWTYPE;
2300    l_temp_rec080_03    csr_chk_inci_code_ele%ROWTYPE;
2301    l_temp_rec080_04    csr_chk_retro_inci_code_ele%ROWTYPE;
2302 
2303    l_temp_rec060_curr_01    csr_get_060_curr_retro_val%ROWTYPE;
2304    l_temp_rec060_curr_02    csr_get_060_curr_retro_date%ROWTYPE;
2305    l_temp_rec060_prev_01    csr_get_060_prev_retro_val%ROWTYPE;
2306    l_temp_rec060_prev_02    csr_get_060_prev_retro_date%ROWTYPE;
2307 
2308    l_temp_rec081        csr_get_081_retro_values%ROWTYPE;
2309 
2310    l_040_eff_date       DATE;
2311    l_temp_date          DATE;
2312    l_temp_index         NUMBER;
2313    l_iwc_change_val     NUMBER;
2314    l_04_counter         NUMBER:=0;
2315    l_prev_iwc           varchar2(1);
2316    l_data_element_val   varchar2(10);
2317    l_prev_ptp_val       varchar2(10);
2318    l_start_date         DATE;
2319    l_02_counter         NUMBER:=0;
2320    l_ptp_change_val     NUMBER:=0;
2321    l_check              varchar2(1);
2322    l_pggm_er_num        varchar2(6);
2323    l_check_date         varchar2(2);
2324    l_check_mon          varchar2(2);
2325    l_flag               varchar2(10);
2326    l_employer_contri    NUMBER;
2327    l_emp_contri         NUMBER;
2328    l_period_start_date  DATE;
2329    l_period_end_date    DATE;
2330    l_period_start_date2 DATE;
2331    l_prev_ptp_std       NUMBER;
2332 BEGIN
2333 --hr_utility.trace_on(null,'SS');
2334 
2335    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
2336    bg_id := p_business_group_id;
2337    g_ptp_index          := 0;
2338    g_retro_ptp_count := 0;
2339    l_ext_rslt_id := Ben_Ext_Thread.g_ext_rslt_id;
2340    l_ext_dfn_id  := Ben_Ext_Thread.g_ext_dfn_id;
2341    -- Executed only once during extract run
2342    IF NOT g_extract_params .EXISTS(bg_id) THEN
2343       Hr_Utility.set_location('..Exract Params PL/SQL not populated ' ,7);
2344       -- Get the extract type, Changes extract or Full Profile
2345       OPEN  csr_ext_attr(c_ext_dfn_id=> l_ext_dfn_id);
2346       FETCH csr_ext_attr INTO l_ext_dfn_type;
2347       CLOSE csr_ext_attr;
2348       Hr_Utility.set_location('..After cursor csr_ext_attr',9);
2349       -- Get the Conc. request id to get the params
2350       OPEN  csr_req_id(c_ext_rslt_id       => l_ext_rslt_id
2351                       ,c_ext_dfn_id        => l_ext_dfn_id
2352                       ,c_business_group_id => p_business_group_id);
2353       FETCH csr_req_id INTO l_conc_reqest_id;
2354       CLOSE csr_req_id;
2355       Hr_Utility.set_location('..After Conc.Request id cursor csr_req_id',11);
2356       -- Get the params. based on the conc. request id.
2357       OPEN  csr_ext_params (c_request_id        => l_conc_reqest_id
2358                            ,c_ext_dfn_id        => l_ext_dfn_id
2359                            ,c_business_group_id => p_business_group_id);
2360       FETCH csr_ext_params INTO l_ext_params;
2361       CLOSE csr_ext_params;
2362       -- Store the params. in a PL/SQL table record
2363       g_extract_params(bg_id).session_id          := l_ext_params.session_id;
2364       g_extract_params(bg_id).ext_dfn_type        := l_ext_dfn_type;
2365       g_extract_params(bg_id).business_group_id   := l_ext_params.business_group_id;
2366       g_extract_params(bg_id).concurrent_req_id   := l_ext_params.tax_unit_id;
2367       g_extract_params(bg_id).ext_dfn_id          := l_ext_params.value1;
2368       g_extract_params(bg_id).payroll_id          := l_ext_params.value2;
2369       g_extract_params(bg_id).con_set_id          := l_ext_params.value3;
2370       g_extract_params(bg_id).org_id              := l_ext_params.value4;
2371       g_extract_params(bg_id).extract_start_date  :=
2372           Fnd_Date.canonical_to_date(l_ext_params.attribute3);
2373       g_extract_params(bg_id).extract_end_date    :=
2374           Fnd_Date.canonical_to_date(l_ext_params.attribute4);
2375       g_extract_params(bg_id).extract_type      := l_ext_params.attribute5;
2376 
2377       OPEN csr_leg_code (c_business_group_id => p_business_group_id);
2378       FETCH csr_leg_code INTO g_extract_params(bg_id).legislation_code,
2379                               g_extract_params(bg_id).currency_code;
2380       CLOSE csr_leg_code;
2381       g_legislation_code  := g_extract_params(bg_id).legislation_code;
2382       g_business_group_id := p_business_group_id;
2383       Hr_Utility.set_location('..Stored the extract parameters in PL/SQL table', 15);
2384 
2385 /*
2386       -- Get Assignment Run dimension Id as we will be using for
2387       -- calculating the amount
2388       OPEN  csr_asg_dimId;
2389       FETCH csr_asg_dimId INTO g_asgrun_dim_id;
2390       CLOSE csr_asg_dimId; */
2391 
2392       -- Set the meaning for concurrent program parameters
2393        Set_ConcProg_Parameter_Values
2394        (p_ext_dfn_id          => g_extract_params(bg_id).ext_dfn_id
2395        ,p_start_date          => g_extract_params(bg_id).extract_start_date
2396        ,p_end_date            => g_extract_params(bg_id).extract_end_date
2397        ,p_payroll_id          => g_extract_params(bg_id).payroll_id
2398        ,p_con_set             => g_extract_params(bg_id).con_set_id
2399        ,p_org_id              => g_extract_params(bg_id).org_id
2400         );
2401 
2402       Hr_Utility.set_location('..Stored the Conc. Program parameters', 17);
2403       -- Store all record ids in a PL/SQL tbl
2404       FOR rcd_rec IN csr_rcd_ids
2405       LOOP
2406           g_ext_rcds(rcd_rec.ext_rcd_id):= rcd_rec;
2407       END LOOP;
2408       -- Add the current org to the org table.
2409        g_org_list(g_extract_params(bg_id).org_id).org_id
2410                           := g_extract_params(bg_id).org_id;
2411 
2412       --Store the PGGM employer number in a global variable
2413       -- Get PGGM Er number from derived org id
2414       OPEN csr_get_pggm_er_num(g_extract_params(bg_id).org_id);
2415       FETCH csr_get_pggm_er_num INTO l_pggm_er_num;
2416       IF csr_get_pggm_er_num%FOUND THEN
2417          g_pggm_employer_num:=l_pggm_er_num;
2418          l_ret_val := 0;
2419       END IF;
2420       CLOSE csr_get_pggm_er_num;
2421 
2422 
2423       -- Check if a hierarchy is attached.
2424       OPEN c_get_org_hierarchy;
2425       FETCH c_get_org_hierarchy INTO l_org_hierarchy;
2426       IF c_get_org_hierarchy%FOUND THEN
2427          CLOSE c_get_org_hierarchy;
2428          -- Get all the children of the Org for which extract is being run
2429          -- based on the hierarchy obtained above.
2430          FOR temp_rec IN c_get_children
2431                          (c_org_str_ver_id => l_org_hierarchy
2432                          ,c_org_id         => g_extract_params(bg_id).org_id)
2433          LOOP
2434 
2435    -- All non-employers  child orgs are added in the list
2436    OPEN csr_tax_org(temp_rec.organization_id_child);
2437    FETCH csr_tax_org INTO l_tax_org_flag;
2438    IF csr_tax_org%NOTFOUND Then
2439         g_org_list(temp_rec.organization_id_child).org_id
2440                            := temp_rec.organization_id_child;
2441      End If;
2442    CLOSE csr_tax_org;
2443   END LOOP;
2444        ELSE
2445           CLOSE c_get_org_hierarchy;
2446        END IF;
2447 
2448 
2449    END IF;
2450 
2451    -- Get the person id for the assignment and store it in a global
2452    -- variable
2453    g_person_id:= Nvl(get_current_extract_person(p_assignment_id),
2454                     Ben_Ext_Person.g_person_id);
2455 
2456     --If person is not retro hired then g_retro_hires record is null
2457     Hr_Utility.set_location('c_start_date'||g_extract_params(bg_id).extract_start_date, 15);
2458     Hr_Utility.set_location('c_end_date'||g_extract_params(bg_id).extract_end_date, 15);
2459    -- Derive the effective date
2460    l_effective_date := Least(g_extract_params(bg_id).extract_end_date,
2461                              p_effective_date);
2462    Hr_Utility.set_location('..Processing Assig Id  : '||p_assignment_id, 17);
2463    Hr_Utility.set_location('..Processing Person Id : '||g_person_id, 17);
2464    Hr_Utility.set_location('..Processing Eff.Date  : '||p_effective_date, 17);
2465    -- Get the list of employers (HR Orgs) in the current hierarchy.
2466    -- Store this value in a PL/SQL Table.
2467    -- Check if the assignments need to be processed. Assignments are
2468    -- processed if
2469    -- 1. The organization of the person assignment exists in the
2470    --    org list derived above.
2471    -- 2. If the primary assignment does not satisfy point 1 then check if
2472    --    the secondary assignments satisfy point 1
2473    -- 3. If the assignment passed is a Benefits assignment
2474 
2475    -- Check if the assignments passed by BEN are in the org list
2476    OPEN csr_assig (c_assignment_id     => p_assignment_id
2477                   ,c_effective_date    => l_effective_date
2478                   ,c_business_group_id => p_business_group_id);
2479    FETCH csr_assig INTO l_assig_rec;
2480    CLOSE csr_assig;
2481 
2482    g_per_details(g_person_id).national_identifier:=substr(l_assig_rec.national_identifier,1,9);
2483    g_per_details(g_person_id).date_of_birth:=to_char(l_assig_rec.date_of_birth,'YYMMDD');
2484    g_per_details(g_person_id).prefix:=substr(l_assig_rec.pre_name_adjunct,1,7);
2485    g_per_details(g_person_id).last_name:=substr(l_assig_rec.last_name,1,18);
2486 
2487    -- Check for Benefits assignment first.
2488    IF l_assig_rec.assignment_type = 'B' THEN
2489       l_return_value := 'Y';
2490    -- Check for EE Assignment
2491    ELSIF l_assig_rec.assignment_type = 'E' THEN
2492       l_return_value := 'N';
2493 
2494       -- Check if the asg org_id is in the list of orgs, Also Check if the
2495       -- value of payroll_id on the ASG is the same as the param Payroll id.
2496 
2497       IF g_org_list.EXISTS(l_assig_rec.organization_id) AND
2498          ( g_extract_params(bg_id).payroll_id IS NULL OR
2499            l_assig_rec.payroll_id =g_extract_params(bg_id).payroll_id )  THEN
2500                l_return_value := 'Y';
2501       END IF;
2502 
2503     END IF;
2504 
2505    -- Check if any secondary assignments exist and need to be picked up
2506    IF l_return_value = 'N' AND l_assig_rec.primary_flag = 'Y' THEN
2507 
2508       FOR temp_rec IN csr_sec_assig (c_assignment_id     => p_assignment_id
2509                                     ,c_effective_date    => l_effective_date
2510                                     ,c_business_group_id => p_business_group_id
2511                                     ,c_person_id         => g_person_id)
2512       -- For all sec asg's..Recheck
2513       LOOP
2514          IF g_org_list.EXISTS(temp_rec.organization_id) AND
2515             ( g_extract_params(bg_id).payroll_id IS NULL OR
2516               temp_rec.payroll_id =g_extract_params(bg_id).payroll_id) THEN
2517               l_return_value := 'Y';
2518           EXIT;
2519          END IF;
2520       END LOOP;
2521 
2522     END IF;
2523 
2524    -- Added to maintain global asg data
2525    IF l_return_value = 'Y' THEN
2526       g_primary_assig(p_assignment_id):=l_assig_rec;
2527 
2528        --Setting the start and end date to check for payroll run
2529        l_pay_start_date:=g_extract_params(p_business_group_id).extract_start_date;
2530        l_pay_end_date:=g_extract_params(p_business_group_id).extract_end_date;
2531 
2532       --Check whether for this assignment payroll has been run or not
2533       OPEN csr_asg_act(p_assignment_id
2534                       ,null
2535                       ,null
2536                       ,l_pay_start_date
2537                       ,l_pay_end_date
2538                       );
2539       FETCH csr_asg_act INTO l_asg_act;
2540       IF csr_asg_act%FOUND THEN
2541          CLOSE csr_asg_act;
2542       ELSE
2543          CLOSE csr_asg_act;
2544          p_error_message := 'Payroll has not been run for this assignment.';
2545       END IF;
2546 
2547      --------------------Record060 Pre Processing----------------
2548      --Initialize global variables for record 060
2549      g_rcd_060.DELETE;
2550      g_rec060_mult_flag:='N';
2551      g_rec_060_count:=0;
2552 
2553      OPEN csr_get_060_curr_retro_val(p_assignment_id,p_effective_date);
2554      OPEN csr_get_060_curr_retro_date(p_assignment_id,p_effective_date);
2555 
2556      LOOP
2557          FETCH csr_get_060_curr_retro_val INTO l_temp_rec060_curr_01;
2558          FETCH csr_get_060_curr_retro_date INTO l_temp_rec060_curr_02;
2559          EXIT WHEN csr_get_060_curr_retro_val%NOTFOUND OR csr_get_060_curr_retro_date%NOTFOUND;
2560 
2561         l_check_date:=substr(l_temp_rec060_curr_02.source_start_date,7,2);
2562         l_check_mon:=substr(l_temp_rec060_curr_02.source_start_date,5,2);
2563 
2564         --Get year start date and month
2565 	OPEN  c_get_period_start_date( substr(l_temp_rec060_curr_02.source_start_date,1,4)
2566 	                             ,p_assignment_id
2567 				     ,p_effective_date );
2568 	FETCH c_get_period_start_date INTO l_period_start_date2;
2569 	CLOSE c_get_period_start_date;
2570 
2571 
2572       IF l_check_date=to_char(l_period_start_date2,'DD') AND l_check_mon=to_char(l_period_start_date2,'MM') THEN
2573             Hr_Utility.set_location('Adding 060 record', 75);
2574              l_temp_index:=l_temp_rec060_curr_01.element_entry_id;
2575              g_rcd_060(l_temp_index).pension_sal_amount :=to_number(l_temp_rec060_curr_01.screen_entry_value);
2576              l_temp_index:=l_temp_rec060_curr_02.element_entry_id;
2577             l_temp_date:=to_date(l_temp_rec060_curr_02.source_start_date,'YYYYMMDD');
2578              g_rcd_060(l_temp_rec060_curr_02.element_entry_id).pension_sal_dt_change:=l_temp_date;
2579             g_rcd_060(l_temp_rec060_curr_02.element_entry_id).element_type:='C';
2580       END IF;
2581      END LOOP;
2582      CLOSE csr_get_060_curr_retro_val;
2583      CLOSE csr_get_060_curr_retro_date;
2584 
2585      OPEN csr_get_060_prev_retro_val(p_assignment_id,p_effective_date);
2586      OPEN csr_get_060_prev_retro_date(p_assignment_id,p_effective_date);
2587      LOOP
2588          FETCH csr_get_060_prev_retro_val INTO l_temp_rec060_prev_01;
2589          FETCH csr_get_060_prev_retro_date INTO l_temp_rec060_prev_02;
2590          EXIT WHEN csr_get_060_prev_retro_val%NOTFOUND OR csr_get_060_prev_retro_date%NOTFOUND;
2591          l_check_date:=substr(l_temp_rec060_prev_02.source_start_date,7,2);
2592          l_check_mon:=substr(l_temp_rec060_prev_02.source_start_date,5,2);
2593 
2594          IF l_check_date='01' AND l_check_mon='01' THEN
2595           Hr_Utility.set_location('Adding 060 record', 75);
2596           l_temp_index:=l_temp_rec060_prev_01.element_entry_id;
2597           g_rcd_060(l_temp_index).pension_sal_amount :=to_number(l_temp_rec060_prev_01.screen_entry_value);
2598           l_temp_index:=l_temp_rec060_prev_02.element_entry_id;
2599           l_temp_date:=to_date(l_temp_rec060_prev_02.source_start_date,'YYYYMMDD');
2600           g_rcd_060(l_temp_rec060_prev_02.element_entry_id).pension_sal_dt_change:=l_temp_date;
2601           g_rcd_060(l_temp_rec060_prev_02.element_entry_id).element_type:='P';
2602          END IF;
2603      END LOOP;
2604      CLOSE csr_get_060_prev_retro_val;
2605      CLOSE csr_get_060_prev_retro_date;
2606 
2607      g_rec_060_count:=g_rcd_060.COUNT;
2608      Hr_Utility.set_location('g_rec_060_count'||g_rec_060_count, 78);
2609 
2610      --------------------Record_080_Pre_Processing ---------------
2611 
2612      --Initialze the variables
2613      g_rcd_080.DELETE;
2614      g_rec_080_type1_count:=0;
2615      g_rec_080_type2_count:=0;
2616      g_rec_080_type3_count:=0;
2617      g_rec_080_type4_count:=0;
2618      --g_080_index:=0         ;
2619      g_080_display_flag:='N';
2620 
2621 
2622 
2623      FOR l_temp_rec080_01 IN csr_chk_curr_ptp_ele(p_assignment_id,p_business_group_id)
2624      LOOP
2625 
2626           OPEN  csr_chk_prev_ptp_ele(p_assignment_id,p_business_group_id,l_temp_rec080_01.effective_start_date);
2627           FETCH csr_chk_prev_ptp_ele INTO l_prev_ptp_val;
2628           Hr_Utility.set_location('g_080_index: '||g_080_index,25);
2629           IF (to_number(NVL(l_prev_ptp_val,'0')) <> to_number(NVL(l_temp_rec080_01.screen_entry_value,'0')))
2630             AND  csr_chk_prev_ptp_ele%FOUND   THEN
2631 
2632             g_ptp_index:=100;
2633             l_index:=g_ptp_index+g_rec_080_type1_count;
2634             g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_01.effective_start_date;
2635             g_rcd_080(l_index).part_time_factor:=to_number(NVL(l_temp_rec080_01.screen_entry_value,'0'));
2636             g_rec_080_type1_count:=g_rec_080_type1_count+1;
2637 
2638             Hr_Utility.set_location('Full_Profile', 75);
2639             Hr_Utility.set_location('..l_index: '||l_index, 76);
2640             Hr_Utility.set_location('..g_ptp_index: '||g_ptp_index, 77);
2641             Hr_Utility.set_location('..Validg_rec_080_type1_count: '||g_rec_080_type1_count, 78);
2642             Hr_Utility.set_location('..g_rcd_080(l_index).part_time_pct_dt_change '||g_rcd_080(l_index).part_time_pct_dt_change, 79);
2643             Hr_Utility.set_location('g_rcd_080(l_index).part_time_factor '||g_rcd_080(l_index).part_time_factor, 80);
2644             g_080_display_flag:='Y';
2645           END IF;
2646  CLOSE csr_chk_prev_ptp_ele;
2647      END LOOP;
2648 
2649 FOR l_temp_rec080_01 IN csr_get_ptp_std_cond(p_assignment_id,p_business_group_id)
2650 LOOP
2651   OPEN csr_get_prev_ptp_std_cond (p_assignment_id,l_temp_rec080_01.effective_start_date);
2652   FETCH csr_get_prev_ptp_std_cond INTO l_prev_ptp_std;
2653   IF csr_get_prev_ptp_std_cond%FOUND AND l_prev_ptp_std <> l_temp_rec080_01.pt_perc THEN
2654       g_ptp_index:=100;
2655       l_index:=g_ptp_index+g_rec_080_type1_count;
2656       g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_01.effective_start_date;
2657       g_rcd_080(l_index).part_time_factor:=l_temp_rec080_01.pt_perc;
2658       g_rec_080_type1_count:=g_rec_080_type1_count+1;
2659       g_080_display_flag:='Y';
2660   END IF;
2661   CLOSE csr_get_prev_ptp_std_cond;
2662 END LOOP;
2663 
2664      Hr_Utility.set_location('..Validg_rec_080_type1_count: '||g_rec_080_type1_count, 78);
2665 
2666      --Initialize the counter
2667      l_02_counter:=0;
2668      FOR l_temp_rec080_02 IN csr_chk_retro_ptp_ele(p_assignment_id,p_business_group_id)
2669      LOOP
2670          g_ptp_index:=200;
2671          --Store the first record details
2672          IF l_02_counter = 0 THEN
2673               l_index:=g_ptp_index+g_rec_080_type2_count;
2674              g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_02.source_start_date;
2675               g_rcd_080(l_index).part_time_factor:=to_number(l_temp_rec080_02.screen_entry_value);
2676               g_rec_080_type2_count:=g_rec_080_type2_count+1;
2677              l_ptp_change_val:=to_number(l_temp_rec080_02.screen_entry_value);
2678              g_080_display_flag:='Y';
2679          ELSE
2680          --Add record details if there is a change in Part Time Percent or not
2681          IF l_ptp_change_val <> to_number(l_temp_rec080_02.screen_entry_value) THEN
2682                l_index:=g_ptp_index+g_rec_080_type2_count;
2683                g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_02.source_start_date;
2684                g_rcd_080(l_index).part_time_factor:=to_number(l_temp_rec080_02.screen_entry_value);
2685                g_rec_080_type2_count:=g_rec_080_type2_count+1;
2686                l_ptp_change_val:=to_number(l_temp_rec080_02.screen_entry_value);
2687                g_080_display_flag:='Y';
2688          END IF;
2689  END IF;
2690  l_02_counter:=l_02_counter+1;
2691 END LOOP;
2692 
2693     Hr_Utility.set_location('..g_rec_080_type2_count: '||g_rec_080_type2_count, 78);
2694      FOR l_temp_rec080_03 IN csr_chk_inci_code_ele(p_assignment_id,p_business_group_id)
2695      LOOP
2696         OPEN  csr_chk_inci_code_chg_ele(p_assignment_id,p_business_group_id,l_temp_rec080_03.effective_start_date);
2697         FETCH csr_chk_inci_code_chg_ele INTO l_prev_iwc;
2698         IF ( to_number(l_prev_iwc) <>
2699              to_number(NVL(l_temp_rec080_03.SEGMENT1,'1'))
2700             AND  csr_chk_inci_code_chg_ele%FOUND )
2701         THEN
2702            g_ptp_index:=300;
2703            l_index:=g_ptp_index+g_rec_080_type3_count;
2704            g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_03.effective_start_date;
2705            g_rcd_080(l_index).incidental_code:=to_number(l_temp_rec080_03.segment1);
2706            g_rec_080_type3_count:=g_rec_080_type3_count+1;
2707            Hr_Utility.set_location('Full_Profile', 75);
2708            Hr_Utility.set_location('..Validg_rec_080_type3_count: '||g_rec_080_type3_count, 78);
2709            Hr_Utility.set_location('..g_rcd_080(l_index).part_time_pct_dt_change '||g_rcd_080(l_index).part_time_pct_dt_change, 79);
2710            Hr_Utility.set_location('g_rcd_080(l_index).part_time_factor '||g_rcd_080(l_index).part_time_factor, 80);
2711            g_080_display_flag:='Y';
2712          END IF;
2713        CLOSE csr_chk_inci_code_chg_ele;
2714      END LOOP;
2715      Hr_Utility.set_location('..g_rec_080_type3_count: '||g_rec_080_type3_count, 78);
2716      --Initialize the counter
2717      l_04_counter:=0;
2718      --Check for Current Year Retro IWC Changes
2719      OPEN csr_retro_pggm_gen_info_iwc;
2720      FETCH csr_retro_pggm_gen_info_iwc INTO l_check;
2721      IF csr_retro_pggm_gen_info_iwc%FOUND THEN
2722        FOR l_temp_rec080_04 IN csr_chk_retro_inci_code_ele(p_assignment_id,p_business_group_id)
2723        LOOP
2724        --Store the first record details
2725        IF l_04_counter = 0 THEN
2726          g_ptp_index:=400;
2727          l_index:=g_ptp_index+g_rec_080_type4_count;
2728          g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_04.source_start_date;
2729          g_rcd_080(l_index).incidental_code:=to_number(l_temp_rec080_04.screen_entry_value);
2730          g_rec_080_type4_count:=g_rec_080_type4_count+1;
2731          l_iwc_change_val:=to_number(l_temp_rec080_04.screen_entry_value);
2732          g_080_display_flag:='Y'; --Display the 080 record
2733        ELSE
2734        --Add record details if there is a change in IWC or not
2735        IF l_iwc_change_val <> to_number(l_temp_rec080_04.screen_entry_value) THEN
2736            l_index:=g_ptp_index+g_rec_080_type4_count;
2737            g_rcd_080(l_index).part_time_pct_dt_change:=l_temp_rec080_04.source_start_date;
2738            g_rcd_080(l_index).incidental_code:=to_number(l_temp_rec080_04.screen_entry_value);
2739            g_rec_080_type4_count:=g_rec_080_type4_count+1;
2740            l_iwc_change_val:=to_number(l_temp_rec080_04.screen_entry_value);
2741        END IF;
2742      END IF;
2743      l_04_counter:=l_04_counter+1;
2744      END LOOP;
2745      END IF;
2746      Hr_Utility.set_location('..Validg_rec_080_type4_count: '||g_rec_080_type4_count, 78);
2747      Hr_Utility.set_location('..Valid Assig Id : '||p_assignment_id, 79);
2748     ---------------End  Record 080 Processing---------------------------------
2749 
2750      --------------------Record_081_Pre_Processing ---------------
2751      --Store all the year for which hours worked or total hours have been changed retrospectively
2752 
2753      --Set flags and initialize the counter
2754      g_rcd_081.DELETE;
2755      g_main_rec_081 :='N';
2756      g_rec_081_type :='C';
2757      g_rec_081_count:=0;
2758 
2759      Hr_Utility.set_location('Record_081_Pre_Processing', 75);
2760      OPEN csr_get_081_retro_values(p_assignment_id,p_business_group_id,g_extract_params(p_business_group_id).extract_start_date);
2761      l_temp_index:=0;
2762      LOOP
2763          FETCH csr_get_081_retro_values INTO l_temp_rec081;
2764          EXIT WHEN csr_get_081_retro_values%NOTFOUND;
2765 	--Get the period start and end dates
2766 	OPEN  c_get_period_start_date(l_temp_rec081.year_of_change
2767 	                             ,p_assignment_id
2768 				     ,p_effective_date );
2769 	FETCH c_get_period_start_date INTO l_period_start_date;
2770 	CLOSE c_get_period_start_date;
2771 
2772 	OPEN  c_get_period_end_date(l_temp_rec081.year_of_change
2773 	                            ,p_assignment_id
2774 				    ,p_effective_date );
2775 	FETCH c_get_period_end_date INTO l_period_end_date;
2776 	CLOSE c_get_period_end_date;
2777         --Calculate deduction amount
2778 	l_emp_contri:=Get_Balance_value(p_assignment_id
2779                                 ,p_business_group_id
2780                                 ,'PGGM Employee Contribution'
2781                                 ,'Assignment Period To Date'
2782                                 ,l_period_start_date
2783                                 ,l_period_end_date
2784                                 );
2785     l_employer_contri:=Get_Balance_value(p_assignment_id
2786                                 ,p_business_group_id
2787                                 ,'PGGM Employer Contribution'
2788                                 ,'Assignment Period To Date'
2789                                 ,l_period_start_date
2790                                 ,l_period_end_date
2791                                 );
2792      --Process 018 only when employee has paid pension premiums
2793      IF (l_emp_contri + l_employer_contri )> 0 THEN
2794           g_rcd_081(l_temp_index).year_of_change:=l_temp_rec081.year_of_change;
2795      END IF;
2796       l_temp_index:=l_temp_index+1;
2797      END LOOP;
2798 
2799        g_rec_081_count:=g_rcd_081.COUNT;
2800        Hr_Utility.set_location('g_rec_081_count'||g_rec_081_count, 75);
2801      CLOSE csr_get_081_retro_values;
2802     ---------------End  Record 081 Processing---------------------------------
2803 
2804     END IF; -- if l_return_value = 'Y'
2805     Hr_Utility.set_location('l_return_value : '||l_return_value, 79);
2806     Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
2807     --hr_utility.trace_off;
2808     RETURN l_return_value;
2809 EXCEPTION
2810    WHEN Others THEN
2811     p_error_message :='SQL-ERRM :'||SQLERRM;
2812     Hr_Utility.set_location('..'||p_error_message,85);
2813     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2814     RETURN l_return_value;
2815 
2816 END Pension_Criteria_Full_Profile;
2817 -- =============================================================================
2818 -- Get_Street
2819 -- =============================================================================
2820 FUNCTION Get_Street
2821          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2822          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2823          ,p_effective_date       IN  Date
2824          ,p_error_message        OUT NOCOPY Varchar2
2825          ,p_data_element_value   OUT NOCOPY Varchar2
2826           ) RETURN Number IS
2827 
2828 
2829 CURSOR cur_get_street(c_person_id IN Number) IS
2830 SELECT region_1
2831   FROM per_addresses_v
2832  WHERE person_id = c_person_id
2833    AND p_effective_date BETWEEN date_from
2834    AND Nvl(date_to,Hr_Api.g_eot)
2835    AND primary_flag = 'Y'
2836    AND style = 'NL'
2837 UNION
2838 SELECT address_line1
2839   FROM per_addresses_v
2840  WHERE person_id = c_person_id
2841    AND p_effective_date BETWEEN date_from
2842    AND Nvl(date_to,Hr_Api.g_eot)
2843    AND primary_flag = 'Y'
2844    AND style = 'NL_GLB';
2845 
2846 l_street     per_addresses_v.region_1%TYPE;
2847 l_proc_name Varchar2(150) := g_proc_name ||'Get_Street';
2848 
2849 BEGIN
2850    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
2851 
2852    OPEN cur_get_street(g_person_id);
2853    FETCH cur_get_street INTO l_street;
2854    CLOSE cur_get_street;
2855 
2856    p_data_element_value := Upper(l_street);
2857    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
2858    RETURN 0;
2859 
2860 EXCEPTION
2861    WHEN Others THEN
2862     p_error_message :='SQL-ERRM :'||SQLERRM;
2863     Hr_Utility.set_location('..'||p_error_message,85);
2864     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2865     RETURN -1;
2866 END Get_Street;
2867 
2868 -- =============================================================================
2869 -- Get_House_Num
2870 -- =============================================================================
2871 FUNCTION Get_House_Num
2872          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2873          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2874          ,p_effective_date       IN  Date
2875          ,p_error_message        OUT NOCOPY Varchar2
2876          ,p_data_element_value   OUT NOCOPY Varchar2
2877           ) RETURN Number IS
2878 
2879 CURSOR cur_get_house_num(c_person_id IN Number) IS
2880 SELECT add_information13
2881   FROM per_addresses_v
2882  WHERE person_id = c_person_id
2883   AND  p_effective_date BETWEEN date_from
2884   AND  Nvl(date_to,Hr_Api.g_eot)
2885   AND style = 'NL'
2886   AND  primary_flag = 'Y'
2887 UNION
2888 SELECT address_line2
2889   FROM per_addresses_v
2890  WHERE person_id = c_person_id
2891   AND  p_effective_date BETWEEN date_from
2892   AND  Nvl(date_to,Hr_Api.g_eot)
2893   AND style = 'NL_GLB'
2894   AND  primary_flag = 'Y';
2895 
2896 
2897 l_house_num    per_addresses_v.address_line1%TYPE;
2898 l_proc_name    Varchar2(150) := g_proc_name ||'Get_House_Num';
2899 l_ret_val      Number := 0;
2900 
2901 BEGIN
2902    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
2903    OPEN cur_get_house_num(g_person_id);
2904    FETCH cur_get_house_num INTO l_house_num;
2905    CLOSE cur_get_house_num;
2906    p_data_element_value := Upper(l_house_num);
2907    l_ret_val :=0;
2908    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
2909    RETURN l_ret_val;
2910 EXCEPTION
2911    WHEN Others THEN
2912     p_error_message :='SQL-ERRM :'||SQLERRM;
2913     Hr_Utility.set_location('..'||p_error_message,85);
2914     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2915     RETURN l_ret_val;
2916 END Get_House_Num;
2917 
2918 -- =============================================================================
2919 -- Get_Addl_House_Num
2920 -- =============================================================================
2921 FUNCTION Get_Addl_House_Num
2922          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2923          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2924          ,p_effective_date       IN  Date
2925          ,p_error_message        OUT NOCOPY Varchar2
2926          ,p_data_element_value   OUT NOCOPY Varchar2
2927          ) RETURN Number IS
2928 
2929 
2930 CURSOR cur_get_addl_house_num(c_person_id IN Number) IS
2931 SELECT add_information14
2932   FROM per_addresses_v
2933  WHERE person_id = c_person_id
2934   AND  p_effective_date BETWEEN date_from
2935   AND  Nvl(date_to,Hr_Api.g_eot)
2936   AND  primary_flag = 'Y'
2937   AND  style = 'NL'
2938 UNION
2939 SELECT address_line3
2940   FROM per_addresses_v
2941  WHERE person_id = c_person_id
2942   AND  p_effective_date BETWEEN date_from
2943   AND  Nvl(date_to,Hr_Api.g_eot)
2944   AND  primary_flag = 'Y'
2945   AND  style = 'NL_GLB';
2946 
2947 l_addl_house_num    per_addresses_v.address_line1%TYPE;
2948 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Addnl_House_Num';
2949 l_ret_val      Number := 0;
2950 
2951 BEGIN
2952    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
2953    OPEN cur_get_addl_house_num(g_person_id);
2954    FETCH cur_get_addl_house_num INTO l_addl_house_num;
2955    CLOSE cur_get_addl_house_num;
2956 
2957    p_data_element_value := Upper(l_addl_house_num);
2958    l_ret_val :=0;
2959 
2960    Hr_Utility.set_location('Leaving:   '||l_proc_name, 15);
2961    RETURN l_ret_val;
2962 
2963 EXCEPTION
2964    WHEN Others THEN
2965     p_error_message :='SQL-ERRM :'||SQLERRM;
2966     Hr_Utility.set_location('..'||p_error_message,85);
2967     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
2968     RETURN l_ret_val;
2969 END Get_Addl_House_Num;
2970 
2971 -- =============================================================================
2972 -- Get_Postal_Code
2973 -- =============================================================================
2974 FUNCTION Get_Postal_Code
2975          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
2976          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
2977          ,p_effective_date       IN  Date
2978          ,p_error_message        OUT NOCOPY Varchar2
2979          ,p_data_element_value   OUT NOCOPY Varchar2
2980           ) RETURN Number IS
2981 
2982 
2983 CURSOR cur_get_postal_code(c_person_id IN Number) IS
2984 SELECT postal_code
2985   FROM per_addresses_v
2986  WHERE person_id = c_person_id
2987    AND p_effective_date BETWEEN date_from
2988    AND Nvl(date_to,Hr_Api.g_eot)
2989    AND  style IN ('NL','NL_GLB')
2990    AND primary_flag = 'Y';
2991 
2992 l_postal_code   per_addresses_v.postal_code%TYPE;
2993 l_postal_code1  per_addresses_v.postal_code%TYPE;
2994 temp_str       varchar2(1);
2995 i              Number := 0;
2996 l_proc_name    Varchar2(150) := g_proc_name ||'Get_Postal_Code';
2997 l_ret_val      Number :=0;
2998 
2999 BEGIN
3000    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3001    OPEN cur_get_postal_code(g_person_id);
3002    FETCH cur_get_postal_code INTO l_postal_code;
3003    IF cur_get_postal_code%FOUND THEN
3004       CLOSE cur_get_postal_code;
3005       FOR i in 1..length(l_postal_code)
3006       LOOP
3007          SELECT substr(l_postal_code,i,1) INTO temp_str from dual;
3008          IF temp_str <> ' ' THEN
3009             l_postal_code1 := l_postal_code1||temp_str;
3010          END IF;
3011       END LOOP;
3012       p_data_element_value := Upper(substr(l_postal_code1,0,6));
3013    ELSE
3014      CLOSE cur_get_postal_code;
3015      p_data_element_value := '';
3016    END IF;
3017    l_ret_val :=0;
3018    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
3019    RETURN l_ret_val;
3020 
3021 EXCEPTION
3022    WHEN Others THEN
3023     p_error_message :='SQL-ERRM :'||SQLERRM;
3024     Hr_Utility.set_location('..'||p_error_message,85);
3025     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
3026     RETURN l_ret_val;
3027 END Get_Postal_Code;
3028 -- =============================================================================
3029 -- Get_City
3030 -- =============================================================================
3031 FUNCTION Get_City
3032          (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
3033          ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
3034          ,p_effective_date       IN  Date
3035          ,p_error_message        OUT NOCOPY Varchar2
3036          ,p_data_element_value   OUT NOCOPY Varchar2
3037           ) RETURN Number IS
3038 
3039 
3040 CURSOR cur_get_city(c_person_id IN Number) IS
3041 SELECT town_or_city
3042   FROM per_addresses_v
3043  WHERE person_id = c_person_id
3044    AND p_effective_date BETWEEN date_from
3045    AND Nvl(date_to,Hr_Api.g_eot)
3046    AND style IN ('NL','NL_GLB')
3047    AND primary_flag = 'Y';
3048 
3049 CURSOR cur_get_foreign_coun(c_person_id IN Number) IS
3050 SELECT Decode(country,'NL','N',country) code
3051       ,d_country
3052   FROM per_addresses_v
3053  WHERE person_id = c_person_id
3054   AND  p_effective_date BETWEEN date_from
3055   AND  Nvl(date_to,Hr_Api.g_eot)
3056   AND style IN ('NL','NL_GLB')
3057   AND  primary_flag = 'Y';
3058 
3059 
3060 CURSOR c_city (p_lookup_code IN VARCHAR2) IS
3061 SELECT meaning
3062   FROM hr_lookups
3063  WHERE lookup_type = 'HR_NL_CITY'
3064    AND lookup_code = p_lookup_code;
3065 
3066 
3067 l_city         per_addresses_v.town_or_city%TYPE;
3068 l_city_name    hr_lookups.meaning%TYPE;
3069 l_country      per_addresses_v.d_country%TYPE;
3070 l_code         per_addresses_v.country%TYPE;
3071 l_proc_name    Varchar2(150) := g_proc_name ||'Get_City';
3072 l_ret_val      Number :=0;
3073 
3074 BEGIN
3075    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3076 
3077    OPEN cur_get_city(g_person_id);
3078    FETCH cur_get_city INTO l_city;
3079    CLOSE cur_get_city;
3080 
3081 /*   OPEN cur_get_foreign_coun(g_person_id);
3082    FETCH cur_get_foreign_coun INTO l_code,l_country;
3083    CLOSE cur_get_foreign_coun; */
3084 
3085    IF l_city IS NOT NULL THEN
3086      FOR c_city_rec IN c_city (l_city) LOOP
3087         l_city_name := c_city_rec.meaning;
3088      END LOOP;
3089    END IF;
3090 
3091    l_city_name := nvl(l_city_name,l_city);
3092 
3093    IF l_code <> 'N' THEN
3094       p_data_element_value := Upper(l_city_name); --||' '||Upper(l_country);
3095    ELSE
3096       p_data_element_value := Upper(l_city_name);
3097    END IF;
3098 
3099   l_ret_val :=0;
3100 
3101    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
3102    RETURN l_ret_val;
3103 
3104 EXCEPTION
3105    WHEN Others THEN
3106     p_error_message :='SQL-ERRM :'||SQLERRM;
3107     Hr_Utility.set_location('..'||p_error_message,85);
3108     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
3109     RETURN l_ret_val;
3110 END Get_City;
3111 --============================================================================
3112 --GET_PERSON_INITIALS
3113 --============================================================================
3114 FUNCTION Get_Person_Initials
3115          ( p_assignment_id      IN Number
3116           ,p_business_group_id  IN Number
3117           ,p_date_earned        IN Date
3118           ,p_error_message      OUT NOCOPY Varchar2
3119           ,p_data_element_value OUT NOCOPY Varchar2
3120          ) RETURN Number IS
3121 
3122     CURSOR cur_get_initials(c_person_id   IN Number,
3123                             c_date_earned IN Date) IS
3124     SELECT Substr(replace(per_information1,'.',NULL),1,5)
3125       FROM per_all_people_f
3126      WHERE person_id         = c_person_id
3127        AND business_group_id = p_business_group_id
3128        AND c_date_earned BETWEEN effective_start_date
3129                              AND effective_end_date;
3130 
3131     l_initials     Varchar2(5);
3132     l_proc_name    Varchar2(150) := g_proc_name ||'Get_Person_Initials';
3133     l_return_value Number :=0;
3134 
3135 BEGIN
3136 
3137     Hr_Utility.set_location('Entering: '||l_proc_name, 5);
3138 
3139     --Get the initials stored as entered by user
3140     OPEN cur_get_initials(g_person_id,p_date_earned);
3141        FETCH cur_get_initials INTO l_initials;
3142     CLOSE cur_get_initials;
3143     p_data_element_value := l_initials;
3144 
3145     Hr_Utility.set_location('Leaving: '||l_proc_name, 10);
3146     RETURN l_return_value;
3147 
3148 EXCEPTION
3149    WHEN Others THEN
3150     p_error_message :='SQL-ERRM :'||SQLERRM;
3151     Hr_Utility.set_location('..'||p_error_message,7);
3152     Hr_Utility.set_location('Leaving: '||l_proc_name, 9);
3153     l_return_value := -1;
3154     RETURN l_return_value;
3155 END Get_Person_Initials;
3156 -- =============================================================================
3157 -- Get_Gender:
3158 -- =============================================================================
3159 FUNCTION Get_Gender
3160           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
3161           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
3162           ,p_effective_date     IN  Date
3163           ,p_error_message      OUT NOCOPY Varchar2
3164           ,p_data_element_value OUT NOCOPY Varchar2
3165           ) RETURN Number IS
3166 CURSOR cur_get_gender(c_date_earned       IN Date
3167                      ,c_business_group_id IN Number) IS
3168 SELECT Decode(sex,'F','V','M') gender
3169   FROM per_all_people_f
3170  WHERE person_id         = g_person_id
3171    AND business_group_id = c_business_group_id
3172    AND c_date_earned BETWEEN effective_start_date
3173                          AND effective_end_date;
3174 
3175  l_proc_name Varchar2(150) := g_proc_name ||'Get_Gender';
3176  l_gender    Varchar2(2);
3177  l_return_value   Number:=0;
3178 
3179 BEGIN
3180    Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3181    OPEN  cur_get_gender(p_effective_date,p_business_group_id);
3182    FETCH cur_get_gender INTO l_gender;
3183    CLOSE cur_get_gender;
3184    p_data_element_value := l_gender;
3185 
3186    Hr_Utility.set_location('p_data_element_value:'||p_data_element_value, 5);
3187    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
3188 
3189    l_return_value := 0;
3190    RETURN l_return_value;
3191 
3192 EXCEPTION
3193    WHEN Others THEN
3194     p_error_message :='SQL-ERRM :'||SQLERRM;
3195     Hr_Utility.set_location('..'||p_error_message,85);
3196     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
3197     l_return_value := -1;
3198     RETURN l_return_value;
3199 END Get_Gender;
3200 -- =============================================================================
3201 -- Get_Occupation_Code --function to get the Occupation Code
3202 -- =============================================================================
3203 
3204 FUNCTION Get_Occupation_Code
3205          (p_assignment_id      IN  Number
3206          ,p_business_group_id  IN Number
3207          ,p_effective_date     IN Date
3208          ,p_error_message      OUT NOCOPY Varchar2
3209          ,p_data_element_value OUT NOCOPY Varchar2
3210          ) RETURN Number IS
3211 
3212 --cursor to fetch the Occupation_Code
3213 --from the soft coding key flex
3214 CURSOR c_get_emp_code IS
3215 SELECT scl.SEGMENT2||scl.SEGMENT3
3216   FROM per_all_assignments_f asg
3217       ,hr_soft_coding_keyflex scl
3218 WHERE asg.assignment_id = p_assignment_id
3219   AND p_effective_date BETWEEN asg.effective_start_date
3220   AND asg.effective_end_date
3221   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
3222 
3223 l_emp_code Varchar2(120);
3224 l_emp_kind Varchar2(1);
3225 l_proc_name Varchar2(150) := 'Get_Occupation_Code';
3226 
3227 BEGIN
3228 
3229 Hr_Utility.set_location('Entering : '||l_proc_name,10);
3230 --first fetch the employment code from the soft coding keyflex
3231 OPEN c_get_emp_code;
3232 FETCH c_get_emp_code INTO l_emp_code;
3233 IF c_get_emp_code%FOUND THEN
3234    CLOSE c_get_emp_code;
3235    Hr_Utility.set_location('found the code as : '||l_emp_code,20);
3236    p_data_element_value := l_emp_code;
3237 ELSE
3238    CLOSE c_get_emp_code;
3239    p_data_element_value := '';
3240 END IF;
3241 Hr_Utility.set_location('Leaving : '||l_proc_name,50);
3242 RETURN 0;
3243 EXCEPTION
3244 WHEN Others THEN
3245 p_error_message := SQLERRM;
3246 Hr_Utility.set_location('error message : '||SQLERRM,10);
3247 Hr_Utility.set_location('Leaving : '||l_proc_name,50);
3248 p_data_element_value := '';
3249 RETURN 1;
3250 
3251 END Get_Occupation_Code;
3252 -- =============================================================================
3253 -- Get_PGGM_ER_Num
3254 -- Private function to fetch PGGM Employer Number stored in Org DDF
3255 -- =============================================================================
3256 Function Get_PGGM_ER_Num
3257 ( p_assignment_id      IN Number
3258  ,p_business_group_id  IN Number
3259  ,p_date_earned        IN Date
3260  ,p_error_message      OUT NOCOPY Varchar2
3261  ,p_data_element_value OUT NOCOPY Varchar2
3262 )
3263  Return Number IS
3264 --local variables
3265 l_proc_name  Varchar2(150) := g_proc_name ||'Get_PGGM_ER_Num';
3266 l_ret_val    Number := 0;
3267 
3268 Begin
3269 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3270 
3271 --return the pggm employer number which has been set for Parent organization
3272 --for all child orgs also,only this value has to be reported
3273 p_data_element_value:=g_pggm_employer_num;
3274 
3275 
3276 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
3277 l_ret_val:=0;
3278 
3279 RETURN l_ret_val;
3280 EXCEPTION
3281    WHEN OTHERS THEN
3282       p_error_message :='SQL-ERRM :'||SQLERRM;
3283       Hr_Utility.set_location('..'||p_error_message,30);
3284       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3285       RETURN l_ret_val;
3286 END Get_PGGM_ER_Num;
3287 
3288 -- ===============================================================================
3289 -- ~ Function to get the Kind of participation stored in PGGM General Info Element as I/P val
3290 -- ===============================================================================
3291 Function Get_Kind_Of_PTP
3292                  ( p_assignment_id       IN Number
3293                    ,p_business_group_id  IN Number
3294                    ,p_date_earned        IN DATE
3295                    ,p_error_message      OUT NOCOPY VARCHAR2
3296                    ,p_data_element_value OUT NOCOPY VARCHAR2
3297                  )
3298 Return Number IS
3299 CURSOR csr_get_kind_of_ptp(c_asg_id IN Number,c_date_earned IN DATE)  IS
3300 SELECT peev.screen_entry_value
3301 FROM
3302 pay_element_types_f pet,
3303 pay_input_values_f piv,
3304 pay_element_entries_f pee,
3305 pay_element_entry_values_f peev
3306 WHERE
3307   pet.element_name = 'PGGM Pensions General Information'
3308   and piv.name ='Kind Of Participation'
3309   and piv.element_type_id=pet.element_type_id
3310   and pee.element_type_id=pet.element_type_id
3311   and pee.assignment_id =c_asg_id
3312   and (c_date_earned between pee.effective_start_date
3313        and pee.effective_end_date)
3314   and peev.element_entry_id=pee.element_entry_id
3315   and peev.input_value_id=piv.input_value_id
3316   and (c_date_earned between peev.effective_start_date
3317        and peev.effective_end_date );
3318 --5869420
3319 CURSOR csr_get_primary_asg (c_assgt_id NUMBER, c_date DATE) IS
3320 SELECT pri.assignment_id
3321 FROM per_all_assignments_f sec,
3322 per_all_assignments_f pri
3323 WHERE sec.assignment_id = c_assgt_id
3324 AND sec.person_id = pri.person_id
3325 AND pri.primary_flag = 'Y'
3326 AND c_date BETWEEN pri.effective_start_date AND pri.effective_end_date
3327 AND c_date BETWEEN sec.effective_start_date AND sec.effective_end_date;
3328 --
3329 l_primary_flag VARCHAR2(2);
3330 l_pri_assignment_id NUMBER;
3331 --End of 5869420
3332 
3333 l_proc_name   Varchar2(150):=g_proc_name || 'Get_Kind_Of_PTP';
3334 l_ret_val     Number:=0;
3335 l_kind_of_ptp varchar2(2):='';
3336 
3337 BEGIN
3338 Hr_Utility.set_location('Entering:   '||l_proc_name,5);
3339 OPEN csr_get_kind_of_ptp(p_assignment_id,p_date_earned);
3340 FETCH csr_get_kind_of_ptp INTO l_kind_of_ptp;
3341 IF csr_get_kind_of_ptp%FOUND THEN
3342      p_data_element_value:=l_kind_of_ptp;
3343      l_ret_val := 0;
3344 END IF;
3345 CLOSE csr_get_kind_of_ptp;
3346 
3347 --5869420
3348 --If Participation Kind is not entered for this assignment, and if this is a
3349 --secondary assignment, get the value from the primary assignment.
3350 IF l_kind_of_ptp = '' OR l_kind_of_ptp IS NULL THEN
3351    OPEN csr_chk_primary_asg (p_assignment_id, p_date_earned);
3352    FETCH csr_chk_primary_asg INTO l_primary_flag;
3353    IF csr_chk_primary_asg%NOTFOUND THEN
3354         OPEN csr_get_primary_asg (p_assignment_id, p_date_earned);
3355         FETCH csr_get_primary_asg INTO l_pri_assignment_id;
3356         CLOSE csr_get_primary_asg;
3357         OPEN csr_get_kind_of_ptp(l_pri_assignment_id,p_date_earned);
3358         FETCH csr_get_kind_of_ptp INTO l_kind_of_ptp;
3359              p_data_element_value:=l_kind_of_ptp;
3360              l_ret_val := 0;
3361         CLOSE csr_get_kind_of_ptp;
3362    END IF;
3363    CLOSE csr_chk_primary_asg;
3364 END IF;
3365 --End of 5869420
3366 
3367 Hr_Utility.set_location(' Leaving:   '||l_proc_name,20);
3368 RETURN l_ret_val;
3369 EXCEPTION
3370    WHEN OTHERS THEN
3371       p_error_message :='SQL-ERRM :'||SQLERRM;
3372       Hr_Utility.set_location('..'||p_error_message,30);
3373       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3374       RETURN l_ret_val;
3375 END Get_Kind_Of_PTP;
3376 -- ===============================================================================
3377 -- ~ Function to get the CAO Code stored in Org DDF
3378 -- ===============================================================================
3379 Function Get_CAO_Code
3380                  ( p_assignment_id       IN Number
3381                    ,p_business_group_id  IN Number
3382                    ,p_date_earned        IN DATE
3383                    ,p_error_message      OUT NOCOPY VARCHAR2
3384                    ,p_data_element_value OUT NOCOPY VARCHAR2
3385  )
3386 Return Number is
3387 -- Cursor to get Org id for the given asg id
3388 CURSOR csr_get_org_id IS
3389 SELECT fnd_number.canonical_to_number (ppf.prl_information1)
3390   FROM per_all_assignments_f paf,
3391        pay_all_payrolls_f ppf
3392  WHERE paf.assignment_id = p_assignment_id
3393    AND paf.business_group_id = p_business_group_id
3394    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN
3395        paf.effective_start_date AND paf.effective_end_date
3396    AND paf.payroll_id = ppf.payroll_id
3397    AND ppf.prl_information_category = 'NL';
3398 
3399 --Cursor to fetch the CAO Code from
3400 --org information context
3401 CURSOR csr_get_cao_code(c_org_id IN Number) IS
3402 SELECT SUBSTR(org_information6,1,6)
3403   FROM hr_organization_information
3404  WHERE org_information_context = 'PQP_NL_PGGM_INFO'
3405    AND organization_id = c_org_id
3406    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN
3407        fnd_date.canonical_to_date (org_information1)
3408        AND nvl(fnd_date.canonical_to_date (org_information2), to_date('47121231','YYYYMMDD'));
3409 
3410 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_CAO_Code';
3411 l_ret_val     Number:=0;
3412 l_cao_code    varchar2(10):='';
3413 l_org_id      Number:=0;
3414 BEGIN
3415 Hr_Utility.set_location('Entering:   '||l_proc_name,5);
3416 -- Get org id
3417  OPEN csr_get_org_id;
3418  FETCH csr_get_org_id  INTO l_org_id;
3419  CLOSE csr_get_org_id ;
3420 
3421  Hr_Utility.set_location('l_org_id: '||l_org_id,10);
3422 
3423  -- Get CAO Code from derived org id
3424  OPEN csr_get_cao_code(l_org_id);
3425  FETCH csr_get_cao_code INTO l_cao_code;
3426  IF csr_get_cao_code%FOUND AND ( l_cao_code <> ' ' OR l_cao_code IS NOT NULL)  THEN
3427     CLOSE csr_get_cao_code;
3428  ELSE
3429     CLOSE csr_get_cao_code;
3430     Hr_Utility.set_location('CAO not found at org level',30);
3431     --Fetch CAO code of parent org
3432     Hr_Utility.set_location('Fetching CAO code of parent org',40);
3433     OPEN csr_get_cao_code(g_extract_params(p_business_group_id).org_id);
3434     FETCH csr_get_cao_code INTO l_cao_code;
3435     IF csr_get_cao_code%NOTFOUND THEN
3436       l_cao_code:=NULL;
3437     END IF;
3438     Hr_Utility.set_location('l_cao_code'||l_cao_code,50);
3439     CLOSE csr_get_cao_code;
3440  END If;
3441 
3442  l_ret_val := 0;
3443  p_data_element_value:=SUBSTR(l_cao_code,1,5);
3444  p_data_element_value:=lpad(p_data_element_value,4,'0');
3445 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
3446 RETURN l_ret_val;
3447 EXCEPTION
3448    WHEN OTHERS THEN
3449       p_error_message :='SQL-ERRM :'||SQLERRM;
3450       Hr_Utility.set_location('..'||p_error_message,30);
3451       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3452       RETURN l_ret_val;
3453 END Get_CAO_Code;
3454 -- ===============================================================================
3455 -- ~ Function to get the Employer Registration Number stored in Org DDF
3456 -- ===============================================================================
3457 Function Get_Emp_Reg_Num
3458                  ( p_assignment_id       IN Number
3459                    ,p_business_group_id  IN Number
3460                    ,p_date_earned        IN DATE
3461                    ,p_error_message      OUT NOCOPY VARCHAR2
3462                    ,p_data_element_value OUT NOCOPY VARCHAR2
3463  )
3464 Return Number is
3465 
3466 -- Cursor to get Org id for the given asg id
3467 CURSOR csr_get_org_id IS
3468 SELECT fnd_number.canonical_to_number (ppf.prl_information1)
3469   FROM per_all_assignments_f paf,
3470        pay_all_payrolls_f ppf
3471  WHERE paf.assignment_id = p_assignment_id
3472    AND paf.business_group_id = p_business_group_id
3473    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN
3474        paf.effective_start_date AND paf.effective_end_date
3475    AND paf.payroll_id = ppf.payroll_id
3476    AND ppf.prl_information_category = 'NL';
3477 
3478 --Cursor to fetch the Emp Reg No. from
3479 --org information context
3480 CURSOR csr_emp_reg_num(c_org_id IN Number) IS
3481 SELECT lpad(org_information7,15,'0')
3482   FROM hr_organization_information
3483  WHERE organization_id = c_org_id
3484    AND org_information_context = 'PQP_NL_PGGM_INFO'
3485    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN
3486        fnd_date.canonical_to_date (org_information1)
3487        AND nvl(fnd_date.canonical_to_date (org_information2), to_date('47121231','YYYYMMDD'));
3488 
3489 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Emp_Reg_Num';
3490 l_ret_val     Number:=0;
3491 l_emp_reg_num varchar2(16):='';
3492 l_org_id      Number:=0;
3493 BEGIN
3494 Hr_Utility.set_location('Entering:   '||l_proc_name,5);
3495 -- Get org id
3496  OPEN csr_get_org_id;
3497  FETCH csr_get_org_id  INTO l_org_id;
3498  CLOSE csr_get_org_id ;
3499 
3500  Hr_Utility.set_location('l_org_id: '||l_org_id,10);
3501 
3502  -- Get Emp Reg Num Code from derived org id
3503  OPEN csr_emp_reg_num(l_org_id);
3504  FETCH csr_emp_reg_num INTO l_emp_reg_num;
3505  IF csr_emp_reg_num%FOUND AND (l_emp_reg_num <> ' ' OR l_emp_reg_num IS NOT NULL) THEN
3506     CLOSE csr_emp_reg_num;
3507     l_ret_val := 0;
3508  ELSE
3509     CLOSE csr_emp_reg_num;
3510     --If not found at org level then fetch it from parent org level
3511     OPEN csr_emp_reg_num(g_extract_params(p_business_group_id).org_id);
3512     FETCH csr_emp_reg_num INTO l_emp_reg_num;
3513     IF csr_emp_reg_num%NOTFOUND THEN
3514        l_emp_reg_num:=NULL;
3515     END IF;
3516     CLOSE csr_emp_reg_num;
3517 
3518  END If;
3519  p_data_element_value:=l_emp_reg_num;
3520 
3521 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
3522 RETURN l_ret_val;
3523 EXCEPTION
3524    WHEN OTHERS THEN
3525       p_error_message :='SQL-ERRM :'||SQLERRM;
3526       Hr_Utility.set_location('..'||p_error_message,30);
3527       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3528       RETURN l_ret_val;
3529 END Get_Emp_Reg_Num;
3530 -- ===============================================================================
3531 -- ~ Function to get the PGGM Emp Number stored in PGGM General Info Element as I/P val
3532 -- ===============================================================================
3533 Function Get_PGGM_Ee_Num
3534 (p_assignment_id      IN Number
3535 ,p_business_group_id  IN Number
3536 ,p_date_earned        IN DATE
3537 ,p_error_message      OUT NOCOPY VARCHAR2
3538 ,p_data_element_value OUT NOCOPY VARCHAR2
3539 )
3540 Return Number is
3541 --Cursor to get PGGM employee number
3542 CURSOR csr_get_pggm_ee_num(c_asg_id IN Number,c_date_earned IN DATE)
3543 IS
3544 SELECT substr(NVL(peev.screen_entry_value,'0'),1,3)
3545 FROM
3546 pay_element_types_f pet,
3547 pay_input_values_f piv,
3548 pay_element_entries_f pee,
3549 pay_element_entry_values_f peev
3550 WHERE
3551   pet.element_name = 'PGGM Pensions General Information'
3552   and piv.name ='PGGM Employee Number'
3553   and piv.element_type_id=pet.element_type_id
3554   and pee.element_type_id=pet.element_type_id
3555   and pee.assignment_id =c_asg_id
3556   and (c_date_earned between pee.effective_start_date
3557        and pee.effective_end_date)
3558   and peev.element_entry_id=pee.element_entry_id
3559   and peev.input_value_id=piv.input_value_id
3560   and (c_date_earned between peev.effective_start_date
3561        and peev.effective_end_date);
3562 
3563 CURSOR csr_get_primary_asg (c_assgt_id NUMBER, c_date DATE) IS
3564 SELECT pri.assignment_id
3565 FROM per_all_assignments_f sec,
3566 per_all_assignments_f pri
3567 WHERE sec.assignment_id = c_assgt_id
3568 AND sec.person_id = pri.person_id
3569 AND pri.primary_flag = 'Y'
3570 AND c_date BETWEEN pri.effective_start_date AND pri.effective_end_date
3571 AND c_date BETWEEN sec.effective_start_date AND sec.effective_end_date;
3572 --
3573 l_primary_flag VARCHAR2(2);
3574 l_pri_assignment_id NUMBER;
3575 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_PGGM_Ee_Num';
3576 l_ret_val     Number :=0;
3577 l_pggm_ee_num varchar2(30) :='0';
3578 Begin
3579 Hr_Utility.set_location(' Entering     ' || l_proc_name , 5);
3580 OPEN csr_get_pggm_ee_num(p_assignment_id,p_date_earned);
3581 FETCH csr_get_pggm_ee_num INTO l_pggm_ee_num;
3582 Hr_Utility.set_location('l_pggm_ee_num: '||l_pggm_ee_num, 45);
3583 IF csr_get_pggm_ee_num%FOUND THEN
3584      p_data_element_value:=l_pggm_ee_num;
3585      l_ret_val :=0;
3586 END If;
3587 Hr_Utility.set_location('p_data_element_value: '||p_data_element_value, 45);
3588 CLOSE csr_get_pggm_ee_num;
3589 
3590 --If PGGM EE Num is not entered for this assignment, and if this is a
3591 --secondary assignment, get the value from the primary assignment.
3592 IF l_pggm_ee_num = '0' THEN
3593    OPEN csr_chk_primary_asg (p_assignment_id, p_date_earned);
3594    FETCH csr_chk_primary_asg INTO l_primary_flag;
3595    IF csr_chk_primary_asg%NOTFOUND THEN
3596         OPEN csr_get_primary_asg (p_assignment_id, p_date_earned);
3597         FETCH csr_get_primary_asg INTO l_pri_assignment_id;
3598         CLOSE csr_get_primary_asg;
3599         OPEN csr_get_pggm_ee_num(l_pri_assignment_id,p_date_earned);
3600         FETCH csr_get_pggm_ee_num INTO l_pggm_ee_num;
3601              p_data_element_value:=l_pggm_ee_num;
3602              l_ret_val := 0;
3603         CLOSE csr_get_pggm_ee_num;
3604    END IF;
3605    CLOSE csr_chk_primary_asg;
3606 END IF;
3607 RETURN l_ret_val;
3608 EXCEPTION
3609   WHEN Others THEN
3610      p_error_message :='SQL-ERRM :'||SQLERRM;
3611      Hr_Utility.set_location('..Exception Others Raised at Get_PGGM_Ee_Num'||p_error_message,40);
3612      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
3613      l_ret_val:=1;
3614      RETURN l_ret_val;
3615 END Get_PGGM_Ee_Num;
3616 
3617 -- =============================================================================
3618 -- Get_EE_Num:
3619 -- =============================================================================
3620 FUNCTION Get_EE_Num
3621           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
3622           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
3623           ,p_effective_date     IN  Date
3624           ,p_error_message      OUT NOCOPY Varchar2
3625           ,p_data_element_value OUT NOCOPY Varchar2
3626           ) RETURN Number IS
3627 
3628   l_proc_name    VARCHAR2(150) := g_proc_name ||'Get_EE_Num';
3629   l_per_ee_num   per_all_people_f.employee_number%TYPE;
3630   l_asg_seq_num  VARCHAR2(2);
3631 
3632 BEGIN
3633 
3634   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3635 
3636   IF g_primary_assig.EXISTS(p_assignment_id) THEN
3637 
3638      l_per_ee_num := g_primary_assig (p_assignment_id).ee_num;
3639 
3640      --
3641      -- Derive the assignment sequence number for the assignment
3642      --
3643      IF g_primary_assig (p_assignment_id).asg_seq_num < 10 THEN
3644         l_asg_seq_num := '0'||g_primary_assig(p_assignment_id).asg_seq_num;
3645      ELSE
3646         l_asg_seq_num := g_primary_assig(p_assignment_id).asg_seq_num;
3647      END IF;
3648 
3649      --
3650      -- Add the asg seq number to the EE number
3651      --
3652      l_per_ee_num := l_per_ee_num || l_asg_seq_num;
3653      l_per_ee_num := lpad(l_per_ee_num,15,'0');
3654      Hr_Utility.set_location('l_asg_seq_num:   '||l_asg_seq_num, 5);
3655 
3656   END IF;
3657 
3658   p_data_element_value := Nvl(l_per_ee_num,'000000000000000');
3659 
3660   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
3661 
3662   RETURN 0;
3663 
3664 EXCEPTION
3665    WHEN Others THEN
3666     p_error_message :='SQL-ERRM :'||SQLERRM;
3667     Hr_Utility.set_location('..'||p_error_message,85);
3668     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
3669     RETURN -1;
3670 END Get_EE_Num;
3671 
3672 -- =============================================================================
3673 -- Get_Hire_Date
3674 -- =============================================================================
3675 FUNCTION Get_Hire_Date
3676           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
3677           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
3678           ,p_effective_date     IN  Date
3679           ,p_error_message      OUT NOCOPY Varchar2
3680           ,p_data_element_value OUT NOCOPY Varchar2
3681           ) RETURN Number IS
3682 
3683 
3684 -- Cursor to get the hire date of the person
3685 /*Cursor csr_get_hire_date IS
3686  SELECT max(date_start)
3687 FROM  per_all_assignments_f asg
3688       ,per_periods_of_service pps
3689 WHERE pps.person_id     = asg.person_id
3690    AND asg.assignment_id = p_assignment_id
3691    AND pps.business_group_id = p_business_group_id
3692    AND date_start <= p_effective_date;*/
3693 
3694 
3695 -- Cursor to get the hire date of the assignment
3696 CURSOR csr_get_hire_date IS
3697 SELECT min(effective_start_date)
3698 FROM  per_all_assignments_f asg
3699 WHERE asg.assignment_id = p_assignment_id
3700    AND asg.business_group_id = p_business_group_id
3701    AND asg.assignment_type='E';
3702 
3703 
3704   l_proc_name       Varchar2(150) := g_proc_name ||'Get_Hire_Date';
3705   l_hire_date       DATE;
3706   BEGIN
3707   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3708 
3709   OPEN csr_get_hire_date;
3710   FETCH csr_get_hire_date INTO l_hire_date;
3711   IF csr_get_hire_date%FOUND THEN
3712   p_data_element_value:=to_char(l_hire_date,'YYYYMMDD');
3713   END IF;
3714   CLOSE csr_get_hire_date;
3715 
3716 
3717   Hr_Utility.set_location('Leaving:   '||l_proc_name, 45);
3718   RETURN 0;
3719 EXCEPTION
3720    WHEN Others THEN
3721     p_error_message :='SQL-ERRM :'||SQLERRM;
3722     Hr_Utility.set_location('..'||p_error_message,85);
3723     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
3724     RETURN 1;
3725 END Get_Hire_Date;
3726 -- =============================================================================
3727 -- Get_Term_Reason
3728 -- =============================================================================
3729 FUNCTION Get_Term_Reason
3730           (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
3731           ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
3732           ,p_effective_date     IN  DATE
3733           ,p_error_message      OUT NOCOPY VARCHAR2
3734           ,p_data_element_value OUT NOCOPY VARCHAR2
3735           ) RETURN NUMBER IS
3736 
3737 --
3738 -- Cursor to get the termination reason
3739 --
3740  CURSOR c_get_end_reason_new IS
3741  SELECT SUBSTR(DECODE(NVL(leaving_reason,'OVE'),'D','OVL'
3742                      ,NVL(leaving_reason,'OVE')),1,3)
3743    FROM per_periods_of_service pps,
3744         per_all_assignments_f asg
3745   WHERE asg.period_of_service_id = pps.period_of_service_id
3746     AND assignment_id = p_assignment_id
3747     AND p_effective_date BETWEEN effective_start_date AND
3748                                  effective_end_date ;
3749 
3750   l_proc_name      VARCHAR2(150) := g_proc_name ||'Get_Term_Reason';
3751   l_reason         VARCHAR2(3);
3752 
3753 BEGIN
3754 
3755    hr_utility.set_location('Entering:   '||l_proc_name, 5);
3756 
3757    --
3758    -- 5869420
3759    --
3760    OPEN c_get_end_reason_new;
3761    FETCH c_get_end_reason_new INTO l_reason;
3762    IF c_get_end_reason_new%FOUND THEN
3763        CLOSE c_get_end_reason_new;
3764    ELSE
3765        --
3766        -- Termination reason not found. Send OVE (Other Reasons)
3767        --
3768        l_reason := 'OVE';
3769        CLOSE c_get_end_reason_new;
3770    END IF;
3771 
3772    --
3773    -- Ensure that the length of termination reason is 3
3774    --
3775    l_reason := RPAD(l_reason,3,' ');
3776 
3777    --
3778    -- Only the following reasons are allowed in the report
3779    -- VWO = Voluntary resignation
3780    -- GO  = Forced resignation
3781    -- OVL = Deceased
3782    -- OP  = Start of pension
3783    -- OBU = Transitional pension
3784    -- OBV = Unpaid leave
3785    -- WAO = Disability
3786    -- OVP = Transition employee
3787    -- OVE = Other reasons
3788    --
3789    IF l_reason NOT IN('VWO','GO ','OVL','OP ','OBU','OBV','WAO','OVP','OVE') THEN
3790       l_reason := 'OVE';
3791    END IF;
3792 
3793    p_data_element_value := l_reason;
3794 
3795    hr_utility.set_location('....Termination reason is : '||l_reason,32);
3796    hr_utility.set_location('Leaving:   '||l_proc_name, 45);
3797 
3798    RETURN 0;
3799 
3800 EXCEPTION
3801    WHEN OTHERS THEN
3802     p_error_message :='SQL-ERRM :'||SQLERRM;
3803     hr_utility.set_location('..'||p_error_message,85);
3804     hr_utility.set_location('Leaving: '||l_proc_name, 90);
3805     RETURN -1;
3806 END Get_Term_Reason;
3807 
3808 
3809 -- ===============================================================================
3810 -- ~ Function to get the Reason of participation stored in PGGM General Info Element as I/P val
3811 -- ===============================================================================
3812 Function Get_Reason_Of_PTP
3813                  ( p_assignment_id       IN Number
3814                    ,p_business_group_id  IN Number
3815                    ,p_date_earned        IN DATE
3816                    ,p_error_message      OUT NOCOPY VARCHAR2
3817                    ,p_data_element_value OUT NOCOPY VARCHAR2
3818                  )
3819 Return Number IS
3820 
3821 CURSOR csr_get_reason_of_ptp(c_asg_id IN Number,c_date_earned IN DATE)  IS
3822 SELECT peev.screen_entry_value
3823 FROM
3824 pay_element_types_f pet,
3825 pay_input_values_f piv,
3826 pay_element_entries_f pee,
3827 pay_element_entry_values_f peev
3828 WHERE
3829   pet.element_name = 'PGGM Pensions General Information'
3830   and piv.name ='Reason Of Participation'
3831   and piv.element_type_id=pet.element_type_id
3832   and pee.element_type_id=pet.element_type_id
3833   and pee.assignment_id =c_asg_id
3834   and (c_date_earned between pee.effective_start_date
3835        and pee.effective_end_date)
3836   and peev.element_entry_id=pee.element_entry_id
3837   and peev.input_value_id=piv.input_value_id
3838   and (c_date_earned between peev.effective_start_date
3839        and peev.effective_end_date );
3840 
3841 CURSOR csr_get_primary_asg (c_assgt_id NUMBER, c_date DATE) IS
3842 SELECT pri.assignment_id
3843 FROM per_all_assignments_f sec,
3844 per_all_assignments_f pri
3845 WHERE sec.assignment_id = c_assgt_id
3846 AND sec.person_id = pri.person_id
3847 AND pri.primary_flag = 'Y'
3848 AND c_date BETWEEN pri.effective_start_date AND pri.effective_end_date
3849 AND c_date BETWEEN sec.effective_start_date AND sec.effective_end_date;
3850 --
3851 l_primary_flag VARCHAR2(2);
3852 l_pri_assignment_id NUMBER;
3853 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Reason_Of_PTP';
3854 l_ret_val     Number:=-1;
3855 l_reason_of_ptp varchar2(40):='';
3856 BEGIN
3857 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3858 
3859 OPEN csr_get_reason_of_ptp(p_assignment_id,p_date_earned);
3860 FETCH csr_get_reason_of_ptp INTO l_reason_of_ptp;
3861 IF csr_get_reason_of_ptp%FOUND THEN
3862      p_data_element_value:=l_reason_of_ptp;
3863      l_ret_val := 0;
3864  END If;
3865 CLOSE csr_get_reason_of_ptp;
3866 
3867 --If PTP Reason is not entered for this assignment, and if this is a
3868 --secondary assignment, get the value from the primary assignment.
3869 IF l_reason_of_ptp = '' OR l_reason_of_ptp IS NULL THEN
3870    OPEN csr_chk_primary_asg (p_assignment_id, p_date_earned);
3871    FETCH csr_chk_primary_asg INTO l_primary_flag;
3872    IF csr_chk_primary_asg%NOTFOUND THEN
3873         OPEN csr_get_primary_asg (p_assignment_id, p_date_earned);
3874         FETCH csr_get_primary_asg INTO l_pri_assignment_id;
3875         CLOSE csr_get_primary_asg;
3876         OPEN csr_get_reason_of_ptp(l_pri_assignment_id,p_date_earned);
3877         FETCH csr_get_reason_of_ptp INTO l_reason_of_ptp;
3878              p_data_element_value:=l_reason_of_ptp;
3879              l_ret_val := 0;
3880         CLOSE csr_get_reason_of_ptp;
3881    END IF;
3882    CLOSE csr_chk_primary_asg;
3883 END IF;
3884 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
3885 RETURN l_ret_val;
3886 EXCEPTION
3887    WHEN OTHERS THEN
3888       p_error_message :='SQL-ERRM :'||SQLERRM;
3889       Hr_Utility.set_location('..'||p_error_message,30);
3890       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3891       RETURN l_ret_val;
3892 END Get_Reason_Of_PTP;
3893 -- ===============================================================================
3894 -- ~ Function to get the part time percent as of hire date
3895 -- ===============================================================================
3896 Function Get_Hire_Date_PTP
3897                  ( p_assignment_id       IN Number
3898                    ,p_business_group_id  IN Number
3899                    ,p_effective_date     IN DATE
3900                    ,p_error_message      OUT NOCOPY VARCHAR2
3901                    ,p_data_element_value OUT NOCOPY VARCHAR2
3902                  )
3903 Return Number IS
3904 --Pick PTP from element entry level
3905 CURSOR csr_get_overide_ptp_val(c_asg_id IN Number,c_date_earned IN DATE)  IS
3906 SELECT peev.screen_entry_value
3907 FROM
3908 pay_element_types_f pet,
3909 pay_input_values_f piv,
3910 pay_element_entries_f pee,
3911 pay_element_entry_values_f peev
3912 WHERE
3913   pet.element_name = 'PGGM Pensions Part Time Percentage'
3914   and piv.name ='Part Time Percentage'
3915   and piv.element_type_id=pet.element_type_id
3916   and pee.element_type_id=pet.element_type_id
3917   and pee.assignment_id =c_asg_id
3918   and (c_date_earned between pee.effective_start_date
3919        and pee.effective_end_date)
3920   and peev.element_entry_id=pee.element_entry_id
3921   and peev.input_value_id=piv.input_value_id
3922   and (c_date_earned between peev.effective_start_date
3923        and peev.effective_end_date )
3924    and peev.screen_entry_value is not null;
3925 
3926 --Pick ptp value from Std conditions at asg level
3927 CURSOR csr_get_ptp_asg_level(c_assignment_id NUMBER,c_effective_date IN DATE) IS
3928 SELECT fnd_number.canonical_to_number(NVL(target.SEGMENT29,'0')) pt_perc
3929  FROM  per_assignments_f asg
3930       ,hr_soft_coding_keyflex target
3931 WHERE  asg.assignment_id = c_assignment_id
3932   AND  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
3933   AND  c_effective_date between asg.effective_start_date
3934   AND  asg.effective_end_date
3935   AND  target.enabled_flag = 'Y';
3936 
3937 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Hire_Date_PTP';
3938 l_ret_val     Number:=-1;
3939 l_hire_date   varchar2(10):='';
3940 l_ptp         NUMBER;
3941 BEGIN
3942 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
3943 
3944 --Fetch the hire date for this assignment
3945 l_ret_val:= Get_Hire_Date(p_assignment_id
3946               ,p_business_group_id
3947               ,p_effective_date
3948               ,p_error_message
3949              ,l_hire_date
3950               );
3951 
3952 --Check whether ptp has been overriden at assignment level
3953 OPEN csr_get_overide_ptp_val(p_assignment_id,to_date(l_hire_date,'YYYYMMDD'));
3954 FETCH csr_get_overide_ptp_val INTO l_ptp;
3955 IF csr_get_overide_ptp_val%FOUND THEN
3956   p_data_element_value:=l_ptp;
3957 ELSE
3958  --IF not overriden then take the asg value (STD conditions)
3959   OPEN csr_get_ptp_asg_level(p_assignment_id,to_date(l_hire_date,'YYYYMMDD'));
3960   FETCH csr_get_ptp_asg_level INTO l_ptp;
3961   p_data_element_value:=l_ptp;
3962   CLOSE csr_get_ptp_asg_level;
3963 END IF;
3964 CLOSE csr_get_overide_ptp_val;
3965 
3966 p_data_element_value := lpad(fnd_number.number_to_canonical(ceil(l_ptp)),3,'0')||'000';
3967 
3968 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
3969 RETURN l_ret_val;
3970 EXCEPTION
3971    WHEN OTHERS THEN
3972       p_error_message :='SQL-ERRM :'||SQLERRM;
3973       Hr_Utility.set_location('..'||p_error_message,30);
3974       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
3975       RETURN l_ret_val;
3976 END Get_Hire_Date_PTP;
3977 -- ===============================================================================
3978 -- ~ Function to get the incidental worker code as of hire date
3979 -- ===============================================================================
3980 Function Get_Hire_Date_IWC
3981                  ( p_assignment_id        IN Number
3982                    ,p_business_group_id   IN Number
3983                    ,p_effective_date      IN DATE
3984                    ,p_error_message       OUT NOCOPY VARCHAR2
3985                    ,p_data_element_value  OUT NOCOPY VARCHAR2
3986                  )
3987 Return Number IS
3988 
3989 CURSOR csr_get_incidental_wkr_code(c_asg_id Number ,c_date_earned Date) IS
3990 SELECT Decode(scl.SEGMENT1,'Y','0','1')
3991   FROM per_all_assignments_f asg
3992       ,hr_soft_coding_keyflex scl
3993 WHERE asg.assignment_id = c_asg_id
3994   AND c_date_earned BETWEEN asg.effective_start_date
3995   AND asg.effective_end_date
3996   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
3997 
3998 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Hire_Date_IWC';
3999 l_ret_val     Number:=-1;
4000 l_hire_date   varchar2(10):='';
4001 l_iwc         varchar2(1);
4002 BEGIN
4003 Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
4004 
4005 --Fetch the hire date for this assignment
4006 l_ret_val:= Get_Hire_Date(p_assignment_id
4007               ,p_business_group_id
4008               ,p_effective_date
4009               ,p_error_message
4010              ,l_hire_date
4011               );
4012 
4013 --Get the iwc at asg level
4014 OPEN csr_get_incidental_wkr_code(p_assignment_id,to_date(l_hire_date,'YYYYMMDD'));
4015 FETCH csr_get_incidental_wkr_code INTO l_iwc;
4016 CLOSE csr_get_incidental_wkr_code;
4017 
4018 IF l_iwc IS NULL THEN
4019     l_iwc := '1';
4020 END IF;
4021 p_data_element_value:=l_iwc;
4022 
4023 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,20);
4024 RETURN l_ret_val;
4025 
4026 EXCEPTION
4027    WHEN OTHERS THEN
4028       p_error_message :='SQL-ERRM :'||SQLERRM;
4029       Hr_Utility.set_location('..'||p_error_message,30);
4030       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
4031       RETURN l_ret_val;
4032 END Get_Hire_Date_IWC;
4033 
4034 -- ===============================================================================
4035 -- ~ Get_End_Date_Of_Employment: Assignment End Date
4036 -- ===============================================================================
4037 Function Get_End_Date_Of_Employment
4038                  ( p_assignment_id        IN Number
4039                    ,p_business_group_id   IN Number
4040                    ,p_effective_date      IN DATE
4041                    ,p_error_message       OUT NOCOPY VARCHAR2
4042                    ,p_data_element_value  OUT NOCOPY VARCHAR2
4043                  )
4044 Return Number IS
4045 /*CURSOR csr_get_assgn_end_date(c_assignment_id NUMBER) IS
4046 SELECT max(actual_termination_date)
4047 FROM  per_all_assignments_f asg
4048       ,per_periods_of_service pps
4049 WHERE pps.person_id     = asg.person_id
4050    AND asg.assignment_id = c_assignment_id
4051    AND pps.business_group_id = p_business_group_id
4052    AND date_start <= p_effective_date;
4053 
4054 CURSOR csr_get_sec_assgn_end_date(c_assignment_id NUMBER,c_business_group_id NUMBER) IS
4055 SELECT paa.effective_start_date
4056   FROM per_all_assignments_f paa,
4057        per_assignment_status_types past
4058 WHERE  paa.assignment_id           = c_assignment_id
4059    AND paa.business_group_id       = c_business_group_id
4060    AND paa.assignment_status_type_id=past.assignment_status_type_id
4061    AND past.per_system_status ='TERM_ASSIGN'
4062    AND ( paa.effective_start_date
4063     BETWEEN  g_extract_params (c_business_group_id).extract_start_date +1
4064              AND g_extract_params (c_business_group_id).extract_end_date + 1 );*/
4065 
4066 --
4067 CURSOR csr_get_term_date IS
4068 SELECT MIN(effective_start_date)-1 term_date
4069  FROM per_all_assignments_f asg
4070 WHERE assignment_id = p_assignment_id
4071   AND assignment_status_type_id IN (SELECT assignment_status_type_id
4072                                       FROM per_assignment_status_types
4073                                      WHERE per_system_status = 'TERM_ASSIGN'
4074                                        AND active_flag = 'Y')
4075 UNION
4076 --
4077 -- Get the dates for any ended assignments. Note that this is for sec
4078 -- assignments only.
4079 --
4080 SELECT MAX(effective_end_date)
4081  FROM per_all_assignments_f asg
4082 WHERE assignment_id    = p_assignment_id
4083   AND asg.primary_flag = 'N'
4084   AND NOT EXISTS( SELECT 1
4085                     FROM per_all_assignments_f  asg1
4086                    WHERE asg1.assignment_id = p_assignment_id
4087                      AND asg1.effective_start_date = asg.effective_end_date + 1
4088                      AND asg.assignment_id = asg1.assignment_id )
4089   AND NOT EXISTS( SELECT 1
4090                     FROM per_all_assignments_f  asg1
4091                    WHERE asg1.assignment_id = p_assignment_id
4092                      AND asg1.effective_start_date < asg.effective_start_date
4093                      AND asg.assignment_id = asg1.assignment_id
4094                      AND asg1.assignment_status_type_id IN (SELECT assignment_status_type_id
4095                                                               FROM per_assignment_status_types
4096                                                              WHERE per_system_status = 'TERM_ASSIGN'
4097                                                                AND active_flag = 'Y'));
4098 --
4099 
4100 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_End_Date_Of_Employment';
4101 l_ret_val     Number:=0;
4102 l_end_date    DATE;
4103 l_check       varchar2(1);
4104 BEGIN
4105 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
4106 /*OPEN csr_chk_primary_asg(p_assignment_id, p_effective_date);
4107 FETCH csr_chk_primary_asg INTO l_check;
4108 IF csr_chk_primary_asg%FOUND THEN
4109   OPEN csr_get_assgn_end_date(p_assignment_id);
4110   FETCH csr_get_assgn_end_date INTO l_end_date;
4111   IF (csr_get_assgn_end_date%FOUND) THEN
4112     l_ret_val:=0;
4113     p_data_element_value:=to_char(l_end_date,'YYYYMMDD');
4114   END IF;
4115   CLOSE csr_get_assgn_end_date;
4116 ELSE
4117 
4118   OPEN csr_get_sec_assgn_end_date(p_assignment_id,p_business_group_id);
4119   FETCH csr_get_sec_assgn_end_date INTO l_end_date;
4120   IF (csr_get_sec_assgn_end_date%FOUND) THEN
4121     l_ret_val:=0;
4122     p_data_element_value:=to_char(l_end_date-1,'YYYYMMDD');
4123   END IF;
4124   CLOSE csr_get_sec_assgn_end_date;
4125 
4126 END IF;
4127 CLOSE csr_chk_primary_asg;*/
4128 
4129 OPEN csr_get_term_date;
4130 FETCH csr_get_term_date INTO l_end_date;
4131 IF csr_get_term_date%FOUND THEN
4132    l_ret_val:=0;
4133    p_data_element_value:=to_char(l_end_date,'YYYYMMDD');
4134 END IF;
4135 CLOSE csr_get_term_date;
4136 
4137 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
4138 RETURN l_ret_val;
4139 EXCEPTION
4140    WHEN OTHERS THEN
4141       p_error_message :='SQL-ERRM :'||SQLERRM;
4142       Hr_Utility.set_location('..'||p_error_message,30);
4143       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
4144       RETURN l_ret_val;
4145 END Get_End_Date_Of_Employment;
4146 -- ===============================================================================
4147 -- ~ Get_Pension_Salary
4148 -- ===============================================================================
4149 Function Get_Pension_Salary
4150                  ( p_assignment_id         IN Number
4151                    ,p_business_group_id    IN Number
4152                    ,p_date_earned          IN DATE
4153                    ,p_error_message        OUT NOCOPY VARCHAR2
4154                    ,p_data_element_value   OUT NOCOPY VARCHAR2
4155   )
4156 Return Number IS
4157 --Cursor to check for PGGM General Info Elements for the current period
4158 CURSOR csr_chk_curr_year_pen_sal_chg(c_asg_id Number,c_start_date DATE) IS
4159 Select 'x'
4160 from pay_element_entries_f  pee,
4161      pay_input_values_f    piv,
4162      pay_element_types_f   pet,
4163      pay_element_entry_values_f peev
4164 where
4165  pet.element_name ='Retro PGGM Pensions General Information'
4166  AND piv.name = 'Annual Pension Salary'
4167  AND piv.element_type_id=pet.element_type_id
4168  AND pee.assignment_id=c_asg_id
4169  AND pee.element_type_id =pet.element_type_id
4170  AND  (pee.effective_start_date  between c_start_date
4171                 and g_extract_params(p_business_group_id).extract_end_date )
4172  AND peev.element_entry_id=pee.element_entry_id
4173  AND peev.input_value_id=piv.input_value_id
4174  AND peev.screen_entry_value is not null
4175  ORDER by source_start_date desc;
4176 
4177   --Cursor to check for PGGM General Info Elements for the previous period
4178 CURSOR csr_chk_prev_year_pen_sal_chg(c_asg_id Number,c_start_date DATE) IS
4179 Select 'x'
4180 from pay_element_entries_f  pee,
4181      pay_input_values_f    piv,
4182      pay_element_types_f   pet,
4183      pay_element_entry_values_f peev
4184 where
4185  pet.element_name ='Retro PGGM Pensions General Information Previous Year'
4186  AND piv.name = 'Annual Pension Salary'
4187  AND piv.element_type_id=pet.element_type_id
4188  AND pee.assignment_id=c_asg_id
4189  AND pee.element_type_id =pet.element_type_id
4190  AND  (pee.effective_start_date  between c_start_date
4191                 and g_extract_params(p_business_group_id).extract_end_date )
4192  AND peev.element_entry_id=pee.element_entry_id
4193  AND peev.input_value_id=piv.input_value_id
4194  AND peev.screen_entry_value is not null
4195  ORDER by source_start_date desc;
4196 
4197  --get the  total value for Retro Previous year element
4198  Cursor csr_total_chg_val(c_asg_id NUMBER,c_start_date DATE,c_end_date DATE) IS
4199  Select count(to_number(peev.screen_entry_value))
4200  from pay_element_entries_f  pee,
4201      pay_input_values_f    piv,
4202      pay_element_types_f   pet,
4203      pay_element_entry_values_f peev
4204  where
4205   pet.element_name ='Retro PGGM Pensions General Information Previous Year'
4206  AND piv.name = 'Annual Pension Salary'
4207  AND piv.element_type_id=pet.element_type_id
4208  AND pee.assignment_id=c_asg_id
4209  AND pee.element_type_id =pet.element_type_id
4210  AND  (pee.effective_start_date  between c_start_date
4211                 and c_end_date )
4212  AND peev.element_entry_id=pee.element_entry_id
4213  AND peev.input_value_id=piv.input_value_id
4214  AND peev.screen_entry_value is not null;
4215 
4216 --
4217 -- Cursor to get the current year override for pension salary
4218 --
4219 CURSOR csr_curr_year_pen_sal_or(c_asg_id Number,c_start_date DATE) IS
4220 SELECT CEIL(fnd_number.canonical_to_number(peev.screen_entry_value))
4221   FROM pay_element_entries_f  pee,
4222        pay_input_values_f    piv,
4223        pay_element_types_f   pet,
4224        pay_element_entry_values_f peev
4225  WHERE pet.element_name ='PGGM Pensions General Information'
4226    AND piv.name = 'Annual Pension Salary'
4227    AND piv.element_type_id = pet.element_type_id
4228    AND pee.assignment_id = c_asg_id
4229    AND pee.element_type_id = pet.element_type_id
4230    AND pee.effective_start_date  BETWEEN c_start_date
4231                 AND g_extract_params(p_business_group_id).extract_end_date
4232    AND peev.effective_start_date  BETWEEN c_start_date
4233                 AND g_extract_params(p_business_group_id).extract_end_date
4234    AND peev.element_entry_id = pee.element_entry_id
4235    AND peev.input_value_id = piv.input_value_id
4236    AND peev.screen_entry_value IS NOT NULL
4237  ORDER by source_start_date desc;
4238 
4239 
4240 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Pension_Salary';
4241 l_ret_val              Number:=0;
4242 l_balance_amount       Number:=0;
4243 l_bal_total_amt        Number:=0;
4244 asgact_rec             csr_asg_act%ROWTYPE;
4245 l_curr_year            NUMBER;
4246 l_prev_year            NUMBER;
4247 l_mon                  Number;
4248 l_end_date             Number;
4249 l_error_message        VARCHAR2(150);
4250 l_pen_sal_date         DATE;
4251 l_start_date_PTP       varchar2(10);
4252 orig_pen_sal_amt       NUMBER;
4253 l_chg_amt              NUMBER:=0;
4254 l_retro_chg_amt        NUMBER:=0;
4255 l_retro_total_amt      NUMBER:=0;
4256 l_chg_date             DATE;
4257 l_data_element_value   DATE;
4258 l_chk_retro            VARCHAR2(1);
4259 l_period_start_date    DATE;
4260 
4261 
4262 Begin
4263   Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
4264 
4265   l_curr_year:=Get_year(p_assignment_id
4266                        ,g_extract_params(p_business_group_id).extract_start_date
4267 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
4268 
4269 
4270 
4271 IF ( g_extract_params(p_business_group_id).extract_type='Y' )  --Annual report
4272 
4273 THEN
4274 
4275 
4276    --Date Parameter will be 0ne less than the current year in annual report
4277    l_curr_year:=l_curr_year+1;
4278 
4279 
4280    --Get Participation start date
4281    l_ret_val:=Get_Start_Date_PTP(p_assignment_id
4282              ,p_business_group_id
4283              ,p_date_earned
4284              ,p_error_message
4285             ,l_start_date_PTP
4286           );
4287 
4288    --Get the period start date
4289     OPEN  c_get_period_start_date(l_curr_year
4290                                  ,p_assignment_id
4291 				 ,p_date_earned);
4292     FETCH c_get_period_start_date INTO l_period_start_date;
4293     CLOSE c_get_period_start_date;
4294 
4295 
4296    --Reporting Date is the latest date of hire date and 1st Jan of that year
4297    --Pension Salary is calculated in this period
4298    l_pen_sal_date:=l_period_start_date;
4299 
4300 
4301    IF l_pen_sal_date < to_date(l_start_date_PTP,'YYYYMMDD') THEN
4302      l_pen_sal_date:=to_date(l_start_date_PTP,'YYYYMMDD');
4303    END IF;
4304 
4305     Hr_Utility.set_location(' Pen Sal Date  '   ||l_pen_sal_date,30);
4306 
4307 
4308      --Check whether there is retro change in pension salary for current year or not
4309      OPEN csr_chk_curr_year_pen_sal_chg(p_assignment_id,l_pen_sal_date);
4310      FETCH csr_chk_curr_year_pen_sal_chg INTO l_chk_retro;
4311      IF csr_chk_curr_year_pen_sal_chg%FOUND THEN
4312 
4313      --Get the YTD value for Retro PGGM Pension Salary Current Year Element
4314      l_chg_amt:=Get_Balance_Value(p_assignment_id
4315                                  ,p_business_group_id
4316                                  ,'Retro PGGM Pension Salary Current Year'
4317                                  ,'Assignment Period To Date'
4318                                  ,g_extract_params(p_business_group_id).extract_start_date
4319                                  ,g_extract_params(p_business_group_id).extract_end_date -- last day of the period/year
4320                                   );
4321      ELSE
4322        l_chg_amt:=0;
4323      END IF;
4324      CLOSE csr_chk_curr_year_pen_sal_chg;
4325       Hr_Utility.set_location('l_chg_amt'   ||l_chg_amt,30);
4326     --Get the original pension salary
4327     l_balance_amount:= Get_Balance_Value(p_assignment_id
4328                                      ,p_business_group_id
4329                                      ,'PGGM Pension Salary'
4330                                      ,'Assignment Year To Date'
4331                                      ,l_pen_sal_date
4332                                      ,last_day(l_pen_sal_date)  -- last day of the month
4333                                      );
4334 
4335      Hr_Utility.set_location('l_balance_amount'   ||l_balance_amount,30);
4336     --Actual Amount is summation of Retro amount and original pension salary
4337     p_data_element_value := CEIL(l_balance_amount+l_chg_amt);
4338     p_data_element_value:=lpad(p_data_element_value,6,'0');
4339     l_ret_val:=0;
4340 
4341    ELSE  ---Monthly Report
4342 
4343    --------------------called from 060 record ---------------------------
4344    IF g_rec060_mult_flag='Y' THEN --if  Record 060 value then calculate it from global table for 060
4345 
4346     IF g_rcd_060(g_060_index).element_type = 'C' Then
4347 
4348       --g_060_index is set at Mult Rec 060 Processing
4349       --l_chg_amt:=g_rcd_060(g_060_index).pension_sal_amount; --  This contains the diffrence in Pensoin Salary
4350       l_pen_sal_date:=g_rcd_060(g_060_index).pension_sal_dt_change;
4351       --Check whether there is retro change in pension salary for current year or not
4352       OPEN csr_chk_curr_year_pen_sal_chg(p_assignment_id,l_pen_sal_date);
4353       FETCH csr_chk_curr_year_pen_sal_chg INTO l_chk_retro;
4354       IF csr_chk_curr_year_pen_sal_chg%FOUND THEN
4355 
4356 
4357          --Get the YTD value for Retro PGGM Pension Salary Current Year Element
4358          l_retro_chg_amt:=Get_Balance_Value(p_assignment_id
4359                                      ,p_business_group_id
4360                                     ,'Retro PGGM Pension Salary Current Year'
4361                                     ,'Assignment Year To Date'
4362                                     ,g_extract_params(p_business_group_id).extract_start_date
4363                                     ,g_extract_params(p_business_group_id).extract_end_date -- last day of the period/year
4364                                     );
4365          ELSE
4366              l_retro_chg_amt:=0;
4367          END IF;
4368      ELSE ---------For Retro PGGM Gen Information previous Year
4369 
4370         l_pen_sal_date:=g_rcd_060(g_060_index).pension_sal_dt_change;
4371         --Check whether there is retro change in pension salary for current year or not
4372         OPEN csr_chk_prev_year_pen_sal_chg(p_assignment_id,l_pen_sal_date);
4373         FETCH csr_chk_prev_year_pen_sal_chg INTO l_chk_retro;
4374         IF csr_chk_prev_year_pen_sal_chg%FOUND THEN
4375 
4376 
4377         --Get the YTD value for Retro PGGM Pension Salary Previous Year Element
4378         l_retro_chg_amt:=Get_Balance_Value(p_assignment_id
4379                                       ,p_business_group_id
4380                                       ,'Retro PGGM Pension Salary Previous Year'
4381                                       ,'Assignment Year To Date'
4382                                       ,l_pen_sal_date
4383                                       ,Last_day(l_pen_sal_date) -- last day of the period/year
4384                                      );
4385         OPEN csr_total_chg_val(p_assignment_id,l_pen_sal_date,g_extract_params(p_business_group_id).extract_end_date);
4386         FETCH csr_total_chg_val INTO l_retro_total_amt;
4387         CLOSE csr_total_chg_val;
4388         l_retro_chg_amt:=l_retro_chg_amt+NVL(l_retro_total_amt,0);
4389 
4390         ELSE
4391           l_retro_chg_amt:=0;
4392         END IF;
4393 
4394 
4395      END IF;--End of element type check
4396 
4397       orig_pen_sal_amt:= Get_Balance_Value(p_assignment_id
4398                                      ,p_business_group_id
4399                                      ,'PGGM Pension Salary'
4400                                      ,'Assignment Year To Date'
4401                                      ,l_pen_sal_date
4402                                      ,last_day(l_pen_sal_date)  -- last day of the month
4403                                      );
4404 
4405        p_data_element_value:=CEIL(l_retro_chg_amt + orig_pen_sal_amt);
4406       l_ret_val:=0;
4407       ------------called from record other than 060 monthly report------------------
4408       ELSE
4409 
4410          --Get Participation start date
4411          l_ret_val:=Get_Start_Date_PTP(
4412                      p_assignment_id
4413                     ,p_business_group_id
4414                     ,p_date_earned
4415                     ,p_error_message
4416                    ,l_start_date_PTP
4417                    );
4418           --Get the period start date
4419          OPEN  c_get_period_start_date(l_curr_year
4420 	                              ,p_assignment_id
4421 				      ,p_date_earned);
4422          FETCH c_get_period_start_date INTO l_period_start_date;
4423          CLOSE c_get_period_start_date;
4424 
4425          --Reporting Date is the latest date of hire date and 1st Jan of that year
4426          --Pension Salary is calculated in this period
4427          l_pen_sal_date:=l_period_start_date;
4428 
4429 
4430          IF l_pen_sal_date < to_date(l_start_date_PTP,'YYYYMMDD') THEN
4431             l_pen_sal_date:=to_date(l_start_date_PTP,'YYYYMMDD');
4432          END IF;
4433 
4434           Hr_Utility.set_location(' Pen Sal Date  '   ||l_pen_sal_date,30);
4435 
4436 
4437           --Check whether there is retro change in pension salary for current year or not
4438           OPEN csr_chk_curr_year_pen_sal_chg(p_assignment_id,l_pen_sal_date);
4439           FETCH csr_chk_curr_year_pen_sal_chg INTO l_chk_retro;
4440           IF csr_chk_curr_year_pen_sal_chg%FOUND THEN
4441 
4442            --Get the YTD value for Retro PGGM Pension Salary Current Year Element
4443           l_chg_amt:=Get_Balance_Value(p_assignment_id
4444                                       ,p_business_group_id
4445                                       ,'Retro PGGM Pension Salary Current Year'
4446                                       ,'Assignment Year To Date'
4447                                       ,g_extract_params(p_business_group_id).extract_start_date
4448                                       ,g_extract_params(p_business_group_id).extract_end_date -- last day of the period/year
4449                                   );
4450           ELSE
4451             l_chg_amt:=0;
4452           END IF;
4453           CLOSE csr_chk_curr_year_pen_sal_chg;
4454           Hr_Utility.set_location('l_chg_amt'   ||l_chg_amt,30);
4455           --Get the original pension salary
4456           l_balance_amount:= Get_Balance_Value(p_assignment_id
4457                                               ,p_business_group_id
4458                                               ,'PGGM Pension Salary'
4459                                               ,'Assignment Year To Date'
4460                                               ,l_pen_sal_date
4461                                               ,g_extract_params(p_business_group_id).extract_end_date
4462 					      -- last day of the month
4463                                              );
4464 
4465          Hr_Utility.set_location('l_balance_amount'   ||l_balance_amount,30);
4466          --Actual Amount is summation of Retro amount and original pension salary
4467          p_data_element_value:=CEIL(l_balance_amount+l_chg_amt);
4468          --p_data_element_value:=lpad(p_data_element_value,6,'0');
4469 
4470          -- Override pension salary
4471          OPEN csr_curr_year_pen_sal_or(p_assignment_id,l_pen_sal_date);
4472          FETCH csr_curr_year_pen_sal_or INTO l_balance_amount;
4473          IF csr_curr_year_pen_sal_or%FOUND THEN
4474             p_data_element_value:=CEIL(l_balance_amount);
4475             --p_data_element_value:=lpad(p_data_element_value,6,'0');
4476          END IF;
4477          CLOSE csr_curr_year_pen_sal_or;
4478 
4479          l_ret_val:=0;
4480 
4481    END IF;--Record 060 check
4482     p_data_element_value:=lpad(p_data_element_value,6,'0');
4483 END IF;---End of Type of report check
4484 
4485   Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,40);
4486 RETURN l_ret_val;
4487 EXCEPTION
4488    WHEN OTHERS THEN
4489       p_error_message :='SQL-ERRM :'||SQLERRM;
4490       Hr_Utility.set_location('..'||p_error_message,50);
4491       Hr_Utility.set_location('Leaving: '||l_proc_name,60);
4492       l_ret_val:=1;
4493       RETURN l_ret_val;
4494 END Get_Pension_Salary;
4495 -- ===============================================================================
4496 -- ~ Get_Final_Part_Time_Val
4497 -- ===============================================================================
4498 Function Get_Final_Part_Time_Val
4499                  ( p_assignment_id        IN Number
4500                    ,p_business_group_id   IN Number
4501                    ,p_date_earned         IN DATE
4502                    ,p_error_message       OUT NOCOPY VARCHAR2
4503                    ,p_data_element_value  OUT NOCOPY VARCHAR2
4504   )
4505 Return Number IS
4506 
4507 CURSOR csr_retro_hours_worked(c_assignment_id NUMBER
4508                               ,c_start_date DATE
4509                               ,c_end_date   DATE
4510 ) IS
4511 Select sum(to_number(NVL(peev.screen_entry_value,0)))
4512 from pay_element_entries_f pee,
4513      pay_input_values_f    piv,
4514      pay_element_types_f   pet,
4515      pay_element_entry_values_f   peev
4516      where
4517      pet.element_name='Retro PGGM Pensions Part Time Percentage'
4518      and piv.name='Hours Worked'
4519      and pee.assignment_id=c_assignment_id
4520      and pet.element_type_id =pee.element_type_id
4521      and ( pee.effective_start_date between c_start_date
4522           and  c_end_date )
4523      and peev.element_entry_id = pee.element_entry_id
4524      and peev.input_value_id = piv.input_value_id
4525      and to_char(pee.source_start_date,'YYYY')=to_char(c_start_date,'YYYY')
4526      and peev.screen_entry_value is not null;
4527 
4528 CURSOR csr_retro_total_hours(c_assignment_id NUMBER
4529                              ,c_start_date DATE
4530                            ,c_end_date   DATE
4531  ) IS
4532 Select sum(to_number(NVL(peev.screen_entry_value,0)))
4533 from pay_element_entries_f pee,
4534      pay_input_values_f    piv,
4535      pay_element_types_f   pet,
4536      pay_element_entry_values_f   peev
4537      where
4538      pet.element_name='Retro PGGM Pensions Part Time Percentage'
4539      and piv.name='Total Hours'
4540      and pee.assignment_id=c_assignment_id
4541      and pet.element_type_id =pee.element_type_id
4542      and ( pee.effective_start_date between c_start_date
4543           and  c_end_date )
4544      and peev.element_entry_id = pee.element_entry_id
4545      and peev.input_value_id = piv.input_value_id
4546      and to_char(pee.source_start_date,'YYYY')=to_char(c_start_date,'YYYY')
4547      and peev.screen_entry_value is not null;
4548 
4549 CURSOR csr_retro_extra_hours(c_assignment_id NUMBER
4550                             ,c_start_date DATE
4551                           ,c_end_date   DATE
4552 ) IS
4553 Select sum(to_number(NVL(peev.screen_entry_value,0)))
4554 from pay_element_entries_f pee,
4555      pay_input_values_f    piv,
4556      pay_element_types_f   pet,
4557      pay_element_entry_values_f   peev
4558      where
4559      pet.element_name='Retro PGGM Pensions Part Time Percentage'
4560      and piv.name='Extra Hours'
4561      and pee.assignment_id=c_assignment_id
4562      and pet.element_type_id =pee.element_type_id
4563      and ( pee.effective_start_date between c_start_date
4564           and  c_end_date )
4565      and peev.element_entry_id = pee.element_entry_id
4566      and peev.input_value_id = piv.input_value_id
4567      and to_char(pee.source_start_date,'YYYY')=to_char(c_start_date,'YYYY')
4568      and peev.screen_entry_value is not null;
4569 
4570 CURSOR csr_get_asg_action_ids (  c_assignment_id NUMBER
4571                               , c_start_date DATE
4572                               , c_end_date  DATE
4573                               )
4574 IS
4575 SELECT paa.assignment_action_id
4576        ,ppa.date_earned
4577 FROM  pay_assignment_actions paa
4578       ,pay_payroll_actions    ppa
4579 WHERE  paa.assignment_id          = c_assignment_id
4580      AND paa.payroll_action_id    = ppa.payroll_action_id
4581      AND paa.source_action_id     IS NOT NULL
4582      AND ppa.action_status        = 'C'
4583      AND paa.action_status        = 'C'
4584      AND ppa.action_type IN ('B','L','O','Q','R')
4585      AND ppa.effective_date BETWEEN c_start_date
4586                                 AND c_end_date
4587      ORDER BY ppa.effective_date;
4588 
4589 CURSOR csr_get_run_result_value
4590        (  p_element_entry_id NUMBER
4591          ,p_input_value_id   NUMBER
4592          ,p_asg_act_id       NUMBER
4593        )
4594   IS
4595   SELECT to_number(prrv.result_value) result
4596     FROM pay_run_result_values prrv
4597         ,pay_run_results       prr
4598     WHERE prrv.run_result_id       = prr.run_result_id
4599       AND prr.assignment_action_id = p_asg_act_id
4600       AND prr.source_id            = p_element_entry_id
4601       AND prrv.input_value_id      = p_input_value_id ;
4602 
4603 CURSOR csr_get_ele_entry_id (c_assignment_id NUMBER
4604                              ,c_date_earned DATE
4605 			     )
4606 IS
4607 SELECT pee.element_entry_id
4608 FROM pay_element_entries_f pee,
4609      pay_element_types_f   pet
4610      WHERE
4611      pet.element_name='PGGM Pensions Part Time Percentage'
4612      AND pee.assignment_id=c_assignment_id
4613      AND pet.element_type_id =pee.element_type_id
4614      AND ( c_date_earned BETWEEN pee.effective_start_date
4615                              AND pee.effective_end_date);
4616 
4617 CURSOR csr_get_input_val_id
4618 IS
4619 SELECT piv.input_value_id  FROM
4620   pay_input_values_f piv,
4621   pay_element_types_f pet
4622 WHERE
4623     pet.element_name = 'PGGM Pensions Part Time Percentage'
4624 AND piv.name ='Extra Hours'
4625 AND piv.element_type_id =pet.element_type_id;
4626 
4627 
4628 l_proc_name             Varchar2(150) :=g_proc_name || 'Get_Final_Part_Time_Val';
4629 l_ret_val                Number:=0;
4630 l_balance_amount_h       Number :=0;
4631 l_balance_amount_t       Number :=0;
4632 l_sum_hours_worked       Number :=0;
4633 l_sum_total_hours        Number :=0;
4634 l_sum_extra_hours        Number :=0;
4635 l_extra_hours            NUMBER :=0;
4636 l_total_extra_hours      NUMBER :=0;
4637 l_chg_year               VARCHAR2(10);
4638 l_input_value_id         NUMBER :=-1;
4639 l_element_entry_id       NUMBER :=-1;
4640 asgact_rec               csr_asg_act%ROWTYPE;
4641 asg_ids_rec              csr_get_asg_action_ids%ROWTYPE;
4642 l_period_start_date      DATE;
4643 l_period_end_date        DATE;
4644 Begin
4645 --hr_utility.trace_on(null,'SS');
4646 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
4647 
4648 IF g_rec_081_type='C' THEN -- Current Year
4649   --Get Hours Worked from Balance
4650      l_balance_amount_h:=Get_Balance_Value(p_assignment_id
4651                                      ,p_business_group_id
4652                                      ,'PGGM Hours Worked'
4653                                      ,'Assignment Period To Date'
4654                                      ,g_extract_params(p_business_group_id).extract_start_date
4655                                      ,g_extract_params(p_business_group_id).extract_end_date
4656                                     );
4657 
4658   --Get Total Hours from Balance
4659      l_balance_amount_t:=Get_Balance_Value(p_assignment_id
4660                                        ,p_business_group_id
4661                                        ,'PGGM Total Hours'
4662                                        ,'Assignment Period To Date'
4663                                        ,g_extract_params(p_business_group_id).extract_start_date
4664                                        ,g_extract_params(p_business_group_id).extract_end_date
4665                                       );
4666  --Get Extra hours
4667  --Get input value id of extra hours
4668    OPEN csr_get_input_val_id;
4669    FETCH csr_get_input_val_id INTO l_input_value_id;
4670    CLOSE csr_get_input_val_id;
4671    Hr_Utility.set_location('l_input_value_id for extra hours'||l_input_value_id,20);
4672  --Get total extra hours from run results of whole year (current)
4673    OPEN csr_get_asg_action_ids( p_assignment_id
4674                                ,g_extract_params(p_business_group_id).extract_start_date
4675                                ,g_extract_params(p_business_group_id).extract_end_date
4676 			       );
4677    LOOP
4678     FETCH csr_get_asg_action_ids INTO asg_ids_rec;
4679     EXIT WHEN  csr_get_asg_action_ids%NOTFOUND;
4680     Hr_Utility.set_location('asg action ids found'||asg_ids_rec.assignment_action_id,20);
4681     OPEN csr_get_ele_entry_id(  p_assignment_id
4682                                ,asg_ids_rec.date_earned
4683                             );
4684     FETCH csr_get_ele_entry_id INTO l_element_entry_id;
4685 
4686     IF csr_get_ele_entry_id%FOUND THEN
4687     Hr_Utility.set_location('l_element_entry_id found '||l_element_entry_id,21);
4688        OPEN csr_get_run_result_value
4689             (  p_element_entry_id => l_element_entry_id
4690               ,p_input_value_id   => l_input_value_id
4691               ,p_asg_act_id       => asg_ids_rec.assignment_action_id
4692             );
4693        FETCH csr_get_run_result_value INTO l_extra_hours;
4694        IF csr_get_run_result_value%FOUND THEN
4695 
4696          Hr_Utility.set_location('run result for extra hours found '||l_extra_hours,23);
4697        ELSE
4698          Hr_Utility.set_location('run result for extra hours not found ',24);
4699        END IF;
4700        CLOSE csr_get_run_result_value;
4701        l_total_extra_hours := l_total_extra_hours + NVL(l_extra_hours,0);
4702        l_extra_hours :=0;
4703     END IF;
4704     CLOSE csr_get_ele_entry_id;
4705 
4706    END LOOP;
4707    CLOSE csr_get_asg_action_ids;
4708 
4709     -- Get sum of retro extra hours
4710     OPEN csr_retro_extra_hours(p_assignment_id
4711                                 ,g_extract_params(p_business_group_id).extract_start_date
4712                                 ,g_extract_params(p_business_group_id).extract_end_date
4713                                 );
4714     FETCH csr_retro_extra_hours INTO l_sum_extra_hours;
4715     CLOSE csr_retro_extra_hours;
4716 
4717      l_total_extra_hours := l_total_extra_hours + NVL(l_sum_extra_hours,0);
4718      Hr_Utility.set_location('l_total_extra_hours'||l_total_extra_hours,20);
4719   --End Extra Hours
4720   OPEN csr_retro_hours_worked(p_assignment_id
4721                                 ,g_extract_params(p_business_group_id).extract_start_date
4722                                 ,g_extract_params(p_business_group_id).extract_end_date
4723                                  );
4724      FETCH csr_retro_hours_worked INTO l_sum_hours_worked;
4725      CLOSE csr_retro_hours_worked;
4726 
4727      Hr_Utility.set_location('l_sum_hours_worked'||l_sum_hours_worked,20);
4728 
4729      OPEN csr_retro_total_hours(p_assignment_id
4730                                 ,g_extract_params(p_business_group_id).extract_start_date
4731                                  ,g_extract_params(p_business_group_id).extract_end_date
4732                                 );
4733      FETCH csr_retro_total_hours INTO l_sum_total_hours;
4734      CLOSE csr_retro_total_hours;
4735      Hr_Utility.set_location('l_sum_total_hours'||l_sum_total_hours,30);
4736      --
4737 
4738      l_sum_hours_worked:=NVL(l_sum_hours_worked,0) + NVL(l_total_extra_hours,0) + l_balance_amount_h;
4739      l_sum_total_hours :=NVL(l_sum_total_hours,0)  +  l_balance_amount_t;
4740 
4741    --Divide hours worked to total hours to get final part time value
4742      IF l_balance_amount_t <> 0 THEN
4743        p_data_element_value:=trim(to_char(((l_sum_hours_worked/l_sum_total_hours)*100),'099'));
4744      Else
4745        p_data_element_value:=0;
4746      END IF;
4747      --p_data_element_value:=lpad(p_data_element_value,6,'0');
4748  ELSE
4749      --g_rec_081_type='P' Previous Years
4750      --Get Hours Worked from Balance
4751      l_chg_year:=g_rcd_081(g_081_index).year_of_change;
4752 
4753      --Get the period start and end dates
4754 	OPEN  c_get_period_start_date(l_chg_year
4755 	                              ,p_assignment_id
4756 				      ,p_date_earned);
4757 	FETCH c_get_period_start_date INTO l_period_start_date;
4758 	CLOSE c_get_period_start_date;
4759 
4760 	OPEN  c_get_period_end_date(l_chg_year
4761 	                           ,p_assignment_id
4762 				   ,p_date_earned);
4763 	FETCH c_get_period_end_date INTO l_period_end_date;
4764 	CLOSE c_get_period_end_date;
4765 
4766      l_balance_amount_h:=Get_Balance_Value(p_assignment_id
4767                                           ,p_business_group_id
4768                                           ,'PGGM Hours Worked'
4769                                           ,'Assignment Period To Date'
4770                                           ,l_period_start_date
4771                                           ,l_period_end_date
4772                                          );
4773     --Get Total Hours from Balance
4774     l_balance_amount_t:=Get_Balance_Value(p_assignment_id
4775                                        ,p_business_group_id
4776                                        ,'PGGM Total Hours'
4777                                        ,'Assignment Period To Date'
4778                                        ,l_period_start_date
4779                                        ,l_period_end_date
4780                                       );
4781 
4782    ---------------Calculate Extra Hours-------------------------------------------
4783    --Get total extra hours from run results of whole year (current)
4784 
4785    --Get input value id of extra hours
4786    OPEN csr_get_input_val_id;
4787    FETCH csr_get_input_val_id INTO l_input_value_id;
4788    CLOSE csr_get_input_val_id;
4789 
4790    OPEN csr_get_asg_action_ids( p_assignment_id
4791                                ,l_period_start_date
4792                                ,l_period_end_date
4793 			       );
4794    LOOP
4795     FETCH csr_get_asg_action_ids INTO asg_ids_rec;
4796     EXIT WHEN  csr_get_asg_action_ids%NOTFOUND;
4797 
4798     OPEN csr_get_ele_entry_id(  p_assignment_id
4799                                ,asg_ids_rec.date_earned
4800                             );
4801     FETCH csr_get_ele_entry_id INTO l_element_entry_id;
4802 
4803     IF csr_get_ele_entry_id%FOUND THEN
4804        OPEN csr_get_run_result_value
4805             (  p_element_entry_id => l_element_entry_id
4806               ,p_input_value_id   => l_input_value_id
4807               ,p_asg_act_id       => asg_ids_rec.assignment_action_id
4808             );
4809        FETCH csr_get_run_result_value INTO l_extra_hours;
4810        CLOSE csr_get_run_result_value;
4811 
4812        l_total_extra_hours := l_total_extra_hours + NVL(l_extra_hours,0);
4813 
4814     END IF;
4815     CLOSE csr_get_ele_entry_id;
4816 
4817    END LOOP;
4818    CLOSE csr_get_asg_action_ids;
4819 
4820     -- Get sum of retro extra hours
4821     OPEN csr_retro_extra_hours(p_assignment_id
4822                                 ,l_period_start_date
4823                                 ,g_extract_params(p_business_group_id).extract_end_date
4824                                 );
4825     FETCH csr_retro_extra_hours INTO l_sum_extra_hours;
4826     CLOSE csr_retro_extra_hours;
4827 
4828      l_total_extra_hours := l_total_extra_hours + NVL(l_sum_extra_hours,0);
4829   ---------------------End Extra Hours ---------------------------------------
4830 
4831      Hr_Utility.set_location('l_total_extra_hours'||l_total_extra_hours,50);
4832 
4833      OPEN csr_retro_hours_worked(p_assignment_id
4834                                 ,l_period_start_date
4835                                 ,g_extract_params(p_business_group_id).extract_end_date
4836                                  );
4837      FETCH csr_retro_hours_worked INTO l_sum_hours_worked;
4838      CLOSE csr_retro_hours_worked;
4839 
4840      Hr_Utility.set_location('l_sum_hours_worked'||l_sum_hours_worked,20);
4841 
4842      OPEN csr_retro_total_hours(p_assignment_id
4843                                 ,l_period_start_date
4844                                  ,g_extract_params(p_business_group_id).extract_end_date
4845                                 );
4846      FETCH csr_retro_total_hours INTO l_sum_total_hours;
4847      CLOSE csr_retro_total_hours;
4848      Hr_Utility.set_location('l_sum_total_hours'||l_sum_total_hours,30);
4849 
4850 
4851 
4852        l_sum_hours_worked:=NVL(l_sum_hours_worked,0) + NVL(l_total_extra_hours,0) + l_balance_amount_h;
4853        l_sum_total_hours :=NVL(l_sum_total_hours,0)  +  l_balance_amount_t;
4854 
4855        --Divide hours worked to total hours to get final part time value
4856        IF l_sum_total_hours <> 0 THEN
4857          p_data_element_value:=trim(to_char( ((l_sum_hours_worked/l_sum_total_hours)*100),'099'));
4858        ELSE
4859          p_data_element_value:=0;
4860        END IF;
4861 
4862        --p_data_element_value:=lpad(p_data_element_value,6,'0');
4863        Hr_Utility.set_location('p_data_element_value'||p_data_element_value,50);
4864  END IF;
4865 --  hr_utility.trace_off;
4866      l_ret_val:=0;
4867 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
4868 RETURN l_ret_val;
4869 EXCEPTION
4870    WHEN OTHERS THEN
4871       p_error_message :='SQL-ERRM :'||SQLERRM;
4872       Hr_Utility.set_location('..'||p_error_message,30);
4873       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
4874       l_ret_val:=1;
4875       RETURN l_ret_val;
4876 END Get_Final_Part_Time_Val;
4877 -- ===============================================================================
4878 -- ~ Get_Part_Time_Percent
4879 -- ===============================================================================
4880 Function Get_Part_Time_Percent
4881                  ( p_assignment_id        IN Number
4882                    ,p_business_group_id   IN Number
4883                    ,p_date_earned         IN DATE
4884                    ,p_error_message       OUT NOCOPY VARCHAR2
4885                    ,p_data_element_value  OUT NOCOPY VARCHAR2
4886   )
4887 Return Number IS
4888 
4889 CURSOR csr_get_def_bal_type_id(c_balance_name VARCHAR2,c_dimension_name VARCHAR2)  IS
4890 SELECT defined_balance_id
4891 FROM  pay_defined_balances pdb,
4892       pay_balance_types pbt,
4893       pay_balance_dimensions pbd
4894 WHERE
4895       pbt.balance_name =c_balance_name
4896       and pbd.legislation_code='NL'
4897       and pbd.DIMENSION_NAME=c_dimension_name
4898       and pdb.balance_type_id = pbt.balance_type_id
4899       and pdb.balance_dimension_id = pbd.balance_dimension_id;
4900 
4901 --Pick PTP from element entry level
4902 CURSOR csr_get_ptp_val(c_asg_id IN Number,c_date_earned IN DATE)  IS
4903 SELECT peev.screen_entry_value
4904 FROM
4905 pay_element_types_f pet,
4906 pay_input_values_f piv,
4907 pay_element_entries_f pee,
4908 pay_element_entry_values_f peev
4909 WHERE
4910   pet.element_name = 'PGGM Pensions Part Time Percentage'
4911   and piv.name ='Part Time Percentage'
4912   and piv.element_type_id=pet.element_type_id
4913   and pee.element_type_id=pet.element_type_id
4914   and pee.assignment_id =c_asg_id
4915   and (c_date_earned between pee.effective_start_date
4916        and pee.effective_end_date)
4917   and peev.element_entry_id=pee.element_entry_id
4918   and peev.input_value_id=piv.input_value_id
4919   and (c_date_earned between peev.effective_start_date
4920        and peev.effective_end_date )
4921    and peev.screen_entry_value is not null;
4922 
4923 --Pick ptp value from Std conditions at asg level
4924 CURSOR c_get_ptp_std_asg(c_effective_date IN DATE) IS
4925 SELECT fnd_number.canonical_to_number(NVL(target.SEGMENT29,'0')) pt_perc
4926  FROM  per_assignments_f asg
4927       ,hr_soft_coding_keyflex target
4928 WHERE  asg.assignment_id = p_assignment_id
4929   AND  target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
4930   AND  c_effective_date between asg.effective_start_date
4931   AND  asg.effective_end_date
4932   AND  target.enabled_flag = 'Y';
4933 
4934 l_proc_name         Varchar2(150) :=g_proc_name || 'Get_Part_Time_Percent';
4935 l_ret_val           Number:=0;
4936 l_balance_amount    Number :=0;
4937 asgact_rec          csr_asg_act%ROWTYPE;
4938 l_pay_start_date    DATE;
4939 l_pay_end_date      DATE;
4940 l_pay_year          NUMBER;
4941 l_pay_mon           NUMBER;
4942 l_pay_day           NUMBER;
4943 l_irr_pay_amt       NUMBER:=0;
4944 l_def_bal_type_id   NUMBER;
4945 l_ptp_value         NUMBER:=0;
4946 l_ptp_diff          NUMBER:=0;
4947 l_count             NUMBER:=0;
4948 Begin
4949 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
4950 
4951 IF g_extract_params(p_business_group_id).extract_type='Y' THEN
4952 l_ret_val:=Get_Final_Part_Time_Val
4953                  (  p_assignment_id
4954                    ,p_business_group_id
4955                    ,p_date_earned
4956                    ,p_error_message
4957                    ,p_data_element_value
4958   );
4959 ELSE  --For Monthly Report
4960 Hr_Utility.set_location('g_ptp_index  '||g_ptp_index,30);
4961 --Depending upon type of change  in part time  percentage
4962 --or incidental worker code set the part time percentage value
4963 
4964 --080 appears due to current changes in Incidental worker code
4965   IF ( g_ptp_index=300 ) THEN
4966  --Fetch the ptp effective on changed date (new value)
4967     --Get the ptp over ridden value from element entry page
4968     OPEN csr_get_ptp_val(p_assignment_id,g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
4969    FETCH csr_get_ptp_val INTO l_ptp_value;
4970 
4971      --If not found then pick it from asg std condition
4972       IF csr_get_ptp_val%NOTFOUND THEN
4973       OPEN  c_get_ptp_std_asg(g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
4974       FETCH c_get_ptp_std_asg INTO l_ptp_value;
4975       CLOSE c_get_ptp_std_asg;
4976        END IF;
4977      CLOSE csr_get_ptp_val;
4978 
4979   ELSE
4980   --080 appears due to retro changes in Incidental worker code
4981       IF ( g_ptp_index=400 ) THEN
4982       l_ptp_value:=0;
4983       --Get the ptp over ridden value from element entry page
4984          OPEN csr_get_ptp_val(p_assignment_id,g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
4985          FETCH csr_get_ptp_val INTO l_ptp_value;
4986 
4987 
4988       --If not found then pick it from asg std condition
4989       IF csr_get_ptp_val%NOTFOUND THEN
4990       OPEN  c_get_ptp_std_asg(g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
4991       FETCH c_get_ptp_std_asg INTO l_ptp_value;
4992       CLOSE c_get_ptp_std_asg;
4993       END IF;
4994          CLOSE csr_get_ptp_val;
4995 
4996       ELSE
4997          --080 appears due to current changes in Part time percentage
4998           IF ( g_ptp_index=100 ) THEN
4999               Hr_Utility.set_location('g_ptp_index+g_080_index'   ||(g_ptp_index+g_080_index),35);
5000              l_ptp_value:=g_rcd_080(g_ptp_index+g_080_index).part_time_factor;
5001 
5002          ELSE
5003      IF(g_ptp_index=200) THEN
5004        --Fetch the ptp effective on changed date (new value)
5005         OPEN csr_get_ptp_val(p_assignment_id,g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
5006        FETCH csr_get_ptp_val INTO l_ptp_value;
5007        --If not found then pick it from asg std condition
5008         IF csr_get_ptp_val%NOTFOUND THEN
5009           OPEN  c_get_ptp_std_asg(g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change);
5010           FETCH c_get_ptp_std_asg INTO l_ptp_value;
5011           CLOSE c_get_ptp_std_asg;
5012         END IF;
5013         CLOSE csr_get_ptp_val;
5014 
5015     ELSE  --g_ptp_index=0
5016               l_ptp_value:=Get_Balance_Value
5017                         (  p_assignment_id
5018                             ,p_business_group_id
5019                             ,'PGGM Part Time Percentage'
5020                             ,'Assignment Period To Date'
5021                             ,g_extract_params(p_business_group_id).extract_start_date
5022                             ,g_extract_params(p_business_group_id).extract_end_date
5023                          );
5024             END IF;
5025 
5026           END IF;
5027        END IF;
5028   END IF;
5029 
5030    p_data_element_value := lpad(fnd_number.number_to_canonical(ceil(l_ptp_value)),3,'0')||'000';
5031 
5032  END IF;
5033  Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5034  l_ret_val:=0;
5035 RETURN l_ret_val;
5036 EXCEPTION
5037    WHEN OTHERS THEN
5038       p_error_message :='SQL-ERRM :'||SQLERRM;
5039       Hr_Utility.set_location('..'||p_error_message,30);
5040       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5041       l_ret_val:=1;
5042       RETURN l_ret_val;
5043 END Get_Part_Time_Percent;
5044 -- ===============================================================================
5045 -- ~ Get_Incidental_Worker
5046 -- ===============================================================================
5047 Function Get_Incidental_Worker
5048                  ( p_assignment_id         IN Number
5049                    ,p_business_group_id    IN Number
5050                    ,p_date_earned          IN DATE
5051                    ,p_error_message        OUT NOCOPY VARCHAR2
5052                    ,p_data_element_value   OUT NOCOPY VARCHAR2
5053                )
5054 Return Number IS
5055 CURSOR csr_get_incidental_wkr_code(c_asg_id Number ,c_date_earned Date) IS
5056 SELECT Decode(scl.SEGMENT1,'Y','0','1')
5057   FROM per_all_assignments_f asg
5058       ,hr_soft_coding_keyflex scl
5059 WHERE asg.assignment_id = c_asg_id
5060   AND c_date_earned BETWEEN asg.effective_start_date
5061   AND asg.effective_end_date
5062   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
5063 
5064 /*
5065 SELECT prrv.result_value
5066 FROM
5067 pay_element_types_f pet,
5068 pay_input_values_f piv,
5069 pay_run_results prr,
5070 pay_run_result_values prrv
5071 WHERE
5072   pet.element_name = 'PGGM Pensions General Information'
5073   and piv.name ='Incidental Worker'
5074   and piv.element_type_id=pet.element_type_id
5075   and prr.element_type_id=pet.element_type_id
5076   and prr.assignment_action_id =c_asg_action_id
5077   and (c_date_earned between prr.start_date
5078        and prr.end_date)
5079   and prrv.run_result_id=prr.run_result_id
5080   and prrv.input_value_id=piv.input_value_id;
5081 */
5082 l_proc_name      Varchar2(150) :=g_proc_name || 'Get_Incidental_Worker';
5083 l_ret_val        Number:=0;
5084 l_inci_wkr_code  varchar2(1):='1';
5085 l_start_date     DATE;
5086 l_ptp_start_date varchar2(10);
5087 l_error_message  varchar2(150);
5088 l_orig_date_earned DATE;
5089 asgact_rec       csr_asg_act%ROWTYPE;
5090 Begin
5091 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
5092 Hr_Utility.set_location(' g_080_index'|| g_080_index,15);
5093 Hr_Utility.set_location(' g_ptp_index'|| g_ptp_index,20);
5094 -- Calculating value for Retro Change
5095 IF g_ptp_index = 400 THEN
5096    IF(g_rcd_080(g_ptp_index + g_080_index).incidental_code = 1 ) THEN
5097    l_inci_wkr_code:=0;
5098    END IF;
5099    IF(g_rcd_080(g_ptp_index + g_080_index).incidental_code = -1 ) THEN
5100    l_inci_wkr_code:=1;
5101    END IF;
5102 ELSE
5103    IF g_ptp_index = 300 THEN
5104    l_inci_wkr_code:=g_rcd_080(g_ptp_index + g_080_index).incidental_code;
5105    ELSE
5106     IF g_ptp_index= 200 THEN
5107 
5108     --Get the  original date earned from the retro element
5109     l_orig_date_earned:=g_rcd_080(g_ptp_index + g_080_index).part_time_pct_dt_change;
5110 
5111     -- Get the incidental worker  code on that date
5112       OPEN  csr_get_incidental_wkr_code(p_assignment_id,l_orig_date_earned);
5113       FETCH csr_get_incidental_wkr_code INTO l_inci_wkr_code;
5114       CLOSE csr_get_incidental_wkr_code;
5115 
5116     ELSE --g_ptp_index=100
5117           IF g_ptp_index = 100 THEN
5118            l_start_date:=g_rcd_080(g_ptp_index + g_080_index).part_time_pct_dt_change;
5119            OPEN  csr_get_incidental_wkr_code(p_assignment_id,l_start_date);
5120            FETCH csr_get_incidental_wkr_code INTO l_inci_wkr_code;
5121            CLOSE csr_get_incidental_wkr_code;
5122   ELSE
5123    OPEN  csr_get_incidental_wkr_code(p_assignment_id,g_extract_params(p_business_group_id).extract_end_date);
5124            FETCH csr_get_incidental_wkr_code INTO l_inci_wkr_code;
5125            CLOSE csr_get_incidental_wkr_code;
5126   END IF;
5127        END IF;
5128 
5129    END IF;
5130 END IF;
5131 
5132 p_data_element_value:=l_inci_wkr_code;
5133 
5134 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5135  l_ret_val:=0;
5136 RETURN l_ret_val;
5137 EXCEPTION
5138    WHEN OTHERS THEN
5139       p_error_message :='SQL-ERRM :'||SQLERRM;
5140       Hr_Utility.set_location('..'||p_error_message,30);
5141       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5142       l_ret_val:=1;
5143       RETURN l_ret_val;
5144 END Get_Incidental_Worker;
5145 -- ===============================================================================
5146 -- ~ Get_Irregular_Payment_Year
5147 -- ===============================================================================
5148 Function Get_Irregular_Payment_Year
5149                  ( p_assignment_id         IN Number
5150                    ,p_business_group_id    IN Number
5151                    ,p_date_earned          IN DATE
5152                    ,p_error_message        OUT NOCOPY VARCHAR2
5153                    ,p_data_element_value   OUT NOCOPY VARCHAR2
5154                )
5155 Return Number IS
5156 l_proc_name     Varchar2(150) :=g_proc_name || 'Get_Irregular_Payment_Year';
5157 l_ret_val       Number:=0;
5158 l_irr_pay_year  NUMBER;
5159 l_irr_pay_amt   NUMBER:=0;
5160 l_pay_year      NUMBER;
5161 l_pay_mon       NUMBER;
5162 l_pay_day       NUMBER;
5163 l_pay_start_date DATE;
5164 l_pay_end_date   DATE;
5165 Begin
5166 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
5167 
5168 --Current year is the irregular payment year
5169 l_irr_pay_year:=Get_year(p_assignment_id
5170                        ,g_extract_params(p_business_group_id).extract_start_date
5171 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
5172 
5173 p_data_element_value:=l_irr_pay_year;
5174 
5175 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5176  l_ret_val:=0;
5177 RETURN l_ret_val;
5178 EXCEPTION
5179    WHEN OTHERS THEN
5180       p_error_message :='SQL-ERRM :'||SQLERRM;
5181       Hr_Utility.set_location('..'||p_error_message,30);
5182       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5183       l_ret_val:=1;
5184       RETURN l_ret_val;
5185 END Get_Irregular_Payment_Year;
5186 -- ===============================================================================
5187 -- ~ Get_Irregular_Payment_Amt
5188 -- ===============================================================================
5189 Function Get_Irregular_Payment_Amt
5190                  ( p_assignment_id         IN Number
5191                    ,p_business_group_id    IN Number
5192                    ,p_date_earned          IN DATE
5193                    ,p_error_message        OUT NOCOPY VARCHAR2
5194                    ,p_data_element_value   OUT NOCOPY VARCHAR2
5195                )
5196 Return Number IS
5197 
5198 -- Cursor to get Org id for the given asg id
5199 CURSOR csr_get_org_id(c_asg_id NUMBER,bg_id NUMBER) IS
5200 SELECT organization_id
5201   FROM per_all_assignments_f
5202  WHERE assignment_id = c_asg_id
5203    AND business_group_id = bg_id
5204    AND g_extract_params(p_business_group_id).extract_end_date BETWEEN
5205        effective_start_date AND effective_end_date;
5206 
5207 --Cursor to get organization start date for that assignment
5208 CURSOR csr_get_org_asg_start_date(c_asg_id NUMBER,org_id NUMBER) IS
5209 Select max(effective_start_date) from per_all_assignments_f
5210 where assignment_id = c_asg_id
5211 and organization_id = org_id;
5212 
5213 
5214 l_proc_name     Varchar2(150) :=g_proc_name || 'Get_Irregular_Payment_Amt';
5215 l_ret_val       Number:=0;
5216 l_irr_pay_amt   NUMBER;
5217 l_pay_start_date  DATE;
5218 l_org_id        NUMBER;
5219 
5220 BEGIN
5221 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
5222 
5223 l_irr_pay_amt :=Get_Balance_Value(p_assignment_id
5224                                   ,p_business_group_id
5225                                   ,'PGGM Pensions Irregular Payments'
5226                                   ,'Assignment Period To Date'
5227                                   ,g_extract_params(p_business_group_id).extract_start_date
5228                                   ,g_extract_params(p_business_group_id).extract_end_date
5229                                  );
5230 p_data_element_value:= lpad(fnd_number.number_to_canonical(CEIL(l_irr_pay_amt)),6,'0');
5231 /*--For yearly report round the irregular payment amount
5232 IF g_extract_params(p_business_group_id).extract_type='Y' THEN
5233     p_data_element_value:= lpad(fnd_number.number_to_canonical(CEIL(l_irr_pay_amt)),6,'0');
5234 ELSE
5235     p_data_element_value:=l_irr_pay_amt;
5236 END IF; */
5237 
5238 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5239  l_ret_val:=0;
5240 RETURN l_ret_val;
5241 EXCEPTION
5242    WHEN OTHERS THEN
5243       p_error_message :='SQL-ERRM :'||SQLERRM;
5244       Hr_Utility.set_location('..'||p_error_message,30);
5245       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5246       l_ret_val:=1;
5247       RETURN l_ret_val;
5248 END Get_Irregular_Payment_Amt;
5249 
5250 -- ===============================================================================
5251 -- ~ Get_Final_PTF_Year:
5252 -- ===============================================================================
5253 Function Get_Final_PTF_Year
5254                  ( p_assignment_id        IN Number
5255                    ,p_business_group_id   IN Number
5256                    ,p_date_earned         IN DATE
5257                    ,p_error_message       OUT NOCOPY VARCHAR2
5258                    ,p_data_element_value  OUT NOCOPY VARCHAR2
5259                  )
5260 Return Number IS
5261 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_Final_PTF_Year';
5262 l_ret_val     Number:=0;
5263 l_final_year  Number;
5264 BEGIN
5265 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
5266 --If called from extract
5267 IF g_rec_081_type='C' THEN
5268 
5269 l_final_year:=Get_year(p_assignment_id
5270                        ,g_extract_params(p_business_group_id).extract_start_date
5271 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
5272 p_data_element_value:=to_char(l_final_year);
5273 ELSE
5274    IF g_rec_081_type='P' THEN
5275        p_data_element_value:=g_rcd_081(g_081_index).year_of_change;
5276    END IF;
5277 END IF;
5278 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5279 RETURN l_ret_val;
5280 EXCEPTION
5281    WHEN OTHERS THEN
5282       p_error_message :='SQL-ERRM :'||SQLERRM;
5283       Hr_Utility.set_location('..'||p_error_message,30);
5284       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5285       l_ret_val:=1;
5286       RETURN l_ret_val;
5287 END Get_Final_PTF_Year;
5288 -- ===============================================================================
5289 -- ~ Get_ST_DT_Change_Pens_Sal
5290 -- ===============================================================================
5291 Function Get_ST_DT_Change_Pens_Sal
5292                  (  p_assignment_id       IN Number
5293                    ,p_business_group_id   IN Number
5294                    ,p_date_earned         IN Date
5295                    ,p_error_message       OUT NOCOPY VARCHAR2
5296                    ,p_data_element_value  OUT NOCOPY VARCHAR2
5297                )
5298      RETURN NUMBER IS
5299 l_proc_name      Varchar2(150) :=g_proc_name || 'Get_ST_DT_Change_Pens_Sal';
5300 l_ret_val        NUMBER:=0;
5301 l_curr_year      NUMBER:=0;
5302 l_prev_year      NUMBER:=0;
5303 l_pen_sal_date   DATE;
5304 l_start_date_PTP VARCHAR2(10);
5305 l_period_start_date DATE;
5306 
5307 BEGIN
5308 Hr_Utility.set_location(' Entering:   '   ||l_proc_name,10);
5309 
5310 --Get the current year
5311 l_curr_year:=Get_year(p_assignment_id
5312                        ,g_extract_params(p_business_group_id).extract_start_date
5313 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
5314 
5315 Hr_Utility.set_location(' l_year   '   ||l_curr_year,15);
5316 
5317 
5318 IF g_extract_params(p_business_group_id).extract_type='Y' THEN  --Yearly Report
5319 l_curr_year:=l_curr_year+1;
5320 
5321 --Get the period start date
5322 OPEN  c_get_period_start_date(l_curr_year
5323                               ,p_assignment_id
5324 			      ,p_date_earned);
5325 FETCH c_get_period_start_date INTO l_period_start_date;
5326 CLOSE c_get_period_start_date;
5327 
5328    --Get Participation start date
5329    l_ret_val:=Get_Start_Date_PTP(p_assignment_id
5330                                 ,p_business_group_id
5331                                 ,p_date_earned
5332                                 ,p_error_message
5333                                ,l_start_date_PTP
5334                                 );
5335 
5336    --Reporting Date is the latest date of hire date and 1st Jan of that year
5337    --Pension Salary is calculated in this period
5338    l_pen_sal_date:=l_period_start_date;
5339    IF l_pen_sal_date < to_date(l_start_date_PTP,'YYYYMMDD') THEN
5340      l_pen_sal_date:=to_date(l_start_date_PTP,'YYYYMMDD');
5341    END IF;
5342 
5343     Hr_Utility.set_location(' Pen Sal Date  '   ||l_pen_sal_date,30);
5344 
5345     p_data_element_value:=to_char(l_pen_sal_date,'YYYYMMDD');
5346     l_ret_val:=0;
5347 ELSE  --Monthy report
5348 
5349      IF g_rec060_mult_flag='Y' THEN --Calling from Record 060
5350          l_pen_sal_date:=g_rcd_060(g_060_index).pension_sal_dt_change;
5351         p_data_element_value:=to_char(l_pen_sal_date,'YYYYMMDD');
5352  l_ret_val:=0;
5353      ELSE  --other than 060 record
5354 
5355     --Get Participation start date
5356            l_ret_val:=Get_Start_Date_PTP(p_assignment_id
5357                                         ,p_business_group_id
5358                                         ,p_date_earned
5359                                         ,p_error_message
5360                                         ,l_start_date_PTP
5361                                          );
5362 
5363        --Get the period start date
5364       OPEN  c_get_period_start_date(l_curr_year
5365                                     ,p_assignment_id
5366 				    ,p_date_earned);
5367       FETCH c_get_period_start_date INTO l_period_start_date;
5368       CLOSE c_get_period_start_date;
5369 
5370        --Reporting Date is the latest date of participation start date and 1st Jan of that year
5371        --Pension Salary is calculated on this date
5372         l_pen_sal_date:=l_period_start_date;
5373         IF l_pen_sal_date < to_date(l_start_date_PTP,'YYYYMMDD') THEN
5374          l_pen_sal_date:=to_date(l_start_date_PTP,'YYYYMMDD');
5375         END IF;
5376 
5377        p_data_element_value:=to_char(l_pen_sal_date,'YYYYMMDD');
5378         l_ret_val:=0;
5379 
5380      END IF;  --060 or other record
5381 
5382 End IF;-- Report type check
5383 
5384 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5385 l_ret_val:=0;
5386 RETURN l_ret_val;
5387 EXCEPTION
5388    WHEN OTHERS THEN
5389       p_error_message :='SQL-ERRM :'||SQLERRM;
5390       Hr_Utility.set_location('..'||p_error_message,30);
5391       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5392       l_ret_val:=1;
5393       RETURN l_ret_val;
5394 END Get_ST_DT_Change_Pens_Sal;
5395 -- ===============================================================================
5396 -- ~ Get_ST_DT_Chg_Part_Time_Per
5397 -- ===============================================================================
5398 Function Get_ST_DT_Chg_Part_Time_Per
5399                  (  p_assignment_id       IN Number
5400                    ,p_business_group_id   IN Number
5401                    ,p_date_earned         IN Date
5402                    ,p_error_message       OUT NOCOPY VARCHAR2
5403                    ,p_data_element_value  OUT NOCOPY VARCHAR2
5404   )
5405      RETURN NUMBER IS
5406      /*
5407 CURSOR csr_chk_retro_ptp_ele(c_asg_id NUMBER,bg_id NUMBER) IS
5408 Select pee.screen_entry_value,pee.effective_start_date
5409 FROM
5410 pay_element_entries_f pee,
5411 pay_element_types_f  pet
5412 where pee.assignment_id = c_asg_id
5413 AND pee.element_type_id =pet.element_type_id
5414 AND pet.element_name='Retro PGGM Pensions Part Time Percentage'
5415 AND g_extract_params(bg_id).extract_start_date
5416 Between  pee.effective_start_date and pee.effective_end_date;
5417 
5418 CURSOR csr_chk_curr_ptp_ele(c_asg_id NUMBER,bg_id NUMBER) IS
5419 SELECT pee.screen_entry_value,pee.effective_start_date
5420 FROM
5421 pay_element_types_f pet,
5422 pay_input_values_f piv,
5423 pay_element_entries_f pee,
5424 pay_element_entry_values_f peev
5425 WHERE
5426   pet.element_name = 'PGGM Pensions Part Time Percentage'
5427   and piv.name ='Part Time Percentage'
5428   and piv.element_type_id=pet.element_type_id
5429   and pee.element_type_id=pet.element_type_id
5430   and pee.assignment_id =c_asg_id
5431   and (g_extract_params(bg_id).extract_start_date between pee.effective_start_date
5432        and pee.effective_end_date)
5433   and peev.element_entry_id=pee.element_entry_id
5434   and peev.input_value_id=piv.input_value_id;*/
5435 
5436 l_proc_name   Varchar2(150) :=g_proc_name || 'Get_ST_DT_Chg_Part_Time_Per';
5437 l_ret_val NUMBER:=0;
5438 BEGIN
5439 Hr_Utility.set_location('Entering:'   ||l_proc_name,10);
5440 
5441    Hr_Utility.set_location(' ptp_chg_date   '   ||g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change,25);
5442    Hr_Utility.set_location(' g_ptp_index,g_080_index'||g_ptp_index||g_080_index,25);
5443 
5444    p_data_element_value:=to_char(g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change,'YYYYMMDD');
5445 
5446 
5447 Hr_Utility.set_location(' Leaving:   '   ||l_proc_name,50);
5448 l_ret_val:=0;
5449 RETURN l_ret_val;
5450 EXCEPTION
5451    WHEN OTHERS THEN
5452       p_error_message :='SQL-ERRM :'||SQLERRM;
5453       Hr_Utility.set_location('..'||p_error_message,30);
5454       Hr_Utility.set_location('Leaving: '||l_proc_name,40);
5455       l_ret_val:=1;
5456       RETURN l_ret_val;
5457 END Get_ST_DT_Chg_Part_Time_Per;
5458 
5459 --============================================================================
5460 -- chk_term_asg_eff
5461 -- Function to check if the assignment is terminated and that
5462 -- the termination has happened before or on the effective date passed
5463 --============================================================================
5464 FUNCTION chk_term_asg_eff
5465         ( p_assignment_id        IN Number
5466          ,p_business_group_id    IN per_all_assignments_f.business_group_id%TYPE
5467          ,p_effective_date       IN DATE
5468         ) RETURN Number IS
5469 CURSOR cur_chk_term IS
5470 SELECT 1 FROM per_periods_of_service
5471 WHERE PERSON_ID = g_person_id
5472   AND TRUNC(actual_termination_date) <=  trunc(p_effective_date)
5473   AND NOT EXISTS ( SELECT 1 FROM PER_PERIODS_OF_SERVICE
5474                     WHERE person_id = g_person_id
5475                       AND trunc(date_start) BETWEEN  trunc(p_effective_date)
5476                       AND add_months(trunc(p_effective_date),1) - 1
5477                       AND actual_termination_date is null) ;
5478 
5479  l_proc_name    Varchar2(150) := g_proc_name ||'chk_term_asg_eff';
5480  l_return_value Number :=0;
5481  l_chk          NUMBER := 0;
5482 
5483 BEGIN
5484 
5485    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
5486 
5487    OPEN cur_chk_term;
5488       FETCH cur_chk_term INTO l_chk;
5489         IF cur_chk_term%FOUND THEN
5490            l_return_value := 1;
5491         ELSIF cur_chk_term%NOTFOUND THEN
5492            l_return_value := 0;
5493         END IF;
5494    CLOSE cur_chk_term;
5495 
5496    Hr_Utility.set_location('Leaving: '||l_proc_name, 10);
5497    RETURN l_return_value;
5498 
5499 EXCEPTION
5500   WHEN Others THEN
5501    Hr_Utility.set_location('Error -- Leaving: '||l_proc_name, 9);
5502    l_return_value := 0;
5503    RETURN l_return_value;
5504 END chk_term_asg_eff;
5505 -- =============================================================================
5506 -- Org_Id_Data Element:Returns  Org Id to Fast formula
5507 -- =============================================================================
5508 
5509 FUNCTION Org_Id_DataElement
5510            (p_assignment_id        IN  per_all_assignments_f.assignment_id%TYPE
5511            ,p_business_group_id    IN  per_all_assignments_f.business_group_id%TYPE
5512            ,p_effective_date       IN  Date
5513            ,p_error_message        OUT NOCOPY Varchar2
5514           ,p_data_element_value   OUT NOCOPY Varchar2
5515           ) RETURN Number IS
5516 
5517   l_temp_sort_org              Varchar2(50);
5518   l_proc_name       Varchar2(150) := g_proc_name ||'Sort_Id_Generator';
5519   l_return_value    Number := 1;
5520 
5521 
5522 BEGIN
5523   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
5524 
5525    IF g_primary_assig.EXISTS(p_assignment_id) THEN
5526      p_data_element_value := g_primary_assig(p_assignment_id).organization_id;
5527   END IF;
5528 
5529   l_return_value := 0;
5530   Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
5531   RETURN l_return_value;
5532 EXCEPTION
5533    WHEN Others THEN
5534     p_error_message :='SQL-ERRM :'||SQLERRM;
5535     Hr_Utility.set_location('..'||p_error_message,85);
5536     RETURN l_return_value;
5537 END Org_Id_DataElement;
5538 -- ================================================================================
5539 -- ~ Sort_Id_Generator : It is concatenated with ernum+empNumber+record.
5540 -- ================================================================================
5541 FUNCTION Sort_Id_Generator
5542            (p_assignment_id       IN         Number
5543            ,p_business_group_id   IN         Number
5544            ,p_effective_date      IN         Date
5545           ,p_generator_record     IN         Varchar2
5546            ,p_error_message       OUT NOCOPY Varchar2
5547           ,p_data_element_value   OUT NOCOPY Varchar2
5548           ) RETURN Number IS
5549 
5550   l_temp_sort_id    Varchar2(50);
5551   l_proc_name       Varchar2(150) := g_proc_name ||'Sort_Id_Generator';
5552   l_employee_number per_all_people_f.Employee_number%TYPE;
5553   l_temp_person_id  per_all_people_f.Employee_number%TYPE;
5554    l_return_value    Number := -1;
5555   l_employer_number Number;
5556   l_asg_seq_num     Varchar2(2);
5557 
5558 BEGIN
5559   Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
5560   -- Get the orgId for assigntment ID
5561  l_return_value := Get_PGGM_ER_Num(p_assignment_id
5562                                  ,p_business_group_id
5563                                  ,p_effective_date
5564                                  ,p_error_message
5565                                  ,p_data_element_value);
5566   l_employer_number := Nvl(p_data_element_value,9999999);
5567   l_employer_number := p_data_element_value;
5568   p_data_element_value :='';
5569 
5570   IF g_primary_assig.EXISTS(p_assignment_id) THEN
5571      l_employee_number := g_primary_assig(p_assignment_id).ee_num;
5572   END IF;
5573 
5574    Hr_Utility.set_location('l_employee_number:   '||l_employee_number, 5);
5575    l_employer_number := Lpad(l_employer_number,9,0);
5576    l_employee_number :=Lpad(l_employee_number,6,0);
5577    l_asg_seq_num     := g_primary_assig(p_assignment_id).asg_seq_num;
5578    IF To_Number(Nvl(l_asg_seq_num,'1')) < 10 THEN
5579   l_asg_seq_num := '0' ||Nvl(l_asg_seq_num,'1');
5580    END IF;
5581 
5582    p_data_element_value :=  l_employer_number ||
5583                             l_employee_number ||
5584     l_asg_seq_num     ||
5585      p_generator_record;
5586 
5587    Hr_Utility.set_location('p_data_element_value:   '||p_data_element_value, 5);
5588    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
5589    l_return_value := 0;
5590 
5591   RETURN l_return_value;
5592 EXCEPTION
5593    WHEN Others THEN
5594     p_error_message :='SQL-ERRM :'||SQLERRM;
5595     Hr_Utility.set_location('..'||p_error_message,85);
5596     RETURN l_return_value;
5597 END Sort_Id_Generator;
5598 
5599 --Multiple Record Processing for Record 060
5600 Function Process_Mult_Rec060
5601                 (   p_assignment_id     IN         Number
5602                   ,p_business_group_id  IN         Number
5603                   ,p_effective_date     IN         DATE
5604                   ,p_error_message      OUT NOCOPY VARCHAR2
5605                )
5606 RETURN Number IS
5607 
5608   l_proc_name          Varchar2(150) := g_proc_name ||'Process_Mult_Rec060';
5609   l_error_message      Varchar2(2000);
5610   l_ret_val            Number := 0;
5611   l_rcd_id             Number :=0;
5612   l_main_rec           csr_rslt_dtl%ROWTYPE;
5613   l_new_rec            csr_rslt_dtl%ROWTYPE;
5614   l_evt_dates          DATE;
5615 BEGIN
5616  Hr_Utility.set_location('Entering: '||l_proc_name,5);
5617 
5618 
5619 
5620    --Fetch the record id from the sequence number
5621    OPEN c_get_rcd_id(6);
5622    FETCH c_get_rcd_id INTO l_rcd_id;
5623    CLOSE c_get_rcd_id;
5624 
5625    -- Fetch result dtl record
5626    OPEN csr_rslt_dtl(c_person_id      => g_person_id
5627                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
5628                     ,c_ext_dtl_rcd_id => l_rcd_id
5629                    );
5630    FETCH csr_rslt_dtl INTO l_main_rec;
5631    CLOSE csr_rslt_dtl;
5632    -- increase the OVN by 1
5633    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
5634    l_new_rec := l_main_rec;
5635    l_new_rec.val_40 := NULL;
5636    Hr_Utility.set_location('g_rec_060_count'||g_rec_060_count,80);
5637    IF g_rec_060_count > 0 THEN
5638     g_rec060_mult_flag:='Y';
5639     g_060_index:=g_rcd_060.FIRST;
5640     While g_060_index IS NOT NULL
5641     LOOP
5642            Process_Ext_Rslt_Dtl_Rec
5643             (p_assignment_id    => p_assignment_id
5644             ,p_organization_id  => NULL
5645             ,p_effective_date   => p_effective_date
5646             ,p_ext_dtl_rcd_id   => l_rcd_id
5647             ,p_rslt_rec         => l_new_rec
5648             ,p_asgaction_no     => NULL
5649             ,p_error_message    => p_error_message
5650    );
5651     g_060_index:=g_rcd_060.NEXT(g_060_index);
5652 
5653     END LOOP;
5654     --Reset the flag
5655     g_rec060_mult_flag:='N';
5656 
5657    END IF;
5658    --Delete the main rec from the ben table
5659    IF (g_rec_060_count >0 )
5660    THEN
5661          l_main_rec.val_40:='Delete';
5662          Upd_Rslt_Dtl(l_main_rec);
5663     Hr_Utility.set_location('Delete main rec',80);
5664    END IF;
5665 
5666    l_ret_val := 0;
5667 
5668  Hr_Utility.set_location('Leaving: '||l_proc_name,80);
5669  RETURN l_ret_val;
5670 EXCEPTION
5671    WHEN Others THEN
5672     p_error_message :='SQL-ERRM :'||SQLERRM;
5673     Hr_Utility.set_location('..'||p_error_message,85);
5674     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
5675     RETURN -1;
5676 END Process_Mult_Rec060;
5677 
5678 --Multiple Record Processing for Record 080
5679 Function Process_Mult_Rec080
5680                 (   p_assignment_id      IN         Number
5681                   ,p_business_group_id   IN         Number
5682                   ,p_effective_date      IN         DATE
5683                   ,p_error_message       OUT NOCOPY VARCHAR2
5684          )
5685 RETURN Number IS
5686 
5687 ------Cursor to check whether there is any change in part time percentage
5688 CURSOR csr_chk_prev_ptp_ele(c_asg_id NUMBER,bg_id NUMBER,c_date DATE) IS
5689 SELECT peev.screen_entry_value
5690 FROM
5691 pay_element_types_f pet,
5692 pay_input_values_f piv,
5693 pay_element_entries_f pee,
5694 pay_element_entry_values_f peev
5695 WHERE
5696   pet.element_name = 'PGGM Pensions Part Time Percentage'
5697   and piv.name ='Part Time Percentage'
5698   and piv.element_type_id=pet.element_type_id
5699   and pee.element_type_id=pet.element_type_id
5700   and pee.assignment_id =c_asg_id
5701   and ((c_date -1) between pee.effective_start_date
5702        and pee.effective_end_date)
5703   and peev.element_entry_id=pee.element_entry_id
5704   and peev.input_value_id=piv.input_value_id
5705   and((c_date-1)  between peev.effective_start_date
5706        and peev.effective_end_date);
5707 
5708 -------Cursor to check whether there is any change in incidental worker code
5709 CURSOR csr_chk_inci_code_chg_ele(c_asg_id NUMBER,bg_id NUMBER,c_date DATE) IS
5710 SELECT Decode(scl.SEGMENT1,'Y','0','1') segment1
5711 FROM   per_all_assignments_f asg
5712       ,hr_soft_coding_keyflex scl
5713 WHERE asg.assignment_id = c_asg_id
5714   AND (c_date - 1 BETWEEN asg.effective_start_date
5715   AND asg.effective_end_date)
5716   AND asg.soft_coding_keyflex_id = scl.soft_coding_keyflex_id;
5717   l_proc_name           Varchar2(150) := g_proc_name ||'Process_Mult_Rec080';
5718 
5719 
5720   l_evt_dates           DATE;
5721   l_error_message       Varchar2(2000);
5722   l_ret_val             Number := 0;
5723   l_rcd_id              Number :=0;
5724   l_main_rec            csr_rslt_dtl%ROWTYPE;
5725   l_new_rec             csr_rslt_dtl%ROWTYPE;
5726   l_ptp_start_date      DATE;
5727   l_start_date          DATE;
5728   l_prev_ptp_val        varchar2(10);
5729   l_data_element_val    VARCHAR2(10);
5730   l_080_index           NUMBER;
5731   l_prev_iwc            VARCHAR2(1);
5732   l_080_rec_type3_flag  VARCHAR2(1):='Y';
5733   l_080_rec_type4_flag  VARCHAR2(1):='Y';
5734   l_check_date          DATE;
5735   l_ptp_index           NUMBER;
5736 
5737 BEGIN
5738  Hr_Utility.set_location('Entering: '||l_proc_name,5);
5739 
5740 
5741    --Fetch the record id from the sequence number
5742    OPEN c_get_rcd_id(8);
5743    FETCH c_get_rcd_id INTO l_rcd_id;
5744    CLOSE c_get_rcd_id;
5745 
5746 
5747    -- Fetch result dtl record
5748    OPEN csr_rslt_dtl(c_person_id      => g_person_id
5749                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
5750                     ,c_ext_dtl_rcd_id => l_rcd_id
5751                    );
5752 
5753    Hr_Utility.set_location('l_rcd_id'||l_rcd_id,10);
5754    Hr_Utility.set_location('g_ext_rslt_id'||Ben_Ext_Thread.g_ext_rslt_id,10);
5755    Hr_Utility.set_location('g_person_id'||g_person_id,10);
5756 
5757    FETCH csr_rslt_dtl INTO l_main_rec;
5758    IF csr_rslt_dtl%FOUND THEN
5759      Hr_Utility.set_location('080 Cursor Found '||l_main_rec.CREATED_BY,10);
5760    ELSE
5761      Hr_Utility.set_location('080 Cursor NOT Found ',10);
5762    END IF;
5763 
5764    CLOSE csr_rslt_dtl;
5765    -- increase the OVN by 1
5766    l_new_rec := l_main_rec;
5767    l_new_rec.val_40 := NULL;
5768    l_new_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
5769 
5770     g_080_index:=0;
5771    Hr_Utility.set_location('g_rec_080_type1_count: '||g_rec_080_type1_count,15);
5772    -- 1) Loop for Current change in part time percentage
5773    IF g_rec_080_type1_count > 0 THEN
5774      g_ptp_index:=100;
5775      g_080_index:=0;
5776      FOR l_080_index IN 0..g_rec_080_type1_count-1
5777      LOOP
5778            Hr_Utility.set_location('Loop'||g_080_index,80);
5779 
5780       g_080_display_flag:='Y';
5781            Process_Ext_Rslt_Dtl_Rec
5782                   (p_assignment_id    => p_assignment_id
5783                    ,p_effective_date   => p_effective_date
5784                    ,p_ext_dtl_rcd_id   => l_rcd_id
5785                    ,p_rslt_rec         => l_new_rec
5786                    ,p_error_message    => p_error_message
5787                    );
5788                   g_080_display_flag:='N';
5789 
5790              g_080_index:= g_080_index + 1;
5791      END LOOP;
5792      g_080_index:=0;
5793 
5794    END IF;-- End of g_rec_080_type1_count check
5795 
5796    Hr_Utility.set_location('g_rec_080_type2_count: '||g_rec_080_type2_count,15);
5797     -- 2) Loop for Retro change in part time percentage
5798    IF g_rec_080_type2_count > 0 THEN
5799      g_ptp_index:=200;
5800      FOR l_080_index IN 0..g_rec_080_type2_count-1
5801      LOOP
5802 
5803               g_080_display_flag:='Y';
5804                   Process_Ext_Rslt_Dtl_Rec
5805                    (p_assignment_id    => p_assignment_id
5806                    ,p_effective_date   => p_effective_date
5807                    ,p_ext_dtl_rcd_id   => l_rcd_id
5808                    ,p_rslt_rec         => l_new_rec
5809                    ,p_error_message    => p_error_message
5810                    );
5811              g_080_display_flag:='N';
5812      g_080_index:= g_080_index + 1;
5813 
5814      END LOOP;
5815      g_080_index:=0;
5816    END IF;-- End of g_rec_080_type2_count check
5817 
5818    Hr_Utility.set_location('g_rec_080_type3_count: '||g_rec_080_type3_count,15);
5819    -- 3) Loop for Current change in Incidental Worker Code
5820    IF g_rec_080_type3_count > 0 THEN
5821      g_ptp_index:=300;
5822 
5823 
5824      FOR l_080_index IN 0..g_rec_080_type3_count-1
5825      LOOP
5826 
5827      --Check if extract date is already in the global table
5828      --if extract is already processed during ptp processing then do not insert it
5829      l_ptp_index:=100;
5830      l_check_date:=g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change;
5831      For  l_index IN 0..g_rec_080_type1_count-1
5832      LOOP
5833    l_080_rec_type3_flag:='Y';
5834    IF l_check_date=g_rcd_080(l_ptp_index).part_time_pct_dt_change THEN
5835       l_080_rec_type3_flag:='N';
5836    END IF;
5837          l_ptp_index:=l_ptp_index+1;
5838      END LOOP;
5839          g_080_display_flag:='Y';
5840 
5841 IF l_080_rec_type3_flag <>'N' THEN
5842                    Process_Ext_Rslt_Dtl_Rec
5843                    (p_assignment_id    => p_assignment_id
5844                    ,p_effective_date   => p_effective_date
5845                    ,p_ext_dtl_rcd_id   => l_rcd_id
5846                    ,p_rslt_rec         => l_new_rec
5847                    ,p_error_message    => p_error_message
5848                    );
5849          END IF;
5850   g_080_display_flag:='N';
5851 
5852        g_080_index:= g_080_index + 1;
5853      END LOOP;
5854      g_080_index:=0;
5855    END IF;-- End of g_rec_080_type1_count check
5856 
5857    Hr_Utility.set_location('g_rec_080_type4_count: '||g_rec_080_type4_count,15);
5858    -- 4) Loop for Retro change in Incidental Worker Code
5859    IF g_rec_080_type4_count > 0 THEN
5860      g_ptp_index:=400;
5861      FOR l_080_index IN 0..g_rec_080_type4_count-1
5862      LOOP
5863      --Check if extract date is already in the global table
5864      --if extract is already processed during ptp processing then do not insert it
5865      l_ptp_index:=200;
5866      l_check_date:=g_rcd_080(g_ptp_index+g_080_index).part_time_pct_dt_change;
5867         Hr_Utility.set_location('l_check_date'||l_check_date,15);
5868        Hr_Utility.set_location('g_rec_080_type2_count'||g_rec_080_type2_count,15);
5869      For  l_index IN 0..g_rec_080_type2_count-1
5870      LOOP
5871          l_080_rec_type4_flag:='Y';
5872          Hr_Utility.set_location('g_rcd_080(l_ptp_index).part_time_pct_dt_change'||g_rcd_080(l_ptp_index).part_time_pct_dt_change,15);
5873        IF l_check_date=g_rcd_080(l_ptp_index).part_time_pct_dt_change THEN
5874          l_080_rec_type4_flag:='N';
5875        END IF;
5876          l_ptp_index:=l_ptp_index+1;
5877      END LOOP;
5878          g_080_display_flag:='Y';
5879 
5880 
5881       IF l_080_rec_type3_flag <>'N' THEN
5882                   Process_Ext_Rslt_Dtl_Rec
5883                    (p_assignment_id    => p_assignment_id
5884                    ,p_effective_date   => p_effective_date
5885                    ,p_ext_dtl_rcd_id   => l_rcd_id
5886                    ,p_rslt_rec         => l_new_rec
5887                    ,p_error_message    => p_error_message
5888                    );
5889       END IF;
5890       g_080_display_flag:='N';
5891            g_080_index:= g_080_index + 1;
5892      END LOOP;
5893      g_080_index:=0;
5894    END IF;-- End of g_rec_080_type4_count check
5895 
5896    -- Delete the 080 record created by extract
5897      IF((g_rec_080_type1_count+g_rec_080_type2_count+g_rec_080_type3_count+g_rec_080_type4_count)>0) THEN
5898            l_main_rec.val_40:='Delete';
5899            Upd_Rslt_Dtl(l_main_rec);
5900      Hr_Utility.set_location('Delete main rec',80);
5901      END IF;
5902 
5903 
5904    l_ret_val := 0;
5905 
5906  Hr_Utility.set_location('Leaving: '||l_proc_name,80);
5907  RETURN l_ret_val;
5908 EXCEPTION
5909    WHEN Others THEN
5910     p_error_message :='SQL-ERRM :'||SQLERRM;
5911     Hr_Utility.set_location('..'||p_error_message,85);
5912     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
5913     RETURN -1;
5914 END Process_Mult_Rec080;
5915 
5916 --Multiple Record Processing for Record 081
5917 Function Process_Mult_Rec081
5918                 (    p_assignment_id       IN         Number
5919                      ,p_business_group_id  IN         Number
5920                      ,p_effective_date     IN         DATE
5921                      ,p_error_message      OUT NOCOPY VARCHAR2
5922                )
5923 RETURN Number IS
5924 
5925   l_proc_name          Varchar2(150) := g_proc_name ||'Process_Mult_Rec081';
5926   l_error_message      Varchar2(2000);
5927   l_ret_val            Number :=0;
5928   l_rcd_id             Number :=0;
5929   l_no_asg_action      NUMBER :=0;
5930   l_organization_id    NUMBER :=0;
5931   l_main_rec           csr_rslt_dtl%ROWTYPE;
5932   l_new_rec            csr_rslt_dtl%ROWTYPE;
5933   l_081_count          NUMBER:=0;
5934 
5935 BEGIN
5936  Hr_Utility.set_location('Entering: '||l_proc_name,5);
5937 
5938    IF  g_rec_081_count > 0 THEN
5939 
5940    --Fetch the record id from the sequence number
5941    OPEN c_get_rcd_id(9);
5942    FETCH c_get_rcd_id INTO l_rcd_id;
5943    CLOSE c_get_rcd_id;
5944 
5945    -- Fetch result dtl record
5946    OPEN csr_rslt_dtl(c_person_id      => g_person_id
5947                     ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
5948                     ,c_ext_dtl_rcd_id => l_rcd_id
5949                    );
5950    FETCH csr_rslt_dtl INTO l_main_rec;
5951    CLOSE csr_rslt_dtl;
5952    -- increase the OVN by 1
5953    l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
5954    l_new_rec := l_main_rec;
5955    l_new_rec.val_40 := NULL;
5956 
5957    g_rec_081_type:='P';
5958    g_081_index:=0;
5959    l_081_count:=g_rcd_081.COUNT;
5960    WHILE g_081_index < l_081_count
5961    LOOP
5962             Process_Ext_Rslt_Dtl_Rec
5963             (p_assignment_id    => p_assignment_id
5964             ,p_organization_id  => NULL
5965             ,p_effective_date   => p_effective_date
5966             ,p_ext_dtl_rcd_id   => l_rcd_id
5967             ,p_rslt_rec         => l_new_rec
5968             ,p_asgaction_no     => NULL
5969             ,p_error_message    => p_error_message
5970    );
5971     g_081_index:=g_081_index+1;
5972 
5973    END LOOP;
5974    --Re set global flag
5975    g_rec_081_type:='C';
5976     -- Delete the 081 record created by extract
5977    IF(g_main_rec_081 = 'D') THEN
5978      l_main_rec.val_40:='Delete';
5979      Upd_Rslt_Dtl(l_main_rec);
5980      Hr_Utility.set_location('Delete main rec',80);
5981      END IF;
5982    END IF;
5983 
5984    l_ret_val := 0;
5985 
5986  Hr_Utility.set_location('Leaving: '||l_proc_name,80);
5987  RETURN l_ret_val;
5988 EXCEPTION
5989    WHEN Others THEN
5990     p_error_message :='SQL-ERRM :'||SQLERRM;
5991     Hr_Utility.set_location('..'||p_error_message,85);
5992     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
5993     RETURN -1;
5994 END Process_Mult_Rec081;
5995 -- =============================================================================
5996 -- Process_Mult_Records: For a given assignment multiple records are created for
5997 -- Records 040,060,080. Addl. rows for the record are
5998 -- provided it satisfies the functional requirements for each record i.e. the
5999 -- record display criteria.
6000 -- =============================================================================
6001 FUNCTION Process_Mult_Records
6002            (p_assignment_id       IN         Number
6003            ,p_business_group_id   IN         Number
6004            ,p_effective_date      IN         Date
6005            ,p_error_message       OUT NOCOPY Varchar2
6006            )
6007 RETURN Number IS
6008   l_proc_name          Varchar2(150) := g_proc_name ||'Process_Mult_Records';
6009   l_data_element_value Varchar2(150);
6010   l_error_message      Varchar2(2000);
6011   l_error_flag         Boolean;
6012   l_ret_val            Number := 0;
6013 
6014 BEGIN
6015    Hr_Utility.set_location('Entering: '||l_proc_name, 4);
6016 
6017    -- Process Multiple Records for Record 060
6018    BEGIN
6019    l_ret_val := Process_Mult_Rec060
6020                 ( p_assignment_id      => p_assignment_id
6021                   ,p_business_group_id  => p_business_group_id
6022                   ,p_effective_date     => p_effective_date
6023                   ,p_error_message      => p_error_message
6024                 );
6025    Hr_Utility.set_location('..Processed Multi Recds for 060 : '||l_proc_name, 20);
6026    EXCEPTION
6027       WHEN Others THEN
6028       Hr_Utility.set_location('..Error in Multi Recds for 060 : '||l_proc_name, 12);
6029       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
6030       l_error_flag    := TRUE;
6031    END;
6032   IF l_ret_val <> 0 THEN
6033       l_error_message := l_error_message ||
6034                          'Error in Processing Multi Record 060 for '||
6035                          'Assignment Id :'||p_assignment_id ;
6036       l_error_flag    := TRUE;
6037    END IF;
6038     -- Process Multiple Records for Record 080
6039    BEGIN
6040    l_ret_val := Process_Mult_Rec080
6041                 (p_assignment_id      => p_assignment_id
6042                 ,p_business_group_id  => p_business_group_id
6043                 ,p_effective_date     => p_effective_date
6044                 ,p_error_message      => p_error_message
6045                );
6046    Hr_Utility.set_location('..Processed Multi Recds for 080 : '||l_proc_name, 12);
6047    EXCEPTION
6048       WHEN Others THEN
6049       Hr_Utility.set_location('..Error in Multi Recds for 080 : '||l_proc_name, 12);
6050       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
6051       l_error_flag    := TRUE;
6052    END;
6053    IF l_ret_val <> 0 THEN
6054       l_error_message := l_error_message ||
6055                          'Error in Processing Multi Record 080 for '||
6056                          'Assignment Id :'||p_assignment_id ;
6057       l_error_flag    := TRUE;
6058    END IF;
6059     -- Process Multiple Records for Record 081
6060    BEGIN
6061    l_ret_val := Process_Mult_Rec081
6062                 ( p_assignment_id      => p_assignment_id
6063                  ,p_business_group_id  => p_business_group_id
6064                  ,p_effective_date     => p_effective_date
6065                  ,p_error_message      => p_error_message
6066                 );
6067    Hr_Utility.set_location('..Processed Multi Recds for 081 : '||l_proc_name, 20);
6068    EXCEPTION
6069       WHEN Others THEN
6070       Hr_Utility.set_location('..Error in Multi Recds for 081 : '||l_proc_name, 12);
6071       l_error_message := Substr('SQL-ERRM :'||SQLERRM,1,2000);
6072       l_error_flag    := TRUE;
6073    END;
6074   IF l_ret_val <> 0 THEN
6075       l_error_message := l_error_message ||
6076                          'Error in Processing Multi Record 081 for '||
6077                          'Assignment Id :'||p_assignment_id ;
6078       l_error_flag    := TRUE;
6079    END IF;
6080 
6081 
6082 
6083    Hr_Utility.set_location('Leaving: '||l_proc_name, 80);
6084    IF  l_error_flag THEN
6085        p_error_message := l_error_message;
6086        RETURN -1;
6087    ELSE
6088        RETURN 0;
6089    END IF;
6090 
6091 EXCEPTION
6092    WHEN Others THEN
6093     p_error_message :='SQL-ERRM :'||SQLERRM;
6094     Hr_Utility.set_location('..'||p_error_message,85);
6095     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6096     RETURN -1;
6097 
6098 END Process_Mult_Records;
6099 -- ===============================================================================
6100 -- ~ Get_Conc_Prog_Information : Common function to get the concurrent program parameters
6101 -- ===============================================================================
6102 FUNCTION Get_Conc_Prog_Information
6103            (p_header_type         IN Varchar2
6104             ,p_error_message      OUT NOCOPY Varchar2
6105            ,p_data_element_value  OUT NOCOPY Varchar2
6106 )
6107 RETURN Number IS
6108 
6109 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Conc_Prog_Information';
6110 l_return_value  Number:=-1;
6111 
6112 BEGIN
6113 
6114    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
6115    Hr_Utility.set_location('p_header_type: '||p_header_type,10);
6116    IF p_header_type = 'EXTRACT_NAME' THEN
6117         p_data_element_value := g_conc_prog_details(0).extract_name;
6118    ELSIF p_header_type = 'PGGM_ER_NAME' THEN
6119        p_data_element_value := g_conc_prog_details(0).orgname;
6120    ELSIF p_header_type = 'ELE_SET' THEN
6121       p_data_element_value := g_conc_prog_details(0).elementset;
6122    ELSIF p_header_type = 'REPORT_TYPE' THEN
6123        p_data_element_value := g_conc_prog_details(0).extract_type;
6124    ELSIF p_header_type = 'EXT_START_DATE' THEN
6125       p_data_element_value := to_char(g_conc_prog_details(0).beginningdt,'YYMM');
6126    ELSIF p_header_type = 'END_DT_PAID' THEN
6127          p_data_element_value := g_conc_prog_details(0).endingdt;
6128    ELSIF p_header_type = 'PAYROLL_NAME' THEN
6129       Hr_Utility.set_location('PAYROLL_NAME: '||g_conc_prog_details(0).payrollname, 5);
6130       p_data_element_value := g_conc_prog_details(0).payrollname;
6131    ELSIF p_header_type = 'CON_SET' THEN
6132       p_data_element_value := g_conc_prog_details(0).consolset;
6133       Hr_Utility.set_location('CON_SET: '||l_return_value, 5);
6134    END IF;
6135    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
6136    l_return_value:=0;
6137   RETURN l_return_value;
6138 EXCEPTION
6139   WHEN Others THEN
6140      p_error_message :='SQL-ERRM :'||SQLERRM;
6141      Hr_Utility.set_location('..Exception Others Raised at  Get_Conc_Prog_Information'||p_error_message,40);
6142      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
6143      l_return_value:=1;
6144      RETURN l_return_value;
6145 END Get_Conc_Prog_Information;
6146 
6147 -- =============================================================================
6148 -- PQP_NL_GET_DATA_ELEMENT_VALUE
6149 -- This function is used for all rule based data elements
6150 -- =============================================================================
6151 
6152 FUNCTION PQP_NL_Get_Data_Element_Value
6153  (  p_assignment_id      IN Number
6154    ,p_business_group_id  IN Number
6155    ,p_date_earned        IN Date
6156    ,p_data_element_cd    IN Varchar2
6157    ,p_error_message      OUT NOCOPY Varchar2
6158    ,p_data_element_value OUT NOCOPY Varchar2
6159  ) RETURN Number IS
6160 
6161  l_ret_val    Number;
6162  l_header_type varchar2(40);
6163  l_debug      Boolean;
6164  l_proc_name  Varchar2(150) := g_proc_name ||'PQP_NL_Get_Data_Element_Value';
6165 
6166 BEGIN
6167 
6168 l_ret_val := 0;
6169 
6170    Hr_Utility.set_location(' Entering :      ' || l_proc_name , 5);
6171    Hr_Utility.set_location(' p_assignment_id ' || p_assignment_id , 10);
6172    Hr_Utility.set_location(' p_bg_id is      ' || p_business_group_id ,15);
6173    Hr_Utility.set_location(' p_date_earned   ' || p_date_earned,20 );
6174    Hr_Utility.set_location(' p_data_ele_cd   ' || p_data_element_cd ,25);
6175    Hr_Utility.set_location(' g_person_id     ' || g_person_id , 30);
6176 
6177    IF (p_data_element_cd = 'PGGM_ER_NUM') THEN
6178 
6179     l_ret_val := Get_PGGM_ER_Num(p_assignment_id
6180                                ,p_business_group_id
6181                                ,p_date_earned
6182                                ,p_error_message
6183                                ,p_data_element_value);
6184     IF ISNUMBER(p_data_element_value) THEN
6185        p_data_element_value := Trim(To_Char(Fnd_Number.Canonical_To_Number
6186                                        (Nvl(p_data_element_value,'0'))
6187                                    ,'099999'));
6188     END IF;
6189     ELSIF(p_data_element_cd = 'PGGM_EE_NUM') THEN
6190 
6191      l_ret_val := Get_PGGM_Ee_Num(p_assignment_id
6192                                ,p_business_group_id
6193                                ,p_date_earned
6194                                ,p_error_message
6195                                ,p_data_element_value);
6196      IF ISNUMBER(p_data_element_value) THEN
6197        p_data_element_value := Trim(To_Char(Fnd_Number.Canonical_To_Number
6198                                        (Nvl(p_data_element_value,'0'))
6199                                    ,'099'));
6200      END IF;
6201      ELSIF(p_data_element_cd = 'EE_NUM') THEN
6202 
6203      l_ret_val := Get_EE_Num(p_assignment_id
6204                                ,p_business_group_id
6205                                ,p_date_earned
6206                                ,p_error_message
6207                                ,p_data_element_value);
6208 
6209      ELSIF (p_data_element_cd = 'KIND_OF_PARTICIPATION') THEN
6210      l_ret_val := Get_Kind_Of_PTP
6211                  ( p_assignment_id
6212                    ,p_business_group_id
6213                    ,p_date_earned
6214                    ,p_error_message
6215                    ,p_data_element_value
6216                  );
6217      ELSIF (p_data_element_cd = 'INITIALS') THEN
6218      l_ret_val := Get_Person_Initials
6219                  ( p_assignment_id
6220                    ,p_business_group_id
6221                    ,p_date_earned
6222                    ,p_error_message
6223                    ,p_data_element_value
6224                  );
6225      ELSIF (p_data_element_cd = 'OCC_CODE') THEN
6226      /*l_ret_val := Get_Occupation_Code
6227                  (p_assignment_id
6228          ,p_business_group_id
6229                  ,p_date_earned
6230          ,p_error_message
6231          ,p_data_element_value);*/
6232      p_data_element_value := '00';
6233      l_ret_val := 0;
6234      ELSIF (p_data_element_cd = 'HIRE_DATE') THEN
6235      l_ret_val := Get_Hire_Date
6236                  ( p_assignment_id
6237                    ,p_business_group_id
6238                    ,p_date_earned
6239                    ,p_error_message
6240                    ,p_data_element_value
6241                  );
6242      ELSIF (p_data_element_cd = 'GENDER') THEN
6243      l_ret_val := Get_Gender
6244                  ( p_assignment_id
6245                    ,p_business_group_id
6246                    ,p_date_earned
6247                    ,p_error_message
6248                    ,p_data_element_value
6249                  );
6250      ELSIF (p_data_element_cd = 'STREET') THEN
6251      l_ret_val := Get_Street
6252                  ( p_assignment_id
6253                    ,p_business_group_id
6254                    ,p_date_earned
6255                    ,p_error_message
6256                    ,p_data_element_value
6257                  );
6258      ELSIF (p_data_element_cd = 'HOUSE_NUM') THEN
6259      l_ret_val := Get_House_Num
6260                  ( p_assignment_id
6261                    ,p_business_group_id
6262                    ,p_date_earned
6263                    ,p_error_message
6264                    ,p_data_element_value
6265                  );
6266      ELSIF (p_data_element_cd = 'ADDL_HOUSE_NUM') THEN
6267      l_ret_val := Get_Addl_House_Num
6268                  ( p_assignment_id
6269                    ,p_business_group_id
6270                    ,p_date_earned
6271                    ,p_error_message
6272                    ,p_data_element_value
6273                  );
6274      ELSIF (p_data_element_cd = 'EMP_REG_NUM') THEN
6275      l_ret_val := Get_Emp_Reg_Num
6276                  ( p_assignment_id
6277                    ,p_business_group_id
6278                    ,p_date_earned
6279                    ,p_error_message
6280                    ,p_data_element_value
6281                  );
6282      ELSIF (p_data_element_cd = 'POSTAL_CODE') THEN
6283      l_ret_val := Get_Postal_Code
6284                  ( p_assignment_id
6285                    ,p_business_group_id
6286                    ,p_date_earned
6287                    ,p_error_message
6288                    ,p_data_element_value
6289                  );
6290      ELSIF (p_data_element_cd = 'CITY') THEN
6291      l_ret_val := Get_City
6292                  ( p_assignment_id
6293                    ,p_business_group_id
6294                    ,p_date_earned
6295                    ,p_error_message
6296                    ,p_data_element_value
6297                  );
6298      ELSIF (p_data_element_cd = 'CAO_CODE') THEN
6299      l_ret_val := Get_CAO_Code
6300                  ( p_assignment_id
6301                    ,p_business_group_id
6302                    ,p_date_earned
6303                    ,p_error_message
6304                    ,p_data_element_value
6305                   );
6306      ELSIF (p_data_element_cd = 'COUNTRY_CODE') THEN
6307      l_ret_val := Get_Country_Code
6308                  ( p_assignment_id
6309                    ,p_business_group_id
6310                    ,p_date_earned
6311                    ,p_error_message
6312                    ,p_data_element_value
6313                   );
6314      ELSIF (p_data_element_cd = 'ST_DT_PTP') THEN
6315      l_ret_val := Get_Start_Date_PTP
6316                  ( p_assignment_id
6317                    ,p_business_group_id
6318                    ,p_date_earned
6319                    ,p_error_message
6320                    ,p_data_element_value
6321                   );
6322      ELSIF (p_data_element_cd = 'REASON_OF_PTP') THEN
6323      l_ret_val := Get_Reason_Of_PTP
6324                  ( p_assignment_id
6325                    ,p_business_group_id
6326                    ,p_date_earned
6327                    ,p_error_message
6328                    ,p_data_element_value
6329                   );
6330      ELSIF (p_data_element_cd = 'TERM_REASON') THEN
6331      l_ret_val := Get_Term_Reason
6332                  ( p_assignment_id
6333                    ,p_business_group_id
6334                    ,p_date_earned
6335                    ,p_error_message
6336                    ,p_data_element_value
6337                   );
6338      ELSIF (p_data_element_cd = 'END_DT_EMPLOYMENT') THEN
6339      l_ret_val := Get_End_Date_Of_Employment
6340                  ( p_assignment_id
6341                    ,p_business_group_id
6342                    ,p_date_earned
6343                    ,p_error_message
6344                    ,p_data_element_value
6345                   );
6346      ELSIF (p_data_element_cd = 'PENSION_SAL') THEN
6347      l_ret_val := Get_Pension_Salary
6348                  ( p_assignment_id
6349                    ,p_business_group_id
6350                    ,p_date_earned
6351                    ,p_error_message
6352                    ,p_data_element_value
6353                   );
6354      ELSIF (p_data_element_cd = 'IRR_PAYMNT_AMT') THEN
6355      l_ret_val := Get_Irregular_Payment_Amt
6356                  ( p_assignment_id
6357                    ,p_business_group_id
6358                    ,p_date_earned
6359                    ,p_error_message
6360                    ,p_data_element_value
6361                  );
6362      ELSIF (p_data_element_cd = 'IRR_PAYMNT_YEAR') THEN
6363      l_ret_val := Get_Irregular_Payment_Year
6364                  ( p_assignment_id
6365                    ,p_business_group_id
6366                    ,p_date_earned
6367                    ,p_error_message
6368                    ,p_data_element_value
6369                  );
6370     ELSIF (p_data_element_cd = 'HIRE_DATE_PTP') THEN
6371      l_ret_val := Get_Hire_Date_PTP
6372                  ( p_assignment_id
6373                    ,p_business_group_id
6374                    ,p_date_earned
6375                    ,p_error_message
6376                    ,p_data_element_value
6377                   );
6378     ELSIF (p_data_element_cd = 'HIRE_DATE_IWC') THEN
6379      l_ret_val := Get_Hire_Date_IWC
6380                  ( p_assignment_id
6381                    ,p_business_group_id
6382                    ,p_date_earned
6383                    ,p_error_message
6384                    ,p_data_element_value
6385                  );
6386     ELSIF (p_data_element_cd = 'PART_TIME_PERCENT') THEN
6387      l_ret_val := Get_Part_Time_Percent
6388                  ( p_assignment_id
6389                    ,p_business_group_id
6390                    ,p_date_earned
6391                    ,p_error_message
6392                    ,p_data_element_value
6393                   );
6394 
6395     ELSIF (p_data_element_cd = 'ST_DT_CHANGE_PENS_SAL') THEN
6396      l_ret_val := Get_ST_DT_Change_Pens_Sal
6397                  ( p_assignment_id
6398                    ,p_business_group_id
6399                    ,p_date_earned
6400                    ,p_error_message
6401                    ,p_data_element_value
6402                   );
6403      ELSIF (p_data_element_cd = 'ST_DT_CHG_PART_TIME_PERCENT') THEN
6404      l_ret_val := Get_ST_DT_Chg_Part_Time_Per
6405                  ( p_assignment_id
6406                    ,p_business_group_id
6407                    ,p_date_earned
6408                    ,p_error_message
6409                    ,p_data_element_value
6410                  );
6411 
6412      ELSIF (p_data_element_cd = 'FINAL_PART_TIME_PERCENTAGE') THEN
6413      l_ret_val := Get_Final_Part_Time_Val
6414                  ( p_assignment_id
6415                    ,p_business_group_id
6416                    ,p_date_earned
6417                    ,p_error_message
6418                    ,p_data_element_value
6419                   );
6420        p_data_element_value := rpad(lpad(p_data_element_value,3,'0'),6,'0');
6421 
6422      ELSIF (p_data_element_cd = 'INCIDENTAL_WORKER') THEN
6423      l_ret_val := Get_Incidental_Worker
6424                  ( p_assignment_id
6425                    ,p_business_group_id
6426                    ,p_date_earned
6427                    ,p_error_message
6428                    ,p_data_element_value
6429                   );
6430      ELSIF (p_data_element_cd = 'FINAL_PTF_YEAR') THEN
6431      l_ret_val := Get_Final_PTF_Year
6432                  ( p_assignment_id
6433                    ,p_business_group_id
6434                    ,p_date_earned
6435                    ,p_error_message
6436                    ,p_data_element_value
6437                   );
6438 
6439      ELSIF (p_data_element_cd = 'PROCESS_MULTIPLE_ASSIGS') THEN
6440      l_ret_val := Process_Addl_Assigs
6441                  (  p_assignment_id
6442                    ,p_business_group_id
6443                    ,p_date_earned
6444                    ,p_error_message
6445                  );
6446      ELSIF (p_data_element_cd = 'MULTIPLE_RECORDS') THEN
6447      l_ret_val := Process_Mult_Records
6448                  (  p_assignment_id
6449                    ,p_business_group_id
6450                    ,p_date_earned
6451                    ,p_error_message
6452                  );
6453      ELSIF (p_data_element_cd = 'HIDE_ORG_ID') THEN
6454      l_ret_val := Org_Id_DataElement
6455                           (p_assignment_id
6456                            ,p_business_group_id
6457                            ,p_date_earned
6458                            ,p_error_message
6459                            ,p_data_element_value
6460                            );
6461      ELSIF (p_data_element_cd = 'SORT_ID_010') THEN
6462 
6463      l_ret_val := Sort_Id_Generator
6464                   ( p_assignment_id
6465                     ,p_business_group_id
6466                     ,p_date_earned
6467                     ,'010'
6468                     ,p_error_message
6469                     ,p_data_element_value
6470                    );
6471      ELSIF (p_data_element_cd = 'SORT_ID_020') THEN
6472 
6473      l_ret_val := Sort_Id_Generator
6474                   ( p_assignment_id
6475                     ,p_business_group_id
6476                     ,p_date_earned
6477                     ,'020'
6478                     ,p_error_message
6479                     ,p_data_element_value
6480                   );
6481      ELSIF (p_data_element_cd = 'SORT_ID_030') THEN
6482      l_ret_val := Sort_Id_Generator
6483                   ( p_assignment_id
6484                    ,p_business_group_id
6485                    ,p_date_earned
6486                    ,'030'
6487                    ,p_error_message
6488                    ,p_data_element_value
6489                   );
6490      ELSIF (p_data_element_cd = 'SORT_ID_040') THEN
6491      l_ret_val := Sort_Id_Generator
6492                   ( p_assignment_id
6493                    ,p_business_group_id
6494                    ,p_date_earned
6495                    ,'040'
6496                    ,p_error_message
6497                    ,p_data_element_value
6498                    );
6499      ELSIF (p_data_element_cd = 'SORT_ID_060') THEN
6500      l_ret_val := Sort_Id_Generator
6501                   ( p_assignment_id
6502                     ,p_business_group_id
6503                     ,p_date_earned
6504                     ,'060'
6505                     ,p_error_message
6506                     ,p_data_element_value
6507                    );
6508      ELSIF (p_data_element_cd = 'SORT_ID_070') THEN
6509      l_ret_val := Sort_Id_Generator
6510                   ( p_assignment_id
6511                    ,p_business_group_id
6512                    ,p_date_earned
6513                    ,'070'
6514                    ,p_error_message
6515                    ,p_data_element_value
6516                   );
6517      ELSIF (p_data_element_cd = 'SORT_ID_080') THEN
6518      l_ret_val := Sort_Id_Generator
6519                   ( p_assignment_id
6520                    ,p_business_group_id
6521                    ,p_date_earned
6522                    ,'080'
6523                    ,p_error_message
6524                    ,p_data_element_value
6525                   );
6526      ELSIF (p_data_element_cd = 'SORT_ID_081') THEN
6527      l_ret_val := Sort_Id_Generator
6528                   ( p_assignment_id
6529                    ,p_business_group_id
6530                    ,p_date_earned
6531                    ,'081'
6532                    ,p_error_message
6533                    ,p_data_element_value
6534                   );
6535      END IF;
6536      p_data_element_value := Upper(p_data_element_value);
6537      l_ret_val:=0;
6538      RETURN l_ret_val;
6539 
6540 EXCEPTION
6541    WHEN Others THEN
6542    p_error_message :='SQL-ERRM :'||SQLERRM;
6543    Hr_Utility.set_location('..'||p_error_message,85);
6544    Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6545    RETURN l_ret_val;
6546 END PQP_NL_GET_DATA_ELEMENT_VALUE;
6547 
6548 
6549 --============================================================================
6550 --This is used to decide the Record010 hide  or show
6551 --============================================================================
6552 FUNCTION Record010_Display_Criteria
6553          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6554          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6555          ,p_effective_date     IN  Date
6556          ,p_error_message      OUT NOCOPY Varchar2
6557          ,p_data_element_value OUT NOCOPY Varchar2
6558           ) RETURN Number IS
6559 
6560 -- The first payroll date is considered as the hire date so that
6561 --late hire scenarios etc. are met
6562 CURSOR csr_chk_new_hire (c_assignment_id      IN Number
6563                         ) IS
6564 SELECT MIN(ppa.effective_date)
6565 FROM  pay_payroll_actions ppa,
6566       pay_assignment_actions paa
6567 WHERE paa.assignment_id = c_assignment_id
6568 AND   paa.payroll_action_id = ppa.payroll_action_id
6569 AND   paa.action_status = 'C'
6570 AND   ppa.action_type IN ('R', 'Q', 'I', 'B', 'V');
6571 
6572 
6573 l_person_id          per_all_people_f.person_id%TYPE;
6574 l_proc_name          VARCHAR2(150) := g_proc_name ||'Record010_Display_Criteria';
6575 l_return_value       NUMBER :=0;
6576 l_new_asg            VARCHAR2(1);
6577 l_prev_pggm_er_num   NUMBER;
6578 l_curr_pggm_er_num   NUMBER;
6579 l_prev_pggm_ee_num   NUMBER;
6580 l_curr_pggm_ee_num   NUMBER;
6581 l_data_element_value VARCHAR2(10);
6582 l_org_id             NUMBER;
6583 l_term_date          DATE;
6584 l_chg_eff_date       DATE;
6585 l_hire_date          DATE;
6586 
6587 Begin
6588 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
6589 --For yearly report hide this record
6590 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y' THEN
6591  p_data_element_value := 'N';
6592  RETURN 0;
6593 ELSE
6594      OPEN csr_chk_new_hire(p_assignment_id);
6595      FETCH csr_chk_new_hire INTO l_hire_date;
6596      IF csr_chk_new_hire%FOUND AND
6597         (l_hire_date >= g_extract_params (p_business_group_id).extract_start_date) AND
6598         (l_hire_date <= g_extract_params (p_business_group_id).extract_end_date) THEN
6599         p_data_element_value := 'Y';
6600      ELSE
6601         p_data_element_value := 'N';
6602      END IF;
6603      CLOSE csr_chk_new_hire;
6604 END IF;
6605    Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6606    l_return_value := 0;
6607 RETURN l_return_value;
6608 EXCEPTION
6609    WHEN Others THEN
6610     p_error_message :='SQL-ERRM :'||SQLERRM;
6611     p_data_element_value := 'N';
6612     Hr_Utility.set_location('..'||p_error_message,85);
6613     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6614     RETURN l_return_value;
6615 END Record010_Display_Criteria ;
6616 
6617 --============================================================================
6618 --This is used to decide the Record_020 hide  or show
6619 --============================================================================
6620 FUNCTION Record020_Display_Criteria
6621          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6622          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6623          ,p_effective_date     IN  Date
6624          ,p_error_message      OUT NOCOPY Varchar2
6625         ,p_data_element_value  OUT NOCOPY Varchar2
6626           ) RETURN Number IS
6627 
6628 --Cursor to check termination of secondary assignment
6629 CURSOR csr_chk_terminate_sec_asg ( c_assignment_id      IN Number
6630                              ,c_business_group_id IN Number
6631                                 ) IS
6632 SELECT min(paa.effective_start_date)
6633   FROM per_all_assignments_f paa,
6634        per_assignment_status_types past
6635  WHERE paa.assignment_id           = c_assignment_id
6636    AND paa.business_group_id       = c_business_group_id
6637    AND paa.assignment_status_type_id=past.assignment_status_type_id
6638    AND past.per_system_status ='TERM_ASSIGN';
6639 
6640    --Cursor to check termiantion of primary assignment
6641 CURSOR csr_chk_terminate_pri_asg ( c_assignment_id      IN Number
6642                              ,c_business_group_id IN Number
6643                                 ) IS
6644 SELECT max(paa.effective_end_date)
6645   FROM per_all_assignments_f paa
6646  WHERE paa.assignment_id           = c_assignment_id
6647    AND paa.business_group_id       = c_business_group_id;
6648 
6649 l_person_id       per_all_people_f.person_id%TYPE;
6650 l_proc_name       Varchar2(150) := g_proc_name ||'Record020_Display_Criteria';
6651 l_return_value    Number :=0;
6652 l_term_asg        Varchar2(1);
6653 l_rev_asg_dt      DATE;
6654 l_term_asg_dt     DATE;
6655 l_chk_term_asg    NUMBER:=0;
6656 l_org_id          NUMBER;
6657 l_asg_end_date    DATE;
6658 l_term_sec_asg_dt     DATE;
6659 l_term_pri_asg_dt     DATE;
6660 l_already_terminated   NUMBER := 0;
6661 
6662 Begin
6663 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
6664 --For yearly report hide this record
6665 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y' THEN
6666  p_data_element_value := 'N';
6667  RETURN 0;
6668 ELSE
6669   --Assignment termination logic
6670    OPEN csr_chk_terminate_sec_asg (p_assignment_id, p_business_group_id);
6671    FETCH csr_chk_terminate_sec_asg INTO l_term_sec_asg_dt;
6672    IF csr_chk_terminate_sec_asg%FOUND THEN
6673       IF(l_term_sec_asg_dt >= g_extract_params(p_business_group_id).extract_start_date + 1) AND
6674         (l_term_sec_asg_dt <= g_extract_params(p_business_group_id).extract_end_date + 1) THEN
6675         p_data_element_value := 'Y';
6676       ELSE
6677         p_data_element_value := 'N';
6678         l_already_terminated := 1;
6679       END IF;
6680     ELSE
6681      p_data_element_value := 'N';
6682     END IF;
6683     CLOSE csr_chk_terminate_sec_asg;
6684 
6685    --End of Employment logic
6686    IF p_data_element_value <> 'Y' THEN
6687      OPEN csr_chk_terminate_pri_asg (p_assignment_id, p_business_group_id);
6688      FETCH csr_chk_terminate_pri_asg INTO l_term_pri_asg_dt;
6689      IF (l_term_pri_asg_dt >= g_extract_params(p_business_group_id).extract_start_date) AND
6690          (l_term_pri_asg_dt <= g_extract_params(p_business_group_id).extract_end_date) AND
6691          l_already_terminated <> 1 THEN
6692        p_data_element_value := 'Y';
6693      ELSE
6694        p_data_element_value := 'N';
6695      END IF;
6696      CLOSE csr_chk_terminate_pri_asg;
6697    END IF;
6698 END IF;--type of report
6699    Hr_Utility.set_location('Leaving:   '||l_proc_name, 50);
6700    l_return_value := 0;
6701 
6702 RETURN l_return_value;
6703 EXCEPTION
6704    WHEN Others THEN
6705     p_error_message :='SQL-ERRM :'||SQLERRM;
6706     p_data_element_value := 'N';
6707     Hr_Utility.set_location('..'||p_error_message,85);
6708     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6709     RETURN l_return_value;
6710 END Record020_Display_Criteria;
6711 
6712 --============================================================================
6713 --This is used to decide the Record_030 hide  or show
6714 --============================================================================
6715 FUNCTION Record030_Display_Criteria
6716          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6717          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6718          ,p_effective_date     IN  Date
6719          ,p_error_message      OUT NOCOPY Varchar2
6720          ,p_data_element_value OUT NOCOPY Varchar2
6721           ) RETURN Number IS
6722 
6723 --cursor to check for termination of primary assignment
6724 CURSOR csr_chk_terminate_asg (c_assignment_id      IN Number
6725                               ,c_business_group_id IN Number
6726                              ) IS
6727 SELECT chg_eff_dt
6728   FROM ben_ext_chg_evt_log
6729  WHERE person_id         = g_person_id
6730    AND business_group_id = c_business_group_id
6731    AND chg_evt_cd = 'AAT'
6732    AND (chg_eff_dt BETWEEN  g_extract_params (c_business_group_id).extract_start_date
6733                        AND g_extract_params (c_business_group_id).extract_end_date)
6734  ORDER BY ext_chg_evt_log_id desc;
6735 
6736 --Cursor to check termiantion of secondary assignment
6737 CURSOR csr_chk_terminate_sec_asg (c_assignment_id      IN Number
6738                                  ,c_business_group_id IN Number
6739                                 ) IS
6740 SELECT 'x'
6741   FROM per_all_assignments_f paa,
6742        per_assignment_status_types past
6743 WHERE  paa.assignment_id           = c_assignment_id
6744    AND paa.business_group_id       = c_business_group_id
6745    AND paa.assignment_status_type_id=past.assignment_status_type_id
6746    AND past.per_system_status ='TERM_ASSIGN'
6747    AND ( paa.effective_start_date
6748     BETWEEN  g_extract_params (c_business_group_id).extract_start_date + 1
6749              AND g_extract_params (c_business_group_id).extract_end_date + 1);
6750 
6751 --Cursor to check termiantion of secondary assignment
6752 CURSOR csr_get_asg_end_date (c_assignment_id      IN Number
6753                              ,c_business_group_id IN Number
6754                              ) IS
6755 SELECT paa.effective_end_date
6756   FROM per_all_assignments_f paa,
6757        per_assignment_status_types past
6758 WHERE  paa.assignment_id           = c_assignment_id
6759    AND paa.business_group_id       = c_business_group_id
6760    AND paa.assignment_status_type_id=past.assignment_status_type_id
6761    AND past.per_system_status = 'TERM_ASSIGN';
6762 
6763 l_person_id       per_all_people_f.person_id%TYPE;
6764 l_proc_name       Varchar2(150) := g_proc_name ||'Record030_Display_Criteria';
6765 l_return_value    Number :=0;
6766 l_term_asg        Varchar2(1);
6767 l_irr_paymnt      NUMBER:=0;
6768 l_year            NUMBER:=0;
6769 l_term_asg_dt     DATE;
6770 l_rev_asg_dt      DATE;
6771 l_start_date_PTP  DATE;
6772 l_start_date      DATE;
6773 l_data_element_value VARCHAR2(10);
6774 l_chk_term_asg    NUMBER:=0;
6775 l_asg_end_date    DATE;
6776 l_period_start_date DATE;
6777 Begin
6778 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
6779 --For yearly report hide this record
6780 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y' THEN
6781  p_data_element_value := 'N';
6782  RETURN 0;
6783 ELSE
6784     --Get End date of assignment
6785     OPEN csr_get_asg_end_date(p_assignment_id
6786                              ,p_business_group_id);
6787     FETCH csr_get_asg_end_date INTO l_asg_end_date;
6788     CLOSE csr_get_asg_end_date;
6789     --If assignment is already ended then do not process further
6790     IF NVL(l_asg_end_date,to_Date('47121231','YYYYMMDD')-1) < g_extract_params (p_business_group_id).extract_start_date THEN
6791         p_data_element_value := 'N';
6792         Hr_Utility.set_location('Leaving:   '||l_proc_name, 30);
6793         RETURN 0;
6794     END IF;
6795     ----Check for irregular payment balance
6796     --Get Participation start date
6797         l_return_value:=Get_Start_Date_PTP(p_assignment_id
6798                                           ,p_business_group_id
6799                                           ,p_effective_date
6800                                           ,p_error_message
6801                                           ,l_data_element_value
6802                                            );
6803 
6804         l_start_date_PTP:=to_date(l_data_element_value,'YYYYMMDD');
6805 
6806 
6807         l_year:=Get_year(p_assignment_id
6808                        ,g_extract_params(p_business_group_id).extract_start_date
6809 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
6810 
6811 	--Get the period start and end dates
6812         OPEN  c_get_period_start_date(l_year
6813 	                              ,p_assignment_id
6814 				      ,p_effective_date);
6815         FETCH c_get_period_start_date INTO l_period_start_date;
6816         CLOSE c_get_period_start_date;
6817 
6818         l_start_date:=l_period_start_date;
6819 
6820         IF l_start_date < l_start_date_PTP THEN
6821              l_start_date:=l_start_date_PTP;
6822         END IF;
6823 
6824         --Get Irregular amount paid to employee
6825         l_irr_paymnt :=Get_Balance_Value(p_assignment_id
6826                                        ,p_business_group_id
6827                                        ,'PGGM Pensions Irregular Payments'
6828                                        ,'Assignment Period To Date'
6829                                        ,l_start_date
6830                                        ,g_extract_params(p_business_group_id).extract_end_date
6831                                        );
6832 
6833           IF l_irr_paymnt <= 0   THEN
6834               p_data_element_value := 'N';
6835               Hr_Utility.set_location('Leaving:   '||l_proc_name, 35);
6836              Return 0;
6837           END IF;
6838 
6839           l_chk_term_asg:=chk_term_asg_eff
6840                             (  p_assignment_id
6841                               ,p_business_group_id
6842                               ,p_effective_date
6843                             );
6844     IF  l_chk_term_asg = 1 THEN
6845        --Check whether person has end of employment event
6846        OPEN csr_chk_terminate_asg(p_assignment_id,p_business_group_id);
6847        FETCH csr_chk_terminate_asg INTO l_term_asg_dt;
6848 
6849         IF csr_chk_terminate_asg%FOUND THEN
6850           CLOSE csr_chk_terminate_asg;
6851           p_data_element_value := 'Y';
6852         ELSE  ---csr_chk_terminate_asg not found
6853           CLOSE csr_chk_terminate_asg;
6854           p_data_element_value := 'N';
6855         END IF;  --END of csr_chk_terminate_asg
6856     ELSE  --l_chk_term_asg is 0
6857 
6858 	--Check only for secondary assignment
6859         OPEN csr_chk_primary_asg(p_assignment_id, p_effective_date);
6860         FETCH csr_chk_primary_asg INTO l_term_asg;
6861         IF csr_chk_primary_asg%NOTFOUND THEN
6862            -- Check for termiantion of secondary assignment
6863            OPEN csr_chk_terminate_sec_asg(p_assignment_id,p_business_group_id);
6864            FETCH csr_chk_terminate_sec_asg INTO l_term_asg;
6865 
6866            IF csr_chk_terminate_sec_asg%FOUND THEN
6867                 p_data_element_value := 'Y';
6868            ELSE
6869                 p_data_element_value := 'N';
6870            END IF;
6871 
6872            CLOSE csr_chk_terminate_sec_asg;
6873          ELSE --primary assignment
6874                   p_data_element_value := 'N';
6875          END IF;
6876         CLOSE csr_chk_primary_asg;
6877      END IF; -- End of End of employment check
6878 END IF;--Type of report
6879 
6880  Hr_Utility.set_location('Leaving:   '||l_proc_name, 5);
6881  l_return_value := 0;
6882 
6883 RETURN l_return_value;
6884 EXCEPTION
6885    WHEN Others THEN
6886     p_error_message :='SQL-ERRM :'||SQLERRM;
6887     p_data_element_value := 'N';
6888     Hr_Utility.set_location('..'||p_error_message,85);
6889     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
6890     RETURN l_return_value;
6891 END Record030_Display_Criteria;
6892 --============================================================================
6893 --This is used to decide the Record_040 hide  or show
6894 --============================================================================
6895 FUNCTION Record040_Display_Criteria
6896          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
6897          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
6898          ,p_effective_date     IN  Date
6899          ,p_error_message      OUT NOCOPY Varchar2
6900          ,p_data_element_value OUT NOCOPY Varchar2
6901        ) RETURN Number IS
6902 
6903 
6904 
6905 --cursor to check for change in address.
6906 CURSOR csr_chk_chg_address(c_business_group_id  IN Number
6907                            ) IS
6908 SELECT chg_eff_dt
6909   FROM ben_ext_chg_evt_log
6910  WHERE person_id         = g_person_id
6911    AND business_group_id = c_business_group_id
6912    AND (chg_evt_cd = 'COCN' ) --OR (chg_evt_cd = 'APA')
6913    AND ( chg_eff_dt between g_extract_params(c_business_group_id).extract_start_date
6914                   and g_extract_params(c_business_group_id).extract_end_date )
6915    ORDER by ext_chg_evt_log_id desc;
6916 
6917 --cursor to check for change in foreign address.
6918 CURSOR csr_chk_chg_foreign_address(c_business_group_id IN Number
6919    ) IS
6920  SELECT chg_eff_dt
6921   FROM ben_ext_chg_evt_log
6922 
6923  WHERE person_id         = g_person_id
6924    AND business_group_id = c_business_group_id
6925    AND  ( chg_evt_cd = 'COPR' or
6926            chg_evt_cd = 'COPC' or chg_evt_cd = 'CORS' OR chg_evt_cd = 'APA' )
6927    AND ( chg_eff_dt between g_extract_params(c_business_group_id).extract_start_date
6928                   and g_extract_params(c_business_group_id).extract_end_date )
6929    ORDER by ext_chg_evt_log_id desc;
6930 
6931 --cursor to check for change in address.
6932 CURSOR csr_chk_chg_COCN(c_business_group_id  IN Number
6933                           ,c_effective_date     IN DATE
6934                         ) IS
6935  SELECT hrl1.lookup_code
6936   FROM ben_ext_chg_evt_log,
6937        hr_lookups hrl1
6938  WHERE person_id         = g_person_id
6939    AND business_group_id = c_business_group_id
6940    AND chg_evt_cd = 'COCN'
6941    AND  Substr(Nvl(old_val1,'-1'),0,7)=hrl1.meaning
6942    AND hrl1.LOOKUP_TYPE='PQP_NL_STUCON_CODE_MAPPING'
6943    AND (chg_eff_dt between  g_extract_params(c_business_group_id).extract_start_date
6944                   AND g_extract_params(c_business_group_id).extract_start_date)
6945    AND chg_eff_dt >=
6946    ( Select min(chg_eff_dt) FROM ben_ext_chg_evt_log
6947         WHERE person_id         = g_person_id
6948      AND business_group_id = c_business_group_id
6949      AND chg_evt_cd = 'COCN'
6950      AND chg_eff_dt >=c_effective_date
6951    )
6952    ORDER by ext_chg_evt_log_id desc;
6953 
6954 
6955 
6956 --Cursor to fetch the old country code from
6957 --the ben_ext_chg_evt_log table in case a change has been made
6958 CURSOR c_get_old_cc( c_effective_date IN DATE) IS
6959 SELECT to_number(hrl1.lookup_code)
6960   FROM ben_ext_chg_evt_log,
6961        hr_lookups hrl1
6962 WHERE  chg_evt_cd  = 'COCN'
6963   AND  ( chg_eff_dt between g_extract_params(p_business_group_id).extract_start_date
6964                   and g_extract_params(p_business_group_id).extract_end_date )
6965   AND  Substr(Nvl(old_val1,'-1'),0,7)=hrl1.meaning
6966   AND  hrl1.lookup_type='PQP_NL_STUCON_CODE_MAPPING'
6967   AND  person_id = g_person_id
6968   ORDER by ext_chg_evt_log_id desc;
6969 
6970 --Cursor to fetch the new country code from
6971 --the ben_ext_chg_evt_log table in case a change has been made
6972 CURSOR c_get_new_cc(c_effective_date IN DATE) IS
6973 SELECT to_number(hrl1.lookup_code)
6974   FROM ben_ext_chg_evt_log,
6975        hr_lookups hrl1
6976 WHERE  chg_evt_cd = 'COCN'
6977   AND  ( chg_eff_dt between g_extract_params(p_business_group_id).extract_start_date
6978                   and g_extract_params(p_business_group_id).extract_end_date )
6979   AND  Substr(Nvl(new_val1,'-1'),0,7)=hrl1.meaning
6980   AND  hrl1.lookup_type='PQP_NL_STUCON_CODE_MAPPING'
6981   AND  person_id = g_person_id
6982   ORDER by ext_chg_evt_log_id desc;
6983 
6984 l_old_country_code Number;
6985 l_new_country_code Number;
6986 l_person_id       per_all_people_f.person_id%TYPE;
6987 l_proc_name       Varchar2(150) := g_proc_name ||'Record040_Display_Criteria';
6988 l_return_value    Number :=0;
6989 l_chg_addr        Varchar2(10);
6990 l_eff_date        DATE;
6991 l_country_code    varchar2(5);
6992 l_check           varchar2(10);
6993 Begin
6994  Hr_Utility.set_location('Entering:   '||l_proc_name, 5);
6995 --For yearly report hide this record
6996 IF (NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y') THEN
6997  p_data_element_value := 'N';
6998  RETURN 0;
6999 ELSE
7000 --Checking the ben event log  to report if the record is for a change of country code
7001 --initialize
7002 p_data_element_value := 'N';
7003  OPEN csr_chk_primary_asg (p_assignment_id, p_effective_date);
7004  FETCH csr_chk_primary_asg INTO l_check;
7005  IF csr_chk_primary_asg%FOUND THEN
7006  CLOSE csr_chk_primary_asg;
7007 
7008    OPEN csr_chk_chg_address(p_business_group_id);
7009    FETCH csr_chk_chg_address INTO l_chg_addr;
7010 
7011    IF csr_chk_chg_address%FOUND THEN
7012         CLOSE csr_chk_chg_address;
7013         Hr_Utility.set_location('Inside csr_chk_chg_address', 15);
7014         Open c_get_old_cc(l_eff_date);
7015         FETCH  c_get_old_cc INTO l_old_country_code;
7016         CLOSE c_get_old_cc;
7017 
7018         Hr_Utility.set_location('l_old_country_code'||l_old_country_code, 15);
7019 
7020          Open c_get_new_cc(l_eff_date);
7021          FETCH  c_get_new_cc INTO l_new_country_code;
7022          CLOSE c_get_new_cc;
7023 
7024 	Hr_Utility.set_location('l_new_country_code'||l_new_country_code, 15);
7025 
7026         IF (l_old_country_code <> 6030 and l_new_country_code = 6030 ) or
7027            (l_old_country_code = 6030 and l_new_country_code <> 6030 ) or
7028            (l_old_country_code <> 6030 and l_new_country_code <> 6030 )
7029         THEN
7030           p_data_element_value :='Y';
7031           Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7032           l_return_value := 0;
7033          RETURN l_return_value;
7034          END IF;
7035 
7036       ELSE
7037         CLOSE csr_chk_chg_address;
7038       END IF;
7039 
7040 
7041      --Check if there is change in foreign address(Non NL)
7042      OPEN csr_chk_chg_foreign_address(p_business_group_id);
7043      FETCH csr_chk_chg_foreign_address INTO l_eff_date;
7044 
7045      IF csr_chk_chg_foreign_address%FOUND THEN
7046 
7047 
7048       l_return_value:=Get_Country_Code (p_assignment_id
7049                                         ,p_business_group_id
7050                                         ,p_effective_date
7051                                         ,p_error_message
7052                                         ,l_country_code);
7053       Hr_Utility.set_location('l_country_code:   '||l_country_code ||'for'||g_person_id, 60);
7054          IF (to_number(l_country_code) <> 6030) THEN
7055            p_data_element_value :='Y';
7056          END IF;
7057       END IF;
7058       CLOSE csr_chk_chg_foreign_address;
7059 
7060    ELSE  --csr_chk_primary_asg not found
7061    CLOSE csr_chk_primary_asg;
7062    p_data_element_value :='N';
7063 
7064   END IF;
7065 
7066 End IF;
7067    Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7068    l_return_value := 0;
7069 
7070 RETURN l_return_value;
7071 EXCEPTION
7072    WHEN Others THEN
7073     p_error_message :='SQL-ERRM :'||SQLERRM;
7074     Hr_Utility.set_location('..'||p_error_message,85);
7075     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7076     l_return_value:=1;
7077     RETURN l_return_value;
7078 END Record040_Display_Criteria;
7079 --============================================================================
7080 --This is used to decide the Record_060 hide  or show
7081 --============================================================================
7082 FUNCTION Record060_Display_Criteria
7083          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
7084          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
7085          ,p_effective_date     IN  Date
7086          ,p_error_message      OUT NOCOPY Varchar2
7087  ,p_data_element_value OUT NOCOPY Varchar2
7088           )
7089 RETURN Number IS
7090 Cursor csr_retro_pggm_gen_info_entry IS
7091 Select 'x'
7092 from pay_element_entries_f  pee,
7093      pay_input_values_f    piv,
7094      pay_element_types_f   pet,
7095      pay_element_entry_values_f peev
7096 where
7097 (    pet.element_name ='Retro PGGM Pensions General Information'
7098  OR  pet.element_name ='Retro PGGM Pensions General Information Previous Year')
7099  AND piv.name = 'Annual Pension Salary'
7100  AND piv.element_type_id=pet.element_type_id
7101  AND pee.assignment_id=p_assignment_id
7102  AND pee.element_type_id =pet.element_type_id
7103  AND  (p_effective_date between pee.effective_start_date
7104                 AND pee.effective_end_date )
7105  AND peev.element_entry_id=pee.element_entry_id
7106  AND peev.input_value_id=piv.input_value_id
7107  AND ( p_effective_date between peev.effective_start_date
7108                 AND peev.effective_end_date )
7109  AND peev.screen_entry_value is not null;
7110 
7111 
7112 CURSOR csr_chk_active_asg(c_asg_id NUMBER,bg_id NUMBER,eff_date DATE) IS
7113 SELECT 'x'
7114   FROM per_all_assignments_f paa,
7115        per_assignment_status_types past
7116 WHERE  paa.assignment_id           = c_asg_id
7117    AND paa.business_group_id       = bg_id
7118    AND paa.assignment_status_type_id=past.assignment_status_type_id
7119    AND past.per_system_status = 'ACTIVE_ASSIGN'
7120    AND (eff_date between paa.effective_start_date and paa.effective_end_date);
7121 
7122 CURSOR c_get_period_num(c_extract_start_date IN DATE
7123                        ,c_assignment_id IN NUMBER
7124 		       ,c_date_earned IN DATE
7125 ) IS
7126 SELECT NVL(period_num,0)
7127 FROM  per_all_assignments_f PAA
7128      ,per_time_periods TPERIOD
7129 WHERE
7130 PAA.assignment_id = c_assignment_id
7131 AND TPERIOD.payroll_id = PAA.payroll_id
7132 AND c_date_earned between PAA.effective_start_date and PAA.effective_end_date
7133 AND c_extract_start_date between TPERIOD.start_date and TPERIOD.end_date;
7134 
7135  l_return_value NUMBER :=0;
7136 l_proc_name    Varchar2(150) := g_proc_name ||'Record060_Display_Criteria';
7137 l_chk_entry     varchar2(1);
7138 l_year          NUMBER;
7139 l_mon           NUMBER;
7140 l_eff_date      DATE;
7141 l_period_start_date DATE;
7142 
7143 Begin
7144 --hr_utility.trace_on(null,'SS');
7145 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
7146 --If yearly report then do not show this record
7147 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y' THEN
7148   p_data_element_value := 'N';
7149 ELSE
7150  --Check whether assignment is active or not
7151 
7152 
7153  l_year:=Get_year(p_assignment_id
7154                        ,g_extract_params(p_business_group_id).extract_start_date
7155 	    	       ,g_extract_params(p_business_group_id).extract_end_date);
7156  Hr_Utility.set_location('l_year :   '||l_year, 15);
7157  --Get the period number of payroll from the extract start date
7158  OPEN c_get_period_num(g_extract_params(p_business_group_id).extract_start_date,
7159                        p_assignment_id
7160 		       ,p_effective_date);
7161  FETCH c_get_period_num INTO l_mon;
7162  CLOSE c_get_period_num;
7163   Hr_Utility.set_location('l_mon :   '||l_mon, 16);
7164  --Get the period start date
7165   OPEN  c_get_period_start_date(l_year
7166                                 ,p_assignment_id
7167 				,p_effective_date);
7168   FETCH c_get_period_start_date INTO l_period_start_date;
7169   CLOSE c_get_period_start_date;
7170 
7171  l_eff_date:=l_period_start_date;
7172     Hr_Utility.set_location('l_eff_date :   '||l_eff_date, 17);
7173    --OPEN csr_chk_active_asg(p_assignment_id,p_business_group_id,l_eff_date);
7174    OPEN csr_chk_active_asg(p_assignment_id,p_business_group_id,p_effective_date);
7175    FETCH csr_chk_active_asg INTO l_chk_entry;
7176    --For First month(pay period) of the year only
7177    IF csr_chk_active_asg%FOUND AND l_mon=1 THEN
7178       p_data_element_value := 'Y';
7179       CLOSE csr_chk_active_asg;
7180       Return 0;
7181    ELSE
7182       p_data_element_value := 'N';
7183    END IF;
7184    CLOSE csr_chk_active_asg;
7185 
7186 
7187   OPEN csr_retro_pggm_gen_info_entry;
7188   FETCH csr_retro_pggm_gen_info_entry  INTO l_chk_entry;
7189    IF csr_retro_pggm_gen_info_entry%FOUND THEN
7190    p_data_element_value := 'Y';
7191    ElSE
7192    p_data_element_value := 'N';
7193    End IF;
7194    CLOSE csr_retro_pggm_gen_info_entry ;
7195 END IF;
7196 l_return_value:=0;
7197 Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7198 -- Hr_Utility.trace_off;
7199 RETURN l_return_value;
7200 EXCEPTION
7201    WHEN Others THEN
7202     p_error_message :='SQL-ERRM :'||SQLERRM;
7203     p_data_element_value := 'N';
7204     Hr_Utility.set_location('..'||p_error_message,85);
7205     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7206     l_return_value:=1;
7207     RETURN l_return_value;
7208 END Record060_Display_Criteria;
7209 --============================================================================
7210 --This is used to decide the Record_070 hide  or show
7211 --============================================================================
7212 FUNCTION Record070_Display_Criteria
7213          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
7214          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
7215          ,p_effective_date     IN  DATE
7216          ,p_error_message      OUT NOCOPY Varchar2
7217  ,p_data_element_value OUT NOCOPY Varchar2
7218           ) RETURN Number IS
7219 
7220 CURSOR csr_chk_active_asg(c_asg_id NUMBER,bg_id NUMBER,eff_date DATE) IS
7221 SELECT 'x'
7222   FROM per_all_assignments_f paa,
7223        per_assignment_status_types past
7224 WHERE  paa.assignment_id           = c_asg_id
7225    AND paa.business_group_id       = bg_id
7226    AND paa.assignment_status_type_id=past.assignment_status_type_id
7227    AND past.per_system_status ='ACTIVE_ASSIGN'
7228    AND (eff_date between paa.effective_start_date and paa.effective_end_date);
7229 
7230 CURSOR csr_chk_active_asg_period(c_asg_id NUMBER,bg_id NUMBER) IS
7231 SELECT 'x'
7232   FROM per_all_assignments_f paa,
7233        per_assignment_status_types past
7234 WHERE  paa.assignment_id           = c_asg_id
7235    AND paa.business_group_id       = bg_id
7236    AND paa.assignment_status_type_id=past.assignment_status_type_id
7237    AND past.per_system_status ='ACTIVE_ASSIGN'
7238    AND (paa.effective_start_date between g_extract_params(bg_id).extract_start_date
7239           and g_extract_params(bg_id).extract_end_date );
7240 
7241 l_return_value NUMBER :=-1;
7242 l_proc_name    Varchar2(150) := g_proc_name ||'Record070_Display_Criteria';
7243 l_irr_paymnt    Number:=0;
7244 l_year          Number:=0;
7245 l_chk           varchar2(1);
7246 l_period_start_date DATE;
7247 l_period_end_date DATE;
7248 
7249 Begin
7250 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
7251 --If monthly report then hide this record
7252 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'M' THEN
7253  p_data_element_value := 'N';
7254  RETURN 0;
7255 ELSE
7256 
7257    --Check whether assignment is active or not
7258    OPEN csr_chk_active_asg(p_assignment_id,p_business_group_id,g_extract_params(p_business_group_id).extract_start_date);
7259    FETCH csr_chk_active_asg INTO l_chk;
7260    IF csr_chk_active_asg%FOUND THEN
7261       CLOSE csr_chk_active_asg;
7262       p_data_element_value := 'Y';
7263    ELSE
7264      CLOSE csr_chk_active_asg;
7265 
7266      OPEN csr_chk_active_asg_period(p_assignment_id,p_business_group_id);
7267      FETCH csr_chk_active_asg_period INTO l_chk;
7268      IF csr_chk_active_asg_period%FOUND THEN
7269          CLOSE csr_chk_active_asg_period;
7270          p_data_element_value := 'Y';
7271      ELSE
7272         CLOSE csr_chk_active_asg_period;
7273         p_data_element_value := 'N';
7274         Hr_Utility.set_location('Leaving:   '||l_proc_name, 35);
7275       RETURN 0;
7276      END IF;
7277    END IF;
7278 
7279 
7280   l_year:=Get_year(p_assignment_id
7281                    ,g_extract_params(p_business_group_id).extract_start_date
7282 	    	   ,g_extract_params(p_business_group_id).extract_end_date);
7283 
7284   Hr_Utility.set_location('l_year  '||l_year, 25);
7285   --Get the period start and end dates
7286   OPEN  c_get_period_start_date(l_year
7287                                 ,p_assignment_id
7288 				,p_effective_date);
7289   FETCH c_get_period_start_date INTO l_period_start_date;
7290   CLOSE c_get_period_start_date;
7291 
7292   OPEN  c_get_period_end_date(l_year
7293                               ,p_assignment_id
7294 			      ,p_effective_date);
7295   FETCH c_get_period_end_date INTO l_period_end_date;
7296   CLOSE c_get_period_end_date;
7297 
7298   l_irr_paymnt :=Get_Balance_Value(p_assignment_id
7299                                   ,p_business_group_id
7300                                   ,'PGGM Pensions Irregular Payments'
7301                                   ,'Assignment Period To Date'
7302                                   ,l_period_start_date
7303                                   ,l_period_end_date
7304                                   );
7305 Hr_Utility.set_location('Irregular balance amount'||l_irr_paymnt, 25);
7306     IF l_irr_paymnt  > 0   THEN
7307     p_data_element_value := 'Y';
7308     ELSE
7309     p_data_element_value := 'N';
7310     END IF;
7311 END IF;
7312 
7313 l_return_value:=0;
7314 Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7315 RETURN l_return_value;
7316 EXCEPTION
7317    WHEN Others THEN
7318     p_error_message :='SQL-ERRM :'||SQLERRM;
7319     p_data_element_value := 'N';
7320     Hr_Utility.set_location('..'||p_error_message,85);
7321     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7322     l_return_value:=1;
7323     RETURN l_return_value;
7324 END Record070_Display_Criteria;
7325 --============================================================================
7326 --This is used to decide the Record_080 hide  or show
7327 --============================================================================
7328 FUNCTION Record080_Display_Criteria
7329          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
7330          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
7331          ,p_effective_date     IN  DATE
7332          ,p_error_message      OUT NOCOPY Varchar2
7333  ,p_data_element_value OUT NOCOPY Varchar2
7334           ) RETURN Number IS
7335 Cursor csr_retro_pggm_ptp_entry  IS
7336 Select 'x'
7337 from pay_element_entries_f  pee,
7338      pay_element_types_f pet
7339      where pet.element_name='Retro PGGM Pensions Part Time Percentage Information Element'
7340      and pee.assignment_id=p_assignment_id
7341      and pet.element_type_id =pee.element_type_id
7342      and p_effective_date between pee.effective_start_date
7343                      and pee.effective_end_date;
7344 l_return_value NUMBER :=-1;
7345 l_proc_name    Varchar2(150) := g_proc_name ||'Record080_Display_Criteria';
7346 l_curr_val     NUMBER:=0;
7347 l_prev_val     NUMBER:=0;
7348 l_chk_entry    varchar2(1);
7349 l_start_date   NUMBER:=0;
7350 l_end_date     NUMBER:=0;
7351 l_mon          NUMBER:=0;
7352 l_year         NUMBER:=0;
7353 l_prev_mon     NUMBER:=0;
7354 Begin
7355 Hr_Utility.set_location('Entering :   '||l_proc_name, 10);
7356 --If yearly report hide this record
7357 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'M') = 'Y' THEN
7358  p_data_element_value := 'N';
7359  RETURN 0;
7360 ELSE
7361 p_data_element_value:=g_080_display_flag;
7362 l_return_value:=0;
7363 END IF;
7364 Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7365 RETURN l_return_value;
7366 EXCEPTION
7367    WHEN Others THEN
7368     p_error_message :='SQL-ERRM :'||SQLERRM;
7369     p_data_element_value := 'N';
7370     Hr_Utility.set_location('..'||p_error_message,85);
7371     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7372     l_return_value:=1;
7373     RETURN l_return_value;
7374 END Record080_Display_Criteria;
7375 --============================================================================
7376 --This is used to decide the Record_081 hide  or show
7377 --============================================================================
7378 FUNCTION Record081_Display_Criteria
7379          (p_assignment_id      IN  per_all_assignments_f.assignment_id%TYPE
7380          ,p_business_group_id  IN  per_all_assignments_f.business_group_id%TYPE
7381          ,p_effective_date     IN  DATE
7382          ,p_error_message      OUT NOCOPY Varchar2
7383  ,p_data_element_value OUT NOCOPY Varchar2
7384           ) RETURN Number IS
7385 
7386 CURSOR csr_chk_active_asg(c_asg_id NUMBER,bg_id NUMBER,eff_date DATE) IS
7387 SELECT 'x'
7388   FROM per_all_assignments_f paa,
7389        per_assignment_status_types past
7390 WHERE  paa.assignment_id           = c_asg_id
7391    AND paa.business_group_id       = bg_id
7392    AND paa.assignment_status_type_id=past.assignment_status_type_id
7393    AND past.per_system_status ='ACTIVE_ASSIGN'
7394    AND (eff_date between paa.effective_start_date and paa.effective_end_date);
7395 
7396 CURSOR csr_chk_active_asg_period(c_asg_id NUMBER,bg_id NUMBER) IS
7397 SELECT 'x'
7398   FROM per_all_assignments_f paa,
7399        per_assignment_status_types past
7400 WHERE  paa.assignment_id           = c_asg_id
7401    AND paa.business_group_id       = bg_id
7402    AND paa.assignment_status_type_id=past.assignment_status_type_id
7403    AND past.per_system_status ='ACTIVE_ASSIGN'
7404    AND (paa.effective_start_date between g_extract_params(bg_id).extract_start_date
7405           and g_extract_params(bg_id).extract_end_date );
7406 /*
7407 Cursor csr_retro_pggm_ptp_entry(c_assignment_id NUMBER)  IS
7408 Select 'x'
7409 from pay_element_entries_f  pee,
7410      pay_element_types_f pet
7411      where pet.element_name='Retro PGGM Pensions Part Time Percentage'
7412      and pee.assignment_id=c_assignment_id
7413      and pet.element_type_id =pee.element_type_id
7414      and ( pee.effective_start_date between g_extract_params(p_business_group_id).extract_start_date
7415           and  g_extract_params(p_business_group_id).extract_end_date)
7416      and pee.source_start_date < g_extract_params(p_business_group_id).extract_start_date;*/
7417 
7418 l_return_value NUMBER :=0;
7419 l_proc_name    Varchar2(150) := g_proc_name ||'Record081_Display_Criteria';
7420 l_emp_contri      NUMBER:=0;
7421 l_employer_contri NUMBER:=0;
7422 l_pay_year        NUMBER:=0;
7423 l_pay_mon         NUMBER:=0;
7424 l_pay_day         NUMBER:=0;
7425 l_pay_start_date  DATE;
7426 l_pay_end_date    DATE;
7427 l_chk             varchar2(1);
7428 
7429 Begin
7430 Hr_Utility.set_location('Entering:   '||l_proc_name, 10);
7431 IF NVL(g_extract_params (p_business_group_id).extract_type  ,'N') = 'M' THEN
7432  p_data_element_value := 'N';
7433  RETURN 0;
7434 ELSE
7435 
7436  --Check whether assignment is to be included or not
7437    OPEN csr_chk_active_asg(p_assignment_id,p_business_group_id,g_extract_params(p_business_group_id).extract_start_date);
7438    FETCH csr_chk_active_asg INTO l_chk;
7439    IF csr_chk_active_asg%FOUND THEN
7440       CLOSE csr_chk_active_asg;
7441       p_data_element_value := 'Y';
7442    ELSE
7443      CLOSE csr_chk_active_asg;
7444 
7445      OPEN csr_chk_active_asg_period(p_assignment_id,p_business_group_id);
7446      FETCH csr_chk_active_asg_period INTO l_chk;
7447      IF csr_chk_active_asg_period%FOUND THEN
7448          CLOSE csr_chk_active_asg_period;
7449          p_data_element_value := 'Y';
7450      ELSE
7451         CLOSE csr_chk_active_asg_period;
7452         p_data_element_value := 'N';
7453         Hr_Utility.set_location('Leaving:   '||l_proc_name, 35);
7454       RETURN 0;
7455      END IF;
7456    END IF;
7457 
7458    --Calculate deduction amount
7459 
7460    l_emp_contri:=Get_Balance_value(p_assignment_id
7461                                   ,p_business_group_id
7462                                   ,'PGGM Employee Contribution'
7463                                   ,'Assignment Period To Date'
7464                                   ,g_extract_params(p_business_group_id).extract_start_date
7465                                   ,g_extract_params(p_business_group_id).extract_end_date
7466                                  );
7467    l_employer_contri:=Get_Balance_value(p_assignment_id
7468                                         ,p_business_group_id
7469                                         ,'PGGM Employer Contribution'
7470                                         ,'Assignment Period To Date'
7471                                         ,g_extract_params(p_business_group_id).extract_start_date
7472                                         ,g_extract_params(p_business_group_id).extract_end_date
7473                                        );
7474 
7475  --Record 081 for current year reporting
7476  IF (l_emp_contri + l_employer_contri) > 0  THEN
7477         p_data_element_value:='Y';
7478  ELSE
7479      IF g_rec_081_count > 0 THEN
7480          --set the global flag so that 081 record created by extract can be deleted
7481  g_main_rec_081:='D';
7482          p_data_element_value:='Y';
7483      ELSE
7484          p_data_element_value:='N';
7485      END IF;
7486  END IF;
7487 
7488 
7489   l_return_value:=0;
7490 END IF;
7491 Hr_Utility.set_location('Leaving:   '||l_proc_name, 65);
7492 RETURN l_return_value;
7493 EXCEPTION
7494    WHEN Others THEN
7495     p_error_message :='SQL-ERRM :'||SQLERRM;
7496     p_data_element_value := 'N';
7497     Hr_Utility.set_location('..'||p_error_message,85);
7498     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7499     l_return_value:=1;
7500     RETURN l_return_value;
7501 END Record081_Display_Criteria;
7502 
7503 -- =============================================================================
7504 -- Chk_If_Req_To_Extract: For a given assignment check to see the record needs to
7505 -- be extracted or not.
7506 -- =============================================================================
7507 FUNCTION Chk_If_Req_To_Extract
7508           (p_assignment_id     IN Number
7509           ,p_business_group_id IN Number
7510           ,p_effective_date    IN Date
7511           ,p_record_num        IN Varchar2
7512           ,p_error_message     OUT NOCOPY Varchar2)
7513 RETURN Varchar2 IS
7514 
7515    l_proc_name          Varchar2(150) := g_proc_name ||'Chk_If_Req_To_Extract';
7516    l_return_value       Number :=0;
7517    l_data_element_value Varchar2(2):='Y';
7518 
7519 BEGIN
7520    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
7521    Hr_Utility.set_location('..p_record_num : '||p_record_num , 6);
7522    IF p_record_num = '010' THEN
7523      l_return_value := Record010_Display_Criteria
7524                        (p_assignment_id      => p_assignment_id
7525                        ,p_business_group_id  => p_business_group_id
7526                        ,p_effective_date     => p_effective_date
7527                        ,p_error_message      => p_error_message
7528                        ,p_data_element_value => l_data_element_value
7529                         );
7530    ELSIF p_record_num = '020' THEN
7531      l_return_value := Record020_Display_Criteria
7532                         (p_assignment_id      => p_assignment_id
7533                         ,p_business_group_id  => p_business_group_id
7534                         ,p_effective_date     => p_effective_date
7535                         ,p_error_message      => p_error_message
7536                         ,p_data_element_value => l_data_element_value
7537                         );
7538    ELSIF p_record_num = '030' THEN
7539      l_return_value :=  Record030_Display_Criteria
7540                         (p_assignment_id      => p_assignment_id
7541                         ,p_business_group_id  => p_business_group_id
7542                         ,p_effective_date     => p_effective_date
7543                         ,p_error_message      => p_error_message
7544                         ,p_data_element_value => l_data_element_value
7545                         );
7546    ELSIF p_record_num = '040' THEN
7547      l_return_value :=  Record040_Display_Criteria
7548                         (p_assignment_id      => p_assignment_id
7549                         ,p_business_group_id  => p_business_group_id
7550                         ,p_effective_date     => p_effective_date
7551                         ,p_error_message      => p_error_message
7552                         ,p_data_element_value => l_data_element_value
7553                         );
7554 
7555    ELSIF p_record_num = '060' THEN
7556      l_return_value :=  Record060_Display_Criteria
7557                         (p_assignment_id      => p_assignment_id
7558                          ,p_business_group_id  => p_business_group_id
7559                          ,p_effective_date     => p_effective_date
7560                          ,p_error_message      => p_error_message
7561                          ,p_data_element_value => l_data_element_value
7562                         );
7563 
7564    ELSIF p_record_num = '070' THEN
7565           l_return_value := Record070_Display_Criteria
7566                     (p_assignment_id
7567                     ,p_business_group_id
7568                     ,p_effective_date
7569                     ,p_error_message
7570                     ,l_data_element_value);
7571 
7572   ELSIF p_record_num = '080' THEN
7573           l_return_value := Record080_Display_Criteria(p_assignment_id
7574                             ,p_business_group_id
7575                             ,p_effective_date
7576                             ,p_error_message
7577                             ,l_data_element_value);
7578 
7579    ELSIF p_record_num = '081' THEN
7580           l_return_value := Record081_Display_Criteria
7581                             (p_assignment_id
7582                              ,p_business_group_id
7583                              ,p_effective_date
7584                              ,p_error_message
7585                              ,l_data_element_value);
7586    ELSIF p_record_num = '10h' THEN
7587        l_data_element_value := 'Y';
7588    ELSE
7589      l_data_element_value := 'N';
7590    END IF;
7591    Hr_Utility.set_location('..l_data_element_value: '||l_data_element_value,45);
7592    Hr_Utility.set_location('Leaving: '||l_proc_name, 50);
7593    IF(l_return_value <> 0) THEN
7594     l_data_element_value:='E';
7595    END IF;
7596 
7597    RETURN l_data_element_value;
7598 
7599 EXCEPTION
7600    WHEN Others THEN
7601     p_error_message :='SQL-ERRM :'||SQLERRM;
7602     Hr_Utility.set_location('..'||p_error_message,85);
7603     Hr_Utility.set_location('Leaving: '||l_proc_name, 90);
7604     l_data_element_value:='E';
7605     RETURN l_data_element_value;
7606 
7607 END Chk_If_Req_To_Extract;
7608 
7609 -- ====================================================================
7610 -- Raise_Extract_Warning:
7611 --    When called from the Rule of a extract detail data element
7612 --    it logs a warning in the ben_ext_rslt_err table against
7613 --    the person being processed (or as specified by context of
7614 --    assignment id ). It prefixes all warning messages with a
7615 --    string "Warning raised in data element "||element_name
7616 --    This allows the same Rule to be called from different data
7617 --    elements. Usage example.
7618 --    RAISE_EXTRACT_WARNING("No initials were found.")
7619 --    RRTURNCODE  MEANING
7620 --    -1          Cannot raise warning against a header/trailer
7621 --                record. System Extract does not allow it.
7622 --    -2          No current extract process was found.
7623 --    -3          No person was found.A Warning in System Extract
7624 --                is always raised against a person.
7625 -- ====================================================================
7626 
7627 FUNCTION Raise_Extract_Warning
7628          (p_assignment_id     IN     Number -- context
7629          ,p_error_text        IN     Varchar2
7630          ,p_error_NUMBER      IN     Number DEFAULT NULL
7631           ) RETURN Number IS
7632   l_ext_rslt_id   Number;
7633   l_person_id     Number;
7634   l_error_text    Varchar2(2000);
7635   l_return_value  Number:= 0;
7636 BEGIN
7637   --
7638     IF p_assignment_id <> -1 THEN
7639       l_ext_rslt_id:= get_current_extract_result;
7640       IF l_ext_rslt_id <> -1 THEN
7641         IF p_error_NUMBER IS NULL THEN
7642           l_error_text:= 'Warning raised in data element '||
7643                           Nvl(Ben_Ext_Person.g_elmt_name
7644                              ,Ben_Ext_Fmt.g_elmt_name)||'. '||
7645                           p_error_text;
7646         ELSE
7647           Ben_Ext_Thread.g_err_num  := p_error_NUMBER;
7648           Ben_Ext_Thread.g_err_name := p_error_text;
7649           l_error_text :=
7650             Ben_Ext_Fmt.get_error_msg(To_Number(Substr(p_error_text, 5, 5)),
7651               p_error_text,Nvl(Ben_Ext_Person.g_elmt_name,Ben_Ext_Fmt.g_elmt_name) );
7652 
7653         END IF;
7654         l_person_id:= Nvl(get_current_extract_person(p_assignment_id)
7655                        ,Ben_Ext_Person.g_person_id);
7656 
7657         IF l_person_id IS NOT NULL THEN
7658         --
7659           Ben_Ext_Util.write_err
7660             (p_err_num           => p_error_NUMBER
7661             ,p_err_name          => l_error_text
7662             ,p_typ_cd            => 'W'
7663             ,p_person_id         => l_person_id
7664             ,p_request_id        => Fnd_Global.conc_request_id
7665             ,p_business_group_id => Fnd_Global.per_business_group_id
7666             ,p_ext_rslt_id       => get_current_extract_result
7667             );
7668           l_return_value:= 0;
7669         ELSE
7670           l_return_value:= -3;
7671         END IF;
7672       ELSE
7673       --
7674         l_return_value:= -2; /* No current extract process was found */
7675       --
7676       END IF;
7677     --
7678     ELSE
7679     --
7680       l_return_value := -1; /* Cannot raise warnings against header/trailers */
7681     --
7682     END IF;
7683   --
7684   RETURN l_return_value;
7685 END Raise_Extract_Warning;
7686 
7687 -- ===============================================================================
7688 -- ~ Get_Trailer_Record_Count : This is used to calculate the record count
7689 -- ===============================================================================
7690 FUNCTION Get_Trailer_Record_Count
7691            (p_rcd_id  IN Number
7692    ,p_org_id IN Number
7693            ) RETURN Number IS
7694 
7695  CURSOR csr_get_record_count(c_record_id IN Number
7696                             ,c_org_id IN Number ) IS
7697    SELECT Count(dtl.ext_rslt_dtl_id)
7698      FROM ben_ext_rslt_dtl dtl
7699     WHERE dtl.ext_rslt_id = Ben_Ext_Thread.g_ext_rslt_id
7700      AND ext_rcd_id IN(c_record_id);
7701      --AND val_31=c_org_id;
7702 
7703 l_proc_name     Varchar2(150) := g_proc_name ||'.Get_Trailer_Record_Count';
7704 l_record_count Number  := 0;
7705 BEGIN
7706    Hr_Utility.set_location('Entering: '||l_proc_name, 5);
7707    OPEN csr_get_record_count(p_rcd_id,p_org_id);
7708    FETCH csr_get_record_count INTO l_record_count;
7709    CLOSE csr_get_record_count;
7710    Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
7711   RETURN l_record_count;
7712 EXCEPTION
7713   WHEN Others THEN
7714      Hr_Utility.set_location('Exception Others Raised at Get_Trailer_Record_Count',40);
7715      Hr_Utility.set_location('Leaving: '||l_proc_name, 45);
7716      RETURN -1;
7717 END Get_Trailer_Record_Count;
7718 
7719 -- ================================================================================
7720 -- ~ Sort_Post_Process : Post process logic
7721 -- ================================================================================
7722 FUNCTION Sort_Post_Process
7723           (p_business_group_id  ben_ext_rslt_dtl.business_group_id%TYPE
7724           )RETURN Number IS
7725 
7726 CURSOR csr_get_rslt(c_org_id         IN Varchar2
7727                    ,c_ext_rslt_id    IN Number ) IS
7728 SELECT DISTINCT(val_32) val_32
7729      FROM ben_ext_rslt_dtl dtl
7730     WHERE dtl.ext_rslt_id = c_ext_rslt_id
7731       AND val_31= c_org_id
7732       ORDER BY val_32 ASC ;
7733 
7734 CURSOR csr_get_rslt1(c_ext_rslt_id    IN Number ) IS
7735 SELECT val_31,val_32
7736      FROM ben_ext_rslt_dtl dtl
7737     WHERE dtl.ext_rslt_id = c_ext_rslt_id
7738       ORDER BY val_32 ASC;
7739 
7740 CURSOR csr_rslt_dtl_sort(c_val_32         IN Varchar2
7741                         ,c_ext_rslt_id    IN Number ) IS
7742    SELECT *
7743      FROM ben_ext_rslt_dtl dtl
7744     WHERE dtl.ext_rslt_id = c_ext_rslt_id
7745     --  AND dtl.person_id   = c_person_id
7746       AND dtl.val_32      =c_val_32;
7747 
7748 
7749 
7750 CURSOR csr_get_header_rslt(c_ext_rslt_id    IN Number
7751              ,c_ext_dtl_rcd_id IN Number ) IS
7752    SELECT *
7753      FROM ben_ext_rslt_dtl dtl
7754     WHERE dtl.ext_rslt_id = c_ext_rslt_id
7755       AND ext_rcd_id= c_ext_dtl_rcd_id;
7756 
7757 
7758 CURSOR csr_get_trailer_rslt(c_ext_rslt_id    IN Number
7759            ,c_ext_dtl_rcd_id IN Number ) IS
7760 SELECT *
7761      FROM ben_ext_rslt_dtl dtl
7762     WHERE dtl.ext_rslt_id = c_ext_rslt_id
7763       AND ext_rcd_id= c_ext_dtl_rcd_id;
7764 
7765 -- Cursor to get the person existence flag
7766 CURSOR csr_get_person_exist(c_org_id IN Number) IS
7767 SELECT 'x'
7768   FROM  ben_ext_rslt_dtl
7769   WHERE ext_rslt_id=Ben_Ext_Thread.g_ext_rslt_id
7770   AND   val_31=c_org_id;
7771 
7772 
7773 l_ext_dtl_rcd_id    ben_ext_rcd.ext_rcd_id%TYPE;
7774 l_rcd_id            NUMBER;
7775 l_rcd_id_060        NUMBER;
7776 l_rcd_id_080        NUMBER;
7777 l_rcd_id_081        NUMBER;
7778 
7779 l_ext_main_rcd_id   ben_ext_rcd.ext_rcd_id%TYPE;
7780 l_proc_name         Varchar2(150):=  g_proc_name||'Sort_Post_Process';
7781 l_return_value      Number := 0; --0= Sucess, -1=Error;
7782 l_tmp_person_id     Number;
7783 l_tmp_org_id        Number;
7784 l_first_flag        Number  :=0;
7785 l_org_pram_id       hr_all_organization_units.organization_id%TYPE;
7786 l_temp_org_pram_id  hr_all_organization_units.organization_id%TYPE;
7787 l_org_detl          g_org_list%TYPE;
7788 l_org_index         Number :=1;
7789 l_global_contribution Number :=0;
7790 l_first_person_id   Number;
7791 l_main_rec          csr_rslt_dtl_sort%ROWTYPE;
7792 l_new_rec           csr_rslt_dtl_sort%ROWTYPE;
7793 l_header_main_rec   csr_get_header_rslt%ROWTYPE;
7794 l_header_new_rec    csr_get_header_rslt%ROWTYPE;
7795 l_trailer_main_rec  csr_get_trailer_rslt%ROWTYPE;
7796 l_trailer_new_rec   csr_get_trailer_rslt%ROWTYPE;
7797 sort_val            Number :=1;
7798 l_sort_val          Varchar2(15);
7799 l_emp_ext_chk       Number:=0;
7800 l_org_count         Number :=0;
7801 l_org_name          hr_all_organization_units.NAME%TYPE;
7802 l_insert_trailer    Number := 1;
7803 l_first_trailer_flag  Number :=0;
7804 l_Person_Exists     Varchar2(2):='y';
7805 i Number := 0;
7806 l_ext_rslt_dtl_id  Number;
7807 l_count            Number := 0;
7808 l_000_rslt_dtl_id  NUMBER;
7809 l_999_rslt_dtl_id  NUMBER;
7810 l_010_count        NUMBER;
7811 l_020_count        NUMBER;
7812 l_030_count        NUMBER;
7813 l_040_count        NUMBER;
7814 l_060_count        NUMBER;
7815 l_070_count        NUMBER;
7816 l_080_count        NUMBER;
7817 l_081_count        NUMBER;
7818 l_total_data_rcd_count        NUMBER;
7819 l_delete_count     NUMBER:=0;
7820 l_delete_index     NUMBER:=0;
7821 del_index          NUMBER:=0;
7822 l_999_inserted     NUMBER := 0;
7823 l_000_inserted     NUMBER := 0;
7824 
7825 BEGIN
7826   Hr_Utility.set_location('Entering :---------'||l_proc_name, 5);
7827 
7828   -- Delete all the hidden Records
7829    FOR csr_rcd_rec IN csr_ext_rcd_id
7830                       (c_hide_flag   => 'Y' -- N=No Y=Yes
7831                       ,c_rcd_type_cd => 'D')-- D=Detail, T=Total, H-Header
7832   -- Loop through each detail record for the extract
7833    LOOP
7834        -- Delete all detail records for the record which are hidden
7835        DELETE ben_ext_rslt_dtl
7836         WHERE ext_rcd_id        = csr_rcd_rec.ext_rcd_id
7837           AND ext_rslt_id       = Ben_Ext_Thread.g_ext_rslt_id
7838           AND business_group_id = p_business_group_id;
7839    END LOOP; -- FOR csr_rcd_rec
7840 
7841 --Fetch the record id from the sequence number
7842    OPEN c_get_rcd_id(6);
7843    FETCH c_get_rcd_id INTO l_rcd_id_060;
7844    CLOSE c_get_rcd_id;
7845 
7846 --Fetch the record id from the sequence number
7847    OPEN c_get_rcd_id(8);
7848    FETCH c_get_rcd_id INTO l_rcd_id_080;
7849    CLOSE c_get_rcd_id;
7850 
7851    --Fetch the record id from the sequence number
7852    OPEN c_get_rcd_id(9);
7853    FETCH c_get_rcd_id INTO l_rcd_id_081;
7854    CLOSE c_get_rcd_id;
7855 
7856    --Delete all extra records created by system extract
7857     DELETE ben_ext_rslt_dtl
7858         WHERE ext_rcd_id        IN ( l_rcd_id_060,l_rcd_id_080,l_rcd_id_081 )
7859           AND ext_rslt_id       = Ben_Ext_Thread.g_ext_rslt_id
7860           AND business_group_id = p_business_group_id
7861           AND val_40='Delete';
7862 
7863 
7864      -- All orgs,fill up the temp. table with the org ids in order of
7865      --the sort value
7866       FOR val IN csr_get_rslt1
7867                 (c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id )
7868       LOOP
7869          hr_utility.set_location('val 32 : '||val.val_32,10);
7870          IF g_org_list.EXISTS(val.val_31) THEN
7871             IF NOT g_ord_details1.EXISTS(val.val_31) THEN
7872                hr_utility.set_location('l_org_index : '||l_org_index,20);
7873                hr_utility.set_location('org : '||val.val_31,30);
7874                g_ord_details(l_org_index).gre_org_id := val.val_31;
7875                g_ord_details1(to_number(val.val_31)).gre_org_id := val.val_31;
7876                l_org_index := l_org_index + 1;
7877             END IF;
7878           END IF;
7879       END LOOP;
7880 
7881       -- Maintaining recordIds with record numbers in plsql table
7882        FOR rcd_dtls IN csr_ext_rcd_id_with_seq()
7883        LOOP
7884            IF rcd_dtls.hide_flag = 'N' THEN
7885               g_rcd_dtls(To_Number(rcd_dtls.rec_num)).ext_rcd_id := rcd_dtls.ext_rcd_id;
7886           END IF;
7887        END LOOP;
7888 
7889        l_org_count := g_ord_details.Count;
7890 
7891        --fetch the extract result id for the trailer records
7892        --these are ids for the records created automatically by
7893        --benefits, and they will be deleted in the end after we
7894        --create our own trailer records for each org based on these
7895        FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
7896                                         ,c_rcd_type_cd => 'T')-- T-Trailer
7897        LOOP
7898         OPEN csr_get_trailer_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
7899                                    ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
7900         FETCH csr_get_trailer_rslt INTO l_trailer_main_rec;
7901         CLOSE csr_get_trailer_rslt;
7902           IF g_rcd_dtls(999).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
7903              l_999_rslt_dtl_id := l_trailer_main_rec.ext_rslt_dtl_id;
7904           END IF;
7905        END LOOP;
7906 
7907        --find the dtl record id for the header record
7908        --since records need to be sorted by employer number, the default
7909        --header record created by benefits needs to be deleted later
7910        FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
7911                                         ,c_rcd_type_cd => 'H')-- H-Header
7912        LOOP
7913 
7914        OPEN csr_get_header_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
7915                                 ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id
7916                                );
7917        FETCH csr_get_header_rslt INTO l_header_main_rec;
7918        CLOSE csr_get_header_rslt;
7919           IF g_rcd_dtls(000).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
7920              l_000_rslt_dtl_id := l_header_main_rec.ext_rslt_dtl_id;
7921           END IF;
7922        END LOOP;
7923 
7924 
7925      -- loop through all orgids
7926      FOR num IN 1..l_org_count
7927      LOOP
7928        -- Check wether employee exists in hierarchy or not
7929        OPEN csr_get_person_exist(g_ord_details(num).gre_org_id);
7930        FETCH csr_get_person_exist INTO l_Person_Exists;
7931        IF csr_get_person_exist%FOUND THEN
7932          l_Person_Exists:='x';
7933 	 exit;
7934        END IF;
7935        CLOSE csr_get_person_exist;
7936      END LOOP;
7937 
7938      IF l_Person_Exists = 'x' THEN
7939       --Loop through Header records
7940       FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
7941                                        ,c_rcd_type_cd => 'H')-- H-Header
7942       LOOP
7943          OPEN csr_get_header_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
7944                                  ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
7945          FETCH csr_get_header_rslt INTO l_header_main_rec;
7946          CLOSE csr_get_header_rslt;
7947          l_header_new_rec :=  l_header_main_rec;
7948          l_sort_val := Lpad(sort_val,15,0);
7949          l_header_new_rec.prmy_sort_val := l_sort_val;
7950          l_header_new_rec.object_version_NUMBER :=  Nvl(l_header_new_rec.object_version_NUMBER,0) + 1;
7951          sort_val :=sort_val+1;
7952 
7953            -- Insert the header record only once for each extract
7954            IF l_000_inserted = 0  THEN
7955             Ins_Rslt_Dtl(p_dtl_rec => l_header_new_rec);
7956               l_000_inserted := 1;
7957            END IF;
7958 
7959        END LOOP;--End of Header Loop
7960     END IF; -- l_person exists
7961 
7962 
7963 
7964 -- loop through all orgids
7965      FOR num IN 1..l_org_count
7966      LOOP
7967       l_count := 0;
7968       Hr_Utility.set_location('Current Org Id:---------'||g_ord_details(num).gre_org_id, 5);
7969       IF num <= l_org_count THEN
7970 
7971        -- Get all records for orgid
7972         FOR val IN csr_get_rslt
7973                      (c_org_id         => g_ord_details(num).gre_org_id
7974                      ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id )
7975        LOOP
7976          -- Get the individual row using sortid key
7977          -- So we will get only one record related data per person
7978           FOR ind_dtl IN csr_rslt_dtl_sort
7979                         (c_val_32=> val.val_32
7980                          ,c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
7981                         )
7982          LOOP
7983           l_main_rec :=  ind_dtl;
7984           l_main_rec.object_version_NUMBER := Nvl(l_main_rec.object_version_NUMBER,0) + 1;
7985           l_new_rec := l_main_rec;
7986             l_sort_val:= Lpad(sort_val,15,0);
7987           l_new_rec.prmy_sort_val := l_sort_val;
7988           sort_val :=sort_val+1;
7989           Upd_Rslt_Dtl(p_dtl_rec => l_new_rec);
7990           l_emp_ext_chk := 1;
7991           END LOOP; --ind_dtl Loop
7992         END LOOP; -- csr_get_rslt Loop
7993 
7994       END IF; -- org count
7995    END LOOP; --End of org loop
7996 
7997     --Check wether trailor record has to be shown or not
7998     IF l_Person_Exists = 'x' THEN
7999       --Loop through trailer records
8000       FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
8001                                       ,c_rcd_type_cd => 'T')-- T-Trailer
8002       LOOP
8003           l_insert_trailer := 1;
8004           OPEN csr_get_trailer_rslt(c_ext_rslt_id    => Ben_Ext_Thread.g_ext_rslt_id
8005                                    ,c_ext_dtl_rcd_id => csr_rcd_rec.ext_rcd_id);
8006           FETCH csr_get_trailer_rslt INTO l_trailer_main_rec;
8007           CLOSE csr_get_trailer_rslt;
8008           l_trailer_new_rec :=  l_trailer_main_rec;
8009 
8010           -- Start of trailer record 999
8011            IF g_rcd_dtls(999).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
8012 
8013                l_total_data_rcd_count:=0;
8014 
8015             --Get the record count for 010
8016             l_010_count:=Get_Trailer_Record_Count(g_rcd_dtls(010).ext_rcd_id
8017                                         ,g_extract_params(p_business_group_id).org_id );
8018             l_trailer_new_rec.val_04 := lpad(fnd_number.number_to_canonical(l_010_count),6,'0');
8019             l_total_data_rcd_count:=l_total_data_rcd_count+l_010_count;
8020 
8021             --Get the record count for 020
8022             l_020_count:=Get_Trailer_Record_Count(g_rcd_dtls(020).ext_rcd_id
8023                                         ,g_extract_params(p_business_group_id).org_id );
8024             l_trailer_new_rec.val_05 := lpad(fnd_number.number_to_canonical(l_020_count),6,'0');
8025             l_total_data_rcd_count:=l_total_data_rcd_count+l_020_count;
8026 
8027             --Get the record count for 030
8028             l_030_count:=Get_Trailer_Record_Count(g_rcd_dtls(030).ext_rcd_id
8029                                          ,g_extract_params(p_business_group_id).org_id );
8030             l_trailer_new_rec.val_06 := lpad(fnd_number.number_to_canonical(l_030_count),6,'0');
8031             l_total_data_rcd_count:=l_total_data_rcd_count+l_030_count;
8032 
8033             --Get the record count for 040
8034             l_040_count:=Get_Trailer_Record_Count(g_rcd_dtls(040).ext_rcd_id
8035                                        ,g_extract_params(p_business_group_id).org_id );
8036             l_trailer_new_rec.val_07 := lpad(fnd_number.number_to_canonical(l_040_count),6,'0');
8037             l_total_data_rcd_count:=l_total_data_rcd_count+l_040_count;
8038 
8039 
8040             --Get the record count for 060
8041             l_060_count:=Get_Trailer_Record_Count(g_rcd_dtls(060).ext_rcd_id
8042                                    ,g_extract_params(p_business_group_id).org_id );
8043             l_trailer_new_rec.val_09 := lpad(fnd_number.number_to_canonical(l_060_count),6,'0');
8044             l_total_data_rcd_count:=l_total_data_rcd_count+l_060_count;
8045 
8046             --Get the record count for 070
8047             l_070_count:=Get_Trailer_Record_Count(g_rcd_dtls(070).ext_rcd_id
8048                                     ,g_extract_params(p_business_group_id).org_id );
8049             l_trailer_new_rec.val_10 := lpad(fnd_number.number_to_canonical(l_070_count),6,'0');
8050             l_total_data_rcd_count:=l_total_data_rcd_count+l_070_count;
8051 
8052             --Get the record count for 080
8053             l_080_count:=Get_Trailer_Record_Count(g_rcd_dtls(080).ext_rcd_id
8054                                     ,g_extract_params(p_business_group_id).org_id );
8055             l_trailer_new_rec.val_11 := lpad(fnd_number.number_to_canonical(l_080_count),6,'0');
8056             l_total_data_rcd_count:=l_total_data_rcd_count+l_080_count;
8057 
8058             --Get the record count for 081
8059             l_081_count:=Get_Trailer_Record_Count(g_rcd_dtls(081).ext_rcd_id
8060                                     ,g_extract_params(p_business_group_id).org_id );
8061             l_trailer_new_rec.val_15 := lpad(fnd_number.number_to_canonical(l_081_count),6,'0');
8062             l_total_data_rcd_count:=l_total_data_rcd_count+l_081_count;
8063 
8064             --Set Total Data Record Count
8065             l_trailer_new_rec.val_03 := lpad(fnd_number.number_to_canonical(l_total_data_rcd_count),6,'0');
8066 
8067          END IF;
8068          --Set the primary sort value
8069           l_sort_val := Lpad(sort_val,15,0);
8070           l_trailer_new_rec.prmy_sort_val := l_sort_val;
8071           l_trailer_new_rec.object_version_NUMBER :=  Nvl(l_trailer_new_rec.object_version_NUMBER,0) + 1;
8072           sort_val :=sort_val+1;
8073 
8074 
8075           -- Inserting new Record 999 for this extract
8076           IF l_999_inserted = 0 THEN
8077              Ins_Rslt_Dtl(p_dtl_rec => l_trailer_new_rec);
8078              l_999_inserted := 1;
8079           END IF;
8080 
8081       END LOOP;  --  Trailor Records csr_rcd_rec
8082 
8083      END IF; -- l_person_exists check
8084 
8085 
8086 
8087 --fetch the result id to delete the extract result
8088 --trailer records created by benefits
8089 FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
8090                                  ,c_rcd_type_cd => 'T')-- T-Trailer
8091 LOOP
8092   IF g_rcd_dtls(999).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
8093      l_ext_rslt_dtl_id := l_999_rslt_dtl_id;
8094   END IF;
8095 
8096   DELETE
8097     FROM ben_ext_rslt_dtl dtl
8098   WHERE dtl.ext_rslt_id  = Ben_Ext_Thread.g_ext_rslt_id
8099     AND dtl.ext_rcd_id    = csr_rcd_rec.ext_rcd_id
8100     AND dtl.ext_rslt_dtl_id = l_ext_rslt_dtl_id
8101     AND business_group_id = p_business_group_id;
8102 
8103 END LOOP;
8104 
8105 --fetch the result id to delete the extract result
8106 --Header records created by benefits
8107 FOR csr_rcd_rec IN csr_ext_rcd_id(c_hide_flag   => 'N'
8108                                  ,c_rcd_type_cd => 'H')-- H-Header
8109 LOOP
8110   IF g_rcd_dtls(000).ext_rcd_id = csr_rcd_rec.ext_rcd_id THEN
8111      l_ext_rslt_dtl_id := l_000_rslt_dtl_id;
8112   END IF;
8113 
8114   DELETE
8115     FROM ben_ext_rslt_dtl dtl
8116   WHERE dtl.ext_rslt_id  = Ben_Ext_Thread.g_ext_rslt_id
8117     AND dtl.ext_rcd_id    = csr_rcd_rec.ext_rcd_id
8118     AND dtl.ext_rslt_dtl_id = l_ext_rslt_dtl_id
8119     AND business_group_id = p_business_group_id;
8120 
8121 END LOOP;
8122 --  Hr_Utility.trace_off;
8123   Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
8124   RETURN l_return_value;
8125 
8126 EXCEPTION
8127   WHEN Others THEN
8128    Hr_Utility.set_location('..Exception when others raised..', 20);
8129    Hr_Utility.set_location('Leaving :'||l_proc_name, 25);
8130    RETURN -1;
8131 END Sort_Post_Process;
8132 
8133 END Pqp_Nl_PGGM_Pension_Extracts ;