DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_EVALUATE_RATE_PROFILES

Source


1 package body BEN_EVALUATE_RATE_PROFILES as
2 /* $Header: benrtprf.pkb 120.11.12020000.3 2012/07/03 12:55:29 amnaraya ship $ */
3 --------------------------------------------------------------------------------
4 --------------------------------------------------------------------------------
5 --
6 --    Global exception handler
7 --
8 g_criteria_failed exception;
9 g_package        varchar2(80) := 'ben_evaluate_rate_profiles';
10 --
11 -- ---------------------------------------------------------------
12 --    People Group
13 -- ---------------------------------------------------------------
14 --
15 procedure check_people_group
16   (p_vrbl_rt_prfl_id      in number
17   ,p_business_group_id    in number
18   ,p_effective_date       in date
19   ,p_lf_evt_ocrd_dt       in date
20   ,p_people_group_id      in varchar2) is
21   --
22   l_inst_set ben_rt_prfl_cache.g_pg_inst_tbl;
23   l_inst_count number;
24   l_ok boolean := false;
25   l_rows_found boolean := false;
26   l_seg_ok     boolean := true;
27   --
28   l_const   varchar2(50) := hr_api.g_varchar2;
29   --
30    cursor c_ppl_grp is
31    select ppg.people_group_id , ppg.segment1 ,ppg.segment2 ,ppg.segment3 ,ppg.segment4 ,
32           ppg.segment5  , ppg.segment6  ,ppg.segment7  ,ppg.segment8  ,ppg.segment9 , ppg.segment10 ,
33           ppg.segment11 , ppg.segment12 ,ppg.segment13 ,ppg.segment14 ,ppg.segment15 ,
34           ppg.segment16 , ppg.segment17 ,ppg.segment18 ,ppg.segment19 ,ppg.segment20 ,
35           ppg.segment21 , ppg.segment22 ,ppg.segment23 ,ppg.segment24 ,ppg.segment25 ,
36           ppg.segment26 , ppg.segment27 ,ppg.segment28 ,ppg.segment29 ,ppg.segment30
37    from pay_people_groups ppg
38    where ppg.people_group_id =  p_people_group_id ;
39 
40    --
41    l_ppl_grp_rec  c_ppl_grp%ROWTYPE ;
42    l_match        boolean ;
43 --
44 begin
45   --
46   -- Get the data from the cache.
47   --
48   ben_rt_prfl_cache.get_rt_prfl_cache
49     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
50     ,p_effective_date    => p_effective_date
51     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
52     ,p_business_group_id => p_business_group_id
53     ,p_inst_set          => l_inst_set
54     ,p_inst_count        => l_inst_count);
55   --
56   if l_inst_count > 0 then
57     --
58     -- Data found. Loop through to see if excld flag is on or off.
59     l_rows_found := true;
60     --
61     for i in l_inst_set.first..l_inst_set.last loop
62 --
63 -- case 1 : id's of profile and ppl grp match, indicating perfect match.
64 --
65       l_ok := l_inst_set(i).people_group_id = p_people_group_id;
66       --
67       if l_ok is null or p_people_group_id is null then
68       --
69         l_ok := false;
70       --
71       end if;
72       --
73       if l_ok and l_inst_set(i).excld_flag = 'N' then
74         --
75         exit;
76         --
77       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
78         --
79         -- raise g_criteria_failed;
80         l_seg_ok := false;
81         l_ok := false;
82         exit ;
83         --
84       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
85         l_ok := true ;
86         -- exit ;
87         --
88       elsif l_inst_set(i).excld_flag = 'N' then
89         --
90         l_rows_found := true;
91         --
92       end if;
93       --
94 --
95 -- case 2 : id's do not match so search for a match.
96 --
97 
98        open c_ppl_grp ;
99        fetch c_ppl_grp into l_ppl_grp_rec ;
100        close c_ppl_grp ;
101 
102 	-- Bug 3241479 If there are multiple segments enabled
103 	-- we need to return false even if one condition fails.
104 	-- appending l_seg_ok to all the conditions.
105 
106 	-- To enter we are first setting the l_seg_ok to true.
107 
108        -- Start of Bug 3241479
109        l_seg_ok := true;
110 	  if l_seg_ok and l_inst_set(i).segment1 is not null then
111        	  if l_inst_set(i).segment1 <> nvl(l_ppl_grp_rec.segment1,l_const)  then
112              l_seg_ok := false ;
113           else
114              l_seg_ok := true;
115           end if;
116        end if ;
117 
118        if  l_seg_ok and l_inst_set(i).segment2 is not null then
119           if l_inst_set(i).segment2 <> nvl(l_ppl_grp_rec.segment2,l_const) then
120 	       l_seg_ok := false ;
121 	  else
122 	       l_seg_ok := true;
123           end if;
124        end if ;
125 
126 
127        if  l_seg_ok and l_inst_set(i).segment3 is not null then
128 	  if l_inst_set(i).segment3 <> nvl(l_ppl_grp_rec.segment3,l_const) then
129              l_seg_ok := false ;
130           else
131              l_seg_ok := true;
132           end if;
133        end if ;
134 
135 
136        if  l_seg_ok and l_inst_set(i).segment4 is not null then
137        	  if l_inst_set(i).segment4 <> nvl(l_ppl_grp_rec.segment4,l_const) then
138              l_seg_ok := false ;
139           else
140              l_seg_ok := true;
141           end if;
142        end if ;
143 
144        if  l_seg_ok and l_inst_set(i).segment5 is not null then
145           if l_inst_set(i).segment5 <> nvl(l_ppl_grp_rec.segment5,l_const) then
146 	       l_seg_ok := false ;
147 	  else
148 	       l_seg_ok := true;
149           end if;
150        end if ;
151 
152 
153        if  l_seg_ok and l_inst_set(i).segment6 is not null then
154 	  if l_inst_set(i).segment6 <> nvl(l_ppl_grp_rec.segment6,l_const) then
155              l_seg_ok := false ;
156           else
157              l_seg_ok := true;
158           end if;
159        end if ;
160 
161        if  l_seg_ok and l_inst_set(i).segment7 is not null then
162        	  if l_inst_set(i).segment7 <> nvl(l_ppl_grp_rec.segment7,l_const) then
163              l_seg_ok := false ;
164           else
165              l_seg_ok := true;
166           end if;
167        end if ;
168 
169        if  l_seg_ok and l_inst_set(i).segment8 is not null then
170           if l_inst_set(i).segment8 <> nvl(l_ppl_grp_rec.segment8,l_const) then
171 	       l_seg_ok := false ;
172 	  else
173 	       l_seg_ok := true;
174           end if;
175        end if ;
176 
177 
178        if  l_seg_ok and l_inst_set(i).segment9 is not null then
179 	  if l_inst_set(i).segment9 <> nvl(l_ppl_grp_rec.segment9,l_const) then
180              l_seg_ok := false ;
181           else
182              l_seg_ok := true;
183           end if;
184        end if ;
185 
186        if  l_seg_ok and l_inst_set(i).segment10 is not null then
187 	 if l_inst_set(i).segment10 <> nvl(l_ppl_grp_rec.segment10,l_const) then
188 	    l_seg_ok := false ;
189 	 else
190 	    l_seg_ok := true;
191 	 end if;
192        end if ;
193 
194        if  l_seg_ok and l_inst_set(i).segment11 is not null then
195            if l_inst_set(i).segment11 <> nvl(l_ppl_grp_rec.segment11,l_const) then
196        	       l_seg_ok := false ;
197        	   else
198        	       l_seg_ok := true;
199            end if;
200        end if ;
201 
202 
203        if  l_seg_ok and l_inst_set(i).segment12 is not null then
204        	  if l_inst_set(i).segment12 <> nvl(l_ppl_grp_rec.segment12,l_const) then
205                l_seg_ok := false ;
206           else
207                l_seg_ok := true;
208           end if;
209        end if ;
210 
211 
212        if  l_seg_ok and l_inst_set(i).segment13 is not null then
213        	  if l_inst_set(i).segment13 <> nvl(l_ppl_grp_rec.segment13,l_const) then
214              l_seg_ok := false ;
215           else
216              l_seg_ok := true;
217           end if;
218        end if ;
219 
220        if  l_seg_ok and l_inst_set(i).segment14 is not null then
221           if l_inst_set(i).segment14 <> nvl(l_ppl_grp_rec.segment14,l_const) then
222 	       l_seg_ok := false ;
223 	  else
224 	       l_seg_ok := true;
225           end if;
226        end if ;
227 
228 
229        if  l_seg_ok and l_inst_set(i).segment15 is not null then
230 	  if l_inst_set(i).segment15 <> nvl(l_ppl_grp_rec.segment15,l_const) then
231              l_seg_ok := false ;
232           else
233              l_seg_ok := true;
234           end if;
235        end if ;
236 
237 
238        if  l_seg_ok and l_inst_set(i).segment16 is not null then
239        	  if l_inst_set(i).segment16 <> nvl(l_ppl_grp_rec.segment16,l_const) then
240              l_seg_ok := false ;
241           else
242              l_seg_ok := true;
243           end if;
244        end if ;
245 
246        if  l_seg_ok and l_inst_set(i).segment17 is not null then
247           if l_inst_set(i).segment17 <> nvl(l_ppl_grp_rec.segment17,l_const) then
248 	       l_seg_ok := false ;
249 	  else
250 	       l_seg_ok := true;
251           end if;
252        end if ;
253 
254 
255        if l_seg_ok and l_inst_set(i).segment18 is not null then
256 	  if l_inst_set(i).segment18 <> nvl(l_ppl_grp_rec.segment18,l_const) then
257              l_seg_ok := false ;
258           else
259              l_seg_ok := true;
260           end if;
261        end if ;
262 
263        if l_seg_ok and  l_inst_set(i).segment19 is not null then
264        	  if l_inst_set(i).segment19 <> nvl(l_ppl_grp_rec.segment19,l_const) then
265              l_seg_ok := false ;
266           else
267              l_seg_ok := true;
268           end if;
269        end if ;
270 
271        if l_seg_ok and  l_inst_set(i).segment20 is not null then
272           if l_inst_set(i).segment20 <> nvl(l_ppl_grp_rec.segment20,l_const) then
273 	       l_seg_ok := false ;
274 	  else
275 	       l_seg_ok := true;
276           end if;
277        end if ;
278 
279 
280        if l_seg_ok and  l_inst_set(i).segment21 is not null then
281 	  if l_inst_set(i).segment21 <> nvl(l_ppl_grp_rec.segment21,l_const) then
282              l_seg_ok := false ;
283           else
284              l_seg_ok := true;
285           end if;
286        end if ;
287 
288        if l_seg_ok and l_inst_set(i).segment22 is not null then
289 	 if l_inst_set(i).segment22 <> nvl(l_ppl_grp_rec.segment22,l_const) then
290 	    l_seg_ok := false ;
291 	 else
292 	    l_seg_ok := true;
293 	 end if;
294        end if ;
295 
296        if l_seg_ok and l_inst_set(i).segment23 is not null then
297            if l_inst_set(i).segment23 <> nvl(l_ppl_grp_rec.segment23,l_const) then
298        	       l_seg_ok := false ;
299        	   else
300        	       l_seg_ok := true;
301            end if;
302        end if ;
303 
304 
305        if l_seg_ok and l_inst_set(i).segment24 is not null then
306        	  if l_inst_set(i).segment24 <> nvl(l_ppl_grp_rec.segment24,l_const) then
307                l_seg_ok := false ;
308           else
309                l_seg_ok := true;
310           end if;
311        end if ;
312 
313 
314        if l_seg_ok and l_inst_set(i).segment25 is not null then
315 	  if l_inst_set(i).segment25 <> nvl(l_ppl_grp_rec.segment25,l_const) then
316              l_seg_ok := false ;
317           else
318              l_seg_ok := true;
319           end if;
320        end if ;
321 
322        if l_seg_ok and l_inst_set(i).segment26 is not null then
323        	  if l_inst_set(i).segment26 <> nvl(l_ppl_grp_rec.segment26,l_const) then
324              l_seg_ok := false ;
325           else
326              l_seg_ok := true;
327           end if;
328        end if ;
329 
330        if l_seg_ok and l_inst_set(i).segment27 is not null then
331           if l_inst_set(i).segment27 <> nvl(l_ppl_grp_rec.segment27,l_const) then
332 	       l_seg_ok := false ;
333 	  else
334 	       l_seg_ok := true;
335           end if;
336        end if ;
337 
338 
339        if l_seg_ok and l_inst_set(i).segment28 is not null then
340 	  if l_inst_set(i).segment28 <> nvl(l_ppl_grp_rec.segment28,l_const) then
341              l_seg_ok := false ;
342           else
343              l_seg_ok := true;
344           end if;
345        end if ;
346 
347        if l_seg_ok and l_inst_set(i).segment29 is not null then
348 	 if l_inst_set(i).segment29 <> nvl(l_ppl_grp_rec.segment29,l_const) then
349 	    l_seg_ok := false ;
350 	 else
351 	    l_seg_ok := true;
352 	 end if;
353        end if ;
354 
355        if l_seg_ok and l_inst_set(i).segment30 is not null then
356            if l_inst_set(i).segment30 <> nvl(l_ppl_grp_rec.segment30,l_const) then
357        	       l_seg_ok := false ;
358        	   else
359        	       l_seg_ok := true;
360            end if;
361        end if ;
362 
363        -- End of bug 3241479
364 
365        if l_inst_set(i).excld_flag = 'Y' and l_seg_ok and not l_ok then
366        	   l_ok := false ;
367        	   l_seg_ok := false;
368            exit;
369        elsif l_inst_set(i).excld_flag = 'Y' and l_seg_ok and l_ok then
370        	   l_ok := false ;
371        	   l_seg_ok := false;
372            exit;
373        elsif l_seg_ok and l_inst_set(i).excld_flag = 'N' then
374        	   exit;
375        end if;
376        --
377 
378     end loop;
379     --
380   end if;
381   --
382   if l_rows_found and not l_ok and not l_seg_ok then
383     --
384     raise g_criteria_failed;
385     --
386   end if;
387   --
388 end check_people_group;
389 --
390 -- ---------------------------------------------------------------
391 --    Formula
392 -- ---------------------------------------------------------------
393 --
394 procedure check_rules
395   (p_vrbl_rt_prfl_id      in number
396   ,p_business_group_id    in number
397   ,p_effective_date       in date
398   ,p_lf_evt_ocrd_dt       in date
399   ,p_assignment_id        in number
400   ,p_organization_id      in number
401   ,p_pgm_id               in number
402   ,p_pl_id                in number
403   ,p_pl_typ_id            in number
404   ,p_opt_id               in number
405   ,p_ler_id               in number
406   ,p_acty_base_rt_id      in number default null
407   ,p_elig_per_elctbl_chc_id      in number default null
408   ,p_jurisdiction_code    in varchar2)
409 is
410   --
411   l_outputs           ff_exec.outputs_t;
412   l_inst_set ben_rt_prfl_cache.g_rl_inst_tbl;
413   l_inst_count number;
414   l_ok boolean := false;
415   l_rows_found boolean := false;
416   l_ben_vapro_rul_cond varchar2(30) := 'A' ;
417   --
418 begin
419   --
420   -- Get the data from the cache.
421   --
422   ben_rt_prfl_cache.get_rt_prfl_cache
423     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
424     ,p_effective_date    => p_effective_date
425     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
426     ,p_business_group_id => p_business_group_id
427     ,p_inst_set          => l_inst_set
428     ,p_inst_count        => l_inst_count);
429   --
430   if l_inst_count > 0 then
431      --- get the  profile setup it can be either AND or OR # 2508757
432      l_ben_vapro_rul_cond :=     fnd_profile.value('BEN_VAPRO_RL_COND');
433 
434      hr_utility.set_location(' l_ben_vapro_rul_cond ' || l_ben_vapro_rul_cond, 757 );
435     --
436     for i in l_inst_set.first..l_inst_set.last loop
437        --
438         hr_utility.set_location(' p_vrbl_rt_prfl_id ' || p_vrbl_rt_prfl_id, 757 );
439        l_outputs := benutils.formula
440                      (p_formula_id        => l_inst_set(i).formula_id
441                      ,p_effective_date    => nvl(p_lf_evt_ocrd_dt
442                                                 ,p_effective_date)
443                      ,p_business_group_id => p_business_group_id
444                      ,p_assignment_id     => p_assignment_id
445                      ,p_organization_id   => p_organization_id
446                      ,p_pgm_id            => p_pgm_id
447                      ,p_pl_id             => p_pl_id
448                      ,p_pl_typ_id         => p_pl_typ_id
449                      ,p_opt_id            => p_opt_id
450                      ,p_ler_id            => p_ler_id
451                      ,p_acty_base_rt_id   => p_acty_base_rt_id
452                      ,p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id
453                      ,p_jurisdiction_code => p_jurisdiction_code
454                      ,p_param1             => 'BEN_VPF_I_VRBL_RT_PRFL_ID'
455                      ,p_param1_value       => to_char(nvl(p_vrbl_rt_prfl_id, -1))
456                      -- FONM
457                      ,p_param2             => 'BEN_IV_RT_STRT_DT'
458                      ,p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt)
459                      ,p_param3             => 'BEN_IV_CVG_STRT_DT'
460                      ,p_param3_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt)
461                      );
462        -- if the profile is AND and one of the rule fails  #2508757
463        if nvl(l_ben_vapro_rul_cond,'A')  = 'A' then
464 
465           hr_utility.set_location(' result  ' || l_outputs(l_outputs.first).value, 758 );
466           if l_outputs(l_outputs.first).value <> 'Y' then
467              raise g_criteria_failed;
468           End if ;
469        Else
470           -- if the profile is OR and  one of the rule pass then exit
471           hr_utility.set_location(' result  ' || l_outputs(l_outputs.first).value, 759 );
472          if l_outputs(l_outputs.first).value = 'Y' then
473             --
474             exit;
475             --
476          end if;
477        End if ;
478       --
479     end loop;
480     -- if the profile is OR and  exit with value 'N' raise the error
481     if  nvl(l_ben_vapro_rul_cond,'A')  = 'O' and l_outputs(l_outputs.first).value <> 'Y' then
482         hr_utility.set_location(' error on OR and N ', 757 );
483         raise g_criteria_failed;
484     end if ;
485     --
486   end if;
487   --
488 end check_rules;
489 --
490 -- ---------------------------------------------------------------
491 --    Tobacco check
492 -- ---------------------------------------------------------------
493 --
494 procedure check_tobacco
495   (p_vrbl_rt_prfl_id      in number
496   ,p_business_group_id    in number
497   ,p_effective_date       in date
498   ,p_lf_evt_ocrd_dt       in date
499   ,p_tobacco              in varchar2) is
500   --
501   l_inst_set ben_rt_prfl_cache.g_tbco_inst_tbl;
502   l_inst_count number;
503   l_ok boolean := false;
504   l_rows_found boolean := false;
505   --
506 begin
507   --
508   -- Get the data from the cache.
509   --
510   ben_rt_prfl_cache.get_rt_prfl_cache
511     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
512     ,p_effective_date    => p_effective_date
513     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
514     ,p_business_group_id => p_business_group_id
515     ,p_inst_set          => l_inst_set
516     ,p_inst_count        => l_inst_count);
517   --
518   if l_inst_count > 0 then
519     --
520     -- Data found. Loop through to see if excld flag is on or off.
521     l_rows_found := true;
522     --
523     for i in l_inst_set.first..l_inst_set.last loop
524       --
525       l_ok := l_inst_set(i).uses_tbco_flag = nvl(p_tobacco,'-1');
526       --
527       --Removing the code for the bug : 6525934.
528      /* if l_ok is null or p_tobacco is null then
529       --
530         l_ok := false;
531       --
532       end if; */
533       --
534       if l_ok and l_inst_set(i).excld_flag = 'N' then
535         --
536         exit;
537         --
538       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
539         -- Bug 2100564
540         l_ok := true ;
541         --exit ;
542         --
543       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
544         --
545         -- raise ben_evaluate_rate_profiles.g_profile_failed;
546         l_ok := false;
547         exit ;
548         --
549       elsif l_inst_set(i).excld_flag = 'N' then
550         --
551         l_rows_found := true;
552         --
553       end if;
554       --
555     end loop;
556     --
557   end if;
558   --
559   if l_rows_found and not l_ok then
560     --
561     raise ben_evaluate_rate_profiles.g_profile_failed;
562     --
563   end if;
564   --
565 end check_tobacco;
566 --
567 -- ---------------------------------------------------------------
568 --    Gender check
569 -- ---------------------------------------------------------------
570 --
571 procedure check_gender
572   (p_vrbl_rt_prfl_id      in number
573   ,p_business_group_id    in number
574   ,p_effective_date       in date
575   ,p_lf_evt_ocrd_dt       in date
576   ,p_sex                  in varchar2) is
577   --
578   l_inst_set ben_rt_prfl_cache.g_gndr_inst_tbl;
579   l_inst_count number;
580   l_ok boolean := false;
581   l_rows_found boolean := false;
582   --
583 begin
584   --
585   -- Get the data from the cache.
586   --
587   ben_rt_prfl_cache.get_rt_prfl_cache
588     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
589     ,p_effective_date    => p_effective_date
590     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
591     ,p_business_group_id => p_business_group_id
592     ,p_inst_set          => l_inst_set
593     ,p_inst_count        => l_inst_count);
594   --
595   if l_inst_count > 0 then
596     --
597     -- Data found. Loop through to see if excld flag is on or off.
598     --
599     l_rows_found := true;
600     --
601     for i in l_inst_set.first..l_inst_set.last loop
602       --
603       hr_utility.set_location(' l_inst_set(i).gndr_cd '||l_inst_set(i).gndr_cd , 12);
604       hr_utility.set_location('  l_inst_set(i).excld_flag '|| l_inst_set(i).excld_flag ,12);
605       --
606       l_ok := l_inst_set(i).gndr_cd = p_sex;
607       --
608       if l_ok is null or p_sex is null then
609       --
610         l_ok := false;
611       --
612       end if;
613       --
614       if l_ok and l_inst_set(i).excld_flag = 'N' then
615         --
616         exit;
617         --
618       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
619         --
620         -- raise ben_evaluate_rate_profiles.g_profile_failed;
621         l_ok := false ;
622         exit ;
623         --
624       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
625         -- Bug 2100564
626         l_ok := true ;
627         --exit ;
628         --
629       elsif l_inst_set(i).excld_flag = 'N' then
630         --
631         l_rows_found := true;
632         --
633       end if;
634       --
635     end loop;
636     --
637   end if;
638   --
639   if l_rows_found and not l_ok then
640     --
641     raise ben_evaluate_rate_profiles.g_profile_failed;
642     --
643   end if;
644   --
645 end check_gender;
646 --
647 -- ---------------------------------------------------------------
648 --    Disabled Code check
649 -- ---------------------------------------------------------------
650 --
651 
652 procedure check_dsbld_cd
653   (p_vrbl_rt_prfl_id      in number
654   ,p_business_group_id    in number
655   ,p_effective_date       in date
656   ,p_lf_evt_ocrd_dt       in date
657   ,p_dsbld_cd             in varchar2) is
658   --
659   l_inst_set ben_rt_prfl_cache.g_dsbld_inst_tbl;
660   l_inst_count number;
661   l_ok boolean := false;
662   l_rows_found boolean := false;
663   --
664 begin
665   --
666   -- Get the data from the cache.
667   --
668   ben_rt_prfl_cache.get_rt_prfl_cache
669     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
670     ,p_effective_date    => p_effective_date
671     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
672     ,p_business_group_id => p_business_group_id
673     ,p_inst_set          => l_inst_set
674     ,p_inst_count        => l_inst_count);
675   --
676   if l_inst_count > 0 then
677     --
678     -- Data found. Loop through to see if excld flag is on or off.
679     l_rows_found := true;
680     --
681     for i in l_inst_set.first..l_inst_set.last loop
682       --
683       l_ok := l_inst_set(i).dsbld_cd = p_dsbld_cd;
684       --
685       if l_ok is null or p_dsbld_cd is null then
686       --
687         l_ok := false;
688       --
689       end if;
690       --
691       if l_ok and l_inst_set(i).excld_flag = 'N' then
692         --
693         exit;
694         --
695       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
696         --
697         -- raise ben_evaluate_rate_profiles.g_profile_failed;
698         l_ok := false;
699         exit ;
700         --
701       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
702         -- Bug 2100564
703         l_rows_found := true;
704         l_ok := true ;
705         --exit ;
706         --
707       elsif l_inst_set(i).excld_flag = 'N' then
708         --
709         l_rows_found := true;
710         --
711       end if;
712       --
713     end loop;
714     --
715   end if;
716   --
717   if l_rows_found and not l_ok then
718     --
719     raise ben_evaluate_rate_profiles.g_profile_failed;
720     --
721   end if;
722   --
723 end check_dsbld_cd;
724 --
725 -- ---------------------------------------------------------------
726 --    Bargaining Unit check
727 -- ---------------------------------------------------------------
728 --
729 procedure check_brgng_unit
730   (p_vrbl_rt_prfl_id       in number
731   ,p_business_group_id     in number
732   ,p_effective_date        in date
733   ,p_lf_evt_ocrd_dt        in date
734   ,p_bargaining_unit_code  in varchar2) is
735   --
736   l_inst_set ben_rt_prfl_cache.g_brgng_inst_tbl;
737   l_inst_count number;
738   l_ok boolean := false;
739   l_rows_found boolean := false;
740   --
741 begin
742   --
743   -- Get the data from the cache.
744   --
745   ben_rt_prfl_cache.get_rt_prfl_cache
746     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
747     ,p_effective_date    => p_effective_date
748     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
749     ,p_business_group_id => p_business_group_id
750     ,p_inst_set          => l_inst_set
751     ,p_inst_count        => l_inst_count);
752   --
753   if l_inst_count > 0 then
754     --
755     -- Data found. Loop through to see if excld flag is on or off.
756     --
757         l_rows_found := true;
758     --
759     for i in l_inst_set.first..l_inst_set.last loop
760       --
761       l_ok := l_inst_set(i).brgng_unit_cd = p_bargaining_unit_code;
762       --
763       if l_ok is null or p_bargaining_unit_code is null then
764       --
765         l_ok := false;
766       --
767       end if;
768       --
769       if l_ok and l_inst_set(i).excld_flag = 'N' then
770         --
771         exit;
772         --
773       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
774         --
775         -- raise g_criteria_failed;
776         l_ok := false;
777         exit ;
778         --
779       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
780         -- Bug 2100564
781         l_ok := true ;
782         -- exit ;
783         --
784       elsif l_inst_set(i).excld_flag = 'N' then
785         --
786         l_rows_found := true;
787         --
788       end if;
789       --
790     end loop;
791     --
792   end if;
793   --
794   if l_rows_found and not l_ok then
795     --
796     raise g_criteria_failed;
797     --
798   end if;
799   --
800 end check_brgng_unit;
801 --
802 -- ---------------------------------------------------------------
803 --  Benefits group check.
804 -- ---------------------------------------------------------------
805 --
806 procedure check_benefits_grp
807   (p_vrbl_rt_prfl_id   in number
808   ,p_person_id         in number
809   ,p_business_group_id in number
810   ,p_effective_date    in date
811   ,p_lf_evt_ocrd_dt    in date
812   ,p_benefit_group_id  in number) is
813   --
814   l_inst_set ben_rt_prfl_cache.g_bnfgrp_inst_tbl;
815   l_inst_count number;
816   l_ok boolean := false;
817   l_rows_found boolean := false;
818   --
819 begin
820   --
821   -- Get the data from the cache.
822   --
823   ben_rt_prfl_cache.get_rt_prfl_cache
824     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
825     ,p_effective_date    => p_effective_date
826     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
827     ,p_business_group_id => p_business_group_id
828     ,p_inst_set          => l_inst_set
829     ,p_inst_count        => l_inst_count);
830   --
831   if l_inst_count > 0 then
832     --
833     -- Data found. Loop through to see if excld flag is on or off.
834     --
835     l_rows_found := true;
836     --
837     for i in l_inst_set.first..l_inst_set.last loop
838       --
839       l_ok := l_inst_set(i).benfts_grp_id = p_benefit_group_id;
840       --
841       if l_ok is null or p_benefit_group_id is null then
842       --
843         l_ok := false;
844       --
845       end if;
846       --
847       if l_ok and l_inst_set(i).excld_flag = 'N' then
848         --
849         exit;
850         --
851       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
852         --
853         -- raise ben_evaluate_rate_profiles.g_profile_failed;
854         l_ok := false;
855         exit;
856         --
857       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
858         -- Bug 2100564
859         l_rows_found := true;
860         l_ok := true ;
861         -- exit ;
862         --
863       elsif l_inst_set(i).excld_flag = 'N' then
864         --
865         l_rows_found := true;
866         --
867       end if;
868       --
869     end loop;
870     --
871   end if;
872   --
873   if l_rows_found and not l_ok then
874     --
875     raise ben_evaluate_rate_profiles.g_profile_failed;
876     --
877   end if;
878   --
879 end check_benefits_grp;
880 --
881 -- --------------------------------------------------
882 --  Employee status check.
883 -- --------------------------------------------------
884 --
885 procedure check_ee_stat
886   (p_vrbl_rt_prfl_id           in number
887   ,p_person_id                 in number
888   ,p_business_group_id         in number
889   ,p_effective_date            in date
890   ,p_lf_evt_ocrd_dt            in date
891   ,p_assignment_status_type_id in number) is
892   --
893   l_inst_set ben_rt_prfl_cache.g_eestat_inst_tbl;
894   l_inst_count number;
895   l_ok boolean := false;
896   l_rows_found boolean := false;
897   --
898 begin
899   --
900   -- Get the data from the cache.
901   --
902   ben_rt_prfl_cache.get_rt_prfl_cache
903     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
904     ,p_effective_date    => p_effective_date
905     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
906     ,p_business_group_id => p_business_group_id
907     ,p_inst_set          => l_inst_set
908     ,p_inst_count        => l_inst_count);
909   --
910   if l_inst_count > 0 then
911     --
912     -- Data found. Loop through to see if excld flag is on or off.
913     --
914     l_rows_found := true;
915     --
916     for i in l_inst_set.first..l_inst_set.last loop
917       --
918       l_ok := l_inst_set(i).assignment_status_type_id = p_assignment_status_type_id;
919       --
920       if l_ok is null or p_assignment_status_type_id is null then
921       --
922         l_ok := false;
923       --
924       end if;
925       --
926       if l_ok and l_inst_set(i).excld_flag = 'N' then
927         --
928         exit;
929         --
930       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
931         --
932         -- raise g_criteria_failed;
933         l_ok := false;
934         exit ;
935         --
936       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
937         -- Bug 2100564
938         l_rows_found := true;
939         l_ok := true ;
940         --exit ;
941         --
942       elsif l_inst_set(i).excld_flag = 'N' then
943         --
944         l_rows_found := true;
945         --
946       end if;
947       --
948     end loop;
949     --
950   end if;
951   --
952   if l_rows_found and not l_ok then
953     --
954     raise g_criteria_failed;
955     --
956   end if;
957   --
958 end check_ee_stat;
959 --
960 -- ---------------------------------------------------------------
961 --  Full time/part time check.
962 -- ---------------------------------------------------------------
963 --
964 procedure check_fl_tm_pt
965   (p_vrbl_rt_prfl_id     in number
966   ,p_person_id           in number
967   ,p_business_group_id   in number
968   ,p_effective_date      in date
969   ,p_lf_evt_ocrd_dt      in date
970   ,p_employment_category in varchar2) is
971   --
972   l_inst_set ben_rt_prfl_cache.g_ftpt_inst_tbl;
973   l_inst_count number;
974   l_ok boolean := false;
975   l_rows_found boolean := false;
976   --
977 begin
978   --
979   -- Get the data from the cache.
980   --
981   ben_rt_prfl_cache.get_rt_prfl_cache
982     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
983     ,p_effective_date    => p_effective_date
984     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
985     ,p_business_group_id => p_business_group_id
986     ,p_inst_set          => l_inst_set
987     ,p_inst_count        => l_inst_count);
988   --
989   if l_inst_count > 0 then
990     --
991     -- Data found. Loop through to see if excld flag is on or off.
992     --
993     l_rows_found := true;
994     --
995     for i in l_inst_set.first..l_inst_set.last loop
996       --
997       l_ok := l_inst_set(i).fl_tm_pt_tm_cd = p_employment_category;
998       --
999       if l_ok is null or p_employment_category is null then
1000       --
1001         l_ok := false;
1002       --
1003       end if;
1004       --
1005       if l_ok and l_inst_set(i).excld_flag = 'N' then
1006         --
1007         exit;
1008         --
1009       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1010         --
1011         -- raise g_criteria_failed;
1012         l_ok := false;
1013         exit ;
1014         --
1015       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1016         -- Bug 2100564
1017         l_rows_found := true;
1018         l_ok := true ;
1019         -- exit ;
1020         --
1021       elsif l_inst_set(i).excld_flag = 'N' then
1022         --
1023         l_rows_found := true;
1024         --
1025       end if;
1026       --
1027     end loop;
1028     --
1029   end if;
1030   --
1031   if l_rows_found and not l_ok then
1032     --
1033     raise g_criteria_failed;
1034     --
1035   end if;
1036   --
1037 end check_fl_tm_pt;
1038 --
1039 -- ------------------------------------------------------
1040 --  Grade check
1041 -- ------------------------------------------------------
1042 --
1043 procedure check_grade
1044   (p_vrbl_rt_prfl_id   in number
1045   ,p_person_id         in number
1046   ,p_business_group_id in number
1047   ,p_effective_date    in date
1048   ,p_lf_evt_ocrd_dt    in date
1049   ,p_grade_id          in number) is
1050   --
1051   l_inst_set ben_rt_prfl_cache.g_grd_inst_tbl;
1052   l_inst_count number;
1053   l_ok boolean := false;
1054   l_rows_found boolean := false;
1055   --
1056 begin
1057   --
1058   -- Get the data from the cache.
1059   --
1060   ben_rt_prfl_cache.get_rt_prfl_cache
1061     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1062     ,p_effective_date    => p_effective_date
1063     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1064     ,p_business_group_id => p_business_group_id
1065     ,p_inst_set          => l_inst_set
1066     ,p_inst_count        => l_inst_count);
1067   --
1068   if l_inst_count > 0 then
1069     --
1070     -- Data found. Loop through to see if excld flag is on or off.
1071     --
1072     l_rows_found := true;
1073     --
1074     for i in l_inst_set.first..l_inst_set.last loop
1075       --
1076       l_ok := l_inst_set(i).grade_id = p_grade_id;
1077       --
1078       if l_ok is null or p_grade_id is null then
1079       --
1080         l_ok := false;
1081       --
1082       end if;
1083       --
1084       if l_ok and l_inst_set(i).excld_flag = 'N' then
1085         --
1086         exit;
1087         --
1088       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1089         --
1090         -- raise g_criteria_failed;
1091         l_ok := false;
1092         exit ;
1093         --
1094       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1095         -- Bug 2100564
1096         l_ok := true ;
1097         --exit ;
1098         --
1099       elsif l_inst_set(i).excld_flag = 'N' then
1100         --
1101         l_rows_found := true;
1102         --
1103       end if;
1104       --
1105     end loop;
1106     --
1107   end if;
1108   --
1109   if l_rows_found and not l_ok then
1110     --
1111     raise g_criteria_failed;
1112     --
1113   end if;
1114   --
1115 end check_grade;
1116 --
1117 -- -----------------------------------------------------------------
1118 --  Percent fulltime check.
1119 -- -----------------------------------------------------------------
1120 --
1121 procedure check_pct_fltm
1122   (p_vrbl_rt_prfl_id         in number
1123   ,p_person_id               in number
1124   ,p_business_group_id       in number
1125   ,p_effective_date          in date
1126   ,p_lf_evt_ocrd_dt          in date
1127   ,p_opt_id                  in number default null
1128   ,p_plip_id                 in number default null
1129   ,p_pl_id                   in number default null
1130   ,p_pgm_id                  in number default null) is
1131   --
1132   l_ok                 boolean := false;
1133   l_opt_id             number(15);
1134   l_rt_pct_fl_tm_val   ben_elig_per_f.rt_pct_fl_tm_val%type := null;
1135 
1136   cursor c_pct_ft is
1137     select bep.rt_pct_fl_tm_val
1138     from   ben_elig_per_f bep,
1139            ben_per_in_ler pil
1140     where  bep.person_id = p_person_id
1141     and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1142     and nvl(bep.pl_id,-1) = nvl(p_pl_id,-1)
1143     and    p_effective_date
1144            between bep.effective_start_date
1145            and     bep.effective_end_date
1146     and pil.per_in_ler_id(+)=bep.per_in_ler_id
1147     and pil.business_group_id(+)=bep.business_group_id+0
1148     and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1149      or pil.per_in_ler_stat_cd is null                  -- outer join condition
1150     );
1151 
1152   cursor c_pct_ft_opt  is
1153   select epo.rt_pct_fl_tm_val
1154     from ben_elig_per_f bep, ben_elig_per_opt_f epo,
1155          ben_per_in_ler pil
1156    where bep.person_id = p_person_id
1157      and bep.elig_per_id = epo.elig_per_id
1158      and epo.opt_id = p_opt_id
1159      and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1160      and nvl(bep.pl_id,-1) = nvl(p_pl_id,-1)
1161      and p_effective_date between epo.effective_start_date
1162                               and epo.effective_end_date
1163      and p_effective_date between bep.effective_start_date
1164                               and bep.effective_end_date
1165      and pil.per_in_ler_id(+)=bep.per_in_ler_id
1166      and pil.business_group_id(+)=bep.business_group_id
1167      and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1168       or  pil.per_in_ler_stat_cd is null);                -- outer join condition
1169 
1170   cursor c_pct_ft_plip  is
1171   select epo.rt_pct_fl_tm_val
1172     from ben_elig_per_f bep, ben_elig_per_opt_f epo,
1173          ben_per_in_ler pil
1174    where bep.person_id = p_person_id
1175      and bep.elig_per_id = epo.elig_per_id
1176      and epo.opt_id = p_opt_id
1177      and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1178      and nvl(bep.plip_id,-1) = nvl(p_plip_id,-1)
1179      and p_effective_date between epo.effective_start_date
1180                               and epo.effective_end_date
1181      and p_effective_date between bep.effective_start_date
1182                               and bep.effective_end_date
1183      and pil.per_in_ler_id(+)=bep.per_in_ler_id
1184      and pil.business_group_id(+)=bep.business_group_id
1185      and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1186       or  pil.per_in_ler_stat_cd is null);                -- outer join condition
1187 
1188   l_inst_set ben_rt_prfl_cache.g_pctft_inst_tbl;
1189   l_inst_count number;
1190   l_rows_found boolean := false;
1191   l_mx_pct_val    number ;
1192   --
1193 begin
1194   hr_utility.set_location ('Entering check_pct_fltm',01);
1195   hr_utility.set_location ('opt' || p_opt_id  ,01);
1196   hr_utility.set_location ('plip'|| p_plip_id  ,01);
1197   hr_utility.set_location ('pl'  || p_pl_id   ,01);
1198   hr_utility.set_location ('pgm' || p_pgm_id ,01);
1199   --
1200 
1201   if p_opt_id is not null then
1202     -- Look for oiplip first.  oiplip elig_per_opt rows hang off plip elig_per
1203     -- records.
1204     if p_plip_id is not null then
1205       open c_pct_ft_plip;
1206       fetch c_pct_ft_plip into l_rt_pct_fl_tm_val;
1207       hr_utility.set_location ('oiplip '||to_char(l_rt_pct_fl_tm_val),01);
1208       close c_pct_ft_plip;
1209     end if;
1210 
1211     -- If there is no oiplip, check for oipl
1212     if l_rt_pct_fl_tm_val is null then
1213       open c_pct_ft_opt;
1214       fetch c_pct_ft_opt into l_rt_pct_fl_tm_val;
1215       hr_utility.set_location ('oipl '||to_char(l_rt_pct_fl_tm_val),01);
1216       close c_pct_ft_opt;
1217     end if;
1218   else
1219      -- just look for pl elig per record.
1220      open c_pct_ft;
1221      fetch c_pct_ft into l_rt_pct_fl_tm_val;
1222      hr_utility.set_location ('pl '||to_char(l_rt_pct_fl_tm_val),01);
1223      close c_pct_ft;
1224   end if;
1225 
1226   -- Get the rate profile data from the cache.
1227   --
1228   ben_rt_prfl_cache.get_rt_prfl_cache
1229     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1230     ,p_effective_date    => p_effective_date
1231     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1232     ,p_business_group_id => p_business_group_id
1233     ,p_inst_set          => l_inst_set
1234     ,p_inst_count        => l_inst_count);
1235   --
1236   if l_inst_count > 0 then
1237     --
1238     -- Data found. Loop through to see if excld flag is on or off.
1239     --
1240     l_rows_found := true;
1241     --
1242     for i in l_inst_set.first..l_inst_set.last loop
1243       --
1244       --
1245       --- if there is fraction compare in differtn way
1246       -- Bug 2101937 fixes
1247       l_mx_pct_val := l_inst_set(i).mx_pct_val ;
1248       --
1249       if ( l_inst_set(i).mx_pct_val <> trunc(l_inst_set(i).mx_pct_val)  OR
1250            l_inst_set(i).mn_pct_val <> trunc(l_inst_set(i).mn_pct_val) ) then
1251         -- Decimal Case
1252         l_mx_pct_val := l_inst_set(i).mx_pct_val + 0.000000001 ;
1253         --
1254       else
1255         --
1256         l_mx_pct_val := l_inst_set(i).mx_pct_val + 1 ;
1257         --
1258       end if;
1259       --
1260       hr_utility.set_location('if' , 610) ;
1261       --
1262       l_ok := ((l_rt_pct_fl_tm_val >=
1263                  l_inst_set(i).mn_pct_val
1264                  and  l_rt_pct_fl_tm_val < l_mx_pct_val )
1265                or
1266                (l_inst_set(i).no_mn_pct_val_flag = 'Y' and
1267                 l_rt_pct_fl_tm_val < l_mx_pct_val )
1268                or
1269                (l_rt_pct_fl_tm_val >= l_inst_set(i).mn_pct_val and
1270                 l_inst_set(i).no_mx_pct_val_flag = 'Y'));
1271 
1272       if l_ok Then
1273          hr_utility.set_location('success ' ,610);
1274       end if ;
1275       --
1276       if l_ok is null or l_rt_pct_fl_tm_val is null then
1277       --
1278         l_ok := false;
1279       --
1280       end if;
1281       --
1282       if l_ok and l_inst_set(i).excld_flag = 'N' then
1283         --
1284         exit;
1285         --
1286       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1287         --
1288         -- raise ben_evaluate_rate_profiles.g_profile_failed;
1289         l_ok := false;
1290         exit ;
1291         --
1292       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1293         -- Bug 2100564
1294         l_ok := true ;
1295         --exit ;
1296         --
1297       elsif l_inst_set(i).excld_flag = 'N' then
1298         --
1299         l_rows_found := true;
1300         --
1301       end if;
1302       --
1303     end loop;
1304     --
1305   end if;
1306   --
1307   if l_rows_found and not l_ok then
1308     --
1309     raise ben_evaluate_rate_profiles.g_profile_failed;
1310     --
1311   end if;
1312   --
1313 end check_pct_fltm;
1314 --
1315 -- ------------------------------
1316 -- Assignment set
1317 -- ------------------------------
1318 --
1319 
1320 procedure check_asnt_set
1321         (p_VRBL_RT_PRFL_ID   in number,
1322          p_business_group_id in number,
1323          p_person_id         in number,
1324          p_lf_evt_ocrd_dt    in date,
1325          p_effective_date    in date) is
1326   --
1327   l_proc          varchar2(100):=g_package||'check_asnt_set';
1328   l_inst_dets     ben_rt_asnt_cache.g_rt_asnt_inst_tbl;
1329   l_inst_count    number;
1330   l_insttorrw_num binary_integer;
1331   l_ok            boolean := false;
1332   l_rows_found    boolean := false;
1333   l_ass_rec       per_all_assignments_f%rowtype;
1334   l_outputs       ff_exec.outputs_t;
1335   l_include_flag  varchar2(80);
1336   --
1337 begin
1338   --
1339   hr_utility.set_location('Entering: '||l_proc, 10);
1340   --
1341   -- Getting eligibility profile compensation level by eligibility profile
1342   --
1343   ben_rt_asnt_cache.get_rt_asnt_cache
1344     (p_effective_date    => p_effective_date
1345     ,p_business_group_id => p_business_group_id
1346     ,p_VRBL_RT_PRFL_ID   => p_VRBL_RT_PRFL_ID
1347     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1348     ,p_inst_set          => l_inst_dets
1349     ,p_inst_count        => l_inst_count);
1350   --
1351    hr_utility.set_location('Int COunt'||l_inst_count,11);
1352   if l_inst_count > 0 then
1353     --
1354     ben_person_object.get_object(p_person_id => p_person_id,
1355                                  p_rec       => l_ass_rec);
1356     --
1357     for l_count in l_inst_dets.first .. l_inst_dets.last loop
1358       --
1359       -- Error if someone hasn't built the formula as this will
1360       -- cause an error. In this case kill the run.
1361       --
1362       hr_utility.set_location('COunt'||l_count,11);
1363       if l_inst_dets(l_count).formula_id is null then
1364         --
1365         fnd_message.set_name('BEN','BEN_92460_ASS_SET_FORMULA');
1366         fnd_message.set_token('PROC',l_proc);
1367         fnd_message.set_token('VARIABLE_RT_PRFL_ID',to_char(p_VRBL_RT_PRFL_ID));
1368         fnd_message.raise_error;
1369         --
1370       end if;
1371       --
1372       hr_utility.set_location('Bef Formula',11);
1373       l_outputs := benutils.formula
1374                       (p_formula_id     => l_inst_dets(l_count).formula_id,
1375                        p_assignment_id  => l_ass_rec.assignment_id,
1376                        p_effective_date => nvl(p_lf_evt_ocrd_dt, p_effective_date), -- FONM
1377                        p_param1             => 'BEN_IV_RT_STRT_DT',
1378                        p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
1379                        p_param2             => 'BEN_IV_CVG_STRT_DT',
1380                        p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt));
1381       --
1382       begin
1383         --
1384         if l_outputs(l_outputs.first).name = 'INCLUDE_FLAG' then
1385           --
1386           hr_utility.set_location('Incl Flag ',11);
1387           l_include_flag := l_outputs(l_outputs.first).value;
1388           --
1389         else
1390           --
1391           -- Account for cases where formula returns an unknown
1392           -- variable name
1393           --
1394           fnd_message.set_name('BEN','BEN_92310_FORMULA_RET_PARAM_');
1395           fnd_message.set_token('PROC',l_proc);
1396           fnd_message.set_token('FORMULA',l_inst_dets(l_count).formula_id);
1397           fnd_message.set_token('PARAMETER',l_outputs(l_outputs.first).name);
1398           fnd_message.raise_error;
1399           --
1400         end if;
1401         --
1402         -- Code for type casting errors from formula return variables
1403         --
1404       exception
1405         --
1406         when others then
1407           --
1408           fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
1409           fnd_message.set_token('PROC',l_proc);
1410           fnd_message.set_token('FORMULA',l_inst_dets(l_count).formula_id);
1411           fnd_message.set_token('PARAMETER',l_outputs(l_outputs.first).name);
1412           fnd_message.raise_error;
1413           --
1414       end;
1415       --
1416       hr_utility.set_location('Include Flag '||l_include_flag,10);
1417       --
1418       l_ok := nvl((l_include_flag = 'Y'),FALSE);
1419       --if l_ok is null then
1420       --  l_ok:=false;
1421       --end if;
1422       --
1423       if l_ok and l_inst_dets(l_count).excld_flag = 'N' then
1424         --
1425         exit;
1426         --
1427       elsif l_ok and l_inst_dets(l_count).excld_flag = 'Y' then
1428         --
1429         l_rows_found := true;
1430         l_ok := false;
1431         exit;
1432         --
1433       elsif (not l_ok) and l_inst_dets(l_count).excld_flag = 'Y' then
1434         --
1435         l_rows_found := true;
1436         l_ok := true;
1437         -- exit;
1438         --
1439       elsif l_inst_dets(l_count).excld_flag = 'N' then
1440         --
1441         l_rows_found := true;
1442         --
1443       end if;
1444       --
1445     end loop;
1446     --
1447   end if;
1448   --
1449   if l_rows_found and
1450     not l_ok then
1451     --
1452     fnd_message.set_name('BEN','BEN_92459_ASS_SET_PRFL_FAIL');
1453     hr_utility.set_location('Criteria Failed: '||l_proc,20);
1454     raise g_criteria_failed;
1455     --
1456   end if;
1457   --
1458   hr_utility.set_location('Leaving :'||l_proc,20);
1459   --
1460 end check_asnt_set;
1461 -- --------------------------------------------------------------------
1462 --  Hours worked in a period check.
1463 -- --------------------------------------------------------------------
1464 --
1465 procedure check_hrs_wkd
1466   (p_vrbl_rt_prfl_id        in number
1467   ,p_person_id              in number
1468   ,p_business_group_id      in number
1469   ,p_effective_date         in date
1470   ,p_lf_evt_ocrd_dt         in date
1471   ,p_opt_id                 in number default null
1472   ,p_plip_id                in number default null
1473   ,p_pl_id                  in number default null
1474   ,p_pgm_id                 in number default null) is
1475   --
1476   l_ok                 boolean := false;
1477   l_opt_id             number(15);
1478   l_rt_hrs_wkd_val     ben_elig_per_f.rt_hrs_wkd_val%type;
1479 
1480 
1481   cursor c_hrs_wkd  is
1482   select bep.rt_hrs_wkd_val
1483     from ben_elig_per_f bep,
1484          ben_per_in_ler pil
1485    where bep.person_id = p_person_id
1486      and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1487      and nvl(bep.pl_id,-1) = nvl(p_pl_id,-1)
1488      and p_effective_date between bep.effective_start_date
1489                               and bep.effective_end_date
1490      and pil.per_in_ler_id(+)=bep.per_in_ler_id
1491      and pil.business_group_id(+)=bep.business_group_id
1492      and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1493       or  pil.per_in_ler_stat_cd is null);                -- outer join condition
1494 
1495   cursor c_hrs_wkd_opt  is
1496   select epo.rt_hrs_wkd_val
1497     from ben_elig_per_f bep, ben_elig_per_opt_f epo,
1498          ben_per_in_ler pil
1499    where bep.person_id = p_person_id
1500      and bep.elig_per_id = epo.elig_per_id
1501      and epo.opt_id = p_opt_id
1502      and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1503      and nvl(bep.pl_id,-1) = nvl(p_pl_id,-1)
1504      and p_effective_date between epo.effective_start_date
1505                               and epo.effective_end_date
1506      and p_effective_date between bep.effective_start_date
1507                               and bep.effective_end_date
1508      and pil.per_in_ler_id(+)=bep.per_in_ler_id
1509      and pil.business_group_id(+)=bep.business_group_id
1510      and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1511       or  pil.per_in_ler_stat_cd is null);                -- outer join condition
1512 
1513   cursor c_hrs_wkd_plip  is
1514   select epo.rt_hrs_wkd_val
1515     from ben_elig_per_f bep, ben_elig_per_opt_f epo,
1516          ben_per_in_ler pil
1517    where bep.person_id = p_person_id
1518      and bep.elig_per_id = epo.elig_per_id
1519      and epo.opt_id = p_opt_id
1520      and nvl(bep.pgm_id,-1) = nvl(p_pgm_id,-1)
1521      and nvl(bep.plip_id,-1) = nvl(p_plip_id,-1)
1522      and p_effective_date between epo.effective_start_date
1523                               and epo.effective_end_date
1524      and p_effective_date between bep.effective_start_date
1525                               and bep.effective_end_date
1526      and pil.per_in_ler_id(+)=bep.per_in_ler_id
1527      and pil.business_group_id(+)=bep.business_group_id
1528      and (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
1529       or  pil.per_in_ler_stat_cd is null);                -- outer join condition
1530 
1531   l_inst_set ben_rt_prfl_cache.g_hrswkd_inst_tbl;
1532   l_inst_count number;
1533   l_rows_found boolean := false;
1534   l_mx_hrs_num number ;
1535 
1536 begin
1537   hr_utility.set_location ('Entering check_hrs_wkd',01);
1538   if p_opt_id is not null then
1539     -- Look for oiplip first.  oiplip elig_per_opt rows hang off plip elig_per
1540     -- records.
1541     if p_plip_id is not null then
1542       open c_hrs_wkd_plip;
1543       fetch c_hrs_wkd_plip into l_rt_hrs_wkd_val;
1544       hr_utility.set_location ('oiplip '||to_char(l_rt_hrs_wkd_val),01);
1545       close c_hrs_wkd_plip;
1546     end if;
1547 
1548     -- If there is no oiplip, check for oipl
1549     if l_rt_hrs_wkd_val is null then
1550       open c_hrs_wkd_opt;
1551       fetch c_hrs_wkd_opt into l_rt_hrs_wkd_val;
1552       hr_utility.set_location ('oipl '||to_char(l_rt_hrs_wkd_val),01);
1553       close c_hrs_wkd_opt;
1554     end if;
1555   else
1556      -- just look for pl elig per record.
1557      open c_hrs_wkd;
1558      fetch c_hrs_wkd into l_rt_hrs_wkd_val;
1559       hr_utility.set_location ('pl '||to_char(l_rt_hrs_wkd_val),01);
1560      close c_hrs_wkd;
1561   end if;
1562 
1563 
1564   --
1565   -- Get the rate profile data from the cache.
1566   --
1567   ben_rt_prfl_cache.get_rt_prfl_cache
1568     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1569     ,p_effective_date    => p_effective_date
1570     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1571     ,p_business_group_id => p_business_group_id
1572     ,p_inst_set          => l_inst_set
1573     ,p_inst_count        => l_inst_count);
1574 
1575   if l_inst_count > 0 then
1576     --
1577     -- Data found. Loop through to see if excld flag is on or off.
1578     --
1579     l_rows_found := true;
1580     --
1581     for i in l_inst_set.first..l_inst_set.last loop
1582       hr_utility.set_location ('hrx criteria'||l_rt_hrs_wkd_val  || ' min:'||
1583       to_char(l_inst_set(i).mn_hrs_num)||' mx:'||to_char(l_inst_set(i).mx_hrs_num),610.2);
1584       --
1585       -- Bug 2101937 fixes
1586       l_mx_hrs_num := l_inst_set(i).mx_hrs_num ;
1587       --
1588       if ( l_inst_set(i).mx_hrs_num <> trunc(l_inst_set(i).mx_hrs_num)  OR
1589            l_inst_set(i).mn_hrs_num <> trunc(l_inst_set(i).mn_hrs_num) ) then
1590         -- Decimal Case
1591         l_mx_hrs_num := l_inst_set(i).mx_hrs_num + 0.000000001 ;
1592         --
1593       else
1594         --
1595         l_mx_hrs_num := l_inst_set(i).mx_hrs_num + 1 ;
1596         --
1597       end if;
1598       --
1599 
1600       l_ok := ((l_rt_hrs_wkd_val >=  l_inst_set(i).mn_hrs_num
1601                 and l_rt_hrs_wkd_val <  l_mx_hrs_num )
1602                 or
1603                (l_inst_set(i).no_mn_hrs_wkd_flag = 'Y' and
1604                 l_rt_hrs_wkd_val <  l_mx_hrs_num )
1605                 or
1606                (l_rt_hrs_wkd_val >= l_inst_set(i).mn_hrs_num and
1607                 l_inst_set(i).no_mx_hrs_wkd_flag = 'Y'));
1608       --
1609       if l_ok is null or l_rt_hrs_wkd_val is null then
1610         l_ok := false;
1611       end if;
1612 
1613       if l_ok and l_inst_set(i).excld_flag = 'N' then
1614         exit;
1615       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1616         --
1617         -- raise ben_evaluate_rate_profiles.g_profile_failed;
1618         l_ok := false;
1619         exit ;
1620         --
1621       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1622         -- Bug 2100564
1623         l_ok := true ;
1624         --exit ;
1625         --
1626       elsif l_inst_set(i).excld_flag = 'N' then
1627         l_rows_found := true;
1628       end if;
1629 
1630     end loop;
1631 
1632   end if;
1633 
1634   if l_rows_found and not l_ok then
1635     raise ben_evaluate_rate_profiles.g_profile_failed;
1636   end if;
1637 
1638 end check_hrs_wkd;
1639 --
1640 -- ----------------------------------------------------------
1641 --  Labor union membership check.
1642 -- ----------------------------------------------------------
1643 procedure check_lbr_union
1644   (p_vrbl_rt_prfl_id          in number
1645   ,p_person_id                in number
1646   ,p_business_group_id        in number
1647   ,p_effective_date           in date
1648   ,p_lf_evt_ocrd_dt           in date
1649   ,p_labour_union_member_flag in varchar2) is
1650   --
1651   l_inst_set ben_rt_prfl_cache.g_lbrmmbr_inst_tbl;
1652   l_inst_count number;
1653   l_ok boolean := false;
1654   l_rows_found boolean := false;
1655   --
1656 begin
1657   --
1658   -- Get the data from the cache.
1659   --
1660   ben_rt_prfl_cache.get_rt_prfl_cache
1661     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1662     ,p_effective_date    => p_effective_date
1663     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1664     ,p_business_group_id => p_business_group_id
1665     ,p_inst_set          => l_inst_set
1666     ,p_inst_count        => l_inst_count);
1667   --
1668   if l_inst_count > 0 then
1669     --
1670     -- Data found. Loop through to see if excld flag is on or off.
1671     --
1672     l_rows_found := true;
1673     --
1674     for i in l_inst_set.first..l_inst_set.last loop
1675       --
1676       l_ok := l_inst_set(i).lbr_mmbr_flag = p_labour_union_member_flag;
1677       --
1678       if l_ok is null or p_labour_union_member_flag is null then
1679       --
1680         l_ok := false;
1681       --
1682       end if;
1683       --
1684       if l_ok and l_inst_set(i).excld_flag = 'N' then
1685         --
1686         exit;
1687         --
1688       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1689         --
1690         -- raise g_criteria_failed;
1691         l_ok := false;
1692         exit ;
1693         --
1694       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1695         -- Bug 2100564
1696         l_ok := true ;
1697         --exit ;
1698         --
1699       elsif l_inst_set(i).excld_flag = 'N' then
1700         --
1701         l_rows_found := true;
1702         --
1703       end if;
1704       --
1705     end loop;
1706     --
1707   end if;
1708   --
1709   if l_rows_found and not l_ok then
1710     --
1711     raise g_criteria_failed;
1712     --
1713   end if;
1714   --
1715 end check_lbr_union;
1716 --
1717 -- -----------------------------------------------
1718 --  Legal entity check.
1719 -- -----------------------------------------------
1720 --
1721 procedure check_lgl_enty
1722   (p_vrbl_rt_prfl_id   in number
1723   ,p_person_id         in number
1724   ,p_business_group_id in number
1725   ,p_effective_date    in date
1726   ,p_lf_evt_ocrd_dt    in date
1727   ,p_gre_id            in varchar2) is
1728   --
1729   l_inst_set ben_rt_prfl_cache.g_lglenty_inst_tbl;
1730   l_inst_count number;
1731   l_ok boolean := false;
1732   l_rows_found boolean := false;
1733   --
1734 begin
1735   --
1736   -- Get the data from the cache.
1737   --
1738   ben_rt_prfl_cache.get_rt_prfl_cache
1739     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1740     ,p_effective_date    => p_effective_date
1741     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1742     ,p_business_group_id => p_business_group_id
1743     ,p_inst_set          => l_inst_set
1744     ,p_inst_count        => l_inst_count);
1745   --
1746   if l_inst_count > 0 then
1747     --
1748     -- Data found. Loop through to see if excld flag is on or off.
1749     --
1750     l_rows_found := true;
1751     --
1752     for i in l_inst_set.first..l_inst_set.last loop
1753       --
1754       l_ok := l_inst_set(i).organization_id = p_gre_id;
1755       --
1756       if l_ok is null or p_gre_id is null then
1757       --
1758         l_ok := false;
1759       --
1760       end if;
1761       --
1762       if l_ok and l_inst_set(i).excld_flag = 'N' then
1763         --
1764         exit;
1765         --
1766       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1767         --
1768         -- raise g_criteria_failed;
1769         l_ok := false;
1770         exit ;
1771         --
1772       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1773         -- Bug 2100564
1774         l_ok := true ;
1775         -- exit ;
1776         --
1777       elsif l_inst_set(i).excld_flag = 'N' then
1778         --
1779         l_rows_found := true;
1780         --
1781       end if;
1782       --
1783     end loop;
1784     --
1785   end if;
1786   --
1787   if l_rows_found and not l_ok then
1788     --
1789     raise g_criteria_failed;
1790     --
1791   end if;
1792   --
1793 end check_lgl_enty;
1794 --
1795 -- ---------------------------------------------------
1796 --  Leave of absence check.
1797 -- ---------------------------------------------------
1798 --
1799 procedure check_loa_rsn
1800   (p_vrbl_rt_prfl_id   in number
1801   ,p_person_id         in number
1802   ,p_business_group_id in number
1803   ,p_effective_date    in date
1804   ,p_lf_evt_ocrd_dt    in date) is
1805   --
1806   l_inst_set       ben_rt_prfl_cache.g_loa_inst_tbl;
1807   l_inst_count     number;
1808   l_ok boolean := false;
1809   l_rows_found boolean := false;
1810   l_effective_date date;
1811   l_dummy          varchar2(1);
1812   --
1813   -- FONM : No need to modify
1814   --
1815   cursor c_get_absence_type(p_absence_attendance_type_id in number,
1816                             p_abs_attendance_reason_id   in number) is
1817     select null
1818     from   per_absence_attendances abs
1819     where  abs.person_id = p_person_id
1820     and    abs.absence_attendance_type_id = p_absence_attendance_type_id
1821     and    nvl(abs.abs_attendance_reason_id,-1) =
1822            nvl(p_abs_attendance_reason_id,nvl(abs.abs_attendance_reason_id,-1))
1823     and    l_effective_date
1824            between nvl(abs.date_start,l_effective_date) and
1825                    nvl(abs.date_end,l_effective_date)
1826     and    abs.business_group_id  = p_business_group_id;
1827   --
1828 begin
1829   --
1830   -- Get the data from the cache.
1831   --
1832   ben_rt_prfl_cache.get_rt_prfl_cache
1833     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1834     ,p_effective_date    => p_effective_date
1835     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1836     ,p_business_group_id => p_business_group_id
1837     ,p_inst_set          => l_inst_set
1838     ,p_inst_count        => l_inst_count);
1839   --
1840   if l_inst_count > 0 then
1841     --
1842     -- FONM
1843     if ben_manage_life_events.fonm = 'Y' then
1844        --
1845        l_effective_date := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
1846                             nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
1847                                nvl(p_lf_evt_ocrd_dt, p_effective_date)));
1848     else
1849        --
1850        l_effective_date := nvl(p_lf_evt_ocrd_dt, p_effective_date);
1851        --
1852     end if;
1853     --
1854     l_rows_found:=true;
1855     --
1856     for i in l_inst_set.first..l_inst_set.last loop
1857       --
1858       open c_get_absence_type(l_inst_set(i).absence_attendance_type_id,
1859                               l_inst_set(i).abs_attendance_reason_id);
1860         --
1861         fetch c_get_absence_type into l_dummy;
1862         --
1863         if c_get_absence_type%found then
1864           --
1865           hr_utility.set_location ('c_get_absence_type found',88);
1866           --
1867           if l_inst_set(i).excld_flag = 'N' then
1868             --
1869             l_ok:=true;
1870             exit;
1871             --
1872           elsif l_inst_set(i).excld_flag = 'Y' then
1873             --
1874             close c_get_absence_type;
1875             -- raise g_criteria_failed;
1876             l_ok:= false ;
1877             exit ;
1878             --
1879           end if;
1880           --
1881         else
1882           --
1883           hr_utility.set_location ('c_get_absence_type not found',88);
1884           --
1885           if l_inst_set(i).excld_flag = 'N' then
1886             --
1887             l_rows_found:=true;
1888             --
1889           elsif l_inst_set(i).excld_flag = 'Y' then
1890             -- Bug 2100564
1891             l_ok := true ;
1892             -- exit ;
1893             --
1894           end if;
1895           --
1896         end if;
1897         --
1898       close c_get_absence_type;
1899       --
1900     end loop;
1901     --
1902     if l_rows_found and not l_ok then
1903       --
1904       raise g_criteria_failed;
1905       --
1906     end if;
1907     --
1908   end if;
1909   --
1910 end check_loa_rsn;
1911 --
1912 -- ---------------------------------------------------------
1913 --  Organization unit check.
1914 -- ---------------------------------------------------------
1915 --
1916 procedure check_org_unit
1917   (p_vrbl_rt_prfl_id   in number
1918   ,p_person_id         in number
1919   ,p_business_group_id in number
1920   ,p_effective_date    in date
1921   ,p_lf_evt_ocrd_dt    in date
1922   ,p_org_id            in number) is
1923   --
1924   l_inst_set ben_rt_prfl_cache.g_org_inst_tbl;
1925   l_inst_count number;
1926   l_ok boolean := false;
1927   l_rows_found boolean := false;
1928   --
1929 begin
1930   --
1931   -- Get the data from the cache.
1932   --
1933   ben_rt_prfl_cache.get_rt_prfl_cache
1934     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
1935     ,p_effective_date    => p_effective_date
1936     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
1937     ,p_business_group_id => p_business_group_id
1938     ,p_inst_set          => l_inst_set
1939     ,p_inst_count        => l_inst_count);
1940   --
1941   if l_inst_count > 0 then
1942     --
1943     -- Data found. Loop through to see if excld flag is on or off.
1944     --
1945     l_rows_found := true;
1946     --
1947     for i in l_inst_set.first..l_inst_set.last loop
1948       --
1949       l_ok := l_inst_set(i).organization_id = p_org_id;
1950       --
1951       if l_ok is null or p_org_id is null then
1952       --
1953         l_ok := false;
1954       --
1955       end if;
1956       --
1957       if l_ok and l_inst_set(i).excld_flag = 'N' then
1958         --
1959         exit;
1960         --
1961       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
1962         --
1963         -- raise g_criteria_failed;
1964         l_ok := false;
1965         exit ;
1966         --
1967       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
1968         -- Bug 2100564
1969         l_ok := true ;
1970         -- exit ;
1971         --
1972       elsif l_inst_set(i).excld_flag = 'N' then
1973         --
1974         l_rows_found := true;
1975         --
1976       end if;
1977       --
1978     end loop;
1979     --
1980   end if;
1981   --
1982   if l_rows_found and not l_ok then
1983     --
1984     raise g_criteria_failed;
1985     --
1986   end if;
1987   --
1988 end check_org_unit;
1989 --
1990 -- -----------------------------------------------------------
1991 -- Person type check.
1992 -- -----------------------------------------------------------
1993 --
1994 procedure check_per_typ
1995   (p_vrbl_rt_prfl_id   in number
1996   ,p_person_id         in number
1997   ,p_business_group_id in number
1998   ,p_effective_date    in date
1999   ,p_lf_evt_ocrd_dt    in date
2000   ,p_person_type       in ben_person_object.
2001                           g_cache_typ_table) is
2002   --
2003   l_inst_set ben_rt_prfl_cache.g_pertyp_inst_tbl;
2004   l_inst_count number;
2005   l_ok boolean := false;
2006   l_rows_found boolean := false;
2007   --
2008 begin
2009   --
2010   -- Get the data from the cache.
2011   --
2012   hr_utility.set_location('p_vrbl_rt_prfl_id -> '||p_vrbl_rt_prfl_id,11);
2013 
2014   ben_rt_prfl_cache.get_rt_prfl_cache
2015     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2016     ,p_effective_date    => p_effective_date
2017     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2018     ,p_business_group_id => p_business_group_id
2019     ,p_inst_set          => l_inst_set
2020     ,p_inst_count        => l_inst_count);
2021   --
2022   if l_inst_count > 0 then
2023     --
2024     -- Data found. Loop through to see if excld flag is on or off.
2025     --
2026     <<outer>>
2027     --
2028     for i in l_inst_set.first..l_inst_set.last loop
2029       --
2030       l_rows_found := true;
2031       --
2032       for l_count in p_person_type.first..p_person_type.last loop
2033         --
2034         hr_utility.set_location(l_inst_set(i).person_type_id,10);
2035         --
2036         -- To support user creatd person type use person_type_id instead of per_typ_cd
2037         --
2038         /*l_ok := l_inst_set(i).per_typ_cd =
2039                 p_person_type(l_count).system_person_type;*/
2040         l_ok := l_inst_set(i).person_type_id =
2041                 p_person_type(l_count).person_type_id;
2042         --
2043         -- To support user creatd person type use person_type_id instead of per_typ_cd
2044         --
2045         /*if l_ok is null or p_person_type(l_count).system_person_type is null then */
2046         if l_ok is null or p_person_type(l_count).person_type_id is null then
2047         --
2048           l_ok := false;
2049         --
2050         end if;
2051         --
2052         if l_ok and l_inst_set(i).excld_flag = 'N' then
2053           --
2054           exit outer;
2055           --
2056         elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2057           --
2058           l_rows_found := true;
2059           l_ok := false;
2060           exit outer;
2061           --
2062         elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2063           -- Bug 2100564
2064           l_rows_found := true;
2065           l_ok := true ;
2066           -- exit outer;
2067           --
2068         elsif l_inst_set(i).excld_flag = 'N' then
2069           --
2070           l_rows_found := true;
2071           --
2072         end if;
2073         --
2074       end loop;
2075       --
2076     end loop;
2077     --
2078   end if;
2079   --
2080   if l_rows_found and not l_ok then
2081     --
2082     raise ben_evaluate_rate_profiles.g_profile_failed;
2083     --
2084   end if;
2085   --
2086 end check_per_typ;
2087 --
2088 -- ---------------------------------------------------------------
2089 --  Zip code range check.
2090 -- ---------------------------------------------------------------
2091 --
2092 PROCEDURE check_zip_code_rng
2093   (p_vrbl_rt_prfl_id   IN NUMBER
2094   ,p_person_id         IN NUMBER
2095   ,p_business_group_id IN NUMBER
2096   ,p_effective_date    IN DATE
2097   ,p_lf_evt_ocrd_dt    IN DATE
2098   ,p_postal_code       IN VARCHAR2) IS
2099   --
2100   --
2101   -- FONM
2102   --
2103      CURSOR get_elig_zip(p_vrbl_rt_prfl_id IN NUMBER
2104                         ,cv_effective_date  IN DATE) IS
2105       SELECT epz.pstl_zip_rng_id,epz.excld_flag
2106       FROM   ben_pstl_zip_rt_f epz
2107       WHERE epz.vrbl_rt_prfl_id = p_vrbl_rt_prfl_id
2108       AND   cv_effective_date -- FONM NVL(p_lf_evt_ocrd_dt, p_effective_date)
2109       BETWEEN epz.effective_start_date
2110       AND     epz.effective_end_date;
2111   --
2112   CURSOR get_zip_ranges(p_pstl_zip_rng_id IN NUMBER
2113                        ,p_postal_code IN VARCHAR2
2114                        ,cv_effective_date in date) IS
2115   SELECT zip.from_value, zip.to_value
2116   FROM   ben_pstl_zip_rng_f zip
2117   WHERE zip.pstl_zip_rng_id = p_pstl_zip_rng_id
2118   AND   LENGTH(p_postal_code) >= LENGTH(zip.from_value)
2119   AND   (SUBSTR( nvl(p_postal_code,'-1'),1,LENGTH(zip.from_value))
2120   BETWEEN zip.from_value AND NVL(zip.to_value,p_postal_code)
2121   OR     NVL(p_postal_code,'-1') = zip.from_value
2122   OR     nvl(p_postal_code,'-1') = zip.to_value)
2123   AND    cv_effective_date
2124   BETWEEN zip.effective_start_date
2125   AND zip.effective_end_date;
2126 
2127   l_rows_found BOOLEAN := FALSE;
2128   l_pstl_zip_rng_id   NUMBER(15);
2129   l_excld_flag        VARCHAR2(1);
2130   l_from_value        VARCHAR2(10);
2131   l_to_value          VARCHAR2(10);
2132   --
2133   -- FONM
2134   l_fonm_cvg_strt_dt   date;
2135   --
2136 BEGIN
2137   --
2138   -- Get the data from the cache.
2139   hr_utility.set_location('entering chck_zip_code', 10);
2140   --
2141   -- FONM
2142   if ben_manage_life_events.fonm = 'Y' then
2143      --
2144      l_fonm_cvg_strt_dt := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
2145                                ben_manage_life_events.g_fonm_cvg_strt_dt);
2146      --
2147   end if;
2148  --
2149  -- FONM
2150  --
2151  OPEN get_elig_zip(p_vrbl_rt_prfl_id,nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt, p_effective_date)));
2152    <<range_loop>>
2153    LOOP
2154      FETCH get_elig_zip into l_pstl_zip_rng_id,l_excld_flag;
2155      EXIT WHEN get_elig_zip%NOTFOUND;
2156      l_rows_found := FALSE;
2157      OPEN get_zip_ranges(l_pstl_zip_rng_id,p_postal_code,
2158                          nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt, p_effective_date)));
2159        <<zip_loop>>
2160        LOOP
2161          FETCH get_zip_ranges INTO l_from_value,l_to_value;
2162          EXIT WHEN get_zip_ranges%NOTFOUND;
2163          --
2164          hr_utility.set_location('person zip '||p_postal_code ,2219.3);
2165          hr_utility.set_location('from zip '||l_from_value ,2219.3);
2166          hr_utility.set_location('to zip '||l_to_value ,2219.3);
2167          --
2168          l_rows_found := TRUE;
2169          EXIT;
2170          --
2171        END LOOP zip_loop;
2172        --
2173        IF (p_postal_code is null)
2174        OR (l_rows_found   AND l_excld_flag = 'N')
2175        THEN
2176          --
2177          close get_zip_ranges;
2178          l_rows_found := TRUE;
2179          exit;
2180          --
2181        ELSIF ( not l_rows_found  AND l_excld_flag = 'Y' ) THEN
2182          --
2183          l_rows_found := TRUE;
2184          --
2185        ELSIF ( l_rows_found AND l_excld_flag = 'Y') THEN
2186          --
2187          l_rows_found := FALSE ;
2188          close get_zip_ranges;
2189          exit;
2190          --
2191        END IF;
2192        --
2193        CLOSE get_zip_ranges;
2194        --
2195      END LOOP range_loop;
2196      --
2197      CLOSE get_elig_zip;
2198      --
2199      if not l_rows_found then
2200        --
2201        RAISE ben_evaluate_rate_profiles.g_profile_failed;
2202        --
2203      end if;
2204      --
2205      hr_utility.set_location('leaving chck_zip_code', 10);
2206      --
2207 END check_zip_code_rng;
2208 --
2209 -- --------------------------------------------------------
2210 --  Payroll check.
2211 -- --------------------------------------------------------
2212 --
2213 procedure check_pyrl
2214   (p_vrbl_rt_prfl_id   in number
2215   ,p_person_id         in number
2216   ,p_business_group_id in number
2217   ,p_effective_date    in date
2218   ,p_lf_evt_ocrd_dt    in date
2219   ,p_payroll_id        in number) is
2220   --
2221   l_inst_set ben_rt_prfl_cache.g_pyrl_inst_tbl;
2222   l_inst_count number;
2223   l_ok boolean := false;
2224   l_rows_found boolean := false;
2225   --
2226 begin
2227   --
2228   -- Get the data from the cache.
2229   --
2230   ben_rt_prfl_cache.get_rt_prfl_cache
2231     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2232     ,p_effective_date    => p_effective_date
2233     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2234     ,p_business_group_id => p_business_group_id
2235     ,p_inst_set          => l_inst_set
2236     ,p_inst_count        => l_inst_count);
2237   --
2238   if l_inst_count > 0 then
2239     --
2240     -- Data found. Loop through to see if excld flag is on or off.
2241     --
2242     l_rows_found := true;
2243     --
2244     for i in l_inst_set.first..l_inst_set.last loop
2245       --
2246       l_ok := p_payroll_id = l_inst_set(i).payroll_id;
2247       --
2248       if l_ok is null or p_payroll_id is null then
2249       --
2250         l_ok := false;
2251       --
2252       end if;
2253       --
2254       if l_ok and l_inst_set(i).excld_flag = 'N' then
2255         --
2256         exit;
2257         --
2258       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2259         --
2260         -- raise g_criteria_failed;
2261         l_ok := false;
2262         exit ;
2263         --
2264       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2265         -- Bug 2100564
2266         l_ok := true ;
2267         -- exit ;
2268         --
2269       elsif l_inst_set(i).excld_flag = 'N' then
2270         --
2271         l_rows_found := true;
2272         --
2273       end if;
2274       --
2275     end loop;
2276     --
2277   end if;
2278   --
2279   if l_rows_found and not l_ok then
2280     --
2281     raise g_criteria_failed;
2282     --
2283   end if;
2284   --
2285 end check_pyrl;
2286 --
2287 -- ----------------------------------------------------------
2288 --  Pay basis check.
2289 -- ----------------------------------------------------------
2290 --
2291 procedure check_py_bss
2292   (p_vrbl_rt_prfl_id   in number
2293   ,p_person_id         in number
2294   ,p_business_group_id in number
2295   ,p_effective_date    in date
2296   ,p_lf_evt_ocrd_dt    in date
2297   ,p_pay_basis_id      in number) is
2298   --
2299   l_inst_set ben_rt_prfl_cache.g_py_bss_inst_tbl;
2300   l_inst_count number;
2301   l_ok boolean := false;
2302   l_rows_found boolean := false;
2303   --
2304 begin
2305   --
2306   -- Get the data from the cache.
2307   --
2308   ben_rt_prfl_cache.get_rt_prfl_cache
2309     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2310     ,p_effective_date    => p_effective_date
2311     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2312     ,p_business_group_id => p_business_group_id
2313     ,p_inst_set          => l_inst_set
2314     ,p_inst_count        => l_inst_count);
2315   --
2316   if l_inst_count > 0 then
2317     --
2318     -- Data found. Loop through to see if excld flag is on or off.
2319     --
2320     l_rows_found := true;
2321     --
2322     for i in l_inst_set.first..l_inst_set.last loop
2323       --
2324       l_ok := p_pay_basis_id = l_inst_set(i).pay_basis_id;
2325       --
2326       if l_ok is null or p_pay_basis_id is null then
2327       --
2328         l_ok := false;
2329       --
2330       end if;
2331       --
2332       if l_ok and l_inst_set(i).excld_flag = 'N' then
2333         --
2334         exit;
2335         --
2336       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2337         --
2338         -- raise g_criteria_failed;
2339         l_ok := false;
2340         exit ;
2341         --
2342       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2343         -- Bug 2100564
2344         l_ok := true ;
2345         --exit ;
2346         --
2347       elsif l_inst_set(i).excld_flag = 'N' then
2348         --
2349         l_rows_found := true;
2350         --
2351       end if;
2352       --
2353     end loop;
2354     --
2355   end if;
2356   --
2357   if l_rows_found and not l_ok then
2358     --
2359     raise g_criteria_failed;
2360     --
2361   end if;
2362   --
2363 end check_py_bss;
2364 --
2365 -- ---------------------------------------------------------
2366 --  Scheduled hours check.
2367 -- ---------------------------------------------------------
2368 --
2369 procedure check_sched_hrs
2370   (p_vrbl_rt_prfl_id   in number
2371   ,p_person_id         in number
2372   ,p_business_group_id in number
2373   ,p_effective_date    in date
2374   ,p_lf_evt_ocrd_dt    in date
2375   ,p_normal_hrs        in number
2376   ,p_frequency         in varchar2
2377   ,p_per_in_ler_id     in number
2378   ,p_assignment_id     in number
2379   ,p_organization_id   in number
2380   ,p_pgm_id            in number
2381   ,p_pl_id             in number
2382   ,p_pl_typ_id         in number
2383   ,p_opt_id            in number
2384   ,p_oipl_id           in number
2385   ,p_ler_id            in number
2386   ,p_jurisdiction_code in varchar2
2387  ) is
2388   --
2389   l_inst_set ben_rt_prfl_cache.g_scdhrs_inst_tbl;
2390   l_inst_count number;
2391   l_ok boolean := false;
2392   l_rows_found boolean := false;
2393 
2394   l_min_hours	       ben_schedd_hrs_rt_f.hrs_num%type;
2395   l_max_hours	       ben_schedd_hrs_rt_f.max_hrs_num%type;
2396   l_freq_cd	       ben_schedd_hrs_rt_f.freq_cd%type;
2397   l_person_freq_cd     ben_schedd_hrs_rt_f.freq_cd%type;
2398   l_person_hours       number;
2399   l_det_dt	       date;
2400   l_output             ff_exec.outputs_t;
2401   l_pl_rec             ben_pl_f%rowtype;
2402   l_pgm_rec            ben_pgm_f%rowtype;
2403   l_package            varchar2(80) := g_package||'.check_sched_hrs';
2404   --
2405   cursor c_scheduled_hours
2406     (c_effective_date    date,
2407      c_person_id         number,
2408      c_freq_cd           varchar2,
2409      c_business_group_id number)  is
2410   select sum(normal_hours)
2411   from   per_all_assignments_f
2412   where  person_id = c_person_id
2413   and    c_effective_date between effective_start_date and effective_end_date
2414   and    frequency = c_freq_cd
2415   and    business_group_id = c_business_group_id;
2416 
2417   cursor c_asg_scheduled_hours
2418     (c_effective_date    date,
2419      c_assignment_id 	 number,
2420      c_business_group_id number)  is
2421   select normal_hours, frequency
2422   from   per_all_assignments_f
2423   where  assignment_id = c_assignment_id
2424   and    c_effective_date between effective_start_date and effective_end_date
2425   and    business_group_id = c_business_group_id;
2426   --
2427 begin
2428   --
2429   -- Get the data from the cache.
2430   --
2431   ben_rt_prfl_cache.get_rt_prfl_cache
2432     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2433     ,p_effective_date    => p_effective_date
2434     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2435     ,p_business_group_id => p_business_group_id
2436     ,p_inst_set          => l_inst_set
2437     ,p_inst_count        => l_inst_count);
2438   --
2439   if l_inst_count > 0 then
2440     --
2441     -- Data found. Loop through to see if excld flag is on or off.
2442     --
2443     l_rows_found := true;
2444     --
2445     for i in l_inst_set.first..l_inst_set.last loop
2446       --
2447       -- If there is a rule evaluate the rule
2448       if l_inst_set(i).schedd_hrs_rl is not null then
2449       	 l_output := benutils.formula
2450 	                 (p_formula_id        => l_inst_set(i).schedd_hrs_rl
2451 		         ,p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date)
2452 		         ,p_business_group_id => p_business_group_id
2453 		         ,p_assignment_id     => p_assignment_id
2454 		         ,p_organization_id   => p_organization_id
2455 		         ,p_pgm_id            => p_pgm_id
2456 		         ,p_pl_id             => p_pl_id
2457 		         ,p_pl_typ_id         => p_pl_typ_id
2458 		         ,p_opt_id            => p_opt_id
2459 		         ,p_ler_id            => p_ler_id
2460 		         ,p_jurisdiction_code => p_jurisdiction_code -- FONM
2461                          ,p_param1             => 'BEN_IV_RT_STRT_DT'
2462                          ,p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt)
2463                          ,p_param2             => 'BEN_IV_CVG_STRT_DT'
2464                          ,p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt));
2465 
2466       	 --
2467          for l_count in l_output.first..l_output.last loop
2468            --
2469            declare
2470            	invalid_param exception;
2471            begin
2472              --
2473              if l_output(l_count).name = 'MIN_HOURS' then
2474                  --
2475                  l_min_hours := to_number(l_output(l_count).value);
2476                  --
2477              elsif l_output(l_count).name = 'MAX_HOURS' then
2478                  --
2479                  l_max_hours := to_number(l_output(l_count).value);
2480                  --
2481              elsif l_output(l_count).name = 'FREQUENCY' then
2482                  --
2483                  l_freq_cd := l_output(l_count).value;
2484                  --
2485              else
2486                --
2487                -- Account for cases where formula returns an unknown
2488                -- variable name
2489                --
2490                fnd_message.set_name('BEN','BEN_92310_FORMULA_RET_PARAM_');
2491                fnd_message.set_token('PROC',l_package);
2492                fnd_message.set_token('FORMULA', l_inst_set(i).schedd_hrs_rl);
2493                fnd_message.set_token('PARAMETER',l_output(l_count).name);
2494 
2495                -- Handling this particular exception seperately.
2496                raise invalid_param;
2497                --
2498              end if;
2499              --
2500              -- Code for type casting errors from formula return variables
2501              --
2502            exception
2503              --
2504              -- Code appended for bug# 2620550
2505 	     when invalid_param then
2506              	fnd_message.raise_error;
2507              when others then
2508                --
2509                fnd_message.set_name('BEN','BEN_92311_FORMULA_VAL_PARAM');
2510                fnd_message.set_token('PROC',l_package);
2511                fnd_message.set_token('FORMULA', l_inst_set(i).schedd_hrs_rl);
2512                fnd_message.set_token('PARAMETER',l_output(l_count).name);
2513                fnd_message.raise_error;
2514              --
2515 	   end;
2516       	 end loop;
2517       	 --
2518       	 if l_min_hours is null and l_max_hours is null then
2519  	       fnd_message.set_name('BEN','BEN_92310_FORMULA_RET_PARAM_');
2520                fnd_message.set_token('PROC',l_package);
2521                fnd_message.set_token('FORMULA', l_inst_set(i).schedd_hrs_rl);
2522                fnd_message.set_token('PARAMETER','MIN_HOURS');
2523                fnd_message.raise_error;
2524          end if;
2525 
2526       	 if l_freq_cd is null then
2527  	       fnd_message.set_name('BEN','BEN_92310_FORMULA_RET_PARAM_');
2528                fnd_message.set_token('PROC',l_package);
2529                fnd_message.set_token('FORMULA', l_inst_set(i).schedd_hrs_rl);
2530                fnd_message.set_token('PARAMETER','FREQUENCY');
2531                fnd_message.raise_error;
2532       	 end if;
2533       else
2534       	   l_min_hours := l_inst_set(i).hrs_num;
2535       	   l_max_hours := l_inst_set(i).max_hrs_num;
2536            l_freq_cd   := l_inst_set(i).freq_cd;
2537       end if;
2538       -- Get the determination date from determination_cd
2539       if l_inst_set(i).determination_cd is not null or l_inst_set(i).determination_rl is not null then
2540          ben_determine_date.main
2541           (p_date_cd           => l_inst_set(i).determination_cd,
2542            p_per_in_ler_id     => p_per_in_ler_id,
2543            p_person_id         => p_person_id,
2544            p_pgm_id            => p_pgm_id,
2545            p_pl_id             => p_pl_id,
2546            p_oipl_id           => p_oipl_id,
2547            p_business_group_id => p_business_group_id,
2548            p_formula_id        => l_inst_set(i).determination_rl,
2549            p_effective_date    => p_effective_date,
2550            p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
2551            p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
2552            p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
2553            p_returned_date     => l_det_dt );
2554       end if;
2555 
2556 
2557      --
2558 
2559 
2560       --
2561       if l_det_dt is null then
2562            -- FONM
2563            l_det_dt  := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
2564                           nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
2565                               nvl(p_lf_evt_ocrd_dt,p_effective_date)));
2566       end if;
2567 
2568       -- get Scheduled hour details from the assignment records
2569       if p_pl_id is not null then
2570            ben_comp_object.get_object(p_pl_id => p_pl_id
2571                                 ,p_rec   => l_pl_rec);
2572       end if;
2573 
2574       if p_pgm_id is not null then
2575        	   ben_comp_object.get_object(p_pgm_id => p_pgm_id
2576                                 ,p_rec    => l_pgm_rec);
2577       end if;
2578       --
2579       if l_pl_rec.use_all_asnts_for_rt_flag = 'Y' or l_pgm_rec.uses_all_asmts_for_rts_flag = 'Y' then
2580       	   open c_scheduled_hours
2581                 (l_det_dt,p_person_id,
2582                  l_freq_cd, p_business_group_id);
2583            fetch c_scheduled_hours into l_person_hours;
2584            close c_scheduled_hours;
2585 
2586            l_person_freq_cd := l_freq_cd;
2587       else
2588       	    open c_asg_scheduled_hours
2589 	                   (l_det_dt,p_assignment_id,
2590 	                    p_business_group_id);
2591 	    fetch c_asg_scheduled_hours into l_person_hours, l_person_freq_cd;
2592             close c_asg_scheduled_hours;
2593       end if;
2594 
2595       -- Applying the rounding code
2596       if (l_inst_set(i).rounding_cd is not null or l_inst_set(i).rounding_rl is not null)
2597         and l_person_hours is not null then
2598             l_person_hours := benutils.do_rounding
2599                         (p_rounding_cd     => l_inst_set(i).rounding_cd,
2600                          p_rounding_rl     => l_inst_set(i).rounding_rl,
2601                          p_value           => l_person_hours,
2602                          p_effective_date  => nvl(p_lf_evt_ocrd_dt,p_effective_date));
2603       end if;
2604 
2605       -- Evaluate
2606       if l_min_hours is not null and l_max_hours is null then
2607       	    l_ok := (l_person_hours >= l_min_hours) and l_person_freq_cd = l_freq_cd;
2608       elsif l_min_hours is null and l_max_hours is not null  then
2609       	    l_ok := l_person_hours <= l_max_hours and l_person_freq_cd = l_freq_cd;
2610       else
2611             l_ok := l_person_hours between l_min_hours and l_max_hours
2612                      and l_person_freq_cd = l_freq_cd;
2613       end if;
2614 
2615       --
2616       if l_ok is null or p_normal_hrs is null or p_frequency is null then
2617       --
2618         l_ok := false;
2619       --
2620       end if;
2621       --
2622       if l_ok and l_inst_set(i).excld_flag = 'N' then
2623         --
2624         exit;
2625         --
2626       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2627         --
2628         -- raise g_criteria_failed;
2629         l_ok := false;
2630         exit ;
2631         --
2632       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2633         -- Bug 2100564
2634         l_ok := true ;
2635         -- exit ;
2636         --
2637       elsif l_inst_set(i).excld_flag = 'N' then
2638         --
2639         l_rows_found := true;
2640         --
2641       end if;
2642       --
2643     end loop;
2644     --
2645   end if;
2646   --
2647   if l_rows_found and not l_ok then
2648     --
2649     raise g_criteria_failed;
2650     --
2651   end if;
2652   --
2653 end check_sched_hrs;
2654 --
2655 -- --------------------------------------------------------------
2656 --  Work location check.
2657 -- --------------------------------------------------------------
2658 --
2659 procedure check_wk_location
2660   (p_vrbl_rt_prfl_id   in number
2661   ,p_person_id         in number
2662   ,p_business_group_id in number
2663   ,p_effective_date    in date
2664   ,p_lf_evt_ocrd_dt    in date
2665   ,p_location_id       in number) is
2666   --
2667   l_inst_set ben_rt_prfl_cache.g_wkloc_inst_tbl;
2668   l_inst_count number;
2669   l_ok boolean := false;
2670   l_rows_found boolean := false;
2671   --
2672 begin
2673   --
2674   ben_rt_prfl_cache.get_rt_prfl_cache
2675     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2676     ,p_effective_date    => p_effective_date
2677     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2678     ,p_business_group_id => p_business_group_id
2679     ,p_inst_set          => l_inst_set
2680     ,p_inst_count        => l_inst_count);
2681   --
2682   if l_inst_count > 0 then
2683     -- Data found. Loop through to see if excld flag is on or off.
2684     l_rows_found := true;
2685     --
2686     for i in l_inst_set.first..l_inst_set.last loop
2687       --
2688       l_ok := p_location_id = l_inst_set(i).location_id;
2689       --
2690       if l_ok is null or p_location_id is null then
2691       --
2692         l_ok := false;
2693       --
2694       end if;
2695       --
2696       if l_ok and l_inst_set(i).excld_flag = 'N' then
2697         --
2698         exit;
2699         --
2700       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2701         --
2702         -- raise g_criteria_failed;
2703         l_ok := false;
2704         exit ;
2705         --
2706       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2707         -- Bug 2100564
2708         l_rows_found := true;
2709         l_ok := true ;
2710         -- exit ;
2711         --
2712       elsif l_inst_set(i).excld_flag = 'N' then
2713         --
2714         l_rows_found := true;
2715         --
2716       end if;
2717       --
2718     end loop;
2719     --
2720   end if;
2721   --
2722   if l_rows_found and not l_ok then
2723     --
2724     raise g_criteria_failed;
2725     --
2726   end if;
2727   --
2728 end check_wk_location;
2729 --
2730 -- ---------------------------------------------------------------
2731 --  Service area check.
2732 -- ---------------------------------------------------------------
2733 --
2734 
2735 PROCEDURE check_service_area
2736   (p_vrbl_rt_prfl_id   IN NUMBER
2737   ,p_person_id         IN NUMBER
2738   ,p_business_group_id IN NUMBER
2739   ,p_effective_date    IN DATE
2740   ,p_lf_evt_ocrd_dt    IN DATE
2741   ,p_postal_code       IN VARCHAR2) IS
2742   --
2743 --
2744 -- FONM
2745 --
2746 CURSOR get_elig_svc (p_vrbl_rt_prfl_id IN NUMBER
2747                     ,cv_effective_date IN DATE) IS
2748    SELECT sar.svc_area_id,  sar.excld_flag
2749    FROM   ben_svc_area_rt_f sar
2750    WHERE  sar.vrbl_rt_prfl_id = p_vrbl_rt_prfl_id
2751    AND    cv_effective_date -- FONM NVL(p_lf_evt_ocrd_dt, p_effective_date)
2752    BETWEEN sar.effective_start_date
2753    AND     sar.effective_end_date;
2754 --
2755 /* NOT USED
2756 CURSOR get_zip_ranges(p_svc_area_id IN NUMBER
2757                      ,p_postal_code in VARCHAR2
2758                      ,cv_effective_date in date) IS
2759 SELECT zip.from_value, zip.to_value
2760 FROM  ben_pstl_zip_rng_f zip
2761 WHERE zip.pstl_zip_rng_id IN (
2762 	SELECT pstl_zip_rng_id
2763 	FROM   ben_svc_area_pstl_zip_rng_f rng
2764 	WHERE  rng.SVC_AREA_ID = p_svc_area_id
2765 	AND    cv_effective_date BETWEEN rng.effective_start_date
2766 	AND rng.effective_end_date)
2767 AND    LENGTH(p_postal_code) >= LENGTH(zip.from_value)
2768 AND    (SUBSTR( NVL(p_postal_code,'-1'),1,LENGTH(zip.from_value))
2769 BETWEEN zip.from_value and NVL(zip.to_value,p_postal_code)
2770 OR     NVL(p_postal_code,'-1') = zip.from_value
2771 OR     NVL(p_postal_code,'-1') = zip.to_value)
2772 AND    cv_effective_date BETWEEN zip.effective_start_date
2773 AND    zip.effective_end_date;
2774 */
2775 
2776   l_rows_found       BOOLEAN := false;
2777   l_svc_area_id      NUMBER(15);
2778   l_excld_flag       VARCHAR2(1);
2779   l_from_value       VARCHAR2(10);
2780   l_to_value         VARCHAR2(10);
2781   l_ok               BOOLEAN := false;
2782   --
2783   -- FONM
2784   l_fonm_cvg_strt_dt   date;
2785   --
2786 BEGIN
2787   --
2788   -- FONM
2789   --
2790   if ben_manage_life_events.fonm = 'Y' then
2791      --
2792      l_fonm_cvg_strt_dt := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
2793                                ben_manage_life_events.g_fonm_cvg_strt_dt);
2794      --
2795   end if;
2796   --
2797   -- Get the data from the cache.
2798   --
2799   -- Getting eligibility profile service area range by eligibility profile
2800   --
2801   OPEN get_elig_svc(p_vrbl_rt_prfl_id,
2802        nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date)));
2803   <<range_loop>>
2804   LOOP
2805     FETCH get_elig_svc INTO l_svc_area_id,l_excld_flag;
2806     EXIT WHEN get_elig_svc%NOTFOUND;
2807     l_rows_found := FALSE;
2808     --
2809     ben_saz_cache.SAZRZR_Exists                 -- 9999 FONM
2810       (p_svc_area_id => l_svc_area_id
2811       ,p_zip_code    => p_postal_code
2812       ,p_eff_date    => p_effective_date -- FONM why not lf_evt_ocrd_dt passed?
2813       --
2814       ,p_exists      => l_rows_found
2815       );
2816     --
2817     IF (l_rows_found AND l_excld_flag = 'N') THEN
2818        --
2819        l_rows_found := TRUE;
2820        l_ok := true;
2821        exit;
2822        --
2823     ELSIF ( NOT l_rows_found AND l_excld_flag = 'Y' ) then
2824        --
2825        l_rows_found := TRUE;
2826        l_ok := true;
2827        --
2828     ELSIF ( l_rows_found AND l_excld_flag = 'Y' ) then
2829        -- close get_elig_svc ;
2830        fnd_message.set_name('BEN','BEN_92225_SVC_AREA_PRFL_FAIL');
2831        -- raise g_criteria_failed;
2832        l_rows_found :=FALSE ;
2833        l_ok := false ;
2834        exit ;
2835     END IF;
2836   --
2837   END LOOP range_loop;
2838   CLOSE get_elig_svc;
2839   --
2840   if (NOT l_rows_found)  and (not l_ok)  then
2841      --
2842      RAISE ben_evaluate_rate_profiles.g_profile_failed;
2843      --
2844   End if;
2845   --
2846   --
2847 END check_service_area;
2848 --
2849 -- ---------------------------------------------------------------
2850 --    Hourly/Salary Code check
2851 -- ---------------------------------------------------------------
2852 --
2853 procedure check_hourly_salary
2854   (p_vrbl_rt_prfl_id      in number
2855   ,p_business_group_id    in number
2856   ,p_effective_date       in date
2857   ,p_lf_evt_ocrd_dt       in date
2858   ,p_hrly_slry            in varchar2) is
2859   --
2860   l_inst_set ben_rt_prfl_cache.g_hrlyslrd_inst_tbl;
2861   l_inst_count number;
2862   l_ok boolean := false;
2863   l_rows_found boolean := false;
2864   --
2865 begin
2866   --
2867   -- Get the data from the cache.
2868   --
2869   ben_rt_prfl_cache.get_rt_prfl_cache
2870     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
2871     ,p_effective_date    => p_effective_date
2872     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2873     ,p_business_group_id => p_business_group_id
2874     ,p_inst_set          => l_inst_set
2875     ,p_inst_count        => l_inst_count);
2876   --
2877   if l_inst_count > 0 then
2878     --
2879     -- Data found. Loop through to see if excld flag is on or off.
2880     --
2881     l_rows_found := true;
2882     --
2883     for i in l_inst_set.first..l_inst_set.last loop
2884       --
2885       l_ok := p_hrly_slry = l_inst_set(i).hrly_slrd_cd;
2886       --
2887       if l_ok is null or p_hrly_slry is null then
2888       --
2889         l_ok := false;
2890       --
2891       end if;
2892       --
2893       if l_ok and l_inst_set(i).excld_flag = 'N' then
2894         --
2895         exit;
2896         --
2897       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
2898         --
2899         -- raise g_criteria_failed;
2900         l_ok := false;
2901         exit ;
2902         --
2903       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
2904         -- Bug 2100564
2905         l_rows_found := true;
2906         l_ok := true ;
2907         -- exit ;
2908         --
2909       elsif l_inst_set(i).excld_flag = 'N' then
2910         --
2911         l_rows_found := true;
2912         --
2913       end if;
2914       --
2915     end loop;
2916     --
2917   end if;
2918   --
2919   if l_rows_found and not l_ok then
2920     --
2921     raise g_criteria_failed;
2922     --
2923   end if;
2924   --
2925 end check_hourly_salary;
2926 --
2927 -- ----------------------------------------------------
2928 --  Age check.
2929 -- ----------------------------------------------------
2930 --
2931 procedure check_age
2932   (p_vrbl_rt_prfl_id        in number
2933   ,p_person_id              in number
2934   ,p_per_dob                in date
2935   ,p_business_group_id      in number
2936   ,p_effective_date         in date
2937   ,p_lf_evt_ocrd_dt         in date
2938   ,p_elig_per_elctbl_chc_id in number
2939   ,p_pl_id                  in number default null
2940   ,p_pgm_id                 in number default null
2941   ,p_oipl_id                in number default null
2942   ,p_plip_id                in number default null
2943   ,p_opt_id                 in number default null
2944   ,p_per_in_ler_id          in number default null
2945   ,p_currepe_row            in ben_determine_rates.g_curr_epe_rec)
2946 is
2947   --
2948   l_proc            varchar2(80) := g_package||'.check_age';
2949   --
2950   l_pl_id           number;
2951   l_pgm_id          number;
2952   l_per_in_ler_id   number;
2953   l_oipl_id         number;
2954   l_per_age         number;
2955   l_dummy_date      date;
2956   l_prtn_ovridn_flag  varchar2(30);
2957   l_prtn_ovridn_thru_dt date;
2958   l_epo_row           ben_derive_part_and_rate_facts.g_cache_structure;
2959   l_effective_date   date ;
2960   --
2961 
2962   --
2963   --    Grab needed parameters for passing into determin_age procedure.
2964   --
2965   cursor c_age_param is
2966     select epe.pl_id, epe.pgm_id, epe.oipl_id, epe.per_in_ler_id
2967     from   ben_elig_per_elctbl_chc epe
2968     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
2969   --
2970   l_inst_set ben_rt_prfl_cache.g_age_inst_tbl;
2971   l_inst_count number;
2972   l_ok boolean := false;
2973   l_rows_found boolean := false;
2974   --RCHASE
2975   l_dob date:=p_per_dob;
2976   l_mx_age_num number ;
2977   --
2978 begin
2979   --
2980   --- fonm2
2981   l_effective_date  := nvl(  p_lf_evt_ocrd_dt,  p_effective_date ) ;
2982   if ben_manage_life_events.fonm = 'Y' then
2983      --
2984       l_effective_date  :=  nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
2985                             nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
2986                                 l_effective_date));
2987      --
2988   end if;
2989 
2990 
2991   --hr_utility.set_location(l_proc||' Entering ',10);
2992   if p_elig_per_elctbl_chc_id is not null then
2993     --
2994     open c_age_param;
2995       --
2996       fetch c_age_param into l_pl_id, l_pgm_id, l_oipl_id, l_per_in_ler_id;
2997       --
2998     close c_age_param;
2999      --
3000   else
3001     --
3002     l_pl_id   := p_pl_id;
3003     l_pgm_id  := p_pgm_id;
3004     l_oipl_id := p_oipl_id;
3005     l_per_in_ler_id := p_per_in_ler_id;
3006     --
3007   end if;
3008   --
3009   -- Get the data from the cache.
3010   --
3011   ben_rt_prfl_cache.get_rt_prfl_cache
3012     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
3013     ,p_effective_date    => p_effective_date
3014     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3015     ,p_business_group_id => p_business_group_id
3016     ,p_inst_set          => l_inst_set
3017     ,p_inst_count        => l_inst_count);
3018   --hr_utility.set_location(l_proc||' Dn GRP Cac ',10);
3019   --
3020   if l_inst_count > 0 then
3021     --
3022     -- plan in program is overriden, capture the data from cache by passing plip_id
3023     if p_opt_id is null and p_pgm_id is not null then
3024        ben_pep_cache.get_pilpep_dets(
3025             p_person_id         => p_person_id,
3026             p_business_group_id => p_business_group_id,
3027             p_effective_date    => l_effective_date,
3028             p_pgm_id            => p_pgm_id,
3029             p_plip_id           => p_plip_id,
3030             p_inst_row          => l_epo_row);
3031             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3032             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3033             l_per_age             := l_epo_row.rt_age_val;
3034     elsif p_opt_id is not null and p_pgm_id is not null then
3035             ben_pep_cache.get_pilepo_dets(
3036             p_person_id         => p_person_id,
3037             p_business_group_id => p_business_group_id,
3038             p_effective_date    => l_effective_date,
3039             p_pgm_id            => p_pgm_id,
3040             p_plip_id           => p_plip_id,
3041             p_opt_id            => p_opt_id,
3042             p_inst_row          => l_epo_row);
3043             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3044             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3045             l_per_age             := l_epo_row.rt_age_val;
3046     else
3047           hr_utility.set_location('Plan not in Program',10);
3048            l_prtn_ovridn_flag    := p_currepe_row.prtn_ovridn_flag;
3049            l_prtn_ovridn_thru_dt := p_currepe_row.prtn_ovridn_thru_dt;
3050            l_per_age             := p_currepe_row.rt_age_val;
3051     end if;
3052 
3053     -- Data found. Loop through to see if excld flag is on or off.
3054     --
3055     l_rows_found := true;
3056     --
3057     for i in l_inst_set.first..l_inst_set.last loop
3058       --
3059       if l_inst_set(i).age_fctr_id is null then
3060         --
3061         fnd_message.set_name('BEN','BEN_91520_BERP_AGE_FCTR_ID');
3062         fnd_message.set_token('L_PROC',l_proc);
3063         fnd_message.set_token('PERSON_ID',to_char(p_person_id));
3064         fnd_message.set_token('VRBL_RT_PRFL_ID',to_char(p_vrbl_rt_prfl_id));
3065         fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
3066         fnd_message.set_token('PL_ID',to_char(p_pl_id));
3067         fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
3068         fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
3069         fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
3070         fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',to_char(p_elig_per_elctbl_chc_id));
3071         fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3072         fnd_message.raise_error;
3073         --
3074       end if;
3075       --
3076       --RCHASE - v115.57 wrap l_prtn_ovridn_flag with NVL,
3077       --         possible NULL return instead of expected TRUE or FALSE
3078       -- Bug 9033589: Commented the if condition below
3079       /*
3080       if not (nvl(l_prtn_ovridn_flag,'N') = 'Y' and
3081                nvl(l_prtn_ovridn_thru_dt,hr_api.g_eot) > p_effective_date)
3082           then
3083       */
3084     --
3085         ben_derive_factors.determine_age
3086         (p_person_id            => p_person_id
3087         --RCHASE changed p_per_dob to l_dob
3088         ,p_per_dob              => l_dob
3089         ,p_age_fctr_id          => l_inst_set(i).age_fctr_id
3090         ,p_pgm_id               => l_pgm_id
3091         ,p_pl_id                => l_pl_id
3092         ,p_oipl_id              => l_oipl_id
3093         ,p_per_in_ler_id        => l_per_in_ler_id
3094         ,p_effective_date       => p_effective_date
3095         ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt
3096         --fonm
3097         ,p_fonm_cvg_strt_dt     => ben_manage_life_events.g_fonm_cvg_strt_dt
3098         ,p_fonm_rt_strt_dt      => ben_manage_life_events.g_fonm_rt_strt_dt
3099         ,p_business_group_id    => p_business_group_id
3100         ,p_perform_rounding_flg => TRUE
3101         ,p_value                => l_per_age
3102         ,p_change_date          => l_dummy_date);
3103       --
3104       hr_utility.set_location(' age ' || l_per_age , 610.2);
3105       hr_utility.set_location(' mn age ' || l_inst_set(i).mn_age_num  , 610.2);
3106       --
3107       l_mx_age_num := l_inst_set(i).mx_age_num ;
3108       --
3109       if ( l_inst_set(i).mx_age_num <> trunc(l_inst_set(i).mx_age_num)  OR
3110            l_inst_set(i).mn_age_num <> trunc(l_inst_set(i).mn_age_num) ) then
3111         -- Decimal Case
3112         l_mx_age_num := l_inst_set(i).mx_age_num + 0.000000001 ;
3113         --
3114       else
3115         --
3116         l_mx_age_num := l_inst_set(i).mx_age_num + 1 ;
3117         --
3118       end if;
3119       --
3120       hr_utility.set_location(' l_mx_age_num '||l_mx_age_num , 610.10);
3121       --
3122       l_ok := (l_per_age >= l_inst_set(i).mn_age_num and
3123               l_per_age < l_mx_age_num )
3124              or
3125              (l_inst_set(i).no_mn_age_flag = 'Y' and
3126               l_per_age < l_mx_age_num )
3127              or
3128              (l_inst_set(i).no_mx_age_flag = 'Y' and
3129               l_per_age >= l_inst_set(i).mn_age_num);
3130       --
3131       if l_ok is null or l_per_age is null then
3132       --
3133         --hr_utility.set_location(' Step 1' ,99);
3134         l_ok := false;
3135       --
3136       end if;
3137       --
3138       if l_ok and l_inst_set(i).excld_flag = 'N' then
3139         --
3140         --hr_utility.set_location(' Step 2' ,99);
3141         exit;
3142         --
3143       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
3144         --
3145         --hr_utility.set_location(' Step 3' ,99);
3146         -- raise ben_evaluate_rate_profiles.g_profile_failed;
3147         l_ok := false;
3148         exit ;
3149         --
3150       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
3151         -- Bug 2100564
3152         l_ok := true ;
3153         -- exit ;
3154         --
3155       elsif l_inst_set(i).excld_flag = 'N' then
3156         --
3157         --hr_utility.set_location(' Step 4' ,99);
3158         l_rows_found := true;
3159         --
3160       end if;
3161       --
3162     end loop;
3163     --
3164   end if;
3165   --
3166   if l_rows_found and not l_ok then
3167     --
3168     --hr_utility.set_location(' Step 5 ' ,99);
3169     raise ben_evaluate_rate_profiles.g_profile_failed;
3170     --
3171   end if;
3172   --
3173 end check_age;
3174 --
3175 -- -----------------------------------------------------------
3176 --  Comp level check.
3177 -- -----------------------------------------------------------
3178 --
3179 procedure check_comp_level
3180   (p_vrbl_rt_prfl_id        in number
3181   ,p_person_id              in number
3182   ,p_business_group_id      in number
3183   ,p_effective_date         in date
3184   ,p_lf_evt_ocrd_dt         in date
3185   ,p_elig_per_elctbl_chc_id in number
3186   ,p_pl_id                  in number default null
3187   ,p_pgm_id                 in number default null
3188   ,p_oipl_id                in number default null
3189   ,p_per_in_ler_id          in number default null)
3190 is
3191   --
3192   l_pl_id              number;
3193   l_pgm_id             number;
3194   l_per_in_ler_id      number;
3195   l_oipl_id            number;
3196   l_compensation_value number;
3197   l_mx_comp_val        number;
3198   l_effective_date     date ;
3199   --
3200   --    Grab needed parameters for passing into determin_age procedure.
3201   --
3202   cursor c_comp_param is
3203     select epe.pl_id, epe.pgm_id, epe.oipl_id, epe.per_in_ler_id
3204     from   ben_elig_per_elctbl_chc epe
3205     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
3206   --
3207   l_proc            varchar2(80) := g_package||'.check_comp_level';
3208   l_inst_set ben_rt_prfl_cache.g_complvl_inst_tbl;
3209   l_inst_count number;
3210   l_ok boolean := false;
3211   l_rows_found boolean := false;
3212   --
3213 begin
3214   --
3215    --- fonm2
3216   l_effective_date  := nvl(  p_lf_evt_ocrd_dt,  p_effective_date ) ;
3217   if ben_manage_life_events.fonm = 'Y' then
3218      --
3219       l_effective_date  :=  nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
3220                             nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
3221                                 l_effective_date));
3222      --
3223   end if;
3224 
3225   if p_elig_per_elctbl_chc_id is not null then
3226     --
3227     open c_comp_param;
3228       --
3229       fetch c_comp_param into l_pl_id, l_pgm_id, l_oipl_id, l_per_in_ler_id;
3230       --
3231     close c_comp_param;
3232     --
3233   else
3234     --
3235     l_pl_id         := p_pl_id;
3236     l_pgm_id        := p_pgm_id;
3237     l_oipl_id       := p_oipl_id;
3238     l_per_in_ler_id := p_per_in_ler_id;
3239     --
3240   end if;
3241   --
3242   -- Get the data from the cache.
3243   --
3244   ben_rt_prfl_cache.get_rt_prfl_cache
3245     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
3246     ,p_effective_date    => p_effective_date
3247     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3248     ,p_business_group_id => p_business_group_id
3249     ,p_inst_set          => l_inst_set
3250     ,p_inst_count        => l_inst_count);
3251   --
3252   if l_inst_count > 0 then
3253     --
3254     -- Data found. Loop through to see if excld flag is on or off.
3255     --
3256     l_rows_found := true;
3257     --
3258     for i in l_inst_set.first..l_inst_set.last loop
3259       --
3260       if l_inst_set(i).comp_lvl_fctr_id is null then
3261         --
3262         fnd_message.set_name('BEN','BEN_91526_BERP_CMP_LVL_FCTR_ID');
3263         fnd_message.set_token('L_PROC',l_proc);
3264         fnd_message.set_token('PERSON_ID',to_char(p_person_id));
3265         fnd_message.set_token('VRBL_RT_PRFL_ID',to_char(p_vrbl_rt_prfl_id));
3266         fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
3267         fnd_message.set_token('PL_ID',to_char(p_pl_id));
3268         fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
3269         fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
3270         fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
3271         fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',to_char(p_elig_per_elctbl_chc_id));
3272         fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3273         fnd_message.raise_error;
3274         --
3275       end if;
3276       --
3277       ben_derive_factors.determine_compensation
3278             (p_comp_lvl_fctr_id     => l_inst_set(i).comp_lvl_fctr_id
3279             ,p_person_id            => p_person_id
3280             ,p_pgm_id               => l_pgm_id
3281             ,p_pl_id                => l_pl_id
3282             ,p_oipl_id              => l_oipl_id
3283             ,p_per_in_ler_id        => l_per_in_ler_id
3284             ,p_business_group_id    => p_business_group_id
3285             ,p_perform_rounding_flg => true
3286             ,p_effective_date       => p_effective_date
3287             ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt
3288 
3289             ,p_fonm_cvg_strt_dt     => ben_manage_life_events.g_fonm_cvg_strt_dt
3290             ,p_fonm_rt_strt_dt      => ben_manage_life_events.g_fonm_rt_strt_dt
3291             ,p_value                => l_compensation_value);
3292 
3293       hr_utility.set_location( ' compen ' || l_compensation_value , 610.2) ;
3294       hr_utility.set_location( ' mn compen ' ||  l_inst_set(i).mn_comp_val   , 610.2) ;
3295       --
3296       -- Bug 2101937 fixes
3297       l_mx_comp_val := l_inst_set(i).mx_comp_val ;
3298       --
3299       if ( l_inst_set(i).mx_comp_val <> trunc(l_inst_set(i).mx_comp_val)  OR
3300            l_inst_set(i).mn_comp_val <> trunc(l_inst_set(i).mn_comp_val) ) then
3301         -- Decimal Case
3302         l_mx_comp_val := l_inst_set(i).mx_comp_val + 0.000000001 ;
3303         --
3304       else
3305         --
3306         l_mx_comp_val := l_inst_set(i).mx_comp_val + 1 ;
3307         --
3308       end if;
3309       --
3310       hr_utility.set_location('if' , 610) ;
3311       --
3312       l_ok := (nvl(l_compensation_value,-1) >= l_inst_set(i).mn_comp_val and
3313                nvl(l_compensation_value,9999999) < l_mx_comp_val )
3314               or
3315               (l_inst_set(i).no_mn_comp_flag = 'Y' and
3316                nvl(l_compensation_value,9999999) < l_mx_comp_val )
3317               or
3318               (l_inst_set(i).no_mx_comp_flag = 'Y' and
3319                nvl(l_compensation_value,-1) >= l_inst_set(i).mn_comp_val);
3320 
3321 
3322       --
3323       if l_ok is null or l_compensation_value is null then
3324       --
3325         l_ok := false;
3326       --
3327       end if;
3328       --
3329       if l_ok and l_inst_set(i).excld_flag = 'N' then
3330         --
3331         exit;
3332         --
3333       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
3334         --
3335         -- raise ben_evaluate_rate_profiles.g_profile_failed;
3336         l_ok := false;
3337         exit ;
3338         --
3339       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
3340         -- Bug 2100564
3341         l_ok := true ;
3342         -- exit ;
3343         --
3344       elsif l_inst_set(i).excld_flag = 'N' then
3345         --
3346         l_rows_found := true;
3347         --
3348       end if;
3349       --
3350     end loop;
3351     --
3352   end if;
3353   --
3354   if l_rows_found and not l_ok then
3355     --
3356     raise ben_evaluate_rate_profiles.g_profile_failed;
3357     --
3358   end if;
3359   --
3360 end check_comp_level;
3361 --
3362 -- -----------------------------------------------------------
3363 --     LOS check.
3364 -- -----------------------------------------------------------
3365 --
3366 procedure check_los
3367   (p_vrbl_rt_prfl_id        in number
3368   ,p_person_id              in number
3369   ,p_business_group_id      in number
3370   ,p_effective_date         in date
3371   ,p_lf_evt_ocrd_dt         in date
3372   ,p_elig_per_elctbl_chc_id in number
3373   ,p_pl_id                  in number default null
3374   ,p_pgm_id                 in number default null
3375   ,p_oipl_id                in number default null
3376   ,p_plip_id                in number default null
3377   ,p_opt_id                 in number default null
3378   ,p_per_in_ler_id          in number default null
3379   ,p_currepe_row            in ben_determine_rates.g_curr_epe_rec)
3380 is
3381   --
3382   l_rows_found        boolean := false;
3383   l_pl_id             number;
3384   l_oipl_id           number;
3385   l_pgm_id            number;
3386   l_plip_id           number;
3387   l_per_los           number;
3388   l_per_in_ler_id     number;
3389   l_dummy_date        date;
3390   l_prtn_ovridn_flag  varchar2(30);
3391   l_prtn_ovridn_thru_dt date;
3392   l_epo_row           ben_derive_part_and_rate_facts.g_cache_structure;
3393   l_effective_date   date ;
3394   --
3395   --  Grab needed parameters for accessing LOS_VAL.
3396   --
3397   cursor c_elect is
3398     select epe.pl_id, epe.pgm_id, epe.oipl_id, epe.per_in_ler_id
3399     from   ben_elig_per_elctbl_chc epe
3400     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
3401   --
3402   l_inst_set ben_rt_prfl_cache.g_los_inst_tbl;
3403   l_inst_count number;
3404   l_ok boolean := false;
3405   l_mx_los_num number ;
3406   --
3407 begin
3408   --
3409   -- retrieve electble choice data needed
3410   --
3411 
3412     --- fonm2
3413   l_effective_date  := nvl(  p_lf_evt_ocrd_dt,  p_effective_date ) ;
3414   if ben_manage_life_events.fonm = 'Y' then
3415      --
3416       l_effective_date  :=  nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
3417                             nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
3418                                 l_effective_date));
3419      --
3420   end if;
3421 
3422 
3423 
3424   if p_elig_per_elctbl_chc_id is not null then
3425      --
3426      open c_elect;
3427        --
3428        fetch c_elect into l_pl_id,
3429                           l_pgm_id,
3430                           l_oipl_id,
3431                           l_per_in_ler_id;
3432        --
3433      close c_elect;
3434      --
3435   else
3436      --
3437      l_pl_id         := p_pl_id;
3438      l_pgm_id        := p_pgm_id;
3439      l_oipl_id       := p_oipl_id;
3440      l_per_in_ler_id := p_per_in_ler_id;
3441      --
3442   end if;
3443   --
3444   -- Get the data from the cache.
3445   --
3446   hr_utility.set_location('p_vrbl_rt_prfl_id rate level '||p_vrbl_rt_prfl_id,10);
3447   --
3448   ben_rt_prfl_cache.get_rt_prfl_cache
3449     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
3450     ,p_effective_date    => p_effective_date
3451     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3452     ,p_business_group_id => p_business_group_id
3453     ,p_inst_set          => l_inst_set
3454     ,p_inst_count        => l_inst_count);
3455   --
3456   hr_utility.set_location('l_per_los rate level '||l_per_los,10);
3457   hr_utility.set_location('l_inst_count '||l_inst_count,10);
3458   --
3459   if l_inst_count > 0 then
3460     --
3461     -- plan in program is overriden, capture the data from cache by passing plip_id
3462     if p_opt_id is null and p_pgm_id is not null then
3463        ben_pep_cache.get_pilpep_dets(
3464             p_person_id         => p_person_id,
3465             p_business_group_id => p_business_group_id,
3466             p_effective_date    => l_effective_date,
3467             p_pgm_id            => p_pgm_id,
3468             p_plip_id           => p_plip_id,
3469             p_inst_row          => l_epo_row);
3470             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3471             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3472             l_per_los             := l_epo_row.rt_los_val;
3473     elsif p_opt_id is not null and p_pgm_id is not null then
3474             ben_pep_cache.get_pilepo_dets(
3475             p_person_id         => p_person_id,
3476             p_business_group_id => p_business_group_id,
3477             p_effective_date    => l_effective_date,
3478             p_pgm_id            => p_pgm_id,
3479             p_plip_id           => p_plip_id,
3480             p_opt_id            => p_opt_id,
3481             p_inst_row          => l_epo_row);
3482             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3483             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3484             l_per_los             := l_epo_row.rt_los_val;
3485     else
3486           hr_utility.set_location('Plan not in Program',10);
3487            l_prtn_ovridn_flag    := p_currepe_row.prtn_ovridn_flag;
3488            l_prtn_ovridn_thru_dt := p_currepe_row.prtn_ovridn_thru_dt;
3489            l_per_los             := p_currepe_row.rt_los_val;
3490     end if;
3491 
3492     -- Data found. Loop through to see if excld flag is on or off.
3493     --
3494     l_rows_found := true;
3495     --
3496     for i in l_inst_set.first..l_inst_set.last loop
3497      -- if the variable rate is overriden then don't call determine_los
3498      --RCHASE - v115.57 wrap l_prtn_ovridn_flag with NVL,
3499      --         possible NULL return instead of expected TRUE or FALSE
3500      -- Bug 9033589: Commented the if condition below
3501      /*
3502      if not (nvl(l_prtn_ovridn_flag,'N') = 'Y' and
3503                nvl(l_prtn_ovridn_thru_dt,hr_api.g_eot) > p_effective_date)
3504           then
3505      */
3506     --
3507       ben_derive_factors.determine_los
3508          (p_person_id            => p_person_id
3509          ,p_los_fctr_id          => l_inst_set(i).los_fctr_id
3510          ,p_per_in_ler_id        => l_per_in_ler_id
3511          ,p_pgm_id               => l_pgm_id
3512          ,p_pl_id                => l_pl_id
3513          ,p_oipl_id              => l_oipl_id
3514          ,p_effective_date       => p_effective_date
3515          ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt
3516          --fonm
3517          ,p_fonm_cvg_strt_dt     => ben_manage_life_events.g_fonm_cvg_strt_dt
3518          ,p_fonm_rt_strt_dt      => ben_manage_life_events.g_fonm_rt_strt_dt
3519          ,p_business_group_id    => p_business_group_id
3520          ,p_perform_rounding_flg => TRUE
3521          ,p_value                => l_per_los
3522          ,p_start_date           => l_dummy_date);
3523       --
3524       hr_utility.set_location( ' los ' || l_per_los , 610.2);
3525       -- Bug 2101937 fixes
3526       l_mx_los_num := l_inst_set(i).mx_los_num ;
3527       --
3528       if ( l_inst_set(i).mx_los_num <> trunc(l_inst_set(i).mx_los_num)  OR
3529            l_inst_set(i).mn_los_num <> trunc(l_inst_set(i).mn_los_num) ) then
3530         -- Decimal Case
3531         l_mx_los_num := l_inst_set(i).mx_los_num + 0.000000001 ;
3532         --
3533       else
3534         --
3535         l_mx_los_num := l_inst_set(i).mx_los_num + 1 ;
3536         --
3537       end if;
3538       --
3539       l_ok := (nvl(l_per_los,-1) >= l_inst_set(i).mn_los_num and
3540                nvl(l_per_los,999999) < l_mx_los_num )
3541              or
3542              (l_inst_set(i).no_mn_los_num_apls_flag = 'Y' and
3543               nvl(l_per_los,999999) < l_mx_los_num )
3544 
3545              or
3546              (l_inst_set(i).no_mx_los_num_apls_flag = 'Y' and
3547               nvl(l_per_los,-1) >= l_inst_set(i).mn_los_num);
3548       --
3549       if l_ok and l_inst_set(i).excld_flag = 'N' then
3550         --
3551         exit;
3552         --
3553       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
3554         --
3555         l_rows_found := true;
3556         l_ok := false;
3557         exit;
3558         --
3559       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
3560         -- Bug 2100564
3561         l_rows_found := true;
3562         l_ok := true ;
3563         -- exit ;
3564         --
3565       elsif l_inst_set(i).excld_flag = 'N' then
3566         --
3567         l_rows_found := true;
3568         --
3569       end if;
3570       --
3571     end loop;
3572     --
3573   end if;
3574   --
3575   if l_rows_found and not l_ok then
3576     --
3577     raise ben_evaluate_rate_profiles.g_profile_failed;
3578     --
3579   end if;
3580   --
3581 end check_los;
3582 --
3583 -- --------------------------------------------------------------------
3584 --  Combination age/los check.
3585 -- --------------------------------------------------------------------
3586 --
3587 procedure check_age_los
3588   (p_vrbl_rt_prfl_id         in number
3589   ,p_person_id               in number
3590   ,p_business_group_id       in number
3591   ,p_effective_date          in date
3592   ,p_lf_evt_ocrd_dt          in date
3593   ,p_elig_per_elctbl_chc_id  in number
3594   ,p_pl_id                   in number default null
3595   ,p_pgm_id                  in number default null
3596   ,p_oipl_id                 in number default null
3597   ,p_plip_id                in number default null
3598   ,p_opt_id                 in number default null
3599   ,p_per_in_ler_id           in number default null
3600   ,p_currepe_row            in ben_determine_rates.g_curr_epe_rec)
3601 is
3602   --
3603   l_pl_id              number;
3604   l_pgm_id             number;
3605   l_per_in_ler_id      number;
3606   l_oipl_id            number;
3607   l_cmbn_age_n_los_val number;
3608   l_dummy_date         date;
3609   l_prtn_ovridn_flag  varchar2(30);
3610   l_prtn_ovridn_thru_dt date;
3611   l_epo_row           ben_derive_part_and_rate_facts.g_cache_structure;
3612   l_effective_date    date ;
3613   --
3614 
3615 
3616   --
3617   --    Grab needed parameters for accessing CMBN_AGE_N_LOS_VAL .
3618   --
3619   cursor c_elect is
3620     select epe.pl_id, epe.pgm_id, epe.oipl_id, epe.per_in_ler_id
3621     from   ben_elig_per_elctbl_chc epe
3622     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
3623   --
3624   l_inst_set ben_rt_prfl_cache.g_age_los_inst_tbl;
3625   l_inst_count number;
3626   l_ok boolean := false;
3627   l_rows_found boolean := false;
3628   --
3629 begin
3630   --
3631       --- fonm2
3632   l_effective_date  := nvl(  p_lf_evt_ocrd_dt,  p_effective_date ) ;
3633   if ben_manage_life_events.fonm = 'Y' then
3634      --
3635       l_effective_date  :=  nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
3636                             nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
3637                                 l_effective_date));
3638      --
3639   end if;
3640 
3641 
3642   -- retrieve electble choice data needed
3643   --
3644   if p_elig_per_elctbl_chc_id is not null then
3645     --
3646     open c_elect;
3647       --
3648       fetch c_elect into l_pl_id,
3649                          l_pgm_id,
3650                          l_oipl_id,
3651                          l_per_in_ler_id;
3652       --
3653     close c_elect;
3654     --
3655   else
3656     --
3657     l_pl_id := p_pl_id;
3658     l_pgm_id := p_pgm_id;
3659     l_oipl_id := p_oipl_id;
3660     l_per_in_ler_id := p_per_in_ler_id;
3661     --
3662   end if;
3663   --
3664   -- Get the data from the cache.
3665   --
3666   ben_rt_prfl_cache.get_rt_prfl_cache
3667     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
3668     ,p_effective_date    => p_effective_date
3669     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3670     ,p_business_group_id => p_business_group_id
3671     ,p_inst_set          => l_inst_set
3672     ,p_inst_count        => l_inst_count);
3673   --
3674   if l_inst_count > 0 then
3675     --
3676      -- plan in program is overriden, capture the data from cache by passing plip_id
3677     if p_opt_id is null and p_pgm_id is not null then
3678        ben_pep_cache.get_pilpep_dets(
3679             p_person_id         => p_person_id,
3680             p_business_group_id => p_business_group_id,
3681             p_effective_date    => l_effective_date,
3682             p_pgm_id            => p_pgm_id,
3683             p_plip_id           => p_plip_id,
3684             p_inst_row          => l_epo_row);
3685             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3686             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3687             l_cmbn_age_n_los_val  := l_epo_row.rt_cmbn_age_n_los_val;
3688     elsif p_opt_id is not null and p_pgm_id is not null then
3689             ben_pep_cache.get_pilepo_dets(
3690             p_person_id         => p_person_id,
3691             p_business_group_id => p_business_group_id,
3692             p_effective_date    => l_effective_date,
3693             p_pgm_id            => p_pgm_id,
3694             p_plip_id           => p_plip_id,
3695             p_opt_id            => p_opt_id,
3696             p_inst_row          => l_epo_row);
3697             l_prtn_ovridn_flag    := l_epo_row.prtn_ovridn_flag;
3698             l_prtn_ovridn_thru_dt := l_epo_row.prtn_ovridn_thru_dt;
3699             l_cmbn_age_n_los_val  := l_epo_row.rt_cmbn_age_n_los_val;
3700     else
3701           hr_utility.set_location('Plan not in Program',10);
3702            l_prtn_ovridn_flag    := p_currepe_row.prtn_ovridn_flag;
3703            l_prtn_ovridn_thru_dt := p_currepe_row.prtn_ovridn_thru_dt;
3704            l_cmbn_age_n_los_val  := p_currepe_row.rt_cmbn_age_n_los_val;
3705     end if;
3706 
3707     -- Data found. Loop through to see if excld flag is on or off.
3708     --
3709     l_rows_found := true;
3710     --
3711     for i in l_inst_set.first..l_inst_set.last loop
3712       --
3713        -- if the variable rate is overriden then don't call determine_los
3714      --RCHASE - v115.57 wrap l_prtn_ovridn_flag with NVL,
3715      --         possible NULL return instead of expected TRUE or FALSE
3716      -- Bug 9033589: Commented the below condition
3717      /*
3718      if not (nvl(l_prtn_ovridn_flag,'N') = 'Y' and
3719                nvl(l_prtn_ovridn_thru_dt,hr_api.g_eot) > p_effective_date)
3720           then
3721      */
3722         --BBULUSU - changed determine_los to determine_comb_age_los below
3723         ben_derive_factors.determine_comb_age_los
3724          (p_person_id            => p_person_id
3725          ,p_cmbn_age_los_fctr_id => l_inst_set(i).cmbn_age_los_fctr_id
3726          ,p_per_in_ler_id        => l_per_in_ler_id
3727          ,p_pgm_id               => l_pgm_id
3728          ,p_pl_id                => l_pl_id
3729          ,p_oipl_id              => l_oipl_id
3730          ,p_effective_date       => p_effective_date
3731          ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt
3732          -- fonm
3733          ,p_fonm_cvg_strt_dt     => ben_manage_life_events.g_fonm_cvg_strt_dt
3734          ,p_fonm_rt_strt_dt      => ben_manage_life_events.g_fonm_rt_strt_dt
3735          ,p_business_group_id    => p_business_group_id
3736          ,p_value                => l_cmbn_age_n_los_val);
3737       --
3738       l_ok := nvl(l_cmbn_age_n_los_val,-1)
3739                 between nvl(l_inst_set(i).cmbnd_min_val,0)
3740                     and nvl(l_inst_set(i).cmbnd_max_val,99999999);
3741       --
3742       if l_ok is null then
3743         --
3744         l_ok := false ;
3745         --
3746       end if;
3747       --
3748       if l_ok and l_inst_set(i).excld_flag = 'N' then
3749         --
3750         exit;
3751         --
3752       elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
3753         --
3754         -- raise ben_evaluate_rate_profiles.g_profile_failed;
3755         l_ok :=  false ;
3756         exit ;
3757         --
3758       elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
3759         -- Bug 2100564
3760         l_ok := true ;
3761         --exit ;
3762         --
3763       elsif l_inst_set(i).excld_flag = 'N' then
3764         --
3765         l_rows_found := true;
3766         --
3767       end if;
3768       --
3769     end loop;
3770     --
3771   end if;
3772   --
3773   if l_rows_found and not l_ok then
3774     --
3775     raise ben_evaluate_rate_profiles.g_profile_failed;
3776     --
3777   end if;
3778   --
3779 end check_age_los;
3780 --
3781 -- ---------------------------------------------------------------
3782 --    Period of enrollment
3783 --   Note:  This profile is only for COBRA. It will be changed later
3784 --          for general use.
3785 -- ---------------------------------------------------------------
3786 --
3787 procedure check_period_of_enrollment
3788   (p_vrbl_rt_prfl_id      in number
3789   ,p_business_group_id    in number
3790   ,p_effective_date       in date
3791   ,p_lf_evt_ocrd_dt       in date
3792   ,p_person_id            in number
3793   ,p_pgm_id               in number default null
3794   ,p_pl_typ_id            in number default null
3795   ,p_ler_id               in number default null) is
3796   --
3797   l_inst_set            ben_rt_prfl_cache.g_poe_inst_tbl;
3798   l_init_lf_evt_ocrd_dt date;
3799   l_inst_count          number;
3800   l_strt_dt             date;
3801   l_end_dt              date;
3802   l_exists              varchar2(1);
3803   l_dsbld               boolean := false;
3804   l_mn_poe_num          ben_poe_rt_f.mn_poe_num%type;
3805   --
3806   cursor c_get_quald_bnf is
3807     select cqb.*, crp.per_in_ler_id
3808     from ben_cbr_quald_bnf cqb
3809         ,ben_cbr_per_in_ler crp
3810         ,ben_per_in_ler pil
3811     where cqb.quald_bnf_person_id = p_person_id
3812     and cqb.quald_bnf_flag = 'Y'
3813     and nvl(p_lf_evt_ocrd_dt,p_effective_date)
3814     between cqb.cbr_elig_perd_strt_dt and
3815             cqb.cbr_elig_perd_end_dt
3816     and cqb.business_group_id = p_business_group_id
3817     and cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
3818     and cqb.pgm_id = nvl(p_pgm_id,cqb.pgm_id)
3819     and nvl(cqb.pl_typ_id,nvl(p_pl_typ_id,-1)) = nvl(p_pl_typ_id,-1)
3820     and crp.per_in_ler_id = pil.per_in_ler_id
3821     and crp.business_group_id = cqb.business_group_id
3822     and pil.business_group_id = crp.business_group_id
3823     and crp.init_evt_flag = 'Y'
3824     and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
3825   --
3826   cursor c_get_all_quald_bnf(p_cvrd_emp_person_id in number) is
3827     select cqb.*
3828     from ben_cbr_quald_bnf cqb
3829         ,ben_cbr_per_in_ler crp
3830         ,ben_per_in_ler pil
3831     where cqb.cvrd_emp_person_id = p_cvrd_emp_person_id
3832     and cqb.quald_bnf_flag = 'Y'
3833     and nvl(p_lf_evt_ocrd_dt,p_effective_date)
3834     between cqb.cbr_elig_perd_strt_dt and
3835             cqb.cbr_elig_perd_end_dt
3836     and cqb.business_group_id = p_business_group_id
3837     and cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
3838     and cqb.pgm_id = nvl(p_pgm_id,cqb.pgm_id)
3839     and nvl(cqb.pl_typ_id,nvl(p_pl_typ_id,-1)) = nvl(p_pl_typ_id,-1)
3840     and crp.per_in_ler_id = pil.per_in_ler_id
3841     and crp.business_group_id = cqb.business_group_id
3842     and pil.business_group_id = crp.business_group_id
3843     and crp.init_evt_flag = 'Y'
3844     and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
3845   --
3846   cursor c_get_dsblity_evt(p_cbr_quald_bnf_id number) is
3847     select null
3848     from ben_cbr_per_in_ler crp
3849        , ben_ler_f ler
3850        , ben_per_in_ler pil
3851     where crp.cbr_quald_bnf_id = p_cbr_quald_bnf_id
3852     and crp.per_in_ler_id = pil.per_in_ler_id
3853     and pil.ler_id = ler.ler_id
3854     and ler.typ_cd = 'DSBLTY'
3855     and ler.qualg_evt_flag = 'Y'
3856     and nvl(p_lf_evt_ocrd_dt,p_effective_date)
3857     between ler.effective_start_date and
3858             ler.effective_end_date
3859     and ler.business_group_id = p_business_group_id
3860     and ler.business_group_id = pil.business_group_id
3861     and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
3862     and crp.cnt_num = (select max(cnt_num)
3863                          from ben_cbr_per_in_ler crp2
3864                               ,ben_per_in_ler pil2
3865                          where crp2.cbr_quald_bnf_id = p_cbr_quald_bnf_id
3866                          and crp2.per_in_ler_id =  pil2.per_in_ler_id
3867                          and pil2.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
3868                          and crp2.business_group_id = p_business_group_id
3869                          and crp2.business_group_id = pil2.business_group_id);
3870   --
3871   cursor c_get_arra_evt(p_cbr_elig_perd_strt_dt date
3872                        ,p_cbr_elig_perd_end_dt  date) is
3873     select null
3874     from  ben_ler_f ler
3875        ,  ben_per_in_ler pil
3876     where ler.ler_id  = pil.ler_id
3877     and   pil.person_id = p_person_id
3878     and   ler.name = 'Assistance Eligible Individual'
3879     and   pil.per_in_ler_stat_cd not in ('VOIDD', 'BCKDT')
3880     and   pil.lf_evt_ocrd_dt
3881           between p_cbr_elig_perd_strt_dt
3882           and p_cbr_elig_perd_end_dt
3883     and   nvl(p_lf_evt_ocrd_dt,p_effective_date)
3884           between ler.effective_start_date
3885           and ler.effective_end_date
3886     and   ler.business_group_id = p_business_group_id
3887     and   pil.business_group_id = ler.business_group_id;
3888 
3889     --
3890     cursor c_ler is
3891       select ler.*
3892       from
3893         ben_ler_f ler
3894       where
3895              ler.ler_id = p_ler_id
3896          and ler.QUALG_EVT_FLAG = 'Y'
3897          and p_effective_date between
3898              ler.effective_start_date and ler.effective_end_date
3899          and ler.business_group_id = p_business_group_id ;
3900    --
3901    l_ler_rec   c_ler%rowtype;
3902 
3903   --
3904   l_cqb_rec   c_get_quald_bnf%rowtype;
3905   l_cqb2_rec   c_get_all_quald_bnf%rowtype;
3906 begin
3907   --
3908   -- Get the data from the cache.
3909   --
3910   ben_rt_prfl_cache.get_rt_prfl_cache
3911     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
3912     ,p_effective_date    => p_effective_date
3913     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3914     ,p_business_group_id => p_business_group_id
3915     ,p_inst_set          => l_inst_set
3916     ,p_inst_count        => l_inst_count);
3917   --
3918   hr_utility.set_location ('l_inst_count:'||l_inst_count,10);
3919   if l_inst_count > 0 then
3920     --
3921     -- Data found. Loop through to see if excld flag is on or off.
3922     --
3923     for i in l_inst_set.first..l_inst_set.last loop
3924       --
3925       --  This profile is only applicable to COBRA qualified
3926       --  beneficiary.
3927       --
3928       open c_get_quald_bnf;
3929       fetch c_get_quald_bnf into l_cqb_rec;
3930       if c_get_quald_bnf%notfound then
3931         hr_utility.set_location ('did not find quald bnf:',10);
3932         close c_get_quald_bnf;
3933           --
3934           -- Bug 1566944 Check for new terminations with qualifying event
3935           --     New a termination life event is processes, system can't find
3936           --     any rows for the person in ben_cbr_quald_bnf. So we are checking the
3937           --     Cobra qualifying event flag for the life event.
3938 
3939              --
3940              open c_ler;
3941              fetch c_ler into l_ler_rec ;
3942               if c_ler%notfound then
3943                 hr_utility.set_location ('not a new qualifying termination event:',10);
3944                 close c_ler;
3945                 raise ben_evaluate_rate_profiles.g_profile_failed;
3946               else
3947                 close c_ler;
3948                 --  Calculate the start date.
3949                 --
3950                 if l_inst_set(i).no_mn_poe_flag = 'N' then
3951                 --
3952                 --  We need to get the first day of the period of enrollment.
3953                 --
3954                    if l_inst_set(i).mn_poe_num > 1 then
3955                       l_mn_poe_num := l_inst_set(i).mn_poe_num - 1;
3956                    end if;
3957                    --
3958                    l_strt_dt := (benutils.derive_date
3959                          (p_date      => nvl(p_lf_evt_ocrd_dt,p_effective_date) -- l_cqb_rec.cbr_elig_perd_strt_dt
3960                          ,p_uom       => l_inst_set(i).poe_nnmntry_uom
3961                          ,p_min       => null
3962                          ,p_max       => l_mn_poe_num
3963                          ,p_value     => null
3964                          )) + 1;
3965                 else
3966                       l_strt_dt := hr_api.g_sot;
3967                 end if;
3968                 --
3969                 hr_utility.set_location ('l_strt_dt '||l_strt_dt, 199);
3970                 --  Calculate the end date.
3971                 --
3972                 if l_inst_set(i).no_mx_poe_flag = 'N' then
3973                    l_end_dt := benutils.derive_date
3974                         (p_date      =>  nvl(p_lf_evt_ocrd_dt,p_effective_date) -- l_cqb_rec.cbr_elig_perd_strt_dt
3975                         ,p_uom       => l_inst_set(i).poe_nnmntry_uom
3976                         ,p_min       => null
3977                         ,p_max       => l_inst_set(i).mx_poe_num
3978                         ,p_value     => null
3979                         );
3980                 else
3981                    l_end_dt := hr_api.g_eot;
3982                 end if;
3983                 --
3984                 hr_utility.set_location ('l_end_dt '||l_end_dt , 199);
3985                 --
3986                 if nvl(p_lf_evt_ocrd_dt, p_effective_date) not between
3987                     l_strt_dt and l_end_dt then
3988                     raise ben_evaluate_rate_profiles.g_profile_failed;
3989                 end if;
3990                 --
3991                 --  arra event
3992                 --
3993                 if (l_inst_set(i).cbr_dsblty_apls_flag = 'N'
3994                     and l_ler_rec.name <> 'Assistance Eligible Individual') then
3995                   raise ben_evaluate_rate_profiles.g_profile_failed;
3996                 end if;
3997                 --
3998                 goto l_ler ;
3999                 --
4000               end if ;
4001 
4002 
4003         raise ben_evaluate_rate_profiles.g_profile_failed;
4004       else
4005         close c_get_quald_bnf;
4006         --
4007         --  Calculate the start date.
4008         --
4009         if l_inst_set(i).no_mn_poe_flag = 'N' then
4010           --
4011           --  We need to get the first day of the period of enrollment.
4012           --
4013           if l_inst_set(i).mn_poe_num > 1 then
4014              l_mn_poe_num := l_inst_set(i).mn_poe_num - 1;
4015           end if;
4016           --
4017           l_strt_dt := (benutils.derive_date
4018                          (p_date      => l_cqb_rec.cbr_elig_perd_strt_dt
4019                          ,p_uom       => l_inst_set(i).poe_nnmntry_uom
4020                          ,p_min       => null
4021                          ,p_max       => l_mn_poe_num
4022                          ,p_value     => null
4023                          ));
4024           hr_utility.set_location ('l_strt_dt '||l_strt_dt, 200);
4025         else
4026           l_strt_dt := hr_api.g_sot;
4027         end if;
4028         --
4029         --  Calculate the end date.
4030         --
4031         if l_inst_set(i).no_mx_poe_flag = 'N' then
4032           l_end_dt := benutils.derive_date
4033                         (p_date      => l_cqb_rec.cbr_elig_perd_strt_dt
4034                         ,p_uom       => l_inst_set(i).poe_nnmntry_uom
4035                         ,p_min       => null
4036                         ,p_max       => l_inst_set(i).mx_poe_num
4037                         ,p_value     => null
4038                         );
4039         else
4040           l_end_dt := hr_api.g_eot;
4041         end if;
4042         --
4043         --  Disability rates applies if:
4044         --  1) if the last qualifying event that the person experienced
4045         --  is disability.  He/she has not experience another event within
4046         --  the 18 month period that entitles them to a longer eligibility
4047         --  period.
4048         --
4049         --  2) If the person was disabled at the time of
4050         --  the qualifying event.
4051         --  Disability rates does not apply if the disabled person
4052         --  is no longer covered. All other qualified beneficiary cannot
4053         --  be charge more than the 102%
4054         --
4055         if l_inst_set(i).cbr_dsblty_apls_flag = 'Y' then
4056           --
4057           --  Check if one of the qualified beneficiaries
4058           --  is disabled.
4059           --
4060           l_dsbld := false;
4061           --
4062           for l_cqb2_rec in c_get_all_quald_bnf(l_cqb_rec.cvrd_emp_person_id)
4063           loop
4064             if ben_cobra_requirements.chk_dsbld
4065                  (p_person_id         => l_cqb2_rec.quald_bnf_person_id
4066                  ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4067                  ,p_effective_date    => p_effective_date
4068                  ,p_business_group_id => p_business_group_id) = true then
4069               --
4070               --  Check if person was disabled at the time of the qualifying
4071               --  event.
4072               --
4073               l_init_lf_evt_ocrd_dt
4074                 := ben_cobra_requirements.get_lf_evt_ocrd_dt
4075                      (p_per_in_ler_id     => l_cqb_rec.per_in_ler_id
4076                      ,p_business_group_id => p_business_group_id
4077                      );
4078               if ben_cobra_requirements.chk_dsbld
4079                 (p_person_id         => l_cqb2_rec.quald_bnf_person_id
4080                 ,p_lf_evt_ocrd_dt    => l_init_lf_evt_ocrd_dt
4081                 ,p_effective_date    => p_effective_date
4082                 ,p_business_group_id => p_business_group_id) = false then
4083                 --
4084                 --  Check if person was disabled within the first 60
4085                 --  days of the qualifying event.
4086                 --
4087                 open c_get_dsblity_evt(l_cqb_rec.cbr_quald_bnf_id);
4088                 fetch c_get_dsblity_evt into l_exists;
4089                 if c_get_dsblity_evt%notfound then
4090                   close c_get_dsblity_evt;
4091                   --
4092                 else
4093                   hr_utility.set_location ('disability rate applies 60 :',10);
4094                   close c_get_dsblity_evt;
4095                   l_dsbld := true;
4096                   exit;
4097                 end if;
4098               else
4099                 hr_utility.set_location ('disability rate applies tom :',10);
4100                 l_dsbld := true;
4101                 exit;
4102               end if;
4103             end if;
4104           end loop;
4105           --
4106           if l_dsbld = false then
4107             raise ben_evaluate_rate_profiles.g_profile_failed;
4108           end if;
4109         else
4110           --
4111           -- arra event
4112           --
4113           open c_get_arra_evt(l_cqb_rec.cbr_elig_perd_strt_dt
4114                                ,l_cqb_rec.cbr_elig_perd_end_dt
4115                                 );
4116           fetch c_get_arra_evt into l_exists;
4117           if c_get_arra_evt%notfound then
4118             hr_utility.set_location ('event not found',10);
4119             close c_get_arra_evt;
4120             raise ben_evaluate_rate_profiles.g_profile_failed;
4121           else
4122             hr_utility.set_location ('event found',10);
4123             close c_get_arra_evt;
4124             l_end_dt := l_end_dt - 1;
4125             hr_utility.set_location ('l_end_dt '||l_end_dt,10);
4126           end if;
4127         end if;
4128         --
4129         if nvl(p_lf_evt_ocrd_dt, p_effective_date) not between
4130           l_strt_dt and l_end_dt then
4131           hr_utility.set_location ('l_strt_dt'||l_strt_dt,10);
4132           raise ben_evaluate_rate_profiles.g_profile_failed;
4133         end if;
4134           hr_utility.set_location ('p_lf_evt_ocrd_dt'||p_lf_evt_ocrd_dt,10);
4135       end if; -- qualified beneficiary
4136       --
4137       <<l_ler>>
4138       null;
4139     end loop;
4140     --
4141   end if;
4142   --
4143 end check_period_of_enrollment;
4144 --
4145 -- ---------------------------------------------------------------
4146 --    ttl_prtt check
4147 -- ---------------------------------------------------------------
4148 --
4149 procedure check_ttl_prtt
4150   (p_vrbl_rt_prfl_id      in number
4151   ,p_business_group_id    in number
4152   ,p_effective_date       in date
4153   ,p_lf_evt_ocrd_dt       in date
4154   ,p_ttl_prtt             in number default null)
4155 is
4156   --
4157   l_proc          varchar2(80) := g_package||'.check_ttl_prtt';
4158   l_inst_set      ben_rt_prfl_cache.g_ttl_prtt_inst_tbl;
4159   l_inst_count    number;
4160   l_profile_match varchar2(1);
4161   --
4162 begin
4163   hr_utility.set_location ('check_ttl_prtt:'||to_char(p_ttl_prtt),10);
4164 
4165   --
4166   -- Get the data from the cache.
4167   --
4168   ben_rt_prfl_cache.get_rt_prfl_cache
4169     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4170     ,p_effective_date    => p_effective_date
4171     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4172     ,p_business_group_id => p_business_group_id
4173     ,p_inst_set          => l_inst_set
4174     ,p_inst_count        => l_inst_count);
4175 
4176 
4177   l_profile_match := 'N';
4178   if l_inst_count > 0 then
4179     if p_ttl_prtt is null then
4180         -- there are variable profile criteria for total number of participants
4181         -- attached, but the process did not pass in a the number of prtts.
4182         fnd_message.set_name('BEN','BEN_92244_TTL_PRTT_REQUIRED');
4183         fnd_message.set_token('L_PROC',l_proc);
4184         fnd_message.set_token('VRBL_RT_PRFL_ID',to_char(p_vrbl_rt_prfl_id));
4185         fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
4186         fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4187         fnd_message.raise_error;
4188     end if;
4189     --
4190     -- Data found. Loop through to see we match the total number of prtts.
4191     --
4192     for i in l_inst_set.first..l_inst_set.last loop
4193       hr_utility.set_location ('p_ttl:'||to_char(p_ttl_prtt)||
4194       ' min:'||to_char(l_inst_set(i).mn_prtt_num)||' max:'||
4195       to_char(l_inst_set(i).mx_prtt_num),33);
4196 
4197       if p_ttl_prtt between nvl(l_inst_set(i).mn_prtt_num,0)
4198          and  nvl(l_inst_set(i).mx_prtt_num,999999999999999) then
4199         -- we match one of the ranges, exit with success.
4200         l_profile_match := 'Y';
4201         exit;
4202       end if;
4203     end loop;
4204 
4205     if l_profile_match = 'N' then
4206       raise ben_evaluate_rate_profiles.g_profile_failed;
4207     end if;
4208 
4209   end if;
4210 end check_ttl_prtt;
4211 
4212 -- --------------------------------------------------
4213 --  JOB RATE.
4214 -- --------------------------------------------------
4215 procedure check_job(p_vrbl_rt_prfl_id   in number,
4216                     p_business_group_id in number,
4217                     p_effective_date    in date,
4218                     p_lf_evt_ocrd_dt    in date,
4219                     p_job_id            in number) is
4220   --
4221   l_proc       	varchar2(100) := g_package||'check_job';
4222   l_inst_set 	ben_rt_prfl_cache.g_job_inst_tbl;
4223   l_inst_count 	number;
4224   l_ok 		boolean := false;
4225   l_rows_found 	boolean := false;
4226   --
4227 begin
4228   --
4229   hr_utility.set_location('Entering : '||l_proc,10);
4230   --
4231   -- Get the data from the cache.
4232   --
4233   ben_rt_prfl_cache.get_rt_prfl_cache
4234     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4235     ,p_effective_date    => p_effective_date
4236     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4237     ,p_business_group_id => p_business_group_id
4238     ,p_inst_set          => l_inst_set
4239     ,p_inst_count        => l_inst_count);
4240 
4241   --
4242   if l_inst_count > 0 then
4243       --
4244       -- Data found. Loop through to see if excld flag is on or off.
4245       --
4246       l_rows_found := true;
4247       --
4248       for i in l_inst_set.first..l_inst_set.last loop
4249         --
4250         l_ok := l_inst_set(i).job_id = p_job_id;
4251         --
4252         if l_ok is null or p_job_id is null then
4253         --
4254           l_ok := false;
4255         --
4256         end if;
4257         --
4258         if l_ok and l_inst_set(i).excld_flag = 'N' then
4259           --
4260           exit;
4261           --
4262         elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
4263           --
4264           -- raise g_criteria_failed;
4265           l_ok := false;
4266           exit ;
4267           --
4268         elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
4269           --
4270           l_ok := true ;
4271           --
4272         elsif l_inst_set(i).excld_flag = 'N' then
4273           --
4274           l_rows_found := true;
4275           --
4276         end if;
4277         --
4278       end loop;
4279       --
4280     end if;
4281     --
4282     if l_rows_found and not l_ok then
4283       --
4284       raise g_criteria_failed;
4285       --
4286     end if;
4287     --
4288 end check_job;
4289 
4290 
4291 -- --------------------------------------------------
4292 --  OPTED FOR MEDICARE.
4293 -- --------------------------------------------------
4294 procedure check_optd_mdcr(p_vrbl_rt_prfl_id    in number,
4295                     		p_business_group_id in number,
4296                     		p_effective_date    in date,
4297 	                        p_lf_evt_ocrd_dt    in date,
4298                     		p_person_id         in number) is
4299   --
4300   l_proc       	varchar2(100) := g_package||'check_optd_for_medicare';
4301   l_inst_set 	ben_rt_prfl_cache.g_optd_mdcr_inst_tbl;
4302   l_inst_count 	number;
4303   l_ok 		boolean := false;
4304   l_rows_found 	boolean := false;
4305   l_rec		per_all_people_f%rowtype;
4306   --
4307 begin
4308   --
4309   hr_utility.set_location('Entering : '||l_proc,10);
4310   --
4311   -- Get the data from the cache.
4312   --
4313   ben_rt_prfl_cache.get_rt_prfl_cache
4314     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4315     ,p_effective_date    => p_effective_date
4316     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4317     ,p_business_group_id => p_business_group_id
4318     ,p_inst_set          => l_inst_set
4319     ,p_inst_count        => l_inst_count);
4320 
4321   --
4322   if l_inst_count > 0 then
4323       ben_person_object.get_object(p_person_id => p_person_id,
4324                                    p_rec       => l_rec);
4325       --
4326       for l_num in l_inst_set.first .. l_inst_set.last loop
4327       --
4328       	   l_rows_found := true;
4329       	   l_ok := nvl((nvl(l_rec.per_information10,'N') =
4330            l_inst_set(l_num).optd_mdcr_flag),FALSE);
4331       --
4332       --  There is only one row so there is no need to do further checking.
4333       --
4334       end loop;
4335   end if;
4336   --
4337   if l_rows_found and not l_ok then
4338       --
4339       raise g_criteria_failed;
4340       --
4341   end if;
4342   --
4343 end check_optd_mdcr;
4344 
4345 -- --------------------------------------------------
4346 --  LEAVING REASON
4347 -- --------------------------------------------------
4348 procedure check_lvg_rsn(p_vrbl_rt_prfl_id    in number,
4349                     	p_business_group_id  in number,
4350                     	p_effective_date     in date,
4351                     	p_lf_evt_ocrd_dt     in date,
4352                     	p_person_id          in number) is
4353   --
4354   l_proc       	varchar2(100) := g_package||'check_lvg_rsn';
4355   l_inst_set 	ben_rt_prfl_cache.g_lvg_rsn_inst_tbl;
4356   l_inst_count 	number;
4357   l_ok 		boolean := false;
4358   l_rows_found 	boolean := false;
4359   l_rec		per_periods_of_service%rowtype;
4360   --
4361 begin
4362   --
4363   hr_utility.set_location('Entering : '||l_proc,10);
4364   --
4365   -- Get the data from the cache.
4366   --
4367   ben_rt_prfl_cache.get_rt_prfl_cache
4368     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4369     ,p_effective_date    => p_effective_date
4370     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4371     ,p_business_group_id => p_business_group_id
4372     ,p_inst_set          => l_inst_set
4373     ,p_inst_count        => l_inst_count);
4374 
4375   --
4376   if l_inst_count > 0 then
4377     ben_person_object.get_object(p_person_id => p_person_id,
4378                                  p_rec       => l_rec);
4379       --
4380       for i in l_inst_set.first..l_inst_set.last loop
4381       --
4382 	      l_rows_found := true;
4383 	      l_ok := nvl((nvl(l_rec.leaving_reason,'-1') =
4384 		      l_inst_set(i).lvg_rsn_cd),FALSE);
4385 	      --
4386 	      if l_ok = true then
4387 		if l_inst_set(i).excld_flag = 'Y' then
4388 		  --
4389 		  l_ok := false;
4390 		  exit ;
4391 		  --
4392 		else
4393 		  --
4394 		  exit;
4395 		  --
4396 		end if;
4397 	      elsif l_inst_set(i).excld_flag = 'Y' then
4398 		--
4399 		l_ok := true;
4400 		-- exit;
4401 		--
4402 	      end if;
4403       --
4404     end loop;
4405   end if;
4406   --
4407   if l_rows_found and not l_ok then
4408       --
4409       raise g_criteria_failed;
4410       --
4411   end if;
4412   --
4413 end check_lvg_rsn;
4414 
4415 
4416 -- --------------------------------------------------
4417 --  COBRA QUALIFIED BENEFICIARY
4418 -- --------------------------------------------------
4419 procedure check_cbr_quald_bnf(p_vrbl_rt_prfl_id    in number,
4420                     	     p_business_group_id  in number,
4421                     	     p_effective_date     in date,
4422                     	     p_person_id          in number,
4423                     	     p_lf_evt_ocrd_dt     in date) is
4424   --
4425   l_proc       	varchar2(100) := g_package||'check_cbr_quald_bnf';
4426   l_inst_set 	ben_rt_prfl_cache.g_cbr_qual_bnf_inst_tbl;
4427   l_inst_count 	number;
4428   l_ok 		boolean := false;
4429   l_rows_found 	boolean := false;
4430   l_rec		per_all_people_f%rowtype;
4431   l_quald_bnf_flag   ben_cbr_quald_bnf.quald_bnf_flag%type;
4432   --
4433   cursor c1(p_person_id      in number
4434             ,p_lf_evt_ocrd_dt in date
4435             ,p_pgm_id         in number
4436             ,p_ptip_id        in number) is
4437   select cqb.quald_bnf_flag
4438   from   ben_cbr_quald_bnf  cqb
4439         ,ben_cbr_per_in_ler crp
4440         ,ben_per_in_ler     pil
4441   where cqb.quald_bnf_person_id = p_person_id
4442   and cqb.pgm_id = nvl(p_pgm_id,cqb.pgm_id)
4443   and nvl(cqb.ptip_id,-1) = nvl(p_ptip_id, -1)
4444   and p_lf_evt_ocrd_dt
4445   between nvl(cqb.cbr_elig_perd_strt_dt , p_lf_evt_ocrd_dt)
4446   and     nvl(cqb.cbr_elig_perd_end_dt , p_lf_evt_ocrd_dt)
4447   and cqb.business_group_id  = p_business_group_id
4448   and cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
4449   and crp.per_in_ler_id = pil.per_in_ler_id
4450   and crp.business_group_id = cqb.business_group_id
4451   and crp.init_evt_flag = 'Y'
4452   and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
4453 
4454 begin
4455   --
4456   hr_utility.set_location('Entering : '||l_proc,10);
4457   --
4458   -- Get the data from the cache.
4459   --
4460   ben_rt_prfl_cache.get_rt_prfl_cache
4461     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4462     ,p_effective_date    => p_effective_date
4463     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4464     ,p_business_group_id => p_business_group_id
4465     ,p_inst_set          => l_inst_set
4466     ,p_inst_count        => l_inst_count);
4467 
4468   --
4469   if l_inst_count > 0 then
4470       ben_person_object.get_object(p_person_id => p_person_id,
4471                                    p_rec       => l_rec);
4472       --
4473       for i in l_inst_set.first..l_inst_set.last loop
4474       --
4475 	      l_rows_found := true;
4476 	      -- FONM
4477 	      open c1(p_person_id
4478 		     ,nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
4479                        nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
4480                          nvl(p_lf_evt_ocrd_dt,p_effective_date)))
4481 		     ,l_inst_set(i).pgm_id
4482 		     ,l_inst_set(i).ptip_id);
4483 	      fetch c1 into l_quald_bnf_flag;
4484 	      if c1%found then
4485 		l_ok := nvl((nvl(l_quald_bnf_flag,'-1') = l_inst_set(i).quald_bnf_flag),FALSE);
4486 	      else
4487 		l_ok := nvl((l_inst_set(i).quald_bnf_flag = 'N'),FALSE);
4488 	      end if;
4489 	      close c1;
4490 
4491 	      if l_ok then
4492 		exit;
4493 	      end if;
4494 	      --
4495       end loop;
4496   end if;
4497   --
4498   if l_rows_found and not l_ok then
4499       --
4500       raise g_criteria_failed;
4501       --
4502   end if;
4503   --
4504 end check_cbr_quald_bnf;
4505 
4506 
4507 -- --------------------------------------------------
4508 --  DEPENDENT COVERED OTHER PLAN
4509 -- --------------------------------------------------
4510 procedure check_dpnt_cvrd_othr_pl(p_vrbl_rt_prfl_id    in number,
4511                     	     p_business_group_id  in number,
4512                     	     p_effective_date     in date,
4513                     	     p_person_id          in number ,
4514                     	     p_lf_evt_ocrd_dt     in date) is
4515   --
4516   l_proc       	varchar2(100) := g_package||'check_dpnt_cvrd_othr_pl';
4517   l_inst_set 	ben_rt_prfl_cache.g_dpnt_cvrd_othr_pl_inst_tbl;
4518   l_inst_count 	number;
4519   l_ok 		boolean := false;
4520   l_rows_found 	boolean := false;
4521 
4522   l_date_to_use      date;
4523   l_dummy            varchar2(1);
4524   --
4525   cursor c1(p_pl_id in number) is
4526     select null
4527     from   ben_elig_cvrd_dpnt_f pdp,
4528            ben_prtt_enrt_rslt_f pen
4529     where  pen.business_group_id  = p_business_group_id
4530     and    pen.pl_id = p_pl_id
4531     and    pdp.dpnt_person_id = p_person_id
4532     and    l_date_to_use
4533            between pen.enrt_cvg_strt_dt
4534            and     pen.enrt_cvg_thru_dt
4535     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
4536     and    pdp.business_group_id  = pen.business_group_id
4537     and    pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
4538     --and    pen.prtt_enrt_rslt_stat_cd not in ('BCKDT', 'VOIDD')
4539     and    pen.prtt_enrt_rslt_stat_cd is null
4540     and    l_date_to_use
4541            between pdp.cvg_strt_dt
4542            and     pdp.cvg_thru_dt
4543     and    pdp.effective_end_date = hr_api.g_eot;
4544 
4545 begin
4546   --
4547   hr_utility.set_location('Entering : '||l_proc,10);
4548   --
4549   -- Get the data from the cache.
4550   --
4551   ben_rt_prfl_cache.get_rt_prfl_cache
4552     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4553     ,p_effective_date    => p_effective_date
4554     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4555     ,p_business_group_id => p_business_group_id
4556     ,p_inst_set          => l_inst_set
4557     ,p_inst_count        => l_inst_count);
4558 
4559   --
4560   if l_inst_count > 0 then
4561     for i in l_inst_set.first..l_inst_set.last loop
4562       --
4563       l_rows_found := true;
4564       --
4565       --
4566       -- Apply the date logic to the life event occurred date.
4567       --
4568       ben_determine_date.main
4569         (p_date_cd        => l_inst_set(i).cvg_det_dt_cd,
4570          p_effective_date => p_effective_date,
4571          p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
4572          p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
4573          p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
4574          p_returned_date  => l_date_to_use);
4575       --
4576       open c1(l_inst_set(i).pl_id);
4577       fetch c1 into l_dummy;
4578       --
4579       if c1%found then
4580         --
4581         close c1;
4582         --
4583         if l_inst_set(i).excld_flag = 'N' then
4584           l_ok := true;
4585           exit;
4586         end if;
4587         --
4588         if l_inst_set(i).excld_flag = 'Y' then
4589           l_ok := false;
4590           exit;
4591         end if;
4592         --
4593       else
4594         --
4595         close c1;
4596         if l_inst_set(i).excld_flag = 'Y' then
4597           l_ok := true;
4598           -- exit;
4599         end if;
4600       end if;
4601       --
4602     end loop;
4603   end if;
4604   --
4605   if l_rows_found and not l_ok then
4606       --
4607       raise g_criteria_failed;
4608       --
4609   end if;
4610   --
4611 end check_dpnt_cvrd_othr_pl;
4612 
4613 
4614 -- --------------------------------------------------
4615 --  DEPENDENT COVERED OTHER PLAN IN PROGRAM
4616 -- --------------------------------------------------
4617 procedure check_dpnt_cvrd_othr_plip (p_vrbl_rt_prfl_id    in number,
4618                     	     p_business_group_id  in number,
4619                     	     p_effective_date     in date,
4620                     	     p_person_id          in number ,
4621                     	     p_lf_evt_ocrd_dt     in date) is
4622   --
4623   l_proc       	varchar2(100) := g_package||'check_dpnt_cvrd_othr_plip';
4624   l_inst_set 	ben_rt_prfl_cache.g_dpnt_cvrd_othr_plip_inst_tbl;
4625   l_inst_count 	number;
4626   l_ok 		boolean := false;
4627   l_rows_found 	boolean := false;
4628 
4629   l_date_to_use      date;
4630   l_dummy            varchar2(1);
4631   --
4632   cursor c1(p_plip_id in number) is
4633     select null
4634     from   ben_prtt_enrt_rslt_f pen
4635           ,ben_elig_cvrd_dpnt_f pdp
4636           ,ben_plip_f           cpp
4637     where  pen.prtt_enrt_rslt_id = pdp.prtt_enrt_rslt_id
4638     --and    pen.prtt_enrt_rslt_stat_cd not in ('BCKDT', 'VOIDD')
4639     and    pen.prtt_enrt_rslt_stat_cd is null
4640     and    pdp.dpnt_person_id = p_person_id
4641     and    pen.pgm_id = cpp.pgm_id
4642     and    pen.pl_id  = cpp.pl_id
4643     and    cpp.plip_id = p_plip_id
4644     and    l_date_to_use
4645            between cpp.effective_start_date
4646            and     cpp.effective_end_date
4647     and    cpp.business_group_id = pen.business_group_id
4648     and    l_date_to_use
4649            between pen.enrt_cvg_strt_dt
4650            and     pen.enrt_cvg_thru_dt
4651     and    pen.business_group_id  = p_business_group_id
4652     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
4653     and    pen.prtt_enrt_rslt_stat_cd is null
4654     and    pdp.business_group_id = pen.business_group_id
4655     and    l_date_to_use
4656            between pdp.cvg_strt_dt
4657            and     pdp.cvg_thru_dt
4658     and    pdp.effective_end_date = hr_api.g_eot;
4659 begin
4660   --
4661   hr_utility.set_location('Entering : '||l_proc,10);
4662   --
4663   -- Get the data from the cache.
4664   --
4665   ben_rt_prfl_cache.get_rt_prfl_cache
4666     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4667     ,p_effective_date    => p_effective_date
4668     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4669     ,p_business_group_id => p_business_group_id
4670     ,p_inst_set          => l_inst_set
4671     ,p_inst_count        => l_inst_count);
4672 
4673   --
4674   if l_inst_count > 0 then
4675     for i in l_inst_set.first..l_inst_set.last loop
4676       --
4677       l_rows_found := true;
4678       --
4679       --
4680       -- Apply the date logic to the life event occurred date.
4681       --
4682       ben_determine_date.main
4683         (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
4684          p_effective_date => p_effective_date,
4685          p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
4686          p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
4687          p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
4688          p_returned_date  => l_date_to_use);
4689       --
4690       open c1(l_inst_set(i).plip_id);
4691       fetch c1 into l_dummy;
4692       --
4693       if c1%found then
4694         --
4695         close c1;
4696         --
4697         if l_inst_set(i).excld_flag = 'N' then
4698           l_ok := true;
4699           exit;
4700         end if;
4701         --
4702         if l_inst_set(i).excld_flag = 'Y' then
4703           l_ok := false;
4704           exit;
4705         end if;
4706         --
4707       else
4708         --
4709         close c1;
4710         if l_inst_set(i).excld_flag = 'Y' then
4711           l_ok := true;
4712           -- exit;
4713         end if;
4714       end if;
4715       --
4716     end loop;
4717   end if;
4718   --
4719   if l_rows_found and not l_ok then
4720       --
4721       raise g_criteria_failed;
4722       --
4723   end if;
4724   --
4725 end check_dpnt_cvrd_othr_plip;
4726 
4727 
4728 -- --------------------------------------------------
4729 --  DEPENDENT COVERED OTHER PLAN TYPE IN PROGRAM
4730 -- --------------------------------------------------
4731 procedure check_dpnt_cvrd_othr_ptip(p_vrbl_rt_prfl_id    in number,
4732 					 p_business_group_id in number,
4733 					 p_effective_date    in date,
4734 				         p_person_id         in number,
4735                                          p_lf_evt_ocrd_dt    in date) is
4736   --
4737   l_proc       	varchar2(100) := g_package||'check_dpnt_cvrd_othr_ptip';
4738   l_inst_set 	ben_rt_prfl_cache.g_dpnt_cvrd_othr_ptip_inst_tbl;
4739   l_inst_count 	number;
4740   l_ok 		boolean := false;
4741   l_rows_found 	boolean := false;
4742 
4743   l_continue    boolean := true;
4744   l_found_ptip  boolean := false;
4745   l_date_to_use date;
4746   l_dummy       varchar2(1);
4747   --
4748   cursor c1(p_ptip_id in number) is
4749     select pen.pl_id
4750     from   ben_prtt_enrt_rslt_f pen
4751           ,ben_elig_cvrd_dpnt_f pdp
4752     where  pen.prtt_enrt_rslt_id = pdp.prtt_enrt_rslt_id
4753     --and    pen.prtt_enrt_rslt_stat_cd not in ('BCKDT', 'VOIDD')
4754     and    pen.prtt_enrt_rslt_stat_cd is null
4755     and    pdp.dpnt_person_id = p_person_id
4756     and    pen.ptip_id = p_ptip_id
4757     and    l_date_to_use
4758            between pen.enrt_cvg_strt_dt
4759            and     pen.enrt_cvg_thru_dt
4760     and    pen.business_group_id  = p_business_group_id
4761     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
4762     and    pen.prtt_enrt_rslt_stat_cd is null
4763     and    pdp.business_group_id = pen.business_group_id
4764     and    l_date_to_use
4765            between pdp.cvg_strt_dt
4766            and     pdp.cvg_thru_dt
4767     and    pdp.effective_end_date = hr_api.g_eot;
4768   --
4769   cursor c2(p_pl_id in number) is
4770     select null
4771     from   ben_pl_regn_f prg
4772           ,ben_regn_f reg
4773     where  prg.pl_id = p_pl_id
4774     and    prg.regn_id = reg.regn_id
4775     and    reg.sttry_citn_name = 'COBRA'
4776     and    prg.business_group_id = p_business_group_id
4777     and    l_date_to_use
4778            between prg.effective_start_date
4779            and     prg.effective_end_date
4780     and    prg.business_group_id = reg.business_group_id
4781     and    l_date_to_use
4782            between reg.effective_start_date
4783            and     reg.effective_end_date;
4784 
4785 begin
4786   --
4787   hr_utility.set_location('Entering : '||l_proc,10);
4788   --
4789   -- Get the data from the cache.
4790   --
4791   ben_rt_prfl_cache.get_rt_prfl_cache
4792     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4793     ,p_effective_date    => p_effective_date
4794     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4795     ,p_business_group_id => p_business_group_id
4796     ,p_inst_set          => l_inst_set
4797     ,p_inst_count        => l_inst_count);
4798 
4799   --
4800   if l_inst_count > 0 then
4801     <<prfl>>
4802     for i in l_inst_set.first..l_inst_set.last loop
4803       --
4804       l_rows_found := true;
4805       --
4806       --
4807       -- Apply the date logic to the life event occurred date.
4808       --
4809       ben_determine_date.main
4810         (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
4811          p_effective_date => p_effective_date,
4812          p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
4813          p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
4814          p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
4815          p_returned_date  => l_date_to_use);
4816       --
4817       <<dpnt>>
4818       for l_pdp_rec in c1(l_inst_set(i).ptip_id) loop
4819               --
4820               --  Check if the dependent have to be covered in the ptip where
4821               --  there are plans subject to cobra.
4822               --
4823               l_continue := true;
4824               --
4825               if l_inst_set(i).only_pls_subj_cobra_flag = 'Y' then
4826 		    open c2(l_pdp_rec.pl_id);
4827 		    fetch c2 into l_dummy;
4828 		    if c2%notfound then
4829 		        l_continue := false;
4830 		    end if;
4831 		    close c2;
4832               end if;
4833               --
4834               if l_continue then
4835                   l_found_ptip := true;
4836                   --
4837                   if l_inst_set(i).excld_flag = 'N' then
4838                      l_ok := true;
4839                      exit prfl;
4840                   end if;
4841                   --
4842                   if l_inst_set(i).excld_flag = 'Y' then
4843                      l_ok := false;
4844                      exit prfl;
4845                   end if;
4846                   --
4847               end if;
4848               --
4849       end loop dpnt;
4850       --
4851       if (l_found_ptip = false
4852          and l_inst_set(i).excld_flag = 'Y') then
4853         l_ok := true;
4854         exit;
4855       end if;
4856       --
4857     end loop prfl;
4858   end if;
4859   --
4860   if l_rows_found and not l_ok then
4861       --
4862       raise g_criteria_failed;
4863       --
4864   end if;
4865   --
4866 end check_dpnt_cvrd_othr_ptip;
4867 
4868 
4869 -- --------------------------------------------------
4870 --  DEPENDENT COVERED OTHER PROGRAM
4871 -- --------------------------------------------------
4872 procedure check_dpnt_cvrd_othr_pgm(p_vrbl_rt_prfl_id    in number,
4873 					 p_business_group_id in number,
4874 					 p_effective_date    in date,
4875 					 p_person_id         in number,
4876                                          p_lf_evt_ocrd_dt    in date) is
4877   --
4878   l_proc       	varchar2(100) := g_package||'check_dpnt_cvrd_othr_pgm';
4879   l_inst_set 	ben_rt_prfl_cache.g_dpnt_cvrd_othr_pgm_inst_tbl;
4880   l_inst_count 	number;
4881   l_ok 		boolean := false;
4882   l_rows_found 	boolean := false;
4883 
4884   l_date_to_use date;
4885   l_dummy       varchar2(1);
4886   --
4887   cursor c1(p_pgm_id in number) is
4888       select null
4889       from   ben_elig_cvrd_dpnt_f pdp,
4890              ben_prtt_enrt_rslt_f pen
4891       where  pen.business_group_id  = p_business_group_id
4892       and    pen.pgm_id = p_pgm_id
4893       and    pdp.dpnt_person_id = p_person_id
4894       and    l_date_to_use
4895              between pen.enrt_cvg_strt_dt
4896              and     pen.enrt_cvg_thru_dt
4897       and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
4898       and    pdp.business_group_id  = pen.business_group_id
4899       and    pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
4900       --and    pen.prtt_enrt_rslt_stat_cd not in ('BCKDT', 'VOIDD')
4901       and    pen.prtt_enrt_rslt_stat_cd is null
4902       and    l_date_to_use
4903              between pdp.cvg_strt_dt
4904              and     pdp.cvg_thru_dt
4905       and    pdp.effective_end_date = hr_api.g_eot;
4906 
4907 
4908 begin
4909   --
4910   hr_utility.set_location('Entering : '||l_proc,10);
4911   --
4912   -- Get the data from the cache.
4913   --
4914   ben_rt_prfl_cache.get_rt_prfl_cache
4915     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
4916     ,p_effective_date    => p_effective_date
4917     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4918     ,p_business_group_id => p_business_group_id
4919     ,p_inst_set          => l_inst_set
4920     ,p_inst_count        => l_inst_count);
4921 
4922   --
4923   if l_inst_count > 0 then
4924      for i in l_inst_set.first..l_inst_set.last loop
4925       --
4926       l_rows_found := true;
4927       --
4928       --
4929       -- Apply the date logic to the life event occurred date.
4930       --
4931       ben_determine_date.main
4932         (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
4933          p_effective_date => p_effective_date,
4934          p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
4935          p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
4936          p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
4937          p_returned_date  => l_date_to_use);
4938       --
4939       open c1(l_inst_set(i).pgm_id);
4940       fetch c1 into l_dummy;
4941       --
4942       if c1%found then
4943         --
4944         close c1;
4945         --
4946         if l_inst_set(i).excld_flag = 'N' then
4947           l_ok := true;
4948           exit;
4949         end if;
4950         --
4951         if l_inst_set(i).excld_flag = 'Y' then
4952           l_ok := false;
4953           exit;
4954         end if;
4955         --
4956       else
4957         --
4958         close c1;
4959         if l_inst_set(i).excld_flag = 'Y' then
4960           l_ok := true;
4961           --exit ;
4962         end if;
4963       end if;
4964       --
4965     end loop;
4966     --
4967   end if;
4968   --
4969   if l_rows_found and not l_ok then
4970       --
4971       raise g_criteria_failed;
4972       --
4973   end if;
4974   --
4975 end check_dpnt_cvrd_othr_pgm;
4976 
4977 
4978 -- --------------------------------------------------
4979 --  ELIGIBLE FOR ANOTHER PLAN
4980 -- --------------------------------------------------
4981 procedure check_prtt_anthr_pl(p_vrbl_rt_prfl_id    in number,
4982 				   p_business_group_id in number,
4983                                    p_person_id         in number,
4984                                    -- FONM overloaded eff date is fine.
4985                                    p_effective_date    in date,
4986                                    p_lf_evt_ocrd_dt    in date) is
4987   --
4988   l_proc       	varchar2(100) := g_package||'check_prtt_anthr_pl';
4989   l_inst_set 	ben_rt_prfl_cache.g_prtt_anthr_pl_inst_tbl;
4990   l_inst_count 	number;
4991   l_ok 		boolean := false;
4992   l_rows_found 	boolean := false;
4993 
4994   l_dummy                 varchar2(1);
4995   --
4996 --Bug 13636427 Modified cursor c1 to fetch the records which are having
4997 --             elig_flag as 'Y' only.If this condition is not added system is
4998 --             considering the plans which are not eligible on that p_effective_date.
4999   cursor c1(p_pl_id in number) is
5000     select null
5001     from ben_elig_per_f epo,
5002          ben_per_in_ler pil
5003     where epo.person_id = p_person_id
5004     and epo.pl_id = p_pl_id
5005     and p_effective_date
5006     between epo.effective_start_date
5007     and     epo.effective_end_date
5008 	and     epo.elig_flag = 'Y'  -- Bug 13636427
5009     and epo.business_group_id  = p_business_group_id
5010     and pil.per_in_ler_id(+)=epo.per_in_ler_id
5011    -- and pil.business_group_id(+)=epo.business_group_id
5012     and (   pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
5013         or pil.per_in_ler_stat_cd is null                  -- outer join condition
5014         );
5015 
5016 
5017 begin
5018   --
5019   hr_utility.set_location('Entering : '||l_proc,10);
5020   --
5021   -- Get the data from the cache.
5022   --
5023   ben_rt_prfl_cache.get_rt_prfl_cache
5024     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
5025     ,p_effective_date    => p_effective_date
5026     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
5027     ,p_business_group_id => p_business_group_id
5028     ,p_inst_set          => l_inst_set
5029     ,p_inst_count        => l_inst_count);
5030 
5031   --
5032   if l_inst_count > 0 then
5033      for i in l_inst_set.first..l_inst_set.last loop
5034            --
5035            l_rows_found := true;
5036            --
5037            open c1(l_inst_set(i).pl_id);
5038            fetch c1 into l_dummy;
5039            if c1%found then
5040              --
5041              close c1;
5042              --
5043              if l_inst_set(i).excld_flag = 'N' then
5044                	l_ok := true;
5045                	exit;
5046              end if;
5047              --
5048              if l_inst_set(i).excld_flag = 'Y' then
5049                	l_ok := false;
5050                	exit;
5051              end if;
5052              --
5053            else
5054              --
5055              close c1;
5056              --
5057              if l_inst_set(i).excld_flag = 'Y' then
5058                l_ok := true;
5059                -- exit;
5060              end if;
5061            end if;
5062              --
5063     end loop;
5064     --
5065   end if;
5066   --
5067   if l_rows_found and not l_ok then
5068       --
5069       raise g_criteria_failed;
5070       --
5071   end if;
5072   --
5073 end check_prtt_anthr_pl;
5074 
5075 -- --------------------------------------------------
5076 --  ELIGIBLE FOR ANOTHER PLAN TYPE IN PROGRAM
5077 -- --------------------------------------------------
5078 procedure check_othr_ptip
5079   (p_vrbl_rt_prfl_id   in number
5080   ,p_business_group_id in number
5081   ,p_effective_date    in date
5082   ,p_lf_evt_ocrd_dt    in date
5083   ,p_person_id         in number
5084   ,p_per_in_ler_id     in number default null
5085   )
5086 is
5087   --
5088   l_proc varchar2(100):='check_othr_ptip';
5089   --
5090   l_inst_set                    ben_rt_prfl_cache.g_othr_ptip_inst_tbl;
5091   l_inst_count                  number;
5092   i               		binary_integer;
5093   l_ok                          boolean := false;
5094   l_rows_found                  boolean := false;
5095   l_dummy                       varchar2(1);
5096   l_pl_rec                      ben_comp_object.g_cache_pl_rec_table;
5097   --
5098   l_cur_found                   boolean := false;
5099   --
5100   cursor pilc1
5101     (c_effective_date           date
5102     ,c_per_in_ler_id            number
5103     ,c_ptip_id                  number
5104     ,c_only_pls_subj_cobra_flag varchar2
5105     )
5106   is
5107    	select /*+ bendtlep.check_othr_ptip.pilc1 */
5108            null
5109     from   ben_pl_f pln,
5110            ben_plip_f cpp,
5111            ben_ptip_f ctp,
5112            ben_elig_per_f epo
5113     where  pln.pl_id = cpp.pl_id
5114     and    c_effective_date
5115            between pln.effective_start_date
5116            and     pln.effective_end_date
5117     and    c_effective_date
5118            between cpp.effective_start_date
5119            and     cpp.effective_end_date
5120     and    cpp.pgm_id = ctp.pgm_id
5121     and    pln.pl_typ_id = ctp.pl_typ_id
5122     and    ctp.ptip_id   = c_ptip_id
5123     and    c_effective_date
5124            between ctp.effective_start_date
5125            and     ctp.effective_end_date
5126     and    epo.per_in_ler_id = c_per_in_ler_id
5127     and    epo.pgm_id = ctp.pgm_id
5128     and    epo.pl_id = pln.pl_id
5129     and    c_effective_date
5130            between epo.effective_start_date
5131            and     epo.effective_end_date
5132     and    epo.elig_flag = 'Y'
5133     and    ( c_only_pls_subj_cobra_flag = 'N'
5134      	     or exists  (select null
5135 			 from   ben_pl_regn_f prg,
5136            			ben_regn_f reg
5137 			 where  prg.pl_id = pln.pl_id
5138 			 and    c_effective_date  between prg.effective_start_date
5139 			 	and prg.effective_end_date
5140 			 and    reg.regn_id = prg.regn_id
5141 			 and    c_effective_date between reg.effective_start_date
5142 			 	and reg.effective_end_date
5143     			 and    reg.sttry_citn_name = 'COBRA') ); -- 2443719
5144   --
5145   cursor c1
5146     (c_business_group_id        in number
5147     ,c_effective_date           in date
5148     ,c_person_id                in number
5149     ,c_ptip_id                  in number
5150     ,c_only_pls_subj_cobra_flag in varchar2
5151     )
5152   is
5153     select /*+ bendtlep.check_othr_ptip.c1 */
5154            null
5155     from   ben_pl_f pln,
5156            ben_plip_f cpp,
5157            ben_ptip_f ctp,
5158            ben_pl_regn_f prg,
5159            ben_regn_f reg,
5160            ben_elig_per_f epo,
5161            ben_per_in_ler pil
5162     where  pln.pl_id = cpp.pl_id
5163     and    pln.business_group_id  = c_business_group_id
5164     and    c_effective_date
5165            between pln.effective_start_date
5166            and     pln.effective_end_date
5167     and    cpp.business_group_id  = pln.business_group_id
5168     and    c_effective_date
5169            between cpp.effective_start_date
5170            and     cpp.effective_end_date
5171     and    cpp.pgm_id = ctp.pgm_id
5172     and    pln.pl_typ_id = ctp.pl_typ_id
5173     and    ctp.ptip_id   = c_ptip_id
5174     and    ctp.business_group_id = pln.business_group_id
5175     and    c_effective_date
5176            between ctp.effective_start_date
5177            and     ctp.effective_end_date
5178     and    epo.person_id = c_person_id
5179     and    epo.pgm_id = ctp.pgm_id
5180     and    epo.pl_id = pln.pl_id
5181     and    epo.business_group_id  = c_business_group_id
5182     and    p_effective_date
5183            between epo.effective_start_date
5184            and     epo.effective_end_date
5185     and    epo.elig_flag = 'Y'
5186     and    ( c_only_pls_subj_cobra_flag = 'N'  -- cobra regulation needed only when the flag is set
5187              or exists  (select null
5188     			 from   ben_pl_regn_f prg,
5189                			ben_regn_f reg
5190     			 where  prg.pl_id = pln.pl_id
5191     			 and    c_effective_date  between prg.effective_start_date
5192     			 	and prg.effective_end_date
5193     			 and    prg.business_group_id  = pln.business_group_id
5194     			 and    reg.regn_id = prg.regn_id
5195     			 and    c_effective_date between reg.effective_start_date
5196     			 	and reg.effective_end_date
5197     			 and    reg.sttry_citn_name = 'COBRA') ) -- 2443719
5198     and pil.per_in_ler_id(+)=epo.per_in_ler_id
5199     --and pil.business_group_id(+)=epo.business_group_id
5200     and (   pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT') -- found row condition
5201           or pil.per_in_ler_stat_cd is null                  -- outer join condition
5202     ) ;
5203   --
5204 begin
5205   --
5206   hr_utility.set_location('Entering: '||l_proc, 10);
5207   --
5208   -- Getting variable profile compensation level by variable profile
5209   --
5210   ben_rt_prfl_cache.get_rt_prfl_cache
5211     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5212      p_business_group_id => p_business_group_id,
5213      p_vrbl_rt_prfl_id     => p_vrbl_rt_prfl_id,
5214      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5215      p_inst_set          => l_inst_set,
5216      p_inst_count        => l_inst_count);
5217   --
5218   if l_inst_count > 0 then
5219     --
5220     -- Operation
5221     -- =========
5222     -- 1) Grab all profiles for this variable rate profile id
5223     -- 2) Look only at profiles for this PTIP_ID
5224     -- 3) if program is not null then, get all the ptip and check if
5225     --
5226     -- 4) Derive set of plans for the pgm that the ptip refers to
5227     -- 5) Set must be derived based on whether the plans are subject
5228     --    to COBRA or not.
5229     -- 6) If person eligible for any of the plans and exclude flag = 'Y'
5230     --    then no problem.
5231     -- 7) If person eligible for any of the plans and exclude flag = 'N'
5232     --    then fail criteria.
5233     --
5234     for i in l_inst_set.first..l_inst_set.last loop
5235       --
5236       l_rows_found := true;
5237       --
5238       if p_per_in_ler_id is not null then
5239         --
5240         open pilc1
5241           (c_effective_date           => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
5242                                           nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
5243                                            nvl(p_lf_evt_ocrd_dt,p_effective_date)))
5244           ,c_per_in_ler_id            => p_per_in_ler_id
5245           ,c_ptip_id                  => l_inst_set(i).ptip_id
5246           ,c_only_pls_subj_cobra_flag => l_inst_set(i).only_pls_subj_cobra_flag
5247           );
5248         fetch pilc1 into l_dummy;
5249         if pilc1%found then
5250           --
5251           l_cur_found := TRUE;
5252           --
5253         else
5254           --
5255           l_cur_found := FALSE;
5256           --
5257         end if;
5258         close pilc1;
5259         --
5260       else
5261         --
5262         open c1
5263           (c_business_group_id        => p_business_group_id
5264           ,c_effective_date           => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
5265                                           nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,                                           nvl(p_lf_evt_ocrd_dt,p_effective_date)))
5266           ,c_person_id                => p_person_id
5267           ,c_ptip_id                  => l_inst_set(i).ptip_id
5268           ,c_only_pls_subj_cobra_flag => l_inst_set(i).only_pls_subj_cobra_flag
5269           );
5270         fetch c1 into l_dummy;
5271         if c1%found then
5272           --
5273           l_cur_found := TRUE;
5274           --
5275         else
5276           --
5277           l_cur_found := FALSE;
5278           --
5279         end if;
5280         close c1;
5281       end if;
5282       --
5283       if l_cur_found then
5284         --
5285         if l_inst_set(i).excld_flag = 'N' then
5286           --
5287           l_ok := true;
5288           exit;
5289           --
5290         end if;
5291         --
5292         if l_inst_set(i).excld_flag = 'Y' then
5293           --
5294           l_ok := false;
5295           exit;
5296           --
5297         end if;
5298         --
5299       else
5300         --
5301         if l_inst_set(i).excld_flag = 'Y' then
5302           --
5303           l_ok := true;
5304           --
5305         end if;
5306         --
5307       end if;
5308       --
5309     end loop;
5310     --
5311   end if;
5312   --
5313   if l_rows_found and
5314     not l_ok then
5315     --
5316     raise g_criteria_failed;
5317     --
5318   end if;
5319   --
5320   hr_utility.set_location('Leaving :'||l_proc,20);
5321   --
5322 end check_othr_ptip ;
5323 
5324 --
5325 -- --------------------------------------------------------------------------
5326 --  ENROLLED IN ANOTHER PLAN
5327 -- --------------------------------------------------------------------------
5328 --
5329 procedure check_enrld_anthr_pl(p_vrbl_rt_prfl_id   in number,
5330                                p_business_group_id in number,
5331                                p_pl_id             in number,
5332                                p_person_id         in number,
5333                                p_effective_date    in date,
5334                                p_lf_evt_ocrd_dt    in date) is
5335   --
5336   l_proc             varchar2(100):=g_package||'check_enrld_anthr_pl';
5337   l_inst_set         ben_rt_prfl_cache.g_enrld_anthr_pl_inst_tbl;
5338   l_inst_count       number;
5339   i    		     binary_integer;
5340   l_ok               boolean := false;
5341   l_rows_found       boolean := false;
5342   l_found_plan       boolean := false;
5343   l_date_to_use      date;
5344   l_dummy            varchar2(1);
5345   --
5346 begin
5347   --
5348   hr_utility.set_location('Entering: '||l_proc, 10);
5349 
5350   --
5351   ben_rt_prfl_cache.get_rt_prfl_cache
5352     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5353      p_business_group_id => p_business_group_id,
5354      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
5355      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5356      p_inst_set          => l_inst_set,
5357      p_inst_count        => l_inst_count);
5358   --
5359   if l_inst_count > 0 then
5360     --
5361     -- Operation
5362     -- =========
5363     -- 1) Grab all profiles for this variable profile profile id
5364     -- 2) If the plan id is the same then check if the person was covered
5365     --    the day before the life event.
5366     --
5367     <<prfl>>
5368     for i in l_inst_set.first..l_inst_set.last loop
5369       --
5370       l_rows_found := true;
5371       --
5372       -- 9999 FONM : how is this cache rebuilt.
5373       <<rslt>>
5374       for l_count in nvl(ben_manage_life_events.g_cache_person_prtn.first,0)..
5375                      nvl(ben_manage_life_events.g_cache_person_prtn.last,-1) loop
5376         if ben_manage_life_events.g_cache_person_prtn(l_count).pl_id =
5377            l_inst_set(i).pl_id then
5378           --
5379           -- Apply the date logic to the life event occurred date.
5380           --
5381           ben_determine_date.main
5382             (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
5383              p_effective_date => p_effective_date,
5384              p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
5385              p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
5386              p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
5387              p_returned_date  => l_date_to_use);
5388           --
5389 
5390           if (l_date_to_use
5391              between ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_strt_dt
5392              and ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_thru_dt) then
5393              l_found_plan := true;
5394             --
5395             if l_inst_set(i).excld_flag = 'N'then
5396               --
5397               l_ok := true;
5398               exit prfl;
5399               --
5400             end if;
5401             --
5402             if l_inst_set(i).excld_flag = 'Y'then
5403               --
5404               l_ok := false;
5405               exit prfl;
5406               --
5407             end if;
5408             --
5409           end if;
5410           --
5411         end if;
5412       end loop rslt;
5413       --
5414       --  If person is not enrolled in plan and exclude flag = 'Y',
5415       --  person is eligible.
5416       --
5417       if (l_found_plan = false
5418          and l_inst_set(i).excld_flag = 'Y') then
5419         l_ok := true;
5420         exit;
5421       end if;
5422       --
5423     end loop prfl;
5424     --
5425   end if;
5426   --
5427   if l_rows_found and not l_ok then
5428     --
5429     raise g_criteria_failed;
5430     --
5431   end if;
5432   --
5433   hr_utility.set_location('Leaving :'||l_proc,20);
5434   --
5435 end check_enrld_anthr_pl;
5436 --
5437 -- --------------------------------------------------------------------------
5438 --  ENROLLED IN ANOTHER OPTION IN PLAN.
5439 -- --------------------------------------------------------------------------
5440 --
5441 procedure check_enrld_anthr_oipl(p_vrbl_rt_prfl_id     in number,
5442                                       p_business_group_id in number,
5443                                       p_oipl_id           in number,
5444                                       p_person_id         in number,
5445                                       p_effective_date    in date,
5446                                       p_lf_evt_ocrd_dt    in date) is
5447   --
5448   l_proc             varchar2(100):=g_package||'check_enrld_anthr_oipl';
5449   l_inst_set         ben_rt_prfl_cache.g_enrld_anthr_oipl_inst_tbl;
5450   l_inst_count       number;
5451   i    		     binary_integer;
5452   l_ok               boolean := false;
5453   l_rows_found       boolean := false;
5454   l_found_oipl       boolean := false;
5455   l_date_to_use      date;
5456   l_dummy            varchar2(1);
5457   --
5458   cursor c1 is
5459     select null
5460     from   ben_prtt_enrt_rslt_f pen
5461     where  pen.business_group_id  = p_business_group_id
5462     and    pen.oipl_id = p_oipl_id
5463     and    pen.person_id = p_person_id
5464     and    l_date_to_use
5465            between pen.enrt_cvg_strt_dt
5466            and     pen.enrt_cvg_thru_dt
5467     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
5468     and    pen.prtt_enrt_rslt_stat_cd is null;
5469   --
5470 begin
5471   --
5472   hr_utility.set_location('Entering: '||l_proc, 10);
5473   --
5474   -- Getting variable rate profile compensation level by variable profile
5475   --
5476   ben_rt_prfl_cache.get_rt_prfl_cache
5477     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5478      p_business_group_id => p_business_group_id,
5479      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
5480      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5481      p_inst_set          => l_inst_set,
5482      p_inst_count        => l_inst_count);
5483   --
5484   if l_inst_count > 0 then
5485     --
5486     -- Operation
5487     -- =========
5488     -- 1) Grab all profiles for this variable profile id
5489     -- 2) If the plan id is the same then check if the person was covered
5490     --    the day before the life event.
5491     --
5492     <<prfl>>
5493     for i in l_inst_set.first..l_inst_set.last loop
5494       --
5495       l_rows_found := true;
5496       --
5497       -- 9999 FONM : how is this cache rebuilt.
5498       <<rslt>>
5499       for l_count in nvl(ben_manage_life_events.g_cache_person_prtn.first,0)..
5500                      nvl(ben_manage_life_events.g_cache_person_prtn.last,-1) loop
5501         if ben_manage_life_events.
5502            g_cache_person_prtn(l_count).oipl_id =
5503              l_inst_set(i).oipl_id then
5504           --
5505           -- Apply the date logic to the life event occurred date.
5506           --
5507           ben_determine_date.main
5508             (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
5509              p_effective_date => p_effective_date,
5510              p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
5511              p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
5512              p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
5513              p_returned_date  => l_date_to_use);
5514           --
5515           if (l_date_to_use
5516              between ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_strt_dt
5517              and ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_thru_dt) then
5518             --
5519             l_found_oipl := true;
5520             --
5521             if l_inst_set(i).excld_flag = 'N'then
5522               --
5523               l_ok := true;
5524               exit prfl;
5525               --
5526             end if;
5527             --
5528             if l_inst_set(i).excld_flag = 'Y'then
5529               --
5530               l_ok := false;
5531               exit prfl;
5532               --
5533             end if;
5534             --
5535           end if;
5536           --
5537         end if;
5538         --
5539       end loop rslt;
5540           --
5541       if (l_found_oipl = false
5542           and l_inst_set(i).excld_flag = 'Y') then
5543         --
5544         l_ok := true;
5545         exit;
5546           --
5547       end if;
5548       --
5549     end loop prfl;
5550     --
5551   end if;
5552   --
5553   if l_rows_found and
5554     not l_ok then
5555     --
5556     raise g_criteria_failed;
5557     --
5558   end if;
5559   --
5560   hr_utility.set_location('Leaving :'||l_proc,20);
5561   --
5562 end check_enrld_anthr_oipl;
5563 
5564 
5565 --
5566 -- --------------------------------------------------------------------------
5567 --  ENROLLED OTHER PLAN TYPE IN PROGRAM.
5568 -- --------------------------------------------------------------------------
5569 --
5570 procedure check_enrld_anthr_ptip(p_vrbl_rt_prfl_id     in number,
5571                                       p_business_group_id in number,
5572                                       p_effective_date    in date,
5573                                       p_lf_evt_ocrd_dt    in date) is
5574   --
5575   l_proc varchar2(100):=g_package||'check_enrld_anthr_ptip';
5576   --
5577   l_inst_set                    ben_rt_prfl_cache.g_enrld_anthr_ptip_inst_tbl;
5578   l_inst_count                  number;
5579   i               		binary_integer;
5580   l_ok                          boolean := false;
5581   l_rows_found                  boolean := false;
5582   l_found_ptip                  boolean := false;
5583   l_continue                    boolean := true;
5584   l_date_to_use                 date;
5585   l_dummy                       varchar2(1);
5586   l_pl_rec                      ben_comp_object.g_cache_pl_rec_table;
5587   --
5588   cursor c1(p_pl_id in number) is
5589     select null
5590     from   ben_pl_f pln,
5591            ben_pl_regn_f prg,
5592            ben_regn_f reg
5593     where  pln.pl_id = p_pl_id
5594     and    pln.business_group_id  = p_business_group_id
5595     and    l_date_to_use
5596            between pln.effective_start_date
5597            and     pln.effective_end_date
5598     and    pln.pl_id = prg.pl_id
5599     and    prg.business_group_id  = pln.business_group_id
5600     and    l_date_to_use
5601            between prg.effective_start_date
5602            and     prg.effective_end_date
5603     and    prg.regn_id = reg.regn_id
5604     and    reg.business_group_id  = prg.business_group_id
5605     and    l_date_to_use
5606            between reg.effective_start_date
5607            and     reg.effective_end_date
5608     and    reg.sttry_citn_name = 'COBRA';
5609 
5610   --
5611 begin
5612   --
5613   hr_utility.set_location('Entering: '||l_proc, 10);
5614   --
5615   -- Getting variable rate profile compensation level
5616   --
5617   ben_rt_prfl_cache.get_rt_prfl_cache
5618     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5619      p_business_group_id => p_business_group_id,
5620      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
5621      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5622      p_inst_set          => l_inst_set,
5623      p_inst_count        => l_inst_count);
5624   --
5625   if l_inst_count > 0 then
5626     --
5627     -- Operation
5628     -- =========
5629     -- 1) Grab all profiles for this variable profile id
5630     -- 2) Look only at profiles for this PTIP_ID
5631     -- 3) Set must be derived based on whether the plans are subject
5632     --    to COBRA or not.
5633     -- 4) If person eligible for any of the plans and exclude flag = 'Y'
5634     --    then no problem.
5635     -- 5) If person eligible for any of the plans and exclude flag = 'N'
5636     --    then fail criteria.
5637     --
5638     hr_utility.set_location('Getting profiles',10);
5639     <<prfl>>
5640     for i in l_inst_set.first..l_inst_set.last loop
5641       --
5642       l_rows_found := true;
5643       --
5644       hr_utility.set_location('Getting results',10);
5645       <<rslt>>
5646       for l_count in nvl(ben_manage_life_events.g_cache_person_prtn.first,0)..
5647                      nvl(ben_manage_life_events.g_cache_person_prtn.last,-1) loop
5648         if ben_manage_life_events.
5649            g_cache_person_prtn(l_count).ptip_id =
5650              l_inst_set(i).ptip_id then
5651           --
5652           -- Apply the date logic to the life event occurred date.
5653           --
5654           ben_determine_date.main
5655             (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
5656              p_effective_date => p_effective_date,
5657              p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
5658              p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
5659              p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
5660              p_returned_date  => l_date_to_use);
5661           --
5662           --  If only check plans that are subject to COBRA.
5663           --
5664           l_continue := true;
5665           --
5666           hr_utility.set_location('Getting cobra plans',10);
5667           --
5668           if l_inst_set(i).only_pls_subj_cobra_flag = 'Y' then
5669             --
5670             open c1(ben_manage_life_events.g_cache_person_prtn(l_count).pl_id);
5671               --
5672               fetch c1 into l_dummy;
5673               --
5674               if c1%notfound then
5675                 --
5676                 hr_utility.set_location('Cobra plans not found',10);
5677                 l_continue := false;
5678                 --
5679               end if;
5680               --
5681             close c1;
5682             --
5683           end if;
5684           --
5685           if l_continue then
5686             --
5687             hr_utility.set_location('Cobra plans found',10);
5688             --
5689             if (l_date_to_use
5690                between ben_manage_life_events.
5691                        g_cache_person_prtn(l_count).enrt_cvg_strt_dt
5692                and ben_manage_life_events.
5693                    g_cache_person_prtn(l_count).enrt_cvg_thru_dt) then
5694               --
5695               l_found_ptip := true;
5696               --
5697               if l_inst_set(i).excld_flag = 'N' then
5698                 --
5699                 hr_utility.set_location('Exclude flags = N Cobra plans found',10);
5700                 l_ok := true;
5701                 exit prfl;
5702                 --
5703               end if;
5704               --
5705               if l_inst_set(i).excld_flag = 'Y' then
5706                 --
5707                 hr_utility.set_location('Exclude flags = Y Cobra plans found',10);
5708                 l_ok := false;
5709                 exit prfl;
5710                 --
5711               end if;
5712               --
5713             end if;
5714             --
5715           end if;
5716           --
5717         end if;
5718         --
5719       end loop rslt;
5720       --
5721       if l_found_ptip = false
5722          and l_inst_set(i).excld_flag = 'Y' then
5723         --
5724         l_ok := true;
5725         exit;
5726         --
5727       end if;
5728       --
5729     end loop prfl;
5730     --
5731   end if;
5732   --
5733   if l_rows_found and
5734     not l_ok then
5735     --
5736     raise g_criteria_failed;
5737     --
5738   end if;
5739   --
5740   hr_utility.set_location('Leaving :'||l_proc,20);
5741   --
5742 end check_enrld_anthr_ptip;
5743 
5744 
5745 --
5746 -- --------------------------------------------------------------------------
5747 --  ENROLLED IN ANOTHER PLAN IN PROGRAM.
5748 -- --------------------------------------------------------------------------
5749 --
5750 procedure check_enrld_anthr_plip(p_vrbl_rt_prfl_id     in number,
5751                                       p_business_group_id in number,
5752                                       p_person_id         in number,
5753                                       p_effective_date    in date,
5754                                       p_lf_evt_ocrd_dt    in date) is
5755   --
5756   l_proc             varchar2(100):=g_package||'check_enrld_anthr_plip';
5757   l_inst_set         ben_rt_prfl_cache.g_enrld_anthr_plip_inst_tbl;
5758   l_inst_count       number;
5759   i    		     binary_integer;
5760   l_ok               boolean := false;
5761   l_rows_found       boolean := false;
5762   l_date_to_use      date;
5763   l_dummy            varchar2(1);
5764   --
5765   cursor c1(p_plip_id in number) is
5766     select null
5767     from   ben_prtt_enrt_rslt_f pen
5768           ,ben_plip_f           cpp
5769     where  pen.business_group_id  = p_business_group_id
5770     and    pen.pgm_id = cpp.pgm_id
5771     and    pen.pl_id  = cpp.pl_id
5772     and    cpp.plip_id = p_plip_id
5773     and    l_date_to_use
5774            between cpp.effective_start_date
5775            and     cpp.effective_end_date
5776     and    cpp.business_group_id = pen.business_group_id
5777     and    pen.person_id = p_person_id
5778     and    l_date_to_use
5779            between pen.enrt_cvg_strt_dt
5780            and     pen.enrt_cvg_thru_dt
5781     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
5782     and    pen.prtt_enrt_rslt_stat_cd is null;
5783   --
5784 begin
5785   --
5786   hr_utility.set_location('Entering: '||l_proc, 10);
5787   --
5788   -- Getting variable profile compensation level by variable profile
5789   --
5790   ben_rt_prfl_cache.get_rt_prfl_cache
5791     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5792      p_business_group_id => p_business_group_id,
5793      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
5794      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5795      p_inst_set          => l_inst_set,
5796      p_inst_count        => l_inst_count);
5797   --
5798   if l_inst_count > 0 then
5799     --
5800     -- Operation
5801     -- =========
5802     -- 1) Grab all profiles for this variable profile id
5803     -- 2) If the plan id is the same then check if the person was covered
5804     --    the day before the life event.
5805     --
5806     for i in l_inst_set.first..l_inst_set.last loop
5807       --
5808       l_rows_found := true;
5809       --
5810       --
5811       -- Apply the date logic to the life event occurred date.
5812       --
5813       ben_determine_date.main
5814         (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
5815          p_effective_date => p_effective_date,
5816          p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
5817          p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
5818          p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
5819          p_returned_date  => l_date_to_use);
5820       --
5821       open c1(l_inst_set(i).plip_id);
5822       fetch c1 into l_dummy;
5823       --
5824       if c1%found then
5825         --
5826         close c1;
5827         --
5828         if l_inst_set(i).excld_flag = 'N' then
5829           l_ok := true;
5830           exit;
5831         end if;
5832         --
5833         if l_inst_set(i).excld_flag = 'Y' then
5834           l_ok := false;
5835           exit;
5836         end if;
5837         --
5838       else
5839         --
5840         close c1;
5841         if l_inst_set(i).excld_flag = 'Y' then
5842           l_ok := true;
5843           -- exit;
5844         end if;
5845       end if;
5846       --
5847     end loop;
5848     --
5849   end if;
5850   --
5851   if l_rows_found and
5852     not l_ok then
5853     --
5854     raise g_criteria_failed;
5855     --
5856   end if;
5857   --
5858   hr_utility.set_location('Leaving :'||l_proc,20);
5859   --
5860 end check_enrld_anthr_plip;
5861 
5862 
5863 --
5864 -- --------------------------------------------------------------------------
5865 --  ENROLLED IN ANOTHER PROGRAM.
5866 -- --------------------------------------------------------------------------
5867 --
5868 procedure check_enrld_anthr_pgm
5869   (
5870    p_vrbl_rt_prfl_id   in number
5871   ,p_business_group_id in number
5872   ,p_pgm_id            in number
5873   ,p_person_id         in number
5874   ,p_effective_date    in date
5875   ,p_lf_evt_ocrd_dt    in date )
5876 is
5877   --
5878   l_proc             varchar2(100):=g_package||'check_enrld_anthr_pgm';
5879   l_inst_set         ben_rt_prfl_cache.g_enrld_anthr_pgm_inst_tbl;
5880   l_inst_count       number;
5881   i    		     binary_integer;
5882   l_ok               boolean := false;
5883   l_rows_found       boolean := false;
5884   l_found_pgm        boolean := false;
5885   l_date_to_use      date;
5886   l_dummy            varchar2(1);
5887   --
5888 begin
5889   --
5890   hr_utility.set_location('Entering: '||l_proc, 10);
5891   hr_utility.set_location('prfl_id: '||p_vrbl_rt_prfl_id, 10);
5892   --
5893   -- Getting variable profile compensation level
5894   --
5895   ben_rt_prfl_cache.get_rt_prfl_cache
5896     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5897      p_business_group_id => p_business_group_id,
5898      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
5899      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5900      p_inst_set          => l_inst_set,
5901      p_inst_count        => l_inst_count);
5902   --
5903   if l_inst_count > 0 then
5904     --
5905     -- Operation
5906     -- =========
5907     -- 1) Grab all profiles for this variable profile id
5908     -- 2) If the plan id is the same then check if the person was covered
5909     --    the day before the life event.
5910     --
5911     <<prfl>>
5912     for i in l_inst_set.first..l_inst_set.last loop
5913       --
5914       l_rows_found := true;
5915       --
5916       <<rslt>>
5917       for l_count in nvl(ben_manage_life_events.g_cache_person_prtn.first,0)..
5918                      nvl(ben_manage_life_events.g_cache_person_prtn.last,-1) loop
5919         if ben_manage_life_events.g_cache_person_prtn(l_count).pgm_id =
5920              l_inst_set(i).pgm_id then
5921            l_found_pgm := true;
5922           --
5923           -- Apply the date logic to the life event occurred date.
5924           --
5925           ben_determine_date.main
5926             (p_date_cd        => l_inst_set(i).enrl_det_dt_cd,
5927              p_effective_date => p_effective_date,
5928              p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt,
5929              p_fonm_cvg_strt_dt  => ben_manage_life_events.g_fonm_cvg_strt_dt,
5930              p_fonm_rt_strt_dt  => ben_manage_life_events.g_fonm_rt_strt_dt,
5931              p_returned_date  => l_date_to_use);
5932           --
5933           if (l_date_to_use
5934              between ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_strt_dt
5935              and ben_manage_life_events.g_cache_person_prtn(l_count).enrt_cvg_thru_dt) then
5936             --
5937             if l_inst_set(i).excld_flag = 'N'then
5938               --
5939               l_ok := true;
5940               exit prfl;
5941               --
5942             end if;
5943             --
5944             if l_inst_set(i).excld_flag = 'Y'then
5945               --
5946               l_ok := false;
5947               exit prfl;
5948               --
5949             end if;
5950             --
5951           end if;
5952           --
5953         end if;
5954         --
5955       end loop rslt;
5956         --
5957         --  If person is not enrolled in the program and exclude flag = "Y"
5958         --  person is eligible.
5959         --
5960         if (l_found_pgm = false
5961             and l_inst_set(i).excld_flag = 'Y') then
5962           --
5963           l_ok := true;
5964           exit;
5965           --
5966         end if;
5967 
5968       --
5969     end loop prfl;
5970     --
5971   end if;
5972   --
5973   if l_rows_found and
5974     not l_ok then
5975     --
5976     raise g_criteria_failed;
5977     --
5978   end if;
5979   --
5980   hr_utility.set_location('Leaving :'||l_proc,20);
5981   --
5982 end check_enrld_anthr_pgm;
5983 
5984 --
5985 -- --------------------------------------------------------------------------
5986 --  DEPENDENT OTHER PLAN TYPE IN PROGRAM
5987 -- --------------------------------------------------------------------------
5988 --
5989 procedure check_dpnt_othr_ptip
5990   (p_vrbl_rt_prfl_id   in number
5991   ,p_business_group_id in number
5992   ,p_effective_date    in date
5993   ,p_lf_evt_ocrd_dt    in date
5994   ,p_person_id         in number
5995   ,p_per_in_ler_id     in number
5996   )
5997 is
5998   --
5999   l_proc varchar2(100):=g_package||'check_dpnt_other_ptip';
6000   --
6001   l_inst_set                    ben_rt_prfl_cache.g_dpnt_othr_ptip_inst_tbl;
6002   l_inst_count                  number;
6003   i               		binary_integer;
6004   l_ok                          boolean := false;
6005   l_rows_found                  boolean := false;
6006   l_dummy                       varchar2(1);
6007   l_pl_rec                      ben_comp_object.g_cache_pl_rec_table;
6008   --
6009   cursor c1
6010     (c_ptip_id        in number
6011     ,c_bgp_id         in number
6012     ,c_eff_date       in date
6013     ,c_dpnt_person_id in number
6014     )
6015   is
6016     select null
6017     from   ben_pl_f pln,
6018            ben_plip_f cpp,
6019            ben_ptip_f ctp,
6020            ben_elig_per_f epo,
6021            ben_elig_dpnt  edp,
6022            ben_per_in_ler pil
6023     where  pln.pl_id = cpp.pl_id
6024     and    pln.business_group_id = c_bgp_id
6025     and    c_eff_date
6026       between pln.effective_start_date and pln.effective_end_date
6027     and    cpp.business_group_id  = pln.business_group_id
6028     and    c_eff_date
6029       between cpp.effective_start_date and cpp.effective_end_date
6030     and    cpp.pgm_id = ctp.pgm_id
6031     and    pln.pl_typ_id = ctp.pl_typ_id
6032     and    ctp.ptip_id   = c_ptip_id
6033     and    ctp.business_group_id = pln.business_group_id
6034     and    c_eff_date
6035       between ctp.effective_start_date and ctp.effective_end_date
6036     and    edp.dpnt_person_id = c_dpnt_person_id
6037     and    epo.pgm_id = ctp.pgm_id
6038     and    epo.pl_id = pln.pl_id
6039     and    epo.business_group_id  = c_bgp_id
6040     and    c_eff_date
6041       between epo.effective_start_date and epo.effective_end_date
6042     and    epo.elig_flag = 'Y'
6043     and    edp.dpnt_inelig_flag = 'N'
6044     and    edp.create_dt = (select max(edp2.create_dt)
6045                             from ben_elig_dpnt edp2
6046                                 ,ben_per_in_ler pil2
6047                             where edp2.dpnt_person_id = edp.dpnt_person_id
6048                             and edp2.elig_per_id = epo.elig_per_id
6049                             and pil2.per_in_ler_id(+)=edp2.per_in_ler_id
6050                             and pil2.business_group_id(+)=edp2.business_group_id
6051                             and (pil2.per_in_ler_stat_cd
6052                                    not in ('VOIDD','BCKDT')
6053                                  or pil2.per_in_ler_stat_cd is null))
6054     and    epo.elig_per_id = edp.elig_per_id
6055     and    pil.per_in_ler_id(+)=edp.per_in_ler_id
6056     and    (pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
6057      or    pil.per_in_ler_stat_cd is null
6058            )
6059     and    epo.per_in_ler_id = edp.per_in_ler_id
6060     and    c_eff_date
6061       between epo.effective_start_date and epo.effective_end_date;
6062   --
6063 begin
6064   --
6065   hr_utility.set_location('Entering: '||l_proc, 10);
6066   --
6067   -- Getting variable profile compensation level by variable profile
6068   --
6069   ben_rt_prfl_cache.get_rt_prfl_cache
6070     (p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
6071      p_business_group_id => p_business_group_id,
6072      p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id,
6073      p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
6074      p_inst_set          => l_inst_set,
6075      p_inst_count        => l_inst_count);
6076 
6077 
6078   --
6079   hr_utility.set_location('l_inst_count: '||l_inst_count, 10);
6080   --
6081   if l_inst_count > 0 then
6082     --
6083     -- Operation
6084     -- =========
6085     -- 1) Grab all profiles for this variable profile
6086     -- 2) Look only at profiles for this PTIP_ID
6087     -- 3) if program is not null then, get all the ptip and check if
6088     --
6089     -- 4) Derive set of plans for the pgm that the ptip refers to
6090     -- 5) If person eligible for any of the plans and exclude flag = 'Y'
6091     --    then no problem.
6092     -- 6) If person eligible for any of the plans and exclude flag = 'N'
6093     --    then fail criteria.
6094     --
6095     for i in l_inst_set.first..l_inst_set.last loop
6096       --
6097       l_rows_found := true;
6098       --
6099       -- Removed the nvls to resolve execute waiting problems for
6100       --
6101       open c1
6102         (c_ptip_id        => l_inst_set(i).ptip_id
6103         ,c_bgp_id         => p_business_group_id
6104         ,c_eff_date       => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
6105                               nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6106                                 nvl(p_lf_evt_ocrd_dt,p_effective_date)))
6107         ,c_dpnt_person_id => p_person_id
6108         );
6109       fetch c1 into l_dummy;
6110       if c1%found then
6111         --
6112         close c1;
6113         if l_inst_set(i).excld_flag = 'N' then
6114           --
6115           l_ok := true;
6116           exit;
6117           --
6118         end if;
6119         --
6120         if l_inst_set(i).excld_flag = 'Y' then
6121           --
6122           l_ok := false;
6123           exit;
6124           --
6125         end if;
6126         --
6127       else
6128         --
6129         close c1;
6130         if l_inst_set(i).excld_flag = 'Y' then
6131           --
6132           l_ok := true;
6133           -- exit ;
6134           --
6135         end if;
6136       end if;
6137       --
6138     end loop;
6139     --
6140   end if;
6141   --
6142   if l_rows_found and
6143     not l_ok then
6144     --
6145     raise g_criteria_failed;
6146     --
6147   end if;
6148   --
6149   hr_utility.set_location('Leaving :'||l_proc,20);
6150   --
6151 end check_dpnt_othr_ptip;
6152 
6153 
6154 -- --------------------------------------------------
6155 --  NO OTHER COVERAGE
6156 -- --------------------------------------------------
6157 procedure check_no_othr_cvg(p_vrbl_rt_prfl_id    in number,
6158 				   p_business_group_id in number,
6159                                    p_person_id         in number,
6160                                    p_effective_date    in date,
6161                                    p_lf_evt_ocrd_dt    in date) is
6162   --
6163   l_proc       	varchar2(100) := g_package||'check_no_othr_cvg';
6164   l_inst_set 	ben_rt_prfl_cache.g_no_othr_cvg_inst_tbl;
6165   l_inst_count 	number;
6166   l_ok 		boolean := false;
6167   l_rows_found 	boolean := false;
6168   l_dummy       varchar2(1);
6169   l_rec         per_all_people_f%rowtype;
6170   --
6171 
6172 
6173 begin
6174   --
6175   hr_utility.set_location('Entering : '||l_proc,10);
6176   --
6177   -- Get the data from the cache.
6178   --
6179   ben_rt_prfl_cache.get_rt_prfl_cache
6180     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6181     ,p_effective_date    => p_effective_date
6182     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6183     ,p_business_group_id => p_business_group_id
6184     ,p_inst_set          => l_inst_set
6185     ,p_inst_count        => l_inst_count);
6186 
6187   --
6188   if l_inst_count > 0 then
6189     ben_person_object.get_object(p_person_id => p_person_id,
6190                                  p_rec       => l_rec);
6191     --
6192     for i in l_inst_set.first..l_inst_set.last loop
6193       --
6194       l_rows_found := true;
6195       l_ok := nvl((nvl(l_rec.coord_ben_no_cvg_flag,'N') =
6196                   l_inst_set(i).coord_ben_no_cvg_flag),FALSE);
6197       --
6198       --
6199     end loop;
6200     --
6201   end if;
6202   --
6203   if l_rows_found and not l_ok then
6204       --
6205       raise g_criteria_failed;
6206       --
6207   end if;
6208   --
6209 end check_no_othr_cvg;
6210 
6211 -- --------------------------------------------------
6212 --  POSITION
6213 -- --------------------------------------------------
6214 procedure check_pstn(p_vrbl_rt_prfl_id   in number,
6215 		     p_business_group_id in number,
6216                      p_asg_position_id   in number,
6217                      p_effective_date	 in date,
6218                      p_lf_evt_ocrd_dt	 in date) is
6219   --
6220   l_proc       	varchar2(100) := g_package||'check_pstn';
6221   l_inst_set 	ben_rt_prfl_cache.g_pstn_inst_tbl;
6222   l_inst_count 	number;
6223   l_ok 		boolean := false;
6224   l_rows_found 	boolean := false;
6225   l_dummy       varchar2(1);
6226   l_rec         per_all_people_f%rowtype;
6227   --
6228 
6229 
6230 begin
6231   --
6232   hr_utility.set_location('Entering : '||l_proc,10);
6233   --
6234   -- Get the data from the cache.
6235   --
6236   ben_rt_prfl_cache.get_rt_prfl_cache
6237     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6238     ,p_effective_date    => p_effective_date
6239     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6240     ,p_business_group_id => p_business_group_id
6241     ,p_inst_set          => l_inst_set
6242     ,p_inst_count        => l_inst_count);
6243 
6244   --
6245   if l_inst_count > 0 then
6246 
6247     for i in l_inst_set.first..l_inst_set.last loop
6248           --
6249           l_ok := nvl((nvl(p_asg_position_id,'-1') = l_inst_set(i).position_id),FALSE);
6250           --
6251           if l_ok and l_inst_set(i).excld_flag = 'N' then
6252             --
6253             exit;
6254             --
6255           elsif l_ok and l_inst_set(i).excld_flag = 'Y' then
6256             --
6257             l_rows_found := true;
6258             l_ok := false;
6259             exit;
6260             --
6261           elsif (not l_ok) and l_inst_set(i).excld_flag = 'Y' then
6262             --
6263             l_rows_found := true;
6264             l_ok := true;
6265             --
6266           elsif l_inst_set(i).excld_flag = 'N' then
6267             --
6268             l_rows_found := true;
6269             --
6270           end if;
6271           --
6272     end loop;
6273     --
6274   end if;
6275   --
6276   if l_rows_found and not l_ok then
6277       --
6278       raise g_criteria_failed;
6279       --
6280   end if;
6281   --
6282 end check_pstn;
6283 
6284 -- --------------------------------------------------
6285 --  COMPETENCE
6286 -- --------------------------------------------------
6287 procedure check_comptncy(p_vrbl_rt_prfl_id   in number,
6288 		     p_business_group_id in number,
6289                      p_person_id   	 in number,
6290                      p_effective_date	 date,
6291                      p_lf_evt_ocrd_dt	 date) is
6292   --
6293   l_proc       	varchar2(100) := g_package||'check_comptncy';
6294   l_inst_set 	ben_rt_prfl_cache.g_comptncy_inst_tbl;
6295   l_inst_count 	number;
6296   l_ok 		boolean := false;
6297   l_rows_found 	boolean := false;
6298   l_dummy       varchar2(1);
6299   --
6300 
6301   cursor c1(p_person_id number
6302   	    ,p_competence_id number
6303   	    ,p_rating_level_id number
6304   	    ,p_lf_evt_ocrd_dt	 date) is
6305   select null
6306   from   per_competence_elements pce
6307   where  pce.person_id = p_person_id
6308   and	 type = 'PERSONAL'
6309   and 	 pce.competence_id  = p_competence_id
6310   and    pce.proficiency_level_id = p_rating_level_id
6311   and    p_lf_evt_ocrd_dt between nvl(pce.effective_date_from, p_lf_evt_ocrd_dt)
6312   	 and nvl(pce.effective_date_to, p_lf_evt_ocrd_dt)
6313   and    pce.business_group_id = p_business_group_id ;
6314 
6315 begin
6316   --
6317   hr_utility.set_location('Entering : '||l_proc,10);
6318   --
6319   -- Get the data from the cache.
6320   --
6321   ben_rt_prfl_cache.get_rt_prfl_cache
6322     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6323     ,p_effective_date    => p_effective_date
6324     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6325     ,p_business_group_id => p_business_group_id
6326     ,p_inst_set          => l_inst_set
6327     ,p_inst_count        => l_inst_count);
6328 
6329   --
6330   if l_inst_count > 0 then
6331 
6332     for i in l_inst_set.first..l_inst_set.last loop
6333  	      l_rows_found := true;
6334  	      --
6335  	      open c1(p_person_id
6336  	             ,l_inst_set(i).competence_id
6337  		     ,l_inst_set(i).rating_level_id
6338  		     ,nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
6339                        nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6340                          nvl(p_lf_evt_ocrd_dt, p_effective_date))) );
6341  	      fetch c1 into l_dummy;
6342 	      if c1%found then
6343 		--
6344 		close c1;
6345 		--
6346 		if l_inst_set(i).excld_flag = 'N' then
6347 		  l_ok := true;
6348 		  exit;
6349 		end if;
6350 		--
6351 		if l_inst_set(i).excld_flag = 'Y' then
6352 		  l_ok := false;
6353 		  exit;
6354 		end if;
6355 		--
6356 	      else
6357 		--
6358 		close c1;
6359 		if l_inst_set(i).excld_flag = 'Y' then
6360 		  l_ok := true;
6361 		  -- exit;
6362 		end if;
6363 	      end if;
6364           --
6365     end loop;
6366     --
6367   end if;
6368   --
6369   if l_rows_found and not l_ok then
6370       --
6371       raise g_criteria_failed;
6372       --
6373   end if;
6374   --
6375 end check_comptncy;
6376 
6377 
6378 
6379 -- --------------------------------------------------
6380 --  QUALIFICATION TITLE
6381 -- --------------------------------------------------
6382 procedure check_qual_titl(p_vrbl_rt_prfl_id   in number,
6383 		     p_business_group_id in number,
6384                      p_person_id   	 in number,
6385                      p_effective_date	 date,
6386                      p_lf_evt_ocrd_dt	 date) is
6387   --
6388   l_proc       	varchar2(100) := g_package||'check_qual_titl';
6389   l_inst_set 	ben_rt_prfl_cache.g_qual_titl_inst_tbl;
6390   l_inst_count 	number;
6391   l_ok 		boolean := false;
6392   l_rows_found 	boolean := false;
6393   l_dummy       varchar2(1);
6394   --
6395 
6396   cursor c1(p_person_id number
6397   	    ,p_qualification_type_id number
6398   	    ,p_title 		     varchar2
6399   	    ,p_lf_evt_ocrd_dt	     date) is
6400   select null
6401   from   per_qualifications pqt
6402   where  pqt.person_id = p_person_id
6403   and 	 pqt.qualification_type_id  = p_qualification_type_id
6404   and    nvl(pqt.title,'NULL' ) = NVL(p_title , 'NULL')
6405   and    p_lf_evt_ocrd_dt between nvl(pqt.start_date , p_lf_evt_ocrd_dt)
6406   	 and nvl(pqt.end_date ,p_lf_evt_ocrd_dt)
6407   and    pqt.business_group_id = p_business_group_id ;
6408 
6409 begin
6410   --
6411   hr_utility.set_location('Entering : '||l_proc,10);
6412   --
6413   -- Get the data from the cache.
6414   --
6415   ben_rt_prfl_cache.get_rt_prfl_cache
6416     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6417     ,p_effective_date    => p_effective_date
6418     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6419     ,p_business_group_id => p_business_group_id
6420     ,p_inst_set          => l_inst_set
6421     ,p_inst_count        => l_inst_count);
6422 
6423   --
6424   if l_inst_count > 0 then
6425 
6426     for i in l_inst_set.first..l_inst_set.last loop
6427  	      l_rows_found := true;
6428  	      --
6429  	      open c1(p_person_id
6430  	             ,l_inst_set(i).qualification_type_id
6431  		     ,l_inst_set(i).title
6432  		     ,nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
6433                        nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6434                          nvl(p_lf_evt_ocrd_dt, p_effective_date))));
6435  	      fetch c1 into l_dummy;
6436 	      if c1%found then
6437 		--
6438 		close c1;
6439 		--
6440 		if l_inst_set(i).excld_flag = 'N' then
6441 		  l_ok := true;
6442 		  exit;
6443 		end if;
6444 		--
6445 		if l_inst_set(i).excld_flag = 'Y' then
6446 		  l_ok := false;
6447 		  exit;
6448 		end if;
6449 		--
6450 	      else
6451 		--
6452 		close c1;
6453 		if l_inst_set(i).excld_flag = 'Y' then
6454 		  l_ok := true;
6455 		  -- exit;
6456 		end if;
6457 	      end if;
6458           --
6459     end loop;
6460     --
6461   end if;
6462   --
6463   if l_rows_found and not l_ok then
6464       --
6465       raise g_criteria_failed;
6466       --
6467   end if;
6468   --
6469 end check_qual_titl;
6470 
6471 
6472 --
6473 -- ---------------------------------------------------------------
6474 --    ttl_cvg check
6475 -- ---------------------------------------------------------------
6476 --
6477 procedure check_ttl_cvg
6478   (p_vrbl_rt_prfl_id      in number
6479   ,p_business_group_id    in number
6480   ,p_effective_date       in date
6481   ,p_lf_evt_ocrd_dt       in date
6482   ,p_ttl_cvg              in number default null)
6483 is
6484   --
6485   l_proc          varchar2(80) := g_package||'.check_ttl_cvg';
6486   l_inst_set      ben_rt_prfl_cache.g_ttl_cvg_inst_tbl;
6487   l_inst_count    number;
6488   l_profile_match varchar2(1);
6489   --
6490 begin
6491   hr_utility.set_location ('check_ttl_cvg:'||to_char(p_ttl_cvg),10);
6492 
6493   --
6494   -- Get the data from the cache.
6495   --
6496   ben_rt_prfl_cache.get_rt_prfl_cache
6497     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6498     ,p_effective_date    => p_effective_date
6499     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6500     ,p_business_group_id => p_business_group_id
6501     ,p_inst_set          => l_inst_set
6502     ,p_inst_count        => l_inst_count);
6503 
6504 
6505   l_profile_match := 'N';
6506   if l_inst_count > 0 then
6507     if p_ttl_cvg is null then
6508         -- there are variable profile criteria for total coverage attached, but
6509         -- the process did not pass in a coverage volumn amount.
6510         fnd_message.set_name('BEN','BEN_92245_TTL_CVG_REQUIRED');
6511         fnd_message.set_token('L_PROC',l_proc);
6512         fnd_message.set_token('VRBL_RT_PRFL_ID',to_char(p_vrbl_rt_prfl_id));
6513         fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
6514         fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6515         fnd_message.raise_error;
6516     end if;
6517     --
6518     -- Data found. Loop through to see we match the total amount of cvg.
6519     --
6520     for i in l_inst_set.first..l_inst_set.last loop
6521       hr_utility.set_location ('min:'||to_char(l_inst_set(i).mn_cvg_vol_amt)||
6522          ' max:'||to_char(l_inst_set(i).mx_cvg_vol_amt),14);
6523       if p_ttl_cvg between nvl(l_inst_set(i).mn_cvg_vol_amt,0)
6524          and nvl(l_inst_set(i).mx_cvg_vol_amt,999999999999999) then
6525         -- we match one of the ranges, exit with success.
6526         l_profile_match := 'Y';
6527         exit;
6528       end if;
6529     end loop;
6530 
6531     if l_profile_match = 'N' then
6532       raise ben_evaluate_rate_profiles.g_profile_failed;
6533     end if;
6534 
6535   end if;
6536 end check_ttl_cvg;
6537 
6538 
6539 -- --------------------------------------------------
6540 --  Quartile in Grade
6541 -- --------------------------------------------------
6542 procedure check_qua_in_gr(p_vrbl_rt_prfl_id   in number,
6543 		     p_business_group_id in number,
6544                      p_person_id   	 in number,
6545                      p_grade_id		 in number,
6546                      p_assignment_id     in number,
6547                      p_effective_date	 date,
6548                      p_lf_evt_ocrd_dt	 date,
6549                      p_pay_basis_id	 in number) is
6550   --
6551   l_proc       	varchar2(100) := g_package||'check_qua_in_gr';
6552   l_inst_set 	ben_rt_prfl_cache.g_qua_in_gr_inst_tbl;
6553   l_inst_count 	number;
6554   l_ok 		boolean := false;
6555   l_rows_found 	boolean := false;
6556   l_max_val	number;
6557   l_min_val	number;
6558   l_max_qualifier  number;
6559   l_min_qualifier  number;
6560   l_in_quartile    boolean;
6561   l_person_sal	   number := 0;
6562   l_ann_fctr       number := 0;   /* Bug 4031314 */
6563   l_ann_sal        number := 0;   /* Bug 4031314 */
6564   l_quar_grad       VARCHAR2 (30);    --    added for bug: 4558945
6565 
6566   --
6567 
6568   cursor c1(p_grade_id 		 number
6569   	    ,p_business_group_id number
6570   	    ,p_lf_evt_ocrd_dt	 date
6571   	    ,p_pay_basis_id 	 number) is
6572   select (maximum * grade_annualization_factor) maximum ,
6573   	 (minimum * grade_annualization_factor) minimum
6574   from 	 pay_grade_rules_f pgr,
6575   	 per_pay_bases ppb                 -- 2594204
6576   where  ppb.pay_basis_id = p_pay_basis_id
6577   and    ppb.business_group_id = p_business_group_id
6578   and	 pgr.rate_id = ppb.rate_id
6579   and    pgr.business_group_id = p_business_group_id
6580   and    pgr.grade_or_spinal_point_id  = p_grade_id
6581   and 	 p_lf_evt_ocrd_dt between nvl(pgr.effective_start_date, p_lf_evt_ocrd_dt)
6582   and 	 nvl(pgr.effective_end_date, p_lf_evt_ocrd_dt);
6583 
6584   /*
6585   Bug 4031314 : We need
6586                 (1) Pay Annualization Factor of Salary Basis
6587                 (2) Person's Approved Pay Proposal
6588                 Splitting the following cursor :
6589 
6590   cursor c2(p_assignment_id 	 number
6591   	    ,p_business_group_id number
6592   	    ,p_lf_evt_ocrd_dt	 date
6593   	    ,p_pay_basis_id      number) is
6594   select ppp.proposed_salary_n * ppb.pay_annualization_factor annual_salary
6595   from   per_pay_bases  	ppb,
6596 	 per_pay_proposals ppp
6597   where  ppb.pay_basis_id = p_pay_basis_id
6598   and    ppb.business_group_id = p_business_group_id
6599   and    ppp.assignment_id = p_assignment_id
6600   and    ppp.change_date <= p_lf_evt_ocrd_dt
6601   order by ppp.change_date desc ;
6602   */
6603 
6604   cursor c_salary ( p_assignment_id 	 number
6605   	           ,p_business_group_id  number
6606   	           ,p_lf_evt_ocrd_dt	 date
6607                    ) is
6608        select ppp.proposed_salary_n
6609          from per_pay_proposals ppp
6610         where ppp.assignment_id = p_assignment_id
6611           and ppp.business_group_id = p_business_group_id
6612           and ppp.approved = 'Y'
6613           and ppp.change_date <= p_lf_evt_ocrd_dt
6614      order by ppp.change_date desc;
6615   --
6616   cursor c_pay_bas_ann_fctr ( p_pay_basis_id number
6617                              ,p_business_group_id number
6618                             ) is
6619       select ppb.pay_annualization_factor
6620         from per_pay_bases ppb
6621        where ppb.pay_basis_id = p_pay_basis_id
6622          and ppb.business_group_id = ppb.business_group_id;
6623   --
6624   procedure get_quartile(p_min 	IN number default 0
6625   		     	,p_max 	IN number default 0
6626   		     	,p_code IN  varchar2
6627   		     	,p_min_qualifier OUT NOCOPY number
6628   		     	,p_max_qualifier OUT NOCOPY number
6629   		     )
6630   is
6631   l_divisor 		number := 4;
6632   l_addition_factor  	number;
6633   l_multiplication_factor number;
6634   BEGIN
6635   	IF p_code not in ('ABV' , 'BLW' , 'NA') then
6636   		l_multiplication_factor := to_number(p_code);
6637   		l_addition_factor := (p_max - p_min)/l_divisor;
6638   		p_min_qualifier := p_max - l_addition_factor * (l_multiplication_factor )  ;
6639   		p_max_qualifier := p_max - l_addition_factor * (l_multiplication_factor - 1 ) ;
6640   		if l_multiplication_factor <> 4 THEN
6641   			p_min_qualifier :=  p_min_qualifier + 1;
6642   		end if;
6643   	END IF;
6644   END;
6645   --
6646 begin
6647   --
6648   hr_utility.set_location('Entering : '||l_proc,10);
6649   --
6650   -- Get the data from the cache.
6651   --
6652   ben_rt_prfl_cache.get_rt_prfl_cache
6653     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6654     ,p_effective_date    => p_effective_date
6655     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6656     ,p_business_group_id => p_business_group_id
6657     ,p_inst_set          => l_inst_set
6658     ,p_inst_count        => l_inst_count);
6659 
6660   --
6661   if l_inst_count > 0 then
6662     open c1(p_grade_id
6663      	    ,p_business_group_id
6664      	    ,nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
6665                        nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6666                          nvl(p_lf_evt_ocrd_dt, p_effective_date)))
6667      	    ,p_pay_basis_id);
6668     fetch c1 into l_max_val, l_min_val;
6669     close c1;
6670     /* Bug 4031314
6671     open c2(p_assignment_id
6672   	    ,p_business_group_id
6673   	    ,nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
6674                        nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6675                          nvl(p_lf_evt_ocrd_dt, p_effective_date)))
6676   	    ,p_pay_basis_id) ;
6677     fetch c2 into l_person_sal;
6678     close c2;
6679     */
6680     open c_salary ( p_assignment_id     => p_assignment_id,
6681                     p_business_group_id => p_business_group_id,
6682                     p_lf_evt_ocrd_dt    => nvl( ben_manage_life_events.g_fonm_rt_strt_dt,
6683                                                     nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
6684                                                            nvl(p_lf_evt_ocrd_dt, p_effective_date
6685                                                               )
6686                                                         )
6687                                                )
6688                   );
6689       fetch c_salary into l_person_sal;
6690     close c_salary;
6691     --
6692     open c_pay_bas_ann_fctr ( p_pay_basis_id      => p_pay_basis_id,
6693                               p_business_group_id => p_business_group_id );
6694       fetch c_pay_bas_ann_fctr into l_ann_fctr;
6695     close c_pay_bas_ann_fctr;
6696     --
6697     l_ann_sal := l_person_sal * l_ann_fctr;
6698     --
6699       -- added for bug: 4558945
6700       l_quar_grad :=
6701       ben_cwb_person_info_pkg.get_grd_quartile (p_salary      => l_ann_sal,
6702 						p_min         => NVL(l_min_val,0),
6703 						p_max         => NVL(l_max_val,0),
6704                                                 p_mid         => (NVL(l_min_val,0)+ NVL(l_max_val,0))/ 2
6705 						);
6706 
6707     for i in l_inst_set.first..l_inst_set.last loop
6708         l_rows_found := true;
6709         --
6710 	/*
6711 	-- commented for bug: 4558945
6712 	get_quartile(p_min  	    => nvl(l_min_val,0)
6713 		   ,p_max 	    => nvl(l_max_val,0)
6714 		   ,p_code 	    => l_inst_set(i).quar_in_grade_cd
6715 		   ,p_min_qualifier => l_min_qualifier
6716 		   ,p_max_qualifier => l_max_qualifier );
6717 
6718 	--
6719 	IF l_inst_set(i).quar_in_grade_cd  = 'ABV' THEN
6720 	   l_in_quartile := l_ann_sal > nvl(l_max_val,0);
6721 	ELSIF l_inst_set(i).quar_in_grade_cd  = 'BLW' THEN
6722 	   l_in_quartile := l_ann_sal < nvl(l_min_val,0);
6723 	ELSE
6724 	   l_in_quartile := l_ann_sal between l_min_qualifier and l_max_qualifier;
6725 	END IF;
6726 	*/
6727 	--
6728 
6729 	-- if l_inst_set(i).excld_flag = 'N' and l_in_quartile then
6730 	-- commented for bug: 4558945
6731         IF   l_inst_set (i).excld_flag = 'N' AND l_inst_set (i).quar_in_grade_cd = l_quar_grad then
6732 	  l_ok := true;
6733 	  exit;
6734 	-- elsif l_inst_set(i).excld_flag = 'N' and not l_in_quartile then
6735 	-- commented for bug: 4558945
6736 	ELSIF     l_inst_set (i).excld_flag = 'N' AND l_inst_set (i).quar_in_grade_cd <> l_quar_grad then
6737 	  l_ok := false;
6738 	-- elsif l_inst_set(i).excld_flag = 'Y' and not l_in_quartile then
6739 	-- commented for bug: 4558945
6740         ELSIF     l_inst_set (i).excld_flag = 'Y' AND l_inst_set (i).quar_in_grade_cd <> l_quar_grad then
6741 	  l_ok := true;
6742 	  -- exit;
6743 	-- elsif l_inst_set(i).excld_flag = 'Y' and l_in_quartile then
6744 	-- commented for bug: 4558945
6745          ELSIF     l_inst_set (i).excld_flag = 'Y' AND l_inst_set (i).quar_in_grade_cd = l_quar_grad then
6746 
6747 	  l_ok := false;
6748 	  exit;
6749 	end if;
6750           --
6751     end loop;
6752     --
6753   end if;
6754   --
6755   if l_rows_found and not l_ok then
6756       --
6757       raise g_criteria_failed;
6758       --
6759   end if;
6760   --
6761 end check_qua_in_gr;
6762 --
6763 
6764 -- --------------------------------------------------
6765 --  Performance Rating
6766 -- --------------------------------------------------
6767 procedure check_perf_rtng(p_vrbl_rt_prfl_id   in number,
6768 		     p_business_group_id in number,
6769                      p_assignment_id   	 in number,
6770                      p_person_id   	 in number,
6771                      p_effective_date	 date,
6772                      p_lf_evt_ocrd_dt	 date) is
6773   --
6774   l_proc       	varchar2(100) := g_package||'check_perf_rtng';
6775   l_inst_set 	ben_rt_prfl_cache.g_perf_rtng_inst_tbl;
6776   l_inst_count 	number;
6777   l_ok 		boolean := false;
6778   l_rows_found 	boolean := false;
6779   l_dummy       varchar2(1);
6780   l_performance_rating      varchar2(80);
6781   --
6782   CURSOR c1 (
6783      p_person_id            NUMBER,
6784      p_event_type           VARCHAR2,
6785      p_business_group_id    NUMBER,
6786      p_assignment_id        NUMBER,
6787      p_lf_evt_ocrd_dt       DATE
6788   )
6789   IS
6790      SELECT ppr.performance_rating
6791        FROM per_performance_reviews ppr, per_events pev
6792       WHERE NVL(pev.assignment_id,p_assignment_id) = p_assignment_id                /* Bug 9679606: added nvl condition */
6793         AND pev.TYPE = p_event_type
6794         AND NVL(pev.business_group_id,p_business_group_id) = p_business_group_id    /* Bug 9679606: added nvl condition */
6795         AND p_lf_evt_ocrd_dt BETWEEN NVL (date_start, p_lf_evt_ocrd_dt)
6796                                  AND NVL (date_end, p_lf_evt_ocrd_dt)
6797         AND ppr.event_id = pev.event_id
6798         AND ppr.person_id = p_person_id
6799      -- AND ppr.performance_rating = p_performance_rating
6800    ORDER BY pev.date_start desc, ppr.review_date desc;
6801   --
6802   /* Bug 4031314
6803    * If ELPRO criteria does not specify Performance Type then we would select
6804    * only those performance reviews which do have Performance (Interview) Type
6805    * as NULL i.e PPR.EVENT_ID IS NULL
6806    */
6807   CURSOR c2_without_events (
6808      p_person_id            NUMBER,
6809      p_effective_date       DATE
6810   )
6811   IS
6812      SELECT ppr.performance_rating
6813        FROM per_performance_reviews ppr
6814       WHERE ppr.person_id = p_person_id
6815      -- AND ppr.performance_rating = p_performance_rating
6816         AND ppr.review_date <= p_effective_date
6817         AND ppr.event_id IS NULL
6818    ORDER BY ppr.review_date desc;
6819   --
6820 
6821 begin
6822   --
6823   hr_utility.set_location('Entering : '||l_proc,10);
6824   --
6825   -- Get the data from the cache.
6826   --
6827   ben_rt_prfl_cache.get_rt_prfl_cache
6828     (p_vrbl_rt_prfl_id   => p_vrbl_rt_prfl_id
6829     ,p_effective_date    => p_effective_date
6830     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6831     ,p_business_group_id => p_business_group_id
6832     ,p_inst_set          => l_inst_set
6833     ,p_inst_count        => l_inst_count);
6834 
6835   --
6836   if l_inst_count > 0 then
6837 
6838     for i in l_inst_set.first..l_inst_set.last
6839     loop
6840       --
6841       l_rows_found := true;
6842       --
6843       /* Bug 4031314
6844        * - When BEN_ELIG_PERF_RTNG_PRTE_F.EVENT_TYPE = '-1', then fetch performance reviews
6845        *   that have Performance (Interview) Type as NULL.
6846        * - When BEN_ELIG_PERF_RTNG_PRTE_F.EVENT_TYPE is not '-1', then fetch performanc reviews
6847        *   with Performance Type as defined in ELPRO criteria
6848        */
6849       if l_inst_set (i).event_type = '-1'
6850       then
6851         --
6852         OPEN c2_without_events (
6853                  p_person_id               => p_person_id,
6854                  p_effective_date          => NVL (ben_manage_life_events.g_fonm_rt_strt_dt,
6855                                                    NVL (ben_manage_life_events.g_fonm_cvg_strt_dt,
6856                                                         NVL (p_lf_evt_ocrd_dt,
6857                                                              p_effective_date
6858                                                             )
6859                                                        )
6860                                                   )
6861           );
6862           --
6863           fetch c2_without_events into l_performance_rating;
6864           --
6865           if c2_without_events%found and l_performance_rating = l_inst_set (i).perf_rtng_cd
6866           then
6867             --
6868             close c2_without_events;
6869             --
6870             if l_inst_set(i).excld_flag = 'N' then
6871               l_ok := true;
6872               exit;
6873             end if;
6874             --
6875             if l_inst_set(i).excld_flag = 'Y' then
6876               l_ok := false;
6877               exit;
6878             end if;
6879             --
6880           else
6881             --
6882             close c2_without_events;
6883             if l_inst_set(i).excld_flag = 'Y' then
6884               l_ok := true;
6885               -- exit;
6886             end if;
6887             --
6888           end if;
6889           --
6890         --
6891       else
6892         --
6893         OPEN c1 (p_person_id               => p_person_id,
6894                  p_event_type              => l_inst_set (i).event_type,
6895                  p_business_group_id       => p_business_group_id,
6896                  p_assignment_id           => p_assignment_id,
6897                  p_lf_evt_ocrd_dt          => NVL (ben_manage_life_events.g_fonm_rt_strt_dt,
6898                                                    NVL (ben_manage_life_events.g_fonm_cvg_strt_dt,
6899                                                         NVL (p_lf_evt_ocrd_dt,
6900                                                              p_effective_date
6901                                                             )
6902                                                        )
6903                                                   )
6904                 );
6905           --
6906           fetch c1 into l_performance_rating;
6907           --
6908           if c1%found and l_performance_rating = l_inst_set (i).perf_rtng_cd
6909           then
6910             --
6911             close c1;
6912             --
6913             if l_inst_set(i).excld_flag = 'N' then
6914               l_ok := true;
6915               exit;
6916             end if;
6917             --
6918             if l_inst_set(i).excld_flag = 'Y' then
6919               l_ok := false;
6920               exit;
6921             end if;
6922             --
6923           else
6924             --
6925             close c1;
6926             if l_inst_set(i).excld_flag = 'Y' then
6927               l_ok := true;
6928               -- exit;
6929             end if;
6930             --
6931           end if;
6932           --
6933       end if;
6934       --
6935     end loop;
6936     --
6937   end if;
6938   --
6939   if l_rows_found and not l_ok then
6940       --
6941       raise g_criteria_failed;
6942       --
6943   end if;
6944   --
6945 end check_perf_rtng;
6946 
6947 
6948 -- ---------------------------------------------------------------------------
6949 -- init_globals
6950 -- ---------------------------------------------------------------------------
6951 procedure init_globals is
6952 begin
6953   ben_evaluate_rate_profiles.g_no_match_cnt         := 0 ;
6954   ben_evaluate_rate_profiles.g_no_match_cvg         := 0 ;
6955   ben_evaluate_rate_profiles.g_all_prfls.delete;
6956 
6957   ben_evaluate_rate_profiles.g_num_of_prfls_used := 0 ;
6958   ben_evaluate_rate_profiles.g_use_prfls.delete;
6959 
6960 end init_globals;
6961 -- ---------------------------------------------------------------------------
6962 -- load_globals
6963 -- ---------------------------------------------------------------------------
6964 procedure load_globals
6965          (p_all_prfls               in boolean default false,
6966           p_use_prfls               in boolean default false,
6967           p_bnft_amt                in number  default null,
6968           p_vrbl_rt_prfl_id         in number,
6969           p_ordr_num                in number,
6970           p_asmt_to_use_cd             in varchar,
6971           p_rt_hrly_slrd_flag          in varchar,
6972           p_rt_pstl_cd_flag            in varchar,
6973           p_rt_lbr_mmbr_flag           in varchar,
6974           p_rt_lgl_enty_flag           in varchar,
6975           p_rt_benfts_grp_flag         in varchar,
6976           p_rt_wk_loc_flag             in varchar,
6977           p_rt_brgng_unit_flag         in varchar,
6978           p_rt_age_flag                in varchar,
6979           p_rt_los_flag                in varchar,
6980           p_rt_per_typ_flag            in varchar,
6981           p_rt_fl_tm_pt_tm_flag        in varchar,
6982           p_rt_ee_stat_flag            in varchar,
6983           p_rt_grd_flag                in varchar,
6984           p_rt_pct_fl_tm_flag          in varchar,
6985           p_rt_asnt_set_flag           in varchar,
6986           p_rt_hrs_wkd_flag            in varchar,
6987           p_rt_comp_lvl_flag           in varchar,
6988           p_rt_org_unit_flag           in varchar,
6989           p_rt_loa_rsn_flag            in varchar,
6990           p_rt_pyrl_flag               in varchar,
6991           p_rt_schedd_hrs_flag         in varchar,
6992           p_rt_py_bss_flag             in varchar,
6993           p_rt_prfl_rl_flag            in varchar,
6994           p_rt_cmbn_age_los_flag       in varchar,
6995           p_rt_prtt_pl_flag            in varchar,
6996           p_rt_svc_area_flag           in varchar,
6997           p_rt_ppl_grp_flag            in varchar,
6998           p_rt_dsbld_flag              in varchar,
6999           p_rt_hlth_cvg_flag           in varchar,
7000           p_rt_poe_flag                in varchar,
7001           p_rt_ttl_cvg_vol_flag        in varchar,
7002           p_rt_ttl_prtt_flag           in varchar,
7003           p_rt_gndr_flag               in varchar,
7004           p_rt_tbco_use_flag           in varchar,
7005           p_rt_cntng_prtn_prfl_flag     in varchar,
7006           p_rt_cbr_quald_bnf_flag	in varchar,
7007           p_rt_optd_mdcr_flag		in varchar,
7008           p_rt_lvg_rsn_flag 		in varchar,
7009           p_rt_pstn_flag 		in varchar,
7010           p_rt_comptncy_flag 		in varchar,
7011           p_rt_job_flag 		in varchar,
7012           p_rt_qual_titl_flag 		in varchar,
7013           p_rt_dpnt_cvrd_pl_flag	in varchar,
7014           p_rt_dpnt_cvrd_plip_flag	in varchar,
7015           p_rt_dpnt_cvrd_ptip_flag	in varchar,
7016           p_rt_dpnt_cvrd_pgm_flag	in varchar,
7017           p_rt_enrld_oipl_flag		in varchar,
7018           p_rt_enrld_pl_flag		in varchar,
7019           p_rt_enrld_plip_flag		in varchar,
7020           p_rt_enrld_ptip_flag		in varchar,
7021           p_rt_enrld_pgm_flag		in varchar,
7022           p_rt_prtt_anthr_pl_flag	in varchar,
7023           p_rt_othr_ptip_flag		in varchar,
7024           p_rt_no_othr_cvg_flag		in varchar,
7025           p_rt_dpnt_othr_ptip_flag	in varchar,
7026           p_rt_qua_in_gr_flag	  	in varchar,
7027           p_rt_perf_rtng_flag		in varchar,
7028           p_rt_elig_prfl_flag           in varchar2
7029           )  is
7030 
7031   l_package           varchar2(80) := g_package||'.load_globals';
7032   l_insert_record     varchar2(1);
7033   l_ctr               number;
7034 begin
7035 --  hr_utility.set_location ('Entering '||l_package,10);
7036 
7037   if p_all_prfls then
7038      -- load the 'all prfls' globals.  These globals use the actl_prem_vrbl_rt.ordr_num
7039      -- as it's index, because the second time we loop thru them, we need them in
7040      -- that order.
7041 
7042            l_insert_record := 'Y';
7043            if g_all_prfls.count > 0 then
7044              -- it's not the first, loop thru the table to see if we've already
7045              -- matched this profile for a person.
7046              l_ctr := g_all_prfls.first;
7047              loop
7048                  if g_all_prfls(l_ctr).vrbl_rt_prfl_id = p_vrbl_rt_prfl_id then
7049                     g_all_prfls(l_ctr).match_cnt := g_all_prfls(l_ctr).match_cnt+1;
7050                     g_all_prfls(l_ctr).match_cvg := g_all_prfls(l_ctr).match_cvg+p_bnft_amt;
7051                     l_insert_record := 'N';
7052                     hr_utility.set_location ('added to profile:'||
7053                                to_char(p_vrbl_rt_prfl_id)||
7054                                ' new num:'||to_char(g_all_prfls(l_ctr).match_cnt)||
7055                                ' new cvg:'||to_char(g_all_prfls(l_ctr).match_cvg),16);
7056 
7057                     exit;
7058                  end if;
7059                  if l_ctr = g_all_prfls.last then
7060                     exit;
7061                  else
7062                     l_ctr := g_all_prfls.next(l_ctr);
7063                  end if;
7064              end loop;
7065            end if;
7066 
7067            if l_insert_record = 'Y' then
7068                 -- We didn't find a match in the table, add a row to table.
7069                 -- increase the total number of profiles matched
7070                 g_all_prfls(p_ordr_num).vrbl_rt_prfl_id :=
7071                              p_vrbl_rt_prfl_id;
7072                 g_all_prfls(p_ordr_num).match_cnt       := 1;
7073                 g_all_prfls(p_ordr_num).match_cvg := p_bnft_amt;
7074                 hr_utility.set_location ('added new profile '||
7075                     to_char(p_vrbl_rt_prfl_id)||
7076                     ' cvg:'||to_char(p_bnft_amt)||
7077                     ' p_ordr_num:'||to_char(p_ordr_num),18);
7078 
7079                 g_all_prfls(p_ordr_num).asmt_to_use_cd     := p_asmt_to_use_cd  ;
7080                 g_all_prfls(p_ordr_num).rt_hrly_slrd_flag  := p_rt_hrly_slrd_flag  ;
7081                 g_all_prfls(p_ordr_num).rt_pstl_cd_flag    := p_rt_pstl_cd_flag  ;
7082                 g_all_prfls(p_ordr_num).rt_lbr_mmbr_flag   := p_rt_lbr_mmbr_flag  ;
7083                 g_all_prfls(p_ordr_num).rt_lgl_enty_flag   := p_rt_lgl_enty_flag  ;
7084                 g_all_prfls(p_ordr_num).rt_benfts_grp_flag := p_rt_benfts_grp_flag  ;
7085                 g_all_prfls(p_ordr_num).rt_wk_loc_flag     := p_rt_wk_loc_flag  ;
7086                 g_all_prfls(p_ordr_num).rt_brgng_unit_flag := p_rt_brgng_unit_flag  ;
7087                 g_all_prfls(p_ordr_num).rt_age_flag        := p_rt_age_flag  ;
7088                 g_all_prfls(p_ordr_num).rt_los_flag        := p_rt_los_flag  ;
7089                 g_all_prfls(p_ordr_num).rt_per_typ_flag    := p_rt_per_typ_flag  ;
7090                 g_all_prfls(p_ordr_num).rt_fl_tm_pt_tm_flag:= p_rt_fl_tm_pt_tm_flag  ;
7091                 g_all_prfls(p_ordr_num).rt_ee_stat_flag    := p_rt_ee_stat_flag  ;
7092                 g_all_prfls(p_ordr_num).rt_grd_flag        := p_rt_grd_flag  ;
7093                 g_all_prfls(p_ordr_num).rt_pct_fl_tm_flag  := p_rt_pct_fl_tm_flag  ;
7094                 g_all_prfls(p_ordr_num).rt_asnt_set_flag   := p_rt_asnt_set_flag  ;
7095                 g_all_prfls(p_ordr_num).rt_hrs_wkd_flag    := p_rt_hrs_wkd_flag  ;
7096                 g_all_prfls(p_ordr_num).rt_comp_lvl_flag   := p_rt_comp_lvl_flag  ;
7097                 g_all_prfls(p_ordr_num).rt_org_unit_flag   := p_rt_org_unit_flag  ;
7098                 g_all_prfls(p_ordr_num).rt_loa_rsn_flag    := p_rt_loa_rsn_flag  ;
7099                 g_all_prfls(p_ordr_num).rt_pyrl_flag       := p_rt_pyrl_flag  ;
7100                 g_all_prfls(p_ordr_num).rt_schedd_hrs_flag := p_rt_schedd_hrs_flag  ;
7101                 g_all_prfls(p_ordr_num).rt_py_bss_flag     := p_rt_py_bss_flag  ;
7102                 g_all_prfls(p_ordr_num).rt_prfl_rl_flag    := p_rt_prfl_rl_flag  ;
7103                 g_all_prfls(p_ordr_num).rt_cmbn_age_los_flag := p_rt_cmbn_age_los_flag ;
7104                 g_all_prfls(p_ordr_num).rt_prtt_pl_flag    := p_rt_prtt_pl_flag  ;
7105                 g_all_prfls(p_ordr_num).rt_svc_area_flag   := p_rt_svc_area_flag  ;
7106                 g_all_prfls(p_ordr_num).rt_ppl_grp_flag    := p_rt_ppl_grp_flag  ;
7107                 g_all_prfls(p_ordr_num).rt_dsbld_flag      := p_rt_dsbld_flag  ;
7108                 g_all_prfls(p_ordr_num).rt_hlth_cvg_flag   := p_rt_hlth_cvg_flag  ;
7109                 g_all_prfls(p_ordr_num).rt_poe_flag        := p_rt_poe_flag  ;
7110                 g_all_prfls(p_ordr_num).rt_ttl_cvg_vol_flag:= p_rt_ttl_cvg_vol_flag  ;
7111                 g_all_prfls(p_ordr_num).rt_ttl_prtt_flag   := p_rt_ttl_prtt_flag  ;
7112                 g_all_prfls(p_ordr_num).rt_gndr_flag       := p_rt_gndr_flag  ;
7113                 g_all_prfls(p_ordr_num).rt_tbco_use_flag   := p_rt_tbco_use_flag ;
7114                 g_all_prfls(p_ordr_num).rt_cntng_prtn_prfl_flag := p_rt_cntng_prtn_prfl_flag ;
7115 		g_all_prfls(p_ordr_num).rt_cbr_quald_bnf_flag   := p_rt_cbr_quald_bnf_flag;
7116 		g_all_prfls(p_ordr_num).rt_optd_mdcr_flag   	:= p_rt_optd_mdcr_flag;
7117 		g_all_prfls(p_ordr_num).rt_lvg_rsn_flag    	:= p_rt_lvg_rsn_flag ;
7118 		g_all_prfls(p_ordr_num).rt_pstn_flag    	:= p_rt_pstn_flag ;
7119 		g_all_prfls(p_ordr_num).rt_comptncy_flag    	:= p_rt_comptncy_flag ;
7120 		g_all_prfls(p_ordr_num).rt_job_flag    		:= p_rt_job_flag ;
7121 		g_all_prfls(p_ordr_num).rt_qual_titl_flag    	:= p_rt_qual_titl_flag ;
7122 		g_all_prfls(p_ordr_num).rt_dpnt_cvrd_pl_flag   	:= p_rt_dpnt_cvrd_pl_flag;
7123 		g_all_prfls(p_ordr_num).rt_dpnt_cvrd_plip_flag  := p_rt_dpnt_cvrd_plip_flag;
7124 		g_all_prfls(p_ordr_num).rt_dpnt_cvrd_ptip_flag  := p_rt_dpnt_cvrd_ptip_flag;
7125 		g_all_prfls(p_ordr_num).rt_dpnt_cvrd_pgm_flag   := p_rt_dpnt_cvrd_pgm_flag;
7126 		g_all_prfls(p_ordr_num).rt_enrld_oipl_flag   	:= p_rt_enrld_oipl_flag;
7127 		g_all_prfls(p_ordr_num).rt_enrld_pl_flag   	:= p_rt_enrld_pl_flag;
7128 		g_all_prfls(p_ordr_num).rt_enrld_plip_flag   	:= p_rt_enrld_plip_flag;
7129 		g_all_prfls(p_ordr_num).rt_enrld_ptip_flag   	:= p_rt_enrld_ptip_flag;
7130 		g_all_prfls(p_ordr_num).rt_enrld_pgm_flag   	:= p_rt_enrld_pgm_flag;
7131 		g_all_prfls(p_ordr_num).rt_prtt_anthr_pl_flag   := p_rt_prtt_anthr_pl_flag;
7132 		g_all_prfls(p_ordr_num).rt_othr_ptip_flag   	:= p_rt_othr_ptip_flag;
7133 		g_all_prfls(p_ordr_num).rt_no_othr_cvg_flag   	:= p_rt_no_othr_cvg_flag;
7134 		g_all_prfls(p_ordr_num).rt_dpnt_othr_ptip_flag  := p_rt_dpnt_othr_ptip_flag;
7135 		g_all_prfls(p_ordr_num).rt_qua_in_gr_flag   	:= p_rt_qua_in_gr_flag;
7136 		g_all_prfls(p_ordr_num).rt_perf_rtng_flag  	:= p_rt_perf_rtng_flag;
7137 		g_all_prfls(p_ordr_num).rt_elig_prfl_flag  	:= p_rt_elig_prfl_flag;
7138 
7139            end if;
7140   else
7141     -- load the 'use prfls' globals.  These can use a regular count for
7142     -- index number and avoid gaps.
7143           l_insert_record := 'Y';
7144           if g_num_of_prfls_used <> 0 then
7145              -- it's not the first, loop thru the table to see if we've already
7146              -- matched this profile for a person.
7147              for y in 1..g_num_of_prfls_used loop
7148                  if g_use_prfls(y).vrbl_rt_prfl_id = p_vrbl_rt_prfl_id then
7149                     g_use_prfls(y).match_cnt := g_use_prfls(y).match_cnt+1;
7150                     g_use_prfls(y).match_cvg := g_use_prfls(y).match_cvg+p_bnft_amt;
7151                     l_insert_record := 'N';
7152                     hr_utility.set_location ('added to profile:'||
7153                                to_char(p_vrbl_rt_prfl_id)||
7154                                ' new num:'||to_char(g_use_prfls(y).match_cnt)||
7155                                ' new cvg:'||to_char(g_use_prfls(y).match_cvg),26);
7156                     exit;
7157                  end if;
7158              end loop;
7159           end if;
7160           if l_insert_record = 'Y' then
7161                 -- We didn't find a match in the table, add a row to table.
7162                 -- increase the total number of profiles matched
7163                 g_num_of_prfls_used := g_num_of_prfls_used + 1;
7164                 g_use_prfls(g_num_of_prfls_used).vrbl_rt_prfl_id :=
7165                              p_vrbl_rt_prfl_id;
7166                 g_use_prfls(g_num_of_prfls_used).match_cnt       := 1;
7167                 g_use_prfls(g_num_of_prfls_used).match_cvg := p_bnft_amt;
7168                 hr_utility.set_location ('added new profile '||
7169                     to_char(p_vrbl_rt_prfl_id)||
7170                     ' cvg:'||to_char(p_bnft_amt),28);
7171           end if;
7172   end if;
7173 --  hr_utility.set_location ('Leaving '||l_package,99);
7174 end load_globals;
7175 --
7176 --
7177 -- ---------------------------------------------------------------------------
7178 -- Main
7179 -- ---------------------------------------------------------------------------
7180  procedure main
7181    (p_currepe_row            in ben_determine_rates.g_curr_epe_rec
7182     := ben_determine_rates.g_def_curr_epe_rec
7183    ,p_per_row                   in per_all_people_F%rowtype
7184     := ben_determine_rates.g_def_curr_per_rec
7185    ,p_asg_row                   in per_all_assignments_f%rowtype
7186     := ben_determine_rates.g_def_curr_asg_rec
7187    ,p_ast_row                   in per_assignment_status_types%rowtype
7188     := ben_determine_rates.g_def_curr_ast_rec
7189    ,p_adr_row                   in per_addresses%rowtype
7190     := ben_determine_rates.g_def_curr_adr_rec
7191    ,p_person_id                 in number
7192    ,p_elig_per_elctbl_chc_id	in number
7193    ,p_acty_base_rt_id           in number  default null
7194    ,p_actl_prem_id              in number  default null
7195    ,p_cvg_amt_calc_mthd_id      in number  default null
7196    ,p_effective_date            in date
7197    ,p_lf_evt_ocrd_dt            in date    default null
7198    ,p_calc_only_rt_val_flag     in boolean default false
7199    ,p_pgm_id                    in number  default null
7200    ,p_pl_id                     in number  default null
7201    ,p_pl_typ_id                 in number  default null
7202    ,p_oipl_id                   in number  default null
7203    ,p_per_in_ler_id             in number  default null
7204    ,p_ler_id                    in number  default null
7205    ,p_business_group_id         in number  default null
7206    ,p_ttl_prtt                  in number  default null
7207    ,p_ttl_cvg                   in number  default null
7208    ,p_all_prfls                 in boolean default false
7209    ,p_use_globals               in boolean default false
7210    ,p_use_prfls                 in boolean default false
7211    ,p_bnft_amt                  in number  default null
7212    ,p_vrbl_rt_prfl_id           out nocopy number
7213    )
7214 is
7215   --
7216   l_package               varchar2(80) := g_package||'.main';
7217   --
7218   cursor c_gre
7219     (c_soft_coding_keyflex_id number
7220     )
7221   is
7222   select sck.segment1 gre_id
7223     from hr_soft_coding_keyflex sck
7224    where sck.soft_coding_keyflex_id = c_soft_coding_keyflex_id;
7225   --
7226   cursor c_epe
7227   is
7228     select epe.pgm_id,
7229            epe.pl_id,
7230            epe.pl_typ_id,
7231            epe.oipl_id,
7232            epe.business_group_id,
7233            epe.plip_id,
7234            epe.ptip_id,
7235            epe.oiplip_id,
7236            pil.ler_id,
7237            pil.per_in_ler_id
7238       from ben_elig_per_elctbl_chc epe,
7239            ben_per_in_ler pil
7240      where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
7241        and epe.per_in_ler_id = pil.per_in_ler_id;
7242   --
7243   l_epe c_epe%rowtype;
7244   --
7245   l_profile           ben_rtp_cache.g_cobcep_cache_rec;
7246   l_vrbl_rt_prfl_id   ben_vrbl_rt_prfl_f.vrbl_rt_prfl_id%type := NULL;
7247   l_oipl_rec          ben_oipl_f%rowtype;
7248   l_gre_id            number(15);
7249   l_person_type       varchar2(30);
7250   l_per_rec           per_all_people_f%rowtype;
7251   l_asg_rec           per_all_assignments_f%rowtype;
7252   l_adr_rec           per_addresses%rowtype;
7253   l_loc_rec           hr_locations_all%rowtype;
7254   l_jurisdiction_code varchar2(30);
7255   l_matched_vrbl_prfl varchar2(1) := 'N';
7256   l_all_ctr           number := 0;
7257   l_ttl_cvg           number;
7258   l_ttl_prtt          number;
7259   l_loop_count        number;
7260   l_typ_rec           ben_person_object.g_cache_typ_table;
7261   l_ast_rec           per_assignment_status_types%rowtype;
7262   l_appass_rec        ben_person_object.g_cache_ass_table;
7263   --
7264   l_effective_date    date;
7265   l_eligible          boolean;
7266   -- FONM
7267   l_fonm_cvg_strt_dt   date;
7268   l_score_tab         ben_evaluate_elig_profiles.scoreTab;
7269   l_inst_set          ben_rtp_cache.g_cobcep_odcache;
7270   --
7271   --
7272 begin
7273   --
7274   hr_utility.set_location ('Entering '||l_package,10);
7275   hr_utility.set_location( 'elig per elect id ' || p_elig_per_elctbl_chc_id, 610.3);
7276   --Bug 5077452
7277   if fnd_global.conc_request_id = -1 then
7278     --
7279     ben_env_object.init(p_business_group_id  => p_business_group_id,
7280                       p_effective_date     => p_effective_date,
7281                       p_thread_id          => 1,
7282                       p_chunk_size         => 1,
7283                       p_threads            => 1,
7284                       p_max_errors         => 1,
7285                       p_benefit_action_id  => null);
7286     --
7287   end if;
7288   --
7289   -- FONM
7290   if ben_manage_life_events.fonm = 'Y' then
7291      --
7292      l_fonm_cvg_strt_dt := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
7293                                ben_manage_life_events.g_fonm_cvg_strt_dt);
7294      --
7295   end if;
7296   --
7297   l_effective_date := nvl(p_lf_evt_ocrd_dt,p_effective_date);
7298   --
7299   if  p_all_prfls  then
7300    hr_utility.set_location('p_all_prfls -> true',11);
7301   else    hr_utility.set_location('p_all_prfls -> false',11); end if;
7302   if  p_use_globals  then
7303    hr_utility.set_location('p_use_globals -> true',11);
7304   else    hr_utility.set_location('p_use_globals -> false',11); end if;
7305 
7306   if p_person_id is NULL then
7307     fnd_message.set_name('BEN','BEN_91521_BERP_PERSON_ID');
7308     fnd_message.set_token('PACKAGE',l_package);
7309     fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
7310     fnd_message.set_token('PL_TYP_ID',to_char(p_pl_typ_id));
7311     fnd_message.set_token('PL_ID',to_char(p_pl_id));
7312     fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
7313     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
7314     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7315     fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',p_elig_per_elctbl_chc_id);
7316     fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
7317     fnd_message.raise_error;
7318   elsif p_effective_date is NULL then
7319     fnd_message.set_name('BEN','BEN_91522_BERP_EFF_DATE');
7320     fnd_message.set_token('PACKAGE',l_package);
7321     fnd_message.set_token('PERSON_ID',p_person_id);
7322     fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
7323     fnd_message.set_token('PL_TYP_ID',to_char(p_pl_typ_id));
7324     fnd_message.set_token('PL_ID',to_char(p_pl_id));
7325     fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
7326     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
7327     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7328     fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',p_elig_per_elctbl_chc_id);
7329     fnd_message.raise_error;
7330   elsif p_elig_per_elctbl_chc_id is NULL and
7331         p_calc_only_rt_val_flag = FALSE then
7332     fnd_message.set_name('BEN','BEN_91523_BERP_ELECTBL_CHC');
7333     fnd_message.set_token('PACKAGE',l_package);
7334     fnd_message.set_token('PERSON_ID',p_person_id);
7335     fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
7336     fnd_message.set_token('PL_TYP_ID',to_char(p_pl_typ_id));
7337     fnd_message.set_token('PL_ID',to_char(p_pl_id));
7338     fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
7339     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
7340     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7341     fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
7342     fnd_message.raise_error;
7343   elsif (p_acty_base_rt_id is NULL and
7344          p_actl_prem_id is NULL and
7345          p_cvg_amt_calc_mthd_id is NULL) then
7346     fnd_message.set_name('BEN','BEN_91524_BERP_MISS_PRFL_ID');
7347     fnd_message.set_token('PACKAGE',l_package);
7348     fnd_message.set_token('PERSON_ID',p_person_id);
7349     fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
7350     fnd_message.set_token('PL_TYP_ID',to_char(p_pl_typ_id));
7351     fnd_message.set_token('PL_ID',to_char(p_pl_id));
7352     fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
7353     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
7354     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7355     fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
7356     fnd_message.raise_error;
7357   elsif (p_acty_base_rt_id is not NULL and
7358          p_actl_prem_id is not NULL) or
7359         (p_acty_base_rt_id is not NULL and
7360          p_cvg_amt_calc_mthd_id is not NULL) or
7361         (p_actl_prem_id  is not NULL and
7362          p_cvg_amt_calc_mthd_id is not NULL) then
7363     fnd_message.set_name('BEN','BEN_91525_BERP_MULTI_PRFL_ID');
7364     fnd_message.set_token('PACKAGE',l_package);
7365     fnd_message.set_token('PERSON_ID',p_person_id);
7366     fnd_message.set_token('PGM_ID',to_char(p_pgm_id));
7367     fnd_message.set_token('PL_TYP_ID',to_char(p_pl_typ_id));
7368     fnd_message.set_token('PL_ID',to_char(p_pl_id));
7369     fnd_message.set_token('OIPL_ID',to_char(p_oipl_id));
7370     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
7371     fnd_message.set_token('PER_IN_LER_ID',to_char(p_per_in_ler_id));
7372     fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
7373     fnd_message.raise_error;
7374   end if;
7375 
7376   if p_per_row.person_id is null then
7377     --
7378     ben_person_object.get_object     --  FONM : 9999 do we need to rebuild the cache
7379       (p_person_id => p_person_id
7380       ,p_rec       => l_per_rec
7381       );
7382     --
7383   else
7384     --
7385     l_per_rec := p_per_row;
7386     --
7387   end if;
7388 
7389   -- fonm check the date of the person cache
7390   if not nvl(l_fonm_cvg_strt_dt,l_effective_date)
7391              between l_per_rec.effective_start_date and l_per_rec.effective_end_date then
7392 
7393           hr_utility.set_location('clearing cache' || nvl(l_fonm_cvg_strt_dt,l_effective_date) ,10);
7394           hr_utility.set_location('cache start  ' || l_per_rec.effective_start_date ,10);
7395           hr_utility.set_location('cache end  ' || l_per_rec.effective_end_date ,10);
7396 
7397           ben_use_cvg_rt_date.fonm_clear_down_cache;
7398           --
7399           ben_person_object.get_object(p_person_id => p_person_id,
7400                                        p_rec       => l_per_rec);
7401 
7402           hr_utility.set_location('nw cache start  ' || l_per_rec.effective_start_date ,10);
7403           hr_utility.set_location('nw cache end  ' || l_per_rec.effective_end_date ,10);
7404    end if ;
7405 
7406 
7407 
7408   if p_asg_row.assignment_id is null then
7409     --
7410     ben_person_object.get_object     --  FONM : 9999 do we need to rebuild the cache
7411       (p_person_id => p_person_id
7412       ,p_rec       => l_asg_rec );
7413     --
7414   else
7415     --
7416     l_asg_rec := p_asg_row;
7417     --
7418   end if;
7419 
7420 
7421 
7422   --
7423 
7424   if l_asg_rec.assignment_id is null then
7425     --
7426     ben_person_object.get_benass_object     --  FONM : 9999 do we need to rebuild the cache
7427       (p_person_id => p_person_id
7428       ,p_rec       => l_asg_rec );
7429     --
7430     -- If benefit assignment not found, get applicant assignment.
7431     --
7432     if l_asg_rec.assignment_id is null then
7433       --
7434       ben_person_object.get_object(p_person_id => p_person_id,     --  FONM : 9999 do we need to rebuild the cache
7435                                    p_rec       => l_appass_rec );
7436       --
7437     else
7438       --
7439       ben_person_object.get_object
7440      (p_assignment_status_type_id => l_asg_rec.assignment_status_type_id   --  FONM : 9999 do we need to rebuild the cache
7441         ,p_rec                       => l_ast_rec );
7442       --
7443     end if;
7444   --
7445   else
7446     --
7447     if p_ast_row.assignment_status_type_id is null then
7448       --
7449       ben_person_object.get_object     --  FONM : 9999 do we need to rebuild the cache
7450         (p_assignment_status_type_id => l_asg_rec.assignment_status_type_id
7451         ,p_rec                       => l_ast_rec
7452         );
7453       --
7454     else
7455       --
7456       l_ast_rec := p_ast_row;
7457       --
7458     end if;
7459     --
7460   end if;
7461   --
7462   -- Check if the address row is passed in
7463   --
7464   if p_adr_row.address_id is null then
7465     --
7466     ben_person_object.get_object     --  FONM : 9999 do we need to rebuild the cache
7467       (p_person_id => p_person_id
7468       ,p_rec       => l_adr_rec
7469       );
7470     --
7471   else
7472     --
7473     l_adr_rec := p_adr_row;
7474     --
7475   end if;
7476   --
7477   if l_asg_rec.location_id is not null then
7478     --
7479     ben_location_object.get_object     --  FONM : 9999 do we need to rebuild the cache
7480       (p_location_id => l_asg_rec.location_id
7481       ,p_rec         => l_loc_rec);
7482     --
7483 --   if l_loc_rec.region_2 is not null then
7484       --
7485 --    l_jurisdiction_code :=
7486 --        pay_mag_utils.lookup_jurisdiction_code
7487 --          (p_state => l_loc_rec.region_2);
7488       --
7489 --   end if;
7490     --
7491   end if;
7492   --
7493   -- Bug 9033589: Commented the below condition because l_epe.plip_id is not getting initialized.
7494 
7495   /*
7496   if p_calc_only_rt_val_flag then
7497     --
7498     l_epe.pgm_id            := p_pgm_id;
7499     l_epe.pl_id             := p_pl_id;
7500     l_epe.pl_typ_id         := p_pl_typ_id;
7501     l_epe.oipl_id           := p_oipl_id;
7502     l_epe.per_in_ler_id     := p_per_in_ler_id;
7503     l_epe.ler_id            := p_ler_id;
7504     l_epe.business_group_id := p_business_group_id;
7505   */
7506   --
7507   -- Check if the context row is populated
7508   --
7509   if p_currepe_row.elig_per_elctbl_chc_id is not null
7510   then
7511     --
7512     hr_utility.set_location( ' else if  ',610);
7513     hr_utility.set_location( ' PLIP ID   '|| p_currepe_row.plip_id ,610);
7514     l_epe.pgm_id            := p_currepe_row.pgm_id;
7515     l_epe.pl_id             := p_currepe_row.pl_id;
7516     l_epe.pl_typ_id         := p_currepe_row.pl_typ_id;
7517     l_epe.oipl_id           := p_currepe_row.oipl_id;
7518     l_epe.oiplip_id         := p_currepe_row.oiplip_id; --9999
7519     l_epe.per_in_ler_id     := p_currepe_row.per_in_ler_id;
7520     l_epe.ler_id            := p_currepe_row.ler_id;
7521     l_epe.plip_id           := p_currepe_row.plip_id;
7522     l_epe.business_group_id := p_currepe_row.business_group_id;
7523     --
7524   else
7525     hr_utility.set_location( ' in cursor ',610) ;
7526     open c_epe;
7527     fetch c_epe into l_epe;
7528     close c_epe;
7529   end if;
7530   --
7531   hr_utility.set_location(' oipl id ' || l_epe.oipl_id , 610.3);
7532   hr_utility.set_location( ' PLIP ID   '|| l_epe.plip_id ,610);
7533   if l_epe.oipl_id is not null then
7534     ben_comp_object.get_object(p_oipl_id => l_epe.oipl_id
7535                               ,p_rec     => l_oipl_rec);
7536   end if;
7537   --
7538   if p_use_globals then
7539     l_all_ctr := g_all_prfls.first;
7540   end if;
7541   --
7542   -- Mallik: Removed the cursors and introduced the call to vapro cache
7543   --
7544   if not (p_actl_prem_id is not NULL and p_use_globals) then
7545      ben_rtp_cache.abravr_odgetdets
7546      (p_effective_date        =>  nvl(l_fonm_cvg_strt_dt,l_effective_date)
7547      ,p_acty_base_rt_id       => p_acty_base_rt_id
7548      ,p_cvg_amt_calc_mthd_id  => p_cvg_amt_calc_mthd_id
7549      ,p_actl_prem_id          => p_actl_prem_id
7550      ,p_inst_set              => l_inst_set
7551      );
7552   end if;
7553 
7554   hr_utility.set_location ('Prof loop '||l_package,10);
7555   for i in 1..l_inst_set.count
7556   loop
7557     --
7558     begin
7559 
7560       l_profile := l_inst_set(i);
7561 
7562       if p_actl_prem_id is not NULL then
7563 
7564         if p_use_globals then
7565           if l_all_ctr is null then
7566             exit;
7567           end if;
7568 
7569           --  load fields that process will use from globals instead of cursor:
7570           l_profile.vrbl_rt_prfl_id    := g_all_prfls(l_all_ctr).vrbl_rt_prfl_id;
7571           l_profile.asmt_to_use_cd     := g_all_prfls(l_all_ctr).asmt_to_use_cd  ;
7572           l_profile.rt_hrly_slrd_flag  := g_all_prfls(l_all_ctr).rt_hrly_slrd_flag  ;
7573           l_profile.rt_pstl_cd_flag    := g_all_prfls(l_all_ctr).rt_pstl_cd_flag  ;
7574           l_profile.rt_lbr_mmbr_flag   := g_all_prfls(l_all_ctr).rt_lbr_mmbr_flag  ;
7575           l_profile.rt_lgl_enty_flag   := g_all_prfls(l_all_ctr).rt_lgl_enty_flag  ;
7576           l_profile.rt_benfts_grp_flag := g_all_prfls(l_all_ctr).rt_benfts_grp_flag  ;
7577           l_profile.rt_wk_loc_flag     := g_all_prfls(l_all_ctr).rt_wk_loc_flag  ;
7578           l_profile.rt_brgng_unit_flag := g_all_prfls(l_all_ctr).rt_brgng_unit_flag  ;
7579           l_profile.rt_age_flag        := g_all_prfls(l_all_ctr).rt_age_flag  ;
7580           l_profile.rt_los_flag        := g_all_prfls(l_all_ctr).rt_los_flag  ;
7581           l_profile.rt_per_typ_flag    := g_all_prfls(l_all_ctr).rt_per_typ_flag  ;
7582           l_profile.rt_fl_tm_pt_tm_flag:= g_all_prfls(l_all_ctr).rt_fl_tm_pt_tm_flag  ;
7583           l_profile.rt_ee_stat_flag    := g_all_prfls(l_all_ctr).rt_ee_stat_flag  ;
7584           l_profile.rt_grd_flag        := g_all_prfls(l_all_ctr).rt_grd_flag  ;
7585           l_profile.rt_pct_fl_tm_flag  := g_all_prfls(l_all_ctr).rt_pct_fl_tm_flag  ;
7586           l_profile.rt_asnt_set_flag   := g_all_prfls(l_all_ctr).rt_asnt_set_flag  ;
7587           l_profile.rt_hrs_wkd_flag    := g_all_prfls(l_all_ctr).rt_hrs_wkd_flag  ;
7588           l_profile.rt_comp_lvl_flag   := g_all_prfls(l_all_ctr).rt_comp_lvl_flag  ;
7589           l_profile.rt_org_unit_flag   := g_all_prfls(l_all_ctr).rt_org_unit_flag  ;
7590           l_profile.rt_loa_rsn_flag    := g_all_prfls(l_all_ctr).rt_loa_rsn_flag  ;
7591           l_profile.rt_pyrl_flag       := g_all_prfls(l_all_ctr).rt_pyrl_flag  ;
7592           l_profile.rt_schedd_hrs_flag := g_all_prfls(l_all_ctr).rt_schedd_hrs_flag  ;
7593           l_profile.rt_py_bss_flag     := g_all_prfls(l_all_ctr).rt_py_bss_flag  ;
7594           l_profile.rt_prfl_rl_flag    := g_all_prfls(l_all_ctr).rt_prfl_rl_flag  ;
7595           l_profile.rt_cmbn_age_los_flag := g_all_prfls(l_all_ctr).rt_cmbn_age_los_flag ;
7596           l_profile.rt_prtt_pl_flag    := g_all_prfls(l_all_ctr).rt_prtt_pl_flag  ;
7597           l_profile.rt_svc_area_flag   := g_all_prfls(l_all_ctr).rt_svc_area_flag  ;
7598           l_profile.rt_ppl_grp_flag    := g_all_prfls(l_all_ctr).rt_ppl_grp_flag  ;
7599           l_profile.rt_dsbld_flag      := g_all_prfls(l_all_ctr).rt_dsbld_flag  ;
7600           l_profile.rt_hlth_cvg_flag   := g_all_prfls(l_all_ctr).rt_hlth_cvg_flag  ;
7601           l_profile.rt_poe_flag        := g_all_prfls(l_all_ctr).rt_poe_flag  ;
7602           l_profile.rt_ttl_cvg_vol_flag:= g_all_prfls(l_all_ctr).rt_ttl_cvg_vol_flag  ;
7603           l_profile.rt_ttl_prtt_flag   := g_all_prfls(l_all_ctr).rt_ttl_prtt_flag  ;
7604           l_profile.rt_gndr_flag       := g_all_prfls(l_all_ctr).rt_gndr_flag  ;
7605           l_profile.rt_tbco_use_flag   := g_all_prfls(l_all_ctr).rt_tbco_use_flag ;
7606           l_profile.rt_cntng_prtn_prfl_flag := g_all_prfls(l_all_ctr).rt_cntng_prtn_prfl_flag;
7607           l_profile.rt_cbr_quald_bnf_flag  := g_all_prfls(l_all_ctr).rt_cbr_quald_bnf_flag;
7608           l_profile.rt_optd_mdcr_flag      := g_all_prfls(l_all_ctr).rt_optd_mdcr_flag;
7609           l_profile.rt_lvg_rsn_flag        := g_all_prfls(l_all_ctr).rt_lvg_rsn_flag;
7610           l_profile.rt_pstn_flag           := g_all_prfls(l_all_ctr).rt_pstn_flag;
7611           l_profile.rt_comptncy_flag       := g_all_prfls(l_all_ctr).rt_comptncy_flag;
7612           l_profile.rt_job_flag            := g_all_prfls(l_all_ctr).rt_job_flag;
7613           l_profile.rt_qual_titl_flag      := g_all_prfls(l_all_ctr).rt_qual_titl_flag;
7614           l_profile.rt_dpnt_cvrd_pl_flag   := g_all_prfls(l_all_ctr).rt_dpnt_cvrd_pl_flag;
7615           l_profile.rt_dpnt_cvrd_plip_flag := g_all_prfls(l_all_ctr).rt_dpnt_cvrd_plip_flag;
7616           l_profile.rt_dpnt_cvrd_ptip_flag := g_all_prfls(l_all_ctr).rt_dpnt_cvrd_ptip_flag;
7617           l_profile.rt_dpnt_cvrd_pgm_flag  := g_all_prfls(l_all_ctr).rt_dpnt_cvrd_pgm_flag;
7618           l_profile.rt_enrld_oipl_flag     := g_all_prfls(l_all_ctr).rt_enrld_oipl_flag;
7619           l_profile.rt_enrld_pl_flag       := g_all_prfls(l_all_ctr).rt_enrld_pl_flag;
7620           l_profile.rt_enrld_plip_flag     := g_all_prfls(l_all_ctr).rt_enrld_plip_flag;
7621           l_profile.rt_enrld_ptip_flag     := g_all_prfls(l_all_ctr).rt_enrld_ptip_flag;
7622           l_profile.rt_enrld_pgm_flag      := g_all_prfls(l_all_ctr).rt_enrld_pgm_flag;
7623           l_profile.rt_prtt_anthr_pl_flag  := g_all_prfls(l_all_ctr).rt_prtt_anthr_pl_flag;
7624           l_profile.rt_othr_ptip_flag      := g_all_prfls(l_all_ctr).rt_othr_ptip_flag;
7625           l_profile.rt_no_othr_cvg_flag    := g_all_prfls(l_all_ctr).rt_no_othr_cvg_flag;
7626           l_profile.rt_dpnt_othr_ptip_flag := g_all_prfls(l_all_ctr).rt_dpnt_othr_ptip_flag;
7627           l_profile.rt_qua_in_gr_flag      := g_all_prfls(l_all_ctr).rt_qua_in_gr_flag;
7628           l_profile.rt_perf_rtng_flag 	   := g_all_prfls(l_all_ctr).rt_perf_rtng_flag;
7629           l_profile.rt_elig_prfl_flag 	   := g_all_prfls(l_all_ctr).rt_elig_prfl_flag;
7630 
7631           --
7632           -- use total counts for all prtts in this plan or oipl that match
7633           -- this particular vrbl rate's criteria.
7634           --
7635           l_ttl_prtt := g_all_prfls(l_all_ctr).match_cnt;
7636           l_ttl_cvg  := g_all_prfls(l_all_ctr).match_cvg;
7637           -- get ready for next loop
7638           l_all_ctr := g_all_prfls.next(l_all_ctr);
7639           --
7640         else
7641           --
7642           -- use total counts for all prtts in this plan or oipl
7643           --
7644           l_ttl_prtt := p_ttl_prtt;
7645           l_ttl_cvg  := p_ttl_cvg;
7646           --
7647         end if;
7648         --
7649       end if;
7650       --
7651       ben_person_object.get_object(p_person_id => p_person_id, -- FONM 9999
7652                                    p_rec       => l_typ_rec);
7653       --
7654  hr_utility.set_location('l_profile.vrbl_rt_prfl_id -> '||l_profile.vrbl_rt_prfl_id,11);
7655  hr_utility.set_location('l_profile.rt_per_typ_flag -> '||l_profile.rt_per_typ_flag,11);
7656 --
7657       if l_profile.rt_elig_prfl_flag = 'Y' then
7658          hr_utility.set_location('elig_for_profiles',10);
7659 
7660          l_eligible :=
7661          ben_evaluate_elig_profiles.eligible
7662         (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id
7663         ,p_person_id            => p_person_id
7664         ,p_business_group_id    => p_business_group_id
7665         ,p_effective_date       => p_effective_date
7666         ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt
7667         ,p_per_in_ler_id        => p_per_in_ler_id
7668         ,p_ler_id               => p_ler_id
7669         ,p_pgm_id               => l_epe.pgm_id
7670         ,p_ptip_id              => l_epe.ptip_id
7671         ,p_plip_id              => nvl(p_currepe_row.plip_id,l_epe.plip_id)
7672         ,p_pl_id                => l_epe.pl_id
7673         ,p_oipl_id              => l_epe.oipl_id
7674         ,p_oiplip_id            => l_epe.oiplip_id
7675         ,p_pl_typ_id            => l_epe.pl_typ_id
7676         ,p_opt_id               => nvl(p_currepe_row.opt_id,l_oipl_rec.opt_id)
7677         ,p_par_pgm_id           => p_currepe_row.pgm_id
7678         ,p_par_plip_id          => p_currepe_row.plip_id
7679         ,p_par_pl_id            => p_currepe_row.pl_id
7680         ,p_par_opt_id           => p_currepe_row.opt_id
7681         ,p_currepe_row          => p_currepe_row
7682         ,p_ttl_prtt             => l_ttl_prtt
7683         ,p_ttl_cvg              => l_ttl_cvg
7684         ,p_all_prfls            => p_all_prfls
7685         ,p_score_tab            => l_score_tab
7686         ,p_eval_typ             => 'V'
7687         );
7688         --
7689         if not l_eligible then
7690            --
7691            raise g_profile_failed;
7692            --
7693         end if;
7694       end if;
7695       hr_utility.set_location ('Dn elig_for_profiles '||l_package,10);
7696 
7697       if l_profile.rt_per_typ_flag = 'Y' then
7698       hr_utility.set_location('check_per_typ',10);
7699       check_per_typ
7700         (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7701          p_person_id         => p_person_id,
7702          p_business_group_id => p_business_group_id,
7703          p_effective_date    => p_effective_date,
7704          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7705          p_person_type       => l_typ_rec);
7706       end if;
7707       hr_utility.set_location ('Dn check_per_typ '||l_package,10);
7708       --
7709       -- Now we check these profiles using the required assignment type
7710       --
7711       l_loop_count := 1;
7712       --
7713       if l_profile.asmt_to_use_cd = 'EAO' then
7714         --
7715         -- Employee assignment only
7716         --
7717 	l_asg_rec := NULL;          --Bug 6399423
7718         ben_person_object.get_object(p_person_id => p_person_id,
7719                                      p_rec       => l_asg_rec);
7720         --
7721       elsif l_profile.asmt_to_use_cd = 'BAO' then
7722         --
7723         -- Benefit assignment only
7724         --
7725 	l_asg_rec := NULL;          --Bug 6399423
7726         ben_person_object.get_benass_object(p_person_id => p_person_id,
7727                                             p_rec       => l_asg_rec);
7728         --
7729       elsif l_profile.asmt_to_use_cd = 'ANY' then
7730         --
7731         -- First assignment only
7732         --
7733         ben_person_object.get_allass_object(p_person_id => p_person_id,
7734                                             p_rec       => l_appass_rec);
7735         --
7736         if not l_appass_rec.exists(1) then
7737           --
7738           -- Initialize first record so that one time test works
7739           --
7740           l_appass_rec(1).person_id := p_person_id;
7741           --
7742         end if;
7743         --
7744         l_asg_rec := l_appass_rec(1);
7745         l_loop_count := l_appass_rec.count;
7746         --
7747       elsif l_profile.asmt_to_use_cd = 'AAO' then
7748         --
7749         -- Applicant assignment only
7750         --
7751         ben_person_object.get_object(p_person_id => p_person_id,
7752                                      p_rec       => l_appass_rec);
7753         --
7754         if not l_appass_rec.exists(1) then
7755           --
7756           -- Initialize first record so that one time test works
7757           --
7758           l_appass_rec(1).person_id := p_person_id;
7759           --
7760         end if;
7761         --
7762         l_asg_rec := l_appass_rec(1);
7763         l_loop_count := l_appass_rec.count;
7764         --
7765       elsif l_profile.asmt_to_use_cd = 'ETB' then
7766         --
7767         -- Employee then Benefits assignment only
7768         --
7769         ben_person_object.get_object(p_person_id => p_person_id,
7770                                      p_rec       => l_asg_rec);
7771         --
7772         if l_asg_rec.assignment_id is null then
7773           --
7774           -- Get Benefits Assignment
7775           --
7776           ben_person_object.get_benass_object(p_person_id => p_person_id,
7777                                               p_rec       => l_asg_rec);
7778           --
7779         end if;
7780         --
7781       elsif l_profile.asmt_to_use_cd = 'BTE' then
7782         --
7783         -- Benefits then Employee assignment only
7784         --
7785         ben_person_object.get_benass_object(p_person_id => p_person_id,
7786                                             p_rec       => l_asg_rec);
7787         --
7788         if l_asg_rec.assignment_id is null then
7789           --
7790           -- Get Employee Assignment
7791           --
7792           ben_person_object.get_object(p_person_id => p_person_id,
7793                                        p_rec       => l_asg_rec);
7794           --
7795         end if;
7796         --
7797       elsif l_profile.asmt_to_use_cd = 'EBA' then
7798         --
7799         -- Employee then Benefits then Applicant assignment only
7800         --
7801         ben_person_object.get_object(p_person_id => p_person_id,
7802                                      p_rec       => l_asg_rec);
7803         --
7804         if l_asg_rec.assignment_id is null then
7805           --
7806           -- Get Benefits Assignment
7807           --
7808           ben_person_object.get_benass_object(p_person_id => p_person_id,
7809                                               p_rec       => l_asg_rec);
7810           --
7811           if l_asg_rec.assignment_id is null then
7812             --
7813             -- Applicant assignment only
7814             --
7815             ben_person_object.get_object(p_person_id => p_person_id,
7816                                          p_rec       => l_appass_rec);
7817             --
7818             if not l_appass_rec.exists(1) then
7819               --
7820               -- Initialize first record so that one time test works
7821               --
7822               l_appass_rec(1).person_id := p_person_id;
7823               --
7824             end if;
7825             --
7826             l_asg_rec := l_appass_rec(1);
7827             l_loop_count := l_appass_rec.count;
7828             --
7829           end if;
7830           --
7831         end if;
7832         --
7833       end if;
7834       --
7835 -- Bug 6399423
7836       hr_utility.set_location ('l_asg_rec'|| l_asg_rec.assignment_id,534511234);
7837       --
7838       if (l_profile.asmt_to_use_cd <> 'ANY' and
7839                  l_asg_rec.assignment_id is null) then
7840                --
7841 	 raise ben_evaluate_rate_profiles.g_profile_failed;
7842       end if;
7843       --
7844 -- Bug 6399423
7845       hr_utility.set_location ('ASG Profs '||l_package,10);
7846       for l_count in 1..l_loop_count loop
7847         --
7848         begin
7849           --
7850           if l_loop_count > 1 then
7851             --
7852             -- Make sure that we pass in the correct assignment
7853             --
7854             l_asg_rec := l_appass_rec(l_count);
7855             --
7856           end if;
7857           --
7858           --          Employee Status
7859           --
7860           if l_profile.rt_ee_stat_flag = 'Y' then
7861           hr_utility.set_location('check_ee_stat',10);
7862           check_ee_stat
7863             (p_vrbl_rt_prfl_id           => l_profile.vrbl_rt_prfl_id,
7864              p_person_id                 => p_person_id,
7865              p_business_group_id         => p_business_group_id,
7866              p_effective_date            => p_effective_date,
7867              p_lf_evt_ocrd_dt            => p_lf_evt_ocrd_dt,
7868              p_assignment_status_type_id => l_asg_rec.assignment_status_type_id);
7869           end if;
7870           --
7871           --          People Group
7872           --
7873           if l_profile.rt_ppl_grp_flag = 'Y' then
7874           hr_utility.set_location('check_people_group',10);
7875           check_people_group
7876             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7877              p_business_group_id => p_business_group_id,
7878              p_effective_date    => p_effective_date,
7879              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7880              p_people_group_id   => l_asg_rec.people_group_id);
7881           end if;
7882           --
7883           --          Hourly/Salary Code
7884           --
7885           if l_profile.rt_hrly_slrd_flag = 'Y' then
7886           hr_utility.set_location('check_hourly_salary',10);
7887           check_hourly_salary
7888             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7889              p_business_group_id => p_business_group_id,
7890              p_effective_date    => p_effective_date,
7891              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7892              p_hrly_slry         => l_asg_rec.hourly_salaried_code);
7893           end if;
7894           --
7895           --          Bargaining Unit
7896           --
7897           if l_profile.rt_brgng_unit_flag = 'Y' then
7898           hr_utility.set_location('check_brgng_unit',10);
7899           check_brgng_unit
7900             (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
7901              p_business_group_id    => p_business_group_id,
7902              p_effective_date       => p_effective_date,
7903              p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
7904              p_bargaining_unit_code => l_asg_rec.bargaining_unit_code);
7905           end if;
7906           --
7907           --            Labor Union
7908           --
7909           if l_profile.rt_lbr_mmbr_flag = 'Y' then
7910           hr_utility.set_location('check_lbr_union',10);
7911           check_lbr_union
7912             (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
7913              p_person_id                => p_person_id,
7914              p_business_group_id        => p_business_group_id,
7915              p_effective_date           => p_effective_date,
7916              p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
7917              p_labour_union_member_flag => l_asg_rec.labour_union_member_flag);
7918           end if;
7919           --
7920           --          Full Time / Part Time
7921           --
7922           if l_profile.rt_fl_tm_pt_tm_flag = 'Y' then
7923           hr_utility.set_location('check_fl_tm_pt',10);
7924           check_fl_tm_pt
7925             (p_vrbl_rt_prfl_id     => l_profile.vrbl_rt_prfl_id,
7926              p_person_id           => p_person_id,
7927              p_business_group_id   => p_business_group_id,
7928              p_effective_date      => p_effective_date,
7929              p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt,
7930              p_employment_category => l_asg_rec.employment_category);
7931           end if;
7932           --
7933           --          Work Location
7934           --
7935           if l_profile.rt_wk_loc_flag = 'Y' then
7936           hr_utility.set_location('check_wk_location',10);
7937           check_wk_location
7938             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7939              p_person_id         => p_person_id,
7940              p_business_group_id => p_business_group_id,
7941              p_effective_date    => p_effective_date,
7942              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7943              p_location_id       => l_asg_rec.location_id);
7944           end if;
7945           --
7946           --          Organization
7947           --
7948           if l_profile.rt_org_unit_flag = 'Y' then
7949           hr_utility.set_location('check_org_unit',10);
7950           check_org_unit
7951             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7952              p_person_id         => p_person_id,
7953              p_business_group_id => p_business_group_id,
7954              p_effective_date    => p_effective_date,
7955              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7956              p_org_id            => l_asg_rec.organization_id);
7957           end if;
7958           --
7959           --          LOA
7960           --
7961           if l_profile.rt_loa_rsn_flag = 'Y' then
7962           hr_utility.set_location('check_loa_rsn',10);
7963           check_loa_rsn
7964             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7965              p_person_id         => p_person_id,
7966              p_business_group_id => p_business_group_id,
7967              p_effective_date    => p_effective_date,
7968              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
7969           end if;
7970           --
7971           --          Scheduled Hours
7972           --
7973           if l_profile.rt_schedd_hrs_flag = 'Y' then
7974           hr_utility.set_location('check_sched_hrs',10);
7975           check_sched_hrs
7976             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
7977              p_person_id         => p_person_id,
7978              p_business_group_id => p_business_group_id,
7979              p_effective_date    => p_effective_date,
7980              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
7981              p_normal_hrs        => l_asg_rec.normal_hours,
7982              p_frequency         => l_asg_rec.frequency,
7983              p_per_in_ler_id     => l_epe.per_in_ler_id,
7984              p_assignment_id     => l_asg_rec.assignment_id,
7985              p_organization_id   => l_asg_rec.organization_id,
7986              p_pgm_id            => l_epe.pgm_id,
7987              p_pl_id             => l_epe.pl_id,
7988              p_pl_typ_id         => l_epe.pl_typ_id,
7989              p_opt_id            => l_oipl_rec.opt_id,
7990              p_oipl_id          => l_epe.oipl_id,
7991              p_ler_id            => l_epe.ler_id,
7992              p_jurisdiction_code => l_jurisdiction_code);
7993           end if;
7994           --
7995           --          Pay Basis
7996           --
7997           if l_profile.rt_py_bss_flag = 'Y' then
7998           hr_utility.set_location('check_py_bss',10);
7999           check_py_bss
8000             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8001              p_person_id         => p_person_id,
8002              p_business_group_id => p_business_group_id,
8003              p_effective_date    => p_effective_date,
8004              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8005              p_pay_basis_id      => l_asg_rec.pay_basis_id);
8006           end if;
8007           --
8008           --          Grade
8009           --
8010           if l_profile.rt_grd_flag = 'Y' then
8011           hr_utility.set_location('check_grade',10);
8012           check_grade
8013             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8014              p_person_id         => p_person_id,
8015              p_business_group_id => p_business_group_id,
8016              p_effective_date    => p_effective_date,
8017              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8018              p_grade_id          => l_asg_rec.grade_id);
8019           end if;
8020           --
8021           --          Legal Entity
8022           --
8023           if l_profile.rt_lgl_enty_flag = 'Y' then
8024           hr_utility.set_location('check_lgl_enty',10);
8025           open c_gre(l_asg_rec.soft_coding_keyflex_id);
8026             --
8027             fetch c_gre into l_gre_id;
8028             --
8029           close c_gre;
8030           --
8031           check_lgl_enty
8032             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8033              p_person_id         => p_person_id,
8034              p_business_group_id => p_business_group_id,
8035              p_effective_date    => p_effective_date,
8036              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8037              p_gre_id            => l_gre_id);
8038           end if;
8039           --
8040           --          Payroll
8041           --
8042           if l_profile.rt_pyrl_flag = 'Y' then
8043           hr_utility.set_location('check_pyrl',10);
8044           check_pyrl
8045             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8046              p_person_id         => p_person_id,
8047              p_business_group_id => p_business_group_id,
8048              p_effective_date    => p_effective_date,
8049              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8050              p_payroll_id        => l_asg_rec.payroll_id);
8051           end if;
8052 
8053           --
8054           -- Job
8055           --
8056           if l_profile.rt_job_flag = 'Y' then
8057           hr_utility.set_location('check_job',10);
8058           check_job
8059             (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8060              p_business_group_id => p_business_group_id,
8061              p_effective_date    => p_effective_date,
8062              p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8063              p_job_id        	 => l_asg_rec.job_id);
8064           end if;
8065 
8066           --
8067 	  -- Postion
8068 	  --
8069 	  if l_profile.rt_pstn_flag = 'Y' then
8070 	  hr_utility.set_location('check_pstn',10);
8071 	  check_pstn
8072 	     (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8073 	     p_business_group_id => p_business_group_id,
8074 	     p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8075 	     p_effective_date	   => p_effective_date,
8076 	     p_asg_position_id   => l_asg_rec.position_id);
8077           end if;
8078 
8079           --
8080 	  --  Quartile in Grade
8081 	  --
8082 	  if l_profile.rt_qua_in_gr_flag = 'Y' then
8083 	  hr_utility.set_location('check_qua_in_gr',10);
8084 	  check_qua_in_gr(p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8085 	  		  p_business_group_id => p_business_group_id,
8086 	                  p_person_id         => p_person_id,
8087 	                  p_grade_id	      => l_asg_rec.grade_id,
8088 	                  p_assignment_id     => l_asg_rec.assignment_id,
8089 	                  p_effective_date    => p_effective_date,
8090                      	  p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8091                      	  p_pay_basis_id      => l_asg_rec.pay_basis_id);
8092           end if;
8093 
8094           --
8095 	  --  Performance Rating
8096 	  --
8097 	  if l_profile.rt_perf_rtng_flag = 'Y' then
8098 	  hr_utility.set_location('check_perf_rtng',10);
8099 	  check_perf_rtng(p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8100 	    		  p_business_group_id => p_business_group_id,
8101 	                  p_assignment_id     => l_asg_rec.assignment_id,
8102 	                  p_person_id         => p_person_id,
8103 	                  p_effective_date    => p_effective_date,
8104 	  		  p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
8105           end if;
8106 
8107           --
8108           -- Rules
8109           --
8110           if l_profile.rt_prfl_rl_flag = 'Y' then
8111           hr_utility.set_location('check_rules',10);
8112           check_rules
8113             (p_vrbl_rt_prfl_id     => l_profile.vrbl_rt_prfl_id,
8114              p_business_group_id   => p_business_group_id,
8115              p_effective_date      => p_effective_date,
8116              p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt,
8117              p_assignment_id       => l_asg_rec.assignment_id,
8118              p_organization_id     => l_asg_rec.organization_id,
8119              p_pgm_id              => l_epe.pgm_id,
8120              p_pl_id               => l_epe.pl_id,
8121              p_pl_typ_id           => l_epe.pl_typ_id,
8122              p_opt_id              => l_oipl_rec.opt_id,
8123              p_ler_id              => l_epe.ler_id,
8124              p_elig_per_elctbl_chc_id =>  p_elig_per_elctbl_chc_id,
8125              p_acty_base_rt_id     => p_acty_base_rt_id,
8126           p_jurisdiction_code   => l_jurisdiction_code);
8127        end if;
8128        --
8129        --  all criteria passed for this profile thus far so exit this
8130        --  loop and check remaining criteria
8131        --
8132        exit;
8133        --
8134        exception
8135          --
8136          when g_criteria_failed then
8137            --
8138            -- Handle case where we want an error if we are dealing with
8139            -- the last assignment to be processed. If it is the last
8140            -- assignment then we want to error the profile.
8141            --
8142            if l_count = l_loop_count then
8143              --
8144              -- Raise error to main exception handler
8145              --
8146              raise ben_evaluate_rate_profiles.g_profile_failed;
8147              --
8148            end if;
8149            --
8150         end;
8151         --
8152       end loop;
8153       --
8154       -- now check remaining criteria
8155       --
8156       --
8157       --
8158       --          PCT Fulltime
8159       --
8160       hr_utility.set_location ('Person Profs '||l_package,10);
8161       if l_profile.rt_pct_fl_tm_flag = 'Y' then
8162       hr_utility.set_location('check_pct_fltm',10);
8163       check_pct_fltm
8164         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id,
8165          p_person_id              => p_person_id,
8166          p_business_group_id      => p_business_group_id,
8167          -- FONM : as lf_evt_ocrd_dt is not used, it's fine to overload the
8168          -- p_effective_date.
8169          p_effective_date         => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
8170                                       nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
8171                                        nvl(p_lf_evt_ocrd_dt, p_effective_date))),
8172          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
8173          p_pgm_id                 => l_epe.pgm_id,
8174          p_pl_id                  => l_epe.pl_id,
8175          p_opt_id                 => l_oipl_rec.opt_id,
8176          p_plip_id                => l_epe.plip_id);
8177       end if;
8178       --
8179       --          Benefits Group
8180       --
8181       if l_profile.rt_benfts_grp_flag = 'Y' then
8182       hr_utility.set_location('check_benefits_group',10);
8183       check_benefits_grp
8184         (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8185          p_person_id         => p_person_id,
8186          p_business_group_id => p_business_group_id,
8187          p_effective_date    => p_effective_date,
8188          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8189          p_benefit_group_id  => l_per_rec.benefit_group_id);
8190       end if;
8191       --
8192       --            Age
8193       --
8194       hr_utility.set_location ('DF Profs '||l_package,10);
8195       if l_profile.rt_age_flag = 'Y' then
8196       hr_utility.set_location('check_age',10);
8197       check_age
8198         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id
8199         ,p_per_dob                => l_per_rec.date_of_birth
8200         ,p_person_id              => p_person_id
8201         ,p_business_group_id      => p_business_group_id
8202         ,p_effective_date         =>  p_effective_date
8203         ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt    -- fonm taken care in procedure
8204         ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8205         ,p_pl_id                  => nvl(l_epe.pl_id,p_pl_id) -- Bug 13919006
8206         ,p_pgm_id                 => nvl(l_epe.pgm_id,p_pgm_id) -- Bug 13919006
8207         ,p_oipl_id                => nvl(l_epe.oipl_id,p_oipl_id) -- Bug 13919006
8208         ,p_per_in_ler_id          => nvl(l_epe.per_in_ler_id,p_per_in_ler_id) -- Bug 13919006
8209         ,p_opt_id                 => nvl(p_currepe_row.opt_id,l_oipl_rec.opt_id)  -- Bug 9033589
8210         ,p_plip_id                => nvl(p_currepe_row.plip_id,l_epe.plip_id)     -- Bug 9033589
8211         ,p_currepe_row            => p_currepe_row
8212         );
8213       end if;
8214       --
8215       --          Tobacco
8216       --
8217       hr_utility.set_location ('Tobacco '||l_package,10);
8218       if l_profile.rt_tbco_use_flag = 'Y' then
8219       hr_utility.set_location('check_tobacco',10);
8220       check_tobacco
8221         (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
8222          p_business_group_id    => p_business_group_id,
8223          p_effective_date       => p_effective_date,
8224          p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
8225 	 --Handling NULL value for uses_tobacco_flag .Refer Bug : 6525934
8226          p_tobacco              => NVL(l_per_rec.uses_tobacco_flag,'N'));
8227       end if;
8228       --
8229       --            LOS
8230       --
8231       hr_utility.set_location ('LOS Prof '||l_package,10);
8232       if l_profile.rt_los_flag = 'Y' then
8233       hr_utility.set_location('check_los',10);
8234       check_los
8235         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id,
8236          p_person_id              => p_person_id,
8237          p_business_group_id      => p_business_group_id,
8238          p_effective_date         => p_effective_date,
8239          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
8240          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
8241          p_pgm_id                 => l_epe.pgm_id,
8242          p_oipl_id                => l_epe.oipl_id,
8243          p_opt_id                 => nvl(p_currepe_row.opt_id,l_oipl_rec.opt_id),  -- Bug 9033589
8244          p_plip_id                => nvl(p_currepe_row.plip_id,l_epe.plip_id),     -- Bug 9033589
8245          p_pl_id                  => l_epe.pl_id,
8246          p_currepe_row            => p_currepe_row);
8247       end if;
8248       --
8249       --    Assignment set
8250       if l_profile.rt_asnt_set_flag = 'Y' then
8251         hr_utility.set_location('Assn Set Flag',10);
8252         check_asnt_set
8253         (p_VRBL_RT_PRFL_ID   => l_profile.vrbl_rt_prfl_id,
8254          p_business_group_id => p_business_group_id,
8255          p_person_id         => p_person_id,
8256          p_lf_evt_ocrd_dt   =>  p_lf_evt_ocrd_dt,
8257          p_effective_date   =>  p_effective_date );
8258       end if;
8259       --          Hours worked
8260       --
8261       if l_profile.rt_hrs_wkd_flag = 'Y' then
8262       hr_utility.set_location('check_hrs_wkd',10);
8263       check_hrs_wkd
8264         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id,
8265          p_person_id              => p_person_id,
8266          p_business_group_id      => p_business_group_id,
8267          -- FONM : as lf_evt_ocrd_dt is not used, it's fine to overload the
8268          -- p_effective_date.
8269          p_effective_date         => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
8270                                       nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
8271                                        nvl(p_lf_evt_ocrd_dt, p_effective_date))),
8272          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
8273          p_pgm_id                 => l_epe.pgm_id,
8274          p_pl_id                  => l_epe.pl_id,
8275          p_opt_id                 => l_oipl_rec.opt_id,
8276          p_plip_id                => l_epe.plip_id);
8277       end if;
8278       --
8279       --          Postal Code
8280       --
8281       if l_profile.rt_pstl_cd_flag = 'Y' then
8282       hr_utility.set_location('check_zip_code_rng',10);
8283       check_zip_code_rng
8284         (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8285          p_person_id         => p_person_id,
8286          p_business_group_id => p_business_group_id,
8287          p_effective_date    => p_effective_date,
8288          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8289          p_postal_code       => l_adr_rec.postal_code);
8290       end if;
8291       --
8292       --            Service Area
8293       --
8294       if l_profile.rt_svc_area_flag = 'Y' then
8295       hr_utility.set_location('check_service_area',10);
8296       check_service_area
8297         (p_vrbl_rt_prfl_id   => l_profile.vrbl_rt_prfl_id,
8298          p_person_id         => p_person_id,
8299          p_business_group_id => p_business_group_id,
8300          p_effective_date    => p_effective_date,
8301          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8302          p_postal_code       => l_adr_rec.postal_code);
8303       end if;
8304       --
8305       --            Comp Level
8306       --
8307       hr_utility.set_location ('DF profs '||l_package,10);
8308       if l_profile.rt_comp_lvl_flag = 'Y' then
8309       hr_utility.set_location('check_comp_level',10);
8310       check_comp_level
8311         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id,
8312          p_person_id              => p_person_id,
8313          p_business_group_id      => p_business_group_id,
8314          p_effective_date         => p_effective_date,   --fonm taken care in the function
8315          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
8316          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
8317          p_pgm_id                 => l_epe.pgm_id,
8318          p_pl_id                  => l_epe.pl_id,
8319          p_oipl_id                => l_epe.oipl_id,
8320          p_per_in_ler_id          => l_epe.per_in_ler_id);
8321       end if;
8322       --
8323       --            Combine Age and LOS
8324       --
8325       if l_profile.rt_cmbn_age_los_flag = 'Y' then
8326       hr_utility.set_location('check_age_los',10);
8327       check_age_los
8328         (p_vrbl_rt_prfl_id        => l_profile.vrbl_rt_prfl_id,
8329          p_person_id              => p_person_id,
8330          p_business_group_id      => p_business_group_id,
8331          p_effective_date         => p_effective_date,
8332          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
8333          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
8334          p_pgm_id                 => l_epe.pgm_id,
8335          p_pl_id                  => l_epe.pl_id,
8336          p_opt_id                 => nvl(p_currepe_row.opt_id,l_oipl_rec.opt_id),  -- Bug 9033589
8337          p_plip_id                => nvl(p_currepe_row.plip_id,l_epe.plip_id),     -- Bug 9033589
8338          p_currepe_row            => p_currepe_row);
8339       end if;
8340       --
8341       --          Gender
8342       --
8343       if l_profile.rt_gndr_flag = 'Y' then
8344       hr_utility.set_location('check_gender',10);
8345       check_gender
8346         (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
8347          p_business_group_id    => p_business_group_id,
8348          p_effective_date       => p_effective_date,
8349          p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
8350          p_sex                  => l_per_rec.sex);
8351       end if;
8352       --
8353       --   Check period of enrollment.  This is
8354       --   currently only for COBRA.
8355       --
8356       hr_utility.set_location ('COBRA profs '||l_package,10);
8357       if l_profile.rt_poe_flag = 'Y' then
8358       hr_utility.set_location('check_period_of_enrollment',10);
8359       check_period_of_enrollment
8360         (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
8361          p_business_group_id    => p_business_group_id,
8362          p_effective_date       => p_effective_date,
8363          p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
8364          p_person_id            => p_person_id,
8365          p_pgm_id               => p_pgm_id,
8366          p_pl_typ_id            => p_pl_typ_id,
8367          p_ler_id               => p_ler_id );
8368       end if;
8369       --
8370       --   Disabled
8371       --
8372       if l_profile.rt_dsbld_flag = 'Y' then
8373       hr_utility.set_location('check_dsbld_cd' ||  l_per_rec.registered_disabled_flag,10);
8374       check_dsbld_cd
8375         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8376          p_business_group_id        => p_business_group_id,
8377          p_effective_date           => p_effective_date,
8378          p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt,
8379          p_dsbld_cd                 => l_per_rec.registered_disabled_flag);
8380       end if;
8381 
8382       --
8383       --   Opted for Medicare
8384       --
8385       if l_profile.rt_optd_mdcr_flag = 'Y' then
8386       hr_utility.set_location('check_optd_mdcr',10);
8387       check_optd_mdcr
8388         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8389          p_business_group_id        => p_business_group_id,
8390          p_effective_date           => p_effective_date,
8391          p_lf_evt_ocrd_dt    	    => p_lf_evt_ocrd_dt,
8392          p_person_id 	  	    => p_person_id );
8393       end if;
8394 
8395       --
8396       --   Leaving Reason
8397       --
8398       if l_profile.rt_lvg_rsn_flag = 'Y' then
8399       hr_utility.set_location('check_lvg_rsn',10);
8400       check_lvg_rsn
8401         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8402          p_business_group_id        => p_business_group_id,
8403          p_effective_date           => p_effective_date,
8404          p_lf_evt_ocrd_dt    	    => p_lf_evt_ocrd_dt,
8405          p_person_id 	  	    => p_person_id );
8406       end if;
8407 
8408       --
8409       --   Cobra Qualified Beneficiary
8410       --
8411       if l_profile.rt_cbr_quald_bnf_flag = 'Y' then
8412       hr_utility.set_location('check_cbr_quald_bnf',10);
8413       check_cbr_quald_bnf
8414         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8415          p_business_group_id        => p_business_group_id,
8416          p_effective_date           => p_effective_date,
8417          p_lf_evt_ocrd_dt    	    => p_lf_evt_ocrd_dt,
8418          p_person_id 	  	    => p_person_id );
8419       end if;
8420 
8421       --
8422       --   Competency
8423       --
8424       if l_profile.rt_comptncy_flag = 'Y' then
8425       hr_utility.set_location('check_comptncy',10);
8426       check_comptncy
8427         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8428          p_business_group_id        => p_business_group_id,
8429          p_person_id		    => p_person_id ,
8430          p_effective_date           => p_effective_date,
8431          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8432       end if;
8433 
8434       --
8435       --   Qualification title
8436       --
8437       if l_profile.rt_qual_titl_flag = 'Y' then
8438       hr_utility.set_location('check_qual_titl',10);
8439       check_qual_titl
8440         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8441          p_business_group_id        => p_business_group_id,
8442          p_person_id		    => p_person_id ,
8443          p_effective_date           => p_effective_date,
8444          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8445       end if;
8446 
8447       --
8448       --   Dependent Covered Other Plan
8449       --
8450       if l_profile.rt_dpnt_cvrd_pl_flag = 'Y' then
8451       hr_utility.set_location('check_dpnt_cvrd_othr_pl',10);
8452       check_dpnt_cvrd_othr_pl
8453         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8454          p_business_group_id        => p_business_group_id,
8455          p_effective_date           => p_effective_date,
8456          p_person_id 		    => p_person_id,
8457          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8458       end if;
8459 
8460 
8461       --
8462       --   Dependent Covered Other Plan in Program
8463       --
8464       if l_profile.rt_dpnt_cvrd_plip_flag = 'Y' then
8465       hr_utility.set_location('check_dpnt_cvrd_othr_plip',10);
8466       check_dpnt_cvrd_othr_plip
8467         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8468          p_business_group_id        => p_business_group_id,
8469          p_effective_date           => p_effective_date,
8470          p_person_id 		    => p_person_id,
8471          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8472       end if;
8473 
8474       --
8475       --   Dependent Covered Other Plan Type in Program
8476       --
8477       if l_profile.rt_dpnt_cvrd_ptip_flag = 'Y' then
8478       hr_utility.set_location('check_dpnt_cvrd_othr_ptip',10);
8479       check_dpnt_cvrd_othr_ptip
8480         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8481          p_business_group_id        => p_business_group_id,
8482          p_effective_date           => p_effective_date,
8483          p_person_id 		    => p_person_id,
8484          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8485       end if;
8486 
8487 
8488       --
8489       --   Dependent Covered Other Program
8490       --
8491       if l_profile.rt_dpnt_cvrd_pgm_flag = 'Y' then
8492       hr_utility.set_location('check_dpnt_cvrd_othr_pgm',10);
8493       check_dpnt_cvrd_othr_pgm
8494         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8495          p_business_group_id        => p_business_group_id,
8496          p_effective_date           => p_effective_date,
8497          p_person_id 		    => p_person_id,
8498          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8499       end if;
8500 
8501 
8502 
8503       --
8504       --   Eligible for Another Plan
8505       --
8506       if l_profile.rt_prtt_anthr_pl_flag = 'Y' then
8507       hr_utility.set_location('check_prtt_anthr_pl',10);
8508       check_prtt_anthr_pl
8509         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8510          p_business_group_id        => p_business_group_id,
8511          -- FONM : as lf_evt_ocrd_dt is not used, it's fine to overload the
8512          -- p_effective_date.
8513          p_effective_date         => nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
8514                                       nvl(ben_manage_life_events.g_fonm_cvg_strt_dt,
8515                                        nvl(p_lf_evt_ocrd_dt, p_effective_date))),
8516          p_person_id 		    => p_person_id,
8517          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8518       end if;
8519 
8520 
8521 
8522       --
8523       --   Eligible for Another Plan Type in Program
8524       --
8525       if l_profile.rt_othr_ptip_flag = 'Y' then
8526       hr_utility.set_location('check_othr_ptip',10);
8527       check_othr_ptip
8528         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8529          p_business_group_id        => p_business_group_id,
8530          -- FONM : do not overload as the lf_evt_ocrd_dt takes precedence over eff dt.
8531          p_effective_date           => p_effective_date,
8532          p_person_id 		    => p_person_id,
8533          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8534       end if;
8535 
8536 
8537       --
8538       --   Enrolled in Another Plan
8539       --
8540       if l_profile.rt_enrld_pl_flag = 'Y' then
8541       hr_utility.set_location('check_enrld_anthr_pl',10);
8542       check_enrld_anthr_pl
8543         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8544          p_business_group_id        => p_business_group_id,
8545          -- FONM : do not overload eff date as determine_date is called.
8546          p_effective_date           => p_effective_date,
8547          p_person_id 		    => p_person_id,
8548          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt,
8549          p_pl_id		    => p_pl_id);
8550       end if;
8551 
8552 
8553       --
8554       --   Enrolled in Another Option In Plan
8555       --
8556       if l_profile.rt_enrld_oipl_flag = 'Y' then
8557       hr_utility.set_location('check_enrld_anthr_oipl',10);
8558       check_enrld_anthr_oipl
8559         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8560          p_business_group_id        => p_business_group_id,
8561          -- FONM : do not overload eff date as determine_date is called.
8562          p_effective_date           => p_effective_date,
8563          p_person_id 		    => p_person_id,
8564          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt,
8565          p_oipl_id		    => p_oipl_id);
8566       end if;
8567 
8568 
8569       --
8570       --   Enrolled in Another Plan in Program
8571       --
8572       if l_profile.rt_enrld_plip_flag = 'Y' then
8573       hr_utility.set_location('check_enrld_anthr_plip',10);
8574       check_enrld_anthr_plip
8575         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8576          p_business_group_id        => p_business_group_id,
8577          -- FONM : do not overload eff date as determine_date is called.
8578          p_effective_date           => p_effective_date,
8579          p_person_id 		    => p_person_id,
8580          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt);
8581       end if;
8582 
8583 
8584       --
8585       --   Enrolled in Another Plan Type in Program
8586       --
8587       if l_profile.rt_enrld_ptip_flag = 'Y' then
8588       hr_utility.set_location('check_enrld_anthr_ptip',10);
8589       check_enrld_anthr_ptip
8590         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8591          p_business_group_id        => p_business_group_id,
8592          -- FONM : do not overload eff date as determine_date is called.
8593          p_effective_date           => p_effective_date,
8594          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt);
8595       end if;
8596 
8597       --
8598       --   Enrolled in Another Program
8599       --
8600       if l_profile.rt_enrld_pgm_flag = 'Y' then
8601       hr_utility.set_location('check_enrld_anthr_pgm',10);
8602       check_enrld_anthr_pgm
8603         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8604          p_business_group_id        => p_business_group_id,
8605          p_pgm_id		    => p_pgm_id ,
8606          p_person_id 		    => p_person_id,
8607          -- FONM : do not overload eff date as determine_date is called.
8608          p_effective_date           => p_effective_date,
8609          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt );
8610       end if;
8611 
8612       --
8613       -- Dependent Other Plan Type in Program
8614       --
8615       if l_profile.rt_dpnt_othr_ptip_flag = 'Y' then
8616       hr_utility.set_location('check_dpnt_othr_ptip',10);
8617       check_dpnt_othr_ptip
8618         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8619          p_business_group_id        => p_business_group_id,
8620          -- FONM : as lf_evt_ocrd_dt is used, do not overload the
8621          -- p_effective_date.
8622          p_effective_date           => p_effective_date,
8623          p_person_id 		    => p_person_id,
8624          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt,
8625          p_per_in_ler_id	    => p_per_in_ler_id);
8626       end if;
8627 
8628       --
8629       -- No Other Coverage
8630       --
8631       if l_profile.rt_no_othr_cvg_flag = 'Y' then
8632       hr_utility.set_location('check_no_othr_cvg',10);
8633       check_no_othr_cvg
8634         (p_vrbl_rt_prfl_id          => l_profile.vrbl_rt_prfl_id,
8635          p_business_group_id        => p_business_group_id,
8636          p_person_id 		    => p_person_id,
8637          p_effective_date           => p_effective_date,
8638          p_lf_evt_ocrd_dt 	    => p_lf_evt_ocrd_dt);
8639       end if;
8640 
8641       --
8642       if not(p_all_prfls) then
8643         --
8644         -- when g_all_prfls is set, we want to determine all the profiles
8645         -- a person matches without considering the total-type criteria.
8646         -- then we'll call this procedure again, with those totals.
8647         -- When g_all_prfls is set, the totals passed in are the total
8648         -- number of people participating in the comp object that match
8649         -- the other criteria in the vrbl prfl.
8650         -- When it's not set, the totals are the total number
8651         -- of people participating in the comp object.
8652         --
8653         --          Total Number of Participants
8654         --
8655         hr_utility.set_location ('Total profs '||l_package,10);
8656         if l_profile.rt_ttl_prtt_flag = 'Y' then
8657         hr_utility.set_location('check_ttl_prtt',10);
8658         check_ttl_prtt
8659           (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
8660            p_business_group_id    => p_business_group_id,
8661            p_effective_date       => p_effective_date,
8662            p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
8663            p_ttl_prtt             => l_ttl_prtt);
8664         end if;
8665         --
8666         --          Total Amount of Coverage
8667         --
8668         if l_profile.rt_ttl_cvg_vol_flag = 'Y' then
8669         hr_utility.set_location('check_ttl_cvg',10);
8670         check_ttl_cvg
8671           (p_vrbl_rt_prfl_id      => l_profile.vrbl_rt_prfl_id,
8672            p_business_group_id    => p_business_group_id,
8673            p_effective_date       => p_effective_date,
8674            p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
8675            p_ttl_cvg              => l_ttl_cvg);
8676         end if;
8677         --
8678       end if;
8679       --
8680       --           If we get this far then everything passed.
8681       --           Assign Variable Rate Id and get out -
8682       --           unless we want to find
8683       --           all the profiles a person matches.
8684       --
8685       l_vrbl_rt_prfl_id := l_profile.vrbl_rt_prfl_id;
8686       l_matched_vrbl_prfl  := 'Y';
8687       --
8688       hr_utility.set_location ('Load globals '||l_package,10);
8689       if p_all_prfls then
8690         --
8691         hr_utility.set_location ('p_all_prfls on ',20);
8692         --
8693         -- first time thru procedure where we are keeping track of all
8694         -- the profiles a person matches, without running the ttl-cvg
8695         -- and ttl-prtt's profiles.
8696         -- Using a table, keep track of the variable profiles matched and
8697         -- how many people matched the profiles.
8698         --
8699         load_globals (p_vrbl_rt_prfl_id => l_vrbl_rt_prfl_id
8700                      ,p_all_prfls       => true
8701                      ,p_use_prfls       => false
8702                      ,p_bnft_amt        => p_bnft_amt
8703                      ,p_ordr_num        => l_profile.ordr_num
8704                      ,p_asmt_to_use_cd     => l_profile.asmt_to_use_cd
8705                      ,p_rt_hrly_slrd_flag  => l_profile.rt_hrly_slrd_flag
8706                      ,p_rt_pstl_cd_flag    => l_profile.rt_pstl_cd_flag
8707                      ,p_rt_lbr_mmbr_flag   => l_profile.rt_lbr_mmbr_flag
8708                      ,p_rt_lgl_enty_flag   => l_profile.rt_lgl_enty_flag
8709                      ,p_rt_benfts_grp_flag => l_profile.rt_benfts_grp_flag
8710                      ,p_rt_wk_loc_flag     => l_profile.rt_wk_loc_flag
8711                      ,p_rt_brgng_unit_flag => l_profile.rt_brgng_unit_flag
8712                      ,p_rt_age_flag        => l_profile.rt_age_flag
8713                      ,p_rt_los_flag        => l_profile.rt_los_flag
8714                      ,p_rt_per_typ_flag    => l_profile.rt_per_typ_flag
8715                      ,p_rt_fl_tm_pt_tm_flag=> l_profile.rt_fl_tm_pt_tm_flag
8716                      ,p_rt_ee_stat_flag    => l_profile.rt_ee_stat_flag
8717                      ,p_rt_grd_flag        => l_profile.rt_grd_flag
8718                      ,p_rt_pct_fl_tm_flag  => l_profile.rt_pct_fl_tm_flag
8719                      ,p_rt_asnt_set_flag   => l_profile.rt_asnt_set_flag
8720                      ,p_rt_hrs_wkd_flag    => l_profile.rt_hrs_wkd_flag
8721                      ,p_rt_comp_lvl_flag   => l_profile.rt_comp_lvl_flag
8722                      ,p_rt_org_unit_flag   => l_profile.rt_org_unit_flag
8723                      ,p_rt_loa_rsn_flag    => l_profile.rt_loa_rsn_flag
8724                      ,p_rt_pyrl_flag       => l_profile.rt_pyrl_flag
8725                      ,p_rt_schedd_hrs_flag => l_profile.rt_schedd_hrs_flag
8726                      ,p_rt_py_bss_flag     => l_profile.rt_py_bss_flag
8727                      ,p_rt_prfl_rl_flag    => l_profile.rt_prfl_rl_flag
8728                      ,p_rt_cmbn_age_los_flag => l_profile.rt_cmbn_age_los_flag
8729                      ,p_rt_prtt_pl_flag    => l_profile.rt_prtt_pl_flag
8730                      ,p_rt_svc_area_flag   => l_profile.rt_svc_area_flag
8731                      ,p_rt_ppl_grp_flag    => l_profile.rt_ppl_grp_flag
8732                      ,p_rt_dsbld_flag      => l_profile.rt_dsbld_flag
8733                      ,p_rt_hlth_cvg_flag   => l_profile.rt_hlth_cvg_flag
8734                      ,p_rt_poe_flag        => l_profile.rt_poe_flag
8735                      ,p_rt_ttl_cvg_vol_flag=> l_profile.rt_ttl_cvg_vol_flag
8736                      ,p_rt_ttl_prtt_flag   => l_profile.rt_ttl_prtt_flag
8737                      ,p_rt_gndr_flag       => l_profile.rt_gndr_flag
8738                      ,p_rt_tbco_use_flag   => l_profile.rt_tbco_use_flag
8739                      ,p_rt_cntng_prtn_prfl_flag => l_profile.rt_cntng_prtn_prfl_flag
8740                      ,p_rt_cbr_quald_bnf_flag   => l_profile.rt_cbr_quald_bnf_flag
8741                      ,p_rt_optd_mdcr_flag	=> l_profile.rt_optd_mdcr_flag
8742                      ,p_rt_lvg_rsn_flag 	=> l_profile.rt_lvg_rsn_flag
8743                      ,p_rt_pstn_flag 	       	=> l_profile.rt_pstn_flag
8744                      ,p_rt_comptncy_flag 	=> l_profile.rt_comptncy_flag
8745                      ,p_rt_job_flag 		=> l_profile.rt_job_flag
8746                      ,p_rt_qual_titl_flag 	=> l_profile.rt_qual_titl_flag
8747                      ,p_rt_dpnt_cvrd_pl_flag	=> l_profile.rt_dpnt_cvrd_pl_flag
8748                      ,p_rt_dpnt_cvrd_plip_flag  => l_profile.rt_dpnt_cvrd_plip_flag
8749                      ,p_rt_dpnt_cvrd_ptip_flag  => l_profile.rt_dpnt_cvrd_ptip_flag
8750                      ,p_rt_dpnt_cvrd_pgm_flag   => l_profile.rt_dpnt_cvrd_pgm_flag
8751                      ,p_rt_enrld_oipl_flag	=> l_profile.rt_enrld_oipl_flag
8752                      ,p_rt_enrld_pl_flag	=> l_profile.rt_enrld_pl_flag
8753                      ,p_rt_enrld_plip_flag	=> l_profile.rt_enrld_plip_flag
8754                      ,p_rt_enrld_ptip_flag	=> l_profile.rt_enrld_ptip_flag
8755                      ,p_rt_enrld_pgm_flag	=> l_profile.rt_enrld_pgm_flag
8756                      ,p_rt_prtt_anthr_pl_flag   => l_profile.rt_prtt_anthr_pl_flag
8757                      ,p_rt_othr_ptip_flag	=> l_profile.rt_othr_ptip_flag
8758                      ,p_rt_no_othr_cvg_flag	=> l_profile.rt_no_othr_cvg_flag
8759                      ,p_rt_dpnt_othr_ptip_flag  => l_profile.rt_dpnt_othr_ptip_flag
8760                      ,p_rt_qua_in_gr_flag	=> l_profile.rt_qua_in_gr_flag
8761                      ,p_rt_perf_rtng_flag  	=> l_profile.rt_perf_rtng_flag
8762                      ,p_rt_elig_prfl_flag  	=> l_profile.rt_elig_prfl_flag
8763                      );
8764         --
8765       else
8766         -- Bug 1211317: changed to use new parm.
8767         if p_use_prfls then
8768           --
8769           hr_utility.set_location ('p_use_globals on ',21);
8770           --
8771           -- our second time thru this procedure where we are
8772           -- determining which profile a person matches with
8773           -- ttl_cvg and ttl_prtt taken into account.  Keep track
8774           -- of number of people that match the profiles.
8775           --
8776           load_globals (p_vrbl_rt_prfl_id => l_vrbl_rt_prfl_id
8777                        ,p_all_prfls       => false
8778                        ,p_use_prfls       => true
8779                        ,p_bnft_amt        => p_bnft_amt
8780                        ,p_ordr_num        => null
8781                      ,p_asmt_to_use_cd     => l_profile.asmt_to_use_cd
8782                      ,p_rt_hrly_slrd_flag  => l_profile.rt_hrly_slrd_flag
8783                      ,p_rt_pstl_cd_flag    => l_profile.rt_pstl_cd_flag
8784                      ,p_rt_lbr_mmbr_flag   => l_profile.rt_lbr_mmbr_flag
8785                      ,p_rt_lgl_enty_flag   => l_profile.rt_lgl_enty_flag
8786                      ,p_rt_benfts_grp_flag => l_profile.rt_benfts_grp_flag
8787                      ,p_rt_wk_loc_flag     => l_profile.rt_wk_loc_flag
8788                      ,p_rt_brgng_unit_flag => l_profile.rt_brgng_unit_flag
8789                      ,p_rt_age_flag        => l_profile.rt_age_flag
8790                      ,p_rt_los_flag        => l_profile.rt_los_flag
8791                      ,p_rt_per_typ_flag    => l_profile.rt_per_typ_flag
8792                      ,p_rt_fl_tm_pt_tm_flag=> l_profile.rt_fl_tm_pt_tm_flag
8793                      ,p_rt_ee_stat_flag    => l_profile.rt_ee_stat_flag
8794                      ,p_rt_grd_flag        => l_profile.rt_grd_flag
8795                      ,p_rt_pct_fl_tm_flag  => l_profile.rt_pct_fl_tm_flag
8796                      ,p_rt_asnt_set_flag   => l_profile.rt_asnt_set_flag
8797                      ,p_rt_hrs_wkd_flag    => l_profile.rt_hrs_wkd_flag
8798                      ,p_rt_comp_lvl_flag   => l_profile.rt_comp_lvl_flag
8799                      ,p_rt_org_unit_flag   => l_profile.rt_org_unit_flag
8800                      ,p_rt_loa_rsn_flag    => l_profile.rt_loa_rsn_flag
8801                      ,p_rt_pyrl_flag       => l_profile.rt_pyrl_flag
8802                      ,p_rt_schedd_hrs_flag => l_profile.rt_schedd_hrs_flag
8803                      ,p_rt_py_bss_flag     => l_profile.rt_py_bss_flag
8804                      ,p_rt_prfl_rl_flag    => l_profile.rt_prfl_rl_flag
8805                      ,p_rt_cmbn_age_los_flag => l_profile.rt_cmbn_age_los_flag
8806                      ,p_rt_prtt_pl_flag    => l_profile.rt_prtt_pl_flag
8807                      ,p_rt_svc_area_flag   => l_profile.rt_svc_area_flag
8808                      ,p_rt_ppl_grp_flag    => l_profile.rt_ppl_grp_flag
8809                      ,p_rt_dsbld_flag      => l_profile.rt_dsbld_flag
8810                      ,p_rt_hlth_cvg_flag   => l_profile.rt_hlth_cvg_flag
8811                      ,p_rt_poe_flag        => l_profile.rt_poe_flag
8812                      ,p_rt_ttl_cvg_vol_flag=> l_profile.rt_ttl_cvg_vol_flag
8813                      ,p_rt_ttl_prtt_flag   => l_profile.rt_ttl_prtt_flag
8814                      ,p_rt_gndr_flag       => l_profile.rt_gndr_flag
8815                      ,p_rt_tbco_use_flag   => l_profile.rt_tbco_use_flag
8816                      ,p_rt_cntng_prtn_prfl_flag => l_profile.rt_cntng_prtn_prfl_flag
8817                      ,p_rt_cbr_quald_bnf_flag   => l_profile.rt_cbr_quald_bnf_flag
8818                      ,p_rt_optd_mdcr_flag	=> l_profile.rt_optd_mdcr_flag
8819                      ,p_rt_lvg_rsn_flag 	=> l_profile.rt_lvg_rsn_flag
8820                      ,p_rt_pstn_flag 	       	=> l_profile.rt_pstn_flag
8821                      ,p_rt_comptncy_flag 	=> l_profile.rt_comptncy_flag
8822                      ,p_rt_job_flag 		=> l_profile.rt_job_flag
8823                      ,p_rt_qual_titl_flag 	=> l_profile.rt_qual_titl_flag
8824                      ,p_rt_dpnt_cvrd_pl_flag	=> l_profile.rt_dpnt_cvrd_pl_flag
8825                      ,p_rt_dpnt_cvrd_plip_flag  => l_profile.rt_dpnt_cvrd_plip_flag
8826                      ,p_rt_dpnt_cvrd_ptip_flag  => l_profile.rt_dpnt_cvrd_ptip_flag
8827                      ,p_rt_dpnt_cvrd_pgm_flag   => l_profile.rt_dpnt_cvrd_pgm_flag
8828                      ,p_rt_enrld_oipl_flag	=> l_profile.rt_enrld_oipl_flag
8829                      ,p_rt_enrld_pl_flag	=> l_profile.rt_enrld_pl_flag
8830                      ,p_rt_enrld_plip_flag	=> l_profile.rt_enrld_plip_flag
8831                      ,p_rt_enrld_ptip_flag	=> l_profile.rt_enrld_ptip_flag
8832                      ,p_rt_enrld_pgm_flag	=> l_profile.rt_enrld_pgm_flag
8833                      ,p_rt_prtt_anthr_pl_flag   => l_profile.rt_prtt_anthr_pl_flag
8834                      ,p_rt_othr_ptip_flag	=> l_profile.rt_othr_ptip_flag
8835                      ,p_rt_no_othr_cvg_flag	=> l_profile.rt_no_othr_cvg_flag
8836                      ,p_rt_dpnt_othr_ptip_flag  => l_profile.rt_dpnt_othr_ptip_flag
8837                      ,p_rt_qua_in_gr_flag	=> l_profile.rt_qua_in_gr_flag
8838                      ,p_rt_perf_rtng_flag 	=> l_profile.rt_perf_rtng_flag
8839                      ,p_rt_elig_prfl_flag       => l_profile.rt_elig_prfl_flag
8840                     );
8841 
8842           --
8843         end if;
8844         --
8845         exit;
8846         --
8847       end if;
8848       --
8849     exception
8850       --
8851       when ben_evaluate_rate_profiles.g_profile_failed then
8852         --
8853         --            If profile failed one of the criteria,
8854         --            go onto next profile.
8855         --
8856         hr_utility.set_location ('g_profile_failed '||l_package,10);
8857         NULL;
8858         --
8859       -- begin bug # 2436338
8860       when g_criteria_failed then
8861 	--
8862 	--            If profile failed one of the criteria,
8863 	--            go onto next profile.
8864 	--
8865 	hr_utility.set_location ('g_profile_failed '||l_package,10);
8866 	NULL;
8867         --
8868        -- end bug # 2436338
8869     end;
8870     --
8871   end loop;
8872   hr_utility.set_location ('Dn Prof loop '||l_package,10);
8873   --
8874   if l_matched_vrbl_prfl = 'N' then
8875     --
8876     if p_all_prfls or p_use_globals then
8877       --
8878       -- the person didn't match any variable profiles,
8879       -- add to no-match count.  This doesn't count people twice,
8880       -- because the second time thru we only loop thru those people
8881       -- who did match profiles the first time thru.
8882       --
8883       g_no_match_cnt := g_no_match_cnt + 1;
8884       g_no_match_cvg := g_no_match_cvg + p_bnft_amt;
8885       --
8886       hr_utility.set_location ('did not match profile :'||
8887                 to_char(p_person_id)||' cnt:'||
8888                 to_char(g_no_match_cnt),88);
8889       --
8890     end if;
8891     --
8892   end if;
8893   --
8894   p_vrbl_rt_prfl_id := l_vrbl_rt_prfl_id;
8895   --
8896   hr_utility.set_location ('Leaving '||l_package,99);
8897   --
8898 end main;
8899 --
8900 end ben_evaluate_rate_profiles;