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