1 PACKAGE BODY PQP_NL_ABP_FUNCTIONS AS
2 /* $Header: pqpnlabp.pkb 120.34 2008/01/03 12:53:48 rsahai noship $ */
3 -- =============================================================================
4 -- to_nl_date: Function to convert the date to the appropriate value
5 -- since the ben logs contain dates in the NL Language -- 31-MEI-05
6 -- 1-OKT-05 etc
7 -- =============================================================================
8 FUNCTION to_nl_date (p_date_value IN VARCHAR2,
9 p_date_format IN VARCHAR2)
10 RETURN DATE IS
11
12 BEGIN
13
14 IF LENGTH(p_date_value) = 9 THEN
15 RETURN TO_DATE(p_date_value,p_date_format,'NLS_DATE_LANGUAGE = ''DUTCH''');
16 ELSE
17 RETURN TO_DATE(p_date_value,p_date_format);
18 END IF;
19
20 EXCEPTION
21 WHEN OTHERS THEN
22 RETURN To_date(p_date_value,p_date_format,'NLS_DATE_LANGUAGE = ''AMERICAN''');
23
24 END to_nl_date;
25
26 --
27 -- ------------------------------------------------------------------------
28 -- |-----------------------< get_reporting_date >-------------------------|
29 -- ------------------------------------------------------------------------
30 --
31 FUNCTION get_reporting_date
32 (p_effective_date IN DATE
33 ,p_person_id IN per_all_people_f.person_id%TYPE
34 ,p_reporting_date OUT NOCOPY DATE
35 )
36 RETURN NUMBER IS
37
38 CURSOR c_last_ext IS
39 SELECT eff_dt
40 FROM ben_ext_rslt res
41 WHERE ext_dfn_id IN (SELECT ext_dfn_id
42 FROM pqp_extract_attributes
43 WHERE ext_dfn_type = 'NL_FPR')
44 AND ext_stat_cd = 'A'
45 AND EXISTS ( SELECT 1 FROM ben_ext_rslt_dtl dtl
46 WHERE dtl.ext_rslt_id = res.ext_rslt_id
47 AND dtl.person_id = p_person_id)
48 ORDER BY ext_rslt_id DESC;
49
50 l_last_app_ext DATE;
51
52 BEGIN
53 --
54 -- Fetch the last date for which the extract was sent to the provider
55 --
56 OPEN c_last_ext;
57 FETCH c_last_ext INTO l_last_app_ext;
58 IF c_last_ext%NOTFOUND THEN
59 l_last_app_ext := NULL;
60 END IF;
61 CLOSE c_last_ext;
62
63 IF l_last_app_ext IS NULL THEN
64 p_reporting_date := trunc(p_effective_date);
65 ELSE
66 p_reporting_date := add_months(TRUNC(l_last_app_ext),1);
67 END IF;
68
69 p_reporting_date := GREATEST(p_reporting_date,trunc(p_effective_date));
70
71 hr_utility.set_location('.......... p_reporting_date IS '||p_reporting_date,10);
72 hr_utility.set_location('.......... l_last_app_ext IS '||l_last_app_ext,10);
73
74 RETURN 0;
75
76 EXCEPTION
77 WHEN OTHERS THEN
78 p_reporting_date := NULL;
79 RETURN 1;
80
81 END get_reporting_date;
82
83 --
84 -- ------------------------------------------------------------------------
85 -- |-----------------------< get_reporting_date >-------------------------|
86 -- ------------------------------------------------------------------------
87 --
88 FUNCTION get_reporting_date
89 (p_effective_date IN DATE
90 ,p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
91 ,p_person_id IN per_all_people_f.person_id%TYPE
92 ,p_reporting_date OUT NOCOPY DATE
93 )
94 RETURN NUMBER IS
95
96 CURSOR c_last_ext IS
97 SELECT eff_dt
98 FROM ben_ext_rslt res
99 WHERE ext_dfn_id IN (SELECT ext_dfn_id
100 FROM pqp_extract_attributes
101 WHERE ext_dfn_type = 'NL_FPR')
102 AND ext_stat_cd = 'A'
103 AND EXISTS ( SELECT 1 FROM ben_ext_rslt_dtl dtl
104 WHERE dtl.ext_rslt_id = res.ext_rslt_id
105 AND dtl.person_id = p_person_id)
106 ORDER BY ext_rslt_id DESC;
107
108 CURSOR c_ppa_dt (c_eff_dt IN DATE) IS
109 SELECT effective_date
110 FROM pay_payroll_actions pact
111 WHERE action_type IN ('Q','R')
112 AND action_status = 'C'
113 AND EXISTS (SELECT 1 FROM pay_assignment_actions act
114 WHERE act.payroll_action_id = pact.payroll_action_id
115 AND assignment_id = p_assignment_id
116 AND action_status = 'C')
117 AND effective_date >= c_eff_dt
118 ORDER BY payroll_action_id desc;
119
120 l_last_app_ext DATE;
121 l_pa_eff_dt DATE;
122
123 BEGIN
124
125
126 --
127 -- Fetch the last date for which the extract was sent to the provider
128 --
129 OPEN c_last_ext;
130 FETCH c_last_ext INTO l_last_app_ext;
131 IF c_last_ext%NOTFOUND THEN
132 l_last_app_ext := NULL;
133 END IF;
134 CLOSE c_last_ext;
135
136 --
137 -- Check if any payroll has been processed after the last file was sent
138 -- to the provider. If payroll has been processed then the reporting date
139 -- is the next month as the change is being made after processing payroll
140 --
141 OPEN c_ppa_dt ( TRUNC(NVL(l_last_app_ext,p_effective_date)));
142 FETCH c_ppa_dt INTO l_pa_eff_dt;
143 IF c_ppa_dt%FOUND THEN
144 p_reporting_date := add_months(TRUNC(l_pa_eff_dt),1);
145 ELSIF c_ppa_dt%NOTFOUND THEN
146 IF l_last_app_ext IS NULL THEN
147 p_reporting_date := p_effective_date;
148 ELSE
149 p_reporting_date := add_months(TRUNC(l_last_app_ext),1);
150 END IF;
151 END IF;
152 CLOSE c_ppa_dt;
153 hr_utility.set_location('.......... p_reporting_date IS '||p_reporting_date,10);
154 hr_utility.set_location('.......... l_pa_eff_dt IS '||l_pa_eff_dt,10);
155 hr_utility.set_location('.......... l_last_app_ext IS '||l_last_app_ext,10);
156
157
158 RETURN 0;
159
160 EXCEPTION
161 WHEN OTHERS THEN
162 p_reporting_date := NULL;
163 RETURN 1;
164
165 END get_reporting_date;
166
167 --
168 -- ----------------------------------------------------------------------------
169 -- |-----------------------< get_valid_start_date >-----------------------------|
170 -- ----------------------------------------------------------------------------
171 --
172
173 Function get_valid_start_date
174 ( p_assignment_id in NUMBER
175 ,p_eff_date in DATE
176 ,p_error_status out nocopy CHAR
177 ,p_error_message out nocopy VARCHAR2)
178 Return DATE IS
179
180 --
181 --Cursor to fetch the Assignment Start Date
182 --
183 CURSOR c_chk_assgn_start_date IS
184 SELECT effective_start_date
185 FROM per_all_assignments_f
186 WHERE (assignment_id = p_assignment_id)
187 AND assignment_type = 'E'
188 AND (TO_DATE('01/01/'||TO_CHAR(p_eff_date,'YYYY'),'dd/mm/yyyy')
189 BETWEEN effective_start_date and effective_end_date);
190
191 --
192 --Cursor to fetch the First Assignment Start Date of a particular year
193 --
194 CURSOR c_get_assgn_start_date IS
195 SELECT MIN(effective_start_date)
196 FROM per_all_assignments_f
197 WHERE assignment_id = p_assignment_id
198 AND assignment_type = 'E'
199 AND (effective_start_date
200 BETWEEN TO_DATE('01/01/'||TO_CHAR(p_eff_date,'YYYY'),'dd/mm/yyyy')
201 AND TO_DATE('31/12/'||TO_CHAR(p_eff_date,'YYYY'),'dd/mm/yyyy'));
202
203 l_hire_date DATE;
204 l_assgn_st_date DATE;
205 l_person_id NUMBER;
206 l_curr_year VARCHAR2(10);
207
208 BEGIN
209
210 --
211 --Fetch the current year from the eff date
212 --
213 l_curr_year := TO_CHAR(p_eff_date,'YYYY');
214 p_error_status :=trim(to_char(0,'9'));
215
216 OPEN c_chk_assgn_start_date;
217 FETCH c_chk_assgn_start_date
218 INTO l_assgn_st_date;
219 --
220 -- If Assignment is valid on 1st jan of that
221 -- year return 1st of Jan of that year
222 --
223 IF c_chk_assgn_start_date%FOUND THEN
224 CLOSE c_chk_assgn_start_date;
225 RETURN TO_DATE('01/01/'||l_curr_year,'dd/mm/yyyy');
226 ELSE
227 CLOSE c_chk_assgn_start_date;
228 --
229 -- If not valid then return first
230 -- assignment date for that year
231 --
232 OPEN c_get_assgn_start_date;
233 FETCH c_get_assgn_start_date
234 INTO l_assgn_st_date;
235
236 IF c_get_assgn_start_date%FOUND THEN
237 CLOSE c_get_assgn_start_date;
238 RETURN l_assgn_st_date;
239 ELSE
240 CLOSE c_get_assgn_start_date;
241 --
242 -- No assignment found
243 --
244 p_error_message := 'PQP_230205_ASSGN_NOT_EXISTS';
245 p_error_status := trim(to_char(1,'9'));
246 return to_date('31/12/4712','dd/mm/yyyy');
247 END IF;
248 END IF;
249
250 END get_valid_start_date;
251
252 -- ----------------------------------------------------------------------------
253 -- |-----------------------< register_retro_change >---------------------------|
254 -- ----------------------------------------------------------------------------
255 --
256 -- This procedure updates the input value on one of the
257 -- ABP Pensions General Information element input values.
258 -- This is necessary so that the change in the ASG EIT will be
259 -- picked up in the retro notification report.
260 --
261
262 PROCEDURE register_retro_change
263 (p_assignment_id NUMBER
264 ,p_effective_date DATE
265 ) IS
266
267 --
268 -- CURSOR to get the input_value_id
269 --
270 CURSOR c_inp_val IS
271 SELECT piv.input_value_id
272 ,pet.element_type_id
273 FROM pay_input_values_f piv
274 ,pay_element_types_f pet
275 WHERE piv.element_type_id = pet.element_type_id
276 AND pet.element_name = 'ABP Pensions Part Time Percentage'
277 AND piv.name = 'Part Time Percentage'
278 AND pet.legislation_code = 'NL'
279 AND piv.legislation_code = 'NL'
280 AND p_effective_date BETWEEN piv.effective_start_date
281 AND piv.effective_end_date
282 AND p_effective_date BETWEEN pet.effective_start_date
283 AND pet.effective_end_date;
284
285 --
286 -- CURSOR to get the element_entry_id
287 --
288 CURSOR c_ele_ent (c_element_type_id IN NUMBER)IS
289 SELECT pee.element_entry_id
290 FROM pay_element_entries_f pee
291 ,pay_element_links_f pel
292 WHERE pee.element_link_id = pel.element_link_id
293 AND pee.assignment_id = p_assignment_id
294 AND pel.element_type_id = c_element_type_id
295 AND p_effective_date BETWEEN pel.effective_start_date
296 AND pel.effective_end_date
297 AND p_effective_date BETWEEN pee.effective_start_date
298 AND pee.effective_end_date;
299
300 --
301 -- CURSOR to check if valid assignment actions exist and
302 -- payroll has been processed.
303 --
304 CURSOR c_ass_act IS
305 SELECT 1
306 FROM pay_payroll_actions ppa
307 WHERE ppa.action_status = 'C'
308 AND ppa.action_type IN ('Q','R')
309 AND ppa.effective_date >= p_effective_date
310 AND EXISTS ( SELECT 1
311 FROM pay_assignment_actions paa
312 WHERE ppa.payroll_action_id = paa.payroll_action_id
313 AND paa.assignment_id = p_assignment_id
314 AND paa.action_status = 'C' )
315 AND rownum = 1;
316
317 l_element_type_id PAY_ELEMENT_TYPES_F.element_type_id%TYPE;
318 l_input_value_id PAY_INPUT_VALUES_F.input_value_id%TYPE;
319 l_element_entry_id PAY_ELEMENT_ENTRIES_F.element_entry_id%TYPE;
320 l_ass_act NUMBER;
321
322 BEGIN
323
324 --
325 -- Check if the change made is a retrospective change.
326 -- Any changes that are made before the effictive date
327 -- passed in are considered retrospective. The reason is
328 -- the existence of asg acts after the effective date.
329 --
330
331 OPEN c_ass_act;
332 FETCH c_ass_act INTO l_ass_act;
333 --
334 -- Proceed further only if a retrospective change is being made
335 --
336 IF c_ass_act%FOUND THEN
337 --
338 -- Get the value for the element_type and input value
339 --
340 OPEN c_inp_val;
341 FETCH c_inp_val INTO
342 l_input_value_id
343 ,l_element_type_id;
344 --
345 -- Check if the seeded element and input exist
346 --
347 IF c_inp_val%FOUND THEN
348 --
349 -- Get the value for the element_entry_id
350 --
351 OPEN c_ele_ent(l_element_type_id);
352 FETCH c_ele_ent INTO
353 l_element_entry_id;
354 --
355 -- Check if element_entry is found
356 --
357 IF c_ele_ent%NOTFOUND THEN
358 NULL;
359 -- Raise Warning
360 ELSE
361 --
362 -- Update the element entry by calling the API
363 --
364 hr_entry_api.update_element_entry
365 (p_dt_update_mode => 'CORRECTION',
366 p_session_date => p_effective_date,
367 p_element_entry_id => l_element_entry_id,
368 p_input_value_id1 => l_input_value_id,
369 p_entry_value1 => 100,
370 p_entry_information_category => NULL,
371 p_override_user_ent_chk => 'Y'
372 );
373
374 hr_entry_api.update_element_entry
375 (p_dt_update_mode => 'CORRECTION',
376 p_session_date => p_effective_date,
377 p_element_entry_id => l_element_entry_id,
378 p_input_value_id1 => l_input_value_id,
379 p_entry_value1 => NULL,
380 p_entry_information_category => NULL,
381 p_override_user_ent_chk => 'Y'
382 );
383
384 END IF; -- Check if element_entry is found
385
386 CLOSE c_ele_ent;
387
388 END IF; -- Check if the seeded element and input exist
389
390 CLOSE c_inp_val;
391
392 END IF; -- Check if asg acts exist
393
394 CLOSE c_ass_act;
395
396 END register_retro_change;
397
398 --
399 -- ----------------------------------------------------------------------------
400 -- |-----------------------------< cre_ret_ent_ad >---------------------------|
401 -- ----------------------------------------------------------------------------
402 --
403 -- Procedure to create retro entries after the deletion of
404 -- ABP participation and override information from the ASG EIT.
405 --
406 PROCEDURE cre_ret_ent_ad
407 ( p_assignment_extra_info_id_o IN NUMBER
408 ,p_assignment_id_o IN NUMBER
409 ,p_information_type_o IN VARCHAR2
410 ,p_aei_information1_o IN VARCHAR2
411 ,p_aei_information2_o IN VARCHAR2) IS
412 BEGIN
413
414 IF p_information_type_o IN ('NL_ABP_PI','NL_ABP_PAR_INFO') THEN
415 --
416 -- Call the procedure to register this change
417 --
418 register_retro_change
419 (p_assignment_id => p_assignment_id_o
420 ,p_effective_date => trunc(to_date(substr(p_aei_information1_o,1,10)
421 ,'YYYY/MM/DD')));
422 END IF;
423
424 END cre_ret_ent_ad;
425
426 --
427 -- ----------------------------------------------------------------------------
428 -- |-----------------------< chk_dup_pt_row_ins >-----------------------------|
429 -- ----------------------------------------------------------------------------
430 --
431 PROCEDURE chk_dup_pt_row_ins ( p_org_information_id number
432 ,p_org_information_context varchar2
433 ,p_organization_id number
434 ,p_org_information1 varchar2
435 ,p_org_information2 varchar2
436 ,p_org_information3 varchar2
437 ,p_org_information4 varchar2 default null
438 ,p_org_information5 varchar2 default null
439 ,p_org_information6 varchar2 default null
440 ) IS
441 CURSOR cur_abp_pt IS
442 SELECT org_information1
443 ,nvl(org_information2,'4712/12/31') org_information2
444 FROM hr_organization_information
445 WHERE org_information3 = p_org_information3
446 AND organization_id = p_organization_id
447 AND org_information_id <> p_org_information_id
448 AND org_information_context = 'PQP_NL_ABP_PT';
449
450 CURSOR cur_pggm_pt IS
451 SELECT org_information1
452 ,nvl(org_information2,'4712/12/31') org_information2
453 FROM hr_organization_information
454 WHERE org_information3 = p_org_information3
455 AND organization_id = p_organization_id
456 AND org_information_id <> p_org_information_id
457 AND org_information_context = 'PQP_NL_PGGM_PT';
458
459 CURSOR cur_pggm_info IS
460 SELECT org_information1
461 ,nvl(org_information2,'4712/12/31') org_information2
462 FROM hr_organization_information
463 WHERE organization_id = p_organization_id
464 AND org_information_id <> p_org_information_id
465 AND org_information_context = 'PQP_NL_PGGM_INFO';
466
467 --
468 --Cursor to find the pension sub category for the ABP Pension Type
469 --
470 CURSOR cur_get_pen_sub_cat(c_pension_type_id in varchar2) IS
471 SELECT pension_sub_category,
472 threshold_conversion_rule,
473 contribution_conversion_rule,
474 pension_basis_calc_method
475 FROM pqp_pension_types_f
476 WHERE pension_type_id = to_number(c_pension_type_id);
477
478 --
479 --Cursor to find the start and end dates for a particular pension type
480 --
481 CURSOR cur_get_st_end_dates(c_pension_type_id in varchar2) IS
482 SELECT effective_start_date,effective_end_date
483 FROM pqp_pension_types_f
484 WHERE pension_type_id = to_number(c_pension_type_id);
485
486 --cursor to fetch the effective date the user has datetracked to
487 CURSOR c_get_eff_date IS
488 SELECT effective_date
489 FROM fnd_sessions
490 WHERE session_id IN
491 (SELECT userenv('sessionid')
492 FROM dual
493 );
494
495 --
496 --Cursor to find all rows which have dates overlapping the current record dates
497 --
498 CURSOR cur_get_overlap_rows IS
499 SELECT org_information3
500 FROM hr_organization_information
501 WHERE organization_id = p_organization_id
502 AND org_information_id <> p_org_information_id
503 AND org_information_context = 'PQP_NL_ABP_PT'
504 AND ((trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
505 >= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
506 AND trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
507 <= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
508 )
509 OR
510 (trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
511 >= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
512 AND trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
513 <= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
514 )
515 OR
516 (trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
517 <= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
518 AND trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
519 >= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
520 )
521 );
522
523 --Cursor to find the start and end dates of schemes created using the given PT
524 CURSOR cur_get_schm_st_end(c_pension_type_id IN varchar2) IS
525 SELECT to_date(substr(eei_information10,1,10),'DD/MM/YYYY') start_date,
526 to_date(substr(eei_information11,1,10),'DD/MM/YYYY') end_date
527 FROM pay_element_type_extra_info
528 WHERE eei_information_category = 'PQP_NL_ABP_DEDUCTION'
529 AND information_type = 'PQP_NL_ABP_DEDUCTION'
530 AND eei_information2 = c_pension_type_id;
531
532 l_min_start_date DATE;
533 l_max_end_date DATE;
534 l_counter NUMBER := 0;
535 l_pen_sub_cat1 pqp_pension_types_f.pension_sub_category%TYPE;
536 l_pen_sub_cat2 pqp_pension_types_f.pension_sub_category%TYPE;
537 l_thresh_conv_rule1 pqp_pension_types_f.threshold_conversion_rule%TYPE;
538 l_thresh_conv_rule2 pqp_pension_types_f.threshold_conversion_rule%TYPE;
539 l_contrib_conv_rule1 pqp_pension_types_f.contribution_conversion_rule%TYPE;
540 l_contrib_conv_rule2 pqp_pension_types_f.contribution_conversion_rule%TYPE;
541 l_basis_method1 pqp_pension_types_f.pension_basis_calc_method%TYPE;
542 l_basis_method2 pqp_pension_types_f.pension_basis_calc_method%TYPE;
543 l_min_st_dt DATE;
544 l_max_end_dt DATE;
545 l_min_schm_st DATE;
546 l_max_schm_end DATE;
547 l_eff_date DATE;
548
549 BEGIN
550 IF p_org_information_context = 'PQP_NL_ABP_PT' THEN
551
552 --first find the eff date the user had datetracked to
553 OPEN c_get_eff_date;
554 FETCH c_get_eff_date INTO l_eff_date;
555 CLOSE c_get_eff_date;
556
557 --
558 -- Check if the End Date is Less than or equal
559 -- to the Start Date
560 --
561 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
562 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
563 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
564 hr_utility.raise_error;
565 END IF;
566
567 --
568 -- Check to see that the start and end dates entered are between the
569 -- min start date and max end date of the pension type
570 --
571 FOR temp_rec IN cur_get_st_end_dates(p_org_information3)
572 LOOP
573
574 -- Loop through all the date tracked rows of the pension type and find
575 -- the minimum start date and maximum end date
576 IF (l_counter = 0) THEN
577 l_min_st_dt := temp_rec.effective_start_date;
578 l_max_end_dt := temp_rec.effective_end_date;
579 ELSE
580 IF temp_rec.effective_start_date < l_min_st_dt THEN
581 l_min_st_dt := temp_rec.effective_start_date;
582 END IF;
583
584 IF temp_rec.effective_end_date > l_max_end_dt THEN
585 l_max_end_dt := temp_rec.effective_end_date;
586 END IF;
587 END IF;
588
589 l_counter := l_counter + 1;
590
591 END LOOP;
592
593 -- if the start/end date is not between the least start date and
594 -- greatest end date,of all date tracked rows of the PT, raise an error
595 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
596 < l_min_st_dt
597 OR trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
598 > l_max_end_dt THEN
599 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
600 hr_utility.raise_error;
601 END IF;
602
603 l_counter := 0;
604 /*
605 --
606 -- Check to see that atleast one scheme created using the pension
607 -- type exists between the date from and date to
608 --
609 FOR temp_rec IN cur_get_schm_st_end(p_org_information3)
610 LOOP
611
612 -- Loop through all the rows of the element extra info and find
613 -- the minimum start date and maximum end date
614 IF (l_counter = 0) THEN
615 l_min_schm_st := temp_rec.start_date;
616 l_max_schm_end := temp_rec.end_date;
617 ELSE
618 IF temp_rec.start_date < l_min_schm_st THEN
619 l_min_schm_st := temp_rec.start_date;
620 END IF;
621
622 IF temp_rec.end_date > l_max_schm_end THEN
623 l_max_schm_end := temp_rec.end_date;
624 END IF;
625 END IF;
626
627 l_counter := l_counter + 1;
628
629 END LOOP;
630
631 -- if the start/end date is not between the least start date and
632 -- greatest end date,of all element EIT rows of the PT, raise an error
633 IF fnd_date.canonical_to_date(p_org_information1)
634 < l_min_schm_st
635 OR fnd_date.canonical_to_date(nvl(p_org_information2,'4712/12/31'))
636 > l_max_schm_end THEN
637 hr_utility.set_message(8303,'PQP_230070_INV_SCHM_DATES');
638 hr_utility.raise_error;
639 END IF;
640 */
641 l_counter := 0;
642
643 FOR temp_rec IN cur_abp_pt
644 LOOP
645
646 -- We need to check if the pension type row
647 -- being entered now is overlapping with data
648 -- that has already been entered for this
649 -- pension type.
650 -- Here are the cases we check for overlap
651 -- D1 is Old St Date and D2 is Old End Date
652 -- N1 is New St Date and N2 is New End Date
653
654 -------D1----------------------D2-------
655 -------------N1-------N2----------------
656 -------------N1----------------N2-------
657 -------------N1---------------------N2--
658 -------N1-------------N2----------------
659 -------N1----------------------N2-------
660 -------N1---------------------------N2--
661 --N1------------------N2----------------
662 --N1---------------------------N2-------
663 --N1--------------------------------N2--
664 --N1---N2-------------------------------
665 -------------------------------N1---N2--
666
667 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
668 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
669 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
670 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
671 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
672 hr_utility.raise_error;
673 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
674 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
675 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
676 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
677 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
678 hr_utility.raise_error;
679 END IF;
680
681 -- Store the Min Start Date and Max End Date
682 IF l_counter = 0 THEN
683 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
684 ,1,10),'YYYY/MM/DD'));
685 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
686 ,1,10),'YYYY/MM/DD'));
687 ELSE
688 IF trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD'))
689 < l_min_start_date THEN
690 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
691 ,1,10),'YYYY/MM/DD'));
692 END IF;
693
694 IF trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))
695 > l_max_end_date THEN
696 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
697 ,1,10),'YYYY/MM/DD'));
698 END IF;
699 END IF;
700
701 l_counter := l_counter + 1;
702
703 END LOOP;
704
705 -- Check to see if the records are in continuous order
706 -- and there are no gaps (no longer need to chk since gaps are allowed now)
707 /*IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
708 > l_max_end_date + 1 THEN
709 hr_utility.set_message(8303, 'PQP_230042_GAP_EXIST_IN_PT_ROW');
710 hr_utility.raise_error;
711 ELSIF trunc(to_date(substr(p_org_information2,1,10),'YYYY/MM/DD'))
712 < l_min_start_date - 1 THEN
713 hr_utility.set_message(8303, 'PQP_230042_GAP_EXIST_IN_PT_ROW');
714 hr_utility.raise_error;
715 END IF;*/
716
717 --Check to see if the start and end dates encompasses all other rows
718 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
719 <= l_min_start_date AND
720 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
721 >= l_max_end_date THEN
722 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
723 hr_utility.raise_error;
724 END IF;
725
726 --Check to see that there is only one pension type of a particular sub
727 --category and conversion rule on a particular date
728
729 hr_utility.set_location('name'||p_org_information3,7);
730 -- find the pension sub category for the current pension type row
731 OPEN cur_get_pen_sub_cat(p_org_information3);
732 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat1
733 ,l_thresh_conv_rule1
734 ,l_contrib_conv_rule1
735 ,l_basis_method1;
736 CLOSE cur_get_pen_sub_cat;
737 hr_utility.set_location('Current sub category'||l_pen_sub_cat1,10);
738 -- now loop through the rows of all overlapping pension type rows
739 --if a row with the same sub category exists , raise an error
740 FOR temp_rec1 in cur_get_overlap_rows
741 LOOP
742 OPEN cur_get_pen_sub_cat(temp_rec1.org_information3);
743 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat2
744 ,l_thresh_conv_rule2
745 ,l_contrib_conv_rule2
746 ,l_basis_method2;
747 CLOSE cur_get_pen_sub_cat;
748 hr_utility.set_location('pension subcategory'||l_pen_sub_cat2,20);
749 IF l_pen_sub_cat1 = l_pen_sub_cat2
750 AND l_thresh_conv_rule1 = l_thresh_conv_rule2
751 AND l_contrib_conv_rule1 = l_contrib_conv_rule2
752 AND l_basis_method1 = l_basis_method2 THEN
753
754 hr_utility.set_message(8303,'PQP_230046_SAME_SUB_CAT_ERR');
755 hr_utility.raise_error;
756
757 END IF;
758
759 END LOOP;
760 /*--validate that the end date should be greater than or equal to the eff date
761 IF l_eff_date > fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
762 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
763 hr_utility.raise_error;
764 END IF; */
765 --hr_utility.trace_off;
766 --call the procedure to fire insert of the change events in the
767 --ben_ext_chg_evt_log table
768 pqp_nl_ext_functions.create_org_pt_ins_chg_evt
769 (p_organization_id => p_organization_id
770 ,p_org_information1 => p_org_information1
771 ,p_org_information2 => p_org_information2
772 ,p_org_information3 => p_org_information3
773 ,p_org_information6 => p_org_information6
774 ,p_effective_date => l_eff_date
775 );
776
777 ELSIF p_org_information_context = 'PQP_NL_PGGM_PT' THEN
778
779 --first find the eff date the user had datetracked to
780 OPEN c_get_eff_date;
781 FETCH c_get_eff_date INTO l_eff_date;
782 CLOSE c_get_eff_date;
783
784 --
785 -- Check if the End Date is Less than or equal
786 -- to the Start Date
787 --
788 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
789 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
790 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
791 hr_utility.raise_error;
792 END IF;
793
794 --
795 -- Check to see that the start and end dates entered are between the
796 -- min start date and max end date of the pension type
797 --
798 FOR temp_rec IN cur_get_st_end_dates(p_org_information3)
799 LOOP
800
801 -- Loop through all the date tracked rows of the pension type and find
802 -- the minimum start date and maximum end date
803 IF (l_counter = 0) THEN
804 l_min_st_dt := temp_rec.effective_start_date;
805 l_max_end_dt := temp_rec.effective_end_date;
806 ELSE
807 IF temp_rec.effective_start_date < l_min_st_dt THEN
808 l_min_st_dt := temp_rec.effective_start_date;
809 END IF;
810
811 IF temp_rec.effective_end_date > l_max_end_dt THEN
812 l_max_end_dt := temp_rec.effective_end_date;
813 END IF;
814 END IF;
815
816 l_counter := l_counter + 1;
817
818 END LOOP;
819
820 -- if the start/end date is not between the least start date and
821 -- greatest end date,of all date tracked rows of the PT, raise an error
822 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
823 < l_min_st_dt
824 OR trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
825 > l_max_end_dt THEN
826 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
827 hr_utility.raise_error;
828 END IF;
829
830 l_counter := 0;
831
832 FOR temp_rec IN cur_pggm_pt
833 LOOP
834
835 -- We need to check if the pension type row
836 -- being entered now is overlapping with data
837 -- that has already been entered for this
838 -- pension type.
839 -- Here are the cases we check for overlap
840 -- D1 is Old St Date and D2 is Old End Date
841 -- N1 is New St Date and N2 is New End Date
842
843 -------D1----------------------D2-------
844 -------------N1-------N2----------------
845 -------------N1----------------N2-------
846 -------------N1---------------------N2--
847 -------N1-------------N2----------------
848 -------N1----------------------N2-------
849 -------N1---------------------------N2--
850 --N1------------------N2----------------
851 --N1---------------------------N2-------
852 --N1--------------------------------N2--
853 --N1---N2-------------------------------
854 -------------------------------N1---N2--
855
856 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
857 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
858 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
859 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
860 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
861 hr_utility.raise_error;
862 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
863 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
864 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
865 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
866 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
867 hr_utility.raise_error;
868 END IF;
869
870 -- Store the Min Start Date and Max End Date
871 IF l_counter = 0 THEN
872 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
873 ,1,10),'YYYY/MM/DD'));
874 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
875 ,1,10),'YYYY/MM/DD'));
876 ELSE
877 IF trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD'))
878 < l_min_start_date THEN
879 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
880 ,1,10),'YYYY/MM/DD'));
881 END IF;
882
883 IF trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))
884 > l_max_end_date THEN
885 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
886 ,1,10),'YYYY/MM/DD'));
887 END IF;
888 END IF;
889
890 l_counter := l_counter + 1;
891
892 END LOOP;
893
894 --Check to see if the start and end dates encompasses all other rows
895 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
896 <= l_min_start_date AND
897 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
898 >= l_max_end_date THEN
899 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
900 hr_utility.raise_error;
901 END IF;
902
903 --validate that if the total contribution percentage has been entered
904 -- then it should be atleast equal to the employee contribution percentage
905 IF p_org_information5 IS NOT NULL THEN
906 IF fnd_number.canonical_to_number(nvl(p_org_information5,'0'))
907 < fnd_number.canonical_to_number(nvl(p_org_information4,'0')) THEN
908 hr_utility.set_message(8303,'PQP_230215_PGGM_INV_CONTRIB');
909 hr_utility.raise_error;
910 END IF;
911 END IF;
912
913 ELSIF p_org_information_context = 'PQP_NL_PGGM_INFO' THEN
914
915 --first find the eff date the user had datetracked to
916 OPEN c_get_eff_date;
917 FETCH c_get_eff_date INTO l_eff_date;
918 CLOSE c_get_eff_date;
919
920 --
921 -- Check if the End Date is Less than or equal
922 -- to the Start Date
923 --
924 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
925 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
926 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
927 hr_utility.raise_error;
928 END IF;
929
930 l_counter := 0;
931
932 FOR temp_rec IN cur_pggm_info
933 LOOP
934
935 -- We need to check if the pension type row
936 -- being entered now is overlapping with data
937 -- that has already been entered for this
938 -- pension type.
939 -- Here are the cases we check for overlap
940 -- D1 is Old St Date and D2 is Old End Date
941 -- N1 is New St Date and N2 is New End Date
942
943 -------D1----------------------D2-------
944 -------------N1-------N2----------------
945 -------------N1----------------N2-------
946 -------------N1---------------------N2--
947 -------N1-------------N2----------------
948 -------N1----------------------N2-------
949 -------N1---------------------------N2--
950 --N1------------------N2----------------
951 --N1---------------------------N2-------
952 --N1--------------------------------N2--
953 --N1---N2-------------------------------
954 -------------------------------N1---N2--
955
956 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
957 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
958 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
959 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
960 hr_utility.set_message(8303, 'PQP_230219_OVERLAP_ROWS');
961 hr_utility.raise_error;
962 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
963 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
964 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
965 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
966 hr_utility.set_message(8303, 'PQP_230219_OVERLAP_ROWS');
967 hr_utility.raise_error;
968 END IF;
969
970 -- Store the Min Start Date and Max End Date
971 IF l_counter = 0 THEN
972 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
973 ,1,10),'YYYY/MM/DD'));
974 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
975 ,1,10),'YYYY/MM/DD'));
976 ELSE
977 IF trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD'))
978 < l_min_start_date THEN
979 l_min_start_date := trunc(to_date(substr(temp_rec.org_information1
980 ,1,10),'YYYY/MM/DD'));
981 END IF;
982
983 IF trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))
984 > l_max_end_date THEN
985 l_max_end_date := trunc(to_date(substr(temp_rec.org_information2
986 ,1,10),'YYYY/MM/DD'));
987 END IF;
988 END IF;
989
990 l_counter := l_counter + 1;
991
992 END LOOP;
993
994 --Check to see if the start and end dates encompasses all other rows
995 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
996 <= l_min_start_date AND
997 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
998 >= l_max_end_date THEN
999 hr_utility.set_message(8303,'PQP_230219_OVERLAP_ROWS');
1000 hr_utility.raise_error;
1001 END IF;
1002
1003 --if the EIT context is Dutch ABP Provider
1004 ELSIF p_org_information_context = 'PQP_ABP_PROVIDER' THEN
1005 --call the procedure to handle the validations for this EIT context
1006 chk_dup_pp_row_ins(p_org_information_id => p_org_information_id
1007 ,p_org_information_context => p_org_information_context
1008 ,p_organization_id => p_organization_id
1009 ,p_org_information1 => p_org_information1
1010 ,p_org_information2 => p_org_information2
1011 ,p_org_information3 => p_org_information3
1012 );
1013 END IF;
1014
1015 END chk_dup_pt_row_ins;
1016
1017 --
1018 -- ----------------------------------------------------------------------------
1019 -- |-----------------------< chk_dup_pt_row_upd >-----------------------------|
1020 -- ----------------------------------------------------------------------------
1021 --
1022 PROCEDURE chk_dup_pt_row_upd ( p_org_information_id number
1023 ,p_org_information_context varchar2
1024 ,p_organization_id number
1025 ,p_org_information1 varchar2
1026 ,p_org_information2 varchar2
1027 ,p_org_information3 varchar2
1028 ,p_org_information4 varchar2 default null
1029 ,p_org_information5 varchar2 default null
1030 ,p_org_information6 varchar2 default null
1031 ,p_org_information1_o varchar2
1032 ,p_org_information2_o varchar2
1033 ,p_org_information3_o varchar2
1034 ,p_org_information4_o varchar2 default null
1035 ,p_org_information5_o varchar2 default null
1036 ,p_org_information6_o varchar2 default null
1037 ) IS
1038 CURSOR cur_abp_pt IS
1039 SELECT org_information1
1040 ,nvl(org_information2,'4712/12/31') org_information2
1041 FROM hr_organization_information
1042 WHERE org_information3 = p_org_information3
1043 AND organization_id = p_organization_id
1044 AND org_information_id <> p_org_information_id
1045 AND org_information_context = 'PQP_NL_ABP_PT';
1046
1047 CURSOR cur_pggm_pt IS
1048 SELECT org_information1
1049 ,nvl(org_information2,'4712/12/31') org_information2
1050 FROM hr_organization_information
1051 WHERE org_information3 = p_org_information3
1052 AND organization_id = p_organization_id
1053 AND org_information_id <> p_org_information_id
1054 AND org_information_context = 'PQP_NL_PGGM_PT';
1055
1056 CURSOR cur_pggm_info IS
1057 SELECT org_information1
1058 ,nvl(org_information2,'4712/12/31') org_information2
1059 FROM hr_organization_information
1060 WHERE organization_id = p_organization_id
1061 AND org_information_id <> p_org_information_id
1062 AND org_information_context = 'PQP_NL_PGGM_INFO';
1063
1064 --Cursor to find the start and end dates for a particular pension type
1065 CURSOR cur_get_st_end_dates(c_pension_type_id in varchar2) IS
1066 SELECT effective_start_date,effective_end_date
1067 FROM pqp_pension_types_f
1068 WHERE pension_type_id = to_number(c_pension_type_id);
1069
1070 --Cursor to find the pension sub category for the ABP Pension Type
1071 CURSOR cur_get_pen_sub_cat(c_pension_type_id in varchar2) IS
1072 SELECT pension_sub_category
1073 ,threshold_conversion_rule
1074 ,contribution_conversion_rule
1075 ,pension_basis_calc_method
1076 FROM pqp_pension_types_f
1077 WHERE pension_type_id = to_number(c_pension_type_id);
1078
1079 --Cursor to find all rows which have dates overlapping the current record dates
1080 CURSOR cur_get_overlap_rows IS
1081 SELECT org_information3
1082 FROM hr_organization_information
1083 WHERE organization_id = p_organization_id
1084 AND org_information_id <> p_org_information_id
1085 AND org_information_context = 'PQP_NL_ABP_PT'
1086 AND ((trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
1087 >= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1088 AND trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
1089 <= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1090 )
1091 OR
1092 (trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1093 >= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1094 AND trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1095 <= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1096 )
1097 OR
1098 (trunc(to_date(substr(org_information1,1,10),'YYYY/MM/DD'))
1099 <= trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1100 AND trunc(to_date(substr(nvl(org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1101 >= trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1102 )
1103 );
1104
1105 --Cursor to find the start and end dates of schemes created using the given PT
1106 CURSOR cur_get_schm_st_end(c_pension_type_id IN varchar2) IS
1107 SELECT to_date(substr(eei_information10,1,10),'DD/MM/YYYY') start_date,
1108 to_date(substr(eei_information11,1,10),'DD/MM/YYYY') end_date
1109 FROM pay_element_type_extra_info
1110 WHERE eei_information_category = 'PQP_NL_ABP_DEDUCTION'
1111 AND information_type = 'PQP_NL_ABP_DEDUCTION'
1112 AND eei_information2 = c_pension_type_id;
1113
1114 --Cursor to derive the assignment Ids for all assignments with
1115 --payroll actions between the old start and end dates , and which have
1116 -- a run result for this current old pension type
1117 CURSOR c_run_results_exist IS
1118 SELECT paa.assignment_id,ppa.date_earned
1119 FROM pay_assignment_actions paa,pay_payroll_actions ppa
1120 WHERE paa.payroll_action_id = ppa.payroll_action_id
1121 AND ppa.date_earned between
1122 fnd_date.canonical_to_date(p_org_information1_o)
1123 AND fnd_date.canonical_to_date(nvl(p_org_information2_o,fnd_date.date_to_canonical(hr_api.g_eot)))
1124 AND paa.assignment_action_id IN
1125 (SELECT assignment_action_id
1126 FROM pay_run_results
1127 WHERE element_type_id IN
1128 (SELECT element_type_id
1129 FROM pay_element_type_extra_info
1130 WHERE information_type = 'PQP_NL_ABP_DEDUCTION'
1131 AND eei_information_category = 'PQP_NL_ABP_DEDUCTION'
1132 AND eei_information2 = p_org_information3_o
1133 )
1134 );
1135
1136 CURSOR c_get_eff_date IS
1137 SELECT effective_date
1138 FROM fnd_sessions
1139 WHERE session_id IN
1140 (SELECT userenv('sessionid')
1141 FROM dual
1142 );
1143
1144 l_eff_date DATE;
1145 l_min_start_date DATE := NULL;
1146 l_max_end_date DATE := NULL;
1147 l_counter NUMBER := 0;
1148 l_pen_sub_cat1 pqp_pension_types_f.pension_sub_category%TYPE;
1149 l_pen_sub_cat2 pqp_pension_types_f.pension_sub_category%TYPE;
1150 l_thresh_conv_rule1 pqp_pension_types_f.threshold_conversion_rule%TYPE;
1151 l_thresh_conv_rule2 pqp_pension_types_f.threshold_conversion_rule%TYPE;
1152 l_basis_method1 pqp_pension_types_f.pension_basis_calc_method%TYPE;
1153 l_basis_method2 pqp_pension_types_f.pension_basis_calc_method%TYPE;
1154 l_contrib_conv_rule1 pqp_pension_types_f.contribution_conversion_rule%TYPE;
1155 l_contrib_conv_rule2 pqp_pension_types_f.contribution_conversion_rule%TYPE;
1156 l_min_st_dt DATE;
1157 l_max_end_dt DATE;
1158 l_min_schm_st DATE;
1159 l_max_schm_end DATE;
1160 l_allow_update NUMBER := 1;
1161 i NUMBER := 1;
1162 l_asg_or_org NUMBER;
1163 l_org_id NUMBER;
1164 l_date_earned DATE;
1165
1166 BEGIN
1167
1168 OPEN c_get_eff_date;
1169 FETCH c_get_eff_date INTO l_eff_date;
1170 CLOSE c_get_eff_date;
1171
1172 IF p_org_information_context = 'PQP_NL_ABP_PT' THEN
1173 hr_utility.set_location('in update',10);
1174 --check to see if the pension type has been changed. If so, throw an error
1175 IF p_org_information3 <> p_org_information3_o THEN
1176 hr_utility.set_message(8303,'PQP_230100_PT_UPD_NOT_ALLOWED');
1177 hr_utility.raise_error;
1178 END IF;
1179 -- Check if the End Date is Less than or equal
1180 -- to the Start Date
1181 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
1182 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
1183 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
1184 hr_utility.raise_error;
1185 END IF;
1186
1187 -- check to see that the start and end dates entered are between the
1188 -- min start date and max end date of the pension type
1189 FOR temp_rec IN cur_get_st_end_dates(p_org_information3)
1190 LOOP
1191
1192 -- loop through all the date tracked rows of the pension type and find
1193 -- the minimum start date and maximum end date
1194 IF (l_counter = 0) THEN
1195 l_min_st_dt := temp_rec.effective_start_date;
1196 l_max_end_dt := temp_rec.effective_end_date;
1197 ELSE
1198 IF temp_rec.effective_start_date < l_min_st_dt THEN
1199 l_min_st_dt := temp_rec.effective_start_date;
1200 END IF;
1201
1202 IF temp_rec.effective_end_date > l_max_end_dt THEN
1203 l_max_end_dt := temp_rec.effective_end_date;
1204 END IF;
1205 END IF;
1206
1207 l_counter := l_counter + 1;
1208
1209 END LOOP;
1210
1211 -- if the start/end date is not between the least start date and greatest
1212 -- end date,of all date tracked rows of the PT, raise an error
1213 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1214 < l_min_st_dt
1215 OR trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1216 > l_max_end_dt THEN
1217 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
1218 hr_utility.raise_error;
1219 END IF;
1220
1221 l_counter := 0;
1222 /*
1223 --
1224 -- Check to see that atleast one scheme created using the pension
1225 -- type exists between the date from and date to
1226 --
1227 FOR temp_rec IN cur_get_schm_st_end(p_org_information3)
1228 LOOP
1229
1230 -- Loop through all the rows of the element extra info and find
1231 -- the minimum start date and maximum end date
1232 IF (l_counter = 0) THEN
1233 l_min_schm_st := temp_rec.start_date;
1234 l_max_schm_end := temp_rec.end_date;
1235 ELSE
1236 IF temp_rec.start_date < l_min_schm_st THEN
1237 l_min_schm_st := temp_rec.start_date;
1238 END IF;
1239
1240 IF temp_rec.end_date > l_max_schm_end THEN
1241 l_max_schm_end := temp_rec.end_date;
1242 END IF;
1243 END IF;
1244
1245 l_counter := l_counter + 1;
1246
1247 END LOOP;
1248
1249 -- if the start/end date is not between the least start date and
1250 -- greatest end date,of all element EIT rows of the PT, raise an error
1251 IF fnd_date.canonical_to_date(p_org_information1)
1252 < l_min_schm_st
1253 OR fnd_date.canonical_to_date(nvl(p_org_information2,'4712/12/31'))
1254 > l_max_schm_end THEN
1255 hr_utility.set_message(8303,'PQP_230070_INV_SCHM_DATES');
1256 hr_utility.raise_error;
1257 END IF;
1258 */
1259 l_counter := 0;
1260
1261 FOR temp_rec IN cur_abp_pt
1262 LOOP
1263
1264 -- We need to check if the pension type row
1265 -- being entered now is overlapping with data
1266 -- that has already been entered for this
1267 -- pension type.
1268 -- Here are the cases we check for overlap
1269 -- D1 is Old St Date and D2 is Old End Date
1270 -- N1 is New St Date and N2 is New End Date
1271
1272 -------D1----------------------D2-------
1273 -------------N1-------N2----------------
1274 -------------N1----------------N2-------
1275 -------------N1---------------------N2--
1276 -------N1-------------N2----------------
1277 -------N1----------------------N2-------
1278 -------N1---------------------------N2--
1279 --N1------------------N2----------------
1280 --N1---------------------------N2-------
1281 --N1--------------------------------N2--
1282 --N1---N2-------------------------------
1283 -------------------------------N1---N2--
1284
1285 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
1286 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1287 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
1288 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1289 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
1290 hr_utility.raise_error;
1291 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
1292 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1293 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
1294 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1295 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
1296 hr_utility.raise_error;
1297 END IF;
1298
1299 END LOOP;
1300
1301 FOR temp_rec1 IN cur_abp_pt
1302 LOOP
1303 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
1304 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
1305 -- Store the Min Start Date and Max End Date
1306 IF l_counter = 0 THEN
1307 l_min_start_date := trunc(to_date(substr(temp_rec1.org_information1
1308 ,1,10),'YYYY/MM/DD'));
1309 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1310 ,1,10),'YYYY/MM/DD'));
1311 ELSE
1312 IF trunc(to_date(substr(temp_rec1.org_information1,1,10),'YYYY/MM/DD'))
1313 < l_min_start_date THEN
1314 l_min_start_date :=
1315 trunc(to_date(substr(temp_rec1.org_information1
1316 ,1,10),'YYYY/MM/DD'));
1317 END IF;
1318 IF trunc(to_date(substr(temp_rec1.org_information2,1,10),'YYYY/MM/DD'))
1319 > l_max_end_date THEN
1320 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1321 ,1,10),'YYYY/MM/DD'));
1322 END IF;
1323 END IF;
1324 l_counter := l_counter + 1;
1325 END LOOP;
1326 --hr_utility.trace_off;
1327
1328 -- Check to see if the records are in continuous order
1329 -- and there are no gaps (no longer need to chk since gaps are allowed)
1330 /*IF trunc(to_date(substr(p_org_information1_o,1,10),'YYYY/MM/DD'))
1331 > l_min_start_date THEN
1332
1333 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1334 > trunc(to_date(substr(p_org_information1_o,1,10),'YYYY/MM/DD')) THEN
1335
1336 hr_utility.set_message(8303,'PQP_230042_GAP_EXIST_IN_PT_ROW');
1337 hr_utility.raise_error;
1338
1339 ELSIF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1340 < trunc(to_date(substr(p_org_information1_o,1,10),'YYYY/MM/DD')) THEN
1341
1342 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
1343 hr_utility.raise_error;
1344
1345 END IF;
1346
1347 ELSIF trunc(to_date(substr(p_org_information2_o,1,10),'YYYY/MM/DD'))
1348 < l_max_end_date THEN
1349
1350 IF trunc(to_date(substr(p_org_information2,1,10),'YYYY/MM/DD'))
1351 < trunc(to_date(substr(p_org_information2_o,1,10),'YYYY/MM/DD')) THEN
1352
1353 hr_utility.set_message(8303,'PQP_230042_GAP_EXIST_IN_PT_ROW');
1354 hr_utility.raise_error;
1355
1356 ELSIF trunc(to_date(substr(p_org_information2,1,10),'YYYY/MM/DD'))
1357 > trunc(to_date(substr(p_org_information2_o,1,10),'YYYY/MM/DD')) THEN
1358
1359 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
1360 hr_utility.raise_error;
1361
1362 END IF;
1363
1364 END IF;*/
1365
1366 --Check to see if the start and end dates encompasses all other rows
1367 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
1368
1369 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1370 <= l_min_start_date AND
1371 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1372 >= l_max_end_date THEN
1373
1374 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
1375 hr_utility.raise_error;
1376
1377 END IF;
1378
1379 END IF;
1380
1381 --Check to see that there is only one pension type of a particular sub
1382 --category on a particular date
1383
1384 hr_utility.set_location('name'||p_org_information3,7);
1385 -- find the pension sub category for the current pension type row
1386 OPEN cur_get_pen_sub_cat(p_org_information3);
1387 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat1
1388 ,l_thresh_conv_rule1
1389 ,l_contrib_conv_rule1
1390 ,l_basis_method1;
1391 CLOSE cur_get_pen_sub_cat;
1392 hr_utility.set_location('Current sub category'||l_pen_sub_cat1,10);
1393 -- now loop through the rows of all overlapping pension type rows
1394 --if a row with the same sub category exists , raise an error
1395 FOR temp_rec1 in cur_get_overlap_rows
1396 LOOP
1397 OPEN cur_get_pen_sub_cat(temp_rec1.org_information3);
1398 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat2
1399 ,l_thresh_conv_rule2
1400 ,l_contrib_conv_rule2
1401 ,l_basis_method2;
1402 CLOSE cur_get_pen_sub_cat;
1403 hr_utility.set_location('pension subcategory'||l_pen_sub_cat2,20);
1404 IF l_pen_sub_cat1 = l_pen_sub_cat2
1405 AND l_thresh_conv_rule1 = l_thresh_conv_rule2
1406 AND l_contrib_conv_rule1 = l_contrib_conv_rule2
1407 AND l_basis_method1 = l_basis_method2 THEN
1408
1409 hr_utility.set_message(8303,'PQP_230046_SAME_SUB_CAT_ERR');
1410 hr_utility.raise_error;
1411
1412 END IF;
1413 --hr_utility.trace_off;
1414 END LOOP;
1415 hr_utility.set_location('now chking for run results',40);
1416 --check to see if any payroll has been run where enrollment comes from
1417 --this EIT row, if so do not allow an update of this row.
1418 -- also store the last date when payroll has been run so that the end date
1419 -- can be updated to a date after that.
1420 FOR csr_row IN c_run_results_exist
1421 LOOP
1422 hr_utility.set_location('calling get part org',50);
1423 get_participation_org(p_assignment_id => csr_row.assignment_id
1424 ,p_date_earned => csr_row.date_earned
1425 ,p_pension_type_id => fnd_number.canonical_to_number(p_org_information3_o)
1426 ,p_asg_or_org => l_asg_or_org
1427 ,p_org_id => l_org_id
1428 );
1429 IF l_asg_or_org = 1 AND l_org_id = p_organization_id THEN
1430 l_allow_update := 0;
1431
1432 IF i = 1 THEN
1433 l_date_earned := csr_row.date_earned;
1434 i := i + 1;
1435 ELSIF csr_row.date_earned > l_date_earned THEN
1436 l_date_earned := csr_row.date_earned;
1437 END IF;
1438
1439 END IF;
1440 hr_utility.set_location('came back from partn org',60);
1441 END LOOP;
1442 hr_utility.set_location('nw chk if upd is allowd or not',70);
1443
1444 --allow an update of pension type only if the update is allowed
1445 IF l_allow_update = 0 THEN
1446 IF p_org_information3 <> p_org_information3_o THEN
1447 hr_utility.set_message(8303,'PQP_230101_UPD_NOT_ALLOWED');
1448 hr_utility.raise_error;
1449 END IF;
1450 END IF;
1451
1452 /* ELSIF fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot)))
1453 <> fnd_date.canonical_to_date(nvl(p_org_information2_o,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
1454 IF l_eff_date <= l_date_earned OR fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot)))
1455 <= l_date_earned THEN
1456 hr_utility.set_message(8303,'PQP_230102_DT_TO_AFTER_PAY_RUN');
1457 hr_utility.raise_error;
1458 ELSIF l_eff_date > fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
1459 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
1460 hr_utility.raise_error;
1461 END IF;
1462 END IF;
1463 ELSIF l_allow_update = 1 THEN
1464 IF (fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot)))
1465 <> fnd_date.canonical_to_date(nvl(p_org_information2_o,fnd_date.date_to_canonical(hr_api.g_eot))))
1466 AND (l_eff_date > fnd_date.canonical_to_date(nvl(p_org_information2,fnd_date.date_to_canonical(hr_api.g_eot)))) THEN
1467 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
1468 hr_utility.raise_error;
1469 END IF;
1470 END IF; */
1471 hr_utility.set_location('calling insert process',20);
1472 --call the procedure to fire insert of the change events in the
1473 --ben_ext_chg_evt_log table
1474 pqp_nl_ext_functions.create_org_pt_upd_chg_evt
1475 (p_organization_id => p_organization_id
1476 ,p_org_information1 => p_org_information1
1477 ,p_org_information2 => p_org_information2
1478 ,p_org_information3 => p_org_information3
1479 ,p_org_information6 => p_org_information6
1480 ,p_org_information1_o => p_org_information1_o
1481 ,p_org_information2_o => p_org_information2_o
1482 ,p_org_information3_o => p_org_information3_o
1483 ,p_org_information6_o => p_org_information6_o
1484 ,p_effective_date => l_eff_date
1485 );
1486 hr_utility.set_location('leaving',30);
1487
1488 --context is PGGM PT
1489 ELSIF p_org_information_context = 'PQP_NL_PGGM_PT' THEN
1490 hr_utility.set_location('in update',10);
1491 --check to see if the pension type has been changed. If so, throw an error
1492 IF p_org_information3 <> p_org_information3_o THEN
1493 hr_utility.set_message(8303,'PQP_230100_PT_UPD_NOT_ALLOWED');
1494 hr_utility.raise_error;
1495 END IF;
1496 -- Check if the End Date is Less than or equal
1497 -- to the Start Date
1498 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
1499 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
1500 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
1501 hr_utility.raise_error;
1502 END IF;
1503
1504 -- check to see that the start and end dates entered are between the
1505 -- min start date and max end date of the pension type
1506 FOR temp_rec IN cur_get_st_end_dates(p_org_information3)
1507 LOOP
1508
1509 -- loop through all the date tracked rows of the pension type and find
1510 -- the minimum start date and maximum end date
1511 IF (l_counter = 0) THEN
1512 l_min_st_dt := temp_rec.effective_start_date;
1513 l_max_end_dt := temp_rec.effective_end_date;
1514 ELSE
1515 IF temp_rec.effective_start_date < l_min_st_dt THEN
1516 l_min_st_dt := temp_rec.effective_start_date;
1517 END IF;
1518
1519 IF temp_rec.effective_end_date > l_max_end_dt THEN
1520 l_max_end_dt := temp_rec.effective_end_date;
1521 END IF;
1522 END IF;
1523
1524 l_counter := l_counter + 1;
1525
1526 END LOOP;
1527
1528 -- if the start/end date is not between the least start date and greatest
1529 -- end date,of all date tracked rows of the PT, raise an error
1530 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1531 < l_min_st_dt
1532 OR trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1533 > l_max_end_dt THEN
1534 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
1535 hr_utility.raise_error;
1536 END IF;
1537
1538 l_counter := 0;
1539
1540 FOR temp_rec IN cur_pggm_pt
1541 LOOP
1542
1543 -- We need to check if the pension type row
1544 -- being entered now is overlapping with data
1545 -- that has already been entered for this
1546 -- pension type.
1547 -- Here are the cases we check for overlap
1548 -- D1 is Old St Date and D2 is Old End Date
1549 -- N1 is New St Date and N2 is New End Date
1550
1551 -------D1----------------------D2-------
1552 -------------N1-------N2----------------
1553 -------------N1----------------N2-------
1554 -------------N1---------------------N2--
1555 -------N1-------------N2----------------
1556 -------N1----------------------N2-------
1557 -------N1---------------------------N2--
1558 --N1------------------N2----------------
1559 --N1---------------------------N2-------
1560 --N1--------------------------------N2--
1561 --N1---N2-------------------------------
1562 -------------------------------N1---N2--
1563
1564 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
1565 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1566 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
1567 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1568 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
1569 hr_utility.raise_error;
1570 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
1571 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1572 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
1573 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1574 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
1575 hr_utility.raise_error;
1576 END IF;
1577
1578 END LOOP;
1579
1580 FOR temp_rec1 IN cur_pggm_pt
1581 LOOP
1582 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
1583 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
1584 -- Store the Min Start Date and Max End Date
1585 IF l_counter = 0 THEN
1586 l_min_start_date := trunc(to_date(substr(temp_rec1.org_information1
1587 ,1,10),'YYYY/MM/DD'));
1588 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1589 ,1,10),'YYYY/MM/DD'));
1590 ELSE
1591 IF trunc(to_date(substr(temp_rec1.org_information1,1,10),'YYYY/MM/DD'))
1592 < l_min_start_date THEN
1593 l_min_start_date :=
1594 trunc(to_date(substr(temp_rec1.org_information1
1595 ,1,10),'YYYY/MM/DD'));
1596 END IF;
1597 IF trunc(to_date(substr(temp_rec1.org_information2,1,10),'YYYY/MM/DD'))
1598 > l_max_end_date THEN
1599 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1600 ,1,10),'YYYY/MM/DD'));
1601 END IF;
1602 END IF;
1603 l_counter := l_counter + 1;
1604 END LOOP;
1605
1606 --Check to see if the start and end dates encompasses all other rows
1607 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
1608
1609 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1610 <= l_min_start_date AND
1611 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1612 >= l_max_end_date THEN
1613
1614 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
1615 hr_utility.raise_error;
1616
1617 END IF;
1618
1619 END IF;
1620
1621 --validate that if the total contribution percentage has been entered
1622 -- then it should be atleast equal to the employee contribution percentage
1623 IF p_org_information5 IS NOT NULL THEN
1624 IF fnd_number.canonical_to_number(nvl(p_org_information5,'0'))
1625 < fnd_number.canonical_to_number(nvl(p_org_information4,'0')) THEN
1626 hr_utility.set_message(8303,'PQP_230215_PGGM_INV_CONTRIB');
1627 hr_utility.raise_error;
1628 END IF;
1629 END IF;
1630
1631 hr_utility.set_location('leaving',30);
1632
1633 --context is PGGM INFO
1634 ELSIF p_org_information_context = 'PQP_NL_PGGM_INFO' THEN
1635 hr_utility.set_location('in update',10);
1636 -- Check if the End Date is Less than or equal
1637 -- to the Start Date
1638 IF trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
1639 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) THEN
1640 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
1641 hr_utility.raise_error;
1642 END IF;
1643
1644 l_counter := 0;
1645
1646 FOR temp_rec IN cur_pggm_info
1647 LOOP
1648
1649 -- We need to check if the pension type row
1650 -- being entered now is overlapping with data
1651 -- that has already been entered for this
1652 -- pension type.
1653 -- Here are the cases we check for overlap
1654 -- D1 is Old St Date and D2 is Old End Date
1655 -- N1 is New St Date and N2 is New End Date
1656
1657 -------D1----------------------D2-------
1658 -------------N1-------N2----------------
1659 -------------N1----------------N2-------
1660 -------------N1---------------------N2--
1661 -------N1-------------N2----------------
1662 -------N1----------------------N2-------
1663 -------N1---------------------------N2--
1664 --N1------------------N2----------------
1665 --N1---------------------------N2-------
1666 --N1--------------------------------N2--
1667 --N1---N2-------------------------------
1668 -------------------------------N1---N2--
1669
1670 IF (trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) >=
1671 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1672 trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD')) <=
1673 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1674 hr_utility.set_message(8303, 'PQP_230219_OVERLAP_ROWS');
1675 hr_utility.raise_error;
1676 ELSIF (trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
1677 trunc(to_date(substr(temp_rec.org_information1,1,10),'YYYY/MM/DD')) AND
1678 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
1679 trunc(to_date(substr(temp_rec.org_information2,1,10),'YYYY/MM/DD'))) THEN
1680 hr_utility.set_message(8303, 'PQP_230219_OVERLAP_ROWS');
1681 hr_utility.raise_error;
1682 END IF;
1683
1684 END LOOP;
1685
1686 FOR temp_rec1 IN cur_pggm_info
1687 LOOP
1688 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
1689 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
1690 -- Store the Min Start Date and Max End Date
1691 IF l_counter = 0 THEN
1692 l_min_start_date := trunc(to_date(substr(temp_rec1.org_information1
1693 ,1,10),'YYYY/MM/DD'));
1694 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1695 ,1,10),'YYYY/MM/DD'));
1696 ELSE
1697 IF trunc(to_date(substr(temp_rec1.org_information1,1,10),'YYYY/MM/DD'))
1698 < l_min_start_date THEN
1699 l_min_start_date :=
1700 trunc(to_date(substr(temp_rec1.org_information1
1701 ,1,10),'YYYY/MM/DD'));
1702 END IF;
1703 IF trunc(to_date(substr(temp_rec1.org_information2,1,10),'YYYY/MM/DD'))
1704 > l_max_end_date THEN
1705 l_max_end_date := trunc(to_date(substr(temp_rec1.org_information2
1706 ,1,10),'YYYY/MM/DD'));
1707 END IF;
1708 END IF;
1709 l_counter := l_counter + 1;
1710 END LOOP;
1711
1712 --Check to see if the start and end dates encompasses all other rows
1713 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
1714
1715 IF trunc(to_date(substr(p_org_information1,1,10),'YYYY/MM/DD'))
1716 <= l_min_start_date AND
1717 trunc(to_date(substr(nvl(p_org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1718 >= l_max_end_date THEN
1719
1720 hr_utility.set_message(8303,'PQP_230219_OVERLAP_ROWS');
1721 hr_utility.raise_error;
1722
1723 END IF;
1724
1725 END IF;
1726
1727 hr_utility.set_location('leaving',30);
1728
1729 --if the EIT context is PQP_ABP_PROVIDER then
1730 ELSIF p_org_information_context = 'PQP_ABP_PROVIDER' THEN
1731 --call the procedure to handle validations for After Update
1732 chk_dup_pp_row_upd(p_org_information_id => p_org_information_id
1733 ,p_org_information_context => p_org_information_context
1734 ,p_organization_id => p_organization_id
1735 ,p_org_information1 => p_org_information1
1736 ,p_org_information2 => p_org_information2
1737 ,p_org_information3 => p_org_information3
1738 ,p_org_information1_o => p_org_information1_o
1739 ,p_org_information2_o => p_org_information2_o
1740 ,p_org_information3_o => p_org_information3_o
1741 );
1742 END IF;
1743
1744 END chk_dup_pt_row_upd;
1745
1746 --------------------------------------------------------------------------------
1747
1748 PROCEDURE chk_dup_pt_row ( p_org_information_id number
1749 ,p_org_information_context varchar2
1750 ,p_organization_id number
1751 ,p_org_information1 varchar2
1752 ,p_org_information2 varchar2
1753 ,p_org_information3 varchar2
1754 ) IS
1755 begin
1756 null;
1757 end;
1758 --
1759
1760 PROCEDURE gen_dynamic_formula ( p_si_tax_balances IN NUMBER
1761 ,p_formula_string OUT NOCOPY varchar2
1762 ) IS
1763 begin
1764 null;
1765 end;
1766
1767 --
1768 -- ----------------------------------------------------------------------------
1769 -- |------------------< chk_dup_asg_info_row_ins >-----------------------------|
1770 -- ----------------------------------------------------------------------------
1771 --
1772 PROCEDURE chk_dup_asg_info_row_ins (p_assignment_extra_info_id IN number
1773 ,p_assignment_id IN number
1774 ,p_information_type IN varchar2
1775 ,p_aei_information1 IN varchar2
1776 ,p_aei_information2 IN varchar2
1777 ,p_aei_information3 IN varchar2
1778 ,p_aei_information4 IN varchar2
1779 ,p_aei_information5 IN varchar2
1780 ,p_aei_information6 IN varchar2
1781 ,p_aei_information7 IN varchar2
1782 ,p_aei_information8 IN varchar2
1783 ,p_aei_information9 IN varchar2
1784 ,p_aei_information10 IN varchar2
1785 ,p_aei_information11 IN varchar2
1786 ,p_aei_information12 IN varchar2
1787 ,p_aei_information13 IN varchar2
1788 ,p_aei_information14 IN varchar2
1789 ,p_aei_information15 IN varchar2
1790 ,p_aei_information16 IN varchar2
1791 ,p_aei_information20 IN varchar2
1792 ,p_aei_information21 IN varchar2
1793 ,p_aei_information22 IN varchar2
1794 ) IS
1795 CURSOR cur_abp_asg_info IS
1796 SELECT aei_information1
1797 ,nvl(aei_information2,'4712/12/31') aei_information2
1798 FROM per_assignment_extra_info
1799 WHERE aei_information3 = p_aei_information3
1800 AND assignment_id = p_assignment_id
1801 AND assignment_extra_info_id <> p_assignment_extra_info_id
1802 AND aei_information_category = 'NL_ABP_PI'
1803 AND information_type = 'NL_ABP_PI';
1804
1805 CURSOR cur_abp_asg_info1 IS
1806 SELECT aei_information1
1807 ,nvl(aei_information2,'4712/12/31') aei_information2
1808 FROM per_assignment_extra_info
1809 WHERE assignment_id = p_assignment_id
1810 AND assignment_extra_info_id <> p_assignment_extra_info_id
1811 AND aei_information_category = 'NL_ABP_PAR_INFO'
1812 AND information_type = 'NL_ABP_PAR_INFO';
1813
1814 --cursor to find all other rows with the same period number
1815 --and the same savings type
1816 CURSOR cur_sav_asg_info IS
1817 SELECT 1
1818 FROM per_assignment_extra_info
1819 WHERE assignment_id = p_assignment_id
1820 AND assignment_extra_info_id <> p_assignment_extra_info_id
1821 AND aei_information_category = 'NL_SAV_INFO'
1822 AND information_type = 'NL_SAV_INFO'
1823 AND aei_information1 = p_aei_information1
1824 AND aei_information2 = p_aei_information2;
1825
1826 --cursor to fetch the number of periods per year
1827 CURSOR cur_periods_per_yr(c_eff_date IN DATE) IS
1828 SELECT decode(hrl.lookup_code,'W',53,number_per_fiscal_year)
1829 FROM per_time_period_types,hr_lookups hrl
1830 WHERE period_type =
1831 (SELECT period_type
1832 FROM pay_payrolls_f
1833 WHERE payroll_id =
1834 (SELECT payroll_id
1835 FROM per_all_assignments_f
1836 WHERE assignment_id = p_assignment_id
1837 AND c_eff_date BETWEEN effective_start_date
1838 AND nvl(effective_end_date,hr_api.g_eot)
1839 )
1840 AND c_eff_date BETWEEN effective_start_date
1841 AND nvl(effective_end_date,hr_api.g_eot)
1842 )
1843 AND hrl.lookup_type = 'PROC_PERIOD_TYPE'
1844 AND hrl.meaning = period_type;
1845
1846 --Cursor to find the start and end dates for a particular pension type
1847 CURSOR cur_get_st_end_dates(c_pension_type_id in varchar2) IS
1848 SELECT effective_start_date,effective_end_date
1849 FROM pqp_pension_types_f
1850 WHERE pension_type_id = to_number(c_pension_type_id);
1851
1852 --cursor to find all the EIT rows which have a salary override
1853 --and fall in the current year
1854 CURSOR cur_get_sal_rows(c_year IN varchar2) IS
1855 SELECT aei_information1,aei_information2
1856 FROM per_assignment_extra_info
1857 WHERE assignment_id = p_assignment_id
1858 AND assignment_extra_info_id <> p_assignment_extra_info_id
1859 AND aei_information_category = 'NL_ABP_PAR_INFO'
1860 AND information_type = 'NL_ABP_PAR_INFO'
1861 AND to_char(trunc(fnd_date.canonical_to_date(aei_information1)),'YYYY')
1862 = c_year
1863 AND to_char(trunc(fnd_date.canonical_to_date(nvl(aei_information2,
1864 fnd_date.date_to_canonical(hr_api.g_eot)))),'YYYY')
1865 = c_year
1866 AND aei_information6 IS NOT NULL;
1867
1868 --Cursor to find the pension sub category for the ABP Pension Type
1869 CURSOR cur_get_pen_sub_cat(c_pension_type_id in varchar2) IS
1870 SELECT pension_sub_category
1871 ,threshold_conversion_rule
1872 ,contribution_conversion_rule
1873 ,pension_basis_calc_method
1874 FROM pqp_pension_types_f
1875 WHERE pension_type_id = to_number(c_pension_type_id);
1876
1877 --Cursor to find all rows which have dates overlapping the current record dates
1878 CURSOR cur_get_overlap_rows IS
1879 SELECT aei_information3
1880 FROM per_assignment_extra_info
1881 WHERE assignment_id = p_assignment_id
1882 AND assignment_extra_info_id <> p_assignment_extra_info_id
1883 AND aei_information_category = 'NL_ABP_PI'
1884 AND information_type = 'NL_ABP_PI'
1885 AND ((trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
1886 >= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
1887 AND trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
1888 <= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1889 )
1890 OR
1891 (trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1892 >= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
1893 AND trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1894 <= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1895 )
1896 OR
1897 (trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
1898 <= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
1899 AND trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1900 >= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
1901 )
1902 );
1903
1904 --Cursor to fetch the hire date of the employee
1905 CURSOR c_get_hire_date(c_eff_date in date) IS
1906 SELECT max(date_start)
1907 FROM per_all_assignments_f asg
1908 ,per_periods_of_service pps
1909 WHERE pps.person_id = asg.person_id
1910 AND asg.assignment_id = p_assignment_id
1911 AND pps.business_group_id = asg.business_group_id
1912 AND date_start <= c_eff_date;
1913
1914 --Cursor to find the start and end dates of schemes created using the given PT
1915 CURSOR cur_get_schm_st_end(c_pension_type_id IN varchar2) IS
1916 SELECT to_date(substr(eei_information10,1,10),'DD/MM/YYYY') start_date,
1917 to_date(substr(eei_information11,1,10),'DD/MM/YYYY') end_date
1918 FROM pay_element_type_extra_info
1919 WHERE eei_information_category = 'PQP_NL_ABP_DEDUCTION'
1920 AND information_type = 'PQP_NL_ABP_DEDUCTION'
1921 AND eei_information2 = c_pension_type_id;
1922
1923 CURSOR c_get_person_id IS
1924 Select person_id from per_all_assignments_f
1925 where assignment_id = p_assignment_id;
1926
1927 CURSOR c_get_eff_date IS
1928 SELECT effective_date
1929 FROM fnd_sessions
1930 WHERE session_id = userenv('sessionid');
1931
1932 CURSOR cur_ret_addl_info_calc IS
1933 SELECT aei_information1
1934 ,nvl(aei_information2,'4712/12/31') aei_information2
1935 FROM per_assignment_extra_info
1936 WHERE assignment_id = p_assignment_id
1937 AND assignment_extra_info_id <> p_assignment_extra_info_id
1938 AND aei_information_category = 'NL_ADDL_CALC'
1939 AND information_type = 'NL_ADDL_CALC';
1940
1941 l_min_start_date DATE;
1942 l_max_end_date DATE;
1943 l_counter NUMBER := 0;
1944 l_pen_sub_cat1 pqp_pension_types_f.pension_sub_category%TYPE;
1945 l_pen_sub_cat2 pqp_pension_types_f.pension_sub_category%TYPE;
1946 l_thresh_conv_rule1 pqp_pension_types_f.threshold_conversion_rule%TYPE;
1947 l_thresh_conv_rule2 pqp_pension_types_f.threshold_conversion_rule%TYPE;
1948 l_contrib_conv_rule1 pqp_pension_types_f.contribution_conversion_rule%TYPE;
1949 l_contrib_conv_rule2 pqp_pension_types_f.contribution_conversion_rule%TYPE;
1950 l_basis_method1 pqp_pension_types_f.pension_basis_calc_method%TYPE;
1951 l_basis_method2 pqp_pension_types_f.pension_basis_calc_method%TYPE;
1952 l_min_st_dt DATE;
1953 l_max_end_dt DATE;
1954 l_hire_date DATE;
1955 l_min_schm_st DATE;
1956 l_max_schm_end DATE;
1957 l_log_id number;
1958 l_ovn number;
1959 l_person_id number;
1960 l_eff_date DATE;
1961 l_abp_rep_date DATE;
1962 l_asg_sav_info_exists NUMBER;
1963 l_periods_per_yr NUMBER;
1964 l_curr_year VARCHAR2(4);
1965 l_start_year VARCHAR2(4);
1966 l_end_year VARCHAR2(4);
1967 l_min_sal_start DATE := null;
1968 l_max_sal_end DATE := null;
1969 l_error_status CHAR :='0';
1970 l_error_message VARCHAR2(100);
1971 l_ret_val NUMBER;
1972
1973 BEGIN
1974 hr_utility.set_location('entered chkdupasginfo'||p_information_type,5);
1975 Open c_get_person_id;
1976 Fetch c_get_person_id INTO l_person_id;
1977 CLOSE c_get_person_id;
1978 hr_utility.set_location('person id : '||l_person_id,7);
1979
1980 --fetch the effective date first
1981 OPEN c_get_eff_date;
1982 FETCH c_get_eff_date INTO l_eff_date;
1983 CLOSE c_get_eff_date;
1984 hr_utility.set_location('eff date : '||l_eff_date,9);
1985
1986 IF p_information_type = 'NL_ABP_PI' THEN
1987
1988 -- Check if the End Date is Less than or equal
1989 -- to the Start Date
1990 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
1991 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
1992 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
1993 hr_utility.raise_error;
1994 END IF;
1995
1996 -- check to see that the start and end dates entered are between the
1997 -- min start date and max end date of the pension type
1998 FOR temp_rec IN cur_get_st_end_dates(p_aei_information3)
1999 LOOP
2000
2001 -- loop through all the date tracked rows of the pension type and find
2002 -- the minimum start date and maximum end date
2003 IF (l_counter = 0) THEN
2004 l_min_st_dt := temp_rec.effective_start_date;
2005 l_max_end_dt := temp_rec.effective_end_date;
2006 ELSE
2007 IF temp_rec.effective_start_date < l_min_st_dt THEN
2008 l_min_st_dt := temp_rec.effective_start_date;
2009 END IF;
2010
2011 IF temp_rec.effective_end_date > l_max_end_dt THEN
2012 l_max_end_dt := temp_rec.effective_end_date;
2013 END IF;
2014 END IF;
2015
2016 l_counter := l_counter + 1;
2017
2018 END LOOP;
2019
2020 -- if the start/end date is not between the least start date and greatest end date,
2021 -- of all date tracked rows of the PT, raise an error
2022 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2023 < l_min_st_dt
2024 OR trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2025 > l_max_end_dt THEN
2026 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
2027 hr_utility.raise_error;
2028 END IF;
2029
2030 l_counter := 0;
2031 /*
2032 --
2033 -- Check to see that atleast one scheme created using the pension
2034 -- type exists between the date from and date to
2035 --
2036 FOR temp_rec IN cur_get_schm_st_end(p_aei_information3)
2037 LOOP
2038
2039 -- Loop through all the rows of the element extra info and find
2040 -- the minimum start date and maximum end date
2041 IF (l_counter = 0) THEN
2042 l_min_schm_st := temp_rec.start_date;
2043 l_max_schm_end := temp_rec.end_date;
2044 ELSE
2045 IF temp_rec.start_date < l_min_schm_st THEN
2046 l_min_schm_st := temp_rec.start_date;
2047 END IF;
2048
2049 IF temp_rec.end_date > l_max_schm_end THEN
2050 l_max_schm_end := temp_rec.end_date;
2051 END IF;
2052 END IF;
2053
2054 l_counter := l_counter + 1;
2055
2056 END LOOP;
2057
2058 -- if the start/end date is not between the least start date and
2059 -- greatest end date,of all element EIT rows of the PT, raise an error
2060 IF fnd_date.canonical_to_date(p_aei_information1)
2061 < l_min_schm_st
2062 OR fnd_date.canonical_to_date(nvl(p_aei_information2,'4712/12/31'))
2063 > l_max_schm_end THEN
2064 hr_utility.set_message(8303,'PQP_230070_INV_SCHM_DATES');
2065 hr_utility.raise_error;
2066 END IF;
2067 */
2068 l_counter := 0;
2069
2070 FOR temp_rec IN cur_abp_asg_info
2071 LOOP
2072
2073 -- We need to check if the pension type row
2074 -- being entered now is overlapping with data
2075 -- that has already been entered for this
2076 -- pension type.
2077 -- Here are the cases we check for overlap
2078 -- D1 is Old St Date and D2 is Old End Date
2079 -- N1 is New St Date and N2 is New End Date
2080
2081 -------D1----------------------D2-------
2082 -------------N1-------N2----------------
2083 -------------N1----------------N2-------
2084 -------------N1---------------------N2--
2085 -------N1-------------N2----------------
2086 -------N1----------------------N2-------
2087 -------N1---------------------------N2--
2088 --N1------------------N2----------------
2089 --N1---------------------------N2-------
2090 --N1--------------------------------N2--
2091 --N1---N2-------------------------------
2092 -------------------------------N1---N2--
2093
2094 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
2095 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2096 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
2097 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2098 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
2099 hr_utility.raise_error;
2100 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
2101 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2102 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
2103 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2104 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
2105 hr_utility.raise_error;
2106 END IF;
2107
2108 -- Store the Min Start Date and Max End Date
2109 IF l_counter = 0 THEN
2110 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2111 ,1,10),'YYYY/MM/DD'));
2112 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2113 ,1,10),'YYYY/MM/DD'));
2114 ELSE
2115 IF trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD'))
2116 < l_min_start_date THEN
2117 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2118 ,1,10),'YYYY/MM/DD'));
2119 END IF;
2120
2121 IF trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))
2122 > l_max_end_date THEN
2123 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2124 ,1,10),'YYYY/MM/DD'));
2125 END IF;
2126 END IF;
2127
2128 l_counter := l_counter + 1;
2129
2130 END LOOP;
2131
2132 -- Check to see if the records are in continuous order
2133 -- and there are no gaps (no longer need to chk since gaps are allowed)
2134 /*IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2135 > l_max_end_date + 1 THEN
2136 hr_utility.set_message(8303, 'PQP_230042_GAP_EXIST_IN_PT_ROW');
2137 hr_utility.raise_error;
2138 ELSIF trunc(to_date(substr(p_aei_information2,1,10),'YYYY/MM/DD'))
2139 < l_min_start_date - 1 THEN
2140 hr_utility.set_message(8303, 'PQP_230042_GAP_EXIST_IN_PT_ROW');
2141 hr_utility.raise_error;
2142 END IF;*/
2143
2144 --Check to see if the start and end dates encompasses all other rows
2145 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2146 <= l_min_start_date AND
2147 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2148 >= l_max_end_date THEN
2149 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
2150 hr_utility.raise_error;
2151 END IF;
2152
2153 --Check to see that there is only one pension type of a particular sub
2154 --category and conversion rule on a particular date
2155
2156 hr_utility.set_location('name'||p_aei_information3,7);
2157 -- find the pension sub category for the current pension type row
2158 OPEN cur_get_pen_sub_cat(p_aei_information3);
2159 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat1
2160 ,l_thresh_conv_rule1
2161 ,l_contrib_conv_rule1
2162 ,l_basis_method1;
2163 CLOSE cur_get_pen_sub_cat;
2164 hr_utility.set_location('Current sub category'||l_pen_sub_cat1,10);
2165 -- now loop through the rows of all overlapping pension type rows
2166 --if a row with the same sub category exists , raise an error
2167 FOR temp_rec1 in cur_get_overlap_rows
2168 LOOP
2169 OPEN cur_get_pen_sub_cat(temp_rec1.aei_information3);
2170 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat2
2171 ,l_thresh_conv_rule2
2172 ,l_contrib_conv_rule2
2173 ,l_basis_method2;
2174 CLOSE cur_get_pen_sub_cat;
2175 hr_utility.set_location('pension subcategory'||l_pen_sub_cat2,20);
2176 IF l_pen_sub_cat1 = l_pen_sub_cat2
2177 AND l_thresh_conv_rule1 = l_thresh_conv_rule2
2178 AND l_contrib_conv_rule1 = l_contrib_conv_rule2
2179 AND l_basis_method1 = l_basis_method2 THEN
2180
2181 hr_utility.set_message(8303,'PQP_230046_SAME_SUB_CAT_ERR');
2182 hr_utility.raise_error;
2183
2184 END IF;
2185
2186 END LOOP;
2187
2188 -- if the contribution method is PE the value should be between 0 and 999.999
2189 IF nvl(p_aei_information13,'PE') = 'PE' THEN
2190 IF fnd_number.canonical_to_number(nvl(p_aei_information14,'0')) > 999.999 THEN
2191 hr_utility.set_message(8303,'PQP_230052_INV_PERCENT_VALUE');
2192 hr_utility.raise_error;
2193 END IF;
2194 END IF;
2195
2196 -- if the contribution method is PE the value should be between 0 and 999.999
2197 IF nvl(p_aei_information15,'PE') = 'PE' THEN
2198 IF fnd_number.canonical_to_number(nvl(p_aei_information16,'0')) > 999.999 THEN
2199 hr_utility.set_message(8303,'PQP_230052_INV_PERCENT_VALUE');
2200 hr_utility.raise_error;
2201 END IF;
2202 END IF;
2203
2204 --validate that the Date From is equal to or greater than the hire date
2205 OPEN c_get_hire_date(l_eff_date);
2206 FETCH c_get_hire_date INTO l_hire_date;
2207 CLOSE c_get_hire_date;
2208 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2209 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
2210 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
2211 hr_utility.raise_error;
2212 END IF;
2213
2214 --validate that if the override value is entered , the reason is also entered
2215 IF ((p_aei_information7 IS NOT NULL) AND (p_aei_information8 IS NULL)
2216 OR (p_aei_information9 IS NOT NULL) AND (p_aei_information10 IS NULL)
2217 OR (p_aei_information11 IS NOT NULL) AND (p_aei_information12 IS NULL)
2218 OR (p_aei_information20 IS NOT NULL) AND (p_aei_information21 IS NULL)
2219 ) THEN
2220 hr_utility.set_message(8303,'PQP_230056_NO_OVERRIDE_REASON');
2221 hr_utility.raise_error;
2222 END IF;
2223
2224 --validate that only one among Pension Salary,Basis or Contribution is overridden
2225 IF NOT (((p_aei_information7 IS NOT NULL)
2226 AND (p_aei_information9 IS NULL)
2227 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
2228 )
2229 OR
2230 ((p_aei_information9 IS NOT NULL)
2231 AND (p_aei_information7 IS NULL)
2232 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
2233 )
2234 OR
2235 (((p_aei_information11 IS NOT NULL) OR (p_aei_information20 IS NOT NULL))
2236 AND (p_aei_information7 IS NULL)
2237 AND (p_aei_information9 IS NULL)
2238 )
2239 OR
2240 ((p_aei_information7 IS NULL)
2241 AND (p_aei_information9 IS NULL)
2242 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
2243 )) THEN
2244 hr_utility.set_message(8303,'PQP_230057_INVALID_OVERRIDES');
2245 hr_utility.raise_error;
2246 END IF;
2247
2248 --validate that if the override is entered for contribution value, then
2249 -- the contribution type is also entered
2250 /*IF ((p_aei_information13 IS NOT NULL AND p_aei_information14 IS NULL)
2251 OR (p_aei_information13 IS NULL AND p_aei_information14 IS NOT NULL)
2252 OR (p_aei_information15 IS NOT NULL AND p_aei_information16 IS NULL)
2253 OR (p_aei_information15 IS NULL AND p_aei_information16 IS NOT NULL)
2254 ) THEN
2255 hr_utility.set_message(8303,'PQP_230058_INVALID_CONTRIB');
2256 hr_utility.raise_error;
2257 END IF;*/
2258
2259 --this validation has now changed as follows
2260 --the following combinations would occur
2261 /*---------------------------------------------------------------
2262 CONTRIBUTION TYPE CONTRIBUTION VALUE
2263 ---------------------------------------------------------------
2264 null null -- age dependant contribution
2265 null non-null value -- validate this case
2266 PE null -- age dependant contribution
2267 PE non-null value -- normal case
2268 FA null -- validate this case
2269 FA non-null value -- normal case
2270 ---------------------------------------------------------------
2271 */
2272
2273 IF ((p_aei_information13 IS NULL AND p_aei_information14 IS NOT NULL)
2274 OR (p_aei_information15 IS NULL AND p_aei_information16 IS NOT NULL)
2275 ) THEN
2276 hr_utility.set_message(8303,'PQP_230140_INV_CONTRIBUTION');
2277 hr_utility.raise_error;
2278 END IF;
2279
2280 IF ((nvl(p_aei_information13,'PE') = 'FA' AND p_aei_information14 IS NULL)
2281 OR (nvl(p_aei_information15,'PE') = 'FA' AND p_aei_information16 IS NULL)
2282 ) THEN
2283 hr_utility.set_message(8303,'PQP_230058_INVALID_CONTRIB');
2284 hr_utility.raise_error;
2285 END IF;
2286
2287 --validate that if an end date is entered, then end reason should also be entered
2288 IF p_aei_information2 IS NOT NULL AND p_aei_information4 IS NULL THEN
2289 hr_utility.set_message(8303,'PQP_230103_ENTER_END_REASON');
2290 hr_utility.raise_error;
2291 END IF;
2292
2293 /*--validate that the eff date is lesser or equal to the end date
2294 IF l_eff_date > fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
2295 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
2296 hr_utility.raise_error;
2297 END IF; */
2298
2299 --
2300 -- Derive the next abp reporting date
2301 --
2302 l_ret_val := get_reporting_date
2303 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(
2304 fnd_date.canonical_to_date(p_aei_information1)),'YYYY/MM')||'/01')
2305 ,p_assignment_id => fnd_number.canonical_to_number(p_assignment_id)
2306 ,p_person_id => l_person_id
2307 ,p_reporting_date => l_abp_rep_date );
2308
2309 IF p_aei_information22 IS NOT NULL THEN
2310 l_abp_rep_date := fnd_date.canonical_to_date(p_aei_information22);
2311 ELSE
2312 l_abp_rep_date := greatest(l_abp_rep_date,fnd_date.canonical_to_date(p_aei_information1));
2313 END IF;
2314
2315 --call the procedure to insert rows into the ben_ext_chg_evt_log table
2316 pqp_nl_ext_functions.create_asg_info_ins_chg_evt
2317 (p_assignment_id => p_assignment_id
2318 ,p_assignment_extra_info_id => p_assignment_extra_info_id
2319 ,p_aei_information1 => p_aei_information1
2320 ,p_aei_information2 => p_aei_information2
2321 ,p_aei_information3 => p_aei_information3
2322 ,p_aei_information4 => p_aei_information4
2323 ,p_effective_date => l_eff_date
2324 ,p_abp_reporting_date => l_abp_rep_date
2325 );
2326
2327 --
2328 -- Call the procedure to register this change
2329 --
2330 register_retro_change
2331 (p_assignment_id => p_assignment_id
2332 ,p_effective_date => trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')));
2333
2334 ELSIF p_information_type = 'NL_ABP_PAR_INFO' THEN
2335
2336 --fetch the current year from the eff date
2337 l_curr_year := to_char(l_eff_date,'YYYY');
2338 l_start_year := to_char(fnd_date.canonical_to_date(p_aei_information1),'YYYY');
2339 l_end_year := to_char(fnd_date.canonical_to_date(nvl(p_aei_information2,
2340 fnd_date.date_to_canonical(hr_api.g_eot))),'YYYY');
2341
2342 -- Check if the End Date is Less than or equal
2343 -- to the Start Date
2344 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
2345 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2346 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
2347 hr_utility.raise_error;
2348 END IF;
2349
2350 l_counter := 0;
2351
2352 FOR temp_rec IN cur_abp_asg_info1
2353 LOOP
2354
2355 -- We need to check if the pension type row
2356 -- being entered now is overlapping with data
2357 -- that has already been entered for this
2358 -- pension type.
2359 -- Here are the cases we check for overlap
2360 -- D1 is Old St Date and D2 is Old End Date
2361 -- N1 is New St Date and N2 is New End Date
2362
2363 -------D1----------------------D2-------
2364 -------------N1-------N2----------------
2365 -------------N1----------------N2-------
2366 -------------N1---------------------N2--
2367 -------N1-------------N2----------------
2368 -------N1----------------------N2-------
2369 -------N1---------------------------N2--
2370 --N1------------------N2----------------
2371 --N1---------------------------N2-------
2372 --N1--------------------------------N2--
2373 --N1---N2-------------------------------
2374 -------------------------------N1---N2--
2375
2376 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
2377 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2378 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
2379 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2380 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
2381 hr_utility.raise_error;
2382 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
2383 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2384 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
2385 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2386 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
2387 hr_utility.raise_error;
2388 END IF;
2389
2390 -- Store the Min Start Date and Max End Date
2391 IF l_counter = 0 THEN
2392 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2393 ,1,10),'YYYY/MM/DD'));
2394 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2395 ,1,10),'YYYY/MM/DD'));
2396 ELSE
2397 IF trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD'))
2398 < l_min_start_date THEN
2399 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2400 ,1,10),'YYYY/MM/DD'));
2401 END IF;
2402
2403 IF trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))
2404 > l_max_end_date THEN
2405 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2406 ,1,10),'YYYY/MM/DD'));
2407 END IF;
2408 END IF;
2409
2410 l_counter := l_counter + 1;
2411
2412 END LOOP;
2413
2414 --Check to see if the start and end dates encompasses all other rows
2415 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2416 <= l_min_start_date AND
2417 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2418 >= l_max_end_date THEN
2419 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
2420 hr_utility.raise_error;
2421 END IF;
2422
2423 --validate that the Date From is equal to or greater than the hire date
2424 OPEN c_get_hire_date(l_eff_date);
2425 FETCH c_get_hire_date INTO l_hire_date;
2426 CLOSE c_get_hire_date;
2427 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2428 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
2429 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
2430 hr_utility.raise_error;
2431 END IF;
2432
2433 --validate that if the override value is entered , the reason is also entered
2434 IF ((p_aei_information6 IS NOT NULL) AND (p_aei_information7 IS NULL)
2435 OR (p_aei_information8 IS NOT NULL) AND (p_aei_information9 IS NULL)
2436 ) THEN
2437 hr_utility.set_message(8303,'PQP_230056_NO_OVERRIDE_REASON');
2438 hr_utility.raise_error;
2439 END IF;
2440
2441 --validate that only one among Pension Salary,Basis or Contribution is overridden
2442 IF NOT (((p_aei_information6 IS NOT NULL)
2443 AND (p_aei_information8 IS NULL)
2444 )
2445 OR
2446 ((p_aei_information8 IS NOT NULL)
2447 AND (p_aei_information6 IS NULL)
2448 )
2449 OR
2450 ((p_aei_information6 IS NULL)
2451 AND (p_aei_information8 IS NULL)
2452 )
2453 ) THEN
2454 hr_utility.set_message(8303,'PQP_230135_INV_EIT_OVERRIDES');
2455 hr_utility.raise_error;
2456 END IF;
2457
2458 /*--validate that the eff date is lesser or equal to the end date
2459 IF l_eff_date > trunc(fnd_date.canonical_to_date(
2460 nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot)))) THEN
2461 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
2462 hr_utility.raise_error;
2463 END IF;*/
2464
2465 --validations for the salary override rows
2466 IF p_aei_information6 IS NOT NULL THEN
2467
2468 --ensure that the end date is also entered
2469 IF p_aei_information2 IS NULL THEN
2470 hr_utility.set_message(8303,'PQP_230155_ENTER_END_DATE');
2471 hr_utility.raise_error;
2472 END IF;
2473
2474 --ensure that the start date and end date are in the same year
2475 IF NOT ((l_start_year = l_curr_year)
2476 AND (l_end_year = l_curr_year)
2477 ) THEN
2478 hr_utility.set_message(8303,'PQP_230156_ENTER_CURR_YEAR');
2479 hr_utility.raise_error;
2480 END IF;
2481
2482 --find the minimum and maximum start and end dates
2483 l_counter := 0;
2484 FOR temp_rec IN cur_get_sal_rows(l_curr_year)
2485 LOOP
2486 IF l_counter = 0 THEN
2487 l_min_sal_start := fnd_date.canonical_to_date(temp_rec.aei_information1);
2488 l_max_sal_end := fnd_date.canonical_to_date(temp_rec.aei_information2);
2489 ELSE
2490 IF trunc(fnd_date.canonical_to_date(temp_rec.aei_information1))
2491 < l_min_sal_start THEN
2492 l_min_sal_start := trunc(fnd_date.canonical_to_date(temp_rec.aei_information1));
2493 END IF;
2494 IF trunc(fnd_date.canonical_to_date(p_aei_information2))
2495 > l_max_sal_end THEN
2496 l_max_sal_end := trunc(fnd_date.canonical_to_date(temp_rec.aei_information2));
2497 END IF;
2498 END IF;
2499 l_counter := l_counter + 1;
2500 END LOOP;
2501
2502 -- Check to see if the records are in continuous order
2503 -- and there are no gaps
2504 IF l_min_sal_start IS NOT NULL AND l_max_sal_end IS NOT NULL THEN
2505 IF trunc(fnd_date.canonical_to_date(p_aei_information1))
2506 > l_max_sal_end + 1 THEN
2507 hr_utility.set_message(8303, 'PQP_230157_GAP_IN_SAL_ROW');
2508 hr_utility.raise_error;
2509 ELSIF trunc(fnd_date.canonical_to_date(p_aei_information2))
2510 < l_min_sal_start - 1 THEN
2511 hr_utility.set_message(8303, 'PQP_230157_GAP_IN_SAL_ROW');
2512 hr_utility.raise_error;
2513 END IF;
2514 END IF;
2515
2516 IF nvl(l_min_sal_start,fnd_date.canonical_to_date(p_aei_information1))
2517 > fnd_date.canonical_to_date(p_aei_information1) THEN
2518 l_min_sal_start := fnd_date.canonical_to_date(p_aei_information1);
2519 END IF;
2520
2521 --verify that the minimum date is correct date of the year
2522 IF (nvl(l_min_sal_start,fnd_date.canonical_to_date(p_aei_information1))
2523 <> get_valid_start_date(p_assignment_id,l_eff_date,l_error_status,l_error_message)) THEN
2524 hr_utility.set_message(8303,'PQP_230158_ST_DT_JAN_01');
2525 hr_utility.raise_error;
2526 Else
2527 IF (l_error_status = trim(to_char(1,'9'))) Then
2528 hr_utility.set_message(8303,'PQP_230205_ASSGN_NOT_EXISTS');
2529 hr_utility.raise_error;
2530 End IF;
2531 END IF;
2532
2533 END IF; /*End of check if salary has been overridden*/
2534
2535 --
2536 -- Derive the next abp reporting date
2537 --
2538 l_ret_val := get_reporting_date
2539 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(
2540 fnd_date.canonical_to_date(p_aei_information1)),'YYYY/MM')||'/01')
2541 ,p_assignment_id => fnd_number.canonical_to_number(p_assignment_id)
2542 ,p_person_id => l_person_id
2543 ,p_reporting_date => l_abp_rep_date );
2544
2545 --call the procedure to insert rows into the ben_ext_chg_evt_log table
2546 pqp_nl_ext_functions.create_sal_info_ins_chg_evt
2547 (p_assignment_id => p_assignment_id
2548 ,p_assignment_extra_info_id => p_assignment_extra_info_id
2549 ,p_aei_information1 => p_aei_information1
2550 ,p_aei_information2 => p_aei_information2
2551 ,p_aei_information4 => p_aei_information4
2552 ,p_aei_information5 => p_aei_information5
2553 ,p_aei_information6 => p_aei_information6
2554 ,p_effective_date => l_eff_date
2555 ,p_abp_reporting_date => l_abp_rep_date
2556 );
2557
2558 --
2559 -- Call the procedure to register this change
2560 --
2561 register_retro_change
2562 (p_assignment_id => p_assignment_id
2563 ,p_effective_date => trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')));
2564
2565 --if the information context is Social Insurance Information, then call the
2566 --procedure to insert information into the ben log tables
2567 ELSIF p_information_type = 'NL_SII' THEN
2568 pqp_nl_ext_functions.create_si_info_ins_chg_evt
2569 (p_assignment_id => p_assignment_id
2570 ,p_aei_information1 => p_aei_information1
2571 ,p_aei_information2 => p_aei_information2
2572 ,p_aei_information3 => p_aei_information3
2573 ,p_effective_date => l_eff_date
2574 );
2575
2576 --if the information context is Saving Schemes Additional Contribution Informaiton,then
2577 --perform the required validations
2578 ELSIF p_information_type = 'NL_SAV_INFO' THEN
2579 hr_utility.set_location('chking for sav eit',10);
2580 --validate that there is no other EIT row with the same savings type
2581 --and period number combination
2582 OPEN cur_sav_asg_info;
2583 FETCH cur_sav_asg_info INTO l_asg_sav_info_exists;
2584 IF cur_sav_asg_info%FOUND THEN
2585 CLOSE cur_sav_asg_info;
2586 hr_utility.set_location('found same sav info',20);
2587 hr_utility.set_message(8303,'PQP_230141_SAV_INFO_EXISTS');
2588 hr_utility.raise_error;
2589 ELSE
2590 CLOSE cur_sav_asg_info;
2591 END IF;
2592
2593 --validate that the period number entered is not greater than
2594 --the number of payroll periods in a year
2595 OPEN cur_periods_per_yr(c_eff_date => l_eff_date);
2596 FETCH cur_periods_per_yr INTO l_periods_per_yr;
2597 IF cur_periods_per_yr%FOUND THEN
2598 CLOSE cur_periods_per_yr;
2599 hr_utility.set_location('found period number'||l_periods_per_yr,30);
2600 IF fnd_number.canonical_to_number(p_aei_information2) > l_periods_per_yr THEN
2601 hr_utility.set_message(8303,'PQP_230142_INV_PERIOD_NUMBER');
2602 hr_utility.raise_error;
2603 END IF;
2604 ELSE
2605 CLOSE cur_periods_per_yr;
2606 END IF;
2607
2608 --validate that the amount entered is > 0
2609 IF fnd_number.canonical_to_number(p_aei_information3) <= 0 THEN
2610 hr_utility.set_message(8303,'PQP_230149_INV_ADDNL_AMT');
2611 hr_utility.raise_error;
2612 END IF;
2613
2614
2615 ELSIF p_information_type = 'NL_ADDL_CALC' THEN
2616
2617 --fetch the current year from the eff date
2618 --l_curr_year := to_char(l_eff_date,'YYYY');
2619 --l_start_year := to_char(fnd_date.canonical_to_date(p_aei_information1),'YYYY');
2620 --l_end_year := to_char(fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))),'YYYY');
2621
2622 -- Check if the End Date is Less than or equal
2623 -- to the Start Date
2624 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
2625 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2626 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
2627 hr_utility.raise_error;
2628 END IF;
2629
2630 l_counter := 0;
2631
2632 FOR temp_rec IN cur_ret_addl_info_calc
2633 LOOP
2634
2635 -- We need to check if the pension type row
2636 -- being entered now is overlapping with data
2637 -- that has already been entered for this
2638 -- pension type.
2639 -- Here are the cases we check for overlap
2640 -- D1 is Old St Date and D2 is Old End Date
2641 -- N1 is New St Date and N2 is New End Date
2642
2643 -------D1----------------------D2-------
2644 -------------N1-------N2----------------
2645 -------------N1----------------N2-------
2646 -------------N1---------------------N2--
2647 -------N1-------------N2----------------
2648 -------N1----------------------N2-------
2649 -------N1---------------------------N2--
2650 --N1------------------N2----------------
2651 --N1---------------------------N2-------
2652 --N1--------------------------------N2--
2653 --N1---N2-------------------------------
2654 -------------------------------N1---N2--
2655
2656 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
2657 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2658 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
2659 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2660 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
2661 hr_utility.raise_error;
2662 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
2663 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
2664 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
2665 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
2666 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
2667 hr_utility.raise_error;
2668 END IF;
2669
2670 -- Store the Min Start Date and Max End Date
2671 IF l_counter = 0 THEN
2672 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2673 ,1,10),'YYYY/MM/DD'));
2674 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2675 ,1,10),'YYYY/MM/DD'));
2676 ELSE
2677 IF trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD'))
2678 < l_min_start_date THEN
2679 l_min_start_date := trunc(to_date(substr(temp_rec.aei_information1
2680 ,1,10),'YYYY/MM/DD'));
2681 END IF;
2682
2683 IF trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))
2684 > l_max_end_date THEN
2685 l_max_end_date := trunc(to_date(substr(temp_rec.aei_information2
2686 ,1,10),'YYYY/MM/DD'));
2687 END IF;
2688 END IF;
2689
2690 l_counter := l_counter + 1;
2691
2692 END LOOP;
2693
2694 --Check to see if the start and end dates encompasses all other rows
2695 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2696 <= l_min_start_date AND
2697 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2698 >= l_max_end_date THEN
2699 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
2700 hr_utility.raise_error;
2701 END IF;
2702
2703 --validate that the Date From is equal to or greater than the hire date
2704 OPEN c_get_hire_date(l_eff_date);
2705 FETCH c_get_hire_date INTO l_hire_date;
2706 CLOSE c_get_hire_date;
2707
2708 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2709 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
2710 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
2711 hr_utility.raise_error;
2712 END IF;
2713
2714
2715 END IF;
2716 END chk_dup_asg_info_row_ins;
2717
2718 --
2719 -- ----------------------------------------------------------------------------
2720 -- |-----------------------< chk_dup_asg_info_row_upd >-----------------------|
2721 -- ----------------------------------------------------------------------------
2722 --
2723 PROCEDURE chk_dup_asg_info_row_upd ( p_assignment_extra_info_id number
2724 ,p_assignment_id number
2725 ,p_information_type varchar2
2726 ,p_aei_information1 varchar2
2727 ,p_aei_information2 varchar2
2728 ,p_aei_information3 varchar2
2729 ,p_aei_information4 varchar2
2730 ,p_aei_information5 IN varchar2
2731 ,p_aei_information6 IN varchar2
2732 ,p_aei_information7 IN varchar2
2733 ,p_aei_information8 IN varchar2
2734 ,p_aei_information9 IN varchar2
2735 ,p_aei_information10 IN varchar2
2736 ,p_aei_information11 IN varchar2
2737 ,p_aei_information12 IN varchar2
2738 ,p_aei_information13 IN varchar2
2739 ,p_aei_information14 IN varchar2
2740 ,p_aei_information15 IN varchar2
2741 ,p_aei_information16 IN varchar2
2742 ,p_aei_information20 IN varchar2
2743 ,p_aei_information21 IN varchar2
2744 ,p_aei_information22 IN varchar2
2745 ,p_aei_information1_o varchar2
2746 ,p_aei_information2_o varchar2
2747 ,p_aei_information3_o varchar2
2748 ,p_aei_information4_o varchar2
2749 ,p_aei_information5_o IN varchar2
2750 ,p_aei_information6_o IN varchar2
2751 ,p_aei_information7_o IN varchar2
2752 ) IS
2753 CURSOR cur_abp_asg_info IS
2754 SELECT aei_information1
2755 ,nvl(aei_information2,'4712/12/31') aei_information2
2756 FROM per_assignment_extra_info
2757 WHERE aei_information3 = p_aei_information3
2758 AND assignment_id = p_assignment_id
2759 AND assignment_extra_info_id <> p_assignment_extra_info_id
2760 AND aei_information_category = 'NL_ABP_PI'
2761 AND information_type = 'NL_ABP_PI';
2762
2763 CURSOR cur_abp_asg_info1 IS
2764 SELECT aei_information1
2765 ,nvl(aei_information2,'4712/12/31') aei_information2
2766 FROM per_assignment_extra_info
2767 WHERE assignment_id = p_assignment_id
2768 AND assignment_extra_info_id <> p_assignment_extra_info_id
2769 AND aei_information_category = 'NL_ABP_PAR_INFO'
2770 AND information_type = 'NL_ABP_PAR_INFO';
2771
2772 --cursor to find all other rows with the same period number
2773 --and the same savings type
2774 CURSOR cur_sav_asg_info IS
2775 SELECT 1
2776 FROM per_assignment_extra_info
2777 WHERE assignment_id = p_assignment_id
2778 AND assignment_extra_info_id <> p_assignment_extra_info_id
2779 AND aei_information_category = 'NL_SAV_INFO'
2780 AND information_type = 'NL_SAV_INFO'
2781 AND aei_information1 = p_aei_information1
2782 AND aei_information2 = p_aei_information2;
2783
2784 --cursor to find all the EIT rows which have a salary override
2785 --and fall in the current year
2786 CURSOR cur_get_sal_rows(c_year IN varchar2) IS
2787 SELECT aei_information1,aei_information2
2788 FROM per_assignment_extra_info
2789 WHERE assignment_id = p_assignment_id
2790 AND assignment_extra_info_id <> p_assignment_extra_info_id
2791 AND aei_information_category = 'NL_ABP_PAR_INFO'
2792 AND information_type = 'NL_ABP_PAR_INFO'
2793 AND to_char(trunc(fnd_date.canonical_to_date(aei_information1)),'YYYY')
2794 = c_year
2795 AND to_char(trunc(fnd_date.canonical_to_date(nvl(aei_information2,
2796 fnd_date.date_to_canonical(hr_api.g_eot)))),'YYYY')
2797 = c_year
2798 AND aei_information6 IS NOT NULL;
2799
2800 --cursor to fetch the number of periods per year
2801 CURSOR cur_periods_per_yr(c_eff_date IN DATE) IS
2802 SELECT decode(hrl.lookup_code,'W',53,number_per_fiscal_year)
2803 FROM per_time_period_types,hr_lookups hrl
2804 WHERE period_type =
2805 (SELECT period_type
2806 FROM pay_payrolls_f
2807 WHERE payroll_id =
2808 (SELECT payroll_id
2809 FROM per_all_assignments_f
2810 WHERE assignment_id = p_assignment_id
2811 AND c_eff_date BETWEEN effective_start_date
2812 AND nvl(effective_end_date,hr_api.g_eot)
2813 )
2814 AND c_eff_date BETWEEN effective_start_date
2815 AND nvl(effective_end_date,hr_api.g_eot)
2816 )
2817 AND hrl.lookup_type = 'PROC_PERIOD_TYPE'
2818 AND hrl.meaning = period_type;
2819
2820 --Cursor to find the start and end dates for a particular pension type
2821 CURSOR cur_get_st_end_dates(c_pension_type_id in varchar2) IS
2822 SELECT effective_start_date,effective_end_date
2823 FROM pqp_pension_types_f
2824 WHERE pension_type_id = to_number(c_pension_type_id);
2825
2826 --Cursor to find the pension sub category for the ABP Pension Type
2827 CURSOR cur_get_pen_sub_cat(c_pension_type_id in varchar2) IS
2828 SELECT pension_sub_category
2829 ,threshold_conversion_rule
2830 ,contribution_conversion_rule
2831 ,pension_basis_calc_method
2832 FROM pqp_pension_types_f
2833 WHERE pension_type_id = to_number(c_pension_type_id);
2834
2835 --Cursor to find all rows which have dates overlapping the current record dates
2836 CURSOR cur_get_overlap_rows IS
2837 SELECT aei_information3
2838 FROM per_assignment_extra_info
2839 WHERE assignment_id = p_assignment_id
2840 AND assignment_extra_info_id <> p_assignment_extra_info_id
2841 AND information_type = 'NL_ABP_PI'
2842 AND aei_information_category = 'NL_ABP_PI'
2843 AND ((trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
2844 >= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2845 AND trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
2846 <= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2847 )
2848 OR
2849 (trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2850 >= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2851 AND trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2852 <= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2853 )
2854 OR
2855 (trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
2856 <= trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
2857 AND trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2858 >= trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
2859 )
2860 );
2861
2862 --Cursor to fetch the hire date of the employee
2863 CURSOR c_get_hire_date(c_eff_date in date) IS
2864 SELECT max(date_start)
2865 FROM per_all_assignments_f asg
2866 ,per_periods_of_service pps
2867 WHERE pps.person_id = asg.person_id
2868 AND asg.assignment_id = p_assignment_id
2869 AND pps.business_group_id = asg.business_group_id
2870 AND date_start <= c_eff_date;
2871
2872 --Cursor to find the start and end dates of schemes created using the given PT
2873 CURSOR cur_get_schm_st_end(c_pension_type_id IN varchar2) IS
2874 SELECT to_date(substr(eei_information10,1,10),'DD/MM/YYYY') start_date,
2875 to_date(substr(eei_information11,1,10),'DD/MM/YYYY') end_date
2876 FROM pay_element_type_extra_info
2877 WHERE eei_information_category = 'PQP_NL_ABP_DEDUCTION'
2878 AND information_type = 'PQP_NL_ABP_DEDUCTION'
2879 AND eei_information2 = c_pension_type_id;
2880
2881 --cursor to find the eff date
2882 CURSOR c_get_eff_date IS
2883 SELECT effective_date
2884 FROM fnd_sessions
2885 WHERE session_id = userenv('sessionid');
2886
2887 CURSOR c_get_person_id IS
2888 Select person_id from per_all_assignments_f
2889 where assignment_id = p_assignment_id;
2890
2891 CURSOR c_run_results_exist IS
2892 SELECT ppa.date_earned
2893 FROM pay_assignment_actions paa,pay_payroll_actions ppa
2894 WHERE paa.payroll_action_id = ppa.payroll_action_id
2895 AND paa.assignment_id = p_assignment_id
2896 AND ppa.date_earned between
2897 fnd_date.canonical_to_date(p_aei_information1_o)
2898 AND nvl(fnd_date.canonical_to_date(p_aei_information2_o),hr_api.g_eot)
2899 AND paa.assignment_action_id IN
2900 (SELECT assignment_action_id
2901 FROM pay_run_results
2902 WHERE element_type_id IN
2903 (SELECT element_type_id
2904 FROM pay_element_type_extra_info
2905 WHERE information_type = 'PQP_NL_ABP_DEDUCTION'
2906 AND eei_information_category = 'PQP_NL_ABP_DEDUCTION'
2907 AND eei_information2 = p_aei_information3_o
2908 )
2909 );
2910
2911
2912 CURSOR cur_ret_addl_info_calc IS
2913 SELECT aei_information1
2914 ,nvl(aei_information2,'4712/12/31') aei_information2
2915 FROM per_assignment_extra_info
2916 WHERE assignment_id = p_assignment_id
2917 AND assignment_extra_info_id <> p_assignment_extra_info_id
2918 AND aei_information_category = 'NL_ADDL_CALC'
2919 AND information_type = 'NL_ADDL_CALC';
2920
2921
2922 l_min_start_date DATE := NULL;
2923 l_max_end_date DATE := NULL;
2924 l_counter NUMBER := 0;
2925 l_pen_sub_cat1 pqp_pension_types_f.pension_sub_category%TYPE;
2926 l_pen_sub_cat2 pqp_pension_types_f.pension_sub_category%TYPE;
2927 l_thresh_conv_rule1 pqp_pension_types_f.threshold_conversion_rule%TYPE;
2928 l_thresh_conv_rule2 pqp_pension_types_f.threshold_conversion_rule%TYPE;
2929 l_contrib_conv_rule1 pqp_pension_types_f.contribution_conversion_rule%TYPE;
2930 l_contrib_conv_rule2 pqp_pension_types_f.contribution_conversion_rule%TYPE;
2931 l_basis_method1 pqp_pension_types_f.pension_basis_calc_method%TYPE;
2932 l_basis_method2 pqp_pension_types_f.pension_basis_calc_method%TYPE;
2933 l_min_st_dt DATE;
2934 l_max_end_dt DATE;
2935 l_hire_date DATE;
2936 l_min_schm_st DATE;
2937 l_max_schm_end DATE;
2938 l_eff_date DATE;
2939 l_abp_rep_date DATE;
2940 l_allow_update NUMBER := 1;
2941 i NUMBER := 1;
2942 l_date_earned DATE;
2943 l_asg_sav_info_exists NUMBER;
2944 l_periods_per_yr NUMBER;
2945 l_curr_year VARCHAR2(4);
2946 l_start_year VARCHAR2(4);
2947 l_end_year VARCHAR2(4);
2948 l_min_sal_start DATE := null;
2949 l_max_sal_end DATE := null;
2950 l_error_status CHAR :='0';
2951 l_error_message VARCHAR2(100);
2952 l_ret_val NUMBER;
2953 l_person_id NUMBER;
2954
2955 BEGIN
2956
2957 --fetch the eff date
2958 OPEN c_get_eff_date;
2959 FETCH c_get_eff_date INTO l_eff_date;
2960 CLOSE c_get_eff_date;
2961
2962 Open c_get_person_id;
2963 Fetch c_get_person_id INTO l_person_id;
2964 CLOSE c_get_person_id;
2965
2966 IF p_information_type = 'NL_ABP_PI' THEN
2967
2968 --check to see if the pension type has been changed. If so, throw an error
2969 IF p_aei_information3 <> p_aei_information3_o THEN
2970 hr_utility.set_message(8303,'PQP_230100_PT_UPD_NOT_ALLOWED');
2971 hr_utility.raise_error;
2972 END IF;
2973 -- Check if the End Date is Less than or equal
2974 -- to the Start Date
2975 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
2976 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
2977 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
2978 hr_utility.raise_error;
2979 END IF;
2980
2981 -- check to see that the start and end dates entered are between the
2982 -- min start date and max end date of the pension type
2983 FOR temp_rec IN cur_get_st_end_dates(p_aei_information3)
2984 LOOP
2985
2986 -- loop through all the date tracked rows of the pension type and find
2987 -- the minimum start date and maximum end date
2988 IF (l_counter = 0) THEN
2989 l_min_st_dt := temp_rec.effective_start_date;
2990 l_max_end_dt := temp_rec.effective_end_date;
2991 ELSE
2992 IF temp_rec.effective_start_date < l_min_st_dt THEN
2993 l_min_st_dt := temp_rec.effective_start_date;
2994 END IF;
2995
2996 IF temp_rec.effective_end_date > l_max_end_dt THEN
2997 l_max_end_dt := temp_rec.effective_end_date;
2998 END IF;
2999 END IF;
3000
3001 l_counter := l_counter + 1;
3002
3003 END LOOP;
3004
3005 -- if the start/end date is not between the least start date and greatest end date,
3006 -- of all date tracked rows of the PT, raise an error
3007 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3008 < l_min_st_dt
3009 OR trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
3010 > l_max_end_dt THEN
3011 hr_utility.set_message(8303,'PQP_230047_INV_ST_END_DATES');
3012 hr_utility.raise_error;
3013 END IF;
3014
3015 l_counter := 0;
3016 /*
3017 --
3018 -- Check to see that atleast one scheme created using the pension
3019 -- type exists between the date from and date to
3020 --
3021 FOR temp_rec IN cur_get_schm_st_end(p_aei_information3)
3022 LOOP
3023
3024 -- Loop through all the rows of the element extra info and find
3025 -- the minimum start date and maximum end date
3026 IF (l_counter = 0) THEN
3027 l_min_schm_st := temp_rec.start_date;
3028 l_max_schm_end := temp_rec.end_date;
3029 ELSE
3030 IF temp_rec.start_date < l_min_schm_st THEN
3031 l_min_schm_st := temp_rec.start_date;
3032 END IF;
3033
3034 IF temp_rec.end_date > l_max_schm_end THEN
3035 l_max_schm_end := temp_rec.end_date;
3036 END IF;
3037 END IF;
3038
3039 l_counter := l_counter + 1;
3040
3041 END LOOP;
3042
3043 -- if the start/end date is not between the least start date and
3044 -- greatest end date,of all element EIT rows of the PT, raise an error
3045 IF fnd_date.canonical_to_date(p_aei_information1)
3046 < l_min_schm_st
3047 OR fnd_date.canonical_to_date(nvl(p_aei_information2,'4712/12/31'))
3048 > l_max_schm_end THEN
3049 hr_utility.set_message(8303,'PQP_230070_INV_SCHM_DATES');
3050 hr_utility.raise_error;
3051 END IF;
3052 */
3053 l_counter := 0;
3054
3055 FOR temp_rec IN cur_abp_asg_info
3056 LOOP
3057
3058 -- We need to check if the pension type row
3059 -- being entered now is overlapping with data
3060 -- that has already been entered for this
3061 -- pension type.
3062 -- Here are the cases we check for overlap
3063 -- D1 is Old St Date and D2 is Old End Date
3064 -- N1 is New St Date and N2 is New End Date
3065
3066 -------D1----------------------D2-------
3067 -------------N1-------N2----------------
3068 -------------N1----------------N2-------
3069 -------------N1---------------------N2--
3070 -------N1-------------N2----------------
3071 -------N1----------------------N2-------
3072 -------N1---------------------------N2--
3073 --N1------------------N2----------------
3074 --N1---------------------------N2-------
3075 --N1--------------------------------N2--
3076 --N1---N2-------------------------------
3077 -------------------------------N1---N2--
3078
3079 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
3080 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3081 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
3082 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3083 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
3084 hr_utility.raise_error;
3085 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
3086 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3087 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
3088 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3089 hr_utility.set_message(8303, 'PQP_230041_OVERLAP_PT_ROWS');
3090 hr_utility.raise_error;
3091 END IF;
3092
3093 END LOOP;
3094
3095 FOR temp_rec1 IN cur_abp_asg_info
3096 LOOP
3097 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
3098 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
3099 -- Store the Min Start Date and Max End Date
3100 IF l_counter = 0 THEN
3101 l_min_start_date := trunc(to_date(substr(temp_rec1.aei_information1
3102 ,1,10),'YYYY/MM/DD'));
3103 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3104 ,1,10),'YYYY/MM/DD'));
3105 ELSE
3106 IF trunc(to_date(substr(temp_rec1.aei_information1,1,10),'YYYY/MM/DD'))
3107 < l_min_start_date THEN
3108 l_min_start_date :=
3109 trunc(to_date(substr(temp_rec1.aei_information1
3110 ,1,10),'YYYY/MM/DD'));
3111 END IF;
3112
3113 IF trunc(to_date(substr(temp_rec1.aei_information2,1,10),'YYYY/MM/DD'))
3114 > l_max_end_date THEN
3115 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3116 ,1,10),'YYYY/MM/DD'));
3117 END IF;
3118 END IF;
3119 l_counter := l_counter + 1;
3120 END LOOP;
3121 --hr_utility.trace_off;
3122
3123 -- Check to see if the records are in continuous order
3124 -- and there are no gaps (no longer need to chk since gaps are allowed)
3125 /*IF trunc(to_date(substr(p_aei_information1_o,1,10),'YYYY/MM/DD'))
3126 > l_min_start_date THEN
3127
3128 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3129 > trunc(to_date(substr(p_aei_information1_o,1,10),'YYYY/MM/DD')) THEN
3130
3131 hr_utility.set_message(8303,'PQP_230042_GAP_EXIST_IN_PT_ROW');
3132 hr_utility.raise_error;
3133
3134 ELSIF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3135 < trunc(to_date(substr(p_aei_information1_o,1,10),'YYYY/MM/DD')) THEN
3136
3137 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
3138 hr_utility.raise_error;
3139
3140 END IF;
3141
3142 ELSIF trunc(to_date(substr(p_aei_information2_o,1,10),'YYYY/MM/DD'))
3143 < l_max_end_date THEN
3144
3145 IF trunc(to_date(substr(p_aei_information2,1,10),'YYYY/MM/DD'))
3146 < trunc(to_date(substr(p_aei_information2_o,1,10),'YYYY/MM/DD')) THEN
3147
3148 hr_utility.set_message(8303,'PQP_230042_GAP_EXIST_IN_PT_ROW');
3149 hr_utility.raise_error;
3150
3151 ELSIF trunc(to_date(substr(p_aei_information2,1,10),'YYYY/MM/DD'))
3152 > trunc(to_date(substr(p_aei_information2_o,1,10),'YYYY/MM/DD')) THEN
3153
3154 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
3155 hr_utility.raise_error;
3156
3157 END IF;
3158
3159 END IF;*/
3160
3161 --Check to see if the start and end dates encompasses all other rows
3162 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
3163
3164 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3165 <= l_min_start_date AND
3166 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
3167 >= l_max_end_date THEN
3168
3169 hr_utility.set_message(8303,'PQP_230041_OVERLAP_PT_ROWS');
3170 hr_utility.raise_error;
3171
3172 END IF;
3173
3174 END IF;
3175
3176 --Check to see that there is only one pension type of a particular sub
3177 --category on a particular date
3178
3179 hr_utility.set_location('name'||p_aei_information3,7);
3180 -- find the pension sub category for the current pension type row
3181 OPEN cur_get_pen_sub_cat(p_aei_information3);
3182 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat1
3183 ,l_thresh_conv_rule1
3184 ,l_contrib_conv_rule1
3185 ,l_basis_method1;
3186 CLOSE cur_get_pen_sub_cat;
3187 hr_utility.set_location('Current sub category'||l_pen_sub_cat1,10);
3188 -- now loop through the rows of all overlapping pension type rows
3189 --if a row with the same sub category exists , raise an error
3190 FOR temp_rec1 in cur_get_overlap_rows
3191 LOOP
3192 OPEN cur_get_pen_sub_cat(temp_rec1.aei_information3);
3193 FETCH cur_get_pen_sub_cat INTO l_pen_sub_cat2
3194 ,l_thresh_conv_rule2
3195 ,l_contrib_conv_rule2
3196 ,l_basis_method2;
3197 CLOSE cur_get_pen_sub_cat;
3198 hr_utility.set_location('pension subcategory'||l_pen_sub_cat2,20);
3199 IF l_pen_sub_cat1 = l_pen_sub_cat2
3200 AND l_thresh_conv_rule1 = l_thresh_conv_rule2
3201 AND l_contrib_conv_rule1 = l_contrib_conv_rule2
3202 AND l_basis_method1 = l_basis_method2 THEN
3203
3204 hr_utility.set_message(8303,'PQP_230046_SAME_SUB_CAT_ERR');
3205 hr_utility.raise_error;
3206
3207 END IF;
3208 --hr_utility.trace_off;
3209 END LOOP;
3210
3211 -- if the contribution method is PE the value should be between 0 and 999.999
3212 IF nvl(p_aei_information13,'PE') = 'PE' THEN
3213 IF fnd_number.canonical_to_number(nvl(p_aei_information14,'0')) > 999.999 THEN
3214 hr_utility.set_message(8303,'PQP_230052_INV_PERCENT_VALUE');
3215 hr_utility.raise_error;
3216 END IF;
3217 END IF;
3218
3219 -- if the contribution method is PE the value should be between 0 and 999.999
3220 IF nvl(p_aei_information15,'PE') = 'PE' THEN
3221 IF fnd_number.canonical_to_number(nvl(p_aei_information16,'0')) > 999.999 THEN
3222 hr_utility.set_message(8303,'PQP_230052_INV_PERCENT_VALUE');
3223 hr_utility.raise_error;
3224 END IF;
3225 END IF;
3226
3227 --validate that the Date From is equal to or greater than the hire date
3228 OPEN c_get_hire_date(l_eff_date);
3229 FETCH c_get_hire_date INTO l_hire_date;
3230 CLOSE c_get_hire_date;
3231 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
3232 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
3233 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
3234 hr_utility.raise_error;
3235 END IF;
3236
3237 --validate that if the override value is entered , the reason is also entered
3238 IF ((p_aei_information7 IS NOT NULL) AND (p_aei_information8 IS NULL)
3239 OR (p_aei_information9 IS NOT NULL) AND (p_aei_information10 IS NULL)
3240 OR (p_aei_information11 IS NOT NULL) AND (p_aei_information12 IS NULL)
3241 OR (p_aei_information20 IS NOT NULL) AND (p_aei_information21 IS NULL)
3242 ) THEN
3243 hr_utility.set_message(8303,'PQP_230056_NO_OVERRIDE_REASON');
3244 hr_utility.raise_error;
3245 END IF;
3246
3247 --validate that only one among Pension Salary,Basis or Contribution is overridden
3248 IF NOT (((p_aei_information7 IS NOT NULL)
3249 AND (p_aei_information9 IS NULL)
3250 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
3251 )
3252 OR
3253 ((p_aei_information9 IS NOT NULL)
3254 AND (p_aei_information7 IS NULL)
3255 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
3256 )
3257 OR
3258 (((p_aei_information11 IS NOT NULL) OR (p_aei_information20 IS NOT NULL))
3259 AND (p_aei_information7 IS NULL)
3260 AND (p_aei_information9 IS NULL)
3261 )
3262 OR
3263 ((p_aei_information7 IS NULL)
3264 AND (p_aei_information9 IS NULL)
3265 AND ((p_aei_information11 IS NULL) AND (p_aei_information20 IS NULL))
3266 )) THEN
3267 hr_utility.set_message(8303,'PQP_230057_INVALID_OVERRIDES');
3268 hr_utility.raise_error;
3269 END IF;
3270
3271 /*--validate that if the override is entered for contribution value, then
3272 -- the contribution type is also entered
3273 IF ((p_aei_information13 IS NOT NULL AND p_aei_information14 IS NULL)
3274 OR (p_aei_information13 IS NULL AND p_aei_information14 IS NOT NULL)
3275 OR (p_aei_information15 IS NOT NULL AND p_aei_information16 IS NULL)
3276 OR (p_aei_information15 IS NULL AND p_aei_information16 IS NOT NULL)
3277 ) THEN
3278 hr_utility.set_message(8303,'PQP_230058_INVALID_CONTRIB');
3279 hr_utility.raise_error;
3280 END IF; */
3281
3282 --this validation has now changed as follows
3283 --the following combinations would occur
3284 /*---------------------------------------------------------------
3285 CONTRIBUTION TYPE CONTRIBUTION VALUE
3286 ---------------------------------------------------------------
3287 null null -- age dependant contribution
3288 null non-null value -- validate this case
3289 PE null -- age dependant contribution
3290 PE non-null value -- normal case
3291 FA null -- validate this case
3292 FA non-null value -- normal case
3293 ---------------------------------------------------------------
3294 */
3295
3296 IF ((p_aei_information13 IS NULL AND p_aei_information14 IS NOT NULL)
3297 OR (p_aei_information15 IS NULL AND p_aei_information16 IS NOT NULL)
3298 ) THEN
3299 hr_utility.set_message(8303,'PQP_230140_INV_CONTRIBUTION');
3300 hr_utility.raise_error;
3301 END IF;
3302
3303 IF ((nvl(p_aei_information13,'PE') = 'FA' AND p_aei_information14 IS NULL)
3304 OR (nvl(p_aei_information15,'PE') = 'FA' AND p_aei_information16 IS NULL)
3305 ) THEN
3306 hr_utility.set_message(8303,'PQP_230058_INVALID_CONTRIB');
3307 hr_utility.raise_error;
3308 END IF;
3309
3310 /*--validate that if an end date is entered, then end reason should also be entered
3311 IF p_aei_information2 IS NOT NULL AND p_aei_information4 IS NULL THEN
3312 hr_utility.set_message(8303,'PQP_230103_ENTER_END_REASON');
3313 hr_utility.raise_error;
3314 END IF; */
3315
3316 --check to see if update can be allowed on the ASG EIT row
3317 --also fetch the greatest date earned, so that any end date entered
3318 --should be greater than this date
3319 FOR csr_row IN c_run_results_exist
3320 LOOP
3321 l_allow_update := 0;
3322 IF i = 1 THEN
3323 l_date_earned := csr_row.date_earned;
3324 i := i+1;
3325 ELSIF l_date_earned < csr_row.date_earned THEN
3326 l_date_earned := csr_row.date_earned;
3327 END IF;
3328 END LOOP;
3329
3330 --do not allow an update of pension type if an update is not
3331 --allowed
3332 IF l_allow_update = 0 THEN
3333 IF (p_aei_information3 <> p_aei_information3_o) THEN
3334 hr_utility.set_message(8303,'PQP_230101_UPD_NOT_ALLOWED');
3335 hr_utility.raise_error;
3336 END IF;
3337 END IF;
3338
3339 /* ELSIF fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))) <>
3340 fnd_date.canonical_to_date(nvl(p_aei_information2_o,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
3341 IF l_eff_date <= l_date_earned OR fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot)))
3342 <= l_date_earned THEN
3343 hr_utility.set_message(8303,'PQP_230102_DT_TO_AFTER_PAY_RUN');
3344 hr_utility.raise_error;
3345 ELSIF l_eff_date > fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
3346 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
3347 hr_utility.raise_error;
3348 END IF;
3349 END IF;
3350 --else update is allowed
3351 ELSE
3352 IF fnd_date.canonical_to_date(nvl(p_aei_information2_o,fnd_date.date_to_canonical(hr_api.g_eot))) <>
3353 fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
3354 IF l_eff_date > fnd_date.canonical_to_date(nvl(p_aei_information2,fnd_date.date_to_canonical(hr_api.g_eot))) THEN
3355 hr_utility.set_message(8303,'PQP_230099_DT_TO_BEF_END_DT');
3356 hr_utility.raise_error;
3357 END IF;
3358 END IF;
3359 END IF;*/
3360
3361 IF p_aei_information1 <> p_aei_information1_o OR
3362 p_aei_information2 <> p_aei_information2_o OR
3363 p_aei_information22 IS NOT NULL THEN
3364 --
3365 -- Derive the next abp reporting date
3366 --
3367 l_ret_val := get_reporting_date
3368 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(
3369 fnd_date.canonical_to_date(p_aei_information1)),'YYYY/MM')||'/01')
3370 ,p_assignment_id => fnd_number.canonical_to_number(p_assignment_id)
3371 ,p_person_id => l_person_id
3372 ,p_reporting_date => l_abp_rep_date );
3373
3374 IF p_aei_information22 IS NOT NULL THEN
3375 l_abp_rep_date := fnd_date.canonical_to_date(p_aei_information22);
3376 ELSE
3377 l_abp_rep_date := greatest(l_abp_rep_date,fnd_date.canonical_to_date(p_aei_information1));
3378 END IF;
3379
3380 --Call the procedure to insert the rows in the ben_ext_chg_evt_log table
3381 pqp_nl_ext_functions.create_asg_info_upd_chg_evt
3382 (p_assignment_id => p_assignment_id
3383 ,p_assignment_extra_info_id => p_assignment_extra_info_id
3384 ,p_aei_information1 => p_aei_information1
3385 ,p_aei_information2 => p_aei_information2
3386 ,p_aei_information3 => p_aei_information3
3387 ,p_aei_information4 => p_aei_information4
3388 ,p_aei_information1_o => p_aei_information1_o
3389 ,p_aei_information2_o => p_aei_information2_o
3390 ,p_effective_date => l_eff_date
3391 ,p_abp_reporting_date => l_abp_rep_date
3392 );
3393 END IF;
3394
3395 --
3396 -- Call the procedure to register this change
3397 --
3398 register_retro_change
3399 (p_assignment_id => p_assignment_id
3400 ,p_effective_date => LEAST( trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')),
3401 trunc(to_date(substr(p_aei_information1_o,1,10),'YYYY/MM/DD'))));
3402
3403 ELSIF p_information_type = 'NL_ABP_PAR_INFO' THEN
3404
3405 --fetch the current year from the eff date
3406 l_curr_year := to_char(l_eff_date,'YYYY');
3407 l_start_year := to_char(fnd_date.canonical_to_date(p_aei_information1),'YYYY');
3408 l_end_year := to_char(fnd_date.canonical_to_date(nvl(p_aei_information2,
3409 fnd_date.date_to_canonical(hr_api.g_eot))),'YYYY');
3410
3411 -- Check if the End Date is Less than or equal
3412 -- to the Start Date
3413 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
3414 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
3415 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
3416 hr_utility.raise_error;
3417 END IF;
3418
3419 l_counter := 0;
3420
3421 FOR temp_rec IN cur_abp_asg_info1
3422 LOOP
3423
3424 -- We need to check if the pension type row
3425 -- being entered now is overlapping with data
3426 -- that has already been entered for this
3427 -- pension type.
3428 -- Here are the cases we check for overlap
3429 -- D1 is Old St Date and D2 is Old End Date
3430 -- N1 is New St Date and N2 is New End Date
3431
3432 -------D1----------------------D2-------
3433 -------------N1-------N2----------------
3434 -------------N1----------------N2-------
3435 -------------N1---------------------N2--
3436 -------N1-------------N2----------------
3437 -------N1----------------------N2-------
3438 -------N1---------------------------N2--
3439 --N1------------------N2----------------
3440 --N1---------------------------N2-------
3441 --N1--------------------------------N2--
3442 --N1---N2-------------------------------
3443 -------------------------------N1---N2--
3444
3445 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
3446 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3447 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
3448 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3449 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
3450 hr_utility.raise_error;
3451 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
3452 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3453 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
3454 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3455 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
3456 hr_utility.raise_error;
3457 END IF;
3458
3459 END LOOP;
3460
3461 FOR temp_rec1 IN cur_abp_asg_info1
3462 LOOP
3463 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
3464 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
3465 -- Store the Min Start Date and Max End Date
3466 IF l_counter = 0 THEN
3467 l_min_start_date := trunc(to_date(substr(temp_rec1.aei_information1
3468 ,1,10),'YYYY/MM/DD'));
3469 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3470 ,1,10),'YYYY/MM/DD'));
3471 ELSE
3472 IF trunc(to_date(substr(temp_rec1.aei_information1,1,10),'YYYY/MM/DD'))
3473 < l_min_start_date THEN
3474 l_min_start_date :=
3475 trunc(to_date(substr(temp_rec1.aei_information1
3476 ,1,10),'YYYY/MM/DD'));
3477 END IF;
3478
3479 IF trunc(to_date(substr(temp_rec1.aei_information2,1,10),'YYYY/MM/DD'))
3480 > l_max_end_date THEN
3481 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3482 ,1,10),'YYYY/MM/DD'));
3483 END IF;
3484 END IF;
3485 l_counter := l_counter + 1;
3486 END LOOP;
3487 --hr_utility.trace_off;
3488
3489 --Check to see if the start and end dates encompasses all other rows
3490 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
3491
3492 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3493 <= l_min_start_date AND
3494 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
3495 >= l_max_end_date THEN
3496
3497 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
3498 hr_utility.raise_error;
3499
3500 END IF;
3501
3502 END IF;
3503
3504 --validate that the Date From is equal to or greater than the hire date
3505 OPEN c_get_hire_date(l_eff_date);
3506 FETCH c_get_hire_date INTO l_hire_date;
3507 CLOSE c_get_hire_date;
3508 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
3509 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
3510 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
3511 hr_utility.raise_error;
3512 END IF;
3513
3514 --validate that if the override value is entered , the reason is also entered
3515 IF ((p_aei_information6 IS NOT NULL) AND (p_aei_information7 IS NULL)
3516 OR (p_aei_information8 IS NOT NULL) AND (p_aei_information9 IS NULL)
3517 ) THEN
3518 hr_utility.set_message(8303,'PQP_230056_NO_OVERRIDE_REASON');
3519 hr_utility.raise_error;
3520 END IF;
3521
3522 --validate that only one among Pension Salary,Basis is overridden
3523 IF NOT (((p_aei_information6 IS NOT NULL)
3524 AND (p_aei_information8 IS NULL)
3525 )
3526 OR
3527 ((p_aei_information8 IS NOT NULL)
3528 AND (p_aei_information6 IS NULL)
3529 )
3530 OR
3531 ((p_aei_information6 IS NULL)
3532 AND (p_aei_information8 IS NULL)
3533 )) THEN
3534 hr_utility.set_message(8303,'PQP_230135_INV_EIT_OVERRIDES');
3535 hr_utility.raise_error;
3536 END IF;
3537
3538 --validations for the salary override rows
3539 IF p_aei_information6 IS NOT NULL THEN
3540
3541 --ensure that the end date is also entered
3542 IF p_aei_information2 IS NULL THEN
3543 hr_utility.set_message(8303,'PQP_230155_ENTER_END_DATE');
3544 hr_utility.raise_error;
3545 END IF;
3546
3547 --ensure that the start date and end date are in the same year
3548 IF NOT ((l_start_year = l_curr_year)
3549 AND (l_end_year = l_curr_year)
3550 ) THEN
3551 hr_utility.set_message(8303,'PQP_230156_ENTER_CURR_YEAR');
3552 hr_utility.raise_error;
3553 END IF;
3554
3555 --find the minimum and maximum start and end dates
3556 l_counter := 0;
3557 FOR temp_rec IN cur_get_sal_rows(l_curr_year)
3558 LOOP
3559 IF l_counter = 0 THEN
3560 l_min_sal_start := fnd_date.canonical_to_date(temp_rec.aei_information1);
3561 l_max_sal_end := fnd_date.canonical_to_date(temp_rec.aei_information2);
3562 ELSE
3563 IF trunc(fnd_date.canonical_to_date(temp_rec.aei_information1))
3564 < l_min_sal_start THEN
3565 l_min_sal_start := trunc(fnd_date.canonical_to_date(temp_rec.aei_information1));
3566 END IF;
3567 IF trunc(fnd_date.canonical_to_date(p_aei_information2))
3568 > l_max_sal_end THEN
3569 l_max_sal_end := trunc(fnd_date.canonical_to_date(temp_rec.aei_information2));
3570 END IF;
3571 END IF;
3572 l_counter := l_counter + 1;
3573 END LOOP;
3574
3575 -- Check to see if the records are in continuous order
3576 -- and there are no gaps
3577 IF l_min_sal_start IS NOT NULL AND l_max_sal_end IS NOT NULL THEN
3578 IF fnd_date.canonical_to_date(p_aei_information1_o)
3579 > l_min_start_date THEN
3580
3581 IF fnd_date.canonical_to_date(p_aei_information1)
3582 > fnd_date.canonical_to_date(p_aei_information1_o) THEN
3583
3584 hr_utility.set_message(8303,'PQP_230157_GAP_IN_SAL_ROW');
3585 hr_utility.raise_error;
3586
3587 ELSIF fnd_date.canonical_to_date(p_aei_information1)
3588 < fnd_date.canonical_to_date(p_aei_information1_o) THEN
3589
3590 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
3591 hr_utility.raise_error;
3592
3593 END IF;
3594
3595 ELSIF fnd_date.canonical_to_date(p_aei_information2_o)
3596 < l_max_end_date THEN
3597
3598 IF fnd_date.canonical_to_date(p_aei_information2)
3599 < fnd_date.canonical_to_date(p_aei_information2_o) THEN
3600
3601 hr_utility.set_message(8303,'PQP_230157_GAP_IN_SAL_ROW');
3602 hr_utility.raise_error;
3603
3604 ELSIF fnd_date.canonical_to_date(p_aei_information2)
3605 > fnd_date.canonical_to_date(p_aei_information2_o) THEN
3606
3607 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
3608 hr_utility.raise_error;
3609
3610 END IF;
3611
3612 END IF;
3613 END IF;/*only if other rows exist*/
3614
3615 IF nvl(l_min_sal_start,fnd_date.canonical_to_date(p_aei_information1))
3616 > fnd_date.canonical_to_date(p_aei_information1) THEN
3617 l_min_sal_start := fnd_date.canonical_to_date(p_aei_information1);
3618 END IF;
3619
3620 --verify that the minimum date is correct date or not
3621
3622 IF (nvl(l_min_sal_start,fnd_date.canonical_to_date(p_aei_information1))
3623 <> get_valid_start_date(p_assignment_id,l_eff_date,l_error_status,l_error_message)) THEN
3624 hr_utility.set_message(8303,'PQP_230158_ST_DT_JAN_01');
3625 hr_utility.raise_error;
3626 Else
3627 IF (l_error_status = trim(to_char(1,'9'))) Then
3628 hr_utility.set_message(8303,'PQP_230205_ASSGN_NOT_EXISTS');
3629 hr_utility.raise_error;
3630 End IF;
3631 END IF;
3632
3633 END IF; /*End of check if salary has been overridden*/
3634
3635 --
3636 -- Derive the next abp reporting date
3637 --
3638 l_ret_val := get_reporting_date
3639 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(
3640 fnd_date.canonical_to_date(p_aei_information1)),'YYYY/MM')||'/01')
3641 ,p_assignment_id => fnd_number.canonical_to_number(p_assignment_id)
3642 ,p_person_id => l_person_id
3643 ,p_reporting_date => l_abp_rep_date );
3644
3645 --Call the procedure to insert the rows in the ben_ext_chg_evt_log table
3646 pqp_nl_ext_functions.create_sal_info_upd_chg_evt
3647 (p_assignment_id => p_assignment_id
3648 ,p_assignment_extra_info_id => p_assignment_extra_info_id
3649 ,p_aei_information1 => p_aei_information1
3650 ,p_aei_information2 => p_aei_information2
3651 ,p_aei_information4 => p_aei_information4
3652 ,p_aei_information5 => p_aei_information5
3653 ,p_aei_information6 => p_aei_information6
3654 ,p_aei_information1_o => p_aei_information1_o
3655 ,p_aei_information2_o => p_aei_information2_o
3656 ,p_aei_information4_o => p_aei_information4_o
3657 ,p_aei_information5_o => p_aei_information5_o
3658 ,p_aei_information6_o => p_aei_information6_o
3659 ,p_effective_date => l_eff_date
3660 ,p_abp_reporting_date => l_abp_rep_date
3661 );
3662
3663 --
3664 -- Call the procedure to register this change
3665 --
3666 register_retro_change
3667 (p_assignment_id => p_assignment_id
3668 ,p_effective_date => LEAST( trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')),
3669 trunc(to_date(substr(p_aei_information1_o,1,10),'YYYY/MM/DD'))));
3670
3671 --if the information type is Social Insurance Information , then call the extract function
3672 --to insert rows as required into the ben log tables for logging the changes
3673 ELSIF p_information_type = 'NL_SII' THEN
3674 pqp_nl_ext_functions.create_si_info_upd_chg_evt
3675 (p_assignment_id => p_assignment_id
3676 ,p_aei_information1 => p_aei_information1
3677 ,p_aei_information2 => p_aei_information2
3678 ,p_aei_information3 => p_aei_information3
3679 ,p_aei_information1_o => p_aei_information1_o
3680 ,p_aei_information2_o => p_aei_information2_o
3681 ,p_aei_information3_o => p_aei_information3_o
3682 ,p_effective_date => l_eff_date
3683 );
3684
3685 --if the information context is Saving Schemes Additional Contribution Informaiton,then
3686 --perform the required validations
3687 ELSIF p_information_type = 'NL_SAV_INFO' THEN
3688
3689 --validate that there is no other EIT row with the same savings type
3690 --and period number combination
3691 OPEN cur_sav_asg_info;
3692 FETCH cur_sav_asg_info INTO l_asg_sav_info_exists;
3693 IF cur_sav_asg_info%FOUND THEN
3694 CLOSE cur_sav_asg_info;
3695 hr_utility.set_message(8303,'PQP_230141_SAV_INFO_EXISTS');
3696 hr_utility.raise_error;
3697 ELSE
3698 CLOSE cur_sav_asg_info;
3699 END IF;
3700
3701 --validate that the period number entered is not greater than
3702 --the number of payroll periods in a year
3703 OPEN cur_periods_per_yr(c_eff_date => l_eff_date);
3704 FETCH cur_periods_per_yr INTO l_periods_per_yr;
3705 IF cur_periods_per_yr%FOUND THEN
3706 CLOSE cur_periods_per_yr;
3707 IF fnd_number.canonical_to_number(p_aei_information2) > l_periods_per_yr THEN
3708 hr_utility.set_message(8303,'PQP_230142_INV_PERIOD_NUMBER');
3709 hr_utility.raise_error;
3710 END IF;
3711 ELSE
3712 CLOSE cur_periods_per_yr;
3713 END IF;
3714
3715 --validate that the amount entered is > 0
3716 IF fnd_number.canonical_to_number(p_aei_information3) <= 0 THEN
3717 hr_utility.set_message(8303,'PQP_230149_INV_ADDNL_AMT');
3718 hr_utility.raise_error;
3719 END IF;
3720
3721
3722 ELSIF p_information_type = 'NL_ADDL_CALC' THEN
3723
3724 -- Check if the End Date is Less than or equal
3725 -- to the Start Date
3726 IF trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <
3727 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
3728 hr_utility.set_message(8303, 'PQP_230040_END_DT_BEF_ST_DT');
3729 hr_utility.raise_error;
3730 END IF;
3731
3732 l_counter := 0;
3733
3734 FOR temp_rec IN cur_ret_addl_info_calc
3735 LOOP
3736
3737 -- We need to check if the pension type row
3738 -- being entered now is overlapping with data
3739 -- that has already been entered for this
3740 -- pension type.
3741 -- Here are the cases we check for overlap
3742 -- D1 is Old St Date and D2 is Old End Date
3743 -- N1 is New St Date and N2 is New End Date
3744
3745 -------D1----------------------D2-------
3746 -------------N1-------N2----------------
3747 -------------N1----------------N2-------
3748 -------------N1---------------------N2--
3749 -------N1-------------N2----------------
3750 -------N1----------------------N2-------
3751 -------N1---------------------------N2--
3752 --N1------------------N2----------------
3753 --N1---------------------------N2-------
3754 --N1--------------------------------N2--
3755 --N1---N2-------------------------------
3756 -------------------------------N1---N2--
3757
3758 IF (trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) >=
3759 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3760 trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) <=
3761 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3762 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
3763 hr_utility.raise_error;
3764 ELSIF (trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) >=
3765 trunc(to_date(substr(temp_rec.aei_information1,1,10),'YYYY/MM/DD')) AND
3766 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD')) <=
3767 trunc(to_date(substr(temp_rec.aei_information2,1,10),'YYYY/MM/DD'))) THEN
3768 hr_utility.set_message(8303, 'PQP_230134_EIT_OVERLAP_ROWS');
3769 hr_utility.raise_error;
3770 END IF;
3771
3772 END LOOP;
3773
3774 FOR temp_rec1 IN cur_ret_addl_info_calc
3775 LOOP
3776 -- hr_utility.set_location('start date'||temp_rec1.org_information1,10);
3777 -- hr_utility.set_location('end date'||temp_rec1.org_information2,20);
3778 -- Store the Min Start Date and Max End Date
3779 IF l_counter = 0 THEN
3780 l_min_start_date := trunc(to_date(substr(temp_rec1.aei_information1
3781 ,1,10),'YYYY/MM/DD'));
3782 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3783 ,1,10),'YYYY/MM/DD'));
3784 ELSE
3785 IF trunc(to_date(substr(temp_rec1.aei_information1,1,10),'YYYY/MM/DD'))
3786 < l_min_start_date THEN
3787 l_min_start_date :=
3788 trunc(to_date(substr(temp_rec1.aei_information1
3789 ,1,10),'YYYY/MM/DD'));
3790 END IF;
3791
3792 IF trunc(to_date(substr(temp_rec1.aei_information2,1,10),'YYYY/MM/DD'))
3793 > l_max_end_date THEN
3794 l_max_end_date := trunc(to_date(substr(temp_rec1.aei_information2
3795 ,1,10),'YYYY/MM/DD'));
3796 END IF;
3797 END IF;
3798 l_counter := l_counter + 1;
3799 END LOOP;
3800 --hr_utility.trace_off;
3801
3802 --Check to see if the start and end dates encompasses all other rows
3803 IF l_min_start_date IS NOT NULL AND l_max_end_date IS NOT NULL THEN
3804
3805 IF trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD'))
3806 <= l_min_start_date AND
3807 trunc(to_date(substr(nvl(p_aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'))
3808 >= l_max_end_date THEN
3809
3810 hr_utility.set_message(8303,'PQP_230134_EIT_OVERLAP_ROWS');
3811 hr_utility.raise_error;
3812
3813 END IF;
3814
3815 END IF;
3816
3817 --validate that the Date From is equal to or greater than the hire date
3818 OPEN c_get_hire_date(l_eff_date);
3819 FETCH c_get_hire_date INTO l_hire_date;
3820 CLOSE c_get_hire_date;
3821 IF l_hire_date > trunc(to_date(substr(p_aei_information1,1,10),'YYYY/MM/DD')) THEN
3822 hr_utility.set_message(8303,'PQP_230055_DATE_FRM_BEF_HIRE');
3823 hr_utility.set_message_token(8303,'HIREDATE',to_char(l_hire_date));
3824 hr_utility.raise_error;
3825 END IF;
3826
3827
3828 END IF;
3829
3830 END chk_dup_asg_info_row_upd;
3831
3832 --
3833 -- Funtion to get the prorated value of ptpn
3834 --
3835 FUNCTION get_vop
3836 (p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
3837 ,p_date_earned IN DATE
3838 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
3839 ,p_pension_type_id IN pqp_pension_types_f.pension_type_id%TYPE
3840 ,p_vop OUT NOCOPY VARCHAR2
3841 ,p_error_message OUT NOCOPY VARCHAR2
3842 ) RETURN NUMBER IS
3843
3844 --cursor to fetch the pay period start and end dates
3845 --for the particular assignment
3846 CURSOR c_get_period_dates IS
3847 SELECT ptp.start_date,ptp.end_date
3848 FROM per_all_assignments_f asg
3849 ,per_time_periods ptp
3850 WHERE asg.assignment_id = p_assignment_id
3851 AND asg.payroll_id = ptp.payroll_id
3852 AND p_date_earned BETWEEN ptp.start_date
3853 AND ptp.end_date;
3854
3855 --
3856 -- Cursor to get the start date for the active asg
3857 --
3858 CURSOR c_get_assign_start_date(c_start_date in date
3859 ,c_end_date in date) IS
3860 SELECT min(asg.effective_start_date)
3861 ,max(asg.effective_end_date)
3862 FROM per_assignments_f asg
3863 ,per_assignment_status_types past
3864 WHERE asg.assignment_status_type_id = past.assignment_status_type_id
3865 AND past.per_system_status = 'ACTIVE_ASSIGN'
3866 AND asg.effective_start_date <= trunc(c_end_date)
3867 AND nvl(asg.effective_end_date, trunc(c_end_date)) >= trunc(c_start_date)
3868 AND asg.assignment_id = p_assignment_id
3869 group by asg.assignment_id;
3870
3871 CURSOR c_vop_current (c_st_dt IN DATE
3872 ,c_ed_dt IN DATE ) IS
3873 --
3874 -- Rows that start in the current period
3875 --
3876 SELECT fnd_number.canonical_to_number(nvl(aei_information5,'1')) VOP
3877 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3878 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3879 FROM per_assignment_extra_info
3880 WHERE assignment_id = p_assignment_id
3881 AND information_type = 'NL_ABP_PAR_INFO'
3882 AND aei_information_category = 'NL_ABP_PAR_INFO'
3883 AND TRUNC(fnd_date.canonical_to_date(aei_information1))
3884 BETWEEN c_st_dt AND c_ed_dt
3885 UNION
3886 --
3887 -- Rows that end in the current period
3888 --
3889 SELECT fnd_number.canonical_to_number(nvl(aei_information5,'1')) VOP
3890 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3891 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3892 FROM per_assignment_extra_info
3893 WHERE assignment_id = p_assignment_id
3894 AND information_type = 'NL_ABP_PAR_INFO'
3895 AND aei_information_category = 'NL_ABP_PAR_INFO'
3896 AND TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt))
3897 BETWEEN c_st_dt AND c_ed_dt
3898 UNION
3899 --
3900 -- Rows that neither start or end in the current period
3901 -- but the data in the EIT is valid for the current period
3902 --
3903 SELECT fnd_number.canonical_to_number(nvl(aei_information5,'1')) VOP
3904 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3905 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3906 FROM per_assignment_extra_info
3907 WHERE assignment_id = p_assignment_id
3908 AND information_type = 'NL_ABP_PAR_INFO'
3909 AND aei_information_category = 'NL_ABP_PAR_INFO'
3910 AND c_ed_dt BETWEEN TRUNC(fnd_date.canonical_to_date(aei_information1))
3911 AND TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt))
3912 ORDER BY st_dt;
3913
3914 -- Bug# 6506736 Start
3915 CURSOR c_vop_current_or (c_st_dt IN DATE
3916 ,c_ed_dt IN DATE ) IS
3917 --
3918 -- Rows that start in the current period
3919 --
3920 SELECT fnd_number.canonical_to_number(nvl(aei_information23,'1')) VOP
3921 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3922 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3923 FROM per_assignment_extra_info aei,
3924 pqp_pension_types_f pty
3925 WHERE assignment_id = p_assignment_id
3926 AND aei_information3 = p_pension_type_id
3927 AND pty.pension_type_id = fnd_number.canonical_to_number(aei.aei_information3)
3928 AND pension_sub_category IN ('PPP' ,'OPNP' ,'OPNP_65'
3929 ,'OPNP_AOW' ,'OPNP_W25','OPNP_W50', 'AAOP'
3930 ,'FPU_B', 'FPU_C', 'FPU_E', 'FPU_R', 'FPU_S', 'FPU_T')
3931 AND c_ed_dt BETWEEN pty.effective_start_date AND NVL(pty.effective_end_date,to_date('31/12/4712','DD/MM/YYYY'))
3932 AND aei_information23 IS NOT NULL
3933 AND information_type = 'NL_ABP_PI'
3934 AND aei_information_category = 'NL_ABP_PI'
3935 AND TRUNC(fnd_date.canonical_to_date(aei_information1))
3936 BETWEEN c_st_dt AND c_ed_dt
3937 UNION
3938 --
3939 -- Rows that end in the current period
3940 --
3941 SELECT fnd_number.canonical_to_number(nvl(aei_information23,'1')) VOP
3942 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3943 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3944 FROM per_assignment_extra_info aei,
3945 pqp_pension_types_f pty
3946 WHERE assignment_id = p_assignment_id
3947 AND aei_information3 = p_pension_type_id
3948 AND pty.pension_type_id = fnd_number.canonical_to_number(aei.aei_information3)
3949 AND pension_sub_category in ('PPP' ,'OPNP' ,'OPNP_65'
3950 ,'OPNP_AOW' ,'OPNP_W25','OPNP_W50', 'AAOP'
3951 ,'FPU_B', 'FPU_C', 'FPU_E', 'FPU_R', 'FPU_S', 'FPU_T')
3952 AND c_ed_dt BETWEEN pty.effective_start_date AND NVL(pty.effective_end_date ,to_date('31/12/4712','DD/MM/YYYY'))
3953 AND aei_information23 IS NOT NULL
3954 AND information_type = 'NL_ABP_PI'
3955 AND aei_information_category = 'NL_ABP_PI'
3956 AND TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt))
3957 BETWEEN c_st_dt AND c_ed_dt
3958 UNION
3959 --
3960 -- Rows that neither start or end in the current period
3961 -- but the data in the EIT is valid for the current period
3962 --
3963 SELECT fnd_number.canonical_to_number(nvl(aei_information23,'1')) VOP
3964 ,TRUNC(fnd_date.canonical_to_date(aei_information1)) St_Dt
3965 ,TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt)) Ed_Dt
3966 FROM per_assignment_extra_info aei,
3967 pqp_pension_types_f pty
3968 WHERE assignment_id = p_assignment_id
3969 AND aei_information3 = p_pension_type_id
3970 AND pty.pension_type_id = fnd_number.canonical_to_number(aei.aei_information3)
3971 AND pension_sub_category in ('PPP' ,'OPNP' ,'OPNP_65'
3972 ,'OPNP_AOW' ,'OPNP_W25','OPNP_W50', 'AAOP'
3973 ,'FPU_B', 'FPU_C', 'FPU_E', 'FPU_R', 'FPU_S', 'FPU_T')
3974 AND c_ed_dt BETWEEN pty.effective_start_date and NVL(pty.effective_end_date ,to_date('31/12/4712','DD/MM/YYYY'))
3975 AND aei_information23 IS NOT NULL
3976 AND information_type = 'NL_ABP_PI'
3977 AND aei_information_category = 'NL_ABP_PI'
3978 AND c_ed_dt BETWEEN TRUNC(fnd_date.canonical_to_date(aei_information1))
3979 AND TRUNC(NVL(fnd_date.canonical_to_date(aei_information2),c_ed_dt))
3980 ORDER BY st_dt;
3981 -- Bug# 6506736 End
3982
3983 l_period_start_date DATE;
3984 l_period_end_date DATE;
3985 l_min_start_date DATE;
3986 l_max_end_date DATE;
3987 l_effective_date DATE;
3988 l_days_in_pp NUMBER;
3989 l_payroll_days NUMBER;
3990 l_min_vop_start DATE;
3991 l_max_vop_end DATE;
3992 l_min_vop_start_or DATE;
3993 l_max_vop_end_or DATE;
3994 l_vop_num NUMBER;
3995 l_vop_num_or NUMBER;
3996
3997 BEGIN
3998
3999 hr_utility.set_location('entered get_proration_factor',10);
4000
4001
4002 --
4003 -- Fetch the pay period start and end dates
4004 --
4005 OPEN c_get_period_dates;
4006 FETCH c_get_period_dates INTO l_period_start_date
4007 ,l_period_end_date;
4008 CLOSE c_get_period_dates;
4009
4010 hr_utility.set_location('start date of pay period : '||l_period_start_date,30);
4011 hr_utility.set_location('end date of pay period : '||l_period_end_date,40);
4012
4013 --
4014 -- Fetch the greater of the assigment start date or the period start date
4015 --
4016 OPEN c_get_assign_start_date(c_start_date => l_period_start_date
4017 ,c_end_date => l_period_end_date);
4018 FETCH c_get_assign_start_date INTO l_effective_date,l_max_end_date;
4019
4020 IF c_get_assign_start_date%FOUND THEN
4021 CLOSE c_get_assign_start_date;
4022 ELSE
4023 CLOSE c_get_assign_start_date;
4024 p_vop := '0';
4025 RETURN 0;
4026 END IF;
4027
4028 l_min_start_date := GREATEST(l_effective_date,trunc(l_period_start_date));
4029 l_max_end_date := LEAST(l_max_end_date,trunc(l_period_end_date));
4030
4031 hr_utility.set_location('l_min_start_date : '||l_min_start_date,50);
4032 hr_utility.set_location('l_max_end_date : '||l_max_end_date,50);
4033
4034 --
4035 -- Calcualte the total number of days in the pay period
4036 --
4037 l_payroll_days := (trunc(l_period_end_date)
4038 - trunc(l_period_start_date)) + 1;
4039
4040 --
4041 -- Find the number of days the assignments has been effective in the
4042 -- current period
4043 --
4044 l_days_in_pp := nvl(l_max_end_date, trunc(l_period_end_date ))
4045 - nvl(l_min_start_date,trunc(l_period_start_date)) + 1;
4046
4047 hr_utility.set_location('days in pay period : '||l_payroll_days,55);
4048 hr_utility.set_location('days asg valid : '||l_days_in_pp,57);
4049
4050 l_min_vop_start := NULL;
4051 l_max_vop_end := NULL;
4052 l_min_vop_start_or := NULL;
4053 l_max_vop_end_or := NULL;
4054 l_vop_num := NULL;
4055 l_vop_num_or := NULL;
4056
4057 --
4058 -- Calculate the normal VOP
4059 --
4060 FOR l_vop_current_rec IN c_vop_current (nvl(l_min_start_date,trunc(l_period_start_date))
4061 ,nvl(l_max_end_date, trunc(l_period_end_date )))
4062 LOOP
4063
4064 IF l_vop_current_rec.st_dt < NVL(l_min_vop_start,TO_DATE('31/12/4712','DD/MM/YYYY')) THEN
4065 l_min_vop_start := GREATEST(l_vop_current_rec.st_dt,nvl(l_min_start_date,trunc(l_period_start_date)));
4066 END IF;
4067
4068 l_max_vop_end := LEAST(l_vop_current_rec.ed_dt,nvl(l_max_end_date,trunc(l_period_end_date )));
4069
4070 l_vop_num := NVL(l_vop_num,0) + (l_vop_current_rec.vop *
4071 ((l_max_vop_end - GREATEST(l_vop_current_rec.st_dt,nvl(l_min_start_date,trunc(l_period_start_date)))) + 1 ));
4072 END LOOP;
4073
4074 --
4075 -- Calculate the override VOP
4076 --
4077 FOR l_vop_current_rec_or IN c_vop_current_or (nvl(l_min_start_date,trunc(l_period_start_date))
4078 ,nvl(l_max_end_date, trunc(l_period_end_date )))
4079 LOOP
4080
4081 IF l_vop_current_rec_or.st_dt < NVL(l_min_vop_start_or,TO_DATE('31/12/4712','DD/MM/YYYY')) THEN
4082 l_min_vop_start_or := GREATEST(l_vop_current_rec_or.st_dt,nvl(l_min_start_date,trunc(l_period_start_date)));
4083 END IF;
4084
4085 l_max_vop_end_or := LEAST(l_vop_current_rec_or.ed_dt,nvl(l_max_end_date,trunc(l_period_end_date )));
4086
4087 l_vop_num_or := NVL(l_vop_num_or,0) + (l_vop_current_rec_or.vop *
4088 ((l_max_vop_end_or - GREATEST(l_vop_current_rec_or.st_dt,nvl(l_min_start_date,trunc(l_period_start_date)))) + 1 ));
4089 END LOOP;
4090
4091 IF l_vop_num_or IS NOT NULL THEN
4092
4093 l_vop_num_or := TRUNC(l_vop_num_or/l_days_in_pp,4);
4094 p_vop := fnd_number.number_to_canonical(l_vop_num_or);
4095 RETURN 0;
4096
4097 ELSIF l_vop_num IS NOT NULL THEN
4098
4099 l_vop_num := TRUNC(l_vop_num/l_days_in_pp,4);
4100 p_vop := fnd_number.number_to_canonical(l_vop_num);
4101 RETURN 0;
4102
4103 ELSIF l_vop_num IS NULL AND l_vop_num_or IS NULL THEN
4104
4105 -- Could not find any data
4106 -- VOP information is not entered for this period
4107 -- Assignment is still valid so return vop as 1
4108 p_vop := '1';
4109 RETURN 0;
4110 END IF;
4111
4112
4113 END get_vop;
4114
4115 --
4116 -- ------------------------------------------------------------------------
4117 -- |------------------< get_assignment_attribute >-------------------------|
4118 -- ------------------------------------------------------------------------
4119 --
4120 FUNCTION get_assignment_attribute
4121 (p_assignment_id in per_all_assignments_f.assignment_id%TYPE
4122 ,p_date_earned in date
4123 ,p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
4124 ,p_pension_type_id in pqp_pension_types_f.pension_type_id%TYPE
4125 ,p_attrib_name in varchar2
4126 ,p_attrib_value out NOCOPY varchar2
4127 ,p_error_message out NOCOPY varchar2
4128 )
4129
4130 RETURN number IS
4131
4132 type t_asg_extra_info is table of per_assignment_extra_info%rowtype index by Binary_Integer;
4133
4134 g_asg_extra_info_rec t_asg_extra_info;
4135
4136 --new record structure for fetching the override for salary,basis,value and kind of
4137 --participation
4138 g_asg_extra_info_rec1 t_asg_extra_info;
4139
4140 l_ret_value number := 0; --return
4141 l_is_ptype_valid number;
4142 l_pen_type_name pqp_pension_types_f.pension_type_name%type;
4143 l_asg_extra_info_id per_assignment_extra_info.assignment_extra_info_id%type;
4144 l_asg_extra_info_id1 per_assignment_extra_info.assignment_extra_info_id%type;
4145 l_override_found number := 0;
4146 l_vop_ret_val NUMBER;
4147
4148 --Cursor to check if the pension type is valid on the date earned
4149 Cursor c_is_ptype_valid Is
4150 Select 1
4151 from pqp_pension_types_f pty
4152 where pty.pension_type_id = p_pension_type_id
4153 and pty.business_group_id = p_business_group_id
4154 and p_date_earned between pty.effective_start_date and pty.effective_end_date;
4155
4156 --Cursor to find the pension type name from the id
4157 Cursor c_find_pen_type_name Is
4158 Select pension_type_name
4159 from pqp_pension_types_f
4160 where pension_type_id = p_pension_type_id
4161 and business_group_id = p_business_group_id;
4162
4163 --Cursor to find if the pension type has a valid information row at the --assignment level
4164 -- if so qry up the asg extra info id
4165 CURSOR c_get_asg_extra_info_id IS
4166 Select paei.assignment_extra_info_id
4167 from per_assignment_extra_info paei,
4168 pqp_pension_types_f pty
4169 where paei.information_type = 'NL_ABP_PI'
4170 and paei.aei_information_category = 'NL_ABP_PI'
4171 and paei.aei_information3 = to_char(p_pension_type_id)
4172 and paei.assignment_id = p_assignment_id
4173 and p_date_earned between trunc(to_date(substr(paei.aei_information1,1,10),'YYYY/MM/DD'))
4174 and trunc(to_date(substr(nvl(paei.aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'));
4175
4176 -- cursor to get the data in per_assignment_extra_info for a particular --asg_extra_info_id
4177 Cursor c_get_asg_extra_info(c_asg_extra_info_id in per_assignment_extra_info.assignment_extra_info_id%type) Is
4178 Select *
4179 from per_assignment_extra_info
4180 where assignment_extra_info_id = c_asg_extra_info_id;
4181
4182 --cursor to get the assignment extra info id for the NL_ABP_PAR_INFO context
4183 CURSOR c_get_extra_info_id IS
4184 SELECT assignment_extra_info_id
4185 FROM per_assignment_extra_info
4186 WHERE assignment_id = p_assignment_id
4187 AND information_type = 'NL_ABP_PAR_INFO'
4188 AND aei_information_category = 'NL_ABP_PAR_INFO'
4189 AND p_date_earned BETWEEN trunc(fnd_date.canonical_to_date(aei_information1))
4190 AND trunc(nvl(fnd_date.canonical_to_date(aei_information2),hr_api.g_eot));
4191
4192 BEGIN
4193
4194 --if the attribute is stored in the participation EIT then
4195 --check first in the participation and salary information EIT
4196 IF p_attrib_name IN ('KIND_OF_PARTICIPATION','VALUE_OF_PARTICIPATION',
4197 'OVERRIDE_ANNUAL_PENSION_SALARY','PENSION_SALARY_OVERRIDE_REASON'
4198 ,'OVERRIDE_PENSION_BASIS','PENSION_BASIS_OVERRIDE_REASON'
4199 ) THEN
4200 hr_utility.set_location('searching in the participation EIT',10);
4201 OPEN c_get_extra_info_id;
4202 FETCH c_get_extra_info_id INTO l_asg_extra_info_id1;
4203 IF c_get_extra_info_id%FOUND THEN
4204 CLOSE c_get_extra_info_id;
4205 hr_utility.set_location('found a row in the participation EIT',20);
4206 OPEN c_get_asg_extra_info(l_asg_extra_info_id1);
4207 FETCH c_get_asg_extra_info INTO g_asg_extra_info_rec1(l_asg_extra_info_id1);
4208 CLOSE c_get_asg_extra_info;
4209
4210 If p_attrib_name = 'KIND_OF_PARTICIPATION' THEN
4211 p_attrib_value
4212 := g_asg_extra_info_rec1(l_asg_extra_info_id1).aei_information4;
4213
4214 Elsif p_attrib_name = 'VALUE_OF_PARTICIPATION' THEN
4215
4216 l_vop_ret_val := get_vop
4217 (p_assignment_id => p_assignment_id
4218 ,p_date_earned => p_date_earned
4219 ,p_business_group_id => p_business_group_id
4220 ,p_pension_type_id => p_pension_type_id
4221 ,p_vop => p_attrib_value
4222 ,p_error_message => p_error_message);
4223
4224 Elsif p_attrib_name = 'OVERRIDE_ANNUAL_PENSION_SALARY' THEN
4225 p_attrib_value
4226 := g_asg_extra_info_rec1(l_asg_extra_info_id1).aei_information6;
4227
4228 Elsif p_attrib_name = 'PENSION_SALARY_OVERRIDE_REASON' THEN
4229 p_attrib_value
4230 := g_asg_extra_info_rec1(l_asg_extra_info_id1).aei_information7;
4231
4232 Elsif p_attrib_name = 'OVERRIDE_PENSION_BASIS' THEN
4233 p_attrib_value
4234 := g_asg_extra_info_rec1(l_asg_extra_info_id1).aei_information8;
4235
4236 Elsif p_attrib_name = 'PENSION_BASIS_OVERRIDE_REASON' THEN
4237 p_attrib_value
4238 := g_asg_extra_info_rec1(l_asg_extra_info_id1).aei_information9;
4239 End If;
4240
4241 ELSE
4242 CLOSE c_get_extra_info_id;
4243 return 1;
4244 END IF;
4245
4246 --else search for the attribute in the ABP Pension Information EIT
4247 ELSE
4248 -- find the pension type name from the pension type id
4249 OPEN c_find_pen_type_name;
4250 FETCH c_find_pen_type_name INTO l_pen_type_name;
4251 If c_find_pen_type_name%NOTFOUND THEN
4252 p_error_message := 'Unable to find the details for the Pension Type';
4253 p_error_message := p_error_message||'. Pension Type Id = '||to_char(p_pension_type_id);
4254 CLOSE c_find_pen_type_name;
4255 return 1;
4256 Else
4257 CLOSE c_find_pen_type_name;
4258 End If;
4259
4260 -- check to see that the pension type is valid on the date earned
4261 OPEN c_is_ptype_valid;
4262 FETCH c_is_ptype_valid INTO l_is_ptype_valid;
4263 If c_is_ptype_valid%NOTFOUND THEN
4264 p_error_message := 'Pension Type : '||l_pen_type_name;
4265 p_error_message:= p_error_message||' is not valid as of '||to_char(p_date_earned);
4266 CLOSE c_is_ptype_valid;
4267 return 1;
4268 Else
4269 CLOSE c_is_ptype_valid;
4270 End If;
4271
4272 -- check to see if there is a valid asg extra info row for the current PT
4273 -- if such a row exists, the cursor returns the assignment_extra_info_id
4274 OPEN c_get_asg_extra_info_id;
4275 FETCH c_get_asg_extra_info_id INTO l_asg_extra_info_id;
4276 -- no row is found for the pension type
4277 -- or the row has been end-dated
4278 If c_get_asg_extra_info_id%NOTFOUND THEN
4279 p_error_message := 'No overrides have been specified at the Assignment ';
4280 p_error_message := p_error_message ||'Extra Information for Pension Type : '||l_pen_type_name;
4281 CLOSE c_get_asg_extra_info_id;
4282 return 1;
4283
4284 -- a row has been found, return it to the record type
4285 Else
4286 CLOSE c_get_asg_extra_info_id;
4287 OPEN c_get_asg_extra_info(l_asg_extra_info_id);
4288 FETCH c_get_asg_extra_info INTO g_asg_extra_info_rec(l_asg_extra_info_id);
4289 CLOSE c_get_asg_extra_info;
4290
4291 -- now FETCH the field required, depending on the input attribute name
4292 If p_attrib_name = 'DATE_FROM' THEN
4293 p_attrib_value
4294 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information1;
4295
4296 Elsif p_attrib_name = 'DATE_TO' THEN
4297 p_attrib_value
4298 := nvl(g_asg_extra_info_rec(l_asg_extra_info_id).aei_information2,'4712/12/31');
4299
4300 Elsif p_attrib_name = 'PENSION_TYPE_NAME' THEN
4301 p_attrib_value
4302 := l_pen_type_name;
4303
4304 Elsif p_attrib_name = 'PARTICIPATE_END_REASON' THEN
4305 p_attrib_value
4306 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information4;
4307
4308 /*Elsif p_attrib_name = 'KIND_OF_PARTICIPATION' THEN
4309 p_attrib_value
4310 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information5;
4311
4312 Elsif p_attrib_name = 'VALUE_OF_PARTICIPATION' THEN
4313
4314 l_vop_ret_val := get_vop
4315 (p_assignment_id => p_assignment_id
4316 ,p_date_earned => p_date_earned
4317 ,p_business_group_id => p_business_group_id
4318 ,p_vop => p_attrib_value
4319 ,p_error_message => p_error_message);
4320
4321 Elsif p_attrib_name = 'OVERRIDE_ANNUAL_PENSION_SALARY' THEN
4322 p_attrib_value
4323 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information7;
4324
4325 Elsif p_attrib_name = 'PENSION_SALARY_OVERRIDE_REASON' THEN
4326 p_attrib_value
4327 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information8;
4328
4329 Elsif p_attrib_name = 'OVERRIDE_PENSION_BASIS' THEN
4330 p_attrib_value
4331 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information9;
4332
4333 Elsif p_attrib_name = 'PENSION_BASIS_OVERRIDE_REASON' THEN
4334 p_attrib_value
4335 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information10; */
4336
4337 Elsif p_attrib_name = 'OVERRIDE_EE_CONTRIBUTION' THEN
4338 p_attrib_value
4339 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information11;
4340
4341 Elsif p_attrib_name = 'EE_CONTRIB_OVERRIDE_REASON' THEN
4342 p_attrib_value
4343 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information12;
4344
4345 Elsif p_attrib_name = 'EE_CONTRIB_DEDN_MTHD' THEN
4346 p_attrib_value
4347 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information13;
4348
4349 Elsif p_attrib_name = 'EE_CONTRIB_VALUE' THEN
4350 p_attrib_value
4351 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information14;
4352
4353 Elsif p_attrib_name = 'ER_CONTRIB_DEDN_MTHD' THEN
4354 p_attrib_value
4355 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information15;
4356
4357 Elsif p_attrib_name = 'ER_CONTRIB_VALUE' THEN
4358 p_attrib_value
4359 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information16;
4360
4361 Elsif p_attrib_name = 'OVERRIDE_EE_ANNUAL_LIMIT' THEN
4362 p_attrib_value
4363 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information17;
4364
4365 Elsif p_attrib_name = 'OVERRIDE_ER_ANNUAL_LIMIT' THEN
4366 p_attrib_value
4367 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information18;
4368
4369 Elsif p_attrib_name = 'OVERRIDE_PENSION_DAYS' THEN
4370 p_attrib_value
4371 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information19;
4372
4373 Elsif p_attrib_name = 'OVERRIDE_ER_CONTRIBUTION' THEN
4374 p_attrib_value
4375 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information20;
4376
4377 Elsif p_attrib_name = 'ER_CONTRIB_OVERRIDE_REASON' THEN
4378 p_attrib_value
4379 := g_asg_extra_info_rec(l_asg_extra_info_id).aei_information21;
4380
4381 Else
4382 p_error_message
4383 := 'Error occured while Fetching values for Assignment Attributes : ';
4384 p_error_message := p_error_message ||'Attribute '||p_attrib_name||' is invalid.';
4385 return 1;
4386 End If;
4387
4388 End If;
4389
4390 End If;
4391 IF p_attrib_value IS NOT NULL THEN
4392 return 0;
4393 ELSE
4394 return 2;
4395 END IF;
4396
4397 END get_assignment_attribute;
4398
4399 --
4400 -- ------------------------------------------------------------------------
4401 -- |------------------< get_contribution_percent >----------------------------|
4402 -- ------------------------------------------------------------------------
4403 --
4404
4405
4406 FUNCTION get_contribution_percent
4407 ( p_assignment_id in per_all_assignments_f.assignment_id%TYPE
4408 ,p_date_earned in date
4409 ,p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
4410 ,p_pension_sub_cat in pqp_pension_types_f.pension_sub_category%TYPE
4411 ,p_udt_table_name in VARCHAR2
4412 ,p_column_value out NOCOPY number
4413 )
4414 RETURN NUMBER IS
4415
4416 CURSOR c_get_person_age IS
4417 SELECT to_char(per.date_of_birth,'RRRR')
4418 FROM per_all_people_f per,per_all_assignments_f paa
4419 WHERE per.person_id = paa.person_id
4420 AND p_date_earned between paa.effective_start_date and paa.effective_end_date
4421 AND p_date_earned between per.effective_start_date and per.effective_end_date
4422 AND paa.assignment_id = p_assignment_id;
4423
4424 CURSOR c_get_subcat (c_sub_cat IN VARCHAR2) IS
4425 SELECT meaning
4426 FROM fnd_lookup_values
4427 WHERE lookup_type = 'PQP_PENSION_SUB_CATEGORY'
4428 AND lookup_code = c_sub_cat
4429 AND language = 'US'
4430 AND nvl(enabled_flag,'N') = 'Y';
4431
4432
4433 CURSOR c_get_part_st_age IS
4434 SELECT aei_information3
4435 FROM per_assignment_extra_info
4436 WHERE p_date_earned between fnd_date.canonical_to_date(aei_information1)
4437 AND fnd_date.canonical_to_date(nvl(aei_information2,fnd_date.date_to_canonical(hr_api.g_eot)))
4438 AND assignment_id = p_assignment_id
4439 AND aei_information_category = 'NL_ABP_PAR_INFO';
4440
4441
4442 l_person_year_of_birth VARCHAR2(10);
4443 l_subcat VARCHAR2(80);
4444 l_part_start_age NUMBER;
4445 l_return_value VARCHAR2(50);
4446
4447 BEGIN
4448
4449 OPEN c_get_person_age;
4450 FETCH c_get_person_age into l_person_year_of_birth;
4451 IF (c_get_person_age%FOUND and l_person_year_of_birth IS NOT NULL) THEN
4452
4453 hr_utility.set_location(' l_person_year_of_birth is '||l_person_year_of_birth,35);
4454
4455 OPEN c_get_subcat(p_pension_sub_cat);
4456 FETCH c_get_subcat INTO l_subcat;
4457 CLOSE c_get_subcat;
4458
4459 OPEN c_get_part_st_age;
4460 FETCH c_get_part_st_age into l_part_start_age;
4461 CLOSE c_get_part_st_age;
4462
4463 hr_utility.set_location(' l_subcat is '||l_subcat,40);
4464 hr_utility.set_location(' l_part_start_age is '||l_part_start_age,50);
4465
4466
4467 IF l_subcat IS NOT NULL THEN
4468
4469 l_return_value :=
4470 hruserdt.get_table_value
4471 (
4472 p_bus_group_id => p_business_group_id
4473 ,p_table_name => p_udt_table_name
4474 ,p_col_name => l_subcat||'-'||l_part_start_age
4475 ,p_row_value => l_person_year_of_birth
4476 ,p_effective_date => p_date_earned
4477 );
4478
4479 l_return_value := NVL(l_return_value,trim(to_char(0,'9')));
4480
4481 hr_utility.set_location(' l_return_value is '||l_return_value,50);
4482
4483 p_column_value := fnd_number.canonical_to_number(l_return_value);
4484
4485 hr_utility.set_location(' p_column_value is '||p_column_value,60);
4486
4487 END IF;-- subcat check
4488
4489 END IF;--c_get_person_age%FOUND
4490 CLOSE c_get_person_age;
4491
4492 RETURN 0;
4493
4494 EXCEPTION
4495
4496 WHEN NO_DATA_FOUND THEN
4497 hr_utility.set_location('NO_DATA_FOUND for UDT : ', 90);
4498
4499 p_column_value := 0;
4500
4501 RETURN 1;
4502
4503 WHEN OTHERS THEN
4504
4505 hr_utility.set_location('sqlcode '||SQLCODE, 70);
4506 hr_utility.set_location('sqlerr '||SQLERRM, 80);
4507 hr_utility.set_location('error occurred while getting values for UDT ', 90);
4508 p_column_value := 0;
4509
4510 RETURN 1;
4511
4512 END get_contribution_percent;
4513
4514
4515 -- ------------------------------------------------------------------------
4516 -- |-----------------------< chk_pt_eligibility >--------------------------|
4517 -- ------------------------------------------------------------------------
4518 --
4519 FUNCTION chk_pt_eligibility
4520 ( p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
4521 ,p_date_earned IN DATE
4522 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
4523 ,p_pt_id IN NUMBER
4524 ,p_hr_org_org_id IN NUMBER
4525 ,p_le_org_id IN NUMBER)
4526 RETURN NUMBER IS
4527
4528 --
4529 -- Cursor to find the validity of a PT at the HR org level
4530 -- Note that this qry considers the "Valid" and
4531 -- "Applicable to all EE" flags
4532 --
4533 CURSOR c_pt_valid_hr_org IS
4534 SELECT 1
4535 FROM hr_organization_information hoi
4536 WHERE hoi.org_information_context = 'PQP_NL_ABP_PT'
4537 AND hoi.org_information3 = TO_CHAR(p_pt_id)
4538 AND NVL(hoi.org_information6,'N') = 'Y'
4539 AND NVL(hoi.org_information7,'N') = 'Y'
4540 AND hoi.organization_id = p_hr_org_org_id
4541 AND p_date_earned BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
4542 AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
4543 fnd_date.date_to_canonical(hr_api.g_eot)));
4544 --
4545 -- Cursor to find the validity of a PT at the Legal ER Level
4546 -- Note that this qry considers the "Valid" and
4547 -- "Applicable to all EE" flags
4548 -- Query also checks to ensure that the PT is also valid at the
4549 -- HR Org level OR no information is entered at the HR org level
4550 --
4551
4552 CURSOR c_pt_valid_le IS
4553 SELECT 1
4554 FROM hr_organization_information hoi
4555 WHERE hoi.org_information_context = 'PQP_NL_ABP_PT'
4556 AND hoi.org_information3 = TO_CHAR(p_pt_id)
4557 AND NVL(hoi.org_information6,'N') = 'Y'
4558 AND NVL(hoi.org_information7,'N') = 'Y'
4559 AND hoi.organization_id = p_le_org_id
4560 AND p_date_earned BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
4561 AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
4562 fnd_date.date_to_canonical(hr_api.g_eot)))
4563 AND NOT EXISTS ( SELECT 1
4564 FROM hr_organization_information hoi
4565 WHERE hoi.org_information_context = 'PQP_NL_ABP_PT'
4566 AND hoi.org_information3 = TO_CHAR(p_pt_id)
4567 AND ( NVL(hoi.org_information6,'N')= 'N'
4568 OR NVL(hoi.org_information7,'N')= 'N')
4569 AND hoi.organization_id = p_hr_org_org_id
4570 AND p_date_earned BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
4571 AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
4572 fnd_date.date_to_canonical(hr_api.g_eot))));
4573 l_pt_valid NUMBER;
4574 l_ret_val NUMBER;
4575
4576 BEGIN
4577
4578 --
4579 -- Note that this function returns 0 if the EE assignment is NOT ELIGIBLE for the PT
4580 -- Note that this function returns 1 if the EE assignment is ELIGIBLE for the PT
4581 --
4582 OPEN c_pt_valid_hr_org;
4583 FETCH c_pt_valid_hr_org INTO l_pt_valid;
4584 IF c_pt_valid_hr_org%FOUND THEN
4585 --
4586 -- PT is valid at the HR Org and EE can contribute towards the PT
4587 --
4588 l_ret_val := 1;
4589
4590 ELSIF c_pt_valid_hr_org%NOTFOUND THEN
4591 --
4592 -- Check if the PT is valid at the Legal ER
4593 --
4594 OPEN c_pt_valid_le;
4595 FETCH c_pt_valid_le INTO l_pt_valid;
4596
4597 IF c_pt_valid_le%FOUND THEN
4598 --
4599 -- PT is valid at the HR Org and Legal ER and the EE
4600 -- can contribute towards the PT
4601 --
4602 l_ret_val := 1;
4603 ELSE
4604 --
4605 -- PT is not valid at the HR Org or Legal ER and the EE
4606 -- cannot contribute towards the PT
4607 --
4608 l_ret_val := 0;
4609 END IF;
4610
4611 CLOSE c_pt_valid_le;
4612
4613 END IF;
4614
4615 CLOSE c_pt_valid_hr_org;
4616
4617 RETURN l_ret_val;
4618
4619 EXCEPTION
4620 WHEN OTHERS THEN
4621 RETURN 0;
4622
4623 END chk_pt_eligibility;
4624
4625 --
4626 -- ------------------------------------------------------------------------
4627 -- |------------------< get_abp_org_contrib_percent >----------------------|
4628 -- ------------------------------------------------------------------------
4629 --
4630 FUNCTION get_abp_org_contrib_percent
4631 ( p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
4632 ,p_date_earned IN DATE
4633 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
4634 ,p_pension_type_id IN pqp_pension_types_f.pension_type_id%TYPE
4635 ,p_ee_contrib OUT NOCOPY NUMBER
4636 ,p_er_contrib OUT NOCOPY NUMBER
4637 ,p_app_to_all_ee IN VARCHAR2)
4638 RETURN NUMBER IS
4639
4640 --
4641 -- Cursor to find the contrib% for a given org id
4642 -- Note that this fetches the values for the
4643 -- pension types that are valid. The applicable to
4644 -- all EE's flag does not matter as the PT is attached
4645 -- at the assignment level.
4646 --
4647 CURSOR c_get_contribution
4648 (c_org_id IN hr_organization_information.organization_id%TYPE) IS
4649 SELECT fnd_number.canonical_to_number(NVL(hoi.org_information4,'-1'))
4650 ,fnd_number.canonical_to_number(NVL(hoi.org_information5,'-1'))
4651 FROM hr_organization_information hoi
4652 WHERE hoi.org_information_context = 'PQP_NL_ABP_PT'
4653 AND hoi.org_information3 = TO_CHAR(p_pension_type_id)
4654 AND hoi.org_information6 = 'Y'
4655 AND hoi.organization_id = c_org_id
4656 AND p_date_earned BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
4657 AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
4658 fnd_date.date_to_canonical(hr_api.g_eot)));
4659
4660 --
4661 -- Cursor to find the org id,payroll and legal ER from the assignment
4662 --
4663 CURSOR c_find_org IS
4664 SELECT asg.organization_id
4665 ,asg.payroll_id
4666 ,fnd_number.canonical_to_number(ppf.prl_information1)
4667 FROM per_all_assignments_f asg,
4668 pay_payrolls_f ppf
4669 WHERE asg.assignment_id = p_assignment_id
4670 AND asg.payroll_id = ppf.payroll_id
4671 AND TRUNC(p_date_earned) BETWEEN asg.effective_start_date
4672 AND asg.effective_end_date
4673 AND TRUNC(p_date_earned) BETWEEN ppf.effective_start_date
4674 AND ppf.effective_end_date
4675 AND asg.business_group_id = p_business_group_id;
4676
4677 --
4678 -- Cursor to fetch contribution values from the Pension Type
4679 --
4680 CURSOR c_pt_val IS
4681 SELECT fnd_number.canonical_to_number(nvl(ee_contribution_percent,'0'))
4682 ,fnd_number.canonical_to_number(nvl(er_contribution_percent,'0'))
4683 FROM pqp_pension_types_f
4684 WHERE pension_type_id = p_pension_type_id
4685 AND p_date_earned BETWEEN effective_start_date
4686 AND effective_end_date;
4687
4688 l_hr_org_id NUMBER;
4689 l_legal_er_org_id NUMBER;
4690 l_payroll_id NUMBER;
4691 l_pt_er_perc NUMBER;
4692 l_pt_ee_perc NUMBER;
4693 l_le_ee_perc NUMBER;
4694 l_le_er_perc NUMBER;
4695 l_proc_name VARCHAR2(30) := 'get_abp_org_contrib_percent';
4696
4697 BEGIN
4698
4699 hr_utility.set_location(' Entering '||l_proc_name,10);
4700 --
4701 -- Get the Org id, Legal ER org id and Payroll id
4702 --
4703 OPEN c_find_org;
4704 FETCH c_find_org
4705 INTO l_hr_org_id,l_payroll_id,l_legal_er_org_id;
4706
4707 CLOSE c_find_org;
4708
4709 hr_utility.set_location('... The HR Org org id is -- '||l_hr_org_id,10);
4710 hr_utility.set_location('... The payroll id is -- '||l_payroll_id,15);
4711 hr_utility.set_location('... The legal ER org id is -- '||l_legal_er_org_id,20);
4712
4713 --
4714 -- Derive the contribution values from the pension type
4715 --
4716 hr_utility.set_location('... Fetching contrib values from the PT',25);
4717
4718 OPEN c_pt_val;
4719 FETCH c_pt_val
4720 INTO l_pt_ee_perc
4721 ,l_pt_er_perc;
4722
4723 IF c_pt_val%NOTFOUND THEN
4724 l_pt_ee_perc := 0;
4725 l_pt_er_perc := 0;
4726 END IF;
4727
4728 CLOSE c_pt_val;
4729
4730 --
4731 -- Initialize EE and ER contribution values
4732 --
4733 p_ee_contrib := -1;
4734 p_er_contrib := -1;
4735
4736 --
4737 -- Check if valid values exist at the HR Org Level
4738 --
4739 OPEN c_get_contribution(l_hr_org_id);
4740 FETCH c_get_contribution
4741 INTO p_ee_contrib
4742 ,p_er_contrib;
4743 CLOSE c_get_contribution;
4744
4745 --
4746 -- Check if valid values exist at the Legal ER Level
4747 -- This condition also caters to the fact that either
4748 -- the EE or ER percentage was left blank at the HR Org level
4749 -- and we need to fetch it from the Legal ER level.
4750 -- Note -- The definition of an legal employer is -- The org
4751 -- attached to the payroll definition of the EE assignment
4752 --
4753 IF (p_ee_contrib = -1 OR p_er_contrib = -1) THEN
4754
4755 OPEN c_get_contribution(l_legal_er_org_id);
4756 FETCH c_get_contribution
4757 INTO l_le_ee_perc
4758 ,l_le_er_perc;
4759 --
4760 -- Assign the values only if these were not derived
4761 -- previously from the HR Org.
4762 --
4763 IF p_ee_contrib = -1 AND l_le_ee_perc IS NOT NULL THEN
4764 p_ee_contrib := l_le_ee_perc;
4765 END IF;
4766
4767 IF p_er_contrib = -1 AND l_le_er_perc IS NOT NULL THEN
4768 p_er_contrib := l_le_er_perc;
4769 END IF;
4770
4771 CLOSE c_get_contribution;
4772
4773 END IF;
4774
4775
4776 --
4777 -- All levels -- HR Org and Legal ER have been searched for
4778 -- a valid contribution percentage. Since it is not available
4779 -- at either levels , derive the value from the Pension Type.
4780 -- Assign the percentage only if it has not been previously
4781 -- derived at the HR Org or Legal ER levels
4782 --
4783 IF p_ee_contrib = -1 THEN
4784 p_ee_contrib := l_pt_ee_perc;
4785 END IF;
4786
4787 IF p_er_contrib = -1 THEN
4788 p_er_contrib := l_pt_er_perc;
4789 END IF;
4790
4791 RETURN 0;
4792
4793 EXCEPTION WHEN OTHERS THEN
4794 p_ee_contrib := 0;
4795 p_er_contrib := 0;
4796 RETURN 1;
4797
4798 END get_abp_org_contrib_percent;
4799 --
4800 -- ------------------------------------------------------------------------
4801 -- |------------------< chk_abp_scheme_created >---------------------------|
4802 -- ------------------------------------------------------------------------
4803 --
4804 FUNCTION chk_abp_scheme_created
4805 (p_date_earned IN DATE
4806 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
4807 ,p_pension_sub_cat IN pqp_pension_types_f.pension_sub_category%TYPE
4808 ,p_pension_type_id OUT NOCOPY NUMBER)
4809
4810 RETURN NUMBER IS
4811 --
4812 -- This function checks to see if an ABP Pension scheme is created
4813 -- for a particular ABP Sub Cat/BG combination. If the scheme is created,
4814 -- it returns the valid pension type id for the scheme
4815 --
4816 CURSOR c_abp_schm IS
4817 SELECT fnd_number.canonical_to_number(eei_information2) pty_id
4818 FROM pay_element_type_extra_info pete,
4819 pay_element_types_f pet
4820 WHERE pete.information_type = 'PQP_NL_ABP_DEDUCTION'
4821 AND pete.element_type_id = pet.element_type_id
4822 AND p_date_earned BETWEEN pet.effective_start_date
4823 AND pet.effective_end_date
4824 AND pet.business_group_id = p_business_group_id
4825 AND pete.eei_information12 = p_pension_sub_cat
4826 AND p_date_earned between TO_DATE(pete.eei_information10,'DD/MM/YYYY')
4827 and TO_DATE(pete.eei_information11,'DD/MM/YYYY');
4828
4829 l_ret_val NUMBER;
4830
4831 BEGIN
4832
4833 OPEN c_abp_schm ;
4834
4835 FETCH c_abp_schm INTO p_pension_type_id;
4836
4837 IF c_abp_schm%FOUND THEN
4838 l_ret_val := 1;
4839 ELSE
4840 l_ret_val := 0;
4841 END IF;
4842
4843 CLOSE c_abp_schm;
4844
4845 RETURN l_ret_val;
4846
4847 END chk_abp_scheme_created;
4848
4849 -- ----------------------------------------------------------------------------
4850 -- |--------------------< get_abp_late_hire_indicator >------------------------|
4851 -- ----------------------------------------------------------------------------
4852 --
4853 -- Function is to check if an assignment is a late hire from an ABP perspective
4854 -- this checks if a payroll has been processed effective the current year
4855 -- with a date paid in the prev year. ABP pension salary
4856 -- calculation has issues in such cases.
4857 --
4858 FUNCTION get_abp_late_hire_indicator
4859 (p_payroll_action_id IN NUMBER)
4860
4861 RETURN NUMBER IS
4862
4863 l_eff_dt DATE;
4864 l_dt_earned DATE;
4865
4866 BEGIN
4867
4868 SELECT effective_date, date_earned
4869 INTO l_eff_dt , l_dt_earned
4870 FROM pay_payroll_actions
4871 WHERE payroll_action_id = p_payroll_action_id;
4872
4873 IF to_char(l_eff_dt,'YYYY') <> to_char(l_dt_earned,'YYYY') THEN
4874 RETURN 1 ;
4875 ELSE
4876 RETURN 0;
4877 END IF;
4878
4879 END get_abp_late_hire_indicator;
4880
4881
4882 --
4883 -- ------------------------------------------------------------------------
4884 -- |------------------< get_abp_contribution >----------------------------|
4885 -- ------------------------------------------------------------------------
4886 --
4887 FUNCTION get_abp_contribution
4888 (p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
4889 ,p_date_earned IN DATE
4890 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
4891 ,p_payroll_action_id IN NUMBER
4892 ,p_pension_sub_cat IN pqp_pension_types_f.pension_sub_category%TYPE
4893 ,p_conversion_rule IN pqp_pension_types_f.threshold_conversion_rule%TYPE
4894 ,p_basis_method IN pqp_pension_types_f.pension_basis_calc_method%TYPE
4895 ,p_ee_contrib_type OUT NOCOPY NUMBER
4896 ,p_ee_contrib_value OUT NOCOPY NUMBER
4897 ,p_er_contrib_type OUT NOCOPY NUMBER
4898 ,p_er_contrib_value OUT NOCOPY NUMBER
4899 )
4900 RETURN NUMBER IS
4901
4902 l_org_id hr_all_organization_units.organization_id%TYPE;
4903 l_payroll_id NUMBER;
4904 l_legal_er_org_id NUMBER;
4905 l_ret_value NUMBER := 0;
4906 l_asg_ret_value NUMBER := 0;
4907 l_pension_type_id NUMBER;
4908 l_ee_contrib_value NUMBER;
4909 l_er_contrib_value NUMBER;
4910 l_er_contrib_value_fa NUMBER;
4911 l_pt_ee_contrib NUMBER;
4912 l_pt_er_contrib NUMBER;
4913 l_ee_return_value NUMBER;
4914 l_er_return_value NUMBER;
4915 l_ee_contrib_type VARCHAR2(2) := 'PE';
4916 l_er_contrib_type VARCHAR2(2) := 'PE';
4917 l_ee_age_contribution VARCHAR2(1);
4918 l_er_age_contribution VARCHAR2(1);
4919 l_ee_age_contri_value VARCHAR2(30);
4920 l_er_age_contri_value VARCHAR2(30);
4921 l_chk_abp_scheme NUMBER;
4922 l_dummy NUMBER;
4923 l_ee_asg_eligible NUMBER;
4924 l_ee_hr_org_contrib NUMBER;
4925 l_er_hr_org_contrib NUMBER;
4926 l_er_le_contrib NUMBER;
4927 l_ee_le_contrib NUMBER;
4928 l_cur_ptp NUMBER;
4929 l_date_earned DATE;
4930 l_late_hire_ind NUMBER;
4931 l_abp_sub_cat VARCHAR2(30);
4932
4933 --
4934 -- Cursor to find the contribution values(% or flat amount)
4935 -- and the contribution type from assignment level information,
4936 -- only if the row is valid on date earned.
4937 --
4938 CURSOR c_get_asg_info (c_pty_id IN NUMBER
4939 ,c_date_earned IN DATE) IS
4940 SELECT NVL(paei.aei_information13,'PE'),
4941 fnd_number.canonical_to_number(NVL(paei.aei_information14,'-1'))
4942 ,NVL(paei.aei_information15,'PE'),
4943 fnd_number.canonical_to_number(NVL(paei.aei_information16,'-1'))
4944 FROM per_assignment_extra_info paei
4945 WHERE paei.information_type = 'NL_ABP_PI'
4946 AND paei.aei_information_category = 'NL_ABP_PI'
4947 AND paei.assignment_id = p_assignment_id
4948 AND fnd_number.canonical_to_number(NVL(aei_information3,-1)) = c_pty_id
4949 AND c_date_earned between fnd_date.canonical_to_date(paei.aei_information1)
4950 AND fnd_date.canonical_to_date(NVL(paei.aei_information2,
4951 fnd_date.date_to_canonical(hr_api.g_eot)));
4952
4953 --
4954 -- Cursor to find the contrib% for a given org id
4955 -- Note that this fetches the values for the information
4956 -- with "Applicable to all EE" flag as a param
4957 --
4958 CURSOR c_get_contribution
4959 (c_org_id IN hr_organization_information.organization_id%TYPE
4960 ,c_pt_id IN NUMBER
4961 ,c_date_earned IN DATE) IS
4962 SELECT fnd_number.canonical_to_number(NVL(hoi.org_information4,'-1'))
4963 ,fnd_number.canonical_to_number(NVL(hoi.org_information5,'-1'))
4964 FROM hr_organization_information hoi
4965 WHERE hoi.org_information_context = 'PQP_NL_ABP_PT'
4966 AND hoi.org_information3 = TO_CHAR(c_pt_id)
4967 AND hoi.org_information6 = 'Y'
4968 AND NVL(hoi.org_information7,'Y') = 'Y'
4969 AND hoi.organization_id = c_org_id
4970 AND c_date_earned BETWEEN fnd_date.canonical_to_date(hoi.org_information1)
4971 AND fnd_date.canonical_to_date(NVL(hoi.org_information2,
4972 fnd_date.date_to_canonical(hr_api.g_eot)));
4973
4974 CURSOR c_pt_dtls (c_pty_id IN NUMBER
4975 ,c_date_earned IN DATE) IS
4976 SELECT NVL(pty.ee_age_contribution,'N')
4977 ,NVL(pty.er_age_contribution,'N')
4978 ,ee_contribution_percent
4979 ,er_contribution_percent
4980 FROM pqp_pension_types_f pty
4981 WHERE c_date_earned BETWEEN pty.effective_start_date
4982 AND pty.effective_end_date
4983 AND pension_type_id = c_pty_id;
4984
4985 CURSOR c_find_org (c_date_earned IN DATE)IS
4986 SELECT asg.organization_id
4987 ,asg.payroll_id
4988 ,fnd_number.canonical_to_number(ppf.prl_information1)
4989 FROM per_all_assignments_f asg,
4990 pay_payrolls_f ppf
4991 WHERE asg.assignment_id = p_assignment_id
4992 AND asg.payroll_id = ppf.payroll_id
4993 AND TRUNC(c_date_earned) BETWEEN asg.effective_start_date
4994 AND asg.effective_end_date
4995 AND TRUNC(c_date_earned) BETWEEN ppf.effective_start_date
4996 AND ppf.effective_end_date
4997 AND asg.business_group_id = p_business_group_id;
4998
4999 CURSOR c_cur_ptp (c_eff_dt IN DATE
5000 ,c_asg_id IN NUMBER) IS
5001 SELECT LEAST(fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')),125) ptp
5002 FROM per_assignments_f asg
5003 ,hr_soft_coding_keyflex target
5004 WHERE target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
5005 AND asg.assignment_id = c_asg_id
5006 AND target.enabled_flag = 'Y'
5007 AND TRUNC(c_eff_dt) BETWEEN asg.effective_start_date AND
5008 asg.effective_end_date;
5009
5010 BEGIN
5011
5012 hr_utility.set_location('Entering...',5);
5013 hr_utility.set_location('...Value of p_assignment_id is '||p_assignment_id,10);
5014 hr_utility.set_location('...Value of p_date_earned is '||p_date_earned,15);
5015 hr_utility.set_location('...Value of p_business_group_id is '||p_business_group_id,20);
5016 hr_utility.set_location('...Value of p_pension_sub_cat is '||p_pension_sub_cat,25);
5017 hr_utility.set_location('...Value of p_conversion_rule is '||p_conversion_rule,30);
5018 hr_utility.set_location('...Value of p_basis_method is '||p_basis_method,35);
5019
5020 --
5021 -- Initialize to p_date_earned.
5022 --
5023 l_date_earned := p_date_earned;
5024
5025 --
5026 -- Initialize the variable to the sub cat
5027 --
5028 l_abp_sub_cat := p_pension_sub_cat;
5029
5030 --
5031 -- Check if the date earned is for the month of December
5032 --
5033 IF TO_CHAR(p_date_earned,'MM') = '12' THEN
5034 --
5035 -- Check if the EE is hourly or Regular.
5036 --
5037 OPEN c_cur_ptp(p_date_earned,p_assignment_id);
5038 FETCH c_cur_ptp INTO l_cur_ptp;
5039 CLOSE c_cur_ptp;
5040
5041 IF l_cur_ptp = 0 THEN
5042 l_date_earned := ADD_MONTHS(LAST_DAY(p_date_earned),1);
5043 END IF;
5044
5045 END IF;
5046
5047 --
5048 -- Check if the EE assignment is a late hire for ABP.
5049 -- An EE assignment is a late hire for ABP if it
5050 -- crosses years. For e.g. an EE is hired as of Nov 2006
5051 -- but first payroll is processed in Jan 2007. In such cases
5052 -- for the 2006 calcualtions, percentages from 2007
5053 -- have to be used. This regulation is from ABP (to use
5054 -- the contribution percentages at the moment of payment (date_paid))
5055 --
5056 l_late_hire_ind := 0;
5057 l_late_hire_ind := get_abp_late_hire_indicator(p_payroll_action_id);
5058
5059 IF l_late_hire_ind = 1 THEN
5060
5061 --
5062 -- Check if the sub cat is IPH or IPL. These sub cats are
5063 -- obselete starting from 1 1 2007. But ABP regulation is
5064 -- that if there are EE assignments making contributions
5065 -- for IPH and IPL in 2007 ( over 2006), these should
5066 -- use the AAOP percentages.
5067 --
5068 IF p_pension_sub_cat IN ('IPBW_H','IPBW_L') AND
5069 TRUNC(p_date_earned) < TO_DATE('01/01/2007','DD/MM/YYYY') THEN
5070
5071 --
5072 -- Check if IPH or IPL schemes are created as of p_date_earned
5073 --
5074 l_chk_abp_scheme := chk_abp_scheme_created
5075 (p_date_earned => p_date_earned
5076 ,p_business_group_id => p_business_group_id
5077 ,p_pension_sub_cat => l_abp_sub_cat
5078 ,p_pension_type_id => l_pension_type_id);
5079
5080 IF l_chk_abp_scheme = 1 THEN
5081 --
5082 -- Scheme was created . Check if EE is eligible for the same
5083 --
5084 OPEN c_get_asg_info(l_pension_type_id,p_date_earned);
5085 FETCH c_get_asg_info
5086 INTO l_ee_contrib_type
5087 ,l_ee_contrib_value
5088 ,l_er_contrib_type
5089 ,l_er_contrib_value;
5090
5091 IF c_get_asg_info%FOUND THEN
5092 --
5093 -- Details for IPH and IPL are entered at the assignment
5094 -- set the subcat to AAOP so that the contributions
5095 -- are calculated as per AAOP percentages.
5096 --
5097 SELECT effective_date
5098 INTO l_date_earned
5099 FROM pay_payroll_actions
5100 WHERE payroll_action_id = p_payroll_action_id;
5101
5102 l_abp_sub_cat := 'AAOP';
5103
5104 ELSE
5105 --
5106 -- Check if the EE is eligible for IPL or IPL at the org level
5107 --
5108 --
5109 -- Get the Org id, Legal ER org id and Payroll id
5110 --
5111 OPEN c_find_org(p_date_earned);
5112 FETCH c_find_org
5113 INTO l_org_id,l_payroll_id,l_legal_er_org_id;
5114 CLOSE c_find_org;
5115
5116 hr_utility.set_location('...LH Asg Override not found. Deriving from the org',150);
5117 hr_utility.set_location('...LH Value of l_org_id is'||l_org_id,160);
5118 hr_utility.set_location('...LH Value of l_payroll_id is'||l_payroll_id,170);
5119 hr_utility.set_location('...LH Value of l_legal_er_org_id is'||l_legal_er_org_id,180);
5120
5121 l_ee_asg_eligible := 0;
5122
5123 l_ee_asg_eligible := chk_pt_eligibility
5124 ( p_assignment_id => p_assignment_id
5125 ,p_date_earned => p_date_earned
5126 ,p_business_group_id => p_business_group_id
5127 ,p_pt_id => l_pension_type_id
5128 ,p_hr_org_org_id => l_org_id
5129 ,p_le_org_id => l_legal_er_org_id);
5130
5131 IF l_ee_asg_eligible = 1 THEN
5132
5133 l_abp_sub_cat := 'AAOP';
5134
5135 SELECT effective_date
5136 INTO l_date_earned
5137 FROM pay_payroll_actions
5138 WHERE payroll_action_id = p_payroll_action_id;
5139
5140 END IF;
5141
5142 END IF;
5143
5144 CLOSE c_get_asg_info;
5145
5146 END IF;
5147
5148 ELSE
5149
5150 SELECT effective_date
5151 INTO l_date_earned
5152 FROM pay_payroll_actions
5153 WHERE payroll_action_id = p_payroll_action_id;
5154
5155 END IF;
5156
5157 END IF;
5158
5159 hr_utility.set_location('...Value of l_date_earned is '||l_date_earned,35);
5160
5161 --
5162 -- For a particular ABP Sub Category/BG combination,
5163 -- check if a ABP Pension Scheme is created. No need to go through
5164 -- the logic if a scheme is not created for a sub cat.
5165 --
5166
5167 l_chk_abp_scheme := chk_abp_scheme_created
5168 (p_date_earned => l_date_earned
5169 ,p_business_group_id => p_business_group_id
5170 ,p_pension_sub_cat => l_abp_sub_cat
5171 ,p_pension_type_id => l_pension_type_id);
5172
5173 hr_utility.set_location('...Value of l_chk_abp_scheme is '||l_chk_abp_scheme,40);
5174
5175 IF l_chk_abp_scheme = 1 THEN
5176
5177 hr_utility.set_location('...ABP Pension Scheme created for PT '||l_pension_type_id,45);
5178
5179 --
5180 -- For IPH and IPL after 31 Dec 2006 Return 0%. This is necessary so that
5181 -- the Tax and SI for the retro contributions in 2006 are reduced in 2007.
5182 --
5183 -- IF p_pension_sub_cat IN ('IPBW_H','IPBW_L') AND TRUNC(l_date_earned) > TO_DATE('31/12/2006','DD/MM/YYYY') THEN
5184 -- p_ee_contrib_type := 0;
5185 -- p_er_contrib_type := 0;
5186 -- p_ee_contrib_value := 0;
5187 -- p_er_contrib_value := 0;
5188 -- RETURN 0;
5189 -- END IF;
5190
5191
5192 --
5193 -- Derive the Pension Type details
5194 --
5195 OPEN c_pt_dtls(l_pension_type_id,l_date_earned);
5196 FETCH c_pt_dtls INTO
5197 l_ee_age_contribution
5198 ,l_er_age_contribution
5199 ,l_pt_ee_contrib
5200 ,l_pt_er_contrib;
5201 CLOSE c_pt_dtls;
5202
5203 --
5204 -- Derive the value of ER Age Dpndnt Contribution
5205 --
5206 IF l_er_age_contribution = 'Y' THEN
5207
5208 hr_utility.set_location('...ABP ER component is age dependant',50);
5209 l_er_return_value := get_contribution_percent
5210 (p_assignment_id
5211 ,l_date_earned
5212 ,p_business_group_id
5213 ,l_abp_sub_cat
5214 ,'PQP_NL_ABP_ER_CONTRIBUTION_PERCENT'
5215 ,l_er_age_contri_value);
5216
5217 END IF;
5218
5219 --
5220 -- Derive the value of EE Age Dpndnt Contribution
5221 --
5222 IF l_ee_age_contribution = 'Y' THEN
5223
5224 hr_utility.set_location('...ABP EE component is age dependant',55);
5225
5226 l_ee_return_value := get_contribution_percent
5227 (p_assignment_id
5228 ,l_date_earned
5229 ,p_business_group_id
5230 ,l_abp_sub_cat
5231 ,'PQP_NL_ABP_EE_CONTRIBUTION_PERCENT'
5232 ,l_ee_age_contri_value);
5233
5234 END IF;
5235
5236 --
5237 -- Find the contribution value and type from the asg extra info.
5238 --
5239 OPEN c_get_asg_info(l_pension_type_id,l_date_earned);
5240 FETCH c_get_asg_info
5241 INTO l_ee_contrib_type
5242 ,l_ee_contrib_value
5243 ,l_er_contrib_type
5244 ,l_er_contrib_value;
5245
5246 IF c_get_asg_info%FOUND THEN
5247
5248 hr_utility.set_location('...Data found at the Asg EIT',60);
5249 hr_utility.set_location('...c_get_asg_info %found ',65);
5250
5251 IF l_er_contrib_type = 'FA' THEN
5252 l_er_contrib_value_fa := l_er_contrib_value;
5253 END IF;
5254 --
5255 -- If the contribution % is not entered, check if the pension type
5256 -- has age dependant contribution enabled.
5257 --
5258 IF l_ee_contrib_type = 'PE' AND l_ee_contrib_value = -1 THEN
5259
5260 --
5261 -- Contribution value is null or empty.Check to see if the pension
5262 -- type has age dependant contribution enabled.
5263 --
5264
5265 IF l_ee_age_contribution = 'Y' THEN
5266
5267 hr_utility.set_location('...Deriving EE age dependant contribution',70);
5268 p_ee_contrib_value := l_ee_age_contri_value;
5269 p_ee_contrib_type := 0;
5270
5271 ELSE
5272 -- Derive the contribution percentage for certain set of
5273 -- assignments. This is indicated at the org level via the
5274 -- "Applicable to all employees" flag in the org developer df
5275
5276 hr_utility.set_location('...Deriving contribution based on Applicable to all employees flag',75);
5277
5278 l_asg_ret_value:= get_abp_org_contrib_percent
5279 (p_assignment_id => p_assignment_id
5280 ,p_date_earned => l_date_earned
5281 ,p_business_group_id => p_business_group_id
5282 ,p_pension_type_id => l_pension_type_id
5283 ,p_ee_contrib => l_ee_contrib_value
5284 ,p_er_contrib => l_dummy
5285 ,p_app_to_all_ee => 'N');
5286
5287 p_ee_contrib_value := l_ee_contrib_value;
5288 p_ee_contrib_type := 0;
5289 l_ee_return_value := l_asg_ret_value;
5290
5291 END IF;-- EE Age Dependant Check
5292
5293 ELSE
5294 --
5295 -- User has defined either a FA or PE return these
5296 --
5297 hr_utility.set_location('...EE Asg Contribution is a PE or FA ',80);
5298 SELECT DECODE(l_ee_contrib_type,'PE',0,'FA',1)
5299 INTO p_ee_contrib_type
5300 FROM dual;
5301 p_ee_contrib_value := l_ee_contrib_value;
5302 l_ee_return_value := 0;
5303
5304 END IF;
5305
5306 IF l_er_contrib_type = 'PE' AND l_er_contrib_value = -1 THEN
5307 --
5308 -- contribution type or value has been left empty,
5309 -- so check to see if the pension type has age
5310 -- dependant contribution enabled
5311 --
5312
5313 IF l_er_age_contribution = 'Y' THEN
5314
5315 hr_utility.set_location('...Deriving ER age dependant contribution',90);
5316 p_er_contrib_value := l_er_age_contri_value;
5317 p_er_contrib_type := 0;
5318
5319 ELSE
5320 --
5321 -- Derive the contribution percentage for certain set of
5322 -- assignments. This is indicated at the org level via the
5323 -- "Applicable to all employees" flag in the org developer df
5324 --
5325 hr_utility.set_location('...Deriving contribution based on Applicable to all employees flag',95);
5326 l_asg_ret_value:= get_abp_org_contrib_percent
5327 (p_assignment_id => p_assignment_id
5328 ,p_date_earned => l_date_earned
5329 ,p_business_group_id => p_business_group_id
5330 ,p_pension_type_id => l_pension_type_id
5331 ,p_ee_contrib => l_dummy
5332 ,p_er_contrib => l_er_contrib_value
5333 ,p_app_to_all_ee => 'N');
5334
5335 p_er_contrib_value := l_er_contrib_value;
5336 p_er_contrib_type := 0;
5337 l_er_return_value := l_asg_ret_value;
5338
5339 END IF;
5340
5341 ELSE
5342
5343 SELECT DECODE(l_er_contrib_type,'PE',0,'FA',1)
5344 INTO p_er_contrib_type
5345 FROM dual;
5346 hr_utility.set_location('...ER Asg Contribution is a PE or FA ',100);
5347 p_er_contrib_value := l_er_contrib_value;
5348 l_er_return_value := 0;
5349
5350 END IF;
5351
5352 CLOSE c_get_asg_info;
5353
5354 IF l_ee_return_value = 1 and l_er_return_value = 1 THEN
5355 l_ret_value := 1;
5356 ELSE
5357 l_ret_value := 0;
5358 END IF;
5359
5360 hr_utility.set_location('...Asg EE Contrib Type is '||p_ee_contrib_type,110);
5361 hr_utility.set_location('...Asg ER Contrib Type is '||p_er_contrib_type,120);
5362 hr_utility.set_location('...Asg EE Contrib Val is '||p_ee_contrib_value,130);
5363 hr_utility.set_location('...Asg ER Contrib Val is '||p_er_contrib_value,140);
5364
5365 ELSE
5366 --
5367 -- No overridden row at ASG level on this date,
5368 -- so search at the HR org and ER Levels.
5369 --
5370 CLOSE c_get_asg_info;
5371
5372 --
5373 -- Get the Org id, Legal ER org id and Payroll id
5374 --
5375 OPEN c_find_org(l_date_earned);
5376 FETCH c_find_org
5377 INTO l_org_id,l_payroll_id,l_legal_er_org_id;
5378 CLOSE c_find_org;
5379
5380 hr_utility.set_location('...Asg Override not found. Deriving from the org',150);
5381 hr_utility.set_location('...Value of l_org_id is'||l_org_id,160);
5382 hr_utility.set_location('...Value of l_payroll_id is'||l_payroll_id,170);
5383 hr_utility.set_location('...Value of l_legal_er_org_id is'||l_legal_er_org_id,180);
5384
5385 l_ee_asg_eligible := 0;
5386
5387 l_ee_asg_eligible := chk_pt_eligibility
5388 ( p_assignment_id => p_assignment_id
5389 ,p_date_earned => l_date_earned
5390 ,p_business_group_id => p_business_group_id
5391 ,p_pt_id => l_pension_type_id
5392 ,p_hr_org_org_id => l_org_id
5393 ,p_le_org_id => l_legal_er_org_id);
5394
5395 IF l_ee_asg_eligible = 1 THEN
5396 --
5397 -- Intialize various variables
5398 --
5399 p_ee_contrib_type := 0;
5400 p_er_contrib_type := 0;
5401 p_ee_contrib_value := -1;
5402 p_er_contrib_value := -1;
5403 l_ret_value := 0;
5404
5405 --
5406 -- If the PT is age dependant, assign these values.
5407 --
5408 IF l_ee_age_contribution = 'Y' THEN
5409 hr_utility.set_location('...Age dependant contribution enabled',20);
5410 p_ee_contrib_value := l_ee_age_contri_value;
5411 END IF;
5412
5413 IF l_er_age_contribution = 'Y' THEN
5414 hr_utility.set_location('...Age dependant contribution enabled',20);
5415 p_er_contrib_value := l_er_age_contri_value;
5416 END IF;
5417
5418 --
5419 -- If the values are not populated derive from the HR Org.
5420 --
5421 IF p_ee_contrib_value = -1 OR p_er_contrib_value = -1 THEN
5422
5423 OPEN c_get_contribution
5424 (c_org_id => l_org_id
5425 ,c_pt_id => l_pension_type_id
5426 ,c_date_earned => l_date_earned);
5427 FETCH c_get_contribution
5428 INTO l_ee_hr_org_contrib,l_er_hr_org_contrib;
5429 CLOSE c_get_contribution;
5430
5431 IF p_ee_contrib_value = -1 AND l_ee_hr_org_contrib IS NOT NULL THEN
5432 p_ee_contrib_value := l_ee_hr_org_contrib;
5433 END IF;
5434
5435 IF p_er_contrib_value = -1 AND l_er_hr_org_contrib IS NOT NULL THEN
5436 p_er_contrib_value := l_er_hr_org_contrib;
5437 END IF;
5438
5439 END IF;
5440
5441 --
5442 -- If the values are not populated derive from the Legal ER.
5443 --
5444 IF p_ee_contrib_value = -1 OR p_er_contrib_value = -1 THEN
5445
5446 OPEN c_get_contribution
5447 (c_org_id => l_legal_er_org_id
5448 ,c_pt_id => l_pension_type_id
5449 ,c_date_earned => l_date_earned);
5450 FETCH c_get_contribution
5451 INTO l_ee_le_contrib,l_er_le_contrib;
5452 CLOSE c_get_contribution;
5453
5454 IF p_ee_contrib_value = -1 AND l_ee_le_contrib IS NOT NULL THEN
5455 p_ee_contrib_value := l_ee_le_contrib;
5456 END IF;
5457
5458 IF p_er_contrib_value = -1 AND l_er_le_contrib IS NOT NULL THEN
5459 p_er_contrib_value := l_er_le_contrib;
5460 END IF;
5461
5462 END IF;
5463
5464 --
5465 -- If the values are not populated derive from the PT
5466 --
5467 IF p_ee_contrib_value = -1 OR p_er_contrib_value = -1 THEN
5468
5469 IF p_ee_contrib_value = -1 THEN
5470 p_ee_contrib_value := l_pt_ee_contrib;
5471 END IF;
5472
5473 IF p_er_contrib_value = -1 THEN
5474 p_er_contrib_value := l_pt_er_contrib;
5475 END IF;
5476
5477 END IF;
5478
5479 ELSE
5480 --
5481 -- EE is not eligible for this PT as there is no valid
5482 -- information at the org level as of date earned.
5483 --
5484 l_ret_value := 1;
5485
5486 END IF; -- Check for EE Asg eligibility
5487
5488 END IF; -- Asg Override Found
5489
5490 ELSE
5491
5492 --
5493 -- Scheme is not created no need to derive %
5494 --
5495 l_ret_value := 1;
5496
5497 END IF; -- Scheme creation check for a subcat
5498
5499 hr_utility.set_location('...EE Contrib Type is '||p_ee_contrib_type,40);
5500 hr_utility.set_location('...ER Contrib Type is '||p_er_contrib_type,50);
5501 hr_utility.set_location('...EE Contrib Value is '||p_ee_contrib_value,40);
5502 hr_utility.set_location('...ER Contrib Value is '||p_er_contrib_value,50);
5503
5504 RETURN l_ret_value;
5505
5506 EXCEPTION
5507
5508 WHEN OTHERS THEN
5509 hr_utility.set_location('...Entered WHEN OTHERS EXCEPTION ',40);
5510 l_ret_value := 1;
5511
5512 END get_abp_contribution;
5513
5514 --
5515 -- ------------------------------------------------------------------------
5516 -- |------------------< get_participation_date >----------------------------|
5517 -- ------------------------------------------------------------------------
5518 --
5519 FUNCTION get_participation_date
5520 (p_assignment_id in per_all_assignments_f.assignment_id%TYPE
5521 ,p_date_earned in date
5522 ,p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
5523 ,p_pension_type_id in pqp_pension_types_f.pension_type_id%TYPE
5524 ,p_start_date out NOCOPY date
5525 )
5526 RETURN number IS
5527
5528 l_org_id hr_all_organization_units.organization_id%type;
5529 l_ret_value number := 0; --return
5530 l_asg_extra_info_id per_assignment_extra_info.assignment_extra_info_id%type;
5531 l_org_info_id hr_organization_information.org_information_id%type;
5532 l_named_hierarchy number;
5533 l_version_id per_org_structure_versions_v.org_structure_version_id%type default null;
5534 l_loop_again number;
5535 l_is_org_info_valid varchar2(1);
5536
5537 --Cursor to find the org id from the assignment id
5538 CURSOR c_find_org_id IS
5539 SELECT organization_id
5540 FROM per_all_assignments_f
5541 WHERE assignment_id = p_assignment_id
5542 AND trunc(p_date_earned) between effective_start_date and effective_end_date
5543 AND business_group_id = p_business_group_id;
5544
5545 --Cursor to find the named hierarchy associated with the BG
5546 CURSOR c_find_named_hierarchy Is
5547 select org_information1
5548 from hr_organization_information
5549 where organization_id = p_business_group_id
5550 and org_information_context = 'NL_BG_INFO';
5551
5552 --Cursor to find the valid version id for the particular named hierarchy
5553 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id in Number) Is
5554 select ORG_STRUCTURE_VERSION_ID
5555 from per_org_structure_versions_v
5556 where organization_structure_id = c_hierarchy_id
5557 and p_date_earned between date_from
5558 and nvl(date_to,hr_api.g_eot);
5559
5560 --Cursor to find the valid version id for a particular business group
5561 CURSOR c_find_ver_frm_bg Is
5562 select ORG_STRUCTURE_VERSION_ID
5563 from per_org_structure_versions_v
5564 where business_group_id = p_business_group_id
5565 and p_date_earned between date_from
5566 and nvl( date_to,hr_api.g_eot);
5567
5568 --Cursor to find the parent id from the org id
5569 CURSOR c_find_parent_id(c_org_id in number
5570 ,c_version_id in number) IS
5571 select organization_id_parent
5572 from per_org_structure_elements
5573 where organization_id_child = c_org_id
5574 AND org_structure_version_id = c_version_id
5575 AND business_group_id = p_business_group_id;
5576
5577 --Cursor to find if there is any information record at the assignment level
5578 --if so return the asg extra info id
5579 CURSOR c_get_valid_asg_info Is
5580 Select paei.assignment_extra_info_id
5581 from per_assignment_extra_info paei
5582 where paei.information_type = 'NL_ABP_PI'
5583 and paei.aei_information_category = 'NL_ABP_PI'
5584 and paei.aei_information3 = to_char(p_pension_type_id)
5585 and paei.assignment_id = p_assignment_id;
5586
5587 --Cursor to find if there is any information record at the org level
5588 --if so return the org info id
5589 CURSOR c_get_valid_org_info(c_org_id in hr_all_organization_units.organization_id%type) IS
5590 Select hoi.org_information_id
5591 from hr_organization_information hoi
5592 where hoi.org_information_context = 'PQP_NL_ABP_PT'
5593 and hoi.org_information3 = to_char(p_pension_type_id)
5594 AND hoi.org_information6 = 'Y'
5595 AND NVL(hoi.org_information7,'Y') = 'Y'
5596 and hoi.organization_id = c_org_id;
5597
5598 --Cursor to find the participation start date from assignment level information
5599 CURSOR c_get_asg_info Is
5600 SELECT fnd_date.canonical_to_date(paei.aei_information1)
5601 FROM per_assignment_extra_info paei
5602 WHERE paei.information_type = 'NL_ABP_PI'
5603 and paei.aei_information_category = 'NL_ABP_PI'
5604 and paei.aei_information3 = to_char(p_pension_type_id)
5605 and paei.assignment_id = p_assignment_id
5606 and p_date_earned between fnd_date.canonical_to_date(paei.aei_information1)
5607 and fnd_date.canonical_to_date(nvl(paei.aei_information2,fnd_date.date_to_canonical(hr_api.g_eot)));
5608
5609 --Cursor to find the participation start date from org level information
5610 CURSOR c_get_org_info(c_org_id in hr_organization_information.organization_id%type) Is
5611 SELECT fnd_date.canonical_to_date(hoi.org_information1)
5612 FROM hr_organization_information hoi
5613 where hoi.org_information_context = 'PQP_NL_ABP_PT'
5614 and hoi.org_information3 = to_char(p_pension_type_id)
5615 and hoi.org_information6 = 'Y'
5616 and NVL(hoi.org_information7,'Y') = 'Y'
5617 and hoi.organization_id = c_org_id
5618 and p_date_earned between fnd_date.canonical_to_date(hoi.org_information1)
5619 and fnd_date.canonical_to_date(nvl(hoi.org_information2,fnd_date.date_to_canonical(hr_api.g_eot)));
5620
5621 BEGIN
5622 -- first check to see if any row exists at the ASG attribute level
5623 OPEN c_get_valid_asg_info;
5624 FETCH c_get_valid_asg_info INTO l_asg_extra_info_id;
5625 IF c_get_valid_asg_info%FOUND THEN
5626 hr_utility.set_location('found row at ASG EIT level',10);
5627 -- find the participation start date from the asg extra info
5628 CLOSE c_get_valid_asg_info;
5629 OPEN c_get_asg_info;
5630 FETCH c_get_asg_info INTO p_start_date;
5631 IF c_get_asg_info%FOUND THEN
5632 l_ret_value := 0;
5633 CLOSE c_get_asg_info;
5634 ELSE
5635 p_start_date := hr_api.g_eot;
5636 l_ret_value := 1;
5637 CLOSE c_get_asg_info;
5638 END IF;
5639 ELSE -- no row at ASG level on this date,so search up the org hierarchy
5640 CLOSE c_get_valid_asg_info;
5641 -- find the org the assignment is attached to
5642 OPEN c_find_org_id;
5643 FETCH c_find_org_id INTO l_org_id;
5644 CLOSE c_find_org_id;
5645
5646 --first chk to see if a named hierarchy exists for the BG
5647 OPEN c_find_named_hierarchy;
5648 FETCH c_find_named_hierarchy INTO l_named_hierarchy;
5649 -- if a named hiearchy is found , find the valid version on that date
5650 IF c_find_named_hierarchy%FOUND THEN
5651 CLOSE c_find_named_hierarchy;
5652 -- now find the valid version on that date
5653 OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
5654 FETCH c_find_ver_frm_hierarchy INTO l_version_id;
5655 --if no valid version is found, try to get it frm the BG
5656 IF c_find_ver_frm_hierarchy%NOTFOUND THEN
5657 CLOSE c_find_ver_frm_hierarchy;
5658 -- find the valid version id from the BG
5659 OPEN c_find_ver_frm_bg;
5660 FETCH c_find_ver_frm_bg INTO l_version_id;
5661 CLOSE c_find_ver_frm_bg;
5662 -- else a valid version has been found for the named hierarchy
5663 ELSE
5664 CLOSE c_find_ver_frm_hierarchy;
5665 END IF; --end of if no valid version found
5666 -- else find the valid version from BG
5667 ELSE
5668 CLOSE c_find_named_hierarchy;
5669 --now find the version number from the BG
5670 OPEN c_find_ver_frm_bg;
5671 FETCH c_find_ver_frm_bg INTO l_version_id;
5672 CLOSE c_find_ver_frm_bg;
5673 END IF; -- end of if named hierarchy found
5674
5675 -- loop through the org hierarchy to find the participation start date at
5676 -- this org level or its parents
5677 l_loop_again := 1;
5678 WHILE (l_loop_again = 1)
5679
5680 LOOP
5681 -- if any org info row is found for this particular org id
5682 -- for a pension type with the given pension type id
5683 -- then return that org info id
5684 OPEN c_get_valid_org_info(l_org_id);
5685 FETCH c_get_valid_org_info INTO l_org_info_id;
5686 IF c_get_valid_org_info%FOUND THEN
5687 hr_utility.set_location('found row @ org info level'||l_org_id,20);
5688 l_loop_again := 0;
5689 CLOSE c_get_valid_org_info;
5690 -- fetch the participation start date from the org info row
5691 OPEN c_get_org_info(l_org_id);
5692 FETCH c_get_org_info INTO p_start_date;
5693 IF c_get_org_info%FOUND THEN
5694 l_ret_value := 0;
5695 l_loop_again := 0;
5696 CLOSE c_get_org_info;
5697 ELSE
5698 l_ret_value := 1;
5699 l_loop_again := 0;
5700 CLOSE c_get_org_info;
5701 END IF;
5702
5703 ELSE -- search at the parent level of the current org
5704 CLOSE c_get_valid_org_info;
5705 -- fetch the parent of this org and loop again
5706 OPEN c_find_parent_id(l_org_id,l_version_id);
5707 FETCH c_find_parent_id INTO l_org_id;
5708 IF c_find_parent_id%NOTFOUND THEN -- the topmost org has been reached
5709 CLOSE c_find_parent_id;
5710 l_ret_value := 1;
5711 l_loop_again := 0;
5712 ELSE
5713 CLOSE c_find_parent_id;
5714 END IF;
5715 END IF;
5716 END LOOP;
5717 END IF; -- end of if valid asg info row found
5718 --hr_utility.trace_off;
5719 return l_ret_value;
5720
5721 END get_participation_date;
5722
5723 --
5724 -- ------------------------------------------------------------------------
5725 -- |------------------< get_participation_org >----------------------------|
5726 -- ------------------------------------------------------------------------
5727 --
5728 PROCEDURE get_participation_org
5729 (p_assignment_id in per_all_assignments_f.assignment_id%TYPE
5730 ,p_date_earned in date
5731 ,p_pension_type_id in pqp_pension_types_f.pension_type_id%TYPE
5732 ,p_asg_or_org out NOCOPY number
5733 ,p_org_id out NOCOPY number
5734 )
5735 IS
5736
5737 l_org_id hr_all_organization_units.organization_id%type;
5738 l_asg_extra_info_id per_assignment_extra_info.assignment_extra_info_id%type;
5739 l_org_info_id hr_organization_information.org_information_id%type;
5740 l_named_hierarchy number;
5741 l_version_id per_org_structure_versions_v.org_structure_version_id%type default null;
5742 l_loop_again number;
5743 l_is_org_info_valid varchar2(1);
5744 l_bgid number;
5745
5746 --Cursor to find the org id from the assignment id
5747 CURSOR c_find_org_id IS
5748 SELECT organization_id,business_group_id
5749 FROM per_all_assignments_f
5750 WHERE assignment_id = p_assignment_id
5751 AND trunc(p_date_earned) between effective_start_date and effective_end_date;
5752
5753 --Cursor to find the named hierarchy associated with the BG
5754 CURSOR c_find_named_hierarchy(c_bgid in number) Is
5755 select org_information1
5756 from hr_organization_information
5757 where organization_id = c_bgid
5758 and org_information_context = 'NL_BG_INFO';
5759
5760 --Cursor to find the valid version id for the particular named hierarchy
5761 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id in Number) Is
5762 select ORG_STRUCTURE_VERSION_ID
5763 from per_org_structure_versions_v
5764 where organization_structure_id = c_hierarchy_id
5765 and p_date_earned between date_from
5766 and nvl(date_to,hr_api.g_eot);
5767
5768 --Cursor to find the valid version id for a particular business group
5769 CURSOR c_find_ver_frm_bg(c_bgid in number) Is
5770 select ORG_STRUCTURE_VERSION_ID
5771 from per_org_structure_versions_v
5772 where business_group_id = c_bgid
5773 and p_date_earned between date_from
5774 and nvl( date_to,hr_api.g_eot);
5775
5776 --Cursor to find the parent id from the org id
5777 CURSOR c_find_parent_id(c_org_id in number
5778 ,c_version_id in number
5779 ,c_bgid in number) IS
5780 select organization_id_parent
5781 from per_org_structure_elements
5782 where organization_id_child = c_org_id
5783 AND org_structure_version_id = c_version_id
5784 AND business_group_id = c_bgid;
5785
5786 --Cursor to find if the information record at the assignment level is valid
5787 -- on the date earned and if so return the asg extra info id
5788 CURSOR c_get_valid_asg_info Is
5789 Select paei.assignment_extra_info_id
5790 from per_assignment_extra_info paei
5791 where paei.information_type = 'NL_ABP_PI'
5792 and paei.aei_information_category = 'NL_ABP_PI'
5793 and paei.aei_information3 = to_char(p_pension_type_id)
5794 and paei.assignment_id = p_assignment_id
5795 and p_date_earned between trunc(to_date(substr(paei.aei_information1,1,10),'YYYY/MM/DD'))
5796 and trunc(to_date(substr(nvl(paei.aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'));
5797
5798 --Cursor to find if the information record at the org level is valid
5799 --on the date earned and if so return the org info id
5800 CURSOR c_get_valid_org_info(c_org_id in hr_all_organization_units.organization_id%type) IS
5801 Select hoi.org_information_id
5802 from hr_organization_information hoi
5803 where hoi.org_information_context = 'PQP_NL_ABP_PT'
5804 and hoi.org_information3 = to_char(p_pension_type_id)
5805 and hoi.org_information6 = 'Y'
5806 AND NVL(hoi.org_information7,'Y') = 'Y'
5807 and hoi.organization_id = c_org_id
5808 and p_date_earned between trunc(to_date(substr(hoi.org_information1,1,10),'YYYY/MM/DD'))
5809 and trunc(to_date(substr(nvl(hoi.org_information2,'4712/12/31'),1,10),'YYYY/MM/DD'));
5810
5811 BEGIN
5812
5813 -- first check to see if a valid row exists at the ASG attribute level
5814 -- on the date earned for the pension type id given
5815 OPEN c_get_valid_asg_info;
5816 FETCH c_get_valid_asg_info INTO l_asg_extra_info_id;
5817 IF c_get_valid_asg_info%FOUND THEN
5818 --set the participation as frm ASG and org id to 0
5819 CLOSE c_get_valid_asg_info;
5820 p_asg_or_org := 0;
5821 p_org_id := 0;
5822 ELSE -- no valid row at ASG level on this date,so search up the org hierarchy
5823 CLOSE c_get_valid_asg_info;
5824 -- find the org the assignment is attached to
5825 OPEN c_find_org_id;
5826 FETCH c_find_org_id INTO l_org_id,l_bgid;
5827 CLOSE c_find_org_id;
5828
5829 --first chk to see if a named hierarchy exists for the BG
5830 OPEN c_find_named_hierarchy(l_bgid);
5831 FETCH c_find_named_hierarchy INTO l_named_hierarchy;
5832 -- if a named hiearchy is found , find the valid version on that date
5833 IF c_find_named_hierarchy%FOUND THEN
5834 CLOSE c_find_named_hierarchy;
5835 -- now find the valid version on that date
5836 OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
5837 FETCH c_find_ver_frm_hierarchy INTO l_version_id;
5838 --if no valid version is found, try to get it frm the BG
5839 IF c_find_ver_frm_hierarchy%NOTFOUND THEN
5840 CLOSE c_find_ver_frm_hierarchy;
5841 -- find the valid version id from the BG
5842 OPEN c_find_ver_frm_bg(l_bgid);
5843 FETCH c_find_ver_frm_bg INTO l_version_id;
5844 CLOSE c_find_ver_frm_bg;
5845 -- else a valid version has been found for the named hierarchy
5846 ELSE
5847 CLOSE c_find_ver_frm_hierarchy;
5848 END IF; --end of if no valid version found
5849 -- else find the valid version from BG
5850 ELSE
5851 CLOSE c_find_named_hierarchy;
5852 --now find the version number from the BG
5853 OPEN c_find_ver_frm_bg(l_bgid);
5854 FETCH c_find_ver_frm_bg INTO l_version_id;
5855 CLOSE c_find_ver_frm_bg;
5856 END IF; -- end of if named hierarchy found
5857
5858 -- loop through the org hierarchy to find the ORG trigerring
5859 -- this enrollment
5860 l_loop_again := 1;
5861 WHILE (l_loop_again = 1)
5862
5863 LOOP
5864 -- if a valid org info row is found for this particular org id
5865 -- for a pension type with the given pension type id
5866 -- on this date, then return that org info id
5867 OPEN c_get_valid_org_info(l_org_id);
5868 FETCH c_get_valid_org_info INTO l_org_info_id;
5869 IF c_get_valid_org_info%FOUND THEN
5870 CLOSE c_get_valid_org_info;
5871 p_asg_or_org := 1;
5872 p_org_id := l_org_id;
5873 l_loop_again := 0;
5874 ELSE -- search at the parent level of the current org
5875 CLOSE c_get_valid_org_info;
5876 -- fetch the parent of this org and loop again
5877 OPEN c_find_parent_id(l_org_id,l_version_id,l_bgid);
5878 FETCH c_find_parent_id INTO l_org_id;
5879 IF c_find_parent_id%NOTFOUND THEN
5880 l_loop_again := 0;
5881 CLOSE c_find_parent_id;
5882 ELSE
5883 CLOSE c_find_parent_id;
5884 END IF;
5885 END IF;
5886 END LOOP;
5887 END IF; -- end of if valid asg info row found
5888
5889 END get_participation_org;
5890
5891 --
5892 -- ------------------------------------------------------------------------
5893 -- |---------------------< chk_dup_pp_row_ins >----------------------------|
5894 -- ------------------------------------------------------------------------
5895 --
5896 PROCEDURE chk_dup_pp_row_ins(p_org_information_id IN number
5897 ,p_org_information_context IN varchar2
5898 ,p_organization_id IN number
5899 ,p_org_information1 IN varchar2
5900 ,p_org_information2 IN varchar2
5901 ,p_org_information3 IN varchar2
5902 ) IS
5903
5904 --cursor to fetch the effective date the user has datetracked to
5905 CURSOR c_get_eff_date IS
5906 SELECT effective_date
5907 FROM fnd_sessions
5908 WHERE session_id = userenv('sessionid');
5909
5910 --cursor to check to see if there are any rows in the ORG EIT
5911 CURSOR c_rows_exist IS
5912 SELECT 1
5913 FROM hr_organization_information
5914 WHERE EXISTS
5915 (SELECT 1
5916 FROM hr_organization_information
5917 WHERE organization_id = p_organization_id
5918 AND org_information_context = p_org_information_context
5919 AND org_information_id <> p_org_information_id
5920 );
5921
5922 l_eff_date DATE;
5923 l_rows_exist NUMBER := 0;
5924 l_proc varchar2(20) := 'chk_dup_pp_row_ins';
5925
5926 BEGIN
5927 hr_utility.set_location('Entering : '||l_proc,10);
5928 --first find the eff date the user had datetracked to
5929 OPEN c_get_eff_date;
5930 FETCH c_get_eff_date INTO l_eff_date;
5931 CLOSE c_get_eff_date;
5932 hr_utility.set_location('got the effective date : '||l_eff_date,20);
5933
5934 --check to see if a row already exists in the EIT for this org
5935 OPEN c_rows_exist;
5936 FETCH c_rows_exist INTO l_rows_exist;
5937 IF c_rows_exist%FOUND THEN
5938 CLOSE c_rows_exist;
5939 hr_utility.set_message(8303,'ONLY_ONE_ROW_CAN_EXIST');
5940 hr_utility.raise_error;
5941 ELSE
5942 CLOSE c_rows_exist;
5943 END IF;
5944
5945 --call the procedure to fire insert of the change events in the
5946 --ben_ext_chg_evt_log table
5947 pqp_nl_ext_functions.create_org_pp_ins_chg_evt
5948 (p_organization_id => p_organization_id
5949 ,p_org_information1 => p_org_information1
5950 ,p_org_information2 => p_org_information2
5951 ,p_org_information3 => p_org_information3
5952 ,p_effective_date => l_eff_date
5953 );
5954
5955 hr_utility.set_location('leaving : '||l_proc,100);
5956 END chk_dup_pp_row_ins;
5957
5958 --
5959 -- ------------------------------------------------------------------------
5960 -- |---------------------< chk_dup_pp_row_upd >----------------------------|
5961 -- ------------------------------------------------------------------------
5962 --
5963 PROCEDURE chk_dup_pp_row_upd(p_org_information_id IN number
5964 ,p_org_information_context IN varchar2
5965 ,p_organization_id IN number
5966 ,p_org_information1 IN varchar2
5967 ,p_org_information2 IN varchar2
5968 ,p_org_information3 IN varchar2
5969 ,p_org_information1_o IN varchar2
5970 ,p_org_information2_o IN varchar2
5971 ,p_org_information3_o IN varchar2
5972 ) IS
5973
5974 CURSOR c_get_eff_date IS
5975 SELECT effective_date
5976 FROM fnd_sessions
5977 WHERE session_id = userenv('sessionid');
5978
5979 l_eff_date DATE;
5980
5981 BEGIN
5982
5983 --first find the eff date the user had datetracked to
5984 OPEN c_get_eff_date;
5985 FETCH c_get_eff_date INTO l_eff_date;
5986 CLOSE c_get_eff_date;
5987
5988 --call the procedure to insert the change in the row into the ben_ext_chg_evt_log table
5989 pqp_nl_ext_functions.create_org_pp_upd_chg_evt
5990 (p_organization_id => p_organization_id
5991 ,p_org_information1 => p_org_information1
5992 ,p_org_information2 => p_org_information2
5993 ,p_org_information3 => p_org_information3
5994 ,p_org_information1_o => p_org_information1_o
5995 ,p_org_information2_o => p_org_information2_o
5996 ,p_org_information3_o => p_org_information3_o
5997 ,p_effective_date => l_eff_date
5998 );
5999
6000
6001 END chk_dup_pp_row_upd;
6002
6003 --
6004 -- ------------------------------------------------------------------------
6005 -- |--------------------< get_absence_adjustment >------------------------|
6006 -- ------------------------------------------------------------------------
6007 --
6008 FUNCTION get_absence_adjustment
6009 (p_assignment_id in per_all_assignments_f.assignment_id%TYPE
6010 ,p_date_earned in date
6011 ,p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
6012 ,p_dedn_amt in number
6013 ,p_adjust_amt out NOCOPY number
6014 ,p_error_message out NOCOPY varchar2
6015 )
6016 RETURN number IS
6017
6018 --cursor to fetch the pay period start and end dates
6019 --for the particular assignment
6020 CURSOR c_get_period_dates IS
6021 SELECT ptp.start_date,ptp.end_date
6022 FROM per_all_assignments_f asg
6023 ,per_time_periods ptp
6024 WHERE asg.assignment_id = p_assignment_id
6025 AND asg.payroll_id = ptp.payroll_id
6026 AND p_date_earned BETWEEN ptp.start_date
6027 AND ptp.end_date;
6028
6029 --
6030 -- Cursor to get the start date for the active asg
6031 --
6032 CURSOR c_get_assign_start_date(c_start_date in date
6033 ,c_end_date in date) IS
6034 SELECT min(asg.effective_start_date)
6035 ,max(asg.effective_end_date)
6036 FROM per_assignments_f asg
6037 ,per_assignment_status_types past
6038 WHERE asg.assignment_status_type_id = past.assignment_status_type_id
6039 AND past.per_system_status = 'ACTIVE_ASSIGN'
6040 AND asg.effective_start_date <= trunc(c_end_date)
6041 AND nvl(asg.effective_end_date, trunc(c_end_date)) >= trunc(c_start_date)
6042 AND asg.assignment_id = p_assignment_id
6043 group by asg.assignment_id;
6044
6045 --cursor to get the sickness element type id and the input value id
6046 --for the Reduction Percentage input
6047 CURSOR c_get_abs_ele IS
6048 SELECT piv.input_value_id
6049 ,pet.element_type_id
6050 FROM pay_input_values_f piv
6051 ,pay_element_types_f pet
6052 WHERE piv.name = 'Reduction Percentage'
6053 AND piv.element_type_id = pet.element_type_id
6054 AND pet.element_name = 'ABP Pensions Premium Reduction Information'
6055 AND p_date_earned BETWEEN piv.effective_start_date
6056 AND piv.effective_end_date
6057 AND p_date_earned BETWEEN pet.effective_start_date
6058 AND pet.effective_end_date;
6059
6060 --cursor to fetch the start and end dates and the element entry id
6061 --for all date tracked element entries made for the Premium Reduction
6062 --element
6063 CURSOR c_get_abs_ele_entry(c_effective_date in date
6064 ,c_element_type_id in number
6065 ,c_input_value_id in number
6066 ,c_period_end_date IN DATE ) IS
6067 SELECT fnd_number.canonical_to_number(nvl(screen_entry_value,'0')) perc_value
6068 ,pee.effective_start_date start_date
6069 ,pee.effective_end_date end_date
6070 FROM pay_element_entry_values_f pef,
6071 pay_element_entries_f pee
6072 WHERE pef.input_value_id = c_input_value_id
6073 AND pef.element_entry_id = pee.element_entry_id
6074 AND pef.effective_start_date = pee.effective_start_date
6075 AND pef.effective_end_date = pee.effective_end_date
6076 AND pee.assignment_id = p_assignment_id
6077 AND pee.element_type_id = c_element_type_id
6078 AND (c_effective_date BETWEEN pee.effective_start_date AND
6079 pee.effective_end_date OR
6080 ( pee.effective_start_date > c_effective_date
6081 AND pee.effective_start_date <= c_period_end_date ));
6082 --
6083 l_start_date DATE;
6084 l_end_date DATE;
6085 l_period_start_date DATE;
6086 l_period_end_date DATE;
6087 l_min_start_date DATE;
6088 l_max_end_date DATE;
6089 l_effective_date DATE;
6090 l_person_id NUMBER;
6091 l_days_in_pp NUMBER;
6092 l_payroll_days NUMBER;
6093 l_abs_ele_id NUMBER;
6094 l_abs_iv_id NUMBER;
6095 l_completed VARCHAR2(1);
6096 l_abs_percent NUMBER := 0;
6097
6098 BEGIN
6099 hr_utility.set_location('entered get_absence_adjustment',10);
6100
6101 --fetch the pay period start and end dates
6102 OPEN c_get_period_dates;
6103 FETCH c_get_period_dates INTO l_period_start_date
6104 ,l_period_end_date;
6105 CLOSE c_get_period_dates;
6106 hr_utility.set_location('start date of pay period : '||l_period_start_date,30);
6107 hr_utility.set_location('end date of pay period : '||l_period_end_date,40);
6108
6109 --fetch the greater of the assigment start date or the period start date
6110 OPEN c_get_assign_start_date(c_start_date => l_period_start_date
6111 ,c_end_date => l_period_end_date);
6112 FETCH c_get_assign_start_date INTO l_effective_date,l_max_end_date;
6113 IF c_get_assign_start_date%FOUND THEN
6114 CLOSE c_get_assign_start_date;
6115 ELSE
6116 CLOSE c_get_assign_start_date;
6117 p_adjust_amt := 0;
6118 return 0;
6119 END IF;
6120
6121 --fetch the element type id and the input value id for the premium
6122 --reduction element
6123 OPEN c_get_abs_ele;
6124 FETCH c_get_abs_ele INTO l_abs_iv_id,l_abs_ele_id;
6125 CLOSE c_get_abs_ele;
6126
6127 hr_utility.set_location('element id : '||l_abs_ele_id,42);
6128 hr_utility.set_location('input value id : '||l_abs_iv_id,45);
6129
6130
6131 l_completed := 'N';
6132
6133 l_effective_date := GREATEST(l_effective_date,trunc(l_period_start_date));
6134 l_min_start_date := l_effective_date;
6135 l_max_end_date := LEAST(l_max_end_date,trunc(l_period_end_date));
6136 hr_utility.set_location('eff date : '||l_effective_date,50);
6137
6138 --find days in the pay period
6139 l_payroll_days := (trunc(l_period_end_date)
6140 - trunc(l_period_start_date)) + 1;
6141
6142 --find the number of days the assignments has been effective in the
6143 --current period
6144 l_days_in_pp := nvl(l_max_end_date,trunc(l_period_end_date))
6145 - nvl(l_min_start_date,trunc(l_period_start_date))
6146 + 1;
6147
6148 hr_utility.set_location('days in pay period : '||l_payroll_days,55);
6149 hr_utility.set_location('days asg valid : '||l_days_in_pp,57);
6150
6151 FOR temp_rec in c_get_abs_ele_entry ( trunc(l_effective_date)
6152 ,l_abs_ele_id
6153 ,l_abs_iv_id
6154 ,l_period_end_date)
6155
6156 LOOP
6157
6158 IF l_completed = 'N' THEN
6159
6160 IF temp_rec.end_date >= trunc(l_period_end_date) THEN
6161 l_end_date := trunc(l_period_end_date);
6162 l_completed := 'Y';
6163 ELSE
6164 l_end_date := temp_rec.end_date;
6165 END IF;
6166
6167 IF temp_rec.start_date < trunc(l_period_start_date) THEN
6168 l_start_date := trunc(l_period_start_date);
6169 ELSE
6170 l_start_date := temp_rec.start_date;
6171 END IF;
6172
6173 hr_utility.set_location('start date : '||l_start_date,60);
6174 hr_utility.set_location('end date : '||l_end_date,70);
6175 hr_utility.set_location('entry value : '||temp_rec.perc_value,80);
6176
6177 l_abs_percent := l_abs_percent + temp_rec.perc_value * ((trunc(l_end_date) -
6178 trunc(l_start_date)) + 1);
6179
6180 END IF;
6181
6182 END LOOP;
6183
6184 --find the average part time percentage value
6185 l_abs_percent := l_abs_percent/l_days_in_pp;
6186
6187 hr_utility.set_location('final value : '||l_abs_percent,90);
6188
6189 p_adjust_amt := ROUND(l_abs_percent,4);
6190
6191 --hr_utility.trace_off;
6192 return 0;
6193
6194 EXCEPTION
6195
6196 WHEN OTHERS THEN
6197
6198 p_adjust_amt := 0;
6199 p_error_message := 'Error occured in get_absence_adjustment : '||SQLERRM;
6200 hr_utility.set_location('error occured exiting get_absence_adjustment',110);
6201 return 1;
6202
6203 END get_absence_adjustment;
6204
6205 --
6206 -- ------------------------------------------------------------------------
6207 -- |----------------------< get_proration_factor>--------------------------|
6208 -- ------------------------------------------------------------------------
6209 --
6210 FUNCTION get_proration_factor
6211 (p_assignment_id in per_all_assignments_f.assignment_id%TYPE
6212 ,p_date_earned in date
6213 ,p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
6214 ,p_proration_factor out NOCOPY number
6215 ,p_error_message out NOCOPY varchar2
6216 )
6217 RETURN number IS
6218
6219 --cursor to fetch the pay period start and end dates
6220 --for the particular assignment
6221 CURSOR c_get_period_dates IS
6222 SELECT ptp.start_date,ptp.end_date
6223 FROM per_all_assignments_f asg
6224 ,per_time_periods ptp
6225 WHERE asg.assignment_id = p_assignment_id
6226 AND asg.payroll_id = ptp.payroll_id
6227 AND p_date_earned BETWEEN ptp.start_date
6228 AND ptp.end_date;
6229
6230 --
6231 -- Cursor to get the start date for the active asg
6232 --
6233 CURSOR c_get_assign_start_date(c_start_date in date
6234 ,c_end_date in date) IS
6235 SELECT min(asg.effective_start_date)
6236 ,max(asg.effective_end_date)
6237 FROM per_assignments_f asg
6238 ,per_assignment_status_types past
6239 WHERE asg.assignment_status_type_id = past.assignment_status_type_id
6240 AND past.per_system_status = 'ACTIVE_ASSIGN'
6241 AND asg.effective_start_date <= trunc(c_end_date)
6242 AND nvl(asg.effective_end_date, trunc(c_end_date)) >= trunc(c_start_date)
6243 AND asg.assignment_id = p_assignment_id
6244 group by asg.assignment_id;
6245
6246 l_period_start_date DATE;
6247 l_period_end_date DATE;
6248 l_min_start_date DATE;
6249 l_max_end_date DATE;
6250 l_effective_date DATE;
6251 l_days_in_pp NUMBER;
6252 l_payroll_days NUMBER;
6253 l_proration_factor NUMBER;
6254
6255 BEGIN
6256 hr_utility.set_location('entered get_proration_factor',10);
6257
6258 --fetch the pay period start and end dates
6259 OPEN c_get_period_dates;
6260 FETCH c_get_period_dates INTO l_period_start_date
6261 ,l_period_end_date;
6262 CLOSE c_get_period_dates;
6263 hr_utility.set_location('start date of pay period : '||l_period_start_date,30);
6264 hr_utility.set_location('end date of pay period : '||l_period_end_date,40);
6265
6266 --fetch the greater of the assigment start date or the period start date
6267 OPEN c_get_assign_start_date(c_start_date => l_period_start_date
6268 ,c_end_date => l_period_end_date);
6269 FETCH c_get_assign_start_date INTO l_effective_date,l_max_end_date;
6270 IF c_get_assign_start_date%FOUND THEN
6271 CLOSE c_get_assign_start_date;
6272 ELSE
6273 CLOSE c_get_assign_start_date;
6274 p_proration_factor := 0;
6275 return 0;
6276 END IF;
6277
6278
6279 l_effective_date := GREATEST(l_effective_date,trunc(l_period_start_date));
6280 l_min_start_date := l_effective_date;
6281 l_max_end_date := LEAST(l_max_end_date,trunc(l_period_end_date));
6282 hr_utility.set_location('eff date : '||l_effective_date,50);
6283
6284 --find days in the pay period
6285 l_payroll_days := (trunc(l_period_end_date)
6286 - trunc(l_period_start_date)) + 1;
6287
6288 --find the number of days the assignments has been effective in the
6289 --current period
6290 l_days_in_pp := nvl(l_max_end_date,trunc(l_period_end_date))
6291 - nvl(l_min_start_date,trunc(l_period_start_date))
6292 + 1;
6293
6294 hr_utility.set_location('days in pay period : '||l_payroll_days,55);
6295 hr_utility.set_location('days asg valid : '||l_days_in_pp,57);
6296
6297 --find the proration factor
6298 l_proration_factor := l_days_in_pp/l_payroll_days;
6299
6300 hr_utility.set_location('final value : '||l_proration_factor,90);
6301
6302 p_proration_factor := l_proration_factor;
6303
6304 --hr_utility.trace_off;
6305 return 0;
6306
6307 EXCEPTION
6308
6309 WHEN OTHERS THEN
6310
6311 p_proration_factor := 1;
6312 p_error_message := 'Error occured in get_proration_factor : '||SQLERRM;
6313 hr_utility.set_location('error occured exiting get_proration_factor',110);
6314 return 1;
6315
6316 END get_proration_factor;
6317
6318 --
6319 -- ------------------------------------------------------------------------
6320 -- |--------------------< get_abp_calc_eff_dt >----------------------------|
6321 -- ------------------------------------------------------------------------
6322 --
6323 FUNCTION get_abp_calc_eff_dt
6324 (p_date_earned IN DATE
6325 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
6326 ,p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
6327 ,p_effective_date OUT NOCOPY DATE
6328 )
6329
6330 RETURN NUMBER IS
6331
6332 -- Cursor to get the hire date of the person
6333 CURSOR c_hire_dt_cur(c_asg_id IN NUMBER) IS
6334 SELECT max(date_start)
6335 FROM per_all_assignments_f asg
6336 ,per_periods_of_service pps
6337 WHERE pps.person_id = asg.person_id
6338 AND asg.assignment_id = c_asg_id
6339 AND pps.business_group_id = p_business_group_id
6340 AND date_start <= p_date_earned;
6341
6342 --cursor to fetch the assignment start date
6343 CURSOR c_get_asg_start IS
6344 SELECT min(effective_start_date)
6345 FROM per_all_assignments_f
6346 WHERE assignment_id = p_assignment_id
6347 AND assignment_type = 'E';
6348
6349 l_run_year NUMBER;
6350 l_begin_of_year_date DATE;
6351 l_asg_st_date DATE;
6352 l_hire_date DATE;
6353
6354 BEGIN
6355
6356 l_run_year := TO_NUMBER(TO_CHAR(p_date_earned,'YYYY'));
6357
6358 --
6359 -- Get the date for 1 JAN of the run year
6360 --
6361 l_begin_of_year_date := TO_DATE('01/01/'||to_char(l_run_year),'DD/MM/YYYY');
6362
6363 --
6364 -- Get the latest start date of the assignment
6365 --
6366 OPEN c_get_asg_start;
6367 FETCH c_get_asg_start INTO l_asg_st_date;
6368 IF c_get_asg_start%FOUND THEN
6369 CLOSE c_get_asg_start;
6370 ELSE
6371 CLOSE c_get_asg_start;
6372 RETURN 1;
6373 END IF;
6374
6375 --
6376 -- Get the hire date
6377 --
6378 OPEN c_hire_dt_cur (p_assignment_id);
6379
6380 FETCH c_hire_dt_cur INTO l_hire_date;
6381 IF c_hire_dt_cur%FOUND THEN
6382 -- The effective date is now the greatest of 1 Jan of the year
6383 -- the hire date and asg start date .
6384 p_effective_date := GREATEST(l_begin_of_year_date,l_hire_date,l_asg_st_date);
6385 CLOSE c_hire_dt_cur;
6386 ELSE
6387 CLOSE c_hire_dt_cur;
6388 RETURN 1;
6389 END IF; -- Hire date found
6390
6391 RETURN 0;
6392
6393 EXCEPTION WHEN OTHERS THEN
6394 RETURN 1;
6395
6396 END;
6397
6398 --
6399 -- ------------------------------------------------------------------------
6400 -- |--------------------< get_proration_flag >----------------------------|
6401 -- ------------------------------------------------------------------------
6402 --
6403 FUNCTION get_proration_flag
6404 (p_date_earned IN DATE
6405 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
6406 ,p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
6407 ,p_assignment_action_id IN per_all_assignments_f.assignment_id%TYPE
6408 ,p_element_type_id IN pay_element_types_f.element_type_id%TYPE
6409 ,p_start_date IN DATE
6410 ,p_end_date IN DATE
6411 )
6412
6413 RETURN VARCHAR2 IS
6414
6415 l_ret_val NUMBER;
6416 l_effective_date DATE;
6417
6418 BEGIN
6419
6420 l_ret_val := pqp_nl_abp_functions.get_abp_calc_eff_dt
6421 (p_date_earned => p_date_earned
6422 ,p_business_group_id => p_business_group_id
6423 ,p_assignment_id => p_assignment_id
6424 ,p_effective_date => l_effective_date
6425 );
6426
6427 IF l_ret_val = 0 THEN
6428 IF trunc(l_effective_date) BETWEEN
6429 trunc(p_start_date) AND
6430 trunc(p_end_date) THEN
6431 RETURN 'Y';
6432 ELSE
6433 RETURN 'N';
6434 END IF;
6435 ELSE
6436 RETURN 'E';
6437 END IF;
6438
6439 END get_proration_flag;
6440
6441 --
6442 -- ------------------------------------------------------------------------
6443 -- |------------------< get_eoy_bonus_percentage >-------------------------|
6444 -- ------------------------------------------------------------------------
6445 --
6446 FUNCTION get_eoy_bonus_percentage
6447 (p_date_earned IN date
6448 ,p_business_group_id IN pqp_pension_types_f.business_group_id%TYPE
6449 ,p_assignment_id IN per_all_assignments_f.assignment_id%TYPE
6450 ,p_eoy_bonus_percentage OUT NOCOPY number
6451 )
6452 RETURN NUMBER IS
6453
6454 --Cursor to find the org id from the assignment id
6455 CURSOR c_find_org_id IS
6456 SELECT organization_id
6457 FROM per_all_assignments_f
6458 WHERE assignment_id = p_assignment_id
6459 AND trunc(p_date_earned) between effective_start_date and effective_end_date
6460 AND business_group_id = p_business_group_id;
6461
6462 --Cursor to find the named hierarchy associated with the BG
6463 CURSOR c_find_named_hierarchy Is
6464 select org_information1
6465 from hr_organization_information
6466 where organization_id = p_business_group_id
6467 and org_information_context = 'NL_BG_INFO';
6468
6469 --Cursor to find the valid version id for the particular named hierarchy
6470 CURSOR c_find_ver_frm_hierarchy(c_hierarchy_id in Number) Is
6471 select ORG_STRUCTURE_VERSION_ID
6472 from per_org_structure_versions_v
6473 where organization_structure_id = c_hierarchy_id
6474 and p_date_earned between date_from
6475 and nvl(date_to,hr_api.g_eot);
6476
6477 --Cursor to find the valid version id for a particular business group
6478 CURSOR c_find_ver_frm_bg Is
6479 select ORG_STRUCTURE_VERSION_ID
6480 from per_org_structure_versions_v
6481 where business_group_id = p_business_group_id
6482 and p_date_earned between date_from
6483 and nvl( date_to,hr_api.g_eot);
6484
6485 --Cursor to find the parent id from the org id
6486 CURSOR c_find_parent_id(c_org_id in number
6487 ,c_version_id in number) IS
6488 select organization_id_parent
6489 from per_org_structure_elements
6490 where organization_id_child = c_org_id
6491 AND org_structure_version_id = c_version_id
6492 AND business_group_id = p_business_group_id;
6493
6494 --Cursor to find the eoy bonus percentage
6495 --if entered at the org level
6496 CURSOR c_find_eoy_percent(c_org_id IN NUMBER) IS
6497 SELECT org_information3
6498 FROM hr_organization_information
6499 WHERE organization_id = c_org_id
6500 AND org_information_context = 'PQP_NL_ABP_PTP_METHOD'
6501 AND org_information3 IS NOT NULL;
6502
6503 l_ret_val NUMBER;
6504 l_named_hierarchy NUMBER;
6505 l_loop_again NUMBER;
6506 l_eoy_percent hr_organization_information.org_information3%TYPE;
6507 l_org_id hr_all_organization_units.organization_id%type;
6508 l_org_info_id hr_organization_information.org_information_id%type;
6509 l_version_id per_org_structure_versions_v.org_structure_version_id%type default null;
6510
6511 BEGIN
6512
6513 hr_utility.set_location('Entering get_eoy_bonus_percentage',10);
6514 --fetch the hr org id from the assignment
6515 OPEN c_find_org_id;
6516 FETCH c_find_org_id INTO l_org_id;
6517 CLOSE c_find_org_id;
6518
6519 hr_utility.set_location('org id for the asg : '||l_org_id,20);
6520 --check to see if a value has been entered for
6521 --the eoy bonus percentage at this org level
6522 OPEN c_find_eoy_percent(l_org_id);
6523 FETCH c_find_eoy_percent INTO l_eoy_percent;
6524 IF c_find_eoy_percent%FOUND THEN
6525 hr_utility.set_location('EOY Bonus Percentage : '||l_eoy_percent,30);
6526 --found a value for the percentage at this org level
6527 --return from this point
6528 CLOSE c_find_eoy_percent;
6529 hr_utility.set_location('Leaving get_eoy_bonus_percentage',35);
6530 p_eoy_bonus_percentage := fnd_number.canonical_to_number(l_eoy_percent);
6531 RETURN 0;
6532 ELSE
6533 --no value found at this org level,try to traverse up the
6534 --org hierarchy to find a value at the parent levels
6535 hr_utility.set_location('no value found at hr org level,going up the tree',40);
6536 CLOSE c_find_eoy_percent;
6537
6538 --first chk to see if a named hierarchy exists for the BG
6539 OPEN c_find_named_hierarchy;
6540 FETCH c_find_named_hierarchy INTO l_named_hierarchy;
6541 -- if a named hiearchy is found , find the valid version on that date
6542 IF c_find_named_hierarchy%FOUND THEN
6543 CLOSE c_find_named_hierarchy;
6544 -- now find the valid version on that date
6545 OPEN c_find_ver_frm_hierarchy(l_named_hierarchy);
6546 FETCH c_find_ver_frm_hierarchy INTO l_version_id;
6547 --if no valid version is found, try to get it frm the BG
6548 IF c_find_ver_frm_hierarchy%NOTFOUND THEN
6549 CLOSE c_find_ver_frm_hierarchy;
6550 -- find the valid version id from the BG
6551 OPEN c_find_ver_frm_bg;
6552 FETCH c_find_ver_frm_bg INTO l_version_id;
6553 CLOSE c_find_ver_frm_bg;
6554 -- else a valid version has been found for the named hierarchy
6555 ELSE
6556 CLOSE c_find_ver_frm_hierarchy;
6557 END IF; --end of if no valid version found
6558 -- else find the valid version from BG
6559 ELSE
6560 CLOSE c_find_named_hierarchy;
6561 --now find the version number from the BG
6562 OPEN c_find_ver_frm_bg;
6563 FETCH c_find_ver_frm_bg INTO l_version_id;
6564 CLOSE c_find_ver_frm_bg;
6565 END IF; -- end of if named hierarchy found
6566
6567 hr_utility.set_location(' l_version_id '||l_version_id,50);
6568
6569 IF l_version_id IS NULL THEN
6570 --no hierarchy has been defined, so return 0%
6571 hr_utility.set_location('No hierarchy found,hence returning 0',60);
6572 hr_utility.set_location('Leaving get_eoy_bonus_percentage',65);
6573 p_eoy_bonus_percentage := 0;
6574 RETURN 0;
6575 END IF;
6576
6577 -- loop through the org hierarchy to find the % values at this org level or its parents
6578 l_loop_again := 1;
6579 WHILE (l_loop_again = 1)
6580 LOOP
6581 --find the parent of this org
6582 OPEN c_find_parent_id(l_org_id,l_version_id);
6583 FETCH c_find_parent_id INTO l_org_id;
6584 IF c_find_parent_id%FOUND THEN
6585 hr_utility.set_location('searching at parent : '||l_org_id,70);
6586 CLOSE c_find_parent_id;
6587 OPEN c_find_eoy_percent(l_org_id);
6588 FETCH c_find_eoy_percent INTO l_eoy_percent;
6589 IF c_find_eoy_percent%FOUND THEN
6590 hr_utility.set_location('found eoy percent as : '||l_eoy_percent,80);
6591 CLOSE c_find_eoy_percent;
6592 p_eoy_bonus_percentage := fnd_number.canonical_to_number(l_eoy_percent);
6593 l_ret_val := 0;
6594 l_loop_again := 0;
6595 ELSE
6596 CLOSE c_find_eoy_percent;
6597 END IF;
6598 ELSE
6599 --no parent found, so return 0
6600 CLOSE c_find_parent_id;
6601 hr_utility.set_location('no parents found,returning 0',90);
6602 p_eoy_bonus_percentage := 0;
6603 l_loop_again := 0;
6604 l_ret_val := 0;
6605 END IF;
6606 END LOOP;
6607 END IF;
6608
6609 hr_utility.set_location('Leaving get_eoy_bonus_percentage',95);
6610 RETURN l_ret_val;
6611
6612 EXCEPTION
6613
6614 WHEN OTHERS THEN
6615 p_eoy_bonus_percentage := 0;
6616 hr_utility.set_location('Error occured : '||SQLERRM,100);
6617 RETURN 1;
6618
6619 END get_eoy_bonus_percentage;
6620
6621 -------------------------------------------------------------------------------
6622 -----------------------------< upd_chg_evt >-----------------------------------
6623 -- ----------------------------------------------------------------------------
6624 -- This procedure updates the change event log registered with a
6625 -- parameter prmtr_09 that contains the ABP Reporting date. The date
6626 -- is derived based on the approval of an ABP Pensions Notification.
6627 -- All reporting to ABP for e.g. Rec 05 and other relevant records
6628 -- are done based on this date. This is also to address certification
6629 -- issues that have been reported due to retrospective changes to various
6630 -- reporting components.
6631 --
6632 PROCEDURE upd_chg_evt
6633 (p_ext_chg_evt_log_id IN NUMBER
6634 ,p_chg_evt_cd IN VARCHAR2
6635 ,p_chg_eff_dt IN DATE
6636 ,p_chg_user_id IN NUMBER
6637 ,p_prmtr_01 IN VARCHAR2
6638 ,p_prmtr_02 IN VARCHAR2
6639 ,p_prmtr_03 IN VARCHAR2
6640 ,p_prmtr_04 IN VARCHAR2
6641 ,p_prmtr_05 IN VARCHAR2
6642 ,p_prmtr_06 IN VARCHAR2
6643 ,p_prmtr_07 IN VARCHAR2
6644 ,p_prmtr_08 IN VARCHAR2
6645 ,p_prmtr_09 IN VARCHAR2
6646 ,p_prmtr_10 IN VARCHAR2
6647 ,p_person_id IN NUMBER
6648 ,p_business_group_id IN NUMBER
6649 ,p_object_version_number IN NUMBER
6650 ,p_effective_date IN DATE
6651 ,p_chg_actl_dt IN DATE
6652 ,p_new_val1 IN VARCHAR2
6653 ,p_new_val2 IN VARCHAR2
6654 ,p_new_val3 IN VARCHAR2
6655 ,p_new_val4 IN VARCHAR2
6656 ,p_new_val5 IN VARCHAR2
6657 ,p_new_val6 IN VARCHAR2
6658 ,p_old_val1 IN VARCHAR2
6659 ,p_old_val2 IN VARCHAR2
6660 ,p_old_val3 IN VARCHAR2
6661 ,p_old_val4 IN VARCHAR2
6662 ,p_old_val5 IN VARCHAR2
6663 ,p_old_val6 IN VARCHAR2 ) IS
6664
6665 --
6666 -- Cursor to get the part time perc from the SC KFF
6667 --
6668 CURSOR c_ptp (c_kff_id IN NUMBER) IS
6669 SELECT fnd_number.canonical_to_number(segment29)
6670 FROM hr_soft_coding_keyflex
6671 WHERE soft_coding_keyflex_id = c_kff_id;
6672
6673 CURSOR c_log_xst( c_kff_id IN NUMBER
6674 ,c_st_dt IN ben_ext_chg_evt_log.prmtr_04%TYPE
6675 ,c_ed_dt IN ben_ext_chg_evt_log.prmtr_05%TYPE
6676 ,c_rep_dt IN ben_ext_chg_evt_log.prmtr_09%TYPE
6677 ,c_asg_id IN ben_ext_chg_evt_log.prmtr_01%TYPE ) IS
6678 SELECT *
6679 FROM ben_ext_chg_evt_log
6680 WHERE chg_evt_cd = 'COPTP'
6681 AND person_id = p_person_id
6682 AND prmtr_04 = c_st_dt
6683 -- AND prmtr_05 = c_ed_dt
6684 AND prmtr_01 = c_asg_id
6685 AND prmtr_02 = c_kff_id;
6686
6687 CURSOR c_upd_log_kff_upd(c_asg_id IN ben_ext_chg_evt_log.prmtr_01%TYPE ) IS
6688 SELECT ext_chg_evt_log_id
6689 ,prmtr_09
6690 FROM ben_ext_chg_evt_log
6691 WHERE chg_evt_cd = 'COPTP'
6692 AND person_id = p_person_id
6693 AND prmtr_01 = c_asg_id
6694 AND prmtr_02 = p_old_val1
6695 AND DECODE(prmtr_05,'4712/12/31 00:00:00',
6696 TRUNC(p_chg_eff_dt) - 1,
6697 TRUNC(fnd_date.canonical_to_date(prmtr_05)))
6698 = TRUNC(p_chg_eff_dt) - 1;
6699
6700 CURSOR c_upd_log_kff(c_asg_id IN ben_ext_chg_evt_log.prmtr_01%TYPE ) IS
6701 SELECT ext_chg_evt_log_id
6702 ,prmtr_09
6703 FROM ben_ext_chg_evt_log
6704 WHERE chg_evt_cd = 'COPTP'
6705 AND person_id = p_person_id
6706 AND prmtr_01 = c_asg_id
6707 AND prmtr_02 = p_old_val1;
6708
6709 CURSOR c_del_log (c_asg_id IN ben_ext_chg_evt_log.prmtr_01%TYPE ) IS
6710 SELECT object_version_number
6711 ,ext_chg_evt_log_id
6712 FROM ben_ext_chg_evt_log
6713 WHERE chg_evt_cd = 'COPTP'
6714 AND person_id = p_person_id
6715 AND prmtr_01 = c_asg_id
6716 AND prmtr_02 = p_old_val1;
6717
6718 l_old_ptp NUMBER;
6719 l_new_ptp NUMBER;
6720 l_ovn NUMBER;
6721 l_ovn1 NUMBER;
6722 l_upd_ovn NUMBER;
6723 l_id NUMBER;
6724 l_id1 NUMBER;
6725 l_xst_log_rec ben_ext_chg_evt_log%ROWTYPE;
6726 l_asg_st_dt ben_ext_chg_evt_log.prmtr_04%TYPE;
6727 l_asg_ed_dt ben_ext_chg_evt_log.prmtr_05%TYPE;
6728 l_out_rep_dt DATE;
6729 l_reporting_dt ben_ext_chg_evt_log.prmtr_09%TYPE;
6730 l_new_log_cre NUMBER;
6731 l_ret_val NUMBER;
6732
6733 BEGIN
6734
6735 --
6736 -- Check if the change event code is COSCKFF
6737 --
6738 IF p_chg_evt_cd = 'COSCKFF' THEN
6739
6740 --
6741 -- Get the reporting date
6742 --
6743 l_ret_val := get_reporting_date
6744 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(p_chg_eff_dt),'YYYY/MM')||'/01')
6745 ,p_assignment_id => fnd_number.canonical_to_number(p_prmtr_01)
6746 ,p_person_id => p_person_id
6747 ,p_reporting_date => l_out_rep_dt );
6748
6749 l_reporting_dt := fnd_date.date_to_canonical(l_out_rep_dt);
6750 l_new_log_cre := 0;
6751
6752 hr_utility.set_location('GAA -- The change event code is COSCKFF',10 );
6753 hr_utility.set_location('GAA -- Reporting date is '||l_reporting_dt,10 );
6754 --
6755 -- Update the change event log row so that prmtr_09 is
6756 -- populated with the next reporting date.
6757 --
6758 l_upd_ovn := p_object_version_number;
6759
6760 ben_xcl_upd.upd
6761 (p_effective_date => TRUNC(p_effective_date)
6762 ,p_ext_chg_evt_log_id => p_ext_chg_evt_log_id
6763 ,p_chg_evt_cd => p_chg_evt_cd
6764 ,p_chg_eff_dt => p_chg_eff_dt
6765 ,p_chg_user_id => p_chg_user_id
6766 ,p_prmtr_01 => p_prmtr_01
6767 ,p_prmtr_02 => p_prmtr_02
6768 ,p_prmtr_03 => p_prmtr_03
6769 ,p_prmtr_04 => p_prmtr_04
6770 ,p_prmtr_05 => p_prmtr_05
6771 ,p_prmtr_06 => p_prmtr_06
6772 ,p_prmtr_07 => p_prmtr_07
6773 ,p_prmtr_08 => p_prmtr_08
6774 ,p_prmtr_09 => l_reporting_dt
6775 ,p_prmtr_10 => p_prmtr_10
6776 ,p_person_id => p_person_id
6777 ,p_business_group_id => p_business_group_id
6778 ,p_object_version_number => l_upd_ovn);
6779
6780 hr_utility.set_location('GAA -- Updated prmtr_09 to the reporting date',10 );
6781
6782 IF p_old_val1 IS NULL and p_new_val1 IS NOT NULL THEN
6783 --
6784 -- This is the first time the SC KFF is being assigned
6785 -- to the assignment . If the value of segment 29 on the
6786 -- SC KFF is NULL, then the PTP to be recorded is NULL
6787 -- For ABP Pensions , NULL will be interpreted as 100%
6788 -- For PGGM it is 0.
6789
6790 -- Call the API to register the part time percentage change
6791 -- event.
6792 NULL;
6793 ELSIF p_old_val1 IS NOT NULL and p_new_val1 IS NOT NULL THEN
6794 hr_utility.set_location('GAA -- KFF Id has changed',10 );
6795 --
6796 -- Assign appropriate assignment start and end dates
6797 --
6798 IF p_prmtr_10 = 'UPDATE' THEN
6799 l_asg_st_dt := p_prmtr_04;
6800 l_asg_ed_dt := p_prmtr_05;
6801 ELSIF p_prmtr_10 = 'CORRECTION' THEN
6802 l_asg_st_dt := p_prmtr_02;
6803 l_asg_ed_dt := p_prmtr_03;
6804 END IF;
6805 hr_utility.set_location('GAA -- prmtr_10 value is : '||p_prmtr_10,10 );
6806
6807 -- Make sure that the reporting date is set to the correct value
6808 -- if the changes are being made for a future date then we use that date
6809 -- to report the change.
6810 IF TRUNC(fnd_date.canonical_to_date(l_asg_st_dt)) >
6811 TRUNC(fnd_date.canonical_to_date(l_reporting_dt)) THEN
6812 l_reporting_dt := fnd_date.date_to_canonical(add_months(fnd_date.canonical_to_date(TO_CHAR(TRUNC(fnd_date.canonical_to_date(l_asg_st_dt)),'YYYY/MM')||'/01'),1) - 1);
6813 END IF;
6814
6815 -- The old KFF id is being replaced by a new one. But it
6816 -- does not nencessarily mean that there has been a change
6817 -- in part time percentage. It can be because of other changes that
6818 -- have happened to the SC KFF segments.
6819
6820 OPEN c_ptp(fnd_number.canonical_to_number(p_old_val1));
6821 FETCH c_ptp INTO l_old_ptp;
6822 CLOSE c_ptp;
6823
6824 OPEN c_ptp(fnd_number.canonical_to_number(p_new_val1));
6825 FETCH c_ptp INTO l_new_ptp;
6826 CLOSE c_ptp;
6827
6828 IF NVL(l_old_ptp,100) <> NVL(l_new_ptp,100) THEN
6829 hr_utility.set_location('GAA -- PTP has changed : ',10 );
6830 --
6831 -- Check the log rows to see if there has been a change of ptp
6832 -- event registerted by the old KFF. If this is true,and the
6833 -- exact same row exists in the db , update it with the changed
6834 -- ptp and the surrogate key that replaced it.
6835 --
6836
6837 OPEN c_log_xst(
6838 c_kff_id => fnd_number.number_to_canonical(p_old_val1)
6839 ,c_st_dt => l_asg_st_dt
6840 ,c_ed_dt => l_asg_ed_dt
6841 ,c_rep_dt => l_reporting_dt
6842 ,c_asg_id => p_prmtr_01);
6843 FETCH c_log_xst INTO l_xst_log_rec;
6844
6845 IF c_log_xst%FOUND THEN
6846 --
6847 -- Update the existing log with the changed part time percentages
6848 --
6849 hr_utility.set_location('GAA -- An existing row is found in the logs: ',10 );
6850 UPDATE ben_ext_chg_evt_log
6851 SET new_val1 = fnd_number.number_to_canonical(l_new_ptp)
6852 ,old_val1 = fnd_number.number_to_canonical(l_old_ptp)
6853 ,prmtr_09 = l_reporting_dt
6854 WHERE ext_chg_evt_log_id = l_xst_log_rec.ext_chg_evt_log_id;
6855
6856 ELSIF c_log_xst%NOTFOUND THEN
6857 hr_utility.set_location('GAA -- Did not find any existing row. Creating new log',10);
6858 --
6859 -- Create new log to register that there has been a
6860 -- change in part time percentage
6861 --
6862 ben_xcl_ins.ins
6863 (p_ext_chg_evt_log_id => l_id
6864 ,p_chg_evt_cd => 'COPTP'
6865 ,p_chg_eff_dt => p_chg_eff_dt
6866 ,p_chg_user_id => p_chg_user_id
6867 ,p_prmtr_01 => p_prmtr_01 -- Assignment Id
6868 ,p_prmtr_02 => p_new_val1 -- New KFF Id
6869 ,p_prmtr_03 => p_prmtr_10 -- Update or Correction
6870 ,p_prmtr_04 => l_asg_st_dt -- Start of change
6871 ,p_prmtr_05 => l_asg_ed_dt -- End of change
6872 ,p_prmtr_06 => NULL
6873 ,p_prmtr_07 => NULL
6874 ,p_prmtr_08 => NULL
6875 ,p_prmtr_09 => l_reporting_dt -- Reporting Date
6876 ,p_prmtr_10 => NULL
6877 ,p_person_id => p_person_id
6878 ,p_business_group_id => p_business_group_id
6879 ,p_object_version_number => l_ovn
6880 ,p_effective_date => TRUNC(p_effective_date)
6881 ,p_chg_actl_dt => p_chg_actl_dt
6882 ,p_new_val1 => fnd_number.number_to_canonical(l_new_ptp)
6883 ,p_new_val2 => NULL
6884 ,p_new_val3 => NULL
6885 ,p_new_val4 => NULL
6886 ,p_new_val5 => NULL
6887 ,p_new_val6 => NULL
6888 ,p_old_val1 => fnd_number.number_to_canonical(l_old_ptp)
6889 ,p_old_val2 => NULL
6890 ,p_old_val3 => NULL
6891 ,p_old_val4 => NULL
6892 ,p_old_val5 => NULL
6893 ,p_old_val6 => NULL);
6894
6895 l_new_log_cre := 1;
6896 END IF;
6897
6898 CLOSE c_log_xst;
6899
6900 ELSIF NVL(l_old_ptp,100) = NVL(l_new_ptp,100) THEN
6901 --
6902 -- Part time percentage has not changed but the flex id is changing.
6903 -- update the surrogate key in the log tables for any changes
6904 -- logged by the old KFF id.
6905 --
6906 hr_utility.set_location('GAA -- PTP is the same no change. KFF id has changed: ',10 );
6907 IF p_prmtr_10 = 'UPDATE' THEN
6908 ben_xcl_ins.ins
6909 (p_ext_chg_evt_log_id => l_id1
6910 ,p_chg_evt_cd => 'COPTP'
6911 ,p_chg_eff_dt => p_chg_eff_dt
6912 ,p_chg_user_id => p_chg_user_id
6913 ,p_prmtr_01 => p_prmtr_01 -- Assignment Id
6914 ,p_prmtr_02 => p_new_val1 -- New KFF Id
6915 ,p_prmtr_03 => p_prmtr_10 -- Update or Correction
6916 ,p_prmtr_04 => l_asg_st_dt -- Start of change
6917 ,p_prmtr_05 => l_asg_ed_dt -- End of change
6918 ,p_prmtr_06 => NULL
6919 ,p_prmtr_07 => NULL
6920 ,p_prmtr_08 => NULL
6921 ,p_prmtr_09 => l_reporting_dt -- Reporting Date
6922 ,p_prmtr_10 => NULL
6923 ,p_person_id => p_person_id
6924 ,p_business_group_id => p_business_group_id
6925 ,p_object_version_number => l_ovn1
6926 ,p_effective_date => TRUNC(p_effective_date)
6927 ,p_chg_actl_dt => p_chg_actl_dt
6928 ,p_new_val1 => fnd_number.number_to_canonical(l_new_ptp)
6929 ,p_new_val2 => NULL
6930 ,p_new_val3 => NULL
6931 ,p_new_val4 => NULL
6932 ,p_new_val5 => NULL
6933 ,p_new_val6 => NULL
6934 ,p_old_val1 => fnd_number.number_to_canonical(l_old_ptp)
6935 ,p_old_val2 => NULL
6936 ,p_old_val3 => NULL
6937 ,p_old_val4 => NULL
6938 ,p_old_val5 => NULL
6939 ,p_old_val6 => NULL);
6940 hr_utility.set_location('GAA -- log row to track update of KFF Id . No chages to ptp ',10 );
6941
6942 END IF; -- If a correction is made to the KFF but ptp did not change
6943
6944 END IF; -- PTP is not equal
6945
6946 --
6947 -- There has been no change in the PTP but the KFF has changed
6948 -- update the surrogate keys to track the current KFF id in the
6949 -- change log rows.
6950 --
6951 IF p_prmtr_10 = 'UPDATE' THEN
6952 --
6953 -- Update any existing log rows based on the changes made
6954 -- also set the end date in case of an update
6955 --
6956 FOR upd_rec IN c_upd_log_kff_upd(c_asg_id => p_prmtr_01) LOOP
6957 IF trunc(fnd_date.canonical_to_date(upd_rec.prmtr_09)) =
6958 trunc(fnd_date.canonical_to_date(l_reporting_dt)) THEN
6959 UPDATE ben_ext_chg_evt_log
6960 SET prmtr_05 = fnd_date.date_to_canonical(TRUNC(p_chg_eff_dt)-1)
6961 ,prmtr_09 = l_reporting_dt
6962 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
6963 ELSE
6964 UPDATE ben_ext_chg_evt_log
6965 SET prmtr_05 = fnd_date.date_to_canonical(TRUNC(p_chg_eff_dt)-1)
6966 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
6967 END IF;
6968 END LOOP;
6969 hr_utility.set_location('GAA -- Updated the existing log to set the end as eff dt -1 ',10 );
6970
6971 ELSIF p_prmtr_10 = 'CORRECTION' THEN
6972 --
6973 -- Update any existing log rows based on the changes made
6974 --
6975 IF l_new_log_cre = 0 THEN
6976 FOR upd_rec IN c_upd_log_kff(c_asg_id => p_prmtr_01) LOOP
6977 IF trunc(fnd_date.canonical_to_date(upd_rec.prmtr_09)) =
6978 trunc(fnd_date.canonical_to_date(l_reporting_dt)) THEN
6979 UPDATE ben_ext_chg_evt_log
6980 SET prmtr_02 = p_new_val1
6981 ,prmtr_09 = l_reporting_dt
6982 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
6983 ELSE
6984 UPDATE ben_ext_chg_evt_log
6985 SET prmtr_02 = p_new_val1
6986 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
6987 END IF;
6988 END LOOP;
6989 ELSIF l_new_log_cre = 1 THEN
6990 FOR upd_rec IN c_upd_log_kff_upd(c_asg_id => p_prmtr_01) LOOP
6991 IF trunc(fnd_date.canonical_to_date(upd_rec.prmtr_09)) =
6992 trunc(fnd_date.canonical_to_date(l_reporting_dt)) THEN
6993 UPDATE ben_ext_chg_evt_log
6994 SET prmtr_05 = fnd_date.date_to_canonical(TRUNC(p_chg_eff_dt)-1)
6995 ,prmtr_09 = l_reporting_dt
6996 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
6997 ELSE
6998 UPDATE ben_ext_chg_evt_log
6999 SET prmtr_05 = fnd_date.date_to_canonical(TRUNC(p_chg_eff_dt)-1)
7000 WHERE ext_chg_evt_log_id = upd_rec.ext_chg_evt_log_id;
7001 END IF;
7002 END LOOP;
7003 END IF; -- check if new logs are created
7004
7005 hr_utility.set_location('GAA -- Updated the existing log to set the KFF id as the new KFF id ',10 );
7006 END IF; -- Check for update or correction
7007
7008 END IF; -- KFF Ids are not equal
7009
7010 ELSIF p_chg_evt_cd IN ('AAT','DAT','COLN','COSS','COUN'
7011 ,'COG','CODB','COM','CCFN'
7012 ,'CORC','COPR','APA','COCN','ASEA'
7013 ) THEN
7014
7015 --
7016 -- Get the reporting date
7017 --
7018 l_ret_val := get_reporting_date
7019 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(p_chg_eff_dt),'YYYY/MM')||'/01')
7020 ,p_person_id => p_person_id
7021 ,p_reporting_date => l_out_rep_dt );
7022
7023 l_reporting_dt := fnd_date.date_to_canonical(l_out_rep_dt);
7024
7025 hr_utility.set_location('... Reporting date is '||l_reporting_dt,10 );
7026 --
7027 -- Update the change event log row so that prmtr_09 is
7028 -- populated with the next reporting date.
7029 --
7030 l_upd_ovn := p_object_version_number;
7031
7032 ben_xcl_upd.upd
7033 (p_effective_date => TRUNC(p_effective_date)
7034 ,p_ext_chg_evt_log_id => p_ext_chg_evt_log_id
7035 ,p_chg_evt_cd => p_chg_evt_cd
7036 ,p_chg_eff_dt => p_chg_eff_dt
7037 ,p_chg_user_id => p_chg_user_id
7038 ,p_prmtr_01 => p_prmtr_01
7039 ,p_prmtr_02 => p_prmtr_02
7040 ,p_prmtr_03 => p_prmtr_03
7041 ,p_prmtr_04 => p_prmtr_04
7042 ,p_prmtr_05 => p_prmtr_05
7043 ,p_prmtr_06 => p_prmtr_06
7044 ,p_prmtr_07 => p_prmtr_07
7045 ,p_prmtr_08 => p_prmtr_08
7046 ,p_prmtr_09 => l_reporting_dt
7047 ,p_prmtr_10 => p_prmtr_10
7048 ,p_person_id => p_person_id
7049 ,p_business_group_id => p_business_group_id
7050 ,p_object_version_number => l_upd_ovn);
7051
7052 hr_utility.set_location('... -- Updated prmtr_09 to the reporting date',10 );
7053 ELSIF p_chg_evt_cd = ('COPOS') THEN
7054 --
7055 -- Get the reporting date
7056 --
7057 l_ret_val := get_reporting_date
7058 (p_effective_date => fnd_date.canonical_to_date(to_char(TRUNC(p_chg_eff_dt),'YYYY/MM')||'/01')
7059 ,p_person_id => p_person_id
7060 ,p_reporting_date => l_out_rep_dt );
7061
7062 IF TRUNC(l_out_rep_dt) < TRUNC(to_nl_date(p_old_val1,'DD-MM-RRRR')) THEN
7063 l_out_rep_dt := TRUNC(to_nl_date(p_old_val1,'DD-MM-RRRR'));
7064 END IF;
7065
7066 l_reporting_dt := fnd_date.date_to_canonical(l_out_rep_dt);
7067
7068 hr_utility.set_location('... Reporting date is '||l_reporting_dt,10 );
7069 --
7070 -- Update the change event log row so that prmtr_09 is
7071 -- populated with the next reporting date.
7072 --
7073 l_upd_ovn := p_object_version_number;
7074
7075 ben_xcl_upd.upd
7076 (p_effective_date => TRUNC(p_effective_date)
7077 ,p_ext_chg_evt_log_id => p_ext_chg_evt_log_id
7078 ,p_chg_evt_cd => p_chg_evt_cd
7079 ,p_chg_eff_dt => p_chg_eff_dt
7080 ,p_chg_user_id => p_chg_user_id
7081 ,p_prmtr_01 => p_prmtr_01
7082 ,p_prmtr_02 => p_prmtr_02
7083 ,p_prmtr_03 => p_prmtr_03
7084 ,p_prmtr_04 => p_prmtr_04
7085 ,p_prmtr_05 => p_prmtr_05
7086 ,p_prmtr_06 => p_prmtr_06
7087 ,p_prmtr_07 => p_prmtr_07
7088 ,p_prmtr_08 => p_prmtr_08
7089 ,p_prmtr_09 => l_reporting_dt
7090 ,p_prmtr_10 => p_prmtr_10
7091 ,p_person_id => p_person_id
7092 ,p_business_group_id => p_business_group_id
7093 ,p_object_version_number => l_upd_ovn);
7094
7095 hr_utility.set_location('... -- Updated prmtr_09 to the reporting date',10 );
7096
7097 ELSIF p_chg_evt_cd = 'COAPP' THEN
7098
7099 update per_assignment_extra_info
7100 set aei_information22 = NULL
7101 where assignment_extra_info_id = fnd_number.canonical_to_number(p_prmtr_03);
7102
7103 END IF; -- If the change event code is COSCKFF
7104
7105
7106 EXCEPTION
7107 WHEN OTHERS THEN
7108 RAISE;
7109
7110 END upd_chg_evt;
7111
7112 -- ----------------------------------------------------------------------------
7113 -- |-------------------------< abp_proration >-------------------------------|
7114 -- ----------------------------------------------------------------------------
7115 --
7116 function abp_proration
7117 (p_business_group_id in pqp_pension_types_f.business_group_id%TYPE
7118 ,p_date_earned in date
7119 ,p_assignment_id in per_all_assignments_f.assignment_id%TYPE
7120 ,p_amount in number
7121 ,p_payroll_period in varchar2
7122 ,p_work_pattern in varchar2
7123 ,p_conversion_rule in varchar2
7124 ,p_prorated_amount out nocopy number
7125 ,p_error_message out nocopy varchar2
7126 ,p_payroll_period_prorate in varchar2
7127 ,p_override_pension_days in NUMBER DEFAULT -9999
7128 ) return NUMBER IS
7129
7130 --
7131 -- Cursor to get the current ptp.
7132 -- this is also used to identify if an EE is a regular EE or
7133 -- a declerant (hourly EE)
7134 --
7135 CURSOR c_cur_ptp (c_eff_dt IN DATE
7136 ,c_asg_id IN NUMBER) IS
7137 SELECT LEAST(fnd_number.canonical_to_number(NVL(target.SEGMENT29,'100')),125) ptp
7138 FROM per_assignments_f asg
7139 ,hr_soft_coding_keyflex target
7140 WHERE target.soft_coding_keyflex_id = asg.soft_coding_keyflex_id
7141 AND asg.assignment_id = c_asg_id
7142 AND target.enabled_flag = 'Y'
7143 AND trunc(c_eff_dt) BETWEEN asg.effective_start_date AND
7144 asg.effective_end_date;
7145
7146 l_current_ptp NUMBER;
7147 l_ret_val NUMBER;
7148
7149 BEGIN
7150
7151 OPEN c_cur_ptp (p_date_earned,p_assignment_id);
7152 FETCH c_cur_ptp INTO l_current_ptp;
7153 CLOSE c_cur_ptp;
7154
7155 IF l_current_ptp = 0 THEN
7156 --
7157 -- Hourly EE do not do any proration.
7158 --
7159 p_prorated_amount := ROUND(p_amount/12,2);
7160 p_error_message := ' ';
7161 l_ret_val := 0;
7162 ELSE
7163 --
7164 -- Regular EE do normal proration.
7165 --
7166 l_ret_val := pqp_pension_functions.prorate_amount
7167 (p_business_group_id => p_business_group_id
7168 ,p_date_earned => p_date_earned
7169 ,p_assignment_id => p_assignment_id
7170 ,p_amount => p_amount
7171 ,p_payroll_period => p_payroll_period
7172 ,p_work_pattern => p_work_pattern
7173 ,p_conversion_rule => p_conversion_rule
7174 ,p_prorated_amount => p_prorated_amount
7175 ,p_error_message => p_error_message
7176 ,p_payroll_period_prorate => p_payroll_period_prorate
7177 ,p_override_pension_days => p_override_pension_days
7178 ) ;
7179
7180 END IF;
7181
7182 RETURN l_ret_val;
7183
7184 EXCEPTION
7185 WHEN OTHERS THEN
7186 p_prorated_amount := 0;
7187 RETURN 1;
7188
7189 END abp_proration;
7190 --
7191 -- ----------------------------------------------------------------------------
7192 -- |-------------------------< Get_Retro_Addnl_Amt >-------------------------|
7193 -- ----------------------------------------------------------------------------
7194 --
7195 -- Any retrospective change in basis over previous year, the
7196 -- contribution needs to be calculated using contribution
7197 -- percentage of the current period.
7198 -- Function calculates all this additional amount, that is
7199 -- paid along with current years premium amount.
7200 --
7201 FUNCTION Get_Retro_Addnl_Amt
7202 (p_bg_id IN NUMBER,
7203 p_date_earned IN DATE,
7204 p_asg_id IN NUMBER,
7205 p_element_type_id IN NUMBER,
7206 p_payroll_id IN NUMBER,
7207 p_contri_perc IN NUMBER,
7208 p_sick_flag IN VARCHAR2,
7209 p_dedn_retro_amt OUT NOCOPY NUMBER,
7210 p_ee_er_flag IN VARCHAR2
7211 ) RETURN NUMBER IS
7212
7213 -- Local Variables
7214 l_addn_ded_retro_amt NUMBER := 0;
7215 l_addn_ded_basis NUMBER := 0;
7216 l_sick_perc NUMBER := 0;
7217 l_contri_perc NUMBER := 0;
7218 l_iv_id_basis NUMBER := 0;
7219 l_iv_id_pv NUMBER := 0;
7220 l_error_msg VARCHAR2(250);
7221 l_ret_val NUMBER := 1;
7222 l_already_retro_paid NUMBER:= 0;
7223 l_sick_flag VARCHAR2(2) := 'Y';
7224 l_payroll_prd_name VARCHAR2(30);
7225 l_prorated_amount NUMBER := 0;
7226 l_ee_er_flag VARCHAR2(2);
7227 l_addn_ded_amt_temp NUMBER := 0;
7228 l_time_span_id NUMBER := 0;
7229 l_retro_basis_exists NUMBER := 0;
7230
7231 --
7232 -- Cursor to fetch the time span id for Correction
7233 -- over previous year.
7234 --
7235 CURSOR csr_time_span_id IS
7236 SELECT ts.time_span_id
7237 FROM pay_time_definitions s, pay_time_definitions e, pay_time_spans ts, pay_retro_components prc
7238 WHERE ts.creator_id = prc.retro_component_id
7239 AND prc.component_name ='Correction'
7240 AND prc.legislation_code = 'NL'
7241 AND ts.creator_type = 'RC'
7242 AND ts.start_time_def_id = s.time_definition_id
7243 AND ts.end_time_def_id = e.time_definition_id
7244 AND s.legislation_code = 'NL'
7245 AND s.definition_name = 'Start of Time'
7246 AND e.legislation_code = 'NL'
7247 AND e.definition_name = 'End of Previous Year';
7248
7249 --
7250 -- Cursor to fetch all retro elements' info based on element_type_id, date_earned
7251 -- This Cursor also gets already paid value in Retro for previous year
7252 --
7253 CURSOR csr_scr_ent_val(p_iv_id IN NUMBER,
7254 p_iv_id_pv IN NUMBER,
7255 p_time_span_id IN NUMBER)
7256 IS
7257 SELECT peev1.screen_entry_value basis,
7258 peev2.screen_entry_value paid,
7259 pay_paywsmee_pkg.get_original_date_earned(pee.element_entry_id) orig_date_earned
7260 FROM pay_element_entry_values_f peev1,
7261 pay_element_entry_values_f peev2,
7262 pay_element_entries_f pee,
7263 pay_retro_component_usages prcu,
7264 pay_retro_components prc,
7265 pay_element_span_usages pesu
7266 WHERE (prc.component_name ='Adjustment' OR (prc.component_name ='Correction'
7267 AND pesu.TIME_SPAN_ID = p_time_span_id) )
7268 AND pee.assignment_id = p_asg_id
7269 AND prc.legislation_code = 'NL'
7270 AND prcu.retro_component_id = prc.retro_component_id
7271 AND prcu.creator_id = p_element_type_id
7272 AND pesu.retro_component_usage_id = prcu.retro_component_usage_id
7273 AND pesu.retro_element_type_id = pee.element_type_id
7274 AND pee.element_entry_id = peev1.element_entry_id
7275 AND peev1.input_value_id = p_iv_id
7276 AND pee.element_entry_id = peev2.element_entry_id
7277 AND peev2.input_value_id = p_iv_id_pv
7278 AND p_date_earned BETWEEN pee.effective_start_date AND pee.effective_end_date
7279 AND p_date_earned BETWEEN peev1.effective_start_date AND peev1.effective_end_date
7280 AND TO_NUMBER(TO_CHAR(pay_paywsmee_pkg.get_original_date_earned(pee.element_entry_id),'YYYY'))
7281 < TO_NUMBER(TO_CHAR(p_date_earned,'YYYY'))
7282 AND p_date_earned BETWEEN peev2.effective_start_date AND peev2.effective_end_date;
7283
7284 --
7285 -- Cursor to fetch input value id for PAY VALUE
7286 --
7287 CURSOR csr_iv_pv_id(p_time_span_id IN number)
7288 IS
7289 SELECT piv.element_type_id ele_id, piv.input_value_id iv_id
7290 FROM pay_input_values_f piv,
7291 pay_retro_component_usages prcu,
7292 pay_retro_components prc,
7293 pay_element_span_usages pesu
7294 WHERE prc.legislation_code = 'NL'
7295 AND prcu.retro_component_id = prc.retro_component_id
7296 AND prcu.creator_id = p_element_type_id
7297 AND (prc.component_name ='Adjustment' OR (prc.component_name ='Correction'
7298 AND pesu.TIME_SPAN_ID = p_time_span_id) )
7299 AND pesu.retro_component_usage_id = prcu.retro_component_usage_id
7300 AND piv.name = 'Pay Value'
7301 AND piv.element_type_id = pesu.retro_element_type_id
7302 AND p_date_earned BETWEEN piv.effective_start_date AND piv.effective_end_date;
7303
7304 --
7305 -- Cursor to fetch input value id based on retro_element_type_id
7306 --
7307 CURSOR csr_iv_id(p_iv_name IN pay_input_values_f.name%TYPE
7308 ,p_retr_ele_type_id pay_element_types_f.element_type_id%TYPE)
7309 IS
7310 SELECT input_value_id
7311 FROM pay_input_values_f
7312 WHERE element_type_id = p_retr_ele_type_id
7313 AND name = p_iv_name
7314 AND p_date_earned BETWEEN effective_start_date AND effective_end_date;
7315 --
7316
7317 --Cursor To detect Whether do additional calculation with Old/New functionality.
7318 CURSOR csr_addl_calc
7319 IS
7320 SELECT NVL(aei_information3,'Y') aei_information3
7321 FROM per_assignment_extra_info
7322 WHERE information_type = 'NL_ADDL_CALC'
7323 AND assignment_id = p_asg_id
7324 --AND p_date_earned BETWEEN fnd_date.canonical_to_date(aei_information1) AND fnd_date.canonical_to_date(nvl(aei_information2,'4712/12/31'));
7325 AND p_date_earned BETWEEN trunc(to_date(substr(aei_information1,1,10),'YYYY/MM/DD'))
7326 AND trunc(to_date(substr(nvl(aei_information2,'4712/12/31'),1,10),'YYYY/MM/DD'));
7327
7328 l_addl_calc_flag per_assignment_extra_info.aei_information3%TYPE;
7329
7330 BEGIN
7331
7332 hr_utility.set_location ('Entering function: pqp_nl_abp_functions.Get_Retro_Addnl_Amt' , 2100);
7333 hr_utility.set_location ('p_bg_id: '||TO_CHAR(p_bg_id) , 2110);
7334 hr_utility.set_location ('p_date_earned : '||TO_CHAR(p_date_earned) , 2120);
7335 hr_utility.set_location ('p_asg_id: '||TO_CHAR(p_asg_id) , 2130);
7336 hr_utility.set_location ('p_element_type_id: '||TO_CHAR(p_element_type_id) , 2140);
7337 hr_utility.set_location ('p_payroll_id: '||TO_CHAR(p_payroll_id) , 2150);
7338 hr_utility.set_location ('p_contri_perc: '||TO_CHAR(p_contri_perc) , 2160);
7339 hr_utility.set_location ('p_sick_flag: '||TO_CHAR(p_sick_flag) , 2170);
7340 hr_utility.set_location ('p_ee_er_flag : '||TO_CHAR(p_ee_er_flag) , 2170);
7341
7342 -- Assign parameter values to local variables
7343 l_sick_flag := p_sick_flag;
7344 l_contri_perc := p_contri_perc;
7345 l_ee_er_flag := p_ee_er_flag;
7346
7347 hr_utility.set_location ('l_sick_flag: '||TO_CHAR(l_sick_flag) , 2180);
7348 hr_utility.set_location ('l_contri_perc: '||TO_CHAR(l_contri_perc) , 2190);
7349 hr_utility.set_location ('l_ee_er_flag : '||TO_CHAR(l_ee_er_flag) , 2200);
7350
7351 OPEN csr_addl_calc;
7352 FETCH csr_addl_calc INTO l_addl_calc_flag;
7353 CLOSE csr_addl_calc;
7354
7355 hr_utility.set_location ('l_addl_calc_flag : '|| NVL(l_addl_calc_flag,'Y') , 2202);
7356
7357 -- If user has entered "No" In Additional Amout Calc EIT then dont calc addl Amt.
7358 IF NVL(l_addl_calc_flag,'Y') = 'Y' THEN
7359
7360 hr_utility.set_location ('Inside EIT If Condition: ', 2205);
7361 -- Get the time span id for correction previous year
7362 -- Pass it as parameter to csr_scr_ent_val
7363 OPEN csr_time_span_id;
7364 FETCH csr_time_span_id INTO l_time_span_id;
7365 CLOSE csr_time_span_id;
7366
7367 hr_utility.set_location ('Time Span Id: ' || TO_CHAR(l_time_span_id), 2210);
7368
7369 -- At Run time decide whether the previous year entry is
7370 -- for Adjustment or Correction.
7371 -- Based on this, fetch the Input value Id for pay_value
7372 -- and subsequently fetch the input value ID
7373 -- for the basis in retro element.
7374 -- Pass that to the main cursor.
7375 FOR csr_iv IN csr_iv_pv_id(l_time_span_id)
7376 LOOP
7377 hr_utility.set_location ('csr_iv.ele_id: ' || TO_CHAR(csr_iv.ele_id), 2212);
7378 hr_utility.set_location ('csr_iv.iv_id: ' || TO_CHAR(csr_iv.iv_id), 2214);
7379 -- Delta in basis is obtained using entry value
7380 -- Names of input value differ for EE and ER.
7381 IF l_ee_er_flag = 'EE' THEN
7382 OPEN csr_iv_id('ABP Employee Pension Basis',csr_iv.ele_id);
7383 FETCH csr_iv_id INTO l_iv_id_basis;
7384 CLOSE csr_iv_id;
7385 hr_utility.set_location ('iv basis id EE: ' || TO_CHAR(l_iv_id_basis), 2220);
7386 ELSIF l_ee_er_flag = 'ER' THEN
7387 OPEN csr_iv_id('ABP Employer Pension Basis',csr_iv.ele_id);
7388 FETCH csr_iv_id INTO l_iv_id_basis;
7389 CLOSE csr_iv_id;
7390 hr_utility.set_location ('iv basis id ER:' || TO_CHAR(l_iv_id_basis), 2230);
7391 ELSE
7392 hr_utility.set_location ('Exiting pqp_nl_abp_functions.Get_Retro_addnl_Amt function', 2240);
7393 p_dedn_retro_amt := 0;
7394 RETURN 1; -- return failure, since parameter passed in not EE or ER*/
7395 END IF;
7396
7397 -- Run the loop for all previous year retro entries in the current year.
7398 -- Add up all additional amount that needs to be paid
7399 -- along with current period's premium
7400 FOR csr_basis IN csr_scr_ent_val(l_iv_id_basis,
7401 csr_iv.iv_id,
7402 l_time_span_id)
7403 LOOP
7404
7405 l_addn_ded_basis := nvl(fnd_number.canonical_to_number(csr_basis.basis),0);
7406 l_already_retro_paid := nvl(fnd_number.canonical_to_number(csr_basis.paid),0);
7407
7408 hr_utility.set_location ('l_addn_ded_basis: ' || l_addn_ded_basis, 2260);
7409 hr_utility.set_location ('l_already_retro_paid: ' || l_already_retro_paid, 2270);
7410
7411 /* code for checking the sickness flag as yes or no in the formula */
7412 IF p_sick_flag = 'Y' THEN
7413 hr_utility.set_location ('Sickness flag is Y', 2290);
7414 l_ret_val := pqp_nl_abp_functions.get_absence_adjustment
7415 (p_asg_id,
7416 csr_basis.orig_date_earned, --p_date_earned,
7417 p_bg_id,
7418 0,
7419 l_sick_perc,
7420 l_error_msg
7421 );
7422 hr_utility.set_location ('l_sick_perc: ' || TO_CHAR(l_sick_perc), 2300);
7423 hr_utility.set_location ('l_ret_val: '|| TO_CHAR(l_ret_val), 2310);
7424 IF l_ret_val = 0 THEN -- Success of previous function call
7425 -- Check if Formula is running for EE/ER, else return Zero.
7426 -- For EE, sickness amount is deducted from premium.
7427 -- For ER, sickness amount is added to premium.
7428 IF l_ee_er_flag = 'EE' THEN
7429 l_addn_ded_basis := l_addn_ded_basis - (l_addn_ded_basis * l_sick_perc/100);
7430 ELSIF l_ee_er_flag = 'ER' THEN
7431 l_addn_ded_basis := l_addn_ded_basis + (l_addn_ded_basis * l_sick_perc/100);
7432 END IF;
7433 --
7434 hr_utility.set_location ('l_addn_ded_basis: ' || TO_CHAR(l_addn_ded_basis), 2320);
7435
7436 l_addn_ded_retro_amt := l_addn_ded_retro_amt
7437 + (l_addn_ded_basis * p_contri_perc/100)
7438 - l_already_retro_paid;
7439
7440 hr_utility.set_location ('l_addn_ded_retro_amt: ' || TO_CHAR(l_addn_ded_retro_amt), 2330);
7441 ELSE -- l_ret_val = 1, previous function call failed
7442 l_addn_ded_retro_amt := 0;
7443 hr_utility.set_location ('l_addn_ded_retro_amt ' || TO_CHAR(l_addn_ded_retro_amt), 2340);
7444 END IF;
7445
7446 ELSE -- no Sickness is attached
7447 hr_utility.set_location ('Sickness flag is N', 2350);
7448 l_addn_ded_retro_amt := l_addn_ded_retro_amt
7449 + (l_addn_ded_basis * p_contri_perc/100)
7450 - l_already_retro_paid ;
7451 hr_utility.set_location ('l_addn_ded_retro_amt ' || TO_CHAR(l_addn_ded_retro_amt), 2360);
7452 END IF; -- Sickness attached or not.
7453
7454 END LOOP; -- iv cursor
7455
7456 END LOOP; -- Cursor csr_scr_ent_val closed
7457
7458 --Get the Final Additional amount
7459
7460 p_dedn_retro_amt := ROUND(NVL(l_addn_ded_retro_amt,0),2); -- final_amt
7461
7462 ELSE
7463
7464 hr_utility.set_location ('Inside EIT Else Condition: ', 2365);
7465 p_dedn_retro_amt := 0;
7466
7467 END IF;
7468
7469 hr_utility.set_location ('p_dedn_retro_amt: ' || TO_CHAR(p_dedn_retro_amt), 2370);
7470 hr_utility.set_location ('Returning from pqp_nl_abp_functions.Get_Retro_addnl_Amt function', 2375);
7471
7472 RETURN 0; -- success
7473
7474 EXCEPTION
7475 WHEN OTHERS THEN
7476 hr_utility.set_location ('Exception occured in pqp_nl_abp_functions.get_retro_addnl_amt', 2380);
7477 p_dedn_retro_amt := 0;
7478 RETURN 1; -- fail
7479
7480 --hr_utility.trace_off;
7481 END Get_Retro_Addnl_Amt;
7482 --
7483 END pqp_nl_abp_functions;