[Home] [Help]
PACKAGE BODY: APPS.BEN_ELEMENT_ENTRY
Source
1 Package Body ben_element_entry as
2 /* $Header: benelmen.pkb 120.62.12020000.5 2013/01/15 03:36:12 usaraswa ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 -- Package Variables
9 --
10 g_debug boolean := hr_utility.debug_enabled;
11 g_package varchar2(33) := ' ben_element_entry.'; -- Global package name
12 g_skip_element varchar2(30);
13 --
14 g_hash_jump number := ben_hash_utility.get_hash_jump;
15 --
16 g_msg_displayed number :=0; --2530582
17 g_acty_base_rt_name ben_acty_base_rt_f.name%type := null;
18 --
19
20 type g_get_link_row is record
21 (assignment_id number
22 ,element_type_id number
23 ,session_date date
24 ,element_link_id number
25 );
26 --
27 type g_get_link_tbl is table of g_get_link_row
28 index by binary_integer;
29 --
30 type abr_asg_rec is record
31 (person_id number,
32 assignment_id number,
33 payroll_id number,
34 organization_id number,
35 asmt_to_use_cd varchar2(30),
36 effective_start_date date,
37 effective_end_date date);
38
39 type per_pay_rec is record
40 (assignment_id number,
41 end_date date,
42 payroll_was_ever_run boolean);
43
44 g_ext_inpval_tab ext_inpval_tab_typ;
45 g_outputs ff_exec.outputs_t;
46 g_get_link_cache g_get_link_tbl;
47 g_get_link_cached pls_integer := 0;
48 g_param_rec benutils.g_batch_param_rec;
49 g_abr_asg_rec abr_asg_rec;
50 g_per_pay_rec per_pay_rec;
51 g_max_end_date date := null;
52 --
53 -- Package cursors
54 --
55 cursor c_plan_year_end_for_pen
56 (c_prtt_enrt_rslt_id in number
57 ,c_rate_start_or_end_dt in date
58 ,c_effective_date in date
59 )
60 is
61 select distinct
62 yp.start_date,yp.end_date
63 from ben_prtt_enrt_rslt_f pen,
64 ben_popl_yr_perd pyp,
65 ben_yr_perd yp
66 where pen.prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
67 and pen.prtt_enrt_rslt_stat_cd is null
68 and c_effective_date <= pen.effective_end_date
69 and pyp.pl_id=pen.pl_id
70 and yp.yr_perd_id=pyp.yr_perd_id
71 and c_rate_start_or_end_dt
72 between yp.start_date and yp.end_date;
73 --
74 cursor c_plan_year_end_for_pl
75 (c_pl_id in number
76 ,c_rate_start_or_end_dt in date
77 )
78 is
79 select distinct
80 yp.start_date,yp.end_date
81 from ben_popl_yr_perd pyp,
82 ben_yr_perd yp
83 where pyp.pl_id=c_pl_id
84 and yp.yr_perd_id=pyp.yr_perd_id
85 and c_rate_start_or_end_dt
86 between yp.start_date and yp.end_date;
87 --
88 -- current result info
89 --
90 cursor c_current_result_info
91 (c_prtt_enrt_rslt_id in number
92 )
93 is
94 select pen.prtt_enrt_rslt_id,
95 pen.pl_id,
96 opt.opt_id,
97 pen.pgm_id,
98 pen.ler_id,
99 pen.pl_typ_id,
100 pen.person_id,
101 pen.effective_start_date,
102 pen.effective_end_date,
103 pen.uom
104 from ben_prtt_enrt_rslt_f pen,
105 ben_oipl_f opt
106 where pen.prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
107 and pen.prtt_enrt_rslt_stat_cd is null
108 and opt.oipl_id(+)=pen.oipl_id
109 and pen.enrt_cvg_strt_dt between opt.effective_start_date(+)
110 and opt.effective_end_date(+)
111 order by pen.effective_start_date desc;
112 --
113 g_result_rec c_current_result_info%rowtype;
114 --
115 -- prtt rt info
116 --
117 cursor c_get_prtt_rt_val
118 (c_prtt_rt_val_id in number
119 )
120 is
121 select prv.prtt_rt_val_id,
122 prv.acty_base_rt_id,
123 prv.prtt_enrt_rslt_id,
124 prv.rt_strt_dt,
125 prv.rt_end_dt,
126 prv.business_group_id,
127 prv.mlt_cd,
128 prv.acty_ref_perd_cd,
129 prv.rt_val,
130 prv.cmcd_rt_val,
131 prv.ann_rt_val,
132 prv.per_in_ler_id,
133 prv.element_entry_value_id,
134 prv.prtt_reimbmt_rqst_id,
135 prv.object_version_number
136 from ben_prtt_rt_val prv
137 where prtt_rt_val_id = c_prtt_rt_val_id;
138 --
139 l_prv_rec c_get_prtt_rt_val%ROWTYPE;
140 --
141 -- -------------------------------------------------------------
142 -- This cursor determines if any payroll actions exist because
143 -- of running payroll. Action type 'X' corresponds to payroll
144 -- actions that are not a result of payroll run. This is a
145 -- precursor to get_max_end_dt()
146 -- -------------------------------------------------------------
147 --
148 cursor c_payroll_was_ever_run
149 (c_assignment_id in number
150 )
151 is
152 select 'Y'
153 from pay_assignment_actions d,
154 pay_payroll_actions e
155 where d.assignment_id = c_assignment_id
156 and d.payroll_action_id = e.payroll_action_id
157 and e.action_type <> 'X';
158 --
159 -- This func replaces the cursor c_get_end_dt
160 --
161 -- ----------------------------------------------------------------------------
162 -- |-----------------------< get_max_end_dt >----------------------------|
163 -- ----------------------------------------------------------------------------
164 --
165 function get_max_end_dt (
166 p_assignment_id number,
167 p_payroll_id number,
168 p_element_type_id number,
169 p_effective_date date)
170 return date is
171 --
172 cursor c_asgact
173 (c_assignment_id in number
174 ,c_payroll_id in number
175 ) is
176 select d.assignment_action_id,
177 g.end_date
178 from pay_assignment_actions d,
179 pay_payroll_actions e,
180 per_time_periods g
181 where d.assignment_id = c_assignment_id
182 and g.payroll_id = c_payroll_id
183 and g.payroll_id = e.payroll_id
184 and d.payroll_action_id = e.payroll_action_id
185 and e.action_type in ('R','Q')
186 and e.time_period_id = g.time_period_id
187 and e.date_earned between g.start_date and g.end_date
188 order by g.end_date desc;
189
190 cursor c_chk_pac
191 (c_assignment_action_id in number
192 ,c_element_type_id in number
193 ) is
194 select 'x'
195 from pay_run_results h
196 where h.element_type_id = c_element_type_id
197 and h.assignment_action_id = c_assignment_action_id
198 and h.status in ('P', 'PA')
199 and h.source_type = 'E';
200
201 l_proc varchar2(72) := g_package||'get_max_end_dt';
202 l_v2dummy varchar2(30);
203 l_assignment_action_id number;
204 l_end_date date;
205 l_max_end_date date;
206
207 begin
208 --
209 if g_debug then
210 hr_utility.set_location('Entering: '||l_proc,5);
211 end if;
212 --
213 open c_asgact(p_assignment_id,
214 p_payroll_id);
215 loop
216 --
217 fetch c_asgact into l_assignment_action_id,
218 l_end_date;
219 if c_asgact%notfound then
220 exit;
221 end if;
222 --
223 open c_chk_pac(l_assignment_action_id,
224 p_element_type_id);
225 fetch c_chk_pac into l_v2dummy;
226 --
227 if c_chk_pac%found then
228 l_max_end_date := l_end_date;
229 close c_chk_pac;
230 exit;
231 end if;
232 --
233 close c_chk_pac;
234 --
235 end loop;
236 close c_asgact;
237 --
238 if g_debug then
239 hr_utility.set_location('Leaving: '||l_proc,5);
240 end if;
241 --
242 return l_max_end_date;
243 --
244 end get_max_end_dt;
245 --
246 -- ----------------------------------------------------------------------------
247 -- |-----------------------< chk_ele_processed >----------------------------|
248 -- ----------------------------------------------------------------------------
249 -- Returns 'Y' if the element entry has already been processed in a payroll
250 -- run.
251 --
252 function chk_ele_processed (
253 p_element_entry_id number,
254 p_original_entry_id number,
255 p_processing_type varchar2,
256 p_entry_type varchar2,
257 p_business_group_id number,
258 p_effective_date date)
259 return varchar2 is
260 --
261 --
262 -- Define how to determine if the entry is processed
263 --
264 cursor nonrecurring_entries (adjust_ee_source in varchar2) is
265 select 'Y'
266 from pay_run_results prr,
267 pay_element_entries_f pee
268 where pee.element_entry_id = p_element_entry_id
269 and p_effective_date between pee.effective_start_date
270 and pee.effective_end_date
271 and prr.source_id = decode(pee.entry_type,
272 'A', decode (adjust_ee_source,
273 'T', pee.target_entry_id,
274 pee.element_entry_id),
275 'R', decode (adjust_ee_source,
276 'T', pee.target_entry_id,
277 pee.element_entry_id),
278 pee.element_entry_id)
279 and prr.entry_type = pee.entry_type
280 and prr.source_type = 'E'
281 and prr.status <> 'U'
282 and not exists
283 (select 1
284 from pay_run_results sub_rr
285 where sub_rr.source_id = prr.run_result_id
286 and sub_rr.source_type in ('R', 'V')) ;
287 --
288 -- Bug 522510, recurring entries are considered as processed in the Date Earned
289 -- period, not Date Paid period - where run results exists.
290 --
291
292 cursor recurring_entries is
293 select 'Y'
294 from pay_run_results result,
295 pay_assignment_actions asgt_action,
296 pay_payroll_actions pay_action,
297 per_time_periods period
298 where result.source_id = nvl (p_original_entry_id, p_element_entry_id)
299 and result.status <> 'U'
300 and result.source_type = 'E'
301 and result.assignment_action_id = asgt_action.assignment_action_id
302 and asgt_action.payroll_action_id = pay_action.payroll_action_id
303 and pay_action.payroll_id = period.payroll_id
304 and pay_action.date_earned between period.start_date
305 and period.end_date
306 and not exists
307 (select 1
308 from pay_run_results rev_result
309 where rev_result.source_id = result.run_result_id
310 and rev_result.source_type in ('R', 'V'));
311 --
312 l_proc varchar2(72) := g_package||'chk_ele_processed';
313 l_processed varchar2(1) := 'N';
314 l_adjust_ee_source varchar2(1);
315
316 begin
317 --
318 if g_debug then
319 hr_utility.set_location('Entering: '||l_proc,5);
320 end if;
321 --
322 if (p_entry_type in ('S','D','A','R') or p_processing_type = 'N') then
323 --
324 begin
325 --
326 select plr.rule_mode
327 into l_adjust_ee_source
328 from pay_legislation_rules plr
329 , per_business_groups_perf pbgf
330 where plr.rule_type = 'ADJUSTMENT_EE_SOURCE'
331 and pbgf.legislation_code = plr.legislation_code
332 and pbgf.business_group_id = p_business_group_id;
333 --
334 exception
335 when no_data_found then
336 l_adjust_ee_source := 'A';
337 end;
338 --
339 open nonrecurring_entries(l_adjust_ee_source);
340 fetch nonrecurring_entries into l_processed;
341 close nonrecurring_entries;
342 --
343 else
344 --
345 open recurring_entries;
346 fetch recurring_entries into l_processed;
347 close recurring_entries;
348 --
349 end if;
350 --
351 if g_debug then
352 hr_utility.set_location('Leaving: '||l_proc,5);
353 end if;
354 --
355 return l_processed;
356 --
357 end chk_ele_processed;
358 --
359 -- ----------------------------------------------------------------------------
360 -- |-----------------------< clear_ext_inpval_tab>----------------------------|
361 -- ----------------------------------------------------------------------------
362 --
363 procedure clear_ext_inpval_tab is
364 l_proc varchar2(72) ;
365 begin
366 if g_debug then
367 l_proc := g_package||'clear_ext_inpval_tab';
368 hr_utility.set_location('Entering: '||l_proc,5);
369 end if;
370 --
371 -- Clear the pl/sql extra inputs cache
372 --
373 g_ext_inpval_tab.delete;
374
375 -- Reset g_ext_inpval_tab to null
376 for i in 1..14 loop
377 g_ext_inpval_tab(i).extra_input_value_id := null;
378 g_ext_inpval_tab(i).upd_when_ele_ended_cd := null;
379 g_ext_inpval_tab(i).input_value_id := null;
380 g_ext_inpval_tab(i).return_var_name := null;
381 g_ext_inpval_tab(i).return_value := null;
382 end loop;
383 --
384 if g_debug then
385 hr_utility.set_location('Leaving: '||l_proc,5);
386 end if;
387 end clear_ext_inpval_tab;
388 --
389 -- ----------------------------------------------------------------------------
390 -- |-----------------------< get_extra_ele_inputs>----------------------------|
391 -- ----------------------------------------------------------------------------
392 --
393 procedure get_extra_ele_inputs
394 (
395 p_effective_date in date
396 ,p_person_id in number
397 ,p_business_group_id in number
398 ,p_assignment_id in number
399 ,p_element_link_id in number
400 ,p_entry_type in varchar2
401 ,p_input_value_id1 in number
402 ,p_entry_value1 in varchar2
403 ,p_element_entry_id in number
404 ,p_acty_base_rt_id in number
405 ,p_input_va_calc_rl in number
406 ,p_abs_ler in boolean
407 ,p_organization_id in number
408 ,p_payroll_id in number
409 ,p_pgm_id in number
410 ,p_pl_id in number
411 ,p_pl_typ_id in number
412 ,p_opt_id in number
413 ,p_ler_id in number
414 ,p_dml_typ in varchar2
415 ,p_jurisdiction_code in varchar2
416 ,p_ext_inpval_tab out nocopy ext_inpval_tab_typ
417 ,p_subpriority out nocopy number
418 ) is
419
420 cursor c_ext_inpval
421 is
422 select eiv.extra_input_value_id,
423 eiv.input_value_id,
424 eiv.acty_base_rt_id,
425 eiv.input_text,
426 eiv.return_var_name,
427 eiv.upd_when_ele_ended_cd
428 from ben_extra_input_values eiv,
429 pay_input_values_f piv
430 where eiv.acty_base_rt_id = p_acty_base_rt_id
431 and eiv.business_group_id = p_business_group_id
432 and piv.input_value_id = eiv.input_value_id
433 and p_effective_date between piv.effective_start_date
434 and piv.effective_end_date
435 order by piv.display_sequence;
436 --
437 l_ext_inpval_rec c_ext_inpval%rowtype;
438 --
439 cursor c_abs_att is
440 select
441 aba.*, pil.per_in_ler_id
442 from per_absence_attendances aba,
443 ben_per_in_ler pil,
444 ben_ler_f ler
445 where aba.person_id = p_person_id
446 and pil.person_id = p_person_id
447 and aba.absence_attendance_id = pil.trgr_table_pk_id
448 and pil.ler_id = ler.ler_id
449 and ler.typ_cd = 'ABS'
450 and pil.per_in_ler_stat_cd = 'STRTD'
451 and p_effective_date between
452 ler.effective_start_date and ler.effective_end_date;
453 --
454 cursor c_inp_name is
455 select upper(replace(name,' ','_'))
456 from pay_input_values_f
457 where input_value_id = p_input_value_id1
458 and p_effective_date between
459 effective_start_date and effective_end_date;
460
461 l_per_abs_att_rec c_abs_att%rowtype;
462 --
463 l_param_tab ff_exec.outputs_t;
464 l_ext_inpval_tab ext_inpval_tab_typ;
465 l_counter number;
466 l_inp_name pay_input_values_f.name%type;
467 l_proc varchar2(72) := g_package||' get_extra_ele_inputs';
468
469 procedure populate_param_tab
470 (p_name in varchar2,
471 p_value in varchar2) is
472 l_next_index number;
473 begin
474
475 l_next_index := nvl(l_param_tab.count,0) + 1;
476 l_param_tab(l_next_index).name := p_name;
477 l_param_tab(l_next_index).value := p_value;
478
479 end;
480
481 begin
482 if g_debug then
483 hr_utility.set_location('Entering: '||l_proc,5);
484 hr_utility.set_location('p_input_va_calc_rl : '||p_input_va_calc_rl ,5);
485 end if;
486
487 clear_ext_inpval_tab;
488
489 if p_input_va_calc_rl is null
490 then
491 if p_input_value_id1 is not null and
492 p_abs_ler then
493
494 open c_inp_name;
495 fetch c_inp_name into l_inp_name;
496 close c_inp_name;
497
498 g_outputs(nvl(g_outputs.count,0)+1).name :=
499 nvl(l_inp_name,'LENGTH_OF_SERVICE');
500 g_outputs(g_outputs.count).value := p_entry_value1;
501 end if;
502 if g_debug then
503 hr_utility.set_location('Extra Input value RL not defined.Leaving ..',5);
504 end if;
505 return;
506 else
507 --
508 --
509 open c_abs_att;
510 fetch c_abs_att into l_per_abs_att_rec;
511 close c_abs_att;
512 --
513 -- Evaluate the formula and store the returned values into a pl/sql structure.
514 --
515 if g_debug then
516 hr_utility.set_location('Before formula executing : ',5);
517 hr_utility.set_location('Eff Date '||to_char(p_effective_date,'dd-mon-rrrr'),20);
518 end if;
519
520 populate_param_tab('BEN_ABS_IV_ABSENCE_ATTENDANCE_ID',
521 to_char(l_per_abs_att_rec.ABSENCE_ATTENDANCE_ID));
522 populate_param_tab('BEN_ABS_IV_PERSON_ID',to_char(l_per_abs_att_rec.PERSON_ID));
523 populate_param_tab('BEN_ABS_IV_DATE_START', to_char(l_per_abs_att_rec.DATE_START, 'YYYY/MM/DD HH24:MI:SS'));
524 populate_param_tab('BEN_ABS_IV_DATE_END', to_char(l_per_abs_att_rec.DATE_END, 'YYYY/MM/DD HH24:MI:SS'));
525 populate_param_tab('BEN_ABS_IV_ABSENCE_ATTENDANCE_TYPE_ID',
526 to_char(l_per_abs_att_rec.ABSENCE_ATTENDANCE_TYPE_ID));
527 populate_param_tab('BEN_ABS_IV_ABS_ATTENDANCE_REASON_ID',
528 to_char(l_per_abs_att_rec.ABS_ATTENDANCE_REASON_ID));
529 populate_param_tab('BEN_ABS_IV_SICKNESS_START_DATE',
530 to_char(l_per_abs_att_rec.SICKNESS_START_DATE, 'YYYY/MM/DD HH24:MI:SS'));
531 populate_param_tab('BEN_ABS_IV_SICKNESS_END_DATE',
532 to_char(l_per_abs_att_rec.SICKNESS_END_DATE, 'YYYY/MM/DD HH24:MI:SS'));
533 populate_param_tab('BEN_ABS_IV_ABSENCE_DAYS', to_char(l_per_abs_att_rec.ABSENCE_DAYS));
534 populate_param_tab('BEN_ABS_IV_ABSENCE_HOURS', to_char(l_per_abs_att_rec.ABSENCE_HOURS));
535 populate_param_tab('BEN_ABS_IV_DATE_NOTIFICATION',
536 to_char(l_per_abs_att_rec.DATE_NOTIFICATION, 'YYYY/MM/DD HH24:MI:SS'));
537 populate_param_tab('BEN_ABS_IV_DATE_PROJECTED_END',
538 to_char(l_per_abs_att_rec.DATE_PROJECTED_END, 'YYYY/MM/DD HH24:MI:SS'));
539 populate_param_tab('BEN_ABS_IV_DATE_PROJECTED_START',
540 to_char(l_per_abs_att_rec.DATE_PROJECTED_START, 'YYYY/MM/DD HH24:MI:SS'));
541 populate_param_tab('BEN_ABS_IV_TIME_END', l_per_abs_att_rec.TIME_END);
542 populate_param_tab('BEN_ABS_IV_TIME_PROJECTED_END', l_per_abs_att_rec.TIME_PROJECTED_END);
543 populate_param_tab('BEN_ABS_IV_TIME_PROJECTED_START', l_per_abs_att_rec.TIME_PROJECTED_START);
544 populate_param_tab('BEN_PIL_IV_PER_IN_LER_ID', to_char(l_per_abs_att_rec.PER_IN_LER_ID));
545 populate_param_tab('BEN_ABS_IV_SSP1_ISSUED', l_per_abs_att_rec.SSP1_ISSUED);
546 populate_param_tab('BEN_ABS_IV_LINKED_ABSENCE_ID',
547 to_char(l_per_abs_att_rec.LINKED_ABSENCE_ID));
548 populate_param_tab('BEN_ABS_IV_PREGNANCY_RELATED_ILLNESS',
549 l_per_abs_att_rec.PREGNANCY_RELATED_ILLNESS);
550 populate_param_tab('BEN_ABS_IV_MATERNITY_ID',to_char(l_per_abs_att_rec.MATERNITY_ID));
551 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION_CATEGORY', l_per_abs_att_rec.abs_information_category);
552 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION1', l_per_abs_att_rec.abs_information1);
553 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION2', l_per_abs_att_rec.abs_information2);
554 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION3', l_per_abs_att_rec.abs_information3);
555 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION4', l_per_abs_att_rec.abs_information4);
556 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION5', l_per_abs_att_rec.abs_information5);
557 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION6', l_per_abs_att_rec.abs_information6);
558 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION7', l_per_abs_att_rec.abs_information7);
559 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION8', l_per_abs_att_rec.abs_information8);
560 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION9', l_per_abs_att_rec.abs_information9);
561 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION10', l_per_abs_att_rec.abs_information10);
562 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION11', l_per_abs_att_rec.abs_information11);
563 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION12', l_per_abs_att_rec.abs_information12);
564 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION13', l_per_abs_att_rec.abs_information13);
565 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION14', l_per_abs_att_rec.abs_information14);
566 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION15', l_per_abs_att_rec.abs_information15);
567 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION16', l_per_abs_att_rec.abs_information16);
568 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION17', l_per_abs_att_rec.abs_information17);
569 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION18', l_per_abs_att_rec.abs_information18);
570 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION19', l_per_abs_att_rec.abs_information19);
571 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION20', l_per_abs_att_rec.abs_information20);
572 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION21', l_per_abs_att_rec.abs_information21);
573 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION22', l_per_abs_att_rec.abs_information22);
574 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION23', l_per_abs_att_rec.abs_information23);
575 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION24', l_per_abs_att_rec.abs_information24);
576 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION25', l_per_abs_att_rec.abs_information25);
577 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION26', l_per_abs_att_rec.abs_information26);
578 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION27', l_per_abs_att_rec.abs_information27);
579 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION28', l_per_abs_att_rec.abs_information28);
580 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION29', l_per_abs_att_rec.abs_information29);
581 populate_param_tab('BEN_ABS_IV_ABS_INFORMATION30', l_per_abs_att_rec.abs_information30);
582 populate_param_tab('BEN_ABS_IV_ATTRIBUTE_CATEGORY', l_per_abs_att_rec.attribute_category);
583 populate_param_tab('BEN_ABS_IV_ATTRIBUTE1', l_per_abs_att_rec.attribute1);
584 populate_param_tab('BEN_ABS_IV_ATTRIBUTE2', l_per_abs_att_rec.attribute2);
585 populate_param_tab('BEN_ABS_IV_ATTRIBUTE3', l_per_abs_att_rec.attribute3);
586 populate_param_tab('BEN_ABS_IV_ATTRIBUTE4', l_per_abs_att_rec.attribute4);
587 populate_param_tab('BEN_ABS_IV_ATTRIBUTE5', l_per_abs_att_rec.attribute5);
588 populate_param_tab('BEN_ABS_IV_ATTRIBUTE6', l_per_abs_att_rec.attribute6);
589 populate_param_tab('BEN_ABS_IV_ATTRIBUTE7', l_per_abs_att_rec.attribute7);
590 populate_param_tab('BEN_ABS_IV_ATTRIBUTE8', l_per_abs_att_rec.attribute8);
591 populate_param_tab('BEN_ABS_IV_ATTRIBUTE9', l_per_abs_att_rec.attribute9);
592 populate_param_tab('BEN_ABS_IV_ATTRIBUTE10', l_per_abs_att_rec.attribute10);
593 populate_param_tab('BEN_ABS_IV_ATTRIBUTE11', l_per_abs_att_rec.attribute11);
594 populate_param_tab('BEN_ABS_IV_ATTRIBUTE12', l_per_abs_att_rec.attribute12);
595 populate_param_tab('BEN_ABS_IV_ATTRIBUTE13', l_per_abs_att_rec.attribute13);
596 populate_param_tab('BEN_ABS_IV_ATTRIBUTE14', l_per_abs_att_rec.attribute14);
597 populate_param_tab('BEN_ABS_IV_ATTRIBUTE15', l_per_abs_att_rec.attribute15);
598 populate_param_tab('BEN_ABS_IV_ATTRIBUTE16', l_per_abs_att_rec.attribute16);
599 populate_param_tab('BEN_ABS_IV_ATTRIBUTE17', l_per_abs_att_rec.attribute17);
600 populate_param_tab('BEN_ABS_IV_ATTRIBUTE18', l_per_abs_att_rec.attribute18);
601 populate_param_tab('BEN_ABS_IV_ATTRIBUTE19', l_per_abs_att_rec.attribute19);
602 populate_param_tab('BEN_ABS_IV_ATTRIBUTE20', l_per_abs_att_rec.attribute20);
603
604 g_outputs.delete;
605 g_outputs := benutils.formula
606 (p_formula_id => p_input_va_calc_rl,
607 p_effective_date => p_effective_date,
608 p_business_group_id => p_business_group_id,
609 p_ler_id => p_ler_id,
610 p_assignment_id => p_assignment_id,
611 p_organization_id => p_organization_id,
612 p_pgm_id => p_pgm_id,
613 p_pl_typ_id => p_pl_typ_id,
614 p_pl_id => p_pl_id,
615 p_opt_id => p_opt_id,
616 p_acty_base_rt_id => p_acty_base_rt_id,
617 p_jurisdiction_code => p_jurisdiction_code,
618 p_param_tab => l_param_tab);
619
620 if g_debug then
621 hr_utility.set_location('formula count :'||g_outputs.count,5);
622 end if;
623
624 if p_input_value_id1 is not null and
625 p_abs_ler then
626
627 open c_inp_name;
628 fetch c_inp_name into l_inp_name;
629 close c_inp_name;
630
631 g_outputs(nvl(g_outputs.count,0)+1).name :=
632 nvl(l_inp_name,'LENGTH_OF_SERVICE');
633 g_outputs(g_outputs.count).value := p_entry_value1;
634 end if;
635
636 if g_debug then
637 hr_utility.set_location('After formula executing : ',5);
638 end if;
639 --
640 --
641 -- Loop through the returned table and make sure that the returned
642 -- values have been found
643
644 l_counter := 0;
645 --
646 for l_count in g_outputs.first..g_outputs.last loop
647 --
648 begin
649 --
650 -- order c_ext_inpval by pay_input_values.display_seq_number
651 -- While updating the element entry need to update the proper
652 -- input values. Ex., may be reuired to update 3, 8, 13th input's
653 -- All other's should be defaulted to what is on api definition.
654 --
655 for l_ext_inpval_rec in c_ext_inpval loop
656 --
657 -- Loop through ben_ext_inpval table and map the
658 -- formula output's to rows.
659 --
660 if g_outputs(l_count).name = l_ext_inpval_rec.return_var_name then
661 if ((p_dml_typ = 'C') or
662 (p_dml_typ = l_ext_inpval_rec.upd_when_ele_ended_cd)) then
663 --
664 -- Put in a pl/sql structure for extra inputs cache.
665 --
666 l_counter := l_counter + 1;
667 if g_debug then
668 hr_utility.set_location('Before assign extra inputs cache',11);
669 end if;
670 --
671 l_ext_inpval_tab(l_counter).extra_input_value_id
672 := l_ext_inpval_rec.extra_input_value_id;
673 l_ext_inpval_tab(l_counter).upd_when_ele_ended_cd
674 := l_ext_inpval_rec.upd_when_ele_ended_cd;
675 l_ext_inpval_tab(l_counter).input_value_id
676 := l_ext_inpval_rec.input_value_id;
677 l_ext_inpval_tab(l_counter).return_var_name
678 := l_ext_inpval_rec.return_var_name;
679 l_ext_inpval_tab(l_counter).return_value
680 := g_outputs(l_count).value;
681 end if;
682 --
683 elsif g_outputs(l_count).name = 'SUBPRIORITY' then
684 --
685 p_subpriority := to_number(g_outputs(l_count).value);
686 --
687 end if;
688 end loop;
689 exception
690 --
691 when others then
692 --
693 fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
694 fnd_message.set_token('PROC',l_proc);
695 --fnd_message.set_token('FORMULA',l_input_va_calc_rl_rec.input_va_calc_rl);
696 fnd_message.set_token('PARAMETER',g_outputs(l_count).name);
697 fnd_message.raise_error;
698 --
699 end;
700 --
701 end loop;
702 --
703 end if;
704 --
705 p_ext_inpval_tab := l_ext_inpval_tab;
706
707 for i in p_ext_inpval_tab.count+1..14
708 loop
709 p_ext_inpval_tab(i).extra_input_value_id := null;
710 p_ext_inpval_tab(i).upd_when_ele_ended_cd := null;
711 p_ext_inpval_tab(i).input_value_id := null;
712 p_ext_inpval_tab(i).return_var_name := null;
713 p_ext_inpval_tab(i).return_value := null;
714 end loop;
715
716 if g_debug then
717 hr_utility.set_location('Leaving: '||l_proc,5);
718 end if;
719 exception
720 --
721 when others then
722 if g_debug then
723 hr_utility.set_location('Error in get_extra_ele '||sqlerrm,5);
724 end if;
725 raise;
726
727 end get_extra_ele_inputs;
728 --
729 -- ----------------------------------------------------------------------------
730 -- |-----------------------< get_legislation_code>----------------------------|
731 -- ----------------------------------------------------------------------------
732 --
733 -- Gets the legislation code for a bg
734 --
735 function get_legislation_code
736 (p_business_group_id in number)
737 return varchar2 is
738
739 l_leg_code per_business_groups.legislation_code%type;
740 cursor c_leg is
741 select bg.legislation_code
742 from per_business_groups bg
743 where bg.business_group_id = p_business_group_id;
744
745 begin
746
747 open c_leg;
748 fetch c_leg into l_leg_code;
749 close c_leg;
750
751 return l_leg_code;
752
753 end;
754 --
755 -- ----------------------------------------------------------------------------
756 -- |-----------------------------< get_inpval_tab >---------------------------|
757 -- ----------------------------------------------------------------------------
758 --
759 procedure get_inpval_tab
760 (p_element_entry_id in number,
761 p_effective_date in date,
762 p_inpval_tab out nocopy inpval_tab_typ) is
763
764 /*
765 -- commented for bug 5721053
766 cursor c_inpval is
767 select input_value_id,
768 screen_entry_value
769 from pay_element_entry_values_f
770 where element_entry_id = p_element_entry_id
771 and p_effective_date between effective_start_date
772 and effective_end_date;
773 */
774 -- changed for bug 5721053
775 cursor c_inpval is
776 select peev.input_value_id,
777 peev.screen_entry_value,
778 piv.UOM
779 from pay_element_entry_values_f peev, pay_input_values_f piv
780 where peev.element_entry_id = p_element_entry_id
781 and p_effective_date between peev.effective_start_date and peev.effective_end_date
782 and piv.input_value_id = peev.input_value_id
783 and p_effective_date between piv.effective_start_date and piv.effective_end_date;
784
785 type t_input_value_id is table of number(15);
786 type t_value is table of varchar2(60);
787 type t_uom is table of VARCHAR2(30);
788
789 l_input_value_id t_input_value_id;
790 l_value t_value;
791 l_uom t_uom;
792 l_canonical_date date;
793
794
795 begin
796
797
798 open c_inpval;
799 fetch c_inpval bulk collect into l_input_value_id, l_value, l_uom;
800 close c_inpval;
801
802 for i in 1..l_input_value_id.count
803 loop
804 p_inpval_tab(i).input_value_id := l_input_value_id(i);
805 -- bug 5721053
806 IF l_uom (i) = 'D' OR l_uom (i) = 'DATE'
807 THEN
808 l_canonical_date := fnd_date.canonical_to_date (l_value (i));
809 p_inpval_tab (i).VALUE :=
810 fnd_date.date_to_displaydate (l_canonical_date);
811 -- Bug 6820098
812 ELSE
813 p_inpval_tab(i).value := l_value(i);
814 -- Bug 6820098
815 END IF;
816 -- end bug 5721053
817 end loop;
818
819 for i in (l_input_value_id.count + 1)..15
820 loop
821 p_inpval_tab(i).input_value_id := null;
822 p_inpval_tab(i).value := null;
823 end loop;
824
825 end get_inpval_tab;
826 -- ----------------------------------------------------------------------------
827 -- |---------------------------------< get_uom>-------------------------------|
828 -- ----------------------------------------------------------------------------
829 --
830 function get_uom
831 (p_business_group_id in number,
832 p_effective_date in date)
833 return varchar2 is
834
835 cursor get_pgm_curr_code (c_pgm_id number,
836 c_effective_date date,
837 c_business_group_id number) is
838 select pgm_uom
839 from ben_pgm_f
840 where pgm_id = c_pgm_id
841 and c_effective_date between effective_start_date
842 and effective_end_date
843 and business_group_id = c_business_group_id;
844
845 -- For plans not in progarms
846 cursor get_pl_curr_code (c_pl_id number,
847 c_effective_date date,
848 c_business_group_id number) is
849 select nip_pl_uom
850 from ben_pl_f
851 where pl_id = c_pl_id
852 and c_effective_date between effective_start_date
853 and effective_end_date
854 and business_group_id = c_business_group_id;
855
856 l_uom varchar2(30);
857
858 begin
859
860 if g_debug then
861 hr_utility.set_location('g_result_rec.pgm_id='|| g_result_rec.pgm_id,5);
862 hr_utility.set_location('g_result_rec.pl_id='|| g_result_rec.pl_id,5);
863 end if;
864
865 if g_result_rec.pgm_id is not null then
866
867 open get_pgm_curr_code
868 ( g_result_rec.pgm_id
869 ,p_effective_date
870 ,p_business_group_id);
871 fetch get_pgm_curr_code into l_uom;
872 close get_pgm_curr_code;
873
874 elsif g_result_rec.pl_id is not null then
875
876 open get_pl_curr_code
877 ( g_result_rec.pl_id
878 ,p_effective_date
879 ,p_business_group_id);
880 fetch get_pl_curr_code into l_uom;
881 close get_pl_curr_code;
882
883 end if;
884
885 if g_debug then
886 hr_utility.set_location('l_uom ='||l_uom,432);
887 end if;
888
889 return l_uom;
890
891 end;
892 --
893 -- ----------------------------------------------------------------------------
894 -- |------------------------------< chkformat>--------------------------------|
895 -- ----------------------------------------------------------------------------
896 --
897 function chkformat(p_value in varchar2
898 ,p_curr_code in varchar2)
899 return number is
900
901 changed_val varchar2(60);
902 nvalue number;
903
904 begin
905
906 nvalue := fnd_number.canonical_to_number(p_value);
907
908 if p_curr_code is null then
909 return to_number(p_value);
910 end if;
911
912 SELECT LTRIM
913 ( TO_CHAR
914 ( DECODE --round to min acct limits if available.
915 ( fc.minimum_accountable_unit,
916 NULL, ROUND( nvalue, fc.precision ),
917 ROUND( nvalue / fc.minimum_accountable_unit ) * fc.minimum_accountable_unit
918 )
919 , CONCAT --construct NLS format mask.
920 ( '99999999999999999990', --currencies formatted without NLS 'G'.
921 DECODE( fc.precision, 0, '', RPAD( 'D', fc.precision+1, '9' ) )
922 )
923 ), ' ' --left trim white space.
924 )
925 INTO changed_val
926 FROM fnd_currencies fc
927 WHERE fc.currency_code = p_curr_code;
928
929 return to_number(changed_val);
930
931 exception
932 when others then
933 return to_number(p_value);
934
935 end chkformat;
936 --
937 -- ----------------------------------------------------------------------------
938 -- |-------------------------< get_ele_dt_upd_mode>---------------------------|
939 -- ----------------------------------------------------------------------------
940 --
941 function get_ele_dt_upd_mode
942 (p_effective_date in date,
943 p_base_key_value in number)
944 return varchar2 is
945
946 l_correction boolean;
947 l_update boolean;
948 l_update_override boolean;
949 l_update_change_insert boolean;
950 l_upd_mode varchar2(30);
951
952 begin
953
954 dt_api.find_dt_upd_modes
955 (p_effective_date => p_effective_date,
956 p_base_table_name => 'PAY_ELEMENT_ENTRIES_F',
957 p_base_key_column => 'element_entry_id',
958 p_base_key_value => p_base_key_value,
959 p_correction => l_correction,
960 p_update => l_update,
961 p_update_override => l_update_override,
962 p_update_change_insert => l_update_change_insert);
963
964 if l_update then
965 l_upd_mode := hr_api.g_update;
966 elsif l_update_override then
967 l_upd_mode := hr_api.g_update_override;
968 else
969 l_upd_mode := hr_api.g_correction;
970 end if;
971
972 return l_upd_mode;
973
974 end;
975 --
976 -- ----------------------------------------------------------------------------
977 -- |-------------------------< cache_quick_pay_run>---------------------------|
978 -- ----------------------------------------------------------------------------
979 --
980 -- Retro pay process for Quick pay run
981 procedure cache_quick_pay_run
982 (p_person_id number,
983 p_element_type_id number,
984 p_assignment_id number,
985 p_element_entry_id number,
986 p_effective_date date,
987 p_start_date date,
988 p_end_date date,
989 p_payroll_id number)
990 is
991 --
992 cursor c_quick_pay_inclusion (p_assignment_id number,
993 p_effective_date date,
994 p_element_type_id number) is
995 select qi.assignment_action_id,
996 qi.element_entry_id,
997 tp.end_date
998 from pay_assignment_actions aa,
999 pay_payroll_actions pa,
1000 pay_quickpay_inclusions qi,
1001 pay_element_links_f el,
1002 pay_element_entries_f ee,
1003 per_time_periods tp
1004 where aa.assignment_id = p_assignment_id
1005 and pa.payroll_action_id = aa.payroll_action_id
1006 and pa.action_type = 'Q'
1007 and pa.time_period_id = tp.time_period_id
1008 and p_effective_date between tp.start_date and tp.end_date
1009 and aa.assignment_action_id = qi.assignment_action_id
1010 and ee.element_entry_id = qi.element_entry_id
1011 and aa.assignment_id = ee.assignment_id
1012 and el.element_link_id = ee.element_link_id
1013 and el.element_type_id = p_element_type_id
1014 and pa.effective_date between el.effective_start_date and
1015 el.effective_end_date
1016 and pa.effective_date between ee.effective_start_date and
1017 ee.effective_end_date;
1018 --
1019 cursor c_periods(v_payroll_id in number,
1020 v_start_date in date,
1021 v_end_date in date) is
1022 select end_date
1023 from per_time_periods ptp
1024 where ptp.payroll_id = v_payroll_id
1025 and ptp.end_date between
1026 v_start_date and v_end_date;
1027 l_quick_pay_inclusion c_quick_pay_inclusion%rowtype;
1028 l_end_date date;
1029 l_count number;
1030
1031 --
1032 begin
1033 --
1034 hr_utility.set_location('Enter : Cache quick pay',111);
1035 open c_periods (p_payroll_id, p_start_date,p_end_date);
1036 loop
1037 fetch c_periods into l_end_date;
1038 if c_periods%notfound then
1039 exit;
1040 --
1041 else
1042 --
1043 hr_utility.set_location('End date : '||l_end_date,112);
1044 open c_quick_pay_inclusion (p_assignment_id,
1045 l_end_date,
1046 p_element_type_id);
1047 fetch c_quick_pay_inclusion into l_quick_pay_inclusion;
1048 if c_quick_pay_inclusion%found then
1049 --pop cache
1050 if g_cache_quick_payrun_object.count > 0 then
1051 if g_cache_quick_payrun_object(1).person_id <> p_person_id then
1052 g_cache_quick_payrun_object.delete;
1053 hr_utility.set_location('Delete : Cache quick pay',113);
1054 end if;
1055 end if;
1056 l_count := nvl(g_cache_quick_payrun_object.last,0) + 1;
1057 -- assign the values into cache
1058 g_cache_quick_payrun_object(l_count).person_id := p_person_id;
1059 g_cache_quick_payrun_object(l_count).element_type_id := p_element_type_id;
1060 g_cache_quick_payrun_object(l_count).assignment_id := p_assignment_id;
1061 g_cache_quick_payrun_object(l_count).assignment_action_id :=
1062 l_quick_pay_inclusion.assignment_action_id;
1063 g_cache_quick_payrun_object(l_count).payroll_end_date :=
1064 l_quick_pay_inclusion.end_date;
1065 hr_utility.set_location('Assignment Action id'||g_cache_quick_payrun_object(l_count).assignment_action_id, 113);
1066 end if;
1067 close c_quick_pay_inclusion;
1068 end if;
1069 end loop;
1070 close c_periods;
1071 --
1072 end;
1073 --
1074 --
1075 -- ----------------------------------------------------------------------------
1076 -- |--------------------------< insert_into_quick_pay>------------------------|
1077 -- ----------------------------------------------------------------------------
1078 --
1079 procedure insert_into_quick_pay
1080 (p_person_id number,
1081 p_element_type_id number,
1082 p_assignment_id number,
1083 p_element_entry_id number,
1084 p_effective_date date,
1085 p_start_date date,
1086 p_end_date date,
1087 p_payroll_id number) is
1088 --
1089 cursor c_periods(v_payroll_id in number,
1090 v_start_date in date,
1091 v_end_date in date) is
1092 select end_date
1093 from per_time_periods ptp
1094 where ptp.payroll_id = v_payroll_id
1095 and ptp.end_date between
1096 v_start_date and v_end_date;
1097 l_end_date date;
1098 l_count number;
1099 --
1100 begin
1101 --
1102 hr_utility.set_location('Enter : insert into quick pay',111);
1103 open c_periods (p_payroll_id, p_start_date,p_end_date);
1104 loop
1105 fetch c_periods into l_end_date;
1106 if c_periods%notfound then
1107 --
1108 exit;
1109 --
1110 else
1111 --
1112 if g_cache_quick_payrun_object.count > 0 then
1113 for j in g_cache_quick_payrun_object.first .. g_cache_quick_payrun_object.last
1114 loop
1115 if g_cache_quick_payrun_object(j).person_id = p_person_id and
1116 g_cache_quick_payrun_object(j).element_type_id = p_element_type_id and
1117 g_cache_quick_payrun_object(j).payroll_end_date = l_end_date then
1118 hr_utility.set_location('Insert quick pay'||p_element_entry_id,11);
1119 hr_utility.set_location('Assignment action Id'||g_cache_quick_payrun_object(j).assignment_action_id, 12);
1120 insert into pay_quickpay_inclusions (element_entry_id, assignment_action_id)
1121 values (p_element_entry_id,g_cache_quick_payrun_object(j).assignment_action_id);
1122 end if;
1123 end loop;
1124 end if;
1125 end if;
1126 end loop;
1127 close c_periods;
1128 End;
1129
1130 -- ----------------------------------------------------------------------------
1131 -- |-----------------------< get_abr_assignment >-----------------------------|
1132 -- ----------------------------------------------------------------------------
1133 procedure get_abr_assignment
1134 (p_person_id in number
1135 ,p_effective_date in date
1136 ,p_acty_base_rt_id in number
1137 ,p_organization_id out nocopy number
1138 ,p_payroll_id out nocopy number
1139 ,p_assignment_id out nocopy number
1140 )
1141 is
1142 --
1143 cursor get_asmt_to_use_cd
1144 (c_acty_base_rt_id in number
1145 ,c_effective_date in date
1146 )
1147 is
1148 select abr.asmt_to_use_cd
1149 from ben_acty_base_rt_f abr
1150 where abr.acty_base_rt_id = c_acty_base_rt_id
1151 and c_effective_date between
1152 abr.effective_start_date and abr.effective_end_date;
1153 --
1154 -- Cursor to get assignment_id
1155 --
1156 CURSOR get_assignment (
1157 c_person_id IN NUMBER,
1158 c_assignment_type IN VARCHAR2,
1159 c_effective_date IN DATE
1160 )
1161 IS
1162 SELECT asg.assignment_id, asg.payroll_id, asg.organization_id,
1163 asg.effective_start_date, asg.effective_end_date
1164 FROM per_all_assignments_f asg, per_assignment_status_types ast
1165 WHERE asg.person_id = c_person_id
1166 AND asg.assignment_type <> 'C'
1167 AND asg.primary_flag = 'Y'
1168 AND asg.assignment_status_type_id = ast.assignment_status_type_id
1169 -- AND ast.per_system_status <> 'TERM_ASSIGN' /* Bug 5655933 */
1170 AND asg.assignment_type =
1171 NVL (c_assignment_type, asg.assignment_type)
1172 AND c_effective_date BETWEEN asg.effective_start_date
1173 AND asg.effective_end_date
1174 ORDER BY asg.assignment_type DESC ; -- Bug 4463077 : Look for employee assignment and then for benefits asg
1175 --
1176 l_effective_start_date date;
1177 l_effective_end_date date;
1178 l_asmt_to_use_cd VARCHAR2(30);
1179 l_proc VARCHAR2(72) := g_package||'get_abr_assignment';
1180 --
1181 begin
1182 --
1183 g_debug := hr_utility.debug_enabled;
1184 if g_debug then
1185 hr_utility.set_location('Entering: '||l_proc,5);
1186 hr_utility.set_location('p_effective_date: '||p_effective_date,5);
1187 end if;
1188 --
1189 -- get assignment to use code.
1190 --
1191 open get_asmt_to_use_cd
1192 (c_acty_base_rt_id => p_acty_base_rt_id
1193 ,c_effective_date => p_effective_date
1194 );
1195 fetch get_asmt_to_use_cd into l_asmt_to_use_cd;
1196 if get_asmt_to_use_cd%notfound then
1197 close get_asmt_to_use_cd;
1198 if g_debug then
1199 hr_utility.set_location('BEN_91723_NO_ENRT_RT_ABR_FOUND',30);
1200 end if;
1201 fnd_message.set_name('BEN','BEN_91723_NO_ENRT_RT_ABR_FOUND');
1202 fnd_message.set_token('PROC',l_proc);
1203 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
1204 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
1205 fnd_message.raise_error;
1206 else
1207 close get_asmt_to_use_cd;
1208 end if;
1209 --
1210 -- check if this info is already cached
1211 --
1212 if g_abr_asg_rec.person_id = p_person_id and
1213 nvl(l_asmt_to_use_cd,'ETB') <> 'BTE' and --------Bug 8394662
1214 nvl(g_abr_asg_rec.asmt_to_use_cd,'ETB') = nvl(l_asmt_to_use_cd,'ETB') and
1215 (p_effective_date between g_abr_asg_rec.effective_start_date and
1216 g_abr_asg_rec.effective_end_date) then
1217
1218 p_assignment_id := g_abr_asg_rec.assignment_id;
1219 p_payroll_id := g_abr_asg_rec.payroll_id;
1220 p_organization_id := g_abr_asg_rec.organization_id;
1221
1222 if g_debug then
1223 hr_utility.set_location('asmt_to_use_cd: '||l_asmt_to_use_cd,5);
1224 hr_utility.set_location('organization_id: '||p_organization_id,5);
1225 hr_utility.set_location('payroll_id: '||p_payroll_id,5);
1226 hr_utility.set_location('assignment_id: '||p_assignment_id,5);
1227 hr_utility.set_location('Leaving: '||l_proc,5);
1228 end if;
1229 return;
1230 else
1231 g_abr_asg_rec.person_id := null;
1232 g_abr_asg_rec.assignment_id := null;
1233 g_abr_asg_rec.payroll_id := null;
1234 g_abr_asg_rec.organization_id := null;
1235 g_abr_asg_rec.effective_start_date := null;
1236 g_abr_asg_rec.effective_end_date := null;
1237 end if;
1238 --
1239 -- Check the assigment to use code to get the assignment id
1240 -- for the element entry.
1241 --
1242 if (l_asmt_to_use_cd = 'EAO') then
1243 --
1244 -- Employee assignment only.
1245 --
1246 open get_assignment
1247 (c_person_id => p_person_id
1248 ,c_assignment_type => 'E'
1249 ,c_effective_date => p_effective_date
1250 );
1251 fetch get_assignment into p_assignment_id
1252 ,p_payroll_id
1253 ,p_organization_id
1254 ,l_effective_start_date
1255 ,l_effective_end_date;
1256 close get_assignment;
1257 --
1258 elsif l_asmt_to_use_cd = 'BAO' then
1259 --
1260 -- Benefit assignment only.
1261 --
1262 open get_assignment
1263 (c_person_id => p_person_id
1264 ,c_assignment_type => 'B'
1265 ,c_effective_date => p_effective_date
1266 );
1267 fetch get_assignment into p_assignment_id
1268 ,p_payroll_id
1269 ,p_organization_id
1270 ,l_effective_start_date
1271 ,l_effective_end_date;
1272 close get_assignment;
1273 --
1274 elsif l_asmt_to_use_cd = 'BTE' then
1275 --
1276 -- Benefit assignment then employee assignment.
1277 --
1278 open get_assignment
1279 (c_person_id => p_person_id
1280 ,c_assignment_type => 'B'
1281 ,c_effective_date => p_effective_date
1282 );
1283 fetch get_assignment into p_assignment_id
1284 ,p_payroll_id
1285 ,p_organization_id
1286 ,l_effective_start_date
1287 ,l_effective_end_date;
1288 if get_assignment%notfound then
1289 close get_assignment;
1290 if g_debug then
1291 hr_utility.set_location('Benefit assignment not found- BTE',5);
1292 end if;
1293 --
1294 -- Get employee assignment.
1295 --
1296 open get_assignment
1297 (c_person_id => p_person_id
1298 ,c_assignment_type => 'E'
1299 ,c_effective_date => p_effective_date
1300 );
1301 fetch get_assignment into p_assignment_id
1302 ,p_payroll_id
1303 ,p_organization_id
1304 ,l_effective_start_date
1305 ,l_effective_end_date;
1306 close get_assignment;
1307 else
1308 close get_assignment;
1309 end if;
1310 --
1311 /* elsif l_asmt_to_use_cd = 'ANY' then
1312 --
1313 -- Any assignment only.
1314 --
1315 open get_assignment
1316 (c_person_id => p_person_id
1317 ,c_assignment_type => null
1318 ,c_effective_date => p_effective_date
1319 );
1320 fetch get_assignment into p_assignment_id
1321 ,p_payroll_id
1322 ,p_organization_id
1323 ,l_effective_start_date
1324 ,l_effective_end_date;
1325 close get_assignment;
1326 --
1327 */
1328 elsif (l_asmt_to_use_cd = 'EBA' or l_asmt_to_use_cd = 'ANY' ) then
1329 --
1330 -- Employee assignment then benefit assignment.
1331 --
1332 open get_assignment
1333 (c_person_id => p_person_id
1334 ,c_assignment_type => 'E'
1335 ,c_effective_date => p_effective_date
1336 );
1337 fetch get_assignment into p_assignment_id
1338 ,p_payroll_id
1339 ,p_organization_id
1340 ,l_effective_start_date
1341 ,l_effective_end_date;
1342 if get_assignment%notfound then
1343 close get_assignment;
1344 --
1345 -- Get benefit assignment.
1346 --
1347 open get_assignment
1348 (c_person_id => p_person_id
1349 ,c_assignment_type => 'B'
1350 ,c_effective_date => p_effective_date
1351 );
1352 fetch get_assignment into p_assignment_id
1353 ,p_payroll_id
1354 ,p_organization_id
1355 ,l_effective_start_date
1356 ,l_effective_end_date;
1357 if get_assignment%notfound then
1358 close get_assignment;
1359 --
1360 -- Get applicant assignment.
1361 --
1362 open get_assignment
1363 (c_person_id => p_person_id
1364 ,c_assignment_type => 'A'
1365 ,c_effective_date => p_effective_date
1366 );
1367 fetch get_assignment into p_assignment_id
1368 ,p_payroll_id
1369 ,p_organization_id
1370 ,l_effective_start_date
1371 ,l_effective_end_date;
1372 close get_assignment;
1373 else
1374 close get_assignment;
1375 end if;
1376 else
1377 close get_assignment;
1378 end if;
1379 --
1380 elsif (l_asmt_to_use_cd = 'ETB' or l_asmt_to_use_cd is null) then
1381 --
1382 -- Employee assignment then benefit assignment. - Default
1383 --
1384 open get_assignment
1385 (c_person_id => p_person_id
1386 ,c_assignment_type => 'E'
1387 ,c_effective_date => p_effective_date
1388 );
1389 fetch get_assignment into p_assignment_id
1390 ,p_payroll_id
1391 ,p_organization_id
1392 ,l_effective_start_date
1393 ,l_effective_end_date;
1394 if get_assignment%notfound then
1395 if g_debug then
1396 hr_utility.set_location('Employee assignment not found- ETB',5);
1397 end if;
1398 close get_assignment;
1399 --
1400 -- Get benefit assignment.
1401 --
1402 open get_assignment
1403 (c_person_id => p_person_id
1404 ,c_assignment_type => 'B'
1405 ,c_effective_date => p_effective_date
1406 );
1407 fetch get_assignment into p_assignment_id
1408 ,p_payroll_id
1409 ,p_organization_id
1410 ,l_effective_start_date
1411 ,l_effective_end_date;
1412 close get_assignment;
1413 else
1414 close get_assignment;
1415 end if;
1416 --
1417 elsif l_asmt_to_use_cd = 'AAO' then
1418 --
1419 -- Applicant assignment only.
1420 --
1421 open get_assignment
1422 (c_person_id => p_person_id
1423 ,c_assignment_type => 'A'
1424 ,c_effective_date => p_effective_date
1425 );
1426 fetch get_assignment into p_assignment_id
1427 ,p_payroll_id
1428 ,p_organization_id
1429 ,l_effective_start_date
1430 ,l_effective_end_date;
1431 close get_assignment;
1432 --
1433 end if;
1434 --
1435 g_abr_asg_rec.person_id := p_person_id;
1436 g_abr_asg_rec.assignment_id := p_assignment_id;
1437 g_abr_asg_rec.payroll_id := p_payroll_id;
1438 g_abr_asg_rec.organization_id := p_organization_id;
1439 g_abr_asg_rec.effective_start_date := l_effective_start_date;
1440 g_abr_asg_rec.effective_end_date := l_effective_end_date;
1441 -- added for bug 5909589
1442 g_abr_asg_rec.asmt_to_use_cd := l_asmt_to_use_cd;
1443
1444 if g_debug then
1445 hr_utility.set_location('asmt_to_use_cd: '||l_asmt_to_use_cd,60);
1446 hr_utility.set_location('organization_id: '||p_organization_id,60);
1447 hr_utility.set_location('payroll_id: '||p_payroll_id,60);
1448 hr_utility.set_location('assignment_id: '||p_assignment_id,60);
1449 hr_utility.set_location('Leaving: '||l_proc,60);
1450 end if;
1451 --
1452 end get_abr_assignment;
1453 --
1454 -- ----------------------------------------------------------------------------
1455 -- |-----------------------< get_default_payroll >----------------------------|
1456 -- ----------------------------------------------------------------------------
1457 --
1458 function get_default_payroll
1459 (p_business_group_id in number
1460 ,p_effective_date in date
1461 ) return number
1462 is
1463 --
1464 l_payroll_id number;
1465 l_proc varchar2(72) := g_package||'get_default_payroll';
1466 --
1467 cursor c_get_default_payroll
1468 (c_business_group_id in number
1469 ,c_effective_date in date
1470 )
1471 is
1472 select payroll_id
1473 from pay_payrolls_f
1474 where business_group_id = c_business_group_id
1475 and period_type = 'Calendar Month'
1476 and c_effective_date
1477 between effective_start_date and effective_end_date;
1478 --
1479 begin
1480
1481 if g_debug then
1482 hr_utility.set_location('Entering:' ||l_proc,5);
1483 end if;
1484
1485 open c_get_default_payroll
1486 (c_business_group_id => p_business_group_id
1487 ,c_effective_date => p_effective_date
1488 );
1489 fetch c_get_default_payroll into l_payroll_id;
1490 close c_get_default_payroll;
1491
1492 if g_debug then
1493 hr_utility.set_location('Leaving:' ||l_proc,5);
1494 end if;
1495
1496 return l_payroll_id;
1497
1498 end get_default_payroll;
1499
1500 -- ----------------------------------------------------------------------------
1501 -- |-----------------------< chk_assign_exists >-----------------------------|
1502 -- ----------------------------------------------------------------------------
1503 -- This Function checks the existence of a current
1504 -- Employee or Benefits assignment
1505 -- and returns the assignment_id and payroll_id
1506 --
1507 function chk_assign_exists
1508 (p_person_id IN NUMBER
1509 ,p_business_group_id IN NUMBER
1510 ,p_effective_date IN DATE
1511 ,p_rate_date IN DATE
1512 ,p_acty_base_rt_id IN number
1513 ,p_assignment_id IN OUT NOCOPY NUMBER
1514 ,p_organization_id in out nocopy number
1515 ,p_payroll_id IN OUT NOCOPY NUMBER
1516 ) RETURN BOOLEAN
1517 is
1518 --
1519 l_proc varchar2(72) := g_package||'chk_assign_exists';
1520 --
1521 cursor c1 is
1522 select nvl(abr.ele_entry_val_cd,'PP') ele_entry_val_cd,
1523 abr.name
1524 from ben_acty_base_rt_f abr
1525 where abr.acty_base_rt_id = p_acty_base_rt_id
1526 and p_rate_date between abr.effective_start_date
1527 and abr.effective_end_date;
1528 --
1529 l_ele_entry_val_cd varchar2(30);
1530 l_name ben_acty_base_rt_f.name%TYPE ;
1531 --
1532 begin
1533 g_debug := hr_utility.debug_enabled;
1534 if g_debug then
1535 hr_utility.set_location('Entering:' ||l_proc,5);
1536 end if;
1537
1538 -- First look for an assignment based on the date the rate is being
1539 -- started or ended. We need to do this so that we pick up the correct
1540 -- assignment that the EE should be attached to. For example: if we are
1541 -- processing a termination event on 5/15 and we want to end a person's
1542 -- EE from prior enrollments, we need to pick up the Employee assignment
1543 -- that exists on 5/14 (rate end date), not the benefit's assignment that
1544 -- is created on 5/15.
1545
1546 if g_debug then
1547 hr_utility.set_location('p_assignment_id:' ||p_assignment_id,5);
1548 end if;
1549 get_abr_assignment (p_person_id => p_person_id
1550 ,p_effective_date => p_rate_date
1551 ,p_acty_base_rt_id => p_acty_base_rt_id
1552 ,p_organization_id => p_organization_id
1553 ,p_payroll_id => p_payroll_id
1554 ,p_assignment_id => p_assignment_id);
1555 if g_debug then
1556 hr_utility.set_location('p_assignment_id:' ||p_assignment_id,10);
1557 end if;
1558 --Bug 3151737 and 3063518
1559 open c1 ;
1560 fetch c1 into l_ele_entry_val_cd,l_name ;
1561 close c1 ;
1562 --
1563 if p_assignment_id is NOT NULL then
1564 --
1565 -- Bug 3151737 and 3063518 Why we do we care this for non EPP / PP cases.
1566 -- User needs explicitly mention communicated or defined value in the value passed
1567 -- to payroll if they are not using the payroll .
1568 -- Then we don't need to care for payroll and also we don't need to compute
1569 -- the pp amount using the bendisrt routines
1570 --
1571 if l_ele_entry_val_cd = 'PP' or
1572 l_ele_entry_val_cd = 'EPP' then
1573 --
1574 if p_payroll_id is null then
1575 /*
1576 if g_debug then
1577 hr_utility.set_location('BEN_92458_NO_ASG_PAYROLL PERSON:'|| to_char(p_person_id),5);
1578 end if;
1579 fnd_message.set_name('BEN', 'BEN_92458_NO_ASG_PAYROLL');
1580 fnd_message.set_token('PROC',l_proc);
1581 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
1582 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
1583 fnd_message.raise_error;
1584 */
1585 if g_debug then
1586 hr_utility.set_location('BEN_93606_NO_ASG_PAYROLL PERSON:'|| to_char(p_person_id),5);
1587 end if;
1588 fnd_message.set_name('BEN', 'BEN_93606_NO_ASG_PAYROLL');
1589 fnd_message.set_token('ABR_NAME', l_name);
1590 fnd_message.set_token('PROC',l_proc);
1591 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
1592 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
1593 fnd_message.raise_error;
1594 end if;
1595 --
1596 end if;
1597 --
1598 return TRUE;
1599 else
1600
1601 -- If there is no assignment on the date the rate is to be started or ended,
1602 -- look for an assignment on the effective date. Example: A new hire event
1603 -- is processsed on 5/15, enrollments are made. On 5/18, the enrollment is
1604 -- changed, the new enrollment is started on 5/15 (as of event date),
1605 -- the old one is ended on 5/14 (one day before event date), there is no
1606 -- assignment on 5/14 (because it was a new hire on 5/15).
1607 --
1608 get_abr_assignment (p_person_id => p_person_id
1609 ,p_effective_date => p_effective_date
1610 ,p_acty_base_rt_id => p_acty_base_rt_id
1611 ,p_organization_id => p_organization_id
1612 ,p_payroll_id => p_payroll_id
1613 ,p_assignment_id => p_assignment_id);
1614 if p_assignment_id is NOT NULL then
1615 --
1616 if l_ele_entry_val_cd = 'PP' or
1617 l_ele_entry_val_cd = 'EPP' then
1618 --
1619 if p_payroll_id is null then
1620 /*
1621 if g_debug then
1622 hr_utility.set_location('BEN_92458_NO_ASG_PAYROLL PERSON:'|| to_char(p_person_id),5);
1623 end if;
1624 fnd_message.set_name('BEN', 'BEN_92458_NO_ASG_PAYROLL');
1625 fnd_message.set_token('PROC',l_proc);
1626 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
1627 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
1628 fnd_message.raise_error;
1629 */
1630 if g_debug then
1631 hr_utility.set_location('BEN_93606_NO_ASG_PAYROLL PERSON:'|| to_char(p_person_id),5);
1632 end if;
1633 fnd_message.set_name('BEN', 'BEN_93606_NO_ASG_PAYROLL');
1634 fnd_message.set_token('ABR_NAME', l_name);
1635 fnd_message.set_token('PROC',l_proc);
1636 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
1637 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
1638 fnd_message.raise_error;
1639 end if;
1640 end if;
1641 return TRUE;
1642 --
1643 else
1644
1645 p_payroll_id := get_default_payroll
1646 (p_business_group_id => p_business_group_id
1647 ,p_effective_date => p_effective_date
1648 );
1649 if p_payroll_id is null then
1650 if g_debug then
1651 hr_utility.set_location('BEN_92347_NO_DFLT_PAYROLL',25);
1652 end if;
1653 fnd_message.set_name('BEN', 'BEN_92347_NO_DFLT_PAYROLL');
1654 fnd_message.set_token('PROC',l_proc);
1655 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
1656 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
1657 fnd_message.set_token('BG_ID',to_char(p_business_group_id));
1658 fnd_message.raise_error;
1659 else
1660 if g_debug then
1661 hr_utility.set_location('Leaving-returning false:' ||l_proc,5);
1662 end if;
1663 return FALSE;
1664 end if;
1665 end if;
1666 end if;
1667 if g_debug then
1668 hr_utility.set_location('Leaving:' ||l_proc,5);
1669 end if;
1670 end chk_assign_exists;
1671
1672 -- ----------------------------------------------------------------------------
1673 -- |---------------< create_benefits_assignment >-----------------------------|
1674 -- ----------------------------------------------------------------------------
1675 -- This Procedure creates a benefits assignments
1676 -- If the participant record being enrolled does not
1677 -- have an assignment.
1678
1679 procedure create_benefits_assignment(p_person_id IN NUMBER
1680 ,p_payroll_id IN NUMBER
1681 ,p_assignment_id IN OUT NOCOPY NUMBER
1682 ,p_business_group_id IN NUMBER
1683 ,p_organization_id in out nocopy number
1684 ,p_effective_date IN DATE) is
1685 --
1686 l_assignment_id NUMBER; -- Assignment ID.
1687 l_effective_start_date DATE; -- Effective Start Date.
1688 l_effective_end_date DATE; -- Effective End Date.
1689 l_assignment_extra_info_id NUMBER; -- Assignment Extra Info ID.
1690 l_object_version_number NUMBER; -- Object version number.
1691 l_aei_object_version_number NUMBER; -- AEI Object version number.
1692 l_proc varchar2(75);
1693 begin
1694 g_debug := hr_utility.debug_enabled;
1695 if g_debug then
1696 l_proc := ' Create_Benefits_Assignment';
1697 hr_utility.set_location('Entering:' ||l_proc,5);
1698 end if;
1699 BEN_assignment_API.create_ben_asg
1700 (p_effective_date => p_effective_date
1701 ,p_PERSON_ID => p_person_id
1702 ,p_ORGANIZATION_ID => p_business_group_id
1703 ,p_PAYROLL_ID => p_payroll_id
1704 -- ,p_ASSIGNMENT_TYPE =>'A'
1705 -- ,p_PRIMARY_FLAG =>'Y'
1706 ,p_ASSIGNMENT_STATUS_TYPE_ID => 1
1707 ,p_ASSIGNMENT_ID => l_assignment_id
1708 ,p_OBJECT_VERSION_NUMBER => l_object_version_number
1709 ,p_EFFECTIVE_START_DATE => l_effective_start_date
1710 ,p_EFFECTIVE_END_DATE => l_effective_end_date
1711 ,p_ASSIGNMENT_EXTRA_INFO_ID => l_assignment_extra_info_id
1712 ,p_AEI_OBJECT_VERSION_NUMBER => l_aei_object_version_number);
1713 p_organization_id:=p_business_group_id;
1714 if g_debug then
1715 hr_utility.set_location('Leaving:' ||l_proc,5);
1716 end if;
1717 end create_benefits_assignment;
1718 --
1719 -- ----------------------------------------------------------------------------
1720 -- |---------------------< prorate_amount >-----------------------------|
1721 -- ----------------------------------------------------------------------------
1722 function prorate_amount(p_amt IN NUMBER --per month amount
1723 ,p_acty_base_rt_id IN NUMBER
1724 ,p_actl_prem_id in number
1725 ,p_cvg_amt_calc_mthd_id in number
1726 ,p_person_id in number
1727 ,p_rndg_cd in varchar2
1728 ,p_rndg_rl in number
1729 ,p_pgm_id in number
1730 ,p_pl_typ_id in number
1731 ,p_pl_id in number
1732 ,p_opt_id in number
1733 ,p_ler_id in number
1734 ,p_prorate_flag IN OUT NOCOPY VARCHAR2
1735 ,p_effective_date in DATE
1736 ,p_start_or_stop_cd in varchar2
1737 ,p_start_or_stop_date in date
1738 ,p_business_group_id in number
1739 ,p_assignment_id in number
1740 ,p_organization_id in number
1741 ,p_jurisdiction_code in varchar2
1742 ,p_wsh_rl_dy_mo_num in number
1743 ,p_prtl_mo_det_mthd_cd in out nocopy varchar2
1744 ,p_prtl_mo_det_mthd_rl in number)
1745 RETURN NUMBER
1746 IS --prorated per month amount
1747 --
1748 cursor get_prtn_row
1749 (c_acty_base_rt_id in number
1750 ,c_actl_prem_id in number
1751 ,c_cvg_amt_calc_mthd_id in number
1752 ,c_effective_date in date
1753 ,c_start_or_stop_date in date
1754 ,c_start_or_stop_cd in varchar2
1755 )
1756 is
1757 select *
1758 from BEN_PRTL_MO_RT_PRTN_VAL_F
1759 where (acty_base_rt_id = p_acty_base_rt_id or
1760 actl_prem_id = p_actl_prem_id or
1761 cvg_amt_calc_mthd_id = p_cvg_amt_calc_mthd_id
1762 )
1763 and c_effective_date
1764 between effective_start_date and effective_end_date
1765 and to_number(to_char(c_start_or_stop_date,'DD'))
1766 between from_dy_mo_num and to_dy_mo_num
1767 and (num_days_month = to_number(to_char(last_day(c_start_or_stop_date),'DD')) or
1768 num_days_month is null)
1769 and c_start_or_stop_cd=
1770 decode(nvl(strt_r_stp_cvg_cd,'ETHR'),'ETHR',c_start_or_stop_cd,strt_r_stp_cvg_cd);
1771 --
1772 --
1773 cursor get_prtn_method
1774 (c_acty_base_rt_id in number
1775 ,c_actl_prem_id in number
1776 ,c_cvg_amt_calc_mthd_id in number
1777 ,c_effective_date in date)
1778 is
1779 select 'Y'
1780 from BEN_PRTL_MO_RT_PRTN_VAL_F
1781 where (acty_base_rt_id = p_acty_base_rt_id or
1782 actl_prem_id = p_actl_prem_id or
1783 cvg_amt_calc_mthd_id = p_cvg_amt_calc_mthd_id
1784 )
1785 and prorate_by_day_to_mon_flag = 'Y'
1786 and c_effective_date
1787 between effective_start_date and effective_end_date;
1788 --
1789 -- 14076301
1790 --
1791 cursor c_get_epe
1792 is
1793 select epe.elig_per_elctbl_chc_id
1794 from ben_elig_per_elctbl_chc epe
1795 ,ben_oipl_f oipl
1796 ,ben_per_in_ler pil
1797 where epe.per_in_ler_id = pil.per_in_ler_id
1798 and nvl(epe.pgm_id, -1) = nvl(p_pgm_id, -1)
1799 and epe.pl_id = p_pl_id
1800 and epe.pl_id = oipl.pl_id(+)
1801 and nvl(epe.oipl_id, -1) = oipl.oipl_id(+)
1802 and nvl(oipl.opt_id, -1) = nvl(p_opt_id, -1)
1803 and pil.person_id = p_person_id
1804 and pil.ler_id = p_ler_id
1805 and pil.per_in_ler_stat_cd = 'STRTD'
1806 and epe.business_group_id = p_business_group_id
1807 and pil.business_group_id = epe.business_group_id
1808 and epe.business_group_id = oipl.business_group_id(+)
1809 and p_effective_date
1810 between oipl.effective_start_date(+) and oipl.effective_end_date(+);
1811 --
1812 l_rounded_value number;
1813 l_prorated_amt number;
1814 l_pct_val number;
1815 p_rec BEN_PRTL_MO_RT_PRTN_VAL_F%ROWTYPE;
1816 l_proc varchar2(75) := ' Prorate_amount';
1817 l_result_amt number;
1818 l_outputs ff_exec.outputs_t;
1819 l_return_amt number;
1820 l_jurisdiction_code varchar2(30);
1821 l_was_rounded boolean:=false;
1822 l_prtn_method varchar2(30);
1823 l_elig_per_elctbl_chc_id number; -- 14076301
1824 --
1825 begin
1826 --
1827 if g_debug then
1828 hr_utility.set_location('Entering:' ||l_proc,5);
1829 end if;
1830 --
1831 if p_prtl_mo_det_mthd_cd='RL' and
1832 p_prtl_mo_det_mthd_rl is not null then
1833 --
1834 l_outputs:=benutils.formula
1835 (p_opt_id =>p_opt_id,
1836 p_pl_id =>p_pl_id,
1837 p_pgm_id =>p_pgm_id,
1838 p_formula_id =>p_prtl_mo_det_mthd_rl,
1839 p_ler_id =>p_ler_id,
1840 p_pl_typ_id =>p_pl_typ_id,
1841 p_assignment_id =>p_assignment_id,
1842 p_acty_base_rt_id =>p_acty_base_rt_id,
1843 p_business_group_id =>p_business_group_id,
1844 p_organization_id =>p_organization_id,
1845 p_jurisdiction_code =>p_jurisdiction_code,
1846 p_effective_date =>p_effective_date);
1847 --
1848 begin
1849 --
1850 -- convert return value to code
1851 --
1852 p_prtl_mo_det_mthd_cd:=l_outputs(l_outputs.first).value;
1853 --
1854 exception
1855 --
1856 when others then
1857 if g_debug then
1858 hr_utility.set_location('BEN_92311_FORMULA_VAL_PARAM',5);
1859 end if;
1860 fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
1861 fnd_message.set_token('PROC',l_proc);
1862 fnd_message.set_token('FORMULA',p_prtl_mo_det_mthd_rl);
1863 fnd_message.set_token('PARAMETER',l_outputs(l_outputs.first).name);
1864 fnd_message.raise_error;
1865 --
1866 end;
1867 end if;
1868 --
1869 if p_prtl_mo_det_mthd_cd is null
1870 or p_prtl_mo_det_mthd_cd = 'ALL'
1871 then
1872 p_prorate_flag:='N';
1873 l_return_amt:=p_amt;
1874 elsif p_prtl_mo_det_mthd_cd='NONE' then
1875 p_prorate_flag:='Y';
1876 l_return_amt:=0;
1877 elsif p_prtl_mo_det_mthd_cd='PRTVAL' then
1878 if g_debug then
1879 hr_utility.set_location('p_start_or_stop_cd '||p_start_or_stop_cd,5);
1880 end if;
1881 --
1882 -- find proration method
1883 open get_prtn_method
1884 (c_acty_base_rt_id => p_acty_base_rt_id
1885 ,c_actl_prem_id => p_actl_prem_id
1886 ,c_cvg_amt_calc_mthd_id => p_cvg_amt_calc_mthd_id
1887 ,c_effective_date => p_effective_date);
1888 fetch get_prtn_method into l_prtn_method;
1889 close get_prtn_method;
1890 --
1891 if l_prtn_method = 'Y' then
1892 --
1893 hr_utility.set_location ('Proration by day to month',111);
1894 if p_start_or_stop_cd = 'STRT' then
1895 --
1896 l_pct_val := (to_number(to_char(last_day(p_start_or_stop_date),'DD')) -
1897 to_number(to_char(p_start_or_stop_date,'DD')) + 1 ) /
1898 to_number(to_char(last_day(p_start_or_stop_date),'DD'));
1899 elsif p_start_or_stop_cd = 'STP' then
1900 --
1901 l_pct_val := to_number(to_char(p_start_or_stop_date,'DD')) /
1902 to_number(to_char(last_day(p_start_or_stop_date),'DD'));
1903 end if;
1904 hr_utility.set_location ('Percentage value'||l_pct_val,112);
1905 if l_pct_val = 100 then
1906 --
1907 p_prorate_flag := 'N';
1908 l_return_amt:=p_amt;
1909 --
1910 else
1911 --
1912 l_prorated_amt := l_pct_val * p_amt;
1913 --
1914 -- Now we have the prorated value, do the rounding
1915 --
1916 if (p_rec.rndg_cd is not null or
1917 p_rec.rndg_rl is not null) and
1918 l_prorated_amt is not null then
1919 --
1920 l_return_amt := benutils.do_rounding
1921 (p_rounding_cd => p_rec.rndg_cd,
1922 p_rounding_rl => p_rec.rndg_rl,
1923 p_value => l_prorated_amt,
1924 p_effective_date => p_effective_date);
1925 --
1926 elsif p_amt<>0 and
1927 p_amt is not null then
1928 --
1929 -- for now later do based on currency precision.
1930 --
1931 l_return_amt:=round(l_prorated_amt,2);
1932 else
1933 l_return_amt:=nvl(l_prorated_amt,0);
1934 end if;
1935 l_was_rounded:=true;
1936 p_prorate_flag:='Y';
1937 end if;
1938 --
1939 else -- proration method is N - old setup
1940 -- Get the correct ben_prtl_mo_rt_prtn_val_f
1941 --
1942 open get_prtn_row
1943 (c_acty_base_rt_id => p_acty_base_rt_id
1944 ,c_actl_prem_id => p_actl_prem_id
1945 ,c_cvg_amt_calc_mthd_id => p_cvg_amt_calc_mthd_id
1946 ,c_effective_date => p_effective_date
1947 ,c_start_or_stop_date => p_start_or_stop_date
1948 ,c_start_or_stop_cd => p_start_or_stop_cd
1949 );
1950 fetch get_prtn_row into p_rec;
1951 if get_prtn_row%notfound
1952 then
1953 if g_debug then
1954 hr_utility.set_location('prtn not found ',5);
1955 end if;
1956 close get_prtn_row;
1957 p_prorate_flag := 'N';
1958 l_return_amt:=p_amt;
1959 else
1960 close get_prtn_row;
1961 --
1962 -- If the pct_val is null then it may be a rule
1963 -- if neither error
1964 --
1965 if p_rec.pct_val is null then
1966 if p_rec.prtl_mo_prortn_rl is null then
1967 --
1968 -- Neither, error
1969 --
1970 if g_debug then
1971 hr_utility.set_location('BEN_92343_NO_PCT_VAL_OR_RL',5);
1972 end if;
1973 fnd_message.set_name('BEN', 'BEN_92343_NO_PCT_VAL_OR_RL');
1974 fnd_message.set_token('PROC',l_proc);
1975 fnd_message.set_token('PRTL_MO_RT_PRTN_VAL_ID',
1976 to_char(p_rec.prtl_mo_rt_prtn_val_id));
1977 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
1978 fnd_message.set_token('ACTL_PREM_ID',to_char(p_actl_prem_id));
1979 fnd_message.set_token('CVG_AMT_CALC_MTHD_ID',
1980 to_char(p_cvg_amt_calc_mthd_id));
1981 fnd_message.raise_error;
1982 else
1983 --
1984 -- Get the choice id. 14076301.
1985 --
1986 open c_get_epe;
1987 fetch c_get_epe into l_elig_per_elctbl_chc_id;
1988 close c_get_epe;
1989 --
1990 hr_utility.set_location('l_elig_per_elctbl_chc_id ' ||l_elig_per_elctbl_chc_id,5);
1991 --
1992 -- Get pct_val from rule execution.
1993 --
1994 l_outputs:=benutils.formula
1995 (p_opt_id =>p_opt_id,
1996 p_pl_id =>p_pl_id,
1997 p_pgm_id =>p_pgm_id,
1998 p_formula_id =>p_rec.prtl_mo_prortn_rl,
1999 p_ler_id =>p_ler_id,
2000 p_pl_typ_id =>p_pl_typ_id,
2001 p_assignment_id =>p_assignment_id,
2002 p_acty_base_rt_id =>p_acty_base_rt_id,
2003 p_elig_per_elctbl_chc_id =>l_elig_per_elctbl_chc_id, -- 14076301
2004 p_business_group_id =>p_business_group_id,
2005 p_organization_id =>p_organization_id,
2006 p_jurisdiction_code =>p_jurisdiction_code,
2007 p_effective_date =>p_effective_date);
2008 --
2009 begin
2010 --
2011 -- convert return value to code
2012 --
2013 l_pct_val:=l_outputs(l_outputs.first).value;
2014 --
2015 exception
2016 --
2017 when others then
2018 if g_debug then
2019 hr_utility.set_location('BEN_92311_FORMULA_VAL_PARAM',15);
2020 end if;
2021 fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
2022 fnd_message.set_token('PROC',l_proc);
2023 fnd_message.set_token('FORMULA',p_rec.prtl_mo_prortn_rl);
2024 fnd_message.set_token('PARAMETER',
2025 l_outputs(l_outputs.first).name);
2026 fnd_message.raise_error;
2027 --
2028 end;
2029 --
2030 end if;
2031 else
2032 l_pct_val:=p_rec.pct_val;
2033 end if;
2034 --
2035 -- Now we have the pct_val compute the amount.
2036 --
2037 if g_debug then
2038 hr_utility.set_location('l_pct_val '||l_pct_val,5);
2039 end if;
2040 if g_debug then
2041 hr_utility.set_location('p_amt '||p_amt,5);
2042 end if;
2043 if l_pct_val = 100 then
2044 --
2045 p_prorate_flag := 'N';
2046 l_return_amt:=p_amt;
2047 --
2048 else
2049 --
2050 l_prorated_amt:=p_amt*l_pct_val/100;
2051 if g_debug then
2052 hr_utility.set_location('l_prorated_amt '||l_prorated_amt,5);
2053 end if;
2054 --
2055 --end if;
2056 -- Now we have the prorated value, do the rounding
2057 --
2058 if (p_rec.rndg_cd is not null or
2059 p_rec.rndg_rl is not null) and
2060 l_prorated_amt is not null then
2061 --
2062 l_return_amt := benutils.do_rounding
2063 (p_rounding_cd => p_rec.rndg_cd,
2064 p_rounding_rl => p_rec.rndg_rl,
2065 p_value => l_prorated_amt,
2066 p_effective_date => p_effective_date);
2067 --
2068 elsif p_amt<>0 and
2069 p_amt is not null then
2070 --
2071 -- for now later do based on currency precision.
2072 --
2073 l_return_amt:=round(l_prorated_amt,2);
2074 else
2075 l_return_amt:=nvl(l_prorated_amt,0);
2076 end if;
2077 l_was_rounded:=true;
2078 p_prorate_flag:='Y';
2079 --
2080 end if; -- pct_val = 100 -- Bug 5515166
2081 end if; --proration not found
2082 --
2083 end if; -- prorate method
2084 elsif p_prtl_mo_det_mthd_cd='WASHRULE' then
2085 if ( p_start_or_stop_cd='STRT' and
2086 to_number(to_char(p_start_or_stop_date,'DD')) > p_wsh_rl_dy_mo_num)
2087 or
2088 ( p_start_or_stop_cd='STP' and
2089 to_number(to_char(p_start_or_stop_date,'DD')) < p_wsh_rl_dy_mo_num)
2090 then
2091 p_prorate_flag := 'Y';
2092 l_return_amt:=0;
2093 else
2094 p_prorate_flag := 'Y';
2095 l_return_amt:=p_amt;
2096 end if;
2097 if g_debug then
2098 hr_utility.set_location('p_start_or_stop_cd '||p_start_or_stop_cd,5);
2099 hr_utility.set_location('p_start_or_stop_date '||p_start_or_stop_date,5);
2100 hr_utility.set_location('p_wsh_rl_dy_mo_num '||p_wsh_rl_dy_mo_num,5);
2101 hr_utility.set_location('p_prorate_flag '||p_prorate_flag,5);
2102 hr_utility.set_location('l_return_amt '||l_return_amt,5);
2103 end if;
2104 else
2105 --
2106 -- unsupported code error out
2107 --
2108 if g_debug then
2109 hr_utility.set_location('BEN_92348_UNKNOWN_PRTN_DET_CD',15);
2110 end if;
2111 fnd_message.set_name('BEN', 'BEN_92348_UNKNOWN_PRTN_DET_CD');
2112 fnd_message.set_token('PROC',l_proc);
2113 fnd_message.set_token('PRTL_MO_DET_MTHD_CD',p_prtl_mo_det_mthd_cd);
2114 fnd_message.raise_error;
2115 end if;
2116 --
2117 if (p_rndg_cd is not null or
2118 p_rndg_rl is not null) and
2119 l_was_rounded=false and
2120 l_return_amt<>0 and
2121 l_return_amt is not null then
2122 --
2123 l_return_amt := benutils.do_rounding
2124 (p_rounding_cd => p_rndg_cd,
2125 p_rounding_rl => p_rndg_rl,
2126 p_value => l_return_amt,
2127 p_effective_date => p_effective_date);
2128 end if;
2129 if g_debug then
2130 hr_utility.set_location('Leaving:' ||l_proc,80);
2131 end if;
2132 --
2133 -- just to be neat, always exit here
2134 --
2135 return l_return_amt;
2136 --
2137 end prorate_amount;
2138 --
2139 -- ----------------------------------------------------------------------------
2140 -- |------------------------------< get_link >--------------------------------|
2141 -- ----------------------------------------------------------------------------
2142 -- This is the process that gets the Element link for the EE contribution
2143 -- of the element for which the acty_base_rt is for.
2144 --
2145 procedure get_link
2146 (p_assignment_id in number
2147 ,p_element_type_id in number
2148 ,p_business_group_id in number
2149 ,p_input_value_id in number
2150 ,p_effective_date in date
2151 --
2152 ,p_element_link_id out nocopy number
2153 )
2154 is
2155 --
2156 l_proc varchar2(75) := g_package || 'Get_link';
2157 --
2158 l_hv pls_integer;
2159 --
2160 l_elk_count pls_integer;
2161 --
2162 l_link_count pls_integer;
2163 --
2164 l_joincond boolean;
2165 --
2166 l_dummy varchar2(1);
2167 --
2168 cursor c_getasgdets
2169 (c_asg_id number
2170 ,c_eff_date date
2171 )
2172 is
2173 select asg.business_group_id,
2174 asg.payroll_id,
2175 asg.job_id,
2176 asg.grade_id,
2177 asg.position_id,
2178 asg.organization_id,
2179 asg.location_id,
2180 asg.pay_basis_id,
2181 asg.employment_category
2182 from per_all_assignments_f asg
2183 where asg.assignment_id = c_asg_id
2184 and c_eff_date
2185 between asg.effective_start_date and asg.effective_end_date;
2186 --
2187 l_getasgdets c_getasgdets%rowtype;
2188 --
2189 cursor c_getelkdets
2190 (c_elt_id number
2191 ,c_eff_date date
2192 )
2193 is
2194 select elk.element_link_id,
2195 elk.business_group_id,
2196 elk.element_type_id,
2197 elk.payroll_id,
2198 elk.link_to_all_payrolls_flag,
2199 elk.job_id,
2200 elk.grade_id,
2201 elk.position_id,
2202 elk.organization_id,
2203 elk.location_id,
2204 elk.pay_basis_id,
2205 elk.employment_category,
2206 elk.people_group_id
2207 from pay_element_links_f elk
2208 where elk.element_type_id = c_elt_id
2209 and c_eff_date
2210 between elk.effective_start_date and elk.effective_end_date;
2211 --
2212 cursor c_chkalu
2213 (c_asg_id number
2214 ,c_elk_id number
2215 ,c_eff_date date
2216 )
2217 is
2218 select null
2219 from pay_assignment_link_usages_f alu
2220 where alu.assignment_id = c_asg_id
2221 and alu.element_link_id = c_elk_id
2222 and c_eff_date
2223 between alu.effective_start_date and alu.effective_end_date;
2224 --
2225 cursor c_getelk
2226 (c_asg_id number
2227 ,c_elt_id number
2228 ,c_eff_date date
2229 )
2230 is
2231 select el.element_link_id
2232 from per_all_assignments_f asg,
2233 pay_element_links_f el
2234 where asg.assignment_id = c_asg_id
2235 and el.business_group_id = asg.business_group_id
2236 and el.element_type_id = c_elt_id
2237 and c_eff_date
2238 between asg.effective_start_date and asg.effective_end_date
2239 and c_eff_date
2240 between el.effective_start_date and el.effective_end_date
2241 and
2242 (
2243 (el.payroll_id is not null and
2244 el.payroll_id = asg.payroll_id)
2245 or (el.link_to_all_payrolls_flag = 'Y' and
2246 asg.payroll_id is not null)
2247 or (el.payroll_id is null and
2248 el.link_to_all_payrolls_flag = 'N')
2249 )
2250 and (el.job_id is null or
2251 el.job_id = asg.job_id)
2252 and (el.grade_id is null or
2253 el.grade_id = asg.grade_id)
2254 and (el.position_id is null or
2255 el.position_id = asg.position_id)
2256 and (el.organization_id is null or
2257 el.organization_id = asg.organization_id)
2258 and (el.location_id is null or
2259 el.location_id = asg.location_id)
2260 and (el.pay_basis_id is null or
2261 el.pay_basis_id = asg.pay_basis_id)
2262 and (el.employment_category is null or
2263 el.employment_category = asg.employment_category)
2264 and (el.people_group_id is null or exists
2265 (select null
2266 from pay_assignment_link_usages_f alu
2267 where alu.assignment_id = asg.assignment_id
2268 and alu.element_link_id = el.element_link_id
2269 and c_eff_date between alu.effective_start_date
2270 and alu.effective_end_date)
2271 )
2272 ;
2273
2274 begin
2275 --
2276 g_debug := hr_utility.debug_enabled;
2277 if g_debug then
2278 --
2279 hr_utility.set_location('Entering:' ||l_proc,5);
2280 hr_utility.set_location('p_assignment_id:' ||p_assignment_id,44333);
2281 hr_utility.set_location('p_element_type_id:' ||p_element_type_id,44333);
2282 hr_utility.set_location('p_business_group_id:' ||p_business_group_id,44333);
2283 hr_utility.set_location('p_input_value_id:' ||p_input_value_id,44333);
2284 hr_utility.set_location('p_effective_date:' ||p_effective_date,44333);
2285 --
2286 end if;
2287 --
2288 if g_get_link_cached > 0 then
2289 --
2290 begin
2291 --
2292 l_hv := mod(nvl(p_assignment_id,1)
2293 +nvl(p_element_type_id,2)
2294 +nvl(p_effective_date-hr_api.g_sot,3)
2295 ,ben_hash_utility.get_hash_key);
2296 --
2297 if nvl(g_get_link_cache(l_hv).assignment_id,-1) = nvl(p_assignment_id,-1)
2298 and nvl(g_get_link_cache(l_hv).element_type_id,-1) = nvl(p_element_type_id,-1)
2299 and nvl(g_get_link_cache(l_hv).session_date,hr_api.g_sot) = nvl(p_effective_date,hr_api.g_sot)
2300 then
2301 --
2302 p_element_link_id := g_get_link_cache(l_hv).element_link_id;
2303 return;
2304 --
2305 else
2306 --
2307 l_hv := l_hv+g_hash_jump;
2308 --
2309 loop
2310 --
2311 if nvl(g_get_link_cache(l_hv).assignment_id,-1) = nvl(p_assignment_id,-1)
2312 and nvl(g_get_link_cache(l_hv).element_type_id,-1) = nvl(p_element_type_id,-1)
2313 and nvl(g_get_link_cache(l_hv).session_date,hr_api.g_sot) = nvl(p_effective_date,hr_api.g_sot)
2314 then
2315 --
2316 exit;
2317 --
2318 else
2319 --
2320 l_hv := l_hv+g_hash_jump;
2321 --
2322 end if;
2323 --
2324 end loop;
2325 --
2326 end if;
2327 --
2328 exception
2329 when no_data_found then
2330 --
2331 l_hv := null;
2332 --
2333 end;
2334 --
2335 end if;
2336 --
2337 -- Initialize the out parameter.
2338 --
2339 p_element_link_id := null;
2340 --
2341 open c_getasgdets
2342 (c_asg_id => p_assignment_id
2343 ,c_eff_date => p_effective_date
2344 );
2345 fetch c_getasgdets into l_getasgdets;
2346 if c_getasgdets%notfound then
2347 --
2348 close c_getasgdets;
2349 --
2350 fnd_message.set_name('BEN', 'BEN_93289_ASG_ABR_NOT_FOUND');
2351 fnd_message.set_token('ACTY_BASE_RT_NAME',g_acty_base_rt_name);
2352 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
2353 if g_debug then
2354 hr_utility.set_location('ASG: BEN_93289_ASG_ABR_NOT_FOUND',5); -- 2105656
2355 end if;
2356 fnd_message.raise_error;
2357 --
2358 end if;
2359 if g_debug then
2360 hr_utility.set_location('c_getasgdets is not null',999);
2361 end if;
2362 close c_getasgdets;
2363 --
2364 l_elk_count := 0;
2365 l_joincond := false;
2366 l_link_count := 0;
2367 --
2368 for elkrow in c_getelkdets
2369 (c_elt_id => p_element_type_id
2370 ,c_eff_date => p_effective_date
2371 )
2372 loop
2373 --
2374 l_link_count := c_getelkdets%rowcount; -- bug 2105656
2375 --
2376 if l_getasgdets.business_group_id = elkrow.business_group_id
2377 and ((elkrow.payroll_id is not null and elkrow.payroll_id = l_getasgdets.payroll_id)
2378 or (elkrow.link_to_all_payrolls_flag = 'Y' and l_getasgdets.payroll_id is not null)
2379 or (elkrow.payroll_id is null and elkrow.link_to_all_payrolls_flag = 'N')
2380 )
2381 and
2382 (elkrow.job_id is null
2383 or elkrow.job_id = l_getasgdets.job_id
2384 )
2385 and
2386 (elkrow.grade_id is null
2387 or elkrow.grade_id = l_getasgdets.grade_id
2388 )
2389 and
2390 (elkrow.position_id is null
2391 or elkrow.position_id = l_getasgdets.position_id
2392 )
2393 and
2394 (elkrow.organization_id is null
2395 or elkrow.organization_id = l_getasgdets.organization_id
2396 )
2397 and
2398 (elkrow.location_id is null
2399 or elkrow.location_id = l_getasgdets.location_id
2400 )
2401 and
2402 (elkrow.pay_basis_id is null
2403 or elkrow.pay_basis_id = l_getasgdets.pay_basis_id
2404 )
2405 and
2406 (elkrow.employment_category is null
2407 or elkrow.employment_category = l_getasgdets.employment_category
2408 )
2409 then
2410 --
2411 l_joincond := true;
2412 --
2413 else
2414 --
2415 l_joincond := false;
2416 --
2417 end if;
2418 --
2419 if (elkrow.people_group_id is null
2420 )
2421 and l_joincond
2422 then
2423 --
2424 l_joincond := true;
2425 --
2426 elsif l_joincond
2427 then
2428 --
2429 open c_chkalu
2430 (c_asg_id => p_assignment_id
2431 ,c_elk_id => elkrow.element_link_id
2432 ,c_eff_date => p_effective_date
2433 );
2434 fetch c_chkalu into l_dummy;
2435 if c_chkalu%found then
2436 --
2437 l_joincond := true;
2438 --
2439 else
2440 --
2441 l_joincond := false;
2442 --
2443 end if;
2444 close c_chkalu;
2445 --
2446 else
2447 --
2448 l_joincond := false;
2449 --
2450 end if;
2451 --
2452 if l_joincond then
2453 --
2454 p_element_link_id := elkrow.element_link_id;
2455 l_elk_count := l_elk_count+1;
2456 exit;
2457 --
2458 end if;
2459 --
2460 end loop;
2461 --
2462 if l_link_count = 0 then
2463 --
2464 fnd_message.set_name('BEN', 'BEN_92344_NO_ELEMENT_LINK');
2465 fnd_message.set_token('PROC',l_proc);
2466 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
2467 fnd_message.set_token('ELEMENT_TYPE_ID',to_char(p_element_type_id));
2468 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
2469 if g_debug then
2470 hr_utility.set_location('ELK: BEN_92344_NO_ELEMENT_LINK',5);
2471 end if;
2472 --
2473 elsif l_elk_count = 0 then -- bug 2105656
2474 --
2475 fnd_message.set_name('BEN', 'BEN_93288_ASG_ELEM_LNK_INELIG');
2476 fnd_message.set_token('ASSIGNMENT_ID',to_char(p_assignment_id));
2477 fnd_message.set_token('ELEMENT_TYPE_ID',to_char(p_element_type_id));
2478 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
2479 if g_debug then
2480 hr_utility.set_location('ELK: BEN_93288_ASG_ELEM_LNK_INELIG',6);
2481 end if;
2482 --
2483 elsif g_get_link_cached > 0 then
2484 --
2485 -- Only store the
2486 --
2487 l_hv := mod(nvl(p_assignment_id,1)
2488 +nvl(p_element_type_id,2)
2489 +nvl(p_effective_date-hr_api.g_sot,3)
2490 ,ben_hash_utility.get_hash_key
2491 );
2492 --
2493 while g_get_link_cache.exists(l_hv)
2494 loop
2495 --
2496 l_hv := l_hv+g_hash_jump;
2497 --
2498 end loop;
2499 --
2500 g_get_link_cache(l_hv).assignment_id := p_assignment_id;
2501 g_get_link_cache(l_hv).element_type_id := p_element_type_id;
2502 g_get_link_cache(l_hv).session_date := p_effective_date;
2503 g_get_link_cache(l_hv).element_link_id := p_element_link_id;
2504 --
2505 end if;
2506 --
2507 if g_debug then
2508 hr_utility.set_location('Leaving:' ||l_proc,5);
2509 end if;
2510 --
2511 end get_link;
2512 --
2513 -- ----------------------------------------------------------------------------
2514 -- |------------------------< chk_future_entries >----------------------------|
2515 -- ----------------------------------------------------------------------------
2516 procedure chk_future_entries
2517 (p_validate in boolean,
2518 p_person_id in number,
2519 p_assignment_id in number,
2520 p_enrt_rslt_id in number,
2521 p_element_type_id in number,
2522 p_multiple_entries_flag in varchar2,
2523 p_effective_date in date) is
2524
2525 cursor c_future_ee
2526 (p_element_type_id in number
2527 ,p_assignment_id in number
2528 ,p_effective_date in date
2529 ) is
2530 select distinct
2531 elt.element_name,
2532 ele.element_entry_id,
2533 ele.effective_start_date,
2534 ele.effective_end_date,
2535 ele.object_version_number,
2536 ele.creator_id,
2537 ele.creator_type
2538 from pay_element_entries_f ele,
2539 pay_element_links_f elk,
2540 pay_element_types_f elt
2541 where ele.effective_start_date = (select min(ele2.effective_start_date)
2542 from pay_element_entries_f ele2
2543 where ele2.element_entry_id
2544 = ele.element_entry_id)
2545 and ele.effective_start_date > p_effective_date
2546 and ele.assignment_id = p_assignment_id
2547 and nvl(ele.creator_id,-1) <> p_enrt_rslt_id
2548 and ele.entry_type = 'E'
2549 and ele.element_link_id = elk.element_link_id
2550 and ele.effective_start_date between elk.effective_start_date
2551 and elk.effective_end_date
2552 and elk.element_type_id = p_element_type_id
2553 and elt.element_type_id = elk.element_type_id
2554 and elk.effective_start_date between elt.effective_start_date
2555 and elt.effective_end_date
2556 order by ele.effective_start_date desc;
2557 l_future_ee_rec c_future_ee%rowtype;
2558
2559 cursor c_chk_rt(p_person_id number,
2560 p_element_entry_id number) is
2561 select abr.name rt_name,
2562 prv.rt_strt_dt
2563 from ben_prtt_enrt_rslt_f pen,
2564 ben_prtt_rt_val prv,
2565 ben_acty_base_rt_f abr
2566 where pen.person_id = p_person_id
2567 and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
2568 and prv.prtt_rt_val_stat_cd is null
2569 and pen.prtt_enrt_rslt_stat_cd is null
2570 and abr.acty_base_rt_id = prv.acty_base_rt_id
2571 and prv.rt_strt_dt between abr.effective_start_date
2572 and abr.effective_end_date
2573 and prv.element_entry_value_id in
2574 (select elv.element_entry_value_id
2575 from pay_element_entry_values_f elv
2576 where elv.element_entry_id = p_element_entry_id);
2577 l_rt_rec c_chk_rt%rowtype;
2578
2579 l_effective_start_date date;
2580 l_effective_end_date date;
2581 l_delete_warning boolean;
2582 l_proc varchar2(72) := g_package||'chk_future_entries';
2583
2584 begin
2585
2586 if g_debug then
2587 hr_utility.set_location('Entering:' ||l_proc,5);
2588 end if;
2589 --
2590 open c_future_ee(p_element_type_id,
2591 p_assignment_id,
2592 p_effective_date);
2593 loop
2594 fetch c_future_ee into l_future_ee_rec;
2595 if c_future_ee%notfound then
2596 exit;
2597 end if;
2598
2599 if g_debug then
2600 hr_utility.set_location('future ee:'||l_future_ee_rec.element_entry_id,6);
2601 hr_utility.set_location('creator type:'||l_future_ee_rec.creator_type,6);
2602 hr_utility.set_location('creator id:'||l_future_ee_rec.creator_id,6);
2603 end if;
2604
2605 if l_future_ee_rec.creator_type ='F' and
2606 l_future_ee_rec.creator_id is not null then
2607 --
2608 -- BEN entry in the future. Something is not right.
2609 -- If there is a valid prtt rt, throw error. otherwise zap the
2610 -- entry
2611 --
2612 open c_chk_rt(p_person_id,
2613 l_future_ee_rec.element_entry_id);
2614 fetch c_chk_rt into l_rt_rec;
2615 if c_chk_rt%found then
2616 --
2617 close c_future_ee;
2618 close c_chk_rt;
2619 fnd_message.set_name('BEN','BEN_93448_FUTURE_BEN_ENTRY');
2620 fnd_message.set_token('P_RATE',l_rt_rec.rt_name);
2621 fnd_message.set_token('P_DATE',to_char(l_future_ee_rec.effective_start_date));
2622 fnd_message.raise_error;
2623 --
2624 end if;
2625 close c_chk_rt;
2626 py_element_entry_api.delete_element_entry
2627 (p_validate =>p_validate
2628 ,p_datetrack_delete_mode =>hr_api.g_zap
2629 ,p_effective_date =>l_future_ee_rec.effective_end_date
2630 ,p_element_entry_id =>l_future_ee_rec.element_entry_id
2631 ,p_object_version_number =>l_future_ee_rec.object_version_number
2632 ,p_effective_start_date =>l_effective_start_date
2633 ,p_effective_end_date =>l_effective_end_date
2634 ,p_delete_warning =>l_delete_warning);
2635
2636 else
2637 --
2638 -- User created entry. Throw error
2639 --
2640 if p_multiple_entries_flag ='N' then
2641 close c_future_ee;
2642 fnd_message.set_name('BEN','BEN_93447_FUTURE_USER_ENTRY');
2643 fnd_message.set_token('P_DATE',to_char(l_future_ee_rec.effective_start_date));
2644 fnd_message.set_token('P_ELEMENT',l_future_ee_rec.element_name);
2645 fnd_message.raise_error;
2646 end if;
2647 end if;
2648
2649 end loop;
2650 close c_future_ee;
2651
2652 if g_debug then
2653 hr_utility.set_location('Leaving:' ||l_proc,10);
2654 end if;
2655 --
2656 end chk_future_entries;
2657 -- Bug 15929812
2658 Function check_for_first_pp_adjustment(p_last_pp_strt_dt in date,
2659 p_last_pp_end_dt in date,
2660 p_annual_amt in number,
2661 p_per_pay_amt in number,
2662 p_payroll_id in number,
2663 p_enrt_rslt_id in number,
2664 p_prtt_rt_val_id in number) return boolean is
2665
2666 l_done boolean := false;
2667 l_per_in_ler_id number;
2668 l_char char(1);
2669 l_pp_start_dt date;
2670 l_pp_end_dt date;
2671
2672
2673 cursor get_pil is
2674 SELECT per_in_ler_id
2675 FROM ben_prtt_rt_val
2676 WHERE prtt_rt_val_id = p_prtt_rt_val_id;
2677
2678 cursor c_prv_change(p_per_in_ler_id number) is
2679 SELECT 'X'
2680 FROM ben_prtt_rt_val
2681 WHERE prtt_enrt_rslt_id = p_enrt_rslt_id
2682 AND ended_per_in_ler_id = p_per_in_ler_id
2683 AND ann_rt_val = p_annual_amt;
2684
2685 cursor c_pp_start_dt is
2686 SELECT ptp.start_date
2687 FROM per_time_periods ptp
2688 WHERE ptp.payroll_id = p_payroll_id
2689 AND ptp.start_date <= p_last_pp_strt_dt
2690 ORDER BY ptp.start_date DESC;
2691
2692 cursor c_pp_end_dt is
2693 SELECT ptp.end_date
2694 FROM per_time_periods ptp
2695 WHERE ptp.payroll_id = p_payroll_id
2696 AND ptp.end_date <= p_last_pp_end_dt
2697 ORDER BY ptp.start_date DESC;
2698
2699 cursor c_per_par_amt_change is
2700 SELECT 'X'
2701 FROM pay_element_entry_values_f
2702 WHERE element_entry_value_id IN
2703 (
2704 SELECT element_entry_value_id
2705 FROM ben_prtt_rt_val
2706 WHERE prtt_enrt_rslt_id = p_enrt_rslt_id
2707 AND prtt_rt_val_stat_cd IS NULL
2708 )
2709 AND effective_start_date >= l_pp_start_dt
2710 AND effective_end_date <= l_pp_end_dt
2711 AND screen_entry_value <> p_per_pay_amt;
2712
2713 begin
2714
2715 if (p_last_pp_strt_dt is null or p_last_pp_end_dt is null or p_annual_amt is null or
2716 p_per_pay_amt is null or p_payroll_id is null or p_enrt_rslt_id is null or
2717 p_prtt_rt_val_id is null) then
2718 return l_done;
2719 end if;
2720
2721 open get_pil;
2722 fetch get_pil into l_per_in_ler_id;
2723 close get_pil;
2724
2725 open c_prv_change(l_per_in_ler_id);
2726 fetch c_prv_change into l_char;
2727 if c_prv_change%notfound then
2728 close c_prv_change;
2729 return l_done;
2730 end if;
2731 close c_prv_change;
2732
2733
2734 open c_pp_start_dt;
2735 fetch c_pp_start_dt into l_pp_start_dt;
2736 close c_pp_start_dt;
2737
2738 open c_pp_end_dt;
2739 fetch c_pp_end_dt into l_pp_end_dt;
2740 close c_pp_end_dt;
2741
2742 open c_per_par_amt_change;
2743 fetch c_per_par_amt_change into l_char;
2744 if c_per_par_amt_change%notfound then
2745 close c_per_par_amt_change;
2746 return l_done;
2747 else
2748 l_done := true;
2749 end if;
2750 close c_per_par_amt_change;
2751 return l_done;
2752 end check_for_first_pp_adjustment;
2753 -- Bug 15929812
2754 --
2755 -- --------------------------------------------------------------------------
2756 -- |------------------< create_enrollment_element >-------------------------|
2757 -- --------------------------------------------------------------------------
2758 -- This procedure is used for both creating and updating element entries
2759 --
2760 procedure create_enrollment_element
2761 (p_validate in boolean default false
2762 ,p_calculate_only_mode in boolean default false
2763 ,p_person_id in number
2764 ,p_acty_base_rt_id in number
2765 ,p_acty_ref_perd in varchar2
2766 ,p_rt_start_date in date
2767 ,p_rt in number
2768 ,p_business_group_id in number
2769 ,p_effective_date in date
2770 ,p_cmncd_rt in number default null
2771 ,p_ann_rt in number default null
2772 ,p_prtt_rt_val_id in number default null
2773 ,p_enrt_rslt_id in number default null
2774 ,p_input_value_id in number default null
2775 ,p_element_type_id in number default null
2776 ,p_pl_id in number default null
2777 ,p_prv_object_version_number in out nocopy number
2778 ,p_element_entry_value_id out nocopy number
2779 ,p_eev_screen_entry_value out nocopy number
2780 )
2781 is
2782 --
2783 cursor get_abr_info
2784 (c_acty_base_rt_id in number
2785 ,c_effective_date in date
2786 )
2787 is
2788 select abr.prtl_mo_det_mthd_cd,
2789 abr.prtl_mo_det_mthd_rl,
2790 abr.wsh_rl_dy_mo_num,
2791 abr.prtl_mo_eff_dt_det_cd,
2792 abr.prtl_mo_eff_dt_det_rl,
2793 abr.rndg_cd,
2794 abr.rndg_rl,
2795 abr.ele_rqd_flag,
2796 abr.one_ann_pymt_cd,
2797 abr.entr_ann_val_flag,
2798 abr.use_calc_acty_bs_rt_flag,
2799 abr.acty_typ_cd,
2800 abr.input_va_calc_rl,
2801 abr.rt_typ_cd,
2802 abr.element_type_id,
2803 abr.input_value_id,
2804 abr.ele_entry_val_cd,
2805 abr.rt_mlt_cd,
2806 abr.parnt_chld_cd,
2807 abr.rcrrg_cd,
2808 abr.name
2809 -- bug 6441505
2810 ,abr.element_det_rl
2811 from ben_acty_base_rt_f abr
2812 where abr.acty_base_rt_id=c_acty_base_rt_id
2813 and c_effective_date between abr.effective_start_date
2814 and abr.effective_end_date;
2815 --
2816 l_get_abr_info get_abr_info%rowtype;
2817 --
2818 cursor get_element_entry(p_element_link_id in number
2819 ,p_assignment_id in number
2820 ,p_enrt_rslt_id in number
2821 ,p_input_value_id in number
2822 ,p_element_entry_id in number
2823 ,p_effective_date in date) is
2824 select ele.element_entry_id,
2825 ele.effective_start_date,
2826 ele.effective_end_date,
2827 ele.object_version_number,
2828 elv.element_entry_value_id
2829 from pay_element_entries_f ele,
2830 pay_element_entry_values_f elv
2831 where ele.element_link_id = p_element_link_id
2832 and ele.assignment_id = p_assignment_id
2833 and (p_enrt_rslt_id is null or
2834 p_enrt_rslt_id = ele.creator_id)
2835 and (p_element_entry_id is null or
2836 p_element_entry_id = ele.element_entry_id)
2837 and p_effective_date between ele.effective_start_date
2838 and ele.effective_end_date
2839 and ele.entry_type = 'E'
2840 and elv.element_entry_id = ele.element_entry_id
2841 and elv.effective_start_date between ele.effective_start_date
2842 and ele.effective_end_date
2843 and elv.input_value_id = p_input_value_id;
2844 --
2845 cursor get_element_entry_v(p_element_entry_value_id in number
2846 ,p_effective_date in date) is
2847 select ele.element_entry_id,
2848 ele.effective_start_date,
2849 ele.effective_end_date,
2850 ele.object_version_number,
2851 elv.element_entry_value_id
2852 from pay_element_entries_f ele,
2853 pay_element_entry_values_f elv
2854 where p_effective_date between ele.effective_start_date
2855 and ele.effective_end_date
2856 and elv.element_entry_id = ele.element_entry_id
2857 and elv.element_entry_value_id = p_element_entry_value_id
2858 and elv.effective_start_date between ele.effective_start_date
2859 and ele.effective_end_date;
2860 --
2861 -- 5229941: Fetch MAX end_date of the Element Entry.
2862 cursor get_max_ee_end_dt(p_element_entry_id in number) is
2863 select max(ele.effective_end_date) max_ee_end_date
2864 from pay_element_entries_f ele
2865 where ele.element_entry_id = p_element_entry_id;
2866 --
2867 --
2868 cursor get_current_value
2869 (p_element_entry_id in number
2870 ,p_input_value_id in number
2871 ,p_effective_date in date
2872 )
2873 is
2874 select eev.screen_entry_value,
2875 ee.object_version_number,
2876 ee.creator_id,
2877 ee.creator_type,
2878 ee.effective_start_date,
2879 ee.effective_end_date
2880 from pay_element_entry_values_f eev,
2881 pay_element_entries_f ee
2882 where eev.element_entry_id = p_element_entry_id
2883 and eev.input_value_id = p_input_value_id
2884 and p_effective_date between eev.effective_start_date
2885 and eev.effective_end_date
2886 and ee.element_entry_id=eev.element_entry_id
2887 and p_effective_date between ee.effective_start_date
2888 and ee.effective_end_date;
2889 --
2890 cursor c_ele_info(p_element_type_id in number,
2891 p_effective_date in date) is
2892 select pet.element_name,
2893 pet.multiple_entries_allowed_flag,
2894 pet.processing_type
2895 from pay_element_types_f pet
2896 where pet.element_type_id = p_element_type_id
2897 and p_effective_date between pet.effective_start_date
2898 and pet.effective_end_date;
2899 --
2900 cursor c_dup_prv(p_element_entry_value_id number,
2901 p_rt_strt_dt date) is
2902 select abr.name
2903 from ben_prtt_enrt_rslt_f pen,
2904 ben_acty_base_rt_f abr,
2905 ben_prtt_rt_val prv
2906 where prv.acty_base_rt_id <> p_acty_base_rt_id
2907 and prv.element_entry_value_id = p_element_entry_value_id
2908 and prv.prtt_rt_val_stat_cd is null
2909 and abr.acty_base_rt_id = prv.acty_base_rt_id
2910 and prv.rt_strt_dt between abr.effective_start_date
2911 and abr.effective_end_date
2912 --bug# 3307450 added rt end dt condition to take care of element fix script
2913 and prv.rt_end_dt > p_rt_strt_dt
2914 and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
2915 and pen.prtt_enrt_rslt_stat_cd is null
2916 and pen.person_id = p_person_id;
2917 --
2918 cursor c_dup_rslt(p_element_entry_id number,
2919 p_rt_strt_dt date) is
2920 select abr1.name
2921 from ben_prtt_enrt_rslt_f pen1,
2922 ben_prtt_enrt_rslt_f pen2,
2923 ben_acty_base_rt_f abr1,
2924 ben_prtt_rt_val prv1
2925 where pen2.prtt_enrt_rslt_id = p_enrt_rslt_id
2926 and pen1.prtt_enrt_rslt_id <> pen2.prtt_enrt_rslt_id
2927 and pen1.person_id = pen2.person_id
2928 and pen1.prtt_enrt_rslt_stat_cd is null
2929 and (nvl(pen1.pgm_id,-1) <> nvl(pen2.pgm_id,-1) or
2930 nvl(pen1.pl_id,-1) <> nvl(pen2.pl_id,-1) or
2931 nvl(pen1.oipl_id,-1) <> nvl(pen2.oipl_id,-1))
2932 and pen1.prtt_enrt_rslt_id = prv1.prtt_enrt_rslt_id
2933 and abr1.acty_base_rt_id = prv1.acty_base_rt_id
2934 and prv1.rt_strt_dt between abr1.effective_start_date
2935 and abr1.effective_end_date
2936 and p_rt_strt_dt between prv1.rt_strt_dt
2937 and prv1.rt_end_dt
2938 and prv1.prtt_rt_val_stat_cd is null
2939 and prv1.element_entry_value_id in
2940 (select pev.element_entry_value_id
2941 from pay_element_entry_values_f pev
2942 where pev.element_entry_id = p_element_entry_id);
2943
2944 cursor c_future_ee
2945 (p_element_entry_id in number
2946 ,p_element_type_id in number
2947 ,p_input_value_id in number
2948 ,p_assignment_id in number
2949 ,p_effective_date in date
2950 ) is
2951 select ele.element_entry_id,
2952 ele.element_link_id,
2953 ele.effective_start_date,
2954 ele.effective_end_date,
2955 ele.object_version_number,
2956 elv.screen_entry_value
2957 from pay_element_entries_f ele,
2958 pay_element_entry_values_f elv,
2959 pay_element_links_f elk
2960 where ele.creator_id = p_enrt_rslt_id
2961 and ele.creator_type = 'F'
2962 and ele.entry_type = 'E'
2963 and ele.effective_start_date > p_effective_date
2964 and ele.element_entry_id <> p_element_entry_id
2965 and elv.element_entry_id = ele.element_entry_id
2966 and elv.input_value_id = p_input_value_id
2967 and elv.effective_start_date between ele.effective_start_date
2968 and ele.effective_end_date
2969 and ele.assignment_id = p_assignment_id
2970 and ele.element_link_id = elk.element_link_id
2971 and ele.effective_start_date between elk.effective_start_date
2972 and elk.effective_end_date
2973 and elk.element_type_id = p_element_type_id
2974 order by ele.effective_start_date asc;
2975 l_future_ee_rec c_future_ee%rowtype;
2976 --
2977 -- Bug 2386380 fix - added default value to decode function
2978 --
2979 cursor c_next_pay_periods
2980 (p_start_date in date
2981 ,p_end_date in date
2982 ,p_prtl_mo_eff_dt_det_cd in varchar2
2983 ,p_payroll_id in number
2984 )
2985 is
2986 select start_date,end_date
2987 from per_time_periods
2988 where payroll_id = p_payroll_id
2989 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
2990 'PPED',end_date,
2991 'DTERND',regular_payment_date,
2992 end_date)
2993 <= p_end_date
2994 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
2995 'PPED',end_date,
2996 'DTERND',regular_payment_date,
2997 end_date)
2998 >= p_start_date
2999 order by start_date desc;
3000 --
3001 -- Bug 2386380 fix - Handling if p_prtl_mo_eff_dt_det_cd is DTERND
3002 --
3003 cursor c_pps_next_month
3004 (p_end_date in date
3005 ,p_prtl_mo_eff_dt_det_cd in varchar2
3006 ,p_payroll_id in number
3007 )
3008 is
3009 select start_date,end_date
3010 from per_time_periods
3011 where payroll_id = p_payroll_id
3012 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
3013 'DTERND',regular_payment_date,
3014 'PPED',end_date,
3015 end_date)
3016 > p_end_date
3017 order by start_date;
3018 --
3019 cursor c_last_pp_of_cal_year
3020 (p_payroll_id in number
3021 ,p_rt_start_date in date
3022 )
3023 is
3024 select ptp.start_date,ptp.end_date
3025 from per_time_periods ptp
3026 where ptp.payroll_id = p_payroll_id
3027 and ptp.end_date<=add_months(trunc(p_rt_start_date,'YYYY'),
3028 12)-1
3029 order by ptp.end_date desc;
3030 --
3031 cursor c_first_pp_after_start
3032 (p_payroll_id in number
3033 ,p_rt_start_date in date
3034 )
3035 is
3036 select ptp.start_date,
3037 ptp.end_date
3038 from per_time_periods ptp
3039 where ptp.payroll_id = p_payroll_id
3040 and ptp.start_date > p_rt_start_date
3041 order by ptp.end_date asc;
3042 --
3043 cursor c_chk_abs_ler (c_per_in_ler_id number,
3044 c_effective_date date) is
3045 select pil.per_in_ler_id,
3046 pil.lf_evt_ocrd_dt,
3047 pil.trgr_table_pk_id,
3048 ler.ler_id,
3049 ler.typ_cd
3050 from ben_per_in_ler pil,
3051 ben_ler_f ler
3052 where pil.per_in_ler_id = c_per_in_ler_id
3053 and ler.ler_id = pil.ler_id
3054 and c_effective_date between
3055 ler.effective_start_date and ler.effective_end_date;
3056 -- Parent rate information
3057 cursor c_abr2
3058 (c_effective_date in date,
3059 c_acty_base_rt_id in number
3060 )
3061 is
3062 select abr2.rt_mlt_cd,
3063 abr2.entr_ann_val_flag
3064 from ben_acty_base_rt_f abr,
3065 ben_acty_base_rt_f abr2
3066 where abr.acty_base_rt_id = c_acty_base_rt_id
3067 and abr2.acty_base_rt_id = abr.parnt_acty_base_rt_id
3068 and abr2.parnt_chld_cd = 'PARNT'
3069 and c_effective_date
3070 between abr.effective_start_date
3071 and abr.effective_end_date
3072 and c_effective_date
3073 between abr2.effective_start_date
3074 and abr2.effective_end_date;
3075 --
3076 cursor c_current_pp_end
3077 (p_payroll_id in number
3078 ,p_rt_start_date in date
3079 )
3080 is
3081 select ptp.end_date
3082 from per_time_periods ptp
3083 where ptp.payroll_id = p_payroll_id
3084 and p_rt_start_date between
3085 ptp.start_date and ptp.end_date ;
3086 --
3087 cursor c_current_fsa_pp_end
3088 (p_payroll_id in number
3089 ,p_rt_start_date in date
3090 )
3091 is
3092 select nvl(ptp.regular_payment_date,ptp.end_date) end_date
3093 ,ptp.end_date ptp_end_date -- Bug 8985608
3094 from per_time_periods ptp
3095 where ptp.payroll_id = p_payroll_id
3096 and p_rt_start_date between
3097 ptp.start_date and ptp.end_date ;
3098
3099 l_ptp_end_date date; -- Bug 8985608
3100
3101 --
3102 l_current_pp_end_date date ;
3103 --
3104 l_prnt_abr c_abr2%rowtype ;
3105 --
3106 -- Bug 6834340
3107 -- to pass correct ler_id to the prorate_amount when subsequent life event
3108 -- offers no electability to the existing enrollments but rates get updated.
3109 --
3110
3111 cursor c_ler_with_current_prv
3112 (p_prtt_rt_val_id in number
3113 , p_rt_start_date in date
3114 )
3115 is
3116 select ler.name name, ler.ler_id ler_id
3117 from ben_prtt_rt_val prv,
3118 ben_per_in_ler pil,
3119 ben_ler_f ler
3120 where prv.per_in_ler_id = pil.per_in_ler_id
3121 and pil.ler_id = ler.ler_id
3122 and prv.prtt_rt_val_id = p_prtt_rt_val_id
3123 and prv.rt_strt_dt = p_rt_start_date;
3124
3125 l_ler_with_current_prv c_ler_with_current_prv%rowtype;
3126
3127 -- Bug 6834340
3128 --
3129 ----Bug 7196470
3130 cursor c_enrt_rt
3131 is
3132 SELECT ecr.enrt_rt_id
3133 FROM ben_enrt_rt ecr,
3134 ben_prtt_rt_val prv,
3135 ben_acty_base_rt_f abr
3136 WHERE prv.prtt_rt_val_id = ecr.prtt_rt_val_id
3137 AND prv.prtt_rt_val_stat_cd is NULL
3138 AND abr.acty_base_rt_id = prv.acty_base_rt_id
3139 AND ecr.acty_base_rt_id = prv.acty_base_rt_id
3140 AND prv.rt_strt_dt between abr.effective_start_date
3141 AND abr.effective_end_date
3142 AND prv.rt_end_dt > prv.rt_strt_dt
3143 AND ecr.business_group_id = p_business_group_id
3144 AND ecr.prtt_rt_val_id = p_prtt_rt_val_id
3145 AND ecr.acty_base_rt_id = p_acty_base_rt_id;
3146 l_enrt_rt_id ben_enrt_rt.enrt_rt_id%type;
3147
3148 ------------------Bug 8872583
3149 cursor c_chk_pay_periods(p_payroll_id number,p_date date)
3150 is
3151 SELECT *
3152 FROM per_time_periods ptp
3153 WHERE payroll_id = p_payroll_id
3154 AND p_date BETWEEN ptp.start_date AND ptp.end_date ;
3155
3156 l_chk_pay_periods c_chk_pay_periods%rowtype;
3157 l_bal_flag varchar2(10) := 'N';
3158 ------------------Bug 8872583
3159
3160 --------------------------------------------------------------------------------------------------
3161 /* Bug 12382133: Check if Non-Recurring element exists in the payroll period */
3162 CURSOR c_entry_exists(l_normal_pp_dt date, l_elem_link_id number, l_ass_id number,
3163 l_input_value_id number) IS
3164 SELECT /*+ LEADING(ee)
3165 INDEX(ee pay_element_entries_f_n51) */
3166 ee.*
3167 FROM pay_element_entries_f ee,
3168 pay_element_types_f et,
3169 pay_element_links_f el,
3170 pay_element_entry_values_f ev
3171 WHERE el.element_link_id = ee.element_link_id
3172 AND el.element_link_id = l_elem_link_id
3173 AND el.element_type_id = et.element_type_id
3174 AND ee.assignment_id = l_ass_id
3175 and ev.ELEMENT_ENTRY_ID = ee.ELEMENT_ENTRY_ID
3176 and ev.INPUT_VALUE_ID = l_input_value_id
3177 AND l_normal_pp_dt BETWEEN ee.effective_start_date
3178 AND ee.effective_end_date
3179 AND l_normal_pp_dt BETWEEN el.effective_start_date
3180 AND el.effective_end_date
3181 AND l_normal_pp_dt BETWEEN et.effective_start_date
3182 AND et.effective_end_date
3183 AND l_normal_pp_dt BETWEEN ev.effective_start_date
3184 AND ev.effective_end_date
3185 AND et.multiple_entries_allowed_flag = 'N'
3186 AND ee.entry_type = 'E'
3187 and et.PROCESSING_TYPE = 'N';
3188
3189 l_entry_exists c_entry_exists%rowtype;
3190
3191 /*Bug 12382133: Get the Rate records of the previous LE which have same element
3192 entry and input value before setting the element entry value to NULL*/
3193 cursor c_get_prv_id(l_element_type_id number,
3194 l_input_value_id number,
3195 l_normal_pp_dt date,
3196 l_ELEMENT_ENTRY_ID number) is
3197 select prv.* from ben_prtt_rt_val prv,
3198 pay_element_entries_f et,
3199 pay_element_entry_values_f ev
3200 where et.element_type_id = l_element_type_id
3201 and ev.input_value_id = l_input_value_id
3202 and et.ELEMENT_ENTRY_ID = l_ELEMENT_ENTRY_ID
3203 and et.ELEMENT_ENTRY_ID = ev.ELEMENT_ENTRY_ID
3204 and ev.ELEMENT_ENTRY_VALUE_ID = prv.ELEMENT_ENTRY_VALUE_ID
3205 AND l_normal_pp_dt BETWEEN et.effective_start_date
3206 AND et.effective_end_date
3207 AND l_normal_pp_dt BETWEEN ev.effective_start_date
3208 AND ev.effective_end_date
3209 and prv.business_group_id = p_business_group_id;
3210 --------------------------------------------------------------------------------------------------
3211
3212 l_proc varchar2(72) := g_package||'create_enrollment_element';
3213 l_start_date date;
3214 l_end_date date;
3215 l_amt NUMBER;
3216 l_curr_val NUMBER;
3217 l_curr_val_char VARCHAR2(60);
3218 l_new_val NUMBER;
3219 l_new_date DATE;
3220 l_temp_val NUMBER;
3221 l_assignment_id NUMBER;
3222 l_payroll_id NUMBER;
3223 l_element_entry_id NUMBER;
3224 l_entry_value_id NUMBER;
3225 l_element_link_id NUMBER;
3226 l_old_element_link_id number;
3227 l_ext_chg_evt_log_id NUMBER;
3228 l_object_version_number NUMBER;
3229 l_ext_object_version_number NUMBER;
3230 l_prtn_flag VARCHAR2(1):='N';
3231 l_effective_start_date DATE;
3232 l_ee_effective_start_date DATE;
3233 l_ee_effective_end_date DATE;
3234 l_upd_mode VARCHAR2(30);
3235 l_delete_warning BOOLEAN;
3236 l_create_warning BOOLEAN;
3237 l_update_warning BOOLEAN;
3238 l_per_month_amt number;
3239 l_per_pay_amt number;
3240 l_prorated_monthly_amt number;
3241 l_update_ee boolean;
3242 l_zero_pp_date date;
3243 l_special_pp_date date;
3244 l_normal_pp_date date;
3245 l_normal_pp_end_date date;
3246 l_special_amt number;
3247 l_outputs ff_exec.outputs_t;
3248 l_organization_id number;
3249 l_remainder number;
3250 l_number_in_month number;
3251 l_old_normal_pp_date date;
3252 l_jurisdiction_code varchar2(30);
3253 l_effective_end_date date;
3254 l_last_pp_strt_dt date;
3255 l_last_pp_end_dt date;
3256 l_range_start date;
3257 l_tmp_bool boolean;
3258 l_pay_periods number;
3259 l_first_pp_adjustment number;
3260 l_rt_strt_dt date := p_rt_start_date;
3261 l_real_num_periods number;
3262 l_mlt_cd varchar2(30);
3263 l_creee_calc_vals g_calculated_values;
3264 l_v2dummy varchar2(30);
3265 l_perd_cd varchar2(30) := 'PP';
3266 l_annual_target boolean ;
3267 l_uom varchar2(30);
3268 l_element_name varchar2(80);
3269 l_processing_type varchar2(30);
3270 l_multiple_entries_flag varchar2(1);
3271 l_recurring_entry boolean := false;
3272 l_dummy_varchar2 varchar2(30) := hr_api.g_varchar2;
3273 l_creator_id number;
3274 l_creator_type varchar2(30);
3275 l_dummy_date date;
3276 l_new_element_link_id number;
3277 l_effective_date date;
3278 l_element_term_rule_date date;
3279 l_element_link_end_date date;
3280 l_out_date_not_required date;
3281 l_encoded_message varchar2(2000);
3282 l_app_short_name varchar2(2000);
3283 l_message_name varchar2(2000);
3284 l_per_in_ler_id number;
3285 l_ler_id number;
3286 l_absence_attendance_id number;
3287 l_subpriority number;
3288 l_dummy varchar2(30);
3289 l_abs_ler boolean := false;
3290 l_override_user_ent_chk varchar2(30) := 'N';
3291 l_string varchar2(4000);
3292 l_err_code varchar2(10);
3293 l_err_mesg varchar2(2000);
3294 l_input_value_id1 number;
3295 l_sarec_dont_create boolean := false ;
3296 l_calculate_only_mode boolean := p_calculate_only_mode;
3297 l_prnt_ann_rt varchar2(1):= 'N';
3298 l_abr_name varchar2(240);
3299 l_inpval_tab inpval_tab_typ;
3300 l_element_type_id number;
3301 l_input_value_id number;
3302 l_pl_id number;
3303 l_lf_evt_ocrd_dt date;
3304 l_ler_typ_cd varchar2(30);
3305 l_old_assignment_id number;
3306 l_non_recurring_ee_id number;
3307 l_max_ee_end_dt DATE;
3308 l_ele_entry_val_cd VARCHAR2(30); -- Bug 5575402
3309 l_dummy_number number;
3310 l_old_asgn_id number; -- for bug 6450363
3311 --Bug 13526198 start
3312 l_out_date_not_required_1 date;
3313 l_asg_max_eligibility_date date;
3314 l_skip boolean:=false;
3315 -- Bug 15929812
3316 l_done boolean:=false;
3317 -- Bug 15929812
3318 --Bug 13526198 end;
3319 --
3320 -- Bug 2675486 to skip computation for SAREC when there is
3321 -- no change in the amount and within the same plan year
3322 --
3323 function keep_same_element(p_person_id number,
3324 p_assignment_id number,
3325 p_prtt_enrt_rslt_id number,
3326 p_prtt_rt_val_id number,
3327 p_acty_base_rt_id number,
3328 p_ann_rt_val number,
3329 p_cmcd_rt_val number,
3330 p_rt_val number,
3331 p_rt_start_date date,
3332 p_mlt_cd varchar2,
3333 p_element_type_id number, -- 5401779
3334 p_input_value_id number, -- 5401779
3335 p_ele_entry_val_cd varchar2) -- Bug 5575402
3336 /*p_input_va_calc_rl number, --6716202
3337 p_organization_id number default null, -- 6716202
3338 p_payroll_id number default null) -- 6716202 */
3339 return boolean is
3340
3341 l_return boolean := false ;
3342 l_yp_start_date date;
3343 l_max_strt_dt date;
3344 l_ee_id number;
3345 l_old_assignment_id number;
3346 l_fsa_ee_effective_end_date date;
3347 l_fsa_element_entry_id number;
3348 l_fsa_ovn number;
3349 l_effective_end_date date;
3350 -- Bug 6716202
3351 /* l_ext_inpval_tab ben_element_entry.ext_inpval_tab_typ;
3352 l_inpval_tab ben_element_entry.inpval_tab_typ;
3353 l_jurisdiction_code varchar2(30);
3354 l_subpriority number;*/
3355 -- Bug 6716202
3356 cursor c_pen is
3357 select pgm_id,pl_id,oipl_id--,pl_typ_id,ler_id -- 6716202
3358 from ben_prtt_enrt_rslt_f pen
3359 where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
3360 and pen.prtt_enrt_rslt_stat_cd is null
3361 and rownum = 1 ;
3362 l_pen c_pen%rowtype;
3363 --
3364 cursor c_pl_popl_yr_period_current(cv_pl_id number,
3365 cv_effective_date date ) IS
3366 select distinct yp.start_date
3367 from ben_popl_yr_perd pyp, ben_yr_perd yp
3368 where pyp.pl_id = cv_pl_id
3369 and pyp.yr_perd_id = yp.yr_perd_id
3370 and pyp.business_group_id = p_business_group_id
3371 and cv_effective_date BETWEEN yp.start_date AND yp.end_date
3372 and yp.business_group_id = p_business_group_id ;
3373 --
3374 cursor c_max_prv is
3375 select
3376 max(prv.rt_strt_dt) max_strt_dt
3377 from ben_prtt_enrt_rslt_f pen,
3378 ben_prtt_rt_val prv
3379 where pen.person_id = p_person_id
3380 and pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
3381 and pen.prtt_enrt_rslt_stat_cd is null
3382 and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3383 and prv.acty_base_rt_id = p_acty_base_rt_id
3384 and prv.prtt_rt_val_id <> p_prtt_rt_val_id
3385 and (p_mlt_cd <> 'SAREC' OR (p_mlt_cd = 'SAREC' and prv.rt_strt_dt >= l_yp_start_date))
3386 and prv.rt_end_dt < p_rt_start_date
3387 and prv.prtt_rt_val_stat_cd is null ;
3388 --
3389 --sshetty: added this cursor to check if there are any
3390 -- mutliple rates with same element type
3391 --Reason for doing this check again here is to skip
3392 --this package totally as end enrollment call would
3393 --have updated the element entry with new temp (0)value
3394 --Skipping this call will ensure the right value in the
3395 --EE input value
3396
3397 cursor c_dup_prv_chk (c_element_entry_id number,
3398 c_effective_date date) is
3399 select count(prv.prtt_enrt_rslt_id)
3400 from ben_prtt_rt_val prv
3401 where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
3402 and prv.acty_base_rt_id <> p_acty_base_rt_id
3403 and prv.rt_end_dt > c_effective_date
3404 and prv.prtt_rt_val_stat_cd is null
3405 and prv.element_entry_value_id in
3406 (select pev.element_entry_value_id
3407 from pay_element_entry_values_f pev
3408 where pev.element_entry_id = c_element_entry_id);
3409 --
3410 -- bug 13709907
3411 --
3412 CURSOR c_pay_period_strt_dt(p_effective_start_date date
3413 ) IS
3414 SELECT ptp.start_date
3415 FROM per_time_periods ptp
3416 ,per_all_assignments_f asg
3417 WHERE ptp.regular_payment_date >= p_effective_start_date
3418 and ptp.payroll_id = asg.payroll_id
3419 AND ptp.start_date <= p_effective_start_date
3420 AND p_business_group_id = asg.business_group_id
3421 AND asg.primary_flag = 'Y'
3422 AND asg.person_id = p_person_id
3423 AND p_effective_start_date
3424 between asg.effective_start_date
3425 and asg.effective_end_date
3426 order by ptp.regular_payment_date;
3427 --
3428 -- end 13709907
3429 --
3430 cursor c_prv is
3431 select pev.element_entry_value_id
3432 from ben_prtt_enrt_rslt_f pen,
3433 ben_prtt_rt_val prv,
3434 pay_element_entry_values_f pev
3435 where pen.person_id = p_person_id
3436 and pen.prtt_enrt_rslt_stat_cd is null
3437 and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3438 and pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
3439 and prv.mlt_cd = 'SAREC'
3440 and prv.acty_base_rt_id = p_acty_base_rt_id
3441 and prv.prtt_rt_val_id <> p_prtt_rt_val_id
3442 and prv.rt_strt_dt = l_max_strt_dt
3443 and prv.rt_end_dt < p_rt_start_date
3444 and prv.prtt_rt_val_stat_cd is null
3445 and prv.ann_rt_val = p_ann_rt_val
3446 and pev.element_entry_value_id = prv.element_entry_value_id
3447 and p_rt_start_date between pev.effective_start_date
3448 and pev.effective_end_date ;
3449 --
3450 --BUG 3878539
3451 -- non fsa type rates.
3452 --
3453 cursor c_non_fsa_prv is
3454 select pev.element_entry_value_id
3455 from ben_prtt_enrt_rslt_f pen,
3456 ben_prtt_rt_val prv,
3457 pay_element_entry_values_f pev
3458 where pen.person_id = p_person_id
3459 and pen.prtt_enrt_rslt_stat_cd is null
3460 and pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
3461 and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
3462 and prv.acty_base_rt_id = p_acty_base_rt_id
3463 and prv.prtt_rt_val_id <> p_prtt_rt_val_id
3464 and prv.rt_strt_dt = l_max_strt_dt
3465 and prv.rt_end_dt < p_rt_start_date
3466 and prv.prtt_rt_val_stat_cd is null
3467 and prv.ann_rt_val = p_ann_rt_val
3468 and prv.rt_val = p_rt_val
3469 and prv.cmcd_rt_val = p_cmcd_rt_val
3470 and pev.element_entry_value_id = prv.element_entry_value_id
3471 and p_rt_start_date between pev.effective_start_date
3472 and pev.effective_end_date ;
3473 --
3474 --bug#3364910
3475 --
3476 cursor c_old_asg is
3477 select pee.element_entry_id,
3478 pee.effective_end_date,
3479 pee.object_version_number,
3480 pee.assignment_id,
3481 pee.element_type_id,
3482 pev.input_value_id,
3483 abr.ele_entry_val_cd -- Bug 5575402
3484 from pay_element_entries_f pee,
3485 pay_element_entry_values_f pev,
3486 ben_acty_base_rt_f abr
3487 where pev.element_entry_value_id = l_ee_id
3488 and pee.element_entry_id = pev.element_entry_id
3489 and pev.effective_start_date between pee.effective_start_date
3490 and pee.effective_end_date
3491 and abr.acty_base_rt_id = p_acty_base_rt_id
3492 and pev.effective_start_date between abr.effective_start_date
3493 and abr.effective_end_date
3494 and abr.element_type_id = pee.element_type_id
3495 and abr.input_value_id = pev.input_value_id
3496 order by pee.effective_end_date desc;
3497
3498 cursor c_payroll_type_changed(
3499 cp_person_id number,
3500 cp_business_group_id number,
3501 cp_effective_date date,
3502 cp_orig_effective_date date
3503 ) is
3504 select pay.period_type
3505 from per_all_assignments_f asg,
3506 pay_payrolls_f pay,
3507 per_all_assignments_f asg2,
3508 pay_payrolls_f pay2
3509 where asg.person_id = cp_person_id
3510 and asg.assignment_type <> 'C'
3511 and asg.business_group_id = cp_business_group_id
3512 and asg.primary_flag = 'Y'
3513 and cp_effective_date between
3514 asg.effective_start_date and asg.effective_end_date
3515 and pay.payroll_id=asg.payroll_id
3516 and pay.business_group_id = asg.business_group_id
3517 and cp_effective_date between
3518 pay.effective_start_date and pay.effective_end_date
3519 and asg2.person_id = cp_person_id
3520 and asg2.assignment_type <> 'C'
3521 and asg2.business_group_id = cp_business_group_id
3522 and asg2.primary_flag = 'Y'
3523 and cp_orig_effective_date between
3524 asg2.effective_start_date and asg2.effective_end_date
3525 and pay2.payroll_id=asg2.payroll_id
3526 and pay2.business_group_id = asg2.business_group_id
3527 and cp_orig_effective_date between
3528 pay2.effective_start_date and pay2.effective_end_date
3529 and pay2.period_type<>pay.period_type
3530 and asg.assignment_type = asg2.assignment_type ;
3531 --
3532 l_period_type varchar2(300);
3533 l_old_element_type_id NUMBER; -- 5401779
3534 l_old_input_value_id NUMBER; -- 5401779
3535 l_old_ele_entry_val_cd varchar2(30); -- Bug 5575402
3536 l_dup_rslt_num number;
3537 --
3538
3539 -- Bug 6716202
3540 /*cursor c_element_entry_values(p_input_value_id number, p_element_entry_value_id number) is
3541 select screen_entry_value,element_entry_value_id
3542 from pay_element_entry_values_f pev
3543 where pev.input_value_id = p_input_value_id
3544 and pev.element_entry_value_id = p_element_entry_value_id
3545 and p_rt_start_date between pev.effective_start_date
3546 and pev.effective_end_date ;
3547 l_element_entry_values c_element_entry_values%ROWTYPE;
3548
3549 cursor c_get_input_value(p_prtt_rt_val_id number, p_rt_start_date date) is
3550 select rt_val
3551 from ben_prtt_rt_val prv
3552 where prv.prtt_rt_val_id = p_prtt_rt_val_id
3553 and p_rt_start_date between prv.rt_strt_dt
3554 and prv.rt_end_dt;
3555
3556 l_get_input_value NUMBER;*/
3557
3558 -- Bug 6716202
3559
3560 cursor c_element_entry_v(p_input_value_id number) is
3561 --
3562 select element_entry_id
3563 from pay_element_entry_values_f pev
3564 where pev.input_value_id = p_input_value_id
3565 and l_max_strt_dt between pev.effective_start_date
3566 and pev.effective_end_date ;
3567 --
3568 l_ext_inp_changed boolean;
3569 l_element_entry_id pay_element_entry_values_f.element_entry_id%TYPE;
3570
3571 --Start Bug 12417510: Added below variables
3572 l_prev_yp_start_date date;
3573 l_no_of_prev_py_periods number;
3574 l_no_of_periods number;
3575 --End Bug 12417510
3576
3577 begin
3578 --
3579 if g_debug then
3580 hr_utility.set_location('IN SAREC p_rt_start_date'||p_rt_start_date,122);
3581 hr_utility.set_location(' p_ann_rt_val '||p_ann_rt_val,122);
3582 end if;
3583
3584 open c_pen ;
3585 fetch c_pen into l_pen;
3586 close c_pen;
3587 --
3588 open c_pl_popl_yr_period_current(l_pen.pl_id,p_rt_start_date);
3589 fetch c_pl_popl_yr_period_current into l_yp_start_date ;
3590 close c_pl_popl_yr_period_current ;
3591 --
3592 -- 13709907. If there is a pay period offset, get the pay period
3593 -- start date of the first pay period of the year.
3594 --
3595 if p_mlt_cd = 'SAREC' then
3596 open c_pay_period_strt_dt(l_yp_start_date);
3597 fetch c_pay_period_strt_dt into l_yp_start_date;
3598 close c_pay_period_strt_dt;
3599 hr_utility.set_location('Pay Period Start Date '||l_yp_start_date,123);
3600 end if;
3601 --
3602 -- end 13709907
3603 --
3604 open c_max_prv ;
3605 fetch c_max_prv into l_max_strt_dt ;
3606 close c_max_prv ;
3607 --
3608 if g_debug then
3609 hr_utility.set_location('l_max_strt_dt '||l_max_strt_dt,122);
3610 end if;
3611 if p_mlt_cd = 'SAREC' then
3612 --
3613 open c_prv ;
3614 fetch c_prv into l_ee_id ;
3615 if c_prv%found then
3616 --
3617 --bug#3364910
3618 l_period_type:=null;
3619 open c_payroll_type_changed(
3620 cp_person_id =>p_person_id,
3621 cp_business_group_id =>p_business_group_id,
3622 cp_effective_date =>p_rt_start_date,
3623 cp_orig_effective_date =>l_max_strt_dt);
3624 fetch c_payroll_type_changed into l_period_type;
3625 close c_payroll_type_changed;
3626 -- no change in payroll then update
3627
3628 if l_ee_id is not null then
3629 open c_old_asg;
3630 fetch c_old_asg into
3631 l_fsa_element_entry_id,
3632 l_fsa_ee_effective_end_date,
3633 l_fsa_ovn,
3634 l_old_assignment_id,
3635 l_old_element_type_id,
3636 l_old_input_value_id,
3637 l_old_ele_entry_val_cd; -- Bug 5575402
3638 close c_old_asg;
3639
3640 end if;
3641
3642 if l_ee_id is not null
3643 and l_period_type is null and
3644 nvl(p_assignment_id,-1) = nvl(l_old_assignment_id,-1)
3645 -- 5401779 : Return False if element_type or input_value changes
3646 and NVL(p_element_type_id, -1) = nvl(l_old_element_type_id,-1)
3647 and NVL(p_input_value_id, -1) = nvl(l_old_input_value_id, -1)
3648 and NVL(p_ele_entry_val_cd,'PP') = nvl(l_old_ele_entry_val_cd, 'PP') -- Bug 5575402
3649 then
3650 -- Bug 6716202
3651
3652 -- We also need to check whether the input value has been changed or not,this was not supported before
3653 -- if input value has been changed in subsequent LE,the input value wont be updated from Std Rate which
3654 -- is not proper,so if input value has been changed then we should recompute
3655 /*open c_element_entry_values(p_input_value_id,l_ee_id);
3656 fetch c_element_entry_values into l_element_entry_values;
3657 close c_element_entry_values;
3658
3659 hr_utility.set_location('screen_entry_value '|| l_element_entry_values.screen_entry_value,34534);
3660
3661 open c_get_input_value(p_prtt_rt_val_id,p_rt_start_date);
3662 fetch c_get_input_value into l_get_input_value;
3663 close c_get_input_value;
3664 --
3665 hr_utility.set_location('l_get_input_value '|| l_get_input_value,34534);
3666
3667 if nvl(l_element_entry_values.screen_entry_value,-1) <> nvl(l_get_input_value,-1) then
3668 return false;
3669 end if;
3670 -- We should also need to check whether any extra input values have been changed or not,this was not supported before
3671 -- if input value has been changed in subsequent LE,the input value wont be updated from Rule which
3672 -- is not proper,so if extra input values have been changed then we should recompute
3673
3674 if p_input_va_calc_rl is not null then
3675
3676 ben_element_entry.get_extra_ele_inputs
3677 (p_effective_date => p_rt_start_date
3678 ,p_person_id => p_person_id
3679 ,p_business_group_id => p_business_group_id
3680 ,p_assignment_id => p_assignment_id
3681 ,p_element_link_id => null
3682 ,p_entry_type => 'E'
3683 ,p_input_value_id1 => null
3684 ,p_entry_value1 => null
3685 ,p_element_entry_id => null
3686 ,p_acty_base_rt_id => p_acty_base_rt_id
3687 ,p_input_va_calc_rl => p_input_va_calc_rl
3688 ,p_abs_ler => null
3689 ,p_organization_id => p_organization_id
3690 ,p_payroll_id => p_payroll_id
3691 ,p_pgm_id => l_pen.pgm_id
3692 ,p_pl_id => l_pen.pl_id
3693 ,p_pl_typ_id => l_pen.pl_typ_id
3694 ,p_opt_id => null
3695 ,p_ler_id => l_pen.ler_id
3696 ,p_dml_typ => 'C'
3697 ,p_jurisdiction_code => l_jurisdiction_code
3698 ,p_ext_inpval_tab => l_ext_inpval_tab
3699 ,p_subpriority => l_subpriority
3700 );
3701
3702 open c_element_entry_v (l_ext_inpval_tab(1).input_value_id);
3703 fetch c_element_entry_v into l_element_entry_id;
3704 close c_element_entry_v;
3705
3706 ben_element_entry.get_inpval_tab
3707 (p_element_entry_id => l_element_entry_id
3708 ,p_effective_date => l_max_strt_dt
3709 ,p_inpval_tab => l_inpval_tab);
3710
3711 l_ext_inp_changed := false;
3712
3713 for i in 1..l_ext_inpval_tab.count
3714 loop
3715 for j in 1..l_inpval_tab.count
3716 loop
3717 if (l_ext_inpval_tab(i).input_value_id =
3718 l_inpval_tab(j).input_value_id) and
3719 (nvl(l_ext_inpval_tab(i).return_value,'-1') <>
3720 nvl(l_inpval_tab(j).value,'-1')) then
3721 l_ext_inp_changed := true;
3722 exit;
3723 end if;
3724 end loop;
3725 if l_ext_inp_changed then
3726 exit;
3727 end if;
3728 end loop;
3729
3730 if l_ext_inp_changed then
3731 return not l_ext_inp_changed;
3732 end if;
3733 end if;*/
3734
3735 -- Bug 6716202
3736 open c_dup_prv_chk (l_fsa_element_entry_id,
3737 p_rt_start_date);
3738 fetch c_dup_prv_chk into l_dup_rslt_num;
3739 close c_dup_prv_chk;
3740
3741 if l_dup_rslt_num > 0 then
3742 return false;
3743 end if;
3744
3745 --
3746 p_prv_object_version_number := nvl(p_prv_object_version_number,
3747 l_prv_rec.object_version_number);
3748
3749 ben_prtt_rt_val_api.update_prtt_rt_val
3750 (p_validate => p_validate
3751 ,p_person_id => p_person_id
3752 ,p_prtt_rt_val_id => p_prtt_rt_val_id
3753 ,p_business_group_id => p_business_group_id
3754 ,p_element_entry_value_id => l_ee_id
3755 ,p_input_value_id => p_input_value_id
3756 ,p_object_version_number => p_prv_object_version_number
3757 ,p_effective_date => p_rt_start_date
3758 );
3759 --
3760 l_return := true ;
3761 --
3762 -- reopen the entry if already ended
3763 --
3764 if l_fsa_element_entry_id is not null and
3765 l_fsa_ee_effective_end_date <> hr_api.g_eot and
3766 l_fsa_ee_effective_end_date <> l_element_term_rule_date and
3767 l_fsa_ee_effective_end_date <> l_element_link_end_date then
3768
3769 begin
3770
3771 py_element_entry_api.delete_element_entry
3772 (p_validate =>p_validate
3773 ,p_datetrack_delete_mode =>'FUTURE_CHANGE'
3774 ,p_effective_date =>l_fsa_ee_effective_end_date
3775 ,p_element_entry_id =>l_fsa_element_entry_id
3776 ,p_object_version_number =>l_fsa_ovn
3777 ,p_effective_start_date =>l_effective_start_date
3778 ,p_effective_end_date =>l_effective_end_date
3779 ,p_delete_warning =>l_delete_warning);
3780
3781 exception
3782 when others then
3783 ben_on_line_lf_evt.get_ser_message(l_encoded_message,
3784 l_app_short_name,
3785 l_message_name);
3786 l_encoded_message := fnd_message.get;
3787 --
3788 if l_message_name like '%HR_6284_ELE_ENTRY_DT_ASG_DEL%' or
3789 l_message_name like '%HR_7187_DT_CANNOT_EXTEND_END%' then
3790 -- assignment is not eligible for link beyond this date.
3791 -- Further reopening is not possible.
3792 --
3793 null;
3794 else
3795 if l_app_short_name is not null then
3796 fnd_message.set_name(l_app_short_name,l_message_name);
3797 fnd_message.raise_error;
3798 else
3799 raise;
3800 end if;
3801 end if;
3802 end;
3803 end if;
3804 end if;
3805 --
3806 end if;
3807 close c_prv ;
3808 else -- NON SAREC case -- normal recurring elements
3809 hr_utility.set_location('Non SAREC else part before opening cursor ',545);
3810 open c_non_fsa_prv ;
3811 fetch c_non_fsa_prv into l_ee_id ;
3812 if c_non_fsa_prv%found then
3813 --
3814 --hr_utility.set_location('p_input_value_id '|| p_input_value_id,3453411);
3815 --bug#3364910
3816 l_period_type:=null;
3817 open c_payroll_type_changed(
3818 cp_person_id =>p_person_id,
3819 cp_business_group_id =>p_business_group_id,
3820 cp_effective_date =>p_rt_start_date,
3821 cp_orig_effective_date =>l_max_strt_dt);
3822 fetch c_payroll_type_changed into l_period_type;
3823 close c_payroll_type_changed;
3824 -- no change in payroll then update
3825
3826 if l_ee_id is not null then
3827 open c_old_asg;
3828 fetch c_old_asg into
3829 l_fsa_element_entry_id,
3830 l_fsa_ee_effective_end_date,
3831 l_fsa_ovn,
3832 l_old_assignment_id,
3833 l_old_element_type_id,
3834 l_old_input_value_id,
3835 l_old_ele_entry_val_cd; -- Bug 5575402
3836 close c_old_asg;
3837
3838 end if;
3839
3840 if l_ee_id is not null
3841 and l_period_type is null and
3842 nvl(p_assignment_id,-1) = nvl(l_old_assignment_id,-1)
3843 -- 5401779 : Return False if element_type or input_value changes
3844 and NVL(p_element_type_id, -1) = nvl(l_old_element_type_id,-1)
3845 and NVL(p_input_value_id, -1) = nvl(l_old_input_value_id, -1)
3846 and NVL(p_ele_entry_val_cd,'PP') = nvl(l_old_ele_entry_val_cd, 'PP') -- Bug 5575402
3847 then
3848
3849 --Start Bug 12417510: Added below codes to check whether there is any change in the
3850 --no. of pay periods from previous Benefits year to current year.
3851 if NVL(p_ele_entry_val_cd,'PP') = 'PP' then--nvl PP
3852
3853 open c_plan_year_end_for_pen
3854 (c_prtt_enrt_rslt_id => p_enrt_rslt_id
3855 ,c_rate_start_or_end_dt => p_rt_start_date
3856 ,c_effective_date => p_effective_date
3857 );
3858 --Gets the current plan year period start date and end date
3859 fetch c_plan_year_end_for_pen into
3860 l_last_pp_strt_dt,
3861 l_last_pp_end_dt;
3862 close c_plan_year_end_for_pen;
3863
3864 hr_utility.set_location('l_last_pp_strt_dt '|| l_last_pp_strt_dt,22);
3865 hr_utility.set_location('l_last_pp_end_dt '|| l_last_pp_end_dt,22);
3866 hr_utility.set_location('l_payroll_id '|| l_payroll_id,22);
3867 hr_utility.set_location('p_business_group_id '|| p_business_group_id,22);
3868 hr_utility.set_location('p_effective_date '|| p_effective_date,22);
3869
3870 l_no_of_periods := ben_distribute_rates.get_periods_between(
3871 p_acty_ref_perd_cd => 'PP',
3872 p_start_date => l_last_pp_strt_dt,
3873 p_end_date => l_last_pp_end_dt,
3874 p_payroll_id => l_payroll_id,
3875 p_business_group_id => p_business_group_id,
3876 p_effective_date => p_effective_date
3877 );
3878
3879 hr_utility.set_location('l_no_of_periods '|| l_no_of_periods,22);
3880
3881 open c_pl_popl_yr_period_current(l_pen.pl_id,p_rt_start_date-1);
3882 --Gets the previous plan year periods
3883 fetch c_pl_popl_yr_period_current into l_prev_yp_start_date ;
3884 close c_pl_popl_yr_period_current;
3885
3886 hr_utility.set_location('l_prev_yp_start_date '|| l_prev_yp_start_date,22);
3887 hr_utility.set_location('p_rt_start_date-1 '|| (p_rt_start_date-1),22);
3888 hr_utility.set_location('l_payroll_id '|| l_payroll_id,22);
3889 hr_utility.set_location('p_business_group_id '|| p_business_group_id,22);
3890 hr_utility.set_location('p_effective_date '|| p_effective_date,22);
3891
3892 l_no_of_prev_py_periods := ben_distribute_rates.get_periods_between(
3893 p_acty_ref_perd_cd => 'PP',
3894 p_start_date => l_prev_yp_start_date,
3895 p_end_date => (p_rt_start_date-1),
3896 p_payroll_id => l_payroll_id,
3897 p_business_group_id => p_business_group_id,
3898 p_effective_date => p_effective_date
3899 );
3900
3901 hr_utility.set_location('l_no_of_prev_py_periods '|| l_no_of_prev_py_periods,22);
3902
3903 if l_no_of_prev_py_periods <> l_no_of_periods then
3904 hr_utility.set_location('Plan Yr Periods are different ',22);
3905 return false;
3906 end if;
3907 end if;--nvl PP
3908 --End Bug 12417510
3909
3910 -- Bug 6716202
3911 --
3912 -- We also need to check whether the input value has been changed or not,this was not supported before
3913 -- if input value has been changed in subsequent LE,the input value wont be updated from Std Rate which
3914 -- is not proper,so if input value has been changed then we should recompute
3915 /* open c_element_entry_values(p_input_value_id,l_ee_id);
3916 fetch c_element_entry_values into l_element_entry_values;
3917 close c_element_entry_values;
3918
3919 hr_utility.set_location('screen_entry_value '|| l_element_entry_values.screen_entry_value,34534);
3920
3921 open c_get_input_value(p_prtt_rt_val_id,p_rt_start_date);
3922 fetch c_get_input_value into l_get_input_value;
3923 close c_get_input_value;
3924
3925 hr_utility.set_location('l_get_input_value '|| l_get_input_value,34534);
3926
3927 if nvl(l_element_entry_values.screen_entry_value,-1) <> nvl(l_get_input_value,-1) then
3928 return false;
3929 end if;
3930 -- We should also need to check whether any extra input values have been changed or not,this was not supported before
3931 -- if input value has been changed in subsequent LE,the input value wont be updated from Rule which
3932 -- is not proper,so if extra input values have been changed then we should recompute
3933
3934 if p_input_va_calc_rl is not null then
3935
3936 ben_element_entry.get_extra_ele_inputs
3937 (p_effective_date => p_rt_start_date
3938 ,p_person_id => p_person_id
3939 ,p_business_group_id => p_business_group_id
3940 ,p_assignment_id => p_assignment_id
3941 ,p_element_link_id => null
3942 ,p_entry_type => 'E'
3943 ,p_input_value_id1 => null
3944 ,p_entry_value1 => null
3945 ,p_element_entry_id => null
3946 ,p_acty_base_rt_id => p_acty_base_rt_id
3947 ,p_input_va_calc_rl => p_input_va_calc_rl
3948 ,p_abs_ler => null
3949 ,p_organization_id => p_organization_id
3950 ,p_payroll_id => p_payroll_id
3951 ,p_pgm_id => l_pen.pgm_id
3952 ,p_pl_id => l_pen.pl_id
3953 ,p_pl_typ_id => l_pen.pl_typ_id
3954 ,p_opt_id => null
3955 ,p_ler_id => l_pen.ler_id
3956 ,p_dml_typ => 'C'
3957 ,p_jurisdiction_code => l_jurisdiction_code
3958 ,p_ext_inpval_tab => l_ext_inpval_tab
3959 ,p_subpriority => l_subpriority
3960 );
3961
3962 open c_element_entry_v (l_ext_inpval_tab(1).input_value_id);
3963 fetch c_element_entry_v into l_element_entry_id;
3964 close c_element_entry_v;
3965
3966 ben_element_entry.get_inpval_tab
3967 (p_element_entry_id => l_element_entry_id
3968 ,p_effective_date => l_max_strt_dt
3969 ,p_inpval_tab => l_inpval_tab);
3970
3971 l_ext_inp_changed := false;
3972
3973 for i in 1..l_ext_inpval_tab.count
3974 loop
3975 for j in 1..l_inpval_tab.count
3976 loop
3977
3978 if (l_ext_inpval_tab(i).input_value_id =
3979 l_inpval_tab(j).input_value_id) and
3980 (nvl(l_ext_inpval_tab(i).return_value,'-1') <>
3981 nvl(l_inpval_tab(j).value,'-1')) then
3982 l_ext_inp_changed := true;
3983 exit;
3984 end if;
3985 end loop;
3986 if l_ext_inp_changed then
3987 exit;
3988 end if;
3989 end loop;
3990
3991 if l_ext_inp_changed then
3992 return not l_ext_inp_changed;
3993 end if;
3994 end if;*/
3995
3996 -- Bug 6716202
3997
3998 open c_dup_prv_chk (l_fsa_element_entry_id,
3999 p_rt_start_date);
4000 fetch c_dup_prv_chk into l_dup_rslt_num;
4001 close c_dup_prv_chk;
4002
4003 if l_dup_rslt_num > 0 then
4004 return false;
4005 end if;
4006 --
4007 p_prv_object_version_number := nvl(p_prv_object_version_number,
4008 l_prv_rec.object_version_number);
4009
4010 ben_prtt_rt_val_api.update_prtt_rt_val
4011 (p_validate => p_validate
4012 ,p_person_id => p_person_id
4013 ,p_prtt_rt_val_id => p_prtt_rt_val_id
4014 ,p_business_group_id => p_business_group_id
4015 ,p_element_entry_value_id => l_ee_id
4016 ,p_input_value_id => p_input_value_id
4017 ,p_object_version_number => p_prv_object_version_number
4018 ,p_effective_date => p_rt_start_date
4019 );
4020 --
4021 l_return := true ;
4022 --
4023 -- reopen the entry if already ended
4024 --
4025 if l_fsa_element_entry_id is not null and
4026 l_fsa_ee_effective_end_date <> hr_api.g_eot and
4027 l_fsa_ee_effective_end_date <> l_element_term_rule_date and
4028 l_fsa_ee_effective_end_date <> l_element_link_end_date then
4029
4030 begin
4031
4032 py_element_entry_api.delete_element_entry
4033 (p_validate =>p_validate
4034 ,p_datetrack_delete_mode =>'FUTURE_CHANGE'
4035 ,p_effective_date =>l_fsa_ee_effective_end_date
4036 ,p_element_entry_id =>l_fsa_element_entry_id
4037 ,p_object_version_number =>l_fsa_ovn
4038 ,p_effective_start_date =>l_effective_start_date
4039 ,p_effective_end_date =>l_effective_end_date
4040 ,p_delete_warning =>l_delete_warning);
4041
4042 exception
4043 when others then
4044 ben_on_line_lf_evt.get_ser_message(l_encoded_message,
4045 l_app_short_name,
4046 l_message_name);
4047 l_encoded_message := fnd_message.get;
4048 --
4049 if l_message_name like '%HR_6284_ELE_ENTRY_DT_ASG_DEL%' or
4050 l_message_name like '%HR_7187_DT_CANNOT_EXTEND_END%' then
4051 -- assignment is not eligible for link beyond this date.
4052 -- Further reopening is not possible.
4053 --
4054 null;
4055 else
4056 if l_app_short_name is not null then
4057 fnd_message.set_name(l_app_short_name,l_message_name);
4058 fnd_message.raise_error;
4059 else
4060 raise;
4061 end if;
4062 end if;
4063 end;
4064 end if;
4065 end if;
4066 --
4067 end if;
4068 close c_non_fsa_prv;
4069 end if;
4070 --
4071 return l_return ;
4072 --
4073 exception when others then
4074 if g_debug then
4075 hr_utility.set_location('in the exception ',122);
4076 end if;
4077 return false ;
4078 end keep_same_element ;
4079 --
4080 begin
4081 g_debug := hr_utility.debug_enabled;
4082 if g_debug then
4083 hr_utility.set_location('Entering:' ||l_proc,5);
4084 hr_utility.set_location('p_prtt_rt_val_id=' ||p_prtt_rt_val_id,5);
4085 hr_utility.set_location('p_rt_start_date=' ||p_rt_start_date,5);
4086 hr_utility.set_location('p_enrt_rslt_id=' ||p_enrt_rslt_id,5);
4087 hr_utility.set_location('p_rt=' ||p_rt,5);
4088 hr_utility.set_location('p_element_type_id=' ||p_element_type_id,5);
4089 hr_utility.set_location('p_input_value_id=' ||p_input_value_id,5);
4090 hr_utility.set_location('p_acty_base_rt_id=' ||p_acty_base_rt_id,5);
4091 hr_utility.set_location('p_effective_date=' ||p_effective_date,5);
4092 end if;
4093 --BUG 3167959 We need to intialize the pl/sql table
4094 clear_ext_inpval_tab ;
4095 --
4096 g_creee_calc_vals := l_creee_calc_vals;
4097 l_amt := p_rt;
4098 --
4099 -- get prtt rt information
4100 --
4101 if p_prtt_rt_val_id is not null then
4102 open c_get_prtt_rt_val
4103 (c_prtt_rt_val_id => p_prtt_rt_val_id
4104 );
4105 fetch c_get_prtt_rt_val into l_prv_rec;
4106 if c_get_prtt_rt_val%notfound
4107 then
4108 --
4109 if g_debug then
4110 hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL',170);
4111 end if;
4112 close c_get_prtt_rt_val;
4113 --
4114 fnd_message.set_name('BEN', 'BEN_92103_NO_PRTT_RT_VAL');
4115 fnd_message.set_token('PROC',l_proc);
4116 fnd_message.set_token('PRTT_RT_VAL',to_char(p_prtt_rt_val_id));
4117 fnd_message.raise_error;
4118 --
4119 end if;
4120 close c_get_prtt_rt_val;
4121 end if;
4122 --
4123 -- check if abs ler
4124 --
4125 open c_chk_abs_ler
4126 (c_per_in_ler_id => l_prv_rec.per_in_ler_id
4127 ,c_effective_date => p_effective_date
4128 );
4129 fetch c_chk_abs_ler into
4130 l_per_in_ler_id,
4131 l_lf_evt_ocrd_dt,
4132 l_absence_attendance_id,
4133 l_ler_id,
4134 l_ler_typ_cd;
4135 close c_chk_abs_ler;
4136 l_abs_ler := (nvl(l_ler_typ_cd,'xx') = 'ABS');
4137 --
4138 -- get activity base rate information
4139 --
4140 open get_abr_info
4141 (c_acty_base_rt_id => p_acty_base_rt_id
4142 ,c_effective_date => greatest(nvl(l_lf_evt_ocrd_dt,l_rt_strt_dt),l_rt_strt_dt)
4143 );
4144 fetch get_abr_info into l_get_abr_info;
4145 if get_abr_info%notfound then
4146 close get_abr_info;
4147 if g_debug then
4148 hr_utility.set_location('BEN_91723_NO_ENRT_RT_ABR_FOUND',5);
4149 end if;
4150 fnd_message.set_name('BEN','BEN_91723_NO_ENRT_RT_ABR_FOUND');
4151 fnd_message.set_token('PROC',l_proc);
4152 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
4153 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
4154 fnd_message.raise_error;
4155 end if;
4156 close get_abr_info;
4157
4158 g_acty_base_rt_name := l_get_abr_info.name;
4159 l_element_type_id := nvl(p_element_type_id,l_get_abr_info.element_type_id);
4160 l_input_value_id := nvl(p_input_value_id,l_get_abr_info.input_value_id);
4161 l_ele_entry_val_cd := l_get_abr_info.ele_entry_val_cd; -- Bug 5575402
4162 --
4163 -- For absences, for loading historical absence balances
4164 -- we need to continue in calculate_only_mode if an ele and inp val
4165 -- are attached. inelg_action_cd stores the flag to decide historical
4166 -- load or not
4167 --
4168 if l_abs_ler and
4169 l_get_abr_info.element_type_id is not null and
4170 l_get_abr_info.input_value_id is not null then
4171
4172 if g_param_rec.inelg_action_cd is null and
4173 benutils.g_benefit_action_id is not null then
4174 benutils.get_batch_parameters
4175 (benutils.g_benefit_action_id,
4176 g_param_rec);
4177 end if;
4178
4179 if nvl(g_param_rec.inelg_action_cd,'N') = 'N' then
4180 g_param_rec.inelg_action_cd := 'N';
4181 if l_get_abr_info.ele_rqd_flag='N' then
4182 if g_debug then
4183 hr_utility.set_location('Not historical abs loading ',124);
4184 hr_utility.set_location('Leaving: '||l_proc,124);
4185 end if;
4186 return;
4187 end if;
4188 else
4189 hr_utility.set_location('Historical abs loading ',124);
4190 l_calculate_only_mode := true;
4191 end if;
4192 elsif (l_get_abr_info.ele_rqd_flag='N' AND l_get_abr_info.element_det_rl is null) OR
4193 -- l_get_abr_info.element_type_id is null or
4194 -- l_get_abr_info.input_value_id is null then
4195 -- bug 6441505
4196 l_element_type_id is null or
4197 l_input_value_id is null then
4198 if g_debug then
4199 hr_utility.set_location('ele_rqd_flag=N',124);
4200 hr_utility.set_location('Leaving: '||l_proc,124);
4201 end if;
4202 return;
4203 end if;
4204 --
4205 -- Check for Current Assignment.
4206 --
4207 if NOT (chk_assign_exists
4208 (p_person_id => p_person_id
4209 ,p_business_group_id => p_business_group_id
4210 ,p_effective_date => p_effective_date
4211 ,p_rate_date => l_rt_strt_dt
4212 ,p_acty_base_rt_id => p_acty_base_rt_id
4213 ,p_assignment_id => l_assignment_id
4214 ,p_organization_id => l_organization_id
4215 ,p_payroll_id => l_payroll_id
4216 ))
4217 then
4218 --
4219 if g_debug then
4220 hr_utility.set_location('Create Benefits Assignment ',10);
4221 end if;
4222 --
4223 if not l_calculate_only_mode then
4224 --
4225 create_benefits_assignment
4226 (p_person_id => p_person_id
4227 ,p_payroll_id => l_payroll_id
4228 ,p_assignment_id => l_assignment_id
4229 ,p_business_group_id => p_business_group_id
4230 ,p_organization_id => l_organization_id
4231 ,p_effective_date => l_rt_strt_dt
4232 );
4233 --
4234 end if;
4235 --
4236 -- After create get values back
4237 --
4238 l_tmp_bool:=chk_assign_exists
4239 (p_person_id => p_person_id
4240 ,p_business_group_id => p_business_group_id
4241 ,p_effective_date => p_effective_date
4242 ,p_rate_date => l_rt_strt_dt
4243 ,p_acty_base_rt_id => p_acty_base_rt_id
4244 ,p_assignment_id => l_assignment_id
4245 ,p_organization_id => l_organization_id
4246 ,p_payroll_id => l_payroll_id
4247 );
4248 --
4249 end if;
4250 if g_debug then
4251 hr_utility.set_location('l_assignment_id:'||l_assignment_id,50);
4252 hr_utility.set_location('l_payroll_id:'||l_payroll_id,50);
4253 end if;
4254 --
4255 -- Bug 2675486 For SAREC Code if the enrollment benefit amount has not
4256 -- changed and the old rate start is in the current yr period NO need
4257 -- to compute the element entries.
4258 --
4259 --
4260 -- get the eligible element link for the assignment and element type
4261 --
4262 get_link(p_assignment_id => l_assignment_id
4263 ,p_element_type_id => l_element_type_id
4264 ,p_business_group_id => p_business_group_id
4265 ,p_input_value_id => l_input_value_id
4266 ,p_effective_date => l_rt_strt_dt
4267 ,p_element_link_id => l_element_link_id
4268 );
4269 if l_element_link_id is null then
4270 --
4271 -- error message already set on stack.
4272 --
4273 fnd_message.raise_error;
4274 end if;
4275
4276 l_old_element_link_id := l_element_link_id;
4277
4278 --
4279 -- determine if recurring entry or not
4280 --
4281 open c_ele_info(l_get_abr_info.element_type_id,l_rt_strt_dt);
4282 fetch c_ele_info into
4283 l_element_name,
4284 l_multiple_entries_flag,
4285 l_processing_type;
4286 close c_ele_info;
4287
4288 l_recurring_entry := (nvl(l_processing_type,l_dummy_varchar2) <> 'N' and
4289 nvl(l_get_abr_info.rcrrg_cd,l_dummy_varchar2) <> 'ONCE');
4290 --
4291 -- get the term rule date and link end date for use later on
4292 --
4293 hr_entry.entry_asg_pay_link_dates (l_assignment_id,
4294 l_element_link_id,
4295 l_rt_strt_dt,
4296 l_element_term_rule_date,
4297 l_out_date_not_required,
4298 l_element_link_end_date,
4299 l_out_date_not_required,
4300 l_out_date_not_required);
4301 --
4302 -- if assignment not terminated, l_element_term_rule_date is
4303 -- populated with eot
4304 --
4305 -- Get the element entry id if it exists.
4306 -- If not found then that's ok. We will create a new one.
4307 -- If found, we will update provided it passes validation checks
4308 --
4309
4310 -- Moved this code intentionally here.
4311 -- This is to address data corruption in an earlier version
4312 --
4313 l_mlt_cd := nvl(l_prv_rec.mlt_cd,l_get_abr_info.rt_mlt_cd);
4314 --
4315 -- Bug 5075200 - Rate with enter annual value is case similar to SAREC
4316 -- where we should not recreate element entries unless
4317 -- the annual value changes.
4318 --
4319 -- if l_mlt_cd = 'SAREC' OR
4320 -- l_get_abr_info.entr_ann_val_flag = 'Y' /* Bug 5075200 */
4321 -- then
4322 -- 5401779 - Can retain same element for both fsa and non_fsa plans, if the rt_val is same
4323 -- and the element_type and input_value are same.
4324
4325 if g_debug then
4326 hr_utility.set_location('l_processing_type = '|| l_processing_type,8085);
4327 end if;
4328
4329 --6643665 : Skip keep_same_element call for non-recurring element
4330 if l_processing_type <> 'N' then
4331 if keep_same_element(p_person_id => p_person_id,
4332 p_assignment_id => l_assignment_id,
4333 p_prtt_enrt_rslt_id=> p_enrt_rslt_id,
4334 p_prtt_rt_val_id => p_prtt_rt_val_id,
4335 p_acty_base_rt_id => p_acty_base_rt_id,
4336 p_ann_rt_val => l_prv_rec.ann_rt_val,
4337 p_cmcd_rt_val => l_prv_rec.cmcd_rt_val,
4338 p_rt_val => p_rt,
4339 p_rt_start_date => l_rt_strt_dt,
4340 p_mlt_cd => l_mlt_cd,
4341 p_element_type_id => p_element_type_id,
4342 p_input_value_id => p_input_value_id,
4343 p_ele_entry_val_cd => l_ele_entry_val_cd) -- Bug 5575402
4344 /*p_input_va_calc_rl => l_get_abr_info.input_va_calc_rl,
4345 p_payroll_id => l_payroll_id,
4346 p_organization_id => l_organization_id)*/
4347 then
4348 --
4349 if g_debug then
4350 hr_utility.set_location('Leaving: Dont need to create the ee',123);
4351 end if;
4352
4353 return;
4354 --
4355 end if ;
4356 end if; --6643665
4357
4358 --end if;
4359 --
4360 if l_prv_rec.element_entry_value_id is not null then
4361
4362 open get_element_entry_v(l_prv_rec.element_entry_value_id
4363 ,l_rt_strt_dt);
4364 fetch get_element_entry_v into
4365 l_element_entry_id,
4366 l_ee_effective_start_date,
4367 l_ee_effective_end_date,
4368 l_object_version_number,
4369 l_entry_value_id;
4370 close get_element_entry_v;
4371 --
4372 if g_debug then
4373 hr_utility.set_location('l_element_enrty_id='||l_element_entry_id,50);
4374 hr_utility.set_location('l_ee start_date='||l_ee_effective_start_date,50);
4375 hr_utility.set_location('l_ee end date='||l_ee_effective_end_date,50);
4376 hr_utility.set_location('l_entry_value_id='||l_entry_value_id,50);
4377 end if;
4378
4379 end if;
4380
4381 if not l_abs_ler or
4382 (l_abs_ler and l_multiple_entries_flag <> 'Y') then
4383 --
4384 if l_element_entry_id is null and
4385 l_recurring_entry then
4386
4387 open get_element_entry(l_element_link_id
4388 ,l_assignment_id
4389 ,null
4390 ,l_input_value_id
4391 ,null
4392 ,l_rt_strt_dt);
4393 fetch get_element_entry into
4394 l_element_entry_id,
4395 l_ee_effective_start_date,
4396 l_ee_effective_end_date,
4397 l_object_version_number,
4398 l_entry_value_id;
4399 close get_element_entry;
4400 --
4401 if g_debug then
4402 hr_utility.set_location('l_element_enrty_id='||l_element_entry_id,50);
4403 hr_utility.set_location('l_ee start_date='||l_ee_effective_start_date,50);
4404 hr_utility.set_location('l_ee end date='||l_ee_effective_end_date,50);
4405 hr_utility.set_location('l_entry_value_id='||l_entry_value_id,50);
4406 end if;
4407
4408 end if;
4409 --
4410 end if;
4411 --
4412 -- Validate the entry to be used
4413 --
4414 if l_element_entry_id is not null then
4415
4416 l_effective_start_date := l_ee_effective_start_date;
4417 l_effective_end_date := l_ee_effective_end_date;
4418 --
4419 --Check if entry value is already used by another prtt rt
4420 --
4421 open c_dup_prv(l_entry_value_id, l_rt_strt_dt);
4422 fetch c_dup_prv into l_abr_name;
4423 if c_dup_prv%found then
4424 --
4425 close c_dup_prv;
4426 fnd_message.set_name('BEN','BEN_92690_ELMNT_ALRDY_USD');
4427 fnd_message.set_token('P_RATE1',l_abr_name);
4428 fnd_message.set_token('P_RATE2',g_acty_base_rt_name);
4429 fnd_message.raise_error;
4430 --
4431 end if;
4432 close c_dup_prv;
4433 --
4434 --Check if entry is already used by another enrt rslt
4435 --
4436 open c_dup_rslt (l_element_entry_id,l_rt_strt_dt);
4437 fetch c_dup_rslt into l_abr_name;
4438 if c_dup_rslt%found then
4439 --
4440 close c_dup_rslt;
4441 fnd_message.set_name('BEN','BEN_93450_ELE_MULTIPLE_RSLT');
4442 fnd_message.set_token('P_RATE1',l_abr_name);
4443 fnd_message.set_token('P_RATE2',g_acty_base_rt_name);
4444 fnd_message.raise_error;
4445 --
4446 end if;
4447 close c_dup_rslt;
4448
4449 end if;
4450 --
4451 -- handle any future entries
4452 --
4453 if not l_abs_ler and
4454 l_recurring_entry then
4455 chk_future_entries
4456 (p_validate => p_validate,
4457 p_person_id => p_person_id,
4458 p_assignment_id => l_assignment_id,
4459 p_enrt_rslt_id => p_enrt_rslt_id,
4460 p_element_type_id => l_element_type_id,
4461 p_multiple_entries_flag => l_multiple_entries_flag,
4462 p_effective_date => l_rt_strt_dt);
4463 end if;
4464 --
4465 -- reopen the entry if already ended
4466 --
4467 l_max_ee_end_dt := null;
4468 --
4469 -- 5229941 : Multiple Rates may update same Element, but different Input values.
4470 -- If the max ee end-date <> EOT, then dont delete EE in FUTURE_CHANGE mode
4471 -- as we want to retain the special/normal adjustment amounts of the first Input Value
4472 -- when we calculate the special/normal adjustment amounts for the second Input Value.
4473 --
4474 open get_max_ee_end_dt(l_element_entry_id);
4475 fetch get_max_ee_end_dt into l_max_ee_end_dt;
4476 close get_max_ee_end_dt;
4477
4478 hr_utility.set_location('Max EE End Date '|| l_max_ee_end_dt, 9999);
4479 --
4480 if l_element_entry_id is not null and
4481 l_max_ee_end_dt <> hr_api.g_eot and -- 5229941
4482 l_ee_effective_end_date <> l_element_term_rule_date and
4483 l_ee_effective_end_date <> l_element_link_end_date then
4484
4485 begin
4486 --
4487 hr_utility.set_location(' Deleting All Future Rows ', 9999);
4488 --
4489 py_element_entry_api.delete_element_entry
4490 (p_validate =>p_validate
4491 ,p_datetrack_delete_mode =>'FUTURE_CHANGE'
4492 ,p_effective_date =>l_ee_effective_end_date
4493 ,p_element_entry_id =>l_element_entry_id
4494 ,p_object_version_number =>l_object_version_number
4495 ,p_effective_start_date =>l_effective_start_date
4496 ,p_effective_end_date =>l_effective_end_date
4497 ,p_delete_warning =>l_delete_warning);
4498
4499 exception
4500 when others then
4501 ben_on_line_lf_evt.get_ser_message(l_encoded_message,
4502 l_app_short_name,
4503 l_message_name);
4504 l_encoded_message := fnd_message.get;
4505 --
4506 if l_message_name like '%HR_6284_ELE_ENTRY_DT_ASG_DEL%' or
4507 l_message_name like '%HR_7187_DT_CANNOT_EXTEND_END%' then
4508 --
4509 -- assignment is not eligible for link beyond this date.
4510 -- Further reopening is not possible.
4511 --
4512 null;
4513 else
4514 if l_app_short_name is not null then
4515 fnd_message.set_name(l_app_short_name,l_message_name);
4516 fnd_message.raise_error;
4517 else
4518 raise;
4519 end if;
4520 end if;
4521 end;
4522
4523 end if;
4524
4525 if l_get_abr_info.parnt_chld_cd = 'CHLD' then
4526 --
4527 open c_abr2 (p_effective_date, p_acty_base_rt_id);
4528 fetch c_abr2 into l_prnt_abr;
4529 if c_abr2%found then
4530 --
4531 if g_debug then
4532 hr_utility.set_location('parnt_chld_cd=CHLD',50);
4533 hr_utility.set_location('prnt rt mlt:'||l_prnt_abr.rt_mlt_cd,50);
4534 hr_utility.set_location('prnt entr ann:'||l_prnt_abr.entr_ann_val_flag,50);
4535 end if;
4536 if l_prnt_abr.rt_mlt_cd = 'SAREC' or
4537 l_prnt_abr.entr_ann_val_flag = 'Y' then
4538 l_prnt_ann_rt := 'Y';
4539 end if ;
4540 --
4541 end if;
4542 close c_abr2 ;
4543 --
4544 end if;
4545 --
4546 if nvl(g_result_rec.prtt_enrt_rslt_id,-1) <> p_enrt_rslt_id then
4547 open c_current_result_info
4548 (c_prtt_enrt_rslt_id => p_enrt_rslt_id
4549 );
4550 fetch c_current_result_info into g_result_rec;
4551 close c_current_result_info;
4552
4553 if g_debug then
4554 hr_utility.set_location('pen esd='||g_result_rec.effective_start_date,10);
4555 hr_utility.set_location('pen eed='||g_result_rec.effective_end_date,10);
4556 end if;
4557
4558 end if;
4559
4560 --
4561 -- Check the PRTL MONTH PRORATION rule
4562 -- against the effective date and payperiod
4563 -- of participants payroll.
4564 --
4565 -- ELE : By pass if the ele_entry_val_cd <> PP,EPP or null.
4566 --
4567 --
4568 if nvl(l_get_abr_info.ele_entry_val_cd, 'PP') = 'PP' or
4569 l_get_abr_info.ele_entry_val_cd = 'EPP' then
4570 --
4571 -- Get proper code from rule execution.
4572 --
4573 if l_get_abr_info.prtl_mo_eff_dt_det_cd = 'RL' and
4574 l_get_abr_info.prtl_mo_eff_dt_det_rl is not null then
4575 --
4576 -- exec rule and get code back
4577 --
4578 l_outputs:=benutils.formula
4579 (p_opt_id => g_result_rec.opt_id,
4580 p_pl_id => g_result_rec.pl_id,
4581 p_pgm_id => g_result_rec.pgm_id,
4582 p_formula_id => l_get_abr_info.prtl_mo_eff_dt_det_rl,
4583 p_ler_id => g_result_rec.ler_id,
4584 p_pl_typ_id => g_result_rec.pl_typ_id,
4585 p_assignment_id => l_assignment_id,
4586 p_acty_base_rt_id => p_acty_base_rt_id,
4587 p_business_group_id => p_business_group_id,
4588 p_organization_id => l_organization_id,
4589 p_jurisdiction_code => l_jurisdiction_code,
4590 p_effective_date => p_effective_date);
4591 --
4592 begin
4593 --
4594 -- convert return value to code
4595 --
4596 l_get_abr_info.prtl_mo_eff_dt_det_cd:=l_outputs(l_outputs.first).value;
4597 --
4598 exception
4599 --
4600 when others then
4601 if g_debug then
4602 hr_utility.set_location('BEN_92311_FORMULA_VAL_PARAM',30);
4603 end if;
4604 fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
4605 fnd_message.set_token('PROC',l_proc);
4606 fnd_message.set_token('FORMULA',l_get_abr_info.prtl_mo_det_mthd_rl);
4607 fnd_message.set_token('PARAMETER',
4608 l_outputs(l_outputs.first).name);
4609 fnd_message.raise_error;
4610 --
4611 end;
4612 end if;
4613 -- ELE :
4614 end if;
4615 --
4616 -- ELE : By pass if the ele_entry_val_cd <> PP, EPP, or null.
4617 --
4618 if nvl(l_get_abr_info.ele_entry_val_cd, 'PP') = 'PP' or
4619 l_get_abr_info.ele_entry_val_cd = 'EPP' then
4620 --
4621 --
4622 -- When this flag is off, we do not annualize the rate value because it's
4623 -- just a 'multiple of' value. Like the '3' in '3% of comp'
4624 --
4625 if l_get_abr_info.use_calc_acty_bs_rt_flag = 'N' then
4626 --
4627 if l_get_abr_info.rt_typ_cd = 'PERTEN' then
4628 -- divide the value by ten
4629 l_amt := l_amt/10;
4630 elsif l_get_abr_info.rt_typ_cd = 'PCT' or l_get_abr_info.rt_typ_cd = 'PERHNDRD' then
4631 -- divide the value by one hundred
4632 l_amt := l_amt/100;
4633 elsif l_get_abr_info.rt_typ_cd = 'PERTHSND' then
4634 -- divide by one thousand
4635 l_amt := l_amt/1000;
4636 elsif l_get_abr_info.rt_typ_cd = 'PERTTHSND' then
4637 -- divide by ten thousand
4638 l_amt := l_amt/10000;
4639 end if; -- if MLT or null, leave value as is.
4640 --
4641 l_per_pay_amt := l_amt;
4642 --
4643 else
4644 --
4645 -- Annualize rate.
4646 --
4647 -- get plan year
4648 --
4649 if g_debug then
4650 hr_utility.set_location('Acty Ref Perd'||p_acty_ref_perd,10);
4651 hr_utility.set_location('prv_id= '|| p_prtt_rt_val_id,10);
4652 hr_utility.set_location('payroll= '|| l_payroll_id,10);
4653 hr_utility.set_location('bg= '|| p_business_group_id,10);
4654 hr_utility.set_location('rt_start= '|| l_rt_strt_dt,10);
4655 end if;
4656 --
4657 --Bug 3430334 we need to find the year period based on the
4658 --pay priod end date or check date to get the right plan
4659 --year period. Rate may start in the previous year period but
4660 --end of pay period may fall in the current pay period.
4661 --
4662 if l_get_abr_info.entr_ann_val_flag='Y' or
4663 l_prnt_ann_rt = 'Y' or
4664 l_mlt_cd = 'SAREC' then
4665 --
4666 open c_current_fsa_pp_end
4667 ( p_payroll_id => l_payroll_id,
4668 p_rt_start_date=> l_rt_strt_dt );
4669 --
4670 fetch c_current_fsa_pp_end into l_current_pp_end_date,l_ptp_end_date;
4671 close c_current_fsa_pp_end ;
4672 hr_utility.set_location('l_current_pp_end_date '||l_current_pp_end_date,10);
4673 hr_utility.set_location('l_ptp_end_date '||l_ptp_end_date,10);
4674
4675 /* Bug 8985608: If check payment date and pay period end date fall in different years
4676 consider the greatest of the two values to get the plan year period*/
4677 if( trunc(l_current_pp_end_date,'YY') <> trunc(l_ptp_end_date,'YY') ) then
4678 l_current_pp_end_date := greatest(l_current_pp_end_date,l_ptp_end_date);
4679 end if;
4680 --
4681 else
4682 --
4683 open c_current_pp_end
4684 ( p_payroll_id => l_payroll_id,
4685 p_rt_start_date=> l_rt_strt_dt );
4686 fetch c_current_pp_end into l_current_pp_end_date ;
4687 close c_current_pp_end ;
4688 --
4689 end if;
4690 --
4691 if g_debug then
4692 hr_utility.set_location('l_current_pp_end_date '||l_current_pp_end_date,10);
4693 end if;
4694 l_pl_id := nvl(p_pl_id,g_result_rec.pl_id);
4695 if l_pl_id is not null then
4696
4697 open c_plan_year_end_for_pl
4698 (c_pl_id => l_pl_id
4699 ,c_rate_start_or_end_dt => nvl(l_current_pp_end_date,l_rt_strt_dt)
4700 );
4701 fetch c_plan_year_end_for_pl into
4702 l_last_pp_strt_dt,
4703 l_last_pp_end_dt;
4704 close c_plan_year_end_for_pl;
4705
4706 else
4707 open c_plan_year_end_for_pen
4708 (c_prtt_enrt_rslt_id => p_enrt_rslt_id
4709 ,c_rate_start_or_end_dt => nvl(l_current_pp_end_date,l_rt_strt_dt)
4710 ,c_effective_date => p_effective_date
4711 );
4712 fetch c_plan_year_end_for_pen into
4713 l_last_pp_strt_dt,
4714 l_last_pp_end_dt;
4715 close c_plan_year_end_for_pen;
4716
4717 end if;
4718
4719 if l_get_abr_info.entr_ann_val_flag='Y' or
4720 l_prnt_ann_rt = 'Y' or
4721 l_mlt_cd = 'SAREC' then
4722 --l_range_start:=l_rt_strt_dt+1;
4723 --bug#2398448 and bug#2392732
4724 l_range_start:=l_rt_strt_dt;
4725 else
4726 --
4727 --Bug 3294702 We can safely take l_last_pp_strt_dt here.
4728 --
4729 --l_range_start:=add_months(l_last_pp_end_dt,-12) + 1;
4730 l_range_start:= l_last_pp_strt_dt ;
4731 --
4732 end if;
4733 --
4734 -- Bug2843979: Raising proper error if year period not found and
4735 -- elig_per_elctbl_chc_id is not populated in the ben_epe_cache
4736 --
4737 if l_last_pp_end_dt is null and
4738 ben_epe_cache.g_currepe_row.elig_per_elctbl_chc_id is null then
4739 --
4740 fnd_message.set_name('BEN','BEN_93368_DETERMINE_PAY_PERIOD');
4741 fnd_message.raise_error;
4742 --
4743 end if;
4744 --
4745 -- Bug 2149438
4746 if l_mlt_cd = 'SAREC' or
4747 l_prnt_ann_rt = 'Y' then
4748 --
4749 -----------Bug 8872583
4750 hr_utility.set_location('l_payroll_id : '|| l_payroll_id,20);
4751 l_bal_flag := 'N';
4752 open c_chk_pay_periods(l_payroll_id,l_lf_evt_ocrd_dt);
4753 fetch c_chk_pay_periods into l_chk_pay_periods;
4754 if c_chk_pay_periods%found then
4755 hr_utility.set_location('l_chk_pay_periods.end_date : '|| l_chk_pay_periods.end_date,20);
4756 hr_utility.set_location('p_rt_start_date : '|| p_rt_start_date,20);
4757 if p_rt_start_date > l_chk_pay_periods.end_date then -- 12852041
4758 ----Bug 7196470
4759 open c_enrt_rt;
4760 fetch c_enrt_rt into l_enrt_rt_id;
4761 close c_enrt_rt;
4762 l_bal_flag := 'Y';
4763 end if;
4764 end if;
4765 hr_utility.set_location('l_bal_flag : '|| l_bal_flag,20);
4766 -------------Bug 8872583
4767 l_amt:=ben_distribute_rates.period_to_annual
4768 (p_amount => l_amt
4769 ,p_enrt_rt_id => l_enrt_rt_id--------Bug 7196470
4770 ,p_acty_ref_perd_cd => p_acty_ref_perd
4771 ,p_business_group_id => p_business_group_id
4772 ,p_effective_date => l_rt_strt_dt
4773 ,p_complete_year_flag => 'N'
4774 ,p_use_balance_flag => nvl(l_bal_flag,'N') ---Bug 8872583,'Y'-------'N'----Bug 7196470
4775 ,p_element_type_id => l_element_type_id
4776 ,p_start_date => l_range_start
4777 ,p_end_date => l_last_pp_end_dt
4778 ,p_payroll_id => l_payroll_id
4779 ,p_rounding_flag => 'N' --Bug 2149438
4780 );
4781 -- Moved the rounding from the bendisrt to handle differently.
4782 --
4783 l_amt := round(l_amt,4);
4784 --
4785 else
4786 --
4787 l_amt:=ben_distribute_rates.period_to_annual
4788 (p_amount => l_amt
4789 ,p_acty_ref_perd_cd => p_acty_ref_perd
4790 ,p_business_group_id => p_business_group_id
4791 ,p_effective_date => l_rt_strt_dt
4792 ,p_complete_year_flag => 'N'
4793 ,p_use_balance_flag => 'N'
4794 ,p_element_type_id => l_element_type_id
4795 ,p_start_date => l_range_start
4796 ,p_end_date => l_last_pp_end_dt
4797 ,p_payroll_id => l_payroll_id
4798 );
4799 --
4800 end if;
4801 --
4802 -- Bug 2675486 To fix the temporary rounding issues not to get more than
4803 -- the annual amount
4804 --
4805 if g_debug then
4806 hr_utility.set_location('before l_amt '||l_amt,20);
4807 end if;
4808 --
4809 if (l_mlt_cd = 'SAREC' or l_prnt_ann_rt = 'Y') and
4810 l_amt > p_ann_rt then
4811 l_amt := p_ann_rt ;
4812 end if;
4813 --
4814 -- To do proration need monthly amount divide by 12.
4815 --
4816 l_per_month_amt := l_amt/12;
4817 if g_debug then
4818 hr_utility.set_location('p_ann_rt '||p_ann_rt,20);
4819 hr_utility.set_location('l_per_month_amt '||l_per_month_amt,20);
4820 hr_utility.set_location('l_amt '||l_amt,20);
4821 end if;
4822 --
4823 -- Compute per pay amt
4824 --
4825 if l_get_abr_info.ele_entry_val_cd = 'EPP' then
4826 l_perd_cd := 'EPP';
4827 end if;
4828 --
4829 if l_get_abr_info.entr_ann_val_flag='Y' or
4830 l_mlt_cd = 'SAREC' or
4831 l_prnt_ann_rt = 'Y' then
4832 l_annual_target := true;
4833 end if;
4834 --
4835 l_per_pay_amt:=ben_distribute_rates.annual_to_period
4836 (p_amount =>l_amt
4837 ,p_acty_ref_perd_cd =>l_perd_cd
4838 ,p_business_group_id =>p_business_group_id
4839 ,p_effective_date =>l_rt_strt_dt
4840 ,p_complete_year_flag =>'N'
4841 ,p_use_balance_flag =>'N'
4842 ,p_element_type_id => l_element_type_id
4843 ,p_start_date =>l_range_start
4844 ,p_end_date =>l_last_pp_end_dt
4845 ,p_payroll_id =>l_payroll_id
4846 ,p_annual_target =>l_annual_target
4847 ,p_rounding_flag =>'N'
4848 );
4849 --
4850 if g_debug then
4851 hr_utility.set_location(' before rounding l_per_pay_amt '||l_per_pay_amt ,122);
4852 end if;
4853 if (l_get_abr_info.rndg_cd is not null
4854 or l_get_abr_info.rndg_rl is not null)
4855 and l_per_pay_amt is not null
4856 then
4857 --
4858 l_per_pay_amt := benutils.do_rounding
4859 (p_rounding_cd => l_get_abr_info.rndg_cd
4860 ,p_rounding_rl => l_get_abr_info.rndg_rl
4861 ,p_value => l_per_pay_amt
4862 ,p_effective_date => l_rt_strt_dt
4863 );
4864 --
4865 elsif l_per_pay_amt is not null
4866 and l_per_pay_amt<>0
4867 then
4868 --
4869 -- Do this for now: in future default to rounding for currency precision
4870 --
4871 l_per_pay_amt:=round(l_per_pay_amt,2);
4872 --
4873 end if;
4874 --
4875 if g_debug then
4876 hr_utility.set_location(' after round per_pay_periodamt '||l_per_pay_amt,103);
4877 hr_utility.set_location(' l_amt ' || l_amt ,103);
4878 hr_utility.set_location(' entr_ann_val_flag ' || l_get_abr_info.entr_ann_val_flag,102);
4879 end if;
4880 -- bug#3443215 - rounding to annual amount is called for all the acty ref period
4881 /* if (l_get_abr_info.entr_ann_val_flag='Y' or
4882 p_acty_ref_perd = 'PYR' or
4883 l_mlt_cd = 'SAREC' or
4884 l_prnt_ann_rt = 'Y') and
4885 */
4886 if l_recurring_entry then
4887
4888 if g_debug then
4889 hr_utility.set_location(' entrer in condition ' ,102);
4890 end if;
4891 --
4892 -- need to match annual amount so adjust for
4893 -- rounding errors on annual basis by finding
4894 -- amount off and adding to first ee.
4895 -- Bug#2809677
4896 --
4897 if l_get_abr_info.entr_ann_val_flag='Y' or
4898 l_mlt_cd = 'SAREC' or
4899 l_prnt_ann_rt = 'Y' then
4900 --
4901 l_pay_periods:=ben_distribute_rates.get_periods_between(
4902 p_acty_ref_perd_cd =>l_perd_cd --'PP'
4903 ,p_start_date =>l_range_start
4904 ,p_end_date =>l_last_pp_end_dt
4905 ,p_payroll_id =>l_payroll_id
4906 ,p_business_group_id =>p_business_group_id
4907 ,p_element_type_id => l_element_type_id
4908 ,p_effective_date => p_effective_date
4909 --bug#2556948
4910 ,p_use_check_date => true
4911 );
4912
4913 else
4914 --
4915 l_pay_periods:=ben_distribute_rates.get_periods_between(
4916 p_acty_ref_perd_cd =>l_perd_cd --'PP'
4917 ,p_start_date =>l_range_start
4918 ,p_end_date =>l_last_pp_end_dt
4919 ,p_payroll_id =>l_payroll_id
4920 ,p_business_group_id =>p_business_group_id
4921 ,p_element_type_id => l_element_type_id
4922 ,p_effective_date => p_effective_date
4923 );
4924 end if;
4925
4926 if g_debug then
4927 hr_utility.set_location(' l_pay_periods '||l_pay_periods ,122);
4928 end if;
4929 --
4930 -- Want amount we are under to be positive so we can
4931 -- add the amount to the first ee.
4932 --
4933 -- Bear in mind that this could be for acty_ref_perd = 'PYR' but
4934 -- entr_ann_val_flag = 'N' in which case the calculation needs
4935 -- to be adjusted.
4936 --
4937 if l_get_abr_info.entr_ann_val_flag = 'Y' or
4938 l_mlt_cd = 'SAREC' or
4939 l_prnt_ann_rt = 'Y' then
4940 --
4941 l_first_pp_adjustment:=l_amt - l_pay_periods * l_per_pay_amt;
4942 --
4943 if g_debug then
4944 hr_utility.set_location(' l_first_pp_adjustment '||l_first_pp_adjustment,122);
4945 end if;
4946 --
4947 else
4948 --
4949 -- Fix for WWBUG 1263111
4950 --
4951 -- We have to do a bit of adjusting here.
4952 --
4953 -- First get the real number of periods left.
4954 --
4955 if nvl(l_lf_evt_ocrd_dt,p_effective_date) < l_last_pp_end_dt then
4956 l_real_num_periods:=ben_distribute_rates.get_periods_between
4957 (p_acty_ref_perd_cd =>l_perd_cd --PP'
4958 ,p_start_date => l_rt_strt_dt --p_effective_date
4959 ,p_end_date => l_last_pp_end_dt
4960 ,p_payroll_id => l_payroll_id
4961 ,p_business_group_id => p_business_group_id
4962 ,p_element_type_id => l_element_type_id
4963 ,p_effective_date => nvl(l_lf_evt_ocrd_dt,p_effective_date));
4964 else
4965 l_real_num_periods:=ben_distribute_rates.get_periods_between
4966 (p_acty_ref_perd_cd =>l_perd_cd --PP'
4967 ,p_start_date => nvl(l_lf_evt_ocrd_dt,p_effective_date)
4968 ,p_payroll_id => l_payroll_id
4969 ,p_business_group_id => p_business_group_id
4970 ,p_element_type_id => l_element_type_id
4971 ,p_effective_date => nvl(l_lf_evt_ocrd_dt,p_effective_date));
4972 end if;
4973 --
4974 l_first_pp_adjustment:= ((l_amt*l_real_num_periods)/l_pay_periods) - (l_real_num_periods * l_per_pay_amt);
4975 --
4976 -- End of Fix for WWBUG 1263111
4977 --
4978 -- Bug 15929812
4979 if l_first_pp_adjustment <> 0 then
4980
4981 l_done:=check_for_first_pp_adjustment(p_last_pp_strt_dt => l_last_pp_strt_dt,
4982 p_last_pp_end_dt => l_last_pp_end_dt,
4983 p_annual_amt => l_amt,
4984 p_per_pay_amt => l_per_pay_amt,
4985 p_payroll_id => l_payroll_id,
4986 p_enrt_rslt_id => p_enrt_rslt_id,
4987 p_prtt_rt_val_id => p_prtt_rt_val_id);
4988
4989 if l_done then
4990 hr_utility.set_location('uxx ',10);
4991 l_first_pp_adjustment := 0;
4992 end if;
4993
4994 end if;
4995 -- Bug 15929812
4996 end if;
4997 --
4998 if (l_get_abr_info.rndg_cd is not null or
4999 l_get_abr_info.rndg_rl is not null) and
5000 l_first_pp_adjustment is not null then
5001 l_first_pp_adjustment := benutils.do_rounding
5002 (p_rounding_cd => l_get_abr_info.rndg_cd,
5003 p_rounding_rl => l_get_abr_info.rndg_rl,
5004 p_value => l_first_pp_adjustment,
5005 p_effective_date => l_rt_strt_dt);
5006 elsif l_first_pp_adjustment is not null and
5007 l_first_pp_adjustment<>0 then
5008 --
5009 -- Do this for now: in future default to rounding for currency precision
5010 --
5011 l_first_pp_adjustment:=round(l_first_pp_adjustment,2);
5012 end if;
5013 if g_debug then
5014 hr_utility.set_location('first pp adjustment='||l_first_pp_adjustment,10);
5015 end if;
5016 --
5017 end if;
5018 --
5019 if g_debug then
5020 hr_utility.set_location(' out nocopy of condition ' ,102);
5021 end if;
5022 end if; -- use_calc_acty_base_rt_flag is 'Y'
5023
5024 if l_get_abr_info.one_ann_pymt_cd is null
5025 and l_get_abr_info.use_calc_acty_bs_rt_flag = 'Y'
5026 then
5027 --
5028 if g_debug then
5029 hr_utility.set_location(' first condition ' ,102);
5030 end if;
5031 -- Prorate the rate, if necessary
5032 -- let prorate_amount function decide then either
5033 -- l_new_val is the same as l_amount, or not for proration.
5034 -- l_prtn_val will be set.
5035 --
5036 -- Don't prorate if it's 'one annual payment' or if we didn't calc rate yet.
5037 --
5038 if g_debug then
5039 hr_utility.set_location('Prorate the rate',20);
5040 hr_utility.set_location('l_per_month_amt '||l_per_month_amt,20);
5041 end if;
5042 --
5043 -- Bug 6834340
5044 open c_ler_with_current_prv(p_prtt_rt_val_id, p_rt_start_date);
5045 fetch c_ler_with_current_prv into l_ler_with_current_prv;
5046 close c_ler_with_current_prv;
5047 -- Bug 6834340
5048 --
5049 l_prorated_monthly_amt := prorate_amount
5050 (p_amt => l_per_month_amt
5051 ,p_acty_base_rt_id => p_acty_base_rt_id
5052 ,p_prorate_flag => l_prtn_flag
5053 ,p_effective_date => l_rt_strt_dt
5054 ,p_start_or_stop_cd => 'STRT'
5055 ,p_start_or_stop_date => l_rt_strt_dt
5056 ,p_business_group_id => p_business_group_id
5057 ,p_assignment_id => l_assignment_id
5058 ,p_organization_id => l_organization_id
5059 ,p_wsh_rl_dy_mo_num => l_get_abr_info.wsh_rl_dy_mo_num
5060 ,p_prtl_mo_det_mthd_cd => l_get_abr_info.prtl_mo_det_mthd_cd
5061 ,p_prtl_mo_det_mthd_rl => l_get_abr_info.prtl_mo_det_mthd_rl
5062 ,p_person_id => g_result_rec.person_id
5063 ,p_pgm_id => g_result_rec.pgm_id
5064 ,p_pl_typ_id => g_result_rec.pl_typ_id
5065 ,p_pl_id => g_result_rec.pl_id
5066 ,p_opt_id => g_result_rec.opt_id
5067 ,p_ler_id => l_ler_with_current_prv.ler_id -- Bug 6834340
5068 ,p_jurisdiction_code => l_jurisdiction_code
5069 ,p_rndg_cd => l_get_abr_info.rndg_cd
5070 ,p_rndg_rl => l_get_abr_info.rndg_rl
5071 );
5072 if g_debug then
5073 hr_utility.set_location('l_prorated_monthly_amt='||l_prorated_monthly_amt,123);
5074 end if;
5075 --
5076 else
5077 if g_debug then
5078 hr_utility.set_location(' else condition '|| l_get_abr_info.one_ann_pymt_cd ,102);
5079 end if;
5080 l_prtn_flag:='N';
5081 if l_get_abr_info.one_ann_pymt_cd='LPPPYCFC' then
5082 l_normal_pp_date:=l_last_pp_strt_dt;
5083 l_normal_pp_end_date:=l_last_pp_end_dt;
5084 elsif l_get_abr_info.one_ann_pymt_cd='LPPCYCFC' then
5085 open c_last_pp_of_cal_year(l_payroll_id
5086 ,l_rt_strt_dt);
5087 loop
5088 fetch c_last_pp_of_cal_year into
5089 l_normal_pp_date,
5090 l_normal_pp_end_date;
5091 exit when c_last_pp_of_cal_year%notfound;
5092 hr_elements.check_element_freq(
5093 p_payroll_id =>l_payroll_id,
5094 p_bg_id =>p_business_group_id,
5095 p_pay_action_id =>to_number(null),
5096 p_date_earned =>l_normal_pp_date,
5097 p_ele_type_id =>l_element_type_id,
5098 p_skip_element =>g_skip_element
5099 );
5100 exit when g_skip_element='N';
5101 end loop;
5102 close c_last_pp_of_cal_year;
5103 elsif l_get_abr_info.one_ann_pymt_cd='FPPCFC' then
5104 open c_first_pp_after_start(l_payroll_id
5105 ,l_rt_strt_dt);
5106 loop
5107 fetch c_first_pp_after_start into
5108 l_normal_pp_date,
5109 l_normal_pp_end_date;
5110 exit when c_first_pp_after_start%notfound;
5111 hr_elements.check_element_freq(
5112 p_payroll_id =>l_payroll_id,
5113 p_bg_id =>p_business_group_id,
5114 p_pay_action_id =>to_number(null),
5115 p_date_earned =>l_normal_pp_date,
5116 p_ele_type_id =>l_element_type_id,
5117 p_skip_element =>g_skip_element
5118 );
5119 exit when g_skip_element='N';
5120 end loop;
5121 close c_first_pp_after_start;
5122 elsif l_get_abr_info.one_ann_pymt_cd is not null then
5123 --
5124 -- raise error as does not exist as lookup
5125 --
5126 if g_debug then
5127 hr_utility.set_location('BEN_91628_LOOKUP_TYPE_GENERIC',30);
5128 end if;
5129 fnd_message.set_name('BEN','BEN_91628_LOOKUP_TYPE_GENERIC');
5130 fnd_message.set_token('FIELD','p_one_ann_pymt_cd');
5131 fnd_message.set_token('TYPE','BEN_ONE_ANN_PYMT');
5132 fnd_message.set_token('VALUE',l_get_abr_info.one_ann_pymt_cd);
5133 fnd_message.raise_error;
5134 end if;
5135 end if;
5136
5137 -- ELE :
5138 end if;
5139 if g_debug then
5140 hr_utility.set_location(' out of if condition' ,102);
5141 end if;
5142 --
5143 -- Create the element entries
5144 --
5145 --
5146 -- Determine prorated first pay periods
5147 -- Where amount is not the normal per pay period amount
5148 --
5149 -- ELE : By pass if the ele_entry_val_cd <> PP, EPP, or null.
5150 --
5151 --
5152 if nvl(l_get_abr_info.ele_entry_val_cd, 'PP') = 'PP' or
5153 l_get_abr_info.ele_entry_val_cd = 'EPP' then
5154 --
5155 if l_prtn_flag = 'Y' then
5156 if g_debug then
5157 hr_utility.set_location('Determine proration ',40);
5158 end if;
5159 if g_debug then
5160 hr_utility.set_location('l_prorated_monthly_amt '||l_prorated_monthly_amt,40);
5161 end if;
5162 --
5163 -- Approach/algorithm to allocating payments:
5164 --
5165 -- In Starting a new rate there are three distinct rate stages
5166 -- 1) No pay periods - pay periods during which no rate should be in effect.
5167 -- 2) Special pay period - pay period during which a rate not equal to the normal rate
5168 -- is in effect. Just one pay period. Spreading them out is outside the scope
5169 -- of this version.
5170 -- 3) Normal pay periods - Periodic rate is in place.
5171 -----------------------------------------------------------
5172 --
5173 -- Want to find the pay periods from the start date
5174 -- ending at the last day of the month or earlier
5175 -- based on the date column specified by prtl_mo_eff_dt_det_cd
5176 --
5177 -- Go backwards and keep overwriting the dates with the most
5178 -- recent one to get the first date it changes to that rate.
5179 --
5180 l_remainder:=l_prorated_monthly_amt;
5181 l_number_in_month:=0;
5182 --
5183 for l_pay_periods in c_next_pay_periods(
5184 p_start_date => l_rt_strt_dt,
5185 p_end_date => add_months(
5186 trunc(l_rt_strt_dt,'mm'),1)-1,
5187 p_prtl_mo_eff_dt_det_cd => l_get_abr_info.prtl_mo_eff_dt_det_cd,
5188 p_payroll_id => l_payroll_id) loop
5189 --
5190 hr_elements.check_element_freq(
5191 p_payroll_id =>l_payroll_id,
5192 p_bg_id =>p_business_group_id,
5193 p_pay_action_id =>to_number(null),
5194 p_date_earned =>l_pay_periods.start_date,
5195 p_ele_type_id =>l_element_type_id,
5196 p_skip_element =>g_skip_element
5197 );
5198 if g_debug then
5199 hr_utility.set_location('pay_start_date '||l_pay_periods.start_date,40);
5200 hr_utility.set_location('end_date '||l_pay_periods.end_date,40);
5201 end if;
5202 if g_skip_element='N' then
5203 l_number_in_month:=l_number_in_month+1;
5204 if l_remainder>l_per_pay_amt then
5205 if g_debug then
5206 hr_utility.set_location('l_per_pay_amt '||l_per_pay_amt,40);
5207 end if;
5208 --
5209 if l_rt_strt_dt > l_pay_periods.start_date then
5210 l_remainder := l_remainder-l_per_pay_amt;
5211 l_old_normal_pp_date:=l_normal_pp_date;
5212 l_normal_pp_date:=l_rt_strt_dt;
5213 exit;
5214 else
5215 --
5216 -- Normal pay period, may not be if have remainder left over
5217 -- In this case will revise date after loop is done
5218 --
5219 l_remainder:=l_remainder-l_per_pay_amt;
5220 l_old_normal_pp_date:=l_normal_pp_date;
5221 l_normal_pp_date:=l_pay_periods.start_date;
5222 end if;
5223 elsif l_remainder=0 then
5224 --
5225 -- Free pay period, no charge
5226 --
5227 l_zero_pp_date:=l_rt_strt_dt;
5228 else
5229 --
5230 -- Special small pay period, from here on it's free.
5231 --
5232 /* if l_zero_pp_date is null then
5233 l_special_pp_date:=l_rt_strt_dt;
5234 else */
5235 if l_rt_strt_dt <= l_pay_periods.start_date then
5236 l_special_pp_date:=l_pay_periods.start_date;
5237 else
5238 l_special_pp_date:=l_rt_strt_dt;
5239 end if;
5240 -- end if;
5241 if g_debug then
5242 hr_utility.set_location('l_special_pp_date '||l_special_pp_date,40);
5243 hr_utility.set_location('l_remainder '||l_remainder,40);
5244 end if;
5245 --
5246 l_special_amt:=l_remainder;
5247 l_remainder:=0;
5248 end if;
5249 end if;
5250 end loop;
5251 --
5252 -- Now check if loop was not entered
5253 --
5254 if l_number_in_month=0 then
5255 --
5256 -- This is the Large amount case
5257 -- where the full amount gets added to the first pp of next month
5258 --
5259 if g_debug then
5260 hr_utility.set_location('p_payroll_id'||l_payroll_id,10);
5261 end if;
5262 --
5263 open c_pps_next_month(
5264 p_end_date => add_months(
5265 trunc(l_rt_strt_dt,'mm'),1)-1,
5266 p_prtl_mo_eff_dt_det_cd => l_get_abr_info.prtl_mo_eff_dt_det_cd,
5267 p_payroll_id => l_payroll_id);
5268 loop
5269 fetch c_pps_next_month into l_start_date,l_end_date;
5270 if c_pps_next_month%notfound then
5271 close c_pps_next_month;
5272 if g_debug then
5273 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',30);
5274 end if;
5275 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
5276 fnd_message.set_token('PROC',l_proc);
5277 fnd_message.raise_error;
5278 end if;
5279 hr_elements.check_element_freq(
5280 p_payroll_id =>l_payroll_id,
5281 p_bg_id =>p_business_group_id,
5282 p_pay_action_id =>to_number(null),
5283 p_date_earned =>l_start_date,
5284 p_ele_type_id =>l_element_type_id,
5285 p_skip_element =>g_skip_element
5286 );
5287 exit when g_skip_element='N';
5288 end loop;
5289
5290 --Bug 5259022 Added the below validation
5291 --element entries overlap if the below validation is absent
5292
5293 if l_start_date <= l_rt_strt_dt then
5294 l_special_pp_date:= l_rt_strt_dt;
5295 else
5296 l_special_pp_date:= l_start_date;
5297 end if;
5298 --End Bug 5259022
5299
5300 l_special_amt:=l_remainder+l_per_pay_amt;
5301 --
5302 loop
5303 fetch c_pps_next_month into l_start_date,l_end_date;
5304 if c_pps_next_month%notfound then
5305 close c_pps_next_month;
5306 if g_debug then
5307 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',32);
5308 end if;
5309 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
5310 fnd_message.set_token('PROC',l_proc);
5311 fnd_message.raise_error;
5312 end if;
5313 hr_elements.check_element_freq(
5314 p_payroll_id =>l_payroll_id,
5315 p_bg_id =>p_business_group_id,
5316 p_pay_action_id =>to_number(null),
5317 p_date_earned =>l_start_date,
5318 p_ele_type_id =>l_element_type_id,
5319 p_skip_element =>g_skip_element
5320 );
5321 exit when g_skip_element='N';
5322 end loop;
5323 close c_pps_next_month;
5324 l_normal_pp_date:= l_start_date;
5325 --
5326 elsif l_remainder>0 then
5327 --
5328 -- This is case where the first pp of the current month
5329 -- should be bigger because the prorated amount could
5330 -- not fit in the month with amounts <= per_pay_amt
5331 -- In this case there will be no zero pay periods
5332 -- The first normal pp is moved forward to the second one
5333 -- The special pp is set to the first normal one
5334 --
5335 l_special_pp_date:=l_normal_pp_date;
5336 l_special_amt:=l_remainder+l_per_pay_amt;
5337 l_normal_pp_date:=l_old_normal_pp_date;
5338 end if;
5339 --
5340 -- In the cases where a normal pp was not found then it
5341 -- must be the first pp of the next month
5342 --
5343 if l_normal_pp_date is null then
5344 open c_pps_next_month(
5345 p_end_date => add_months(
5346 trunc(l_rt_strt_dt,'mm'),1)-1,
5347 p_prtl_mo_eff_dt_det_cd => l_get_abr_info.prtl_mo_eff_dt_det_cd,
5348 p_payroll_id => l_payroll_id);
5349 loop
5350 fetch c_pps_next_month into l_start_date,l_end_date;
5351 if c_pps_next_month%notfound then
5352 close c_pps_next_month;
5353 if g_debug then
5354 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',34);
5355 end if;
5356 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
5357 fnd_message.set_token('PROC',l_proc);
5358 fnd_message.raise_error;
5359 end if;
5360 hr_elements.check_element_freq(
5361 p_payroll_id => l_payroll_id,
5362 p_bg_id => p_business_group_id,
5363 p_pay_action_id => to_number(null),
5364 p_date_earned => l_start_date,
5365 p_ele_type_id => l_element_type_id,
5366 p_skip_element => g_skip_element
5367 );
5368 exit when g_skip_element='N';
5369 end loop;
5370 close c_pps_next_month;
5371 l_normal_pp_date:=l_start_date;
5372 end if;
5373 elsif l_normal_pp_date is null then
5374 if nvl(l_first_pp_adjustment,0) <> 0 then
5375 --
5376 l_special_amt:=l_per_pay_amt + l_first_pp_adjustment;
5377 --
5378 -- get first pp
5379 --
5380 l_special_pp_date := l_rt_strt_dt;
5381 --
5382 --
5383 -- BEGIN OF FIX FOR WWBUG 1402696
5384 --
5385 /*
5386 loop
5387 fetch c_first_pp_after_start into
5388 l_special_pp_date,
5389 l_dummy_date;
5390 exit when c_first_pp_after_start%notfound;
5391 hr_elements.check_element_freq(
5392 p_payroll_id =>l_payroll_id,
5393 p_bg_id =>p_business_group_id,
5394 p_pay_action_id =>to_number(null),
5395 p_date_earned =>l_normal_pp_date,
5396 p_ele_type_id =>l_element_type_id,
5397 p_skip_element =>g_skip_element
5398 );
5399 exit when g_skip_element='N';
5400 end loop;
5401 --
5402 */
5403 --
5404 -- END OF FIX FOR WWBUG 1402696
5405 --
5406 -- get second pp to start normal amounts
5407 --
5408 open c_first_pp_after_start(l_payroll_id
5409 ,l_rt_strt_dt);
5410 loop
5411 fetch c_first_pp_after_start into
5412 l_normal_pp_date,
5413 l_dummy_date;
5414 exit when c_first_pp_after_start%notfound;
5415 hr_elements.check_element_freq(
5416 p_payroll_id =>l_payroll_id,
5417 p_bg_id =>p_business_group_id,
5418 p_pay_action_id =>to_number(null),
5419 p_date_earned =>l_normal_pp_date,
5420 p_ele_type_id =>l_element_type_id,
5421 p_skip_element =>g_skip_element
5422 );
5423 exit when g_skip_element='N';
5424 end loop;
5425 close c_first_pp_after_start;
5426 else
5427 l_normal_pp_date:=l_rt_strt_dt;
5428 end if;
5429 end if;
5430 -- ELE :
5431 end if;
5432
5433 -- Don't make unnecessary changes: compare old value to new one
5434 -- if ee already exists, if not compare to impossible number
5435 --
5436 if l_element_entry_id is not null then
5437 if g_debug then
5438 hr_utility.set_location('Updating if the rate has changed ',90);
5439 end if;
5440 l_update_ee:=true;
5441 else
5442 if g_debug then
5443 hr_utility.set_location('inserting mode ',90);
5444 end if;
5445 l_update_ee:=false;
5446 l_curr_val:=hr_api.g_number;
5447 end if;
5448 --
5449 -- Do the actual creates/updates to element entry
5450 --
5451 if g_debug then
5452 hr_utility.set_location('Determined rate changes ',41);
5453 hr_utility.set_location(' pp date '|| l_zero_pp_date ,41);
5454 end if;
5455
5456 if l_calculate_only_mode then
5457 if g_debug then
5458 hr_utility.set_location(' calc mode true ' ,41);
5459 end if;
5460 end if ;
5461 --
5462 -- ELE : By pass if the ele_entry_val_cd <> PP , EPP or null.
5463 --
5464 if nvl(l_get_abr_info.ele_entry_val_cd, 'PP') = 'PP' or
5465 l_get_abr_info.ele_entry_val_cd = 'EPP' then
5466 --
5467 if l_zero_pp_date is not null
5468 and l_calculate_only_mode
5469 then
5470 --
5471 -- Set screen entry value out parameter to the special value
5472 --
5473 if g_debug then
5474 hr_utility.set_location('set secreen entry value ' ,42);
5475 end if;
5476
5477 p_eev_screen_entry_value := l_per_pay_amt;
5478 --
5479 elsif l_zero_pp_date is not null and
5480 l_zero_pp_date <= least(l_element_term_rule_date,l_element_link_end_date)
5481 then
5482 --
5483 if g_debug then
5484 hr_utility.set_location('Determined rate changes ',41);
5485 end if;
5486
5487 get_extra_ele_inputs
5488 (p_effective_date => l_zero_pp_date
5489 ,p_person_id => p_person_id
5490 ,p_business_group_id => p_business_group_id
5491 ,p_assignment_id => l_assignment_id
5492 ,p_element_link_id => l_element_link_id
5493 ,p_entry_type => 'E'
5494 ,p_input_value_id1 => null
5495 ,p_entry_value1 => 0
5496 ,p_element_entry_id => null
5497 ,p_acty_base_rt_id => p_acty_base_rt_id
5498 ,p_input_va_calc_rl => l_get_abr_info.input_va_calc_rl
5499 ,p_abs_ler => l_abs_ler
5500 ,p_organization_id => l_organization_id
5501 ,p_payroll_id => l_payroll_id
5502 ,p_pgm_id => g_result_rec.pgm_id
5503 ,p_pl_id => NVL(g_result_rec.pl_id,p_pl_id)
5504 ,p_pl_typ_id => g_result_rec.pl_typ_id
5505 ,p_opt_id => g_result_rec.opt_id
5506 ,p_ler_id => l_ler_id
5507 ,p_dml_typ => 'C'
5508 ,p_jurisdiction_code => l_jurisdiction_code
5509 ,p_ext_inpval_tab => g_ext_inpval_tab
5510 ,p_subpriority => l_subpriority
5511 );
5512
5513 --
5514 -- If free pay periods exist start/create ee
5515 --
5516 if l_update_ee then
5517 open get_current_value(l_element_entry_id,l_input_value_id,
5518 l_zero_pp_date);
5519 --
5520 if g_debug then
5521 hr_utility.set_location('l_element_entry_id '||l_element_entry_id,10);
5522 hr_utility.set_location('l_input_value_id '||l_input_value_id,10);
5523 hr_utility.set_location('l_zero_pp_date '||l_zero_pp_date,10);
5524 end if;
5525 --
5526 fetch get_current_value into
5527 l_curr_val,
5528 l_object_version_number,
5529 l_creator_id,
5530 l_creator_type,
5531 l_ee_effective_start_date,
5532 l_ee_effective_end_date;
5533 if get_current_value%notfound then
5534 close get_current_value;
5535 if g_debug then
5536 hr_utility.set_location('BEN_92101_NO_RATE ',90);
5537 end if;
5538 fnd_message.set_name('BEN', 'BEN_92101_NO_RATE');
5539 fnd_message.set_token('PROC',l_proc);
5540 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_element_entry_id));
5541 fnd_message.set_token('INPUT_VALUE_ID',to_char(l_input_value_id));
5542 fnd_message.set_token('EFFECTIVE_DATE',to_char(l_zero_pp_date));
5543 fnd_message.set_token('ABR_NAME',l_get_abr_info.name); -- Bug 2519349
5544 fnd_message.raise_error;
5545 end if;
5546 close get_current_value;
5547
5548 --
5549 if nvl(l_curr_val,0)<>0 then
5550 /*
5551 Before :-
5552 02-JAN-1994
5553 |-A----------------------------------------------------->
5554 ED
5555
5556 After :-
5557 02-JAN-1994 15-JUL-1994
5558 |-A----------------------------|-B---------------------->
5559 ED
5560 */
5561 l_upd_mode := get_ele_dt_upd_mode(l_zero_pp_date,
5562 l_element_entry_id);
5563 py_element_entry_api.update_element_entry
5564 (p_validate =>p_validate
5565 ,p_override_user_ent_chk =>'Y'
5566 ,p_datetrack_update_mode =>l_upd_mode
5567 ,p_effective_date =>l_zero_pp_date
5568 ,p_business_group_id =>p_business_group_id
5569 ,p_element_entry_id =>l_element_entry_id
5570 ,p_object_version_number =>l_object_version_number
5571 ,p_creator_type =>'F'
5572 ,p_creator_id =>p_enrt_rslt_id
5573 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
5574 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
5575 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
5576 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
5577 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
5578 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
5579 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
5580 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
5581 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
5582 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
5583 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
5584 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
5585 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
5586 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
5587 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
5588 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
5589 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
5590 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
5591 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
5592 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
5593 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
5594 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
5595 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
5596 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
5597 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
5598 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
5599 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
5600 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
5601 ,p_input_value_id15 =>l_input_value_id
5602 ,p_entry_value15 =>0
5603 ,p_effective_start_date =>l_effective_start_date
5604 ,p_effective_end_date =>l_effective_end_date
5605 ,p_update_warning =>l_update_warning
5606 );
5607 --
5608 -- write to the change event log
5609 --
5610 ben_ext_chlg.log_element_chg
5611 (p_action => l_upd_mode
5612 ,p_amt => 0
5613 ,p_old_amt => l_curr_val
5614 ,p_input_value_id => l_input_value_id
5615 ,p_element_entry_id => l_element_entry_id
5616 ,p_person_id => p_person_id
5617 ,p_business_group_id => p_business_group_id
5618 ,p_effective_date => l_zero_pp_date
5619 );
5620 --
5621 -- update curr val to prevent unnecessary updates
5622 --
5623 l_curr_val:=0;
5624 l_creator_id := p_enrt_rslt_id;
5625 l_creator_type := 'F';
5626 --
5627 elsif nvl(l_creator_id,-1) <> p_enrt_rslt_id or
5628 nvl(l_creator_type,'-1') <> 'F' then
5629
5630 l_upd_mode :=get_ele_dt_upd_mode(l_zero_pp_date,
5631 l_element_entry_id);
5632 py_element_entry_api.update_element_entry
5633 (p_validate =>p_validate
5634 ,p_datetrack_update_mode =>l_upd_mode
5635 ,p_effective_date =>l_zero_pp_date
5636 ,p_business_group_id =>p_business_group_id
5637 ,p_element_entry_id =>l_element_entry_id
5638 ,p_object_version_number =>l_object_version_number
5639 ,p_override_user_ent_chk => 'Y'
5640 ,p_creator_type =>'F'
5641 ,p_creator_id =>p_enrt_rslt_id
5642 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
5643 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
5644 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
5645 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
5646 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
5647 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
5648 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
5649 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
5650 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
5651 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
5652 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
5653 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
5654 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
5655 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
5656 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
5657 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
5658 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
5659 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
5660 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
5661 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
5662 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
5663 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
5664 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
5665 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
5666 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
5667 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
5668 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
5669 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
5670 ,p_effective_start_date =>l_effective_start_date
5671 ,p_effective_end_date =>l_effective_end_date
5672 ,p_update_warning =>l_update_warning
5673 );
5674
5675 l_creator_id := p_enrt_rslt_id;
5676 l_creator_type := 'F';
5677 end if;
5678 else
5679 --
5680 -- create ee since there were no zero pay periods
5681 --
5682 /*
5683 02-JAN-1994
5684 |-A----------------------------------------------------->
5685 ED
5686 */
5687 --
5688 if g_debug then
5689 hr_utility.set_location('calling create ' , 2293);
5690 end if;
5691 py_element_entry_api.create_element_entry
5692 (p_validate =>p_validate
5693 ,p_effective_date =>l_zero_pp_date
5694 ,p_business_group_id =>p_business_group_id
5695 ,p_assignment_id =>l_assignment_id
5696 ,p_element_link_id =>l_element_link_id
5697 ,p_entry_type =>'E'
5698 ,p_override_user_ent_chk =>'Y'
5699 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
5700 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
5701 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
5702 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
5703 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
5704 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
5705 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
5706 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
5707 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
5708 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
5709 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
5710 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
5711 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
5712 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
5713 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
5714 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
5715 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
5716 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
5717 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
5718 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
5719 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
5720 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
5721 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
5722 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
5723 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
5724 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
5725 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
5726 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
5727 ,p_input_value_id15 =>l_input_value_id
5728 ,p_entry_value15 =>0
5729 ,p_effective_start_date =>l_effective_start_date
5730 ,p_effective_end_date =>l_effective_end_date
5731 ,p_element_entry_id =>l_element_entry_id
5732 ,p_object_version_number =>l_object_version_number
5733 ,p_create_warning =>l_create_warning
5734 );
5735 --
5736 -- Tell next steps to update instead of create
5737 --
5738 l_update_ee:=true;
5739 --
5740 -- write to the change event log
5741 --
5742 ben_ext_chlg.log_element_chg
5743 (p_action => 'CREATE'
5744 ,p_amt => 0
5745 ,p_input_value_id => l_input_value_id
5746 ,p_element_entry_id => l_element_entry_id
5747 ,p_person_id => p_person_id
5748 ,p_business_group_id => p_business_group_id
5749 ,p_effective_date => l_zero_pp_date
5750 );
5751 --
5752 -- Change the creator type and id from the default
5753 --
5754 if g_debug then
5755 hr_utility.set_location('Change creator type and id ',50);
5756 end if;
5757 /*
5758 Before:-
5759 02-JAN-1994
5760 |-A----------------------------------------------------->
5761 ED
5762 After:-
5763 02-JAN-1994
5764 |-A----------------------------------------------------->
5765 ED
5766 */
5767 py_element_entry_api.update_element_entry
5768 (p_validate => p_validate
5769 ,p_datetrack_update_mode => hr_api.g_correction
5770 ,p_effective_date => l_zero_pp_date
5771 ,p_business_group_id => p_business_group_id
5772 ,p_element_entry_id => l_element_entry_id
5773 ,p_override_user_ent_chk =>'Y'
5774 ,p_object_version_number => l_object_version_number
5775 ,p_creator_type => 'F'
5776 ,p_creator_id => p_enrt_rslt_id
5777 ,p_effective_start_date => l_effective_start_date
5778 ,p_effective_end_date => l_effective_end_date
5779 ,p_update_warning => l_update_warning
5780 );
5781 --
5782 -- update curr val to prevent unnecessary updates
5783 --
5784 l_curr_val:=0;
5785 l_creator_id := p_enrt_rslt_id;
5786 l_creator_type := 'F';
5787 --
5788 end if;
5789 end if;
5790 --
5791 -- Done with zero value pay periods, now do special one
5792 --
5793 -- Check for calculate only mode
5794 --
5795 if g_debug then
5796 hr_utility.set_location('l_special_pp_date '||l_special_pp_date , 2293);
5797 end if;
5798 if l_special_pp_date is not null
5799 and l_calculate_only_mode
5800 then
5801 --
5802 -- Set screen entry value out parameter to the special value
5803 --
5804 p_eev_screen_entry_value := l_special_amt;
5805 --
5806 elsif l_special_pp_date is not null and
5807 l_special_pp_date <= least(l_element_term_rule_date,l_element_link_end_date)
5808 then
5809 --
5810 get_extra_ele_inputs
5811 (p_effective_date => l_special_pp_date
5812 ,p_person_id => p_person_id
5813 ,p_business_group_id => p_business_group_id
5814 ,p_assignment_id => l_assignment_id
5815 ,p_element_link_id => l_element_link_id
5816 ,p_entry_type => 'E'
5817 ,p_input_value_id1 => null
5818 ,p_entry_value1 => l_special_amt
5819 ,p_element_entry_id => null
5820 ,p_acty_base_rt_id => p_acty_base_rt_id
5821 ,p_input_va_calc_rl => l_get_abr_info.input_va_calc_rl
5822 ,p_abs_ler => l_abs_ler
5823 ,p_organization_id => l_organization_id
5824 ,p_payroll_id => l_payroll_id
5825 ,p_pgm_id => g_result_rec.pgm_id
5826 ,p_pl_id => NVL(g_result_rec.pl_id,p_pl_id)
5827 ,p_pl_typ_id => g_result_rec.pl_typ_id
5828 ,p_opt_id => g_result_rec.opt_id
5829 ,p_ler_id => l_ler_id
5830 ,p_dml_typ => 'C'
5831 ,p_jurisdiction_code => l_jurisdiction_code
5832 ,p_ext_inpval_tab => g_ext_inpval_tab
5833 ,p_subpriority => l_subpriority
5834 );
5835
5836 if l_update_ee then
5837 --
5838 open get_current_value(l_element_entry_id,l_input_value_id,
5839 l_special_pp_date);
5840 --
5841 fetch get_current_value into
5842 l_curr_val_char,
5843 l_object_version_number,
5844 l_creator_id,
5845 l_creator_type,
5846 l_ee_effective_start_date,
5847 l_ee_effective_end_date;
5848
5849 if get_current_value%notfound then
5850 close get_current_value;
5851 if g_debug then
5852 hr_utility.set_location('BEN_92101_NO_RATE ',92);
5853 end if;
5854 fnd_message.set_name('BEN', 'BEN_92101_NO_RATE');
5855 fnd_message.set_token('PROC',l_proc);
5856 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_element_entry_id));
5857 fnd_message.set_token('INPUT_VALUE_ID',to_char(l_input_value_id));
5858 fnd_message.set_token('EFFECTIVE_DATE',to_char(l_special_pp_date));
5859 fnd_message.set_token('ABR_NAME',l_get_abr_info.name); -- Bug 2519349
5860 fnd_message.raise_error;
5861 end if;
5862 close get_current_value;
5863
5864 if l_uom is null then
5865 l_uom := get_uom(p_business_group_id,p_effective_date);
5866 end if;
5867 l_curr_val := chkformat(l_curr_val_char, l_uom);
5868
5869 if g_debug then
5870 hr_utility.set_location('l_uom='|| l_uom ,432);
5871 hr_utility.set_location('aft frmt chg '||l_curr_val_char,432);
5872 hr_utility.set_location('converted no. value is '||l_curr_val,432);
5873 end if;
5874
5875 if nvl(l_curr_val,hr_api.g_number) <>l_special_amt then
5876 /*
5877 Before :-
5878 02-JAN-1994
5879 |-A----------------------------------------------------->
5880 ED
5881
5882 After :-
5883 02-JAN-1994 15-JUL-1994
5884 |-A----------------------------|-B---------------------->
5885 ED
5886 */
5887 --
5888 l_upd_mode := get_ele_dt_upd_mode(l_special_pp_date,
5889 l_element_entry_id);
5890 py_element_entry_api.update_element_entry
5891 (p_validate =>p_validate
5892 ,p_datetrack_update_mode =>l_upd_mode
5893 ,p_effective_date =>l_special_pp_date
5894 ,p_business_group_id =>p_business_group_id
5895 ,p_element_entry_id =>l_element_entry_id
5896 ,p_override_user_ent_chk =>'Y'
5897 ,p_object_version_number =>l_object_version_number
5898 ,p_creator_type =>'F'
5899 ,p_creator_id =>p_enrt_rslt_id
5900 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
5901 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
5902 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
5903 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
5904 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
5905 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
5906 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
5907 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
5908 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
5909 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
5910 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
5911 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
5912 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
5913 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
5914 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
5915 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
5916 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
5917 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
5918 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
5919 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
5920 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
5921 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
5922 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
5923 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
5924 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
5925 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
5926 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
5927 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
5928 ,p_input_value_id15 =>l_input_value_id
5929 ,p_entry_value15 =>l_special_amt
5930 ,p_effective_start_date =>l_effective_start_date
5931 ,p_effective_end_date =>l_effective_end_date
5932 ,p_update_warning =>l_update_warning
5933 );
5934 --
5935 -- write to the change event log
5936 --
5937 ben_ext_chlg.log_element_chg
5938 (p_action => l_upd_mode
5939 ,p_amt => l_special_amt
5940 ,p_old_amt => l_curr_val
5941 ,p_input_value_id => l_input_value_id
5942 ,p_element_entry_id => l_element_entry_id
5943 ,p_person_id => p_person_id
5944 ,p_business_group_id => p_business_group_id
5945 ,p_effective_date => l_special_pp_date
5946 );
5947 --
5948 -- update curr val to prevent unnecessary updates
5949 --
5950 l_curr_val:=l_special_amt;
5951 l_creator_id := p_enrt_rslt_id;
5952 l_creator_type := 'F';
5953 --
5954 elsif nvl(l_creator_id,-1) <> p_enrt_rslt_id or
5955 nvl(l_creator_type,'-1') <> 'F' then
5956
5957 l_upd_mode :=get_ele_dt_upd_mode(l_special_pp_date,
5958 l_element_entry_id);
5959 py_element_entry_api.update_element_entry
5960 (p_validate =>p_validate
5961 ,p_datetrack_update_mode =>l_upd_mode
5962 ,p_effective_date =>l_special_pp_date
5963 ,p_business_group_id =>p_business_group_id
5964 ,p_element_entry_id =>l_element_entry_id
5965 ,p_override_user_ent_chk =>'Y'
5966 ,p_object_version_number =>l_object_version_number
5967 ,p_creator_type =>'F'
5968 ,p_creator_id =>p_enrt_rslt_id
5969 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
5970 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
5971 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
5972 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
5973 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
5974 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
5975 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
5976 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
5977 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
5978 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
5979 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
5980 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
5981 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
5982 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
5983 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
5984 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
5985 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
5986 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
5987 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
5988 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
5989 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
5990 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
5991 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
5992 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
5993 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
5994 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
5995 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
5996 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
5997 ,p_effective_start_date =>l_effective_start_date
5998 ,p_effective_end_date =>l_effective_end_date
5999 ,p_update_warning =>l_update_warning
6000 );
6001 l_creator_id := p_enrt_rslt_id;
6002 l_creator_type := 'F';
6003 end if;
6004 --
6005 else
6006 --
6007 -- create ee since there were no zero pay periods
6008 --
6009 /*
6010 02-JAN-1994
6011 |-A----------------------------------------------------->
6012 ED
6013 */
6014 --
6015 if g_debug then
6016 hr_utility.set_location('l_special_amt='||l_special_amt,433);
6017 end if;
6018
6019 py_element_entry_api.create_element_entry
6020 (p_validate =>p_validate
6021 ,p_effective_date =>l_special_pp_date
6022 ,p_business_group_id =>p_business_group_id
6023 ,p_assignment_id =>l_assignment_id
6024 ,p_element_link_id =>l_element_link_id
6025 ,p_entry_type =>'E'
6026 ,p_override_user_ent_chk =>'Y'
6027 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6028 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6029 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6030 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6031 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6032 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6033 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6034 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6035 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6036 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6037 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6038 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6039 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6040 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6041 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6042 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6043 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6044 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6045 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6046 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6047 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6048 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6049 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6050 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6051 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6052 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6053 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6054 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6055 ,p_input_value_id15 =>l_input_value_id
6056 ,p_entry_value15 =>l_special_amt
6057 ,p_effective_start_date =>l_effective_start_date
6058 ,p_effective_end_date =>l_effective_end_date
6059 ,p_element_entry_id =>l_element_entry_id
6060 ,p_object_version_number =>l_object_version_number
6061 ,p_create_warning =>l_create_warning
6062 );
6063 --
6064 -- Tell next steps to update instead of create
6065 --
6066 l_update_ee:=true;
6067 --
6068 -- write to the change event log
6069 --
6070 ben_ext_chlg.log_element_chg
6071 (p_action => 'CREATE'
6072 ,p_amt => l_special_amt
6073 ,p_input_value_id => l_input_value_id
6074 ,p_element_entry_id => l_element_entry_id
6075 ,p_person_id => p_person_id
6076 ,p_business_group_id => p_business_group_id
6077 ,p_effective_date => l_special_pp_date
6078 );
6079 --
6080 -- Change the creator type and id from the default
6081 --
6082 if g_debug then
6083 hr_utility.set_location('Change creator type and id ',50);
6084 end if;
6085 /*
6086 Before:-
6087 02-JAN-1994
6088 |-A----------------------------------------------------->
6089 ED
6090 After:-
6091 02-JAN-1994
6092 |-A----------------------------------------------------->
6093 ED
6094 */
6095 py_element_entry_api.update_element_entry
6096 (p_validate => p_validate
6097 ,p_datetrack_update_mode => hr_api.g_correction
6098 ,p_effective_date => l_special_pp_date
6099 ,p_business_group_id => p_business_group_id
6100 ,p_element_entry_id => l_element_entry_id
6101 ,p_override_user_ent_chk =>'Y'
6102 ,p_object_version_number => l_object_version_number
6103 ,p_creator_type => 'F'
6104 ,p_creator_id => p_enrt_rslt_id
6105 ,p_effective_start_date => l_effective_start_date
6106 ,p_effective_end_date => l_effective_end_date
6107 ,p_update_warning => l_update_warning
6108 );
6109 --
6110 -- update curr val to prevent unnecessary updates
6111 --
6112 l_curr_val:=l_special_amt;
6113 l_creator_id := p_enrt_rslt_id;
6114 l_creator_type := 'F';
6115 --
6116 end if;
6117 --
6118 end if;
6119 -- ELE :
6120 end if;
6121 --
6122 -- Get entry value id.
6123 --
6124 if g_debug then
6125 hr_utility.set_location('not p_calculate_only_mode ' ,41);
6126 hr_utility.set_location('normal pp date '|| l_normal_pp_date ,41);
6127 end if;
6128 --
6129 -- Done with special value pay period, now do normal one
6130 --
6131 -- ELE : By pass if the ele_entry_val_cd <> PP , EPP or null.
6132 --
6133 if nvl(l_get_abr_info.ele_entry_val_cd, 'PP') not in ('PP', 'EPP') then
6134 --
6135 l_normal_pp_date := l_rt_strt_dt;
6136 l_zero_pp_date := null;
6137 l_special_pp_date := null;
6138 --
6139 if l_get_abr_info.ele_entry_val_cd = 'DFND' then
6140 --
6141 l_per_pay_amt := p_rt;
6142 --
6143 elsif l_get_abr_info.ele_entry_val_cd = 'CMCD' then
6144 --
6145 l_per_pay_amt := p_cmncd_rt;
6146 --
6147 elsif l_get_abr_info.ele_entry_val_cd = 'PYR' then
6148 --
6149 l_per_pay_amt := p_ann_rt;
6150 --
6151 end if;
6152 end if;
6153 --
6154 if l_abs_ler then
6155 l_input_value_id1 := l_input_value_id;
6156 else
6157 l_input_value_id1 := null;
6158 end if;
6159 --
6160 get_extra_ele_inputs
6161 (p_effective_date => l_normal_pp_date
6162 ,p_person_id => p_person_id
6163 ,p_business_group_id => p_business_group_id
6164 ,p_assignment_id => l_assignment_id
6165 ,p_element_link_id => l_element_link_id
6166 ,p_entry_type => 'E'
6167 ,p_input_value_id1 => l_input_value_id1
6168 ,p_entry_value1 => l_per_pay_amt
6169 ,p_element_entry_id => null
6170 ,p_acty_base_rt_id => p_acty_base_rt_id
6171 ,p_input_va_calc_rl => l_get_abr_info.input_va_calc_rl
6172 ,p_abs_ler => l_abs_ler
6173 ,p_organization_id => l_organization_id
6174 ,p_payroll_id => l_payroll_id
6175 ,p_pgm_id => g_result_rec.pgm_id
6176 ,p_pl_id => NVL(g_result_rec.pl_id,p_pl_id)
6177 ,p_pl_typ_id => g_result_rec.pl_typ_id
6178 ,p_opt_id => g_result_rec.opt_id
6179 ,p_ler_id => l_ler_id
6180 ,p_dml_typ => 'C'
6181 ,p_jurisdiction_code => l_jurisdiction_code
6182 ,p_ext_inpval_tab => g_ext_inpval_tab
6183 ,p_subpriority => l_subpriority
6184 );
6185
6186 if g_debug then
6187 hr_utility.set_location( 'ext inp count '|| g_ext_inpval_tab.count , 30);
6188 end if;
6189
6190 --
6191 -- Check for calculate only mode
6192 --
6193 if not l_calculate_only_mode then
6194 --
6195 --Bug 13526198 start
6196 if l_special_pp_date is not null then
6197 hr_entry.get_eligibility_period (l_assignment_id,
6198 l_element_link_id,
6199 trunc(l_special_pp_date),
6200 l_out_date_not_required_1,
6201 l_asg_max_eligibility_date);
6202 end if;
6203 -- Bug 13526198 end
6204
6205 hr_utility.set_location( 'l_asg_max_eligibility_date '|| l_asg_max_eligibility_date , 30);
6206 hr_utility.set_location( 'l_effective_end_date '|| l_effective_end_date , 30);
6207 --
6208 if l_normal_pp_date is not null and
6209 l_normal_pp_date <= least(l_element_term_rule_date,l_element_link_end_date)
6210 --Bug 13526198 start
6211 and
6212 ((l_special_pp_date is null) or ((l_special_pp_date is not null) and not
6213 ((l_asg_max_eligibility_date < l_normal_pp_date
6214 and l_asg_max_eligibility_date = l_effective_end_date
6215 and l_normal_pp_date = l_asg_max_eligibility_date + 1))))
6216 --Bug 13526198 end
6217 then
6218 if l_update_ee then
6219 l_skip := true; -- Bug 13526198
6220 open get_current_value(l_element_entry_id,
6221 l_input_value_id,
6222 l_normal_pp_date);
6223 --
6224 fetch get_current_value into
6225 l_curr_val_char,
6226 l_object_version_number,
6227 l_creator_id,
6228 l_creator_type,
6229 l_ee_effective_start_date,
6230 l_ee_effective_end_date;
6231
6232 if g_debug then
6233 hr_utility.set_location('fetched all values' ,432);
6234 end if;
6235
6236 if get_current_value%notfound then
6237 close get_current_value;
6238 if g_debug then
6239 hr_utility.set_location('BEN_92101_NO_RATE ',94);
6240 end if;
6241 fnd_message.set_name('BEN', 'BEN_92101_NO_RATE');
6242 fnd_message.set_token('PROC',l_proc);
6243 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_element_entry_id));
6244 fnd_message.set_token('INPUT_VALUE_ID',to_char(l_input_value_id));
6245 fnd_message.set_token('EFFECTIVE_DATE',to_char(l_normal_pp_date));
6246 fnd_message.set_token('ABR_NAME',l_get_abr_info.name); -- Bug 2519349
6247 fnd_message.raise_error;
6248 end if;
6249 close get_current_value;
6250 --
6251 if l_uom is null then
6252 l_uom := get_uom(p_business_group_id,p_effective_date);
6253 end if;
6254 l_curr_val := chkformat(l_curr_val_char, l_uom);
6255
6256 if g_debug then
6257 hr_utility.set_location('l_uom='|| l_uom ,432);
6258 hr_utility.set_location('aft frmt chg '||l_curr_val_char,432);
6259 hr_utility.set_location('converted no. value is '||l_curr_val,432);
6260 end if;
6261
6262 if nvl(l_curr_val,hr_api.g_number) <>l_per_pay_amt then
6263 /*
6264 Before :-
6265 02-JAN-1994
6266 |-A----------------------------------------------------->
6267 ED
6268
6269 After :-
6270 02-JAN-1994 15-JUL-1994
6271 |-A----------------------------|-B---------------------->
6272 ED
6273 */
6274 --
6275 l_upd_mode :=get_ele_dt_upd_mode(l_normal_pp_date,
6276 l_element_entry_id);
6277 --
6278 py_element_entry_api.update_element_entry
6279 (p_validate =>p_validate
6280 ,p_datetrack_update_mode =>l_upd_mode
6281 ,p_effective_date =>l_normal_pp_date
6282 ,p_business_group_id =>p_business_group_id
6283 ,p_element_entry_id =>l_element_entry_id
6284 ,p_override_user_ent_chk =>'Y'
6285 ,p_object_version_number =>l_object_version_number
6286 ,p_creator_type =>'F'
6287 ,p_creator_id =>p_enrt_rslt_id
6288 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6289 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6290 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6291 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6292 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6293 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6294 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6295 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6296 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6297 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6298 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6299 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6300 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6301 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6302 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6303 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6304 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6305 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6306 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6307 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6308 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6309 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6310 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6311 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6312 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6313 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6314 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6315 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6316 ,p_input_value_id15 =>l_input_value_id
6317 ,p_entry_value15 =>l_per_pay_amt
6318 ,p_effective_start_date =>l_effective_start_date
6319 ,p_effective_end_date =>l_effective_end_date
6320 ,p_update_warning =>l_update_warning
6321 );
6322 --
6323 -- write to the change event log
6324 --
6325 ben_ext_chlg.log_element_chg
6326 (p_action => l_upd_mode
6327 ,p_amt => l_per_pay_amt
6328 ,p_old_amt => l_curr_val
6329 ,p_input_value_id => l_input_value_id
6330 ,p_element_entry_id => l_element_entry_id
6331 ,p_person_id => p_person_id
6332 ,p_business_group_id => p_business_group_id
6333 ,p_effective_date => l_normal_pp_date
6334 );
6335 --
6336 l_ee_effective_end_date := l_effective_end_date;
6337 l_creator_id := p_enrt_rslt_id;
6338 l_creator_type := 'F';
6339
6340 elsif nvl(l_creator_id,-1) <> p_enrt_rslt_id or
6341 nvl(l_creator_type,'-1') <> 'F' then
6342
6343 l_upd_mode :=get_ele_dt_upd_mode(l_normal_pp_date,
6344 l_element_entry_id);
6345 py_element_entry_api.update_element_entry
6346 (p_validate =>p_validate
6347 ,p_datetrack_update_mode =>l_upd_mode
6348 ,p_effective_date =>l_normal_pp_date
6349 ,p_business_group_id =>p_business_group_id
6350 ,p_element_entry_id =>l_element_entry_id
6351 ,p_override_user_ent_chk =>'Y'
6352 ,p_object_version_number =>l_object_version_number
6353 ,p_creator_type =>'F'
6354 ,p_creator_id =>p_enrt_rslt_id
6355 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6356 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6357 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6358 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6359 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6360 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6361 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6362 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6363 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6364 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6365 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6366 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6367 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6368 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6369 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6370 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6371 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6372 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6373 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6374 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6375 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6376 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6377 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6378 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6379 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6380 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6381 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6382 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6383 ,p_effective_start_date =>l_effective_start_date
6384 ,p_effective_end_date =>l_effective_end_date
6385 ,p_update_warning =>l_update_warning
6386 );
6387 l_creator_id := p_enrt_rslt_id;
6388 l_creator_type := 'F';
6389 end if;
6390 --
6391
6392 else
6393 --
6394 -- create ee since there were no zero pay periods
6395 --
6396 /*
6397 02-JAN-1994
6398 |-A----------------------------------------------------->
6399 ED
6400 */
6401 if g_debug then
6402 hr_utility.set_location( 'entering', 30.2);
6403 hr_utility.set_location( 'amout '|| l_amt , 30.2);
6404 end if;
6405
6406 /* Bug 12382133 : If Non recurring element exists in the payroll period while creating the element entry,
6407 delete the old element entry, set the element_entry_value_id on rate record to NULL and create a
6408 new element entry for the payroll period. Added code in the else part c_entry_exists%FOUND */
6409 open c_entry_exists(l_normal_pp_date, l_element_link_id, l_assignment_id,p_input_value_id);
6410 fetch c_entry_exists into l_entry_exists;
6411 if c_entry_exists%NOTFOUND then
6412
6413 py_element_entry_api.create_element_entry
6414 (p_validate =>p_validate
6415 ,p_effective_date =>l_normal_pp_date
6416 ,p_business_group_id =>p_business_group_id
6417 ,p_assignment_id =>l_assignment_id
6418 ,p_element_link_id =>l_element_link_id
6419 ,p_entry_type =>'E'
6420 ,p_override_user_ent_chk =>'Y'
6421 ,p_subpriority =>l_subpriority
6422 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6423 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6424 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6425 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6426 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6427 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6428 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6429 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6430 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6431 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6432 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6433 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6434 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6435 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6436 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6437 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6438 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6439 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6440 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6441 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6442 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6443 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6444 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6445 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6446 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6447 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6448 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6449 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6450 ,p_input_value_id15 =>l_input_value_id
6451 ,p_entry_value15 =>l_per_pay_amt
6452 ,p_effective_start_date =>l_effective_start_date
6453 ,p_effective_end_date =>l_effective_end_date
6454 ,p_element_entry_id =>l_element_entry_id
6455 ,p_object_version_number =>l_object_version_number
6456 ,p_create_warning =>l_create_warning
6457 );
6458 --
6459 hr_utility.set_location('l_effective_end_date after pay.create_element_entry '||l_effective_end_date,44333);
6460 --
6461 --
6462 -- Tell next steps to update instead of create
6463 --
6464
6465 l_update_ee:=true;
6466 --
6467 -- write to the change event log
6468 --
6469 ben_ext_chlg.log_element_chg
6470 (p_action => 'CREATE'
6471 ,p_amt => l_per_pay_amt
6472 ,p_input_value_id => l_input_value_id
6473 ,p_element_entry_id => l_element_entry_id
6474 ,p_person_id => p_person_id
6475 ,p_business_group_id => p_business_group_id
6476 ,p_effective_date => l_normal_pp_date
6477 );
6478 --
6479 -- Change the creator type and id from the default
6480 --
6481 if g_debug then
6482 hr_utility.set_location('Change creator type and id ',50);
6483 end if;
6484 /*
6485 Before:-
6486 02-JAN-1994
6487 |-A----------------------------------------------------->
6488 ED
6489 After:-
6490 02-JAN-1994
6491 |-A----------------------------------------------------->
6492 ED
6493 */
6494 py_element_entry_api.update_element_entry
6495 (p_validate =>p_validate
6496 ,p_datetrack_update_mode =>hr_api.g_correction
6497 ,p_effective_date =>l_normal_pp_date
6498 ,p_business_group_id =>p_business_group_id
6499 ,p_element_entry_id =>l_element_entry_id
6500 ,p_override_user_ent_chk =>'Y'
6501 ,p_object_version_number =>l_object_version_number
6502 ,p_creator_type =>'F'
6503 ,p_creator_id => p_enrt_rslt_id
6504 ,p_effective_start_date =>l_effective_start_date
6505 ,p_effective_end_date =>l_effective_end_date
6506 ,p_update_warning =>l_update_warning
6507 );
6508 --
6509 l_ee_effective_end_date := l_effective_end_date;
6510 l_creator_id := p_enrt_rslt_id;
6511 l_creator_type := 'F';
6512
6513 hr_utility.set_location('l_ee_effective_end_date '||l_ee_effective_end_date,44333);
6514 hr_utility.set_location('l_creator_id '||l_creator_id,44333);
6515 hr_utility.set_location('l_creator_type '||l_creator_type,44333);
6516 else
6517 hr_utility.set_location('l_entry_exists.CREATOR_ID '||l_entry_exists.CREATOR_ID,44333);
6518 hr_utility.set_location('p_enrt_rslt_id '||p_enrt_rslt_id,44333);
6519 if l_entry_exists.CREATOR_ID <> p_enrt_rslt_id then
6520
6521 hr_utility.set_location('Clearing the prv ele input values ',44333);
6522
6523 for j in c_get_prv_id(p_element_type_id,
6524 p_input_value_id,
6525 l_normal_pp_date,
6526 l_entry_exists.ELEMENT_ENTRY_ID) loop
6527 hr_utility.set_location(' j.prtt_rt_val_id '|| j.prtt_rt_val_id,44333);
6528 ben_prtt_rt_val_api.update_prtt_rt_val(
6529 p_validate => p_validate
6530 ,p_prtt_rt_val_id => j.prtt_rt_val_id
6531 ,p_element_entry_value_id => NULL
6532 ,p_object_version_number => j.object_version_number
6533 ,p_effective_date=> j.RT_STRT_DT
6534 ,p_business_group_id => p_business_group_id);
6535 end loop;
6536
6537 hr_utility.set_location('deleting the element ',44333);
6538 py_element_entry_api.delete_element_entry
6539 (p_validate => p_validate
6540 ,p_datetrack_delete_mode => hr_api.g_zap
6541 ,p_effective_date => l_entry_exists.effective_start_date
6542 ,p_element_entry_id => l_entry_exists.element_entry_id
6543 ,p_object_version_number => l_entry_exists.object_version_number
6544 ,p_effective_start_date => l_effective_start_date
6545 ,p_effective_end_date => l_effective_end_date
6546 ,p_delete_warning => l_delete_warning
6547 );
6548 --
6549 -- write to the change event log
6550 --
6551 /*hr_utility.set_location('Writing to log ',44333);
6552 ben_ext_chlg.log_element_chg
6553 (p_action => hr_api.g_delete
6554 ,p_old_amt => l_per_pay_amt
6555 ,p_input_value_id => l_input_value_id
6556 ,p_element_entry_id => l_element_entry_id
6557 ,p_person_id => p_person_id
6558 ,p_business_group_id => p_business_group_id
6559 ,p_effective_date => l_normal_pp_end_date
6560 );*/
6561
6562 hr_utility.set_location('creaying the element ',44333);
6563 py_element_entry_api.create_element_entry
6564 (p_validate =>p_validate
6565 ,p_effective_date =>l_normal_pp_date
6566 ,p_business_group_id =>p_business_group_id
6567 ,p_assignment_id =>l_assignment_id
6568 ,p_element_link_id =>l_element_link_id
6569 ,p_entry_type =>'E'
6570 ,p_override_user_ent_chk =>'Y'
6571 ,p_subpriority =>l_subpriority
6572 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6573 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6574 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6575 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6576 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6577 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6578 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6579 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6580 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6581 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6582 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6583 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6584 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6585 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6586 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6587 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6588 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6589 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6590 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6591 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6592 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6593 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6594 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6595 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6596 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6597 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6598 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6599 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6600 ,p_input_value_id15 =>l_input_value_id
6601 ,p_entry_value15 =>l_per_pay_amt
6602 ,p_effective_start_date =>l_effective_start_date
6603 ,p_effective_end_date =>l_effective_end_date
6604 ,p_element_entry_id =>l_element_entry_id
6605 ,p_object_version_number =>l_object_version_number
6606 ,p_create_warning =>l_create_warning
6607 );
6608
6609 ben_ext_chlg.log_element_chg
6610 (p_action => 'CREATE'
6611 ,p_amt => l_per_pay_amt
6612 ,p_input_value_id => l_input_value_id
6613 ,p_element_entry_id => l_element_entry_id
6614 ,p_person_id => p_person_id
6615 ,p_business_group_id => p_business_group_id
6616 ,p_effective_date => l_normal_pp_date
6617 );
6618
6619 py_element_entry_api.update_element_entry
6620 (p_validate =>p_validate
6621 ,p_datetrack_update_mode =>hr_api.g_correction
6622 ,p_effective_date =>l_normal_pp_date
6623 ,p_business_group_id =>p_business_group_id
6624 ,p_element_entry_id =>l_element_entry_id
6625 ,p_override_user_ent_chk =>'Y'
6626 ,p_object_version_number =>l_object_version_number
6627 ,p_creator_type =>'F'
6628 ,p_creator_id => p_enrt_rslt_id
6629 ,p_effective_start_date =>l_effective_start_date
6630 ,p_effective_end_date =>l_effective_end_date
6631 ,p_update_warning =>l_update_warning
6632 );
6633 --
6634 l_ee_effective_end_date := l_effective_end_date;
6635 l_creator_id := p_enrt_rslt_id;
6636 l_creator_type := 'F';
6637
6638 hr_utility.set_location('l_ee_effective_end_date '||l_ee_effective_end_date,44333);
6639 hr_utility.set_location('l_creator_id '||l_creator_id,44333);
6640 hr_utility.set_location('l_creator_type '||l_creator_type,44333);
6641 else
6642 return;
6643 end if;
6644 end if;--sang
6645
6646 end if;
6647 --
6648 end if;
6649
6650 if l_normal_pp_date is not null then
6651 --
6652 hr_utility.set_location('if l_normal_pp_date is not null then ',44333);
6653 --
6654 --------------------Bug 13526198 start
6655 if not l_skip then
6656 l_ee_effective_end_date := l_effective_end_date;
6657 end if;
6658 ---------------------Bug 13526198 end
6659 if l_ee_effective_end_date < l_element_term_rule_date then
6660 --
6661 hr_utility.set_location('if l_ee_effective_end_date < l_element_term_rule_date then ',44333);
6662 --
6663
6664 open c_future_ee(l_element_entry_id,
6665 l_element_type_id,
6666 l_input_value_id,
6667 l_assignment_id,
6668 l_normal_pp_date);
6669 loop
6670 fetch c_future_ee into l_future_ee_rec;
6671
6672 if c_future_ee%notfound then
6673 --
6674 hr_utility.set_location('if c_future_ee%notfound then ',44333);
6675 --
6676 exit;
6677 end if;
6678
6679 l_element_link_id := l_future_ee_rec.element_link_id;
6680 l_effective_start_date := l_future_ee_rec.effective_start_date;
6681 l_effective_end_date := l_future_ee_rec.effective_end_date;
6682
6683 l_curr_val :=chkformat(l_future_ee_rec.screen_entry_value,l_uom);
6684
6685 if g_debug then
6686 hr_utility.set_location('future ee='||l_future_ee_rec.element_entry_id ,433);
6687 hr_utility.set_location('l_curr_val_char='||l_future_ee_rec.screen_entry_value ,433);
6688 hr_utility.set_location('l_curr_val='||l_curr_val ,433);
6689 hr_utility.set_location('l_per_pay_amt='||l_per_pay_amt ,433);
6690 end if;
6691
6692 if nvl(l_per_pay_amt,0) <> nvl(l_curr_val,0) then
6693 --
6694 hr_utility.set_location('if nvl(l_per_pay_amt,0) <> nvl(l_curr_val,0) then',44333);
6695 --
6696 py_element_entry_api.update_element_entry
6697 (p_validate =>p_validate
6698 ,p_datetrack_update_mode =>hr_api.g_correction
6699 ,p_effective_date =>l_future_ee_rec.effective_start_date
6700 ,p_business_group_id =>p_business_group_id
6701 ,p_element_entry_id =>l_future_ee_rec.element_entry_id
6702 ,p_override_user_ent_chk =>'Y'
6703 ,p_object_version_number =>l_future_ee_rec.object_version_number
6704 ,p_input_value_id1 =>l_input_value_id
6705 ,p_entry_value1 =>l_per_pay_amt
6706 ,p_effective_start_date =>l_effective_start_date
6707 ,p_effective_end_date =>l_effective_end_date
6708 ,p_update_warning =>l_update_warning
6709 );
6710 end if;
6711 end loop;
6712 close c_future_ee;
6713 end if;
6714
6715 loop
6716 --
6717 -- created till max possible date. exit now
6718 --
6719 if l_effective_end_date=l_element_term_rule_date then
6720 --
6721 hr_utility.set_location('if l_effective_end_date=l_element_term_rule_date then',44333);
6722 --
6723 exit;
6724 end if;
6725
6726 l_effective_date := l_effective_end_date + 1;
6727 --
6728 if g_debug then
6729 hr_utility.set_location('l_effective_date '||l_effective_date,44333);
6730 hr_utility.set_location('l_effective_end_date '||l_effective_end_date,44333);
6731 end if;
6732 --
6733 -- get the next eligible element link for the assignment and elt
6734 --
6735 -- added here for bug 6450363
6736 if l_abs_ler then -- bug # 7383673, 7390204
6737 -- bug # 7383673, 7390204 -- restricting bug 6450363 fix only for absences
6738 l_old_asgn_id := l_assignment_id;
6739 hr_utility.set_location('l_old_asgn_id '||l_old_asgn_id,44333);
6740 --
6741 get_abr_assignment (p_person_id => p_person_id
6742 ,p_effective_date => l_effective_date
6743 ,p_acty_base_rt_id => l_prv_rec.acty_base_rt_id
6744 ,p_organization_id => l_dummy_number
6745 ,p_payroll_id => l_payroll_id
6746 ,p_assignment_id => l_assignment_id);
6747 --
6748 hr_utility.set_location('l_assignment_id'||l_assignment_id,44333);
6749 if l_old_asgn_id = l_assignment_id then
6750 --
6751 hr_utility.set_location('if l_old_asgn_id = l_assignment_id then',44333);
6752 --
6753 get_link(p_assignment_id => l_assignment_id
6754 ,p_element_type_id => l_element_type_id
6755 ,p_business_group_id => p_business_group_id
6756 ,p_input_value_id => l_input_value_id
6757 ,p_effective_date => l_effective_date
6758 ,p_element_link_id => l_new_element_link_id
6759 );
6760 else
6761 --
6762 hr_utility.set_location('if l_old_asgn_id = l_assignment_id then',44333);
6763 --
6764 l_assignment_id := l_old_asgn_id;
6765 --
6766 get_link(p_assignment_id => l_assignment_id
6767 ,p_element_type_id => l_element_type_id
6768 ,p_business_group_id => p_business_group_id
6769 ,p_input_value_id => l_input_value_id
6770 ,p_effective_date => l_effective_end_date
6771 ,p_element_link_id => l_new_element_link_id
6772 );
6773 end if;
6774 --added till here for bug 6450363
6775 else
6776 get_link(p_assignment_id => l_assignment_id
6777 ,p_element_type_id => l_element_type_id
6778 ,p_business_group_id => p_business_group_id
6779 ,p_input_value_id => l_input_value_id
6780 ,p_effective_date => l_effective_date
6781 ,p_element_link_id => l_new_element_link_id
6782 );
6783
6784 end if;
6785
6786 if g_debug then
6787 hr_utility.set_location('new_elk='||l_new_element_link_id,50);
6788 end if;
6789
6790 if l_new_element_link_id = l_element_link_id or
6791 l_new_element_link_id is null then
6792 --
6793 -- No new link found. Get out of the loop
6794 --
6795 exit;
6796 end if;
6797
6798 l_element_link_id := l_new_element_link_id;
6799
6800 if nvl(l_inpval_tab.count,0) = 0 then
6801 get_inpval_tab(l_element_entry_id,
6802 l_effective_start_date,
6803 l_inpval_tab);
6804 end if;
6805 --
6806 hr_utility.set_location('again before pay.create_element',44333);
6807 --
6808 if l_skip then ---- Bug 13526198
6809 py_element_entry_api.create_element_entry
6810 (p_validate =>p_validate
6811 ,p_effective_date =>l_effective_date
6812 ,p_business_group_id =>p_business_group_id
6813 ,p_assignment_id =>l_assignment_id
6814 ,p_element_link_id =>l_element_link_id
6815 ,p_entry_type =>'E'
6816 ,p_override_user_ent_chk =>'Y'
6817 ,p_subpriority =>l_subpriority
6818 ,p_input_value_id1 =>l_inpval_tab(1).input_value_id
6819 ,p_entry_value1 =>l_inpval_tab(1).value
6820 ,p_input_value_id2 =>l_inpval_tab(2).input_value_id
6821 ,p_entry_value2 =>l_inpval_tab(2).value
6822 ,p_input_value_id3 =>l_inpval_tab(3).input_value_id
6823 ,p_entry_value3 =>l_inpval_tab(3).value
6824 ,p_input_value_id4 =>l_inpval_tab(4).input_value_id
6825 ,p_entry_value4 =>l_inpval_tab(4).value
6826 ,p_input_value_id5 =>l_inpval_tab(5).input_value_id
6827 ,p_entry_value5 =>l_inpval_tab(5).value
6828 ,p_input_value_id6 =>l_inpval_tab(6).input_value_id
6829 ,p_entry_value6 =>l_inpval_tab(6).value
6830 ,p_input_value_id7 =>l_inpval_tab(7).input_value_id
6831 ,p_entry_value7 =>l_inpval_tab(7).value
6832 ,p_input_value_id8 =>l_inpval_tab(8).input_value_id
6833 ,p_entry_value8 =>l_inpval_tab(8).value
6834 ,p_input_value_id9 =>l_inpval_tab(9).input_value_id
6835 ,p_entry_value9 =>l_inpval_tab(9).value
6836 ,p_input_value_id10 =>l_inpval_tab(10).input_value_id
6837 ,p_entry_value10 =>l_inpval_tab(10).value
6838 ,p_input_value_id11 =>l_inpval_tab(11).input_value_id
6839 ,p_entry_value11 =>l_inpval_tab(11).value
6840 ,p_input_value_id12 =>l_inpval_tab(12).input_value_id
6841 ,p_entry_value12 =>l_inpval_tab(12).value
6842 ,p_input_value_id13 =>l_inpval_tab(13).input_value_id
6843 ,p_entry_value13 =>l_inpval_tab(13).value
6844 ,p_input_value_id14 =>l_inpval_tab(14).input_value_id
6845 ,p_entry_value14 =>l_inpval_tab(14).value
6846 ,p_input_value_id15 =>l_inpval_tab(15).input_value_id
6847 ,p_entry_value15 =>l_inpval_tab(15).value
6848 ,p_effective_start_date =>l_effective_start_date
6849 ,p_effective_end_date =>l_effective_end_date
6850 ,p_element_entry_id =>l_element_entry_id
6851 ,p_object_version_number =>l_object_version_number
6852 ,p_create_warning =>l_create_warning
6853 );
6854 else
6855 --------------------------------------------Bug 13526198 start
6856 hr_utility.set_location('uxx2 l_per_pay_amt '||l_per_pay_amt,10);
6857 py_element_entry_api.create_element_entry
6858 (p_validate =>p_validate
6859 ,p_effective_date =>l_effective_date
6860 ,p_business_group_id =>p_business_group_id
6861 ,p_assignment_id =>l_assignment_id
6862 ,p_element_link_id =>l_element_link_id
6863 ,p_entry_type =>'E'
6864 ,p_override_user_ent_chk =>'Y'
6865 ,p_subpriority =>l_subpriority
6866 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
6867 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
6868 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
6869 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
6870 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
6871 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
6872 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
6873 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
6874 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
6875 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
6876 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
6877 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
6878 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
6879 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
6880 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
6881 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
6882 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
6883 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
6884 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
6885 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
6886 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
6887 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
6888 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
6889 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
6890 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
6891 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
6892 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
6893 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
6894 ,p_input_value_id15 =>l_input_value_id
6895 ,p_entry_value15 =>l_per_pay_amt
6896 ,p_effective_start_date =>l_effective_start_date
6897 ,p_effective_end_date =>l_effective_end_date
6898 ,p_element_entry_id =>l_element_entry_id
6899 ,p_object_version_number =>l_object_version_number
6900 ,p_create_warning =>l_create_warning
6901 );
6902 --------------------------------------------Bug 13526198 end
6903 end if;
6904 --
6905 --
6906 -- write to the change event log
6907 --
6908 ben_ext_chlg.log_element_chg
6909 (p_action => 'CREATE'
6910 ,p_amt => l_per_pay_amt
6911 ,p_input_value_id => l_input_value_id
6912 ,p_element_entry_id => l_element_entry_id
6913 ,p_person_id => p_person_id
6914 ,p_business_group_id => p_business_group_id
6915 ,p_effective_date => l_effective_date
6916 );
6917 --
6918 -- Change the creator type and id from the default
6919 --
6920 py_element_entry_api.update_element_entry
6921 (p_validate =>p_validate
6922 ,p_datetrack_update_mode =>hr_api.g_correction
6923 ,p_effective_date =>l_effective_date
6924 ,p_business_group_id =>p_business_group_id
6925 ,p_element_entry_id =>l_element_entry_id
6926 ,p_override_user_ent_chk =>'Y'
6927 ,p_object_version_number =>l_object_version_number
6928 ,p_creator_type =>'F'
6929 ,p_creator_id =>p_enrt_rslt_id
6930 ,p_effective_start_date =>l_effective_start_date
6931 ,p_effective_end_date =>l_effective_end_date
6932 ,p_update_warning =>l_update_warning
6933 );
6934
6935 end loop;
6936
6937 end if;
6938
6939 if l_effective_end_date <> hr_api.g_eot and
6940 l_recurring_entry then
6941
6942 if l_effective_end_date < l_element_term_rule_date then
6943 l_message_name := 'BEN_93454_NO_ELK_TILL_EOT';
6944 else
6945 l_message_name := 'BEN_93449_NO_ELE_TILL_EOT';
6946 end if;
6947 --
6948 ben_warnings.load_warning
6949 (p_application_short_name => 'BEN',
6950 p_message_name => l_message_name,
6951 p_parma => l_element_name,
6952 p_parmb => to_char(l_effective_end_date),
6953 p_person_id => p_person_id);
6954 --
6955 if fnd_global.conc_request_id not in ( 0,-1) then
6956 --
6957 fnd_message.set_name('BEN',l_message_name);
6958 fnd_message.set_token('PARMA',l_element_name);
6959 fnd_message.set_token('PARMB',to_char(l_effective_end_date));
6960 l_string := fnd_message.get;
6961 benutils.write(p_text => l_string);
6962 --
6963 end if;
6964 --
6965 end if;
6966 --
6967 -- get the fudged start date to use for the requery
6968 --
6969 if l_zero_pp_date is not null then
6970 l_rt_strt_dt:=l_zero_pp_date;
6971 elsif l_special_pp_date is not null then
6972 l_rt_strt_dt:=l_special_pp_date;
6973 elsif l_normal_pp_date is not null then
6974 l_rt_strt_dt:=l_normal_pp_date;
6975 end if;
6976 --
6977 if not l_recurring_entry then
6978 l_non_recurring_ee_id := l_element_entry_id;
6979 end if;
6980
6981 open get_element_entry(l_old_element_link_id
6982 ,l_assignment_id
6983 ,p_enrt_rslt_id
6984 ,l_input_value_id
6985 ,l_non_recurring_ee_id
6986 ,l_rt_strt_dt);
6987 fetch get_element_entry into
6988 l_element_entry_id,
6989 l_ee_effective_start_date,
6990 l_ee_effective_end_date,
6991 l_object_version_number,
6992 l_entry_value_id;
6993 if get_element_entry%notfound then
6994 --
6995 if g_debug then
6996 hr_utility.set_location('no entry created',140);
6997 end if;
6998 close get_element_entry;
6999 --
7000 if g_debug then
7001 hr_utility.set_location('BEN_92102_NO_ENTRY_CREATED',140);
7002 end if;
7003 fnd_message.set_name('BEN', 'BEN_92102_NO_ENTRY_CREATED');
7004 fnd_message.set_token('PROC',l_proc);
7005 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_old_element_link_id));
7006 fnd_message.set_token('INPUT_VALUE_ID',to_char(l_input_value_id));
7007 fnd_message.set_token('EFFECTIVE_DATE',to_char(l_rt_strt_dt));
7008 fnd_message.raise_error;
7009 --
7010 end if;
7011 close get_element_entry;
7012 --
7013 -- If it was a one time rate, i.e. not recurring end it
7014 --
7015 if g_debug then
7016 hr_utility.set_location ('normal_pp_end_date'||l_normal_pp_end_date,293.9);
7017 end if;
7018 if l_normal_pp_end_date is not null then
7019 --
7020 py_element_entry_api.delete_element_entry
7021 (p_validate => p_validate
7022 ,p_datetrack_delete_mode => hr_api.g_delete
7023 ,p_effective_date => l_normal_pp_end_date
7024 ,p_element_entry_id => l_element_entry_id
7025 ,p_object_version_number => l_object_version_number
7026 ,p_effective_start_date => l_effective_start_date
7027 ,p_effective_end_date => l_effective_end_date
7028 ,p_delete_warning => l_delete_warning
7029 );
7030 --
7031 -- write to the change event log
7032 --
7033 ben_ext_chlg.log_element_chg
7034 (p_action => hr_api.g_delete
7035 ,p_old_amt => l_per_pay_amt
7036 ,p_input_value_id => l_input_value_id
7037 ,p_element_entry_id => l_element_entry_id
7038 ,p_person_id => p_person_id
7039 ,p_business_group_id => p_business_group_id
7040 ,p_effective_date => l_normal_pp_end_date
7041 );
7042 --
7043 end if;
7044 --
7045 -- reset l_rt_strt_dt
7046 --
7047 l_rt_strt_dt := p_rt_start_date;
7048 --
7049 g_max_end_date := null;
7050 --
7051 --Bug 3151737 and 3063518 if there is no payroll for the assignment and if
7052 --it is not required we dont need to compute this.
7053 --
7054 if l_payroll_id is null and
7055 nvl(l_get_abr_info.ele_entry_val_cd, 'PP') not in ('PP', 'EPP') then
7056 --
7057 null;
7058 --
7059 else
7060 --
7061 if nvl(g_per_pay_rec.assignment_id,-1) <> l_assignment_id then
7062 --
7063 open c_payroll_was_ever_run
7064 (c_assignment_id => l_assignment_id
7065 );
7066 fetch c_payroll_was_ever_run into l_v2dummy;
7067 g_per_pay_rec.assignment_id := l_assignment_id;
7068 g_per_pay_rec.payroll_was_ever_run := c_payroll_was_ever_run%found;
7069 close c_payroll_was_ever_run;
7070 --
7071 end if;
7072 --
7073 if g_per_pay_rec.payroll_was_ever_run and
7074 g_per_pay_rec.end_date is null then
7075 --
7076 g_max_end_date :=
7077 get_max_end_dt (
7078 p_assignment_id => l_assignment_id,
7079 p_payroll_id => l_payroll_id,
7080 p_element_type_id => l_element_type_id,
7081 p_effective_date => l_rt_strt_dt);
7082 g_per_pay_rec.end_date := g_max_end_date;
7083 --
7084 elsif g_per_pay_rec.end_date is not null then
7085 g_max_end_date := g_per_pay_rec.end_date;
7086 end if;
7087 --
7088 end if;
7089 --
7090 --
7091 -- even if there are any run results the entry start date
7092 -- should be same as rate start date. Payroll retro process will take care
7093 --
7094 if g_max_end_date is not null and (g_max_end_date +1) > l_rt_strt_dt
7095 and not (l_abs_ler) then
7096 --
7097 if (g_msg_displayed <>1 )
7098 -- added for bug: 5607214
7099 OR fnd_global.conc_request_id not in ( 0,-1)
7100 then -- 2530582
7101 --
7102 -- Issue a warning to the user. These will display on the enrt forms.
7103 ben_warnings.load_warning
7104 (p_application_short_name => 'BEN',
7105 p_message_name => 'BEN_92455_STRT_RUN_RESULTS',
7106 p_parma => fnd_date.date_to_chardate(g_max_end_date),
7107 p_person_id => p_person_id);
7108
7109 if fnd_global.conc_request_id in ( 0,-1) then
7110 --
7111 fnd_message.set_name('BEN','BEN_92455_STRT_RUN_RESULTS');
7112 fnd_message.set_token('PARMA', fnd_date.date_to_chardate(g_max_end_date,calendar_aware=>2));
7113 l_string := fnd_message.get;
7114 benutils.write(p_text => l_string);
7115 --
7116 end if;
7117 g_msg_displayed := 1;
7118 end if;
7119
7120 insert_into_quick_pay
7121 (p_person_id => p_person_id,
7122 p_element_type_id => l_element_type_id,
7123 p_assignment_id => l_assignment_id,
7124 p_element_entry_id => l_element_entry_id,
7125 p_effective_date => l_rt_strt_dt,
7126 p_start_date => l_rt_strt_dt,
7127 p_end_date => g_max_end_date,
7128 p_payroll_id => l_payroll_id);
7129 --
7130 end if;
7131 --
7132 -- Update prtt_rt_val with the new element entry value id
7133 --
7134 if g_debug then
7135 hr_utility.set_location('update prtt_rt_val',180);
7136 end if;
7137 --
7138 if p_prtt_rt_val_id is not null then
7139 p_prv_object_version_number := nvl(p_prv_object_version_number,
7140 l_prv_rec.object_version_number);
7141 ben_prtt_rt_val_api.update_prtt_rt_val
7142 (p_validate => p_validate
7143 ,p_business_group_id => l_prv_rec.business_group_id
7144 ,p_prtt_rt_val_id => l_prv_rec.prtt_rt_val_id
7145 ,p_element_entry_value_id => l_entry_value_id
7146 ,p_object_version_number => p_prv_object_version_number
7147 ,p_effective_date => l_rt_strt_dt
7148 );
7149 --
7150 end if;
7151 end if;
7152 --
7153 -- call pqp routine for updating absence balances
7154 --
7155 if l_normal_pp_date is not null and
7156 l_abs_ler then
7157 if g_debug then
7158 hr_utility.set_location('Calling pqp_absence_plan_process ',189);
7159 end if;
7160 pqp_absence_plan_process.create_absence_plan_details
7161 (p_person_id => p_person_id
7162 ,p_assignment_id => l_assignment_id
7163 ,p_business_group_id => p_business_group_id
7164 ,p_legislation_code => get_legislation_code(p_business_group_id)
7165 ,p_effective_date => p_effective_date
7166 ,p_element_type_id => l_element_type_id
7167 ,p_pl_id => g_result_rec.pl_id
7168 ,p_pl_typ_id => g_result_rec.pl_typ_id
7169 ,p_ler_id => l_ler_id
7170 ,p_per_in_ler_id => l_per_in_ler_id
7171 ,p_absence_attendance_id => l_absence_attendance_id
7172 ,p_effective_start_date => l_effective_start_date
7173 ,p_effective_end_date => nvl(l_effective_end_date,hr_api.g_eot)
7174 ,p_formula_outputs => g_outputs
7175 ,p_error_code => l_err_code
7176 ,p_error_message => l_err_mesg
7177 );
7178 end if;
7179 --
7180 if g_debug then
7181 hr_utility.set_location('element_entry_id='||l_element_entry_id,189);
7182 hr_utility.set_location('Leaving: '||l_proc,190);
7183 end if;
7184 --
7185
7186 p_element_entry_value_id := l_entry_value_id;
7187 g_creee_calc_vals.element_entry_id := l_element_entry_id;
7188 g_creee_calc_vals.zero_pp_date := l_zero_pp_date;
7189 g_creee_calc_vals.special_pp_date := l_special_pp_date;
7190 g_creee_calc_vals.special_amt := l_special_amt;
7191 g_creee_calc_vals.normal_pp_date := l_normal_pp_date;
7192 g_creee_calc_vals.normal_amt := l_per_pay_amt;
7193 g_creee_calc_vals.normal_pp_end_date := l_normal_pp_end_date;
7194 g_creee_calc_vals.prtn_flag := l_prtn_flag;
7195 g_creee_calc_vals.first_pp_adjustment := l_first_pp_adjustment;
7196 g_creee_calc_vals.rt_strt_dt := l_rt_strt_dt;
7197 g_creee_calc_vals.range_start := l_range_start;
7198 g_creee_calc_vals.last_pp_end_dt := l_last_pp_end_dt;
7199 g_creee_calc_vals.payroll_id := l_payroll_id;
7200 --
7201 end create_enrollment_element;
7202 --
7203 -- ----------------------------------------------------------------------------
7204 -- |-------------------< reopen_closed_enrollment >--------------------------|
7205 -- ----------------------------------------------------------------------------
7206 procedure reopen_closed_enrollment
7207 (p_validate in boolean
7208 ,p_business_group_id in number
7209 ,p_person_id in number
7210 ,p_acty_base_rt_id in number
7211 ,p_element_type_id in number
7212 ,p_prtt_rt_val_id in number
7213 ,p_input_value_id in number
7214 ,p_rt in number
7215 ,p_rt_start_date in date
7216 ,p_effective_date in date
7217 ) is
7218
7219 cursor get_abr_info (p_acty_base_rt_id in number,
7220 p_effective_date date) is
7221 select abr.ele_rqd_flag,
7222 abr.input_va_calc_rl,
7223 abr.element_type_id,
7224 abr.input_value_id,
7225 abr.prtl_mo_det_mthd_cd
7226 from ben_acty_base_rt_f abr
7227 where abr.acty_base_rt_id=p_acty_base_rt_id
7228 and p_effective_date between
7229 abr.effective_start_date and abr.effective_end_date;
7230 --
7231 l_abr_info get_abr_info%rowtype;
7232 --
7233 cursor c_ele_info (p_person_id in number,
7234 p_prtt_enrt_rslt_id in number,
7235 p_element_entry_value_id in number) is
7236 select pee.element_entry_id,
7237 asg.assignment_id,
7238 asg.payroll_id,
7239 pet.element_name,
7240 pet.multiple_entries_allowed_flag,
7241 pel.element_type_id,
7242 pev.input_value_id
7243 from per_all_assignments_f asg,
7244 pay_element_links_f pel,
7245 pay_element_types_f pet,
7246 pay_element_entries_f pee,
7247 pay_element_entry_values_f pev
7248 where asg.person_id = p_person_id
7249 and asg.assignment_id = pee.assignment_id
7250 and pee.effective_start_date between asg.effective_start_date
7251 and asg.effective_end_date
7252 and pev.element_entry_value_id = p_element_entry_value_id
7253 and pee.element_entry_id = pev.element_entry_id
7254 and pee.creator_id = p_prtt_enrt_rslt_id
7255 and pee.creator_type = 'F'
7256 and pee.entry_type = 'E'
7257 and pev.effective_start_date between pee.effective_start_date
7258 and pee.effective_end_date
7259 and pel.element_link_id = pee.element_link_id
7260 and pee.effective_start_date between pel.effective_start_date
7261 and pel.effective_end_date
7262 and pet.element_type_id = pel.element_type_id
7263 and pel.effective_start_date between pet.effective_start_date
7264 and pet.effective_end_date;
7265 --
7266 -- Cursor to get the entry to be reopened
7267 --
7268 cursor get_last_element_entry
7269 (p_element_type_id in number
7270 ,p_input_value_id in number
7271 ,p_assignment_id in number
7272 ,p_prtt_enrt_rslt_id in number
7273 ,p_effective_date in date
7274 )
7275 is
7276 select ele.element_entry_id,
7277 ele.element_link_id,
7278 ele.effective_start_date,
7279 ele.effective_end_date,
7280 pev.screen_entry_value,
7281 ele.object_version_number
7282 from pay_element_entries_f ele,
7283 pay_element_entry_values_f pev,
7284 pay_element_links_f elk
7285 where ele.creator_id = p_prtt_enrt_rslt_id
7286 and ele.creator_type = 'F'
7287 and ele.entry_type = 'E'
7288 and ele.assignment_id = p_assignment_id
7289 and ele.element_link_id = elk.element_link_id
7290 and ele.effective_start_date between elk.effective_start_date
7291 and elk.effective_end_date
7292 and elk.element_type_id = p_element_type_id
7293 and pev.element_entry_id = ele.element_entry_id
7294 and pev.input_value_id = p_input_value_id
7295 and pev.effective_start_date between ele.effective_start_date
7296 and ele.effective_end_date
7297 order by ele.effective_start_date desc;
7298 --
7299 cursor c_current_ee
7300 (p_element_type_id in number
7301 ,p_prtt_enrt_rslt_id in number
7302 ,p_assignment_id in number
7303 ,p_effective_date in date
7304 ) is
7305 select ele.element_entry_id,
7306 ele.effective_start_date,
7307 ele.effective_end_date,
7308 ele.object_version_number
7309 from pay_element_entries_f ele,
7310 pay_element_links_f elk
7311 where p_effective_date between ele.effective_start_date
7312 and ele.effective_end_date
7313 and ele.assignment_id = p_assignment_id
7314 and ele.element_link_id = elk.element_link_id
7315 and ele.effective_start_date between elk.effective_start_date
7316 and elk.effective_end_date
7317 and elk.element_type_id = p_element_type_id
7318 and ele.creator_type ='F'
7319 and ele.entry_type = 'E'
7320 and nvl(ele.creator_id,-1) <> p_prtt_enrt_rslt_id
7321 order by ele.effective_start_date desc;
7322 l_current_ee_rec c_current_ee%rowtype;
7323 --
7324 cursor c_min_max_dt(p_element_entry_id number) is
7325 select min(effective_start_date),
7326 max(effective_end_date)
7327 from pay_element_entries_f
7328 where element_entry_id = p_element_entry_id;
7329 --
7330 cursor c_chk_abs_ler (c_per_in_ler_id number,
7331 c_effective_date date) is
7332 select pil.per_in_ler_id,
7333 pil.trgr_table_pk_id,
7334 ler.ler_id
7335 from ben_per_in_ler pil,
7336 ben_ler_f ler
7337 where pil.per_in_ler_id = c_per_in_ler_id
7338 and ler.ler_id = pil.ler_id
7339 and ler.typ_cd ='ABS'
7340 and c_effective_date between
7341 ler.effective_start_date and ler.effective_end_date;
7342 --
7343 -- bug 7206471
7344 --
7345 Cursor c_adjust_exists is
7346 select leclr.*
7347 from ben_le_clsn_n_rstr leclr
7348 ,ben_prtt_rt_val prv
7349 ,ben_acty_base_rt_f abr
7350 where bkup_tbl_typ_cd = 'BEN_PRTT_RT_VAL_ADJ'
7351 and bkup_tbl_id = prv.prtt_rt_val_id
7352 and prv.acty_base_rt_id = abr.acty_base_rt_id
7353 and abr.element_type_id = p_element_type_id;
7354 --
7355 l_adjust_exists ben_le_clsn_n_rstr%rowtype;
7356 --
7357 -- -- bug 7206471
7358 --
7359 l_prtt_enrt_rslt_id number;
7360 l_absence_attendance_id number;
7361 l_per_in_ler_id number;
7362 l_ler_id number;
7363 l_abs_ler boolean := false;
7364 l_input_value_id number;
7365 l_input_va_calc_rl number;
7366 l_element_entry_id NUMBER;
7367 l_screen_entry_value NUMBER;
7368 l_ext_chg_evt_log_id NUMBER;
7369 l_ext_object_version_number NUMBER;
7370 l_object_version_number NUMBER;
7371 l_effective_start_date DATE;
7372 l_effective_end_date DATE;
7373 l_effective_date DATE;
7374 l_assignment_id NUMBER;
7375 l_organization_id NUMBER;
7376 l_payroll_id NUMBER;
7377 l_delete_warning BOOLEAN;
7378 l_dummy_number number;
7379 l_ele_rqd_flag VARCHAR2(30);
7380 l_jurisdiction_code varchar2(30);
7381 l_subpriority number;
7382 l_err_code varchar2(10);
7383 l_err_mesg varchar2(2000);
7384 l_update_warning boolean;
7385 l_create_ee boolean := false;
7386 l_create_warning boolean;
7387 l_dummy_date date;
7388 l_out_date_not_required date;
7389 l_asg_max_eligibility_date date;
7390 l_element_term_rule_date date;
7391 l_element_link_end_date date;
7392 l_element_name varchar2(80);
7393 l_recurring_end_date date;
7394 l_element_link_id number;
7395 l_element_type_id number;
7396 l_multiple_entries_flag varchar2(1);
7397 l_new_element_link_id number;
7398 l_encoded_message varchar2(2000);
7399 l_app_short_name varchar2(2000);
7400 l_message_name varchar2(2000);
7401 l_dt_del_mode varchar2(30);
7402 l_prv_ovn number;
7403 l_inpval_tab inpval_tab_typ;
7404 l_string varchar2(4000);
7405 l_min_start_date date;
7406 l_max_end_date date;
7407 l_proc VARCHAR2(72) := g_package||'reopen_closed_enrollment';
7408
7409 -- 3266166
7410 l_uom varchar2(30);
7411 l_screen_entry_value_var varchar2(60);
7412 l_recompute_proration boolean := false;
7413 l_v2dummy varchar2(30);
7414 l_date date;
7415 --
7416
7417
7418 begin
7419 g_debug := hr_utility.debug_enabled;
7420 if g_debug then
7421 hr_utility.set_location('Entering: '||l_proc,5);
7422 hr_utility.set_location('p_eff_dt: '||to_char(p_effective_date),5);
7423 hr_utility.set_location('p_prtt_rt_val_id: '||p_prtt_rt_val_id,5);
7424 end if;
7425 --
7426 --BUG 3167959 We need to intialize the pl/sql table
7427 clear_ext_inpval_tab ;
7428 --
7429 -- get prv info
7430 --
7431 open c_get_prtt_rt_val
7432 (c_prtt_rt_val_id => p_prtt_rt_val_id
7433 );
7434 fetch c_get_prtt_rt_val into l_prv_rec;
7435 if c_get_prtt_rt_val%notfound
7436 then
7437 --
7438 if g_debug then
7439 hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL',170);
7440 end if;
7441 close c_get_prtt_rt_val;
7442 --
7443 fnd_message.set_name('BEN', 'BEN_92103_NO_PRTT_RT_VAL');
7444 fnd_message.set_token('PROC',l_proc);
7445 fnd_message.set_token('PRTT_RT_VAL',to_char(p_prtt_rt_val_id));
7446 fnd_message.raise_error;
7447 --
7448 end if;
7449 close c_get_prtt_rt_val;
7450 --
7451 -- if no element entry was created to start with, just return
7452 --
7453 if l_prv_rec.element_entry_value_id is null then
7454 if g_debug then
7455 hr_utility.set_location('No entry. Leaving: '||l_proc,60);
7456 end if;
7457 return;
7458 end if;
7459 --
7460 -- get activity base rate information
7461 --
7462 open get_abr_info(l_prv_rec.acty_base_rt_id,
7463 l_prv_rec.rt_strt_dt);
7464 fetch get_abr_info into l_abr_info;
7465 if get_abr_info%notfound then
7466 close get_abr_info;
7467 if g_debug then
7468 hr_utility.set_location('BEN_91723_NO_ENRT_RT_ABR_FOUND',30);
7469 end if;
7470 fnd_message.set_name('BEN','BEN_91723_NO_ENRT_RT_ABR_FOUND');
7471 fnd_message.set_token('PROC',l_proc);
7472 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
7473 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
7474 fnd_message.raise_error;
7475 end if;
7476 close get_abr_info;
7477 --
7478 -- get the element type and input value based on entry value attached to
7479 -- prtt rt. Do NOT get them from abr for reopening
7480 --
7481 hr_utility.set_location('p_person_id: '||p_person_id,5);
7482 hr_utility.set_location('prtt_enrt_rslt_id: '||l_prv_rec.prtt_enrt_rslt_id,5);
7483 hr_utility.set_location('l_prv_rec.element_entry_value_id: '||l_prv_rec.element_entry_value_id,5);
7484
7485 open c_ele_info(p_person_id,
7486 l_prv_rec.prtt_enrt_rslt_id,
7487 l_prv_rec.element_entry_value_id);
7488 fetch c_ele_info into
7489 l_element_entry_id,
7490 l_assignment_id,
7491 l_payroll_id,
7492 l_element_name,
7493 l_multiple_entries_flag,
7494 l_element_type_id,
7495 l_input_value_id;
7496 close c_ele_info;
7497
7498 if g_debug then
7499 hr_utility.set_location(' l_asg_id: '||l_assignment_id,50);
7500 hr_utility.set_location(' p_elt_id: '||l_element_type_id,50);
7501 hr_utility.set_location(' p_inp_val: '||l_input_value_id,50);
7502 hr_utility.set_location(' l_ele_id: '||l_element_entry_id,50);
7503 hr_utility.set_location(' l_ele_id: '||l_element_entry_id,50);
7504 end if;
7505 --
7506 -- If the abr has proration defined we will need to recompute
7507 -- the prorated amounts
7508 --
7509 -- This still does not address the case, where there is a special pp
7510 -- because of rounding. Will address that issue in a future version
7511 --
7512 hr_utility.set_location('prtl_mo_det_mthd_cd: '||l_abr_info.prtl_mo_det_mthd_cd,50);
7513 if nvl(l_abr_info.prtl_mo_det_mthd_cd,'NONE') <> 'NONE' then
7514 l_recompute_proration := true;
7515 end if;
7516
7517 -- <ELE>
7518 if l_element_entry_id is null or
7519 l_recompute_proration then
7520 --
7521 -- This is for the case when the entry attached to prtt rt got zapped.
7522 -- Possible 1) prior to FP C when ct. could delete the entries
7523 -- 2) prior to retro pay changes
7524 --
7525 -- Also for the case when we need to recompute prorated amounts
7526 --
7527 get_abr_assignment (p_person_id => p_person_id
7528 ,p_effective_date => l_prv_rec.rt_strt_dt
7529 ,p_acty_base_rt_id => l_prv_rec.acty_base_rt_id
7530 ,p_organization_id => l_dummy_number
7531 ,p_payroll_id => l_payroll_id
7532 ,p_assignment_id => l_assignment_id);
7533
7534 open c_current_ee(l_abr_info.element_type_id,
7535 l_prv_rec.prtt_enrt_rslt_id,
7536 l_assignment_id,
7537 l_prv_rec.rt_strt_dt);
7538 fetch c_current_ee into l_current_ee_rec;
7539 close c_current_ee;
7540 --
7541 if l_element_entry_id is null and
7542 l_current_ee_rec.element_entry_id is not null then
7543 --
7544 -- Determine dt track mode.
7545 --
7546 open c_min_max_dt(l_current_ee_rec.element_entry_id);
7547 fetch c_min_max_dt into l_min_start_date,l_max_end_date;
7548 close c_min_max_dt;
7549
7550 if l_prv_rec.rt_strt_dt-1 < l_min_start_date then
7551 l_dt_del_mode := hr_api.g_zap;
7552 else
7553 l_dt_del_mode := hr_api.g_delete;
7554 end if;
7555
7556 l_effective_date :=
7557 greatest(l_current_ee_rec.effective_start_date,l_prv_rec.rt_strt_dt -1);
7558
7559 py_element_entry_api.delete_element_entry
7560 (p_validate =>p_validate
7561 ,p_datetrack_delete_mode =>l_dt_del_mode
7562 ,p_effective_date =>l_effective_date
7563 ,p_element_entry_id =>l_current_ee_rec.element_entry_id
7564 ,p_object_version_number =>l_current_ee_rec.object_version_number
7565 ,p_effective_start_date =>l_dummy_date
7566 ,p_effective_end_date =>l_dummy_date
7567 ,p_delete_warning =>l_delete_warning);
7568 --
7569 -- write to the change event log
7570 --
7571 ben_ext_chlg.log_element_chg(
7572 p_action => hr_api.g_delete,
7573 p_old_amt => null,
7574 p_input_value_id => l_abr_info.input_value_id,
7575 p_element_entry_id => l_current_ee_rec.element_entry_id,
7576 p_person_id => p_person_id,
7577 p_business_group_id => p_business_group_id,
7578 p_effective_date => l_prv_rec.rt_strt_dt -1 );
7579
7580 end if;
7581 --
7582 create_enrollment_element
7583 (p_business_group_id => p_business_group_id
7584 ,p_prtt_rt_val_id => p_prtt_rt_val_id
7585 ,p_person_id => p_person_id
7586 ,p_acty_ref_perd => l_prv_rec.acty_ref_perd_cd
7587 ,p_acty_base_rt_id => l_prv_rec.acty_base_rt_id
7588 ,p_enrt_rslt_id => l_prv_rec.prtt_enrt_rslt_id
7589 ,p_rt_start_date => l_prv_rec.rt_strt_dt
7590 ,p_rt => l_prv_rec.rt_val
7591 ,p_cmncd_rt => l_prv_rec.cmcd_rt_val
7592 ,p_ann_rt => l_prv_rec.ann_rt_val
7593 ,p_input_value_id => l_abr_info.input_value_id
7594 ,p_element_type_id => l_abr_info.element_type_id
7595 ,p_prv_object_version_number=> l_prv_ovn
7596 ,p_effective_date => l_prv_rec.rt_strt_dt
7597 ,p_eev_screen_entry_value => l_dummy_number
7598 ,p_element_entry_value_id => l_dummy_number
7599 );
7600 else
7601 --
7602 -- get the element entry that needs to be reopened. This entry could be
7603 -- different from what is attached to prtt rt
7604 --
7605 if g_debug then
7606 hr_utility.set_location('enrt_rslt_id='||l_prv_rec.prtt_enrt_rslt_id,10);
7607 hr_utility.set_location('rt_strt_dt='||l_prv_rec.rt_strt_dt,10);
7608 end if;
7609
7610 open get_last_element_entry(l_element_type_id,
7611 l_input_value_id,
7612 l_assignment_id,
7613 l_prv_rec.prtt_enrt_rslt_id,
7614 l_prv_rec.rt_strt_dt);
7615 fetch get_last_element_entry into
7616 l_element_entry_id
7617 ,l_element_link_id
7618 ,l_effective_start_date
7619 ,l_effective_end_date
7620 ,l_screen_entry_value_var
7621 ,l_object_version_number;
7622
7623 -- 3266166
7624 hr_utility.set_location('l_screen_entry_value_var='||l_screen_entry_value_var,10);
7625 --
7626 if l_uom is null then
7627 if nvl(g_result_rec.prtt_enrt_rslt_id,-1)<>l_prv_rec.prtt_enrt_rslt_id
7628 then
7629 open c_current_result_info (c_prtt_enrt_rslt_id => l_prv_rec.prtt_enrt_rslt_id);
7630 fetch c_current_result_info into g_result_rec;
7631 close c_current_result_info;
7632 end if;
7633 --
7634 if g_result_rec.uom is not null
7635 then
7636 l_uom := g_result_rec.uom;
7637 else
7638 l_uom := get_uom(p_business_group_id,p_effective_date);
7639 end if;
7640 end if;
7641 --
7642 l_screen_entry_value := chkformat(l_screen_entry_value_var, l_uom);
7643 hr_utility.set_location('l_screen_entry_value='||l_screen_entry_value,10);
7644 --
7645 if get_last_element_entry%notfound
7646 then
7647 if g_debug then
7648 hr_utility.set_location('BEN_92105_NO_PRIOR_ENROLLMENT',40);
7649 end if;
7650 close get_last_element_entry;
7651 fnd_message.set_name('BEN', 'BEN_92105_NO_PRIOR_ENROLLMENT');
7652 fnd_message.set_token('PROC',l_proc);
7653 fnd_message.set_token('ELEMENT_TYPE_ID',to_char(l_element_type_id));
7654 fnd_message.set_token('ASSGN_ID',to_char(l_assignment_id));
7655 fnd_message.set_token('PRTT_RT_VAL_ID',to_char(p_prtt_rt_val_id));
7656 fnd_message.raise_error;
7657 --
7658 end if;
7659 close get_last_element_entry;
7660
7661 if g_debug then
7662 hr_utility.set_location(' l_ele_id: '||l_element_entry_id,50);
7663 hr_utility.set_location(' l_esd: '||l_effective_start_date,50);
7664 hr_utility.set_location(' l_eed: '||l_effective_end_date,50);
7665 end if;
7666
7667 l_effective_date := l_effective_end_date;
7668 g_max_end_date := null;
7669 --
7670 -- for quick pay fix
7671 --
7672 --Bug 3151737 and 3063518 we need to do this if payroll exists for the
7673 --assignment else skip this part.
7674 --
7675 if l_payroll_id is not null then
7676 --
7677 if nvl(g_per_pay_rec.assignment_id,-1) <> l_assignment_id then
7678 --
7679 open c_payroll_was_ever_run
7680 (c_assignment_id => l_assignment_id
7681 );
7682 fetch c_payroll_was_ever_run into l_v2dummy;
7683 g_per_pay_rec.assignment_id := l_assignment_id;
7684 g_per_pay_rec.payroll_was_ever_run := c_payroll_was_ever_run%found;
7685 close c_payroll_was_ever_run;
7686 --
7687 end if;
7688 --
7689 if g_per_pay_rec.payroll_was_ever_run and
7690 g_per_pay_rec.end_date is null then
7691 --
7692 g_max_end_date :=
7693 get_max_end_dt (
7694 p_assignment_id => l_assignment_id,
7695 p_payroll_id => l_payroll_id,
7696 p_element_type_id => l_element_type_id,
7697 p_effective_date => l_effective_date);
7698 --
7699 g_per_pay_rec.end_date := g_max_end_date;
7700 --
7701 elsif g_per_pay_rec.end_date is not null then
7702 g_max_end_date := g_per_pay_rec.end_date;
7703 end if;
7704
7705 if g_max_end_date > l_effective_date then
7706 -- insert rows into pay_quickpay_inclusions
7707 insert_into_quick_pay
7708 (p_person_id => p_person_id,
7709 p_element_type_id => l_element_type_id,
7710 p_assignment_id => l_assignment_id,
7711 p_element_entry_id => l_element_entry_id,
7712 p_effective_date => l_effective_date,
7713 p_start_date => l_effective_date,
7714 p_end_date => g_max_end_date,
7715 p_payroll_id => l_payroll_id);
7716 --
7717 end if;
7718 --
7719 end if ; -- l_payroll_id
7720 --
7721 hr_entry.entry_asg_pay_link_dates (l_assignment_id,
7722 l_element_link_id,
7723 l_effective_start_date,
7724 l_element_term_rule_date,
7725 l_out_date_not_required,
7726 l_element_link_end_date,
7727 l_out_date_not_required,
7728 l_out_date_not_required);
7729
7730 --
7731 --
7732 if g_debug then
7733 hr_utility.set_location('l_element_term_rule_date '||l_element_term_rule_date,44333);
7734 hr_utility.set_location('l_element_link_end_date '||l_element_link_end_date,44333);
7735 hr_utility.set_location('l_effective_date '||l_effective_date,44333);
7736 end if;
7737 -- Call update
7738 --
7739 /*
7740 Before :-
7741 02-JAN-1994 05-FEB-1994 08-AUG-1995
7742 |-A----------|-B----------------------|
7743 ED
7744 After :-
7745 02-JAN-1994 05-FEB-1994
7746 |-A----------|-E------------------------------------------------->
7747 ED
7748 */
7749 if g_debug then
7750 hr_utility.set_location(' l_element_entry_id: '||l_element_entry_id,50);
7751 hr_utility.set_location(' l_effective_date: '||l_effective_date,50);
7752 hr_utility.set_location(' l_ovn: '||l_object_version_number,50);
7753 end if;
7754 --
7755
7756 -- <REOPEN>
7757 if l_effective_date <> hr_api.g_eot then
7758 --
7759 -- check if abs ler
7760 --
7761 open c_chk_abs_ler
7762 (c_per_in_ler_id => l_prv_rec.per_in_ler_id
7763 ,c_effective_date => p_effective_date
7764 );
7765 fetch c_chk_abs_ler into
7766 l_per_in_ler_id,
7767 l_absence_attendance_id,
7768 l_ler_id;
7769 l_abs_ler := c_chk_abs_ler%found;
7770 close c_chk_abs_ler;
7771
7772 --
7773 -- handle any future entries
7774 --
7775 open c_adjust_exists; -- bug 7206471
7776 fetch c_adjust_exists into l_adjust_exists; -- bug 7206471
7777 if c_adjust_exists%notfound then -- bug 7206471
7778 if not l_abs_ler then
7779 chk_future_entries
7780 (p_validate => p_validate,
7781 p_person_id => p_person_id,
7782 p_assignment_id => l_assignment_id,
7783 p_enrt_rslt_id => l_prv_rec.prtt_enrt_rslt_id,
7784 p_element_type_id => l_element_type_id,
7785 p_multiple_entries_flag => l_multiple_entries_flag,
7786 p_effective_date => l_effective_date);
7787 end if;
7788 end if; -- bug 7206471
7789 close c_adjust_exists; -- bug 7206471
7790
7791 if l_element_link_end_date <> l_effective_date and
7792 l_element_term_rule_date <> l_effective_date then
7793
7794 begin
7795 --
7796 hr_utility.set_location('before pay.delete l_effective_date '||l_effective_date,44333);
7797 --
7798 py_element_entry_api.delete_element_entry
7799 (p_validate =>p_validate
7800 ,p_datetrack_delete_mode =>'FUTURE_CHANGE'
7801 ,p_effective_date =>l_effective_date
7802 ,p_element_entry_id =>l_element_entry_id
7803 ,p_object_version_number =>l_object_version_number
7804 ,p_effective_start_date =>l_effective_start_date
7805 ,p_effective_end_date =>l_effective_end_date
7806 ,p_delete_warning =>l_delete_warning);
7807 --
7808 hr_utility.set_location('after pay.delete l_effective_date '||l_effective_date,44333);
7809 hr_utility.set_location('l_effective_end_date '||l_effective_end_date,44333);
7810 --
7811 l_effective_date := l_effective_end_date;
7812 --
7813 -- write to the change event log
7814 --
7815 ben_ext_chlg.log_element_chg(
7816 p_action => hr_api.g_delete,
7817 p_old_amt => null,
7818 p_input_value_id => l_input_value_id,
7819 p_element_entry_id => l_element_entry_id,
7820 p_person_id => p_person_id,
7821 p_business_group_id => p_business_group_id,
7822 p_effective_date => l_effective_date);
7823 --
7824 exception
7825 when others then
7826 ben_on_line_lf_evt.get_ser_message(l_encoded_message,
7827 l_app_short_name,
7828 l_message_name);
7829 l_encoded_message := fnd_message.get;
7830 --
7831 if l_message_name like '%HR_6284_ELE_ENTRY_DT_ASG_DEL%' or
7832 l_message_name like '%HR_7187_DT_CANNOT_EXTEND_END%' then
7833 --
7834 --asg is not eligible for link beyond l_effective_date
7835 --
7836 null;
7837 else
7838 if l_app_short_name is not null then
7839 fnd_message.set_name(l_app_short_name,l_message_name);
7840 fnd_message.raise_error;
7841 else
7842 raise;
7843 end if;
7844 end if;
7845 end;
7846 end if;
7847 --
7848 loop
7849
7850 if l_effective_date = l_element_term_rule_date then
7851 --
7852 -- Element entry created till the max possible date.
7853 --
7854 exit;
7855 end if;
7856
7857 if l_abs_ler then
7858 -- bug # 7383673, 7390204 -- restricting bug 6450363 fix only for absences
7859
7860 -- added here for bug 6450363
7861
7862 l_date := l_effective_date + 1;
7863 if g_debug then
7864 hr_utility.set_location('l_effective_date '||l_effective_date,44333);
7865 hr_utility.set_location('l_effective_date + 1 '||l_date,44333);
7866 end if;
7867
7868 get_abr_assignment (p_person_id => p_person_id
7869 ,p_effective_date => l_effective_date + 1
7870 ,p_acty_base_rt_id => l_prv_rec.acty_base_rt_id
7871 ,p_organization_id => l_dummy_number
7872 ,p_payroll_id => l_payroll_id
7873 ,p_assignment_id => l_assignment_id);
7874
7875 --added till here for bug 6450363
7876 end if;
7877
7878 get_link
7879 (p_assignment_id => l_assignment_id
7880 ,p_element_type_id => l_element_type_id
7881 ,p_business_group_id => p_business_group_id
7882 ,p_input_value_id => l_input_value_id
7883 ,p_effective_date => l_effective_date + 1
7884 ,p_element_link_id => l_new_element_link_id);
7885
7886 if l_new_element_link_id = l_element_link_id or
7887 l_new_element_link_id is null then
7888 --
7889 -- No new link found. Get out of the loop
7890 --
7891 exit;
7892 end if;
7893
7894 if nvl(l_inpval_tab.count,0) = 0 then
7895 get_inpval_tab(l_element_entry_id,
7896 l_effective_date,
7897 l_inpval_tab);
7898 end if;
7899
7900 l_element_link_id := l_new_element_link_id;
7901 l_effective_date := l_effective_date + 1;
7902
7903 py_element_entry_api.create_element_entry
7904 (p_validate =>p_validate
7905 ,p_effective_date =>l_effective_date
7906 ,p_business_group_id =>p_business_group_id
7907 ,p_assignment_id =>l_assignment_id
7908 ,p_element_link_id =>l_element_link_id
7909 ,p_entry_type =>'E'
7910 ,p_override_user_ent_chk =>'Y'
7911 ,p_subpriority =>l_subpriority
7912 ,p_input_value_id1 =>l_inpval_tab(1).input_value_id
7913 ,p_entry_value1 =>l_inpval_tab(1).value
7914 ,p_input_value_id2 =>l_inpval_tab(2).input_value_id
7915 ,p_entry_value2 =>l_inpval_tab(2).value
7916 ,p_input_value_id3 =>l_inpval_tab(3).input_value_id
7917 ,p_entry_value3 =>l_inpval_tab(3).value
7918 ,p_input_value_id4 =>l_inpval_tab(4).input_value_id
7919 ,p_entry_value4 =>l_inpval_tab(4).value
7920 ,p_input_value_id5 =>l_inpval_tab(5).input_value_id
7921 ,p_entry_value5 =>l_inpval_tab(5).value
7922 ,p_input_value_id6 =>l_inpval_tab(6).input_value_id
7923 ,p_entry_value6 =>l_inpval_tab(6).value
7924 ,p_input_value_id7 =>l_inpval_tab(7).input_value_id
7925 ,p_entry_value7 =>l_inpval_tab(7).value
7926 ,p_input_value_id8 =>l_inpval_tab(8).input_value_id
7927 ,p_entry_value8 =>l_inpval_tab(8).value
7928 ,p_input_value_id9 =>l_inpval_tab(9).input_value_id
7929 ,p_entry_value9 =>l_inpval_tab(9).value
7930 ,p_input_value_id10 =>l_inpval_tab(10).input_value_id
7931 ,p_entry_value10 =>l_inpval_tab(10).value
7932 ,p_input_value_id11 =>l_inpval_tab(11).input_value_id
7933 ,p_entry_value11 =>l_inpval_tab(11).value
7934 ,p_input_value_id12 =>l_inpval_tab(12).input_value_id
7935 ,p_entry_value12 =>l_inpval_tab(12).value
7936 ,p_input_value_id13 =>l_inpval_tab(13).input_value_id
7937 ,p_entry_value13 =>l_inpval_tab(13).value
7938 ,p_input_value_id14 =>l_inpval_tab(14).input_value_id
7939 ,p_entry_value14 =>l_inpval_tab(14).value
7940 ,p_input_value_id15 =>l_inpval_tab(15).input_value_id
7941 ,p_entry_value15 =>l_inpval_tab(15).value
7942 ,p_effective_start_date =>l_effective_start_date
7943 ,p_effective_end_date =>l_effective_end_date
7944 ,p_element_entry_id =>l_element_entry_id
7945 ,p_object_version_number =>l_object_version_number
7946 ,p_create_warning =>l_create_warning
7947 );
7948
7949 py_element_entry_api.update_element_entry
7950 (p_validate =>p_validate
7951 ,p_datetrack_update_mode =>hr_api.g_correction
7952 ,p_effective_date =>l_effective_date
7953 ,p_business_group_id =>p_business_group_id
7954 ,p_element_entry_id =>l_element_entry_id
7955 ,p_override_user_ent_chk =>'Y'
7956 ,p_object_version_number =>l_object_version_number
7957 ,p_creator_type =>'F'
7958 ,p_creator_id =>l_prv_rec.prtt_enrt_rslt_id
7959 ,p_effective_start_date =>l_effective_start_date
7960 ,p_effective_end_date =>l_effective_end_date
7961 ,p_update_warning =>l_update_warning
7962 );
7963 --
7964 -- write to the change event log
7965 --
7966 ben_ext_chlg.log_element_chg(
7967 p_action => 'CREATE',
7968 p_amt => l_screen_entry_value,
7969 p_input_value_id => l_input_value_id,
7970 p_element_entry_id => l_element_entry_id,
7971 p_person_id => p_person_id,
7972 p_business_group_id => p_business_group_id,
7973 p_effective_date => l_effective_date);
7974 --
7975
7976 l_effective_date := l_effective_end_date;
7977
7978 end loop;
7979
7980 if l_effective_date <> hr_api.g_eot then
7981
7982 if l_effective_date < l_element_term_rule_date then
7983 l_message_name := 'BEN_93454_NO_ELK_TILL_EOT';
7984 else
7985 l_message_name := 'BEN_93449_NO_ELE_TILL_EOT';
7986 end if;
7987
7988 --
7989 ben_warnings.load_warning
7990 (p_application_short_name => 'BEN',
7991 p_message_name => l_message_name,
7992 p_parma => l_element_name,
7993 p_parmb => to_char(l_effective_date),
7994 p_person_id => p_person_id);
7995 --
7996 if fnd_global.conc_request_id in ( 0,-1) then
7997 --
7998 fnd_message.set_name('BEN',l_message_name);
7999 fnd_message.set_token('PARMA',l_element_name);
8000 fnd_message.set_token('PARMB',to_char(l_effective_date));
8001 l_string := fnd_message.get;
8002 benutils.write(p_text => l_string);
8003 --
8004 end if;
8005
8006 end if;
8007 -- <ABS>
8008 if l_abs_ler then
8009
8010 if nvl(g_result_rec.prtt_enrt_rslt_id,-1)<>l_prv_rec.prtt_enrt_rslt_id then
8011 open c_current_result_info
8012 (c_prtt_enrt_rslt_id => l_prv_rec.prtt_enrt_rslt_id
8013 );
8014 fetch c_current_result_info into g_result_rec;
8015 close c_current_result_info;
8016 end if;
8017
8018 get_extra_ele_inputs
8019 (p_effective_date => l_effective_date
8020 ,p_person_id => p_person_id
8021 ,p_business_group_id => p_business_group_id
8022 ,p_assignment_id => l_assignment_id
8023 ,p_element_link_id => null
8024 ,p_entry_type => 'E'
8025 ,p_input_value_id1 => l_input_value_id
8026 ,p_entry_value1 => l_screen_entry_value
8027 ,p_element_entry_id => l_element_entry_id
8028 ,p_acty_base_rt_id => p_acty_base_rt_id
8029 ,p_input_va_calc_rl => l_abr_info.input_va_calc_rl
8030 ,p_abs_ler => l_abs_ler
8031 ,p_organization_id => l_organization_id
8032 ,p_payroll_id => l_payroll_id
8033 ,p_pgm_id => g_result_rec.pgm_id
8034 ,p_pl_id => g_result_rec.pl_id
8035 ,p_pl_typ_id => g_result_rec.pl_typ_id
8036 ,p_opt_id => g_result_rec.opt_id
8037 ,p_ler_id => l_ler_id
8038 ,p_dml_typ => 'U'
8039 ,p_jurisdiction_code => l_jurisdiction_code
8040 ,p_ext_inpval_tab => g_ext_inpval_tab
8041 ,p_subpriority => l_subpriority
8042 );
8043
8044 py_element_entry_api.update_element_entry
8045 (p_validate =>p_validate
8046 ,p_datetrack_update_mode =>hr_api.g_correction
8047 ,p_effective_date =>l_effective_date
8048 ,p_business_group_id =>p_business_group_id
8049 ,p_element_entry_id =>l_element_entry_id
8050 ,p_object_version_number =>l_object_version_number
8051 ,p_creator_type =>'F'
8052 ,p_creator_id =>l_prv_rec.prtt_enrt_rslt_id
8053 ,p_subpriority =>l_subpriority
8054 ,p_override_user_ent_chk =>'Y'
8055 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
8056 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
8057 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
8058 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
8059 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
8060 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
8061 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
8062 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
8063 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
8064 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
8065 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
8066 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
8067 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
8068 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
8069 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
8070 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
8071 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
8072 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
8073 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
8074 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
8075 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
8076 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
8077 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
8078 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
8079 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
8080 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
8081 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
8082 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
8083 ,p_effective_start_date =>l_effective_start_date
8084 ,p_effective_end_date =>l_effective_end_date
8085 ,p_update_warning =>l_update_warning
8086 );
8087
8088 pqp_absence_plan_process.update_absence_plan_details
8089 (p_person_id => p_person_id
8090 ,p_assignment_id => l_assignment_id
8091 ,p_business_group_id => p_business_group_id
8092 ,p_legislation_code => get_legislation_code(p_business_group_id)
8093 ,p_effective_date => l_effective_date
8094 ,p_element_type_id => l_element_type_id
8095 ,p_pl_id => g_result_rec.pl_id
8096 ,p_pl_typ_id => g_result_rec.pl_typ_id
8097 ,p_ler_id => l_ler_id
8098 ,p_per_in_ler_id => l_per_in_ler_id
8099 ,p_absence_attendance_id => l_absence_attendance_id
8100 ,p_effective_start_date => l_effective_start_date
8101 ,p_effective_end_date => l_effective_end_date
8102 ,p_formula_outputs => g_outputs
8103 ,p_error_code => l_err_code
8104 ,p_error_message => l_err_mesg
8105 );
8106 end if; -- <ABS>
8107 end if; -- <REOPEN>
8108 end if; -- <ELE>
8109 --
8110 if g_debug then
8111 hr_utility.set_location('Leaving: '||l_proc,60);
8112 end if;
8113 --
8114 end reopen_closed_enrollment;
8115 --
8116 -- ----------------------------------------------------------------------------
8117 -- |----------------------< recreate_enrollment_element >----------------------|
8118 -- ----------------------------------------------------------------------------
8119 procedure recreate_enrollment_element(p_validate IN BOOLEAN default FALSE
8120 ,p_business_group_id IN NUMBER
8121 ,p_person_id IN NUMBER
8122 ,p_enrt_rslt_id IN NUMBER
8123 ,p_acty_ref_perd in varchar2
8124 ,p_acty_base_rt_id in number
8125 ,p_element_entry_id IN NUMBER
8126 ,p_element_link_id IN NUMBER
8127 ,p_input_value_id IN NUMBER
8128 ,p_prtt_rt_val_id in number
8129 ,p_input_va_calc_rl in number
8130 ,p_abs_ler in boolean
8131 ,p_rt_strt_date in date
8132 ,p_rt_end_date IN DATE
8133 ,p_effective_date IN DATE
8134 ,p_amt in number
8135 ,p_object_version_number IN NUMBER) is
8136 cursor get_abr_info is
8137 select abr.prtl_mo_det_mthd_cd,
8138 abr.prtl_mo_det_mthd_rl,
8139 abr.wsh_rl_dy_mo_num,
8140 abr.prtl_mo_eff_dt_det_cd,
8141 abr.prtl_mo_eff_dt_det_rl,
8142 abr.acty_typ_cd,
8143 abr.element_type_id,
8144 abr.input_value_id,
8145 abr.input_va_calc_rl,
8146 abr.rndg_cd,
8147 abr.rndg_rl,
8148 abr.ele_rqd_flag,
8149 abr.one_ann_pymt_cd,
8150 abr.entr_ann_val_flag,
8151 abr.ele_entry_val_cd
8152 from ben_acty_base_rt_f abr
8153 where abr.acty_base_rt_id=p_acty_base_rt_id
8154 and abr.business_group_id=p_business_group_id
8155 and p_effective_date between
8156 abr.effective_start_date and abr.effective_end_date;
8157 --
8158 -- Get created element_entry_value_id
8159 --
8160 cursor get_created_entry_value
8161 (p_element_entry_id IN NUMBER
8162 ,p_input_value_id IN NUMBER
8163 ,p_effective_date IN DATE
8164 )
8165 is
8166 select element_entry_value_id
8167 from pay_element_entry_values_f
8168 where element_entry_id = p_element_entry_id
8169 and input_value_id = p_input_value_id
8170 and p_effective_date between effective_start_date
8171 and effective_end_date;
8172
8173 -- bug 5768050
8174 CURSOR c_ee_ovn (v_element_entry_id IN NUMBER)
8175 IS
8176 SELECT object_version_number
8177 FROM pay_element_entries_f
8178 WHERE element_entry_id = v_element_entry_id
8179 AND p_effective_date BETWEEN effective_start_date AND effective_end_date;
8180
8181 l_ovn pay_element_entries_f.object_version_number%TYPE;
8182
8183 -- end bug 5768050
8184
8185 l_per_month_amt number;
8186 l_assignment_id number;
8187 l_payroll_id number;
8188 l_element_entry_id number;
8189 l_ext_chg_evt_log_id number;
8190 l_input_value_id number;
8191 l_input_va_calc_rl number;
8192 l_screen_entry_value varchar2(60);
8193 l_prv_object_version_number number;
8194 l_object_version_number number;
8195 l_ext_object_version_number number;
8196 l_rt number;
8197 l_effective_start_date date;
8198 l_effective_end_date date;
8199 l_rt_end_dt date;
8200 l_delete_warning boolean;
8201 l_proc varchar2(72) := g_package||'recreate_enrollment_element';
8202 l_organization_id number;
8203 l_immediate_end boolean:=false;
8204 l_prtl_mo_det_mthd_cd varchar2(30);
8205 l_prtl_mo_det_mthd_rl number;
8206 l_wsh_rl_dy_mo_num number;
8207 l_prtl_mo_eff_dt_det_cd varchar2(30);
8208 l_prtl_mo_eff_dt_det_rl number;
8209 l_per_pay_amt number;
8210 l_prorated_monthly_amt number;
8211 l_amt number;
8212 l_prtn_flag varchar2(1);
8213 l_acty_typ_cd varchar2(30);
8214 l_element_type_id number;
8215 l_outputs ff_exec.outputs_t;
8216 l_remainder number;
8217 l_number_in_month number;
8218 l_old_normal_pp_date date;
8219 l_normal_pp_date date;
8220 l_special_pp_date date;
8221 l_old_normal_pp_end_date date;
8222 l_normal_pp_end_date date;
8223 l_special_pp_end_date date;
8224 l_zero_pp_date date default null;
8225 l_special_amt number;
8226 l_element_link_id number;
8227 l_entry_value_id number;
8228 l_start_date date;
8229 l_end_date date;
8230 l_update_ee boolean;
8231 l_curr_val number;
8232 l_new_date date;
8233 l_end_of_time date;
8234 l_create_warning boolean;
8235 l_update_warning boolean;
8236 l_jurisdiction_code varchar2(30);
8237 l_abr_rndg_cd varchar2(30);
8238 l_abr_rndg_rl number;
8239 l_ele_rqd_flag varchar2(30);
8240 l_one_ann_pymt_cd varchar2(30);
8241 l_entr_ann_val_flag varchar2(30);
8242 l_ele_entry_val_cd varchar2(30);
8243 l_last_pp_strt_dt date;
8244 l_last_pp_end_dt date;
8245 l_range_start date;
8246 l_ee_start_date date;
8247 l_cnt number;
8248 l_correction boolean;
8249 l_update boolean;
8250 l_update_override boolean;
8251 l_update_change_insert boolean;
8252 l_dt_upd_mode varchar2(30);
8253 l_element_entry_start_date date;
8254 l_perd_cd varchar2(30) := 'PP';
8255 l_subpriority number;
8256 l_override_user_ent_chk varchar2(30) := 'N';
8257
8258 begin
8259 if g_debug then
8260 hr_utility.set_location('Entering :'||l_proc,5);
8261 end if;
8262
8263 l_object_version_number := p_object_version_number;
8264 --
8265 if NOT (chk_assign_exists(p_person_id, p_business_group_id,
8266 p_effective_date, p_rt_end_date,
8267 p_acty_base_rt_id,
8268 l_assignment_id, l_organization_id,
8269 l_payroll_id)) then
8270
8271 if g_debug then
8272 hr_utility.set_location('BEN_92106_PRTT_NO_ASGN',5);
8273 end if;
8274 fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
8275 fnd_message.set_token('PROC',l_proc);
8276 fnd_message.set_token('PERSON_ID',to_char(p_person_id));
8277 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
8278 fnd_message.raise_error;
8279
8280 end if;
8281 if g_debug then
8282 hr_utility.set_location('l_assignment_id='||l_assignment_id,6);
8283 end if;
8284 --
8285 -- get activity base rate information
8286 --
8287 open get_abr_info;
8288 fetch get_abr_info into l_prtl_mo_det_mthd_cd,
8289 l_prtl_mo_det_mthd_rl,
8290 l_wsh_rl_dy_mo_num,
8291 l_prtl_mo_eff_dt_det_cd,
8292 l_prtl_mo_eff_dt_det_rl,
8293 l_acty_typ_cd,
8294 l_element_type_id,
8295 l_input_value_id,
8296 l_input_va_calc_rl,
8297 l_abr_rndg_cd,
8298 l_abr_rndg_rl,
8299 l_ele_rqd_flag,
8300 l_one_ann_pymt_cd,
8301 l_entr_ann_val_flag,
8302 l_ele_entry_val_cd;
8303 if get_abr_info%notfound then
8304 close get_abr_info;
8305 if g_debug then
8306 hr_utility.set_location('BEN_91723_NO_ENRT_RT_ABR_FOUND',40);
8307 end if;
8308 fnd_message.set_name('BEN','BEN_91723_NO_ENRT_RT_ABR_FOUND');
8309 fnd_message.set_token('PROC',l_proc);
8310 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
8311 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
8312 fnd_message.raise_error;
8313 end if;
8314 close get_abr_info;
8315 l_rt_end_dt := p_rt_end_date;
8316
8317 --
8318 -- ZAP the element entries
8319 --
8320 if g_debug then
8321 hr_utility.set_location('ZAP mode',10);
8322 end if;
8323
8324 py_element_entry_api.delete_element_entry
8325 (p_validate => p_validate
8326 ,p_datetrack_delete_mode => hr_api.g_zap
8327 ,p_effective_date => p_rt_strt_date
8328 ,p_element_entry_id => p_element_entry_id
8329 ,p_object_version_number => l_object_version_number
8330 ,p_effective_start_date => l_effective_start_date -- out parm
8331 ,p_effective_end_date => l_effective_end_date -- out parm
8332 ,p_delete_warning => l_delete_warning
8333 );
8334 -- write to the change event log
8335 --
8336 ben_ext_chlg.log_element_chg(
8337 p_action => hr_api.g_zap,
8338 p_old_amt => p_amt,
8339 p_input_value_id => p_input_value_id,
8340 p_element_entry_id => p_element_entry_id,
8341 p_person_id => p_person_id,
8342 p_business_group_id => p_business_group_id,
8343 p_effective_date => p_rt_strt_date);
8344 --
8345 -- recreate the element
8346 --
8347 get_extra_ele_inputs
8348 (p_effective_date => p_effective_date
8349 ,p_person_id => p_person_id
8350 ,p_business_group_id => p_business_group_id
8351 ,p_assignment_id => l_assignment_id
8352 ,p_element_link_id => p_element_link_id
8353 ,p_entry_type => 'E'
8354 ,p_input_value_id1 => p_input_value_id
8355 ,p_entry_value1 => p_amt
8356 ,p_element_entry_id => p_element_entry_id
8357 ,p_acty_base_rt_id => p_acty_base_rt_id
8358 ,p_input_va_calc_rl => p_input_va_calc_rl
8359 ,p_abs_ler => p_abs_ler
8360 ,p_organization_id => l_organization_id
8361 ,p_payroll_id => l_payroll_id
8362 ,p_pgm_id => g_result_rec.pgm_id
8363 ,p_pl_id => g_result_rec.pl_id
8364 ,p_pl_typ_id => g_result_rec.pl_typ_id
8365 ,p_opt_id => g_result_rec.opt_id
8366 ,p_ler_id => g_result_rec.ler_id
8367 ,p_dml_typ => 'C'
8368 ,p_jurisdiction_code => null
8369 ,p_ext_inpval_tab => g_ext_inpval_tab
8370 ,p_subpriority => l_subpriority
8371 );
8372
8373 if g_debug then
8374 hr_utility.set_location('Hits'||g_ext_inpval_tab.count,30);
8375 end if;
8376
8377 py_element_entry_api.create_element_entry
8378 (p_validate =>p_validate
8379 ,p_effective_date =>p_rt_strt_date
8380 ,p_business_group_id =>p_business_group_id
8381 ,p_assignment_id =>l_assignment_id
8382 ,p_element_link_id =>p_element_link_id
8383 ,p_entry_type =>'E'
8384 ,p_subpriority =>l_subpriority
8385 ,p_override_user_ent_chk =>'Y'
8386 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
8387 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
8388 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
8389 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
8390 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
8391 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
8392 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
8393 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
8394 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
8395 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
8396 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
8397 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
8398 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
8399 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
8400 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
8401 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
8402 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
8403 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
8404 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
8405 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
8406 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
8407 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
8408 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
8409 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
8410 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
8411 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
8412 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
8413 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
8414 ,p_input_value_id15 =>p_input_value_id
8415 ,p_entry_value15 =>p_amt
8416 ,p_effective_start_date =>l_effective_start_date
8417 ,p_effective_end_date =>l_effective_end_date
8418 ,p_element_entry_id =>l_element_entry_id
8419 ,p_object_version_number =>l_object_version_number
8420 ,p_create_warning =>l_create_warning
8421 );
8422
8423 py_element_entry_api.update_element_entry
8424 (p_validate =>p_validate
8425 ,p_datetrack_update_mode =>hr_api.g_correction
8426 ,p_effective_date =>p_rt_strt_date
8427 ,p_business_group_id =>p_business_group_id
8428 ,p_element_entry_id =>l_element_entry_id
8429 ,p_object_version_number =>l_object_version_number
8430 ,p_override_user_ent_chk =>'Y'
8431 ,p_creator_type =>'F'
8432 ,p_creator_id =>p_enrt_rslt_id
8433 ,p_effective_start_date =>l_effective_start_date
8434 ,p_effective_end_date =>l_effective_end_date
8435 ,p_update_warning =>l_update_warning
8436 );
8437
8438 if g_debug then
8439 hr_utility.set_location('Element entry Id '||l_element_entry_id,30);
8440 hr_utility.set_location('ee start date '||to_char(l_effective_start_date),30);
8441 hr_utility.set_location('ee end date '||to_char(l_effective_end_date),30);
8442 end if;
8443
8444 open get_created_entry_value(l_element_entry_id,p_input_value_id,
8445 p_rt_strt_date);
8446 --
8447 fetch get_created_entry_value into l_entry_value_id;
8448 --
8449 if get_created_entry_value%notfound then
8450 --
8451 if g_debug then
8452 hr_utility.set_location('no entry created',140);
8453 end if;
8454 close get_created_entry_value;
8455 --
8456 if g_debug then
8457 hr_utility.set_location('BEN_92102_NO_ENTRY_CREATED',140);
8458 end if;
8459 fnd_message.set_name('BEN', 'BEN_92102_NO_ENTRY_CREATED');
8460 fnd_message.set_token('PROC',l_proc);
8461 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_element_entry_id));
8462 fnd_message.set_token('INPUT_VALUE_ID',to_char(p_input_value_id));
8463 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_rt_strt_date));
8464 fnd_message.raise_error;
8465 --
8466 end if;
8467 close get_created_entry_value;
8468 if g_debug then
8469 hr_utility.set_location('Element entry value Id '||l_entry_value_id,30);
8470 end if;
8471
8472 open c_get_prtt_rt_val
8473 (c_prtt_rt_val_id => p_prtt_rt_val_id
8474 );
8475 fetch c_get_prtt_rt_val into l_prv_rec;
8476 if c_get_prtt_rt_val%notfound
8477 then
8478 --
8479 if g_debug then
8480 hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL',170);
8481 end if;
8482 close c_get_prtt_rt_val;
8483 --
8484 fnd_message.set_name('BEN', 'BEN_92103_NO_PRTT_RT_VAL');
8485 fnd_message.set_token('PROC',l_proc);
8486 fnd_message.set_token('PRTT_RT_VAL',to_char(p_prtt_rt_val_id));
8487 fnd_message.raise_error;
8488 --
8489 end if;
8490 close c_get_prtt_rt_val;
8491 --
8492 l_prv_object_version_number := l_prv_rec.object_version_number;
8493
8494 -- update the prv with the new element_entry_id
8495 --
8496 ben_prtt_rt_val_api.update_prtt_rt_val
8497 (p_validate => p_validate
8498 ,p_person_id => p_person_id
8499 ,p_prtt_rt_val_id => l_prv_rec.prtt_rt_val_id
8500 ,p_business_group_id => l_prv_rec.business_group_id
8501 ,p_element_entry_value_id => l_entry_value_id
8502 ,p_input_value_id => p_input_value_id
8503 ,p_object_version_number => l_prv_object_version_number
8504 ,p_effective_date => p_rt_strt_date
8505 );
8506 --
8507 if g_debug then
8508 hr_utility.set_location('rt end dt '||to_char(p_rt_end_date),30);
8509 end if;
8510 if (p_rt_end_date is not null)
8511 then
8512 -- end date the element entry
8513 -- bug 5768050
8514 OPEN c_ee_ovn (l_element_entry_id);
8515
8516 FETCH c_ee_ovn
8517 INTO l_ovn;
8518
8519 IF c_ee_ovn%FOUND
8520 THEN
8521 hr_utility.set_location ('ovn found ending element', 121);
8522 py_element_entry_api.delete_element_entry
8523 (p_validate => p_validate
8524 ,p_datetrack_delete_mode => hr_api.g_delete
8525 ,p_effective_date => p_rt_end_date
8526 ,p_element_entry_id => l_element_entry_id
8527 -- ,p_object_version_number => l_object_version_number
8528 ,p_object_version_number => l_ovn
8529 ,p_effective_start_date => l_effective_start_date -- out parm
8530 ,p_effective_end_date => l_effective_end_date -- out parm
8531 ,p_delete_warning => l_delete_warning
8532 );
8533 end if;
8534 close c_ee_ovn;
8535 -- end bug 5768050
8536 if g_debug then
8537 hr_utility.set_location('ee start date '||to_char(l_effective_start_date),30);
8538 end if;
8539 if g_debug then
8540 hr_utility.set_location('ee end date '||to_char(l_effective_end_date),30);
8541 end if;
8542 -- write to the change event log
8543 --
8544 ben_ext_chlg.log_element_chg(
8545 p_action => hr_api.g_delete,
8546 p_old_amt => p_amt,
8547 p_input_value_id => p_input_value_id,
8548 p_element_entry_id => p_element_entry_id,
8549 p_person_id => p_person_id,
8550 p_business_group_id => p_business_group_id,
8551 p_effective_date => p_effective_date);
8552 end if;
8553 if g_debug then
8554 hr_utility.set_location('Leaving :'||l_proc,5);
8555 end if;
8556 --
8557 end recreate_enrollment_element;
8558 -- ----------------------------------------------------------------------------
8559 -- |----------------------< end_enrollment_element >--------------------------|
8560 -- ----------------------------------------------------------------------------
8561 procedure end_enrollment_element(p_validate IN BOOLEAN
8562 ,p_business_group_id IN NUMBER
8563 ,p_person_id IN NUMBER
8564 ,p_enrt_rslt_id IN NUMBER
8565 ,p_acty_ref_perd in varchar2
8566 ,p_acty_base_rt_id in number
8567 ,p_element_link_id IN NUMBER
8568 ,p_prtt_rt_val_id in number
8569 ,p_rt_end_date IN DATE
8570 ,p_effective_date IN DATE
8571 ,p_dt_delete_mode IN VARCHAR2
8572 ,p_amt in number) is
8573 --
8574 -- Bug 2386380 fix - added default value to decode function
8575 --
8576 cursor c_pps_prev_month(p_end_date in date,
8577 p_prtl_mo_eff_dt_det_cd in varchar2,
8578 p_payroll_id in number) is
8579 select start_date,end_date
8580 from per_time_periods
8581 where payroll_id = p_payroll_id
8582 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
8583 'PPED',end_date,
8584 'DTERND',regular_payment_date,
8585 end_date)
8586 < p_end_date
8587 order by start_date desc;
8588 --
8589 -- Bug 2386380 fix - added default value to decode function
8590 --
8591 cursor c_get_current_pp(p_end_date in date
8592 ,p_prtl_mo_eff_dt_det_cd in varchar2
8593 ,p_payroll_id in number) is
8594 select start_date,end_date
8595 from per_time_periods
8596 where payroll_id = p_payroll_id
8597 and p_end_date between
8598 start_date
8599 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date
8600 ,'PPED',end_date
8601 ,'DTERND',regular_payment_date
8602 ,end_date);
8603 --
8604 -- Bug 2386380 fix - added default value to decode function
8605 --
8606 cursor c_last_pay_periods(p_start_date in date,
8607 p_end_date in date,
8608 p_prtl_mo_eff_dt_det_cd in varchar2,
8609 p_payroll_id in number) is
8610 select start_date,end_date
8611 from per_time_periods
8612 where payroll_id = p_payroll_id
8613 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
8614 'PPED',end_date,
8615 'DTERND',regular_payment_date,
8616 end_date)
8617 <= p_end_date
8618 and decode(p_prtl_mo_eff_dt_det_cd,'DTPD',regular_payment_date,
8619 'PPED',end_date,
8620 'DTERND',regular_payment_date,
8621 end_date)
8622 >= p_start_date
8623 order by start_date asc;
8624 --
8625 cursor get_abr_info(p_effective_date in date) is
8626 select abr.prtl_mo_det_mthd_cd,
8627 abr.prtl_mo_det_mthd_rl,
8628 abr.wsh_rl_dy_mo_num,
8629 abr.prtl_mo_eff_dt_det_cd,
8630 abr.prtl_mo_eff_dt_det_rl,
8631 abr.input_va_calc_rl,
8632 abr.rndg_cd,
8633 abr.rndg_rl,
8634 abr.rcrrg_cd,
8635 abr.ele_rqd_flag,
8636 abr.one_ann_pymt_cd,
8637 abr.entr_ann_val_flag,
8638 abr.ele_entry_val_cd,
8639 abr.name
8640 from ben_acty_base_rt_f abr
8641 where abr.acty_base_rt_id=p_acty_base_rt_id
8642 and abr.business_group_id=p_business_group_id
8643 and p_effective_date between
8644 abr.effective_start_date and abr.effective_end_date;
8645 --
8646 cursor c_ele_info(p_element_entry_value_id number) is
8647 select pel.element_link_id,
8648 pel.element_type_id,
8649 pev.input_value_id,
8650 pet.element_name,
8651 pet.processing_type
8652 from pay_element_types_f pet,
8653 pay_element_links_f pel,
8654 pay_element_entries_f pee,
8655 pay_element_entry_values_f pev
8656 where pev.element_entry_value_id = p_element_entry_value_id
8657 and pee.element_entry_id = pev.element_entry_id
8658 and pev.effective_start_date between pee.effective_start_date
8659 and pee.effective_end_date
8660 and pel.element_link_id = pee.element_link_id
8661 and pee.effective_start_date between pel.effective_start_date
8662 and pel.effective_end_date
8663 and pet.element_type_id = pel.element_type_id
8664 and pel.effective_start_date between pet.effective_start_date
8665 and pet.effective_end_date;
8666 --
8667 -- Get element entry ID
8668 --
8669 cursor get_element_entry_id (p_enrt_rslt_id in number
8670 ,p_element_type_id in number
8671 ,p_input_value_id in number
8672 ,p_element_entry_value_id in number
8673 ,p_effective_date in date)
8674 is
8675 select asg.assignment_id,
8676 asg.payroll_id,
8677 pee.element_entry_id,
8678 pee.effective_start_date,
8679 pee.effective_end_date,
8680 pee.object_version_number,
8681 pee.original_entry_id,
8682 pee.entry_type,
8683 pee.element_link_id,
8684 pev.screen_entry_value
8685 from per_all_assignments_f asg,
8686 pay_element_links_f pel,
8687 pay_element_entries_f pee,
8688 pay_element_entry_values_f pev
8689 where asg.person_id = p_person_id
8690 and pee.assignment_id = asg.assignment_id
8691 and p_effective_date between asg.effective_start_date
8692 and asg.effective_end_date
8693 and pee.creator_id = p_enrt_rslt_id
8694 and pee.creator_type = 'F'
8695 and pee.entry_type = 'E'
8696 and p_effective_date <= pee.effective_end_date
8697 and pel.element_link_id = pee.element_link_id
8698 and pee.effective_start_date between pel.effective_start_date
8699 and pel.effective_end_date
8700 and pel.element_type_id = p_element_type_id
8701 and pev.element_entry_id = pee.element_entry_id
8702 and pev.input_value_id = p_input_value_id
8703 and (p_element_entry_value_id is null or
8704 pev.element_entry_value_id = p_element_entry_value_id)
8705 and pev.effective_start_date between pee.effective_start_date
8706 and pee.effective_end_date
8707 order by pee.effective_start_date ;
8708
8709 cursor get_future_element_entry (p_enrt_rslt_id IN NUMBER
8710 ,p_assignment_id in number
8711 ,p_element_type_id in number
8712 ,p_effective_date in date) is
8713 select pee.element_entry_id,
8714 pee.effective_start_date,
8715 pee.effective_end_date,
8716 pee.object_version_number
8717 from pay_element_entries_f pee,
8718 pay_element_links_f pel
8719 where pee.assignment_id = p_assignment_id
8720 and pee.creator_id = p_enrt_rslt_id
8721 and pee.creator_type = 'F'
8722 and pee.entry_type = 'E'
8723 and pee.effective_start_date > p_effective_date
8724 and pel.element_link_id = pee.element_link_id
8725 and pee.effective_start_date between pel.effective_start_date
8726 and pel.effective_end_date
8727 and pel.element_type_id = p_element_type_id
8728 and pee.effective_start_date
8729 = (select min(pee2.effective_start_date)
8730 from pay_element_entries_f pee2
8731 where pee2.element_entry_id = pee.element_entry_id);
8732 l_future_ee_rec get_future_element_entry%rowtype;
8733
8734 /* Bug 7597154: Commented the existing cursor c_dup_prv
8735 --
8736 --Added prv.rt_strt_dt <=c_effective_date condition
8737 --to fix bug 6132571. To filter our rates that are
8738 --already processed.
8739 cursor c_dup_prv(c_element_entry_id number,
8740 c_effective_date date) is
8741 select 'x'
8742 from ben_prtt_rt_val prv
8743 where prv.prtt_enrt_rslt_id = p_enrt_rslt_id
8744 and prv.acty_base_rt_id <> p_acty_base_rt_id
8745 and prv.rt_end_dt > c_effective_date
8746 -- and prv.rt_strt_dt <=c_effective_date
8747 and prv.prtt_rt_val_stat_cd is null
8748 and prv.element_entry_value_id in
8749 (select pev.element_entry_value_id
8750 from pay_element_entry_values_f pev
8751 where pev.element_entry_id = c_element_entry_id);
8752 --
8753
8754 */
8755
8756 -- Bug 7597154: Modified cursor c_dup_prv
8757 cursor c_dup_prv(c_element_type_id number,
8758 c_effective_date date) is
8759 select 'x'
8760 from ben_prtt_rt_val prv
8761 where prv.prtt_enrt_rslt_id = p_enrt_rslt_id
8762 and prv.acty_base_rt_id <> p_acty_base_rt_id
8763 and prv.rt_end_dt > c_effective_date
8764 -- and prv.rt_strt_dt <=c_effective_date
8765 and prv.prtt_rt_val_stat_cd is null
8766 and prv.acty_base_rt_id in
8767 (select abr.acty_base_rt_id
8768 from ben_acty_base_rt_f abr
8769 where abr.acty_base_rt_id = prv.acty_base_rt_id
8770 and abr.element_type_id = c_element_type_id
8771 and c_effective_date between abr.effective_start_date
8772 and abr.effective_end_date);
8773
8774 -- Bug 7597154
8775
8776 -- Bug 9148303
8777
8778 cursor c_ass_type (c_assignment_id number,
8779 c_effective_date date) is
8780 select paa.primary_flag
8781 from per_all_assignments_f paa
8782 where paa.assignment_id = c_assignment_id
8783 and c_effective_date between paa.effective_start_date and paa.effective_end_date;
8784
8785 l_ass_type c_ass_type%rowtype;
8786
8787 -- Bug 9148303
8788
8789 cursor c_chk_abs_ler (c_prtt_rt_val_id number,
8790 c_effective_date date) is
8791 select pil.lf_evt_ocrd_dt,
8792 pil.trgr_table_pk_id,
8793 pil.per_in_ler_id,
8794 ler.ler_id
8795 from ben_prtt_rt_val prt,
8796 ben_per_in_ler pil,
8797 ben_ler_f ler
8798 where prt.prtt_rt_val_id = c_prtt_rt_val_id
8799 -- ended_per_in_ler_id may be null in case of back out
8800 and pil.per_in_ler_id = nvl(prt.ended_per_in_ler_id,prt.per_in_ler_id)
8801 and ler.ler_id = pil.ler_id
8802 and ler.typ_cd ='ABS'
8803 and c_effective_date between
8804 ler.effective_start_date and ler.effective_end_date;
8805 --
8806 cursor c_min_max_dt(p_element_entry_id number) is
8807 select min(effective_start_date),
8808 max(effective_end_date)
8809 from pay_element_entries_f
8810 where element_entry_id = p_element_entry_id;
8811 --
8812 cursor c_element_ovn(p_element_entry_id number,
8813 p_effective_date date) is
8814 select object_version_number
8815 from pay_element_entries_f pee
8816 where pee.element_entry_id = p_element_entry_id
8817 and p_effective_date between pee.effective_start_date
8818 and pee.effective_end_date;
8819
8820 --
8821 -- Bug 6834340
8822 -- to pass correct ler_id to the prorate_amount when subsequent life event
8823 -- offers no electability to the existing enrollments but rates get updated.
8824 --
8825
8826 cursor c_ler_with_ended_prv
8827 (p_prtt_rt_val_id in number
8828 , p_rt_end_date in date
8829 )
8830 is
8831 select ler.name name, ler.ler_id ler_id
8832 from ben_prtt_rt_val prv,
8833 ben_per_in_ler pil,
8834 ben_ler_f ler
8835 where prv.per_in_ler_id = pil.per_in_ler_id
8836 and pil.ler_id = ler.ler_id
8837 and prv.prtt_rt_val_id = p_prtt_rt_val_id
8838 and prv.rt_end_dt = p_rt_end_date;
8839
8840 l_ler_with_ended_prv c_ler_with_ended_prv%rowtype;
8841
8842 -- Bug 6834340
8843 --
8844 ---------Bug 7687104
8845 cursor c_chk_payroll_chg(p_rt_end_date date,p_payroll_id number)is
8846 select pay2.payroll_id old_payroll_id,pay.payroll_id new_payroll_id
8847 from per_all_assignments_f asg,
8848 pay_payrolls_f pay,
8849 per_all_assignments_f asg2,
8850 pay_payrolls_f pay2
8851 where asg.person_id = p_person_id
8852 and asg.business_group_id = p_business_group_id
8853 and asg.primary_flag = 'Y'
8854 and p_rt_end_date between
8855 asg.effective_start_date and asg.effective_end_date
8856 and pay.payroll_id=asg.payroll_id
8857 and pay.business_group_id = asg.business_group_id
8858 and p_rt_end_date between
8859 pay.effective_start_date and pay.effective_end_date
8860 AND asg.assignment_id <> asg2.assignment_id
8861 and asg2.person_id = p_person_id
8862 and asg2.business_group_id = p_business_group_id
8863 and asg2.primary_flag = 'Y'
8864 and p_rt_end_date between
8865 asg2.effective_start_date and asg2.effective_end_date
8866 and pay2.payroll_id=asg2.payroll_id
8867 and pay2.business_group_id = asg2.business_group_id
8868 and p_rt_end_date between
8869 pay2.effective_start_date and pay2.effective_end_date
8870 and pay2.payroll_id<>pay.payroll_id
8871 AND pay2.payroll_id = p_payroll_id ;
8872 l_chk_payroll_chg c_chk_payroll_chg%rowtype;
8873
8874 cursor c_days_in_pp(p_payroll_id number,p_rt_end_date date) is
8875 SELECT ((end_date - START_DATE) + 1)
8876 FROM per_time_periods
8877 WHERE payroll_id = p_payroll_id
8878 AND p_rt_end_date BETWEEN start_date AND end_date;
8879
8880 l_old_pp_days number;
8881 l_new_pp_days number;
8882
8883 cursor c_get_prev_ele(p_rt_end_date date) is
8884 SELECT pev.*
8885 FROM pay_element_entry_values_f pev,
8886 ben_prtt_rt_val prv
8887 WHERE prv.prtt_rt_val_id = p_prtt_rt_val_id
8888 AND prv.rt_end_dt = p_rt_end_date
8889 AND prv.element_entry_value_id = pev.element_entry_value_id
8890 and p_rt_end_date between pev.effective_start_date and pev.effective_end_date;
8891
8892 l_get_prev_ele c_get_prev_ele%rowtype;
8893 l_prev_entry_val number;
8894 --------Bug 7687104
8895 --------------------Bug 9235544
8896 cursor c_current_pil is
8897 select pil.*
8898 from ben_peR_in_ler pil,
8899 ben_ler_f ler
8900 where pil.procd_dt is null
8901 and pil.business_group_id = p_business_group_id
8902 and pil.person_id = p_person_id
8903 and pil.per_in_ler_stat_cd = 'STRTD'
8904 and pil.ler_id = ler.ler_id
8905 and ler.typ_cd not in ('IREC','GSP','COMP','ABS','SCHEDDU')
8906 and ler.business_group_id = p_business_group_id
8907 order by pil.lf_evt_ocrd_dt desc;
8908
8909 l_current_pil c_current_pil%rowtype;
8910
8911 cursor c_check_current_pen(p_pil_id number) is
8912 select *
8913 from ben_prtt_enrt_rslt_f pen
8914 where pen.prtt_enrt_rslt_id = p_enrt_rslt_id
8915 and pen.business_group_id = p_business_group_id
8916 and pen.person_id = p_person_id
8917 and pen.prtt_enrt_rslt_stat_cd is null
8918 and pen.per_in_ler_id = p_pil_id
8919 and pen.effective_end_Date = hr_api.g_eot
8920 and pen.enrt_cvg_thru_dt = hr_api.g_eot;
8921
8922 l_check_current_pen c_check_current_pen%rowtype;
8923 --------------------Bug 9235544
8924 --
8925 --
8926 l_per_month_amt number;
8927 l_assignment_id NUMBER;
8928 l_payroll_id NUMBER;
8929 l_element_entry_id NUMBER;
8930 l_ext_chg_evt_log_id NUMBER;
8931 l_input_value_id NUMBER;
8932 l_abr_input_value_id NUMBER;
8933 l_object_version_number NUMBER;
8934 l_ext_object_version_number NUMBER;
8935 l_effective_start_date DATE;
8936 l_effective_end_date DATE;
8937 l_rt_end_dt DATE := p_rt_end_date;
8938 l_delete_warning BOOLEAN;
8939 l_proc VARCHAR2(72) := g_package||'end_enrollment_element';
8940 l_organization_id number;
8941 l_immediate_end boolean:=false;
8942 l_prtl_mo_det_mthd_cd varchar2(30);
8943 l_prtl_mo_det_mthd_rl number;
8944 l_wsh_rl_dy_mo_num number;
8945 l_prtl_mo_eff_dt_det_cd varchar2(30);
8946 l_prtl_mo_eff_dt_det_rl number;
8947 l_per_pay_amt number;
8948 l_prorated_monthly_amt number;
8949 l_amt number;
8950 l_prtn_flag varchar2(1);
8951 l_element_type_id number;
8952 l_abr_element_type_id number;
8953 l_outputs ff_exec.outputs_t;
8954 l_remainder number;
8955 l_number_in_month number;
8956 l_old_normal_pp_date date;
8957 l_normal_pp_date date;
8958 l_special_pp_date date;
8959 l_old_normal_pp_end_date date;
8960 l_normal_pp_end_date date;
8961 l_special_pp_end_date date;
8962 l_zero_pp_date date default null;
8963 l_dt_to_use date;
8964 l_special_amt number;
8965 l_element_link_id number;
8966 l_start_date date;
8967 l_end_date date;
8968 l_update_ee boolean;
8969 l_curr_val number;
8970 l_new_date date;
8971 l_end_of_time date;
8972 l_create_warning BOOLEAN;
8973 l_update_warning BOOLEAN;
8974 l_jurisdiction_code varchar2(30);
8975 l_abr_rndg_cd varchar2(30);
8976 l_abr_rndg_rl number;
8977 l_ele_rqd_flag varchar2(30);
8978 l_one_ann_pymt_cd varchar2(30);
8979 l_entr_ann_val_flag varchar2(30);
8980 l_ele_entry_val_cd varchar2(30);
8981 l_last_pp_strt_dt date;
8982 l_last_pp_end_dt date;
8983 l_range_start date;
8984 l_dt_delete_mode varchar2(80);
8985 l_cnt number;
8986 l_absence_attendance_id number;
8987 l_per_in_ler_id number;
8988 l_ler_id number;
8989 l_input_va_calc_rl number;
8990 l_subpriority number;
8991 l_original_entry_id number;
8992 l_entry_type varchar2(30);
8993 l_processing_type varchar2(30);
8994 l_lf_evt_ocrd_dt date;
8995 l_abs_ler boolean := false;
8996 l_recreate boolean := false;
8997 l_ele_processed varchar2(1);
8998 l_err_code varchar2(10);
8999 l_err_mesg varchar2(2000);
9000 l_dummy varchar2(30);
9001 l_curr_val_char varchar2 (60);
9002 l_uom varchar2(30);
9003 l_correction boolean;
9004 l_update boolean;
9005 l_update_override boolean;
9006 l_update_change_insert boolean;
9007 l_dt_upd_mode varchar2(30);
9008 l_element_entry_start_date date;
9009 l_element_entry_end_date date;
9010 l_string varchar2(4000);
9011 l_abr_name varchar2(240); -- 2519349
9012 l_effective_date date;
9013 l_rt_strt_dt date;
9014 l_perd_cd varchar2(30) := 'PP';
9015 l_element_name varchar2(80);
9016 l_object_version_number2 number;
9017 l_another_prv_exists boolean := false;
9018 l_min_start_date date;
9019 l_max_end_date date;
9020 l_non_recurring_entry boolean := false;
9021 l_abr_rcrrg_cd varchar2(30);
9022 l_element_entry_value_id number;
9023 l_v2dummy varchar2(30);
9024 --
9025 begin
9026 g_debug := hr_utility.debug_enabled;
9027 if g_debug then
9028 hr_utility.set_location('Entering :'||l_proc,5);
9029 hr_utility.set_location('Element_link_id='||to_char(p_element_link_id),6);
9030 hr_utility.set_location('Effective_date='||to_char(p_effective_date),6);
9031 hr_utility.set_location('p_prtt_rt_val_id='||p_prtt_rt_val_id,6);
9032 hr_utility.set_location('p_enrt_rslt_id='||p_enrt_rslt_id,6);
9033 hr_utility.set_location('p_rt_end_date='||to_char(p_rt_end_date),6);
9034 end if;
9035 --
9036 --BUG 3167959 We need to intialize the pl/sql table
9037 clear_ext_inpval_tab ;
9038 --
9039 -- get prv info
9040 --
9041 open c_get_prtt_rt_val
9042 (c_prtt_rt_val_id => p_prtt_rt_val_id
9043 );
9044 fetch c_get_prtt_rt_val into l_prv_rec;
9045 if c_get_prtt_rt_val%notfound
9046 then
9047 --
9048 if g_debug then
9049 hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL',170);
9050 end if;
9051 close c_get_prtt_rt_val;
9052 --
9053 fnd_message.set_name('BEN', 'BEN_92103_NO_PRTT_RT_VAL');
9054 fnd_message.set_token('PROC',l_proc);
9055 fnd_message.set_token('PRTT_RT_VAL',to_char(p_prtt_rt_val_id));
9056 fnd_message.raise_error;
9057 --
9058 end if;
9059 close c_get_prtt_rt_val;
9060 --
9061 -- if no element entry was created to start with, return
9062 --
9063 if l_prv_rec.element_entry_value_id is null then
9064 hr_utility.set_location('no element entry '||l_proc,7);
9065 hr_utility.set_location('Leaving: '||l_proc,7);
9066 return;
9067 end if;
9068 --
9069 -- find the element type and input value based on element_entry_value_id
9070 -- attached to prtt rt.
9071 --
9072 open c_ele_info(l_prv_rec.element_entry_value_id);
9073 fetch c_ele_info into
9074 l_element_link_id,
9075 l_element_type_id,
9076 l_input_value_id,
9077 l_element_name,
9078 l_processing_type;
9079 --
9080 if c_ele_info%notfound then
9081 close c_ele_info;
9082 if g_debug then
9083 --
9084 -- entry_value_id attached to prtt rt does not exist. This is possible
9085 -- prior to FP C when ct. could delete the entries
9086 --
9087 hr_utility.set_location('Leaving: '||l_proc,7);
9088 end if;
9089 return;
9090 end if;
9091 close c_ele_info;
9092 --
9093 -- This is for the case when prtt rt is ended one day before start dt
9094 --
9095 l_effective_date := greatest(l_prv_rec.rt_strt_dt,l_rt_end_dt);
9096
9097 if g_debug then
9098 hr_utility.set_location('ele type='||l_element_type_id,7);
9099 hr_utility.set_location('inp val='||l_input_value_id,7);
9100 hr_utility.set_location('l_effective_date='||l_effective_date,7);
9101 end if;
9102 --
9103 -- get abr info
9104 --
9105 open get_abr_info(l_effective_date);
9106 fetch get_abr_info into l_prtl_mo_det_mthd_cd,
9107 l_prtl_mo_det_mthd_rl,
9108 l_wsh_rl_dy_mo_num,
9109 l_prtl_mo_eff_dt_det_cd,
9110 l_prtl_mo_eff_dt_det_rl,
9111 l_input_va_calc_rl,
9112 l_abr_rndg_cd,
9113 l_abr_rndg_rl,
9114 l_abr_rcrrg_cd,
9115 l_ele_rqd_flag,
9116 l_one_ann_pymt_cd,
9117 l_entr_ann_val_flag,
9118 l_ele_entry_val_cd,
9119 l_abr_name;
9120 if get_abr_info%notfound then
9121 close get_abr_info;
9122 if g_debug then
9123 hr_utility.set_location('BEN_91723_NO_ENRT_RT_ABR_FOUND',40);
9124 end if;
9125 fnd_message.set_name('BEN','BEN_91723_NO_ENRT_RT_ABR_FOUND');
9126 fnd_message.set_token('PROC',l_proc);
9127 fnd_message.set_token('ACTY_BASE_RT_ID',to_char(p_acty_base_rt_id));
9128 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
9129 fnd_message.raise_error;
9130 end if;
9131 close get_abr_info;
9132
9133 hr_utility.set_location('l_abr_rcrrg_cd '||l_abr_rcrrg_cd,40);
9134 hr_utility.set_location('l_processing_type '||l_processing_type,40);
9135 l_non_recurring_entry := ((l_abr_rcrrg_cd = 'ONCE') or (l_processing_type='N'));
9136 if l_non_recurring_entry then
9137 l_element_entry_value_id := l_prv_rec.element_entry_value_id;
9138 end if;
9139 hr_utility.set_location('l_element_entry_value_id '||l_element_entry_value_id,40);
9140
9141 --
9142 -- find the element entry that needs to be deleted.
9143 -- This could be different from what is attached to prtt rt
9144 --
9145 open get_element_entry_id(p_enrt_rslt_id
9146 ,l_element_type_id
9147 ,l_input_value_id
9148 ,l_element_entry_value_id
9149 ,l_effective_date);
9150 fetch get_element_entry_id into
9151 l_assignment_id,
9152 l_payroll_id,
9153 l_element_entry_id,
9154 l_element_entry_start_date,
9155 l_element_entry_end_date,
9156 l_object_version_number,
9157 l_original_entry_id,
9158 l_entry_type,
9159 l_element_link_id,
9160 l_curr_val_char;
9161 --
9162 if get_element_entry_id%notfound then
9163 close get_element_entry_id;
9164 if g_debug then
9165 -- element entry already ended.
9166 hr_utility.set_location('element entry already ended',8);
9167 hr_utility.set_location('Leaving: '||l_proc,7);
9168 end if;
9169
9170 --
9171 ben_warnings.load_warning
9172 (p_application_short_name => 'BEN',
9173 p_message_name => 'BEN_93455_ELE_ALREADY_ENDED',
9174 p_parma => l_element_name,
9175 p_parmb => to_char(l_effective_date),
9176 p_person_id => p_person_id);
9177 --
9178 if fnd_global.conc_request_id in ( 0,-1) then
9179 --
9180 fnd_message.set_name('BEN','BEN_93455_ELE_ALREADY_ENDED');
9181 fnd_message.set_token('PARMA',l_element_name);
9182 fnd_message.set_token('PARMB',to_char(l_effective_date));
9183 l_string := fnd_message.get;
9184 benutils.write(p_text => l_string);
9185 --
9186 end if;
9187 --
9188 return;
9189 --
9190 end if;
9191 close get_element_entry_id;
9192
9193 if g_debug then
9194 hr_utility.set_location('ee id='||l_element_entry_id,9);
9195 hr_utility.set_location('ee strtdt ='||l_element_entry_start_date,9);
9196 hr_utility.set_location('ee end dt='||l_element_entry_end_date,9);
9197 hr_utility.set_location('l_ovn='||l_object_version_number,9);
9198 hr_utility.set_location('l_payroll_id='||l_payroll_id,9);
9199 hr_utility.set_location('l_assignment_id='||l_assignment_id,9);
9200 end if;
9201 --
9202 -- get prtt enrt rslt info
9203 --
9204 if nvl(g_result_rec.prtt_enrt_rslt_id,-1)<>p_enrt_rslt_id then
9205 open c_current_result_info
9206 (c_prtt_enrt_rslt_id => p_enrt_rslt_id
9207 );
9208 fetch c_current_result_info into g_result_rec;
9209 close c_current_result_info;
9210 end if;
9211 --
9212 -- check if abs ler
9213 --
9214 open c_chk_abs_ler
9215 (c_prtt_rt_val_id => p_prtt_rt_val_id
9216 ,c_effective_date => l_effective_date
9217 );
9218 fetch c_chk_abs_ler into
9219 l_lf_evt_ocrd_dt,
9220 l_absence_attendance_id,
9221 l_per_in_ler_id,
9222 l_ler_id;
9223 l_abs_ler := c_chk_abs_ler%found;
9224 close c_chk_abs_ler;
9225 --
9226 -- Get the latest payroll run date
9227 --
9228 g_max_end_date := null;
9229 --
9230 --Bug 3151737and 3063518 if there is no payroll_id on assignment means
9231 --customer might not be using the payroll so we don't need to determine
9232 --the g_max_end_date .
9233 --
9234 if l_payroll_id is not null then
9235 --
9236 if nvl(g_per_pay_rec.assignment_id,-1) <> l_assignment_id then
9237 --
9238 open c_payroll_was_ever_run
9239 (c_assignment_id => l_assignment_id
9240 );
9241 fetch c_payroll_was_ever_run into l_v2dummy;
9242 g_per_pay_rec.assignment_id := l_assignment_id;
9243 g_per_pay_rec.payroll_was_ever_run := c_payroll_was_ever_run%found;
9244 close c_payroll_was_ever_run;
9245 --
9246 end if;
9247 --
9248 if g_per_pay_rec.payroll_was_ever_run and
9249 g_per_pay_rec.end_date is null then
9250 --
9251 g_max_end_date :=
9252 get_max_end_dt (
9253 p_assignment_id => l_assignment_id,
9254 p_payroll_id => l_payroll_id,
9255 p_element_type_id => l_element_type_id,
9256 p_effective_date => l_effective_date);
9257 --
9258 g_per_pay_rec.end_date := g_max_end_date;
9259 --
9260 elsif g_per_pay_rec.end_date is not null then
9261 g_max_end_date := g_per_pay_rec.end_date;
9262 end if;
9263 --
9264 end if;
9265 --
9266 if g_debug then
9267 hr_utility.set_location('g_max_end_date='||g_max_end_date,10);
9268 end if;
9269 --
9270 -- If the entry has already been processed in the pay period
9271 -- in which it is going to be ended, show a warning
9272 --
9273 if not (l_abs_ler) and
9274 g_max_end_date is not null and
9275 g_max_end_date > l_rt_end_dt
9276 then
9277 if (g_msg_displayed <>1)
9278 -- added for bug: 5607214
9279 or fnd_global.conc_request_id not in ( 0,-1)
9280 then
9281 --l_immediate_end:=true;
9282 -- Issue a warning to the user. These will display on the enrt forms.
9283 ben_warnings.load_warning
9284 (p_application_short_name => 'BEN',
9285 p_message_name => 'BEN_92456_END_RUN_RESULTS',
9286 p_parma => fnd_date.date_to_chardate(g_max_end_date),
9287 p_person_id => p_person_id);
9288
9289 if fnd_global.conc_request_id not in ( 0,-1) then
9290 --
9291 fnd_message.set_name('BEN','BEN_92456_END_RUN_RESULTS');
9292 fnd_message.set_token('PARMA',fnd_date.date_to_chardate(g_max_end_date,calendar_aware=>2));
9293 l_string := fnd_message.get;
9294 benutils.write(p_text => l_string);
9295 --
9296 end if;
9297 g_msg_displayed :=1;
9298 end if;
9299 --
9300 -- cache quickpay run entries
9301 --
9302 cache_quick_pay_run
9303 (p_person_id => p_person_id,
9304 p_element_type_id => l_element_type_id,
9305 p_assignment_id => l_assignment_id,
9306 p_element_entry_id => l_element_entry_id,
9307 p_effective_date => l_rt_end_dt + 1,
9308 p_start_date => l_rt_end_dt + 1,
9309 p_end_date => g_max_end_date,
9310 p_payroll_id => l_payroll_id);
9311 end if;
9312 --
9313 -- Determine dt track mode.
9314 --
9315 open c_min_max_dt(l_element_entry_id);
9316 fetch c_min_max_dt into l_min_start_date,l_max_end_date;
9317 close c_min_max_dt;
9318
9319 if l_rt_end_dt < l_min_start_date then
9320 l_dt_delete_mode := hr_api.g_zap;
9321 elsif l_rt_end_dt < l_max_end_date then
9322 l_dt_delete_mode := hr_api.g_delete;
9323 end if;
9324
9325 /*Bug 12382133: If the element type is Non recurring, ZAP the element*/
9326 if l_non_recurring_entry then
9327 l_dt_delete_mode := hr_api.g_zap;
9328 end if;
9329 hr_utility.set_location('l_dt_delete_mode ' || l_dt_delete_mode,1200);
9330 --
9331 -- if the entry is to be ended on l_rt_end_dt (or)
9332 -- has already been ended on l_rt_end_dt, then update the extra input vales
9333 --
9334 if l_rt_end_dt >= l_element_entry_start_date and
9335 l_rt_end_dt <= l_max_end_date then
9336 get_extra_ele_inputs
9337 (p_effective_date => p_effective_date
9338 ,p_person_id => p_person_id
9339 ,p_business_group_id => p_business_group_id
9340 ,p_assignment_id => l_assignment_id
9341 ,p_element_link_id => l_element_link_id
9342 ,p_entry_type => 'E'
9343 ,p_input_value_id1 => l_input_value_id
9344 ,p_entry_value1 => l_curr_val_char
9345 ,p_element_entry_id => l_element_entry_id
9346 ,p_acty_base_rt_id => p_acty_base_rt_id
9347 ,p_input_va_calc_rl => l_input_va_calc_rl
9348 ,p_abs_ler => l_abs_ler
9349 ,p_organization_id => l_organization_id
9350 ,p_payroll_id => l_payroll_id
9351 ,p_pgm_id => g_result_rec.pgm_id
9352 ,p_pl_id => g_result_rec.pl_id
9353 ,p_pl_typ_id => g_result_rec.pl_typ_id
9354 ,p_opt_id => g_result_rec.opt_id
9355 ,p_ler_id => l_ler_id
9356 ,p_dml_typ => 'U'
9357 ,p_jurisdiction_code => l_jurisdiction_code
9358 ,p_ext_inpval_tab => g_ext_inpval_tab
9359 ,p_subpriority => l_subpriority
9360 );
9361
9362 if g_ext_inpval_tab.count > 0 and
9363 /* Bug 3890546: When previous payroll periods are closed,
9364 the below update_element_entry errors out. So, restricting this call
9365 to only when atleast one extra input_value_id NOT NULL */
9366 ( g_ext_inpval_tab(1).input_value_id IS NOT NULL
9367 OR g_ext_inpval_tab(2).input_value_id IS NOT NULL
9368 OR g_ext_inpval_tab(3).input_value_id IS NOT NULL
9369 OR g_ext_inpval_tab(4).input_value_id IS NOT NULL
9370 OR g_ext_inpval_tab(5).input_value_id IS NOT NULL
9371 OR g_ext_inpval_tab(6).input_value_id IS NOT NULL
9372 OR g_ext_inpval_tab(7).input_value_id IS NOT NULL
9373 OR g_ext_inpval_tab(8).input_value_id IS NOT NULL
9374 OR g_ext_inpval_tab(9).input_value_id IS NOT NULL
9375 OR g_ext_inpval_tab(10).input_value_id IS NOT NULL
9376 OR g_ext_inpval_tab(11).input_value_id IS NOT NULL
9377 OR g_ext_inpval_tab(12).input_value_id IS NOT NULL
9378 OR g_ext_inpval_tab(13).input_value_id IS NOT NULL
9379 OR g_ext_inpval_tab(14).input_value_id IS NOT NULL)
9380 then
9381 pay_element_entry_api.update_element_entry
9382 (p_validate =>p_validate
9383 ,p_datetrack_update_mode =>hr_api.g_correction
9384 ,p_effective_date =>l_element_entry_start_date
9385 ,p_business_group_id =>p_business_group_id
9386 ,p_element_entry_id =>l_element_entry_id
9387 ,p_object_version_number =>l_object_version_number
9388 ,p_subpriority =>l_subpriority
9389 ,p_override_user_ent_chk =>'Y'
9390 ,p_input_value_id1 =>g_ext_inpval_tab(1).input_value_id
9391 ,p_entry_value1 =>g_ext_inpval_tab(1).return_value
9392 ,p_input_value_id2 =>g_ext_inpval_tab(2).input_value_id
9393 ,p_entry_value2 =>g_ext_inpval_tab(2).return_value
9394 ,p_input_value_id3 =>g_ext_inpval_tab(3).input_value_id
9395 ,p_entry_value3 =>g_ext_inpval_tab(3).return_value
9396 ,p_input_value_id4 =>g_ext_inpval_tab(4).input_value_id
9397 ,p_entry_value4 =>g_ext_inpval_tab(4).return_value
9398 ,p_input_value_id5 =>g_ext_inpval_tab(5).input_value_id
9399 ,p_entry_value5 =>g_ext_inpval_tab(5).return_value
9400 ,p_input_value_id6 =>g_ext_inpval_tab(6).input_value_id
9401 ,p_entry_value6 =>g_ext_inpval_tab(6).return_value
9402 ,p_input_value_id7 =>g_ext_inpval_tab(7).input_value_id
9403 ,p_entry_value7 =>g_ext_inpval_tab(7).return_value
9404 ,p_input_value_id8 =>g_ext_inpval_tab(8).input_value_id
9405 ,p_entry_value8 =>g_ext_inpval_tab(8).return_value
9406 ,p_input_value_id9 =>g_ext_inpval_tab(9).input_value_id
9407 ,p_entry_value9 =>g_ext_inpval_tab(9).return_value
9408 ,p_input_value_id10 =>g_ext_inpval_tab(10).input_value_id
9409 ,p_entry_value10 =>g_ext_inpval_tab(10).return_value
9410 ,p_input_value_id11 =>g_ext_inpval_tab(11).input_value_id
9411 ,p_entry_value11 =>g_ext_inpval_tab(11).return_value
9412 ,p_input_value_id12 =>g_ext_inpval_tab(12).input_value_id
9413 ,p_entry_value12 =>g_ext_inpval_tab(12).return_value
9414 ,p_input_value_id13 =>g_ext_inpval_tab(13).input_value_id
9415 ,p_entry_value13 =>g_ext_inpval_tab(13).return_value
9416 ,p_input_value_id14 =>g_ext_inpval_tab(14).input_value_id
9417 ,p_entry_value14 =>g_ext_inpval_tab(14).return_value
9418 ,p_effective_start_date =>l_effective_start_date
9419 ,p_effective_end_date =>l_effective_end_date
9420 ,p_update_warning =>l_update_warning
9421 );
9422 end if;
9423
9424 if l_abs_ler then
9425 pqp_absence_plan_process.update_absence_plan_details
9426 (p_person_id => p_person_id
9427 ,p_assignment_id => l_assignment_id
9428 ,p_business_group_id => p_business_group_id
9429 ,p_legislation_code => get_legislation_code(p_business_group_id)
9430 ,p_effective_date => p_effective_date
9431 ,p_element_type_id => l_element_type_id
9432 ,p_pl_id => g_result_rec.pl_id
9433 ,p_pl_typ_id => g_result_rec.pl_typ_id
9434 ,p_ler_id => l_ler_id
9435 ,p_per_in_ler_id => l_per_in_ler_id
9436 ,p_absence_attendance_id => l_absence_attendance_id
9437 ,p_effective_start_date => l_effective_start_date
9438 ,p_effective_end_date => l_effective_end_date
9439 ,p_formula_outputs => g_outputs
9440 ,p_error_code => l_err_code
9441 ,p_error_message => l_err_mesg
9442 );
9443 end if;
9444
9445 end if;
9446
9447 if l_abs_ler and
9448 l_dt_delete_mode = hr_api.g_delete then
9449 --
9450 -- ABSENCES: ZAP and recreate the element entry if the absence
9451 -- was processed in a payroll and is currently end dated in a
9452 -- period for which payroll has already been run.
9453 --
9454 -- This needs to be eventually merged with c_get_end_dt cursor
9455 --
9456 l_ele_processed := chk_ele_processed
9457 (p_element_entry_id => l_element_entry_id
9458 ,p_original_entry_id=> l_original_entry_id
9459 ,p_processing_type => l_processing_type
9460 ,p_entry_type => l_entry_type
9461 ,p_business_group_id => p_business_group_id
9462 ,p_effective_date => p_effective_date);
9463
9464 if l_ele_processed = 'Y' and
9465 l_lf_evt_ocrd_dt < g_max_end_date then
9466 l_recreate := true;
9467 end if;
9468
9469 end if;
9470 --
9471 --Check if entry is used by another prv. This info is used further down
9472 --
9473 hr_utility.set_location('l_rt_end_dt '||l_rt_end_dt,1100);
9474 open c_dup_prv(l_element_type_id,
9475 l_rt_end_dt);
9476 fetch c_dup_prv into l_dummy;
9477 l_another_prv_exists := c_dup_prv%found;
9478 close c_dup_prv;
9479 --
9480 -- Delete the element entries
9481 --
9482 if (l_recreate) then
9483 --
9484 -- this part is called only in case of Absence processing
9485 --
9486 recreate_enrollment_element
9487 (p_validate => false
9488 ,p_business_group_id => p_business_group_id
9489 ,p_person_id => p_person_id
9490 ,p_enrt_rslt_id => p_enrt_rslt_id
9491 ,p_acty_ref_perd => p_acty_ref_perd
9492 ,p_acty_base_rt_id => p_acty_base_rt_id
9493 ,p_element_entry_id => l_element_entry_id
9494 ,p_element_link_id => l_element_link_id
9495 ,p_input_value_id => l_input_value_id
9496 ,p_prtt_rt_val_id => p_prtt_rt_val_id
9497 ,p_input_va_calc_rl => l_input_va_calc_rl
9498 ,p_abs_ler => l_abs_ler
9499 ,p_rt_strt_date => l_element_entry_start_date
9500 ,p_rt_end_date => l_rt_end_dt
9501 ,p_effective_date => p_effective_date
9502 ,p_amt =>l_curr_val_char
9503 ,p_object_version_number => l_object_version_number);
9504
9505 pqp_absence_plan_process.update_absence_plan_details
9506 (p_person_id => p_person_id
9507 ,p_assignment_id => l_assignment_id
9508 ,p_business_group_id => p_business_group_id
9509 ,p_legislation_code => get_legislation_code(p_business_group_id)
9510 ,p_effective_date => p_effective_date
9511 ,p_element_type_id => l_element_type_id
9512 ,p_pl_id => g_result_rec.pl_id
9513 ,p_pl_typ_id => g_result_rec.pl_typ_id
9514 ,p_ler_id => l_ler_id
9515 ,p_per_in_ler_id => l_per_in_ler_id
9516 ,p_absence_attendance_id => l_absence_attendance_id
9517 ,p_effective_start_date => l_effective_start_date
9518 ,p_effective_end_date => l_rt_end_dt
9519 ,p_formula_outputs => g_outputs
9520 ,p_error_code => l_err_code
9521 ,p_error_message => l_err_mesg
9522 );
9523
9524 elsif l_dt_delete_mode = hr_api.g_zap then
9525 if g_debug then
9526 hr_utility.set_location('ZAP mode',11);
9527 end if;
9528 /*
9529 Before :-
9530 02-JAN-1994 05-FEB-1994
9531 |-A--------------|-B--------------------------------------->
9532 ED
9533
9534 After :-
9535
9536 */
9537 py_element_entry_api.delete_element_entry
9538 (p_validate => p_validate
9539 ,p_datetrack_delete_mode => hr_api.g_zap
9540 ,p_effective_date => l_element_entry_start_date
9541 ,p_element_entry_id => l_element_entry_id
9542 ,p_object_version_number => l_object_version_number
9543 ,p_effective_start_date => l_effective_start_date
9544 ,p_effective_end_date => l_effective_end_date
9545 ,p_delete_warning => l_delete_warning
9546 );
9547 -- write to the change event log
9548 --
9549
9550 ben_ext_chlg.log_element_chg(
9551 p_action => 'DELETE',
9552 p_old_amt => fnd_number.canonical_to_number(l_curr_val_char),
9553 p_input_value_id => l_input_value_id,
9554 p_element_entry_id => l_element_entry_id,
9555 p_person_id => p_person_id,
9556 p_business_group_id => p_business_group_id,
9557 p_effective_date => p_effective_date);
9558 --
9559 if l_abs_ler then
9560 pqp_absence_plan_process.delete_absence_plan_details
9561 (p_assignment_id => l_assignment_id
9562 ,p_business_group_id => p_business_group_id
9563 ,p_legislation_code => get_legislation_code(p_business_group_id)
9564 ,p_effective_date => p_effective_date
9565 ,p_pl_id => g_result_rec.pl_id
9566 ,p_pl_typ_id => g_result_rec.pl_typ_id
9567 ,p_ler_id => l_ler_id
9568 ,p_per_in_ler_id => l_per_in_ler_id
9569 ,p_absence_attendance_id => l_absence_attendance_id
9570 ,p_effective_start_date => l_effective_start_date
9571 ,p_effective_end_date => l_effective_end_date
9572 ,p_formula_outputs => g_outputs
9573 ,p_error_code => l_err_code
9574 ,p_error_message => l_err_mesg
9575 );
9576 end if;
9577
9578 elsif l_dt_delete_mode = hr_api.g_delete then
9579 if g_debug then
9580 hr_utility.set_location('DELETE mode',11);
9581 end if;
9582 --
9583 -- End date as of the pre-calculated rate end date.
9584 --
9585 if g_debug then
9586 hr_utility.set_location('pre-calc rate end date',12);
9587 end if;
9588 /*
9589 Before :-
9590 02-JAN-1994 05-FEB-1994
9591 |-A--------------|-B--------------------------------------->
9592 ED
9593
9594 After :-
9595 02-JAN-1994 05-FEB-1994 15-JUL-1994
9596 |-A--------------|-B-------------------|
9597 ED
9598
9599 */
9600 if l_immediate_end=false then
9601 --
9602 -- Annualize the rate
9603 --
9604 if g_debug then
9605 hr_utility.set_location('prv_id= '|| p_prtt_rt_val_id,10);
9606 hr_utility.set_location('payroll= '|| l_payroll_id,10);
9607 hr_utility.set_location('bg= '|| p_business_group_id,10);
9608 hr_utility.set_location('rt_end= '|| l_rt_end_dt,10);
9609 hr_utility.set_location('effective_date= '|| p_effective_date,10);
9610 end if;
9611 --
9612 -- ELE : By pass if the ele_entry_val_cd <> PP , EPP or null.
9613 --
9614 if nvl(l_ele_entry_val_cd, 'PP') = 'PP' or
9615 l_ele_entry_val_cd = 'EPP' then
9616 --
9617 open c_plan_year_end_for_pen
9618 (c_prtt_enrt_rslt_id => p_enrt_rslt_id
9619 ,c_rate_start_or_end_dt => l_rt_end_dt
9620 ,c_effective_date => p_effective_date
9621 );
9622 fetch c_plan_year_end_for_pen into l_last_pp_strt_dt, l_last_pp_end_dt;
9623 close c_plan_year_end_for_pen;
9624 --
9625 -- For ending always do full year processing
9626 --
9627 --l_range_start:=add_months(l_last_pp_end_dt,-12)+1;
9628 --
9629 --BUG 3294702
9630 --l_range_start:=add_months(l_last_pp_end_dt,-12)+1;
9631 l_range_start:=l_last_pp_strt_dt ;
9632 --
9633 if g_debug then
9634 hr_utility.set_location('range start= '|| l_range_start,10);
9635 hr_utility.set_location('range end = '|| l_last_pp_end_dt,10);
9636 hr_utility.set_location('p_amt='||p_amt,100);
9637 end if;
9638 l_amt:=ben_distribute_rates.period_to_annual(
9639 p_amount =>p_amt
9640 ,p_acty_ref_perd_cd =>p_acty_ref_perd
9641 ,p_business_group_id =>p_business_group_id
9642 ,p_effective_date =>p_effective_date
9643 ,p_complete_year_flag =>'N' -- done using start
9644 ,p_use_balance_flag =>'N'
9645 ,p_element_type_id => l_element_type_id
9646 ,p_start_date =>l_range_start
9647 ,p_end_date =>l_last_pp_end_dt
9648 ,p_payroll_id =>l_payroll_id
9649 ,p_rounding_flag =>'N'
9650 );
9651 --
9652 -- to do proration need monthly amount divide by 12.
9653 --
9654 l_per_month_amt := l_amt/12;
9655 if g_debug then
9656 hr_utility.set_location('l_per_month_amt='||l_per_month_amt,100);
9657 hr_utility.set_location('l_amt='||l_amt,100);
9658 end if;
9659 --
9660 -- Compute per pay amt
9661 --
9662 if l_ele_entry_val_cd = 'EPP' then
9663 l_perd_cd := 'EPP';
9664 end if;
9665 l_per_pay_amt:=ben_distribute_rates.annual_to_period(
9666 p_amount =>l_amt
9667 ,p_acty_ref_perd_cd =>l_perd_cd --'PP' -- per pay period
9668 ,p_business_group_id =>p_business_group_id
9669 ,p_effective_date =>p_effective_date
9670 ,p_complete_year_flag =>'N'
9671 ,p_use_balance_flag =>'N'
9672 ,p_element_type_id => l_element_type_id
9673 ,p_start_date =>l_range_start
9674 ,p_end_date =>l_last_pp_end_dt
9675 ,p_payroll_id =>l_payroll_id
9676 );
9677 if g_debug then
9678 hr_utility.set_location('l_per_pay_amt'||l_per_pay_amt,293.1);
9679 end if;
9680 --
9681 if (l_abr_rndg_cd is not null or
9682 l_abr_rndg_rl is not null) and
9683 l_per_pay_amt is not null then
9684 --
9685 l_per_pay_amt := benutils.do_rounding
9686 (p_rounding_cd => l_abr_rndg_cd,
9687 p_rounding_rl => l_abr_rndg_rl,
9688 p_value => l_per_pay_amt,
9689 p_effective_date => p_effective_date);
9690 elsif l_per_pay_amt is not null and
9691 l_per_pay_amt<>0 then
9692 --
9693 -- Do this for now: in future default to rounding for currency prec
9694 --
9695 l_per_pay_amt:=round(l_per_pay_amt,2);
9696 end if;
9697 --
9698 -- Prorate the rate, if necessary
9699 -- let prorate_amount function decide then either
9700 -- l_new_val is the same as l_amount, or not for proration.
9701 -- l_prtn_val will be set.
9702 --
9703 if g_debug then
9704 hr_utility.set_location('Prorate the rate',20);
9705 hr_utility.set_location('l_per_month_amt '||l_per_month_amt,20);
9706 end if;
9707 --
9708 -- Bug 6834340
9709 open c_ler_with_ended_prv(p_prtt_rt_val_id, p_rt_end_date);
9710 fetch c_ler_with_ended_prv into l_ler_with_ended_prv;
9711 close c_ler_with_ended_prv;
9712 -- Bug 6834340
9713 --
9714 -----------Bug 7687104
9715 hr_utility.set_location('l_per_month_amt : '|| l_per_month_amt,20);
9716 open c_chk_payroll_chg(l_rt_end_dt,l_payroll_id);
9717 fetch c_chk_payroll_chg into l_chk_payroll_chg;
9718 if c_chk_payroll_chg%found then
9719 open c_days_in_pp(l_chk_payroll_chg.old_payroll_id,l_rt_end_dt);
9720 fetch c_days_in_pp into l_old_pp_days;
9721 close c_days_in_pp;
9722 hr_utility.set_location('l_old_pp_days : '|| l_old_pp_days,20);
9723 open c_days_in_pp(l_chk_payroll_chg.new_payroll_id,l_rt_end_dt);
9724 fetch c_days_in_pp into l_new_pp_days;
9725 close c_days_in_pp;
9726 hr_utility.set_location('l_new_pp_days : '|| l_new_pp_days,20);
9727 if l_old_pp_days > l_new_pp_days then
9728 open c_get_prev_ele(l_rt_end_dt);
9729 fetch c_get_prev_ele into l_get_prev_ele;
9730 if c_get_prev_ele%found then
9731 hr_utility.set_location('prev_ele.screen_value : '|| l_get_prev_ele.screen_entry_value,20);
9732 l_prev_entry_val := l_get_prev_ele.screen_entry_value;
9733 end if;
9734 close c_get_prev_ele;
9735 end if;
9736 end if;
9737 close c_chk_payroll_chg;
9738 -----------Bug 7687104
9739 -------------Bug 9235544
9740 open c_current_pil;
9741 fetch c_current_pil into l_current_pil;
9742 if c_current_pil%found then
9743 hr_utility.set_location('l_current_pil.per_in_ler_id : '|| l_current_pil.per_in_ler_id,22);
9744 open c_check_current_pen(l_current_pil.per_in_ler_id);
9745 fetch c_check_current_pen into l_check_current_pen;
9746 if c_check_current_pen%notfound then
9747 hr_utility.set_location('pen for the current pil is not found',22);
9748 open c_get_prev_ele(l_rt_end_dt);
9749 fetch c_get_prev_ele into l_get_prev_ele;
9750 if c_get_prev_ele%found then
9751 hr_utility.set_location('prev_ele.screen_value1 : '|| l_get_prev_ele.screen_entry_value,22);
9752 l_prev_entry_val := l_get_prev_ele.screen_entry_value;
9753 end if;
9754 close c_get_prev_ele;
9755 end if;
9756 close c_check_current_pen;
9757 end if;
9758 close c_current_pil;
9759 -------------Bug 9235544
9760 l_prorated_monthly_amt := prorate_amount(
9761 p_amt =>nvl(l_prev_entry_val,l_per_month_amt) --------Bug 7687104
9762 ,p_acty_base_rt_id =>p_acty_base_rt_id
9763 ,p_prorate_flag =>l_prtn_flag
9764 ,p_effective_date =>p_effective_date
9765 ,p_start_or_stop_cd =>'STP'
9766 ,p_start_or_stop_date =>l_rt_end_dt
9767 ,p_business_group_id =>p_business_group_id
9768 ,p_assignment_id =>l_assignment_id
9769 ,p_organization_id =>l_organization_id
9770 ,p_wsh_rl_dy_mo_num =>l_wsh_rl_dy_mo_num
9771 ,p_prtl_mo_det_mthd_cd =>l_prtl_mo_det_mthd_cd
9772 ,p_prtl_mo_det_mthd_rl =>l_prtl_mo_det_mthd_rl
9773 -- new parms below
9774 ,p_person_id =>g_result_rec.person_id
9775 ,p_pgm_id =>g_result_rec.pgm_id
9776 ,p_pl_typ_id =>g_result_rec.pl_typ_id
9777 ,p_pl_id =>g_result_rec.pl_id
9778 ,p_opt_id =>g_result_rec.opt_id
9779 ,p_ler_id =>l_ler_with_ended_prv.ler_id -- Bug 6834340
9780 ,p_jurisdiction_code =>l_jurisdiction_code
9781 ,p_rndg_cd =>l_abr_rndg_cd
9782 ,p_rndg_rl =>l_abr_rndg_rl
9783 );
9784 --
9785 -- ELE :
9786 end if;
9787 -- already have the element_entry_id
9788 --
9789 -- Check the PRTL MONTH PRORATION rule
9790 -- against the effective date and payperiod
9791 -- of participants payroll.
9792 --
9793 -- Get the Element Link ID
9794 -- and the Input value id for EE Contr.
9795 --
9796 -- ELE : By pass if the ele_entry_val_cd <> PP , EPP or null.
9797 --
9798 if nvl(l_ele_entry_val_cd, 'PP') not in ('PP','EPP') then
9799 l_prtn_flag := 'N';
9800 l_special_pp_date := null;
9801 end if;
9802 --
9803 -- Determine prorated first pay periods
9804 -- Where amount is not the normal per pay period amount
9805 --
9806 if l_prtn_flag = 'Y' then
9807 if g_debug then
9808 hr_utility.set_location('Determine proration ',40);
9809 end if;
9810 if l_prtl_mo_eff_dt_det_cd = 'RL' and
9811 l_prtl_mo_eff_dt_det_rl is not null then
9812 --
9813 -- exec rule and get code back
9814 --
9815 l_outputs:=benutils.formula
9816 (p_opt_id =>g_result_rec.opt_id,
9817 p_pl_id =>g_result_rec.pl_id,
9818 p_pgm_id =>g_result_rec.pgm_id,
9819 p_formula_id =>l_prtl_mo_eff_dt_det_rl,
9820 p_ler_id =>g_result_rec.ler_id,
9821 p_pl_typ_id =>g_result_rec.pl_typ_id,
9822 p_assignment_id =>l_assignment_id,
9823 p_acty_base_rt_id =>p_acty_base_rt_id,
9824 p_business_group_id =>p_business_group_id,
9825 p_organization_id =>l_organization_id,
9826 p_jurisdiction_code =>l_jurisdiction_code,
9827 p_effective_date =>l_rt_end_dt);
9828 --
9829 begin
9830 --
9831 -- convert return value to code
9832 --
9833 l_prtl_mo_eff_dt_det_cd:=l_outputs(l_outputs.first).value;
9834 --
9835 exception
9836 --
9837 when others then
9838 if g_debug then
9839 hr_utility.set_location('BEN_92311_FORMULA_VAL_PARAM',46);
9840 end if;
9841 fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
9842 fnd_message.set_token('PROC',l_proc);
9843 fnd_message.set_token('FORMULA',l_prtl_mo_det_mthd_rl);
9844 fnd_message.set_token('PARAMETER',
9845 l_outputs(l_outputs.first).name);
9846 fnd_message.raise_error;
9847 --
9848 end;
9849 end if;
9850 --
9851 -- Approach/algorithm to allocating payments:
9852 --
9853 -- In ending a rate there are three distinct rate stages
9854 -- 1) Normal pay periods - Periodic rate is still in place.
9855 -- 2) Special pay period - pay period during which a rate not equal to the normal rate
9856 -- is in effect. Just one pay period. Spreading them out is outside the scope
9857 -- of this version.
9858 -- 3) No pay periods - pay periods during which no rate should be in effect.
9859 -----------------------------------------------------------
9860 --
9861 -- Want to find the pay periods from the start date
9862 -- ending at the last day of the month or earlier
9863 -- based on the date column specified by prtl_mo_eff_dt_det_cd
9864 --
9865 -- Go backwards and keep overwriting the dates with the most
9866 -- recent one to get the first date it changes to that rate.
9867 --
9868 l_remainder:=l_prorated_monthly_amt;
9869 l_number_in_month:=0;
9870 for l_pay_periods in c_last_pay_periods(
9871 p_start_date => trunc(l_rt_end_dt,'mm'),
9872 p_end_date => add_months(
9873 trunc(l_rt_end_dt,'mm'),1)-1,
9874 p_prtl_mo_eff_dt_det_cd => l_prtl_mo_eff_dt_det_cd,
9875 p_payroll_id => l_payroll_id) loop
9876 --
9877 exit when l_pay_periods.start_date > l_rt_end_dt;
9878 --
9879 hr_elements.check_element_freq(
9880 p_payroll_id =>l_payroll_id,
9881 p_bg_id =>p_business_group_id,
9882 p_pay_action_id =>to_number(null),
9883 p_date_earned =>l_pay_periods.start_date,
9884 p_ele_type_id =>l_element_type_id,
9885 p_skip_element =>g_skip_element
9886 );
9887 if g_skip_element='N' then
9888 l_number_in_month:=l_number_in_month+1;
9889 if g_debug then
9890 hr_utility.set_location('l_zero_pp_date'||l_pay_periods.start_date,293.1);
9891 hr_utility.set_location('l_remainder'||l_remainder,293.1);
9892 hr_utility.set_location('l_pay_periods.end_date'||l_pay_periods.end_date,293.1);
9893 hr_utility.set_location('l_per_pay_amt'||l_per_pay_amt,293.1);
9894 hr_utility.set_location('l_rt_end_dt'||l_rt_end_dt,293.1);
9895 end if;
9896 if (l_remainder>l_per_pay_amt and
9897 l_rt_end_dt > l_pay_periods.end_date) then
9898 --
9899 -- Normal pay period, may not be if have remainder left over
9900 -- In this case will revise date after loop is done
9901 --
9902 l_remainder:=l_remainder-l_per_pay_amt;
9903 l_old_normal_pp_date:=l_normal_pp_date;
9904 l_old_normal_pp_end_date:=l_normal_pp_end_date;
9905 l_normal_pp_end_date:=l_pay_periods.end_date;
9906 l_normal_pp_date:=l_pay_periods.start_date;
9907 if g_debug then
9908 hr_utility.set_location('normal end date'||l_normal_pp_end_date,293.1);
9909 end if;
9910 if g_debug then
9911 hr_utility.set_location('l_per_pay_amt'||l_per_pay_amt,293.1);
9912 end if;
9913 elsif l_remainder=0 then
9914 --
9915 -- Free pay period, no charge
9916 --
9917 l_zero_pp_date := l_pay_periods.start_date;
9918 if g_debug then
9919 hr_utility.set_location('l_zero_pp_date'||l_pay_periods.start_date,293.1);
9920 end if;
9921 exit;
9922 else
9923 --
9924 -- Special small pay period, from here on it's free.
9925 --
9926 l_special_pp_end_date:=l_pay_periods.end_date;
9927 l_special_pp_date:=l_pay_periods.start_date;
9928 l_special_amt:=l_remainder;
9929 l_remainder:=0;
9930 end if;
9931 end if;
9932 end loop;
9933 --
9934 -- Now check if loop was not entered
9935 --
9936 if l_remainder > 0 then
9937 --
9938 -- This is the Large amount case where the full amount gets added
9939 -- to the last pp of prev month
9940 --
9941 --
9942 -- The remaining amount is added to the current pay period.
9943 --
9944 open c_get_current_pp
9945 (p_end_date => l_rt_end_dt
9946 ,p_prtl_mo_eff_dt_det_cd => l_prtl_mo_eff_dt_det_cd
9947 ,p_payroll_id => l_payroll_id
9948 );
9949 fetch c_get_current_pp into l_start_date,l_end_date;
9950 if c_get_current_pp%notfound then
9951 close c_get_current_pp;
9952 if g_debug then
9953 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',48);
9954 end if;
9955 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
9956 fnd_message.set_token('PROC',l_proc);
9957 fnd_message.raise_error;
9958 end if;
9959 --
9960 close c_get_current_pp;
9961 --
9962 -- Prorate for the current pay period.
9963 --
9964 -- If it is a skip period, do not prorate.
9965 --
9966 hr_elements.check_element_freq(
9967 p_payroll_id =>l_payroll_id,
9968 p_bg_id =>p_business_group_id,
9969 p_pay_action_id =>to_number(null),
9970 p_date_earned =>l_start_date,
9971 p_ele_type_id =>l_element_type_id,
9972 p_skip_element =>g_skip_element
9973 );
9974 --
9975 if g_skip_element = 'N' then
9976 l_special_pp_end_date:= l_end_date;
9977 l_special_pp_date:= l_start_date;
9978 if (l_number_in_month = 0 or
9979 l_end_date = l_rt_end_dt) then
9980 l_special_amt:=l_remainder + l_per_pay_amt;
9981 else
9982 l_special_amt := l_remainder;
9983 end if;
9984 else
9985 --
9986 -- If skip element then display a informational message
9987 -- indicating that there is no proration and user will need
9988 -- to manually process a deduction.
9989 --
9990 ben_warnings.load_warning
9991 (p_application_short_name => 'BEN',
9992 p_message_name => 'BEN_92939_NO_PRORATION',
9993 p_person_id => p_person_id);
9994 --
9995 fnd_message.set_name('BEN', 'BEN_92939_NO_PRORATION');
9996 if fnd_global.conc_request_id <> -1 then
9997 benutils.write(fnd_message.get);
9998 end if;
9999 --
10000 l_immediate_end := true;
10001 end if;
10002 elsif (l_remainder = 0 and
10003 l_rt_end_dt > l_special_pp_end_date
10004 and l_zero_pp_date is null) then
10005 --
10006 -- The remaining amount is added to the current pay period.
10007 --
10008 open c_get_current_pp
10009 (p_end_date => l_rt_end_dt
10010 ,p_prtl_mo_eff_dt_det_cd => l_prtl_mo_eff_dt_det_cd
10011 ,p_payroll_id => l_payroll_id
10012 );
10013 fetch c_get_current_pp into l_zero_pp_date,l_end_date;
10014 if c_get_current_pp%notfound then
10015 close c_get_current_pp;
10016 if g_debug then
10017 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',48);
10018 end if;
10019 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
10020 fnd_message.set_token('PROC',l_proc);
10021 fnd_message.raise_error;
10022 end if;
10023 --
10024 close c_get_current_pp;
10025 end if; -- l_remainder > 0
10026 --
10027 --
10028 -- In the cases where a normal pp was not found then it
10029 -- must be the last pp of the previous month but
10030 --
10031 --
10032 if l_normal_pp_date is null then
10033 open c_pps_prev_month(
10034 p_end_date => trunc(l_rt_end_dt,'mm'),
10035 p_prtl_mo_eff_dt_det_cd => l_prtl_mo_eff_dt_det_cd,
10036 p_payroll_id => l_payroll_id);
10037 loop
10038 fetch c_pps_prev_month into l_start_date,l_end_date;
10039 if c_pps_prev_month%notfound then
10040 close c_pps_prev_month;
10041 if g_debug then
10042 hr_utility.set_location('BEN_92346_PAYROLL_NOT_DEFINED',50);
10043 end if;
10044 fnd_message.set_name('BEN', 'BEN_92346_PAYROLL_NOT_DEFINED');
10045 fnd_message.set_token('PROC',l_proc);
10046 fnd_message.raise_error;
10047 end if;
10048 hr_elements.check_element_freq(
10049 p_payroll_id =>l_payroll_id,
10050 p_bg_id =>p_business_group_id,
10051 p_pay_action_id =>to_number(null),
10052 p_date_earned =>l_start_date,
10053 p_ele_type_id =>l_element_type_id,
10054 p_skip_element =>g_skip_element
10055 );
10056 exit when g_skip_element='N';
10057 end loop;
10058 close c_pps_prev_month;
10059 l_normal_pp_end_date:=l_end_date;
10060 l_normal_pp_date:=l_start_date;
10061 if g_debug then
10062 hr_utility.set_location('normal end date'||l_normal_pp_end_date,293.1);
10063 end if;
10064 end if;
10065 else
10066 --
10067 -- No proration end on rt_end date.
10068 --
10069 l_immediate_end:=true;
10070 --
10071 end if;
10072 --
10073 -- Don't make unnecessary changes: compare old value to new one
10074 --
10075 -- Do special pay period.
10076 --
10077 if g_debug then
10078 hr_utility.set_location('l_special_pp_date '||l_special_pp_date,20);
10079 hr_utility.set_location('l_special_amt '||l_special_amt,20);
10080 end if;
10081
10082 if l_special_pp_date is not null and
10083 l_immediate_end=false then
10084 --
10085 -- bug 2651153 get the currency of the program
10086
10087 --
10088 -- changes the format of the screen entry value as per the session
10089 --
10090
10091 if l_uom is null then
10092 l_uom := get_uom(p_business_group_id,p_effective_date);
10093 end if;
10094 l_curr_val := chkformat(l_curr_val_char, l_uom);
10095
10096 if g_debug then
10097 hr_utility.set_location('l_uom='|| l_uom ,432);
10098 hr_utility.set_location('aft frmt chg '||l_curr_val_char,432);
10099 hr_utility.set_location('converted no. value is '||l_curr_val,432);
10100 end if;
10101
10102 if nvl(l_curr_val,hr_api.g_number) <>l_special_amt then
10103 /*
10104 Before :-
10105 02-JAN-1994
10106 |-A----------------------------------------------------->
10107 ED
10108
10109 After :-
10110 02-JAN-1994 15-JUL-1994
10111 |-A----------------------------|-B---------------------->
10112 ED
10113 */
10114
10115 -- Bug 2331574 start
10116 -- To handle cases where the element entry start date >
10117 -- special pay period start date
10118 if g_debug then
10119 hr_utility.set_location('Updating if the rate has changed ',90);
10120 hr_utility.set_location('l_immediate_end=false ',20);
10121 end if;
10122
10123 if l_special_pp_date < l_element_entry_start_date then
10124 l_special_pp_date := l_element_entry_start_date;
10125 end if;
10126
10127 -- Determine the Date track update mode for calling
10128 -- py_element_entry_api.update_element_entry
10129
10130 l_dt_upd_mode := get_ele_dt_upd_mode(l_special_pp_date,l_element_entry_id);
10131 --
10132 open c_element_ovn (l_element_entry_id, l_special_pp_date);
10133 fetch c_element_ovn into l_object_version_number;
10134 close c_element_ovn;
10135 --
10136 if g_debug then
10137 hr_utility.set_location('Obj No.'||l_object_version_number,111);
10138 hr_utility.set_location('Special PP'||l_special_pp_date,112);
10139 hr_utility.set_location('Datetrack Mode'||l_dt_upd_mode,113);
10140 end if;
10141
10142 py_element_entry_api.update_element_entry
10143 (p_validate =>p_validate
10144 ,p_datetrack_update_mode =>l_dt_upd_mode
10145 ,p_effective_date =>l_special_pp_date
10146 ,p_business_group_id =>p_business_group_id
10147 ,p_element_entry_id =>l_element_entry_id
10148 ,p_object_version_number =>l_object_version_number
10149 ,p_creator_type =>'F'
10150 ,p_creator_id =>p_enrt_rslt_id
10151 ,p_override_user_ent_chk =>'Y'
10152 ,p_input_value_id1 =>l_input_value_id
10153 ,p_entry_value1 =>l_special_amt
10154 ,p_effective_start_date =>l_new_date
10155 ,p_effective_end_date =>l_end_of_time
10156 ,p_update_warning =>l_update_warning
10157 );
10158 --
10159 --
10160 -- write to the change event log
10161 --
10162 ben_ext_chlg.log_element_chg(
10163 p_action => l_dt_upd_mode,
10164 p_amt => l_special_amt,
10165 p_old_amt => l_curr_val,
10166 p_input_value_id => l_input_value_id,
10167 p_element_entry_id => l_element_entry_id,
10168 p_person_id => p_person_id,
10169 p_business_group_id => p_business_group_id,
10170 p_effective_date => l_special_pp_date);
10171 --
10172 --
10173 -- Set the rate end date to the earlier of the
10174 -- rate_end_date or the period end date
10175 --
10176 end if;
10177 end if;
10178 --
10179 -- Bug:2730801 - Moved the following code out from the
10180 -- special pay periods if condition.
10181 -- Because this is executing only for the special pay periods.
10182 --
10183 /*
10184 Example: When rate has a wash role as 15 days. If a employee
10185 terminated 14th of the month then he should not get charged
10186 from 1st to 14th of the month, that pay period will be
10187 zero pay period.
10188 Before :-
10189 02-JAN-1994
10190 |-A----------------------------------------------------->
10191 ED
10192
10193 After :-
10194 02-JAN-1994 01-JUL-94 14-JUL-1994
10195 |-A------------------|----------|-B---------------------->
10196 zero pp ED
10197 */
10198 if l_zero_pp_date is not null and
10199 l_immediate_end=false then
10200 --
10201 l_curr_val := l_special_amt;
10202 if g_debug then
10203 hr_utility.set_location('l_zero_pp_date '||l_zero_pp_date,20);
10204 end if;
10205
10206 l_dt_to_use := greatest(l_prv_rec.rt_strt_dt,l_zero_pp_date);
10207 open c_element_ovn (l_element_entry_id, l_dt_to_use);
10208 fetch c_element_ovn into l_object_version_number;
10209 close c_element_ovn;
10210 --
10211 l_dt_upd_mode := get_ele_dt_upd_mode(l_dt_to_use,l_element_entry_id);
10212
10213 py_element_entry_api.update_element_entry
10214 (p_validate =>p_validate
10215 ,p_datetrack_update_mode =>l_dt_upd_mode
10216 ,p_effective_date =>l_dt_to_use
10217 ,p_business_group_id =>p_business_group_id
10218 ,p_element_entry_id =>l_element_entry_id
10219 ,p_object_version_number =>l_object_version_number
10220 ,p_override_user_ent_chk =>'Y'
10221 ,p_creator_type =>'F'
10222 ,p_creator_id =>p_enrt_rslt_id
10223 ,p_input_value_id1 =>l_input_value_id
10224 ,p_entry_value1 =>0
10225 ,p_effective_start_date =>l_new_date
10226 ,p_effective_end_date =>l_end_of_time
10227 ,p_update_warning =>l_update_warning
10228 );
10229 --
10230 -- write to the change event log
10231 --
10232 ben_ext_chlg.log_element_chg
10233 (p_action => hr_api.g_update
10234 ,p_amt => 0
10235 ,p_old_amt => l_curr_val
10236 ,p_input_value_id => l_input_value_id
10237 ,p_element_entry_id => l_element_entry_id
10238 ,p_person_id => p_person_id
10239 ,p_business_group_id => p_business_group_id
10240 ,p_effective_date => l_dt_to_use
10241 );
10242 end if;
10243 end if;
10244 --
10245 -- Done with special value pay period, now end rate
10246 --
10247 if g_debug then
10248 hr_utility.set_location('DT Delete mode '||l_dt_delete_mode,30);
10249 end if;
10250 --
10251 -- bug 9148303 : update only if the element entry is attached to primary assignment
10252 -- and another prv exists
10253
10254 open c_ass_type (l_assignment_id, l_rt_end_dt+1);
10255 fetch c_ass_type into l_ass_type;
10256 close c_ass_type;
10257
10258 if l_another_prv_exists and nvl(l_ass_type.primary_flag,'N') = 'Y' then
10259 --
10260 l_dt_upd_mode := get_ele_dt_upd_mode(l_rt_end_dt+1,l_element_entry_id);
10261 --
10262 -- get the ovn
10263 --
10264 open c_element_ovn (l_element_entry_id, l_rt_end_dt+1);
10265 fetch c_element_ovn into l_object_version_number;
10266 close c_element_ovn;
10267 --
10268 py_element_entry_api.update_element_entry
10269 (p_validate =>p_validate
10270 ,p_datetrack_update_mode =>l_dt_upd_mode
10271 ,p_effective_date =>l_rt_end_dt + 1
10272 ,p_business_group_id =>p_business_group_id
10273 ,p_element_entry_id =>l_element_entry_id
10274 ,p_override_user_ent_chk =>'Y'
10275 ,p_object_version_number =>l_object_version_number
10276 ,p_input_value_id1 =>l_input_value_id
10277 ,p_entry_value1 =>0
10278 ,p_effective_start_date =>l_effective_start_date
10279 ,p_effective_end_date =>l_effective_end_date
10280 ,p_update_warning =>l_update_warning
10281 );
10282 --
10283 -- write to the change event log
10284 --
10285 ben_ext_chlg.log_element_chg
10286 (p_action => 'UPDATE'
10287 ,p_amt => 0
10288 ,p_old_amt => fnd_number.canonical_to_number(l_curr_val_char)
10289 ,p_input_value_id => l_input_value_id
10290 ,p_element_entry_id => l_element_entry_id
10291 ,p_person_id => p_person_id
10292 ,p_business_group_id=> p_business_group_id
10293 ,p_effective_date => l_rt_end_dt + 1
10294 );
10295 --
10296 else
10297 --
10298 -- get the ovn
10299 --
10300 open c_element_ovn (l_element_entry_id, l_rt_end_dt);
10301 fetch c_element_ovn into l_object_version_number;
10302 close c_element_ovn;
10303 --
10304 py_element_entry_api.delete_element_entry
10305 (p_validate => p_validate
10306 ,p_datetrack_delete_mode => l_dt_delete_mode
10307 ,p_effective_date => l_rt_end_dt
10308 ,p_element_entry_id => l_element_entry_id
10309 ,p_object_version_number => l_object_version_number
10310 ,p_effective_start_date => l_effective_start_date
10311 ,p_effective_end_date => l_effective_end_date
10312 ,p_delete_warning => l_delete_warning);
10313 --
10314 -- write to the change event log
10315 --
10316 ben_ext_chlg.log_element_chg(
10317 p_action => hr_api.g_delete,
10318 p_old_amt => fnd_number.canonical_to_number(l_curr_val_char),
10319 p_input_value_id => l_input_value_id,
10320 p_element_entry_id => l_element_entry_id,
10321 p_person_id => p_person_id,
10322 p_business_group_id => p_business_group_id,
10323 p_effective_date => l_rt_end_dt);
10324 --
10325 end if;
10326
10327 if l_abs_ler then
10328 pqp_absence_plan_process.update_absence_plan_details
10329 (p_person_id => p_person_id
10330 ,p_assignment_id => l_assignment_id
10331 ,p_business_group_id => p_business_group_id
10332 ,p_legislation_code => get_legislation_code(p_business_group_id)
10333 ,p_effective_date => p_effective_date
10334 ,p_element_type_id => l_element_type_id
10335 ,p_pl_id => g_result_rec.pl_id
10336 ,p_pl_typ_id => g_result_rec.pl_typ_id
10337 ,p_ler_id => l_ler_id
10338 ,p_per_in_ler_id => l_per_in_ler_id
10339 ,p_absence_attendance_id => l_absence_attendance_id
10340 ,p_effective_start_date => l_effective_start_date
10341 ,p_effective_end_date => l_effective_end_date
10342 ,p_formula_outputs => g_outputs
10343 ,p_error_code => l_err_code
10344 ,p_error_message => l_err_mesg
10345 );
10346 end if;
10347 --
10348 end if;
10349 --
10350 -- delete/update any future entries for the same enrt result.
10351 -- Future entries could exist if there was an update to assignment
10352 -- that affected link eligibility
10353 --
10354 open get_future_element_entry
10355 (p_enrt_rslt_id
10356 ,l_assignment_id
10357 ,l_element_type_id
10358 ,l_effective_date);
10359 loop
10360 fetch get_future_element_entry into l_future_ee_rec;
10361 if get_future_element_entry%notfound then
10362 exit;
10363 end if;
10364
10365 if l_another_prv_exists then
10366 --
10367 l_dt_upd_mode := get_ele_dt_upd_mode
10368 (l_future_ee_rec.effective_end_date,
10369 l_future_ee_rec.element_entry_id);
10370 --
10371 py_element_entry_api.update_element_entry
10372 (p_validate =>p_validate
10373 ,p_datetrack_update_mode =>l_dt_upd_mode
10374 ,p_effective_date =>l_future_ee_rec.effective_end_date
10375 ,p_business_group_id =>p_business_group_id
10376 ,p_element_entry_id =>l_future_ee_rec.element_entry_id
10377 ,p_override_user_ent_chk =>'Y'
10378 ,p_object_version_number =>l_future_ee_rec.object_version_number
10379 ,p_input_value_id1 =>l_input_value_id
10380 ,p_entry_value1 =>0
10381 ,p_effective_start_date =>l_effective_start_date
10382 ,p_effective_end_date =>l_effective_end_date
10383 ,p_update_warning =>l_update_warning
10384 );
10385 --
10386 -- write to the change event log
10387 --
10388 ben_ext_chlg.log_element_chg
10389 (p_action => l_dt_upd_mode
10390 ,p_amt => 0
10391 ,p_old_amt => fnd_number.canonical_to_number(l_curr_val_char)
10392 ,p_input_value_id => l_input_value_id
10393 ,p_element_entry_id => l_future_ee_rec.element_entry_id
10394 ,p_person_id => p_person_id
10395 ,p_business_group_id=> p_business_group_id
10396 ,p_effective_date => p_effective_date);
10397 --
10398 else
10399 py_element_entry_api.delete_element_entry
10400 (p_validate => p_validate
10401 ,p_datetrack_delete_mode => hr_api.g_zap
10402 ,p_effective_date => l_future_ee_rec.effective_start_date
10403 ,p_element_entry_id => l_future_ee_rec.element_entry_id
10404 ,p_object_version_number => l_future_ee_rec.object_version_number
10405 ,p_effective_start_date => l_effective_start_date
10406 ,p_effective_end_date => l_effective_end_date
10407 ,p_delete_warning => l_delete_warning
10408 );
10409 --
10410 -- write to the change event log
10411 --
10412 ben_ext_chlg.log_element_chg(
10413 p_action => 'DELETE',
10414 p_old_amt => fnd_number.canonical_to_number(l_curr_val_char),
10415 p_input_value_id => l_input_value_id,
10416 p_element_entry_id => l_future_ee_rec.element_entry_id,
10417 p_person_id => p_person_id,
10418 p_business_group_id => p_business_group_id,
10419 p_effective_date => p_effective_date);
10420 --
10421 end if;
10422 --
10423 end loop;
10424 close get_future_element_entry;
10425
10426 if g_debug then
10427 hr_utility.set_location('Leaving :'||l_proc,5);
10428 end if;
10429
10430 end end_enrollment_element;
10431 --
10432 -- 0 - Always refresh
10433 -- 1 - Initialise cache
10434 -- 2 - Cache hit
10435 --
10436 procedure clear_down_cache
10437 is
10438
10439 begin
10440 --
10441 g_get_link_cache.delete;
10442 g_get_link_cached := 1;
10443 g_abr_asg_rec := null;
10444 g_per_pay_rec := null;
10445 --
10446 end clear_down_cache;
10447 --
10448 procedure set_no_cache_context
10449 is
10450
10451 begin
10452 --
10453 g_get_link_cache.delete;
10454 g_get_link_cached := 0;
10455 --
10456 end set_no_cache_context;
10457 --
10458 procedure reset_msg_displayed --bug 2530582
10459 is
10460 begin
10461 g_msg_displayed := 0;
10462 end reset_msg_displayed;
10463 --
10464 procedure create_reimburse_element
10465 (p_validate in boolean default false
10466 ,p_person_id in number
10467 ,p_acty_base_rt_id in number
10468 ,p_amt in number
10469 ,p_business_group_id in number
10470 ,p_effective_date in date
10471 ,p_prtt_reimbmt_rqst_id in number default null
10472 ,p_input_value_id in number default null
10473 ,p_element_type_id in number default null
10474 ,p_pl_id in number default null
10475 ,p_prtt_rmt_aprvd_fr_pymt_id in number
10476 ,p_object_version_number in out nocopy number
10477 ) is
10478 --
10479 cursor c_element_entry (p_element_entry_id number,
10480 p_input_value_id number) is
10481 select element_entry_value_id
10482 from pay_element_entry_values_f
10483 where ELEMENT_ENTRY_ID = p_element_entry_id
10484 and input_value_id = p_input_value_id;
10485 --
10486 cursor c_ety is
10487 select processing_type
10488 from pay_element_types_f
10489 where element_type_id = p_element_type_id
10490 and p_effective_date between effective_start_date
10491 and effective_end_date ;
10492 --
10493 l_tmp_bool boolean;
10494 l_assignment_id number;
10495 l_organization_id number;
10496 l_payroll_id number;
10497 l_create_warning BOOLEAN;
10498 l_update_warning BOOLEAN;
10499 l_effective_start_date date;
10500 l_effective_end_Date date;
10501 l_object_version_number number;
10502 l_element_link_id NUMBER;
10503 l_input_value_id number;
10504 L_ELEMENT_ENTRY_ID number;
10505 l_element_entry_value_id number;
10506 l_processing_type varchar2(300);
10507 l_delete_warning boolean;
10508 --
10509
10510 begin
10511 --
10512 if g_debug then
10513 hr_utility.set_location('Entering : create_reimburse_element',50);
10514 end if;
10515 l_tmp_bool:=chk_assign_exists
10516 (p_person_id => p_person_id
10517 ,p_business_group_id => p_business_group_id
10518 ,p_effective_date => p_effective_date
10519 ,p_rate_date => p_effective_date
10520 ,p_acty_base_rt_id => p_acty_base_rt_id
10521 ,p_assignment_id => l_assignment_id
10522 ,p_organization_id => l_organization_id
10523 ,p_payroll_id => l_payroll_id
10524 );
10525 --
10526 --
10527 if g_debug then
10528 hr_utility.set_location('l_assignment_id:'||l_assignment_id,50);
10529 hr_utility.set_location('l_payroll_id:'||l_payroll_id,50);
10530 end if;
10531 --
10532 get_link(p_assignment_id => l_assignment_id
10533 ,p_element_type_id => p_element_type_id
10534 ,p_business_group_id => p_business_group_id
10535 ,p_input_value_id => l_input_value_id
10536 ,p_effective_date => p_effective_date
10537 ,p_element_link_id => l_element_link_id
10538 );
10539 if l_element_link_id is null then
10540 --
10541 -- error message already set on stack.
10542 --
10543 fnd_message.raise_error;
10544 end if;
10545 hr_utility.set_location( 'entering', 30.2);
10546 py_element_entry_api.create_element_entry
10547 (p_validate =>p_validate
10548 ,p_effective_date =>p_effective_date
10549 ,p_business_group_id =>p_business_group_id
10550 ,p_assignment_id =>l_assignment_id
10551 ,p_element_link_id =>l_element_link_id
10552 ,p_entry_type =>'E'
10553 ,p_input_value_id1 =>p_input_value_id
10554 ,p_entry_value1 =>p_amt
10555 ,p_effective_start_date =>l_effective_start_date
10556 ,p_effective_end_date =>l_effective_end_Date
10557 ,p_element_entry_id =>l_element_entry_id
10558 ,p_object_version_number =>l_object_version_number
10559 ,p_create_warning =>l_create_warning
10560 );
10561 --
10562 --
10563 hr_utility.set_location('Change creator type and id ',50);
10564 py_element_entry_api.update_element_entry
10565 (p_validate =>p_validate
10566 ,p_datetrack_update_mode =>'CORRECTION'
10567 ,p_effective_date =>p_effective_date
10568 ,p_business_group_id =>p_business_group_id
10569 ,p_element_entry_id =>l_element_entry_id
10570 ,p_object_version_number =>l_object_version_number
10571 ,p_creator_type =>'F'
10572 ,p_creator_id =>p_prtt_reimbmt_rqst_id
10573 ,p_input_value_id1 =>p_input_value_id
10574 ,p_entry_value1 =>p_amt
10575 ,p_effective_start_date =>l_effective_start_date
10576 ,p_effective_end_date =>l_effective_end_Date
10577 ,p_update_warning =>l_update_warning
10578 );
10579 --
10580 --
10581 open c_ety;
10582 fetch c_ety into l_processing_type;
10583 if l_processing_type = 'R' then
10584 -- the element should be end dated
10585 py_element_entry_api.delete_element_entry
10586 (p_validate => p_validate
10587 ,p_datetrack_delete_mode => hr_api.g_delete
10588 ,p_effective_date => p_effective_date
10589 ,p_element_entry_id => l_element_entry_id
10590 ,p_object_version_number => l_object_version_number
10591 ,p_effective_start_date => l_effective_start_date
10592 ,p_effective_end_date => l_effective_end_date
10593 ,p_delete_warning => l_delete_warning
10594 );
10595 --
10596
10597 end if;
10598 close c_ety;
10599 --
10600 open c_element_entry (l_element_entry_id,p_input_value_id);
10601 fetch c_element_entry into l_element_entry_value_id;
10602 close c_element_entry;
10603 --
10604 if l_element_entry_value_id is null then
10605 --
10606 if g_debug then
10607 hr_utility.set_location('BEN_92102_NO_ENTRY_CREATED',140);
10608 end if;
10609 fnd_message.set_name('BEN', 'BEN_92102_NO_ENTRY_CREATED');
10610 fnd_message.set_token('PROC','Create_reimburse_element');
10611 fnd_message.set_token('ELEMENT_ENTRY_ID',to_char(l_element_link_id));
10612 fnd_message.set_token('INPUT_VALUE_ID',to_char(l_input_value_id));
10613 fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
10614 fnd_message.raise_error;
10615 else
10616 --
10617 ben_prtt_rmt_aprvd_pymt_api.update_prtt_rmt_aprvd_pymt
10618 (p_prtt_rmt_aprvd_fr_pymt_id => p_prtt_rmt_aprvd_fr_pymt_id,
10619 p_effective_start_date => l_effective_start_date,
10620 p_effective_end_date => l_effective_end_date,
10621 p_element_entry_value_id => l_element_entry_value_id,
10622 p_object_version_number => p_object_version_number,
10623 p_effective_date => p_effective_date,
10624 p_aprvd_fr_pymt_amt => p_amt,
10625 p_datetrack_mode => 'CORRECTION');
10626 --
10627 end if;
10628
10629
10630 hr_utility.set_location('Leaving : Create_reimburse_element',51);
10631 --
10632 end ;
10633 --
10634 procedure end_reimburse_element(p_validate IN BOOLEAN default FALSE
10635 ,p_business_group_id IN NUMBER
10636 ,p_person_id IN NUMBER
10637 ,p_prtt_reimbmt_rqst_id IN NUMBER
10638 ,p_element_link_id IN NUMBER
10639 ,p_prtt_rmt_aprvd_fr_pymt_id in number
10640 ,p_effective_date IN DATE
10641 ,p_dt_delete_mode IN VARCHAR2
10642 ,p_element_entry_value_id in number) is
10643 --
10644 cursor c_ele_info (p_element_entry_value_id number) is
10645 select ele.element_entry_id,
10646 ele.entry_type,
10647 ele.original_entry_id,
10648 elt.processing_type,
10649 elk.element_type_id,
10650 elk.effective_end_date
10651 from pay_element_entry_values_f elv,
10652 pay_element_entries_f ele,
10653 pay_element_links_f elk,
10654 pay_element_types_f elt
10655 where elv.element_entry_value_id = p_element_entry_value_id
10656 and elv.element_entry_id = ele.element_entry_id
10657 and elv.effective_start_date between ele.effective_start_date
10658 and ele.effective_end_date
10659 and ele.element_link_id = elk.element_link_id
10660 and ele.effective_start_date between elk.effective_start_date
10661 and elk.effective_end_date
10662 and elk.element_type_id = elt.element_type_id
10663 and elk.effective_start_date between elt.effective_start_date
10664 and elt.effective_end_date ;
10665 --
10666 l_ele_rec c_ele_info%rowtype;
10667 --
10668 cursor c_element_entry (p_element_entry_id number) is
10669 select object_version_number
10670 from pay_element_entries_f
10671 where element_entry_id = p_element_entry_id;
10672 --
10673 l_object_version_number number;
10674 l_element_entry_id number;
10675 l_effective_start_date date;
10676 l_effective_end_date date;
10677 l_delete_warning boolean;
10678 l_processed_flag varchar2(300);
10679
10680 begin
10681 --
10682 open c_ele_info(p_element_entry_value_id);
10683 fetch c_ele_info into l_ele_rec;
10684 --
10685 if c_ele_info%notfound then
10686 close c_ele_info;
10687 if g_debug then
10688 --
10689 hr_utility.set_location('Leaving: End reimburse element',7);
10690 end if;
10691 return;
10692 end if;
10693 close c_ele_info;
10694 --
10695 l_processed_flag := substr(pay_paywsmee_pkg.processed(
10696 l_ele_rec.element_entry_id,
10697 l_ele_rec.original_entry_id,
10698 l_ele_rec.processing_type,
10699 l_ele_rec.entry_type,
10700 p_effective_date), 1,1) ;
10701 --
10702 if l_processed_flag = 'Y' then
10703 --
10704 fnd_message.set_name ('BEN','BEN_93341_PRCCSD_IN_PAYROLL');
10705 fnd_message.raise_error;
10706 --
10707 end if;
10708 --
10709 open c_element_entry (l_ele_rec.element_entry_id);
10710 fetch c_element_entry into l_object_version_number;
10711 close c_element_entry;
10712 --
10713 py_element_entry_api.delete_element_entry
10714 (p_validate => p_validate
10715 ,p_datetrack_delete_mode => hr_api.g_zap
10716 ,p_effective_date => p_effective_date
10717 ,p_element_entry_id => l_ele_rec.element_entry_id
10718 ,p_object_version_number => l_object_version_number
10719 ,p_effective_start_date => l_effective_start_date
10720 ,p_effective_end_date => l_effective_end_date
10721 ,p_delete_warning => l_delete_warning
10722 );
10723
10724 hr_utility.set_location('Leaving: End reimburse element',7);
10725 end;
10726
10727 --
10728 end ben_element_entry;