DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_PBF_BUS

Source


1 Package Body pay_pbf_bus as
2 /* $Header: pypbfrhi.pkb 120.1 2005/08/02 12:12:56 susivasu noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_pbf_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_balance_feed_id             number         default null;
15 --
16 --  ---------------------------------------------------------------------------
17 --  |----------------------< set_security_group_id >--------------------------|
18 --  ---------------------------------------------------------------------------
19 --
20 Procedure set_security_group_id
21   (p_balance_feed_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,pbg.legislation_code
29       from PER_BUSINESS_GROUPS_PERF pbg
30          , pay_balance_feeds_f pbf
31      where pbf.balance_feed_id = p_balance_feed_id
32        and pbg.business_group_id = pbf.business_group_id;
33   --
34   -- Declare local variables
35   --
36   l_security_group_id number;
37   l_legislation_code  varchar2(150);
38   l_proc              varchar2(72)  :=  g_package||'set_security_group_id';
39   --
40 begin
41   --
42   hr_utility.set_location('Entering:'|| l_proc, 10);
43   --
44   -- Ensure that all the mandatory parameter are not null
45   --
46   hr_api.mandatory_arg_error
47     (p_api_name           => l_proc
48     ,p_argument           => 'balance_feed_id'
49     ,p_argument_value     => p_balance_feed_id
50     );
51   --
52   open csr_sec_grp;
53   fetch csr_sec_grp into l_security_group_id,l_legislation_code;
54   --
55   if csr_sec_grp%notfound then
56      --
57      close csr_sec_grp;
58      --
59      -- The primary key is invalid therefore we must error
60      --
61      fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
62      hr_multi_message.add
63        (p_associated_column1
64          => nvl(p_associated_column1,'BALANCE_FEED_ID')
65        );
66      --
67   else
68     close csr_sec_grp;
69     --
70     -- Set the security_group_id in CLIENT_INFO
71     --
72     hr_api.set_security_group_id
73       (p_security_group_id => l_security_group_id
74       );
75 
76     -- Set the sessions legislation context in HR_SESSION_DATA
77     --
78     hr_api.set_legislation_context(l_legislation_code);
79 
80   end if;
81   --
82   hr_utility.set_location(' Leaving:'|| l_proc, 20);
83   --
84 end set_security_group_id;
85 --
86 --  ---------------------------------------------------------------------------
87 --  |---------------------< return_legislation_code >-------------------------|
88 --  ---------------------------------------------------------------------------
89 --
90 Function return_legislation_code
91   (p_balance_feed_id                      in     number
92   )
93   Return Varchar2 Is
94   --
95   -- Declare cursor
96   --
97   cursor csr_leg_code is
98     select pbg.legislation_code
99       from per_business_groups_perf pbg
100          , pay_balance_feeds_f pbf
101      where pbf.balance_feed_id = p_balance_feed_id
102        and pbg.business_group_id (+) = pbf.business_group_id;
103   --
104   -- Declare local variables
105   --
106   l_legislation_code  varchar2(150);
107   l_proc              varchar2(72)  :=  g_package||'return_legislation_code';
108   --
109 Begin
110   --
111   hr_utility.set_location('Entering:'|| l_proc, 10);
112   --
113   -- Ensure that all the mandatory parameter are not null
114   --
115   hr_api.mandatory_arg_error
116     (p_api_name           => l_proc
117     ,p_argument           => 'balance_feed_id'
118     ,p_argument_value     => p_balance_feed_id
119     );
120   --
121   if ( nvl(pay_pbf_bus.g_balance_feed_id, hr_api.g_number)
122        = p_balance_feed_id) then
123     --
124     -- The legislation code has already been found with a previous
125     -- call to this function. Just return the value in the global
126     -- variable.
127     --
128     l_legislation_code := pay_pbf_bus.g_legislation_code;
129     hr_utility.set_location(l_proc, 20);
130   else
131     --
132     -- The ID is different to the last call to this function
133     -- or this is the first call to this function.
134     --
135     open csr_leg_code;
136     fetch csr_leg_code into l_legislation_code;
137     --
138     if csr_leg_code%notfound then
139       --
140       -- The primary key is invalid therefore we must error
141       --
142       close csr_leg_code;
143       fnd_message.set_name('PAY','HR_7220_INVALID_PRIMARY_KEY');
144       fnd_message.raise_error;
145     end if;
146     hr_utility.set_location(l_proc,30);
147     --
148     -- Set the global variables so the values are
149     -- available for the next call to this function.
150     --
151     close csr_leg_code;
152     pay_pbf_bus.g_balance_feed_id             := p_balance_feed_id;
153     pay_pbf_bus.g_legislation_code  := l_legislation_code;
154   end if;
155   hr_utility.set_location(' Leaving:'|| l_proc, 40);
156   return l_legislation_code;
157 end return_legislation_code;
158 --
159 -- ----------------------------------------------------------------------------
160 -- |-----------------------< chk_non_updateable_args >------------------------|
161 -- ----------------------------------------------------------------------------
162 -- {Start Of Comments}
163 --
164 -- Description:
165 --   This procedure is used to ensure that non updateable attributes have
166 --   not been updated. If an attribute has been updated an error is generated.
167 --
168 -- Pre Conditions:
169 --   g_old_rec has been populated with details of the values currently in
170 --   the database.
171 --
172 -- In Arguments:
173 --   p_rec has been populated with the updated values the user would like the
174 --   record set to.
175 --
176 -- Post Success:
177 --   Processing continues if all the non updateable attributes have not
178 --   changed.
179 --
180 -- Post Failure:
181 --   An application error is raised if any of the non updatable attributes
182 --   have been altered.
183 --
184 -- {End Of Comments}
185 -- ----------------------------------------------------------------------------
186 Procedure chk_non_updateable_args
187   (p_effective_date  in date
188   ,p_rec             in pay_pbf_shd.g_rec_type
189   ) IS
190 --
191   l_proc     varchar2(72) := g_package || 'chk_non_updateable_args';
192   l_argument varchar2(30);
193 --
194 Begin
195   --
196   hr_utility.set_location('Entering:'||l_proc, 5);
197 
198   -- Only proceed with the validation if a row exists for the current
199   -- record in the HR Schema.
200   --
201   IF NOT pay_pbf_shd.api_updating
202       (p_balance_feed_id                  => p_rec.balance_feed_id
203       ,p_effective_date                   => p_effective_date
204       ,p_object_version_number            => p_rec.object_version_number
205       ) THEN
206      fnd_message.set_name('PER', 'HR_6153_ALL_PROCEDURE_FAIL');
207      fnd_message.set_token('PROCEDURE ', l_proc);
208      fnd_message.set_token('STEP ', '5');
209      fnd_message.raise_error;
210   END IF;
211   --
212   hr_utility.set_location('Entering:'||l_proc, 6);
213 
214   if nvl(p_rec.business_group_id, hr_api.g_number) <>
215          nvl(pay_pbf_shd.g_old_rec.business_group_id, hr_api.g_number) then
216 	     l_argument := 'business_group_id';
217 	     raise hr_api.argument_changed;
218   end if;
219 
220   hr_utility.set_location('Entering:'||l_proc, 7);
221   if nvl(p_rec.input_value_id, hr_api.g_number) <>
222          nvl(pay_pbf_shd.g_old_rec.input_value_id, hr_api.g_number) then
223 	    l_argument := 'input_value_id';
224 	    raise hr_api.argument_changed;
225   end if;
226 
227   hr_utility.set_location('Entering:'||l_proc, 8);
228   if nvl(p_rec.balance_type_id, hr_api.g_number) <>
229          nvl(pay_pbf_shd.g_old_rec.balance_type_id, hr_api.g_number) then
230 	    l_argument := 'balance_type_id';
231 	    raise hr_api.argument_changed;
232   end if;
233 
234   hr_utility.set_location('Entering:'||l_proc, 9);
235   if nvl(p_rec.legislation_code, hr_api.g_varchar2) <>
236          nvl(pay_pbf_shd.g_old_rec.legislation_code, hr_api.g_varchar2) then
237 	    l_argument := 'legislation_code';
238 	    raise hr_api.argument_changed;
239   end if;
240 
241   hr_utility.set_location('Entering:'||l_proc, 9);
242   if nvl(p_rec.legislation_subgroup, hr_api.g_varchar2) <>
243          nvl(pay_pbf_shd.g_old_rec.legislation_subgroup, hr_api.g_varchar2) then
244 	    l_argument := 'legislation_subgroup';
245 	    raise hr_api.argument_changed;
246   end if;
247 
248   hr_utility.set_location(' Leaving:'||l_proc, 10);
249 
250   Exception
251   When hr_api.argument_changed Then
252   -- A non updatetable attribute has been changed therefore we
253   -- must report this error
254      hr_api.argument_changed_error
255      (p_api_name => l_proc
256      ,p_argument => l_argument
257      );
258 
259   --
260 End chk_non_updateable_args;
261 --
262 -- ----------------------------------------------------------------------------
263 -- |--------------------------< dt_update_validate >--------------------------|
264 -- ----------------------------------------------------------------------------
265 -- {Start Of Comments}
266 --
267 -- Description:
268 --   This procedure is used for referential integrity of datetracked
269 --   parent entities when a datetrack update operation is taking place
270 --   and where there is no cascading of update defined for this entity.
271 --
272 -- Prerequisites:
273 --   This procedure is called from the update_validate.
274 --
275 -- In Parameters:
276 --
277 -- Post Success:
278 --   Processing continues.
279 --
280 -- Post Failure:
281 --
282 -- Developer Implementation Notes:
283 --   This procedure should not need maintenance unless the HR Schema model
284 --   changes.
285 --
286 -- Access Status:
287 --   Internal Row Handler Use Only.
288 --
289 -- {End Of Comments}
290 -- ----------------------------------------------------------------------------
291 Procedure dt_update_validate
292   (p_datetrack_mode                in varchar2
293   ,p_validation_start_date         in date
294   ,p_validation_end_date           in date
295   ) Is
296 --
297   l_proc  varchar2(72) := g_package||'dt_update_validate';
298 --
299 Begin
300   --
301   -- Ensure that the p_datetrack_mode argument is not null
302   --
303   hr_api.mandatory_arg_error
304     (p_api_name       => l_proc
305     ,p_argument       => 'datetrack_mode'
306     ,p_argument_value => p_datetrack_mode
307     );
308   --
309   -- Mode will be valid, as this is checked at the start of the upd.
310   --
311   -- Ensure the arguments are not null
312   --
313   hr_api.mandatory_arg_error
314     (p_api_name       => l_proc
315     ,p_argument       => 'validation_start_date'
316     ,p_argument_value => p_validation_start_date
317     );
318   --
319   hr_api.mandatory_arg_error
320     (p_api_name       => l_proc
321     ,p_argument       => 'validation_end_date'
322     ,p_argument_value => p_validation_end_date
323     );
324   --
325     --
326   --
327 Exception
328   When Others Then
329     --
330     -- An unhandled or unexpected error has occurred which
331     -- we must report
332     --
333     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
334     fnd_message.set_token('PROCEDURE', l_proc);
335     fnd_message.set_token('STEP','15');
336     fnd_message.raise_error;
337 End dt_update_validate;
338 --
339 -- ----------------------------------------------------------------------------
340 -- |--------------------------< dt_delete_validate >--------------------------|
341 -- ----------------------------------------------------------------------------
342 -- {Start Of Comments}
343 --
344 -- Description:
345 --   This procedure is used for referential integrity of datetracked
346 --   child entities when either a datetrack DELETE or ZAP is in operation
347 --   and where there is no cascading of delete defined for this entity.
348 --   For the datetrack mode of DELETE or ZAP we must ensure that no
349 --   datetracked child rows exist between the validation start and end
350 --   dates.
351 --
352 -- Prerequisites:
353 --   This procedure is called from the delete_validate.
354 --
355 -- In Parameters:
356 --
357 -- Post Success:
358 --   Processing continues.
359 --
360 -- Post Failure:
361 --   If a row exists by determining the returning Boolean value from the
362 --   generic dt_api.rows_exist function then we must supply an error via
363 --   the use of the local exception handler l_rows_exist.
364 --
365 -- Developer Implementation Notes:
366 --   This procedure should not need maintenance unless the HR Schema model
367 --   changes.
368 --
369 -- Access Status:
370 --   Internal Row Handler Use Only.
371 --
372 -- {End Of Comments}
373 -- ----------------------------------------------------------------------------
374 Procedure dt_delete_validate
375   (p_balance_feed_id                  in number
376   ,p_datetrack_mode                   in varchar2
377   ,p_validation_start_date            in date
378   ,p_validation_end_date              in date
379   ) Is
380 --
381   l_proc        varchar2(72)    := g_package||'dt_delete_validate';
382 --
383 Begin
384   --
385   -- Ensure that the p_datetrack_mode argument is not null
386   --
387   hr_api.mandatory_arg_error
388     (p_api_name       => l_proc
389     ,p_argument       => 'datetrack_mode'
390     ,p_argument_value => p_datetrack_mode
391     );
392   --
393   -- Only perform the validation if the datetrack mode is either
394   -- DELETE or ZAP
395   --
396   If (p_datetrack_mode = hr_api.g_delete or
397       p_datetrack_mode = hr_api.g_zap) then
398     --
399     --
400     -- Ensure the arguments are not null
401     --
402     hr_api.mandatory_arg_error
403       (p_api_name       => l_proc
404       ,p_argument       => 'validation_start_date'
405       ,p_argument_value => p_validation_start_date
406       );
407     --
408     hr_api.mandatory_arg_error
409       (p_api_name       => l_proc
410       ,p_argument       => 'validation_end_date'
411       ,p_argument_value => p_validation_end_date
412       );
413     --
414     hr_api.mandatory_arg_error
415       (p_api_name       => l_proc
416       ,p_argument       => 'balance_feed_id'
417       ,p_argument_value => p_balance_feed_id
418       );
419     --
420   --
421     --
422   End If;
423   --
424 Exception
425   When Others Then
426     --
427     -- An unhandled or unexpected error has occurred which
428     -- we must report
429     --
430     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
431     fnd_message.set_token('PROCEDURE', l_proc);
432     fnd_message.set_token('STEP','15');
433     fnd_message.raise_error;
434   --
435 End dt_delete_validate;
436 --
437 -- ----------------------------------------------------------------------------
438 -- |----------------------< chk_startup_action >------------------------------|
439 -- ----------------------------------------------------------------------------
440 --
441 -- Description:
442 --  This procedure will check that the current action is allowed according
443 --  to the current startup mode.
444 --
445 -- ----------------------------------------------------------------------------
446 PROCEDURE chk_startup_action
447   (p_insert               IN boolean
448   ,p_business_group_id    IN number
449   ,p_legislation_code     IN varchar2
450   ,p_legislation_subgroup IN varchar2 DEFAULT NULL) IS
451 --
452 BEGIN
453   --
454   -- Call the supporting procedure to check startup mode
455   -- EDIT_HERE: The following call should be edited if certain types of rows
456   -- are not permitted.
457   IF (p_insert) THEN
458     hr_startup_data_api_support.chk_startup_action
459       (p_generic_allowed   => FALSE
460       ,p_startup_allowed   => TRUE
461       ,p_user_allowed      => TRUE
462       ,p_business_group_id => p_business_group_id
463       ,p_legislation_code  => p_legislation_code
464       ,p_legislation_subgroup => p_legislation_subgroup
465       );
466   ELSE
467     hr_startup_data_api_support.chk_upd_del_startup_action
468       (p_generic_allowed   => FALSE
469       ,p_startup_allowed   => TRUE
470       ,p_user_allowed      => TRUE
471       ,p_business_group_id => p_business_group_id
472       ,p_legislation_code  => p_legislation_code
473       ,p_legislation_subgroup => p_legislation_subgroup
474       );
475   END IF;
476   --
477 END chk_startup_action;
478 --
479 --
480 -- check procedures
481 -- ----------------------------------------------------------------------------
482 -- |------------------------< chk_business_group_id >-------------------------|
483 -- ----------------------------------------------------------------------------
484 --
485 -- Description:
486 --   This procedure is used to validate the business group id against the
487 --   parent table
488 --
489 -- ----------------------------------------------------------------------------
490 Procedure chk_business_group_id
491   (p_business_group_id in number
492   ,p_input_value_id    in number
493   ,p_effective_date    in date
494   ) is
495 --
496   l_proc               varchar2(72) := g_package||'chk_business_group_id';
497   l_exists	       varchar2(1);
498   l_balance_init_flag  number := 0;
499 
500   Cursor c_chk_bg_id
501   is
502     select '1'
503       from hr_organization_units
504      where business_group_id = p_business_group_id;
505      -- and  ( l_balance_init_flag = 1 or
506      --         ( p_effective_date between date_from
507 	 -- 	and nvl(date_to, hr_api.g_eot) ) );
508 --
509 Begin
510   hr_utility.set_location('Entering:'||l_proc, 5);
511   --
512 
513   --
514   hr_api.mandatory_arg_error
515       (p_api_name       => l_proc
516       ,p_argument       => 'input_value_id'
517       ,p_argument_value => p_input_value_id
518       );
519   --
520 
521   if get_balance_init_flag ( p_input_value_id => p_input_value_id ) then
522        l_balance_init_flag := 1;
523   end if;
524 
525   If p_business_group_id is not null then
526     Open c_chk_bg_id;
527     Fetch c_chk_bg_id into l_exists;
528     If c_chk_bg_id%notfound Then
529       --
530       Close c_chk_bg_id;
531       fnd_message.set_name('PAY','PAY_33085_INVALID_FK');
532       fnd_message.set_token('COLUMN','BUSINESS_GROUP_ID');
533       fnd_message.set_token('TABLE','HR_ORGANIZATION_UNITS');
534       fnd_message.raise_error;
535       --
536     End If;
537     Close c_chk_bg_id;
538   End If;
539   --
540   hr_utility.set_location('Leaving:'||l_proc, 10);
541 End;
542 --
543 -- ----------------------------------------------------------------------------
544 -- |------------------------< chk_legislation_code >--------------------------|
545 -- ----------------------------------------------------------------------------
546 --
547 -- Description:
548 --   This procedure is used to validate the legislation code against the
549 --   parent table
550 --
551 -- ----------------------------------------------------------------------------
552 Procedure chk_legislation_code
553   (p_legislation_code  in varchar2)
554   is
555 --
556   l_proc        varchar2(72) := g_package||'chk_legislation_code';
557   l_exists	    varchar2(1);
558   Cursor c_chk_leg_code
559   is
560     select '1'
561       from fnd_territories
562      where territory_code = p_legislation_code;
563 --
564 Begin
565   hr_utility.set_location('Entering:'||l_proc, 5);
566   --
567   If p_legislation_code is not null then
568 
569   	Open c_chk_leg_code;
570   	Fetch c_chk_leg_code into l_exists;
571   	If c_chk_leg_code%notfound Then
572   	  --
573   	  Close c_chk_leg_code;
574   	  fnd_message.set_name('PAY','PAY_33085_INVALID_FK');
575   	  fnd_message.set_token('COLUMN','LEGISLATION_CODE');
576   	  fnd_message.set_token('TABLE','FND_TERRITORIES');
577   	  fnd_message.raise_error;
578   	  --
579   	End If;
580   	Close c_chk_leg_code;
581 
582   End If;
583   --
584   hr_utility.set_location('Leaving:'||l_proc, 10);
585 End;
586 --
587 -- ----------------------------------------------------------------------------
588 -- |------------------------< chk_input_value_id >----------------------------|
589 -- ----------------------------------------------------------------------------
590 --
591 -- Description:
592 --   This procedure is used to validate the input value id against the
593 --   parent table
594 --
595 -- ----------------------------------------------------------------------------
596 Procedure chk_input_value_id
597   (p_input_value_id    in number
598   ,p_business_group_id in pay_balance_feeds_f.business_group_id%type
599   ,p_legislation_code  in pay_balance_feeds_f.legislation_code%type
600   ) is
601 --
602   l_proc             varchar2(72) := g_package||'chk_input_value_id';
603   l_exists	     varchar2(1);
604   l_legislation_code per_business_groups.legislation_code%type;
605 
606     cursor csr_ipv_id is
607     select '1'
608     from pay_input_values_f
609     where input_value_id = p_input_value_id
610     and nvl(legislation_code, nvl(l_legislation_code, hr_api.g_varchar2))
611        = nvl(l_legislation_code, hr_api.g_varchar2)
612     and nvl(business_group_id, nvl(p_business_group_id, hr_api.g_number))
613        = nvl(p_business_group_id, hr_api.g_number);
614 
615     cursor csr_ipv_multiple_feeds is
616     select null
617     from pay_balance_feeds_f pbf
618     where pbf.input_value_id = p_input_value_id;
619 --
620 Begin
621   hr_utility.set_location('Entering:'||l_proc, 5);
622   --
623 
624   l_legislation_code := nvl(p_legislation_code
625                            ,hr_api.return_legislation_code
626                                 (p_business_group_id));
627 
628   Open csr_ipv_id;
629   Fetch csr_ipv_id into l_exists;
630   If csr_ipv_id%notfound Then
631     --
632     Close csr_ipv_id;
633     fnd_message.set_name('PAY','PAY_34154_LEG_BUS_MISMATCH');
634     fnd_message.set_token('ENTITY1','INITIAL BALANCE FEED');
635     fnd_message.set_token('ENTITY2','INPUT VALUE');
636     fnd_message.raise_error;
637     --
638   End If;
639   Close csr_ipv_id;
640 
641   -- no other balance feed must be created with the input value when creating
642   -- initial balance feed.
643 
644   if get_balance_init_flag (p_input_value_id => p_input_value_id) then
645 
646 	open csr_ipv_multiple_feeds;
647 	fetch csr_ipv_multiple_feeds into l_exists;
648 
649 	if csr_ipv_multiple_feeds%found then
650 
651 	    close csr_ipv_multiple_feeds;
652 	    fnd_message.set_name('PAY','PAY_33245_BIFEED_IPV_MUL_FEEDS');
653 	    fnd_message.raise_error;
654 
655 	end if;
656 
657 	close csr_ipv_multiple_feeds;
658 
659   end if;
660 
661   --
662   hr_utility.set_location('Leaving:'||l_proc, 10);
663 End;
664 --
665 -- ----------------------------------------------------------------------------
666 -- |------------------------< chk_balance_type_id >-------------------------|
667 -- ----------------------------------------------------------------------------
668 --
669 -- Description:
670 --   This procedure is used to validate the balance type id against the
671 --   parent table
672 --
673 -- ----------------------------------------------------------------------------
674 Procedure chk_balance_type_id
675   (p_balance_type_id in number
676   ,p_business_group_id in pay_balance_feeds_f.business_group_id%type
677   ,p_legislation_code  in pay_balance_feeds_f.legislation_code%type
678   ) is
679 --
680   l_proc              varchar2(72) := g_package||'chk_balance_type_id';
681   l_exists	      varchar2(1);
682   l_legislation_code  per_business_groups.legislation_code%type;
683 
684     cursor csr_bal_type_id is
685     select '1'
686       from pay_balance_types
687      where balance_type_id = p_balance_type_id
688      and nvl(legislation_code, nvl(l_legislation_code, hr_api.g_varchar2))
689         = nvl(l_legislation_code, hr_api.g_varchar2)
690      and nvl(business_group_id, nvl(p_business_group_id, hr_api.g_number))
691         = nvl(p_business_group_id, hr_api.g_number);
692 
693 --
694 Begin
695   hr_utility.set_location('Entering:'||l_proc, 5);
696   --
697 
698   l_legislation_code := nvl(p_legislation_code
699                            ,hr_api.return_legislation_code
700                                (p_business_group_id));
701 
702   Open csr_bal_type_id;
703   Fetch csr_bal_type_id into l_exists;
704   If csr_bal_type_id%notfound Then
705     --
706     Close csr_bal_type_id;
707     fnd_message.set_name('PAY','PAY_34154_LEG_BUS_MISMATCH');
708     fnd_message.set_token('ENTITY1','INITIAL BALANCE FEED');
709     fnd_message.set_token('ENTITY2','BALANCE');
710     fnd_message.raise_error;
711     --
712   End If;
713   Close csr_bal_type_id;
714   --
715   hr_utility.set_location('Leaving:'||l_proc, 10);
716 End;
717 --
718 -- ----------------------------------------------------------------------------
719 -- |-----------------< chk_bal_class_exists >---------------------------------|
720 -- ----------------------------------------------------------------------------
721 -- {Start Of Comments}
722 --
723 -- Description:
724 --   This procedure is used to ensure that for a balance_type_id if there
725 --   already exists a balance classification that feeds the balance then the
726 --   insert/update/delete balance feed operation cannot be performed.
727 --
728 -- In Arguments:
729 --   The balance type id for which feed is being created/updated/deleted
730 --
731 -- Post Success:
732 --   Processing continues and balance feed is inserted/updated/deleted
733 --
734 -- Post Failure:
735 --   An application error is raised if a balance classification already exists
736 --   for the balance to which feed is being created/updated/deleted.
737 --
738 -- {End Of Comments}
739 
740 procedure chk_bal_class_exists
741            (p_balance_type_id number) is
742 --
743 l_proc        varchar2(72) := g_package||'chk_bal_class_exists';
744 
745    cursor csr_classifications_exist is
746    select bcl.classification_id
747      from pay_balance_classifications bcl
748     where bcl.balance_type_id = p_balance_type_id;
749 --
750    l_classification_id number;
751 --
752  begin
753 
754  hr_utility.set_location('Entering:'||l_proc, 5);
755 --
756    open csr_classifications_exist;
757    fetch csr_classifications_exist into l_classification_id;
758    if csr_classifications_exist%found then
759      close csr_classifications_exist;
760      fnd_message.set_name('PAY','HR_7444_BAL_FEED_READ_ONLY');
761      fnd_message.raise_error;
762    else
763      close csr_classifications_exist;
764    end if;
765 --
766    hr_utility.set_location(' Leaving:'||l_proc, 10);
767 --
768  end chk_bal_class_exists;
769 --
770 -- ---------------------------------------------------------------------------
771 -- |----------------------< chk_initial_feed_exists >-------------------------|
772 -- ----------------------------------------------------------------------------
773 -- {Start Of Comments}
774 --
775 -- Description:
776 --   This procedure is used to ensure that when creating a feed for a
777 --   balance, no initial balance feed already exists for that balance
778 --
779 -- In Arguments:
780 --   The balance type id for which feed is being created
781 --
782 -- Post Success:
783 --   Processing continues and balance feed is inserted
784 --
785 -- Post Failure:
786 --   An application error is raised if an initial feed already exists
787 --   for the balance to which feed is being created.
788 --
789 -- {End Of Comments}
790 
791 procedure chk_initial_feed_exists
792            (p_balance_type_id   in number
793            ,p_business_group_id in pay_balance_feeds_f.business_group_id%type
794            ,p_legislation_code  in pay_balance_feeds_f.legislation_code%type
795            ) is
796 --
797 l_proc        varchar2(72) := g_package||'chk_initial_feed_exists';
798 l_legislation_code per_business_groups.legislation_code%type;
799 
800 CURSOR csr_initial_feed_exist IS
801 SELECT 1
802 FROM   pay_balance_feeds_f         blf,
803        pay_input_values_f          inv,
804        pay_element_types_f         elt,
805        pay_element_classifications ec
806 WHERE  blf.balance_type_id   = p_balance_type_id
807 AND    blf.input_value_id    = inv.input_value_id
808 AND    inv.element_type_id   = elt.element_type_id
809 AND    nvl(elt.legislation_code
810           ,nvl(l_legislation_code, '~nvl~'))
811          = nvl(l_legislation_code, '~nvl~')
812 AND    nvl(elt.business_group_id
813           ,nvl(p_business_group_id, -1))
814          = nvl(p_business_group_id, -1)
815 AND    elt.classification_id = ec.classification_id
816 AND    ec.balance_initialization_flag ='Y';
817 
818 --
819    l_balance_initialization_flag varchar2(30);
820 --
821  begin
822 
823  hr_utility.set_location('Entering:'||l_proc, 5);
824 --
825 
826    l_legislation_code := nvl(p_legislation_code
827                            ,hr_api.return_legislation_code
828                                 (p_business_group_id));
829 
830    open csr_initial_feed_exist;
831    fetch csr_initial_feed_exist into l_balance_initialization_flag;
832    if csr_initial_feed_exist%found then
833      close csr_initial_feed_exist;
834      fnd_message.set_name('PAY','HR_7875_BAL_FEED_HAS_INIT_FEED');
835      fnd_message.raise_error;
836    else
837      close csr_initial_feed_exist;
838    end if;
839 --
840    hr_utility.set_location(' Leaving:'||l_proc, 10);
841 --
842  end chk_initial_feed_exists;
843 --
844 -- ---------------------------------------------------------------------------
845 -- |-------------------------------< chk_uom >--------------------------------|
846 -- ----------------------------------------------------------------------------
847 -- {Start Of Comments}
848 --
849 -- Description:
850 --   This procedure is used to ensure the UOM of the input value and the balance
851 --   must match ie. be in the same class
852 --
853 -- In Arguments:
854 --   The input value id and the balance type id for which feed is being created
855 --
856 -- Post Success:
857 --   Processing continues and balance feed is created.
858 --
859 -- Post Failure:
860 --   An application error is raised if the uom of the balance for which feed is
861 --   being created and that of the input value do not match.
862 --
863 -- {End Of Comments}
864 procedure chk_uom
865            (p_input_value_id  number
866 	   ,p_balance_type_id number
867 	   ,p_effective_date  date) is
868 --
869 l_proc        varchar2(72) := g_package||'chk_uom';
870 
871 CURSOR  csr_bal_uom IS
872 SELECT  pbt.balance_uom
873 FROM    pay_balance_types pbt
874 WHERE   pbt.balance_type_id = p_balance_type_id;
875 --
876 CURSOR  csr_ipv_uom IS
877 SELECT  piv.uom
878 FROM    pay_input_values_f piv
879 WHERE   piv.input_value_id = p_input_value_id
880 AND     p_effective_date between piv.effective_start_date
881 AND     piv.effective_end_date;
882 --
883    l_bal_uom varchar2(30);
884    l_ipv_uom varchar2(30);
885 --
886  begin
887 
888  hr_utility.set_location('Entering:'||l_proc, 5);
889 --
890    open csr_bal_uom;
891    fetch csr_bal_uom into l_bal_uom;
892    close csr_bal_uom;
893 --
894    open csr_ipv_uom;
895    fetch csr_ipv_uom into l_ipv_uom;
896    close csr_ipv_uom;
897 --
898    if substr(l_bal_uom,1,1) <> substr(l_ipv_uom,1,1) then
899       fnd_message.set_name('PAY','HR_6553_BAL_WRONG_UOM');
900       fnd_message.raise_error;
901    end if;
902 --
903    hr_utility.set_location(' Leaving:'||l_proc, 10);
904 --
905  end chk_uom;
906 -- ---------------------------------------------------------------------------
907 -- |--------------------------< chk_currency_match >--------------------------|
908 -- ----------------------------------------------------------------------------
909 -- {Start Of Comments}
910 --
911 -- Description:
912 --   This procedure is used to ensure the output currency code of the input
913 --   value that feeds the balance and the currency code of the balance must
914 --   match if the UOM of the balance is of type 'Money'
915 --
916 -- In Arguments:
917 --   The input value id and the balance type id for which feed is being created
918 --
919 -- Post Success:
920 --   Processing continues and balance feed is created.
921 --
922 -- Post Failure:
923 --   An application error is raised if the currency codes do not match
924 --
925 -- {End Of Comments}
926 
927 procedure chk_currency_match
928            (p_input_value_id number
929 	   ,p_balance_type_id number) is
930 --
931 l_proc        varchar2(72) := g_package||'chk_currency_match';
932 
933 CURSOR csr_balance_uom IS
934 SELECT balance_uom
935 FROM   pay_balance_types
936 WHERE  balance_type_id = p_balance_type_id;
937 
938 CURSOR csr_currency_match IS
939 SELECT 1
940 FROM   pay_balance_types pbt,
941        pay_input_values_f piv,
942        pay_element_types_f pet
943 WHERE  pbt.balance_type_id = p_balance_type_id
944 AND    piv.input_value_id = p_input_value_id
945 AND    pet.element_type_id = piv.element_type_id
946 AND    pbt.currency_code = pet.output_currency_code;
947 
948 --
949    l_exists number;
950    l_uom    varchar2(30);
951 --
952  begin
953 
954  hr_utility.set_location('Entering:'||l_proc, 5);
955 --
956    open csr_balance_uom;
957    fetch csr_balance_uom into l_uom;
958    if csr_balance_uom%found then
959       close csr_balance_uom;
960       if (l_uom = 'M') then
961          open csr_currency_match;
962          fetch csr_currency_match into l_exists;
963          if csr_currency_match%notfound then
964             close csr_currency_match;
965             fnd_message.set_name('PAY','PAY_33246_BF_CUR_MISMATCH');
966             fnd_message.raise_error;
967          else
968             close csr_currency_match;
969          end if;
970       end if;
971    else
972       close csr_balance_uom;
973    end if;
974 --
975    hr_utility.set_location(' Leaving:'||l_proc, 10);
976 
977 end chk_currency_match;
978 --
979 -- ---------------------------------------------------------------------------
980 -- |----------------------------< chk_scale_value >---------------------------|
981 -- ----------------------------------------------------------------------------
982 -- {Start Of Comments}
983 --
984 -- Description:
985 --   This procedure is used to ensure that valid value for Scale is entered for
986 --   the feed that is being created.
987 --
988 -- In Arguments:
989 --   The scale and the effective date on which feed is created or updated.
990 --
991 -- Post Success:
992 --   Processing continues and balance feed is created.
993 --
994 -- Post Failure:
995 --   An application error is raised if the value for scale does not exist in
996 --   hr_lookups table for lookup_type 'ADD_SUBTRACT'
997 --
998 -- {End Of Comments}
999 
1000 procedure chk_scale_value
1001            (p_scale          number
1002 	   ,p_input_value_id number
1003 	   ,p_effective_date date) is
1004 --
1005 l_proc        varchar2(72) := g_package||'chk_scale_value';
1006 
1007 --
1008    l_exists number;
1009 --
1010  begin
1011 
1012  hr_utility.set_location('Entering:'||l_proc, 5);
1013 --
1014    if hr_api.NOT_EXISTS_IN_HR_LOOKUPS
1015                     (p_effective_date => p_effective_date
1016 		    ,p_lookup_type    => 'ADD_SUBTRACT'
1017 		    ,p_lookup_code    => p_scale
1018 		    )
1019    then
1020      fnd_message.set_name('PAY','HR_52966_INVALID_LOOKUP');
1021      fnd_message.raise_error;
1022    end if;
1023 
1024    --
1025    hr_api.mandatory_arg_error
1026       (p_api_name       => l_proc
1027       ,p_argument       => 'input_value_id'
1028       ,p_argument_value => p_input_value_id
1029       );
1030    --
1031 
1032    -- Scale value must only be 1 when initial balance feed is being created
1033 
1034    if get_balance_init_flag (p_input_value_id => p_input_value_id)  and p_scale <> 1 then
1035         fnd_message.set_name('PAY','PAY_33242_BIFEED_INV_SCALE');
1036 	fnd_message.raise_error;
1037    end if;
1038 --
1039    hr_utility.set_location(' Leaving:'||l_proc, 10);
1040 
1041 end chk_scale_value;
1042 --
1043 -- ---------------------------------------------------------------------------
1044 -- |--------------------------< chk_bal_feed_unique >-------------------------|
1045 -- ----------------------------------------------------------------------------
1046 -- {Start Of Comments}
1047 --
1048 -- Description:
1049 --   This procedure is used to ensure that balance feeds are date-effectively
1050 --   unique ie. an input value cannot have two balance feeds to the same balance
1051 --   type at the same point in (date-effective) time
1052 --
1053 -- In Arguments:
1054 --   The balance_type_id, input_value_id, effective_start_date and
1055 --   effective_end_date on which feed is being created.
1056 --
1057 -- Post Success:
1058 --   Processing continues and balance feed is created.
1059 --
1060 -- Post Failure:
1061 --   An application error is raised if balance feed already exists for the input
1062 --   value id in the same date-effective time.
1063 --
1064 -- {End Of Comments}
1065 
1066 procedure chk_bal_feed_unique
1067            (p_input_value_id  number
1068 	   ,p_balance_type_id number
1069 	   ,p_effective_date  date) is
1070 --
1071 l_proc        varchar2(72) := g_package||'chk_bal_feed_unique';
1072 
1073 CURSOR csr_bal_feed_unique IS
1074 SELECT 1
1075 FROM   pay_balance_feeds_f
1076 WHERE  input_value_id = p_input_value_id
1077 AND    balance_type_id =p_balance_type_id
1078 AND    p_effective_date between effective_start_date and effective_end_date;
1079 
1080 --
1081    l_exists number;
1082 --
1083  begin
1084 
1085  hr_utility.set_location('Entering:'||l_proc, 5);
1086 --
1087    open csr_bal_feed_unique;
1088    fetch csr_bal_feed_unique into l_exists;
1089    if csr_bal_feed_unique%found then
1090      close csr_bal_feed_unique;
1091      fnd_message.set_name('PAY','HR_6109_BAL_UNI_FEED');
1092      fnd_message.raise_error;
1093    else
1094      close csr_bal_feed_unique;
1095    end if;
1096 --
1097    hr_utility.set_location(' Leaving:'||l_proc, 10);
1098 
1099 end chk_bal_feed_unique;
1100 --
1101 --
1102 -- ---------------------------------------------------------------------------
1103 -- |--------------------------< chk_feed_ipv_life >---------------------------|
1104 -- ----------------------------------------------------------------------------
1105 -- {Start Of Comments}
1106 --
1107 -- Description:
1108 --   This procedure is used to ensure that balance feeds cannot be created
1109 --   outside the life-time of the input value that feeds the balance.
1110 --
1111 -- In Arguments:
1112 --   The input_value_id, and the effective_date on which feed is being created.
1113 --
1114 -- Post Success:
1115 --   Processing continues and balance feed is created.
1116 --
1117 -- Post Failure:
1118 --   An application error is raised if balance feed being created is outside the
1119 --   the life-time of the input value that feeds the balance.
1120 --
1121 -- {End Of Comments}
1122 
1123 procedure chk_feed_ipv_life
1124            (p_input_value_id       number
1125 	   ,p_effective_date       date) is
1126 --
1127 l_proc        varchar2(72) := g_package||'chk_feed_ipv_life';
1128 
1129 CURSOR csr_feed_ipv_value IS
1130 SELECT 1
1131 FROM   pay_input_values_f
1132 WHERE  input_value_id = p_input_value_id
1133 AND    p_effective_date between effective_start_date and effective_end_date;
1134 --
1135   l_exists number;
1136 --
1137  begin
1138 
1139  hr_utility.set_location('Entering:'||l_proc, 5);
1140 --
1141    open csr_feed_ipv_value;
1142    fetch csr_feed_ipv_value into l_exists;
1143 
1144    if(csr_feed_ipv_value%notfound) then
1145       close csr_feed_ipv_value;
1146    --raise error since balance feed is outside the life-time of the input value
1147       fnd_message.set_name('PAY','HR_7048_BAL_FEED_PAST_INP_VAL');
1148       fnd_message.raise_error;
1149    else
1150       close csr_feed_ipv_value;
1151    end if;
1152 --
1153    hr_utility.set_location(' Leaving:'||l_proc, 10);
1154 
1155 end chk_feed_ipv_life;
1156 --
1157 -- ---------------------------------------------------------------------------
1158 -- |--------------------------< chk_dtupd_allowed >--------------------------|
1159 -- ---------------------------------------------------------------------------
1160 -- {Start Of Comments}
1161 --
1162 -- Description:
1163 --   This procedure is used to ensure that date effective update is not
1164 --   allowed for initial balance feeds.
1165 --
1166 -- In Arguments:
1167 --   Date track mode for the operation
1168 --
1169 -- Post Success:
1170 --   Processing continues and balance feed is updated.
1171 --
1172 -- Post Failure:
1173 --   An error is raised if date effective update is attempted on
1174 --   an initial balance feed.
1175 --
1176 -- {End Of Comments}
1177 
1178 procedure chk_dtupd_allowed
1179            (p_datetrack_mode  in varchar2
1180 	   ,p_input_value_id  in number
1181 	   ) is
1182 --
1183 l_proc        varchar2(72) := g_package||'chk_dtupd_allowed';
1184 --
1185  begin
1186 
1187  hr_utility.set_location('Entering:'||l_proc, 5);
1188 --
1189 
1190    --
1191    hr_api.mandatory_arg_error
1192       (p_api_name       => l_proc
1193       ,p_argument       => 'input_value_id'
1194       ,p_argument_value => p_input_value_id
1195       );
1196    --
1197 
1198    -- Date effective update must not be allowed for the initial balance feed.
1199    --
1200 
1201    if get_balance_init_flag (p_input_value_id => p_input_value_id) and
1202 		p_datetrack_mode <> hr_api.g_correction then
1203 
1204       fnd_message.set_name('PAY','PAY_33244_BIFEED_INV_ACTION');
1205       fnd_message.set_token('ACTION', 'UPDATE');
1206       fnd_message.set_token('MODE', p_datetrack_mode);
1207       fnd_message.raise_error;
1208 
1209    end if;
1210 --
1211    hr_utility.set_location(' Leaving:'||l_proc, 10);
1212 
1213 end chk_dtupd_allowed;
1214 --
1215 -- ---------------------------------------------------------------------------
1216 -- |--------------------------< chk_dtdel_allowed >--------------------------|
1217 -- ---------------------------------------------------------------------------
1218 -- {Start Of Comments}
1219 --
1220 -- Description:
1221 --   This procedure is used to ensure that date effective delete is not
1222 --   allowed for initial balance feeds.
1223 --
1224 -- In Arguments:
1225 --   Date track mode for the operation
1226 --
1227 -- Post Success:
1228 --   Processing continues and balance feed is deleted.
1229 --
1230 -- Post Failure:
1231 --   An error is raised if date effective delete is attempted on
1232 --   an initial balance feed.
1233 --
1234 -- {End Of Comments}
1235 
1236 procedure chk_dtdel_allowed
1237            (p_datetrack_mode  in varchar2
1238 	   ,p_input_value_id  in number
1239 	   ) is
1240 --
1241 l_proc        varchar2(72) := g_package||'chk_dtdel_allowed';
1242 --
1243  begin
1244 
1245  hr_utility.set_location('Entering:'||l_proc, 5);
1246 --
1247 
1248   --
1249   hr_api.mandatory_arg_error
1250       (p_api_name       => l_proc
1251       ,p_argument       => 'input_value_id'
1252       ,p_argument_value => p_input_value_id
1253       );
1254   --
1255 
1256   --
1257   -- Date effective delete must not be allowed for the initial balance feed.
1258   --
1259 
1260    if get_balance_init_flag( p_input_value_id => p_input_value_id)
1261            and p_datetrack_mode <> hr_api.g_zap then
1262 
1263       fnd_message.set_name('PAY','PAY_33244_BIFEED_INV_ACTION');
1264       fnd_message.set_token('ACTION', 'DELETE');
1265       fnd_message.set_token('MODE', p_datetrack_mode);
1266       fnd_message.raise_error;
1267 
1268    end if;
1269 --
1270    hr_utility.set_location(' Leaving:'||l_proc, 10);
1271 
1272 end chk_dtdel_allowed;
1273 --
1274 -- ----------------------------------------------------------------------------
1275 -- |---------------------------< insert_validate >----------------------------|
1276 -- ----------------------------------------------------------------------------
1277 Procedure insert_validate
1278   (p_rec                   in pay_pbf_shd.g_rec_type
1279   ,p_effective_date        in date
1280   ,p_datetrack_mode        in varchar2
1281   ,p_validation_start_date in date
1282   ,p_validation_end_date   in date
1283   ,p_initial_feed	   in boolean
1284   ,p_exist_run_result_warning	out nocopy boolean
1285   ) is
1286 --
1287   l_proc        varchar2(72) := g_package||'insert_validate';
1288   l_validation_end_date date;
1289 --
1290 Begin
1291   hr_utility.set_location('Entering:'||l_proc, 5);
1292 
1293   -- Clearing the Global variable since the record may have been changed.
1294   --
1295   g_balance_init_flag := NULL;
1296   --
1297 
1298   --
1299   -- Call all supporting business operations
1300   --
1301 
1302   chk_startup_action(true
1303                     ,p_rec.business_group_id
1304                     ,p_rec.legislation_code
1305                     );
1306   IF hr_startup_data_api_support.g_startup_mode
1307                      NOT IN ('GENERIC','STARTUP') THEN
1308      --
1309      -- Validate Important Attributes
1310      --
1311      hr_api.validate_bus_grp_id
1312        (p_business_group_id => p_rec.business_group_id
1313        ,p_associated_column1 => pay_pbf_shd.g_tab_nam
1314                                 || '.BUSINESS_GROUP_ID');
1315      --
1316      -- after validating the set of important attributes,
1317      -- if Multiple Message Detection is enabled and at least
1318      -- one error has been found then abort further validation.
1319      --
1320      hr_multi_message.end_validation_set;
1321   END IF;
1322   --
1323   -- Validate the following before actually inserting balance feed
1324   --
1325      pay_pbf_bus.chk_business_group_id
1326                  (p_business_group_id  => p_rec.business_group_id
1327 		 ,p_input_value_id     => p_rec.input_value_id
1328 		 ,p_effective_date     => p_effective_date
1329 		 );
1330   --
1331 
1332      pay_pbf_bus.chk_legislation_code
1333                  (p_legislation_code   => p_rec.legislation_code
1334 		 );
1335   --
1336 
1337      pay_pbf_bus.chk_input_value_id
1338                  (p_input_value_id     => p_rec.input_value_id
1339 		 ,p_business_group_id  => p_rec.business_group_id
1340 		 ,p_legislation_code    => p_rec.legislation_code
1341 		 );
1342   --
1343 
1344      pay_pbf_bus.chk_balance_type_id
1345                  (p_balance_type_id    => p_rec.balance_type_id
1346  		 ,p_business_group_id  => p_rec.business_group_id
1347 		 ,p_legislation_code    => p_rec.legislation_code
1348 		 );
1349   --
1350      pay_pbf_bus.chk_uom
1351                  (p_input_value_id    => p_rec.input_value_id
1352 		 ,p_balance_type_id   => p_rec.balance_type_id
1353 		 ,p_effective_date    => p_effective_date
1354 		 );
1355   --
1356 
1357      pay_pbf_bus.chk_currency_match
1358                  (p_input_value_id    => p_rec.input_value_id
1359 		 ,p_balance_type_id   => p_rec.balance_type_id
1360 		 );
1361   --
1362 
1363      pay_pbf_bus.chk_bal_feed_unique
1364                  (p_input_value_id       => p_rec.input_value_id
1365 		 ,p_balance_type_id      => p_rec.balance_type_id
1366 		 ,p_effective_date	 => p_effective_date
1367 		 );
1368   --
1369 
1370      pay_pbf_bus.chk_bal_class_exists
1371                  (p_balance_type_id         => p_rec.balance_type_id);
1372 
1373   --
1374 
1375      -- If trying to create an initial feed then check no other initial feed
1376      -- already exists
1377      if (get_balance_init_flag (p_input_value_id => p_rec.input_value_id) ) then
1378          pay_pbf_bus.chk_initial_feed_exists
1379                      (p_balance_type_id    => p_rec.balance_type_id
1380         	     ,p_business_group_id  => p_rec.business_group_id
1381 		     ,p_legislation_code    => p_rec.legislation_code
1382 		     );
1383      end if;
1384 
1385   --
1386 
1387      pay_pbf_bus.chk_feed_ipv_life
1388                  (p_input_value_id	    => p_rec.input_value_id
1389 		 ,p_effective_date	    => p_effective_date
1390 		 );
1391 
1392   --
1393      -- When creating a balance feed derive the end date
1394      -- ie. input value may be date effectively deleted in
1395      -- the future or there are future balance feeds.
1396      l_validation_end_date := hr_balance_feeds.bal_feed_end_date
1397                                   (null,
1398                                    p_rec.balance_type_id,
1399                                    p_rec.input_value_id,
1400                                    p_effective_date,
1401                                    p_validation_start_date);
1402 
1403      if hr_balance_feeds.bf_chk_proc_run_results
1404           ('BALANCE_FEED',
1405            'INSERT',
1406            null, null, null, null, null,
1407            p_rec.input_value_id,
1408            p_validation_start_date,
1409            l_validation_end_date) then
1410 
1411 	   fnd_message.set_name('PAY','HR_7876_BAL_FEED_RESULTS_EXIST');
1412            p_exist_run_result_warning :=TRUE;
1413 
1414      end if;
1415 
1416      -- When initial balance feed is being created, the effective end date must be
1417      -- hr_api.g_eot.
1418 
1419      if get_balance_init_flag (p_input_value_id => p_rec.input_value_id)
1420                and l_validation_end_date <> hr_api.g_eot then
1421         fnd_message.set_name('PAY','PAY_33243_BIFEED_INV_EDATE');
1422 	fnd_message.raise_error;
1423      end if;
1424 
1425   --
1426   -- Validate Dependent Attributes
1427   --
1428      pay_pbf_bus.chk_scale_value
1429                  (p_scale          => p_rec.scale
1430 		 ,p_input_value_id => p_rec.input_value_id
1431 		 ,p_effective_date => p_effective_date
1432 		 );
1433   --
1434   hr_utility.set_location(' Leaving:'||l_proc, 10);
1435 
1436 End insert_validate;
1437 --
1438 -- ----------------------------------------------------------------------------
1439 -- |---------------------------< update_validate >----------------------------|
1440 -- ----------------------------------------------------------------------------
1441 Procedure update_validate
1442   (p_rec                     in pay_pbf_shd.g_rec_type
1443   ,p_effective_date          in date
1444   ,p_datetrack_mode          in varchar2
1445   ,p_validation_start_date   in date
1446   ,p_validation_end_date     in date
1447   ,p_exist_run_result_warning out nocopy boolean
1448   ) is
1449 --
1450   l_proc        varchar2(72) := g_package||'update_validate';
1451 --
1452 Begin
1453   hr_utility.set_location('Entering:'||l_proc, 5);
1454   --
1455 
1456   -- Clearing the Global variable since the record may have been changed.
1457   --
1458   g_balance_init_flag := NULL;
1459   --
1460 
1461   chk_dtupd_allowed ( p_datetrack_mode => p_datetrack_mode
1462                      ,p_input_value_id => p_rec.input_value_id );
1463 
1464   --
1465   -- Call all supporting business operations
1466   --
1467   -- Check that the fields which cannot be updated have not be changed
1468 
1469   chk_non_updateable_args(p_effective_date   => p_effective_date
1470 		           ,p_rec            => p_rec
1471         		   );
1472 
1473   chk_startup_action(false
1474                     ,p_rec.business_group_id
1475                     ,p_rec.legislation_code
1476                     );
1477   IF hr_startup_data_api_support.g_startup_mode
1478                      NOT IN ('GENERIC','STARTUP') THEN
1479      --
1480      -- Validate Important Attributes
1481      --
1482      hr_api.validate_bus_grp_id
1483        (p_business_group_id => p_rec.business_group_id
1484        ,p_associated_column1 => pay_pbf_shd.g_tab_nam
1485                                 || '.BUSINESS_GROUP_ID');
1486      --
1487      -- After validating the set of important attributes,
1488      -- if Multiple Message Detection is enabled and at least
1489      -- one error has been found then abort further validation.
1490      --
1491      hr_multi_message.end_validation_set;
1492   END IF;
1493   --
1494   --
1495   -- Validate the following before actually updating balance feed
1496   --
1497     pay_pbf_bus.chk_bal_class_exists
1498       (p_balance_type_id         => p_rec.balance_type_id);
1499   --
1500     if hr_balance_feeds.bf_chk_proc_run_results
1501          ('BALANCE_FEED'
1502          ,'UPDATE_DELETE'
1503          ,null, null, null
1504          ,p_rec.balance_feed_id
1505          ,null, null
1506          ,p_validation_start_date
1507          ,p_validation_end_date
1508          ) then
1509        fnd_message.set_name('PAY','HR_7876_BAL_FEED_RESULTS_EXIST');
1510        p_exist_run_result_warning :=TRUE;
1511     end if;
1512   --
1513   -- Validate Dependent Attributes
1514   --
1515        pay_pbf_bus.chk_scale_value
1516                  (p_scale          => p_rec.scale
1517 		 ,p_input_value_id => p_rec.input_value_id
1518 		 ,p_effective_date => p_effective_date
1519 		 );
1520   --
1521   -- Call the datetrack update integrity operation
1522   --
1523   dt_update_validate
1524     (p_datetrack_mode                 => p_datetrack_mode
1525     ,p_validation_start_date          => p_validation_start_date
1526     ,p_validation_end_date            => p_validation_end_date
1527     );
1528   --
1529   --
1530   hr_utility.set_location(' Leaving:'||l_proc, 10);
1531 
1532 End update_validate;
1533 --
1534 -- ----------------------------------------------------------------------------
1535 -- |---------------------------< delete_validate >----------------------------|
1536 -- ----------------------------------------------------------------------------
1537 Procedure delete_validate
1538   (p_rec                    in pay_pbf_shd.g_rec_type
1539   ,p_effective_date         in date
1540   ,p_datetrack_mode         in varchar2
1541   ,p_validation_start_date  in date
1542   ,p_validation_end_date    in date
1543   ,p_exist_run_result_warning out nocopy boolean
1544   ) is
1545 --
1546   l_proc        varchar2(72) := g_package||'delete_validate';
1547   l_validation_end_date date;
1548 --
1549 Begin
1550   hr_utility.set_location('Entering:'||l_proc, 5);
1551   --
1552 
1553   -- Clearing the Global variable since the record may have been changed.
1554   --
1555   g_balance_init_flag := NULL;
1556   --
1557 
1558   --
1559 
1560   chk_dtdel_allowed ( p_datetrack_mode => p_datetrack_mode
1561                      ,p_input_value_id => p_rec.input_value_id);
1562 
1563   chk_startup_action(false
1564                     ,pay_pbf_shd.g_old_rec.business_group_id
1565                     ,pay_pbf_shd.g_old_rec.legislation_code
1566                     );
1567 
1568   IF hr_startup_data_api_support.g_startup_mode
1569                      NOT IN ('GENERIC','STARTUP') THEN
1570      --
1571      -- Validate Important Attributes
1572      --
1573      --
1574      -- After validating the set of important attributes,
1575      -- if Multiple Message Detection is enabled and at least
1576      -- one error has been found then abort further validation.
1577      --
1578      hr_multi_message.end_validation_set;
1579   END IF;
1580   --
1581   -- Call all supporting business operations
1582   --
1583 
1584       -- If extending the lifetime of a balance feed derive the end date ie. input
1585      -- value may be date effectively deleted in the future or there are future
1586      -- future balance feeds.
1587      if (p_datetrack_mode = 'FUTURE_CHANGE' or
1588         (p_datetrack_mode = 'DELETE_NEXT_CHANGE' and
1589          p_validation_end_date = hr_api.g_eot)) then
1590        l_validation_end_date := hr_balance_feeds.bal_feed_end_date
1591                                     (p_rec.balance_feed_id,
1592                                      p_rec.balance_type_id,
1593                                      p_rec.input_value_id,
1594                                      p_effective_date,
1595                                      p_validation_start_date);
1596      end if;
1597 
1598      if hr_balance_feeds.bf_chk_proc_run_results
1599           ('BALANCE_FEED',
1600            'UPDATE_DELETE',
1601            null, null, null,
1602            p_rec.balance_feed_id,
1603            null, null,
1604            p_validation_start_date,
1605            l_validation_end_date) then
1606 
1607 	   fnd_message.set_name('PAY','HR_7876_BAL_FEED_RESULTS_EXIST');
1608            p_exist_run_result_warning :=TRUE;
1609 
1610      end if;
1611  --
1612 
1613      pay_pbf_bus.chk_bal_class_exists
1614                  (p_balance_type_id         => p_rec.balance_type_id);
1615 
1616   --
1617   dt_delete_validate
1618     (p_datetrack_mode                   => p_datetrack_mode
1619     ,p_validation_start_date            => p_validation_start_date
1620     ,p_validation_end_date              => p_validation_end_date
1621     ,p_balance_feed_id                  => p_rec.balance_feed_id
1622     );
1623   --
1624   hr_utility.set_location(' Leaving:'||l_proc, 10);
1625 
1626 End delete_validate;
1627 --
1628 --
1629 --  ---------------------------------------------------------------------------
1630 --  |-----------------------< get_balance_init_flag >-------------------------|
1631 --  ---------------------------------------------------------------------------
1632 --
1633 Function get_balance_init_flag
1634   (p_input_value_id  in  number)
1635   Return boolean Is
1636   --
1637   -- Declare cursor
1638   --
1639   cursor csr_balance_init_flag is
1640 	SELECT 1
1641 	        FROM   pay_input_values_f     inv,
1642 		       pay_element_types_f    elt,
1643 		       pay_element_classifications ec
1644 		WHERE  inv.input_value_id = p_input_value_id
1645 		AND    inv.element_type_id = elt.element_type_id
1646 		AND    elt.classification_id = ec.classification_id
1647 		AND    ec.balance_initialization_flag = 'Y';
1648 
1649   --
1650   -- Declare local variables
1651   --
1652   l_exists varchar2(1);
1653   l_proc  varchar2(72)  :=  g_package||'get_balance_init_flag';
1654   --
1655 Begin
1656   --
1657   hr_utility.set_location('Entering:'|| l_proc, 10);
1658   --
1659     if g_balance_init_flag is null then
1660 
1661 	open  csr_balance_init_flag;
1662 	fetch csr_balance_init_flag into l_exists;
1663 
1664 	if csr_balance_init_flag%found then
1665 		g_balance_init_flag := true;
1666 	else
1667 		g_balance_init_flag := false;
1668 	end if;
1669 
1670 	close csr_balance_init_flag;
1671 
1672     end if;
1673 
1674   --
1675   hr_utility.set_location(' Leaving:'|| l_proc, 40);
1676   return g_balance_init_flag;
1677   --
1678 End get_balance_init_flag;
1679 --
1680 --
1681 end pay_pbf_bus;