DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_CAL_INS

Source


1 Package Body pay_cal_ins as
2 /* $Header: pycalrhi.pkb 120.1.12020000.2 2012/07/04 21:43:33 amnaraya ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_cal_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_cost_allocation_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_cost_allocation_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_cal_ins.g_cost_allocation_id_i := p_cost_allocation_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_cal_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_cost_allocations_f t
92     where  t.cost_allocation_id       = p_rec.cost_allocation_id
93     and    t.effective_start_date =
94              pay_cal_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_cost_allocations_f.created_by%TYPE;
99   l_creation_date       pay_cost_allocations_f.creation_date%TYPE;
100   l_last_update_date    pay_cost_allocations_f.last_update_date%TYPE;
101   l_last_updated_by     pay_cost_allocations_f.last_updated_by%TYPE;
102   l_last_update_login   pay_cost_allocations_f.last_update_login%TYPE;
103 --
104 Begin
105    hr_utility.set_location('Entering:'||l_proc, 5);
106   --
107   -- Set the effective start and end dates to the corresponding
108   -- validation start and end dates
109   --
110   p_rec.effective_start_date := p_validation_start_date;
111   p_rec.effective_end_date   := p_validation_end_date;
112   --
113   -- If the datetrack_mode is not INSERT then we must populate the WHO
114   -- columns with the 'old' creation values and 'new' updated values.
115   --
116   If (p_datetrack_mode <> hr_api.g_insert) then
117     hr_utility.set_location(l_proc, 10);
118     --
119       -- Get the object version number for the insert
120   --
121   p_rec.object_version_number :=
122     dt_api.get_object_version_number
123       (p_base_table_name => 'pay_cost_allocations_f'
124       ,p_base_key_column => 'cost_allocation_id'
125       ,p_base_key_value  => p_rec.cost_allocation_id
126       );
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   Else
151     p_rec.object_version_number := 1;  -- Initialise the object version
152   End If;
153   --
154   pay_cal_shd.g_api_dml := true;  -- Set the api dml status
155   --
156   -- Insert the row into: pay_cost_allocations_f
157   --
158   insert into pay_cost_allocations_f
159       (cost_allocation_id
160       ,effective_start_date
161       ,effective_end_date
162       ,business_group_id
163       ,cost_allocation_keyflex_id
164       ,assignment_id
165       ,proportion
166       ,request_id
167       ,program_application_id
168       ,program_id
169       ,program_update_date
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.cost_allocation_id
179     ,p_rec.effective_start_date
180     ,p_rec.effective_end_date
181     ,p_rec.business_group_id
182     ,p_rec.cost_allocation_keyflex_id
183     ,p_rec.assignment_id
184     ,p_rec.proportion
185     ,p_rec.request_id
186     ,p_rec.program_application_id
187     ,p_rec.program_id
188     ,p_rec.program_update_date
189     ,p_rec.object_version_number
190     ,l_created_by
191     ,l_creation_date
192     ,l_last_update_date
193     ,l_last_updated_by
194     ,l_last_update_login
195     );
196   --
197   --
198   pay_cal_shd.g_api_dml := false;   -- Unset the api dml status
199   hr_utility.set_location(' Leaving:'||l_proc, 15);
200 --
201 Exception
202   When hr_api.check_integrity_violated Then
203     -- A check constraint has been violated
204     pay_cal_shd.g_api_dml := false;   -- Unset the api dml status
205     pay_cal_shd.constraint_error
206       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
207   When hr_api.unique_integrity_violated Then
208     -- Unique integrity has been violated
209     pay_cal_shd.g_api_dml := false;   -- Unset the api dml status
210     pay_cal_shd.constraint_error
211       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
212   When Others Then
213     pay_cal_shd.g_api_dml := false;   -- Unset the api dml status
214     Raise;
215 End dt_insert_dml;
216 --
217 -- ----------------------------------------------------------------------------
218 -- |------------------------------< insert_dml >------------------------------|
219 -- ----------------------------------------------------------------------------
220 Procedure insert_dml
221   (p_rec                   in out nocopy pay_cal_shd.g_rec_type
222   ,p_effective_date        in date
223   ,p_datetrack_mode        in varchar2
224   ,p_validation_start_date in date
225   ,p_validation_end_date   in date
226   ) is
227 --
228   l_proc        varchar2(72) := g_package||'insert_dml';
229 --
230 Begin
231   hr_utility.set_location('Entering:'||l_proc, 5);
232   --
233   pay_cal_ins.dt_insert_dml
234     (p_rec                   => p_rec
235     ,p_effective_date        => p_effective_date
236     ,p_datetrack_mode        => p_datetrack_mode
237     ,p_validation_start_date => p_validation_start_date
238     ,p_validation_end_date   => p_validation_end_date
239     );
240   --
241   hr_utility.set_location(' Leaving:'||l_proc, 10);
242 End insert_dml;
243 --
244 -- ----------------------------------------------------------------------------
245 -- |------------------------------< pre_insert >------------------------------|
246 -- ----------------------------------------------------------------------------
247 -- {Start Of Comments}
248 --
249 -- Description:
250 --   This private procedure contains any processing which is required before
251 --   the insert dml. Presently, if the entity has a corresponding primary
252 --   key which is maintained by an associating sequence, the primary key for
253 --   the entity will be populated with the next sequence value in
254 --   preparation for the insert dml.
255 --   Also, if comments are defined for this entity, the comments insert
256 --   logic will also be called, generating a comment_id if required.
257 --
258 -- Prerequisites:
259 --   This is an internal procedure which is called from the ins procedure.
260 --
261 -- In Parameters:
262 --   A Pl/Sql record structure.
263 --
264 -- Post Success:
265 --   Processing continues.
266 --
267 -- Post Failure:
268 --   If an error has occurred, an error message and exception will be raised
269 --   but not handled.
270 --
271 -- Developer Implementation Notes:
272 --   Any pre-processing required before the insert dml is issued should be
273 --   coded within this procedure. As stated above, a good example is the
274 --   generation of a primary key number via a corresponding sequence.
275 --   It is important to note that any 3rd party maintenance should be reviewed
276 --   before placing in this procedure.
277 --
278 -- Access Status:
279 --   Internal Row Handler Use Only.
280 --
281 -- {End Of Comments}
282 -- ----------------------------------------------------------------------------
283 Procedure pre_insert
284   (p_rec                   in out nocopy pay_cal_shd.g_rec_type
285   ,p_effective_date        in date
286   ,p_datetrack_mode        in varchar2
287   ,p_validation_start_date in date
288   ,p_validation_end_date   in date
289   ) is
290 --
291   Cursor C_Sel1 is select pay_cost_allocations_s.nextval from sys.dual;
292 --
293  Cursor C_Sel2 is
294     Select null
295       from pay_cost_allocations_f
296      where cost_allocation_id =
297              pay_cal_ins.g_cost_allocation_id_i;
298 --
299   l_proc        varchar2(72) := g_package||'pre_insert';
300   l_exists      varchar2(1);
301 --
302 Begin
303   hr_utility.set_location('Entering:'||l_proc, 5);
304   --
305     If (pay_cal_ins.g_cost_allocation_id_i is not null) Then
306     --
307     -- Verify registered primary key values not already in use
308     --
309     Open C_Sel2;
310     Fetch C_Sel2 into l_exists;
311     If C_Sel2%found Then
312        Close C_Sel2;
313        --
314        -- The primary key values are already in use.
315        --
316        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
317        fnd_message.set_token('TABLE_NAME','pay_cost_allocations_f');
318        fnd_message.raise_error;
319     End If;
320     Close C_Sel2;
321     --
322     -- Use registered key values and clear globals
323     --
324     p_rec.cost_allocation_id :=
325       pay_cal_ins.g_cost_allocation_id_i;
326     pay_cal_ins.g_cost_allocation_id_i := null;
327   Else
328     --
329     -- No registerd key values, so select the next sequence number
330     --
331     --
332     -- Select the next sequence number
333     --
334     Open C_Sel1;
335     Fetch C_Sel1 Into p_rec.cost_allocation_id;
336     Close C_Sel1;
337   End If;
338   --
339   --
340   hr_utility.set_location(' Leaving:'||l_proc, 10);
341 End pre_insert;
342 --
343 -- ----------------------------------------------------------------------------
344 -- |----------------------------< post_insert >-------------------------------|
345 -- ----------------------------------------------------------------------------
346 -- {Start Of Comments}
347 --
348 -- Description:
349 --   This private procedure contains any processing which is required after
350 --   the insert dml.
351 --
352 -- Prerequisites:
353 --   This is an internal procedure which is called from the ins procedure.
354 --
355 -- In Parameters:
356 --   A Pl/Sql record structure.
357 --
358 -- Post Success:
359 --   Processing continues.
360 --
361 -- Post Failure:
362 --   If an error has occurred, an error message and exception will be raised
363 --   but not handled.
364 --
365 -- Developer Implementation Notes:
366 --   Any post-processing required after the insert dml is issued should be
367 --   coded within this procedure. It is important to note that any 3rd party
368 --   maintenance should be reviewed before placing in this procedure.
369 --
370 -- Access Status:
371 --   Internal Row Handler Use Only.
372 --
373 -- {End Of Comments}
374 -- ----------------------------------------------------------------------------
375 -- ----------------------------------------------------------------------------
376 Procedure post_insert
377   (p_rec                   in pay_cal_shd.g_rec_type
378   ,p_effective_date        in date
379   ,p_datetrack_mode        in varchar2
380   ,p_validation_start_date in date
381   ,p_validation_end_date   in date
382   ) is
383 --
384   l_proc        varchar2(72) := g_package||'post_insert';
385 --
386 Begin
387   hr_utility.set_location('Entering:'||l_proc, 5);
388   begin
389     --
390     pay_cal_rki.after_insert
391       (p_effective_date
392       => p_effective_date
393       ,p_validation_start_date
394       => p_validation_start_date
395       ,p_validation_end_date
396       => p_validation_end_date
397       ,p_cost_allocation_id
398       => p_rec.cost_allocation_id
399       ,p_effective_start_date
400       => p_rec.effective_start_date
401       ,p_effective_end_date
402       => p_rec.effective_end_date
403       ,p_business_group_id
404       => p_rec.business_group_id
405       ,p_cost_allocation_keyflex_id
406       => p_rec.cost_allocation_keyflex_id
407       ,p_assignment_id
408       => p_rec.assignment_id
409       ,p_proportion
410       => p_rec.proportion
411       ,p_request_id
412       => p_rec.request_id
413       ,p_program_application_id
414       => p_rec.program_application_id
415       ,p_program_id
416       => p_rec.program_id
417       ,p_program_update_date
418       => p_rec.program_update_date
419       ,p_object_version_number
420       => p_rec.object_version_number
421       );
422     --
423   exception
424     --
425     when hr_api.cannot_find_prog_unit then
426       --
427       hr_api.cannot_find_prog_unit_error
428         (p_module_name => 'PAY_COST_ALLOCATIONS_F'
429         ,p_hook_type   => 'AI');
430       --
431   end;
432   --
433   hr_utility.set_location(' Leaving:'||l_proc, 10);
434 End post_insert;
435 --
436 -- ----------------------------------------------------------------------------
437 -- |-------------------------------< ins_lck >--------------------------------|
438 -- ----------------------------------------------------------------------------
439 -- {Start Of Comments}
440 --
441 -- Description:
442 --   The ins_lck process has one main function to perform. When inserting
443 --   a datetracked row, we must validate the DT mode.
444 --
445 -- Prerequisites:
446 --   This procedure can only be called for the datetrack mode of INSERT.
447 --
448 -- In Parameters:
449 --
450 -- Post Success:
451 --   On successful completion of the ins_lck process the parental
452 --   datetracked rows will be locked providing the p_enforce_foreign_locking
453 --   argument value is TRUE.
454 --   If the p_enforce_foreign_locking argument value is FALSE then the
455 --   parential rows are not locked.
456 --
457 -- Post Failure:
458 --   The Lck process can fail for:
459 --   1) When attempting to lock the row the row could already be locked by
460 --      another user. This will raise the HR_Api.Object_Locked exception.
461 --   2) When attempting to the lock the parent which doesn't exist.
462 --      For the entity to be locked the parent must exist!
463 --
464 -- Developer Implementation Notes:
465 --   None.
466 --
467 -- Access Status:
468 --   Internal Row Handler Use Only.
469 --
470 -- {End Of Comments}
471 -- ----------------------------------------------------------------------------
472 Procedure ins_lck
473   (p_effective_date        in date
474   ,p_datetrack_mode        in varchar2
475   ,p_rec                   in pay_cal_shd.g_rec_type
476   ,p_validation_start_date out nocopy date
477   ,p_validation_end_date   out nocopy date
478   ) is
479 --
480   l_proc                  varchar2(72) := g_package||'ins_lck';
481   l_validation_start_date date;
482   l_validation_end_date   date;
483 --
484 Begin
485   hr_utility.set_location('Entering:'||l_proc, 5);
486   --
487   -- Validate the datetrack mode mode getting the validation start
488   -- and end dates for the specified datetrack operation.
489   --
490   dt_api.validate_dt_mode
491     (p_effective_date          => p_effective_date
492     ,p_datetrack_mode          => p_datetrack_mode
493     ,p_base_table_name         => 'pay_cost_allocations_f'
494     ,p_base_key_column         => 'cost_allocation_id'
495     ,p_base_key_value          => p_rec.cost_allocation_id
496     ,p_enforce_foreign_locking => true
497     ,p_validation_start_date   => l_validation_start_date
498     ,p_validation_end_date     => l_validation_end_date
499     );
500   --
501   -- Set the validation start and end date OUT arguments
502   --
503   p_validation_start_date := l_validation_start_date;
504   p_validation_end_date   := l_validation_end_date;
505   --
506   hr_utility.set_location(' Leaving:'||l_proc, 10);
507   --
508 End ins_lck;
509 --
510 -- ----------------------------------------------------------------------------
511 -- |---------------------------------< ins >----------------------------------|
512 -- ----------------------------------------------------------------------------
513 Procedure ins
514   (p_effective_date in     date
515   ,p_rec            in out nocopy pay_cal_shd.g_rec_type
516   ) is
517 --
518   l_proc                        varchar2(72) := g_package||'ins';
519   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
520   l_validation_start_date       date;
521   l_validation_end_date         date;
522 --
523 Begin
524   hr_utility.set_location('Entering:'||l_proc, 5);
525   --
526   -- Call the lock operation
527   --
528   pay_cal_ins.ins_lck
529     (p_effective_date        => p_effective_date
530     ,p_datetrack_mode        => l_datetrack_mode
531     ,p_rec                   => p_rec
532     ,p_validation_start_date => l_validation_start_date
533     ,p_validation_end_date   => l_validation_end_date
534     );
535   --
536   -- Call the supporting insert validate operations
537   --
538   pay_cal_bus.insert_validate
539     (p_rec                   => p_rec
540     ,p_effective_date        => p_effective_date
541     ,p_datetrack_mode        => l_datetrack_mode
542     ,p_validation_start_date => l_validation_start_date
543     ,p_validation_end_date   => l_validation_end_date
544     );
545   --
546   -- Call to raise any errors on multi-message list
547   hr_multi_message.end_validation_set;
548   --
549   -- Call the supporting pre-insert operation
550   --
551   pay_cal_ins.pre_insert
552     (p_rec                   => p_rec
553     ,p_effective_date        => p_effective_date
554     ,p_datetrack_mode        => l_datetrack_mode
555     ,p_validation_start_date => l_validation_start_date
556     ,p_validation_end_date   => l_validation_end_date
557     );
558   --
559   -- Insert the row
560   --
561   pay_cal_ins.insert_dml
562     (p_rec                   => p_rec
563     ,p_effective_date        => p_effective_date
564     ,p_datetrack_mode        => l_datetrack_mode
565     ,p_validation_start_date => l_validation_start_date
566     ,p_validation_end_date   => l_validation_end_date
567     );
568   --
569   -- Call the supporting post-insert operation
570   --
571   pay_cal_ins.post_insert
572     (p_rec                   => p_rec
573     ,p_effective_date        => p_effective_date
574     ,p_datetrack_mode        => l_datetrack_mode
575     ,p_validation_start_date => l_validation_start_date
576     ,p_validation_end_date   => l_validation_end_date
577     );
578   --
579   -- Call to raise any errors on multi-message list
580   hr_multi_message.end_validation_set;
581   --
582   hr_utility.set_location('Leaving:'||l_proc,10);
583 end ins;
584 --
585 -- ----------------------------------------------------------------------------
586 -- |---------------------------------< ins >----------------------------------|
587 -- ----------------------------------------------------------------------------
588 Procedure ins
589   (p_effective_date                 in     date
590   ,p_business_group_id              in     number
591   ,p_cost_allocation_keyflex_id     in     number
592   ,p_assignment_id                  in     number
593   ,p_proportion                     in     number
594   ,p_request_id                     in     number   default null
595   ,p_program_application_id         in     number   default null
596   ,p_program_id                     in     number   default null
597   ,p_program_update_date            in     date     default null
598   ,p_cost_allocation_id                out nocopy number
599   ,p_object_version_number             out nocopy number
600   ,p_effective_start_date              out nocopy date
601   ,p_effective_end_date                out nocopy date
602   ) is
603 --
604   l_rec         pay_cal_shd.g_rec_type;
605   l_proc        varchar2(72) := g_package||'ins';
606 --
607 Begin
608   hr_utility.set_location('Entering:'||l_proc, 5);
609   --
610   -- Call conversion function to turn arguments into the
611   -- p_rec structure.
612   --
613   l_rec :=
614   pay_cal_shd.convert_args
615     (null
616     ,null
617     ,null
618     ,p_business_group_id
619     ,p_cost_allocation_keyflex_id
620     ,p_assignment_id
621     ,p_proportion
622     ,p_request_id
623     ,p_program_application_id
624     ,p_program_id
625     ,p_program_update_date
626     ,null
627     );
628   --
629   -- Having converted the arguments into the pay_cal_rec
630   -- plsql record structure we call the corresponding record
631   -- business process.
632   --
633   pay_cal_ins.ins
634     (p_effective_date
635     ,l_rec
636     );
637   --
638   -- Set the OUT arguments.
639   --
640   p_cost_allocation_id               := l_rec.cost_allocation_id;
641   p_effective_start_date             := l_rec.effective_start_date;
642   p_effective_end_date               := l_rec.effective_end_date;
643   p_object_version_number            := l_rec.object_version_number;
644   --
645   --
646   hr_utility.set_location(' Leaving:'||l_proc, 10);
647 End ins;
648 --
649 end pay_cal_ins;