DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_DETERMINE_DATE

Source


4 -- Get the plan year during the life event or effective date.
1 PACKAGE BODY ben_determine_date as
2 /* $Header: bendetdt.pkb 120.36.12020000.3 2012/10/31 08:19:19 amnaraya ship $ */
3 -- --------------------------------------------------------------------
5 -- --------------------------------------------------------------------
6 g_debug boolean := hr_utility.debug_enabled;
7 --
8 --
9 -- ----------------------------------------------------------------------------
10 -- |----------------------< get_profile_ff_warn_val >-------------------------|
11 -- ----------------------------------------------------------------------------
12 --
13 -- Description:
14 -- Bug 5088591: The function returns the value of profile BEN_DISP_FF_WARN_MSG.
15 -- If profile is not set then the function returns N
16 --
17 -- ----------------------------------------------------------------------------
18 FUNCTION get_profile_ff_warn_val
19    RETURN VARCHAR2
20 IS
21 --
22 BEGIN
23    --
24    IF g_ben_disp_ff_warn_msg IS NULL
25    THEN
26       --
27       g_ben_disp_ff_warn_msg := nvl(fnd_profile.VALUE ('BEN_DISP_FF_WARN_MSG'), 'Y');
28       --
29    END IF;
30    --
31    RETURN g_ben_disp_ff_warn_msg;
32    --
33 --
34 END get_profile_ff_warn_val;
35 --
36 --
37 procedure  get_plan_year
38            (p_effective_date in date
39            ,p_lf_evt_ocrd_dt in date
40            ,p_pl_id          in number
41            ,p_pgm_id         in number
42            ,p_oipl_id        in number
43            ,p_date_cd        in varchar2
44            ,p_comp_obj_mode  in boolean default true
45            ,p_start_date     out nocopy date
46            ,p_end_date       out nocopy date) is
47 
48   l_proc   varchar2(80)  := g_package ||'ben_determine_date.get_plan_year';
49 
50   l_effective_date date;
51 
52   cursor c_pgm_popl_yr is
53   select yrp.start_date,
54          yrp.end_date
55     from ben_yr_perd yrp,
56          ben_popl_yr_perd cpy
57    where cpy.pgm_id = p_pgm_id
58      and cpy.yr_perd_id = yrp.yr_perd_id
59      and l_effective_date
60          between yrp.start_date
61              and yrp.end_date;
62   --
63   cursor c_pl_popl_yr is
64   select yrp.start_date,
65          yrp.end_date
69      and cpy.yr_perd_id = yrp.yr_perd_id
66     from ben_yr_perd yrp,
67          ben_popl_yr_perd cpy
68    where cpy.pl_id = p_pl_id
70      and l_effective_date
71          between yrp.start_date
72              and yrp.end_date;
73    --
74   cursor c_oipl_popl_yr is
75   select yrp.start_date,
76          yrp.end_date
77     from ben_yr_perd yrp,
78          ben_popl_yr_perd cpy,
79          ben_oipl_f cop
80    where cpy.pl_id = cop.pl_id
81      and cop.oipl_id = p_oipl_id
82      and cpy.yr_perd_id = yrp.yr_perd_id
83      and l_effective_date
84          between yrp.start_date
85              and yrp.end_date
86      and l_effective_date
87          between cop.effective_start_date
88              and cop.effective_end_date;
89 
90 begin
91 
92   l_effective_date := nvl(p_lf_evt_ocrd_dt,p_effective_date);
93   if p_comp_obj_mode then
94     if p_pl_id is not null then
95        open c_pl_popl_yr;
96        fetch c_pl_popl_yr into p_start_date, p_end_date;
97        close c_pl_popl_yr;
98 
99     elsif p_pgm_id is not null then
100       open c_pgm_popl_yr;
101       fetch c_pgm_popl_yr into p_start_date, p_end_date;
102       close c_pgm_popl_yr;
103 
104     elsif p_oipl_id is not null then
105       open c_oipl_popl_yr;
106       fetch c_oipl_popl_yr into p_start_date, p_end_date;
107       close c_oipl_popl_yr;
108 
109     else
110       if g_debug then
111          hr_utility.set_location('BEN_92489_CANNOT_CALC_DATE',55);
112       end if;
113 
114       fnd_message.set_name('BEN','BEN_92489_CANNOT_CALC_DATE');
115       fnd_message.set_token('DATE_CODE',p_date_cd);
116       fnd_message.set_token('L_PROC',l_proc);
117       fnd_message.raise_error;
118     end if;
119   else
120     p_start_date := to_date('01/01/'||to_char(l_effective_date,'YYYY'),'dd/mm/rrrr');
121     p_end_date := to_date('31/12/'||to_char(l_effective_date,'YYYY'),'dd/mm/rrrr');
122 
123   end if;
124 exception   -- nocopy changes
125   --
126   when others then
127     --
128     p_start_date    := null;
129     p_end_date      := null;
130     raise;
131     --
132 end get_plan_year;
133 
134 -- --------------------------------------------------------------------
135 -- Validating Coverage Rate Dates Computed Using Rule
136 -- --------------------------------------------------------------------
137 
138 procedure validate_rule_cd_date
139                       ( p_formula_id            in number,
140 		        p_computed_Date         in date ,
141                         p_lf_evt_ocrd_dt        in date,
142                         p_per_in_ler_id         in number,
143                         p_effective_date        in date,
144                         p_pgm_id                in number,
145                         p_pl_id                 in number,
146                         p_opt_id                in number,
147                         p_person_id             in number
148                       )
149               is
150 
151   cursor c_formula_type_id_name
152   is
153   select fft.formula_type_id,fft.formula_type_name
154   from   ff_formula_types fft,ff_formulas_f ff
155   where  ff.formula_id=p_formula_id
156   and    ff.formula_type_id= fft.formula_type_id
157   and    p_effective_date between ff.effective_start_date and ff.effective_end_date;
158 
159 
160   cursor c_pgm_name
161   is
162   select name
163   from   ben_pgm_f pgm
164   where  pgm_id=p_pgm_id
165   and    p_effective_Date between effective_start_date and effective_end_date;
166 
167   cursor c_pl_name
168   is
169   select name
170   from   ben_pl_f pln
171   where  pl_id=p_pl_id
172   and    p_effective_Date between effective_start_date and effective_end_date;
173 
174   cursor c_opt_name
175   is
176   select name
177   from   ben_opt_f opt
178   where  opt_id=p_opt_id
179   and    p_effective_Date between effective_start_date and effective_end_date;
180 
181   cursor c_mode
182   is
183   select 1
184   from   ben_per_in_ler pil,
185          ben_ler_f ler
186   where  pil.ler_id = ler.ler_id
187   and    pil.per_in_ler_id=p_per_in_ler_id
188   and    ler.typ_cd not like 'SCHED%'
189   and    p_lf_evt_ocrd_dt between effective_start_date and effective_end_date;
190 
191   cursor c_national_identifier
192   is
193   select national_identifier
194   from   per_all_people_f
195   where  person_id=p_person_id;
196 
197 
198   l_message_name1   varchar2(500) := 'BEN_94441_ENROL_ST_DT_RANGE';
199   l_message_name2   varchar2(500) := 'BEN_94464_ENROL_ED_DT_RANGE';
200   l_message_name3   varchar2(500) := 'BEN_93964_ENRO_DT_LT_LE_OCD_DT';
201 
202 
203   l_formula_type_id ff_formulas_f.formula_type_id%type;
204   l_formula_type_name ff_formula_types.formula_type_name%type;
205   l_pgm_name ben_pgm_f.name%type;
206   l_pl_name ben_pl_f.name%type;
207   l_opt_name ben_opt_f.name%type;
208   l_dummy number;
209   l_national_identifier per_all_people_f.national_identifier%type;
210 
211 begin
212    hr_utility.set_location('Entering validate_rule_cd_date',1000);
213 
214    open  c_formula_type_id_name;
215    fetch c_formula_type_id_name into l_formula_type_id,l_formula_type_name;
216    close c_formula_type_id_name;
217 
218 
219    if l_formula_type_id in (-27,-28,-29,-30,-504,-503,-66,-67) then
220 
221     open c_pgm_name;
222     fetch c_pgm_name into l_pgm_name;
223     close c_pgm_name;
224 
225     open c_pl_name;
226     fetch c_pl_name into l_pl_name;
227     close c_pl_name;
228 
229     open c_opt_name;
233     open  c_national_identifier;
230     fetch c_opt_name into l_opt_name;
231     close c_opt_name;
232 
234     fetch c_national_identifier into l_national_identifier;
235     close c_national_identifier;
236 
237   end if;
238 
239    if l_formula_type_id in (-27,-28,-29,-30,-504,-503,-66,-67) then
240           if  p_computed_Date <= hr_api.g_sot then
241 	  fnd_message.set_name('BEN','BEN_94441_ENROL_ST_DT_RANGE');
242 	  fnd_message.set_token('PARMA',l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
243           fnd_message.set_token('PARMB',fnd_date.date_to_displaydate(hr_api.g_sot,calendar_aware=>2));
244 	  fnd_message.set_token('PARMC','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name );
245           benutils.write(p_text=>fnd_message.get);
246           ben_warnings.load_warning
247 		       (p_application_short_name  => 'BEN'
248 		       ,p_message_name            => l_message_name1
249 		       ,p_parma                   => l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
250 		       ,p_parmb    	          => fnd_date.date_to_displaydate(hr_api.g_sot,calendar_aware=>2)
251 		       ,p_parmc                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
252 		       ,p_person_id               => p_person_id
253 		       );
254       elsif p_computed_Date >= hr_api.g_eot then
255           fnd_message.set_name('BEN','BEN_94464_ENROL_ED_DT_RANGE');
256   	  fnd_message.set_token('PARMA',l_formula_type_name|| ' ' || fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
257           fnd_message.set_token('PARMB',fnd_date.date_to_displaydate(hr_api.g_eot,calendar_aware=>2));
258 	  fnd_message.set_token('PARMC','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name );
259           benutils.write(p_text=>fnd_message.get);
260 	  ben_warnings.load_warning
261 		       (p_application_short_name  => 'BEN'
262 		       ,p_message_name            => l_message_name2
263 		       ,p_parma                   => l_formula_type_name|| ' ' || fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
264 		       ,p_parmb    	          => fnd_date.date_to_displaydate(hr_api.g_eot,calendar_aware=>2)
265 		       ,p_parmc                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
266 		       ,p_person_id               => p_person_id
267 		       );
268 
269     elsif l_formula_type_id in (-29,-66,-67) then
270       if p_computed_Date < p_lf_evt_ocrd_dt  then
271          fnd_message.set_name('BEN','BEN_93964_ENRO_DT_LT_LE_OCD_DT');
272          fnd_message.set_token('PARMA',l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
273          fnd_message.set_token('PARMB','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name);
274 	 fnd_message.set_token('PARMC',fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2));
275 	 benutils.write(p_text=>fnd_message.get);
276 	 ben_warnings.load_warning
277 		       (p_application_short_name  => 'BEN'
278 		       ,p_message_name            => l_message_name3
279 		       ,p_parma                   => l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
280 		       ,p_parmb                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
281 		       ,p_parmc                   => fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2)
282 		       ,p_person_id               => p_person_id
283 		       );
284        end if;
285 
286 --Bug 5070692
287 
288    elsif l_formula_type_id in (-27,-28) then
289       if p_computed_Date < p_lf_evt_ocrd_dt  then
290          fnd_message.set_name('BEN','BEN_93964_ENRO_DT_LT_LE_OCD_DT');
291          fnd_message.set_token('PARMA',l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
292          fnd_message.set_token('PARMB','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name);
293 	 fnd_message.set_token('PARMC',fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2));
294 
295 	 g_dep_rec.text := fnd_message.get;
296 	 g_dep_rec.rep_typ_cd := 'WARNING';
297 	 g_dep_rec.error_message_code :='BEN_93964_ENRO_DT_LT_LE_OCD_DT';
298 	 g_dep_rec.national_identifier :=l_national_identifier;
299 	 g_dep_rec.person_id :=p_person_id;
300 	 g_dep_rec.pgm_id :=p_pgm_id;
301 	 g_dep_rec.pl_id :=p_pl_id;
302 
303 --Bug 5070692
304 	 benutils.write(p_rec=>g_dep_rec);
305 	 ben_warnings.load_warning
306 		       (p_application_short_name  => 'BEN'
307 		       ,p_message_name            => l_message_name3
308 		       ,p_parma                   => l_formula_type_name || ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
309 		       ,p_parmb                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
310 		       ,p_parmc                   => fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2)
311 		       ,p_person_id               => p_person_id
312 		       );
313        end if;
314 
315 --Bug 5070692
316 
317 --Bug 5076010
318     elsif l_formula_type_id = -30 then
319       if p_computed_Date < p_lf_evt_ocrd_dt  then
320          fnd_message.set_name('BEN','BEN_93964_ENRO_DT_LT_LE_OCD_DT');
321          fnd_message.set_token('PARMA',substr(l_formula_type_name,1,10) ||' '||'Coverage End Date'|| ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
322          fnd_message.set_token('PARMB','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name );
323 	 fnd_message.set_token('PARMC',fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2));
324 
328 		       ,p_message_name            => l_message_name3
325          benutils.write(p_text=>fnd_message.get);
326 	 ben_warnings.load_warning
327 		       (p_application_short_name  => 'BEN'
329 		       ,p_parma                   => substr(l_formula_type_name,1,10) ||' '||'Coverage End Date'|| ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
330 		       ,p_parmb                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
331 		       ,p_parmc                   => fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2)
332 		       ,p_person_id               => p_person_id
333 		       );
334        end if;
335 --Bug 5076010
336 
337     else
338       open c_mode;
339       fetch c_mode into l_dummy;
340       if c_mode%found then
341         if p_computed_Date < p_lf_evt_ocrd_dt  then
342          fnd_message.set_name('BEN','BEN_93964_ENRO_DT_LT_LE_OCD_DT');
343          fnd_message.set_token('PARMA',l_formula_type_name|| ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2));
344          fnd_message.set_token('PARMB','Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name );
345 	 fnd_message.set_token('PARMC',fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2));
346 
347            benutils.write(p_text=>fnd_message.get);
348            ben_warnings.load_warning
349                (p_application_short_name  => 'BEN'
350 	           ,p_message_name            => l_message_name3
351 	           ,p_parma                   => l_formula_type_name|| ' ' ||fnd_date.date_to_displaydate(p_computed_Date,calendar_aware=>2)
352 	           ,p_parmb                   => 'Program:'||' '|| l_pgm_name ||' '||'-'||' '||'Plan:'||' '|| l_pl_name ||' '||'-'||' '||'Option:'||' '|| l_opt_name
353 	           ,p_parmc                   => fnd_date.date_to_displaydate(p_lf_evt_ocrd_dt,calendar_aware=>2)
354 	           ,p_person_id               => p_person_id);
355         end if;
356       end if;
357       --
358       close c_mode; -- Bug fix 5057685. Moved here
359       --
360     end if;
361 end if;
362 hr_utility.set_location('Leaving validate_rule_cd_date',8888);
363 end validate_rule_cd_date;
364 
365 -- --------------------------------------------------------------------
366 -- Get the plan year that starts after the life event or effective date.
367 -- --------------------------------------------------------------------
368 procedure  get_next_plan_year
369            (p_effective_date in date
370            ,p_lf_evt_ocrd_dt in date
371            ,p_pl_id          in number
372            ,p_pgm_id         in number
373            ,p_oipl_id        in number
374            ,p_date_cd        in varchar2
375            ,p_comp_obj_mode  in boolean default true
376            ,p_start_date     out nocopy date
377            ,p_end_date       out nocopy date) is
378 
379   l_proc   varchar2(80)  := g_package ||'ben_determine_date.get_next_plan_year';
380   l_effective_date date;
381 
382   cursor c_pgm_next_popl_yr is
383   select yrp.start_date, yrp.end_date
384     from ben_yr_perd yrp,
385          ben_popl_yr_perd cpy
386    where cpy.pgm_id = p_pgm_id
387      and cpy.yr_perd_id = yrp.yr_perd_id
388      and l_effective_date < yrp.start_date
389    order by 1;
390   --
391   cursor c_pl_next_popl_yr is
392   select yrp.start_date, yrp.end_date
393     from ben_yr_perd yrp,
394          ben_popl_yr_perd cpy
395    where cpy.pl_id = p_pl_id
396      and cpy.yr_perd_id = yrp.yr_perd_id
397      and l_effective_date < yrp.start_date
398    order by 1;
399   --
400   cursor c_oipl_next_popl_yr is
401   select yrp.start_date, yrp.end_date
402     from ben_yr_perd yrp,
403          ben_popl_yr_perd cpy,
404          ben_oipl_f cop
405    where cpy.pl_id = cop.pl_id
406      and cop.oipl_id = p_oipl_id
407      and cpy.yr_perd_id = yrp.yr_perd_id
408      and l_effective_date < yrp.start_date
409      and l_effective_date between cop.effective_start_date
410      and cop.effective_end_date
411    order by 1;
412 
413 begin
414 
415   l_effective_date := nvl(p_lf_evt_ocrd_dt,p_effective_date);
416   if p_comp_obj_mode then
417     if p_pl_id is not null then
418       open c_pl_next_popl_yr;
419       fetch c_pl_next_popl_yr into p_start_date,p_end_date;
420       close c_pl_next_popl_yr;
421     elsif p_pgm_id is not null then
422       open c_pgm_next_popl_yr;
423       fetch c_pgm_next_popl_yr into  p_start_date,p_end_date;
424       close c_pgm_next_popl_yr;
425     elsif p_oipl_id is not null then
426       open c_oipl_next_popl_yr;
427       fetch c_oipl_next_popl_yr into  p_start_date,p_end_date;
428       close c_oipl_next_popl_yr;
429     else
430     if g_debug then
431         hr_utility.set_location('BEN_92489_CANNOT_CALC_DATE',55);
432     end if;
433       fnd_message.set_name('BEN','BEN_92489_CANNOT_CALC_DATE');
434       fnd_message.set_token('DATE_CODE',p_date_cd);
435       fnd_message.set_token('L_PROC',l_proc);
436       fnd_message.raise_error;
437     end if;
438   else
439     p_start_date := to_date('01/01/'||to_char(l_effective_date,'YYYY'),'dd/mm/rrrr');
440     p_end_date := to_date('31/12/'||to_char(l_effective_date,'YYYY'),'dd/mm/rrrr');
441 
442   end if;
443 exception   -- nocopy changes
444   --
445   when others then
446     --
447     p_start_date    := null;
448     p_end_date      := null;
449     raise;
450     --
451 end get_next_plan_year;
452 
453 -- --------------------------------------------------------------------
454 -- function get_event_date used to make consistent event date handling
455 -- for all codes which need it.
456 -- --------------------------------------------------------------------
460   ,p_pil_row        in     ben_per_in_ler%rowtype
457 function get_event_date
458   (p_cache_mode     in     boolean default false
459 /*
461 */
462   ,p_per_in_ler_id  in     number
463   ,p_effective_date in     date
464   ) return date
465 is
466   --
467   l_event_date         date;
468   --
469   cursor c_per_in_ler
470   is
471   select pil.lf_evt_ocrd_dt
472     from ben_per_in_ler pil
473    where pil.per_in_ler_id = p_per_in_ler_id;
474   --
475 begin
476   if p_per_in_ler_id is null then
477     l_event_date:=p_effective_date;
478   else
479     open c_per_in_ler;
480     fetch c_per_in_ler into l_event_date;
481     if c_per_in_ler%notfound then
482       close c_per_in_ler;
483     if g_debug then
484         hr_utility.set_location('BEN_91530_CANNOT_FIND_AED_DATE',40);
485     end if;
486       fnd_message.set_name('BEN','BEN_91530_CANNOT_FIND_AED_DATE');
487       fnd_message.raise_error;
488     end if;
489     close c_per_in_ler;
490   end if;
491   --
492   -- Single exit point for readability
493   --
494   return l_event_date;
495   --
496 end get_event_date;
497 --
498 --
499 -- function get_recorded_date used to make consistent date handling
500 -- for all new life event codes.
501 --
502 function get_recorded_date
503   (p_cache_mode     in     boolean default false
504 /*
505   ,p_pil_row        in     ben_per_in_ler%rowtype
506 */
507   ,p_per_in_ler_id  in     number
508   ,p_effective_date in     date
509   ) return date
510 is
511   --
512   l_pil_row        ben_pil_cache.g_pil_inst_row;
513   --
514   l_recorded_date  date;
515   --
516 /*
517   cursor c_per_in_ler
518   is
519   select pil.ntfn_dt
520     from ben_per_in_ler pil
521    where pil.per_in_ler_id = p_per_in_ler_id;
522   --
523 */
524 begin
525   --
526   if p_per_in_ler_id is null then
527     --
528     l_recorded_date := p_effective_date;
529     --
530 /*
531   elsif p_cache_mode
532     and p_pil_row.per_in_ler_id is not null
533   then
534     --
535     l_recorded_date := p_pil_row.ntfn_dt;
536     --
537 */
538   else
539     --
540     ben_pil_cache.PIL_GetPILDets
541       (p_per_in_ler_id => p_per_in_ler_id
542       ,p_inst_row      => l_pil_row
543       );
544     --
545     l_recorded_date := l_pil_row.ntfn_dt;
546     --
547     if l_pil_row.per_in_ler_id is null then
548       --
549       fnd_message.set_name('BEN','BEN_92391_CANT_FIND_RCRD_DATE');
550       fnd_message.raise_error;
551       --
552     end if;
553     --
554 /*
555   else
556     --
557     open c_per_in_ler;
558     fetch c_per_in_ler into l_recorded_date;
559     if c_per_in_ler%notfound then
560       close c_per_in_ler;
561       if g_debug then
562         hr_utility.set_location('BEN_92391_CANT_FIND_RCRD_DATE',40);
563       end if;
564       fnd_message.set_name('BEN','BEN_92391_CANT_FIND_RCRD_DATE');
565       fnd_message.raise_error;
566     end if;
567     close c_per_in_ler;
568     --
569 */
570   end if;
571   --
572   if l_recorded_date is null then
573     --
574     return p_effective_date;
575     --
576   else
577     --
578     return l_recorded_date;
579     --
580   end if;
581   --
582 end get_recorded_date;
583 --
584 procedure main
585   (p_cache_mode             in     boolean  default false
586   --
587   ,p_date_cd                in     varchar2
588   ,p_per_in_ler_id          in     number   default null
589   ,p_person_id              in     number   default null
590   ,p_pgm_id                 in     number   default null
591   ,p_pl_id                  in     number   default null
592   ,p_oipl_id                in     number   default null
593   ,p_elig_per_elctbl_chc_id in     number   default null -- optional for all
594   ,p_business_group_id      in     number   default null
595   ,p_formula_id             in     number   default null
596   ,p_acty_base_rt_id        in     number   default null -- as a context to formula calls
597   ,p_bnfts_bal_id           in     number   default null
598   ,p_effective_date         in     date
599   ,p_lf_evt_ocrd_dt         in     date     default null
600   ,p_start_date             in     date     default null
601   ,p_returned_date          out nocopy    date
602   ,p_parent_person_id       in     number   default null
603  -- Added two more parameters to fix the Bug 1531647
604   ,p_param1                 in     varchar2 default null
605   ,p_param1_value           in     varchar2 default null
606   ,p_enrt_cvg_end_dt        in     date     default null
607   ,p_comp_obj_mode          in     boolean  default true
608   ,p_fonm_cvg_strt_dt       in     date default null
609   ,p_fonm_rt_strt_dt        in     date default null
610   ,p_cmpltd_dt              in     date default null
611   )
612 is
613 --
614   l_proc               varchar2(80)  := g_package ||'.determine_date.main';
615   l_per_in_ler_id      number;
616   l_person_id          number;
617   l_pgm_id             number;
618   l_pl_id              number;
619   l_pl_typ_id          number;
620   l_ler_id             number;
621   l_oipl_id            number;
622   l_business_group_id  number;
623   l_date               date;
624   l_start_date         date;
625   l_end_date           date;
626   l_procg_end_dt       date;
627   l_next_popl_yr_strt  date;
628   l_next_popl_yr_end   date;
629   l_months             number;
633   l_lf_evt_ocrd_dt     date;
630   l_outputs            ff_exec.outputs_t;
631   l_event_date         date;
632   l_recorded_date      date;
634   l_hire_date          date;
635   l_jurisdiction_code  varchar2(30);
636   l_enrt_eff_strt_date date;
637   l_date_temp date;
638   --
639   l_pil_row            ben_per_in_ler%rowtype;
640   --
641  cursor c_asg is
642   select asg.assignment_id,asg.organization_id
643     from per_all_assignments_f asg
644    where asg.person_id = l_person_id
645      and asg.assignment_type <> 'C'
646      and asg.primary_flag = 'Y'
647      and nvl(p_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date)) between asg.effective_start_date
648                                                                          and asg.effective_end_date
649      order by asg.assignment_type desc , asg.effective_start_date desc ;
650   --
651   l_asg c_asg%rowtype;
652   --
653 
654   cursor c_per_elig_elctbl_chc is
655   select pil.per_in_ler_id,
656          pil.person_id,
657          epe.pgm_id,
658          epe.pl_id,
659          epe.pl_typ_id,
660          epe.oipl_id,
661          pil.ler_id,
662          epe.business_group_id,
663          epe.enrt_cvg_strt_dt
664     from ben_per_in_ler pil,
665          ben_elig_per_elctbl_chc epe
666    where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
667      and epe.per_in_ler_id = pil.per_in_ler_id;
668   --
669   cursor c_opt(l_oipl_id  number) is
670     select opt_id
671     from ben_oipl_f oipl
672     where oipl_id = l_oipl_id
673         and business_group_id   = p_business_group_id
674         and nvl(l_lf_evt_ocrd_dt,p_effective_date)
675          between oipl.effective_start_date
676              and oipl.effective_end_date;
677   --
678   l_opt c_opt%rowtype;
679   --
680   cursor c_pl_typ(l_pl_id  number) is
681     select pl.pl_typ_id
682     from ben_pl_f pl
683     where pl.pl_id = l_pl_id
684         and pl.business_group_id   = p_business_group_id
685         and nvl(l_lf_evt_ocrd_dt,p_effective_date)
686          between pl.effective_start_date
687              and pl.effective_end_date;
688   --
689   cursor c_ler is
690     select pil.ler_id
691     from   ben_per_in_ler pil
692     where  pil.per_in_ler_id = p_per_in_ler_id
693       and  pil.business_group_id   = p_business_group_id;
694   --
695   cursor c_pay_period(p_assignment_id number default null) is  -----------Bug 8394662
696   select tpe.start_date,
697          tpe.end_date
698     from per_time_periods tpe,
699          per_all_assignments_f asg
700    where tpe.payroll_id = asg.payroll_id
701      and   asg.assignment_type <> 'C'
702      and asg.business_group_id = l_business_group_id
703      and asg.person_id = l_person_id
704      and asg.primary_flag = 'Y'
705      and asg.assignment_id = nvl(p_assignment_id,asg.assignment_id) -----------Bug 8394662
706      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
707           between asg.effective_start_date
708               and asg.effective_end_date
709      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
710          between tpe.start_date
711              and tpe.end_date
712      --and rownum = 1
713   order by decode(asg.assignment_type,'E',1,2) asc;
714   --
715   Cursor c_state is
716   select region_2
717   from hr_locations_all loc,per_all_assignments_f asg
718   where loc.location_id = asg.location_id
719   and asg.person_id = p_person_id
720        and   asg.assignment_type <> 'C'
721        and p_effective_date between
722              asg.effective_start_date and asg.effective_end_date
723        and asg.business_group_id =p_business_group_id;
724 
725   l_state      c_state%rowtype;
726 
727   l_pay_period c_pay_period%rowtype;
728   --
729   cursor c_pay_period_for_date(p_date_dt date) is
730   select tpe.start_date,
731          tpe.end_date
732     from per_time_periods tpe,
733          per_all_assignments_f asg
734    where tpe.payroll_id = asg.payroll_id
735      and   asg.assignment_type <> 'C'
736      and asg.business_group_id = l_business_group_id
737      and asg.person_id = l_person_id
738      and asg.primary_flag = 'Y'
739      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
740            between asg.effective_start_date
741                and asg.effective_end_date
742      and p_date_dt between tpe.start_date and tpe.end_date
743   order by decode(asg.assignment_type,'E',1,2) asc;
744   --
745   --   and rownum = 1;
746   --
747   l_pay_period_for_date c_pay_period_for_date%rowtype;
748   --
749   --pay period on check date
750   cursor c_pay_period_for_check (p_date_dt date, p_assignment_type varchar2) is
751   select min(tpe.start_date )
752     from per_time_periods tpe,
753          per_all_assignments_f asg
754    where tpe.payroll_id = asg.payroll_id
755      and   asg.assignment_type = p_assignment_type
756      and asg.business_group_id = l_business_group_id
757      and asg.person_id = l_person_id
758      and asg.primary_flag = 'Y'
759      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
760            between asg.effective_start_date
761                and asg.effective_end_date
762      and p_date_dt <= nvl(tpe.regular_payment_date,tpe.end_date);
763   --
764   l_start_date_check   date;
765   --
766   cursor c_pay_period_for_check_end
767           (p_date_dt date, p_assignment_type varchar2) is
768   select max(tpe.end_date )
769     from per_time_periods tpe,
770          per_all_assignments_f asg
771    where tpe.payroll_id = asg.payroll_id
772      and   asg.assignment_type = p_assignment_type
773      and asg.business_group_id = l_business_group_id
774      and asg.person_id = l_person_id
775      and asg.primary_flag = 'Y'
779      and p_date_dt > nvl(tpe.regular_payment_date,tpe.end_date);
776      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
777            between asg.effective_start_date
778                and asg.effective_end_date
780   --
781   l_end_date_check     date;
782   --
783   cursor c_next_pay_period(p_date_dt date,p_assignment_id number default null) is  -----------Bug 8394662
784   select tpe.start_date,
785          tpe.end_date
786     from per_time_periods tpe,
787          per_all_assignments_f asg
788    where tpe.payroll_id = asg.payroll_id
789      and   asg.assignment_type <> 'C'
790      and asg.business_group_id = l_business_group_id
791      and asg.person_id = l_person_id
792      and asg.primary_flag = 'Y'
793      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
794          between asg.effective_start_date
795              and asg.effective_end_date
796      and asg.assignment_id = nvl(p_assignment_id,asg.assignment_id)  -----------Bug 8394662
797      and tpe.start_date > p_date_dt
798   order by decode(asg.assignment_type,'E',1,2) asc,
799         tpe.start_date;
800   --   and rownum = 1
801   --
802   l_next_pay_period c_next_pay_period%rowtype;
803   --
804   --6025969 fix
805   cursor c_pre_pay_period(p_date_dt date) is
806   select tpe.start_date,
807          tpe.end_date
808     from per_time_periods tpe,
809          per_all_assignments_f asg
810    where tpe.payroll_id = asg.payroll_id
811      and   asg.assignment_type <> 'C'
812      and asg.business_group_id = l_business_group_id
813      and asg.person_id = l_person_id
814      and asg.primary_flag = 'Y'
815      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
816          between asg.effective_start_date
817              and asg.effective_end_date
818      and tpe.end_date < p_date_dt
819   order by decode(asg.assignment_type,'E',1,2) asc,
820         tpe.end_date desc;
821 
822   l_pre_pay_period c_pre_pay_period%rowtype;
823   --
824 
825   cursor c_pps is
826   select date_start
827   from per_periods_of_service  pps
828   where pps.person_id = p_person_id
829     and pps.date_start = (select max(pps1.date_start) -- this gets most recent
830                             from per_periods_of_service pps1
831                            where pps1.person_id = p_person_id
832                              and pps1.date_start = nvl(l_lf_evt_ocrd_dt,p_effective_date )
833                           );
834   --
835   cursor c_hire_date is
836     select max(date_start)
837     from per_periods_of_service  pps
838     where pps.person_id = p_person_id
839     and   pps.date_start <= nvl(l_lf_evt_ocrd_dt,p_effective_date);
840 
841   --
842   cursor c_pgm_popl_lim_yr is
843   select yrp.lmtn_yr_strt_dt,
844          yrp.lmtn_yr_end_dt
845     from ben_yr_perd yrp,
846          ben_popl_yr_perd cpy
847    where cpy.pgm_id = l_pgm_id
848      and cpy.yr_perd_id = yrp.yr_perd_id
849      and yrp.business_group_id   = l_business_group_id
850      and cpy.business_group_id   = l_business_group_id
851      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
852          between yrp.start_date
853              and yrp.end_date;
854   --
855   cursor c_pl_popl_lim_yr is
856   select yrp.lmtn_yr_strt_dt,
857          yrp.lmtn_yr_end_dt
858     from ben_yr_perd yrp,
859          ben_popl_yr_perd cpy
860    where cpy.pl_id = l_pl_id
861      and cpy.yr_perd_id = yrp.yr_perd_id
862      and yrp.business_group_id   = l_business_group_id
863      and cpy.business_group_id   = l_business_group_id
864      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
865          between yrp.start_date
866              and yrp.end_date;
867   --
868   cursor c_oipl_popl_lim_yr is
869   select yrp.lmtn_yr_strt_dt,
870          yrp.lmtn_yr_end_dt
871     from ben_yr_perd yrp,
872          ben_popl_yr_perd cpy,
873          ben_oipl_f cop
874    where cpy.pl_id = cop.pl_id
875      and cop.oipl_id = l_oipl_id
876      and cpy.yr_perd_id = yrp.yr_perd_id
877      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
878          between yrp.start_date
879              and yrp.end_date
880      and cpy.business_group_id   = l_business_group_id
881      and cop.business_group_id   = l_business_group_id
882      and yrp.business_group_id   = l_business_group_id
883      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
884          between cop.effective_start_date
885              and cop.effective_end_date;
886   --
887   cursor c_pil_popl is
888   select pel.enrt_perd_end_dt,
889          pel.procg_end_dt
890     from ben_pil_elctbl_chc_popl pel,
891          ben_elig_per_elctbl_chc epe
892    where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
893      and epe.business_group_id   = l_business_group_id
894      and epe.pil_elctbl_chc_popl_id = pel.pil_elctbl_chc_popl_id
895      and pel.business_group_id   = l_business_group_id;
896   --
897   l_enrt_end_dt date;
898   --
899   --  Removed MIN() grouping for this cursor.  Based on the
900   --  where clause this should only return 1 row.
901   --
902   cursor c_cm_enrt_perd_strt_dt is
903   select enrt_perd_strt_dt
904   from ben_pil_elctbl_chc_popl
905   where per_in_ler_id = l_per_in_ler_id
906   and ((l_pgm_id is not null and pgm_id = l_pgm_id)
907        or (l_pgm_id is null and pl_id = l_pl_id)
908        or (l_pgm_id is null and l_pl_id is null))
909   and business_group_id   = l_business_group_id;
910   --
911   cursor c_cm_enrt_perd_end_dt is
912   select min(enrt_perd_end_dt)
913   from ben_pil_elctbl_chc_popl
914   where per_in_ler_id = l_per_in_ler_id
915   and ((l_pgm_id is not null and pgm_id = l_pgm_id)
916        or (l_pgm_id is null and pl_id = l_pl_id)
917        or (l_pgm_id is null and l_pl_id is null))
921   select min(dflt_asnd_dt)
918   and business_group_id   = l_business_group_id;
919   --
920   cursor c_cm_dflt_asnd_dt is
922   from ben_pil_elctbl_chc_popl
923   where per_in_ler_id = l_per_in_ler_id
924   and ((l_pgm_id is not null and pgm_id = l_pgm_id)
925        or (l_pgm_id is null and pl_id = l_pl_id)
926        or (l_pgm_id is null and l_pl_id is null))
927   and business_group_id   = l_business_group_id;
928   --
929   cursor c_cm_auto_asnd_dt is
930   select min(auto_asnd_dt)
931   from ben_pil_elctbl_chc_popl
932   where per_in_ler_id = l_per_in_ler_id
933   and ((l_pgm_id is not null and pgm_id = l_pgm_id)
934        or (l_pgm_id is null and pl_id = l_pl_id)
935        or (l_pgm_id is null and l_pl_id is null))
936   and business_group_id   = l_business_group_id;
937   --
938   cursor c_cm_elcns_made_dt is
939   select min(elcns_made_dt)
940   from ben_pil_elctbl_chc_popl
941   where per_in_ler_id = l_per_in_ler_id
942   and ((l_pgm_id is not null and pgm_id = l_pgm_id)
943        or (l_pgm_id is null and pl_id = l_pl_id)
944        or (l_pgm_id is null and l_pl_id is null))
945   and business_group_id   = l_business_group_id;
946   --
947   cursor c_cm_elig_prtn_strt_dt is
948   select min(prtn_strt_dt)
949   from ben_elig_per_f pep, ben_per_in_ler pil
950   where pep.person_id = p_person_id
951   and   pep.business_group_id   = p_business_group_id
952   and   p_effective_date = pep.effective_start_date
953   and   pil.per_in_ler_id(+) = pep.per_in_ler_id
954   and   pil.business_group_id = p_business_group_id
955   and   (   pil.per_in_ler_stat_cd not in ('VOIDD', 'BCKDT')
956          or
957             pil.per_in_ler_stat_cd is null);
958   --
959   cursor c_cm_elig_prtn_end_dt is
960   select min(prtn_end_dt)
961   from ben_elig_per_f pep, ben_per_in_ler pil
962   where pep.person_id = p_person_id
963 --  and   pep.business_group_id   = p_business_group_id
964   and   nvl(p_fonm_cvg_strt_dt,p_effective_date )  = pep.effective_start_date
965   and   pil.per_in_ler_id(+) = pep.per_in_ler_id
966   and   pil.business_group_id = p_business_group_id
967   and   (   pil.per_in_ler_stat_cd not in ('VOIDD', 'BCKDT')
968          or
969             pil.per_in_ler_stat_cd is null);
970   --
971   cursor c_elig_cvg_dpnt_dts is
972   select  ecd.cvg_thru_dt,
973           ecd.effective_end_date
974     from  ben_elig_cvrd_dpnt_f ecd
975     where ecd.per_in_ler_id = l_per_in_ler_id
976       and ecd.business_group_id  = l_business_group_id
977       and nvl(l_lf_evt_ocrd_dt,p_effective_date)
978           between ecd.effective_start_date
979               and ecd.effective_end_date;
980   --
981   cursor c_prtt_enrt_rslt_dts is
982   select  pen.enrt_cvg_thru_dt,
983           pen.enrt_cvg_strt_dt,
984           pen.effective_start_date
985     from  ben_prtt_enrt_rslt_f pen
986     where pen.per_in_ler_id = l_per_in_ler_id and
987           pen.pl_id=l_pl_id
988       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
989       and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
990       and pen.business_group_id  = l_business_group_id
991 -- Bug 1633284
992 /*
993       and nvl(l_lf_evt_ocrd_dt,p_effective_date)
994           between pen.effective_start_date
995               and pen.effective_end_date; */
996       and p_effective_date
997           between pen.effective_start_date
998              and pen.effective_end_date
999 --
1000 -- Bug 4309203 Modified the effective_end_date to enrt_cvg_thru_dt as
1001 --             effective_end_date would pick up invalid records.
1002       and pen.enrt_cvg_thru_dt = hr_api.g_eot ;
1003   --
1004 /*
1005   cursor c_prtt_rt_val_dts is
1006   select  prv.rt_strt_dt,
1007           prv.rt_end_dt
1008 
1009     from  ben_prtt_rt_val prv,
1010           ben_prtt_enrt_rslt_f pen
1011     where pen.per_in_ler_id = l_per_in_ler_id
1012       and pen.pl_id=l_pl_id
1013       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
1014       and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
1015       and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
1016       and prv.business_group_id  = l_business_group_id
1017       and nvl(l_lf_evt_ocrd_dt,p_effective_date)
1018           between pen.effective_start_date
1019               and pen.effective_end_date;
1020 */
1021 --
1022   cursor c_prtt_rt_val_dts is
1023   select null
1024     from
1025           ben_prtt_enrt_rslt_f pen
1026     where pen.per_in_ler_id = l_per_in_ler_id
1027       and pen.pl_id=l_pl_id
1028       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
1029 --      and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
1030 --      and pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
1031       and pen.business_group_id  = l_business_group_id
1032       and p_effective_date
1033           between pen.effective_start_date
1034               and pen.effective_end_date;
1035 --
1036 -- Added to fix code ODBEWM
1037 --
1038    cursor c_enrt_rt_val_dt is
1039    select er.rt_strt_dt
1040     from  ben_enrt_rt er,
1041           ben_enrt_bnft eb
1042    where  eb.elig_per_elctbl_chc_id =p_elig_per_elctbl_chc_id
1043    and    er.elig_per_elctbl_chc_id is null
1044    and    eb.enrt_bnft_id=er.enrt_bnft_id
1045    --
1046    union
1047    --
1048    select er.rt_strt_dt
1049     from  ben_enrt_rt er
1050     where er.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id ;
1051 
1052   cursor c_elig_dpnt_dts is
1053   select  ecd.cvg_strt_dt,
1054           ecd.cvg_thru_dt
1055     from  ben_elig_cvrd_dpnt_f ecd
1056     where ecd.per_in_ler_id = l_per_in_ler_id
1057       and ecd.business_group_id  = l_business_group_id
1058       and nvl(l_lf_evt_ocrd_dt,p_effective_date)
1059           between ecd.effective_start_date
1060               and ecd.effective_end_date;
1061 
1062   cursor c_birth_date is
1066   --
1063   select  paf.date_of_birth
1064     from  per_all_people_f paf
1065     where paf.person_id = p_person_id;
1067   cursor c_ler_id is
1068     select pil.ler_id
1069     from   ben_per_in_ler pil
1070     where  pil.per_in_ler_id = p_per_in_ler_id;
1071   --
1072  cursor c_pay_id is
1073   select asg.payroll_id
1074     from per_time_periods tpe,
1075          per_all_assignments_f asg
1076    where tpe.payroll_id = asg.payroll_id
1077      and   asg.assignment_type <> 'C'
1078      and asg.business_group_id = l_business_group_id
1079      and asg.person_id = l_person_id
1080      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
1081           between asg.effective_start_date
1082               and asg.effective_end_date
1083      and nvl(l_lf_evt_ocrd_dt,p_effective_date)
1084          between tpe.start_date
1085              and tpe.end_date
1086   order by decode(asg.assignment_type,'E',1,2) asc;
1087 
1088   /* Bug 12351605*/
1089   cursor c_prtt_enrt_rslt_dts_bckdt(c_per_in_ler_id number) is
1090   select  pen.enrt_cvg_thru_dt,
1091           pen.enrt_cvg_strt_dt,
1092           pen.effective_start_date
1093     from  ben_prtt_enrt_rslt_f pen
1094     where pen.per_in_ler_id = c_per_in_ler_id
1095       and pen.pl_id=l_pl_id
1096       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
1097       and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
1098       --and pen.pl_typ_id = l_pl_typ_id
1099       and pen.business_group_id  = l_business_group_id
1100       and pen.enrt_cvg_thru_dt = hr_api.g_eot
1101       and not exists
1102           (select '1' from ben_prtt_enrt_rslt_f pen1
1103            where pen.prtt_enrt_rslt_id = pen1.RPLCS_SSPNDD_RSLT_ID
1104            and pen1.per_in_ler_id = c_per_in_ler_id);
1105 
1106 
1107 cursor c_rt_dts_bckdt(c_per_in_ler_id number) is
1108   select  prv.rt_strt_dt,
1109           prv.rt_end_dt
1110     from  ben_prtt_enrt_rslt_f pen,
1111           ben_prtt_rt_val prv
1112     where pen.per_in_ler_id = c_per_in_ler_id
1113       and pen.pl_id=l_pl_id
1114       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
1115       and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
1116       --and pen.pl_typ_id = l_pl_typ_id
1117       and pen.business_group_id  = l_business_group_id
1118       and pen.enrt_cvg_thru_dt = hr_api.g_eot
1119       and prv.per_in_ler_id = c_per_in_ler_id
1120       and prv.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1121       and not exists
1122           (select '1' from ben_prtt_enrt_rslt_f pen1
1123            where pen.prtt_enrt_rslt_id = pen1.RPLCS_SSPNDD_RSLT_ID
1124            and pen1.per_in_ler_id = c_per_in_ler_id);
1125 
1126   l_rt_strt_dt1 date;
1127   l_rt_end_dt1 date;
1128 
1129 
1130   l_payroll_id  number ;
1131   --
1132   l_enrt_cvg_end_dt date;
1133   l_enrt_cvg_strt_dt date;
1134   l_cvg_thru_dt date;
1135   l_effective_end_date date;
1136   l_cm_date date;
1137   l_dummy   varchar2(30) ;
1138   l_fonm_rt_cvg_strt_dt  date ;
1139   l_rl_lf_evt_ocrd_dt    date ;
1140   l_cmpltd_dt            date ;
1141   l_ben_disp_ff_warn_msg varchar2(10);
1142   l_env   ben_env_object.g_global_env_rec_type;  -- 6823087 (CWB Requirement for 'ENTRBL')
1143   l_mode  l_env.mode_cd%TYPE;                    -- 6823087 (CWB Requirement for 'ENTRBL')
1144 --
1145   ----------Bug 8394662
1146   l_organization_id  number;
1147   l_payroll_id1      number;
1148   l_assignment_id    number;
1149   -----------Bug 8394662
1150 begin
1151 
1152 --    hr_utility.trace_on (null, 'ORACLE');
1153 
1154   g_debug := hr_utility.debug_enabled;
1155   --
1156   -- Commented out for performance
1157   --
1158   --
1159   --  hr_utility.set_location('Entering :'|| l_proc,10);
1160   --        comment these out until we need to debug a code
1161   --  hr_utility.set_location('p_date_cd               : '||p_date_cd                ,15);
1162   --  hr_utility.set_location('p_per_in_ler_id         : '||p_per_in_ler_id          ,15);
1163   --  hr_utility.set_location('p_person_id             : '||p_person_id              ,15);
1164   --  hr_utility.set_location('p_pgm_id                : '||p_pgm_id                 ,15);
1165   --  hr_utility.set_location('p_pl_id                 : '||p_pl_id                  ,15);
1166   --  hr_utility.set_location('p_oipl_id               : '||p_oipl_id                ,15);
1167   --  hr_utility.set_location('p_elig_per_elctbl_chc_id: '||p_elig_per_elctbl_chc_id ,15);
1168   --  hr_utility.set_location('p_effective_date        : '||p_effective_date         ,15);
1169   --  hr_utility.set_location('p_lf_evt_ocrd_dt        : '||p_lf_evt_ocrd_dt         ,15);
1170   --  hr_utility.set_location('p_start_date            : '||p_start_date             ,15);
1171   --  hr_utility.set_location('person         : '||p_person_id         ,665);
1172   --  hr_utility.set_location('parent         : '||p_parent_person_id         ,665);
1173   --
1174   --- Fonm2  Determine the fonm and effective date
1175   l_fonm_rt_cvg_strt_dt  :=  nvl(p_fonm_cvg_strt_dt,p_fonm_rt_strt_dt) ;
1176   l_lf_evt_ocrd_dt      :=  nvl(l_fonm_rt_cvg_strt_dt, p_lf_evt_ocrd_dt ) ;
1177   ---
1178 
1179 
1180 
1181   If p_elig_per_elctbl_chc_id  is not null then
1182     --
1183     -- If electible choice id has a value, then gather other important data
1184     -- needed by routines below.  If electable choice is null, then the calling
1185     -- procedures will have to provide these values:   per_in_ler_id,
1186     -- person_id, pl_id, oipl_id, pgm_id.
1187     --
1188    if g_debug then
1189      hr_utility.set_location('open c_per_elig_elctbl_chc',10);
1190    end if;
1191 
1192     open c_per_elig_elctbl_chc;
1193 
1194     fetch c_per_elig_elctbl_chc into
1195           l_per_in_ler_id,
1196           l_person_id,
1197           l_pgm_id,
1198           l_pl_id,
1199           l_pl_typ_id,
1200           l_oipl_id,
1201           l_ler_id,
1205     if g_debug then
1202           l_business_group_id,
1203           l_enrt_cvg_strt_dt;
1204 
1206       hr_utility.set_location('l_enrt_cvg_strt_dt from c_per_elig_elctbl_chc'||l_enrt_cvg_strt_dt,19);
1207     end if;
1208 
1209     if c_per_elig_elctbl_chc%notfound then
1210       close c_per_elig_elctbl_chc;
1211     if g_debug then
1212         hr_utility.set_location('BEN_91529_CANNOT_FIND_ELEC_CHC',40);
1213     end if;
1214       fnd_message.set_name('BEN','BEN_91529_CANNOT_FIND_ELEC_CHC');
1215       fnd_message.set_token('L_PROC',l_proc);
1216       fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',p_elig_per_elctbl_chc_id);
1217       fnd_message.raise_error;
1218     end if;
1219     close c_per_elig_elctbl_chc;
1220 
1221   else
1222 
1223     l_per_in_ler_id     := p_per_in_ler_id;
1224     l_person_id         := p_person_id;
1225     l_pgm_id            := p_pgm_id;
1226     l_pl_id             := p_pl_id;
1227     l_oipl_id           := p_oipl_id;
1228     l_business_group_id := p_business_group_id;
1229     --
1230 /*
1231     --
1232     -- Removed because called twice
1233     --
1234     open c_ler_id;
1235       --
1236       fetch c_ler_id into l_ler_id;
1237       --
1238     close c_ler_id;
1239 */
1240     --
1241   end if;
1242   ----------Bug 8394662
1243     if p_acty_base_rt_id is not null then
1244         l_organization_id := null;
1245 	l_payroll_id1 := null;
1246 	l_assignment_id := null;
1247         ben_element_entry.get_abr_assignment (p_person_id       => p_person_id
1248 					     ,p_effective_date  => nvl(l_lf_evt_ocrd_dt, p_effective_date) --12999039
1249 					     ,p_acty_base_rt_id => p_acty_base_rt_id
1250 					     ,p_organization_id => l_organization_id
1251 					     ,p_payroll_id      => l_payroll_id1
1252 					     ,p_assignment_id   => l_assignment_id);
1253 
1254     hr_utility.set_location('p_acty_base_rt_id : '||p_acty_base_rt_id,10);
1255     hr_utility.set_location('l_payroll_id1 : '||l_payroll_id1,10);
1256     hr_utility.set_location('l_assignment_id : '||l_assignment_id,10);
1257     end if;
1258     ------------Bug 8394662
1259   --
1260   -- when the date determinne from pay period for the  contact
1261   -- decide whether the contct has pay_period  bug 1510665
1262 
1263 
1264   if p_parent_person_id is not null   and p_date_cd in
1265       ('AFDCPP','AFDFPP','ALDCPP','ALDLPPEPPY',
1266        'FDLPPEPPY','FDLPPEPPYCF','FDPPCF','LAFDFPP','LALDCPP','LALDLPPEPPY',
1267        'LFDPPCF', 'LWALDCPP','FDPPCF','LALDPPP','WALDCPP','WALDLPPEPPY',
1268        'LWALDLPPEPPY','FDLPPPPYAES', 'EEELDPPADI','LDPPFEE','LDPPOAEE',
1269        'FDPPCFES','FDPPFES','LESFDPPAD','FDPPFED','FDPPOED','FDPPELD' )
1270   then
1271        open c_pay_id ;
1272        fetch c_pay_id into l_payroll_id ;
1273        if c_pay_id%notfound then
1274           l_person_id := p_parent_person_id ;
1275           if g_debug then
1276             hr_utility.set_location('for chold prill not found '        ,665);
1277           end if;
1278        end if ;
1279        close c_pay_id ;
1280   end if ;
1281 
1282   if g_debug then
1283     hr_utility.set_location('person   : '||l_person_id      ,665);
1284   end if;
1285 /*
1286 
1287   -- Check for cache mode. If so then get the per in ler details
1288   -- for the per in ler id
1289   --
1290   if p_cache_mode then
1291     --
1292     ben_pil_object.get_object
1293       (p_per_in_ler_id => l_per_in_ler_id
1294       ,p_rec           => l_pil_row
1295       );
1296     --
1297   end if;
1298   --
1299 */
1300 
1301   if g_debug then
1302     hr_utility.set_location('l_lf_evt_ocrd_dt :'||l_lf_evt_ocrd_dt,19);
1303   end if;
1304   if g_debug then
1305     hr_utility.set_location('p_date_cd :'||p_date_cd,19);
1306   end if;
1307 
1308   -- AED - Event Date
1309 
1310   if p_date_cd in  ( 'AED' , 'NUMDOE')  then
1311   --
1312   if g_debug then
1313       hr_utility.set_location('Entering AED',10);
1314   end if;
1315     --
1316     if l_lf_evt_ocrd_dt is null then
1317     --
1318        p_returned_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
1319     --
1320     else
1321     --
1322        p_returned_date:= l_lf_evt_ocrd_dt;
1323     --
1324     end if;
1325   --
1326   -- WAED 1 prior or Event
1327   --
1328   elsif p_date_cd = 'WAED' then
1329   --
1330   if g_debug then
1331       hr_utility.set_location('Entering AED',10);
1332   end if;
1333       --
1334       if l_lf_evt_ocrd_dt is null then
1335         --
1336         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
1337         --
1338       else
1339         --
1340         l_event_date:= l_lf_evt_ocrd_dt;
1341         --
1342       end if;
1343         --
1344         p_returned_date := l_event_date - 1;
1345         --
1346   -----------------------------------------------------------
1347   --
1348   -- OFDEP    - On Enrollment Period Start.
1349   -- 5DAFDEP  -  5 Days After Enrollment Period Start.
1350   -- 10DAFDEP - 10 Days After Enrollment Period Start.
1351   -- 10DBSEPD - 10 Days before Enrollment Period Start.
1352   -- 15DAFDEP - 15 Days After Enrollment Period Start.
1353   -- 20DAFDEP - 20 Days After Enrollment Period Start.
1354   -- 25DAFDEP - 25 Days After Enrollment Period Start.
1355   -- 30DAFDEP - 20 Days After Enrollment Period Start.
1356   -- TODFEPS  - 31 Days After Enrollment Period Start.
1357   -- FFDFEPS  - 45 Days After Enrollment Period Start.
1361   -----------------------------------------------------------
1358   -- SDFEPSD  - 60 Days After Enrollment Period Start.
1359   -- NDFEPS   - 90 Days After Enrollment Period Start.
1360   --
1362   elsif p_date_cd = 'FFDFEPS'  or p_date_cd = 'NDFEPS'   or
1363         p_date_cd = 'TODFEPS'  or p_date_cd = 'SDFEPSD'  or
1364         p_date_cd = 'OFDEP'    or p_date_cd = '5DAFDEP'  or
1365         p_date_cd = '10DAFDEP' or p_date_cd = '10DBSEPD' or
1366         p_date_cd = '15DAFDEP' or p_date_cd = '20DAFDEP' or
1367         p_date_cd = '25DAFDEP' or p_date_cd = '30DAFDEP' then
1368     --
1369   if g_debug then
1370       hr_utility.set_location('Entering '||p_date_cd,10);
1371   end if;
1372     --
1373     open c_cm_enrt_perd_strt_dt;
1374       fetch c_cm_enrt_perd_strt_dt into l_cm_date;
1375     --
1376     if c_cm_enrt_perd_strt_dt%notfound then
1377     --
1378       if p_start_date is not null then
1379       --
1380          l_cm_date := p_start_date;
1381       --
1382       else
1383       --
1384         close c_cm_enrt_perd_strt_dt;
1385       if g_debug then
1386          hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',40);
1387       end if;
1388         fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
1389         fnd_message.set_token('DATE_CODE',p_date_cd);
1390         fnd_message.set_token('L_PROC',l_proc);
1391         fnd_message.raise_error;
1392       --
1393       end if;
1394     --
1395     end if;
1396     --
1397     close c_cm_enrt_perd_strt_dt;
1398     --
1399     if p_date_cd  = 'OFDEP' then
1400     --
1401        p_returned_date := l_cm_date;
1402     --
1403     elsif p_date_cd  = '5DAFDEP' then
1404     --
1405       p_returned_date := l_cm_date + 5;
1406     --
1407     elsif p_date_cd  = '10DAFDEP' then
1408     --
1409       p_returned_date := l_cm_date + 10;
1410     --
1411     elsif p_date_cd  = '10DBSEPD' then
1412     --
1413       p_returned_date := l_cm_date - 10;
1414     --
1415     elsif p_date_cd  = '15DAFDEP' then
1416     --
1417       p_returned_date := l_cm_date + 15;
1418     --
1419     elsif p_date_cd  = '20DAFDEP' then
1420     --
1421       p_returned_date := l_cm_date + 20;
1422     --
1423     elsif p_date_cd  = '25DAFDEP' then
1424     --
1425       p_returned_date := l_cm_date + 25;
1426     --
1427     elsif p_date_cd  = '30DAFDEP' then
1428     --
1429       p_returned_date := l_cm_date + 30;
1430     --
1431     elsif p_date_cd  = 'TODFEPS' then
1432     --
1433        p_returned_date := l_cm_date + 31;
1434     --
1435     elsif p_date_cd  = 'FFDFEPS' then
1436     --
1437        p_returned_date := l_cm_date + 45;
1438     --
1439     elsif p_date_cd  = 'SDFEPSD' then
1440     --
1441       p_returned_date := l_cm_date + 60;
1442     --
1443     elsif p_date_cd  = 'NDFEPS' then
1444     --
1445        p_returned_date := l_cm_date + 90;
1446     --
1447     end if;
1448   --
1449   -- ------------------------------------------------------------------------
1450   -- Enrollment End
1451   -- ------------------------------------------------------------------------
1452   -- LDPPFEE - End of Pay Period After Enrollment End
1453   -- LDPPOAEE - End of Pay Period On or After Enrollment End
1454   -- FDLMPPYAES - First of Last Month in Year After enrollment
1455   -- FDLPPPPYAES - First of Last Pay Period in Event Year After Enrollment Start
1456   -- LDMFEE - Last day of Month after Enrollment End
1457   -- LDMOAEE - Last day of Month on or after Enrollment End
1458   -- EEELDPPADI - Earlier of Enrollment End or Last Day of Pay Period after
1459   --              Dedesignated or Ineligible
1460   -- EEELDMADI - Earlier of Enrollment End or Last Day of Month after
1461   --             Dedesignated or Ineligible
1462   -- EEDI - Earliest of Enrollment End, Dedesignated or Ineligible
1463   -- OCED - On the Coverage End Date.
1464   -- PECED - Participant's Enrollment Coverage End Date.
1465 
1466   elsif p_date_cd  = 'LDPPFEE' or p_date_cd = 'LDPPOAEE' or p_date_cd = 'FDLMPPYAES'
1467     or p_date_cd = 'FDLPPPPYAES' or p_date_cd = 'LDMFEE' or p_date_cd = 'LDMOAEE'
1468     or p_date_cd = 'EEELDPPADI' or p_date_cd = 'EEELDMADI' or p_date_cd = 'EEDI'
1469     or p_date_cd = 'OCED' or p_date_cd = 'PECED'  then
1470     --
1471     if g_debug then
1472       hr_utility.set_location('Entering '||p_date_cd,23);
1473     end if;
1474     --
1475     if l_lf_evt_ocrd_dt is null then
1476        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
1477     end if;
1478 
1479     if p_start_date is null then
1480        -- p_start_date is the enrollment coverage end date in this case.
1481        open c_prtt_enrt_rslt_dts;
1482        fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
1483                                     l_enrt_cvg_strt_dt,
1484                                     l_enrt_eff_strt_date;
1485        if g_debug then
1486          hr_utility.set_location('l_enrt_cvg_end_dt cursor returns ', 19);
1487        end if;
1488        close c_prtt_enrt_rslt_dts;
1489     else
1490        l_enrt_cvg_end_dt := p_start_date;
1491     end if;
1492 
1493 
1494     if p_date_cd = 'FDLPPPPYAES' or p_date_cd = 'EEELDPPADI' then
1495        if p_date_cd = 'FDLPPPPYAES' then
1496           -- First of Last Pay Period in Event Year
1497           get_plan_year
1498            (p_effective_date => p_effective_date
1499            ,p_lf_evt_ocrd_dt => l_enrt_cvg_strt_dt -- l_enrt_cvg_end_dt 5303167
1500            ,p_pl_id          => l_pl_id
1501            ,p_pgm_id         => l_pgm_id
1502            ,p_oipl_id        => l_oipl_id
1506            ,p_end_date       => l_end_date) ;
1503            ,p_date_cd        => p_date_cd
1504            ,p_comp_obj_mode  => p_comp_obj_mode
1505            ,p_start_date     => l_start_date
1507        elsif p_date_cd = 'EEELDPPADI' then
1508           -- Earlier of Enrollment End or Last Day of Pay Period after
1509           --              Dedesignated or Ineligible
1510           l_end_date := p_effective_date+1;
1511        end if;
1512 
1513        open c_pay_period_for_date(l_end_date);  -- l_end_date is just a parm
1514        fetch c_pay_period_for_date into
1515           l_start_date,
1516           l_end_date;  -- l_end_date is now the payroll end date.
1517 
1518        if c_pay_period_for_date%notfound and l_enrt_eff_strt_date is not null then
1519          close c_pay_period_for_date;
1520        if g_debug then
1521            hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',15);
1522        end if;
1523          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1524          fnd_message.set_token('DATE_CODE',p_date_cd);
1525          fnd_message.set_token('L_PROC',l_proc);
1526          fnd_message.set_token('PERSON_ID',l_person_id);
1527          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1528          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1529          fnd_message.raise_error;
1530        end if;
1531        close c_pay_period_for_date;
1532 
1533        if p_date_cd = 'FDLPPPPYAES' then
1534           p_returned_date := l_start_date;
1535        elsif p_date_cd = 'EEELDPPADI' then
1536           if l_enrt_cvg_end_dt < l_end_date then
1537              p_returned_date := l_enrt_cvg_end_dt;
1538           else
1539              p_returned_date := l_end_date;
1540           end if;
1541        end if;
1542 
1543     elsif p_date_cd  = 'LDPPFEE' or p_date_cd = 'LDPPOAEE'
1544        then
1545        -- End of Pay Period (On or) After
1546        if l_enrt_cvg_end_dt <>  hr_api.g_eot then
1547        --
1548        if g_debug then
1549          hr_utility.set_location(' Step 2 ' ,19);
1550        end if;
1551        open c_pay_period_for_date(l_enrt_cvg_end_dt);
1552        fetch c_pay_period_for_date into
1553           l_start_date,
1554           l_end_date;
1555 
1556        if c_pay_period_for_date%notfound and l_enrt_eff_strt_date is not null then
1557          close c_pay_period_for_date;
1558          if g_debug then
1559            hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',15);
1560          end if;
1561          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1562          fnd_message.set_token('DATE_CODE',p_date_cd);
1563          fnd_message.set_token('L_PROC',l_proc);
1564          fnd_message.set_token('PERSON_ID',l_person_id);
1565          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1566          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1567          fnd_message.raise_error;
1568        end if;
1569        close c_pay_period_for_date;
1570 
1571        else
1572           if g_debug then
1573             hr_utility.set_location('End of Time set 1 ' , 19 );
1574           end if;
1575           l_end_date := l_enrt_cvg_end_dt ;
1576        end if ;
1577 
1578        --
1579        if l_enrt_cvg_end_dt <>  hr_api.g_eot then
1580        --
1581        if l_end_date = l_enrt_cvg_end_dt then
1582           if p_date_cd = 'LDPPFEE' then
1583              -- End of Pay Period After
1584              -- retrieve last day of next pay period
1585              if g_debug then
1586                hr_utility.set_location(' Step 3 ' ,19);
1587              end if;
1588              open c_pay_period_for_date(l_end_date+1);
1589              fetch c_pay_period_for_date into
1590                 l_start_date,
1591                 l_end_date;
1592 
1593              if c_pay_period_for_date%notfound and
1594                l_enrt_eff_strt_date is not null then
1595                close c_pay_period_for_date;
1596                if g_debug then
1597                  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',25);
1598                end if;
1599                fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1600                fnd_message.set_token('DATE_CODE',p_date_cd);
1601                fnd_message.set_token('L_PROC',l_proc);
1602                fnd_message.set_token('PERSON_ID',l_person_id);
1603                fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1604                fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1605                fnd_message.raise_error;
1606              end if;
1607              close c_pay_period_for_date;
1608           end if;
1609        end if ;
1610        --
1611        else
1612           if g_debug then
1613             hr_utility.set_location('End of Time set 2' , 19 );
1614           end if;
1615           l_end_date := l_enrt_cvg_end_dt ;
1616        end if;
1617 
1618        p_returned_date := l_end_date;
1619 
1620     elsif p_date_cd = 'FDLMPPYAES' then
1621        -- First of Last Month in Year
1622        get_plan_year
1623            (p_effective_date =>  p_effective_date
1624            ,p_lf_evt_ocrd_dt => l_enrt_cvg_strt_dt -- 5303167 l_enrt_cvg_end_dt
1625            ,p_pl_id          => l_pl_id
1626            ,p_pgm_id         => l_pgm_id
1627            ,p_oipl_id        => l_oipl_id
1628            ,p_date_cd        => p_date_cd
1629            ,p_comp_obj_mode  => p_comp_obj_mode
1630            ,p_start_date     => l_start_date
1631            ,p_end_date       => l_end_date) ;
1632 
1633        p_returned_date := last_day(add_months(l_end_date,-1))+1;
1634        -- ? What if enrollment date is during last month of year
1635     elsif p_date_cd = 'LDMFEE'  then
1636        -- Last day of Month after
1637        p_returned_date := last_day(l_enrt_cvg_end_dt+1);
1641     elsif p_date_cd = 'EEELDMADI' then
1638     elsif p_date_cd = 'LDMOAEE' then
1639        -- Last day of Month on or after
1640        p_returned_date := last_day(l_enrt_cvg_end_dt);
1642        --  Earlier of Enrollment End or Last Day of Month after
1643        --  Dedesignated or Ineligible
1644        if l_enrt_cvg_end_dt < last_day(p_effective_date +1) then
1645           p_returned_date := l_enrt_cvg_end_dt;
1646        else
1647           p_returned_date := last_day(p_effective_date +1);
1648        end if;
1649     elsif p_date_cd = 'EEDI' then
1650        -- Earliest of Enrollment End, Dedesignated or Ineligible
1651        if l_enrt_cvg_end_dt < p_effective_date then
1652           p_returned_date := l_enrt_cvg_end_dt;
1653        else
1654           p_returned_date := p_effective_date ;
1655        end if;
1656     elsif p_date_cd = 'OCED' then
1657        -- Enrollment End
1658        p_returned_date := l_enrt_cvg_end_dt;
1659     elsif p_date_cd = 'PECED' then
1660        if p_enrt_cvg_end_dt is not null then
1661           p_returned_date := p_enrt_cvg_end_dt;
1662        else
1663           p_returned_date := l_enrt_cvg_end_dt;
1664        end if;
1665     end if;
1666 
1667   -- ------------------------------------------------------------------------
1668   -- Enrollment Start or Later
1669   -- ------------------------------------------------------------------------
1670   --
1671   -- LEMES - Later of Elections Made or Enrollment Start
1672   -- LFYEMES - First of Year After Later Elections or Enrollment Start
1673   -- LFMEMES - First of Month After Later Elections or Enrollment Start
1674   -- FDMCFES - First of Month on or After Enrollment Start
1675   -- FDMFES - First of Month After Enrollment Start
1676   -- LFPPEMES - First of Pay Period After Later Elections or Enrollment Start
1677   -- FDPPCFES - First of Pay Period On or After Enrollment
1678   -- FDPPFES - First of Pay Period after Enrollment Start
1679   -- LESWD - Later of Enrollment Start or When Dedesignated
1680   -- LESFDPPAD - Later of Enrt Strt or First Day of Pay Period after Dedesignated
1681   -- LESFDMAD - Later of Enrt Start or First Day of Month after Dedesignated
1682   -- FDSMFES - First of Semi month after enrollment start
1683   -- FDSMCFES - First of Semi Month on or After Enrollment
1684   -- LESFDSMAD - Later of Enrollment Start or First of Semi Month After
1685   --             Designated
1686   elsif p_date_cd  = 'LEMES' or p_date_cd = 'LFPPEMES' or p_date_cd = 'LFMEMES'
1687     or  p_date_cd  = 'LFYEMES'  or p_date_cd = 'FDMCFES'  or p_date_cd = 'FDMFES'
1688     or p_date_cd = 'FDPPCFES' or p_date_cd = 'FDPPFES'  or p_date_cd = 'LESWD'
1689     or p_date_cd = 'LESFDPPAD' or p_date_cd = 'LESFDMAD' or p_date_cd = 'FDPPELD'
1690     or p_date_cd = 'FDSMFES' or p_date_cd = 'FDSMCFES' or p_date_cd = 'LESFDSMAD'
1691     then
1692    if g_debug then
1693      hr_utility.set_location('Entering '||p_date_cd,17);
1694    end if;
1695    if g_debug then
1696      hr_utility.set_location('l_lf_evt_ocrd_dt :'||l_lf_evt_ocrd_dt , 17);
1697    end if;
1698 
1699    if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL
1700      and p_date_cd in ('LEMES','LFMEMES','LFPPEMES','LFYEMES') ) then
1701       hr_utility.set_location('l_lf_evt_ocrd_dt bckdt:'||ben_manage_life_events.g_bckdt_per_in_ler_id, 17);
1702             open c_rt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
1703 	          fetch c_rt_dts_bckdt into l_rt_strt_dt1,
1704 	                                    l_rt_end_dt1;
1705 	          close c_rt_dts_bckdt;
1706 
1707             if l_rt_strt_dt1 is null then
1708 	              l_rt_strt_dt1 :=p_effective_date;
1709 	          end if;
1710       hr_utility.set_location('l_rt_strt_dt1: '||l_rt_strt_dt1, 17);
1711             p_returned_date := l_rt_strt_dt1;
1712          return;
1713    end if;
1714 
1715     if l_lf_evt_ocrd_dt is null then
1716        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
1717        if g_debug then
1718          hr_utility.set_location('In the get_event_date '||l_lf_evt_ocrd_dt,17);
1719        end if ;
1720     end if;
1721 
1722    if g_debug then
1723      hr_utility.set_location('before cursor l_enrt_cvg_strt_dt:'||l_enrt_cvg_strt_dt,18);
1724    end if;
1725 
1726     open c_prtt_enrt_rslt_dts;
1727     fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
1728                                     l_enrt_cvg_strt_dt,
1729                                     l_enrt_eff_strt_date;
1730     -- bug fix 1633284  if the cursor fails, we are using the p_start_date and
1731     -- p_effective_date parameters for further processing.
1732 
1733         --Bug 5225815 commented the p_start_date not null check.
1734        --assign the default when no prior elections exists
1735 
1736        --Bug 5394353 Undid Modification done for Bug 5225815
1737        --Uncommented the p_start_date not null check.
1738        --p_start_date would be null in cases where rt_strt_dt is to be calculated at enrollment
1739 
1740     if c_prtt_enrt_rslt_dts%notfound  and   p_start_date is not null then
1741       l_enrt_cvg_strt_dt   := p_start_date ;
1742       l_enrt_eff_strt_date := p_effective_date ;
1743     end if;
1744     --
1745     close c_prtt_enrt_rslt_dts;
1746      if g_debug then
1747        hr_utility.set_location('l_enrt_cvg_end_dt :'||l_enrt_cvg_end_dt , 18);
1748      end if;
1749      if g_debug then
1750        hr_utility.set_location('l_enrt_cvg_strt_dt:'||l_enrt_cvg_strt_dt,18);
1751      end if;
1752      if g_debug then
1753        hr_utility.set_location('l_enrt_eff_strt_date:'||l_enrt_eff_strt_date,18);
1754      end if;
1755     --
1756     --
1757     if p_date_cd  = 'LEMES' or p_date_cd = 'LFPPEMES' or p_date_cd = 'LFMEMES'
1758        or p_date_cd  = 'LFYEMES'  then
1759        -- Later of Elections Made or Enrollment Start
1760        -- For all but LEMES, this is just a starting date. More code below.
1764           p_returned_date := l_enrt_eff_strt_date;
1761        if l_enrt_cvg_strt_dt > l_enrt_eff_strt_date then
1762           p_returned_date := l_enrt_cvg_strt_dt;
1763        else
1765        end if;
1766     else  -- start with enrollment start date.
1767           p_returned_date := l_enrt_cvg_strt_dt;
1768     end if;
1769       --
1770 
1771     -- LESFDSMAD - Later of Enrollment Start or First of Semi Month After
1772     --
1773     if p_date_cd = 'LESFDSMAD' then
1774       --
1775       if to_char(p_effective_date, 'DD') > 15 then
1776         --
1777         l_event_date := round(p_effective_date,'Month') ;
1778         --
1779       else
1780         --
1781         l_event_date := round(p_effective_date,'Month')+ 15  ;
1782         --
1783       end if;
1784       --
1785       if l_enrt_cvg_strt_dt > l_event_date then
1786         --
1787         p_returned_date := l_enrt_cvg_strt_dt ;
1788         --
1789       else
1790         --
1791         p_returned_date := l_event_date ;
1792         --
1793       end if;
1794     --
1795     end if ;
1796     --
1797     -- FDSMFES - First of Semi month after enrollment start
1798     -- FDSMCFES - First of Semi Month on or After Enrollment
1799     if p_date_cd = 'FDSMFES' or p_date_cd = 'FDSMCFES' then
1800       --
1801       if p_date_cd = 'FDSMCFES' and to_number(to_char(l_enrt_cvg_strt_dt, 'DD')) in ( 1, 16 )
1802       then
1803         --
1804         p_returned_date := l_enrt_cvg_strt_dt ;
1805         if g_debug then
1806           hr_utility.set_location('Case 1',15);
1807         end if;
1808         --
1809       elsif to_char(l_enrt_cvg_strt_dt, 'DD') > 15 then
1810         --
1811         p_returned_date := round(l_enrt_cvg_strt_dt,'Month')  ;
1812         if g_debug then
1813           hr_utility.set_location('Case 2',15);
1814         end if;
1815         --
1816       else
1817         --
1818         p_returned_date := round(l_enrt_cvg_strt_dt,'Month') + 15 ;
1819         if g_debug then
1820           hr_utility.set_location('Case 3'||l_enrt_cvg_strt_dt,15);
1821         end if;
1822         if g_debug then
1823           hr_utility.set_location('Case 3'||p_returned_date,15);
1824         end if;
1825 
1826         --
1827       end if;
1828       --
1829     end if;
1830     --
1831     if p_date_cd = 'FDPPCFES' or p_date_cd ='FDPPELD'  then
1832        -- First of Pay Period On or After Enrollment
1833        --
1834        if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL
1835           and p_date_cd ='FDPPELD') then
1836            hr_utility.set_location('Entering FDPPELD',11);
1837             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
1838 	          fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
1839 	                                    l_enrt_cvg_strt_dt,
1840 	                                    l_enrt_eff_strt_date;
1841 	    --
1842 	    close c_prtt_enrt_rslt_dts_bckdt;
1843 
1844             if l_enrt_eff_strt_date is null then
1845 	      l_enrt_eff_strt_date:=p_effective_date;
1846 	    end if;
1847             p_returned_date := l_enrt_eff_strt_date;
1848 	    return;
1849       end if;
1850 
1851        if  p_date_cd ='FDPPELD' then
1852           p_returned_date := p_effective_date;
1853        end if;
1854        --
1855        open c_pay_period_for_date(p_returned_date);
1856        fetch c_pay_period_for_date into
1857           l_start_date,
1858           l_end_date;
1859 
1860        if c_pay_period_for_date%notfound and
1861          l_enrt_cvg_strt_dt is not null then
1862          if g_debug then
1863            hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',80);
1864          end if;
1865          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1866          fnd_message.set_token('DATE_CODE',p_date_cd);
1867          fnd_message.set_token('L_PROC',l_proc);
1868          fnd_message.set_token('PERSON_ID',l_person_id);
1869          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1870          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1871          fnd_message.raise_error;
1872        end if;
1873        close c_pay_period_for_date;
1874     end if;
1875 
1876     if (p_date_cd = 'FDPPCFES' or p_date_cd ='FDPPELD' ) and p_returned_date = l_start_date
1877        then
1878           null; -- use p_returned_date (enrt strt)
1879     elsif ((p_date_cd = 'FDPPCFES' or p_date_cd ='FDPPELD')
1880             and p_returned_date <> l_start_date)
1881           or p_date_cd = 'LFPPEMES' or p_date_cd = 'FDPPFES'
1882           or p_date_cd = 'LESFDPPAD' then
1883            if g_debug then
1884              hr_utility.set_location('LFPPEMES  First of Pay Period After',20);
1885            end if;
1886           -- First of Pay Period After
1887           if p_date_cd = 'LESFDPPAD' then
1888              -- need to get pay period after designation, not enrt strt.
1889              p_returned_date := nvl(l_fonm_rt_cvg_strt_dt, p_effective_date );
1890           end if;
1891           open c_next_pay_period(p_returned_date);
1892           fetch c_next_pay_period into l_next_pay_period;
1893 
1894           if g_debug then
1895             hr_utility.set_location('l_next_pay_period.start_date'||l_next_pay_period.start_date,20);
1896           end if;
1897           if c_next_pay_period%notfound and
1898              l_enrt_cvg_strt_dt is not null then
1899             close c_next_pay_period;
1900             if g_debug then
1901               hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',40);
1902             end if;
1903             fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1904             fnd_message.set_token('DATE_CODE',p_date_cd);
1905             fnd_message.set_token('L_PROC',l_proc);
1909             fnd_message.raise_error;
1906             fnd_message.set_token('PERSON_ID',l_person_id);
1907             fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1908             fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1910           end if;
1911           close c_next_pay_period;
1912 
1913           if p_date_cd = 'LESFDPPAD' and
1914              l_enrt_eff_strt_date > l_next_pay_period.start_date then
1915              -- Later of Enrt Strt or First Day of Pay Period after Dedesignated
1916              p_returned_date := l_enrt_eff_strt_date;
1917           else
1918              p_returned_date := l_next_pay_period.start_date;
1919              if g_debug then
1920                hr_utility.set_location('Else case :'||l_next_pay_period.start_date,20);
1921              end if;
1922           end if;
1923 
1924     elsif p_date_cd = 'LFMEMES' or p_date_cd = 'FDMCFES' or p_date_cd = 'FDMFES'
1925           then
1926           -- First of Month
1927           if p_date_cd = 'FDMCFES' and to_char(p_returned_date, 'dd') = '01' then
1928              null;  -- use p_returned_date (enrt strt)
1929           else
1930              p_returned_date := last_day(p_returned_date)+1;
1931           end if;
1932     elsif p_date_cd = 'LESFDMAD' then
1933           -- Later of Enrt Start or First Day of Month after Dedesignated
1934           if last_day(p_effective_date)+1 > p_returned_date then
1935              p_returned_date := last_day(p_effective_date)+1;
1936           end if;  -- else use p_returned date (enrt strt)
1937     elsif p_date_cd  = 'LFYEMES' then
1938           -- First of Year
1939           get_next_plan_year
1940                  (p_effective_date => p_effective_date
1941                  ,p_lf_evt_ocrd_dt => p_returned_date
1942                  ,p_pl_id          => l_pl_id
1943                  ,p_pgm_id         => l_pgm_id
1944                  ,p_oipl_id        => l_oipl_id
1945                  ,p_date_cd        => p_date_cd
1946                  ,p_comp_obj_mode  => p_comp_obj_mode
1947                  ,p_start_date     => l_next_popl_yr_strt
1948                  ,p_end_date       => l_next_popl_yr_end) ;
1949 
1950           p_returned_date :=l_next_popl_yr_strt;
1951     elsif  p_date_cd = 'LESWD' then
1952           -- Later of Enrollment Start or When Dedesignated
1953           if l_enrt_cvg_strt_dt > p_effective_date then
1954              p_returned_date := l_enrt_cvg_strt_dt;
1955           else
1956              p_returned_date := p_effective_date;
1957           end if;
1958     end if;
1959   --
1960   elsif p_date_cd = 'FDPPFED' or p_date_cd = 'LDPPFEFD' then
1961    --
1962    open c_next_pay_period(p_effective_date);
1963    fetch c_next_pay_period into l_next_pay_period;
1964    if g_debug then
1965      hr_utility.set_location('l_next_pay_period.start_date'||l_next_pay_period.start_date,20);
1966    end if;
1967    if c_next_pay_period%notfound then
1968       close c_next_pay_period;
1969       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1970       fnd_message.set_token('DATE_CODE',p_date_cd);
1971       fnd_message.set_token('L_PROC',l_proc);
1972       fnd_message.set_token('PERSON_ID',l_person_id);
1973       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1974       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
1975       fnd_message.raise_error;
1976    end if;
1977    close c_next_pay_period;
1978    if p_date_cd = 'FDPPFED' then
1979      p_returned_date := l_next_pay_period.start_date;
1980    else
1981      p_returned_date := l_next_pay_period.end_date;
1982    end if;
1983  --
1984  -- ** FDPPOED - First of Pay Period On or After Effective Date
1985  elsif p_date_cd = 'FDPPOED' then
1986     -- Bug:4268494: Changed the logic. Get the current pay-period start/end dates
1987     -- If start_date <> effective_date, fetch next pay period start/end dates. Return start_date.
1988     hr_utility.set_location('Evaluate FDPPOED',10);
1989     l_event_date := NVL(l_fonm_rt_cvg_strt_dt,p_effective_date);
1990     --
1991     open c_pay_period;
1992     fetch c_pay_period into l_pay_period;
1993     if c_pay_period%notfound then
1994       close c_pay_period;
1995       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
1996       fnd_message.set_token('DATE_CODE',p_date_cd);
1997       fnd_message.set_token('PERSON_ID',l_person_id);
1998       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
1999       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
2000       fnd_message.raise_error;
2001     end if;
2002     close c_pay_period ;
2003     --
2004     if l_event_date =  l_pay_period.start_date then
2005        p_returned_date := l_pay_period.start_date;
2006        hr_utility.set_location('l_pay_period.start_date '||l_pay_period.start_date,10);
2007     else
2008        --
2009        open c_next_pay_period(NVL(l_event_date,p_effective_date));
2010        fetch c_next_pay_period into l_next_pay_period;
2011        --
2012        if c_next_pay_period%notfound then
2013          close c_next_pay_period;
2014          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
2015          fnd_message.set_token('DATE_CODE',p_date_cd);
2016          fnd_message.set_token('PERSON_ID',l_person_id);
2017          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
2018          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
2019          fnd_message.raise_error;
2020        end if;
2021        close c_next_pay_period;
2022        p_returned_date := l_next_pay_period.start_date;
2023        hr_utility.set_location('l_pay_period.start_date '|| l_next_pay_period.start_date,20);
2024        --
2025     end if;
2026     --
2027  --
2028  -- ** LDPPOEFD - 1 Prior or End of Pay Period On or After Effective Date
2029  elsif p_date_cd = 'LDPPOEFD' THEN
2030     -- Bug:4268494: Changed the logic. Get the current pay-period start/end dates
2034     --
2031     -- If end_date <> effective_date, fetch next pay period start/end dates. Return end_date.
2032     hr_utility.set_location('Evaluate LDPPOEFD',10);
2033     l_event_date := NVL(l_fonm_rt_cvg_strt_dt,p_effective_date);
2035     open c_pay_period;
2036     fetch c_pay_period into l_pay_period;
2037     if c_pay_period%notfound then
2038       close c_pay_period;
2039       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
2040       fnd_message.set_token('DATE_CODE',p_date_cd);
2041       fnd_message.set_token('PERSON_ID',l_person_id);
2042       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
2043       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
2044       fnd_message.raise_error;
2045     end if;
2046     close c_pay_period ;
2047     --
2048     if l_event_date =  l_pay_period.end_date then
2049        p_returned_date := l_pay_period.end_date;
2050        hr_utility.set_location('l_pay_period.end_date '|| l_pay_period.end_date,20);
2051     else
2052        --
2053        open c_next_pay_period(NVL(l_event_date,p_effective_date));
2054        fetch c_next_pay_period into l_next_pay_period;
2055        --
2056        if c_next_pay_period%notfound then
2057          close c_next_pay_period;
2058          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
2059          fnd_message.set_token('DATE_CODE',p_date_cd);
2060          fnd_message.set_token('PERSON_ID',l_person_id);
2061          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
2062          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
2063          fnd_message.raise_error;
2064        end if;
2065        close c_next_pay_period;
2066        p_returned_date := l_next_pay_period.end_date;
2067        hr_utility.set_location('l_pay_period.end_date '|| l_next_pay_period.end_date,20);
2068        --
2069     end if;
2070   --
2071   -- AFDCSMFDFFNSM First of next Semi month,if from day is first,
2072   --               else first of next semi month
2073   elsif p_date_cd = 'AFDCSMFDFFNSM' then
2074 
2075     l_lf_evt_ocrd_dt := nvl(l_fonm_rt_cvg_strt_dt,p_effective_date ) ;   -- Age Determination
2076     --
2077     if to_number(to_char(l_lf_evt_ocrd_dt, 'DD')) in (1,16) then
2078       --
2079       p_returned_date := l_lf_evt_ocrd_dt ;
2080       --
2081     elsif to_char(l_lf_evt_ocrd_dt, 'DD') > 15 then
2082       --
2083       p_returned_date := round(l_lf_evt_ocrd_dt,'Month')  ;
2084       --
2085     else
2086       --
2087       p_returned_date := round(l_lf_evt_ocrd_dt,'Month') + 15 ;
2088       --
2089     end if;
2090 
2091     -- FDSMCF - First of Semi Month on or After Event
2092     --
2093     elsif p_date_cd = 'FDSMCF' then
2094       --
2095       if l_lf_evt_ocrd_dt is null then
2096       --
2097         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2098       --
2099       else
2100         l_event_date:=  l_lf_evt_ocrd_dt ;
2101       --
2102       end if;
2103         --
2104         if to_number(to_char(l_event_date, 'DD')) in ( 1, 16 ) then
2105           --
2106           p_returned_date := l_event_date ;
2107           --
2108         elsif to_char(l_event_date, 'DD') > 15 then
2109           --
2110           p_returned_date := last_day(l_event_date)+1  ;
2111           --
2112         else
2113           --
2114           p_returned_date := trunc(l_event_date,'Month') + 15 ;
2115           --
2116         end if;
2117         --
2118     -- LAFDFSM - First of Semi Month After Later Event or Notified
2119     --
2120     elsif p_date_cd = 'LAFDFSM' then
2121       --
2122       if l_lf_evt_ocrd_dt is null then
2123       --
2124         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2125       --
2126       else
2127       --
2128         l_event_date:= l_lf_evt_ocrd_dt;
2129       --
2130       end if;
2131 
2132       --
2133       l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2134       --
2135       if l_event_date > l_recorded_date then
2136         --
2137         if to_char(l_event_date, 'DD') > 15 then
2138           --
2139           p_returned_date := last_day(l_event_date)+1  ;
2140           --
2141         else
2142           --
2143           p_returned_date := trunc(l_event_date,'Month') + 15 ;
2144           --
2145         end if;
2146       else
2147         --
2148         if to_char(l_recorded_date, 'DD') > 15 then
2149           --
2150           p_returned_date := last_day(l_recorded_date)+1  ;
2151           --
2152         else
2153           --
2154           p_returned_date := trunc(l_recorded_date,'Month') + 15 ;
2155           --
2156         end if;
2157         --
2158       end if;
2159       --
2160     -- LFDSMCF - First of Semi Month on or After Later Event or Notified
2161     --
2162     elsif p_date_cd = 'LFDSMCF' then
2163       --
2164       if l_lf_evt_ocrd_dt is null then
2165       --
2166         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2167       --
2168       else
2169       --
2170         l_event_date:= l_lf_evt_ocrd_dt;
2171       --
2172       end if;
2173       --
2174       l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2175       --
2176       if l_event_date > l_recorded_date then
2177         --
2178         if  to_number(to_char(l_event_date, 'DD')) in ( 1, 16 ) then
2179           --
2180           p_returned_date := l_event_date ;
2181           --
2182         elsif to_char(l_event_date, 'DD') > 15 then
2186         else
2183           --
2184           p_returned_date := last_day(l_event_date)+1  ;
2185           --
2187           --
2188           p_returned_date := trunc(l_event_date,'Month') + 15 ;
2189           --
2190         end if;
2191         --
2192       else
2193         --
2194         if to_number(to_char(l_recorded_date, 'DD')) in ( 1, 16 ) then
2195           --
2196           p_returned_date := l_recorded_date ;
2197           --
2198         elsif to_char(l_recorded_date, 'DD') > 15 then
2199           --
2200           p_returned_date := last_day(l_recorded_date)+1  ;
2201           --
2202         else
2203           --
2204           p_returned_date := trunc(l_recorded_date,'Month') + 15 ;
2205           --
2206         end if;
2207         --
2208       end if;
2209 
2210   -- 1 Prior or Later Event or Notified Semi Month End
2211   --
2212   elsif p_date_cd = 'LWALDCSM' then
2213   --    --
2214     if g_debug then
2215       hr_utility.set_location('Entering LWALDCSM',10);
2216     end if;
2217     --
2218        if l_lf_evt_ocrd_dt is null then
2219        --
2220           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2221        --
2222        else
2223        --
2224           l_event_date:= l_lf_evt_ocrd_dt;
2225        --
2226        end if;
2227        --
2228        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2229        --
2230        If l_recorded_date > l_event_date then
2231        --
2232           if to_char(l_recorded_date, 'DD') > 15 then
2233             p_returned_date := round(l_recorded_date,'Month')  ;
2234           else
2235             p_returned_date := round(l_recorded_date,'Month') + 15 ;
2236           end if;
2237        --
2238        else
2239        --
2240           --
2241           if to_char(l_event_date, 'DD') > 15 then
2242              p_returned_date := round(l_event_date,'Month')  ;
2243           else
2244              p_returned_date := round(l_event_date,'Month') + 15 ;
2245           end if;
2246           --
2247        End If;
2248     --
2249   -- 1 Prior or Semi Month End
2250   -- Semi Month end is if le is between 1 and 15 then take 15 else take end of month
2251   --
2252 
2253   elsif p_date_cd = 'WALDCSM' then
2254   --    --
2255     if g_debug then
2256       hr_utility.set_location('Entering WALDCSM',10);
2257     end if;
2258     --
2259        if l_lf_evt_ocrd_dt is null then
2260        --
2261           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2262        --
2263        else
2264        --
2265           l_event_date:= l_lf_evt_ocrd_dt;
2266        --
2267        end if;
2268        --
2269        if to_char(l_event_date, 'DD') > 15 then
2270           p_returned_date := last_day(l_event_date)  ;
2271        else
2272           p_returned_date := trunc(l_event_date,'Month') + 14 ;
2273        end if;
2274        --
2275        if g_debug then
2276          hr_utility.set_location('p_returned_date  '||p_returned_date , 19 );
2277        end if;
2278     --
2279   --
2280   -- EEELDNSMADI --  Earlier Participant Enrollment End or Next Semi Month End
2281   -- for dependent coverage end date
2282   elsif p_date_cd = 'EEELDNSMADI' then
2283   --
2284     if g_debug then
2285       hr_utility.set_location('Entering EEELDNSMADI',10);
2286     end if;
2287     --
2288       --
2289       --  p_effective_date   -- Designated Date
2290       --
2291       if to_char(p_effective_date, 'DD') > 15 then
2292         --
2293         l_event_date := round( nvl(l_fonm_rt_cvg_strt_dt,p_effective_date))+ 14 ;
2294         --
2295       else
2296         --
2297         l_event_date := last_day(nvl(l_fonm_rt_cvg_strt_dt,p_effective_date)) ;
2298         --
2299       end if;
2300       --
2301       open c_prtt_enrt_rslt_dts;
2302       --
2303       fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
2304                                       l_enrt_cvg_strt_dt,
2305                                       l_enrt_eff_strt_date;
2306       --
2307       close c_prtt_enrt_rslt_dts;
2308       --
2309       if l_enrt_cvg_end_dt < l_event_date then
2310         --
2311 	p_returned_date := l_enrt_cvg_end_dt ;
2312         --
2313       else
2314         --
2315         p_returned_date := l_event_date ;
2316         --
2317       end if;
2318       --
2319   -- ALDPSM End of Previuos Semi Month  ( if day between 1 and 15 then last day of prev month
2320   --                                      else 15th of the same month )
2321   --
2322   elsif p_date_cd = 'ALDPSM' then
2323   --
2324        --
2325        if g_debug then
2326          hr_utility.set_location('Entering ALDPSM',10);
2327        end if;
2328        --
2329        if l_lf_evt_ocrd_dt is null then
2330        --
2331           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2332        --
2333        else
2334        --
2335           l_event_date:= l_lf_evt_ocrd_dt;
2336        --
2337        end if;
2338        --
2339        if to_char(l_event_date, 'DD') > 15 then
2340           p_returned_date := trunc(l_event_date,'Month')+ 14 ;
2341        else
2342           p_returned_date := last_day(add_months(l_event_date,-1)) ;
2343        end if;
2344   --
2345   -- LALDPSM End of Previuos Semi Month later event or Notified
2349   elsif p_date_cd = 'LALDPSM' then
2346   --            ( if later day between 1 and 15 then last day of prev month
2347   --                                      else 15th of the same month )
2348   --
2350   --
2351        --
2352        if g_debug then
2353          hr_utility.set_location('Entering ALDPSM',10);
2354        end if;
2355        --
2356        if l_lf_evt_ocrd_dt is null then
2357        --
2358           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2359        --
2360        else
2361        --
2362           l_event_date:= l_lf_evt_ocrd_dt;
2363        --
2364        end if;
2365        --
2366        l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2367        --
2368        if l_event_date > l_recorded_date then
2369          --
2370          if to_char(l_event_date, 'DD') > 15 then
2371            --
2372            p_returned_date := trunc(l_event_date,'Month')+ 14 ;
2373            --
2374          else
2375            --
2376            p_returned_date := last_day(add_months(l_event_date,-1)) ;
2377            --
2378          end if;
2379          --
2380        else
2381          --
2382          if to_char(l_recorded_date, 'DD') > 15 then
2383            --
2384            p_returned_date := trunc(l_recorded_date,'Month')+ 14 ;
2385            --
2386          else
2387            --
2388            p_returned_date := last_day(add_months(l_recorded_date,-1)) ;
2389            --
2390          end if;
2391          --
2392        end if;
2393        --
2394   --
2395   --  ALDCSM End of Semi-month.
2396   --
2397   elsif p_date_cd = 'ALDCSM' then
2398     --
2399     if g_debug then
2400       hr_utility.set_location('Entering ALDCSM',10);
2401     end if;
2402     --
2403     if l_lf_evt_ocrd_dt is null then
2404       --
2405       l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2406       --
2407     else
2408       --
2409       l_event_date:= l_lf_evt_ocrd_dt;
2410       --
2411     end if;
2412     --
2413     if to_char(l_event_date, 'DD') > 15 then
2414        --
2415        p_returned_date := last_day(l_event_date)  ;
2416        --
2417     else
2418        --
2419        p_returned_date := trunc(l_event_date,'Month') + 14 ;
2420        --
2421     end if;
2422     --
2423     if g_debug then
2424       hr_utility.set_location('p_returned_date '||p_returned_date , 199) ;
2425     end if;
2426   --
2427   --  LALDCSM End of Semi-month later event or Notified.
2428   --
2429   elsif p_date_cd = 'LALDCSM' then
2430     --
2431     if g_debug then
2432       hr_utility.set_location('Entering LALDCSM',10);
2433     end if;
2434     --
2435     if l_lf_evt_ocrd_dt is null then
2436       --
2437       l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2438       --
2439     else
2440       --
2441       l_event_date:= l_lf_evt_ocrd_dt;
2442       --
2443     end if;
2444     --
2445     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2446     --
2447     if l_event_date > l_recorded_date then
2448       --
2449       if to_char(l_event_date, 'DD') > 15 then
2450         --
2451         p_returned_date := last_day(l_event_date)  ;
2452         --
2453       else
2454         --
2455         p_returned_date := trunc(l_event_date,'Month') + 14 ;
2456         --
2457       end if;
2458     else
2459       --
2460       if to_char(l_recorded_date, 'DD') > 15 then
2461         --
2462         p_returned_date := last_day(l_recorded_date)  ;
2463         --
2464       else
2465         --
2466         p_returned_date := trunc(l_recorded_date,'Month') + 14 ;
2467         --
2468       end if;
2469       --
2470     end if;
2471   --
2472   --  AFDFSM First of next Semi-month.
2473   --
2474   elsif p_date_cd = 'AFDFSM' then
2475     --
2476     if g_debug then
2477       hr_utility.set_location('Entering AFDFSM',10);
2478     end if;
2479     --
2480     if l_lf_evt_ocrd_dt is null then
2481     --
2482       l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2483     --
2484     else
2485     --
2486       l_event_date:= l_lf_evt_ocrd_dt;
2487     --
2488     end if;
2489     --
2490     if to_char(l_event_date, 'DD') > 15 then
2491       p_returned_date := round(l_event_date,'Month')  ;
2492     else
2493       p_returned_date := round(l_event_date,'Month') + 15 ;
2494     end if;
2495     --
2496   --  AFDCSM First of Semi-month.
2497   --
2498   elsif p_date_cd = 'AFDCSM' then
2499     --
2500     if g_debug then
2501       hr_utility.set_location('Entering AFDCSM',10);
2502     end if;
2503     --
2504     if l_lf_evt_ocrd_dt is null then
2505     --
2506       l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2507     --
2508     else
2509     --
2510       l_event_date:= l_lf_evt_ocrd_dt;
2511     --
2512     end if;
2513     --
2514     if to_char(l_event_date, 'DD') > 15 then
2515       --
2516       p_returned_date := trunc(l_event_date,'Month')+ 15  ;
2517       --
2518     else
2519       --
2520       p_returned_date := trunc(l_event_date,'Month')  ;
2521       --
2522     end if;
2523     --
2524 
2525 
2526   -- -------------------------------------------------------------------------
2527   -- After Completion
2528   -- -------------------------------------------------------------------------
2532   -- FDMFC - First of Month After Completed
2529   -- eg:  year 1-jan to 31-dec.  a. dt = 4-feb  b. dt=1-jan   c. dt=2-dec
2530   -- FDMCFC - First of Month on or After Completed
2531      -- a. 1-mar            b. 1-jan        c. 1-Jan-next
2533   -- FDLMPPYFC - First of Last Month in Year After Completion
2534      -- a. 1-dec            b. 1-dec        c. ?1-jan-next
2535   -- FDLPPPPYFC - First of Last Pay Period in Year After Completion
2536   -- FDPPCFC - First of Pay Period On or After Completion
2537      -- a. 1-mar            b. 1-jan        c. 1-jan-next  (if monthly)
2538   -- FDPPFC - First of Pay Period After Completion
2539   -- FDPPYCFC - First of Year On or After Completed
2540      -- a. 1-Jan-next       b. 1-Jan        c. 1-Jan-next
2541   -- FDPPYFC - First of Year After Completed
2542      -- a. 1-Jan-next       b. 1-Jan-next   c. 1-Jan-next
2543   -- FDSMFC First of Semi Month after Completion
2544      -- a. if day upto 15 then take 16th of the month else take 1st of following month
2545   -- FDSMCFC First of Semi Month on or after Completion
2546      -- a. if day upto 15 then take 16th of the month else take 1st of following month
2547      -- exception is for 1 take 1 and for 16 take 16
2548   --
2549   elsif p_date_cd  = 'FDMCFC' or p_date_cd = 'FDMFC' or p_date_cd = 'FDLMPPYFC'
2550      or p_date_cd = 'FDLPPPPYFC' or p_date_cd = 'FDPPCFC' or p_date_cd = 'FDPPFC'
2551      or p_date_cd = 'FDPPYCFC' or p_date_cd = 'FDPPYFC'
2552      or p_date_cd = 'FDSMFC' or p_date_cd = 'FDSMCFC'
2553   then
2554 
2555     if g_debug then
2556       hr_utility.set_location('Entering '||p_date_cd,14);
2557     end if;
2558 
2559     l_lf_evt_ocrd_dt := nvl(l_fonm_rt_cvg_strt_dt, p_effective_date) ;  -- completion date.
2560 
2561     l_cmpltd_dt     := nvl(p_cmpltd_dt,p_effective_date);
2562 
2563     if to_char( nvl(l_cmpltd_dt, p_effective_date), 'dd') = '01' and p_date_cd = 'FDMCFC' then
2564        -- First of Month on or After Completed
2565        -- p_returned_date :=  nvl(l_fonm_rt_cvg_strt_dt, p_effective_date);
2566        p_returned_date := l_cmpltd_dt ;
2567        --
2568     elsif p_date_cd = 'FDSMFC' then
2569       -- First of Semi Month after Completion
2570       if g_debug then
2571         hr_utility.set_location('Entering FDSMFC',10);
2572       end if;
2573       --
2574       /*
2575       if to_char(l_lf_evt_ocrd_dt, 'DD') > 15 then
2576         p_returned_date := round(l_lf_evt_ocrd_dt,'Month')  ;
2577       else
2578         p_returned_date := round(l_lf_evt_ocrd_dt,'Month') + 15 ;
2579       end if;
2580       */
2581       if to_char(l_cmpltd_dt, 'DD') > 15 then
2582         p_returned_date := round(l_cmpltd_dt,'Month')  ;
2583       else
2584         p_returned_date := round(l_cmpltd_dt,'Month') + 15 ;
2585       end if;
2586     --
2587     elsif p_date_cd = 'FDSMCFC' then
2588       -- First of Semi Month on or after Completion
2589       if g_debug then
2590         hr_utility.set_location('Entering FDSMCFC',10);
2591       end if;
2592       --
2593       /*
2594       if to_number(to_char(l_lf_evt_ocrd_dt, 'DD')) in ( 1, 16 )  then
2595          p_returned_date := l_lf_evt_ocrd_dt ;
2596       elsif to_char(l_lf_evt_ocrd_dt, 'DD') > 15 then
2597         p_returned_date := round(l_lf_evt_ocrd_dt,'Month')  ;
2598       else
2599         p_returned_date := round(l_lf_evt_ocrd_dt,'Month') + 15 ;
2600       end if;
2601       */
2602       if to_number(to_char(l_cmpltd_dt, 'DD')) in ( 1, 16 )  then
2603          p_returned_date := l_cmpltd_dt ;
2604       elsif to_char(l_cmpltd_dt, 'DD') > 15 then
2605         p_returned_date := round(l_cmpltd_dt,'Month')  ;
2606       else
2607         p_returned_date := round(l_cmpltd_dt,'Month') + 15 ;
2608       end if;
2609       --
2610     elsif (p_date_cd = 'FDMCFC' and to_char(l_cmpltd_dt, 'dd') <> '01')
2611           or p_date_cd = 'FDMFC' then
2612        -- First of Month After Completed
2613        -- p_returned_date := last_day(p_effective_date)+1;
2614        --
2615        p_returned_date := last_day(l_cmpltd_dt)+1;
2616        --
2617     elsif p_date_cd = 'FDLMPPYFC' or p_date_cd = 'FDPPYCFC' or p_date_cd = 'FDPPYFC'
2618        then
2619        get_plan_year
2620            (p_effective_date =>  p_effective_date
2621            ,p_lf_evt_ocrd_dt => l_cmpltd_dt -- l_lf_evt_ocrd_dt
2622            ,p_pl_id          => l_pl_id
2623            ,p_pgm_id         => l_pgm_id
2624            ,p_oipl_id        => l_oipl_id
2625            ,p_date_cd        => p_date_cd
2626            ,p_comp_obj_mode  => p_comp_obj_mode
2627            ,p_start_date     => l_start_date
2628            ,p_end_date       => l_end_date) ;
2629 
2630         if p_date_cd = 'FDLMPPYFC' then
2631            -- First of Last Month in Year After Completion
2632            if  nvl(l_cmpltd_dt, p_effective_date) >=  add_months(l_end_date,-1)+1 then
2633               -- if eff dt is on or after first day of last month in plan year
2634               -- use first day of month in next plan year?
2635               p_returned_date := last_day(l_end_date)+1;
2636            else
2637               p_returned_date := last_day(add_months(l_end_date,-1))+1;
2638            end if;
2639         elsif p_date_cd = 'FDPPYCFC' and l_cmpltd_dt = l_start_date then
2640            -- First of Year On or After Completed
2641               p_returned_date := l_start_date;
2642         elsif (p_date_cd = 'FDPPYCFC' and  nvl(l_cmpltd_dt, p_effective_date) <> l_start_date) or
2643                p_date_cd = 'FDPPYFC' then
2644                -- First of Year After Completed
2645                get_next_plan_year
2646                  (p_effective_date =>   p_effective_date
2647                  ,p_lf_evt_ocrd_dt => l_cmpltd_dt
2648                  ,p_pl_id          => l_pl_id
2649                  ,p_pgm_id         => l_pgm_id
2650                  ,p_oipl_id        => l_oipl_id
2651                  ,p_date_cd        => p_date_cd
2652                  ,p_comp_obj_mode  => p_comp_obj_mode
2656                 p_returned_date :=l_start_date;
2653                  ,p_start_date     => l_start_date
2654                  ,p_end_date       => l_end_date) ;
2655 
2657 
2658         end if;
2659     elsif p_date_cd = 'FDLPPPPYFC'  or p_date_cd = 'FDPPCFC'  or p_date_cd = 'FDPPFC'
2660          then
2661         -- First of Last Pay Period in Year After Completion
2662         -- FDLPPPPYFC  this is wrong - emailed Denise for correction.
2663 
2664         -- First of Pay Period (On or) After Completion
2665         if p_date_cd =  'FDPPCFC' then
2666            open c_pay_period_for_date( nvl(l_cmpltd_dt, p_effective_date));
2667            fetch c_pay_period_for_date into l_start_date, l_end_date;
2668            if c_pay_period_for_date%notfound and
2669               p_effective_date is not null then
2670               close c_pay_period_for_date;
2671             if g_debug then
2672                 hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',45);
2673             end if;
2674               fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
2675               fnd_message.set_token('DATE_CODE',p_date_cd);
2676               fnd_message.set_token('L_PROC',l_proc);
2677               fnd_message.set_token('PERSON_ID',l_person_id);
2678               fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
2679               fnd_message.set_token('EFFECTIVE_DATE',l_cmpltd_dt);
2680               fnd_message.raise_error;
2681 
2682            end if;
2683            close c_pay_period_for_date;
2684 
2685            if p_effective_date = l_start_date then
2686               p_returned_date := l_start_date;
2687            end if;
2688         end if;
2689 
2690         if (l_cmpltd_dt <> l_start_date and p_date_cd = 'FDPPCFC') or
2691            p_date_cd = 'FDPPFC' then
2692 
2693            open c_next_pay_period(nvl(l_cmpltd_dt,p_effective_date));
2694            fetch c_next_pay_period into l_next_pay_period;
2695 
2696            if c_next_pay_period%notfound and
2697               p_effective_date is not null then
2698              close c_next_pay_period;
2699            if g_debug then
2700                hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',55);
2701            end if;
2702              fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
2703              fnd_message.set_token('DATE_CODE',p_date_cd);
2704              fnd_message.set_token('L_PROC',l_proc);
2705              fnd_message.set_token('PERSON_ID',l_person_id);
2706              fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
2707              fnd_message.set_token('EFFECTIVE_DATE',l_cmpltd_dt);
2708              fnd_message.raise_error;
2709            end if;
2710            close c_next_pay_period;
2711 
2712            p_returned_date := l_next_pay_period.start_date;
2713         end if;
2714     end if;
2715 
2716 
2717   --
2718   -- AFDELY - First of Limitation Year
2719   --
2720   elsif p_date_cd  = 'AFDELY' then
2721   --
2722   if g_debug then
2723       hr_utility.set_location('Entering AFDELY',10);
2724   end if;
2725     --
2726     if l_lf_evt_ocrd_dt is null then
2727     --
2728        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2729     --
2730     else
2731     --
2732        l_lf_evt_ocrd_dt:= l_lf_evt_ocrd_dt;
2733     --
2734     end if;
2735     --
2736     --  get end date for comp object
2737     --
2738     if l_pl_id is not null then
2739       open c_pl_popl_lim_yr;
2740       fetch c_pl_popl_lim_yr into l_start_date, l_end_date;
2741       close c_pl_popl_lim_yr;
2742     --
2743     elsif l_pgm_id is not null then
2744       open c_pgm_popl_lim_yr;
2745       fetch c_pgm_popl_lim_yr into l_start_date, l_end_date;
2746       close c_pgm_popl_lim_yr;
2747     --
2748     elsif l_oipl_id is not null then
2749       open c_oipl_popl_lim_yr;
2750       fetch c_oipl_popl_lim_yr into l_start_date, l_end_date;
2751       close c_oipl_popl_lim_yr;
2752     --
2753     else
2754     if g_debug then
2755         hr_utility.set_location('BEN_92489_CANNOT_CALC_DATE',55);
2756     end if;
2757       fnd_message.set_name('BEN','BEN_92489_CANNOT_CALC_DATE');
2758       fnd_message.set_token('DATE_CODE',p_date_cd);
2759       fnd_message.set_token('L_PROC',l_proc);
2760       fnd_message.raise_error;
2761     --
2762     end if;
2763     --
2764     p_returned_date:= l_start_date;
2765   --
2766   -- ALDELMY - End of Limitation Year
2767   --
2768   elsif p_date_cd  = 'ALDELMY' then
2769   --
2770   if g_debug then
2771       hr_utility.set_location('Entering ALDELMY',10);
2772   end if;
2773     --
2774     if l_lf_evt_ocrd_dt is null then
2775     --
2776        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2777     --
2778     else
2779     --
2780        l_lf_evt_ocrd_dt:= l_lf_evt_ocrd_dt;
2781     --
2782     end if;
2783     --
2784     --  get end date for comp object
2785     --
2786     if l_pl_id is not null then
2787       open c_pl_popl_lim_yr;
2788       fetch c_pl_popl_lim_yr into l_start_date, l_end_date;
2789       close c_pl_popl_lim_yr;
2790     --
2791     elsif l_pgm_id is not null then
2792       open c_pgm_popl_lim_yr;
2793       fetch c_pgm_popl_lim_yr into l_start_date, l_end_date;
2794       close c_pgm_popl_lim_yr;
2795     --
2796     elsif l_oipl_id is not null then
2797       open c_oipl_popl_lim_yr;
2798       fetch c_oipl_popl_lim_yr into l_start_date, l_end_date;
2799       close c_oipl_popl_lim_yr;
2800     --
2801     else
2802     --  hr_utility.set_location('BEN_92489_CANNOT_CALC_DATE',55);
2803       fnd_message.set_name('BEN','BEN_92489_CANNOT_CALC_DATE');
2807     --
2804       fnd_message.set_token('DATE_CODE',p_date_cd);
2805       fnd_message.set_token('L_PROC',l_proc);
2806       fnd_message.raise_error;
2808     end if;
2809     --
2810     p_returned_date:= l_end_date;
2811   --
2812   -- FDODD - Within 5 Days After Due
2813   --
2814   elsif p_date_cd = 'FDODD' then
2815   --
2816   --  hr_utility.set_location('Entering FDODD',10);
2817     --
2818     p_returned_date:= p_effective_date + 5;
2819   --
2820   -- FRTYFV - Within 45 Days After Due
2821   --
2822   elsif p_date_cd = 'FRTYFV' then
2823   --
2824   --  hr_utility.set_location('Entering FRTYFV',10);
2825     --
2826     p_returned_date:= p_effective_date + 45;
2827   ---
2828   -- TDODD - Within 10 Days after Due
2829   --
2830   elsif p_date_cd = 'TDODD' then
2831   --
2832   --  hr_utility.set_location('Entering TDODD',10);
2833     --
2834     p_returned_date:= p_effective_date + 10;
2835   --
2836   -- THRTY - Within 30 Days after Due
2837   --
2838   elsif p_date_cd = 'THRTY' then
2839   --
2840   --  hr_utility.set_location('Entering THRTY',10);
2841     --
2842     p_returned_date:= p_effective_date + 30;
2843   --
2844   -- THRTYONE - Within 31 Days after Due
2845   --
2846   elsif p_date_cd = 'THRTYONE' then
2847   --
2848   --  hr_utility.set_location('Entering THRTYONE',10);
2849     --
2850     p_returned_date:= p_effective_date + 31;
2851   --
2852   -- DO - Date Occurred
2853   --
2854   elsif p_date_cd = 'DO' then
2855   --
2856   --  hr_utility.set_location('Entering DO',10);
2857 
2858     p_returned_date:= p_effective_date;
2859   --
2860   -- DR - Date Recorded or Notified
2861   --
2862   elsif p_date_cd in ('DR','ODNPE') then
2863   --
2864   --  hr_utility.set_location('Entering DR',10);
2865 
2866     p_returned_date:= sysdate;
2867   --
2868   -- LOR - Later Occurred Date or Recorded Date.
2869   --
2870   elsif p_date_cd = 'LOR' then
2871   --
2872   --  hr_utility.set_location('Entering LOR',10);
2873     --
2874     if sysdate > nvl(l_lf_evt_ocrd_dt,hr_api.g_sot) then
2875       p_returned_date := sysdate;
2876     else
2877       p_returned_date := p_effective_date;
2878     end if;
2879   --
2880   -- DAO - Day After Occurred Date.
2881   -- or
2882   -- ODAED - One day after Event Date
2883   --
2884     --
2885   elsif p_date_cd = 'DAO' or p_date_cd = 'ODAED' then
2886   --
2887   --  hr_utility.set_location('Entering DAO',10);
2888   --  hr_utility.set_location('Entering ODAED',10);
2889     --
2890     --p_returned_date := p_effective_date + 1;
2891     if l_lf_evt_ocrd_dt is null then
2892     --
2893        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2894     --
2895     else
2896     --
2897        l_event_date:= l_lf_evt_ocrd_dt;
2898     --
2899     end if;
2900     --
2901     p_returned_date:=l_event_date+1;
2902     --
2903   --
2904   -- LDAOR -  Later of Day After Occurred Date
2905   --          or Recorded Date.
2906   --
2907   elsif p_date_cd = 'LDAOR' then
2908   --
2909   --  hr_utility.set_location('Entering LDAOR',10);
2910     --
2911     if sysdate > (nvl(l_lf_evt_ocrd_dt,hr_api.g_sot) + 1) then
2912       p_returned_date := sysdate;
2913     else
2914       p_returned_date := p_effective_date + 1;
2915     end if;
2916   --
2917   -- ALDECLY - End of Calendar Year
2918   --
2919   elsif p_date_cd = 'ALDECLY' then
2920   --
2921   --  hr_utility.set_location('Entering ALDECLY',10);
2922     --
2923     if l_lf_evt_ocrd_dt is null then
2924     --
2925        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2926     --
2927     else
2928     --
2929        l_event_date:= l_lf_evt_ocrd_dt;
2930     --
2931     end if;
2932     --
2933     p_returned_date:= add_months(trunc(l_event_date,'YYYY'),12)-1;
2934     --
2935   --
2936   --
2937   -- FFDFED - 45 Days After Event
2938   --
2939   elsif p_date_cd = 'FFDFED' then
2940   --
2941   --  hr_utility.set_location('Entering FFDFED',10);
2942     --
2943     if l_lf_evt_ocrd_dt is null then
2944     --
2945        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2946     --
2947     else
2948     --
2949        l_event_date:= l_lf_evt_ocrd_dt;
2950     --
2951     end if;
2952     --
2953     p_returned_date := l_event_date+45;
2954   --
2955   -- NDFED - 90 Days After Event
2956   --
2957   elsif p_date_cd = 'NDFED' then
2958   --
2959   --  hr_utility.set_location('Entering NDFED',10);
2960     --
2961     if l_lf_evt_ocrd_dt is null then
2962     --
2963        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2964     --
2965     else
2966     --
2967        l_event_date:= l_lf_evt_ocrd_dt;
2968     --
2969     end if;
2970     --
2971     p_returned_date := l_event_date+90;
2972   --
2973   -- LFFDFED - 45 Days After Later Event or Notified
2974   --
2975   elsif p_date_cd = 'LFFDFED' then
2976     --
2977   --  hr_utility.set_location('Entering LFFDFED',10);
2978     --
2979     if l_lf_evt_ocrd_dt is null then
2980     --
2981        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2982     --
2983     else
2984     --
2985        l_event_date:= l_lf_evt_ocrd_dt;
2986     --
2987     end if;
2988     --
2989     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
2990     --
2994     --
2991     if l_event_date > l_recorded_date then
2992     --
2993        l_date := l_event_date+45;
2995     else
2996     --
2997        l_date := l_recorded_date+45;
2998     --
2999     end if;
3000     --
3001     p_returned_date := l_date;
3002   --
3003   -- LNDFED - 90 Days After Later Event or Notified
3004   --
3005   elsif p_date_cd = 'LNDFED' then
3006     --
3007   --  hr_utility.set_location('Entering LNDFED',10);
3008     --
3009     if l_lf_evt_ocrd_dt is null then
3010     --
3011        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3012     --
3013     else
3014     --
3015        l_event_date:= l_lf_evt_ocrd_dt;
3016     --
3017     end if;
3018     --
3019     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3020     --
3021     if l_event_date > l_recorded_date then
3022     --
3023        l_date := l_event_date+90;
3024     --
3025     else
3026     --
3027        l_date := l_recorded_date+90;
3028     --
3029     end if;
3030     --
3031     p_returned_date := l_date;
3032   --
3033   -- LTDFED - 30 Days After Later Event or Notified
3034   --
3035   elsif p_date_cd = 'LTDFED' then
3036     --
3037   --  hr_utility.set_location('Entering LTDFED',10);
3038     --
3039     if l_lf_evt_ocrd_dt is null then
3040     --
3041        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3042     --
3043     else
3044     --
3045        l_event_date:= l_lf_evt_ocrd_dt;
3046     --
3047     end if;
3048     --
3049     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3050     --
3051     if l_event_date > l_recorded_date then
3052     --
3053        l_date := l_event_date+30;
3054     --
3055     else
3056     --
3057        l_date := l_recorded_date+30;
3058     --
3059     end if;
3060     --
3061     p_returned_date := l_date;
3062   --
3063   -- ALDPM - End of Previous Month
3064   --
3065   elsif p_date_cd = 'ALDPM' then
3066 
3067   --  hr_utility.set_location('Entering ALDPM',10);
3068 
3069     if l_lf_evt_ocrd_dt is null then
3070 
3071        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3072 
3073     else
3074 
3075        l_event_date:= l_lf_evt_ocrd_dt;
3076 
3077     end if;
3078 
3079     l_date := add_months(l_event_date,-1);
3080 
3081     p_returned_date := last_day(l_date);
3082 
3083   -- LALDPM - End of Previous Month Later Event or Notified
3084 
3085   elsif p_date_cd = 'LALDPM' then
3086 
3087   --  hr_utility.set_location('Entering LALDPM',10);
3088 
3089     if l_lf_evt_ocrd_dt is null then
3090 
3091        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3092 
3093     else
3094 
3095        l_event_date:= l_lf_evt_ocrd_dt;
3096 
3097     end if;
3098 
3099     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3100 
3101     if l_event_date > l_recorded_date then
3102 
3103        l_date := add_months(l_event_date,-1);
3104 
3105     else
3106 
3107        l_date := add_months(l_recorded_date,-1);
3108 
3109     end if;
3110     p_returned_date := last_day(l_date);
3111 
3112   -- ALDPPP - End of Previous Pay period
3113 
3114   elsif p_date_cd = 'ALDPPP' then
3115     --
3116   --  hr_utility.set_location('Entering ALDPPP',10);
3117 
3118     if l_lf_evt_ocrd_dt is null then
3119 
3120        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3121 
3122     else
3123 
3124        l_lf_evt_ocrd_dt := l_lf_evt_ocrd_dt;
3125 
3126     end if;
3127 
3128     open c_pay_period;
3129       fetch c_pay_period into l_pay_period;
3130 
3131     if c_pay_period%notfound then
3132 
3133       close c_pay_period;
3134     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',65);
3135       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
3136       fnd_message.set_token('DATE_CODE',p_date_cd);
3137       fnd_message.set_token('L_PROC',l_proc);
3138       fnd_message.set_token('PERSON_ID',l_person_id);
3139       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
3140       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3141       fnd_message.raise_error;
3142 
3143     end if;
3144 
3145     close c_pay_period ;
3146 
3147     p_returned_date := l_pay_period.start_date-1;
3148 
3149   -- LALDPPP - End of Previous Pay period Later Event or Notified
3150 
3151   elsif p_date_cd = 'LALDPPP' then
3152     --
3153   --  hr_utility.set_location('Entering LALDPPP',10);
3154 
3155     if l_lf_evt_ocrd_dt is null then
3156 
3157        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3158 
3159     else
3160 
3161        l_lf_evt_ocrd_dt := l_lf_evt_ocrd_dt;
3162 
3163     end if;
3164 
3165     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3166 
3167     -- Use later of event or recorded date
3168 
3169     if l_lf_evt_ocrd_dt < l_recorded_date then
3170 
3171        l_lf_evt_ocrd_dt := l_recorded_date;
3172 
3173     end if;
3174 
3175     open c_pay_period;
3176       fetch c_pay_period into l_pay_period;
3177 
3178     if c_pay_period%notfound then
3179 
3183       fnd_message.set_token('DATE_CODE',p_date_cd);
3180       close c_pay_period;
3181     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',70);
3182       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
3184       fnd_message.set_token('L_PROC',l_proc);
3185       fnd_message.set_token('PERSON_ID',l_person_id);
3186       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
3187       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3188       fnd_message.raise_error;
3189 
3190     end if;
3191 
3192     close c_pay_period ;
3193 
3194     p_returned_date := l_pay_period.start_date-1;
3195 
3196 
3197   -- LALDPPPY - Last Day of previous Program or Plan Year
3198   --            Later Event or Notified
3199 
3200   elsif p_date_cd  = 'LALDPPPY' then
3201 
3202   --  hr_utility.set_location('Entering LALDPPPY',10);
3203 
3204     if l_lf_evt_ocrd_dt is null then
3205 
3206        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3207 
3208     else
3209 
3210        l_lf_evt_ocrd_dt := l_lf_evt_ocrd_dt;
3211 
3212     end if;
3213 
3214     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3215 
3216     -- Use later of event or recorded date
3217 
3218     if l_lf_evt_ocrd_dt < l_recorded_date then
3219 
3220        l_lf_evt_ocrd_dt := l_recorded_date;
3221 
3222     end if;
3223 
3224     get_plan_year
3225            (p_effective_date => p_effective_date
3226            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3227            ,p_pl_id          => l_pl_id
3228            ,p_pgm_id         => l_pgm_id
3229            ,p_oipl_id        => l_oipl_id
3230            ,p_date_cd        => p_date_cd
3231            ,p_comp_obj_mode  => p_comp_obj_mode
3232            ,p_start_date     => l_start_date
3233            ,p_end_date       => l_end_date) ;
3234 
3235     p_returned_date := l_start_date-1;
3236 
3237   -- -------------------------------------------------------------------
3238   -- First Day of Quarters
3239   -- -------------------------------------------------------------------
3240   -- eg:  year 1-jan to 31-dec.  a. dt = 1-feb  b. dt=1-jul   c. dt=1-nov
3241   -- *AFDCPPQ - First day of current program or plan Quarter
3242      -- a. 1-Jan            b. 1-jul        c. 1-Oct
3243   -- AFDFPPQ - First of next Quarter
3244      -- a. 1-Apr            b. 1-oct        c. 1-Jan-Next
3245   -- *LAFDFPPQ - First of Quarter After Later Event or Notified
3246      -- a. 1-Apr            b. 1-oct        c. 1-Jan-Next
3247   -- FDPPQCF - First of Quarter on or After Event
3248      -- a. 1-Apr            b. 1-jul        c. 1-Jan-Next
3249   -- *LFDPPQCF - First of Quarter on or After Later Event or Notified
3250      -- a. 1-Apr            b. 1-jul        c. 1-Jan-Next
3251 
3252   -- -------------------------------------------------------------------
3253   -- Last Day of Quarters
3254   -- -------------------------------------------------------------------
3255   -- *ALDCPPQ -  Last Day of the Current Program or Plan Quarter
3256      -- a. 31-Mar            b. 30-Sep        c. 31-dec
3257   -- LALDCPPQ - End of Quarter Later event or Notified
3258      -- a. 31-Mar            b. 30-Sep        c. 31-dec
3259   -- *ALDPPPQ - End of Previous Quarter
3260      -- a. 31-Dec-last       b. 30-Jun        c. 31-sep
3261   -- LALDPPPQ - End of Previous Quarter Later Event or Notified
3262      -- a. 31-Dec-last       b. 30-Jun        c. 31-sep
3263 
3264 
3265 
3266   elsif p_date_cd = 'AFDFPPQ' or p_date_cd = 'ALDCPPQ' or p_date_cd = 'FDPPQCF'
3267      or p_date_cd = 'AFDCPPQ' or p_date_cd = 'LAFDFPPQ' or p_date_cd = 'ALDPPPQ'
3268      or p_date_cd = 'LALDPPPQ' or p_date_cd = 'LALDCPPQ' or p_date_cd = 'LFDPPQCF'
3269      then
3270 
3271   --  hr_utility.set_location('Entering '||p_date_cd,12);
3272 
3273     if l_lf_evt_ocrd_dt is null then
3274        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3275     end if;
3276 
3277     if p_date_cd = 'LAFDFPPQ' or p_date_cd = 'LALDPPPQ' or p_date_cd = 'LALDCPPQ'
3278        or p_date_cd = 'LFDPPQCF' then
3279        -- Use later of event or recorded date
3280        l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3281        if l_lf_evt_ocrd_dt < l_recorded_date then
3282           l_lf_evt_ocrd_dt := l_recorded_date;
3283        end if;
3284     end if;
3285 
3286     get_plan_year
3287            (p_effective_date => p_effective_date
3288            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3289            ,p_pl_id          => l_pl_id
3290            ,p_pgm_id         => l_pgm_id
3291            ,p_oipl_id        => l_oipl_id
3292            ,p_date_cd        => p_date_cd
3293            ,p_comp_obj_mode  => p_comp_obj_mode
3294            ,p_start_date     => l_start_date
3295            ,p_end_date       => l_end_date) ;
3296 
3297     l_months := round(months_between(l_end_date,l_start_date)/4);
3298     l_date := add_months(l_start_date,l_months); -- end date of '1st' quarter
3299 
3300     -- First day of quarters:
3301     if p_date_cd = 'AFDFPPQ'  or p_date_cd = 'LAFDFPPQ' then -- First of next Qtr
3302        if l_lf_evt_ocrd_dt < l_date then
3303           p_returned_date := l_date;
3304 
3305        elsif l_lf_evt_ocrd_dt < add_months(l_date,l_months) then
3306           p_returned_date := add_months(l_date,l_months);
3307 
3308        elsif l_lf_evt_ocrd_dt < add_months(l_date,(2*l_months)) then
3309           p_returned_date := add_months(l_date,(2*l_months));
3310 
3311        elsif l_lf_evt_ocrd_dt <= l_end_date then
3312           p_returned_date := l_end_date+1;
3313        end if;
3317           p_returned_date := l_start_date;
3314     elsif p_date_cd = 'FDPPQCF' or p_date_cd = 'LFDPPQCF' then
3315        --First of Quarter on or After Event
3316        if l_lf_evt_ocrd_dt = l_start_date then
3318 
3319        elsif l_lf_evt_ocrd_dt <= l_date then
3320           p_returned_date := l_date;
3321        elsif l_lf_evt_ocrd_dt <= add_months(l_date,l_months) then
3322           p_returned_date := add_months(l_date,l_months);
3323 
3324        elsif l_lf_evt_ocrd_dt <= add_months(l_date,(2*l_months)) then
3325           p_returned_date := add_months(l_date,(2*l_months));
3326 
3327        elsif l_lf_evt_ocrd_dt <= l_end_date then
3328           p_returned_date := l_end_date+1;
3329        end if;
3330     elsif p_date_cd = 'AFDCPPQ' then  --First day of current pgm or plan Qtr
3331        if l_lf_evt_ocrd_dt < l_date then
3332           p_returned_date := l_start_date;
3333 
3334        elsif l_lf_evt_ocrd_dt < add_months(l_date,l_months) then
3335           p_returned_date := l_date;
3336 
3337        elsif l_lf_evt_ocrd_dt < add_months(l_date,(2*l_months)) then
3338           p_returned_date := add_months(l_date,(l_months));
3339 
3340        elsif l_lf_evt_ocrd_dt <= l_end_date then
3341           p_returned_date := add_months(l_date,(2*l_months));
3342        end if;
3343 
3344     -- last day of quarters:
3345     elsif p_date_cd = 'ALDCPPQ' or p_date_cd = 'LALDCPPQ' then
3346        --Last Day of the Current Pgm or Plan Qtr
3347        if l_lf_evt_ocrd_dt < l_date then
3348           p_returned_date := l_date-1;
3349 
3350        elsif l_lf_evt_ocrd_dt < add_months(l_date,l_months) then
3351          p_returned_date := add_months(l_date,l_months)-1;
3352 
3353        elsif l_lf_evt_ocrd_dt < add_months(l_date,(2*l_months)) then
3354           p_returned_date := add_months(l_date,(2*l_months))-1;
3355 
3356        elsif l_lf_evt_ocrd_dt <= l_end_date then
3357           p_returned_date := l_end_date;
3358        end if;
3359     elsif p_date_cd = 'ALDPPPQ' or p_date_cd = 'LALDPPPQ' then  -- End of Prev Qtr
3360        if l_lf_evt_ocrd_dt < l_date then
3361           p_returned_date := l_start_date-1;
3362 
3363        elsif l_lf_evt_ocrd_dt < add_months(l_date,l_months) then
3364           p_returned_date := l_date-1;
3365 
3366        elsif l_lf_evt_ocrd_dt < add_months(l_date,(2*l_months)) then
3367           p_returned_date := add_months(l_date,l_months)-1;
3368 
3369        elsif l_lf_evt_ocrd_dt <= l_end_date then
3370           p_returned_date := add_months(l_date,(2*l_months))-1;
3371        end if;
3372 
3373     end if;
3374 
3375   -- SDBED - Sixty days Before Event Date
3376   elsif p_date_cd = 'SDBED' then
3377 
3378   --  hr_utility.set_location('Entering SDBED',10);
3379 
3380     if l_lf_evt_ocrd_dt is null then
3381 
3382        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3383 
3384     else
3385 
3386        l_event_date:= l_lf_evt_ocrd_dt;
3387 
3388     end if;
3389 
3390     p_returned_date := l_event_date - 60;
3391 
3392 
3393   -- -------------------------------------------------------------------
3394   -- First Day of Semi (or Half) Years
3395   -- -------------------------------------------------------------------
3396 
3397   -- eg:  year 1-jan to 31-dec.  a. dt = 1-feb  b. dt=1-jul   c. dt=1-nov
3398   -- AFDCSPPY - First day of current program or plan semi year
3399      -- a. 1-Jan            b. 1-jul        c. 1-jul
3400   -- FDSPPYCF - First Day of Half year On or After Event
3401      -- a. 1-jul            b. 1-jul        c. 1-jan-next
3402   -- LFDPPSYCF - first of half year on or after later of event or notified
3403      -- a. 1-jul            b. 1-jul        c. 1-jan-next
3404   -- LAFDFPPSY - Later: First day of following program or plan semi year
3405      -- a. 1-jul            b. 1-jan-next    c. 1-jan-next
3406   -- AFDFPPSY - First day of following program or plan semi year
3407      -- a. 1-jul            b. 1-jan-next    c. 1-jan-next
3408 
3409   -- -------------------------------------------------------------------
3410   -- Last Day of Semi (or Half) Years
3411   -- -------------------------------------------------------------------
3412   -- ALDCPPSY - Last day of current program or plan semi year
3413      -- a. 30-jun            b. 31-dec       c. 31-dec
3414   -- LALDCPPSY - End of Half Year Later Event or Notified
3415      -- a. 30-jun            b. 31-dec       c. 31-dec
3416   -- ALDPPPSY - Last day of previous program or plan semi year
3417      -- a. 31-dec-prev       b. 31-jun       c. 31-jun
3418   -- LALDPPPSY - Last day of prev pgm or plan semiyear- Later Event or Notified
3419      -- a. 31-dec-prev       b. 31-jun       c. 31-jun
3420 
3421   elsif p_date_cd  = 'LFDPPSYCF' or p_date_cd  = 'FDSPPYCF' or p_date_cd = 'AFDCSPPY'
3422      or p_date_cd  = 'LAFDFPPSY' or p_date_cd = 'AFDFPPSY' or p_date_cd = 'ALDCPPSY'
3423      or p_date_cd = 'LALDCPPSY'  or p_date_cd = 'ALDPPPSY' or p_date_cd = 'LALDPPPSY'
3424      then
3425 
3426   --  hr_utility.set_location('Entering '||p_date_cd,22);
3427 
3428     if l_lf_evt_ocrd_dt is null then
3429        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3430     end if;
3431 
3432     if p_date_cd  = 'LFDPPSYCF' or p_date_cd = 'LAFDFPPSY'  or
3433        p_date_cd = 'LALDCPPSY' or p_date_cd = 'LALDPPPSY' then
3434        -- Use later of event or recorded date
3435        l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3436        if l_lf_evt_ocrd_dt < l_recorded_date then
3437           l_lf_evt_ocrd_dt := l_recorded_date;
3438        end if;
3439     end if;
3440 
3441     get_plan_year
3442            (p_effective_date => p_effective_date
3446            ,p_oipl_id        => l_oipl_id
3443            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3444            ,p_pl_id          => l_pl_id
3445            ,p_pgm_id         => l_pgm_id
3447            ,p_date_cd        => p_date_cd
3448            ,p_comp_obj_mode  => p_comp_obj_mode
3449            ,p_start_date     => l_start_date
3450            ,p_end_date       => l_end_date) ;
3451 
3452     l_months := round(months_between(l_end_date,l_start_date)/2);
3453     l_date := add_months(l_start_date,l_months);  -- half year date.
3454 
3455     --
3456     -- First Day of Semi (or Half) Years:
3457     --
3458     if p_date_cd = 'FDSPPYCF' or p_date_cd = 'LFDPPSYCF' then
3459        --First Day of Half year On or After Event
3460        if l_lf_evt_ocrd_dt = l_start_date then
3461           p_returned_date := l_start_date;
3462        elsif l_lf_evt_ocrd_dt <= l_date then
3463           p_returned_date := l_date;
3464        else
3465           p_returned_date := l_end_date+1;
3466        end if;
3467     elsif p_date_cd = 'LAFDFPPSY' or p_date_cd = 'AFDFPPSY' then
3468        -- First day of following program or plan semi year
3469        if l_lf_evt_ocrd_dt < l_date then
3470           p_returned_date := l_date;
3471        else
3472           p_returned_date := l_end_date+1;
3473        end if;
3474     elsif p_date_cd = 'AFDCSPPY' then
3475        -- First day of current program or plan semi year
3476        if l_lf_evt_ocrd_dt < l_date then
3477           p_returned_date := l_start_date;
3478        else
3479           p_returned_date := l_date;
3480        end if;
3481     --
3482     -- Last Day of Semi (or Half) Years:
3483     --
3484     elsif p_date_cd = 'ALDCPPSY' or p_date_cd = 'LALDCPPSY' then
3485        -- Last day of current program or plan semi year
3486        if l_lf_evt_ocrd_dt < l_date then
3487           p_returned_date := l_date -1;
3488        else
3489           p_returned_date := l_end_date;
3490        end if;
3491     elsif p_date_cd = 'ALDPPPSY' or p_date_cd = 'LALDPPPSY' then
3492         -- Last day of previous program or plan semi year
3493        if l_lf_evt_ocrd_dt < l_date then
3494           p_returned_date := l_start_date -1;
3495        else
3496           p_returned_date := l_date;
3497        end if;
3498 
3499     end if;
3500 
3501   -- ODCED - Dependent Coverage End
3502   elsif p_date_cd  = 'ODCED'  then
3503 
3504   --  hr_utility.set_location('Entering ODCED',10);
3505 
3506     if l_lf_evt_ocrd_dt is null then
3507 
3508        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3509 
3510 
3511     end if;
3512 
3513     open c_elig_dpnt_dts;
3514     fetch c_elig_dpnt_dts into l_start_date,
3515                                l_end_date;
3516 
3517     close c_elig_dpnt_dts;
3518 
3519     p_returned_date:= l_end_date;
3520 
3521   -- ODCSD - Dependent Coverage End
3522 
3523   elsif p_date_cd  = 'ODCSD'  then
3524 
3525   --  hr_utility.set_location('Entering ODCSD',10);
3526 
3527     if l_lf_evt_ocrd_dt is null then
3528 
3529        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3530 
3531     end if;
3532 
3533     open c_elig_dpnt_dts;
3534     fetch c_elig_dpnt_dts into l_start_date,
3535                                l_end_date;
3536 
3537     close c_elig_dpnt_dts;
3538 
3539     p_returned_date:= l_start_date;
3540 
3541   -- AFDECY - First of Calendar year
3542 
3543   elsif p_date_cd  = 'AFDECY'  then
3544 
3545   --  hr_utility.set_location('Entering AFDECY',10);
3546 
3547     if l_lf_evt_ocrd_dt is null then
3548 
3549        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3550 
3551     end if;
3552 
3553     p_returned_date:= trunc(l_lf_evt_ocrd_dt,'YYYY');
3554 
3555   -- 30DANED - 30 Days After Notice to Enroll
3556 
3557   elsif p_date_cd  = '30DANED'  then
3558 
3559   --  hr_utility.set_location('Entering 30DANED',10);
3560 
3561     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3562 
3563     p_returned_date := l_recorded_date + 30;
3564 
3565   -- AFDCMFDFFNM - First of Month,( if From Day(DOB) is First, First of Next Month )
3566   -- Example of the functionality
3567   --Case DOB 08/03/1935 , Event 08/03/2000 , return date should be 08/01/2000
3568   --Case DOB 08/01/1935 , Event 08/03/2000 , return date should be 09/01/2000
3569 
3570   elsif p_date_cd = 'AFDCMFDFFNM' then
3571 
3572   --  hr_utility.set_location('Entering AFDCMFDFFNM',10);
3573    /*Bug 13695553: l_event_date has to be set irrespective of the l_lf_evt_ocrd_dt is null or
3574    not null
3575    if l_lf_evt_ocrd_dt is null then*/
3576 
3577        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3578 
3579 	 --Bug 13695553 end if;
3580 
3581     open c_birth_date;
3582     fetch c_birth_date into l_start_date;
3583     close c_birth_date;
3584     --Bug 1802578
3585     /*
3586 
3587     l_date := last_day(add_months(l_event_date,-1))+1;
3588 
3589     if l_date = l_start_date then
3590 
3591        p_returned_date := add_months(l_date,1);
3592 
3593     else
3594 
3595        p_returned_date := l_date;
3596 
3597     end if;
3598     */
3599     declare
3600       l_day   number := null ;
3601     begin
3602       --
3603       l_day := to_number(to_char(l_start_date, 'DD')) ;
3604       if l_day = 1 then
3605         --
3606         p_returned_date := last_day(l_event_date)+1 ;
3607         --
3608       else
3609         --
3613       --
3610         p_returned_date := last_day(add_months(l_event_date,-1))+1;
3611         --
3612       end if;
3614     end ;
3615       --
3616   --
3617   -- DOD - Date of Determination
3618   --
3619   elsif p_date_cd = 'DOD' then
3620   --
3621   --  hr_utility.set_location('Entering DOD',10);
3622     --
3623     if l_lf_evt_ocrd_dt is null then
3624     --
3625        p_returned_date:= p_effective_date;
3626     --
3627     else
3628     --
3629        p_returned_date:= l_lf_evt_ocrd_dt;
3630     --
3631     end if;
3632     --
3633   --
3634   -- DODM1 - Date of Determination Minus 1 day
3635   --
3636   elsif p_date_cd = 'DODM1' then
3637   --
3638   --  hr_utility.set_location('Entering DODM1',10);
3639     --
3640     if l_lf_evt_ocrd_dt is null then
3641     --
3642        p_returned_date:= p_effective_date - 1;
3643     --
3644     else
3645     --
3646        p_returned_date:= l_lf_evt_ocrd_dt - 1;
3647     --
3648     end if;
3649     --
3650   --
3651   -- FDLMEPPYCF - First Day of Last Month in Event Program or Plan Year
3652   --              Concurrent with or Following
3653   --
3654   elsif p_date_cd  = 'FDLMEPPYCF' then
3655   --
3656   --  hr_utility.set_location('Entering FDLMEPPYCF',10);
3657     --
3658     if l_lf_evt_ocrd_dt is null then
3659     --
3660        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3661     --
3662     end if;
3663     --
3664     get_plan_year
3665            (p_effective_date => p_effective_date
3666            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3667            ,p_pl_id          => l_pl_id
3668            ,p_pgm_id         => l_pgm_id
3669            ,p_oipl_id        => l_oipl_id
3670            ,p_date_cd        => p_date_cd
3671            ,p_comp_obj_mode  => p_comp_obj_mode
3672            ,p_start_date     => l_start_date
3673            ,p_end_date       => l_end_date) ;
3674 
3675     if l_lf_evt_ocrd_dt = last_day(add_months(l_end_date,-1))+1 then
3676     --
3677        p_returned_date := last_day(add_months(l_end_date,-1))+1;
3678     --
3679     else
3680     --
3681        get_next_plan_year
3682                  (p_effective_date => p_effective_date
3683                  ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3684                  ,p_pl_id          => l_pl_id
3685                  ,p_pgm_id         => l_pgm_id
3686                  ,p_oipl_id        => l_oipl_id
3687                  ,p_date_cd        => p_date_cd
3688                  ,p_comp_obj_mode  => p_comp_obj_mode
3689                  ,p_start_date     => l_next_popl_yr_strt
3690                  ,p_end_date       => l_next_popl_yr_end) ;
3691        --
3692        p_returned_date := last_day(add_months(l_end_date,-1))+1;
3693     --
3694     end if;
3695     --
3696   --
3697   -- ALDPPPY - Last Day of previous Program or Plan Year
3698   --
3699   elsif p_date_cd  = 'ALDPPPY' then
3700   --
3701   --  hr_utility.set_location('Entering ALDPPPY',10);
3702     --
3703     if l_lf_evt_ocrd_dt is null then
3704     --
3705        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3706     --
3707     end if;
3708     --
3709     get_plan_year
3710            (p_effective_date => p_effective_date
3711            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3712            ,p_pl_id          => l_pl_id
3713            ,p_pgm_id         => l_pgm_id
3714            ,p_oipl_id        => l_oipl_id
3715            ,p_date_cd        => p_date_cd
3716            ,p_comp_obj_mode  => p_comp_obj_mode
3717            ,p_start_date     => l_start_date
3718            ,p_end_date       => l_end_date) ;
3719 
3720     p_returned_date := l_start_date-1;
3721     --
3722   --
3723   -- ALDLPPEPPY - Last Day Last Pay period of Event Program or plan Year
3724   --
3725   elsif p_date_cd  = 'ALDLPPEPPY' then
3726     --
3727   --  hr_utility.set_location('Entering ALDLPPEPPY',10);
3728     --
3729     if l_lf_evt_ocrd_dt is null then
3730 
3731        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3732 
3733 
3734     end if;
3735     --
3736     get_plan_year
3737            (p_effective_date => p_effective_date
3738            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3739            ,p_pl_id          => l_pl_id
3740            ,p_pgm_id         => l_pgm_id
3741            ,p_oipl_id        => l_oipl_id
3742            ,p_date_cd        => p_date_cd
3743            ,p_comp_obj_mode  => p_comp_obj_mode
3744            ,p_start_date     => l_start_date
3745            ,p_end_date       => l_end_date) ;
3746     --
3747     open c_pay_period_for_date(l_end_date);
3748     fetch c_pay_period_for_date into
3749           l_start_date,
3750           l_end_date;
3751     --
3752     if c_pay_period_for_date%notfound then
3753     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',95);
3754       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
3755       fnd_message.set_token('DATE_CODE',p_date_cd);
3756       fnd_message.set_token('L_PROC',l_proc);
3757       fnd_message.set_token('PERSON_ID',l_person_id);
3758       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
3759       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3760       fnd_message.raise_error;
3761     --
3762     end if;
3763     --
3764     p_returned_date:=l_end_date;
3765     --
3766     close c_pay_period_for_date;
3767   --
3768   -- FDLPPEPPY - First Day Last Pay period of Event Program or plan Year
3769   --
3770   elsif p_date_cd  = 'FDLPPEPPY' then
3771     --
3772   --  hr_utility.set_location('Entering FDLPPEPPY',10);
3776        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3773     --
3774     if l_lf_evt_ocrd_dt is null then
3775     --
3777     --
3778     end if;
3779     --
3780     get_plan_year
3781            (p_effective_date => p_effective_date
3782            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3783            ,p_pl_id          => l_pl_id
3784            ,p_pgm_id         => l_pgm_id
3785            ,p_oipl_id        => l_oipl_id
3786            ,p_date_cd        => p_date_cd
3787            ,p_comp_obj_mode  => p_comp_obj_mode
3788            ,p_start_date     => l_start_date
3789            ,p_end_date       => l_end_date) ;
3790     --
3791     open c_pay_period_for_date(l_end_date);
3792     fetch c_pay_period_for_date into
3793           l_start_date,
3794           l_end_date;
3795     --
3796     if c_pay_period_for_date%notfound then
3797     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',100);
3798       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
3799       fnd_message.set_token('DATE_CODE',p_date_cd);
3800       fnd_message.set_token('L_PROC',l_proc);
3801       fnd_message.set_token('PERSON_ID',l_person_id);
3802       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
3803       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3804       fnd_message.raise_error;
3805     end if;
3806     --
3807     p_returned_date:=l_start_date;
3808     --
3809     close c_pay_period_for_date;
3810     --
3811   --
3812   -- FDLPPEPPYCF - First Day Last Pay period in Year on or after event
3813   --
3814   elsif p_date_cd  = 'FDLPPEPPYCF' then
3815     --
3816   --  hr_utility.set_location('Entering FDLPPEPPYCF',10);
3817     --
3818     if l_lf_evt_ocrd_dt is null then
3819     --
3820        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3821     --
3822     end if;
3823     --
3824     get_plan_year
3825            (p_effective_date => p_effective_date
3826            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
3827            ,p_pl_id          => l_pl_id
3828            ,p_pgm_id         => l_pgm_id
3829            ,p_oipl_id        => l_oipl_id
3830            ,p_date_cd        => p_date_cd
3831            ,p_comp_obj_mode  => p_comp_obj_mode
3832            ,p_start_date     => l_start_date
3833            ,p_end_date       => l_end_date) ;
3834     --
3835     open c_pay_period_for_date(l_end_date);
3836     fetch c_pay_period_for_date into
3837           l_start_date,
3838           l_end_date;
3839     --
3840     if c_pay_period_for_date%notfound then
3841     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',105);
3842       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
3843       fnd_message.set_token('DATE_CODE',p_date_cd);
3844       fnd_message.set_token('L_PROC',l_proc);
3845       fnd_message.set_token('PERSON_ID',l_person_id);
3846       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
3847       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
3848       fnd_message.raise_error;
3849     end if;
3850     --
3851     p_returned_date:=l_start_date;
3852     --
3853     close c_pay_period_for_date;
3854   --
3855   -- ODBED - One day before Event Date
3856   --
3857   elsif p_date_cd =  'ODBED' then
3858     --
3859   --  hr_utility.set_location('Entering ODBED WODBED OR WEM',10);
3860     --
3861     if l_lf_evt_ocrd_dt is null then
3862     --
3863        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3864     --
3865     else
3866        l_event_date:= l_lf_evt_ocrd_dt;
3867     --
3868     end if;
3869     --
3870     p_returned_date:=l_event_date-1;
3871     --
3872   --
3873   -- WEM   - 1 Prior
3874   --
3875   elsif p_date_cd = 'WEM' then
3876     --
3877     if g_debug then
3878       hr_utility.set_location('Entering WEM',10);
3879     end if;
3880     --
3881     if l_lf_evt_ocrd_dt is null then
3882     --
3883        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3884     --
3885     else
3886     --
3887        l_event_date:= l_lf_evt_ocrd_dt;
3888     --
3889     end if;
3890     --
3891     p_returned_date:=nvl(p_start_date,l_event_date -1 ) ;
3892     --
3893   -- WODBED - 1 Prior or One day before event
3894   --
3895   elsif p_date_cd =  'WODBED' then
3896     --
3897     if g_debug then
3898       hr_utility.set_location('Entering WODBED',10);
3899     end if;
3900     --
3901       --
3902       if l_lf_evt_ocrd_dt is null then
3903       --
3904         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3905       --
3906       else
3907       --
3908         l_event_date:= l_lf_evt_ocrd_dt;
3909       --
3910       end if;
3911       --
3912       p_returned_date:=l_event_date-1;
3913       --
3914   -- AFDCM - First day of Current Month
3915   --
3916   elsif p_date_cd = 'AFDCM' then
3917   --
3918   --  hr_utility.set_location('Entering AFDCM',10);
3919     --
3920     if l_lf_evt_ocrd_dt is null then
3921     --
3922        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3923     --
3924     else
3925     --
3926        l_event_date:= l_lf_evt_ocrd_dt;
3927     --
3928     end if;
3929     --
3930     l_date := add_months(l_event_date,-1);
3931     --
3932     p_returned_date := last_day(l_date)+1;
3933     --
3934   --
3935   -- ALDCM - Last day of Current Month
3936   --
3937   elsif p_date_cd = 'ALDCM'  then
3938   --
3939     if g_debug then
3943     if l_lf_evt_ocrd_dt is null then
3940       hr_utility.set_location('Entering ALDCM',10);
3941     end if;
3942     --
3944     --
3945        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3946     --
3947     else
3948     --
3949        l_event_date:= l_lf_evt_ocrd_dt;
3950     --
3951     end if;
3952     --
3953     p_returned_date := last_day(l_event_date);
3954   --
3955   -- WALDCM - 1 Prior or Month End
3956   --
3957   elsif p_date_cd = 'WALDCM' then
3958   --
3959     if g_debug then
3960       hr_utility.set_location('Entering WALDCM',10);
3961     end if;
3962     --
3963       if l_lf_evt_ocrd_dt is null then
3964       --
3965         l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3966       --
3967       else
3968         --
3969         l_event_date:= l_lf_evt_ocrd_dt;
3970         --
3971       end if;
3972       --
3973       p_returned_date := last_day(l_event_date);
3974     --
3975     --
3976   -- ALDFM - Last day of Following Month
3977   --
3978   elsif p_date_cd = 'ALDFM' then
3979   --
3980   --  hr_utility.set_location('Entering ALDFM',10);
3981     --
3982     if l_lf_evt_ocrd_dt is null then
3983     --
3984        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
3985     --
3986     end if;
3987     --
3988     p_returned_date := last_day(add_months(l_lf_evt_ocrd_dt,1));
3989     --
3990   --
3991   -- AEOT - As of End of Time
3992   --
3993   elsif p_date_cd = 'AEOT' then
3994   --
3995   --  hr_utility.set_location('Entering AEOT',10);
3996     --
3997     p_returned_date := to_date('31-12-4712','DD-MM-YYYY');
3998   --
3999   -- A30DFPSD - As of 30 days from the participation start date
4000   --
4001   elsif p_date_cd = 'A30DFPSD' then
4002   --
4003   --  hr_utility.set_location('Entering A30DFPSD',10);
4004     --
4005     p_returned_date := p_start_date+30;
4006   --
4007   -- A45DFPSD - As of 45 days from the participation start date
4008   --
4009   elsif p_date_cd = 'A45DFPSD' then
4010   --
4011   --  hr_utility.set_location('Entering A45DFPSD',10);
4012     --
4013     p_returned_date := p_start_date+45;
4014   --
4015   -- A60DFPSD - As of 60 days from the participation start date
4016   --
4017   elsif p_date_cd = 'A60DFPSD' then
4018   --
4019   --  hr_utility.set_location('Entering A60DFPSD',10);
4020     --
4021     p_returned_date := p_start_date+60;
4022   --
4023   -- A12MFPSD - As of 12 months from the participation start date
4024   --
4025   elsif p_date_cd = 'A12MFPSD' then
4026   --
4027   --  hr_utility.set_location('Entering A12MFPSD',10);
4028     --
4029     p_returned_date := add_months(p_start_date,12);
4030   --
4031   -- A18MFPSD - As of 18 months from the participation start date
4032   --
4033   elsif p_date_cd = 'A18MFPSD' then
4034   --
4035   --  hr_utility.set_location('Entering A18MFPSD',10);
4036     --
4037     p_returned_date := add_months(p_start_date,18);
4038   --
4039   -- A1MFPSD - As of 1 months from the participation start date
4040   --
4041   elsif p_date_cd = 'A1MFPSD' then
4042   --
4043   --  hr_utility.set_location('Entering A1MFPSD',10);
4044     --
4045     p_returned_date := add_months(p_start_date,1);
4046   --
4047   -- A29MFPSD - As of 29 months from the participation start date
4048   --
4049   elsif p_date_cd = 'A29MFPSD' then
4050   --
4051   --  hr_utility.set_location('Entering A29MFPSD',10);
4052     --
4053     p_returned_date := add_months(p_start_date,29);
4054   --
4055   -- A36MFPSD - As of 36 months from the participation start date
4056   --
4057   elsif p_date_cd = 'A36MFPSD' then
4058   --
4059   --  hr_utility.set_location('Entering A36MFPSD',10);
4060     --
4061     p_returned_date := add_months(p_start_date,36);
4062   --
4063   -- As of First Day of Following Month
4064   --
4065   elsif p_date_cd = 'AFDFM' then
4066   --
4067   --  hr_utility.set_location('Entering AFDFM',10);
4068     --
4069     if l_lf_evt_ocrd_dt is null then
4070     --
4071        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4072     --
4073     else
4074     --
4075        l_event_date:= l_lf_evt_ocrd_dt;
4076     --
4077     end if;
4078     --
4079     p_returned_date := last_day(l_event_date)+1;
4080   --
4081   -- As of First Day of Following Month after 15 days
4082   --
4083   elsif p_date_cd = 'AFDFM15' then
4084   --
4085   --  hr_utility.set_location('Entering AFDFM15',10);
4086     --
4087     if l_lf_evt_ocrd_dt is null then
4088     --
4089        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4090     --
4091     else
4092     --
4093        l_event_date:= l_lf_evt_ocrd_dt;
4094     --
4095     end if;
4096     --
4097     p_returned_date := last_day(l_event_date+15)+1;
4098   --
4099   -- ALDCPPY - Last day of current program or plan year
4100   --
4101   elsif p_date_cd  = 'ALDCPPY' then
4102     --
4103   --  hr_utility.set_location('Entering ALDCPPY',10);
4104     --
4105     if l_lf_evt_ocrd_dt is null then
4106     --
4107        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4108     --
4109     end if;
4110     --
4111     get_plan_year
4112            (p_effective_date => p_effective_date
4113            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
4114            ,p_pl_id          => l_pl_id
4115            ,p_pgm_id         => l_pgm_id
4116            ,p_oipl_id        => l_oipl_id
4120            ,p_end_date       => l_end_date) ;
4117            ,p_date_cd        => p_date_cd
4118            ,p_comp_obj_mode  => p_comp_obj_mode
4119            ,p_start_date     => l_start_date
4121     --
4122     p_returned_date :=l_end_date;
4123   --
4124 
4125   -- WALDCPPY - 1 Prior or Year End
4126   --
4127   elsif  p_date_cd = 'WALDCPPY' then
4128     --
4129     if g_debug then
4130       hr_utility.set_location('Entering ALDCPPY',10);
4131     end if;
4132     --
4133       --
4134       if l_lf_evt_ocrd_dt is null then
4135       --
4136         l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4137       --
4138       end if;
4139       --
4140       get_plan_year
4141            (p_effective_date => p_effective_date
4142            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
4143            ,p_pl_id          => l_pl_id
4144            ,p_pgm_id         => l_pgm_id
4145            ,p_oipl_id        => l_oipl_id
4146            ,p_date_cd        => p_date_cd
4147            ,p_comp_obj_mode  => p_comp_obj_mode
4148            ,p_start_date     => l_start_date
4149            ,p_end_date       => l_end_date) ;
4150       --
4151       p_returned_date :=l_end_date;
4152       --
4153   --
4154   -- FDLMPPY - First Day Last Month of current Program or Pl Year
4155   --
4156   elsif p_date_cd  = 'FDLMPPY' then
4157     --
4158   --  hr_utility.set_location('Entering FDLMPPY',10);
4159     --
4160     if l_lf_evt_ocrd_dt is null then
4161     --
4162        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4163     --
4164     end if;
4165     --
4166     get_plan_year
4167            (p_effective_date => p_effective_date
4168            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
4169            ,p_pl_id          => l_pl_id
4170            ,p_pgm_id         => l_pgm_id
4171            ,p_oipl_id        => l_oipl_id
4172            ,p_date_cd        => p_date_cd
4173            ,p_comp_obj_mode  => p_comp_obj_mode
4174            ,p_start_date     => l_start_date
4175            ,p_end_date       => l_end_date) ;
4176     --
4177     l_date := add_months(l_end_date,-1);
4178     p_returned_date := last_day(l_date)+1;
4179   --
4180   -- AFDCPPY - First day of current program or plan year
4181   --
4182   elsif p_date_cd  = 'AFDCPPY' then
4183     --
4184   --  hr_utility.set_location('Entering AFDCPPY',10);
4185     --
4186     if l_lf_evt_ocrd_dt is null then
4187     --
4188        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4189     --
4190     end if;
4191     --
4192     get_plan_year
4193            (p_effective_date => p_effective_date
4194            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
4195            ,p_pl_id          => l_pl_id
4196            ,p_pgm_id         => l_pgm_id
4197            ,p_oipl_id        => l_oipl_id
4198            ,p_date_cd        => p_date_cd
4199            ,p_comp_obj_mode  => p_comp_obj_mode
4200            ,p_start_date     => l_start_date
4201            ,p_end_date       => l_end_date) ;
4202     --
4203     p_returned_date :=l_start_date;
4204 
4205   --
4206   -- AFDFPPY - First day of following program or plan year
4207   --
4208   elsif p_date_cd = 'AFDFPPY' then
4209     --
4210   --  hr_utility.set_location('Entering AFDFPPY',10);
4211     --
4212     if l_lf_evt_ocrd_dt is null then
4213     --
4214        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4215     --
4216     --
4217     end if;
4218     --
4219     get_next_plan_year
4220                  (p_effective_date => p_effective_date
4221                  ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
4222                  ,p_pl_id          => l_pl_id
4223                  ,p_pgm_id         => l_pgm_id
4224                  ,p_oipl_id        => l_oipl_id
4225                  ,p_date_cd        => p_date_cd
4226                  ,p_comp_obj_mode  => p_comp_obj_mode
4227                  ,p_start_date     => l_next_popl_yr_strt
4228                  ,p_end_date       => l_next_popl_yr_end) ;
4229     --
4230     p_returned_date :=l_next_popl_yr_strt;
4231   --
4232   -- AFDCPP - First day of current pay period
4233   --
4234   elsif p_date_cd = 'AFDCPP' then
4235     --
4236   --  hr_utility.set_location('Entering AFDCPP',10);
4237     --
4238     if l_lf_evt_ocrd_dt is null then
4239     --
4240        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4241     --
4242     end if;
4243     --
4244     open c_pay_period;
4245       fetch c_pay_period into l_pay_period;
4246     --
4247     if c_pay_period%notfound then
4248     --
4249       close c_pay_period;
4250     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',110);
4251       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4252       fnd_message.set_token('DATE_CODE',p_date_cd);
4253       fnd_message.set_token('L_PROC',l_proc);
4254       fnd_message.set_token('PERSON_ID',l_person_id);
4255       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4256       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4257       fnd_message.raise_error;
4258     --
4259     end if;
4260     --
4261     p_returned_date := l_pay_period.start_date;
4262     --
4263     close c_pay_period ;
4264   --
4265   -- ALDCPP - Last day of current pay period
4266   --
4267   elsif p_date_cd = 'ALDCPP' then
4268     --
4269     if g_debug then
4270       hr_utility.set_location('Entering ALDCPP',10);
4274     --
4271     end if;
4272     --
4273     if l_lf_evt_ocrd_dt is null then
4275        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4276     --
4277     end if;
4278     --
4279     open c_pay_period(l_assignment_id); ----Bug 8394662
4280     fetch c_pay_period into l_pay_period;
4281     --
4282     if c_pay_period%notfound then
4283       close c_pay_period;
4284     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',115);
4285       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4286       fnd_message.set_token('DATE_CODE',p_date_cd);
4287       fnd_message.set_token('L_PROC',l_proc);
4288       fnd_message.set_token('PERSON_ID',l_person_id);
4289       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4290       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4291       fnd_message.raise_error;
4292     end if;
4293     p_returned_date := l_pay_period.end_date;
4294     close c_pay_period ;
4295   --
4296   -- WALDCPP - 1 Prior or pay period end
4297   --
4298   elsif p_date_cd = 'WALDCPP' then
4299     --
4300     if g_debug then
4301       hr_utility.set_location('Entering WALDCPP',10);
4302     end if;
4303     --
4304       --
4305       if l_lf_evt_ocrd_dt is null then
4306       --
4307         l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4308       --
4309       end if;
4310       --
4311       open c_pay_period;
4312       fetch c_pay_period into l_pay_period;
4313       --
4314       if c_pay_period%notfound then
4315       close c_pay_period;
4316         if g_debug then
4317           hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',115);
4318         end if;
4319         fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4320         fnd_message.set_token('DATE_CODE',p_date_cd);
4321         fnd_message.set_token('L_PROC',l_proc);
4322         fnd_message.set_token('PERSON_ID',l_person_id);
4323         fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4324         fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4325         fnd_message.raise_error;
4326       end if;
4327       --
4328       p_returned_date := l_pay_period.end_date;
4329       close c_pay_period ;
4330     --
4331   --
4332   -- AFDFPP - First day of following pay period
4333   --
4334   elsif p_date_cd = 'AFDFPP' then
4335     --
4336   --  hr_utility.set_location('Entering AFDFPP',10);
4337     --
4338     if l_lf_evt_ocrd_dt is null then
4339     --
4340        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4341     --
4342     end if;
4343     --
4344     open c_next_pay_period(nvl(l_lf_evt_ocrd_dt,p_effective_date),l_assignment_id); ------Bug 8394662
4345     fetch c_next_pay_period into l_next_pay_period;
4346     --
4347     if c_next_pay_period%notfound then
4348       close c_next_pay_period;
4349     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',120);
4350       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4351       fnd_message.set_token('DATE_CODE',p_date_cd);
4352       fnd_message.set_token('PERSON_ID',l_person_id);
4353       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4354       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4355       fnd_message.raise_error;
4356     end if;
4357     close c_next_pay_period;
4358 
4359     p_returned_date := l_next_pay_period.start_date;
4360   --
4361   -- APOCT1 - Prior October 1st
4362   --
4363   elsif p_date_cd = 'APOCT1' then
4364     -- tilak
4365     --
4366     --  hr_utility.set_location('Entering APOCT1',10);
4367     --
4368     if l_lf_evt_ocrd_dt is null then
4369     --
4370        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4371     --
4372     end if;
4373     --
4374     --- whne the le_evt_ocrd_dt is oct 1st it should return previos year october first
4375     --- so when the month is calculated the date is dedcited with 1
4376     l_date   :=  l_lf_evt_ocrd_dt-1 ;
4377     l_months := to_number(to_char(l_date,'MM'))+3;
4378     --
4379     -- subtract 12 if it's oct nov or dec so we dont go farther than 1 yr back.
4380     --
4381     if l_months > 12 then
4382       l_months := l_months - 12;
4383     end if;
4384     --
4385     l_date := add_months(l_date,-l_months);
4386     --
4387     -- Set to first of month of October
4388     --
4389     p_returned_date := last_day(l_date)+1;
4390     if g_debug then
4391       hr_utility.set_location(' APOCT1 date : ' || p_returned_date , 450) ;
4392     end if;
4393   -- tilak
4394 
4395   -- OMFED - One Month Afl_event_date p_date_cd  = 'OMFED' then
4396   --
4397   elsif p_date_cd = 'OMFED' then
4398     --
4399   --  hr_utility.set_location('Entering OMFED',10);
4400     --
4401     if l_lf_evt_ocrd_dt is null then
4402     --
4403        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4404     --
4405     else
4406     --
4407        l_event_date:= l_lf_evt_ocrd_dt;
4408     --
4409     end if;
4410     --
4411     p_returned_date := add_months(l_event_date,1);
4412   --
4413   -- TMFED - Two Months After Event Date
4414   --
4415   elsif p_date_cd  = 'TMFED' then
4416     --
4417   --  hr_utility.set_location('Entering TMFED',10);
4418     --
4419     if l_lf_evt_ocrd_dt is null then
4420     --
4421        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4422     --
4423     else
4424     --
4428     --
4425        l_event_date:= l_lf_evt_ocrd_dt;
4426     --
4427     end if;
4429     p_returned_date := add_months(l_event_date,2);
4430   --
4431   -- 30DFLED - Thirty days from Life Event Date
4432   --
4433   elsif p_date_cd = '30DFLED' then
4434     --
4435   --  hr_utility.set_location('Entering 30DFLED',10);
4436     --
4437     if l_lf_evt_ocrd_dt is null then
4438     --
4439        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4440     --
4441     else
4442     --
4443        l_event_date:= l_lf_evt_ocrd_dt;
4444     --
4445     end if;
4446     --
4447     p_returned_date := l_event_date + 30;
4448   --
4449   -- TDBED - Thirty days before event date
4450   --
4451   elsif p_date_cd = 'TDBED' then
4452     --
4453   --  hr_utility.set_location('Entering TDBED',10);
4454     --
4455     if l_lf_evt_ocrd_dt is null then
4456     --
4457        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4458     --
4459     else
4460     --
4461        l_event_date:= l_lf_evt_ocrd_dt;
4462     --
4463     end if;
4464     --
4465     p_returned_date := l_event_date - 30;
4466   --
4467   -- LTDBED - Later: Thirty days before event date or notified
4468   --
4469   elsif p_date_cd = 'LTDBED' then
4470     --
4471   --  hr_utility.set_location('Entering LTDBED',10);
4472     --
4473     if l_lf_evt_ocrd_dt is null then
4474     --
4475        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4476     --
4477     else
4478     --
4479        l_event_date:= l_lf_evt_ocrd_dt;
4480     --
4481     end if;
4482     --
4483     l_recorded_date := get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4484     --
4485     -- RCHASE Bug Fix, do not subtract 30 days from both.  Evaluate 30 days minus event date
4486 --    if l_recorded_date > l_event_date then
4487     --
4488 --       p_returned_date := l_recorded_date - 30;
4489     --
4490 --    else
4491     --
4492 --       p_returned_date := l_event_date - 30;
4493     --
4494 --    end if;
4495     if l_recorded_date > l_event_date-30 then
4496     --
4497        p_returned_date := l_recorded_date;
4498     --
4499     else
4500     --
4501        p_returned_date := l_event_date - 30;
4502     --
4503     end if;
4504   --
4505   -- SDFED - Sixty days After Event Date
4506   --
4507   elsif p_date_cd = 'SDFED' then
4508     --
4509   --  hr_utility.set_location('Entering SDFED',10);
4510     --
4511     if l_lf_evt_ocrd_dt is null then
4512     --
4513        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4514     --
4515     else
4516     --
4517        l_event_date:= l_lf_evt_ocrd_dt;
4518     --
4519     end if;
4520     --
4521     p_returned_date := l_event_date + 60;
4522     --
4523   --
4524   --
4525   -- LSDBED - Later: Sixty days before Event Date
4526   --
4527   elsif p_date_cd = 'LSDBED' then
4528     --
4529   --  hr_utility.set_location('Entering LSDBED',10);
4530     --
4531     if l_lf_evt_ocrd_dt is null then
4532     --
4533        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4534     --
4535     else
4536     --
4537        l_event_date:= l_lf_evt_ocrd_dt;
4538     --
4539     end if;
4540     --
4541     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4542 
4543     -- RCHASE Bug Fix, do not subtract 30 days from both.  Evaluate 30 days minus event date
4544     --If l_recorded_date > l_event_date then
4545     --
4546     --   p_returned_date := l_recorded_date - 60;
4547     --
4548     --else
4549     --
4550     --   p_returned_date := l_event_date - 60;
4551     --
4552     --end if;
4553     If l_recorded_date > l_event_date-60 then
4554     --
4555        p_returned_date := l_recorded_date;
4556     --
4557     else
4558     --
4559        p_returned_date := l_event_date - 60;
4560     --
4561     end if;
4562   --
4563   -- TODFED - Thirty-one days After Event Date
4564   --
4565   elsif p_date_cd  = 'TODFED' then
4566     --
4567   --  hr_utility.set_location('Entering TODFED',10);
4568     --
4569     if l_lf_evt_ocrd_dt is null then
4570     --
4571        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4572     --
4573     else
4574     --
4575        l_event_date:= l_lf_evt_ocrd_dt;
4576     --
4577     end if;
4578     --
4579     p_returned_date := l_event_date + 31;
4580   --
4581   -- LEPPPED - Later of Enrollment Period End Date and Processing End Date.
4585   --  hr_utility.set_location('Entering LEPPPED',10);
4582   --
4583   elsif p_date_cd = 'LEPPPED' then
4584     --
4586     --
4587     open c_pil_popl;
4588     fetch c_pil_popl into l_enrt_end_dt, l_procg_end_dt;
4589     --
4590     if c_pil_popl%notfound then
4591       close c_pil_popl;
4592     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',81);
4593       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4594       fnd_message.set_token('DATE_CODE',p_date_cd);
4595       fnd_message.set_token('L_PROC',l_proc);
4596       fnd_message.raise_error;
4597     end if;
4598     --
4599     close c_pil_popl;
4600     --
4601     if nvl(l_procg_end_dt,hr_api.g_sot) > nvl(l_enrt_end_dt,hr_api.g_sot) then
4602       l_enrt_end_dt := l_procg_end_dt;
4603     end if;
4604     --
4605     p_returned_date := l_enrt_end_dt;
4606   --
4607   elsif p_date_cd  = '5DBEEPD' then
4608     --
4609     -- 5DBEEPD - 5 Days before the end of the enrollment period end date
4610     --
4611   --  hr_utility.set_location('Entering 5DBEEPD',10);
4612     --
4613     open c_cm_enrt_perd_end_dt;
4614     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4615     if c_cm_enrt_perd_end_dt%notfound then
4616       close c_cm_enrt_perd_end_dt;
4617     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',86);
4618       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4619       fnd_message.set_token('DATE_CODE',p_date_cd);
4620       fnd_message.set_token('L_PROC',l_proc);
4621       fnd_message.raise_error;
4622     end if;
4623     --
4624     close c_cm_enrt_perd_end_dt;
4625     --
4626     p_returned_date := l_cm_date - 5;
4627     --
4628 
4629   elsif p_date_cd  = '10DBEEPD' then
4630     --
4631     -- 10DBEEPD - 10 Days before the end of the enrollment period end date
4632     --
4633   --  hr_utility.set_location('Entering 10DBEEPD',10);
4634     --
4635     open c_cm_enrt_perd_end_dt;
4636     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4637     if c_cm_enrt_perd_end_dt%notfound then
4638       close c_cm_enrt_perd_end_dt;
4639     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',87);
4640       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4641       fnd_message.set_token('DATE_CODE',p_date_cd);
4642       fnd_message.set_token('L_PROC',l_proc);
4643       fnd_message.raise_error;
4644     end if;
4645     --
4646     close c_cm_enrt_perd_end_dt;
4647     --
4648     p_returned_date := l_cm_date - 10;
4649     --
4650   elsif p_date_cd  = '20DBEEPD' then
4651     --
4652     -- 20DBEEPD - 20 Days before the end of the enrollment period end date
4653     --
4654   --  hr_utility.set_location('Entering 20DBEEPD',10);
4655     --
4656     open c_cm_enrt_perd_end_dt;
4657     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4658     if c_cm_enrt_perd_end_dt%notfound then
4659       close c_cm_enrt_perd_end_dt;
4660     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',89);
4661       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4662       fnd_message.set_token('DATE_CODE',p_date_cd);
4663       fnd_message.set_token('L_PROC',l_proc);
4664       fnd_message.raise_error;
4665     end if;
4666     --
4667     close c_cm_enrt_perd_end_dt;
4668     --
4669     p_returned_date := l_cm_date - 20;
4670     --
4671   elsif p_date_cd  = '25DBEEPD' then
4672     --
4673     -- 25DBEEPD - 25 Days before the end of the enrollment period end date
4674     --
4675   --  hr_utility.set_location('Entering 25DBEEPD',10);
4676     --
4677     open c_cm_enrt_perd_end_dt;
4678     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4679     if c_cm_enrt_perd_end_dt%notfound then
4680       close c_cm_enrt_perd_end_dt;
4681     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',90);
4682       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4683       fnd_message.set_token('DATE_CODE',p_date_cd);
4684       fnd_message.set_token('L_PROC',l_proc);
4685       fnd_message.raise_error;
4686     end if;
4687     --
4688     close c_cm_enrt_perd_end_dt;
4689     --
4690     p_returned_date := l_cm_date - 25;
4691     --
4692   elsif p_date_cd  = '30DBEEPD' then
4693     --
4694     -- 30DBEEPD - 30 Days before the end of the enrollment period end date
4695     --
4696   --  hr_utility.set_location('Entering 30DBEEPD',10);
4697     --
4698     open c_cm_enrt_perd_end_dt;
4699     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4700     if c_cm_enrt_perd_end_dt%notfound then
4701       close c_cm_enrt_perd_end_dt;
4702     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',91);
4703       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4704       fnd_message.set_token('DATE_CODE',p_date_cd);
4705       fnd_message.set_token('L_PROC',l_proc);
4706       fnd_message.raise_error;
4707     end if;
4708     --
4709     close c_cm_enrt_perd_end_dt;
4710     --
4711     p_returned_date := l_cm_date - 30;
4712     --
4713 
4714   elsif p_date_cd  = '10DBDAD' then
4715     --
4716     -- 10DBDAD - 10 Days before the default applied date
4717     --
4718   --  hr_utility.set_location('Entering 10DBDAD',10);
4719     --
4720     open c_cm_dflt_asnd_dt;
4721     fetch c_cm_dflt_asnd_dt into l_cm_date;
4722     if c_cm_dflt_asnd_dt%notfound then
4723       close c_cm_dflt_asnd_dt;
4724     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',92);
4725       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4726       fnd_message.set_token('DATE_CODE',p_date_cd);
4727       fnd_message.set_token('L_PROC',l_proc);
4728       fnd_message.raise_error;
4729     end if;
4730     --
4731     close c_cm_dflt_asnd_dt;
4732     --
4733     p_returned_date := l_cm_date - 10;
4734     --
4735   elsif p_date_cd  = '14DBEPD' then
4736     --
4740     --
4737     -- 14DBEPD - 14 Days before the Eligible to Participate Date
4738     --
4739   --  hr_utility.set_location('Entering 14DBEPD',10);
4741     open c_cm_elig_prtn_strt_dt;
4742     fetch c_cm_elig_prtn_strt_dt into l_cm_date;
4743     if c_cm_elig_prtn_strt_dt%notfound then
4744       close c_cm_elig_prtn_strt_dt;
4745     --  hr_utility.set_location('BEN_91386_FIRST_INELIG',81);
4746       fnd_message.set_name('BEN', 'BEN_91386_FIRST_INELIG');
4747       fnd_message.set_token('DATE_CODE',p_date_cd);
4748       fnd_message.set_token('PROC',l_proc);
4749       fnd_message.set_token('PERSON_ID',to_char(p_person_id));
4750       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
4751       fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
4752       fnd_message.raise_error;
4753     end if;
4754     close c_cm_elig_prtn_strt_dt;
4755     --
4756     p_returned_date := l_cm_date - 14;
4757     --
4758   elsif p_date_cd  = '14DBIPD' then
4759     --
4760     -- 14DBIPD - 14 Days before the Ineligible to Participate Date
4761     --
4762     open c_cm_elig_prtn_end_dt;
4763     fetch c_cm_elig_prtn_end_dt into l_cm_date;
4764     if c_cm_elig_prtn_end_dt%notfound then
4765       close c_cm_elig_prtn_end_dt;
4766     --  hr_utility.set_location('BEN_91386_FIRST_INELIG',93);
4767       fnd_message.set_name('BEN', 'BEN_91386_FIRST_INELIG');
4768       fnd_message.set_token('DATE_CODE',p_date_cd);
4769       fnd_message.set_token('PROC',l_proc);
4770       fnd_message.set_token('PERSON_ID',to_char(p_person_id));
4771       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
4772       fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
4773       fnd_message.raise_error;
4774     end if;
4775     close c_cm_elig_prtn_end_dt;
4776     --
4777     p_returned_date := l_cm_date  - 14;
4778   --
4779   elsif p_date_cd  = '15DBEEPD' then
4780     --
4781     -- 15DBEEPD - 15 Days before the end of the enrollment period end date
4782     --
4783   --  hr_utility.set_location('Entering 15DBEEPD',10);
4784     --
4785     open c_cm_enrt_perd_end_dt;
4786     fetch c_cm_enrt_perd_end_dt into l_cm_date;
4787     if c_cm_enrt_perd_end_dt%notfound then
4788       close c_cm_enrt_perd_end_dt;
4789     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',88);
4790       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4791       fnd_message.set_token('DATE_CODE',p_date_cd);
4792       fnd_message.set_token('L_PROC',l_proc);
4793       fnd_message.raise_error;
4794     end if;
4795     --
4796     close c_cm_enrt_perd_end_dt;
4797     --
4798     p_returned_date := l_cm_date - 15;
4799   elsif p_date_cd  = 'OAED' then
4800     --
4801     -- OAED - On the Automatic Enrollment Date.
4802     --
4803   --  hr_utility.set_location('Entering OAED',10);
4804     --
4805     open c_cm_auto_asnd_dt;
4806     fetch c_cm_auto_asnd_dt into l_cm_date;
4807     if c_cm_auto_asnd_dt%notfound then
4808       close c_cm_auto_asnd_dt;
4809     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',98);
4810       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
4811       fnd_message.set_token('DATE_CODE',p_date_cd);
4812       fnd_message.set_token('L_PROC',l_proc);
4813       fnd_message.raise_error;
4814     end if;
4815     close c_cm_auto_asnd_dt;
4816     --
4817     p_returned_date := l_cm_date;
4818     --
4819 
4820   elsif p_date_cd  = 'OCSD' or p_date_cd = 'PECSD' then
4821     --
4822     -- OCSD - On the Coverage Start Date.
4823     --
4824   --  hr_utility.set_location('Entering OCSD',10);
4825     --
4826     open c_prtt_enrt_rslt_dts;
4827     fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
4828                                     l_enrt_cvg_strt_dt,
4829                                     l_enrt_eff_strt_date;
4830     if c_prtt_enrt_rslt_dts%notfound then
4831         --
4832         l_enrt_cvg_strt_dt := p_start_date ;
4833         --
4834         if g_debug then
4835           hr_utility.set_location('OCSD Not found ', 19);
4836         end if;
4837         --
4838     end if;
4839     --
4840     close c_prtt_enrt_rslt_dts;
4841     --
4842     p_returned_date := l_enrt_cvg_strt_dt;
4843     --
4844   --
4845   -- LFDMCF - First of Month on or After Later of Event or Notified
4846   --
4847   elsif p_date_cd  = 'LFDMCF' then
4848     --
4849   --  hr_utility.set_location('Entering LFDMCF',10);
4850     --
4851     if l_lf_evt_ocrd_dt is null then
4852     --
4853        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4854     --
4855     end if;
4856     --
4857     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4858     --
4859     if l_lf_evt_ocrd_dt > l_recorded_date then
4860     --
4861        if l_lf_evt_ocrd_dt <> last_day(add_months(l_lf_evt_ocrd_dt,-1))+1 then
4862        --
4863          p_returned_date := last_day(l_lf_evt_ocrd_dt)+1;
4864        --
4865        else
4866        --
4867          p_returned_date := l_lf_evt_ocrd_dt;
4868        --
4869        end if;
4870     --
4871     else
4872     --
4873        if l_recorded_date <> last_day(add_months(l_recorded_date,-1))+1 then
4874        --
4875          p_returned_date := last_day(l_recorded_date)+1;
4876        --
4877        else
4878        --
4879          p_returned_date := l_recorded_date;
4880        --
4881        end if;
4882     --
4883     end if;
4884     --
4885   --
4886   -- LFDPPCF - First of Pay Period on or After Later of Event or Notified
4887   --
4888   elsif p_date_cd  = 'LFDPPCF' then
4889     --
4890   --  hr_utility.set_location('Entering LFDPPCF',10);
4891     --
4895     --
4892     if l_lf_evt_ocrd_dt is null then
4893     --
4894        l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4896     end if;
4897     --
4898     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
4899     --
4900 
4901     if l_lf_evt_ocrd_dt > l_recorded_date  then
4902 
4903        open c_pay_period_for_date(l_lf_evt_ocrd_dt);
4904        fetch c_pay_period_for_date into
4905           l_start_date,
4906           l_end_date;
4907        --
4908        if c_pay_period_for_date%notfound then
4909        --
4910          close c_pay_period_for_date;
4911        --  hr_utility.set_location('BEN_92380_CANNOT_CALC_LFDPPCF',96);
4912        --  hr_utility.set_location('l_lf_evt_ocrd_dt'||to_char(l_lf_evt_ocrd_dt),96);
4913          fnd_message.set_name('BEN','BEN_92380_CANNOT_CALC_LFDPPCF');
4914          fnd_message.set_token('L_PROC',l_proc);
4915          fnd_message.set_token('PERSON_ID',l_person_id);
4916          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4917          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4918          fnd_message.set_token('LF_EVT_OCRD_DT',l_lf_evt_ocrd_dt);
4919          fnd_message.raise_error;
4920        --
4921        end if;
4922        --
4923        close c_pay_period_for_date;
4924        --
4925        if l_lf_evt_ocrd_dt =  l_start_date then
4926        --
4927           p_returned_date := l_start_date;
4928        --
4929        else
4930        --
4931           open c_next_pay_period(nvl(l_lf_evt_ocrd_dt,p_effective_date));
4932           fetch c_next_pay_period into l_next_pay_period;
4933           --
4934           if c_next_pay_period%notfound then
4935             close c_next_pay_period;
4936           --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',125);
4937             fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4938             fnd_message.set_token('DATE_CODE',p_date_cd);
4939             fnd_message.set_token('PERSON_ID',l_person_id);
4940             fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4941             fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4942             fnd_message.raise_error;
4943           end if;
4944           --
4945           p_returned_date := l_next_pay_period.start_date;
4946           --
4947           close c_next_pay_period;
4948        --
4949        end if;
4950     --
4951     else
4952     --
4953        open c_pay_period_for_date(l_recorded_date);
4954        fetch c_pay_period_for_date into
4955           l_start_date,
4956           l_end_date;
4957        --
4958        if c_pay_period_for_date%notfound then
4959        --
4960          close c_pay_period_for_date;
4961        --  hr_utility.set_location('BEN_92380_CANNOT_CALC_LFDPPCF',97);
4962        --  hr_utility.set_location('l_recorded_date'||to_char(l_recorded_date),97);
4963          fnd_message.set_name('BEN','BEN_92380_CANNOT_CALC_LFDPPCF');
4964          fnd_message.set_token('L_PROC',l_proc);
4965          fnd_message.set_token('PERSON_ID',l_person_id);
4966          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4967          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4968          fnd_message.set_token('LF_EVT_OCRD_DT',l_lf_evt_ocrd_dt);
4969          fnd_message.raise_error;
4970        --
4971        end if;
4972        --
4973        close c_pay_period_for_date;
4974        --
4975        if l_recorded_date =  l_start_date then
4976        --
4977           p_returned_date := l_start_date;
4978        --
4979        else
4980        --
4981           l_lf_evt_ocrd_dt := l_recorded_date;
4982           --
4983           open c_next_pay_period(nvl(l_lf_evt_ocrd_dt,p_effective_date));
4984           fetch c_next_pay_period into l_next_pay_period;
4985           --
4986           if c_next_pay_period%notfound then
4987             close c_next_pay_period;
4988           --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',130);
4989             fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
4990             fnd_message.set_token('DATE_CODE',p_date_cd);
4991             fnd_message.set_token('PERSON_ID',l_person_id);
4992             fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
4993             fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
4994             fnd_message.raise_error;
4995           end if;
4996           --
4997           p_returned_date := l_next_pay_period.start_date;
4998           --
4999           close c_next_pay_period;
5000        --
5001        end if;
5002     --
5003     end if;
5004   --
5005   -- LELD - Latest of Elections, Event or Notified
5006   --
5007   elsif p_date_cd  = 'LELD' then
5008     --
5009   --  hr_utility.set_location('Entering LELD',10);
5010     --
5011     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL) then
5012       hr_utility.set_location('Entering LELD',11);
5013             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
5014 	    fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
5015 	                                    l_enrt_cvg_strt_dt,
5016 	                                    l_enrt_eff_strt_date;
5017 	    --
5018 	    close c_prtt_enrt_rslt_dts_bckdt;
5019 
5020             if l_enrt_eff_strt_date is null then
5021 	                 l_enrt_eff_strt_date:=p_effective_date;
5022 	         end if;
5023 	    p_returned_date := l_enrt_eff_strt_date;
5024     else
5025 	    if l_lf_evt_ocrd_dt is null then
5026 	    --
5027 	       l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5028 	    --
5029 	    end if;
5030 	    --
5031 	    l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5035 					    l_enrt_cvg_strt_dt,
5032 	    --
5033 	    open c_prtt_enrt_rslt_dts;
5034 	    fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
5036 					    l_enrt_eff_strt_date;
5037 	    --
5038 	    if l_enrt_eff_strt_date is null then
5039 	      l_enrt_eff_strt_date:=p_effective_date;
5040 	    end if;
5041 	    --
5042 	    l_cm_date:=l_enrt_eff_strt_date;
5043 	    --
5044 	    close c_prtt_enrt_rslt_dts;
5045 
5046 	    if l_lf_evt_ocrd_dt > l_recorded_date  then
5047 	    --
5048 	       if l_lf_evt_ocrd_dt > l_cm_date then
5049 	       --
5050 		 p_returned_date := l_lf_evt_ocrd_dt;
5051 	       --
5052 	       else
5053 		 -- also for null condition
5054 		 p_returned_date:=l_cm_date;
5055 	       end if;
5056 	    --
5057 	    elsif l_recorded_date > l_cm_date then
5058 	    --
5059 	       p_returned_date := l_recorded_date;
5060 	    --
5061 	    else
5062 	    --
5063 	       p_returned_date := l_cm_date;
5064 	    --
5065 	    end if;
5066      end if;
5067 
5068     --
5069   --
5070   -- LELDED - Later of Elections or Event
5071   --
5072   elsif p_date_cd  = 'LELDED' then
5073     --
5074   --  hr_utility.set_location('Entering LELDED',10);
5075     --
5076     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL) then
5077       hr_utility.set_location('Entering LELDED',11);
5078             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
5079 	    fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
5080 	                                    l_enrt_cvg_strt_dt,
5081 	                                    l_enrt_eff_strt_date;
5082 	    --
5083 	    close c_prtt_enrt_rslt_dts_bckdt;
5084 
5085             if l_enrt_eff_strt_date is null then
5086 	      l_enrt_eff_strt_date:=p_effective_date;
5087 	    end if;
5088              p_returned_date := l_enrt_eff_strt_date;
5089     else
5090 	    if l_lf_evt_ocrd_dt is null then
5091 	    --
5092 	       l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5093 	    --
5094 	    end if;
5095 	    --
5096 	    open c_prtt_enrt_rslt_dts;
5097 	    fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
5098 					    l_enrt_cvg_strt_dt,
5099 					    l_enrt_eff_strt_date;
5100 	    --
5101 	    if l_enrt_eff_strt_date is null then
5102 	      l_enrt_eff_strt_date:=p_effective_date;
5103 	    end if;
5104 	    --
5105 	    l_cm_date:=l_enrt_eff_strt_date;
5106 	    --
5107 	    close c_prtt_enrt_rslt_dts;
5108 	    --
5109 	    if l_lf_evt_ocrd_dt > l_cm_date then
5110 	    --
5111 	      p_returned_date := l_lf_evt_ocrd_dt;
5112 	    --
5113 	    else
5114 	    --
5115 	      p_returned_date := l_cm_date;
5116 	    --
5117 	    end if;
5118    end if;
5119     --
5120   --
5121   -- ODEWM - On the Day Elections Were Made.
5122   --
5123   elsif p_date_cd  = 'ODEWM' then
5124     --
5125     -- should return null if result with current pil
5126     -- is not found, i.e. in benmngle.  gets date at
5127     -- time of enrollment.
5128     --
5129   --  hr_utility.set_location('Entering ODEWM',10);
5130     --
5131      /*Added for Bug 12351605. get the old coverage from backed out pen result. Added if condition */
5132     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL) then
5133       hr_utility.set_location('Entering ODEWM',11);
5134             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
5135 	    fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
5136 	                                    l_enrt_cvg_strt_dt,
5137 	                                    l_enrt_eff_strt_date;
5138 	    --
5139 	    close c_prtt_enrt_rslt_dts_bckdt;
5140 
5141             if l_enrt_eff_strt_date is null then
5142 	      l_enrt_eff_strt_date:=p_effective_date;
5143 	    end if;
5144      else
5145 	    open c_prtt_enrt_rslt_dts;
5146 	    fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
5147 	                                    l_enrt_cvg_strt_dt,
5148 	                                    l_enrt_eff_strt_date;
5149 	    --
5150 	    close c_prtt_enrt_rslt_dts;
5151 	    --
5152 	    if l_enrt_eff_strt_date is null then
5153 	      l_enrt_eff_strt_date:=p_effective_date;
5154 	    end if;
5155     end if;
5156     --
5157     /*if l_enrt_eff_strt_date is null then
5158       l_enrt_eff_strt_date:=p_effective_date;
5159     end if;*/
5160     --
5161     p_returned_date := l_enrt_eff_strt_date;
5162     --
5163     --
5164     -- AFDELD First of Month After Elections Made
5165     --
5166     elsif p_date_cd  = 'AFDELD' then
5167     --
5168       -- should return null if result with current pil
5169       -- is not found, i.e. in benmngle.  gets date at
5170       -- time of enrollment.
5171       --
5172       hr_utility.set_location('Entering AFDELD',10);
5173     --
5174     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL) then
5175       hr_utility.set_location('Entering AFDELD',11);
5176             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
5177 	    fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
5178 	                                    l_enrt_cvg_strt_dt,
5179 	                                    l_enrt_eff_strt_date;
5180 	    --
5181 	    close c_prtt_enrt_rslt_dts_bckdt;
5182 
5183             if l_enrt_eff_strt_date is null then
5184 	      l_enrt_eff_strt_date:=p_effective_date;
5185 	    end if;
5186             p_returned_date := l_enrt_eff_strt_date;
5187     else
5191 					    l_enrt_eff_strt_date;
5188 	    open c_prtt_enrt_rslt_dts;
5189 	    fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
5190 					    l_enrt_cvg_strt_dt,
5192 	    --
5193 	    close c_prtt_enrt_rslt_dts;
5194 
5195 	    hr_utility.set_location('Entering AFDELD ' || l_enrt_eff_strt_date ,10);
5196 	    --
5197 	    -- when the first time cvg calcualted there may not be a result
5198 	    if l_enrt_eff_strt_date is null then
5199 	       l_enrt_eff_strt_date :=p_effective_date;
5200 	    end if;
5201 	    p_returned_date := last_day(l_enrt_eff_strt_date) + 1 ;
5202     end if;
5203     hr_utility.set_location('AFDELD ' ||  p_returned_date ,10);
5204     --
5205     --
5206     -- FDMELD First of Month on or After Elections Made
5207     elsif p_date_cd  = 'FDMELD' then
5208     --
5209       -- should return null if result with current pil
5210       -- is not found, i.e. in benmngle.  gets date at
5211       -- time of enrollment.
5212       --
5213       hr_utility.set_location('Entering FDMELD',10);
5214     --
5215     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL) then
5216       hr_utility.set_location('Entering FDMELD',11);
5217             open c_prtt_enrt_rslt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
5218 	    fetch c_prtt_enrt_rslt_dts_bckdt into l_enrt_cvg_end_dt,
5219 	                                    l_enrt_cvg_strt_dt,
5220 	                                    l_enrt_eff_strt_date;
5221 	    --
5222 	    close c_prtt_enrt_rslt_dts_bckdt;
5223 
5224             if l_enrt_eff_strt_date is null then
5225 	      l_enrt_eff_strt_date:=p_effective_date;
5226 	    end if;
5227             p_returned_date := l_enrt_eff_strt_date;
5228     else
5229 	    open c_prtt_enrt_rslt_dts;
5230 	    fetch c_prtt_enrt_rslt_dts into l_enrt_cvg_end_dt,
5231 					    l_enrt_cvg_strt_dt,
5232 					    l_enrt_eff_strt_date;
5233 	    --
5234 	    close c_prtt_enrt_rslt_dts;
5235 	    --
5236 	    if l_enrt_eff_strt_date is null then
5237 	      l_enrt_eff_strt_date :=p_effective_date;
5238 	    end if ;
5239 	    p_returned_date := trunc( add_months( (l_enrt_eff_strt_date -1 ) ,1) , 'MM') ;
5240    end if;
5241 
5242 
5243   elsif p_date_cd  = 'ODD' then
5244     --
5245     -- ODD - On the De-enrollment Date.
5246     --
5247   --  hr_utility.set_location('Entering ODD',10);
5248     --
5249     p_returned_date := p_effective_date;
5250     --
5251   elsif p_date_cd  = 'ODAD' then
5252     --
5253     -- ODAD - On the Default Applied Date.
5254     --
5255   --  hr_utility.set_location('Entering ODAD',10);
5256     --
5257     open c_cm_dflt_asnd_dt;
5258     fetch c_cm_dflt_asnd_dt into l_cm_date;
5259     if c_cm_dflt_asnd_dt%notfound then
5260       close c_cm_dflt_asnd_dt;
5261     --  hr_utility.set_location('BEN_91942_PEL_NOT_FOUND',96);
5262       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
5263       fnd_message.set_token('DATE_CODE',p_date_cd);
5264       fnd_message.set_token('L_PROC',l_proc);
5265       fnd_message.raise_error;
5266     end if;
5267     close c_cm_dflt_asnd_dt;
5268     --
5269     p_returned_date := l_cm_date;
5270     --
5271   elsif p_date_cd  = 'OEPD' then
5272     --
5273     -- OEPD - On the Eligible to Participate Date.
5274     --
5275   --  hr_utility.set_location('Entering OEPD',10);
5276     --
5277     open c_cm_elig_prtn_strt_dt;
5278     fetch c_cm_elig_prtn_strt_dt into l_cm_date;
5279     if c_cm_elig_prtn_strt_dt%notfound then
5280       close c_cm_elig_prtn_strt_dt;
5281     --  hr_utility.set_location('BEN_92381_ELIG_PER_NOT_FOUND',96);
5282       fnd_message.set_name('BEN', 'BEN_92381_ELIG_PER_NOT_FOUND');
5283       fnd_message.set_token('PROC',l_proc);
5284       fnd_message.set_token('DATE_CODE',p_date_cd);
5285       fnd_message.set_token('PERSON_ID',to_char(p_person_id));
5286       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
5287       fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
5288       fnd_message.raise_error;
5289     end if;
5290     close c_cm_elig_prtn_strt_dt;
5291     --
5292     p_returned_date := l_cm_date;
5293     --
5294   elsif p_date_cd  = 'OIPD' then
5295     --
5296     -- OIPD - On the Ineligible to Participate Date.
5297     --
5298   --  hr_utility.set_location('Entering OIPD',10);
5299     --
5300     open c_cm_elig_prtn_end_dt;
5301     fetch c_cm_elig_prtn_end_dt into l_cm_date;
5302     if c_cm_elig_prtn_end_dt%notfound then
5303       close c_cm_elig_prtn_end_dt;
5304     --  hr_utility.set_location('BEN_92381_ELIG_PER_NOT_FOUND',98);
5305       fnd_message.set_name('BEN', 'BEN_92381_ELIG_PER_NOT_FOUND');
5306       fnd_message.set_token('PROC',l_proc);
5307       fnd_message.set_token('DATE_CODE',p_date_cd);
5308       fnd_message.set_token('PERSON_ID',to_char(p_person_id));
5309       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
5310       fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
5311       fnd_message.raise_error;
5312     end if;
5313     close c_cm_elig_prtn_end_dt;
5314     --
5315     p_returned_date := l_cm_date;
5316     --
5317   elsif p_date_cd  = 'OLDEP' then
5318     --
5319     -- OLDEP - On the last day of the enrollment period.
5320     --
5321   --  hr_utility.set_location('Entering OLDEP',10);
5322     --
5323     open c_cm_enrt_perd_end_dt;
5324     fetch c_cm_enrt_perd_end_dt into l_cm_date;
5325     if c_cm_enrt_perd_end_dt%notfound then
5326       close c_cm_enrt_perd_end_dt;
5327       fnd_message.set_name('BEN', 'BEN_91942_PEL_NOT_FOUND');
5328       fnd_message.set_token('DATE_CODE',p_date_cd);
5332     close c_cm_enrt_perd_end_dt;
5329       fnd_message.set_token('L_PROC',l_proc);
5330       fnd_message.raise_error;
5331     end if;
5333     --
5334     p_returned_date := l_cm_date;
5335     --
5336   elsif p_date_cd  = 'OED' or p_date_cd = 'ENTRBL' or p_date_cd = 'WAENT' or p_date_cd = 'ENTRBLFD' then -- For ICD
5337 
5338     --6823087 -- For CWB (mode = W), if the rate start date code is 'Enterable'
5339               -- we should retrun the rate start date as null
5340 
5341     if p_date_cd = 'ENTRBL' or p_date_cd = 'WAENT' then
5342       ben_env_object.get(p_rec => l_env);
5343 
5344         if nvl(l_env.mode_cd,'~') = 'W' then
5345           p_returned_date := null;
5346         else  -- not CWB
5347           p_returned_date := p_effective_date;
5348         end if;
5349 
5350     else   -- OED
5351     --
5352     -- OED - On the effective date.
5353     --
5354   --  hr_utility.set_location('Entering OED',10);
5355     --
5356     p_returned_date := p_effective_date;
5357   --
5358   -- ODBEFFD - One day before the effective date.
5359   --
5360 
5361     end if;
5362 
5363     --6823087
5364 
5365   elsif p_date_cd  = 'ODBEFFD' then
5366     --
5367   --  hr_utility.set_location('Entering ODBEFFD',10);
5368     --
5369     p_returned_date := p_effective_date-1;
5370     --
5371   --Bug 6212793
5372   elsif p_date_cd  = '10DFED' then
5373       p_returned_date := p_effective_date+10;
5374   elsif p_date_cd  = '20DFED' then
5375       p_returned_date := p_effective_date+20;
5376   elsif p_date_cd  = '30DFED' then
5377       p_returned_date := p_effective_date+30;
5378   ----Bug --Bug 6212793
5379   --
5380   -- FDPPYCF - First Day of Program or Plan Year Concurrent with or Following
5381   --
5382   elsif p_date_cd  = 'FDPPYCF' then
5383   --
5384   --  hr_utility.set_location('Entering FDPPYCF',10);
5385     --
5386     if l_lf_evt_ocrd_dt is null then
5387     --
5388        l_lf_evt_ocrd_dt := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5389     --
5390     end if;
5391     --
5392     get_plan_year
5393            (p_effective_date => p_effective_date
5394            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
5395            ,p_pl_id          => l_pl_id
5396            ,p_pgm_id         => l_pgm_id
5397            ,p_oipl_id        => l_oipl_id
5398            ,p_date_cd        => p_date_cd
5399            ,p_comp_obj_mode  => p_comp_obj_mode
5400            ,p_start_date     => l_start_date
5401            ,p_end_date       => l_end_date) ;
5402     --
5403     if l_start_date = nvl(l_lf_evt_ocrd_dt,p_effective_date) then
5404     --
5405        p_returned_date :=l_start_date;
5406     --
5407     else
5408     --
5409       get_next_plan_year
5410                  (p_effective_date => p_effective_date
5411                  ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
5412                  ,p_pl_id          => l_pl_id
5413                  ,p_pgm_id         => l_pgm_id
5414                  ,p_oipl_id        => l_oipl_id
5415                  ,p_date_cd        => p_date_cd
5416                  ,p_comp_obj_mode  => p_comp_obj_mode
5417                  ,p_start_date     => l_next_popl_yr_strt
5418                  ,p_end_date       => l_next_popl_yr_end) ;
5419        --
5420        p_returned_date :=l_next_popl_yr_strt;
5421     --
5422     end if;
5423   --
5424   -- FDMCF - First Day of Month concurrent with or following
5425   --
5426   elsif p_date_cd  = 'FDMCF' then
5427     --
5428   --  hr_utility.set_location('Entering FDMCF',10);
5429     --
5430     if l_lf_evt_ocrd_dt is null then
5431     --
5432        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5433     --
5434     else
5435     --
5436        l_event_date:= l_lf_evt_ocrd_dt;
5437     --
5438     end if;
5439     --
5440     l_date := add_months(l_event_date,-1);
5441 
5442     if l_event_date = last_day(l_date)+1 then
5443     --
5444        p_returned_date := last_day(l_date)+1;
5445     --
5446     else
5447     --
5448        p_returned_date := last_day(l_event_date)+1;
5449 
5450     --
5451     end if;
5452   --
5453   -- FDPPCF - First day of pay period concurrent with or following
5454   --
5455   elsif p_date_cd = 'FDPPCF' then
5456     --
5457   --  hr_utility.set_location('Entering FDPPCF',10);
5458     --
5459     if l_lf_evt_ocrd_dt is null then
5460     --
5461        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5462        l_lf_evt_ocrd_dt := l_event_date; --9312164
5463     --
5464     else
5465     --
5466        l_event_date:= l_lf_evt_ocrd_dt;
5467     --
5468     end if;
5469     --
5470     open c_pay_period;
5471     fetch c_pay_period into l_pay_period;
5472     if c_pay_period%notfound then
5473       close c_pay_period;
5474     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',135);
5475       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
5476       fnd_message.set_token('DATE_CODE',p_date_cd);
5477       fnd_message.set_token('PERSON_ID',l_person_id);
5478       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
5479       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
5480       fnd_message.raise_error;
5481     end if;
5482     --
5483     close c_pay_period ;
5484     --
5485     if l_event_date =  l_pay_period.start_date then
5486     --
5487        p_returned_date := l_pay_period.start_date;
5488     --
5489     else
5490     --
5491        open c_next_pay_period(nvl(l_lf_evt_ocrd_dt,p_effective_date));
5492        fetch c_next_pay_period into l_next_pay_period;
5493        --
5497          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
5494        if c_next_pay_period%notfound then
5495          close c_next_pay_period;
5496        --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',140);
5498          fnd_message.set_token('DATE_CODE',p_date_cd);
5499          fnd_message.set_token('PERSON_ID',l_person_id);
5500          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
5501          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
5502          fnd_message.raise_error;
5503        end if;
5504        --
5505        p_returned_date := l_next_pay_period.start_date;
5506        --
5507        close c_next_pay_period;
5508     --
5509     end if;
5510   --
5511   -- RL - Rule
5512   --
5513   elsif p_date_cd  = 'RL' then
5514     --
5515   --  hr_utility.set_location('Entering RL',10);
5516     --
5517     open c_asg;
5518     fetch c_asg into l_asg; --if notfound, don't care, will pass null to formula
5519     close c_asg;
5520     --
5521 /* -- 4031733 - Cursor c_state populates l_state variable which is no longer
5522    -- used in the package. Cursor can be commented
5523 
5524    if p_person_id is not null then
5525       open c_state;
5526       fetch c_state into l_state;
5527       close c_state;
5528 
5529       --if l_state.region_2 is not null then
5530 
5531       --  l_jurisdiction_code :=
5532       --    pay_mag_utils.lookup_jurisdiction_code
5533       --      (p_state => l_state.region_2);
5534       --end if;
5535 
5536    end if;
5537 */
5538 
5539    if l_oipl_id is not null then
5540       open c_opt(l_oipl_id);
5541       fetch c_opt into l_opt;
5542       close c_opt;
5543    end if;
5544 
5545    if l_pl_id is not null then
5546      open c_pl_typ(l_pl_id);
5547      fetch c_pl_typ into l_pl_typ_id;
5548      close c_pl_typ;
5549    end if;
5550 
5551     if g_debug then
5552       hr_utility.set_location ('ler_id '||to_char(l_ler_id),70);
5553     end if;
5554    if l_per_in_ler_id is not null then
5555      open c_ler;
5556      fetch c_ler into l_ler_id;
5557      close c_ler;
5558    end if;
5559 
5560     if g_debug then
5561       hr_utility.set_location ('Organization_id 	'||l_asg.organization_id,10);
5562     end if;
5563     if g_debug then
5564       hr_utility.set_location ('assignment_id 	'||l_asg.assignment_id,15);
5565     end if;
5566     if g_debug then
5567       hr_utility.set_location ('Business_group_id '||p_business_group_id,20);
5568     end if;
5569     if g_debug then
5570       hr_utility.set_location ('pgm_id 		'||l_pgm_id,30);
5571     end if;
5572     if g_debug then
5573       hr_utility.set_location ('pl_id 		'||l_pl_id,40);
5574     end if;
5575     if g_debug then
5576       hr_utility.set_location ('pl_typ_id 	'||l_pl_typ_id,50);
5577     end if;
5578     if g_debug then
5579       hr_utility.set_location ('opt_id 		'||l_opt.opt_id,60);
5580     end if;
5581     if g_debug then
5582       hr_utility.set_location ('ler_id 		'||l_ler_id,70);
5583     end if;
5584     if g_debug then
5585       hr_utility.set_location ('p_acty_base_rt_id '||p_acty_base_rt_id,50);
5586     end if;
5587     if g_debug then
5588       hr_utility.set_location ('p_bnfts_bal_id 	'||p_bnfts_bal_id,60);
5589     end if;
5590     if g_debug then
5591       hr_utility.set_location ('jurisdiction_code '||l_jurisdiction_code,70);
5592     end if;
5593 
5594     -- for all other codes LE date is calcualted when the  LE date is null
5595     -- this update does that for  formula too
5596     -- when ever there is a call from ben_newly_ineligible->delete_enrollment->bendetdt.main
5597     --  LE date is null and effectiv date is  le_date -1
5598 
5599     if p_lf_evt_ocrd_dt is  null then
5600        l_rl_lf_evt_ocrd_dt :=  get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5601     else
5602        l_rl_lf_evt_ocrd_dt := p_lf_evt_ocrd_dt ;
5603     end if ;
5604 
5605     -- Call formula initialise routine
5606     -- Added param1 and param1_value parameters to fix bug 1531647
5607 
5608     if g_debug then
5609       hr_utility.set_location ('p_formula_id	'||p_formula_id,1689);
5610     end if;
5611 
5612     l_outputs := benutils.formula
5613       (p_formula_id        => p_formula_id
5614       ,p_effective_date    => nvl(l_rl_lf_evt_ocrd_dt,p_effective_date)
5615       ,p_business_group_id => p_business_group_id
5616       ,p_assignment_id     => l_asg.assignment_id
5617       ,p_organization_id   => l_asg.organization_id
5618       ,p_pgm_id            => l_pgm_id
5619       ,p_pl_id             => l_pl_id
5620       ,p_pl_typ_id         => l_pl_typ_id
5621       ,p_opt_id            => l_opt.opt_id
5622       ,p_ler_id            => l_ler_id
5623       ,p_acty_base_rt_id   => p_acty_base_rt_id
5624       ,p_bnfts_bal_id      => p_bnfts_bal_id
5625       ,p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id
5626  -- Added two more parameters to fix the Bug 1531647
5627       ,p_param1            => p_param1
5628       ,p_param1_value      => p_param1_value
5629       -- FONM
5630       ,p_param2             => 'BEN_IV_RT_STRT_DT'
5631       ,p_param2_value       => fnd_date.date_to_canonical(nvl(p_fonm_rt_strt_dt,ben_manage_life_events.g_fonm_rt_strt_dt))
5632       ,p_param3             => 'BEN_IV_CVG_STRT_DT'
5633       ,p_param3_value       => fnd_date.date_to_canonical(nvl(p_fonm_cvg_strt_dt,ben_manage_life_events.g_fonm_cvg_strt_dt))
5634       ,p_param4             => 'BEN_IV_PERSON_ID'             -- Bug 5331889
5635       ,p_param4_value       => to_char(p_person_id)
5636       ,p_jurisdiction_code => l_jurisdiction_code);
5637     --
5638 
5639     p_returned_date := fnd_date.canonical_to_date(l_outputs(l_outputs.first).value);
5640 
5641     if g_debug then
5645     --
5642      hr_utility.set_location ('p_returned_date='||p_returned_date,1689);
5643     end if;
5644     --
5646     l_ben_disp_ff_warn_msg := get_profile_ff_warn_val();
5647     --
5648     IF l_ben_disp_ff_warn_msg = 'Y'  /* Bug 5088591 */
5649     THEN
5650       -- For Bug#5070692 in Dependent case p_effective_date was passing as NULL
5651       --
5652       if p_effective_date is null then
5653          l_date_temp := nvl(l_rl_lf_evt_ocrd_dt,p_lf_evt_ocrd_dt) ;
5654       end if;
5655       --
5656       validate_rule_cd_date
5657                            ( p_formula_id     => p_formula_id
5658   			    ,p_computed_Date  => p_returned_date
5659   			    ,p_lf_evt_ocrd_dt => l_rl_lf_evt_ocrd_dt
5660   			    ,p_per_in_ler_id  => p_per_in_ler_id
5661   			    ,p_effective_date => l_date_temp
5662   			    ,p_pgm_id         => p_pgm_id
5663   			    ,p_pl_id          => p_pl_id
5664   			    ,p_opt_id         => l_opt.opt_id
5665   			    ,p_person_id      => p_person_id
5666             		   );
5667       --
5668     END IF;
5669     --
5670   --
5671   --
5672   -- LRD - Later of Recorded Date and Event Date
5673   --
5674   elsif p_date_cd  in ( 'LRD' , 'NUMDOEN')  then
5675   --  hr_utility.set_location('Entering LRD',10);
5676 
5677     if l_lf_evt_ocrd_dt is null then
5678        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5679     else
5680        l_event_date:= l_lf_evt_ocrd_dt;
5681     end if;
5682 
5683     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5684 
5685     If l_recorded_date > l_event_date then
5686         p_returned_date:=l_recorded_date;
5687     else
5688         p_returned_date:=l_event_date;
5689     End If;
5690     --
5691   -- notified date
5692   elsif p_date_cd  =  'NUMDON'  then
5693        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5694        if l_recorded_date is null then
5695           if l_lf_evt_ocrd_dt is null then
5696              l_recorded_date := get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5697           else
5698              l_recorded_date := l_lf_evt_ocrd_dt;
5699           end if;
5700        end if ;
5701        p_returned_date:=l_recorded_date;
5702   --
5703   -- LODBED - One day before later of Recorded Date and Event Date
5704   --
5705   elsif p_date_cd in ('LODBED','LWEM') then
5706     --
5707   --  hr_utility.set_location('Entering LODBED OR LWEM',10);
5708     --
5709     if l_lf_evt_ocrd_dt is null then
5710     --
5711        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5712     --
5713     else
5714     --
5715        l_event_date:= l_lf_evt_ocrd_dt;
5716     --
5717     end if;
5718     --
5719     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5720 
5721     If l_recorded_date > l_event_date then
5722         p_returned_date:=l_recorded_date-1;
5723     else
5724         p_returned_date:=l_event_date-1;
5725     End If;
5726     --
5727     if p_date_cd = 'LWEM' and p_start_date > p_returned_date then
5728       --
5729       p_returned_date := p_start_date ;
5730       --
5731     end if;
5732 
5733      --
5734   --
5735   -- LALDCM - End of Month Later Event or Notified
5736   --
5737   elsif p_date_cd = 'LALDCM'  then
5738     --
5739   --  hr_utility.set_location('Entering LALDCM',10);
5740     --
5741     if l_lf_evt_ocrd_dt is null then
5742     --
5743        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5744     --
5745     else
5746     --
5747        l_event_date:= l_lf_evt_ocrd_dt;
5748     --
5749     end if;
5750     --
5751     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5752 
5753     If l_recorded_date > l_event_date then
5754        p_returned_date := last_day(l_recorded_date);
5755     else
5756        p_returned_date := last_day(l_event_date);
5757     End If;
5758   --
5759   -- LALDFM - End of Month After Later Event or Notified
5760   --
5761   elsif p_date_cd = 'LALDFM' then
5762     --
5763   --  hr_utility.set_location('Entering LALDFM',10);
5764     --
5765     if l_lf_evt_ocrd_dt is null then
5766     --
5767        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5768     --
5769     else
5770     --
5771        l_event_date:= l_lf_evt_ocrd_dt;
5772     --
5773     end if;
5774     --
5775     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5776     If l_recorded_date > l_event_date then
5780     End If;
5777        p_returned_date := last_day(add_months(l_recorded_date,1));
5778     else
5779        p_returned_date := last_day(add_months(l_event_date,1));
5781   --
5782   -- LAFDFM - Later: First Day of Following Month
5783   --
5784   elsif p_date_cd = 'LAFDFM' then
5785     --
5786   --  hr_utility.set_location('Entering LAFDFM',10);
5787     --
5788     if l_lf_evt_ocrd_dt is null then
5789     --
5790        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5791     --
5792     else
5793     --
5794        l_event_date:= l_lf_evt_ocrd_dt;
5795     --
5796     end if;
5797     --
5798     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5799     If l_recorded_date > l_event_date then
5800        p_returned_date := last_day(l_recorded_date)+1;
5801     else
5802        p_returned_date := last_day(l_event_date)+1;
5803     End If;
5804  --
5805  -- LALDCPPY - Later: Last day of current program or plan year
5806  --
5807  elsif p_date_cd  = 'LALDCPPY' then
5808    --
5809   --  hr_utility.set_location('Entering LALDCPPY',10);
5810     --
5811     if l_lf_evt_ocrd_dt is null then
5812     --
5813        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5814     --
5815     else
5816     --
5817        l_event_date:= l_lf_evt_ocrd_dt;
5818     --
5819     end if;
5820     --
5821    l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5822 
5823    If l_recorded_date > l_event_date then
5824       l_lf_evt_ocrd_dt := l_recorded_date;
5825    else
5826       l_lf_evt_ocrd_dt  := l_event_date;
5827    End If;
5828 
5829     get_plan_year
5830            (p_effective_date => p_effective_date
5831            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
5832            ,p_pl_id          => l_pl_id
5833            ,p_pgm_id         => l_pgm_id
5834            ,p_oipl_id        => l_oipl_id
5835            ,p_date_cd        => p_date_cd
5836            ,p_comp_obj_mode  => p_comp_obj_mode
5837            ,p_start_date     => l_start_date
5838            ,p_end_date       => l_end_date) ;
5839     --
5840     p_returned_date :=l_end_date;
5841  --
5842  -- LAFDLMEPPY - First of Last Month in Year Later Event or Notified
5843  --
5844  elsif p_date_cd  = 'LAFDLMEPPY' then
5845    --
5846   --  hr_utility.set_location('Entering LAFDLMEPPY',10);
5847     --
5848     if l_lf_evt_ocrd_dt is null then
5849     --
5850        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5851     --
5852     else
5853     --
5854        l_event_date:= l_lf_evt_ocrd_dt;
5855     --
5856     end if;
5857     --
5858    l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5859 
5860    If l_recorded_date > l_event_date then
5861       l_lf_evt_ocrd_dt := l_recorded_date;
5862    else
5863       l_lf_evt_ocrd_dt  := l_event_date;
5864    End If;
5865 
5866     get_plan_year
5867            (p_effective_date => p_effective_date
5868            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
5869            ,p_pl_id          => l_pl_id
5870            ,p_pgm_id         => l_pgm_id
5871            ,p_oipl_id        => l_oipl_id
5872            ,p_date_cd        => p_date_cd
5873            ,p_comp_obj_mode  => p_comp_obj_mode
5874            ,p_start_date     => l_start_date
5875            ,p_end_date       => l_end_date) ;
5876     --
5877     p_returned_date := last_day(add_months(l_end_date,-1))+1;
5878     --
5879  --
5880  -- LALDLPPEPPY - End of Last Pay Period of Event Year Later Event or Notified
5881  --
5882  elsif p_date_cd  = 'LALDLPPEPPY' then
5883    --
5884   --  hr_utility.set_location('Entering LALDLPPEPPY',10);
5885     --
5886     if l_lf_evt_ocrd_dt is null then
5887     --
5888        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5889     --
5890     else
5891     --
5892        l_event_date:= l_lf_evt_ocrd_dt;
5893     --
5894     end if;
5895     --
5896     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5897     --
5898     If l_recorded_date > l_event_date then
5899        l_lf_evt_ocrd_dt := l_recorded_date;
5900     else
5901        l_lf_evt_ocrd_dt  := l_event_date;
5902     End If;
5903     --
5904     open c_pay_period_for_date(l_lf_evt_ocrd_dt);
5905     fetch c_pay_period_for_date into
5906           l_start_date,
5907           l_end_date;
5908     --
5909     if c_pay_period_for_date%notfound then
5910     --
5911       close c_pay_period_for_date;
5912     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',145);
5913       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
5914       fnd_message.set_token('DATE_CODE',p_date_cd);
5915       fnd_message.set_token('PERSON_ID',l_person_id);
5916       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
5917       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
5918       fnd_message.raise_error;
5919     --
5920     end if;
5921     --
5922     close c_pay_period_for_date;
5923     --
5924     p_returned_date := l_end_date;
5925     --
5926   --
5927   -- WALDLPPEPPY - 1 Prior or Last Pay Period End
5928   --
5929   elsif p_date_cd  = 'WALDLPPEPPY' then
5930     --
5931     if g_debug then
5932       hr_utility.set_location('Entering WALDLPPEPPY',10);
5933     end if;
5934     --
5935        if l_lf_evt_ocrd_dt is null then
5936        --
5940        --
5937           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5938        --
5939        else
5941           l_event_date := l_lf_evt_ocrd_dt;
5942        --
5943        end if;
5944        --
5945       --
5946       open c_pre_pay_period(l_event_date);
5947        fetch c_pre_pay_period into l_pre_pay_period;
5948 
5949        --
5950        if c_pre_pay_period%notfound then
5951        --
5952          close c_pre_pay_period;
5953       --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',150);
5954          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
5955          fnd_message.set_token('DATE_CODE',p_date_cd);
5956          fnd_message.set_token('PERSON_ID',l_person_id);
5957          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
5958          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
5959          fnd_message.raise_error;
5960        --
5961        end if;
5962        --
5963 	close c_pre_pay_period;
5964        --
5965 	p_returned_date := l_pre_pay_period.end_date;
5966     --
5967     --
5968   --
5969   -- LODBEWM - 1 Prior New Rate Start or 1 Before Later Event or Notified
5970   --
5971   elsif p_date_cd  = 'LODBEWM' then
5972     --
5973   --  hr_utility.set_location('Entering LODBEWM',10);
5974     --
5975     open c_prtt_rt_val_dts;
5976     --
5977 /*
5978       fetch c_prtt_rt_val_dts into l_start_date,
5979                                    l_end_date;
5980 */
5981     fetch c_prtt_rt_val_dts into l_dummy ;
5982     --
5983     if c_prtt_rt_val_dts%notfound then
5984     --
5985        if l_lf_evt_ocrd_dt is null then
5986        --
5987           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5988        --
5989        end if;
5990        --
5991        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
5992        --
5993        --RCHASE Bug fix logic
5994        --If l_recorded_date > l_event_date then
5995        If l_recorded_date > l_event_date-1 then
5996        --
5997           --RCHASE Bug fix logic
5998           --p_returned_date := l_recorded_date - 1;
5999           p_returned_date := l_recorded_date;
6000        --
6001        else
6002        --
6003           p_returned_date := l_event_date - 1;
6004        --
6005        End If;
6006     --
6007     else
6008     --
6009 /*
6010       open c_enrt_rt_val_dt;
6011       --
6012       fetch c_enrt_rt_val_dt into l_end_date;
6013       if c_enrt_rt_val_dt%found then
6014           --
6015           if g_debug then
6016             hr_utility.set_location('l_end_date - 1',1999);
6017           end if;
6018           p_returned_date := l_end_date - 1;
6019           --
6020       else
6021           --
6022        if l_lf_evt_ocrd_dt is null then
6023        --
6024        if g_debug then
6025          hr_utility.set_location('l_lf_evt_ocrd_dt is null',1999);
6026        end if;
6027        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6028        --
6029        end if;
6030 
6031           p_returned_date := l_event_date - 1;
6032           --
6033       end if;
6034       --
6035       close c_enrt_rt_val_dt ;
6036 */
6037 
6038     --  p_returned_date := p_start_date - 1;
6039         p_returned_date := null ; -- This is handled in rate and coverages call
6040     --
6041     end if;
6042     --
6043     close c_prtt_rt_val_dts;
6044 
6045     --
6046   --
6047   -- ODBEWM - 1 Prior New Rate Start or 1 Day Before Event
6048   --
6049   elsif p_date_cd  = 'ODBEWM' then
6050     --
6051     if g_debug then
6052       hr_utility.set_location('Entering ODBEWM',10);
6053     end if;
6054     --
6055     open c_prtt_rt_val_dts;
6056     --
6057 /*
6058       fetch c_prtt_rt_val_dts into l_start_date,
6059                                    l_end_date;
6060 */
6061       fetch c_prtt_rt_val_dts into l_dummy ;
6062     --
6063     if g_debug then
6064       hr_utility.set_location('l_start_date'||l_start_date , 1999);
6065     end if;
6066     if g_debug then
6067       hr_utility.set_location('l_end_date'||l_end_date , 1999);
6068     end if;
6069 
6070     if c_prtt_rt_val_dts%notfound then
6071     --
6072        if l_lf_evt_ocrd_dt is null then
6073        --
6074        if g_debug then
6075          hr_utility.set_location('l_lf_evt_ocrd_dt is null',1999);
6076        end if;
6077           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6078        --
6079        end if;
6080        --
6081        if g_debug then
6082          hr_utility.set_location('l_event_date - 1',1999);
6083        end if;
6084        p_returned_date := l_event_date - 1;
6085     --
6086     else
6087 /*
6088 
6089       open c_enrt_rt_val_dt;
6090       --
6091       fetch c_enrt_rt_val_dt into l_end_date;
6092       --
6093       if c_enrt_rt_val_dt%found then
6094           --
6095          if g_debug then
6096            hr_utility.set_location('l_end_date - 1',1999);
6097          end if;
6098          p_returned_date := l_end_date - 1;
6099           --
6100       else
6101 
6102        if l_lf_evt_ocrd_dt is null then
6103        --
6104        if g_debug then
6105          hr_utility.set_location('p_lf_evt_ocrd_dt is null',1999);
6106        end if;
6110           if g_debug then
6107        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6108        --
6109        end if;
6111             hr_utility.set_location('l_lf_evt_ocrd_dt else'||l_event_date , 1999);
6112           end if;
6113           p_returned_date := l_event_date - 1;
6114           --
6115       end if;
6116 
6117       -- p_returned_date := l_start_date - 1;
6118       --
6119       close c_enrt_rt_val_dt ;
6120 */
6121    -- p_returned_date := p_start_date - 1;
6122       p_returned_date := null ; -- This is handled in rate and coverages call
6123 
6124     --
6125     end if;
6126     --
6127     close c_prtt_rt_val_dts;
6128     --
6129   --
6130   -- LWODBED - 1 Prior or 1 Day Before Later of Event or Notified
6131   --
6132   elsif p_date_cd  = 'LWODBED' then
6133     --
6134     if g_debug then
6135       hr_utility.set_location('Entering LWODBED',10);
6136     end if;
6137     --
6138        if l_lf_evt_ocrd_dt is null then
6139        --
6140           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6141        --
6142        else
6143        --
6144           l_event_date:= l_lf_evt_ocrd_dt;
6145        --
6146        end if;
6147        --
6148        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6149        --
6150        --RCHASE Bug fix logic
6151        --If l_recorded_date > l_event_date then
6152        If l_recorded_date > l_event_date-1 then
6153        --
6154           --RCHASE Bug fix logic
6155           --p_returned_date := l_recorded_date - 1;
6156           p_returned_date := l_recorded_date;
6157        --
6158        else
6159        --
6160           p_returned_date := l_event_date - 1;
6161        --
6162        End If;
6163     --
6164   --
6165   -- LWALDLPPEPPY - 1 Prior or Later Event or Notified Last Pay Period End
6166   --
6167   elsif p_date_cd  = 'LWALDLPPEPPY' then
6168   --
6169     if g_debug then
6170       hr_utility.set_location('Entering LWALDLPPEPPY',10);
6171     end if;
6172     --
6173        if l_lf_evt_ocrd_dt is null then
6174        --
6175           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6176        --
6177        else
6178        --
6179           l_event_date:= l_lf_evt_ocrd_dt;
6180        --
6181        end if;
6182        --
6183        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6184        --
6185        If l_recorded_date > l_event_date then
6186        --
6187           l_lf_evt_ocrd_dt := l_recorded_date;
6188           --
6189            get_plan_year
6190            (p_effective_date => p_effective_date
6191            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6192            ,p_pl_id          => l_pl_id
6193            ,p_pgm_id         => l_pgm_id
6194            ,p_oipl_id        => l_oipl_id
6195            ,p_date_cd        => p_date_cd
6196            ,p_comp_obj_mode  => p_comp_obj_mode
6197            ,p_start_date     => l_start_date
6198            ,p_end_date       => l_end_date) ;
6199           --
6200           open c_pay_period_for_date(l_end_date);
6201           fetch c_pay_period_for_date into
6202                 l_start_date,
6203                 l_end_date;
6204           --
6205           if c_pay_period_for_date%notfound then
6206           --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',160);
6207             fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6208             fnd_message.set_token('DATE_CODE',p_date_cd);
6209             fnd_message.set_token('PERSON_ID',l_person_id);
6210             fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6211             fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6212             fnd_message.raise_error;
6213           --
6214           end if;
6215           --
6216           close c_pay_period_for_date;
6217           --
6218           p_returned_date := l_end_date;
6219        --
6220        else
6221        --
6222           l_lf_evt_ocrd_dt := l_event_date;
6223           --
6224           get_plan_year
6225            (p_effective_date => p_effective_date
6226            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6227            ,p_pl_id          => l_pl_id
6228            ,p_pgm_id         => l_pgm_id
6229            ,p_oipl_id        => l_oipl_id
6230            ,p_date_cd        => p_date_cd
6231            ,p_comp_obj_mode  => p_comp_obj_mode
6232            ,p_start_date     => l_start_date
6233            ,p_end_date       => l_end_date) ;
6234           --
6235           open c_pay_period_for_date(l_end_date);
6236           fetch c_pay_period_for_date into
6237                 l_start_date,
6238                 l_end_date;
6239           --
6240           if c_pay_period_for_date%notfound then
6241           --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',165);
6242             fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6243             fnd_message.set_token('DATE_CODE',p_date_cd);
6244             fnd_message.set_token('PERSON_ID',l_person_id);
6245             fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6246             fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6247             fnd_message.raise_error;
6248           --
6249           end if;
6250           --
6251           close c_pay_period_for_date;
6252           --
6253           p_returned_date := l_end_date;
6254        --
6255        End If;
6256     --
6257   --
6258   -- LWALDCPPY - 1 Prior or Later Event or Notified Year End
6259   --
6260   elsif p_date_cd  = 'LWALDCPPY' then
6261   --
6262     if g_debug then
6266        if l_lf_evt_ocrd_dt is null then
6263       hr_utility.set_location('Entering LWALDCPPY',10);
6264     end if;
6265     --
6267        --
6268           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6269        --
6270        else
6271        --
6272           l_event_date:= l_lf_evt_ocrd_dt;
6273        --
6274        end if;
6275        --
6276        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6277        --
6278        If l_recorded_date > l_event_date then
6279        --
6280           l_lf_evt_ocrd_dt := l_recorded_date;
6281           --
6282           get_plan_year
6283            (p_effective_date => p_effective_date
6284            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6285            ,p_pl_id          => l_pl_id
6286            ,p_pgm_id         => l_pgm_id
6287            ,p_oipl_id        => l_oipl_id
6288            ,p_date_cd        => p_date_cd
6289            ,p_comp_obj_mode  => p_comp_obj_mode
6290            ,p_start_date     => l_start_date
6291            ,p_end_date       => l_end_date) ;
6292           --
6293           p_returned_date := l_end_date;
6294        --
6295        else
6296        --
6297           l_lf_evt_ocrd_dt := l_event_date;
6298           --
6299            get_plan_year
6300            (p_effective_date => p_effective_date
6301            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6302            ,p_pl_id          => l_pl_id
6303            ,p_pgm_id         => l_pgm_id
6304            ,p_oipl_id        => l_oipl_id
6305            ,p_date_cd        => p_date_cd
6306            ,p_comp_obj_mode  => p_comp_obj_mode
6307            ,p_start_date     => l_start_date
6308            ,p_end_date       => l_end_date) ;
6309           --
6310           p_returned_date := l_end_date;
6311        --
6312        End If;
6313     --
6314   --
6315   -- LWALDCPP - 1 Prior or Later Event or Notified Pay Period End
6316   --
6317   elsif p_date_cd  = 'LWALDCPP' then
6318   --
6319     if g_debug then
6320       hr_utility.set_location('Entering LWALDCPP',10);
6321     end if;
6322     --
6323        if l_lf_evt_ocrd_dt is null then
6324        --
6325           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6326        --
6327        else
6328        --
6329           l_event_date:= l_lf_evt_ocrd_dt;
6330        --
6331        end if;
6332        --
6333        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6334        --
6335        If l_recorded_date > l_event_date then
6336        --
6337           open c_pay_period_for_date(l_recorded_date);
6338           fetch c_pay_period_for_date into
6339              l_start_date,
6340              l_end_date;
6341           close c_pay_period_for_date;
6342           --
6343           p_returned_date := l_end_date;
6344        --
6345        else
6346        --
6347           open c_pay_period_for_date(l_event_date);
6348           fetch c_pay_period_for_date into
6349              l_start_date,
6350              l_end_date;
6351           close c_pay_period_for_date;
6352           --
6353           p_returned_date := l_end_date;
6354        --
6355        End If;
6356     --
6357   --
6358   -- LWALDCM - 1 Prior or Later Event or Notified Month End
6359   --
6360   elsif p_date_cd  = 'LWALDCM' then
6361     --
6362     if g_debug then
6363       hr_utility.set_location('Entering LWALDCM',10);
6364     end if;
6365     --
6366        if l_lf_evt_ocrd_dt is null then
6367        --
6368           l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6369        --
6370        else
6371        --
6372           l_event_date:= l_lf_evt_ocrd_dt;
6373        --
6374        end if;
6375        --
6376        l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6377        --
6378        If l_recorded_date > l_event_date then
6379        --
6380           p_returned_date := last_day(l_recorded_date);
6381        --
6382        else
6383        --
6384           p_returned_date := last_day(l_event_date);
6385        --
6386        End If;
6387     --
6388   --
6389   -- LFDPPYCF - First of Year On or After Later of Event or Notified
6390   --
6391   elsif p_date_cd  = 'LFDPPYCF' then
6392   --
6393   --  hr_utility.set_location('Entering LFDPPYCF',10);
6394     --
6395     if l_lf_evt_ocrd_dt is null then
6396     --
6397        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6398     --
6399     else
6400     --
6401        l_event_date:= l_lf_evt_ocrd_dt;
6402     --
6403     end if;
6404     --
6405     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6406 
6407     If l_recorded_date > l_event_date then
6408        l_lf_evt_ocrd_dt := l_recorded_date;
6409     else
6410        l_lf_evt_ocrd_dt  := l_event_date;
6411     End If;
6412 
6413     get_plan_year
6414            (p_effective_date => p_effective_date
6415            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6416            ,p_pl_id          => l_pl_id
6417            ,p_pgm_id         => l_pgm_id
6418            ,p_oipl_id        => l_oipl_id
6419            ,p_date_cd        => p_date_cd
6420            ,p_comp_obj_mode  => p_comp_obj_mode
6421            ,p_start_date     => l_start_date
6422            ,p_end_date       => l_end_date) ;
6423     --
6424     if l_lf_evt_ocrd_dt = l_start_date then
6425     --
6426       p_returned_date :=l_start_date;
6427     --
6428     else
6429     --
6433                  ,p_pl_id          => l_pl_id
6430       get_next_plan_year
6431                  (p_effective_date => p_effective_date
6432                  ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6434                  ,p_pgm_id         => l_pgm_id
6435                  ,p_oipl_id        => l_oipl_id
6436                  ,p_date_cd        => p_date_cd
6437                  ,p_comp_obj_mode  => p_comp_obj_mode
6438                  ,p_start_date     => l_next_popl_yr_strt
6439                  ,p_end_date       => l_next_popl_yr_end) ;
6440       --
6441       p_returned_date :=l_next_popl_yr_strt;
6442     --
6443     end if;
6444     --
6445   --
6446   -- LAFDCPPY - Later: First day of current program or plan year
6447   --
6448   elsif p_date_cd  = 'LAFDCPPY' then
6449   --
6450   --  hr_utility.set_location('Entering LAFDCPPY',10);
6451     --
6452     if l_lf_evt_ocrd_dt is null then
6453     --
6454        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6455     --
6456     else
6457     --
6458        l_event_date:= l_lf_evt_ocrd_dt;
6459     --
6460     end if;
6461     --
6462     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6463 
6464     If l_recorded_date > l_event_date then
6465        l_lf_evt_ocrd_dt := l_recorded_date;
6466     else
6467        l_lf_evt_ocrd_dt  := l_event_date;
6468     End If;
6469 
6470     get_plan_year
6471            (p_effective_date => p_effective_date
6472            ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6473            ,p_pl_id          => l_pl_id
6474            ,p_pgm_id         => l_pgm_id
6475            ,p_oipl_id        => l_oipl_id
6476            ,p_date_cd        => p_date_cd
6477            ,p_comp_obj_mode  => p_comp_obj_mode
6478            ,p_start_date     => l_start_date
6479            ,p_end_date       => l_end_date) ;
6480     --
6481     p_returned_date :=l_start_date;
6482   --
6483   -- LAFDFPPY - Later: First day of following program or plan year
6484   --
6485   elsif p_date_cd = 'LAFDFPPY' then
6486     --
6487   --  hr_utility.set_location('Entering LAFDFPPY',10);
6488     --
6489     if l_lf_evt_ocrd_dt is null then
6490     --
6491        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6492     --
6493     else
6494     --
6495        l_event_date:= l_lf_evt_ocrd_dt;
6496     --
6497     end if;
6498     --
6499     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6500 
6501     If l_recorded_date > l_event_date then
6502        l_lf_evt_ocrd_dt := l_recorded_date;
6503     else
6504        l_lf_evt_ocrd_dt  := l_event_date;
6505     End If;
6506 
6507     get_next_plan_year
6508                  (p_effective_date => p_effective_date
6509                  ,p_lf_evt_ocrd_dt => l_lf_evt_ocrd_dt
6510                  ,p_pl_id          => l_pl_id
6511                  ,p_pgm_id         => l_pgm_id
6512                  ,p_oipl_id        => l_oipl_id
6513                  ,p_date_cd        => p_date_cd
6514                  ,p_comp_obj_mode  => p_comp_obj_mode
6515                  ,p_start_date     => l_next_popl_yr_strt
6516                  ,p_end_date       => l_next_popl_yr_end) ;
6517     --
6518     p_returned_date :=l_next_popl_yr_strt;
6519   --
6520   -- LALDCPP - Later: Last day of current pay period
6521   --
6522   elsif p_date_cd = 'LALDCPP' then
6523     --
6524   --  hr_utility.set_location('Entering LALDCPP',10);
6525     --
6526     if l_lf_evt_ocrd_dt is null then
6527     --
6528        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6529     --
6530     else
6531     --
6532        l_event_date:= l_lf_evt_ocrd_dt;
6533     --
6534     end if;
6535     --
6536     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6537 
6538     If l_recorded_date > l_event_date then
6539        l_lf_evt_ocrd_dt := l_recorded_date;
6540     else
6541        l_lf_evt_ocrd_dt  := l_event_date;
6542     End If;
6543 
6544     open c_pay_period;
6545     fetch c_pay_period into l_pay_period;
6546     if c_pay_period%notfound then
6547       close c_pay_period;
6548     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',170);
6549       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6550       fnd_message.set_token('DATE_CODE',p_date_cd);
6551       fnd_message.set_token('PERSON_ID',l_person_id);
6552       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6553       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6554       fnd_message.raise_error;
6555     end if;
6556     p_returned_date := l_pay_period.end_date;
6557     close c_pay_period ;
6558   --
6559   --
6560   -- LAFDFPP - Later: First day of following pay period
6561   --
6562   elsif p_date_cd = 'LAFDFPP' then
6563     --
6564   --  hr_utility.set_location('Entering LAFDFPP',10);
6565     --
6566     if l_lf_evt_ocrd_dt is null then
6567     --
6568        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6569     --
6570     else
6571     --
6572        l_event_date:= l_lf_evt_ocrd_dt;
6573     --
6574     end if;
6575     --
6576     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6577 
6578     If l_recorded_date > l_event_date then
6579        l_lf_evt_ocrd_dt := l_recorded_date;
6580     else
6581        l_lf_evt_ocrd_dt  := l_event_date;
6582     End If;
6583 
6584     open c_next_pay_period(nvl(l_lf_evt_ocrd_dt,p_effective_date));
6585     fetch c_next_pay_period into l_next_pay_period;
6586     --
6587     if c_next_pay_period%notfound then
6591       fnd_message.set_token('DATE_CODE',p_date_cd);
6588       close c_next_pay_period;
6589     --  hr_utility.set_location('BEN_91477_PAY_PERIOD_MISSING',170);
6590       fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6592       fnd_message.set_token('PERSON_ID',l_person_id);
6593       fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6594       fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6595       fnd_message.raise_error;
6596     end if;
6597     p_returned_date := l_next_pay_period.start_date;
6598     close c_next_pay_period;
6599   --
6600   -- LTODFED - Thirty-one days After Later of Recorded Date and Event Date
6601   --
6602   elsif p_date_cd  = 'LTODFED' then
6603     --
6604   --  hr_utility.set_location('Entering LTODFED',10);
6605     --
6606     if l_lf_evt_ocrd_dt is null then
6607     --
6608        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6609     --
6610     else
6611     --
6612        l_event_date:= l_lf_evt_ocrd_dt;
6613     --
6614     end if;
6615     --
6616     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6617     If l_recorded_date > l_event_date then
6618        p_returned_date := l_recorded_date + 31;
6619     else
6620        p_returned_date := l_event_date + 31;
6621     End If;
6622   --
6623   -- LSDFED - Sixty days After Later of Recorded Date and Event Date
6624   --
6625   elsif p_date_cd  = 'LSDFED' then
6626     --
6627   --  hr_utility.set_location('Entering LSDFED',10);
6628     --
6629     if l_lf_evt_ocrd_dt is null then
6630     --
6631        l_event_date:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6632     --
6633     else
6634     --
6635        l_event_date:= l_lf_evt_ocrd_dt;
6636 
6637     end if;
6638 
6639     l_recorded_date:= get_recorded_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6640 
6641     If l_recorded_date > l_event_date then
6642        p_returned_date := l_recorded_date + 60;
6643     else
6644        p_returned_date := l_event_date + 60;
6645     End If;
6646   elsif p_date_cd = 'NA' then
6647        -- Not Applicable
6648        p_returned_date := null ;
6649 
6650     --- date related to hire dates
6651  elsif p_date_cd in ( '30DAHRD','31DAHRD','60DAHRD','61DAHRD') then
6652 
6653        -- get the latest hire date, if fails error
6654        if g_debug then
6655          hr_utility.set_location(' Hire date '  , 99 );
6656        end if;
6657        open c_pps ;
6658        fetch c_pps into l_hire_date ;
6659        close c_pps ;
6660        if g_debug then
6661          hr_utility.set_location(' Hire date ' || l_hire_date, 99 );
6662        end if;
6663        if  l_hire_date is null then
6664            fnd_message.set_name('BEN','BEN_92489_CANNOT_CALC_DATE');
6665            fnd_message.set_token('DATE_CODE',p_date_cd);
6666            fnd_message.set_token('L_PROC',l_proc);
6667            fnd_message.raise_error;
6668        end if ;
6669        if g_debug then
6670          hr_utility.set_location(' Hire date ' || l_hire_date, 99 );
6671        end if;
6672 
6673        if p_date_cd = '30DAHRD' then
6674           p_returned_date := l_hire_date + 30 ;
6675        elsif p_date_cd = '31DAHRD' then
6676           p_returned_date := l_hire_date + 31 ;
6677        elsif p_date_cd = '60DAHRD' then
6678           p_returned_date := l_hire_date + 60 ;
6679        elsif p_date_cd = '61DAHRD' then
6680           p_returned_date := l_hire_date + 61 ;
6681        end if ;
6682         if g_debug then
6683           hr_utility.set_location(' p_date_cd  ' || p_returned_date, 99 );
6684         end if;
6685 
6686   elsif p_date_cd in ('AFDELY','ALDELMY','FDM','FDMCFC','FDMFC',
6687                       'FDPP','FDPPQCFC','FDPPQFC','FDPPSYCFC','FDPPSYFC',                      'FDPPYCFC','FDPPYFC','FDQ','FFDFED','FFDFEPS',
6688                       'FDPPY','LDPPFEE','LDPPOAEE','LWALDCPPQ','LWALDPPSY',
6689                       'NDFEPS','WALDCPPQ','WALDCPPSY','FDCY','FFDFEPS',
6690                       'FDLY','FDQ','FDSY', 'LFSEMES'
6691                      ) then
6692 
6693    --  hr_utility.set_location('Future Date Code:  '||p_date_cd , 222);
6694      fnd_message.set_name('BEN','FUTURE_DATE_CD_DO_NOT_USE');
6695      fnd_message.set_token('DATE_CODE',p_date_cd);
6696      fnd_message.raise_error;
6697 
6698    elsif p_date_cd in ('FDPPFCDE','FDPPFCDEL') then
6699      --
6700      if g_debug then
6701          hr_utility.set_location(' Step 2 ' ,181);
6702      end if;
6703      --
6704      if p_date_cd = 'FDPPFCDE' then
6705        --
6706        if l_lf_evt_ocrd_dt is null then
6707          l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6708        end if;
6709        l_start_date := l_lf_evt_ocrd_dt;
6710      else
6711        --
6712        hr_utility.set_location('p effective date '||p_effective_date,182);
6713        l_start_date := p_effective_date;
6714      end if;
6715      --
6716      open c_pay_period_for_check(l_start_date, 'E');
6717      fetch c_pay_period_for_check into l_start_date;
6718      if c_pay_period_for_check%notfound then
6719        --
6720        close c_pay_period_for_check;
6721        open c_pay_period_for_check(l_start_date, 'B');
6722        fetch c_pay_period_for_check into l_start_date;
6723        if c_pay_period_for_check%notfound then
6724          --
6725          close c_pay_period_for_check;
6726          --
6727          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6728          fnd_message.set_token('DATE_CODE',p_date_cd);
6729          fnd_message.set_token('L_PROC',l_proc);
6730          fnd_message.set_token('PERSON_ID',l_person_id);
6731          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6735        end if;
6732          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6733          fnd_message.raise_error;
6734          --
6736      else
6737        --  rehire and new hire validation
6738        open c_hire_date;
6739        fetch c_hire_date into l_hire_date;
6740        close c_hire_date;
6741        --
6742        if l_hire_date > l_start_date then
6743          --
6744          l_start_date := l_hire_date;
6745          --
6746        end if;
6747        --
6748      end if;
6749      --
6750      close c_pay_period_for_check;
6751      p_returned_date := l_start_date;
6752 
6753    elsif p_date_cd in ('WAPPCDE','WAPPDEL') then
6754      --
6755      if g_debug then
6756          hr_utility.set_location(' Step 2 ' ,181);
6757      end if;
6758      --
6759      if p_date_cd = 'WAPPCDE' then
6760        --
6761        if l_lf_evt_ocrd_dt is null then
6762          l_lf_evt_ocrd_dt:= get_event_date(p_cache_mode,l_per_in_ler_id,p_effective_date);
6763        end if;
6764        l_end_date := l_lf_evt_ocrd_dt;
6765      else
6766        --
6767        l_end_date := p_effective_date;
6768      end if;
6769      --
6770      open c_pay_period_for_check_end (l_end_date, 'E');
6771      fetch c_pay_period_for_check_end  into l_end_date;
6772      if c_pay_period_for_check_end %notfound then
6773        --
6774        close c_pay_period_for_check_end ;
6775        open c_pay_period_for_check_end (l_end_date, 'B');
6776        fetch c_pay_period_for_check_end  into l_end_date;
6777        if c_pay_period_for_check_end %notfound then
6778          --
6779          close c_pay_period_for_check_end ;
6780          --
6781          fnd_message.set_name('BEN','BEN_91477_PAY_PERIOD_MISSING');
6782          fnd_message.set_token('DATE_CODE',p_date_cd);
6783          fnd_message.set_token('L_PROC',l_proc);
6784          fnd_message.set_token('PERSON_ID',l_person_id);
6785          fnd_message.set_token('BUSINESS_GROUP_ID',l_business_group_id);
6786          fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
6787          fnd_message.raise_error;
6788          --
6789        end if;
6790      end if;
6791      --
6792      close c_pay_period_for_check_end ;
6793      p_returned_date := l_end_date;
6794   else
6795 
6796      hr_utility.set_location('Unknown Date Code:  '||p_date_cd , 222);
6797      fnd_message.set_name('BEN','BEN_91534_BEN_UNKNOWN_DATE_CD');
6798      fnd_message.set_token('DATE_CODE',p_date_cd);
6799      fnd_message.set_token('L_PROC',l_proc);
6800      fnd_message.raise_error;
6801 
6802   end  if;
6803   --
6804   if g_debug then
6805     hr_utility.set_location('p_returned_date: '||p_returned_date,15);
6806   end if;
6807   p_returned_date := trunc(p_returned_date);
6808   --
6809   if g_debug then
6810     hr_utility.set_location('sent dt code ' || p_date_cd ,596);
6811   end if;
6812   if g_debug then
6813     hr_utility.set_location('sent_dt p_returned_date: '||p_returned_date,15);
6814   end if;
6815   if g_debug then
6816     hr_utility.set_location('Leaving : '||l_proc , 20);
6817   end if;
6818 exception   -- nocopy changes
6819   --
6820   when others then
6821     --
6822     p_returned_date := null;
6823     raise;
6824     --
6825 end main;
6826 --
6827 -- Procedure Name
6828 --    Rate and Coverage Dates
6829 -- Purpose
6830 --    This procedure is used to determine the (rate or coverage) (start or end)
6831 --    date, code, and rule.  It calls ben_determine_date if the absolute date
6832 --    is needed.
6833 --
6834 procedure rate_and_coverage_dates
6835   (p_cache_mode             in     boolean default false
6836   --
6837   -- Cache related parameters
6838   --
6839   ,p_pgm_row                in     ben_cobj_cache.g_pgm_inst_row
6840   := ben_cobj_cache.g_pgm_default_row
6841   ,p_ptip_row               in     ben_cobj_cache.g_ptip_inst_row
6842   := ben_cobj_cache.g_ptip_default_row
6843   ,p_plip_row               in     ben_cobj_cache.g_plip_inst_row
6844   := ben_cobj_cache.g_plip_default_row
6845   ,p_pl_row                 in     ben_cobj_cache.g_pl_inst_row
6846   := ben_cobj_cache.g_pl_default_row
6847   --
6848   ,p_per_in_ler_id          in     number  default null
6849   ,p_person_id              in     number  default null
6850   ,p_pgm_id                 in     number  default null
6851   ,p_pl_id                  in     number  default null
6852   ,p_oipl_id                in     number  default null
6853   ,p_par_ptip_id            in     number  default null
6854   ,p_par_plip_id            in     number  default null
6855   ,p_lee_rsn_id             in     number  default null
6856   ,p_enrt_perd_id           in     number  default null
6857   ,p_enrt_perd_for_pl_id    in     number  default null
6858   --
6859              -- which dates is R for rate, C for coverage, B for both
6860   ,p_which_dates_cd         in     varchar2      default 'B'
6861              -- will error if Y and an absolute date not found
6862              --   Note: codes must allways be found.
6863   ,p_date_mandatory_flag    in     varchar2      default 'Y'
6864              -- compute_dates_flag is Y for compute dates, N for Don't
6865   ,p_compute_dates_flag     in     varchar2      default 'Y'
6866              --
6867              -- optional for everything
6868              --
6869   ,p_elig_per_elctbl_chc_id in     number  default null
6870   ,p_acty_base_rt_id        in     number  default null
6871   ,p_business_group_id      in     number
6872   ,p_start_date             in     date    default null
6873   ,p_end_date               in     date    default null
6874   ,p_effective_date         in     date
6875   ,p_lf_evt_ocrd_dt         in     date    default null
6876   --
6877   ,p_enrt_cvg_strt_dt          out nocopy date
6881   ,p_rt_strt_dt_cd             out nocopy varchar2
6878   ,p_enrt_cvg_strt_dt_cd       out nocopy varchar2
6879   ,p_enrt_cvg_strt_dt_rl       out nocopy number
6880   ,p_rt_strt_dt                out nocopy date
6882   ,p_rt_strt_dt_rl             out nocopy number
6883   ,p_enrt_cvg_end_dt           out nocopy date
6884   ,p_enrt_cvg_end_dt_cd        out nocopy varchar2
6885   ,p_enrt_cvg_end_dt_rl        out nocopy number
6886   ,p_rt_end_dt                 out nocopy date
6887   ,p_rt_end_dt_cd              out nocopy varchar2
6888   ,p_rt_end_dt_rl              out nocopy number
6889   )
6890 is
6891   --
6892   type t_rec is record
6893     (order_number        number
6894     ,enrt_cvg_strt_dt_cd varchar2(30)
6895     ,enrt_cvg_strt_dt_rl number
6896     ,enrt_cvg_end_dt_cd  varchar2(30)
6897     ,enrt_cvg_end_dt_rl  number
6898     ,rt_strt_dt_cd       varchar2(30)
6899     ,rt_strt_dt_rl       number
6900     ,rt_end_dt_cd        varchar2(30)
6901     ,rt_end_dt_rl        number
6902     );
6903   --
6904   type t_tab is table of t_rec index by binary_integer;
6905   --
6906   l_proc                  varchar2(72) := g_package||'.rate_and_coverage_dates';
6907   --
6908   l_union_set             t_tab;
6909   --
6910   l_found                 boolean;
6911   l_done                  boolean:=FALSE;
6912   l_enrt_cvg_strt_dt      date;
6913   l_enrt_cvg_strt_dt_cd   varchar2(30);
6914   l_enrt_cvg_strt_dt_rl   number;
6915   l_rt_strt_dt            date;
6916   l_rt_strt_dt_cd         varchar2(30);
6917   l_rt_strt_dt_rl         number;
6918   l_enrt_cvg_end_dt       date;
6919   l_enrt_cvg_end_dt_cd    varchar2(30);
6920   l_enrt_cvg_end_dt_rl    number;
6921   l_rt_end_dt             date;
6922   l_rt_end_dt_cd          varchar2(30);
6923   l_rt_end_dt_rl          number;
6924   l_pgm_id                number;
6925   l_pl_id                 number;
6926   l_enrt_perd_id          number;
6927   l_lee_rsn_id            number;
6928   l_oipl_id               number;
6929   l_per_in_ler_id         number;
6930   l_person_id             number;
6931   l_pass_cvg_end_dt       date;
6932   l_effective_date        date;
6933   l_plip_id               number;
6934   l_ptip_id               number;
6935   l_enrt_perd_for_pl_id   number;
6936   l_unionele_num          pls_integer;
6937   l_unionmaxele_num       pls_integer;
6938   l_pass_cvg_strt_dt      date;
6939   l_fonm_cvg_strt_dt      date;
6940   --
6941   -- Bug No 3965571
6942   --
6943   l_pln_name               ben_pl_f.name%type;
6944   l_pgm_name              ben_pgm_f.name%type;
6945   l_opt_name               ben_opt_f.name%type;
6946   --
6947   -- Cursor declaration.
6948   --
6949   -- Scheduled enrolment for plans in programs
6950   --
6951   cursor c_sched_for_plip
6952     (c_effective_date in date
6953     ,c_pgm_id         in number
6954     ,c_ptip_id        in number
6955     ,c_pl_id          in number
6956     ,c_plip_id        in number
6957     ,c_enrt_perd_id   in number
6958     ,c_epfp_id        in number
6959     ,c_per_in_ler_id  in number -- bug 4356591
6960     )
6961   is
6962     select  1 order_number,
6963             epp.enrt_cvg_strt_dt_cd,
6964             epp.enrt_cvg_strt_dt_rl,
6965             epp.enrt_cvg_end_dt_cd,
6966             epp.enrt_cvg_end_dt_rl,
6967             epp.rt_strt_dt_cd,
6968             epp.rt_strt_dt_rl,
6969             epp.rt_end_dt_cd,
6970             epp.rt_end_dt_rl
6971     from    ben_enrt_perd_for_pl_f epp
6972     where   epp.ENRT_PERD_FOR_PL_ID = c_epfp_id
6973     and     c_effective_date
6974       between epp.effective_start_date and epp.effective_end_date
6975    union
6976 -- Bug # 4356591
6977 -- in case of a plip. if the enrt_perd details are defined at the plan level
6978 -- then details are selected by this select. The enrt_perd_id stored in
6979 -- ben_pil_elctbl_chc is of the pgm or the first plan defined in the program
6980    select  2 order_number,
6981             epd.enrt_cvg_strt_dt_cd,
6982             epd.enrt_cvg_strt_dt_rl,
6983             epd.enrt_cvg_end_dt_cd,
6984             epd.enrt_cvg_end_dt_rl,
6985             epd.rt_strt_dt_cd,
6986             epd.rt_strt_dt_rl,
6987             epd.rt_end_dt_cd,
6988             epd.rt_end_dt_rl
6989    from     ben_popl_enrt_typ_cycl_f popl,
6990 	    ben_enrt_perd epd,
6991 	    ben_per_in_ler pil
6992     where   popl.pl_id = c_pl_id
6993     and     epd.popl_enrt_typ_cycl_id = popl.popl_enrt_typ_cycl_id
6994     and     pil.per_in_ler_id = c_per_in_ler_id
6995     and     epd.asnd_lf_evt_dt = pil.lf_evt_ocrd_dt /* removed join btw PIL and LER instead made join btw epd $ pil.*/
6996     and     c_effective_date between popl.effective_start_date and popl.effective_end_date
6997     and     (    enrt_cvg_strt_dt_cd is not null
6998              and enrt_cvg_end_dt_cd is not null
6999              and rt_strt_dt_cd is not null
7000              and rt_end_dt_cd is not null )
7001  -- end 4356591
7002    union
7003   -- Bug # 4356591
7004   -- If the enrt_perd details defined at program level and not at plan level
7005   -- then details are selected by this select.
7006     select  3 order_number,
7007             epd.enrt_cvg_strt_dt_cd,
7008             epd.enrt_cvg_strt_dt_rl,
7009             epd.enrt_cvg_end_dt_cd,
7010             epd.enrt_cvg_end_dt_rl,
7011             epd.rt_strt_dt_cd,
7012             epd.rt_strt_dt_rl,
7013             epd.rt_end_dt_cd,
7014             epd.rt_end_dt_rl
7015     from    ben_popl_enrt_typ_cycl_f popl, -- start 4356591
7016 	    ben_enrt_perd epd,
7017 	    ben_per_in_ler pil
7018     where   popl.pgm_id = c_pgm_id
7022     and     c_effective_date between popl.effective_start_date and popl.effective_end_date
7019     and     epd.popl_enrt_typ_cycl_id = popl.popl_enrt_typ_cycl_id
7020     and     pil.per_in_ler_id = c_per_in_ler_id
7021     and     epd.asnd_lf_evt_dt = pil.lf_evt_ocrd_dt /* removed join btw PIL and LER instead made join btw epd $ pil.*/
7023     and     (    enrt_cvg_strt_dt_cd is not null
7024              and enrt_cvg_end_dt_cd is not null
7025              and rt_strt_dt_cd is not null
7026              and rt_end_dt_cd is not null ) -- end 4356591
7027    union
7028     select  4 order_number,
7029             plp.enrt_cvg_strt_dt_cd,
7030             plp.enrt_cvg_strt_dt_rl,
7031             plp.enrt_cvg_end_dt_cd,
7032             plp.enrt_cvg_end_dt_rl,
7033             plp.rt_strt_dt_cd,
7034             plp.rt_strt_dt_rl,
7035             plp.rt_end_dt_cd,
7036             plp.rt_end_dt_rl
7037     from    ben_plip_f plp
7038     where   plp.plip_id=c_plip_id
7039     and     c_effective_date
7040       between plp.effective_start_date and plp.effective_end_date
7041   union
7042     select  5 order_number,
7043             pln.enrt_cvg_strt_dt_cd,
7044             pln.enrt_cvg_strt_dt_rl,
7045             pln.enrt_cvg_end_dt_cd,
7046             pln.enrt_cvg_end_dt_rl,
7047             pln.rt_strt_dt_cd,
7048             pln.rt_strt_dt_rl,
7049             pln.rt_end_dt_cd,
7050             pln.rt_end_dt_rl
7051     from    ben_pl_f pln
7052     where   pln.pl_id=c_pl_id
7053     and     c_effective_date
7054       between pln.effective_start_date and pln.effective_end_date
7055   union
7056     select  6 order_number,
7057             ptip.enrt_cvg_strt_dt_cd,
7058             ptip.enrt_cvg_strt_dt_rl,
7059             ptip.enrt_cvg_end_dt_cd,
7060             ptip.enrt_cvg_end_dt_rl,
7061             ptip.rt_strt_dt_cd,
7062             ptip.rt_strt_dt_rl,
7063             ptip.rt_end_dt_cd,
7064             ptip.rt_end_dt_rl
7065     from    ben_ptip_f ptip
7066     where   ptip.ptip_id=c_ptip_id
7067     and     c_effective_date
7068       between ptip.effective_start_date and ptip.effective_end_date
7069   union
7070     select  7 order_number,
7071             pgm.enrt_cvg_strt_dt_cd,
7072             pgm.enrt_cvg_strt_dt_rl,
7073             pgm.enrt_cvg_end_dt_cd,
7074             pgm.enrt_cvg_end_dt_rl,
7075             pgm.rt_strt_dt_cd,
7076             pgm.rt_strt_dt_rl,
7077             pgm.rt_end_dt_cd,
7078             pgm.rt_end_dt_rl
7079     from    ben_pgm_f pgm
7080     where   pgm.pgm_id = c_pgm_id
7081     and     c_effective_date
7082       between pgm.effective_start_date and pgm.effective_end_date
7083       order by 1; -- bug 5717428
7084   --
7085   -- Scheduled enrolment for plans not in programs
7086   --
7087   cursor c_sched_for_pl_nip is
7088     select  '2' order_number,
7089             enrt_cvg_strt_dt_cd,
7090             enrt_cvg_strt_dt_rl,
7091             enrt_cvg_end_dt_cd,
7092             enrt_cvg_end_dt_rl,
7093             rt_strt_dt_cd,
7094             rt_strt_dt_rl,
7095             rt_end_dt_cd,
7096             rt_end_dt_rl
7097     from    ben_enrt_perd
7098     where   enrt_perd_id=l_enrt_perd_id and
7099             business_group_id =p_business_group_id
7100   union
7101     select  '4' order_number,
7102             enrt_cvg_strt_dt_cd,
7103             enrt_cvg_strt_dt_rl,
7104             enrt_cvg_end_dt_cd,
7105             enrt_cvg_end_dt_rl,
7106             rt_strt_dt_cd,
7107             rt_strt_dt_rl,
7108             rt_end_dt_cd,
7109             rt_end_dt_rl
7110     from    ben_pl_f
7111     where   pl_id=l_pl_id and
7112             business_group_id =p_business_group_id and
7113             nvl(p_lf_evt_ocrd_dt,p_effective_date) between
7114               effective_start_date and effective_end_date
7115   order by 1;
7116   --
7117   -- Life event enrolment for plans in programs
7118   --
7119   cursor c_life_for_plip
7120     (c_effective_date    in date
7121     ,c_epfp_id           in number
7122     ,c_lee_rsn_id        in number
7123     ,c_plip_id           in number
7124     ,c_pl_id             in number
7125     ,c_ptip_id           in number
7126     ,c_pgm_id            in number
7127     ,c_per_in_ler_id     in number
7128     )
7129   is
7130     select  1 order_number,
7131             epp.enrt_cvg_strt_dt_cd,
7132             epp.enrt_cvg_strt_dt_rl,
7133             epp.enrt_cvg_end_dt_cd,
7134             epp.enrt_cvg_end_dt_rl,
7135             epp.rt_strt_dt_cd,
7136             epp.rt_strt_dt_rl,
7137             epp.rt_end_dt_cd,
7138             epp.rt_end_dt_rl
7139     from    ben_enrt_perd_for_pl_f epp
7140     where   epp.ENRT_PERD_FOR_PL_ID=c_epfp_id
7141     and     c_effective_date
7142     between epp.effective_start_date and epp.effective_end_date
7143     and     (    enrt_cvg_strt_dt_cd is not null
7144              and enrt_cvg_end_dt_cd is not null
7145              and rt_strt_dt_cd is not null
7146              and rt_end_dt_cd is not null
7147             )
7148    union
7149 -- Bug # 2527347
7150 -- in case of a plip. if the lee_rsn details are defined at the plan level
7151 -- then details are selected by this select. The lee_rsn_id stored in
7152 -- ben_pil_elctbl_chc is of the pgm or the first plan defined in the program
7153     select  2 order_number,
7154             lee.enrt_cvg_strt_dt_cd,
7155             lee.enrt_cvg_strt_dt_rl,
7156             lee.enrt_cvg_end_dt_cd,
7157             lee.enrt_cvg_end_dt_rl,
7158             lee.rt_strt_dt_cd,
7159             lee.rt_strt_dt_rl,
7163 	    ben_lee_rsn_f lee,
7160             lee.rt_end_dt_cd,
7161             lee.rt_end_dt_rl
7162     from    ben_popl_enrt_typ_cycl_f popl,
7164 	    ben_ler_f     ler,
7165 	    ben_per_in_ler pil
7166     where   popl.pl_id = c_pl_id
7167     and     c_effective_date between popl.effective_start_date and popl.effective_end_date
7168     and     lee.popl_enrt_typ_cycl_id = popl.popl_enrt_typ_cycl_id
7169     and     pil.per_in_ler_id = c_per_in_ler_id
7170     and     ler.ler_id = pil.ler_id
7171     and     lee.ler_id = ler.ler_id
7172     and     c_effective_date between lee.effective_start_date and lee.effective_end_date
7173     and     c_effective_date between popl.effective_start_date and popl.effective_end_date
7174     and     (    enrt_cvg_strt_dt_cd is not null
7175              and enrt_cvg_end_dt_cd is not null
7176              and rt_strt_dt_cd is not null
7177              and rt_end_dt_cd is not null )
7178 -- end bug # 2527347
7179    union
7180    -- Bug # 4356591
7181    -- If the lee_rsn_details defined at program level and not at plan level
7182    -- then details are selected by this select.
7183     select  3 order_number,
7184             lee.enrt_cvg_strt_dt_cd,
7185             lee.enrt_cvg_strt_dt_rl,
7186             lee.enrt_cvg_end_dt_cd,
7187             lee.enrt_cvg_end_dt_rl,
7188             lee.rt_strt_dt_cd,
7189             lee.rt_strt_dt_rl,
7190             lee.rt_end_dt_cd,
7191             lee.rt_end_dt_rl
7192     from    ben_popl_enrt_typ_cycl_f popl, -- start 4356591
7193 	    ben_lee_rsn_f lee,
7194 	    ben_per_in_ler pil
7195     where   popl.pgm_id = c_pgm_id
7196     and     c_effective_date between popl.effective_start_date and popl.effective_end_date
7197     and     lee.popl_enrt_typ_cycl_id = popl.popl_enrt_typ_cycl_id
7198     and     pil.per_in_ler_id = c_per_in_ler_id
7199     and     lee.ler_id = pil.ler_id
7200     and     c_effective_date between lee.effective_start_date and lee.effective_end_date
7201     and     c_effective_date between popl.effective_start_date and popl.effective_end_date -- end 4356591
7202     and     (    enrt_cvg_strt_dt_cd is not null
7203              and enrt_cvg_end_dt_cd is not null
7204              and rt_strt_dt_cd is not null
7205              and rt_end_dt_cd is not null
7206             )
7207   union
7208     select  4 order_number,
7209             plp.enrt_cvg_strt_dt_cd,
7210             plp.enrt_cvg_strt_dt_rl,
7211             plp.enrt_cvg_end_dt_cd,
7212             plp.enrt_cvg_end_dt_rl,
7213             plp.rt_strt_dt_cd,
7214             plp.rt_strt_dt_rl,
7215             plp.rt_end_dt_cd,
7216             plp.rt_end_dt_rl
7217     from    ben_plip_f plp
7218     where   plp.plip_id=c_plip_id
7219     and     c_effective_date
7220       between plp.effective_start_date and plp.effective_end_date
7221     and     (    enrt_cvg_strt_dt_cd is not null
7222              and enrt_cvg_end_dt_cd is not null
7223              and rt_strt_dt_cd is not null
7224              and rt_end_dt_cd is not null
7225             )
7226   union
7227     select  5 order_number,
7228             pln.enrt_cvg_strt_dt_cd,
7229             pln.enrt_cvg_strt_dt_rl,
7230             pln.enrt_cvg_end_dt_cd,
7231             pln.enrt_cvg_end_dt_rl,
7232             pln.rt_strt_dt_cd,
7233             pln.rt_strt_dt_rl,
7234             pln.rt_end_dt_cd,
7235             pln.rt_end_dt_rl
7236     from    ben_pl_f pln
7237     where   pln.pl_id=c_pl_id
7238     and     c_effective_date
7239       between pln.effective_start_date and pln.effective_end_date
7240     and     (    enrt_cvg_strt_dt_cd is not null
7241              and enrt_cvg_end_dt_cd is not null
7242              and rt_strt_dt_cd is not null
7243              and rt_end_dt_cd is not null
7244             )
7245   union
7246     select  6 order_number,
7247             ptip.enrt_cvg_strt_dt_cd,
7248             ptip.enrt_cvg_strt_dt_rl,
7249             ptip.enrt_cvg_end_dt_cd,
7250             ptip.enrt_cvg_end_dt_rl,
7251             ptip.rt_strt_dt_cd,
7252             ptip.rt_strt_dt_rl,
7253             ptip.rt_end_dt_cd,
7254             ptip.rt_end_dt_rl
7255     from    ben_ptip_f ptip
7256     where   ptip.ptip_id=c_ptip_id
7257     and     c_effective_date
7258       between ptip.effective_start_date and ptip.effective_end_date
7259     and     (    enrt_cvg_strt_dt_cd is not null
7260              and enrt_cvg_end_dt_cd is not null
7261              and rt_strt_dt_cd is not null
7262              and rt_end_dt_cd is not null
7263             )
7264   union
7265     select  7 order_number,
7266             pgm.enrt_cvg_strt_dt_cd,
7267             pgm.enrt_cvg_strt_dt_rl,
7268             pgm.enrt_cvg_end_dt_cd,
7269             pgm.enrt_cvg_end_dt_rl,
7270             pgm.rt_strt_dt_cd,
7271             pgm.rt_strt_dt_rl,
7272             pgm.rt_end_dt_cd,
7273             pgm.rt_end_dt_rl
7274     from    ben_pgm_f pgm
7275     where   pgm.pgm_id=c_pgm_id
7276     and     c_effective_date
7277       between pgm.effective_start_date and pgm.effective_end_date
7278     and     (    enrt_cvg_strt_dt_cd is not null
7279              and enrt_cvg_end_dt_cd is not null
7280              and rt_strt_dt_cd is not null
7281              and rt_end_dt_cd is not null
7282             )
7283     order by 1 ; --  Bug 2122643
7284   --
7285   -- Life event enrolment for plans not in programs
7286   --
7287   cursor c_life_for_pl_nip is
7288     select  '2' order_number,
7289             enrt_cvg_strt_dt_cd,
7290             enrt_cvg_strt_dt_rl,
7291             enrt_cvg_end_dt_cd,
7292             enrt_cvg_end_dt_rl,
7293             rt_strt_dt_cd,
7294             rt_strt_dt_rl,
7295             rt_end_dt_cd,
7296             rt_end_dt_rl
7297     from    ben_lee_rsn_f
7298     where   lee_rsn_id=l_lee_rsn_id and
7302   union
7299             business_group_id =p_business_group_id and
7300             nvl(p_lf_evt_ocrd_dt,p_effective_date) between
7301               effective_start_date and effective_end_date
7303     select  '4' order_number,
7304             enrt_cvg_strt_dt_cd,
7305             enrt_cvg_strt_dt_rl,
7306             enrt_cvg_end_dt_cd,
7307             enrt_cvg_end_dt_rl,
7308             rt_strt_dt_cd,
7309             rt_strt_dt_rl,
7310             rt_end_dt_cd,
7311             rt_end_dt_rl
7312     from    ben_pl_f
7313     where   pl_id=l_pl_id and
7314             business_group_id =p_business_group_id and
7315             nvl(p_lf_evt_ocrd_dt,p_effective_date) between
7316               effective_start_date and effective_end_date
7317   order by 1;
7318   --
7319   l_rec c_life_for_plip%rowtype;
7320   --
7321   -- get elig_per_elctbl_chc_info
7322   --
7323   cursor c_epe_info is
7324     select
7325         epe.pl_id,
7326         epe.pgm_id,
7327         pel.enrt_perd_id,
7328         pel.lee_rsn_id,
7329         epe.oipl_id,
7330         epe.per_in_ler_id,
7331         pil.person_id,
7332         epe.fonm_cvg_strt_dt
7333     from
7334         ben_elig_per_elctbl_chc epe,
7335         ben_pil_elctbl_chc_popl pel,
7336         ben_per_in_ler pil
7337     where
7338         epe.elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id and
7339         pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id and
7340         pil.per_in_ler_id=epe.per_in_ler_id;
7341         -- removed these joins, as a run was getting a null BG id passed in
7342         -- and if we have the chc id we shouldn't need bg id:
7343         --pel.business_group_id =p_business_group_id and
7344         --pil.business_group_id =p_business_group_id
7345         --epe.business_group_id =p_business_group_id and
7346   --
7347   cursor c_gptip_id
7348     (c_pl_id          in number
7349     ,c_pgm_id         in number
7350     ,c_effective_date in date
7351     )
7352   is
7353     select ptp.ptip_id
7354     from ben_ptip_f ptp,
7355          ben_pl_f pln
7356     where ptp.pl_typ_id = pln.pl_typ_id
7357     and   c_effective_date
7358       between pln.effective_start_date and pln.effective_end_date
7359     and   ptp.pgm_id    = c_pgm_id
7360     and   pln.pl_id     = c_pl_id
7361     and   c_effective_date
7362       between ptp.effective_start_date and ptp.effective_end_date;
7363 
7364   --
7365   cursor c_gplip_id
7366     (c_pl_id          in number
7367     ,c_pgm_id         in number
7368     ,c_effective_date in date
7369     )
7370   is
7371     select plp.plip_id
7372     from ben_plip_f plp
7373     where plp.pgm_id    = c_pgm_id
7374     and   plp.pl_id     = c_pl_id
7375     and   c_effective_date
7376       between plp.effective_start_date and plp.effective_end_date;
7377 
7378   cursor c_glee_epfp_id
7379     (c_pl_id          in number
7380     ,c_lee_rsn_id     in number
7381     ,c_effective_date in date
7382     )
7383   is
7384     select epfp.ENRT_PERD_FOR_PL_ID
7385     from ben_enrt_perd_for_pl_f epfp
7386     where epfp.lee_rsn_id = c_lee_rsn_id
7387     and   epfp.pl_id      = c_pl_id
7388     and   c_effective_date
7389       between epfp.effective_start_date and epfp.effective_end_date;
7390 
7391   cursor c_genp_epfp_id
7392     (c_pl_id          in number
7393     ,c_enrt_perd_id   in number
7394     ,c_effective_date in date
7395     )
7396   is
7397     select epfp.ENRT_PERD_FOR_PL_ID
7398     from ben_enrt_perd_for_pl_f epfp
7399     where epfp.enrt_perd_id = c_enrt_perd_id
7400     and   epfp.pl_id        = c_pl_id
7401     and   c_effective_date
7402       between epfp.effective_start_date and epfp.effective_end_date;
7403 
7404   cursor c_gepp_dets
7405     (c_epfp_id        in number
7406     ,c_effective_date in date
7407     )
7408   is
7409     select 1 order_number,
7410             epp.enrt_cvg_strt_dt_cd,
7411             epp.enrt_cvg_strt_dt_rl,
7412             epp.enrt_cvg_end_dt_cd,
7413             epp.enrt_cvg_end_dt_rl,
7414             epp.rt_strt_dt_cd,
7415             epp.rt_strt_dt_rl,
7416             epp.rt_end_dt_cd,
7417             epp.rt_end_dt_rl
7418     from    ben_enrt_perd_for_pl_f epp
7419     where   epp.ENRT_PERD_FOR_PL_ID=c_epfp_id
7420     and     c_effective_date
7421     between epp.effective_start_date and epp.effective_end_date
7422     and     (    enrt_cvg_strt_dt_cd is not null
7423              and enrt_cvg_end_dt_cd is not null
7424              and rt_strt_dt_cd is not null
7425              and rt_end_dt_cd is not null
7426             );
7427 
7428   l_epp_rec c_gepp_dets%rowtype;
7429 
7430   cursor c_gleersn_dets
7431     (c_lee_rsn_id     in number
7432     ,c_effective_date in date
7433     )
7434   is
7435     select 2 order_number,
7436             lee.enrt_cvg_strt_dt_cd,
7437             lee.enrt_cvg_strt_dt_rl,
7438             lee.enrt_cvg_end_dt_cd,
7439             lee.enrt_cvg_end_dt_rl,
7440             lee.rt_strt_dt_cd,
7441             lee.rt_strt_dt_rl,
7442             lee.rt_end_dt_cd,
7443             lee.rt_end_dt_rl
7444     from    ben_lee_rsn_f lee
7445     where   lee.lee_rsn_id=c_lee_rsn_id
7446     and     c_effective_date
7447       between lee.effective_start_date and lee.effective_end_date
7448     and     (    enrt_cvg_strt_dt_cd is not null
7449              and enrt_cvg_end_dt_cd is not null
7450              and rt_strt_dt_cd is not null
7451              and rt_end_dt_cd is not null
7452             );
7453 
7454   --
7455   -- Bug No 3965571
7456   --
7457   cursor c_pln
7458   (c_pl_id     in number
7459   ,c_effective_date in date)
7460   is
7464                      and c_effective_date between pln.effective_start_date and pln.effective_end_date;
7461     select pln.name
7462         from ben_pl_f pln
7463 	   where pln.pl_id = c_pl_id and pln.business_group_id = p_business_group_id
7465 
7466   cursor c_pgm
7467   (c_pgm_id     in number
7468   ,c_effective_date in date)
7469   is
7470     select pgm.name
7471         from ben_pgm_f pgm
7472 	   where pgm.pgm_id = c_pgm_id and pgm.business_group_id = p_business_group_id
7473                      and c_effective_date between pgm.effective_start_date and pgm.effective_end_date;
7474 
7475   cursor c_opt
7476   (c_oipl_id   in number
7477   ,c_effective_date in date)
7478   is
7479    select opt.name
7480         from ben_oipl_f oipl, ben_opt_f opt
7481           where oipl.business_group_id=p_business_group_id
7482                    and oipl.opt_id = opt.opt_id and oipl.oipl_id = c_oipl_id
7483 		   and c_effective_date between oipl.effective_start_date and oipl.effective_end_date
7484 		   and c_effective_date between opt.effective_start_date and opt.effective_end_date;
7485 --
7486 -- End 3965571
7487 --
7488 
7489   l_leersn_rec c_gleersn_dets%rowtype;
7490   l_pil_row    ben_per_in_ler%rowtype;
7491 
7492 cursor c_rt_dts_bckdt(c_per_in_ler_id number) is
7493   select  prv.rt_strt_dt,
7494           prv.rt_end_dt
7495     from  ben_prtt_enrt_rslt_f pen,
7496           ben_prtt_rt_val prv
7497     where pen.per_in_ler_id = c_per_in_ler_id
7498       and pen.pl_id=l_pl_id
7499       and nvl(pen.pgm_id,-1)=nvl(l_pgm_id,-1)
7500       and nvl(pen.oipl_id,-1)=nvl(l_oipl_id,-1)
7501       --and pen.pl_typ_id = l_pl_typ_id
7502       and pen.business_group_id  = p_business_group_id
7503       and pen.enrt_cvg_thru_dt = hr_api.g_eot
7504       and prv.per_in_ler_id = c_per_in_ler_id
7505       and prv.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
7506       and not exists
7507           (select '1' from ben_prtt_enrt_rslt_f pen1
7508            where pen.prtt_enrt_rslt_id = pen1.RPLCS_SSPNDD_RSLT_ID
7509            and pen1.per_in_ler_id = c_per_in_ler_id);
7510 
7511   l_rt_strt_dt1 date;
7512   l_rt_end_dt1 date;
7513 
7514 
7515 begin
7516   --
7517   g_debug := hr_utility.debug_enabled;
7518   if g_debug then
7519     hr_utility.set_location ('Entering '||l_proc,10);
7520   end if;
7521 /*
7522   if p_which_dates_cd = 'R' then
7523     --hr_utility.set_location('p_cache_mode               '|| p_cache_mode             , 1687);
7524     if g_debug then
7525       hr_utility.set_location('p_per_in_ler_id             '|| p_per_in_ler_id          , 1687);
7526     end if;
7527     if g_debug then
7528       hr_utility.set_location('p_person_id              	 '|| p_person_id              , 1687);
7529     end if;
7530     if g_debug then
7531       hr_utility.set_location('p_pgm_id                 	 '|| p_pgm_id                 , 1687);
7532     end if;
7533     if g_debug then
7534       hr_utility.set_location('p_pl_id                  	 '|| p_pl_id                  , 1687);
7535     end if;
7536     if g_debug then
7537       hr_utility.set_location('p_oipl_id                	 '|| p_oipl_id                , 1687);
7538     end if;
7539     if g_debug then
7540       hr_utility.set_location('p_par_ptip_id            	 '|| p_par_ptip_id            , 1687);
7541     end if;
7542     if g_debug then
7543       hr_utility.set_location('p_lee_rsn_id             	 '|| p_lee_rsn_id             , 1687);
7544     end if;
7545     if g_debug then
7546       hr_utility.set_location('p_enrt_perd_id           	 '|| p_enrt_perd_id           , 1687);
7547     end if;
7548     if g_debug then
7549       hr_utility.set_location('p_enrt_perd_for_pl_id    	 '|| p_enrt_perd_for_pl_id    , 1687);
7550     end if;
7551     if g_debug then
7552       hr_utility.set_location('p_which_dates_cd         	 '|| p_which_dates_cd         , 1687);
7553     end if;
7554     if g_debug then
7555       hr_utility.set_location('p_date_mandatory_flag    	 '|| p_date_mandatory_flag    , 1687);
7556     end if;
7557     if g_debug then
7558       hr_utility.set_location('p_compute_dates_flag     	 '|| p_compute_dates_flag     , 1687);
7559     end if;
7560     if g_debug then
7561       hr_utility.set_location('p_elig_per_elctbl_chc_id 	 '|| p_elig_per_elctbl_chc_id , 1687);
7562     end if;
7563     if g_debug then
7564       hr_utility.set_location('p_acty_base_rt_id        	 '|| p_acty_base_rt_id        , 1687);
7565     end if;
7566     if g_debug then
7567       hr_utility.set_location('p_business_group_id      	 '|| p_business_group_id      , 1687);
7568     end if;
7569     if g_debug then
7570       hr_utility.set_location('p_start_date             	 '|| p_start_date             , 1687);
7571     end if;
7572     if g_debug then
7573       hr_utility.set_location('p_end_date               	 '|| p_end_date               , 1687);
7574     end if;
7575     if g_debug then
7576       hr_utility.set_location('p_effective_date         	 '|| p_effective_date         , 1687);
7577     end if;
7578     if g_debug then
7579       hr_utility.set_location('p_lf_evt_ocrd_dt         	 '|| p_lf_evt_ocrd_dt         , 1687);
7580     end if;
7581   end if;
7582 */
7583   --
7584 
7585 
7586   l_effective_date := nvl(p_lf_evt_ocrd_dt,p_effective_date);
7587 
7588   hr_utility.set_location('l_effective_date ' || l_effective_date, 2080);
7589   --
7590   -- Get the necessary info to start processing
7591   --
7592   if p_cache_mode
7593   then
7594     --
7595     l_person_id           := p_person_id;
7596     l_per_in_ler_id       := p_per_in_ler_id;
7597     l_pgm_id              := p_pgm_id;
7598     l_ptip_id             := p_par_ptip_id;
7599     l_pl_id               := p_pl_id;
7600     l_plip_id             := p_par_plip_id;
7601     l_oipl_id             := p_oipl_id;
7605     --l_fonm_cvg_strt_dt    := ben_manage_life_events.g_fonm_cvg_strt_dt ;
7602     l_enrt_perd_id        := p_enrt_perd_id;
7603     l_lee_rsn_id          := p_lee_rsn_id;
7604     l_enrt_perd_for_pl_id := p_enrt_perd_for_pl_id;
7606     --
7607   elsif p_elig_per_elctbl_chc_id is not null then
7608     --
7609     if g_debug then
7610       hr_utility.set_location(l_proc , 20);
7611     end if;
7612     --
7613     -- get from elig_per_elctbl_chc
7614     --   Note: Don't need all the args just the ones for direct use by
7615     --         this module, let determine date take care of itself
7616     --
7617     open c_epe_info;
7618     fetch c_epe_info into
7619       l_pl_id,
7620       l_pgm_id,
7621       l_enrt_perd_id,
7622       l_lee_rsn_id,
7623       l_oipl_id,
7624       l_per_in_ler_id,
7625       l_person_id,
7626       l_fonm_cvg_strt_dt
7627     ;
7628     --
7629     if g_debug then
7630       hr_utility.set_location('l_oipl_id '||l_oipl_id,19);
7631     end if;
7632     if c_epe_info%notfound then
7633       close c_epe_info;
7634       fnd_message.set_name('BEN','BEN_91457_ELCTBL_CHC_NOT_FOUND');
7635       --fnd_message.set_token('ID', to_char(p_business_group_id));
7636       fnd_message.set_token('ID', to_char(p_elig_per_elctbl_chc_id));
7637       fnd_message.set_token('PROC',l_proc);
7638       fnd_message.raise_error;
7639     end if;
7640     if g_debug then
7641       hr_utility.set_location(l_proc , 40);
7642     end if;
7643 
7644     close c_epe_info;
7645   else
7646     if g_debug then
7647       hr_utility.set_location(l_proc , 50);
7648     end if;
7649     --
7650     -- use args
7651     --
7652     l_pl_id:=p_pl_id;
7653     l_pgm_id:=p_pgm_id;
7654     l_enrt_perd_id:=p_enrt_perd_id;
7655     l_lee_rsn_id:=p_lee_rsn_id;
7656     l_oipl_id:=p_oipl_id;
7657     l_per_in_ler_id:=p_per_in_ler_id;
7658     l_person_id:=p_person_id;
7659     --
7660   end if;
7661   --
7662   if g_debug then
7663     hr_utility.set_location(l_proc , 60);
7664     hr_utility.set_location('FONM FLAG ' || ben_manage_life_events.fonm   , 60);
7665     hr_utility.set_location('FONM gc date  ' ||  ben_manage_life_events.g_fonm_cvg_strt_dt  , 60);
7666     hr_utility.set_location('FONM gr date  ' ||  ben_manage_life_events.g_fonm_rt_strt_dt  , 60);
7667     hr_utility.set_location('FONM epe date  ' || l_fonm_cvg_strt_dt  , 60);
7668     hr_utility.set_location('which date code   ' ||  p_which_dates_cd   , 60);
7669     hr_utility.set_location('plan    ' ||  p_pl_id    , 60);
7670 
7671   end if;
7672 
7673 
7674   --
7675   -- Get the codes and rules
7676   --
7677   -- Open and fetch first row
7678   --
7679   if l_pgm_id is not null then
7680     --
7681     -- Get the ptip id for the pl and pgm
7682     --
7683     if l_ptip_id is null then
7684     --  hr_utility.set_location(' c_gptip_id: '||l_proc , 140);
7685       open c_gptip_id
7686         (c_pl_id          => l_pl_id
7687         ,c_pgm_id         => l_pgm_id
7688         ,c_effective_date => l_effective_date
7689         );
7690       fetch c_gptip_id into l_ptip_id;
7691       close c_gptip_id;
7692       if g_debug then
7693         hr_utility.set_location(' Dn c_gptip_id: '||l_proc , 140);
7694       end if;
7695     else
7696       l_ptip_id := p_par_ptip_id;
7697     end if;
7698     --
7699     -- Get the plip id for the pl and pgm
7700     --
7701     if l_plip_id is null then
7702       if g_debug then
7703         hr_utility.set_location(' c_gplip_id: '||l_proc , 140);
7704       end if;
7705       open c_gplip_id
7706         (c_pl_id          => l_pl_id
7707         ,c_pgm_id         => l_pgm_id
7708         ,c_effective_date => l_effective_date
7709         );
7710       fetch c_gplip_id into l_plip_id;
7711       close c_gplip_id;
7712       if g_debug then
7713         hr_utility.set_location(' Dn c_gplip_id: '||l_proc , 140);
7714       end if;
7715     else
7716       l_plip_id := p_par_plip_id;
7717     end if;
7718     --
7719     if l_enrt_perd_id is not null then
7720       if g_debug then
7721         hr_utility.set_location(' Op c_SCFP: '||l_proc , 140);
7722       end if;
7723       --
7724       -- Check if the enrt perd for pl id is passed in
7725       --
7726       if l_enrt_perd_for_pl_id is null then
7727         --
7728         open c_genp_epfp_id
7729           (c_pl_id          => l_pl_id
7730           ,c_enrt_perd_id   => l_enrt_perd_id
7731           ,c_effective_date => l_effective_date
7732           );
7733         fetch c_genp_epfp_id into l_enrt_perd_for_pl_id;
7734         close c_genp_epfp_id;
7735         --
7736       else
7737         --
7738         l_enrt_perd_for_pl_id := p_enrt_perd_for_pl_id;
7739         --
7740       end if;
7741       --
7742       open c_sched_for_plip
7743         (c_effective_date => l_effective_date
7744         ,c_pgm_id         => l_pgm_id
7745         ,c_ptip_id        => l_ptip_id
7746         ,c_pl_id          => l_pl_id
7747         ,c_plip_id        => l_plip_id
7748         ,c_enrt_perd_id   => l_enrt_perd_id
7749         ,c_epfp_id        => l_enrt_perd_for_pl_id
7750 	,c_per_in_ler_id  => l_per_in_ler_id      -- bug 4356591
7751         );
7752       fetch c_sched_for_plip into l_rec;
7753       if g_debug then
7754         hr_utility.set_location(' Dn Fet c_SCFP: '||l_proc , 140);
7755 	hr_utility.set_location(' l_rec.enrt_cvg_strt_dt_cd : '|| l_rec.enrt_cvg_strt_dt_cd , 140);
7756         hr_utility.set_location(' l_rec.enrt_cvg_end_dt_cd : '|| l_rec.enrt_cvg_end_dt_cd , 140);
7757       end if;
7758       l_found:=c_sched_for_plip%found;
7759     else
7760       --
7761       -- do life event plip processing
7765         hr_utility.set_location(' Op c_glee_epfp_id: '||l_proc , 150);
7762       -- also used for unrestricted plip
7763       --
7764       if g_debug then
7766       end if;
7767       --
7768       if l_enrt_perd_for_pl_id is null then
7769         --
7770         open c_glee_epfp_id
7771           (c_pl_id          => l_pl_id
7772           ,c_lee_rsn_id     => l_lee_rsn_id
7773           ,c_effective_date => l_effective_date
7774           );
7775         fetch c_glee_epfp_id into l_enrt_perd_for_pl_id;
7776         close c_glee_epfp_id;
7777         --
7778       else
7779         --
7780         l_enrt_perd_for_pl_id := p_enrt_perd_for_pl_id;
7781         --
7782       end if;
7783       --
7784    if g_debug then
7785      hr_utility.set_location(' Dn c_glee_epfp_id: '||l_proc , 150);
7786    end if;
7787       --
7788       -- Fetch the first row from the union cache
7789       --
7790       if p_pgm_row.pgm_id is not null
7791         and p_ptip_row.ptip_id is not null
7792         and p_plip_row.plip_id is not null
7793         and p_pl_row.pl_id is not null
7794       then
7795 
7796       if g_debug then
7797         hr_utility.set_location(' Building the union cache ', 1687);
7798       end if;
7799         --
7800         -- Build up union set
7801         --
7802         l_unionele_num := 0;
7803         l_union_set.delete;
7804         --
7805         open c_gepp_dets
7806           (c_epfp_id        => l_enrt_perd_for_pl_id
7807           ,c_effective_date => l_effective_date
7808           );
7809         fetch c_gepp_dets into l_epp_rec;
7810         if c_gepp_dets%found then
7811           --
7812           l_union_set(l_unionele_num).order_number        := 1;
7813           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := l_epp_rec.enrt_cvg_strt_dt_cd;
7814           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := l_epp_rec.enrt_cvg_strt_dt_rl;
7815           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := l_epp_rec.enrt_cvg_end_dt_cd;
7816           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := l_epp_rec.enrt_cvg_end_dt_rl;
7817           l_union_set(l_unionele_num).rt_strt_dt_cd       := l_epp_rec.rt_strt_dt_cd;
7818           l_union_set(l_unionele_num).rt_strt_dt_rl       := l_epp_rec.rt_strt_dt_rl;
7819           l_union_set(l_unionele_num).rt_end_dt_cd        := l_epp_rec.rt_end_dt_cd;
7820           l_union_set(l_unionele_num).rt_end_dt_rl        := l_epp_rec.rt_end_dt_rl;
7821           l_unionele_num := l_unionele_num+1;
7822           --
7823         end if;
7824         close c_gepp_dets;
7825         --
7826 if g_debug then
7827   hr_utility.set_location(' l_lee_rsn_id: '||l_lee_rsn_id, 1687);
7828 end if;
7829 
7830         open c_gleersn_dets
7831           (c_lee_rsn_id     => l_lee_rsn_id
7832           ,c_effective_date => l_effective_date
7833           );
7834         fetch c_gleersn_dets into l_leersn_rec;
7835         if c_gleersn_dets%found then
7836           --
7837           l_union_set(l_unionele_num).order_number        := 2;
7838           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := l_leersn_rec.enrt_cvg_strt_dt_cd;
7839           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := l_leersn_rec.enrt_cvg_strt_dt_rl;
7840           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := l_leersn_rec.enrt_cvg_end_dt_cd;
7841           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := l_leersn_rec.enrt_cvg_end_dt_rl;
7842           l_union_set(l_unionele_num).rt_strt_dt_cd       := l_leersn_rec.rt_strt_dt_cd;
7843           l_union_set(l_unionele_num).rt_strt_dt_rl       := l_leersn_rec.rt_strt_dt_rl;
7844           l_union_set(l_unionele_num).rt_end_dt_cd        := l_leersn_rec.rt_end_dt_cd;
7845           l_union_set(l_unionele_num).rt_end_dt_rl        := l_leersn_rec.rt_end_dt_rl;
7846           l_unionele_num := l_unionele_num+1;
7847           --
7848         end if;
7849         close c_gleersn_dets;
7850         --
7851         if p_plip_row.plip_id is not null
7852           and (p_plip_row.enrt_cvg_strt_dt_cd is not null
7853               and p_plip_row.enrt_cvg_end_dt_cd is not null
7854               and p_plip_row.rt_strt_dt_cd is not null
7855               and p_plip_row.rt_end_dt_cd is not null
7856               )
7857         then
7858           --
7859           l_union_set(l_unionele_num).order_number        := 3;
7860           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := p_plip_row.enrt_cvg_strt_dt_cd;
7861           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := p_plip_row.enrt_cvg_strt_dt_rl;
7862           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := p_plip_row.enrt_cvg_end_dt_cd;
7863           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := p_plip_row.enrt_cvg_end_dt_rl;
7864           l_union_set(l_unionele_num).rt_strt_dt_cd       := p_plip_row.rt_strt_dt_cd;
7865           l_union_set(l_unionele_num).rt_strt_dt_rl       := p_plip_row.rt_strt_dt_rl;
7866           l_union_set(l_unionele_num).rt_end_dt_cd        := p_plip_row.rt_end_dt_cd;
7867           l_union_set(l_unionele_num).rt_end_dt_rl        := p_plip_row.rt_end_dt_rl;
7868           l_unionele_num := l_unionele_num+1;
7869           --
7870         end if;
7871         --
7872         if p_pl_row.pl_id is not null
7873           and (p_pl_row.enrt_cvg_strt_dt_cd is not null
7874               and p_pl_row.enrt_cvg_end_dt_cd is not null
7875               and p_pl_row.rt_strt_dt_cd is not null
7876               and p_pl_row.rt_end_dt_cd is not null
7877               )
7878         then
7879           --
7880           l_union_set(l_unionele_num).order_number        := 4;
7881           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := p_pl_row.enrt_cvg_strt_dt_cd;
7882           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := p_pl_row.enrt_cvg_strt_dt_rl;
7883           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := p_pl_row.enrt_cvg_end_dt_cd;
7884           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := p_pl_row.enrt_cvg_end_dt_rl;
7888           l_union_set(l_unionele_num).rt_end_dt_rl        := p_pl_row.rt_end_dt_rl;
7885           l_union_set(l_unionele_num).rt_strt_dt_cd       := p_pl_row.rt_strt_dt_cd;
7886           l_union_set(l_unionele_num).rt_strt_dt_rl       := p_pl_row.rt_strt_dt_rl;
7887           l_union_set(l_unionele_num).rt_end_dt_cd        := p_pl_row.rt_end_dt_cd;
7889           l_unionele_num := l_unionele_num+1;
7890           --
7891         end if;
7892         --
7893         if p_ptip_row.ptip_id is not null
7894           and (p_ptip_row.enrt_cvg_strt_dt_cd is not null
7895               and p_ptip_row.enrt_cvg_end_dt_cd is not null
7896               and p_ptip_row.rt_strt_dt_cd is not null
7897               and p_ptip_row.rt_end_dt_cd is not null
7898               )
7899         then
7900           --
7901           l_union_set(l_unionele_num).order_number        := 5;
7902           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := p_ptip_row.enrt_cvg_strt_dt_cd;
7903           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := p_ptip_row.enrt_cvg_strt_dt_rl;
7904           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := p_ptip_row.enrt_cvg_end_dt_cd;
7905           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := p_ptip_row.enrt_cvg_end_dt_rl;
7906           l_union_set(l_unionele_num).rt_strt_dt_cd       := p_ptip_row.rt_strt_dt_cd;
7907           l_union_set(l_unionele_num).rt_strt_dt_rl       := p_ptip_row.rt_strt_dt_rl;
7908           l_union_set(l_unionele_num).rt_end_dt_cd        := p_ptip_row.rt_end_dt_cd;
7909           l_union_set(l_unionele_num).rt_end_dt_rl        := p_ptip_row.rt_end_dt_rl;
7910           l_unionele_num := l_unionele_num+1;
7911           --
7912         end if;
7913         --
7914         if p_pgm_row.pgm_id is not null
7915           and (p_pgm_row.enrt_cvg_strt_dt_cd is not null
7916               and p_pgm_row.enrt_cvg_end_dt_cd is not null
7917               and p_pgm_row.rt_strt_dt_cd is not null
7918               and p_pgm_row.rt_end_dt_cd is not null
7919               )
7920         then
7921           --
7922           l_union_set(l_unionele_num).order_number        := 6;
7923           l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd := p_pgm_row.enrt_cvg_strt_dt_cd;
7924           l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl := p_pgm_row.enrt_cvg_strt_dt_rl;
7925           l_union_set(l_unionele_num).enrt_cvg_end_dt_cd  := p_pgm_row.enrt_cvg_end_dt_cd;
7926           l_union_set(l_unionele_num).enrt_cvg_end_dt_rl  := p_pgm_row.enrt_cvg_end_dt_rl;
7927           l_union_set(l_unionele_num).rt_strt_dt_cd       := p_pgm_row.rt_strt_dt_cd;
7928           l_union_set(l_unionele_num).rt_strt_dt_rl       := p_pgm_row.rt_strt_dt_rl;
7929           l_union_set(l_unionele_num).rt_end_dt_cd        := p_pgm_row.rt_end_dt_cd;
7930           l_union_set(l_unionele_num).rt_end_dt_rl        := p_pgm_row.rt_end_dt_rl;
7931           l_unionele_num := l_unionele_num+1;
7932           --
7933         end if;
7934         --
7935         if l_union_set.count > 0 then
7936           --
7937           l_found           := TRUE;
7938           l_unionele_num    := 0;
7939           l_unionmaxele_num := l_union_set.count-1;
7940           --
7941           l_rec.order_number        := l_union_set(l_unionele_num).order_number;
7942           l_rec.enrt_cvg_strt_dt_cd := l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd;
7943           l_rec.enrt_cvg_strt_dt_rl := l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl;
7944           l_rec.enrt_cvg_end_dt_cd  := l_union_set(l_unionele_num).enrt_cvg_end_dt_cd;
7945           l_rec.enrt_cvg_end_dt_rl  := l_union_set(l_unionele_num).enrt_cvg_end_dt_rl;
7946           l_rec.rt_strt_dt_cd       := l_union_set(l_unionele_num).rt_strt_dt_cd;
7947           l_rec.rt_strt_dt_rl       := l_union_set(l_unionele_num).rt_strt_dt_rl;
7948           l_rec.rt_end_dt_cd        := l_union_set(l_unionele_num).rt_end_dt_cd;
7949           l_rec.rt_end_dt_rl        := l_union_set(l_unionele_num).rt_end_dt_rl;
7950           l_unionele_num := l_unionele_num+1;
7951           --
7952         else
7953           --
7954           l_found := FALSE;
7955           --
7956         end if;
7957         --
7958 if g_debug then
7959   hr_utility.set_location(' Done Building the union cache l_unionele_num = '||l_unionele_num, 1687);
7960 end if;
7961       else
7962         --
7963         open c_life_for_plip
7964           (c_effective_date => l_effective_date
7965           ,c_pgm_id         => l_pgm_id
7966           ,c_ptip_id        => l_ptip_id
7967           ,c_pl_id          => l_pl_id
7968           ,c_plip_id        => l_plip_id
7969           ,c_lee_rsn_id     => l_lee_rsn_id
7970           ,c_epfp_id        => l_enrt_perd_for_pl_id
7971           ,c_per_in_ler_id  => l_per_in_ler_id
7972           );
7973 if g_debug then
7974   hr_utility.set_location('Fetching rt start date cd' , 1687);
7975 end if;
7976         fetch c_life_for_plip into l_rec;
7977       if g_debug then
7978         hr_utility.set_location(' Dn Fet c_LFP: '||l_proc , 150);
7979       end if;
7980         l_found:=c_life_for_plip%found;
7981         --
7982       end if;
7983       --
7984     end if;
7985   else
7986     if l_enrt_perd_id is not null then
7987       if g_debug then
7988         hr_utility.set_location(l_proc , 190);
7989       end if;
7990       -- do scheduled pl_nip processing
7991       open c_sched_for_pl_nip;
7992       fetch c_sched_for_pl_nip into l_rec;
7993       l_found:=c_sched_for_pl_nip%found;
7994     else
7995       if g_debug then
7996         hr_utility.set_location(l_proc , 200);
7997       end if;
7998       -- do life event pl_nip processing
7999       -- also used for unrestricted pl_nip
8000 if g_debug then
8001   hr_utility.set_location(' Doing c_life_for_pl_nip', 1687);
8002 end if;
8003       open c_life_for_pl_nip;
8004       fetch c_life_for_pl_nip into l_rec;
8005       l_found:=c_life_for_pl_nip%found;
8006     end if;
8007   end if;
8008   loop
8012     exit when l_found = FALSE;
8009     if g_debug then
8010       hr_utility.set_location(l_proc , 240);
8011     end if;
8013     --
8014     -- process rates
8015     --
8016     if g_debug then
8017       hr_utility.set_location(l_proc , 250);
8018     end if;
8019     if p_which_dates_cd in ('R','B') then
8020       if l_rt_strt_dt_cd is null and
8021          l_rec.rt_strt_dt_cd is not null then
8022       if g_debug then
8023           hr_utility.set_location(l_proc , 270);
8024       end if;
8025         l_rt_strt_dt_cd:=l_rec.rt_strt_dt_cd;
8026         l_rt_strt_dt_rl:=l_rec.rt_strt_dt_rl;
8027       end if;
8028       if l_rt_end_dt_cd is null and
8029          l_rec.rt_end_dt_cd is not null then
8030         if g_debug then
8031           hr_utility.set_location(l_proc , 290);
8032         end if;
8033         l_rt_end_dt_cd:=l_rec.rt_end_dt_cd;
8034         l_rt_end_dt_rl:=l_rec.rt_end_dt_rl;
8035       end if;
8036     end if;
8037     --
8038     if g_debug then
8039       hr_utility.set_location(l_proc , 310);
8040     end if;
8041     --
8042     -- process coverage
8043     --
8044     if p_which_dates_cd in ('C','B') then
8045       if l_enrt_cvg_strt_dt_cd is null and
8046          l_rec.enrt_cvg_strt_dt_cd is not null then
8047         if g_debug then
8048           hr_utility.set_location(l_proc , 330);
8049         end if;
8050         l_enrt_cvg_strt_dt_cd:=l_rec.enrt_cvg_strt_dt_cd;
8051         l_enrt_cvg_strt_dt_rl:=l_rec.enrt_cvg_strt_dt_rl;
8052       end if;
8053       if l_enrt_cvg_end_dt_cd is null and
8054          l_rec.enrt_cvg_end_dt_cd is not null then
8055         if g_debug then
8056           hr_utility.set_location(l_proc , 350);
8057         end if;
8058         l_enrt_cvg_end_dt_cd:=l_rec.enrt_cvg_end_dt_cd;
8059         l_enrt_cvg_end_dt_rl:=l_rec.enrt_cvg_end_dt_rl;
8060       end if;
8061     end if;
8062     --
8063     if g_debug then
8064       hr_utility.set_location(l_proc , 360);
8065     end if;
8066     --
8067     -- determine if done
8068     --
8069     if ((p_which_dates_cd ='C' and
8070          l_enrt_cvg_strt_dt_cd is not null and
8071          l_enrt_cvg_end_dt_cd is not null) or
8072         (p_which_dates_cd ='R' and
8073          l_rt_strt_dt_cd is not null and
8074          l_rt_end_dt_cd is not null) or
8075         (p_which_dates_cd ='B' and
8076          l_enrt_cvg_strt_dt_cd is not null and
8077          l_enrt_cvg_end_dt_cd is not null and
8078          l_rt_strt_dt_cd is not null and
8079          l_rt_end_dt_cd is not null)) then
8080       if g_debug then
8081         hr_utility.set_location(l_proc , 380);
8082       end if;
8083       l_found:=FALSE;
8084       l_done:=TRUE;
8085     else
8086       if g_debug then
8087         hr_utility.set_location(l_proc , 390);
8088       end if;
8089       --
8090       -- if not done then get the next row
8091       --
8092       if l_pgm_id is not null then
8093         if l_enrt_perd_id is not null then
8094           if g_debug then
8095             hr_utility.set_location(l_proc , 410);
8096           end if;
8097           -- do scheduled plip processing
8098           fetch c_sched_for_plip into l_rec;
8099           l_found:=c_sched_for_plip%found;
8100         else
8101           -- do life event plip processing
8102           -- also used for unrestricted pl_nip
8103           if g_debug then
8104             hr_utility.set_location(' Fet c_LFPLIP: '||l_proc , 420);
8105           end if;
8106           if p_pgm_row.pgm_id is not null
8107             and p_ptip_row.ptip_id is not null
8108             and p_plip_row.plip_id is not null
8109             and p_pl_row.pl_id is not null
8110           then
8111             --
8112             l_rec.order_number        := l_union_set(l_unionele_num).order_number;
8113             l_rec.enrt_cvg_strt_dt_cd := l_union_set(l_unionele_num).enrt_cvg_strt_dt_cd;
8114             l_rec.enrt_cvg_strt_dt_rl := l_union_set(l_unionele_num).enrt_cvg_strt_dt_rl;
8115             l_rec.enrt_cvg_end_dt_cd  := l_union_set(l_unionele_num).enrt_cvg_end_dt_cd;
8116             l_rec.enrt_cvg_end_dt_rl  := l_union_set(l_unionele_num).enrt_cvg_end_dt_rl;
8117             l_rec.rt_strt_dt_cd       := l_union_set(l_unionele_num).rt_strt_dt_cd;
8118             l_rec.rt_strt_dt_rl       := l_union_set(l_unionele_num).rt_strt_dt_rl;
8119             l_rec.rt_end_dt_cd        := l_union_set(l_unionele_num).rt_end_dt_cd;
8120             l_rec.rt_end_dt_rl        := l_union_set(l_unionele_num).rt_end_dt_rl;
8121             --
8122             if l_unionele_num = l_unionmaxele_num then
8123               --
8124               l_found := FALSE;
8125               --
8126             else
8127               --
8128               l_found := TRUE;
8129               l_unionele_num := l_unionele_num+1;
8130               --
8131             end if;
8132             --
8133           else
8134             --
8135             fetch c_life_for_plip into l_rec;
8136             l_found:=c_life_for_plip%found;
8137             --
8138           end if;
8139         end if;
8140       else
8141         if l_enrt_perd_id is not null then
8142           if g_debug then
8143             hr_utility.set_location(l_proc , 460);
8144           end if;
8145           -- do scheduled pl_nip processing
8146           fetch c_sched_for_pl_nip into l_rec;
8147           l_found:=c_sched_for_pl_nip%found;
8148         else
8149           if g_debug then
8150             hr_utility.set_location(l_proc , 470);
8151           end if;
8155           l_found:=c_life_for_pl_nip%found;
8152           -- do life event pl_nip processing
8153           -- also used for unrestricted pl_nip
8154           fetch c_life_for_pl_nip into l_rec;
8156         end if;
8157       end if;
8158     end if;
8159     if g_debug then
8160       hr_utility.set_location(' End loop: '||l_proc , 420);
8161     end if;
8162   end loop;
8163   --
8164   -- close cursors
8165   --
8166   if l_pgm_id is not null then
8167     if l_enrt_perd_id is not null then
8168       if g_debug then
8169         hr_utility.set_location(l_proc , 860);
8170       end if;
8171       -- do scheduled plip processing
8172       close c_sched_for_plip;
8173     else
8174       if g_debug then
8175         hr_utility.set_location(l_proc , 870);
8176       end if;
8177       -- do life event plip processing
8178       -- also used for unrestricted plip
8179       if p_pgm_row.pgm_id is not null
8180         or p_ptip_row.ptip_id is not null
8181         or p_plip_row.plip_id is not null
8182         or p_pl_row.pl_id is not null
8183       then
8184         --
8185         null;
8186         --
8187       else
8188         --
8189         close c_life_for_plip;
8190         --
8191       end if;
8192       --
8193     end if;
8194   else
8195     if l_enrt_perd_id is not null then
8196       if g_debug then
8197         hr_utility.set_location(l_proc , 900);
8198       end if;
8199       -- do scheduled pl_nip processing
8200       close c_sched_for_pl_nip;
8201     else
8202       if g_debug then
8203         hr_utility.set_location(l_proc , 910);
8204       end if;
8205       -- do life event pl_nip processing
8206       -- also used for unrestricted pl_nip
8207       close c_life_for_pl_nip;
8208     end if;
8209   end if;
8210     --
8211     -- Bug no 3965571
8212     --
8213     open c_pln
8214           (c_pl_id                => l_pl_id
8215 	  ,c_effective_date => l_effective_date);
8216      fetch c_pln into l_pln_name;
8217      close c_pln;
8218     --
8219     open c_pgm
8220           (c_pgm_id             => l_pgm_id
8221 	  ,c_effective_date => l_effective_date);
8222      fetch c_pgm into l_pgm_name;
8223      close c_pgm;
8224      --
8225     open c_opt
8226           (c_oipl_id             => l_oipl_id
8227 	  ,c_effective_date => l_effective_date);
8228           fetch c_opt into l_opt_name;
8229      close c_opt;
8230 
8231  --  End Bug 3965571
8232 
8233   --
8234   -- must be done
8235   --
8236   if l_done=FALSE then
8237     if g_debug then
8238       hr_utility.set_location(l_proc , 530);
8239     end if;
8240 
8241     -- Bug No 3965571 : All ids are replaced by their names in the error message's tokens.
8242 
8243     if p_which_dates_cd in ('R','B') and
8244        l_rt_strt_dt_cd is null then
8245       if g_debug then
8246         hr_utility.set_location('BEN_91455_RT_STRT_DT_NOT_FOUND' , 540);
8247       end if;
8248       fnd_message.set_name('BEN','BEN_91455_RT_STRT_DT_NOT_FOUND');
8249       fnd_message.set_token('PLAN_ID',l_pln_name);
8250       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8251       fnd_message.set_token('PGM_ID',l_pgm_name);
8252       fnd_message.set_token('OIPL_ID',l_opt_name);
8253       fnd_message.raise_error;
8254     elsif p_which_dates_cd in ('R','B') and
8255           l_rt_end_dt_cd is null then
8256       if g_debug then
8257         hr_utility.set_location('BEN_91703_NOT_DET_RATE_END_DT' , 550);
8258       end if;
8259       fnd_message.set_name('BEN','BEN_91703_NOT_DET_RATE_END_DT');
8260       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8261       fnd_message.set_token('PGM_ID',l_pgm_name);
8262       fnd_message.set_token('PL_ID',l_pln_name);
8263       fnd_message.set_token('OIPL_ID',l_opt_name);
8264       fnd_message.raise_error;
8265     elsif p_which_dates_cd in ('C','B') and
8266           l_enrt_cvg_strt_dt_cd is null then
8267       if g_debug then
8268         hr_utility.set_location('BEN_91453_CVG_STRT_DT_NOT_FOUN' , 560);
8269       end if;
8270       fnd_message.set_name('BEN','BEN_91453_CVG_STRT_DT_NOT_FOUN');
8271       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8272       fnd_message.set_token('PGM_ID',l_pgm_name);
8273       fnd_message.set_token('PLAN_ID',l_pln_name);
8274       fnd_message.set_token('OIPL_ID',l_opt_name);
8275       fnd_message.raise_error;
8276     elsif p_which_dates_cd in ('C','B') and
8277           l_enrt_cvg_end_dt_cd is null then
8278       if g_debug then
8279         hr_utility.set_location(l_proc , 570);
8280       end if;
8281       fnd_message.set_name('BEN','BEN_91702_NOT_DET_CVG_END_DT');
8282       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8283       fnd_message.set_token('PGM_ID',l_pgm_name);
8284       fnd_message.set_token('PL_ID',l_pln_name);
8285       fnd_message.set_token('OIPL_ID',l_opt_name);
8286       fnd_message.raise_error;
8287     end if;
8288     --
8289   end if;
8290   --
8291   -- If necessary call the date function to get the absolute date
8292   if p_compute_dates_flag='Y' then
8293     --
8294     if (l_enrt_cvg_strt_dt_cd is not NULL) then
8295       if g_debug then
8296         hr_utility.set_location(' ECSDCD DETDT_MN '||l_proc , 630);
8297       end if;
8298       main
8299         (p_cache_mode             => p_cache_mode
8300         ,p_date_cd                => l_enrt_cvg_strt_dt_cd
8301         ,p_formula_id             => l_enrt_cvg_strt_dt_rl
8302         ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8303         ,p_business_group_id      => p_business_group_id
8304         ,p_effective_date         => p_effective_date
8305         ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
8309         ,p_pgm_id                 => l_pgm_id
8306         ,p_returned_date          => l_enrt_cvg_strt_dt
8307         ,p_per_in_ler_id          => l_per_in_ler_id
8308         ,p_person_id              => l_person_id
8310         ,p_pl_id                  => l_pl_id
8311         ,p_oipl_id                => l_oipl_id
8312         ,p_acty_base_rt_id        => p_acty_base_rt_id
8313         ,p_start_date             => p_start_date);
8314     if g_debug then
8315         hr_utility.set_location(' DN ECSDCD DETDT_MN '||l_proc , 630);
8316     end if;
8317     --
8318     end if;
8319     --
8320 /*
8321     -- ikasire - l_enrt_cvg_strt_dt is passed as a parameter for p_start_date
8322     -- to determinate the cvg end date which depends on cvg strt dt.
8323     -- Testing Only for 'WALDCSM'
8324     if l_enrt_cvg_end_dt_cd in ('WALDCSM','LWALDCSM', 'LWALDCM',
8325                                 'LWALDCPP','LWALDCPPY','LWALDLPPEPPY',
8326                                 'LWEM','LWODBED','WAED','WALDCM' ,
8327                                 'WALDCPP','WALDCPPY','WALDLPPEPPY',
8328                                 'WEM','WODBED' )
8329     then
8330       hr_utility.set_location('pasing start date '||l_enrt_cvg_strt_dt , 199);
8331       l_pass_cvg_strt_dt := l_enrt_cvg_strt_dt ;
8332     else
8333       l_pass_cvg_strt_dt := p_start_date ;
8334     end if;
8335 */
8336     l_pass_cvg_strt_dt := p_start_date ;
8337     --
8338     if (l_enrt_cvg_end_dt_cd is not NULL) then
8339       hr_utility.set_location(' ECEDCD DETDT_MN '||l_proc , 610);
8340       main
8341         (p_cache_mode             => p_cache_mode
8342         ,p_date_cd                => l_enrt_cvg_end_dt_cd
8343         ,p_formula_id             => l_enrt_cvg_end_dt_rl
8344         ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8345         ,p_business_group_id      => p_business_group_id
8346         ,p_effective_date         => p_effective_date
8347         ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
8348         ,p_per_in_ler_id          => l_per_in_ler_id
8349         ,p_person_id              => l_person_id
8350         ,p_pgm_id                 => l_pgm_id
8351         ,p_pl_id                  => l_pl_id
8352         ,p_oipl_id                => l_oipl_id
8353         ,p_acty_base_rt_id        => p_acty_base_rt_id
8354         ,p_start_date             => l_pass_cvg_strt_dt
8355         ,p_returned_date          => l_enrt_cvg_end_dt
8356         );
8357     --  hr_utility.set_location(' Dn ECEDCD DETDT_MN '||l_proc , 610);
8358       --
8359     end if;
8360     --
8361 
8362     -- rate start date calcualted before the end date
8363     if l_rt_strt_dt_cd is not NULL then
8364       if g_debug then
8365         hr_utility.set_location(' SDC DETDT_MN '||l_proc , 670);
8366       end if;
8367       --
8368       -- Passing Enrollment coverage
8369       --
8370       if l_enrt_cvg_strt_dt is not null then
8371         --
8372         l_pass_cvg_strt_dt := l_enrt_cvg_strt_dt ;
8373         --
8374       else
8375         --
8376         l_pass_cvg_strt_dt := p_start_date ;
8377         --
8378       end if;
8379       --
8380       main
8381         (p_cache_mode             => p_cache_mode
8382         ,p_date_cd                => l_rt_strt_dt_cd
8383         ,p_formula_id             => l_rt_strt_dt_rl
8384         ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8385         ,p_business_group_id      => p_business_group_id
8386         ,p_effective_date         => p_effective_date
8387         ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
8388         ,p_returned_date          => l_rt_strt_dt
8389         ,p_per_in_ler_id          => l_per_in_ler_id
8390         ,p_person_id              => l_person_id
8391         ,p_pgm_id                 => l_pgm_id
8392         ,p_pl_id                  => l_pl_id
8393         ,p_oipl_id                => l_oipl_id
8394         ,p_acty_base_rt_id        => p_acty_base_rt_id
8395         ,p_start_date             => l_pass_cvg_strt_dt );
8396 
8397       if g_debug then
8398         hr_utility.set_location(' rate start date =  '||l_rt_strt_dt , 1687);
8399       end if;
8400       if g_debug then
8401         hr_utility.set_location(' Dn SDC DETDT_MN '||l_proc , 670);
8402       end if;
8403       --- assign the fonm rat from the rate so the end date rule can use the fonm value
8404       if ben_manage_life_events.fonm  = 'Y'  or  l_fonm_cvg_strt_dt is not null then
8405          if ben_manage_life_events.g_fonm_rt_strt_dt is null or
8406             ben_manage_life_events.g_fonm_rt_strt_dt <> l_rt_strt_dt then
8407              ben_manage_life_events.g_fonm_rt_strt_dt :=  l_rt_strt_dt ;
8408          end if ;
8409          hr_utility.set_location('FONM gr date  ' ||  ben_manage_life_events.g_fonm_rt_strt_dt  , 60);
8410       end if ;
8411 
8412     end if;
8413 
8414 
8415     if l_rt_end_dt_cd is not NULL then
8416       -- There are rate end dates that are based on the coverage end date.
8417       -- Since we haven't updated the result yet, we need to pass the cvg end date
8418       -- into main.  Bug 1155069.
8419       if l_enrt_cvg_end_dt is not null then
8420          l_pass_cvg_end_dt := l_enrt_cvg_end_dt;
8421       else
8422          -- otherwise pass in the start date that was passed in to this proc.
8423          l_pass_cvg_end_dt := p_start_date;
8424       end if;
8425       --
8426       -- Bug 1647095.
8427       -- The case when coverage end date is enterable, then the actual
8428       -- coverage end date should come from the api.
8429       --
8430       if l_enrt_cvg_end_dt_cd = 'ENTRBL' and p_end_date is not null then
8431         l_pass_cvg_end_dt := p_end_date;
8432       end if;
8433       --
8434       if g_debug then
8435         hr_utility.set_location(' EDC DETDT_MN '||l_proc , 650);
8436       end if;
8437       main
8438         (p_cache_mode             => p_cache_mode
8442         ,p_business_group_id      => p_business_group_id
8439         ,p_date_cd                => l_rt_end_dt_cd
8440         ,p_formula_id             => l_rt_end_dt_rl
8441         ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8443         ,p_effective_date         => p_effective_date
8444         ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
8445         ,p_returned_date          => l_rt_end_dt
8446         ,p_per_in_ler_id          => l_per_in_ler_id
8447         ,p_person_id              => l_person_id
8448         ,p_pgm_id                 => l_pgm_id
8449         ,p_pl_id                  => l_pl_id
8450         ,p_oipl_id                => l_oipl_id
8451         ,p_acty_base_rt_id        => p_acty_base_rt_id
8452         ,p_start_date             => l_pass_cvg_end_dt);
8453       if g_debug then
8454         hr_utility.set_location(' Dn EDC DETDT_MN '||l_proc , 650);
8455       end if;
8456 
8457     end if;
8458     --
8459     -- rate start date moved above end date to detdermine the fomn_dt_strt_Dt
8460     -- when calc rt_end_dt_cd
8461 
8462 
8463 
8464     -- In case of the rate end date codes which depend on rate start date codes
8465     -- LODBEWM and ODBEWM. Presently rt_end_dt is coming out of a cursor using
8466     -- ben_enrt_rt table. If rt_strt_dt_cd is stored in that table instead of
8467     -- rt_strt_dt we get a null . So our plan is to get the rt_end_dt from
8468     -- rt_strt_dt - 1 , if the above codes are used and the result is null
8469     --
8470     if l_rt_end_dt_cd = 'LODBEWM' or l_rt_end_dt_cd = 'ODBEWM'
8471     then
8472        --
8473        if l_rt_end_dt is null
8474        then
8475           if g_debug then
8476             hr_utility.set_location('Special condition for LODBEWM ODBEWM ', 199);
8477           end if;
8478           l_rt_end_dt := l_rt_strt_dt - 1 ;
8479           if g_debug then
8480             hr_utility.set_location('l_rt_end_dt '||l_rt_end_dt , 199) ;
8481           end if;
8482        end if;
8483        --
8484     end if;
8485     --
8486     if l_rt_strt_dt_cd in ( 'FDSMCFES' , 'FDSMFES' , 'LFMESMES'  )
8487        and l_rt_strt_dt is NULL
8488     then
8489       --
8490     if(ben_manage_life_events.g_bckdt_per_in_ler_id is not NULL
8491        and l_rt_strt_dt_cd in ('LFMESMES') ) then
8492             open c_rt_dts_bckdt(ben_manage_life_events.g_bckdt_per_in_ler_id);
8493 	          fetch c_rt_dts_bckdt into l_rt_strt_dt,
8494 	                                    l_rt_end_dt;
8495 	    --
8496 	        close c_rt_dts_bckdt;
8497 
8498             if l_rt_strt_dt is null then
8499 	              l_rt_strt_dt:=p_effective_date;
8500 	              end if;
8501    elsif l_rt_strt_dt_cd = 'FDSMCFES'
8502          and to_number(to_char(l_enrt_cvg_strt_dt, 'DD')) in ( 1, 16 )
8503       then
8504         --
8505         l_rt_strt_dt := l_enrt_cvg_strt_dt ;
8506         if g_debug then
8507           hr_utility.set_location('Case 1',15);
8508         end if;
8509         --
8510       elsif to_char(l_enrt_cvg_strt_dt, 'DD') > 15 then
8511         --
8512         l_rt_strt_dt := round(l_enrt_cvg_strt_dt,'Month')  ;
8513         if g_debug then
8514           hr_utility.set_location('Case 2',15);
8515         end if;
8516         --
8517       else
8518         --
8519         l_rt_strt_dt := round(l_enrt_cvg_strt_dt,'Month') + 15 ;
8520         if g_debug then
8521           hr_utility.set_location('Case 3'||l_enrt_cvg_strt_dt,15);
8522         end if;
8523 
8524         --
8525       end if;
8526       --
8527     end if;
8528   --
8529   end if;
8530 
8531   --
8532   -- If date is set null out code and rule
8533   --
8534   if l_rt_strt_dt is not null and
8535      (not do_date_at_enrollment(l_rt_strt_dt_cd)) and
8536      p_date_mandatory_flag='N' then
8537     if g_debug then
8538       hr_utility.set_location(l_proc , 700);
8539     end if;
8540     l_rt_strt_dt_cd:=null;
8541     l_rt_strt_dt_rl:=null;
8542   end if;
8543   --
8544   if l_rt_end_dt is not null and
8545      (not do_date_at_enrollment(l_rt_end_dt_cd)) and
8546      p_date_mandatory_flag='N' then
8547     if g_debug then
8548       hr_utility.set_location(l_proc , 720);
8549     end if;
8550     l_rt_end_dt_cd:=null;
8551     l_rt_end_dt_rl:=null;
8552   end if;
8553   --
8554   if l_enrt_cvg_strt_dt is not null and
8555      (not do_date_at_enrollment(l_enrt_cvg_strt_dt_cd)) and
8556      p_date_mandatory_flag='N' then
8557     if g_debug then
8558       hr_utility.set_location(l_proc , 740);
8559     end if;
8560     l_enrt_cvg_strt_dt_cd:=null;
8561     l_enrt_cvg_strt_dt_rl:=null;
8562   end if;
8563   --
8564   if l_enrt_cvg_end_dt is not null and
8565      (not do_date_at_enrollment(l_enrt_cvg_end_dt_cd)) and
8566      p_date_mandatory_flag ='N' then
8567     if g_debug then
8568       hr_utility.set_location(l_proc , 760);
8569     end if;
8570     l_enrt_cvg_end_dt_cd:=null;
8571     l_enrt_cvg_end_dt_rl:=null;
8572   end if;
8573   --
8574   -- if p_date_mandatory_flag is set to Y generate appropriate
8575   -- message if the hard date is not found.
8576   -- That is all. Have a happy day.
8577   --
8578 
8579   if p_date_mandatory_flag='Y' and
8580      p_compute_dates_flag='Y' then
8581     if g_debug then
8582       hr_utility.set_location(l_proc , 780);
8583     end if;
8584 
8585     -- Bug No 3965571 : All ids are replaced by their names in the error message's tokens.
8586 
8587     if p_which_dates_cd in ('R','B') and
8588        l_rt_strt_dt is null then
8589       if g_debug then
8590         hr_utility.set_location('BEN_91455_RT_STRT_DT_NOT_FOUND',37);
8591       end if;
8592       fnd_message.set_name('BEN','BEN_91455_RT_STRT_DT_NOT_FOUND');
8596       fnd_message.set_token('OIPL_ID',l_opt_name);
8593       fnd_message.set_token('PLAN_ID',l_pln_name);
8594       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8595       fnd_message.set_token('PGM_ID',l_pgm_name);
8597       fnd_message.raise_error;
8598     elsif p_which_dates_cd in ('R','B') and
8599           l_rt_end_dt is null then
8600       if g_debug then
8601         hr_utility.set_location('BEN_91703_NOT_DET_RATE_END_DT',37);
8602       end if;
8603       fnd_message.set_name('BEN','BEN_91703_NOT_DET_RATE_END_DT');
8604       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8605       fnd_message.set_token('PGM_ID',l_pgm_name);
8606       fnd_message.set_token('PL_ID',l_pln_name);
8607       fnd_message.set_token('OIPL_ID',l_opt_name);
8608       fnd_message.raise_error;
8609     elsif p_which_dates_cd in ('C','B') and
8610         l_enrt_cvg_strt_dt is null then
8611       if g_debug then
8612         hr_utility.set_location('BEN_91453_CVG_STRT_DT_NOT_FOUN',37);
8613       end if;
8614       fnd_message.set_name('BEN','BEN_91453_CVG_STRT_DT_NOT_FOUN');
8615       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8616       fnd_message.set_token('PGM_ID',l_pgm_name);
8617       fnd_message.set_token('PLAN_ID',l_pln_name);
8618       fnd_message.set_token('OIPL_ID',l_opt_name);
8619       fnd_message.raise_error;
8620     elsif p_which_dates_cd in ('C','B') and
8621           l_enrt_cvg_end_dt is null then
8622       if g_debug then
8623         hr_utility.set_location('BEN_91702_NOT_DET_CVG_END_DT',37);
8624       end if;
8625       fnd_message.set_name('BEN','BEN_91702_NOT_DET_CVG_END_DT');
8626       fnd_message.set_token('PERSON_ID',to_char(l_person_id));
8627       fnd_message.set_token('PGM_ID',l_pgm_name);
8628       fnd_message.set_token('PL_ID',l_pln_name);
8629       fnd_message.set_token('OIPL_ID',l_opt_name);
8630       fnd_message.raise_error;
8631     end if;
8632 
8633   end if;
8634   --
8635   -- Move the results back into the out parms
8636   --
8637   p_rt_strt_dt:=l_rt_strt_dt;
8638   p_rt_strt_dt_cd:=l_rt_strt_dt_cd;
8639   p_rt_strt_dt_rl:=l_rt_strt_dt_rl;
8640   p_rt_end_dt:=l_rt_end_dt;
8641   p_rt_end_dt_cd:=l_rt_end_dt_cd;
8642   p_rt_end_dt_rl:=l_rt_end_dt_rl;
8643   p_enrt_cvg_strt_dt:=l_enrt_cvg_strt_dt;
8644   p_enrt_cvg_strt_dt_cd:=l_enrt_cvg_strt_dt_cd;
8645   p_enrt_cvg_strt_dt_rl:=l_enrt_cvg_strt_dt_rl;
8646   p_enrt_cvg_end_dt:=l_enrt_cvg_end_dt;
8647   p_enrt_cvg_end_dt_cd:=l_enrt_cvg_end_dt_cd;
8648   p_enrt_cvg_end_dt_rl:=l_enrt_cvg_end_dt_rl;
8649   --
8650 --  hr_utility.set_location(' Leaving:'||l_proc, 930);
8651 --
8652 
8653 exception   -- nocopy changes
8654   --
8655   when others then
8656     --
8657     p_enrt_cvg_strt_dt         := null;
8658     p_enrt_cvg_strt_dt_cd      := null;
8659     p_enrt_cvg_strt_dt_rl      := null;
8660     p_rt_strt_dt               := null;
8661     p_rt_strt_dt_cd            := null;
8662     p_rt_strt_dt_rl            := null;
8663     p_enrt_cvg_end_dt          := null;
8664     p_enrt_cvg_end_dt_cd       := null;
8665     p_enrt_cvg_end_dt_rl       := null;
8666     p_rt_end_dt                := null;
8667     p_rt_end_dt_cd             := null;
8668     p_rt_end_dt_rl             := null;
8669     raise;
8670     --
8671 end rate_and_coverage_dates;
8672 --
8673 function do_date_at_enrollment(p_date_cd in varchar2) return boolean is
8674 begin
8675   if p_date_cd in ('ODEWM'
8676                   , 'LELD'
8677                   , 'LELDED'
8678                   , 'ENTRBL'
8679                   , 'WAENT'
8680 		  , 'ENTRBLFD' -- ICD ENH
8681                   , 'RL'   --  Bug 2122643
8682                   , 'LDPPFEFD'
8683                   , 'LDPPOEFD'
8684                   , 'FDPPFED'
8685                   , 'FDPPOED'
8686                   , 'AFDELD'
8687                   , 'FDMELD'
8688                   , 'FDPPFCDEL'
8689                   , 'FDPPELD'
8690                   , 'WAPPDEL'
8691                   ) then
8692     return true;
8693   else
8694     return false;
8695   end if;
8696   -- defense
8697   return true;
8698 end do_date_at_enrollment;
8699 --
8700 procedure rate_and_coverage_dates_nc
8701   (p_per_in_ler_id          in     number  default null
8702   ,p_person_id              in     number  default null
8703   ,p_pgm_id                 in     number  default null
8704   ,p_pl_id                  in     number  default null
8705   ,p_oipl_id                in     number  default null
8706   ,p_par_ptip_id            in     number  default null
8707   ,p_par_plip_id            in     number  default null
8708   ,p_lee_rsn_id             in     number  default null
8709   ,p_enrt_perd_id           in     number  default null
8710   ,p_enrt_perd_for_pl_id    in     number  default null
8711   ,p_which_dates_cd         in     varchar2      default 'B'
8712   ,p_date_mandatory_flag    in     varchar2      default 'Y'
8713   ,p_compute_dates_flag     in     varchar2      default 'Y'
8714   ,p_elig_per_elctbl_chc_id in     number  default null
8715   ,p_acty_base_rt_id        in     number  default null
8716   ,p_business_group_id      in     number
8717   ,p_start_date             in     date    default null
8718   ,p_end_date               in     date    default null
8719   ,p_effective_date         in     date
8720   ,p_lf_evt_ocrd_dt         in     date    default null
8721   ,p_enrt_cvg_strt_dt          out nocopy date
8722   ,p_enrt_cvg_strt_dt_cd       out nocopy varchar2
8723   ,p_enrt_cvg_strt_dt_rl       out nocopy number
8724   ,p_rt_strt_dt                out nocopy date
8725   ,p_rt_strt_dt_cd             out nocopy varchar2
8726   ,p_rt_strt_dt_rl             out nocopy number
8727   ,p_enrt_cvg_end_dt           out nocopy date
8728   ,p_enrt_cvg_end_dt_cd        out nocopy varchar2
8729   ,p_enrt_cvg_end_dt_rl        out nocopy number
8733   ) is
8730   ,p_rt_end_dt                 out nocopy date
8731   ,p_rt_end_dt_cd              out nocopy varchar2
8732   ,p_rt_end_dt_rl              out nocopy number
8734   begin
8735     --
8736     rate_and_coverage_dates
8737       (p_per_in_ler_id          => p_per_in_ler_id
8738       ,p_person_id              => p_person_id
8739       ,p_pgm_id                 => p_pgm_id
8740       ,p_pl_id                  => p_pl_id
8741       ,p_oipl_id                => p_oipl_id
8742       ,p_par_ptip_id            => p_par_ptip_id
8743       ,p_par_plip_id            => p_par_plip_id
8744       ,p_lee_rsn_id             => p_lee_rsn_id
8745       ,p_enrt_perd_id           => p_enrt_perd_id
8746       ,p_enrt_perd_for_pl_id    => p_enrt_perd_for_pl_id
8747       ,p_which_dates_cd         =>p_which_dates_cd
8748       ,p_date_mandatory_flag    => p_date_mandatory_flag
8749       ,p_compute_dates_flag     => p_compute_dates_flag
8750       ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8751       ,p_acty_base_rt_id        => p_acty_base_rt_id
8752       ,p_business_group_id      => p_business_group_id
8753       ,p_start_date             => p_start_date
8754       ,p_end_date               =>  p_end_date
8755       ,p_effective_date         => p_effective_date
8756       ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
8757       ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt
8758       ,p_enrt_cvg_strt_dt_cd     => p_enrt_cvg_strt_dt_cd
8759       ,p_enrt_cvg_strt_dt_rl     => p_enrt_cvg_strt_dt_rl
8760       ,p_rt_strt_dt              => p_rt_strt_dt
8761       ,p_rt_strt_dt_cd            => p_rt_strt_dt_cd
8762       ,p_rt_strt_dt_rl            => p_rt_strt_dt_rl
8763       ,p_enrt_cvg_end_dt          => p_enrt_cvg_end_dt
8764       ,p_enrt_cvg_end_dt_cd       => p_enrt_cvg_end_dt_cd
8765       ,p_enrt_cvg_end_dt_rl       => p_enrt_cvg_end_dt_rl
8766       ,p_rt_end_dt                => p_rt_end_dt
8767       ,p_rt_end_dt_cd             => p_rt_end_dt_cd
8768       ,p_rt_end_dt_rl             => p_rt_end_dt_rl
8769    );
8770   end rate_and_coverage_dates_nc ;
8771   --
8772 END ben_determine_date;