[Home] [Help]
PACKAGE BODY: APPS.PAY_FR_PTO_PKG
Source
4 g_rate_tab rate_tab;
1 package body pay_fr_pto_pkg as
2 /* $Header: pyfrhpto.pkb 120.2 2005/09/21 06:43:47 ayegappa noship $ */
3 g_package varchar2(50) := ' pay_fr_pto_pkg.'; -- Global package name
5
6 TYPE term_payment_rec is RECORD
7 (payment number,
8 days number,
9 daily_rate number,
10 accrual_date date,
11 next_payment number);
12
13 TYPE term_payment_tab is TABLE of term_payment_rec INDEX by BINARY_INTEGER;
14
15 term_payment term_payment_tab;
16
17 TYPE reg_payment_rec is RECORD
18 (payment number,
19 accrual_date date,
20 next_payment number);
21
22 TYPE reg_payment_tab is TABLE of reg_payment_rec INDEX by BINARY_INTEGER;
23
24 reg_payment reg_payment_tab;
25
26 --
27 -------------------------------------------------------------------------------
28 -- Function read_termination_payment_rate
29 -- obtains the first Rate value from the pl/sql table
30 -------------------------------------------------------------------------------
31 Function read_termination_payment_rate(p_accrual_plan_id IN NUMBER,
32 p_days OUT NOCOPY NUMBER)
33 return number is
34 l_index number;
35
36 begin
37
38 hr_utility.trace('in read termination payment rate');
39
40 hr_utility.trace('p_accrual_plan_id = ' || p_accrual_plan_id);
41
42 l_index := p_accrual_plan_id * 10 + 1;
43
44 p_days := term_payment(l_index).days;
45
46 hr_utility.trace('p_days = ' || p_days);
47
48 hr_utility.trace('left read termination payment rate');
49
50 return 0;
51
52 EXCEPTION
53 WHEN OTHERS THEN
54 hr_utility.trace('read_termination_payment rate');
55 hr_utility.trace(SQLCODE);
56 hr_utility.trace(SQLERRM);
57 Raise;
58 end read_termination_payment_rate;
59
60
61 --
62 -------------------------------------------------------------------------------
63 -- LOAD_FR_PAYSLIP_ACCRUAL_DATA Archiver Call
64 -- Called by the payslip archiver PAY_FR_ARC_PKG
65 -------------------------------------------------------------------------------
66 Procedure load_fr_payslip_accrual_data
67 (P_assignment_id IN Number
68 ,p_date_earned IN Date
69 ,p_business_Group_id IN Number) is
70 --
71 -- Cursor to get all accrual plans for this assignment as at date earned
72 --
73 CURSOR csr_all_plans is
74 select /*+ USE_NL(pap, asg, pee) */
75 pap.accrual_plan_id accrual_plan_id
76 ,pap.accrual_plan_name accrual_plan_name
77 ,pap.accrual_category accrual_category
78 ,pap.accrual_plan_element_type_id accrual_plan_element_type_id
79 ,pee.effective_start_date effective_start_date
80 ,asg.payroll_id payroll_id
81 from pay_accrual_plans pap
82 ,pay_element_entries_f pee
83 ,per_all_assignments_f asg
84 where pap.business_group_id + 0 = p_business_group_id
85 and asg.assignment_id = p_assignment_id
86 and p_date_earned between asg.effective_start_date and asg.effective_end_date
87 and pee.element_link_id in (select element_link_id
88 from pay_element_links_f
89 where element_type_id = pap.accrual_plan_element_type_id
90 )
91 and pee.assignment_id = p_assignment_id
92 and p_date_earned between pee.effective_start_date and pee.effective_end_date;
93
94 cursor csr_check_for_termination is
95 select null
96 from per_periods_of_service pds
97 ,PER_ALL_ASSIGNMENTS_F ASG
98 where pds.period_of_service_id = asg.period_of_service_id
102 and pds.actual_termination_date is not null;
99 and asg.assignment_id = p_assignment_id
100 and pds.actual_termination_date
101 between asg.effective_start_date and asg.effective_end_Date
103
104 l_accrual_total number := 0;
105 l_ent_total number := 0;
106 l_taken_total number := 0;
107 l_balance_total number := 0;
108
109 l_accrual_this number := 0;
110 l_taken_this number := 0;
111 l_balance_this number := 0;
112 l_ent_this number := 0;
113 l_ent_balance number := 0;
114
115 l_standard_entitlement number := 0;
116 l_standard_accrual number := 0;
117
118 l_term_pay_total number := 0;
119 l_term_pay_this number := 0;
120 --l_term_ent_total number := 0;
121 --l_term_ent_this number := 0;
122 l_term_pay_period_1 number := 0;
123 l_gross_taken_total number := 0;
124 l_ret number;
125
126 l_unused_date date;
127 l_unused_number number;
128 l_unused_char varchar2(10);
129 l_remaining number;
130
131 l_total_accrued_pto number := 0;
132 l_total_accrued_protected number := 0;
133
134 l_ent_m number;
135 l_net_m number;
136
137 l_fr_plan_info g_fr_plan_info;
138 l_fr_pay_info g_fr_pay_info;
139 l_fr_pay_r_info g_fr_pay_info;
140
141 l_index number := 0;
142
143 l_std_start_date date;
144 l_std_end_date date;
145 l_std_absence number;
146 l_std_carryover number;
147 l_std_other number;
148 l_payslip_taken_to_date date;
149
150 l_proc VARCHAR2(72) := g_package||' load_fr_payslip_accrual_data ';
151 BEGIN
152 hr_utility.set_location('Entering ' || l_proc,10);
153 --
154 -- Set flag to accrual formula to not deduct holiday from the accrual
155 -- (this is usually done if there is no entitlement stored)
156 --
157 -- Clear the structure to hold the results;
158 --
159 g_fr_payslip_info.DELETE;
160 hr_utility.set_location('Step ' || l_proc,30);
161 --
162 -- Main loop for all plans for this assignment
163 --
164 hr_utility.set_location('assignment_id is ', p_assignment_id);
165 hr_utility.set_location('business_group_id is ' , p_business_group_id);
166 hr_utility.set_location('date earned is ' || to_char(p_date_earned), 30);
167
168
169 FOR l_accrual_plan_rec in csr_all_plans LOOP
170 l_index := l_index + 1;
171
172 hr_utility.set_location('l_accrual_plan_rec.accrual_plan_id is ', l_accrual_plan_rec.accrual_plan_id);
176 IF l_accrual_plan_rec.accrual_category in ('FR_MAIN_HOLIDAY', 'FR_RTT_HOLIDAY', 'FR_ADDITIONAL_HOLIDAY') THEN
173 hr_utility.set_location('l_accrual_plan_rec.accrual_plan_element_type_id is ' , l_accrual_plan_rec.accrual_plan_element_type_id);
174 hr_utility.set_location('l_accrual_plan_rec.payroll_id is ' , l_accrual_plan_rec.payroll_id);
175
177 --
178 -- Call this year and previous 3 years
179 --
180 l_accrual_total := 0;
181 l_ent_total := 0;
182 l_taken_total := 0;
183 l_balance_total := 0;
184
185 l_accrual_this := 0;
186 l_ent_this := 0;
187 l_taken_this := 0;
188 l_term_pay_total := 0;
189 l_term_pay_this := 0;
190
191 l_total_accrued_pto := 0;
192 l_total_accrued_protected := 0;
193
194 --
195 -- Load the plan info
196 --
197 hr_utility.set_location('Step ' || l_proc,40);
198 l_fr_plan_info := get_fr_accrual_plan_info(
199 p_accrual_plan_id => l_accrual_plan_rec.accrual_plan_id
200 ,p_accrual_date => p_date_earned);
201 --
202 -- record the date as at holiday must be taken before to reduce entitlement, rather than appear
203 -- on the payslip as 'taken' bug 2448832
204 --
205 l_payslip_taken_to_date := l_fr_plan_info.accrual_year_start;
206
207 hr_utility.set_location('Step ' || l_proc,50);
208 --
209 -- Call the accrual formula for this year, up to date_earned. Do not deduct holiday taken
210 -- from accrual. This may return zero if entitlement is stored past p_date_earned - this
211 -- will be picked up by entitlement
212 --
213 /**/
214 FR_Get_Accrual
215 (P_Assignment_ID => P_Assignment_ID
216 ,P_Calculation_Date => p_date_earned
217 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
218 ,P_Plan_ID => l_accrual_plan_rec.accrual_plan_id
219 ,P_Business_Group_ID => p_business_Group_id
220 ,P_Payroll_ID => l_accrual_plan_rec.payroll_id
224 ,P_Start_Date => l_unused_date
221 ,p_create_all => 'N' /* (do not create extra accrual types) */
222 ,p_reprocess_whole_period => 'N' /* (only run accrual from latest ent to p_date_earned) */
223 ,p_payslip_process => 'Y'
225 ,P_End_Date => l_unused_date
226 ,P_Accrual_End_Date => l_unused_date
227 ,P_total_accrued_pto => l_total_accrued_pto
228 ,P_total_Accrued_protected => l_total_Accrued_protected
229 ,P_total_Accrued_seniority => l_unused_number
230 ,P_total_Accrued_mothers => l_unused_number
231 ,P_total_Accrued_conventional => l_unused_number ) ;
232
233 hr_utility.set_location('Step ' || l_proc,60);
234 l_accrual_this := nvl(l_total_accrued_pto,0) + nvl(l_total_Accrued_protected,0);
235 l_accrual_total := l_accrual_total + l_accrual_this;
236
237
238 --
239 -- Get the entitlement and net for this year. Only deduct holidays taken and paid
240 -- (do not deduct all holidays booked, as the payslip must only show days taken to date )
241 --
242 hr_utility.set_location('Step ' || l_proc,60);
243
244 get_fr_net_entitlement
245 (p_accrual_plan_id => l_accrual_plan_rec.accrual_plan_id
246 ,p_effective_date => p_date_earned
247 ,p_assignment_id => p_assignment_id
248 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
249 ,p_remaining => l_term_pay_this
250 ,p_net_main => l_taken_total /* days taken and paid this accrual year, from any accrual year */
251 ,p_net_protected => l_unused_number
252 ,p_net_young_mothers => l_unused_number
253 ,p_net_seniority => l_unused_number
254 ,p_net_conventional => l_unused_number
255 ,p_ent_main => l_ent_this /* net entitlement, excluding days paid this year */
256 ,p_ent_protected => l_unused_number
257 ,p_ent_young_mothers => l_unused_number
258 ,p_ent_seniority => l_unused_number
259 ,p_ent_conventional => l_unused_number
260 ,p_accrual_start_date => l_unused_date
261 ,p_accrual_end_date => l_unused_date
262 ,p_type_calculation => 'Y' /* indicated paid days should be deducted */
263 ,p_paid_days_to => l_payslip_taken_to_date);
264
265 hr_utility.set_location('Step ' || l_proc,70);
266 hr_utility.trace('y=1 l_payslip_taken_to_date is ' || l_payslip_taken_to_date);
267 hr_utility.trace('y=1 ltaken_total is ' || l_taken_total);
268 hr_utility.trace('y=1 l_ent_this is ' || l_ent_this);
269 hr_utility.trace('y=1 l_term_pay_this is ' || l_term_pay_this);
270 l_term_pay_period_1 := l_term_pay_this;
271 --
272 -- Add back the term payments for this year to ent
273 --
274 l_ent_this := l_ent_this + l_term_pay_this;
275 l_term_pay_total := l_term_pay_total + nvl(l_term_pay_this,0);
276 l_ent_total := l_ent_total + nvl(l_ent_this,0);
277 hr_utility.trace('y=1 adj ent is ' || l_ent_this);
278 --
279 -- Y-1
280 --
281 hr_utility.set_location('3 get net ent', 130);
282 get_fr_net_entitlement
283 (p_accrual_plan_id => l_accrual_plan_rec.accrual_plan_id
284 ,p_effective_date => add_months(p_date_earned, -12)
285 ,p_assignment_id => p_assignment_id
286 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
287 ,p_remaining => l_term_pay_this
288 ,p_net_main => l_unused_number
289 ,p_net_protected => l_unused_number
290 ,p_net_young_mothers => l_unused_number
291 ,p_net_seniority => l_unused_number
292 ,p_net_conventional => l_unused_number
293 ,p_ent_main => l_ent_this
294 ,p_ent_protected => l_unused_number
295 ,p_ent_young_mothers => l_unused_number
296 ,p_ent_seniority => l_unused_number
297 ,p_ent_conventional => l_unused_number
298 ,p_accrual_start_date => l_unused_date
299 ,p_accrual_end_date => l_unused_date
300 ,p_type_calculation => 'Y' /* indicates paid days should be deducted */
301 ,p_paid_days_to => l_payslip_taken_to_date);
302
306 hr_utility.trace('y=2 l_ent_this is ' || l_ent_this);
303 hr_utility.set_location('Step ' || l_proc,80);
304 hr_utility.trace('y=2 l_payslip_taken_to_date is ' || l_payslip_taken_to_date);
305 hr_utility.trace('y=2 ltaken_total is ' || l_taken_total);
307 hr_utility.trace('y=2 l_term_pay_this is ' || l_term_pay_this);
308 --
309 -- Add back the term payments for this year to ent
310 --
311 l_ent_this := l_ent_this + l_term_pay_this;
312 l_term_pay_total := l_term_pay_total + nvl(l_term_pay_this,0);
313 hr_utility.trace('l_ent_this is ' || l_ent_this);
314 hr_utility.trace('y=2 adj ent is ' || l_ent_this);
315
316 l_ent_total := l_ent_total + nvl(l_ent_this,0);
317 --
318 -- Y-2
319 --
320 get_fr_net_entitlement
321 (p_accrual_plan_id => l_accrual_plan_rec.accrual_plan_id
322 ,p_effective_date => add_months(p_date_earned, -24)
323 ,p_assignment_id => p_assignment_id
324 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
325 ,p_remaining => l_term_pay_this
326 ,p_net_main => l_unused_number
327 ,p_net_protected => l_unused_number
328 ,p_net_young_mothers => l_unused_number
329 ,p_net_seniority => l_unused_number
330 ,p_net_conventional => l_unused_number
331 ,p_ent_main => l_ent_this
332 ,p_ent_protected => l_unused_number
333 ,p_ent_young_mothers => l_unused_number
334 ,p_ent_seniority => l_unused_number
335 ,p_ent_conventional => l_unused_number
336 ,p_accrual_start_date => l_unused_date
337 ,p_accrual_end_date => l_unused_date
338 ,p_type_calculation => 'Y' /* indicated paid days should be deducted */
339 ,p_paid_days_to => l_payslip_taken_to_date);
340
341 hr_utility.set_location('Step ' || l_proc,80);
342 hr_utility.trace('l_ent_this is ' || l_ent_this);
343 hr_utility.trace('y=3 l_term_pay_this is ' || l_term_pay_this);
344 --
345 -- Add back the term payments for this year to ent
346 --
347 l_ent_this := l_ent_this + l_term_pay_this;
348 l_term_pay_total := l_term_pay_total + nvl(l_term_pay_this,0);
349 hr_utility.trace('l_ent_this is ' || l_ent_this);
350 l_ent_total := l_ent_total + nvl(l_ent_this,0);
351 hr_utility.trace('y=3 adj ent is ' || l_ent_this);
352 --
353 -- Y-3
354 --
355 get_fr_net_entitlement
356 (p_accrual_plan_id => l_accrual_plan_rec.accrual_plan_id
357 ,p_effective_date => add_months(p_date_earned, -36)
358 ,p_assignment_id => p_assignment_id
359 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
360 ,p_remaining => l_term_pay_this
361 ,p_net_main => l_unused_number
362 ,p_net_protected => l_unused_number
363 ,p_net_young_mothers => l_unused_number
364 ,p_net_seniority => l_unused_number
365 ,p_net_conventional => l_unused_number
366 ,p_ent_main => l_ent_this
367 ,p_ent_protected => l_unused_number
368 ,p_ent_young_mothers => l_unused_number
369 ,p_ent_seniority => l_unused_number
370 ,p_ent_conventional => l_unused_number
371 ,p_accrual_start_date => l_unused_date
372 ,p_accrual_end_date => l_unused_date
373 ,p_type_calculation => 'Y' /* indicated paid days should be deducted */
374 ,p_paid_days_to => l_payslip_taken_to_date);
375
376 hr_utility.set_location('Step ' || l_proc,90);
377 hr_utility.trace('y=3 l_payslip_taken_to_date is ' || l_payslip_taken_to_date);
378 hr_utility.trace('y=3 ltaken_total is ' || l_taken_total);
379 hr_utility.trace('y=3 l_ent_this is ' || l_ent_this);
380 hr_utility.trace('l_ent_this is ' || l_ent_this);
381 --
382 -- Add back the term payments for this year to ent
386 hr_utility.trace('l_ent_this is ' || l_ent_this);
383 --
384 l_ent_this := l_ent_this + l_term_pay_this;
385
387 hr_utility.trace('y=4 l_term_pay_this is ' || l_term_pay_this);
388 l_term_pay_total := l_term_pay_total + nvl(l_term_pay_this,0);
389 hr_utility.trace('l_ent_this is ' || l_ent_this);
390 hr_utility.trace('y=4 adj ent is ' || l_ent_this);
391
392 l_ent_total := l_ent_total + nvl(l_ent_this,0);
393 l_ent_balance := nvl(l_ent_total,0) - nvl(l_taken_total,0);
394
395 --
396 -- If termination, adjust the output as follows:
397 -- if acc + ent (gross of term payments) = termination days paid + holiday days paid
398 -- set values to zero.
399 -- the taken represents all termination payments over all years +
400 -- any holidays booked and paid this period.
401 --
402 open csr_check_for_termination;
403 fetch csr_check_for_termination into l_unused_char;
404 if csr_check_for_termination%FOUND then
405 l_gross_taken_total := l_taken_total - l_term_pay_period_1;
406 if l_accrual_total + l_ent_total = l_term_pay_total + l_gross_taken_total THEN
407 -- set variables to zero. Taken represents all paid hols is year, + all
408 -- termination payments this year.
409 --
410 l_accrual_total := 0;
411 l_ent_total := 0;
412 l_ent_balance := 0;
413 l_taken_total := l_gross_taken_total + l_term_pay_total;
414 end if;
415 end if;
416 close csr_check_for_termination;
417 hr_utility.trace('end tot acc = ' || l_accrual_total);
418 hr_utility.trace('end ent tot = ' || l_ent_total);
419 hr_utility.trace('end tak tot = ' || l_taken_total);
420 hr_utility.trace('end bal tot = ' || l_ent_balance);
421 hr_utility.trace('end term tot = ' || l_term_pay_total);
422
423
424 --
425 -- Calculate and store values in record structure.
426 --
427 g_fr_payslip_info(l_index).assignment_id := p_assignment_id;
428 g_fr_payslip_info(l_index).plan_name := l_accrual_plan_rec.accrual_plan_name;
429 g_fr_payslip_info(l_index).Accrual := nvl(l_accrual_total,0);
430 g_fr_payslip_info(l_index).Entitlement := nvl(l_ent_total,0);
431 g_fr_payslip_info(l_index).Taken := nvl(l_taken_total,0);
432 g_fr_payslip_info(l_index).Balance := l_ent_balance;
433
437 --
434 hr_utility.set_location('Step ' || l_proc,100);
435 --
436 --
438 ELSE
439 --
440 -- Call the standard functions
441 --
442 hr_utility.set_location('Step ' || l_proc,100);
443
444 per_accrual_calc_functions.get_accrual(
445 p_assignment_id => p_assignment_id
446 ,p_plan_id => l_accrual_plan_rec.accrual_plan_id
447 ,p_calculation_date => p_date_earned
448 ,p_business_group_id => p_business_group_id
449 ,p_payroll_id => l_accrual_plan_rec.payroll_id
450 ,p_assignment_action_id => -1
451 ,p_accrual_start_date => null
452 ,p_accrual_latest_balance => null
453 ,p_start_date => l_std_start_date
454 ,p_end_date => l_std_end_date
455 ,p_accrual_end_date => l_unused_date
456 ,p_accrual => l_accrual_total);
457
458 hr_utility.set_location('Step ' || l_proc,110);
459
460 l_std_absence := per_accrual_calc_functions.get_absence(
461 p_assignment_id => p_assignment_id
462 ,p_plan_id => l_accrual_plan_rec.accrual_plan_id
463 ,p_start_date => l_std_start_date
464 ,p_calculation_date => l_std_end_date);
465
466 hr_utility.set_location('Step ' || l_proc,120);
467
468 l_std_other := per_accrual_calc_functions.get_other_net_contribution(
469 p_assignment_id => p_assignment_id
470 ,p_plan_id => l_accrual_plan_rec.accrual_plan_id
471 ,p_start_date => l_std_start_date
472 ,p_calculation_date => l_std_end_date );
473
474 hr_utility.set_location('Step ' || l_proc,130);
475
476 l_std_carryover := per_accrual_calc_functions.get_carry_over(
477 p_assignment_id => p_assignment_id
478 ,p_plan_id => l_accrual_plan_rec.accrual_plan_id
479 ,p_start_date => l_std_start_date
480 ,p_calculation_date => l_std_end_date);
481
482 hr_utility.set_location('Step ' || l_proc,140);
483
484 --
485 -- Archive the values
486 --
487 g_fr_payslip_info(l_index).assignment_id := p_assignment_id;
488 g_fr_payslip_info(l_index).plan_name := l_accrual_plan_rec.accrual_plan_name;
489 g_fr_payslip_info(l_index).Accrual := 0;
493
490 g_fr_payslip_info(l_index).Entitlement := nvl(l_accrual_total,0) + nvl(l_std_other,0) + nvl(l_std_carryover,0);
491 g_fr_payslip_info(l_index).Taken := nvl(l_std_absence,0);
492 g_fr_payslip_info(l_index).Balance := nvl(l_accrual_total,0) + nvl(l_std_other,0) + nvl(l_std_carryover,0) - nvl(l_std_absence,0);
494 hr_utility.set_location('Step ' || l_proc,150);
495
496 hr_utility.set_location(' loop_counter is ' || to_char(l_index), 20);
497 hr_utility.set_location(' g_fr_payslip_info(l_index).Accrual is ' , g_fr_payslip_info(l_index).Accrual);
498 hr_utility.set_location(' g_fr_payslip_info(l_index).Entitlementl is ' , g_fr_payslip_info(l_index).Entitlement);
499 hr_utility.set_location(' g_fr_payslip_info(l_index).Taken is ' , g_fr_payslip_info(l_index).Taken);
500 hr_utility.set_location(' g_fr_payslip_info(l_index).Balance is ' , g_fr_payslip_info(l_index).Balance);
501
502 END IF; /* if French Type accrual category */
503 END LOOP; /* loop of all plans */
504 --
505 -- Reset the payslip taken to date bug 2448832
506 --
507 hr_utility.set_location('Leaving: '||l_proc,160);
508 END load_fr_payslip_accrual_data;
509 --
510 -------------------------------------------------------------------------------
511 -- PROCEDURE GET_FR_NET_ENTITLEMENT --
512 -------------------------------------------------------------------------------
513 procedure get_fr_net_entitlement
514 (p_accrual_plan_id IN Number
515 ,p_effective_date IN Date
516 ,p_assignment_id IN Number
517 ,p_ignore_ent_adjustments IN Varchar2 default 'N'
518 -- adding extra parameter for additional holidays
519 -- to get correct accrual dates
520 ,p_accrual_type IN varchar2 default null
521 ,p_legal_period_end IN date default null
522 --
523 ,p_remaining OUT NOCOPY Number
524 ,p_net_main OUT NOCOPY Number
525 ,p_net_protected OUT NOCOPY Number
526 ,p_net_young_mothers OUT NOCOPY Number
527 ,p_net_seniority OUT NOCOPY Number
528 ,p_net_conventional OUT NOCOPY Number
529 ,p_ent_main OUT NOCOPY Number
530 ,p_ent_protected OUT NOCOPY Number
531 ,p_ent_young_mothers OUT NOCOPY Number
532 ,p_ent_seniority OUT NOCOPY Number
533 ,p_ent_conventional OUT NOCOPY Number
534 ,p_accrual_start_date OUT NOCOPY Date
535 ,p_accrual_end_date OUT NOCOPY Date
536 ,p_type_calculation IN Varchar2 default 'N' /* Normal, Y=Payslip A=Archive */
537 ,p_paid_days_to IN Date default null
538 ) is
539 --
540 l_fr_plan_info g_fr_plan_info;
541 l_fr_pay_info g_fr_pay_info;
542 l_fr_pay_r_info g_fr_pay_info;
543 --
544 l_accrual_plan_id number := p_accrual_plan_id;
545 l_net_m Number := 0; l_net_p Number := 0; l_net_y Number := 0; l_net_s Number := 0; l_net_c Number := 0;
546 --
547 l_ent_m Number := 0; l_ent_p Number := 0; l_ent_y Number := 0; l_ent_s Number := 0; l_ent_c Number := 0;
548 l_obs_m Number := 0; l_obs_p Number := 0; l_obs_y Number := 0; l_obs_s Number := 0; l_obs_c Number := 0;
549 l_adj_m Number := 0; l_adj_p Number := 0; l_adj_y Number := 0; l_adj_s Number := 0; l_adj_c Number := 0;
550 --
551 l_paid_m0 Number := 0; l_paid_p0 Number := 0; l_paid_y0 Number := 0; l_paid_s0 Number := 0; l_paid_c0 Number := 0;
552 l_paid_m1 Number := 0; l_paid_p1 Number := 0; l_paid_y1 Number := 0; l_paid_s1 Number := 0; l_paid_c1 Number := 0;
553 --
554 l_taken_total Number;
555 l_unused_number Number;
556 l_unused_char varchar2(30);
557 l_unused_date date;
558 l_latest_entitlement_date date;
559 l_ret Number;
560 l_previous_paid_absences Number := 0;
561 l_current_paid_absences Number := 0;
562 l_previous_paid_absences_retro Number := 0;
563 l_current_paid_absences_retro Number := 0;
564 l_action_sequence PAY_ASSIGNMENT_ACTIONS.ACTION_SEQUENCE%TYPE;
565 --
569 --
566 l_booked_m Number; l_booked_s Number; l_booked_y Number; l_booked_c Number; l_booked_p Number;
567 --
568 l_term_payment Number;
570 l_net_main Number;
571 l_net_protected Number;
572 l_net_conventional Number;
573 l_net_seniority Number;
574 l_net_young_mothers Number;
575 --
576 l_ent_main Number;
577 l_ent_protected Number;
578 l_ent_young_mothers Number;
579 l_ent_seniority Number;
580 l_ent_conventional Number;
581
582
583 -- Get the sum per accrual type of all booked absences for this asg
584 -- Includes this absence (if it is saved).
585 --
586 cursor csr_check_for_termination is
587 select null
588 from per_periods_of_service pds
589 ,PER_ALL_ASSIGNMENTS_F ASG
590 where pds.period_of_service_id = asg.period_of_service_id
591 and asg.assignment_id = p_assignment_id
592 and pds.actual_termination_date
593 between asg.effective_start_date and asg.effective_end_Date
594 and pds.actual_termination_date is not null
595 ;
596 --
597 -- Payslip processing - sum the totals of paid absences, fetching from run results, not
598 -- all booked (element entries).
599 --
600 CURSOR csr_previous_action_sequence is
601 select max(paa.action_sequence)
602 from pay_assignment_actions paa
603 ,pay_payroll_actions ppa
604 where ppa.payroll_action_id = paa.payroll_action_id
605 and paa.assignment_id = p_assignment_id
606 and p_paid_days_to >= ppa.effective_date
607 and ppa.action_type in ('Q','R');
608
609 CURSOR csr_previous_paid_absences is
610 select sum(prrv_days.result_value)
611 from pay_run_result_values prrv_days
612 ,pay_run_result_values prrv_accrual
613 ,pay_run_result_values prrv_plan
614 ,pay_run_results prr
615 ,pay_assignment_actions paa
616 where prrv_days.run_result_id = prr.run_result_id
617 and prrv_plan.run_result_id = prr.run_result_id
618 and prrv_accrual.run_result_id = prr.run_result_id
619 and prrv_days.input_value_id = l_fr_pay_info.pay_total_days_input_ID
620 and prrv_accrual.input_value_id = l_fr_pay_info.pay_accrual_date_input_ID
621 and prrv_plan.input_value_id = l_fr_pay_info.pay_plan_input_ID
622 and prr.assignment_action_id = paa.assignment_action_id
623 and paa.assignment_id = p_assignment_id
624 and prr.element_type_id = l_fr_pay_info.pay_element_id
625 and prr.status in ('P','PA')
626 and prrv_plan.result_value = l_accrual_plan_id
627 and paa.action_sequence < l_action_sequence
628 /* restrict to just this accrual year, otherwise all taken across all plan years will be added in */
629 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
630 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
631
632
633 CURSOR csr_previous_paid_absences_r is
634 select sum(prrv_days.result_value)
635 from pay_run_result_values prrv_days
636 ,pay_run_result_values prrv_accrual
637 ,pay_run_result_values prrv_plan
638 ,pay_run_results prr
639 ,pay_assignment_actions paa
640 where prrv_days.run_result_id = prr.run_result_id
641 and prrv_plan.run_result_id = prr.run_result_id
642 and prrv_accrual.run_result_id = prr.run_result_id
643 and prrv_days.input_value_id = l_fr_pay_r_info.pay_total_days_input_ID
644 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_accrual_date_input_ID
645 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_plan_input_ID
646 and prr.assignment_action_id = paa.assignment_action_id
647 and paa.assignment_id = p_assignment_id
648 and prr.element_type_id = l_fr_pay_r_info.pay_element_id
649 and prr.status in ('P','PA')
650 and prrv_plan.result_value = l_accrual_plan_id
651 and paa.action_sequence < l_action_sequence
655 --
652 /* restrict to just this accrual year, otherwise all taken across all plan years will be added in */
653 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
654 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
656 -- Get the absences on or after the action sequence
657 CURSOR csr_current_paid_absences is
658 select sum(prrv_days.result_value)
659 from pay_run_result_values prrv_days
660 ,pay_run_result_values prrv_accrual
661 ,pay_run_result_values prrv_plan
662 ,pay_run_results prr
663 ,pay_assignment_actions paa
664 where prrv_days.run_result_id = prr.run_result_id
665 and prrv_plan.run_result_id = prr.run_result_id
666 and prrv_accrual.run_result_id = prr.run_result_id
667 and prrv_days.input_value_id = l_fr_pay_info.pay_total_days_input_ID
668 and prrv_accrual.input_value_id = l_fr_pay_info.pay_accrual_date_input_ID
669 and prrv_plan.input_value_id = l_fr_pay_info.pay_plan_input_ID
670 and prrv_plan.result_value = l_accrual_plan_id
671 and prr.status in ('P','PA')
672 and paa.action_sequence >= l_action_sequence
673 and prr.assignment_action_id = paa.assignment_action_id
674 and paa.assignment_id = p_assignment_id
675 and prr.element_type_id = l_fr_pay_info.pay_element_id;
676
677 -- Get the absences on or after the action sequence
678 CURSOR csr_current_paid_absences_r is
679 select sum(prrv_days.result_value)
680 from pay_run_result_values prrv_days
681 ,pay_run_result_values prrv_accrual
682 ,pay_run_result_values prrv_plan
683 ,pay_run_results prr
684 ,pay_assignment_actions paa
685 where prrv_days.run_result_id = prr.run_result_id
686 and prrv_plan.run_result_id = prr.run_result_id
687 and prrv_accrual.run_result_id = prr.run_result_id
688 and prrv_days.input_value_id = l_fr_pay_r_info.pay_total_days_input_ID
689 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_accrual_date_input_ID
690 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_plan_input_ID
691 and prrv_plan.result_value = l_accrual_plan_id
692 and paa.action_sequence >= l_action_sequence
693 and prr.assignment_action_id = paa.assignment_action_id
694 and paa.assignment_id = p_assignment_id
695 and prr.status in ('P','PA')
696 and prr.element_type_id = l_fr_pay_r_info.pay_element_id;
697
698 -- Get the minimum action sequence in this accrual year
699 --
700 CURSOR csr_current_action_sequence is
701 select min(paa.action_sequence)
702 from pay_assignment_actions paa
703 ,pay_payroll_actions ppa
704 where ppa.payroll_action_id = paa.payroll_action_id
705 and paa.assignment_id = p_assignment_id
706 and p_paid_days_to <= ppa.effective_date
707 and ppa.action_type in ('Q','R');
708
709 CURSOR csr_previous_and_current_seq is
710 select max(paa.action_sequence)
711 from pay_assignment_actions paa
712 ,pay_payroll_actions ppa
713 where ppa.payroll_action_id = paa.payroll_action_id
714 and paa.assignment_id = p_assignment_id
715 and p_paid_days_to >= ppa.effective_date
716 and ppa.action_type in ('Q','R');
717
718
719 CURSOR csr_prev_and_current_paid_abs is
720 select sum(prrv_days.result_value)
721 from pay_run_result_values prrv_days
722 ,pay_run_result_values prrv_accrual
723 ,pay_run_result_values prrv_plan
724 ,pay_run_results prr
725 ,pay_assignment_actions paa
726 where prrv_days.run_result_id = prr.run_result_id
727 and prrv_plan.run_result_id = prr.run_result_id
728 and prrv_accrual.run_result_id = prr.run_result_id
729 and prrv_days.input_value_id = l_fr_pay_info.pay_total_days_input_ID
730 and prrv_accrual.input_value_id = l_fr_pay_info.pay_accrual_date_input_ID
731 and prrv_plan.input_value_id = l_fr_pay_info.pay_plan_input_ID
732 and prr.assignment_action_id = paa.assignment_action_id
733 and paa.assignment_id = p_assignment_id
734 and prrv_plan.result_value = l_accrual_plan_id
735 and prr.element_type_id = l_fr_pay_info.pay_element_id
736 and prr.status in ('P','PA')
737 and paa.action_sequence <= l_action_sequence
738 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
739 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
740
741 CURSOR csr_prev_and_cur_paid_abs_r is
742 select sum(prrv_days.result_value)
743 from pay_run_result_values prrv_days
744 ,pay_run_result_values prrv_accrual
745 ,pay_run_result_values prrv_plan
746 ,pay_run_results prr
747 ,pay_assignment_actions paa
748 where prrv_days.run_result_id = prr.run_result_id
752 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_accrual_date_input_ID
749 and prrv_plan.run_result_id = prr.run_result_id
750 and prrv_accrual.run_result_id = prr.run_result_id
751 and prrv_days.input_value_id = l_fr_pay_r_info.pay_total_days_input_ID
753 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_plan_input_ID
754 and prr.assignment_action_id = paa.assignment_action_id
755 and paa.assignment_id = p_assignment_id
756 and prrv_plan.result_value = l_accrual_plan_id
757 and prr.element_type_id = l_fr_pay_r_info.pay_element_id
758 and prr.status in ('P','PA')
759 and paa.action_sequence <= l_action_sequence
760 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
761 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
762
763 --
764 -- Termination processing - get sum of paid absences
765 --
766 cursor csr_get_paid_days is
767 select sum(prrv_days.result_value)
768 from pay_run_result_values prrv_days
769 ,pay_run_result_values prrv_accrual
770 ,pay_run_results prr
771 ,pay_assignment_actions paa
772 ,pay_payroll_actions ppa
773 where prrv_days.run_result_id = prr.run_result_id
774 and prrv_accrual.run_result_id = prr.run_result_id
775 and prrv_days.input_value_id = l_fr_plan_info.term_days_iv_ID
776 and prrv_accrual.input_value_id = l_fr_plan_info.term_accrual_date_iv_ID
777 and prr.assignment_action_id = paa.assignment_action_id
778 and paa.assignment_id = p_assignment_id
779 and prr.element_type_id = l_fr_plan_info.term_element_id
780 and prr.status in ('P','PA')
781 and ppa.payroll_action_id = paa.payroll_action_id
782 -- termination payments always exist over all time for an accrual year
783 -- and p_paid_days_to >= ppa.effective_date
784 -- restrict to just this accrual year,
785 -- otherwise all taken across all plan years will be added in
786 -- this cursor is used by the accruals calculation
787 and prrv_accrual.result_value between
788 fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
789 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
790
791
792 --
793 -- get the total of ENTITLEMENT, OBSOLETION, ADJUSTMENT entries for this asg for this accrual plan year
794 --
795 cursor csr_get_ent_obs(
796 p_type_m_iv_id number
797 ,p_type_p_iv_id number
798 ,p_type_s_iv_id number
799 ,p_type_c_iv_id number
800 ,p_type_y_iv_id number
801 ,p_type_accrual_date_iv_id number ) is
802 select sum(fnd_number.canonical_to_number(pevm.screen_entry_value))
803 ,sum(fnd_number.canonical_to_number(pevp.screen_entry_value))
804 ,sum(fnd_number.canonical_to_number(pevc.screen_entry_value))
805 ,sum(fnd_number.canonical_to_number(pevs.screen_entry_value))
806 ,sum(fnd_number.canonical_to_number(pevy.screen_entry_value))
807 from pay_element_entry_values_f pevm
808 ,pay_element_entry_values_f pevp
809 ,pay_element_entry_values_f pevc
810 ,pay_element_entry_values_f pevs
811 ,pay_element_entry_values_f pevy
812 ,pay_element_entry_values_f pevdate
813 ,pay_element_entries_f pee
814 where pevm.input_value_id = p_type_m_iv_id
815 and pevp.input_value_id = p_type_p_iv_id
816 and pevs.input_value_id = p_type_s_iv_id
817 and pevc.input_value_id = p_type_c_iv_id
818 and pevy.input_value_id = p_type_y_iv_id
819 and pevdate.input_value_id = p_type_accrual_date_iv_id
820 and pee.element_entry_id = pevm.element_entry_id
821 and pee.element_entry_id = pevp.element_entry_id
822 and pee.element_entry_id = pevs.element_entry_id
823 and pee.element_entry_id = pevc.element_entry_id
824 and pee.element_entry_id = pevy.element_entry_id
825 and pee.element_entry_id = pevdate.element_entry_id
826 and pevdate.screen_entry_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
827 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end)
828 and pee.assignment_id = p_assignment_id ;
829 --
830 -- Cursor for calculating existing entitlements for additional holidays
831 cursor csr_get_ent_add(
832 p_type_m_iv_id number
833 ,p_type_accrual_date_iv_id number) is
834 select sum(pevm.screen_entry_value)
835 from pay_element_entry_values_f pevm
836 ,pay_element_entry_values_f pevdate
837 ,pay_element_entries_f pee
838 where pevm.input_value_id = p_type_m_iv_id
839 and pevdate.input_value_id = p_type_accrual_date_iv_id
840 and pee.element_entry_id = pevm.element_entry_id
841 and pee.element_entry_id = pevdate.element_entry_id
842 and pevdate.screen_entry_value = fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end)
843 and pee.assignment_id = p_assignment_id
844 and pee.effective_start_date between p_legal_period_end and
845 add_months(l_fr_plan_info.accrual_year_end,12);
846 --
847 l_proc VARCHAR2(72) := g_package||' get_fr_net_entitlement ';
851
848
849 BEGIN
850 hr_utility.set_location('Entering ' || l_proc,10);
852 --
853 -- Get plan info
854 --
855 l_fr_plan_info := get_fr_accrual_plan_info(
856 p_accrual_plan_id => l_accrual_plan_id
857 ,p_accrual_date => p_effective_date );
858
859 hr_utility.set_location('Step ' || l_proc,20);
860 --
861 -- Get the payment element type if it will be used ie type calculation = 'Y' or Accruals
862 --
863 IF p_type_calculation = 'Y' or p_type_calculation = 'A' THEN
864 l_fr_pay_info := get_payment_globals;
865 l_fr_pay_r_info := get_payment_globals_r;
866 hr_utility.set_location('Step ' || l_proc,30);
867 END IF;
868 -- /***/
869 --
870 hr_utility.set_location(' Accrual type is: '||p_accrual_type, 22);
871 hr_utility.set_location('Legal period end is: '||to_char(p_legal_period_end), 22);
872 hr_utility.set_location('Accrual year end is: '||to_char(l_fr_plan_info.accrual_year_end),22);
873 hr_utility.set_location('l_fr_plan_info.ent_m_iv_id is: '||to_char(l_fr_plan_info.ent_m_iv_id), 22);
874 hr_utility.set_location('l_fr_plan_info.ent_accrual_date_iv_id is: '||to_char(l_fr_plan_info.ent_accrual_date_iv_id), 22);
875 -- Get the ENTitlement Entries for this assignment / accrual date
876 -- Added condition for addtional holidays
877 IF p_accrual_type = 'ADD' THEN
878 --
879 Open csr_get_ent_add(l_fr_plan_info.ent_m_iv_id, l_fr_plan_info.ent_accrual_date_iv_id);
880 Fetch csr_get_ent_add into l_ent_m;
881 Close csr_get_ent_add;
882 --
883 ELSE
884 --
885 open csr_get_ent_obs(l_fr_plan_info.ent_m_iv_id, l_fr_plan_info.ent_p_iv_id
886 ,l_fr_plan_info.ent_s_iv_id, l_fr_plan_info.ent_c_iv_id
887 ,l_fr_plan_info.ent_y_iv_id, l_fr_plan_info.ent_accrual_date_iv_id);
888 fetch csr_get_ent_obs into l_ent_m, l_ent_p, l_ent_c, l_ent_s, l_ent_y;
889 close csr_get_ent_obs;
890 --
891 END IF;
892 hr_utility.set_location('Step ' || l_proc,40);
893
894 hr_utility.trace('l_ent_m is ' || l_ent_m);
895 hr_utility.trace('l_ent_p is ' || l_ent_p);
896 hr_utility.trace('l_ent_c is ' || l_ent_c);
897 hr_utility.trace('l_ent_s is ' || l_ent_s);
898 hr_utility.trace('l_ent_y is ' || l_ent_y);
899
900 --
901 -- The parameter p_ignore_ent_adjustments relates to the 'ENT' output variables.
902 -- If it is 'Y', the adjustments should not be added into the ENT parameters, otherwist they sdhould bw.
903 -- The absence form will show ent with adjustments,
904 -- The create entitlement process will need pure entitlement regardless of adjustments.
905 -- If the parameter p_ignore_ent_adjustments is 'Y', this is the only type of entitlement to consider.
906 -- otherwise, continue with other types and also deduct holidays and if termination, paid days.
907 --
908 --
909 -- Get the OBSoletion entries
910 --
911 open csr_get_ent_obs(l_fr_plan_info.obs_m_iv_id, l_fr_plan_info.obs_p_iv_id
912 ,l_fr_plan_info.obs_s_iv_id, l_fr_plan_info.obs_c_iv_id
913 ,l_fr_plan_info.obs_y_iv_id, l_fr_plan_info.obs_accrual_date_iv_id);
914 fetch csr_get_ent_obs into l_obs_m, l_obs_p, l_obs_c, l_obs_s, l_obs_y;
915 close csr_get_ent_obs;
916 hr_utility.trace('l_obs_m is ' || l_obs_m);
917 hr_utility.trace('l_obs_p is ' || l_obs_p);
918 hr_utility.trace('l_obs_c is ' || l_obs_c);
919 hr_utility.trace('l_obs_s is ' || l_obs_s);
920 hr_utility.trace('l_obs_y is ' || l_obs_y);
921
922 hr_utility.set_location('Step ' || l_proc,50);
923 --
924 -- Get the ASJustment entries
925 --
926 open csr_get_ent_obs(l_fr_plan_info.adj_m_iv_id, l_fr_plan_info.adj_p_iv_id
927 ,l_fr_plan_info.adj_s_iv_id, l_fr_plan_info.adj_c_iv_id
928 ,l_fr_plan_info.adj_y_iv_id, l_fr_plan_info.adj_accrual_date_iv_id);
929 fetch csr_get_ent_obs into l_adj_m, l_adj_p, l_adj_c, l_adj_s, l_adj_y;
930 close csr_get_ent_obs;
931 hr_utility.trace('l_adj_m is ' || l_adj_m);
932 hr_utility.trace('l_adj_p is ' || l_adj_p);
933 hr_utility.trace('l_adj_c is ' || l_adj_c);
934 hr_utility.trace('l_adj_s is ' || l_adj_s);
935 hr_utility.trace('l_adj_y is ' || l_adj_y);
936 hr_utility.set_location('Step ' || l_proc,60);
937 --
938 -- Uncommented and modified for termination
939 -- If this assignment is terminated, (ie there is a termination date),
940 -- Deduct any paid holidays
941 open csr_check_for_termination;
942 fetch csr_check_for_termination into l_unused_date;
943 if csr_check_for_termination%FOUND then
944 close csr_check_for_termination;
945 hr_utility.trace('IN TERMINATION');
946 --
947 --hr_utility.trace(' l_fr_plan_info.term_days_iv_ID ' || l_fr_plan_info.term_days_iv_ID);
948 --hr_utility.trace(' l_fr_plan_info.term_accrual_date_iv_ID ' || l_fr_plan_info.term_accrual_date_iv_ID);
949 --hr_utility.trace(' p_assignment_id ' || p_assignment_id);
950 --hr_utility.trace(' l_fr_plan_info.term_element_id ' || l_fr_plan_info.term_element_id);
951 --hr_utility.trace(' p_paid_days_to ' || p_paid_days_to);
952 --hr_utility.trace(' l_fr_plan_info.accrual_year_start ' || l_fr_plan_info.accrual_year_start);
953 --hr_utility.trace(' l_fr_plan_info.accrual_year_end ' || l_fr_plan_info.accrual_year_end);
954 --hr_utility.trace(' p_paid_days_to ' || p_paid_days_to);
955
956 open csr_get_paid_days ;
957 fetch csr_get_paid_days into l_term_payment;
958 close csr_get_paid_days;
959 --
960 else
961 l_term_payment :=0;
962 close csr_check_for_termination;
963 end if;
964 --
965 IF p_type_calculation = 'N' THEN
969 -- otherwise it will be taken off of accrual
966 hr_utility.trace('P type = N');
967 --
968 -- only deduct holidays if there is entitlement stored against this accrual plan
970 --
971 l_ret := get_fr_latest_ent_date
972 (p_assignment_id => p_assignment_id
973 ,p_accrual_plan_id => p_accrual_plan_id
974 ,p_effective_date => p_effective_date
975 ,p_latest_date => l_latest_entitlement_date
976 ,p_entitlement_start_date => l_unused_date
977 ,p_accrual_start_date => l_unused_date
978 ,p_accrual_end_date => l_unused_date);
979 hr_utility.set_location('Step ' || l_proc,70);
980 --
981 IF l_latest_entitlement_date > to_date('1990-01-01','yyyy-mm-dd') THEN
982 --
983 -- Deduct any holidays booked against this assignment / accrual plan / accrual date
984 --
985 hr_utility.set_location('Step ' || l_proc,80);
986 l_ret := Get_fr_holidays_booked_list (
987 P_assignment_id => p_assignment_id
988 ,p_business_Group_id => l_fr_plan_info.business_Group_id
989 ,P_accrual_plan_id => p_accrual_plan_id
990 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
991 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
992 ,p_holiday_element_id => l_fr_plan_info.holiday_element_id
993 ,p_total_m => l_booked_m
994 ,p_total_p => l_booked_p
995 ,p_total_c => l_booked_c
996 ,p_total_s => l_booked_s
997 ,p_total_y => l_booked_y );
998 hr_utility.set_location('Step ' || l_proc,90);
999 END IF;
1000 ELSE
1001 IF p_type_calculation = 'Y' then /* payslip */
1002 hr_utility.trace('P type = Y');
1003 -- This calculation is for the payslip - deduct holidays paid for asg / plan / year
1004 --
1005 open csr_previous_action_sequence;
1006 fetch csr_previous_action_sequence into l_action_sequence;
1007 close csr_previous_action_sequence;
1008 open csr_previous_paid_absences;
1009 fetch csr_previous_paid_absences into l_previous_paid_absences;
1010 l_previous_paid_absences := nvl(l_previous_paid_absences, 0);
1011 hr_utility.trace('l_previous_paid_absences is ' || l_previous_paid_absences);
1012 close csr_previous_paid_absences;
1013 hr_utility.set_location('Step ' || l_proc,100);
1014 open csr_previous_paid_absences_r;
1015 fetch csr_previous_paid_absences_r into l_previous_paid_absences_retro;
1016 l_previous_paid_absences_retro := nvl(l_previous_paid_absences_retro, 0);
1017 l_previous_paid_absences := nvl(l_previous_paid_absences, 0) + l_previous_paid_absences_retro;
1018 hr_utility.trace('l_previous_paid_absences is ' || l_previous_paid_absences);
1019 close csr_previous_paid_absences_r;
1020 hr_utility.set_location('Step ' || l_proc,110);
1021 --
1022 -- This calculation is for the payslip - find holidays taken this period
1023 --
1024 open csr_current_action_sequence;
1025 fetch csr_current_action_sequence into l_action_sequence;
1026 close csr_current_action_sequence;
1027 hr_utility.trace('csr_current_paid_absences is ' || l_Action_sequence);
1028 hr_utility.trace('p_paid_days_to is ' || to_char(p_paid_days_to));
1029 open csr_current_paid_absences;
1030 fetch csr_current_paid_absences into l_current_paid_absences;
1031 l_current_paid_absences := nvl(l_current_paid_absences, 0);
1032 hr_utility.trace('l_current_paid_absences is ' || l_current_paid_absences);
1033 close csr_current_paid_absences;
1034 hr_utility.set_location('Step ' || l_proc,120);
1035
1036 open csr_current_paid_absences_r;
1037 fetch csr_current_paid_absences_r into l_current_paid_absences_retro;
1038 l_current_paid_absences := nvl(l_current_paid_absences, 0) + nvl(l_current_paid_absences_retro, 0);
1039 hr_utility.trace('l_current_paid_absences is ' || l_current_paid_absences);
1040 close csr_current_paid_absences_r;
1041 hr_utility.set_location('Step ' || l_proc,130);
1042
1043 -- Added code for termination
1044 l_current_paid_absences := l_current_paid_absences + nvl(l_term_payment,0);
1045 --
1046 ELSE
1047 hr_utility.trace('P type = ACCRUALS');
1048 --
1049 -- This calculation is for accruals - deduct all hols taken prior to date earned.
1050 --
1051 open csr_previous_and_current_seq;
1052 fetch csr_previous_and_current_seq into l_action_sequence;
1053 close csr_previous_and_current_seq;
1054 hr_utility.trace('csr_prev_and_current_paid_abs is ' || l_action_sequence);
1055 open csr_prev_and_current_paid_abs;
1056 fetch csr_prev_and_current_paid_abs into l_previous_paid_absences;
1057 close csr_prev_and_current_paid_abs;
1058 hr_utility.set_location('Step ' || l_proc,135);
1059
1060 open csr_prev_and_cur_paid_abs_r;
1061 fetch csr_prev_and_cur_paid_abs_r into l_previous_paid_absences_retro;
1062 close csr_prev_and_cur_paid_abs_r;
1063 l_previous_paid_absences := nvl(l_previous_paid_absences,0) + nvl(l_previous_paid_absences_retro,0);
1064 hr_utility.set_location('Step ' || l_proc,145);
1065
1066 -- Added code for termination
1067 l_previous_paid_absences := l_previous_paid_absences + nvl(l_term_payment,0);
1068 --
1069 END IF;
1070 END IF;
1071 --
1075
1072 -- Modified for termination
1073 --
1074 hr_utility.set_location('Step ' || l_proc,150);
1076 hr_utility.trace('l_ent_m is ' || l_ent_m);
1077 hr_utility.trace('l_ent_p is ' || l_ent_p);
1078 hr_utility.trace('l_ent_c is ' || l_ent_c);
1079 hr_utility.trace('l_ent_s is ' || l_ent_s);
1080 hr_utility.trace('l_ent_y is ' || l_ent_y);
1081
1082
1083 l_net_main := nvl(l_ent_m,0) + nvl(l_adj_m,0) + nvl(l_obs_m,0) - nvl(l_booked_m,0)- nvl(l_term_payment,0);
1084 hr_utility.trace('l_term_payment is ' || l_term_payment);
1085 hr_utility.trace('l_booked_m is ' || l_booked_m);
1086 hr_utility.trace('18 l_NET_main is ' || l_net_main);
1087 -- replaced out paramter with declared variable
1088 l_net_protected := nvl(l_ent_p,0) + nvl(l_adj_p,0) + nvl(l_obs_p,0) - nvl(l_booked_p,0);
1089 -- Bug 2861012
1090 l_net_conventional := nvl(l_ent_c,0) + nvl(l_adj_c,0) + nvl(l_obs_c,0) - nvl(l_booked_c,0);
1091 l_net_seniority := nvl(l_ent_s,0) + nvl(l_adj_s,0) + nvl(l_obs_s,0) - nvl(l_booked_s,0);
1092 l_net_young_mothers := nvl(l_ent_y,0) + nvl(l_adj_y,0) + nvl(l_obs_y,0) - nvl(l_booked_y,0);
1093 --
1094 -- End of modified code
1095 p_remaining := l_net_main
1096 + l_net_protected /* replaced out paramter */
1097 /* + p_net_seniority
1098 + p_net_young_mothers
1099 + p_net_conventional; */
1100 -- Bug 2861012
1101 + l_net_seniority
1102 + l_net_young_mothers
1103 + l_net_conventional;
1104
1105 if p_ignore_ent_adjustments = 'N' THEN
1106 hr_utility.trace('P_IGNORE ENT ADJ IS N');
1107 l_ent_main := nvl(l_ent_m,0) + nvl(l_adj_m,0);
1108 l_ent_protected := nvl(l_ent_p,0) + nvl(l_adj_p,0);
1109 l_ent_conventional := nvl(l_ent_c,0) + nvl(l_adj_c,0);
1110 l_ent_seniority := nvl(l_ent_s,0) + nvl(l_adj_s,0);
1111 l_ent_young_mothers := nvl(l_ent_y,0) + nvl(l_adj_y,0);
1112 hr_utility.set_location('Step ' || l_proc,120);
1113 hr_utility.trace('20 l_ent_main ' || l_ent_main);
1114 ELSE
1115 hr_utility.trace('P_IGNORE ENT ADJ IS Y');
1116 l_ent_main := nvl(l_ent_m,0);
1117 l_ent_protected := nvl(l_ent_p,0);
1118 l_ent_conventional := nvl(l_ent_c,0);
1119 l_ent_seniority := nvl(l_ent_s,0);
1120 l_ent_young_mothers := nvl(l_ent_y,0);
1121 hr_utility.set_location('Step ' || l_proc,130);
1122 hr_utility.trace('21 l_ent_main ' || l_ent_main);
1123 END IF;
1124 IF p_type_calculation = 'Y' or p_type_calculation = 'A' THEN /* paYslip or Accruals */
1125 hr_utility.trace('IN Y OR A - resetting l_ent_main');
1126 hr_utility.trace('22 l_NET_main is ' || l_net_main);
1127 --
1128 -- Use only the net main and ent main OUT variables as totals. Still include termination paid days.
1129 -- Replaced out paramter p_net_protected
1130
1131 -- carry out similar change for p_net_conventional,p_net_seniority and p_net_young_mothers
1132 -- Bug 2861012
1133 l_ent_main := l_net_main + l_net_protected + l_net_conventional + l_net_seniority + l_net_young_mothers - nvl(l_previous_paid_absences,0);
1134 hr_utility.set_location('l_ent_main: '||to_char(l_ent_main), 22);
1135 l_net_main := nvl(l_current_paid_absences,0);
1136 l_net_protected := 0;
1137
1138 -- Bug 2861012
1139 l_net_conventional := 0;
1140 l_net_seniority := 0;
1141 l_net_young_mothers := 0;
1142 l_ent_protected := 0;
1143 l_ent_young_mothers := 0;
1144 l_ent_seniority := 0;
1145 l_ent_conventional := 0;
1146 p_remaining := nvl(l_term_payment,0);
1147 hr_utility.set_location('Step ' || l_proc,160);
1148 END IF;
1149
1150 p_accrual_start_date := l_fr_plan_info.accrual_year_start;
1151 p_accrual_end_date := l_fr_plan_info.accrual_year_end;
1152
1153 -- Assigning value of local variable to out parameter
1154 p_net_main := l_net_main;
1155 p_net_protected := l_net_protected;
1156 p_net_conventional := l_net_conventional;
1157 p_net_seniority := l_net_seniority;
1158 p_net_young_mothers := l_net_young_mothers;
1159 p_ent_main := l_ent_main;
1160 p_ent_protected := l_ent_protected;
1161 p_ent_conventional := l_ent_conventional;
1162 p_ent_seniority := l_ent_seniority;
1163 p_ent_young_mothers := l_ent_young_mothers;
1164
1165 hr_utility.set_location('p_ent_main is :'||to_char(p_ent_main), 22);
1166 hr_utility.set_location('Leaving: '||l_proc,170);
1167 end get_fr_net_entitlement;
1168 --------------------------------------------------------------------------------
1169 -- Read_Regularization_Payment
1170 --------------------------------------------------------------------------------
1171 Function read_regularization_payment
1172 (p_accrual_plan_id IN number,
1173 p_index IN number,
1174 p_reg_payment OUT NOCOPY number,
1175 p_accrual_date OUT NOCOPY date,
1176 p_next_payment OUT NOCOPY number)
1177 return number is
1178
1179 l_index number;
1180
1181 begin
1182
1183 l_index := p_index;
1184
1185 if p_index is null OR p_index = 0 Then
1186 l_index := p_accrual_plan_id * 10 + 1;
1187 end if;
1188
1189 p_reg_payment := reg_payment(l_index).payment;
1190 p_accrual_date := reg_payment(l_index).accrual_date;
1191 p_next_payment := nvl(reg_payment(l_index).next_payment, 0);
1192
1193 return 0;
1194 EXCEPTION
1195 WHEN OTHERS THEN
1196 Raise;
1197
1201 -------------------------------------------------------------------------------
1198 end read_regularization_payment;
1199 ---------------------------------------------------------------------------------
1200 -- Write_Regularization_Payment
1202 Function write_regularization_payment
1203 (p_accrual_plan_id number,
1204 p_y0_reg_payment number,
1205 p_y0_accrual_date date,
1206 p_y1_reg_payment number,
1207 p_y1_accrual_date date,
1208 p_y2_reg_payment number,
1209 p_y2_accrual_date date,
1210 p_y3_reg_payment number,
1211 p_y3_accrual_date date
1212 ) return number is
1213
1214 i number;
1215 last_i number;
1216
1217 begin
1218 i := p_accrual_plan_id * 10;
1219 if p_y0_reg_payment <> 0 and p_y0_reg_payment is not null then
1220 i := i+1;
1221 reg_payment(i).payment := p_y0_reg_payment;
1222 reg_payment(i).accrual_date := p_y0_accrual_date;
1223 reg_payment(i).next_payment := 0;
1224 last_i := i;
1225 end if;
1226
1227 if p_y1_reg_payment <> 0 and p_y1_reg_payment is not null then
1228 i := i+1;
1229 reg_payment(i).payment := p_y1_reg_payment;
1230 reg_payment(i).accrual_date := p_y1_accrual_date;
1231 reg_payment(i).next_payment := 0;
1232
1233 if last_i is not null then
1234 reg_payment(last_i).next_payment := i;
1235 end if;
1236
1237 last_i := i;
1238 end if;
1239
1240 if p_y2_reg_payment <> 0 and p_y2_reg_payment is not null then
1241 i := i+1;
1242 reg_payment(i).payment := p_y2_reg_payment;
1243 reg_payment(i).accrual_date := p_y2_accrual_date;
1244 reg_payment(i).next_payment := 0;
1245
1246 if last_i is not null then
1247 reg_payment(last_i).next_payment := i;
1248 end if;
1249
1250 last_i := i;
1251 end if;
1252
1253 if p_y3_reg_payment <> 0 and p_y3_reg_payment is not null then
1254 i := i+1;
1255 reg_payment(i).payment := p_y3_reg_payment;
1256 reg_payment(i).accrual_date := p_y3_accrual_date;
1257 reg_payment(i).next_payment := 0;
1258
1259 if last_i is not null then
1260 reg_payment(last_i).next_payment := i;
1261 end if;
1262
1263 last_i := i;
1264 end if;
1265
1266 return 0;
1267
1268 EXCEPTION
1269 WHEN OTHERS THEN
1270 Raise;
1271
1272 end write_regularization_payment;
1273 --
1274 -------------------------------------------------------------------------------
1275 -- Get_fr_reg_payments
1276 -------------------------------------------------------------------------------
1277
1278 function Get_fr_reg_payments
1279 (p_assignment_id IN Number
1280 ,p_date_earned IN Date
1281 ,p_accrual_plan_id IN Number
1282 ,p_calculation_date IN Date
1283 ,p_y0_term_payments IN Number
1284 ,p_y1_term_payments IN Number
1285 ,p_global_reg_sal_pct IN Number
1286 ,p_daily_rate IN Number
1287 ,p_y0_regularized_amt OUT NOCOPY Number
1288 ,p_y1_regularized_amt OUT NOCOPY Number
1289 ,p_y2_regularized_amt OUT NOCOPY Number
1290 ,p_y3_regularized_amt OUT NOCOPY Number
1291 ,p_y0_accrual_date OUT NOCOPY Date
1292 ,p_y1_accrual_date OUT NOCOPY Date
1293 ,p_y2_accrual_date OUT NOCOPY Date
1294 ,p_y3_accrual_date OUT NOCOPY Date
1295 ,p_reg_option_flg OUT NOCOPY Varchar2
1296 ) return number is
1297 --
1298 l_proc varchar2(72) := g_package||'Get_fr_reg_payments';
1299 l_regularize_possible Varchar2(3);
1300 l_session_date Date;
1301 l_accrued_start_date Date;
1302 l_accrued_end_date Date;
1303 l_reference_days_accrued Number;
1304 l_total_days_to_regularize Number;
1305 l_original_payment Number;
1306 l_tot_days_to_regularize_retro Number;
1307 l_original_payment_retro Number;
1308 l_previous_reg_payment Number;
1309 l_term_reg_payments Number;
1310 l_new_payment Number;
1311 l_reference_salary Number;
1312 l_return Number;
1313 l_yr_count Number;
1314 l_action_sequence Number;
1315 l_next_accrued_end_date Date;
1316 l_fr_pay_info g_fr_pay_info;
1317 l_fr_pay_r_info g_fr_pay_info;
1318 l_reg_option_flg Varchar2(3);
1319
1320 TYPE l_yr_payments_rec IS RECORD(
1321 l_accrual_date Date,
1322 l_regularized_payment Number,
1323 l_term_payments Number);
1324 TYPE l_yr_payments_tab is TABLE of l_yr_payments_rec INDEX by BINARY_INTEGER;
1325 l_yr_payments l_yr_payments_tab;
1326 --
1327 -- Cursor for finding number of days to be regularized
1328 -- and holiday payments made
1329 -- in case of unregularized payments
1330 Cursor csr_paid_absence IS
1331 select sum(prrv_days.result_value), sum(prrv_pay.result_value)
1332 from pay_run_result_values prrv_days
1333 ,pay_run_result_values prrv_pay
1334 ,pay_run_result_values prrv_accrual
1335 ,pay_run_result_values prrv_flag
1336 ,pay_run_result_values prrv_plan
1337 ,pay_run_results prr
1338 ,pay_assignment_actions paa
1339 where prrv_days.run_result_id = prr.run_result_id
1340 and prrv_pay.run_result_id = prr.run_result_id
1341 and prrv_plan.run_result_id = prr.run_result_id
1342 and prrv_flag.run_result_id = prr.run_result_id
1343 and prrv_accrual.run_result_id = prr.run_result_id
1347 and prrv_plan.input_value_id = l_fr_pay_info.pay_plan_input_ID
1344 and prrv_days.input_value_id = l_fr_pay_info.pay_total_days_input_ID
1345 and prrv_pay.input_value_id = l_fr_pay_info.pay_payment_input_ID
1346 and prrv_accrual.input_value_id = l_fr_pay_info.pay_accrual_date_input_ID
1348 and prrv_flag.input_value_id = l_fr_pay_info.pay_flag_input_ID
1349 and prr.assignment_action_id = paa.assignment_action_id
1350 and paa.assignment_id = p_assignment_id
1351 and prr.element_type_id = l_fr_pay_info.pay_element_id
1352 and prr.status in ('P','PA')
1353 and prrv_accrual.result_value
1354 between fnd_date.date_to_canonical(l_accrued_start_date)
1355 and fnd_date.date_to_canonical(l_accrued_end_date);
1356 --
1357 -- Cursor for finding number of days to be regularized
1358 -- and holiday payments made
1359 -- in case of unregularized payments retro
1360 Cursor csr_paid_absence_r IS
1361 select sum(prrv_days.result_value), sum(prrv_pay.result_value)
1362 from pay_run_result_values prrv_days
1363 ,pay_run_result_values prrv_pay
1364 ,pay_run_result_values prrv_accrual
1365 ,pay_run_result_values prrv_flag
1366 ,pay_run_result_values prrv_plan
1367 ,pay_run_results prr
1368 ,pay_assignment_actions paa
1369 where prrv_days.run_result_id = prr.run_result_id
1370 and prrv_pay.run_result_id = prr.run_result_id
1371 and prrv_plan.run_result_id = prr.run_result_id
1372 and prrv_flag.run_result_id = prr.run_result_id
1373 and prrv_accrual.run_result_id = prr.run_result_id
1374 and prrv_days.input_value_id = l_fr_pay_r_info.pay_total_days_input_ID
1375 and prrv_pay.input_value_id = l_fr_pay_r_info.pay_payment_input_ID
1376 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_accrual_date_input_ID
1377 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_plan_input_ID
1378 and prrv_flag.input_value_id = l_fr_pay_r_info.pay_flag_input_ID
1379 and prr.assignment_action_id = paa.assignment_action_id
1380 and paa.assignment_id = p_assignment_id
1381 and prr.element_type_id = l_fr_pay_r_info.pay_element_id
1382 and prr.status in ('P','PA')
1383 and prrv_accrual.result_value
1384 between fnd_date.date_to_canonical(l_accrued_start_date)
1385 and fnd_date.date_to_canonical(l_accrued_end_date);
1386 --
1387 -- Cursor to fetch all previous regularized payments
1388 Cursor csr_prev_reg_pymt IS
1389 select sum(prrv_pay.result_value)
1390 from pay_run_result_values prrv_pay
1391 ,pay_run_result_values prrv_accrual
1392 ,pay_run_result_values prrv_plan
1393 ,pay_run_results prr
1394 ,pay_assignment_actions paa
1395 where prrv_pay.run_result_id = prr.run_result_id
1396 and prrv_plan.run_result_id = prr.run_result_id
1397 and prrv_accrual.run_result_id = prr.run_result_id
1398 and prrv_pay.input_value_id = l_fr_pay_info.pay_reg_payment_input_ID
1399 and prrv_accrual.input_value_id = l_fr_pay_info.pay_reg_date_input_ID
1400 and prrv_plan.input_value_id = l_fr_pay_info.pay_reg_plan_input_ID
1401 and prr.assignment_action_id = paa.assignment_action_id
1402 and paa.assignment_id = p_assignment_id
1403 and prr.element_type_id = l_fr_pay_info.pay_reg_element_id
1404 and prr.status in ('P','PA')
1405 and prrv_accrual.result_value
1406 between fnd_date.date_to_canonical(l_accrued_start_date)
1407 and fnd_date.date_to_canonical(l_accrued_end_date);
1408
1409 -- Cursor to fetch all previous regularized payments retro
1410 Cursor csr_prev_reg_pymt_r IS
1411 select sum(prrv_pay.result_value)
1412 from pay_run_result_values prrv_pay
1413 ,pay_run_result_values prrv_accrual
1414 ,pay_run_result_values prrv_plan
1415 ,pay_run_results prr
1416 ,pay_assignment_actions paa
1417 where prrv_pay.run_result_id = prr.run_result_id
1418 and prrv_plan.run_result_id = prr.run_result_id
1419 and prrv_accrual.run_result_id = prr.run_result_id
1420 and prrv_pay.input_value_id = l_fr_pay_r_info.pay_reg_payment_input_ID
1421 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_reg_date_input_ID
1422 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_reg_plan_input_ID
1423 and prr.assignment_action_id = paa.assignment_action_id
1424 and paa.assignment_id = p_assignment_id
1425 and prr.element_type_id = l_fr_pay_r_info.pay_reg_element_id
1426 and prr.status in ('P','PA')
1427 and prrv_accrual.result_value
1428 between fnd_date.date_to_canonical(l_accrued_start_date)
1429 and fnd_date.date_to_canonical(l_accrued_end_date);
1430 --
1431 --
1432 -- Cursor to fetch regularised payments on termination
1433 Cursor csr_fetch_term_reg_pymts IS
1434 select sum(nvl(prrv_pay.result_value,0)) payments
1435 from pay_run_result_values prrv_pay
1436 ,pay_run_result_values prrv_accrual
1437 ,pay_run_result_values prrv_plan
1438 ,pay_element_types_f petf
1439 ,pay_input_values_f pivf_pay
1440 ,pay_input_values_f pivf_accrual
1441 ,pay_input_values_f pivf_plan
1442 ,pay_run_results prr
1443 ,pay_assignment_actions paa
1444 where prrv_pay.run_result_id = prr.run_result_id
1445 and prrv_plan.run_result_id = prr.run_result_id
1446 and prrv_accrual.run_result_id = prr.run_result_id
1447 and prrv_pay.input_value_id = pivf_pay.input_value_id
1448 and prrv_accrual.input_value_id = pivf_accrual.input_value_id
1449 and prrv_plan.input_value_id = pivf_plan.input_value_id
1453 and pivf_pay.element_type_id = petf.element_type_id
1450 --
1451 and petf.element_name = 'FR_TERMINATION_REGULARIZE'
1452 and petf.legislation_code = 'FR'
1454 and prr.status in ('P','PA')
1455 and pivf_pay.name = 'Pay Value'
1456 and pivf_accrual.element_type_id= petf.element_type_id
1457 and pivf_plan.element_type_id = petf.element_type_id
1458 and pivf_accrual.name = 'Accrual Date'
1459 and pivf_plan.name = 'Accrual Plan ID'
1460 --
1461 and prr.assignment_action_id = paa.assignment_action_id
1462 and prrv_plan.result_value = p_accrual_plan_id
1463 and paa.action_sequence <= nvl(l_action_sequence, paa.action_sequence)
1464 and paa.assignment_id = p_assignment_id
1465 and prr.element_type_id = petf.element_type_id
1466 and prrv_accrual.result_value
1467 between fnd_date.date_to_canonical(l_accrued_start_date)
1468 and fnd_date.date_to_canonical(l_accrued_end_date);
1469
1470 -- Cursor to check whether user has opted for regularization
1471 Cursor csr_reg_option_flg IS
1472 Select nvl(INFORMATION30, 'N') reg_flg
1473 from pay_accrual_plans
1474 where ACCRUAL_PLAN_ID = p_accrual_plan_id
1475 and INFORMATION_CATEGORY in ('FR_FR_MAIN_HOLIDAY', 'FR_FR_RTT_HOLIDAY', 'FR_FR_ADDITIONAL_HOLIDAY');
1476 --
1477 Begin
1478 --
1479 -- Check whether regularization is to be done
1480 OPEN csr_reg_option_flg;
1481 FETCH csr_reg_option_flg INTO l_reg_option_flg;
1482 CLOSE csr_reg_option_flg;
1483 --
1484 IF l_reg_option_flg ='N' THEN
1485 -- initialise OUT parameters
1486 p_y0_regularized_amt := 0;
1487 p_y1_regularized_amt := 0;
1488 p_y2_regularized_amt := 0;
1489 p_y3_regularized_amt := 0;
1490 p_y0_accrual_date := to_date('01-01-0001', 'dd-mm-yyyy');
1491 p_y1_accrual_date := to_date('01-01-0001', 'dd-mm-yyyy');
1492 p_y2_accrual_date := to_date('01-01-0001', 'dd-mm-yyyy');
1493 p_y3_accrual_date := to_date('01-01-0001', 'dd-mm-yyyy');
1494 p_reg_option_flg := l_reg_option_flg;
1495 --
1496 ELSE
1497 -- Estimate regularization amount
1498 l_fr_pay_info := get_payment_globals;
1499 l_fr_pay_r_info := get_payment_globals_r;
1500 --
1504 --
1501 l_next_accrued_end_date := p_calculation_date;
1502 l_yr_payments(1).l_term_payments := nvl(p_y0_term_payments,0);
1503 l_yr_payments(2).l_term_payments := nvl(p_y1_term_payments,0);
1505 FOR l_yr_count in 1..4 LOOP
1506 -- Intiialize the accrual date
1507 l_yr_payments(l_yr_count).l_accrual_date:= l_next_accrued_end_date;
1508 --
1509 l_return := pay_fr_pto_pkg.Get_fr_holiday_reg_details
1510 (p_assignment_id => p_assignment_id
1511 ,p_date_earned => p_date_earned
1512 ,P_accrual_plan_id => p_accrual_plan_id
1513 ,P_accrual_date => l_yr_payments(l_yr_count).l_accrual_date
1514 ,P_accrue_start_Date => l_accrued_start_date
1515 ,P_accrue_end_date => l_accrued_end_date
1516 ,P_reference_entitlement => l_reference_days_accrued
1517 ,p_reference_salary => l_reference_salary
1518 ,p_session_date => l_session_date
1519 ,p_regularization_possible => l_regularize_possible
1520 ,p_total_days_paid => l_total_days_to_regularize
1521 ,p_total_payment_made => l_original_payment
1522 ,p_previous_reg_payments => l_previous_reg_payment);
1523 --
1524 -- if regularization is possible, calculate the regularized payment
1525 IF l_regularize_possible = 'Y' THEN
1526 -- Calculate the regularized Amount
1527 IF l_yr_count = 1 OR l_yr_count = 2 THEN
1528 l_reference_salary := l_reference_salary + l_yr_payments(l_yr_count).l_term_payments;
1529 END IF;
1530 l_new_payment := ((p_global_reg_sal_pct/100) * l_reference_salary * l_total_days_to_regularize)/l_reference_days_accrued;
1531 l_yr_payments(l_yr_count).l_regularized_payment:= GREATEST(0, (l_new_payment - l_original_payment - l_previous_reg_payment));
1532 ELSE
1533 -- Calculate the number of days to be regularized
1534 -- and the holiday payments made
1535 OPEN csr_paid_absence;
1536 FETCH csr_paid_absence INTO l_total_days_to_regularize, l_original_payment;
1537 CLOSE csr_paid_absence;
1538 l_total_days_to_regularize := nvl(l_total_days_to_regularize, 0);
1539 l_original_payment := nvl(l_original_payment, 0);
1540
1544 CLOSE csr_paid_absence_r;
1541 -- Calculate the number of days to be regularized retro
1542 OPEN csr_paid_absence_r;
1543 FETCH csr_paid_absence_r INTO l_tot_days_to_regularize_retro, l_original_payment_retro;
1545 l_total_days_to_regularize := l_total_days_to_regularize + nvl(l_tot_days_to_regularize_retro,0);
1546 l_original_payment := l_original_payment + nvl(l_original_payment_retro, 0);
1547
1548 -- Calculate previous regularized payment
1549 OPEN csr_prev_reg_pymt;
1550 FETCH csr_prev_reg_pymt INTO l_previous_reg_payment;
1551 CLOSE csr_prev_reg_pymt;
1552 l_previous_reg_payment := nvl(l_previous_reg_payment, 0);
1553 -- Calculate the holiday payments made
1554 -- fetch all regularization payments paid by termination element
1555 OPEN csr_fetch_term_reg_pymts;
1556 FETCH csr_fetch_term_reg_pymts INTO l_term_reg_payments;
1557 CLOSE csr_fetch_term_reg_pymts;
1558 l_term_reg_payments := nvl(l_term_reg_payments, 0);
1559 -- Add the termination payments to the previous regularization payments
1560 l_previous_reg_payment := l_previous_reg_payment + l_term_reg_payments;
1561 --
1562 -- Calculate the total regularization payment to be made
1563 -- (the p_daile_rate is equal to the earnings for each day, i.e.
1564 -- either the FR_SUBJECT_TO_EARNINGS_DEDUCTION_ASG_PTD balance
1565 -- or the notice period payment
1566 -- divided by the corresponding number of days)
1567 l_new_payment := p_daily_rate * l_total_days_to_regularize;
1568 --
1569 -- Calculate the net regularization payment
1570 l_yr_payments(l_yr_count).l_regularized_payment:= GREATEST(0, (l_new_payment - l_original_payment - l_previous_reg_payment));
1571 --
1572 END IF;
1573 -- Calculate and store the previous year accrual date
1574 l_next_accrued_end_date := add_months(l_accrued_end_date, -12);
1575 END LOOP;
1576 -- populate OUT variables
1577 p_y0_regularized_amt := l_yr_payments(1).l_regularized_payment;
1578 p_y1_regularized_amt := l_yr_payments(2).l_regularized_payment;
1579 p_y2_regularized_amt := l_yr_payments(3).l_regularized_payment;
1580 p_y3_regularized_amt := l_yr_payments(4).l_regularized_payment;
1581 p_y0_accrual_date := l_yr_payments(1).l_accrual_date;
1582 p_y1_accrual_date := l_yr_payments(2).l_accrual_date;
1583 p_y2_accrual_date := l_yr_payments(3).l_accrual_date;
1584 p_y3_accrual_date := l_yr_payments(4).l_accrual_date;
1585 p_reg_option_flg := l_reg_option_flg;
1586 --
1587 END IF;
1588 Return 1;
1589 END;
1590
1591 --
1592 ---------------------------------------------------------------------------------
1593 -- Get_FR_HOLIDAY_REG_DETAILS REG Fast Formula
1594 -------------------------------------------------------------------------------
1595 function Get_fr_holiday_reg_details
1596 (P_assignment_id IN Number
1597 ,p_date_earned IN Date
1598 ,P_accrual_plan_id IN Number
1599 ,P_accrual_date IN Date
1600 ,P_accrue_start_Date OUT NOCOPY Date /* period start date of accrual year */
1601 ,P_accrue_end_date OUT NOCOPY Date /* period start date of accrual year */
1602 ,P_reference_entitlement OUT NOCOPY Number /* The main days of entitlement in the accrual year */
1603 ,p_reference_salary OUT NOCOPY Number /* the salary (stored on entitlement element) */
1604 ,p_session_date OUT NOCOPY Date /* The sesssion date */
1605 ,p_regularization_possible OUT NOCOPY Varchar2 /* flag if this accrual period is not yet closed as as session date */
1606 ,p_total_days_paid OUT NOCOPY Number /* The number of days paid in this accrual year */
1607 ,p_total_payment_made OUT NOCOPY Number /* The original payment made for those days */
1608 ,p_previous_reg_payments OUT NOCOPY Number /* Any previous regularization payments made */
1609 ) return number is
1610 --
1611 l_proc varchar2(72) := g_package||'Get_FR_holiday_reg_details';
1612
1613 l_remaining Number := 0;
1614 l_unused Number := 0;
1618 l_session_date Date;
1615 l_accrue_start_Date Date;
1616 l_accrue_end_date Date;
1617 l_reference_entitlement Number := 0;
1619 l_regularization_possible Varchar2(10);
1620 l_reference_salary Number;
1621 l_total_days_paid Number := 0;
1622 l_total_payment_made Number := 0;
1623 l_total_days_paid_r Number := 0;
1624 l_total_payment_made_r Number := 0;
1625 l_previous_reg_payments Number := 0;
1626 l_term_reg_payments Number := 0;
1630 l_fr_pay_info g_fr_pay_info;
1627 l_action_sequence PAY_ASSIGNMENT_ACTIONS.ACTION_SEQUENCE%TYPE := null;
1628 --
1629 l_fr_plan_info g_fr_plan_info;
1631 l_fr_pay_r_info g_fr_pay_info;
1632 --
1633 cursor csr_session_date is
1634 select effective_date
1635 from fnd_sessions
1636 where session_id = USERENV('SESSIONID');
1637 --
1638 -- Get the termination regularization amount
1639 --
1640
1641 Cursor csr_fetch_term_reg_pymts IS
1642 select sum(nvl(prrv_pay.result_value,0)) payments
1643 from pay_run_result_values prrv_pay
1644 ,pay_run_result_values prrv_accrual
1645 ,pay_run_result_values prrv_plan
1646 ,pay_element_types_f petf
1647 ,pay_input_values_f pivf_pay
1648 ,pay_input_values_f pivf_accrual
1649 ,pay_input_values_f pivf_plan
1650 ,pay_run_results prr
1651 ,pay_assignment_actions paa
1652 where prrv_pay.run_result_id = prr.run_result_id
1653 and prrv_plan.run_result_id = prr.run_result_id
1654 and prrv_accrual.run_result_id = prr.run_result_id
1655 and prrv_pay.input_value_id = pivf_pay.input_value_id
1656 and prrv_accrual.input_value_id = pivf_accrual.input_value_id
1657 and prrv_plan.input_value_id = pivf_plan.input_value_id
1658 --
1659 and petf.element_name = 'FR_TERMINATION_REGULARIZE'
1660 and petf.legislation_code = 'FR'
1661 and pivf_pay.element_type_id = petf.element_type_id
1662 and pivf_pay.name = 'Pay Value'
1663 and pivf_accrual.element_type_id= petf.element_type_id
1664 and pivf_plan.element_type_id = petf.element_type_id
1665 and pivf_accrual.name = 'Accrual Date'
1666 and pivf_plan.name = 'Accrual Plan ID'
1667 --
1668 and prr.assignment_action_id = paa.assignment_action_id
1669 and prrv_plan.result_value = p_accrual_plan_id
1670 and paa.action_sequence <= nvl(l_action_sequence, paa.action_sequence)
1671 and paa.assignment_id = p_assignment_id
1672 and prr.element_type_id = petf.element_type_id
1673 and prr.status in ('P','PA')
1674 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
1675 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
1676
1677 --
1678 -- Get the payments made for all absences in this accrual year. (NOT regularization payments)
1679 --
1680
1681 CURSOR csr_fetch_all_reg_payments is
1682 select sum(prrv_pay.result_value)
1683 from pay_run_result_values prrv_pay
1684 ,pay_run_result_values prrv_accrual
1685 ,pay_run_result_values prrv_plan
1686 ,pay_run_results prr
1687 ,pay_assignment_actions paa
1688 where prrv_pay.run_result_id = prr.run_result_id
1689 and prrv_plan.run_result_id = prr.run_result_id
1690 and prrv_accrual.run_result_id = prr.run_result_id
1691 and prrv_pay.input_value_id = l_fr_pay_info.pay_reg_payment_input_ID
1692 and prrv_accrual.input_value_id = l_fr_pay_info.pay_reg_date_input_ID
1693 and prrv_plan.input_value_id = l_fr_pay_info.pay_reg_plan_input_ID
1694 and prr.assignment_action_id = paa.assignment_action_id
1695 and prrv_plan.result_value = p_accrual_plan_id
1696 and paa.action_sequence <= nvl(l_action_sequence, paa.action_sequence)
1697 and paa.assignment_id = p_assignment_id
1698 and prr.element_type_id = l_fr_pay_info.pay_reg_element_id
1699 and prr.status in ('P','PA')
1700 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
1701 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
1702
1703 --
1704 -- Get the payments made for all absences in this accrual year. (NOT regularization payments)
1705 --
1706
1707 CURSOR csr_fetch_all_paid_absences is
1708 select sum(prrv_days.result_value), sum(prrv_pay.result_value)
1709 from pay_run_result_values prrv_days
1710 ,pay_run_result_values prrv_pay
1711 ,pay_run_result_values prrv_accrual
1712 ,pay_run_result_values prrv_plan
1713 ,pay_run_results prr
1714 ,pay_assignment_actions paa
1715 where prrv_days.run_result_id = prr.run_result_id
1716 and prrv_pay.run_result_id = prr.run_result_id
1717 and prrv_plan.run_result_id = prr.run_result_id
1718 and prrv_accrual.run_result_id = prr.run_result_id
1719 and prrv_days.input_value_id = l_fr_pay_info.pay_total_days_input_ID
1720 and prrv_pay.input_value_id = l_fr_pay_info.pay_payment_input_ID
1721 and prrv_accrual.input_value_id = l_fr_pay_info.pay_accrual_date_input_ID
1722 and prrv_plan.input_value_id = l_fr_pay_info.pay_plan_input_ID
1723 and prr.assignment_action_id = paa.assignment_action_id
1724 and paa.assignment_id = p_assignment_id
1725 and prr.element_type_id = l_fr_pay_info.pay_element_id
1726 and prr.status in ('P','PA')
1727 and prrv_plan.result_value = p_accrual_plan_id
1728 and paa.action_sequence <= l_action_sequence
1729 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
1730 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
1734 ,pay_run_result_values prrv_pay
1731 CURSOR csr_fetch_all_paid_absences_r is
1732 select sum(prrv_days.result_value), sum(prrv_pay.result_value)
1733 from pay_run_result_values prrv_days
1735 ,pay_run_result_values prrv_accrual
1739 where prrv_days.run_result_id = prr.run_result_id
1736 ,pay_run_result_values prrv_plan
1737 ,pay_run_results prr
1738 ,pay_assignment_actions paa
1740 and prrv_pay.run_result_id = prr.run_result_id
1741 and prrv_plan.run_result_id = prr.run_result_id
1742 and prrv_accrual.run_result_id = prr.run_result_id
1743 and prrv_days.input_value_id = l_fr_pay_r_info.pay_total_days_input_ID
1744 and prrv_pay.input_value_id = l_fr_pay_r_info.pay_payment_input_ID
1745 and prrv_accrual.input_value_id = l_fr_pay_r_info.pay_accrual_date_input_ID
1746 and prrv_plan.input_value_id = l_fr_pay_r_info.pay_plan_input_ID
1747 and prr.assignment_action_id = paa.assignment_action_id
1748 and paa.assignment_id = p_assignment_id
1749 and prr.element_type_id = l_fr_pay_r_info.pay_element_id
1750 and prr.status in ('P','PA')
1751 and prrv_plan.result_value = p_accrual_plan_id
1752 and paa.action_sequence <= l_action_sequence
1753 and prrv_accrual.result_value between fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_start)
1754 and fnd_date.date_to_canonical(l_fr_plan_info.accrual_year_end);
1755 CURSOR csr_action_sequence_all_paid is
1756 select max(paa.action_sequence)
1757 from pay_assignment_actions paa
1758 ,pay_payroll_Actions ppa
1759 where ppa.payroll_action_id = paa.payroll_action_id
1760 and paa.assignment_id = p_assignment_id;
1761 begin
1762 hr_utility.set_location('Entering ' || l_proc,10);
1763 -- --fnd_file.put_line(fnd_file.log,'Entering ' || l_proc);
1764
1765 --
1766 -- Fetch the effective_date
1767 --
1768 open csr_session_date;
1769 fetch csr_session_date into l_session_date;
1770 close csr_session_date;
1771 --
1772 -- Ensure globals for this accrual_plan_id are set.
1773 --
1774 l_fr_plan_info := get_fr_accrual_plan_info(
1775 p_accrual_plan_id => p_accrual_plan_id
1776 ,p_accrual_date => p_accrual_date );
1777
1778 hr_utility.set_location('Step ' || l_proc,20);
1779 --
1780 -- Get the Payment globals
1781 --
1782 l_fr_pay_info := get_payment_globals;
1783 l_fr_pay_r_info := get_payment_globals_r;
1784 hr_utility.set_location('Step ' || l_proc,30);
1785 --
1786 -- Calculate if the accrual period has ended yet - this is needed as the regularized payment
1787 -- is only possible if the accrual period is closed and therefore the salary balance is known.
1788 --
1789 if p_date_earned >= l_fr_plan_info.accrual_year_end then
1790 l_regularization_possible := 'Y';
1791 hr_utility.set_location('Step ' || l_proc,40);
1792 else
1793 l_regularization_possible := 'N';
1794 end if;
1795 --
1796 -- If regularization is possible, get the total entitlement for main and protected stored
1797 -- for this assignment for this accrual period.
1798 --
1799 if l_regularization_possible = 'Y' then
1800
1801 /*
1802
1803 get_reference_entitlement(
1804 P_ACCRUAL_PLAN_ID => p_accrual_plan_id
1805 ,P_ACCRUAL_START_DATE => l_fr_plan_info.accrual_year_start
1806 ,P_ACCRUAL_END_DATE => l_fr_plan_info.accrual_year_end
1807 ,P_ASSIGNMENT_ID => p_assignment_id
1808 ,P_ENT_REF_DAYS_ID => l_fr_plan_info.ent_reference_days_iv_id
1809 ,P_ENT_REF_SALARY_ID => l_fr_plan_info.ent_reference_sal_iv_id
1810 ,P_ENT_ACCRUAL_DATE_IV_ID => l_fr_plan_info.ent_accrual_date_iv_id
1811 ,P_REF_MAIN_DAYS => l_reference_entitlement
1812 ,P_REF_SALARY => l_reference_salary);
1813 */
1814
1815 get_reference_entitlement(
1816 P_ACCRUAL_PLAN_ID => p_accrual_plan_id
1817 ,P_ACCRUAL_START_DATE => l_fr_plan_info.accrual_year_start
1818 ,P_ACCRUAL_END_DATE => l_fr_plan_info.accrual_year_end
1819 ,P_ASSIGNMENT_ID => p_assignment_id
1820 ,P_ENT_REF_DAYS_ID => ''
1821 ,P_ENT_REF_SALARY_ID => ''
1822 ,P_ENT_ACCRUAL_DATE_IV_ID => ''
1823 ,P_REF_MAIN_DAYS => l_reference_entitlement
1824 ,P_REF_SALARY => l_reference_salary);
1825
1826 hr_utility.set_location('In reg_details, l_reference_entitlement 1 ' , l_reference_entitlement);
1827
1828 --
1829 -- A regularization is only posible if the reference salary is non-zero and
1830 -- the reference days is non-zero.
1831 --
1835 END IF;
1832 IF ((nvl(l_reference_entitlement,0) = 0) OR (nvl(l_reference_salary,0) = 0)) THEN
1833 l_regularization_possible := 'N';
1834 hr_utility.set_location('Step ' || l_proc,60);
1836 end if;
1837 hr_utility.set_location('In reg_details, l_reference_entitlement 2 ' , l_reference_entitlement);
1838
1839 --
1840 -- if a regularization is possible, get the total days paid, and the original payments
1841 -- paid for these days.
1842 --
1843 IF l_regularization_possible = 'Y' THEN
1844 open csr_action_sequence_all_paid;
1845 fetch csr_action_sequence_all_paid into l_action_sequence;
1846 close csr_action_sequence_all_paid;
1847 hr_utility.trace('new action seq csr_fetch_all_paid_absences is ' || l_action_sequence);
1848 open csr_fetch_all_paid_absences;
1849 fetch csr_fetch_all_paid_absences into l_total_days_paid, l_total_payment_made;
1850 close csr_fetch_all_paid_absences;
1851 --
1852 -- adjust for any retro paid absences
1853 open csr_fetch_all_paid_absences_r;
1854 fetch csr_fetch_all_paid_absences_r into l_total_days_paid_r, l_total_payment_made_r;
1855 close csr_fetch_all_paid_absences_r;
1856 hr_utility.trace('regularization paid absence csr, l_total_days_paid:' || to_char(l_total_days_paid) ||
1857 ' l_total_payment_made:'|| to_char(l_total_payment_made) ||
1858 ' l_total_days_paid_r:' || to_char(l_total_days_paid_r) ||
1859 ' l_total_payment_made_r:'|| to_char(l_total_payment_made_r));
1860
1861 l_total_days_paid := l_total_days_paid + nvl(l_total_days_paid_r,0);
1862 l_total_payment_made := l_total_payment_made + nvl(l_total_payment_made_r,0);
1863
1864 hr_utility.set_location('Step ' || l_proc,70);
1865 hr_utility.set_location('In reg_details, l_reference_entitlement 3 ' , l_reference_entitlement);
1866 -- Also, get the total of regularization payments already made for asg/accrual plan/accrual date
1867 --
1868 l_action_sequence := null;
1869 hr_utility.trace('new action seq csr_fetch_all_reg_payments is ' || l_action_sequence);
1870 open csr_fetch_all_reg_payments;
1871 fetch csr_fetch_all_reg_payments into l_previous_reg_payments;
1872 close csr_fetch_all_reg_payments;
1873 hr_utility.set_location('In reg_details, l_reference_entitlement 4 ' , l_reference_entitlement);
1874 hr_utility.set_location('Step ' || l_proc,80);
1875 -- fetch all regularization payments paid by termination element
1876 OPEN csr_fetch_term_reg_pymts;
1877 FETCH csr_fetch_term_reg_pymts INTO l_term_reg_payments;
1878 CLOSE csr_fetch_term_reg_pymts;
1879 l_term_reg_payments := nvl(l_term_reg_payments, 0);
1880 l_previous_reg_payments := l_previous_reg_payments + l_term_reg_payments;
1881
1882 END IF;
1883 IF nvl(l_reference_entitlement,0) = 0 then
1884 l_regularization_possible := 'N';
1885 hr_utility.set_location('Step ' || l_proc,90);
1886 END IF;
1887
1888 hr_utility.set_location('In reg_details, l_reference_entitlement 5 ' , l_reference_entitlement);
1889 hr_utility.set_location('l_fr_pay_info.pay_reg_payment_input_ID' , l_fr_pay_info.pay_reg_payment_input_ID);
1890 hr_utility.set_location('l_fr_pay_info.pay_reg_date_input_ID' , l_fr_pay_info.pay_reg_date_input_ID);
1891 hr_utility.set_location('l_fr_pay_info.pay_reg_plan_input_ID' , l_fr_pay_info.pay_reg_plan_input_ID);
1892 hr_utility.set_location('p_assignment_id ' , p_assignment_id );
1893 hr_utility.set_location('l_fr_pay_info.pay_reg_element_id' , l_fr_pay_info.pay_reg_element_id);
1894 --
1895 -- Set Out Variables
1896 --
1897 p_accrue_start_Date := l_fr_plan_info.accrual_year_start;
1898 p_accrue_end_date := l_fr_plan_info.accrual_year_end;
1899 p_reference_entitlement := nvl(l_reference_entitlement,0);
1900 p_reference_salary := nvl(l_reference_salary,0);
1901 p_session_date := l_session_date;
1902 p_regularization_possible := l_regularization_possible;
1903 p_total_days_paid := nvl(l_total_days_paid,0);
1904 p_total_payment_made := nvl(l_total_payment_made,0);
1905 p_previous_reg_payments := nvl(l_previous_reg_payments,0);
1906 --
1907 hr_utility.set_location('In reg_details, l_reference_entitlement 6 ' , l_reference_entitlement);
1908 hr_utility.set_location('In reg_details, p_reference_entitlement 7 ' , p_reference_entitlement);
1909
1910
1911 hr_utility.set_location('Leaving: '||l_proc,100);
1912 return 1;
1913 end Get_fr_holiday_reg_details;
1914 --
1915 -------------------------------------------------------------------------------
1916 -- FUNCTION GET_PAYMENT_GLOBALS
1917 -------------------------------------------------------------------------------
1918 function get_payment_globals
1919 return g_fr_pay_info is
1920 --
1921 l_unused number;
1922 --
1923 CURSOR csr_input_values (p_input_name in varchar2, p_element_name in varchar2) is
1924 select piv.input_value_id, pet.element_type_id
1925 from pay_element_types_f pet
1926 ,pay_input_values_f piv
1927 where piv.element_Type_id = pet.element_type_id
1928 and pet.legislation_code = 'FR'
1929 -- and piv.legislation_code = 'FR'
1930 and pet.element_name = p_element_name
1931 and piv.name = p_input_name;
1932
1933
1934 l_fr_pay_info g_fr_pay_info;
1935 l_proc VARCHAR2(72) := g_package||' get_payment_globals ';
1936 --
1937 --
1938 BEGIN
1939 hr_utility.set_location('Entering ' || l_proc,10);
1940 --
1941 -- load the regularization values into the structure
1942 --
1943 open csr_input_values('Pay Value', 'FR_HOLIDAY_REGULARIZE');
1947 hr_utility.set_location('pay reg element id ' , l_fr_pay_info.pay_reg_element_id);
1944 fetch csr_input_values into l_fr_pay_info.pay_reg_payment_input_ID, l_fr_pay_info.pay_reg_element_id;
1945 close csr_input_values;
1946
1948 hr_utility.set_location('pay reg value iv id ' , l_fr_pay_info.pay_reg_payment_input_ID);
1949
1950 open csr_input_values('Accrual Plan ID', 'FR_HOLIDAY_REGULARIZE');
1951 fetch csr_input_values into l_fr_pay_info.pay_reg_plan_input_ID, l_unused;
1952 close csr_input_values;
1953 hr_utility.set_location('pay reg plan iv id ' , l_fr_pay_info.pay_reg_plan_input_ID);
1954
1955 open csr_input_values('Accrual Date', 'FR_HOLIDAY_REGULARIZE');
1956 fetch csr_input_values into l_fr_pay_info.pay_reg_date_input_ID, l_unused;
1957 close csr_input_values;
1958
1959 hr_utility.set_location('pay reg date iv id ' , l_fr_pay_info.pay_reg_date_input_ID);
1960 --
1961 -- load the payment input values into the structure
1962 --
1963 open csr_input_values('Rate', 'FR_HOLIDAY_PAY');
1964 fetch csr_input_values into l_fr_pay_info.pay_total_days_input_ID, l_fr_pay_info.pay_element_id;
1965 close csr_input_values;
1966
1967 hr_utility.set_location('pay element ID id ' , l_fr_pay_info.pay_element_id);
1968 hr_utility.set_location('pay total days - rate - iv id ' , l_fr_pay_info.pay_total_days_input_ID);
1969
1970 open csr_input_values('Protected Days Paid', 'FR_HOLIDAY_PAY');
1971 fetch csr_input_values into l_fr_pay_info.pay_protected_days_input_ID, l_unused;
1972 close csr_input_values;
1973
1974 hr_utility.set_location('pay protected days iv id ' , l_fr_pay_info.pay_protected_days_input_ID);
1975
1976 open csr_input_values('Accrual Date', 'FR_HOLIDAY_PAY');
1977 fetch csr_input_values into l_fr_pay_info.pay_accrual_date_input_ID, l_unused;
1978 close csr_input_values;
1979 hr_utility.set_location('pay date days iv id ' , l_fr_pay_info.pay_accrual_date_input_ID);
1980
1981 open csr_input_values('Pay Value', 'FR_HOLIDAY_PAY');
1982 fetch csr_input_values into l_fr_pay_info.pay_payment_input_ID, l_unused;
1983 close csr_input_values;
1984 hr_utility.set_location('pay pay value iv id ' , l_fr_pay_info.pay_payment_input_ID);
1985
1986 open csr_input_values('Regularized Flag', 'FR_HOLIDAY_PAY');
1987 fetch csr_input_values into l_fr_pay_info.pay_flag_input_ID, l_unused;
1988 close csr_input_values;
1989 hr_utility.set_location('pay regularized flag days iv id ' , l_fr_pay_info.pay_flag_input_ID);
1990
1991 open csr_input_values('Accrual Plan ID', 'FR_HOLIDAY_PAY');
1992 fetch csr_input_values into l_fr_pay_info.pay_plan_input_ID, l_unused;
1993 close csr_input_values;
1994 hr_utility.set_location('pay plan iv id ' , l_fr_pay_info.pay_plan_input_ID);
1995
1996 open csr_input_values('Absence Attendance ID', 'FR_HOLIDAY_PAY');
1997 fetch csr_input_values into l_fr_pay_info.pay_abs_attend_input_id, l_unused;
1998 close csr_input_values;
1999 hr_utility.set_location('pay abs_attend iv id ' , l_fr_pay_info.pay_abs_attend_input_id);
2000 --
2004 -------------------------------------------------------------------------------
2001 hr_utility.set_location('Leaving: '||l_proc,100);
2002 return l_fr_pay_info;
2003 end get_payment_globals;
2005 -- FUNCTION FR_LATEST_PLAN_START_DATE
2006 -------------------------------------------------------------------------------
2007 function fr_latest_plan_start_date (p_element_entry_id in number)
2008 return date is
2009
2010 l_proc VARCHAR2(200) := g_package||'fr_latest_plan_start_date ';
2011 l_effective_start_date date;
2012
2013 CURSOR csr_get_effective_start_date is
2014 SELECT min(pee.effective_start_date) start_date
2015 from pay_element_entries_f pee
2016 where pee.element_entry_id = p_element_entry_id;
2017
2018 BEGIN
2019
2020 hr_utility.set_location('Entering ' || l_proc, 10);
2021
2022 open csr_get_effective_start_date;
2023 fetch csr_get_effective_start_date into l_effective_start_date;
2024 close csr_get_effective_start_date;
2025
2029
2026 hr_utility.set_location('Assigned the value ' || l_proc, 20);
2027
2028 hr_utility.set_location('Leaving ' || l_proc, 30);
2030 return l_effective_start_date;
2031 end fr_latest_plan_start_date;
2032 --
2033 -------------------------------------------------------------------------------
2034 -- FUNCTION GET_PAYMENT_GLOBALS_R
2035 -------------------------------------------------------------------------------
2036 function get_payment_globals_r
2037 return g_fr_pay_info is
2038 --
2039 l_unused number;
2040 --
2041 CURSOR csr_input_values (p_input_name in varchar2, p_element_name in varchar2) is
2042 select piv.input_value_id, pet.element_type_id
2043 from pay_element_types_f pet
2044 ,pay_input_values_f piv
2045 where piv.element_Type_id = pet.element_type_id
2046 and pet.legislation_code = 'FR'
2047 -- and piv.legislation_code = 'FR'
2048 and pet.element_name = p_element_name
2049 and piv.name = p_input_name;
2050
2051
2052 l_fr_pay_r_info g_fr_pay_info;
2053 l_proc VARCHAR2(72) := g_package||' get_payment_globals_r ';
2054 --
2055 --
2056 BEGIN
2057 -- load the regularization values into the structure
2058 --
2059 open csr_input_values('Amount', 'FR_HOLIDAY_REGULARIZE_INFO_RETRO');
2060 fetch csr_input_values into l_fr_pay_r_info.pay_reg_payment_input_ID, l_fr_pay_r_info.pay_reg_element_id;
2061 close csr_input_values;
2062
2063 hr_utility.set_location('pay reg element id retro' , l_fr_pay_r_info.pay_reg_element_id);
2064 hr_utility.set_location('pay reg value iv id retro' , l_fr_pay_r_info.pay_reg_payment_input_ID);
2065
2066 open csr_input_values('Accrual Plan ID', 'FR_HOLIDAY_REGULARIZE_INFO_RETRO');
2067 fetch csr_input_values into l_fr_pay_r_info.pay_reg_plan_input_ID, l_unused;
2068 close csr_input_values;
2069 hr_utility.set_location('pay reg plan iv id retro' , l_fr_pay_r_info.pay_reg_plan_input_ID);
2070
2071 open csr_input_values('Accrual Date', 'FR_HOLIDAY_REGULARIZE_INFO_RETRO');
2072 fetch csr_input_values into l_fr_pay_r_info.pay_reg_date_input_ID, l_unused;
2073 close csr_input_values;
2074
2075 hr_utility.set_location('pay reg date iv id retro' , l_fr_pay_r_info.pay_reg_date_input_ID);
2076 --
2077 -- load the payment input values into the structure
2078 --
2079 open csr_input_values('Days', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2080 fetch csr_input_values into l_fr_pay_r_info.pay_total_days_input_ID, l_fr_pay_r_info.pay_element_id;
2081 close csr_input_values;
2082
2083 hr_utility.set_location('pay element ID id retro' , l_fr_pay_r_info.pay_element_id);
2084 hr_utility.set_location('pay total days - rate - iv id ' , l_fr_pay_r_info.pay_total_days_input_ID);
2085
2086 open csr_input_values('Protected Days Paid', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2087 fetch csr_input_values into l_fr_pay_r_info.pay_protected_days_input_ID, l_unused;
2088 close csr_input_values;
2089
2090 hr_utility.set_location('pay protected days iv id retro' , l_fr_pay_r_info.pay_protected_days_input_ID);
2091
2092 open csr_input_values('Accrual Date', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2093 fetch csr_input_values into l_fr_pay_r_info.pay_accrual_date_input_ID, l_unused;
2094 close csr_input_values;
2095 hr_utility.set_location('pay date days iv id retro' , l_fr_pay_r_info.pay_accrual_date_input_ID);
2096
2097 open csr_input_values('Amount', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2098 fetch csr_input_values into l_fr_pay_r_info.pay_payment_input_ID, l_unused;
2099 close csr_input_values;
2100 hr_utility.set_location('pay amount iv id retro' , l_fr_pay_r_info.pay_payment_input_ID);
2101
2102 open csr_input_values('Regularized Flag', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2103 fetch csr_input_values into l_fr_pay_r_info.pay_flag_input_ID, l_unused;
2104 close csr_input_values;
2105 hr_utility.set_location('pay regularized flag days iv id retro' , l_fr_pay_r_info.pay_flag_input_ID);
2106
2107 open csr_input_values('Accrual Plan ID', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2108 fetch csr_input_values into l_fr_pay_r_info.pay_plan_input_ID, l_unused;
2109 close csr_input_values;
2110 hr_utility.set_location('pay plan iv id retro' , l_fr_pay_r_info.pay_plan_input_ID);
2111
2112 open csr_input_values('Absence Attendance ID', 'FR_HOLIDAY_PAY_DAYS_RETRO');
2113 fetch csr_input_values into l_fr_pay_r_info.pay_abs_attend_input_id, l_unused;
2114 close csr_input_values;
2115 hr_utility.set_location('pay abs_attend iv id retro' , l_fr_pay_r_info.pay_abs_attend_input_id);
2116 --
2117 hr_utility.set_location('Leaving: '||l_proc,100);
2118 return l_fr_pay_r_info;
2119 end get_payment_globals_r;
2120 --
2121 -------------------------------------------------------------------------------
2122 -- FR_CREATE_ENTITLEMENT
2123 -------------------------------------------------------------------------------
2124 procedure fr_create_entitlement
2125 (ERRBUF OUT NOCOPY varchar2
2126 ,RETCODE OUT NOCOPY number
2127 ,P_business_group_id IN number
2128 ,p_assignment_id IN number DEFAULT Null
2129 ,P_calculation_date IN varchar2
2130 ,P_accrual_date IN varchar2
2131 ,P_plan_id IN number
2132 ,P_type IN varchar2
2133 ) is
2134 --
2135 -- p_type can be :
2136 -- 'ENT' to create entitlement in MAIN or RTT
2137 -- 'OBS' to obsolete entitlement in MAIN, RTT or ADDitional
2138 -- 'ADD' to create additional days in an FR_ADDITIONAL_DAYS plan.
2139 --
2140 l_dummy varchar2(10);
2141 l_calculation_date date := to_date(p_calculation_date, 'YYYY/MM/DD HH24:MI:SS');
2145 l_balance_type_id Number;
2142 l_accrual_date date := to_date(p_accrual_date, 'YYYY/MM/DD HH24:MI:SS');
2143 l_accrual_plan_element_id Number; /* asg - accrual plan member link */
2144 l_index Number := 1;
2146 l_latest_aa Number;
2147 l_asg_count Number := 0;
2148 -- addign variables for additional holidays
2149 l_assg_hiredate date;
2150 l_start_legal_period date;
2151 l_end_legal_period date;
2152 l_main_plan_info g_fr_plan_info;
2153 --
2154 l_fr_plan_info g_fr_plan_info;
2155 --
2156 -- Cursor to fetch plan type
2157 --
2158 CURSOR csr_get_assignment_action (l_assignment_id number) is
2159 select fnd_number.canonical_to_number(substr(max(lpad(paa.action_sequence,15,'0')||
2160 paa.assignment_action_id),16))
2161 from pay_assignment_actions paa,
2162 pay_payroll_actions ppa
2163 where paa.assignment_id = l_assignment_id
2164 and ppa.payroll_action_id = paa.payroll_action_id
2165 and ppa.effective_date between l_fr_plan_info.accrual_year_start and l_fr_plan_info.accrual_year_end
2166 and ppa.action_type in ('R', 'Q', 'I', 'V', 'B');
2167 --
2168 CURSOR csr_get_balance_type_id is
2169 select balance_type_id
2170 from pay_balance_types
2171 where balance_name = 'FR_SUBJECT_TO_EARNINGS_DEDUCTION'
2172 and legislation_code = 'FR';
2173 --
2174 CURSOR csr_plan_type is
2175 select accrual_formula_id, co_formula_id
2176 from PAY_ACCRUAL_PLANS
2177 where ACCRUAL_PLAN_ID = p_plan_id
2178 and ACCRUAL_CATEGORY in ('FR_MAIN_HOLIDAY', 'FR_RTT_HOLIDAY', 'FR_ADDITIONAL_HOLIDAY');
2179 --
2180 -- Modified for bug 3730069
2181 -- Substituted get_fr_plan_info.accrual_year_start
2182 -- in sub-query.
2183 CURSOR csr_get_balance_value is
2184 Select nvl(sum(fnd_number.canonical_to_number(TARGET.result_value) * FEED.scale),0)
2185 from
2186 pay_run_result_values TARGET
2187 ,pay_balance_feeds_f FEED
2188 ,pay_run_results RR
2189 ,pay_assignment_actions ASSACT
2190 ,pay_assignment_actions BAL_ASSACT
2191 ,pay_payroll_actions PACT
2192 ,pay_payroll_actions BACT
2193 ,per_time_periods PTP
2194 where BAL_ASSACT.assignment_action_id = l_latest_aa /*B1 */
2195 and BAL_ASSACT.payroll_action_id = BACT.payroll_action_id
2196 and FEED.balance_type_id = l_balance_type_id /*U1*/
2197 + decode(TARGET.input_value_id, null, 0, 0)
2198 and FEED.input_value_id = TARGET.input_value_id
2199 and nvl(TARGET.result_value, '0') <> '0'
2200 and TARGET.run_result_id = RR.run_result_id
2201 and RR.assignment_action_id = ASSACT.assignment_action_id
2202 and ASSACT.payroll_action_id = PACT.payroll_action_id
2203 and PACT.effective_date between
2204 FEED.effective_start_date and FEED.effective_end_date
2205 and RR.status in ('P','PA')
2206 and ASSACT.action_sequence <= BAL_ASSACT.action_sequence
2207 and ASSACT.assignment_id = BAL_ASSACT.assignment_id
2208 and PTP.time_period_id = BACT.time_period_id
2209 /* Year To Date */
2210 and PACT.effective_date > (
2211 select nvl(min(PTP1.end_date),l_fr_plan_info.accrual_year_start)
2212 from PAY_ACCRUAL_PLANS PAP1
2213 ,per_time_periods PTP1
2214 where PAP1.ACCRUAL_PLAN_ID = l_fr_plan_info.accrual_plan_id
2215 and pap1.information1 is not null
2216 AND PTP1.payroll_id = BACT.payroll_id
2217 and l_fr_plan_info.accrual_year_start -1
2218 between PTP1.start_date and PTP1.end_date);
2219 --
2220 -- get all the assignments in the plan to process
2221 --
2222 -- Changed for Performance bug 2662236
2223 CURSOR csr_get_assignment(c_assignment_id number) is
2224 select pee.assignment_id assignment_id
2225 from pay_element_entries_f pee
2226 where pee.element_type_id = l_fr_plan_info.accrual_plan_element_id
2227 and pee.assignment_id = nvl(c_assignment_id,pee.assignment_id)
2231 -- Cursor to fetch payroll details for a given asg
2228 and l_calculation_date between pee.effective_start_date
2229 and pee.effective_end_date;
2230 --
2232 --
2233 CURSOR c_payroll_period(p_payroll_id number, p_effective_date date) is
2234 select ptp.start_date
2235 ,ptp.end_date
2236 from per_time_periods ptp
2237 where ptp.payroll_id = p_payroll_id
2238 and p_effective_date between ptp.start_date and ptp.end_date;
2239 --
2240 -- Cursor to return payroll_id
2241 --
2242 -- Changed and renamed cursor c_payroll_id for bug 2662236
2243 CURSOR csr_asg_details (p_assignment_id number, p_effective_date date) is
2244 select payroll_id, assignment_number
2245 from per_all_assignments_f
2246 where assignment_id = p_assignment_id
2247 and (p_effective_date between effective_start_date and effective_end_date);
2248 --
2249 -- Cursor to get the last effective end date of the assignment
2250 -- so that terminated employees can be evaluated.
2251 --
2252 CURSOR c_get_asg_end_date (p_assignment_id number) is
2253 select max(effective_end_date)
2254 from per_all_assignments_f
2255 where assignment_id = p_assignment_id;
2256 --
2257 -- Defining cursor selecting hiredate
2258 Cursor csr_assg_hiredate(c_assignment_id number,
2259 c_accrual_date date) is
2260 Select ppos.date_start
2261 From per_all_assignments_f pasg,
2262 per_periods_of_service ppos
2263 Where ppos.period_of_service_id = pasg.period_of_service_id
2264 and pasg.assignment_id = c_assignment_id
2265 and c_accrual_date between pasg.effective_start_date
2266 and pasg.effective_end_date;
2267 --
2268 -- Local Variables
2269 l_accrual_plan_id Number := p_plan_id;
2270 l_accrual_start_date Date; /* plan year start date */
2271 l_accrual_end_date Date; /* plan year end date */
2272 l_assignment_number per_all_assignments_f.assignment_number%TYPE;
2273
2274 l_unused_date Date;
2275 l_payroll_id number;
2276 l_max_asg_end_date date;
2277 l_new_ee_id number;
2278
2279 l_unused_number Number;
2280 l_unused_char Varchar2(30);
2281
2282 L_TYPE_M_IV_ID Number;
2283 L_TYPE_P_IV_ID Number;
2284 L_TYPE_Y_IV_ID Number;
2285 L_TYPE_S_IV_ID Number;
2286 L_TYPE_C_IV_ID Number;
2287 L_TYPE_ACP_IV_ID Number;
2288 L_TYPE_ACCRUAL_DATE_IV_ID Number;
2289
2290
2291 l_ent_link_id Number := Null;
2292 l_adj_link_id Number := Null;
2293 l_type_link_id Number := Null;
2294 --
2295 l_previous_main Number := Null;
2296 l_previous_protected Number := Null;
2297 l_previous_mothers Number := Null;
2298 l_previous_seniority Number := Null;
2299 l_previous_conventional Number := Null;
2300 l_previous_ref_days Number := 0;
2301 l_previous_ref_salary Number := 0;
2302
2303 --
2304 l_total_accrued_pto Number := Null;
2305 l_total_Accrued_protected Number := Null;
2306 l_total_Accrued_seniority Number := Null;
2307 l_total_Accrued_mothers Number := Null;
2308 l_total_Accrued_conventional Number := Null;
2309 --
2310 l_new_main Number := Null;
2311 l_new_protected Number := Null;
2312 l_new_mothers Number := Null;
2313 l_new_seniority Number := Null;
2314 l_new_conventional Number := Null;
2315 l_new_ref_days Number := Null;
2316 l_new_ref_salary Number := Null;
2317 --
2318 l_net_entitlement Number := Null;
2319 l_net_main Number := Null;
2320 l_net_protected Number := Null;
2321 l_net_young_mother Number := Null;
2322 l_net_seniority Number := Null;
2323 l_net_conventional Number := Null;
2324 l_net_ref_days Number := Null;
2325 l_net_ref_salary Number := Null;
2326
2327 l_formula_id Number := Null;
2328 l_co_formula_id Number := Null;
2329
2330 i Number := 1;
2331 --
2332 l_pay_period_start_date date;
2333 l_pay_period_end_date date;
2334
2335 l_message_count Number := Null;
2336 l_message varchar2(256);
2337
2338 -- Declare tables for input value ids and Screen Entry Values
2339
2340 inp_value_id_tbl hr_entry.number_table;
2341 scr_valuetbl hr_entry.varchar2_table;
2342
2343 l_proc VARCHAR2(72) := g_package||' FR_Create_Entitlement ';
2344 --
2345 BEGIN
2346 hr_utility.set_location('Entering ' || l_proc,10);
2347
2348 ERRBUF := Null;
2349 RETCODE:= 0;
2350 per_accrual_message_pkg.clear_table;
2351
2352 open csr_plan_type;
2353 --
2354 -- check the plan type is correct
2355 --
2356
2357 hr_utility.set_location('Step ' || l_proc,20);
2358 fetch csr_plan_type into l_formula_id, l_co_formula_id;
2359 close csr_plan_type;
2360
2361 hr_utility.set_location('formual_id is ', l_formula_id);
2362 --
2363 --
2364 --
2365 l_fr_plan_info := get_fr_accrual_plan_info(
2366 p_accrual_plan_id => l_accrual_plan_id
2367 ,p_accrual_date => l_accrual_date );
2368 --
2369 -- Retrieve the correct accrual dates for additional holidays
2370 IF p_type ='ADD' THEN
2371 -- Calculate accrual dates accordingly
2372 l_main_plan_info := get_fr_accrual_plan_info(
2373 p_accrual_plan_id => l_fr_plan_info.main_holiday_acc_plan_id
2374 ,p_accrual_date => l_accrual_date );
2378 --
2375 l_fr_plan_info.accrual_year_start := l_main_plan_info.accrual_year_start;
2376 l_fr_plan_info.accrual_year_end := l_main_plan_info.accrual_year_end;
2377 END IF;
2379 hr_utility.set_location('Step ' || l_proc,30);
2380 --
2381 -- Set variables for saving to either the ENTitlement element
2382 -- Except link, which varies by assignment
2383 --
2384 if (P_type = 'ENT' or p_type = 'ADD') then
2385 l_type_accrual_date_iv_id := l_fr_plan_info.ent_accrual_date_iv_id;
2386 l_type_m_iv_id := l_fr_plan_info.ent_m_iv_id;
2387 l_type_p_iv_id := l_fr_plan_info.ent_p_iv_id;
2388 l_type_y_iv_id := l_fr_plan_info.ent_y_iv_id;
2389 l_type_s_iv_id := l_fr_plan_info.ent_s_iv_id;
2390 l_type_c_iv_id := l_fr_plan_info.ent_c_iv_id;
2391 l_type_acp_iv_id := l_fr_plan_info.ent_acp_iv_id;
2392 hr_utility.set_location('Step ' || l_proc,40);
2393 --
2394 -- or the OBSoletion element
2395 --
2396 ELSE
2397 l_type_accrual_date_iv_id := l_fr_plan_info.obs_accrual_date_iv_id;
2398 l_type_m_iv_id := l_fr_plan_info.obs_m_iv_id;
2399 l_type_p_iv_id := l_fr_plan_info.obs_p_iv_id;
2400 l_type_y_iv_id := l_fr_plan_info.obs_y_iv_id;
2401 l_type_s_iv_id := l_fr_plan_info.obs_s_iv_id;
2402 l_type_c_iv_id := l_fr_plan_info.obs_c_iv_id;
2403 l_type_acp_iv_id := l_fr_plan_info.obs_acp_iv_id;
2404 END IF;
2405 -- For additional holidays
2406 -- calculate the legal period start and end dates
2407 IF p_type = 'ADD' THEN
2408 IF to_date(to_char(l_calculation_date, 'DD-MM'),'DD-MM') > to_date('31-10', 'DD-MM') THEN
2409 l_start_legal_period := to_date('01-05-'||to_char(l_calculation_date, 'YYYY'), 'DD-MM-YYYY');
2410 ELSE
2411 l_start_legal_period := to_date('01-05-'||to_char(add_months(l_calculation_date, -12), 'YYYY'), 'DD-MM-YYYY');
2412 END IF;
2413 l_end_legal_period := last_day(add_months(l_start_legal_period, 6)-1);
2414 END IF;
2415 --
2416 -- putting in a check for the element entry date
2417 -- if the accrual type is 'ADD'
2418 IF p_type <> 'ADD' OR
2419 (p_type = 'ADD' AND
2420 l_calculation_date <= add_months(l_fr_plan_info.accrual_year_end,12)) THEN
2421 /* */
2422 /* MAIN loop for all assignments */
2423 /* */
2424
2425 for l_asg in csr_get_assignment(p_assignment_id) LOOP
2426 l_asg_count := l_asg_count+1;
2427 l_index := 0;
2428 --
2429 -- putting in check for each assignment
2430 OPEN csr_assg_hiredate(l_asg.assignment_id, l_accrual_date);
2431 FETCH csr_assg_hiredate INTO l_assg_hiredate;
2432 CLOSE csr_assg_hiredate;
2433
2434 IF p_type <> 'ADD' OR
2435 (p_type = 'ADD' AND l_assg_hiredate < l_start_legal_period)THEN
2436
2437 -- Get the persons payroll_id as at calc date.
2438 --
2439 hr_utility.set_location('In loop index ' , l_index);
2440
2441 open csr_asg_details(l_asg.assignment_id,
2442 l_calculation_date);
2443 fetch csr_asg_details into l_payroll_id, l_assignment_number;
2444 close csr_asg_details;
2445 --
2446 -- For this assignment, get the total accrual from the
2447 -- beginning of the accrual year (adjusted for eligibility
2448 -- and starting / leaving plan etc by formula)
2449 if (P_type = 'ENT' or p_type = 'ADD') then
2450 FR_Get_Accrual
2451 (P_Assignment_ID => l_asg.assignment_id
2452 ,P_Calculation_Date => l_calculation_date /* calc accruals up to this date */
2453 ,p_accrual_start_date => l_accrual_date /* formula will adjust this */
2454 ,P_Plan_ID => p_plan_id
2455 ,P_Business_Group_ID => l_fr_plan_info.business_Group_id
2456 ,P_Payroll_ID => l_payroll_id
2457 ,P_Assignment_Action_ID => null
2458 ,P_Accrual_Latest_Balance => null
2459 ,p_create_all => 'Y' /* generate each accrual value */
2460 ,p_reprocess_whole_period => 'Y' /* calculate from beginning */
2461 --
2462 ,p_legal_period_start_date =>l_start_legal_period
2463 ,p_entitlement_offset =>l_fr_plan_info.entitlement_offset
2464 ,p_main_holiday_acc_plan_id =>l_fr_plan_info.main_holiday_acc_plan_id
2465 ,p_type =>p_type
2466 --
2467 ,P_Start_Date => l_unused_Date
2468 ,P_End_Date => l_unused_Date
2469 ,P_Accrual_End_Date => l_unused_Date
2470 ,P_total_accrued_pto => l_total_accrued_pto
2471 ,P_total_Accrued_protected => l_total_Accrued_protected
2472 ,P_total_Accrued_seniority => l_total_Accrued_seniority
2473 ,P_total_Accrued_mothers => l_total_Accrued_mothers
2474 ,P_total_Accrued_conventional => l_total_Accrued_conventional) ;
2475 end if;
2476 --
2477 --
2478 -- Previous runs may have converted accruals already, this
2479 -- must be netted off before storage
2480 -- Also, there may already be an entry in this period, in which
2481 -- case multiple entries allowed = Y must be on - User DOC - on
2482 -- all entitlement entries. The process must store the net adjustment
2483 -- but can only INCREASE the entitlements
2484 --
2485 hr_utility.set_location('Step ' || l_proc,50);
2486 IF (p_type ='ENT') then
2487 l_dummy := 'Y';
2491 --
2488 ELSE
2489 l_dummy := 'N';
2490 END IF;
2492 get_fr_net_entitlement
2493 (p_accrual_plan_id => p_plan_id
2494 ,p_effective_date => l_accrual_date /* a date in the accrual period */
2495 ,p_assignment_id => l_asg.assignment_id
2496 ,p_ignore_ent_adjustments => l_dummy /* need pure entitlement already stored - ignore user additions / subtractions */
2497 -- pass parameter to get correct accrual dates for additional holidays
2498 -- to check for existing entitlements
2499 , p_accrual_type => p_type
2500 , p_legal_period_end => l_end_legal_period
2501 --
2502 ,p_remaining => l_net_entitlement
2503 ,p_net_main => l_net_main
2504 ,p_net_protected => l_net_protected
2505 ,p_net_young_mothers => l_net_young_mother
2506 ,p_net_seniority => l_net_seniority
2507 ,p_net_conventional => l_net_conventional
2508 ,p_ent_main => l_previous_main /* these value hold already stored entitlement */
2509 ,p_ent_protected => l_previous_protected
2510 ,p_ent_young_mothers => l_previous_mothers
2511 ,p_ent_seniority => l_previous_seniority
2512 ,p_ent_conventional => l_previous_conventional
2513 ,p_accrual_start_date => l_unused_date
2514 ,p_accrual_end_date => l_unused_date);
2515
2516 hr_utility.set_location('Step ' || l_proc,60);
2517 --
2518 -- Calculate the net new amount to store
2519 --
2520 if (P_type='ENT' or p_type='ADD') then
2521 l_new_main := nvl(l_total_accrued_pto, 0) - nvl(l_previous_main, 0);
2522 l_new_protected := nvl(l_total_Accrued_protected, 0) - nvl(l_previous_protected, 0);
2523 l_new_mothers := nvl(l_total_Accrued_mothers, 0) - nvl(l_previous_mothers, 0);
2524 l_new_seniority := nvl(l_total_Accrued_seniority, 0) - nvl(l_previous_seniority, 0);
2525 l_new_conventional := nvl(l_total_Accrued_conventional, 0) - nvl(l_previous_conventional, 0);
2526
2527 hr_utility.set_location('Step ' || l_proc,70);
2528 hr_utility.set_location('new m ' || l_new_main,70);
2529 hr_utility.set_location('new p ' || l_new_protected,70);
2530 hr_utility.set_location('new m ' || l_new_mothers,70);
2531 hr_utility.set_location('new s ' || l_new_seniority,70);
2532 hr_utility.set_location('new c ' || l_new_conventional,70);
2533
2534 elsif(P_type='OBS') then
2535 hr_utility.set_location('Step ' || l_proc,80);
2536 obsoletion_procedure
2537 (p_business_group_id => l_fr_plan_info.business_group_id
2538 ,p_assignment_id => l_asg.assignment_id
2539 ,p_accrual_plan_id => p_plan_id
2540 ,p_effective_date => l_calculation_date
2541 ,p_accrual_date => l_accrual_date
2542 ,p_formula_id => l_co_formula_id
2543 ,p_payroll_id => l_payroll_id
2544 ,p_net_entitlement => l_net_entitlement
2545 ,p_net_main_days => l_net_main
2546 ,p_net_conven_days => l_net_conventional
2547 ,p_net_seniority_days => l_net_seniority
2548 ,p_net_protected_days => l_net_protected
2549 ,p_net_youngmother_days => l_net_young_mother
2550 ,p_new_main_days => l_new_main
2551 ,p_new_conven_days => l_new_conventional
2552 ,p_new_seniority_days => l_new_seniority
2553 ,p_new_protected_days => l_new_protected
2554 ,p_new_youngmother_days => l_new_mothers) ;
2555 end if;
2556 --
2557 -- Get the links each of the entitlement elements.
2558 -- These cannot be stored in globals, as they could change by assignment
2559 -- Also, only MAIN may exist - others are not mandatory.
2560
2561 IF (P_type = 'ENT' or p_type = 'ADD') then
2562 l_type_link_id := hr_entry_api.get_link(
2563 P_assignment_id => l_asg.assignment_id,
2564 P_element_type_id => l_fr_plan_info.ent_element_id,
2565 P_session_date => l_calculation_date);
2566 ELSE
2567 l_type_link_id := hr_entry_api.get_link(
2568 P_assignment_id => l_asg.assignment_id,
2569 P_element_type_id => l_fr_plan_info.obs_element_id,
2570 P_session_date => l_calculation_date);
2571 END IF;
2572
2573 --
2574 -- Get the reference days, and the reference salary value
2575 -- if the reference period has ended. The reference period ending is calculated as the accrual year end date
2576 -- is less than the canculation date.
2577 --
2578 hr_utility.set_location('Step ' || l_proc,90);
2579
2580 IF (P_type = 'ENT') and l_fr_plan_info.accrual_year_end <= l_calculation_date THEN
2581 hr_utility.set_location('Step ' || l_proc,100);
2582 --
2583 l_previous_ref_salary := 0;
2584 l_previous_ref_days := 0;
2585 --
2586 get_reference_entitlement(
2587 p_accrual_plan_id => p_plan_id
2591 ,p_ent_ref_days_id => l_fr_plan_info.ent_reference_days_iv_id
2588 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
2589 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
2590 ,p_assignment_id => l_asg.assignment_id
2592 ,p_ent_ref_salary_id => l_fr_plan_info.ent_reference_sal_iv_id
2593 ,p_ent_accrual_date_iv_id => l_type_accrual_date_iv_id
2594 ,p_ref_main_days => l_previous_ref_days
2595 ,p_ref_salary => l_previous_ref_salary);
2596 --
2597 l_new_ref_days := nvl(l_total_accrued_pto,0) + nvl(l_total_accrued_protected,0);
2598 --
2599 -- calculate the value of the balance for reference salary
2600 -- Pleace holder for now - need to check if period has ended.
2601 --
2602 open csr_get_assignment_action(l_asg.assignment_id);
2603 fetch csr_get_assignment_action into l_latest_aa;
2604 close csr_get_assignment_action;
2605 hr_utility.set_location('Step ' || l_proc,110);
2606
2607 hr_utility.set_location('l_latest_aa is ' || l_latest_aa, 110);
2608 --
2609 --
2610 open csr_get_balance_type_id;
2611 fetch csr_get_balance_type_id into l_balance_type_id;
2612 close csr_get_balance_type_id;
2613 hr_utility.set_location('Step ' || l_proc,120);
2614 --
2615 l_new_ref_salary := 0;
2616
2617 open csr_get_balance_value;
2618 fetch csr_get_balance_value into l_new_ref_salary;
2619 close csr_get_balance_value;
2620 hr_utility.set_location('Step ' || l_proc,130);
2621
2622 hr_utility.set_location('l_new_ref_salary is ' || l_new_ref_salary, 110);
2623 --
2624 --
2625 -- Calculate new values to store - only post increments
2626 --
2627 l_net_ref_salary := greatest(0, nvl(l_new_ref_salary,0) - nvl(l_previous_ref_salary, 0));
2628 l_net_ref_days := greatest(0, nvl(l_new_ref_days,0) - nvl(l_previous_ref_days, 0));
2629
2630 hr_utility.set_location('l_net_ref_salary is ' || l_net_ref_salary, 110);
2631 hr_utility.set_location('l_net_ref_days is ' || l_net_ref_days, 110);
2632
2633 ELSE
2634 hr_utility.set_location('Step ' || l_proc,140);
2635 null;
2636 END IF;
2637
2638 --
2639 -- new ENT storage is necessary only if any of these are posiitve
2640 -- new OBS storage if any are non-zero
2641 --
2642
2643 IF ((p_type = 'ENT' or p_type = 'ADD') and l_new_main > 0 or l_new_protected > 0 or l_new_mothers > 0 or l_new_seniority > 0 or l_new_conventional > 0 or l_net_ref_salary > 0 or l_net_ref_days > 0 )
2644 OR ((p_type = 'OBS') and l_new_main <> 0 or l_new_protected <> 0 or l_new_mothers <> 0 or l_new_seniority <> 0 or l_new_conventional <> 0) THEN
2645
2646 hr_utility.set_location('creating entries ' || l_proc,150);
2647 --
2648 -- We must get the payroll period start and end dates for
2649 -- the period in which the element entry will be made,
2650 -- as these are the effective start and end dates for all
2651 -- non-recurring element entries.
2652 --
2653 open c_payroll_period(l_payroll_id, l_calculation_date);
2654 fetch c_payroll_period into l_pay_period_start_date, l_pay_period_end_date;
2655 close c_payroll_period;
2656 hr_utility.set_location('Step ' || l_proc,150);
2657 --
2658 -- Check that the assignment does not end before the payroll
2659 -- period end date.
2660 --
2661 open c_get_asg_end_date(l_asg.assignment_id);
2662 fetch c_get_asg_end_date into l_max_asg_end_date;
2663 close c_get_asg_end_date;
2664 hr_utility.set_location('Step ' || l_proc,160);
2665
2666 If l_max_asg_end_date < l_pay_period_end_date then
2667 --
2668 -- warn user in log : assignment ends before payroll period end date
2669 --
2670 fnd_message.set_name('PAY','PAY_75024_PTO_ACC_PERIOD');
2671 fnd_message.set_token('ASG_NO', l_assignment_number);
2672 fnd_file.put_line(FND_FILE.LOG,fnd_message.get);
2673 ELSE
2674 --
2675 -- proceed with the element entries.
2676 --
2677 --
2678 -- One of the entitlements are non-zero, so populate the record
2679 --
2680 -- The date will always be present
2681 --
2682 l_index := l_index + 1;
2683 inp_value_id_tbl(l_index) := l_type_accrual_date_iv_id;
2684 l_accrual_date := l_fr_plan_info.accrual_year_end;
2685 scr_valuetbl(l_index) := fnd_date.date_to_displaydate(l_accrual_date);
2686 --
2687 -- The Accrual Plan ID will always be present
2691 scr_valuetbl(l_index) := fnd_number.number_to_canonical(p_plan_id);
2688 --
2689 l_index := l_index + 1;
2690 inp_value_id_tbl(l_index) := l_type_acp_iv_id;
2692 --
2693 -- The Main will always exist
2694 --
2695 l_index := l_index + 1;
2696 inp_value_id_tbl(l_index) := l_type_m_iv_id;
2697 scr_valuetbl(l_index) := l_new_main;
2698 --
2699 -- Protected may not exist
2700 --
2701 IF l_type_p_iv_id is not null THEN
2702 l_index := l_index + 1;
2703 inp_value_id_tbl(l_index) := l_type_p_iv_id;
2704 scr_valuetbl(l_index) := l_new_protected;
2705 END IF;
2706 --
2707 -- Conventional may not exist
2708 --
2709 IF l_type_c_iv_id is not null THEN
2710 l_index := l_index + 1;
2711 inp_value_id_tbl(l_index) := l_type_c_iv_id;
2712 scr_valuetbl(l_index) := l_new_conventional;
2713 END IF;
2714 --
2715 -- Seniority may not exist
2716 --
2717 IF l_type_s_iv_id is not null THEN
2718 l_index := l_index + 1;
2719 inp_value_id_tbl(l_index) := l_type_s_iv_id;
2720 scr_valuetbl(l_index) := l_new_seniority;
2721 END IF;
2722 --
2723 -- Young Mothers may not exist
2724 --
2725 IF l_type_y_iv_id is not null THEN
2726 l_index := l_index + 1;
2727 inp_value_id_tbl(l_index) := l_type_y_iv_id;
2728 scr_valuetbl(l_index) := l_new_mothers;
2729 END IF;
2730 --
2731 -- Also create the reference salary and days
2732 --
2733 IF p_type = 'ENT' THEN
2734 IF l_fr_plan_info.ent_reference_days_iv_id is not null and l_net_ref_days > 0 THEN
2735 l_index := l_index + 1;
2736 inp_value_id_tbl(l_index) := l_fr_plan_info.ent_reference_days_iv_id;
2737 scr_valuetbl(l_index) := l_net_ref_days;
2738 END IF;
2739 IF l_fr_plan_info.ent_reference_sal_iv_id is not null and l_net_ref_salary > 0 THEN
2740 l_index := l_index + 1;
2741 inp_value_id_tbl(l_index) := l_fr_plan_info.ent_reference_sal_iv_id;
2742 scr_valuetbl(l_index) := l_net_ref_salary;
2743 END IF;
2744 END IF;
2745 --
2746 -- Write the record
2747 --
2748
2749 hr_utility.set_location('Step ' || l_proc,200);
2750
2751 IF l_type_link_id is null then
2752 --
2753 -- error : warn user in log : this asg does not have the link to the element
2754 --
2755 fnd_message.set_name('PAY','PAY_75023_PTO_ACC_LINK');
2756 fnd_message.set_token('ASG_NO', l_assignment_number);
2757 fnd_file.put_line(FND_FILE.LOG,fnd_message.get);
2758 END IF;
2759
2760 hr_entry_api.insert_element_entry(
2761 p_effective_start_date => l_pay_period_start_date,
2762 p_effective_end_date => l_pay_period_end_date,
2763 p_element_entry_id => l_new_ee_id,
2764 p_assignment_id => l_asg.assignment_id,
2765 p_element_link_id => l_type_link_id,
2766 p_creator_type => 'F',
2767 p_entry_type => 'E',
2768 p_num_entry_values => l_index,
2769 p_input_value_id_tbl => inp_value_id_tbl,
2770 p_entry_value_tbl => scr_valuetbl);
2771 hr_utility.set_location('Step ' || l_proc,210);
2772
2773 IF l_new_ee_id is null THEN
2774 --
2775 -- warn user in log : could not create the entry
2776 --
2777 fnd_message.set_name('PAY','PAY_75025_PTO_ACC_NO_ENTRY');
2778 fnd_message.set_token('ASG_NO', l_assignment_number);
2779 fnd_file.put_line(FND_FILE.LOG,fnd_message.get);
2780 END IF;
2781
2782 hr_utility.set_location('l_new_ee_id is ' , l_new_ee_id);
2783
2784 END IF; /* l_max_asg_end_date >= l_pay_period_end_date */
2785 END IF; /* l_new_main > 0 or l_new_protected ... */
2786 --
2787 -- flush messges
2788 --
2789 l_message_count := per_accrual_message_pkg.count_messages;
2790 for i in 1..l_message_count loop
2791 --
2792 l_message := per_accrual_message_pkg.get_message(i);
2793 hr_utility.trace(l_message);
2794 --
2795 end loop; /* messages */
2796 --
2797 END IF;
2798 END LOOP; /* l_asg in csr_get_assignment */
2799 --
2800 ELSE
2801 --
2802 IF p_type = 'ADD' THEN
2806 fnd_file.put_line(FND_FILE.LOG, fnd_message.get);
2803 IF l_calculation_date > add_months(l_fr_plan_info.accrual_year_end,12) THEN
2804 -- show warning log message
2805 fnd_message.set_name('PAY','PAY_75196_ADD_ENT_DATE_MORE');
2807 --
2808 END IF;
2809 END IF;
2810 --
2811 END IF;
2812 --
2813 fnd_message.set_name('PAY','PAY_75026_PTO_ACC_PROCESSED');
2814 fnd_file.put_line(FND_FILE.LOG,to_char(l_asg_count) || ' ' || fnd_message.get);
2815 --
2816 hr_utility.set_location('Leaving: '||l_proc,50);
2817 end fr_create_entitlement;
2818 --
2819 -------------------------------------------------------------------------------
2820 -- Get FR Accrual PLAN INFO
2821 -------------------------------------------------------------------------------
2822 function get_fr_accrual_plan_info(
2823 p_accrual_plan_id IN number
2824 ,p_element_entry_id IN number default null
2825 ,p_accrual_date IN date default null
2826 ) return g_fr_plan_info is
2827
2828 l_fr_plan_info g_fr_plan_info;
2829
2830 CURSOR csr_plan_input (p_element_type_id in number) is
2831 select piv1.input_value_id acp_plan_id
2835
2832 from pay_input_values_f piv1
2833 where piv1.element_type_id = p_element_type_id
2834 and piv1.display_sequence = 10;
2836 CURSOR csr_reference_inputs (p_ent_accrual_date_iv in number) is
2837 select piv1.input_value_id reference_salary
2838 ,piv2.input_value_id reference_days
2839 from pay_input_values_f piv1
2840 ,pay_input_values_f piv2
2841 ,pay_input_values_f piv
2842 where piv1.element_type_id = piv2.element_type_id
2843 and piv1.element_type_id = piv.element_type_id
2844 and piv.input_value_id = p_ent_accrual_date_iv
2845 and piv1.display_sequence = 80
2846 and piv2.display_sequence = 90;
2847
2848 CURSOR csr_plan_info (p_accrual_plan_id in Number) is
2849 select nvl(pap.information1,6) accrual_start_month
2850 ,pap.information2 entitlement_offset
2851 ,pap.information3 entitlement_duration
2852 ,pap.information4 working_days
2853 ,pap.information5 protected_days
2854 ,pap.information6 accounting_method
2855 ,pap.information7 main_holiday_acc_plan_id
2856 ,pap.information8 ent_m_iv_id
2857 ,pap.information9 ent_p_iv_id
2858 ,pap.information10 ent_c_iv_id
2859 ,pap.information11 ent_s_iv_id
2860 ,pap.information12 ent_y_iv_id
2861 ,pap.information13 obs_m_iv_id
2862 ,pap.information14 obs_p_iv_id
2863 ,pap.information15 obs_c_iv_id
2864 ,pap.information16 obs_s_iv_id
2865 ,pap.information17 obs_y_iv_id
2866 ,pap.information18 adj_m_iv_id
2867 ,pap.information19 adj_p_iv_id
2868 ,pap.information20 adj_c_iv_id
2869 ,pap.information21 adj_s_iv_id
2870 ,pap.information22 adj_y_iv_id
2871 ,pap.information23 ent_accrual_date_iv_id
2875 ,pap.information27 protected_days_iv_id
2872 ,pap.information24 obs_accrual_date_iv_id
2873 ,pap.information25 adj_accrual_date_iv_id
2874 ,pap.information26 working_days_iv_id
2876 -- lines added for termination processing
2877 ,pap.information28 term_days_iv_id
2878 ,pap.information29 term_accrual_date_iv_id
2879 --
2880 ,pap.accrual_plan_element_type_id accrual_plan_element_id
2881 ,piv.element_type_id holiday_element_id
2882 ,pivE.element_type_id ENT_element_id
2883 ,pivO.element_type_id OBS_element_id
2884 ,pivA.element_type_id ADJ_element_id
2885 -- added for termination processing
2886 ,pivT.element_type_id TERM_element_id
2887 --
2888 ,pap.business_group_id business_Group_id
2889 from pay_accrual_plans pap
2890 ,pay_input_values_f piv
2891 ,pay_input_values_f pivE
2892 ,pay_input_values_f pivO
2893 ,pay_input_values_f pivA
2894 -- added for termination processing
2895 ,pay_input_values_f pivT
2896 where pap.accrual_plan_id = p_accrual_plan_id
2897 and piv.input_value_id = pap.pto_input_value_id
2898 and pivE.input_value_id = pap.information8
2899 and pivO.input_value_id = pap.information13
2900 and pivA.input_value_id = pap.information18
2901 -- Added for termination processing
2902 and pivT.input_value_id(+) = pap.information28;
2903
2904 CURSOR csr_plan_info_ee (c_element_entry_id in number) is
2905 select pap.information1 accrual_start_month
2906 ,pap.information2 entitlement_offset
2907 ,pap.information3 entitlement_duration
2908 ,pap.information4 working_days
2909 ,pap.information5 protected_days
2910 ,pap.information6 accounting_method
2911 ,pap.information7 main_holiday_acc_plan_id
2912 ,pap.information8 ent_m_iv_id
2913 ,pap.information9 ent_p_iv_id
2914 ,pap.information10 ent_c_iv_id
2915 ,pap.information11 ent_s_iv_id
2916 ,pap.information12 ent_y_iv_id
2917 ,pap.information13 obs_m_iv_id
2918 ,pap.information14 obs_p_iv_id
2919 ,pap.information15 obs_c_iv_id
2920 ,pap.information16 obs_s_iv_id
2921 ,pap.information17 obs_y_iv_id
2922 ,pap.information18 adj_m_iv_id
2923 ,pap.information19 adj_p_iv_id
2924 ,pap.information20 adj_c_iv_id
2925 ,pap.information21 adj_s_iv_id
2926 ,pap.information22 adj_y_iv_id
2927 ,pap.information23 ent_accrual_date_iv_id
2928 ,pap.information24 obs_accrual_date_iv_id
2929 ,pap.information25 adj_accrual_date_iv_id
2930 ,pap.accrual_plan_element_type_id accrual_plan_element_id
2931 ,pap.accrual_plan_id accrual_plan_id
2932 ,pap.information26 working_days_iv_id
2933 ,pap.information27 protected_days_iv_id
2934 ,pap.information28 term_days_iv_id
2935 ,pap.information29 term_accrual_date_iv_id
2936 ,pivT.element_type_id term_element_id
2937 ,piv.element_Type_id holiday_element_id
2938 ,pivE.element_type_id ENT_element_id
2939 ,pivO.element_type_id OBS_element_id
2940 ,pivA.element_type_id ADJ_element_id
2941 ,pap.business_group_id business_Group_id
2942 from pay_accrual_plans pap
2943 ,per_absence_attendances paa
2944 ,per_absence_attendance_types pat
2945 ,pay_element_entries_f pee
2946 ,pay_input_values_f piv
2947 ,pay_input_values_f pivE
2948 ,pay_input_values_f pivO
2949 ,pay_input_values_f pivA
2950 ,pay_input_values_f pivT
2951 where paa.absence_attendance_type_id = pat.absence_attendance_type_id
2952 and pivE.input_value_id = pap.information8
2953 and pivO.input_value_id = pap.information13
2954 and pivA.input_value_id = pap.information18
2955 and pat.input_value_id = pap.pto_input_value_id
2956 and paa.absence_Attendance_id = pee.creator_id
2957 and pee.creator_type = 'A'
2958 and piv.input_value_id = pap.pto_input_value_id
2959 and pivT.input_value_id(+) = pap.information28
2960 and pee.element_entry_id = c_element_entry_id;
2961
2962 -- the ddf stores BASE input value id - but the RATE is needed
2963 CURSOR csr_temp_swap_rate (p_element_type_id in number) is
2964 select piv.input_value_id input_value_id
2965 from pay_input_values_f piv
2966 where piv.element_type_id = p_element_type_id
2967 and piv.display_sequence = 40;
2968
2969 rec_plan_info csr_plan_info%ROWTYPE;
2970 rec_plan_info_ee csr_plan_info_ee%ROWTYPE;
2971 rec_reference_inputs csr_reference_inputs%ROWTYPE;
2972
2973 l_asat_month number;
2974 l_add_months number := 0;
2975 temp_ent_accrual_date_iv_id number := 0;
2976 temp_accrual_start_month number := 0;
2977
2981
2978 l_proc VARCHAR2(72) := g_package||' Get FR Accrual Plan Info ';
2979 BEGIN
2980 hr_utility.set_location('Entering ' || l_proc,10);
2982 IF p_accrual_plan_id is not null THEN
2983 open csr_plan_info(p_accrual_plan_id);
2984 fetch csr_plan_info into rec_plan_info;
2985 close csr_plan_info;
2986 l_fr_plan_info.accrual_plan_id := p_accrual_plan_id;
2987 l_fr_plan_info.accrual_start_month := fnd_number.canonical_to_number(rec_plan_info.accrual_start_month);
2988 l_fr_plan_info.entitlement_offset := fnd_number.canonical_to_number(rec_plan_info.entitlement_offset);
2989 l_fr_plan_info.entitlement_duration := fnd_number.canonical_to_number(rec_plan_info.entitlement_duration);
2990 l_fr_plan_info.working_days := fnd_number.canonical_to_number(rec_plan_info.working_days);
2991 l_fr_plan_info.protected_days := fnd_number.canonical_to_number(rec_plan_info.protected_days);
2992 l_fr_plan_info.accounting_method := rec_plan_info.accounting_method;
2993 l_fr_plan_info.ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
2994 l_fr_plan_info.ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
2995 l_fr_plan_info.ent_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_m_iv_id);
2996 l_fr_plan_info.ent_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_p_iv_id);
2997 l_fr_plan_info.ent_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_c_iv_id);
2998 l_fr_plan_info.ent_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_s_iv_id);
2999 l_fr_plan_info.ent_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_y_iv_id);
3000 l_fr_plan_info.obs_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_accrual_date_iv_id);
3001 l_fr_plan_info.obs_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_m_iv_id);
3002 l_fr_plan_info.obs_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_p_iv_id);
3003 l_fr_plan_info.obs_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_c_iv_id);
3004 l_fr_plan_info.obs_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_s_iv_id);
3005 l_fr_plan_info.obs_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_y_iv_id);
3006 l_fr_plan_info.adj_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_accrual_date_iv_id);
3007 l_fr_plan_info.adj_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_m_iv_id);
3008 l_fr_plan_info.adj_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_p_iv_id);
3009 l_fr_plan_info.adj_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_c_iv_id);
3010 l_fr_plan_info.adj_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_s_iv_id);
3011 l_fr_plan_info.adj_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_y_iv_id);
3012 l_fr_plan_info.main_holiday_acc_plan_id := fnd_number.canonical_to_number(rec_plan_info.main_holiday_acc_plan_id);
3013 l_fr_plan_info.holiday_element_id := rec_plan_info.holiday_element_id;
3014 l_fr_plan_info.business_group_id := rec_plan_info.business_Group_id;
3015 l_fr_plan_info.accrual_plan_element_id := rec_plan_info.accrual_plan_element_id;
3016 l_fr_plan_info.working_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.working_days_iv_id);
3017 l_fr_plan_info.protected_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.protected_days_iv_id);
3018 l_fr_plan_info.ent_element_id := rec_plan_info.ENT_element_id;
3019 l_fr_plan_info.obs_element_id := rec_plan_info.OBS_element_id;
3020 l_fr_plan_info.adj_element_id := rec_plan_info.ADJ_element_id;
3021 l_fr_plan_info.term_element_id := rec_plan_info.term_element_id;
3022 l_fr_plan_info.term_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.term_accrual_date_iv_id);
3023 l_fr_plan_info.term_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.term_days_iv_id);
3024 temp_ent_accrual_date_iv_id:= fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
3025 temp_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info.accrual_start_month);
3026 ELSE
3027 open csr_plan_info_ee(p_element_entry_id);
3028 fetch csr_plan_info_ee into rec_plan_info_ee;
3029 close csr_plan_info_ee;
3030 l_fr_plan_info.accrual_start_month := fnd_number.canonical_to_number(rec_plan_info_ee.accrual_start_month);
3031 l_fr_plan_info.entitlement_offset := fnd_number.canonical_to_number(rec_plan_info_ee.entitlement_offset);
3032 l_fr_plan_info.entitlement_duration := fnd_number.canonical_to_number(rec_plan_info_ee.entitlement_duration);
3033 l_fr_plan_info.working_days := fnd_number.canonical_to_number(rec_plan_info_ee.working_days);
3034 l_fr_plan_info.protected_days := fnd_number.canonical_to_number(rec_plan_info_ee.protected_days);
3035 l_fr_plan_info.accounting_method := rec_plan_info_ee.accounting_method;
3036 l_fr_plan_info.ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
3037 l_fr_plan_info.ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
3038 l_fr_plan_info.ent_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_m_iv_id);
3039 l_fr_plan_info.ent_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_p_iv_id);
3043 l_fr_plan_info.obs_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_accrual_date_iv_id);
3040 l_fr_plan_info.ent_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_c_iv_id);
3041 l_fr_plan_info.ent_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_s_iv_id);
3042 l_fr_plan_info.ent_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_y_iv_id);
3044 l_fr_plan_info.obs_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_m_iv_id);
3045 l_fr_plan_info.obs_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_p_iv_id);
3046 l_fr_plan_info.obs_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_c_iv_id);
3047 l_fr_plan_info.obs_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_s_iv_id);
3048 l_fr_plan_info.obs_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_y_iv_id);
3049 l_fr_plan_info.adj_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_accrual_date_iv_id);
3050 l_fr_plan_info.adj_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_m_iv_id);
3051 l_fr_plan_info.adj_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_p_iv_id);
3052 l_fr_plan_info.adj_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_c_iv_id);
3056 l_fr_plan_info.holiday_element_id := rec_plan_info_ee.holiday_element_id;
3053 l_fr_plan_info.adj_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_s_iv_id);
3054 l_fr_plan_info.adj_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_y_iv_id);
3055 l_fr_plan_info.main_holiday_acc_plan_id := fnd_number.canonical_to_number(rec_plan_info_ee.main_holiday_acc_plan_id);
3057 l_fr_plan_info.business_group_id := rec_plan_info_ee.business_Group_id;
3058 l_fr_plan_info.accrual_plan_id := rec_plan_info_ee.accrual_plan_id;
3059 l_fr_plan_info.accrual_plan_element_id := rec_plan_info_ee.accrual_plan_element_id;
3060 l_fr_plan_info.working_days_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.working_days_iv_id);
3061 l_fr_plan_info.ent_element_id := rec_plan_info_ee.ENT_element_id;
3062 l_fr_plan_info.obs_element_id := rec_plan_info_ee.OBS_element_id;
3063 l_fr_plan_info.adj_element_id := rec_plan_info_ee.ADJ_element_id;
3064 l_fr_plan_info.protected_days_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.protected_days_iv_id);
3065 l_fr_plan_info.term_element_id := rec_plan_info.term_element_id;
3066 l_fr_plan_info.term_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.term_accrual_date_iv_id);
3067 l_fr_plan_info.term_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.term_days_iv_id);
3068 temp_ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
3069 temp_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info_ee.accrual_start_month);
3070 END IF;
3071
3072 open csr_temp_swap_rate(l_fr_plan_info.term_element_id);
3073 fetch csr_temp_swap_rate into l_fr_plan_info.term_days_iv_id;
3074 close csr_temp_swap_rate;
3075 hr_utility.trace('new days is ' ||l_fr_plan_info.term_days_iv_id);
3076 --
3077 open csr_reference_inputs (temp_ent_accrual_date_iv_id);
3078 fetch csr_reference_inputs into rec_reference_inputs;
3079 close csr_reference_inputs;
3080 hr_utility.set_location('Step ' || l_proc,20);
3081 --
3082 --
3083 -- Get the plan dates, if p_accrual_date is not null
3084 --
3085 IF p_accrual_date is not null then
3086 l_asat_month := to_number(to_char(p_accrual_date, 'mm'));
3087 if l_asat_month < temp_accrual_start_month then
3088 l_add_months := -12;
3089 end if;
3090
3091 --fnd_file.put_line(fnd_file.log,'in accrual_plan_info h1');
3092 --fnd_file.put_line(fnd_file.log,'temp_accrual_start_month ' || temp_accrual_start_month );
3093 --fnd_file.put_line(fnd_file.log,'pa_accrual_Date is ' || p_accrual_date );
3094 --fnd_file.put_line(fnd_file.log,'l_asat_month is ' || l_asat_month );
3095 --fnd_file.put_line(fnd_file.log,'l_add_months is ' || l_add_months );
3096 --fnd_file.put_line(fnd_file.log,'rec_plan_infoe.accrual_start_month is ' || rec_plan_info.accrual_start_month);
3097 --fnd_file.put_line(fnd_file.log,'l_fr_plan_info.entitlement_offset is ' || l_fr_plan_info.entitlement_offset);
3098
3099 l_fr_plan_info.accrual_year_start := to_date('01-' || temp_accrual_start_month || '-'
3100 || to_char(add_months(p_accrual_date,l_add_months), 'yyyy') || ' 00:00:00'
3101 , 'dd-mm-yyyy hh24:mi:ss');
3102
3103 l_fr_plan_info.accrual_year_end := add_months(l_fr_plan_info.accrual_year_start - 1,12);
3104 end if;
3105
3106 l_fr_plan_info.ent_reference_sal_iv_id := rec_reference_inputs.reference_salary;
3110 fetch csr_plan_input into l_fr_plan_info.ent_acp_iv_id;
3107 l_fr_plan_info.ent_reference_days_iv_id := rec_reference_inputs.reference_days;
3108
3109 open csr_plan_input (l_fr_plan_info.ent_element_id);
3111 close csr_plan_input;
3112 open csr_plan_input (l_fr_plan_info.obs_element_id);
3113 fetch csr_plan_input into l_fr_plan_info.obs_acp_iv_id;
3114 close csr_plan_input;
3115 open csr_plan_input (l_fr_plan_info.adj_element_id);
3116 fetch csr_plan_input into l_fr_plan_info.adj_acp_iv_id;
3117 close csr_plan_input;
3118
3119 --
3120 hr_utility.set_location('Leaving: '||l_proc,100);
3121 return l_fr_plan_info;
3122 end get_fr_accrual_plan_info;
3123 --
3124 -------------------------------------------------------------------------------
3125 -- FR_GET_ACRUAL HIGH - CALLS FR_CALCULATE_ACCRUAL
3126 -- Made changes to the procedure to accept extra parameters for calculation of
3127 -- Additional entitlement. Bug#3030610.
3128 -------------------------------------------------------------------------------
3129 procedure FR_Get_Accrual
3130 (P_Assignment_ID IN Number
3131 ,P_Calculation_Date IN Date
3132 ,p_accrual_start_date IN Date
3133 ,P_Plan_ID IN Number
3134 ,P_Business_Group_ID IN Number
3135 ,P_Payroll_ID IN Number
3136 ,P_Assignment_Action_ID IN Number default null
3137 ,P_Accrual_Latest_Balance IN Number default null
3138 ,p_create_all IN Varchar2 default 'N'
3139 ,p_reprocess_whole_period IN Varchar2 default 'N'
3140 ,p_payslip_process IN Varchar2 default 'N'
3141 -- Added extra inputs for additional days requirements
3142 ,p_legal_period_start_date IN Date default null
3143 ,p_entitlement_offset IN Number default null
3144 ,p_main_holiday_acc_plan_id IN Number default null
3145 ,p_type IN Varchar2 default null
3146 --
3147 ,P_Start_Date OUT NOCOPY Date /* accrual year start date */
3148 ,P_End_Date OUT NOCOPY Date /* accrual year end date */
3149 ,P_Accrual_End_Date OUT NOCOPY Date /* accrual end date */
3150 --
3151 ,P_total_accrued_pto OUT NOCOPY number
3152 ,P_total_Accrued_protected OUT NOCOPY number
3153 ,P_total_Accrued_seniority OUT NOCOPY number
3154 ,P_total_Accrued_mothers OUT NOCOPY number
3155 ,P_total_Accrued_conventional OUT NOCOPY number
3156 ) is
3157
3158 l_proc varchar2(72) := g_package||'FR_Get_Accrual';
3159 l_accrual_plan_rec per_Accrual_calc_functions.g_accrual_plan_rec_type;
3160 l_accrual_for_plan number := 0;
3161 l_effective_start_date date;
3162 l_effective_end_date date;
3163 l_accrual_end_date date;
3164 l_enrolled_in_plan boolean;
3165 l_ret number := 0;
3166
3167 begin
3168 --
3169 hr_utility.set_location('Entering FR_Get_Accrual'||l_proc, 5);
3170
3171 l_accrual_plan_rec := per_accrual_calc_functions.get_accrual_plan(p_plan_id);
3172 hr_utility.set_location('Step ' || l_proc,10);
3173 --fnd_file.put_line(fnd_file.log,'In FR_GET_ACCRUAL' );
3174 --fnd_file.put_line(fnd_file.log,'asg ' || p_assignment_id );
3175 hr_utility.set_location('Calling paer_accrual_calc_functions'||l_proc, 25);
3176 l_Enrolled_In_Plan := per_accrual_calc_functions.check_assignment_enrollment(
3177 p_assignment_id
3178 ,l_accrual_plan_rec.accrual_plan_element_type_id
3179 ,p_calculation_date);
3180
3181 IF l_enrolled_in_plan then
3182 hr_utility.set_location('l_enrolled_in_plan is true in FR_Get_Accrual'||l_proc, 5);
3183 --Added following if statement to support Addtional Holidays
3184 IF p_type IS NULL OR p_type <> 'ADD' THEN
3185 hr_utility.set_location('Enrolled in Plan ' || l_proc,20);
3186 --
3187 l_ret := per_formula_functions.set_text('CREATE_ALL', p_create_all);
3188 l_ret := per_formula_functions.set_text('REPROCESS_ALL', p_reprocess_whole_period);
3189 l_ret := per_formula_functions.set_text('FR_PAYSLIP_PROCESS', p_payslip_process);
3190 l_ret := per_formula_functions.set_date('PROCESS_DATE', p_calculation_date);
3191
3192 FR_calculate_accrual(p_assignment_id => p_assignment_id,
3193 p_plan_id => p_plan_id,
3194 p_payroll_id => p_payroll_id,
3195 p_business_group_id => p_business_group_id,
3196 p_accrual_formula_id => l_accrual_plan_rec.accrual_formula_id,
3197 p_assignment_action_id => p_assignment_action_id,
3198 p_calculation_date => p_calculation_date,
3199 p_accrual_start_date => p_accrual_start_date,
3200 p_accrual_latest_balance => p_accrual_latest_balance,
3201 p_total_accrued_pto => P_total_accrued_pto,
3202 p_total_accrued_protected => p_total_accrued_protected,
3203 p_total_accrued_seniority => p_total_accrued_seniority,
3204 p_total_accrued_mothers => p_total_accrued_mothers,
3205 p_total_accrued_conventional => p_total_accrued_conventional,
3206 p_effective_start_date => l_effective_start_date,
3207 p_effective_end_date => l_effective_end_date,
3208 p_accrual_end_date => l_accrual_end_date
3209 );
3210 hr_utility.set_location('Step ' || l_proc,40);
3211
3212 -- reset these variables
3213 l_ret := per_formula_functions.set_text('CREATE_ALL', ' ');
3217 -- Set the return values of the out parameters
3214 l_ret := per_formula_functions.set_text('REPROCESS_ALL', ' ');
3215 l_ret := per_formula_functions.set_text('FR_PAYSLIP_PROCESS', ' ');
3216 --
3218 --
3219 p_start_date := l_effective_start_date;
3220 p_end_date := l_effective_end_date;
3221 p_accrual_end_date := l_accrual_end_date;
3222 hr_utility.set_location('Step ' || l_proc,50);
3223 --
3224 --
3225 ELSIF p_type = 'ADD' THEN
3226 /*** ie. if p_type = 'ADD'
3227 Additional Holidays Process. Call the the accrual formula related. BUG#3030610***/
3228 hr_utility.set_location('Calling fr_calculate_accrual'||l_proc,125);
3229 FR_calculate_accrual(p_assignment_id => p_assignment_id,
3230 p_plan_id => p_plan_id,
3231 p_payroll_id => p_payroll_id,
3232 p_business_group_id => p_business_group_id,
3233 p_accrual_formula_id => l_accrual_plan_rec.accrual_formula_id,
3234 p_assignment_action_id => p_assignment_action_id,
3235 p_calculation_date => p_calculation_date,
3236 p_accrual_start_date => p_accrual_start_date,
3237 p_accrual_latest_balance => p_accrual_latest_balance,
3238 -- added for additional holidays
3239 p_legal_period_start_date => p_legal_period_start_date,
3240 --
3241 p_entitlement_offset => p_entitlement_offset,
3242 p_main_holiday_acc_plan_id => p_main_holiday_acc_plan_id,
3243 p_type => p_type,
3244 p_total_accrued_pto => P_total_accrued_pto,
3245 p_total_accrued_protected => p_total_accrued_protected,
3246 p_total_accrued_seniority => p_total_accrued_seniority,
3247 p_total_accrued_mothers => p_total_accrued_mothers,
3248 p_total_accrued_conventional => p_total_accrued_conventional,
3249 p_effective_start_date => l_effective_start_date,
3250 p_effective_end_date => l_effective_end_date,
3251 p_accrual_end_date => l_accrual_end_date);
3252 END IF;
3253 --
3254 ELSE --Enrolled plan
3255 hr_utility.set_location('Not Enrolled in plan ' || l_proc,50);
3256 --
3257 p_start_date := null;
3258 p_end_date := null;
3259 p_accrual_end_date := null;
3260 p_total_accrued_pto := 0;
3261 P_total_Accrued_protected := 0;
3262 P_total_Accrued_seniority := 0;
3263 P_total_Accrued_mothers := 0;
3264 P_total_Accrued_conventional := 0;
3265 --
3266 end if;
3267 --
3268 hr_utility.set_location('Leaving '||l_proc, 100);
3269 --fnd_file.put_line(fnd_file.log,'Leaving FR_GET_ACCRUAL' );
3270 --
3271 end FR_Get_Accrual;
3272 -------------------------------------------------------------------------------
3273 -- FR_CALCULATE_ACRUAL LOW LEVEL FAST FORMULA CALL
3274 --Made changes for bug#3030610. The procedure now accepts extra inputs for
3275 --the calculation of additional entitlements.
3276 -------------------------------------------------------------------------------
3277 procedure FR_Calculate_Accrual
3278 (P_Assignment_ID IN Number
3279 ,P_Plan_ID IN Number
3280 ,P_Payroll_ID IN Number
3281 ,P_Business_Group_ID IN Number
3282 ,P_Accrual_formula_ID IN Number
3283 ,P_Assignment_Action_ID IN Number default null
3284 ,P_Calculation_Date IN Date
3285 ,p_accrual_START_date IN Date
3286 -- Added extra inputs for additional days requirements
3287 ,p_legal_period_start_date IN Date default null
3288 ,p_entitlement_offset IN Number default null
3289 ,p_main_holiday_acc_plan_id IN Number default null
3290 ,p_type IN Varchar2 default null
3291 --
3292 ,P_Accrual_Latest_Balance IN Number default null
3293 ,P_Total_Accrued_PTO OUT NOCOPY Number
3294 ,p_total_accrued_protected OUT NOCOPY Number
3295 ,p_total_accrued_seniority OUT NOCOPY Number
3296 ,p_total_accrued_mothers OUT NOCOPY Number
3297 ,p_total_accrued_conventional OUT NOCOPY Number
3298 ,P_Effective_Start_Date OUT NOCOPY Date /* returned by formula */
3299 ,P_Effective_End_Date OUT NOCOPY Date /* returned by formula */
3300 ,P_Accrual_End_date OUT NOCOPY Date) is /* returned by formula */
3301 --
3302 l_proc varchar2(72) := g_package||'FR_Calculate_Accrual';
3303 l_inputs ff_exec.inputs_t;
3304 l_outputs ff_exec.outputs_t;
3305 l_ret number;
3306 -- Added Following variables to support additional day requirements
3307 l_main_holiday_acc_plan_id Number := p_main_holiday_acc_plan_id;
3308 l_accounting_method Varchar2(60);
3309 l_working_days Number;
3310 l_protected_days Number;
3311 l_main_accrual_year_start Date;
3312 l_main_entitlement_offset Number;
3313 l_main_entitlement_duration Number;
3314 l_n Number;
3315 l_d Date;
3316 -- added to retrieve entitlements
3317 l_ent_accrual_date_iv_id Number;
3318 l_type_m_iv_id Number;
3319 l_type_p_iv_id Number;
3320
3321 --
3322 l_add_days NUMBER;
3323 l_add_ent_found NUMBER;
3324 --
3325 -- Cursor for fetching entitled main and protected days
3326 -- from element entries for additional holidays
3327 Cursor csr_entitled_days (c_start_date date,
3331 c_type_p_iv_id number)IS
3328 c_end_date date,
3329 c_type_accrual_date_iv_id number,
3330 c_type_m_iv_id number,
3332 select sum(pevm.screen_entry_value)
3333 ,sum(pevp.screen_entry_value)
3334 from pay_element_entry_values_f pevm
3335 ,pay_element_entry_values_f pevp
3336 ,pay_element_entry_values_f pevdate
3337 ,pay_element_entries_f pee
3338 where pevm.input_value_id = c_type_m_iv_id
3339 and pevp.input_value_id = c_type_p_iv_id
3340 and pevdate.input_value_id = c_type_accrual_date_iv_id
3341 and pee.element_entry_id = pevm.element_entry_id
3342 and pee.element_entry_id = pevp.element_entry_id
3343 and pee.element_entry_id = pevdate.element_entry_id
3344 and pevdate.screen_entry_value between fnd_date.date_to_canonical(c_start_date) and fnd_date.date_to_canonical(c_end_date)
3345 and pee.assignment_id = p_assignment_id ;
3346 --
3347 begin
3348 hr_utility.set_location('Entering ' || l_proc,10);
3349 --fnd_file.put_line(fnd_file.log,'In FR_CALCULATE_ACCRUAL' );
3350 --
3351 -- Added Following line to support additional day requirements.bug#3030610
3352 IF p_type IS NULL OR p_type <> 'ADD' THEN
3353 --
3354 l_ret := per_formula_functions.set_number('TOTAL_ACCRUED_PTO_PROTECTED',0);
3355 l_ret := per_formula_functions.set_number('TOTAL_ACCRUED_PTO_SENIORITY',0);
3356 l_ret := per_formula_functions.set_number('TOTAL_ACCRUED_PTO_MOTHERS',0);
3357 l_ret := per_formula_functions.set_number('TOTAL_ACCRUED_PTO_CONVENTIONAL',0);
3358
3359 hr_utility.set_location('Step ' || l_proc,20);
3360 --
3361 l_inputs(1).name := 'ASSIGNMENT_ID';
3362 l_inputs(1).value := p_assignment_id;
3363 l_inputs(2).name := 'DATE_EARNED';
3364 l_inputs(2).value := fnd_date.date_to_canonical(p_calculation_date);
3365 l_inputs(3).name := 'ACCRUAL_PLAN_ID';
3366 l_inputs(3).value := p_plan_id;
3367 l_inputs(4).name := 'BUSINESS_GROUP_ID';
3368 l_inputs(4).value := p_business_group_id;
3369 l_inputs(5).name := 'PAYROLL_ID';
3370 l_inputs(5).value := p_payroll_id;
3371 l_inputs(6).name := 'CALCULATION_DATE';
3372 l_inputs(6).value := fnd_date.date_to_canonical(p_calculation_date);
3373 l_inputs(7).name := 'ACCRUAL_START_DATE';
3374 l_inputs(7).value := fnd_date.date_to_canonical(p_accrual_start_date);
3375 l_inputs(8).name := 'ASSIGNMENT_ACTION_ID';
3376 l_inputs(8).value := p_assignment_action_id;
3377 l_inputs(9).name := 'ACCRUAL_LATEST_BALANCE';
3378 l_inputs(9).value := p_accrual_latest_balance;
3379
3380 l_outputs(1).name := 'TOTAL_ACCRUED_PTO';
3381 l_outputs(2).name := 'EFFECTIVE_START_DATE';
3382 l_outputs(3).name := 'EFFECTIVE_END_DATE';
3383 l_outputs(4).name := 'ACCRUAL_END_DATE';
3384
3385 per_formula_functions.run_formula(p_formula_id => p_accrual_formula_id,
3386 p_calculation_date => p_calculation_date,
3387 p_inputs => l_inputs,
3388 p_outputs => l_outputs);
3389
3390
3391 p_total_accrued_pto := fnd_number.canonical_to_number(l_outputs(1).value);
3392 p_effective_start_date := fnd_date.canonical_to_date(l_outputs(2).value);
3393 p_effective_end_date := fnd_date.canonical_to_date(l_outputs(3).value);
3394 p_accrual_end_date := fnd_date.canonical_to_date(l_outputs(4).value);
3395 P_total_Accrued_protected := per_formula_functions.get_number('TOTAL_ACCRUED_PTO_PROTECTED');
3396 P_total_Accrued_seniority := per_formula_functions.get_number('TOTAL_ACCRUED_PTO_SENIORITY');
3397 P_total_Accrued_mothers := per_formula_functions.get_number('TOTAL_ACCRUED_PTO_MOTHERS');
3398 P_total_Accrued_conventional := per_formula_functions.get_number('TOTAL_ACCRUED_PTO_CONVENTIONAL');
3399 --
3400 --
3401 ELSIF p_type = 'ADD' THEN
3402 /*** That is if p_type = 'ADD' -- The Additional Days Entitlement Process' .bug#3030610**/
3403 get_accrual_plan_info(
3404 p_accrual_plan_id => l_main_holiday_acc_plan_id
3405 ,p_accrual_date => p_accrual_start_date
3406 ,p_accrual_year_start => l_main_accrual_year_start
3407 ,p_accrual_year_end => l_d
3408 ,p_accrual_start_month => l_n
3409 ,p_entitlement_offset => l_main_entitlement_offset
3410 ,p_entitlement_duration => l_main_entitlement_duration
3411 ,p_working_days => l_working_days
3412 ,p_protected_days => l_protected_days
3413 ,p_accounting_method => l_accounting_method
3414 ,p_ent_accrual_date_iv_id => l_ent_accrual_date_iv_id -- modified for fetching entitlements
3415 ,p_ent_reference_sal_iv_id => l_n
3416 ,p_ent_reference_days_iv_id => l_n
3417 ,p_ent_m_iv_id => l_type_m_iv_id -- modified for fetching entitlements
3418 ,p_ent_p_iv_id => l_type_p_iv_id -- modified for fetching entitlements
3419 ,p_ent_c_iv_id => l_n
3420 ,p_ent_s_iv_id => l_n
3421 ,p_ent_y_iv_id => l_n
3422 ,p_ent_acp_iv_id => l_n
3423 ,p_obs_accrual_date_iv_id => l_n
3424 ,p_obs_m_iv_id => l_n
3425 ,p_obs_p_iv_id => l_n
3426 ,p_obs_c_iv_id => l_n
3427 ,p_obs_s_iv_id => l_n
3428 ,p_obs_y_iv_id => l_n
3429 ,p_obs_acp_iv_id => l_n
3430 ,p_adj_accrual_date_iv_id => l_n
3431 ,p_adj_m_iv_id => l_n
3432 ,p_adj_p_iv_id => l_n
3433 ,p_adj_c_iv_id => l_n
3434 ,p_adj_s_iv_id => l_n
3435 ,p_adj_y_iv_id => l_n
3439 ,p_accrual_plan_element_id => l_n
3436 ,p_adj_acp_iv_id => l_n
3437 ,p_main_holiday_acc_plan_id => l_n
3438 ,p_holiday_element_id => l_n
3440 ,p_working_days_iv_id => l_n
3441 ,p_protected_days_iv_id => l_n
3442 ,p_business_Group_id => l_n
3443 ,p_ent_element_id => l_n
3444 ,P_obs_element_id => l_n
3445 ,P_adj_element_id => l_n);
3446 --
3447 -- Pick up the number of days entitlement from from element entry
3448 OPEN csr_entitled_days (l_main_accrual_year_start,
3449 add_months(l_main_accrual_year_start-1, 12),
3450 l_ent_accrual_date_iv_id,
3451 l_type_m_iv_id,
3452 l_type_p_iv_id);
3453 FETCH csr_entitled_days INTO l_working_days, l_protected_days;
3454 CLOSE csr_entitled_days;
3455 --
3456 /*** Note that holiday start period = legal period start date
3457 Legal period start date = add_months(l_main_accrual_year_start,l_main_entitlement_offset) ***/
3458 --
3459 l_inputs(1).name := 'ASSIGNMENT_ID';
3460 l_inputs(1).value := p_assignment_id;
3461 l_inputs(2).name := 'CALCULATION_DATE';
3462 l_inputs(2).value := fnd_date.date_to_canonical(p_calculation_date);
3463 l_inputs(3).name := 'LEGAL_PERIOD';
3464 -- hard coding the legal period
3465 l_inputs(3).value := 6;
3466 --
3467 l_inputs(4).name := 'MAIN_HOLIDAY_ACC_PLAN_ID';
3468 l_inputs(4).value := p_main_holiday_acc_plan_id;
3469 l_inputs(5).name := 'ACCOUNTING_METHOD';
3470 l_inputs(5).value := l_accounting_method;
3471 l_inputs(6).name := 'PROCESS_FLAG';
3472 l_inputs(6).value := p_type;
3473 l_inputs(7).name := 'MAIN_WORKING_DAYS';
3474 l_inputs(7).value := l_working_days;
3475 l_inputs(8).name := 'MAIN_PROTECTED_DAYS';
3476 l_inputs(8).value := l_protected_days;
3477 l_inputs(9).name := 'LEGAL_PERIOD_START_DATE';
3478 -- modified input values and value name
3479 l_inputs(9).value := fnd_date.date_to_canonical(p_legal_period_start_date);
3480 l_inputs(10).name := 'HOLIDAY_PERIOD_START_DATE';
3481 l_inputs(10).value := fnd_date.date_to_canonical(add_months(l_main_accrual_year_start,l_main_entitlement_offset));
3482 l_inputs(11).name := 'HOLIDAY_PERIOD';
3483 l_inputs(11).value := l_main_entitlement_duration;
3484
3485
3486 l_outputs(1).name := 'ADDITIONAL_ENTITLEMENT';
3487
3488
3489 hr_utility.set_location('Formula ID:'||p_accrual_formula_id, 555);
3490 hr_utility.set_location('Calc Date:'||p_calculation_date,556);
3491 hr_utility.set_location(l_inputs(1).name||':'||l_inputs(1).value,557);
3492 hr_utility.set_location(l_inputs(2).name||':'||l_inputs(2).value,558);
3493 hr_utility.set_location(l_inputs(3).name||':'||l_inputs(3).value,559);
3494 hr_utility.set_location(l_inputs(4).name||':'||l_inputs(4).value,560);
3495 hr_utility.set_location(l_inputs(5).name||':'||l_inputs(5).value,561);
3496 hr_utility.set_location(l_inputs(6).name||':'||l_inputs(6).value,562);
3497 hr_utility.set_location(l_inputs(7).name||':'||l_inputs(7).value,563);
3498 hr_utility.set_location(l_inputs(8).name||':'||l_inputs(8).value,564);
3499 hr_utility.set_location(l_inputs(9).name||':'||l_inputs(9).value,565);
3500 hr_utility.set_location(l_inputs(10).name||':'||l_inputs(10).value,566);
3501 hr_utility.set_location(l_inputs(11).name||':'||l_inputs(11).value,567);
3502
3503
3504 per_formula_functions.run_formula(p_formula_id => p_accrual_formula_id,
3505 p_calculation_date => p_calculation_date,
3506 p_inputs => l_inputs,
3507 p_outputs => l_outputs);
3508
3509 p_total_accrued_pto := nvl(l_outputs(1).value,0);
3510 hr_utility.set_location( l_outputs(1).name||':'|| p_total_accrued_pto,21);
3511
3512 END IF;
3513 --
3514 --fnd_file.put_line(fnd_file.log,'Leaving FR_CALCULATE_ACCRUAL' );
3515 --
3516 end FR_Calculate_Accrual;
3517 --
3518
3519 -------------------------------------------------------------------------------
3520 -- OBSOLETION_PROCEDURE
3521 -------------------------------------------------------------------------------
3522 procedure obsoletion_procedure
3523 (p_business_group_id IN number
3524 ,p_assignment_id IN number default null
3525 ,p_accrual_plan_id IN number
3526 ,p_effective_date IN date
3527 ,p_accrual_date IN date
3528 ,p_formula_id IN number
3529 ,p_payroll_id IN number
3530 ,p_net_entitlement IN number
3531 ,p_net_main_days IN number
3532 ,p_net_conven_days IN number
3533 ,p_net_seniority_days IN number
3534 ,p_net_protected_days IN number
3535 ,p_net_youngmother_days IN number
3536 ,p_new_main_days OUT NOCOPY number
3537 ,p_new_conven_days OUT NOCOPY number
3538 ,p_new_seniority_days OUT NOCOPY number
3539 ,p_new_protected_days OUT NOCOPY number
3540 ,p_new_youngmother_days OUT NOCOPY number) is
3541
3542
3543 l_date date;
3544 l_ent_start_date date;
3545 l_expiry_date date;
3546 l_max_carryovers number;
3547 no_of_obsoletes number;
3548 l_number number;
3549 l_unused_date date;
3550 l_proc VARCHAR2(72) := g_package||' obsoletion_Procedure ';
3551
3552 begin
3553 hr_utility.set_location('Entering ' || l_proc,10);
3554 --fnd_file.put_line(fnd_file.log,'In Obsoletion Procedure' );
3555
3556 l_number := per_formula_functions.set_date('PROCESS_DATE', p_effective_date);
3557
3561 P_EFFECTIVE_DATE => p_accrual_date,
3558 l_number := get_fr_latest_ent_date(
3559 P_ASSIGNMENT_ID => p_assignment_id,
3560 P_ACCRUAL_PLAN_ID => p_accrual_plan_id,
3562 P_LATEST_DATE => l_date,
3563 P_ENTITLEMENT_START_DATE => l_ent_start_date,
3564 P_ACCRUAL_START_DATE => l_date,
3565 P_ACCRUAL_END_DATE => l_unused_date);
3566
3567 hr_utility.set_location('Step ' || l_proc,30);
3568
3569 --fnd_file.put_line(fnd_file.log,'Ent start date' || l_ent_start_date );
3570 --fnd_file.put_line(fnd_file.log,'Formula ID' || p_formula_id );
3571 --fnd_file.put_line(fnd_file.log,'Assignment id' || p_assignment_id );
3572 --fnd_file.put_line(fnd_file.log,'Accrual Plan Id' || p_accrual_plan_id );
3573 --fnd_file.put_line(fnd_file.log,'Business Group Id' || p_business_group_id );
3574 --fnd_file.put_line(fnd_file.log,'Payroll Id' || p_payroll_id );
3575 --fnd_file.put_line(fnd_file.log,'Effective Date' || p_effective_date );
3576
3577 per_accrual_calc_functions.get_carry_over_values(
3578 p_co_formula_id => p_formula_id
3579 ,p_assignment_id => p_assignment_id
3580 ,p_accrual_plan_id => p_accrual_plan_id
3581 ,p_business_group_id => p_business_group_id
3582 ,p_payroll_id => p_payroll_id
3583 ,p_calculation_date => l_ent_start_date
3584 ,p_session_date => p_effective_date
3585 ,p_accrual_term => 'PROCESS'
3586 ,p_effective_date => l_date
3587 ,p_expiry_date => l_expiry_date
3588 ,p_max_carry_over => l_max_carryovers );
3589
3590 no_of_obsoletes := p_net_entitlement - l_max_carryovers;
3591 hr_utility.set_location('Step ' || l_proc,40);
3592
3593 --fnd_file.put_line(fnd_file.log,'Net entitlement' || p_net_entitlement );
3594 --fnd_file.put_line(fnd_file.log,'Carryovers' || l_max_carryovers );
3595 --fnd_file.put_line(fnd_file.log,'no of obsoletes' || no_of_obsoletes );
3596
3597 FOR i in 1..5 LOOP
3598
3599 IF (i = 1 and p_net_youngmother_days > 0 and no_of_obsoletes > 0) then
3600
3601 if (no_of_obsoletes >= p_net_youngmother_days ) then
3602 no_of_obsoletes := no_of_obsoletes - p_net_youngmother_days;
3603 p_new_youngmother_days := p_net_youngmother_days;
3604 else
3605 p_new_youngmother_days := no_of_obsoletes;
3606 p_new_main_days := 0;
3607 p_new_conven_days := 0;
3608 p_new_seniority_days := 0;
3609 p_new_protected_days := 0;
3610 no_of_obsoletes := 0;
3611 hr_utility.set_location('Step ' || l_proc,50);
3612 end if;
3613 END IF;
3614 IF (i = 2 and p_net_protected_days > 0 and no_of_obsoletes > 0) then
3615 if (no_of_obsoletes >= p_net_protected_days ) then
3616 no_of_obsoletes := no_of_obsoletes - p_net_protected_days ;
3617 p_new_protected_days := p_net_protected_days;
3618 else
3619 p_new_main_days := 0;
3620 p_new_conven_days := 0;
3621 p_new_seniority_days := 0;
3622 p_new_protected_days := no_of_obsoletes;
3623 no_of_obsoletes := 0;
3624 hr_utility.set_location('Step ' || l_proc,60);
3625 end if;
3626 END IF;
3627 IF (i = 3 and p_net_seniority_days > 0 and no_of_obsoletes > 0) then
3628 if (no_of_obsoletes >= p_net_seniority_days ) then
3629 no_of_obsoletes := no_of_obsoletes - p_net_seniority_days;
3630 p_new_seniority_days := p_net_seniority_days;
3631 else
3632 p_new_main_days := 0;
3633 p_new_conven_days := 0;
3634 p_new_seniority_days := no_of_obsoletes;
3635 no_of_obsoletes := 0;
3636 hr_utility.set_location('Step ' || l_proc,70);
3637 end if;
3638 END IF;
3639 IF (i = 4 and p_net_conven_days > 0 and no_of_obsoletes > 0) then
3640 if (no_of_obsoletes >= p_net_conven_days ) then
3641 no_of_obsoletes := no_of_obsoletes - p_net_conven_days;
3642 p_new_conven_days := p_net_conven_days;
3643 else
3644 p_new_main_days := 0;
3645 p_new_conven_days := no_of_obsoletes;
3646 no_of_obsoletes := 0;
3647 end if;
3648 END IF;
3649 IF (i = 5 and p_net_main_days > 0 and no_of_obsoletes > 0) then
3650 if (no_of_obsoletes >= p_net_main_days ) then
3651 no_of_obsoletes := no_of_obsoletes - p_net_main_days;
3652 p_new_main_days := p_net_main_days;
3653 else
3654 p_new_main_days := no_of_obsoletes;
3655 no_of_obsoletes := 0;
3656 hr_utility.set_location('Step ' || l_proc,80);
3657 end if;
3658 END IF;
3659 end loop;
3660
3661 p_new_youngmother_days := 0 - p_new_youngmother_days;
3662 p_new_main_days := 0 - p_new_main_days;
3663 p_new_conven_days := 0 - p_new_conven_days;
3664 p_new_seniority_days := 0 - p_new_seniority_days;
3665 p_new_protected_days := 0 - p_new_protected_days;
3666
3667 --fnd_file.put_line(fnd_file.log,' Net Mothers' || p_net_youngmother_days );
3668 --fnd_file.put_line(fnd_file.log,'Net Main' || p_net_main_days );
3669 --fnd_file.put_line(fnd_file.log,'Net Conventional' || p_net_conven_days );
3670 --fnd_file.put_line(fnd_file.log,'Net Seniority' || p_net_seniority_days );
3671 --fnd_file.put_line(fnd_file.log,'Net Protected' || p_net_protected_days );
3672
3673 --fnd_file.put_line(fnd_file.log,'Mothers' || p_new_youngmother_days );
3674 --fnd_file.put_line(fnd_file.log,'Main' || p_new_main_days );
3675 --fnd_file.put_line(fnd_file.log,'Conventional' || p_new_conven_days );
3676 --fnd_file.put_line(fnd_file.log,'Seniority' || p_new_seniority_days );
3677 --fnd_file.put_line(fnd_file.log,'Protected' || p_new_protected_days );
3678
3682 -------------------------------------------------------------------------------
3679 --fnd_file.put_line(fnd_file.log,'Leaving Obsolete Procedure' );
3680 hr_utility.set_location('Leaving: '||l_proc,100);
3681 end obsoletion_procedure;
3683 -- GET_FR_HOLIDAYS_BOOKED FORMULA FUNCTION
3684 -------------------------------------------------------------------------------
3685 function Get_fr_holidays_booked
3686 (P_assignment_id IN Number /* the assignment */
3687 ,p_business_Group_id IN Number
3688 ,P_accrual_plan_id IN Number
3689 ,p_accrual_start_date IN Date
3690 ,p_total_booked OUT NOCOPY Number
3691 ) return number is
3692
3693 l_accrual_plan_id Number := p_accrual_plan_id;
3694 l_accrual_year_start Date;
3695 l_accrual_year_end Date;
3696 l_holiday_element_id Number;
3697 l_unused_char Varchar2(30);
3698 l_unused_number Number;
3699 l_ret Number;
3700 --
3701 l_total_m Number := 0;
3702 l_total_p Number := 0;
3703 l_total_s Number := 0;
3704 l_total_c Number := 0;
3705 l_total_y Number := 0;
3706 l_proc VARCHAR2(72) := g_package||' Get_fr_holidays_booked ';
3707 --
3708 BEGIN
3709 hr_utility.set_location('Entering ' || l_proc,10);
3710 --
3711 -- fetch variables for this accrual plan
3712 --
3713 get_accrual_plan_data(
3714 p_accrual_plan_id => l_accrual_plan_id
3715 ,p_accrual_date => p_accrual_start_date
3716 ,p_accrual_year_start => l_accrual_year_start
3717 ,p_accrual_year_end => l_accrual_year_end
3718 ,p_accounting_method => l_unused_char
3719 ,p_entitlement_offset => l_unused_number
3720 ,p_ent_ref_days_id => l_unused_number
3721 ,p_ent_ref_salary_id => l_unused_number
3722 ,p_ent_accrual_date_iv_id => l_unused_number
3723 ,p_holiday_element_id => l_holiday_element_id);
3724
3725 hr_utility.set_location('Step ' || l_proc,20);
3726 --
3727 -- Call sub procedure to calculate the totals
3728 --
3729 l_ret := Get_fr_holidays_booked_list (
3730 P_assignment_id => P_assignment_id
3731 ,p_business_Group_id => p_business_Group_id
3732 ,P_accrual_plan_id => P_accrual_plan_id
3733 ,p_accrual_start_date => l_accrual_year_start
3734 ,p_accrual_end_date => l_accrual_year_end
3735 ,p_holiday_element_id => l_holiday_element_id
3736 ,p_total_m => l_total_m
3737 ,p_total_p => l_total_p
3738 ,p_total_c => l_total_c
3739 ,p_total_s => l_total_s
3740 ,p_total_y => l_total_y );
3741
3742 p_total_booked := nvl(l_total_m,0) + nvl(l_total_p,0) +nvl(l_total_c,0) +nvl(l_total_s,0) +nvl(l_total_y,0);
3743 --
3744 hr_utility.set_location('Leaving: '||l_proc,50);
3745 return 1;
3746 END get_fr_holidays_booked;
3747 --
3748 -------------------------------------------------------------------------------
3749 -- GET_FR_HOLIDAYS_BOOKED_LIST
3750 -------------------------------------------------------------------------------
3751 function Get_fr_holidays_booked_list
3752 (P_assignment_id IN Number /* the assignment */
3753 ,p_business_Group_id IN Number
3754 ,P_accrual_plan_id IN Number
3755 ,p_accrual_start_date IN Date
3756 ,p_accrual_end_date IN Date
3757 ,p_holiday_element_id IN Number
3758 ,p_total_m OUT NOCOPY Number
3759 ,p_total_p OUT NOCOPY Number
3760 ,p_total_c OUT NOCOPY Number
3761 ,p_total_s OUT NOCOPY Number
3762 ,p_total_y OUT NOCOPY Number
3763 ) return number is
3764
3765 CURSOR csr_booked_holiday (p_assignment_id in number, p_holiday_element_id in number
3766 ,p_accrual_year_start date, p_accrual_year_end Date) is
3767 select sum(to_number(nvl(paa.abs_information2,'0'))) /* main days booked */
3768 ,sum(to_number(nvl(paa.abs_information3,'0'))) /* protected days booked */
3769 ,sum(to_number(nvl(paa.abs_information4,'0'))) /* conventional days booked */
3770 ,sum(to_number(nvl(paa.abs_information5,'0'))) /* Seniority days booked */
3771 ,sum(to_number(nvl(paa.abs_information6,'0'))) /* Young mothers days booked */
3772 from per_absence_attendances paa
3773 ,pay_element_entries_f pee
3774 where pee.element_link_id in (select element_link_id
3775 from pay_element_links_f
3776 where element_type_id = p_holiday_element_id
3777 )
3778 and pee.creator_type = 'A'
3779 and paa.absence_Attendance_id = pee.creator_id
3780 and paa.abs_information1 between fnd_date.date_to_canonical(p_accrual_year_start)
3781 and fnd_date.date_to_canonical(p_accrual_year_end)
3782 and pee.assignment_id = p_assignment_id;
3783
3784 l_proc VARCHAR2(72) := g_package||' Get_fr_holidays_booked_list ';
3785
3786 BEGIN
3787 hr_utility.set_location('Entering ' || l_proc,10);
3788 --
3789 -- Fetch breakdown of booked holidays
3790 --
3791 hr_utility.set_location('p_assignment_id ' , p_assignment_id);
3792 hr_utility.set_location('p_holiday_element_id ' , p_holiday_element_id);
3793 hr_utility.set_location('sd' || to_char(p_accrual_start_date,'dd-mm-yyyy'), 10);
3797 Fetch csr_booked_holiday into p_total_m, p_total_p, p_total_c ,p_total_s ,p_total_y;
3794 hr_utility.set_location('ed' || to_char(p_accrual_end_date,'dd-mm-yyyy'), 20);
3795
3796 OPEN csr_booked_holiday (p_assignment_id, p_holiday_element_id, p_accrual_start_date, p_accrual_end_date);
3798 close csr_booked_holiday;
3799
3800 hr_utility.set_location('p_total_m ' , p_total_m);
3801 hr_utility.set_location('p_total_p ' , p_total_p);
3802 hr_utility.set_location('p_total_c ' , p_total_c);
3803 hr_utility.set_location('p_total_s ' , p_total_s);
3804 hr_utility.set_location('p_total_u ' , p_total_y);
3805 --
3806 hr_utility.set_location('Leaving: '||l_proc,100);
3807 return 1;
3808 END get_fr_holidays_booked_list;
3809 --
3810 -------------------------------------------------------------------------------
3811 -- GET_FR_YOUNG_MOTHERS_DAYS
3812 -------------------------------------------------------------------------------
3813 function Get_fr_young_mothers_days
3814 (P_assignment_id IN Number
3815 ,p_business_Group_id IN Number
3816 ,P_child_age_date IN Date /* CHILD COMPARISON DATE */
3817 ,p_child_age IN Number /* max age of eligible children */
3818 ,p_no_of_children OUT NOCOPY Number /* number of children */
3819 ) return number is
3820
3821 CURSOR csr_count is
3822 select count(distinct(d.person_id))
3823 from per_all_people_f d
3824 ,per_all_people_f p
3825 ,per_contact_relationships pcr
3826 ,per_all_assignments_f asg
3827 where asg.assignment_id = P_assignment_id
3828 and asg.business_group_id = p_business_Group_id
3829 and asg.person_id = p.person_id
3830 and trunc(sysdate) between asg.effective_start_date and asg.effective_end_date
3831 and trunc(sysdate) between p.effective_start_date and p.effective_end_date
3832 and trunc(sysdate) between d.effective_start_date and d.effective_end_date
3833 and asg.person_id = pcr.person_id
3834 and pcr.contact_person_id = d.person_id
3835 and add_months(d.date_of_birth, 12 * 16) > P_child_age_date
3836 and add_months(p.date_of_birth, 12 * 21) > add_months(P_child_age_date, -12)
3837 and p.current_employee_flag = 'Y'
3838 and p.sex = 'F'
3839 and nvl(pcr.date_end, P_child_age_date) >= P_child_age_date
3840 AND EXISTS
3841 ( SELECT pst.INFORMATION3 from per_shared_types pst
3842 WHERE pcr.contact_type = pst.system_type_cd
3843 AND pst.lookup_type = 'CONTACT'
3844 AND pst.INFORMATION3 = 'Y'
3845 AND ( pst.business_group_id = asg.business_group_id
3846 OR pst.business_group_id IS NULL)
3847 );
3848 l_proc VARCHAR2(72) := g_package||' Get_fr_young_mothers_days ';
3849
3850 BEGIN
3851 hr_utility.set_location('Entering ' || l_proc,10);
3852 --
3853 open csr_count;
3854 fetch csr_count into p_no_of_children;
3855 close csr_count;
3856 --
3857 hr_utility.set_location('p_no_of_children ', p_no_of_children);
3858 hr_utility.set_location('Leaving: '||l_proc,50);
3859 --
3860 return 1;
3861 end Get_fr_young_mothers_days;
3862 -------------------------------------------------------------------------------
3863 -- GET_FR_ACCRUAL_RATE_CHANGES ACCRUALS FORMULA FUNCTION
3864 -------------------------------------------------------------------------------
3865 function get_fr_accrual_rate_changes
3866 (p_assignment_id IN Number
3867 ,p_plan_id IN Number
3868 ,p_month_in_date IN Date
3869 ,p_main_rate OUT NOCOPY Number
3870 ,p_protected_rate OUT NOCOPY Number)
3871 return number is
3872 l_ret Number;
3873 l_main_rate_defualt_value Number;
3874 l_protected_rate_defualt_value Number;
3875 l_month_in_date Date := trunc(p_month_in_date);
3876 l_index Number;
3877 l_proc VARCHAR2(72) := g_package||' get_fr_accrual_rate_changes ';
3878 BEGIN
3879 hr_utility.set_location('Entering ' || l_proc,10);
3880 --
3881 -- If the global collection has not been set, set it
3882 --
3883 IF p_assignment_id <> nvl(g_rate_assignment_in_table, -1)
3884 OR
3885 p_plan_id <> g_plan_in_table THEN
3886 l_ret := set_fr_Accrual_rate_changes
3887 (p_assignment_id => p_assignment_id
3888 ,p_plan_id => p_plan_id
3889 ,p_start_date => hr_api.g_sot
3890 ,p_end_date => hr_api.g_eot);
3891 END IF;
3892 --
3893 -- Get defualt values for main and protected
3894 --
3895 l_main_rate_defualt_value := g_rate_tab(1).main_rate;
3896 l_protected_rate_defualt_value := g_rate_tab(1).protected_rate;
3897 --
3898 -- Search the array for the rate as at l_month_in_date
3899 -- Look for earliest end date on or after l_month_in_date.
3900 --
3901 l_index := 2;
3902 IF l_index <= g_rate_tab.COUNT THEN
3903
3904 FOR i in 2 .. g_rate_tab.LAST LOOP
3905 l_index := i;
3906 EXIT WHEN l_month_in_date <= g_rate_tab(i).end_date;
3907 END LOOP;
3908 --
3909 -- This may be the natural end of loop, the correct record, or both
3910 --
3911 IF l_month_in_date between g_rate_tab(l_index).start_date
3912 and g_rate_tab(l_index).end_date THEN
3913 p_main_rate := g_rate_tab(l_index).main_rate;
3914 p_protected_rate := nvl(g_rate_tab(l_index).protected_rate,g_rate_tab(1).protected_rate) ;
3915 ELSE
3916 --
3917 -- Gaps in the arry are filled by the defaults
3918 --
3922 ELSE
3919 p_main_rate := g_rate_tab(1).main_rate;
3920 p_protected_rate := g_rate_tab(1).protected_rate;
3921 END IF;
3923 --
3924 -- If there are no records, the defualts are used.
3925 --
3926 p_main_rate := nvl(g_rate_tab(1).main_rate,0);
3927 p_protected_rate := nvl(g_rate_tab(1).protected_rate,0);
3928 END IF;
3929 hr_utility.set_location('Leaving: '||l_proc,50);
3930 return 1;
3931 END ;
3932 -------------------------------------------------------------------------------
3933 -- SET_FR_ACCRUAL_RATE_CHANGES ACCRUALS FORMULA FUNCTION
3934 -------------------------------------------------------------------------------
3935 function set_fr_Accrual_rate_changes
3936 (p_assignment_id IN Number
3937 ,p_plan_id IN Number
3938 ,p_start_date IN Date
3939 ,p_end_date IN Date )
3940 return number is
3941 l_working_days_iv_id Number;
3942 l_protected_days_iv_id Number;
3943 l_accrual_plan_element_id Number;
3944
3945 l_start_date date;
3946 l_end_date date;
3947 l_main_rate Number ;
3948 l_protected_rate Number;
3949 l_index Number := 1;
3950 l_main_rate_defualt_value Number;
3951 l_protected_rate_defualt_value Number;
3952 l_proc VARCHAR2(72) := g_package||' set_fr_Accrual_rate_changes ';
3953 --
3954 CURSOR csr_get_overrides is
3955 select peevM.effective_start_Date start_date
3956 ,peevM.effective_end_date end_date
3957 ,peevM.screen_entry_value main_rate
3958 ,peevP.screen_entry_value protected_rate
3959 from
3960 pay_element_entries_f pee
3961 ,pay_element_entry_values_f peevM
3962 ,pay_element_entry_values_f peevP
3963 where
3964 pee.element_entry_id = peevM.element_entry_id
3965 and pee.element_entry_id = peevP.element_entry_id(+)
3966 and pee.element_link_id in (select element_link_id
3967 from pay_element_links_f
3968 where element_type_id = l_accrual_plan_element_id
3969 )
3970 and peevM.input_value_id = l_working_days_iv_id
3971 and peevP.input_value_id(+) = l_protected_days_iv_id
3972 and pee.effective_start_Date = peevM.effective_start_Date
3973 and pee.effective_end_Date = peevM.effective_end_Date
3974 and pee.effective_start_Date = peevP.effective_start_Date(+)
3975 and pee.effective_end_Date = peevP.effective_end_Date(+)
3976 and pee.assignment_id = p_assignment_id
3977 Order by
3978 peevM.effective_start_Date;
3979
3980
3981 BEGIN
3982 hr_utility.set_location('Entering ' || l_proc,10);
3983 get_accrual_plan_overrides(
3984 p_accrual_plan_id => p_plan_id
3985 ,p_accrual_plan_element_id => l_accrual_plan_element_id
3986 ,p_working_days_iv_id => l_working_days_iv_id
3987 ,p_protected_days_iv_id => l_protected_days_iv_id
3988 ,p_main_rate_defualt_value => l_main_rate_defualt_value
3989 ,p_protected_rate_defualt_value => l_protected_rate_defualt_value);
3990
3991 hr_utility.set_location('accrual plan element id is ' , l_accrual_plan_element_id);
3992 hr_utility.set_location('accrual plan working days id is ' , l_working_days_iv_id);
3993 hr_utility.set_location('accrual plan protected days id is ' , l_protected_days_iv_id);
3994 --
3995 -- Clear out the structure
3996 --
3997 g_rate_tab.Delete;
3998 g_rate_assignment_in_table := -1;
3999 g_plan_in_table := -1;
4000 --
4001 -- Set the defaults in instance 1
4002 --
4003 g_rate_tab(1).main_rate := l_main_rate_defualt_value;
4004 g_rate_tab(1).protected_rate := l_protected_rate_defualt_value;
4005
4006 for csr_rec in csr_get_overrides LOOP
4007 l_index := l_index + 1;
4008 hr_utility.set_location('l_index ' , l_index);
4009
4010 g_rate_tab(l_index).main_rate := csr_rec.main_rate;
4011 g_rate_tab(l_index).protected_rate := csr_rec.protected_rate;
4012 g_rate_tab(l_index).start_date := csr_rec.start_date;
4013 g_rate_tab(l_index).end_date := csr_rec.end_date;
4014
4015 END LOOP;
4016 g_rate_assignment_in_table := p_assignment_id;
4017 g_plan_in_table := p_plan_id;
4018 --
4019 hr_utility.set_location('Leaving: '||l_proc,50);
4020 return 1;
4021 end set_fr_accrual_rate_changes;
4022
4023 -------------------------------------------------------------------------------
4024 -- Get Accrual Plan Overrides
4025 -------------------------------------------------------------------------------
4026 procedure get_accrual_plan_overrides(
4027 p_accrual_plan_id IN number
4028 ,p_accrual_plan_element_id OUT NOCOPY Number
4029 ,p_working_days_iv_id OUT NOCOPY Number
4030 ,p_protected_days_iv_id OUT NOCOPY Number
4031 ,p_main_rate_defualt_value OUT NOCOPY Number
4032 ,p_protected_rate_defualt_value OUT NOCOPY Number
4033 ) is
4034 l_d date;
4035 l_n number;
4036 l_v varchar2(90);
4037 l_accrual_plan_id number := p_accrual_plan_id;
4038 begin
4039
4040 get_accrual_plan_info(
4041 p_accrual_plan_id => l_accrual_plan_id
4042 ,p_element_entry_id => l_n
4043 ,p_accrual_date => l_d
4044 ,p_accrual_year_start => l_d
4045 ,p_accrual_year_end => l_d
4046 ,p_accrual_start_month => l_n
4047 ,p_entitlement_offset => l_n
4051 ,p_accounting_method => l_v
4048 ,p_entitlement_duration => l_n
4049 ,p_working_days => p_main_rate_defualt_value
4050 ,p_protected_days => p_protected_rate_defualt_value
4052 ,p_ent_accrual_date_iv_id => l_n
4053 ,p_ent_reference_sal_iv_id => l_n
4054 ,p_ent_reference_days_iv_id => l_n
4055 ,p_ent_m_iv_id => l_n
4056 ,p_ent_p_iv_id => l_n
4057 ,p_ent_c_iv_id => l_n
4058 ,p_ent_s_iv_id => l_n
4059 ,p_ent_y_iv_id => l_n
4060 ,p_ent_acp_iv_id => l_n
4061 ,p_obs_accrual_date_iv_id => l_n
4062 ,p_obs_m_iv_id => l_n
4063 ,p_obs_p_iv_id => l_n
4064 ,p_obs_c_iv_id => l_n
4065 ,p_obs_s_iv_id => l_n
4066 ,p_obs_y_iv_id => l_n
4067 ,p_obs_acp_iv_id => l_n
4068 ,p_adj_accrual_date_iv_id => l_n
4069 ,p_adj_m_iv_id => l_n
4070 ,p_adj_p_iv_id => l_n
4071 ,p_adj_c_iv_id => l_n
4072 ,p_adj_s_iv_id => l_n
4073 ,p_adj_y_iv_id => l_n
4074 ,p_adj_acp_iv_id => l_n
4075 ,p_main_holiday_acc_plan_id => l_n
4076 ,p_accrual_plan_element_id => p_accrual_plan_element_id
4077 ,p_holiday_element_id => l_n
4078 ,p_working_days_iv_id => p_working_days_iv_id
4079 ,p_protected_days_iv_id => p_protected_days_iv_id
4080 ,p_business_group_id => l_n
4081 ,p_ent_element_id => l_n
4082 ,P_obs_element_id => l_n
4083 ,P_adj_element_id => l_n);
4084 --
4085 --
4086 end get_accrual_plan_overrides;
4087 --
4088 -------------------------------------------------------------------------------
4089 -- FUNCTION GET_FR_LATEST_ENT_DATE FORMULA_FUNCTION
4090 -------------------------------------------------------------------------------
4091 function get_fr_latest_ent_date
4092 (p_assignment_id IN Number
4093 ,p_accrual_plan_id IN Number
4094 ,p_effective_date IN Date /* a date in the accrual plan */
4095 ,p_latest_date OUT NOCOPY Date /* out - the latest date of storage, or null */
4096 ,p_entitlement_start_date OUT NOCOPY Date /* out - the ent start relative to effective_date */
4097 ,p_accrual_start_date OUT NOCOPY Date /* out - the accrual start relative to effective_date */
4098 ,p_accrual_end_date OUT NOCOPY Date ) /* out - the accrual end relative to effective_date */
4099 return number is
4100
4101 l_accrual_start_date Date;
4102 l_accrual_end_date Date;
4103 l_ent_accrual_date_iv_id Number;
4104 l_accrual_plan_id Number := p_accrual_plan_id;
4105 l_unused_char Varchar2(30);
4106 l_unused_number Number;
4107 l_entitlement_offset Number;
4108 l_not_found_date Date := to_date('01-01-0001 00:00:00','dd-mm-yyyy hh24:mi:ss');
4109 l_latest_date Date;
4110 l_proc VARCHAR2(72) := g_package||' get_fr_latest_ent_date ';
4111 --
4112 CURSOR csr_latest_ent_date (p_ent_accrual_date_iv_id in number, p_Accrual_start_date in date, p_accrual_end_date in date) is
4113 select max(pee.effective_end_Date)
4114 from pay_element_entry_values_f pevd
4115 ,pay_element_entries_f pee
4116 where pevd.input_value_id = p_ent_accrual_date_iv_id
4117 and pee.element_entry_id = pevd.element_entry_id
4118 and pevd.screen_entry_value between fnd_date.date_to_canonical(p_accrual_start_date)
4119 and fnd_date.date_to_canonical(p_accrual_end_Date)
4120 and pee.assignment_id = p_assignment_id;
4121 --
4122 BEGIN
4123 hr_utility.set_location('Entering ' || l_proc,10);
4124 --
4125 -- Get input variables and plan dates
4126 --
4127 get_accrual_plan_data(
4128 p_accrual_plan_id => l_accrual_plan_id
4129 ,p_accrual_date => p_effective_date
4130 ,p_accrual_year_start => l_accrual_start_date
4131 ,p_accrual_year_end => l_accrual_end_date
4132 ,p_accounting_method => l_unused_char
4133 ,p_entitlement_offset => l_entitlement_offset
4134 ,p_ent_ref_days_id => l_unused_number
4135 ,p_ent_ref_salary_id => l_unused_number
4136 ,p_ent_accrual_date_iv_id => l_ent_accrual_date_iv_id
4137 ,p_holiday_element_id => l_unused_number);
4138 --
4139 hr_utility.set_location('Step ' || l_proc,30);
4140 open csr_latest_ent_date (l_ent_accrual_date_iv_id, l_accrual_start_date, l_accrual_end_date );
4141 fetch csr_latest_ent_date into p_latest_date;
4142
4143 if p_latest_date is null THEN
4144 close csr_latest_ent_date;
4145 p_latest_date := l_not_found_date;
4146 end if;
4147 p_accrual_end_date := l_accrual_end_date;
4148 p_accrual_start_date := l_accrual_start_date;
4149 p_entitlement_start_date := add_months(p_accrual_start_date, l_entitlement_offset);
4150
4151 hr_utility.set_location('Leaving: '||l_proc,60);
4152 --
4153 return 1;
4154 end get_fr_latest_ent_date ;
4155 --
4156 -------------------------------------------------------------------------------
4157 -- GET_REFERENCE_ENTITLEMENT --
4158 -- gets the sum of main and protected days only for the regularized calculation
4159 -- ignores user adjustements ('ADJ' type)
4160 -- called from FR_GET_HOLIDAY_DETAILS
4161 -------------------------------------------------------------------------------
4162 procedure get_reference_entitlement
4163 (p_accrual_plan_id IN Number
4164 ,p_accrual_start_date IN Date
4165 ,p_accrual_end_date IN Date
4169 ,p_ent_accrual_date_iv_id IN Number default null
4166 ,p_assignment_id IN Number
4167 ,p_ent_ref_days_id IN Number default null
4168 ,p_ent_ref_salary_id IN Number default null
4170 ,p_ref_main_days OUT NOCOPY Number
4171 ,p_ref_salary OUT NOCOPY Number ) is
4172 --
4173 l_ent_ref_days_id Number := p_ent_ref_days_id;
4174 l_ent_ref_salary_id Number := p_ent_ref_salary_id;
4175 l_ent_accrual_date_iv_id Number := p_ent_accrual_date_iv_id;
4176 l_accrual_plan_id Number := p_accrual_plan_id;
4177 l_unused_date Date := null;
4178 l_unused_char Varchar2(30);
4179 l_unused_number Number;
4180 l_proc VARCHAR2(72) := g_package||' get_reference_entitlement ';
4181 --
4182 CURSOR csr_ref_entitlement (p_sal_input_id in number,p_day_input_id in number,p_date_input_id in number) is
4183 select sum(fnd_number.canonical_to_number(pevn.screen_entry_value)),
4184 sum(fnd_number.canonical_to_number(pevs.screen_entry_value))
4185 from pay_element_entry_values_f pevn
4186 ,pay_element_entry_values_f pevd
4187 ,pay_element_entry_values_f pevs
4188 ,pay_element_entries_f pee
4189 where pevn.input_value_id = p_day_input_id
4190 and pevd.input_value_id = p_date_input_id
4191 and pevs.input_value_id = p_sal_input_id
4192 and pee.element_entry_id = pevn.element_entry_id
4193 and pee.element_entry_id = pevs.element_entry_id
4194 and pee.element_entry_id = pevd.element_entry_id
4195 and pevd.screen_entry_value between fnd_date.date_to_canonical(p_accrual_start_date)
4196 and fnd_date.date_to_canonical(p_accrual_end_Date)
4197 and pee.assignment_id = p_assignment_id;
4198
4199 l_fr_plan_info g_fr_plan_info;
4200
4201 BEGIN
4202 hr_utility.set_location('Entering ' || l_proc,10);
4203 --
4204 -- Ensure correct globals are set
4205 --
4206 p_ref_main_days := 0;
4207 p_ref_salary := 0;
4208
4209 if l_ent_ref_days_id is null then
4210
4211 l_fr_plan_info := get_fr_accrual_plan_info(
4212 p_accrual_plan_id => l_accrual_plan_id
4213 ,p_accrual_date => p_accrual_start_date);
4214
4215 l_ent_ref_days_id := l_fr_plan_info.ent_reference_days_iv_id;
4216 l_ent_ref_salary_id := l_fr_plan_info.ent_reference_sal_iv_id;
4217 l_ent_accrual_date_iv_id := l_fr_plan_info.ent_accrual_date_iv_id;
4218 end if;
4219
4220 hr_utility.set_location('IN REF ENTITLEMENT',10);
4221 hr_utility.set_location('l_ent_ref_salary_id ',l_ent_ref_salary_id );
4222 hr_utility.set_location('l_ent_ref_days_id',l_ent_ref_days_id);
4223 hr_utility.set_location('l_ent_accrual_date_iv_id',l_ent_accrual_date_iv_id);
4224 hr_utility.set_location('p_accrual_start_date' || p_accrual_start_date,10);
4225 hr_utility.set_location('p_accrual_end_date'|| p_accrual_end_date,10);
4226 hr_utility.set_location('p_assignment_id', p_assignment_id);
4227 hr_utility.set_location('Step ' || l_proc,30);
4228
4229 open csr_ref_entitlement ( l_ent_ref_salary_id, l_ent_ref_days_id, l_ent_accrual_date_iv_id );
4230 fetch csr_ref_entitlement into p_ref_main_days, p_ref_salary;
4231 close csr_ref_entitlement;
4232
4233 hr_utility.set_location('p_ref_main_days ', p_ref_main_days);
4234 hr_utility.set_location('p_ref_salary ' ,p_ref_salary);
4235
4236 --fnd_file.put_line(fnd_file.log,'Leaving ' || l_proc);
4237 --
4238 hr_utility.set_location('Leaving: '||l_proc,50);
4239 end get_reference_entitlement;
4240 -------------------------------------------------------------------------------
4241 -- GET_ACCRUAL_PLAN_DATA
4242 -------------------------------------------------------------------------------
4243 procedure get_accrual_plan_data(
4244 p_accrual_plan_id IN OUT NOCOPY number
4245 ,p_element_entry_id IN number default null
4246 ,p_accrual_date IN date default null
4247 ,p_accrual_year_start OUT NOCOPY date
4248 ,p_accrual_year_end OUT NOCOPY date
4249 ,p_accounting_method OUT NOCOPY varchar2
4250 ,p_entitlement_offset OUT NOCOPY number
4251 ,p_ent_ref_days_id OUT NOCOPY number
4252 ,p_ent_ref_salary_id OUT NOCOPY number
4253 ,p_ent_accrual_date_iv_id OUT NOCOPY Number
4254 ,p_holiday_element_id OUT NOCOPY Number) is
4255
4256 l_d date;
4257 l_n number;
4258 l_v varchar2(90);
4259 l_accrual_plan_id number := p_accrual_plan_id;
4260 l_proc VARCHAR2(72) := g_package||' get_accrual_plan_data ';
4261 begin
4262
4263 get_accrual_plan_info(
4264 p_accrual_plan_id => l_accrual_plan_id
4265 ,p_element_entry_id => p_element_entry_id
4269 ,p_accrual_start_month => l_n
4266 ,p_accrual_date => p_accrual_date
4267 ,p_accrual_year_start => p_accrual_year_start
4268 ,p_accrual_year_end => p_accrual_year_end
4270 ,p_entitlement_offset => p_entitlement_offset
4271 ,p_entitlement_duration => l_n
4272 ,p_working_days => l_n
4273 ,p_protected_days => l_n
4274 ,p_accounting_method => p_accounting_method
4275 ,p_ent_accrual_date_iv_id => p_ent_accrual_date_iv_id
4276 ,p_ent_reference_sal_iv_id => p_ent_ref_salary_id
4277 ,p_ent_reference_days_iv_id => p_ent_ref_days_id
4278 ,p_ent_m_iv_id => l_n
4279 ,p_ent_p_iv_id => l_n
4280 ,p_ent_c_iv_id => l_n
4281 ,p_ent_s_iv_id => l_n
4282 ,p_ent_y_iv_id => l_n
4283 ,p_ent_acp_iv_id => l_n
4284 ,p_obs_accrual_date_iv_id => l_n
4285 ,p_obs_m_iv_id => l_n
4286 ,p_obs_p_iv_id => l_n
4287 ,p_obs_c_iv_id => l_n
4288 ,p_obs_s_iv_id => l_n
4289 ,p_obs_y_iv_id => l_n
4290 ,p_obs_acp_iv_id => l_n
4291 ,p_adj_accrual_date_iv_id => l_n
4292 ,p_adj_m_iv_id => l_n
4293 ,p_adj_p_iv_id => l_n
4294 ,p_adj_c_iv_id => l_n
4295 ,p_adj_s_iv_id => l_n
4296 ,p_adj_y_iv_id => l_n
4297 ,p_adj_acp_iv_id => l_n
4298 ,p_main_holiday_acc_plan_id => l_n
4299 ,p_holiday_element_id => p_holiday_element_id
4300 ,p_accrual_plan_element_id => l_n
4301 ,p_working_days_iv_id => l_n
4302 ,p_protected_days_iv_id => l_n
4303 ,p_business_Group_id => l_n
4304 ,p_ent_element_id => l_n
4305 ,P_obs_element_id => l_n
4306 ,P_adj_element_id => l_n);
4307 --
4308 p_accrual_plan_id := l_accrual_plan_id;
4309 --
4310 hr_utility.set_location('Leaving: '||l_proc,50);
4311 end get_accrual_plan_data;
4312 --
4313 -------------------------------------------------------------------------------
4314 -- Get_Payment_info
4315 -------------------------------------------------------------------------------
4316 procedure get_payment_info(
4317 p_days_input_id OUT NOCOPY number
4318 ,p_protected_days_input_id OUT NOCOPY number
4319 ,p_element_type_id OUT NOCOPY number
4320 ,p_absence_input_id OUT NOCOPY Number) is
4321
4322 CURSOR csr_input_values is
4323 select piv1.input_value_id
4324 ,piv2.input_value_id
4325 ,piv3.input_value_id
4326 ,pet.element_type_id
4327 from pay_element_types_f pet
4328 ,pay_input_values_f piv1
4329 ,pay_input_values_f piv2
4330 ,pay_input_values_f piv3
4331 where piv1.element_Type_id = pet.element_type_id
4332 and piv2.element_Type_id = pet.element_type_id
4333 and piv3.element_Type_id = pet.element_type_id
4334 and pet.legislation_code = 'FR'
4335 -- and piv1.legislation_code = 'FR'
4336 -- and piv2.legislation_code = 'FR'
4337 -- and piv3.legislation_code = 'FR'
4338 and pet.business_group_id is null
4339 and piv1.business_group_id is null
4340 and piv2.business_group_id is null
4341 and piv3.business_group_id is null
4342 and pet.element_name = 'FR_HOLIDAY_PAY'
4343 and piv1.name = 'Rate'
4344 and piv2.name = 'Protected Days Paid'
4345 and piv3.name = 'Absence Attendance ID';
4346
4347 -- /* legislation comments*/
4348 --
4349 l_proc VARCHAR2(72) := g_package||' get_payment_info ';
4350 BEGIN
4351 hr_utility.set_location('Entering ' || l_proc,10);
4352 open csr_input_values;
4353 fetch csr_input_values into p_days_input_id, p_protected_days_input_id, p_absence_input_id, p_element_type_id;
4354 close csr_input_values;
4355 hr_utility.set_location('Leaving: '||l_proc,50);
4356 END get_payment_info;
4357 --
4358 -------------------------------------------------------------------------------
4359 -- GET_PREVIOUS_HOLIDAY_ABSENCE
4360 -------------------------------------------------------------------------------
4361 procedure get_previous_holiday_absence(
4362 p_absence_attendance_id IN Number
4363 ,p_assignment_id IN Number
4364 ,p_paid_element_type_id IN Number default null
4365 ,p_days_input_id IN Number default null
4366 ,p_protected_days_input_id IN Number default null
4367 ,p_absence_attendance_input_ID IN Number default null
4368 ,p_total_days_paid OUT NOCOPY Number
4369 ,p_protected_days_paid OUT NOCOPY Number ) is
4370 --
4371 l_paid_element_type_id Number := p_paid_element_type_id;
4372 l_days_input_id Number := p_days_input_id;
4373 l_protected_days_input_id Number := p_protected_days_input_id;
4374 l_absence_attendance_input_ID Number := p_absence_attendance_input_ID;
4375 l_proc VARCHAR2(72) := g_package||' get_previous_holiday_absence ';
4376 l_fr_pay_info g_fr_pay_info;
4377 l_fr_pay_r_info g_fr_pay_info;
4378 l_total_days_paid Number;
4379 l_protected_days_paid Number;
4380 l_start_date Date;
4381 --
4382 -- The payment element is seeded; it will always contain the protected days element regardless of the
4386 --
4383 -- plan type, however the prrv entry for protected may not exist.
4384 --
4385 -- handles all paid absence attendance ids
4387 CURSOR csr_previous_payments (l_days_input_id number ,l_assignment_id number
4388 ,l_absence_attendance_id number ,l_protected_days_input_id number
4389 ,l_paid_element_type_id number, l_absence_attendance_input_ID number
4390 ,l_start_date date) is
4391 select sum(decode(prrvm.input_value_id,l_days_input_id, prrvm.result_value))
4392 ,sum(decode(prrvm.input_value_id,l_protected_days_input_id, prrvm.result_value))
4393 from pay_run_result_values prrvm
4394 ,pay_run_result_values prrva
4395 ,pay_run_results prr
4396 ,pay_assignment_actions paa
4397 ,pay_payroll_actions ppa
4398 where prrvm.run_result_id = prr.run_result_id
4399 and prrva.run_result_id = prr.run_result_id
4400 and prrvm.input_value_id in(l_days_input_id, l_protected_days_input_id)
4401 and prrva.input_value_id = l_absence_attendance_input_id
4402 and prrva.result_value = l_absence_attendance_id
4403 and prr.assignment_action_id = paa.assignment_action_id
4404 and prr.element_type_id = l_paid_element_type_id
4405 and prr.status in ('P','PA')
4406 and paa.payroll_action_id = ppa.payroll_Action_id
4407 and ppa.effective_date >= l_start_date
4408 and paa.assignment_id = l_assignment_id;
4409
4410 /* fetch from before the absence started */
4411 cursor csr_start_date is
4412 select date_start - 366
4413 from per_absence_attendances
4414 where absence_attendance_id = p_absence_attendance_id;
4415
4416 BEGIN
4417
4418 hr_utility.set_location('Entering ' || l_proc,10);
4419 --
4420 -- If necessary fetch the input values that hold the number of days / protected days paid.
4421 --
4422 if p_days_input_id is null then
4423 l_fr_pay_info := get_payment_globals;
4424 end if;
4425 --
4426 open csr_start_date;
4427 fetch csr_start_date into l_start_date;
4428 close csr_start_date;
4429 hr_utility.trace('start_date is ' || to_char(l_start_date,'dd-mm-yyyy'));
4430 --
4431 open csr_previous_payments(l_fr_pay_info.pay_total_days_input_ID, p_assignment_id, p_absence_attendance_id
4432 ,l_fr_pay_info.pay_protected_days_input_ID, l_fr_pay_info.pay_element_id
4433 ,l_fr_pay_info.pay_abs_attend_input_id, l_start_date);
4434 fetch csr_previous_payments into p_total_days_paid, p_protected_days_paid;
4435 close csr_previous_payments;
4436
4437 p_total_days_paid := nvl(p_total_days_paid, 0);
4438 p_protected_days_paid := nvl(p_protected_days_paid, 0);
4439
4440 -- also check for retro results for the same
4441 open csr_previous_payments(l_fr_pay_r_info.pay_total_days_input_ID, p_assignment_id, p_absence_attendance_id
4442 ,l_fr_pay_r_info.pay_protected_days_input_ID, l_fr_pay_r_info.pay_element_id
4443 ,l_fr_pay_r_info.pay_abs_attend_input_id ,l_start_date);
4444 fetch csr_previous_payments into l_total_days_paid, l_protected_days_paid;
4445 close csr_previous_payments;
4446
4447 p_total_days_paid := nvl(p_total_days_paid, 0) + nvl(l_total_days_paid,0);
4448 p_protected_days_paid := nvl(p_protected_days_paid, 0) + nvl(l_protected_days_paid,0);
4449
4450 hr_utility.trace('get_previous_absence_paid p_absence_attendance_id is ' || to_char(p_absence_attendance_id));
4451 hr_utility.trace('p_total_days_paid is ' || to_char(p_total_days_paid));
4452 hr_utility.trace('p_protected_days_paid is ' || to_char(p_protected_days_paid));
4453 --fnd_file.put_line(fnd_file.log,'pay_total_days_input_ID is ' || to_char(l_fr_pay_info.pay_total_days_input_ID));
4454 --fnd_file.put_line(fnd_file.log,'pay_protected_days_input_ID is ' || to_char(l_fr_pay_info.pay_protected_days_input_ID));
4455 --fnd_file.put_line(fnd_file.log,'l_pay_element_id is ' || to_char(l_fr_pay_info.pay_element_id));
4456 --fnd_file.put_line(fnd_file.log,'p_assignment_id is ' || to_char(p_assignment_id));
4457 --fnd_file.put_line(fnd_file.log,'p_total_days_paid is ' || to_char(p_total_days_paid));
4458 --fnd_file.put_line(fnd_file.log,'p_protected_days_paid is ' || to_char(p_protected_days_paid));
4459 hr_utility.set_location('Leaving: '||l_proc,50);
4460 end get_previous_holiday_absence;
4461 --
4462 -------------------------------------------------------------------------------
4463 -- GET_ACCRUAL_PLAN_INFO
4464 -------------------------------------------------------------------------------
4465 procedure get_accrual_plan_info(
4466 p_accrual_plan_id IN OUT NOCOPY number
4467 ,p_element_entry_id IN number default null
4468 ,p_accrual_date IN date default null
4469 ,p_accrual_year_start OUT NOCOPY date
4470 ,p_accrual_year_end OUT NOCOPY date
4471 ,p_accrual_start_month OUT NOCOPY number
4472 ,p_entitlement_offset OUT NOCOPY number
4473 ,p_entitlement_duration OUT NOCOPY number
4474 ,p_working_days OUT NOCOPY Number
4475 ,p_protected_days OUT NOCOPY Number
4476 ,p_accounting_method OUT NOCOPY Varchar2
4477 ,p_ent_accrual_date_iv_id OUT NOCOPY number
4478 ,p_ent_reference_sal_iv_id OUT NOCOPY number
4479 ,p_ent_reference_days_iv_id OUT NOCOPY number
4480 ,p_ent_m_iv_id OUT NOCOPY number
4481 ,p_ent_p_iv_id OUT NOCOPY number
4482 ,p_ent_c_iv_id OUT NOCOPY number
4483 ,p_ent_s_iv_id OUT NOCOPY number
4484 ,p_ent_y_iv_id OUT NOCOPY number
4485 ,p_ent_acp_iv_id OUT NOCOPY Number
4486 ,p_obs_accrual_date_iv_id OUT NOCOPY number
4487 ,p_obs_m_iv_id OUT NOCOPY number
4488 ,p_obs_p_iv_id OUT NOCOPY number
4489 ,p_obs_c_iv_id OUT NOCOPY number
4490 ,p_obs_s_iv_id OUT NOCOPY number
4494 ,p_adj_m_iv_id OUT NOCOPY number
4491 ,p_obs_y_iv_id OUT NOCOPY number
4492 ,p_obs_acp_iv_id OUT NOCOPY Number
4493 ,p_adj_accrual_date_iv_id OUT NOCOPY number
4495 ,p_adj_p_iv_id OUT NOCOPY number
4496 ,p_adj_c_iv_id OUT NOCOPY number
4497 ,p_adj_s_iv_id OUT NOCOPY number
4498 ,p_adj_y_iv_id OUT NOCOPY number
4499 ,p_adj_acp_iv_id OUT NOCOPY Number
4500 ,p_main_holiday_acc_plan_id OUT NOCOPY number
4501 ,p_holiday_element_id OUT NOCOPY Number
4502 ,p_accrual_plan_element_id OUT NOCOPY Number
4503 ,p_working_days_iv_id OUT NOCOPY Number
4504 ,p_protected_days_iv_id OUT NOCOPY Number
4505 ,p_business_Group_id OUT NOCOPY Number
4506 ,p_ent_element_id OUT NOCOPY Number
4507 ,P_obs_element_id OUT NOCOPY Number
4508 ,P_adj_element_id OUT NOCOPY Number) is
4509
4510
4511 CURSOR csr_plan_input (p_element_type_id in number) is
4512 select piv1.input_value_id acp_plan_id
4513 from pay_input_values_f piv1
4514 where piv1.element_type_id = p_element_type_id
4515 and piv1.display_sequence = 10;
4516
4517 CURSOR csr_reference_inputs (p_ent_accrual_date_iv in number) is
4518 select piv1.input_value_id reference_salary
4519 ,piv2.input_value_id reference_days
4520 from pay_input_values_f piv1
4521 ,pay_input_values_f piv2
4522 ,pay_input_values_f piv
4523 where piv1.element_type_id = piv2.element_type_id
4524 and piv1.element_type_id = piv.element_type_id
4525 and piv.input_value_id = p_ent_accrual_date_iv
4526 and piv1.display_sequence = 80
4527 and piv2.display_sequence = 90;
4528
4529 CURSOR csr_plan_info (p_accrual_plan_id in Number) is
4530 select nvl(pap.information1,6) accrual_start_month
4531 ,pap.information2 entitlement_offset
4532 ,pap.information3 entitlement_duration
4533 ,pap.information4 working_days
4534 ,pap.information5 protected_days
4535 ,pap.information6 accounting_method
4536 ,pap.information7 main_holiday_acc_plan_id
4537 ,pap.information8 ent_m_iv_id
4538 ,pap.information9 ent_p_iv_id
4539 ,pap.information10 ent_c_iv_id
4540 ,pap.information11 ent_s_iv_id
4541 ,pap.information12 ent_y_iv_id
4542 ,pap.information13 obs_m_iv_id
4543 ,pap.information14 obs_p_iv_id
4544 ,pap.information15 obs_c_iv_id
4545 ,pap.information16 obs_s_iv_id
4546 ,pap.information17 obs_y_iv_id
4547 ,pap.information18 adj_m_iv_id
4548 ,pap.information19 adj_p_iv_id
4549 ,pap.information20 adj_c_iv_id
4550 ,pap.information21 adj_s_iv_id
4551 ,pap.information22 adj_y_iv_id
4552 ,pap.information23 ent_accrual_date_iv_id
4553 ,pap.information24 obs_accrual_date_iv_id
4554 ,pap.information25 adj_accrual_date_iv_id
4555 ,pap.information26 working_days_iv_id
4556 ,pap.information27 protected_days_iv_id
4557 ,pap.accrual_plan_element_type_id accrual_plan_element_id
4558 ,piv.element_type_id holiday_element_id
4559 ,pivE.element_type_id ENT_element_id
4560 ,pivO.element_type_id OBS_element_id
4561 ,pivA.element_type_id ADJ_element_id
4562 ,pap.business_group_id business_Group_id
4563 from pay_accrual_plans pap
4564 ,pay_input_values_f piv
4565 ,pay_input_values_f pivE
4566 ,pay_input_values_f pivO
4567 ,pay_input_values_f pivA
4568 where pap.accrual_plan_id = p_accrual_plan_id
4569 and piv.input_value_id = pap.pto_input_value_id
4570 and pivE.input_value_id = pap.information8
4571 and pivO.input_value_id = pap.information13
4572 and pivA.input_value_id = pap.information18;
4573
4574 CURSOR csr_plan_info_ee (c_element_entry_id in number) is
4575 select pap.information1 accrual_start_month
4576 ,pap.information2 entitlement_offset
4577 ,pap.information3 entitlement_duration
4578 ,pap.information4 working_days
4579 ,pap.information5 protected_days
4580 ,pap.information6 accounting_method
4581 ,pap.information7 main_holiday_acc_plan_id
4582 ,pap.information8 ent_m_iv_id
4583 ,pap.information9 ent_p_iv_id
4584 ,pap.information10 ent_c_iv_id
4585 ,pap.information11 ent_s_iv_id
4586 ,pap.information12 ent_y_iv_id
4587 ,pap.information13 obs_m_iv_id
4588 ,pap.information14 obs_p_iv_id
4589 ,pap.information15 obs_c_iv_id
4590 ,pap.information16 obs_s_iv_id
4591 ,pap.information17 obs_y_iv_id
4592 ,pap.information18 adj_m_iv_id
4593 ,pap.information19 adj_p_iv_id
4594 ,pap.information20 adj_c_iv_id
4595 ,pap.information21 adj_s_iv_id
4596 ,pap.information22 adj_y_iv_id
4597 ,pap.information23 ent_accrual_date_iv_id
4598 ,pap.information24 obs_accrual_date_iv_id
4599 ,pap.information25 adj_accrual_date_iv_id
4600 ,pap.accrual_plan_element_type_id accrual_plan_element_id
4601 ,pap.accrual_plan_id accrual_plan_id
4602 ,pap.information26 working_days_iv_id
4603 ,pap.information27 protected_days_iv_id
4604 ,piv.element_Type_id holiday_element_id
4605 ,pivE.element_type_id ENT_element_id
4606 ,pivO.element_type_id OBS_element_id
4607 ,pivA.element_type_id ADJ_element_id
4608 ,pap.business_group_id business_Group_id
4609 from pay_accrual_plans pap
4610 ,per_absence_attendances paa
4611 ,per_absence_attendance_types pat
4612 ,pay_element_entries_f pee
4613 ,pay_input_values_f piv
4617 where paa.absence_attendance_type_id = pat.absence_attendance_type_id
4614 ,pay_input_values_f pivE
4615 ,pay_input_values_f pivO
4616 ,pay_input_values_f pivA
4618 and pivE.input_value_id = pap.information8
4619 and pivO.input_value_id = pap.information13
4620 and pivA.input_value_id = pap.information18
4621 and pat.input_value_id = pap.pto_input_value_id
4622 and paa.absence_Attendance_id = pee.creator_id
4623 and pee.creator_type = 'A'
4624 and piv.input_value_id = pap.pto_input_value_id
4625 and pee.element_entry_id = c_element_entry_id;
4626
4627 rec_plan_info csr_plan_info%ROWTYPE;
4628 rec_plan_info_ee csr_plan_info_ee%ROWTYPE;
4629 rec_reference_inputs csr_reference_inputs%ROWTYPE;
4630 l_asat_month number;
4631 l_add_months number := 0;
4632 temp_ent_accrual_date_iv_id number := 0;
4633 temp_accrual_start_month number := 0;
4634 l_proc VARCHAR2(72) := g_package||' get_accrual_plan_inf0 ';
4635 BEGIN
4636 hr_utility.set_location('Entering ' || l_proc,10);
4637 IF p_accrual_plan_id is not null THEN
4638 open csr_plan_info(p_accrual_plan_id);
4639 fetch csr_plan_info into rec_plan_info;
4640 close csr_plan_info;
4641 p_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info.accrual_start_month);
4642 p_entitlement_offset := fnd_number.canonical_to_number(rec_plan_info.entitlement_offset);
4643 p_entitlement_duration := fnd_number.canonical_to_number(rec_plan_info.entitlement_duration);
4644 p_working_days := fnd_number.canonical_to_number(rec_plan_info.working_days);
4645 p_protected_days := fnd_number.canonical_to_number(rec_plan_info.protected_days);
4646 p_accounting_method := rec_plan_info.accounting_method;
4647 p_ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
4648 p_ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
4649 p_ent_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_m_iv_id);
4650 p_ent_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_p_iv_id);
4651 p_ent_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_c_iv_id);
4652 p_ent_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_s_iv_id);
4653 p_ent_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.ent_y_iv_id);
4654 p_obs_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_accrual_date_iv_id);
4655 p_obs_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_m_iv_id);
4656 p_obs_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_p_iv_id);
4657 p_obs_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_c_iv_id);
4658 p_obs_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_s_iv_id);
4659 p_obs_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.obs_y_iv_id);
4660 p_adj_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_accrual_date_iv_id);
4661 p_adj_m_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_m_iv_id);
4662 p_adj_p_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_p_iv_id);
4663 p_adj_c_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_c_iv_id);
4664 p_adj_s_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_s_iv_id);
4665 p_adj_y_iv_id := fnd_number.canonical_to_number(rec_plan_info.adj_y_iv_id);
4666 p_main_holiday_acc_plan_id := fnd_number.canonical_to_number(rec_plan_info.main_holiday_acc_plan_id);
4667 p_holiday_element_id := rec_plan_info.holiday_element_id;
4668 p_business_group_id := rec_plan_info.business_Group_id;
4669 temp_ent_accrual_date_iv_id:= fnd_number.canonical_to_number(rec_plan_info.ent_accrual_date_iv_id);
4670 p_accrual_plan_element_id := rec_plan_info.accrual_plan_element_id;
4671 p_working_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.working_days_iv_id);
4672 p_protected_days_iv_id := fnd_number.canonical_to_number(rec_plan_info.protected_days_iv_id);
4673 p_ent_element_id := rec_plan_info.ENT_element_id;
4674 p_obs_element_id := rec_plan_info.OBS_element_id;
4675 p_adj_element_id := rec_plan_info.ADJ_element_id;
4676 temp_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info.accrual_start_month);
4677 ELSE
4678 open csr_plan_info_ee(p_element_entry_id);
4679 fetch csr_plan_info_ee into rec_plan_info_ee;
4680 close csr_plan_info_ee;
4681 p_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info_ee.accrual_start_month);
4682 p_entitlement_offset := fnd_number.canonical_to_number(rec_plan_info_ee.entitlement_offset);
4683 p_entitlement_duration := fnd_number.canonical_to_number(rec_plan_info_ee.entitlement_duration);
4684 p_working_days := fnd_number.canonical_to_number(rec_plan_info_ee.working_days);
4685 p_protected_days := fnd_number.canonical_to_number(rec_plan_info_ee.protected_days);
4686 p_accounting_method := rec_plan_info_ee.accounting_method;
4687 p_ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
4688 p_ent_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
4689 p_ent_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_m_iv_id);
4690 p_ent_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_p_iv_id);
4691 p_ent_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_c_iv_id);
4692 p_ent_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_s_iv_id);
4693 p_ent_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.ent_y_iv_id);
4694 p_obs_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_accrual_date_iv_id);
4695 p_obs_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_m_iv_id);
4699 p_obs_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_y_iv_id);
4696 p_obs_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_p_iv_id);
4697 p_obs_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_c_iv_id);
4698 p_obs_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.obs_s_iv_id);
4700 p_adj_accrual_date_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_accrual_date_iv_id);
4701 p_adj_m_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_m_iv_id);
4702 p_adj_p_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_p_iv_id);
4703 p_adj_c_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_c_iv_id);
4704 p_adj_s_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_s_iv_id);
4705 p_adj_y_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.adj_y_iv_id);
4706 p_main_holiday_acc_plan_id := fnd_number.canonical_to_number(rec_plan_info_ee.main_holiday_acc_plan_id);
4707 p_holiday_element_id := rec_plan_info_ee.holiday_element_id;
4708 p_business_group_id := rec_plan_info.business_Group_id;
4709 p_accrual_plan_id := rec_plan_info_ee.accrual_plan_id;
4710 p_accrual_plan_element_id := rec_plan_info_ee.accrual_plan_element_id;
4711 p_working_days_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.working_days_iv_id);
4712 p_ent_element_id := rec_plan_info.ENT_element_id;
4713 p_obs_element_id := rec_plan_info.OBS_element_id;
4714 p_adj_element_id := rec_plan_info.ADJ_element_id;
4715 p_protected_days_iv_id := fnd_number.canonical_to_number(rec_plan_info_ee.protected_days_iv_id);
4716 temp_ent_accrual_date_iv_id:= fnd_number.canonical_to_number(rec_plan_info_ee.ent_accrual_date_iv_id);
4717 temp_accrual_start_month := fnd_number.canonical_to_number(rec_plan_info_ee.accrual_start_month);
4718 END IF;
4719 --
4720 open csr_reference_inputs (temp_ent_accrual_date_iv_id);
4721 fetch csr_reference_inputs into rec_reference_inputs;
4722 close csr_reference_inputs;
4723 --
4724 --
4725 -- Get the plan dates, if p_accrual_date is not null
4726 --
4727 hr_utility.set_location('p_accrual_date is ' || p_accrual_date, 20);
4728
4729 IF p_accrual_date is not null then
4730 l_asat_month := to_number(to_char(p_accrual_date, 'mm'));
4731 hr_utility.set_location('l_asat_month is ' || l_asat_month, 30);
4732 hr_utility.set_location('temp_accrual_start_month is ' || temp_accrual_start_month, 40);
4733 if l_asat_month < temp_accrual_start_month then
4734 hr_utility.set_location('Step ', 40);
4735 l_add_months := -12;
4736 end if;
4737 p_accrual_year_start := to_date('01-' || temp_accrual_start_month || '-'
4738 || to_char(add_months(p_accrual_date,l_add_months), 'yyyy') || ' 00:00:00'
4739 , 'dd-mm-yyyy hh24:mi:ss');
4740 p_accrual_year_end := add_months(p_accrual_year_start - 1,12);
4741 end if;
4742
4743 hr_utility.set_location('p_accrual_date is ' || p_accrual_date, 50);
4744 hr_utility.set_location('p_accrual_year_start is ' || p_accrual_year_start, 51);
4745 hr_utility.set_location('p_accrual_year_end is ' || p_accrual_year_end, 52);
4746
4747
4748 p_ent_reference_sal_iv_id := rec_reference_inputs.reference_salary;
4749 p_ent_reference_days_iv_id := rec_reference_inputs.reference_days;
4750
4751 open csr_plan_input (p_ent_element_id);
4752 fetch csr_plan_input into p_ent_acp_iv_id;
4753 close csr_plan_input;
4754 open csr_plan_input (p_obs_element_id);
4755 fetch csr_plan_input into p_obs_acp_iv_id;
4756 close csr_plan_input;
4757 open csr_plan_input (p_adj_element_id);
4758 fetch csr_plan_input into p_adj_acp_iv_id;
4759 close csr_plan_input;
4760 hr_utility.set_location('Leaving: '||l_proc,50);
4761 --
4765 --------------------------------------------------------------------------*/
4762 end get_accrual_plan_info;
4763 /* ===========================================================================
4764 Name : Get_fr_holiday_details FORMULA_FUNCTION
4766 function Get_fr_holiday_details
4767 (P_ELEMENT_ENTRY_ID IN Number
4768 ,p_date_earned IN Date
4769 ,p_prorate_end IN Date /* the proration period end date - may be null */
4770 ,P_Absence_attendance_ID OUT NOCOPY Number /* Identifier of the Absence Record */
4771 ,P_accrual_plan_id OUT NOCOPY Number /* Identifier of the Accrual plan */
4775 ,P_total_Main_Days OUT NOCOPY Number /* keyed absence ddf main days in whole absence */
4772 ,P_Entry_Start_Date OUT NOCOPY Date /* The element entry start date of the keyed absence */
4773 ,P_Entry_End_Date OUT NOCOPY Date /* The element entry end date of the keyed absence */
4774 ,P_Date_Accrued OUT NOCOPY Date /* keyed absence ddf accrued date */
4776 ,P_total_Seniority_Days OUT NOCOPY Number /* keyed absence ddf seniority days in whole absence */
4777 ,P_total_Young_Mothers_Days OUT NOCOPY Number /* keyed absence ddf YM days in whole absence */
4778 ,P_total_Conventional_Days OUT NOCOPY Number /* keyed absence ddf Conventional days in whole absence */
4779 ,P_total_Protected_Days OUT NOCOPY Number /* keyed absence ddf Protected days in whole absence */
4780 ,P_taken_total_days OUT NOCOPY Number /* total days paid for this absence in previous periods */
4781 ,P_taken_protected_Days OUT NOCOPY Number /* protected days paid for this absence in previous periods */
4782 ,P_proration_period OUT NOCOPY Varchar2 /* LAST - This is the last of proration period */
4783 ,p_regularize_possible OUT NOCOPY Varchar2 /* if reference values are stored (Y/N) if can do a reg payt*/
4784 ,p_session_date OUT NOCOPY Date /* the session date applicable to this session */
4785 ,p_accrue_start_date OUT NOCOPY Date /* The accrual start date, relative to the DDF date_accrued */
4786 ,p_accrue_end_date OUT NOCOPY Date /* The accrual end date, relative to the accrual start date */
4787 ,P_Assignment_id OUT NOCOPY Number /* The assignment ID owning the absence */
4788 ,p_ref_total_accrued OUT NOCOPY Number /* The total accrued in the period, for main and protected */
4789 ,p_reference_salary OUT NOCOPY Number /* The reference salary for the accrual period - if available */
4790 ,p_accounting_method OUT NOCOPY Varchar2 /* The accounting method from the accrual plan ddf */
4791 ) return number is
4792 --
4793 l_proc varchar2(72) := g_package||'Get_FR_holiday_details';
4794 -- Accrual Plan DDF
4795 -- values for the whole absence
4796 l_whole_absence_attendance_id number;
4797 l_whole_date_Accrued Date;
4798 l_whole_entry_Start_Date Date;
4799 l_whole_Entry_End_Date Date;
4800 l_whole_Main_Days Number;
4801 l_whole_seniority_Days Number;
4802 l_whole_Young_Mothers_Days Number;
4803 l_whole_Conventional_Days Number;
4804 l_whole_Protected_Days Number;
4805 l_whole_total_days Number;
4806 -- values for previous part absences
4807 l_previous_Total_Days Number := 0;
4808 l_previous_Protected_Days Number := 0;
4809 -- working variables
4810 l_to_pay_flag varchar2(30); /* is this the last proration period? */
4811 l_session_date date;
4812 l_assignment_id Number;
4813 l_regularize_possible varchar2(10);
4814 l_remaining Number := 0;
4815 l_unused Number := 0;
4816 l_days_input_id Number := 0;
4817 l_protected_days_input_id Number := 0;
4818 l_paid_element_type_id Number := 0;
4819 l_reference_days_id Number := 0;
4820 l_reference_salary_id Number := 0;
4821 l_ent_accrual_date_iv_id Number := 0;
4822 --
4823 --
4824 CURSOR csr_get_abs_detail(c_element_entry_id in number) is
4825 select pee.effective_start_date
4826 ,pee.effective_end_date
4827 ,abs.absence_attendance_id
4828 ,fnd_date.canonical_to_date(abs.abs_information1) /* date accrued */
4829 ,abs.abs_information2 /* main days */
4830 ,abs.abs_information3 /* seniority */
4831 ,abs.abs_information4 /* young mothers */
4832 ,abs.abs_information5 /* conventional days */
4833 ,abs.abs_information6 /* protected days */
4834 ,pee.assignment_id
4835 from pay_element_entries_f pee
4836 ,per_absence_attendances abs
4837 where pee.element_entry_id = c_element_entry_id
4838 and pee.creator_id = abs.absence_attendance_id;
4839 --
4840 CURSOR csr_session_date is
4841 select effective_date
4842 from fnd_sessions
4843 where session_id = USERENV('SESSIONID');
4844
4845 begin
4846 hr_utility.set_location('Entering ' || l_proc,10);
4847 --
4848 -- Fetch the effective_date
4849 --
4850 open csr_session_date;
4851 fetch csr_session_date into l_session_date;
4852 close csr_session_date;
4853 --
4854 -- Get the absence information for this absence_id
4855 --
4856 open csr_get_abs_detail(P_element_entry_id);
4857 fetch csr_get_abs_detail into l_whole_Entry_Start_Date
4858 ,l_whole_Entry_End_Date
4859 ,l_whole_Absence_attendance_ID
4860 ,l_whole_Date_Accrued
4861 ,l_whole_Main_Days
4862 ,l_whole_Protected_Days
4863 ,l_whole_Conventional_Days
4864 ,l_whole_Seniority_Days
4865 ,l_whole_Young_Mothers_Days
4866 ,l_assignment_id;
4867 close csr_get_abs_detail;
4868 hr_utility.set_location('Step ' || l_proc,30);
4869 --
4870 -- get the plan start date / end date for this accrual date in the plan.
4871 --
4872 get_accrual_plan_data(
4876 ,p_accrual_year_start => p_accrue_start_date
4873 p_element_entry_id => p_element_entry_id
4874 ,p_accrual_plan_id => p_accrual_plan_id
4875 ,p_accrual_date => l_whole_Date_Accrued
4877 ,p_accrual_year_end => p_accrue_end_date
4878 ,p_accounting_method => p_accounting_method
4879 ,p_entitlement_offset => l_unused
4880 ,p_ent_ref_days_id => l_reference_days_id
4881 ,p_ent_ref_salary_id => l_reference_salary_id
4882 ,p_ent_accrual_date_iv_id => l_ent_accrual_date_iv_id
4883 ,p_holiday_element_id => l_unused);
4884 hr_utility.set_location('Step ' || l_proc,40);
4885 --
4886 --
4887 -- Determine which proration period this releates to. This is useful in determining if any
4888 -- proration is necessary in the number of days, or if this is the last (or only)period
4889 -- then all the days should be paid (previous days paid + this period days paid = total requested days).
4890 -- This function can only return the
4891 -- If the absence happens to be the same as a whole payroll period, the prorate days are not set.
4892 -- If element entry end date = prorate_end date
4893 -- OR
4894 -- IF prorate end is null and and effective date and element entry end date is in same year / month
4895 -- then this is the last period.
4896 --
4897 hr_utility.set_location('Step ' || l_proc,50);
4898
4899 if (to_char(l_whole_entry_end_date, 'ddmmyyyy') = to_char(p_prorate_end, 'ddmmyyyy')
4900 and p_prorate_end <> to_date('47121231','yyyymmdd'))
4901 OR (p_prorate_end = to_date('47121231','yyyymmdd') and
4902 to_char(l_whole_entry_end_date, 'mmyyyy') = to_char(p_date_earned,'mmyyyy') ) THEN
4903 l_to_pay_flag := 'LAST';
4904 else
4905 l_to_pay_flag := 'OTHER';
4906 end if;
4907 --fnd_file.put_line(fnd_file.log,'l_to_pay_flag is ' || l_to_pay_flag);
4908 --
4909 -- Calculate if the accrual period has ended yet - this is needed as the regularized payment
4910 -- is only possible if the accrual period is closed and therefore the salary balance is known.
4911 --
4912
4913 if l_session_date is not null and l_session_date between p_accrue_start_date and p_accrue_end_date then
4914 l_regularize_possible := 'N';
4915 hr_utility.set_location('Step ' || l_proc,60);
4916 else
4917 l_regularize_possible := 'Y';
4918 end if;
4919 --
4920 -- If this is the LAST proration period, get the number of days already paid for this absence
4921 --
4922
4923 hr_utility.set_location('Step ' || l_proc,70);
4924 get_previous_holiday_absence(
4925 p_absence_attendance_id => l_whole_Absence_attendance_ID
4926 ,p_assignment_id => l_assignment_id
4927 ,p_total_days_paid => l_previous_total_days /* all absence types */
4928 ,p_protected_days_paid => l_previous_protected_days); /* just protected */
4929 --
4930 --fnd_file.put_line(fnd_file.log,'l_previous_total_days is ' || to_char(l_previous_total_days));
4931 --fnd_file.put_line(fnd_file.log,'l_previous_protected_days is ' || to_char(l_previous_protected_days));
4932 --fnd_file.put_line(fnd_file.log,'previous element id is ' || to_char(l_previous_protected_days));
4933 --
4934 -- If regularization is possible, get the total entitlement for main and protected stored
4935 -- for this assignment for this accrual period.
4936 --
4937 if l_regularize_possible = 'Y' then
4938 hr_utility.set_location('Step ' || l_proc,80);
4939 get_reference_entitlement(
4940 p_accrual_plan_id => p_accrual_plan_id
4941 ,p_accrual_start_date => p_accrue_start_date
4942 ,p_accrual_end_date => p_accrue_end_date
4943 ,p_assignment_id => l_assignment_id
4944 ,p_ent_ref_days_id => l_reference_days_id
4945 ,p_ent_ref_salary_id => l_reference_salary_id
4946 ,p_ent_accrual_date_iv_id => l_ent_accrual_date_iv_id
4947 ,p_ref_main_days => p_ref_total_accrued
4948 ,p_ref_salary => p_reference_salary
4949 );
4950 if nvl(p_reference_salary,0) = 0 THEN
4951 l_regularize_possible := 'N';
4952 hr_utility.set_location('Step ' || l_proc,90);
4953 END IF;
4954 end if;
4955 --
4956 -- Set Out Variables
4957 --
4958 p_ref_total_accrued := nvl(p_ref_total_accrued,0);
4959 p_reference_salary := nvl(p_reference_salary,0);
4960 P_Absence_attendance_ID := l_whole_Absence_attendance_ID;
4961 P_Assignment_id := l_assignment_id;
4962 P_Entry_Start_Date := l_whole_Entry_Start_Date;
4963 P_Entry_End_Date := l_whole_Entry_End_Date;
4964 P_Date_Accrued := l_whole_Date_Accrued;
4965 P_total_Main_Days := nvl(l_whole_Main_Days,0);
4966 P_total_Seniority_Days := nvl(l_whole_Seniority_Days,0);
4967 P_total_Young_Mothers_Days := nvl(l_whole_Young_Mothers_Days,0);
4968 P_total_Conventional_Days := nvl(l_whole_Conventional_Days,0);
4969 P_total_Protected_Days := nvl(l_whole_Protected_Days,0);
4970 P_taken_total_days := nvl(l_previous_total_days,0);
4971 P_taken_protected_Days := nvl(l_previous_protected_days,0);
4972 P_proration_period := l_to_pay_flag;
4973 p_regularize_possible := l_regularize_possible;
4974 p_session_date := l_session_date;
4975 --
4976 hr_utility.set_location('Leaving: '||l_proc,50);
4977 return 1;
4978 end Get_fr_holiday_details;
4979 --
4980 --
4981 -------------------------------------------------------------------------------
4982 -- GET_ACCRUAL_RATE_PERCENTAGE /**/
4983 -------------------------------------------------------------------------------
4984 function get_accrual_rate_percentage
4988 ,p_charges_percentage OUT NOCOPY number
4985 (p_date_earned IN date
4986 ,p_assignment_id IN number
4987 ,p_process_type IN varchar2
4989 ) return number is
4990 --
4991 l_proc varchar2(72) := g_package||'get_accrual_rate_percentage';
4992 l_estab_accrual_rate_part_time Number :=0;
4993 l_estab_accrual_rate_normal Number :=0;
4994 l_estab_accrual_rate_app Number :=0;
4995 l_estab_accrual_rate_ori Number :=0;
4996 l_estab_accrual_rate_yq Number :=0;
4997 --
4998 l_comp_accrual_rate_part_time Number :=0;
4999 l_comp_accrual_rate_normal Number :=0;
5000 l_comp_accrual_rate_app Number :=0;
5001 l_comp_accrual_rate_ori Number :=0;
5002 l_comp_accrual_rate_yq Number :=0;
5003 --
5004 -- Get the accrual charges percentages for the establishment
5005 --
5006 cursor csr_fetch_estab_process_rates(p_date_earned in date, p_assignment_id in number) is
5007 select target.org_information3
5008 ,target.org_information4
5009 ,target.org_information5
5013 ,per_all_assignments_f assign
5010 ,target.org_information6
5011 ,target.org_information7
5012 from hr_organization_information target
5014 WHERE p_date_earned BETWEEN assign.effective_start_date AND assign.effective_end_date
5015 AND assign.assignment_id = p_assignment_id
5016 AND assign.establishment_id = target.organization_id
5017 AND target.org_information_context = 'FR_ESTAB_ACCRUAL_RATE'
5018 AND fnd_date.date_to_canonical(p_date_earned)
5019 BETWEEN target.org_information1
5020 AND nvl(target.org_information2, '4712/12/31 00:00:00');
5021
5022 --
5023 -- Get the accrual charges percentages for the Company
5024 --
5025 cursor csr_fetch_comp_process_rates(p_date_earned in date, p_assignment_id in number) is
5026 select target.org_information3
5027 ,target.org_information4
5028 ,target.org_information5
5029 ,target.org_information6
5030 ,target.org_information7
5031 from hr_organization_units comp
5032 ,hr_organization_information target
5033 ,hr_organization_information estab
5034 ,per_all_assignments_f assign
5035 WHERE p_date_earned BETWEEN assign.effective_start_date AND assign.effective_end_date
5036 AND assign.assignment_id = p_assignment_id
5037 AND assign.establishment_id = estab.organization_id
5038 AND target.organization_id = comp.organization_id
5039 AND estab.org_information1 = to_char(comp.organization_id)
5040 AND target.org_information_context = 'FR_COMP_ACCRUAL_RATE'
5041 AND fnd_date.date_to_canonical(p_date_earned)
5042 BETWEEN target.org_information1
5043 AND nvl(target.org_information2, '4712/12/31 00:00:00');
5044
5045 begin
5046 hr_utility.set_location('Entering ' || l_proc,10);
5047 --
5048 -- Fetch the comp / process type percentages
5049 --
5050 open csr_fetch_comp_process_rates(p_date_earned,p_assignment_id);
5051 fetch csr_fetch_comp_process_rates into l_comp_accrual_rate_normal,l_comp_accrual_rate_part_time
5052 ,l_comp_accrual_rate_app, l_comp_accrual_rate_ori
5053 ,l_comp_accrual_rate_yq;
5054 hr_utility.set_location('Step '|| l_proc,20);
5055 --
5056 if csr_fetch_comp_process_rates%FOUND then
5057
5058 --
5059 -- Fetch the Estab / process type percentages
5060 --
5061 open csr_fetch_estab_process_rates(p_date_earned,p_assignment_id);
5062 fetch csr_fetch_estab_process_rates into l_estab_accrual_rate_normal,l_estab_accrual_rate_part_time
5063 ,l_estab_accrual_rate_app, l_estab_accrual_rate_ori
5064 ,l_estab_accrual_rate_yq;
5065
5066 hr_utility.set_location('Step ' || l_proc,30);
5067 --
5068 if csr_fetch_estab_process_rates%NOTFOUND then
5069
5070 --
5071 If p_process_type = 'NORMAL' then
5072 hr_utility.set_location('Step ' || l_proc,40);
5073 p_charges_percentage := l_comp_accrual_rate_normal;
5074 elsif p_process_type = 'PART_TIME' then
5075 hr_utility.set_location('Step ' || l_proc,50);
5076 p_charges_percentage := l_comp_accrual_rate_part_time;
5077 elsif p_process_type = 'APPRENTICE' then
5078 hr_utility.set_location('Step ' || l_proc,52);
5079 p_charges_percentage := l_comp_accrual_rate_app;
5080 elsif p_process_type = 'ORIENT' then
5081 hr_utility.set_location('Step ' || l_proc,53);
5082 p_charges_percentage := l_comp_accrual_rate_ori;
5083 elsif p_process_type = 'YPQUAL' then
5084 hr_utility.set_location('Step ' || l_proc,54);
5085 p_charges_percentage := l_comp_accrual_rate_yq;
5086 end if;
5087 --
5088 else
5089 --
5090 If p_process_type = 'NORMAL' then
5091 hr_utility.set_location('Step ' || l_proc,60);
5092 p_charges_percentage := nvl(l_estab_accrual_rate_normal,l_comp_accrual_rate_normal);
5093 elsif p_process_type = 'PART_TIME' then
5094 hr_utility.set_location('Step ' || l_proc,70);
5095 p_charges_percentage := nvl(l_estab_accrual_rate_part_time,l_comp_accrual_rate_part_time);
5096 elsif p_process_type = 'APPRENTICE' then
5097 hr_utility.set_location('Step ' || l_proc,72);
5098 p_charges_percentage := nvl(l_estab_accrual_rate_app,l_comp_accrual_rate_app);
5099 elsif p_process_type = 'ORIENT' then
5100 hr_utility.set_location('Step ' || l_proc,73);
5101 p_charges_percentage := nvl(l_estab_accrual_rate_ori,l_comp_accrual_rate_ori);
5102 elsif p_process_type = 'YPQUAL' then
5103 hr_utility.set_location('Step ' || l_proc,74);
5104 p_charges_percentage := nvl(l_estab_accrual_rate_yq,l_comp_accrual_rate_yq);
5108 --
5105 end if;
5106 --
5107 end if;
5109 close csr_fetch_estab_process_rates;
5110
5111 else
5112 open csr_fetch_estab_process_rates(p_date_earned,p_assignment_id);
5113 fetch csr_fetch_estab_process_rates into l_estab_accrual_rate_normal,l_estab_accrual_rate_part_time
5114 ,l_estab_accrual_rate_app, l_estab_accrual_rate_ori
5115 ,l_estab_accrual_rate_yq;
5116 hr_utility.set_location('Step ' || l_proc,80);
5117 --
5118 if csr_fetch_estab_process_rates%FOUND then
5119 --
5120 If p_process_type = 'NORMAL' then
5121 hr_utility.set_location('Step ' || l_proc,90);
5122 p_charges_percentage := l_estab_accrual_rate_normal;
5123 elsif p_process_type = 'PART_TIME' then
5124 hr_utility.set_location('Step ' || l_proc,100);
5125 p_charges_percentage := l_estab_accrual_rate_part_time;
5126 elsif p_process_type = 'APPRENTICE' then
5127 hr_utility.set_location('Step ' || l_proc,105);
5128 p_charges_percentage := l_estab_accrual_rate_app;
5129 elsif p_process_type = 'ORIENT' then
5130 hr_utility.set_location('Step ' || l_proc,106);
5131 p_charges_percentage := l_estab_accrual_rate_ori;
5132 elsif p_process_type = 'YPQUAL' then
5133 hr_utility.set_location('Step ' || l_proc,107);
5134 p_charges_percentage := l_estab_accrual_rate_yq;
5135 end if;
5136 --
5137 else
5138 p_charges_percentage := 0;
5139 end if;
5140 --
5141 close csr_fetch_estab_process_rates;
5142 end if;
5143 --
5144 close csr_fetch_comp_process_rates;
5145
5146 --
5147 If p_charges_percentage <> 0 then
5148 p_charges_percentage := nvl(p_charges_percentage,0);
5149 hr_utility.set_location('Step ' || l_proc,110);
5150 return 1;
5151 else
5152 p_charges_percentage := nvl(p_charges_percentage,0);
5153 hr_utility.set_location('Step ' || l_proc,120);
5154 return 0;
5155 end if;
5156 --
5157 hr_utility.set_location('Leaving: '||l_proc,130);
5158 --
5159 end get_accrual_rate_percentage;
5160 --
5161 -------------------------------------------------------------------------------
5162 -- GET_ACCOUNTING_DETAILS
5163 -------------------------------------------------------------------------------
5164 function Get_accounting_details
5165 (P_ELEMENT_ENTRY_ID IN Number
5166 ,P_PAYROLL_ID IN NUMBER
5167 ,P_ASSIGNMENT_ID IN NUMBER
5168 -- added 2 new parameters and modified 1 parameter for termination
5169 ,P_ACCOUNTING_DATE IN DATE /* Replaced with new date parameter for termination*/
5170 ,p_accounting_plan_id OUT NOCOPY Number /* the accrual plan id*/
5171 ,p_accrual_start_month OUT NOCOPY Number /* the accrual plan's start month*/
5172 --
5173 ,p_accounting_method OUT NOCOPY Varchar2 /* the accrual plan's accounting method */
5174 ,p_y0_net_days OUT NOCOPY Number /* the assignment's net days to pay for this year */
5175 ,P_y0_ref_salary OUT NOCOPY Number /* the assignment's reference salary for this year */
5176 ,P_y0_ref_days OUT NOCOPY Number /* the assignment's reference days accrued for this year */
5177 ,p_y1_net_days OUT NOCOPY Number /* the assignment's net days to pay for this year */
5178 ,P_y1_ref_salary OUT NOCOPY Number /* the assignment's reference salary for this year */
5179 ,P_y1_ref_days OUT NOCOPY Number /* the assignment's reference days accrued for this year */
5180 ,p_y2_net_days OUT NOCOPY Number /* the assignment's net days to pay for this year */
5181 ,P_y2_ref_salary OUT NOCOPY Number /* the assignment's reference salary for this year */
5182 ,P_y2_ref_days OUT NOCOPY Number /* the assignment's reference days accrued for this year */
5183 ,p_y3_net_days OUT NOCOPY Number /* the assignment's net days to pay for this year */
5184 ,P_y3_ref_salary OUT NOCOPY Number /* the assignment's reference salary for this year */
5185 ,P_y3_ref_days OUT NOCOPY Number /* the assignment's reference days accrued for this year */
5186 ) return number is
5187
5188 CURSOR csr_get_plan is
5189 select pap.accrual_plan_id
5190 from pay_accrual_plans pap
5191 ,pay_element_entries_f pee
5192 ,pay_element_links_f pel
5193 where pee.element_entry_id = P_ELEMENT_ENTRY_ID
5194 and pee.element_link_id = pel.element_link_id
5195 and pel.element_type_id = pap.accrual_plan_element_type_id;
5196
5197 l_accrual_plan_id number;
5198 l_total_accrued_pto number;
5199 l_total_accrued_protected number;
5200 l_accrual_this number;
5201 l_ent_this number;
5202 l_unused_number number;
5203 l_unused_date date;
5204 l_paid_this number;
5205 l_fr_plan_info g_fr_plan_info;
5206 l_count_paid_days_upto date;
5207
5208 l_proc VARCHAR2(72) := g_package||' get_accounting_details';
5209
5210 BEGIN
5211 hr_utility.set_location('Entering ' || l_proc,10);
5212 hr_utility.trace('p_element entry id ' || p_element_entry_id );
5213 hr_utility.trace('p_payroll_id ' || p_payroll_id );
5214 hr_utility.trace('p_assignment_id ' || p_assignment_id );
5215 hr_utility.trace('p_accounting_date ' || p_accounting_date );
5216 --
5217 -- Get the accrual plan
5221 close csr_get_plan;
5218 --
5219 open csr_get_plan;
5220 fetch csr_get_plan into l_accrual_plan_id;
5222 --
5223 -- Load the plan info
5224 --
5225 l_fr_plan_info := get_fr_accrual_plan_info(
5226 p_accrual_plan_id => l_accrual_plan_id
5227 ,p_accrual_date => P_ACCOUNTING_DATE);/* Replaced with new date parameter*/
5228 --
5229 -- record the date as at holiday must be taken before to reduce entitlement
5230 --
5231 l_count_paid_days_upto := P_ACCOUNTING_DATE;/* Replaced with new date parameter*/
5232 --
5233 -- Call this year and previous 3 years
5234 --
5235 hr_utility.set_location('Step ' || l_proc,50);
5236 --
5237 -- Call the accrual formula for this year, up to accounting_date. Do not deduct holiday taken
5238 -- from accrual. This may return zero if entitlement is stored past p_accounting_date - this
5239 -- will be picked up by entitlement
5240 --
5241 FR_Get_Accrual
5242 (P_Assignment_ID => P_Assignment_ID
5243 ,P_Calculation_Date => P_ACCOUNTING_DATE /* Replaced with new date parameter*/
5244 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
5245 ,P_Plan_ID => l_fr_plan_info.accrual_plan_id
5246 ,P_Business_Group_ID => l_fr_plan_info.business_Group_id
5247 ,P_Payroll_ID => P_PAYROLL_ID
5248 ,P_Assignment_Action_ID => null
5249 ,P_Accrual_Latest_Balance => null
5250 ,p_create_all => 'N' /* (do not create extra accrual types) */
5251 ,p_reprocess_whole_period => 'N' /* (only run accrual from latest ent to p_accounting_date) */
5252 ,p_payslip_process => 'Y' /* (indicates do not deduct hols taken from accrual - ent will show this) */
5253 ,P_Start_Date => l_unused_date
5254 ,P_End_Date => l_unused_date
5255 ,P_Accrual_End_Date => l_unused_date
5256 ,P_total_accrued_pto => l_total_accrued_pto
5257 ,P_total_Accrued_protected => l_total_Accrued_protected
5258 ,P_total_Accrued_seniority => l_unused_number
5259 ,P_total_Accrued_mothers => l_unused_number
5260 ,P_total_Accrued_conventional => l_unused_number ) ;
5261
5262 hr_utility.set_location('Step ' || l_proc,60);
5263
5264 l_accrual_this := nvl(l_total_accrued_pto,0) + nvl(l_total_Accrued_protected,0);
5265 hr_utility.set_location('l_accrual_this'||to_char(l_accrual_this),22);
5266 --
5267 -- Get the entitlement and net for this year. Only deduct holidays taken and paid
5268 -- (do not deduct all holidays booked, as the payslip must only show days taken to date )
5269 --
5270 hr_utility.set_location('Step ' || l_proc,60);
5271 get_fr_net_entitlement
5272 (p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5273 ,p_effective_date => P_ACCOUNTING_DATE /* Replaced with new date parameter*/
5274 ,p_assignment_id => P_ASSIGNMENT_ID
5275 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
5276 ,p_remaining => l_unused_number
5277 ,p_net_main => l_paid_this /* days paid as at (or after) the current accounting_date */
5278 ,p_net_protected => l_unused_number
5279 ,p_net_young_mothers => l_unused_number
5280 ,p_net_seniority => l_unused_number
5281 ,p_net_conventional => l_unused_number
5282 ,p_ent_main => l_ent_this /* net entitlement, including days paid before p_accounting_date */
5283 ,p_ent_protected => l_unused_number
5284 ,p_ent_young_mothers => l_unused_number
5285 ,p_ent_seniority => l_unused_number
5286 ,p_ent_conventional => l_unused_number
5287 ,p_accrual_start_date => l_unused_date
5288 ,p_accrual_end_date => l_unused_date
5289 ,p_type_calculation => 'A' /* Accrual type */
5290 ,p_paid_days_to => l_count_paid_days_upto);
5291
5292 hr_utility.set_location('Step ' || l_proc,70);
5293 hr_utility.set_location('l_ent_this'||to_char(l_ent_this), 22);
5294 hr_utility.set_location('l_paid_this'||to_char(l_paid_this), 22);
5295 hr_utility.trace('net Y0 is ' || to_char(nvl(l_ent_this,0) - nvl(l_paid_this,0)));
5296 p_y0_net_days := l_accrual_this + nvl(l_ent_this,0) - nvl(l_paid_this,0);
5297
5298 --
5299 -- Get the reference entitlement for this year
5300 --
5301 get_reference_entitlement(
5302 p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5303 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
5304 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
5305 ,p_assignment_id => P_ASSIGNMENT_ID
5306 ,p_ent_ref_days_id => l_fr_plan_info.ent_reference_days_iv_id
5307 ,p_ent_ref_salary_id => l_fr_plan_info.ent_reference_sal_iv_id
5308 ,p_ent_accrual_date_iv_id => l_fr_plan_info.ent_accrual_date_iv_id
5309 ,p_ref_main_days => P_y0_ref_days
5310 ,p_ref_salary => P_y0_ref_salary);
5311
5312 --
5313 -- Repeat for the previous year (n-1)
5314 --
5315 --
5316 -- Load the plan info for n-1
5317 --
5318 l_fr_plan_info := get_fr_accrual_plan_info(
5319 p_accrual_plan_id => l_accrual_plan_id
5320 ,p_accrual_date => add_months(P_ACCOUNTING_DATE, -12));/* Replaced with new date parameter*/
5321
5322 hr_utility.set_location('Step ' || l_proc,160);
5323
5324 get_fr_net_entitlement
5328 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
5325 (p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5326 ,p_effective_date => add_months(P_ACCOUNTING_DATE, -12) /* Replaced with new date parameter*/
5327 ,p_assignment_id => P_ASSIGNMENT_ID
5329 ,p_remaining => l_unused_number
5330 ,p_net_main => l_paid_this /* days paid as at (or after) the current accounting_date */
5331 ,p_net_protected => l_unused_number
5332 ,p_net_young_mothers => l_unused_number
5333 ,p_net_seniority => l_unused_number
5334 ,p_net_conventional => l_unused_number
5335 ,p_ent_main => l_ent_this /* net entitlement, including days paid before p_accounting_date */
5336 ,p_ent_protected => l_unused_number
5337 ,p_ent_young_mothers => l_unused_number
5338 ,p_ent_seniority => l_unused_number
5339 ,p_ent_conventional => l_unused_number
5340 ,p_accrual_start_date => l_unused_date
5341 ,p_accrual_end_date => l_unused_date
5342 ,p_type_calculation => 'A' /* Accrual type */
5343 ,p_paid_days_to => l_count_paid_days_upto);
5344
5345 hr_utility.set_location('Step ' || l_proc,170);
5346 hr_utility.trace('net Y1 is ' || to_char(nvl(l_ent_this,0) - nvl(l_paid_this,0)));
5347 p_y1_net_days := nvl(l_ent_this,0) - nvl(l_paid_this,0);
5348
5349 hr_utility.trace('p_y1_net_days is ' || p_y1_net_days );
5350 --
5351 -- Get the reference entitlement for this year
5352 --
5353 get_reference_entitlement(
5354 p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5355 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
5356 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
5357 ,p_assignment_id => P_ASSIGNMENT_ID
5358 ,p_ent_ref_days_id => l_fr_plan_info.ent_reference_days_iv_id
5359 ,p_ent_ref_salary_id => l_fr_plan_info.ent_reference_sal_iv_id
5360 ,p_ent_accrual_date_iv_id => l_fr_plan_info.ent_accrual_date_iv_id
5361 ,p_ref_main_days => P_y1_ref_days
5362 ,p_ref_salary => P_y1_ref_salary);
5363
5364 --
5365 -- Repeat for the previous year (n-2)
5366 --
5367 --
5368 -- Load the plan info for n-2
5369 --
5370 l_fr_plan_info := get_fr_accrual_plan_info(
5371 p_accrual_plan_id => l_accrual_plan_id
5372 ,p_accrual_date => add_months(P_ACCOUNTING_DATE, -24));/* Replaced with new date parameter*/
5373
5374 hr_utility.set_location('Step ' || l_proc,260);
5375
5376 get_fr_net_entitlement
5377 (p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5378 ,p_effective_date => add_months(P_ACCOUNTING_DATE, -24) /* Replaced with new date parameter*/
5379 ,p_assignment_id => P_ASSIGNMENT_ID
5380 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
5381 ,p_remaining => l_unused_number
5382 ,p_net_main => l_paid_this /* days paid as at (or after) the current accounting_date */
5383 ,p_net_protected => l_unused_number
5384 ,p_net_young_mothers => l_unused_number
5385 ,p_net_seniority => l_unused_number
5386 ,p_net_conventional => l_unused_number
5387 ,p_ent_main => l_ent_this /* net entitlement, including days paid before p_accounting_date */
5388 ,p_ent_protected => l_unused_number
5389 ,p_ent_young_mothers => l_unused_number
5390 ,p_ent_seniority => l_unused_number
5391 ,p_ent_conventional => l_unused_number
5392 ,p_accrual_start_date => l_unused_date
5393 ,p_accrual_end_date => l_unused_date
5394 ,p_type_calculation => 'A' /* Accrual type */
5395 ,p_paid_days_to => l_count_paid_days_upto);
5396
5397 hr_utility.set_location('Step ' || l_proc,270);
5398 hr_utility.trace('net Y2 is ' || to_char(nvl(l_ent_this,0) - nvl(l_paid_this,0)));
5399 p_y2_net_days := nvl(l_ent_this,0) - nvl(l_paid_this,0);
5400
5401 hr_utility.trace('p_y2_net_days is ' || p_y2_net_days );
5402 --
5403 -- Get the reference entitlement for this year
5404 --
5405 get_reference_entitlement(
5406 p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5407 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
5408 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
5409 ,p_assignment_id => P_ASSIGNMENT_ID
5410 ,p_ent_ref_days_id => l_fr_plan_info.ent_reference_days_iv_id
5411 ,p_ent_ref_salary_id => l_fr_plan_info.ent_reference_sal_iv_id
5412 ,p_ent_accrual_date_iv_id => l_fr_plan_info.ent_accrual_date_iv_id
5413 ,p_ref_main_days => P_y2_ref_days
5414 ,p_ref_salary => P_y2_ref_salary);
5415
5416 --
5417 -- Repeat for the previous year (n-3)
5418 --
5419 --
5420 -- Load the plan info for n-3
5421 --
5422 l_fr_plan_info := get_fr_accrual_plan_info(
5423 p_accrual_plan_id => l_accrual_plan_id
5424 ,p_accrual_date => add_months(P_ACCOUNTING_DATE, -36));/* Replaced with new date parameter*/
5425
5426 hr_utility.set_location('Step ' || l_proc,360);
5427
5428 get_fr_net_entitlement
5429 (p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5433 ,p_remaining => l_unused_number
5430 ,p_effective_date => add_months(P_ACCOUNTING_DATE, -36) /* Replaced with new date parameter*/
5431 ,p_assignment_id => P_ASSIGNMENT_ID
5432 ,p_ignore_ent_adjustments => 'N' /* (include obsoletions and adjustments in ent parameters) */
5434 ,p_net_main => l_paid_this /* days paid as at (or after) the current accounting_date */
5435 ,p_net_protected => l_unused_number
5436 ,p_net_young_mothers => l_unused_number
5437 ,p_net_seniority => l_unused_number
5438 ,p_net_conventional => l_unused_number
5439 ,p_ent_main => l_ent_this /* net entitlement, including days paid before p_accounting_date */
5440 ,p_ent_protected => l_unused_number
5441 ,p_ent_young_mothers => l_unused_number
5442 ,p_ent_seniority => l_unused_number
5443 ,p_ent_conventional => l_unused_number
5444 ,p_accrual_start_date => l_unused_date
5445 ,p_accrual_end_date => l_unused_date
5446 ,p_type_calculation => 'A' /* Accrual type */
5447 ,p_paid_days_to => l_count_paid_days_upto);
5448
5449 hr_utility.set_location('Step ' || l_proc,370);
5450 hr_utility.trace('net Y3 is ' || to_char(nvl(l_ent_this,0) - nvl(l_paid_this,0)));
5451 p_y3_net_days := nvl(l_ent_this,0) - nvl(l_paid_this,0);
5452
5453 hr_utility.trace('p_y3_net_days is ' || p_y3_net_days );
5454 --
5455 -- Get the reference entitlement for this year
5456 --
5457 get_reference_entitlement(
5458 p_accrual_plan_id => l_fr_plan_info.accrual_plan_id
5459 ,p_accrual_start_date => l_fr_plan_info.accrual_year_start
5460 ,p_accrual_end_date => l_fr_plan_info.accrual_year_end
5461 ,p_assignment_id => P_ASSIGNMENT_ID
5462 ,p_ent_ref_days_id => l_fr_plan_info.ent_reference_days_iv_id
5463 ,p_ent_ref_salary_id => l_fr_plan_info.ent_reference_sal_iv_id
5464 ,p_ent_accrual_date_iv_id => l_fr_plan_info.ent_accrual_date_iv_id
5465 ,p_ref_main_days => P_y3_ref_days
5466 ,p_ref_salary => P_y3_ref_salary);
5467 --
5468 hr_utility.set_location('Leaving: '||l_proc,360);
5469 --
5470 p_accounting_method := l_fr_plan_info.accounting_method;
5471 -- added code for termination processing
5472 p_accounting_plan_id := l_fr_plan_info.accrual_plan_id;
5473 p_accrual_start_month := l_fr_plan_info.accrual_start_month ;
5474 --
5475 p_y0_net_days := nvl(p_y0_net_days,0);
5476 P_y0_ref_salary := nvl(P_y0_ref_salary,0);
5477 P_y0_ref_days := nvl(P_y0_ref_days,0);
5478
5479 p_y1_net_days := nvl(p_y1_net_days ,0);
5480 P_y1_ref_salary := nvl(P_y1_ref_salary,0);
5481 P_y1_ref_days := nvl(P_y1_ref_days ,0);
5482
5483 p_y2_net_days := nvl(p_y2_net_days ,0);
5484 P_y2_ref_salary := nvl(P_y2_ref_salary,0);
5485 P_y2_ref_days := nvl(P_y2_ref_days ,0);
5486
5487 p_y3_net_days := nvl(p_y3_net_days ,0);
5488 P_y3_ref_salary := nvl(P_y3_ref_salary,0);
5489 P_y3_ref_days := nvl(P_y3_ref_days ,0);
5490 --
5491 hr_utility.trace('p_y0_net_days GAD is ' || p_y0_net_days);
5492 hr_utility.trace('p_y1_net_days GAD is ' || p_y1_net_days);
5493 hr_utility.trace('p_y2_net_days GAD is ' || p_y2_net_days);
5494
5495 return 1;
5496 END Get_accounting_details;
5497 --
5498
5499 Function write_termination_payment
5500 (p_accrual_plan_id number,
5501 p_y0_payment number,
5502 p_y0_payment_days number,
5503 p_y0_payment_rate number,
5504 p_y0_accrual_year date,
5505 p_y1_payment number,
5506 p_y1_payment_days number,
5507 p_y1_payment_rate number,
5508 p_y1_accrual_year date,
5509 p_y2_payment number,
5510 p_y2_payment_days number,
5511 p_y2_payment_rate number,
5512 p_y2_accrual_year date,
5513 p_y3_payment number,
5514 p_y3_payment_days number,
5515 p_y3_payment_rate number,
5516 p_y3_accrual_year date
5517 ) return number is
5518
5519 i number;
5520 last_i number;
5521
5522 begin
5523
5524 hr_utility.trace('plan _id = ' || p_accrual_plan_id);
5525 hr_utility.trace('y0_payment = ' || p_y0_payment);
5526 hr_utility.trace('y0_payment_days = ' || p_y0_payment_days);
5527 hr_utility.trace('y0_payment_rate = ' || p_y0_payment_rate);
5528 hr_utility.trace('y0_payment_year = ' || p_y0_accrual_year);
5529
5530 hr_utility.trace('y1_payment = ' || p_y1_payment);
5531 hr_utility.trace('y1_payment_days = ' || p_y1_payment_days);
5532 hr_utility.trace('y1_payment_rate = ' || p_y1_payment_rate);
5533 hr_utility.trace('y1_payment_year = ' || p_y1_accrual_year);
5534
5535 hr_utility.trace('y2_payment = ' || p_y2_payment);
5536 hr_utility.trace('y2_payment_days = ' || p_y2_payment_days);
5537 hr_utility.trace('y2_payment_rate = ' || p_y2_payment_rate);
5538 hr_utility.trace('y2_payment_year = ' || p_y2_accrual_year);
5539
5540 hr_utility.trace('y3_payment = ' || p_y3_payment);
5541 hr_utility.trace('y3_payment_days = ' || p_y3_payment_days);
5542 hr_utility.trace('y3_payment_rate = ' || p_y3_payment_rate);
5543 hr_utility.trace('y3_payment_year = ' || p_y3_accrual_year);
5544
5545 i := p_accrual_plan_id * 10;
5546 if p_y0_payment <> 0 and p_y0_payment is not null then
5547 i := i+1;
5548 term_payment(i).payment := p_y0_payment;
5549 term_payment(i).days := p_y0_payment_days;
5553 last_i := i;
5550 term_payment(i).daily_rate := p_y0_payment_rate;
5551 term_payment(i).accrual_date := p_y0_accrual_year;
5552 term_payment(i).next_payment := 0;
5554 end if;
5555
5556 if p_y1_payment <> 0 and p_y1_payment is not null then
5557 i := i+1;
5558 term_payment(i).payment := p_y1_payment;
5559 term_payment(i).days := p_y1_payment_days;
5560 term_payment(i).daily_rate := p_y1_payment_rate;
5561 term_payment(i).accrual_date := p_y1_accrual_year;
5562 term_payment(i).next_payment := 0;
5563
5564 if last_i is not null then
5565 term_payment(last_i).next_payment := i;
5566 end if;
5567
5568 last_i := i;
5569 end if;
5570
5571 if p_y2_payment <> 0 and p_y2_payment is not null then
5572 i := i+1;
5573 term_payment(i).payment := p_y2_payment;
5574 term_payment(i).days := p_y2_payment_days;
5575 term_payment(i).daily_rate := p_y2_payment_rate;
5576 term_payment(i).accrual_date := p_y2_accrual_year;
5577 term_payment(i).next_payment := 0;
5578
5579 if last_i is not null then
5580 term_payment(last_i).next_payment := i;
5581 end if;
5582
5583 last_i := i;
5584 end if;
5585
5586 if p_y3_payment <> 0 and p_y3_payment is not null then
5587 i := i+1;
5588 term_payment(i).payment := p_y3_payment;
5589 term_payment(i).days := p_y3_payment_days;
5590 term_payment(i).daily_rate := p_y3_payment_rate;
5591 term_payment(i).accrual_date := p_y3_accrual_year;
5592 term_payment(i).next_payment := 0;
5593
5594 if last_i is not null then
5595 term_payment(last_i).next_payment := i;
5596 end if;
5597
5598 last_i := i;
5599 end if;
5600
5601 return 0;
5602
5603 EXCEPTION
5604 WHEN OTHERS THEN
5605 hr_utility.trace('write_termination_payment');
5606 hr_utility.trace(SQLCODE);
5607 hr_utility.trace(SQLERRM);
5608 Raise;
5609
5610 end write_termination_payment;
5611
5612 Function read_termination_payment
5613 (p_accrual_plan_id IN NUMBER,
5614 p_index IN number,
5615 p_payment OUT NOCOPY number,
5616 p_days OUT NOCOPY number,
5617 p_daily_rate OUT NOCOPY number,
5618 p_accrual_date OUT NOCOPY date,
5619 p_next_payment OUT NOCOPY number)
5620 return number is
5621
5622 l_index number;
5623
5624 begin
5625 hr_utility.trace('in read termination payment');
5626 hr_utility.trace('p_accrual_plan_id = ' || p_accrual_plan_id);
5627 hr_utility.trace('p_index = ' || p_index);
5628
5629 l_index := p_index;
5630
5631 if p_index is null OR p_index = 0 Then
5632 l_index := p_accrual_plan_id * 10 + 1;
5633 end if;
5634
5635 p_payment := term_payment(l_index).payment;
5636 p_daily_rate := term_payment(l_index).daily_rate;
5637 p_accrual_date := term_payment(l_index).accrual_date;
5638 p_next_payment := term_payment(l_index).next_payment;
5639
5640 /* Bug 4538139 Obtains the next row */
5641 if p_next_payment is not null and p_next_payment <> 0 then
5642 p_days := term_payment(p_next_payment).days;
5643 end if;
5644
5645 hr_utility.trace('p_payment = ' || p_payment);
5646 hr_utility.trace('p_days = ' || p_days);
5647 hr_utility.trace('p_daily_rate = ' || p_daily_rate);
5648 hr_utility.trace('p_accrual_date = ' || p_accrual_date);
5649 hr_utility.trace('p_next_payment = ' || p_next_payment);
5650
5651 hr_utility.trace('left read termination payment');
5652
5653 return 0;
5654 EXCEPTION
5655 WHEN OTHERS THEN
5656 hr_utility.trace('read_termination_payment');
5657 hr_utility.trace(SQLCODE);
5658 hr_utility.trace(SQLERRM);
5659 Raise;
5660
5661 end read_termination_payment;
5662 --
5663 -------------------------------------------------------------------------------
5664 -- VALID_FIXED_TERM_CONTRACT_REF
5665 -- Used by FR_FIXED_TERM_CONTRACT_INDEMNITY_REFERENCE Element Input Validation
5666 -------------------------------------------------------------------------------
5667 function Valid_Fixed_Term_Contract_Ref
5668 (p_assignment_id in number
5669 ,p_date_earned in date
5670 ,p_reference in varchar2) return varchar2 is
5671 --
5672 l_valid varchar2(10);
5673 cursor csr_find_match is
5674 select 'TRUE'
5675 from per_all_assignments_f asg,
5676 per_contracts_f pcf
5677 where p_date_earned >= asg.effective_start_date
5678 and p_assignment_id = asg.assignment_id
5679 and asg.contract_id = pcf.contract_id
5680 and p_date_earned between pcf.effective_start_date
5681 and pcf.effective_end_date
5682 and pcf.reference = p_reference
5683 and pcf.ctr_information2 = 'FIXED_TERM';
5684 --
5685 BEGIN
5686 open csr_find_match;
5687 fetch csr_find_match into l_valid;
5688 if csr_find_match%NOTFOUND then
5689 l_valid := 'FALSE';
5690 end if;
5691 close csr_find_match;
5692 return l_valid;
5693 END Valid_Fixed_Term_Contract_Ref;
5694 --
5695 -------------------------------------------------------------------------------
5696 -- CONTRACT_ACTIVE_END_DATE
5697 -- Used by FR_FIXED_TERM_CONTRACT_INDEMNITY formula
5698 -------------------------------------------------------------------------------
5702 ,p_reference in varchar2) /* entry ref input value */
5699 function contract_active_end_date
5700 (p_assignment_id in number
5701 ,p_date_earned in date
5703 return date is
5704 l_contract_id per_contracts_f.contract_id%TYPE;
5705 l_contract_status per_contracts_f.status%TYPE;
5706 --
5707 cursor csr_get_contract_details is
5708 select pcf.contract_id, pcf.status
5709 from per_all_assignments_f asg,
5710 per_contracts_f pcf
5711 where p_assignment_id = asg.assignment_id
5712 and asg.contract_id = pcf.contract_id
5713 and p_date_earned >= asg.effective_start_date
5714 and p_date_earned between pcf.effective_start_date
5715 and pcf.effective_end_date
5716 and pcf.reference = p_reference;
5717 --
5718 BEGIN
5719 open csr_get_contract_details;
5720 fetch csr_get_contract_details into l_contract_id, l_contract_status;
5721 close csr_get_contract_details;
5722 if l_contract_id is null then
5723 fnd_message.set_name('PAY','PAY_75056_ACC_CTR_FT_BAD_REF');
5724 fnd_message.raise_error;
5725 end if;
5726 return nvl(hr_contract_api.get_active_end_date
5727 (l_contract_id, p_date_earned, l_contract_status),
5728 hr_general.end_of_time);
5729 END contract_active_end_date;
5730 --
5731 -------------------------------------------------------------------------------
5732 -- GET_FIXED_TERM_CTR_ENTRY_INFO
5733 -- Used by FR_FIXED_TERM_CONTRACT_INDEMNITY formula
5734 -------------------------------------------------------------------------------
5735 function Get_Fixed_Term_Ctr_Entry_info
5736 (p_assignment_id in number
5737 ,p_date_earned in date
5738 ,p_reference in varchar2 /* the ref of the entry value */
5739 ,p_deferred_payment out nocopy varchar2 /* payment to be deferred? */
5740 ) return number
5741 is
5742 l_value_defaulted number(1);
5743 cursor csr_find_entry is
5744 select 0, pev_def.screen_entry_value
5745 from pay_element_entries_f pee
5746 ,pay_element_entry_values_f pev_ref
5747 ,pay_input_values_f piv_ref
5748 ,pay_element_types_f pet
5749 ,pay_input_values_f piv_def
5750 ,pay_element_entry_values_f pev_def
5751 where pet.element_name = 'FR_FIXED_TERM_CONTRACT_INDEMNITY'
5752 and pet.legislation_code = 'FR'
5753 and pet.business_group_id is null
5754 and pet.element_type_id = piv_ref.element_type_id
5755 and piv_def.name = 'Deferred Payment'
5756 and piv_def.legislation_code = 'FR'
5757 and piv_def.business_group_id is null
5758 and pev_def.input_value_id = piv_def.input_Value_id
5759 and pee.element_entry_id = pev_def.element_entry_id
5760 and pev_ref.screen_entry_value = p_reference
5761 and piv_ref.name = 'Contract Reference'
5762 and piv_ref.legislation_code = 'FR'
5763 and piv_ref.business_group_id is null
5764 and pev_ref.input_value_id = piv_ref.input_Value_id
5765 and pee.element_entry_id = pev_ref.element_entry_id
5766 and pee.assignment_id = p_assignment_id
5767 and p_date_earned between pev_def.effective_start_date
5768 and pev_def.effective_end_date
5769 and p_date_earned between piv_def.effective_start_date
5770 and piv_def.effective_end_date
5771 and p_date_earned between pev_ref.effective_start_date
5772 and pev_ref.effective_end_date
5773 and p_date_earned between piv_ref.effective_start_date
5774 and piv_ref.effective_end_date
5775 and p_date_earned between pet.effective_start_date
5776 and pet.effective_end_date
5777 and p_date_earned between pee.effective_start_date
5778 and pee.effective_end_date;
5779 BEGIN
5780 open csr_find_entry;
5781 fetch csr_find_entry into l_value_defaulted, p_deferred_payment;
5782 if csr_find_entry%NOTFOUND then
5783 p_deferred_payment := 'N';
5784 l_value_defaulted := 1;
5785 end if;
5786 close csr_find_entry;
5787 return l_value_defaulted;
5788 END Get_Fixed_Term_Ctr_Entry_info;
5789 --
5790 --------------------------------------------------------------------
5791 -- Function Check_fr_holidays_booked
5792 -- Created for bug 2874154 - srjadhav
5793 --------------------------------------------------------------------
5794 function Check_fr_holidays_booked
5795 (P_assignment_id IN Number /* the assignment */
5796 ,P_accrual_plan_id IN Number
5797 ,p_start_date IN Date
5798 ,p_end_date IN Date
5799 ) return number IS
5800 l_accrual_plan_id Number := P_accrual_plan_id;
5801 l_assignment_id Number := P_assignment_id;
5802 l_date_start Date := p_start_date;
5803 l_date_end Date := p_end_date;
5804 l_holiday_element_id Number;
5805 l_unused_char Varchar2(30);
5806 l_main_holidays Number;
5807 l_unused_number Number;
5808 l_unused_date Date;
5809 --
5810
5811 CURSOR csr_booked_holiday_sickness (p_assignment_id in number
5812 ,p_start_date Date, p_end_date Date) is
5813 -- Added the following cursor for cheking whether the employee
5814 -- has taken a sick leave between LDW and ATD. Bug#2874154
5815 select 1
5816 from per_absence_attendances paa
5817 ,pay_element_entries_f pee
5818 ,per_absence_attendance_types pat
5819 where pee.creator_type = 'A'
5820 and paa.absence_attendance_id = pee.creator_id
5824 and pat.absence_category = 'S';
5821 and fnd_date.date_to_canonical (paa.date_start) between fnd_date.date_to_canonical(p_start_date) and fnd_date.date_to_canonical(p_end_date)
5822 and pee.assignment_id = p_assignment_id
5823 and paa.absence_attendance_type_id = pat.absence_attendance_type_id
5825 --
5826 --Changed the following cursor for bug#3030610.
5827 CURSOR csr_booked_holiday (p_assignment_id in number, p_holiday_element_id in number
5828 ,p_start_date Date, p_end_date Date) is
5829 select NVL(sum(paa.abs_information2), -1)
5830 from per_absence_attendances paa
5831 ,pay_element_entries_f pee
5832 where pee.element_link_id in (select element_link_id
5833 from pay_element_links_f
5834 where element_type_id = p_holiday_Element_id
5835 )
5836 and pee.creator_type = 'A'
5837 and paa.absence_Attendance_id = pee.creator_id
5838 and fnd_date.date_to_canonical(paa.date_start) between fnd_date.date_to_canonical(p_start_date)
5839 and fnd_date.date_to_canonical(p_end_date)
5840 and pee.assignment_id = p_assignment_id;
5841
5842 l_proc VARCHAR2(72) := g_package||' Check_fr_holidays_booked ';
5843 --
5844 BEGIN
5845 --
5846 hr_utility.set_location('Entering:'||l_proc,777);
5847 -- fetch variables for this accrual plan
5848 --
5849 OPEN csr_booked_holiday_sickness (l_assignment_id, l_date_start, l_date_end);
5850 FETCH csr_booked_holiday_sickness into l_unused_number;
5851 -- Added the following IF statement to check whether any sick leave
5852 -- has been taken or not
5853 IF csr_booked_holiday_sickness%FOUND THEN
5854 RETURN 1;
5855 ELSE
5856
5857 -- The following procedure is used to check whether the employee has taken
5858 -- leave of any other categories
5859
5860 get_accrual_plan_data(
5861 p_accrual_plan_id => l_accrual_plan_id
5862 ,p_accrual_year_start => l_unused_date
5863 ,p_accrual_year_end => l_unused_date
5864 ,p_accounting_method => l_unused_char
5865 ,p_entitlement_offset => l_unused_number
5866 ,p_ent_ref_days_id => l_unused_number
5867 ,p_ent_ref_salary_id => l_unused_number
5868 ,p_ent_accrual_date_iv_id => l_unused_number
5869 ,p_holiday_element_id => l_holiday_element_id);
5870 --
5871 -- Call sub procedure to calculate the totals
5872 --
5873 OPEN csr_booked_holiday (l_assignment_id, l_holiday_element_id, l_date_start, l_date_end);
5874 FETCH csr_booked_holiday into l_main_holidays;
5875 RETURN l_main_holidays;
5876 END IF;
5877
5878
5879 close csr_booked_holiday;
5880 close csr_booked_holiday_sickness;
5881
5882 END Check_fr_holidays_booked;
5883 --
5884
5885 --
5886 --------------------------------------------------------------------
5887 -- Function Check_fr_consecutive_holidays_booked
5888 -- Function will return 1 if successful otherwise
5889 -- will return 0. Bug#3030610
5890 --------------------------------------------------------------------
5891 function Check_fr_cons_holidays_booked
5892 (P_assignment_id IN Number /* the assignment */
5893 ,P_accrual_plan_id IN Number
5894 ,p_start_date IN Date
5895 ,p_end_date IN Date
5896 ) return number IS
5897 l_accrual_plan_id Number := P_accrual_plan_id;
5898 l_assignment_id Number := P_assignment_id;
5899 l_date_start Date := p_start_date;
5900 l_date_end Date := p_end_date;
5901 l_holiday_element_id Number;
5902 l_main_holidays Number;
5903 l_accounting_method Varchar2(30);
5904 l_unused_char Varchar2(30);
5905 l_unused_number Number;
5906 l_unused_date Date;
5907 l_no_absences Number;
5908 --
5909
5910 CURSOR csr_booked_holiday (p_assignment_id in number, p_holiday_element_id in number
5911 ,p_start_date Date, p_end_date Date, p_no_absences in number) is
5912 select 1
5913 from per_absence_attendances paa
5914 ,pay_element_entries_f pee
5915 where pee.element_link_id in (select element_link_id
5916 from pay_element_links_f
5917 where element_type_id = p_holiday_element_id
5918 )
5919 and pee.creator_type = 'A'
5920 and paa.absence_Attendance_id = pee.creator_id
5921 and fnd_date.date_to_canonical(paa.date_start) >= fnd_date.date_to_canonical(p_start_date)
5922 and fnd_date.date_to_canonical(paa.date_end) <= fnd_date.date_to_canonical(p_end_date)
5923 and paa.absence_days >= p_no_absences
5924 and pee.assignment_id = p_assignment_id;
5925
5926
5927
5928 l_proc VARCHAR2(72) := g_package||' Check_fr_cons_holidays_booked';
5929
5930 l_found NUMBER := 0;
5931 --
5932 BEGIN
5933 --
5934 -- fetch variables for this accrual plan
5935 --
5936 hr_utility.set_location('Entering:'||l_proc,777);
5937
5938 get_accrual_plan_data(
5939 p_accrual_plan_id => l_accrual_plan_id
5940 ,p_accrual_year_start => l_unused_date
5941 ,p_accrual_year_end => l_unused_date
5942 ,p_accounting_method => l_accounting_method
5943 ,p_entitlement_offset => l_unused_number
5944 ,p_ent_ref_days_id => l_unused_number
5948 --
5945 ,p_ent_ref_salary_id => l_unused_number
5946 ,p_ent_accrual_date_iv_id => l_unused_number
5947 ,p_holiday_element_id => l_holiday_element_id);
5949 -- Call sub procedure to calculate the totals
5950 --
5951 IF l_accounting_method ='FR_OPEN_DAYS' THEN
5952 l_no_absences := 12;
5953 ELSE /*** will be defaulted to 'FR_WORK_DAYS'**/
5954 l_no_absences := 10;
5955 END IF;
5956 hr_utility.set_location('Cursor Parameters:'||l_proc,780);
5957 hr_utility.set_location('l_assignment_id:'||l_proc,l_assignment_id);
5958 hr_utility.set_location('l_holiday_element_id:'||l_proc,l_holiday_element_id);
5959 hr_utility.set_location('l_date_start:'||l_date_start||':'||l_proc,1001);
5960 hr_utility.set_location('l_date_end:'||l_date_end||':'||l_proc,1002);
5961 hr_utility.set_location('l_no_absences:'||l_proc,l_no_absences);
5962
5963 OPEN csr_booked_holiday (l_assignment_id
5964 , l_holiday_element_id
5965 , l_date_start
5966 , l_date_end
5967 , l_no_absences);
5968 FETCH csr_booked_holiday into l_main_holidays;
5969
5970 IF csr_booked_holiday%FOUND THEN
5971 l_found := 1;
5972 ELSE --IF csr_booked_holiday%NOTFOUND THEN
5973 l_found := 0;
5974 END IF;
5975
5976 CLOSE csr_booked_holiday;
5977 hr_utility.set_location('Returning :'||l_found||':'||l_proc,779);
5978 RETURN l_found;
5979
5980 END Check_fr_cons_holidays_booked;
5981 --
5982 ----------------------------------------------------------------------------
5983 -- Procedure get_fr_add_net_ent
5984 -- called from HREMEA.pld to calculate net additional entitlement
5985 ---------------------------------------------------------------------------
5986 PROCEDURE get_fr_add_net_ent(
5987 p_absence_attendance_type_id in number,
5988 p_abs_date_start in date,
5989 p_abs_date_end in date,
5990 p_person_id in number,
5991 p_accrual_plan_id in number,
5992 p_total_ent out nocopy number,
5993 p_net_ent out nocopy number)
5994 IS
5995 -- Defining cursor to get existing entitlements
5996 cursor csr_get_ent(
5997 c_type_m_iv_id number
5998 ,c_start_date date
5999 ,c_end_date date) is
6000 select nvl(sum(pevm.screen_entry_value),0)
6001 from pay_element_entry_values_f pevm
6002 ,pay_element_entries_f pee
6003 ,per_all_assignments_f pasg
6004 where pevm.input_value_id = c_type_m_iv_id
6005 and pee.element_entry_id = pevm.element_entry_id
6006 and pevm.effective_start_date between c_start_date and c_end_date
6007 and pee.effective_start_date between c_start_date and c_end_date
6008 and pee.assignment_id = pasg.assignment_id
6009 and pasg.person_id = p_person_id;
6010 --
6011 -- Defining cursor selecting hiredate
6012 Cursor csr_assg_hiredate(c_person_id number) is
6013 Select max(ppos.date_start)
6014 From per_periods_of_service ppos
6015 Where ppos.person_id = c_person_id
6016 and ppos.date_start <= p_abs_date_start;
6017
6018 --
6019 -- Cursor to sum up existing absences against entitled holidays
6020 Cursor csr_exist_abs(p_hire_date date) is
6021 Select sum(date_end-date_start+1)
6022 from per_absence_attendances
6023 where person_id = p_person_id
6024 and date_end <= p_abs_date_end
6025 and date_start >= p_hire_date
6026 and absence_attendance_type_id = p_absence_attendance_type_id;
6027 --
6028 l_fr_plan_info g_fr_plan_info;
6029 l_ent_m number :=0;
6030 l_hiredate date;
6031 l_exist_absence number;
6032 l_net_entitlement number;
6033 --
6034 --
6035 BEGIN
6036 --
6037 --
6038 l_fr_plan_info := get_fr_accrual_plan_info(
6039 p_accrual_plan_id => p_accrual_plan_id
6040 ,p_accrual_date => p_abs_date_start );
6041 -- Get the hire date
6042 -- to get the date range for checking absence
6043 open csr_assg_hiredate(p_person_id);
6044 fetch csr_assg_hiredate into l_hiredate;
6045 close csr_assg_hiredate;
6046 -- Calculate the sum of total entitlements created for this accrual plan
6047 -- within the hire date and absence start date
6048 hr_utility.set_location('l_fr_plan_info.ent_m_iv_id is : '||to_char(l_fr_plan_info.ent_m_iv_id), 22);
6049 hr_utility.set_location('l_hiredate is: '||to_char(l_hiredate), 22);
6050 hr_utility.set_location('p_abs_date_start is: '||to_char(p_abs_date_start),22);
6051 open csr_get_ent(l_fr_plan_info.ent_m_iv_id,
6052 l_hiredate,
6053 p_abs_date_start);
6054 fetch csr_get_ent into l_ent_m;
6055 close csr_get_ent;
6056 hr_utility.set_location('total entitlements are :'||l_ent_m, 22);
6057 -- Check for sum of existing absences against additional entitlements
6058 open csr_exist_abs(l_hiredate);
6059 fetch csr_exist_abs into l_exist_absence;
6060 close csr_exist_abs;
6061 IF l_exist_absence IS NULL THEN
6062 l_exist_absence := 0;
6063 END IF;
6064 hr_utility.set_location('Total absences are : '||l_exist_absence, 22);
6065 --
6066 l_net_entitlement := l_ent_m - l_exist_absence;
6067 hr_utility.set_location('Net entitlements are : '||l_net_entitlement, 22);
6068 -- Assign OUT parameters
6069 p_total_ent := l_ent_m;
6070 p_net_ent := l_net_entitlement;
6071 --
6072 END get_fr_add_net_ent;
6073 --
6074 function get_contr_dates(p_assignment_id in number,
6075 p_calculation_start_date in date,
6079 return number is
6076 p_contract_start_date out nocopy date,
6077 p_contract_end_date out nocopy date,
6078 p_contract_category out nocopy varchar2)
6080
6081 cursor csr_min_effect_start_date(c_assignment_id per_all_assignments_f.assignment_id%type) is
6082 select min(effective_start_date)as min_effective_start_date
6083 from per_all_assignments_f
6084 where assignment_id=c_assignment_id;
6085
6086 cursor csr_fnd_contract_id(c_assignment_id per_all_assignments_f.assignment_id%type,
6087 c_min_effective_start_date per_all_assignments_f.effective_start_date%TYPE) is
6088 select contract_id,effective_end_date,effective_start_date
6089 from per_all_assignments_f
6090 where c_min_effective_start_date between effective_start_date and effective_end_date
6091 and assignment_id=c_assignment_id ;
6092
6093 -- Added new cursors for bugs 4099667 and 4103779.
6094 -- Modified cursor to find contract category
6095 cursor csr_contr_change_catg(c_contract_id per_all_assignments_f.contract_id%TYPE) is
6096 select effective_start_date, ctr_information2 con_catg
6097 from per_contracts_f
6098 where contract_id=c_contract_id
6099 and ctr_information_category = 'FR';
6100
6101 cursor csr_contr_max_end(c_contract_id per_all_assignments_f.contract_id%TYPE) is
6102 select max(effective_end_date)
6103 from per_contracts_f contr
6104 where contract_id=c_contract_id;
6105
6106 l_csr_min_effect_start_date csr_min_effect_start_date%rowtype;
6107 l_csr_fnd_contract_id csr_fnd_contract_id%rowtype;
6108 l_con_start_date date;
6109 l_con_end_date date;
6110 l_con_category varchar2(50);
6111 l_min_effective_start_date per_all_assignments_f.effective_start_date%TYPE;
6112 l_loop_count number;
6113
6114
6115 begin
6116
6117 open csr_min_effect_start_date(p_assignment_id);
6118 fetch csr_min_effect_start_date into l_csr_min_effect_start_date;
6119 close csr_min_effect_start_date;
6120
6121
6122 if l_csr_min_effect_start_date.min_effective_start_date < p_calculation_start_date then
6123 l_min_effective_start_date:=p_calculation_start_date;
6124 else
6125 l_min_effective_start_date:=l_csr_min_effect_start_date.min_effective_start_date;
6126 end if;
6127
6128 open csr_fnd_contract_id(p_assignment_id,l_min_effective_start_date);
6129 fetch csr_fnd_contract_id into l_csr_fnd_contract_id;
6130 close csr_fnd_contract_id;
6131
6132 if(l_csr_fnd_contract_id.contract_id is null)
6133 then
6134 p_contract_start_date:=l_csr_fnd_contract_id.effective_start_date;
6135 p_contract_end_date:=l_csr_fnd_contract_id.effective_end_date;
6136
6137 else
6138 --
6139 l_loop_count :=0;
6140 for c_contr_chg_catg in csr_contr_change_catg(l_csr_fnd_contract_id.contract_id) loop
6141 l_loop_count := l_loop_count +1;
6142 if l_loop_count = 1 then
6143 l_con_start_date := c_contr_chg_catg.effective_start_date;
6144 if c_contr_chg_catg.con_catg = 'PERMANENT' then
6145 l_con_category := c_contr_chg_catg.con_catg;
6146 exit;
6147 end if;
6148 else
6149 -- compare the previous and present categories
6150 if c_contr_chg_catg.con_catg <> l_con_category then
6151 -- note the start dates
6152 if months_between(c_contr_chg_catg.effective_start_date,l_con_start_date)<4 then
6153 l_con_category := c_contr_chg_catg.con_catg;
6154 end if;
6155 exit;
6156 end if;
6157 end if;
6158 l_con_category := c_contr_chg_catg.con_catg;
6159 end loop;
6160 --
6161 open csr_contr_max_end(l_csr_fnd_contract_id.contract_id);
6162 fetch csr_contr_max_end into l_con_end_date;
6163 close csr_contr_max_end;
6164 --
6165 p_contract_start_date:=l_con_start_date;
6166 p_contract_end_date:=l_con_end_date;
6167 p_contract_category := l_con_category;
6168 --
6169 end if;
6170 --
6171 IF(p_contract_start_date IS NULL) THEN
6172 select min(effective_end_date),min(effective_start_date) INTO p_contract_end_date,p_contract_start_date
6173 from per_all_assignments_f paf
6174 where paf.assignment_id=assignment_id ;
6175 RETURN 1;
6176 END IF;
6177 return 0;
6178
6179 end get_contr_dates;
6180 --
6181 ------------------------------------------------------------
6182 -- Function called from the DIF sub accrual formula
6183 -- to get the working time values.
6184 -- Added for bugs 4099667 and 4103779.
6185 ------------------------------------------------------------
6186 function get_time_values(p_business_group_id in number,
6187 p_assignment_id in number,
6188 p_effective_date in date,
6189 p_working_hours out nocopy number,
6190 p_working_frequency out nocopy varchar2,
6191 p_cipdz_catg out nocopy varchar2) return number
6192 is
6193 --
6194 l_working_hours number;
6195 l_working_frequency varchar2(3);
6196 l_cipdz_catg varchar2(3);
6197 --
6198 Cursor csr_get_time_catg is
6199 Select decode(con.ctr_information12,'HOUR', con.ctr_information13, asg.frequency) frequency,
6200 decode(con.ctr_information12,'HOUR', fnd_number.canonical_to_number(con.ctr_information11), asg.normal_hours) hours,
6201 substr(hruserdt.get_table_value(p_business_group_id, 'FR_CIPDZ', 'CIPDZ',nvl(asg.employment_category,'FR'),p_effective_date),1,1) cipdz_catg
6202 from per_all_assignments_f asg,
6203 per_contracts_f con
6204 where asg.assignment_id = p_assignment_id
6205 and asg.business_group_id = p_business_group_id
6206 and p_effective_date between
6207 asg.effective_start_date and asg.effective_end_date
6208 and asg.contract_id = con.contract_id
6209 and con.business_group_id = p_business_group_id
6210 and p_effective_date between
6211 con.effective_start_date and con.effective_end_date;
6212 --
6213 begin
6214 --
6215 OPEN csr_get_time_catg;
6216 FETCH csr_get_time_catg INTO l_working_frequency,l_working_hours, l_cipdz_catg;
6217 CLOSE csr_get_time_catg;
6218 --
6219 p_working_frequency := l_working_frequency;
6220 p_working_hours := l_working_hours;
6221 p_cipdz_catg := l_cipdz_catg;
6222 --
6223 return 1;
6224 end get_time_values;
6225 ----
6226 end pay_fr_pto_pkg;