1 PACKAGE BODY PAY_NO_ABSENCE AS
2 /* $Header: pynoabsence.pkb 120.1 2007/07/10 05:38:01 pdavidra noship $ */
3 Function CALCULATE_PAYMENT
4 ( p_assignment_id IN NUMBER
5 ,p_effective_date IN DATE
6 -- ,p_absence_category IN VARCHAR2
7 ,p_abs_categorycode IN VARCHAR
8 ,p_abs_start_date IN DATE
9 ,p_abs_end_date IN DATE
10 ,p_prorate_start IN DATE
11 ,p_prorate_end IN DATE
12 ,p_abs_attendance_id IN NUMBER
13 -- Balance Variables
14 ,p_sickabs_paybase IN NUMBER
15 ,p_sickabs_totaldays IN NUMBER
16 -- Sickness Benefit variables
17 ,p_abs_empr_days OUT NOCOPY NUMBER
18 ,p_abs_ss_days OUT NOCOPY NUMBER
19 ,p_abs_total_days OUT NOCOPY NUMBER
20 ,p_abs_daily_rate OUT NOCOPY NUMBER
21 ,p_abs_sick_days OUT NOCOPY NUMBER
22 -- Earnings adjustment values
23 ,p_ear_value OUT NOCOPY NUMBER
24 ,p_ear_startdt OUT NOCOPY DATE
25 ,p_ear_enddt OUT NOCOPY DATE
26 -- Global values
27 ,p_abs_link_period IN NUMBER
28 ,p_abs_min_gap IN NUMBER
29 ,p_abs_month IN NUMBER
30 ,p_abs_annual_days IN NUMBER
31 ,p_abs_work_days IN NUMBER
32 ,p_abs_cal_days IN NUMBER
33 -- pay earned start and end date
34 ,p_pay_start_date IN DATE
35 ,p_pay_end_date IN DATE
36 -- To determine actual payroll period. Mainly for proration calculation.
37 ,p_hourly_paid IN Varchar2
38 -- Balance Variables
39 ,p_4weeks_paybase IN NUMBER
40 ,p_3years_paybase IN NUMBER
41 -- Reclaimable benefit output variables
42 ,p_rec_empr_days OUT NOCOPY NUMBER
43 ,p_rec_ss_days OUT NOCOPY NUMBER
44 ,p_rec_total_days OUT NOCOPY NUMBER
45 ,p_rec_daily_rate OUT NOCOPY NUMBER
46 ,p_ss_daily_rate OUT NOCOPY NUMBER
47 -- User defined daily rate calculation logic option
48 ,p_rate_option1 OUT NOCOPY VARCHAR
49 ,p_rate_option2 OUT NOCOPY VARCHAR
50 ,p_rate_option3 OUT NOCOPY VARCHAR
51 ,p_rate_option4 OUT NOCOPY VARCHAR
52 ,p_rate_option5 OUT NOCOPY VARCHAR
53 ,p_rate_option6 OUT NOCOPY VARCHAR
54 ,p_rate_option7 OUT NOCOPY VARCHAR
55 ,p_rate_option8 OUT NOCOPY VARCHAR
56 ,p_rate_option9 OUT NOCOPY VARCHAR
57 ,p_rate_option10 OUT NOCOPY VARCHAR
58 -- ,p_abs_categorycode OUT NOCOPY VARCHAR
59 ,p_abs_error OUT NOCOPY VARCHAR
60 ,p_adopt_bal_days IN NUMBER
61 ,p_parental_bal_days IN NUMBER
62 ,p_abs_child_emp_days_limit IN NUMBER
63 ,p_child_emp_days IN NUMBER
64 ,p_child_ss_days IN NUMBER
65 ,p_pts_percentage OUT NOCOPY NUMBER
66 ,p_abs_total_cal_days OUT NOCOPY NUMBER
67 ,p_sickbal_total_caldays IN NUMBER
68 ,p_abs_ear_adj_base IN NUMBER
69 ) RETURN NUMBER IS
70
71 -- Cursor to fetch previous absences exists with sickness and part-time sickness for calculating
72 -- Continuous linking period. It will not consider overlapping sickness. It will pick absences
73 -- that are started and ended before the start date of the current absence.
74 CURSOR CSR_CONT_LINK (l_person_id number) IS
75 SELECT paa.absence_attendance_id
76 ,paa.date_start
77 ,paa.date_end,
78 DECODE(paa.date_start, paa.date_end, 1, (paa.date_end-paa.date_start)+1) AS days_diff
79 FROM per_absence_attendances paa, per_absence_attendance_types pat
80 WHERE paa.person_id = l_person_id
81 AND paa.date_start < p_abs_start_date
82 AND paa.date_end < p_abs_start_date
83 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
84 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
85 AND pat.absence_category IN ('S','PTS')
86 ORDER BY paa.date_end desc ;
87
88 CURSOR CSR_ELE_ENT_VAL_FETCH (l_asg_id number, l_eff_dt date, l_inp_val_name varchar2, l_start_dt date, l_end_dt date) IS
89 SELECT eev1.screen_entry_value screen_entry_value
90 FROM per_all_assignments_f asg1
91 ,per_all_assignments_f asg2
92 ,per_all_people_f per
93 ,pay_element_links_f el
94 ,pay_element_types_f et
95 ,pay_input_values_f iv1
96 ,pay_element_entries_f ee
97 ,pay_element_entry_values_f eev1
98 WHERE asg1.assignment_id = l_asg_id
99 AND l_eff_dt BETWEEN asg1.effective_start_date AND asg1.effective_end_date
100 AND l_eff_dt BETWEEN asg2.effective_start_date AND asg2.effective_end_date
101 AND per.person_id = asg1.person_id
102 AND asg2.person_id = per.person_id
103 AND asg2.primary_flag = 'Y'
104 AND et.element_name = 'Absence Detail'
105 AND et.legislation_code = 'NO'
106 AND iv1.element_type_id = et.element_type_id
107 AND iv1.name = l_inp_val_name
108 AND el.business_group_id = per.business_group_id
109 AND el.element_type_id = et.element_type_id
110 AND ee.assignment_id = asg2.assignment_id
111 AND ee.element_link_id = el.element_link_id
112 AND eev1.element_entry_id = ee.element_entry_id
113 AND eev1.input_value_id = iv1.input_value_id
114 AND ee.effective_start_date = l_start_dt
115 AND ee.effective_end_date = l_end_dt
116 AND eev1.effective_start_date = l_start_dt
117 AND eev1.effective_end_date = l_end_dt ;
118
119 CURSOR CSR_RUN_RESULT_FETCH (p_input_name varchar2, stdate date, enddate date) IS
120 SELECT result_value
121 FROM pay_element_types_f pet
122 , pay_element_entries_f pee
123 , pay_run_results prr
124 , pay_run_result_values prrv
125 , pay_input_values_f piv
126 WHERE pet.element_type_id = pee.element_type_id
127 AND pet.element_type_id = prr.element_type_id
128 AND pee.element_entry_id = prr.element_entry_id
129 AND prr.run_result_id = prrv.run_result_id
130 AND pet.element_type_id = piv.element_type_id
131 AND piv.input_value_id = prrv.input_value_id
132 AND pet.element_name LIKE 'Absence Detail'
133 AND piv.NAME = p_input_name
134 AND pee.effective_start_date = stdate
135 AND pee.effective_end_date = enddate ;
136
137 CURSOR CSR_CUR_ABS_PRORATED (P_ASSIGNMENT_ID NUMBER, P_EFFECTIVE_DATE DATE, P_ST_DT DATE, P_EN_DT DATE) IS
138 SELECT DATE_EARNED
139 FROM PER_ALL_ASSIGNMENTS_F PAA
140 ,PAY_PAYROLL_ACTIONS PPA
141 ,PAY_ASSIGNMENT_ACTIONS PASG
142 WHERE PAA.PAYROLL_ID = PPA.PAYROLL_ID
143 AND PAA.ASSIGNMENT_ID = P_ASSIGNMENT_ID
144 AND PAA.ASSIGNMENT_ID = PASG.ASSIGNMENT_ID
145 AND PPA.PAYROLL_ACTION_ID = PASG.PAYROLL_ACTION_ID
146 AND PASG.SOURCE_ACTION_ID IS NOT NULL
147 AND P_EFFECTIVE_DATE BETWEEN PAA.EFFECTIVE_START_DATE
148 AND PAA.EFFECTIVE_END_DATE
149 AND DATE_EARNED BETWEEN P_ST_DT AND P_EN_DT
150 GROUP BY DATE_EARNED
151 ORDER BY DATE_EARNED ASC;
152
153 CURSOR child_prev_emp (personid NUMBER, stdate DATE) IS
154 SELECT START_DATE
155 ,END_DATE
156 ,fnd_number.canonical_to_number(PEM_INFORMATION1) AS PEM_INFORMATION1
157 FROM PER_PREVIOUS_EMPLOYERS
158 WHERE person_id = personid
159 AND end_date BETWEEN TO_DATE('01/01/'|| TO_CHAR(stdate,'yyyy'), 'mm/dd/yyyy' )
160 AND stdate
161 ORDER BY end_date DESC;
162
163 CURSOR child_contact ( personid NUMBER, contacttype VARCHAR2, abs_stdt DATE) IS
164 SELECT pap.date_of_birth
165 ,ROUND(MONTHS_BETWEEN( abs_stdt, pap.date_of_birth ) / 12, 2) AS AGE
166 ,pcr.contact_type
167 ,pcr.cont_information1
168 ,pcr.cont_information2
169 FROM per_all_people_f pap
170 ,per_contact_relationships pcr
171 WHERE pap.person_id = pcr.contact_person_id
172 AND pcr.person_id = personid
173 AND pcr.contact_type = contacttype
174 AND (pcr.date_start is null or pcr.date_start <= abs_stdt)
175 AND (pcr.date_end is null or pcr.date_end >= abs_stdt ); /* 5413738 */
176
177 -- Cursor to fetch previous absences exists with child minder sickness category for calculating
178 -- employer and social security days. It will not consider overlapping sickness. It will pick absences
179 -- that are started and ended before the start date of the current absence.
180 CURSOR child_link (l_person_id number) IS
181 SELECT paa.absence_attendance_id
182 ,paa.date_start
183 ,paa.date_end,
184 DECODE(paa.date_start, paa.date_end, 1, (paa.date_end-paa.date_start)+1) AS days_diff
185 FROM per_absence_attendances paa, per_absence_attendance_types pat
186 WHERE paa.person_id = l_person_id
187 AND paa.date_start < p_abs_start_date
188 AND paa.date_end < p_abs_start_date
189 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
190 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
191 AND pat.absence_category IN ('CMS')
192 ORDER BY paa.date_end desc ;
193
194 /*Pgopal - Bug 5393827 and 5349713 fix*/
195 CURSOR csr_get_intial_abs_st_date( p_intial_abs_attend_id IN NUMBER ) IS
196 SELECT
197 paa.date_start
198 FROM
199 PER_ABSENCE_ATTENDANCES paa
200 WHERE
201 PAA.ABSENCE_ATTENDANCE_ID = p_intial_abs_attend_id;
202
203 /* Cursor to get the initial absence start date for sickness */
204 CURSOR csr_get_intial_sick_abs_st_dt(p_abs_attn_id IN VARCHAR2 ) IS
205 SELECT nvl(peef2.effective_start_date,peef1.effective_start_date)
206 FROM pay_element_entry_values_f peevf
207 ,pay_input_values_f pivf
208 ,pay_element_entries_f peef1
209 ,pay_element_entries_f peef2
210 WHERE peevf.screen_entry_value = p_abs_attn_id
211 AND pivf.input_value_id = peevf.input_value_id
212 AND pivf.NAME = 'CREATOR_ID'
213 AND pivf.legislation_code = 'NO'
214 AND peef1.element_entry_id = peevf.element_entry_id
215 AND peef2.element_entry_id(+) = peef1.original_entry_id;
216
217 /* Cursor to get the initial absence payroll start date */
218 CURSOR csr_intial_abs_pay_stdt (p_assignment_id in number, p_initial_abs_start_date in date) is
219 SELECT ptp.start_date
220 FROM per_all_assignmeNts_f paaf, PER_TIME_PERIODS ptp
221 WHERE paaf.assignment_id = p_assignment_id
222 AND ptp.payroll_id = paaf.payroll_id
223 AND p_initial_abs_start_date between ptp.start_date and ptp.end_date;
224
225 p_adopt_days Number := 0;
226 p_adopt_rate Number := 0;
227 p_adopt_comprate Number := 0;
228
229 l_abs_category_code Varchar2(50);
230 p_person_id Number;
231 p_business_group_id Number;
232 l_rate Number;
233 l_error_message Varchar2(1000);
234 l_return Number;
235 l_social_security_rate Number;
236 l_g_rate Number;
237 l_empr_daily_rate Number;
238 l_ben_payvalue Number;
239 l_benreclaim_payvalue Number;
240 l_asg_hour_sal Varchar2(10);
241 l_abs_worked_days Number;
242 p_dbi_26week_stdt Date;
243 p_dbi_26week_endt Date;
244 l_social_security_days Number;
245 p_work_pattern Varchar2(100);
246
247 -- To keep the net value after checking the null value with 3 priority levels absence, person and legal employer
248 l_gen_hour_sal Varchar2(10);
249 l_gen_entitled_sc Varchar2(10);
250 l_gen_exempt_empr Varchar2(10);
251 l_gen_reimb_ss Varchar2(10);
252 l_gen_restrict_dr_ss Varchar2(10);
253 l_gen_restrict_empr_sl Varchar2(10);
254 l_gen_restrict_ss_sl Varchar2(10);
255
256 l_gen_totalabs_days Number;
257 l_gen_pro_days Number;
258 l_gen_empr_days Number;
259 l_gen_ss_days Number;
260 l_gen_empr_st_date Date;
261 l_gen_ss_st_date Date;
262 l_gen_rate_option Varchar2(10);
263
264 -- Validating Override element
265 l_override_start_date Date;
266 l_override_end_date Date;
267 l_override_empr_days Number;
268 l_override_ss_days Number;
269 l_override_empr_rate Number;
270 l_override_ss_rate Number;
271 l_override_reclaim_rate Number;
272 l_over_return Number;
273 l_msg_error varchar2(500) := '';
274 -- Calculation of Absence Days based on Work schedule
275 l_days_or_hours Varchar2(10) := 'D';
276 l_include_event Varchar2(10) := 'Y';
277 l_start_time_char Varchar2(10) := '0';
278 l_end_time_char Varchar2(10) := '23.59';
279 l_duration Number;
280 l_wrk_schd_return Number;
281
282 -- Person form absence payment details
283 l_hourly_salaried Varchar2(10);
284 l_entitled_sc Varchar2(10);
285 l_exempt_empr Varchar2(10);
286 l_reimb_ss Varchar2(10);
287 l_restrict_dr_ss Varchar2(10);
288 l_restrict_empr_sl Varchar2(10);
289 l_restrict_ss_sl Varchar2(10);
290 l_dateofjoin Date;
291 l_per_daily_rate Varchar2(10);
292
293 -- Absence form absence payment details
294 l_cert_type Varchar2(10);
295 l_cert_stdt Date;
296 l_cert_endt Date;
297 l_follow_due Date;
298 l_follow_created Date;
299 l_follow_sent Date;
300 l_abs_reimb_ss Varchar2(10);
301 l_abs_restrict_dr_ss Varchar2(10);
302 l_abs_restrict_empr_sl Varchar2(10);
303 l_abs_restrict_ss_sl Varchar2(10);
304 l_abs_pts_percent Number;
305 l_abs_daily_rate Varchar2(10);
306 -- Legal employer EIT absence details
307 l_le_reimb_ss Varchar2(10);
308 l_le_restrict_dr_ss Varchar2(10);
309 l_le_restrict_empr_sl Varchar2(10);
310 l_le_restrict_ss_sl Varchar2(10);
311 l_le_hour_sal Varchar2(10);
312 l_le_entitled_sc Varchar2(10);
313 l_le_exempt_empr Varchar2(10);
314 l_le_daily_rate Varchar2(10);
315
316 -- Sickness payment variables
317 l_abs_unauthor Number;
318 l_dateofjoin_28 Date;
319 l_abs_reason Varchar2(100);
320 l_abs_count Number(5);
321 l_actual_days Number;
322 l_loop_start_date Date;
323 l_loop_empr_days Number;
324 l_loop_empr_work_days Number;
325 l_actual_cal_days Number;
326 l_reimb_ss_val Varchar2(100);
327 -- Payment Result variables
328 l_empr_days Number;
329 l_ss_days Number;
330 l_total_days Number;
331 l_daily_rate Number;
332
333 l_reclaim_empr_days Number;
334 l_reclaim_ss_days Number;
335 l_reclaim_total_days Number;
336 l_reclaim_daily_rate Number;
337
338 -- Override check for continuous link period
339 l_cont_start_date Date;
340 l_cont_end_date Date;
341 l_cont_empr_rate Number;
342 l_cont_ss_rate Number;
343 l_cont_reclaim_rate Number;
344 l_cont_empr_days Number;
345 l_cont_ss_days Number;
346
347 l_counter Number;
348 l_prev_paydate Date;
349
350 -- Adoption variables
351 l_adopt_days Number;
352 l_eligibility Boolean;
353 l_adopt_doa Date;
354 l_adopt_dob Date;
355 l_adopt_comprate Number;
356 l_dummy Varchar2(100);
357 l_adopt_sum Number;
358 l_adopt_glb_80 Number;
359 l_adopt_glb_100 Number;
360
361 /* Bug Fix 5380091 : Start */
362
363 l_no_of_children NUMBER ;
364 l_gen_no_of_children NUMBER ;
365
366 /* Bug Fix 5380091 : End */
367
368
369 /* Bug Fix 5346832 : Start */
370
371 l_adopt_glb_80_add_child Number;
372 l_adopt_glb_100_add_child Number;
373
374 /* Bug Fix 5346832 : End */
375
376 -- Part Time Adoption variables
377 l_adopt_ptp Number;
378 l_adopt_reimb_ss Varchar2(10);
379 l_adopt_restrict_dr_ss Varchar2(10);
380 l_adopt_restrict_empr_sl Varchar2(10);
381 l_adopt_daily_rate Varchar2(40);
382
383 -- Child minder variables
384 l_child_1_13 Number;
385 l_child_2_13 Number;
386 l_child_1_19 Number;
387 l_childsg_1_13 Number;
388 l_childsg_2_13 Number;
389 l_childsg_1_19 Number;
390 l_child_prev_stdt Date;
391 l_child_prev_endt Date;
392 l_child_prev_value Number;
393 l_gen_child_limit Number;
394 l_child_cnt_ab Number;
395 l_child_cnt_c Number;
396 l_child_cnt_sgab Number;
397 l_child_cnt_sgc Number;
398
399 --Parental benefits
400 l_max_parental_days_100 number;
401 l_max_parental_days_80 number;
402 l_parental_days_add_child number;
403 l_parental_days_remaining number;
404
405 -- Maternity variables
406 l_m_expected_dob date;
407 l_m_dob date;
408 l_m_no_of_babies_born number;
409 l_m_compensation_rate number;
410 l_m_spouse varchar2(10);
411 l_m_paternity_days number;
412 l_m_pt_paternity_days number;
413 l_m_reimurse_from_ss varchar2(10);
414 l_m_use_ss_daily_rate varchar2(10);
415 l_m_reclaimable_pay_max_6g varchar2(10);
416 l_m_hol_acc_ent varchar2(10);
417 l_m_daily_rate_calc varchar2(10);
418 l_m_date_stillborn date;
419 l_maternity_sum number;
420 l_maternity_days number;
421 p_parental_days Number := 0;
422 p_parental_rate Number := 0;
423 p_parental_comprate Number := 0;
424
425 -- Part Time Maternity variables
426 l_ptm_expected_dob date;
427 l_ptm_dob date;
428 l_ptm_percentage number;
429 l_ptm_compensation_rate number;
430 l_ptm_paternity_days number;
431 l_ptm_pt_paternity_days number;
432 l_ptm_no_of_babies_born number;
433 l_ptm_use_ss_daily_rate varchar2(10);
434 l_ptm_daily_rate_calc varchar2(10);
435 l_ptm_hol_acc_ent varchar2(20);
436 l_pt_maternity_sum number;
437 l_pt_maternity_days number;
438 l_ptm_reimburse_from_ss varchar2(10);
439 l_ptm_reclaim_pay_max_6g varchar2(10);
440
441 -- Paternity variables
442 l_p_expected_dob date;
443 l_p_dob date;
444 l_p_maternity_days number;
445 l_p_pt_maternity_days number;
446 l_p_no_of_babies_born number;
447 l_p_compensation_rate number;
448 l_p_paternity_days number;
449 l_p_pt_paternity_days number;
450 l_p_use_ss_daily_rate varchar2(10);
451 l_p_daily_rate_calc varchar2(10);
452 l_p_date_stillborn date;
453 l_paternity_sum number;
454 l_paternity_days number;
455 l_p_reimburse_from_ss varchar2(10);
456
457 l_p_reclaimable_pay_max_6g varchar2(10);
458 l_p_hol_acc_ent varchar2(10);
459
460 -- Part Time Paternity variables
461 l_ptp_expected_dob date;
462 l_ptp_dob date;
463 l_ptp_percentage number;
464 l_ptp_paternity_percent number;
465 l_ptp_compensation_rate number;
466 l_ptp_pt_paternity_days number;
467 l_ptp_no_of_babies_born number;
468 l_ptp_use_ss_daily_rate varchar2(10);
469 l_ptp_daily_rate_calc varchar2(10);
470 l_ptp_hol_acc_ent varchar2(20);
471 l_ptp_maternity_sum number;
472 l_ptp_maternity_days number;
473 l_ptp_percent number;
474 l_ptp_days_spouse_mat_leave number;
475 l_ptp_mat_compensation_rate number;
476 l_ptp_days_pt_maternity number;
477 l_ptp_reimburse_from_ss varchar2(10);
478 l_ptp_reclaimable_pay_max_6g varchar2(10);
479 l_pt_paternity_sum number;
480 l_pt_paternity_days number;
481 curr_year_cms_emp_days number;
482 curr_year_cms_ss_days number;
483 l_emp_end_date date;
484
485 /*Pgopal - Bug 5393827 and 5349713 fix*/
486 l_initial_absence CHAR ;
487 l_initial_abs_attend_id NUMBER ;
488 l_initial_abs_st_date DATE ;
489 l_initial_abs_pay_stdt DATE ;
490
491 BEGIN
492 hr_utility.set_location('Entering into absence package: ', 1);
493 p_abs_sick_days := 0;
494 -- To select absence category code by passing absence category meaning.
495 /* pgopal - passing the abs category code directly by attaching a value set to the element i/p value*/
496 /* BEGIN
497 SELECT LOOKUP_CODE
498 INTO l_abs_category_code
499 FROM HR_LOOKUPS /* Bug fix 5263714 used hr_lookups instead of fnd_lookup_values
500 FROM FND_LOOKUP_VALUES
501 WHERE LOOKUP_TYPE = 'ABSENCE_CATEGORY'
502 AND ENABLED_FLAG = 'Y'
503 AND MEANING = p_absence_category;
504 EXCEPTION
505 WHEN others THEN
506 l_abs_category_code := null;
507 END;*/
508 l_abs_category_code := p_abs_categorycode;
509 -- p_abs_categorycode := l_abs_category_code;
510 -- Selecting person id, business group id through assignment id
511 BEGIN
512 SELECT PERSON_ID
513 ,BUSINESS_GROUP_ID
514 ,HOURLY_SALARIED_CODE
515 INTO p_person_id
516 ,p_business_group_id
517 ,l_asg_hour_sal
518 FROM PER_ALL_ASSIGNMENTS_F ASG
519 WHERE ASG.ASSIGNMENT_ID = p_assignment_id
520 AND p_effective_date BETWEEN ASG.EFFECTIVE_START_DATE
521 AND ASG.EFFECTIVE_END_DATE;
522 EXCEPTION
523 WHEN OTHERS THEN
524 p_person_id := null;
525 p_business_group_id := null;
526 l_asg_hour_sal := null;
527 END;
528
529 -- To get legal employer level EIT details
530 BEGIN
531 SELECT hoi4.ORG_INFORMATION1
532 ,hoi4.ORG_INFORMATION2
533 ,hoi4.ORG_INFORMATION3
534 ,hoi4.ORG_INFORMATION4
535 ,hoi4.ORG_INFORMATION5
536 ,hoi4.ORG_INFORMATION6
537 ,hoi4.ORG_INFORMATION7
538 ,hoi4.ORG_INFORMATION8
539 INTO l_le_reimb_ss
540 ,l_le_restrict_dr_ss
541 ,l_le_restrict_empr_sl
542 ,l_le_restrict_ss_sl
543 ,l_le_hour_sal
544 ,l_le_entitled_sc
545 ,l_le_exempt_empr
546 ,l_le_daily_rate
547 FROM HR_ORGANIZATION_UNITS o1
548 ,HR_ORGANIZATION_INFORMATION hoi1
549 ,HR_ORGANIZATION_INFORMATION hoi2
550 ,HR_ORGANIZATION_INFORMATION hoi3
551 ,HR_ORGANIZATION_INFORMATION hoi4
552 ,( SELECT TRIM(SCL.SEGMENT2) AS ORG_ID
553 FROM PER_ALL_ASSIGNMENTS_F ASG
554 ,HR_SOFT_CODING_KEYFLEX SCL
555 WHERE ASG.ASSIGNMENT_ID = p_assignment_id
556 AND ASG.SOFT_CODING_KEYFLEX_ID = SCL.SOFT_CODING_KEYFLEX_ID
557 AND P_EFFECTIVE_DATE BETWEEN ASG.EFFECTIVE_START_DATE AND ASG.EFFECTIVE_END_DATE ) X
558 WHERE o1.business_group_id = p_business_group_id
559 AND hoi1.organization_id = o1.organization_id
560 AND hoi1.organization_id = X.ORG_ID
561 AND hoi1.org_information1 = 'NO_LOCAL_UNIT'
562 AND hoi1.org_information_context = 'CLASS'
563 AND o1.organization_id = hoi2.org_information1
564 AND hoi2.ORG_INFORMATION_CONTEXT='NO_LOCAL_UNITS'
565 AND hoi2.organization_id = hoi3.organization_id
566 AND hoi3.ORG_INFORMATION_CONTEXT='CLASS'
567 AND hoi3.org_information1 = 'HR_LEGAL_EMPLOYER'
568 AND hoi3.organization_id = hoi4.organization_id
569 AND hoi4.ORG_INFORMATION_CONTEXT='NO_ABSENCE_PAYMENT_DETAILS';
570 EXCEPTION
571 WHEN OTHERS THEN
572 l_le_reimb_ss := NULL;
573 l_le_restrict_dr_ss := NULL;
574 l_le_restrict_empr_sl := NULL;
575 l_le_restrict_ss_sl := NULL;
576 l_le_hour_sal := NULL;
577 l_le_entitled_sc := NULL;
578 l_le_exempt_empr := NULL;
579 l_le_daily_rate := NULL;
580 END;
581 -- To get absence payment details under person form.
582 BEGIN
583 SELECT PER_INFORMATION6 AS HOURLY_SALARIED
584 ,PER_INFORMATION7 AS ENTITLE_SC
585 ,PER_INFORMATION8 AS EXEMPT_EMPR
586 ,PER_INFORMATION9 AS REIMB_SS
587 ,PER_INFORMATION10 AS RESTRICT_DR_SS
588 ,PER_INFORMATION11 AS RESTRICT_EMPR_SL
589 ,PER_INFORMATION12 AS RESTRICT_SS_SL
590 ,PER_INFORMATION14 AS DAILY_RATE /* knelli changed from PER_INFORMATION13*/
591 ,START_DATE AS DATEOFJOIN
592 INTO l_hourly_salaried
593 ,l_entitled_sc
594 ,l_exempt_empr
595 ,l_reimb_ss
596 ,l_restrict_dr_ss
597 ,l_restrict_empr_sl
598 ,l_restrict_ss_sl
599 ,l_per_daily_rate
600 ,l_dateofjoin
601 FROM PER_ALL_PEOPLE_F PER
602 WHERE PER.PERSON_ID = p_person_id
603 AND P_EFFECTIVE_DATE BETWEEN PER.EFFECTIVE_START_DATE
604 AND PER.EFFECTIVE_END_DATE;
605 EXCEPTION
606 WHEN others THEN
607 l_hourly_salaried := NULL;
608 l_entitled_sc := NULL;
609 l_exempt_empr := NULL;
610 l_reimb_ss := NULL;
611 l_restrict_dr_ss := NULL;
612 l_restrict_empr_sl := NULL;
613 l_restrict_ss_sl := NULL;
614 l_dateofjoin := NULL;
615 l_per_daily_rate := NULL;
616 END;
617
618 /***************************************************************************
619 SICKNESS - PART TIME SICKNESS ABSENCE CATEGORY
620 ****************************************************************************/
621
622 IF l_abs_category_code in ( 'S', 'PTS' ) THEN
623 IF l_abs_category_code = 'S' THEN
624 -- Fetch EIT values from absence payment details form
625 BEGIN
626 SELECT PAA.ABS_INFORMATION1 AS Cert_type
627 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Cert_stdt
628 ,to_date(PAA.ABS_INFORMATION3,'yyyy/mm/dd hh24:mi:ss') AS Cert_endt
629 ,to_date(PAA.ABS_INFORMATION4,'yyyy/mm/dd hh24:mi:ss') AS Follow_due
630 ,to_date(PAA.ABS_INFORMATION5,'yyyy/mm/dd hh24:mi:ss') AS Follow_created
631 ,PAA.ABS_INFORMATION6 AS reimb_ss
632 ,PAA.ABS_INFORMATION7 AS dailyrate_ss
633 ,PAA.ABS_INFORMATION8 AS employer_6g
634 ,PAA.ABS_INFORMATION9 AS socialsec_6g
635 ,to_date(PAA.ABS_INFORMATION10,'yyyy/mm/dd hh24:mi:ss') AS Follow_sent
636 ,PAA.ABS_INFORMATION11 AS Daily_rate
637 INTO l_cert_type
638 ,l_cert_stdt
639 ,l_cert_endt
640 ,l_follow_due
641 ,l_follow_created
642 ,l_abs_reimb_ss
643 ,l_abs_restrict_dr_ss
644 ,l_abs_restrict_empr_sl
645 ,l_abs_restrict_ss_sl
646 ,l_follow_sent
647 ,l_abs_daily_rate
648 FROM PER_ABSENCE_ATTENDANCES PAA
649 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
650 EXCEPTION
651 WHEN OTHERS THEN
652 l_cert_type := null;
653 l_cert_stdt := null;
654 l_cert_endt := null;
655 l_follow_due := null;
656 l_follow_created := null;
657 l_abs_reimb_ss := null;
658 l_abs_restrict_dr_ss := null;
659 l_abs_restrict_empr_sl := null;
660 l_abs_restrict_ss_sl := null;
661 l_follow_sent := null;
662 l_abs_daily_rate := null;
663 END;
664
665 ELSE
666 -- Fetch EIT values from absence payment details form
667 BEGIN
668 SELECT PAA.ABS_INFORMATION1 AS Cert_type
669 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Cert_stdt
670 ,to_date(PAA.ABS_INFORMATION3,'yyyy/mm/dd hh24:mi:ss') AS Cert_endt
671 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) AS PT_Percent
672 ,to_date(PAA.ABS_INFORMATION5,'yyyy/mm/dd hh24:mi:ss') AS Follow_due
673 ,to_date(PAA.ABS_INFORMATION6,'yyyy/mm/dd hh24:mi:ss') AS Follow_created
674 ,PAA.ABS_INFORMATION7 AS reimb_ss
675 ,PAA.ABS_INFORMATION8 AS dailyrate_ss
676 ,PAA.ABS_INFORMATION9 AS employer_6g
677 ,PAA.ABS_INFORMATION10 AS socialsec_6g
678 ,to_date(PAA.ABS_INFORMATION11,'yyyy/mm/dd hh24:mi:ss') AS Follow_sent
679 ,PAA.ABS_INFORMATION12 AS Daily_rate
680 INTO l_cert_type
681 ,l_cert_stdt
682 ,l_cert_endt
683 ,l_abs_pts_percent
684 ,l_follow_due
685 ,l_follow_created
686 ,l_abs_reimb_ss
687 ,l_abs_restrict_dr_ss
688 ,l_abs_restrict_empr_sl
689 ,l_abs_restrict_ss_sl
690 ,l_follow_sent
691 ,l_abs_daily_rate
692 FROM PER_ABSENCE_ATTENDANCES PAA
693 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
694 EXCEPTION
695 WHEN OTHERS THEN
696 l_cert_type := null;
697 l_cert_stdt := null;
698 l_cert_endt := null;
699 l_abs_pts_percent := null;
700 l_follow_due := null;
701 l_follow_created := null;
702 l_abs_reimb_ss := null;
703 l_abs_restrict_dr_ss := null;
704 l_abs_restrict_empr_sl := null;
705 l_abs_restrict_ss_sl := null;
706 l_follow_sent := null;
707 l_abs_daily_rate := null;
708 END;
709
710 END IF;
711 /* Identifying the input values based on the Priority levels. If none of the level has been
712 set then default value will be assigned. Refer mail dated 20th Feb 06 from Borge.*/
713 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
714 l_gen_entitled_sc := nvl(nvl(l_entitled_sc, l_le_entitled_sc), 'Y');
715 l_gen_exempt_empr := nvl(nvl(l_exempt_empr, l_le_exempt_empr), 'N');
716 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
717 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
718 l_gen_restrict_empr_sl := nvl(nvl(nvl(l_abs_restrict_empr_sl, l_restrict_empr_sl), l_le_restrict_empr_sl), 'Y');
719 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_abs_restrict_ss_sl, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
720 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
721
722 p_pts_percentage := l_abs_pts_percent ; /* 5410901 */
723 /* This Message has been handled at Absence Recording Level itself
724 -- Entitled to self certificate is set to no with self certificate has chosen then a warning message should be generated
725 IF l_gen_entitled_sc = 'N' AND l_cert_type = 'SC' THEN
726
727 / knelli commented code and added one line of code
728 IF length(l_msg_error) > 1 THEN
729 l_msg_error := 'Error7';
730 END IF;
731 /
732
733 l_msg_error := to_char(7);
734
735
736
737 END IF;*/
738
739 -- If current absence is a self certificate sickness and there are any
740 -- sc sickness of total 3 days in the previous 14 days then warning message will be generated.
741 /* This Message has been handled at Absence Recording Level itself
742 IF l_abs_category_code IN ('S','PTS') AND l_cert_type = 'SC' THEN
743 BEGIN
744 SELECT SUM( PAA.DATE_END - PAA.DATE_START )
745 INTO l_abs_count
746 FROM PER_ABSENCE_ATTENDANCES PAA
747 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id
748 AND PAA.DATE_END BETWEEN (p_abs_start_date - (p_abs_link_period+1)) AND (p_abs_start_date -1)
749 AND PAA.ABS_INFORMATION1 = 'SC'
750 AND PAA.DATE_START IS NOT NULL
751 AND PAA.DATE_END IS NOT NULL;
752 EXCEPTION
753 WHEN OTHERS THEN
754 NULL;
755 END;
756 IF l_abs_count > 3 THEN
757 / knelli
758 IF length(l_msg_error) > 1 THEN
759 l_msg_error := 'Error1';
760 END IF;/
761 l_msg_error := to_char(1);
762
763 -- Message to throw an warning message. No self certificate absences are allowed within 14 days of more than 3 days.
764 END IF;
765 END IF; */
766 /* This Message has been handled at Absence Recording Level itself
767 l_abs_count := null;
768 -- If current absence is a self certificate sickness and there are more than 4
769 -- sc sickness in the previous 12 months then a warining message should be thrown.
770 IF l_abs_category_code IN ('S','PTS') AND l_cert_type = 'SC' THEN
771 BEGIN
772 SELECT count(1)
773 INTO l_abs_count
774 FROM PER_ABSENCE_ATTENDANCES PAA
775 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id
776 AND PAA.DATE_END BETWEEN add_months(p_abs_start_date, -12) AND (p_abs_start_date-1)
777 AND PAA.ABS_INFORMATION1 = 'SC'
778 AND PAA.DATE_START IS NOT NULL
779 AND PAA.DATE_END IS NOT NULL;
780 EXCEPTION
781 WHEN OTHERS THEN
782 NULL;
783 END;
784 IF l_abs_count > 0 THEN
785 / knelli
786 IF length(l_msg_error) = 1 THEN
787 l_msg_error := 'Error2';
788 END IF;/
789 l_msg_error := to_char(2);
790
791
792 -- Message to throw an warning message. Only 4 self certificate absences are allowed for an year.
793 END IF;
794 END IF; */
795
796 l_abs_count := null;
797 -- Fetch absence reason from the lookup
798 BEGIN
799 SELECT LKP.Meaning
800 INTO l_abs_reason
801 FROM FND_LOOKUP_VALUES LKP
802 ,PER_ABSENCE_ATTENDANCES PAA
803 ,PER_ABS_ATTENDANCE_REASONS PAR
804 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAR.ABSENCE_ATTENDANCE_TYPE_ID
805 AND PAA.ABS_ATTENDANCE_REASON_ID = PAR.ABS_ATTENDANCE_REASON_ID
806 AND PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id
807 AND LKP.lookup_type = 'ABSENCE_REASON'
808 AND LOOKUP_CODE = PAR.NAME
809 GROUP BY LKP.Meaning;
810 EXCEPTION
811 WHEN OTHERS THEN
812 l_abs_reason := NULL;
813 END;
814
815 -- Condition 1. First sick is allowed after 28 days of Join.
816 /*5475038 - This message has been moved to recording level
817 l_dateofjoin_28 := l_dateofjoin + p_abs_min_gap ;
818 IF (l_abs_reason is Null or l_abs_reason <> 'Work Accident' ) THEN
819 BEGIN
820 /pdavidra - bug no 5330109 - Unauthorised absence count should be taken
821 form DOJ to current absence date
822 instead of DOJ to DOJ+28 days.
823 SELECT SUM ( CASE WHEN PAA.DATE_END > l_dateofjoin_28 THEN
824 ( l_dateofjoin_28 - PAA.DATE_START)
825 WHEN PAA.DATE_START = PAA.DATE_END THEN
826 1
827 ELSE (PAA.DATE_END - PAA.DATE_START) END ) AS DAYS
828 INTO l_abs_unauthor
829 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
830 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
831 AND PAT.ABSENCE_CATEGORY = 'UN'
832 AND PAA.DATE_START <= l_dateofjoin_28
833 AND PAA.DATE_END >= l_dateofjoin
834 AND PAA.DATE_START IS NOT NULL
835 AND PAA.DATE_END IS NOT NULL
836 AND PAA.PERSON_ID = p_person_id;/
837 SELECT SUM ( CASE WHEN PAA.DATE_END > (p_abs_start_date-1) THEN
838 ( (p_abs_start_date-1) - PAA.DATE_START) + 1
839 WHEN PAA.DATE_START = PAA.DATE_END THEN
840 1
841 ELSE (PAA.DATE_END - PAA.DATE_START) + 1 END ) AS DAYS
842 INTO l_abs_unauthor
843 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
844 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
845 AND PAT.ABSENCE_CATEGORY = 'UN'
846 AND PAA.DATE_START <= (p_abs_start_date-1)
847 AND PAA.DATE_END >= l_dateofjoin
848 AND PAA.DATE_START IS NOT NULL
849 AND PAA.DATE_END IS NOT NULL
850 AND PAA.PERSON_ID = p_person_id;
851 EXCEPTION
852 WHEN OTHERS THEN
853 l_abs_unauthor := 0;
854 END;
855
856 IF ( p_abs_start_date - l_dateofjoin ) < (p_abs_min_gap + nvl(l_abs_unauthor,0) ) THEN
857
858 / knelli
859 IF length(l_msg_error) > 1 THEN
860 l_msg_error := 'Error3';
861 END IF;/
862 l_msg_error := to_char(3);
863
864 END IF;
865
866 -- Condition 2. Minimum 28 days employment is required to avail sick pay except sickness or holiday
867 -- within 28 days from start of the current absence. If any other absence exists with more than
868 -- 14 days within 28 days then no sickness will be paid.
869 BEGIN
870 SELECT COUNT(1)
871 INTO l_abs_count
872 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
873 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
874 AND PAT.ABSENCE_CATEGORY IN ( 'CMS','PA','PTP','M','PTM','IE_AL' ,'PTA')
875 AND PAA.DATE_END BETWEEN (p_abs_start_date - (p_abs_min_gap+1)) AND p_abs_start_date
876 AND ( PAA.DATE_END - PAA.DATE_START ) > p_abs_link_period
877 AND PAA.DATE_START IS NOT NULL
878 AND PAA.DATE_END IS NOT NULL
879 AND PAA.PERSON_ID = p_person_id;
880 EXCEPTION
881 WHEN OTHERS THEN
882 l_abs_count := 0;
883 END;
884
885 -- There are sickness exists within 28days of current sickness start date with more than 14 days
886 -- except absence categories Sickness, Part-time sickness and Vacation.
887 IF l_abs_count > 0 THEN
888 / knelli
889 IF length(l_msg_error) > 1 THEN
890 l_msg_error := 'Error4';
891 END IF;/
892 l_msg_error := to_char(4);
893
894 END IF;
895 END IF; -- Work accident end if */
896
897 -- Calling override to get override days and daily rate
898 l_over_return := get_override_details
899 ( p_assignment_id,p_effective_date,p_abs_start_date,
900 p_abs_end_date, p_abs_categorycode, l_override_start_date,
901 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
902 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
903 );
904
905 /* Multiple override element attached against one absence element. ie) *
906 * One or more override entry exists with same start and end date */
907 IF (l_over_return = -1) THEN
908 /* knelli
909 IF length(l_msg_error) > 1 THEN
910 l_msg_error := 'Error5';
911 END IF;*/
912 l_msg_error := to_char(5);
913 p_abs_error := l_msg_error;
914 RETURN 1;
915 END IF;
916 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
917 l_msg_error := to_char(13);
918 END IF;
919 l_include_event := 'N';
920 -- Calculating actual sickness days through work schedule
921 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
922 ( p_assignment_id, l_days_or_hours, l_include_event,
923 p_prorate_start, p_prorate_end, l_start_time_char,
924 l_end_time_char, l_duration
925 );
926
927 l_actual_cal_days := nvl(l_duration,0);
928
929 -- Calculate Earnings Adjustment value
930 IF l_abs_category_code = 'PTS' THEN /* 5437889 */
931 --p_ear_value := ( ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * (nvl(l_abs_pts_percent,0)/100) ) * l_actual_cal_days; 5925652
932 p_ear_value := round(( ( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ) * (nvl(l_abs_pts_percent,0)/100) ),2) * l_actual_cal_days;
933 ELSE
934 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
935 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * l_actual_cal_days;
936 END IF;
937 p_ear_startdt := p_prorate_start;
938 p_ear_enddt := p_prorate_end;
939 p_ear_value := nvl(p_ear_value,0);
940
941 -- Calculate total absence days
942 l_gen_totalabs_days := (p_abs_end_date - p_abs_start_date ) + 1;
943 -- Calculate total prorated day(s) of the current payroll
944 l_gen_pro_days := (p_prorate_end - p_prorate_start ) + 1;
945 -- Calculate Employer's period start date
946 l_gen_empr_st_date := p_prorate_start;
947 -- Seeking the start of the Social Security start date.
948
949 IF l_gen_totalabs_days > p_abs_cal_days THEN
950 l_gen_ss_st_date := (p_abs_start_date + p_abs_cal_days);
951 ELSE
952 l_gen_ss_st_date := null;
953 END IF;
954
955 p_abs_total_cal_days := (p_prorate_end - p_prorate_start) + 1 ;
956
957 l_return := null;
958 -- To fetch the 26week rule period values
959 l_return := get_sick_unpaid (p_assignment_id, p_effective_date, p_dbi_26week_stdt, p_dbi_26week_endt);
960 /*====================================================================================================
961 -- Implementation of top logic to calculate actual days using proration and finding
962 -- the continuous linking period.
963 IF p_abs_start_date between p_pay_start_date AND p_pay_end_date
964 AND p_abs_end_date between p_pay_start_date AND p_pay_end_date THEN
965
966 -- Condition 3 - Calculate continuous linking period of sickness
967 -- If there are multiple sickness exists within 14 days before start date then
968 -- include those sickness in calculating employer days.
969 l_loop_empr_days := 0;
970 l_loop_empr_work_days := 0;
971 l_loop_start_date := p_abs_start_date ;
972 FOR i in CSR_CONT_LINK (p_person_id) LOOP
973 IF ( i.date_start = i.date_end ) THEN
974 l_loop_empr_days := l_loop_empr_days + 1;
975 l_duration := 0;
976 l_include_event := 'N';
977 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
978 ( p_assignment_id, l_days_or_hours, l_include_event,
979 i.date_start, i.date_end, l_start_time_char,
980 l_end_time_char, l_duration
981 );
982 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
983 ELSIF ( l_loop_start_date - i.date_end ) <= p_abs_link_period then
984 l_duration := 0;
985 l_duration := (i.date_end - i.date_start) +1;
986 l_loop_empr_days := (l_loop_empr_days + nvl(l_duration,0));
987 -- Calling override to get override days and daily rate
988 l_over_return := get_override_details
989 ( p_assignment_id,p_effective_date,i.date_start,
990 i.date_end, p_abs_categorycode, l_cont_start_date,
991 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
992 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
993 );
994 / Multiple override element attached against one absence element. ie) *
995 * One or more override entry exists with same start and end date /
996 IF (l_over_return = -1) THEN
997 / knelli
998 IF length(l_msg_error) > 1 THEN
999 l_msg_error := 'Error5';
1000 END IF;/
1001 l_msg_error := to_char(5);
1002 END IF;
1003 -- If override element exists for the continuous absences then override the work days.
1004 IF l_cont_empr_days IS NULL THEN
1005 l_duration := 0;
1006 l_include_event := 'N';
1007 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1008 ( p_assignment_id, l_days_or_hours, l_include_event,
1009 i.date_start, i.date_end, l_start_time_char,
1010 l_end_time_char, l_duration
1011 );
1012 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
1013 ELSE
1014 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
1015 END IF;
1016 ELSE -- No linking absence exists.
1017 EXIT;
1018 END IF;
1019 l_loop_start_date := i.date_start;
1020 END LOOP;
1021
1022 -- Calculation of Employer Days in terms of calendar days
1023 -- If continuous linked cal days exceeds maximum 16 days then for current absence empr period will be 0
1024 IF l_loop_empr_days >= p_abs_cal_days THEN
1025 l_empr_days := 0;
1026 l_gen_ss_st_date := p_prorate_start ;
1027 IF l_gen_reimb_ss = 'N' THEN
1028 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1029 END IF;
1030 -- Update the element input value Employer Cal Days with existing plus current empr days.
1031 -- ie) existing := existing + l_empr_days
1032 ELSE
1033 / pdavidra commented
1034 IF l_gen_totalabs_days > (p_abs_cal_days - l_loop_empr_days) THEN
1035 -- Absence lies within a payroll period
1036 -- Calculating actual sickness days through work schedule
1037 l_gen_ss_st_date := p_prorate_start + (p_abs_cal_days - l_loop_empr_days);
1038
1039 -- Ignore public holidays if the one present in between absence start and end dates.
1040 l_include_event := 'N';
1041 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1042 ( p_assignment_id, l_days_or_hours, l_include_event,
1043 p_prorate_start, (l_gen_ss_st_date - 1), l_start_time_char,
1044 l_end_time_char, l_duration
1045 );
1046 l_actual_days := l_duration;
1047 p_abs_sick_days := (l_gen_ss_st_date - p_prorate_start);
1048
1049 -- Update the element input value Employer Cal Days with existing plus current empr days.
1050 -- ie) existing := existing + (p_abs_cal_days - l_loop_empr_days)
1051 ELSE
1052 -- Calculation of Employer Days
1053 -- Absence lies within a payroll period
1054 -- Calculating actual sickness days through work schedule
1055 l_gen_ss_st_date := null;
1056
1057 -- Ignore public holidays if the one present in between absence start and end dates.
1058 l_include_event := 'N';
1059 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1060 ( p_assignment_id, l_days_or_hours, l_include_event,
1061 p_prorate_start, p_prorate_end, l_start_time_char,
1062 l_end_time_char, l_duration
1063 );
1064 l_actual_days := nvl(l_duration,0);
1065 p_abs_sick_days := (p_prorate_end - p_prorate_start) + 1;
1066
1067 -- Update the element input value Employer Cal Days with existing plus current empr days.
1068 -- ie) existing := existing + l_gen_totalabs_days
1069 END IF; /
1070
1071 / pdavidra added code start - Bug no: 5277080/
1072 l_include_event := 'N';
1073 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1074 ( p_assignment_id, l_days_or_hours, l_include_event,
1075 p_prorate_start, p_prorate_end, l_start_time_char,
1076 l_end_time_char, l_duration
1077 );
1078 l_actual_days := l_duration;
1079 / pdavidra added code end/
1080
1081 -- Continuous sickness work days greater than 12 working days so no more empr days will be paid.
1082 IF l_loop_empr_work_days >= p_abs_work_days THEN
1083
1084 l_empr_days := 0;
1085 IF l_gen_reimb_ss = 'N' THEN
1086 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1087 END IF;
1088 ELSE -- Continuous sickness days is less than 12 working days
1089 -- if actual working days > remaning available then social security days will be paid
1090
1091 IF l_actual_days > ( p_abs_work_days - l_loop_empr_work_days ) THEN
1092 l_empr_days := ( p_abs_work_days - l_loop_empr_work_days );
1093 IF l_gen_reimb_ss = 'N' THEN
1094 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1095 END IF;
1096 -- if override employer days is present calculate actual days through continuous linking sickness
1097 -- and then override that with the override days.
1098 IF l_override_empr_days IS NOT NULL THEN
1099 l_empr_days := least(l_override_empr_days, l_empr_days);
1100 END IF;
1101 -- Update the element input value Employer work Days with existing plus current empr days.
1102 -- ie) existing := existing + l_empr_days;
1103 ELSE
1104 l_empr_days := l_actual_days;
1105 -- if override employer days is present calculate actual days through continuous linking sickness
1106 -- and then override that with the override days.
1107 IF l_override_empr_days IS NOT NULL THEN
1108 l_empr_days := least(l_override_empr_days, l_empr_days);
1109 END IF;
1110 -- Update the element input value Employer work Days with existing plus current empr days.
1111 -- ie) existing := existing + l_empr_days;
1112 END IF;
1113
1114 END IF;
1115 END IF;
1116 / 5277080 start - Calculate the Social Security Start Date /
1117 l_gen_ss_st_date := p_prorate_start + l_empr_days ;
1118 loop
1119 l_include_event := 'N';
1120 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1121 ( p_assignment_id, l_days_or_hours, l_include_event,
1122 p_prorate_start, l_gen_ss_st_date, l_start_time_char,
1123 l_end_time_char, l_duration
1124 );
1125
1126 IF l_duration = (l_empr_days +1) THEN
1127 exit;
1128 END IF;
1129 l_gen_ss_st_date := l_gen_ss_st_date + 1;
1130 end loop;
1131 / 5277080 End /
1132
1133 -- CALCULATION OF SOCIAL SECURITY DAYS
1134 -- Calculate social security days if reimburse from social security is set to Yes at any level
1135
1136 IF l_gen_reimb_ss = 'Y' THEN
1137 -- IF social security start date is within the current payroll period then
1138 IF l_gen_ss_st_date >= p_prorate_start and l_gen_ss_st_date <= p_prorate_end then
1139 -- If the 26week rule element input value's start date and end date are set then
1140 IF l_return = 0 THEN
1141 -- If Current absence is withing the 26week rule period then throw a warning message
1142 IF l_gen_ss_st_date <= p_dbi_26week_endt AND p_prorate_end >= p_dbi_26week_stdt THEN
1143 l_social_security_days := null;
1144 l_msg_error := to_char(9);
1145 --Throw warning message that no social security days will be paid due to 26week rule.
1146 ELSE
1147 p_work_pattern := '5DAY';
1148 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1149 -- if exempt from employer period id set to no
1150 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1151 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1152 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1153 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1154 ELSE
1155 l_social_security_days := l_duration;
1156 END IF;
1157 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1158 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1159 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1160 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1161 ELSE -- user can avail the actual ss days as it is within 260 limit
1162 l_social_security_days := l_duration;
1163 END IF;
1164 END IF; -- l_gen_exempt_empr = 'N'
1165 END IF; -- Current absence is beyond the 26week rule period
1166
1167 ELSE -- 26week rule element not attached to this assignment
1168 p_work_pattern := '5DAY';
1169 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1170 -- if exempt from employer period id set to no
1171 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1172 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1173 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1174 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1175 ELSE
1176 l_social_security_days := l_duration;
1177 END IF;
1178 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1179 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1180 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1181 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1182 ELSE -- user can avail the actual ss days as it is within 260 limit
1183 l_social_security_days := l_duration;
1184 END IF;
1185
1186 END IF; -- l_gen_exempt_empr = 'N'
1187 END IF; -- If the 26week rule element input value's start date and end date are set then
1188 ELSE
1189
1190 / knelli changed code /
1191 l_social_security_days := 0;
1192 /l_social_security_days := l_actual_days - l_empr_days;/
1193 END IF; -- IF social security start date is within the absence period or prorated period then
1194
1195 END IF; --Calculate social security days if reimburse from social security is set to Yes at any level
1196 -- if override social security days is present calculate actual days with the override days.
1197
1198 IF l_override_ss_days IS NOT NULL THEN
1199 l_social_security_days := least(l_override_ss_days, l_social_security_days);
1200 END IF;
1201 -- If social security days availed from this absence exeeecs 220 days then a warning message should be thrown.
1202 IF ( nvl(l_social_security_days,0) + nvl(p_3years_paybase,0) ) > 220 THEN
1203 / knelli
1204 IF length(l_msg_error) > 1 THEN
1205 l_msg_error := 'Error6';
1206 END IF;/
1207 l_msg_error := to_char(6);
1208
1209 END IF;
1210 ------------------------------------------------------------------------------
1211 ------------------------------------------------------------------------------
1212
1213 Else -- Absences lies more than one payroll period
1214 -- Absence start date lies in between the payroll period st dt and end dt.
1215 IF p_abs_start_date between p_pay_start_date and p_pay_end_date THEN
1216
1217 -- Condition 3 - Calculate continuous linking period of sickness
1218 -- If there are multiple sickness exists within 14 days before start date then
1219 -- include those sickness in calculating employer days.
1220 l_loop_empr_days := 0;
1221 l_loop_empr_work_days := 0;
1222 l_loop_start_date := p_abs_start_date ;
1223 FOR i in CSR_CONT_LINK (p_person_id) LOOP
1224 IF ( i.date_start = i.date_end ) THEN
1225 l_loop_empr_days := l_loop_empr_days + 1;
1226 l_duration := 0;
1227 l_include_event := 'N';
1228 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1229 ( p_assignment_id, l_days_or_hours, l_include_event,
1230 i.date_start, i.date_end, l_start_time_char,
1231 l_end_time_char, l_duration
1232 );
1233 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
1234 ELSIF ( l_loop_start_date - i.date_end ) <= p_abs_link_period then
1235 l_duration := 0;
1236 l_duration := (i.date_end - i.date_start) +1;
1237 l_loop_empr_days := (l_loop_empr_days + nvl(l_duration,0));
1238 -- Calling override to get override days and daily rate
1239 l_over_return := get_override_details
1240 ( p_assignment_id,p_effective_date,i.date_start,
1241 i.date_end, p_abs_categorycode, l_cont_start_date,
1242 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
1243 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
1244 );
1245 / Multiple override element attached against one absence element. ie) *
1246 * One or more override entry exists with same start and end date /
1247 IF (l_over_return = -1) THEN
1248 / knelli
1249 IF length(l_msg_error) > 1 THEN
1250 l_msg_error := 'Error5';
1251 END IF;/
1252 l_msg_error := to_char(5);
1253 END IF;
1254 -- If override element exists for the continuous absences then override the work days.
1255 IF l_cont_empr_days IS NULL THEN
1256 l_duration := 0;
1257 l_include_event := 'N';
1258 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1259 ( p_assignment_id, l_days_or_hours, l_include_event,
1260 i.date_start, i.date_end, l_start_time_char,
1261 l_end_time_char, l_duration
1262 );
1263 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
1264 ELSE
1265 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
1266 END IF;
1267 ELSE -- No linking absence exists.
1268 EXIT;
1269 END IF;
1270 l_loop_start_date := i.date_start;
1271 END LOOP;
1272
1273 -- Calculation of employer days if proration was enabled
1274 l_counter := 1;
1275 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
1276 -- It means absences crosses between one payroll period
1277 IF l_counter = 1 THEN
1278 -- Newly introduced to knock off calendar and work days variables of employers period already taken.
1279 -- As it is a start of the proration period.
1280 l_loop_empr_days := nvl(l_loop_empr_days,0) + 0;
1281 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + 0;
1282
1283 ELSE
1284 -- Calculating calendar days with prorated period
1285 l_loop_empr_days := nvl(l_loop_empr_days,0) + ( i.date_earned - l_prev_paydate);
1286 -- Calculating actual days with prorated period
1287 l_duration := 0;
1288 l_include_event := 'N';
1289 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1290 ( p_assignment_id, l_days_or_hours, l_include_event,
1291 (l_prev_paydate+1), i.date_earned, l_start_time_char,
1292 l_end_time_char, l_duration
1293 );
1294 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
1295 END IF;
1296 l_counter := l_counter + 1;
1297 l_prev_paydate := i.date_earned;
1298 END LOOP;
1299
1300 -- Calculation of Employer Days in terms of calendar days
1301 -- If continuous linked cal days exceeds maximum 16 days then for current absence empr period will be 0
1302
1303 IF l_loop_empr_days >= p_abs_cal_days THEN
1304 l_empr_days := 0;
1305 l_gen_ss_st_date := p_prorate_start ;
1306 IF l_gen_reimb_ss = 'N' THEN
1307 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1308 END IF;
1309 -- Update the element input value Employer Cal Days with existing plus current empr days.
1310 -- ie) existing := existing + l_empr_days
1311 ELSE
1312
1313 / knelli commented
1314 IF l_gen_totalabs_days > (p_abs_cal_days - l_loop_empr_days) THEN
1315 -- Absence lies within a payroll period
1316 -- Calculating actual sickness days through work schedule
1317 l_gen_ss_st_date := p_prorate_start + (p_abs_cal_days - l_loop_empr_days);
1318 -- Ignore public holidays if the one present in between absence start and end dates.
1319 l_include_event := 'N';
1320 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1321 ( p_assignment_id, l_days_or_hours, l_include_event,
1322 p_prorate_start, (l_gen_ss_st_date - 1), l_start_time_char,
1323 l_end_time_char, l_duration
1324 );
1325 l_actual_days := l_duration;
1326 -- Update the element input value Employer Cal Days with existing plus current empr days.
1327 -- ie) existing := existing + (p_abs_cal_days - l_loop_empr_days)
1328 ELSE
1329 -- Calculation of Employer Days
1330 -- Absence lies within a payroll period
1331 -- Calculating actual sickness days through work schedule
1332 l_gen_ss_st_date := null;
1333 -- Ignore public holidays if the one present in between absence start and end dates.
1334 l_include_event := 'N';
1335 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1336 ( p_assignment_id, l_days_or_hours, l_include_event,
1337 p_prorate_start, p_prorate_end, l_start_time_char,
1338 l_end_time_char, l_duration
1339 );
1340 l_actual_days := l_duration;
1341 END IF;
1342 /
1343
1344 / knelli added code start/
1345 l_include_event := 'N';
1346 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1347 ( p_assignment_id, l_days_or_hours, l_include_event,
1348 p_prorate_start, p_prorate_end, l_start_time_char,
1349 l_end_time_char, l_duration
1350 );
1351 l_actual_days := l_duration;
1352 / knelli added code end/
1353
1354 -- Continuous sickness work days greater than 12 working days so no more empr days will be paid.
1355 IF l_loop_empr_work_days >= p_abs_work_days THEN
1356 l_empr_days := 0;
1357 IF l_gen_reimb_ss = 'N' THEN
1358 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1359 END IF;
1360 ELSE -- Continuous sickness days is less than 12 working days
1361 -- if actual working days > remaning available then social security days will be paid
1362 IF l_actual_days > ( p_abs_work_days - l_loop_empr_work_days ) THEN
1363 l_empr_days := ( p_abs_work_days - l_loop_empr_work_days );
1364 IF l_gen_reimb_ss = 'N' THEN
1365 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1366 END IF;
1367 -- if override employer days is present calculate actual days through continuous linking sickness
1368 -- and then override that with the override days.
1369 IF l_override_empr_days IS NOT NULL THEN
1370 l_empr_days := least(l_override_empr_days, l_empr_days);
1371 END IF;
1372 ELSE
1373 l_empr_days := l_actual_days;
1374 -- if override employer days is present calculate actual days through continuous linking sickness
1375 -- and then override that with the override days.
1376 IF l_override_empr_days IS NOT NULL THEN
1377 l_empr_days := least(l_override_empr_days, l_empr_days);
1378 END IF;
1379 END IF;
1380 END IF;
1381 END IF;
1382 / 5277080 start - Calculate the Social Security Start Date /
1383 l_gen_ss_st_date := p_prorate_start + l_empr_days ;
1384 loop
1385 l_include_event := 'N';
1386 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1387 ( p_assignment_id, l_days_or_hours, l_include_event,
1388 p_prorate_start, l_gen_ss_st_date, l_start_time_char,
1389 l_end_time_char, l_duration
1390 );
1391
1392 IF l_duration = (l_empr_days +1) THEN
1393 exit;
1394 END IF;
1395 l_gen_ss_st_date := l_gen_ss_st_date + 1;
1396 end loop;
1397 / 5277080 End /
1398
1399 -- CALCULATION OF SOCIAL SECURITY DAYS
1400 -- Calculate social security days if reimburse from social security is set to Yes at any level
1401 IF l_gen_reimb_ss = 'Y' THEN
1402 -- IF social security start date is within the current payroll period then
1403 IF l_gen_ss_st_date >= p_prorate_start and l_gen_ss_st_date <= p_prorate_end then
1404 -- If the 26week rule element input value's start date and end date are set then
1405 IF l_return = 0 THEN
1406 -- If Current absence is withing the 26week rule period then throw a warning message
1407 IF l_gen_ss_st_date <= p_dbi_26week_endt AND p_prorate_end >= p_dbi_26week_stdt THEN
1408 l_social_security_days := null;
1409 / knelli
1410 IF length(l_msg_error) > 1 THEN
1411 l_msg_error := 'Error9';
1412 END IF;/
1413 l_msg_error := to_char(9);
1414 --Throw warning message that no social security days will be paid due to 26week rule.
1415 ELSE
1416 p_work_pattern := '5DAY';
1417 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1418 -- if exempt from employer period id set to no
1419 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1420 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1421 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1422 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1423 ELSE
1424 l_social_security_days := l_duration;
1425 END IF;
1426 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1427 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1428 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1429 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1430 ELSE -- user can avail the actual ss days as it is within 260 limit
1431 l_social_security_days := l_duration;
1432 END IF;
1433 END IF; -- l_gen_exempt_empr = 'N'
1434 END IF; -- Current absence is beyond the 26week rule period
1435
1436 ELSE -- 26week rule element not attached to this assignment
1437 p_work_pattern := '5DAY';
1438 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1439 -- if exempt from employer period id set to no
1440 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1441 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1442 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1443 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1444 ELSE
1445 l_social_security_days := l_duration;
1446 END IF;
1447 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1448 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1449 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1450 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1451 ELSE -- user can avail the actual ss days as it is within 260 limit
1452 l_social_security_days := l_duration;
1453 END IF;
1454 END IF; -- l_gen_exempt_empr = 'N'
1455 END IF; -- If the 26week rule element input value's start date and end date are set then
1456 ELSE
1457 l_social_security_days := 0;
1458 END IF; -- IF social security start date is within the absence period or prorated period then
1459
1460 END IF; --Calculate social security days if reimburse from social security is set to Yes at any level
1461 -- if override social security days is present calculate actual days with the override days.
1462 IF l_override_ss_days IS NOT NULL THEN
1463 l_social_security_days := least(l_override_ss_days, l_social_security_days);
1464 END IF;
1465
1466 -- If social security days availed from this absence exeeecs 220 days then a warning message should be thrown.
1467 IF ( nvl(l_social_security_days,0) + nvl(p_3years_paybase,0) ) > 220 THEN
1468 / knelli
1469 IF length(l_msg_error) > 1 THEN
1470 l_msg_error := 'Error6';
1471 END IF;/
1472 l_msg_error := to_char(6);
1473
1474 END IF;
1475 -------------------------------------------------------------------------
1476 -------------------------------------------------------------------------
1477
1478 -- Refer the previous payroll period's element input value for Empr and SS days calc.
1479 -- Absence end date lies in between the payroll period st dt and end dt.
1480 ELSIF p_abs_end_date between p_pay_start_date and p_pay_end_date THEN
1481
1482 -- Condition 3 - Calculate continuous linking period of sickness
1483 -- If there are multiple sickness exists within 14 days before start date then
1484 -- include those sickness in calculating employer days.
1485 l_loop_empr_days := 0;
1486 l_loop_empr_work_days := 0;
1487 l_loop_start_date := p_abs_start_date ;
1488 FOR i in CSR_CONT_LINK (p_person_id) LOOP
1489
1490 IF ( i.date_start = i.date_end ) THEN
1491 l_loop_empr_days := l_loop_empr_days + 1;
1492 l_duration := 0;
1493 l_include_event := 'N';
1494 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1495 ( p_assignment_id, l_days_or_hours, l_include_event,
1496 i.date_start, i.date_end, l_start_time_char,
1497 l_end_time_char, l_duration
1498 );
1499 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
1500
1501 ELSIF ( l_loop_start_date - i.date_end ) <= p_abs_link_period then
1502 -- Calculate the employer period days in terms of calendar days.
1503 l_duration := 0;
1504 l_duration := (i.date_end - i.date_start) +1;
1505 l_loop_empr_days := (l_loop_empr_days + nvl(l_duration,0));
1506 -- Calculate the employer period days in terms of actual working days.
1507 -- Calling override to get override days and daily rate
1508 l_over_return := get_override_details
1509 ( p_assignment_id,p_effective_date,i.date_start,
1510 i.date_end, p_abs_categorycode, l_cont_start_date,
1511 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
1512 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
1513 );
1514 / Multiple override element attached against one absence element. ie) *
1515 * One or more override entry exists with same start and end date /
1516 IF (l_over_return = -1) THEN
1517 / knelli
1518 IF length(l_msg_error) > 1 THEN
1519 l_msg_error := 'Error5';
1520 END IF;/
1521 l_msg_error := to_char(5);
1522 END IF;
1523 -- If override element exists for the continuous absences then override the work days.
1524 IF l_cont_empr_days IS NULL THEN
1525 l_duration := 0;
1526 l_include_event := 'N';
1527 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1528 ( p_assignment_id, l_days_or_hours, l_include_event,
1529 i.date_start, i.date_end, l_start_time_char,
1530 l_end_time_char, l_duration
1531 );
1532 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
1533 ELSE
1534 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
1535 END IF;
1536 ELSE -- No linking absence exists.
1537 EXIT;
1538 END IF;
1539 l_loop_start_date := i.date_start;
1540 END LOOP;
1541
1542 -- Calculation of employer days if proration was enabled
1543 l_counter := 1;
1544 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
1545 -- It means absences crosses between one payroll period
1546 IF l_counter = 1 THEN
1547 -- Calculating calendar days with prorated period
1548 l_loop_empr_days := nvl(l_loop_empr_days,0) + (i.date_earned - p_abs_start_date)+1;
1549 -- Calculating actual days with prorated period
1550 l_duration := 0;
1551 l_include_event := 'N';
1552 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1553 ( p_assignment_id, l_days_or_hours, l_include_event,
1554 p_abs_start_date, i.date_earned, l_start_time_char,
1555 l_end_time_char, l_duration
1556 );
1557 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
1558 ELSE
1559 -- Calculating calendar days with prorated period
1560 l_loop_empr_days := nvl(l_loop_empr_days,0) + ( i.date_earned - l_prev_paydate);
1561 -- Calculating actual days with prorated period
1562 l_duration := 0;
1563 l_include_event := 'N';
1564 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1565 ( p_assignment_id, l_days_or_hours, l_include_event,
1566 (l_prev_paydate+1), i.date_earned, l_start_time_char,
1567 l_end_time_char, l_duration
1568 );
1569 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
1570 END IF;
1571 l_counter := l_counter + 1;
1572 l_prev_paydate := i.date_earned;
1573 END LOOP;
1574
1575 -- Calculation of Employer Days in terms of calendar days
1576 -- If continuous linked cal days exceeds maximum 16 days then for current absence empr period will be 0
1577
1578 IF l_loop_empr_days >= p_abs_cal_days THEN
1579 l_empr_days := 0;
1580 l_gen_ss_st_date := p_prorate_start ;
1581 IF l_gen_reimb_ss = 'N' THEN
1582 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1583 END IF;
1584 ELSE
1585
1586 / knelli commented
1587 IF l_gen_totalabs_days > (p_abs_cal_days - l_loop_empr_days) THEN
1588 -- Absence lies within a payroll period
1589 -- Calculating actual sickness days through work schedule
1590 l_gen_ss_st_date := p_prorate_start + (p_abs_cal_days - l_loop_empr_days);
1591 -- Ignore public holidays if the one present in between absence start and end dates.
1592 l_include_event := 'N';
1593 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1594 ( p_assignment_id, l_days_or_hours, l_include_event,
1595 p_prorate_start, (l_gen_ss_st_date - 1), l_start_time_char,
1596 l_end_time_char, l_duration
1597 );
1598 l_actual_days := l_duration;
1599 ELSE
1600 -- Calculation of Employer Days
1601 -- Absence lies within a payroll period
1602 -- Calculating actual sickness days through work schedule
1603 l_gen_ss_st_date := null;
1604 -- Ignore public holidays if the one present in between absence start and end dates.
1605 l_include_event := 'N';
1606 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1607 ( p_assignment_id, l_days_or_hours, l_include_event,
1608 p_prorate_start, p_prorate_end, l_start_time_char,
1609 l_end_time_char, l_duration
1610 );
1611 l_actual_days := l_duration;
1612 END IF;
1613 /
1614
1615 / knelli added code start/
1616 l_include_event := 'N';
1617 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1618 ( p_assignment_id, l_days_or_hours, l_include_event,
1619 p_prorate_start, p_prorate_end, l_start_time_char,
1620 l_end_time_char, l_duration
1621 );
1622 l_actual_days := l_duration;
1623 / knelli added code end /
1624
1625 -- Continuous sickness work days greater than 12 working days so no more empr days will be paid.
1626 IF l_loop_empr_work_days >= p_abs_work_days THEN
1627 l_empr_days := 0;
1628 IF l_gen_reimb_ss = 'N' THEN
1629 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1630 END IF;
1631 ELSE -- Continuous sickness days is less than 12 working days
1632 -- if actual working days > remaning available then social security days will be paid
1633 IF l_actual_days > ( p_abs_work_days - l_loop_empr_work_days ) THEN
1634 l_empr_days := ( p_abs_work_days - l_loop_empr_work_days );
1635 IF l_gen_reimb_ss = 'N' THEN
1636 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1637 END IF;
1638 -- if override employer days is present calculate actual days through continuous linking sickness
1639 -- and then override that with the override days.
1640 IF l_override_empr_days IS NOT NULL THEN
1641 l_empr_days := least(l_override_empr_days, l_empr_days);
1642 END IF;
1643 ELSE
1644 l_empr_days := l_actual_days;
1645 -- if override employer days is present calculate actual days through continuous linking sickness
1646 -- and then override that with the override days.
1647 IF l_override_empr_days IS NOT NULL THEN
1648 l_empr_days := least(l_override_empr_days, l_empr_days);
1649 END IF;
1650 END IF;
1651 END IF;
1652 END IF;
1653 / 5277080 start - Calculate the Social Security Start Date /
1654 l_gen_ss_st_date := p_prorate_start + l_empr_days ;
1655 loop
1656 l_include_event := 'N';
1657 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1658 ( p_assignment_id, l_days_or_hours, l_include_event,
1659 p_prorate_start, l_gen_ss_st_date, l_start_time_char,
1660 l_end_time_char, l_duration
1661 );
1662
1663 IF l_duration = (l_empr_days +1) THEN
1664 exit;
1665 END IF;
1666 l_gen_ss_st_date := l_gen_ss_st_date + 1;
1667 end loop;
1668 / 5277080 End /
1669
1670 -- CALCULATION OF SOCIAL SECURITY DAYS
1671 -- Calculate social security days if reimburse from social security is set to Yes at any level
1672 IF l_gen_reimb_ss = 'Y' THEN
1673 -- IF social security start date is within the current payroll period then
1674 IF l_gen_ss_st_date >= p_prorate_start and l_gen_ss_st_date <= p_prorate_end then
1675 -- If the 26week rule element input value's start date and end date are set then
1676 IF l_return = 0 THEN
1677 -- If Current absence is withing the 26week rule period then throw a warning message
1678 IF l_gen_ss_st_date <= p_dbi_26week_endt AND p_prorate_end >= p_dbi_26week_stdt THEN
1679 l_social_security_days := null;
1680 / knelli
1681 IF length(l_msg_error) > 1 THEN
1682 l_msg_error := 'Error9';
1683 END IF;/
1684 l_msg_error := to_char(9);
1685 --Throw warning message that no social security days will be paid due to 26week rule.
1686 ELSE
1687 p_work_pattern := '5DAY';
1688 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1689 -- if exempt from employer period id set to no
1690 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1691 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1692 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1693 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1694 ELSE
1695 l_social_security_days := l_duration;
1696 END IF;
1697 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1698 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1699 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1700 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1701 ELSE -- user can avail the actual ss days as it is within 260 limit
1702 l_social_security_days := l_duration;
1703 END IF;
1704 END IF; -- l_gen_exempt_empr = 'N'
1705 END IF; -- Current absence is beyond the 26week rule period
1706
1707 ELSE -- 26week rule element not attached to this assignment
1708 p_work_pattern := '5DAY';
1709 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1710 -- if exempt from employer period id set to no
1711 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1712 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1713 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1714 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1715 ELSE
1716 l_social_security_days := l_duration;
1717 END IF;
1718 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1719 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1720 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1721 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1722 ELSE -- user can avail the actual ss days as it is within 260 limit
1723 l_social_security_days := l_duration;
1724 END IF;
1725 END IF; -- l_gen_exempt_empr = 'N'
1726 END IF; -- If the 26week rule element input value's start date and end date are set then
1727 ELSE
1728 l_social_security_days := 0;
1729 END IF; -- IF social security start date is within the absence period or prorated period then
1730
1731 END IF; --Calculate social security days if reimburse from social security is set to Yes at any level
1732 -- if override social security days is present calculate actual days with the override days.
1733 IF l_override_ss_days IS NOT NULL THEN
1734 l_social_security_days := least(l_override_ss_days, l_social_security_days);
1735 END IF;
1736 -- If social security days availed from this absence exeeecs 220 days then a warning message should be thrown.
1737 IF ( nvl(l_social_security_days,0) + nvl(p_3years_paybase,0) ) > 220 THEN
1738 / knelli
1739 IF length(l_msg_error) > 1 THEN
1740 l_msg_error := 'Error6';
1741 END IF;/
1742 l_msg_error := to_char(6);
1743
1744 END IF;
1745 ----------------------------------------------------------------------
1746 ----------------------------------------------------------------------
1747 ELSE -- Absence start and end date, both not lying in between the payroll period st dt and end dt.
1748 -- Condition 3 - Calculate continuous linking period of sickness
1749 -- If there are multiple sickness exists within 14 days before start date then
1750 -- include those sickness in calculating employer days.
1751
1752 l_loop_empr_days := 0;
1753 l_loop_empr_work_days := 0;
1754 l_loop_start_date := p_abs_start_date ;
1755 FOR i in CSR_CONT_LINK (p_person_id) LOOP
1756
1757 IF ( i.date_start = i.date_end ) THEN
1758
1759 l_loop_empr_days := l_loop_empr_days + 1;
1760 l_duration := 0;
1761 l_include_event := 'N';
1762 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1763 ( p_assignment_id, l_days_or_hours, l_include_event,
1764 i.date_start, i.date_end, l_start_time_char,
1765 l_end_time_char, l_duration
1766 );
1767 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
1768 ELSIF ( l_loop_start_date - i.date_end ) <= p_abs_link_period then
1769 -- Calculate the employer period days in terms of calendar days.
1770 l_duration := 0;
1771 l_duration := (i.date_end - i.date_start) +1;
1772 l_loop_empr_days := (l_loop_empr_days + nvl(l_duration,0));
1773 -- Calculate the employer period days in terms of actual working days.
1774 -- Calling override to get override days and daily rate
1775 l_over_return := get_override_details
1776 ( p_assignment_id,p_effective_date,i.date_start,
1777 i.date_end, p_abs_categorycode, l_cont_start_date,
1778 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
1779 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
1780 );
1781 / Multiple override element attached against one absence element. ie) *
1782 * One or more override entry exists with same start and end date /
1783 IF (l_over_return = -1) THEN
1784 / knelli
1785 IF length(l_msg_error) > 1 THEN
1786 l_msg_error := 'Error5';
1787 END IF;/
1788 l_msg_error := to_char(5);
1789 END IF;
1790 -- If override element exists for the continuous absences then override the work days.
1791 IF l_cont_empr_days IS NULL THEN
1792 l_duration := 0;
1793 l_include_event := 'N';
1794 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1795 ( p_assignment_id, l_days_or_hours, l_include_event,
1796 i.date_start, i.date_end, l_start_time_char,
1797 l_end_time_char, l_duration
1798 );
1799 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
1800 ELSE
1801 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
1802 END IF;
1803 ELSE -- No linking absence exists.
1804 EXIT;
1805 END IF;
1806 l_loop_start_date := i.date_start;
1807 END LOOP;
1808
1809 -- Calculation of employer days if proration was enabled
1810 l_counter := 1;
1811 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
1812 -- It means absences crosses between one payroll period
1813 IF l_counter = 1 THEN
1814 -- Calculating calendar days with prorated period
1815 l_loop_empr_days := nvl(l_loop_empr_days,0) + (i.date_earned - p_abs_start_date)+1;
1816 -- Calculating actual days with prorated period
1817 l_duration := 0;
1818 l_include_event := 'N';
1819 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1820 ( p_assignment_id, l_days_or_hours, l_include_event,
1821 p_abs_start_date, i.date_earned, l_start_time_char,
1822 l_end_time_char, l_duration
1823 );
1824 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
1825 ELSE
1826 -- Calculating calendar days with prorated period
1827 l_loop_empr_days := nvl(l_loop_empr_days,0) + ( i.date_earned - l_prev_paydate);
1828 -- Calculating actual days with prorated period
1829 l_duration := 0;
1830 l_include_event := 'N';
1831 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1832 ( p_assignment_id, l_days_or_hours, l_include_event,
1833 (l_prev_paydate+1), i.date_earned, l_start_time_char,
1834 l_end_time_char, l_duration
1835 );
1836 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
1837 END IF;
1838 l_counter := l_counter + 1;
1839 l_prev_paydate := i.date_earned;
1840 END LOOP;
1841
1842 / knelli added code start /
1843 l_include_event := 'N';
1844 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1845 ( p_assignment_id, l_days_or_hours, l_include_event,
1846 p_prorate_start, p_prorate_end, l_start_time_char,
1847 l_end_time_char, l_duration
1848 );
1849 l_actual_days := l_duration;
1850
1851 IF l_loop_empr_work_days > 0 THEN
1852 l_loop_empr_work_days := l_loop_empr_work_days - l_actual_days;
1853 END IF;
1854 / knelli added code end /
1855
1856 -- Calculation of Employer Days in terms of calendar days
1857 -- If continuous linked cal days exceeds maximum 16 days then for current absence empr period will be 0
1858 / knelli changed check condition
1859 IF l_loop_empr_days >= p_abs_cal_days THEN/
1860 IF l_loop_empr_work_days >= p_abs_work_days THEN
1861 l_empr_days := 0;
1862 l_gen_ss_st_date := p_prorate_start ;
1863 IF l_gen_reimb_ss = 'N' THEN
1864 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1865 END IF;
1866 ELSE
1867 / knelli commented code
1868 IF l_gen_totalabs_days > (p_abs_cal_days - l_loop_empr_days) THEN
1869 -- Absence lies within a payroll period
1870 -- Calculating actual sickness days through work schedule
1871 l_gen_ss_st_date := p_prorate_start + (p_abs_cal_days - l_loop_empr_days);
1872 -- Ignore public holidays if the one present in between absence start and end dates.
1873 l_include_event := 'N';
1874 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1875 ( p_assignment_id, l_days_or_hours, l_include_event,
1876 p_prorate_start, (l_gen_ss_st_date - 1), l_start_time_char,
1877 l_end_time_char, l_duration
1878 );
1879 l_actual_days := l_duration;
1880 ELSE
1881 -- Calculation of Employer Days
1882 -- Absence lies within a payroll period
1883 -- Calculating actual sickness days through work schedule
1884 l_gen_ss_st_date := null;
1885 -- Ignore public holidays if the one present in between absence start and end dates.
1886 l_include_event := 'N';
1887 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1888 ( p_assignment_id, l_days_or_hours, l_include_event,
1889 p_prorate_start, p_prorate_end, l_start_time_char,
1890 l_end_time_char, l_duration
1891 );
1892 l_actual_days := l_duration;
1893 END IF;
1894 /
1895
1896
1897 -- Continuous sickness work days greater than 12 working days so no more empr days will be paid.
1898 IF l_loop_empr_work_days >= p_abs_work_days THEN
1899 l_empr_days := 0;
1900 IF l_gen_reimb_ss = 'N' THEN
1901 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1902 END IF;
1903 ELSE -- Continuous sickness days is less than 12 working days
1904 -- if actual working days > remaning available then social security days will be paid
1905 IF l_actual_days > ( p_abs_work_days - l_loop_empr_work_days ) THEN
1906 l_empr_days := ( p_abs_work_days - l_loop_empr_work_days );
1907 IF l_gen_reimb_ss = 'N' THEN
1908 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1909 END IF;
1910 -- if override employer days is present calculate actual days through continuous linking sickness
1911 -- and then override that with the override days.
1912 IF l_override_empr_days IS NOT NULL THEN
1913 l_empr_days := least(l_override_empr_days, l_empr_days);
1914 END IF;
1915 ELSE
1916 l_empr_days := l_actual_days;
1917 -- if override employer days is present calculate actual days through continuous linking sickness
1918 -- and then override that with the override days.
1919 IF l_override_empr_days IS NOT NULL THEN
1920 l_empr_days := least(l_override_empr_days, l_empr_days);
1921 END IF;
1922 END IF;
1923 END IF;
1924 END IF;
1925 / 5277080 start - Calculate the Social Security Start Date/
1926 l_gen_ss_st_date := p_prorate_start + l_empr_days ;
1927 loop
1928 l_include_event := 'N';
1929 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
1930 ( p_assignment_id, l_days_or_hours, l_include_event,
1931 p_prorate_start, l_gen_ss_st_date, l_start_time_char,
1932 l_end_time_char, l_duration
1933 );
1934
1935 IF l_duration = (l_empr_days +1) THEN
1936 exit;
1937 END IF;
1938 l_gen_ss_st_date := l_gen_ss_st_date + 1;
1939 end loop;
1940 / 5277080 End /
1941
1942 -- CALCULATION OF SOCIAL SECURITY DAYS
1943 -- Calculate social security days if reimburse from social security is set to Yes at any level
1944
1945 IF l_gen_reimb_ss = 'Y' THEN
1946 -- IF social security start date is within the current payroll period then
1947 IF l_gen_ss_st_date >= p_prorate_start and l_gen_ss_st_date <= p_prorate_end then
1948 -- If the 26week rule element input value's start date and end date are set then
1949
1950 IF l_return = 0 THEN
1951 -- If Current absence is within the 26week rule period then throw a warning message
1952 IF l_gen_ss_st_date <= p_dbi_26week_endt AND p_prorate_end >= p_dbi_26week_stdt THEN
1953 l_social_security_days := null;
1954 / knelli
1955 IF length(l_msg_error) > 1 THEN
1956 l_msg_error := 'Error9';
1957 END IF;/
1958 l_msg_error := to_char(9);
1959
1960 --Throw warning message that no social security days will be paid due to 26week rule.
1961 ELSE
1962 p_work_pattern := '5DAY';
1963 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1964 -- if exempt from employer period id set to no
1965 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1966 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1967 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1968 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1969 ELSE
1970 l_social_security_days := l_duration;
1971 END IF;
1972 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1973 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1974 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1975 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1976 ELSE -- user can avail the actual ss days as it is within 260 limit
1977 l_social_security_days := l_duration;
1978 END IF;
1979 END IF; -- l_gen_exempt_empr = 'N'
1980 END IF; -- Current absence is beyond the 26week rule period
1981
1982 ELSE -- 26week rule element not attached to this assignment
1983 p_work_pattern := '5DAY';
1984 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
1985 -- if exempt from employer period id set to no
1986 IF l_gen_exempt_empr = 'N' THEN -- 248 days
1987 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
1988 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
1989 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1990 ELSE
1991 l_social_security_days := l_duration;
1992 END IF;
1993 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
1994 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
1995 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
1996 l_msg_error := to_char(12); / Legislative limit exhausted Message /
1997 ELSE -- user can avail the actual ss days as it is within 260 limit
1998 l_social_security_days := l_duration;
1999 END IF;
2000 END IF; -- l_gen_exempt_empr = 'N'
2001 END IF; -- If the 26week rule element input value's start date and end date are set then
2002 ELSE
2003 l_social_security_days := 0;
2004 END IF; -- IF social security start date is within the absence period or prorated period then
2005
2006 END IF; --Calculate social security days if reimburse from social security is set to Yes at any level
2007 -- if override social security days is present calculate actual days with the override days.
2008 IF l_override_ss_days IS NOT NULL THEN
2009 l_social_security_days := least(l_override_ss_days, l_social_security_days);
2010 END IF;
2011
2012 -- If social security days availed from this absence exeeecs 220 days then a warning message should be thrown.
2013 IF ( nvl(l_social_security_days,0) + nvl(p_3years_paybase,0) ) > 220 THEN
2014 / knelli
2015 IF length(l_msg_error) > 1 THEN
2016 l_msg_error := 'Error6';
2017 END IF;/
2018 l_msg_error := to_char(6);
2019
2020 END IF;
2021 END IF; -- Prorated Absences calculation ends
2022 END IF; -- Outer if - identifying absence st and end both lies inside payroll period
2023 ====================================================================================================*/
2024 /* calculating employer days and Social Security days based on the Total Calender days.
2025 First 16 cal days are consider as a employer days remaining day are social security days*/
2026 IF p_sickbal_total_caldays >= p_abs_cal_days THEN
2027 l_empr_days := 0;
2028 l_gen_ss_st_date := p_prorate_start ;
2029 IF l_gen_reimb_ss = 'N' THEN
2030 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2031 END IF;
2032 ELSE
2033 l_emp_end_date := p_prorate_start + (p_abs_cal_days - p_sickbal_total_caldays) - 1 ;
2034 l_gen_ss_st_date := p_prorate_start + (p_abs_cal_days - p_sickbal_total_caldays);
2035
2036 IF l_emp_end_date >= p_prorate_end THEN
2037 l_emp_end_date := p_prorate_end ;
2038 ELSE
2039 IF l_gen_reimb_ss = 'N' THEN
2040 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2041 END IF;
2042 END IF;
2043
2044 -- Ignore public holidays if the one present in between absence start and end dates.
2045 l_include_event := 'N';
2046 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2047 ( p_assignment_id, l_days_or_hours, l_include_event,
2048 p_prorate_start, l_emp_end_date, l_start_time_char,
2049 l_end_time_char, l_duration
2050 );
2051 l_empr_days := l_duration;
2052 /*IF l_override_empr_days IS NOT NULL THEN
2053 /l_empr_days := least(l_override_empr_days, l_empr_days); 5380130/
2054 l_empr_days := l_override_empr_days;
2055 END IF;*/
2056 END IF;
2057
2058
2059 -- CALCULATION OF SOCIAL SECURITY DAYS
2060 -- Calculate social security days if reimburse from social security is set to Yes at any level
2061 IF l_gen_reimb_ss = 'Y' THEN
2062 -- IF social security start date is within the current payroll period then
2063 IF l_gen_ss_st_date >= p_prorate_start and l_gen_ss_st_date <= p_prorate_end then
2064 -- If the 26week rule element input value's start date and end date are set then
2065 IF l_return = 0 THEN
2066 -- If Current absence is withing the 26week rule period then throw a warning message
2067 IF l_gen_ss_st_date <= p_dbi_26week_endt AND p_prorate_end >= p_dbi_26week_stdt THEN
2068 l_social_security_days := null;
2069 l_msg_error := to_char(9);
2070 --Throw warning message that no social security days will be paid due to 26week rule.
2071 ELSE
2072 p_work_pattern := '5DAY';
2073 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
2074 -- if exempt from employer period id set to no
2075 IF l_gen_exempt_empr = 'N' THEN -- 248 days
2076 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
2077 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
2078 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2079 ELSE
2080 l_social_security_days := l_duration;
2081 END IF;
2082 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
2083 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
2084 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
2085 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2086 ELSE -- user can avail the actual ss days as it is within 260 limit
2087 l_social_security_days := l_duration;
2088 END IF;
2089 END IF; -- l_gen_exempt_empr = 'N'
2090 END IF; -- Current absence is beyond the 26week rule period
2091
2092 ELSE -- 26week rule element not attached to this assignment
2093 p_work_pattern := '5DAY';
2094 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
2095 -- if exempt from employer period id set to no
2096 IF l_gen_exempt_empr = 'N' THEN -- 248 days
2097 IF l_duration > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0)) THEN
2098 l_social_security_days := ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0));
2099 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2100 ELSE
2101 l_social_security_days := l_duration;
2102 END IF;
2103 ELSE -- Exempt from employer period is set to yes ie) eligible for 260 days
2104 IF l_duration > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
2105 l_social_security_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
2106 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2107 ELSE -- user can avail the actual ss days as it is within 260 limit
2108 l_social_security_days := l_duration;
2109 END IF;
2110
2111 END IF; -- l_gen_exempt_empr = 'N'
2112 END IF; -- If the 26week rule element input value's start date and end date are set then
2113 ELSE
2114 l_social_security_days := 0;
2115 END IF; -- IF social security start date is within the absence period or prorated period then
2116 END IF; --Calculate social security days if reimburse from social security is set to Yes at any level
2117
2118 -- if override social security days is present calculate actual days with the override days.
2119 /*IF l_override_ss_days IS NOT NULL THEN
2120 /l_social_security_days := least(l_override_ss_days, l_social_security_days); 5380130 /
2121 l_social_security_days := l_override_ss_days;
2122 END IF;*/
2123 IF l_social_security_days < 0 THEN
2124 l_social_security_days := 0 ;
2125 END IF;
2126 -- If social security days availed from this absence exeeecs 220 days then a warning message should be thrown.
2127 IF (( nvl(l_social_security_days,0) + nvl(p_3years_paybase,0) ) > 220 ) AND
2128 (l_msg_error is NULL or l_msg_error <> '12') THEN
2129 l_msg_error := to_char(6);
2130 END IF;
2131
2132
2133 -- Calculated result are assigned to output variables except daily rate
2134 p_abs_empr_days := nvl(l_empr_days,0) ;
2135 p_abs_ss_days := nvl(l_social_security_days,0) ;
2136 p_abs_total_days := (p_abs_empr_days + p_abs_ss_days);
2137 p_rec_empr_days := nvl(l_empr_days,0) ;
2138 p_rec_ss_days := nvl(l_social_security_days,0) ;
2139 p_rec_total_days := (p_rec_empr_days + p_rec_ss_days);
2140
2141 OPEN csr_get_intial_sick_abs_st_dt(to_char(p_abs_attendance_id));
2142 FETCH csr_get_intial_sick_abs_st_dt INTO l_initial_abs_st_date;
2143 CLOSE csr_get_intial_sick_abs_st_dt;
2144
2145 --OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date); /* 5762854 pass the current absence start date */
2146 OPEN csr_intial_abs_pay_stdt(p_assignment_id,p_abs_start_date);
2147 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
2148 CLOSE csr_intial_abs_pay_stdt;
2149
2150 -- Get the daily rate value
2151 -- Calculation of G rate
2152
2153 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
2154 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
2155
2156 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
2157 --l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id); /* 5762854 pass the current absence start date */
2158 l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
2159 /* End Bug Fix : 5380121 */
2160
2161 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
2162 IF l_gen_hour_sal = 'S' THEN
2163
2164 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
2165 (p_assignment_id, p_effective_date, 'Contractual Earnings',
2166 'R', 'D', l_rate, l_error_message, null, null);*/
2167
2168 /*pgopal - Bug 5441078 fix - Passing absence start date*/
2169 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
2170 (p_assignment_id, p_abs_start_date, 'Contractual Earnings',
2171 'R', 'D', l_rate, l_error_message, null, null);
2172
2173 -- Override social security date was present.
2174 IF l_override_ss_rate IS NOT NULL THEN
2175 l_social_security_rate := l_override_ss_rate;
2176 ELSE
2177 l_social_security_rate := l_rate;
2178 END IF;
2179 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
2180 IF l_gen_restrict_ss_sl = 'Y' THEN
2181 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
2182 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
2183 END IF;
2184 END IF;
2185 -- if restrict daily rate to social security is not set then
2186 IF l_gen_restrict_dr_ss = 'N' THEN
2187 -- (absence pay base * 12) / 260;
2188 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
2189 -- if override employer daily rate was present then take that for sick pay.
2190 IF l_override_empr_rate IS NOT NULL THEN
2191 l_empr_daily_rate := l_override_empr_rate ;
2192 END IF;
2193 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
2194 IF l_gen_restrict_empr_sl = 'Y' THEN
2195 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
2196 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
2197 END IF;
2198 END IF;
2199
2200 -- if restrict daily rate to social security is no then pick whichever is
2201 -- less between historic and daily rate.
2202 IF l_social_security_rate > l_empr_daily_rate THEN
2203 l_reclaim_daily_rate := l_empr_daily_rate;
2204 ELSE
2205 l_reclaim_daily_rate := l_social_security_rate;
2206 END IF;
2207 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
2208 ELSE
2209 l_empr_daily_rate := l_social_security_rate;
2210 l_reclaim_daily_rate := l_social_security_rate;
2211
2212 IF l_override_empr_rate IS NOT NULL THEN
2213 l_empr_daily_rate := l_override_empr_rate ;
2214 END IF;
2215 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
2216 IF l_gen_restrict_empr_sl = 'Y' THEN
2217 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
2218 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
2219 END IF;
2220 END IF;
2221 END IF;
2222
2223 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
2224 ELSIF l_gen_hour_sal = 'H' THEN
2225 p_ear_value := 0;
2226 IF p_hourly_paid IN ('W', 'B') THEN
2227 -- Ignore public holidays if the one present in between absence start and end dates.
2228 l_include_event := 'Y';
2229 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
2230 /* pgopal - Bug 5393827 and 5349713 fix - taking the absence start date instead
2231 of payroll start date to get the last 4 weeks worked days*/
2232 /* condition added by pdavidra for Bug 5330188*/
2233 /*5475038 IF (l_abs_reason = 'Work Accident') AND
2234 ( (p_abs_start_date - p_abs_min_gap) < l_dateofjoin ) THEN
2235 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2236 ( p_assignment_id, l_days_or_hours, l_include_event,
2237 l_dateofjoin, (p_abs_start_date-1), l_start_time_char,
2238 l_end_time_char, l_duration
2239 );
2240 ELSE
2241 / pdavidra - bug 5330066 - redused the start date parameter by 1/
2242 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2243 ( p_assignment_id, l_days_or_hours, l_include_event,
2244 (p_abs_start_date - p_abs_min_gap), (p_abs_start_date-1), l_start_time_char,
2245 l_end_time_char, l_duration
2246 );
2247 END IF; */
2248 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2249 ( p_assignment_id, l_days_or_hours, l_include_event,
2250 greatest(l_dateofjoin,((l_initial_abs_pay_stdt) - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
2251 l_end_time_char, l_duration
2252 );
2253 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
2254 BEGIN
2255 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
2256 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
2257 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
2258 ( (l_initial_abs_pay_stdt-1) - date_start )+1
2259 WHEN date_end = date_start THEN
2260 1
2261 ELSE (date_end - date_start) + 1 END ) AS Days_diff
2262 INTO l_abs_worked_days
2263 FROM per_absence_attendances
2264 WHERE person_id = p_person_id
2265 AND date_start < (l_initial_abs_pay_stdt-1)
2266 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
2267 AND date_start IS NOT NULL
2268 AND date_end IS NOT NULL ;
2269 EXCEPTION
2270 WHEN NO_DATA_FOUND THEN
2271 l_abs_worked_days := 0;
2272 WHEN OTHERS THEN
2273 l_abs_worked_days := 0;
2274 END;
2275
2276 l_duration := l_duration - nvl(l_abs_worked_days, 0);
2277
2278 /* Bug Fix 5263714 added check condition */
2279 IF l_duration > 0 THEN
2280 l_social_security_rate := ( p_4weeks_paybase / l_duration);
2281 ELSE
2282 l_social_security_rate := 0;
2283 END IF;
2284 -- Override social security date was present.
2285 IF l_override_ss_rate IS NOT NULL THEN
2286 l_social_security_rate := l_override_ss_rate;
2287 END IF;
2288 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
2289 IF l_gen_restrict_ss_sl = 'Y' THEN
2290 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
2291 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
2292 END IF;
2293 END IF;
2294
2295 -- if override employer daily rate was present then take that for sick pay.
2296 IF l_override_empr_rate IS NOT NULL THEN
2297 l_empr_daily_rate := l_override_empr_rate ;
2298 ELSE
2299 l_empr_daily_rate := l_social_security_rate;
2300 END IF;
2301
2302 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
2303 IF l_gen_restrict_empr_sl = 'Y' THEN
2304 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
2305 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
2306 END IF;
2307 END IF;
2308
2309 l_reclaim_daily_rate := l_social_security_rate;
2310
2311 ELSIF p_hourly_paid = 'M' THEN
2312 /* knelli
2313 IF length(l_msg_error) > 1 THEN
2314 l_msg_error := 'Error7';
2315 END IF;*/
2316 l_msg_error := to_char(7);
2317 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
2318 -- Previous 4 weeks period logic will not work.
2319 END IF;
2320 END IF;
2321
2322 IF l_abs_category_code = 'PTS' THEN
2323 p_abs_daily_rate := l_empr_daily_rate * (nvl(l_abs_pts_percent,0)/100);
2324 p_ss_daily_rate := l_social_security_rate * (nvl(l_abs_pts_percent,0)/100);
2325 ELSE
2326 p_abs_daily_rate := nvl(l_empr_daily_rate,0);
2327 p_ss_daily_rate := nvl(l_social_security_rate,0);
2328
2329 END IF;
2330 -- If reclaimable daily rate is set on override element then use the value to reclaim
2331 -- from social security else use social security rate calculated.
2332 IF l_override_reclaim_rate IS NOT NULL THEN
2333 p_rec_daily_rate := l_override_reclaim_rate;
2334 ELSE
2335 p_rec_daily_rate := p_ss_daily_rate;
2336 END IF;
2337
2338 -- Calculate Employer and social security periods
2339 -- If exempt from employer is set and reimburse from social security is not set
2340 -- then 12 working days are allowed to be paid and reimbursed
2341 IF l_gen_exempt_empr = 'Y' AND l_gen_reimb_ss = 'N' THEN
2342 /*pdavidra 5330536 - if Exempt empr is Y, all absence days should be consider as a SS days
2343 and reimp_ss is N, max 12 working days are allowed to paid and reimbursed
2344 p_abs_empr_days := nvl(l_empr_days,0);
2345 p_abs_ss_days := 0;*/
2346 p_abs_empr_days := 0;
2347 p_abs_ss_days := nvl(l_empr_days,0);
2348 p_abs_total_days := (p_abs_empr_days + p_abs_ss_days) ;
2349
2350 p_rec_empr_days := p_abs_empr_days ;
2351 p_rec_ss_days := p_abs_ss_days ;
2352 p_rec_total_days := (p_rec_empr_days + p_rec_ss_days);
2353 END IF;
2354 IF l_gen_exempt_empr = 'Y' AND l_gen_reimb_ss = 'Y' THEN
2355 /*pdavidra 5330536 - if Exempt empr is Y, all absence days should be consider as a SS days
2356 and reimp_ss is Y, max 12 + 248 working days are allowed to paid and reimbursed*/
2357 p_abs_empr_days := 0;
2358 p_abs_ss_days := nvl(l_empr_days,0) + nvl(p_abs_ss_days,0);
2359 IF p_abs_ss_days > (p_abs_annual_days - nvl(p_3years_paybase,0)) THEN
2360 p_abs_ss_days := (p_abs_annual_days - nvl(p_3years_paybase,0));
2361 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2362 END IF;
2363 p_abs_total_days := (p_abs_empr_days + p_abs_ss_days) ;
2364 END IF;
2365 -- If exempt from employer is not set and reimburse from social security is not set
2366 -- then 16 calendar days are allowed to be paid including continuous linking sick period.
2367 IF l_gen_exempt_empr = 'N' AND l_gen_reimb_ss = 'N' THEN
2368 p_abs_empr_days := nvl(l_empr_days,0);
2369 p_abs_ss_days := 0;
2370 p_abs_total_days := (p_abs_empr_days + p_abs_ss_days) ;
2371
2372 p_rec_empr_days := 0 ;
2373 p_rec_ss_days := 0 ;
2374 p_rec_total_days := (p_rec_empr_days + p_rec_ss_days);
2375 -- p_rec_daily_rate := 0;
2376 -- p_ss_daily_rate := 0;
2377 END IF;
2378
2379 IF l_override_empr_days IS NOT NULL THEN
2380 p_abs_empr_days := l_override_empr_days;
2381 p_abs_total_days := (nvl(p_abs_empr_days,0) + nvl(p_abs_ss_days,0)) ;
2382 END IF;
2383 -- if override social security days is present calculate actual days with the override days.
2384 IF l_override_ss_days IS NOT NULL THEN
2385 p_abs_ss_days := l_override_ss_days;
2386 p_abs_total_days := (nvl(p_abs_empr_days,0) + nvl(p_abs_ss_days,0)) ;
2387 IF ( (nvl(p_abs_ss_days,0) + nvl(p_3years_paybase,0)) > 220 ) AND (l_msg_error is NULL or l_msg_error <> '12') THEN
2388 l_msg_error := to_char(6);
2389 END IF;
2390 END IF;
2391 IF (l_gen_exempt_empr = 'N' AND l_gen_reimb_ss = 'N' AND nvl(p_abs_ss_days,0) > 0 ) OR
2392 (l_gen_exempt_empr = 'Y' AND l_gen_reimb_ss = 'N' AND nvl(p_abs_empr_days,0) > 0 ) OR
2393 (l_gen_exempt_empr = 'Y' AND l_gen_reimb_ss = 'Y' AND (nvl(p_abs_ss_days,0) > (p_abs_annual_days - nvl(p_3years_paybase,0))) ) OR
2394 (l_gen_exempt_empr = 'N' AND l_gen_reimb_ss = 'Y' AND (nvl(p_abs_ss_days,0) > ((p_abs_annual_days - p_abs_work_days) - nvl(p_3years_paybase,0))) ) THEN
2395 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
2396 END IF;
2397
2398 IF l_gen_rate_option = 'DRATE_OPT1' THEN
2399 p_rate_option1 := 'Y';
2400 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
2401 p_rate_option2 := 'Y';
2402 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
2403 p_rate_option3 := 'Y';
2404 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
2405 p_rate_option4 := 'Y';
2406 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
2407 p_rate_option5 := 'Y';
2408 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
2409 p_rate_option6 := 'Y';
2410 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
2411 p_rate_option7 := 'Y';
2412 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
2413 p_rate_option8 := 'Y';
2414 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
2415 p_rate_option9 := 'Y';
2416 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
2417 p_rate_option10 := 'Y';
2418 ELSE
2419 p_rate_option1 := null;
2420 p_rate_option2 := null;
2421 p_rate_option3 := null;
2422 p_rate_option4 := null;
2423 p_rate_option5 := null;
2424 p_rate_option6 := null;
2425 p_rate_option7 := null;
2426 p_rate_option8 := null;
2427 p_rate_option9 := null;
2428 p_rate_option10 := null;
2429 -- If calculated employer daily rate is less than 50% of G daily rate then no social security period will be paid.
2430 IF l_abs_category_code = 'PTS' THEN
2431 IF p_abs_daily_rate < ( ((l_g_rate / p_abs_annual_days) / 2) * (nvl(l_abs_pts_percent,0)/100) ) THEN
2432 --Employers period alone can be paid. No social security period will be paid.
2433 p_rec_empr_days := 0;
2434 p_rec_ss_days := 0;
2435 p_rec_total_days := 0;
2436 p_rec_daily_rate := 0;
2437 p_ss_daily_rate := 0;
2438 IF p_abs_ss_days > 0 then
2439 l_msg_error := to_char(11); /* 50% G Message */
2440 END IF;
2441 p_abs_ss_days := 0;
2442 p_abs_total_days := (nvl(p_abs_empr_days,0) + nvl(p_abs_ss_days,0)) ;
2443 END IF;
2444 ELSE
2445 IF p_abs_daily_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
2446 --Employers period alone can be paid. No social security period will be paid.
2447 p_rec_empr_days := 0;
2448 p_rec_ss_days := 0;
2449 p_rec_total_days := 0;
2450 p_rec_daily_rate := 0;
2451 p_ss_daily_rate := 0;
2452 IF p_abs_ss_days > 0 then
2453 l_msg_error := to_char(11); /* 50% G Message */
2454 END IF;
2455 p_abs_ss_days := 0;
2456 p_abs_total_days := (nvl(p_abs_empr_days,0) + nvl(p_abs_ss_days,0)) ;
2457 END IF;
2458 END IF;
2459 END IF;
2460
2461 p_abs_error := l_msg_error ;
2462
2463 /*****************************************************************************
2464 CHILD MINDER'S SICKNESS ABSENCE CATEGORY
2465 *****************************************************************************/
2466
2467 ELSIF l_abs_category_code = 'CMS' THEN
2468
2469 -- Fetch EIT values from absence payment details form
2470 BEGIN
2471 SELECT PAA.ABS_INFORMATION1 AS Cert_type
2472 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Cert_stdt
2473 ,to_date(PAA.ABS_INFORMATION3,'yyyy/mm/dd hh24:mi:ss') AS Cert_endt
2474 ,PAA.ABS_INFORMATION4 AS reimb_ss
2475 ,PAA.ABS_INFORMATION5 AS dailyrate_ss
2476 ,PAA.ABS_INFORMATION6 AS employer_6g
2477 ,PAA.ABS_INFORMATION7 AS socialsec_6g
2478 ,PAA.ABS_INFORMATION8 AS Daily_rate
2479 INTO l_cert_type
2480 ,l_cert_stdt
2481 ,l_cert_endt
2482 ,l_abs_reimb_ss
2483 ,l_abs_restrict_dr_ss
2484 ,l_abs_restrict_empr_sl
2485 ,l_abs_restrict_ss_sl
2486 ,l_abs_daily_rate
2487 FROM PER_ABSENCE_ATTENDANCES PAA
2488 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
2489 EXCEPTION
2490 WHEN OTHERS THEN
2491 l_cert_type := null;
2492 l_cert_stdt := null;
2493 l_cert_endt := null;
2494 l_abs_reimb_ss := null;
2495 l_abs_restrict_dr_ss := null;
2496 l_abs_restrict_empr_sl := null;
2497 l_abs_restrict_ss_sl := null;
2498 l_abs_daily_rate := null;
2499 END;
2500 /* Identifying the input values based on the Priority levels. If none of the level has been
2501 set then default value will be assigned. Refer mail dated 20th Feb 06 from Borge.*/
2502 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
2503 l_gen_entitled_sc := nvl(nvl(l_entitled_sc, l_le_entitled_sc), 'Y');
2504 l_gen_exempt_empr := nvl(nvl(l_exempt_empr, l_le_exempt_empr), 'N');
2505 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
2506 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
2507 l_gen_restrict_empr_sl := nvl(nvl(nvl(l_abs_restrict_empr_sl, l_restrict_empr_sl), l_le_restrict_empr_sl), 'Y');
2508 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_abs_restrict_ss_sl, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
2509 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
2510 /* This Message has been handled at Absence Recording Level itself
2511 -- Entitled to self certificate is set to no with self certificate has chosen then a warning message should be generated
2512 IF l_gen_entitled_sc = 'N' AND l_cert_type = 'SC' THEN
2513 / knelli
2514 IF length(l_msg_error) > 1 THEN
2515 l_msg_error := 'Error7';
2516 END IF;/
2517 l_msg_error := to_char(7);
2518 END IF;*/
2519
2520 -- Condition 1. First sick is allowed after 28 days of Join.
2521 /*5475038 - This message has been moved to recording level
2522 l_dateofjoin_28 := l_dateofjoin + p_abs_min_gap ;
2523 BEGIN
2524 /pdavidra - bug no 5330109 - Unauthorised absence count should be taken
2525 form DOJ to current absence date
2526 instead of DOJ to DOJ+28 days.
2527 SELECT SUM ( CASE WHEN PAA.DATE_END > l_dateofjoin_28 THEN
2528 ( l_dateofjoin_28 - PAA.DATE_START)
2529 WHEN PAA.DATE_START = PAA.DATE_END THEN
2530 1
2531 ELSE (PAA.DATE_END - PAA.DATE_START) END ) AS DAYS
2532 INTO l_abs_unauthor
2533 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
2534 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
2535 AND PAT.ABSENCE_CATEGORY = 'UN'
2536 AND PAA.DATE_START <= l_dateofjoin_28
2537 AND PAA.DATE_END >= l_dateofjoin
2538 AND PAA.DATE_START IS NOT NULL
2539 AND PAA.DATE_END IS NOT NULL
2540 AND PAA.PERSON_ID = p_person_id;/
2541 SELECT SUM ( CASE WHEN PAA.DATE_END > (p_abs_start_date-1) THEN
2542 ( (p_abs_start_date-1) - PAA.DATE_START) + 1
2543 WHEN PAA.DATE_START = PAA.DATE_END THEN
2544 1
2545 ELSE (PAA.DATE_END - PAA.DATE_START) + 1 END ) AS DAYS
2546 INTO l_abs_unauthor
2547 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
2548 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
2549 AND PAT.ABSENCE_CATEGORY = 'UN'
2550 AND PAA.DATE_START <= (p_abs_start_date-1)
2551 AND PAA.DATE_END >= l_dateofjoin
2552 AND PAA.DATE_START IS NOT NULL
2553 AND PAA.DATE_END IS NOT NULL
2554 AND PAA.PERSON_ID = p_person_id;
2555 EXCEPTION
2556 WHEN OTHERS THEN
2557 l_abs_unauthor := 0;
2558 END;
2559
2560 IF ( p_abs_start_date - l_dateofjoin ) < (p_abs_min_gap + nvl(l_abs_unauthor,0) ) THEN
2561 / knelli
2562 IF length(l_msg_error) > 1 THEN
2563 l_msg_error := 'Error3';
2564 END IF;/
2565 l_msg_error := to_char(3);
2566 END IF;
2567
2568 -- Condition 2. Minimum 28 days employment is required to avail Child Minder Sick pay except sickness or holiday
2569 -- within 28 days from start of the current absence. If any other absence exists with more than
2570 -- 14 days within 28 days then no Child Minder Sickness will be paid.
2571 BEGIN
2572 SELECT COUNT(1)
2573 INTO l_abs_count
2574 FROM PER_ABSENCE_ATTENDANCES PAA, PER_ABSENCE_ATTENDANCE_TYPES PAT
2575 WHERE PAA.ABSENCE_ATTENDANCE_TYPE_ID = PAT.ABSENCE_ATTENDANCE_TYPE_ID
2576 AND PAT.ABSENCE_CATEGORY IN ( 'S','PTS','PA','PTP','M','PTM','IE_AL','PTA' )
2577 AND PAA.DATE_END BETWEEN (p_abs_start_date - (p_abs_min_gap+1)) AND p_abs_start_date
2578 AND ( PAA.DATE_END - PAA.DATE_START ) > p_abs_link_period
2579 AND PAA.DATE_START IS NOT NULL
2580 AND PAA.DATE_END IS NOT NULL
2581 AND PAA.PERSON_ID = p_person_id;
2582 EXCEPTION
2583 WHEN OTHERS THEN
2584 l_abs_count := 0;
2585 END;
2586
2587 -- There are Child Minder sickness exists within 28days of current Child Minder sickness start date with more than 14 days
2588 -- except absence categories Sickness, Part-time sickness and Vacation.
2589 IF l_abs_count > 0 THEN
2590 / knelli
2591 IF length(l_msg_error) > 1 THEN
2592 l_msg_error := 'Error4';
2593 END IF;/
2594 l_msg_error := to_char(4);
2595 END IF; */
2596
2597 -- Calling override to get override days and daily rate
2598 l_over_return := get_override_details
2599 ( p_assignment_id,p_effective_date,p_abs_start_date,
2600 p_abs_end_date, p_abs_categorycode, l_override_start_date,
2601 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
2602 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
2603 );
2604
2605 /* Multiple override element attached against one absence element. ie) *
2606 * One or more override entry exists with same start and end date */
2607 IF (l_over_return = -1) THEN
2608 /* knelli
2609 IF length(l_msg_error) > 1 THEN
2610 l_msg_error := 'Error5';
2611 END IF;*/
2612 l_msg_error := to_char(5);
2613 p_abs_error := l_msg_error;
2614 RETURN 1;
2615 END IF;
2616 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
2617 l_msg_error := to_char(13);
2618 END IF;
2619 l_include_event := 'N';
2620 -- Calculating actual sickness days through work schedule
2621 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2622 ( p_assignment_id, l_days_or_hours, l_include_event,
2623 p_prorate_start, p_prorate_end, l_start_time_char,
2624 l_end_time_char, l_duration
2625 );
2626
2627 l_actual_cal_days := nvl(l_duration,0);
2628 -- Calculate Earnings Adjustment value
2629 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
2630 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * l_actual_cal_days;
2631 p_ear_startdt := p_prorate_start;
2632 p_ear_enddt := p_prorate_end;
2633 p_ear_value := nvl(p_ear_value,0);
2634
2635 -- To get slab values for child minder sickness.
2636 -- One child with less than 13 years of age.
2637 l_child_1_13 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2638 'NO_CHILDMINDER_SICK_DURATION','Duration','A');
2639
2640
2641 -- Two children with less than 13 years of age.
2642 l_child_2_13 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2643 'NO_CHILDMINDER_SICK_DURATION','Duration','B');
2644
2645
2646 -- More than One child with less than 19 years of age.
2647 l_child_1_19 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2648 'NO_CHILDMINDER_SICK_DURATION','Duration','C');
2649
2650
2651 -- One Sole Guardian child with less than 13 years of age.
2652 l_childsg_1_13 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2653 'NO_CHILDMINDER_SICK_DURATION','Duration','A_SG');
2654
2655
2656 -- Two Sole Guardian children with less than 13 years of age.
2657 l_childsg_2_13 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2658 'NO_CHILDMINDER_SICK_DURATION','Duration','B_SG');
2659
2660
2661 -- More than One Sole Guardian child with less than 19 years of age.
2662 l_childsg_1_19 := PAY_NO_ABSENCE.GET_USERTABLE (p_effective_date, p_business_group_id,
2663 'NO_CHILDMINDER_SICK_DURATION','Duration','C_SG');
2664
2665
2666 -- Calculate total absence days
2667 l_gen_totalabs_days := (p_abs_end_date - p_abs_start_date ) + 1;
2668 -- Calculate total prorated day(s) of the current payroll
2669 l_gen_pro_days := (p_prorate_end - p_prorate_start ) + 1;
2670 -- Calculate Employer's period start date
2671 l_gen_empr_st_date := p_prorate_start;
2672
2673 -- To fetch previous employment's child minder sickness value
2674 OPEN child_prev_emp (p_person_id, p_abs_start_date);
2675 FETCH child_prev_emp INTO l_child_prev_stdt, l_child_prev_endt, l_child_prev_value;
2676 CLOSE child_prev_emp;
2677 l_child_cnt_ab := 0;
2678 l_child_cnt_c := 0;
2679 l_child_cnt_sgab := 0;
2680 l_child_cnt_sgc := 0;
2681 -- To fetch dependent child information
2682 FOR I IN child_contact ( p_person_id, 'DC', p_abs_start_date )
2683 LOOP
2684
2685
2686 /* knelli commented code
2687 IF I.AGE < 13 AND i.CONT_INFORMATION1 = 'N' AND i.CONT_INFORMATION2 = 'N' THEN
2688 l_child_cnt_ab := l_child_cnt_ab + 1;
2689 -- 1+ child exists with < 19 years with chronic as Yes and Sole guardian as No
2690 ELSIF I.AGE < 19 AND i.CONT_INFORMATION1 = 'Y' AND i.CONT_INFORMATION2 = 'N' THEN
2691 l_child_cnt_c := l_child_cnt_c + 1;
2692 -- 1 or 2 child exists with < 13 years with chronic as No and Sole guardian as Yes
2693 ELSIF I.AGE < 13 AND i.CONT_INFORMATION1 = 'N' AND i.CONT_INFORMATION2 = 'Y' THEN
2694 l_child_cnt_sgab := l_child_cnt_sgab + 1;
2695 -- 1+ child exists with < 19 years with chronic as Yes and Sole guardian as Yes
2696 ELSIF I.AGE < 19 AND i.CONT_INFORMATION1 = 'Y' AND i.CONT_INFORMATION2 = 'Y' THEN
2697 l_child_cnt_sgc := l_child_cnt_sgc + 1;
2698 END IF:
2699 commnted code ends here */
2700
2701 /*knelli changed code */
2702
2703 i.CONT_INFORMATION1 := nvl(i.CONT_INFORMATION1,'N');
2704 i.CONT_INFORMATION2 := nvl(i.CONT_INFORMATION2,'N');
2705
2706 IF I.AGE < 13 AND i.CONT_INFORMATION1 = 'N' AND i.CONT_INFORMATION2 = 'N' THEN
2707 l_child_cnt_ab := l_child_cnt_ab + 1;
2708 -- 1+ child exists with < 19 years with chronic as Yes and Sole guardian as No
2709 ELSIF I.AGE < 19 AND i.CONT_INFORMATION1 = 'N' AND i.CONT_INFORMATION2 = 'Y' THEN
2710 l_child_cnt_c := l_child_cnt_c + 1;
2711 -- 1 or 2 child exists with < 13 years with chronic as No and Sole guardian as Yes
2712 ELSIF I.AGE < 13 AND i.CONT_INFORMATION1 = 'Y' AND i.CONT_INFORMATION2 = 'N' THEN
2713 l_child_cnt_sgab := l_child_cnt_sgab + 1;
2714 -- 1+ child exists with < 19 years with chronic as Yes and Sole guardian as Yes
2715 ELSIF I.AGE < 19 AND i.CONT_INFORMATION1 = 'Y' AND i.CONT_INFORMATION2 = 'Y' THEN
2716 l_child_cnt_sgc := l_child_cnt_sgc + 1;
2717 END IF;
2718 END LOOP;
2719 /* pdavidra 5360031 - The highest eligibility limit of multiple options/combinations should be considered
2720 -- To identify the maximum limit
2721 IF l_child_cnt_ab = 1 THEN
2722 l_gen_child_limit := l_child_1_13;
2723 ELSIF l_child_cnt_ab >= 2 THEN / knelli changed from = 2 /
2724 l_gen_child_limit := l_child_2_13;
2725 ELSIF l_child_cnt_c >= 1 THEN / knelli changed from > to >= /
2726 l_gen_child_limit := l_child_1_19;
2727 ELSIF l_child_cnt_sgab = 1 THEN
2728 l_gen_child_limit := l_childsg_1_13;
2729 ELSIF l_child_cnt_sgab >= 2 THEN / knelli changed from = 2 /
2730 l_gen_child_limit := l_childsg_2_13;
2731 ELSIF l_child_cnt_sgc >= 1 THEN / knelli changed from > 1 /
2732 l_gen_child_limit := l_childsg_1_19;
2733 ELSE
2734 l_gen_child_limit := 0;
2735 /l_gen_child_limit := l_child_1_13; knelli changed to l_child_1_13 from 0 , but check/
2736 END IF; */
2737 -- To identify the maximum limit
2738
2739 l_gen_child_limit := 0;
2740 IF l_child_cnt_ab = 1 THEN
2741 l_gen_child_limit := l_child_1_13;
2742 END IF;
2743 IF l_child_cnt_ab >= 2 THEN
2744 l_gen_child_limit := l_child_2_13;
2745 END IF;
2746 IF l_child_cnt_c >= 1 THEN
2747 l_gen_child_limit := l_child_1_19;
2748 END IF;
2749 IF l_child_cnt_sgab = 1 THEN
2750 l_gen_child_limit := l_childsg_1_13;
2751 END IF;
2752 IF l_child_cnt_sgab >= 2 THEN
2753 l_gen_child_limit := l_childsg_2_13;
2754 END IF;
2755 IF l_child_cnt_sgc >= 1 THEN
2756 l_gen_child_limit := l_childsg_1_19;
2757 END IF;
2758
2759 -- If no record exists with dependent child status then throw an error.
2760 IF l_gen_child_limit = 0 THEN
2761 /* knelli commented code */
2762 /*IF length(l_msg_error) > 1 THEN
2763 l_msg_error := 'Error10';
2764 END IF;*/
2765 /* knelli added code */
2766 l_msg_error := to_char(10);
2767 p_abs_error := l_msg_error;
2768 RETURN 1;
2769
2770 END IF;
2771
2772 --=========================================================================================================================
2773 --5392465 and 5360031 Taking the Employer / Social Security days from Balance (ASG_YTD)
2774 --instead of calculating full employee period
2775 -- Implementation of top logic to calculate actual days using proration and finding
2776 -- the continuous linking period.
2777 /* IF p_abs_start_date between p_pay_start_date AND p_pay_end_date
2778 AND p_abs_end_date between p_pay_start_date AND p_pay_end_date THEN
2779
2780 -- Condition 3 - Calculate continuous linking period of sickness
2781 -- If there are multiple sickness exists within 14 days before start date then
2782 -- include those sickness in calculating employer days.
2783 l_loop_empr_work_days := 0;
2784 l_loop_start_date := p_abs_start_date ;
2785 FOR i in child_link (p_person_id) LOOP
2786 IF ( i.date_start = i.date_end ) THEN
2787 l_duration := 0;
2788 l_include_event := 'N';
2789
2790 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2791 ( p_assignment_id, l_days_or_hours, l_include_event,
2792 i.date_start, i.date_end, l_start_time_char,
2793 l_end_time_char, l_duration
2794 );
2795 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
2796
2797 -- start date and end date are different then calculate working days between them
2798 ELSE
2799 -- Calling override to get override days and daily rate
2800
2801 l_over_return := get_override_details
2802 ( p_assignment_id,p_effective_date,i.date_start,
2803 i.date_end, p_abs_categorycode, l_cont_start_date,
2804 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
2805 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
2806 );
2807 / Multiple override element attached against one absence element. ie) *
2808 * One or more override entry exists with same start and end date /
2809 IF (l_over_return = -1) THEN
2810 / knelli
2811 IF length(l_msg_error) > 1 THEN
2812 l_msg_error := 'Error5';
2813 END IF;/
2814 l_msg_error := to_char(5);
2815 END IF;
2816
2817 -- If override element not exists for the continuous absences then calculate actual work days.
2818 IF l_cont_empr_days IS NULL THEN
2819 l_duration := 0;
2820 l_include_event := 'N';
2821
2822 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2823 ( p_assignment_id, l_days_or_hours, l_include_event,
2824 i.date_start, i.date_end, l_start_time_char,
2825 l_end_time_char, l_duration
2826 );
2827 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
2828 ELSE
2829 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
2830 END IF;
2831
2832 END IF;
2833 l_loop_start_date := i.date_start;
2834 END LOOP;
2835
2836 -- Calculation of actual working days present with the current absence.
2837 -- Ignore public holidays if the one present in between absence start and end dates.
2838 l_include_event := 'N';
2839 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2840 ( p_assignment_id, l_days_or_hours, l_include_event,
2841 p_prorate_start, p_prorate_end, l_start_time_char,
2842 l_end_time_char, l_duration
2843 );
2844 l_actual_days := nvl(l_duration,0);
2845
2846 -- Recalculate employer days with previous employment child minder days.
2847 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_child_prev_value,0);
2848
2849 -- Child minder sickness already taken is greater than 10 working days so no more empr days will be paid.
2850 IF l_loop_empr_work_days >= l_child_1_13 THEN
2851 l_empr_days := 0;
2852 -- If total days taken is < the entitlement limit then remaining days will be taken
2853 IF l_loop_empr_work_days < l_gen_child_limit THEN
2854 -- If current absence days is > limit then restrict it to limit
2855 IF l_actual_days > ( l_gen_child_limit - l_loop_empr_work_days ) THEN
2856 l_social_security_days := ( l_gen_child_limit - l_loop_empr_work_days );
2857 ELSE
2858 l_social_security_days := l_actual_days;
2859 END IF;
2860 ELSE -- If all the absences are exhausted earlier then no social security will be entertained.
2861 l_social_security_days := 0;
2862 END IF;
2863 -- Override element exists then override the calculated value
2864 IF l_override_ss_days IS NOT NULL THEN
2865 l_social_security_days := least(l_override_ss_days, l_social_security_days);
2866 END IF;
2867 ELSE -- Continuous sickness days is less than 12 working days
2868 -- if actual working days > remaning available then social security days will be paid
2869 IF l_actual_days > ( l_child_1_13 - l_loop_empr_work_days ) THEN
2870 l_empr_days := ( l_child_1_13 - l_loop_empr_work_days );
2871 l_social_security_days := (l_actual_days - l_empr_days);
2872 /pdavidra - 5260950 /
2873 IF l_social_security_days > (l_gen_child_limit - l_loop_empr_work_days - l_empr_days) THEN
2874 l_social_security_days := (l_gen_child_limit - l_loop_empr_work_days - l_empr_days);
2875 END IF;
2876 -- if override employer days is present calculate actual days through linking sickness
2877 -- and then override that with the override days.
2878 IF l_override_empr_days IS NOT NULL THEN
2879 l_empr_days := least(l_override_empr_days, l_empr_days);
2880 END IF;
2881
2882 IF l_override_ss_days IS NOT NULL THEN
2883 l_social_security_days := least(l_override_ss_days, l_social_security_days);
2884 END IF;
2885 ELSE
2886 l_empr_days := l_actual_days;
2887 l_social_security_days := 0;
2888 -- if override employer days is present calculate actual days through continuous linking sickness
2889 -- and then override that with the override days.
2890 IF l_override_empr_days IS NOT NULL THEN
2891 l_empr_days := least(l_override_empr_days, l_empr_days);
2892 END IF;
2893 END IF;
2894 END IF;
2895 -- If reimburse from social security is not set
2896 / knelli removed check
2897 IF l_gen_reimb_ss = 'N' THEN
2898 l_social_security_days := 0;
2899 END IF;/
2900
2901
2902 ------------------------------------------------------------------------------
2903 ------------------------------------------------------------------------------
2904 Else -- Absences lies more than one payroll period
2905
2906 -- Absence start date lies in between the payroll period st dt and end dt.
2907
2908 IF p_abs_start_date between p_pay_start_date and p_pay_end_date THEN
2909
2910 -- Condition 3 - Calculate continuous linking period of sickness
2911 -- If there are multiple sickness exists within 14 days before start date then
2912 -- include those sickness in calculating employer days.
2913 l_loop_empr_work_days := 0;
2914 l_loop_start_date := p_abs_start_date ;
2915 FOR i in child_link (p_person_id) LOOP
2916
2917 IF ( i.date_start = i.date_end ) THEN
2918 l_duration := 0;
2919 l_include_event := 'N';
2920
2921 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2922 ( p_assignment_id, l_days_or_hours, l_include_event,
2923 i.date_start, i.date_end, l_start_time_char,
2924 l_end_time_char, l_duration
2925 );
2926 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
2927
2928 ELSE
2929
2930 -- Calling override to get override days and daily rate
2931 l_over_return := get_override_details
2932 ( p_assignment_id,p_effective_date,i.date_start,
2933 i.date_end, p_abs_categorycode, l_cont_start_date,
2934 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
2935 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
2936 );
2937 / Multiple override element attached against one absence element. ie) *
2938 * One or more override entry exists with same start and end date /
2939 IF (l_over_return = -1) THEN
2940 / knelli
2941 IF length(l_msg_error) > 1 THEN
2942 l_msg_error := 'Error5';
2943 END IF;/
2944 l_msg_error := to_char(5);
2945 END IF;
2946 -- If override element not exists for the continuous absences then calculate actual work days.
2947 IF l_cont_empr_days IS NULL THEN
2948
2949 l_duration := 0;
2950 l_include_event := 'N';
2951
2952 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2953 ( p_assignment_id, l_days_or_hours, l_include_event,
2954 i.date_start, i.date_end, l_start_time_char,
2955 l_end_time_char, l_duration
2956 );
2957 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
2958
2959 ELSE
2960 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
2961 END IF;
2962
2963 END IF;
2964 l_loop_start_date := i.date_start;
2965 END LOOP;
2966
2967 -- Calculation of employer days if proration was enabled
2968 l_counter := 1;
2969 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
2970 -- It means absences crosses between one payroll period
2971
2972 IF l_counter = 1 THEN
2973 -- Newly introduced to knock off calendar and work days variables of employers period already taken.
2974 -- As it is a start of the proration period.
2975 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + 0;
2976
2977 ELSE
2978 -- Calculating actual days with prorated period
2979 l_duration := 0;
2980 l_include_event := 'N';
2981
2982 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2983 ( p_assignment_id, l_days_or_hours, l_include_event,
2984 (l_prev_paydate+1), i.date_earned, l_start_time_char,
2985 l_end_time_char, l_duration
2986 );
2987 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
2988 END IF;
2989 l_counter := l_counter + 1;
2990 l_prev_paydate := i.date_earned;
2991 END LOOP;
2992
2993 -- Calculation of actual working days present with the current absence.
2994 -- Ignore public holidays if the one present in between absence start and end dates.
2995 l_include_event := 'N';
2996
2997 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
2998 ( p_assignment_id, l_days_or_hours, l_include_event,
2999 p_prorate_start, p_prorate_end, l_start_time_char,
3000 l_end_time_char, l_duration
3001 );
3002 l_actual_days := nvl(l_duration,0);
3003
3004 -- Recalculate employer days with previous employment child minder days.
3005 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_child_prev_value,0);
3006
3007
3008 -- Child minder sickness already taken is greater than 10 working days so no more empr days will be paid.
3009 IF l_loop_empr_work_days >= l_child_1_13 THEN
3010 l_empr_days := 0;
3011 -- If total days taken is < the entitlement limit then remaining days will be taken
3012 IF l_loop_empr_work_days < l_gen_child_limit THEN
3013 -- If current absence days is > limit then restrict it to limit
3014 IF l_actual_days > ( l_gen_child_limit - l_loop_empr_work_days ) THEN
3015 l_social_security_days := ( l_gen_child_limit - l_loop_empr_work_days );
3016 ELSE
3017 l_social_security_days := l_actual_days;
3018 END IF;
3019 ELSE -- If all the absences are exhausted earlier then no social security will be entertained.
3020 l_social_security_days := 0;
3021 END IF;
3022 -- Override element exists then override the calculated value
3023 IF l_override_ss_days IS NOT NULL THEN
3024 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3025 END IF;
3026 ELSE -- Continuous sickness days is less than 12 working days
3027 -- if actual working days > remaning available then social security days will be paid
3028 IF l_actual_days > ( l_child_1_13 - l_loop_empr_work_days ) THEN
3029 l_empr_days := ( l_child_1_13 - l_loop_empr_work_days );
3030 l_social_security_days := (l_actual_days - l_empr_days);
3031 /pdavidra - 5260950 /
3032 IF l_social_security_days > (l_gen_child_limit - l_loop_empr_work_days - l_empr_days) THEN
3033 l_social_security_days := (l_gen_child_limit - l_loop_empr_work_days - l_empr_days);
3034 END IF;
3035 -- if override employer days is present calculate actual days through linking sickness
3036 -- and then override that with the override days.
3037 IF l_override_empr_days IS NOT NULL THEN
3038 l_empr_days := least(l_override_empr_days, l_empr_days);
3039 END IF;
3040
3041 IF l_override_ss_days IS NOT NULL THEN
3042 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3043 END IF;
3044 ELSE
3045 l_empr_days := l_actual_days;
3046 l_social_security_days := 0;
3047 -- if override employer days is present calculate actual days through continuous linking sickness
3048 -- and then override that with the override days.
3049 IF l_override_empr_days IS NOT NULL THEN
3050 l_empr_days := least(l_override_empr_days, l_empr_days);
3051 END IF;
3052 END IF;
3053 END IF;
3054
3055 -- If reimburse from social security is not set
3056 / knelli following check not valied
3057 IF l_gen_reimb_ss = 'N' THEN
3058 l_social_security_days := 0;
3059 END IF;/
3060
3061 -------------------------------------------------------------------------
3062 -------------------------------------------------------------------------
3063 -- Refer the previous payroll period's element input value for Empr and SS days calc.
3064 -- Absence end date lies in between the payroll period st dt and end dt.
3065 ELSIF p_abs_end_date between p_pay_start_date and p_pay_end_date THEN
3066
3067 -- Condition 3 - Calculate continuous linking period of sickness
3068 -- If there are multiple sickness exists within 14 days before start date then
3069 -- include those sickness in calculating employer days.
3070 l_loop_empr_work_days := 0;
3071 l_loop_start_date := p_abs_start_date ;
3072 FOR i in child_link (p_person_id) LOOP
3073
3074 IF ( i.date_start = i.date_end ) THEN
3075 l_duration := 0;
3076 l_include_event := 'N';
3077
3078 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3079 ( p_assignment_id, l_days_or_hours, l_include_event,
3080 i.date_start, i.date_end, l_start_time_char,
3081 l_end_time_char, l_duration
3082 );
3083 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
3084
3085 ELSE
3086
3087 -- Calling override to get override days and daily rate
3088 l_over_return := get_override_details
3089 ( p_assignment_id,p_effective_date,i.date_start,
3090 i.date_end, p_abs_categorycode, l_cont_start_date,
3091 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
3092 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
3093 );
3094 / Multiple override element attached against one absence element. ie) *
3095 * One or more override entry exists with same start and end date /
3096 IF (l_over_return = -1) THEN
3097 / knelli
3098 IF length(l_msg_error) > 1 THEN
3099 l_msg_error := 'Error5';
3100 END IF;/
3101 l_msg_error := to_char(5);
3102 END IF;
3103 -- If override element not exists for the continuous absences then calculate actual work days.
3104 IF l_cont_empr_days IS NULL THEN
3105
3106 l_duration := 0;
3107 l_include_event := 'N';
3108
3109 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3110 ( p_assignment_id, l_days_or_hours, l_include_event,
3111 i.date_start, i.date_end, l_start_time_char,
3112 l_end_time_char, l_duration
3113 );
3114 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
3115 ELSE
3116 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
3117 END IF;
3118
3119 END IF;
3120 l_loop_start_date := i.date_start;
3121 END LOOP;
3122
3123 -- Calculation of employer days if proration was enabled
3124 l_counter := 1;
3125 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
3126 -- It means absences crosses between one payroll period
3127
3128 IF l_counter = 1 THEN
3129 -- Calculating actual days with prorated period
3130 l_duration := 0;
3131 l_include_event := 'N';
3132
3133 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3134 ( p_assignment_id, l_days_or_hours, l_include_event,
3135 p_abs_start_date, i.date_earned, l_start_time_char,
3136 l_end_time_char, l_duration
3137 );
3138 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
3139 ELSE
3140 -- Calculating actual days with prorated period
3141 l_duration := 0;
3142 l_include_event := 'N';
3143
3144 / knelli bug 5261106 added check/
3145 IF p_abs_end_date NOT BETWEEN l_prev_paydate+1 AND i.date_earned THEN
3146 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3147 ( p_assignment_id, l_days_or_hours, l_include_event,
3148 (l_prev_paydate+1), i.date_earned, l_start_time_char,
3149 l_end_time_char, l_duration
3150 );
3151 END IF;
3152 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
3153 END IF;
3154 l_counter := l_counter + 1;
3155 l_prev_paydate := i.date_earned;
3156 END LOOP;
3157
3158 -- Calculation of actual working days present with the current absence.
3159 -- Ignore public holidays if the one present in between absence start and end dates.
3160 l_include_event := 'N';
3161 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3162 ( p_assignment_id, l_days_or_hours, l_include_event,
3163 p_prorate_start, p_prorate_end, l_start_time_char,
3164 l_end_time_char, l_duration
3165 );
3166 l_actual_days := nvl(l_duration,0);
3167
3168 -- Recalculate employer days with previous employment child minder days.
3169 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_child_prev_value,0);
3170
3171 /knelli added logic -- not required for this case/
3172 /IF l_loop_empr_work_days > 0 THEN
3173 l_loop_empr_work_days := l_loop_empr_work_days - l_actual_days;
3174 END IF;/
3175
3176 -- Child minder sickness already taken is greater than 10 working days so no more empr days will be paid.
3177 IF l_loop_empr_work_days >= l_child_1_13 THEN
3178 l_empr_days := 0;
3179 -- If total days taken is < the entitlement limit then remaining days will be taken
3180 IF l_loop_empr_work_days < l_gen_child_limit THEN
3181 -- If current absence days is > limit then restrict it to limit
3182 IF l_actual_days > ( l_gen_child_limit - l_loop_empr_work_days ) THEN
3183 l_social_security_days := ( l_gen_child_limit - l_loop_empr_work_days );
3184 ELSE
3185 l_social_security_days := l_actual_days;
3186 END IF;
3187 ELSE -- If all the absences are exhausted earlier then no social security will be entertained.
3188 l_social_security_days := 0;
3189 END IF;
3190 -- Override element exists then override the calculated value
3191 IF l_override_ss_days IS NOT NULL THEN
3192 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3193 END IF;
3194 ELSE -- Continuous sickness days is less than 12 working days
3195 -- if actual working days > remaning available then social security days will be paid
3196 IF l_actual_days > ( l_child_1_13 - l_loop_empr_work_days ) THEN
3197 l_empr_days := ( l_child_1_13 - l_loop_empr_work_days );
3198 l_social_security_days := (l_actual_days - l_empr_days);
3199 /pdavidra - 5260950 /
3200 IF l_social_security_days > (l_gen_child_limit - l_loop_empr_work_days - l_empr_days) THEN
3201 l_social_security_days := (l_gen_child_limit - l_loop_empr_work_days - l_empr_days);
3202 END IF;
3203 -- if override employer days is present calculate actual days through linking sickness
3204 -- and then override that with the override days.
3205 IF l_override_empr_days IS NOT NULL THEN
3206 l_empr_days := least(l_override_empr_days, l_empr_days);
3207 END IF;
3208
3209 IF l_override_ss_days IS NOT NULL THEN
3210 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3211 END IF;
3212 ELSE
3213 l_empr_days := l_actual_days;
3214 l_social_security_days := 0;
3215 -- if override employer days is present calculate actual days through continuous linking sickness
3216 -- and then override that with the override days.
3217 IF l_override_empr_days IS NOT NULL THEN
3218 l_empr_days := least(l_override_empr_days, l_empr_days);
3219 END IF;
3220 END IF;
3221 END IF;
3222 -- If reimburse from social security is not set
3223 / knelli removed the check
3224 IF l_gen_reimb_ss = 'N' THEN
3225 l_social_security_days := 0;
3226 END IF;/
3227
3228 ----------------------------------------------------------------------
3229 ----------------------------------------------------------------------
3230 ELSE -- Absence start and end date, both not lying in between the payroll period st dt and end dt.
3231 -- Condition 3 - Calculate continuous linking period of sickness
3232 -- If there are multiple sickness exists within 14 days before start date then
3233 -- include those sickness in calculating employer days.
3234
3235 l_loop_empr_work_days := 0;
3236 l_loop_start_date := p_abs_start_date ;
3237 FOR i in child_link (p_person_id) LOOP
3238
3239 IF ( i.date_start = i.date_end ) THEN
3240 l_duration := 0;
3241 l_include_event := 'N';
3242
3243 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3244 ( p_assignment_id, l_days_or_hours, l_include_event,
3245 i.date_start, i.date_end, l_start_time_char,
3246 l_end_time_char, l_duration
3247 );
3248 l_loop_empr_work_days := l_loop_empr_work_days + nvl(l_duration,0);
3249
3250 ELSE
3251
3252 -- Calling override to get override days and daily rate
3253 l_over_return := get_override_details
3254 ( p_assignment_id,p_effective_date,i.date_start,
3255 i.date_end, p_abs_categorycode, l_cont_start_date,
3256 l_cont_end_date,l_cont_empr_rate, l_cont_ss_rate,
3257 l_cont_reclaim_rate, l_cont_empr_days, l_cont_ss_days
3258 );
3259 / Multiple override element attached against one absence element. ie) *
3260 * One or more override entry exists with same start and end date /
3261 IF (l_over_return = -1) THEN
3262 / knelli
3263 IF length(l_msg_error) > 1 THEN
3264 l_msg_error := 'Error5';
3265 END IF;/
3266 l_msg_error := to_char(5);
3267 END IF;
3268 -- If override element not exists for the continuous absences then calculate actual work days.
3269 IF l_cont_empr_days IS NULL THEN
3270
3271 l_duration := 0;
3272 l_include_event := 'N';
3273
3274 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3275 ( p_assignment_id, l_days_or_hours, l_include_event,
3276 i.date_start, i.date_end, l_start_time_char,
3277 l_end_time_char, l_duration
3278 );
3279
3280 l_loop_empr_work_days := (l_loop_empr_work_days + nvl(l_duration,0));
3281
3282 ELSE
3283 l_loop_empr_work_days := l_loop_empr_work_days + l_cont_empr_days;
3284 END IF;
3285
3286 END IF;
3287 l_loop_start_date := i.date_start;
3288 END LOOP;
3289 -- Calculation of employer days if proration was enabled
3290 l_counter := 1;
3291 FOR I IN CSR_CUR_ABS_PRORATED(p_assignment_id, p_effective_date, p_abs_start_date, p_abs_end_date) LOOP
3292 -- It means absences crosses between one payroll period
3293
3294 IF l_counter = 1 THEN
3295 -- Calculating actual days with prorated period
3296 l_duration := 0;
3297 l_include_event := 'N';
3298
3299 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3300 ( p_assignment_id, l_days_or_hours, l_include_event,
3301 p_abs_start_date, i.date_earned, l_start_time_char,
3302 l_end_time_char, l_duration
3303 );
3304 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
3305
3306 ELSE
3307
3308 -- Calculating actual days with prorated period
3309 l_duration := 0;
3310 l_include_event := 'N';
3311
3312 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3313 ( p_assignment_id, l_days_or_hours, l_include_event,
3314 (l_prev_paydate+1), i.date_earned, l_start_time_char,
3315 l_end_time_char, l_duration
3316 );
3317 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_duration,0);
3318
3319 END IF;
3320 l_counter := l_counter + 1;
3321 l_prev_paydate := i.date_earned;
3322 END LOOP;
3323
3324 / knelli call work schedule /
3325 l_include_event := 'N';
3326 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3327 ( p_assignment_id, l_days_or_hours, l_include_event,
3328 p_prorate_start, p_prorate_end, l_start_time_char,
3329 l_end_time_char, l_duration
3330 );
3331 l_actual_days := nvl(l_duration,0);
3332 / knelli call work schedule /
3333 -- Child minder sickness already taken is greater than 10 working
3334 -- days so no more empr days will be paid.
3335
3336 / knelli replaced logic /
3337
3338 -- Child minder sickness already taken is greater than 10 working days so no more empr days will be paid.
3339 /knelli added logic/
3340 IF l_loop_empr_work_days > 0 THEN
3341 l_loop_empr_work_days := l_loop_empr_work_days - l_actual_days;
3342 END IF;
3343 -- Recalculate employer days with previous employment child minder days.
3344 l_loop_empr_work_days := nvl(l_loop_empr_work_days,0) + nvl(l_child_prev_value,0);
3345 IF l_loop_empr_work_days >= l_child_1_13 THEN
3346 l_empr_days := 0;
3347 -- If total days taken is < the entitlement limit then remaining days will be taken
3348 IF l_loop_empr_work_days < l_gen_child_limit THEN
3349 -- If current absence days is > limit then restrict it to limit
3350 IF l_actual_days > ( l_gen_child_limit - l_loop_empr_work_days ) THEN
3351 l_social_security_days := ( l_gen_child_limit - l_loop_empr_work_days );
3352 ELSE
3353 l_social_security_days := l_actual_days;
3354 END IF;
3355 ELSE -- If all the absences are exhausted earlier then no social security will be entertained.
3356 l_social_security_days := 0;
3357 END IF;
3358 -- Override element exists then override the calculated value
3359 IF l_override_ss_days IS NOT NULL THEN
3360 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3361 END IF;
3362 ELSE -- Continuous sickness days is less than 12 working days
3363 -- if actual working days > remaning available then social security days will be paid
3364 IF l_actual_days > ( l_child_1_13 - l_loop_empr_work_days ) THEN
3365 l_empr_days := ( l_child_1_13 - l_loop_empr_work_days );
3366 l_social_security_days := (l_actual_days - l_empr_days);
3367 /pdavidra - 5260950 /
3368 IF l_social_security_days > (l_gen_child_limit - l_loop_empr_work_days - l_empr_days) THEN
3369 l_social_security_days := (l_gen_child_limit - l_loop_empr_work_days - l_empr_days);
3370 END IF;
3371 -- if override employer days is present calculate actual days through linking sickness
3372 -- and then override that with the override days.
3373 IF l_override_empr_days IS NOT NULL THEN
3374 l_empr_days := least(l_override_empr_days, l_empr_days);
3375 END IF;
3376
3377 IF l_override_ss_days IS NOT NULL THEN
3378 l_social_security_days := least(l_override_ss_days, l_social_security_days);
3379 END IF;
3380 ELSE
3381 l_empr_days := l_actual_days;
3382 l_social_security_days := 0;
3383 -- if override employer days is present calculate actual days through continuous linking sickness
3384 -- and then override that with the override days.
3385 IF l_override_empr_days IS NOT NULL THEN
3386 l_empr_days := least(l_override_empr_days, l_empr_days);
3387 END IF;
3388 END IF;
3389 END IF;
3390
3391
3392 /knelli this check is not required , means always we have SS days/
3393 /IF l_gen_reimb_ss = 'N' THEN
3394 l_social_security_days := 0;
3395 END IF;/
3396 END IF; -- Current absence is prorated.
3397 END IF; -- Main logic end */
3398
3399 --=========================================================================================================================
3400
3401 curr_year_cms_emp_days := nvl(p_child_emp_days,0);
3402 curr_year_cms_ss_days := nvl(p_child_ss_days,0);
3403 l_child_prev_value := nvl(l_child_prev_value,0);
3404 -- Calculation of actual working days present with the current absence.
3405 -- Ignore public holidays if the one present in between absence start and end dates.
3406 l_include_event := 'N';
3407
3408 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3409 ( p_assignment_id, l_days_or_hours, l_include_event,
3410 p_prorate_start, p_prorate_end, l_start_time_char,
3411 l_end_time_char, l_duration
3412 );
3413 l_actual_days := nvl(l_duration,0);
3414 -- Recalculate employer/social security days with previous employment child minder days.
3415 IF l_child_prev_value <= p_abs_child_emp_days_limit THEN
3416 curr_year_cms_emp_days := curr_year_cms_emp_days + l_child_prev_value;
3417 ELSE
3418 curr_year_cms_emp_days := p_abs_child_emp_days_limit;
3419 curr_year_cms_ss_days := curr_year_cms_ss_days + (l_child_prev_value - p_abs_child_emp_days_limit) ;
3420 END IF;
3421
3422 --Check if the current year emp days is >= entitlement limit then
3423 IF curr_year_cms_emp_days >= p_abs_child_emp_days_limit THEN
3424 l_empr_days := 0;
3425 l_gen_ss_st_date := p_prorate_start ;
3426 -- If total days taken is < the entitlement limit then remaining days will be SS days
3427 IF (curr_year_cms_emp_days + curr_year_cms_ss_days) < l_gen_child_limit THEN
3428 p_work_pattern := '5DAY';
3429 l_duration := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
3430 -- If current absence days is > total limit then restrict it to limit
3431 IF l_duration > ( l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) ) THEN
3432 l_social_security_days := ( l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) );
3433 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3434 ELSE
3435 l_social_security_days := l_duration;
3436 END IF;
3437 ELSE -- If all the absences are exhausted earlier then no social security will be entertained.
3438 l_social_security_days := 0;
3439 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3440 END IF;
3441 ELSE
3442 -- if actual working days > remaning available
3443 IF l_actual_days > ( p_abs_child_emp_days_limit - curr_year_cms_emp_days ) THEN
3444 l_empr_days := ( p_abs_child_emp_days_limit - curr_year_cms_emp_days );
3445 l_gen_ss_st_date := p_prorate_start + nvl(l_empr_days,0) ;
3446 LOOP
3447 l_include_event := 'N';
3448 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3449 ( p_assignment_id, l_days_or_hours, l_include_event,
3450 p_prorate_start, l_gen_ss_st_date, l_start_time_char,
3451 l_end_time_char, l_duration );
3452 IF l_duration = (l_empr_days +1) THEN
3453 exit;
3454 END IF;
3455 l_gen_ss_st_date := l_gen_ss_st_date + 1;
3456 END LOOP;
3457 p_work_pattern := '5DAY';
3458 l_social_security_days := get_weekdays(l_gen_ss_st_date, p_prorate_end, p_work_pattern);
3459 --l_social_security_days := (l_actual_days - l_empr_days);
3460 -- if Social Security days > total limit
3461 IF l_social_security_days > (l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) - l_empr_days) THEN
3462 l_social_security_days := (l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) - l_empr_days);
3463 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3464 END IF;
3465 ELSE
3466 l_empr_days := l_actual_days;
3467 l_social_security_days := 0;
3468 END IF;
3469 IF l_empr_days > ( l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) ) THEN
3470 l_empr_days := ( l_gen_child_limit - (curr_year_cms_emp_days + curr_year_cms_ss_days) );
3471 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3472 IF l_empr_days < 0 THEN
3473 l_empr_days := 0;
3474 END IF;
3475 END IF;
3476 END IF;
3477
3478 IF l_social_security_days < 0 THEN
3479 l_social_security_days := 0;
3480 END IF;
3481
3482 -- if override employer days is present calculate actual days through linking sickness
3483 -- and then override that with the override days.
3484 IF l_override_empr_days IS NOT NULL THEN
3485 /*l_empr_days := least(l_override_empr_days, l_empr_days); 5380130 */
3486 l_empr_days := l_override_empr_days;
3487 IF (curr_year_cms_emp_days + l_empr_days) > p_abs_child_emp_days_limit THEN
3488 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3489 END IF;
3490 END IF;
3491 IF l_override_ss_days IS NOT NULL THEN
3492 /*l_social_security_days := least(l_override_ss_days, l_social_security_days); 5380130 */
3493 l_social_security_days := l_override_ss_days;
3494 IF (curr_year_cms_emp_days + l_empr_days + curr_year_cms_ss_days + l_social_security_days) > l_gen_child_limit THEN
3495 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3496 END IF;
3497 END IF;
3498
3499 -- Calculated result are assigned to output variables except daily rate
3500 p_abs_empr_days := nvl(l_empr_days,0) ;
3501 p_abs_ss_days := nvl(l_social_security_days,0) ;
3502 p_abs_total_days := (p_abs_empr_days + p_abs_ss_days);
3503 p_rec_empr_days := nvl(l_empr_days,0) ;
3504 p_rec_ss_days := nvl(l_social_security_days,0) ;
3505 p_rec_total_days := (p_rec_empr_days + p_rec_ss_days);
3506
3507 OPEN csr_intial_abs_pay_stdt(p_assignment_id,p_abs_start_date);
3508 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
3509 CLOSE csr_intial_abs_pay_stdt;
3510
3511 -- Get the daily rate value
3512 -- Calculation of G rate
3513
3514 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
3515 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
3516
3517 -- l_g_rate := GET_GRATE ( p_effective_date, p_assignment_id, p_business_group_id);
3518 l_g_rate := GET_GRATE ( p_abs_start_date, p_assignment_id, p_business_group_id);
3519
3520 /* End Bug Fix : 5380121 */
3521
3522 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
3523 IF l_gen_hour_sal = 'S' THEN
3524
3525 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
3526 (p_assignment_id, p_effective_date, 'Contractual Earnings',
3527 'R', 'D', l_rate, l_error_message, null, null);*/
3528 /*pgopal - Bug 5441078 fix - Passing absence start date*/
3529 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
3530 (p_assignment_id, p_abs_start_date, 'Contractual Earnings',
3531 'R', 'D', l_rate, l_error_message, null, null);
3532
3533 -- Override social security date was present.
3534 IF l_override_ss_rate IS NOT NULL THEN
3535 l_social_security_rate := l_override_ss_rate;
3536 ELSE
3537 l_social_security_rate := l_rate;
3538 END IF;
3539 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
3540 IF l_gen_restrict_ss_sl = 'Y' THEN
3541 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3542 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3543 END IF;
3544 END IF;
3545 -- if restrict daily rate to social security is not set then
3546 IF l_gen_restrict_dr_ss = 'N' THEN
3547 -- (absence pay base * 12) / 260;
3548 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
3549 -- if override employer daily rate was present then take that for sick pay.
3550 IF l_override_empr_rate IS NOT NULL THEN
3551 l_empr_daily_rate := l_override_empr_rate ;
3552 END IF;
3553 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
3554 IF l_gen_restrict_empr_sl = 'Y' THEN
3555 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3556 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3557 END IF;
3558 END IF;
3559
3560 -- if restrict daily rate to social security is no then pick whichever is
3561 -- less between historic and daily rate.
3562 IF l_social_security_rate > l_empr_daily_rate THEN
3563 l_reclaim_daily_rate := l_empr_daily_rate;
3564 ELSE
3565 l_reclaim_daily_rate := l_social_security_rate;
3566 END IF;
3567 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
3568 ELSE
3569 l_empr_daily_rate := l_social_security_rate;
3570 l_reclaim_daily_rate := l_social_security_rate;
3571
3572 IF l_override_empr_rate IS NOT NULL THEN
3573 l_empr_daily_rate := l_override_empr_rate ;
3574 END IF;
3575 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
3576 IF l_gen_restrict_empr_sl = 'Y' THEN
3577 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3578 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3579 END IF;
3580 END IF;
3581 END IF;
3582
3583 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
3584 ELSIF l_gen_hour_sal = 'H' THEN
3585 p_ear_value := 0;
3586 IF p_hourly_paid IN ('W', 'B') THEN
3587 -- Ignore public holidays if the one present in between absence start and end dates.
3588 l_include_event := 'Y';
3589 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
3590 /* pgopal - Bug 5393827 and 5349713 fix - taking the absence start date instead
3591 of payroll start date to get the last 4 weeks worked days*/
3592
3593 /* knelli changed date_start parameter, reduced date by 1 */
3594 /* 5475038 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3595 ( p_assignment_id, l_days_or_hours, l_include_event,
3596 ((p_abs_start_date) - p_abs_min_gap), (p_abs_start_date-1), l_start_time_char,
3597 l_end_time_char, l_duration
3598 );*/
3599 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
3600 ( p_assignment_id, l_days_or_hours, l_include_event,
3601 greatest(l_dateofjoin,((l_initial_abs_pay_stdt) - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
3602 l_end_time_char, l_duration );
3603 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
3604
3605
3606 BEGIN
3607 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
3608 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
3609 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
3610 ( (l_initial_abs_pay_stdt-1) - date_start )+1
3611 WHEN date_end = date_start THEN
3612 1
3613 ELSE (date_end - date_start) + 1 END ) AS Days_diff
3614 INTO l_abs_worked_days
3615 FROM per_absence_attendances
3616 WHERE person_id = p_person_id
3617 AND date_start < (l_initial_abs_pay_stdt-1)
3618 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
3619 AND date_start IS NOT NULL
3620 AND date_end IS NOT NULL ;
3621 EXCEPTION
3622 WHEN NO_DATA_FOUND THEN
3623 l_abs_worked_days := 0;
3624
3625 WHEN OTHERS THEN
3626 l_abs_worked_days := 0;
3627
3628 END;
3629
3630 l_duration := l_duration - nvl(l_abs_worked_days, 0);
3631 /* Bug Fix 5263714 added check condition*/
3632 IF l_duration > 0 THEN
3633 l_social_security_rate := ( p_4weeks_paybase / l_duration);
3634 ELSE
3635 l_social_security_rate := 0;
3636 END IF;
3637 -- Override social security date was present.
3638 IF l_override_ss_rate IS NOT NULL THEN
3639 l_social_security_rate := l_override_ss_rate;
3640 END IF;
3641 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
3642
3643 IF l_gen_restrict_ss_sl = 'Y' THEN
3644 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3645 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3646 END IF;
3647 END IF;
3648
3649 -- if override employer daily rate was present then take that for sick pay.
3650 IF l_override_empr_rate IS NOT NULL THEN
3651 l_empr_daily_rate := l_override_empr_rate ;
3652 ELSE
3653 l_empr_daily_rate := l_social_security_rate;
3654 END IF;
3655
3656 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
3657
3658 IF l_gen_restrict_empr_sl = 'Y' THEN
3659 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3660 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3661 END IF;
3662 END IF;
3663
3664 l_reclaim_daily_rate := l_social_security_rate;
3665
3666 ELSIF p_hourly_paid = 'M' THEN
3667 /* knelli
3668 IF length(l_msg_error) > 1 THEN
3669 l_msg_error := 'Error7';
3670 END IF;*/
3671 l_msg_error := to_char(7);
3672 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
3673 -- Previous 4 weeks period logic will not work.
3674 END IF;
3675 END IF;
3676
3677 p_abs_daily_rate := nvl(l_empr_daily_rate,0);
3678 p_ss_daily_rate := nvl(l_social_security_rate,0);
3679
3680
3681 -- If reclaimable daily rate is set on override element then use the value to reclaim
3682 -- from social security else use social security rate calculated.
3683 IF l_override_reclaim_rate IS NOT NULL THEN
3684 p_rec_daily_rate := l_override_reclaim_rate;
3685 ELSE
3686 p_rec_daily_rate := p_ss_daily_rate;
3687 END IF;
3688
3689 IF l_gen_rate_option = 'DRATE_OPT1' THEN
3690 p_rate_option1 := 'Y';
3691 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
3692 p_rate_option2 := 'Y';
3693 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
3694 p_rate_option3 := 'Y';
3695 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
3696 p_rate_option4 := 'Y';
3697 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
3698 p_rate_option5 := 'Y';
3699 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
3700 p_rate_option6 := 'Y';
3701 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
3702 p_rate_option7 := 'Y';
3703 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
3704 p_rate_option8 := 'Y';
3705 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
3706 p_rate_option9 := 'Y';
3707 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
3708 p_rate_option10 := 'Y';
3709 ELSE
3710 p_rate_option1 := null;
3711 p_rate_option2 := null;
3712 p_rate_option3 := null;
3713 p_rate_option4 := null;
3714 p_rate_option5 := null;
3715 p_rate_option6 := null;
3716 p_rate_option7 := null;
3717 p_rate_option8 := null;
3718 p_rate_option9 := null;
3719 p_rate_option10 := null;
3720 -- If calculated employer daily rate is less than 50% of G daily rate then no social security period will be paid.
3721 IF p_abs_daily_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
3722 --Employers period alone can be paid. No social security period will be paid.
3723 p_rec_empr_days := 0;
3724 p_rec_ss_days := 0;
3725 p_rec_total_days := 0;
3726 p_rec_daily_rate := 0;
3727 p_ss_daily_rate := 0;
3728 IF p_abs_ss_days > 0 then
3729 l_msg_error := to_char(11); /* 50% G Message */
3730 END IF;
3731 p_abs_ss_days := 0;
3732 p_abs_total_days := (nvl(p_abs_empr_days,0) + nvl(p_abs_ss_days,0)) ;
3733 END IF;
3734 END IF;
3735 p_abs_error := l_msg_error ;
3736
3737 ELSIF l_abs_category_code = 'PA' THEN
3738
3739 -- Fetch EIT values from absence payment details form
3740 -- 9 segments
3741 BEGIN
3742 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') --AS l_p_dob
3743 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION2) --AS l_p_compensation_rate
3744 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) --AS l_p_maternity_days
3745 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) --AS l_p_pt_maternity_days
3746 ,PAA.ABS_INFORMATION5 --AS l_p_reimburse_from_ss
3747 ,PAA.ABS_INFORMATION6 --AS l_p_use_ss_daily_rate
3748 ,PAA.ABS_INFORMATION7 --AS l_p_reclaimable_pay_max_6g
3749 ,PAA.ABS_INFORMATION8 --AS l_p_hol_acc_ent
3750 ,PAA.ABS_INFORMATION9 --AS l_p_daily_rate_calc
3751 ,PAA.ABS_INFORMATION15 --AS intial_absence
3752 ,PAA.ABS_INFORMATION16 -- AS intial_abs_attend_id
3753 INTO l_p_dob
3754 ,l_p_compensation_rate
3755 ,l_p_maternity_days
3756 ,l_p_pt_maternity_days
3757 ,l_p_reimburse_from_ss
3758 ,l_p_use_ss_daily_rate
3759 ,l_p_reclaimable_pay_max_6g
3760 ,l_p_hol_acc_ent
3761 ,l_p_daily_rate_calc
3762 ,l_initial_absence
3763 ,l_initial_abs_attend_id
3764 FROM PER_ABSENCE_ATTENDANCES PAA
3765 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
3766
3767 EXCEPTION
3768 WHEN OTHERS THEN
3769
3770 l_p_dob := null;
3771 l_p_compensation_rate := null;
3772 l_p_maternity_days := null;
3773 l_p_pt_maternity_days := null;
3774 l_p_reimburse_from_ss := null;
3775 l_p_use_ss_daily_rate := null;
3776 l_p_reclaimable_pay_max_6g := null;
3777 l_p_hol_acc_ent := null;
3778 l_p_daily_rate_calc := null;
3779 l_initial_absence :=NULL;
3780 l_initial_abs_attend_id := NULL ;
3781
3782 END;
3783 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
3784 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
3785 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
3786 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
3787 /*pgopal -Bug 5380065 fix*/
3788 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_p_reclaimable_pay_max_6g, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
3789 -- If reimburse from social security is set then adoption leave will be paid.
3790 IF l_gen_reimb_ss = 'Y' THEN
3791 -- Calling override to get override days and daily rate
3792 l_over_return := get_override_details
3793 ( p_assignment_id,p_effective_date,p_abs_start_date,
3794 p_abs_end_date, p_abs_categorycode, l_override_start_date,
3795 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
3796 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
3797 );
3798 /* Multiple override element attached against one absence element. ie) *
3799 * One or more override entry exists with same start and end date */
3800 IF (l_over_return = -1) THEN
3801 /* knelli
3802 IF length(l_msg_error) > 1 THEN
3803 l_msg_error := 'Error5';
3804 END IF;*/
3805 l_msg_error := to_char(5);
3806 p_abs_error := l_msg_error;
3807 RETURN 1;
3808 END IF;
3809 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
3810 l_msg_error := to_char(13);
3811 END IF;
3812 IF nvl(l_override_empr_days,0) > 0 THEN
3813 l_msg_error := to_char(14);
3814 p_abs_error := l_msg_error;
3815 RETURN 1;
3816 END IF;
3817 p_work_pattern := '5DAY';
3818 -- To find out number of days adoption leave has been taken in the current payroll period
3819 BEGIN
3820 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
3821 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
3822 INTO l_paternity_sum
3823 FROM per_absence_attendances paa, per_absence_attendance_types pat
3824 WHERE paa.person_id = p_person_id
3825 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
3826 AND paa.date_end < p_abs_start_date
3827 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
3828 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
3829 AND pat.absence_category = 'M'
3830 ORDER BY paa.date_end DESC ;
3831 EXCEPTION
3832 WHEN OTHERS THEN
3833 l_paternity_sum := null;
3834 END;
3835
3836
3837 -- Calculate actual days based on 5 day week pattern.
3838 p_work_pattern := '5DAY';
3839 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
3840
3841 -- If override element exists for the adoption absence then use the override value.
3842 /*IF l_override_ss_days IS NOT NULL THEN
3843 l_duration := l_override_ss_days;
3844 END IF;*/
3845
3846
3847 IF l_p_compensation_rate = 100 THEN
3848 -- To fetch parental days limit based on the compensation rate chosen.
3849
3850 OPEN GLB_VALUE ('NO_100_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
3851 FETCH GLB_VALUE INTO l_max_parental_days_100;
3852 CLOSE GLB_VALUE;
3853 /*
3854 IF nvl(l_m_no_of_babies_born,1) > 1 THEN
3855 OPEN GLB_VALUE ('NO_100_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
3856 FETCH GLB_VALUE INTO l_parental_days_add_child;
3857 CLOSE GLB_VALUE;
3858 l_max_parental_days_100 := l_max_parental_days_100 + (l_parental_days_add_child*l_m_no_of_babies_born);
3859 END IF;*/
3860
3861 l_parental_days_remaining := l_max_parental_days_100 - nvl(p_parental_bal_days,0);
3862 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
3863 l_parental_days_remaining := l_parental_days_remaining - nvl(l_maternity_sum,0);
3864
3865 IF l_parental_days_remaining < 0 THEN
3866 l_parental_days_remaining := 0;
3867 END IF;
3868
3869 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
3870 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
3871 IF l_duration > l_parental_days_remaining THEN
3872 p_parental_days := l_parental_days_remaining;
3873 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3874 ELSE
3875 p_parental_days := l_duration;
3876 END IF;
3877
3878 ELSIF l_p_compensation_rate = 80 THEN
3879 -- To fetch parental days limit based on the compensation rate chosen.
3880
3881 OPEN GLB_VALUE ('NO_80_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
3882 FETCH GLB_VALUE INTO l_max_parental_days_80;
3883 CLOSE GLB_VALUE;
3884 /*
3885 IF nvl(l_m_no_of_babies_born,1) > 1 THEN
3886 OPEN GLB_VALUE ('NO_80_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
3887 FETCH GLB_VALUE INTO l_parental_days_add_child;
3888 CLOSE GLB_VALUE;
3889 l_max_parental_days_80 := l_max_parental_days_80 + (l_parental_days_add_child*l_m_no_of_babies_born);
3890 END IF;*/
3891
3892 l_parental_days_remaining := l_max_parental_days_80 - nvl(p_parental_bal_days,0);
3893 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
3894 l_parental_days_remaining := l_parental_days_remaining - nvl(l_maternity_sum,0);
3895
3896 IF l_parental_days_remaining < 0 THEN
3897 l_parental_days_remaining := 0;
3898 END IF;
3899
3900 /*IF l_duration > ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum)) THEN
3901 p_parental_days := ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum));*/
3902 IF l_duration > l_parental_days_remaining THEN
3903 p_parental_days := l_parental_days_remaining;
3904 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3905 ELSE
3906 p_parental_days := l_duration;
3907 END IF;
3908 END IF;
3909
3910 -- If override element exists for the adoption absence then use the override value.
3911 IF l_override_ss_days IS NOT NULL THEN
3912 p_parental_days := l_override_ss_days;
3913 IF p_parental_days > l_parental_days_remaining THEN
3914 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
3915 END IF ;
3916 END IF;
3917
3918 -- Daily Rate calculation
3919 -- Calculation of G rate
3920
3921 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
3922 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
3923
3924 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
3925
3926 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
3927 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
3928
3929 /* End Bug Fix : 5380121 */
3930
3931 /* pgopal - to get the initial absence start date*/
3932 IF ( l_initial_absence = 'N') THEN
3933 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
3934 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
3935 CLOSE csr_get_intial_abs_st_date;
3936 ELSE
3937 l_initial_abs_st_date := p_abs_start_date;
3938 END IF ;
3939
3940 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
3941 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
3942 CLOSE csr_intial_abs_pay_stdt;
3943
3944 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
3945 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
3946
3947 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
3948 IF l_gen_hour_sal = 'S' THEN
3949 /* l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
3950 (p_assignment_id, p_effective_date, 'Contractual Earnings',
3951 'R', 'D', l_rate, l_error_message, null, null);*/
3952 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
3953 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
3954 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
3955 'R', 'D', l_rate, l_error_message, null, null);
3956
3957 -- Override social security date was present.
3958 IF l_override_ss_rate IS NOT NULL THEN
3959 l_social_security_rate := l_override_ss_rate;
3960 ELSE
3961 l_social_security_rate := l_rate;
3962 END IF;
3963
3964 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
3965 IF l_gen_restrict_ss_sl = 'Y' THEN
3966 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3967 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3968 END IF;
3969 END IF;
3970
3971 -- if restrict daily rate to social security is not set then
3972 IF l_gen_restrict_dr_ss = 'N' THEN
3973 -- (absence pay base * 12) / 260;
3974 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
3975
3976 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
3977 IF l_gen_restrict_empr_sl = 'Y' THEN
3978 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
3979 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
3980 END IF;
3981 END IF;
3982
3983 -- if restrict daily rate to social security is no then pick whichever is
3984 -- less between historic and daily rate.
3985 IF l_social_security_rate > l_empr_daily_rate THEN
3986 l_reclaim_daily_rate := l_empr_daily_rate;
3987 ELSE
3988 l_reclaim_daily_rate := l_social_security_rate;
3989 END IF;
3990 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
3991 ELSE
3992 l_empr_daily_rate := l_social_security_rate;
3993 l_reclaim_daily_rate := l_social_security_rate;
3994
3995 END IF;
3996
3997 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
3998 ELSIF l_gen_hour_sal = 'H' THEN
3999 p_ear_value := 0;
4000 IF p_hourly_paid IN ('W', 'B') THEN
4001
4002 -- Ignore public holidays if the one present in between absence start and end dates.
4003 l_include_event := 'Y';
4004 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
4005 /* pgopal - Bug 5393827 and 5349713 fix - taking the initial absence start date instead
4006 of payroll start date to get the last 4 weeks worked days*/
4007
4008 /* BUG Fix 5346832 : Start
4009 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
4010 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
4011 for hr_loc_work_schedule.calc_sch_based_dur */
4012
4013 /*
4014 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4015 ( p_assignment_id, l_days_or_hours, l_include_event,
4016 ((l_initial_abs_st_date) - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
4017 l_end_time_char, l_duration
4018 );
4019 */
4020 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4021 ( p_assignment_id, l_days_or_hours, l_include_event,
4022 greatest(l_dateofjoin,((l_initial_abs_pay_stdt) - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
4023 l_end_time_char, l_duration
4024 );
4025
4026 /* BUG Fix 5346832 : End */
4027
4028
4029 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
4030 BEGIN
4031 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
4032 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
4033 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
4034 ( (l_initial_abs_pay_stdt-1) - date_start )+1
4035 WHEN date_end = date_start THEN
4036 1
4037 ELSE (date_end - date_start) + 1 END ) AS Days_diff
4038 INTO l_abs_worked_days
4039 FROM per_absence_attendances
4040 WHERE person_id = p_person_id
4041 AND date_start < (l_initial_abs_pay_stdt-1)
4042 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
4043 AND date_start IS NOT NULL
4044 AND date_end IS NOT NULL ;
4045 EXCEPTION
4046 WHEN NO_DATA_FOUND THEN
4047 l_abs_worked_days := 0;
4048 WHEN OTHERS THEN
4049 l_abs_worked_days := 0;
4050 END;
4051
4052 l_duration := l_duration - nvl(l_abs_worked_days, 0);
4053 /* Bug fix 5263714 */
4054 IF l_duration > 0 THEN
4055 l_social_security_rate := ( p_4weeks_paybase / l_duration);
4056 ELSE
4057 l_social_security_rate := 0;
4058 END IF;
4059 -- Override social security date was present.
4060 IF l_override_ss_rate IS NOT NULL THEN
4061 l_social_security_rate := l_override_ss_rate;
4062 END IF;
4063 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
4064 IF l_gen_restrict_ss_sl = 'Y' THEN
4065 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4066 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4067 END IF;
4068 END IF;
4069
4070 l_empr_daily_rate := l_social_security_rate;
4071 l_reclaim_daily_rate := l_social_security_rate;
4072 ELSIF p_hourly_paid = 'M' THEN
4073 /* knelli
4074 IF length(l_msg_error) > 1 THEN
4075 l_msg_error := 'Error7';
4076 END IF;*/
4077 l_msg_error := to_char(7);
4078 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
4079 -- Previous 4 weeks period logic will not work.
4080 END IF;
4081 END IF;
4082
4083 p_parental_rate := l_reclaim_daily_rate ;
4084 /* knelli added logic */
4085 /*pgopal Bug 5353824 fix*/
4086 /*IF l_m_compensation_rate = 80 THEN*/
4087 IF l_p_compensation_rate = 80 THEN
4088 p_parental_rate := p_parental_rate * 0.8;
4089 END IF;
4090 p_parental_comprate := l_p_compensation_rate ;
4091 -- Reusing the existing siciness output variables for adoption
4092 p_rec_total_days := p_parental_days;
4093 p_rec_daily_rate := p_parental_comprate;
4094 p_ss_daily_rate := p_parental_rate;
4095
4096
4097 l_include_event := 'N';
4098 -- Calculating actual sickness days through work schedule
4099 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4100 ( p_assignment_id, l_days_or_hours, l_include_event,
4101 p_prorate_start, p_prorate_end, l_start_time_char,
4102 l_end_time_char, l_duration
4103 );
4104 l_actual_cal_days := nvl(l_duration,0);
4105 -- Calculate Earnings Adjustment value
4106 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
4107 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * l_actual_cal_days;
4108 p_ear_startdt := p_prorate_start;
4109 p_ear_enddt := p_prorate_end;
4110 p_ear_value := nvl(p_ear_value,0);
4111
4112 IF l_gen_hour_sal = 'H' THEN
4113 p_ear_value := 0;
4114 END IF;
4115
4116 IF l_gen_rate_option = 'DRATE_OPT1' THEN
4117 p_rate_option1 := 'Y';
4118 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
4119 p_rate_option2 := 'Y';
4120 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
4121 p_rate_option3 := 'Y';
4122 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
4123 p_rate_option4 := 'Y';
4124 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
4125 p_rate_option5 := 'Y';
4126 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
4127 p_rate_option6 := 'Y';
4128 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
4129 p_rate_option7 := 'Y';
4130 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
4131 p_rate_option8 := 'Y';
4132 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
4133 p_rate_option9 := 'Y';
4134 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
4135 p_rate_option10 := 'Y';
4136 ELSE
4137 p_rate_option1 := null;
4138 p_rate_option2 := null;
4139 p_rate_option3 := null;
4140 p_rate_option4 := null;
4141 p_rate_option5 := null;
4142 p_rate_option6 := null;
4143 p_rate_option7 := null;
4144 p_rate_option8 := null;
4145 p_rate_option9 := null;
4146 p_rate_option10 := null;
4147 END IF;
4148 p_abs_error := l_msg_error ;
4149
4150 /* Bug Fix 5349636 : Start */
4151
4152 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
4153 IF p_parental_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
4154 -- No social security period will be paid.
4155 p_rec_total_days := 0;
4156 p_rec_daily_rate := 0;
4157 p_ss_daily_rate := 0;
4158 p_ear_value := 0;
4159 l_msg_error := to_char(11); /* 50% G Message */
4160 p_abs_error := l_msg_error ;
4161 END IF;
4162
4163 /* Bug Fix 5349636 : End */
4164
4165 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
4166 -- Reusing the existing siciness output variables for adoption
4167
4168 p_rec_total_days := 0;
4169 p_rec_daily_rate := 0;
4170 p_ss_daily_rate := 0;
4171 p_ear_value := 0;
4172 p_abs_error := l_msg_error ;
4173
4174 END IF; -- Reimburse from social security
4175
4176 ELSIF l_abs_category_code = 'PTP' THEN
4177
4178
4179 -- Fetch EIT values from absence payment details form
4180 -- 9 segments
4181 BEGIN
4182 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') --AS l_ptp_dob
4183 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION2) --AS l_ptp_mat_compensation_rate
4184 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) --AS l_ptp_paternity_percent
4185 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) --AS l_ptp_days_spouse_mat_leave
4186 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION5) --AS l_ptp_days_pt_maternity
4187 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION6) --AS l_ptp_no_of_babies_born
4188 ,PAA.ABS_INFORMATION7 --AS l_ptp_reimburse_from_ss
4189 ,PAA.ABS_INFORMATION8 --AS l_ptp_use_ss_daily_rate
4190 ,PAA.ABS_INFORMATION9 --AS l_ptp_reclaimable_pay_max_6g
4191 ,PAA.ABS_INFORMATION10 --AS l_ptp_hol_acc_ent
4192 ,PAA.ABS_INFORMATION11 --AS l_ptp_daily_rate_calc
4193 ,PAA.ABS_INFORMATION15 --AS intial_absence
4194 ,PAA.ABS_INFORMATION16 -- AS intial_abs_attend_id
4195 INTO l_ptp_dob
4196 ,l_ptp_mat_compensation_rate
4197 ,l_ptp_paternity_percent
4198 ,l_ptp_days_spouse_mat_leave
4199 ,l_ptp_days_pt_maternity
4200 ,l_ptp_no_of_babies_born
4201 ,l_ptp_reimburse_from_ss
4202 ,l_ptp_use_ss_daily_rate
4203 ,l_ptp_reclaimable_pay_max_6g
4204 ,l_ptp_hol_acc_ent
4205 ,l_ptp_daily_rate_calc
4206 ,l_initial_absence
4207 ,l_initial_abs_attend_id
4208 FROM PER_ABSENCE_ATTENDANCES PAA
4209 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
4210
4211 EXCEPTION
4212 WHEN OTHERS THEN
4213
4214 l_ptp_dob := null;
4215 l_ptp_mat_compensation_rate := null;
4216 l_ptp_paternity_percent := null;
4217 l_ptp_days_spouse_mat_leave := null;
4218 l_ptp_days_pt_maternity := null;
4219 l_ptp_no_of_babies_born := null;
4220 l_ptp_reimburse_from_ss := null;
4221 l_ptp_use_ss_daily_rate := null;
4222 l_ptp_reclaimable_pay_max_6g := null;
4223 l_ptp_hol_acc_ent := null;
4224 l_ptp_daily_rate_calc := null;
4225 l_initial_absence :=NULL;
4226 l_initial_abs_attend_id := NULL ;
4227
4228 END;
4229 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
4230 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
4231 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
4232 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
4233 /*pgopal -Bug 5380065 fix*/
4234 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_ptp_reclaimable_pay_max_6g, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
4235
4236
4237 -- If reimburse from social security is set then adoption leave will be paid.
4238 IF l_gen_reimb_ss = 'Y' THEN
4239
4240 -- Calling override to get override days and daily rate
4241 l_over_return := get_override_details
4242 ( p_assignment_id,p_effective_date,p_abs_start_date,
4243 p_abs_end_date, p_abs_categorycode, l_override_start_date,
4244 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
4245 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
4246 );
4247 /* Multiple override element attached against one absence element. ie) *
4248 * One or more override entry exists with same start and end date */
4249 IF (l_over_return = -1) THEN
4250 /* knelli
4251 IF length(l_msg_error) > 1 THEN
4252 l_msg_error := 'Error5';
4253 END IF;*/
4254 l_msg_error := to_char(5);
4255 p_abs_error := l_msg_error;
4256 RETURN 1;
4257 END IF;
4258 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
4259 l_msg_error := to_char(13);
4260 END IF;
4261 IF nvl(l_override_empr_days,0) > 0 THEN
4262 l_msg_error := to_char(14);
4263 p_abs_error := l_msg_error;
4264 RETURN 1;
4265 END IF;
4266 p_work_pattern := '5DAY';
4267 -- To find out number of days adoption leave has been taken in the current payroll period
4268 BEGIN
4269 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
4270 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
4271 INTO l_pt_paternity_sum
4272 FROM per_absence_attendances paa, per_absence_attendance_types pat
4273 WHERE paa.person_id = p_person_id
4274 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
4275 AND paa.date_end < p_abs_start_date
4276 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
4277 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
4278 AND pat.absence_category = 'PTM'
4279 ORDER BY paa.date_end DESC ;
4280 EXCEPTION
4281 WHEN OTHERS THEN
4282 l_pt_paternity_sum := null;
4283 END;
4284
4285
4286 -- Calculate actual days based on 5 day week pattern.
4287 p_work_pattern := '5DAY';
4288 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
4289
4290 -- If override element exists for the adoption absence then use the override value.
4291 /*IF l_override_ss_days IS NOT NULL THEN
4292 l_duration := l_override_ss_days;
4293 END IF;*/
4294
4295
4296 IF l_ptp_mat_compensation_rate = 100 THEN
4297 -- To fetch parental days limit based on the compensation rate chosen.
4298
4299 OPEN GLB_VALUE ('NO_100_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
4300 FETCH GLB_VALUE INTO l_max_parental_days_100;
4301 CLOSE GLB_VALUE;
4302
4303 IF nvl(l_ptp_no_of_babies_born,1) > 1 THEN
4304 OPEN GLB_VALUE ('NO_100_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
4305 FETCH GLB_VALUE INTO l_parental_days_add_child;
4306 CLOSE GLB_VALUE;
4307 l_max_parental_days_100 := l_max_parental_days_100 + (l_parental_days_add_child*l_ptp_no_of_babies_born);
4308 END IF;
4309
4310 l_parental_days_remaining := l_max_parental_days_100 - nvl(p_parental_bal_days,0);
4311 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
4312 l_parental_days_remaining := l_parental_days_remaining - nvl(l_pt_paternity_sum,0);
4313
4314 IF l_parental_days_remaining < 0 THEN
4315 l_parental_days_remaining := 0;
4316 END IF;
4317
4318 IF nvl(l_ptp_paternity_percent,0) > 0 THEN
4319 l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_ptp_paternity_percent));
4320
4321 END IF;
4322 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
4323 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
4324 IF l_duration > l_parental_days_remaining THEN
4325 p_parental_days := l_parental_days_remaining;
4326 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4327 ELSE
4328 p_parental_days := l_duration;
4329 END IF;
4330
4331
4332 ELSIF l_ptp_mat_compensation_rate = 80 THEN
4333 -- To fetch parental days limit based on the compensation rate chosen.
4334
4335 OPEN GLB_VALUE ('NO_80_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
4336 FETCH GLB_VALUE INTO l_max_parental_days_80;
4337 CLOSE GLB_VALUE;
4338
4339 IF nvl(l_ptp_no_of_babies_born,1) > 1 THEN
4340 OPEN GLB_VALUE ('NO_80_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
4341 FETCH GLB_VALUE INTO l_parental_days_add_child;
4342 CLOSE GLB_VALUE;
4343 l_max_parental_days_80 := l_max_parental_days_80 + (l_parental_days_add_child*l_ptp_no_of_babies_born);
4344 END IF;
4345
4346 l_parental_days_remaining := l_max_parental_days_80 - nvl(p_parental_bal_days,0);
4347 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
4348 l_parental_days_remaining := l_parental_days_remaining - nvl(l_pt_paternity_sum,0);
4349
4350 IF l_parental_days_remaining < 0 THEN
4351 l_parental_days_remaining := 0;
4352 END IF;
4353
4354 IF nvl(l_ptp_paternity_percent,0) > 0 THEN
4355 l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_ptp_paternity_percent));
4356 END IF;
4357 /*IF l_duration > ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum)) THEN
4358 p_parental_days := ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum));*/
4359 IF l_duration > l_parental_days_remaining THEN
4360 p_parental_days := l_parental_days_remaining;
4361 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4362 ELSE
4363 p_parental_days := l_duration;
4364 END IF;
4365
4366 END IF;
4367
4368 /* pgopal - Bug 5355902 fix*/
4369 --p_parental_days := p_parental_days * trunc((l_ptp_paternity_percent/100),2);
4370 p_parental_days := round(p_parental_days * (l_ptp_paternity_percent/100),2);
4371 -- If override element exists for the adoption absence then use the override value.
4372 IF l_override_ss_days IS NOT NULL THEN
4373 p_parental_days := l_override_ss_days;
4374 IF p_parental_days > l_parental_days_remaining THEN
4375 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4376 END IF ;
4377 END IF;
4378 -- Daily Rate calculation
4379 -- Calculation of G rate
4380
4381 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
4382 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
4383
4384 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
4385
4386 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
4387 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
4388
4389 /* End Bug Fix : 5380121 */
4390
4391 /* pgopal - to get the initial absence start date*/
4392 IF ( l_initial_absence = 'N') THEN
4393 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
4394 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
4395 CLOSE csr_get_intial_abs_st_date;
4396 ELSE
4397 l_initial_abs_st_date := p_abs_start_date;
4398 END IF ;
4399
4400 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
4401 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
4402 CLOSE csr_intial_abs_pay_stdt;
4403
4404 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
4405 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
4406
4407 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
4408 IF l_gen_hour_sal = 'S' THEN
4409
4410 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
4411 (p_assignment_id, p_effective_date, 'Contractual Earnings',
4412 'R', 'D', l_rate, l_error_message, null, null);*/
4413 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
4414 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
4415 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
4416 'R', 'D', l_rate, l_error_message, null, null);
4417
4418
4419 -- Override social security date was present.
4420 IF l_override_ss_rate IS NOT NULL THEN
4421 l_social_security_rate := l_override_ss_rate;
4422 ELSE
4423 l_social_security_rate := l_rate;
4424 END IF;
4425
4426 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
4427 IF l_gen_restrict_ss_sl = 'Y' THEN
4428 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4429 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4430 END IF;
4431 END IF;
4432
4433 -- if restrict daily rate to social security is not set then
4434 IF l_gen_restrict_dr_ss = 'N' THEN
4435
4436 -- (absence pay base * 12) / 260;
4437 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
4438
4439 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
4440 IF l_gen_restrict_empr_sl = 'Y' THEN
4441 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4442 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4443 END IF;
4444 END IF;
4445
4446 -- if restrict daily rate to social security is no then pick whichever is
4447 -- less between historic and daily rate.
4448 IF l_social_security_rate > l_empr_daily_rate THEN
4449 l_reclaim_daily_rate := l_empr_daily_rate;
4450 ELSE
4451 l_reclaim_daily_rate := l_social_security_rate;
4452 END IF;
4453 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
4454 ELSE
4455 l_empr_daily_rate := l_social_security_rate;
4456 l_reclaim_daily_rate := l_social_security_rate;
4457
4458
4459 END IF;
4460
4461 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
4462 ELSIF l_gen_hour_sal = 'H' THEN
4463 p_ear_value := 0;
4464 IF p_hourly_paid IN ('W', 'B') THEN
4465
4466 -- Ignore public holidays if the one present in between absence start and end dates.
4467 l_include_event := 'Y';
4468 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
4469 /* pdavidra - bug 5330066 - redused the start date parameter by 1*/
4470 /* pgopal - Bug 5393827 and 5349713 fix - taking the initial absence start date instead
4471 of payroll start date to get the last 4 weeks worked days*/
4472
4473 /* BUG Fix 5346832 : Start
4474 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
4475 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
4476 for hr_loc_work_schedule.calc_sch_based_dur */
4477
4478 /*
4479 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4480 ( p_assignment_id, l_days_or_hours, l_include_event,
4481 (l_initial_abs_st_date - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
4482 l_end_time_char, l_duration
4483 );
4484 */
4485 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4486 ( p_assignment_id, l_days_or_hours, l_include_event,
4487 greatest(l_dateofjoin,(l_initial_abs_pay_stdt - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
4488 l_end_time_char, l_duration
4489 );
4490
4491 /* BUG Fix 5346832 : End */
4492
4493
4494 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
4495 BEGIN
4496 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
4497 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
4498 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
4499 ( (l_initial_abs_pay_stdt-1) - date_start )+1
4500 WHEN date_end = date_start THEN
4501 1
4502 ELSE (date_end - date_start) + 1 END ) AS Days_diff
4503 INTO l_abs_worked_days
4504 FROM per_absence_attendances
4505 WHERE person_id = p_person_id
4506 AND date_start < (l_initial_abs_pay_stdt-1)
4507 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
4508 AND date_start IS NOT NULL
4509 AND date_end IS NOT NULL ;
4510 EXCEPTION
4511 WHEN NO_DATA_FOUND THEN
4512 l_abs_worked_days := 0;
4513 WHEN OTHERS THEN
4514 l_abs_worked_days := 0;
4515 END;
4516
4517 l_duration := l_duration - nvl(l_abs_worked_days, 0);
4518
4519 /* BUG Fix 5346832 : Start */
4520
4521 IF (l_duration > 0) THEN
4522 l_social_security_rate := ( p_4weeks_paybase / l_duration);
4523 ELSE
4524 l_social_security_rate := 0 ;
4525 END IF;
4526
4527 /* BUG Fix 5346832 : End */
4528
4529 -- Override social security date was present.
4530 IF l_override_ss_rate IS NOT NULL THEN
4531 l_social_security_rate := l_override_ss_rate;
4532 END IF;
4533 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
4534 IF l_gen_restrict_ss_sl = 'Y' THEN
4535 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4536 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4537 END IF;
4538 END IF;
4539
4540 l_empr_daily_rate := l_social_security_rate;
4541 l_reclaim_daily_rate := l_social_security_rate;
4542 ELSIF p_hourly_paid = 'M' THEN
4543 /* knelli
4544 IF length(l_msg_error) > 1 THEN
4545 l_msg_error := 'Error7';
4546 END IF;*/
4547 l_msg_error := to_char(7);
4548 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
4549 -- Previous 4 weeks period logic will not work.
4550 END IF;
4551 END IF;
4552
4553 p_parental_rate := l_reclaim_daily_rate ;
4554
4555 /* knelli added logic */
4556 /*IF l_m_compensation_rate = 80 THEN*/
4557 /*pgopal - Bug 5355902 fix*/
4558 IF l_ptp_mat_compensation_rate = 80 THEN
4559 p_parental_rate := p_parental_rate * 0.8;
4560 END IF;
4561 p_parental_comprate := l_ptp_mat_compensation_rate ;
4562 -- Reusing the existing siciness output variables for adoption
4563 p_rec_total_days := p_parental_days;
4564 p_rec_daily_rate := p_parental_comprate;
4565 p_ss_daily_rate := p_parental_rate;
4566
4567
4568 l_include_event := 'N';
4569 -- Calculating actual sickness days through work schedule
4570 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4571 ( p_assignment_id, l_days_or_hours, l_include_event,
4572 p_prorate_start, p_prorate_end, l_start_time_char,
4573 l_end_time_char, l_duration
4574 );
4575 l_actual_cal_days := nvl(l_duration,0);
4576 -- Calculate Earnings Adjustment value
4577 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
4578 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * p_parental_days;
4579 p_ear_startdt := p_prorate_start;
4580 p_ear_enddt := p_prorate_end;
4581 p_ear_value := nvl(p_ear_value,0);
4582
4583 IF l_gen_hour_sal = 'H' THEN
4584 p_ear_value := 0;
4585 END IF;
4586
4587 IF l_gen_rate_option = 'DRATE_OPT1' THEN
4588 p_rate_option1 := 'Y';
4589 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
4590 p_rate_option2 := 'Y';
4591 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
4592 p_rate_option3 := 'Y';
4593 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
4594 p_rate_option4 := 'Y';
4595 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
4596 p_rate_option5 := 'Y';
4597 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
4598 p_rate_option6 := 'Y';
4599 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
4600 p_rate_option7 := 'Y';
4601 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
4602 p_rate_option8 := 'Y';
4603 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
4604 p_rate_option9 := 'Y';
4605 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
4606 p_rate_option10 := 'Y';
4607 ELSE
4608 p_rate_option1 := null;
4609 p_rate_option2 := null;
4610 p_rate_option3 := null;
4611 p_rate_option4 := null;
4612 p_rate_option5 := null;
4613 p_rate_option6 := null;
4614 p_rate_option7 := null;
4615 p_rate_option8 := null;
4616 p_rate_option9 := null;
4617 p_rate_option10 := null;
4618 END IF;
4619 p_abs_error := l_msg_error ;
4620
4621 /* Bug Fix 5349636 : Start */
4622
4623 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
4624 IF p_parental_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
4625 -- No social security period will be paid.
4626 p_rec_total_days := 0;
4627 p_rec_daily_rate := 0;
4628 p_ss_daily_rate := 0;
4629 p_ear_value := 0;
4630 l_msg_error := to_char(11); /* 50% G Message */
4631 p_abs_error := l_msg_error ;
4632 END IF;
4633
4634 /* Bug Fix 5349636 : End */
4635
4636 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
4637 -- Reusing the existing siciness output variables for adoption
4638
4639 p_rec_total_days := 0;
4640 p_rec_daily_rate := 0;
4641 p_ss_daily_rate := 0;
4642 p_ear_value := 0;
4643 p_abs_error := l_msg_error ;
4644
4645 END IF; -- Reimburse from social security
4646
4647 ELSIF l_abs_category_code = 'M' THEN
4648 -- Fetch EIT values from absence payment details form
4649 -- 9 segments, 12 segments, now 13 segments, 14 segments, 14th not used for calc
4650 BEGIN
4651 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') --AS l_m_expected_dob
4652 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') --AS l_m_dob
4653 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) --AS l_m_no_of_babies_born
4654 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) --AS l_m_compensation_rate
4655 ,PAA.ABS_INFORMATION5 --AS l_m_spouse
4656 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION6) --AS l_m_paternity_days
4657 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION7) --AS l_m_pt_paternity_days
4658 ,PAA.ABS_INFORMATION8 --AS l_m_reimurse_from_ss
4659 ,PAA.ABS_INFORMATION9 --AS l_m_use_ss_daily_rate
4660 ,PAA.ABS_INFORMATION10 --AS l_m_reclaimable_pay_max_6g
4661 ,PAA.ABS_INFORMATION11 --AS l_m_hol_acc_ent
4662 ,PAA.ABS_INFORMATION12 --AS l_m_daily_rate_calc
4663 ,to_date(PAA.ABS_INFORMATION13,'yyyy/mm/dd hh24:mi:ss') --AS l_m_date_stillborn
4664 ,PAA.ABS_INFORMATION15 --AS intial_absence
4665 ,PAA.ABS_INFORMATION16 -- AS intial_abs_attend_id
4666 INTO l_m_expected_dob
4667 ,l_m_dob
4668 ,l_m_no_of_babies_born
4669 ,l_m_compensation_rate
4670 ,l_m_spouse
4671 ,l_m_paternity_days
4672 ,l_m_pt_paternity_days
4673 ,l_m_reimurse_from_ss
4674 ,l_m_use_ss_daily_rate
4675 ,l_m_reclaimable_pay_max_6g
4676 ,l_m_hol_acc_ent
4677 ,l_m_daily_rate_calc
4678 ,l_m_date_stillborn
4679 ,l_initial_absence
4680 ,l_initial_abs_attend_id
4681 FROM PER_ABSENCE_ATTENDANCES PAA
4682 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
4683 EXCEPTION
4684 WHEN OTHERS THEN
4685
4686 l_m_expected_dob := null;
4687 l_m_dob := null;
4688 l_m_no_of_babies_born := null;
4689 l_m_compensation_rate := null;
4690 l_m_spouse := null;
4691 l_m_paternity_days := null;
4692 l_m_pt_paternity_days := null;
4693 l_m_reimurse_from_ss := null;
4694 l_m_use_ss_daily_rate := null;
4695 l_m_reclaimable_pay_max_6g := null;
4696 l_m_hol_acc_ent := null;
4697 l_m_daily_rate_calc := null;
4698 l_m_date_stillborn := null;
4699 l_initial_absence :=NULL;
4700 l_initial_abs_attend_id := NULL ;
4701 END;
4702
4703 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
4704 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
4705 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
4706 /* knelli change replace l_abs_daily_rate by l_m_daily_rate_calc
4707 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);*/
4708 /*pgopal - Bug 5380057 fix*/
4709 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_m_reclaimable_pay_max_6g, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
4710
4711
4712 -- If reimburse from social security is set then adoption leave will be paid.
4713 IF l_gen_reimb_ss = 'Y' THEN
4714 -- Calling override to get override days and daily rate
4715 l_over_return := get_override_details
4716 ( p_assignment_id,p_effective_date,p_abs_start_date,
4717 p_abs_end_date, p_abs_categorycode, l_override_start_date,
4718 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
4719 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
4720 );
4721 /* Multiple override element attached against one absence element. ie) *
4722 * One or more override entry exists with same start and end date */
4723 IF (l_over_return = -1) THEN
4724 /* knelli
4725 IF length(l_msg_error) > 1 THEN
4726 l_msg_error := 'Error5';
4727 END IF;*/
4728 l_msg_error := to_char(5);
4729 p_abs_error := l_msg_error;
4730 RETURN 1;
4731 END IF;
4732 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
4733 l_msg_error := to_char(13);
4734 END IF;
4735 IF nvl(l_override_empr_days,0) > 0 THEN
4736 l_msg_error := to_char(14);
4737 p_abs_error := l_msg_error;
4738 RETURN 1;
4739 END IF;
4740 p_work_pattern := '5DAY';
4741 -- To find out number of days maternity leave has been taken in the current payroll period
4742 BEGIN
4743 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
4744 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
4745 INTO l_maternity_sum
4746 FROM per_absence_attendances paa, per_absence_attendance_types pat
4747 WHERE paa.person_id = p_person_id
4748 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
4749 AND paa.date_end < p_abs_start_date
4750 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
4751 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
4752 AND pat.absence_category = 'M'
4753 ORDER BY paa.date_end DESC ;
4754 EXCEPTION
4755 WHEN OTHERS THEN
4756 l_maternity_sum := null;
4757 END;
4758
4759 -- Calculate actual days based on 5 day week pattern.
4760 p_work_pattern := '5DAY';
4761 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
4762
4763 -- If override element exists for the adoption absence then use the override value.
4764 /*IF l_override_ss_days IS NOT NULL THEN
4765 l_duration := l_override_ss_days;
4766 END IF;*/
4767
4768 IF l_m_compensation_rate = 100 THEN
4769 -- To fetch parental days limit based on the compensation rate chosen.
4770
4771 OPEN GLB_VALUE ('NO_100_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
4772 FETCH GLB_VALUE INTO l_max_parental_days_100;
4773 CLOSE GLB_VALUE;
4774
4775 IF nvl(l_m_no_of_babies_born,1) > 1 THEN
4776 OPEN GLB_VALUE ('NO_100_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
4777 FETCH GLB_VALUE INTO l_parental_days_add_child;
4778 CLOSE GLB_VALUE;
4779 /*pgopal - Bug 5351991 fix*/
4780 /*l_max_parental_days_100 := l_max_parental_days_100 + (l_parental_days_add_child*l_m_no_of_babies_born);*/
4781 l_max_parental_days_100 := l_max_parental_days_100 + (l_parental_days_add_child * (l_m_no_of_babies_born -1));
4782 END IF;
4783 l_parental_days_remaining := l_max_parental_days_100 - nvl(p_parental_bal_days,0);
4784 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
4785 l_parental_days_remaining := l_parental_days_remaining - nvl(l_maternity_sum,0);
4786
4787 IF l_parental_days_remaining < 0 THEN
4788 l_parental_days_remaining := 0;
4789 END IF;
4790
4791 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
4792 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
4793 IF l_duration > l_parental_days_remaining THEN
4794 p_parental_days := l_parental_days_remaining;
4795 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4796 ELSE
4797 p_parental_days := l_duration;
4798 END IF;
4799
4800
4801 ELSIF l_m_compensation_rate = 80 THEN
4802 -- To fetch parental days limit based on the compensation rate chosen.
4803
4804 OPEN GLB_VALUE ('NO_80_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
4805 FETCH GLB_VALUE INTO l_max_parental_days_80;
4806 CLOSE GLB_VALUE;
4807
4808 IF nvl(l_m_no_of_babies_born,1) > 1 THEN
4809 OPEN GLB_VALUE ('NO_80_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
4810 FETCH GLB_VALUE INTO l_parental_days_add_child;
4811 CLOSE GLB_VALUE;
4812 /*pgopal - Bug 5351991 fix*/
4813 /*l_max_parental_days_80 := l_max_parental_days_80 + (l_parental_days_add_child*l_m_no_of_babies_born);*/
4814 l_max_parental_days_80 := l_max_parental_days_80 + (l_parental_days_add_child * (l_m_no_of_babies_born-1));
4815 END IF;
4816 l_parental_days_remaining := l_max_parental_days_80 - nvl(p_parental_bal_days,0);
4817 l_parental_days_remaining := l_parental_days_remaining - nvl(l_m_paternity_days,0) - nvl(l_m_pt_paternity_days,0);
4818 l_parental_days_remaining := l_parental_days_remaining - nvl(l_maternity_sum,0);
4819
4820 IF l_parental_days_remaining < 0 THEN
4821 l_parental_days_remaining := 0;
4822 END IF;
4823
4824 /*IF l_duration > ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum)) THEN
4825 p_parental_days := ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum));*/
4826 IF l_duration > l_parental_days_remaining THEN
4827 p_parental_days := l_parental_days_remaining;
4828 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4829 ELSE
4830 p_parental_days := l_duration;
4831 END IF;
4832 END IF;
4833
4834 -- If override element exists for the adoption absence then use the override value.
4835 IF l_override_ss_days IS NOT NULL THEN
4836 p_parental_days := l_override_ss_days;
4837 IF p_parental_days > l_parental_days_remaining THEN
4838 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
4839 END IF ;
4840 END IF;
4841
4842 -- Daily Rate calculation
4843 -- Calculation of G rate
4844
4845 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
4846 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
4847
4848 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
4849
4850 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
4851 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
4852
4853 /* Pgopal - to get the initial absence start date*/
4854 IF ( l_initial_absence = 'N') THEN
4855 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
4856 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
4857 CLOSE csr_get_intial_abs_st_date;
4858 ELSE
4859 l_initial_abs_st_date := p_abs_start_date;
4860 END IF ;
4861
4862 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
4863 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
4864 CLOSE csr_intial_abs_pay_stdt;
4865
4866 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
4867 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
4868
4869 /* End Bug Fix : 5380121 */
4870
4871 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
4872 IF l_gen_hour_sal = 'S' THEN
4873
4874 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
4875 (p_assignment_id, p_effective_date, 'Contractual Earnings',
4876 'R', 'D', l_rate, l_error_message, null, null);*/
4877 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
4878 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
4879 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
4880 'R', 'D', l_rate, l_error_message, null, null);
4881
4882
4883 -- Override social security date was present.
4884 IF l_override_ss_rate IS NOT NULL THEN
4885 l_social_security_rate := l_override_ss_rate;
4886 ELSE
4887 l_social_security_rate := l_rate;
4888 END IF;
4889
4890 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
4891 IF l_gen_restrict_ss_sl = 'Y' THEN
4892 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4893 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4894 END IF;
4895 END IF;
4896
4897 -- if restrict daily rate to social security is not set then
4898 IF l_gen_restrict_dr_ss = 'N' THEN
4899
4900 -- (absence pay base * 12) / 260;
4901 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
4902
4903 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
4904 IF l_gen_restrict_empr_sl = 'Y' THEN
4905 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4906 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4907 END IF;
4908 END IF;
4909
4910 -- if restrict daily rate to social security is no then pick whichever is
4911 -- less between historic and daily rate.
4912 IF l_social_security_rate > l_empr_daily_rate THEN
4913 l_reclaim_daily_rate := l_empr_daily_rate;
4914 ELSE
4915 l_reclaim_daily_rate := l_social_security_rate;
4916 END IF;
4917 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
4918 ELSE
4919 l_empr_daily_rate := l_social_security_rate;
4920 l_reclaim_daily_rate := l_social_security_rate;
4921
4922 END IF;
4923
4924 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
4925 ELSIF l_gen_hour_sal = 'H' THEN
4926 p_ear_value := 0;
4927 IF p_hourly_paid IN ('W', 'B') THEN
4928
4929
4930 -- Ignore public holidays if the one present in between absence start and end dates.
4931 l_include_event := 'Y';
4932 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
4933 /* knelli changed absence start date */
4934 /* pgopal - Bug 5393827 and 5349713 fix - taking the initial absence start date instead
4935 of payroll start date to get the last 4 weeks worked days*/
4936
4937 /* BUG Fix 5346832 : Start
4938 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
4939 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
4940 for hr_loc_work_schedule.calc_sch_based_dur */
4941
4942 /*
4943 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4944 ( p_assignment_id, l_days_or_hours, l_include_event,
4945 ((l_initial_abs_st_date) - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
4946 l_end_time_char, l_duration
4947 );
4948 */
4949
4950 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
4951 ( p_assignment_id, l_days_or_hours, l_include_event,
4952 greatest(l_dateofjoin,((l_initial_abs_pay_stdt) - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
4953 l_end_time_char, l_duration
4954 );
4955
4956 /* BUG Fix 5346832 : End */
4957
4958 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
4959 BEGIN
4960 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
4961 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
4962 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
4963 ( (l_initial_abs_pay_stdt-1) - date_start )+1
4964 WHEN date_end = date_start THEN
4965 1
4966 ELSE (date_end - date_start) + 1 END ) AS Days_diff
4967 INTO l_abs_worked_days
4968 FROM per_absence_attendances
4969 WHERE person_id = p_person_id
4970 AND date_start < (l_initial_abs_pay_stdt-1)
4971 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
4972 AND date_start IS NOT NULL
4973 AND date_end IS NOT NULL ;
4974 EXCEPTION
4975 WHEN NO_DATA_FOUND THEN
4976 l_abs_worked_days := 0;
4977 WHEN OTHERS THEN
4978 l_abs_worked_days := 0;
4979 END;
4980
4981 l_duration := l_duration - nvl(l_abs_worked_days, 0);
4982
4983 /* knelli added logic */
4984 IF l_duration > 0 THEN
4985 l_social_security_rate := ( p_4weeks_paybase / l_duration);
4986 ELSE
4987 l_social_security_rate := 0;
4988 END IF;
4989
4990 -- Override social security date was present.
4991 IF l_override_ss_rate IS NOT NULL THEN
4992 l_social_security_rate := l_override_ss_rate;
4993 END IF;
4994 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
4995 IF l_gen_restrict_ss_sl = 'Y' THEN
4996 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
4997 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
4998 END IF;
4999 END IF;
5000
5001 l_empr_daily_rate := l_social_security_rate;
5002 l_reclaim_daily_rate := l_social_security_rate;
5003
5004 ELSIF p_hourly_paid = 'M' THEN
5005 /* knelli
5006 IF length(l_msg_error) > 1 THEN
5007 l_msg_error := 'Error7';
5008 END IF;*/
5009 l_msg_error := to_char(7);
5010 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
5011 -- Previous 4 weeks period logic will not work.
5012 END IF;
5013 END IF;
5014
5015 p_parental_rate := l_reclaim_daily_rate ;
5016 /* knelli added logic */
5017 IF l_m_compensation_rate = 80 THEN
5018 p_parental_rate := p_parental_rate * 0.8;
5019 END IF;
5020
5021 p_parental_comprate := l_m_compensation_rate ;
5022 -- Reusing the existing siciness output variables for adoption
5023 p_rec_total_days := p_parental_days;
5024 p_rec_daily_rate := p_parental_comprate;
5025 p_ss_daily_rate := p_parental_rate;
5026
5027
5028 l_include_event := 'N';
5029 -- Calculating actual sickness days through work schedule
5030 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5031 ( p_assignment_id, l_days_or_hours, l_include_event,
5032 p_prorate_start, p_prorate_end, l_start_time_char,
5033 l_end_time_char, l_duration
5034 );
5035 l_actual_cal_days := nvl(l_duration,0);
5036
5037 -- Calculate Earnings Adjustment value
5038 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
5039 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * l_actual_cal_days;
5040 p_ear_startdt := p_prorate_start;
5041 p_ear_enddt := p_prorate_end;
5042 p_ear_value := nvl(p_ear_value,0);
5043
5044 IF l_gen_hour_sal = 'H' THEN
5045 p_ear_value := 0;
5046 END IF;
5047
5048 IF l_gen_rate_option = 'DRATE_OPT1' THEN
5049 p_rate_option1 := 'Y';
5050 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
5051 p_rate_option2 := 'Y';
5052 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
5053 p_rate_option3 := 'Y';
5054 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
5055 p_rate_option4 := 'Y';
5056 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
5057 p_rate_option5 := 'Y';
5058 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
5059 p_rate_option6 := 'Y';
5060 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
5061 p_rate_option7 := 'Y';
5062 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
5063 p_rate_option8 := 'Y';
5064 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
5065 p_rate_option9 := 'Y';
5066 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
5067 p_rate_option10 := 'Y';
5068 ELSE
5069 p_rate_option1 := null;
5070 p_rate_option2 := null;
5071 p_rate_option3 := null;
5072 p_rate_option4 := null;
5073 p_rate_option5 := null;
5074 p_rate_option6 := null;
5075 p_rate_option7 := null;
5076 p_rate_option8 := null;
5077 p_rate_option9 := null;
5078 p_rate_option10 := null;
5079 END IF;
5080
5081
5082 p_abs_error := l_msg_error ;
5083
5084 /* Bug Fix 5349636 : Start */
5085
5086 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
5087 IF p_parental_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
5088 -- No social security period will be paid.
5089 p_rec_total_days := 0;
5090 p_rec_daily_rate := 0;
5091 p_ss_daily_rate := 0;
5092 p_ear_value := 0;
5093 l_msg_error := to_char(11); /* 50% G Message */
5094 p_abs_error := l_msg_error ;
5095 END IF;
5096
5097 /* Bug Fix 5349636 : End */
5098
5099 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
5100 -- Reusing the existing siciness output variables for adoption
5101
5102 p_rec_total_days := 0;
5103 p_rec_daily_rate := 0;
5104 p_ss_daily_rate := 0;
5105 p_ear_value := 0;
5106 p_abs_error := l_msg_error ;
5107
5108 END IF; -- Reimburse from social security
5109 ELSIF l_abs_category_code = 'PTM' THEN
5110
5111
5112 -- Fetch EIT values from absence payment details form
5113 -- 9 segments, 13 segments
5114 BEGIN
5115 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') --AS l_ptm_expected_dob
5116 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') --AS l_ptm_dob
5117 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) --AS l_ptm_percentage
5118 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) --AS l_ptm_compensation_rate
5119 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION5) --AS l_ptm_paternity_days
5120 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION6) --AS l_ptm_pt_paternity_days
5121 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION7) --AS l_ptm_no_of_babies_born
5122 ,PAA.ABS_INFORMATION8 --AS l_ptm_reimburse_from_ss
5123 ,PAA.ABS_INFORMATION9 --AS l_ptm_use_ss_daily_rate
5124 ,PAA.ABS_INFORMATION10 --AS l_ptm_reclaim_pay_max_6g
5125 ,PAA.ABS_INFORMATION11 --AS l_ptm_hol_acc_ent
5126 ,PAA.ABS_INFORMATION12 --AS l_ptm_daily_rate_calc
5127 ,PAA.ABS_INFORMATION15 --AS intial_absence
5128 ,PAA.ABS_INFORMATION16 -- AS intial_abs_attend_id
5129 INTO l_ptm_expected_dob
5130 ,l_ptm_dob
5131 ,l_ptm_percentage
5132 ,l_ptm_compensation_rate
5133 ,l_ptm_paternity_days
5134 ,l_ptm_pt_paternity_days
5135 ,l_ptm_no_of_babies_born
5136 ,l_ptm_reimburse_from_ss
5137 ,l_ptm_use_ss_daily_rate
5138 ,l_ptm_reclaim_pay_max_6g
5139 ,l_ptm_hol_acc_ent
5140 ,l_ptm_daily_rate_calc
5141 ,l_initial_absence
5142 ,l_initial_abs_attend_id
5143 FROM PER_ABSENCE_ATTENDANCES PAA
5144 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
5145
5146 EXCEPTION
5147 WHEN OTHERS THEN
5148
5149 l_ptm_expected_dob := null;
5150 l_ptm_dob := null;
5151 l_ptm_percentage := null;
5152 l_ptm_compensation_rate := null;
5153 l_ptm_pt_paternity_days := null;
5154 l_ptm_no_of_babies_born := null;
5155 l_ptm_use_ss_daily_rate := null;
5156 l_ptm_daily_rate_calc := null;
5157 l_ptm_hol_acc_ent := null;
5158 l_initial_absence :=NULL;
5159 l_initial_abs_attend_id := NULL ;
5160 END;
5161 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
5162 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
5163 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
5164 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
5165 /*pgopal - Bug 5380057 fix*/
5166 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_ptm_reclaim_pay_max_6g, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
5167
5168 -- If reimburse from social security is set then adoption leave will be paid.
5169 IF l_gen_reimb_ss = 'Y' THEN
5170
5171 -- Calling override to get override days and daily rate
5172 l_over_return := get_override_details
5173 ( p_assignment_id,p_effective_date,p_abs_start_date,
5174 p_abs_end_date, p_abs_categorycode, l_override_start_date,
5175 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
5176 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
5177 );
5178 /* Multiple override element attached against one absence element. ie) *
5179 * One or more override entry exists with same start and end date */
5180 IF (l_over_return = -1) THEN
5181 /* knelli
5182 IF length(l_msg_error) > 1 THEN
5183 l_msg_error := 'Error5';
5184 END IF;*/
5185 l_msg_error := to_char(5);
5186 p_abs_error := l_msg_error;
5187 RETURN 1;
5188 END IF;
5189 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
5190 l_msg_error := to_char(13);
5191 END IF;
5192 IF nvl(l_override_empr_days,0) > 0 THEN
5193 l_msg_error := to_char(14);
5194 p_abs_error := l_msg_error;
5195 RETURN 1;
5196 END IF;
5197
5198 p_work_pattern := '5DAY';
5199 -- To find out number of days adoption leave has been taken in the current payroll period
5200 BEGIN
5201 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
5202 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
5203 INTO l_pt_maternity_sum
5204 FROM per_absence_attendances paa, per_absence_attendance_types pat
5205 WHERE paa.person_id = p_person_id
5206 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
5207 AND paa.date_end < p_abs_start_date
5208 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
5209 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
5210 AND pat.absence_category = 'M'
5211 ORDER BY paa.date_end DESC ;
5212 EXCEPTION
5213 WHEN OTHERS THEN
5214 l_pt_maternity_sum := null;
5215 END;
5216
5217
5218
5219
5220 -- Calculate actual days based on 5 day week pattern.
5221 p_work_pattern := '5DAY';
5222 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
5223
5224 -- If override element exists for the adoption absence then use the override value.
5225 /*IF l_override_ss_days IS NOT NULL THEN
5226 l_duration := l_override_ss_days;
5227 END IF;*/
5228
5229 IF l_ptm_compensation_rate = 100 THEN
5230 -- To fetch parental days limit based on the compensation rate chosen.
5231
5232 OPEN GLB_VALUE ('NO_100_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
5233 FETCH GLB_VALUE INTO l_max_parental_days_100;
5234 CLOSE GLB_VALUE;
5235
5236 IF nvl(l_ptm_no_of_babies_born,1) > 1 THEN
5237 OPEN GLB_VALUE ('NO_100_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
5238 FETCH GLB_VALUE INTO l_parental_days_add_child;
5239 CLOSE GLB_VALUE;
5240 l_max_parental_days_100 := l_max_parental_days_100 + (l_parental_days_add_child*l_ptm_no_of_babies_born);
5241 END IF;
5242
5243 l_parental_days_remaining := l_max_parental_days_100 - nvl(p_parental_bal_days,0);
5244 l_parental_days_remaining := l_parental_days_remaining - nvl(l_ptm_paternity_days,0) - nvl(l_ptm_pt_paternity_days,0);
5245 l_parental_days_remaining := l_parental_days_remaining - nvl(l_pt_maternity_sum,0);
5246
5247 IF l_parental_days_remaining < 0 THEN
5248 l_parental_days_remaining := 0;
5249 END IF;
5250
5251 IF nvl(l_ptm_percentage,0) > 0 THEN
5252 l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_ptm_percentage));
5253
5254 END IF;
5255 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
5256 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
5257 IF l_duration > l_parental_days_remaining THEN
5258 p_parental_days := l_parental_days_remaining;
5259 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5260 ELSE
5261 p_parental_days := l_duration;
5262 END IF;
5263
5264
5265 ELSIF l_ptm_compensation_rate = 80 THEN
5266 -- To fetch parental days limit based on the compensation rate chosen.
5267
5268 OPEN GLB_VALUE ('NO_80_MAX_PARENTAL_BENEFIT_DAYS', p_abs_start_date );
5269 FETCH GLB_VALUE INTO l_max_parental_days_80;
5270 CLOSE GLB_VALUE;
5271
5272 IF nvl(l_ptm_no_of_babies_born,1) > 1 THEN
5273 OPEN GLB_VALUE ('NO_80_MAX_MAT_DAYS_PER_ADDITIONAL_CHILD', p_abs_start_date );
5274 FETCH GLB_VALUE INTO l_parental_days_add_child;
5275 CLOSE GLB_VALUE;
5276 l_max_parental_days_80 := l_max_parental_days_80 + (l_parental_days_add_child*l_ptm_no_of_babies_born);
5277 END IF;
5278
5279 l_parental_days_remaining := l_max_parental_days_80 - nvl(p_parental_bal_days,0);
5280 l_parental_days_remaining := l_parental_days_remaining - nvl(l_ptm_paternity_days,0) - nvl(l_ptm_pt_paternity_days,0);
5281 l_parental_days_remaining := l_parental_days_remaining - nvl(l_pt_maternity_sum,0);
5282
5283 IF l_parental_days_remaining < 0 THEN
5284 l_parental_days_remaining := 0;
5285 END IF;
5286
5287 IF nvl(l_ptm_percentage,0) > 0 THEN
5288 l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_ptm_percentage));
5289
5290 END IF;
5291 /*IF l_duration > ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum)) THEN
5292 p_parental_days := ( l_max_parental_days_80 - ( p_parental_bal_days + l_maternity_sum));*/
5293 IF l_duration > l_parental_days_remaining THEN
5294 p_parental_days := l_parental_days_remaining;
5295 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5296 ELSE
5297 p_parental_days := l_duration;
5298 END IF;
5299
5300 END IF;
5301 --p_parental_days := p_parental_days * trunc((l_ptm_percentage/100),2);
5302 p_parental_days := round(p_parental_days * (l_ptm_percentage/100),2);
5303 -- If override element exists for the adoption absence then use the override value.
5304 IF l_override_ss_days IS NOT NULL THEN
5305 p_parental_days := l_override_ss_days;
5306 IF p_parental_days > l_parental_days_remaining THEN
5307 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5308 END IF ;
5309 END IF;
5310
5311
5312 -- Daily Rate calculation
5313 -- Calculation of G rate
5314
5315 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
5316 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
5317
5318 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
5319
5320 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
5321 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
5322
5323 /* End Bug Fix : 5380121 */
5324 /* Pgopal - to get the initial absence start date*/
5325 IF ( l_initial_absence = 'N') THEN
5326 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
5327 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
5328 CLOSE csr_get_intial_abs_st_date;
5329 ELSE
5330 l_initial_abs_st_date := p_abs_start_date;
5331 END IF ;
5332
5333 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
5334 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
5335 CLOSE csr_intial_abs_pay_stdt;
5336
5337 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
5338 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
5339
5340 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
5341 IF l_gen_hour_sal = 'S' THEN
5342
5343 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
5344 (p_assignment_id, p_effective_date, 'Contractual Earnings',
5345 'R', 'D', l_rate, l_error_message, null, null);*/
5346 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
5347 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
5348 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
5349 'R', 'D', l_rate, l_error_message, null, null);
5350
5351
5352 -- Override social security date was present.
5353 IF l_override_ss_rate IS NOT NULL THEN
5354 l_social_security_rate := l_override_ss_rate;
5355 ELSE
5356 l_social_security_rate := l_rate;
5357 END IF;
5358
5359 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
5360 IF l_gen_restrict_ss_sl = 'Y' THEN
5361 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5362 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5363 END IF;
5364 END IF;
5365
5366 -- if restrict daily rate to social security is not set then
5367 IF l_gen_restrict_dr_ss = 'N' THEN
5368
5369 -- (absence pay base * 12) / 260;
5370 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
5371
5372 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
5373 IF l_gen_restrict_empr_sl = 'Y' THEN
5374 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5375 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5376 END IF;
5377 END IF;
5378
5379 -- if restrict daily rate to social security is no then pick whichever is
5380 -- less between historic and daily rate.
5381 IF l_social_security_rate > l_empr_daily_rate THEN
5382 l_reclaim_daily_rate := l_empr_daily_rate;
5383 ELSE
5384 l_reclaim_daily_rate := l_social_security_rate;
5385 END IF;
5386 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
5387 ELSE
5388 l_empr_daily_rate := l_social_security_rate;
5389 l_reclaim_daily_rate := l_social_security_rate;
5390
5391
5392 END IF;
5393
5394 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
5395 ELSIF l_gen_hour_sal = 'H' THEN
5396 p_ear_value := 0;
5397 IF p_hourly_paid IN ('W', 'B') THEN
5398
5399
5400 -- Ignore public holidays if the one present in between absence start and end dates.
5401 l_include_event := 'Y';
5402 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
5403 /* pdavidra - bug 5330066 - redused the start date parameter by 1*/
5404 /* pgopal - Bug 5393827 and 5349713 fix - taking the initial absence start date instead
5405 of payroll start date to get the last 4 weeks worked days*/
5406
5407 /* BUG Fix 5346832 : Start
5408 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
5409 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
5410 for hr_loc_work_schedule.calc_sch_based_dur */
5411
5412 /*
5413 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5414 ( p_assignment_id, l_days_or_hours, l_include_event,
5415 (l_initial_abs_st_date - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
5416 l_end_time_char, l_duration
5417 );
5418 */
5419
5420 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5421 ( p_assignment_id, l_days_or_hours, l_include_event,
5422 greatest(l_dateofjoin,(l_initial_abs_pay_stdt - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
5423 l_end_time_char, l_duration
5424 );
5425
5426 /* BUG Fix 5346832 : End */
5427
5428 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
5429 BEGIN
5430 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
5431 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
5432 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
5433 ( (l_initial_abs_pay_stdt-1) - date_start )+1
5434 WHEN date_end = date_start THEN
5435 1
5436 ELSE (date_end - date_start) + 1 END ) AS Days_diff
5437 INTO l_abs_worked_days
5438 FROM per_absence_attendances
5439 WHERE person_id = p_person_id
5440 AND date_start < (l_initial_abs_pay_stdt-1)
5441 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
5442 AND date_start IS NOT NULL
5443 AND date_end IS NOT NULL ;
5444 EXCEPTION
5445 WHEN NO_DATA_FOUND THEN
5446 l_abs_worked_days := 0;
5447 WHEN OTHERS THEN
5448 l_abs_worked_days := 0;
5449 END;
5450
5451 l_duration := l_duration - nvl(l_abs_worked_days, 0);
5452
5453 /* BUG Fix 5346832 : Start */
5454
5455 IF (l_duration > 0) THEN
5456 l_social_security_rate := ( p_4weeks_paybase / l_duration);
5457 ELSE
5458 l_social_security_rate := 0 ;
5459 END IF;
5460
5461 /* BUG Fix 5346832 : End */
5462
5463
5464 -- Override social security date was present.
5465 IF l_override_ss_rate IS NOT NULL THEN
5466 l_social_security_rate := l_override_ss_rate;
5467 END IF;
5468 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
5469 IF l_gen_restrict_ss_sl = 'Y' THEN
5470 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5471 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5472 END IF;
5473 END IF;
5474
5475 l_empr_daily_rate := l_social_security_rate;
5476 l_reclaim_daily_rate := l_social_security_rate;
5477 ELSIF p_hourly_paid = 'M' THEN
5478 /* knelli
5479 IF length(l_msg_error) > 1 THEN
5480 l_msg_error := 'Error7';
5481 END IF;*/
5482 l_msg_error := to_char(7);
5483 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
5484 -- Previous 4 weeks period logic will not work.
5485 END IF;
5486 END IF;
5487
5488 p_parental_rate := l_reclaim_daily_rate ;
5489 /* knelli added logic */
5490 /*IF l_m_compensation_rate = 80 THEN*/
5491 /*pgopal Bug 5355910 fix*/
5492 IF l_ptm_compensation_rate = 80 THEN
5493 p_parental_rate := p_parental_rate * 0.8;
5494 END IF;
5495 p_parental_comprate := l_ptm_compensation_rate ;
5496 -- Reusing the existing siciness output variables for adoption
5497 p_rec_total_days := p_parental_days;
5498 p_rec_daily_rate := p_parental_comprate;
5499 p_ss_daily_rate := p_parental_rate;
5500
5501
5502 l_include_event := 'N';
5503 -- Calculating actual sickness days through work schedule
5504 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5505 ( p_assignment_id, l_days_or_hours, l_include_event,
5506 p_prorate_start, p_prorate_end, l_start_time_char,
5507 l_end_time_char, l_duration
5508 );
5509 l_actual_cal_days := nvl(l_duration,0);
5510 -- Calculate Earnings Adjustment value
5511 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
5512 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * p_parental_days;
5513 p_ear_startdt := p_prorate_start;
5514 p_ear_enddt := p_prorate_end;
5515 p_ear_value := nvl(p_ear_value,0);
5516
5517 IF l_gen_hour_sal = 'H' THEN
5518 p_ear_value := 0;
5519 END IF;
5520
5521 IF l_gen_rate_option = 'DRATE_OPT1' THEN
5522 p_rate_option1 := 'Y';
5523 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
5524 p_rate_option2 := 'Y';
5525 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
5526 p_rate_option3 := 'Y';
5527 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
5528 p_rate_option4 := 'Y';
5529 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
5530 p_rate_option5 := 'Y';
5531 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
5532 p_rate_option6 := 'Y';
5533 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
5534 p_rate_option7 := 'Y';
5535 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
5536 p_rate_option8 := 'Y';
5537 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
5538 p_rate_option9 := 'Y';
5539 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
5540 p_rate_option10 := 'Y';
5541 ELSE
5542 p_rate_option1 := null;
5543 p_rate_option2 := null;
5544 p_rate_option3 := null;
5545 p_rate_option4 := null;
5546 p_rate_option5 := null;
5547 p_rate_option6 := null;
5548 p_rate_option7 := null;
5549 p_rate_option8 := null;
5550 p_rate_option9 := null;
5551 p_rate_option10 := null;
5552 END IF;
5553 p_abs_error := l_msg_error ;
5554
5555 /* Bug Fix 5349636 : Start */
5556
5557 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
5558 IF p_parental_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
5559 -- No social security period will be paid.
5560 p_rec_total_days := 0;
5561 p_rec_daily_rate := 0;
5562 p_ss_daily_rate := 0;
5563 p_ear_value := 0;
5564 l_msg_error := to_char(11); /* 50% G Message */
5565 p_abs_error := l_msg_error ;
5566 END IF;
5567
5568 /* Bug Fix 5349636 : End */
5569
5570 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
5571 -- Reusing the existing siciness output variables for adoption
5572
5573 p_rec_total_days := 0;
5574 p_rec_daily_rate := 0;
5575 p_ss_daily_rate := 0;
5576 p_ear_value := 0;
5577 p_abs_error := l_msg_error ;
5578
5579 END IF; -- Reimburse from social security
5580
5581 /***************************************************************************
5582 ADOPTION ABSENCE CATEGORY
5583 ****************************************************************************/
5584
5585 ELSIF l_abs_category_code = 'IE_AL' THEN
5586 -- Fetch EIT values from absence payment details form
5587
5588 BEGIN
5589 /* Bug Fix 5380091 : Start */
5590
5591 -- Commenting the cursor for changes in the segments
5592
5593 /*
5594 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') AS Dateofadoption
5595 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Dateofbirth
5596 ,to_number(PAA.ABS_INFORMATION3) AS Comprate
5597 ,PAA.ABS_INFORMATION4 AS Use_ss_rate
5598 ,PAA.ABS_INFORMATION5 AS Daily_rate_option
5599 ,PAA.ABS_INFORMATION6 AS dummy
5600 INTO l_adopt_doa
5601 ,l_adopt_dob
5602 ,l_adopt_comprate
5603 ,l_abs_restrict_dr_ss
5604 ,l_abs_daily_rate
5605 ,l_dummy
5606 FROM PER_ABSENCE_ATTENDANCES PAA
5607 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
5608
5609 EXCEPTION
5610 WHEN OTHERS THEN
5611
5612 l_adopt_doa := null;
5613 l_adopt_dob := null;
5614 l_adopt_comprate := null;
5615 l_restrict_dr_ss := null;
5616 l_abs_daily_rate := null;
5617 END;
5618
5619 */
5620
5621 -- rewriting cursor for changed segments
5622 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') AS Dateofadoption
5623 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Dateofbirth
5624 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) AS Comprate
5625 ,PAA.ABS_INFORMATION4 AS reimb_ss
5626 ,PAA.ABS_INFORMATION5 AS Use_ss_rate
5627 ,PAA.ABS_INFORMATION6 AS restrict_ss_sl
5628 ,PAA.ABS_INFORMATION7 AS dummy
5629 ,PAA.ABS_INFORMATION8 AS Daily_rate_option
5630 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION9) AS NumOfChildren
5631 ,PAA.ABS_INFORMATION15 AS intial_absence
5632 ,PAA.ABS_INFORMATION16 AS intial_abs_attend_id
5633 INTO l_adopt_doa
5634 ,l_adopt_dob
5635 ,l_adopt_comprate
5636 ,l_abs_reimb_ss
5637 ,l_abs_restrict_dr_ss
5638 ,l_abs_restrict_ss_sl
5639 ,l_dummy
5640 ,l_abs_daily_rate
5641 ,l_no_of_children
5642 ,l_initial_absence
5643 ,l_initial_abs_attend_id
5644 FROM PER_ABSENCE_ATTENDANCES PAA
5645 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
5646
5647 EXCEPTION
5648 WHEN OTHERS THEN
5649
5650 l_adopt_doa := null;
5651 l_adopt_dob := null;
5652 l_adopt_comprate := null;
5653 l_abs_reimb_ss := null;
5654 l_abs_restrict_dr_ss := null;
5655 l_abs_restrict_ss_sl := null;
5656 l_dummy := null;
5657 --l_restrict_dr_ss := null;
5658 l_abs_daily_rate := null;
5659 l_no_of_children := null;
5660 l_initial_absence :=NULL;
5661 l_initial_abs_attend_id := NULL ;
5662
5663 END;
5664
5665 /* Bug Fix 5380091 : End */
5666
5667 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
5668 l_gen_reimb_ss := nvl(nvl(nvl(l_abs_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
5669 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_abs_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
5670 l_gen_rate_option := nvl(nvl(l_abs_daily_rate, l_per_daily_rate), l_le_daily_rate);
5671
5672 /* Start Bug Fix : 5282895 */
5673
5674 l_adopt_comprate := nvl(l_adopt_comprate,100) ;
5675
5676 /* End Bug Fix : 5282895 */
5677
5678
5679 /* Bug Fix 5380091 : Start -- Defaulting value for l_gen_restrict_ss_sl (Reclaimable Pay Maximum 6G). */
5680
5681 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_abs_restrict_ss_sl, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
5682 l_gen_no_of_children := nvl(l_no_of_children , 1 ) ;
5683
5684 /* Bug Fix 5380091 : End */
5685
5686 -- If reimburse from social security is set then adoption leave will be paid.
5687 IF l_gen_reimb_ss = 'Y' THEN
5688 -- Calling override to get override days and daily rate
5689 l_over_return := get_override_details
5690 ( p_assignment_id,p_effective_date,p_abs_start_date,
5691 p_abs_end_date, p_abs_categorycode, l_override_start_date,
5692 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
5693 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
5694 );
5695 /* Multiple override element attached against one absence element. ie) *
5696 * One or more override entry exists with same start and end date */
5697 IF (l_over_return = -1) THEN
5698 /* knelli
5699 IF length(l_msg_error) > 1 THEN
5700 l_msg_error := 'Error5';
5701 END IF;*/
5702 l_msg_error := to_char(5);
5703 p_abs_error := l_msg_error;
5704 RETURN 1;
5705 END IF;
5706 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
5707 l_msg_error := to_char(13);
5708 END IF;
5709 IF nvl(l_override_empr_days,0) > 0 THEN
5710 l_msg_error := to_char(14);
5711 p_abs_error := l_msg_error;
5712 RETURN 1;
5713 END IF;
5714 p_work_pattern := '5DAY';
5715 -- To find out number of days adoption leave has been taken in the current payroll period
5716 BEGIN
5717 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
5718 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
5719 INTO l_adopt_sum
5720 FROM per_absence_attendances paa, per_absence_attendance_types pat
5721 WHERE paa.person_id = p_person_id
5722 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
5723 AND paa.date_end < p_abs_start_date
5724 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
5725 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
5726 AND pat.absence_category = 'IE_AL'
5727 ORDER BY paa.date_end DESC ;
5728 EXCEPTION
5729 WHEN OTHERS THEN
5730 l_adopt_sum := null;
5731 END;
5732
5733
5734
5735 -- Calculate actual days based on 5 day week pattern.
5736 p_work_pattern := '5DAY';
5737 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
5738 -- If override element exists for the adoption absence then use the override value.
5739 /*IF l_override_ss_days IS NOT NULL THEN
5740 l_duration := l_override_ss_days;
5741 END IF;*/
5742
5743 IF l_adopt_comprate = 80 THEN
5744 -- To fetch adoption maximum limit based on the compensation rate chosen.
5745 OPEN GLB_VALUE ('NO_ADOPTION_EIGHTY', p_abs_start_date );
5746 FETCH GLB_VALUE INTO l_adopt_glb_80;
5747 CLOSE GLB_VALUE;
5748
5749 /* Bug Fix 5346832 : Start */
5750
5751 -- To fetch adoption days for each additional child based on the compensation rate chosen.
5752 OPEN GLB_VALUE ('NO_ADOPTION_EIGHTY_ADDITIONAL_CHILD', p_abs_start_date);
5753 FETCH GLB_VALUE INTO l_adopt_glb_80_add_child;
5754 CLOSE GLB_VALUE;
5755
5756 /* knelli commented
5757 IF l_duration > ( l_adopt_glb_80 - ( p_adopt_bal_days + l_adopt_sum)) THEN
5758 p_adopt_days := ( l_adopt_glb_80 - ( p_adopt_bal_days + l_adopt_sum));
5759 ELSE
5760 p_adopt_days := l_duration;
5761 END IF;*/
5762 /* knelli added code */
5763
5764 -- l_parental_days_remaining := l_adopt_glb_80 - nvl(p_adopt_bal_days,0);
5765
5766 l_parental_days_remaining := l_adopt_glb_80 + (l_adopt_glb_80_add_child * (l_gen_no_of_children - 1)) - nvl(p_adopt_bal_days,0);
5767 /* Bug Fix 5346832 : End */
5768
5769 l_parental_days_remaining := l_parental_days_remaining - nvl(l_adopt_sum,0);
5770 IF l_parental_days_remaining < 0 THEN
5771 l_parental_days_remaining := 0;
5772 END IF;
5773
5774 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
5775 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
5776 IF l_duration > l_parental_days_remaining THEN
5777 p_adopt_days := l_parental_days_remaining;
5778 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5779 ELSE
5780 p_adopt_days := l_duration;
5781 END IF;
5782
5783 ELSIF l_adopt_comprate = 100 THEN
5784 -- To fetch adoption maximum limit based on the compensation rate chosen.
5785 OPEN GLB_VALUE ('NO_ADOPTION_HUNDRED', p_abs_start_date);
5786 FETCH GLB_VALUE INTO l_adopt_glb_100;
5787 CLOSE GLB_VALUE;
5788
5789 /* Bug Fix 5346832 : Start */
5790
5791 -- To fetch adoption days for each additional child based on the compensation rate chosen.
5792 OPEN GLB_VALUE ('NO_ADOPTION_HUNDRED_ADDITIONAL_CHILD', p_abs_start_date);
5793 FETCH GLB_VALUE INTO l_adopt_glb_100_add_child;
5794 CLOSE GLB_VALUE;
5795
5796 /* knelli commented code
5797 IF l_duration > ( l_adopt_glb_100 - ( p_adopt_bal_days + l_adopt_sum)) THEN
5798 p_adopt_days := ( l_adopt_glb_100 - ( p_adopt_bal_days + l_adopt_sum));
5799 ELSE
5800 p_adopt_days := l_duration;
5801 END IF;*/
5802 /* knelli added code */
5803
5804 -- l_parental_days_remaining := l_adopt_glb_100 - nvl(p_adopt_bal_days,0);
5805
5806 l_parental_days_remaining := l_adopt_glb_100 + (l_adopt_glb_100_add_child * (l_gen_no_of_children - 1)) - nvl(p_adopt_bal_days,0);
5807 /* Bug Fix 5346832 : End */
5808
5809 l_parental_days_remaining := l_parental_days_remaining - nvl(l_adopt_sum,0);
5810 IF l_parental_days_remaining < 0 THEN
5811 l_parental_days_remaining := 0;
5812 END IF;
5813
5814 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
5815 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
5816 IF l_duration > l_parental_days_remaining THEN
5817 p_adopt_days := l_parental_days_remaining;
5818 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5819 ELSE
5820 p_adopt_days := l_duration;
5821 END IF;
5822
5823 END IF;
5824 -- If override element exists for the adoption absence then use the override value.
5825 IF l_override_ss_days IS NOT NULL THEN
5826 p_adopt_days := l_override_ss_days;
5827 IF p_adopt_days > l_parental_days_remaining THEN
5828 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
5829 END IF ;
5830 END IF;
5831 -- Daily Rate calculation
5832 -- Calculation of G rate
5833
5834 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
5835 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
5836
5837 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
5838
5839 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
5840 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
5841
5842 /* End Bug Fix : 5380121 */
5843 /* pgopal - to get the initial absence start date*/
5844 IF ( l_initial_absence = 'N') THEN
5845 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
5846 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
5847 CLOSE csr_get_intial_abs_st_date;
5848 ELSE
5849 l_initial_abs_st_date := p_abs_start_date;
5850 END IF ;
5851
5852 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
5853 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
5854 CLOSE csr_intial_abs_pay_stdt;
5855
5856 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
5857 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
5858
5859
5860 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
5861 IF l_gen_hour_sal = 'S' THEN
5862
5863 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
5864 (p_assignment_id, p_effective_date, 'Contractual Earnings',
5865 'R', 'D', l_rate, l_error_message, null, null);*/
5866 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
5867 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
5868 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
5869 'R', 'D', l_rate, l_error_message, null, null);
5870
5871 -- Override social security date was present.
5872 IF l_override_ss_rate IS NOT NULL THEN
5873 l_social_security_rate := l_override_ss_rate;
5874 ELSE
5875 l_social_security_rate := l_rate;
5876 END IF;
5877
5878 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
5879 IF l_gen_restrict_ss_sl = 'Y' THEN
5880 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5881 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5882 END IF;
5883
5884 END IF;
5885 -- if restrict daily rate to social security is not set then
5886 IF l_gen_restrict_dr_ss = 'N' THEN
5887
5888 -- (absence pay base * 12) / 260;
5889 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
5890 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
5891 IF l_gen_restrict_empr_sl = 'Y' THEN
5892 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5893 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5894 END IF;
5895 END IF;
5896
5897 -- if restrict daily rate to social security is no then pick whichever is
5898 -- less between historic and daily rate.
5899 IF l_social_security_rate > l_empr_daily_rate THEN
5900 l_reclaim_daily_rate := l_empr_daily_rate;
5901 ELSE
5902 l_reclaim_daily_rate := l_social_security_rate;
5903 END IF;
5904 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
5905 ELSE
5906 l_empr_daily_rate := l_social_security_rate;
5907 l_reclaim_daily_rate := l_social_security_rate;
5908
5909 END IF;
5910
5911 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
5912 ELSIF l_gen_hour_sal = 'H' THEN
5913 p_ear_value := 0;
5914 IF p_hourly_paid IN ('W', 'B') THEN
5915
5916
5917 -- Ignore public holidays if the one present in between absence start and end dates.
5918 l_include_event := 'Y';
5919 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
5920 /* pdavidra - bug 5330066 - redused the start date parameter by 1*/
5921 /* pgopal - Bug 5393827 and 5349713 fix - taking the initial absence start date instead
5922 of payroll start date to get the last 4 weeks worked days*/
5923
5924 /* BUG Fix 5346832 : Start
5925 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
5926 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
5927 for hr_loc_work_schedule.calc_sch_based_dur */
5928
5929 /*
5930 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5931 ( p_assignment_id, l_days_or_hours, l_include_event,
5932 (l_initial_abs_st_date - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
5933 l_end_time_char, l_duration
5934 );
5935 */
5936
5937 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
5938 ( p_assignment_id, l_days_or_hours, l_include_event,
5939 greatest(l_dateofjoin,(l_initial_abs_pay_stdt - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
5940 l_end_time_char, l_duration
5941 );
5942
5943 /* BUG Fix 5346832 : End */
5944
5945 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
5946 BEGIN
5947 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
5948 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
5949 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
5950 ( (l_initial_abs_pay_stdt-1) - date_start )+1
5951 WHEN date_end = date_start THEN
5952 1
5953 ELSE (date_end - date_start) + 1 END ) AS Days_diff
5954 INTO l_abs_worked_days
5955 FROM per_absence_attendances
5956 WHERE person_id = p_person_id
5957 AND date_start < (l_initial_abs_pay_stdt-1)
5958 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
5959 AND date_start IS NOT NULL
5960 AND date_end IS NOT NULL ;
5961 EXCEPTION
5962 WHEN NO_DATA_FOUND THEN
5963 l_abs_worked_days := 0;
5964 WHEN OTHERS THEN
5965 l_abs_worked_days := 0;
5966 END;
5967 l_duration := l_duration - nvl(l_abs_worked_days, 0);
5968
5969
5970 /* BUG Fix 5346832 : Start */
5971
5972 IF (l_duration > 0) THEN
5973 l_social_security_rate := ( p_4weeks_paybase / l_duration);
5974 ELSE
5975 l_social_security_rate := 0 ;
5976 END IF;
5977
5978 /* BUG Fix 5346832 : End */
5979
5980
5981 -- Override social security date was present.
5982 IF l_override_ss_rate IS NOT NULL THEN
5983 l_social_security_rate := l_override_ss_rate;
5984 END IF;
5985 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
5986 IF l_gen_restrict_ss_sl = 'Y' THEN
5987 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
5988 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
5989 END IF;
5990 END IF;
5991
5992 l_empr_daily_rate := l_social_security_rate;
5993 l_reclaim_daily_rate := l_social_security_rate;
5994
5995 ELSIF p_hourly_paid = 'M' THEN
5996 /* knelli
5997 IF length(l_msg_error) > 1 THEN
5998 l_msg_error := 'Error7';
5999 END IF;*/
6000 l_msg_error := to_char(7);
6001 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
6002 -- Previous 4 weeks period logic will not work.
6003 END IF;
6004 END IF;
6005
6006 p_adopt_rate := l_reclaim_daily_rate ;
6007 /* knelli added logic for bug fix 5284260 */
6008 IF l_adopt_comprate = 80 THEN
6009 p_adopt_rate := p_adopt_rate * 0.8;
6010 END IF;
6011 p_adopt_comprate := l_adopt_comprate ;
6012 -- Reusing the existing siciness output variables for adoption
6013 p_rec_total_days := p_adopt_days;
6014 p_rec_daily_rate := p_adopt_comprate;
6015 p_ss_daily_rate := p_adopt_rate;
6016
6017 l_include_event := 'N';
6018 -- Calculating actual sickness days through work schedule
6019 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
6020 ( p_assignment_id, l_days_or_hours, l_include_event,
6021 p_prorate_start, p_prorate_end, l_start_time_char,
6022 l_end_time_char, l_duration
6023 );
6024 l_actual_cal_days := nvl(l_duration,0);
6025 -- Calculate Earnings Adjustment value
6026 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
6027 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * l_actual_cal_days;
6028 p_ear_startdt := p_prorate_start;
6029 p_ear_enddt := p_prorate_end;
6030 p_ear_value := nvl(p_ear_value,0);
6031
6032 IF l_gen_hour_sal = 'H' THEN
6033 p_ear_value := 0;
6034 END IF;
6035
6036 IF l_gen_rate_option = 'DRATE_OPT1' THEN
6037 p_rate_option1 := 'Y';
6038 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
6039 p_rate_option2 := 'Y';
6040 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
6041 p_rate_option3 := 'Y';
6042 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
6043 p_rate_option4 := 'Y';
6044 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
6045 p_rate_option5 := 'Y';
6046 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
6047 p_rate_option6 := 'Y';
6048 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
6049 p_rate_option7 := 'Y';
6050 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
6051 p_rate_option8 := 'Y';
6052 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
6053 p_rate_option9 := 'Y';
6054 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
6055 p_rate_option10 := 'Y';
6056 ELSE
6057 p_rate_option1 := null;
6058 p_rate_option2 := null;
6059 p_rate_option3 := null;
6060 p_rate_option4 := null;
6061 p_rate_option5 := null;
6062 p_rate_option6 := null;
6063 p_rate_option7 := null;
6064 p_rate_option8 := null;
6065 p_rate_option9 := null;
6066 p_rate_option10 := null;
6067 END IF;
6068 p_abs_error := l_msg_error ;
6069
6070 /* Bug Fix 5349636 : Start */
6071
6072 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
6073 IF p_adopt_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
6074 -- No social security period will be paid.
6075 p_rec_total_days := 0;
6076 p_rec_daily_rate := 0;
6077 p_ss_daily_rate := 0;
6078 p_ear_value := 0;
6079 l_msg_error := to_char(11); /* 50% G Message */
6080 p_abs_error := l_msg_error ;
6081 END IF;
6082
6083 /* Bug Fix 5349636 : End */
6084
6085 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
6086 -- Reusing the existing siciness output variables for adoption
6087 p_rec_total_days := 0;
6088 p_rec_daily_rate := 0;
6089 p_ss_daily_rate := 0;
6090 p_ear_value := 0;
6091 p_abs_error := l_msg_error ;
6092 END IF; -- Reimburse from social security
6093
6094 ELSIF l_abs_category_code = 'PTA' THEN
6095 -- Fetch EIT values from absence payment details form
6096
6097 BEGIN
6098 /* Bug Fix 5346832 : Start */
6099 /*
6100 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') AS Dateofadoption
6101 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Dateofbirth
6102 ,to_number(PAA.ABS_INFORMATION3) AS PartTimePercent
6103 ,to_number(PAA.ABS_INFORMATION4) AS Comprate
6104 ,PAA.ABS_INFORMATION5 AS reimurse_ss--Use_ss_rate
6105 ,PAA.ABS_INFORMATION6 AS use_ss_rate
6106 ,PAA.ABS_INFORMATION7 AS reclaim_6g
6107 ,PAA.ABS_INFORMATION9 AS dailtrate
6108 INTO l_adopt_doa
6109 ,l_adopt_dob
6110 ,l_adopt_ptp
6111 ,l_adopt_comprate
6112 ,l_adopt_reimb_ss
6113 ,l_adopt_restrict_dr_ss
6114 ,l_adopt_restrict_empr_sl
6115 ,l_adopt_daily_rate
6116 FROM PER_ABSENCE_ATTENDANCES PAA
6117 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
6118
6119 EXCEPTION
6120 WHEN OTHERS THEN
6121
6122 l_adopt_doa := NULL;
6123 l_adopt_dob := NULL;
6124 l_adopt_ptp := NULL;
6125 l_adopt_comprate := NULL;
6126 l_adopt_reimb_ss := NULL;
6127 l_adopt_restrict_dr_ss := NULL;
6128 l_adopt_restrict_empr_sl := NULL;
6129 l_adopt_daily_rate := NULL;
6130 END;
6131 */
6132
6133 SELECT to_date(PAA.ABS_INFORMATION1,'yyyy/mm/dd hh24:mi:ss') AS Dateofadoption
6134 ,to_date(PAA.ABS_INFORMATION2,'yyyy/mm/dd hh24:mi:ss') AS Dateofbirth
6135 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION3) AS PartTimePercent
6136 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION4) AS Comprate
6137 ,PAA.ABS_INFORMATION5 AS reimurse_ss--Use_ss_rate
6138 ,PAA.ABS_INFORMATION6 AS use_ss_rate
6139 ,PAA.ABS_INFORMATION7 AS reclaim_6g
6140 ,PAA.ABS_INFORMATION9 AS dailtrate
6141 ,fnd_number.canonical_to_number(PAA.ABS_INFORMATION10) AS NumOfChildren
6142 ,PAA.ABS_INFORMATION15 AS intial_absence
6143 ,PAA.ABS_INFORMATION16 AS intial_abs_attend_id
6144 INTO l_adopt_doa
6145 ,l_adopt_dob
6146 ,l_adopt_ptp
6147 ,l_adopt_comprate
6148 ,l_adopt_reimb_ss
6149 ,l_adopt_restrict_dr_ss
6150 ,l_adopt_restrict_empr_sl
6151 ,l_adopt_daily_rate
6152 ,l_no_of_children
6153 ,l_initial_absence
6154 ,l_initial_abs_attend_id
6155 FROM PER_ABSENCE_ATTENDANCES PAA
6156 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
6157
6158 EXCEPTION
6159 WHEN OTHERS THEN
6160
6161 l_adopt_doa := NULL;
6162 l_adopt_dob := NULL;
6163 l_adopt_ptp := NULL;
6164 l_adopt_comprate := NULL;
6165 l_adopt_reimb_ss := NULL;
6166 l_adopt_restrict_dr_ss := NULL;
6167 l_adopt_restrict_empr_sl := NULL;
6168 l_adopt_daily_rate := NULL;
6169 l_no_of_children := null;
6170 l_initial_absence :=NULL;
6171 l_initial_abs_attend_id := NULL ;
6172 END;
6173
6174 /* Bug Fix 5346832 : End */
6175
6176 /* knelli check for l_adopt_restrict_empr_sl */
6177 l_gen_hour_sal := nvl(nvl(nvl(l_asg_hour_sal,l_hourly_salaried), l_le_hour_sal), 'S');
6178 l_gen_reimb_ss := nvl(nvl(nvl(l_adopt_reimb_ss, l_reimb_ss), l_le_reimb_ss), 'N');
6179 l_gen_restrict_dr_ss := nvl(nvl(nvl(l_adopt_restrict_dr_ss, l_restrict_dr_ss), l_le_restrict_dr_ss), 'Y');
6180 l_gen_rate_option := nvl(nvl(l_adopt_daily_rate, l_per_daily_rate), l_le_daily_rate);
6181
6182 /* Start Bug Fix : 5282895 */
6183
6184 l_adopt_comprate := nvl(l_adopt_comprate,100) ;
6185
6186 /* End Bug Fix : 5282895 */
6187
6188 /* Bug Fix 5380091 : Start -- Defaulting value for l_gen_restrict_ss_sl (Reclaimable Pay Maximum 6G). */
6189
6190 l_gen_restrict_ss_sl := nvl(nvl(nvl(l_adopt_restrict_empr_sl, l_restrict_ss_sl), l_le_restrict_ss_sl), 'Y');
6191
6192 /* Bug Fix 5380091 : End */
6193
6194 /* Bug Fix 5346832 : Start */
6195 l_gen_no_of_children := nvl(l_no_of_children , 1 ) ;
6196 /* Bug Fix 5346832 : End */
6197
6198
6199 -- If reimburse from social security is set then adoption leave will be paid.
6200 IF l_gen_reimb_ss = 'Y' THEN
6201 -- Calling override to get override days and daily rate
6202 l_over_return := get_override_details
6203 ( p_assignment_id,p_effective_date,p_abs_start_date,
6204 p_abs_end_date, p_abs_categorycode, l_override_start_date,
6205 l_override_end_date,l_override_empr_rate, l_override_ss_rate,
6206 l_override_reclaim_rate, l_override_empr_days, l_override_ss_days
6207 );
6208 /* Multiple override element attached against one absence element. ie) *
6209 * One or more override entry exists with same start and end date */
6210 IF (l_over_return = -1) THEN
6211 /* knelli
6212 IF length(l_msg_error) > 1 THEN
6213 l_msg_error := 'Error5';
6214 END IF;*/
6215 l_msg_error := to_char(5);
6216 p_abs_error := l_msg_error;
6217 RETURN 1;
6218 END IF;
6219 IF (nvl(l_override_empr_days,0) + nvl(l_override_ss_days,0)) > (p_prorate_end - p_prorate_start + 1) THEN
6220 l_msg_error := to_char(13);
6221 END IF;
6222 IF nvl(l_override_empr_days,0) > 0 THEN
6223 l_msg_error := to_char(14);
6224 p_abs_error := l_msg_error;
6225 RETURN 1;
6226 END IF;
6227 -- To find out number of days adoption leave has been taken in the current payroll period
6228 BEGIN
6229 SELECT SUM(DECODE(paa.date_start, paa.date_end, 1,
6230 get_weekdays(greatest(p_pay_start_date, paa.date_start), paa.date_end, p_work_pattern) )) AS days_diff
6231 INTO l_adopt_sum
6232 FROM per_absence_attendances paa, per_absence_attendance_types pat
6233 WHERE paa.person_id = p_person_id
6234 AND paa.date_end BETWEEN p_pay_start_date AND p_pay_end_date
6235 AND paa.date_end < p_abs_start_date
6236 AND paa.date_start IS NOT NULL AND paa.date_end IS NOT NULL
6237 AND paa.absence_attendance_type_id = pat.absence_attendance_type_id
6238 AND pat.absence_category = 'PTA'
6239 ORDER BY paa.date_end DESC ;
6240 EXCEPTION
6241 WHEN OTHERS THEN
6242 l_adopt_sum := null;
6243 END;
6244
6245
6246
6247 -- Calculate actual days based on 5 day week pattern.
6248 p_work_pattern := '5DAY';
6249 l_duration := get_weekdays(p_prorate_start, p_prorate_end, p_work_pattern);
6250 -- If override element exists for the adoption absence then use the override value.
6251 /*IF l_override_ss_days IS NOT NULL THEN
6252 l_duration := l_override_ss_days;
6253 END IF;*/
6254
6255 IF l_adopt_comprate = 80 THEN
6256 -- To fetch adoption maximum limit based on the compensation rate chosen.
6257 OPEN GLB_VALUE ('NO_ADOPTION_EIGHTY', p_abs_start_date );
6258 FETCH GLB_VALUE INTO l_adopt_glb_80;
6259 CLOSE GLB_VALUE;
6260
6261 /* Bug Fix 5346832 : Start */
6262
6263 -- To fetch adoption days for each additional child based on the compensation rate chosen.
6264 OPEN GLB_VALUE ('NO_ADOPTION_EIGHTY_ADDITIONAL_CHILD', p_abs_start_date);
6265 FETCH GLB_VALUE INTO l_adopt_glb_80_add_child;
6266 CLOSE GLB_VALUE;
6267
6268 /* knelli commented
6269 IF l_duration > ( l_adopt_glb_80 - ( p_adopt_bal_days + l_adopt_sum)) THEN
6270 p_adopt_days := ( l_adopt_glb_80 - ( p_adopt_bal_days + l_adopt_sum));
6271 ELSE
6272 p_adopt_days := l_duration;
6273 END IF;*/
6274 /* knelli added code */
6275
6276 -- l_parental_days_remaining := l_adopt_glb_80 - nvl(p_adopt_bal_days,0);
6277
6278 l_parental_days_remaining := l_adopt_glb_80 + (l_adopt_glb_80_add_child * (l_gen_no_of_children - 1)) - nvl(p_adopt_bal_days,0);
6279 /* Bug Fix 5346832 : End */
6280
6281 l_parental_days_remaining := l_parental_days_remaining - nvl(l_adopt_sum,0);
6282 IF l_parental_days_remaining < 0 THEN
6283 l_parental_days_remaining := 0;
6284 END IF;
6285
6286 IF nvl(l_adopt_ptp,0) > 0 THEN
6287
6288 /* Bug Fix 5380082 : Start */
6289
6290 -- l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_adopt_ptp));
6291 -- l_duration := trunc(l_duration * l_adopt_ptp / 100 );
6292 l_duration := round((l_duration * l_adopt_ptp / 100 ),2) ;
6293
6294 /* Bug Fix 5380082 : End */
6295
6296 END IF;
6297
6298 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
6299 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
6300 IF l_duration > l_parental_days_remaining THEN
6301 p_adopt_days := l_parental_days_remaining;
6302 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
6303 ELSE
6304 p_adopt_days := l_duration;
6305 END IF;
6306
6307 ELSIF l_adopt_comprate = 100 THEN
6308 -- To fetch adoption maximum limit based on the compensation rate chosen.
6309 OPEN GLB_VALUE ('NO_ADOPTION_HUNDRED', p_abs_start_date);
6310 FETCH GLB_VALUE INTO l_adopt_glb_100;
6311 CLOSE GLB_VALUE;
6312
6313 /* Bug Fix 5346832 : Start */
6314
6315 -- To fetch adoption days for each additional child based on the compensation rate chosen.
6316 OPEN GLB_VALUE ('NO_ADOPTION_HUNDRED_ADDITIONAL_CHILD', p_abs_start_date);
6317 FETCH GLB_VALUE INTO l_adopt_glb_100_add_child;
6318 CLOSE GLB_VALUE;
6319
6320 /* knelli commented code
6321 IF l_duration > ( l_adopt_glb_100 - ( p_adopt_bal_days + l_adopt_sum)) THEN
6322 p_adopt_days := ( l_adopt_glb_100 - ( p_adopt_bal_days + l_adopt_sum));
6323 ELSE
6324 p_adopt_days := l_duration;
6325 END IF;*/
6326 /* knelli added code */
6327
6328 -- l_parental_days_remaining := l_adopt_glb_100 - nvl(p_adopt_bal_days,0);
6329
6330 l_parental_days_remaining := l_adopt_glb_100 + (l_adopt_glb_100_add_child * (l_gen_no_of_children - 1)) - nvl(p_adopt_bal_days,0);
6331 /* Bug Fix 5346832 : End */
6332
6333 l_parental_days_remaining := l_parental_days_remaining - nvl(l_adopt_sum,0);
6334 IF l_parental_days_remaining < 0 THEN
6335 l_parental_days_remaining := 0;
6336 END IF;
6337
6338 IF nvl(l_adopt_ptp,0) > 0 THEN
6339
6340 /* Bug Fix 5380082 : Start */
6341
6342 -- l_parental_days_remaining := trunc(l_parental_days_remaining * 100/(100-l_adopt_ptp));
6343 -- l_duration := trunc(l_duration * l_adopt_ptp / 100 );
6344 l_duration := round((l_duration * l_adopt_ptp / 100 ),2) ;
6345
6346 /* Bug Fix 5380082 : End */
6347
6348 END IF;
6349
6350 /*IF l_duration > ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum)) THEN
6351 p_parental_days := ( l_max_parental_days_100 - ( p_parental_bal_days + l_maternity_sum));*/
6352 IF l_duration > l_parental_days_remaining THEN
6353 p_adopt_days := l_parental_days_remaining;
6354 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
6355 ELSE
6356 p_adopt_days := l_duration;
6357 END IF;
6358
6359 END IF;
6360 -- If override element exists for the adoption absence then use the override value.
6361 IF l_override_ss_days IS NOT NULL THEN
6362 p_adopt_days := l_override_ss_days;
6363 IF p_adopt_days > l_parental_days_remaining THEN
6364 l_msg_error := to_char(12); /* Legislative limit exhausted Message */
6365 END IF ;
6366 END IF;
6367 -- Daily Rate calculation
6368 -- Calculation of G rate
6369
6370 /* Start Bug Fix : 5380121 - Even if there is a change in the G rate during an absence period because of legislation changes,
6371 the G rate at the beginning of the particular absence only should be considered for calculation of the 6G */
6372
6373 -- l_g_rate := GET_GRATE(p_effective_date, p_assignment_id, p_business_group_id);
6374
6375 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
6376 -- l_g_rate := GET_GRATE(p_abs_start_date, p_assignment_id, p_business_group_id);
6377
6378 /* End Bug Fix : 5380121 */
6379
6380 /* pgopal - to get the initial absence start date*/
6381 IF ( l_initial_absence = 'N') THEN
6382 OPEN csr_get_intial_abs_st_date(l_initial_abs_attend_id);
6383 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
6384 CLOSE csr_get_intial_abs_st_date;
6385 ELSE
6386 l_initial_abs_st_date := p_abs_start_date;
6387 END IF ;
6388
6389 OPEN csr_intial_abs_pay_stdt(p_assignment_id,l_initial_abs_st_date);
6390 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
6391 CLOSE csr_intial_abs_pay_stdt;
6392
6393 -- BUG 5380121 reopened : G rate at the initial absence of the particular absence should be considered
6394 l_g_rate := GET_GRATE(l_initial_abs_st_date, p_assignment_id, p_business_group_id);
6395
6396 -- Calculation of daily rate for salaried employees (based on input value not actual payroll)
6397 IF l_gen_hour_sal = 'S' THEN
6398
6399 /*l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
6400 (p_assignment_id, p_effective_date, 'Contractual Earnings',
6401 'R', 'D', l_rate, l_error_message, null, null);*/
6402 /*pgopal - Bug 5441078 fix - Passing initial absence start date*/
6403 l_return := PQP_RATES_HISTORY_CALC.RATES_HISTORY
6404 (p_assignment_id, l_initial_abs_st_date, 'Contractual Earnings',
6405 'R', 'D', l_rate, l_error_message, null, null);
6406
6407 -- Override social security date was present.
6408 IF l_override_ss_rate IS NOT NULL THEN
6409 l_social_security_rate := l_override_ss_rate;
6410 ELSE
6411 l_social_security_rate := l_rate;
6412 END IF;
6413
6414 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
6415 IF l_gen_restrict_ss_sl = 'Y' THEN
6416 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
6417 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
6418 END IF;
6419
6420 END IF;
6421 -- if restrict daily rate to social security is not set then
6422 IF l_gen_restrict_dr_ss = 'N' THEN
6423
6424 -- (absence pay base * 12) / 260;
6425 l_empr_daily_rate := ( p_sickabs_paybase * p_abs_month ) / p_abs_annual_days ;
6426 -- IF employers pay is greater than 6g then restrict it to 6g if the flag is set
6427 IF l_gen_restrict_empr_sl = 'Y' THEN
6428 IF l_empr_daily_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
6429 l_empr_daily_rate := ((l_g_rate * 6)/ p_abs_annual_days);
6430 END IF;
6431 END IF;
6432
6433 -- if restrict daily rate to social security is no then pick whichever is
6434 -- less between historic and daily rate.
6435 IF l_social_security_rate > l_empr_daily_rate THEN
6436 l_reclaim_daily_rate := l_empr_daily_rate;
6437 ELSE
6438 l_reclaim_daily_rate := l_social_security_rate;
6439 END IF;
6440 -- if restrict daily rate to social security is set then both ss and empr rate will be same.
6441 ELSE
6442 l_empr_daily_rate := l_social_security_rate;
6443 l_reclaim_daily_rate := l_social_security_rate;
6444
6445 END IF;
6446
6447 -- Calculation of Daily rate for Hourly paid employees ( based on input value not actual payroll)
6448 ELSIF l_gen_hour_sal = 'H' THEN
6449 p_ear_value := 0;
6450 IF p_hourly_paid IN ('W', 'B') THEN
6451
6452 -- Ignore public holidays if the one present in between absence start and end dates.
6453 l_include_event := 'Y';
6454 -- Calculate actual days in the previous 4 weeks skipping holidays and weekends.
6455 /* pdavidra - bug 5330066 - redused the start date parameter by 1*/
6456
6457 /* BUG Fix 5346832 : Start
6458 Changing the start date from (l_initial_abs_st_date - p_abs_min_gap)
6459 to greatest(l_dateofjoin,(l_initial_abs_st_date - p_abs_min_gap))
6460 for hr_loc_work_schedule.calc_sch_based_dur */
6461
6462 /*
6463 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
6464 ( p_assignment_id, l_days_or_hours, l_include_event,
6465 (l_initial_abs_st_date - p_abs_min_gap), (l_initial_abs_st_date-1), l_start_time_char,
6466 l_end_time_char, l_duration
6467 );
6468 */
6469
6470 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
6471 ( p_assignment_id, l_days_or_hours, l_include_event,
6472 greatest(l_dateofjoin,(l_initial_abs_pay_stdt - p_abs_min_gap)), (l_initial_abs_pay_stdt-1), l_start_time_char,
6473 l_end_time_char, l_duration
6474 );
6475
6476 /* BUG Fix 5346832 : End */
6477
6478
6479 -- Calculating actual number of absence days in the previous 4 weeks (payroll) periods.
6480 BEGIN
6481 SELECT SUM( CASE WHEN date_start < (l_initial_abs_pay_stdt - p_abs_min_gap) THEN
6482 ( date_end - (l_initial_abs_pay_stdt - p_abs_min_gap) ) +1
6483 WHEN date_end > (l_initial_abs_pay_stdt-1) THEN
6484 ( (l_initial_abs_pay_stdt-1) - date_start )+1
6485 WHEN date_end = date_start THEN
6486 1
6487 ELSE (date_end - date_start) + 1 END ) AS Days_diff
6488 INTO l_abs_worked_days
6489 FROM per_absence_attendances
6490 WHERE person_id = p_person_id
6491 AND date_start < (l_initial_abs_pay_stdt-1)
6492 AND date_end > (l_initial_abs_pay_stdt - p_abs_min_gap)
6493 AND date_start IS NOT NULL
6494 AND date_end IS NOT NULL ;
6495 EXCEPTION
6496 WHEN NO_DATA_FOUND THEN
6497 l_abs_worked_days := 0;
6498 WHEN OTHERS THEN
6499 l_abs_worked_days := 0;
6500 END;
6501 l_duration := l_duration - nvl(l_abs_worked_days, 0);
6502
6503 /* BUG Fix 5346832 : Start */
6504
6505 IF (l_duration > 0) THEN
6506 l_social_security_rate := ( p_4weeks_paybase / l_duration);
6507 ELSE
6508 l_social_security_rate := 0 ;
6509 END IF;
6510
6511 /* BUG Fix 5346832 : End */
6512
6513 -- Override social security date was present.
6514 IF l_override_ss_rate IS NOT NULL THEN
6515 l_social_security_rate := l_override_ss_rate;
6516 END IF;
6517 -- If social security rate is greater than 6g then restrict it to 6g if the flag is set
6518 IF l_gen_restrict_ss_sl = 'Y' THEN
6519 IF l_social_security_rate > ((l_g_rate * 6)/ p_abs_annual_days) THEN
6520 l_social_security_rate := ((l_g_rate * 6)/ p_abs_annual_days);
6521 END IF;
6522 END IF;
6523
6524 l_empr_daily_rate := l_social_security_rate;
6525 l_reclaim_daily_rate := l_social_security_rate;
6526
6527 ELSIF p_hourly_paid = 'M' THEN
6528 /* knelli
6529 IF length(l_msg_error) > 1 THEN
6530 l_msg_error := 'Error7';
6531 END IF;*/
6532 l_msg_error := to_char(7);
6533 -- Throw a warning message that the person in monthly payroll with hourly flag chosen and
6534 -- Previous 4 weeks period logic will not work.
6535 END IF;
6536 END IF;
6537
6538 p_adopt_rate := l_reclaim_daily_rate ;
6539 /* knelli added logic for bug fix 5284260 */
6540 IF l_adopt_comprate = 80 THEN
6541 p_adopt_rate := p_adopt_rate * 0.8;
6542 END IF;
6543 p_adopt_comprate := l_adopt_comprate ;
6544 -- Reusing the existing siciness output variables for adoption
6545 p_rec_total_days := p_adopt_days;
6546 p_rec_daily_rate := p_adopt_comprate;
6547 p_ss_daily_rate := p_adopt_rate;
6548
6549 l_include_event := 'N';
6550 -- Calculating actual sickness days through work schedule
6551 l_wrk_schd_return := hr_loc_work_schedule.calc_sch_based_dur
6552 ( p_assignment_id, l_days_or_hours, l_include_event,
6553 p_prorate_start, p_prorate_end, l_start_time_char,
6554 l_end_time_char, l_duration
6555 );
6556 l_actual_cal_days := nvl(l_duration,0);
6557 -- Calculate Earnings Adjustment value
6558 --p_ear_value := ( ( p_sickabs_paybase * p_abs_month) / p_abs_annual_days ) * l_actual_cal_days; 5925652
6559 p_ear_value := round(( ( p_abs_ear_adj_base * p_abs_month) / p_abs_annual_days ),2) * p_adopt_days;
6560 p_ear_startdt := p_prorate_start;
6561 p_ear_enddt := p_prorate_end;
6562 p_ear_value := nvl(p_ear_value,0);
6563
6564 IF l_gen_hour_sal = 'H' THEN
6565 p_ear_value := 0;
6566 END IF;
6567
6568 IF l_gen_rate_option = 'DRATE_OPT1' THEN
6569 p_rate_option1 := 'Y';
6570 ELSIF l_gen_rate_option = 'DRATE_OPT2' THEN
6571 p_rate_option2 := 'Y';
6572 ELSIF l_gen_rate_option = 'DRATE_OPT3' THEN
6573 p_rate_option3 := 'Y';
6574 ELSIF l_gen_rate_option = 'DRATE_OPT4' THEN
6575 p_rate_option4 := 'Y';
6576 ELSIF l_gen_rate_option = 'DRATE_OPT5' THEN
6577 p_rate_option5 := 'Y';
6578 ELSIF l_gen_rate_option = 'DRATE_OPT6' THEN
6579 p_rate_option6 := 'Y';
6580 ELSIF l_gen_rate_option = 'DRATE_OPT7' THEN
6581 p_rate_option7 := 'Y';
6582 ELSIF l_gen_rate_option = 'DRATE_OPT8' THEN
6583 p_rate_option8 := 'Y';
6584 ELSIF l_gen_rate_option = 'DRATE_OPT9' THEN
6585 p_rate_option9 := 'Y';
6586 ELSIF l_gen_rate_option = 'DRATE_OPT10' THEN
6587 p_rate_option10 := 'Y';
6588 ELSE
6589 p_rate_option1 := null;
6590 p_rate_option2 := null;
6591 p_rate_option3 := null;
6592 p_rate_option4 := null;
6593 p_rate_option5 := null;
6594 p_rate_option6 := null;
6595 p_rate_option7 := null;
6596 p_rate_option8 := null;
6597 p_rate_option9 := null;
6598 p_rate_option10 := null;
6599 END IF;
6600 p_abs_error := l_msg_error ;
6601
6602 /* Bug Fix 5349636 : Start */
6603
6604 -- If calculated daily rate is less than 50% of G daily rate then no social security period will be paid.
6605 IF p_adopt_rate < ((l_g_rate / p_abs_annual_days) / 2) THEN
6606 -- No social security period will be paid.
6607 p_rec_total_days := 0;
6608 p_rec_daily_rate := 0;
6609 p_ss_daily_rate := 0;
6610 p_ear_value := 0;
6611 l_msg_error := to_char(11); /* 50% G Message */
6612 p_abs_error := l_msg_error ;
6613 END IF;
6614
6615 /* Bug Fix 5349636 : End */
6616
6617 ELSE -- if reimburse from social security is set to No then no adoption will be paid.
6618 -- Reusing the existing siciness output variables for adoption
6619 p_rec_total_days := 0;
6620 p_rec_daily_rate := 0;
6621 p_ss_daily_rate := 0;
6622 p_ear_value := 0;
6623 p_abs_error := l_msg_error ;
6624 END IF; -- Reimburse from social security
6625 END IF;
6626 hr_utility.set_location('Leaving absence package: ', 2);
6627 return 1;
6628 END CALCULATE_PAYMENT;
6629
6630 PROCEDURE GET_SICKPAY
6631 (p_person_id IN NUMBER
6632 ,p_assignment_id IN NUMBER
6633 ,p_effective_date IN DATE
6634 ,p_dateofjoin IN DATE
6635 )
6636 AS
6637 BEGIN
6638 null;
6639 END GET_SICKPAY;
6640
6641 FUNCTION get_override_details
6642 (p_assignment_id IN NUMBER
6643 ,p_effective_date IN DATE
6644 ,p_abs_start_date IN DATE
6645 ,p_abs_end_date IN DATE
6646 ,p_abs_categorycode IN VARCHAR2
6647 ,p_start_date OUT NOCOPY DATE
6648 ,p_end_date OUT NOCOPY DATE
6649 ,p_over_empr_rate OUT NOCOPY NUMBER
6650 ,p_over_ss_rate OUT NOCOPY NUMBER
6651 ,p_over_reclaim_rate OUT NOCOPY NUMBER
6652 ,p_over_empr_days OUT NOCOPY NUMBER
6653 ,p_over_ss_days OUT NOCOPY NUMBER ) RETURN NUMBER IS
6654 --
6655 CURSOR get_details(p_assignment_id NUMBER , p_effective_date DATE ) IS
6656 SELECT ee.element_entry_id element_entry_id
6657 , eev1.screen_entry_value screen_entry_value
6658 , iv1.name
6659 FROM per_all_assignments_f asg1
6660 ,per_all_assignments_f asg2
6661 ,per_all_people_f per
6662 ,pay_element_links_f el
6663 ,pay_element_types_f et
6664 ,pay_input_values_f iv1
6665 ,pay_element_entries_f ee
6666 ,pay_element_entry_values_f eev1
6667 WHERE asg1.assignment_id = p_assignment_id
6668 AND p_effective_date BETWEEN asg1.effective_start_date AND asg1.effective_end_date
6669 AND p_effective_date BETWEEN asg2.effective_start_date AND asg2.effective_end_date
6670 AND per.person_id = asg1.person_id
6671 AND asg2.person_id = per.person_id
6672 AND et.element_name = 'Absence Detail Override'
6673 AND et.legislation_code = 'NO'
6674 AND iv1.element_type_id = et.element_type_id
6675 AND iv1.name in ('Start Date', 'End Date', 'Employer Period Daily Rate', 'Social Security Daily Rate', 'Reclaimable Daily Rate', 'Employer Period Days', 'Social Security Period Days', 'Absence Category')
6676 AND el.business_group_id = per.business_group_id
6677 AND el.element_type_id = et.element_type_id
6678 AND ee.assignment_id = asg2.assignment_id
6679 AND ee.element_link_id = el.element_link_id
6680 AND eev1.element_entry_id = ee.element_entry_id
6681 AND eev1.input_value_id = iv1.input_value_id
6682 AND p_effective_date BETWEEN ee.effective_start_date AND ee.effective_end_date
6683 AND p_effective_date BETWEEN eev1.effective_start_date AND eev1.effective_end_date
6684 AND p_effective_date BETWEEN iv1.effective_start_date AND iv1.effective_end_date
6685 AND p_effective_date BETWEEN et.effective_start_date AND et.effective_end_date
6686 AND p_effective_date BETWEEN el.effective_start_date AND el.effective_end_date
6687 AND p_effective_date BETWEEN per.effective_start_date AND per.effective_end_date
6688 ORDER BY ee.element_entry_id;
6689 --
6690 TYPE l_record is record (eeid pay_element_entries_f.element_entry_id%TYPE,
6691 eevalue pay_element_entry_values_f.screen_entry_value%TYPE,
6692 eename pay_input_values_f.name%TYPE );
6693 l_rec l_record;
6694 TYPE l_table is table of l_record index by BINARY_INTEGER;
6695 l_tab l_table;
6696
6697 l_start_date date;
6698 l_end_date date;
6699
6700 l_over_empr_rate number;
6701 l_over_ss_rate number;
6702 l_over_reclaim_rate number;
6703 l_over_empr_days number;
6704 l_over_ss_days number;
6705
6706 l_over_category Varchar2(50);
6707 l_abs_category_code varchar2(50);
6708 l_counter number ;
6709 l_bool_match boolean;
6710 l_num_match number;
6711 l_check_nomatch number;
6712 --
6713 BEGIN
6714 --
6715 l_counter := 1;
6716 l_bool_match := FALSE;
6717 l_check_nomatch := 0;
6718
6719 -- To select absence category code by passing absence category meaning.
6720 /* BEGIN
6721 SELECT LOOKUP_CODE
6722 INTO l_abs_category_code
6723 FROM HR_LOOKUPS /* Bug Fix 5263714 referred hr_lookups instead of fnd_lookup_values
6724 FROM FND_LOOKUP_VALUES
6725 WHERE LOOKUP_TYPE = 'ABSENCE_CATEGORY'
6726 AND ENABLED_FLAG = 'Y'
6727 AND MEANING = p_abs_category;
6728 EXCEPTION
6729 WHEN others THEN
6730 l_abs_category_code := null;
6731 END;*/
6732 l_abs_category_code := p_abs_categorycode;
6733
6734 -- Open cursor to fetch all screen entry values of Override Holiday Duration element.
6735 OPEN get_details(p_assignment_id , p_effective_date );
6736 -- Assign the values to a table type
6737 FETCH get_details BULK COLLECT INTO l_tab;
6738 CLOSE get_details;
6739
6740 -- Loop through each values for processing.
6741 FOR l_cur in 1..l_tab.count LOOP
6742 -- Assign values to local variables.
6743 IF l_tab(l_cur).eename = 'Start Date' THEN
6744 l_start_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss') ;
6745 elsif l_tab(l_cur).eename = 'End Date' THEN
6746 l_end_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss');
6747 elsif l_tab(l_cur).eename = 'Employer Period Daily Rate' THEN
6748 l_over_empr_rate := fnd_number.canonical_to_number(l_tab(l_cur).eevalue);
6749 elsif l_tab(l_cur).eename = 'Social Security Daily Rate' THEN
6750 l_over_ss_rate := fnd_number.canonical_to_number(l_tab(l_cur).eevalue);
6751 elsif l_tab(l_cur).eename = 'Reclaimable Daily Rate' THEN
6752 l_over_reclaim_rate := fnd_number.canonical_to_number(l_tab(l_cur).eevalue);
6753 elsif l_tab(l_cur).eename = 'Employer Period Days' THEN
6754 l_over_empr_days := fnd_number.canonical_to_number(l_tab(l_cur).eevalue);
6755 elsif l_tab(l_cur).eename = 'Social Security Period Days' THEN
6756 l_over_ss_days := fnd_number.canonical_to_number(l_tab(l_cur).eevalue);
6757 elsif l_tab(l_cur).eename = 'Absence Category' THEN
6758 l_over_category := l_tab(l_cur).eevalue;
6759 end if;
6760 -- Check no. of input values of override element is 5
6761 IF l_counter < 8 then
6762 l_counter := l_counter + 1;
6763 else
6764 -- Check the absence category of parent element matches with override element. If so then check for
6765 -- matching override element to override the absence days and daily rate.
6766 IF l_over_category = l_abs_category_code THEN
6767 -- Check override element's start and end date matches with Absent element.
6768 if l_start_date = p_abs_start_date then -- and l_end_date = p_abs_end_date 5380130
6769 -- Multiple entry exists with same start and end date
6770 IF l_bool_match THEN
6771 p_start_date := null;
6772 p_end_date := null;
6773 p_over_empr_rate := null;
6774 p_over_ss_rate := null;
6775 p_over_reclaim_rate := null;
6776 p_over_empr_days := null;
6777 p_over_ss_days := null;
6778 return -1;
6779 -- Exact match found
6780 ELSE
6781 l_bool_match := True;
6782 END IF;
6783 -- Assign input values to output variables.
6784 p_start_date := l_start_date;
6785 p_end_date := l_end_date;
6786 p_over_empr_rate := l_over_empr_rate;
6787 p_over_ss_rate := l_over_ss_rate;
6788 p_over_reclaim_rate := l_over_reclaim_rate;
6789 p_over_empr_days := l_over_empr_days;
6790 p_over_ss_days := l_over_ss_days;
6791 end if;
6792 l_counter := 1;
6793 -- Override element exists for the category with start date and end date are not matching
6794 else
6795 l_check_nomatch := l_check_nomatch + 1;
6796 end if;
6797 END if;
6798 END LOOP;
6799
6800 -- Match found successfully
6801 IF p_start_date is not null then
6802 RETURN 1;
6803 -- Override element exists but date doesnt match.
6804 elsif p_start_date is null and l_check_nomatch > 0 then
6805 RETURN 2;
6806 -- No override element attached
6807 else
6808 RETURN 0;
6809 end if;
6810 --
6811 END get_override_details;
6812
6813 FUNCTION get_weekdays(p_period_start_date IN DATE
6814 ,p_period_end_date IN DATE
6815 ,p_work_pattern IN VARCHAR) RETURN NUMBER IS
6816
6817 /* Commented to add new logic
6818 l_abs_start_date date;
6819 l_abs_end_date date;
6820 l_loop_start_date date;
6821 l_days number;
6822 l_start_d number;
6823 l_end_d number;
6824 l_work_pattern varchar2(6);
6825 l_index number;
6826 l_weekdays number;
6827 l_curr_date date;
6828 l_d number;
6829 begin
6830 l_abs_start_date := p_period_start_date;
6831 l_abs_end_date := p_period_end_date;
6832 l_days := (l_abs_end_date - l_abs_start_date) + 1;
6833 l_weekdays := 0;
6834 l_curr_date := l_abs_start_date;
6835 l_work_pattern := p_work_pattern;
6836 IF l_work_pattern = '5DAY' then
6837 FOR l_index IN 1..l_days
6838 loop
6839 l_curr_date := l_abs_start_date + (l_index - 1);
6840 l_d := to_number(to_char(l_curr_date,'d'));
6841 IF l_d NOT IN (7,1) then
6842 l_weekdays := l_weekdays +1;
6843 END IF;
6844 END loop;
6845 END if;
6846
6847 IF l_work_pattern = '6DAY' then
6848 FOR l_index IN 1..l_days
6849 loop
6850 l_curr_date := l_abs_start_date + (l_index - 1);
6851 l_d := to_number(to_char(l_curr_date,'d'));
6852 IF l_d <> 1 then
6853 l_weekdays := l_weekdays +1;
6854 END IF;
6855 END loop;
6856 END if;
6857 */
6858
6859 /* New Logic */
6860 v_st_date date;
6861 v_en_date date;
6862 v_beg_of_week date;
6863 v_end_of_week date;
6864 l_weekdays number;
6865 v_work_pattern varchar2(20);
6866 begin
6867 v_st_date :=p_period_start_date;
6868 v_en_date :=p_period_end_date;
6869 l_weekdays := 0;
6870 v_work_pattern := p_work_pattern;
6871 if p_period_start_date > p_period_end_date then
6872 return l_weekdays;
6873 end if;
6874 --Determine the Beginning of Week Date for Start Date
6875 --and End of Week Date for End Date
6876 v_beg_of_week := v_st_date - (get_day_of_week(v_st_date)-1);
6877 v_end_of_week := v_en_date;
6878 if get_day_of_week(v_en_date) NOT IN('1') then
6879 v_end_of_week := v_en_date + (7- get_day_of_week(v_en_date)+1);
6880 end if;
6881 IF v_work_pattern = '5DAY' THEN
6882 --Calculate the Total Week Days @ of 5 per week
6883 l_weekdays := ((v_end_of_week-v_beg_of_week)/7)*5;
6884 --Adjust the Total Week Days by subtracting
6885 --No of Days before the Start Date
6886 if (v_st_date > (v_beg_of_week+1)) then
6887 l_weekdays := l_weekdays - (v_st_date - (v_beg_of_week+1)) ;
6888 end if;
6889 if v_end_of_week <> v_en_date then
6890 v_end_of_week := v_end_of_week -2;
6891 else
6892 if v_st_date = v_en_date then
6893 l_weekdays := 0;
6894 end if;
6895 end if;
6896 --Adjust the Total Week Days by subtracting
6897 --No of Days After the End Date
6898 if (v_end_of_week - v_en_date) >= 0 then
6899 l_weekdays := l_weekdays - (v_end_of_week - v_en_date) ;
6900 end if;
6901
6902 ELSE
6903 --Calculate the Total Week Days @ of 6 per week
6904 l_weekdays := ((v_end_of_week-v_beg_of_week)/7)*6;
6905 --Adjust the Total Week Days by subtracting
6906 --No of Days before the Start Date
6907 if (v_st_date > (v_beg_of_week+1)) then
6908 l_weekdays := l_weekdays - (v_st_date - (v_beg_of_week+1)) ;
6909 end if;
6910 if v_end_of_week <> v_en_date then
6911 v_end_of_week := v_end_of_week -1;
6912 else
6913 if v_st_date = v_en_date then
6914 l_weekdays := 0;
6915 end if;
6916 end if;
6917 --Adjust the Total Week Days by subtracting
6918 --No of Days After the End Date
6919 if (v_end_of_week - v_en_date) >= 0 then
6920 l_weekdays := l_weekdays - (v_end_of_week - v_en_date) ;
6921 end if;
6922 END IF;
6923
6924 RETURN l_weekdays;
6925
6926 END get_weekdays;
6927
6928 /* added function get_day_of_week
6929 This Function returns the day of the week.
6930 Sunday is considered to be the first day of the week*/
6931 FUNCTION get_day_of_week(p_date DATE) RETURN NUMBER IS
6932 l_reference_date date:=to_date('01/01/1984','DD/MM/YYYY');
6933 v_index number;
6934
6935 BEGIN
6936 v_index := abs(p_date - l_reference_date);
6937 v_index := mod(v_index,7);
6938 v_index := v_index + 1;
6939 RETURN v_index;
6940
6941 END get_day_of_week;
6942
6943 FUNCTION get_sick_unpaid
6944 (p_assignment_id IN NUMBER
6945 ,p_effective_date IN DATE
6946 ,p_start_date OUT NOCOPY DATE
6947 ,p_end_date OUT NOCOPY DATE) RETURN NUMBER IS
6948 --
6949 CURSOR get_details(p_assignment_id NUMBER , p_effective_date DATE, effdt DATE ) IS
6950 SELECT ee.element_entry_id element_entry_id
6951 , eev1.screen_entry_value screen_entry_value
6952 , iv1.name
6953 FROM per_all_assignments_f asg1
6954 ,per_all_assignments_f asg2
6955 ,per_all_people_f per
6956 ,pay_element_links_f el
6957 ,pay_element_types_f et
6958 ,pay_input_values_f iv1
6959 ,pay_element_entries_f ee
6960 ,pay_element_entry_values_f eev1
6961 WHERE asg1.assignment_id = p_assignment_id
6962 AND p_effective_date BETWEEN asg1.effective_start_date AND asg1.effective_end_date
6963 AND p_effective_date BETWEEN asg2.effective_start_date AND asg2.effective_end_date
6964 AND per.person_id = asg1.person_id
6965 AND asg2.person_id = per.person_id
6966 AND et.element_name = 'Sickness Unpaid'
6967 AND et.legislation_code = 'NO'
6968 AND iv1.element_type_id = et.element_type_id
6969 AND iv1.name IN ('Start Date', 'End Date')
6970 AND el.business_group_id = per.business_group_id
6971 AND el.element_type_id = et.element_type_id
6972 AND ee.assignment_id = asg2.assignment_id
6973 AND ee.element_link_id = el.element_link_id
6974 AND eev1.element_entry_id = ee.element_entry_id
6975 AND eev1.input_value_id = iv1.input_value_id
6976 AND effdt BETWEEN ee.effective_start_date AND ee.effective_end_date
6977 AND effdt BETWEEN eev1.effective_start_date AND eev1.effective_end_date
6978 AND p_effective_date BETWEEN iv1.effective_start_date AND iv1.effective_end_date
6979 AND p_effective_date BETWEEN et.effective_start_date AND et.effective_end_date
6980 AND effdt BETWEEN el.effective_start_date AND el.effective_end_date
6981 AND p_effective_date BETWEEN per.effective_start_date AND per.effective_end_date
6982 ORDER BY ee.element_entry_id;
6983 --
6984 TYPE l_record is record (eeid pay_element_entries_f.element_entry_id%TYPE,
6985 eevalue pay_element_entry_values_f.screen_entry_value%TYPE,
6986 eename pay_input_values_f.name%TYPE );
6987 l_rec l_record;
6988 TYPE l_table is table of l_record index by BINARY_INTEGER;
6989 l_tab l_table;
6990
6991 l_start_date date;
6992 l_end_date date;
6993 l_over_hours number;
6994 l_over_days number;
6995 l_counter number ;
6996 l_bool_match boolean;
6997 l_num_match number;
6998 l_effective_date date;
6999 l_assignment_id number;
7000 l_max_date date;
7001 --
7002 BEGIN
7003 --
7004 l_counter := 1;
7005 l_bool_match := FALSE;
7006
7007 BEGIN
7008 SELECT MAX(ee.effective_end_date)
7009 INTO l_max_date
7010 FROM pay_element_types_f et
7011 ,pay_element_links_f el
7012 ,pay_input_values_f iv1
7013 ,pay_element_entries_f ee
7014 ,pay_element_entry_values_f eev1
7015 WHERE et.element_name = 'Sickness Unpaid'
7016 AND et.legislation_code = 'NO'
7017 AND iv1.element_type_id = et.element_type_id
7018 AND iv1.NAME = 'End Date'
7019 AND el.element_type_id = et.element_type_id
7020 AND ee.element_link_id = el.element_link_id
7021 AND eev1.element_entry_id = ee.element_entry_id
7022 AND eev1.input_value_id = iv1.input_value_id
7023 AND ee.effective_end_date <= p_effective_date
7024 AND ee.assignment_id = p_assignment_id;
7025 EXCEPTION
7026 WHEN OTHERS THEN
7027 l_max_date := NULL;
7028 END;
7029 -- Open cursor to fetch all screen entry values of Override Holiday Duration element.
7030 OPEN get_details(p_assignment_id , p_effective_date, l_max_date );
7031 -- Assign the values to a table type
7032 FETCH get_details BULK COLLECT INTO l_tab;
7033 CLOSE get_details;
7034
7035 -- Loop through each values for processing.
7036 FOR l_cur in 1..l_tab.count LOOP
7037 -- Assign values to local variables.
7038 IF l_tab(l_cur).eename = 'Start Date' THEN
7039 p_start_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss') ;
7040 elsif l_tab(l_cur).eename = 'End Date' THEN
7041 p_end_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss');
7042 end if;
7043 END LOOP;
7044 -- Match found successfully
7045 IF p_start_date is not null and p_end_date is not null then
7046 RETURN 0;
7047 ELSE
7048 RETURN -1;
7049 end if;
7050 --
7051 END get_sick_unpaid;
7052 --
7053
7054 FUNCTION GET_GRATE ( p_effective_date IN DATE
7055 ,p_assignment_id IN NUMBER
7056 ,p_business_group_id IN NUMBER) RETURN NUMBER IS
7057 l_g_rate Number;
7058 BEGIN
7059 -- Get the daily rate value
7060 -- Check daily rate is < 50% of G Per day then no social security amount will be paid.
7061 -- Calculation of G rate
7062 BEGIN
7063
7064 /*
7065 select pucf.VALUE
7066 into l_g_rate
7067 from pay_user_tables put
7068 ,pay_user_rows_f pur
7069 ,pay_user_columns puc
7070 ,pay_user_column_instances_f pucf
7071 where put.USER_TABLE_NAME = 'NO_GLOBAL_CONSTANTS'
7072 and pur.ROW_LOW_RANGE_OR_NAME = 'NATIONAL_INSURANCE_BASE_RATE'
7073 and puc.USER_COLUMN_NAME = 'Value'
7074 and put.legislation_code = 'NO'
7075 and pur.legislation_code = 'NO'
7076 and puc.legislation_code = 'NO'
7077 and ( pucf.business_group_id = p_business_group_id OR pucf.business_group_id is NULL )
7078 and put.user_table_id = pur.user_table_id
7079 and put.user_table_id = puc.user_table_id
7080 and pucf.user_row_id = pur.user_row_id
7081 and pucf.user_column_id = puc.user_column_id
7082 and p_effective_date between pur.effective_start_date and pur.effective_end_date
7083 and p_effective_date between pucf.effective_start_date and pucf.effective_end_date ;
7084
7085 */
7086
7087 -- Bug Fix 5566622 : Value of G (National Insurance Base Rate) to be taken
7088 -- from Global (NO_NATIONAL_INSURANCE_BASE_RATE) and not user table (NATIONAL_INSURANCE_BASE_RATE).
7089
7090 select fnd_number.canonical_to_number(GLOBAL_VALUE)
7091 into l_g_rate
7092 from ff_globals_f
7093 where global_name = 'NO_NATIONAL_INSURANCE_BASE_RATE'
7094 and LEGISLATION_CODE = 'NO'
7095 and BUSINESS_GROUP_ID IS NULL
7096 and p_effective_date between EFFECTIVE_START_DATE and EFFECTIVE_END_DATE ;
7097
7098 EXCEPTION
7099 when no_data_found then
7100 l_g_rate := null;
7101 END;
7102
7103 RETURN l_g_rate;
7104 END GET_GRATE;
7105
7106 FUNCTION GET_SOURCEID (p_source_id IN NUMBER) return number
7107 is
7108 begin
7109 return p_source_id;
7110 end get_sourceid;
7111
7112 FUNCTION GET_26WEEK (P_ASSIGNMENT_ACTION_ID IN NUMBER)
7113 RETURN DATE
7114 IS
7115 CURSOR get_details(p_assignment_id NUMBER , p_effective_date DATE, effdt DATE ) IS
7116 SELECT ee.element_entry_id element_entry_id
7117 , eev1.screen_entry_value screen_entry_value
7118 , iv1.name
7119 FROM per_all_assignments_f asg1
7120 ,per_all_assignments_f asg2
7121 ,per_all_people_f per
7122 ,pay_element_links_f el
7123 ,pay_element_types_f et
7124 ,pay_input_values_f iv1
7125 ,pay_element_entries_f ee
7126 ,pay_element_entry_values_f eev1
7127 WHERE asg1.assignment_id = p_assignment_id
7128 AND p_effective_date BETWEEN asg1.effective_start_date AND asg1.effective_end_date
7129 AND p_effective_date BETWEEN asg2.effective_start_date AND asg2.effective_end_date
7130 AND per.person_id = asg1.person_id
7131 AND asg2.person_id = per.person_id
7132 AND et.element_name = 'Sickness Unpaid'
7133 AND et.legislation_code = 'NO'
7134 AND iv1.element_type_id = et.element_type_id
7135 AND iv1.name = 'End Date'
7136 AND el.business_group_id = per.business_group_id
7137 AND el.element_type_id = et.element_type_id
7138 AND ee.assignment_id = asg2.assignment_id
7139 AND ee.element_link_id = el.element_link_id
7140 AND eev1.element_entry_id = ee.element_entry_id
7141 AND eev1.input_value_id = iv1.input_value_id
7142 AND effdt BETWEEN ee.effective_start_date AND ee.effective_end_date
7143 AND effdt BETWEEN eev1.effective_start_date AND eev1.effective_end_date
7144 AND p_effective_date BETWEEN iv1.effective_start_date AND iv1.effective_end_date
7145 AND p_effective_date BETWEEN et.effective_start_date AND et.effective_end_date
7146 AND effdt BETWEEN el.effective_start_date AND el.effective_end_date
7147 AND p_effective_date BETWEEN per.effective_start_date AND per.effective_end_date
7148 ORDER BY ee.element_entry_id;
7149 --
7150 TYPE l_record is record (eeid pay_element_entries_f.element_entry_id%TYPE,
7151 eevalue pay_element_entry_values_f.screen_entry_value%TYPE,
7152 eename pay_input_values_f.name%TYPE );
7153 l_rec l_record;
7154 TYPE l_table is table of l_record index by BINARY_INTEGER;
7155 l_tab l_table;
7156
7157 l_start_date date;
7158 l_end_date date;
7159 l_over_hours number;
7160 l_over_days number;
7161 l_counter number ;
7162 l_bool_match boolean;
7163 l_num_match number;
7164 l_effective_date date;
7165 l_assignment_id number;
7166 l_max_date date;
7167 --
7168 BEGIN
7169 --
7170 l_counter := 1;
7171 l_bool_match := FALSE;
7172
7173 -- To fetch the effective date and assignment id for the given assignment action id.
7174 BEGIN
7175 SELECT PPA.EFFECTIVE_DATE
7176 ,PAA.ASSIGNMENT_ID
7177 INTO l_effective_date
7178 ,l_assignment_id
7179 FROM PAY_PAYROLL_ACTIONS PPA
7180 ,PAY_ASSIGNMENT_ACTIONS PAA
7181 WHERE PPA.PAYROLL_ACTION_ID = PAA.PAYROLL_ACTION_ID
7182 AND PAA.ASSIGNMENT_ACTION_ID = P_ASSIGNMENT_ACTION_ID;
7183 EXCEPTION
7184 WHEN NO_DATA_FOUND THEN
7185 l_effective_date := NULL;
7186 l_assignment_id := NULL;
7187 WHEN OTHERS THEN
7188 l_effective_date := NULL;
7189 l_assignment_id := NULL;
7190 END;
7191
7192 BEGIN
7193 SELECT MAX(ee.effective_end_date)
7194 INTO l_max_date
7195 FROM pay_element_types_f et
7196 ,pay_element_links_f el
7197 ,pay_input_values_f iv1
7198 ,pay_element_entries_f ee
7199 ,pay_element_entry_values_f eev1
7200 WHERE et.element_name = 'Sickness Unpaid'
7201 AND et.legislation_code = 'NO'
7202 AND iv1.element_type_id = et.element_type_id
7203 AND iv1.NAME = 'End Date'
7204 AND el.element_type_id = et.element_type_id
7205 AND ee.element_link_id = el.element_link_id
7206 AND eev1.element_entry_id = ee.element_entry_id
7207 AND eev1.input_value_id = iv1.input_value_id
7208 AND ee.effective_end_date <= l_effective_date
7209 AND ee.assignment_id = l_assignment_id;
7210 EXCEPTION
7211 WHEN OTHERS THEN
7212 NULL;
7213 END;
7214 -- Open cursor to fetch all screen entry values of Override Holiday Duration element.
7215 OPEN get_details(l_assignment_id , l_effective_date, l_max_date );
7216 -- Assign the values to a table type
7217 FETCH get_details BULK COLLECT INTO l_tab;
7218 CLOSE get_details;
7219
7220 -- Loop through each values for processing.
7221 FOR l_cur in 1..l_tab.count LOOP
7222 -- Assign values to local variables.
7223 IF l_tab(l_cur).eename = 'Start Date' THEN
7224 l_start_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss') ;
7225 elsif l_tab(l_cur).eename = 'End Date' THEN
7226 l_end_date := to_date(l_tab(l_cur).eevalue,'yyyy/mm/dd hh24:mi:ss');
7227 end if;
7228 END LOOP;
7229 IF l_end_date IS NULL THEN
7230 l_end_date := to_date('01/01/0001 00:00:00','dd/mm/yyyy hh24:mi:ss');
7231 END IF;
7232 RETURN l_end_date;
7233 END GET_26WEEK;
7234
7235 FUNCTION GET_USERTABLE (p_effective_date IN DATE
7236 ,p_business_group_id IN NUMBER
7237 ,p_usertable_name IN VARCHAR2
7238 ,p_usertable_colname IN VARCHAR2
7239 ,p_exact_text IN VARCHAR2 )
7240 RETURN NUMBER IS
7241 l_value NUMBER;
7242 BEGIN
7243 BEGIN
7244 SELECT pucf.VALUE
7245 INTO l_value
7246 FROM pay_user_tables put
7247 ,pay_user_rows_f pur
7248 ,pay_user_columns puc
7249 ,pay_user_column_instances_f pucf
7250 WHERE put.USER_TABLE_NAME = p_usertable_name
7251 AND pur.ROW_LOW_RANGE_OR_NAME = p_exact_text
7252 AND puc.USER_COLUMN_NAME = p_usertable_colname
7253 AND put.legislation_code = 'NO'
7254 AND pur.legislation_code = 'NO'
7255 AND puc.legislation_code = 'NO'
7256 AND ( pucf.business_group_id = p_business_group_id OR pucf.business_group_id IS NULL )
7257 AND put.user_table_id = pur.user_table_id
7258 AND put.user_table_id = puc.user_table_id
7259 AND pucf.user_row_id = pur.user_row_id
7260 AND pucf.user_column_id = puc.user_column_id
7261 AND p_effective_date BETWEEN pur.effective_start_date AND pur.effective_end_date
7262 AND p_effective_date BETWEEN pucf.effective_start_date AND pucf.effective_end_date ;
7263 EXCEPTION
7264 WHEN OTHERS THEN
7265 l_value := NULL;
7266 END;
7267 RETURN l_value;
7268 END GET_USERTABLE;
7269
7270 FUNCTION get_months_employed(p_person_id IN NUMBER
7271 ,p_check_start_date IN DATE
7272 ,p_check_end_date IN DATE ) return NUMBER IS
7273
7274 l_min_start_date date;
7275 l_max_end_date date;
7276 l_fjob_start_date date;
7277 l_ljob_end_date date;
7278 l_start_date date;
7279 l_end_date date;
7280 l_person_id number;
7281 l_months_employed number;
7282 l_records number;
7283
7284 TYPE l_rec IS TABLE OF date INDEX BY binary_integer;
7285 --TYPE l_rec IS TABLE OF varchar2(50) INDEX BY binary_integer;
7286
7287 CURSOR csr_prev_emplr_start_date(p_person_id number, p_check_start_date date,p_check_end_date date) is
7288 SELECT start_date FROM per_previous_employers
7289 WHERE person_id = p_person_id
7290 AND end_date >= p_check_start_date
7291 AND start_date <= p_check_end_date
7292 ORDER BY start_date;
7293
7294 CURSOR csr_prev_emplr_end_date(p_person_id number, p_check_start_date date,p_check_end_date date) IS
7295 SELECT end_date FROM per_previous_employers
7296 WHERE person_id = p_person_id
7297 AND end_date >= p_check_start_date
7298 AND start_date <= p_check_end_date
7299 ORDER BY start_date;
7300
7301 CURSOR csr_get_fjob_start_date(p_person_id number, p_check_start_date date,p_check_end_date date) IS
7302 SELECT min(start_date) FROM per_previous_employers
7303 WHERE person_id = p_person_id
7304 AND end_date >= p_check_start_date
7305 AND start_date <= p_check_end_date;
7306
7307 CURSOR csr_get_ljob_end_date(p_person_id number, p_check_start_date date,p_check_end_date date) IS
7308 SELECT max(end_date) FROM per_previous_employers
7309 WHERE person_id = p_person_id
7310 AND end_date >= p_check_start_date
7311 AND start_date <= p_check_end_date;
7312
7313 l_start_date_rec l_rec;
7314 l_end_date_rec l_rec;
7315 l_effective_date date;
7316 l_person_hire_date date;
7317 l_10_month_start_date date;
7318 l_months number;
7319 l_check_start_date date;
7320 l_check_end_date date;
7321
7322 BEGIN
7323
7324 l_months_employed := 0;
7325 l_person_id := p_person_id;
7326 l_check_start_date := p_check_start_date;
7327 l_check_end_date := p_check_end_date - 1;
7328 l_10_month_start_date := p_check_start_date;
7329
7330
7331 OPEN csr_prev_emplr_start_date(l_person_id,l_check_start_date,l_check_end_date);
7332 FETCH csr_prev_emplr_start_date BULK COLLECT INTO l_start_date_rec;
7333 CLOSE csr_prev_emplr_start_date;
7334
7335 OPEN csr_prev_emplr_end_date(l_person_id,l_check_start_date,l_check_end_date);
7336 FETCH csr_prev_emplr_end_date BULK COLLECT INTO l_end_date_rec;
7337 CLOSE csr_prev_emplr_end_date;
7338
7339 OPEN csr_get_fjob_start_date(l_person_id,l_check_start_date,l_check_end_date);
7340 FETCH csr_get_fjob_start_date INTO l_fjob_start_date;
7341 CLOSE csr_get_fjob_start_date;
7342
7343 OPEN csr_get_ljob_end_date(l_person_id,l_check_start_date,l_check_end_date);
7344 FETCH csr_get_ljob_end_date INTO l_ljob_end_date;
7345 CLOSE csr_get_ljob_end_date;
7346
7347 l_records := l_start_date_rec.count;
7348
7349 IF l_records > 0 THEN
7350 IF l_start_date_rec(1) = l_fjob_start_date AND l_end_date_rec(1) = l_ljob_end_date THEN
7351 IF l_start_date_rec(1) < l_10_month_start_date THEN
7352 l_fjob_start_date := l_10_month_start_date;
7353 END IF;
7354 IF l_end_date_rec(1) > l_check_end_date THEN
7355 l_fjob_start_date := l_check_end_date;
7356 END IF;
7357 l_months_employed := trunc(months_between(l_ljob_end_date+1,l_fjob_start_date),2);
7358
7359 ELSE
7360 FOR i IN 1..l_records LOOP
7361 l_start_date := l_start_date_rec(i);
7362 l_end_date := l_end_date_rec(i);
7363
7364 IF l_start_date < l_10_month_start_date THEN
7365 l_start_date := l_10_month_start_date;
7366 END IF;
7367 IF l_end_date > l_check_end_date THEN
7368 l_end_date := l_check_end_date;
7369 END IF;
7370
7371 IF i > 1 AND l_start_date < l_end_date_rec(i-1) THEN
7372 l_start_date := l_end_date_rec(i-1) + 1;
7373 END IF;
7374
7375 l_months := trunc(months_between(l_end_date+1,l_start_date),2);
7376 l_months_employed := l_months_employed + l_months;
7377
7378 END LOOP;
7379
7380 END IF;
7381
7382 END IF;
7383
7384 RETURN l_months_employed;
7385 END get_months_employed;
7386
7387
7388 FUNCTION get_parental_ben_sd(p_assignment_action_id IN NUMBER
7389 ,p_element_entry_id IN NUMBER)
7390 RETURN DATE IS
7391
7392 --
7393 CURSOR csr_get_person_id(p_assignment_action_id NUMBER) IS
7394 SELECT pap.person_id FROM
7395 pay_assignment_actions paa, per_all_assignments_f asgmt, per_all_people_f pap
7396 WHERE paa.assignment_action_id = p_assignment_action_id
7397 AND paa.assignment_id = asgmt.assignment_id
7398 AND asgmt.person_id = pap.person_id;
7399
7400 CURSOR csr_get_maternity_sd(p_person_id NUMBER, p_dob VARCHAR2 ) IS
7401 SELECT min(date_start) from
7402 per_absence_attendances
7403 where person_id = p_person_id
7404 AND ABS_INFORMATION_CATEGORY = 'NO_M'
7405 AND abs_information2 = p_dob;
7406
7407 CURSOR csr_get_baby_dob(p_abs_attendance_id NUMBER) IS
7408 SELECT abs_information2 from
7409 per_absence_attendances
7410 WHERE ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7411
7412 CURSOR csr_get_element_type_id(p_element_entry_id NUMBER) IS
7413 SELECT element_type_id from
7414 pay_element_entries_f
7415 WHERE element_entry_id = p_element_entry_id;
7416
7417 CURSOR csr_get_input_value_id(p_element_type_id NUMBER) IS
7418 SELECT input_value_id from
7419 pay_input_values_f
7420 WHERE element_type_id = p_element_type_id
7421 AND NAME = 'CREATOR_ID';
7422
7423 CURSOR csr_get_screen_value(p_element_entry_id NUMBER
7424 ,p_input_value_id NUMBER ) IS
7425 SELECT screen_entry_value
7426 FROM pay_element_entry_values_f
7427 WHERE element_entry_id = p_element_entry_id
7428 AND input_value_id = p_input_value_id;
7429
7430
7431 l_start_date date;
7432 l_person_id number;
7433 l_elt_type_id number;
7434 l_ip_value_id number;
7435 l_creator_id varchar2(20);
7436 l_creator_id_num number;
7437 l_dob varchar2(60);
7438
7439 BEGIN
7440
7441 OPEN csr_get_person_id(p_assignment_action_id);
7442 FETCH csr_get_person_id INTO l_person_id;
7443 CLOSE csr_get_person_id;
7444
7445 OPEN csr_get_element_type_id(p_element_entry_id);
7446 FETCH csr_get_element_type_id INTO l_elt_type_id;
7447 CLOSE csr_get_element_type_id;
7448
7449 OPEN csr_get_input_value_id(l_elt_type_id);
7450 FETCH csr_get_input_value_id INTO l_ip_value_id;
7451 CLOSE csr_get_input_value_id;
7452
7453 OPEN csr_get_screen_value(p_element_entry_id,l_ip_value_id);
7454 FETCH csr_get_screen_value INTO l_creator_id;
7455 CLOSE csr_get_screen_value;
7456
7457 l_creator_id_num := fnd_number.canonical_to_number(l_creator_id);
7458
7459 OPEN csr_get_baby_dob(l_creator_id_num);
7460 FETCH csr_get_baby_dob INTO l_dob;
7461 CLOSE csr_get_baby_dob;
7462
7463 OPEN csr_get_maternity_sd(l_person_id,l_dob);
7464 FETCH csr_get_maternity_sd INTO l_start_date;
7465 CLOSE csr_get_maternity_sd;
7466
7467
7468 RETURN l_start_date;
7469 END get_parental_ben_sd;
7470
7471 /* Added function */
7472 FUNCTION get_adoption_ben_sd(p_assignment_action_id IN NUMBER
7473 ,p_element_entry_id IN NUMBER)
7474 RETURN DATE IS
7475
7476 --
7477 CURSOR csr_get_person_id(p_assignment_action_id NUMBER) IS
7478 SELECT pap.person_id FROM
7479 pay_assignment_actions paa, per_all_assignments_f asgmt, per_all_people_f pap
7480 WHERE paa.assignment_action_id = p_assignment_action_id
7481 AND paa.assignment_id = asgmt.assignment_id
7482 AND asgmt.person_id = pap.person_id;
7483
7484 /* Bug Fix 5380111 : Start */
7485
7486 /*
7487 CURSOR csr_get_adoption_sd(p_person_id NUMBER, p_dob VARCHAR2 ) IS
7488 SELECT min(date_start) from
7489 per_absence_attendances
7490 where person_id = p_person_id
7491 AND ABS_INFORMATION_CATEGORY = 'NO_IE_AL'
7492 AND abs_information2 = p_dob;
7493 */
7494
7495 CURSOR csr_get_adoption_sd(p_person_id NUMBER, p_dob VARCHAR2 ) IS
7496 SELECT min(date_start) from
7497 per_absence_attendances
7498 where person_id = p_person_id
7499 AND ABS_INFORMATION_CATEGORY IN ('NO_IE_AL','NO_PTA')
7500 AND abs_information2 = p_dob;
7501
7502 /* Bug Fix 5380111 : End */
7503
7504
7505 CURSOR csr_get_baby_dob(p_abs_attendance_id NUMBER) IS
7506 SELECT abs_information2 from
7507 per_absence_attendances
7508 WHERE ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7509
7510 CURSOR csr_get_element_type_id(p_element_entry_id NUMBER) IS
7511 SELECT element_type_id from
7512 pay_element_entries_f
7513 WHERE element_entry_id = p_element_entry_id;
7514
7515 CURSOR csr_get_input_value_id(p_element_type_id NUMBER) IS
7516 SELECT input_value_id from
7517 pay_input_values_f
7518 WHERE element_type_id = p_element_type_id
7519 AND NAME = 'CREATOR_ID';
7520
7521 CURSOR csr_get_screen_value(p_element_entry_id NUMBER
7522 ,p_input_value_id NUMBER ) IS
7523 SELECT screen_entry_value
7524 FROM pay_element_entry_values_f
7525 WHERE element_entry_id = p_element_entry_id
7526 AND input_value_id = p_input_value_id;
7527
7528
7529 l_start_date date;
7530 l_person_id number;
7531 l_elt_type_id number;
7532 l_ip_value_id number;
7533 l_creator_id varchar2(20);
7534 l_creator_id_num number;
7535 l_dob varchar2(60);
7536
7537 BEGIN
7538
7539 OPEN csr_get_person_id(p_assignment_action_id);
7540 FETCH csr_get_person_id INTO l_person_id;
7541 CLOSE csr_get_person_id;
7542
7543 OPEN csr_get_element_type_id(p_element_entry_id);
7544 FETCH csr_get_element_type_id INTO l_elt_type_id;
7545 CLOSE csr_get_element_type_id;
7546
7547 OPEN csr_get_input_value_id(l_elt_type_id);
7548 FETCH csr_get_input_value_id INTO l_ip_value_id;
7549 CLOSE csr_get_input_value_id;
7550
7551 OPEN csr_get_screen_value(p_element_entry_id,l_ip_value_id);
7552 FETCH csr_get_screen_value INTO l_creator_id;
7553 CLOSE csr_get_screen_value;
7554
7555 l_creator_id_num := fnd_number.canonical_to_number(l_creator_id);
7556
7557 OPEN csr_get_baby_dob(l_creator_id_num);
7558 FETCH csr_get_baby_dob INTO l_dob;
7559 CLOSE csr_get_baby_dob;
7560
7561 OPEN csr_get_adoption_sd(l_person_id,l_dob);
7562 FETCH csr_get_adoption_sd INTO l_start_date;
7563 CLOSE csr_get_adoption_sd;
7564
7565
7566 RETURN l_start_date;
7567 END get_adoption_ben_sd;
7568
7569 /*Bug 5393827 and 5349713 fixes - Added funtion get_initial_abs_sd*/
7570 /* Bug 5762854, Sickness and Part Time Sickness absences the daily rate should be calculated as the
7571 previous four weeks earnings / working days of current absence not initial absence . So this function
7572 should pass the curr abs payroll st dt for S and PTS, for other category should pass initial abs payroll st dt */
7573 FUNCTION get_initial_abs_sd(p_org_entry_id IN NUMBER, p_elem_entry_id IN NUMBER)
7574 RETURN DATE IS
7575
7576 CURSOR csr_get_ele_details(p_original_entry_id IN NUMBER ) IS
7577 SELECT peef.effective_start_date,peef.assignment_id
7578 FROM pay_element_entries_f peef
7579 WHERE peef.element_entry_id = p_original_entry_id;
7580
7581 /* Cursor to get the payroll start date given absence*/
7582 CURSOR csr_intial_abs_pay_stdt (p_assignment_id number, p_initial_abs_start_date date) is
7583 SELECT ptp.start_date
7584 FROM per_all_assignments_f paaf, per_time_periods ptp
7585 WHERE paaf.assignment_id = p_assignment_id
7586 AND ptp.payroll_id = paaf.payroll_id
7587 AND p_initial_abs_start_date between ptp.start_date and ptp.end_date;
7588
7589 /* Cursor to get the absence category based on the given element entry id*/
7590 CURSOR csr_abs_category (p_element_entry_id number) is
7591 SELECT screen_entry_value
7592 FROM pay_element_entries_f peef,
7593 pay_input_values_f pivf,
7594 pay_element_entry_values_f peevf
7595 WHERE peef.element_entry_id = p_element_entry_id
7596 AND pivf.element_type_id = peef.element_type_id
7597 AND pivf.name = 'Absence Category'
7598 AND pivf.legislation_code = 'NO'
7599 AND peevf.input_value_id = pivf.input_value_id
7600 AND peevf.element_entry_id = peef.element_entry_id;
7601
7602 l_get_ele_details csr_get_ele_details%ROWTYPE ;
7603 l_initial_abs_pay_stdt DATE;
7604 l_abs_category varchar2(10);
7605 BEGIN
7606
7607 /* Findout the absence category */
7608 OPEN csr_abs_category(p_elem_entry_id);
7609 FETCH csr_abs_category INTO l_abs_category;
7610 CLOSE csr_abs_category;
7611
7612 IF l_abs_category IN ('S','PTS') THEN
7613 /* getting the start date of the absence based on the element entry id context*/
7614 OPEN csr_get_ele_details(p_elem_entry_id);
7615 FETCH csr_get_ele_details INTO l_get_ele_details;
7616 CLOSE csr_get_ele_details;
7617 ELSE
7618 /* getting the start date of the initial absence based on the original entry id context*/
7619 OPEN csr_get_ele_details(p_org_entry_id);
7620 FETCH csr_get_ele_details INTO l_get_ele_details;
7621 CLOSE csr_get_ele_details;
7622 END IF;
7623
7624 /* geting the payroll start date of the given assignment and date */
7625 OPEN csr_intial_abs_pay_stdt(l_get_ele_details.assignment_id,l_get_ele_details.effective_start_date);
7626 FETCH csr_intial_abs_pay_stdt INTO l_initial_abs_pay_stdt;
7627 CLOSE csr_intial_abs_pay_stdt;
7628
7629 RETURN l_initial_abs_pay_stdt;
7630
7631 END get_initial_abs_sd;
7632
7633 /* 5261223 Added function for get the Assignment termination date */
7634 FUNCTION get_assg_trem_date(p_business_group_id IN NUMBER, p_asg_id IN NUMBER,
7635 p_pay_proc_period_start_date IN DATE, p_pay_proc_period_end_date IN DATE) RETURN DATE IS
7636
7637 CURSOR csr_asg IS
7638 SELECT MAX(paaf.effective_end_date) effective_end_date
7639 FROM per_all_assignments_f paaf
7640 WHERE paaf.business_group_id = p_business_group_id
7641 AND paaf.assignment_id = p_asg_id
7642 AND paaf.assignment_status_type_id = 1;
7643
7644 l_asg_trem_date DATE;
7645 l_asg_status csr_asg % rowtype;
7646
7647 BEGIN
7648
7649 OPEN csr_asg;
7650 FETCH csr_asg
7651 INTO l_asg_status;
7652 CLOSE csr_asg;
7653 l_asg_trem_date := l_asg_status.effective_end_date;
7654 RETURN l_asg_trem_date;
7655
7656 END get_assg_trem_date;
7657
7658 FUNCTION get_restrict_hol_to_6g(p_business_group_id in number ,
7659 p_assignment_id in NUMBER,
7660 p_effective_date IN DATE ,
7661 p_restrict_hol_to_6G OUT nocopy VARCHAR2) RETURN NUMBER IS
7662 CURSOR csr_person_id IS
7663 SELECT PERSON_ID
7664 FROM PER_ALL_ASSIGNMENTS_F ASG
7665 WHERE ASG.ASSIGNMENT_ID = p_assignment_id
7666 AND p_effective_date BETWEEN ASG.EFFECTIVE_START_DATE
7667 AND ASG.EFFECTIVE_END_DATE;
7668
7669
7670 CURSOR csr_person_details(p_person_id IN NUMBER ) is
7671 SELECT PER_INFORMATION22 AS restrict_hol_to_6G
7672 FROM PER_ALL_PEOPLE_F PER
7673 WHERE PER.PERSON_ID = p_person_id
7674 AND P_EFFECTIVE_DATE BETWEEN PER.EFFECTIVE_START_DATE
7675 AND PER.EFFECTIVE_END_DATE;
7676
7677
7678
7679 CURSOR csr_le_details is
7680 SELECT hoi4.ORG_INFORMATION10 AS restrict_hol_to_6G
7681 FROM HR_ORGANIZATION_UNITS o1
7682 ,HR_ORGANIZATION_INFORMATION hoi1
7683 ,HR_ORGANIZATION_INFORMATION hoi2
7684 ,HR_ORGANIZATION_INFORMATION hoi3
7685 ,HR_ORGANIZATION_INFORMATION hoi4
7686 ,( SELECT TRIM(SCL.SEGMENT2) AS ORG_ID
7687 FROM PER_ALL_ASSIGNMENTS_F ASG
7688 ,HR_SOFT_CODING_KEYFLEX SCL
7689 WHERE ASG.ASSIGNMENT_ID = p_assignment_id
7690 AND ASG.SOFT_CODING_KEYFLEX_ID = SCL.SOFT_CODING_KEYFLEX_ID
7691 AND P_EFFECTIVE_DATE BETWEEN ASG.EFFECTIVE_START_DATE AND ASG.EFFECTIVE_END_DATE ) X
7692 WHERE o1.business_group_id = p_business_group_id
7693 AND hoi1.organization_id = o1.organization_id
7694 AND hoi1.organization_id = X.ORG_ID
7695 AND hoi1.org_information1 = 'NO_LOCAL_UNIT'
7696 AND hoi1.org_information_context = 'CLASS'
7697 AND o1.organization_id = hoi2.org_information1
7698 AND hoi2.ORG_INFORMATION_CONTEXT='NO_LOCAL_UNITS'
7699 AND hoi2.organization_id = hoi3.organization_id
7700 AND hoi3.ORG_INFORMATION_CONTEXT='CLASS'
7701 AND hoi3.org_information1 = 'HR_LEGAL_EMPLOYER'
7702 AND hoi3.organization_id = hoi4.organization_id
7703 AND hoi4.ORG_INFORMATION_CONTEXT='NO_ABSENCE_PAYMENT_DETAILS';
7704
7705 l_person_id NUMBER ;
7706 csr_person_details_rec csr_person_details%ROWTYPE ;
7707 csr_le_details_rec csr_le_details%ROWTYPE ;
7708 BEGIN
7709
7710 OPEN csr_person_id;
7711 FETCH csr_person_id INTO l_person_id;
7712 CLOSE csr_person_id;
7713
7714 OPEN csr_person_details(l_person_id);
7715 FETCH csr_person_details INTO csr_person_details_rec;
7716 CLOSE csr_person_details;
7717
7718 OPEN csr_le_details;
7719 FETCH csr_le_details INTO csr_le_details_rec;
7720 CLOSE csr_le_details;
7721
7722 p_restrict_hol_to_6G := NVL(NVL(csr_person_details_rec.restrict_hol_to_6G,csr_le_details_rec.restrict_hol_to_6G),'Y');
7723
7724
7725 RETURN 1 ;
7726 EXCEPTION WHEN OTHERS THEN
7727 RETURN 0 ;
7728 END get_restrict_hol_to_6g;
7729
7730
7731 FUNCTION get_holiday_days (p_abs_category in varchar2,
7732 p_abs_attendance_id IN NUMBER,
7733 p_hol_days OUT nocopy NUMBER ) RETURN NUMBER IS
7734
7735 CURSOR csr_mat_get_hol_days IS
7736 SELECT paa.abs_information14 hol_days
7737 FROM PER_ABSENCE_ATTENDANCES PAA
7738 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7739
7740 CURSOR csr_pt_mat_get_hol_days IS
7741 SELECT paa.abs_information13 hol_days
7742 FROM PER_ABSENCE_ATTENDANCES PAA
7743 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7744
7745 CURSOR csr_pat_get_hol_days IS
7746 SELECT paa.abs_information10 hol_days
7747 FROM PER_ABSENCE_ATTENDANCES PAA
7748 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7749
7750 CURSOR csr_pt_pat_get_hol_days IS
7751 SELECT paa.abs_information12 hol_days
7752 FROM PER_ABSENCE_ATTENDANCES PAA
7753 WHERE PAA.ABSENCE_ATTENDANCE_ID = p_abs_attendance_id;
7754
7755 BEGIN
7756
7757 IF p_abs_category = 'M' THEN
7758 OPEN csr_mat_get_hol_days;
7759 FETCH csr_mat_get_hol_days INTO p_hol_days;
7760 CLOSE csr_mat_get_hol_days;
7761
7762 ELSIF p_abs_category = 'PTM' THEN
7763 OPEN csr_pt_mat_get_hol_days;
7764 FETCH csr_pt_mat_get_hol_days INTO p_hol_days;
7765 CLOSE csr_pt_mat_get_hol_days;
7766
7767 ELSIF p_abs_category = 'PA' THEN
7768 OPEN csr_pat_get_hol_days;
7769 FETCH csr_pat_get_hol_days INTO p_hol_days;
7770 CLOSE csr_pat_get_hol_days;
7771
7772 ELSIF p_abs_category = 'PTP' THEN
7773 OPEN csr_pt_pat_get_hol_days;
7774 FETCH csr_pt_pat_get_hol_days INTO p_hol_days;
7775 CLOSE csr_pt_pat_get_hol_days;
7776 END IF ;
7777
7778 RETURN 1 ;
7779
7780 EXCEPTION WHEN OTHERS THEN
7781 RETURN 0 ;
7782
7783 END get_holiday_days;
7784
7785 /* 5413738 Added function for get the CMS contact start and end date if singale contact attached to the person*/
7786 FUNCTION get_cms_contact_date(p_assignment_id IN NUMBER, p_abs_start_date IN DATE,
7787 p_cms_contact_start_date OUT nocopy DATE, p_cms_contact_end_date OUT nocopy DATE,
7788 p_cms_contact_count OUT nocopy NUMBER) RETURN NUMBER IS
7789
7790 CURSOR csr_person_id IS
7791 SELECT PERSON_ID
7792 FROM PER_ALL_ASSIGNMENTS_F ASG
7793 WHERE ASG.ASSIGNMENT_ID = p_assignment_id
7794 AND p_abs_start_date BETWEEN ASG.EFFECTIVE_START_DATE
7795 AND ASG.EFFECTIVE_END_DATE;
7796
7797 CURSOR child_contact ( personid NUMBER, contacttype VARCHAR2, abs_stdt DATE) IS
7798 SELECT pap.date_of_birth
7799 ,ROUND(MONTHS_BETWEEN( abs_stdt, pap.date_of_birth ) / 12, 2) AS AGE
7800 ,pcr.contact_type
7801 ,pcr.cont_information1
7802 ,pcr.cont_information2
7803 ,pcr.date_start
7804 ,pcr.date_end
7805 FROM per_all_people_f pap
7806 ,per_contact_relationships pcr
7807 WHERE pap.person_id = pcr.contact_person_id
7808 AND pcr.person_id = personid
7809 AND pcr.contact_type = contacttype
7810 AND (pcr.date_start is null or pcr.date_start <= abs_stdt)
7811 AND (pcr.date_end is null or pcr.date_end >= abs_stdt );
7812
7813 l_person_id NUMBER ;
7814 BEGIN
7815
7816 OPEN csr_person_id;
7817 FETCH csr_person_id INTO l_person_id;
7818 CLOSE csr_person_id;
7819
7820 P_cms_contact_count := 0 ;
7821 p_cms_contact_start_date := NULL ;
7822 p_cms_contact_end_date := NULL ;
7823 FOR I IN child_contact ( l_person_id, 'DC', p_abs_start_date )
7824 LOOP
7825 i.CONT_INFORMATION2 := nvl(i.CONT_INFORMATION2,'N');
7826 -- Age is less than 13 years (or) Age is less than 19 years with chronic flag as Yes
7827 IF (I.AGE < 13) OR (I.AGE < 19 AND i.CONT_INFORMATION2 = 'Y') THEN
7828 P_cms_contact_count := P_cms_contact_count + 1 ;
7829 p_cms_contact_start_date := i.date_start;
7830 p_cms_contact_end_date := i.date_end;
7831 END IF;
7832 END LOOP;
7833 /* if more than one contact is available */
7834 IF P_cms_contact_count <> 1 THEN
7835 p_cms_contact_start_date := NULL ;
7836 p_cms_contact_end_date := NULL ;
7837 END IF;
7838
7839 RETURN 1 ;
7840 EXCEPTION WHEN OTHERS THEN
7841 RETURN 0 ;
7842 END get_cms_contact_date;
7843
7844 FUNCTION get_init_abs_st_date (p_abs_attendance_id IN NUMBER) RETURN DATE IS
7845
7846 CURSOR csr_get_intial_abs_st_date(p_abs_attn_id IN VARCHAR2 ) IS
7847 SELECT nvl(peef2.effective_start_date,peef1.effective_start_date)
7848 FROM pay_element_entry_values_f peevf
7849 ,pay_input_values_f pivf
7850 ,pay_element_entries_f peef1
7851 ,pay_element_entries_f peef2
7852 WHERE peevf.screen_entry_value = p_abs_attn_id
7853 AND pivf.input_value_id = peevf.input_value_id
7854 AND pivf.NAME = 'CREATOR_ID'
7855 AND pivf.legislation_code = 'NO'
7856 AND peef1.element_entry_id = peevf.element_entry_id
7857 AND peef2.element_entry_id(+) = peef1.original_entry_id;
7858
7859 l_initial_abs_st_date DATE ;
7860
7861 BEGIN
7862
7863 OPEN csr_get_intial_abs_st_date(to_char(p_abs_attendance_id));
7864 FETCH csr_get_intial_abs_st_date INTO l_initial_abs_st_date;
7865 CLOSE csr_get_intial_abs_st_date;
7866 RETURN l_initial_abs_st_date ;
7867
7868 END get_init_abs_st_date;
7869
7870 /* fetch the current absence start date */
7871 FUNCTION get_abs_st_date (p_abs_attendance_id IN NUMBER) RETURN DATE IS
7872
7873 CURSOR csr_get_abs_st_date(p_abs_attn_id IN VARCHAR2 ) IS
7874 SELECT date_start
7875 FROM per_absence_attendances
7876 WHERE absence_attendance_id = p_abs_attn_id ;
7877
7878 l_abs_st_date DATE ;
7879
7880 BEGIN
7881
7882 OPEN csr_get_abs_st_date(p_abs_attendance_id);
7883 FETCH csr_get_abs_st_date INTO l_abs_st_date;
7884 CLOSE csr_get_abs_st_date;
7885 RETURN l_abs_st_date ;
7886
7887 END get_abs_st_date;
7888
7889
7890 END PAY_NO_ABSENCE;