4 -- ----------------------------------------------------------------------------
1 Package Body pay_evc_ins as
2 /* $Header: pyevcrhi.pkb 115.6 2003/05/27 17:21:31 jford noship $ */
3 --
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pay_evc_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_event_value_change_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_event_value_change_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_evc_ins.g_event_value_change_id_i := p_event_value_change_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_evc_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_event_value_changes_f t
92 where t.event_value_change_id = p_rec.event_value_change_id
93 and t.effective_start_date =
94 pay_evc_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_event_value_changes_f.created_by%TYPE;
99 l_creation_date pay_event_value_changes_f.creation_date%TYPE;
100 l_last_update_date pay_event_value_changes_f.last_update_date%TYPE;
101 l_last_updated_by pay_event_value_changes_f.last_updated_by%TYPE;
102 l_last_update_login pay_event_value_changes_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_event_value_changes_f'
112 ,p_base_key_column => 'event_value_change_id'
113 ,p_base_key_value => p_rec.event_value_change_id
114 );
115 --
116 -- Set the effective start and end dates to the corresponding
117 -- validation start and end dates
118 --
119 p_rec.effective_start_date := p_validation_start_date;
120 p_rec.effective_end_date := p_validation_end_date;
121 --
122 -- If the datetrack_mode is not INSERT then we must populate the WHO
123 -- columns with the 'old' creation values and 'new' updated values.
124 --
125 If (p_datetrack_mode <> hr_api.g_insert) then
126 hr_utility.set_location(l_proc, 10);
127 --
128 -- Select the 'old' created values
129 --
133 --
130 Open C_Sel1;
131 Fetch C_Sel1 Into l_created_by, l_creation_date;
132 If C_Sel1%notfound Then
134 -- The previous 'old' created row has not been found. We need
135 -- to error as an internal datetrack problem exists.
136 --
137 Close C_Sel1;
138 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
139 fnd_message.set_token('PROCEDURE', l_proc);
140 fnd_message.set_token('STEP','10');
141 fnd_message.raise_error;
142 End If;
143 Close C_Sel1;
144 --
145 -- Set the AOL updated WHO values
146 --
147 l_last_update_date := sysdate;
148 l_last_updated_by := fnd_global.user_id;
149 l_last_update_login := fnd_global.login_id;
150 End If;
151 --
152 --
153 --
154 -- Insert the row into: pay_event_value_changes_f
155 --
156 insert into pay_event_value_changes_f
157 (event_value_change_id
158 ,effective_start_date
159 ,effective_end_date
160 ,event_qualifier_id
161 ,datetracked_event_id
162 ,default_event
163 ,valid_event
164 ,business_group_id
165 ,legislation_code
166 ,from_value
167 ,to_value
168 ,proration_style
169 ,qualifier_value
170 ,object_version_number
171 ,created_by
172 ,creation_date
173 ,last_update_date
174 ,last_updated_by
175 ,last_update_login
176 )
177 Values
178 (p_rec.event_value_change_id
179 ,p_rec.effective_start_date
180 ,p_rec.effective_end_date
181 ,p_rec.event_qualifier_id
182 ,p_rec.datetracked_event_id
183 ,p_rec.default_event
184 ,p_rec.valid_event
185 ,p_rec.business_group_id
186 ,p_rec.legislation_code
187 ,p_rec.from_value
188 ,p_rec.to_value
189 ,p_rec.proration_style
190 ,p_rec.qualifier_value
191 ,p_rec.object_version_number
192 ,l_created_by
193 ,l_creation_date
194 ,l_last_update_date
195 ,l_last_updated_by
196 ,l_last_update_login
197 );
198 --
199 --
200 hr_utility.set_location(' Leaving:'||l_proc, 15);
201 --
202 Exception
203 When hr_api.check_integrity_violated Then
204 -- A check constraint has been violated
205 --
206 pay_evc_shd.constraint_error
207 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
208 When hr_api.unique_integrity_violated Then
209 -- Unique integrity has been violated
210 --
211 pay_evc_shd.constraint_error
212 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
213 When Others Then
214 --
215 Raise;
216 End dt_insert_dml;
217 --
218 -- ----------------------------------------------------------------------------
219 -- |-----------------------< create_app_ownerships >--------------------------|
220 -- ----------------------------------------------------------------------------
221 --
222 -- Description:
223 -- This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
224 -- when the row handler is called in the appropriate mode.
225 --
226 -- ----------------------------------------------------------------------------
227 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
228 ,p_pk_value IN varchar2) IS
229 --
230 CURSOR csr_definition IS
231 SELECT product_short_name
232 FROM hr_owner_definitions
233 WHERE session_id = hr_startup_data_api_support.g_session_id;
234 --
235 BEGIN
236 --
237 IF (hr_startup_data_api_support.return_startup_mode IN
238 ('STARTUP','GENERIC')) THEN
239 --
240 FOR c1 IN csr_definition LOOP
241 --
242 INSERT INTO hr_application_ownerships
243 (key_name
244 ,key_value
245 ,product_name
246 )
247 VALUES
248 (p_pk_column
249 ,fnd_number.number_to_canonical(p_pk_value)
250 ,c1.product_short_name
251 );
252 END LOOP;
253 END IF;
254 END create_app_ownerships;
255 --
256 -- ----------------------------------------------------------------------------
257 -- |-----------------------< create_app_ownerships >--------------------------|
258 -- ----------------------------------------------------------------------------
259 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
260 ,p_pk_value IN number) IS
261 --
262 BEGIN
263 create_app_ownerships(p_pk_column, to_char(p_pk_value));
264 END create_app_ownerships;
265 --
266 -- ----------------------------------------------------------------------------
267 -- |------------------------------< insert_dml >------------------------------|
268 -- ----------------------------------------------------------------------------
269 Procedure insert_dml
270 (p_rec in out nocopy pay_evc_shd.g_rec_type
271 ,p_effective_date in date
272 ,p_datetrack_mode in varchar2
273 ,p_validation_start_date in date
274 ,p_validation_end_date in date
275 ) is
276 --
277 l_proc varchar2(72) := g_package||'insert_dml';
278 --
279 Begin
280 hr_utility.set_location('Entering:'||l_proc, 5);
281 --
282 pay_evc_ins.dt_insert_dml
283 (p_rec => p_rec
284 ,p_effective_date => p_effective_date
285 ,p_datetrack_mode => p_datetrack_mode
289 --
286 ,p_validation_start_date => p_validation_start_date
287 ,p_validation_end_date => p_validation_end_date
288 );
290 hr_utility.set_location(' Leaving:'||l_proc, 10);
291 End insert_dml;
292 --
293 -- ----------------------------------------------------------------------------
294 -- |------------------------------< pre_insert >------------------------------|
295 -- ----------------------------------------------------------------------------
296 -- {Start Of Comments}
297 --
298 -- Description:
299 -- This private procedure contains any processing which is required before
300 -- the insert dml. Presently, if the entity has a corresponding primary
301 -- key which is maintained by an associating sequence, the primary key for
302 -- the entity will be populated with the next sequence value in
303 -- preparation for the insert dml.
304 -- Also, if comments are defined for this entity, the comments insert
305 -- logic will also be called, generating a comment_id if required.
306 --
307 -- Prerequisites:
308 -- This is an internal procedure which is called from the ins procedure.
309 --
310 -- In Parameters:
311 -- A Pl/Sql record structure.
312 --
313 -- Post Success:
314 -- Processing continues.
315 --
316 -- Post Failure:
317 -- If an error has occurred, an error message and exception will be raised
318 -- but not handled.
319 --
320 -- Developer Implementation Notes:
321 -- Any pre-processing required before the insert dml is issued should be
322 -- coded within this procedure. As stated above, a good example is the
323 -- generation of a primary key number via a corresponding sequence.
324 -- It is important to note that any 3rd party maintenance should be reviewed
325 -- before placing in this procedure.
326 --
327 -- Access Status:
328 -- Internal Row Handler Use Only.
329 --
330 -- {End Of Comments}
331 -- ----------------------------------------------------------------------------
332 Procedure pre_insert
333 (p_rec in out nocopy pay_evc_shd.g_rec_type
334 ,p_effective_date in date
335 ,p_datetrack_mode in varchar2
336 ,p_validation_start_date in date
337 ,p_validation_end_date in date
338 ) is
339 --
340 Cursor C_Sel1 is select pay_event_value_changes_s.nextval from sys.dual;
341 --
342 Cursor C_Sel2 is
343 Select null
344 from pay_event_value_changes_f
345 where event_value_change_id =
346 pay_evc_ins.g_event_value_change_id_i;
347 --
348 l_proc varchar2(72) := g_package||'pre_insert';
349 l_exists varchar2(1);
350 --
351 Begin
352 hr_utility.set_location('Entering:'||l_proc, 5);
353 --
354 If (pay_evc_ins.g_event_value_change_id_i is not null) Then
355 --
356 -- Verify registered primary key values not already in use
357 --
358 Open C_Sel2;
359 Fetch C_Sel2 into l_exists;
360 If C_Sel2%found Then
361 Close C_Sel2;
362 --
363 -- The primary key values are already in use.
364 --
365 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
366 fnd_message.set_token('TABLE_NAME','pay_event_value_changes_f');
367 fnd_message.raise_error;
368 End If;
369 Close C_Sel2;
370 --
371 -- Use registered key values and clear globals
372 --
373 p_rec.event_value_change_id :=
374 pay_evc_ins.g_event_value_change_id_i;
375 pay_evc_ins.g_event_value_change_id_i := null;
376 Else
377 --
378 -- No registerd key values, so select the next sequence number
379 --
380 --
381 -- Select the next sequence number
382 --
383 Open C_Sel1;
384 Fetch C_Sel1 Into p_rec.event_value_change_id;
385 Close C_Sel1;
386 End If;
387 --
388 --
389 hr_utility.set_location(' Leaving:'||l_proc, 10);
390 End pre_insert;
391 --
392 -- ----------------------------------------------------------------------------
393 -- |----------------------------< post_insert >-------------------------------|
394 -- ----------------------------------------------------------------------------
395 -- {Start Of Comments}
396 --
397 -- Description:
398 -- This private procedure contains any processing which is required after
399 -- the insert dml.
400 --
401 -- Prerequisites:
402 -- This is an internal procedure which is called from the ins procedure.
403 --
404 -- In Parameters:
405 -- A Pl/Sql record structure.
406 --
407 -- Post Success:
408 -- Processing continues.
409 --
410 -- Post Failure:
411 -- If an error has occurred, an error message and exception will be raised
412 -- but not handled.
413 --
414 -- Developer Implementation Notes:
415 -- Any post-processing required after the insert dml is issued should be
416 -- coded within this procedure. It is important to note that any 3rd party
417 -- maintenance should be reviewed before placing in this procedure.
418 --
419 -- Access Status:
420 -- Internal Row Handler Use Only.
421 --
422 -- {End Of Comments}
423 -- ----------------------------------------------------------------------------
424 Procedure post_insert
425 (p_rec in pay_evc_shd.g_rec_type
426 ,p_effective_date in date
427 ,p_datetrack_mode in varchar2
428 ,p_validation_start_date in date
429 ,p_validation_end_date in date
430 ) is
431 --
432 l_proc varchar2(72) := g_package||'post_insert';
436 begin
433 --
434 Begin
435 hr_utility.set_location('Entering:'||l_proc, 5);
437 --
438 -- insert ownerships if applicable
439 create_app_ownerships
440 ('EVENT_VALUE_CHANGE_ID', p_rec.event_value_change_id
441 );
442 --
443 --
444 pay_evc_rki.after_insert
445 (p_effective_date
446 => p_effective_date
447 ,p_validation_start_date
448 => p_validation_start_date
449 ,p_validation_end_date
450 => p_validation_end_date
451 ,p_event_value_change_id
452 => p_rec.event_value_change_id
453 ,p_effective_start_date
454 => p_rec.effective_start_date
455 ,p_effective_end_date
456 => p_rec.effective_end_date
457 ,p_event_qualifier_id
458 => p_rec.event_qualifier_id
459 ,p_datetracked_event_id
460 => p_rec.datetracked_event_id
461 ,p_default_event
462 => p_rec.default_event
463 ,p_valid_event
464 => p_rec.valid_event
465 ,p_business_group_id
466 => p_rec.business_group_id
467 ,p_legislation_code
468 => p_rec.legislation_code
469 ,p_from_value
470 => p_rec.from_value
471 ,p_to_value
472 => p_rec.to_value
473 ,p_proration_style
474 => p_rec.proration_style
475 ,p_qualifier_value
476 => p_rec.qualifier_value
477 ,p_object_version_number
478 => p_rec.object_version_number
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_EVENT_VALUE_CHANGES_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_evc_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_event_value_changes_f'
552 ,p_base_key_column => 'event_value_change_id'
553 ,p_base_key_value => p_rec.event_value_change_id
554 ,p_parent_table_name1 => 'pay_event_qualifiers_f'
555 ,p_parent_key_column1 => 'event_qualifier_id'
556 ,p_parent_key_value1 => p_rec.event_qualifier_id
557 ,p_enforce_foreign_locking => true
558 ,p_validation_start_date => l_validation_start_date
559 ,p_validation_end_date => l_validation_end_date
560 );
561 --
562 -- Set the validation start and end date OUT arguments
563 --
564 p_validation_start_date := l_validation_start_date;
565 p_validation_end_date := l_validation_end_date;
566 --
567 hr_utility.set_location(' Leaving:'||l_proc, 10);
568 --
569 End ins_lck;
570 --
571 -- ----------------------------------------------------------------------------
572 -- |---------------------------------< ins >----------------------------------|
573 -- ----------------------------------------------------------------------------
574 Procedure ins
575 (p_effective_date in date
576 ,p_rec in out nocopy pay_evc_shd.g_rec_type
577 ) is
578 --
579 l_proc varchar2(72) := g_package||'ins';
580 l_datetrack_mode varchar2(30) := hr_api.g_insert;
581 l_validation_start_date date;
582 l_validation_end_date date;
583 --
584 Begin
585 hr_utility.set_location('Entering:'||l_proc, 5);
586 --
587 -- Call the lock operation
588 --
589 pay_evc_ins.ins_lck
590 (p_effective_date => p_effective_date
591 ,p_datetrack_mode => l_datetrack_mode
592 ,p_rec => p_rec
593 ,p_validation_start_date => l_validation_start_date
594 ,p_validation_end_date => l_validation_end_date
595 );
596 --
597 -- Call the supporting insert validate operations
598 --
599 pay_evc_bus.insert_validate
600 (p_rec => p_rec
601 ,p_effective_date => p_effective_date
602 ,p_datetrack_mode => l_datetrack_mode
603 ,p_validation_start_date => l_validation_start_date
604 ,p_validation_end_date => l_validation_end_date
605 );
606 --
607 -- Call to raise any errors on multi-message list
608 hr_multi_message.end_validation_set;
609 --
610 -- Call the supporting pre-insert operation
611 --
612 pay_evc_ins.pre_insert
613 (p_rec => p_rec
614 ,p_effective_date => p_effective_date
615 ,p_datetrack_mode => l_datetrack_mode
616 ,p_validation_start_date => l_validation_start_date
617 ,p_validation_end_date => l_validation_end_date
618 );
619 --
620 -- Insert the row
621 --
622 pay_evc_ins.insert_dml
623 (p_rec => p_rec
624 ,p_effective_date => p_effective_date
625 ,p_datetrack_mode => l_datetrack_mode
626 ,p_validation_start_date => l_validation_start_date
627 ,p_validation_end_date => l_validation_end_date
628 );
629 --
630 -- Call the supporting post-insert operation
631 --
632 pay_evc_ins.post_insert
633 (p_rec => p_rec
634 ,p_effective_date => p_effective_date
635 ,p_datetrack_mode => l_datetrack_mode
636 ,p_validation_start_date => l_validation_start_date
637 ,p_validation_end_date => l_validation_end_date
638 );
639 --
640 -- Call to raise any errors on multi-message list
641 hr_multi_message.end_validation_set;
642 --
643 hr_utility.set_location('Leaving:'||l_proc,10);
644 end ins;
645 --
646 -- ----------------------------------------------------------------------------
647 -- |---------------------------------< ins >----------------------------------|
648 -- ----------------------------------------------------------------------------
649 Procedure ins
650 (p_effective_date in date
651 ,p_event_qualifier_id in number
652 ,p_default_event in varchar2
653 ,p_valid_event in varchar2
654 ,p_datetracked_event_id in number default null
655 ,p_business_group_id in number default null
656 ,p_legislation_code in varchar2 default null
657 ,p_from_value in varchar2 default null
658 ,p_to_value in varchar2 default null
659 ,p_proration_style in varchar2 default null
660 ,p_qualifier_value in varchar2 default null
661 ,p_event_value_change_id out nocopy number
662 ,p_object_version_number out nocopy number
663 ,p_effective_start_date out nocopy date
664 ,p_effective_end_date out nocopy date
665 ) is
666 --
667 l_rec pay_evc_shd.g_rec_type;
668 l_proc varchar2(72) := g_package||'ins';
669 --
670 Begin
671 hr_utility.set_location('Entering:'||l_proc, 5);
672 --
673 -- Call conversion function to turn arguments into the
674 -- p_rec structure.
675 --
676 l_rec :=
677 pay_evc_shd.convert_args
678 (null
679 ,null
680 ,null
681 ,p_event_qualifier_id
682 ,p_datetracked_event_id
683 ,p_default_event
684 ,p_valid_event
685 ,p_business_group_id
686 ,p_legislation_code
687 ,p_from_value
688 ,p_to_value
689 ,p_proration_style
690 ,p_qualifier_value
691 ,null
692 );
693 --
694 -- Having converted the arguments into the pay_evc_rec
695 -- plsql record structure we call the corresponding record
696 -- business process.
697 --
698 pay_evc_ins.ins
699 (p_effective_date
700 ,l_rec
701 );
702 --
703 -- Set the OUT arguments.
704 --
705 p_event_value_change_id := l_rec.event_value_change_id;
706 p_effective_start_date := l_rec.effective_start_date;
707 p_effective_end_date := l_rec.effective_end_date;
708 p_object_version_number := l_rec.object_version_number;
709 --
710 --
711 hr_utility.set_location(' Leaving:'||l_proc, 10);
712 End ins;
713 --
714 end pay_evc_ins;