DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_PCM_BUS

Source


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