DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_REG_BUS

Source


1 Package Body ben_reg_bus as
2 /* $Header: beregrhi.pkb 120.3 2008/04/29 07:22:53 sagnanas noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  ben_reg_bus.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------< chk_regn_id >------|
12 -- ----------------------------------------------------------------------------
13 --
14 -- Description
15 --   This procedure is used to check that the primary key for the table
16 --   is created properly. It should be null on insert and
17 --   should not be able to be updated.
18 --
19 -- Pre Conditions
20 --   None.
21 --
22 -- In Parameters
23 --   regn_id PK of record being inserted or updated.
24 --   effective_date Effective Date of session
25 --   object_version_number Object version number of record being
26 --                         inserted or updated.
27 --
28 -- Post Success
29 --   Processing continues
30 --
31 -- Post Failure
32 --   Errors handled by the procedure
33 --
34 -- Access Status
35 --   Internal table handler use only.
36 --
37 Procedure chk_regn_id(p_regn_id                in number,
38                            p_effective_date              in date,
42   l_api_updating boolean;
39                            p_object_version_number       in number) is
40   --
41   l_proc         varchar2(72) := g_package||'chk_regn_id';
43   --
44 Begin
45   --
46   hr_utility.set_location('Entering:'||l_proc, 5);
47   --
48   l_api_updating := ben_reg_shd.api_updating
49     (p_effective_date              => p_effective_date,
50      p_regn_id                => p_regn_id,
51      p_object_version_number       => p_object_version_number);
52   --
53   if (l_api_updating
54      and nvl(p_regn_id,hr_api.g_number)
55      <>  ben_reg_shd.g_old_rec.regn_id) then
56     --
57     -- raise error as PK has changed
58     --
59     ben_reg_shd.constraint_error('BEN_REGN_PK');
60     --
61   elsif not l_api_updating then
62     --
63     -- check if PK is null
64     --
65     if p_regn_id is not null then
66       --
67       -- raise error as PK is not null
68       --
69       ben_reg_shd.constraint_error('BEN_REGN_PK');
70       --
71     end if;
72     --
73   end if;
74   --
75   hr_utility.set_location('Leaving:'||l_proc, 10);
76   --
77 End chk_regn_id;
78 --
79 -- ----------------------------------------------------------------------------
80 -- |------< chk_name >------|
81 -- ----------------------------------------------------------------------------
82 --
83 -- Description
84 --   This procedure is used to check that the name field is unique
85 --   on insert and on update.
86 --
87 -- Pre Conditions
88 --   None.
89 --
90 -- In Parameters
91 --   regn_id PK of record being inserted or updated.
92 --   name that is beeing inserted ot updated to.
93 --   effective_date Effective Date of session
94 --   business group ID
95 --   object_version_number Object version number of record being
96 --                         inserted or updated.
97 --
98 -- Post Success
99 --   Processing continues
100 --
101 -- Post Failure
102 --   Errors handled by the procedure
103 --
104 -- Access Status
105 --   HR Development Internal use only.
106 --
107 Procedure chk_name(p_regn_id                     in number,
108                    p_name                        in varchar2,
109                    p_effective_date              in date,
110                    p_validation_start_date         in date,
111                    p_validation_end_date           in date,
112                    p_business_group_id           in number,
113                    p_object_version_number       in number) is
114   --
115   l_proc         varchar2(72) := g_package||'chk_name';
116   l_api_updating boolean;
117   l_exists       varchar2(1);
118   --
119   --
120   cursor csr_name is
121      select null
122         from ben_regn_f
123         where name = p_name
124           and regn_id <> nvl(p_regn_id, hr_api.g_number)
125           and business_group_id + 0 = p_business_group_id
126           and p_validation_start_date <= effective_end_date
127           and p_validation_end_date >= effective_start_date;
128   --
129   --
130 Begin
131   --
132   hr_utility.set_location('Entering:'||l_proc, 5);
133   --
134   l_api_updating := ben_reg_shd.api_updating
135     (p_effective_date              => p_effective_date,
136      p_regn_id                     => p_regn_id,
137      p_object_version_number       => p_object_version_number);
138   --
139   if (l_api_updating
140       and p_name <> ben_reg_shd.g_old_rec.name) or
141       not l_api_updating then
142     --
143     hr_utility.set_location('Entering:'||l_proc, 10);
144     --
145     -- check if this name already exist
146     --
147     open csr_name;
148     fetch csr_name into l_exists;
149     if csr_name%found then
150       close csr_name;
151       --
152       -- raise error as UK1 is violated
153       --
154       ben_reg_shd.constraint_error('BEN_REGN_UK1');
155       --
156     end if;
157     --
158   end if;
159   --
160   hr_utility.set_location('Leaving:'||l_proc, 20);
161   --
162 End chk_name;
163 --
164 -- ----------------------------------------------------------------------------
165 -- |--------------------------< dt_update_validate >--------------------------|
166 -- ----------------------------------------------------------------------------
167 -- {Start Of Comments}
168 --
169 -- Description:
170 --   This procedure is used for referential integrity of datetracked
171 --   parent entities when a datetrack update operation is taking place
172 --   and where there is no cascading of update defined for this entity.
173 --
174 -- Prerequisites:
175 --   This procedure is called from the update_validate.
176 --
177 -- In Parameters:
178 --
179 -- Post Success:
180 --   Processing continues.
181 --
182 -- Post Failure:
183 --
184 -- Developer Implementation Notes:
185 --   This procedure should not need maintenance unless the HR Schema model
186 --   changes.
187 --
188 -- Access Status:
189 --   Internal Row Handler Use Only.
190 --
191 -- {End Of Comments}
192 -- ----------------------------------------------------------------------------
193 Procedure dt_update_validate
194             (
195 	     p_datetrack_mode		     in varchar2,
196              p_validation_start_date	     in date,
197 	     p_validation_end_date	     in date) Is
198 --
202 --
199   l_proc	    varchar2(72) := g_package||'dt_update_validate';
200   l_integrity_error Exception;
201   l_table_name	    all_tables.table_name%TYPE;
203 Begin
204   hr_utility.set_location('Entering:'||l_proc, 5);
205   --
206   -- Ensure that the p_datetrack_mode argument is not null
207   --
208   hr_api.mandatory_arg_error
209     (p_api_name       => l_proc,
210      p_argument       => 'datetrack_mode',
211      p_argument_value => p_datetrack_mode);
212   --
213   -- Only perform the validation if the datetrack update mode is valid
214   --
215   If (dt_api.validate_dt_upd_mode(p_datetrack_mode => p_datetrack_mode)) then
216     --
217     --
218     -- Ensure the arguments are not null
219     --
220     hr_api.mandatory_arg_error
221       (p_api_name       => l_proc,
222        p_argument       => 'validation_start_date',
223        p_argument_value => p_validation_start_date);
224     --
225     hr_api.mandatory_arg_error
226       (p_api_name       => l_proc,
227        p_argument       => 'validation_end_date',
228        p_argument_value => p_validation_end_date);
229     --
230     --
231     --
232   End If;
233   --
234   hr_utility.set_location(' Leaving:'||l_proc, 10);
235 Exception
236   When l_integrity_error Then
237     --
238     -- A referential integrity check was violated therefore
239     -- we must error
240     --
241     fnd_message.set_name('PAY', 'HR_7216_DT_UPD_INTEGRITY_ERR');
242     fnd_message.set_token('TABLE_NAME', l_table_name);
243     fnd_message.raise_error;
244   When Others Then
245     --
246     -- An unhandled or unexpected error has occurred which
247     -- we must report
248     --
249     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
250     fnd_message.set_token('PROCEDURE', l_proc);
251     fnd_message.set_token('STEP','15');
252     fnd_message.raise_error;
253 End dt_update_validate;
254 --
255 -- ----------------------------------------------------------------------------
256 -- |--------------------------< dt_delete_validate >--------------------------|
257 -- ----------------------------------------------------------------------------
258 -- {Start Of Comments}
259 --
260 -- Description:
261 --   This procedure is used for referential integrity of datetracked
262 --   child entities when either a datetrack DELETE or ZAP is in operation
263 --   and where there is no cascading of delete defined for this entity.
264 --   For the datetrack mode of DELETE or ZAP we must ensure that no
265 --   datetracked child rows exist between the validation start and end
266 --   dates.
267 --
268 -- Prerequisites:
269 --   This procedure is called from the delete_validate.
270 --
271 -- In Parameters:
272 --
273 -- Post Success:
274 --   Processing continues.
275 --
276 -- Post Failure:
277 --   If a row exists by determining the returning Boolean value from the
278 --   generic dt_api.rows_exist function then we must supply an error via
279 --   the use of the local exception handler l_rows_exist.
280 --
281 -- Developer Implementation Notes:
282 --   This procedure should not need maintenance unless the HR Schema model
283 --   changes.
284 --
285 -- Access Status:
286 --   Internal Row Handler Use Only.
287 --
288 -- {End Of Comments}
289 -- ----------------------------------------------------------------------------
290 Procedure dt_delete_validate
291             (p_regn_id		in number,
292              p_datetrack_mode		in varchar2,
293 	     p_validation_start_date	in date,
294 	     p_validation_end_date	in date) Is
295 --
296   l_proc	varchar2(72) 	:= g_package||'dt_delete_validate';
297   l_rows_exist	Exception;
298   l_table_name	all_tables.table_name%TYPE;
299 --
300 Begin
301   hr_utility.set_location('Entering:'||l_proc, 5);
302   --
303   -- Ensure that the p_datetrack_mode argument is not null
304   --
305   hr_api.mandatory_arg_error
306     (p_api_name       => l_proc,
307      p_argument       => 'datetrack_mode',
308      p_argument_value => p_datetrack_mode);
309   --
310   -- Only perform the validation if the datetrack mode is either
311   -- DELETE or ZAP
312   --
313   If (p_datetrack_mode = 'DELETE' or
314       p_datetrack_mode = 'ZAP') then
315     --
316     --
317     -- Ensure the arguments are not null
318     --
319     hr_api.mandatory_arg_error
320       (p_api_name       => l_proc,
321        p_argument       => 'validation_start_date',
322        p_argument_value => p_validation_start_date);
323     --
324     hr_api.mandatory_arg_error
325       (p_api_name       => l_proc,
326        p_argument       => 'validation_end_date',
327        p_argument_value => p_validation_end_date);
328     --
329     hr_api.mandatory_arg_error
330       (p_api_name       => l_proc,
331        p_argument       => 'regn_id',
332        p_argument_value => p_regn_id);
333     --
334     If (dt_api.rows_exist
335           (p_base_table_name => 'ben_pl_regn_f',
336            p_base_key_column => 'regn_id',
337            p_base_key_value  => p_regn_id,
338            p_from_date       => p_validation_start_date,
339            p_to_date         => p_validation_end_date)) Then
340       l_table_name := 'ben_pl_regn_f';
341       Raise l_rows_exist;
342     End If;
343     If (dt_api.rows_exist
344           (p_base_table_name => 'ben_regn_for_regy_body_f',
345            p_base_key_column => 'regn_id',
346            p_base_key_value  => p_regn_id,
347            p_from_date       => p_validation_start_date,
348            p_to_date         => p_validation_end_date)) Then
349       l_table_name := 'ben_regn_for_regy_body_f';
353   End If;
350       Raise l_rows_exist;
351     End If;
352     --
354   --
355   hr_utility.set_location(' Leaving:'||l_proc, 10);
356 Exception
357   When l_rows_exist Then
358     --
359     -- A referential integrity check was violated therefore
360     -- we must error
361     --
362     fnd_message.set_name('PAY', 'HR_7215_DT_CHILD_EXISTS');
363     fnd_message.set_token('TABLE_NAME', l_table_name);
364     fnd_message.raise_error;
365   When Others Then
366     --
367     -- An unhandled or unexpected error has occurred which
368     -- we must report
369     --
370     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
371     fnd_message.set_token('PROCEDURE', l_proc);
372     fnd_message.set_token('STEP','15');
373     fnd_message.raise_error;
374 End dt_delete_validate;
375 --
376 -- ----------------------------------------------------------------------------
377 -- |---------------------------< insert_validate >----------------------------|
378 -- ----------------------------------------------------------------------------
379 Procedure insert_validate
380 	(p_rec 			 in ben_reg_shd.g_rec_type,
381 	 p_effective_date	 in date,
382 	 p_datetrack_mode	 in varchar2,
383 	 p_validation_start_date in date,
384 	 p_validation_end_date	 in date) is
385 --
386   l_proc	varchar2(72) := g_package||'insert_validate';
387 --
388 Begin
389   hr_utility.set_location('Entering:'||l_proc, 5);
390   --
391   -- Call all supporting business operations
392   --
393   --
394   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
395   --
396   chk_regn_id
397   (p_regn_id          => p_rec.regn_id,
398    p_effective_date        => p_effective_date,
399    p_object_version_number => p_rec.object_version_number);
400   --
401   chk_name
402   (p_regn_id                 => p_rec.regn_id,
403    p_name                    => p_rec.name,
404    p_effective_date          => p_effective_date,
405    p_validation_start_date   => p_validation_start_date,
406    p_validation_end_date     => p_validation_end_date,
407    p_business_group_id       => p_rec.business_group_id,
408    p_object_version_number   => p_rec.object_version_number);
409   --
410   hr_utility.set_location(' Leaving:'||l_proc, 10);
411 End insert_validate;
412 --
413 -- ----------------------------------------------------------------------------
414 -- |---------------------------< update_validate >----------------------------|
415 -- ----------------------------------------------------------------------------
416 Procedure update_validate
417 	(p_rec 			 in ben_reg_shd.g_rec_type,
418 	 p_effective_date	 in date,
419 	 p_datetrack_mode	 in varchar2,
420 	 p_validation_start_date in date,
421 	 p_validation_end_date	 in date) is
422 --
423   l_proc	varchar2(72) := g_package||'update_validate';
424 --
425 Begin
426   hr_utility.set_location('Entering:'||l_proc, 5);
427   --
428   -- Call all supporting business operations
429   --
430   --
431   hr_api.validate_bus_grp_id(p_rec.business_group_id);  -- Validate Bus Grp
432   --
433   chk_regn_id
434   (p_regn_id          => p_rec.regn_id,
435    p_effective_date        => p_effective_date,
436    p_object_version_number => p_rec.object_version_number);
437   --
438   chk_name
439   (p_regn_id               => p_rec.regn_id,
440    p_name                  => p_rec.name,
441    p_effective_date        => p_effective_date,
442    p_validation_start_date   => p_validation_start_date,
443    p_validation_end_date     => p_validation_end_date,
444    p_business_group_id     => p_rec.business_group_id,
445    p_object_version_number => p_rec.object_version_number);
446   --
447   --
448   -- Call the datetrack update integrity operation
449   --
450   dt_update_validate
451     (
452      p_datetrack_mode                => p_datetrack_mode,
453      p_validation_start_date	     => p_validation_start_date,
454      p_validation_end_date	     => p_validation_end_date);
455   --
456   hr_utility.set_location(' Leaving:'||l_proc, 10);
457 End update_validate;
458 --
459 -- ----------------------------------------------------------------------------
460 -- |---------------------------< delete_validate >----------------------------|
461 -- ----------------------------------------------------------------------------
462 Procedure delete_validate
463 	(p_rec 			 in ben_reg_shd.g_rec_type,
464 	 p_effective_date	 in date,
465 	 p_datetrack_mode	 in varchar2,
466 	 p_validation_start_date in date,
467 	 p_validation_end_date	 in date) is
468 --
469   l_proc	varchar2(72) := g_package||'delete_validate';
470 --
471 Begin
472   hr_utility.set_location('Entering:'||l_proc, 5);
473   --
474   -- Call all supporting business operations
475   --
476   dt_delete_validate
477     (p_datetrack_mode		=> p_datetrack_mode,
478      p_validation_start_date	=> p_validation_start_date,
479      p_validation_end_date	=> p_validation_end_date,
480      p_regn_id		=> p_rec.regn_id);
481   --
482   hr_utility.set_location(' Leaving:'||l_proc, 10);
483 End delete_validate;
484 --
485 --
486 --  ---------------------------------------------------------------------------
487 --  |---------------------< return_legislation_code >-------------------------|
488 --  ---------------------------------------------------------------------------
489 --
490 function return_legislation_code
491   (p_regn_id in number) return varchar2 is
492   --
493   -- Declare cursor
494   --
495   cursor csr_leg_code is
496     select a.legislation_code
497     from   per_business_groups a,
498            ben_regn_f b
499     where b.regn_id      = p_regn_id
500     and   a.business_group_id = b.business_group_id;
501   --
502   -- Declare local variables
503   --
504   l_legislation_code  varchar2(150);
505   l_proc              varchar2(72)  :=  g_package||'return_legislation_code';
506   --
507 begin
508   --
509   hr_utility.set_location('Entering:'|| l_proc, 10);
510   --
511   -- Ensure that all the mandatory parameter are not null
512   --
513   hr_api.mandatory_arg_error(p_api_name       => l_proc,
514                              p_argument       => 'regn_id',
515                              p_argument_value => p_regn_id);
516   --
517   open csr_leg_code;
518     --
519     fetch csr_leg_code into l_legislation_code;
520     --
521     if csr_leg_code%notfound then
522       --
523       close csr_leg_code;
524       --
525       -- The primary key is invalid therefore we must error
526       --
527       fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
528       fnd_message.raise_error;
529       --
530     end if;
531     --
532   close csr_leg_code;
533   --
534   hr_utility.set_location(' Leaving:'|| l_proc, 20);
535   --
536   return l_legislation_code;
537   --
538 end return_legislation_code;
539 --
540 end ben_reg_bus;