1 Package Body pay_pur_ins as
2 /* $Header: pypurrhi.pkb 120.1.12010000.2 2009/12/23 09:46:10 asnell ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pay_pur_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_user_row_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_user_row_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_pur_ins.g_user_row_id_i := p_user_row_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_pur_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_user_rows_f t
92 where t.user_row_id = p_rec.user_row_id
93 and t.effective_start_date =
94 pay_pur_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_user_rows_f.created_by%TYPE;
99 l_creation_date pay_user_rows_f.creation_date%TYPE;
100 l_last_update_date pay_user_rows_f.last_update_date%TYPE;
101 l_last_updated_by pay_user_rows_f.last_updated_by%TYPE;
102 l_last_update_login pay_user_rows_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_user_rows_f'
112 ,p_base_key_column => 'user_row_id'
113 ,p_base_key_value => p_rec.user_row_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 --
130 Open C_Sel1;
131 Fetch C_Sel1 Into l_created_by, l_creation_date;
132 If C_Sel1%notfound Then
133 --
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 pay_pur_shd.g_api_dml := true; -- Set the api dml status
153 --
154 -- Insert the row into: pay_user_rows_f
155 --
156 insert into pay_user_rows_f
157 (user_row_id
158 ,effective_start_date
159 ,effective_end_date
160 ,business_group_id
161 ,legislation_code
162 ,user_table_id
163 ,row_low_range_or_name
164 ,display_sequence
165 ,row_high_range
166 ,object_version_number
167 ,created_by
168 ,creation_date
169 ,last_update_date
170 ,last_updated_by
171 ,last_update_login
172 )
173 Values
174 (p_rec.user_row_id
175 ,p_rec.effective_start_date
176 ,p_rec.effective_end_date
177 ,p_rec.business_group_id
178 ,p_rec.legislation_code
179 ,p_rec.user_table_id
180 ,p_rec.row_low_range_or_name
181 ,p_rec.display_sequence
182 ,p_rec.row_high_range
183 ,p_rec.object_version_number
184 ,l_created_by
185 ,l_creation_date
186 ,l_last_update_date
187 ,l_last_updated_by
188 ,l_last_update_login
189 );
190 --
191 pay_pur_shd.g_api_dml := false; -- Unset the api dml status
192 hr_utility.set_location(' Leaving:'||l_proc, 15);
193 --
194 Exception
195 When hr_api.check_integrity_violated Then
196 -- A check constraint has been violated
197 pay_pur_shd.g_api_dml := false; -- Unset the api dml status
198 pay_pur_shd.constraint_error
199 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
200 When hr_api.unique_integrity_violated Then
201 -- Unique integrity has been violated
202 pay_pur_shd.g_api_dml := false; -- Unset the api dml status
203 pay_pur_shd.constraint_error
204 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
205 When Others Then
206 pay_pur_shd.g_api_dml := false; -- Unset the api dml status
207 Raise;
208 End dt_insert_dml;
209 --
210 -- ----------------------------------------------------------------------------
211 -- |-----------------------< create_app_ownerships >--------------------------|
212 -- ----------------------------------------------------------------------------
213 --
214 -- Description:
215 -- This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
216 -- when the row handler is called in the appropriate mode.
217 --
218 -- ----------------------------------------------------------------------------
219 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
220 ,p_pk_value IN varchar2) IS
221 --
222 CURSOR csr_definition IS
223 SELECT product_short_name
224 FROM hr_owner_definitions
225 WHERE session_id = hr_startup_data_api_support.g_session_id;
226 --
227 BEGIN
228 --
229 IF (hr_startup_data_api_support.return_startup_mode IN
230 ('STARTUP','GENERIC')) THEN
231 --
232 FOR c1 IN csr_definition LOOP
233 --
234 INSERT INTO hr_application_ownerships
235 (key_name
236 ,key_value
237 ,product_name
238 )
239 VALUES
240 (p_pk_column
241 ,fnd_number.number_to_canonical(p_pk_value)
242 ,c1.product_short_name
243 );
244 END LOOP;
245 END IF;
246 END create_app_ownerships;
247 --
248 -- ----------------------------------------------------------------------------
249 -- |-----------------------< create_app_ownerships >--------------------------|
250 -- ----------------------------------------------------------------------------
251 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
252 ,p_pk_value IN number) IS
253 --
254 BEGIN
255 create_app_ownerships(p_pk_column, to_char(p_pk_value));
256 END create_app_ownerships;
257 --
258 -- ----------------------------------------------------------------------------
259 -- |------------------------------< insert_dml >------------------------------|
260 -- ----------------------------------------------------------------------------
261 Procedure insert_dml
262 (p_rec in out nocopy pay_pur_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 pay_pur_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 pay_pur_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 pay_user_rows_s.nextval from sys.dual;
333 --
334 Cursor C_Sel2 is
335 Select null
336 from pay_user_rows_f
337 where user_row_id =
338 pay_pur_ins.g_user_row_id_i;
339 --
340 l_proc varchar2(72) := g_package||'pre_insert';
341 l_exists varchar2(1);
342 --
343 Begin
344 hr_utility.set_location('Entering:'||l_proc, 5);
345 --
346 If (pay_pur_ins.g_user_row_id_i is not null) Then
347 --
348 -- Verify registered primary key values not already in use
349 --
350 Open C_Sel2;
351 Fetch C_Sel2 into l_exists;
352 If C_Sel2%found Then
353 Close C_Sel2;
354 --
355 -- The primary key values are already in use.
356 --
357 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
358 fnd_message.set_token('TABLE_NAME','pay_user_rows_f');
359 fnd_message.raise_error;
360 End If;
361 Close C_Sel2;
362 --
363 -- Use registered key values and clear globals
364 --
365 p_rec.user_row_id :=
366 pay_pur_ins.g_user_row_id_i;
367 pay_pur_ins.g_user_row_id_i := null;
368 Else
369 --
370 -- No registerd key values, so select the next sequence number
371 --
372 --
373 -- Select the next sequence number
374 --
375 Open C_Sel1;
376 Fetch C_Sel1 Into p_rec.user_row_id;
377 Close C_Sel1;
378 End If;
379 --
380 --
381 hr_utility.set_location(' Leaving:'||l_proc, 10);
382 End pre_insert;
383 --
384 -- ----------------------------------------------------------------------------
385 -- |----------------------------< post_insert >-------------------------------|
386 -- ----------------------------------------------------------------------------
387 -- {Start Of Comments}
388 --
389 -- Description:
390 -- This private procedure contains any processing which is required after
391 -- the insert dml.
392 --
393 -- Prerequisites:
394 -- This is an internal procedure which is called from the ins procedure.
395 --
396 -- In Parameters:
397 -- A Pl/Sql record structure.
398 --
399 -- Post Success:
400 -- Processing continues.
401 --
402 -- Post Failure:
403 -- If an error has occurred, an error message and exception will be raised
404 -- but not handled.
405 --
406 -- Developer Implementation Notes:
407 -- Any post-processing required after the insert dml is issued should be
408 -- coded within this procedure. It is important to note that any 3rd party
409 -- maintenance should be reviewed before placing in this procedure.
410 --
411 -- Access Status:
412 -- Internal Row Handler Use Only.
413 --
414 -- {End Of Comments}
415 -- ----------------------------------------------------------------------------
416 Procedure post_insert
417 (p_rec in pay_pur_shd.g_rec_type
418 ,p_effective_date in date
419 ,p_datetrack_mode in varchar2
420 ,p_disable_units_check in boolean
421 ,p_disable_range_overlap_check in boolean
422 ,p_validation_start_date in date
423 ,p_validation_end_date in date
424 ) is
425 --
426 l_proc varchar2(72) := g_package||'post_insert';
427 --
428 Begin
429 hr_utility.set_location('Entering:'||l_proc, 5);
430 begin
431 --
432 -- insert ownerships if applicable
433 create_app_ownerships
434 ('USER_ROW_ID', p_rec.user_row_id
435 );
436 --
437 --
438 pay_pur_rki.after_insert
439 (p_effective_date
440 => p_effective_date
441 ,p_validation_start_date
442 => p_validation_start_date
443 ,p_validation_end_date
444 => p_validation_end_date
445 ,p_user_row_id
446 => p_rec.user_row_id
447 ,p_effective_start_date
448 => p_rec.effective_start_date
449 ,p_effective_end_date
450 => p_rec.effective_end_date
451 ,p_business_group_id
452 => p_rec.business_group_id
453 ,p_legislation_code
454 => p_rec.legislation_code
455 ,p_user_table_id
456 => p_rec.user_table_id
457 ,p_row_low_range_or_name
458 => p_rec.row_low_range_or_name
459 ,p_display_sequence
460 => p_rec.display_sequence
461 ,p_row_high_range
462 => p_rec.row_high_range
463 ,p_object_version_number
464 => p_rec.object_version_number
465 ,p_disable_units_check
466 => p_disable_units_check
467 ,p_disable_range_overlap_check
468 => p_disable_range_overlap_check
469 );
470 --
471 exception
472 --
473 when hr_api.cannot_find_prog_unit then
474 --
475 hr_api.cannot_find_prog_unit_error
476 (p_module_name => 'PAY_USER_ROWS_F'
477 ,p_hook_type => 'AI');
478 --
479 end;
480 --
481 hr_utility.set_location(' Leaving:'||l_proc, 10);
482 End post_insert;
483 --
484 -- ----------------------------------------------------------------------------
485 -- |-------------------------------< ins_lck >--------------------------------|
486 -- ----------------------------------------------------------------------------
487 -- {Start Of Comments}
488 --
489 -- Description:
490 -- The ins_lck process has one main function to perform. When inserting
491 -- a datetracked row, we must validate the DT mode.
492 --
493 -- Prerequisites:
494 -- This procedure can only be called for the datetrack mode of INSERT.
495 --
496 -- In Parameters:
497 --
498 -- Post Success:
499 -- On successful completion of the ins_lck process the parental
500 -- datetracked rows will be locked providing the p_enforce_foreign_locking
501 -- argument value is TRUE.
502 -- If the p_enforce_foreign_locking argument value is FALSE then the
503 -- parential rows are not locked.
504 --
505 -- Post Failure:
506 -- The Lck process can fail for:
507 -- 1) When attempting to lock the row the row could already be locked by
508 -- another user. This will raise the HR_Api.Object_Locked exception.
509 -- 2) When attempting to the lock the parent which doesn't exist.
510 -- For the entity to be locked the parent must exist!
511 --
512 -- Developer Implementation Notes:
513 -- None.
514 --
515 -- Access Status:
516 -- Internal Row Handler Use Only.
517 --
518 -- {End Of Comments}
519 -- ----------------------------------------------------------------------------
520 Procedure ins_lck
521 (p_effective_date in date
522 ,p_datetrack_mode in varchar2
523 ,p_rec in pay_pur_shd.g_rec_type
524 ,p_validation_start_date out nocopy date
525 ,p_validation_end_date out nocopy date
526 ) is
527 --
528 l_proc varchar2(72) := g_package||'ins_lck';
529 l_validation_start_date date;
530 l_validation_end_date date;
531 --
532 Begin
533 hr_utility.set_location('Entering:'||l_proc, 5);
534 --
535 -- Validate the datetrack mode mode getting the validation start
536 -- and end dates for the specified datetrack operation.
537 --
538 dt_api.validate_dt_mode
539 (p_effective_date => p_effective_date
540 ,p_datetrack_mode => p_datetrack_mode
541 ,p_base_table_name => 'pay_user_rows_f'
542 ,p_base_key_column => 'user_row_id'
543 ,p_base_key_value => p_rec.user_row_id
544 ,p_enforce_foreign_locking => true
545 ,p_validation_start_date => l_validation_start_date
546 ,p_validation_end_date => l_validation_end_date
547 );
548 --
549 -- Set the validation start and end date OUT arguments
550 --
551 p_validation_start_date := l_validation_start_date;
552 p_validation_end_date := l_validation_end_date;
553 --
554 hr_utility.set_location(' Leaving:'||l_proc, 10);
555 --
556 End ins_lck;
557 --
558 -- ----------------------------------------------------------------------------
559 -- |---------------------------------< ins >----------------------------------|
560 -- ----------------------------------------------------------------------------
561 Procedure ins
562 (p_effective_date in date
563 ,p_rec in out nocopy pay_pur_shd.g_rec_type
564 ,p_disable_units_check in boolean default false
565 ,p_disable_range_overlap_check in boolean default false
566 ) is
567 --
568 l_proc varchar2(72) := g_package||'ins';
569 l_datetrack_mode varchar2(30) := hr_api.g_insert;
570 l_validation_start_date date;
571 l_validation_end_date date;
572 --
573 Begin
574 hr_utility.set_location('Entering:'||l_proc, 5);
575 --
576 -- Call the lock operation
577 --
578 pay_pur_ins.ins_lck
579 (p_effective_date => p_effective_date
580 ,p_datetrack_mode => l_datetrack_mode
581 ,p_rec => p_rec
582 ,p_validation_start_date => l_validation_start_date
583 ,p_validation_end_date => l_validation_end_date
584 );
585 --
586 -- Call the supporting insert validate operations
587 --
588 pay_pur_bus.insert_validate
589 (p_rec => p_rec
590 ,p_effective_date => p_effective_date
591 ,p_datetrack_mode => l_datetrack_mode
592 ,p_validation_start_date => l_validation_start_date
593 ,p_validation_end_date => l_validation_end_date
594 ,p_disable_units_check => p_disable_units_check
595 ,p_disable_range_overlap_check => p_disable_range_overlap_check
596 );
597 --
598 -- Call to raise any errors on multi-message list
599 hr_multi_message.end_validation_set;
600 --
601 -- Call the supporting pre-insert operation
602 --
603 pay_pur_ins.pre_insert
604 (p_rec => p_rec
605 ,p_effective_date => p_effective_date
606 ,p_datetrack_mode => l_datetrack_mode
607 ,p_validation_start_date => l_validation_start_date
608 ,p_validation_end_date => l_validation_end_date
609 );
610 --
611 -- Insert the row
612 --
613 pay_pur_ins.insert_dml
614 (p_rec => p_rec
615 ,p_effective_date => p_effective_date
616 ,p_datetrack_mode => l_datetrack_mode
617 ,p_validation_start_date => l_validation_start_date
618 ,p_validation_end_date => l_validation_end_date
619 );
620 --
621 -- Call the supporting post-insert operation
622 --
623 pay_pur_ins.post_insert
624 (p_rec => p_rec
625 ,p_effective_date => p_effective_date
626 ,p_datetrack_mode => l_datetrack_mode
627 ,p_disable_units_check => p_disable_units_check
628 ,p_disable_range_overlap_check => p_disable_range_overlap_check
629 ,p_validation_start_date => l_validation_start_date
630 ,p_validation_end_date => l_validation_end_date
631 );
632 --
633 -- Call to raise any errors on multi-message list
634 hr_multi_message.end_validation_set;
635 --
636 hr_utility.set_location('Leaving:'||l_proc,10);
637 end ins;
638 --
639 -- ----------------------------------------------------------------------------
640 -- |---------------------------------< ins >----------------------------------|
641 -- ----------------------------------------------------------------------------
642 Procedure ins
643 (p_effective_date in date
644 ,p_user_table_id in number
645 ,p_row_low_range_or_name in varchar2
646 ,p_business_group_id in number default null
647 ,p_legislation_code in varchar2 default null
648 ,p_display_sequence in number default null
649 ,p_row_high_range in varchar2 default null
650 ,p_disable_units_check in boolean default false
651 ,p_disable_range_overlap_check in boolean default false
652 ,p_user_row_id out nocopy number
653 ,p_object_version_number out nocopy number
654 ,p_effective_start_date out nocopy date
655 ,p_effective_end_date out nocopy date
656 ) is
657 --
658 l_rec pay_pur_shd.g_rec_type;
659 l_proc varchar2(72) := g_package||'ins';
660 --
661 Begin
662 hr_utility.set_location('Entering:'||l_proc, 5);
663 --
664 -- Call conversion function to turn arguments into the
665 -- p_rec structure.
666 --
667 l_rec :=
668 pay_pur_shd.convert_args
669 (null
670 ,null
671 ,null
672 ,p_business_group_id
673 ,p_legislation_code
674 ,p_user_table_id
675 ,p_row_low_range_or_name
676 ,p_display_sequence
677 ,p_row_high_range
678 ,null
679 );
680 --
681 -- Having converted the arguments into the pay_pur_rec
682 -- plsql record structure we call the corresponding record
683 -- business process.
684 --
685 pay_pur_ins.ins
686 (p_effective_date
687 ,l_rec
688 ,p_disable_units_check
689 ,p_disable_range_overlap_check
690 );
691 --
692 -- Set the OUT arguments.
693 --
694 p_user_row_id := l_rec.user_row_id;
695 p_effective_start_date := l_rec.effective_start_date;
696 p_effective_end_date := l_rec.effective_end_date;
697 p_object_version_number := l_rec.object_version_number;
698 --
699 --
700 hr_utility.set_location(' Leaving:'||l_proc, 10);
701 End ins;
702 --
703 end pay_pur_ins;