DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_EGU_BUS

Source


1 Package Body pay_egu_bus as
2 /* $Header: pyegurhi.pkb 120.0 2005/09/26 09:28 tvankayl noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_egu_bus.';  -- Global package name
9 --
10 -- The following two global variables are only to be
11 -- used by the return_legislation_code function.
12 --
13 g_legislation_code            varchar2(150)  default null;
14 g_event_group_usage_id        number         default null;
15 --
16 --  ---------------------------------------------------------------------------
17 --  |----------------------< set_security_group_id >--------------------------|
18 --  ---------------------------------------------------------------------------
19 --
20 Procedure set_security_group_id
21   (p_event_group_usage_id                 in number
22   ,p_associated_column1                   in varchar2 default null
23   ) is
24   --
25   -- Declare cursor
26   --
27   cursor csr_sec_grp is
28     select pbg.security_group_id,
29            pbg.legislation_code
30       from per_business_groups_perf pbg
31          , pay_event_group_usages egu
32      where egu.event_group_usage_id = p_event_group_usage_id
33        and pbg.business_group_id (+) = egu.business_group_id;
34   --
35   -- Declare local variables
36   --
37   l_security_group_id number;
38   l_proc              varchar2(72)  :=  g_package||'set_security_group_id';
39   l_legislation_code  varchar2(150);
40   --
41 begin
42   --
43   hr_utility.set_location('Entering:'|| l_proc, 10);
44   --
45   -- Ensure that all the mandatory parameter are not null
46   --
47   hr_api.mandatory_arg_error
48     (p_api_name           => l_proc
49     ,p_argument           => 'event_group_usage_id'
50     ,p_argument_value     => p_event_group_usage_id
51     );
52   --
53   open csr_sec_grp;
54   fetch csr_sec_grp into l_security_group_id
55                        , l_legislation_code;
56   --
57   if csr_sec_grp%notfound then
58      --
59      close csr_sec_grp;
60      --
61      -- The primary key is invalid therefore we must error
62      --
63      fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
64      hr_multi_message.add
65        (p_associated_column1
66         => nvl(p_associated_column1,'EVENT_GROUP_USAGE_ID')
67        );
68      --
69   else
70     close csr_sec_grp;
71     --
72     -- Set the security_group_id in CLIENT_INFO
73     --
74     hr_api.set_security_group_id
75       (p_security_group_id => l_security_group_id
76       );
77     --
78     -- Set the sessions legislation context in HR_SESSION_DATA
79     --
80     hr_api.set_legislation_context(l_legislation_code);
81   end if;
82   --
83   hr_utility.set_location(' Leaving:'|| l_proc, 20);
84   --
85 end set_security_group_id;
86 --
87 --  ---------------------------------------------------------------------------
88 --  |---------------------< return_legislation_code >-------------------------|
89 --  ---------------------------------------------------------------------------
90 --
91 Function return_legislation_code
92   (p_event_group_usage_id                 in     number
93   )
94   Return Varchar2 Is
95   --
96   -- Declare cursor
97   --
98   cursor csr_leg_code is
99     select pbg.legislation_code
100       from per_business_groups_perf pbg
101          , pay_event_group_usages egu
102      where egu.event_group_usage_id = p_event_group_usage_id
103        and pbg.business_group_id (+) = egu.business_group_id;
104   --
105   -- Declare local variables
106   --
107   l_legislation_code  varchar2(150);
108   l_proc              varchar2(72)  :=  g_package||'return_legislation_code';
109   --
110 Begin
111   --
112   hr_utility.set_location('Entering:'|| l_proc, 10);
113   --
114   -- Ensure that all the mandatory parameter are not null
115   --
116   hr_api.mandatory_arg_error
117     (p_api_name           => l_proc
118     ,p_argument           => 'event_group_usage_id'
119     ,p_argument_value     => p_event_group_usage_id
120     );
121   --
122   if ( nvl(pay_egu_bus.g_event_group_usage_id, hr_api.g_number)
123        = p_event_group_usage_id) then
124     --
125     -- The legislation code has already been found with a previous
126     -- call to this function. Just return the value in the global
127     -- variable.
128     --
129     l_legislation_code := pay_egu_bus.g_legislation_code;
130     hr_utility.set_location(l_proc, 20);
131   else
132     --
133     -- The ID is different to the last call to this function
134     -- or this is the first call to this function.
135     --
136     open csr_leg_code;
137     fetch csr_leg_code into l_legislation_code;
138     --
139     if csr_leg_code%notfound then
140       --
141       -- The primary key is invalid therefore we must error
142       --
143       close csr_leg_code;
144       fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
145       fnd_message.raise_error;
146     end if;
147     hr_utility.set_location(l_proc,30);
148     --
149     -- Set the global variables so the values are
150     -- available for the next call to this function.
151     --
152     close csr_leg_code;
153     pay_egu_bus.g_event_group_usage_id        := p_event_group_usage_id;
154     pay_egu_bus.g_legislation_code  := l_legislation_code;
155   end if;
156   hr_utility.set_location(' Leaving:'|| l_proc, 40);
157   return l_legislation_code;
158 end return_legislation_code;
159 --
160 -- ----------------------------------------------------------------------------
161 -- |----------------------< chk_startup_action >------------------------------|
162 -- ----------------------------------------------------------------------------
163 --
164 -- Description:
165 --  This procedure will check that the current action is allowed according
166 --  to the current startup mode.
167 --
168 -- ----------------------------------------------------------------------------
169 PROCEDURE chk_startup_action
170   (p_insert               IN boolean
171   ,p_business_group_id    IN number
172   ,p_legislation_code     IN varchar2
173   ,p_legislation_subgroup IN varchar2 DEFAULT NULL) IS
174 --
175 BEGIN
176   --
177 
178   IF (p_insert) THEN
179 
180     if p_business_group_id is not null and p_legislation_code is not null then
181         fnd_message.set_name('PAY', 'PAY_33179_BGLEG_INVALID');
182         fnd_message.raise_error;
183     end if;
184 
185     hr_startup_data_api_support.chk_startup_action
186       (p_generic_allowed   => TRUE
187       ,p_startup_allowed   => TRUE
188       ,p_user_allowed      => TRUE
189       ,p_business_group_id => p_business_group_id
190       ,p_legislation_code  => p_legislation_code
191       ,p_legislation_subgroup => p_legislation_subgroup
192       );
193   ELSE
194     hr_startup_data_api_support.chk_upd_del_startup_action
195       (p_generic_allowed   => TRUE
196       ,p_startup_allowed   => TRUE
197       ,p_user_allowed      => TRUE
198       ,p_business_group_id => p_business_group_id
199       ,p_legislation_code  => p_legislation_code
200       ,p_legislation_subgroup => p_legislation_subgroup
201       );
202   END IF;
203   --
204 END chk_startup_action;
205 --
206 -- ----------------------------------------------------------------------------
207 -- |--------------------------< chk_element_set_id >--------------------------|
208 -- ----------------------------------------------------------------------------
209 --
210 --  Description:
211 --    Validates that the element_set_id exists in pay_element_sets
212 --
213 --  Pre-Requisites:
214 --    None
215 --
216 --  In Parameters:
217 --    p_element_set_id
218 --    p_legislation_code
219 --    p_business_group_id
220 --
221 --  Post Success:
222 --    Processing continues if the element_set_id is valid.
223 --
224 --  Post Failure:
225 --    An application error is raised and processing is terminated if
226 --    the element_set_id is invalid.
227 --
228 --  Developer/Implementation Notes:
229 --    None
230 --
231 --  Access Status:
232 --    Internal Row Handler Use Only
233 --
234 procedure chk_element_set_id
235 (p_element_set_id     in number
236 ,p_legislation_code   in varchar2
237 ,p_business_group_id  in number
238 ) is
239 --
240 cursor csr_element_set_id is
241 select pes.legislation_code , pes.business_group_id, pes.element_set_type
242 from   pay_element_sets pes
243 where  pes.element_set_id = p_element_set_id ;
244 --
245 l_busgrpid PAY_ELEMENT_SETS.BUSINESS_GROUP_ID%TYPE;
246 l_legcode  PAY_ELEMENT_SETS.LEGISLATION_CODE%TYPE;
247 l_ele_set_type PAY_ELEMENT_SETS.ELEMENT_SET_TYPE%TYPE;
248 
249 l_proc   varchar2(100) := g_package || 'chk_element_set_id';
250 begin
251 
252   hr_utility.set_location('Entering:'|| l_proc, 10);
253   --
254   -- ELEMENT_SET_ID is mandatory.
255   --
256   hr_api.mandatory_arg_error
257   (p_api_name       =>  l_proc
258   ,p_argument       =>  'ELEMENT_SET_ID'
259   ,p_argument_value =>  p_element_set_id
260   );
261   --
262   open csr_element_set_id;
263   fetch csr_element_set_id into l_legcode, l_busgrpid, l_ele_set_type ;
264 
265   if csr_element_set_id%notfound then
266     close csr_element_set_id;
267     fnd_message.set_name('PAY', 'PAY_33174_PARENT_ID_INVALID');
268     fnd_message.set_token('PARENT' , 'Element Set Id' );
269     fnd_message.raise_error;
270   end if;
271   close csr_element_set_id;
272   --
273   -- Confirm that the parent Element Set's startup mode is compatible
274   -- with this child row.
275   --
276   if not pay_put_shd.chk_startup_mode_compatible
277          (p_parent_bgid    => l_busgrpid
278          ,p_parent_legcode => l_legcode
279          ,p_child_bgid     => p_business_group_id
280          ,p_child_legcode  => p_legislation_code
281          ) then
282       fnd_message.set_name('PAY', 'PAY_33175_BGLEG_MISMATCH');
283       fnd_message.set_token('CHILD', 'Event Group Usage');
284       fnd_message.set_token('PARENT' , 'Element Set');
285       fnd_message.raise_error;
286   end if;
287 
288   if l_ele_set_type <> 'E' then
289 
290     fnd_message.set_name('PAY', 'PAY_294524_INV_ESET_TYPE');
291     fnd_message.raise_error;
292 
293   end if;
294 
295   hr_utility.set_location(' Leaving:'|| l_proc, 20);
296 
297 exception
298   when app_exception.application_exception then
299     if hr_multi_message.exception_add
300        (p_associated_column1 => 'PAY_EVENT_GROUP_USAGES.ELEMENT_SET_ID'
301        ) then
302       raise;
303     end if;
304   when others then
305     if csr_element_set_id%isopen then
306       close csr_element_set_id;
307     end if;
308     raise;
309 
310 end chk_element_set_id;
311 --
312 -- ----------------------------------------------------------------------------
313 -- |--------------------------< chk_event_group_id >--------------------------|
314 -- ----------------------------------------------------------------------------
315 --
316 --  Description:
317 --    Validates that the event_group_id exists in pay_event_groups
318 --
319 --  Pre-Requisites:
320 --    None
321 --
322 --  In Parameters:
323 --    p_event_group_id
324 --    p_legislation_code
325 --    p_business_group_id
326 --
327 --  Post Success:
328 --    Processing continues if the event_group_id is valid.
329 --
330 --  Post Failure:
331 --    An application error is raised and processing is terminated if
332 --    the event_group_id is invalid.
333 --
334 --  Developer/Implementation Notes:
335 --    None
336 --
337 --  Access Status:
338 --    Internal Row Handler Use Only
339 --
340 procedure chk_event_group_id
341 (p_event_group_id     in number
342 ,p_legislation_code   in varchar2
343 ,p_business_group_id  in number
344 ) is
345 --
346 cursor csr_event_group_id is
347 select peg.legislation_code , peg.business_group_id
348 from   pay_event_groups peg
349 where  peg.event_group_id = p_event_group_id ;
350 --
351 l_busgrpid PAY_EVENT_GROUPS.BUSINESS_GROUP_ID%TYPE;
352 l_legcode  PAY_EVENT_GROUPS.LEGISLATION_CODE%TYPE;
353 
354 l_proc   varchar2(100) := g_package || 'chk_event_group_id';
355 begin
356 
357   hr_utility.set_location('Entering:'|| l_proc, 10);
358   --
359   -- EVENT_GROUP_ID is mandatory.
360   --
361   hr_api.mandatory_arg_error
362   (p_api_name       =>  l_proc
363   ,p_argument       =>  'EVENT_GROUP_ID'
364   ,p_argument_value =>  p_event_group_id
365   );
366   --
367   open csr_event_group_id;
368   fetch csr_event_group_id into l_legcode, l_busgrpid ;
369 
370   if csr_event_group_id%notfound then
371     close csr_event_group_id;
372     fnd_message.set_name('PAY', 'PAY_33174_PARENT_ID_INVALID');
373     fnd_message.set_token('PARENT' , 'Event Group Id' );
374     fnd_message.raise_error;
375   end if;
376   close csr_event_group_id;
377   --
378   -- Confirm that the parent Event Group's startup mode is compatible
379   -- with this child row.
380   --
381   if not pay_put_shd.chk_startup_mode_compatible
382          (p_parent_bgid    => l_busgrpid
383          ,p_parent_legcode => l_legcode
384          ,p_child_bgid     => p_business_group_id
385          ,p_child_legcode  => p_legislation_code
386          ) then
387       fnd_message.set_name('PAY', 'PAY_33175_BGLEG_MISMATCH');
388       fnd_message.set_token('CHILD', 'Event Group Usage');
389       fnd_message.set_token('PARENT' , 'Event Group');
390       fnd_message.raise_error;
391   end if;
392 
393   hr_utility.set_location(' Leaving:'|| l_proc, 20);
394 
395 exception
396   when app_exception.application_exception then
397     if hr_multi_message.exception_add
398        (p_associated_column1 => 'PAY_EVENT_GROUP_USAGES.EVENT_GROUP_ID'
399        ) then
400       raise;
401     end if;
402   when others then
403     if csr_event_group_id%isopen then
404       close csr_event_group_id;
405     end if;
406     raise;
407 
408 end chk_event_group_id;
409 --
410 -- ----------------------------------------------------------------------------
411 -- |------------------------< chk_event_group_ele_set >-----------------------|
412 -- ----------------------------------------------------------------------------
413 --
414 --  Description:
415 --    Validates that there is only one row in PAY_EVENT_GROUP_USAGES
416 --    with the combination of EVENT_GROUP_ID and ELEMENT_SET_ID
417 --    in a particular business group or legislation.
418 --
419 --  Pre-Requisites:
420 --    Event Group Id and Element Set Id are valid
421 --
422 --  In Parameters:
423 --    p_event_group_id
424 --    p_element_set_id
425 --    p_legislation_code
426 --    p_business_group_id
427 --
428 --  Post Success:
429 --    Processing continues if the combination is valid.
430 --
431 --  Post Failure:
432 --    An application error is raised and processing is terminated if
433 --    the combination is invalid.
434 --
435 --  Developer/Implementation Notes:
436 --    None
437 --
438 --  Access Status:
439 --    Internal Row Handler Use Only
440 --
441 procedure chk_event_group_ele_set
442 ( p_event_group_id in number
443  ,p_element_set_id  in number
444  ,p_business_group_id in number
445  ,p_legislation_code in varchar2
446 ) is
447 --
448 cursor csr_event_group_ele_set is
449 select  null
450 from    pay_event_group_usages egu
451 where   egu.event_group_id = p_event_group_id
452 and     egu.element_set_id = p_element_set_id
453 and ( p_business_group_id is null
454         or ( p_business_group_id is not null and p_business_group_id = egu.business_group_id )
455         or ( p_business_group_id is not null and
456                 egu.legislation_code is null and egu.business_group_id is null )
457         or ( p_business_group_id is not null and
458                 egu.legislation_code = hr_api.return_legislation_code(p_business_group_id )))
459 and ( p_legislation_code is null
460         or ( p_legislation_code is not null and p_legislation_code = egu.legislation_code )
461         or ( p_legislation_code is not null and
462                 egu.legislation_code is null and egu.business_group_id is null)
463         or ( p_legislation_code is not null and
464                 p_legislation_code = hr_api.return_legislation_code(egu.business_group_id )));
465 
466 l_proc   varchar2(100) := g_package || 'chk_event_group_ele_set';
467 l_exists varchar2(1);
468 --
469 begin
470 
471   hr_utility.set_location('Entering:'|| l_proc, 10);
472 
473   if hr_multi_message.no_exclusive_error
474      (p_check_column1      => 'PAY_EVENT_GROUP_USAGES.EVENT_GROUP_ID'
475      ,p_check_column2      => 'PAY_EVENT_GROUP_USAGES.ELEMENT_SET_ID'
476      ,p_associated_column1 => 'PAY_EVENT_GROUP_USAGES.EVENT_GROUP_ID'
477      ,p_associated_column2 => 'PAY_EVENT_GROUP_USAGES.ELEMENT_SET_ID'
478      ) then
479     --
480             open csr_event_group_ele_set;
481             fetch csr_event_group_ele_set into l_exists;
482 
483             if csr_event_group_ele_set%found then
484                 close csr_event_group_ele_set;
485                 fnd_message.set_name('PAY', 'PAY_294525_ECU_EXISTS');
486                 fnd_message.raise_error;
487             end if;
488 
489             close csr_event_group_ele_set;
490 
491   end if;
492   hr_utility.set_location(' Leaving:'|| l_proc, 20);
493 
494 exception
495 
496     when app_exception.application_exception then
497        if hr_multi_message.exception_add
498          (p_associated_column1 => 'PAY_EVENT_GROUP_USAGES.EVENT_GROUP_ID',
499           p_associated_column2 => 'PAY_EVENT_GROUP_USAGES.ELEMENT_SET_ID') then
500               raise;
501        end if;
502 
503     when others then
504         if csr_event_group_ele_set%isopen then
505                 close csr_event_group_ele_set ;
506         end if;
507         raise;
508 
509 end chk_event_group_ele_set ;
510 --
511 -- ----------------------------------------------------------------------------
512 -- |--------------------------< chk_legislation_code>-------------------------|
513 -- ----------------------------------------------------------------------------
514 --
515 --  Description:
516 --    Validates that the legislation code exists in fnd_territories
517 --
518 --  Pre-Requisites:
519 --    None
520 --
521 --  In Parameters:
522 --    p_legislation_code
523 --
524 --  Post Success:
525 --    Processing continues if the legislation_code is valid.
526 --
527 --  Post Failure:
528 --    An application error is raised and processing is terminated if
529 --    the legislation_code is invalid.
530 --
531 --  Developer/Implementation Notes:
532 --    None
533 --
534 --  Access Status:
535 --    Internal Row Handler Use Only
536 --
537 procedure chk_legislation_code
538 ( p_legislation_code  in varchar2 )
539 is
540 --
541 cursor csr_legislation_code is
542 select null
543 from fnd_territories
544 where territory_code = p_legislation_code ;
545 --
546 l_exists varchar2(1);
547 l_proc   varchar2(100) := g_package || 'chk_legislation_code';
548 begin
549   --
550   hr_utility.set_location('Entering:'|| l_proc, 10);
551 
552   open csr_legislation_code;
553   fetch csr_legislation_code into l_exists ;
554 
555   if csr_legislation_code%notfound then
556     close csr_legislation_code;
557     fnd_message.set_name('PAY', 'PAY_33177_LEG_CODE_INVALID');
558     fnd_message.raise_error;
559   end if;
560   close csr_legislation_code;
561 
562   hr_utility.set_location(' Leaving:'|| l_proc, 20);
563   --
564 exception
565   when app_exception.application_exception then
566     if hr_multi_message.exception_add
567        (p_associated_column1 => 'PAY_EVENT_GROUP_USAGES.LEGISLATION_CODE'
568        ) then
569       raise;
570     end if;
571   when others then
572     if csr_legislation_code%isopen then
573       close csr_legislation_code;
574     end if;
575     raise;
576 end chk_legislation_code;
577 --
578 -- ----------------------------------------------------------------------------
579 -- |---------------------------< insert_validate >----------------------------|
580 -- ----------------------------------------------------------------------------
581 Procedure insert_validate
582   (p_effective_date               in date
583   ,p_rec                          in pay_egu_shd.g_rec_type
584   ) is
585 --
586   l_proc  varchar2(72) := g_package||'insert_validate';
587 --
588 Begin
589   hr_utility.set_location('Entering:'||l_proc, 5);
590   --
591   -- Call all supporting business operations
592   --
593   --
594   chk_startup_action(true
595                     ,p_rec.business_group_id
596                     ,p_rec.legislation_code
597                     );
598 
599   IF hr_startup_data_api_support.g_startup_mode
600                      NOT IN ('GENERIC','STARTUP') THEN
601      --
602      -- Validate Important Attributes
603      --
604      hr_api.validate_bus_grp_id
605        (p_business_group_id => p_rec.business_group_id
606        ,p_associated_column1 => pay_egu_shd.g_tab_nam
607                                 || '.BUSINESS_GROUP_ID');
608      --
609      -- after validating the set of important attributes,
610      -- if Multiple Message Detection is enabled and at least
611      -- one error has been found then abort further validation.
612      --
613      hr_multi_message.end_validation_set;
614   END IF;
615   --
616   if hr_startup_data_api_support.g_startup_mode not in ('GENERIC','USER') then
617 
618      --
619      -- Validate Important Attributes
620      --
621         chk_legislation_code(p_legislation_code => p_rec.legislation_code);
622      --
623         hr_multi_message.end_validation_set;
624 
625   end if;
626   --
627   --
628   -- Validate Dependent Attributes
629   --
630   chk_element_set_id
631   (p_element_set_id     => p_rec.element_set_id
632   ,p_legislation_code   => p_rec.legislation_code
633   ,p_business_group_id  => p_rec.business_group_id
634   );
635 
636   chk_event_group_id
637   (p_event_group_id     => p_rec.event_group_id
638   ,p_legislation_code   => p_rec.legislation_code
639   ,p_business_group_id  => p_rec.business_group_id
640   );
641 
642   chk_event_group_ele_set
643   ( p_event_group_id    => p_rec.event_group_id
644    ,p_element_set_id    => p_rec.element_set_id
645    ,p_business_group_id => p_rec.business_group_id
646    ,p_legislation_code  => p_rec.legislation_code
647   );
648 
649   --
650   hr_utility.set_location(' Leaving:'||l_proc, 10);
651 End insert_validate;
652 --
653 -- ----------------------------------------------------------------------------
654 -- |---------------------------< delete_validate >----------------------------|
655 -- ----------------------------------------------------------------------------
656 Procedure delete_validate
657   (p_rec                          in pay_egu_shd.g_rec_type
658   ) is
659 --
660   l_proc  varchar2(72) := g_package||'delete_validate';
661 --
662 Begin
663   hr_utility.set_location('Entering:'||l_proc, 5);
664   --
665   --
666   chk_startup_action(false
667                     ,pay_egu_shd.g_old_rec.business_group_id
668                     ,pay_egu_shd.g_old_rec.legislation_code
669                     );
670 
671   IF hr_startup_data_api_support.g_startup_mode
672                      NOT IN ('GENERIC','STARTUP') THEN
673      --
674      -- Validate Important Attributes
675      --
676      --
677      -- After validating the set of important attributes,
678      -- if Multiple Message Detection is enabled and at least
679      -- one error has been found then abort further validation.
680      --
681      hr_multi_message.end_validation_set;
682   END IF;
683   --
684   -- Call all supporting business operations
685   --
686   hr_utility.set_location(' Leaving:'||l_proc, 10);
687 End delete_validate;
688 --
689 end pay_egu_bus;