1 Package Body pay_pgr_ins as
2 /* $Header: pypgrrhi.pkb 120.6.12020000.2 2013/01/17 09:39:34 sclakkar ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pay_pgr_ins.'; -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_grade_rule_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_grade_rule_id in number) is
20 --
21 l_proc varchar2(72) := g_package||'set_base_key_value';
22 --
23 Begin
24 hr_utility.set_location('Entering:'||l_proc, 10);
25 --
26 pay_pgr_ins.g_grade_rule_id_i := p_grade_rule_id;
27 --
28 hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 --
32 -- ----------------------------------------------------------------------------
33 -- |----------------------------< dt_insert_dml >-----------------------------|
34 -- ----------------------------------------------------------------------------
35 -- {Start Of Comments}
36 --
37 -- Description:
38 -- This procedure controls the actual dml insert logic for datetrack. The
39 -- functions of this procedure are as follows:
40 -- 1) Get the object_version_number.
41 -- 2) To set the effective start and end dates to the corresponding
42 -- validation start and end dates. Also, the object version number
43 -- record attribute is set.
44 -- 3) To set and unset the g_api_dml status as required (as we are about to
45 -- perform dml).
46 -- 4) To insert the row into the schema with the derived effective start
47 -- and end dates and the object version number.
48 -- 5) To trap any constraint violations that may have occurred.
49 -- 6) To raise any other errors.
50 --
51 -- Prerequisites:
52 -- This is an internal private procedure which must be called from the
53 -- insert_dml and pre_update (logic permitting) procedure and must have
54 -- all mandatory arguments set.
55 --
56 -- In Parameters:
57 -- A Pl/Sql record structure.
58 --
59 -- Post Success:
60 -- The specified row will be inserted into the schema.
61 --
62 -- Post Failure:
63 -- On the insert dml failure it is important to note that we always reset the
64 -- g_api_dml status to false.
65 -- If a check or unique integrity constraint violation is raised the
66 -- constraint_error procedure will be called.
67 -- If any other error is reported, the error will be raised after the
68 -- g_api_dml status is reset.
69 --
70 -- Developer Implementation Notes:
71 -- This is an internal datetrack maintenance procedure which should
72 -- not be modified in anyway.
73 --
74 -- Access Status:
75 -- Internal Row Handler Use Only.
76 --
77 -- {End Of Comments}
78 -- ----------------------------------------------------------------------------
79 Procedure dt_insert_dml
80 (p_rec in out nocopy pay_pgr_shd.g_rec_type
81 ,p_effective_date in date
82 ,p_datetrack_mode in varchar2
83 ,p_validation_start_date in date
84 ,p_validation_end_date in date
85 ) is
86 -- Cursor to select 'old' created AOL who column values
87 --
88 Cursor C_Sel1 Is
89 select t.created_by,
90 t.creation_date
91 from pay_grade_rules_f t
92 where t.grade_rule_id = p_rec.grade_rule_id
93 and t.effective_start_date =
94 pay_pgr_shd.g_old_rec.effective_start_date
95 and t.effective_end_date = (p_validation_start_date - 1);
96 --
97 l_proc varchar2(72) := g_package||'dt_insert_dml';
98 l_created_by pay_grade_rules_f.created_by%TYPE;
99 l_creation_date pay_grade_rules_f.creation_date%TYPE;
100 l_last_update_date pay_grade_rules_f.last_update_date%TYPE;
101 l_last_updated_by pay_grade_rules_f.last_updated_by%TYPE;
102 l_last_update_login pay_grade_rules_f.last_update_login%TYPE;
103 --
104 Begin
105 hr_utility.set_location('Entering:'||l_proc, 5);
106 --
107 -- Get the object version number for the insert
108 --
109 p_rec.object_version_number :=
110 dt_api.get_object_version_number
111 (p_base_table_name => 'pay_grade_rules_f'
112 ,p_base_key_column => 'grade_rule_id'
113 ,p_base_key_value => p_rec.grade_rule_id
114 );
115 --
116 hr_utility.set_location(l_proc, 10);
117 --
118 -- Set the effective start and end dates to the corresponding
119 -- validation start and end dates
120 --
121 p_rec.effective_start_date := p_validation_start_date;
122 p_rec.effective_end_date := p_validation_end_date;
123 --
124 -- If the datetrack_mode is not INSERT then we must populate the WHO
125 -- columns with the 'old' creation values and 'new' updated values.
126 --
127 If (p_datetrack_mode <> hr_api.g_insert) then
128 --
129 hr_utility.set_location(l_proc, 30);
130 --
131 -- Select the 'old' created values
132 --
133 Open C_Sel1;
134 Fetch C_Sel1 Into l_created_by, l_creation_date;
135 If C_Sel1%notfound Then
136 --
137 -- The previous 'old' created row has not been found. We need
138 -- to error as an internal datetrack problem exists.
139 --
140 Close C_Sel1;
141 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
142 fnd_message.set_token('PROCEDURE', l_proc);
143 fnd_message.set_token('STEP','10');
144 fnd_message.raise_error;
145 End If;
146 Close C_Sel1;
147 --
148 -- Set the AOL updated WHO values
149 --
150 l_last_update_date := sysdate;
151 l_last_updated_by := fnd_global.user_id;
152 l_last_update_login := fnd_global.login_id;
153 End If;
154 --
155 pay_pgr_shd.g_api_dml := true; -- Set the api dml status
156 --
157 -- Insert the row into: pay_grade_rules_f
158 --
159 hr_utility.set_location(l_proc, 30);
160 --
161 insert into pay_grade_rules_f
162 (grade_rule_id
163 ,effective_start_date
164 ,effective_end_date
165 ,business_group_id
166 ,rate_id
167 ,grade_or_spinal_point_id
168 ,rate_type
169 ,maximum
170 ,mid_value
171 ,minimum
172 ,sequence
173 ,value
174 ,request_id
175 ,program_application_id
176 ,program_id
177 ,program_update_date
178 ,object_version_number
179 ,currency_code
180 ,created_by
181 ,creation_date
182 ,last_update_date
183 ,last_updated_by
184 ,last_update_login
185 )
186 Values
187 (p_rec.grade_rule_id
188 ,p_rec.effective_start_date
189 ,p_rec.effective_end_date
190 ,p_rec.business_group_id
191 ,p_rec.rate_id
192 ,p_rec.grade_or_spinal_point_id
193 ,p_rec.rate_type
194 ,p_rec.maximum
195 ,p_rec.mid_value
196 ,p_rec.minimum
197 ,p_rec.sequence
198 ,p_rec.value
199 ,p_rec.request_id
200 ,p_rec.program_application_id
201 ,p_rec.program_id
202 ,p_rec.program_update_date
203 ,p_rec.object_version_number
204 ,p_rec.currency_code
205 ,l_created_by
206 ,l_creation_date
207 ,l_last_update_date
208 ,l_last_updated_by
209 ,l_last_update_login
210 );
211 --
212 pay_pgr_shd.g_api_dml := false; -- Unset the api dml status
213 hr_utility.set_location(' Leaving:'||l_proc, 15);
214 --
215 Exception
216 When hr_api.check_integrity_violated Then
217 -- A check constraint has been violated
218 pay_pgr_shd.g_api_dml := false; -- Unset the api dml status
219 pay_pgr_shd.constraint_error
220 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
221 When hr_api.unique_integrity_violated Then
222 -- Unique integrity has been violated
223 pay_pgr_shd.g_api_dml := false; -- Unset the api dml status
224 pay_pgr_shd.constraint_error
225 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
226 When Others Then
227 pay_pgr_shd.g_api_dml := false; -- Unset the api dml status
228 Raise;
229 End dt_insert_dml;
230 --
231 -- ----------------------------------------------------------------------------
232 -- |------------------------------< insert_dml >------------------------------|
233 -- ----------------------------------------------------------------------------
234 Procedure insert_dml
235 (p_rec in out nocopy pay_pgr_shd.g_rec_type
236 ,p_effective_date in date
237 ,p_datetrack_mode in varchar2
238 ,p_validation_start_date in date
239 ,p_validation_end_date in date
240 ) is
241 --
242 l_proc varchar2(72) := g_package||'insert_dml';
243 --
244 Begin
245 hr_utility.set_location('Entering:'||l_proc, 5);
246 --
247 pay_pgr_ins.dt_insert_dml
248 (p_rec => p_rec
249 ,p_effective_date => p_effective_date
250 ,p_datetrack_mode => p_datetrack_mode
251 ,p_validation_start_date => p_validation_start_date
252 ,p_validation_end_date => p_validation_end_date
253 );
254 --
255 hr_utility.set_location(' Leaving:'||l_proc, 10);
256 End insert_dml;
257 --
258 -- ----------------------------------------------------------------------------
259 -- |------------------------------< pre_insert >------------------------------|
260 -- ----------------------------------------------------------------------------
261 -- {Start Of Comments}
262 --
263 -- Description:
264 -- This private procedure contains any processing which is required before
265 -- the insert dml. Presently, if the entity has a corresponding primary
266 -- key which is maintained by an associating sequence, the primary key for
267 -- the entity will be populated with the next sequence value in
268 -- preparation for the insert dml.
269 -- Also, if comments are defined for this entity, the comments insert
270 -- logic will also be called, generating a comment_id if required.
271 --
272 -- Prerequisites:
273 -- This is an internal procedure which is called from the ins procedure.
274 --
275 -- In Parameters:
276 -- A Pl/Sql record structure.
277 --
278 -- Post Success:
279 -- Processing continues.
280 --
281 -- Post Failure:
282 -- If an error has occurred, an error message and exception will be raised
283 -- but not handled.
284 --
285 -- Developer Implementation Notes:
286 -- Any pre-processing required before the insert dml is issued should be
287 -- coded within this procedure. As stated above, a good example is the
288 -- generation of a primary key number via a corresponding sequence.
289 -- It is important to note that any 3rd party maintenance should be reviewed
290 -- before placing in this procedure.
291 --
292 -- Access Status:
293 -- Internal Row Handler Use Only.
294 --
295 -- {End Of Comments}
296 -- ----------------------------------------------------------------------------
297 Procedure pre_insert
298 (p_rec in out nocopy pay_pgr_shd.g_rec_type
299 ,p_effective_date in date
300 ,p_datetrack_mode in varchar2
301 ,p_validation_start_date in date
302 ,p_validation_end_date in date
303 ) is
304 --
305 Cursor C_Sel1 is select pay_grade_rules_s.nextval from sys.dual;
306 --
307 Cursor C_Sel2 is
308 Select null
309 from pay_grade_rules_f
310 where grade_rule_id =
311 pay_pgr_ins.g_grade_rule_id_i;
312 --
313 Cursor C_Grade_Sequence IS
314 Select Sequence
315 From per_grades
316 Where grade_id = p_rec.grade_or_spinal_point_id;
317 --
318 Cursor C_Spinal_Point_Sequence IS
319 Select Sequence
320 From per_spinal_points
321 Where spinal_point_id = p_rec.grade_or_spinal_point_id;
322 --
323 l_proc varchar2(72) := g_package||'pre_insert';
324 l_exists varchar2(1);
325 --
326 Begin
327 hr_utility.set_location('Entering:'||l_proc, 5);
328 --
329 If (pay_pgr_ins.g_grade_rule_id_i is not null) Then
330 --
331 -- Verify registered primary key values not already in use
332 --
333 Open C_Sel2;
334 Fetch C_Sel2 into l_exists;
335 If C_Sel2%found Then
336 Close C_Sel2;
337 --
338 -- The primary key values are already in use.
339 --
340 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
341 fnd_message.set_token('TABLE_NAME','pay_grade_rules_f');
342 fnd_message.raise_error;
343 End If;
344 Close C_Sel2;
345 --
346 -- Use registered key values and clear globals
347 --
348 p_rec.grade_rule_id := pay_pgr_ins.g_grade_rule_id_i;
349 pay_pgr_ins.g_grade_rule_id_i := null;
350 Else
351 --
352 -- No registerd key values, so select the next sequence number
353 --
354 --
355 -- Select the next sequence number
356 --
357 Open C_Sel1;
358 Fetch C_Sel1 Into p_rec.grade_rule_id;
359 Close C_Sel1;
360 End If;
361 --
362 -- Reverting change that allows user to pass their own sequence when creating grade rates.
363 -- This gives rise to bugs similar to 5019308.
364 -- If (p_rec.sequence is NULL) Then
365 --Checking if the user has entered value for the sequence field.
366 If p_rec.rate_type = 'G' Then
367 --
368 hr_utility.set_location(l_proc,20);
369 --
370 open C_Grade_Sequence;
371 Fetch C_Grade_Sequence Into p_rec.sequence;
372 Close C_Grade_Sequence;
373 --
374 Elsif p_rec.rate_type = 'SP' Then
375 --
376 hr_utility.set_location(l_proc,30);
377 --
378 Open C_Spinal_Point_Sequence;
379 Fetch C_Spinal_Point_Sequence Into p_rec.sequence;
380 Close C_Spinal_Point_Sequence;
381 --
382 End if;
383 --
384 -- End If;
385 --
386 hr_utility.set_location(' Leaving:'||l_proc, 999);
387 --
388 End pre_insert;
389 --
390 -- ----------------------------------------------------------------------------
391 -- |----------------------------< post_insert >-------------------------------|
392 -- ----------------------------------------------------------------------------
393 -- {Start Of Comments}
394 --
395 -- Description:
396 -- This private procedure contains any processing which is required after
397 -- the insert dml.
398 --
399 -- Prerequisites:
400 -- This is an internal procedure which is called from the ins procedure.
401 --
402 -- In Parameters:
403 -- A Pl/Sql record structure.
404 --
405 -- Post Success:
406 -- Processing continues.
407 --
408 -- Post Failure:
409 -- If an error has occurred, an error message and exception will be raised
410 -- but not handled.
411 --
412 -- Developer Implementation Notes:
413 -- Any post-processing required after the insert dml is issued should be
414 -- coded within this procedure. It is important to note that any 3rd party
415 -- maintenance should be reviewed before placing in this procedure.
416 --
417 -- Access Status:
418 -- Internal Row Handler Use Only.
419 --
420 -- {End Of Comments}
421 -- ----------------------------------------------------------------------------
422 Procedure post_insert
423 (p_rec in pay_pgr_shd.g_rec_type
424 ,p_effective_date in date
425 ,p_datetrack_mode in varchar2
426 ,p_validation_start_date in date
427 ,p_validation_end_date in date
428 ) is
429 --
430 l_proc varchar2(72) := g_package||'post_insert';
431 --
432 Begin
433 hr_utility.set_location('Entering:'||l_proc, 5);
434 begin
435 --
436 pay_pgr_rki.after_insert
437 (p_effective_date
438 => p_effective_date
439 ,p_validation_start_date
440 => p_validation_start_date
441 ,p_validation_end_date
442 => p_validation_end_date
443 ,p_grade_rule_id
444 => p_rec.grade_rule_id
445 ,p_effective_start_date
446 => p_rec.effective_start_date
447 ,p_effective_end_date
448 => p_rec.effective_end_date
449 ,p_business_group_id
450 => p_rec.business_group_id
451 ,p_rate_id
452 => p_rec.rate_id
453 ,p_grade_or_spinal_point_id
454 => p_rec.grade_or_spinal_point_id
455 ,p_rate_type
456 => p_rec.rate_type
457 ,p_maximum
458 => p_rec.maximum
459 ,p_mid_value
460 => p_rec.mid_value
461 ,p_minimum
462 => p_rec.minimum
463 ,p_sequence
464 => p_rec.sequence
465 ,p_value
466 => p_rec.value
467 ,p_request_id
468 => p_rec.request_id
469 ,p_program_application_id
470 => p_rec.program_application_id
471 ,p_program_id
472 => p_rec.program_id
473 ,p_program_update_date
474 => p_rec.program_update_date
475 ,p_object_version_number
476 => p_rec.object_version_number
477 ,p_currency_code
478 => p_rec.currency_code
479 );
480 --
481 exception
482 --
483 when hr_api.cannot_find_prog_unit then
484 --
485 hr_api.cannot_find_prog_unit_error
486 (p_module_name => 'PAY_GRADE_RULES_F'
487 ,p_hook_type => 'AI');
488 --
489 end;
490 --
491 hr_utility.set_location(' Leaving:'||l_proc, 10);
492 End post_insert;
493 --
494 -- ----------------------------------------------------------------------------
495 -- |-------------------------------< ins_lck >--------------------------------|
496 -- ----------------------------------------------------------------------------
497 -- {Start Of Comments}
498 --
499 -- Description:
500 -- The ins_lck process has one main function to perform. When inserting
501 -- a datetracked row, we must validate the DT mode.
502 --
503 -- Prerequisites:
504 -- This procedure can only be called for the datetrack mode of INSERT.
505 --
506 -- In Parameters:
507 --
508 -- Post Success:
509 -- On successful completion of the ins_lck process the parental
510 -- datetracked rows will be locked providing the p_enforce_foreign_locking
511 -- argument value is TRUE.
512 -- If the p_enforce_foreign_locking argument value is FALSE then the
513 -- parential rows are not locked.
514 --
515 -- Post Failure:
516 -- The Lck process can fail for:
517 -- 1) When attempting to lock the row the row could already be locked by
518 -- another user. This will raise the HR_Api.Object_Locked exception.
519 -- 2) When attempting to the lock the parent which doesn't exist.
520 -- For the entity to be locked the parent must exist!
521 --
522 -- Developer Implementation Notes:
523 -- None.
524 --
525 -- Access Status:
526 -- Internal Row Handler Use Only.
527 --
528 -- {End Of Comments}
529 -- ----------------------------------------------------------------------------
530 Procedure ins_lck
531 (p_effective_date in date
532 ,p_datetrack_mode in varchar2
533 ,p_rec in pay_pgr_shd.g_rec_type
534 ,p_validation_start_date out nocopy date
535 ,p_validation_end_date out nocopy date
536 ) is
537 --
538 l_proc varchar2(72) := g_package||'ins_lck';
539 l_validation_start_date date;
540 l_validation_end_date date;
541 --
542 Begin
543 hr_utility.set_location('Entering:'||l_proc, 5);
544 --
545 -- Validate the datetrack mode mode getting the validation start
546 -- and end dates for the specified datetrack operation.
547 --
548 dt_api.validate_dt_mode
549 (p_effective_date => p_effective_date
550 ,p_datetrack_mode => p_datetrack_mode
551 ,p_base_table_name => 'pay_grade_rules_f'
552 ,p_base_key_column => 'grade_rule_id'
553 ,p_base_key_value => p_rec.grade_rule_id
554 ,p_enforce_foreign_locking => true
555 ,p_validation_start_date => l_validation_start_date
556 ,p_validation_end_date => l_validation_end_date
557 );
558 --
559 -- Set the validation start and end date OUT arguments
560 --
561 p_validation_start_date := l_validation_start_date;
562 p_validation_end_date := l_validation_end_date;
563 --
564 hr_utility.set_location(' Leaving:'||l_proc, 10);
565 --
566 End ins_lck;
567 --
568 -- ----------------------------------------------------------------------------
569 -- |---------------------------------< ins >----------------------------------|
570 -- ----------------------------------------------------------------------------
571 Procedure ins
572 (p_effective_date in date
573 ,p_rec in out nocopy pay_pgr_shd.g_rec_type
574 ) is
575 --
576 l_proc varchar2(72) := g_package||'ins';
577 l_datetrack_mode varchar2(30) := hr_api.g_insert;
578 l_validation_start_date date;
579 l_validation_end_date date;
580 --
581 Begin
582 hr_utility.set_location('Entering:'||l_proc, 5);
583 --
584 -- Call the lock operation
585 --
586 pay_pgr_ins.ins_lck
587 (p_effective_date => p_effective_date
588 ,p_datetrack_mode => l_datetrack_mode
589 ,p_rec => p_rec
590 ,p_validation_start_date => l_validation_start_date
591 ,p_validation_end_date => l_validation_end_date
592 );
593 --
594 -- Call the supporting insert validate operations
595 --
596 pay_pgr_bus.insert_validate
597 (p_rec => p_rec
598 ,p_effective_date => p_effective_date
599 ,p_datetrack_mode => l_datetrack_mode
600 ,p_validation_start_date => l_validation_start_date
601 ,p_validation_end_date => l_validation_end_date
602 );
603 --
604 -- Call to raise any errors on multi-message list
605 hr_multi_message.end_validation_set;
606 --
607 -- Call the supporting pre-insert operation
608 --
609 pay_pgr_ins.pre_insert
610 (p_rec => p_rec
611 ,p_effective_date => p_effective_date
612 ,p_datetrack_mode => l_datetrack_mode
613 ,p_validation_start_date => l_validation_start_date
614 ,p_validation_end_date => l_validation_end_date
615 );
616 --
617 -- Insert the row
618 --
619 pay_pgr_ins.insert_dml
620 (p_rec => p_rec
621 ,p_effective_date => p_effective_date
622 ,p_datetrack_mode => l_datetrack_mode
623 ,p_validation_start_date => l_validation_start_date
624 ,p_validation_end_date => l_validation_end_date
625 );
626 --
627 -- Call the supporting post-insert operation
628 --
629 pay_pgr_ins.post_insert
630 (p_rec => p_rec
631 ,p_effective_date => p_effective_date
632 ,p_datetrack_mode => l_datetrack_mode
633 ,p_validation_start_date => l_validation_start_date
634 ,p_validation_end_date => l_validation_end_date
635 );
636 --
637 -- Call to raise any errors on multi-message list
638 hr_multi_message.end_validation_set;
639 --
640 hr_utility.set_location('Leaving:'||l_proc,10);
641 end ins;
642 --
643 -- ----------------------------------------------------------------------------
644 -- |---------------------------------< ins >----------------------------------|
645 -- ----------------------------------------------------------------------------
646 Procedure ins
647 (p_effective_date in date
648 ,p_business_group_id in number
649 ,p_rate_id in number
650 ,p_grade_or_spinal_point_id in number
651 ,p_rate_type in varchar2
652 ,p_maximum in varchar2 default null
653 ,p_mid_value in varchar2 default null
654 ,p_minimum in varchar2 default null
655 ,p_sequence in number default null
656 ,p_value in varchar2 default null
657 ,p_currency_code in varchar2 default null
658 ,p_grade_rule_id out nocopy number
659 ,p_object_version_number out nocopy number
660 ,p_effective_start_date out nocopy date
661 ,p_effective_end_date out nocopy date
662 ) is
663 --
664 l_rec pay_pgr_shd.g_rec_type;
665 l_proc varchar2(72) := g_package||'ins';
666 --
667 Begin
668 hr_utility.set_location('Entering:'||l_proc, 5);
669 --
670 -- Call conversion function to turn arguments into the
671 -- p_rec structure.
672 --
673 l_rec :=
674 pay_pgr_shd.convert_args
675 (null
676 ,null
677 ,null
678 ,p_business_group_id
679 ,p_rate_id
680 ,p_grade_or_spinal_point_id
681 ,p_rate_type
682 ,p_maximum
683 ,p_mid_value
684 ,p_minimum
685 ,p_sequence
686 ,p_value
687 ,NULL --p_request_id
688 ,NULL --p_program_application_id
689 ,NULL --p_program_id
690 ,NULL --p_program_update_date
691 ,null
692 ,p_currency_code
693 );
694 --
695 -- Having converted the arguments into the pay_pgr_rec
696 -- plsql record structure we call the corresponding record
697 -- business process.
698 --
699 pay_pgr_ins.ins
700 (p_effective_date
701 ,l_rec
702 );
703 --
704 -- Set the OUT arguments.
705 --
706 p_grade_rule_id := l_rec.grade_rule_id;
707 p_effective_start_date := l_rec.effective_start_date;
708 p_effective_end_date := l_rec.effective_end_date;
709 p_object_version_number := l_rec.object_version_number;
710 --
711 --
712 hr_utility.set_location(' Leaving:'||l_proc, 10);
713 End ins;
714 --
715 end pay_pgr_ins;