1 package body hrentmnt as
2 /* $Header: pyentmnt.pkb 120.72.12020000.11 2013/02/25 06:53:45 vmaripal ship $ */
3 --
4 g_debug boolean := hr_utility.debug_enabled;
5 indent varchar2 (32767) := null;
6 g_package constant varchar2 (32) := 'hrentmnt.';
7 g_original_entry_id pay_element_entries_f.original_entry_id%type := null;
8 --
9 -- Record type to cache an element entry for use when splitting into two.
10 --
11 type t_ele_entry_rec is record
12 (cost_allocation_keyflex_id number,
13 creator_type varchar2(10),
14 entry_type varchar2(1),
15 comment_id number,
16 creator_id number,
17 reason varchar2(30),
18 target_entry_id number,
19
20 subpriority number,
21 personal_payment_method_id number,
22 date_earned date,
23
24 balance_adj_cost_flag varchar2(30),
25 source_asg_action_id number,
26 source_link_id number,
27 source_trigger_entry number,
28 source_period number,
29 source_run_type number,
30 source_start_date date,
31 source_end_date date,
32
33 attribute_category varchar2(30),
34 attribute1 varchar2(150),
35 attribute2 varchar2(150),
36 attribute3 varchar2(150),
37 attribute4 varchar2(150),
38 attribute5 varchar2(150),
39 attribute6 varchar2(150),
40 attribute7 varchar2(150),
41 attribute8 varchar2(150),
42 attribute9 varchar2(150),
43 attribute10 varchar2(150),
44 attribute11 varchar2(150),
45 attribute12 varchar2(150),
46 attribute13 varchar2(150),
47 attribute14 varchar2(150),
48 attribute15 varchar2(150),
49 attribute16 varchar2(150),
50 attribute17 varchar2(150),
51 attribute18 varchar2(150),
52 attribute19 varchar2(150),
53 attribute20 varchar2(150),
54
55 entry_information_category varchar2(30),
56 entry_information1 varchar2(150),
57 entry_information2 varchar2(150),
58 entry_information3 varchar2(150),
59 entry_information4 varchar2(150),
60 entry_information5 varchar2(150),
61 entry_information6 varchar2(150),
62 entry_information7 varchar2(150),
63 entry_information8 varchar2(150),
64 entry_information9 varchar2(150),
65 entry_information10 varchar2(150),
66 entry_information11 varchar2(150),
67 entry_information12 varchar2(150),
68 entry_information13 varchar2(150),
69 entry_information14 varchar2(150),
70 entry_information15 varchar2(150),
71 entry_information16 varchar2(150),
72 entry_information17 varchar2(150),
73 entry_information18 varchar2(150),
74 entry_information19 varchar2(150),
75 entry_information20 varchar2(150),
76 entry_information21 varchar2(150),
77 entry_information22 varchar2(150),
78 entry_information23 varchar2(150),
79 entry_information24 varchar2(150),
80 entry_information25 varchar2(150),
81 entry_information26 varchar2(150),
82 entry_information27 varchar2(150),
83 entry_information28 varchar2(150),
84 entry_information29 varchar2(150),
85 entry_information30 varchar2(150));
86 --
87 -- Record type and ref cursor type to hold assignment eligibility criteria, i.e.
88 -- payroll_id, organization_id, people_group_id etc.
89 -- Used by recreate_cached_entry and val_nonrec_entries.
90 type t_asg_criteria_rec is record (
91 organization_id number,
92 people_group_id number,
93 job_id number,
94 position_id number,
95 grade_id number,
96 location_id number,
97 employment_category varchar2(30),
98 payroll_id number,
99 pay_basis_id number,
100 business_group_id number);
101 --
102 type t_asg_criteria_cur is ref cursor return t_asg_criteria_rec;
103 --
104 -- Record type and ref cursor type to hold min/max dates of an element link
105 -- that matches certain eligibility criteria.
106 -- Used by recreate_cached_entry and val_nonrec_entries when fetching
107 -- alternative element links for existing invalidated entries.
108 type t_eligible_links_rec is record (
109 element_link_id number,
110 effective_start_date date,
111 effective_end_date date);
112 --
113 type t_eligible_links_cur is ref cursor return t_eligible_links_rec;
114 --
115 ------------------------------------------------------------------------------
116 -- NAME --
117 -- hrentmnt.min_eligibility_date --
118 -- --
119 -- DESCRIPTION --
120 -- Calculates the minimum date an element entries start date could be set --
121 -- to taking into account the eligibility of the element entry over time. --
122 -- NOTES --
123 -- New functionality added in response to WWBug 278071. This is used within --
124 -- adjust_entries_pqc to tighten up the setting of element entry start --
125 -- date in response to changing personal qualifying conditions. --
126 ------------------------------------------------------------------------------
127 --
128 function min_eligibility_date
129 (
130 p_element_link_id number,
131 p_assignment_id number,
132 p_range_start_date date,
133 p_range_end_date date
134 ) return date is
135 --
136 -- Returns the eligibility criteria for an element link.
137 --
138 cursor csr_link
139 (
140 p_element_link_id number
141 ) is
142 select EL.element_link_id,
143 EL.effective_start_date,
144 EL.link_to_all_payrolls_flag,
145 EL.payroll_id,
146 EL.job_id,
147 EL.grade_id,
148 EL.position_id,
149 EL.organization_id,
150 EL.location_id,
151 EL.pay_basis_id,
152 EL.employment_category,
153 EL.people_group_id
154 from pay_element_links_f EL
155 where EL.element_link_id = p_element_link_id
156 order by EL.effective_start_date;
157 --
158 -- Fetches all assignment rows for a given assignment that match specific
159 -- elgibility criteria over a range of dates NB. they are returned in
160 -- reverse order.
161 --
162 -- EL |-------------------------------A--------------------------------->
163 --
164 -- ASG |----A---|----A----|------B-----|-----A-----|------A-----|----B--->
165 --
166 -- Range |---------------------------------------------------->
167 --
168 -- Fetch 1 |------A-----|
169 -- Fetch 2 |-----A-----|
170 -- Fetch 3 |----A----|
171 --
172 cursor csr_assignment
173 (
174 p_element_link_id number,
175 p_assignment_id number,
176 p_range_start_date date,
177 p_range_end_date date,
178 p_payroll_id number,
179 p_link_to_all_payrolls_flag varchar2,
180 p_job_id number,
181 p_grade_id number,
182 p_position_id number,
183 p_organization_id number,
184 p_location_id number,
185 p_pay_basis_id number,
186 p_employment_category varchar2,
187 p_people_group_id number
188 ) is
189 select ASG.effective_start_date,
190 ASG.effective_end_date
191 from per_all_assignments_f ASG
192 where ASG.assignment_id = p_assignment_id
193 and ASG.assignment_type = 'E'
194 and ASG.effective_start_date <= p_range_end_date
195 and ASG.effective_end_date >= p_range_start_date
196 and ((p_payroll_id is not null and
197 p_payroll_id = ASG.payroll_id)
198 or (p_link_to_all_payrolls_flag = 'Y' and
199 ASG.payroll_id is not null)
200 or (p_link_to_all_payrolls_flag = 'N' and
201 p_payroll_id is null))
202 and (p_job_id is null or
203 p_job_id = ASG.job_id)
204 and (p_grade_id is null or
205 p_grade_id = ASG.grade_id)
206 and (p_position_id is null or
207 p_position_id = ASG.position_id)
208 and (p_organization_id is null or
209 p_organization_id = ASG.organization_id)
210 and (p_location_id is null or
211 p_location_id = ASG.location_id)
212 and (p_pay_basis_id is null or
213 p_pay_basis_id = ASG.pay_basis_id)
214 and (p_employment_category is null or
215 p_employment_category = ASG.employment_category)
216 and (p_people_group_id is null or
217 exists
218 (select null
219 from pay_assignment_link_usages_f ALU
220 where ALU.assignment_id = p_assignment_id
221 and ALU.element_link_id = p_element_link_id
222 and ALU.effective_start_date <= ASG.effective_end_date
223 and ALU.effective_end_date >= ASG.effective_start_date))
224 order by ASG.effective_start_date desc;
225 --
226 -- Record to hold a row fetched using the csr_link cursor.
227 --
228 v_link_rec csr_link%rowtype;
229 --
230 -- Record to hold a row fetched using the csr_link cursor.
231 --
232 v_asg_rec csr_assignment%rowtype;
233 --
234 -- Variables to hold the start and ends dates of the current assignment row.
235 --
236 v_asg_start_date date;
237 v_asg_end_date date;
238 --
239 procedure check_parameters is
240 begin
241 --
242 hr_utility.trace('In min_eligibility_date');
243 hr_utility.trace ('');
244 hr_utility.trace (' p_element_link_id = '
245 ||to_char (p_element_link_id));
246 hr_utility.trace (' p_assignment_id'
247 ||to_char (p_assignment_id));
248 hr_utility.trace (' p_range_start_date'
249 ||to_char (p_range_start_date));
250 hr_utility.trace (' p_range_end_date'
251 ||to_char (p_range_end_date));
252 hr_utility.trace ('');
253 --
254 end check_parameters;
255 --
256 begin
257 --
258 if g_debug then
259 check_parameters;
260 end if;
261 --
262 --
263 -- Fetch the first date effective row of the link NB. the criteria cannot
264 -- be date effectively changed on a link so the criteria should be the same
265 -- for all rows.
266 --
267 open csr_link(p_element_link_id);
268 fetch csr_link into v_link_rec;
269 if csr_link%notfound then
270 close csr_link;
271 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
272 hr_utility.set_message_token('PROCEDURE', 'hrentmnt.min_eligibility_date');
273 hr_utility.set_message_token('STEP','1');
274 hr_utility.raise_error;
275 end if;
276 close csr_link;
277 --
278 --
279 -- Open the cursor ready for processing.
280 --
281 open csr_assignment
282 (p_element_link_id,
283 p_assignment_id,
284 p_range_start_date,
285 p_range_end_date,
286 v_link_rec.payroll_id,
287 v_link_rec.link_to_all_payrolls_flag,
288 v_link_rec.job_id,
289 v_link_rec.grade_id,
290 v_link_rec.position_id,
291 v_link_rec.organization_id,
292 v_link_rec.location_id,
293 v_link_rec.pay_basis_id,
294 v_link_rec.employment_category,
295 v_link_rec.people_group_id);
296 --
297 --
298 -- Get first assignment row that matches the criteria. The assumption is
299 -- that the there should be at least one row that matches. This assumption
300 -- is based on the intended use of this function ie. an entry should already
301 -- exist for the assignment / link combination at the end of the seerch
302 -- range.
303 --
304 fetch csr_assignment into v_asg_rec;
305 if csr_assignment%notfound then
306 close csr_assignment;
307 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
308 hr_utility.set_message_token('PROCEDURE', 'hrentmnt.min_eligibility_date');
309 hr_utility.set_message_token('STEP','2');
310 hr_utility.raise_error;
311 end if;
312 --
313 --
314 -- Initialise variables holding the start and end dates of the current
315 -- assignment row from the cursor.
316 --
317 v_asg_start_date := v_asg_rec.effective_start_date;
318 v_asg_end_date := v_asg_rec.effective_end_date;
319 --
320 -- Fetch all the assignment rows that match the criteria over the range of
321 -- dates NB. they are returned in reverse order ie. latest first. Each row
322 -- is compared to the previous row to see if the eligibility criteria is
323 -- contiguous. If not then we have found the minimum date on which an
324 -- element entry could start given that it existed at the end of the range
325 -- of dates over which the assignment rows were found ie.
326 --
327 -- EE |-------------------------------------->
328 --
329 -- EL |----------------------------A------------------------------->
330 -- .
331 -- ASG |---A--|-B--|--A--|------A------|--------A-------|-----A----->
332 -- .
333 -- Range |---------------------|
334 -- '
335 -- New EE |------------------------------------------------>
336 --
337 loop
338 --
339 --
340 -- Get next assignment row that matches the criteria.
341 --
342 fetch csr_assignment into v_asg_rec;
343 --
344 -- Exit the loop if there are no more assignment rows or the new assignment
345 -- row is not contiguous with the previous assignment row found ie. there
346 -- is a break in eligibility.
347 --
348 exit when (csr_assignment%notfound or
349 v_asg_rec.effective_end_date <> v_asg_start_date - 1);
350 --
351 -- Set variables to hold the start and end dates of the current
352 -- assignment row from the cursor. These can then be used for comparisons
353 -- during the next iteration of the loop.
354 --
355 v_asg_start_date := v_asg_rec.effective_start_date;
356 v_asg_end_date := v_asg_rec.effective_end_date;
357 --
358 end loop;
359 --
360 --
361 close csr_assignment;
362 --
363 -- Calculate the minimum eligibility date based on when the element link
364 -- starts and the assignments eligibility for the link ie.
365 --
366 -- EL |----------------------------A------------------------------>
367 --
368 -- ASG |------A------|------A-------|---------------B----------------->
369 --
370 -- Range |--------------------------|
371 --
372 -- Compare |----------.... (EL)
373 -- |------A---.... (ASG)
374 --
375 -- Greatest |----------... (EL)
376 --
377 return(greatest(v_link_rec.effective_start_date,v_asg_start_date));
378 --
379 end min_eligibility_date;
380 --
381 ------------------------------------------------------------------------------
382 -- NAME --
383 -- hrentmnt.maintain_alu_asg --
384 -- --
385 -- DESCRIPTION --
386 -- Maintains the ALU's for an assignment. An ALU represnts the intersection --
387 -- of the people group flexfield on the assignment and element link. The --
388 -- ALU is used to speed up quickpicks where the partial matching of 30 --
389 -- columns causes performance problems. --
390 ------------------------------------------------------------------------------
391 --
392 procedure maintain_alu_asg
393 (
394 p_assignment_id number,
395 p_business_group_id number,
396 p_dt_mode varchar2,
397 p_old_people_group_id number,
398 p_new_people_group_id number,
399 p_old_organization_id number,
400 p_new_organization_id number,
401 p_old_employment_category varchar2,
402 p_new_employment_category varchar2,
403 p_old_payroll_id number,
404 p_new_payroll_id number
405 ) is
406 --
407 -- user defined types
408 --
409 type t_asg_rec is record
410 (effective_start_date date,
411 effective_end_date date,
412 people_group_id number,
413 id_flex_num number);
414 --
415 -- Bugfix 3720575
416 -- Added these extra user-defined types to enable bulk-inserts...
417 type t_alu_id is table of pay_assignment_link_usages_f.assignment_link_usage_id%type
418 index by binary_integer;
419 --
420 type t_alu_start_date is table of pay_assignment_link_usages_f.effective_start_date%type
421 index by binary_integer;
422 --
423 type t_alu_end_date is table of pay_assignment_link_usages_f.effective_end_date%type
424 index by binary_integer;
425 --
426 type t_alu_link_id is table of pay_assignment_link_usages_f.element_link_id%type
427 index by binary_integer;
428 --
429 -- find all instances of the assignment that has a people group
430 --
431 cursor csr_assignment
432 (
433 p_assignment_id number
434 ) is
435 select asg.effective_start_date,
436 asg.effective_end_date,
437 asg.people_group_id,
438 ppg.id_flex_num
439 from per_all_assignments_f asg,
440 pay_people_groups ppg
441 where asg.assignment_id = p_assignment_id
442 and asg.people_group_id is not null
443 and asg.assignment_type not in ('A' ,'O') -- non-applicant assignments only
444 and ppg.people_group_id = asg.people_group_id
445 order by asg.effective_start_date;
446 --
447 --
448 -- local variables
449 --
450 v_assignment t_asg_rec;
451 v_asg_start_date date;
452 v_asg_end_date date;
453 v_people_group_id number;
454 v_id_flex_num number;
455 v_alu_start_date date;
456 v_alu_end_date date;
457 v_alu_term_date date;
458 v_dummy_date date;
459 -- Bugfix 3720575
460 -- Added these extra local variables types to enable bulk-inserts...
461 v_counter number := 0;
462 v_alu_id_tab t_alu_id;
463 v_alu_start_date_tab t_alu_start_date;
464 v_alu_end_date_tab t_alu_end_date;
465 v_alu_link_id_tab t_alu_link_id;
466 --
467 l_proc varchar2 (72);
468 --
469 procedure check_parameters is
470 begin
471 --
472 hr_utility.trace('In '||l_proc);
473 hr_utility.trace ('');
474 hr_utility.trace (' p_assignment_id = '
475 ||to_char (p_assignment_id));
476 --
477 hr_utility.trace (' p_business_group_id = '
478 ||to_char (p_business_group_id));
479 --
480 hr_utility.trace (' p_dt_mode = '
481 ||p_dt_mode);
482 --
483 hr_utility.trace (' p_old_people_group_id = '
484 ||to_char (p_old_people_group_id));
485 --
486 hr_utility.trace (' p_new_people_group_id = '
487 ||to_char (p_new_people_group_id));
488 hr_utility.trace (' p_old_organization_id = '
489 ||to_char (p_old_organization_id));
490 hr_utility.trace (' p_new_organization_id = '
491 ||to_char (p_new_organization_id));
492 hr_utility.trace (' p_old_employment_category = '
493 ||p_old_employment_category);
494 hr_utility.trace (' p_new_employment_category = '
495 ||p_new_employment_category);
496 hr_utility.trace (' p_old_payroll_id = '
497 ||p_old_payroll_id);
498 hr_utility.trace (' p_new_payroll_id = '
499 ||p_new_payroll_id);
500 --
501 hr_utility.trace ('');
502 --
503 end check_parameters;
504 --
505 begin
506 --
507 if g_debug then
508 l_proc := g_package||'maintain_alu_asg';
509 check_parameters;
510 end if;
511 --
512 -- Bugfix 3720575
513 -- Only rebuild Assignment Link Usages when there has been a genuine change
514 -- in people group.
515 --
516 -- N.B: When both p_old_people_group_id and p_new_people_group_id are null
517 -- we want to perform the rebuild, this is probably because the calling
518 -- code is not setting these 2 params properly.
519 --
520 if (((nvl(p_old_people_group_id,-1) <> nvl(p_new_people_group_id,-2))
521 or (nvl(p_old_organization_id,-1) <> nvl(p_new_organization_id,-2))
522 or (nvl(p_old_payroll_id,-1) <> nvl(p_new_payroll_id,-2))
523 or (nvl(p_old_employment_category,'-1') <> nvl(p_new_employment_category,'-2')))
524 and p_dt_mode in ('UPDATE',
525 'UPDATE_CHANGE_INSERT',
526 'CORRECTION')
527 )
528 -- Always rebuild for the following DT modes:
529 or p_dt_mode in ('INSERT',
530 'UPDATE_OVERRIDE',
531 'DELETE',
532 'FUTURE_CHANGE',
533 'DELETE_NEXT_CHANGE',
534 'ZAP')
535 then --{ dt operation
536 --
537 open csr_assignment(p_assignment_id);
538 --
539 -- get first assignment row to verify assignment is candidate for alus
540 --
541 fetch csr_assignment into v_assignment;
542 if csr_assignment%found then -- { asg found
543 -- bug 9675136 replace the alu logic with a call to rebuild_alu so
544 -- code can be maintained in one place
545 pay_asg_link_usages_pkg.rebuild_alus(p_assignment_id);
546 --
547 end if; -- } asg found
548 --
549 close csr_assignment;
550 --
551 end if; --} dt operation
552 --
553 if g_debug then
554 hr_utility.trace('Out '||l_proc);
555 end if;
556 --
557 end maintain_alu_asg;
558 --
559 ------------------------------------------------------------------------------
560 -- NAME --
561 -- hrentmnt.remove_pay_proposals --
562 -- --
563 -- DESCRIPTION --
564 -- Salary Admin specific procedure that will remove a pay proposal if there --
565 -- are no element entries for the pay proposal. --
566 ------------------------------------------------------------------------------
567 --
568 procedure remove_pay_proposals
569 (
570 p_assignment_id number,
571 p_pay_proposal_id number
572 ) is
573 begin
574 --
575 -- Remove the pay proposal if there are no element entries for it.
576 --
577 -- bug 9648525 remove proposal components as well as proposal
578 delete from per_pay_proposal_components ppc
579 where ppc.pay_proposal_id in ( select pp.pay_proposal_id
580 from per_pay_proposals pp
581 where pp.assignment_id = p_assignment_id
582 and pp.pay_proposal_id = p_pay_proposal_id
583 and not exists
584 (select null
585 from pay_element_entries_f ee
586 where ee.assignment_id = pp.assignment_id
587 and ee.creator_type = 'SP'
588 and ee.creator_id = pp.pay_proposal_id));
589 --
590 delete from per_pay_proposals pp
591 where pp.assignment_id = p_assignment_id
592 and pp.pay_proposal_id = p_pay_proposal_id
593 and not exists
594 (select null
595 from pay_element_entries_f ee
596 where ee.assignment_id = pp.assignment_id
597 and ee.creator_type = 'SP'
598 and ee.creator_id = pp.pay_proposal_id);
599 end remove_pay_proposals;
600 --
601 ------------------------------------------------------------------------------
602 -- NAME --
603 -- hrentmnt.remove_quickpay_inclusions --
604 -- --
605 -- DESCRIPTION --
606 -- Removes any quickpay inclusions for which the element entry no longer --
607 -- date effectively exists NB. the procedure is used with the assumption --
608 -- that the caller has identified the period over which the element entry --
609 -- is being removed. Added due to WW Bug 269356. --
610 ------------------------------------------------------------------------------
611 --
612 procedure remove_quickpay_inclusions
613 (
614 p_element_entry_id number,
615 p_validation_start_date date,
616 p_validation_end_date date
617 ) is
618 begin
619 --
620 -- Remove any quickpay inclusions for the element entry where the element
621 -- entry no longer date effectively exists.
622 --
623 delete from pay_quickpay_inclusions pqi
624 where pqi.element_entry_id = p_element_entry_id
625 and exists
626 (select null
627 from pay_assignment_actions paa,
628 pay_payroll_actions ppa
629 where paa.assignment_action_id = pqi.assignment_action_id
630 and ppa.payroll_action_id = paa.payroll_action_id
631 and ppa.date_earned between p_validation_start_date
632 and p_validation_end_date);
633 --
634 end remove_quickpay_inclusions;
635 --
636 ------------------------------------------------------------------------------
637 -- NAME --
638 -- hrentmnt.remove_quickpay_exclusions --
639 -- --
640 -- DESCRIPTION --
641 -- Introduced via enhancement 3368211
642 -- Removes any quickpay exclusions for which the element entry no longer --
643 -- date effectively exists NB. the procedure is used with the assumption --
644 -- that the caller has identified the period over which the element entry --
645 -- is being removed. --
646 ------------------------------------------------------------------------------
647 --
648 procedure remove_quickpay_exclusions
649 (
650 p_element_entry_id number,
651 p_validation_start_date date,
652 p_validation_end_date date
653 ) is
654 begin
655 --
656 -- Remove any quickpay exclusions for the element entry where the element
657 -- entry no longer date effectively exists.
658 --
659 delete from pay_quickpay_exclusions pqe
660 where pqe.element_entry_id = p_element_entry_id
661 and exists
662 (select null
663 from pay_assignment_actions paa,
664 pay_payroll_actions ppa
665 where paa.assignment_action_id = pqe.assignment_action_id
666 and ppa.payroll_action_id = paa.payroll_action_id
667 and ppa.date_earned between p_validation_start_date
668 and p_validation_end_date);
669 --
670 end remove_quickpay_exclusions;
671 --
672 ------------------------------------------------------------------------------
673 -- NAME --
674 -- hrentmnt.check_payroll_changes_asg --
675 -- --
676 -- DESCRIPTION --
677 -- Makes sure that payroll exists for the lifetime of the assignment that --
678 -- uses it and also makes sure that no assignment actions are orphaned by a --
679 -- change in payroll. --
680 ------------------------------------------------------------------------------
681 --
682 procedure check_payroll_changes_asg
683 (
684 p_assignment_id number,
685 p_payroll_id number,
686 p_dt_mode varchar2,
687 p_validation_start_date date,
688 p_validation_end_date date
689 ) is
690 --
691 -- local variables
692 --
693 v_check_failed varchar2(1) := 'N';
694 --
695 --
696 cursor csr_del_or_zap is
697 select pa.effective_date
698 from pay_assignment_actions aa,
699 pay_payroll_actions pa
700 where aa.assignment_id = p_assignment_id
701 and pa.action_type not in ('X', 'BEE')
702 and pa.payroll_action_id = aa.payroll_action_id
703 and ((pa.effective_date >= p_validation_start_date)
704 or
705 (pa.date_earned >= p_validation_start_date));
706 --
707 cursor csr_not_insert(l_validation_start_date date) is
708 select pa.effective_date
709 from pay_assignment_actions aa,
710 pay_payroll_actions pa
711 where aa.assignment_id = p_assignment_id
712 and pa.payroll_action_id = aa.payroll_action_id
713 and pa.action_type not in ('X', 'BEE')
714 and ((pa.effective_date between l_validation_start_date
715 and p_validation_end_date)
716 or
717 (pa.date_earned between l_validation_start_date
718 and p_validation_end_date))
719 and not (exists
720 (select null
721 from per_all_assignments_f asg
722 where asg.assignment_id = p_assignment_id
723 and pa.effective_date
724 between asg.effective_start_date
725 and asg.effective_end_date
726 and asg.payroll_id + 0 = p_payroll_id)
727 and exists
728 (select null
729 from per_all_assignments_f asg
730 where asg.assignment_id = p_assignment_id
731 and nvl(pa.date_earned,pa.effective_date)
732 between asg.effective_start_date
733 and asg.effective_end_date
734 and asg.payroll_id + 0 = p_payroll_id));
735 --
736 cursor csr_valid_payroll (p_date date) is
737 select 'Y'
738 from sys.dual
739 where not exists
740 (select null
741 from per_all_assignments_f asg
742 where asg.assignment_id = p_assignment_id
743 and p_date
744 between asg.effective_start_date
745 and asg.effective_end_date
746 and asg.payroll_id + 0 = p_payroll_id);
747
748 cursor csr_asg is
749 select asg.effective_start_date
750 from per_all_assignments_f asg
751 where asg.assignment_id = p_assignment_id
752 and p_validation_start_date between
753 asg.effective_start_date and asg.effective_end_date;
754 --
755 l_dummy varchar2(1);
756 l_date date;
757 l_validation_start_date date;
758 --
759 procedure check_parameters is
760 --
761 begin
762 --
763 hr_utility.trace('In check_payroll_changes_asg');
764 hr_utility.trace ('');
765 hr_utility.trace (' p_assignment_id = '
766 ||to_char (p_assignment_id));
767 hr_utility.trace (' p_payroll_id = '
768 ||to_char (p_payroll_id));
769 hr_utility.trace (' p_dt_mode = '
770 ||p_dt_mode);
771 hr_utility.trace (' p_validation_start_date = '
772 ||to_char (p_validation_start_date));
773 hr_utility.trace (' p_validation_end_date = '
774 ||to_char (p_validation_end_date));
775 hr_utility.trace ('');
776 --
777 end check_parameters;
778 --
779 --
780 begin
781 --
782 g_debug := hr_utility.debug_enabled;
783 if g_debug then
784 check_parameters;
785 end if;
786 --
787 -- check to see that when a payroll is used on the assignment it exists for
788 -- the duration of the assignments use of the payroll.
789 --
790 if p_payroll_id is not null and not
791 (p_dt_mode = 'DELETE' or
792 p_dt_mode = 'ZAP') then
793 --
794 --
795 begin
796 select 'Y'
797 into v_check_failed
798 from sys.dual
799 where exists
800 (select null
801 from pay_payrolls_f pay
802 where pay.payroll_id = p_payroll_id
803 and p_validation_end_date >
804 (select max(pay2.effective_end_date)
805 from pay_payrolls_f pay2
806 where pay2.payroll_id = pay.payroll_id));
807 --
808 if v_check_failed = 'Y' then
809 hr_utility.set_message(801,'HR_6590_ASS_PYRLL_NOT_EXIST');
810 hr_utility.raise_error;
811 end if;
812 --
813 exception
814 when no_data_found then null;
815 end;
816 --
817 end if;
818 --
819 -- Checks to see if there are any assignment actions for the assignment
820 -- which are for a payroll that is not on the assignment record at the
821 -- point in time the assignment action was processed ie. there are no
822 -- orphaned assignment actions nb. the check is different for 'delete' and
823 -- 'zap' modes because there is not an new payroll to take into account.
824 --
825 if p_dt_mode = 'DELETE' or
826 p_dt_mode = 'ZAP' then
827 --
828 --
829 -- begin
830 -- select 'Y'
831 -- into v_check_failed
832 -- from sys.dual
833 -- where exists
834 -- (select null
835 -- from pay_assignment_actions aa,
836 -- pay_payroll_actions pa
837 -- where aa.assignment_id = p_assignment_id
838 -- and pa.action_type not in ('X', 'BEE')
839 -- and pa.payroll_action_id = aa.payroll_action_id
840 -- and ((pa.effective_date >= p_validation_start_date)
841 -- or
842 -- (pa.date_earned >= p_validation_start_date)));
843 -- exception
844 -- when no_data_found then null;
845 -- end;
846 --
847 --
848 for l_rec in csr_del_or_zap loop
849 --
850 if l_rec.effective_date >= p_validation_start_date then
851 l_date := l_rec.effective_date;
852 v_check_failed := 'Y';
853 exit;
854 else
855 hr_utility.set_message(801,'PAY_449682_RUN_EXISTS_FOR_DE');
856 hr_utility.set_warning;
857 end if;
858 --
859 end loop;
860 --
861 --
862 -- Check if there assignment actions that would be invalidated by the
863 -- change to the assignment.
864 --
865 elsif not p_dt_mode = 'INSERT' then
866 l_validation_start_date := p_validation_start_date;
867
868 if p_dt_mode = 'CORRECTION' then
869
870 -- bug 9594416 for CORRECTION validate from assignment effective_start_date
871 -- p_validation_start_date is passed in as session date but need to validate
872 -- from start of assignment
873
874 open csr_asg;
875 fetch csr_asg into l_validation_start_date;
876 close csr_asg;
877 end if;
878 --
879 --
880 -- begin
881 -- select 'Y'
882 -- into v_check_failed
883 -- from sys.dual
884 -- where exists
885 -- (select null
886 -- from pay_assignment_actions aa,
887 -- pay_payroll_actions pa
888 -- where aa.assignment_id = p_assignment_id
889 -- and pa.payroll_action_id = aa.payroll_action_id
890 -- and pa.action_type not in ('X', 'BEE')
891 -- and ((pa.effective_date between p_validation_start_date
892 -- and p_validation_end_date)
893 -- or
894 -- (pa.date_earned between p_validation_start_date
895 -- and p_validation_end_date))
896 -- and not (exists
897 -- (select null
898 -- from per_all_assignments_f asg
899 -- where asg.assignment_id = p_assignment_id
900 -- and pa.effective_date
901 -- between asg.effective_start_date
902 -- and asg.effective_end_date
903 -- and asg.payroll_id + 0 = p_payroll_id)
904 -- and exists
905 -- (select null
906 -- from per_all_assignments_f asg
907 -- where asg.assignment_id = p_assignment_id
908 -- and nvl(pa.date_earned,pa.effective_date)
909 -- between asg.effective_start_date
910 -- and asg.effective_end_date
911 -- and asg.payroll_id + 0 = p_payroll_id)));
912 -- exception
913 -- when no_data_found then null;
914 -- end;
915 --
916 for l_rec in csr_not_insert(l_validation_start_date) loop
917 --
918 if (l_rec.effective_date >= l_validation_start_date and
919 l_rec.effective_date <= p_validation_end_date) then
920 --
921 open csr_valid_payroll(l_rec.effective_date);
922 fetch csr_valid_payroll into l_dummy;
923 if csr_valid_payroll%found then
924 l_date := l_rec.effective_date;
925 v_check_failed := 'Y';
926 exit;
927 else
928 --
929 hr_utility.set_message(801,'PAY_449682_RUN_EXISTS_FOR_DE');
930 hr_utility.set_warning;
931 --
932 end if;
933 close csr_valid_payroll;
934 --
935 else
936 --
937 hr_utility.set_message(801,'PAY_449682_RUN_EXISTS_FOR_DE');
938 hr_utility.set_warning;
939 --
940 end if;
941 --
942 end loop;
943 --
944 end if;
945 --
946 if v_check_failed = 'Y' then
947 hr_utility.set_message(801,'HR_449757_ASS_ACTIONS_EXIST');
948 hr_utility.set_message_token('1', pay_wrapper_pkg.date_to_displaydate(l_date));
949 hr_utility.raise_error;
950 end if;
951 --
952 end check_payroll_changes_asg;
953 --
954 ------------------------------------------------------------------------------
955 -- NAME --
956 -- hrentmnt.cache_element_entry --
957 -- --
958 -- DESCRIPTION --
959 -- When splitting element entries ie. when there is a change in assignment --
960 -- criteria, the entry values are cached and used when creating the second --
961 -- part of the entry. --
962 ------------------------------------------------------------------------------
963 --
964 procedure cache_element_entry
965 (
966 p_element_entry_id number,
967 p_date date,
968 p_ele_entry_rec out nocopy hrentmnt.t_ele_entry_rec,
969 p_num_entry_values out nocopy number,
970 p_input_value_id_tbl out nocopy hr_entry.number_table,
971 p_entry_value_tbl out nocopy hr_entry.varchar2_table
972 ) is
973 --
974 -- Finds all entry values for an entry.
975 --
976 cursor csr_entry_values
977 (
978 p_element_entry_id number,
979 p_date date
980 ) is
981 select eev.input_value_id,
982 eev.screen_entry_value,
983 iv.uom,
984 -- change 115.30
985 iv.LOOKUP_TYPE,
986 -- Bugfix 2827092
987 iv.value_set_id,
988 et.input_currency_code
989 from pay_element_entry_values_f eev,
990 pay_input_values_f iv,
991 pay_element_types_f et
992 where eev.element_entry_id = p_element_entry_id
993 and iv.input_value_id = eev.input_value_id
994 and et.element_type_id = iv.element_type_id
995 and eev.effective_end_date = p_date
996 and p_date between iv.effective_start_date
997 and iv.effective_end_date
998 and p_date between et.effective_start_date
999 and et.effective_end_date;
1000 --
1001 -- Local Variables
1002 --
1003 v_ele_entry_rec hrentmnt.t_ele_entry_rec;
1004 v_num_values number := 0;
1005 v_input_value_id_tbl hr_entry.number_table;
1006 v_entry_value_tbl hr_entry.varchar2_table;
1007 v_db_format varchar2(60);
1008 v_screen_format varchar2(80);
1009 --
1010 procedure check_parameters is
1011 --
1012 begin
1013 --
1014 hr_utility.trace('In hrentmnt.cache_element_entry');
1015 --
1016 hr_utility.trace ('');
1017 hr_utility.trace (' p_element_entry_id = '
1018 ||to_char (p_element_entry_id));
1019 hr_utility.trace (' p_date = '
1020 ||to_char (p_date));
1021 hr_utility.trace ('');
1022 --
1023 end check_parameters;
1024 --
1025 begin
1026 --
1027 if g_debug then
1028 check_parameters;
1029 end if;
1030 --
1031 -- Fetch entry information into a record.
1032 --
1033 begin
1034 select ee.cost_allocation_keyflex_id,
1035 ee.creator_type,
1036 ee.entry_type,
1037 ee.comment_id,
1038 ee.creator_id,
1039 ee.reason,
1040 ee.target_entry_id,
1041 ee.subpriority,
1042 ee.personal_payment_method_id,
1043 ee.date_earned,
1044 ee.balance_adj_cost_flag,
1045 ee.source_asg_action_id,
1046 ee.source_link_id,
1047 ee.source_trigger_entry,
1048 ee.source_period,
1049 ee.source_run_type,
1050 ee.source_start_date,
1051 ee.source_end_date,
1052 ee.attribute_category,
1053 ee.attribute1,
1054 ee.attribute2,
1055 ee.attribute3,
1056 ee.attribute4,
1057 ee.attribute5,
1058 ee.attribute6,
1059 ee.attribute7,
1060 ee.attribute8,
1061 ee.attribute9,
1062 ee.attribute10,
1063 ee.attribute11,
1064 ee.attribute12,
1065 ee.attribute13,
1066 ee.attribute14,
1067 ee.attribute15,
1068 ee.attribute16,
1069 ee.attribute17,
1070 ee.attribute18,
1071 ee.attribute19,
1072 ee.attribute20,
1073 ee.entry_information_category,
1074 ee.entry_information1,
1075 ee.entry_information2,
1076 ee.entry_information3,
1077 ee.entry_information4,
1078 ee.entry_information5,
1079 ee.entry_information6,
1080 ee.entry_information7,
1081 ee.entry_information8,
1082 ee.entry_information9,
1083 ee.entry_information10,
1084 ee.entry_information11,
1085 ee.entry_information12,
1086 ee.entry_information13,
1087 ee.entry_information14,
1088 ee.entry_information15,
1089 ee.entry_information16,
1090 ee.entry_information17,
1091 ee.entry_information18,
1092 ee.entry_information19,
1093 ee.entry_information20,
1094 ee.entry_information21,
1095 ee.entry_information22,
1096 ee.entry_information23,
1097 ee.entry_information24,
1098 ee.entry_information25,
1099 ee.entry_information26,
1100 ee.entry_information27,
1101 ee.entry_information28,
1102 ee.entry_information29,
1103 ee.entry_information30
1104 into v_ele_entry_rec
1105 from pay_element_entries_f ee
1106 where ee.element_entry_id = p_element_entry_id
1107 and p_date between ee.effective_start_date
1108 and ee.effective_end_date;
1109 exception
1110 when no_data_found then
1111 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1112 hr_utility.set_message_token('PROCEDURE',
1113 'hrentmnt.cache_element_entry');
1114 hr_utility.set_message_token('STEP','1');
1115 hr_utility.raise_error;
1116 end;
1117 --
1118 -- Retrieve all entry values for the element entry and convert into screen
1119 -- format. Store these in a table to be used later by the element entry
1120 -- api call hr_entry_api.insert_element_entry.
1121 --
1122 for v_entry_value in csr_entry_values(p_element_entry_id,
1123 p_date) loop
1124 --
1125 v_screen_format := null; -- must be null at each loop.
1126 v_num_values := v_num_values + 1;
1127 v_input_value_id_tbl(v_num_values) := v_entry_value.input_value_id;
1128 --
1129 v_db_format := v_entry_value.screen_entry_value;
1130
1131 -- start of change 115.30
1132 if g_debug then
1133 hr_utility.trace('*****before*****');
1134 hr_utility.trace('*****v_entry_value.lookup_type>' ||
1135 v_entry_value.lookup_type || '<');
1136 hr_utility.trace('*****v_entry_value.value_set_id>' ||
1137 v_entry_value.value_set_id || '<');
1138 hr_utility.trace('*****v_entry_value.screen_entry_value>' ||
1139 v_entry_value.screen_entry_value || '<');
1140 end if;
1141 --
1142 -- if entry has lookup and the entry_value is not null,
1143 -- do special processing
1144 --
1145 if v_entry_value.lookup_type is not null
1146 and v_entry_value.screen_entry_value is not null
1147 then
1148 SELECT meaning
1149 INTO v_screen_format
1150 FROM HR_LOOKUPS
1151 WHERE lookup_type = v_entry_value.lookup_type
1152 and lookup_code = v_entry_value.screen_entry_value;
1153 -- Bugfix 2827092
1154 elsif v_entry_value.value_set_id is not null
1155 and v_entry_value.screen_entry_value is not null
1156 then
1157 --
1158 -- Entry value is validated by a value set
1159 -- We need to derive the screen format
1160 --
1161 v_screen_format := pay_input_values_pkg.decode_vset_value(
1162 p_value_set_id => v_entry_value.value_set_id,
1163 p_value_set_value => v_entry_value.screen_entry_value);
1164 --
1165 else
1166 --
1167 -- Convert entry value from DB format to screen format.
1168 --
1169 hr_chkfmt.changeformat
1170 (v_db_format,
1171 v_screen_format,
1172 v_entry_value.uom,
1173 v_entry_value.input_currency_code);
1174 end if;
1175
1176 if g_debug then
1177 hr_utility.trace('*****v_screen_format>' || v_screen_format || '<');
1178 hr_utility.trace('*****v_db_format>' || v_db_format || '<');
1179 hr_utility.trace('*****after*****');
1180 end if;
1181 -- end of change 115.30
1182
1183 --
1184 -- Store screen format in table.
1185 --
1186 v_entry_value_tbl(v_num_values) := v_screen_format;
1187 --
1188 end loop;
1189 --
1190 -- Assign out variables ie. entry record and tables containing entry values.
1191 --
1192 p_ele_entry_rec := v_ele_entry_rec;
1193 p_num_entry_values := v_num_values;
1194 p_input_value_id_tbl := v_input_value_id_tbl;
1195 p_entry_value_tbl := v_entry_value_tbl;
1196 --
1197 if g_debug then
1198 hr_utility.trace('Out hrentmnt.cache_element_entry');
1199 end if;
1200 --
1201 end cache_element_entry;
1202 --
1203 ------------------------------------------------------------------------------
1204 -- NAME --
1205 -- hrentmnt.check_entry_overridden --
1206 -- --
1207 -- DESCRIPTION --
1208 -- Checks to see if a change in the existence of a recurring element entry --
1209 -- will leave an override for it that will exist outside the recurring --
1210 -- entry. --
1211 ------------------------------------------------------------------------------
1212 --
1213 procedure check_entry_overridden
1214 (
1215 p_assignment_id number,
1216 p_element_entry_id number,
1217 p_validation_start_date date,
1218 p_validation_end_date date
1219 ) is
1220 --
1221 -- Local Variables
1222 --
1223 v_entry_overridden varchar2(1) := 'N';
1224 --
1225 procedure check_parameters is
1226 --
1227 begin
1228 --
1229 hr_utility.trace('In hrentmnt.check_entry_overridden');
1230 hr_utility.trace ('');
1231 hr_utility.trace(' p_assignment_id = '
1232 ||to_char (p_assignment_id));
1233 hr_utility.trace(' p_element_entry_id = '
1234 ||to_char (p_element_entry_id));
1235 hr_utility.trace(' p_validation_start_date = '
1236 ||to_char (p_validation_start_date));
1237 hr_utility.trace(' p_validation_end_date = '
1238 ||to_char (p_validation_end_date));
1239 hr_utility.trace ('');
1240 --
1241 end check_parameters;
1242 --
1243 begin
1244 --
1245 if g_debug then
1246 check_parameters;
1247 end if;
1248 --
1249 -- Make sure that the recurring entry about to be altered ie. deleted or
1250 -- shortened does not have an adjustment over the time of change. An
1251 -- adjustment's target entry should exist for the duration of the
1252 -- adjustment.
1253 --
1254 begin
1255 select 'Y'
1256 into v_entry_overridden
1257 from sys.dual
1258 where exists
1259 (select null
1260 from pay_element_entries_f ee
1261 where ee.assignment_id = p_assignment_id
1262 and ee.entry_type in ('A','R')
1263 and ee.target_entry_id = p_element_entry_id
1264 and ee.effective_start_date <= p_validation_end_date
1265 and ee.effective_end_date >= p_validation_start_date);
1266 exception
1267 when no_data_found then null;
1268 end;
1269 --
1270 if v_entry_overridden = 'Y' then
1271 hr_utility.set_message(801, 'HR_6304_ELE_ENTRY_DT_DEL_ADJ');
1272 hr_utility.raise_error;
1273 end if;
1274 --
1275 end check_entry_overridden;
1276 --
1277 --
1278 ------------------------------------------------------------------------------
1279 -- NAME --
1280 -- hrentmnt.log_entry_event --
1281 -- --
1282 -- DESCRIPTION --
1283 -- This procedure is used to record the events in pay_process_events. This --
1284 -- operation is normally carried out in the API, in below cases we don't --
1285 -- call API.
1286 -- 1) Backdating the start date of an entry. --
1287 -- 2) Extendinging the end date of an entry. --
1288 -- For test case Ref Bug#9197105
1289 ------------------------------------------------------------------------------
1290 --
1291 procedure log_entry_event (p_element_entry_id in pay_element_entries_f.element_entry_id%TYPE
1292 ,p_old_date in date
1293 ,p_new_date in date
1294 ,p_start_or_end_date in varchar2
1295 ,p_old_start_date in date
1296 ,p_old_end_date in date
1297 ,p_old_upd_action_id in pay_element_entries_f.updating_action_id%TYPE
1298 ,p_old_upd_action_type in pay_element_entries_f.updating_action_type%TYPE) is
1299
1300 cursor csr_entry is
1301 select ee.original_entry_id,
1302 ee.cost_allocation_keyflex_id,
1303 ee.creator_type,
1304 ee.entry_type,
1305 ee.comment_id,
1306 ee.creator_id,
1307 ee.reason,
1308 ee.target_entry_id,
1309 ee.subpriority,
1310 ee.personal_payment_method_id,
1311 ee.date_earned,
1312 ee.source_id,
1313 ee.balance_adj_cost_flag,
1314 ee.source_asg_action_id,
1315 ee.source_link_id,
1316 ee.source_trigger_entry,
1317 ee.source_period,
1318 ee.source_run_type,
1319 ee.source_start_date,
1320 ee.source_end_date,
1321 ee.assignment_id,
1322 ee.updating_action_id,
1323 ee.updating_action_type,
1324 ee.element_link_id,
1325 ee.element_type_id,
1326 ee.object_version_number,
1327 ee.attribute_category,
1328 ee.attribute1,
1329 ee.attribute2,
1330 ee.attribute3,
1331 ee.attribute4,
1332 ee.attribute5,
1333 ee.attribute6,
1334 ee.attribute7,
1335 ee.attribute8,
1336 ee.attribute9,
1337 ee.attribute10,
1338 ee.attribute11,
1339 ee.attribute12,
1340 ee.attribute13,
1341 ee.attribute14,
1342 ee.attribute15,
1343 ee.attribute16,
1344 ee.attribute17,
1345 ee.attribute18,
1346 ee.attribute19,
1347 ee.attribute20,
1348 ee.entry_information_category,
1349 ee.entry_information1,
1350 ee.entry_information2,
1351 ee.entry_information3,
1352 ee.entry_information4,
1353 ee.entry_information5,
1354 ee.entry_information6,
1355 ee.entry_information7,
1356 ee.entry_information8,
1357 ee.entry_information9,
1358 ee.entry_information10,
1359 ee.entry_information11,
1360 ee.entry_information12,
1361 ee.entry_information13,
1362 ee.entry_information14,
1363 ee.entry_information15,
1364 ee.entry_information16,
1365 ee.entry_information17,
1366 ee.entry_information18,
1367 ee.entry_information19,
1368 ee.entry_information20,
1369 ee.entry_information21,
1370 ee.entry_information22,
1371 ee.entry_information23,
1372 ee.entry_information24,
1373 ee.entry_information25,
1374 ee.entry_information26,
1375 ee.entry_information27,
1376 ee.entry_information28,
1377 ee.entry_information29,
1378 ee.entry_information30
1379 from pay_element_entries_f ee
1380 where ee.element_entry_id = p_element_entry_id
1381 and ee.effective_start_date = decode(p_start_or_end_date,
1382 'START',p_new_date,
1383 ee.effective_start_date)
1384 and ee.effective_end_date = decode(p_start_or_end_date,
1385 'END',p_new_date,
1386 ee.effective_end_date);
1387 v_entry_rec csr_entry%rowtype;
1388 l_proc varchar2(100) := g_package||' log_entry_event';
1389
1390 l_updating_action_id pay_element_entries_f.updating_action_id%TYPE;
1391 l_updating_action_type pay_element_entries_f.updating_action_type%TYPE;
1392 l_effective_start_date pay_element_entries_f.effective_start_date%TYPE;
1393 l_effective_end_date pay_element_entries_f.effective_end_date%TYPE;
1394
1395 l_datetrack_mode varchar2(10);
1396 l_effective_date date;
1397
1398 begin
1399 hr_utility.set_location(l_proc, 10);
1400 hr_utility.trace('p_element_entry_id => '||p_element_entry_id);
1401 hr_utility.trace('p_start_or_end_date => '||p_start_or_end_date);
1402 hr_utility.trace('p_old_date => '||p_old_date);
1403 hr_utility.trace('p_new_date => '||p_new_date);
1404 hr_utility.trace('p_old_start_date => '||p_old_start_date);
1405 hr_utility.trace('p_old_end_date => '||p_old_end_date);
1406
1407 /*Get the old entry data*/
1408 open csr_entry;
1409 fetch csr_entry into v_entry_rec;
1410 if (csr_entry%NOTFOUND) then
1411 close csr_entry;
1412 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
1413 hr_utility.set_message_token('PROCEDURE','hrentmnt.log_entry_event');
1414 hr_utility.set_message_token('STEP','1');
1415 hr_utility.raise_error;
1416 end if;
1417 l_updating_action_id := p_old_upd_action_id;
1418 l_updating_action_type := p_old_upd_action_type;
1419
1420 /*Determining the start date and end date of the new record*/
1421 if (p_start_or_end_date = 'START') then
1422 if (p_old_upd_action_type <> 'S') then
1423 l_updating_action_id := null;
1424 l_updating_action_type := null;
1425 end if;
1426 l_effective_start_date := p_new_date;
1427 l_effective_end_date := p_old_end_date;
1428 elsif (p_start_or_end_date = 'END') then
1429 if (p_old_upd_action_type <> 'U') then
1430 l_updating_action_id := null;
1431 l_updating_action_type := null;
1432 end if;
1433 l_effective_start_date := p_old_start_date;
1434 l_effective_end_date := p_new_date;
1435 end if;
1436 if (p_start_or_end_date = 'START') then
1437 l_datetrack_mode := 'UPDATE';
1438 l_effective_date := p_new_date;
1439 else
1440 l_datetrack_mode := 'DELETE';
1441 end if;
1442
1443 /*Find out the session date for effective date. Eventhough we pass the
1444 session date, the new date to which the record is back-dated/extended
1445 is inserted in EFFECTIVE_DATE of the PROCESS_EVENTS. If need comes
1446 need to revisit the code to store the proper date.*/
1447 begin
1448 select effective_date into l_effective_date
1449 from fnd_sessions where session_id = userenv('sessionid');
1450 exception
1451 when no_data_found then
1452 l_effective_date := p_new_date;
1453 end;
1454 hr_utility.trace('l_session_date => '||l_effective_date);
1455 hr_utility.trace('l_datetrack_mode => '||l_datetrack_mode);
1456 if (p_start_or_end_date = 'START' or p_start_or_end_date = 'END') then
1457 begin
1458 /*Calling the AFTER-UPDATE API call to log the event in
1459 PAY_PROCESS_EVENTS.*/
1460 pay_ele_rku.after_update
1461 (
1462 p_effective_date => l_effective_date
1463 ,p_validation_start_date => p_old_start_date
1464 ,p_validation_end_date => p_old_end_date
1465 ,p_datetrack_mode => l_datetrack_mode
1466 -- new values set
1467 ,p_element_entry_id => p_element_entry_id
1468 ,p_effective_start_date => l_effective_start_date
1469 ,p_effective_end_date => l_effective_end_date
1470 ,p_original_entry_id => v_entry_rec.original_entry_id
1471 ,p_creator_type => v_entry_rec.creator_type
1472 ,p_cost_allocation_keyflex_id => v_entry_rec.cost_allocation_keyflex_id
1473 -- Needed for row handler
1474 ,p_target_entry_id => null
1475 ,p_source_id => null
1476 ,p_balance_adj_cost_flag => null
1477 ,p_entry_type => null
1478 --
1479 ,p_updating_action_id => l_updating_action_id
1480 ,p_updating_action_type => l_updating_action_type
1481 ,p_comment_id => v_entry_rec.comment_id
1482 ,p_creator_id => v_entry_rec.creator_id
1483 ,p_reason => v_entry_rec.reason
1484 ,p_subpriority => v_entry_rec.subpriority
1485 ,p_date_earned => v_entry_rec.date_earned
1486 ,p_personal_payment_method_id => v_entry_rec.personal_payment_method_id
1487 ,p_attribute_category => v_entry_rec.attribute_category
1488 ,p_attribute1 => v_entry_rec.attribute1
1489 ,p_attribute2 => v_entry_rec.attribute2
1490 ,p_attribute3 => v_entry_rec.attribute3
1491 ,p_attribute4 => v_entry_rec.attribute4
1492 ,p_attribute5 => v_entry_rec.attribute5
1493 ,p_attribute6 => v_entry_rec.attribute6
1494 ,p_attribute7 => v_entry_rec.attribute7
1495 ,p_attribute8 => v_entry_rec.attribute8
1496 ,p_attribute9 => v_entry_rec.attribute9
1497 ,p_attribute10 => v_entry_rec.attribute10
1498 ,p_attribute11 => v_entry_rec.attribute11
1499 ,p_attribute12 => v_entry_rec.attribute12
1500 ,p_attribute13 => v_entry_rec.attribute13
1501 ,p_attribute14 => v_entry_rec.attribute14
1502 ,p_attribute15 => v_entry_rec.attribute15
1503 ,p_attribute16 => v_entry_rec.attribute16
1504 ,p_attribute17 => v_entry_rec.attribute17
1505 ,p_attribute18 => v_entry_rec.attribute18
1506 ,p_attribute19 => v_entry_rec.attribute19
1507 ,p_attribute20 => v_entry_rec.attribute20
1508 ,p_entry_information_category => v_entry_rec.entry_information_category
1509 ,p_entry_information1 => v_entry_rec.entry_information1
1510 ,p_entry_information2 => v_entry_rec.entry_information2
1511 ,p_entry_information3 => v_entry_rec.entry_information3
1512 ,p_entry_information4 => v_entry_rec.entry_information4
1513 ,p_entry_information5 => v_entry_rec.entry_information5
1514 ,p_entry_information6 => v_entry_rec.entry_information6
1515 ,p_entry_information7 => v_entry_rec.entry_information7
1516 ,p_entry_information8 => v_entry_rec.entry_information8
1517 ,p_entry_information9 => v_entry_rec.entry_information9
1518 ,p_entry_information10 => v_entry_rec.entry_information10
1519 ,p_entry_information11 => v_entry_rec.entry_information11
1520 ,p_entry_information12 => v_entry_rec.entry_information12
1521 ,p_entry_information13 => v_entry_rec.entry_information13
1522 ,p_entry_information14 => v_entry_rec.entry_information14
1523 ,p_entry_information15 => v_entry_rec.entry_information15
1524 ,p_entry_information16 => v_entry_rec.entry_information16
1525 ,p_entry_information17 => v_entry_rec.entry_information17
1526 ,p_entry_information18 => v_entry_rec.entry_information18
1527 ,p_entry_information19 => v_entry_rec.entry_information19
1528 ,p_entry_information20 => v_entry_rec.entry_information20
1529 ,p_entry_information21 => v_entry_rec.entry_information21
1530 ,p_entry_information22 => v_entry_rec.entry_information22
1531 ,p_entry_information23 => v_entry_rec.entry_information23
1532 ,p_entry_information24 => v_entry_rec.entry_information24
1533 ,p_entry_information25 => v_entry_rec.entry_information25
1534 ,p_entry_information26 => v_entry_rec.entry_information26
1535 ,p_entry_information27 => v_entry_rec.entry_information27
1536 ,p_entry_information28 => v_entry_rec.entry_information28
1537 ,p_entry_information29 => v_entry_rec.entry_information29
1538 ,p_entry_information30 => v_entry_rec.entry_information30
1539 ,p_object_version_number => v_entry_rec.object_version_number
1540 ,p_comments => null
1541 ,p_all_entry_values_null => null
1542 -- old values set
1543 ,p_effective_start_date_o => p_old_start_date
1544 ,p_effective_end_date_o => p_old_end_date
1545 ,p_cost_allocation_keyflex_id_o => v_entry_rec.cost_allocation_keyflex_id
1546 ,p_assignment_id_o => v_entry_rec.assignment_id
1547 ,p_updating_action_id_o => v_entry_rec.updating_action_id
1548 ,p_updating_action_type_o => v_entry_rec.updating_action_type
1549 ,p_element_link_id_o => v_entry_rec.element_link_id
1550 ,p_original_entry_id_o => v_entry_rec.original_entry_id
1551 ,p_creator_type_o => v_entry_rec.creator_type
1552 ,p_entry_type_o => v_entry_rec.entry_type
1553 ,p_comment_id_o => v_entry_rec.comment_id
1554 ,p_creator_id_o => v_entry_rec.creator_id
1555 ,p_reason_o => v_entry_rec.reason
1556 ,p_target_entry_id_o => v_entry_rec.target_entry_id
1557 ,p_source_id_o => v_entry_rec.source_id
1558 ,p_attribute_category_o => v_entry_rec.attribute_category
1559 ,p_attribute1_o => v_entry_rec.attribute1
1560 ,p_attribute2_o => v_entry_rec.attribute2
1561 ,p_attribute3_o => v_entry_rec.attribute3
1562 ,p_attribute4_o => v_entry_rec.attribute4
1563 ,p_attribute5_o => v_entry_rec.attribute5
1564 ,p_attribute6_o => v_entry_rec.attribute6
1565 ,p_attribute7_o => v_entry_rec.attribute7
1566 ,p_attribute8_o => v_entry_rec.attribute8
1567 ,p_attribute9_o => v_entry_rec.attribute9
1568 ,p_attribute10_o => v_entry_rec.attribute10
1569 ,p_attribute11_o => v_entry_rec.attribute11
1570 ,p_attribute12_o => v_entry_rec.attribute12
1571 ,p_attribute13_o => v_entry_rec.attribute13
1572 ,p_attribute14_o => v_entry_rec.attribute14
1573 ,p_attribute15_o => v_entry_rec.attribute15
1574 ,p_attribute16_o => v_entry_rec.attribute16
1575 ,p_attribute17_o => v_entry_rec.attribute17
1576 ,p_attribute18_o => v_entry_rec.attribute18
1577 ,p_attribute19_o => v_entry_rec.attribute19
1578 ,p_attribute20_o => v_entry_rec.attribute20
1579 ,p_entry_information_category_o => v_entry_rec.entry_information_category
1580 ,p_entry_information1_o => v_entry_rec.entry_information1
1581 ,p_entry_information2_o => v_entry_rec.entry_information2
1582 ,p_entry_information3_o => v_entry_rec.entry_information3
1583 ,p_entry_information4_o => v_entry_rec.entry_information4
1584 ,p_entry_information5_o => v_entry_rec.entry_information5
1585 ,p_entry_information6_o => v_entry_rec.entry_information6
1586 ,p_entry_information7_o => v_entry_rec.entry_information7
1587 ,p_entry_information8_o => v_entry_rec.entry_information8
1588 ,p_entry_information9_o => v_entry_rec.entry_information9
1589 ,p_entry_information10_o => v_entry_rec.entry_information10
1590 ,p_entry_information11_o => v_entry_rec.entry_information11
1591 ,p_entry_information12_o => v_entry_rec.entry_information12
1592 ,p_entry_information13_o => v_entry_rec.entry_information13
1593 ,p_entry_information14_o => v_entry_rec.entry_information14
1594 ,p_entry_information15_o => v_entry_rec.entry_information15
1595 ,p_entry_information16_o => v_entry_rec.entry_information16
1596 ,p_entry_information17_o => v_entry_rec.entry_information17
1597 ,p_entry_information18_o => v_entry_rec.entry_information18
1598 ,p_entry_information19_o => v_entry_rec.entry_information19
1599 ,p_entry_information20_o => v_entry_rec.entry_information20
1600 ,p_entry_information21_o => v_entry_rec.entry_information21
1601 ,p_entry_information22_o => v_entry_rec.entry_information22
1602 ,p_entry_information23_o => v_entry_rec.entry_information23
1603 ,p_entry_information24_o => v_entry_rec.entry_information24
1604 ,p_entry_information25_o => v_entry_rec.entry_information25
1605 ,p_entry_information26_o => v_entry_rec.entry_information26
1606 ,p_entry_information27_o => v_entry_rec.entry_information27
1607 ,p_entry_information28_o => v_entry_rec.entry_information28
1608 ,p_entry_information29_o => v_entry_rec.entry_information29
1609 ,p_entry_information30_o => v_entry_rec.entry_information30
1610 ,p_subpriority_o => v_entry_rec.subpriority
1611 ,p_personal_payment_method_id_o => v_entry_rec.personal_payment_method_id
1612 ,p_date_earned_o => v_entry_rec.date_earned
1613 ,p_object_version_number_o => v_entry_rec.object_version_number
1614 ,p_balance_adj_cost_flag_o => v_entry_rec.balance_adj_cost_flag
1615 ,p_comments_o => null
1616 ,p_element_type_id_o => v_entry_rec.element_type_id
1617 ,p_all_entry_values_null_o => null
1618 );
1619 exception
1620 when hr_api.cannot_find_prog_unit then
1621 hr_api.cannot_find_prog_unit_error
1622 (p_module_name => 'PAY_ELEMENT_ENTRIES_F'
1623 ,p_hook_type => 'AU'
1624 );
1625 end;
1626 end if;
1627
1628 end log_entry_event;
1629 --
1630 ------------------------------------------------------------------------------
1631 -- NAME --
1632 -- hrentmnt.validate_adjust_entry --
1633 -- --
1634 -- DESCRIPTION --
1635 -- Validates and adjusts recurring element entries. It accepts 2 modes ie. --
1636 -- UPDATE and DELETE NB. only UPDATE will result in changes to an --
1637 -- element entry. The other 2 modes only carry out validation / 3rd party --
1638 -- logic as it is assumed the DML is done elsewhere. This should be called --
1639 -- whenever an element entry is created , removed or changed. --
1640 ------------------------------------------------------------------------------
1641 --
1642 procedure validate_adjust_entry
1643 (
1644 p_mode varchar2,
1645 p_assignment_id number,
1646 p_element_entry_id number,
1647 p_start_or_end_date varchar2,
1648 p_old_date date,
1649 p_new_date date,
1650 p_effective_start_date date,
1651 p_effective_end_date date,
1652 p_entries_changed in out nocopy varchar2
1653 ) is
1654 --
1655 -- Cursor to fetch element information Nb. there are two distinct parts to
1656 -- the statement. The first part returns if the element entry is used for
1657 -- salary admin while the second returns if the element entry is not used
1658 -- for salary admin.
1659 --
1660 cursor csr_ele_info is
1661 select EL.element_type_id element_type_id,
1662 'Y' salary_element
1663 from pay_element_entries_f EE,
1664 pay_element_links_f EL
1665 where EE.element_entry_id = p_element_entry_id
1666 and EL.element_link_id = EE.element_link_id
1667 and nvl(p_old_date,p_effective_start_date) between
1668 EE.effective_start_date and EE.effective_end_date
1669 and nvl(p_old_date,p_effective_start_date) between
1670 EL.effective_start_date and EL.effective_end_date
1671 and exists (select null
1672 from pay_input_values_f IV,
1673 per_pay_bases PB
1674 where IV.element_type_id = EL.element_type_id
1675 and PB.input_value_id = IV.input_value_id)
1676 UNION ALL
1677 select EL.element_type_id element_type_id,
1678 'N' salary_element
1679 from pay_element_entries_f EE,
1680 pay_element_links_f EL
1681 where EE.element_entry_id = p_element_entry_id
1682 and EL.element_link_id = EE.element_link_id
1683 and nvl(p_old_date,p_effective_start_date) between
1684 EE.effective_start_date and EE.effective_end_date
1685 and nvl(p_old_date,p_effective_start_date) between
1686 EL.effective_start_date and EL.effective_end_date
1687 and not exists (select null
1688 from pay_input_values_f IV,
1689 per_pay_bases PB
1690 where IV.element_type_id = EL.element_type_id
1691 and PB.input_value_id = IV.input_value_id);
1692 --
1693 -- Local Variables
1694 --
1695 v_element_type_id number;
1696 v_change_start_date date;
1697 v_change_end_date date;
1698 v_ele_info_rec csr_ele_info%rowtype;
1699
1700 l_effective_start_date pay_element_entries_f.effective_start_date%TYPE;
1701 l_effective_end_date pay_element_entries_f.effective_end_date%TYPE;
1702 l_updating_action_type pay_element_entries_f.updating_action_type%TYPE;
1703 l_updating_action_id pay_element_entries_f.updating_action_id%TYPE;
1704 --
1705 procedure check_parameters is
1706 --
1707 begin
1708 --
1709 hr_utility.trace('In hrentmnt.validate_adjust_entry');
1710 hr_utility.trace ('');
1711 hr_utility.trace (' p_mode = '
1712 ||p_mode);
1713 hr_utility.trace (' p_assignment_id = '
1714 ||to_char (p_assignment_id));
1715 hr_utility.trace (' p_element_entry_id = '
1716 ||to_char (p_element_entry_id));
1717 hr_utility.trace (' p_start_or_end_date = '
1718 ||p_start_or_end_date);
1719 hr_utility.trace (' p_old_date = '
1720 ||to_char (p_old_date));
1721 hr_utility.trace (' p_new_date = '
1722 ||to_char (p_new_date));
1723 hr_utility.trace (' p_effective_start_date = '
1724 ||to_char (p_effective_start_date));
1725 hr_utility.trace (' p_effective_end_date = '
1726 ||to_char (p_effective_end_date));
1727 hr_utility.trace (' p_entries_changed = '
1728 ||p_entries_changed);
1729 hr_utility.trace ('');
1730 --
1731 end check_parameters;
1732 --
1733 begin
1734 --
1735 if g_debug then
1736 check_parameters;
1737 end if;
1738 --
1739 -- Get information about the element entry for future use.
1740 --
1741 open csr_ele_info;
1742 fetch csr_ele_info into v_ele_info_rec;
1743 if csr_ele_info%notfound then
1744 close csr_ele_info;
1745 --
1746 -- The cursor unexpectedly returned no rows. Present an error message
1747 -- which includes all the procedure's parameters to assist diagnosis of
1748 -- why this error occurred.
1749 --
1750 hr_utility.set_message(801, 'HR_51058_PAY_VALIDATE_ADJUST');
1751 hr_utility.set_message_token('P_MODE',p_mode);
1752 hr_utility.set_message_token('P_ASSIGNMENT_ID',p_assignment_id);
1753 hr_utility.set_message_token('P_ELEMENT_ENTRY_ID',p_element_entry_id);
1754 hr_utility.set_message_token('P_START_OR_END_DATE',p_start_or_end_date);
1755 hr_utility.set_message_token('P_OLD_DATE',p_old_date);
1756 hr_utility.set_message_token('P_NEW_DATE',p_new_date);
1757 hr_utility.set_message_token('P_EFFECTIVE_START_DATE',p_effective_start_date);
1758 hr_utility.set_message_token('P_EFFECTIVE_END_DATE',p_effective_end_date);
1759 hr_utility.set_message_token('P_ENTRIES_CHANGED',p_entries_changed);
1760 hr_utility.raise_error;
1761 end if;
1762 close csr_ele_info;
1763 --
1764 -- Set the dates over which the change is taking place.
1765 --
1766 if p_mode = 'DELETE' then
1767 --
1768 v_change_start_date := p_effective_start_date;
1769 v_change_end_date := p_effective_end_date;
1770 --
1771 elsif p_mode = 'UPDATE' then
1772 --
1773 v_change_start_date := least(p_old_date,p_new_date);
1774 v_change_end_date := greatest(p_old_date,p_new_date);
1775 --
1776 end if;
1777 --
1778 hr_entry.trigger_workload_shifting
1779 ('ELEMENT_ENTRY',
1780 p_assignment_id,
1781 v_change_start_date,
1782 v_change_end_date);
1783 --
1784 hr_entry.chk_element_entry_open
1785 (v_ele_info_rec.element_type_id,
1786 v_change_start_date,
1787 v_change_start_date,
1788 v_change_end_date,
1789 p_assignment_id);
1790 --
1791 -- When removing or shortening element entries need to
1792 --
1793 -- make sure that the element entry has not been overidden.
1794 -- remove orphaned quickpay inclusions.
1795 -- set flag to indicate that element entries have been affected.
1796 --
1797 if p_mode = 'DELETE' or
1798 (p_mode = 'UPDATE' and
1799 ((p_start_or_end_date = 'START' and
1800 p_old_date < p_new_date) or
1801 (p_start_or_end_date = 'END' and
1802 p_old_date > p_new_date))) then
1803 --
1804 hrentmnt.check_entry_overridden
1805 (p_assignment_id,
1806 p_element_entry_id,
1807 v_change_start_date,
1808 v_change_end_date);
1809 --
1810 -- Enhancement 3368211
1811 --
1812 -- Delete both QuickPay Inclusions AND Exclusions.
1813 --
1814 -- There is a chance the element entry id exists in both tables if
1815 -- any QuickPay assignment actions were created before the QuickPay
1816 -- Exclusions data model was in use.
1817 --
1818 hrentmnt.remove_quickpay_exclusions
1819 (p_element_entry_id,
1820 v_change_start_date,
1821 v_change_end_date);
1822 --
1823 hrentmnt.remove_quickpay_inclusions
1824 (p_element_entry_id,
1825 v_change_start_date,
1826 v_change_end_date);
1827 --
1828 -- Set flag to identify that element entries have been shortened
1829 -- or removed. If the entry is a salary entry then set the flag to 'S' so
1830 -- that a special warning can be given to the user. Once the flag has been
1831 -- set to 'S' then make sure that it cannot be set to 'Y' as this would
1832 -- cover the fact that a salary element entry had been affected.
1833 --
1834 if p_entries_changed IN ('S','I') then
1835 null;
1836 else
1837 if v_ele_info_rec.salary_element = 'Y' then
1838 p_entries_changed := 'S';
1839 else
1840 p_entries_changed := 'Y';
1841 end if;
1842 end if;
1843 --
1844 end if;
1845
1846 -- Update the covered dependents and beneficiaries for the element entry
1847 -- This should be called in both DELETE and UPDATE modes.
1848 --
1849 if p_start_or_end_date = 'START' then
1850 hr_entry.delete_covered_dependants(
1851 p_validation_start_date => p_old_date,
1852 p_element_entry_id => p_element_entry_id,
1853 p_start_date => p_new_date);
1854
1855 hr_entry.delete_beneficiaries(
1856 p_validation_start_date => p_old_date,
1857 p_element_entry_id => p_element_entry_id,
1858 p_start_date => p_new_date);
1859
1860 elsif p_start_or_end_date = 'END' then
1861 hr_entry.delete_covered_dependants(
1862 p_validation_start_date => p_old_date,
1863 p_element_entry_id => p_element_entry_id,
1864 p_end_date => p_new_date);
1865
1866 hr_entry.delete_beneficiaries(
1867 p_validation_start_date => p_old_date,
1868 p_element_entry_id => p_element_entry_id,
1869 p_end_date => p_new_date);
1870
1871 end if;
1872
1873 --
1874 -- When updating an element entry do the DML to move the start or end date.
1875 --
1876 -- Bug#9197105 : As we are calling DML so this event is not logging into the
1877 -- PAY_PROCESS_EVENTS table. So, after the DML is executed, we are calling
1878 -- AFTER-UPDATE API of element entries to log this event.
1879 hr_utility.trace('Mode => '||p_mode);
1880 if p_mode = 'UPDATE' then
1881 --
1882 if p_start_or_end_date = 'START' then
1883 --
1884 /*Collecting old data to push the details into PAY_PROCESS_EVENTS*/
1885 hr_utility.trace('Collecting the old data : For back-dating the start date');
1886 select ee.effective_start_date,
1887 ee.effective_end_date,
1888 ee.updating_action_id,
1889 ee.updating_action_type
1890 into l_effective_start_date,
1891 l_effective_end_date,
1892 l_updating_action_id,
1893 l_updating_action_type
1894 from pay_element_entries_f ee
1895 where ee.element_entry_id = p_element_entry_id
1896 and ee.effective_start_date = p_old_date;
1897
1898 /*Back-dating the start date of the entry.*/
1899 hr_utility.trace('Calling actual DML to back-date the effective start date');
1900 update pay_element_entries_f ee
1901 set ee.effective_start_date = p_new_date,
1902 ee.updating_action_id = decode(ee.updating_action_type, 'S', ee.updating_action_id,
1903 null),
1904 ee.updating_action_type = decode(ee.updating_action_type, 'S', 'S', null)
1905 where ee.element_entry_id = p_element_entry_id
1906 and ee.effective_start_date = p_old_date;
1907 --
1908 update pay_element_entry_values_f eev
1909 set eev.effective_start_date = p_new_date
1910 where eev.element_entry_id = p_element_entry_id
1911 and eev.effective_start_date = p_old_date;
1912 --
1913 elsif p_start_or_end_date = 'END' then
1914 --
1915 --
1916 /*Collecting old data to push the details into PAY_PROCESS_EVENTS*/
1917 hr_utility.trace('Collecting the old data : For extending the end date');
1918 select ee.effective_start_date,
1919 ee.effective_end_date,
1920 ee.updating_action_id,
1921 ee.updating_action_type
1922 into l_effective_start_date,
1923 l_effective_end_date,
1924 l_updating_action_id,
1925 l_updating_action_type
1926 from pay_element_entries_f ee
1927 where ee.element_entry_id = p_element_entry_id
1928 and ee.effective_end_date = p_old_date;
1929
1930 /*Extending the effective_end_date of the entry.*/
1931 hr_utility.trace('Calling actual DML to extend the effective end date');
1932 update pay_element_entries_f ee
1933 set ee.effective_end_date = p_new_date,
1934 ee.updating_action_id = decode(ee.updating_action_type, 'U', ee.updating_action_id,
1935 null),
1936 ee.updating_action_type = decode(ee.updating_action_type, 'U', 'U', null)
1937 where ee.element_entry_id = p_element_entry_id
1938 and ee.effective_end_date = p_old_date;
1939 --
1940 update pay_element_entry_values_f eev
1941 set eev.effective_end_date = p_new_date
1942 where eev.element_entry_id = p_element_entry_id
1943 and eev.effective_end_date = p_old_date;
1944 --
1945 end if;
1946 if p_start_or_end_date = 'START' or p_start_or_end_date = 'END' then
1947 /*As we have back-dated the entry's start date/extended the entry's end date,
1948 we need to log this event by calling AFTER-UPDATE trigger.*/
1949 hr_utility.trace('Calling LOG_ENTRY_EVENT to log the event of above date change');
1950 log_entry_event( p_element_entry_id => p_element_entry_id
1951 ,p_old_date => p_old_date
1952 ,p_new_date => p_new_date
1953 ,p_start_or_end_date => p_start_or_end_date
1954 ,p_old_start_date => l_effective_start_date
1955 ,p_old_end_date => l_effective_end_date
1956 ,p_old_upd_action_id => l_updating_action_id
1957 ,p_old_upd_action_type => l_updating_action_type);
1958 end if;
1959 end if;
1960 --
1961 if g_debug then
1962 hr_utility.trace('Out hrentmnt.validate_adjust_entry');
1963 end if;
1964 --
1965 end validate_adjust_entry;
1966 --
1967 ------------------------------------------------------------------------------
1968 -- NAME --
1969 -- hrentmnt.validate_purge --
1970 -- --
1971 -- DESCRIPTION --
1972 -- Validates whether it is legal to purge a particular element entry --
1973 -- depending on the setting of the HR_ELE_ENTRY_PURGE_CONTROL profile and --
1974 -- the setting of the elements non_payments_flag. --
1975 -- Because of the circumstances of calling, the only real way to tell if --
1976 -- element has been purged is to actually see if any rows remain on the --
1977 -- database. i.e. the user doesn't specify a dt mode that we can use. --
1978 ------------------------------------------------------------------------------
1979 --
1980 procedure validate_purge
1981 (
1982 p_element_entry_id in number,
1983 p_element_link_id in varchar2
1984 ) is
1985 l_prof_value varchar2(30);
1986 l_count number;
1987 l_non_payments_flag varchar2(30);
1988 begin
1989 -- Read the prof value.
1990 fnd_profile.get('HR_ELE_ENTRY_PURGE_CONTROL', l_prof_value);
1991 --
1992 -- See if profile is set in such a way that
1993 -- we need to perform validation.
1994 if l_prof_value is not null and l_prof_value <> 'A' then
1995 -- Use the element_link_id to obtain the non_payment_flag
1996 -- on the element classification. We are not concerned
1997 -- with datetrack joins here.
1998 begin
1999 select nvl(pec.non_payments_flag, 'N')
2000 into l_non_payments_flag
2001 from pay_element_links_f pel,
2002 pay_element_types_f pet,
2003 pay_element_classifications pec
2004 where pel.element_link_id = p_element_link_id
2005 and pet.element_type_id = pel.element_type_id
2006 and pec.classification_id = pet.classification_id
2007 and not exists (
2008 select null
2009 from pay_element_entries_f pee
2010 where pee.element_entry_id = p_element_entry_id)
2011 and rownum = 1;
2012 exception
2013 -- If we didn't get a row, this means that we haven't
2014 -- purged the entry. We therefore don't care and
2015 -- can immediately return.
2016 when no_data_found then return;
2017 end;
2018 --
2019 -- Check whether we need to raise error.
2020 if l_prof_value = 'N' or
2021 (l_prof_value = 'I' and l_non_payments_flag = 'N')
2022 then
2023 -- Either no entries can be purged or attempting to
2024 -- purge a payments type of entry when we shouldn't.
2025 hr_utility.set_message (800,'HR_33000_ENTRY_CANT_PURGE');
2026 hr_utility.raise_error;
2027 end if;
2028 --
2029 end if;
2030 --
2031 end validate_purge;
2032 --
2033 procedure maintain_dependent_entities(
2034 p_element_entry_id in number,
2035 p_element_entry_ESD in date,
2036 p_element_entry_EED in date,
2037 p_new_element_entry_id in number,
2038 p_new_element_entry_ESD in date,
2039 p_new_element_entry_EED in date)
2040 is
2041 begin
2042 hr_utility.trace('> hrentmnt.maintain_dependent_entities');
2043
2044 if g_debug then
2045 hr_utility.trace('p_element_entry_id >' || p_element_entry_id || '<');
2046 hr_utility.trace('p_element_entry_ESD >' || p_element_entry_ESD || '<');
2047 hr_utility.trace('p_element_entry_EED >' || p_element_entry_EED || '<');
2048
2049 hr_utility.trace('p_new_element_entry_id >' || p_new_element_entry_id || '<');
2050 hr_utility.trace('p_new_element_entry_ESD>' || p_new_element_entry_ESD || '<');
2051 hr_utility.trace('p_new_element_entry_EED>' || p_new_element_entry_EED || '<');
2052 end if;
2053
2054 hr_entry.maintain_covered_dependants(
2055 p_element_entry_id => p_element_entry_id
2056 ,p_element_entry_ESD => p_element_entry_ESD
2057 ,p_element_entry_EED => p_element_entry_EED
2058 ,p_new_element_entry_id => p_new_element_entry_id
2059 ,p_new_element_entry_ESD => p_new_element_entry_ESD
2060 ,p_new_element_entry_EED => p_new_element_entry_EED);
2061
2062 hr_entry.maintain_beneficiaries(
2063 p_element_entry_id => p_element_entry_id
2064 ,p_element_entry_ESD => p_element_entry_ESD
2065 ,p_element_entry_EED => p_element_entry_EED
2066 ,p_new_element_entry_id => p_new_element_entry_id
2067 ,p_new_element_entry_ESD => p_new_element_entry_ESD
2068 ,p_new_element_entry_EED => p_new_element_entry_EED);
2069
2070
2071 end maintain_dependent_entities;
2072 --
2073 ------------------------------------------------------------------------------
2074 -- NAME --
2075 -- hrentmnt.open_asg_criteria_cur --
2076 -- --
2077 -- SINCE --
2078 -- Bugfix 5584631 --
2079 -- --
2080 -- DESCRIPTION --
2081 -- --
2082 -- USAGES --
2083 -- Used by recreate_cached_entry and val_nonrec_entries. --
2084 ------------------------------------------------------------------------------
2085 procedure open_asg_criteria_cur (
2086 p_assignment_id in number,
2087 p_validation_start_date in date,
2088 p_asg_criteria_cv in out nocopy t_asg_criteria_cur -- cursor variable
2089 )
2090 is
2091 begin
2092 --
2093 open p_asg_criteria_cv for
2094 select asg.organization_id,
2095 asg.people_group_id,
2096 asg.job_id,
2097 asg.position_id,
2098 asg.grade_id,
2099 asg.location_id,
2100 asg.employment_category,
2101 asg.payroll_id,
2102 asg.pay_basis_id,
2103 asg.business_group_id
2104 from per_all_assignments_f asg
2105 where asg.assignment_id = p_assignment_id
2106 and p_validation_start_date between
2107 asg.effective_start_date and asg.effective_end_date;
2108 --
2109 end open_asg_criteria_cur;
2110 --
2111 ------------------------------------------------------------------------------
2112 -- NAME --
2113 -- hrentmnt.open_eligible_links_cur --
2114 -- --
2115 -- SINCE --
2116 -- Bugfix 5584631 --
2117 -- --
2118 -- DESCRIPTION --
2119 -- Opens a ref cursor variable for a cursor of element links for given --
2120 -- eligibility criteria and element type. --
2121 -- The OUT parameter, p_eligible_links_cv, is a pointer to the cursor that --
2122 -- is successfully opened. --
2123 -- --
2124 -- USAGES --
2125 -- Used by recreate_cached_entry and val_nonrec_entries. --
2126 ------------------------------------------------------------------------------
2127 procedure open_eligible_links_cur (
2128 p_assignment_id in number,
2129 p_validation_start_date in date,
2130 p_validation_end_date in date,
2131 p_element_type_id in number,
2132 p_organization_id in number,
2133 p_people_group_id in number,
2134 p_job_id in number,
2135 p_position_id in number,
2136 p_grade_id in number,
2137 p_location_id in number,
2138 p_employment_category in varchar2,
2139 p_payroll_id in number,
2140 p_pay_basis_id in number,
2141 p_business_group_id in number,
2142 p_eligible_links_cv in out nocopy t_eligible_links_cur -- cursor variable
2143 )
2144 is
2145 begin
2146 --
2147 open p_eligible_links_cv for
2148 select el.element_link_id,
2149 min(el.effective_start_date) effective_start_date,
2150 max(el.effective_end_date) effective_end_date
2151 from pay_element_links_f el
2152 where el.element_type_id = p_element_type_id
2153 and el.standard_link_flag = 'N'
2154 and el.business_group_id = p_business_group_id
2155 --
2156 -- make sure EL piece overlaps validation period
2157 --
2158 -- Bugfix 4627931
2159 -- Ensure the EL exists as at the validation start date.
2160 -- This is because hr_entry_api expects the EL to exist as at this date
2161 -- and raises error APP-PAY-07027 if it does not.
2162 -- Also, we should not re-create entries after there has been any gap in
2163 -- eligibility after the validation start date.
2164 and p_validation_start_date between el.effective_start_date and el.effective_end_date
2165 --
2166 -- match crieria on EL to that on asg
2167 --
2168 and (
2169 (el.payroll_id is not null and
2170 el.payroll_id = p_payroll_id)
2171 or
2172 (el.link_to_all_payrolls_flag = 'Y' and
2173 p_payroll_id is not null)
2174 or
2175 (el.link_to_all_payrolls_flag = 'N' and
2176 el.payroll_id is null)
2177 )
2178 and (el.job_id is null or
2179 el.job_id = p_job_id)
2180 and (el.grade_id is null or
2181 el.grade_id = p_grade_id)
2182 and (el.position_id is null or
2183 el.position_id = p_position_id)
2184 and (el.organization_id is null or
2185 el.organization_id = p_organization_id)
2186 and (el.location_id is null or
2187 el.location_id = p_location_id)
2188 and (el.employment_category is null or
2189 el.employment_category = p_employment_category)
2190 and (
2191 el.pay_basis_id = p_pay_basis_id
2192 or
2193 el.pay_basis_id is null and
2194 not exists
2195 (select pb.pay_basis_id
2196 from per_pay_bases pb,
2197 pay_input_values_f iv
2198 where iv.element_type_id = el.element_type_id
2199 and p_validation_start_date between
2200 iv.effective_start_date and iv.effective_end_date
2201 and pb.input_value_id = iv.input_value_id
2202 and pb.business_group_id = p_business_group_id
2203 )
2204 or
2205 el.pay_basis_id is null and
2206 exists
2207 (select pb.pay_basis_id
2208 from per_pay_bases pb,
2209 pay_input_values_f iv
2210 where iv.element_type_id = el.element_type_id
2211 and p_validation_start_date between
2212 iv.effective_start_date and iv.effective_end_date
2213 and pb.input_value_id = iv.input_value_id
2214 and pb.pay_basis_id = p_pay_basis_id
2215 )
2216 or
2217 el.pay_basis_id is null and
2218 p_pay_basis_id is null and
2219 exists
2220 (select pb.pay_basis_id
2221 from per_pay_bases pb,
2222 pay_input_values_f iv
2223 where iv.element_type_id = el.element_type_id
2224 and p_validation_start_date between
2225 iv.effective_start_date and iv.effective_end_date
2226 and pb.input_value_id = iv.input_value_id
2227 and pb.business_group_id = p_business_group_id
2228 )
2229 )
2230 and (el.people_group_id is null
2231 or exists
2232 (select null
2233 from pay_assignment_link_usages_f alu
2234 where alu.assignment_id = p_assignment_id
2235 and alu.element_link_id = el.element_link_id
2236 and alu.effective_start_date <= p_validation_end_date
2237 and alu.effective_end_date >= p_validation_start_date
2238 )
2239 )
2240 group by el.element_link_id;
2241 --
2242 end open_eligible_links_cur;
2243 --
2244 ------------------------------------------------------------------------------
2245 -- NAME --
2246 -- hrentmnt.recreate_cached_entry --
2247 -- --
2248 -- SINCE --
2249 -- Bugfix 5247607 --
2250 -- --
2251 -- DESCRIPTION --
2252 -- Attempts to recreate a deleted/end-dated recurring entry from cache, via --
2253 -- a different link if a suitable one exists. --
2254 -- The OUT parameter, p_entry_recreated, will be set to TRUE if the cached --
2255 -- entry is successfully recreated. --
2256 -- Otherwise, it will be FALSE. --
2257 ------------------------------------------------------------------------------
2258 procedure recreate_cached_entry (
2259 p_assignment_id in number,
2260 p_element_type_id in number,
2261 p_element_link_id in number,
2262 p_element_entry_id in number,
2263 p_validation_start_date in date,
2264 p_validation_end_date in date,
2265 p_ee_effective_start_date in date,
2266 p_ee_effective_end_date in date,
2267 p_ee_creator_type in varchar2,
2268 p_rec_ee in hrentmnt.t_ele_entry_rec,
2269 p_num_eevs in number,
2270 p_tbl_ivids in hr_entry.number_table,
2271 p_tbl_eevs in hr_entry.varchar2_table,
2272 p_entry_recreated out nocopy boolean
2273 )
2274 is
2275 --
2276 l_proc varchar2(80) := 'hrentmnt.recreate_cached_entry';
2277 l_asg_criteria_cv t_asg_criteria_cur;
2278 l_rec_asg_criteria t_asg_criteria_rec;
2279 l_eligible_links_cv t_eligible_links_cur;
2280 rec_eligible_links t_eligible_links_rec;
2281 l_entry_recreated boolean := false;
2282 l_prof_value varchar2(30);
2283 l_eeid_out number;
2284 l_calc_ee_esd date;
2285 l_calc_ee_eed date;
2286 l_ee_eed_out date;
2287 l_original_entry_id pay_element_entries_f.original_entry_id%type;
2288 v_original_entry_exists number; -- Bug 14184639
2289 sp_exists number; --Bug 9295968
2290 --
2291 begin
2292
2293 sp_exists :=0;
2294 --
2295 if g_debug then
2296 hr_utility.set_location(l_proc,10);
2297 hr_utility.trace('********** BEFORE OAB **********');
2298 end if;
2299
2300 /*Bug 9295968 Begin */
2301 begin
2302 select 1
2303 into sp_exists
2304 from per_assignments_f
2305 where assignment_id = p_assignment_id
2306 and pay_basis_id is not null
2307 and p_validation_start_date between effective_start_date and effective_end_date;
2308
2309 exception when no_data_found then
2310 sp_exists:=0;
2311 end;
2312 /*Bug 9295968 End */
2313 --
2314 -- Read the prof value
2315 --
2316 fnd_profile.get('PAY_ORIG_EL_BEHAVE', l_prof_value);
2317 if g_debug then
2318 hr_utility.trace('l_prof_value>' || l_prof_value || '<');
2319 end if;
2320 --
2321 -- Check if any other entries can be created up to the REE's EED,
2322 -- create REE from VSD to REE's EED
2323 -- nb. do not look for any new EEs if the EE being updated is a 'SP' EE
2324 --
2325 -- Modified for bug 10078286
2326 if l_prof_value is null and
2327 ((p_ee_creator_type = 'SP' AND sp_exists <> 0) OR p_ee_creator_type <> 'SP' ) then
2328 -- change 115.28
2329 -- and p_ee_creator_type <> 'SP' then (Commented for the bug fix 8779392,
2330 -- so that we check for SP EE also.)
2331 --
2332 if g_debug then
2333 hr_utility.set_location(l_proc,20);
2334 hr_utility.trace('EE being updated>' || p_element_entry_id || '<');
2335 hr_utility.trace('VSD>' || p_validation_start_date || '<');
2336 hr_utility.trace('VED>' || p_validation_end_date || '<');
2337 hr_utility.trace('EE ESD>' || p_ee_effective_start_date || '<');
2338 hr_utility.trace('EE EED>' || p_ee_effective_end_date || '<');
2339 end if;
2340 --
2341 -- Fetch the assignment criteria
2342 open_asg_criteria_cur(p_assignment_id, p_validation_start_date, l_asg_criteria_cv);
2343 fetch l_asg_criteria_cv into l_rec_asg_criteria;
2344 close l_asg_criteria_cv;
2345 --
2346 open_eligible_links_cur (
2347 p_assignment_id,
2348 -- Bugfix 5629530
2349 greatest(p_ee_effective_start_date, p_validation_start_date),
2350 least(p_ee_effective_end_date, p_validation_end_date),
2351 p_element_type_id,
2352 l_rec_asg_criteria.organization_id,
2353 l_rec_asg_criteria.people_group_id,
2354 l_rec_asg_criteria.job_id,
2355 l_rec_asg_criteria.position_id,
2356 l_rec_asg_criteria.grade_id,
2357 l_rec_asg_criteria.location_id,
2358 l_rec_asg_criteria.employment_category,
2359 l_rec_asg_criteria.payroll_id,
2360 l_rec_asg_criteria.pay_basis_id,
2361 l_rec_asg_criteria.business_group_id,
2362 l_eligible_links_cv
2363 );
2364 --
2365 loop
2366 --
2367 if g_debug then
2368 hr_utility.set_location(l_proc,25);
2369 end if;
2370 --
2371 fetch l_eligible_links_cv into rec_eligible_links;
2372 exit when l_eligible_links_cv%notfound;
2373 --
2374 if g_debug then
2375 hr_utility.set_location(l_proc,30);
2376 hr_utility.trace('***** element_link_id>' ||
2377 rec_eligible_links.element_link_id || '<');
2378 hr_utility.trace('***** ESD of EL>' ||
2379 rec_eligible_links.effective_start_date || '<');
2380 hr_utility.trace('***** EED of EL>' ||
2381 rec_eligible_links.effective_end_date || '<');
2382 end if;
2383 --
2384 l_calc_ee_esd := greatest(p_ee_effective_start_date,
2385 p_validation_start_date);
2386 l_calc_ee_eed := least(p_ee_effective_end_date,
2387 rec_eligible_links.effective_end_date);
2388 /* Bug 14184639 Changes start */
2389 l_original_entry_id := p_element_entry_id;
2390 hr_utility.trace('Before:l_original_entry_id: '||l_original_entry_id);
2391 begin
2392 select 1
2393 into v_original_entry_exists
2394 from sys.dual
2395 where exists
2396 (select null
2397 from pay_element_entries_f ee
2398 ,pay_element_links_f el
2399 ,pay_element_types_f et
2400 where ee.assignment_id = p_assignment_id
2401 and ee.element_entry_id = p_element_entry_id
2402 and ee.entry_type = 'E'
2403 and el.element_link_id = ee.element_link_id
2404 and ee.effective_start_date between el.effective_start_date
2405 and el.effective_end_date
2406 and et.element_type_id = el.element_type_id
2407 and ee.effective_start_date between et.effective_start_date
2408 and et.effective_end_date
2409 and et.processing_type = 'R');
2410 exception
2411 when no_data_found then
2412 l_original_entry_id := g_original_entry_id;
2413 end;
2414 hr_utility.trace('After:l_original_entry_id: '||l_original_entry_id);
2415 /* Bug 14184639 Changes end */
2416 --
2417 hr_entry_api.insert_element_entry(
2418 p_effective_start_date => l_calc_ee_esd,
2419 p_effective_end_date => l_ee_eed_out,
2420 p_element_entry_id => l_eeid_out,
2421 p_original_entry_id => l_original_entry_id, -- Bug fix 12364433
2422 p_assignment_id => p_assignment_id,
2423 p_element_link_id => rec_eligible_links.element_link_id,
2424 p_creator_type => p_rec_ee.creator_type,
2425 p_entry_type => p_rec_ee.entry_type,
2426 p_cost_allocation_keyflex_id
2427 => p_rec_ee.cost_allocation_keyflex_id,
2428 p_comment_id => p_rec_ee.comment_id,
2429 p_creator_id => p_rec_ee.creator_id,
2430 p_reason => p_rec_ee.reason,
2431 p_target_entry_id => p_rec_ee.target_entry_id,
2432 p_subpriority => p_rec_ee.subpriority,
2433 p_personal_payment_method_id
2434 => p_rec_ee.personal_payment_method_id,
2435 p_date_earned => p_rec_ee.date_earned,
2436 p_attribute_category => p_rec_ee.attribute_category,
2437 p_attribute1 => p_rec_ee.attribute1,
2438 p_attribute2 => p_rec_ee.attribute2,
2439 p_attribute3 => p_rec_ee.attribute3,
2440 p_attribute4 => p_rec_ee.attribute4,
2441 p_attribute5 => p_rec_ee.attribute5,
2442 p_attribute6 => p_rec_ee.attribute6,
2443 p_attribute7 => p_rec_ee.attribute7,
2444 p_attribute8 => p_rec_ee.attribute8,
2445 p_attribute9 => p_rec_ee.attribute9,
2446 p_attribute10 => p_rec_ee.attribute10,
2447 p_attribute11 => p_rec_ee.attribute11,
2448 p_attribute12 => p_rec_ee.attribute12,
2449 p_attribute13 => p_rec_ee.attribute13,
2450 p_attribute14 => p_rec_ee.attribute14,
2451 p_attribute15 => p_rec_ee.attribute15,
2452 p_attribute16 => p_rec_ee.attribute16,
2453 p_attribute17 => p_rec_ee.attribute17,
2454 p_attribute18 => p_rec_ee.attribute18,
2455 p_attribute19 => p_rec_ee.attribute19,
2456 p_attribute20 => p_rec_ee.attribute20,
2457 p_entry_information_category
2458 => p_rec_ee.entry_information_category,
2459 p_entry_information1 => p_rec_ee.entry_information1,
2460 p_entry_information2 => p_rec_ee.entry_information2,
2461 p_entry_information3 => p_rec_ee.entry_information3,
2462 p_entry_information4 => p_rec_ee.entry_information4,
2463 p_entry_information5 => p_rec_ee.entry_information5,
2464 p_entry_information6 => p_rec_ee.entry_information6,
2465 p_entry_information7 => p_rec_ee.entry_information7,
2466 p_entry_information8 => p_rec_ee.entry_information8,
2467 p_entry_information9 => p_rec_ee.entry_information9,
2468 p_entry_information10 => p_rec_ee.entry_information10,
2469 p_entry_information11 => p_rec_ee.entry_information11,
2470 p_entry_information12 => p_rec_ee.entry_information12,
2471 p_entry_information13 => p_rec_ee.entry_information13,
2472 p_entry_information14 => p_rec_ee.entry_information14,
2473 p_entry_information15 => p_rec_ee.entry_information15,
2474 p_entry_information16 => p_rec_ee.entry_information16,
2475 p_entry_information17 => p_rec_ee.entry_information17,
2476 p_entry_information18 => p_rec_ee.entry_information18,
2477 p_entry_information19 => p_rec_ee.entry_information19,
2478 p_entry_information20 => p_rec_ee.entry_information20,
2479 p_entry_information21 => p_rec_ee.entry_information21,
2480 p_entry_information22 => p_rec_ee.entry_information22,
2481 p_entry_information23 => p_rec_ee.entry_information23,
2482 p_entry_information24 => p_rec_ee.entry_information24,
2483 p_entry_information25 => p_rec_ee.entry_information25,
2484 p_entry_information26 => p_rec_ee.entry_information26,
2485 p_entry_information27 => p_rec_ee.entry_information27,
2486 p_entry_information28 => p_rec_ee.entry_information28,
2487 p_entry_information29 => p_rec_ee.entry_information29,
2488 p_entry_information30 => p_rec_ee.entry_information30,
2489 p_num_entry_values => p_num_eevs,
2490 p_input_value_id_tbl => p_tbl_ivids,
2491 p_entry_value_tbl => p_tbl_eevs
2492 );
2493 --
2494 if l_eeid_out is not null then
2495 -- Set flag to denote entry has been recreated
2496 l_entry_recreated := true;
2497 end if;
2498 --
2499 if g_debug then
2500 --
2501 hr_utility.set_location(l_proc,40);
2502 hr_utility.trace('***** new EE>' || l_eeid_out || '<');
2503 hr_utility.trace('***** actual ESD of new EE>' ||
2504 l_calc_ee_esd || '<');
2505 hr_utility.trace('***** actual EED of new EE>' ||
2506 l_ee_eed_out || '<');
2507 --
2508 end if;
2509 --
2510 if l_ee_eed_out > l_calc_ee_eed then
2511 --
2512 -- the above call creates the EE upto the least of the:
2513 -- EL's EED or
2514 -- asg piece's EED
2515 --
2516 -- if the EED of the created EE is greater than the calc
2517 -- EED, bring it back
2518 -- nb. only 1 EE exists at this stage, therefore no need
2519 -- to use ESD and EED
2520 --
2521 if g_debug then
2522 hr_utility.set_location(l_proc,50);
2523 hr_utility.trace('***** bring EED of new EE back');
2524 end if;
2525 --
2526 -- Change l_ee_eed_out here, for separate update to
2527 -- pay_element_entries_f, below, which *always* occurs.
2528 --
2529 l_ee_eed_out := l_calc_ee_eed;
2530 --
2531 update pay_element_entry_values_f eev
2532 set eev.effective_end_date = l_ee_eed_out
2533 where eev.element_entry_id = l_eeid_out;
2534 --
2535 end if;
2536 --
2537 -- Set attributes on pay_element_entries_f that are not supported by API.
2538 -- Also, effective_end_date of new entry is brought back here, if
2539 -- necessary.
2540 --
2541 update pay_element_entries_f pee
2542 set pee.effective_end_date = l_ee_eed_out,
2543 pee.balance_adj_cost_flag = p_rec_ee.balance_adj_cost_flag,
2544 pee.source_asg_action_id = p_rec_ee.source_asg_action_id,
2545 pee.source_link_id = p_rec_ee.source_link_id,
2546 pee.source_trigger_entry = p_rec_ee.source_trigger_entry,
2547 pee.source_period = p_rec_ee.source_period,
2548 pee.source_run_type = p_rec_ee.source_run_type,
2549 pee.source_start_date = p_rec_ee.source_start_date,
2550 pee.source_end_date = p_rec_ee.source_end_date
2551 where pee.element_entry_id = l_eeid_out
2552 and l_calc_ee_esd between
2553 pee.effective_start_date and pee.effective_end_date;
2554 --
2555 end loop;
2556 --
2557 close l_eligible_links_cv;
2558 --
2559 end if;
2560 --
2561 -- call routine to maintain entities with FKs to element entry
2562 -- row just date ended and newly created
2563 --
2564 if g_debug then
2565 hr_utility.set_location(l_proc,60);
2566 hr_utility.trace('***** maintain dependent entities');
2567 end if;
2568 --
2569 maintain_dependent_entities(
2570 p_element_entry_id,
2571 p_ee_effective_start_date,
2572 p_validation_start_date - 1,
2573 l_eeid_out,
2574 l_calc_ee_esd,
2575 l_calc_ee_eed
2576 );
2577 --
2578 if g_debug then
2579 hr_utility.set_location(l_proc,70);
2580 hr_utility.trace('********** AFTER OAB **********');
2581 end if;
2582 --
2583 p_entry_recreated := l_entry_recreated;
2584 --
2585 end recreate_cached_entry;
2586 --
2587 ------------------------------------------------------------------------------
2588 -- NAME --
2589 -- hrentmnt.remove_ineligible_recurring --
2590 -- --
2591 -- DESCRIPTION --
2592 -- Removes any recurring element entries for a particular assignment and --
2593 -- element link that exist within a specified period of time that are not --
2594 -- eligible, or exist beyond the start of the assignment's TERM_ASSIGN status.
2595 ------------------------------------------------------------------------------
2596 --
2597 procedure remove_ineligible_recurring
2598 (
2599 p_assignment_id number,
2600 p_entries_changed in out nocopy varchar2,
2601 p_validation_start_date date,
2602 p_validation_end_date date,
2603 p_dt_mode varchar2 default null
2604 ) is
2605 --
2606 -- Local Cursors
2607 --
2608 cursor csr_orphaned_entries
2609 (
2610 p_assignment_id number
2611 ) is
2612 select distinct ee.element_entry_id
2613 from pay_element_entries_f ee
2614 where ee.assignment_id = p_assignment_id;
2615 --
2616 cursor csr_entry
2617 (
2618 p_assignment_id number,
2619 p_validation_start_date date,
2620 p_validation_end_date date
2621 ) is
2622 select
2623 distinct
2624 ee.element_entry_id,
2625 ee.creator_type,
2626 ee.creator_id,
2627 ee.effective_start_date,
2628 ee.effective_end_date,
2629 el.element_link_id,
2630 el.standard_link_flag,
2631 el.element_type_id
2632 from
2633 pay_element_entries_f ee,
2634 pay_element_links_f el,
2635 pay_element_types_f et
2636 where ee.assignment_id = p_assignment_id
2637 and ee.effective_start_date <= p_validation_end_date
2638 and ee.effective_end_date >= p_validation_start_date
2639 and ee.entry_type='E'
2640 and ee.element_link_id=el.element_link_id
2641 and el.effective_start_date <= ee.effective_end_date
2642 and el.effective_end_date >= ee.effective_start_date
2643 -- start of change 115.18 --
2644 and ee.effective_start_date between
2645 el.effective_start_date and el.effective_end_date
2646 -- end of change 115.18 --
2647 and el.element_type_id=et.element_type_id
2648 and et.effective_start_date <= el.effective_end_date
2649 and et.effective_end_date >= el.effective_start_date
2650 -- start of change 115.19 --
2651 and ee.effective_start_date between
2652 et.effective_start_date and et.effective_end_date
2653 -- end of change 115.19 --
2654 and et.processing_type='R'
2655 and (
2656 not exists
2657 (select null
2658 from per_all_assignments_f asg
2659 where asg.assignment_id = ee.assignment_id
2660 /* Added Benefits assignment type to the below code to ensure
2661 removal of entries wont happen in the case of benifits
2662 assignment type also */
2663 and (asg.assignment_type = 'E' or asg.assignment_type='B')
2664 and asg.effective_start_date <= p_validation_end_date
2665 and asg.effective_end_date >= p_validation_start_date
2666 and ((el.payroll_id is not null and
2667 el.payroll_id = asg.payroll_id)
2668 or (el.link_to_all_payrolls_flag = 'Y' and
2669 asg.payroll_id is not null)
2670 or (el.payroll_id is null and
2671 el.link_to_all_payrolls_flag = 'N'))
2672 and (el.job_id is null or
2673 el.job_id = asg.job_id)
2674 and (el.grade_id is null or
2675 el.grade_id = asg.grade_id)
2676 and (el.position_id is null or
2677 el.position_id = asg.position_id)
2678 and (el.organization_id is null or
2679 el.organization_id = asg.organization_id)
2680 and (el.location_id is null or
2681 el.location_id = asg.location_id)
2682 -- start of change 115.22 --
2683 and (
2684 --
2685 -- if EL is associated with a pay basis then this clause fails
2686 --
2687 el.pay_basis_id is null and
2688 NOT EXISTS
2689 (SELECT pb.pay_basis_id
2690 FROM PER_PAY_BASES pb,
2691 PAY_INPUT_VALUES_F iv,
2692 PER_PAY_PROPOSALS pp
2693 WHERE iv.element_type_id = el.element_type_id
2694 and iv.effective_start_date <= asg.effective_end_date /*Bug 7662923 */
2695 and iv.effective_end_date >= asg.effective_start_date
2696 and pb.input_value_id = iv.input_value_id
2697 and pb.business_group_id = asg.business_group_id
2698 and pp.assignment_id = asg.assignment_id /*fix 176449*/
2699 )
2700 or
2701 --
2702 -- if EL is associated with a pay basis then the associated
2703 -- PB_ID must match the PB_ID on ASG
2704 --
2705 el.pay_basis_id is null and
2706 EXISTS
2707 (SELECT pb.pay_basis_id
2708 FROM PER_PAY_BASES pb,
2709 PAY_INPUT_VALUES_F iv
2710 WHERE iv.element_type_id = el.element_type_id
2711 and iv.effective_start_date <= asg.effective_start_date
2712 and iv.effective_end_date >= asg.effective_start_date
2713 and pb.input_value_id =
2714 iv.input_value_id
2715 and pb.pay_basis_id = asg.pay_basis_id
2716 )
2717 -- change 115.26
2718 or
2719 el.standard_link_flag = 'Y' and
2720 el.pay_basis_id is null and
2721 asg.pay_basis_id is null and
2722 EXISTS
2723 (SELECT pb.pay_basis_id
2724 FROM PER_PAY_BASES pb,
2725 PAY_INPUT_VALUES_F iv
2726 WHERE iv.element_type_id = el.element_type_id
2727 and iv.effective_start_date <= asg.effective_start_date
2728 and iv.effective_end_date >= asg.effective_start_date
2729 and pb.input_value_id =
2730 iv.input_value_id
2731 and pb.business_group_id = asg.business_group_id
2732 )
2733 or
2734 el.pay_basis_id = asg.pay_basis_id
2735 )
2736 -- end of change 115.22 --
2737 and (el.employment_category is null or
2738 el.employment_category = asg.employment_category)
2739 and (el.people_group_id is null or
2740 exists
2741 (select null
2742 from pay_assignment_link_usages_f alu
2743 where alu.assignment_id = ee.assignment_id
2744 and alu.element_link_id = ee.element_link_id
2745 and alu.effective_start_date <=
2746 asg.effective_end_date
2747 and alu.effective_end_date >=
2748 asg.effective_start_date))))
2749 ;
2750 --
2751 procedure check_parameters
2752 is
2753 --
2754 begin
2755 --
2756 hr_utility.trace('In hrentmnt.remove_ineligible_recurring');
2757 hr_utility.trace ('');
2758 hr_utility.trace (' p_assignment_id = '||to_char (p_assignment_id));
2759 hr_utility.trace (' p_entries_changed = '||p_entries_changed);
2760 hr_utility.trace (' p_validation_start_date = '||to_char(p_validation_start_date,'DD-MON-YYYY'));
2761 hr_utility.trace (' p_validation_end_date = '||to_char(p_validation_end_date,'DD-MON-YYYY'));
2762 hr_utility.trace (' p_dt_mode = '||p_dt_mode);
2763 hr_utility.trace ('');
2764 --
2765 end check_parameters;
2766 --
2767 --
2768 --
2769 -- Bugfix 4358408
2770 -- The 'do normal delete of REE', 'bring end date of current REE
2771 -- backwards' and 'move start date of current REE forwards' logic
2772 -- within this procedure has all been re-created as modular
2773 -- procedures (do_normal_delete_of_ree, bring_ree_end_date_backwards
2774 -- and bring_ree_start_date_forwards respectively).
2775 --
2776 procedure do_normal_delete_of_ree (
2777 p_assignment_id in number,
2778 p_element_type_id in number,
2779 p_element_link_id in number,
2780 p_element_entry_id in number,
2781 p_validation_start_date in date,
2782 p_validation_end_date in date,
2783 p_ee_effective_start_date in date,
2784 p_ee_effective_end_date in date,
2785 p_ee_creator_type in varchar2,
2786 p_ee_creator_id in number,
2787 p_entries_changed in out nocopy varchar2
2788 )
2789 is
2790 -- cursor added for 8870436
2791 CURSOR csr_bus_group(p_assignment_id number) IS
2792 SELECT business_group_id
2793 FROM per_all_assignments_f
2794 WHERE assignment_id = p_assignment_id;
2795
2796 -- cursor added for 8870436
2797 CURSOR csr_leg_grp(p_business_group_id number) IS
2798 SELECT LEGISLATION_CODE
2799 FROM per_business_groups
2800 where business_group_id=p_business_group_id;
2801
2802 l_rec_ee hrentmnt.t_ele_entry_rec;
2803 l_num_eevs number := 0;
2804 l_tbl_ivids hr_entry.number_table;
2805 l_tbl_eevs hr_entry.varchar2_table;
2806 l_entry_recreated boolean := false;
2807 -- below variables added for 8870436
2808 l_dyt_mode varchar2(75);
2809 l_business_group_id number;
2810 l_legislation_code varchar2(10);
2811 begin
2812 --
2813 if g_debug then
2814 hr_utility.trace ('***** doing normal delete of REE');
2815 hr_utility.trace ('***** caching EE before delete');
2816 end if;
2817 --
2818 hrentmnt.cache_element_entry(
2819 p_element_entry_id,
2820 p_ee_effective_end_date,
2821 l_rec_ee,
2822 l_num_eevs,
2823 l_tbl_ivids,
2824 l_tbl_eevs);
2825 --
2826 hrentmnt.validate_adjust_entry
2827 ('DELETE',
2828 p_assignment_id,
2829 p_element_entry_id,
2830 null,
2831 null,
2832 null,
2833 p_ee_effective_start_date,
2834 p_ee_effective_end_date,
2835 p_entries_changed);
2836 --
2837 /* Bug 14184639 Changes start */
2838 select ee.original_entry_id
2839 into g_original_entry_id
2840 from pay_element_entries_f ee
2841 where ee.element_entry_id = p_element_entry_id
2842 and ee.effective_start_date >= p_ee_effective_start_date
2843 and ee.effective_end_date <= p_ee_effective_end_date;
2844 /* Bug 14184639 Changes end */
2845 delete from pay_element_entry_values_f eev
2846 where eev.element_entry_id = p_element_entry_id
2847 and eev.effective_start_date >= p_ee_effective_start_date
2848 and eev.effective_end_date <= p_ee_effective_end_date;
2849 --
2850 delete from pay_element_entries_f ee
2851 where ee.element_entry_id = p_element_entry_id
2852 and ee.effective_start_date >= p_ee_effective_start_date
2853 and ee.effective_end_date <= p_ee_effective_end_date;
2854 --
2855 -- Attempt to recreate cached entry before doing further deletes
2856 --
2857 recreate_cached_entry (
2858 p_assignment_id,
2859 p_element_type_id,
2860 p_element_link_id,
2861 p_element_entry_id,
2862 p_validation_start_date,
2863 p_validation_end_date,
2864 p_ee_effective_start_date,
2865 p_ee_effective_end_date,
2866 p_ee_creator_type,
2867 l_rec_ee,
2868 l_num_eevs,
2869 l_tbl_ivids,
2870 l_tbl_eevs,
2871 l_entry_recreated
2872 );
2873 --
2874 if not l_entry_recreated then
2875 --
2876 -- Cached entry was not recreated so proceed with deletes
2877 if g_debug then
2878 hr_utility.trace(' Cached entry not recreated. Continuing with delete.');
2879 end if;
2880 --
2881 -- Only delete grossup balance exclusion rows if we are purging the
2882 -- entry.
2883 --
2884 delete from pay_grossup_bal_exclusions exc
2885 where exc.source_id = p_element_entry_id
2886 and exc.source_type = 'EE'
2887 and not exists
2888 ( select null
2889 from pay_element_entries_f pee
2890 where pee.element_entry_id = p_element_entry_id);
2891 --
2892 -- Call the routine that checks whether an illegal purge
2893 -- has occurred (i.e. disallowed by profile).
2894 hrentmnt.validate_purge(p_element_entry_id, p_element_link_id);
2895 --
2896 -- Salary Admin entry is being removed. See if the pay proposal is used by
2897 -- any other entry. If not then it is removed.
2898 --
2899 if p_ee_creator_type = 'SP' then
2900 --
2901 hrentmnt.remove_pay_proposals
2902 (p_assignment_id,
2903 p_ee_creator_id);
2904 --
2905 end if;
2906 --
2907 -- code for bug 8870436 starts
2908 l_dyt_mode := pay_dyn_triggers.g_dyt_mode;
2909 pay_dyn_triggers.g_dyt_mode := 'ZAP';
2910 --
2911 open csr_bus_group(p_assignment_id);
2912 fetch csr_bus_group into l_business_group_id;
2913 close csr_bus_group;
2914 --
2915 open csr_leg_grp(l_business_group_id);
2916 fetch csr_leg_grp into l_legislation_code;
2917 close csr_leg_grp;
2918
2919 pay_continuous_calc.element_entries_ard(
2920 p_business_group_id => l_business_group_id,
2921 p_legislation_code => l_legislation_code,
2922 p_assignment_id => p_assignment_id,
2923 p_old_ELEMENT_ENTRY_ID => p_element_entry_id,
2924 p_old_effective_start_date => p_ee_effective_start_date,
2925 p_new_effective_start_date => null,
2926 p_old_effective_end_date => p_ee_effective_end_date,
2927 p_new_effective_end_date => null,
2928 p_old_ELEMENT_TYPE_ID => p_element_type_id
2929 );
2930 --
2931 pay_dyn_triggers.g_dyt_mode := l_dyt_mode;
2932 -- code for bug 8870436 ends
2933 end if;
2934 --
2935 end do_normal_delete_of_ree;
2936 --
2937 --
2938 -- bring_ree_end_date_backwards:
2939 -- ***** updating "end" date of current REE backwards *****
2940 -- ***** VSD|<----- |VED *****
2941 -- ***** current |-----------------| *****
2942 --
2943 procedure bring_ree_end_date_backwards (
2944 p_assignment_id in number,
2945 p_element_type_id in number,
2946 p_element_link_id in number,
2947 p_element_entry_id in number,
2948 p_validation_start_date in date,
2949 p_validation_end_date in date,
2950 p_ee_effective_start_date in date,
2951 p_ee_effective_end_date in date,
2952 p_ee_creator_type in varchar2,
2953 p_ee_creator_id in number,
2954 p_entries_changed in out nocopy varchar2
2955 )
2956 is
2957 --
2958 CURSOR csr_bus_group(p_assignment_id number) IS
2959 SELECT business_group_id
2960 FROM per_all_assignments_f
2961 WHERE assignment_id = p_assignment_id;
2962
2963 /*Cursor added for bug:7440183for getting leg code */
2964 CURSOR csr_leg_grp(p_business_group_id number) IS
2965 SELECT LEGISLATION_CODE
2966 FROM per_business_groups
2967 where business_group_id=p_business_group_id;
2968
2969 --
2970 l_rec_ee hrentmnt.t_ele_entry_rec;
2971 l_num_eevs number := 0;
2972 l_tbl_ivids hr_entry.number_table;
2973 l_tbl_eevs hr_entry.varchar2_table;
2974 l_entry_recreated boolean := false;
2975 l_dyt_mode varchar2(75);
2976 l_business_group_id number;
2977 l_legislation_code varchar2(10);
2978 --
2979 begin
2980 --
2981 if g_debug then
2982 hr_utility.trace ('***** updating "end" date of current REE backwards *****');
2983 hr_utility.trace ('***** VSD|<----- |VED *****');
2984 hr_utility.trace ('***** current |-----------------| *****');
2985 end if;
2986 --
2987 hrentmnt.validate_adjust_entry
2988 ('DELETE',
2989 p_assignment_id,
2990 p_element_entry_id,
2991 null,
2992 null,
2993 null,
2994 --
2995 -- bugfix 1115901
2996 --
2997 p_validation_start_date,
2998 p_ee_effective_end_date,
2999 p_entries_changed);
3000 --
3001 -- update first piece of REE that crosses eligibility boundary,
3002 -- do not delete as this REE cannot be recreated later,
3003 -- update its EED so that it is a day less than the VSD
3004 --
3005 UPDATE PAY_ELEMENT_ENTRY_VALUES_F eev
3006 SET eev.effective_end_date = p_validation_start_date - 1
3007 WHERE eev.element_entry_id = p_element_entry_id
3008 and eev.effective_start_date < p_validation_start_date
3009 -- Change 115.60
3010 -- and eev.effective_end_date > p_validation_start_date
3011 and eev.effective_end_date >= p_validation_start_date
3012 -- End of change 115.60
3013 ;
3014 --
3015 UPDATE PAY_ELEMENT_ENTRIES_F ee
3016 SET ee.effective_end_date = p_validation_start_date - 1,
3017 ee.updating_action_id = decode(ee.updating_action_type, 'U', ee.updating_action_id,
3018 null),
3019 ee.updating_action_type = decode(ee.updating_action_type, 'U', 'U', null)
3020 WHERE ee.element_entry_id = p_element_entry_id
3021 and ee.effective_start_date < p_validation_start_date
3022 -- Change 115.60
3023 -- and ee.effective_end_date > p_validation_start_date
3024 and ee.effective_end_date >= p_validation_start_date
3025 -- End of change 115.60
3026 ;
3027 --
3028 -- take a copy of the updated EE as these details will be used
3029 -- to create the new EE
3030 -- Bugfix 4520103
3031 -- Use p_validation_start_date - 1 as this is the new effective end
3032 -- date of the entry.
3033 --
3034 hrentmnt.cache_element_entry(
3035 p_element_entry_id,
3036 p_validation_start_date - 1,
3037 l_rec_ee,
3038 l_num_eevs,
3039 l_tbl_ivids,
3040 l_tbl_eevs);
3041 --
3042 recreate_cached_entry (
3043 p_assignment_id,
3044 p_element_type_id,
3045 p_element_link_id,
3046 p_element_entry_id,
3047 p_validation_start_date,
3048 p_validation_end_date,
3049 p_ee_effective_start_date,
3050 p_ee_effective_end_date,
3051 p_ee_creator_type,
3052 l_rec_ee,
3053 l_num_eevs,
3054 l_tbl_ivids,
3055 l_tbl_eevs,
3056 l_entry_recreated
3057 );
3058
3059 -- Bug 6164943 - Log an event in PAY_PROCESS_EVENTS if the entry is end dated
3060 -- permanently
3061
3062 if(not l_entry_recreated) then
3063 --
3064 l_dyt_mode := pay_dyn_triggers.g_dyt_mode;
3065 pay_dyn_triggers.g_dyt_mode := 'DELETE';
3066 --
3067 open csr_bus_group(p_assignment_id);
3068 fetch csr_bus_group into l_business_group_id;
3069 close csr_bus_group;
3070 --
3071 open csr_leg_grp(l_business_group_id);
3072 fetch csr_leg_grp into l_legislation_code;
3073 close csr_leg_grp;
3074
3075 /* Changed the null value for p_legislation_code to the actual
3076 leg code for fixing bug 7440183 */
3077
3078 pay_continuous_calc.element_entries_ard(
3079 p_business_group_id => l_business_group_id,
3080 p_legislation_code => l_legislation_code,
3081 p_assignment_id => p_assignment_id,
3082 p_old_ELEMENT_ENTRY_ID => p_element_entry_id,
3083 p_old_effective_start_date => p_ee_effective_start_date,
3084 p_new_effective_start_date => p_ee_effective_start_date,
3085 p_old_effective_end_date => p_ee_effective_end_date,
3086 p_new_effective_end_date => p_validation_start_date -1,
3087 p_old_ELEMENT_TYPE_ID => p_element_type_id
3088 );
3089 --
3090 pay_dyn_triggers.g_dyt_mode := l_dyt_mode;
3091 --
3092 end if;
3093 --
3094 end bring_ree_end_date_backwards;
3095 --
3096 --
3097 -- bring_ree_start_date_forwards:
3098 -- ***** updating "start" date of current REE forwards *****
3099 -- ***** VSD| ----->|VED *****
3100 -- ***** current |-----------------> *****
3101 --
3102 procedure bring_ree_start_date_forwards (
3103 p_assignment_id in number,
3104 p_element_entry_id in number,
3105 p_ee_effective_start_date in date,
3106 p_validation_end_date in date,
3107 p_ee_creator_type in varchar2,
3108 p_ee_creator_id in number,
3109 p_entries_changed in out nocopy varchar2
3110 )
3111 is
3112 /* Added for bug #9370749 */
3113 CURSOR csr_bus_group(p_assignment_id number) IS
3114 SELECT business_group_id
3115 FROM per_all_assignments_f
3116 WHERE assignment_id = p_assignment_id;
3117
3118 CURSOR csr_leg_grp(p_business_group_id number) IS
3119 SELECT LEGISLATION_CODE
3120 FROM per_business_groups
3121 where business_group_id=p_business_group_id;
3122
3123 CURSOR csr_ele_entry_details(p_element_entry_id number, p_date in date) IS
3124 SELECT *
3125 from pay_element_entries_f
3126 where element_entry_id = p_element_entry_id
3127 and p_date between effective_start_date and effective_end_date;
3128
3129 l_business_group_id number;
3130 l_legislation_code varchar2(10);
3131 l_ele_ent_rec csr_ele_entry_details%rowtype;
3132 l_dyt_mode varchar2(75);
3133 /* End for bug #9370749 */
3134
3135 begin
3136 --
3137 if g_debug then
3138 hr_utility.trace ('***** updating "start" date of current REE forwards *****');
3139 hr_utility.trace ('***** VSD| ----->|VED *****');
3140 hr_utility.trace ('***** current |-----------------> *****');
3141 end if;
3142 --
3143 hrentmnt.validate_adjust_entry
3144 ('DELETE',
3145 p_assignment_id,
3146 p_element_entry_id,
3147 null,
3148 null,
3149 null,
3150 p_ee_effective_start_date,
3151 p_validation_end_date,
3152 p_entries_changed);
3153 --
3154 -- update piece of REE that crosses eligibility boundary,
3155 -- do not delete as this REE cannot be recreated later,
3156 -- update its EED so that it is a day greater than the VSD
3157 --
3158 UPDATE PAY_ELEMENT_ENTRY_VALUES_F eev
3159 SET eev.effective_start_date = p_validation_end_date + 1
3160 WHERE eev.element_entry_id = p_element_entry_id
3161 -- Change 115.60
3162 -- and eev.effective_start_date < p_validation_end_date
3163 and eev.effective_start_date <= p_validation_end_date
3164 -- End of change 115.60
3165 and eev.effective_end_date > p_validation_end_date
3166 ;
3167
3168 UPDATE PAY_ELEMENT_ENTRIES_F ee
3169 SET ee.effective_start_date = p_validation_end_date + 1,
3170 ee.updating_action_id = decode(ee.updating_action_type, 'S', ee.updating_action_id, null),
3171 ee.updating_action_type = decode(ee.updating_action_type, 'S', 'S', null)
3172 WHERE ee.element_entry_id = p_element_entry_id
3173 -- Change 115.60
3174 -- and ee.effective_start_date < p_validation_end_date
3175 and ee.effective_start_date <= p_validation_end_date
3176 -- End of change 115.60
3177 and ee.effective_end_date > p_validation_end_date
3178 ;
3179 -- end of change 115.21 --
3180
3181 -- start of change 115.22 --
3182 --
3183 -- also maintain salary proposal change date
3184 --
3185 if p_ee_creator_type = 'SP' then
3186 if g_debug then
3187 hr_utility.trace ('***** maintain end date of PP >' ||
3188 (p_validation_end_date + 1) || '<');
3189 end if;
3190 UPDATE PER_PAY_PROPOSALS pp
3191 SET pp.change_date = p_validation_end_date + 1
3192 WHERE pp.assignment_id = p_assignment_id
3193 and pp.pay_proposal_id = p_ee_creator_id
3194 ;
3195 end if;
3196 -- end of change 115.22 --
3197 --
3198 /* Added for bug #9370749 */
3199 open csr_bus_group(p_assignment_id);
3200 fetch csr_bus_group into l_business_group_id;
3201 close csr_bus_group;
3202 --
3203 open csr_leg_grp(l_business_group_id);
3204 fetch csr_leg_grp into l_legislation_code;
3205 close csr_leg_grp;
3206
3207 begin
3208 open csr_ele_entry_details(p_element_entry_id, (p_validation_end_date + 1));
3209 fetch csr_ele_entry_details into l_ele_ent_rec;
3210 close csr_ele_entry_details;
3211 exception
3212 when no_data_found then
3213 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
3214 hr_utility.set_message_token('PROCEDURE',
3215 'hrentmnt.bring_ree_start_date_forwards');
3216 hr_utility.set_message_token('STEP','1');
3217 hr_utility.raise_error;
3218 end;
3219 hr_utility.trace('Debug p_validation_end_date:'||p_validation_end_date);
3220 hr_utility.trace('Debug p_ee_effective_start_date:'||p_ee_effective_start_date);
3221 hr_utility.trace('Debug pay_dyn_triggers.g_dyt_mode:'||pay_dyn_triggers.g_dyt_mode);
3222
3223 l_dyt_mode := pay_dyn_triggers.g_dyt_mode;
3224 pay_dyn_triggers.g_dyt_mode := 'UPDATE';
3225
3226 pay_continuous_calc.PAY_ELEMENT_ENTRIES_F_aru(
3227 p_business_group_id => l_business_group_id,
3228 p_legislation_code => l_legislation_code,
3229 --p_effective_date => p_validation_end_date+1,
3230 p_effective_date => p_ee_effective_start_date,
3231 p_old_ASSIGNMENT_ID => l_ele_ent_rec.assignment_id,
3232 p_new_ASSIGNMENT_ID => l_ele_ent_rec.assignment_id,
3233 p_old_ATTRIBUTE1 => l_ele_ent_rec.attribute1,
3234 p_new_ATTRIBUTE1 => l_ele_ent_rec.attribute1,
3235 p_old_ATTRIBUTE10 => l_ele_ent_rec.attribute10,
3236 p_new_ATTRIBUTE10 => l_ele_ent_rec.attribute10,
3237 p_old_ATTRIBUTE11 => l_ele_ent_rec.attribute11,
3238 p_new_ATTRIBUTE11 => l_ele_ent_rec.attribute11,
3239 p_old_ATTRIBUTE12 => l_ele_ent_rec.attribute12,
3240 p_new_ATTRIBUTE12 => l_ele_ent_rec.attribute12,
3241 p_old_ATTRIBUTE13 => l_ele_ent_rec.attribute13,
3242 p_new_ATTRIBUTE13 => l_ele_ent_rec.attribute13,
3243 p_old_ATTRIBUTE14 => l_ele_ent_rec.attribute14,
3244 p_new_ATTRIBUTE14 => l_ele_ent_rec.attribute14,
3245 p_old_ATTRIBUTE15 => l_ele_ent_rec.attribute15,
3246 p_new_ATTRIBUTE15 => l_ele_ent_rec.attribute15,
3247 p_old_ATTRIBUTE16 => l_ele_ent_rec.attribute16,
3248 p_new_ATTRIBUTE16 => l_ele_ent_rec.attribute16,
3249 p_old_ATTRIBUTE17 => l_ele_ent_rec.attribute17,
3250 p_new_ATTRIBUTE17 => l_ele_ent_rec.attribute17,
3251 p_old_ATTRIBUTE18 => l_ele_ent_rec.attribute18,
3252 p_new_ATTRIBUTE18 => l_ele_ent_rec.attribute18,
3253 p_old_ATTRIBUTE19 => l_ele_ent_rec.attribute19,
3254 p_new_ATTRIBUTE19 => l_ele_ent_rec.attribute19,
3255 p_old_ATTRIBUTE2 => l_ele_ent_rec.attribute2,
3256 p_new_ATTRIBUTE2 => l_ele_ent_rec.attribute2,
3257 p_old_ATTRIBUTE20 => l_ele_ent_rec.attribute20,
3258 p_new_ATTRIBUTE20 => l_ele_ent_rec.attribute20,
3259 p_old_ATTRIBUTE3 => l_ele_ent_rec.attribute3,
3260 p_new_ATTRIBUTE3 => l_ele_ent_rec.attribute3,
3261 p_old_ATTRIBUTE4 => l_ele_ent_rec.attribute4,
3262 p_new_ATTRIBUTE4 => l_ele_ent_rec.attribute4,
3263 p_old_ATTRIBUTE5 => l_ele_ent_rec.attribute5,
3264 p_new_ATTRIBUTE5 => l_ele_ent_rec.attribute5,
3265 p_old_ATTRIBUTE6 => l_ele_ent_rec.attribute6,
3266 p_new_ATTRIBUTE6 => l_ele_ent_rec.attribute6,
3267 p_old_ATTRIBUTE7 => l_ele_ent_rec.attribute7,
3268 p_new_ATTRIBUTE7 => l_ele_ent_rec.attribute7,
3269 p_old_ATTRIBUTE8 => l_ele_ent_rec.attribute8,
3270 p_new_ATTRIBUTE8 => l_ele_ent_rec.attribute8,
3271 p_old_ATTRIBUTE9 => l_ele_ent_rec.attribute9,
3272 p_new_ATTRIBUTE9 => l_ele_ent_rec.attribute9,
3273 p_old_ATTRIBUTE_CATEGORY => l_ele_ent_rec.attribute_category,
3274 p_new_ATTRIBUTE_CATEGORY => l_ele_ent_rec.attribute_category,
3275 p_old_COST_ALLOCATION_KEYFLEX => l_ele_ent_rec.cost_allocation_keyflex_id,
3276 p_new_COST_ALLOCATION_KEYFLEX => l_ele_ent_rec.cost_allocation_keyflex_id,
3277 p_old_DATE_EARNED => l_ele_ent_rec.date_earned,
3278 p_new_DATE_EARNED => l_ele_ent_rec.date_earned,
3279 p_old_EFFECTIVE_END_DATE => l_ele_ent_rec.effective_end_date,
3280 p_new_EFFECTIVE_END_DATE => l_ele_ent_rec.effective_end_date,
3281 p_old_EFFECTIVE_START_DATE => p_ee_effective_start_date,
3282 p_new_EFFECTIVE_START_DATE => l_ele_ent_rec.effective_start_date,
3283 p_old_ENTRY_INFORMATION1 => l_ele_ent_rec.entry_information1,
3284 p_new_ENTRY_INFORMATION1 => l_ele_ent_rec.entry_information1,
3285 p_old_ENTRY_INFORMATION10 => l_ele_ent_rec.entry_information10,
3286 p_new_ENTRY_INFORMATION10 => l_ele_ent_rec.entry_information10,
3287 p_old_ENTRY_INFORMATION11 => l_ele_ent_rec.entry_information11,
3288 p_new_ENTRY_INFORMATION11 => l_ele_ent_rec.entry_information11,
3289 p_old_ENTRY_INFORMATION12 => l_ele_ent_rec.entry_information12,
3290 p_new_ENTRY_INFORMATION12 => l_ele_ent_rec.entry_information12,
3291 p_old_ENTRY_INFORMATION13 => l_ele_ent_rec.entry_information13,
3292 p_new_ENTRY_INFORMATION13 => l_ele_ent_rec.entry_information13,
3293 p_old_ENTRY_INFORMATION14 => l_ele_ent_rec.entry_information14,
3294 p_new_ENTRY_INFORMATION14 => l_ele_ent_rec.entry_information14,
3295 p_old_ENTRY_INFORMATION15 => l_ele_ent_rec.entry_information15,
3296 p_new_ENTRY_INFORMATION15 => l_ele_ent_rec.entry_information15,
3297 p_old_ENTRY_INFORMATION16 => l_ele_ent_rec.entry_information16,
3298 p_new_ENTRY_INFORMATION16 => l_ele_ent_rec.entry_information16,
3299 p_old_ENTRY_INFORMATION17 => l_ele_ent_rec.entry_information17,
3300 p_new_ENTRY_INFORMATION17 => l_ele_ent_rec.entry_information17,
3301 p_old_ENTRY_INFORMATION18 => l_ele_ent_rec.entry_information18,
3302 p_new_ENTRY_INFORMATION18 => l_ele_ent_rec.entry_information18,
3303 p_old_ENTRY_INFORMATION19 => l_ele_ent_rec.entry_information19,
3304 p_new_ENTRY_INFORMATION19 => l_ele_ent_rec.entry_information19,
3305 p_old_ENTRY_INFORMATION2 => l_ele_ent_rec.entry_information2,
3306 p_new_ENTRY_INFORMATION2 => l_ele_ent_rec.entry_information2,
3307 p_old_ENTRY_INFORMATION20 => l_ele_ent_rec.entry_information20,
3308 p_new_ENTRY_INFORMATION20 => l_ele_ent_rec.entry_information20,
3309 p_old_ENTRY_INFORMATION21 => l_ele_ent_rec.entry_information21,
3310 p_new_ENTRY_INFORMATION21 => l_ele_ent_rec.entry_information21,
3311 p_old_ENTRY_INFORMATION22 => l_ele_ent_rec.entry_information22,
3312 p_new_ENTRY_INFORMATION22 => l_ele_ent_rec.entry_information22,
3313 p_old_ENTRY_INFORMATION23 => l_ele_ent_rec.entry_information23,
3314 p_new_ENTRY_INFORMATION23 => l_ele_ent_rec.entry_information23,
3315 p_old_ENTRY_INFORMATION24 => l_ele_ent_rec.entry_information24,
3316 p_new_ENTRY_INFORMATION24 => l_ele_ent_rec.entry_information24,
3317 p_old_ENTRY_INFORMATION25 => l_ele_ent_rec.entry_information25,
3318 p_new_ENTRY_INFORMATION25 => l_ele_ent_rec.entry_information25,
3319 p_old_ENTRY_INFORMATION26 => l_ele_ent_rec.entry_information26,
3320 p_new_ENTRY_INFORMATION26 => l_ele_ent_rec.entry_information26,
3321 p_old_ENTRY_INFORMATION27 => l_ele_ent_rec.entry_information27,
3322 p_new_ENTRY_INFORMATION27 => l_ele_ent_rec.entry_information27,
3323 p_old_ENTRY_INFORMATION28 => l_ele_ent_rec.entry_information28,
3324 p_new_ENTRY_INFORMATION28 => l_ele_ent_rec.entry_information28,
3325 p_old_ENTRY_INFORMATION29 => l_ele_ent_rec.entry_information29,
3326 p_new_ENTRY_INFORMATION29 => l_ele_ent_rec.entry_information29,
3327 p_old_ENTRY_INFORMATION3 => l_ele_ent_rec.entry_information3,
3328 p_new_ENTRY_INFORMATION3 => l_ele_ent_rec.entry_information3,
3329 p_old_ENTRY_INFORMATION30 => l_ele_ent_rec.entry_information30,
3330 p_new_ENTRY_INFORMATION30 => l_ele_ent_rec.entry_information30,
3331 p_old_ENTRY_INFORMATION4 => l_ele_ent_rec.entry_information4,
3332 p_new_ENTRY_INFORMATION4 => l_ele_ent_rec.entry_information4,
3333 p_old_ENTRY_INFORMATION5 => l_ele_ent_rec.entry_information5,
3334 p_new_ENTRY_INFORMATION5 => l_ele_ent_rec.entry_information5,
3335 p_old_ENTRY_INFORMATION6 => l_ele_ent_rec.entry_information6,
3336 p_new_ENTRY_INFORMATION6 => l_ele_ent_rec.entry_information6,
3337 p_old_ENTRY_INFORMATION7 => l_ele_ent_rec.entry_information7,
3338 p_new_ENTRY_INFORMATION7 => l_ele_ent_rec.entry_information7,
3339 p_old_ENTRY_INFORMATION8 => l_ele_ent_rec.entry_information8,
3340 p_new_ENTRY_INFORMATION8 => l_ele_ent_rec.entry_information8,
3341 p_old_ENTRY_INFORMATION9 => l_ele_ent_rec.entry_information9,
3342 p_new_ENTRY_INFORMATION9 => l_ele_ent_rec.entry_information9,
3343 p_old_ENTRY_INFORMATION_CATEGO => l_ele_ent_rec.entry_information_category,
3344 p_new_ENTRY_INFORMATION_CATEGO => l_ele_ent_rec.entry_information_category,
3345 p_old_ORIGINAL_ENTRY_ID => l_ele_ent_rec.original_entry_id,
3346 p_new_ORIGINAL_ENTRY_ID => l_ele_ent_rec.original_entry_id,
3347 p_old_PERSONAL_PAYMENT_METHOD_ => l_ele_ent_rec.personal_payment_method_id,
3348 p_new_PERSONAL_PAYMENT_METHOD_ => l_ele_ent_rec.personal_payment_method_id,
3349 p_old_REASON => l_ele_ent_rec.reason,
3350 p_new_REASON => l_ele_ent_rec.reason,
3351 p_old_SUBPRIORITY => l_ele_ent_rec.subpriority,
3352 p_new_SUBPRIORITY => l_ele_ent_rec.subpriority,
3353 p_old_UPDATING_ACTION_ID => l_ele_ent_rec.updating_action_id,
3354 p_new_UPDATING_ACTION_ID => l_ele_ent_rec.updating_action_id,
3355 p_old_ELEMENT_ENTRY_ID => p_element_entry_id);
3356
3357 pay_dyn_triggers.g_dyt_mode := l_dyt_mode;
3358 /* End for bug #9370749 */
3359
3360 end bring_ree_start_date_forwards;
3361 --
3362 begin
3363 --
3364 if g_debug then
3365 check_parameters;
3366 end if;
3367 --
3368 -- Bugfix 2725909
3369 -- When datetrack mode is ZAP, remove all entries and entry values, as
3370 -- parent assignment has been removed, and then exit.
3371 --
3372 -- Bug 8230599. removed the code added for 7202321
3373
3374 if p_dt_mode = 'ZAP' then
3375 --
3376 if g_debug then
3377 --
3378 hr_utility.trace('ZAP orphaned entries and entry values');
3379 --
3380 end if;
3381 --
3382 -- Remove orphaned entries and entry values
3383 --
3384 for v_entry in csr_orphaned_entries(p_assignment_id) loop
3385 --
3386 delete from pay_element_entry_values_f eev
3387 where eev.element_entry_id = v_entry.element_entry_id;
3388 --
3389 delete from pay_element_entries_f ee
3390 where ee.element_entry_id = v_entry.element_entry_id;
3391 --
3392 end loop;
3393 --
3394 if g_debug then
3395 --
3396 hr_utility.trace('Out hrentmnt.remove_ineligible_recurring');
3397 --
3398 end if;
3399 --
3400 return;
3401 --
3402 end if;
3403 --
3404 -- Retrieve all recurring entries for the assignment that are no longer
3405 -- valid ie. assignment and link no longer matches over the existence of the
3406 -- element entry.
3407 --
3408 for v_entry in csr_entry(p_assignment_id,
3409 p_validation_start_date, p_validation_end_date) loop
3410 --
3411 -- bug 891323,
3412 -- if a non-SL'ed REE is crossing eligibility boundary then
3413 -- do special processing as it cannot be recreated later
3414 --
3415 if v_entry.effective_start_date < p_validation_start_date and
3416 -- change 115.23 --
3417 v_entry.effective_end_date >= p_validation_start_date then
3418 --
3419 -- ***** updating "end" date of current REE backwards *****
3420 -- ***** VSD|<----- |VED *****
3421 -- ***** current |-----------------| *****
3422 --
3423 bring_ree_end_date_backwards (
3424 p_assignment_id => p_assignment_id,
3425 p_element_type_id => v_entry.element_type_id,
3426 p_element_link_id => v_entry.element_link_id,
3427 p_element_entry_id => v_entry.element_entry_id,
3428 p_validation_start_date => p_validation_start_date,
3429 p_validation_end_date => p_validation_end_date,
3430 p_ee_effective_start_date => v_entry.effective_start_date,
3431 p_ee_effective_end_date => v_entry.effective_end_date,
3432 p_ee_creator_type => v_entry.creator_type,
3433 p_ee_creator_id => v_entry.creator_id,
3434 p_entries_changed => p_entries_changed
3435 );
3436 --
3437 -- start of change 115.21 --
3438 -- change 115.23 --
3439 elsif v_entry.effective_start_date <= p_validation_end_date and
3440 v_entry.effective_end_date > p_validation_end_date then
3441 --
3442 -- ***** updating "start" date of current REE forwards *****
3443 -- ***** VSD| ----->|VED *****
3444 -- ***** current |-----------------> *****
3445 --
3446 bring_ree_start_date_forwards (
3447 p_assignment_id => p_assignment_id,
3448 p_element_entry_id => v_entry.element_entry_id,
3449 p_ee_effective_start_date => v_entry.effective_start_date,
3450 p_validation_end_date => p_validation_end_date,
3451 p_ee_creator_type => v_entry.creator_type,
3452 p_ee_creator_id => v_entry.creator_id,
3453 p_entries_changed => p_entries_changed
3454 );
3455 --
3456 -- start of change 115.23 --
3457 elsif v_entry.effective_start_date >= p_validation_start_date and
3458 v_entry.effective_end_date <= p_validation_end_date then
3459 -- end of change 115.23 --
3460 --
3461 -- Entry exists entirely within the validation period.
3462 -- Do normal delete of REE.
3463 --
3464 -- Bugfix 5247607
3465 -- Now, whenever a recurring entry is deleted as a result of an
3466 -- assignment criteria change, we always look for a suitable
3467 -- alternative link under which the entry can be recreated. A new
3468 -- procedure, recreate_cached_entry, has been created to do this
3469 -- for us. This is now called from do_normal_delete_of_ree.
3470 --
3471 do_normal_delete_of_ree (
3472 p_assignment_id => p_assignment_id,
3473 p_element_type_id => v_entry.element_type_id,
3474 p_element_link_id => v_entry.element_link_id,
3475 p_element_entry_id => v_entry.element_entry_id,
3476 p_validation_start_date => p_validation_start_date,
3477 p_validation_end_date => p_validation_end_date,
3478 p_ee_effective_start_date => v_entry.effective_start_date,
3479 p_ee_effective_end_date => v_entry.effective_end_date,
3480 p_ee_creator_type => v_entry.creator_type,
3481 p_ee_creator_id => v_entry.creator_id,
3482 p_entries_changed => p_entries_changed
3483 );
3484 --
3485 else
3486 -- start of change 115.23 --
3487 if g_debug then
3488 hr_utility.trace ('***** not adjusting, REE outside validation range *****');
3489 hr_utility.trace ('***** VSD| |VED *****');
3490 hr_utility.trace ('***** current |----| *****');
3491 hr_utility.trace ('***** or *****');
3492 hr_utility.trace ('***** current |-------> *****');
3493 end if;
3494 -- end of change 115.23 --
3495 end if;
3496 end loop;
3497 --
3498 if g_debug then
3499 hr_utility.trace('Out hrentmnt.remove_ineligible_recurring');
3500 end if;
3501 --
3502 end remove_ineligible_recurring;
3503 --
3504 ------------------------------------------------------------------------------
3505 -- NAME --
3506 -- hrentmnt.remove_ineligible_nonrecurring --
3507 -- --
3508 -- DESCRIPTION --
3509 -- Deletes any nonrecurring element entries that will be made ineligible by --
3510 -- a change in assignment criteria. The delete runs after the change to the --
3511 -- assignment has taken place. --
3512 -- NB. val_nonrec_entries should be run first. This makes sure that only --
3513 -- processed nonrecurring and unprocessed personnel element entries --
3514 -- are deleted. --
3515 ------------------------------------------------------------------------------
3516 --
3517 procedure remove_ineligible_nonrecurring
3518 (
3519 p_assignment_id number,
3520 p_validation_start_date date,
3521 p_validation_end_date date,
3522 p_entries_changed in out nocopy varchar2
3523 ) is
3524 --Added for 6809717
3525 l_obj_ver_num number;
3526 l_eff_str_date date;
3527 l_eff_end_date date;
3528 l_del_war boolean;
3529 l_cnt NUMBER := 0;
3530 l_prof_value varchar2(30);
3531 l_entry_processed varchar2(10);
3532 lv_asg_exists NUMBER := 0;
3533 --
3534 cursor csr_entry
3535 (
3536 p_assignment_id number,
3537 p_validation_start_date date,
3538 p_validation_end_date date
3539 ) is
3540 select ee.element_entry_id,
3541 ee.effective_start_date,
3542 ee.effective_end_date,
3543 ee.element_link_id
3544 from pay_element_entries_f ee
3545 where ee.assignment_id = p_assignment_id
3546 and ee.effective_start_date <= p_validation_end_date
3547 and ee.effective_end_date >= p_validation_start_date
3548 and ee.creator_type in ('F','H')
3549 and ((ee.entry_type <> 'E')
3550 or (ee.entry_type = 'E' and
3551 exists
3552 (select null
3553 from pay_element_links_f el,
3554 pay_element_types_f et
3555 where el.element_link_id = ee.element_link_id
3556 and el.element_type_id = et.element_type_id
3557 and et.processing_type = 'N')))
3558 and not exists
3559 (select null
3560 from per_all_assignments_f asg,
3561 pay_element_links_f el
3562 where el.element_link_id = ee.element_link_id
3563 and asg.assignment_id = ee.assignment_id
3564 and asg.assignment_type = 'E'
3565 and asg.effective_start_date <= ee.effective_end_date
3566 -- changed to validation start date not effective start date
3567 -- wmcveagh bug 586139 17/2/98
3568 and asg.effective_end_date >= p_validation_start_date
3569 and el.effective_start_date <= ee.effective_end_date
3570 and el.effective_end_date >= ee.effective_start_date
3571 and el.effective_start_date <= asg.effective_end_date
3572 and el.effective_end_date >= asg.effective_start_date
3573 and ((el.payroll_id is not null and
3574 el.payroll_id = asg.payroll_id)
3575 or (el.link_to_all_payrolls_flag = 'Y' and
3576 asg.payroll_id is not null)
3577 or (el.payroll_id is null and
3578 el.link_to_all_payrolls_flag = 'N'))
3579 and (el.job_id is null or
3580 el.job_id = asg.job_id)
3581 and (el.grade_id is null or
3582 el.grade_id = asg.grade_id)
3583 and (el.position_id is null or
3584 el.position_id = asg.position_id)
3585 and (el.organization_id is null or
3586 el.organization_id = asg.organization_id)
3587 and (el.location_id is null or
3588 el.location_id = asg.location_id)
3589 and (el.pay_basis_id is null or
3590 el.pay_basis_id = asg.pay_basis_id)
3591 and (el.employment_category is null or
3592 el.employment_category = asg.employment_category)
3593 and (el.people_group_id is null or
3594 exists
3595 (select null
3596 from pay_assignment_link_usages_f alu
3597 where alu.assignment_id = ee.assignment_id
3598 and alu.element_link_id = ee.element_link_id
3599 and alu.effective_start_date <=
3600 asg.effective_end_date
3601 and alu.effective_end_date >=
3602 asg.effective_start_date)));
3603 --
3604 procedure check_parameters is
3605 begin
3606 hr_utility.trace('In hrentmnt.remove_ineligible_nonrecurring');
3607 --
3608 hr_utility.trace ('');
3609 hr_utility.trace (' p_assignment_id = '
3610 ||to_char(p_assignment_id));
3611 hr_utility.trace (' p_validation_start_date = '
3612 ||to_char(p_validation_start_date));
3613 hr_utility.trace (' p_validation_end_date = '
3614 ||to_char(p_validation_end_date));
3615 hr_utility.trace (' p_entries_changed = '
3616 ||p_entries_changed);
3617 hr_utility.trace ('');
3618 --
3619 end check_parameters;
3620 --
3621 begin
3622 --
3623 if g_debug then
3624 check_parameters;
3625 end if;
3626 lv_asg_exists := 0;
3627 --
3628 -- Retrieve all nonrecurring entries for the assignment that are no longer
3629 -- valid ie. assignment and link no longer matches over the existence of the
3630 -- element entry.
3631 --
3632 /*Bug 9710104 Checking if assignment exists if not then its purged */
3633 Begin
3634 select 1
3635 into lv_asg_exists
3636 from dual
3637 where exists (select 1
3638 from per_all_assignments_f
3639 where assignment_id =p_assignment_id);
3640 Exception when no_data_found then
3641 lv_asg_exists:=0;
3642 end;
3643
3644
3645 for v_entry in csr_entry(p_assignment_id,
3646 p_validation_start_date,
3647 p_validation_end_date) loop
3648 --
3649 --
3650 hrentmnt.validate_adjust_entry
3651 ('DELETE',
3652 p_assignment_id,
3653 v_entry.element_entry_id,
3654 null,
3655 null,
3656 null,
3657 v_entry.effective_start_date,
3658 v_entry.effective_end_date,
3659 p_entries_changed);
3660 --
3661 --
3662 delete from pay_run_results rr
3663 where rr.status not like 'P%'
3664 and rr.source_type = 'E'
3665 and rr.source_id = v_entry.element_entry_id;
3666 --
3667 --
3668
3669 -- Added for Bug 7578009
3670
3671 -- Bug 8230599. Using only element_entry_id in the where clause to get ovn, as
3672 -- every non-recurring element entry has only one record in pay_element_Entries_f.
3673 -- Call the entry api for 'ZAP' mode also to enable logging of events.
3674
3675 select OBJECT_VERSION_NUMBER into l_obj_ver_num
3676 from pay_element_entries_f
3677 where element_entry_id=v_entry.element_entry_id;
3678
3679 if g_debug then
3680 hr_utility.trace(' obj vber no : '||l_obj_ver_num);
3681 hr_utility.trace(' p_validation_start_date : '||p_validation_start_date);
3682 end if;
3683
3684 if(v_entry.effective_start_date>= p_validation_start_date) THEN
3685
3686 -- Read the profile value.
3687 fnd_profile.get('HR_ELE_ENTRY_PURGE_CONTROL', l_prof_value);
3688
3689 l_entry_processed := pay_paywsmee_pkg.processed(p_element_entry_id => v_entry.element_entry_id,
3690 p_original_entry_id => null,
3691 p_processing_type => 'N',
3692 p_entry_type => null ,
3693 p_effective_date => null);
3694 if g_debug then
3695 hr_utility.trace('l_prof_value : '|| l_prof_value);
3696 hr_utility.trace('l_entry_processed : '|| l_entry_processed);
3697 end if;
3698
3699 if (l_prof_value = 'PN' and l_entry_processed = 'N') then
3700 hr_utility.set_message (800,'PAY_33469_UNPROC_NONREC_PURGE');
3701 hr_utility.raise_error;
3702 end if;
3703
3704 if g_debug then
3705 hr_utility.trace(' ZAP element entry ');
3706 end if;
3707
3708 If lv_asg_exists = 0 then
3709 /*Bug 9710104 If assignment doesnt exists delete the entries */
3710
3711 delete from pay_element_entry_values_f eev
3712 where eev.element_entry_id = v_entry.element_entry_id;
3713 --
3714 delete from pay_element_entries_f ee
3715 where ee.element_entry_id = v_entry.element_entry_id;
3716
3717 else
3718
3719 pay_element_entry_api.delete_element_entry
3720 (p_datetrack_delete_mode => 'ZAP'
3721 ,p_effective_date => v_entry.effective_start_date -- 8230599, pass v_entry.effective_start_date
3722 ,p_element_entry_id => v_entry.element_entry_id
3723 ,p_object_version_number => l_obj_ver_num
3724 ,p_effective_start_date =>l_eff_str_date
3725 ,p_effective_end_date =>l_eff_end_date
3726 ,p_delete_warning =>l_del_war);
3727 end if;
3728 else
3729
3730 if g_debug then
3731 hr_utility.trace(' DELETE element entry ');
3732 end if;
3733
3734 pay_element_entry_api.delete_element_entry
3735 (p_datetrack_delete_mode => 'DELETE'
3736 ,p_effective_date => p_validation_start_date-1
3737 ,p_element_entry_id => v_entry.element_entry_id
3738 ,p_object_version_number => l_obj_ver_num
3739 ,p_effective_start_date =>l_eff_str_date
3740 ,p_effective_end_date =>l_eff_end_date
3741 ,p_delete_warning =>l_del_war);
3742 end if;
3743 -- end of change 115.116
3744
3745 --Commented the below code as part of 6809717
3746 /* delete from pay_element_entry_values_f eev
3747 where eev.element_entry_id = v_entry.element_entry_id;
3748 --
3749 delete from pay_element_entries_f ee
3750 where ee.element_entry_id = v_entry.element_entry_id;*/
3751 --
3752 -- Call the routine that checks whether an illegal purge
3753 -- has occurred (i.e. disallowed by profile).
3754 hrentmnt.validate_purge(v_entry.element_entry_id, v_entry.element_link_id);
3755 --
3756 end loop;
3757 --
3758 if g_debug then
3759 hr_utility.trace('Out hrentmnt.remove_ineligible_nonrecurring');
3760 end if;
3761 --
3762 end remove_ineligible_nonrecurring;
3763 --
3764 ------------------------------------------------------------------------------
3765 -- NAME --
3766 -- hrentmnt.return_entry_dates --
3767 -- --
3768 -- DESCRIPTION --
3769 -- Given an assignment and element link this returns the start and end --
3770 -- dates of the element entry taking into account personal qualifying --
3771 -- conditions and also any future terminations of the assignment NB. for --
3772 -- discretionary element entries the personal qualifying conditions are not --
3773 -- taken into account as the user is allowed to ignore these when creating --
3774 -- an entry. --
3775 ------------------------------------------------------------------------------
3776 --
3777 procedure return_entry_dates
3778 (
3779 p_assignment_id number,
3780 p_asg_start_date date,
3781 p_element_link_id number,
3782 p_link_start_date date,
3783 p_standard_link_flag varchar2,
3784 p_entry_start_date out nocopy date,
3785 p_entry_end_date out nocopy date
3786 ) is
3787 --
3788 -- Local Variables
3789 --
3790 v_los_date date;
3791 v_age_date date;
3792 v_pqc_start_date date;
3793 v_entry_start_date date;
3794 v_entry_end_date date;
3795 --
3796 procedure check_parameters is
3797 --
3798 begin
3799 --
3800 hr_utility.trace('In hrentmnt.return_entry_dates');
3801 hr_utility.trace ('');
3802 hr_utility.trace (' p_assignment_id = '
3803 ||to_char (p_assignment_id));
3804 hr_utility.trace (' p_asg_start_date = '
3805 ||to_char (p_asg_start_date));
3806 hr_utility.trace (' p_element_link_id = '
3807 ||to_char (p_element_link_id));
3808 hr_utility.trace (' p_link_start_date = '
3809 ||to_char (p_link_start_date));
3810 hr_utility.trace (' p_standard_link_flag = '
3811 ||p_standard_link_flag);
3812 hr_utility.trace ('');
3813 --
3814 end check_parameters;
3815 --
3816 begin
3817 --
3818 if g_debug then
3819 check_parameters;
3820 end if;
3821 --
3822 -- Only take into account personal qualifying conditions for standard
3823 -- element entries.
3824 --
3825 if p_standard_link_flag = 'Y' then
3826 --
3827 hr_entry.return_qualifying_conditions
3828 (p_assignment_id,
3829 p_element_link_id,
3830 greatest(p_link_start_date,p_asg_start_date),
3831 v_los_date,
3832 v_age_date);
3833 --
3834 v_pqc_start_date := least(nvl(v_los_date,v_age_date),
3835 nvl(v_age_date,v_los_date));
3836 --
3837 -- Discretionary entry so do not apply personal qualifying conditions.
3838 --
3839 else
3840 --
3841 v_pqc_start_date := p_asg_start_date;
3842 --
3843 end if;
3844 --
3845 v_entry_start_date := greatest(p_link_start_date,
3846 p_asg_start_date,
3847 nvl(v_pqc_start_date,p_asg_start_date));
3848 --
3849 -- Calculate the element entry end date taking into account future
3850 -- terminations.
3851 --
3852 v_entry_end_date := hr_entry.recurring_entry_end_date
3853 (p_assignment_id,
3854 p_element_link_id,
3855 greatest(p_link_start_date,p_asg_start_date),
3856 'N',
3857 'N',
3858 null,
3859 null);
3860 --
3861 -- It is possible that personal qualifying conditions can result in an
3862 -- entry not being able to start until after the person has become
3863 -- ineligible for it.
3864 --
3865 -- It is not possible for elements to end before they start
3866 --
3867 if v_entry_start_date <= v_entry_end_date then
3868 p_entry_start_date := v_entry_start_date;
3869 p_entry_end_date := v_entry_end_date;
3870 end if;
3871 --
3872 if g_debug then
3873 hr_utility.trace('Out hrentmnt.return_entry_dates');
3874 end if;
3875 --
3876 end return_entry_dates;
3877 --
3878 ------------------------------------------------------------------------------
3879 -- NAME --
3880 -- hrentmnt.mult_ent_allowed_flag --
3881 -- --
3882 -- DESCRIPTION --
3883 -- Simple function to return a flag indicating if multiple entries are --
3884 -- allowed for a particular element type. --
3885 ------------------------------------------------------------------------------
3886 --
3887 function mult_ent_allowed_flag
3888 (
3889 p_element_link_id number
3890 ) return varchar2 is
3891 --
3892 -- Are multiple entries allowed.
3893 --
3894 cursor csr_element
3895 (
3896 p_element_link_id number
3897 ) is
3898 select et.multiple_entries_allowed_flag
3899 from pay_element_links_f el,
3900 pay_element_types_f et
3901 where el.element_link_id = p_element_link_id
3902 and et.element_type_id = el.element_type_id;
3903 --
3904 -- Local Variables
3905 --
3906 v_mult_ent_allowed_flag varchar2(30);
3907 --
3908 procedure check_parameters is
3909 --
3910 begin
3911 --
3912 hr_utility.trace('In hrentmnt.mult_ent_allowed_flag');
3913 hr_utility.trace ('');
3914 hr_utility.trace (' p_element_link_id = '
3915 ||to_char (p_element_link_id));
3916 hr_utility.trace ('');
3917 --
3918 end check_parameters;
3919 --
3920 begin
3921 --
3922 if g_debug then
3923 check_parameters;
3924 end if;
3925 --
3926 open csr_element(p_element_link_id);
3927 fetch csr_element into v_mult_ent_allowed_flag;
3928 if csr_element%notfound then
3929 close csr_element;
3930 hr_utility.set_message(801, 'HR_6153_ALL_PROCEDURE_FAIL');
3931 hr_utility.set_message_token('PROCEDURE',
3932 'hrentmnt.mult_ent_allowed_flag');
3933 hr_utility.set_message_token('STEP','1');
3934 hr_utility.raise_error;
3935 end if;
3936 close csr_element;
3937 --
3938 return v_mult_ent_allowed_flag;
3939 --
3940 end mult_ent_allowed_flag;
3941 --
3942 ------------------------------------------------------------------------------
3943 -- NAME --
3944 -- hrentmnt.val_nonrec_entries --
3945 -- --
3946 -- DESCRIPTION --
3947 -- Checks to see if there are nonrecurring element entries that will be --
3948 -- made ineligible by a change in assignment criteria. The check runs --
3949 -- after the change to the assignment has taken place. The nonrecurring --
3950 -- element entries that are validated are : --
3951 -- --
3952 -- Balance Adjustment processed / unprocessed --
3953 -- Override unprocessed --
3954 -- Replacement Adjustment '' '' --
3955 -- Additive Adjustment '' '' --
3956 -- Additional Entry '' '' --
3957 -- Payroll Nonrecurring '' '' --
3958 -- Special Entries ie. SSP, Quickpay etc ... processed / unprocessed --
3959 -- --
3960 -- NB. the nonrecurring entry is still valid providing the element link --
3961 -- and assignment match for at least one day during the duration of --
3962 -- the entry. --
3963 -- --
3964 -- As this check is run during a batch operation it is not possible to --
3965 -- return specific details for each nonrecurring entry that has been --
3966 -- made ineligible so an error is only raised for the first one found. --
3967 ------------------------------------------------------------------------------
3968 --
3969 procedure val_nonrec_entries
3970 (
3971 p_assignment_id number,
3972 p_validation_start_date date,
3973 p_validation_end_date date,
3974 p_entries_changed in out nocopy varchar2
3975 ) is
3976 --
3977 -- Cursor returns all nonrecurring entries for an assignment over a
3978 -- specified time period that are unprocessed overrides, replacement
3979 -- adjustments, additive adjustments, additional entries or nonrecurring
3980 -- payroll entries. It also returns special nonrecurring entries
3981 -- irrespective of them having been processed or not ie. Quickpay
3982 -- entries etc ...
3983 --
3984 cursor csr_entry
3985 (
3986 p_assignment_id number,
3987 p_validation_start_date date,
3988 p_validation_end_date date,
3989 p_adjust_ee_source varchar2
3990 ) is
3991 select ee.*
3992 from pay_element_entries_f ee
3993 ,pay_element_types_f et
3994 where ee.assignment_id = p_assignment_id
3995 and ee.effective_start_date <= p_validation_end_date
3996 and ee.effective_end_date >= p_validation_start_date
3997 and ee.element_type_id = et.element_type_id
3998 and ee.effective_start_date between et.effective_start_date
3999 and et.effective_end_date
4000 --
4001 -- Restrict to nonrecurring entries
4002 --
4003 and (ee.entry_type in ('S','R','A','D')
4004 or (ee.entry_type = 'E'
4005 -- and et.process_in_run_flag = 'Y' /* Bug 14529043*/
4006 and et.processing_type = 'N'))
4007 --
4008 -- Restrict to ordinary creator-type entries which have been processed
4009 -- or to special creator-type entries regardless of processing.
4010 --
4011 /* Bug 7603986. All processed and unprocessed entries are checked for any alternate element links
4012 and ((ee.creator_type in ('F','H')
4013 and not exists
4014 (select null
4015 from pay_run_results rr
4016 where rr.source_id = decode(ee.entry_type,
4017 'A', decode (p_adjust_ee_source,
4018 'T', ee.target_entry_id,
4019 ee.element_entry_id),
4020 'R', decode (p_adjust_ee_source,
4021 'T', ee.target_entry_id,
4022 ee.element_entry_id),
4023 ee.element_entry_id)
4024 and rr.source_type = 'E'
4025 and rr.entry_type = ee.entry_type
4026 and rr.status like 'P%'))
4027 or (ee.creator_type not in ('F','H')))
4028 */
4029 --
4030 -- Restrict to entries for links which no longer match the assignment
4031 -- criteria.
4032 --
4033 and not exists
4034 (select null
4035 from per_all_assignments_f asg,
4036 pay_element_links_f el
4037 where asg.assignment_id = ee.assignment_id
4038 and el.element_link_id = ee.element_link_id
4039 and asg.assignment_type = 'E'
4040 and asg.effective_start_date <= ee.effective_end_date
4041 and asg.effective_end_date >= ee.effective_end_date -- bug 6485636
4042 and el.effective_start_date <= ee.effective_end_date
4043 and el.effective_end_date >= ee.effective_start_date
4044 and el.effective_start_date <= asg.effective_end_date
4045 and el.effective_end_date >= asg.effective_start_date
4046 --
4047 -- and the link does NOT match the assignment criteria
4048 --
4049 and ((el.payroll_id is not null
4050 and el.payroll_id = asg.payroll_id)
4051 or (el.link_to_all_payrolls_flag = 'Y'
4052 and asg.payroll_id is not null)
4053 or (el.payroll_id is null and
4054 el.link_to_all_payrolls_flag = 'N'))
4055 and (el.job_id is null
4056 or el.job_id = asg.job_id)
4057 and (el.grade_id is null
4058 or el.grade_id = asg.grade_id)
4059 and (el.position_id is null
4060 or el.position_id = asg.position_id)
4061 and (el.organization_id is null
4062 or el.organization_id = asg.organization_id)
4063 and (el.location_id is null
4064 or el.location_id = asg.location_id)
4065 and (el.pay_basis_id is null
4066 or el.pay_basis_id = asg.pay_basis_id)
4067 and (el.employment_category is null
4068 or el.employment_category = asg.employment_category)
4069 and (el.people_group_id is null
4070 or exists (select null
4071 from pay_assignment_link_usages_f alu
4072 where alu.assignment_id = ee.assignment_id
4073 and alu.element_link_id = ee.element_link_id
4074 and alu.effective_start_date <=
4075 asg.effective_end_date
4076 and alu.effective_end_date >=
4077 asg.effective_start_date)));
4078 --
4079 -- Local types
4080 --
4081 type t_element_entry_table_rec is record (
4082 element_entry_id dbms_sql.number_table,
4083 element_link_id dbms_sql.number_table,
4084 effective_start_date dbms_sql.date_table,
4085 effective_end_date dbms_sql.date_table
4086 );
4087 --
4088 -- Local variables
4089 --
4090 l_counter number := 1;
4091 l_entry_table t_element_entry_table_rec;
4092 l_asg_criteria_cv t_asg_criteria_cur; -- cursor variable for assignment criteria
4093 l_asg_criteria_rec t_asg_criteria_rec;
4094 l_eligible_links_cv t_eligible_links_cur; -- cursor variable for eligible links for invalidated entries
4095 l_eligible_links_rec t_eligible_links_rec;
4096 l_link_suitable boolean;
4097 l_creator_type_meaning varchar2(60);
4098 l_adjust_ee_source varchar2(1);
4099 l_proc varchar2(80) := 'hrentmnt.val_nonrec_entries';
4100 --
4101 l_obj_ver_num number;
4102 l_eff_str_date date;
4103 l_eff_end_date date;
4104 l_del_war boolean;
4105 l_cnt NUMBER := 0;
4106 begin
4107 --
4108 if g_debug then
4109 hr_utility.set_location(l_proc, 10);
4110 hr_utility.trace(' p_assignment_id = ' ||to_char(p_assignment_id));
4111 hr_utility.trace(' p_validation_start_date = ' ||to_char(p_validation_start_date));
4112 hr_utility.trace(' p_validation_end_date = ' ||to_char(p_validation_end_date));
4113 end if;
4114 --
4115 -- Get the assignment criteria
4116 open_asg_criteria_cur(p_assignment_id, p_validation_start_date, l_asg_criteria_cv);
4117 fetch l_asg_criteria_cv into l_asg_criteria_rec;
4118 close l_asg_criteria_cv;
4119 --
4120 -- Get the legisative rule ADJUSTMENT_EE_SOURCE.
4121 --
4122 begin
4123 --
4124 if g_debug then
4125 hr_utility.set_location(l_proc, 20);
4126 end if;
4127 --
4128 select /*+ INDEX(paf PER_ASSIGNMENTS_F_PK)*/ plr.rule_mode
4129 into l_adjust_ee_source
4130 from pay_legislation_rules plr,
4131 per_business_groups_perf pbg,
4132 per_all_assignments_f paf
4133 where paf.assignment_id = p_assignment_id
4134 and p_validation_start_date between paf.effective_start_date
4135 and paf.effective_end_date
4136 and paf.business_group_id = pbg.business_group_id
4137 and pbg.legislation_code = plr.legislation_code
4138 and plr.rule_type = 'ADJUSTMENT_EE_SOURCE';
4139 --
4140 exception
4141 when no_data_found then
4142 l_adjust_ee_source := 'A';
4143 end;
4144 --
4145 if g_debug then
4146 hr_utility.trace(' l_adjust_ee_source: '||l_adjust_ee_source);
4147 end if;
4148 --
4149 -- Bugfix 5584631
4150 -- Loop through all invalidated nonrecurring entries.
4151 -- Look to see if there exists an alternative link for each invalidated entry
4152 -- Raise an error if no alternative link exists for ANY of the invalidated
4153 -- entries.
4154 -- If ALL invalidated nonrecurring entries have an alternative link available
4155 -- then DO NOT raise an error but update the element_link_id stamped on the
4156 -- invalidated entries to point to the new links.
4157 --
4158 for r_entry in csr_entry (
4159 p_assignment_id,
4160 p_validation_start_date,
4161 p_validation_end_date,
4162 l_adjust_ee_source
4163 ) loop
4164 --
4165 if g_debug then
4166 hr_utility.set_location(l_proc, 30);
4167 end if;
4168 --
4169 -- Look for an alternative element link based on the invalidated entry's
4170 -- element type and the assignment criteria
4171 open_eligible_links_cur (
4172 p_assignment_id,
4173 -- Bugfix 6809717 added greatest , least to the following two lines
4174 greatest(r_entry.effective_start_date,p_validation_start_date), -- link must span lifetime of entry
4175 least(r_entry.effective_end_date,p_validation_end_date),
4176 r_entry.element_type_id,
4177 l_asg_criteria_rec.organization_id,
4178 l_asg_criteria_rec.people_group_id,
4179 l_asg_criteria_rec.job_id,
4180 l_asg_criteria_rec.position_id,
4181 l_asg_criteria_rec.grade_id,
4182 l_asg_criteria_rec.location_id,
4183 l_asg_criteria_rec.employment_category,
4184 l_asg_criteria_rec.payroll_id,
4185 l_asg_criteria_rec.pay_basis_id,
4186 l_asg_criteria_rec.business_group_id,
4187 l_eligible_links_cv
4188 );
4189 --
4190 fetch l_eligible_links_cv into l_eligible_links_rec;
4191 --
4192 -- Determine if a suitable alternative link has been found
4193 -- i.e. link must span lifetime of entry
4194 --
4195 l_link_suitable :=
4196 l_eligible_links_cv%found and
4197 l_eligible_links_rec.effective_start_date <= r_entry.effective_start_date and
4198 l_eligible_links_rec.effective_end_date >= r_entry.effective_end_date;
4199 --
4200 close l_eligible_links_cv;
4201 --
4202 if not l_link_suitable then
4203 --
4204 if g_debug then
4205 hr_utility.set_location(l_proc, 40);
4206 end if;
4207 --
4208 -- No alternative link found.
4209 -- Clear down l_entry_table and raise error.
4210 --
4211 l_entry_table.element_entry_id.delete;
4212 l_entry_table.element_link_id.delete;
4213 l_entry_table.effective_start_date.delete;
4214 l_entry_table.effective_end_date.delete;
4215 --
4216 if r_entry.creator_type not in ('F','H') then
4217 --
4218 -- Special entry was invalidated eg. Balance Adjustment, Quickpay etc .
4219 -- Lookup the entry type for reporting in error.
4220 --
4221 if g_debug then
4222 hr_utility.set_location(l_proc, 50);
4223 end if;
4224 --
4225 select hl.meaning
4226 into l_creator_type_meaning
4227 from hr_lookups hl
4228 where hl.lookup_type = 'CREATOR_TYPE'
4229 and hl.lookup_code = r_entry.creator_type;
4230 --
4231 hr_utility.set_message(801,'HR_6589_ASS_SPCL_NONREC_EXIST');
4232 hr_utility.set_message_token('TYPE',l_creator_type_meaning);
4233 hr_utility.raise_error;
4234 --
4235 else
4236 --
4237 -- An unprocessed nonrecurring entry was invalidated. Includes
4238 -- overrides etc .
4239 --
4240 if g_debug then
4241 hr_utility.set_location(l_proc, 60);
4242 end if;
4243
4244 -- 8230599 removed delete logic as val_nonrec is not supposed to delete any entries. All the deletes
4245 -- are done in remove_ineligible_nonrecurring
4246
4247 -- 8311681
4248 p_entries_changed := 'I';
4249
4250 -- hr_utility.set_message(801,'HR_6588_ASS_UNPROC_NONREC');
4251 -- hr_utility.raise_error;
4252
4253 --
4254 end if;
4255 --
4256 else
4257 --
4258 -- A suitable alternative link was found
4259 -- Store the new link id with the entry details for a bulk update later
4260 --
4261 if g_debug then
4262 hr_utility.set_location(l_proc, 70);
4263 hr_utility.trace(' Alt element_link_id found for entry '||to_char(r_entry.element_entry_id));
4264 hr_utility.trace(' Old element_link_id: '||to_char(r_entry.element_link_id)||', new element_link_id: '||to_char(l_eligible_links_rec.element_link_id));
4265 end if;
4266 --
4267 l_entry_table.element_entry_id(l_counter) := r_entry.element_entry_id;
4268 l_entry_table.element_link_id(l_counter) := l_eligible_links_rec.element_link_id;
4269 l_entry_table.effective_start_date(l_counter) := r_entry.effective_start_date;
4270 l_entry_table.effective_end_date(l_counter) := r_entry.effective_end_date;
4271 --
4272 l_counter := l_counter + 1;
4273 --
4274 end if;
4275 --
4276 end loop;
4277 --
4278 if l_entry_table.element_entry_id.count > 0 then
4279 --
4280 if g_debug then
4281 hr_utility.set_location(l_proc, 80);
4282 hr_utility.trace('Doing bulk update of element_link_id');
4283 end if;
4284 --
4285 -- Do bulk update of element entries, to point to their respective new
4286 -- alternative links
4287 --
4288 forall i in 1 .. l_entry_table.element_entry_id.count
4289 update pay_element_entries_f
4290 set element_link_id = l_entry_table.element_link_id(i)
4291 where element_entry_id = l_entry_table.element_entry_id(i)
4292 and effective_start_date = l_entry_table.effective_start_date(i)
4293 and effective_end_date = l_entry_table.effective_end_date(i);
4294 --
4295 end if;
4296 --
4297 if g_debug then
4298 hr_utility.set_location(l_proc, 90);
4299 end if;
4300 --
4301 end val_nonrec_entries;
4302 --
4303 ------------------------------------------------------------------------------
4304 -- NAME --
4305 -- hrentmnt.validate_adjustment_entries --
4306 -- --
4307 -- DESCRIPTION --
4308 -- This routine checks for element entries which have more than one --
4309 -- adjustments(entry_type = 'A') in the same pay period --
4310 -- and raise an ERROR if such an entry exists. --
4311 ------------------------------------------------------------------------------
4312 procedure validate_adjustment_entries /* Added for bug 8419416 */
4313 (
4314 p_payroll_id in number,
4315 p_assignment_id in number,
4316 p_val_start_date in date
4317 )
4318 is
4319 cursor csr_cae is
4320 select null
4321 from dual
4322 where exists
4323 (select null
4324 from pay_element_entries_f pee,
4325 per_time_periods ptp
4326 where pee.assignment_id = p_assignment_id
4327 and pee.entry_type in ('A','R','S')
4328 and pee.effective_start_date > p_val_start_date
4329 and ptp.payroll_id = p_payroll_id
4330 and pee.effective_start_date between ptp.start_date and ptp.end_date
4331 and pee.effective_end_date between ptp.start_date and ptp.end_date
4332 group by pee.target_entry_id ,ptp.time_period_id
4333 having count(*) > 1);
4334 begin
4335 hr_utility.set_location('hrentmnt.validate_adjustment_entries',10);
4336 for csr_cae_rec in csr_cae loop
4337 -- any record fetched is an error
4338 hr_utility.set_message(801, 'PAY_34196_INVALID_ADJUSTMENTS');
4339 hr_utility.raise_error;
4340 end loop;
4341 hr_utility.set_location('hrentmnt.validate_adjustment_entries',20);
4342 return;
4343 end validate_adjustment_entries;
4344 --
4345 ------------------------------------------------------------------------------
4346 -- NAME --
4347 -- hrentmnt.adjust_nonrecurring_entries --
4348 -- --
4349 -- DESCRIPTION --
4350 -- Adjusts nonrecurring entries when there is a change in payroll or the --
4351 -- assignment ends. Nonrecurring entries now only exist for the duration of --
4352 -- the period for which the payroll / assignment exists. --
4353 ------------------------------------------------------------------------------
4354 --
4355 procedure adjust_nonrecurring_entries
4356 (
4357 p_assignment_id number,
4358 p_val_start_date_minus_one date,
4359 p_val_end_date_plus_one date,
4360 p_entries_changed in out nocopy varchar2,
4361 p_dt_mode VARCHAR2 DEFAULT NULL /* Added for Bug No : 6835808 */
4362 ) is
4363 --
4364 -- Finds all nonrecurring entries that overlap with the period of change of
4365 -- the assignment.
4366 --
4367 cursor csr_entry
4368 (
4369 p_assignment_id number,
4370 p_val_start_date_minus_one date,
4371 p_val_end_date_plus_one date
4372 ) is
4373 select ee.element_entry_id,
4374 ee.effective_start_date,
4375 ee.effective_end_date,
4376 ee.element_link_id
4377 from pay_element_entries_f ee
4378 where ee.assignment_id = p_assignment_id
4379 and ee.effective_start_date <= p_val_end_date_plus_one
4380 and ee.effective_end_date >= p_val_start_date_minus_one
4381 and ((ee.entry_type <> 'E') or
4382 (ee.entry_type = 'E' and
4383 exists
4384 (select null
4385 from pay_element_links_f el,
4386 pay_element_types_f et
4387 where el.element_link_id = ee.element_link_id
4388 and et.element_type_id = el.element_type_id
4389 and et.processing_type = 'N')));
4390 --
4391 cursor get_asg_start_date is -- bug 8359932
4392 select min(effective_start_date)
4393 from per_all_assignments_f
4394 where assignment_id = p_assignment_id;
4395
4396 --
4397 -- Local Variables
4398 --
4399 v_effective_start_date date;
4400 v_effective_end_date date;
4401 v_payroll_id number;
4402 v_period_start_date date;
4403 v_period_end_date date;
4404 v_session_date date;
4405 v_asg_start_date date;
4406 --Added for bug:6809717
4407 v_val_date date;
4408 v_alu_cnt number;
4409 v_vale_start_date date;
4410 v_start_date_check number;
4411 v_end_date_check number;
4412 v_chng_date date;
4413 v_min_eligible_date date;
4414 v_max_eligible_date date;
4415 -- Added for bug 8536385
4416 l_prof_value varchar2(30);
4417 l_entry_processed varchar2(10);
4418 procedure check_parameters is
4419 --
4420 begin
4421 --
4422 hr_utility.trace ('In hrentmnt.adjust_nonrecurring_entries');
4423 hr_utility.trace ('');
4424 hr_utility.trace (' p_assignment_id = '
4425 ||to_char (p_assignment_id));
4426 hr_utility.trace (' p_val_start_date_minus_one = '
4427 ||to_char (p_val_start_date_minus_one));
4428 hr_utility.trace (' p_val_end_date_plus_one = '
4429 ||to_char (p_val_end_date_plus_one));
4430 hr_utility.trace (' p_entries_changed = '
4431 ||p_entries_changed);
4432 hr_utility.trace ('');
4433 --
4434 end check_parameters;
4435 --
4436 begin
4437 --
4438 if g_debug then
4439 check_parameters;
4440 end if;
4441 --
4442 v_vale_start_date:=hr_general.start_of_time;
4443 -- Retrieve all nonrecurring entries that overlap the period of change
4444 /* Bug : 6809717 Added the following block of code to calculate the validation start date
4445 properly in case of people group change in assignment information*/
4446 --Start
4447 if p_dt_mode in ('DELETE_NEXT_CHANGE','FUTURE_CHANGE') then
4448 if g_debug then
4449 hr_utility.trace ('1');
4450 end if;
4451 --
4452 select count(*) into v_start_date_check from per_time_periods where payroll_id in(
4453 select payroll_id from per_all_assignments_f where assignment_id=p_assignment_id
4454 and p_val_start_date_minus_one between effective_start_date and effective_end_date)
4455 and p_val_start_date_minus_one between start_date and end_date;
4456
4457 select count(*) into v_end_date_check from per_time_periods where payroll_id in(
4458 select payroll_id from per_all_assignments_f where assignment_id=p_assignment_id
4459 and p_val_end_date_plus_one between effective_start_date and effective_end_date)
4460 and p_val_end_date_plus_one between start_date and end_date;
4461
4462 if g_debug then
4463 hr_utility.trace ('2');
4464 end if;
4465 --
4466 if v_start_date_check=0 and v_end_date_check=0 then
4467 v_chng_date:=p_val_start_date_minus_one;
4468 elsif v_start_date_check=0 then
4469 v_chng_date:=p_val_end_date_plus_one;
4470 else
4471 v_chng_date:=p_val_start_date_minus_one;
4472 end if;
4473 if g_debug then
4474 hr_utility.trace ('3');
4475 end if;
4476 --
4477 if v_start_date_check<>0 or v_end_date_check<>0 then
4478 select end_date into v_vale_start_date from per_time_periods where payroll_id in(
4479 select payroll_id from per_all_assignments_f where assignment_id=p_assignment_id
4480 and v_chng_date between effective_start_date and effective_end_date)
4481 and v_chng_date between start_date and end_date;
4482 end if;
4483
4484 if g_debug then
4485 hr_utility.trace ('4');
4486 end if;
4487 --
4488 if v_vale_start_date<>p_val_start_date_minus_one then /*Bug 8798020 Removed query to get v_alu_cnt and the condition v_alu_cnt = 0 */
4489 v_vale_start_date:=p_val_start_date_minus_one;
4490 else
4491 v_vale_start_date:=p_val_start_date_minus_one+1;
4492 end if;
4493 else
4494 v_vale_start_date:=p_val_start_date_minus_one+1;
4495 end if;
4496
4497 -- bug 8359932
4498 open get_asg_start_date;
4499 fetch get_asg_start_date into v_asg_start_date;
4500 close get_asg_start_date;
4501
4502 if g_debug then
4503 hr_utility.trace('v_asg_start_date : '|| v_asg_start_date);
4504 end if;
4505
4506 --End
4507 for v_entry in csr_entry(p_assignment_id,
4508 v_vale_start_date,
4509 p_val_end_date_plus_one) loop
4510
4511 -- Added 1 with p_val_start_date_minus_one to ensure that entries whichever
4512 -- created in past wasnt touched during this check.
4513
4514
4515 -- If nonrecurring entry existed before the period of change then
4516 -- calculate its new dates using the effective date of change otherwise use
4517 -- the end date of the entry NB. entries that are within the period of
4518 -- change will either be invalid or if they are link to all payrolls then
4519 -- their dates may have to be changed.
4520 --
4521
4522 -- Bug 6485636. Modified the logic of passing v_session_date, as it was creating
4523 -- erroneous entries for non-recurring element entries with their periods not
4524 -- matching the payroll periods and hence not being processed.
4525 -- Now, (p_val_start_date_minus_one +1) is passed as v_session_date when the date of
4526 -- payroll change lies in the period of the entry. As the date lies in
4527 -- the updated assignment period, the new payroll period will be used to update the
4528 -- non-recurring entry period. Hence, passing the session_date
4529 -- as (p_val_start_date_minus_one +1) will give correct dates from get_nonrecurring_dates().
4530
4531 /* Altered the following code for Bug No:6835808 which has previously has fix for Bug No:6722391 */
4532 if p_dt_mode='DELETE' then
4533 /* Code for termination of employee */
4534 if v_entry.effective_start_date <= p_val_start_date_minus_one then
4535 v_session_date := v_entry.effective_start_date;
4536 else
4537 v_session_date := v_entry.effective_end_date;
4538 end if;
4539 else
4540 /* Code for termination of payroll or Assignment */
4541 if v_entry.effective_start_date > p_val_start_date_minus_one then
4542 v_session_date := v_entry.effective_start_date;
4543 else
4544 v_session_date := p_val_start_date_minus_one+1;
4545 end if;
4546 end if;
4547
4548 -- bug 8359932
4549 if v_session_date < v_asg_start_date then
4550 v_session_date := v_asg_start_date;
4551 end if;
4552
4553 if g_debug then
4554 hr_utility.trace('Before calling get_nonrecurring_dates, v_session_date : '|| v_session_date);
4555 end if;
4556 v_min_eligible_date := null;
4557 v_max_eligible_date := null;
4558 --
4559 -- Calculate the start and end dates of the nonrecurring entry.
4560 --
4561 hr_entry.get_nonrecurring_dates
4562 (p_assignment_id,
4563 v_session_date,
4564 v_effective_start_date,
4565 v_effective_end_date,
4566 v_payroll_id,
4567 v_period_start_date,
4568 v_period_end_date);
4569
4570 /*Bug 8798020 Added Call to hr_entry.get_eligibility_period */
4571 hr_entry.get_eligibility_period (p_assignment_id,
4572 v_entry.element_link_id,
4573 v_session_date,
4574 v_min_eligible_date,
4575 v_max_eligible_date);
4576
4577 v_effective_start_date :=greatest(v_effective_start_date,nvl(v_min_eligible_date,v_effective_start_date));
4578 v_effective_end_date :=least(v_effective_end_date,nvl(v_max_eligible_date,v_effective_end_date));
4579
4580 -- Added for Bug 8536385 - Controlling the adjustment of Processed non-recurring entries based on a profile value(If set to Y)
4581 -- If the entry is processed, then do not adjust the element entry
4582 -- Else, adjust the element entry
4583 -- Read the profile value.
4584 fnd_profile.get('HR_ADJUST_PROCESSED_NONREC_ENTRIES', l_prof_value);
4585
4586 if nvl(l_prof_value,'Y') = 'N' then
4587 l_entry_processed := pay_paywsmee_pkg.processed(p_element_entry_id => v_entry.element_entry_id,
4588 p_original_entry_id => null,
4589 p_processing_type => 'N',
4590 p_entry_type => null ,
4591 p_effective_date => v_session_date);
4592 if g_debug then
4593 hr_utility.trace('HR_ADJUST_PROCESSED_NONREC_ENTRIES l_prof_value : '|| l_prof_value);
4594 hr_utility.trace('l_entry_processed : '|| l_entry_processed);
4595 end if;
4596 else
4597 l_entry_processed := 'N';
4598 end if;
4599
4600 if l_entry_processed = 'N' then
4601 --
4602 -- If current start date is wrong then adjust nonrecurring entry.
4603 --
4604 if v_entry.effective_start_date <> v_effective_start_date then
4605 hrentmnt.validate_adjust_entry
4606 ('UPDATE',
4607 p_assignment_id,
4608 v_entry.element_entry_id,
4609 'START',
4610 v_entry.effective_start_date,
4611 v_effective_start_date,
4612 null,
4613 null,
4614 p_entries_changed);
4615 end if;
4616 --
4617 -- If current end date is wrong then adjust nonrecurring entry.
4618 --
4619 if v_entry.effective_end_date <> v_effective_end_date then
4620 hrentmnt.validate_adjust_entry
4621 ('UPDATE',
4622 p_assignment_id,
4623 v_entry.element_entry_id,
4624 'END',
4625 v_entry.effective_end_date,
4626 v_effective_end_date,
4627 null,
4628 null,
4629 p_entries_changed);
4630 end if;
4631 end if;
4632 --
4633 end loop;
4634 --
4635 if g_debug then
4636 hr_utility.trace ('Out hrentmnt.adjust_nonrecurring_entries');
4637 end if;
4638 --
4639 end adjust_nonrecurring_entries;
4640 --
4641
4642 function get_entry_info_category(
4643 p_assignment_id in number,
4644 p_effective_date in date,
4645 p_element_link_id in number)
4646 return varchar2
4647 is
4648 cursor csr_entry_info_category(b_assignment_id in number,
4649 b_effective_date in date,
4650 b_element_link_id in number) is
4651 SELECT dfc.descriptive_flex_context_code
4652 FROM PER_BUSINESS_GROUPS_PERF bg,
4653 PAY_ELEMENT_LINKS_F el,
4654 PAY_ELEMENT_TYPES_F et,
4655 PAY_ELEMENT_CLASSIFICATIONS ec,
4656 FND_DESCR_FLEX_CONTEXTS dfc
4657 WHERE bg.business_group_id =
4658 el.business_group_id
4659 and el.element_link_id = b_element_link_id
4660 and b_effective_date between
4661 el.effective_start_date and el.effective_end_date
4662 and et.element_type_id =
4663 el.element_type_id
4664 and b_effective_date between
4665 et.effective_start_date and et.effective_end_date
4666 and ec.classification_id =
4667 et.classification_id
4668 and dfc.descriptive_flex_context_code = upper(
4669 bg.legislation_code || '_' || ec.classification_name)
4670 and dfc.application_id = 801
4671 and dfc.descriptive_flexfield_name = 'Element Entry Developer DF';
4672
4673 l_category fnd_descr_flex_contexts.descriptive_flex_context_code%type;
4674 begin
4675 null;
4676 open csr_entry_info_category(p_assignment_id, p_effective_date,
4677 p_element_link_id);
4678 fetch csr_entry_info_category into l_category;
4679 close csr_entry_info_category;
4680
4681 return l_category;
4682 end get_entry_info_category;
4683
4684 ------------------------------------------------------------------------------
4685 -- NAME --
4686 -- hrentmnt.adjust_recurring_entries --
4687 -- --
4688 -- DESCRIPTION --
4689 -- When passed a table containing what an element entry should look like --
4690 -- for a particular assignment and element link, it finds and adjusts all --
4691 -- current entries that represent the same element entry so that they are --
4692 -- consistent eg. --
4693 -- --
4694 -- Calc Entry |---------------------| |---------------> --
4695 -- Current Entry |--------------------------------------------------> --
4696 -- --
4697 -- The current entry would be split into 2 to look exactly like the --
4698 -- calculated entry.
4699 ------------------------------------------------------------------------------
4700 --
4701 procedure adjust_recurring_entries
4702 (
4703 p_dt_mode varchar2,
4704 p_assignment_id number,
4705 p_element_link_id number,
4706 p_standard_link_flag varchar2,
4707 p_mult_ent_allowed_flag varchar2,
4708 p_validation_start_date date,
4709 p_validation_end_date date,
4710 p_val_start_date_minus_one date,
4711 p_val_end_date_plus_one date,
4712 p_entry_count number,
4713 p_entry_start_date_tbl hrentmnt.t_date_table,
4714 p_entry_end_date_tbl hrentmnt.t_date_table,
4715 p_entries_changed in out nocopy varchar2,
4716 p_old_hire_date date
4717 ) is
4718 --
4719 cursor csr_distinct_entries
4720 (
4721 p_mult_ent_allowed_flag varchar2,
4722 p_assignment_id number,
4723 p_element_link_id number,
4724 p_entry_start_date date,
4725 p_entry_end_date date
4726 ) is
4727 select distinct nvl(ee.original_entry_id,ee.element_entry_id)
4728 from pay_element_entries_f ee
4729 where p_mult_ent_allowed_flag = 'Y'
4730 and ee.entry_type = 'E'
4731 and ee.assignment_id = p_assignment_id
4732 and ee.element_link_id = p_element_link_id
4733 and ee.effective_start_date <= p_entry_end_date
4734 and ee.effective_end_date >= p_entry_start_date
4735 UNION ALL
4736 select to_number(null)
4737 from sys.dual
4738 where p_mult_ent_allowed_flag = 'N'
4739 and exists
4740 (select null
4741 from pay_element_entries_f ee
4742 where ee.entry_type = 'E'
4743 and ee.assignment_id = p_assignment_id
4744 and ee.element_link_id = p_element_link_id
4745 and ee.effective_start_date <= p_entry_end_date
4746 and ee.effective_end_date >= p_entry_start_date);
4747 --
4748 -- Tuned in response to WWBug 273820. Splitting the SQL statement into 3
4749 -- distinct selects allows the use of indexes on all 3 selects. When the
4750 -- SQL was one select the combination of OR's and NVL's disabled all the
4751 -- available indexes.
4752 --
4753 -- bug 14315886 hint for 3rd union
4754 cursor csr_entry
4755 (
4756 p_mult_ent_allowed_flag varchar2,
4757 p_element_entry_id number,
4758 p_assignment_id number,
4759 p_element_link_id number,
4760 p_entry_start_date date,
4761 p_entry_end_date date
4762 ) is
4763 select ee.element_entry_id,
4764 ee.original_entry_id,
4765 ee.effective_start_date,
4766 ee.effective_end_date,
4767 ee.element_link_id,
4768 ee.creator_type
4769 from pay_element_entries_f ee
4770 where ee.entry_type = 'E'
4771 and ee.effective_start_date <= p_entry_end_date
4772 and ee.effective_end_date >= p_entry_start_date
4773 and p_mult_ent_allowed_flag = 'Y'
4774 and ee.element_entry_id = p_element_entry_id
4775 and ee.original_entry_id is null
4776 UNION ALL
4777 select ee.element_entry_id,
4778 ee.original_entry_id,
4779 ee.effective_start_date,
4780 ee.effective_end_date,
4781 ee.element_link_id,
4782 ee.creator_type
4783 from pay_element_entries_f ee
4784 where ee.entry_type = 'E'
4785 and ee.effective_start_date <= p_entry_end_date
4786 and ee.effective_end_date >= p_entry_start_date
4787 and p_mult_ent_allowed_flag = 'Y'
4788 and ee.original_entry_id = p_element_entry_id
4789 UNION ALL
4790 select /*+ index(ee PAY_ELEMENT_ENTRIES_F_N51) */ ee.element_entry_id,
4791 ee.original_entry_id,
4792 ee.effective_start_date,
4793 ee.effective_end_date,
4794 ee.element_link_id,
4795 ee.creator_type
4796 from pay_element_entries_f ee
4797 where ee.entry_type = 'E'
4798 and ee.effective_start_date <= p_entry_end_date
4799 and ee.effective_end_date >= p_entry_start_date
4800 and p_mult_ent_allowed_flag = 'N'
4801 and ee.assignment_id = p_assignment_id
4802 and ee.element_link_id = p_element_link_id
4803 order by 3;
4804 --
4805 v_entry csr_entry%rowtype;
4806 v_distinct_entry_id number;
4807 v_first_entry_adjusted boolean := false;
4808 v_dummy_date date;
4809 v_element_entry_id number;
4810 v_first_element_entry_id number;
4811 v_last_element_entry_id number;
4812 v_entry_start_date date;
4813 v_entry_end_date date;
4814 v_calc_entry_start_date date;
4815 v_calc_entry_end_date date;
4816 v_ele_entry_rec hrentmnt.t_ele_entry_rec;
4817 v_num_entry_values number := 0;
4818 v_input_value_id_tbl hr_entry.number_table;
4819 v_entry_value_tbl hr_entry.varchar2_table;
4820
4821 -- bugfix 1691062
4822 l_category fnd_descr_flex_contexts.descriptive_flex_context_code%type;
4823 --
4824 procedure check_parameters is
4825 --
4826 begin
4827 --
4828 hr_utility.trace('In hrentmnt.adjust_recurring_entries');
4829 hr_utility.trace ('');
4830 hr_utility.trace (' p_dt_mode = '
4831 ||p_dt_mode);
4832 hr_utility.trace (' p_assignment_id = '
4833 ||to_char (p_assignment_id));
4834 hr_utility.trace (' p_element_link_id = '
4835 ||to_char (p_element_link_id));
4836 hr_utility.trace (' p_standard_link_flag = '
4837 ||p_standard_link_flag);
4838 hr_utility.trace (' p_mult_ent_allowed_flag = '
4839 ||p_mult_ent_allowed_flag);
4840 hr_utility.trace (' p_validation_start_date = '
4841 ||to_char (p_validation_start_date));
4842 hr_utility.trace (' p_validation_end_date = '
4843 ||to_char (p_validation_end_date));
4844 hr_utility.trace (' p_val_start_date_minus_one = '
4845 ||to_char (p_val_start_date_minus_one));
4846 hr_utility.trace (' p_val_end_date_plus_one = '
4847 ||to_char (p_val_end_date_plus_one));
4848 --
4849 hr_utility.trace (' p_entry_count = '
4850 ||to_char (p_entry_count));
4851 hr_utility.trace (' p_entries_changed = '
4852 ||p_entries_changed);
4853 hr_utility.trace ('');
4854 --
4855 end check_parameters;
4856 --
4857 function standard_element (
4858 --
4859 -- Returns TRUE if the element link specified is a standard
4860 -- one.
4861 --
4862 p_element_link_id in number,
4863 p_effective_date in date)
4864 --
4865 return boolean is
4866 --
4867 cursor csr_standard_link is
4868 --
4869 select standard_link_flag
4870 from pay_element_links_f
4871 where element_link_id = p_element_link_id
4872 and p_effective_date between effective_start_date
4873 and effective_end_date;
4874 --
4875 l_standard varchar2 (30) := 'N';
4876 no_link_found exception;
4877 --
4878 begin
4879 --
4880 open csr_standard_link;
4881 fetch csr_standard_link into l_standard;
4882 --
4883 if csr_standard_link%notfound then
4884 close csr_standard_link;
4885 raise no_link_found;
4886 else
4887 close csr_standard_link;
4888 end if;
4889 --
4890 return (l_standard = 'Y');
4891 --
4892 EXCEPTION
4893 --
4894 when no_link_found then
4895 --
4896 fnd_message.set_name ('PAY','HR_6153_ALL_PROCEDURE_FAIL');
4897 fnd_message.set_token ('PROCEDURE',
4898 'hrentmnt.adjust_recurring_entries');
4899 fnd_message.set_token ('STEP','1');
4900 fnd_message.raise_error;
4901 --
4902 end standard_element;
4903 --
4904 function check_prior_eligibility (p_assignment_id number
4905 ,p_element_link_id number
4906 ,p_effective_date date)
4907 return varchar2 is
4908 PRAGMA AUTONOMOUS_TRANSACTION;
4909 begin
4910 return hr_entry.assignment_eligible_for_link(p_assignment_id
4911 ,p_element_link_id
4912 ,p_effective_date);
4913 exception
4914 when others then
4915 return 'N';
4916 end check_prior_eligibility;
4917
4918 begin
4919 --
4920 if g_debug then
4921 check_parameters;
4922 end if;
4923 --
4924 -- Find all distinct element entries that match the calculated element entry
4925 -- and overlap with the period of change NB. it is possible that multiple
4926 -- element entries exist and each must be processed separately ie.
4927 --
4928 -- period of change |--------------------------------|
4929 -- current entry 1 |--------------------|
4930 -- current entry 2 |--------------------|
4931 -- current entry 3 |--------------------|
4932 --
4933 open csr_distinct_entries(p_mult_ent_allowed_flag,
4934 p_assignment_id,
4935 p_element_link_id,
4936 p_val_start_date_minus_one,
4937 p_val_end_date_plus_one);
4938 --
4939 -- Get the first distinct current element entry.
4940 --
4941 fetch csr_distinct_entries into v_distinct_entry_id;
4942 --
4943 -- A current element entry matches the calculated element entry.
4944 --
4945 if csr_distinct_entries%found then
4946 --
4947 -- Continue for all distinct current element entries.
4948 --
4949 if g_debug then
4950 hr_utility.trace('Distinct entries found');
4951 end if;
4952 --
4953 while csr_distinct_entries%found loop
4954 --
4955 -- Loop around for each part of the calculated element entry NB. it is
4956 -- possible that a change can split an element entry which is then
4957 -- represented by 2 calculated element entries ie.
4958 --
4959 -- period of change |------------------|
4960 -- current entry |------------------------|
4961 -- calc entry |--| |--|
4962 --
4963 -- and find any current element entries that overlap with it.
4964 --
4965 for v_loop in 1..p_entry_count loop
4966 --
4967 -- Initialse the start and end dates of calculated element entry.
4968 --
4969 v_calc_entry_start_date := p_entry_start_date_tbl(v_loop);
4970 v_calc_entry_end_date := p_entry_end_date_tbl(v_loop);
4971 --
4972 if g_debug then
4973 hr_utility.trace('esd : ' || v_calc_entry_start_date);
4974 hr_utility.trace('eed : ' || v_calc_entry_end_date);
4975 end if;
4976 --
4977 -- Initialise the flag.
4978 --
4979 v_first_entry_adjusted := false;
4980 --
4981 -- Find current element entries that overlap with calculated element
4982 -- entry (for distinct element entry).
4983 --
4984 open csr_entry(p_mult_ent_allowed_flag,
4985 v_distinct_entry_id,
4986 p_assignment_id,
4987 p_element_link_id,
4988 v_calc_entry_start_date,
4989 v_calc_entry_end_date);
4990 --
4991 -- Get the first current element entry (for distinct element entry).
4992 --
4993 fetch csr_entry into v_entry;
4994 --
4995 -- Current element entry has been found (for distinct element entry).
4996 --
4997 if csr_entry%found then
4998 --
4999 -- Initialse the start and end dates of current element entry.
5000 --
5001 v_first_element_entry_id := v_entry.element_entry_id;
5002 v_last_element_entry_id := v_entry.element_entry_id;
5003 v_entry_start_date := v_entry.effective_start_date;
5004 v_entry_end_date := v_entry.effective_end_date;
5005 --
5006 -- Take a copy of the current element entry as this may be needed
5007 -- later.
5008 --
5009 hrentmnt.cache_element_entry
5010 (v_entry.element_entry_id,
5011 v_entry.effective_end_date,
5012 v_ele_entry_rec,
5013 v_num_entry_values,
5014 v_input_value_id_tbl,
5015 v_entry_value_tbl);
5016 --
5017 -- Continue for all current element entries that overlap with the
5018 -- calculated element entry (for current distinct element entry).
5019 --
5020 while csr_entry%found loop
5021 --
5022 -- Get next current element entry that overlaps with the
5023 -- calculated element entry (for distinct element entry).
5024 --
5025 fetch csr_entry into v_entry;
5026 --
5027 -- Either there are no more current element entries that overlap
5028 -- with the calculated element entry or the next element entry
5029 -- is not contiguous with the previous one ie.
5030 --
5031 -- calc entry |--------------------------------->
5032 -- current entry |---|----|---|-----| |----->
5033 -- 1 2 3 4
5034 --
5035 -- This can occur when the element entries have been previously
5036 -- split.
5037 --
5038 -- Now have the start and end dates of the calculated and
5039 -- current element entries which are then compared iand the
5040 -- current element entry is adjusted accordingly to be in line
5041 -- with the calculated element entry.
5042 --
5043 -- NB. although several element entries may exist only the first
5044 -- and last could possible be changed ie. 1 and 4.
5045 --
5046 if csr_entry%notfound or
5047 v_entry.effective_start_date <> v_entry_end_date + 1 then
5048 --
5049 -- Existing element entry starts before the calculated start
5050 -- date of new entry so need move the start date forwards.
5051 --
5052 -- calc entry |------------------------>
5053 -- current entry |---------------------------->
5054 --
5055 if v_entry_start_date < v_calc_entry_start_date and
5056 v_calc_entry_start_date > p_validation_start_date and
5057 v_calc_entry_start_date <= p_val_end_date_plus_one and
5058 not v_first_entry_adjusted then
5059
5060 if g_debug then
5061 hr_utility.trace ('***** bringing "start" date of current REE forwards *****');
5062 hr_utility.trace ('***** calc |-------------> *****');
5063 hr_utility.trace ('***** -----> *****');
5064 hr_utility.trace ('***** current |--------------------> *****');
5065 end if;
5066 --
5067 -- Validate the adjustment, maintain referential integrity,
5068 -- and adjust the element entry.
5069 --
5070 hrentmnt.validate_adjust_entry
5071 ('UPDATE',
5072 p_assignment_id,
5073 v_first_element_entry_id,
5074 'START',
5075 v_entry_start_date,
5076 v_calc_entry_start_date,
5077 null,
5078 null,
5079 p_entries_changed);
5080 --
5081 -- Flag that the EFFECTIVE_START_DATE of an element entry
5082 -- has been adjusted.
5083 --
5084 v_first_entry_adjusted := true;
5085 --
5086 -- Existing element entry starts after the calculated start date
5087 -- of new entry so need move the start date backwards. NB This
5088 -- should only be done for standard elements.
5089 --
5090 -- calc entry |------------------------>
5091 -- current entry |------------------->
5092 --
5093 --
5094 -- bugfix 725811
5095 -- if EEs have been created from the Salary Admin form,
5096 -- then it is valid to pull the EE's ESD
5097 -- backwards in line with the calculated ESD,
5098 -- only in the case where the old hire date is the
5099 -- same as the current entry start date (fix 1711753).
5100 -- nb. this breaks the rule that EEs associated
5101 -- with a non-standard element link should NOT have their
5102 -- ESD/EED altered programatically, however in the case of
5103 -- Salary Proposal EEs this is ok
5104 --
5105 elsif v_entry_start_date > v_calc_entry_start_date and
5106 v_calc_entry_start_date >= p_validation_start_date and
5107 v_calc_entry_start_date < p_val_end_date_plus_one and
5108 not v_first_entry_adjusted and
5109 (standard_element(v_entry.element_link_id,
5110 v_calc_entry_start_date)
5111 or
5112 (v_entry.creator_type = 'SP'
5113 and p_old_hire_date = v_entry_start_date)
5114 )
5115 then
5116
5117 if g_debug then
5118 hr_utility.trace ('***** bringing "start" date of current REE backwards *****');
5119 hr_utility.trace ('***** calc |--------------------> *****');
5120 hr_utility.trace ('***** <----- *****');
5121 hr_utility.trace ('***** current |-------------> *****');
5122 end if;
5123 --
5124 -- Validate the adjustment, maintain referential integrity,
5125 -- and adjust the element entry.
5126 --
5127 hrentmnt.validate_adjust_entry
5128 ('UPDATE',
5129 p_assignment_id,
5130 v_first_element_entry_id,
5131 'START',
5132 v_entry_start_date,
5133 v_calc_entry_start_date,
5134 null,
5135 null,
5136 p_entries_changed);
5137 --
5138 -- Flag that the EFFECTIVE_START_DATE of an element entry
5139 -- has been adjusted.
5140 --
5141 v_first_entry_adjusted := true;
5142 --
5143 end if;
5144 --
5145 -- Existing element entry ends after the calculated end date
5146 -- of new entry so need move the end date backwards.
5147 --
5148 -- calc entry |----------------|
5149 -- current entry |------------------------>
5150 --
5151 if v_entry_end_date > v_calc_entry_end_date then
5152
5153 if g_debug then
5154 hr_utility.trace ('***** bringing "end" date of current REE backwards *****');
5155 hr_utility.trace ('***** calc |-------------| *****');
5156 hr_utility.trace ('***** <----- *****');
5157 hr_utility.trace ('***** current |--------------------> *****');
5158 end if;
5159 hrentmnt.validate_adjust_entry
5160 ('UPDATE',
5161 p_assignment_id,
5162 v_last_element_entry_id,
5163 'END',
5164 v_entry_end_date,
5165 p_entry_end_date_tbl(v_loop),
5166 null,
5167 null,
5168 p_entries_changed);
5169 --
5170 -- Existing element entry ends before the calculated end date
5171 -- of new entry so need move the end date forwards. NB This
5172 -- should only be done for standard elements.
5173 -- Bug 514895. Enabled for non standard elements, this makes above sentence
5174 -- invalid.
5175 --
5176 -- calc entry |------------------------------->
5177 -- current entry |------------------|
5178 --
5179 -- NB. if the user is doing a CORRECTION then only extend the
5180 -- end date of the current element entry if it exists up to
5181 -- the day before the change ie. (WWBug 268814)
5182 --
5183 -- calc entry |--------------------------|
5184 -- current entry |-----------| (do not extend)
5185 -- current entry |--| (extend)
5186 --
5187 -- The same rule applies to DELETE_NEXT_CHANGE as this
5188 -- effectively corrects the next row using the values from the
5189 -- earlier row.
5190 --
5191 -- NB. if the user is doing an UPDATE then do not extend the
5192 -- end date of the current element entry. The updating of an
5193 -- assignment can only result in the shutting down of
5194 -- existing element entries or the creation of new ones
5195 -- ie. (WWBug 283275).
5196 --
5197 -- The same rule applies to UPDATE_CHANGE_INSERT.
5198 --
5199 -- calc entry |--------------------------|
5200 -- current entry |-----------| (do not extend)
5201 --
5202 -- Bug 514895. Removed condition for standard element. See comments above.
5203 --
5204
5205 --
5206 -- bug 911328,
5207 -- when in CORRECT mode only update REE that are SL'ed,
5208 -- ie. it possible that a non-SL'ed REE may end a
5209 -- day before the VSD,
5210 -- in this case its EED should be left alone
5211 --
5212 elsif v_entry_end_date < v_calc_entry_end_date and
5213 v_entry_end_date >= p_val_start_date_minus_one and
5214 p_dt_mode <> 'UPDATE' and
5215 p_dt_mode <> 'UPDATE_CHANGE_INSERT' and
5216 --
5217 -- boundary cases --
5218 (
5219 -- Bugfix 4221603
5220 -- In UPDATE_OVERRIDE mode, only move
5221 -- end date forwards when the entry is
5222 -- a standard entry.
5223 (p_dt_mode = 'UPDATE_OVERRIDE' and
5224 standard_element(v_entry.element_link_id,
5225 v_calc_entry_end_date) and
5226 -- Bugfix 4765204
5227 -- Only continue if entry ends within the
5228 -- 'range of change'.
5229 p_validation_start_date <= v_entry_end_date
5230 )
5231 or
5232 -- Or when the entry was created by a
5233 -- Salary Proposal
5234 (p_dt_mode = 'UPDATE_OVERRIDE' and
5235 v_entry.creator_type = 'SP' and
5236 -- Bugfix 4765204
5237 -- Only continue if entry ends within the
5238 -- 'range of change'.
5239 p_validation_start_date <= v_entry_end_date
5240 )
5241 or
5242 (p_dt_mode <> 'UPDATE_OVERRIDE')
5243 ) and
5244 (
5245 (p_dt_mode = 'DELETE_NEXT_CHANGE' and
5246 p_val_start_date_minus_one = v_entry_end_date and
5247 standard_element(v_entry.element_link_id,
5248 v_calc_entry_end_date)
5249 )
5250 or
5251 (p_dt_mode = 'DELETE_NEXT_CHANGE' and
5252 p_val_start_date_minus_one = v_entry_end_date and
5253 --Bug 6809717 Added F to the following code to adjust recurring
5254 --entries properly
5255 /* Bug 12663687 - If entry was end dated by user, don't remove end date.
5256 Logic: if element link for entry is valid in period beyond the entry end
5257 end date, we can assume it was manually end dated and end date should be
5258 retained. */
5259 (v_entry.creator_type in ('SP', 'UT') or -- fix for bug 12663687
5260 (v_entry.creator_type = 'F' and
5261 check_prior_eligibility(p_assignment_id
5262 ,v_entry.element_link_id
5263 ,p_validation_start_date) = 'N')) -- 2437795
5264 )
5265 or
5266 (p_dt_mode <> 'DELETE_NEXT_CHANGE')
5267 ) and
5268 -- Bugfix 4354757
5269 -- Only move end date forwards in FUTURE_CHANGE mode
5270 -- for standard entries, salary proposal entries and
5271 -- US tax entries (to be consistent with
5272 -- DELETE_NEXT_CHANGE mode).
5273 (
5274 (p_dt_mode = 'FUTURE_CHANGE' and
5275 p_val_start_date_minus_one = v_entry_end_date and
5276 standard_element(v_entry.element_link_id,
5277 v_calc_entry_end_date)
5278 )
5279 or
5280 (p_dt_mode = 'FUTURE_CHANGE' and
5281 p_val_start_date_minus_one = v_entry_end_date and
5282 v_entry.creator_type in ('SP', 'UT')
5283 )
5284 or
5285 (p_dt_mode <> 'FUTURE_CHANGE')
5286 ) and
5287 (
5288 (p_dt_mode = 'CORRECTION' and
5289 p_val_start_date_minus_one = v_entry_end_date and
5290 standard_element(v_entry.element_link_id,
5291 v_calc_entry_end_date)
5292 )
5293 or
5294 (p_dt_mode = 'CORRECTION' and
5295 p_val_start_date_minus_one = v_entry_end_date and
5296 v_entry.creator_type = 'SP'
5297 )
5298 or
5299 (p_dt_mode <> 'CORRECTION')
5300 ) and
5301 (
5302 (p_dt_mode = 'INSERT' and
5303 p_val_start_date_minus_one = v_entry_end_date and
5304 standard_element(v_entry.element_link_id,
5305 v_calc_entry_end_date)
5306 )
5307 or
5308 (p_dt_mode = 'INSERT' and
5309 p_val_start_date_minus_one = v_entry_end_date and
5310 v_entry.creator_type in ('SP', 'UT')
5311 )
5312 or
5313 (p_dt_mode <> 'INSERT')
5314 ) then
5315
5316 if g_debug then
5317 hr_utility.trace ('***** bringing "end" date of current REE forwards *****');
5318 hr_utility.trace ('***** calc |--------------------> *****');
5319 hr_utility.trace ('***** -----> *****');
5320 hr_utility.trace ('***** current |--------------| *****');
5321 end if;
5322 --
5323 -- Another current entry exists in the future so only move the
5324 -- end date to the day before the this element entry.
5325 --
5326 if csr_entry%found then
5327 --
5328 -- Validate the adjustment, maintain referential integrity,
5329 -- and adjust the element entry.
5330 --
5331 hrentmnt.validate_adjust_entry
5332 ('UPDATE',
5333 p_assignment_id,
5334 v_last_element_entry_id,
5335 'END',
5336 v_entry_end_date,
5337 v_entry.effective_start_date - 1,
5338 null,
5339 null,
5340 p_entries_changed);
5341 --
5342 else
5343 --
5344 -- Validate the adjustment, maintain referential integrity,
5345 -- and adjust the element entry.
5346 --
5347 hrentmnt.validate_adjust_entry
5348 ('UPDATE',
5349 p_assignment_id,
5350 v_last_element_entry_id,
5351 'END',
5352 v_entry_end_date,
5353 v_calc_entry_end_date,
5354 null,
5355 null,
5356 p_entries_changed);
5357 --
5358 end if;
5359 --
5360 end if;
5361 --
5362 -- A new element entry has been found ie. not contiguous so hold
5363 -- information about this new element entry.
5364 --
5365 v_last_element_entry_id := v_entry.element_entry_id;
5366 v_entry_start_date := v_entry.effective_start_date;
5367 v_entry_end_date := v_entry.effective_end_date;
5368 --
5369 else
5370 --
5371 -- A contiguous current element entry has been found so update
5372 -- the current element entry end date.
5373 --
5374 v_last_element_entry_id := v_entry.element_entry_id;
5375 v_entry_end_date := v_entry.effective_end_date;
5376 --
5377 end if;
5378 --
5379 end loop;
5380 --
5381 -- Current element entry has been split and first part of new
5382 -- element entry has been created by adjusting the existing current
5383 -- element entry. Need to create a new element entry for the
5384 -- element entry on the other side of the split NB. this uses the
5385 -- cached values from the first element entry ie.
5386 --
5387 -- calc entry |----| |----|
5388 -- current entry |------------------------|
5389 -- new entry |----| (created by adjusting the current entry)
5390 -- new entry |----| (created from new)
5391 --
5392 --
5393 -- Create element entry.
5394 -- Do it only when its calculated start date is within a validation
5395 -- period (bug 398360).
5396 -- However, do not do so if the entry has a creator type
5397 -- of SP (salary proposal) - fix 2298468..
5398
5399 elsif (v_calc_entry_start_date >= p_validation_start_date and
5400 v_ele_entry_rec.creator_type <> 'SP') then
5401 --
5402 if g_debug then
5403 hr_utility.trace('Original_entry_id : ' || v_distinct_entry_id);
5404 end if;
5405 hr_entry_api.insert_element_entry
5406 (p_effective_start_date => v_calc_entry_start_date,
5407 p_effective_end_date => v_dummy_date,
5408 p_element_entry_id => v_element_entry_id,
5409 p_original_entry_id => v_distinct_entry_id,
5410 p_assignment_id => p_assignment_id,
5411 p_element_link_id => p_element_link_id,
5412 p_creator_type => v_ele_entry_rec.creator_type,
5413 p_entry_type => v_ele_entry_rec.entry_type,
5414 p_cost_allocation_keyflex_id
5415 => v_ele_entry_rec.cost_allocation_keyflex_id,
5416 p_comment_id => v_ele_entry_rec.comment_id,
5417 p_creator_id => v_ele_entry_rec.creator_id,
5418 p_reason => v_ele_entry_rec.reason,
5419 p_target_entry_id => v_ele_entry_rec.target_entry_id,
5420 p_subpriority => v_ele_entry_rec.subpriority,
5421 p_personal_payment_method_id
5422 => v_ele_entry_rec.personal_payment_method_id,
5423 p_date_earned => v_ele_entry_rec.date_earned,
5424 p_attribute_category => v_ele_entry_rec.attribute_category,
5425 p_attribute1 => v_ele_entry_rec.attribute1,
5426 p_attribute2 => v_ele_entry_rec.attribute2,
5427 p_attribute3 => v_ele_entry_rec.attribute3,
5428 p_attribute4 => v_ele_entry_rec.attribute4,
5429 p_attribute5 => v_ele_entry_rec.attribute5,
5430 p_attribute6 => v_ele_entry_rec.attribute6,
5431 p_attribute7 => v_ele_entry_rec.attribute7,
5432 p_attribute8 => v_ele_entry_rec.attribute8,
5433 p_attribute9 => v_ele_entry_rec.attribute9,
5434 p_attribute10 => v_ele_entry_rec.attribute10,
5435 p_attribute11 => v_ele_entry_rec.attribute11,
5436 p_attribute12 => v_ele_entry_rec.attribute12,
5437 p_attribute13 => v_ele_entry_rec.attribute13,
5438 p_attribute14 => v_ele_entry_rec.attribute14,
5439 p_attribute15 => v_ele_entry_rec.attribute15,
5440 p_attribute16 => v_ele_entry_rec.attribute16,
5441 p_attribute17 => v_ele_entry_rec.attribute17,
5442 p_attribute18 => v_ele_entry_rec.attribute18,
5443 p_attribute19 => v_ele_entry_rec.attribute19,
5444 p_attribute20 => v_ele_entry_rec.attribute20,
5445 p_entry_information_category
5446 => v_ele_entry_rec.entry_information_category,
5447 p_entry_information1 => v_ele_entry_rec.entry_information1,
5448 p_entry_information2 => v_ele_entry_rec.entry_information2,
5449 p_entry_information3 => v_ele_entry_rec.entry_information3,
5450 p_entry_information4 => v_ele_entry_rec.entry_information4,
5451 p_entry_information5 => v_ele_entry_rec.entry_information5,
5452 p_entry_information6 => v_ele_entry_rec.entry_information6,
5453 p_entry_information7 => v_ele_entry_rec.entry_information7,
5454 p_entry_information8 => v_ele_entry_rec.entry_information8,
5455 p_entry_information9 => v_ele_entry_rec.entry_information9,
5456 p_entry_information10 => v_ele_entry_rec.entry_information10,
5457 p_entry_information11 => v_ele_entry_rec.entry_information11,
5458 p_entry_information12 => v_ele_entry_rec.entry_information12,
5459 p_entry_information13 => v_ele_entry_rec.entry_information13,
5460 p_entry_information14 => v_ele_entry_rec.entry_information14,
5461 p_entry_information15 => v_ele_entry_rec.entry_information15,
5462 p_entry_information16 => v_ele_entry_rec.entry_information16,
5463 p_entry_information17 => v_ele_entry_rec.entry_information17,
5464 p_entry_information18 => v_ele_entry_rec.entry_information18,
5465 p_entry_information19 => v_ele_entry_rec.entry_information19,
5466 p_entry_information20 => v_ele_entry_rec.entry_information20,
5467 p_entry_information21 => v_ele_entry_rec.entry_information21,
5468 p_entry_information22 => v_ele_entry_rec.entry_information22,
5469 p_entry_information23 => v_ele_entry_rec.entry_information23,
5470 p_entry_information24 => v_ele_entry_rec.entry_information24,
5471 p_entry_information25 => v_ele_entry_rec.entry_information25,
5472 p_entry_information26 => v_ele_entry_rec.entry_information26,
5473 p_entry_information27 => v_ele_entry_rec.entry_information27,
5474 p_entry_information28 => v_ele_entry_rec.entry_information28,
5475 p_entry_information29 => v_ele_entry_rec.entry_information29,
5476 p_entry_information30 => v_ele_entry_rec.entry_information30,
5477 p_num_entry_values => v_num_entry_values,
5478 p_input_value_id_tbl => v_input_value_id_tbl,
5479 p_entry_value_tbl => v_entry_value_tbl);
5480
5481 -- ** remove ** following update when api supports
5482 -- the attributes that are being updated.
5483 update pay_element_entries_f pee
5484 set pee.balance_adj_cost_flag = v_ele_entry_rec.balance_adj_cost_flag,
5485 pee.source_asg_action_id = v_ele_entry_rec.source_asg_action_id,
5486 pee.source_link_id = v_ele_entry_rec.source_link_id,
5487 pee.source_trigger_entry = v_ele_entry_rec.source_trigger_entry,
5488 pee.source_period = v_ele_entry_rec.source_period,
5489 pee.source_run_type = v_ele_entry_rec.source_run_type,
5490 pee.source_start_date = v_ele_entry_rec.source_start_date,
5491 pee.source_end_date = v_ele_entry_rec.source_end_date
5492 where pee.element_entry_id = v_element_entry_id
5493 and v_calc_entry_start_date between
5494 pee.effective_start_date and pee.effective_end_date;
5495 --
5496 end if;
5497 --
5498 close csr_entry;
5499 --
5500 end loop;
5501 --
5502 -- Get the next distinct element entry.
5503 --
5504 fetch csr_distinct_entries into v_distinct_entry_id;
5505 --
5506 end loop;
5507 --
5508 -- No distinct element entries exist for the calculated entry so create
5509 -- new element entries.
5510 --
5511 else
5512 --
5513 -- for each calculated element entry.
5514 --
5515 for v_loop in 1..p_entry_count loop
5516 --
5517 -- Set the start date for each new element entry.
5518 --
5519 v_calc_entry_start_date := p_entry_start_date_tbl(v_loop);
5520 --
5521 -- Create new element entry.
5522 -- Do it only when its calculated start date is within a validation
5523 -- period (bug 398360).
5524 --
5525 if v_calc_entry_start_date >= p_validation_start_date then
5526 --
5527 if g_debug then
5528 hr_utility.trace('********** ASG criteria delta');
5529 hr_utility.trace('********** for SL call EE insert interface');
5530 end if;
5531 hr_entry_api.insert_element_entry
5532 (p_effective_start_date => v_calc_entry_start_date,
5533 p_effective_end_date => v_dummy_date,
5534 p_element_entry_id => v_element_entry_id,
5535 p_assignment_id => p_assignment_id,
5536 p_element_link_id => p_element_link_id,
5537 p_creator_type => 'F',
5538 p_entry_type => 'E');
5539 --
5540 -- bugfix 1691062,
5541 -- check if the element entry could potentially make use of the DDFF,
5542 -- ie. entry information category is not null,
5543 -- if so, then entry_information_category needs to be set on database
5544 --
5545 -- nb. this is only done for new entries created,
5546 -- not entries that are being maintained
5547 --
5548 l_category := get_entry_info_category(p_assignment_id,
5549 v_calc_entry_start_date,
5550 p_element_link_id);
5551 --
5552 -- cannot use insert interface as other DDFF column are not present
5553 -- and these may have validation set up
5554 --
5555 if l_category is not null then
5556 if g_debug then
5557 hr_utility.trace('********** ASG criteria delta');
5558 hr_utility.trace('********** l_category>' || l_category || '<');
5559 end if;
5560
5561 --
5562 -- only single element entry row exists, no need for effective dates
5563 --
5564 UPDATE pay_element_entries_f
5565 SET entry_information_category = l_category
5566 WHERE element_entry_id = v_element_entry_id;
5567 end if;
5568 --
5569 end if;
5570 --
5571 end loop;
5572 --
5573 end if;
5574 --
5575 close csr_distinct_entries;
5576 --
5577 if g_debug then
5578 hr_utility.trace('Out hrentmnt.adjust_recurring_entries');
5579 end if;
5580 --
5581 end adjust_recurring_entries;
5582 --
5583 ------------------------------------------------------------------------------
5584 -- NAME --
5585 -- hrentmnt.adjust_entries_pqc --
5586 -- --
5587 -- DESCRIPTION --
5588 -- Adjusts element entries when the personal qualifying conditions for the --
5589 -- assignment are changed ie. DOB or probation period NB. this is only --
5590 -- applied for standard element entries as the user is able to override --
5591 -- personal qualifying conditions when creating discretionary element --
5592 -- entries. --
5593 -- NOTES --
5594 -- Only existing standard element entries are adjusted due to a change in --
5595 -- personal qualifying conditions ie. no new standard element entries are --
5596 -- created during this process. --
5597 ------------------------------------------------------------------------------
5598 --
5599 procedure adjust_entries_pqc
5600 (
5601 p_assignment_id number,
5602 p_entries_changed in out nocopy varchar2
5603 ) is
5604 --
5605 -- Local Cursors
5606 --
5607 cursor csr_standard_entries is
5608 select ee.element_entry_id,
5609 ee.creator_type,
5610 ee.creator_id,
5611 ee.effective_start_date,
5612 ee.effective_end_date,
5613 ee.element_link_id
5614 from pay_element_entries_f ee
5615 where ee.assignment_id = p_assignment_id
5616 and ee.entry_type = 'E'
5617 and exists
5618 (select null
5619 from pay_element_links_f el,
5620 pay_element_types_f et
5621 where el.element_link_id = ee.element_link_id
5622 and el.standard_link_flag = 'Y'
5623 and et.element_type_id = el.element_type_id
5624 and et.processing_type = 'R')
5625 order by ee.element_link_id, ee.effective_start_date;
5626 --
5627 -- Local Variables
5628 --
5629 v_current_element_link_id number := -1;
5630 v_los_date date;
5631 v_age_date date;
5632 v_start_date_qc date;
5633 v_new_entry_start_date date;
5634 v_min_entry_start_date date;
5635 v_first_entry_adjusted boolean := false;
5636 --
5637 procedure check_parameters is
5638 --
5639 begin
5640 --
5641 hr_utility.trace('In hrentmnt.adjust_entries_pqc');
5642 hr_utility.trace ('');
5643 hr_utility.trace (' p_assignment_id = '
5644 ||to_char (p_assignment_id));
5645 hr_utility.trace (' p_entries_changed = '
5646 ||p_entries_changed);
5647 hr_utility.trace ('');
5648 --
5649 end check_parameters;
5650 --
5651 begin
5652 --
5653 if g_debug then
5654 check_parameters;
5655 end if;
5656 --
5657 -- Find all standard element entries for the assignment / element link NB.
5658 -- each date effective instance is returned in order for each element entry
5659 -- ie.
5660 --
5661 -- EE1 |-----------|-----------|----------|------------->
5662 --
5663 -- loop 1 |-----------|
5664 -- loop 2 |-----------|
5665 -- loop 3 |----------|
5666 -- loop 4 |------------->
5667 --
5668 -- "
5669 -- | QC start date
5670 --
5671 -- This is repeated for each element entry.
5672 --
5673 -- Each row is compared against the qualifying condition start date. Each
5674 -- row that exists completely before is removed, the first row that overlaps
5675 -- with the qualifying condition start date is adjusted accordingly and then
5676 -- all subsequent rows are left alone eg.
5677 --
5678 -- loop 1 row exists before start date so remove.
5679 -- loop 2 row exists before start date so remove.
5680 -- loop 3 row overlaps with QC start date so adjust.
5681 -- loop 4 leave row alone.
5682 --
5683 for v_entry in csr_standard_entries loop
5684 --
5685 -- Check to see if the qualifying condition start date has already been
5686 -- obtained for the element entry.
5687 --
5688 if v_current_element_link_id <> v_entry.element_link_id then
5689 --
5690 -- Get the start date of the element entry accordinbg to the qualifying
5691 -- conditions.
5692 --
5693 hr_entry.return_qualifying_conditions
5694 (p_assignment_id,
5695 v_entry.element_link_id,
5696 v_entry.effective_start_date,
5697 v_los_date,
5698 v_age_date);
5699 --
5700 -- Calculate the element entry start date according to the qualifying
5701 -- conditions. Changed due to WWBug 272990.
5702 --
5703 v_start_date_qc := least(nvl(v_los_date,v_age_date),
5704 nvl(v_age_date,v_los_date));
5705 v_first_entry_adjusted := false;
5706 v_current_element_link_id := v_entry.element_link_id;
5707 --
5708 end if;
5709 --
5710 -- Element entry start date is not the same as that according to the
5711 -- qualifying conditions.
5712 --
5713 if v_start_date_qc is not null and
5714 v_start_date_qc <> v_entry.effective_start_date then
5715 --
5716 -- Element entry ends before it is eligible according to the
5717 -- qualifying conditions ie.
5718 --
5719 -- EE |--------------------------|
5720 -- "
5721 -- | QC date
5722 --
5723 if v_start_date_qc > v_entry.effective_end_date then
5724 --
5725 -- Remove element entry that exists before qualifying conditions.
5726 --
5727 hrentmnt.validate_adjust_entry
5728 ('DELETE',
5729 p_assignment_id,
5730 v_entry.element_entry_id,
5731 null,
5732 null,
5733 null,
5734 v_entry.effective_start_date,
5735 v_entry.effective_end_date,
5736 p_entries_changed);
5737 --
5738 -- Remove element entry values.
5739 --
5740 delete from pay_element_entry_values_f eev
5741 where eev.element_entry_id = v_entry.element_entry_id
5742 and eev.effective_start_date = v_entry.effective_start_date
5743 and eev.effective_end_date = v_entry.effective_end_date;
5744 --
5745 -- Remove element entries.
5746 --
5747 delete from pay_element_entries_f ee
5748 where ee.element_entry_id = v_entry.element_entry_id
5749 and ee.effective_start_date = v_entry.effective_start_date
5750 and ee.effective_end_date = v_entry.effective_end_date;
5751 --
5752 -- Call the routine that checks whether an illegal purge
5753 -- has occurred (i.e. disallowed by profile).
5754 hrentmnt.validate_purge(v_entry.element_entry_id,
5755 v_entry.element_link_id);
5756 --
5757 -- Salary Admin entry is being removed. See if the pay proposal is
5758 -- used by any other entry. If not then it is removed.
5759 --
5760 if v_entry.creator_type = 'SP' then
5761 --
5762 hrentmnt.remove_pay_proposals
5763 (p_assignment_id,
5764 v_entry.creator_id);
5765 --
5766 end if;
5767 --
5768 -- Element entry start date does match the qualifying condition
5769 -- start date ie.
5770 --
5771 -- EE |----------|---------|----->
5772 -- "
5773 -- | QC date
5774 --
5775 -- or
5776 --
5777 -- EE |-------|--------|--------->
5778 -- "
5779 -- | QC date
5780 --
5781 -- NB. only adjust the first date effective instance of each
5782 -- element entry. Any date effective instances of the element entry
5783 -- that exist completely before the qualifying condition start date
5784 -- will have already been removed.
5785 --
5786 elsif not v_first_entry_adjusted then
5787 --
5788 -- The change in qualifying conditions has meant that the start date
5789 -- of the element entry has to be moved back ie.
5790 --
5791 -- EE |-----------|-----------|----------|------------->
5792 -- "
5793 -- | QC start date
5794 --
5795 -- Must make sure that the element entry is only moved back as far as
5796 -- it is eligible ie. the assignments criteria may be different
5797 -- earlier such that it is not eligible for the element entry ie.
5798 --
5799 -- ASG |--A--|--B--|--B--|-------------------B-------------------->
5800 --
5801 -- EL |-------------------------------B-------------------------->
5802 --
5803 -- EE |-----------|-----------|----------|------------->
5804 -- "
5805 -- | QC start date
5806 --
5807 -- New EE |---------------|----.........
5808 --
5809 -- ie. back to point where element entry ceased to be eligible.
5810 --
5811 if v_start_date_qc < v_entry.effective_start_date then
5812 --
5813 -- Get the earliest date the element entry could be moved back to
5814 -- ie. as far back as the eligibility allows.
5815 --
5816 v_min_entry_start_date := min_eligibility_date
5817 (v_current_element_link_id,
5818 p_assignment_id,
5819 v_start_date_qc,
5820 v_entry.effective_start_date);
5821 --
5822 -- The element entry start date must fall within the time where
5823 -- the element entry is eligible ie. if the minimum possible start
5824 -- date is aftere the start date according to the qualifying
5825 -- conditions then the minimum eligibility date must be used.
5826 --
5827 v_new_entry_start_date := greatest(v_min_entry_start_date,
5828 v_start_date_qc);
5829 --
5830 -- The change in qualifying conditions has meant that the start date
5831 -- of the element entry has to be moved forward. This change in
5832 -- element entry start date always falls within the date effective
5833 -- lifetime of an existing element entry which means the element
5834 -- entry will be eligible for the assignment and therefore no extra
5835 -- validation relating to eligibility is required ie.
5836 --
5837 -- EE |-----------|-----------|----------|------------->
5838 -- "
5839 -- | QC start date
5840 --
5841 else
5842 v_new_entry_start_date := v_start_date_qc;
5843 end if;
5844 --
5845 -- Adjust element entry to bring element entry start date into line
5846 -- with the qualifying condition start date NB. if the new date is
5847 -- restricted to the current date due to earlier eligibility changes
5848 -- to the assignment then the start date cannot be altered ie.
5849 --
5850 -- EL |-----------------------A------------------------------->
5851 --
5852 -- ASG |----A-----|--------B--------|------------A------------->
5853 --
5854 -- EE |-------------------------->
5855 -- ^
5856 -- | current pqc date
5857 -- ^
5858 -- | new pqc date
5859 --
5860 -- In this case the element entry cannot have its start date altered
5861 -- as this would result in it existing during a period of time when it
5862 -- was not eligible.
5863 --
5864 if v_new_entry_start_date <> v_entry.effective_start_date then
5865 hrentmnt.validate_adjust_entry
5866 ('UPDATE',
5867 p_assignment_id,
5868 v_entry.element_entry_id,
5869 'START',
5870 v_entry.effective_start_date,
5871 v_new_entry_start_date,
5872 null,
5873 null,
5874 p_entries_changed);
5875 end if;
5876 --
5877 -- Indicate that the element entry has had its start date assessed
5878 -- relative to the qualifying condition start date.
5879 --
5880 v_first_entry_adjusted := true;
5881 --
5882 end if;
5883 --
5884 end if;
5885 --
5886 end loop;
5887 --
5888 if g_debug then
5889 hr_utility.trace('Out hrentmnt.adjust_entries_pqc');
5890 end if;
5891 --
5892 end adjust_entries_pqc;
5893 --
5894 ------------------------------------------------------------------------------
5895 -- NAME --
5896 -- hrentmnt.adjust_entries_cncl_term --
5897 -- --
5898 -- DESCRIPTION --
5899 -- Adjusts element entries that have been closed down during a termination. --
5900 -- When the termination is cancelled all recurring element entries that --
5901 -- were closed down are opened up again NB. any nonrecurring entries that --
5902 -- removed cannot be recreated.
5903 ------------------------------------------------------------------------------
5904 --
5905 procedure adjust_entries_cncl_term
5906 (
5907 p_business_group_id number,
5908 p_assignment_id number,
5909 p_actual_term_date date,
5910 p_last_standard_date date,
5911 p_final_process_date date,
5912 p_entries_changed in out nocopy varchar2,
5913 p_dt_mode varchar2,
5914 p_old_people_group_id number,
5915 p_new_people_group_id number,
5916 p_old_organization_id number,
5917 p_new_organization_id number,
5918 p_old_employment_category varchar2,
5919 p_new_employment_category varchar2,
5920 p_old_payroll_id number,
5921 p_new_payroll_id number
5922 ) is
5923 --
5924 -- Find all recurring element entries that are ended according to their
5925 -- termination processing rule.
5926 --
5927 -- Bugfix 2249308:
5928 -- Ignore entries that were previously stopped by a formula result
5929 -- rule. We do not wish to extend entries of this type.
5930 --
5931 cursor csr_entry
5932 (
5933 p_assignment_id number,
5934 p_actual_term_date date,
5935 p_last_standard_date date,
5936 p_final_process_date date,
5937 p_sot date
5938 ) is
5939 select ee.element_entry_id,
5940 ee.effective_start_date,
5941 ee.effective_end_date,
5942 ee.element_link_id
5943 from pay_element_entries_f ee
5944 where ee.assignment_id = p_assignment_id
5945 and ee.entry_type = 'E'
5946 and nvl(ee.updating_action_type,'null') <> 'S' -- Bugfix 2249308
5947 and exists
5948 (select null
5949 from pay_element_links_f el,
5950 pay_element_types_f et
5951 where el.element_link_id = ee.element_link_id
5952 and el.element_type_id = et.element_type_id
5953 and et.processing_type = 'R')
5954 and ee.effective_end_date =
5955 (select decode(et.post_termination_rule,
5956 'A',nvl(p_actual_term_date,p_sot),
5957 'L',nvl(p_last_standard_date,p_sot),
5958 'F',nvl(p_final_process_date,p_sot),
5959 p_sot)
5960 from pay_element_links_f el,
5961 pay_element_types_f et
5962 where el.element_link_id = ee.element_link_id
5963 and et.element_type_id = el.element_type_id
5964 and ee.effective_start_date between el.effective_start_date
5965 and el.effective_end_date
5966 and ee.effective_start_date between et.effective_start_date
5967 and et.effective_end_date);
5968 cursor csr_period_start_date
5969 (
5970 p_assignment_id number,
5971 p_final_process_date date
5972 ) is
5973 select ptp.start_date
5974 from per_assignments_f asg,
5975 per_time_periods ptp
5976 where asg.assignment_id = p_assignment_id
5977 and p_final_process_date
5978 between effective_start_date and asg.effective_end_date
5979 and ptp.payroll_id = asg.payroll_id
5980 and p_final_process_date between ptp.start_date and ptp.end_date
5981 and exists ( select null from pay_element_entries_f ent,
5982 pay_element_types_f et
5983 where ent.assignment_id = asg.assignment_id
5984 and et.element_type_id = ent.element_type_id
5985 and et.processing_type = 'N'
5986 and ent.effective_end_date >= ptp.start_date);
5987 --
5988 -- Local Constants
5989 --
5990 c_sot constant date := to_date('01/01/0001','DD/MM/YYYY');
5991 --
5992 -- Local Variables
5993 --
5994 v_entry_end_date date;
5995 v_period_start_date date;
5996 v_entries_changed varchar2(1);
5997 --
5998 procedure check_parameters is
5999 --
6000 begin
6001 --
6002 hr_utility.trace('In hrentmnt.adjust_entries_cncl_term');
6003 hr_utility.trace ('');
6004 hr_utility.trace (' p_business_group_id = '
6005 ||to_char (p_business_group_id));
6006 hr_utility.trace (' p_assignment_id = '
6007 ||to_char (p_assignment_id));
6008 hr_utility.trace (' p_actual_term_date = '
6009 ||to_char (p_actual_term_date));
6010 hr_utility.trace (' p_last_standard_date = '
6011 ||to_char (p_last_standard_date));
6012 hr_utility.trace (' p_final_process_date = '
6013 ||to_char (p_final_process_date));
6014 hr_utility.trace (' p_entries_changed = '
6015 ||p_entries_changed);
6016 hr_utility.trace ('');
6017 --
6018 end check_parameters;
6019 --
6020 begin
6021 --
6022 if g_debug then
6023 check_parameters;
6024 end if;
6025 --
6026 -- Maintain assignment link usages for the assignment.
6027 --
6028 hrentmnt.maintain_alu_asg
6029 (p_assignment_id,
6030 p_business_group_id,
6031 p_dt_mode,
6032 p_old_people_group_id,
6033 p_new_people_group_id,
6034 p_old_organization_id,
6035 p_new_organization_id,
6036 p_old_employment_category,
6037 p_new_employment_category,
6038 p_old_payroll_id,
6039 p_new_payroll_id);
6040 --
6041 -- The final process date has been set for the termination so the assignment
6042 -- will have been date effectively ended.
6043 --
6044 if p_final_process_date is not null then
6045 --
6046 -- Open up any nonrecurring entries which had been closed down when the
6047 -- assignment was date effectively ended.
6048 --
6049 -- WWBUG 314279. Switched the ordering of c_sot and p_final_process_date
6050 -- so that they agree with the parameters.
6051 -- c_sot -> validation_start_date
6052 -- p_final_process_date -> validation_end_date
6053 -- rathers than the other way around
6054 -- bug 9907554 for nonrecurring only go back as far as the start of period
6055 -- and at least one entry exists in that period
6056 open csr_period_start_date( p_assignment_id, p_final_process_date);
6057 fetch csr_period_start_date into v_period_start_date;
6058 If csr_period_start_date%FOUND then
6059 if g_debug then
6060 hr_utility.trace(' hrentmnt.adjust_entries_cncl_term period_start_date'||to_char(v_period_start_date));
6061 end if;
6062
6063 --
6064 hrentmnt.adjust_nonrecurring_entries
6065 (p_assignment_id,
6066 v_period_start_date,
6067 p_final_process_date,
6068 v_entries_changed,
6069 p_dt_mode);
6070
6071 end if;
6072 --
6073 end if;
6074 --
6075 -- Loop for all recurring entries which have been closed down during the
6076 -- employees termination.
6077 --
6078 for v_entry in csr_entry(p_assignment_id,
6079 p_actual_term_date,
6080 p_last_standard_date,
6081 p_final_process_date,
6082 c_sot) loop
6083 --
6084 -- Get the true end date of the recurring entry.
6085 --
6086 v_entry_end_date := hr_entry.recurring_entry_end_date
6087 (p_assignment_id,
6088 v_entry.element_link_id,
6089 v_entry.effective_start_date,
6090 'N',
6091 'N',
6092 null,
6093 null);
6094 --
6095 -- The recurring entry end date is less than the true end date of the
6096 -- element entry.
6097 --
6098 if v_entry.effective_end_date < v_entry_end_date then
6099 --
6100 -- Extend the recurring entry end date to the correct date.
6101 --
6102 hrentmnt.validate_adjust_entry
6103 ('UPDATE',
6104 p_assignment_id,
6105 v_entry.element_entry_id,
6106 'END',
6107 v_entry.effective_end_date,
6108 v_entry_end_date,
6109 null,
6110 null,
6111 p_entries_changed);
6112 --
6113 end if;
6114 --
6115 end loop;
6116 --
6117 if g_debug then
6118 hr_utility.trace('Out hrentmnt.adjust_entries_cncl_term');
6119 end if;
6120 --
6121 end adjust_entries_cncl_term;
6122 --
6123 ------------------------------------------------------------------------------
6124 -- NAME --
6125 -- hrentmnt.adjust_entries_cncl_hire --
6126 -- --
6127 -- DESCRIPTION --
6128 -- Adjusts element entries that are no longer valid when the hiring of a --
6129 -- person to an assignment is cancelled. The assignment ceases to exist as --
6130 -- an employee assignment so it is no longer valid to have element entries. --
6131 ------------------------------------------------------------------------------
6132 --
6133 procedure adjust_entries_cncl_hire
6134 (
6135 p_business_group_id number,
6136 p_assignment_id number,
6137 p_validation_start_date date,
6138 p_validation_end_date date,
6139 p_entries_changed in out nocopy varchar2,
6140 p_dt_mode varchar2,
6141 p_old_people_group_id number,
6142 p_new_people_group_id number,
6143 p_old_organization_id number,
6144 p_new_organization_id number,
6145 p_old_employment_category varchar2,
6146 p_new_employment_category varchar2,
6147 p_old_payroll_id number,
6148 p_new_payroll_id number
6149 ) is
6150 procedure check_parameters is
6151 --
6152 begin
6153 --
6154 hr_utility.trace('In hrentmnt.adjust_entries_cncl_hire');
6155 hr_utility.trace ('');
6156 hr_utility.trace (' p_business_group_id = '
6157 ||to_char (p_business_group_id));
6158 hr_utility.trace (' p_assignment_id = '
6159 ||to_char (p_assignment_id));
6160 hr_utility.trace (' p_validation_start_date = '
6161 ||to_char (p_validation_start_date));
6162 hr_utility.trace (' p_validation_end_date = '
6163 ||to_char (p_validation_end_date));
6164 hr_utility.trace (' p_entries_changed = '
6165 ||p_entries_changed);
6166 hr_utility.trace ('');
6167 --
6168 end check_parameters;
6169 --
6170 begin
6171 --
6172 if g_debug then
6173 check_parameters;
6174 end if;
6175 --
6176 -- Maintain assignment link usages for the assignment.
6177 --
6178 hrentmnt.maintain_alu_asg
6179 (p_assignment_id,
6180 p_business_group_id,
6181 p_dt_mode,
6182 p_old_people_group_id,
6183 p_new_people_group_id,
6184 p_old_organization_id,
6185 p_new_organization_id,
6186 p_old_employment_category,
6187 p_new_employment_category,
6188 p_old_payroll_id,
6189 p_new_payroll_id
6190 );
6191 --
6192 -- Make sure there are no nonrecurring entries that have been made
6193 -- invalid by a change in assignment criteria.
6194 --
6195 hrentmnt.val_nonrec_entries
6196 (p_assignment_id,
6197 p_validation_start_date,
6198 p_validation_end_date,
6199 p_entries_changed);
6200 --
6201 -- Remove any recurring entries which are no longer valid.
6202 --
6203 /*
6204 hrentmnt.remove_ineligible_recurring
6205 (p_assignment_id,
6206 p_entries_changed);
6207 Added the p_dt_mode parameter to the following call to enable purging of
6208 entries if cancel hire is being done*/
6209 hrentmnt.remove_ineligible_recurring
6210 (p_assignment_id,
6211 p_entries_changed,
6212 p_validation_start_date,
6213 p_validation_end_date,
6214 p_dt_mode);
6215 --
6216 -- Remove any nonrecurring entries which are no longer valid.
6217 --
6218 hrentmnt.remove_ineligible_nonrecurring
6219 (p_assignment_id,
6220 p_validation_start_date,
6221 p_validation_end_date,
6222 p_entries_changed);
6223 --
6224 if g_debug then
6225 hr_utility.trace('Out hrentmnt.adjust_entries_cncl_hire');
6226 end if;
6227 --
6228 end adjust_entries_cncl_hire;
6229 --
6230 ------------------------------------------------------------------------------
6231 -- NAME --
6232 -- hrentmnt.adjust_entries_asg_criteria --
6233 -- --
6234 -- DESCRIPTION --
6235 -- Adjusts element entries that are affected by changes in assignment --
6236 -- criteria. --
6237 ------------------------------------------------------------------------------
6238 --
6239 procedure adjust_entries_asg_criteria
6240 (
6241 p_business_group_id number,
6242 p_assignment_id number,
6243 p_dt_mode varchar2,
6244 p_old_payroll_id number,
6245 p_new_payroll_id number,
6246 p_validation_start_date date,
6247 p_validation_end_date date,
6248 p_entries_changed in out nocopy varchar2,
6249 p_old_hire_date date,
6250 p_old_people_group_id number,
6251 p_new_people_group_id number,
6252 p_old_organization_id number,
6253 p_new_organization_id number,
6254 p_old_employment_category varchar2,
6255 p_new_employment_category varchar2
6256 ) is
6257 --
6258 type t_asg_rec is record
6259 (effective_start_date date,
6260 effective_end_date date);
6261 --
6262 cursor csr_link
6263 --
6264 -- Finds all standard links and also any links for which the assignment has
6265 -- entries NB. only those links that exist during the time over which the
6266 -- assignment has been changed are returned.
6267 -- also see bugs 2167881 and 2610904.
6268 --
6269 (
6270 p_business_group_id number,
6271 p_assignment_id number,
6272 p_validation_start_date date,
6273 p_validation_end_date date,
6274 p_val_start_date_minus_one date,
6275 p_val_end_date_plus_one date
6276 ) is
6277 select el.element_link_id,
6278 min(el.effective_start_date) effective_start_date,
6279 max(el.effective_end_date) effective_end_date,
6280 el.link_to_all_payrolls_flag,
6281 el.payroll_id,
6282 el.job_id,
6283 el.grade_id,
6284 el.position_id,
6285 el.organization_id,
6286 el.location_id,
6287 el.pay_basis_id,
6288 el.employment_category,
6289 el.people_group_id,
6290 el.element_type_id,
6291 el.standard_link_flag
6292 from pay_element_links_f el
6293 where el.business_group_id = p_business_group_id
6294 and ((el.standard_link_flag = 'Y' and
6295 exists
6296 (select null
6297 from pay_element_links_f el2
6298 where el2.element_link_id = el.element_link_id
6299 and el.effective_start_date <= p_validation_end_date
6300 and el.effective_end_date >= p_validation_start_date))
6301 or (el.standard_link_flag = 'N' and
6302 (exists
6303 (
6304 -- change 115.40
6305 --select null
6306 select /*+ index(ee pay_element_entries_f_n51) */ null
6307 from pay_element_entries_f ee,
6308 pay_element_types_f et
6309 where ee.element_type_id = et.element_type_id
6310 and et.processing_type = 'R'
6311 and ee.entry_type = 'E'
6312 and ee.assignment_id = p_assignment_id
6313 and ee.element_link_id = el.element_link_id
6314 -- Bugfix 7662923
6315 and ee.effective_start_date <= p_val_end_date_plus_one
6316 and ee.effective_end_date >= p_val_start_date_minus_one)) /*Bug 8879339 reverted fix for 7662923 ,it is now fixed in remove_eligible_recurring */
6317 -- bug 15932432 removed exists() check for 'SP'
6318 -- start of change 115.16 --
6319 -- Ensure this non-standard link has not been changed from/to a standard link
6320 and NOT EXISTS
6321 (SELECT null
6322 FROM PAY_ELEMENT_LINKS_F el_sub
6323 WHERE el_sub.element_link_id = el.element_link_id
6324 and el_sub.standard_link_flag = 'Y'
6325 )
6326 -- end of change 115.16 --
6327 ))
6328 -- Change 115.60
6329 -- Bugfix 2121907
6330 -- Ensure no entries exist for this element link and assignment
6331 and not exists (
6332 select null
6333 from pay_element_entries_f ee
6334 where ee.assignment_id = p_assignment_id
6335 and ee.element_link_id = el.element_link_id
6336 and ee.effective_start_date <= p_validation_end_date
6337 and ee.effective_end_date >= p_validation_start_date
6338 and p_dt_mode in
6339 ('UPDATE','CORRECTION','UPDATE_CHANGE_INSERT'))
6340 -- End of change 115.60
6341 -- Change 115.146
6342 -- Bugfix 10401986, changes start
6343 -- Ensure when salary basis is removed in CORRECTION mode, salary
6344 -- element link is not picked up for eligibility criteria validation.
6345 and not exists (
6346 SELECT null
6347 FROM per_all_assignments_f asg_cur, pay_element_entries_f peef
6348 WHERE asg_cur.assignment_id = p_assignment_id
6349 AND asg_cur.effective_start_date = p_validation_start_date
6350 AND asg_cur.pay_basis_id is null
6351 AND EXISTS ( select null
6352 from per_all_assignments_f asg_pre
6353 where asg_pre.assignment_id = p_assignment_id
6354 and asg_pre.effective_end_date = p_val_start_date_minus_one
6355 and asg_pre.pay_basis_id is not null)
6356 AND peef.element_link_id = el.element_link_id
6357 AND peef.assignment_id = p_assignment_id
6358 AND peef.creator_type = 'SP'
6359 AND p_dt_mode in ('CORRECTION')
6360 )
6361 -- End of change 115.146
6362 group by el.element_link_id,
6363 el.link_to_all_payrolls_flag,
6364 el.payroll_id,
6365 el.job_id,
6366 el.grade_id,
6367 el.position_id,
6368 el.organization_id,
6369 el.location_id,
6370 el.pay_basis_id,
6371 el.employment_category,
6372 el.people_group_id,
6373 el.element_type_id,
6374 el.standard_link_flag
6375 ;
6376 --
6377 -- Finds all assignment pieces that match the element link eg.
6378 --
6379 -- EL |-----------------------------A------------------------------>
6380 --
6381 -- ASG |---A----|----A----|-----B-----|-----A------|-----A----->
6382 --
6383 -- pieces |--------|---------| |------------|----------->
6384 --
6385 -- These pieces can then be assembled into possible element entries that
6386 -- need to be created ie.
6387 --
6388 -- EE |------------------|
6389 --
6390 -- EE |------------------------>
6391 --
6392 -- also see bugs 2167881 and 2610904.
6393 cursor csr_assignment
6394 (
6395 p_element_link_id number,
6396 p_link_start_date date,
6397 p_link_end_date date,
6398 p_assignment_id number,
6399 p_val_start_date_minus_one date,
6400 p_val_end_date_plus_one date,
6401 p_payroll_id number,
6402 p_link_to_all_payrolls_flag varchar2,
6403 p_job_id number,
6404 p_grade_id number,
6405 p_position_id number,
6406 p_organization_id number,
6407 p_location_id number,
6408 p_pay_basis_id number,
6409 p_employment_category varchar2,
6410 p_people_group_id number
6411 ) is
6412 select asg.effective_start_date,
6413 asg.effective_end_date
6414 from per_all_assignments_f asg
6415 where asg.assignment_id = p_assignment_id
6416 and asg.assignment_type = 'E'
6417 and asg.effective_start_date <= p_val_end_date_plus_one
6418 and asg.effective_end_date >= p_val_start_date_minus_one
6419 and asg.effective_start_date <= p_link_end_date
6420 and asg.effective_end_date >= p_link_start_date
6421 and ((p_payroll_id is not null and
6422 p_payroll_id = asg.payroll_id)
6423 or (p_link_to_all_payrolls_flag = 'Y' and
6424 asg.payroll_id is not null)
6425 or (p_link_to_all_payrolls_flag = 'N' and
6426 p_payroll_id is null))
6427 and (p_job_id is null or
6428 p_job_id = asg.job_id)
6429 and (p_grade_id is null or
6430 p_grade_id = asg.grade_id)
6431 and (p_position_id is null or
6432 p_position_id = asg.position_id)
6433 and (p_organization_id is null or
6434 p_organization_id = asg.organization_id)
6435 and (p_location_id is null or
6436 p_location_id = asg.location_id)
6437 and (
6438 --
6439 -- null passed down from EL,
6440 -- if EL is NOT associated with a pay basis then return true
6441 --
6442 p_pay_basis_id is null and
6443 NOT EXISTS
6444 (SELECT /*+ ORDERED INDEX(pb PER_PAY_BASES_N1)*/
6445 pb.pay_basis_id
6446 FROM PAY_ELEMENT_LINKS_F el,
6447 PAY_INPUT_VALUES_F iv,
6448 PER_PAY_BASES pb
6449 WHERE el.element_link_id = p_element_link_id
6450 and el.effective_start_date <= asg.effective_start_date
6451 and el.effective_end_date >= asg.effective_start_date
6452 and iv.element_type_id =
6453 el.element_type_id
6454 and iv.effective_start_date <= el.effective_start_date
6455 and iv.effective_end_date >= el.effective_start_date
6456 and pb.input_value_id =
6457 iv.input_value_id
6458 and pb.business_group_id = asg.business_group_id
6459 )
6460 or
6461 --
6462 -- null passed down from EL,
6463 -- if EL is associated with a pay basis then the associated PB_ID
6464 -- must match the PB_ID on ASG
6465 --
6466 p_pay_basis_id is null and
6467 EXISTS
6468 (SELECT pb.pay_basis_id
6469 FROM PER_PAY_BASES pb,
6470 PAY_INPUT_VALUES_F iv,
6471 PAY_ELEMENT_LINKS_F el
6472 WHERE el.element_link_id = p_element_link_id
6473 and el.effective_start_date <= asg.effective_start_date
6474 and el.effective_end_date >= asg.effective_start_date
6475 and iv.element_type_id =
6476 el.element_type_id
6477 and iv.effective_start_date <= el.effective_start_date
6478 and iv.effective_end_date >= el.effective_start_date
6479 and pb.input_value_id =
6480 iv.input_value_id
6481 and pb.pay_basis_id = asg.pay_basis_id
6482 )
6483 -- change 115.26
6484 or
6485 p_pay_basis_id is null and
6486 asg.pay_basis_id is null and
6487 EXISTS
6488 (SELECT /*+ ORDERED INDEX(pb PER_PAY_BASES_N1)*/
6489 pb.pay_basis_id
6490 FROM PAY_ELEMENT_LINKS_F el,
6491 PAY_INPUT_VALUES_F iv,
6492 PER_PAY_BASES pb
6493 WHERE el.element_link_id = p_element_link_id
6494 and el.effective_start_date <= asg.effective_start_date
6495 and el.effective_end_date >= asg.effective_start_date
6496 and iv.element_type_id =
6497 el.element_type_id
6498 and iv.effective_start_date <= el.effective_start_date
6499 and iv.effective_end_date >= el.effective_start_date
6500 and pb.input_value_id =
6501 iv.input_value_id
6502 and pb.business_group_id = asg.business_group_id
6503 )
6504 or
6505 p_pay_basis_id = asg.pay_basis_id
6506 )
6507 and (p_employment_category is null or
6508 p_employment_category = asg.employment_category)
6509 and (p_people_group_id is null or
6510 exists
6511 (select null
6512 from pay_assignment_link_usages_f alu
6513 where alu.assignment_id = p_assignment_id
6514 and alu.element_link_id = p_element_link_id
6515 and alu.effective_start_date <= asg.effective_end_date
6516 and alu.effective_end_date >= asg.effective_start_date))
6517 order by asg.effective_start_date
6518 for update;
6519 --
6520 -- Local Variables
6521 --
6522 v_mult_ent_allowed_flag varchar2(30);
6523 v_assignment t_asg_rec;
6524 v_asg_start_date date;
6525 v_asg_end_date date;
6526 v_entry_start_date date;
6527 v_entry_end_date date;
6528 v_val_start_date_minus_one date;
6529 v_val_end_date_plus_one date;
6530 v_entry_count number := 0;
6531 v_entry_start_date_tbl hrentmnt.t_date_table;
6532 v_entry_end_date_tbl hrentmnt.t_date_table;
6533 v_message_name varchar2(30);
6534 v_appl_short_name varchar2(30);
6535 l_proc constant varchar2 (72) := g_package||'adjust_entries_asg_criteria';
6536 --
6537 procedure check_parameters is
6538 --
6539 begin
6540 --
6541 hr_utility.trace('In '||l_proc);
6542 hr_utility.trace ('');
6543 hr_utility.trace (' p_business_group_id = '
6544 ||to_char (p_business_group_id));
6545 --
6546 hr_utility.trace (' p_assignment_id = '
6547 ||to_char (p_assignment_id));
6548 --
6549 hr_utility.trace (' p_dt_mode = '
6550 ||p_dt_mode);
6551 --
6552 hr_utility.trace (' p_old_payroll_id = '
6553 ||to_char (p_old_payroll_id));
6554 --
6555 hr_utility.trace (' p_new_payroll_id = '
6556 ||to_char (p_new_payroll_id));
6557 --
6558 hr_utility.trace (' p_validation_start_date = '
6559 ||to_char (p_validation_start_date));
6560 --
6561 hr_utility.trace (' p_validation_end_date = '
6562 ||to_char (p_validation_end_date));
6563 --
6564 hr_utility.trace (' p_entries_changed = '
6565 ||p_entries_changed);
6566 --
6567 hr_utility.trace (' p_old_hire_date = '
6568 ||to_char(p_old_hire_date));
6569 --
6570 hr_utility.trace (' p_old_people_group_id = '
6571 ||to_char(p_old_people_group_id));
6572 --
6573 hr_utility.trace (' p_new_people_group_id = '
6574 ||to_char(p_new_people_group_id));
6575 --
6576 hr_utility.trace ('');
6577 --
6578 end check_parameters;
6579 --
6580 begin
6581 --
6582 if g_debug then
6583 check_parameters;
6584 end if;
6585 --
6586 if p_validation_start_date = hr_general.start_of_time then
6587 v_val_start_date_minus_one := hr_general.start_of_time;
6588 else
6589 v_val_start_date_minus_one := p_validation_start_date -1;
6590 end if;
6591 --
6592 if p_validation_end_date = hr_general.end_of_time then
6593 v_val_end_date_plus_one := hr_general.end_of_time;
6594 else
6595 v_val_end_date_plus_one := p_validation_end_date +1;
6596 end if;
6597 --
6598 -- Maintain assignment link usages for the assignment.
6599 --
6600 hrentmnt.maintain_alu_asg (p_assignment_id,
6601 p_business_group_id,
6602 p_dt_mode,
6603 p_old_people_group_id,
6604 p_new_people_group_id,
6605 p_old_organization_id,
6606 p_new_organization_id,
6607 p_old_employment_category,
6608 p_new_employment_category,
6609 p_old_payroll_id,
6610 p_new_payroll_id
6611 );
6612 --
6613 -- Make sure there are no nonrecurring entries that have been made
6614 -- invalid by a change in assignment criteria.
6615 --
6616 hrentmnt.val_nonrec_entries ( p_assignment_id,
6617 p_validation_start_date,
6618 p_validation_end_date,
6619 p_entries_changed);
6620 --
6621 -- Remove any nonrecurring entries which are no longer valid.
6622 --
6623 hrentmnt.remove_ineligible_nonrecurring ( p_assignment_id,
6624 p_validation_start_date,
6625 p_validation_end_date,
6626 p_entries_changed);
6627 --
6628 -- Only adjust nonrecurring entries when there has been a change of payroll
6629 --
6630 if (p_old_payroll_id <> p_new_payroll_id
6631 and p_dt_mode in ( 'UPDATE',
6632 'UPDATE_CHANGE_INSERT',
6633 'UPDATE_OVERRIDE',
6634 'CORRECTION') )
6635 --
6636 or p_dt_mode in ( 'DELETE',
6637 'FUTURE_CHANGE',
6638 'DELETE_NEXT_CHANGE')
6639 then
6640 --
6641 -- Adjust any nonrecurring entries which have been affected by a change
6642 -- of payroll.
6643 --
6644 hrentmnt.adjust_nonrecurring_entries ( p_assignment_id,
6645 v_val_start_date_minus_one,
6646 v_val_end_date_plus_one,
6647 p_entries_changed,
6648 p_dt_mode);
6649 --
6650 -- Check for element entries which have more than one adjustments
6651 -- in the same pay period.
6652 -- Fix for bug 8419416
6653 hrentmnt.validate_adjustment_entries ( p_new_payroll_id,
6654 p_assignment_id,
6655 v_val_start_date_minus_one);
6656 --
6657 end if;
6658 --
6659 -- Remove any recurring entries that are no longer eligible NB. this makes
6660 -- the adjustment of entries easier.
6661 --
6662 hrentmnt.remove_ineligible_recurring(p_assignment_id, p_entries_changed,p_validation_start_date,p_validation_end_date,p_dt_mode);
6663 --
6664 -- By this stage, all that should be left to do is to adjust the dates of
6665 -- any entries which cross the boundary of the criteria change and to insert
6666 -- any standard entries for which the assignment is eligible as a result of
6667 -- the change.
6668 --
6669 -- Find all links that are either standard links or links for which the
6670 -- assignment already has recurring entries.
6671 --
6672 for v_link in csr_link ( p_business_group_id,
6673 p_assignment_id,
6674 p_validation_start_date,
6675 p_validation_end_date,
6676 v_val_start_date_minus_one,
6677 v_val_end_date_plus_one)
6678 LOOP
6679 --
6680 -- No links match the assignment so stop processing.
6681 --
6682 if v_link.element_link_id is null then
6683 exit;
6684 end if;
6685 --
6686 open csr_assignment ( v_link.element_link_id,
6687 v_link.effective_start_date,
6688 v_link.effective_end_date,
6689 p_assignment_id,
6690 v_val_start_date_minus_one,
6691 v_val_end_date_plus_one,
6692 v_link.payroll_id,
6693 v_link.link_to_all_payrolls_flag,
6694 v_link.job_id,
6695 v_link.grade_id,
6696 v_link.position_id,
6697 v_link.organization_id,
6698 v_link.location_id,
6699 v_link.pay_basis_id,
6700 v_link.employment_category,
6701 v_link.people_group_id);
6702 --
6703 -- Get first assignment piece matching the standard link.
6704 --
6705 fetch csr_assignment into v_assignment;
6706 --
6707 -- Assignment matching standard link has been found.
6708 --
6709 if csr_assignment%found then
6710 --
6711 v_asg_start_date := v_assignment.effective_start_date;
6712 v_asg_end_date := v_assignment.effective_end_date;
6713 --
6714 -- Loop for all assignment pieces that match the standard link.
6715 --
6716 while csr_assignment%found loop
6717 --
6718 -- Get next piece of assignment.
6719 --
6720 fetch csr_assignment into v_assignment;
6721 --
6722 -- No more Assignment pieces exist or piece is is not contiguous with
6723 -- the previous piece of assignment.
6724 --
6725 if csr_assignment%notfound
6726 or v_assignment.effective_start_date <> v_asg_end_date + 1
6727 then
6728 --
6729 -- Calculate the element entry dates NB. need to check to see if the
6730 -- element entry cannot be created because the assignment has been
6731 -- terminated in the future and the end date according to the
6732 -- termination rule is before the calculated start date of the
6733 -- element entry. This should not stop other entries being created !
6734 --
6735 begin
6736 --
6737 hrentmnt.return_entry_dates (p_assignment_id,
6738 v_asg_start_date,
6739 v_link.element_link_id,
6740 v_link.effective_start_date,
6741 v_link.standard_link_flag,
6742 v_entry_start_date,
6743 v_entry_end_date);
6744 --
6745 exception
6746 --
6747 when hr_utility.hr_error then
6748 --
6749 hr_utility.get_message_details(v_message_name,v_appl_short_name);
6750 --
6751 if v_message_name = 'HR_6370_ELE_ENTRY_NO_TERM' then
6752 --
6753 v_entry_start_date := null;
6754 v_message_name := null;
6755 v_appl_short_name := null;
6756 --
6757 else
6758 --
6759 raise;
6760 --
6761 end if;
6762 --
6763 end;
6764 --
6765 -- Bug 2950302 : remove restriction on putting details of
6766 -- entry into array when assignment has been terminated,
6767 -- as originally introduced for bugs 425686 and 476600.
6768 --
6769 -- Put details of entry into array for subsequent processing.
6770 --
6771 v_entry_count := v_entry_count + 1;
6772 v_entry_start_date_tbl(v_entry_count) := v_entry_start_date;
6773 v_entry_end_date_tbl(v_entry_count) := v_entry_end_date;
6774 --
6775 --
6776 -- Reset the variables to the effective dates of the new assignment.
6777 --
6778 v_asg_start_date := v_assignment.effective_start_date;
6779 v_asg_end_date := v_assignment.effective_end_date;
6780 --
6781 -- Assignment piece is for the same assignment as the previous piece
6782 -- and it is contiguous with the previous piece.
6783 --
6784 else
6785 --
6786 -- Increment the end date of the assignment.
6787 --
6788 v_asg_end_date := v_assignment.effective_end_date;
6789 --
6790 end if;
6791 --
6792 end loop;
6793 --
6794 -- Have found some entries which may need changing.
6795 --
6796 if v_entry_count > 0 then
6797 --
6798 -- Compare the calculated element entries with those on the system
6799 -- and adjust as necessary.
6800 --
6801 if g_debug then
6802 hr_utility.trace('v_entry_count : ' || v_entry_count);
6803 end if;
6804 --
6805 -- See if multiple entries are allowed.
6806 --
6807 v_mult_ent_allowed_flag := hrentmnt.mult_ent_allowed_flag
6808 (v_link.element_link_id);
6809 --
6810 hrentmnt.adjust_recurring_entries ( p_dt_mode,
6811 p_assignment_id,
6812 v_link.element_link_id,
6813 v_link.standard_link_flag,
6814 v_mult_ent_allowed_flag,
6815 p_validation_start_date,
6816 p_validation_end_date,
6817 v_val_start_date_minus_one,
6818 v_val_end_date_plus_one,
6819 v_entry_count,
6820 v_entry_start_date_tbl,
6821 v_entry_end_date_tbl,
6822 p_entries_changed,
6823 p_old_hire_date);
6824 --
6825 -- Reset the number of entries found.
6826 --
6827 v_entry_count := 0;
6828 --
6829 end if;
6830 --
6831 end if;
6832 --
6833 close csr_assignment;
6834 --
6835 end loop;
6836 --
6837 if g_debug then
6838 hr_utility.trace('Out hrentmnt.adjust_entries_asg_criteria');
6839 end if;
6840 --
6841 end adjust_entries_asg_criteria;
6842 --
6843 ------------------------------------------------------------------------------
6844 -- NAME --
6845 -- hrentmnt.maintain_entries_el --
6846 -- --
6847 -- DESCRIPTION --
6848 -- Creates element entries on creation of a standard element link. --
6849 -- If p_assignment_id is specified, the element entry is created only for --
6850 -- the assignment. By default all of the eligible assignments will be --
6851 -- processed. --
6852 ------------------------------------------------------------------------------
6853 --
6854 procedure maintain_entries_el
6855 (
6856 p_business_group_id number,
6857 p_element_link_id number,
6858 p_element_type_id number,
6859 p_effective_start_date date,
6860 p_effective_end_date date,
6861 p_payroll_id number,
6862 p_link_to_all_payrolls_flag varchar2,
6863 p_job_id number,
6864 p_grade_id number,
6865 p_position_id number,
6866 p_organization_id number,
6867 p_location_id number,
6868 p_pay_basis_id number,
6869 p_employment_category varchar2,
6870 p_people_group_id number,
6871 p_assignment_id number default null
6872 ) is
6873 --
6874 -- Finds all assignment pieces that match the standard element link eg.
6875 --
6876 -- EL |-----------------------------A------------------------------>
6877 --
6878 -- ASG |---A----|----A----|-----B-----|-----A------|-----A----->
6879 --
6880 -- pieces |--------|---------| |------------|----------->
6881 --
6882 -- These pieces can then be assembled into possible element entries that
6883 -- need to be created ie.
6884 --
6885 -- EE |------------------|
6886 --
6887 -- EE |------------------------>
6888 --
6889 type t_asg_rec is record
6890 (assignment_id number,
6891 effective_start_date date,
6892 effective_end_date date);
6893 type cursor_type is ref cursor;
6894 --
6895 -- performance fix on cursor csr_assignment to split it based on assignment_id - bug 9167393
6896 --
6897 csr_assignment cursor_type;
6898 --
6899 -- Check if the assignment is visible with the secure view. Bug 5512101.
6900 --
6901 cursor csr_sec_asg(p_asgid number)
6902 is
6903 select 1
6904 from per_assignments_f
6905 where assignment_id = p_asgid;
6906
6907 --
6908 -- local variables
6909 --
6910 v_assignment t_asg_rec;
6911 v_asg_id number;
6912 v_asg_start_date date;
6913 v_asg_end_date date;
6914 v_entry_start_date date;
6915 v_entry_end_date date;
6916 v_dummy_number number;
6917 v_num_entry_values number;
6918 v_input_value_id_tbl hr_entry.number_table;
6919 v_entry_value_tbl hr_entry.varchar2_table;
6920 v_message_name varchar2(30);
6921 v_appl_short_name varchar2(30);
6922 v_asg_visible number;
6923 -- bugfix 1691062
6924 l_category fnd_descr_flex_contexts.descriptive_flex_context_code%type;
6925 --
6926 procedure check_parameters is
6927 --
6928 begin
6929 --
6930 hr_utility.trace ('hrentmnt.maintain_entries_el');
6931 hr_utility.trace ('');
6932 hr_utility.trace (' p_business_group_id = '
6933 ||to_char (p_business_group_id));
6934 hr_utility.trace (' p_element_link_id = '
6935 ||to_char (p_element_link_id));
6936 hr_utility.trace (' p_element_type_id = '
6937 ||to_char (p_element_type_id));
6938 hr_utility.trace (' p_effective_start_date = '
6939 ||to_char (p_effective_start_date));
6940 hr_utility.trace (' p_effective_end_date = '
6941 ||to_char (p_effective_end_date));
6942 hr_utility.trace (' p_payroll_id = '
6943 ||to_char (p_payroll_id));
6944 hr_utility.trace (' p_link_to_all_payrolls_flag = '
6945 ||p_link_to_all_payrolls_flag);
6946 hr_utility.trace (' p_job_id = '
6947 ||to_char (p_job_id));
6948 hr_utility.trace (' p_grade_id = '
6949 ||to_char (p_grade_id));
6950 hr_utility.trace (' p_position_id = '
6951 ||to_char (p_position_id));
6952 hr_utility.trace (' p_organization_id = '
6953 ||to_char (p_organization_id));
6954 hr_utility.trace (' p_location_id = '
6955 ||to_char (p_location_id));
6956 hr_utility.trace (' p_pay_basis_id = '
6957 ||to_char (p_pay_basis_id));
6958 hr_utility.trace (' p_employment_category = '
6959 ||p_employment_category);
6960 hr_utility.trace (' p_people_group_id = '
6961 ||to_char (p_people_group_id));
6962 hr_utility.trace ('');
6963 --
6964 end check_parameters;
6965 --
6966 begin
6967 g_debug := hr_utility.debug_enabled;
6968 --
6969 if g_debug then
6970 check_parameters;
6971 end if;
6972 --
6973 -- Open assignment cursor ready for processing.
6974 --
6975 begin
6976 -- performance fix on cursor csr_assignment to split it based on assignment_id - bug 9167393
6977 if p_assignment_id is not null then
6978 open csr_assignment for
6979 select asg.assignment_id,
6980 asg.effective_start_date,
6981 asg.effective_end_date
6982 from per_all_assignments_f asg
6983 where asg.assignment_id = p_assignment_id
6984 and asg.assignment_type = 'E'
6985 and asg.effective_start_date <= p_effective_end_date
6986 and asg.effective_end_date >= p_effective_start_date
6987 and ((p_payroll_id is not null and
6988 p_payroll_id = asg.payroll_id)
6989 or (p_link_to_all_payrolls_flag = 'Y' and
6990 asg.payroll_id is not null)
6991 or (p_link_to_all_payrolls_flag = 'N' and
6992 p_payroll_id is null))
6993 and (p_job_id is null or
6994 p_job_id = asg.job_id)
6995 and (p_grade_id is null or
6996 p_grade_id = asg.grade_id)
6997 and (p_position_id is null or
6998 p_position_id = asg.position_id)
6999 and (p_organization_id is null or
7000 p_organization_id = asg.organization_id)
7001 and (p_location_id is null or
7002 p_location_id = asg.location_id)
7003 and (p_employment_category is null or
7004 p_employment_category = asg.employment_category)
7005 and (p_people_group_id is null or
7006 exists
7007 (select null
7008 from pay_assignment_link_usages_f alu
7009 where alu.assignment_id = asg.assignment_id
7010 and alu.element_link_id = p_element_link_id
7011 and alu.effective_start_date <= asg.effective_end_date
7012 and alu.effective_end_date >= asg.effective_start_date))
7013 and (p_pay_basis_id = asg.pay_basis_id
7014 or (p_pay_basis_id is null and
7015 (asg.pay_basis_id is null
7016 -- Indirect salary basis check.
7017 or not exists
7018 (select pb.pay_basis_id
7019 from per_pay_bases pb,
7020 pay_input_values_f iv
7021 where iv.element_type_id = p_element_type_id
7022 and pb.input_value_id = iv.input_value_id
7023 and pb.business_group_id = p_business_group_id
7024 )
7025 or exists
7026 (select pb.pay_basis_id
7027 from per_pay_bases pb,
7028 pay_input_values_f iv
7029 where iv.element_type_id = p_element_type_id
7030 and pb.input_value_id = iv.input_value_id
7031 and pb.pay_basis_id = asg.pay_basis_id
7032 )
7033 )
7034 )
7035 )
7036 --
7037 -- ensure no entries exist for the assignment
7038 --
7039 and not exists
7040 (select null from pay_element_entries_f pee
7041 where pee.assignment_id = asg.assignment_id
7042 and pee.element_link_id = p_element_link_id
7043 )
7044 order by asg.assignment_id, asg.effective_start_date
7045 for update nowait;
7046 else
7047 open csr_assignment for
7048 select asg.assignment_id,
7049 asg.effective_start_date,
7050 asg.effective_end_date
7051 from per_all_assignments_f asg
7052 where asg.business_group_id = p_business_group_id
7053 and asg.assignment_type = 'E'
7054 and asg.effective_start_date <= p_effective_end_date
7055 and asg.effective_end_date >= p_effective_start_date
7056 and ((p_payroll_id is not null and
7057 p_payroll_id = asg.payroll_id)
7058 or (p_link_to_all_payrolls_flag = 'Y' and
7059 asg.payroll_id is not null)
7060 or (p_link_to_all_payrolls_flag = 'N' and
7061 p_payroll_id is null))
7062 and (p_job_id is null or
7063 p_job_id = asg.job_id)
7064 and (p_grade_id is null or
7065 p_grade_id = asg.grade_id)
7066 and (p_position_id is null or
7067 p_position_id = asg.position_id)
7068 and (p_organization_id is null or
7069 p_organization_id = asg.organization_id)
7070 and (p_location_id is null or
7071 p_location_id = asg.location_id)
7072 and (p_employment_category is null or
7073 p_employment_category = asg.employment_category)
7074 and (p_people_group_id is null or
7075 exists
7076 (select null
7077 from pay_assignment_link_usages_f alu
7078 where alu.assignment_id = asg.assignment_id
7079 and alu.element_link_id = p_element_link_id
7080 and alu.effective_start_date <= asg.effective_end_date
7081 and alu.effective_end_date >= asg.effective_start_date))
7082 and (p_pay_basis_id = asg.pay_basis_id
7083 or (p_pay_basis_id is null and
7084 (asg.pay_basis_id is null
7085 -- Indirect salary basis check.
7086 or not exists
7087 (select pb.pay_basis_id
7088 from per_pay_bases pb,
7089 pay_input_values_f iv
7090 where iv.element_type_id = p_element_type_id
7091 and pb.input_value_id = iv.input_value_id
7092 and pb.business_group_id = p_business_group_id
7093 )
7094 or exists
7095 (select pb.pay_basis_id
7096 from per_pay_bases pb,
7097 pay_input_values_f iv
7098 where iv.element_type_id = p_element_type_id
7099 and pb.input_value_id = iv.input_value_id
7100 and pb.pay_basis_id = asg.pay_basis_id
7101 )
7102 )
7103 )
7104 )
7105 --
7106 -- ensure no entries exist for the assignment
7107 --
7108 and not exists
7109 (select null from pay_element_entries_f pee
7110 where pee.assignment_id = asg.assignment_id
7111 and pee.element_link_id = p_element_link_id
7112 )
7113 order by asg.assignment_id, asg.effective_start_date
7114 for update nowait;
7115 end if;
7116 exception
7117 when hr_api.object_locked then
7118 --
7119 -- Failed to lock the assignment.
7120 --
7121 hr_utility.set_message(801, 'HR_7165_OBJECT_LOCKED');
7122 hr_utility.set_message_token('TABLE_NAME', 'per_all_assignments_f');
7123 hr_utility.raise_error;
7124 end;
7125 --
7126 -- Get first assignment piece matching the standard link.
7127 --
7128 fetch csr_assignment into v_assignment;
7129 --
7130 -- Assignment matching standard link has been found.
7131 --
7132 if csr_assignment%found then
7133 --
7134 -- Initialise variables for the assignment.
7135 --
7136 v_asg_id := v_assignment.assignment_id;
7137 v_asg_start_date := v_assignment.effective_start_date;
7138 v_asg_end_date := v_assignment.effective_end_date;
7139 --
7140 -- Check to see if this assignment is visible to a secure user.
7141 -- Bug 5512101.
7142 --
7143 open csr_sec_asg(v_asg_id);
7144 fetch csr_sec_asg into v_asg_visible;
7145 if csr_sec_asg%notfound then
7146 --
7147 if g_debug then
7148 hr_utility.trace('Assignment ID Not Found: '||v_asg_id);
7149 end if;
7150 --
7151 -- The user is not authorized to process this assignment.
7152 --
7153 close csr_sec_asg;
7154 close csr_assignment;
7155 --
7156 hr_utility.set_message(801,'PAY_33449_STD_LINK_SEC_ASG');
7157 hr_utility.raise_error;
7158 end if;
7159 close csr_sec_asg;
7160
7161 --
7162 -- Loop for all assignment pieces that match the standard link.
7163 --
7164 while csr_assignment%found loop
7165 --
7166 -- Get next piece of assignment.
7167 --
7168 fetch csr_assignment into v_assignment;
7169 --
7170 -- Assignment piece is not for the same assignment previously found or
7171 -- it is but is is not contiguous with the previous pice of assignment.
7172 --
7173 if csr_assignment%notfound or not
7174 (v_assignment.assignment_id = v_asg_id and
7175 v_assignment.effective_start_date = v_asg_end_date + 1) then
7176 --
7177 -- Calculate the element entry dates NB. need to check to see if the
7178 -- element entry cannot be created because the assignment has been
7179 -- terminated in the future and the end date according to the
7180 -- termination rule is before the calculated start date of the element
7181 -- entry. This should not stop other entries being created !
7182 --
7183 begin
7184 hrentmnt.return_entry_dates
7185 (v_asg_id,
7186 v_asg_start_date,
7187 p_element_link_id,
7188 p_effective_start_date,
7189 'Y',
7190 v_entry_start_date,
7191 v_entry_end_date);
7192 exception
7193 when hr_utility.hr_error then
7194 hr_utility.get_message_details(v_message_name,v_appl_short_name);
7195 if v_message_name = 'HR_6370_ELE_ENTRY_NO_TERM' then
7196 v_entry_start_date := null;
7197 v_message_name := null;
7198 v_appl_short_name := null;
7199 else
7200 raise;
7201 end if;
7202 end;
7203 --
7204 -- An element entry needs to be created.
7205 --
7206 if v_entry_start_date is not null then
7207 --
7208 -- Create new element netry for standard link.
7209 --
7210 if g_debug then
7211 hr_utility.trace('********** SL creation');
7212 hr_utility.trace('********** for SL call EE insert interface');
7213 end if;
7214 hr_entry_api.insert_element_entry
7215 (p_effective_start_date => v_entry_start_date,
7216 p_effective_end_date => v_entry_end_date,
7217 p_element_entry_id => v_dummy_number,
7218 p_assignment_id => v_asg_id,
7219 p_element_link_id => p_element_link_id,
7220 p_creator_type => 'F',
7221 p_entry_type => 'E');
7222
7223 -- bugfix 1691062
7224 l_category := get_entry_info_category(v_asg_id,
7225 v_entry_start_date,
7226 p_element_link_id);
7227 if l_category is not null then
7228 if g_debug then
7229 hr_utility.trace('********** SL creation');
7230 hr_utility.trace('********** l_category>' || l_category || '<');
7231 end if;
7232
7233 UPDATE pay_element_entries_f
7234 SET entry_information_category = l_category
7235 WHERE element_entry_id = v_dummy_number;
7236 end if;
7237
7238 end if;
7239 --
7240 -- Reset the variables to the effective dates of the new assignment.
7241 --
7242 v_asg_start_date := v_assignment.effective_start_date;
7243 v_asg_end_date := v_assignment.effective_end_date;
7244 --
7245 -- Assignment piece is for the same assignment as the previous piece
7246 -- and it is contiguous with the previous piece.
7247 --
7248 else
7249 --
7250 -- Increment the end date of the assignment.
7251 --
7252 v_asg_end_date := v_assignment.effective_end_date;
7253 --
7254 end if;
7255 --
7256 -- Keep track of the current assignment being processed.
7257 --
7258 v_asg_id := v_assignment.assignment_id;
7259 --
7260 end loop;
7261 --
7262 end if;
7263 --
7264 -- Close assignment cursor as all assignments have been processed.
7265 --
7266 close csr_assignment;
7267 --
7268 if g_debug then
7269 hr_utility.trace ('Out hrentmnt.maintain_entries_el');
7270 end if;
7271 --
7272 end maintain_entries_el;
7273 --
7274 --
7275 --
7276 procedure dump_info(p_assignment_id in number,
7277 p_business_group_id in number)
7278 is
7279 cursor csr_assignment(b_assignment_id number,
7280 b_business_group_id number) is
7281 SELECT asg.assignment_id,
7282 asg.effective_start_date,
7283 asg.effective_end_date,
7284 asg.primary_flag,
7285 --
7286 -- begin criteria used for EL matching
7287 --
7288 asg.organization_id,
7289 asg.people_group_id,
7290 asg.job_id,
7291 asg.position_id,
7292 asg.grade_id,
7293 asg.location_id,
7294 asg.employment_category,
7295 asg.payroll_id,
7296 asg.pay_basis_id
7297 --
7298 -- end criteria used for EL matching
7299 --
7300 FROM PER_ALL_ASSIGNMENTS_F asg
7301 WHERE asg.assignment_id = b_assignment_id
7302 and asg.business_group_id = b_business_group_id
7303 ORDER BY
7304 asg.assignment_id,
7305 asg.effective_start_date
7306 ;
7307
7308 cursor ee is
7309 select distinct
7310 pee.element_entry_id,
7311 pee.entry_type,
7312 pee.creator_type,
7313 to_char(pee.effective_start_date, 'YYYY/MM/DD') esd,
7314 to_char(pee.effective_end_date, 'YYYY/MM/DD') eed,
7315 pel.element_link_id,
7316 pel.element_type_id,
7317 pel.payroll_id,
7318 pel.job_id,
7319 pel.position_id,
7320 pel.people_group_id,
7321 pel.organization_id,
7322 pel.location_id,
7323 pel.grade_id,
7324 pel.pay_basis_id,
7325 pel.link_to_all_payrolls_flag,
7326 pel.standard_link_flag
7327 from pay_element_entries_f pee,
7328 pay_element_links_f pel
7329 where pee.assignment_id = p_assignment_id
7330 and pel.element_link_id = pee.element_link_id;
7331
7332 begin
7333 hr_utility.trace('***** dump start *****');
7334
7335 for rec_assignment in csr_assignment(p_assignment_id,
7336 p_business_group_id) loop
7337 hr_utility.trace('rec_assignment.assignment_id>' ||
7338 rec_assignment.assignment_id || '<');
7339 hr_utility.trace(' rec_assignment.effective_start_date>' ||
7340 rec_assignment.effective_start_date || '<');
7341 hr_utility.trace(' rec_assignment.effective_end_date>' ||
7342 rec_assignment.effective_end_date || '<');
7343 hr_utility.trace(' rec_assignment.primary_flag>' ||
7344 rec_assignment.primary_flag || '<');
7345 hr_utility.trace(' rec_assignment.organization_id>' ||
7346 rec_assignment.organization_id || '<');
7347 hr_utility.trace(' rec_assignment.people_group_id>' ||
7348 rec_assignment.people_group_id || '<');
7349 hr_utility.trace(' rec_assignment.job_id>' ||
7350 rec_assignment.job_id || '<');
7351 hr_utility.trace(' rec_assignment.position_id>' ||
7352 rec_assignment.position_id || '<');
7353 hr_utility.trace(' rec_assignment.grade_id>' ||
7354 rec_assignment.grade_id || '<');
7355 hr_utility.trace(' rec_assignment.location_id>' ||
7356 rec_assignment.location_id || '<');
7357 hr_utility.trace(' rec_assignment.employment_category>' ||
7358 rec_assignment.employment_category || '<');
7359 hr_utility.trace(' rec_assignment.payroll_id>' ||
7360 rec_assignment.payroll_id || '<');
7361 hr_utility.trace(' rec_assignment.pay_basis_id>' ||
7362 rec_assignment.pay_basis_id || '<');
7363 end loop;
7364
7365 hr_utility.trace('>>> Element Entry info <<<');
7366 hr_utility.trace('EEID ET CT ESD EED ELID ETID PYID JOB POS PGRP ORG LOC GRD PBID LFLG SLFLG');
7367
7368 for eerec in ee loop
7369
7370 hr_utility.trace(
7371 eerec.element_entry_id || ' ' ||
7372 eerec.entry_type || ' ' ||
7373 eerec.creator_type || ' ' ||
7374 eerec.esd || ' ' ||
7375 eerec.eed || ' ' ||
7376 eerec.element_link_id || ' ' ||
7377 eerec.element_type_id || ' ' ||
7378 nvl(to_char(eerec.payroll_id), '*') || ' ' ||
7379 nvl(to_char(eerec.job_id), '*') || ' ' ||
7380 nvl(to_char(eerec.position_id), '*') || ' ' ||
7381 nvl(to_char(eerec.people_group_id), '*') || ' ' ||
7382 nvl(to_char(eerec.organization_id), '*') || ' ' ||
7383 nvl(to_char(eerec.location_id), '*') || ' ' ||
7384 nvl(to_char(eerec.grade_id), '*') || ' ' ||
7385 nvl(to_char(eerec.pay_basis_id), '*') || ' ' ||
7386 eerec.link_to_all_payrolls_flag || ' ' ||
7387 eerec.standard_link_flag);
7388
7389 end loop;
7390
7391 hr_utility.trace('***** dump end *****');
7392 end dump_info;
7393 --
7394 --
7395 --
7396 ------------------------------------------------------------------------------
7397 -- NAME --
7398 -- hrentmnt.maintain_entries_asg --
7399 -- --
7400 -- DESCRIPTION --
7401 -- This forms the interface into the procedures that maintain element --
7402 -- entries when affected by various events ie. --
7403 -- --
7404 -- CHANGE_PQC : changes in personal qualifying conditions. --
7405 -- CNCL_TERM : a termination is cancelled. --
7406 -- CNCL_HIRE : the hiring of a person is cancelled. --
7407 -- ASG_CRITERIA : assignment criteria has chnaged. --
7408 -- HIRE_APPL : an applicant is hired. --
7409 ------------------------------------------------------------------------------
7410 --
7411 procedure maintain_entries_asg
7412 (
7413 p_assignment_id number,
7414 p_old_payroll_id number,
7415 p_new_payroll_id number,
7416 p_business_group_id number,
7417 p_operation varchar2,
7418 p_actual_term_date date,
7419 p_last_standard_date date,
7420 p_final_process_date date,
7421 p_dt_mode varchar2,
7422 p_validation_start_date date,
7423 p_validation_end_date date,
7424 p_entries_changed in out nocopy varchar2,
7425 p_old_hire_date date default null,
7426 p_old_people_group_id number ,
7427 p_new_people_group_id number ,
7428 p_old_organization_id number ,
7429 p_new_organization_id number ,
7430 p_old_job_id number default null,
7431 p_new_job_id number default null,
7432 p_new_position_id number default null,
7433 p_old_position_id number default null,
7434 p_new_location_id number default null,
7435 p_old_location_id number default null,
7436 p_new_grade_id number default null,
7437 p_old_grade_id number default null,
7438 p_new_pay_basis_id number default null,
7439 p_old_pay_basis_id number default null,
7440 p_old_employment_category varchar2 default null,
7441 p_new_employment_category varchar2 default null
7442 ) is
7443 --
7444 procedure check_parameters is
7445 --
7446 begin
7447 --
7448 hr_utility.trace('In hrentmnt.maintain_entries_asg');
7449 hr_utility.trace ('');
7450 hr_utility.trace (' p_assignment_id = '
7451 ||to_char (p_assignment_id));
7452 hr_utility.trace (' p_old_payroll_id = '
7453 ||to_char (p_old_payroll_id));
7454 hr_utility.trace (' p_new_payroll_id = '
7455 ||to_char (p_new_payroll_id));
7456 hr_utility.trace (' p_business_group_id = '
7457 ||to_char (p_business_group_id));
7458 hr_utility.trace (' p_operation = '
7459 ||p_operation);
7460 hr_utility.trace (' p_actual_term_date = '
7461 ||to_char (p_actual_term_date));
7462 hr_utility.trace (' p_last_standard_date = '
7463 ||to_char (p_last_standard_date));
7464 hr_utility.trace (' p_final_process_date = '
7465 ||to_char (p_final_process_date));
7466 hr_utility.trace (' p_dt_mode = '
7467 ||p_dt_mode);
7468 hr_utility.trace (' p_validation_start_date = '
7469 ||to_char (p_validation_start_date));
7470 hr_utility.trace (' p_validation_end_date = '
7471 ||to_char (p_validation_end_date));
7472 hr_utility.trace (' p_entries_changed = '
7473 ||p_entries_changed);
7474 hr_utility.trace (' p_old_hire_date = '
7475 ||to_char(p_old_hire_date));
7476 hr_utility.trace (' p_old_people_group_id = '
7477 ||to_char(p_old_people_group_id));
7478 hr_utility.trace (' p_new_people_group_id = '
7479 ||to_char(p_new_people_group_id));
7480 hr_utility.trace (' p_old_organization_id = '
7481 ||to_char(p_old_organization_id));
7482 hr_utility.trace (' p_new_organization_id = '
7483 ||to_char(p_new_organization_id));
7484 hr_utility.trace ('');
7485 --
7486 end check_parameters;
7487 --
7488 begin
7489 --
7490 null;
7491 -- --
7492 begin
7493 g_debug := hr_utility.debug_enabled;
7494 --
7495 if g_debug then
7496 check_parameters;
7497 end if;
7498 --
7499 p_entries_changed := null;
7500 --
7501 -- Qualifying conditions have changed.
7502 --
7503 if p_operation = 'CHANGE_PQC' then
7504 hrentmnt.adjust_entries_pqc
7505 (p_assignment_id,
7506 p_entries_changed);
7507 --
7508 -- An employee termination is being cancelled.
7509 --
7510 elsif p_operation = 'CNCL_TERM' then
7511 hrentmnt.adjust_entries_cncl_term
7512 (p_business_group_id,
7513 p_assignment_id,
7514 p_actual_term_date,
7515 p_last_standard_date,
7516 p_final_process_date,
7517 p_entries_changed,
7518 p_dt_mode,
7519 p_old_people_group_id,
7520 p_new_people_group_id,
7521 p_old_organization_id,
7522 p_new_organization_id,
7523 p_old_employment_category,
7524 p_new_employment_category,
7525 p_old_payroll_id,
7526 p_new_payroll_id
7527 );
7528 --
7529 -- The hiring of an employee has been cancelled.
7530 --
7531 elsif p_operation = 'CNCL_HIRE' then
7532 hrentmnt.adjust_entries_cncl_hire
7533 (p_business_group_id,
7534 p_assignment_id,
7535 p_validation_start_date,
7536 p_validation_end_date,
7537 p_entries_changed,
7538 p_dt_mode,
7539 p_old_people_group_id,
7540 p_new_people_group_id,
7541 p_old_organization_id,
7542 p_new_organization_id,
7543 p_old_employment_category,
7544 p_new_employment_category,
7545 p_old_payroll_id,
7546 p_new_payroll_id
7547 );
7548 --
7549 -- An employees assignment has been changed.
7550 --
7551 elsif p_operation ='ASG_CRITERIA' then
7552 hrentmnt.adjust_entries_asg_criteria
7553 (p_business_group_id,
7554 p_assignment_id,
7555 p_dt_mode,
7556 p_old_payroll_id,
7557 p_new_payroll_id,
7558 p_validation_start_date,
7559 p_validation_end_date,
7560 p_entries_changed,
7561 p_old_hire_date,
7562 p_old_people_group_id,
7563 p_new_people_group_id,
7564 p_old_organization_id,
7565 p_new_organization_id,
7566 p_old_employment_category,
7567 p_new_employment_category);
7568 --
7569 -- An applicant has been hired
7570 --
7571 elsif p_operation = 'HIRE_APPL' then
7572 --
7573 -- Bugfix 5182845
7574 -- We need to ensure that the ALUs are rebuilt, since ALUs are never
7575 -- maintained for applicants. Therefore, even if the old and new people
7576 -- group ids are the same, the ALUs won't have been built previously.
7577 -- In order to force a rebuild of the ALUs, the old and new people group
7578 -- ids must differ. We modify the old people group id to ensure this.
7579 -- The min value of the pay_people_groups_s sequence is 1, so setting
7580 -- p_old_people_group_id to 0 will guarantee the old and new people group
7581 -- ids will always differ.
7582 --
7583 hrentmnt.adjust_entries_asg_criteria
7584 (p_business_group_id,
7585 p_assignment_id,
7586 p_dt_mode,
7587 p_old_payroll_id,
7588 p_new_payroll_id,
7589 p_validation_start_date,
7590 p_validation_end_date,
7591 p_entries_changed,
7592 p_old_hire_date,
7593 0, -- p_old_new_people_group_id
7594 p_new_people_group_id,
7595 p_old_organization_id,
7596 p_new_organization_id,
7597 p_old_employment_category,
7598 p_new_employment_category);
7599 end if;
7600 --
7601 if g_debug then
7602 hr_utility.trace('Out hrentmnt.maintain_entries_asg');
7603 end if;
7604 --
7605 exception
7606 when others then
7607 --
7608 -- if an error occurs, print the message and raise the error again
7609 if g_debug then
7610
7611 hr_utility.trace('****************************************');
7612 hr_utility.trace('Sqlcode>' || Sqlcode || '<');
7613 hr_utility.trace('Sqlerrm>' || Sqlerrm || '<');
7614 hr_utility.trace('****************************************');
7615
7616 dump_info(p_assignment_id, p_business_group_id);
7617
7618 end if;
7619 raise;
7620 end;
7621 -- --
7622 end maintain_entries_asg;
7623 --
7624 ------------------------------------------------------------------------------
7625 -- NAME --
7626 -- hrentmnt.maintain_entries_asg --
7627 -- Overloaded version2 to allow backward compatibility. --
7628 -- --
7629 -- DESCRIPTION --
7630 -- This forms the interface into the procedures that maintain element --
7631 -- entries when affected by various events ie. --
7632 -- --
7633 -- CHANGE_PQC : changes in personal qualifying conditions. --
7634 -- CNCL_TERM : a termination is cancelled. --
7635 -- CNCL_HIRE : the hiring of a person is cancelled. --
7636 -- ASG_CRITERIA : assignment criteria has chnaged. --
7637 -- HIRE_APPL : an applicant is hired. --
7638 ------------------------------------------------------------------------------
7639 --
7640 procedure maintain_entries_asg
7641 (
7642 p_assignment_id number,
7643 p_old_payroll_id number,
7644 p_new_payroll_id number,
7645 p_business_group_id number,
7646 p_operation varchar2,
7647 p_actual_term_date date,
7648 p_last_standard_date date,
7649 p_final_process_date date,
7650 p_dt_mode varchar2,
7651 p_validation_start_date date,
7652 p_validation_end_date date,
7653 p_entries_changed in out nocopy varchar2,
7654 p_old_hire_date date default null,
7655 p_old_people_group_id number default null,
7656 p_new_people_group_id number default null
7657 ) is
7658 --
7659 procedure check_parameters is
7660 --
7661 begin
7662 --
7663 hr_utility.trace('In hrentmnt.maintain_entries_asg. overload 2 with pg but no org');
7664 --
7665 end check_parameters;
7666 --
7667 begin
7668 --
7669 null;
7670 -- --
7671 begin
7672 g_debug := hr_utility.debug_enabled;
7673 --
7674 if g_debug then
7675 check_parameters;
7676 end if;
7677 --
7678 -- bug 12728282 call overloaded version - no org_id is available
7679 hrentmnt.maintain_entries_asg
7680 (p_assignment_id,
7681 p_old_payroll_id,
7682 p_new_payroll_id,
7683 p_business_group_id,
7684 p_operation,
7685 p_actual_term_date,
7686 p_last_standard_date,
7687 p_final_process_date,
7688 p_dt_mode,
7689 p_validation_start_date,
7690 p_validation_end_date,
7691 p_entries_changed,
7692 p_old_hire_date,
7693 p_old_people_group_id,
7694 p_new_people_group_id,
7695 null, --p_old_organization_id
7696 null); --p_new_organization_id
7697 --
7698 exception
7699 when others then
7700 --
7701 -- if an error occurs, print the message and raise the error again
7702 if g_debug then
7703
7704 hr_utility.trace('****************************************');
7705 hr_utility.trace('Sqlcode>' || Sqlcode || '<');
7706 hr_utility.trace('Sqlerrm>' || Sqlerrm || '<');
7707 hr_utility.trace('****************************************');
7708
7709 dump_info(p_assignment_id, p_business_group_id);
7710
7711 end if;
7712 raise;
7713 end;
7714 -- --
7715 end maintain_entries_asg;
7716 --
7717 ------------------------------------------------------------------------------
7718 -- NAME --
7719 -- hrentmnt.maintain_entries_asg --
7720 -- --
7721 -- DESCRIPTION --
7722 -- Overloaded version1 to allow backward compatibility. --
7723 ------------------------------------------------------------------------------
7724 --
7725 procedure maintain_entries_asg
7726 (
7727 p_assignment_id number,
7728 p_business_group_id number,
7729 p_operation varchar2,
7730 p_actual_term_date date,
7731 p_last_standard_date date,
7732 p_final_process_date date,
7733 p_dt_mode varchar2,
7734 p_validation_start_date date,
7735 p_validation_end_date date
7736 ) is
7737 --
7738 -- Local Variables
7739 --
7740 v_entries_changed varchar2(1);
7741 --
7742 procedure check_parameters is
7743 --
7744 begin
7745 --
7746 hr_utility.trace('In hrentmnt.maintain_entries_asg. overload 1 no pg or org');
7747 --
7748 end check_parameters;
7749 --
7750 begin
7751 null;
7752 -- --
7753 begin
7754 g_debug := hr_utility.debug_enabled;
7755 --
7756 if g_debug then
7757 check_parameters;
7758 end if;
7759 --
7760 hrentmnt.maintain_entries_asg
7761 (p_assignment_id,
7762 1,
7763 2,
7764 p_business_group_id,
7765 p_operation,
7766 p_actual_term_date,
7767 p_last_standard_date,
7768 p_final_process_date,
7769 p_dt_mode,
7770 p_validation_start_date,
7771 p_validation_end_date,
7772 v_entries_changed,
7773 null, -- p_old_people_group_id
7774 null); -- p_new_people_group_id
7775 --
7776 exception
7777 when others then
7778 --
7779 -- if an error occurs, print the message and raise the error again
7780 --
7781 if g_debug then
7782 hr_utility.trace('***** over');
7783 hr_utility.trace('Sqlcode>' || Sqlcode || '<');
7784 hr_utility.trace('Sqlerrm>' || Sqlerrm || '<');
7785 hr_utility.trace('*****');
7786 end if;
7787 raise;
7788 end;
7789 -- --
7790 end maintain_entries_asg;
7791 --
7792 ------------------------------------------------------------------------------
7793 -- NAME --
7794 -- hrentmnt.check_opmu --
7795 -- --
7796 -- DESCRIPTION --
7797 -- Ensures that on transfer of Payroll (on the Assignment) or when a change --
7798 -- causes the Payroll to change in the future that Personal Payment Methods --
7799 -- have corresponding Org Pay Methods that are used by the new Payroll. --
7800 -- i.e. that Personal Payment Methods are not invalidated. --
7801 ------------------------------------------------------------------------------
7802 --
7803 procedure check_opmu
7804 (
7805 p_assignment_id number,
7806 p_payroll_id number,
7807 p_dt_mode varchar2,
7808 p_validation_start_date date,
7809 p_validation_end_date date
7810 ) is
7811 --
7812 cursor csr_personal_payment_methods
7813 (
7814 p_assignment_id number,
7815 p_validation_start_date date,
7816 p_validation_end_date date
7817 ) is
7818 select ppm.personal_payment_method_id,
7819 ppm.org_payment_method_id,
7820 greatest(ppm.effective_start_date,p_validation_start_date)
7821 start_date,
7822 least(ppm.effective_end_date,p_validation_end_date) end_date
7823 from pay_personal_payment_methods_f ppm
7824 where ppm.assignment_id = p_assignment_id
7825 and ppm.effective_start_date <= p_validation_end_date
7826 and ppm.effective_end_date >= p_validation_start_date;
7827 --
7828 -- Local Variables
7829 --
7830 no_opmu varchar2(1) := 'N';
7831 --
7832 procedure check_parameters is
7833 --
7834 begin
7835 --
7836 hr_utility.trace ('In hrentmnt.check_opmu');
7837 hr_utility.trace ('');
7838 hr_utility.trace (' p_assignment_id = '
7839 ||to_char (p_assignment_id));
7840 hr_utility.trace (' p_payroll_id = '
7841 ||to_char (p_payroll_id));
7842 hr_utility.trace (' p_dt_mode = '
7843 ||p_dt_mode);
7844 hr_utility.trace (' p_validation_start_date = '
7845 ||to_char (p_validation_start_date));
7846 hr_utility.trace (' p_validation_end_date = '
7847 ||to_char (p_validation_end_date));
7848 hr_utility.trace ('');
7849 --
7850 end check_parameters;
7851 --
7852 begin
7853 g_debug := hr_utility.debug_enabled;
7854 --
7855 if g_debug then
7856 check_parameters;
7857 end if;
7858 --
7859 -- If the mode is DELETE or ZAP then merely check to see if there will be
7860 -- any PPMs left after the end date of the Assignment
7861 --
7862 if p_dt_mode = 'DELETE' or p_dt_mode = 'ZAP' then
7863 --
7864 begin
7865 select 'Y'
7866 into no_opmu
7867 from sys.dual
7868 where exists
7869 (select null
7870 from pay_personal_payment_methods_f ppm
7871 where assignment_id = p_assignment_id
7872 and ppm.effective_end_date >= p_validation_start_date);
7873 exception
7874 when no_data_found then
7875 if g_debug then
7876 hr_utility.trace('No opmu for DELETE or ZAP mode');
7877 end if;
7878 end;
7879 --
7880 -- Otherwise check that the existing PPMs remain valid after the Transfer
7881 --
7882 elsif not p_dt_mode = 'INSERT' then
7883 --
7884 -- For each PPM for the Assignment that has any part of its life within the
7885 -- Assignment Validation Start Date and Validation End Date Range if the
7886 -- following statements returns 'Y' then ERROR because OPMUs are
7887 -- invalidated by the change of PAYROLL.
7888 --
7889 for v_ppm in csr_personal_payment_methods(p_assignment_id,
7890 p_validation_start_date,
7891 p_validation_end_date) loop
7892 --
7893 -- first ensure that there is a valid opmu on the start date of the ppm
7894 -- if there isn't then flag an error
7895 --
7896 begin
7897 select 'Y'
7898 into no_opmu
7899 from sys.dual
7900 where not exists
7901 (select null
7902 from pay_org_pay_method_usages_f opmu,
7903 pay_payrolls_f p
7904 where v_ppm.start_date between opmu.effective_start_date
7905 and opmu.effective_end_date
7906 and opmu.org_payment_method_id =
7907 v_ppm.org_payment_method_id
7908 and opmu.effective_start_date
7909 between p.effective_start_date and p.effective_end_date
7910 and opmu.payroll_id = p.payroll_id
7911 and p.payroll_id = p_payroll_id);
7912 exception
7913 when no_data_found then null;
7914 end;
7915 --
7916 if no_opmu = 'Y' then
7917 if g_debug then
7918 hr_utility.trace('No opmu from first check.');
7919 end if;
7920 exit;
7921 end if;
7922 --
7923 -- Now ensure that there is a valid OPMU for the lifetime of the PPM.
7924 -- For each OPMU that is valid ensure that if it ends before the end of
7925 -- the PPM then there is at least one other OPMU that is valid on the day
7926 -- after the end date of the OPMU currently being considered. If there is
7927 -- no such OPMU then an error is flagged.
7928 --
7929 begin
7930 select 'Y'
7931 into no_opmu
7932 from sys.dual
7933 where exists
7934 (select null
7935 from pay_org_pay_method_usages_f opmu,
7936 pay_payrolls_f p
7937 where opmu.effective_start_date <= v_ppm.end_date
7938 and opmu.effective_end_date >= v_ppm.start_date
7939 and opmu.org_payment_method_id =
7940 v_ppm.org_payment_method_id
7941 and opmu.effective_start_date between
7942 p.effective_start_date and p.effective_end_date
7943 and opmu.payroll_id = p.payroll_id
7944 and p.payroll_id = p_payroll_id
7945 and opmu.effective_end_date < v_ppm.end_date
7946 and not exists
7947 (select null
7948 from pay_org_pay_method_usages_f opmu2,
7949 pay_payrolls_f p2
7950 where opmu2.effective_start_date <=
7951 opmu.effective_end_date + 1
7952 and opmu2.effective_end_date >
7953 opmu.effective_end_date
7954 and opmu2.org_payment_method_id =
7955 v_ppm.org_payment_method_id
7956 and opmu2.payroll_id = p2.payroll_id
7957 and p2.payroll_id = p_payroll_id
7958 and opmu2.effective_start_date between
7959 p2.effective_start_date and p2.effective_end_date));
7960 exception
7961 when no_data_found then null;
7962 end;
7963 --
7964 if no_opmu = 'Y' then
7965 if g_debug then
7966 hr_utility.trace('No opmu from second check.');
7967 end if;
7968 exit;
7969 end if;
7970 --
7971 end loop;
7972 --
7973 end if;
7974 --
7975 if no_opmu = 'Y' then
7976 hr_utility.set_message(801,'HR_6844_ASS_PPM_INVALID');
7977 hr_utility.raise_error;
7978 end if;
7979 --
7980 if g_debug then
7981 hr_utility.trace ('Out hrentmnt.check_opmu');
7982 end if;
7983 --
7984 end check_opmu;
7985 --
7986
7987 ------------------------------------------------------------------------------
7988 -- NAME --
7989 -- hr_entry_api.move_fpd_entries --
7990 -- --
7991 -- DESCRIPTION --
7992 -- This procedure should be called from HR code to carry out entry changes --
7993 -- when final process date is changed. --
7994 ------------------------------------------------------------------------------
7995
7996 procedure move_fpd_entries
7997 (
7998 p_assignment_id in number
7999 ,p_period_of_service_id in number
8000 ,p_new_final_process_date in date
8001 ,p_old_final_process_date in date
8002 )
8003 is
8004 l_session_date date;
8005 l_new_esd date;
8006 l_new_eed date;
8007 l_object_version_number number;
8008 l_warnings_exist boolean;
8009 l_new_final_process_date date;
8010 l_proc varchar2(80):= 'hrentmnt.move_fpd_entries';
8011 --
8012 cursor process_entries(c_old_final_process_date date, c_assignment_id number) is
8013 select asg.assignment_id,
8014 ee.element_entry_id,
8015 ee.element_link_id,
8016 ee.original_entry_id,
8017 ee.effective_start_date,
8018 ee.effective_end_date,
8019 ee.target_entry_id,
8020 ee.entry_type,
8021 ee.creator_type,
8022 et.processing_type,
8023 ee.updating_action_id,
8024 ee.updating_action_type,
8025 ee.object_version_number
8026 from per_all_assignments_f asg
8027 , pay_element_entries_f ee
8028 , pay_element_types_f et
8029 where asg.assignment_id = c_assignment_id
8030 and asg.assignment_id = ee.assignment_id
8031 and ee.element_type_id = et.element_type_id
8032 and et.post_termination_rule = 'F'
8033 and c_old_final_process_date between ee.effective_start_date and ee.effective_end_date
8034 and c_old_final_process_date between et.effective_start_date and et.effective_end_date;
8035
8036 BEGIN
8037 hr_utility.set_location(l_proc, 10);
8038
8039 SAVEPOINT move_fpd_entries;
8040
8041 l_new_final_process_date := p_new_final_process_date;
8042
8043 if l_new_final_process_date is null then
8044 l_new_final_process_date := hr_general.end_of_time;
8045 end if;
8046
8047
8048 -- Get all the entries of termination rule type F which could be affected by change in fpd.
8049 for r_entry in process_entries(p_old_final_process_date,p_assignment_id)
8050 loop
8051 --
8052 hr_utility.set_location(l_proc,20);
8053 hr_utility.trace('EE processing type: '||r_entry.processing_type);
8054 hr_utility.trace('Old EE effective end date: '||to_char(r_entry.effective_end_date,'DD-MON-YYYY'));
8055
8056 l_object_version_number := r_entry.object_version_number;
8057 l_new_esd := r_entry.effective_start_date;
8058 l_new_eed := r_entry.effective_end_date;
8059 l_session_date := least(r_entry.effective_end_date, l_new_final_process_date);
8060
8061 if l_new_final_process_date < r_entry.effective_start_date then
8062
8063 /* Code to ZAP the element entry*/
8064 hr_utility.set_location(l_proc,30);
8065
8066 pay_element_entry_api.delete_element_entry
8067 (p_validate => false
8068 ,p_datetrack_delete_mode => 'ZAP'
8069 ,p_effective_date => l_session_date
8070 ,p_element_entry_id => r_entry.element_entry_id
8071 ,p_object_version_number => r_entry.object_version_number
8072 ,p_effective_start_date => l_new_esd
8073 ,p_effective_end_date => l_new_eed
8074 ,p_delete_warning => l_warnings_exist
8075 );
8076
8077 else
8078 if r_entry.processing_type = 'N' then
8079 hr_utility.set_location(l_proc,40);
8080 -- Non-recurring entry
8081 -- Derive new effective end date using chk_element_entry_main
8082 -- This will ensure the payroll period is considered
8083 hr_entry.chk_element_entry_main
8084 (
8085 p_element_entry_id => r_entry.element_entry_id,
8086 p_original_entry_id => r_entry.original_entry_id,
8087 p_session_date => l_session_date,
8088 p_element_link_id => r_entry.element_link_id,
8089 p_assignment_id => r_entry.assignment_id,
8090 p_entry_type => r_entry.entry_type,
8091 p_effective_start_date => l_new_esd,
8092 p_effective_end_date => l_new_eed,
8093 p_validation_start_date => r_entry.effective_start_date,
8094 p_validation_end_date => hr_general.end_of_time,
8095 p_dt_update_mode => 'CORRECTION',
8096 p_dt_delete_mode => null,
8097 p_usage => 'UPDATE',
8098 p_target_entry_id => r_entry.target_entry_id,
8099 p_creator_type => r_entry.creator_type
8100 );
8101 else
8102 hr_utility.set_location(l_proc,50);
8103 -- Recurring entry
8104 -- Derive new effective end date using get_eligibility_period
8105 -- This will ensure entry is not extended beyond lifetime of link
8106 hr_entry.get_eligibility_period
8107 (
8108 p_assignment_id => r_entry.assignment_id,
8109 p_element_link_id => r_entry.element_link_id,
8110 p_session_date => l_session_date,
8111 p_min_eligibility_date => l_new_esd,
8112 p_max_eligibility_date => l_new_eed
8113 );
8114 end if;
8115 --
8116 hr_utility.trace('New EE effective end date: '||to_char(l_new_eed,'DD-MON-YYYY'));
8117 --
8118 -- Now we have the new effective end date
8119 -- Perform checks to make sure we don't move the EED unnecessarily
8120
8121 if l_new_final_process_date > p_old_final_process_date then
8122 -- Moving FPD forwards
8123 -- Only change effective end date of entry if it wasn't earlier than the old FPD
8124 -- i.e. the entry may have been stopped by something other than the termination
8125 -- Added a condition to check that the entries do not have the updating_action_id - which
8126 -- means that the entry was updated by UPDATE_RECURRING or STOP_RECURRING formula result rules.
8127
8128 if r_entry.effective_end_date >= p_old_final_process_date
8129 AND (r_entry.updating_action_id IS NULL -- bug 7315564
8130 OR r_entry.updating_action_type = 'U') THEN -- bug 9069114
8131 --Bug Fix 9069114, Modified condition to check element entries
8132 -- NOT end dated by STOP_RECURRING formula result rules
8133
8134 hr_utility.set_location(l_proc,60);
8135
8136 update pay_element_entry_values_f
8137 set effective_end_date = l_new_eed
8138 where element_entry_id = r_entry.element_entry_id
8139 and p_old_final_process_date between effective_start_date and effective_end_date;
8140
8141 update pay_element_entries_f
8142 set effective_end_date = l_new_eed
8143 where element_entry_id = r_entry.element_entry_id
8144 and p_old_final_process_date between effective_start_date and effective_end_date;
8145
8146 end if;
8147
8148 else
8149 -- Moving FPD backwards
8150 -- Only change effective end date of entry if it is greater than the new FPD
8151 if r_entry.effective_end_date > l_new_final_process_date then
8152
8153 hr_utility.set_location(l_proc,70);
8154
8155 update pay_element_entry_values_f
8156 set effective_end_date = l_new_eed
8157 where element_entry_id = r_entry.element_entry_id
8158 and p_old_final_process_date between effective_start_date and effective_end_date
8159 and l_new_eed >= effective_start_date;
8160
8161 update pay_element_entries_f
8162 set effective_end_date = l_new_eed
8163 where element_entry_id = r_entry.element_entry_id
8164 and p_old_final_process_date between effective_start_date and effective_end_date
8165 and l_new_eed >= effective_start_date;
8166
8167 end if;
8168 end if;
8169 end if;
8170 end loop;
8171
8172 EXCEPTION
8173 --
8174 WHEN OTHERS THEN
8175
8176 ROLLBACK TO move_fpd_entries;
8177 RAISE;
8178
8179 END move_fpd_entries;
8180 --
8181
8182 end hrentmnt;