DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_ROM_INS

Source


1 Package Body pay_rom_ins as
2 /* $Header: pyromrhi.pkb 115.3 2002/12/09 15:04:01 divicker noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  pay_rom_ins.';  -- Global package name
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_rom_shd.g_rec_type
59   ,p_effective_date          in date
63   ) is
60   ,p_datetrack_mode          in varchar2
61   ,p_validation_start_date   in date
62   ,p_validation_end_date     in date
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_run_type_org_methods_f t
70     where  t.run_type_org_method_id       = p_rec.run_type_org_method_id
71     and    t.effective_start_date =
72              pay_rom_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_run_type_org_methods_f.created_by%TYPE;
77   l_creation_date       pay_run_type_org_methods_f.creation_date%TYPE;
78   l_last_update_date   	pay_run_type_org_methods_f.last_update_date%TYPE;
79   l_last_updated_by     pay_run_type_org_methods_f.last_updated_by%TYPE;
80   l_last_update_login   pay_run_type_org_methods_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_run_type_org_methods_f'
90       ,p_base_key_column => 'run_type_org_method_id'
91       ,p_base_key_value  => p_rec.run_type_org_method_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_run_type_org_methods_f
133   --
134   insert into pay_run_type_org_methods_f
135       (run_type_id
136       ,org_payment_method_id
137       ,effective_start_date
138       ,effective_end_date
139       ,priority
140       ,percentage
141       ,amount
142       ,object_version_number
143       ,run_type_org_method_id
144       ,business_group_id
145       ,legislation_code
146       ,created_by
147       ,creation_date
148       ,last_update_date
149       ,last_updated_by
150       ,last_update_login
151       )
152   Values
153     (p_rec.run_type_id
154     ,p_rec.org_payment_method_id
155     ,p_rec.effective_start_date
156     ,p_rec.effective_end_date
157     ,p_rec.priority
158     ,p_rec.percentage
159     ,p_rec.amount
160     ,p_rec.object_version_number
161     ,p_rec.run_type_org_method_id
162     ,p_rec.business_group_id
163     ,p_rec.legislation_code
164     ,l_created_by
165     ,l_creation_date
166     ,l_last_update_date
167     ,l_last_updated_by
168     ,l_last_update_login
169     );
170   --
171   --
172   hr_utility.set_location(' Leaving:'||l_proc, 15);
173 --
174 Exception
175   When hr_api.check_integrity_violated Then
176     -- A check constraint has been violated
177     --
178     pay_rom_shd.constraint_error
179       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
180   When hr_api.unique_integrity_violated Then
181     -- Unique integrity has been violated
182     --
183     pay_rom_shd.constraint_error
184       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
185   When Others Then
186     --
187     Raise;
188 End dt_insert_dml;
189 --
190 -- ----------------------------------------------------------------------------
191 -- |-----------------------< create_app_ownerships >--------------------------|
192 -- ----------------------------------------------------------------------------
193 --
194 -- Description:
195 --   This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
196 --   when the row handler is called in the appropriate mode.
197 --
198 -- ----------------------------------------------------------------------------
199 PROCEDURE create_app_ownerships(p_pk_column  IN varchar2
200                                ,p_pk_value   IN varchar2) IS
201 --
202 CURSOR csr_definition (p_session_id number) IS
203   SELECT product_short_name
204     FROM hr_owner_definitions
205    WHERE session_id = p_session_id;
206 --
207 l_session_id number;
208 --
209 BEGIN
210   --
211   IF (hr_startup_data_api_support.return_startup_mode IN
212                                ('STARTUP','GENERIC')) THEN
213   --
214   l_session_id := nvl(hr_startup_data_api_support.g_startup_session_id,
215                       hr_startup_data_api_support.g_session_id);
216      --
217      FOR c1 IN csr_definition(l_session_id) LOOP
218        --
219        INSERT INTO hr_application_ownerships
220          (key_name
221          ,key_value
222          ,product_name
223          )
224        VALUES
225          (p_pk_column
226          ,fnd_number.number_to_canonical(p_pk_value)
227          ,c1.product_short_name
228          );
229      END LOOP;
230   END IF;
231 END create_app_ownerships;
232 --
233 -- ----------------------------------------------------------------------------
234 -- |-----------------------< create_app_ownerships >--------------------------|
235 -- ----------------------------------------------------------------------------
236 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
237                                ,p_pk_value  IN number) IS
238 --
239 BEGIN
240   create_app_ownerships(p_pk_column, to_char(p_pk_value));
241 END create_app_ownerships;
242 --
243 -- ----------------------------------------------------------------------------
244 -- |------------------------------< insert_dml >------------------------------|
245 -- ----------------------------------------------------------------------------
246 Procedure insert_dml
247   (p_rec                   in out nocopy pay_rom_shd.g_rec_type
248   ,p_effective_date        in date
249   ,p_datetrack_mode        in varchar2
250   ,p_validation_start_date in date
251   ,p_validation_end_date   in date
252   ) is
253 --
254   l_proc	varchar2(72) := g_package||'insert_dml';
255 --
256 Begin
257   hr_utility.set_location('Entering:'||l_proc, 5);
258   --
259   pay_rom_ins.dt_insert_dml
260     (p_rec                   => p_rec
261     ,p_effective_date        => p_effective_date
262     ,p_datetrack_mode        => p_datetrack_mode
263     ,p_validation_start_date => p_validation_start_date
264     ,p_validation_end_date   => p_validation_end_date
265     );
266   --
267   hr_utility.set_location(' Leaving:'||l_proc, 10);
268 End insert_dml;
269 --
270 -- ----------------------------------------------------------------------------
271 -- |------------------------------< pre_insert >------------------------------|
272 -- ----------------------------------------------------------------------------
273 -- {Start Of Comments}
274 --
275 -- Description:
276 --   This private procedure contains any processing which is required before
277 --   the insert dml. Presently, if the entity has a corresponding primary
278 --   key which is maintained by an associating sequence, the primary key for
279 --   the entity will be populated with the next sequence value in
280 --   preparation for the insert dml.
281 --   Also, if comments are defined for this entity, the comments insert
282 --   logic will also be called, generating a comment_id if required.
283 --
284 -- Prerequisites:
285 --   This is an internal procedure which is called from the ins procedure.
286 --
287 -- In Parameters:
288 --   A Pl/Sql record structure.
289 --
290 -- Post Success:
291 --   Processing continues.
292 --
293 -- Post Failure:
294 --   If an error has occurred, an error message and exception will be raised
295 --   but not handled.
296 --
297 -- Developer Implementation Notes:
298 --   Any pre-processing required before the insert dml is issued should be
299 --   coded within this procedure. As stated above, a good example is the
300 --   generation of a primary key number via a corresponding sequence.
301 --   It is important to note that any 3rd party maintenance should be reviewed
302 --   before placing in this procedure.
303 --
304 -- Access Status:
305 --   Internal Row Handler Use Only.
306 --
307 -- {End Of Comments}
308 -- ----------------------------------------------------------------------------
309 Procedure pre_insert
310   (p_rec                   in out nocopy pay_rom_shd.g_rec_type
311   ,p_effective_date        in date
312   ,p_datetrack_mode        in varchar2
313   ,p_validation_start_date in date
314   ,p_validation_end_date   in date
315   ) is
316 --
317   l_proc	varchar2(72) := g_package||'pre_insert';
318 --
319   Cursor C_Sel1 is select pay_run_type_org_methods_s.nextval from sys.dual;
320 --
321 Begin
322   hr_utility.set_location('Entering:'||l_proc, 5);
323   --
324   --
325   -- Select the next sequence number
326   --
327   Open C_Sel1;
328   Fetch C_Sel1 Into p_rec.run_type_org_method_id;
329   Close C_Sel1;
330   --
331   --
332   hr_utility.set_location(' Leaving:'||l_proc, 10);
333 End pre_insert;
334 --
335 -- ----------------------------------------------------------------------------
336 -- |----------------------------< post_insert >-------------------------------|
337 -- ----------------------------------------------------------------------------
338 -- {Start Of Comments}
339 --
340 -- Description:
341 --   This private procedure contains any processing which is required after the
342 --   insert dml.
343 --
344 -- Prerequisites:
345 --   This is an internal procedure which is called from the ins procedure.
346 --
347 -- In Parameters:
348 --   A Pl/Sql record structure.
349 --
350 -- Post Success:
351 --   Processing continues.
352 --
353 -- Post Failure:
354 --   If an error has occurred, an error message and exception will be raised
355 --   but not handled.
356 --
357 -- Developer Implementation Notes:
358 --   Any post-processing required after the insert dml is issued should be
359 --   coded within this procedure. It is important to note that any 3rd party
360 --   maintenance should be reviewed before placing in this procedure.
361 --
362 -- Access Status:
363 --   Internal Row Handler Use Only.
364 --
365 -- {End Of Comments}
366 -- ----------------------------------------------------------------------------
367 Procedure post_insert
368   (p_rec                   in pay_rom_shd.g_rec_type
369   ,p_effective_date        in date
370   ,p_datetrack_mode        in varchar2
371   ,p_validation_start_date in date
372   ,p_validation_end_date   in date
373   ) is
374 --
375   l_proc	varchar2(72) := g_package||'post_insert';
376 --
377 Begin
378   hr_utility.set_location('Entering:'||l_proc, 5);
379   begin
380     --
381     -- insert ownerships if applicable
382     --
383     create_app_ownerships('RUN_TYPE_ORG_METHOD_ID', p_rec.run_type_org_method_id);
384     --
385     pay_rom_rki.after_insert
386       (p_effective_date
387       => p_effective_date
388       ,p_validation_start_date
389       => p_validation_start_date
390       ,p_validation_end_date
391       => p_validation_end_date
392       ,p_run_type_id
393       => p_rec.run_type_id
394       ,p_org_payment_method_id
395       => p_rec.org_payment_method_id
396       ,p_effective_start_date
397       => p_rec.effective_start_date
398       ,p_effective_end_date
399       => p_rec.effective_end_date
400       ,p_priority
401       => p_rec.priority
402       ,p_percentage
403       => p_rec.percentage
404       ,p_amount
405       => p_rec.amount
406       ,p_object_version_number
407       => p_rec.object_version_number
408       ,p_run_type_org_method_id
409       => p_rec.run_type_org_method_id
410       ,p_business_group_id
411       => p_rec.business_group_id
412       ,p_legislation_code
413       => p_rec.legislation_code
414       );
415     --
416   exception
417     --
418     when hr_api.cannot_find_prog_unit then
419       --
420       hr_api.cannot_find_prog_unit_error
421         (p_module_name => 'PAY_RUN_TYPE_ORG_METHODS_F'
422         ,p_hook_type   => 'AI');
423       --
424   end;
425   --
426   hr_utility.set_location(' Leaving:'||l_proc, 10);
427 End post_insert;
428 --
429 -- ----------------------------------------------------------------------------
430 -- |-------------------------------< ins_lck >--------------------------------|
431 -- ----------------------------------------------------------------------------
432 -- {Start Of Comments}
433 --
434 -- Description:
435 --   The ins_lck process has one main function to perform. When inserting
436 --   a datetracked row, we must validate the DT mode.
437 --
438 -- Prerequisites:
439 --   This procedure can only be called for the datetrack mode of INSERT.
440 --
441 -- In Parameters:
442 --
443 -- Post Success:
444 --   On successful completion of the ins_lck process the parental
445 --   datetracked rows will be locked providing the p_enforce_foreign_locking
446 --   argument value is TRUE.
447 --   If the p_enforce_foreign_locking argument value is FALSE then the
448 --   parential rows are not locked.
449 --
450 -- Post Failure:
451 --   The Lck process can fail for:
452 --   1) When attempting to lock the row the row could already be locked by
453 --      another user. This will raise the HR_Api.Object_Locked exception.
454 --   2) When attempting to the lock the parent which doesn't exist.
455 --      For the entity to be locked the parent must exist!
456 --
457 -- Developer Implementation Notes:
458 --   None.
459 --
460 -- Access Status:
461 --   Internal Row Handler Use Only.
462 --
463 -- {End Of Comments}
464 -- ----------------------------------------------------------------------------
465 Procedure ins_lck
466   (p_effective_date        in date
467   ,p_datetrack_mode        in varchar2
468   ,p_rec                   in pay_rom_shd.g_rec_type
469   ,p_validation_start_date out nocopy date
470   ,p_validation_end_date   out nocopy date
471   ) is
472 --
473   l_proc		  varchar2(72) := g_package||'ins_lck';
474   l_validation_start_date date;
475   l_validation_end_date	  date;
476 --
477 Begin
478   hr_utility.set_location('Entering:'||l_proc, 5);
479   --
480   -- Validate the datetrack mode mode getting the validation start
481   -- and end dates for the specified datetrack operation.
482   --
483   dt_api.validate_dt_mode
484     (p_effective_date	       => p_effective_date
485     ,p_datetrack_mode          => p_datetrack_mode
486     ,p_base_table_name         => 'pay_run_type_org_methods_f'
487     ,p_base_key_column         => 'run_type_org_method_id'
488     ,p_base_key_value          => p_rec.run_type_org_method_id
489     ,p_parent_table_name1      => 'pay_org_payment_methods_f'
490     ,p_parent_key_column1      => 'org_payment_method_id'
491     ,p_parent_key_value1       => p_rec.org_payment_method_id
492     ,p_parent_table_name2      => 'pay_run_types_f'
493     ,p_parent_key_column2      => 'run_type_id'
494     ,p_parent_key_value2       => p_rec.run_type_id
495     ,p_enforce_foreign_locking => true
496     ,p_validation_start_date   => l_validation_start_date
497     ,p_validation_end_date     => l_validation_end_date
498     );
499   --
500   -- Set the validation start and end date OUT arguments
501   --
502   p_validation_start_date := l_validation_start_date;
503   p_validation_end_date   := l_validation_end_date;
504   --
505   hr_utility.set_location(' Leaving:'||l_proc, 10);
506 --
507 End ins_lck;
508 --
509 -- ----------------------------------------------------------------------------
510 -- |---------------------------------< ins >----------------------------------|
511 -- ----------------------------------------------------------------------------
512 Procedure ins
513   (p_effective_date in     date
514   ,p_rec            in out nocopy pay_rom_shd.g_rec_type
515   ) is
516 --
517   l_proc                        varchar2(72) := g_package||'ins';
518   l_datetrack_mode              varchar2(30) := hr_api.g_insert;
519   l_validation_start_date       date;
520   l_validation_end_date         date;
521 --
522 Begin
523   hr_utility.set_location('Entering:'||l_proc, 5);
524   --
525   -- Call the lock operation
526   --
527   pay_rom_ins.ins_lck
528     (p_effective_date        => p_effective_date
529     ,p_datetrack_mode        => l_datetrack_mode
530     ,p_rec                   => p_rec
531     ,p_validation_start_date => l_validation_start_date
532     ,p_validation_end_date   => l_validation_end_date
533     );
534   --
535   -- Call the supporting insert validate operations
536   --
537   pay_rom_bus.insert_validate
538     (p_rec                   => p_rec
539     ,p_effective_date        => p_effective_date
540     ,p_datetrack_mode        => l_datetrack_mode
541     ,p_validation_start_date => l_validation_start_date
542     ,p_validation_end_date   => l_validation_end_date
543     );
544   --
545   -- Call the supporting pre-insert operation
546   --
547   pay_rom_ins.pre_insert
548     (p_rec                   => p_rec
549     ,p_effective_date        => p_effective_date
550     ,p_datetrack_mode        => l_datetrack_mode
551     ,p_validation_start_date => l_validation_start_date
552     ,p_validation_end_date   => l_validation_end_date
553     );
554   --
555   -- Insert the row
556   --
557   pay_rom_ins.insert_dml
558     (p_rec                   => p_rec
559     ,p_effective_date        => p_effective_date
560     ,p_datetrack_mode        => l_datetrack_mode
561     ,p_validation_start_date => l_validation_start_date
562     ,p_validation_end_date   => l_validation_end_date
563     );
564   --
565   -- Call the supporting post-insert operation
566   --
567   pay_rom_ins.post_insert
568     (p_rec                   => p_rec
569     ,p_effective_date        => p_effective_date
570     ,p_datetrack_mode        => l_datetrack_mode
571     ,p_validation_start_date => l_validation_start_date
572     ,p_validation_end_date   => l_validation_end_date
573     );
574   --
575   hr_utility.set_location('Leaving:'||l_proc,10);
576 end ins;
577 --
578 -- ----------------------------------------------------------------------------
579 -- |---------------------------------< ins >----------------------------------|
580 -- ----------------------------------------------------------------------------
581 Procedure ins
582   (p_effective_date                 in     date
583   ,p_run_type_id                    in     number
584   ,p_org_payment_method_id          in     number
585   ,p_priority                       in     number
586   ,p_percentage                     in     number   default null
587   ,p_amount                         in     number   default null
588   ,p_business_group_id              in     number   default null
589   ,p_legislation_code               in     varchar2 default null
590   ,p_run_type_org_method_id            out nocopy number
591   ,p_object_version_number             out nocopy number
592   ,p_effective_start_date              out nocopy date
593   ,p_effective_end_date                out nocopy date
594   ) is
595 --
596   l_rec         pay_rom_shd.g_rec_type;
597   l_proc        varchar2(72) := g_package||'ins';
598 --
599 Begin
600   hr_utility.set_location('Entering:'||l_proc, 5);
601   --
602   -- Call conversion function to turn arguments into the
603   -- p_rec structure.
604   --
605   l_rec :=
606   pay_rom_shd.convert_args
607     (p_run_type_id
608     ,p_org_payment_method_id
609     ,null
610     ,null
611     ,p_priority
612     ,p_percentage
613     ,p_amount
614     ,null
615     ,null
616     ,p_business_group_id
617     ,p_legislation_code
618     );
619   --
620   -- Having converted the arguments into the pay_rom_rec
621   -- plsql record structure we call the corresponding record
622   -- business process.
623   --
624   pay_rom_ins.ins
625     (p_effective_date
626     ,l_rec
627     );
628   --
629   -- Set the OUT arguments.
630   --
631   p_run_type_org_method_id           := l_rec.run_type_org_method_id;
632   p_effective_start_date             := l_rec.effective_start_date;
633   p_effective_end_date               := l_rec.effective_end_date;
634   p_object_version_number            := l_rec.object_version_number;
635   --
636   --
637   hr_utility.set_location(' Leaving:'||l_proc, 10);
638 End ins;
639 --
640 end pay_rom_ins;