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