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