DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_LF_EVT_CLPS_RESTORE

Source


1 package body ben_lf_evt_clps_restore as
2 /* $Header: benleclr.pkb 120.58.12020000.8 2013/01/01 15:03:04 amnaraya ship $ */
3 --
4 -- Package Variables
5 --
6 g_package  varchar2(33) := '  ben_lf_evt_clps_restore.';
7 --
8 g_sys_date date := trunc(sysdate);
9 g_bckt_csd_lf_evt_ocrd_dt date;
10 --
11 type g_pgm_rec is record
12        (pgm_id              ben_pgm_f.pgm_id%type,
13         enrt_mthd_cd        ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
14         multi_row_edit_done boolean,
15         non_automatics_flag boolean,
16         max_enrt_esd        date);
17 --
18 type g_pl_rec is record
19        (pl_id               ben_pl_f.pl_id%type,
20         enrt_mthd_cd        ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
21         multi_row_edit_done boolean,
22         max_enrt_esd        date);
23 --
24 type g_enrt_rec is record
25        (prtt_enrt_rslt_id        ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
26         bckdt_prtt_enrt_rslt_id  ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
27         bckdt_enrt_ovridn_flag   varchar2(1),
28         bckdt_enrt_cvg_strt_dt   date,
29         bckdt_enrt_cvg_thru_dt   date,
30         enrt_ovrid_thru_dt       date,
31 	--Bug 13355114
32         bckdt_sspndd_flag varchar2(1),
33         bckdt_RPLCS_SSPNDD_RSLT_ID number,
34 	--Bug 13355114
35         enrt_ovrid_rsn_cd        ben_prtt_enrt_rslt_f.enrt_ovrid_rsn_cd%type,
36         g_sys_date               date,
37         pen_ovn_number           ben_prtt_enrt_rslt_f.object_version_number%type,
38         old_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
39         new_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
40         old_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
41         new_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
42         old_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
43         new_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
44         pgm_id                   ben_prtt_enrt_rslt_f.pgm_id%type,
45         ler_id                   ben_ler_f.ler_id%type,
46         elig_per_elctbl_chc_id   ben_elig_per_elctbl_chc.elig_per_elctbl_chc_id%type,
47         dpnt_cvg_strt_dt_cd      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_cd%type,
48         dpnt_cvg_strt_dt_rl      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_rl%type,
49         effective_start_date     ben_prtt_enrt_rslt_f.effective_start_date%type,
50 	reinstate_flag varchar2(1) DEFAULT 'N',
51 	enrt_mthd_cd             varchar2(1) -- Bug 9045559
52         );
53 --
54 type g_pgm_table  is table of g_pgm_rec  index by binary_integer;
55 type g_pl_table   is table of g_pl_rec   index by binary_integer;
56 type g_enrt_table is table of g_enrt_rec index by binary_integer;
57 
58 --
59 --Start Private Cursors
60   cursor g_bckdt_pen(
61            c_bckdt_per_in_ler_id number,
62            c_person_id           number,
63            c_effective_date      date,
64            c_pgm_id              number,
65            c_pl_id               number )
66            is
67    select
68           pen.EFFECTIVE_END_DATE,
69           pen.ASSIGNMENT_ID,
70           pen.BNFT_AMT,
71           pen.BNFT_NNMNTRY_UOM,
72           pen.BNFT_ORDR_NUM,
73           pen.BNFT_TYP_CD,
74           pen.BUSINESS_GROUP_ID,
75           pen.COMP_LVL_CD,
76           pen.CREATED_BY,
77           pen.CREATION_DATE,
78           pen.EFFECTIVE_START_DATE,
79           pen.ENRT_CVG_STRT_DT,
80           pen.ENRT_CVG_THRU_DT,
81           pen.ENRT_MTHD_CD,
82           pen.ENRT_OVRIDN_FLAG,
83           pen.ENRT_OVRID_RSN_CD,
84           pen.ENRT_OVRID_THRU_DT,
85           pen.ERLST_DEENRT_DT,
86           pen.LAST_UPDATED_BY,
87           pen.LAST_UPDATE_DATE,
88           pen.LAST_UPDATE_LOGIN,
89           pen.LER_ID,
90           pen.NO_LNGR_ELIG_FLAG,
91           pen.OBJECT_VERSION_NUMBER,
92           pen.OIPL_ID,
93           pen.OIPL_ORDR_NUM,
94           pen.ORGNL_ENRT_DT,
95           pen.PEN_ATTRIBUTE1,
96           pen.PEN_ATTRIBUTE10,
97           pen.PEN_ATTRIBUTE11,
98           pen.PEN_ATTRIBUTE12,
99           pen.PEN_ATTRIBUTE13,
100           pen.PEN_ATTRIBUTE14,
101           pen.PEN_ATTRIBUTE15,
102           pen.PEN_ATTRIBUTE16,
103           pen.PEN_ATTRIBUTE17,
104           pen.PEN_ATTRIBUTE18,
105           pen.PEN_ATTRIBUTE19,
106           pen.PEN_ATTRIBUTE2,
107           pen.PEN_ATTRIBUTE20,
108           pen.PEN_ATTRIBUTE21,
109           pen.PEN_ATTRIBUTE22,
110           pen.PEN_ATTRIBUTE23,
111           pen.PEN_ATTRIBUTE24,
112           pen.PEN_ATTRIBUTE25,
113           pen.PEN_ATTRIBUTE26,
114           pen.PEN_ATTRIBUTE27,
115           pen.PEN_ATTRIBUTE28,
116           pen.PEN_ATTRIBUTE29,
117           pen.PEN_ATTRIBUTE3,
118           pen.PEN_ATTRIBUTE30,
119           pen.PEN_ATTRIBUTE4,
120           pen.PEN_ATTRIBUTE5,
121           pen.PEN_ATTRIBUTE6,
122           pen.PEN_ATTRIBUTE7,
123           pen.PEN_ATTRIBUTE8,
124           pen.PEN_ATTRIBUTE9,
125           pen.PEN_ATTRIBUTE_CATEGORY,
126           pen.PERSON_ID,
127           pen.PER_IN_LER_ID,
128           pen.PGM_ID,
129           pen.PLIP_ORDR_NUM,
130           pen.PL_ID,
131           pen.PL_ORDR_NUM,
132           pen.PL_TYP_ID,
133           pen.PROGRAM_APPLICATION_ID,
134           pen.PROGRAM_ID,
135           pen.PROGRAM_UPDATE_DATE,
136           pen.PRTT_ENRT_RSLT_ID,
137           pen.PRTT_ENRT_RSLT_STAT_CD,
138           pen.PRTT_IS_CVRD_FLAG,
139           pen.PTIP_ID,
140           pen.PTIP_ORDR_NUM,
141           pen.REQUEST_ID,
142           pen.RPLCS_SSPNDD_RSLT_ID,
143           pen.SSPNDD_FLAG,
144           pen.UOM
145     from   ben_prtt_enrt_rslt_f pen,
146            ben_per_in_ler pil,
147            ben_pil_elctbl_chc_popl pel --Added for Bug 4423161
148     where  pil.per_in_ler_id       = c_bckdt_per_in_ler_id
149     and    pil.person_id           = c_person_id
150     and    pil.per_in_ler_id       = pen.per_in_ler_id
151     and    pil.per_in_ler_id       = pel.per_in_ler_id
152     and    ((pel.pgm_id is null and c_pgm_id is null) or
153              pel.pgm_id = c_pgm_id )
154     and    ( c_pl_id is null or
155              pel.pl_id = c_pl_id )
156     and    (pel.dflt_asnd_dt is not null or
157             pel.elcns_made_dt is not null or
158 	    pel.auto_asnd_dt is not null) -- Bug 8305552, Check for Automatic Enrolled Plans
159     --To Handle Programs and  Plans not in Program
160     and    ((pen.pgm_id is null and c_pgm_id is null) or
161              pen.pgm_id = c_pgm_id )
162     and    ( c_pl_id is null or
163              pen.pl_id = c_pl_id )
164     and    (pen.effective_end_date = hr_api.g_eot or
165             pen.effective_end_date = (select max(effective_end_date)
166                                         from ben_prtt_enrt_rslt_f
167                                        where prtt_enrt_rslt_id =
168                                                          pen.prtt_enrt_rslt_id))
169     and    (pen.enrt_cvg_thru_dt is null or
170             pen.enrt_cvg_thru_dt    = hr_api.g_eot
171            )
172     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
173     and pen.prtt_enrt_rslt_id not in (
174          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
175            from   ben_prtt_enrt_rslt_f pen_inner,
176                   ben_per_in_ler pil_inner
177            where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
178            and    pil_inner.person_id           = c_person_id
179            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
180            and    (pen_inner.enrt_cvg_thru_dt is null or
181                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
182                   )
183            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
184          union
185          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
186              from  ben_le_clsn_n_rstr  pen_inner,
187                     ben_per_in_ler pil_inner
188              where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
189              and    pil_inner.person_id           = c_person_id
190              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
191              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
192            and    (pen_inner.enrt_cvg_thru_dt is null or
193                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
194                   )
195            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
196        )
197    union
198    select
199           pen.EFFECTIVE_END_DATE,
200           pen.ASSIGNMENT_ID,
201           pen.BNFT_AMT,
202           pen.BNFT_NNMNTRY_UOM,
203           pen.BNFT_ORDR_NUM,
204           pen.BNFT_TYP_CD,
205           pen.BUSINESS_GROUP_ID,
206           pen.COMP_LVL_CD,
207           pen.CREATED_BY,
208           pen.CREATION_DATE,
209           pen.EFFECTIVE_START_DATE,
210           pen.ENRT_CVG_STRT_DT,
211           pen.ENRT_CVG_THRU_DT,
212           pen.ENRT_MTHD_CD,
213           pen.ENRT_OVRIDN_FLAG,
214           pen.ENRT_OVRID_RSN_CD,
215           pen.ENRT_OVRID_THRU_DT,
216           pen.ERLST_DEENRT_DT,
217           pen.LAST_UPDATED_BY,
218           pen.LAST_UPDATE_DATE,
219           pen.LAST_UPDATE_LOGIN,
220           pen.LER_ID,
221           pen.NO_LNGR_ELIG_FLAG,
222           pen.OBJECT_VERSION_NUMBER,
223           pen.OIPL_ID,
224           pen.OIPL_ORDR_NUM,
225           pen.ORGNL_ENRT_DT,
226           pen.LCR_ATTRIBUTE1,
227           pen.LCR_ATTRIBUTE10,
228           pen.LCR_ATTRIBUTE11,
229           pen.LCR_ATTRIBUTE12,
230           pen.LCR_ATTRIBUTE13,
231           pen.LCR_ATTRIBUTE14,
232           pen.LCR_ATTRIBUTE15,
233           pen.LCR_ATTRIBUTE16,
234           pen.LCR_ATTRIBUTE17,
235           pen.LCR_ATTRIBUTE18,
236           pen.LCR_ATTRIBUTE19,
237           pen.LCR_ATTRIBUTE2,
238           pen.LCR_ATTRIBUTE20,
239           pen.LCR_ATTRIBUTE21,
240           pen.LCR_ATTRIBUTE22,
241           pen.LCR_ATTRIBUTE23,
242           pen.LCR_ATTRIBUTE24,
243           pen.LCR_ATTRIBUTE25,
244           pen.LCR_ATTRIBUTE26,
245           pen.LCR_ATTRIBUTE27,
246           pen.LCR_ATTRIBUTE28,
247           pen.LCR_ATTRIBUTE29,
248           pen.LCR_ATTRIBUTE3,
249           pen.LCR_ATTRIBUTE30,
250           pen.LCR_ATTRIBUTE4,
251           pen.LCR_ATTRIBUTE5,
252           pen.LCR_ATTRIBUTE6,
253           pen.LCR_ATTRIBUTE7,
254           pen.LCR_ATTRIBUTE8,
255           pen.LCR_ATTRIBUTE9,
256           pen.LCR_ATTRIBUTE_CATEGORY,
257           pen.PERSON_ID,
258           pen.PER_IN_LER_ID,
259           pen.PGM_ID,
260           pen.PLIP_ORDR_NUM,
261           pen.PL_ID,
262           pen.PL_ORDR_NUM,
263           pen.PL_TYP_ID,
264           pen.PROGRAM_APPLICATION_ID,
265           pen.PROGRAM_ID,
266           pen.PROGRAM_UPDATE_DATE,
267           pen.bkup_tbl_id, -- Mapped to PRTT_ENRT_RSLT_ID,
268           pen.PRTT_ENRT_RSLT_STAT_CD,
269           pen.PRTT_IS_CVRD_FLAG,
270           pen.PTIP_ID,
271           pen.PTIP_ORDR_NUM,
272           pen.REQUEST_ID,
273           pen.RPLCS_SSPNDD_RSLT_ID,
274           pen.SSPNDD_FLAG,
275           pen.UOM
276     from  ben_le_clsn_n_rstr  pen,
277           ben_per_in_ler pil,
278           ben_pil_elctbl_chc_popl pel   --Added for Bug 4423161
279     where  pil.per_in_ler_id       = c_bckdt_per_in_ler_id
280     and    pil.person_id           = c_person_id
281     and    pil.per_in_ler_id       = pel.per_in_ler_id
282     and    ((pel.pgm_id is null and c_pgm_id is null) or
283              pel.pgm_id = c_pgm_id )
284     and    ( c_pl_id is null or
285              pel.pl_id = c_pl_id )
286     and    (pel.dflt_asnd_dt is not null or
287             pel.elcns_made_dt is not null or
288 	    pel.auto_asnd_dt is not null) -- Bug 8305552, Check for Automatic Enrolled Plans
289     AND    pil.per_in_ler_id       = pen.per_in_ler_id
290     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
291     --To Handle Programs and  Plans not in Program
292     and    ((pen.pgm_id is null and c_pgm_id is null) or
293              pen.pgm_id = c_pgm_id )
294     and    ( c_pl_id is null or
295              pen.pl_id = c_pl_id )
296     and    ((pen.enrt_cvg_thru_dt is null or
297             pen.enrt_cvg_thru_dt    = hr_api.g_eot)  and
298             pen.effective_end_date  = hr_api.g_eot
299            )
300     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
301     and pen.bkup_tbl_id not in (
302          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
303            from   ben_prtt_enrt_rslt_f pen_inner,
304                   ben_per_in_ler pil_inner
305            where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
306            and    pil_inner.person_id           = c_person_id
307            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
308            and    (pen_inner.enrt_cvg_thru_dt is null or
309                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
310                   )
311            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
312          union
313          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
314              from  ben_le_clsn_n_rstr  pen_inner,
315                     ben_per_in_ler pil_inner
316              where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
317              and    pil_inner.person_id           = c_person_id
318              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
319              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
320            and    (pen_inner.enrt_cvg_thru_dt is null or
321                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
322                   )
323            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
324        )
325     order by 1;
326   --
327   TYPE g_bckdt_pen_tbl is TABLE OF g_bckdt_pen%rowtype INDEX BY BINARY_INTEGER;
328 
329 
330   /* Bug 8900007: Cursor g_bckdt_pen_sspnd_rslt is used to fetch all the
331   carry forward enrollments created for the backedout LE */
332   cursor g_bckdt_pen_sspnd_rslt(
333            c_bckdt_per_in_ler_id number,
334            c_person_id           number,
335            c_effective_date      date)
336            is
337    select
338           pen.EFFECTIVE_END_DATE,
339           pen.BUSINESS_GROUP_ID,
340           pen.EFFECTIVE_START_DATE,
341           pen.ENRT_CVG_STRT_DT,
342           pen.ENRT_CVG_THRU_DT,
343           pen.ENRT_MTHD_CD,
344           pen.OBJECT_VERSION_NUMBER,
345           pen.OIPL_ID,
346           pen.PERSON_ID,
347           pen.PER_IN_LER_ID,
348           pen.PGM_ID,
349           pen.PL_ID,
350           pen.PL_TYP_ID,
351           pen.PRTT_ENRT_RSLT_ID,
352           pen.PRTT_ENRT_RSLT_STAT_CD,
353           pen.PTIP_ID,
354           pen.RPLCS_SSPNDD_RSLT_ID,
355           pen.SSPNDD_FLAG
356     from   ben_prtt_enrt_rslt_f pen,
357            ben_per_in_ler pil,
358            ben_pil_elctbl_chc_popl pel --Added for Bug 4423161
359     where  pil.per_in_ler_id       = c_bckdt_per_in_ler_id
360     and    pil.person_id           = c_person_id
361     and    pil.per_in_ler_id       = pen.per_in_ler_id
362     and    pil.per_in_ler_id       = pel.per_in_ler_id
363     and    (pel.dflt_asnd_dt is null and
364             pel.elcns_made_dt is null) -- Bug 8305552, Check for Automatic Enrolled Plans
365     and exists
366                  (select '1' from ben_prtt_enrt_rslt_f epen where
367 	                  epen.per_in_ler_id       = c_bckdt_per_in_ler_id
368 			  and epen.person_id       = c_person_id
369 			  and (epen.enrt_cvg_thru_dt is null or
370                                epen.enrt_cvg_thru_dt    = hr_api.g_eot)
371 			  and epen.effective_end_date  = hr_api.g_eot)
372     --To Handle Programs and  Plans not in Program
373     and    (pen.effective_end_date = hr_api.g_eot or
374             pen.effective_end_date = (select max(effective_end_date)
375                                         from ben_prtt_enrt_rslt_f
376                                        where prtt_enrt_rslt_id =
377                                                          pen.prtt_enrt_rslt_id))
378     and    (pen.enrt_cvg_thru_dt is null or
379             pen.enrt_cvg_thru_dt    = hr_api.g_eot
380            )
381     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
382     and pen.prtt_enrt_rslt_id not in (
383          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
384            from   ben_prtt_enrt_rslt_f pen_inner,
385                   ben_per_in_ler pil_inner
386            where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
387            and    pil_inner.person_id           = c_person_id
388            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
389            and    (pen_inner.enrt_cvg_thru_dt is null or
390                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
391                   )
392            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
393          union
394          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
395              from  ben_le_clsn_n_rstr  pen_inner,
396                     ben_per_in_ler pil_inner
397              where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
398              and    pil_inner.person_id           = c_person_id
399              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
400              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
401            and    (pen_inner.enrt_cvg_thru_dt is null or
402                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
403                   )
404            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
405        )
406    union
407    select
408           pen.EFFECTIVE_END_DATE,
409           pen.BUSINESS_GROUP_ID,
410           pen.EFFECTIVE_START_DATE,
411           pen.ENRT_CVG_STRT_DT,
412           pen.ENRT_CVG_THRU_DT,
413           pen.ENRT_MTHD_CD,
414 	  pen.OBJECT_VERSION_NUMBER,
415           pen.OIPL_ID,
416           pen.PERSON_ID,
417           pen.PER_IN_LER_ID,
418           pen.PGM_ID,
419           pen.PL_ID,
420           pen.PL_TYP_ID,
421           pen.bkup_tbl_id, -- Mapped to PRTT_ENRT_RSLT_ID,
422           pen.PRTT_ENRT_RSLT_STAT_CD,
423           pen.PTIP_ID,
424           pen.RPLCS_SSPNDD_RSLT_ID,
425           pen.SSPNDD_FLAG
426     from  ben_le_clsn_n_rstr  pen,
427           ben_per_in_ler pil,
428           ben_pil_elctbl_chc_popl pel   --Added for Bug 4423161
429     where  pil.per_in_ler_id       = c_bckdt_per_in_ler_id
430     and    pil.person_id           = c_person_id
431     and    pil.per_in_ler_id       = pel.per_in_ler_id
432     and    (pel.dflt_asnd_dt is null and
433             pel.elcns_made_dt is null) -- Bug 8305552, Check for Automatic Enrolled Plans
434     and exists
435                  (select '1' from ben_prtt_enrt_rslt_f epen where
436 	                  epen.per_in_ler_id       = c_bckdt_per_in_ler_id
437 			  and epen.person_id       = c_person_id
438 			  and (epen.enrt_cvg_thru_dt is null or
439                                epen.enrt_cvg_thru_dt    = hr_api.g_eot)
440 			  and epen.effective_end_date  = hr_api.g_eot)
441     AND    pil.per_in_ler_id       = pen.per_in_ler_id
442     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
443     and    ((pen.enrt_cvg_thru_dt is null or
444             pen.enrt_cvg_thru_dt    = hr_api.g_eot)  and
445             pen.effective_end_date  = hr_api.g_eot
446            )
447     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
448     and pen.bkup_tbl_id not in (
449          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
450            from   ben_prtt_enrt_rslt_f pen_inner,
451                   ben_per_in_ler pil_inner
452            where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
453            and    pil_inner.person_id           = c_person_id
454            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
455            and    (pen_inner.enrt_cvg_thru_dt is null or
456                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
457                   )
458            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
459          union
460          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
461              from  ben_le_clsn_n_rstr  pen_inner,
462                     ben_per_in_ler pil_inner
463              where  pil_inner.per_in_ler_id       = c_bckdt_per_in_ler_id
464              and    pil_inner.person_id           = c_person_id
465              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
466              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
467            and    (pen_inner.enrt_cvg_thru_dt is null or
468                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
469                   )
470            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
471        )
472     order by 1;
473   --
474   --
475 --End Private Cursors
476 --
477 function get_epe
478   (p_per_in_ler_id  in     number
479   ,p_pgm_id         in     number
480   ,p_pl_id          in     number
481   ,p_oipl_id        in     number
482   --
483   ) return number
484 is
485   --
486   l_proc varchar2(72) :=  'get_epe';
487   --
488   l_elig_per_elctbl_chc_id number ;
489   --
490   CURSOR c_choice_exists_for_option
491     (c_per_in_ler_id  number
492     ,c_pgm_id         number
493     ,c_oipl_id        number
494     )
495   is
496     SELECT   epe.elig_per_elctbl_chc_id
497     FROM     ben_elig_per_elctbl_chc epe
498     WHERE    epe.oipl_id = c_oipl_id
499     AND      epe.pgm_id = c_pgm_id
500     AND      epe.per_in_ler_id = c_per_in_ler_id;
501   --
502   CURSOR c_chc_exists_for_plnip_option
503     (c_per_in_ler_id  number
504     ,c_oipl_id        number
505     )
506   is
507     SELECT   epe.elig_per_elctbl_chc_id
508     FROM     ben_elig_per_elctbl_chc epe
509     WHERE    epe.oipl_id = c_oipl_id
510     AND      epe.pgm_id IS NULL
511     AND      epe.per_in_ler_id = c_per_in_ler_id;
512   --
513   CURSOR c_choice_exists_for_plan
514     (c_per_in_ler_id number
515     ,c_pgm_id        number
516     ,c_pl_id         number
517     )
518   is
519     SELECT   epe.elig_per_elctbl_chc_id
520     FROM     ben_elig_per_elctbl_chc epe
521     WHERE    epe.pl_id = c_pl_id
522     AND      epe.oipl_id IS NULL
523     AND      epe.pgm_id = c_pgm_id
524     AND      epe.per_in_ler_id = c_per_in_ler_id;
525     --
526   CURSOR c_choice_exists_for_plnip
527     (c_per_in_ler_id number
528     ,c_pl_id         number
529     )
530   is
531     SELECT   epe.elig_per_elctbl_chc_id
532     FROM     ben_elig_per_elctbl_chc epe
533     WHERE    epe.pl_id = c_pl_id
534     AND      epe.oipl_id IS NULL
535     AND      epe.pgm_id IS NULL
536     AND      epe.per_in_ler_id = c_per_in_ler_id;
537     --
538 begin
539   --
540   if p_oipl_id is null
541   then
542     --
543     if p_pgm_id is not null
544     then
545       --
546       OPEN c_choice_exists_for_plan
547         (c_per_in_ler_id  => p_per_in_ler_id
548         ,c_pgm_id         => p_pgm_id
549         ,c_pl_id          => p_pl_id
550         );
551       FETCH c_choice_exists_for_plan INTO l_elig_per_elctbl_chc_id;
552       CLOSE c_choice_exists_for_plan;
553       --
554     else
555       --
556       OPEN c_choice_exists_for_plnip
557         (c_per_in_ler_id  => p_per_in_ler_id
558         ,c_pl_id          => p_pl_id
559         );
560       FETCH c_choice_exists_for_plnip INTO l_elig_per_elctbl_chc_id;
561       CLOSE c_choice_exists_for_plnip;
562       --
563     end if;
564     --
565   else
566     --
567     if p_pgm_id is not null
568     then
569       --
570       OPEN c_choice_exists_for_option
571         (c_per_in_ler_id  => p_per_in_ler_id
572         ,c_pgm_id         => p_pgm_id
573         ,c_oipl_id        => p_oipl_id
574         );
575       FETCH c_choice_exists_for_option INTO l_elig_per_elctbl_chc_id;
576       CLOSE c_choice_exists_for_option;
577       --
578     else
579       --
580       OPEN c_chc_exists_for_plnip_option
581         (c_per_in_ler_id  => p_per_in_ler_id
582         ,c_oipl_id        => p_oipl_id
583         );
584       FETCH c_chc_exists_for_plnip_option INTO l_elig_per_elctbl_chc_id;
585       CLOSE c_chc_exists_for_plnip_option;
586       --
587     end if;
588     --
589   end if;
590   --
591   return l_elig_per_elctbl_chc_id;
592   --
593 end get_epe;
594 --
595 -- ----------------------------------------------------------------------------
596 -- |------------------------< get_ori_bckdt_pil >-------------------------|
597 -- ----------------------------------------------------------------------------
598 --
599 procedure default_comp_obj
600                   (p_validate           in  Boolean default FALSE
601                   ,p_per_in_ler_id      in  Number
602                   ,p_person_id          in  Number
603                   ,p_business_group_id  in  Number
604                   ,p_effective_date     in  Date
605                   ,p_pgm_id             in  Number
606                   ,p_pl_nip_id          in  Number
607                   ,p_susp_flag          out nocopy Boolean
608                   ,p_batch_flag         in  Boolean default FALSE
609                   ,p_cls_enrt_flag      in  Boolean default TRUE
610                   ,p_called_frm_ss      in  Boolean default FALSE
611                   ,p_reinstate_dflts_flag in varchar2 default 'N' -- Enhancement Bug :8716679
612                   ,p_prev_per_in_ler_id in Number default null -- Enhancement Bug :8716679
613                   ) is
614 --
615 l_proc                    varchar2(72) := g_package||'.default_comp_obj';
616 begin
617   --
618   ben_manage_default_enrt.default_comp_obj
619                   (p_validate           => p_validate
620                   ,p_per_in_ler_id      => p_per_in_ler_id
621                   ,p_person_id          => p_person_id
622                   ,p_business_group_id  => p_business_group_id
623                   ,p_effective_date     => p_effective_date
624                   ,p_pgm_id             => p_pgm_id
625                   ,p_pl_nip_id          => p_pl_nip_id
626                   ,p_susp_flag          => p_susp_flag
627                   ,p_batch_flag         => p_batch_flag
628                   ,p_cls_enrt_flag      => p_cls_enrt_flag
629                   ,p_called_frm_ss      => p_called_frm_ss
630 		  ,p_reinstate_dflts_flag => p_reinstate_dflts_flag -- Enhancement Bug :8716679
631 		  ,p_prev_per_in_ler_id => p_prev_per_in_ler_id -- Enhancement Bug :8716679
632                  );
633   --
634 end default_comp_obj ;
635 --
636 procedure get_ori_bckdt_pil(p_person_id            in number
637                             ,p_business_group_id   in number
638                             ,p_ler_id              in number
639                             ,p_effective_date      in date
640                             ,p_bckdt_per_in_ler_id out nocopy number
641                            ) is
642   --
643   l_proc                    varchar2(72) := g_package||'.get_ori_bckdt_pil';
644   --
645   -- Get the info of pil which got backed out and also the pil
646   -- which backed it.
647   --
648   -- #3248770 voided per in ler is not reinsated , the staus is validated
649 
650   cursor get_bckdt_per_in_ler is
651     select pil.per_in_ler_id,
652            ler.name,
653            pil.bckt_per_in_ler_id,
654            ler_cs_bckdt.name ler_cs_bckdt_name
655     from   ben_per_in_ler pil
656           ,ben_ler_f      ler
657           ,ben_per_in_ler pil_cs_bckdt
658           ,ben_ler_f      ler_cs_bckdt
659           ,ben_ptnl_ler_for_per  plr
660     where  pil.person_id            = p_person_id
661     and    pil.business_group_id    = p_business_group_id
662     and    pil.ler_id               = p_ler_id
663     and    pil.ler_id               = ler.ler_id
664     and    ler.business_group_id    = pil.business_group_id
665     and    pil.per_in_ler_stat_cd   = 'BCKDT'
666     and    pil.bckt_per_in_ler_id   = pil_cs_bckdt.per_in_ler_id(+)
667     and    pil_cs_bckdt.ler_id      = ler_cs_bckdt.ler_id(+)
668     and    pil.ptnl_ler_for_per_id   = plr.ptnl_ler_for_per_id
669     and    plr.ptnl_ler_for_per_stat_cd <> 'VOIDD'
670     and    nvl(pil_cs_bckdt.business_group_id, p_business_group_id) = p_business_group_id
671     and    nvl(ler_cs_bckdt.business_group_id, p_business_group_id) = p_business_group_id
672     and    pil.lf_evt_ocrd_dt       = p_effective_date
673     and    pil.ler_id <> ben_manage_life_events.g_ler_id
674     and    p_effective_date between ler.effective_start_date
675                                 and ler.effective_end_date
676     and    p_effective_date between nvl(ler_cs_bckdt.effective_start_date, p_effective_date)
677                                 and nvl(ler_cs_bckdt.effective_end_date, p_effective_date)
678     order by pil.per_in_ler_id desc
679    ;
680   --
681   l_bckdt_per_in_ler_rec          get_bckdt_per_in_ler%ROWTYPE;
682   --
683 begin
684   --
685   hr_utility.set_location('Entering:'|| l_proc, 10);
686   --
687   open  get_bckdt_per_in_ler;
688   fetch get_bckdt_per_in_ler into l_bckdt_per_in_ler_rec;
689   --
690   p_bckdt_per_in_ler_id := l_bckdt_per_in_ler_rec.per_in_ler_id;
691   g_bckdt_ler_name      := l_bckdt_per_in_ler_rec.name;
692   g_ler_name_cs_bckdt   := l_bckdt_per_in_ler_rec.ler_cs_bckdt_name;
693   g_pil_id_cs_bckdt     := l_bckdt_per_in_ler_rec.bckt_per_in_ler_id;
694   --
695   if get_bckdt_per_in_ler%found then
696     --
697     hr_utility.set_location('backout per in ler :'||  p_bckdt_per_in_ler_id, 10);
698     fnd_message.set_name('BEN','BEN_92246_BCKDT_PIL_FOUND');
699     fnd_message.set_token('LER_NAME',l_bckdt_per_in_ler_rec.name);
700     benutils.write(p_text => fnd_message.get);
701     --
702   end if;
703   close get_bckdt_per_in_ler;
704   --
705   hr_utility.set_location('Leaving:'|| l_proc, 10);
706   --
707 end get_ori_bckdt_pil;
708 --
709 -- ----------------------------------------------------------------------------
710 -- |------------------------< ele_made_for_bckdt_pil >-------------------------|
711 -- ----------------------------------------------------------------------------
712 --
713 -- If elections were made for the backout per in ler then
714 -- return Y else N
715 --
716 function  ele_made_for_bckdt_pil (
717                         p_bckdt_per_in_ler_id      in number,
718                         p_person_id                in number,
719                         p_business_group_id        in number,
720                         p_effective_date           in date) return varchar2 is
721   --
722   l_proc                     varchar2(72) := g_package||'.ele_made_for_bckdt_pil';
723   --
724   --
725   -- To determine whether elections are made for backed out
726   -- life events.
727   --
728   cursor c_enrt_rslt_exists is
729     select 'Y'
730     from   ben_prtt_enrt_rslt_f pen,
731            ben_per_in_ler pil
732     where  pil.per_in_ler_id = p_bckdt_per_in_ler_id
733     and    pil.business_group_id = p_business_group_id
734     and    pen.per_in_ler_id = pil.per_in_ler_id
735     and    pen.business_group_id = pil.business_group_id
736     and    pen.prtt_enrt_rslt_stat_cd = 'BCKDT'
737     and    nvl(pen.prtt_enrt_rslt_stat_cd, 'XXXX') =  'BCKDT'
738     and    p_effective_date between pen.effective_start_date
739                                 and pen.effective_end_date
740     /* 9999 complete this part from the backup table  */
741     union
742     select 'Y'
743     from  ben_le_clsn_n_rstr lcr
744     where lcr.per_in_ler_id = p_bckdt_per_in_ler_id
745     and    lcr.business_group_id = p_business_group_id
746     and    p_effective_date between lcr.effective_start_date
747                                 and lcr.effective_end_date;
748   -- 9999 only p_effective_date => esd is relevant check with examples.
749   --
750   l_enrt_rslt_exists varchar2(1) := 'N';
751   --
752 begin
753   --
754   hr_utility.set_location ('Entering '||l_proc,10);
755   --
756   open c_enrt_rslt_exists;
757   fetch c_enrt_rslt_exists into  l_enrt_rslt_exists;
758   close c_enrt_rslt_exists;
759   --
760   hr_utility.set_location ('Leaving '||l_proc,10);
761   --
762   return l_enrt_rslt_exists;
763   --
764 end ele_made_for_bckdt_pil;
765 --
766 -- ----------------------------------------------------------------------------
767 -- |------------------------< ele_made_for_inter_pil >-------------------------|
768 -- ----------------------------------------------------------------------------
769 --
770 function comp_prev_new_pen(p_person_id               in number
771                               ,p_business_group_id   in number
772                               ,p_effective_date      in date
773                               ,p_new_per_in_ler_id   in number
774                               ,p_prev_per_in_ler_id  in number
775                            ) return varchar2 is
776   --
777   l_proc                   varchar2(72) := g_package||'.comp_ori_new_pen';
778   --
779   -- Following are the tables whose data will be compared to
780   -- find any differences exists between the two runs of same ler.
781   --
782   -- ben_prtt_enrt_rslt_f
783   --
784   cursor c_pen_dat(p_pil_id number) is
785    select
786           pen.OIPL_ID,
787           pen.PGM_ID,
788           pen.PL_ID,
789           pen.SSPNDD_FLAG
790     from   ben_prtt_enrt_rslt_f pen,
791            ben_per_in_ler pil
792     where  pil.per_in_ler_id       = p_pil_id
793     and    pil.person_id           = p_person_id
794     and    pil.business_group_id = p_business_group_id
795     AND    pil.per_in_ler_id       = pen.per_in_ler_id
796     and    pen.prtt_enrt_rslt_stat_cd is null
797     and    pen.enrt_cvg_thru_dt    = hr_api.g_eot
798     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP') ;
799   --
800   TYPE l_prev_pen_rec is TABLE OF c_pen_dat%rowtype INDEX BY BINARY_INTEGER;
801   --
802   TYPE l_int_pen_rec is TABLE OF c_pen_dat%rowtype INDEX BY BINARY_INTEGER;
803   --
804   l_differ         varchar2(1) := 'N';
805   l_prev_pen_table l_prev_pen_rec;
806   l_int_pen_table  l_int_pen_rec;
807   l_next_row       binary_integer := 1 ;
808   l_found          boolean;
809   --
810 begin
811   --
812   hr_utility.set_location ('Entering '||l_proc,10);
813   hr_utility.set_location ('Entering bck pil id '||p_prev_per_in_ler_id,10);
814   hr_utility.set_location ('Entering pil id '||p_new_per_in_ler_id,10);
815   --
816   --
817   for  int_pen_rec in c_pen_dat(p_new_per_in_ler_id)
818   loop
819      --
820      l_int_pen_table(l_next_row)   := int_pen_rec;
821      l_next_row := l_next_row + 1;
822      --
823   end loop;
824   --
825   -- Check Number of records in both tables differ
826   --
827   if nvl(l_int_pen_table.last, 0) = 0 then
828        --
829        l_differ := 'N';
830        hr_utility.set_location('Leaving:  ' || l_differ
831                                             ||' 0 '|| l_proc, 10);
832        return l_differ;
833        --
834   end if;
835   --
836   -- Now compare the original pen record and new pen record.
837   --
838   hr_utility.set_location(to_char(nvl(l_int_pen_table.last, 0)) ,4987);
839   --
840   --
841   hr_utility.set_location(' Before first Loop ',4987);
842   for  l_int_count in l_int_pen_table.first..l_int_pen_table.last loop
843     --
844     l_found  := FALSE;
845     --
846     hr_utility.set_location(' Before Loop ',4987);
847     for prev_pen_rec in c_pen_dat(p_prev_per_in_ler_id)
848     loop
849       --
850       hr_utility.set_location(' Before if ',4987);
851       if nvl(prev_pen_rec.SSPNDD_FLAG, '$') =
852                    nvl(l_int_pen_table(l_int_count).SSPNDD_FLAG, '$') and
853          nvl(prev_pen_rec.PGM_ID, -1) =
854                    nvl(l_int_pen_table(l_int_count).PGM_ID, -1) and
855          nvl(prev_pen_rec.PL_ID, -1) =
856                    nvl(l_int_pen_table(l_int_count).PL_ID, -1) and
857          nvl(prev_pen_rec.OIPL_ID, -1) =
858             nvl(l_int_pen_table(l_int_count).OIPL_ID, -1)
859       then
860         --
861         l_found   := TRUE;
862         --
863         exit;
864       end if;
865       --
866     end loop;
867     --
868     if l_found   = FALSE then
869        --
870        l_differ := 'Y';
871        exit;
872     end if;
873     --
874   end loop;
875   --
876   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
877   --
878   return l_differ;
879   --
880 end comp_prev_new_pen;
881 --
882 -- ----------------------------------------------------------------------------
883 -- |------------------------< get_inter_pil_cnt >-------------------------|
884 -- ----------------------------------------------------------------------------
885 --
886 -- If more than one pil exists between two runs of a pil then
887 -- no restoration to be done.
888 --
889 procedure  get_inter_pil_cnt (
890                         p_bckdt_per_in_ler_id      in number,
891                         p_per_in_ler_id            in number,
892                         p_person_id                in number,
893                         p_bckt_csd_lf_evt_ocrd_dt  out nocopy date,
894                         p_bckt_csd_per_in_ler_id   out nocopy number,
895                         p_inter_per_in_ler_id      out nocopy number,
896                         p_inter_pil_ovn            out nocopy number,
897                         p_inter_pil_cnt            out nocopy number,
898                         p_inter_pil_le_dt          out nocopy date,
899                         p_business_group_id        in number,
900                         p_effective_date           in date) is
901   --
902   l_proc                     varchar2(72) := g_package||'.get_inter_pil_cnt';
903   --
904   -- Bug 4987 ( WWW Bug 1266433)
905   -- When counting the intervening life events only count the pil's
906   -- whose lf_evt_ocrd_dt is more than the back out date of the
907   -- backed out per in ler.
908   --
909   cursor c_bckt_csd_pil is
910          select csd_pil.lf_evt_ocrd_dt,
911                 csd_pil.per_in_ler_id
912          from ben_per_in_ler csd_pil,
913               ben_per_in_ler bckt_pil
914          where bckt_pil.per_in_ler_id = p_bckdt_per_in_ler_id
915            and bckt_pil.BCKT_PER_IN_LER_ID = csd_pil.per_in_ler_id
916            and bckt_pil.business_group_id = p_business_group_id
917            and csd_pil.business_group_id = p_business_group_id;
918   --
919   l_bckt_csd_lf_evt_ocrd_dt date;
920   l_bckt_csd_per_in_ler_id number;
921   --
922   -- Bug 5415 : Intermediate pil count should be between
923   -- the life event occured date of pil which causes back out
924   -- and the current reprocessing backed out pil.
925   -- iREC : do not consider iRec, ABS, COMP, GSP pils.
926   --
927   cursor c_inter_pil_cnt(cv_bckt_csd_lf_evt_ocrd_dt date) is
928     select pil.per_in_ler_id, pil.object_version_number
929     from   ben_per_in_ler pil,
930            ben_ler_f ler
931     where  pil.per_in_ler_id <> p_per_in_ler_id
932     and    pil.per_in_ler_id <> p_bckdt_per_in_ler_id
933     and    pil.person_id         = p_person_id
934     and    pil.ler_id            = ler.ler_id
935     and    p_effective_date between
936            ler.effective_start_date and ler.effective_end_date
937     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
938     and    pil.business_group_id = p_business_group_id
939     and    nvl(pil.per_in_ler_stat_cd, 'XXXX') not in('BCKDT', 'VOIDD')
940     and    pil.lf_evt_ocrd_dt > cv_bckt_csd_lf_evt_ocrd_dt
941     and    pil.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt
942                                  from ben_per_in_ler
943                                  where per_in_ler_id = p_bckdt_per_in_ler_id
944                                    and business_group_id = p_business_group_id
945                                 )
946     order by pil.lf_evt_ocrd_dt asc;
947   --
948   l_count number     := 0;
949   --
950 begin
951   --
952   hr_utility.set_location ('Entering '||l_proc,10);
953   --
954   p_inter_pil_cnt := 0;
955   open c_bckt_csd_pil;
956   fetch c_bckt_csd_pil into l_bckt_csd_lf_evt_ocrd_dt,l_bckt_csd_per_in_ler_id;
957   close c_bckt_csd_pil;
958   --
959   p_bckt_csd_lf_evt_ocrd_dt := l_bckt_csd_lf_evt_ocrd_dt;
960   p_bckt_csd_per_in_ler_id  := l_bckt_csd_per_in_ler_id;
961   --
962   g_bckt_csd_lf_evt_ocrd_dt := l_bckt_csd_lf_evt_ocrd_dt;
963   --
964   open  c_inter_pil_cnt(l_bckt_csd_lf_evt_ocrd_dt);
965   fetch c_inter_pil_cnt into  p_inter_per_in_ler_id, p_inter_pil_ovn;
966   if c_inter_pil_cnt%found then
967      --
968      -- Find are there more intervening PIL's.
969      --
970      p_inter_pil_cnt := 1;
971      fetch c_inter_pil_cnt into  p_inter_per_in_ler_id, p_inter_pil_ovn;
972      if c_inter_pil_cnt%found then
973         p_inter_pil_cnt := p_inter_pil_cnt + 1;
974      end if;
975      --
976   end if;
977   --
978   close c_inter_pil_cnt;
979   --
980   hr_utility.set_location ('Leaving '||l_proc,10);
981   --
982 end get_inter_pil_cnt;
983 --
984 -- ----------------------------------------------------------------------------
985 -- |------------------------< ele_made_for_inter_pil >-------------------------|
986 -- ----------------------------------------------------------------------------
987 --
988 -- If elections were made for the backout per in ler then
989 -- return Y else N
990 --
991 function ele_made_for_inter_pil(
992                         p_per_in_ler_id            in number,
993                         p_bckdt_per_in_ler_id      in number,
994                         p_person_id                in number,
995                         p_business_group_id        in number,
996                         p_effective_date           in date,
997 			p_reinstate_cd in varchar2 default NULL) return varchar2 is
998   --
999   l_proc                     varchar2(72) := g_package||'.ele_made_for_inter_pil';
1000   --
1001   -- To determine whether elections are made for intervening
1002   -- life events, if so stop the restore process.
1003   --
1004 
1005   l_prev_per_in_ler_id1 number;
1006 
1007   cursor c_ele_md_for_inter_pil is
1008     select 'Y'
1009     from   ben_prtt_enrt_rslt_f pen,
1010            ben_ler_f ler
1011     where  pen.per_in_ler_id not in (p_per_in_ler_id,p_bckdt_per_in_ler_id)
1012            /* Bug 8305552: Added 'not in (p_per_in_ler_id)'. Do not check elections for the current LifeEvent,because for Automatic enrollments
1013 	    record will be present during validation of the cursor*/
1014     and    pen.person_id           = p_person_id
1015     and    pen.prtt_enrt_rslt_stat_cd is null
1016     -- and    pen.enrt_cvg_thru_dt = hr_api.g_eot  BUG  4642657
1017     and    pen.effective_end_date = hr_api.g_eot
1018     and    pen.ler_id = ler.ler_id
1019     and    p_effective_date between ler.effective_start_date and
1020                                     ler.effective_end_date
1021     and    ler.typ_cd not in  ('IREC','SCHEDDU', 'COMP', 'GSP', 'ABS')
1022     /*Commented the below condition and added a new condition for Bug :8716679 */
1023     /* Bug 12871602: Changed the below condition. If p_reinstate_cd = 'VALIDATE_EXPLICIT_ENRT' check elections
1024     are made for the intervening LE based on per_in_ler_id of intervening LE*/
1025     and (   ((p_reinstate_cd is NULL or p_reinstate_cd <> 'VALIDATE_EXPLICIT_ENRT' )
1026            and ( pen.effective_start_date >= (select decode(PRVS_STAT_CD, 'STRTD',STRTD_DT,
1027                                        'PROCD',PROCD_DT,LF_EVT_OCRD_DT)
1028                                        from ben_per_in_ler
1029                                        where per_in_ler_id = p_bckdt_per_in_ler_id
1030                                       )
1031 		)) or (p_reinstate_cd = 'VALIDATE_EXPLICIT_ENRT' and  pen.per_in_ler_id= l_prev_per_in_ler_id1 )
1032          )
1033     and rownum =  1 ;
1034   --
1035 
1036   cursor c_prev_pil(p_bckt_csd_lf_evt_ocrd_dt date,p_bckt_csd_per_in_ler_id number ) is
1037     select pil.per_in_ler_id
1038     from   ben_per_in_ler pil,
1039            ben_ler_f ler
1040     where  pil.per_in_ler_id not in (p_per_in_ler_id,p_bckt_csd_per_in_ler_id)
1041     and    pil.person_id     = p_person_id
1042     and    pil.ler_id        = ler.ler_id
1043     and    p_effective_date between
1044            ler.effective_start_date and ler.effective_end_date
1045     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
1046     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
1047     and    pil.lf_evt_ocrd_dt in (select max(lf_evt_ocrd_dt)
1048                                  from ben_per_in_ler pil2
1049                                  where pil2.ler_id    = pil.ler_id
1050                                    and pil2.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD')
1051                                    and pil2.person_id = p_person_id
1052                                    and pil2.lf_evt_ocrd_dt < p_bckt_csd_lf_evt_ocrd_dt
1053                                 );
1054   --
1055   l_count number     := 0;
1056 
1057  /* Added for Enhancement Bug :8716679 */
1058 
1059  l_int_pil_id number;
1060  /* Cursor to get the Intervening per_in_ler_id*/
1061  cursor c_int_pil_id is
1062   select bckt_per_in_ler_id
1063         from ben_per_in_ler pil
1064 	where pil.per_in_ler_id = p_bckdt_per_in_ler_id;
1065 
1066 /*Cursor to get the latest Intervening per_in_ler_id that has been processed*/
1067 cursor c_prev_pil1 is
1068        select pil.per_in_ler_id
1069     from   ben_per_in_ler pil,
1070            ben_ler_f ler
1071     where  pil.per_in_ler_id not in (p_per_in_ler_id,p_bckdt_per_in_ler_id)
1072     and    pil.person_id     = p_person_id
1073     and    pil.ler_id        = ler.ler_id
1074     and    p_effective_date between
1075            ler.effective_start_date and ler.effective_end_date
1076     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
1077     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
1078     and    pil.lf_evt_ocrd_dt in (select lf_evt_ocrd_dt
1079 				 from ben_per_in_ler pil2,
1080 				      ben_ler_f ler1
1081 				 where pil2.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD')
1082 				    and pil2.person_id = p_person_id
1083 				    and    pil2.ler_id        = ler1.ler_id
1084 				    and    p_effective_date between
1085 					   ler1.effective_start_date and ler1.effective_end_date
1086 				    and    ler1.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
1087 				    and pil2.lf_evt_ocrd_dt > (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
1088 							      per_in_ler_id = l_int_pil_id)
1089 				    and pil2.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
1090 							      per_in_ler_id = p_bckdt_per_in_ler_id)
1091                                 )
1092    order by pil.lf_evt_ocrd_dt desc;
1093   /* End of Enhancement Bug :8716679 */
1094 
1095   l_enrt_rslt_exists varchar2(1) := 'N';
1096   l_inter_pil_ovn            number;
1097   l_inter_pil_cnt            number := 0;
1098   l_inter_per_in_ler_id      number;
1099   l_prev_per_in_ler_id       number;
1100   l_inter_pil_le_dt          date;
1101   l_bckt_csd_lf_evt_ocrd_dt  date;
1102   l_bckt_csd_per_in_ler_id   number;
1103   --
1104   l_differ                   varchar2(30) := 'N';
1105   --
1106 begin
1107   --
1108   hr_utility.set_location ('Entering '||l_proc,10);
1109   hr_utility.set_location ('modified '||l_proc,10);
1110   --
1111   --First Get the intervening life event count
1112   --
1113 
1114    /* Added for Enhancement Bug :8716679 */
1115   open c_int_pil_id;
1116   fetch c_int_pil_id into l_int_pil_id;
1117   close c_int_pil_id;
1118   hr_utility.set_location ('l_int_pil_id '||l_int_pil_id,10);
1119 
1120   open c_prev_pil1;
1121   fetch c_prev_pil1 into l_prev_per_in_ler_id1;
1122   if(c_prev_pil1%notfound) then
1123     hr_utility.set_location ('cursor notfound ',10);
1124     l_prev_per_in_ler_id1 := l_int_pil_id;
1125     close c_prev_pil1;
1126   else
1127      close c_prev_pil1;
1128   end if;
1129   hr_utility.set_location ('l_prev_per_in_ler_id1 '||l_prev_per_in_ler_id1,10);
1130   /* End of Enhancement Bug :8716679 */
1131 
1132   open  c_ele_md_for_inter_pil;
1133   fetch c_ele_md_for_inter_pil into  l_enrt_rslt_exists;
1134   close c_ele_md_for_inter_pil;
1135   --
1136   if l_enrt_rslt_exists = 'Y' then
1137     --
1138     get_inter_pil_cnt ( p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id,
1139                       p_per_in_ler_id            => p_per_in_ler_id,
1140                       p_person_id                => p_person_id,
1141                       p_business_group_id        => p_business_group_id,
1142                       p_bckt_csd_lf_evt_ocrd_dt  => l_bckt_csd_lf_evt_ocrd_dt,
1143                       p_bckt_csd_per_in_ler_id   => l_bckt_csd_per_in_ler_id,
1144                       p_inter_per_in_ler_id      => l_inter_per_in_ler_id,
1145                       p_inter_pil_ovn            => l_inter_pil_ovn,
1146                       p_inter_pil_cnt            => l_inter_pil_cnt,
1147                       p_inter_pil_le_dt          => l_inter_pil_le_dt,
1148                       p_effective_date           => p_effective_date);
1149     --
1150     hr_utility.set_location ('l_inter_pil_cnt '||l_inter_pil_cnt,199);
1151     hr_utility.set_location ('l_inter_pil_le_dt '||l_inter_pil_le_dt,199);
1152     hr_utility.set_location ('l_inter_per_in_ler_id '||l_inter_per_in_ler_id,199);
1153     hr_utility.set_location ('l_bckt_csd_lf_evt_ocrd_dt '||l_bckt_csd_lf_evt_ocrd_dt,199);
1154     hr_utility.set_location ('l_bckt_csd_per_in_ler_id '||l_bckt_csd_per_in_ler_id,199);
1155     --
1156     if l_inter_pil_cnt = 0 then
1157       --
1158       --Get the previous life event
1159       open c_prev_pil(l_bckt_csd_lf_evt_ocrd_dt,l_bckt_csd_per_in_ler_id);
1160       fetch c_prev_pil into l_prev_per_in_ler_id ;
1161       close c_prev_pil;
1162       --
1163       if l_prev_per_in_ler_id is not null then
1164         --
1165         hr_utility.set_location ('l_prev_per_in_ler_id '||l_prev_per_in_ler_id,199);
1166         --
1167         l_differ := comp_prev_new_pen(p_person_id         => p_person_id
1168                                      ,p_business_group_id => p_business_group_id
1169                                      ,p_effective_date    => p_effective_date
1170                                      ,p_new_per_in_ler_id => l_bckt_csd_per_in_ler_id
1171                                      ,p_prev_per_in_ler_id=> l_prev_per_in_ler_id);
1172         --
1173         hr_utility.set_location (' l_differ '||l_differ,199);
1174         if l_differ = 'N' then
1175           --
1176           l_enrt_rslt_exists := 'N';
1177           --
1178         else
1179           --
1180           l_enrt_rslt_exists := 'Y';
1181           --
1182         end if;
1183         --
1184       else
1185         --There was no previous enrollment when the backedout life event was processed bt
1186         --there is a life event exists. Donot reinstate
1187         --If there is no life event which backed out the life event then reset
1188         --l_enrt_rslt_exists to N
1189         --
1190         if l_bckt_csd_per_in_ler_id is NULL then
1191           l_enrt_rslt_exists := 'N';
1192         else
1193           l_enrt_rslt_exists := 'Y';
1194         end if;
1195         --
1196       end if ;
1197       --
1198     elsif l_inter_pil_cnt = 1 then
1199       --More than one intevening life events.
1200       --Dont reinstare
1201       l_differ := comp_prev_new_pen(p_person_id           => p_person_id
1202                                    ,p_business_group_id => p_business_group_id
1203                                    ,p_effective_date    => p_effective_date
1204                                    ,p_new_per_in_ler_id => l_inter_per_in_ler_id
1205                                    ,p_prev_per_in_ler_id=> l_bckt_csd_per_in_ler_id );
1206       --
1207       hr_utility.set_location (' l_differ '||l_differ,299);
1208       if l_differ = 'N' then
1209         --
1210         l_enrt_rslt_exists := 'N';
1211         --
1212       else
1213         --
1214         l_enrt_rslt_exists := 'Y';
1215         --
1216       end if;
1217       --
1218     else
1219       --Sorry.. You can't get it reinstated.. there are more than two intervening life events.
1220       l_enrt_rslt_exists := 'Y';
1221       --
1222     end if;
1223   --
1224   else
1225     --
1226     l_enrt_rslt_exists := 'N';
1227     --
1228   end if;
1229   --
1230   hr_utility.set_location ('Leaving l_enrt_rslt_exists '||l_enrt_rslt_exists,199);
1231   --
1232   hr_utility.set_location ('Leaving '||l_proc,10);
1233   --
1234   return l_enrt_rslt_exists;
1235   --
1236 end ele_made_for_inter_pil;
1237 --
1238 -- ----------------------------------------------------------------------------
1239 -- |------------------------< comp_ori_new_egd >-------------------------|
1240 -- ----------------------------------------------------------------------------
1241 --
1242 -- This procedure compares the original and new
1243 -- elig dependents for a electble choice and per in ler id.
1244 --
1245 function comp_ori_new_egd(p_person_id               in number
1246                           ,p_business_group_id      in number
1247                           ,p_effective_date         in date
1248                           ,p_per_in_ler_id          in number
1249                           ,p_bckdt_per_in_ler_id    in number
1250                           ,p_curr_epe_id            in number
1251                           ,p_bckdt_epe_id           in number
1252                           ) return varchar2 is
1253   --
1254   l_proc                    varchar2(72) := g_package||'.comp_ori_new_egd';
1255   --
1256   l_differ                  varchar2(1) := 'N';
1257   --
1258   cursor c_bckdt_epe_egd is
1259     select epe_egd.*
1260     from   ben_elig_dpnt epe_egd
1261     where epe_egd.elig_per_elctbl_chc_id = p_bckdt_epe_id
1262     and   epe_egd.business_group_id  = p_business_group_id
1263     and   epe_egd.per_in_ler_id      = p_bckdt_per_in_ler_id;
1264   --
1265   cursor c_curr_epe_egd is
1266     select epe_egd.*
1267     from   ben_elig_dpnt epe_egd
1268     where epe_egd.elig_per_elctbl_chc_id = p_curr_epe_id
1269     and   epe_egd.business_group_id  = p_business_group_id
1270     and   epe_egd.per_in_ler_id      = p_per_in_ler_id;
1271   --
1272   TYPE l_bckdt_epe_egd_rec is TABLE OF c_bckdt_epe_egd%rowtype
1273        INDEX BY BINARY_INTEGER;
1274   --
1275   TYPE l_curr_epe_egd_rec is TABLE OF c_curr_epe_egd%rowtype
1276        INDEX BY BINARY_INTEGER;
1277   --
1278   l_bckdt_epe_egd_table  l_bckdt_epe_egd_rec;
1279   l_curr_epe_egd_table   l_curr_epe_egd_rec;
1280   l_next_row             binary_integer;
1281   l_found                boolean;
1282   l_bckdt_epe_egd_count  number;
1283   --
1284 begin
1285   --
1286   hr_utility.set_location ('Entering '||l_proc,10);
1287   --
1288   select count(*) into l_bckdt_epe_egd_count
1289     from   ben_elig_dpnt epe_egd
1290     where epe_egd.elig_per_elctbl_chc_id = p_bckdt_epe_id
1291     and   epe_egd.business_group_id  = p_business_group_id
1292     and   epe_egd.per_in_ler_id      = p_bckdt_per_in_ler_id;
1293   --
1294   l_curr_epe_egd_table.delete;
1295   l_next_row := nvl(l_curr_epe_egd_table.LAST, 0) + 1;
1296   for  curr_epe_egd_rec in c_curr_epe_egd
1297   loop
1298      --
1299      l_curr_epe_egd_table(l_next_row)   := curr_epe_egd_rec;
1300      l_next_row := l_next_row + 1;
1301      --
1302   end loop;
1303   --
1304   --
1305   -- Check Number of records in both tables for difference
1306   --
1307   if nvl(l_curr_epe_egd_table.last, 0) = 0  and
1308      nvl(l_bckdt_epe_egd_count,0)  = 0
1309   then
1310        --
1311        l_differ := 'N';
1312        hr_utility.set_location ('Leaving : N : 0 '||l_proc,10);
1313        return l_differ;
1314        --
1315   elsif nvl(l_curr_epe_egd_table.last, 0) <> nvl(l_bckdt_epe_egd_count,0) then
1316        --
1317        l_differ := 'Y';
1318        hr_utility.set_location ('Leaving : Y : <>0 '||l_proc,10);
1319        hr_utility.set_location ('Leaving : Y : ' || nvl(l_curr_epe_egd_table.last, 0)
1320                                 || '  ' || nvl(l_bckdt_epe_egd_count,0) || '  ' ||
1321                                 l_proc,10);
1322        return l_differ;
1323        --
1324   end if;
1325   --
1326   -- Now compare the original epe_egd record and new epe_egd record
1327   -- for each epe record.
1328   --
1329   for bckdt_epe_egd_rec in c_bckdt_epe_egd
1330   loop
1331     --
1332     l_found  := FALSE;
1333     --
1334     for  l_curr_count in l_curr_epe_egd_table.first..l_curr_epe_egd_table.last
1335     loop
1336        /* -- Columns to compare
1337 
1338           DPNT_INELIG_FLAG
1339           DPNT_PERSON_ID
1340           INELG_RSN_CD
1341           ELIG_STRT_DT
1342           ELIG_THRU_DT
1343           --
1344           -- Do we need to compare the following columns.
1345           --
1346           OVRDN_THRU_DT
1347           OVRDN_FLAG
1348           CREATE_DT
1349           ELIG_PER_ID
1350           ELIG_PER_OPT_ID
1351           ELIG_CVRD_DPNT_ID
1352       */
1353       --
1354       if nvl(bckdt_epe_egd_rec.DPNT_INELIG_FLAG, '$') =
1355                    nvl(l_curr_epe_egd_table(l_curr_count).DPNT_INELIG_FLAG, '$') and
1356          nvl(bckdt_epe_egd_rec.INELG_RSN_CD, '$') =
1357                    nvl(l_curr_epe_egd_table(l_curr_count).INELG_RSN_CD, '$') and
1358          nvl(bckdt_epe_egd_rec.ELIG_STRT_DT, hr_api.g_eot) =
1359             nvl(l_curr_epe_egd_table(l_curr_count).ELIG_STRT_DT, hr_api.g_eot) and
1360          nvl(bckdt_epe_egd_rec.ELIG_THRU_DT, hr_api.g_eot) =
1361             nvl(l_curr_epe_egd_table(l_curr_count).ELIG_THRU_DT, hr_api.g_eot) and
1362          nvl(bckdt_epe_egd_rec.DPNT_PERSON_ID, -1) =
1363                    nvl(l_curr_epe_egd_table(l_curr_count).DPNT_PERSON_ID, -1)
1364       then
1365         l_found   := TRUE;
1366         exit;
1367       end if;
1368       --
1369     end loop;
1370     --
1371     if l_found   = FALSE then
1372        --
1373        -- Current epe for a given backed out epe is not found
1374        --
1375        l_differ := 'Y';
1376        exit;
1377     end if;
1378   --
1379   end loop;
1380   --
1381   hr_utility.set_location('Leaving: ' || l_differ || l_proc, 10);
1382   --
1383   return l_differ;
1384   --
1385 end comp_ori_new_egd;
1386 --
1387 --
1388 -- ----------------------------------------------------------------------------
1389 -- |------------------------< comp_ori_new_enb_ecr >-------------------------|
1390 -- ----------------------------------------------------------------------------
1391 --
1392 -- This procedure compares the original and new enrollment benefit
1393 -- for comparable electble choice and per in ler id.
1394 --
1395 function comp_ori_new_enb_ecr(p_person_id               in number
1396                           ,p_business_group_id      in number
1397                           ,p_effective_date         in date
1398                           ,p_per_in_ler_id          in number
1399                           ,p_bckdt_per_in_ler_id    in number
1400                           ,p_curr_enb_id            in number
1401                           ,p_bckdt_enb_id           in number
1402                           ) return varchar2 is
1403   --
1404   l_proc                    varchar2(72) := g_package||'.comp_ori_new_enb_ecr';
1405   --
1406   l_differ                  varchar2(1) := 'N';
1407   --
1408   cursor c_bckdt_enb_ecr is
1409     select enb_ecr.*
1410     from   ben_enrt_rt enb_ecr
1411     where enb_ecr.enrt_bnft_id = p_bckdt_enb_id
1412     and   enb_ecr.business_group_id  = p_business_group_id
1413     and   enb_ecr.elig_per_elctbl_chc_id is null;
1414   --
1415   cursor c_curr_enb_ecr is
1416     select enb_ecr.*
1417     from   ben_enrt_rt enb_ecr
1418     where enb_ecr.enrt_bnft_id = p_curr_enb_id
1419     and   enb_ecr.business_group_id  = p_business_group_id
1420     and   enb_ecr.elig_per_elctbl_chc_id is null;
1421   --
1422   TYPE l_bckdt_enb_ecr_rec is TABLE OF c_bckdt_enb_ecr%rowtype
1423        INDEX BY BINARY_INTEGER;
1424   --
1425   TYPE l_curr_enb_ecr_rec is TABLE OF c_curr_enb_ecr%rowtype
1426        INDEX BY BINARY_INTEGER;
1427   --
1428   l_bckdt_enb_ecr_table l_bckdt_enb_ecr_rec;
1429   l_curr_enb_ecr_table  l_curr_enb_ecr_rec;
1430   l_next_row            binary_integer;
1431   l_found               boolean;
1432   l_bckdt_enb_ecr_count number;
1433   --
1434 begin
1435   --
1436   hr_utility.set_location ('Entering '||l_proc,10);
1437   --
1438   select count(*) into l_bckdt_enb_ecr_count
1439     from   ben_enrt_rt enb_ecr
1440     where enb_ecr.enrt_bnft_id = p_bckdt_enb_id
1441     and   enb_ecr.business_group_id  = p_business_group_id
1442     and   enb_ecr.elig_per_elctbl_chc_id is null;
1443   --
1444   l_curr_enb_ecr_table.delete;
1445   l_next_row := nvl(l_curr_enb_ecr_table.LAST, 0) + 1;
1446   for  curr_enb_ecr_rec in c_curr_enb_ecr
1447   loop
1448      --
1449      l_curr_enb_ecr_table(l_next_row)   := curr_enb_ecr_rec;
1450      l_next_row := l_next_row + 1;
1451      --
1452   end loop;
1453   --
1454   -- Check Number of records in both tables for difference
1455   --
1456   if nvl(l_curr_enb_ecr_table.last, 0) = 0  and
1457      nvl(l_bckdt_enb_ecr_count,0)  = 0
1458   then
1459        --
1460        l_differ := 'N';
1461        hr_utility.set_location ('Leavingi : N : 0 '||l_proc,10);
1462        return l_differ;
1463        --
1464   elsif nvl(l_curr_enb_ecr_table.last, 0) <> nvl(l_bckdt_enb_ecr_count,0) then
1465        --
1466        l_differ := 'Y';
1467        hr_utility.set_location ('Leavingi : Y : <>0 '||l_proc,10);
1468        return l_differ;
1469        --
1470   end if;
1471   --
1472   -- Now compare the original enb_ecr record and new enb_ecr record for each
1473   -- epe record.
1474   --
1475   -- for  l_count in l_bckdt_enb_ecr_table.first..l_bckdt_enb_ecr_table.last loop
1476   for bckdt_enb_ecr_rec in c_bckdt_enb_ecr
1477   loop
1478     --
1479     l_found  := FALSE;
1480     --
1481     for  l_curr_count in l_curr_enb_ecr_table.first..l_curr_enb_ecr_table.last
1482     loop
1483       --
1484       if nvl(bckdt_enb_ecr_rec.ACTY_TYP_CD, '$') =
1485                    nvl(l_curr_enb_ecr_table(l_curr_count).ACTY_TYP_CD, '$') and
1486          nvl(bckdt_enb_ecr_rec.TX_TYP_CD, '$') =
1487                    nvl(l_curr_enb_ecr_table(l_curr_count).TX_TYP_CD, '$') and
1488          nvl(bckdt_enb_ecr_rec.CTFN_RQD_FLAG, '$') =
1489                    nvl(l_curr_enb_ecr_table(l_curr_count).CTFN_RQD_FLAG, '$') and
1490          nvl(bckdt_enb_ecr_rec.DFLT_FLAG, '$') =
1491                    nvl(l_curr_enb_ecr_table(l_curr_count).DFLT_FLAG, '$') and
1492          nvl(bckdt_enb_ecr_rec.DFLT_VAL, -1) =
1493                    nvl(l_curr_enb_ecr_table(l_curr_count).DFLT_VAL, -1) and
1494          nvl(bckdt_enb_ecr_rec.ANN_VAL, -1) =
1495                    nvl(l_curr_enb_ecr_table(l_curr_count).ANN_VAL, -1) and
1496          nvl(bckdt_enb_ecr_rec.ANN_MN_ELCN_VAL, -1) =
1497                    nvl(l_curr_enb_ecr_table(l_curr_count).ANN_MN_ELCN_VAL, -1) and
1498          nvl(bckdt_enb_ecr_rec.ANN_MX_ELCN_VAL, -1) =
1499                    nvl(l_curr_enb_ecr_table(l_curr_count).ANN_MX_ELCN_VAL, -1) and
1500          nvl(bckdt_enb_ecr_rec.MX_ELCN_VAL, -1) =
1501                    nvl(l_curr_enb_ecr_table(l_curr_count).MX_ELCN_VAL, -1) and
1502          nvl(bckdt_enb_ecr_rec.MN_ELCN_VAL, -1) =
1503                    nvl(l_curr_enb_ecr_table(l_curr_count).MN_ELCN_VAL, -1) and
1504          nvl(bckdt_enb_ecr_rec.INCRMT_ELCN_VAL, -1) =
1505                    nvl(l_curr_enb_ecr_table(l_curr_count).INCRMT_ELCN_VAL, -1) and
1506          nvl(bckdt_enb_ecr_rec.RT_STRT_DT, hr_api.g_eot) =
1507             nvl(l_curr_enb_ecr_table(l_curr_count).RT_STRT_DT, hr_api.g_eot) and
1508          nvl(bckdt_enb_ecr_rec.RT_STRT_DT_CD, '$') =
1509                    nvl(l_curr_enb_ecr_table(l_curr_count).RT_STRT_DT_CD, '$') and
1510          nvl(bckdt_enb_ecr_rec.RT_STRT_DT_RL, -1) =
1511                    nvl(l_curr_enb_ecr_table(l_curr_count).RT_STRT_DT_RL, -1) and
1512          nvl(bckdt_enb_ecr_rec.ACTY_BASE_RT_ID, -1) =
1513                    nvl(l_curr_enb_ecr_table(l_curr_count).ACTY_BASE_RT_ID, -1) and
1514          nvl(bckdt_enb_ecr_rec.DECR_BNFT_PRVDR_POOL_ID, -1) =
1515             nvl(l_curr_enb_ecr_table(l_curr_count).DECR_BNFT_PRVDR_POOL_ID, -1) and
1516          nvl(bckdt_enb_ecr_rec.CVG_AMT_CALC_MTHD_ID, -1) =
1517             nvl(l_curr_enb_ecr_table(l_curr_count).CVG_AMT_CALC_MTHD_ID, -1) and
1518          nvl(bckdt_enb_ecr_rec.ACTL_PREM_ID, -1) =
1519                    nvl(l_curr_enb_ecr_table(l_curr_count).ACTL_PREM_ID, -1) and
1520          nvl(bckdt_enb_ecr_rec.COMP_LVL_FCTR_ID, -1) =
1521                    nvl(l_curr_enb_ecr_table(l_curr_count).COMP_LVL_FCTR_ID, -1)
1522       then
1523         l_found   := TRUE;
1524         exit;
1525       end if;
1526       --
1527     end loop;
1528     --
1529     if l_found   = FALSE then
1530        --
1531        -- Current epe for a given backed out epe is not found
1532        --
1533        l_differ := 'Y';
1534        exit;
1535     end if;
1536   --
1537   end loop;
1538   --
1539   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
1540   --
1541   return l_differ;
1542   --
1543 end comp_ori_new_enb_ecr;
1544 --
1545 -- ----------------------------------------------------------------------------
1546 -- |------------------------< comp_ori_new_epe_ecr >-------------------------|
1547 -- ----------------------------------------------------------------------------
1548 --
1549 -- This procedure compares the original and new enrollment benefit
1550 -- for comparable electble choice and per in ler id.
1551 --
1552 function comp_ori_new_epe_ecr(p_person_id               in number
1553                           ,p_business_group_id      in number
1554                           ,p_effective_date         in date
1555                           ,p_per_in_ler_id          in number
1556                           ,p_bckdt_per_in_ler_id    in number
1557                           ,p_curr_epe_id            in number
1558                           ,p_bckdt_epe_id           in number
1559                           ) return varchar2 is
1560   --
1561   l_proc                    varchar2(72) := g_package||'.comp_ori_new_epe_ecr';
1562   --
1563   l_differ                  varchar2(1) := 'N';
1564   --
1565   cursor c_bckdt_epe_ecr is
1566     select epe_ecr.*
1567     from   ben_enrt_rt epe_ecr
1568     where epe_ecr.elig_per_elctbl_chc_id = p_bckdt_epe_id
1569     and   epe_ecr.business_group_id  = p_business_group_id
1570     and   epe_ecr.enrt_bnft_id is null;
1571   --
1572   cursor c_curr_epe_ecr is
1573     select epe_ecr.*
1574     from   ben_enrt_rt epe_ecr
1575     where epe_ecr.elig_per_elctbl_chc_id = p_curr_epe_id
1576     and   epe_ecr.business_group_id  = p_business_group_id
1577     and   epe_ecr.enrt_bnft_id is null;
1578   --
1579   TYPE l_bckdt_epe_ecr_rec is TABLE OF c_bckdt_epe_ecr%rowtype
1580        INDEX BY BINARY_INTEGER;
1581   --
1582   TYPE l_curr_epe_ecr_rec is TABLE OF c_curr_epe_ecr%rowtype
1583        INDEX BY BINARY_INTEGER;
1584   --
1585   l_bckdt_epe_ecr_table  l_bckdt_epe_ecr_rec;
1586   l_curr_epe_ecr_table   l_curr_epe_ecr_rec;
1587   l_next_row             binary_integer;
1588   l_found                boolean;
1589   l_bckdt_epe_ecr_count  number;
1590   --
1591 begin
1592   --
1593   hr_utility.set_location ('Entering '||l_proc,10);
1594   --
1595   select count(*) into l_bckdt_epe_ecr_count
1596     from   ben_enrt_rt epe_ecr
1597     where epe_ecr.elig_per_elctbl_chc_id = p_bckdt_epe_id
1598     and   epe_ecr.business_group_id  = p_business_group_id
1599     and   epe_ecr.enrt_bnft_id is null;
1600 
1601   /* l_bckdt_epe_ecr_table.delete;
1602   l_next_row := nvl(l_bckdt_epe_ecr_table.LAST, 0) + 1;
1603   --
1604   for bckdt_epe_ecr_rec in c_bckdt_epe_ecr
1605   loop
1606      --
1607      l_bckdt_epe_ecr_table(l_next_row)   := bckdt_epe_ecr_rec;
1608      l_next_row := l_next_row + 1;
1609      --
1610   end loop; */
1611   --
1612   l_curr_epe_ecr_table.delete;
1613   l_next_row := nvl(l_curr_epe_ecr_table.LAST, 0) + 1;
1614   for  curr_epe_ecr_rec in c_curr_epe_ecr
1615   loop
1616      --
1617      l_curr_epe_ecr_table(l_next_row)   := curr_epe_ecr_rec;
1618      l_next_row := l_next_row + 1;
1619      --
1620   end loop;
1621   --
1622   --
1623   -- Check Number of records in both tables for difference
1624   --
1625   if nvl(l_curr_epe_ecr_table.last, 0) = 0  and
1626      nvl(l_bckdt_epe_ecr_count,0)  = 0
1627   then
1628        --
1629        l_differ := 'N';
1630        hr_utility.set_location ('Leavingi : N : 0 '||l_proc,10);
1631        return l_differ;
1632        --
1633   elsif nvl(l_curr_epe_ecr_table.last, 0) <> nvl(l_bckdt_epe_ecr_count,0) then
1634        --
1635        l_differ := 'Y';
1636        hr_utility.set_location ('Leavingi : Y : <>0 '||l_proc,10);
1637        return l_differ;
1638        --
1639   end if;
1640   --
1641   -- Now compare the original epe_ecr record and new epe_ecr record for each epe
1642   --  record.
1643   --
1644   -- for  l_count in l_bckdt_epe_ecr_table.first..l_bckdt_epe_ecr_table.last loop
1645   for bckdt_epe_ecr_rec in c_bckdt_epe_ecr
1646   loop
1647     --
1648     l_found  := FALSE;
1649     --
1650     for  l_curr_count in l_curr_epe_ecr_table.first..l_curr_epe_ecr_table.last
1651     loop
1652       --
1653       if nvl(bckdt_epe_ecr_rec.ACTY_TYP_CD, '$') =
1654                    nvl(l_curr_epe_ecr_table(l_curr_count).ACTY_TYP_CD, '$') and
1655          nvl(bckdt_epe_ecr_rec.TX_TYP_CD, '$') =
1656                    nvl(l_curr_epe_ecr_table(l_curr_count).TX_TYP_CD, '$') and
1657          nvl(bckdt_epe_ecr_rec.CTFN_RQD_FLAG, '$') =
1658                    nvl(l_curr_epe_ecr_table(l_curr_count).CTFN_RQD_FLAG, '$') and
1659          nvl(bckdt_epe_ecr_rec.DFLT_FLAG, '$') =
1660                    nvl(l_curr_epe_ecr_table(l_curr_count).DFLT_FLAG, '$') and
1661          nvl(bckdt_epe_ecr_rec.DFLT_VAL, -1) =
1662                    nvl(l_curr_epe_ecr_table(l_curr_count).DFLT_VAL, -1) and
1663          nvl(bckdt_epe_ecr_rec.ANN_VAL, -1) =
1664                    nvl(l_curr_epe_ecr_table(l_curr_count).ANN_VAL, -1) and
1665          nvl(bckdt_epe_ecr_rec.ANN_MN_ELCN_VAL, -1) =
1666                    nvl(l_curr_epe_ecr_table(l_curr_count).ANN_MN_ELCN_VAL, -1) and
1667          nvl(bckdt_epe_ecr_rec.ANN_MX_ELCN_VAL, -1) =
1668                    nvl(l_curr_epe_ecr_table(l_curr_count).ANN_MX_ELCN_VAL, -1) and
1669          nvl(bckdt_epe_ecr_rec.MX_ELCN_VAL, -1) =
1670                    nvl(l_curr_epe_ecr_table(l_curr_count).MX_ELCN_VAL, -1) and
1671          nvl(bckdt_epe_ecr_rec.MN_ELCN_VAL, -1) =
1672                    nvl(l_curr_epe_ecr_table(l_curr_count).MN_ELCN_VAL, -1) and
1673          nvl(bckdt_epe_ecr_rec.INCRMT_ELCN_VAL, -1) =
1674                    nvl(l_curr_epe_ecr_table(l_curr_count).INCRMT_ELCN_VAL, -1) and
1675          nvl(bckdt_epe_ecr_rec.RT_STRT_DT, hr_api.g_eot) =
1676             nvl(l_curr_epe_ecr_table(l_curr_count).RT_STRT_DT, hr_api.g_eot) and
1677          nvl(bckdt_epe_ecr_rec.RT_STRT_DT_CD, '$') =
1678                    nvl(l_curr_epe_ecr_table(l_curr_count).RT_STRT_DT_CD, '$') and
1679          nvl(bckdt_epe_ecr_rec.RT_STRT_DT_RL, -1) =
1680                    nvl(l_curr_epe_ecr_table(l_curr_count).RT_STRT_DT_RL, -1) and
1681          nvl(bckdt_epe_ecr_rec.ACTY_BASE_RT_ID, -1) =
1682                    nvl(l_curr_epe_ecr_table(l_curr_count).ACTY_BASE_RT_ID, -1) and
1683          nvl(bckdt_epe_ecr_rec.DECR_BNFT_PRVDR_POOL_ID, -1) =
1684             nvl(l_curr_epe_ecr_table(l_curr_count).DECR_BNFT_PRVDR_POOL_ID, -1) and
1685          nvl(bckdt_epe_ecr_rec.CVG_AMT_CALC_MTHD_ID, -1) =
1686             nvl(l_curr_epe_ecr_table(l_curr_count).CVG_AMT_CALC_MTHD_ID, -1) and
1687          nvl(bckdt_epe_ecr_rec.ACTL_PREM_ID, -1) =
1688                    nvl(l_curr_epe_ecr_table(l_curr_count).ACTL_PREM_ID, -1) and
1689          nvl(bckdt_epe_ecr_rec.COMP_LVL_FCTR_ID, -1) =
1690                    nvl(l_curr_epe_ecr_table(l_curr_count).COMP_LVL_FCTR_ID, -1)
1691       then
1692         l_found   := TRUE;
1693         exit;
1694       end if;
1695       --
1696     end loop;
1697     --
1698     if l_found   = FALSE then
1699        --
1700        -- Current epe for a given backed out epe is not found
1701        --
1702        l_differ := 'Y';
1703        exit;
1704     end if;
1705   --
1706   end loop;
1707   --
1708   hr_utility.set_location('Leaving:'||l_differ ||  l_proc, 10);
1709   --
1710   return l_differ;
1711   --
1712 end comp_ori_new_epe_ecr;
1713 --
1714 -- ----------------------------------------------------------------------------
1715 -- |------------------------< comp_ori_new_enb >-------------------------|
1716 -- ----------------------------------------------------------------------------
1717 --
1718 -- This procedure compares the original and new enrollment benefit
1719 -- for comparable electble choice and per in ler id.
1720 --
1721 function comp_ori_new_enb(p_person_id               in number
1722                           ,p_business_group_id      in number
1723                           ,p_effective_date         in date
1724                           ,p_per_in_ler_id          in number
1725                           ,p_bckdt_per_in_ler_id    in number
1726                           ,p_curr_epe_id            in number
1727                           ,p_bckdt_epe_id           in number
1728                           ) return varchar2 is
1729   --
1730   l_proc                    varchar2(72) := g_package||'.comp_ori_new_enb';
1731   --
1732   l_differ                  varchar2(1) := 'N';
1733   l_enb_ecr_differ          varchar2(1) := 'N';
1734   --
1735   cursor c_bckdt_enb is
1736     select enb.dflt_flag
1737           ,enb.bndry_perd_cd
1738           ,enb.val
1739           ,enb.bnft_typ_cd
1740           ,enb.mn_val
1741           ,enb.mx_val
1742           ,enb.incrmt_val
1743           ,enb.rt_typ_cd
1744           ,enb.cvg_mlt_cd
1745           ,enb.ctfn_rqd_flag
1746           ,enb.ordr_num
1747           ,enb.dflt_val
1748           ,enb.comp_lvl_fctr_id
1749           ,enb.enrt_bnft_id
1750     from   ben_enrt_bnft enb
1751     where enb.elig_per_elctbl_chc_id = p_bckdt_epe_id ;
1752   --
1753   cursor c_curr_enb is
1754     select enb.dflt_flag
1755           ,enb.bndry_perd_cd
1756           ,enb.val
1757           ,enb.bnft_typ_cd
1758           ,enb.mn_val
1759           ,enb.mx_val
1760           ,enb.incrmt_val
1761           ,enb.rt_typ_cd
1762           ,enb.cvg_mlt_cd
1763           ,enb.ctfn_rqd_flag
1764           ,enb.ordr_num
1765           ,enb.dflt_val
1766           ,enb.comp_lvl_fctr_id
1767           ,enb.enrt_bnft_id
1768     from   ben_enrt_bnft enb
1769     where enb.elig_per_elctbl_chc_id = p_curr_epe_id ;
1770   --
1771   TYPE l_bckdt_enb_rec is TABLE OF c_bckdt_enb%rowtype
1772        INDEX BY BINARY_INTEGER;
1773   --
1774   TYPE l_curr_enb_rec is TABLE OF c_curr_enb%rowtype
1775        INDEX BY BINARY_INTEGER;
1776   --
1777   l_bckdt_enb_table l_bckdt_enb_rec;
1778   l_curr_enb_table  l_curr_enb_rec;
1779   l_next_row        binary_integer;
1780   l_found           boolean;
1781   l_bckdt_enb_count number;
1782   --
1783 begin
1784   --
1785   hr_utility.set_location ('Entering '||l_proc,10);
1786   --
1787   select count(*) into l_bckdt_enb_count
1788     from   ben_enrt_bnft enb
1789     where enb.elig_per_elctbl_chc_id = p_bckdt_epe_id
1790     and   enb.business_group_id  = p_business_group_id;
1791 /*
1792   l_bckdt_enb_table.delete;
1793   l_next_row := nvl(l_bckdt_enb_table.LAST, 0) + 1;
1794   --
1795   for bckdt_enb_rec in c_bckdt_enb
1796   loop
1797      --
1798      --
1799      l_bckdt_enb_table(l_next_row)   := bckdt_enb_rec;
1800      l_next_row := l_next_row + 1;
1801      --
1802   end loop;
1803 */
1804   --
1805   l_curr_enb_table.delete;
1806   l_next_row := nvl(l_curr_enb_table.LAST, 0) + 1;
1807   for  curr_enb_rec in c_curr_enb
1808   loop
1809      --
1810      l_curr_enb_table(l_next_row)   := curr_enb_rec;
1811      l_next_row := l_next_row + 1;
1812      --
1813   end loop;
1814   --
1815   -- Check Number of records in both tables differ
1816   --
1817   if nvl(l_curr_enb_table.last, 0) = 0  and
1818      nvl(l_bckdt_enb_count,0)  = 0
1819   then
1820        --
1821        l_differ := 'N';
1822 
1823        hr_utility.set_location('Leaving:  ' || l_differ ||' 0 '|| l_proc, 10);
1824        return l_differ;
1825        --
1826   elsif nvl(l_curr_enb_table.last, 0) <> nvl(l_bckdt_enb_count,0) then
1827        --
1828        l_differ := 'Y';
1829 
1830        hr_utility.set_location('Leaving:  ' || l_differ ||' <>0 '|| l_proc, 10);
1831        return l_differ;
1832        --
1833   end if;
1834   --
1835   --
1836   -- Now compare the original enb record and new enb record for each epe record.
1837   --
1838   -- for  l_count in l_bckdt_enb_table.first..l_bckdt_enb_table.last loop
1839   for bckdt_enb_rec in c_bckdt_enb
1840   loop
1841     --
1842     l_found  := FALSE;
1843     --
1844     for  l_curr_count in l_curr_enb_table.first..l_curr_enb_table.last loop
1845       --
1846       if nvl(bckdt_enb_rec.dflt_flag, '$') =
1847                    nvl(l_curr_enb_table(l_curr_count).dflt_flag, '$') and
1848          nvl(bckdt_enb_rec.bndry_perd_cd, '$') =
1849                    nvl(l_curr_enb_table(l_curr_count).bndry_perd_cd, '$') and
1850          nvl(bckdt_enb_rec.val, -1) =
1851                    nvl(l_curr_enb_table(l_curr_count).val, -1) and
1852          nvl(bckdt_enb_rec.bnft_typ_cd, '$') =
1853                    nvl(l_curr_enb_table(l_curr_count).bnft_typ_cd, '$') and
1854          nvl(bckdt_enb_rec.mn_val, -1) =
1855                    nvl(l_curr_enb_table(l_curr_count).mn_val, -1) and
1856          nvl(bckdt_enb_rec.mx_val, -1) =
1857                    nvl(l_curr_enb_table(l_curr_count).mx_val, -1) and
1858          nvl(bckdt_enb_rec.incrmt_val, -1) =
1859                    nvl(l_curr_enb_table(l_curr_count).incrmt_val, -1) and
1860          nvl(bckdt_enb_rec.rt_typ_cd, '$') =
1861                    nvl(l_curr_enb_table(l_curr_count).rt_typ_cd, '$') and
1862          nvl(bckdt_enb_rec.cvg_mlt_cd, '$') =
1863                    nvl(l_curr_enb_table(l_curr_count).cvg_mlt_cd, '$') and
1864          nvl(bckdt_enb_rec.cvg_mlt_cd, '$') =
1865                    nvl(l_curr_enb_table(l_curr_count).cvg_mlt_cd, '$') and
1866          nvl(bckdt_enb_rec.ctfn_rqd_flag, '$') =
1867                    nvl(l_curr_enb_table(l_curr_count).ctfn_rqd_flag, '$') and
1868          nvl(bckdt_enb_rec.ordr_num, -1) =
1869                    nvl(l_curr_enb_table(l_curr_count).ordr_num, -1) and
1870          nvl(bckdt_enb_rec.dflt_val, -1) =
1871                    nvl(l_curr_enb_table(l_curr_count).dflt_val, -1) and
1872          nvl(bckdt_enb_rec.comp_lvl_fctr_id, -1) =
1873                    nvl(l_curr_enb_table(l_curr_count).comp_lvl_fctr_id, -1)
1874       then
1875         --
1876         l_enb_ecr_differ := comp_ori_new_enb_ecr(
1877            p_person_id              => p_person_id
1878            ,p_business_group_id     => p_business_group_id
1879            ,p_effective_date        => p_effective_date
1880            ,p_per_in_ler_id         => p_per_in_ler_id
1881            ,p_bckdt_per_in_ler_id   => p_bckdt_per_in_ler_id
1882            ,p_curr_enb_id           => l_curr_enb_table(l_curr_count).enrt_bnft_id
1883            ,p_bckdt_enb_id          => bckdt_enb_rec.enrt_bnft_id
1884            );
1885         --
1886         if l_enb_ecr_differ = 'Y' then
1887            --
1888            -- even though epe, ecd, enb are same there may be differences
1889            -- in enrt_rt
1890            --
1891            l_found   := FALSE;
1892            --
1893         else
1894            --
1895            l_found   := TRUE;
1896            --
1897         end if;
1898         exit;
1899       end if;
1900       --
1901     end loop;
1902     --
1903     if l_found   = FALSE then
1904        --
1905        -- Current epe for a given backed out epe is not found
1906        --
1907        l_differ := 'Y';
1908        exit;
1909     end if;
1910   --
1911   end loop;
1912   --
1913 
1914   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
1915   --
1916   return l_differ;
1917   --
1918 end comp_ori_new_enb;
1919 --
1920 -- ----------------------------------------------------------------------------
1921 -- |------------------------< comp_ori_new_ecd >-------------------------|
1922 -- ----------------------------------------------------------------------------
1923 --
1924 -- This procedure compares the original and new elig covered dependents
1925 -- for comparable electble choice and per in ler id.
1926 --
1927 function comp_ori_new_ecd(p_person_id               in number
1928                           ,p_business_group_id      in number
1929                           ,p_effective_date         in date
1930                           ,p_per_in_ler_id          in number
1931                           ,p_bckdt_per_in_ler_id    in number
1932                           ,p_curr_epe_id            in number
1933                           ,p_bckdt_epe_id           in number
1934                           ) return varchar2 is
1935   --
1936   l_proc                    varchar2(72) := g_package||'.comp_ori_new_ecd';
1937   --
1938   l_differ                  varchar2(1) := 'N';
1939   --
1940   cursor c_bckdt_ecd is
1941     select ecd.effective_start_date
1942           ,ecd.effective_end_date
1943           ,ecd.cvg_strt_dt
1944           ,ecd.cvg_thru_dt
1945           ,ecd.cvg_pndg_flag
1946           ,ecd.ovrdn_flag
1947           ,ecd.ovrdn_thru_dt
1948           ,ecd.dpnt_person_id
1949     from   ben_elig_cvrd_dpnt_f ecd,
1950            ben_per_in_ler pil
1951     where  ecd.business_group_id=p_business_group_id
1952     and p_effective_date between
1953         ecd.effective_start_date and ecd.effective_end_date
1954     and pil.per_in_ler_id=ecd.per_in_ler_id
1955     and ecd.elig_per_elctbl_chc_id = p_bckdt_epe_id
1956     and pil.per_in_ler_id=p_bckdt_per_in_ler_id
1957     and pil.business_group_id=ecd.business_group_id
1958     and pil.per_in_ler_stat_cd = 'BCKDT';
1959   --
1960   cursor c_curr_ecd(p_effective_date date,
1961                     p_curr_epe_id number,
1962                     p_per_in_ler_id number) is
1963     select ecd.effective_start_date
1964           ,ecd.effective_end_date
1965           ,ecd.cvg_strt_dt
1966           ,ecd.cvg_thru_dt
1967           ,ecd.cvg_pndg_flag
1968           ,ecd.ovrdn_flag
1969           ,ecd.ovrdn_thru_dt
1970           ,ecd.dpnt_person_id
1971     from   ben_elig_cvrd_dpnt_f ecd,
1972            ben_per_in_ler pil
1973     where  p_effective_date between
1974         ecd.effective_start_date and ecd.effective_end_date
1975     and pil.per_in_ler_id=ecd.per_in_ler_id
1976     and ecd.elig_per_elctbl_chc_id = p_curr_epe_id
1977     and pil.per_in_ler_id=p_per_in_ler_id
1978     and pil.business_group_id=ecd.business_group_id;
1979   --
1980   TYPE l_bckdt_ecd_rec is TABLE OF c_bckdt_ecd%rowtype
1981        INDEX BY BINARY_INTEGER;
1982   --
1983   TYPE l_curr_ecd_rec is TABLE OF c_curr_ecd%rowtype
1984        INDEX BY BINARY_INTEGER;
1985   --
1986   l_bckdt_ecd_table l_bckdt_ecd_rec;
1987   l_curr_ecd_table  l_curr_ecd_rec;
1988   l_next_row        binary_integer;
1989   l_found           boolean;
1990   l_bckdt_ecd_count number;
1991   --
1992 begin
1993   --
1994   hr_utility.set_location ('Entering '||l_proc,10);
1995   --
1996   select count(*) into l_bckdt_ecd_count
1997     from   ben_elig_cvrd_dpnt_f ecd,
1998            ben_per_in_ler pil
1999     where  ecd.business_group_id=p_business_group_id
2000     and p_effective_date between
2001         ecd.effective_start_date and ecd.effective_end_date
2002     and pil.per_in_ler_id=ecd.per_in_ler_id
2003     and ecd.elig_per_elctbl_chc_id = p_bckdt_epe_id
2004     and pil.per_in_ler_id=p_bckdt_per_in_ler_id
2005     and pil.business_group_id=ecd.business_group_id
2006     and pil.per_in_ler_stat_cd = 'BCKDT';
2007   --
2008   l_curr_ecd_table.delete;
2009   l_next_row := nvl(l_curr_ecd_table.LAST, 0) + 1;
2010   --
2011   for  curr_ecd_rec  in c_curr_ecd(p_effective_date,p_curr_epe_id,p_per_in_ler_id)
2012   loop
2013      --
2014      l_curr_ecd_table(l_next_row)   := curr_ecd_rec;
2015      l_next_row := l_next_row + 1;
2016      --
2017   end loop;
2018   --
2019   -- Check Number of records in both tables differ
2020   --
2021   if nvl(l_curr_ecd_table.last, 0) = 0  and
2022      nvl(l_bckdt_ecd_count,0)  = 0
2023   then
2024        --
2025        l_differ := 'N';
2026 
2027        hr_utility.set_location('Leaving:  ' || l_differ ||' 0 '|| l_proc, 10);
2028        return l_differ;
2029        --
2030   elsif nvl(l_curr_ecd_table.last, 0) <> nvl(l_bckdt_ecd_count,0) then
2031        --
2032        l_differ := 'Y';
2033 
2034        hr_utility.set_location('Leaving:  ' || l_differ ||' <>0 '|| l_proc, 10);
2035        return l_differ;
2036        --
2037   end if;
2038   --
2039   --
2040   -- Now compare the original ecd record and new ecd record for each epe record.
2041   --
2042   for bckdt_ecd_rec in c_bckdt_ecd
2043   loop
2044     --
2045     l_found  := FALSE;
2046     --
2047     for  l_curr_count in l_curr_ecd_table.first..l_curr_ecd_table.last loop
2048       --
2049       if nvl(bckdt_ecd_rec.dpnt_person_id, -1) =
2050                    nvl(l_curr_ecd_table(l_curr_count).dpnt_person_id, -1) and
2051          nvl(bckdt_ecd_rec.effective_end_date, hr_api.g_eot) =
2052             nvl(l_curr_ecd_table(l_curr_count).effective_end_date, hr_api.g_eot) and
2053          nvl(bckdt_ecd_rec.cvg_thru_dt, hr_api.g_eot) =
2054                nvl(l_curr_ecd_table(l_curr_count).cvg_thru_dt, hr_api.g_eot)
2055       then
2056         l_found   := TRUE;
2057         exit;
2058       end if;
2059       --
2060     end loop;
2061     --
2062     if l_found   = FALSE then
2063        --
2064        -- Current epe for a given backed out epe is not found
2065        --
2066        l_differ := 'Y';
2067        exit;
2068     end if;
2069     --
2070   end loop;
2071   --
2072 
2073   hr_utility.set_location('Leaving:  ' || l_differ ||' 0 '|| l_proc, 10);
2074   --
2075   return l_differ;
2076   --
2077 end comp_ori_new_ecd;
2078 --
2079 -- ----------------------------------------------------------------------------
2080 -- |------------------------< comp_ori_new_pil_outcome >-------------------------|
2081 -- ----------------------------------------------------------------------------
2082 --
2083 -- This procedure compares the original and new electability
2084 -- data associated with the same ler and returns Y if changes
2085 -- exists else returns N.
2086 --
2087 function comp_ori_new_pil_outcome(p_person_id       in number
2088                               ,p_business_group_id   in number
2089                               ,p_ler_id              in number
2090                               ,p_effective_date      in date
2091                               ,p_per_in_ler_id       in number
2092                               ,p_bckdt_per_in_ler_id in number
2093                            ) return varchar2 is
2094   --
2095   l_proc                   varchar2(72) := g_package||'.comp_ori_new_pil_outcome';
2096   --
2097   -- Following are the tables whose data will be compared to
2098   -- find any differences exists between the two runs of same ler.
2099   --
2100   -- ben_elig_cvrd_dpnt_f
2101   -- ben_prtt_enrt_actn_f
2102   -- ben_elig_per_elctbl_chc    -- 9999 done
2103   -- ben_enrt_bnft
2104   -- ben_enrt_rt
2105   -- ben_elctbl_chc_ctfn
2106   --
2107   cursor c_bckdt_epe_cnt is
2108     select count(*)
2109     from   ben_elig_per_elctbl_chc epe,
2110            ben_per_in_ler pil
2111     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
2112     and    pil.person_id           = p_person_id
2113     and    pil.business_group_id = p_business_group_id
2114     AND    pil.per_in_ler_id       = epe.per_in_ler_id;
2115   --   and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
2116   --
2117   cursor c_curr_epe_cnt is
2118     select count(*)
2119     from   ben_elig_per_elctbl_chc epe,
2120            ben_per_in_ler pil
2121     where  pil.per_in_ler_id       = p_per_in_ler_id
2122     and    pil.person_id           = p_person_id
2123     and    pil.business_group_id = p_business_group_id
2124     AND    pil.per_in_ler_id       = epe.per_in_ler_id;
2125   --   and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT'); -- 9999 any status codes to add.
2126   --  and    pil.per_in_ler_stat_cd = 'STRTD'
2127   --
2128   l_bckdt_epe_cnt           number  := 0;
2129   l_curr_epe_cnt            number  := 0;
2130   l_differ                  varchar2(1) := 'N';
2131   l_egd_differ              varchar2(1) := 'N';
2132   l_ecd_differ              varchar2(1) := 'N';
2133   l_enb_differ              varchar2(1) := 'N';
2134   l_epe_ecr_differ          varchar2(1) := 'N';
2135   l_diff_auto_flag          boolean   := true ;
2136   --
2137   cursor c_bckdt_epe_dat is
2138     select epe.*
2139     from   ben_elig_per_elctbl_chc epe,
2140            ben_per_in_ler pil
2141     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
2142     and    pil.person_id           = p_person_id
2143     and    pil.business_group_id = p_business_group_id
2144     AND    pil.per_in_ler_id       = epe.per_in_ler_id;
2145   --   and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
2146   --
2147   cursor c_curr_epe_dat is
2148     select epe.*
2149     from   ben_elig_per_elctbl_chc epe,
2150            ben_per_in_ler pil
2151     where  pil.per_in_ler_id       = p_per_in_ler_id
2152     and    pil.person_id           = p_person_id
2153     and    pil.business_group_id = p_business_group_id
2154     AND    pil.per_in_ler_id       = epe.per_in_ler_id;
2155   --
2156   TYPE l_bckdt_epe_rec is TABLE OF c_bckdt_epe_dat%rowtype
2157        INDEX BY BINARY_INTEGER;
2158   --
2159   TYPE l_curr_epe_rec is TABLE OF c_curr_epe_dat%rowtype
2160        INDEX BY BINARY_INTEGER;
2161   --
2162   l_bckdt_epe_table l_bckdt_epe_rec;
2163   l_curr_epe_table  l_curr_epe_rec;
2164   l_next_row        binary_integer;
2165   l_found           boolean;
2166   --
2167 begin
2168   --
2169   hr_utility.set_location ('Entering '||l_proc,10);
2170   --
2171   open  c_bckdt_epe_cnt;
2172   fetch c_bckdt_epe_cnt into l_bckdt_epe_cnt;
2173   close c_bckdt_epe_cnt;
2174   --
2175   open  c_curr_epe_cnt;
2176   fetch c_curr_epe_cnt into l_curr_epe_cnt;
2177   close c_curr_epe_cnt;
2178   --
2179   if l_bckdt_epe_cnt <> l_curr_epe_cnt then
2180      --
2181      l_differ := 'Y';
2182      --
2183   elsif (l_bckdt_epe_cnt = 0 and  l_curr_epe_cnt = 0) then
2184      --
2185      -- How to handle the case where the elecable choices are 0 9999
2186      --
2187      l_differ := 'N';
2188      --
2189   else
2190      --
2191      -- count of epe is same so look for actual diffs.
2192      --
2193      l_bckdt_epe_table.delete;
2194      l_next_row := nvl(l_bckdt_epe_table.LAST, 0) + 1;
2195      --
2196      for bckdt_epe_rec in c_bckdt_epe_dat
2197      loop
2198         --
2199         l_bckdt_epe_table(l_next_row)   := bckdt_epe_rec;
2200         l_next_row := l_next_row + 1;
2201         --
2202      end loop;
2203      --
2204      l_curr_epe_table.delete;
2205      l_next_row := nvl(l_curr_epe_table.LAST, 0) + 1;
2206      for  curr_epe_rec in c_curr_epe_dat
2207      loop
2208         --
2209         l_curr_epe_table(l_next_row)   := curr_epe_rec;
2210         l_next_row := l_next_row + 1;
2211         --
2212      end loop;
2213      --
2214      -- Now compare the original epe record and new epe record for each comp
2215      -- object.
2216      --
2217      for  l_count in l_bckdt_epe_table.first..l_bckdt_epe_table.last loop
2218        --
2219 /*
2220 hr_utility.set_location('pl_id = ' || nvl(l_bckdt_epe_table(l_count).pl_id, -1), 1234);
2221 hr_utility.set_location('oipl_id = ' || nvl(l_bckdt_epe_table(l_count).oipl_id, -1), 1234);
2222 hr_utility.set_location('PGM_ID = ' || nvl(l_bckdt_epe_table(l_count).PGM_ID, -1), 1234);
2223 hr_utility.set_location('PLIP_ID = ' || nvl(l_bckdt_epe_table(l_count).PLIP_ID, -1), 1234);
2224 hr_utility.set_location('PTIP_ID = ' || nvl(l_bckdt_epe_table(l_count).PTIP_ID, -1), 1234);
2225 hr_utility.set_location('PL_TYP_ID = ' || nvl(l_bckdt_epe_table(l_count).PL_TYP_ID, -1), 1234);
2226 hr_utility.set_location('CMBN_PTIP_ID = ' || nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_ID, -1), 1234);
2227 hr_utility.set_location('CMBN_PTIP_OPT_ID = ' || nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_OPT_ID, -1), 1234);
2228 hr_utility.set_location('CMBN_PLIP_ID = ' || nvl(l_bckdt_epe_table(l_count).CMBN_PLIP_ID, -1), 1234);
2229 hr_utility.set_location('SPCL_RT_PL_ID = ' || nvl(l_bckdt_epe_table(l_count).SPCL_RT_PL_ID, -1), 1234);
2230 hr_utility.set_location('SPCL_RT_OIPL_ID = ' || nvl(l_bckdt_epe_table(l_count).SPCL_RT_OIPL_ID, -1), 1234);
2231 hr_utility.set_location('MUST_ENRL_ANTHR_PL_ID = ' || nvl(l_bckdt_epe_table(l_count).MUST_ENRL_ANTHR_PL_ID, -1), 1234);
2232 hr_utility.set_location('DFLT_FLAG = ' || l_bckdt_epe_table(l_count).DFLT_FLAG, 1234);
2233 hr_utility.set_location('ELCTBL_FLAG = ' || l_bckdt_epe_table(l_count).ELCTBL_FLAG, 1234);
2234 hr_utility.set_location('MNDTRY_FLAG = ' || l_bckdt_epe_table(l_count).MNDTRY_FLAG, 1234);
2235 hr_utility.set_location('ALWS_DPNT_DSGN_FLAG = ' || l_bckdt_epe_table(l_count).ALWS_DPNT_DSGN_FLAG, 1234);
2236 hr_utility.set_location('AUTO_ENRT_FLAG = ' || l_bckdt_epe_table(l_count).AUTO_ENRT_FLAG, 1234);
2237 hr_utility.set_location('CTFN_RQD_FLAG = ' || l_bckdt_epe_table(l_count).CTFN_RQD_FLAG, 1234);
2238 hr_utility.set_location('BNFT_PRVDR_POOL_ID = ' || nvl(l_bckdt_epe_table(l_count).BNFT_PRVDR_POOL_ID, -1), 1234);
2239 hr_utility.set_location('YR_PERD_ID = ' || nvl(l_bckdt_epe_table(l_count).YR_PERD_ID, -1), 1234);
2240 hr_utility.set_location('ENRT_CVG_STRT_DT_CD = ' || nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_CD, '$'), 1234);
2241 hr_utility.set_location('ENRT_CVG_STRT_DT_RL = ' || nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_RL, -1), 1234);
2242 hr_utility.set_location('DPNT_CVG_STRT_DT_CD = ' || nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_CD, '$'), 1234);
2243 hr_utility.set_location('LER_CHG_DPNT_CVG_CD = ' || nvl(l_bckdt_epe_table(l_count).LER_CHG_DPNT_CVG_CD, '$'), 1234);
2244 hr_utility.set_location('DPNT_CVG_STRT_DT_RL = ' || nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_RL, -1), 1234);
2245 hr_utility.set_location('ENRT_CVG_STRT_DT = ' || nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT, hr_api.g_eot), 1234);
2246 hr_utility.set_location('ERLST_DEENRT_DT = ' || nvl(l_bckdt_epe_table(l_count).ERLST_DEENRT_DT, hr_api.g_eot), 1234);
2247 */
2248        l_found  := FALSE;
2249        l_diff_auto_flag := TRUE ;
2250        --
2251        for  l_curr_count in l_curr_epe_table.first..l_curr_epe_table.last loop
2252          --
2253 /*
2254 hr_utility.set_location('Curr pl_id = ' || nvl(l_curr_epe_table(l_curr_count).pl_id, -1), 1234);
2255 hr_utility.set_location('Curr oipl_id = ' || nvl(l_curr_epe_table(l_curr_count).oipl_id, -1), 1234);
2256 hr_utility.set_location('Curr PGM_ID = ' || nvl(l_curr_epe_table(l_curr_count).PGM_ID, -1), 1234);
2257 hr_utility.set_location('Curr PLIP_ID = ' || nvl(l_curr_epe_table(l_curr_count).PLIP_ID, -1), 1234);
2258 hr_utility.set_location('Curr PTIP_ID = ' || nvl(l_curr_epe_table(l_curr_count).PTIP_ID, -1), 1234);
2259 hr_utility.set_location('Curr PL_TYP_ID = ' || nvl(l_curr_epe_table(l_curr_count).PL_TYP_ID, -1), 1234);
2260 hr_utility.set_location('Curr CMBN_PTIP_ID = ' || nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_ID, -1), 1234);
2261 hr_utility.set_location('Curr CMBN_PTIP_OPT_ID = ' || nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_OPT_ID, -1), 1234);
2262 hr_utility.set_location('Curr CMBN_PLIP_ID = ' || nvl(l_curr_epe_table(l_curr_count).CMBN_PLIP_ID, -1), 1234);
2263 hr_utility.set_location('Curr SPCL_RT_PL_ID = ' || nvl(l_curr_epe_table(l_curr_count).SPCL_RT_PL_ID, -1), 1234);
2264 hr_utility.set_location('Curr SPCL_RT_OIPL_ID = ' || nvl(l_curr_epe_table(l_curr_count).SPCL_RT_OIPL_ID, -1), 1234);
2265 hr_utility.set_location('Curr MUST_ENRL_ANTHR_PL_ID = ' || nvl(l_curr_epe_table(l_curr_count).MUST_ENRL_ANTHR_PL_ID, -1), 1234);
2266 hr_utility.set_location('Curr DFLT_FLAG = ' || l_curr_epe_table(l_curr_count).DFLT_FLAG, 1234);
2267 hr_utility.set_location('Curr ELCTBL_FLAG = ' || l_curr_epe_table(l_curr_count).ELCTBL_FLAG, 1234);
2268 hr_utility.set_location('Curr MNDTRY_FLAG = ' || l_curr_epe_table(l_curr_count).MNDTRY_FLAG, 1234);
2269 hr_utility.set_location('Curr ALWS_DPNT_DSGN_FLAG = ' || l_curr_epe_table(l_curr_count).ALWS_DPNT_DSGN_FLAG, 1234);
2270 hr_utility.set_location('Curr AUTO_ENRT_FLAG = ' || l_curr_epe_table(l_curr_count).AUTO_ENRT_FLAG, 1234);
2271 hr_utility.set_location('Curr CTFN_RQD_FLAG = ' || l_curr_epe_table(l_curr_count).CTFN_RQD_FLAG, 1234);
2272 hr_utility.set_location('Curr BNFT_PRVDR_POOL_ID = ' || nvl(l_curr_epe_table(l_curr_count).BNFT_PRVDR_POOL_ID, -1), 1234);
2273 hr_utility.set_location('Curr YR_PERD_ID = ' || nvl(l_curr_epe_table(l_curr_count).YR_PERD_ID, -1), 1234);
2274 hr_utility.set_location('Curr ENRT_CVG_STRT_DT_CD = ' || nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_CD,  '$'), 1234);
2275 hr_utility.set_location('Curr ENRT_CVG_STRT_DT_RL = ' || nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_RL, -1), 1234);
2276 hr_utility.set_location('Curr DPNT_CVG_STRT_DT_CD = ' || nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_CD,  '$'), 1234);
2277 hr_utility.set_location('Curr LER_CHG_DPNT_CVG_CD = ' || nvl(l_curr_epe_table(l_curr_count).LER_CHG_DPNT_CVG_CD,  '$'), 1234);
2278 hr_utility.set_location('Curr DPNT_CVG_STRT_DT_RL = ' || nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_RL, -1), 1234);
2279 hr_utility.set_location('Curr ENRT_CVG_STRT_DT = ' || nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT, hr_api.g_eot), 1234);
2280 hr_utility.set_location('Curr ERLST_DEENRT_DT = ' || nvl(l_curr_epe_table(l_curr_count).ERLST_DEENRT_DT, hr_api.g_eot) , 1234);
2281 
2282 
2283  if l_bckdt_epe_table(l_count).AUTO_ENRT_FLAG = 'Y'     and
2284     l_curr_epe_table(l_curr_count).AUTO_ENRT_FLAG = 'Y' and
2285     l_bckdt_epe_table(l_count).CRNTLY_ENRD_FLAG   =
2286                 l_curr_epe_table(l_curr_count).CRNTLY_ENRD_FLAG
2287 
2288  then
2289       l_diff_auto_flag := FALSE ;
2290  end if ;
2291 */
2292 
2293      --    if l_diff_auto_flag and
2294          if  nvl(l_bckdt_epe_table(l_count).pl_id, -1) =
2295                       nvl(l_curr_epe_table(l_curr_count).pl_id, -1) and
2296             nvl(l_bckdt_epe_table(l_count).oipl_id, -1) =
2297                       nvl(l_curr_epe_table(l_curr_count).oipl_id, -1) and
2298             nvl(l_bckdt_epe_table(l_count).PGM_ID, -1) =
2299                       nvl(l_curr_epe_table(l_curr_count).PGM_ID, -1) and
2300             nvl(l_bckdt_epe_table(l_count).PLIP_ID, -1) =
2301                       nvl(l_curr_epe_table(l_curr_count).PLIP_ID, -1) and
2302             nvl(l_bckdt_epe_table(l_count).PTIP_ID, -1) =
2303                       nvl(l_curr_epe_table(l_curr_count).PTIP_ID, -1) and
2304             nvl(l_bckdt_epe_table(l_count).PL_TYP_ID, -1) =
2305                       nvl(l_curr_epe_table(l_curr_count).PL_TYP_ID, -1) and
2306             nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_ID, -1) =
2307                       nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_ID, -1) and
2308             nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_OPT_ID, -1) =
2309                       nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_OPT_ID, -1) and
2310             nvl(l_bckdt_epe_table(l_count).CMBN_PLIP_ID, -1) =
2311                       nvl(l_curr_epe_table(l_curr_count).CMBN_PLIP_ID, -1) and
2312             nvl(l_bckdt_epe_table(l_count).SPCL_RT_PL_ID, -1) =
2313                       nvl(l_curr_epe_table(l_curr_count).SPCL_RT_PL_ID, -1) and
2314             nvl(l_bckdt_epe_table(l_count).SPCL_RT_OIPL_ID, -1) =
2315                       nvl(l_curr_epe_table(l_curr_count).SPCL_RT_OIPL_ID, -1) and
2316             nvl(l_bckdt_epe_table(l_count).MUST_ENRL_ANTHR_PL_ID, -1) =
2317                nvl(l_curr_epe_table(l_curr_count).MUST_ENRL_ANTHR_PL_ID, -1) and
2318             l_bckdt_epe_table(l_count).DFLT_FLAG =
2319                       l_curr_epe_table(l_curr_count).DFLT_FLAG and
2320             l_bckdt_epe_table(l_count).ELCTBL_FLAG =
2321                       l_curr_epe_table(l_curr_count).ELCTBL_FLAG and
2322             l_bckdt_epe_table(l_count).MNDTRY_FLAG =
2323                       l_curr_epe_table(l_curr_count).MNDTRY_FLAG and
2324             l_bckdt_epe_table(l_count).ALWS_DPNT_DSGN_FLAG =
2325                       l_curr_epe_table(l_curr_count).ALWS_DPNT_DSGN_FLAG and
2326             l_bckdt_epe_table(l_count).AUTO_ENRT_FLAG =
2327                       l_curr_epe_table(l_curr_count).AUTO_ENRT_FLAG and
2328             l_bckdt_epe_table(l_count).CTFN_RQD_FLAG =
2329                       l_curr_epe_table(l_curr_count).CTFN_RQD_FLAG and
2330             nvl(l_bckdt_epe_table(l_count).BNFT_PRVDR_POOL_ID, -1) =
2331                nvl(l_curr_epe_table(l_curr_count).BNFT_PRVDR_POOL_ID, -1) and
2332             nvl(l_bckdt_epe_table(l_count).YR_PERD_ID, -1) =
2333                       nvl(l_curr_epe_table(l_curr_count).YR_PERD_ID, -1) and
2334             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_CD, '$') =
2335                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_CD,  '$') and
2336             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_RL, -1) =
2337                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_RL, -1) and
2338             nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_CD, '$') =
2339                nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_CD,  '$') and
2340             nvl(l_bckdt_epe_table(l_count).LER_CHG_DPNT_CVG_CD, '$') =
2341                nvl(l_curr_epe_table(l_curr_count).LER_CHG_DPNT_CVG_CD,  '$') and
2342             nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_RL, -1) =
2343                nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_RL, -1) and
2344             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT, hr_api.g_eot) =
2345                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT, hr_api.g_eot) and
2346             nvl(l_bckdt_epe_table(l_count).ERLST_DEENRT_DT, hr_api.g_eot) =
2347                nvl(l_curr_epe_table(l_curr_count).ERLST_DEENRT_DT, hr_api.g_eot)
2348          then
2349           --
2350           -- Now check elig_dpnt rows for any differences.
2351           --
2352           l_egd_differ := comp_ori_new_egd(
2353                            p_person_id              => p_person_id
2354                           ,p_business_group_id      => p_business_group_id
2355                           ,p_effective_date         => p_effective_date
2356                           ,p_per_in_ler_id          => p_per_in_ler_id
2357                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2358                           ,p_curr_epe_id            =>
2359                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2360                           ,p_bckdt_epe_id           =>
2361                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2362                           );
2363           --
2364           if l_egd_differ = 'Y' then
2365            --
2366            l_found   := FALSE;
2367            --
2368           else
2369            --
2370            l_ecd_differ := comp_ori_new_ecd(
2371                            p_person_id              => p_person_id
2372                           ,p_business_group_id      => p_business_group_id
2373                           ,p_effective_date         => p_effective_date
2374                           ,p_per_in_ler_id          => p_per_in_ler_id
2375                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2376                           ,p_curr_epe_id            =>
2377                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2378                           ,p_bckdt_epe_id           =>
2379                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2380                           );
2381            --
2382            if l_ecd_differ = 'Y' then
2383               --
2384               -- even though epe is same ecd differ logically we need to exit.
2385               --
2386               l_found   := FALSE;
2387            else
2388               --
2389               l_enb_differ := comp_ori_new_enb(
2390                            p_person_id              => p_person_id
2391                           ,p_business_group_id      => p_business_group_id
2392                           ,p_effective_date         => p_effective_date
2393                           ,p_per_in_ler_id          => p_per_in_ler_id
2394                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2395                           ,p_curr_epe_id            =>
2396                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2397                           ,p_bckdt_epe_id           =>
2398                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2399                           );
2400               --
2401               if l_enb_differ = 'Y' then
2402                  --
2403                  -- even though epe, ecd are same there may be differences in
2404                  -- enrt_bnft
2405                  --
2406                  l_found   := FALSE;
2407               else
2408                  --
2409                  l_epe_ecr_differ := comp_ori_new_epe_ecr(
2410                            p_person_id              => p_person_id
2411                           ,p_business_group_id      => p_business_group_id
2412                           ,p_effective_date         => p_effective_date
2413                           ,p_per_in_ler_id          => p_per_in_ler_id
2414                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2415                           ,p_curr_epe_id            =>
2416                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2417                           ,p_bckdt_epe_id           =>
2418                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2419                           );
2420                  --
2421                  if l_epe_ecr_differ = 'Y' then
2422                     --
2423                     -- even though epe, ecd, enb are same there may be
2424                     -- differences in enrt_rt
2425                     --
2426                     l_found   := FALSE;
2427                     --
2428                  else
2429                     --
2430                     l_found   := TRUE;
2431                     --
2432                  end if;
2433               end if;
2434               --
2435            end if;
2436            --
2437           end if; -- Diff in egd
2438           exit;
2439          end if;
2440          --
2441        end loop;
2442        --
2443        if l_found   = FALSE then
2444           --
2445           -- Current epe for a given backed out epe is not found
2446           --
2447           l_differ := 'Y';
2448           exit;
2449        end if;
2450        --
2451      end loop;
2452      --
2453   end if; -- epe ckecks if statement
2454   --
2455 
2456   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
2457   --
2458   return l_differ;
2459   --
2460 end comp_ori_new_pil_outcome;
2461 --
2462 --
2463 -- ----------------------------------------------------------------------------
2464 -- |------------------------< comp_ori_new_pil_for_popl >-------------------------|
2465 -- ----------------------------------------------------------------------------
2466 --
2467 -- This procedure compares the original and new electability
2468 -- data associated with the same ler and returns Y if changes
2469 -- exists else returns N.
2470 --
2471 function comp_ori_new_pil_for_popl(p_person_id       in number
2472                               ,p_business_group_id   in number
2473                               ,p_ler_id              in number
2474                               ,p_effective_date      in date
2475                               ,p_per_in_ler_id       in number
2476                               ,p_bckdt_per_in_ler_id in number
2477                               ,p_pgm_id              in number
2478                               ,p_pl_id               in number
2479                            ) return varchar2 is
2480   --
2481   l_proc                   varchar2(72) := g_package||'.comp_ori_new_pil_outcome';
2482   --
2483   -- Following are the tables whose data will be compared to
2484   -- find any differences exists between the two runs of same ler.
2485   --
2486   -- ben_elig_cvrd_dpnt_f
2487   -- ben_prtt_enrt_actn_f
2488   -- ben_elig_per_elctbl_chc
2489   -- ben_enrt_bnft
2490   -- ben_enrt_rt
2491   -- ben_elctbl_chc_ctfn
2492   --
2493   cursor c_bckdt_epe_cnt is
2494     select count(*)
2495     from   ben_elig_per_elctbl_chc epe,
2496            ben_pil_elctbl_chc_popl pel,
2497            ben_per_in_ler pil
2498     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
2499     and    pil.person_id           = p_person_id
2500     and    pil.per_in_ler_id       = pel.per_in_ler_id
2501     and    (pel.pgm_id = p_pgm_id or
2502             (p_pgm_id is null and pel.pgm_id is null))
2503     and    (pel.pl_id = p_pl_id or
2504             (pel.pl_id is null and p_pl_id is null))
2505     and    pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id;
2506   --
2507   cursor c_curr_epe_cnt is
2508     select count(*)
2509     from   ben_elig_per_elctbl_chc epe,
2510            ben_pil_elctbl_chc_popl pel,
2511            ben_per_in_ler pil
2512     where  pil.per_in_ler_id       = p_per_in_ler_id
2513     and    pil.person_id           = p_person_id
2514     and    pil.per_in_ler_id       = pel.per_in_ler_id
2515     and    (pel.pgm_id = p_pgm_id or
2516             (p_pgm_id is null and pel.pgm_id is null))
2517     and    (pel.pl_id = p_pl_id or
2518             (pel.pl_id is null and p_pl_id is null))
2519     and    pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id;
2520   --
2521   l_bckdt_epe_cnt           number  := 0;
2522   l_curr_epe_cnt            number  := 0;
2523   l_differ                  varchar2(1) := 'N';
2524   l_egd_differ              varchar2(1) := 'N';
2525   l_ecd_differ              varchar2(1) := 'N';
2526   l_enb_differ              varchar2(1) := 'N';
2527   l_epe_ecr_differ          varchar2(1) := 'N';
2528   l_diff_auto_flag          boolean   := true ;
2529   --
2530   cursor c_bckdt_epe_dat is
2531     select epe.*
2532     from   ben_elig_per_elctbl_chc epe,
2533            ben_pil_elctbl_chc_popl pel,
2534            ben_per_in_ler pil
2535     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
2536     and    pil.person_id           = p_person_id
2537     and    pil.per_in_ler_id       = pel.per_in_ler_id
2538     and    (pel.pgm_id = p_pgm_id or
2539             (p_pgm_id is null and pel.pgm_id is null))
2540     and    (pel.pl_id = p_pl_id or
2541             (pel.pl_id is null and p_pl_id is null))
2542     and    pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id ;
2543   --
2544   cursor c_curr_epe_dat is
2545     select epe.*
2546     from   ben_elig_per_elctbl_chc epe,
2547            ben_pil_elctbl_chc_popl pel,
2548            ben_per_in_ler pil
2549     where  pil.per_in_ler_id       = p_per_in_ler_id
2550     and    pil.person_id           = p_person_id
2551     and    pil.per_in_ler_id       = pel.per_in_ler_id
2552     and    (pel.pgm_id = p_pgm_id or
2553             (p_pgm_id is null and pel.pgm_id is null))
2554     and    (pel.pl_id = p_pl_id or
2555             (pel.pl_id is null and p_pl_id is null))
2556     and    pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id ;
2557   --
2558   TYPE l_bckdt_epe_rec is TABLE OF c_bckdt_epe_dat%rowtype
2559        INDEX BY BINARY_INTEGER;
2560   --
2561   TYPE l_curr_epe_rec is TABLE OF c_curr_epe_dat%rowtype
2562        INDEX BY BINARY_INTEGER;
2563   --
2564   l_bckdt_epe_table l_bckdt_epe_rec;
2565   l_curr_epe_table  l_curr_epe_rec;
2566   l_next_row        binary_integer;
2567   l_found           boolean;
2568   --
2569 begin
2570   --
2571   hr_utility.set_location ('Entering '||l_proc,10);
2572   --
2573   open  c_bckdt_epe_cnt;
2574   fetch c_bckdt_epe_cnt into l_bckdt_epe_cnt;
2575   close c_bckdt_epe_cnt;
2576   --
2577   open  c_curr_epe_cnt;
2578   fetch c_curr_epe_cnt into l_curr_epe_cnt;
2579   close c_curr_epe_cnt;
2580   --
2581   if l_bckdt_epe_cnt <> l_curr_epe_cnt then
2582      --
2583      l_differ := 'Y';
2584      --
2585   elsif (l_bckdt_epe_cnt = 0 and  l_curr_epe_cnt = 0) then
2586      --
2587      -- How to handle the case where the elecable choices are 0 9999
2588      --
2589      l_differ := 'N';
2590      --
2591   else
2592      --
2593      -- count of epe is same so look for actual diffs.
2594      --
2595      l_bckdt_epe_table.delete;
2596      l_next_row := nvl(l_bckdt_epe_table.LAST, 0) + 1;
2597      --
2598      for bckdt_epe_rec in c_bckdt_epe_dat
2599      loop
2600         --
2601         l_bckdt_epe_table(l_next_row)   := bckdt_epe_rec;
2602         l_next_row := l_next_row + 1;
2603         --
2604      end loop;
2605      --
2606      l_curr_epe_table.delete;
2607      l_next_row := nvl(l_curr_epe_table.LAST, 0) + 1;
2608      for  curr_epe_rec in c_curr_epe_dat
2609      loop
2610         --
2611         l_curr_epe_table(l_next_row)   := curr_epe_rec;
2612         l_next_row := l_next_row + 1;
2613         --
2614      end loop;
2615      --
2616      -- Now compare the original epe record and new epe record for each comp
2617      -- object.
2618      --
2619      for  l_count in l_bckdt_epe_table.first..l_bckdt_epe_table.last loop
2620        --
2621        l_found  := FALSE;
2622        l_diff_auto_flag := TRUE ;
2623        --
2624        for  l_curr_count in l_curr_epe_table.first..l_curr_epe_table.last loop
2625          --
2626          if  nvl(l_bckdt_epe_table(l_count).pl_id, -1) =
2627                       nvl(l_curr_epe_table(l_curr_count).pl_id, -1) and
2628             nvl(l_bckdt_epe_table(l_count).oipl_id, -1) =
2629                       nvl(l_curr_epe_table(l_curr_count).oipl_id, -1) and
2630             nvl(l_bckdt_epe_table(l_count).PGM_ID, -1) =
2631                       nvl(l_curr_epe_table(l_curr_count).PGM_ID, -1) and
2632             nvl(l_bckdt_epe_table(l_count).PLIP_ID, -1) =
2633                       nvl(l_curr_epe_table(l_curr_count).PLIP_ID, -1) and
2634             nvl(l_bckdt_epe_table(l_count).PTIP_ID, -1) =
2635                       nvl(l_curr_epe_table(l_curr_count).PTIP_ID, -1) and
2636             nvl(l_bckdt_epe_table(l_count).PL_TYP_ID, -1) =
2637                       nvl(l_curr_epe_table(l_curr_count).PL_TYP_ID, -1) and
2638             nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_ID, -1) =
2639                       nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_ID, -1) and
2640             nvl(l_bckdt_epe_table(l_count).CMBN_PTIP_OPT_ID, -1) =
2641                       nvl(l_curr_epe_table(l_curr_count).CMBN_PTIP_OPT_ID, -1) and
2642             nvl(l_bckdt_epe_table(l_count).CMBN_PLIP_ID, -1) =
2643                       nvl(l_curr_epe_table(l_curr_count).CMBN_PLIP_ID, -1) and
2644             nvl(l_bckdt_epe_table(l_count).SPCL_RT_PL_ID, -1) =
2645                       nvl(l_curr_epe_table(l_curr_count).SPCL_RT_PL_ID, -1) and
2646             nvl(l_bckdt_epe_table(l_count).SPCL_RT_OIPL_ID, -1) =
2647                       nvl(l_curr_epe_table(l_curr_count).SPCL_RT_OIPL_ID, -1) and
2648             nvl(l_bckdt_epe_table(l_count).MUST_ENRL_ANTHR_PL_ID, -1) =
2649                nvl(l_curr_epe_table(l_curr_count).MUST_ENRL_ANTHR_PL_ID, -1) and
2650             l_bckdt_epe_table(l_count).DFLT_FLAG =
2651                       l_curr_epe_table(l_curr_count).DFLT_FLAG and
2652             l_bckdt_epe_table(l_count).ELCTBL_FLAG =
2653                       l_curr_epe_table(l_curr_count).ELCTBL_FLAG and
2654             l_bckdt_epe_table(l_count).MNDTRY_FLAG =
2655                       l_curr_epe_table(l_curr_count).MNDTRY_FLAG and
2656             l_bckdt_epe_table(l_count).ALWS_DPNT_DSGN_FLAG =
2657                       l_curr_epe_table(l_curr_count).ALWS_DPNT_DSGN_FLAG and
2658             l_bckdt_epe_table(l_count).AUTO_ENRT_FLAG =
2659                       l_curr_epe_table(l_curr_count).AUTO_ENRT_FLAG and
2660             l_bckdt_epe_table(l_count).CTFN_RQD_FLAG =
2661                       l_curr_epe_table(l_curr_count).CTFN_RQD_FLAG and
2662             nvl(l_bckdt_epe_table(l_count).BNFT_PRVDR_POOL_ID, -1) =
2663                nvl(l_curr_epe_table(l_curr_count).BNFT_PRVDR_POOL_ID, -1) and
2664             nvl(l_bckdt_epe_table(l_count).YR_PERD_ID, -1) =
2665                       nvl(l_curr_epe_table(l_curr_count).YR_PERD_ID, -1) and
2666             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_CD, '$') =
2667                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_CD,  '$') and
2668             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT_RL, -1) =
2669                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT_RL, -1) and
2670             nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_CD, '$') =
2671                nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_CD,  '$') and
2672             nvl(l_bckdt_epe_table(l_count).LER_CHG_DPNT_CVG_CD, '$') =
2673                nvl(l_curr_epe_table(l_curr_count).LER_CHG_DPNT_CVG_CD,  '$') and
2674             nvl(l_bckdt_epe_table(l_count).DPNT_CVG_STRT_DT_RL, -1) =
2675                nvl(l_curr_epe_table(l_curr_count).DPNT_CVG_STRT_DT_RL, -1) and
2676             nvl(l_bckdt_epe_table(l_count).ENRT_CVG_STRT_DT, hr_api.g_eot) =
2677                nvl(l_curr_epe_table(l_curr_count).ENRT_CVG_STRT_DT, hr_api.g_eot) and
2678             nvl(l_bckdt_epe_table(l_count).ERLST_DEENRT_DT, hr_api.g_eot) =
2679                nvl(l_curr_epe_table(l_curr_count).ERLST_DEENRT_DT, hr_api.g_eot)
2680          then
2681           --
2682           -- Now check elig_dpnt rows for any differences.
2683           --
2684           l_egd_differ := comp_ori_new_egd(
2685                            p_person_id              => p_person_id
2686                           ,p_business_group_id      => p_business_group_id
2687                           ,p_effective_date         => p_effective_date
2688                           ,p_per_in_ler_id          => p_per_in_ler_id
2689                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2690                           ,p_curr_epe_id            =>
2691                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2692                           ,p_bckdt_epe_id           =>
2693                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2694                           );
2695           --
2696           if l_egd_differ = 'Y' then
2697            --
2698            l_found   := FALSE;
2699            --
2700           else
2701            --
2702            l_ecd_differ := comp_ori_new_ecd(
2703                            p_person_id              => p_person_id
2704                           ,p_business_group_id      => p_business_group_id
2705                           ,p_effective_date         => p_effective_date
2706                           ,p_per_in_ler_id          => p_per_in_ler_id
2707                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2708                           ,p_curr_epe_id            =>
2709                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2710                           ,p_bckdt_epe_id           =>
2711                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2712                           );
2713            --
2714            if l_ecd_differ = 'Y' then
2715               --
2716               -- even though epe is same ecd differ logically we need to exit.
2717               --
2718               l_found   := FALSE;
2719            else
2720               --
2721               l_enb_differ := comp_ori_new_enb(
2722                            p_person_id              => p_person_id
2723                           ,p_business_group_id      => p_business_group_id
2724                           ,p_effective_date         => p_effective_date
2725                           ,p_per_in_ler_id          => p_per_in_ler_id
2726                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2727                           ,p_curr_epe_id            =>
2728                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2729                           ,p_bckdt_epe_id           =>
2730                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2731                           );
2732               --
2733               if l_enb_differ = 'Y' then
2734                  --
2735                  -- even though epe, ecd are same there may be differences in
2736                  -- enrt_bnft
2737                  --
2738                  l_found   := FALSE;
2739               else
2740                  --
2741                  l_epe_ecr_differ := comp_ori_new_epe_ecr(
2742                            p_person_id              => p_person_id
2743                           ,p_business_group_id      => p_business_group_id
2744                           ,p_effective_date         => p_effective_date
2745                           ,p_per_in_ler_id          => p_per_in_ler_id
2746                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
2747                           ,p_curr_epe_id            =>
2748                             l_curr_epe_table(l_curr_count).ELIG_PER_ELCTBL_CHC_ID
2749                           ,p_bckdt_epe_id           =>
2750                             l_bckdt_epe_table(l_count).ELIG_PER_ELCTBL_CHC_ID
2751                           );
2752                  --
2753                  if l_epe_ecr_differ = 'Y' then
2754                     --
2755                     -- even though epe, ecd, enb are same there may be
2756                     -- differences in enrt_rt
2757                     --
2758                     l_found   := FALSE;
2759                     --
2760                  else
2761                     --
2762                     l_found   := TRUE;
2763                     --
2764                  end if;
2765               end if;
2766               --
2767            end if;
2768            --
2769           end if; -- Diff in egd
2770           exit;
2771          end if;
2772          --
2773        end loop;
2774        --
2775        if l_found   = FALSE then
2776           --
2777           -- Current epe for a given backed out epe is not found
2778           --
2779           l_differ := 'Y';
2780           exit;
2781        end if;
2782        --
2783      end loop;
2784      --
2785   end if; -- epe ckecks if statement
2786   --
2787 
2788   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
2789   --
2790   return l_differ;
2791   --
2792 end comp_ori_new_pil_for_popl;
2793 --
2794 procedure void_literature(p_person_id            in number
2795                           ,p_business_group_id   in number
2796                           ,p_effective_date      in date
2797                           ,p_ler_id              in number
2798                           ,p_per_in_ler_id       in number
2799                          ) is
2800   --
2801   l_proc                    varchar2(72) := g_package||'.void_literature';
2802   --
2803   -- Output variables
2804   --
2805   l_object_version_number number;
2806   l_effective_start_date  date;
2807   l_effective_end_date    date;
2808   --
2809   cursor c_per_cm is
2810       select pcd.*
2811       from   ben_per_cm_f pcm,
2812              ben_per_cm_prvdd_f pcd
2813       where  pcm.person_id           = p_person_id
2814       and    pcm.ler_id              = p_ler_id
2815       and    pcm.business_group_id  = p_business_group_id
2816       and    p_effective_date
2817              between pcm.effective_start_date
2818              and     pcm.effective_end_date
2819       and    pcd.per_cm_id = pcm.per_cm_id
2820       and    pcd.sent_dt is null
2821       and    pcd.business_group_id  = p_business_group_id
2822       and    p_effective_date
2823              between pcd.effective_start_date
2824              and     pcd.effective_end_date;
2825 
2826 begin
2827   --
2828   hr_utility.set_location('Entering:'|| l_proc, 10);
2829   --
2830   for per_cm_rec in c_per_cm loop
2831     --
2832     ben_per_cm_prvdd_api.update_per_cm_prvdd
2833             (p_validate                       => false
2834             ,p_per_cm_prvdd_id                => per_cm_rec.per_cm_prvdd_id
2835             ,p_effective_start_date           => l_effective_start_date
2836             ,p_effective_end_date             => l_effective_end_date
2837             ,p_per_cm_prvdd_stat_cd           => 'VOID'
2838             ,p_object_version_number          => per_cm_rec.object_version_number
2839             ,p_effective_date                 => p_effective_date
2840             ,p_datetrack_mode                 => hr_api.g_correction);
2841     --
2842   end loop;
2843   --
2844   hr_utility.set_location('Leaving:'|| l_proc, 10);
2845   --
2846 end void_literature;
2847 --
2848 procedure pad_cmnt_to_rsnd_lit(
2849                           p_person_id            in number
2850                           ,p_business_group_id   in number
2851                           ,p_effective_date      in date
2852                           ,p_ler_id              in number
2853                           ,p_per_in_ler_id       in number
2854                           ,p_cmnt_txt            in varchar2
2855                          ) is
2856   --
2857   l_proc                    varchar2(72) := g_package||'.pad_cmnt_to_rsnd_lit';
2858   --
2859   -- Output variables
2860   --
2861   l_object_version_number number;
2862   l_effective_start_date  date;
2863   l_effective_end_date    date;
2864   l_resnd_cmnt_txt        fnd_new_messages.message_text%type;
2865   --
2866   cursor c_per_cm is
2867       select pcd.*
2868       from   ben_per_cm_f pcm,
2869              ben_per_cm_prvdd_f pcd
2870       where  pcm.person_id           = p_person_id
2871       and    pcm.ler_id              = p_ler_id
2872       and    pcm.business_group_id  = p_business_group_id
2873       and    p_effective_date
2874              between pcm.effective_start_date
2875              and     pcm.effective_end_date
2876       and    pcd.per_cm_id = pcm.per_cm_id
2877       and    pcd.sent_dt is null
2878       and    pcd.business_group_id  = p_business_group_id
2879       and    p_effective_date
2880              between pcd.effective_start_date
2881              and     pcd.effective_end_date;
2882   --
2883 begin
2884   --
2885   hr_utility.set_location('Entering:'|| l_proc, 10);
2886   --
2887   for per_cm_rec in c_per_cm loop
2888     --
2889     --
2890     ben_per_cm_prvdd_api.update_per_cm_prvdd
2891             (p_validate                       => false
2892             ,p_per_cm_prvdd_id                => per_cm_rec.per_cm_prvdd_id
2893             ,p_effective_start_date           => l_effective_start_date
2894             ,p_effective_end_date             => l_effective_end_date
2895             ,p_sent_dt                        => null
2896             ,p_resnd_rsn_cd                   => 'RPE'  -- event reprocessed
2897             ,p_resnd_cmnt_txt                 => l_resnd_cmnt_txt
2898             ,p_object_version_number          => per_cm_rec.object_version_number
2899             ,p_effective_date                 => p_effective_date
2900             ,p_datetrack_mode                 => hr_api.g_correction);
2901    --
2902   end loop;
2903   --
2904   hr_utility.set_location('Leaving:'|| l_proc, 10);
2905   --
2906 end pad_cmnt_to_rsnd_lit;
2907 --
2908 procedure extend_enrt_date(p_person_id             in number
2909                             ,p_business_group_id   in number
2910                             ,p_ler_id              in number
2911                             ,p_effective_date      in date
2912                             ,p_per_in_ler_id       in number
2913                            ) is
2914   --
2915   l_proc                    varchar2(72) := g_package||'.extend_enrt_date';
2916   --
2917   cursor c_ben_pil_elctbl_chc_popl is
2918     select pel.*
2919     from   ben_pil_elctbl_chc_popl pel,
2920            ben_per_in_ler pil
2921     where  pil.per_in_ler_id = p_per_in_ler_id
2922     and    pil.business_group_id = p_business_group_id
2923     and    pel.per_in_ler_id = pil.per_in_ler_id
2924     and    pel.business_group_id = pil.business_group_id;
2925   --
2926   l_move_out_by number;
2927 begin
2928   --
2929   hr_utility.set_location('Entering:'|| l_proc, 10);
2930   --
2931   -- Only extend the dates if the pel status was STRTD
2932   --
2933   if g_bckdt_pil_prvs_stat_cd = 'STRTD'  then
2934   --
2935    for pel_rec in c_ben_pil_elctbl_chc_popl
2936    loop
2937     --
2938     -- Give person same enrollment period starting from now
2939     -- Or if the enrollment period has not yet started then
2940     -- leave it alone.
2941     --
2942     if pel_rec.enrt_perd_strt_dt<trunc(sysdate) then
2943       --
2944       -- Now need to extend dates by difference between
2945       -- sysdate and old enrt_perd_strt_dt
2946       --
2947       l_move_out_by:=trunc(sysdate)-pel_rec.enrt_perd_strt_dt;
2948       --
2949       -- Update pel now
2950       --
2951 
2952       ben_Pil_Elctbl_chc_Popl_api.update_Pil_Elctbl_chc_Popl (
2953          p_validate               => false
2954         ,p_pil_elctbl_chc_popl_id => pel_rec.pil_elctbl_chc_popl_id
2955         ,p_object_version_number  => pel_rec.object_version_number
2956         ,p_effective_date         => p_effective_date
2957         ,p_enrt_perd_strt_dt      => pel_rec.enrt_perd_strt_dt+l_move_out_by
2958         ,p_enrt_perd_end_dt       => pel_rec.enrt_perd_end_dt+l_move_out_by
2959         ,p_dflt_enrt_dt           => pel_rec.dflt_enrt_dt+l_move_out_by
2960         ,p_procg_end_dt           => pel_rec.procg_end_dt+l_move_out_by
2961       );
2962       --
2963     end if;
2964    end loop;
2965    --
2966   end if;
2967   --
2968   hr_utility.set_location('Leaving:'|| l_proc, 10);
2969   --
2970 end extend_enrt_date;
2971 --
2972 -- ----------------------------------------------------------------------------
2973 -- |------------------------< reinstate_cbr_dates >-------------------------|
2974 -- ----------------------------------------------------------------------------
2975 procedure reinstate_cbr_dates(
2976                             p_person_id            in number
2977                             ,p_business_group_id   in number
2978                             ,p_ler_id              in number
2979                             ,p_effective_date      in date
2980                             ,p_per_in_ler_id       in number
2981                             ,p_bckdt_per_in_ler_id in number
2982                            ) is
2983   --
2984   l_proc                    varchar2(72) := g_package||'.reinstate_cbr_dates';
2985   --
2986   l_exists                  varchar2(1);
2987   l_object_version_number   ben_cbr_quald_bnf.object_version_number%type;
2988   --
2989   --  Get cobra secondary qualifying event
2990   --
2991   cursor c_get_cbr_per_in_ler is
2992     select crp.*
2993     from   ben_cbr_per_in_ler crp
2994     where  crp.per_in_ler_id = p_bckdt_per_in_ler_id
2995     and    crp.init_evt_flag = 'N'
2996     and    crp.business_group_id = p_business_group_id;
2997   --
2998   cursor c_bckdt_cqb is
2999     select cqb.*
3000     from   ben_le_clsn_n_rstr cqb
3001     where  cqb.per_in_ler_id       = p_bckdt_per_in_ler_id
3002     and    cqb.business_group_id = p_business_group_id
3003     and    cqb.bkup_tbl_typ_cd     = 'BEN_CBR_QUALD_BNF';
3004   --
3005   cursor c_cqb(p_cbr_quald_bnf_id in number) is
3006     select cqb.*
3007     from   ben_cbr_quald_bnf cqb
3008     where  cqb.cbr_quald_bnf_id  = p_cbr_quald_bnf_id
3009     and    cqb.business_group_id = p_business_group_id;
3010   --
3011   l_bckdt_cqb_rec             c_bckdt_cqb%rowtype;
3012   l_cqb_rec                   c_cqb%rowtype;
3013   l_crp_rec                   c_get_cbr_per_in_ler%rowtype;
3014 begin
3015   --
3016   hr_utility.set_location('Entering:'|| l_proc, 10);
3017   --
3018   --  If backout event was a secondary COBRA qualifying event,
3019   --  re-instate the COBRA eligibility end date.
3020   --
3021   open c_get_cbr_per_in_ler;
3022   fetch c_get_cbr_per_in_ler into l_crp_rec;
3023   if c_get_cbr_per_in_ler%found then
3024     close c_get_cbr_per_in_ler;
3025     --
3026     --  Get backed up data.
3027     --
3028     for l_bckdt_cqb_rec in c_bckdt_cqb loop
3029       --
3030       --  Get object version number.
3031       --
3032       open c_cqb(l_bckdt_cqb_rec.bkup_tbl_id);
3033       fetch c_cqb into l_cqb_rec;
3034       if c_cqb%found then
3035         close c_cqb;
3036         --
3037         l_object_version_number := l_cqb_rec.object_version_number;
3038         --
3039         ben_cbr_quald_bnf_api.update_cbr_quald_bnf
3040           (p_validate              => false
3041           ,p_cbr_quald_bnf_id      => l_cqb_rec.cbr_quald_bnf_id
3042           ,p_cbr_elig_perd_end_dt  => l_bckdt_cqb_rec.elig_thru_dt
3043           ,p_business_group_id     => p_business_group_id
3044           ,p_object_version_number => l_object_version_number
3045           ,p_effective_date        => p_effective_date
3046           );
3047       else
3048         close c_cqb;
3049       end if;
3050     end loop;
3051   else
3052     close c_get_cbr_per_in_ler;
3053   end if;
3054   --
3055   -- Delete all the backup rows from the backup table after the
3056   -- restoration of rows.
3057   --
3058   delete from ben_le_clsn_n_rstr cqb
3059   where  cqb.per_in_ler_id       = p_bckdt_per_in_ler_id
3060     and  cqb.business_group_id = p_business_group_id
3061     and  cqb.bkup_tbl_typ_cd     = 'BEN_CBR_QUALD_BNF';
3062   --
3063   hr_utility.set_location('Leaving:'|| l_proc, 10);
3064 
3065 end reinstate_cbr_dates;
3066 --
3067 -- ----------------------------------------------------------------------------
3068 -- |------------------------< comp_ori_new_prv >-------------------------|
3069 -- ----------------------------------------------------------------------------
3070 --
3071 -- This procedure compares the original and new rates for Enrollment results
3072 -- data associated with the same ler and returns Y if changes
3073 -- exists else returns N.
3074 --
3075 function comp_ori_new_prv(p_person_id       in number
3076                               ,p_business_group_id   in number
3077                               ,p_effective_date      in date
3078                               ,p_per_in_ler_id       in number
3079                               ,p_bckdt_per_in_ler_id in number
3080                               ,p_curr_pen_id         in number
3081                               ,p_bckdt_pen_id        in number
3082                               ,p_dont_check_cnt_flag in varchar2 default 'N'
3083                            ) return varchar2 is
3084   --
3085   l_proc                   varchar2(72) := g_package||'.comp_ori_new_prv';
3086   --
3087   l_differ                  varchar2(1) := 'N';
3088   --
3089   cursor c_bckdt_prv is
3090     select prv.*
3091     from   ben_prtt_rt_val prv
3092     where prv.prtt_enrt_rslt_id  = p_bckdt_pen_id
3093     and   prv.business_group_id  = p_business_group_id;
3094   --
3095   cursor c_curr_prv is
3096     select prv.*
3097     from   ben_prtt_rt_val prv
3098     where prv.prtt_enrt_rslt_id  = p_curr_pen_id
3099     and   prv.business_group_id  = p_business_group_id;
3100   --
3101   TYPE l_bckdt_prv_rec is TABLE OF c_bckdt_prv%rowtype
3102        INDEX BY BINARY_INTEGER;
3103   --
3104   TYPE l_curr_prv_rec is TABLE OF c_curr_prv%rowtype
3105        INDEX BY BINARY_INTEGER;
3106   --
3107   l_bckdt_prv_table     l_bckdt_prv_rec;
3108   l_curr_prv_table      l_curr_prv_rec;
3109   l_next_row            binary_integer;
3110   l_found               boolean;
3111   l_bckdt_prv_count     number;
3112   --
3113 begin
3114   --
3115   hr_utility.set_location ('Entering '||l_proc,10);
3116   --
3117   select count(*) into l_bckdt_prv_count
3118     from   ben_prtt_rt_val prv
3119     where prv.prtt_enrt_rslt_id = p_bckdt_pen_id
3120     and   prv.business_group_id  = p_business_group_id;
3121   --
3122   l_curr_prv_table.delete;
3123   l_next_row := nvl(l_curr_prv_table.LAST, 0) + 1;
3124   for  curr_prv_rec in c_curr_prv
3125   loop
3126      --
3127      l_curr_prv_table(l_next_row)   := curr_prv_rec;
3128      l_next_row := l_next_row + 1;
3129      --
3130   end loop;
3131   --
3132   -- Check Number of records in both tables for difference
3133   --
3134   if nvl(l_curr_prv_table.last, 0) = 0  and
3135      nvl(l_bckdt_prv_count,0)  = 0
3136   then
3137        --
3138        l_differ := 'N';
3139 
3140        hr_utility.set_location('Leaving:  ' || l_differ ||' 0 '|| l_proc, 10);
3141        return l_differ;
3142        --
3143   elsif nvl(l_curr_prv_table.last, 0) <> nvl(l_bckdt_prv_count,0) then
3144        --
3145        l_differ := 'Y';
3146 
3147        hr_utility.set_location('Leaving:  ' || l_differ ||'<> 0 '|| l_proc, 10);
3148        return l_differ;
3149        --
3150   end if;
3151   --
3152   -- Now compare the original prv record and new prv record for each
3153   -- pen record.
3154   --
3155   for bckdt_prv_rec in c_bckdt_prv
3156   loop
3157     --
3158     l_found  := FALSE;
3159     --
3160     for  l_curr_count in l_curr_prv_table.first..l_curr_prv_table.last
3161     loop
3162       --
3163       if nvl(bckdt_prv_rec.RT_TYP_CD, '$') =
3164                    nvl(l_curr_prv_table(l_curr_count).RT_TYP_CD, '$') and
3165          nvl(bckdt_prv_rec.RT_STRT_DT, hr_api.g_eot) =
3166             nvl(l_curr_prv_table(l_curr_count).RT_STRT_DT, hr_api.g_eot) and
3167          (nvl(bckdt_prv_rec.RT_END_DT, hr_api.g_eot) =
3168             nvl(l_curr_prv_table(l_curr_count).RT_END_DT, hr_api.g_eot) or
3169             p_dont_check_cnt_flag = 'Y'
3170          ) and
3171          nvl(bckdt_prv_rec.TX_TYP_CD, '$') =
3172                    nvl(l_curr_prv_table(l_curr_count).TX_TYP_CD, '$') and
3173          nvl(bckdt_prv_rec.ACTY_TYP_CD, '$') =
3174                    nvl(l_curr_prv_table(l_curr_count).ACTY_TYP_CD, '$') and
3175          nvl(bckdt_prv_rec.MLT_CD, '$') =
3176                    nvl(l_curr_prv_table(l_curr_count).MLT_CD, '$') and
3177          nvl(bckdt_prv_rec.ACTY_REF_PERD_CD, '$') =
3178                    nvl(l_curr_prv_table(l_curr_count).ACTY_REF_PERD_CD, '$') and
3179          (nvl(bckdt_prv_rec.RT_VAL, -1) =
3180                    nvl(l_curr_prv_table(l_curr_count).RT_VAL, -1) or
3181             p_dont_check_cnt_flag = 'Y'  -- 999 also check entr_val_at_enrt_flag = 'Y'
3182          ) and
3183          (nvl(bckdt_prv_rec.ANN_RT_VAL, -1) =
3184                    nvl(l_curr_prv_table(l_curr_count).ANN_RT_VAL, -1) or
3185             p_dont_check_cnt_flag = 'Y'  -- 999 also check entr_val_at_enrt_flag
3186          ) and
3187          (nvl(bckdt_prv_rec.CMCD_RT_VAL, -1) =
3188                    nvl(l_curr_prv_table(l_curr_count).CMCD_RT_VAL, -1) or
3189             p_dont_check_cnt_flag = 'Y'  -- 999 also check entr_val_at_enrt_flag
3190          ) and
3191          nvl(bckdt_prv_rec.CMCD_REF_PERD_CD, '$') =
3192                    nvl(l_curr_prv_table(l_curr_count).CMCD_REF_PERD_CD, '$') and
3193          nvl(bckdt_prv_rec.BNFT_RT_TYP_CD, '$') =
3194                    nvl(l_curr_prv_table(l_curr_count).BNFT_RT_TYP_CD, '$') and
3195          nvl(bckdt_prv_rec.DSPLY_ON_ENRT_FLAG, '$') =
3196                    nvl(l_curr_prv_table(l_curr_count).DSPLY_ON_ENRT_FLAG, '$') and
3197          nvl(bckdt_prv_rec.RT_OVRIDN_FLAG, '$') =
3198                    nvl(l_curr_prv_table(l_curr_count).RT_OVRIDN_FLAG, '$') and
3199          nvl(bckdt_prv_rec.RT_OVRIDN_THRU_DT, hr_api.g_eot) =
3200             nvl(l_curr_prv_table(l_curr_count).RT_OVRIDN_THRU_DT, hr_api.g_eot) and
3201          nvl(bckdt_prv_rec.ELCTNS_MADE_DT, hr_api.g_eot) =
3202             nvl(l_curr_prv_table(l_curr_count).ELCTNS_MADE_DT, hr_api.g_eot) and
3203          nvl(bckdt_prv_rec.CVG_AMT_CALC_MTHD_ID, -1) =
3204                    nvl(l_curr_prv_table(l_curr_count).CVG_AMT_CALC_MTHD_ID, -1) and
3205          nvl(bckdt_prv_rec.ACTL_PREM_ID, -1) =
3206                    nvl(l_curr_prv_table(l_curr_count).ACTL_PREM_ID, -1) and
3207          nvl(bckdt_prv_rec.COMP_LVL_FCTR_ID, -1) =
3208                    nvl(l_curr_prv_table(l_curr_count).COMP_LVL_FCTR_ID, -1) and
3209          nvl(bckdt_prv_rec.ACTY_BASE_RT_ID, -1) =
3210                    nvl(l_curr_prv_table(l_curr_count).ACTY_BASE_RT_ID, -1)
3211       then
3212         l_found   := TRUE;
3213         exit;
3214       end if;
3215       --
3216     end loop;
3217     --
3218     if l_found   = FALSE then
3219        --
3220        -- Current prv for a given backed out prv is not found
3221        --
3222        l_differ := 'Y';
3223        exit;
3224     end if;
3225   --
3226   end loop;
3227   --
3228 
3229   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
3230   --
3231   return l_differ;
3232   --
3233 end comp_ori_new_prv;
3234 --
3235 -- ----------------------------------------------------------------------------
3236 -- |------------------------< comp_ori_new_pen >-------------------------|
3237 -- ----------------------------------------------------------------------------
3238 --
3239 -- This procedure compares the original and new Enrollment results
3240 -- data associated with the same ler and returns Y if changes
3241 -- exists else returns N.
3242 --
3243 function comp_ori_new_pen(p_person_id       in number
3244                               ,p_business_group_id   in number
3245                               ,p_ler_id              in number
3246                               ,p_effective_date      in date
3247                               ,p_per_in_ler_id       in number
3248                               ,p_bckdt_per_in_ler_id in number
3249                               ,p_dont_check_cnt_flag in varchar2 default 'N'
3250                            ) return varchar2 is
3251   --
3252   l_proc                   varchar2(72) := g_package||'.comp_ori_new_pen';
3253   --
3254   -- Following are the tables whose data will be compared to
3255   -- find any differences exists between the two runs of same ler.
3256   --
3257   -- ben_prtt_enrt_rslt_f
3258   -- ben_prtt_rt_val
3259   --
3260   l_bckdt_pen_cnt           number  := 0;
3261   l_bckdt_pen_cnt_temp      number  := 0;
3262   l_curr_pen_cnt            number  := 0;
3263   l_differ                  varchar2(1) := 'N';
3264   l_prv_differ              varchar2(1) := 'N';
3265   --
3266   cursor c_bckdt_pen_dat is
3267    select pen.ASSIGNMENT_ID,
3268           pen.BNFT_AMT,
3269           pen.BNFT_NNMNTRY_UOM,
3270           pen.BNFT_ORDR_NUM,
3271           pen.BNFT_TYP_CD,
3272           pen.BUSINESS_GROUP_ID,
3273           pen.COMP_LVL_CD,
3274           pen.CREATED_BY,
3275           pen.CREATION_DATE,
3276           pen.EFFECTIVE_END_DATE,
3277           pen.EFFECTIVE_START_DATE,
3278           pen.ENRT_CVG_STRT_DT,
3279           pen.ENRT_CVG_THRU_DT,
3280           pen.ENRT_MTHD_CD,
3281           pen.ENRT_OVRIDN_FLAG,
3282           pen.ENRT_OVRID_RSN_CD,
3283           pen.ENRT_OVRID_THRU_DT,
3284           pen.ERLST_DEENRT_DT,
3285           pen.LAST_UPDATED_BY,
3286           pen.LAST_UPDATE_DATE,
3287           pen.LAST_UPDATE_LOGIN,
3288           pen.LER_ID,
3289           pen.NO_LNGR_ELIG_FLAG,
3290           pen.OBJECT_VERSION_NUMBER,
3291           pen.OIPL_ID,
3292           pen.OIPL_ORDR_NUM,
3293           pen.ORGNL_ENRT_DT,
3294           pen.PEN_ATTRIBUTE1,
3295           pen.PEN_ATTRIBUTE10,
3296           pen.PEN_ATTRIBUTE11,
3297           pen.PEN_ATTRIBUTE12,
3298           pen.PEN_ATTRIBUTE13,
3299           pen.PEN_ATTRIBUTE14,
3300           pen.PEN_ATTRIBUTE15,
3301           pen.PEN_ATTRIBUTE16,
3302           pen.PEN_ATTRIBUTE17,
3303           pen.PEN_ATTRIBUTE18,
3304           pen.PEN_ATTRIBUTE19,
3305           pen.PEN_ATTRIBUTE2,
3306           pen.PEN_ATTRIBUTE20,
3307           pen.PEN_ATTRIBUTE21,
3308           pen.PEN_ATTRIBUTE22,
3309           pen.PEN_ATTRIBUTE23,
3310           pen.PEN_ATTRIBUTE24,
3311           pen.PEN_ATTRIBUTE25,
3312           pen.PEN_ATTRIBUTE26,
3313           pen.PEN_ATTRIBUTE27,
3314           pen.PEN_ATTRIBUTE28,
3315           pen.PEN_ATTRIBUTE29,
3316           pen.PEN_ATTRIBUTE3,
3317           pen.PEN_ATTRIBUTE30,
3318           pen.PEN_ATTRIBUTE4,
3319           pen.PEN_ATTRIBUTE5,
3320           pen.PEN_ATTRIBUTE6,
3321           pen.PEN_ATTRIBUTE7,
3322           pen.PEN_ATTRIBUTE8,
3323           pen.PEN_ATTRIBUTE9,
3324           pen.PEN_ATTRIBUTE_CATEGORY,
3325           pen.PERSON_ID,
3326           pen.PER_IN_LER_ID,
3327           pen.PGM_ID,
3328           pen.PLIP_ORDR_NUM,
3329           pen.PL_ID,
3330           pen.PL_ORDR_NUM,
3331           pen.PL_TYP_ID,
3332           pen.PROGRAM_APPLICATION_ID,
3333           pen.PROGRAM_ID,
3334           pen.PROGRAM_UPDATE_DATE,
3335           pen.PRTT_ENRT_RSLT_ID,
3336           pen.PRTT_ENRT_RSLT_STAT_CD,
3337           pen.PRTT_IS_CVRD_FLAG,
3338           pen.PTIP_ID,
3339           pen.PTIP_ORDR_NUM,
3340           pen.REQUEST_ID,
3341           pen.RPLCS_SSPNDD_RSLT_ID,
3342           pen.SSPNDD_FLAG,
3343           pen.UOM
3344     from   ben_prtt_enrt_rslt_f pen,
3345            ben_per_in_ler pil
3346     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3347     and    pil.person_id           = p_person_id
3348     and    pil.business_group_id = p_business_group_id
3349     AND    pil.per_in_ler_id       = pen.per_in_ler_id
3350     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
3351    union
3352    select
3353           pen.ASSIGNMENT_ID,
3354           pen.BNFT_AMT,
3355           pen.BNFT_NNMNTRY_UOM,
3356           pen.BNFT_ORDR_NUM,
3357           pen.BNFT_TYP_CD,
3358           pen.BUSINESS_GROUP_ID,
3359           pen.COMP_LVL_CD,
3360           pen.CREATED_BY,
3361           pen.CREATION_DATE,
3362           pen.EFFECTIVE_END_DATE,
3363           pen.EFFECTIVE_START_DATE,
3364           pen.ENRT_CVG_STRT_DT,
3365           pen.ENRT_CVG_THRU_DT,
3366           pen.ENRT_MTHD_CD,
3367           pen.ENRT_OVRIDN_FLAG,
3368           pen.ENRT_OVRID_RSN_CD,
3369           pen.ENRT_OVRID_THRU_DT,
3370           pen.ERLST_DEENRT_DT,
3371           pen.LAST_UPDATED_BY,
3372           pen.LAST_UPDATE_DATE,
3373           pen.LAST_UPDATE_LOGIN,
3374           pen.LER_ID,
3375           pen.NO_LNGR_ELIG_FLAG,
3376           pen.OBJECT_VERSION_NUMBER,
3377           pen.OIPL_ID,
3378           pen.OIPL_ORDR_NUM,
3379           pen.ORGNL_ENRT_DT,
3380           pen.LCR_ATTRIBUTE1,
3381           pen.LCR_ATTRIBUTE10,
3382           pen.LCR_ATTRIBUTE11,
3383           pen.LCR_ATTRIBUTE12,
3384           pen.LCR_ATTRIBUTE13,
3385           pen.LCR_ATTRIBUTE14,
3386           pen.LCR_ATTRIBUTE15,
3387           pen.LCR_ATTRIBUTE16,
3388           pen.LCR_ATTRIBUTE17,
3389           pen.LCR_ATTRIBUTE18,
3390           pen.LCR_ATTRIBUTE19,
3391           pen.LCR_ATTRIBUTE2,
3392           pen.LCR_ATTRIBUTE20,
3393           pen.LCR_ATTRIBUTE21,
3394           pen.LCR_ATTRIBUTE22,
3395           pen.LCR_ATTRIBUTE23,
3396           pen.LCR_ATTRIBUTE24,
3397           pen.LCR_ATTRIBUTE25,
3398           pen.LCR_ATTRIBUTE26,
3399           pen.LCR_ATTRIBUTE27,
3400           pen.LCR_ATTRIBUTE28,
3401           pen.LCR_ATTRIBUTE29,
3402           pen.LCR_ATTRIBUTE3,
3403           pen.LCR_ATTRIBUTE30,
3404           pen.LCR_ATTRIBUTE4,
3405           pen.LCR_ATTRIBUTE5,
3406           pen.LCR_ATTRIBUTE6,
3407           pen.LCR_ATTRIBUTE7,
3408           pen.LCR_ATTRIBUTE8,
3409           pen.LCR_ATTRIBUTE9,
3410           pen.LCR_ATTRIBUTE_CATEGORY,
3411           pen.PERSON_ID,
3412           pen.PER_IN_LER_ID,
3413           pen.PGM_ID,
3414           pen.PLIP_ORDR_NUM,
3415           pen.PL_ID,
3416           pen.PL_ORDR_NUM,
3417           pen.PL_TYP_ID,
3418           pen.PROGRAM_APPLICATION_ID,
3419           pen.PROGRAM_ID,
3420           pen.PROGRAM_UPDATE_DATE,
3421           pen.bkup_tbl_id, -- Mapped to PRTT_ENRT_RSLT_ID,
3422           pen.PRTT_ENRT_RSLT_STAT_CD,
3423           pen.PRTT_IS_CVRD_FLAG,
3424           pen.PTIP_ID,
3425           pen.PTIP_ORDR_NUM,
3426           pen.REQUEST_ID,
3427           pen.RPLCS_SSPNDD_RSLT_ID,
3428           pen.SSPNDD_FLAG,
3429           pen.UOM
3430     from  ben_le_clsn_n_rstr  pen,
3431            ben_per_in_ler pil
3432     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3433     and    pil.person_id           = p_person_id
3434     and    pil.business_group_id   = p_business_group_id
3435     AND    pil.per_in_ler_id       = pen.per_in_ler_id
3436     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
3437     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP');
3438   --   and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
3439   --
3440   cursor c_curr_pen_dat is
3441     select pen.*
3442     from   ben_prtt_enrt_rslt_f pen,
3443            ben_per_in_ler pil
3444     where  pil.per_in_ler_id       = p_per_in_ler_id
3445     and    pil.person_id           = p_person_id
3446     and    pil.business_group_id = p_business_group_id
3447     AND    pil.per_in_ler_id       = pen.per_in_ler_id
3448     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP');
3449   --
3450   TYPE l_bckdt_pen_rec is TABLE OF c_bckdt_pen_dat%rowtype
3451        INDEX BY BINARY_INTEGER;
3452   --
3453   TYPE l_curr_pen_rec is TABLE OF c_curr_pen_dat%rowtype
3454        INDEX BY BINARY_INTEGER;
3455   --
3456   l_bckdt_pen_table l_bckdt_pen_rec;
3457   l_curr_pen_table  l_curr_pen_rec;
3458   l_next_row        binary_integer;
3459   l_found           boolean;
3460   --
3461 begin
3462   --
3463   hr_utility.set_location ('Entering '||l_proc,10);
3464   hr_utility.set_location ('Entering bck pil id '||p_bckdt_per_in_ler_id,10);
3465   hr_utility.set_location ('Entering pil id '||p_per_in_ler_id,10);
3466   --
3467   -- Bug 1266433 : Do not consider the results of flex credits and
3468   -- imputed income as they are not considered in c_curr_pen_dat
3469   --
3470   select count(*) into l_bckdt_pen_cnt_temp
3471     from   ben_prtt_enrt_rslt_f pen,
3472            ben_per_in_ler pil
3473     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3474     and    pil.person_id           = p_person_id
3475     and    pil.business_group_id   = p_business_group_id
3476     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
3477     AND    pil.per_in_ler_id       = pen.per_in_ler_id;
3478   --
3479   select count(*) into l_bckdt_pen_cnt
3480     from  ben_le_clsn_n_rstr  pen,
3481            ben_per_in_ler pil
3482     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3483     and    pil.person_id           = p_person_id
3484     and    pil.business_group_id   = p_business_group_id
3485     AND    pil.per_in_ler_id       = pen.per_in_ler_id
3486     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
3487     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F';
3488   --
3489   l_bckdt_pen_cnt  := l_bckdt_pen_cnt_temp + l_bckdt_pen_cnt;
3490   l_curr_pen_table.delete;
3491   l_next_row := nvl(l_curr_pen_table.LAST, 0) + 1;
3492   for  curr_pen_rec in c_curr_pen_dat
3493   loop
3494      --
3495      l_curr_pen_table(l_next_row)   := curr_pen_rec;
3496      l_next_row := l_next_row + 1;
3497      --
3498   end loop;
3499   --
3500   -- Check Number of records in both tables differ
3501   --
3502   if nvl(l_curr_pen_table.last, 0) = 0  and
3503      nvl(l_bckdt_pen_cnt,0)  = 0
3504   then
3505        --
3506        l_differ := 'N';
3507 
3508        hr_utility.set_location('Leaving:  ' || l_differ
3509                                             ||' 0 '|| l_proc, 10);
3510        return l_differ;
3511        --
3512   elsif nvl(l_curr_pen_table.last, 0) = 0 and
3513        p_dont_check_cnt_flag  =  'Y' then
3514        --
3515        l_differ := 'N';
3516 
3517        hr_utility.set_location('Leaving:  ' || l_differ
3518                                             ||' 0 '|| l_proc, 10);
3519        return l_differ;
3520        --
3521   elsif nvl(l_curr_pen_table.last, 0) <> nvl(l_bckdt_pen_cnt,0) and
3522        p_dont_check_cnt_flag  =  'N' then
3523        --
3524        l_differ := 'Y';
3525 
3526        hr_utility.set_location('Leaving:  ' || l_differ ||' <>0 '||
3527                       nvl(l_curr_pen_table.last, 0) || ' bck= '
3528                    || nvl(l_bckdt_pen_cnt,0) || l_proc, 10);
3529        return l_differ;
3530        --
3531   end if;
3532   --
3533   -- Now compare the original pen record and new pen record.
3534   --
3535   l_found  := FALSE;
3536   --
3537   hr_utility.set_location(to_char(nvl(l_curr_pen_table.last, 0)) ,4987);
3538   if nvl(l_curr_pen_table.last, 0) > 0 then
3539     --
3540     hr_utility.set_location(' Before first Loop ',4987);
3541    for  l_curr_count in l_curr_pen_table.first..l_curr_pen_table.last loop
3542     --
3543     l_found  := FALSE;
3544     --
3545     hr_utility.set_location(' Before Loop ',4987);
3546     for bckdt_pen_rec in c_bckdt_pen_dat
3547     loop
3548       --
3549 
3550         hr_utility.set_location(' Before if ',4987);
3551         /*
3552         hr_utility.set_location(  'SSPNDD_FLAG '     ||
3553                  nvl(bckdt_pen_rec.SSPNDD_FLAG, '$r') ||'--'||
3554                  nvl(l_curr_pen_table(l_curr_count).SSPNDD_FLAG, '$'),4987);
3555         hr_utility.set_location( 'ENRT_CVG_STRT_DT '
3556                  ||  nvl(bckdt_pen_rec.ENRT_CVG_STRT_DT, hr_api.g_eot)  ||'--'||
3557                 nvl(l_curr_pen_table(l_curr_count).ENRT_CVG_STRT_DT, hr_api.g_eot),4987);
3558         hr_utility.set_location( 'ENRT_CVG_THRU_DT '
3559                  ||  nvl(bckdt_pen_rec.ENRT_CVG_THRU_DT, hr_api.g_eot)||'--'||
3560                nvl(l_curr_pen_table(l_curr_count).ENRT_CVG_THRU_DT, hr_api.g_eot),4987);
3561         hr_utility.set_location( 'PRTT_IS_CVRD_FLA '
3562                  ||  nvl(bckdt_pen_rec.PRTT_IS_CVRD_FLAG, '$') ||'--'||
3563               nvl(l_curr_pen_table(l_curr_count).PRTT_IS_CVRD_FLAG, '$'),4987);
3564         hr_utility.set_location( 'PRTT_IS_CVRD_FLAG'
3565                  ||  nvl(bckdt_pen_rec.BNFT_AMT, -1)||'--'||
3566               nvl(l_curr_pen_table(l_curr_count).BNFT_AMT, -1),4987);
3567         hr_utility.set_location( 'BNFT_NNMNTRY_UOM '
3568                  ||  nvl(bckdt_pen_rec.BNFT_NNMNTRY_UOM, '$') ||'--'||
3569               nvl(l_curr_pen_table(l_curr_count).BNFT_NNMNTRY_UOM, '$'),4987);
3570         hr_utility.set_location( 'BNFT_TYP_CD '
3571                  ||  nvl(bckdt_pen_rec.BNFT_TYP_CD, '$') ||'--'||
3572               nvl(l_curr_pen_table(l_curr_count).BNFT_TYP_CD, '$'),4987);
3573         hr_utility.set_location( 'UOM ' ||  nvl(bckdt_pen_rec.UOM, '$') ||'--'||
3574               nvl(l_curr_pen_table(l_curr_count).UOM, '$'),4987);
3575         hr_utility.set_location( 'ORGNL_ENRT_DT '
3576                  ||  nvl(bckdt_pen_rec.ORGNL_ENRT_DT, hr_api.g_eot)  ||'--'||
3577               nvl(l_curr_pen_table(l_curr_count).ORGNL_ENRT_DT, hr_api.g_eot),4987);
3578         hr_utility.set_location( 'ENRT_MTHD_CD '
3579                  ||  nvl(bckdt_pen_rec.ENRT_MTHD_CD, '$') ||'--'||
3580               nvl(l_curr_pen_table(l_curr_count).ENRT_MTHD_CD, '$'),4987);
3581         hr_utility.set_location( 'ENRT_OVRIDN_FLAG '||
3582                  nvl(bckdt_pen_rec.ENRT_OVRIDN_FLAG, '$') ||'--'||
3583               nvl(l_curr_pen_table(l_curr_count).ENRT_OVRIDN_FLAG, '$'),4987);
3584         hr_utility.set_location( 'ENRT_OVRID_RSN_CD '
3585                  ||  nvl(bckdt_pen_rec.ENRT_OVRID_RSN_CD, '$')||'--'||
3586               nvl(l_curr_pen_table(l_curr_count).ENRT_OVRID_RSN_CD, '$'),4987);
3587         hr_utility.set_location( 'ERLST_DEENRT_DT '
3588                  ||  nvl(bckdt_pen_rec.ERLST_DEENRT_DT, hr_api.g_eot)||'--'||
3589               nvl(l_curr_pen_table(l_curr_count).ERLST_DEENRT_DT, hr_api.g_eot),4987);
3590 
3591        hr_utility.set_location( 'ENRT_OVRID_THRU_DT'
3592                  ||  nvl(bckdt_pen_rec.ENRT_OVRID_THRU_DT, hr_api.g_eot) ||'--'||
3593               nvl(l_curr_pen_table(l_curr_count).ENRT_OVRID_THRU_DT, hr_api.g_eot),4987);
3594         hr_utility.set_location( 'NO_LNGR_ELIG_FLAG'
3595                  ||  nvl(bckdt_pen_rec.NO_LNGR_ELIG_FLAG, '$')||'--'||
3596               nvl(l_curr_pen_table(l_curr_count).NO_LNGR_ELIG_FLAG, '$'),4987);
3597         hr_utility.set_location( 'PRTT_ENRT_RSLT_STAT_CD'
3598                  || nvl(bckdt_pen_rec.PRTT_ENRT_RSLT_STAT_CD, '$')||'--'||
3599               nvl(l_curr_pen_table(l_curr_count).PRTT_ENRT_RSLT_STAT_CD, '$')
3600                  ||'--'||  p_dont_check_cnt_flag ,4987);
3601         hr_utility.set_location( 'COMP_LVL_CD' || nvl(bckdt_pen_rec.COMP_LVL_CD, '$')||'--'||
3602               nvl(l_curr_pen_table(l_curr_count). COMP_LVL_CD, '$'),4987);
3603         hr_utility.set_location( 'PGM_ID '  || nvl(bckdt_pen_rec.PGM_ID, -1)||'--'||
3604               nvl(l_curr_pen_table(l_curr_count).PGM_ID,-1),4987);
3605         hr_utility.set_location( 'PL_ID '   || nvl(bckdt_pen_rec.PL_ID, -1)||'--'||
3606              nvl(l_curr_pen_table(l_curr_count).PL_ID, -1), 4987);
3607         hr_utility.set_location( 'PL_TYP_ID '||nvl(bckdt_pen_rec.PL_TYP_ID, -1)||'--'||
3608              nvl(l_curr_pen_table(l_curr_count).PL_TYP_ID, -1),4987);
3609 
3610          hr_utility.set_location( 'OIPL_ID'          ||  nvl(bckdt_pen_rec.OIPL_ID, -1) ||'--'||
3611              nvl(l_curr_pen_table(l_curr_count).OIPL_ID, -1),4987);
3612         hr_utility.set_location( 'PTIP_ID ' ||  nvl(bckdt_pen_rec.PTIP_ID, -1) ||'--'||
3613              nvl(l_curr_pen_table(l_curr_count).PTIP_ID, -1),4987);
3614         hr_utility.set_location( 'LER_ID '  ||  nvl(bckdt_pen_rec.LER_ID, -1) ||'--'||
3615              nvl(l_curr_pen_table(l_curr_count).LER_ID, -1),4987);
3616         hr_utility.set_location( 'RPLCS_SSPNDD_RSLT_ID '
3617                  || nvl(bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID, -1)||'--'||
3618             nvl(l_curr_pen_table(l_curr_count).RPLCS_SSPNDD_RSLT_ID, -1),4987);
3619 
3620         */
3621       if nvl(bckdt_pen_rec.SSPNDD_FLAG, '$') =
3622                    nvl(l_curr_pen_table(l_curr_count).SSPNDD_FLAG, '$') and
3623          nvl(bckdt_pen_rec.ENRT_CVG_STRT_DT, hr_api.g_eot) =
3624             nvl(l_curr_pen_table(l_curr_count).ENRT_CVG_STRT_DT, hr_api.g_eot) and
3625          nvl(bckdt_pen_rec.ENRT_CVG_THRU_DT, hr_api.g_eot) =
3626             nvl(l_curr_pen_table(l_curr_count).ENRT_CVG_THRU_DT, hr_api.g_eot) and
3627          nvl(bckdt_pen_rec.PRTT_IS_CVRD_FLAG, '$') =
3628                    nvl(l_curr_pen_table(l_curr_count).PRTT_IS_CVRD_FLAG, '$') and
3629          nvl(bckdt_pen_rec.BNFT_AMT, -1) =
3630                    nvl(l_curr_pen_table(l_curr_count).BNFT_AMT, -1) and
3631          nvl(bckdt_pen_rec.BNFT_NNMNTRY_UOM, '$') =
3632                    nvl(l_curr_pen_table(l_curr_count).BNFT_NNMNTRY_UOM, '$') and
3633          nvl(bckdt_pen_rec.BNFT_TYP_CD, '$') =
3634                    nvl(l_curr_pen_table(l_curr_count).BNFT_TYP_CD, '$') and
3635          nvl(bckdt_pen_rec.UOM, '$') =
3636                    nvl(l_curr_pen_table(l_curr_count).UOM, '$') and
3637          nvl(bckdt_pen_rec.ORGNL_ENRT_DT, hr_api.g_eot) =
3638             nvl(l_curr_pen_table(l_curr_count).ORGNL_ENRT_DT, hr_api.g_eot) and
3639          nvl(bckdt_pen_rec.ENRT_MTHD_CD, '$') =
3640                    nvl(l_curr_pen_table(l_curr_count).ENRT_MTHD_CD, '$') and
3641          nvl(bckdt_pen_rec.ENRT_OVRIDN_FLAG, '$') =
3642                    nvl(l_curr_pen_table(l_curr_count).ENRT_OVRIDN_FLAG, '$') and
3643          nvl(bckdt_pen_rec.ENRT_OVRID_RSN_CD, '$') =
3644                    nvl(l_curr_pen_table(l_curr_count).ENRT_OVRID_RSN_CD, '$') and
3645          nvl(bckdt_pen_rec.ERLST_DEENRT_DT, hr_api.g_eot) =
3646             nvl(l_curr_pen_table(l_curr_count).ERLST_DEENRT_DT, hr_api.g_eot) and
3647          nvl(bckdt_pen_rec.ENRT_OVRID_THRU_DT, hr_api.g_eot) =
3648             nvl(l_curr_pen_table(l_curr_count).ENRT_OVRID_THRU_DT, hr_api.g_eot) and
3649          nvl(bckdt_pen_rec.NO_LNGR_ELIG_FLAG, '$') =
3650                    nvl(l_curr_pen_table(l_curr_count).NO_LNGR_ELIG_FLAG, '$') and
3651          /*
3652            Bug 1266433 : Do not compare the status codes.
3653          ( nvl(bckdt_pen_rec.PRTT_ENRT_RSLT_STAT_CD, '$') =
3654                    nvl(l_curr_pen_table(l_curr_count).PRTT_ENRT_RSLT_STAT_CD, '$') or
3655            p_dont_check_cnt_flag  =  'Y'
3656          ) and
3657          */
3658          nvl(bckdt_pen_rec.COMP_LVL_CD, '$') =
3659                    nvl(l_curr_pen_table(l_curr_count).COMP_LVL_CD, '$') and
3660          nvl(bckdt_pen_rec.PGM_ID, -1) =
3661                    nvl(l_curr_pen_table(l_curr_count).PGM_ID, -1) and
3662          nvl(bckdt_pen_rec.PL_ID, -1) =
3663                    nvl(l_curr_pen_table(l_curr_count).PL_ID, -1) and
3664          nvl(bckdt_pen_rec.PL_TYP_ID, -1) =
3665             nvl(l_curr_pen_table(l_curr_count).PL_TYP_ID, -1) and
3666          nvl(bckdt_pen_rec.OIPL_ID, -1) =
3667             nvl(l_curr_pen_table(l_curr_count).OIPL_ID, -1) and
3668          nvl(bckdt_pen_rec.PTIP_ID, -1) =
3669                    nvl(l_curr_pen_table(l_curr_count).PTIP_ID, -1) and
3670          /*
3671            Bug 1266433 : Do not compare the ler id .
3672          nvl(bckdt_pen_rec.LER_ID, -1) =
3673                    nvl(l_curr_pen_table(l_curr_count).LER_ID, -1)  and
3674          */
3675          nvl(bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID, -1) =
3676                    nvl(l_curr_pen_table(l_curr_count).RPLCS_SSPNDD_RSLT_ID, -1)
3677       then
3678         --
3679         l_prv_differ := comp_ori_new_prv(
3680            p_person_id              => p_person_id
3681            ,p_business_group_id     => p_business_group_id
3682            ,p_effective_date        => p_effective_date
3683            ,p_per_in_ler_id         => p_per_in_ler_id
3684            ,p_bckdt_per_in_ler_id   => p_bckdt_per_in_ler_id
3685            ,p_curr_pen_id           => l_curr_pen_table(l_curr_count).prtt_enrt_rslt_id
3686            ,p_bckdt_pen_id          => bckdt_pen_rec.prtt_enrt_rslt_id
3687            ,p_dont_check_cnt_flag   => p_dont_check_cnt_flag
3688            );
3689         --
3690         if l_prv_differ = 'Y' then
3691            --
3692            -- even though pen are same there may be differences
3693            -- in prtt_rt_val
3694            --
3695            l_found   := FALSE;
3696            --
3697         else
3698            --
3699            l_found   := TRUE;
3700            --
3701         end if;
3702         exit;
3703       end if;
3704       --
3705     end loop;
3706     --
3707     if l_found   = FALSE then
3708        --
3709        -- Current pen for a given backed out pen is not found
3710        --
3711        l_differ := 'Y';
3712        exit;
3713     end if;
3714     --
3715    end loop;
3716    --
3717   else
3718    --
3719    if l_found   = FALSE then
3720        --
3721        -- Current pen for a given backed out pen is not found
3722        --
3723        l_differ := 'Y';
3724        --
3725    end if;
3726    --
3727   end if;
3728   --
3729 
3730   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
3731   --
3732   return l_differ;
3733   --
3734 end comp_ori_new_pen;
3735 --
3736 -- ----------------------------------------------------------------------------
3737 -- |------------------------< get_inter_pil_cnt >-------------------------|
3738 -- ----------------------------------------------------------------------------
3739 --
3740 -- If more than one pil exists between two runs of a pil then
3741 -- no restoration to be done.
3742 --
3743 /*
3744 procedure  get_inter_pil_cnt (
3745                         p_bckdt_per_in_ler_id      in number,
3746                         p_per_in_ler_id            in number,
3747                         p_person_id                in number,
3748                         p_inter_per_in_ler_id      out nocopy number,
3749                         p_inter_pil_ovn            out nocopy number,
3750                         p_inter_pil_cnt            out nocopy number,
3751                         p_business_group_id        in number,
3752                         p_effective_date           in date) is
3753   --
3754   l_proc                     varchar2(72) := g_package||'.get_inter_pil_cnt';
3755   --
3756   -- Bug 4987 ( WWW Bug 1266433)
3757   -- When counting the intervening life events only count the pil's
3758   -- whose lf_evt_ocrd_dt is more than the back out date of the
3759   -- backed out per in ler.
3760   --
3761   cursor c_bckt_csd_pil is
3762          select csd_pil.lf_evt_ocrd_dt
3763          from ben_per_in_ler csd_pil,
3764               ben_per_in_ler bckt_pil
3765          where bckt_pil.per_in_ler_id = p_bckdt_per_in_ler_id
3766            and bckt_pil.BCKT_PER_IN_LER_ID = csd_pil.per_in_ler_id
3767            and bckt_pil.business_group_id = p_business_group_id
3768            and csd_pil.business_group_id = p_business_group_id;
3769   --
3770   l_bckt_csd_lf_evt_ocrd_dt date;
3771   --
3772   -- Bug 5415 : Intermediate pil count should be between
3773   -- the life event occured date of pil which causes back out
3774   -- and the current reprocessing backed out pil.
3775   -- iREC : do not consider iRec, ABS, COMP, GSP pils.
3776   --
3777   cursor c_inter_pil_cnt(cv_bckt_csd_lf_evt_ocrd_dt date) is
3778     select pil.per_in_ler_id, pil.object_version_number
3779     from   ben_per_in_ler pil,
3780            ben_ler_f ler
3781     where  pil.per_in_ler_id <> p_per_in_ler_id
3782     and    pil.per_in_ler_id <> p_bckdt_per_in_ler_id
3783     and    pil.person_id         = p_person_id
3784     and    pil.ler_id            = ler.ler_id
3785     and    p_effective_date between
3786            ler.effective_start_date and ler.effective_end_date
3787     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
3788     and    pil.business_group_id = p_business_group_id
3789     and    nvl(pil.per_in_ler_stat_cd, 'XXXX') not in('BCKDT', 'VOIDD')
3790     and    pil.lf_evt_ocrd_dt > cv_bckt_csd_lf_evt_ocrd_dt
3791     and    pil.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt
3792                                  from ben_per_in_ler
3793                                  where per_in_ler_id = p_bckdt_per_in_ler_id
3794                                    and business_group_id = p_business_group_id
3795                                 );
3796   --
3797   l_count number     := 0;
3798   --
3799 begin
3800   --
3801   hr_utility.set_location ('Entering '||l_proc,10);
3802   --
3803   p_inter_pil_cnt := 0;
3804   open c_bckt_csd_pil;
3805   fetch c_bckt_csd_pil into l_bckt_csd_lf_evt_ocrd_dt;
3806   close c_bckt_csd_pil;
3807   --
3808   g_bckt_csd_lf_evt_ocrd_dt := l_bckt_csd_lf_evt_ocrd_dt;
3809   --
3810   open  c_inter_pil_cnt(l_bckt_csd_lf_evt_ocrd_dt);
3811   fetch c_inter_pil_cnt into  p_inter_per_in_ler_id, p_inter_pil_ovn;
3812   if c_inter_pil_cnt%found then
3813      --
3814      -- Find are there more intervening PIL's.
3815      --
3816      p_inter_pil_cnt := 1;
3817      fetch c_inter_pil_cnt into  p_inter_per_in_ler_id, p_inter_pil_ovn;
3818      if c_inter_pil_cnt%found then
3819         p_inter_pil_cnt := p_inter_pil_cnt + 1;
3820      end if;
3821      --
3822   end if;
3823   --
3824   close c_inter_pil_cnt;
3825   --
3826   hr_utility.set_location ('Leaving '||l_proc,10);
3827   --
3828 end get_inter_pil_cnt;
3829 */
3830 --
3831 procedure reinstate_bpl_per_pen(
3832                            p_person_id              in number
3833                           ,p_business_group_id      in number
3834                           ,p_effective_date         in date
3835                           ,p_per_in_ler_id          in number
3836                           ,p_bckdt_per_in_ler_id    in number
3837                           ) is
3838   --
3839   l_proc                    varchar2(72) := g_package||'.reinstate_bpl_per_pen';
3840   --
3841   cursor c_bckdt_pen is
3842    select  pen.EFFECTIVE_END_DATE,
3843            pen.OIPL_ID,
3844            pen.prtt_enrt_rslt_id,
3845            pen.OBJECT_VERSION_NUMBER,
3846            pen.PGM_ID,
3847            pen.PL_ID,
3848            pen.PL_TYP_ID,
3849            pen.PTIP_ID
3850     from   ben_prtt_enrt_rslt_f pen,
3851            ben_per_in_ler pil
3852     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3853     and    pil.person_id           = p_person_id
3854     and    pil.business_group_id = p_business_group_id
3855     and    pil.per_in_ler_id       = pen.per_in_ler_id
3856     and    pen.comp_lvl_cd         = 'PLANFC'
3857    union
3858    select  pen.EFFECTIVE_END_DATE,
3859            pen.OIPL_ID,
3860            pen.bkup_tbl_id, -- Mapped to PRTT_ENRT_RSLT_ID,
3861            pen.OBJECT_VERSION_NUMBER,
3862            pen.PGM_ID,
3863            pen.PL_ID,
3864            pen.PL_TYP_ID,
3865            pen.PTIP_ID
3866     from  ben_le_clsn_n_rstr  pen,
3867            ben_per_in_ler pil
3868     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
3869     and    pil.person_id           = p_person_id
3870     and    pil.business_group_id   = p_business_group_id
3871     AND    pil.per_in_ler_id       = pen.per_in_ler_id
3872     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
3873     and    pen.comp_lvl_cd         = 'PLANFC'
3874     order by 1; -- pen.effective_end_date; -- Low to High
3875   --
3876   cursor c_curr_pen(cp_pl_id in number, cp_oipl_id in number,
3877                     cp_pgm_id in number) is
3878    select  pen.EFFECTIVE_END_DATE,
3879            pen.OIPL_ID,
3880            pen.prtt_enrt_rslt_id,
3881            pen.OBJECT_VERSION_NUMBER,
3882            pen.PGM_ID,
3883            pen.PL_ID,
3884            pen.PL_TYP_ID,
3885            pen.PTIP_ID,
3886            pen.effective_start_date
3887     from   ben_prtt_enrt_rslt_f pen,
3888            ben_per_in_ler pil
3889     where  pil.per_in_ler_id       = p_per_in_ler_id
3890     and    pil.person_id           = p_person_id
3891     and    pil.business_group_id   = p_business_group_id
3892     and    pil.per_in_ler_id       = pen.per_in_ler_id
3893     and    nvl(pen.pl_id, -1)      = nvl(cp_pl_id, -1)
3894     and    nvl(pen.oipl_id, -1)    = nvl(cp_oipl_id, -1)
3895     and    nvl(pen.pgm_id, -1)     = nvl(cp_pgm_id, -1)
3896     and    pen.comp_lvl_cd         = 'PLANFC';
3897   --
3898   cursor c_bckdt_bpl(cp_bckdt_prtt_enrt_rslt_id in number)
3899    is
3900     select
3901            bckdt_bpl.EFFECTIVE_END_DATE
3902            ,bckdt_bpl.BNFT_PRVDD_LDGR_ID
3903            ,bckdt_bpl.EFFECTIVE_START_DATE
3904            ,bckdt_bpl.PRTT_RO_OF_UNUSD_AMT_FLAG
3905            ,bckdt_bpl.FRFTD_VAL
3906            ,bckdt_bpl.PRVDD_VAL
3907            ,bckdt_bpl.USED_VAL
3908            ,bckdt_bpl.CASH_RECD_VAL
3909            ,bckdt_bpl.BNFT_PRVDR_POOL_ID
3910            ,bckdt_bpl.ACTY_BASE_RT_ID
3911            ,bckdt_bpl.PRTT_ENRT_RSLT_ID
3912            ,bckdt_bpl.BUSINESS_GROUP_ID
3913            ,bckdt_bpl.BPL_ATTRIBUTE_CATEGORY
3914            ,bckdt_bpl.BPL_ATTRIBUTE1
3915            ,bckdt_bpl.BPL_ATTRIBUTE2
3916            ,bckdt_bpl.BPL_ATTRIBUTE3
3917            ,bckdt_bpl.BPL_ATTRIBUTE4
3918            ,bckdt_bpl.BPL_ATTRIBUTE5
3919            ,bckdt_bpl.BPL_ATTRIBUTE6
3920            ,bckdt_bpl.BPL_ATTRIBUTE7
3921            ,bckdt_bpl.BPL_ATTRIBUTE8
3922            ,bckdt_bpl.BPL_ATTRIBUTE9
3923            ,bckdt_bpl.BPL_ATTRIBUTE10
3924            ,bckdt_bpl.BPL_ATTRIBUTE11
3925            ,bckdt_bpl.BPL_ATTRIBUTE12
3926            ,bckdt_bpl.BPL_ATTRIBUTE13
3927            ,bckdt_bpl.BPL_ATTRIBUTE14
3928            ,bckdt_bpl.BPL_ATTRIBUTE15
3929            ,bckdt_bpl.BPL_ATTRIBUTE16
3930            ,bckdt_bpl.BPL_ATTRIBUTE17
3931            ,bckdt_bpl.BPL_ATTRIBUTE18
3932            ,bckdt_bpl.BPL_ATTRIBUTE19
3933            ,bckdt_bpl.BPL_ATTRIBUTE20
3934            ,bckdt_bpl.BPL_ATTRIBUTE21
3935            ,bckdt_bpl.BPL_ATTRIBUTE22
3936            ,bckdt_bpl.BPL_ATTRIBUTE23
3937            ,bckdt_bpl.BPL_ATTRIBUTE24
3938            ,bckdt_bpl.BPL_ATTRIBUTE25
3939            ,bckdt_bpl.BPL_ATTRIBUTE26
3940            ,bckdt_bpl.BPL_ATTRIBUTE27
3941            ,bckdt_bpl.BPL_ATTRIBUTE28
3942            ,bckdt_bpl.BPL_ATTRIBUTE29
3943            ,bckdt_bpl.BPL_ATTRIBUTE30
3944            ,bckdt_bpl.LAST_UPDATE_DATE
3945            ,bckdt_bpl.LAST_UPDATED_BY
3946            ,bckdt_bpl.LAST_UPDATE_LOGIN
3947            ,bckdt_bpl.CREATED_BY
3948            ,bckdt_bpl.CREATION_DATE
3949            ,bckdt_bpl.OBJECT_VERSION_NUMBER
3950            ,bckdt_bpl.RLD_UP_VAL
3951            ,bckdt_bpl.PER_IN_LER_ID
3952     from   ben_bnft_prvdd_ldgr_f bckdt_bpl
3953     where bckdt_bpl.per_in_ler_id = p_bckdt_per_in_ler_id
3954       and bckdt_bpl.business_group_id  = p_business_group_id
3955       and bckdt_bpl.prtt_enrt_rslt_id = cp_bckdt_prtt_enrt_rslt_id
3956     union
3957     select
3958            bckdt_bpl.EFFECTIVE_END_DATE
3959            ,bckdt_bpl.BKUP_TBL_ID
3960            ,bckdt_bpl.EFFECTIVE_START_DATE
3961            ,bckdt_bpl.NO_LNGR_ELIG_FLAG -- Used for PRTT_RO_OF_UNUSD_AMT_FLAG
3962            ,bckdt_bpl.AMT_DSGD_VAL -- Used for FRFTD_VAL
3963            ,bckdt_bpl.ANN_RT_VAL   -- Used for PRVDD_VAL
3964            ,bckdt_bpl.CMCD_RT_VAL  -- Used for USED_VAL
3965            ,bckdt_bpl.RT_VAL       -- Used for CASH_RECD_VAL
3966            ,bckdt_bpl.COMP_LVL_FCTR_ID -- Used as BNFT_PRVDR_POOL_ID
3967            ,bckdt_bpl.ACTY_BASE_RT_ID
3968            ,bckdt_bpl.PRTT_ENRT_RSLT_ID
3969            ,bckdt_bpl.BUSINESS_GROUP_ID
3970            ,bckdt_bpl.LCR_ATTRIBUTE_CATEGORY
3971            ,bckdt_bpl.LCR_ATTRIBUTE1
3972            ,bckdt_bpl.LCR_ATTRIBUTE2
3973            ,bckdt_bpl.LCR_ATTRIBUTE3
3974            ,bckdt_bpl.LCR_ATTRIBUTE4
3975            ,bckdt_bpl.LCR_ATTRIBUTE5
3976            ,bckdt_bpl.LCR_ATTRIBUTE6
3977            ,bckdt_bpl.LCR_ATTRIBUTE7
3978            ,bckdt_bpl.LCR_ATTRIBUTE8
3979            ,bckdt_bpl.LCR_ATTRIBUTE9
3980            ,bckdt_bpl.LCR_ATTRIBUTE10
3981            ,bckdt_bpl.LCR_ATTRIBUTE11
3982            ,bckdt_bpl.LCR_ATTRIBUTE12
3983            ,bckdt_bpl.LCR_ATTRIBUTE13
3984            ,bckdt_bpl.LCR_ATTRIBUTE14
3985            ,bckdt_bpl.LCR_ATTRIBUTE15
3986            ,bckdt_bpl.LCR_ATTRIBUTE1
3987            ,bckdt_bpl.LCR_ATTRIBUTE17
3988            ,bckdt_bpl.LCR_ATTRIBUTE18
3989            ,bckdt_bpl.LCR_ATTRIBUTE19
3990            ,bckdt_bpl.LCR_ATTRIBUTE20
3991            ,bckdt_bpl.LCR_ATTRIBUTE21
3992            ,bckdt_bpl.LCR_ATTRIBUTE22
3993            ,bckdt_bpl.LCR_ATTRIBUTE23
3994            ,bckdt_bpl.LCR_ATTRIBUTE24
3995            ,bckdt_bpl.LCR_ATTRIBUTE25
3996            ,bckdt_bpl.LCR_ATTRIBUTE26
3997            ,bckdt_bpl.LCR_ATTRIBUTE27
3998            ,bckdt_bpl.LCR_ATTRIBUTE28
3999            ,bckdt_bpl.LCR_ATTRIBUTE29
4000            ,bckdt_bpl.LCR_ATTRIBUTE30
4001            ,bckdt_bpl.LAST_UPDATE_DATE
4002            ,bckdt_bpl.LAST_UPDATED_BY
4003            ,bckdt_bpl.LAST_UPDATE_LOGIN
4004            ,bckdt_bpl.CREATED_BY
4005            ,bckdt_bpl.CREATION_DATE
4006            ,bckdt_bpl.OBJECT_VERSION_NUMBER
4007            ,bckdt_bpl.VAL -- Used for RLD_UP_VAL
4008            ,bckdt_bpl.PER_IN_LER_ID
4009     from  ben_le_clsn_n_rstr bckdt_bpl
4010     where bckdt_bpl.per_in_ler_id = p_bckdt_per_in_ler_id
4011       and bckdt_bpl.business_group_id  = p_business_group_id
4012       and bckdt_bpl.prtt_enrt_rslt_id = cp_bckdt_prtt_enrt_rslt_id
4013       and bckdt_bpl.BKUP_TBL_TYP_CD   = 'BEN_BNFT_PRVDD_LDGR_F'
4014     order by 1;
4015   --
4016   cursor c_curr_bpl(cp_acty_base_rt_id    in number,
4017                     cp_bnft_prvdr_pool_id in number,
4018                     cp_prtt_enrt_rslt_id in number,
4019                     cp_effective_date in date) is
4020     select bpl.*
4021     from   ben_bnft_prvdd_ldgr_f  bpl
4022     where bpl.per_in_ler_id     = p_per_in_ler_id
4023       and bpl.prtt_enrt_rslt_id = cp_prtt_enrt_rslt_id
4024       --
4025       and cp_effective_date between bpl.effective_start_date
4026                               and bpl.effective_end_date
4027       and bpl.business_group_id  = p_business_group_id
4028       and bpl.acty_base_rt_id    = cp_acty_base_rt_id
4029       and nvl(bpl.bnft_prvdr_pool_id, -1)  = nvl(cp_bnft_prvdr_pool_id, -1);
4030 
4031   --
4032   l_curr_bpl_rec             c_curr_bpl%rowtype;
4033   l_datetrack_mode           varchar2(80);
4034   l_bpl_effective_start_date date;
4035   l_bpl_effective_end_date   date;
4036   l_bpl_object_version_number number;
4037   l_bnft_prvdd_ldgr_id       number;
4038   --
4039 begin
4040  --
4041  hr_utility.set_location ('Entering '||l_proc,10);
4042  --
4043   for l_bckdt_pen_rec in c_bckdt_pen loop
4044    --
4045    for l_curr_pen_rec in c_curr_pen(l_bckdt_pen_rec.pl_id ,
4046                                     l_bckdt_pen_rec.oipl_id ,
4047                                     l_bckdt_pen_rec.pgm_id )
4048    loop
4049      --
4050      for bckdt_bpl_rec in c_bckdt_bpl(l_bckdt_pen_rec.prtt_enrt_rslt_id) loop
4051       --
4052       open c_curr_bpl(bckdt_bpl_rec.acty_base_rt_id,
4053                       bckdt_bpl_rec.bnft_prvdr_pool_id,
4054                       l_curr_pen_rec.prtt_enrt_rslt_id,
4055                       l_curr_pen_rec.effective_start_date);
4056       fetch c_curr_bpl into l_curr_bpl_rec;
4057       if c_curr_bpl%found then
4058          --
4059          -- If the corresponding record is found then is it different.
4060          -- If so then go and update it with the old values.
4061          --
4062          if bckdt_bpl_rec.PRTT_RO_OF_UNUSD_AMT_FLAG   <> l_curr_bpl_rec.PRTT_RO_OF_UNUSD_AMT_FLAG or
4063             bckdt_bpl_rec.FRFTD_VAL     <> l_curr_bpl_rec.FRFTD_VAL or
4064             bckdt_bpl_rec.PRVDD_VAL     <> l_curr_bpl_rec.PRVDD_VAL or
4065             bckdt_bpl_rec.USED_VAL      <> l_curr_bpl_rec.USED_VAL  or
4066             bckdt_bpl_rec.CASH_RECD_VAL <> l_curr_bpl_rec.CASH_RECD_VAL
4067          then
4068            --
4069            l_curr_bpl_rec.PRTT_RO_OF_UNUSD_AMT_FLAG := bckdt_bpl_rec.PRTT_RO_OF_UNUSD_AMT_FLAG;
4070            l_curr_bpl_rec.FRFTD_VAL := bckdt_bpl_rec.FRFTD_VAL;
4071            l_curr_bpl_rec.PRVDD_VAL := bckdt_bpl_rec.PRVDD_VAL;
4072            l_curr_bpl_rec.USED_VAL  := bckdt_bpl_rec.USED_VAL;
4073            l_curr_bpl_rec.CASH_RECD_VAL := bckdt_bpl_rec.CASH_RECD_VAL;
4074            --
4075            if l_curr_pen_rec.effective_start_date = l_curr_bpl_rec.effective_start_date  or
4076               l_curr_pen_rec.effective_start_date = l_curr_bpl_rec.effective_end_date
4077            then
4078               l_datetrack_mode := hr_api.g_correction;
4079            else
4080               l_datetrack_mode := hr_api.g_update;
4081            end if;
4082            --
4083            ben_Benefit_Prvdd_Ledger_api.update_Benefit_Prvdd_Ledger (
4084              p_bnft_prvdd_ldgr_id           => l_curr_bpl_rec.bnft_prvdd_ldgr_id
4085             ,p_effective_start_date         => l_bpl_effective_start_date
4086             ,p_effective_end_date           => l_bpl_effective_end_date
4087             ,p_object_version_number        => l_curr_bpl_rec.object_version_number
4088             ,p_prtt_ro_of_unusd_amt_flag    => l_curr_bpl_rec.prtt_ro_of_unusd_amt_flag
4089             ,p_frftd_val                    => l_curr_bpl_rec.frftd_val
4090             ,p_prvdd_val                    => l_curr_bpl_rec.prvdd_val
4091             ,p_used_val                     => l_curr_bpl_rec.used_val
4092             ,p_bnft_prvdr_pool_id           => l_curr_bpl_rec.bnft_prvdr_pool_id
4093             ,p_acty_base_rt_id              => l_curr_bpl_rec.acty_base_rt_id
4094             ,p_per_in_ler_id                => p_per_in_ler_id
4095             ,p_prtt_enrt_rslt_id            => l_curr_bpl_rec.prtt_enrt_rslt_id
4096             ,p_business_group_id            => p_business_group_id
4097             ,p_cash_recd_val                => l_curr_bpl_rec.cash_recd_val
4098             ,p_effective_date               => l_curr_pen_rec.effective_start_date
4099             ,p_datetrack_mode               => l_datetrack_mode
4100             ,p_process_enrt_flag             => 'Y'
4101             ,p_from_reinstate_enrt_flag     => 'Y'
4102            );
4103            --
4104          end if;
4105          --
4106       end if;
4107       close c_curr_bpl;
4108       --
4109      end loop;
4110    end loop;
4111  end loop;
4112  --
4113  hr_utility.set_location('Leaving:'|| l_proc, 10);
4114  --
4115 end reinstate_bpl_per_pen;
4116 --
4117 procedure reinstate_ppr_per_pen(
4118                              p_person_id                in number
4119                             ,p_bckdt_prtt_enrt_rslt_id  in number
4120                             ,p_prtt_enrt_rslt_id        in number
4121                             ,p_business_group_id        in number
4122                             ,p_elig_cvrd_dpnt_id        in number
4123                             ,p_effective_date           in date
4124                             ,p_bckdt_elig_cvrd_dpnt_id  in number
4125                            ) is
4126   --
4127   l_proc                    varchar2(72) := g_package || '.reinstate_ppr_per_pen';
4128   --
4129   cursor c_old_ppr_pen is
4130   select
4131        ppr.EFFECTIVE_END_DATE
4132        ,ppr.PRMRY_CARE_PRVDR_ID
4133        ,ppr.EFFECTIVE_START_DATE
4134        ,ppr.PRMRY_CARE_PRVDR_TYP_CD
4135        ,ppr.NAME
4136        ,ppr.EXT_IDENT
4137        ,ppr.PRTT_ENRT_RSLT_ID
4138        ,ppr.ELIG_CVRD_DPNT_ID
4139        ,ppr.BUSINESS_GROUP_ID
4140        ,ppr.PPR_ATTRIBUTE_CATEGORY
4141        ,ppr.PPR_ATTRIBUTE1
4142        ,ppr.PPR_ATTRIBUTE2
4143        ,ppr.PPR_ATTRIBUTE3
4144        ,ppr.PPR_ATTRIBUTE4
4145        ,ppr.PPR_ATTRIBUTE5
4146        ,ppr.PPR_ATTRIBUTE6
4147        ,ppr.PPR_ATTRIBUTE7
4148        ,ppr.PPR_ATTRIBUTE8
4149        ,ppr.PPR_ATTRIBUTE9
4150        ,ppr.PPR_ATTRIBUTE10
4151        ,ppr.PPR_ATTRIBUTE11
4152        ,ppr.PPR_ATTRIBUTE12
4153        ,ppr.PPR_ATTRIBUTE13
4154        ,ppr.PPR_ATTRIBUTE14
4155        ,ppr.PPR_ATTRIBUTE15
4156        ,ppr.PPR_ATTRIBUTE16
4157        ,ppr.PPR_ATTRIBUTE17
4158        ,ppr.PPR_ATTRIBUTE18
4159        ,ppr.PPR_ATTRIBUTE19
4160        ,ppr.PPR_ATTRIBUTE20
4161        ,ppr.PPR_ATTRIBUTE21
4162        ,ppr.PPR_ATTRIBUTE22
4163        ,ppr.PPR_ATTRIBUTE23
4164        ,ppr.PPR_ATTRIBUTE24
4165        ,ppr.PPR_ATTRIBUTE25
4166        ,ppr.PPR_ATTRIBUTE26
4167        ,ppr.PPR_ATTRIBUTE27
4168        ,ppr.PPR_ATTRIBUTE28
4169        ,ppr.PPR_ATTRIBUTE29
4170        ,ppr.PPR_ATTRIBUTE30
4171        ,ppr.LAST_UPDATE_DATE
4172        ,ppr.LAST_UPDATED_BY
4173        ,ppr.LAST_UPDATE_LOGIN
4174        ,ppr.CREATED_BY
4175        ,ppr.CREATION_DATE
4176        ,ppr.REQUEST_ID
4177        ,ppr.PROGRAM_APPLICATION_ID
4178        ,ppr.PROGRAM_ID
4179        ,ppr.PROGRAM_UPDATE_DATE
4180        ,ppr.OBJECT_VERSION_NUMBER
4181     from ben_prmry_care_prvdr_f ppr
4182     where ppr.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id -- Bug 3709516
4183       and ppr.business_group_id = p_business_group_id
4184       and p_effective_date between ppr.effective_start_date and ppr.effective_end_date; --Added p_effective_date condition for Bug 7497016
4185 --
4186   cursor c_old_ppr_pdp is
4187   select
4188        ppr.EFFECTIVE_END_DATE
4189        ,ppr.PRMRY_CARE_PRVDR_ID
4190        ,ppr.EFFECTIVE_START_DATE
4191        ,ppr.PRMRY_CARE_PRVDR_TYP_CD
4192        ,ppr.NAME
4193        ,ppr.EXT_IDENT
4194        ,ppr.PRTT_ENRT_RSLT_ID
4195        ,ppr.ELIG_CVRD_DPNT_ID
4196        ,ppr.BUSINESS_GROUP_ID
4197        ,ppr.PPR_ATTRIBUTE_CATEGORY
4198        ,ppr.PPR_ATTRIBUTE1
4199        ,ppr.PPR_ATTRIBUTE2
4200        ,ppr.PPR_ATTRIBUTE3
4201        ,ppr.PPR_ATTRIBUTE4
4202        ,ppr.PPR_ATTRIBUTE5
4203        ,ppr.PPR_ATTRIBUTE6
4204        ,ppr.PPR_ATTRIBUTE7
4205        ,ppr.PPR_ATTRIBUTE8
4206        ,ppr.PPR_ATTRIBUTE9
4207        ,ppr.PPR_ATTRIBUTE10
4208        ,ppr.PPR_ATTRIBUTE11
4209        ,ppr.PPR_ATTRIBUTE12
4210        ,ppr.PPR_ATTRIBUTE13
4211        ,ppr.PPR_ATTRIBUTE14
4212        ,ppr.PPR_ATTRIBUTE15
4213        ,ppr.PPR_ATTRIBUTE16
4214        ,ppr.PPR_ATTRIBUTE17
4215        ,ppr.PPR_ATTRIBUTE18
4216        ,ppr.PPR_ATTRIBUTE19
4217        ,ppr.PPR_ATTRIBUTE20
4218        ,ppr.PPR_ATTRIBUTE21
4219        ,ppr.PPR_ATTRIBUTE22
4220        ,ppr.PPR_ATTRIBUTE23
4221        ,ppr.PPR_ATTRIBUTE24
4222        ,ppr.PPR_ATTRIBUTE25
4223        ,ppr.PPR_ATTRIBUTE26
4224        ,ppr.PPR_ATTRIBUTE27
4225        ,ppr.PPR_ATTRIBUTE28
4226        ,ppr.PPR_ATTRIBUTE29
4227        ,ppr.PPR_ATTRIBUTE30
4228        ,ppr.LAST_UPDATE_DATE
4229        ,ppr.LAST_UPDATED_BY
4230        ,ppr.LAST_UPDATE_LOGIN
4231        ,ppr.CREATED_BY
4232        ,ppr.CREATION_DATE
4233        ,ppr.REQUEST_ID
4234        ,ppr.PROGRAM_APPLICATION_ID
4235        ,ppr.PROGRAM_ID
4236        ,ppr.PROGRAM_UPDATE_DATE
4237        ,ppr.OBJECT_VERSION_NUMBER
4238     from ben_prmry_care_prvdr_f ppr
4239     where ppr.elig_cvrd_dpnt_id = p_bckdt_elig_cvrd_dpnt_id -- Bug 3709516
4240       and ppr.business_group_id   = p_business_group_id
4241       and p_effective_date between ppr.effective_start_date and ppr.effective_end_date; -- Bug 11667555
4242 
4243 -- 5123666
4244 CURSOR c_curr_ppr(c_prmry_care_prvdr_id in number)
4245    IS
4246       SELECT *
4247         FROM ben_prmry_care_prvdr_f ppr
4248        WHERE ppr.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4249          AND ppr.business_group_id = p_business_group_id
4250          AND ppr.prmry_care_prvdr_id = c_prmry_care_prvdr_id
4251          AND NVL (ppr.elig_cvrd_dpnt_id, -1) = NVL (p_elig_cvrd_dpnt_id, -1)
4252 	 and p_effective_date between ppr.effective_start_date and ppr.effective_end_date; --Added p_effective_date condition for Bug 7497016
4253 
4254  --
4255   l_PRMRY_CARE_PRVDR_ID         number(15);
4256   l_ppr_effective_start_date    date;
4257   l_ppr_effective_end_date      date;
4258   l_ppr_object_version_number   number(9);
4259   -- 5123666
4260   l_curr_ppr                 c_curr_ppr%rowtype;
4261   l_datetrack_mode           varchar2(80);
4262   --
4263 begin
4264   --
4265   hr_utility.set_location('Entering ' || l_proc,10);
4266   hr_utility.set_location('p_bckdt_prtt_enrt_rslt_id ' || p_bckdt_prtt_enrt_rslt_id,10);
4267   hr_utility.set_location('p_prtt_enrt_rslt_id ' || p_prtt_enrt_rslt_id,10);
4268   hr_utility.set_location('p_effective_date ' || p_effective_date,10);
4269   hr_utility.set_location('p_bckdt_elig_cvrd_dpnt_id ' || p_bckdt_elig_cvrd_dpnt_id,10);
4270   --
4271   -- for participant
4272   --
4273   IF  p_bckdt_prtt_enrt_rslt_id is not null
4274   and p_bckdt_elig_cvrd_dpnt_id is null
4275   then
4276   --
4277   FOR l_old_ppr_rec IN c_old_ppr_pen
4278   LOOP
4279       -- create the primary care provider records.
4280       -- 5123666
4281       OPEN c_curr_ppr (l_old_ppr_rec.prmry_care_prvdr_id
4282                       );
4283       FETCH c_curr_ppr INTO l_curr_ppr;
4284 
4285       IF c_curr_ppr%NOTFOUND
4286       THEN
4287          hr_utility.set_location('Reinstate Provider by Creating ',99099);
4288          ben_prmry_care_prvdr_api.create_prmry_care_prvdr (p_validate                     => FALSE,
4289                                                            p_prmry_care_prvdr_id          => l_prmry_care_prvdr_id,
4290                                                            p_effective_start_date         => l_ppr_effective_start_date,
4291                                                            p_effective_end_date           => l_ppr_effective_end_date,
4292                                                            p_name                         => l_old_ppr_rec.NAME,
4293                                                            p_ext_ident                    => l_old_ppr_rec.ext_ident,
4294                                                            p_prmry_care_prvdr_typ_cd      => l_old_ppr_rec.prmry_care_prvdr_typ_cd,
4295                                                            p_prtt_enrt_rslt_id            => p_prtt_enrt_rslt_id,
4296                                                            p_elig_cvrd_dpnt_id            => p_elig_cvrd_dpnt_id,
4297                                                            p_business_group_id            => p_business_group_id,
4298                                                            p_ppr_attribute_category       => l_old_ppr_rec.ppr_attribute_category,
4299                                                            p_ppr_attribute1               => l_old_ppr_rec.ppr_attribute1,
4300                                                            p_ppr_attribute2               => l_old_ppr_rec.ppr_attribute2,
4301                                                            p_ppr_attribute3               => l_old_ppr_rec.ppr_attribute3,
4302                                                            p_ppr_attribute4               => l_old_ppr_rec.ppr_attribute4,
4303                                                            p_ppr_attribute5               => l_old_ppr_rec.ppr_attribute5,
4304                                                            p_ppr_attribute6               => l_old_ppr_rec.ppr_attribute6,
4305                                                            p_ppr_attribute7               => l_old_ppr_rec.ppr_attribute7,
4306                                                            p_ppr_attribute8               => l_old_ppr_rec.ppr_attribute8,
4307                                                            p_ppr_attribute9               => l_old_ppr_rec.ppr_attribute9,
4308                                                            p_ppr_attribute10              => l_old_ppr_rec.ppr_attribute10,
4309                                                            p_ppr_attribute11              => l_old_ppr_rec.ppr_attribute11,
4310                                                            p_ppr_attribute12              => l_old_ppr_rec.ppr_attribute12,
4311                                                            p_ppr_attribute13              => l_old_ppr_rec.ppr_attribute13,
4312                                                            p_ppr_attribute14              => l_old_ppr_rec.ppr_attribute14,
4313                                                            p_ppr_attribute15              => l_old_ppr_rec.ppr_attribute15,
4314                                                            p_ppr_attribute16              => l_old_ppr_rec.ppr_attribute16,
4315                                                            p_ppr_attribute17              => l_old_ppr_rec.ppr_attribute17,
4316                                                            p_ppr_attribute18              => l_old_ppr_rec.ppr_attribute18,
4317                                                            p_ppr_attribute19              => l_old_ppr_rec.ppr_attribute19,
4318                                                            p_ppr_attribute20              => l_old_ppr_rec.ppr_attribute20,
4319                                                            p_ppr_attribute21              => l_old_ppr_rec.ppr_attribute21,
4320                                                            p_ppr_attribute22              => l_old_ppr_rec.ppr_attribute22,
4321                                                            p_ppr_attribute23              => l_old_ppr_rec.ppr_attribute23,
4322                                                            p_ppr_attribute24              => l_old_ppr_rec.ppr_attribute24,
4323                                                            p_ppr_attribute25              => l_old_ppr_rec.ppr_attribute25,
4324                                                            p_ppr_attribute26              => l_old_ppr_rec.ppr_attribute26,
4325                                                            p_ppr_attribute27              => l_old_ppr_rec.ppr_attribute27,
4326                                                            p_ppr_attribute28              => l_old_ppr_rec.ppr_attribute28,
4327                                                            p_ppr_attribute29              => l_old_ppr_rec.ppr_attribute29,
4328                                                            p_ppr_attribute30              => l_old_ppr_rec.ppr_attribute30,
4329                                                            p_request_id                   => l_old_ppr_rec.request_id,
4330                                                            p_program_application_id       => l_old_ppr_rec.program_application_id,
4331                                                            p_program_id                   => l_old_ppr_rec.program_id,
4332                                                            p_program_update_date          => l_old_ppr_rec.program_update_date,
4333                                                            p_object_version_number        => l_ppr_object_version_number,
4334                                                            p_effective_date               => p_effective_date      -- Bug : 5124 As per Jeana, data
4335                                                                                                               -- should be reinstated with system date
4336                                                                                                               -- rather than p_effective_date
4337                                                           );
4338       ELSE
4339          IF    l_curr_ppr.effective_start_date = l_old_ppr_rec.effective_start_date
4340             OR l_curr_ppr.effective_start_date = l_old_ppr_rec.effective_end_date
4341          THEN
4342             l_datetrack_mode := hr_api.g_correction;
4343          ELSE
4344             l_datetrack_mode := hr_api.g_update;
4345          END IF;
4346          hr_utility.set_location('Reinstate Provider by Updating in mode '||l_datetrack_mode,99099);
4347          ben_prmry_care_prvdr_api.update_prmry_care_prvdr (p_validate                     => FALSE,
4348                                                            p_prmry_care_prvdr_id          => l_old_ppr_rec.prmry_care_prvdr_id,
4349                                                            p_effective_start_date         => l_ppr_effective_start_date,
4350                                                            p_effective_end_date           => l_ppr_effective_end_date,
4351                                                            p_name                         => l_old_ppr_rec.NAME,
4352                                                            p_ext_ident                    => l_old_ppr_rec.ext_ident,
4353                                                            p_prmry_care_prvdr_typ_cd      => l_old_ppr_rec.prmry_care_prvdr_typ_cd,
4354                                                            p_prtt_enrt_rslt_id            => p_prtt_enrt_rslt_id,
4355                                                            p_elig_cvrd_dpnt_id            => p_elig_cvrd_dpnt_id,
4356                                                            p_business_group_id            => p_business_group_id,
4357                                                            p_ppr_attribute_category       => l_old_ppr_rec.ppr_attribute_category,
4358                                                            p_ppr_attribute1               => l_old_ppr_rec.ppr_attribute1,
4359                                                            p_ppr_attribute2               => l_old_ppr_rec.ppr_attribute2,
4360                                                            p_ppr_attribute3               => l_old_ppr_rec.ppr_attribute3,
4361                                                            p_ppr_attribute4               => l_old_ppr_rec.ppr_attribute4,
4362                                                            p_ppr_attribute5               => l_old_ppr_rec.ppr_attribute5,
4363                                                            p_ppr_attribute6               => l_old_ppr_rec.ppr_attribute6,
4364                                                            p_ppr_attribute7               => l_old_ppr_rec.ppr_attribute7,
4365                                                            p_ppr_attribute8               => l_old_ppr_rec.ppr_attribute8,
4366                                                            p_ppr_attribute9               => l_old_ppr_rec.ppr_attribute9,
4367                                                            p_ppr_attribute10              => l_old_ppr_rec.ppr_attribute10,
4368                                                            p_ppr_attribute11              => l_old_ppr_rec.ppr_attribute11,
4369                                                            p_ppr_attribute12              => l_old_ppr_rec.ppr_attribute12,
4370                                                            p_ppr_attribute13              => l_old_ppr_rec.ppr_attribute13,
4371                                                            p_ppr_attribute14              => l_old_ppr_rec.ppr_attribute14,
4372                                                            p_ppr_attribute15              => l_old_ppr_rec.ppr_attribute15,
4373                                                            p_ppr_attribute16              => l_old_ppr_rec.ppr_attribute16,
4374                                                            p_ppr_attribute17              => l_old_ppr_rec.ppr_attribute17,
4375                                                            p_ppr_attribute18              => l_old_ppr_rec.ppr_attribute18,
4376                                                            p_ppr_attribute19              => l_old_ppr_rec.ppr_attribute19,
4377                                                            p_ppr_attribute20              => l_old_ppr_rec.ppr_attribute20,
4378                                                            p_ppr_attribute21              => l_old_ppr_rec.ppr_attribute21,
4379                                                            p_ppr_attribute22              => l_old_ppr_rec.ppr_attribute22,
4380                                                            p_ppr_attribute23              => l_old_ppr_rec.ppr_attribute23,
4381                                                            p_ppr_attribute24              => l_old_ppr_rec.ppr_attribute24,
4382                                                            p_ppr_attribute25              => l_old_ppr_rec.ppr_attribute25,
4383                                                            p_ppr_attribute26              => l_old_ppr_rec.ppr_attribute26,
4384                                                            p_ppr_attribute27              => l_old_ppr_rec.ppr_attribute27,
4385                                                            p_ppr_attribute28              => l_old_ppr_rec.ppr_attribute28,
4386                                                            p_ppr_attribute29              => l_old_ppr_rec.ppr_attribute29,
4387                                                            p_ppr_attribute30              => l_old_ppr_rec.ppr_attribute30,
4388                                                            p_request_id                   => l_old_ppr_rec.request_id,
4389                                                            p_program_application_id       => l_old_ppr_rec.program_application_id,
4390                                                            p_program_id                   => l_old_ppr_rec.program_id,
4391                                                            p_program_update_date          => l_old_ppr_rec.program_update_date,
4392                                                            p_object_version_number        => l_old_ppr_rec.object_version_number,
4393                                                            p_effective_date               => p_effective_date,
4394                                                            p_datetrack_mode               => l_datetrack_mode
4395                                                           );
4396       END IF;   -- main if
4397               --
4398   close c_curr_ppr; -- Bug 11667555
4399   END LOOP;
4400   --
4401   END IF;
4402   --
4403   hr_utility.set_location('after participant ' || l_proc,20);
4404   -- for dependent
4405   --
4406   IF  p_bckdt_prtt_enrt_rslt_id is null
4407   and p_bckdt_elig_cvrd_dpnt_id is not null
4408   then
4409   --
4410   FOR l_old_ppr_rec IN c_old_ppr_pdp
4411   LOOP
4412       -- create the primary care provider records.
4413       -- 5123666
4414       OPEN c_curr_ppr (l_old_ppr_rec.prmry_care_prvdr_id
4415                       );
4416       FETCH c_curr_ppr INTO l_curr_ppr;
4417 
4418       IF c_curr_ppr%NOTFOUND
4419       THEN
4420          hr_utility.set_location('Reinstate Provider by Creating ',99099);
4421          ben_prmry_care_prvdr_api.create_prmry_care_prvdr (p_validate                     => FALSE,
4422                                                            p_prmry_care_prvdr_id          => l_prmry_care_prvdr_id,
4423                                                            p_effective_start_date         => l_ppr_effective_start_date,
4424                                                            p_effective_end_date           => l_ppr_effective_end_date,
4425                                                            p_name                         => l_old_ppr_rec.NAME,
4426                                                            p_ext_ident                    => l_old_ppr_rec.ext_ident,
4427                                                            p_prmry_care_prvdr_typ_cd      => l_old_ppr_rec.prmry_care_prvdr_typ_cd,
4428                                                            p_prtt_enrt_rslt_id            => p_prtt_enrt_rslt_id,
4429                                                            p_elig_cvrd_dpnt_id            => p_elig_cvrd_dpnt_id,
4430                                                            p_business_group_id            => p_business_group_id,
4431                                                            p_ppr_attribute_category       => l_old_ppr_rec.ppr_attribute_category,
4432                                                            p_ppr_attribute1               => l_old_ppr_rec.ppr_attribute1,
4433                                                            p_ppr_attribute2               => l_old_ppr_rec.ppr_attribute2,
4434                                                            p_ppr_attribute3               => l_old_ppr_rec.ppr_attribute3,
4435                                                            p_ppr_attribute4               => l_old_ppr_rec.ppr_attribute4,
4436                                                            p_ppr_attribute5               => l_old_ppr_rec.ppr_attribute5,
4437                                                            p_ppr_attribute6               => l_old_ppr_rec.ppr_attribute6,
4438                                                            p_ppr_attribute7               => l_old_ppr_rec.ppr_attribute7,
4439                                                            p_ppr_attribute8               => l_old_ppr_rec.ppr_attribute8,
4440                                                            p_ppr_attribute9               => l_old_ppr_rec.ppr_attribute9,
4441                                                            p_ppr_attribute10              => l_old_ppr_rec.ppr_attribute10,
4442                                                            p_ppr_attribute11              => l_old_ppr_rec.ppr_attribute11,
4443                                                            p_ppr_attribute12              => l_old_ppr_rec.ppr_attribute12,
4444                                                            p_ppr_attribute13              => l_old_ppr_rec.ppr_attribute13,
4445                                                            p_ppr_attribute14              => l_old_ppr_rec.ppr_attribute14,
4446                                                            p_ppr_attribute15              => l_old_ppr_rec.ppr_attribute15,
4447                                                            p_ppr_attribute16              => l_old_ppr_rec.ppr_attribute16,
4448                                                            p_ppr_attribute17              => l_old_ppr_rec.ppr_attribute17,
4449                                                            p_ppr_attribute18              => l_old_ppr_rec.ppr_attribute18,
4450                                                            p_ppr_attribute19              => l_old_ppr_rec.ppr_attribute19,
4451                                                            p_ppr_attribute20              => l_old_ppr_rec.ppr_attribute20,
4452                                                            p_ppr_attribute21              => l_old_ppr_rec.ppr_attribute21,
4453                                                            p_ppr_attribute22              => l_old_ppr_rec.ppr_attribute22,
4454                                                            p_ppr_attribute23              => l_old_ppr_rec.ppr_attribute23,
4455                                                            p_ppr_attribute24              => l_old_ppr_rec.ppr_attribute24,
4456                                                            p_ppr_attribute25              => l_old_ppr_rec.ppr_attribute25,
4457                                                            p_ppr_attribute26              => l_old_ppr_rec.ppr_attribute26,
4458                                                            p_ppr_attribute27              => l_old_ppr_rec.ppr_attribute27,
4459                                                            p_ppr_attribute28              => l_old_ppr_rec.ppr_attribute28,
4460                                                            p_ppr_attribute29              => l_old_ppr_rec.ppr_attribute29,
4461                                                            p_ppr_attribute30              => l_old_ppr_rec.ppr_attribute30,
4462                                                            p_request_id                   => l_old_ppr_rec.request_id,
4463                                                            p_program_application_id       => l_old_ppr_rec.program_application_id,
4464                                                            p_program_id                   => l_old_ppr_rec.program_id,
4465                                                            p_program_update_date          => l_old_ppr_rec.program_update_date,
4466                                                            p_object_version_number        => l_ppr_object_version_number,
4467                                                            p_effective_date               => p_effective_date      -- Bug : 5124 As per Jeana, data
4468                                                                                                               -- should be reinstated with system date
4469                                                                                                               -- rather than p_effective_date
4470                                                           );
4471       ELSE
4472          IF    l_curr_ppr.effective_start_date = l_old_ppr_rec.effective_start_date
4473             OR l_curr_ppr.effective_start_date = l_old_ppr_rec.effective_end_date
4474          THEN
4475             l_datetrack_mode := hr_api.g_correction;
4476          ELSE
4477             l_datetrack_mode := hr_api.g_update;
4478          END IF;
4479          hr_utility.set_location('Reinstate Provider by Updating in mode '||l_datetrack_mode,99099);
4480          ben_prmry_care_prvdr_api.update_prmry_care_prvdr (p_validate                     => FALSE,
4481                                                            p_prmry_care_prvdr_id          => l_old_ppr_rec.prmry_care_prvdr_id,
4482                                                            p_effective_start_date         => l_ppr_effective_start_date,
4483                                                            p_effective_end_date           => l_ppr_effective_end_date,
4484                                                            p_name                         => l_old_ppr_rec.NAME,
4485                                                            p_ext_ident                    => l_old_ppr_rec.ext_ident,
4486                                                            p_prmry_care_prvdr_typ_cd      => l_old_ppr_rec.prmry_care_prvdr_typ_cd,
4487                                                            p_prtt_enrt_rslt_id            => p_prtt_enrt_rslt_id,
4488                                                            p_elig_cvrd_dpnt_id            => p_elig_cvrd_dpnt_id,
4489                                                            p_business_group_id            => p_business_group_id,
4490                                                            p_ppr_attribute_category       => l_old_ppr_rec.ppr_attribute_category,
4491                                                            p_ppr_attribute1               => l_old_ppr_rec.ppr_attribute1,
4492                                                            p_ppr_attribute2               => l_old_ppr_rec.ppr_attribute2,
4493                                                            p_ppr_attribute3               => l_old_ppr_rec.ppr_attribute3,
4494                                                            p_ppr_attribute4               => l_old_ppr_rec.ppr_attribute4,
4495                                                            p_ppr_attribute5               => l_old_ppr_rec.ppr_attribute5,
4496                                                            p_ppr_attribute6               => l_old_ppr_rec.ppr_attribute6,
4497                                                            p_ppr_attribute7               => l_old_ppr_rec.ppr_attribute7,
4498                                                            p_ppr_attribute8               => l_old_ppr_rec.ppr_attribute8,
4499                                                            p_ppr_attribute9               => l_old_ppr_rec.ppr_attribute9,
4500                                                            p_ppr_attribute10              => l_old_ppr_rec.ppr_attribute10,
4501                                                            p_ppr_attribute11              => l_old_ppr_rec.ppr_attribute11,
4502                                                            p_ppr_attribute12              => l_old_ppr_rec.ppr_attribute12,
4503                                                            p_ppr_attribute13              => l_old_ppr_rec.ppr_attribute13,
4504                                                            p_ppr_attribute14              => l_old_ppr_rec.ppr_attribute14,
4505                                                            p_ppr_attribute15              => l_old_ppr_rec.ppr_attribute15,
4506                                                            p_ppr_attribute16              => l_old_ppr_rec.ppr_attribute16,
4507                                                            p_ppr_attribute17              => l_old_ppr_rec.ppr_attribute17,
4508                                                            p_ppr_attribute18              => l_old_ppr_rec.ppr_attribute18,
4509                                                            p_ppr_attribute19              => l_old_ppr_rec.ppr_attribute19,
4510                                                            p_ppr_attribute20              => l_old_ppr_rec.ppr_attribute20,
4511                                                            p_ppr_attribute21              => l_old_ppr_rec.ppr_attribute21,
4512                                                            p_ppr_attribute22              => l_old_ppr_rec.ppr_attribute22,
4513                                                            p_ppr_attribute23              => l_old_ppr_rec.ppr_attribute23,
4514                                                            p_ppr_attribute24              => l_old_ppr_rec.ppr_attribute24,
4515                                                            p_ppr_attribute25              => l_old_ppr_rec.ppr_attribute25,
4516                                                            p_ppr_attribute26              => l_old_ppr_rec.ppr_attribute26,
4517                                                            p_ppr_attribute27              => l_old_ppr_rec.ppr_attribute27,
4518                                                            p_ppr_attribute28              => l_old_ppr_rec.ppr_attribute28,
4519                                                            p_ppr_attribute29              => l_old_ppr_rec.ppr_attribute29,
4520                                                            p_ppr_attribute30              => l_old_ppr_rec.ppr_attribute30,
4521                                                            p_request_id                   => l_old_ppr_rec.request_id,
4522                                                            p_program_application_id       => l_old_ppr_rec.program_application_id,
4523                                                            p_program_id                   => l_old_ppr_rec.program_id,
4524                                                            p_program_update_date          => l_old_ppr_rec.program_update_date,
4525                                                            p_object_version_number        => l_old_ppr_rec.object_version_number,
4526                                                            p_effective_date               => p_effective_date,
4527                                                            p_datetrack_mode               => l_datetrack_mode
4528                                                           );
4529       END IF;   -- main if
4530               --
4531   close c_curr_ppr; -- Bug 11667555
4532   END LOOP;
4533   --
4534   END IF;
4535   --
4536   hr_utility.set_location('Leaving ' || l_proc,30);
4537   --
4538 end reinstate_ppr_per_pen;
4539 --
4540 procedure reinstate_pea_per_pen(
4541                              p_person_id                in number
4542                             ,p_bckdt_prtt_enrt_rslt_id  in number
4543                             ,p_prtt_enrt_rslt_id        in number
4544                             ,p_rslt_object_version_number in number
4545                             ,p_business_group_id        in number
4546                             ,p_per_in_ler_id            in number
4547                             ,p_effective_date           in date
4548                             ,p_bckdt_per_in_ler_id      in number
4549                             ,p_pl_bnf_id                in number default null
4550                             ,p_elig_cvrd_dpnt_id        in number default null
4551                             ,p_old_pl_bnf_id            in number default null
4552                             ,p_old_elig_cvrd_dpnt_id    in number default null
4553                            ) is
4554   --
4555   l_proc                    varchar2(72) := g_package || '.reinstate_pea_per_pen';
4556   --
4557   --BUG 4502165
4558   --When the certification is made on a later date, we need to take the latest record
4559   --otherwise pea record will not have the CMPLTD_DT.
4560   --
4561   cursor c_old_pea is
4562   select pea.CMPLTD_DT,
4563          pea.ACTN_TYP_ID
4564     from ben_prtt_enrt_actn_f pea
4565     where pea.per_in_ler_id       = p_bckdt_per_in_ler_id
4566       and pea.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
4567       and pea.business_group_id   = p_business_group_id
4568       and nvl(pea.pl_bnf_id, -1)  = nvl(p_old_pl_bnf_id, -1)
4569       and nvl(pea.elig_cvrd_dpnt_id, -1) = nvl(p_old_elig_cvrd_dpnt_id, -1)
4570       and pea.effective_end_date = hr_api.g_eot  --BUG 4502165 fix
4571      --  and pea.PL_BNF_ID is null
4572      --  and pea.ELIG_CVRD_DPNT_ID is null
4573   union
4574   select pea.OVRDN_THRU_DT, -- used as pea.CMPLTD_DT
4575          pea.PL_TYP_ID -- used as ACTN_TYP_ID
4576     from ben_le_clsn_n_rstr pea
4577    where pea.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
4578      and pea.business_group_id = p_business_group_id
4579      and pea.per_in_ler_id     = p_bckdt_per_in_ler_id
4580      and p_effective_date between pea.effective_start_date
4581                               and pea.effective_end_date
4582      and nvl(pea.enrt_bnft_id, -1)  = nvl(p_old_pl_bnf_id, -1)
4583               -- enrt_bnft_id used as PL_BNF_ID
4584      and nvl(pea.dpnt_person_id, -1) = nvl(p_old_elig_cvrd_dpnt_id, -1)
4585               -- dpnt_person_id used as elig_cvrd_dpnt_id
4586      -- and pea.ENRT_BNFT_ID is null -- used as pea.PL_BNF_ID
4587      -- and pea.DPNT_PERSON_ID is null -- used as ELIG_CVRD_DPNT_ID is null
4588      and pea.bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_ACTN_F'
4589      order by 1; -- pbn.effective_end_date; -- Low to High
4590   --
4591   l_prtt_enrt_actn_id           number(15);
4592   l_pea_effective_start_date    date;
4593   l_pea_effective_end_date      date;
4594   l_pea_object_version_number   number(9);
4595   --
4596   cursor c_pea(cp_actn_typ_id in number) is
4597   select pea.*
4598     from ben_prtt_enrt_actn_f pea
4599    where pea.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4600      and pea.actn_typ_id     = cp_actn_typ_id
4601      and pea.business_group_id = p_business_group_id
4602      and pea.per_in_ler_id     = p_per_in_ler_id
4603      and nvl(pea.PL_BNF_ID, -1) = nvl(p_PL_BNF_ID, -1)
4604      and nvl(pea.ELIG_CVRD_DPNT_ID, -1) = nvl(p_ELIG_CVRD_DPNT_ID, -1)
4605      -- and pea.PL_BNF_ID is null
4606      -- and pea.ELIG_CVRD_DPNT_ID is null
4607      --
4608      and p_effective_date between pea.effective_start_date
4609                               and pea.effective_end_date;
4610   --
4611   l_pea_rec               c_pea%rowtype;
4612   l_datetrack_mode        varchar2(80) := null;
4613   l_rslt_ovn              number;
4614   --
4615 begin
4616   --
4617   hr_utility.set_location('Entering benleclr' || l_proc,10);
4618   --
4619   for l_old_pea_rec in c_old_pea loop
4620       --
4621       open c_pea(l_old_pea_rec.actn_typ_id);
4622       fetch c_pea into l_pea_rec;
4623       if c_pea%found then
4624         --
4625         if nvl(l_old_pea_rec.CMPLTD_DT, hr_api.g_eot) <> nvl(l_pea_rec.CMPLTD_DT, hr_api.g_eot)
4626         then
4627            --
4628            -- Use the correction mode.
4629            l_datetrack_mode := hr_api.g_correction;
4630            --
4631            -- update the action items.
4632            --
4633            -- If completion date is > p_effective_date .
4634            --
4635            /* BUG 4558512
4636            if l_old_pea_rec.CMPLTD_DT > p_effective_date then
4637               l_old_pea_rec.CMPLTD_DT := p_effective_date;
4638            end if;
4639            */
4640            --
4641            l_rslt_ovn := p_rslt_object_version_number;
4642            --
4643            ben_prtt_enrt_actn_api.update_prtt_enrt_actn
4644              (p_cmpltd_dt                  => l_old_pea_rec.CMPLTD_DT
4645              ,p_prtt_enrt_actn_id          => l_pea_rec.prtt_enrt_actn_id
4646              ,p_prtt_enrt_rslt_id          => l_pea_rec.prtt_enrt_rslt_id
4647              ,p_rslt_object_version_number => l_rslt_ovn
4648              ,p_actn_typ_id                => l_pea_rec.actn_typ_id
4649              ,p_rqd_flag                   => l_pea_rec.rqd_flag
4650              ,p_effective_date             => p_effective_date
4651              ,p_post_rslt_flag             => 'Y' -- p_post_rslt_flag
4652              ,p_business_group_id          => p_business_group_id
4653              ,p_effective_start_date       => l_pea_effective_start_date
4654              ,p_effective_end_date         => l_pea_effective_end_date
4655              ,p_object_version_number      => l_pea_rec.object_version_number
4656              ,p_datetrack_mode             => l_datetrack_mode
4657              );
4658            --
4659            --
4660         end if;
4661         --
4662       end if;
4663       --
4664       close c_pea;
4665   end loop;
4666   --
4667   hr_utility.set_location('Leaving ' || l_proc,10);
4668   --
4669 end reinstate_pea_per_pen;
4670 
4671 procedure reinstate_cpp_per_pdp(
4672                              p_person_id                in number
4673                             ,p_bckdt_prtt_enrt_rslt_id  in number
4674                             ,p_prtt_enrt_rslt_id        in number
4675                             ,p_business_group_id        in number
4676                             ,p_per_in_ler_id            in number
4677                             ,p_effective_date           in date
4678                             ,p_bckdt_per_in_ler_id      in number
4679                             ,p_elig_cvrd_dpnt_id        in number default null
4680                             ,p_old_elig_cvrd_dpnt_id    in number default null
4681                            ) is
4682   --
4683   l_proc          varchar2(72) :=  g_package ||'.reinstate_cpp_per_pdp';
4684   --
4685   cursor c_old_cpp is
4686   select cpp.DPNT_DSGN_CTFN_RECD_DT,
4687          pea.ACTN_TYP_ID,
4688          cpp.DPNT_DSGN_CTFN_TYP_CD
4689     from ben_prtt_enrt_actn_f pea,
4690          ben_cvrd_dpnt_ctfn_prvdd_f cpp
4691     where pea.per_in_ler_id       = p_bckdt_per_in_ler_id
4692       and pea.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
4693       and pea.business_group_id   = p_business_group_id
4694       and pea.elig_cvrd_dpnt_id   = p_old_elig_cvrd_dpnt_id
4695       and cpp.PRTT_ENRT_ACTN_ID   = pea.PRTT_ENRT_ACTN_ID
4696       and pea.elig_cvrd_dpnt_id   = p_old_elig_cvrd_dpnt_id
4697       and cpp.elig_cvrd_dpnt_id   = p_old_elig_cvrd_dpnt_id
4698      --  and pea.PL_BNF_ID is null
4699      --  and pea.ELIG_CVRD_DPNT_ID is null
4700      order by 1; -- pbn.effective_end_date; -- Low to High
4701   --
4702   l_prtt_enrt_actn_id           number(15);
4703   l_cpp_effective_start_date    date;
4704   l_cpp_effective_end_date      date;
4705   l_cpp_object_version_number   number(9);
4706   --
4707   cursor c_cpp(cp_actn_typ_id in number,
4708                cp_DPNT_DSGN_CTFN_TYP_CD in varchar2) is
4709   select cpp.*
4710     from ben_prtt_enrt_actn_f pea,
4711          ben_cvrd_dpnt_ctfn_prvdd_f cpp
4712    where pea.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4713      and pea.actn_typ_id       = cp_actn_typ_id
4714      and pea.business_group_id = p_business_group_id
4715      and pea.per_in_ler_id     = p_per_in_ler_id
4716      and cpp.PRTT_ENRT_ACTN_ID = pea.PRTT_ENRT_ACTN_ID
4717      and pea.ELIG_CVRD_DPNT_ID = p_elig_cvrd_dpnt_id
4718      and cpp.elig_cvrd_dpnt_id = p_elig_cvrd_dpnt_id
4719      and cpp.DPNT_DSGN_CTFN_TYP_CD = cp_DPNT_DSGN_CTFN_TYP_CD
4720      --
4721      and p_effective_date between pea.effective_start_date
4722                         and pea.effective_end_date
4723      and p_effective_date between cpp.effective_start_date
4724                         and cpp.effective_end_date;
4725      -- and p_effective_date between pea.effective_start_date
4726      --                          and pea.effective_end_date;
4727   --
4728   l_cpp_rec               c_cpp%rowtype;
4729   l_datetrack_mode        varchar2(80) := null;
4730   --
4731 begin
4732   --
4733   hr_utility.set_location('Entering ' || l_proc,10);
4734   --
4735   for l_old_cpp_rec in c_old_cpp loop
4736       --
4737       open c_cpp(l_old_cpp_rec.actn_typ_id, l_old_cpp_rec.dpnt_dsgn_ctfn_typ_cd);
4738       fetch c_cpp into l_cpp_rec;
4739       if c_cpp%found then
4740         --
4741         if nvl(l_old_cpp_rec.DPNT_DSGN_CTFN_RECD_DT, hr_api.g_eot) <>
4742            nvl(l_cpp_rec.DPNT_DSGN_CTFN_RECD_DT, hr_api.g_eot)
4743         then
4744            --
4745            -- Use the correction mode.
4746            -- update the dependent certification received.
4747            --
4748            l_datetrack_mode := hr_api.g_correction;
4749            --
4750            if l_old_cpp_rec.DPNT_DSGN_CTFN_RECD_DT < p_effective_date then
4751               l_old_cpp_rec.DPNT_DSGN_CTFN_RECD_DT := p_effective_date;
4752            end if;
4753            --
4754               BEN_cvrd_dpnt_ctfn_prvdd_API.update_cvrd_dpnt_ctfn_prvdd
4755                  (p_validate => FALSE
4756                  ,p_CVRD_DPNT_CTFN_PRVDD_ID  => l_cpp_rec.CVRD_DPNT_CTFN_PRVDD_ID
4757                  ,p_EFFECTIVE_START_DATE     => l_cpp_EFFECTIVE_START_DATE
4758                  ,p_EFFECTIVE_END_DATE       => l_cpp_EFFECTIVE_END_DATE
4759                  ,p_DPNT_DSGN_CTFN_TYP_CD    => l_cpp_rec.DPNT_DSGN_CTFN_TYP_CD
4760                  ,p_DPNT_DSGN_CTFN_RQD_FLAG  => l_cpp_rec.DPNT_DSGN_CTFN_RQD_FLAG
4761                  ,p_DPNT_DSGN_CTFN_RECD_DT   => l_old_cpp_rec.DPNT_DSGN_CTFN_RECD_DT
4762                  ,p_ELIG_CVRD_DPNT_ID        => l_cpp_rec.ELIG_CVRD_DPNT_ID
4763                  ,p_prtt_enrt_actn_id        => l_cpp_rec.PRTT_ENRT_ACTN_ID
4764                  ,p_BUSINESS_GROUP_ID        => l_cpp_rec.BUSINESS_GROUP_ID
4765                  ,p_CCP_ATTRIBUTE_CATEGORY   => l_cpp_rec.CCP_ATTRIBUTE_CATEGORY
4766                  ,p_CCP_ATTRIBUTE1           => l_cpp_rec.CCP_ATTRIBUTE1
4767                  ,p_CCP_ATTRIBUTE2           => l_cpp_rec.CCP_ATTRIBUTE2
4768                  ,p_CCP_ATTRIBUTE3           => l_cpp_rec.CCP_ATTRIBUTE3
4769                  ,p_CCP_ATTRIBUTE4           => l_cpp_rec.CCP_ATTRIBUTE4
4770                  ,p_CCP_ATTRIBUTE5           => l_cpp_rec.CCP_ATTRIBUTE5
4771                  ,p_CCP_ATTRIBUTE6           => l_cpp_rec.CCP_ATTRIBUTE6
4772                  ,p_CCP_ATTRIBUTE7           => l_cpp_rec.CCP_ATTRIBUTE7
4773                  ,p_CCP_ATTRIBUTE8           => l_cpp_rec.CCP_ATTRIBUTE8
4774                  ,p_CCP_ATTRIBUTE9           => l_cpp_rec.CCP_ATTRIBUTE9
4775                  ,p_CCP_ATTRIBUTE10           => l_cpp_rec.CCP_ATTRIBUTE10
4776                  ,p_CCP_ATTRIBUTE11           => l_cpp_rec.CCP_ATTRIBUTE11
4777                  ,p_CCP_ATTRIBUTE12           => l_cpp_rec.CCP_ATTRIBUTE12
4778                  ,p_CCP_ATTRIBUTE13           => l_cpp_rec.CCP_ATTRIBUTE13
4779                  ,p_CCP_ATTRIBUTE14           => l_cpp_rec.CCP_ATTRIBUTE14
4780                  ,p_CCP_ATTRIBUTE15           => l_cpp_rec.CCP_ATTRIBUTE15
4781                  ,p_CCP_ATTRIBUTE16           => l_cpp_rec.CCP_ATTRIBUTE16
4782                  ,p_CCP_ATTRIBUTE17           => l_cpp_rec.CCP_ATTRIBUTE17
4783                  ,p_CCP_ATTRIBUTE18           => l_cpp_rec.CCP_ATTRIBUTE18
4784                  ,p_CCP_ATTRIBUTE19           => l_cpp_rec.CCP_ATTRIBUTE19
4785                  ,p_CCP_ATTRIBUTE20           => l_cpp_rec.CCP_ATTRIBUTE20
4786                  ,p_CCP_ATTRIBUTE21           => l_cpp_rec.CCP_ATTRIBUTE21
4787                  ,p_CCP_ATTRIBUTE22           => l_cpp_rec.CCP_ATTRIBUTE22
4788                  ,p_CCP_ATTRIBUTE23           => l_cpp_rec.CCP_ATTRIBUTE23
4789                  ,p_CCP_ATTRIBUTE24           => l_cpp_rec.CCP_ATTRIBUTE24
4790                  ,p_CCP_ATTRIBUTE25           => l_cpp_rec.CCP_ATTRIBUTE25
4791                  ,p_CCP_ATTRIBUTE26           => l_cpp_rec.CCP_ATTRIBUTE26
4792                  ,p_CCP_ATTRIBUTE27           => l_cpp_rec.CCP_ATTRIBUTE27
4793                  ,p_CCP_ATTRIBUTE28           => l_cpp_rec.CCP_ATTRIBUTE28
4794                  ,p_CCP_ATTRIBUTE29           => l_cpp_rec.CCP_ATTRIBUTE29
4795                  ,p_CCP_ATTRIBUTE30           => l_cpp_rec.CCP_ATTRIBUTE30
4796                  ,p_request_id                => l_cpp_rec.REQUEST_ID
4797                  ,p_program_application_id    => l_cpp_rec.PROGRAM_APPLICATION_ID
4798                  ,p_program_id                => l_cpp_rec.PROGRAM_ID
4799                  ,p_program_update_date       => l_cpp_rec.PROGRAM_UPDATE_DATE
4800                  ,p_OBJECT_VERSION_NUMBER     => l_cpp_rec.OBJECT_VERSION_NUMBER
4801                  ,p_effective_date            => p_effective_date
4802                  ,p_datetrack_mode            => l_datetrack_mode
4803                  );
4804            --
4805         end if;
4806         --
4807       end if;
4808       --
4809       close c_cpp;
4810   end loop;
4811   --
4812   hr_utility.set_location('Leaving ' || l_proc,10);
4813   --
4814 end reinstate_cpp_per_pdp;
4815 --
4816 -- This procedure creates the enrollment results based on what participant
4817 -- enrolled as of the backed out per in ler.
4818 --
4819 procedure reinstate_dpnts_per_pen(
4820                              p_person_id                in number
4821                             ,p_bckdt_prtt_enrt_rslt_id  in number
4822                             ,p_prtt_enrt_rslt_id        in number
4823                             ,p_pen_ovn_number           in out nocopy number
4824                             ,p_old_pl_id                in number default null
4825                             ,p_new_pl_id                in number default null
4826                             ,p_old_oipl_id              in number default null
4827                             ,p_new_oipl_id              in number default null
4828                             ,p_old_pl_typ_id            in number default null
4829                             ,p_new_pl_typ_id            in number default null
4830                             ,p_pgm_id                   in number default null
4831                             ,p_ler_id                   in number default null
4832                             ,p_elig_per_elctbl_chc_id   in number
4833                             ,p_business_group_id        in number
4834                             ,p_effective_date           in date
4835                             ,p_per_in_ler_id            in number
4836                             ,p_bckdt_per_in_ler_id      in number
4837                             ,p_dpnt_cvg_strt_dt_cd      in varchar2
4838                             ,p_dpnt_cvg_strt_dt_rl      in number
4839                             ,p_enrt_cvg_strt_dt         in date
4840                            ) is
4841   --
4842   l_proc                    varchar2(72) := g_package||'.reinstate_dpnts_per_pen';
4843   --
4844   -- Cursor to fetch all the depenedents attched to the backed out
4845   -- enrollment result.
4846   --
4847   cursor c_bckdt_pen_dpnts is
4848     select
4849                 pdp_old.EFFECTIVE_END_DATE,
4850                 pdp_old.CVG_STRT_DT,
4851                 pdp_old.CVG_THRU_DT,
4852                 pdp_old.CVG_PNDG_FLAG,
4853                 pdp_old.OVRDN_FLAG,
4854                 pdp_old.OVRDN_THRU_DT,
4855                 pdp_old.PRTT_ENRT_RSLT_ID,
4856                 pdp_old.DPNT_PERSON_ID,
4857                 pdp_old.PER_IN_LER_ID,
4858                 pdp_old.BUSINESS_GROUP_ID,
4859                 pdp_old.PDP_ATTRIBUTE_CATEGORY,
4860                 pdp_old.PDP_ATTRIBUTE1,
4861                 pdp_old.PDP_ATTRIBUTE2,
4862                 pdp_old.PDP_ATTRIBUTE3,
4863                 pdp_old.PDP_ATTRIBUTE4,
4864                 pdp_old.PDP_ATTRIBUTE5,
4865                 pdp_old.PDP_ATTRIBUTE6,
4866                 pdp_old.PDP_ATTRIBUTE7,
4867                 pdp_old.PDP_ATTRIBUTE8,
4868                 pdp_old.PDP_ATTRIBUTE9,
4869                 pdp_old.PDP_ATTRIBUTE10,
4870                 pdp_old.PDP_ATTRIBUTE11,
4871                 pdp_old.PDP_ATTRIBUTE12,
4872                 pdp_old.PDP_ATTRIBUTE13,
4873                 pdp_old.PDP_ATTRIBUTE14,
4874                 pdp_old.PDP_ATTRIBUTE15,
4875                 pdp_old.PDP_ATTRIBUTE16,
4876                 pdp_old.PDP_ATTRIBUTE17,
4877                 pdp_old.PDP_ATTRIBUTE18,
4878                 pdp_old.PDP_ATTRIBUTE19,
4879                 pdp_old.PDP_ATTRIBUTE20,
4880                 pdp_old.PDP_ATTRIBUTE21,
4881                 pdp_old.PDP_ATTRIBUTE22,
4882                 pdp_old.PDP_ATTRIBUTE23,
4883                 pdp_old.PDP_ATTRIBUTE24,
4884                 pdp_old.PDP_ATTRIBUTE25,
4885                 pdp_old.PDP_ATTRIBUTE26,
4886                 pdp_old.PDP_ATTRIBUTE27,
4887                 pdp_old.PDP_ATTRIBUTE28,
4888                 pdp_old.PDP_ATTRIBUTE29,
4889                 pdp_old.PDP_ATTRIBUTE30,
4890                 pdp_old.LAST_UPDATE_DATE,
4891                 pdp_old.LAST_UPDATED_BY,
4892                 pdp_old.LAST_UPDATE_LOGIN,
4893                 pdp_old.CREATED_BY,
4894                 pdp_old.CREATION_DATE,
4895                 pdp_old.REQUEST_ID,
4896                 pdp_old.PROGRAM_APPLICATION_ID,
4897                 pdp_old.PROGRAM_ID,
4898                 pdp_old.PROGRAM_UPDATE_DATE,
4899                 pdp_old.OBJECT_VERSION_NUMBER,
4900                 pdp_old.elig_cvrd_dpnt_id,
4901                 pdp_old.EFFECTIVE_START_DATE
4902     from ben_elig_cvrd_dpnt_f pdp_old
4903     where pdp_old.per_in_ler_id       = p_bckdt_per_in_ler_id
4904       and pdp_old.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
4905       and pdp_old.business_group_id   = p_business_group_id
4906     union
4907     select
4908                 pdp_old.EFFECTIVE_END_DATE,
4909                 pdp_old.CVG_STRT_DT,
4910                 pdp_old.CVG_THRU_DT,
4911                 pdp_old.CVG_PNDG_FLAG,
4912                 pdp_old.OVRDN_FLAG,
4913                 pdp_old.OVRDN_THRU_DT,
4914                 pdp_old.PRTT_ENRT_RSLT_ID,
4915                 pdp_old.DPNT_PERSON_ID,
4916                 pdp_old.PER_IN_LER_ID,
4917                 pdp_old.BUSINESS_GROUP_ID,
4918                 pdp_old.LCR_ATTRIBUTE_CATEGORY,
4919                 pdp_old.LCR_ATTRIBUTE1,
4920                 pdp_old.LCR_ATTRIBUTE2,
4921                 pdp_old.LCR_ATTRIBUTE3,
4922                 pdp_old.LCR_ATTRIBUTE4,
4923                 pdp_old.LCR_ATTRIBUTE5,
4924                 pdp_old.LCR_ATTRIBUTE6,
4925                 pdp_old.LCR_ATTRIBUTE7,
4926                 pdp_old.LCR_ATTRIBUTE8,
4927                 pdp_old.LCR_ATTRIBUTE9,
4928                 pdp_old.LCR_ATTRIBUTE10,
4929                 pdp_old.LCR_ATTRIBUTE11,
4930                 pdp_old.LCR_ATTRIBUTE12,
4931                 pdp_old.LCR_ATTRIBUTE13,
4932                 pdp_old.LCR_ATTRIBUTE14,
4933                 pdp_old.LCR_ATTRIBUTE15,
4934                 pdp_old.LCR_ATTRIBUTE16,
4935                 pdp_old.LCR_ATTRIBUTE17,
4936                 pdp_old.LCR_ATTRIBUTE18,
4937                 pdp_old.LCR_ATTRIBUTE19,
4938                 pdp_old.LCR_ATTRIBUTE20,
4939                 pdp_old.LCR_ATTRIBUTE21,
4940                 pdp_old.LCR_ATTRIBUTE22,
4941                 pdp_old.LCR_ATTRIBUTE23,
4942                 pdp_old.LCR_ATTRIBUTE24,
4943                 pdp_old.LCR_ATTRIBUTE25,
4944                 pdp_old.LCR_ATTRIBUTE26,
4945                 pdp_old.LCR_ATTRIBUTE27,
4946                 pdp_old.LCR_ATTRIBUTE28,
4947                 pdp_old.LCR_ATTRIBUTE29,
4948                 pdp_old.LCR_ATTRIBUTE30,
4949                 pdp_old.LAST_UPDATE_DATE,
4950                 pdp_old.LAST_UPDATED_BY,
4951                 pdp_old.LAST_UPDATE_LOGIN,
4952                 pdp_old.CREATED_BY,
4953                 pdp_old.CREATION_DATE,
4954                 pdp_old.REQUEST_ID,
4955                 pdp_old.PROGRAM_APPLICATION_ID,
4956                 pdp_old.PROGRAM_ID,
4957                 pdp_old.PROGRAM_UPDATE_DATE,
4958                 pdp_old.OBJECT_VERSION_NUMBER,
4959                 pdp_old.BKUP_TBL_ID,
4960                 pdp_old.EFFECTIVE_START_DATE
4961     from   ben_le_clsn_n_rstr pdp_old
4962     where  pdp_old.per_in_ler_id       = p_bckdt_per_in_ler_id
4963     and    pdp_old.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
4964     and    pdp_old.business_group_id   = p_business_group_id
4965     and    pdp_old.bkup_tbl_typ_cd     = 'BEN_ELIG_CVRD_DPNT_F'
4966     order by 1; -- pdp_old.effective_end_date; -- Low to High
4967   --
4968   --5692797
4969   cursor c_chk_valid_pdp(p_elig_cvrd_dpnt_id number) is
4970     select 'Y'
4971     from   ben_elig_cvrd_dpnt_f pdp_old
4972     where  pdp_old.elig_cvrd_dpnt_id = p_elig_cvrd_dpnt_id
4973     and    pdp_old.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
4974     and    (pdp_old.effective_end_date = hr_api.g_eot or
4975             pdp_old.effective_end_date = (select max(effective_end_date)
4976                                           from ben_elig_cvrd_dpnt_f
4977                                           where elig_cvrd_dpnt_id = pdp_old.elig_cvrd_dpnt_id
4978                                           and prtt_enrt_rslt_id = pdp_old.prtt_enrt_rslt_id))
4979     and    (pdp_old.cvg_thru_dt is null or pdp_old.cvg_thru_dt = hr_api.g_eot)
4980     /*Bug 12419118: Added below exists clause*/
4981     and  exists
4982            (select '1' from ben_elig_cvrd_dpnt_f
4983             where elig_cvrd_dpnt_id = p_elig_cvrd_dpnt_id
4984             and prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
4985             and effective_end_date = hr_api.g_eot
4986             and cvg_thru_dt = hr_api.g_eot
4987             and per_in_ler_id = p_bckdt_per_in_ler_id
4988             union
4989             select '1' from ben_le_clsn_n_rstr
4990             where BKUP_TBL_ID = p_elig_cvrd_dpnt_id
4991             and prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
4992             and effective_end_date = hr_api.g_eot
4993             and cvg_thru_dt = hr_api.g_eot
4994             and per_in_ler_id = p_bckdt_per_in_ler_id
4995             and bkup_tbl_typ_cd = 'BEN_ELIG_CVRD_DPNT_F'
4996             )
4997     union
4998     select 'Y'
4999     from   ben_le_clsn_n_rstr pdp_old
5000     where  pdp_old.bkup_tbl_id = p_elig_cvrd_dpnt_id
5001     and    pdp_old.bkup_tbl_typ_cd = 'BEN_ELIG_CVRD_DPNT_F'
5002     and    pdp_old.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
5003     and    ((pdp_old.cvg_thru_dt is null or pdp_old.cvg_thru_dt = hr_api.g_eot)  and
5004             pdp_old.effective_end_date = hr_api.g_eot
5005            )
5006     and pdp_old.per_in_ler_id = p_bckdt_per_in_ler_id; --Bug 12419118
5007   --
5008   l_chk_valid_pdp char;
5009   --
5010   cursor c_pen_dpnts(cp_dpnt_person_id in number) is
5011   select pdp.*
5012     from ben_elig_cvrd_dpnt_f pdp ,
5013          ben_per_in_ler pil
5014    where pdp.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5015      and pdp.cvg_strt_dt is not null
5016      and nvl(pdp.cvg_thru_dt, hr_api.g_eot) = hr_api.g_eot
5017      and pdp.business_group_id = p_business_group_id
5018      and pdp.dpnt_person_id    = cp_dpnt_person_id
5019      and p_effective_date between pdp.effective_start_date
5020                               and pdp.effective_end_date
5021      and pdp.per_in_ler_id =  pil.per_in_ler_id
5022      and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
5023   --
5024   l_pen_dpnts_rec               c_pen_dpnts%rowtype;
5025   --
5026   --
5027   cursor c_epe_dpnt(cp_dpnt_person_id in number) is
5028   select edg.*
5029   from ben_elig_dpnt edg
5030   where  edg.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5031     and  edg.business_group_id      = p_business_group_id
5032     and  edg.dpnt_person_id         = cp_dpnt_person_id;
5033   --
5034   l_epe_dpnt_rec               c_epe_dpnt%rowtype;
5035   -- bug 5895645
5036   cursor get_dt_c is
5037      select enrt_cvg_strt_dt
5038      from   ben_prtt_enrt_rslt_f
5039      where  prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5040      and    p_effective_date between effective_start_date
5041                                and effective_end_date;
5042 -- end 5895645
5043   l_cvg_strt_dt                 date;
5044   l_elig_cvrd_dpnt_id           number(15);
5045   l_effective_start_date        date;
5046   l_effective_end_date          date;
5047   l_pdp_object_version_number   number(9);
5048   l_pdp_cr_up_flag              boolean := FALSE;
5049   l_new_pl_id                   number;
5050   l_enrt_cvg_strt_dt            date;  -- bug 5895645
5051   --
5052 begin
5053   --
5054   hr_utility.set_location('Entering ' || l_proc,10);
5055   hr_utility.set_location('p_bckdt_per_in_ler_id ' || p_bckdt_per_in_ler_id,10);
5056   hr_utility.set_location('p_bckdt_prtt_enrt_rslt_id ' || p_bckdt_prtt_enrt_rslt_id,10);
5057   hr_utility.set_location('p_prtt_enrt_rslt_id ' || p_prtt_enrt_rslt_id,10);
5058   --
5059 
5060    --
5061   for bckdt_pen_dpnts_rec in c_bckdt_pen_dpnts loop
5062       --
5063       hr_utility.set_location('Reinstating dependent person id = ' ||
5064                                bckdt_pen_dpnts_rec.dpnt_person_id, 999);
5065       open c_pen_dpnts(bckdt_pen_dpnts_rec.dpnt_person_id);
5066       fetch c_pen_dpnts into l_pen_dpnts_rec;
5067       if c_pen_dpnts%notfound then
5068          hr_utility.set_location('Creating new dependent row', 8085);
5069          --
5070          -- Create the dependents row.
5071          --
5072          -- Calculate Dependents Coverage Start Date
5073          --
5074          ben_determine_date.main
5075            (p_date_cd                 => p_dpnt_cvg_strt_dt_cd
5076            ,p_per_in_ler_id           => null
5077            ,p_person_id               => null
5078            ,p_pgm_id                  => null
5079            ,p_pl_id                   => null
5080            ,p_oipl_id                 => null
5081            ,p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id
5082            ,p_business_group_id       => p_business_group_id
5083            ,p_formula_id              => p_dpnt_cvg_strt_dt_rl
5084            ,p_effective_date          => p_effective_date -- Bug : 5124 As per Jeana, data
5085                                                    -- should be reinstated with system date
5086                                                    -- rather than p_effective_date,
5087            ,p_returned_date           => l_cvg_strt_dt);
5088          -- start bug 5895645
5089 	 open get_dt_c;
5090          fetch get_dt_c into l_enrt_cvg_strt_dt;
5091          close get_dt_c;
5092 	 -- end bug 5895645
5093 
5094          if l_cvg_strt_dt is null then
5095            -- error
5096            --
5097            fnd_message.set_name('BEN', 'BEN_91657_DPNT_CVG_STRT_DT');
5098            fnd_message.raise_error;
5099          end if;
5100          --
5101          -- Take the latter of the calculated date and p_enrt_cvg_strt_dt
5102          --
5103          if l_cvg_strt_dt < nvl(p_enrt_cvg_strt_dt,l_enrt_cvg_strt_dt) then
5104            --
5105            l_cvg_strt_dt := nvl(p_enrt_cvg_strt_dt,l_enrt_cvg_strt_dt);
5106            --
5107          end if;
5108          --
5109 	 hr_utility.set_location('Cvg start dt ='||to_char(l_cvg_strt_dt), 25);
5110          hr_utility.set_location('p_enrt_cvg_strt_dt  ='||to_char(p_enrt_cvg_strt_dt), 25);
5111 	  hr_utility.set_location('l_enrt_cvg_strt_dt  =' || l_enrt_cvg_strt_dt, 25);
5112          --
5113          -- Now hook the depenedent to the new enrollment result.
5114          --
5115          open c_epe_dpnt(bckdt_pen_dpnts_rec.dpnt_person_id);
5116          fetch c_epe_dpnt into l_epe_dpnt_rec;
5117          if c_epe_dpnt%found then
5118             l_pdp_cr_up_flag  := TRUE;
5119             ben_ELIG_DPNT_api.process_dependent(
5120                 p_elig_dpnt_id          => l_epe_dpnt_rec.elig_dpnt_id,
5121                 p_business_group_id     => p_business_group_id,
5122                 p_effective_date        => p_effective_date, -- Bug : 5124 As per Jeana, data
5123                                                    -- should be reinstated with system date
5124                                                    -- rather than p_effective_date,
5125                 p_cvg_strt_dt           => l_cvg_strt_dt,
5126                 p_cvg_thru_dt           => hr_api.g_eot,
5127                 p_datetrack_mode        => hr_api.g_insert,
5128                 p_elig_cvrd_dpnt_id     => l_elig_cvrd_dpnt_id,
5129                 p_effective_start_date  => l_effective_start_date,
5130                 p_effective_end_date    => l_effective_end_date,
5131                 p_object_version_number => l_pdp_object_version_number,
5132                 p_multi_row_actn        => TRUE );
5133          end if;
5134          close c_epe_dpnt;
5135          --
5136        --
5137       elsif bckdt_pen_dpnts_rec.cvg_thru_dt <> hr_api.g_eot then
5138          hr_utility.set_location('End-dated row found - vvp', 7777);
5139 
5140          --5692797 Check whether backed out PDP record exists for the dependent in same enrollment
5141          --with valid coverage. If yes, no need to reinstate this end-dated record.
5142          l_chk_valid_pdp := null;
5143          open c_chk_valid_pdp(bckdt_pen_dpnts_rec.elig_cvrd_dpnt_id);
5144          fetch c_chk_valid_pdp into l_chk_valid_pdp;
5145          close c_chk_valid_pdp;
5146 
5147          hr_utility.set_location('l_chk_valid_pdp = '|| l_chk_valid_pdp, 8085);
5148          if l_chk_valid_pdp is null then
5149            open c_epe_dpnt(bckdt_pen_dpnts_rec.dpnt_person_id);
5150            fetch c_epe_dpnt into l_epe_dpnt_rec;
5151            if c_epe_dpnt%found then
5152               l_pdp_cr_up_flag  := TRUE;
5153               ben_ELIG_DPNT_api.process_dependent(
5154                   p_elig_dpnt_id          => l_epe_dpnt_rec.elig_dpnt_id,
5155                   p_business_group_id     => p_business_group_id,
5156                   p_effective_date        => p_effective_date, -- Bug : 5124 As per Jeana, data
5157                                                      -- should be reinstated with system date
5158                                                      -- rather than p_effective_date,
5159                   p_cvg_strt_dt           => bckdt_pen_dpnts_rec.cvg_strt_dt,
5160                   p_cvg_thru_dt           => bckdt_pen_dpnts_rec.cvg_thru_dt,
5161                   p_datetrack_mode        => hr_api.g_update,
5162                   p_elig_cvrd_dpnt_id     => l_elig_cvrd_dpnt_id,
5163                   p_effective_start_date  => l_effective_start_date,
5164                   p_effective_end_date    => l_effective_end_date,
5165                   p_object_version_number => l_pdp_object_version_number,
5166                   p_multi_row_actn        => TRUE );
5167            end if;
5168            close c_epe_dpnt;
5169          end if; --end l_chk_valid_pdp
5170       end if;
5171       close c_pen_dpnts;
5172       --
5173       hr_utility.set_location('l_elig_cvrd_dpnt_id ='||l_elig_cvrd_dpnt_id, 25);
5174       hr_utility.set_location('p_bckdt_prtt_enrt_rslt_id'||p_bckdt_prtt_enrt_rslt_id,25);
5175       hr_utility.set_location('bckdt_pen_dpnts_rec.elig_cvrd_dpnt_id'||bckdt_pen_dpnts_rec.elig_cvrd_dpnt_id,25);
5176       hr_utility.set_location('p_prtt_enrt_rslt_id'||p_prtt_enrt_rslt_id,25);
5177       hr_utility.set_location('p_business_group_id'||p_business_group_id,25);
5178       hr_utility.set_location('p_effective_date'||p_effective_date,25);
5179       hr_utility.set_location('p_person_id '||p_person_id,25);
5180       --
5181       if l_elig_cvrd_dpnt_id is not null then
5182          --Reinstates PCP at dependent level.
5183          reinstate_ppr_per_pen(
5184                 p_person_id                => p_person_id
5185                 ,p_bckdt_prtt_enrt_rslt_id => NULL -- p_bckdt_prtt_enrt_rslt_id Bug 3709516
5186                 ,p_prtt_enrt_rslt_id       => NULL -- p_prtt_enrt_rslt_id
5187                 ,p_business_group_id       => p_business_group_id
5188                 ,p_elig_cvrd_dpnt_id       => l_elig_cvrd_dpnt_id
5189                 ,p_effective_date          => p_effective_date
5190                 ,p_bckdt_elig_cvrd_dpnt_id => bckdt_pen_dpnts_rec.elig_cvrd_dpnt_id
5191                 );
5192          --
5193          -- Complete the certifications associated with the dependents.
5194          --
5195          reinstate_cpp_per_pdp(
5196             p_person_id                => p_person_id
5197             ,p_bckdt_prtt_enrt_rslt_id  => p_bckdt_prtt_enrt_rslt_id
5198             ,p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id
5199             ,p_business_group_id        => p_business_group_id
5200             ,p_per_in_ler_id            => p_per_in_ler_id
5201             ,p_effective_date           => p_effective_date
5202             ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
5203             ,p_elig_cvrd_dpnt_id        => l_elig_cvrd_dpnt_id
5204             ,p_old_elig_cvrd_dpnt_id    => bckdt_pen_dpnts_rec.elig_cvrd_dpnt_id
5205             );
5206          --
5207       end if;
5208   end loop;
5209   if l_pdp_cr_up_flag then
5210      --
5211      if p_pgm_id is null then
5212         l_new_pl_id := p_new_pl_id;
5213      else
5214         l_new_pl_id := null;
5215      end if;
5216      --
5217      ben_proc_common_enrt_rslt.process_post_enrollment(
5218            p_per_in_ler_id     => p_PER_IN_LER_ID
5219           ,p_pgm_id            => p_pgm_id
5220           ,p_pl_id             => l_new_pl_id
5221           ,p_enrt_mthd_cd      => 'E'   -- Explicit
5222           ,p_cls_enrt_flag     => FALSE
5223           ,p_proc_cd           => 'DSGNDPNT'
5224           ,p_person_id         => p_PERSON_ID
5225           ,p_business_group_id => p_BUSINESS_GROUP_ID
5226           ,p_effective_date    => p_effective_date -- Bug : 5124 As per Jeana, data
5227                                              -- should be reinstated with system date
5228                                              -- rather than  p_effective_date
5229           ,p_validate          => FALSE
5230            );
5231      --
5232   end if;
5233   --
5234   hr_utility.set_location('Leaving ' || l_proc,10);
5235   --
5236 end reinstate_dpnts_per_pen;
5237 --
5238 procedure reinstate_pbc_per_pbn(
5239                              p_person_id                in number
5240                             ,p_bckdt_prtt_enrt_rslt_id  in number
5241                             ,p_prtt_enrt_rslt_id        in number
5242                             ,p_business_group_id        in number
5243                             ,p_per_in_ler_id            in number
5244                             ,p_effective_date           in date
5245                             ,p_bckdt_per_in_ler_id      in number
5246                             ,p_PL_BNF_ID        in number default null
5247                             ,p_old_PL_BNF_ID    in number default null
5248                            ) is
5249   --
5250   l_proc          varchar2(72) :=  g_package ||'.reinstate_pbc_per_pbn';
5251   --
5252   cursor c_old_pbc is
5253   select pbc.BNF_CTFN_RECD_DT,
5254          pea.ACTN_TYP_ID,
5255          pbc.BNF_CTFN_TYP_CD
5256     from ben_prtt_enrt_actn_f pea,
5257          ben_pl_bnf_ctfn_prvdd_f pbc
5258     where pea.per_in_ler_id       = p_bckdt_per_in_ler_id
5259       and pea.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
5260       and pea.business_group_id   = p_business_group_id
5261       and pea.PL_BNF_ID           = p_old_PL_BNF_ID
5262       and pbc.PRTT_ENRT_ACTN_ID   = pea.PRTT_ENRT_ACTN_ID
5263       and pbc.PL_BNF_ID           = p_old_PL_BNF_ID
5264      order by 1; -- pbn.effective_end_date; -- Low to High
5265   --
5266   l_prtt_enrt_actn_id           number(15);
5267   l_pbc_effective_start_date    date;
5268   l_pbc_effective_end_date      date;
5269   l_pbc_object_version_number   number(9);
5270   --
5271   cursor c_pbc(cp_actn_typ_id in number,
5272                cp_BNF_CTFN_TYP_CD in varchar2) is
5273   select pbc.*
5274     from ben_prtt_enrt_actn_f pea,
5275          ben_pl_bnf_ctfn_prvdd_f pbc
5276    where pea.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5277      and pea.actn_typ_id       = cp_actn_typ_id
5278      and pea.business_group_id = p_business_group_id
5279      and pea.per_in_ler_id     = p_per_in_ler_id
5280      and pbc.PRTT_ENRT_ACTN_ID = pea.PRTT_ENRT_ACTN_ID
5281      and pea.ELIG_CVRD_DPNT_ID = p_PL_BNF_ID
5282      and pbc.PL_BNF_ID = p_PL_BNF_ID
5283      and pbc.BNF_CTFN_TYP_CD = cp_BNF_CTFN_TYP_CD
5284      and p_effective_date between pea.effective_start_date
5285                         and pea.effective_end_date
5286      and p_effective_date between pbc.effective_start_date
5287                         and pbc.effective_end_date;
5288      -- and p_effective_date between pea.effective_start_date
5289      --                          and pea.effective_end_date;
5290   --
5291   l_pbc_rec               c_pbc%rowtype;
5292   l_datetrack_mode        varchar2(80) := null;
5293   --
5294 begin
5295   --
5296   hr_utility.set_location('Entering ' || l_proc,10);
5297   --
5298   for l_old_pbc_rec in c_old_pbc loop
5299       --
5300       open c_pbc(l_old_pbc_rec.actn_typ_id, l_old_pbc_rec.BNF_CTFN_TYP_CD);
5301       fetch c_pbc into l_pbc_rec;
5302       if c_pbc%found then
5303         --
5304         if nvl(l_old_pbc_rec.BNF_CTFN_RECD_DT, hr_api.g_eot) <>
5305            nvl(l_pbc_rec.BNF_CTFN_RECD_DT, hr_api.g_eot)
5306         then
5307            --
5308            -- Use the correction mode.
5309            -- update the dependent certification received.
5310            --
5311            l_datetrack_mode := hr_api.g_correction;
5312            --
5313            if l_old_pbc_rec.BNF_CTFN_RECD_DT < p_effective_date then
5314               l_old_pbc_rec.BNF_CTFN_RECD_DT := p_effective_date;
5315            end if;
5316            --
5317            BEN_pl_bnf_ctfn_prvdd_API.update_pl_bnf_ctfn_prvdd
5318                  (p_validate => FALSE
5319                  ,p_PL_BNF_CTFN_PRVDD_ID     => l_pbc_rec.PL_BNF_CTFN_PRVDD_ID
5320                  ,p_EFFECTIVE_START_DATE     => l_pbc_EFFECTIVE_START_DATE
5321                  ,p_EFFECTIVE_END_DATE       => l_pbc_EFFECTIVE_END_DATE
5322                  ,p_BNF_CTFN_TYP_CD          => l_pbc_rec.BNF_CTFN_TYP_CD
5323                  ,p_BNF_CTFN_RECD_DT         => l_old_pbc_rec.BNF_CTFN_RECD_DT
5324                  ,p_BNF_CTFN_RQD_FLAG        => l_pbc_rec.BNF_CTFN_RQD_FLAG
5325                  ,p_PL_BNF_ID                => l_pbc_rec.PL_BNF_ID
5326                  ,p_prtt_enrt_actn_id        => l_pbc_rec.PRTT_ENRT_ACTN_ID
5327                  ,p_BUSINESS_GROUP_ID        => l_pbc_rec.BUSINESS_GROUP_ID
5328                  ,p_PBC_ATTRIBUTE_CATEGORY   => l_pbc_rec.PBC_ATTRIBUTE_CATEGORY
5329                  ,p_PBC_ATTRIBUTE1           => l_pbc_rec.PBC_ATTRIBUTE1
5330                  ,p_PBC_ATTRIBUTE2           => l_pbc_rec.PBC_ATTRIBUTE2
5331                  ,p_PBC_ATTRIBUTE3           => l_pbc_rec.PBC_ATTRIBUTE3
5332                  ,p_PBC_ATTRIBUTE4           => l_pbc_rec.PBC_ATTRIBUTE4
5333                  ,p_PBC_ATTRIBUTE5           => l_pbc_rec.PBC_ATTRIBUTE5
5334                  ,p_PBC_ATTRIBUTE6           => l_pbc_rec.PBC_ATTRIBUTE6
5335                  ,p_PBC_ATTRIBUTE7           => l_pbc_rec.PBC_ATTRIBUTE7
5336                  ,p_PBC_ATTRIBUTE8           => l_pbc_rec.PBC_ATTRIBUTE8
5337                  ,p_PBC_ATTRIBUTE9           => l_pbc_rec.PBC_ATTRIBUTE9
5338                  ,p_PBC_ATTRIBUTE10           => l_pbc_rec.PBC_ATTRIBUTE10
5339                  ,p_PBC_ATTRIBUTE11           => l_pbc_rec.PBC_ATTRIBUTE11
5340                  ,p_PBC_ATTRIBUTE12           => l_pbc_rec.PBC_ATTRIBUTE12
5341                  ,p_PBC_ATTRIBUTE13           => l_pbc_rec.PBC_ATTRIBUTE13
5342                  ,p_PBC_ATTRIBUTE14           => l_pbc_rec.PBC_ATTRIBUTE14
5343                  ,p_PBC_ATTRIBUTE15           => l_pbc_rec.PBC_ATTRIBUTE15
5344                  ,p_PBC_ATTRIBUTE16           => l_pbc_rec.PBC_ATTRIBUTE16
5345                  ,p_PBC_ATTRIBUTE17           => l_pbc_rec.PBC_ATTRIBUTE17
5346                  ,p_PBC_ATTRIBUTE18           => l_pbc_rec.PBC_ATTRIBUTE18
5347                  ,p_PBC_ATTRIBUTE19           => l_pbc_rec.PBC_ATTRIBUTE19
5348                  ,p_PBC_ATTRIBUTE20           => l_pbc_rec.PBC_ATTRIBUTE20
5349                  ,p_PBC_ATTRIBUTE21           => l_pbc_rec.PBC_ATTRIBUTE21
5350                  ,p_PBC_ATTRIBUTE22           => l_pbc_rec.PBC_ATTRIBUTE22
5351                  ,p_PBC_ATTRIBUTE23           => l_pbc_rec.PBC_ATTRIBUTE23
5352                  ,p_PBC_ATTRIBUTE24           => l_pbc_rec.PBC_ATTRIBUTE24
5353                  ,p_PBC_ATTRIBUTE25           => l_pbc_rec.PBC_ATTRIBUTE25
5354                  ,p_PBC_ATTRIBUTE26           => l_pbc_rec.PBC_ATTRIBUTE26
5355                  ,p_PBC_ATTRIBUTE27           => l_pbc_rec.PBC_ATTRIBUTE27
5356                  ,p_PBC_ATTRIBUTE28           => l_pbc_rec.PBC_ATTRIBUTE28
5357                  ,p_PBC_ATTRIBUTE29           => l_pbc_rec.PBC_ATTRIBUTE29
5358                  ,p_PBC_ATTRIBUTE30           => l_pbc_rec.PBC_ATTRIBUTE30
5359                  ,p_request_id                => l_pbc_rec.REQUEST_ID
5360                  ,p_program_application_id    => l_pbc_rec.PROGRAM_APPLICATION_ID
5361                  ,p_program_id                => l_pbc_rec.PROGRAM_ID
5362                  ,p_program_update_date       => l_pbc_rec.PROGRAM_UPDATE_DATE
5363                  ,p_OBJECT_VERSION_NUMBER     => l_pbc_rec.OBJECT_VERSION_NUMBER
5364                  ,p_effective_date            => p_effective_date
5365                  ,p_datetrack_mode            => l_datetrack_mode
5366                  );
5367            --
5368         end if;
5369         --
5370       end if;
5371       --
5372       close c_pbc;
5373   end loop;
5374   --
5375   hr_utility.set_location('Leaving ' || l_proc,10);
5376   --
5377 end reinstate_pbc_per_pbn;
5378 --
5379 -- This procedure creates the enrollment beneficiary records for each
5380 -- enrollment linked to backed out per in ler.
5381 --
5382 procedure reinstate_pbn_per_pen(
5383                              p_person_id                in number
5384                             ,p_bckdt_prtt_enrt_rslt_id  in number
5385                             ,p_rslt_object_version_number in number
5386                             ,p_prtt_enrt_rslt_id        in number
5387                             ,p_business_group_id        in number
5388                             ,p_per_in_ler_id            in number
5389                             ,p_effective_date           in date
5390                             ,p_bckdt_per_in_ler_id      in number
5391                            ) is
5392   --
5393   l_proc                    varchar2(72) := g_package||'.reinstate_pbn_per_pen';
5394   --
5395   cursor c_old_bnf is
5396   select
5397           pbn.EFFECTIVE_END_DATE,
5398           pbn.pbn_ATTRIBUTE1,
5399           pbn.pbn_ATTRIBUTE2,
5400           pbn.pbn_ATTRIBUTE3,
5401           pbn.pbn_ATTRIBUTE4,
5402           pbn.pbn_ATTRIBUTE5,
5403           pbn.pbn_ATTRIBUTE6,
5404           pbn.pbn_ATTRIBUTE7,
5405           pbn.pbn_ATTRIBUTE8,
5406           pbn.pbn_ATTRIBUTE9,
5407           pbn.pbn_ATTRIBUTE10,
5408           pbn.pbn_ATTRIBUTE11,
5409           pbn.pbn_ATTRIBUTE12,
5410           pbn.pbn_ATTRIBUTE13,
5411           pbn.pbn_ATTRIBUTE14,
5412           pbn.pbn_ATTRIBUTE15,
5413           pbn.pbn_ATTRIBUTE16,
5414           pbn.pbn_ATTRIBUTE17,
5415           pbn.pbn_ATTRIBUTE18,
5416           pbn.pbn_ATTRIBUTE19,
5417           pbn.pbn_ATTRIBUTE20,
5418           pbn.pbn_ATTRIBUTE21,
5419           pbn.pbn_ATTRIBUTE22,
5420           pbn.pbn_ATTRIBUTE23,
5421           pbn.pbn_ATTRIBUTE24,
5422           pbn.pbn_ATTRIBUTE25,
5423           pbn.pbn_ATTRIBUTE26,
5424           pbn.pbn_ATTRIBUTE27,
5425           pbn.pbn_ATTRIBUTE28,
5426           pbn.pbn_ATTRIBUTE29,
5427           pbn.pbn_ATTRIBUTE30,
5428           pbn.LAST_UPDATE_DATE,
5429           pbn.LAST_UPDATED_BY,
5430           pbn.LAST_UPDATE_LOGIN,
5431           pbn.CREATED_BY,
5432           pbn.CREATION_DATE,
5433           pbn.REQUEST_ID,
5434           pbn.PROGRAM_APPLICATION_ID,
5435           pbn.PROGRAM_ID,
5436           pbn.PROGRAM_UPDATE_DATE,
5437           pbn.OBJECT_VERSION_NUMBER,
5438           pbn.pl_bnf_id,
5439           pbn.EFFECTIVE_START_DATE,
5440           pbn.PRMRY_CNTNGNT_CD,
5441           pbn.PCT_DSGD_NUM,
5442           pbn.AMT_DSGD_VAL,
5443           pbn.AMT_DSGD_UOM,
5444           pbn.ADDL_INSTRN_TXT,
5445           pbn.DSGN_THRU_DT,
5446           pbn.DSGN_STRT_DT,
5447           pbn.PRTT_ENRT_RSLT_ID,
5448           pbn.ORGANIZATION_ID,
5449           pbn.BNF_PERSON_ID,
5450           pbn.TTEE_PERSON_ID,
5451           pbn.BUSINESS_GROUP_ID,
5452           pbn.PER_IN_LER_ID,
5453           pbn.pbn_ATTRIBUTE_CATEGORY,
5454 	  /* Bug 12964358: Check whether there are date track updated records after the effective_start_date*/
5455           decode( (select 'Y' from dual where exists
5456                 (select 'Y' from  ben_pl_bnf_f pbn1
5457 						    where pbn1.per_in_ler_id       = pbn.per_in_ler_id
5458 						      and pbn1.prtt_enrt_rslt_id   = pbn.prtt_enrt_rslt_id
5459 						      and pbn1.business_group_id   = pbn.business_group_id
5460                   and pbn1.effective_start_date > pbn.effective_start_date
5461                   and pbn1.pl_bnf_id = pbn.pl_bnf_id)),
5462                  'Y','Y','N') ftr_rec
5463     from ben_pl_bnf_f pbn
5464     where pbn.per_in_ler_id       = p_bckdt_per_in_ler_id
5465       and pbn.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
5466       and pbn.business_group_id   = p_business_group_id
5467   union
5468   select
5469           pbn.EFFECTIVE_END_DATE,
5470           pbn.LCR_ATTRIBUTE1,
5471           pbn.LCR_ATTRIBUTE2,
5472           pbn.LCR_ATTRIBUTE3,
5473           pbn.LCR_ATTRIBUTE4,
5474           pbn.LCR_ATTRIBUTE5,
5475           pbn.LCR_ATTRIBUTE6,
5476           pbn.LCR_ATTRIBUTE7,
5477           pbn.LCR_ATTRIBUTE8,
5478           pbn.LCR_ATTRIBUTE9,
5479           pbn.LCR_ATTRIBUTE10,
5480           pbn.LCR_ATTRIBUTE11,
5481           pbn.LCR_ATTRIBUTE12,
5482           pbn.LCR_ATTRIBUTE13,
5483           pbn.LCR_ATTRIBUTE14,
5484           pbn.LCR_ATTRIBUTE15,
5485           pbn.LCR_ATTRIBUTE16,
5486           pbn.LCR_ATTRIBUTE17,
5487           pbn.LCR_ATTRIBUTE18,
5488           pbn.LCR_ATTRIBUTE19,
5489           pbn.LCR_ATTRIBUTE20,
5490           pbn.LCR_ATTRIBUTE21,
5491           pbn.LCR_ATTRIBUTE22,
5492           pbn.LCR_ATTRIBUTE23,
5493           pbn.LCR_ATTRIBUTE24,
5494           pbn.LCR_ATTRIBUTE25,
5495           pbn.LCR_ATTRIBUTE26,
5496           pbn.LCR_ATTRIBUTE27,
5497           pbn.LCR_ATTRIBUTE28,
5498           pbn.LCR_ATTRIBUTE29,
5499           pbn.LCR_ATTRIBUTE30,
5500           pbn.LAST_UPDATE_DATE,
5501           pbn.LAST_UPDATED_BY,
5502           pbn.LAST_UPDATE_LOGIN,
5503           pbn.CREATED_BY,
5504           pbn.CREATION_DATE,
5505           pbn.REQUEST_ID,
5506           pbn.PROGRAM_APPLICATION_ID,
5507           pbn.PROGRAM_ID,
5508           pbn.PROGRAM_UPDATE_DATE,
5509           pbn.OBJECT_VERSION_NUMBER,
5510           pbn.BKUP_TBL_ID,
5511           pbn.EFFECTIVE_START_DATE,
5512           pbn.PRMRY_CNTNGNT_CD,
5513           pbn.PCT_DSGD_NUM,
5514           pbn.AMT_DSGD_VAL,
5515           pbn.AMT_DSGD_UOM,
5516           pbn.ADDL_INSTRN_TXT,
5517           pbn.DSGN_THRU_DT,
5518           pbn.DSGN_STRT_DT,
5519           pbn.PRTT_ENRT_RSLT_ID,
5520           pbn.ORGANIZATION_ID,
5521           pbn.BNF_PERSON_ID,
5522           pbn.PERSON_TTEE_ID,
5523           pbn.BUSINESS_GROUP_ID,
5524           pbn.PER_IN_LER_ID,
5525           pbn.LCR_ATTRIBUTE_CATEGORY,
5526 	  /* Bug 12964358: Check whether there are date track updated records after the effective_start_date*/
5527           decode(  (select 'Y' from dual where exists
5528                 (select 'Y' from  ben_le_clsn_n_rstr pbn1
5529 						    where pbn1.per_in_ler_id       = pbn.per_in_ler_id
5530 						      and pbn1.prtt_enrt_rslt_id   = pbn.prtt_enrt_rslt_id
5531 						      and pbn1.business_group_id   = pbn.business_group_id
5532                   and pbn1.effective_start_date > pbn.effective_start_date
5533                   and pbn1.BKUP_TBL_ID = pbn.BKUP_TBL_ID)),
5534                  'Y','Y','N') ftr_rec
5535     from ben_le_clsn_n_rstr pbn
5536    where pbn.prtt_enrt_rslt_id = p_bckdt_prtt_enrt_rslt_id
5537      and pbn.business_group_id = p_business_group_id
5538      and pbn.per_in_ler_id     = p_bckdt_per_in_ler_id
5539      and p_effective_date between pbn.effective_start_date
5540                                and pbn.effective_end_date
5541      and pbn.bkup_tbl_typ_cd = 'BEN_PL_BNF_F'
5542      order by 1;
5543   --
5544   l_old_pl_bnf_id               number(15);
5545   l_pl_bnf_id                   number(15);
5546   l_bnf_effective_start_date    date;
5547   l_bnf_effective_end_date      date;
5548   l_bnf_object_version_number   number(9);
5549   --
5550   cursor c_bnf(cp_bnf_person_id in number) is
5551   select pbn.*
5552     from ben_pl_bnf_f pbn
5553    where pbn.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5554      and pbn.bnf_person_id     = cp_bnf_person_id
5555      and pbn.business_group_id = p_business_group_id
5556     --  and pbn.per_in_ler_id     = p_per_in_ler_id  --BUG Bug 4178570
5557      and p_effective_date between pbn.effective_start_date
5558                               and pbn.effective_end_date;
5559   --
5560   l_bnf_rec c_bnf%rowtype;
5561   l_datetrack_mode             varchar2(80) := null;
5562 
5563   /*  Bug 12964358 */
5564   cursor c_bnf_rec(c_bnf_pl_id number,c_effective_date date) is
5565   select pbn.*
5566     from ben_pl_bnf_f pbn
5567    where pbn.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5568      and pbn.pl_bnf_id     = c_bnf_pl_id
5569      and pbn.business_group_id = p_business_group_id
5570      and c_effective_date between pbn.effective_start_date
5571                               and pbn.effective_end_date;
5572   l_bnf_rec_upd c_bnf_rec%rowtype;
5573   l_upd_obj_version_number number;
5574 
5575   L_DEL_DATE date;
5576   l_creation_date date;
5577   l_upd_mode boolean;
5578   l_upd_date date;
5579   --
5580 begin
5581   --
5582   hr_utility.set_location('Entering ' || l_proc,10);
5583   l_upd_mode := false;
5584   --
5585   for l_old_bnf_rec in c_old_bnf loop
5586       --
5587       hr_utility.set_location('l_old_bnf_rec.effective_end_date ' || l_old_bnf_rec.effective_end_date,10);
5588       hr_utility.set_location('l_old_bnf_rec.effective_start_date ' || l_old_bnf_rec.effective_start_date,10);
5589       hr_utility.set_location('l_old_bnf_rec.ftr_rec ' || l_old_bnf_rec.ftr_rec,10);
5590 
5591       open c_bnf(l_old_bnf_rec.bnf_person_id);
5592       fetch c_bnf into l_bnf_rec;
5593       if c_bnf%notfound then
5594         --
5595         hr_utility.set_location('In create call ' || l_proc,10);
5596         ben_plan_beneficiary_api.create_plan_beneficiary
5597           (p_validate                => FALSE
5598           ,p_pl_bnf_id               => l_pl_bnf_id
5599           ,p_effective_start_date    => l_bnf_effective_start_date
5600           ,p_effective_end_date      => l_bnf_effective_end_date
5601           ,p_business_group_id       => p_business_group_id
5602           ,p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id
5603           ,p_bnf_person_id           => l_old_bnf_rec.bnf_person_id
5604           ,p_organization_id         => l_old_bnf_rec.organization_id
5605           ,p_ttee_person_id          => l_old_bnf_rec.ttee_person_id
5606           ,p_prmry_cntngnt_cd        => l_old_bnf_rec.prmry_cntngnt_cd
5607           ,p_pct_dsgd_num            => l_old_bnf_rec.pct_dsgd_num
5608           ,p_amt_dsgd_val            => l_old_bnf_rec.amt_dsgd_val
5609           ,p_amt_dsgd_uom            => l_old_bnf_rec.amt_dsgd_uom
5610           ,p_addl_instrn_txt         => l_old_bnf_rec.addl_instrn_txt
5611           ,p_per_in_ler_id           => p_per_in_ler_id
5612           ,p_pbn_attribute_category  => l_old_bnf_rec.pbn_attribute_category
5613           ,p_pbn_attribute1          => l_old_bnf_rec.pbn_attribute1
5614           ,p_pbn_attribute2          => l_old_bnf_rec.pbn_attribute2
5615           ,p_pbn_attribute3          => l_old_bnf_rec.pbn_attribute3
5616           ,p_pbn_attribute4          => l_old_bnf_rec.pbn_attribute4
5617           ,p_pbn_attribute5          => l_old_bnf_rec.pbn_attribute5
5618           ,p_pbn_attribute6          => l_old_bnf_rec.pbn_attribute6
5619           ,p_pbn_attribute7          => l_old_bnf_rec.pbn_attribute7
5620           ,p_pbn_attribute8          => l_old_bnf_rec.pbn_attribute8
5621           ,p_pbn_attribute9          => l_old_bnf_rec.pbn_attribute9
5622           ,p_pbn_attribute10         => l_old_bnf_rec.pbn_attribute10
5623           ,p_pbn_attribute11         => l_old_bnf_rec.pbn_attribute11
5624           ,p_pbn_attribute12         => l_old_bnf_rec.pbn_attribute12
5625           ,p_pbn_attribute13         => l_old_bnf_rec.pbn_attribute13
5626           ,p_pbn_attribute14         => l_old_bnf_rec.pbn_attribute14
5627           ,p_pbn_attribute15         => l_old_bnf_rec.pbn_attribute15
5628           ,p_pbn_attribute16         => l_old_bnf_rec.pbn_attribute16
5629           ,p_pbn_attribute17         => l_old_bnf_rec.pbn_attribute17
5630           ,p_pbn_attribute18         => l_old_bnf_rec.pbn_attribute18
5631           ,p_pbn_attribute19         => l_old_bnf_rec.pbn_attribute19
5632           ,p_pbn_attribute20         => l_old_bnf_rec.pbn_attribute20
5633           ,p_pbn_attribute21         => l_old_bnf_rec.pbn_attribute21
5634           ,p_pbn_attribute22         => l_old_bnf_rec.pbn_attribute22
5635           ,p_pbn_attribute23         => l_old_bnf_rec.pbn_attribute23
5636           ,p_pbn_attribute24         => l_old_bnf_rec.pbn_attribute24
5637           ,p_pbn_attribute25         => l_old_bnf_rec.pbn_attribute25
5638           ,p_pbn_attribute26         => l_old_bnf_rec.pbn_attribute26
5639           ,p_pbn_attribute27         => l_old_bnf_rec.pbn_attribute27
5640           ,p_pbn_attribute28         => l_old_bnf_rec.pbn_attribute28
5641           ,p_pbn_attribute29         => l_old_bnf_rec.pbn_attribute29
5642           ,p_pbn_attribute30         => l_old_bnf_rec.pbn_attribute30
5643           ,p_request_id              => fnd_global.conc_request_id
5644           ,p_program_application_id  => fnd_global.prog_appl_id
5645           ,p_program_id              => fnd_global.conc_program_id
5646           ,p_program_update_date     => sysdate
5647           ,p_object_version_number   => l_bnf_object_version_number
5648           ,p_multi_row_actn          => FALSE --TRUE                        -- bug  2552295
5649           ,p_effective_date          => p_effective_date
5650           ,p_dsgn_thru_dt            => l_old_bnf_rec.dsgn_thru_dt
5651           ,p_dsgn_strt_dt            => l_old_bnf_rec.dsgn_strt_dt);
5652 
5653           hr_utility.set_location('In create call ' || l_bnf_effective_start_date,10);
5654           hr_utility.set_location('In create call ' || l_bnf_effective_end_date,10);
5655 
5656            /*Bug 12964358: Set the flag l_upd_mode to true if history is to reinstated on reprocessing the LE */
5657            if(l_upd_mode = false and
5658                   l_old_bnf_rec.effective_start_date = l_bnf_effective_start_date) then
5659                 l_upd_mode := true;
5660            end if;
5661 
5662           /* Bug 12791126: While reinstating the plan beneficiary, if the beneficiary record is end dated,
5663               then after creating the beneficiary record, record should be end dated. Added 'if' condition */
5664            if(l_old_bnf_rec.effective_end_date <> hr_api.g_eot and l_old_bnf_rec.ftr_rec = 'N') then
5665                  if(l_old_bnf_rec.effective_start_date = l_bnf_effective_start_date ) then
5666                      l_del_date :=l_old_bnf_rec.effective_end_date;
5667                  else
5668                      l_del_date :=l_bnf_effective_start_date;
5669                  end if;
5670                hr_utility.set_location('In delete call create' || l_bnf_effective_end_date,10);
5671                ben_plan_beneficiary_api.delete_PLAN_BENEFICIARY
5672 				(p_validate   => false
5673 				,p_pl_bnf_id    => l_pl_bnf_id
5674 				,p_effective_start_date  => l_bnf_effective_start_date
5675 				,p_effective_end_date   => l_bnf_effective_end_date
5676 				,p_object_version_number  => l_bnf_object_version_number
5677 				,p_business_group_id   => p_business_group_id
5678 				,p_effective_date     => l_del_date+1
5679 				 ,p_datetrack_mode     => hr_api.g_delete
5680 				,p_multi_row_actn   => FALSE
5681 			 );
5682           end if;
5683         --
5684       else
5685         --
5686           hr_utility.set_location('p_effective_date ' || p_effective_date,10);
5687           hr_utility.set_location('l_bnf_rec.effective_start_date ' || l_bnf_rec.effective_start_date,10);
5688           hr_utility.set_location('l_bnf_rec.effective_end_date ' || l_bnf_rec.effective_end_date,10);
5689         if p_effective_date = l_bnf_rec.effective_start_date or
5690            p_effective_date = l_bnf_rec.effective_end_date then
5691 	   /*Bug 12964358: Reinstate the plan beneficiary history on reprocessing the LE.If elections are reinstated
5692 	   as of sysdate, then update mode will be 'update' else 'correction' . Flag  l_upd_mode is set based upon the date on which
5693 	   plan beneficiary is reinstated. Also end dated beneficiary should be reinstated correctly on reprocessing the LE. Added below 'if'  */
5694            if(l_upd_mode) then
5695                l_datetrack_mode := hr_api.g_update;
5696                l_upd_date := l_old_bnf_rec.effective_start_date;
5697                 open c_bnf_rec(l_bnf_rec.pl_bnf_id,l_upd_date);
5698                 fetch c_bnf_rec into l_bnf_rec_upd;
5699                 if(c_bnf_rec%notfound) then
5700                    l_upd_obj_version_number := l_bnf_rec.object_version_number;
5701                 else
5702                    l_upd_obj_version_number := l_bnf_rec_upd.object_version_number;
5703                 end if;
5704                 close c_bnf_rec;
5705            /*End of Bug 12964358 */
5706            else
5707               l_datetrack_mode := hr_api.g_correction;
5708               l_upd_date := p_effective_date;
5709               l_upd_obj_version_number := l_bnf_rec.object_version_number;
5710            end if;
5711         else
5712            l_upd_date := p_effective_date;--Bug 16059081
5713            l_upd_obj_version_number := l_bnf_rec.object_version_number;
5714            l_datetrack_mode := hr_api.g_update;
5715         end if;
5716         --
5717         hr_utility.set_location('update call ' ,10);
5718         ben_plan_beneficiary_api.update_PLAN_BENEFICIARY
5719           (p_validate                       => FALSE
5720           ,p_pl_bnf_id                      => l_bnf_rec.pl_bnf_id
5721           ,p_effective_start_date           => l_bnf_effective_start_date
5722           ,p_effective_end_date             => l_bnf_effective_end_date
5723           ,p_business_group_id              => p_business_group_id
5724           ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
5725           ,p_bnf_person_id                  => l_old_bnf_rec.bnf_person_id
5726           ,p_organization_id                => l_old_bnf_rec.organization_id
5727           ,p_ttee_person_id                 => l_old_bnf_rec.ttee_person_id
5728           ,p_prmry_cntngnt_cd               => l_old_bnf_rec.prmry_cntngnt_cd
5729           ,p_pct_dsgd_num                   => l_old_bnf_rec.pct_dsgd_num
5730           ,p_amt_dsgd_val                   => l_old_bnf_rec.amt_dsgd_val
5731           ,p_amt_dsgd_uom                   => l_old_bnf_rec.amt_dsgd_uom
5732           ,p_dsgn_strt_dt                   => l_old_bnf_rec.dsgn_strt_dt
5733           ,p_dsgn_thru_dt                   => l_old_bnf_rec.dsgn_thru_dt
5734           ,p_addl_instrn_txt                => l_old_bnf_rec.addl_instrn_txt
5735           ,p_pbn_attribute_category         => l_old_bnf_rec.pbn_attribute_category
5736           ,p_pbn_attribute1                 => l_old_bnf_rec.pbn_attribute1
5737           ,p_pbn_attribute2                 => l_old_bnf_rec.pbn_attribute2
5738           ,p_pbn_attribute3                 => l_old_bnf_rec.pbn_attribute3
5739           ,p_pbn_attribute4                 => l_old_bnf_rec.pbn_attribute4
5740           ,p_pbn_attribute5                 => l_old_bnf_rec.pbn_attribute5
5741           ,p_pbn_attribute6                 => l_old_bnf_rec.pbn_attribute6
5742           ,p_pbn_attribute7                 => l_old_bnf_rec.pbn_attribute7
5743           ,p_pbn_attribute8                 => l_old_bnf_rec.pbn_attribute8
5744           ,p_pbn_attribute9                 => l_old_bnf_rec.pbn_attribute9
5745           ,p_pbn_attribute10                => l_old_bnf_rec.pbn_attribute10
5746           ,p_pbn_attribute11                => l_old_bnf_rec.pbn_attribute11
5747           ,p_pbn_attribute12                => l_old_bnf_rec.pbn_attribute12
5748           ,p_pbn_attribute13                => l_old_bnf_rec.pbn_attribute13
5749           ,p_pbn_attribute14                => l_old_bnf_rec.pbn_attribute14
5750           ,p_pbn_attribute15                => l_old_bnf_rec.pbn_attribute15
5751           ,p_pbn_attribute16                => l_old_bnf_rec.pbn_attribute16
5752           ,p_pbn_attribute17                => l_old_bnf_rec.pbn_attribute17
5753           ,p_pbn_attribute18                => l_old_bnf_rec.pbn_attribute18
5754           ,p_pbn_attribute19                => l_old_bnf_rec.pbn_attribute19
5755           ,p_pbn_attribute20                => l_old_bnf_rec.pbn_attribute20
5756           ,p_pbn_attribute21                => l_old_bnf_rec.pbn_attribute21
5757           ,p_pbn_attribute22                => l_old_bnf_rec.pbn_attribute22
5758           ,p_pbn_attribute23                => l_old_bnf_rec.pbn_attribute23
5759           ,p_pbn_attribute24                => l_old_bnf_rec.pbn_attribute24
5760           ,p_pbn_attribute25                => l_old_bnf_rec.pbn_attribute25
5761           ,p_pbn_attribute26                => l_old_bnf_rec.pbn_attribute26
5762           ,p_pbn_attribute27                => l_old_bnf_rec.pbn_attribute27
5763           ,p_pbn_attribute28                => l_old_bnf_rec.pbn_attribute28
5764           ,p_pbn_attribute29                => l_old_bnf_rec.pbn_attribute29
5765           ,p_pbn_attribute30                => l_old_bnf_rec.pbn_attribute30
5766           ,p_request_id                     => fnd_global.conc_request_id
5767           ,p_program_application_id         => fnd_global.prog_appl_id
5768           ,p_program_id                     => fnd_global.conc_program_id
5769           ,p_program_update_date            => sysdate
5770           ,p_object_version_number          => l_upd_obj_version_number
5771           ,p_per_in_ler_id                  => p_per_in_ler_id
5772           ,p_effective_date                 => l_upd_date
5773           ,p_datetrack_mode                 => l_datetrack_mode
5774           ,p_multi_row_actn                 => FALSE -- TRUE    -- bug 2552295
5775           );
5776         --
5777         l_pl_bnf_id := l_bnf_rec.pl_bnf_id;
5778 
5779         /*Bug 12964358: Beneficiary that are end dated should be end dated on reprocessing the LE*/
5780         if(l_old_bnf_rec.effective_end_date <> hr_api.g_eot and l_old_bnf_rec.ftr_rec = 'N') then
5781                  if(l_old_bnf_rec.effective_start_date = l_bnf_effective_start_date ) then
5782                      l_del_date :=l_old_bnf_rec.effective_end_date;
5783                  else
5784                      l_del_date :=l_bnf_effective_start_date;
5785                  end if;
5786                l_bnf_object_version_number := l_upd_obj_version_number;
5787                hr_utility.set_location('In delete call upd' || l_bnf_effective_end_date,10);
5788                ben_plan_beneficiary_api.delete_PLAN_BENEFICIARY
5789 					(p_validate   => false
5790 					,p_pl_bnf_id    => l_pl_bnf_id
5791 					,p_effective_start_date  => l_bnf_effective_start_date
5792 					,p_effective_end_date   => l_bnf_effective_end_date
5793 					,p_object_version_number  => l_upd_obj_version_number
5794 					,p_business_group_id   => p_business_group_id
5795 					,p_effective_date     => l_del_date+1
5796 					 ,p_datetrack_mode     => hr_api.g_delete
5797 					,p_multi_row_actn   => FALSE
5798 				 );
5799           end if;
5800         --
5801         -- Reinstate the certifications.
5802         --
5803         reinstate_pbc_per_pbn(
5804                  p_person_id                => p_person_id
5805                 ,p_bckdt_prtt_enrt_rslt_id  => p_bckdt_prtt_enrt_rslt_id
5806                 ,p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id
5807                 ,p_business_group_id        => p_business_group_id
5808                 ,p_per_in_ler_id            => p_per_in_ler_id
5809                 ,p_effective_date           => p_effective_date
5810                 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
5811                 ,p_pl_bnf_id                => l_pl_bnf_id
5812                 ,p_old_pl_bnf_id            => l_old_bnf_rec.pl_bnf_id
5813                 );
5814       end if;
5815       --
5816       --
5817       -- maybe a table having all pl_bnf_id needs to put reinstate_pea_per_pen
5818       -- outside loop;
5819       --
5820       -- Reinstate the action items.
5821       --
5822 
5823       -- May not be necessary as plan beneficiary certifications are
5824       -- reinstated.
5825       --
5826 
5827       -- bug  2552295 uncommented the code to reinstate the action items
5828          reinstate_pea_per_pen(
5829                  p_person_id                => p_person_id
5830                 ,p_bckdt_prtt_enrt_rslt_id  => p_bckdt_prtt_enrt_rslt_id
5831                 ,p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id
5832                 ,p_rslt_object_version_number => p_rslt_object_version_number
5833                 ,p_business_group_id        => p_business_group_id
5834                 ,p_per_in_ler_id            => p_per_in_ler_id
5835                 ,p_effective_date           => p_effective_date
5836                 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
5837                 ,p_pl_bnf_id                => l_pl_bnf_id
5838                 ,p_old_pl_bnf_id            => l_old_bnf_rec.pl_bnf_id
5839                 );
5840       -- end bug 2552295
5841       close c_bnf;
5842   end loop;
5843   --
5844   --We need to add the call to process_bnf_actn_items which will
5845   hr_utility.set_location('Leaving ' || l_proc,10);
5846 
5847   --
5848 end reinstate_pbn_per_pen;
5849 --
5850 procedure reinstate_pcs_per_pen(
5851                              p_person_id                in number
5852                             ,p_bckdt_prtt_enrt_rslt_id  in number
5853                             ,p_prtt_enrt_rslt_id        in number
5854                             ,p_rslt_object_version_number in number
5855                             ,p_business_group_id        in number
5856                             ,p_prtt_enrt_actn_id        in number
5857                             ,p_effective_date           in date
5858                             ,p_bckdt_prtt_enrt_actn_id  in number
5859                             ,p_per_in_ler_id            in number
5860                             ,p_bckdt_per_in_ler_id      in number
5861                            ) is
5862   --
5863   l_proc                    varchar2(72) := g_package || '.reinstate_pcs_per_pen';
5864   --
5865   cursor c_old_pcs is
5866   select pcs.*, pea.ACTN_TYP_ID
5867     from ben_prtt_enrt_ctfn_prvdd_f pcs,
5868          ben_prtt_enrt_actn_f pea
5869     where pcs.prtt_enrt_actn_id   = pea.prtt_enrt_actn_id
5870       and pcs.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
5871       and pea.per_in_ler_id       = p_bckdt_per_in_ler_id
5872       and pea.prtt_enrt_rslt_id   = pcs.prtt_enrt_rslt_id
5873       and pcs.business_group_id   = p_business_group_id
5874       and p_effective_date between pcs.effective_start_date
5875                                and pcs.effective_end_date
5876       and p_effective_date between pea.effective_start_date
5877                                and pea.effective_end_date
5878    /* Bug 8910111: While reinstating the certifications, if the certification records
5879       are end dated by the next life event, then as on p_effective_date cursor will not fetch any records.
5880       Added union condition to get the latest certification  record(if records exists in update mode) while
5881       reinstating the certification record.*/
5882    union
5883    select pcs.*, pea.ACTN_TYP_ID
5884     from ben_prtt_enrt_ctfn_prvdd_f pcs,
5885          ben_prtt_enrt_actn_f pea
5886     where pcs.prtt_enrt_actn_id   = pea.prtt_enrt_actn_id
5887       and pcs.prtt_enrt_rslt_id   = p_bckdt_prtt_enrt_rslt_id
5888       and pea.per_in_ler_id       = p_bckdt_per_in_ler_id
5889       and pea.prtt_enrt_rslt_id   = pcs.prtt_enrt_rslt_id
5890       and pcs.business_group_id   = p_business_group_id
5891       and pea.effective_start_date = (select max(effective_start_date) from ben_prtt_enrt_actn_f pea1
5892                                       where pea1.per_in_ler_id = pea.per_in_ler_id
5893                                       and pea1.prtt_enrt_rslt_id = pea.prtt_enrt_rslt_id
5894                                       and pea1.prtt_enrt_actn_id = pea.prtt_enrt_actn_id)
5895       and pcs.effective_start_date = (select max(effective_start_date)  from ben_prtt_enrt_ctfn_prvdd_f pcs1
5896                                      where pcs1.prtt_enrt_rslt_id = pcs.prtt_enrt_rslt_id
5897                                       and pcs1.prtt_enrt_actn_id = pcs.prtt_enrt_actn_id);
5898   --
5899   l_pcs_effective_start_date    date;
5900   l_pcs_effective_end_date      date;
5901   l_pcs_object_version_number   number(9);
5902   --
5903   cursor c_pcs(cp_enrt_ctfn_typ_cd in varchar2,
5904                cp_ENRT_R_BNFT_CTFN_CD in varchar2,
5905                cp_ACTN_TYP_ID in varchar2) is
5906   select pcs.*
5907     from ben_prtt_enrt_ctfn_prvdd_f pcs,
5908          ben_prtt_enrt_actn_f pea
5909    where pcs.prtt_enrt_rslt_id          = p_prtt_enrt_rslt_id
5910      and nvl(pcs.enrt_ctfn_typ_cd, -1)  = nvl(cp_enrt_ctfn_typ_cd, -1)
5911      and nvl(pcs.enrt_r_bnft_ctfn_cd, -1)  = nvl(cp_enrt_r_bnft_ctfn_cd, -1)
5912      and pea.prtt_enrt_rslt_id   = pcs.prtt_enrt_rslt_id
5913      and pea.ACTN_TYP_ID         = cp_ACTN_TYP_ID
5914      and pcs.business_group_id   = p_business_group_id
5915      and pcs.prtt_enrt_actn_id   = pea.prtt_enrt_actn_id
5916      and pea.per_in_ler_id       = p_per_in_ler_id
5917      and p_effective_date between pcs.effective_start_date
5918                         and pcs.effective_end_date
5919      and p_effective_date between pea.effective_start_date
5920                         and pea.effective_end_date;
5921   --
5922   l_pcs_rec               c_pcs%rowtype;
5923   l_datetrack_mode        varchar2(80) := null;
5924   --
5925 begin
5926   --
5927   hr_utility.set_location('Entering ' || l_proc,10);
5928   --
5929   for l_old_pcs_rec in c_old_pcs loop
5930       --
5931       open c_pcs(l_old_pcs_rec.enrt_ctfn_typ_cd,
5932                  l_old_pcs_rec.ENRT_R_BNFT_CTFN_CD,
5933                  l_old_pcs_rec.ACTN_TYP_ID);
5934       fetch c_pcs into l_pcs_rec;
5935       if c_pcs%found then
5936         --
5937         if nvl(l_old_pcs_rec.ENRT_CTFN_RECD_DT, hr_api.g_eot) <>
5938            nvl(l_pcs_rec.ENRT_CTFN_RECD_DT, hr_api.g_eot) or
5939            nvl(l_old_pcs_rec.ENRT_CTFN_DND_DT, hr_api.g_eot) <>
5940            nvl(l_pcs_rec.ENRT_CTFN_DND_DT, hr_api.g_eot)
5941         then
5942            --
5943            -- Use the correction mode.
5944            l_datetrack_mode := hr_api.g_correction;
5945            --
5946            -- update the action items.
5947            --
5948            -- If completion date is > p_effective_date .
5949            --
5950            --
5951            /* BUG 4558512
5952            if l_old_pcs_rec.ENRT_CTFN_RECD_DT < p_effective_date then
5953               l_old_pcs_rec.ENRT_CTFN_RECD_DT := p_effective_date;
5954            end if;
5955            --
5956            if l_old_pcs_rec.ENRT_CTFN_DND_DT < p_effective_date then
5957               l_old_pcs_rec.ENRT_CTFN_DND_DT := p_effective_date;
5958            end if;
5959            */
5960            --
5961            BEN_prtt_enrt_ctfn_prvdd_API.update_prtt_enrt_ctfn_prvdd (
5962                p_prtt_enrt_ctfn_prvdd_id => l_pcs_rec.PRTT_ENRT_CTFN_PRVDD_ID
5963                ,p_prtt_enrt_actn_id       => l_pcs_rec.prtt_enrt_actn_id
5964                ,p_prtt_enrt_rslt_id       => l_pcs_rec.prtt_enrt_rslt_id
5965                ,p_business_group_id       => p_business_group_id
5966                ,p_EFFECTIVE_START_DATE    => l_pcs_EFFECTIVE_START_DATE
5967                ,p_EFFECTIVE_END_DATE      => l_pcs_EFFECTIVE_END_DATE
5968                ,p_ENRT_CTFN_RECD_DT       => l_old_pcs_rec.ENRT_CTFN_RECD_DT
5969                ,p_ENRT_CTFN_DND_DT        => l_old_pcs_rec.ENRT_CTFN_DND_DT
5970                ,p_OBJECT_VERSION_NUMBER   => l_pcs_rec.OBJECT_VERSION_NUMBER
5971                ,p_effective_date          => p_effective_date
5972                ,p_datetrack_mode          => l_datetrack_mode
5973            );
5974            --
5975            --
5976         end if;
5977         --
5978       end if;
5979       --
5980       close c_pcs;
5981   end loop;
5982   --
5983   hr_utility.set_location('Leaving ' || l_proc,10);
5984   --
5985 end reinstate_pcs_per_pen;
5986 --
5987 -- This procedure creates the enrollment results based on what participant
5988 -- enrolled as of the backed out per in ler.
5989 --
5990 procedure reinstate_the_prev_enrt(
5991                              p_person_id            in number
5992                             ,p_business_group_id   in number
5993                             ,p_ler_id              in number
5994                             ,p_effective_date      in date
5995                             ,p_per_in_ler_id       in number
5996                             ,p_bckdt_per_in_ler_id in number
5997                             ,p_bckdt_pil_prev_stat_cd in varchar2 default null
5998                            ) is
5999   --
6000   l_proc                    varchar2(72) := g_package||'.reinstate_the_prev_enrt';
6001   --
6002   cursor c_bckdt_pil is
6003     select pil.PRVS_STAT_CD, pil.object_version_number, pil.BCKT_PER_IN_LER_ID
6004     from ben_per_in_ler pil
6005     where pil.per_in_ler_id = p_bckdt_per_in_ler_id
6006       and pil.business_group_id = p_business_group_id;
6007   --
6008   l_bckt_csd_per_in_ler_id  number;
6009   l_bckdt_pil_prev_stat_cd  varchar2(80);
6010   l_bckdt_pil_ovn           number;
6011   l_date                    date;
6012   l_procd_dt                date;
6013   l_strtd_dt                date;
6014   l_voidd_dt                date;
6015 
6016   --
6017   -- Get the enrollment results from the backup table for backed out pil.
6018   --
6019   cursor c_bckdt_pen is
6020    select
6021           pen.EFFECTIVE_END_DATE,
6022           pen.ASSIGNMENT_ID,
6023           pen.BNFT_AMT,
6024           pen.BNFT_NNMNTRY_UOM,
6025           pen.BNFT_ORDR_NUM,
6026           pen.BNFT_TYP_CD,
6027           pen.BUSINESS_GROUP_ID,
6028           pen.COMP_LVL_CD,
6029           pen.CREATED_BY,
6030           pen.CREATION_DATE,
6031           pen.EFFECTIVE_START_DATE,
6032           pen.ENRT_CVG_STRT_DT,
6033           pen.ENRT_CVG_THRU_DT,
6034           pen.ENRT_MTHD_CD,
6035           pen.ENRT_OVRIDN_FLAG,
6036           pen.ENRT_OVRID_RSN_CD,
6037           pen.ENRT_OVRID_THRU_DT,
6038           pen.ERLST_DEENRT_DT,
6039           pen.LAST_UPDATED_BY,
6040           pen.LAST_UPDATE_DATE,
6041           pen.LAST_UPDATE_LOGIN,
6042           pen.LER_ID,
6043           pen.NO_LNGR_ELIG_FLAG,
6044           pen.OBJECT_VERSION_NUMBER,
6045           pen.OIPL_ID,
6046           pen.OIPL_ORDR_NUM,
6047           pen.ORGNL_ENRT_DT,
6048           pen.PEN_ATTRIBUTE1,
6049           pen.PEN_ATTRIBUTE10,
6050           pen.PEN_ATTRIBUTE11,
6051           pen.PEN_ATTRIBUTE12,
6052           pen.PEN_ATTRIBUTE13,
6053           pen.PEN_ATTRIBUTE14,
6054           pen.PEN_ATTRIBUTE15,
6055           pen.PEN_ATTRIBUTE16,
6056           pen.PEN_ATTRIBUTE17,
6057           pen.PEN_ATTRIBUTE18,
6058           pen.PEN_ATTRIBUTE19,
6059           pen.PEN_ATTRIBUTE2,
6060           pen.PEN_ATTRIBUTE20,
6061           pen.PEN_ATTRIBUTE21,
6062           pen.PEN_ATTRIBUTE22,
6063           pen.PEN_ATTRIBUTE23,
6064           pen.PEN_ATTRIBUTE24,
6065           pen.PEN_ATTRIBUTE25,
6066           pen.PEN_ATTRIBUTE26,
6067           pen.PEN_ATTRIBUTE27,
6068           pen.PEN_ATTRIBUTE28,
6069           pen.PEN_ATTRIBUTE29,
6070           pen.PEN_ATTRIBUTE3,
6071           pen.PEN_ATTRIBUTE30,
6072           pen.PEN_ATTRIBUTE4,
6073           pen.PEN_ATTRIBUTE5,
6074           pen.PEN_ATTRIBUTE6,
6075           pen.PEN_ATTRIBUTE7,
6076           pen.PEN_ATTRIBUTE8,
6077           pen.PEN_ATTRIBUTE9,
6078           pen.PEN_ATTRIBUTE_CATEGORY,
6079           pen.PERSON_ID,
6080           pen.PER_IN_LER_ID,
6081           pen.PGM_ID,
6082           pen.PLIP_ORDR_NUM,
6083           pen.PL_ID,
6084           pen.PL_ORDR_NUM,
6085           pen.PL_TYP_ID,
6086           pen.PROGRAM_APPLICATION_ID,
6087           pen.PROGRAM_ID,
6088           pen.PROGRAM_UPDATE_DATE,
6089           pen.PRTT_ENRT_RSLT_ID,
6090           pen.PRTT_ENRT_RSLT_STAT_CD,
6091           pen.PRTT_IS_CVRD_FLAG,
6092           pen.PTIP_ID,
6093           pen.PTIP_ORDR_NUM,
6094           pen.REQUEST_ID,
6095           pen.RPLCS_SSPNDD_RSLT_ID,
6096           pen.SSPNDD_FLAG,
6097           pen.UOM
6098     from   ben_prtt_enrt_rslt_f pen,
6099            ben_per_in_ler pil
6100     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
6101     and    pil.person_id           = p_person_id
6102     and    pil.business_group_id = p_business_group_id
6103     and    pil.per_in_ler_id       = pen.per_in_ler_id
6104            /*Pick up both end-dated and non-end-dated results*/
6105     and    (pen.effective_end_date = hr_api.g_eot or
6106             pen.effective_end_date = (select max(effective_end_date)
6107                                         from ben_prtt_enrt_rslt_f
6108                                        where prtt_enrt_rslt_id =
6109                                                          pen.prtt_enrt_rslt_id))
6110     and    (pen.enrt_cvg_thru_dt is null or
6111             pen.enrt_cvg_thru_dt    = hr_api.g_eot
6112            )
6113     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6114     and pen.prtt_enrt_rslt_id not in (
6115          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
6116            from   ben_prtt_enrt_rslt_f pen_inner,
6117                   ben_per_in_ler pil_inner
6118            where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
6119            and    pil_inner.person_id           = p_person_id
6120            and    pil_inner.business_group_id = p_business_group_id
6121            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
6122            and    (pen_inner.enrt_cvg_thru_dt is null or
6123                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
6124                   )
6125            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6126          union
6127          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
6128              from  ben_le_clsn_n_rstr  pen_inner,
6129                     ben_per_in_ler pil_inner
6130              where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
6131              and    pil_inner.person_id           = p_person_id
6132              and    pil_inner.business_group_id   = p_business_group_id
6133              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
6134              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
6135            and    (pen_inner.enrt_cvg_thru_dt is null or
6136                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
6137                   )
6138            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6139        )
6140    union
6141    select
6142           pen.EFFECTIVE_END_DATE,
6143           pen.ASSIGNMENT_ID,
6144           pen.BNFT_AMT,
6145           pen.BNFT_NNMNTRY_UOM,
6146           pen.BNFT_ORDR_NUM,
6147           pen.BNFT_TYP_CD,
6148           pen.BUSINESS_GROUP_ID,
6149           pen.COMP_LVL_CD,
6150           pen.CREATED_BY,
6151           pen.CREATION_DATE,
6152           pen.EFFECTIVE_START_DATE,
6153           pen.ENRT_CVG_STRT_DT,
6154           pen.ENRT_CVG_THRU_DT,
6155           pen.ENRT_MTHD_CD,
6156           pen.ENRT_OVRIDN_FLAG,
6157           pen.ENRT_OVRID_RSN_CD,
6158           pen.ENRT_OVRID_THRU_DT,
6159           pen.ERLST_DEENRT_DT,
6160           pen.LAST_UPDATED_BY,
6161           pen.LAST_UPDATE_DATE,
6162           pen.LAST_UPDATE_LOGIN,
6163           pen.LER_ID,
6164           pen.NO_LNGR_ELIG_FLAG,
6165           pen.OBJECT_VERSION_NUMBER,
6166           pen.OIPL_ID,
6167           pen.OIPL_ORDR_NUM,
6168           pen.ORGNL_ENRT_DT,
6169           pen.LCR_ATTRIBUTE1,
6170           pen.LCR_ATTRIBUTE10,
6171           pen.LCR_ATTRIBUTE11,
6172           pen.LCR_ATTRIBUTE12,
6173           pen.LCR_ATTRIBUTE13,
6174           pen.LCR_ATTRIBUTE14,
6175           pen.LCR_ATTRIBUTE15,
6176           pen.LCR_ATTRIBUTE16,
6177           pen.LCR_ATTRIBUTE17,
6178           pen.LCR_ATTRIBUTE18,
6179           pen.LCR_ATTRIBUTE19,
6180           pen.LCR_ATTRIBUTE2,
6181           pen.LCR_ATTRIBUTE20,
6182           pen.LCR_ATTRIBUTE21,
6183           pen.LCR_ATTRIBUTE22,
6184           pen.LCR_ATTRIBUTE23,
6185           pen.LCR_ATTRIBUTE24,
6186           pen.LCR_ATTRIBUTE25,
6187           pen.LCR_ATTRIBUTE26,
6188           pen.LCR_ATTRIBUTE27,
6189           pen.LCR_ATTRIBUTE28,
6190           pen.LCR_ATTRIBUTE29,
6191           pen.LCR_ATTRIBUTE3,
6192           pen.LCR_ATTRIBUTE30,
6193           pen.LCR_ATTRIBUTE4,
6194           pen.LCR_ATTRIBUTE5,
6195           pen.LCR_ATTRIBUTE6,
6196           pen.LCR_ATTRIBUTE7,
6197           pen.LCR_ATTRIBUTE8,
6198           pen.LCR_ATTRIBUTE9,
6199           pen.LCR_ATTRIBUTE_CATEGORY,
6200           pen.PERSON_ID,
6201           pen.PER_IN_LER_ID,
6202           pen.PGM_ID,
6203           pen.PLIP_ORDR_NUM,
6204           pen.PL_ID,
6205           pen.PL_ORDR_NUM,
6206           pen.PL_TYP_ID,
6207           pen.PROGRAM_APPLICATION_ID,
6208           pen.PROGRAM_ID,
6209           pen.PROGRAM_UPDATE_DATE,
6210           pen.bkup_tbl_id, -- Mapped to PRTT_ENRT_RSLT_ID,
6211           pen.PRTT_ENRT_RSLT_STAT_CD,
6212           pen.PRTT_IS_CVRD_FLAG,
6213           pen.PTIP_ID,
6214           pen.PTIP_ORDR_NUM,
6215           pen.REQUEST_ID,
6216           pen.RPLCS_SSPNDD_RSLT_ID,
6217           pen.SSPNDD_FLAG,
6218           pen.UOM
6219     from  ben_le_clsn_n_rstr  pen,
6220            ben_per_in_ler pil
6221     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
6222     and    pil.person_id           = p_person_id
6223     and    pil.business_group_id   = p_business_group_id
6224     AND    pil.per_in_ler_id       = pen.per_in_ler_id
6225     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
6226     and    ((pen.enrt_cvg_thru_dt is null or
6227             pen.enrt_cvg_thru_dt    = hr_api.g_eot)  and
6228 --bug#2604375 - added to control updated result rows for the same per_in_ler
6229             pen.effective_end_date  = hr_api.g_eot
6230            )
6231     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6232     and pen.bkup_tbl_id not in (
6233          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
6234            from   ben_prtt_enrt_rslt_f pen_inner,
6235                   ben_per_in_ler pil_inner
6236            where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
6237            and    pil_inner.person_id           = p_person_id
6238            and    pil_inner.business_group_id = p_business_group_id
6239            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
6240            and    (pen_inner.enrt_cvg_thru_dt is null or
6241                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
6242                   )
6243            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6244          union
6245          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
6246              from  ben_le_clsn_n_rstr  pen_inner,
6247                     ben_per_in_ler pil_inner
6248              where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
6249              and    pil_inner.person_id           = p_person_id
6250              and    pil_inner.business_group_id   = p_business_group_id
6251              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
6252              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
6253            and    (pen_inner.enrt_cvg_thru_dt is null or
6254                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
6255                   )
6256            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6257        )
6258     order by 1, 11 desc; -- pen.effective_end_date; -- Low to High
6259   --
6260   -- Get the electable choice data.
6261   --
6262   cursor c_epe_pen(cp_pl_id in number,
6263                    cp_pgm_id in number,
6264                    cp_oipl_id in number) is
6265     select epe.*,
6266            pel.enrt_typ_cycl_cd,
6267            pel.enrt_perd_end_dt,
6268            pel.enrt_perd_strt_dt,
6269            to_date('31-12-4712','DD-MM-YYYY') enrt_cvg_end_dt,
6270            pel.dflt_enrt_dt
6271     from   ben_elig_per_elctbl_chc epe,
6272            ben_per_in_ler pil,
6273            ben_pil_elctbl_chc_popl pel
6274     where  epe.per_in_ler_id     = p_per_in_ler_id
6275       and  epe.business_group_id = p_business_group_id
6276       and  epe.pl_id             = cp_pl_id
6277       and  nvl(epe.pgm_id, -1)   = nvl(cp_pgm_id, -1)
6278       and  nvl(epe.oipl_id, -1)  = nvl(cp_oipl_id, -1)
6279       and  pil.business_group_id = p_business_group_id
6280       and  pel.business_group_id = epe.business_group_id
6281       and  pil.person_id = p_person_id
6282       and  epe.per_in_ler_id = pil.per_in_ler_id
6283       and  pel.per_in_ler_id = epe.per_in_ler_id
6284       and  pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id;
6285   --
6286   l_epe_pen_rec c_epe_pen%rowtype;
6287   --
6288   cursor c_bnft(cp_elig_per_elctbl_chc_id in number,cp_ordr_num number ) is
6289      select enb.enrt_bnft_id,
6290             enb.entr_val_at_enrt_flag,
6291             enb.dflt_val,
6292             enb.val,
6293             enb.dflt_flag,
6294             enb.cvg_mlt_cd   --Bug 3315323
6295       from  ben_enrt_bnft enb
6296       where enb.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
6297   -- Bug  2526994 we need take the right one
6298   --    and   nvl(enb.mx_wo_ctfn_flag,'N') = 'N' ;
6299         and enb.ordr_num = cp_ordr_num ; --This is more accurate
6300   --
6301   l_bnft_rec            c_bnft%rowtype;
6302   l_bnft_rec_reset      c_bnft%rowtype;
6303   l_bnft_entr_val_found boolean;
6304   l_num_bnft_recs       number := 0;
6305   --
6306   cursor c_rt(cp_elig_per_elctbl_chc_id number,
6307               cp_enrt_bnft_id           number) is
6308       select ecr.enrt_rt_id,
6309              ecr.dflt_val,
6310              ecr.val,
6311              ecr.entr_val_at_enrt_flag,
6312              ecr.acty_base_rt_id
6313       from   ben_enrt_rt ecr
6314       where  ecr.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
6315       and    ecr.business_group_id = p_business_group_id
6316       and    ecr.entr_val_at_enrt_flag = 'Y'
6317       and    ecr.spcl_rt_enrt_rt_id is null
6318   --    and    ecr.prtt_rt_val_id is null
6319       union
6320       select ecr.enrt_rt_id,
6321              ecr.dflt_val,
6322              ecr.val,
6323              ecr.entr_val_at_enrt_flag,
6324              ecr.acty_base_rt_id
6325       from   ben_enrt_rt ecr
6326       where  ecr.enrt_bnft_id = cp_enrt_bnft_id
6327       and    ecr.business_group_id = p_business_group_id
6328       and    ecr.entr_val_at_enrt_flag = 'Y'
6329       and    ecr.spcl_rt_enrt_rt_id is null;
6330   --    and    ecr.prtt_rt_val_id is null;
6331   --
6332   l_rt c_rt%rowtype;
6333   --
6334   type g_rt_rec is record
6335       (enrt_rt_id ben_enrt_rt.enrt_rt_id%type,
6336        dflt_val   ben_enrt_rt.dflt_val%type,
6337        calc_val   ben_enrt_rt.dflt_val%type,
6338        cmcd_rt_val number,
6339        ann_rt_val  number);
6340   --
6341   type g_rt_table is table of g_rt_rec index by binary_integer;
6342   --
6343   l_rt_table g_rt_table;
6344   l_count    number;
6345   --
6346   type pgm_rec is record
6347        (pgm_id        ben_pgm_f.pgm_id%type,
6348         enrt_mthd_cd  ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
6349         multi_row_edit_done boolean,
6350         non_automatics_flag boolean,
6351         max_enrt_esd  date);
6352   --
6353   type pl_rec is record
6354        (pl_id         ben_pl_f.pl_id%type,
6355         enrt_mthd_cd  ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
6356         multi_row_edit_done boolean,
6357         max_enrt_esd  date);
6358   --
6359   type enrt_rec is record
6360        (prtt_enrt_rslt_id        ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
6361         bckdt_prtt_enrt_rslt_id  ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
6362         bckdt_enrt_ovridn_flag    varchar2(1),
6363         bckdt_enrt_cvg_strt_dt   date,
6364         bckdt_enrt_cvg_thru_dt   date,
6365         g_sys_date               date,
6366         pen_ovn_number           ben_prtt_enrt_rslt_f.object_version_number%type,
6367         old_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
6368         new_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
6369         old_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
6370         new_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
6371         old_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
6372         new_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
6373         pgm_id                   ben_prtt_enrt_rslt_f.pgm_id%type,
6374         ler_id                   ben_ler_f.ler_id%type,
6375         elig_per_elctbl_chc_id   ben_elig_per_elctbl_chc.elig_per_elctbl_chc_id%type,
6376         dpnt_cvg_strt_dt_cd      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_cd%type,
6377         dpnt_cvg_strt_dt_rl      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_rl%type,
6378         effective_start_date     ben_prtt_enrt_rslt_f.effective_start_date%type
6379         );
6380   --
6381   type t_pgm_table is table of pgm_rec index by binary_integer;
6382   type t_pl_table is table of pl_rec index by binary_integer;
6383   type t_enrt_table is table of enrt_rec index by binary_integer;
6384   type t_prtt_rt_val_table is table of number index by binary_integer;
6385   l_pgm_table     t_pgm_table;
6386   l_pl_table      t_pl_table;
6387   l_enrt_table    t_enrt_table;
6388   l_pgm_count     number;
6389   l_pl_count      number;
6390   l_enrt_count    number;
6391   l_prtt_rt_val_table t_prtt_rt_val_table;
6392   --
6393   cursor c_prv(cv_prtt_enrt_rslt_id in number,
6394                cv_acty_base_rt_id   in number) is
6395          select  prv.*
6396          from ben_prtt_rt_val prv
6397          where prv.prtt_enrt_rslt_id      = cv_prtt_enrt_rslt_id
6398            and prv.per_in_ler_id     = p_bckdt_per_in_ler_id
6399            and prv.business_group_id = p_business_group_id
6400            and prv.acty_base_rt_id   = cv_acty_base_rt_id;
6401   --
6402   l_prv_rec c_prv%rowtype;
6403   l_prv_rec_nulls c_prv%rowtype;
6404   --
6405   cursor c_bckt_csd_pen(cv_per_in_ler_id in number) is
6406          select pen.*, pil.lf_evt_ocrd_dt
6407          from ben_prtt_enrt_rslt_f pen,
6408               ben_per_in_ler pil
6409          where pen.per_in_ler_id = cv_per_in_ler_id
6410            and pen.per_in_ler_id = pil.per_in_ler_id
6411            and pen.business_group_id = p_business_group_id
6412            and pil.business_group_id = p_business_group_id
6413            and pen.prtt_enrt_rslt_stat_cd is null
6414            and pen.effective_end_date = hr_api.g_eot
6415            and pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
6416            and (pen.enrt_cvg_thru_dt is null or
6417                 pen.enrt_cvg_thru_dt    = hr_api.g_eot
6418                );
6419   type t_bckt_csd_pen_table is table of c_bckt_csd_pen%rowtype index by binary_integer;
6420   l_bckt_csd_pil_enrt_table t_bckt_csd_pen_table;
6421   l_bckt_csd_pen_esd        date;
6422   l_bckt_csd_pil_leod       date;
6423   -- Bug 2677804 Added new parameter to see the thru date
6424   cursor c_ovridn_rt(v_bckdt_pen_id number
6425                     ,v_new_pen_id   number ) is
6426   select prv2.prtt_rt_val_id new_prv_id,
6427          prv2.object_version_number new_prv_ovn,
6428          prv1.*
6429     from ben_prtt_rt_val prv1, ben_prtt_rt_val prv2
6430    where prv1.prtt_enrt_rslt_id = v_bckdt_pen_id
6431      and prv2.prtt_enrt_rslt_id = v_new_pen_id
6432      and prv1.acty_base_rt_id = prv2.acty_base_rt_id
6433      and prv1.rt_ovridn_flag = 'Y'
6434      and prv1.rt_end_dt <> hr_api.g_eot
6435      and prv1.rt_ovridn_thru_dt >= prv2.rt_strt_dt
6436 --     and prv1.prtt_rt_val_stat_cd is null
6437      and prv2.prtt_rt_val_stat_cd is null
6438      and prv2.per_in_ler_id = p_per_in_ler_id ;
6439   --
6440   cursor c_ovridn_dpnt(v_bckdt_pen_id number
6441                       ,v_new_pen_id   number
6442                       ,v_effective_date date) is
6443   select pdp2.elig_cvrd_dpnt_id new_pdp_id,
6444          pdp2.object_version_number new_pdp_ovn,
6445          pdp1.*
6446     from ben_elig_cvrd_dpnt_f pdp1,
6447          ben_elig_cvrd_dpnt_f pdp2
6448    where pdp1.prtt_enrt_rslt_id = v_bckdt_pen_id
6449      and pdp2.prtt_enrt_rslt_id = v_new_pen_id
6450      and pdp1.dpnt_person_id = pdp2.dpnt_person_id
6451      and pdp1.ovrdn_flag = 'Y'
6452      and v_effective_date between pdp1.effective_start_date
6453                               and pdp1.effective_end_date
6454      and v_effective_date between pdp2.effective_start_date
6455                             and pdp2.effective_end_date;
6456   --
6457   cursor c_ovn(v_prtt_enrt_rslt_id number) is
6458   select object_version_number
6459     from ben_prtt_enrt_rslt_f
6460    where prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
6461      and effective_end_date = hr_api.g_eot;
6462   --
6463   cursor c_prv_ovn (v_prtt_rt_val_id number) is
6464     select prv.*
6465           ,abr.input_value_id
6466           ,abr.element_type_id
6467     from   ben_prtt_rt_val  prv,
6468            ben_acty_base_rt_f abr
6469     where  prtt_rt_val_id = v_prtt_rt_val_id
6470        and abr.acty_base_rt_id=prv.acty_base_rt_id
6471        and abr.business_group_id = p_business_group_id
6472        and p_effective_date between
6473              abr.effective_start_date and abr.effective_end_date;
6474   --
6475   l_upd_rt_val            boolean;
6476   l_prv_ovn               c_prv_ovn%rowtype;
6477   l_suspend_flag          varchar2(30);
6478   l_prtt_rt_val_id1       number;
6479   l_prtt_rt_val_id2       number;
6480   l_prtt_rt_val_id3       number;
6481   l_prtt_rt_val_id4       number;
6482   l_prtt_rt_val_id5       number;
6483   l_prtt_rt_val_id6       number;
6484   l_prtt_rt_val_id7       number;
6485   l_prtt_rt_val_id8       number;
6486   l_prtt_rt_val_id9       number;
6487   l_prtt_rt_val_id10      number;
6488   l_effective_start_date  date;
6489   l_effective_end_date    date;
6490   l_dpnt_actn_warning     boolean;
6491   l_bnf_actn_warning      boolean;
6492   l_ctfn_actn_warning     boolean;
6493   l_prtt_enrt_interim_id  number;
6494   l_prtt_enrt_rslt_id     number;
6495   l_object_version_number number;
6496   l_cls_enrt_flag         boolean := FALSE;
6497   l_prev_pgm_id           number := NULL; -- Do not change it
6498   l_enrt_mthd_cd          varchar2(30);
6499   l_found                 boolean;
6500   l_enrt_cnt              number := 1;
6501   l_max_enrt_esd          date;
6502   l_esd_out               date;
6503   l_eed_out               date;
6504   l_ovn                   number(15);
6505   --RCHASE - ensure automatics are handled differently than
6506   --         form enrollments by process_post_enrollment
6507   l_proc_cd               varchar2(30);
6508   --
6509   l_found_non_automatics  boolean;
6510   l_dummy_number          number;
6511   --
6512   l_enrt_cvg_strt_dt      date;
6513   --
6514 
6515 begin
6516   --
6517   hr_utility.set_location('Entering ' || l_proc,10);
6518   --
6519   open c_bckdt_pil;
6520   fetch c_bckdt_pil into l_bckdt_pil_prev_stat_cd, l_bckdt_pil_ovn, l_bckt_csd_per_in_ler_id;
6521   close c_bckdt_pil;
6522   if l_bckdt_pil_prev_stat_cd = 'PROCD' then
6523      --
6524      l_cls_enrt_flag := TRUE;
6525      --
6526   end if;
6527   l_pgm_table.delete;
6528   l_pl_table.delete;
6529   l_enrt_table.delete;
6530   l_bckt_csd_pil_enrt_table.delete;
6531   --
6532   -- Get the enrollment results attached to per in ler which
6533   -- caused the back out of currenlty backed out per in ler.
6534   --
6535   if l_bckt_csd_per_in_ler_id is not null then
6536      --
6537      for l_bckt_csd_pen_rec in c_bckt_csd_pen(l_bckt_csd_per_in_ler_id) loop
6538          --
6539          l_bckt_csd_pil_enrt_table(l_enrt_cnt) := l_bckt_csd_pen_rec;
6540          l_enrt_cnt := l_enrt_cnt + 1;
6541          --
6542      end loop;
6543      --
6544   end if;
6545   --
6546   -- For each of the enrollment result in back up table, create
6547   -- a enrollment.
6548   --
6549   FOR l_bckdt_pen_rec in c_bckdt_pen loop
6550     --
6551     -- If the enrollment record is valid for the current
6552     -- effective_date then recreate the enrollment.
6553     --
6554     hr_utility.set_location('Inside BCKDT pen loop ' || l_proc,20);
6555     --
6556     -- if p_effective_date <= l_bckdt_pen_rec.effective_end_date
6557     --
6558     l_bckt_csd_pen_esd  := null;
6559     l_bckt_csd_pil_leod := null;
6560     if nvl(l_bckt_csd_pil_enrt_table.last,0) > 0 then
6561        --
6562        for l_cnt in 1..l_bckt_csd_pil_enrt_table.LAST loop
6563            --
6564            if nvl(l_bckt_csd_pil_enrt_table(l_cnt).pl_id, -1) = nvl(l_bckdt_pen_rec.pl_id, -1) and
6565               nvl(l_bckt_csd_pil_enrt_table(l_cnt).pgm_id, -1) = nvl(l_bckdt_pen_rec.pgm_id, -1) and
6566               nvl(l_bckt_csd_pil_enrt_table(l_cnt).oipl_id, -1) = nvl(l_bckdt_pen_rec.oipl_id, -1)
6567            then
6568                  l_bckt_csd_pen_esd := l_bckt_csd_pil_enrt_table(l_cnt).effective_start_date;
6569                  l_bckt_csd_pil_leod := l_bckt_csd_pil_enrt_table(l_cnt).lf_evt_ocrd_dt;
6570                  exit;
6571            end if;
6572            --
6573        end loop;
6574        --
6575     end if;
6576     --
6577     open c_epe_pen(l_bckdt_pen_rec.pl_id,
6578                      l_bckdt_pen_rec.pgm_id,
6579                      l_bckdt_pen_rec.oipl_id);
6580     fetch c_epe_pen into l_epe_pen_rec;
6581     close c_epe_pen;
6582     hr_utility.set_location('After epe fetch ' || l_proc,30);
6583     --
6584      g_sys_date := greatest(trunc(l_epe_pen_rec.enrt_perd_strt_dt),
6585                     nvl(nvl(l_bckt_csd_pen_esd, g_bckt_csd_lf_evt_ocrd_dt), hr_api.g_sot),
6586                     l_bckdt_pen_rec.effective_start_date);
6587     /*
6588     g_sys_date := greatest(trunc(sysdate),
6589                     nvl(nvl(l_bckt_csd_pen_esd, g_bckt_csd_lf_evt_ocrd_dt), hr_api.g_sot) + 1,
6590                     l_bckdt_pen_rec.effective_start_date);
6591     */
6592     --
6593     l_max_enrt_esd := greatest(g_sys_date, nvl(l_max_enrt_esd, hr_api.g_sot));
6594     --
6595     --
6596     hr_utility.set_location('Date used to reinstate the enrollment = ' || g_sys_date, 333);
6597     if g_sys_date <= l_bckdt_pen_rec.effective_end_date
6598     then
6599        --
6600        -- Get the benefits Information.
6601        --
6602        l_num_bnft_recs := 0;
6603        l_bnft_entr_val_found := FALSE;
6604        l_bnft_rec := l_bnft_rec_reset;
6605        --
6606        open c_bnft(l_epe_pen_rec.elig_per_elctbl_chc_id,l_bckdt_pen_rec.bnft_ordr_num );
6607        loop
6608          --
6609 
6610          hr_utility.set_location('Inside bnft loop ' || l_proc,40);
6611          --Bug 3315323 we need to reinstate the previuos benefit amount for the case
6612          --of SAAEAR also as enb record may have null value there for first enrollment
6613          --or it may not be the right amount.
6614          --
6615          fetch c_bnft into l_bnft_rec;
6616          exit when c_bnft%notfound;
6617          if l_bnft_rec.entr_val_at_enrt_flag = 'Y' OR l_bnft_rec.cvg_mlt_cd='SAAEAR' then
6618             l_bnft_entr_val_found := TRUE;
6619          end if;
6620          l_num_bnft_recs := l_num_bnft_recs + 1;
6621          --
6622          if l_bckdt_pen_rec.BNFT_AMT = l_bnft_rec.VAL then
6623             --
6624             -- Found the benefit we are looking for, so exit.
6625             --
6626             exit;
6627             --
6628          end if;
6629          --
6630        end loop;
6631        --
6632        -- Bug 5282 :  When a backed out life event is repeocessed
6633        -- plans with enter 'enter val at enrollment' coverage amount
6634        -- previous amount is not used when enrollments reinstated.
6635        --
6636        if l_bnft_entr_val_found
6637        then
6638          if l_num_bnft_recs =  0 then
6639             null;
6640             -- This is a error condition, so rollback all the reinstate process.
6641          else
6642             --
6643             l_bnft_rec.val := l_bckdt_pen_rec.BNFT_AMT;
6644             --
6645          end if;
6646        end if;
6647        hr_utility.set_location(l_proc,50);
6648        close c_bnft;
6649        --
6650        for l_count in 1..10 loop
6651           --
6652           -- Initialise array to null
6653           --
6654           l_rt_table(l_count).enrt_rt_id := null;
6655           l_rt_table(l_count).dflt_val := null;
6656           --
6657        end loop;
6658        --
6659        -- Now get the rates.
6660        --
6661        l_count:= 0;
6662        --
6663        for l_rec in c_rt(l_epe_pen_rec.elig_per_elctbl_chc_id,
6664                          l_bnft_rec.enrt_bnft_id)
6665        loop
6666           --
6667           hr_utility.set_location('Inside rate loop ' ||l_proc,50);
6668           --
6669           -- Get the prtt rate val for this enrollment result.
6670           -- Use to pass to the enrollment process.
6671           --
6672           -- Bug : 1634870 : If the user not selected the rate before backout
6673           -- then do not pass it to the reinstate process.
6674           --
6675           hr_utility.set_location('enrt_rt_id : dflt_val : val : entr_val' ||
6676                                   '_at_enrt_flag : acty_base_rt_id : ' , 501);
6677           hr_utility.set_location(l_rec.enrt_rt_id || ' : ' || l_rec.dflt_val || ' : ' || l_rec.val || ' : '
6678                                   || l_rec.entr_val_at_enrt_flag || ' : ' ||
6679                                   l_rec.acty_base_rt_id, 501);
6680           --
6681           l_prv_rec := l_prv_rec_nulls;
6682           open c_prv(l_bckdt_pen_rec.prtt_enrt_rslt_id ,
6683                      l_rec.acty_base_rt_id);
6684           fetch c_prv into l_prv_rec;
6685           if c_prv%found then -- l_prv_rec.prtt_rt_val_id is not null then
6686              --
6687              l_count := l_count+1;
6688              hr_utility.set_location('prtt_rt_val_id : rt_val : ' ||
6689                      l_prv_rec.prtt_rt_val_id ||  ' : ' || l_prv_rec.rt_val
6690                      || ' : ' || l_prv_rec.acty_base_rt_id , 502);
6691              l_rt_table(l_count).enrt_rt_id := l_rec.enrt_rt_id;
6692              if l_prv_rec.mlt_cd in ('CL','CVG','AP','PRNT','CLANDCVG','APANDCVG','PRNTANDCVG') then
6693                 l_rt_table(l_count).dflt_val := l_rec.dflt_val;
6694                 l_rt_table(l_count).calc_val := l_prv_rec.rt_val;
6695                 l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
6696                 l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
6697              else
6698                 l_rt_table(l_count).dflt_val   := l_prv_rec.rt_val;
6699                 l_rt_table(l_count).calc_val   := l_prv_rec.rt_val;
6700                 l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
6701                 l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
6702              end if;
6703              --
6704           end if;
6705           close c_prv;
6706           --
6707        end loop;
6708        --
6709        -- Call election information batch process
6710        --
6711        -- initialize all the out parameters.
6712        l_suspend_flag          := null;
6713        l_prtt_rt_val_id1       := null;
6714        l_prtt_rt_val_id2       := null;
6715        l_prtt_rt_val_id3       := null;
6716        l_prtt_rt_val_id4       := null;
6717        l_prtt_rt_val_id5       := null;
6718        l_prtt_rt_val_id6       := null;
6719        l_prtt_rt_val_id7       := null;
6720        l_prtt_rt_val_id8       := null;
6721        l_prtt_rt_val_id9       := null;
6722        l_prtt_rt_val_id10      := null;
6723        l_effective_start_date  := null;
6724        l_effective_end_date    := null;
6725        l_dpnt_actn_warning     := null;
6726        l_bnf_actn_warning      := null;
6727        l_ctfn_actn_warning     := null;
6728        l_prtt_enrt_interim_id  := null;
6729        l_prtt_enrt_rslt_id     := null;
6730        l_object_version_number := null;
6731        l_enrt_cvg_strt_dt := null;
6732 
6733        -- if cvg_st_dt_cd is enterable then copy the l_bckdt_pen_rec.enrt_cvg_strt_dt
6734        -- 5746429 starts
6735 
6736        if  l_epe_pen_rec.enrt_cvg_strt_dt_cd = 'ENTRBL'
6737         then
6738 	      l_enrt_cvg_strt_dt := l_bckdt_pen_rec.enrt_cvg_strt_dt ;
6739        end if ;
6740        -- 5746429 ends
6741        hr_utility.set_location('Calling ben_election_information ' ||l_proc,60);
6742        hr_utility.set_location('Calling l_bnft_rec.val ' ||l_bnft_rec.val,60);
6743        hr_utility.set_location('Calling l_enrt_cvg_strt_dt ' ||l_enrt_cvg_strt_dt,60);
6744        --
6745        --
6746 
6747        ben_election_information.election_information
6748           (p_elig_per_elctbl_chc_id => l_epe_pen_rec.elig_per_elctbl_chc_id,
6749            p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,-- l_epe_pen_rec.prtt_enrt_rslt_id,
6750            p_effective_date         => g_sys_date,
6751            p_enrt_mthd_cd           => l_bckdt_pen_rec.enrt_mthd_cd,
6752            p_business_group_id      => p_business_group_id,
6753            p_enrt_bnft_id           => l_bnft_rec.enrt_bnft_id,
6754            p_bnft_val               => l_bnft_rec.val,
6755 	       p_enrt_cvg_strt_dt       => l_enrt_cvg_strt_dt, -- 5746429
6756            p_enrt_rt_id1            => l_rt_table(1).enrt_rt_id,
6757            p_rt_val1                => l_rt_table(1).dflt_val,
6758            p_ann_rt_val1            => l_rt_table(1).ann_rt_val,
6759            p_enrt_rt_id2            => l_rt_table(2).enrt_rt_id,
6760            p_rt_val2                => l_rt_table(2).dflt_val,
6761            p_ann_rt_val2            => l_rt_table(2).ann_rt_val,
6762            p_enrt_rt_id3            => l_rt_table(3).enrt_rt_id,
6763            p_rt_val3                => l_rt_table(3).dflt_val,
6764            p_ann_rt_val3            => l_rt_table(3).ann_rt_val,
6765            p_enrt_rt_id4            => l_rt_table(4).enrt_rt_id,
6766            p_rt_val4                => l_rt_table(4).dflt_val,
6767            p_ann_rt_val4            => l_rt_table(4).ann_rt_val,
6768            p_enrt_rt_id5            => l_rt_table(5).enrt_rt_id,
6769            p_rt_val5                => l_rt_table(5).dflt_val,
6770            p_ann_rt_val5            => l_rt_table(5).ann_rt_val,
6771            p_enrt_rt_id6            => l_rt_table(6).enrt_rt_id,
6772            p_rt_val6                => l_rt_table(6).dflt_val,
6773            p_ann_rt_val6            => l_rt_table(6).ann_rt_val,
6774            p_enrt_rt_id7            => l_rt_table(7).enrt_rt_id,
6775            p_rt_val7                => l_rt_table(7).dflt_val,
6776            p_ann_rt_val7            => l_rt_table(7).ann_rt_val,
6777            p_enrt_rt_id8            => l_rt_table(8).enrt_rt_id,
6778            p_rt_val8                => l_rt_table(8).dflt_val,
6779            p_ann_rt_val8            => l_rt_table(8).ann_rt_val,
6780            p_enrt_rt_id9            => l_rt_table(9).enrt_rt_id,
6781            p_rt_val9                => l_rt_table(9).dflt_val,
6782            p_ann_rt_val9            => l_rt_table(9).ann_rt_val,
6783            p_enrt_rt_id10           => l_rt_table(10).enrt_rt_id,
6784            p_rt_val10               => l_rt_table(10).dflt_val,
6785            p_ann_rt_val10           => l_rt_table(10).ann_rt_val,
6786            p_datetrack_mode         => hr_api.g_insert, --
6787            p_suspend_flag           => l_suspend_flag,
6788            p_called_from_sspnd      => 'N',
6789            p_prtt_enrt_interim_id   => l_prtt_enrt_interim_id,
6790            p_prtt_rt_val_id1        => l_prtt_rt_val_id1,
6791            p_prtt_rt_val_id2        => l_prtt_rt_val_id2,
6792            p_prtt_rt_val_id3        => l_prtt_rt_val_id3,
6793            p_prtt_rt_val_id4        => l_prtt_rt_val_id4,
6794            p_prtt_rt_val_id5        => l_prtt_rt_val_id5,
6795            p_prtt_rt_val_id6        => l_prtt_rt_val_id6,
6796            p_prtt_rt_val_id7        => l_prtt_rt_val_id7,
6797            p_prtt_rt_val_id8        => l_prtt_rt_val_id8,
6798            p_prtt_rt_val_id9        => l_prtt_rt_val_id9,
6799            p_prtt_rt_val_id10       => l_prtt_rt_val_id10,
6800            -- 6131609 : reinstate DFF values
6801             p_pen_attribute_category => l_bckdt_pen_rec.pen_attribute_category,
6802             p_pen_attribute1  => l_bckdt_pen_rec.pen_attribute1,
6803             p_pen_attribute2  => l_bckdt_pen_rec.pen_attribute2,
6804             p_pen_attribute3  => l_bckdt_pen_rec.pen_attribute3,
6805             p_pen_attribute4  => l_bckdt_pen_rec.pen_attribute4,
6806             p_pen_attribute5  => l_bckdt_pen_rec.pen_attribute5,
6807             p_pen_attribute6  => l_bckdt_pen_rec.pen_attribute6,
6808             p_pen_attribute7  => l_bckdt_pen_rec.pen_attribute7,
6809             p_pen_attribute8  => l_bckdt_pen_rec.pen_attribute8,
6810             p_pen_attribute9  => l_bckdt_pen_rec.pen_attribute9,
6811             p_pen_attribute10 => l_bckdt_pen_rec.pen_attribute10,
6812             p_pen_attribute11 => l_bckdt_pen_rec.pen_attribute11,
6813             p_pen_attribute12 => l_bckdt_pen_rec.pen_attribute12,
6814             p_pen_attribute13 => l_bckdt_pen_rec.pen_attribute13,
6815             p_pen_attribute14 => l_bckdt_pen_rec.pen_attribute14,
6816             p_pen_attribute15 => l_bckdt_pen_rec.pen_attribute15,
6817             p_pen_attribute16 => l_bckdt_pen_rec.pen_attribute16,
6818             p_pen_attribute17 => l_bckdt_pen_rec.pen_attribute17,
6819             p_pen_attribute18 => l_bckdt_pen_rec.pen_attribute18,
6820             p_pen_attribute19 => l_bckdt_pen_rec.pen_attribute19,
6821             p_pen_attribute20 => l_bckdt_pen_rec.pen_attribute20,
6822             p_pen_attribute21 => l_bckdt_pen_rec.pen_attribute21,
6823             p_pen_attribute22 => l_bckdt_pen_rec.pen_attribute22,
6824             p_pen_attribute23 => l_bckdt_pen_rec.pen_attribute23,
6825             p_pen_attribute24 => l_bckdt_pen_rec.pen_attribute24,
6826             p_pen_attribute25 => l_bckdt_pen_rec.pen_attribute25,
6827             p_pen_attribute26 => l_bckdt_pen_rec.pen_attribute26,
6828             p_pen_attribute27 => l_bckdt_pen_rec.pen_attribute27,
6829             p_pen_attribute28 => l_bckdt_pen_rec.pen_attribute28,
6830             p_pen_attribute29 => l_bckdt_pen_rec.pen_attribute29,
6831             p_pen_attribute30 => l_bckdt_pen_rec.pen_attribute30,
6832             --
6833            p_object_version_number  => l_object_version_number,
6834            p_effective_start_date   => l_effective_start_date,
6835            p_effective_end_date     => l_effective_end_date,
6836            p_dpnt_actn_warning      => l_dpnt_actn_warning,
6837            p_bnf_actn_warning       => l_bnf_actn_warning,
6838            p_ctfn_actn_warning      => l_ctfn_actn_warning);
6839        --
6840 
6841        l_prtt_rt_val_table(1)       := l_prtt_rt_val_id1;
6842        l_prtt_rt_val_table(2)       := l_prtt_rt_val_id2;
6843        l_prtt_rt_val_table(3)       := l_prtt_rt_val_id3;
6844        l_prtt_rt_val_table(4)       := l_prtt_rt_val_id4;
6845        l_prtt_rt_val_table(5)       := l_prtt_rt_val_id5;
6846        l_prtt_rt_val_table(6)       := l_prtt_rt_val_id6;
6847        l_prtt_rt_val_table(7)       := l_prtt_rt_val_id7;
6848        l_prtt_rt_val_table(8)       := l_prtt_rt_val_id8;
6849        l_prtt_rt_val_table(9)       := l_prtt_rt_val_id9;
6850        l_prtt_rt_val_table(10)      := l_prtt_rt_val_id10;
6851 
6852 
6853 
6854        -- if rate is enter value at enrollment and calculation method is like multiple and
6855        -- calculate flag is on, first the prtt_rt_val is created with default value and
6856        -- subsequently the calculated value is updated by taking values from backedout rows
6857        for i  in 1..l_count loop
6858           l_upd_rt_val  := FALSE;
6859           open c_prv_ovn (l_prtt_rt_val_table(i));
6860           fetch c_prv_ovn into l_prv_ovn;
6861           if c_prv_ovn%found then
6862               if l_prv_ovn.rt_val <>l_rt_table(i).calc_val  then
6863                  l_upd_rt_val := TRUE;
6864               end if;
6865           end if;
6866           close c_prv_ovn;
6867           if l_upd_rt_val then
6868               ben_prtt_rt_val_api.update_prtt_rt_val
6869                 (p_prtt_rt_val_id        => l_prtt_rt_val_table(i)
6870                 ,p_person_id             => p_person_id
6871                 ,p_rt_val                => l_rt_table(i).calc_val
6872                 ,p_acty_ref_perd_cd      => l_prv_ovn.acty_ref_perd_cd
6873                 ,p_cmcd_rt_val           => l_rt_table(i).cmcd_rt_val
6874                 ,p_cmcd_ref_perd_cd      => l_prv_ovn.cmcd_ref_perd_cd
6875                 ,p_ann_rt_val            => l_rt_table(i).ann_rt_val
6876                 ,p_business_group_id     => p_business_group_id
6877                 ,p_object_version_number => l_prv_ovn.object_version_number
6878                 ,p_effective_date        => g_sys_date);
6879               --
6880           end if;
6881        end loop;
6882 
6883 
6884 
6885        -- Populate the enrollment results electble choice data
6886        -- to be used for dependents and beneficiaries restoration.
6887        -- the reinstate beneficiaries and dependents processes
6888        -- from hare as multi row edit process may create
6889        -- these records as part of recycle. So reinstate beneficiaries
6890        -- and dependents processes should be called after multi row edits.
6891        --
6892        l_found := FALSE;
6893        if nvl(l_enrt_table.LAST, 0) > 0 then
6894           for l_cnt in 1..l_enrt_table.LAST loop
6895               --
6896               if l_enrt_table(l_cnt).prtt_enrt_rslt_id = l_prtt_enrt_rslt_id
6897               then
6898                  l_found := TRUE;
6899                  exit;
6900               end if;
6901               --
6902            end loop;
6903        end if;
6904        --
6905        if not l_found then
6906           --
6907           --
6908           l_enrt_count := nvl(l_enrt_table.LAST, 0) + 1;
6909           l_enrt_table(l_enrt_count).prtt_enrt_rslt_id := l_prtt_enrt_rslt_id;
6910           l_enrt_table(l_enrt_count).effective_start_date := l_effective_start_date;
6911           l_enrt_table(l_enrt_count).bckdt_prtt_enrt_rslt_id
6912                                            := l_bckdt_pen_rec.prtt_enrt_rslt_id;
6913           l_enrt_table(l_enrt_count).bckdt_enrt_ovridn_flag
6914                                            := l_bckdt_pen_rec.enrt_ovridn_flag;
6915           l_enrt_table(l_enrt_count).bckdt_enrt_cvg_strt_dt
6916                                            := l_bckdt_pen_rec.enrt_cvg_strt_dt;
6917           l_enrt_table(l_enrt_count).bckdt_enrt_cvg_thru_dt
6918                                            := l_bckdt_pen_rec.enrt_cvg_thru_dt;
6919           l_enrt_table(l_enrt_count).g_sys_date := g_sys_date;
6920           l_enrt_table(l_enrt_count).pen_ovn_number := l_object_version_number;
6921           l_enrt_table(l_enrt_count).old_pl_id := l_bckdt_pen_rec.pl_id;
6922           l_enrt_table(l_enrt_count).new_pl_id := l_bckdt_pen_rec.pl_id;
6923           l_enrt_table(l_enrt_count).old_oipl_id := l_bckdt_pen_rec.oipl_id;
6924           l_enrt_table(l_enrt_count).new_oipl_id := l_bckdt_pen_rec.oipl_id;
6925           l_enrt_table(l_enrt_count).old_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
6926           l_enrt_table(l_enrt_count).new_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
6927           l_enrt_table(l_enrt_count).pgm_id := l_bckdt_pen_rec.pgm_id;
6928           l_enrt_table(l_enrt_count).ler_id := null;
6929           l_enrt_table(l_enrt_count).elig_per_elctbl_chc_id
6930                                            := l_epe_pen_rec.elig_per_elctbl_chc_id;
6931           l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_cd
6932                                            := l_epe_pen_rec.dpnt_cvg_strt_dt_cd;
6933           l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_rl
6934                                            := l_epe_pen_rec.dpnt_cvg_strt_dt_rl;
6935           /* Trace messages for the enrollments, uncomment for tracing bugs */
6936           hr_utility.set_location('prtt_enrt_rslt_id = ' ||
6937                      l_enrt_table(l_enrt_count).prtt_enrt_rslt_id, 9999);
6938           hr_utility.set_location('bckdt_prtt_enrt_rslt_id = ' ||
6939                      l_enrt_table(l_enrt_count).bckdt_prtt_enrt_rslt_id, 9999);
6940           hr_utility.set_location('bckdt_enrt_ovridn_flag = ' ||
6941                      l_enrt_table(l_enrt_count).bckdt_enrt_ovridn_flag, 72);
6942           hr_utility.set_location('bckdt_enrt_cvg_strt_dt = ' ||
6943                      l_enrt_table(l_enrt_count).bckdt_enrt_cvg_strt_dt, 72);
6944           hr_utility.set_location('pen_ovn_number = ' ||
6945                      l_enrt_table(l_enrt_count).pen_ovn_number, 9999);
6946           hr_utility.set_location('old_pl_id = ' ||
6947                      l_enrt_table(l_enrt_count).old_pl_id, 9999);
6948           hr_utility.set_location('new_pl_id = ' ||
6949                      l_enrt_table(l_enrt_count).new_pl_id, 9999);
6950           hr_utility.set_location('old_oipl_id = ' ||
6951                      l_enrt_table(l_enrt_count).old_oipl_id, 9999);
6952           hr_utility.set_location('new_oipl_id = ' ||
6953                      l_enrt_table(l_enrt_count).new_oipl_id, 9999);
6954           hr_utility.set_location('old_pl_typ_id = ' ||
6955                      l_enrt_table(l_enrt_count).old_pl_typ_id, 9999);
6956           hr_utility.set_location('new_pl_typ_id = ' ||
6957                      l_enrt_table(l_enrt_count).new_pl_typ_id, 9999);
6958           hr_utility.set_location('pgm_id = ' ||
6959                      l_enrt_table(l_enrt_count).pgm_id, 9999);
6960           hr_utility.set_location('elig_per_elctbl_chc_id = ' ||
6961                      l_enrt_table(l_enrt_count).elig_per_elctbl_chc_id, 9999);
6962           /**/
6963           --
6964        end if;
6965        --
6966        -- Populate the pgm and pl tables, to pocess post results.
6967        --
6968        if l_epe_pen_rec.pgm_id is null then
6969           --
6970           --
6971           l_found := FALSE;
6972           if nvl(l_pl_table.LAST, 0) > 0 then
6973              --
6974              --
6975              for l_cnt in 1..l_pl_table.LAST loop
6976                  --
6977 	         --
6978                  if l_pl_table(l_cnt).pl_id = l_epe_pen_rec.pl_id  and
6979                     l_pl_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd
6980                  then
6981                     l_found := TRUE;
6982                     l_pl_table(l_cnt).max_enrt_esd := greatest(l_pl_table(l_cnt).max_enrt_esd,
6983                                                                g_sys_date);
6984                     exit;
6985                  end if;
6986                  --
6987              end loop;
6988           end if;
6989           --
6990           if not l_found then
6991              --
6992              --
6993              l_pl_count := nvl(l_pl_table.LAST, 0) + 1;
6994              l_pl_table(l_pl_count).pl_id            := l_epe_pen_rec.pl_id;
6995              l_pl_table(l_pl_count).enrt_mthd_cd     := l_bckdt_pen_rec.enrt_mthd_cd;
6996              l_pl_table(l_pl_count).multi_row_edit_done := FALSE;
6997              l_pl_table(l_pl_count).max_enrt_esd := g_sys_date;
6998              --
6999           end if;
7000        else
7001           --
7002           l_found := FALSE;
7003           --
7004 	  --
7005           if nvl(l_pgm_table.LAST, 0) > 0 then
7006              for l_cnt in 1..l_pgm_table.LAST loop
7007                  --
7008                  --
7009 
7010                  if l_pgm_table(l_cnt).pgm_id = l_epe_pen_rec.pgm_id and
7011                     l_pgm_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd
7012                  then
7013                     l_found := TRUE;
7014                     l_pgm_table(l_cnt).max_enrt_esd := greatest(l_pgm_table(l_cnt).max_enrt_esd,
7015                                                                g_sys_date);
7016                     exit;
7017                  end if;
7018                  --
7019              end loop;
7020           end if;
7021           --
7022           if not l_found then
7023              --
7024              --
7025              l_pgm_count := nvl(l_pgm_table.LAST, 0) + 1;
7026              l_pgm_table(l_pgm_count).pgm_id         := l_epe_pen_rec.pgm_id;
7027              l_pgm_table(l_pgm_count).enrt_mthd_cd   := l_bckdt_pen_rec.enrt_mthd_cd;
7028              l_pgm_table(l_pgm_count).multi_row_edit_done := FALSE;
7029              l_pgm_table(l_pgm_count).max_enrt_esd := g_sys_date;
7030              --
7031           end if;
7032           --
7033        end if;
7034        --
7035     end if;
7036     --
7037   end loop;
7038   --
7039   -- Apply the multi row edits.
7040   --
7041   if nvl(l_pgm_table.LAST, 0) > 0 then
7042      for l_cnt in 1..l_pgm_table.LAST loop
7043         --
7044         -- First see multi row edits are already checked.
7045         --
7046         l_found  := FALSE;
7047         for l_inn_cnt in 1..l_cnt loop
7048           if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
7049              l_pgm_table(l_inn_cnt).multi_row_edit_done
7050           then
7051              l_found  := TRUE;
7052              exit;
7053           end if;
7054         end loop;
7055         --
7056         if not l_found then
7057            --
7058            --
7059            -- Now see if there are non automatic enrollments
7060            --
7061            if l_bckdt_pil_prev_stat_cd='STRTD' then
7062              l_found_non_automatics:=FALSE;
7063              for l_inn_cnt in 1..l_pgm_table.last loop
7064                if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
7065                   l_pgm_table(l_inn_cnt).enrt_mthd_cd<>'A'
7066                then
7067                   l_found_non_automatics  := TRUE;
7068                   exit;
7069                end if;
7070              end loop;
7071            end if;
7072            --
7073            if l_bckdt_pil_prev_stat_cd<>'STRTD' or
7074               l_found_non_automatics then
7075              hr_utility.set_location('Date for multi row edits = ' ||
7076                                       l_pgm_table(l_cnt).max_enrt_esd || '  ' || ' pgm = ' ||
7077                                       l_pgm_table(l_cnt).pgm_id, 333);
7078              ben_prtt_enrt_result_api.multi_rows_edit
7079               (p_person_id         => p_person_id,
7080                p_effective_date    => l_pgm_table(l_cnt).max_enrt_esd,
7081                p_business_group_id => p_business_group_id,
7082                p_per_in_ler_id     => p_per_in_ler_id,
7083                p_pgm_id            => l_pgm_table(l_cnt).pgm_id);
7084              --
7085            end if;
7086            l_pgm_table(l_cnt).multi_row_edit_done := TRUE;
7087            --
7088         end if;
7089         --
7090      end loop;
7091   end if;
7092   --
7093   -- Call multi_rows_edit, process_post_results, reinstate_bpl_per_pen
7094   -- Only if the enrollments are reinstated.
7095   --
7096   if nvl(l_enrt_table.LAST, 0) > 0 then
7097      --
7098      -- Call multi row edits and post results only if enrollments are
7099      -- created.
7100      --
7101      -- Call multi row edits just as miscellanious form calls.
7102      --
7103      hr_utility.set_location('Date for multi row edits = ' ||
7104                               l_max_enrt_esd , 333);
7105      ben_prtt_enrt_result_api.multi_rows_edit
7106       (p_person_id         => p_person_id,
7107        p_effective_date    => l_max_enrt_esd,
7108        p_business_group_id => p_business_group_id,
7109        p_per_in_ler_id     => p_per_in_ler_id,
7110        p_pgm_id            => null);
7111      --
7112      -- Invoke post result process once for Explicit/Automatic/ Default.
7113      --
7114      ben_proc_common_enrt_rslt.process_post_results
7115       (p_person_id          => p_person_id,
7116        p_enrt_mthd_cd       => 'E',
7117        p_effective_date     => l_max_enrt_esd,
7118        p_business_group_id  => p_business_group_id,
7119        p_per_in_ler_id      => p_per_in_ler_id);
7120      --
7121      ben_proc_common_enrt_rslt.process_post_results
7122       (p_person_id          => p_person_id,
7123        p_enrt_mthd_cd       => 'D',
7124        p_effective_date     => l_max_enrt_esd,
7125        p_business_group_id  => p_business_group_id,
7126        p_per_in_ler_id      => p_per_in_ler_id);
7127      --
7128      ben_proc_common_enrt_rslt.process_post_results
7129       (p_person_id          => p_person_id,
7130        p_enrt_mthd_cd       => 'A',
7131        p_effective_date     => l_max_enrt_esd,
7132        p_business_group_id  => p_business_group_id,
7133        p_per_in_ler_id      => p_per_in_ler_id);
7134      --
7135   end if;
7136   --
7137   -- Apply process post enrollments once for each program.
7138   --
7139   if nvl(l_pgm_table.LAST, 0) > 0 then
7140      for l_cnt in 1..l_pgm_table.LAST loop
7141         --
7142         --RCHASE - ensure automatics are handled differently than
7143         --         form enrollments by process_post_enrollment
7144         --
7145         -- Bug 5623259.
7146         --
7147         if l_pgm_table(l_cnt).enrt_mthd_cd = 'E' then
7148            l_proc_cd := 'FORMENRT';
7149         elsif l_pgm_table(l_cnt).enrt_mthd_cd = 'D' then
7150            l_proc_cd := 'DFLTENRT';
7151         else
7152            l_proc_cd := NULL;
7153         end if;
7154         ben_proc_common_enrt_rslt.process_post_enrollment
7155           (p_per_in_ler_id     => p_per_in_ler_id,
7156            p_pgm_id            => l_pgm_table(l_cnt).pgm_id,
7157            p_pl_id             => null,
7158            p_enrt_mthd_cd      => l_pgm_table(l_cnt).enrt_mthd_cd,
7159            p_cls_enrt_flag     => FALSE,
7160            --RCHASE
7161            p_proc_cd           => l_proc_cd,--'FORMENRT',
7162            p_person_id         => p_person_id,
7163            p_business_group_id => p_business_group_id,
7164            p_effective_date    => l_pgm_table(l_cnt).max_enrt_esd );
7165         --
7166       end loop;
7167   end if;
7168   --
7169   -- Apply process post enrollments once for each program.
7170   --
7171   if nvl(l_pl_table.LAST, 0) > 0 then
7172      for l_cnt in 1..l_pl_table.LAST loop
7173         --
7174         -- Invoke post result process
7175         --
7176         hr_utility.set_location('Date = ' || l_pl_table(l_cnt).max_enrt_esd, 333);
7177         hr_utility.set_location('PL = ' || l_pl_table(l_cnt).pl_id, 333);
7178         --RCHASE - ensure automatics are handled differently than
7179         --         form enrollments by process_post_enrollment
7180         -- Bug 5623259.
7181         --
7182         if l_pl_table(l_cnt).enrt_mthd_cd = 'E' then
7183            l_proc_cd := 'FORMENRT';
7184         elsif l_pl_table(l_cnt).enrt_mthd_cd = 'D' then
7185            l_proc_cd := 'DFLTENRT';
7186         else
7187            l_proc_cd := NULL;
7188         end if;
7189         ben_proc_common_enrt_rslt.process_post_enrollment
7190           (p_per_in_ler_id     => p_per_in_ler_id,
7191            p_pgm_id            => null,
7192            p_pl_id             => l_pl_table(l_cnt).pl_id,
7193            p_enrt_mthd_cd      => l_pl_table(l_cnt).enrt_mthd_cd,
7194            p_cls_enrt_flag     => FALSE,
7195            --RCHASE
7196            p_proc_cd           => l_proc_cd,--'FORMENRT',
7197            p_person_id         => p_person_id,
7198            p_business_group_id => p_business_group_id,
7199            p_effective_date    => l_pl_table(l_cnt).max_enrt_esd );
7200         --
7201       end loop;
7202   end if;
7203   --
7204   if nvl(l_enrt_table.LAST, 0) > 0 then
7205      --
7206      -- Reinstate the ledgers if any created.
7207      --
7208      reinstate_bpl_per_pen(
7209          p_person_id              => p_person_id
7210          ,p_business_group_id      => p_business_group_id
7211          ,p_effective_date         => p_effective_date
7212          ,p_per_in_ler_id          => p_per_in_ler_id
7213          ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
7214          );
7215      --
7216      for l_cnt in 1..l_enrt_table.LAST loop
7217        --
7218        -- Reinstate the enrollment beneficiary rows.
7219        --
7220        hr_utility.set_location('Enrt Date = ' ||
7221                                 l_enrt_table(l_cnt).effective_start_date, 333);
7222   hr_utility.set_location('Reinstate the enrollment beneficiary rows',12);
7223        reinstate_pbn_per_pen(
7224          p_person_id                => p_person_id
7225          ,p_bckdt_prtt_enrt_rslt_id
7226                                     => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
7227          ,p_prtt_enrt_rslt_id       => l_enrt_table(l_cnt).prtt_enrt_rslt_id
7228          ,p_rslt_object_version_number => l_enrt_table(l_cnt).pen_ovn_number
7229          ,p_business_group_id        => p_business_group_id
7230          ,p_per_in_ler_id            => p_per_in_ler_id
7231          ,p_effective_date           => nvl(l_enrt_table(l_cnt).effective_start_date,
7232                                             g_sys_date)
7233          ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
7234          );
7235        --
7236       --Bug 3709516 to reinstate participant PCP
7237         reinstate_ppr_per_pen(
7238            p_person_id                => p_person_id
7239           ,p_bckdt_prtt_enrt_rslt_id => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
7240           ,p_prtt_enrt_rslt_id       => l_enrt_table(l_cnt).prtt_enrt_rslt_id
7241           ,p_business_group_id       => p_business_group_id
7242           ,p_elig_cvrd_dpnt_id       => NULL
7243           ,p_effective_date          => nvl(l_enrt_table(l_cnt).effective_start_date,
7244                                                    nvl(g_sys_date, p_effective_date) ) -- bug 5344392
7245           ,p_bckdt_elig_cvrd_dpnt_id => NULL
7246           );
7247        -- Reinstate the covered dependents.
7248        --
7249        reinstate_dpnts_per_pen(
7250                p_person_id                 => p_person_id
7251                ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
7252                ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).prtt_enrt_rslt_id
7253                ,p_pen_ovn_number           => l_enrt_table(l_cnt).pen_ovn_number
7254                ,p_old_pl_id                => l_enrt_table(l_cnt).old_pl_id
7255                ,p_new_pl_id                => l_enrt_table(l_cnt).new_pl_id
7256                ,p_old_oipl_id              => l_enrt_table(l_cnt).old_oipl_id
7257                ,p_new_oipl_id              => l_enrt_table(l_cnt).new_oipl_id
7258                ,p_old_pl_typ_id            => l_enrt_table(l_cnt).old_pl_typ_id
7259                ,p_new_pl_typ_id            => l_enrt_table(l_cnt).new_pl_typ_id
7260                ,p_pgm_id                   => l_enrt_table(l_cnt).pgm_id
7261                ,p_ler_id                   => l_enrt_table(l_cnt).ler_id
7262                ,p_elig_per_elctbl_chc_id   => l_enrt_table(l_cnt).elig_per_elctbl_chc_id
7263                ,p_business_group_id        => p_business_group_id
7264                -- # 2508745
7265                ,p_effective_date           => nvl(l_enrt_table(l_cnt).effective_start_date,
7266                                                     p_effective_date)
7267                ,p_per_in_ler_id            => p_per_in_ler_id
7268                ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
7269                ,p_dpnt_cvg_strt_dt_cd      => l_enrt_table(l_cnt).dpnt_cvg_strt_dt_cd
7270                ,p_dpnt_cvg_strt_dt_rl      => l_enrt_table(l_cnt).dpnt_cvg_strt_dt_rl
7271                ,p_enrt_cvg_strt_dt         => null -- 9999 this should be fetched from base table
7272                );
7273         --
7274         -- Reinstate the enrollment certifications.
7275         --
7276         reinstate_pcs_per_pen(
7277                p_person_id                 => p_person_id
7278                ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
7279                ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).prtt_enrt_rslt_id
7280                ,p_rslt_object_version_number => l_enrt_table(l_cnt).pen_ovn_number -- prtt_enrt_rslt_id
7281                ,p_business_group_id        => p_business_group_id
7282                ,p_prtt_enrt_actn_id        => null
7283                ,p_effective_date           => l_enrt_table(l_cnt).effective_start_date
7284                ,p_bckdt_prtt_enrt_actn_id  => null
7285                -- CFW
7286                ,p_per_in_ler_id            => p_per_in_ler_id
7287                ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
7288                );
7289        --
7290        -- Reinstate the action items.
7291        --
7292        reinstate_pea_per_pen(
7293                  p_person_id                => p_person_id
7294                 ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
7295                 ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).prtt_enrt_rslt_id -- pen_ovn_number
7296                 ,p_rslt_object_version_number => l_enrt_table(l_cnt).pen_ovn_number -- prtt_enrt_rslt_id
7297                 ,p_business_group_id        => p_business_group_id
7298                 ,p_per_in_ler_id            => p_per_in_ler_id
7299                 ,p_effective_date           => l_enrt_table(l_cnt).effective_start_date
7300                 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
7301                 );
7302      end loop;
7303   end if;
7304   --
7305   -- If any of the backed out enrt rslts were overriden, then update the new
7306   -- rslts with the overriden data.
7307   --
7308   if nvl(l_enrt_table.last, 0) > 0 then
7309     --
7310     for i in 1..l_enrt_table.last loop
7311       --
7312       if l_enrt_table(i).bckdt_enrt_ovridn_flag = 'Y' then
7313         --
7314         hr_utility.set_location('Restoring the overriden result: ' ||
7315                                 l_enrt_table(i).bckdt_prtt_enrt_rslt_id, 72);
7316         --
7317         -- Get the latest object version number as the post enrollment process
7318         -- may have updated the new enrt result.
7319         --
7320         open c_ovn(l_enrt_table(i).prtt_enrt_rslt_id);
7321         fetch c_ovn into l_ovn;
7322         close c_ovn;
7323         --
7324         ben_prtt_enrt_result_api.update_prtt_enrt_result
7325           (p_prtt_enrt_rslt_id      => l_enrt_table(i).prtt_enrt_rslt_id
7326           ,p_effective_start_date   => l_esd_out
7327           ,p_effective_end_date     => l_eed_out
7328           ,p_enrt_cvg_strt_dt       => l_enrt_table(i).bckdt_enrt_cvg_strt_dt
7329           ,p_enrt_cvg_thru_dt       => l_enrt_table(i).bckdt_enrt_cvg_thru_dt
7330           ,p_enrt_ovridn_flag       => 'Y'
7331           ,p_object_version_number  => l_ovn
7332           ,p_effective_date         => l_enrt_table(i).g_sys_date
7333           ,p_datetrack_mode         => hr_api.g_correction
7334           ,p_multi_row_validate     => FALSE);
7335         --
7336       end if;
7337       --
7338       -- Check if any of the rates have been overriden and update the new
7339       -- rates with the overriden values.
7340       -- Bug 2677804 changed the cursor
7341       -- We need to see the overriden thru date also.
7342       for l_rt_rec in c_ovridn_rt(l_enrt_table(i).bckdt_prtt_enrt_rslt_id
7343                                  ,l_enrt_table(i).prtt_enrt_rslt_id )
7344       loop
7345         --
7346         hr_utility.set_location('Updating new prv: ' || l_rt_rec.new_prv_id ||
7347                                 ' with overriden prv_id: ' ||
7348                                 l_rt_rec.prtt_rt_val_id, 72);
7349         --
7350         ben_prtt_rt_val_api.update_prtt_rt_val
7351           (p_prtt_rt_val_id        => l_rt_rec.new_prv_id
7352           ,p_person_id             => p_person_id
7353           ,p_rt_strt_dt            => l_rt_rec.rt_strt_dt
7354           ,p_rt_val                => l_rt_rec.rt_val
7355           ,p_acty_ref_perd_cd      => l_rt_rec.acty_ref_perd_cd
7356           ,p_cmcd_rt_val           => l_rt_rec.cmcd_rt_val
7357           ,p_cmcd_ref_perd_cd      => l_rt_rec.cmcd_ref_perd_cd
7358           ,p_ann_rt_val            => l_rt_rec.ann_rt_val
7359           ,p_rt_ovridn_flag        => l_rt_rec.rt_ovridn_flag
7360           ,p_rt_ovridn_thru_dt     => l_rt_rec.rt_ovridn_thru_dt
7361           ,p_business_group_id     => p_business_group_id
7362           ,p_object_version_number => l_rt_rec.new_prv_ovn
7363           ,p_effective_date        => l_enrt_table(i).g_sys_date);
7364         --
7365       end loop;
7366       --
7367       -- Check if there are any dependents that are overriden and update the new
7368       -- elig_cvrd_dpnt records with the overriden values.
7369       --
7370       for l_dpnt_rec in c_ovridn_dpnt(l_enrt_table(i).bckdt_prtt_enrt_rslt_id
7371                                      ,l_enrt_table(i).prtt_enrt_rslt_id
7372                                      ,l_enrt_table(i).g_sys_date)
7373       loop
7374         --
7375         hr_utility.set_location('Updating new ecd with overriden ecd_id: ' ||
7376                                 l_dpnt_rec.elig_cvrd_dpnt_id, 72);
7377         --
7378         ben_elig_cvrd_dpnt_api.update_elig_cvrd_dpnt
7379           (p_elig_cvrd_dpnt_id     => l_dpnt_rec.new_pdp_id
7380           ,p_effective_start_date  => l_esd_out
7381           ,p_effective_end_date    => l_eed_out
7382           ,p_cvg_strt_dt           => l_dpnt_rec.cvg_strt_dt
7383           ,p_cvg_thru_dt           => l_dpnt_rec.cvg_thru_dt
7384           ,p_ovrdn_flag            => l_dpnt_rec.ovrdn_flag
7385           ,p_ovrdn_thru_dt         => l_dpnt_rec.ovrdn_thru_dt
7386           ,p_object_version_number => l_dpnt_rec.new_pdp_ovn
7387           ,p_datetrack_mode        => hr_api.g_correction
7388           ,p_effective_date        => l_enrt_table(i).g_sys_date);
7389         --
7390       end loop;
7391       --
7392     end loop;
7393     --
7394   end if;
7395   --
7396   -- Call the Close enrollement process if the
7397   -- backed out pil's status is PROCD.
7398   --
7399   if l_cls_enrt_flag then
7400      --
7401         ben_close_enrollment.close_single_enrollment
7402                       (p_per_in_ler_id      => p_per_in_ler_id
7403                       ,p_effective_date     => nvl(l_max_enrt_esd,p_effective_date)
7404                       ,p_business_group_id  => p_business_group_id
7405                       ,p_close_cd           => 'FORCE'
7406                       ,p_validate           => FALSE
7407                       ,p_close_uneai_flag     => NULL
7408                       ,p_uneai_effective_date => NULL);
7409      --
7410   end if;
7411   --
7412   -- VOIDD the backed out per in ler.
7413   --
7414   ben_Person_Life_Event_api.update_person_life_event
7415              (p_per_in_ler_id         => p_bckdt_per_in_ler_id
7416              ,p_per_in_ler_stat_cd    => 'VOIDD'
7417              ,p_object_version_number => l_bckdt_pil_ovn
7418              ,p_effective_date        => nvl(l_max_enrt_esd,p_effective_date)
7419              ,P_PROCD_DT              => l_procd_dt  -- outputs
7420              ,P_STRTD_DT              => l_strtd_dt
7421              ,P_VOIDD_DT              => l_voidd_dt  );
7422   --
7423   g_bckdt_pil_restored_flag := 'Y';
7424   --
7425   -- Void the communications created to new per_in ler.
7426   --
7427   void_literature(p_person_id           => p_person_id
7428                  ,p_business_group_id   => p_business_group_id
7429                  ,p_effective_date      => nvl(l_max_enrt_esd,p_effective_date)
7430                  ,p_ler_id              => null
7431                  ,p_per_in_ler_id       => p_per_in_ler_id
7432                  );
7433   --
7434   hr_utility.set_location ('Leaving '||l_proc,10);
7435   --
7436 end reinstate_the_prev_enrt;
7437 --
7438 -- ----------------------------------------------------------------------------
7439 -- |------------------------< comp_rslts_n_process >-------------------------|
7440 -- ----------------------------------------------------------------------------
7441 --
7442 procedure comp_rslts_n_process (
7443          p_bckdt_per_in_ler_id      in number,
7444          p_per_in_ler_id            in number,
7445          p_person_id                in number,
7446          p_business_group_id        in number,
7447          p_effective_date           in date) is
7448   --
7449   l_proc                     varchar2(72) := g_package||'.comp_rslts_n_process';
7450   --
7451   l_inter_pil_ovn            number;
7452   l_inter_pil_cnt            number;
7453   l_inter_per_in_ler_id      number;
7454   l_inter_pil_le_dt          date;
7455   l_resnd_cmnt_txt           fnd_new_messages.message_text%type;
7456   l_bckt_csd_lf_evt_ocrd_dt  date;
7457   l_bckt_csd_per_in_ler_id   number;
7458 
7459   --
7460 begin
7461   --
7462   hr_utility.set_location ('Entering '||l_proc,10);
7463   --
7464   get_inter_pil_cnt (
7465                         p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id,
7466                         p_per_in_ler_id            => p_per_in_ler_id,
7467                         p_person_id                => p_person_id,
7468                         p_business_group_id        => p_business_group_id,
7469                         p_bckt_csd_lf_evt_ocrd_dt  => l_bckt_csd_lf_evt_ocrd_dt,
7470                         p_bckt_csd_per_in_ler_id   => l_bckt_csd_per_in_ler_id,
7471                         p_inter_per_in_ler_id      => l_inter_per_in_ler_id,
7472                         p_inter_pil_ovn            => l_inter_pil_ovn,
7473                         p_inter_pil_cnt            => l_inter_pil_cnt,
7474                         p_inter_pil_le_dt          => l_inter_pil_le_dt,
7475                         p_effective_date           => p_effective_date);
7476   --
7477   hr_utility.set_location ('Entering Inter pil ='|| l_inter_pil_cnt , 4987);
7478   if  l_inter_pil_cnt = 0
7479   then
7480       --
7481       -- No intervening pil's so need to check the backed out
7482       -- enrollment results and current results.
7483       -- If the results are same and check bckdt have more enrt rows then
7484       -- restore the backdt rows and make the current pil voidd.
7485       -- Decision DW, PB : Restore the old backed out pil if the
7486       -- automatic enrollments are same.
7487       --
7488       -- Bug 5108 : JB/DW : Decision is no need to compare the
7489       -- enrollment results. These are automatics.
7490       -- Just go and reinstate the enrollment results.
7491       --
7492       /* if comp_ori_new_pen(p_person_id           => p_person_id
7493                          ,p_business_group_id   => p_business_group_id
7494                          ,p_ler_id              => null
7495                          ,p_effective_date      => p_effective_date
7496                          ,p_per_in_ler_id       => p_per_in_ler_id
7497                          ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7498                          ,p_dont_check_cnt_flag => 'Y'
7499         ) = 'N' then
7500       */
7501         --
7502         -- Now restore the original pil i.e., backed out pil.
7503         --
7504         -- Mark the per-in-ler as voidd
7505         -- 9999 do I need to void any other data, status etc.,
7506         --
7507         -- Now restore the backed out pil to Started status.
7508         -- It should be restored to the prev status 99999 once the column is
7509         -- added to the ben_per_in_ler.
7510         --
7511         reinstate_the_prev_enrt(
7512                             p_person_id            => p_person_id
7513                             ,p_business_group_id   => p_business_group_id
7514                             ,p_ler_id              => null
7515                             ,p_effective_date      => p_effective_date
7516                             ,p_per_in_ler_id       => p_per_in_ler_id
7517                             ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7518                             ,p_bckdt_pil_prev_stat_cd => null
7519                            );
7520         --
7521       /* Bug 5108 : This else part never gets executed
7522          as enrollment results are not compared.
7523          --
7524       else
7525         --
7526         -- Literature needs to be added with comment text.
7527         --
7528         -- Add comments to new literature sent out
7529         -- Comment Ex: Because you have experienced another enrollment, your
7530         -- originlal elections have been voided. You must call benefits centre
7531         -- to re-elect.
7532         --
7533         fnd_message.set_name('BEN','BEN_91283_ORI_ELE_VOID_CMNT');
7534         fnd_message.set_token('LER_NAME',
7535                   ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
7536         l_resnd_cmnt_txt :=  fnd_message.get;
7537         --
7538         pad_cmnt_to_rsnd_lit(
7539                           p_person_id            => p_person_id
7540                           ,p_business_group_id   => p_business_group_id
7541                           ,p_effective_date      => p_effective_date
7542                           ,p_ler_id              => null
7543                           ,p_per_in_ler_id       => p_per_in_ler_id
7544                           ,p_cmnt_txt            => l_resnd_cmnt_txt
7545                          );
7546         --
7547       end if;
7548       */
7549       --
7550    elsif l_inter_pil_cnt = 1 then
7551       --
7552       -- Exactly one inrevening pil just needs to compare the intervening pil
7553       -- and current pil, if differ do nothing, else compare inter pil and
7554       -- backdt pil. if they are same then see the count differ. if count
7555       -- differ then restore the bckdt pil, else void the bckdt pil and keep the
7556       -- inter pil results, void the current pil as well.
7557       --
7558       -- Decision PB, DW: First compare the intervening pil results and
7559       -- backed out results, if they are same then compare results of
7560       -- current pil and intervening pil. If they are same then restore
7561       -- the enrollment results of backed out pil.
7562       -- Bug 1266433 : When intervening ler results and backed out ler results
7563       -- are compared consider the number of enrollments for finding diffrences.
7564       --
7565       if comp_ori_new_pen(p_person_id           => p_person_id
7566                          ,p_business_group_id   => p_business_group_id
7567                          ,p_ler_id              => null
7568                          ,p_effective_date      => p_effective_date
7569                          ,p_per_in_ler_id       => l_inter_per_in_ler_id
7570                          ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7571                          ,p_dont_check_cnt_flag => 'N'
7572          ) = 'N' and
7573          comp_ori_new_pen(p_person_id           => p_person_id
7574                          ,p_business_group_id   => p_business_group_id
7575                          ,p_ler_id              => null
7576                          ,p_effective_date      => p_effective_date
7577                          ,p_per_in_ler_id       => p_per_in_ler_id
7578                          ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7579                          ,p_dont_check_cnt_flag => 'Y'
7580          ) = 'N'
7581       then
7582         --
7583         reinstate_the_prev_enrt(
7584                             p_person_id            => p_person_id
7585                             ,p_business_group_id   => p_business_group_id
7586                             ,p_ler_id              => null
7587                             ,p_effective_date      => p_effective_date
7588                             ,p_per_in_ler_id       => p_per_in_ler_id
7589                             ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7590                             ,p_bckdt_pil_prev_stat_cd => null
7591                            );
7592         --
7593       else
7594          --
7595          -- Add comments to literature. and continue with the current pil.
7596          --
7597          null;
7598         --
7599         -- Add comments to new literature sent out
7600         -- Comment Ex: Because you have experienced another enrollment, your
7601         -- originlal elections have been voided. You must call benefits centre
7602         -- to re-elect.
7603         --
7604         fnd_message.set_name('BEN','BEN_91283_ORI_ELE_VOID_CMNT');
7605         fnd_message.set_token('LER_NAME',
7606                   ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
7607         l_resnd_cmnt_txt :=  fnd_message.get;
7608         --
7609         pad_cmnt_to_rsnd_lit(
7610                           p_person_id            => p_person_id
7611                           ,p_business_group_id   => p_business_group_id
7612                           ,p_effective_date      => p_effective_date
7613                           ,p_ler_id              => null
7614                           ,p_per_in_ler_id       => p_per_in_ler_id
7615                           ,p_cmnt_txt            => l_resnd_cmnt_txt
7616                          );
7617          --
7618       end if;
7619       --
7620    else
7621       --
7622       -- More than one intervening PIL's so do nothing.
7623       -- VOID the new pil literature.
7624       --
7625       void_literature(p_person_id                 => p_person_id
7626                           ,p_business_group_id   => p_business_group_id
7627                           ,p_effective_date      => p_effective_date
7628                           ,p_ler_id              => null
7629                           ,p_per_in_ler_id       => p_per_in_ler_id
7630                          );
7631      --
7632    end if;
7633    --
7634 end comp_rslts_n_process;
7635 --
7636 -- ----------------------------------------------------------------------------
7637 -- |------------------------< comp_ori_new_epe >-------------------------------|
7638 -- ----------------------------------------------------------------------------
7639 --
7640 -- This procedure compares the original and new electability
7641 -- data associated with the same ler and returns Y if changes
7642 -- exists else returns N.
7643 --
7644 function comp_ori_new_epe(p_bckdt_epe_row        ben_reinstate_epe_cache.g_pilepe_inst_row,
7645                           p_current_epe_row      ben_reinstate_epe_cache.g_pilepe_inst_row,
7646                           p_per_in_ler_id        number,
7647                           p_bckdt_per_in_ler_id  number,
7648                           p_person_id            number,
7649                           p_business_group_id    number,
7650                           p_effective_date       date
7651                            ) return varchar2 is
7652   --
7653   l_proc                   varchar2(72) := g_package||'.comp_ori_new_epe';
7654   --
7655   --
7656   l_bckdt_epe_cnt           number  := 0;
7657   l_curr_epe_cnt            number  := 0;
7658   l_differ                  varchar2(1) := 'N';
7659   l_egd_differ              varchar2(1) := 'N';
7660   l_ecd_differ              varchar2(1) := 'N';
7661   l_enb_differ              varchar2(1) := 'N';
7662   l_epe_ecr_differ          varchar2(1) := 'N';
7663   --
7664   l_next_row        binary_integer;
7665   l_found           boolean;
7666   --
7667 begin
7668   --
7669   hr_utility.set_location ('Entering '||l_proc,10);
7670   l_found  := FALSE;
7671   --
7672   if  nvl(p_bckdt_epe_row.pl_id, -1)                = nvl(p_current_epe_row.pl_id, -1) and
7673       nvl(p_bckdt_epe_row.oipl_id, -1)              = nvl(p_current_epe_row.oipl_id, -1) and
7674       nvl(p_bckdt_epe_row.PGM_ID, -1)               = nvl(p_current_epe_row.PGM_ID, -1) and
7675       nvl(p_bckdt_epe_row.PLIP_ID, -1)              = nvl(p_current_epe_row.PLIP_ID, -1) and
7676       nvl(p_bckdt_epe_row.PTIP_ID, -1)              = nvl(p_current_epe_row.PTIP_ID, -1) and
7677       nvl(p_bckdt_epe_row.PL_TYP_ID, -1)            = nvl(p_current_epe_row.PL_TYP_ID, -1) and
7678       nvl(p_bckdt_epe_row.CMBN_PTIP_ID, -1)         = nvl(p_current_epe_row.CMBN_PTIP_ID, -1) and
7679       nvl(p_bckdt_epe_row.CMBN_PTIP_OPT_ID, -1)     = nvl(p_current_epe_row.CMBN_PTIP_OPT_ID, -1) and
7680       nvl(p_bckdt_epe_row.CMBN_PLIP_ID, -1)         = nvl(p_current_epe_row.CMBN_PLIP_ID, -1) and
7681       nvl(p_bckdt_epe_row.SPCL_RT_PL_ID, -1)        = nvl(p_current_epe_row.SPCL_RT_PL_ID, -1) and
7682       nvl(p_bckdt_epe_row.SPCL_RT_OIPL_ID, -1)      = nvl(p_current_epe_row.SPCL_RT_OIPL_ID, -1) and
7683       nvl(p_bckdt_epe_row.MUST_ENRL_ANTHR_PL_ID, -1)= nvl(p_current_epe_row.MUST_ENRL_ANTHR_PL_ID, -1) and
7684       p_bckdt_epe_row.DFLT_FLAG                     = p_current_epe_row.DFLT_FLAG and
7685       p_bckdt_epe_row.ELCTBL_FLAG                   = p_current_epe_row.ELCTBL_FLAG and
7686       p_bckdt_epe_row.MNDTRY_FLAG                   = p_current_epe_row.MNDTRY_FLAG and
7687       p_bckdt_epe_row.ALWS_DPNT_DSGN_FLAG           = p_current_epe_row.ALWS_DPNT_DSGN_FLAG and
7688       p_bckdt_epe_row.AUTO_ENRT_FLAG                = p_current_epe_row.AUTO_ENRT_FLAG and
7689       p_bckdt_epe_row.CTFN_RQD_FLAG                 = p_current_epe_row.CTFN_RQD_FLAG and
7690       nvl(p_bckdt_epe_row.BNFT_PRVDR_POOL_ID, -1)   = nvl(p_current_epe_row.BNFT_PRVDR_POOL_ID, -1) and
7691       nvl(p_bckdt_epe_row.YR_PERD_ID, -1)           = nvl(p_current_epe_row.YR_PERD_ID, -1) and
7692       nvl(p_bckdt_epe_row.ENRT_CVG_STRT_DT_CD, '$') = nvl(p_current_epe_row.ENRT_CVG_STRT_DT_CD,  '$') and
7693       nvl(p_bckdt_epe_row.ENRT_CVG_STRT_DT_RL, -1)  = nvl(p_current_epe_row.ENRT_CVG_STRT_DT_RL, -1) and
7694       nvl(p_bckdt_epe_row.DPNT_CVG_STRT_DT_CD, '$') = nvl(p_current_epe_row.DPNT_CVG_STRT_DT_CD,  '$') and
7695       nvl(p_bckdt_epe_row.LER_CHG_DPNT_CVG_CD, '$') = nvl(p_current_epe_row.LER_CHG_DPNT_CVG_CD,  '$') and
7696       nvl(p_bckdt_epe_row.DPNT_CVG_STRT_DT_RL, -1)  = nvl(p_current_epe_row.DPNT_CVG_STRT_DT_RL, -1) and
7697       nvl(p_bckdt_epe_row.ENRT_CVG_STRT_DT, hr_api.g_eot) = nvl(p_current_epe_row.ENRT_CVG_STRT_DT, hr_api.g_eot) and
7698       nvl(p_bckdt_epe_row.ERLST_DEENRT_DT, hr_api.g_eot) = nvl(p_current_epe_row.ERLST_DEENRT_DT, hr_api.g_eot)
7699   then
7700     --
7701     -- Now check elig_dpnt rows for any differences.
7702     --
7703     l_egd_differ := comp_ori_new_egd(
7704                            p_person_id              => p_person_id
7705                           ,p_business_group_id      => p_business_group_id
7706                           ,p_effective_date         => p_effective_date
7707                           ,p_per_in_ler_id          => p_per_in_ler_id
7708                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
7709                           ,p_curr_epe_id            => p_current_epe_row.ELIG_PER_ELCTBL_CHC_ID
7710                           ,p_bckdt_epe_id           => p_bckdt_epe_row.ELIG_PER_ELCTBL_CHC_ID
7711                           );
7712     --
7713     if l_egd_differ = 'Y' then
7714       --
7715       l_found   := FALSE;
7716       --
7717     else
7718       --
7719       l_ecd_differ := comp_ori_new_ecd(
7720                            p_person_id              => p_person_id
7721                           ,p_business_group_id      => p_business_group_id
7722                           ,p_effective_date         => p_effective_date
7723                           ,p_per_in_ler_id          => p_per_in_ler_id
7724                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
7725                           ,p_curr_epe_id            => p_current_epe_row.ELIG_PER_ELCTBL_CHC_ID
7726                           ,p_bckdt_epe_id           => p_bckdt_epe_row.ELIG_PER_ELCTBL_CHC_ID
7727                           );
7728       --
7729       if l_ecd_differ = 'Y' then
7730         --
7731         -- even though epe is same ecd differ logically we need to exit.
7732         --
7733         l_found   := FALSE;
7734       else
7735         --
7736         l_enb_differ := comp_ori_new_enb(
7737                            p_person_id              => p_person_id
7738                           ,p_business_group_id      => p_business_group_id
7739                           ,p_effective_date         => p_effective_date
7740                           ,p_per_in_ler_id          => p_per_in_ler_id
7741                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
7742                           ,p_curr_epe_id            => p_current_epe_row.ELIG_PER_ELCTBL_CHC_ID
7743                           ,p_bckdt_epe_id           => p_bckdt_epe_row.ELIG_PER_ELCTBL_CHC_ID
7744                           );
7745         --
7746         if l_enb_differ = 'Y' then
7747           --
7748           -- even though epe, ecd are same there may be differences in
7749           -- enrt_bnft
7750           --
7751           l_found   := FALSE;
7752         else
7753           --
7754           l_epe_ecr_differ := comp_ori_new_epe_ecr(
7755                            p_person_id              => p_person_id
7756                           ,p_business_group_id      => p_business_group_id
7757                           ,p_effective_date         => p_effective_date
7758                           ,p_per_in_ler_id          => p_per_in_ler_id
7759                           ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
7760                           ,p_curr_epe_id            => p_current_epe_row.ELIG_PER_ELCTBL_CHC_ID
7761                           ,p_bckdt_epe_id           => p_bckdt_epe_row.ELIG_PER_ELCTBL_CHC_ID
7762                           );
7763           --
7764           if l_epe_ecr_differ = 'Y' then
7765             --
7766             -- even though epe, ecd, enb are same there may be
7767             -- differences in enrt_rt
7768             --
7769             l_found   := FALSE;
7770             --
7771           else
7772             --
7773             l_found   := TRUE;
7774             --
7775           end if;
7776         end if;
7777         --
7778       end if;
7779       --
7780     end if; -- Diff in egd
7781   end if;
7782   --
7783   if l_found   = FALSE then
7784     --
7785     -- Current epe for a given backed out epe is not found
7786     --
7787     l_differ := 'Y';
7788     --
7789   end if; -- epe ckecks if statement
7790   --
7791   hr_utility.set_location('Leaving:' || l_differ || l_proc, 10);
7792   --
7793   return l_differ;
7794   --
7795 end comp_ori_new_epe;
7796 --
7797 -- ----------------------------------------------------------------------------
7798 -- |------------------------< get_backedout_results >-------------------------
7799 -- ----------------------------------------------------------------------------
7800 procedure get_backedout_results(
7801                              p_person_id              in number
7802                             ,p_pgm_id                 in number
7803                             ,p_pl_id                  in number
7804                             ,p_effective_date         in date
7805                             ,p_bckdt_per_in_ler_id    in number
7806                             ,p_pilepe_inst_table     out nocopy ben_reinstate_epe_cache.g_pilepe_inst_tbl
7807                             ,p_bckdt_pen_table       out nocopy g_bckdt_pen_tbl
7808                            ) is
7809   --
7810   l_proc                    varchar2(72) := g_package||'.get_backedout_results';
7811   --
7812   -- Get the electable choice data.
7813   --
7814   l_bkd_pilepe_inst_row     ben_reinstate_epe_cache.g_pilepe_inst_row;
7815   l_bkd_pilepe_inst_table     ben_reinstate_epe_cache.g_pilepe_inst_tbl;
7816   l_bkd_penepe_counter      binary_integer  ;
7817   l_hv                      pls_integer;
7818   --
7819   l_dummy_number        number;
7820   --Table for backed out Enrollment results
7821   --Table for EPE records associated with backed out enrollment results
7822   --
7823   --
7824   --Table for valid enrollment results and associated EPE data for reinstante
7825   l_bckdt_pen_table         g_bckdt_pen_tbl ;
7826   l_bckdt_pen_rec           g_bckdt_pen%rowtype ;
7827   --
7828   --
7829 begin
7830   --
7831   hr_utility.set_location('Entering ' || l_proc,10);
7832   --
7833   l_bkd_penepe_counter := 0 ;
7834   l_bkd_pilepe_inst_table.delete ;
7835   l_bckdt_pen_table.delete ;
7836   --
7837   FOR l_bckdt_pen_rec in g_bckdt_pen(
7838            c_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id ,
7839            c_person_id           => p_person_id,
7840            c_effective_date      => p_effective_date,
7841            c_pgm_id              => p_pgm_id,
7842            c_pl_id               => p_pl_id ) loop
7843     --
7844     --
7845     hr_utility.set_location('Inside BCKDT pen loop ' || l_proc,20);
7846     --
7847     ben_reinstate_epe_cache.get_pilcobjepe_dets(
7848       p_per_in_ler_id => p_bckdt_per_in_ler_id
7849      ,p_pgm_id        => l_bckdt_pen_rec.pgm_id
7850      ,p_pl_id         => l_bckdt_pen_rec.pl_id
7851      ,p_oipl_id       => l_bckdt_pen_rec.oipl_id
7852      ,p_inst_row      => l_bkd_pilepe_inst_row
7853       );
7854     --
7855     --
7856     if l_bkd_pilepe_inst_row.elig_per_elctbl_chc_id is not null then
7857       --
7858       --Write EPE records to a table
7859       --
7860       l_bkd_penepe_counter := l_bkd_penepe_counter + 1;
7861       l_bkd_pilepe_inst_table(l_bkd_penepe_counter) := l_bkd_pilepe_inst_row;
7862       --
7863       --Also write the backedout results to another table
7864       --
7865       l_bckdt_pen_table(l_bkd_penepe_counter) := l_bckdt_pen_rec ;
7866       --
7867     else
7868       -- write into a exception table for further notification that all the results are not
7869       -- reinstated due to getting the electable choice data in the backed out per in ler
7870       -- this is uncommon.
7871       null;
7872       --
7873     end if;
7874     --
7875   end loop;
7876   p_pilepe_inst_table := l_bkd_pilepe_inst_table ;
7877   p_bckdt_pen_table := l_bckdt_pen_table ;
7878   --
7879   hr_utility.set_location ('Leaving '||l_proc,10);
7880   --
7881 end get_backedout_results;
7882 --
7883 /**** NO LONGER USED.... NEEDS TO BE DELETED COMPLETD
7884 -- ----------------------------------------------------------------------------
7885 -- |------------------------< p_lf_evt_clps_restore >-------------------------|
7886 -- ----------------------------------------------------------------------------
7887 --
7888 procedure p_lf_evt_clps_restore_old(p_person_id               in number
7889                           ,p_business_group_id      in number
7890                           ,p_effective_date         in date
7891                           ,p_per_in_ler_id          in number
7892                           ,p_bckdt_per_in_ler_id    in number
7893                           ) is
7894   --
7895   cursor c_pil(p_per_in_ler_id in number) is
7896     select pil.object_version_number
7897     from   ben_per_in_ler pil
7898     where  pil.per_in_ler_id = p_per_in_ler_id;
7899   --
7900   cursor c_multiple_rate is
7901     select null
7902     from   ben_le_clsn_n_rstr
7903     where  BKUP_TBL_TYP_CD = 'MULTIPLE_RATE'
7904     and    per_in_ler_id  = p_bckdt_per_in_ler_id;
7905    --
7906   l_dummy     varchar2(1);
7907 
7908   l_pil                     c_pil%rowtype;
7909   --
7910   l_proc                    varchar2(72) := g_package||'.p_lf_evt_clps_restore';
7911   l_chages_ocrd_flag        varchar2(1);
7912   l_rslt_exist_flag         varchar2(1);
7913   l_date                    date;
7914   l_resnd_cmnt_txt          fnd_new_messages.message_text%type;
7915   l_dummy1 VARCHAR2(4000);
7916   l_dummy2 VARCHAR2(4000);
7917   l_schema VARCHAR2(10);
7918   --
7919 begin
7920   --
7921   hr_utility.set_location ('Entering '||l_proc,10);
7922   --
7923   -- 9999 Remove it after complete test.
7924   -- bug 4615207 : added GHR product installation chk -Multiple Rate chk to be performed only for GHR
7925   IF (fnd_installation.get_app_info('GHR',l_dummy1, l_dummy2, l_schema)) THEN
7926   open c_multiple_rate;
7927   fetch c_multiple_rate into l_dummy;
7928   if c_multiple_rate%found then
7929   close c_multiple_rate;
7930     -- Multiple rate is found and no reinstate
7931     hr_utility.set_location ('Multiple rate found and no reinstate done',11);
7932     return;
7933   end if;
7934   close c_multiple_rate;
7935 
7936   end if;
7937   --
7938   l_chages_ocrd_flag := comp_ori_new_pil_outcome(
7939                            p_person_id            => p_person_id
7940                            ,p_business_group_id   => p_business_group_id
7941                            ,p_ler_id              => null
7942                            ,p_effective_date      => p_effective_date
7943                            ,p_per_in_ler_id       => p_per_in_ler_id
7944                            ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
7945                           );
7946   --
7947   l_rslt_exist_flag  := ele_made_for_bckdt_pil (
7948                            p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
7949                            ,p_person_id               => p_person_id
7950                            ,p_business_group_id       => p_business_group_id
7951                            ,p_effective_date          => p_effective_date
7952                           );
7953   --
7954   if l_chages_ocrd_flag = 'Y' then
7955      --
7956      -- Changes in electable choices or rates or costs occure.
7957      --
7958      if l_rslt_exist_flag = 'Y' then
7959         --
7960         -- Add comments to new literature sent out
7961         -- Comment Ex: Because you have experienced another enrollment, your
7962         -- originlal elections have been voided. You must call benefits centre
7963         -- to re-elect.
7964         --
7965         fnd_message.set_name('BEN','BEN_91283_ORI_ELE_VOID_CMNT');
7966         fnd_message.set_token('LER_NAME',
7967                   ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
7968         l_resnd_cmnt_txt :=  fnd_message.get;
7969         --
7970         pad_cmnt_to_rsnd_lit(
7971                           p_person_id            => p_person_id
7972                           ,p_business_group_id   => p_business_group_id
7973                           ,p_effective_date      => p_effective_date
7974                           ,p_ler_id              => null
7975                           ,p_per_in_ler_id       => p_per_in_ler_id
7976                           ,p_cmnt_txt            => l_resnd_cmnt_txt
7977                          );
7978      else
7979         --
7980         -- Add comments to new literature sent out
7981         -- Comment Ex: This is a replacement PFS generated as a result of the
7982         --    { name of the new event }
7983         --
7984         fnd_message.set_name('BEN','BEN_92284_RESND_LIT_CMNT');
7985         fnd_message.set_token('LER_NAME',
7986                   ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
7987         l_resnd_cmnt_txt :=  fnd_message.get;
7988         --
7989         pad_cmnt_to_rsnd_lit(
7990                           p_person_id            => p_person_id
7991                           ,p_business_group_id   => p_business_group_id
7992                           ,p_effective_date      => p_effective_date
7993                           ,p_ler_id              => null
7994                           ,p_per_in_ler_id       => p_per_in_ler_id
7995                           ,p_cmnt_txt            => l_resnd_cmnt_txt
7996                          );
7997         --
7998      end if;
7999      --
8000   else
8001      --
8002      -- Now compare the enrollment results and decide whether to restore or
8003      -- not.
8004      comp_rslts_n_process (
8005          p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id,
8006          p_per_in_ler_id            => p_per_in_ler_id,
8007          p_person_id                => p_person_id,
8008          p_business_group_id        => p_business_group_id,
8009          p_effective_date           => p_effective_date);
8010      --
8011   end if;
8012   --
8013   hr_utility.set_location('Leaving:'|| l_proc, 10);
8014   --
8015 end p_lf_evt_clps_restore_old;
8016 -- New reinstate Enrollment routine
8017 */
8018 --
8019 procedure reinstate_prev_enrt_for_popl(
8020                              p_bckdt_pen_table     in g_bckdt_pen_tbl
8021                             ,p_epe_table           in ben_reinstate_epe_cache.g_pilepe_inst_tbl
8022                             ,p_pgm_table       in out nocopy g_pgm_table
8023                             ,p_pl_table        in out nocopy g_pl_table
8024                             ,p_enrt_table      in out nocopy g_enrt_table
8025                             ,p_person_id           in number
8026                             ,p_pgm_id              in number
8027                             ,p_pl_id               in number
8028                             ,p_business_group_id   in number
8029                             ,p_effective_date      in date
8030                             ,p_per_in_ler_id       in number
8031                             ,p_bckdt_per_in_ler_id in number
8032                             ,p_enrt_perd_strt_dt   in date
8033                             ,p_max_enrt_esd        out nocopy date
8034                            ) is
8035   --
8036   l_proc                    varchar2(72) := g_package||'.reinstate_prev_enrt_for_popl';
8037   --
8038   cursor c_bckdt_pil is
8039     select pil.PRVS_STAT_CD, pil.object_version_number, pil.BCKT_PER_IN_LER_ID
8040     from ben_per_in_ler pil
8041     where pil.per_in_ler_id = p_bckdt_per_in_ler_id
8042       and pil.business_group_id = p_business_group_id;
8043   --
8044   l_bckt_csd_per_in_ler_id  number;
8045   l_bckdt_pil_prev_stat_cd  varchar2(80);
8046   l_bckdt_pil_ovn           number;
8047   l_date                    date;
8048   l_procd_dt                date;
8049   l_strtd_dt                date;
8050   l_voidd_dt                date;
8051   --
8052   l_bckdt_pen_count         number := 0 ;
8053   l_bckdt_pen_rec           g_bckdt_pen%rowtype;
8054   --
8055   -- Get the enrollment results from the backup table for backed out pil.
8056   --
8057   l_epe_pen_rec ben_reinstate_epe_cache.g_pilepe_inst_row;
8058   --
8059   cursor c_bnft(cp_elig_per_elctbl_chc_id in number,cp_ordr_num number ) is
8060      select enb.enrt_bnft_id,
8061             enb.entr_val_at_enrt_flag,
8062             enb.dflt_val,
8063             enb.val,
8064             enb.dflt_flag,
8065             enb.cvg_mlt_cd   --Bug 3315323
8066       from  ben_enrt_bnft enb
8067       where enb.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
8068   -- Bug  2526994 we need take the right one
8069   --    and   nvl(enb.mx_wo_ctfn_flag,'N') = 'N' ;
8070         and enb.ordr_num = cp_ordr_num ; --This is more accurate
8071   --
8072   l_bnft_rec            c_bnft%rowtype;
8073   l_bnft_rec_reset      c_bnft%rowtype;
8074   l_bnft_entr_val_found boolean;
8075   l_num_bnft_recs       number := 0;
8076   --
8077   cursor c_rt(cp_elig_per_elctbl_chc_id number,
8078               cp_enrt_bnft_id           number) is
8079       select ecr.enrt_rt_id,
8080              ecr.dflt_val,
8081              ecr.val,
8082              ecr.entr_val_at_enrt_flag,
8083              ecr.acty_base_rt_id
8084       from   ben_enrt_rt ecr
8085       where  ecr.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
8086       and    ecr.business_group_id = p_business_group_id
8087       and    ecr.entr_val_at_enrt_flag = 'Y'
8088       and    ecr.spcl_rt_enrt_rt_id is null
8089   --    and    ecr.prtt_rt_val_id is null
8090       union
8091       select ecr.enrt_rt_id,
8092              ecr.dflt_val,
8093              ecr.val,
8094              ecr.entr_val_at_enrt_flag,
8095              ecr.acty_base_rt_id
8096       from   ben_enrt_rt ecr
8097       where  ecr.enrt_bnft_id = cp_enrt_bnft_id
8098       and    ecr.business_group_id = p_business_group_id
8099       and    ecr.entr_val_at_enrt_flag = 'Y'
8100       and    ecr.spcl_rt_enrt_rt_id is null;
8101   --    and    ecr.prtt_rt_val_id is null;
8102   --
8103   l_rt c_rt%rowtype;
8104   --
8105   type g_rt_rec is record
8106       (enrt_rt_id ben_enrt_rt.enrt_rt_id%type,
8107        dflt_val   ben_enrt_rt.dflt_val%type,
8108        calc_val   ben_enrt_rt.dflt_val%type,
8109        cmcd_rt_val number,
8110        ann_rt_val  number);
8111   --
8112   type g_rt_table is table of g_rt_rec index by binary_integer;
8113   --
8114   l_rt_table g_rt_table;
8115   l_count    number;
8116   --
8117   type t_prtt_rt_val_table is table of number index by binary_integer;
8118   --
8119   l_pgm_table     g_pgm_table := p_pgm_table ;
8120   l_pl_table      g_pl_table  := p_pl_table ;
8121   l_enrt_table    g_enrt_table:= p_enrt_table ;
8122   l_pgm_count     number;
8123   l_pl_count      number;
8124   l_enrt_count    number;
8125   l_prtt_rt_val_table t_prtt_rt_val_table;
8126   --
8127   cursor c_prv(cv_prtt_enrt_rslt_id in number,
8128                cv_acty_base_rt_id   in number) is
8129          select  prv.*
8130          from ben_prtt_rt_val prv
8131          where prv.prtt_enrt_rslt_id      = cv_prtt_enrt_rslt_id
8132            and prv.per_in_ler_id     = p_bckdt_per_in_ler_id
8133            and prv.business_group_id = p_business_group_id
8134            and prv.acty_base_rt_id   = cv_acty_base_rt_id;
8135   --
8136   --
8137   l_prv_rec c_prv%rowtype;
8138   l_prv_rec_nulls c_prv%rowtype;
8139   --
8140   cursor c_bckt_csd_pen(cv_per_in_ler_id in number) is
8141          select pen.*, pil.lf_evt_ocrd_dt
8142          from ben_prtt_enrt_rslt_f pen,
8143               ben_per_in_ler pil
8144          where pen.per_in_ler_id = cv_per_in_ler_id
8145            and pen.per_in_ler_id = pil.per_in_ler_id
8146            and pen.business_group_id = p_business_group_id
8147            and pil.business_group_id = p_business_group_id
8148            and pen.prtt_enrt_rslt_stat_cd is null
8149            and pen.effective_end_date = hr_api.g_eot
8150            and pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
8151            and (pen.enrt_cvg_thru_dt is null or
8152                 pen.enrt_cvg_thru_dt    = hr_api.g_eot
8153                );
8154   type t_bckt_csd_pen_table is table of c_bckt_csd_pen%rowtype index by binary_integer;
8155   l_bckt_csd_pil_enrt_table t_bckt_csd_pen_table;
8156   l_bckt_csd_pen_esd        date;
8157   l_bckt_csd_pil_leod       date;
8158   --
8159   --
8160   cursor c_prv_ovn (v_prtt_rt_val_id number) is
8161     select prv.*
8162           ,abr.input_value_id
8163           ,abr.element_type_id
8164     from   ben_prtt_rt_val  prv,
8165            ben_acty_base_rt_f abr
8166     where  prtt_rt_val_id = v_prtt_rt_val_id
8167        and abr.acty_base_rt_id=prv.acty_base_rt_id
8168        and abr.business_group_id = p_business_group_id
8169        and p_effective_date between
8170              abr.effective_start_date and abr.effective_end_date;
8171   --
8172   --
8173   l_upd_rt_val            boolean;
8174   l_prv_ovn               c_prv_ovn%rowtype;
8175   l_suspend_flag          varchar2(30);
8176   l_prtt_rt_val_id1       number;
8177   l_prtt_rt_val_id2       number;
8178   l_prtt_rt_val_id3       number;
8179   l_prtt_rt_val_id4       number;
8180   l_prtt_rt_val_id5       number;
8181   l_prtt_rt_val_id6       number;
8182   l_prtt_rt_val_id7       number;
8183   l_prtt_rt_val_id8       number;
8184   l_prtt_rt_val_id9       number;
8185   l_prtt_rt_val_id10      number;
8186   l_effective_start_date  date;
8187   l_effective_end_date    date;
8188   l_dpnt_actn_warning     boolean;
8189   l_bnf_actn_warning      boolean;
8190   l_ctfn_actn_warning     boolean;
8191   l_prtt_enrt_interim_id  number;
8192   l_prtt_enrt_rslt_id     number;
8193   l_object_version_number number;
8194   l_cls_enrt_flag         boolean := FALSE;
8195   l_prev_pgm_id           number := NULL; -- Do not change it
8196   l_enrt_mthd_cd          varchar2(30);
8197   l_found                 boolean;
8198   l_enrt_cnt              number := 1;
8199   l_max_enrt_esd          date;
8200   l_esd_out               date;
8201   l_eed_out               date;
8202   l_ovn                   number(15);
8203   l_proc_cd               varchar2(30);
8204   --
8205   l_found_non_automatics  boolean;
8206   l_dummy_number          number;
8207   l_susp_interim_same_epe varchar(1):= 'N'; --Bug 14059090
8208   --
8209   l_enrt_cvg_strt_dt     date;
8210 
8211   /* Bug 9307262:Moved the fix done for Bug 7426609 from procedure 'reinstate_the_prev_enrt' to 'reinstate_prev_enrt_for_popl'*/
8212   /*Added for Bug 7426609*/
8213  cursor c_get_epe_id(c_prtt_enrt_rslt_id number,c_per_in_ler_id number) is
8214    select elig_per_elctbl_chc_id from ben_elig_per_elctbl_chc epe,
8215 		ben_prtt_enrt_rslt_f pen
8216 		where pen.prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
8217 		and pen.per_in_ler_id = c_per_in_ler_id
8218 		and epe.per_in_ler_id=pen.per_in_ler_id
8219 		and epe.pl_id=pen.pl_id
8220 		and    nvl(epe.pgm_id,-1) = nvl(pen.pgm_id,-1)
8221 		and    nvl(epe.oipl_id,-1) = nvl(pen.oipl_id,-1);
8222 		--and    epe.crntly_enrd_flag = 'Y';
8223 
8224 cursor c_interim_bnft(p_elig_per_elctbl_chc_id number) is
8225         select enb.val bnft_amt,
8226         enb.enrt_bnft_id
8227         from   ben_enrt_bnft enb
8228         where  enb.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
8229 		--Bug 14059090
8230 		and  ((l_susp_interim_same_epe = 'Y' and enb.ordr_num in (0))
8231              or (l_susp_interim_same_epe = 'N' and enb.ordr_num in (-1,1)))
8232   --     and    enb.ordr_num in (-1,1)
8233 	order by enb.ordr_num;
8234 
8235 l_int_bnft_amt c_interim_bnft%rowtype;
8236 l_sus_bnft_amt c_interim_bnft%rowtype;
8237 
8238 cursor c_get_new_epe_id( c_elig_per_elctbl_chc_id number) is
8239 select newchc.elig_per_elctbl_chc_id
8240 from ben_elig_per_elctbl_chc oldchc,
8241 ben_elig_per_elctbl_chc newchc
8242 where oldchc.elig_per_elctbl_chc_id = c_elig_per_elctbl_chc_id
8243 and newchc.per_in_ler_id = p_per_in_ler_id
8244 and newchc.pl_id = oldchc.pl_id
8245 and nvl(oldchc.pgm_id,-1) = nvl(newchc.pgm_id,-1)
8246 and nvl(oldchc.oipl_id,-1) = nvl(newchc.oipl_id,-1);
8247 
8248 l_interim_chc_id number;
8249 
8250 cursor c_prev_pil is
8251 select pil.per_in_ler_id
8252     from   ben_per_in_ler pil,
8253            ben_ler_f ler
8254     where  pil.per_in_ler_id not in (p_per_in_ler_id)
8255     and    pil.person_id     = p_person_id
8256     and    pil.ler_id        = ler.ler_id
8257     and    p_effective_date between
8258            ler.effective_start_date and ler.effective_end_date
8259     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
8260     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
8261     and    pil.lf_evt_ocrd_dt in (select max(lf_evt_ocrd_dt)
8262 				 from ben_per_in_ler pil2,
8263 				      ben_ler_f ler1
8264 				 where pil2.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD')
8265 				    and pil2.person_id = p_person_id
8266 				    and    pil2.ler_id        = ler1.ler_id
8267 				    and    p_effective_date between
8268 					   ler1.effective_start_date and ler1.effective_end_date
8269 				    and    ler1.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
8270 				    and pil2.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
8271 							      per_in_ler_id = p_per_in_ler_id)
8272                                 );
8273 
8274 cursor c_prev_pil_epe_id( c_elig_per_elctbl_chc_id number,c_per_in_ler_id number) is
8275 select prevepe.elig_per_elctbl_chc_id
8276 from ben_elig_per_elctbl_chc prevepe,
8277      ben_elig_per_elctbl_chc newepe,
8278      ben_prtt_enrt_rslt_f prevpen
8279 where newepe.elig_per_elctbl_chc_id = c_elig_per_elctbl_chc_id
8280 and prevepe.per_in_ler_id = c_per_in_ler_id
8281 and newepe.pl_id = prevepe.pl_id
8282 and nvl(prevepe.pgm_id,-1) = nvl(newepe.pgm_id,-1)
8283 and nvl(prevepe.oipl_id,-1) = nvl(newepe.oipl_id,-1)
8284 and prevpen.prtt_enrt_rslt_id = prevepe.prtt_enrt_rslt_id
8285 and prevpen.enrt_cvg_thru_dt = hr_api.g_eot
8286 --and prevpen.effective_end_date = hr_api.g_eot
8287 and prevpen.prtt_enrt_rslt_stat_cd is null;
8288 
8289 l_prev_pil_id number;
8290 l_prev_pil_sus_epe_id number;
8291 l_prev_pil_int_epe_id number;
8292 l_prev_sus_bnft_amt number;
8293 l_prev_int_bnft_amt number;
8294 l_prev_sus_bnf_id number;
8295 l_prev_int_bnf_id number;
8296 l_susp_epe_id number;
8297 l_new_susp_epe_id number;
8298 /*End of Bug 7422609*/
8299 
8300 /*Bug 9538592: Cursor to check whether the enrollment is an interim enrollment
8301 and suspended and interim enrollment have the same plan,option and plan type*/
8302 cursor c_prev_pil_epe_id1(c_prev_pil_id number,c_epe_id number) is
8303 select epe.elig_per_elctbl_chc_id,
8304        pen.prtt_enrt_rslt_id,
8305        pen.bnft_amt,
8306        epe.object_version_number
8307 from
8308        ben_elig_per_elctbl_chc epe,
8309        ben_prtt_enrt_rslt_f pen,
8310        ben_enrt_bnft bnft
8311 where pen.per_in_ler_id = c_prev_pil_id
8312       and pen.pl_id = epe.pl_id
8313       and pen.pgm_id = epe.pgm_id
8314       and pen.pl_typ_id = epe.pl_typ_id
8315       and nvl(pen.oipl_id,-1) = nvl(epe.oipl_id,-1)
8316       and epe.elig_per_elctbl_chc_id = c_epe_id
8317       and pen.prtt_enrt_rslt_stat_cd is null
8318       and bnft.elig_per_elctbl_chc_id = epe.elig_per_elctbl_chc_id
8319       and exists
8320           (select '1' from
8321 	     ben_prtt_enrt_rslt_f pen1
8322 	     where pen1.RPLCS_SSPNDD_RSLT_ID = pen.prtt_enrt_rslt_id
8323 	     and pen1.per_in_ler_id = pen.per_in_ler_id
8324 	     and pen1.prtt_enrt_rslt_stat_cd is null
8325 	     and pen.pl_id = pen1.pl_id
8326 	     and pen.pgm_id = pen1.pgm_id
8327 	     and pen.pl_typ_id = pen1.pl_typ_id
8328 	     and nvl(pen.oipl_id,-1) = nvl(pen1.oipl_id,-1));
8329 
8330  l_prev_pil_epe_id1 c_prev_pil_epe_id1%rowtype;
8331  /*End Bug 9538592*/
8332   --
8333 begin
8334   --
8335   hr_utility.set_location('Entering ' || l_proc,10);
8336   --
8337   open c_bckdt_pil;
8338   fetch c_bckdt_pil into l_bckdt_pil_prev_stat_cd, l_bckdt_pil_ovn, l_bckt_csd_per_in_ler_id;
8339   close c_bckdt_pil;
8340   if l_bckdt_pil_prev_stat_cd = 'PROCD' then
8341      --
8342      l_cls_enrt_flag := TRUE;
8343      --
8344   end if;
8345   -- l_pgm_table.delete;
8346   -- l_pl_table.delete;
8347   -- l_enrt_table.delete;
8348   l_bckt_csd_pil_enrt_table.delete;
8349   --
8350   -- Get the enrollment results attached to per in ler which
8351   -- caused the back out of currenlty backed out per in ler.
8352   --
8353   if l_bckt_csd_per_in_ler_id is not null then
8354      --
8355      for l_bckt_csd_pen_rec in c_bckt_csd_pen(l_bckt_csd_per_in_ler_id) loop
8356          --
8357          l_bckt_csd_pil_enrt_table(l_enrt_cnt) := l_bckt_csd_pen_rec;
8358          l_enrt_cnt := l_enrt_cnt + 1;
8359          --
8360      end loop;
8361      --
8362   end if;
8363   --
8364   -- For each of the enrollment result in back up table, create
8365   -- a enrollment.
8366   --
8367   l_bckdt_pen_count  := p_bckdt_pen_table.COUNT;
8368   for l_pen_record in 1..l_bckdt_pen_count loop
8369     --
8370     l_bckdt_pen_rec := p_bckdt_pen_table(l_pen_record);
8371 
8372          /* Added for Bug 7426609*/
8373 	     g_reinstate_interim_flag := false;
8374              g_reinstate_interim_chc_id := null;
8375 	 /* End of Bug 7426609*/
8376     --
8377     --
8378     -- If the enrollment record is valid for the current
8379     -- effective_date then recreate the enrollment.
8380     --
8381     hr_utility.set_location('Inside BCKDT pen loop ' || l_proc,20);
8382     --
8383     --
8384     l_bckt_csd_pen_esd  := null;
8385     l_bckt_csd_pil_leod := null;
8386     if nvl(l_bckt_csd_pil_enrt_table.last,0) > 0 then
8387        --
8388        for l_cnt in 1..l_bckt_csd_pil_enrt_table.LAST loop
8389            --
8390            if nvl(l_bckt_csd_pil_enrt_table(l_cnt).pl_id, -1) = nvl(l_bckdt_pen_rec.pl_id, -1) and
8391               nvl(l_bckt_csd_pil_enrt_table(l_cnt).pgm_id, -1) = nvl(l_bckdt_pen_rec.pgm_id, -1) and
8392               nvl(l_bckt_csd_pil_enrt_table(l_cnt).oipl_id, -1) = nvl(l_bckdt_pen_rec.oipl_id, -1)
8393            then
8394                  l_bckt_csd_pen_esd := l_bckt_csd_pil_enrt_table(l_cnt).effective_start_date;
8395                  l_bckt_csd_pil_leod := l_bckt_csd_pil_enrt_table(l_cnt).lf_evt_ocrd_dt;
8396                  exit;
8397            end if;
8398            --
8399        end loop;
8400        --
8401     end if;
8402     --
8403     --
8404     l_epe_pen_rec := p_epe_table(l_pen_record);
8405     --
8406     hr_utility.set_location('After epe fetch ' || l_proc,30);
8407     --
8408     g_sys_date := greatest(trunc(p_enrt_perd_strt_dt),
8409                     nvl(nvl(l_bckt_csd_pen_esd, g_bckt_csd_lf_evt_ocrd_dt), hr_api.g_sot),
8410                     l_bckdt_pen_rec.effective_start_date);
8411     --
8412     l_max_enrt_esd := greatest(g_sys_date, nvl(l_max_enrt_esd, hr_api.g_sot));
8413     --
8414     --
8415     hr_utility.set_location('Date used to reinstate the enrollment = ' || g_sys_date, 333);
8416     --
8417     if g_sys_date <= l_bckdt_pen_rec.effective_end_date
8418     then
8419        --
8420        -- Get the benefits Information.
8421        --
8422        l_num_bnft_recs := 0;
8423        l_bnft_entr_val_found := FALSE;
8424        l_bnft_rec := l_bnft_rec_reset;
8425        --
8426        open c_bnft(l_epe_pen_rec.elig_per_elctbl_chc_id,l_bckdt_pen_rec.bnft_ordr_num );
8427        loop
8428          --
8429          hr_utility.set_location('Inside bnft loop ' || l_proc,40);
8430          --Bug 3315323 we need to reinstate the previuos benefit amount for the case
8431          --of SAAEAR also as enb record may have null value there for first enrollment
8432          --or it may not be the right amount.
8433          --
8434          fetch c_bnft into l_bnft_rec;
8435          exit when c_bnft%notfound;
8436          if l_bnft_rec.entr_val_at_enrt_flag = 'Y' OR l_bnft_rec.cvg_mlt_cd='SAAEAR' then
8437             l_bnft_entr_val_found := TRUE;
8438          end if;
8439          l_num_bnft_recs := l_num_bnft_recs + 1;
8440          --
8441          if l_bckdt_pen_rec.BNFT_AMT = l_bnft_rec.VAL then
8442             --
8443             -- Found the benefit we are looking for, so exit.
8444             --
8445             exit;
8446             --
8447          end if;
8448          --
8449        end loop;
8450        --
8451        -- Bug 5282 :  When a backed out life event is repeocessed
8452        -- plans with enter 'enter val at enrollment' coverage amount
8453        -- previous amount is not used when enrollments reinstated.
8454        --
8455        if l_bnft_entr_val_found
8456        then
8457          if l_num_bnft_recs =  0 then
8458             null;
8459             -- This is a error condition, so rollback all the reinstate process.
8460          else
8461             --
8462             l_bnft_rec.val := l_bckdt_pen_rec.BNFT_AMT;
8463             --
8464          end if;
8465        end if;
8466        hr_utility.set_location(l_proc,50);
8467        close c_bnft;
8468        --
8469        for l_count in 1..10 loop
8470           --
8471           -- Initialise array to null
8472           --
8473           l_rt_table(l_count).enrt_rt_id := null;
8474           l_rt_table(l_count).dflt_val := null;
8475           --
8476        end loop;
8477        --
8478        -- Now get the rates.
8479        --
8480        l_count:= 0;
8481        --
8482        for l_rec in c_rt(l_epe_pen_rec.elig_per_elctbl_chc_id,
8483                          l_bnft_rec.enrt_bnft_id)
8484        loop
8485           --
8486           hr_utility.set_location('Inside rate loop ' ||l_proc,50);
8487           --
8488           -- Get the prtt rate val for this enrollment result.
8489           -- Use to pass to the enrollment process.
8490           --
8491           -- Bug : 1634870 : If the user not selected the rate before backout
8492           -- then do not pass it to the reinstate process.
8493           --
8494           hr_utility.set_location('enrt_rt_id : dflt_val : val : entr_val' ||
8495                                   '_at_enrt_flag : acty_base_rt_id : ' , 501);
8496           hr_utility.set_location(l_rec.enrt_rt_id || ' : ' || l_rec.dflt_val || ' : ' || l_rec.val || ' : '
8497                                   || l_rec.entr_val_at_enrt_flag || ' : ' ||
8498                                   l_rec.acty_base_rt_id, 501);
8499           --
8500           l_prv_rec := l_prv_rec_nulls;
8501           open c_prv(l_bckdt_pen_rec.prtt_enrt_rslt_id ,
8502                      l_rec.acty_base_rt_id);
8503           fetch c_prv into l_prv_rec;
8504           if c_prv%found then -- l_prv_rec.prtt_rt_val_id is not null then
8505              --
8506              l_count := l_count+1;
8507              hr_utility.set_location('prtt_rt_val_id : rt_val : ' ||
8508                      l_prv_rec.prtt_rt_val_id ||  ' : ' || l_prv_rec.rt_val
8509                      || ' : ' || l_prv_rec.acty_base_rt_id , 502);
8510              l_rt_table(l_count).enrt_rt_id := l_rec.enrt_rt_id;
8511              if l_prv_rec.mlt_cd in ('CL','CVG','AP','PRNT','CLANDCVG','APANDCVG','PRNTANDCVG') then
8512                 l_rt_table(l_count).dflt_val := l_rec.dflt_val;
8513                 l_rt_table(l_count).calc_val := l_prv_rec.rt_val;
8514                 l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
8515                 l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
8516              else
8517                 l_rt_table(l_count).dflt_val   := l_prv_rec.rt_val;
8518                 l_rt_table(l_count).calc_val   := l_prv_rec.rt_val;
8519                 l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
8520                 l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
8521              end if;
8522              --
8523           end if;
8524           close c_prv;
8525           --
8526        end loop;
8527        --
8528        -- Call election information batch process
8529        --
8530        -- initialize all the out parameters.
8531        l_suspend_flag          := null;
8532        l_prtt_rt_val_id1       := null;
8533        l_prtt_rt_val_id2       := null;
8534        l_prtt_rt_val_id3       := null;
8535        l_prtt_rt_val_id4       := null;
8536        l_prtt_rt_val_id5       := null;
8537        l_prtt_rt_val_id6       := null;
8538        l_prtt_rt_val_id7       := null;
8539        l_prtt_rt_val_id8       := null;
8540        l_prtt_rt_val_id9       := null;
8541        l_prtt_rt_val_id10      := null;
8542        l_effective_start_date  := null;
8543        l_effective_end_date    := null;
8544        l_dpnt_actn_warning     := null;
8545        l_bnf_actn_warning      := null;
8546        l_ctfn_actn_warning     := null;
8547        l_prtt_enrt_interim_id  := null;
8548        l_prtt_enrt_rslt_id     := null;
8549        l_object_version_number := null;
8550        l_enrt_cvg_strt_dt      := null;
8551 
8552        -- if cvg_st_dt_cd is enterable then copy the l_bckdt_pen_rec.enrt_cvg_strt_dt
8553        -- 5746429 starts
8554 
8555        if  l_epe_pen_rec.enrt_cvg_strt_dt_cd = 'ENTRBL'
8556         then
8557 	      l_enrt_cvg_strt_dt := l_bckdt_pen_rec.enrt_cvg_strt_dt ;
8558        end if ;
8559        -- 5746429 ends
8560        --
8561        hr_utility.set_location('Calling ben_election_information ' ||l_proc,60);
8562        hr_utility.set_location('Calling l_bnft_rec.val ' ||l_bnft_rec.val,60);
8563        hr_utility.set_location('Calling l_enrt_cvg_strt_dt ' ||l_enrt_cvg_strt_dt,60);
8564        --
8565 
8566        /*Added for Bug 7426609 */
8567        /* Get the old epe id of the Interim from the backed out pen records.  */
8568        hr_utility.set_location('Suspended Flag  ' ||l_bckdt_pen_rec.SSPNDD_FLAG,60);
8569        hr_utility.set_location('Interim Rslt Id  ' ||l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID,60);
8570        hr_utility.set_location('P_per_in_ler_id  ' ||p_per_in_ler_id,60);
8571 
8572 
8573        if(l_bckdt_pen_rec.SSPNDD_FLAG = 'Y' and l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID is not NULL) then
8574 		l_prev_pil_id := null;
8575 		l_prev_pil_sus_epe_id := null;
8576 		l_prev_pil_int_epe_id := null;
8577 		l_prev_sus_bnft_amt := null;
8578 		l_prev_int_bnft_amt := null;
8579 		l_prev_sus_bnf_id := null;
8580 		l_prev_int_bnf_id := null;
8581 		l_susp_epe_id := null;
8582 		l_new_susp_epe_id := null;
8583 		/* Bug 10416289: While reinstating the second set of suspended enrollments, if
8584 		Interim is a Waive plan, ben table will not have a record for benefit amount.Cursor c_interim_bnft will not fetch any record
8585 		for interim enrollment. But l_int_bnft_amt will have the values of first suspended enrollment result that is reinstated.
8586 		Since the condition (l_prev_int_bnft_amt,-1) = nvl(l_int_bnft_amt.bnft_amt,-1) is not satisfied, interim is not created for second
8587 		suspended result. Initialize the variables to NULL. */
8588 		l_sus_bnft_amt := null;
8589 		l_int_bnft_amt := null;
8590 
8591              open c_prev_pil;
8592 	     fetch c_prev_pil into l_prev_pil_id;
8593 	     close c_prev_pil;
8594 	     hr_utility.set_location('Prev per_in_ler_id='||l_prev_pil_id,9995);
8595 
8596 	     /* Get new and old suspended epe id */
8597 	     open c_get_epe_id(l_bckdt_pen_rec.prtt_enrt_rslt_id,l_bckdt_pen_rec.per_in_ler_id);
8598 	     fetch c_get_epe_id into l_susp_epe_id;
8599 	     close c_get_epe_id;
8600 	     hr_utility.set_location('Old Susp_chc='||l_susp_epe_id,9995);
8601 
8602 	     open c_get_new_epe_id(l_susp_epe_id);
8603 	     fetch c_get_new_epe_id into l_new_susp_epe_id;
8604 	     close c_get_new_epe_id;
8605 	     hr_utility.set_location('New Susp_chc='||l_new_susp_epe_id,9995);
8606 
8607 	     open c_interim_bnft(l_new_susp_epe_id);
8608 	     fetch c_interim_bnft into l_sus_bnft_amt;
8609 	     close c_interim_bnft;
8610 
8611 	     open c_prev_pil_epe_id(l_new_susp_epe_id,l_prev_pil_id);
8612 	     fetch c_prev_pil_epe_id into l_prev_pil_sus_epe_id;
8613 	     close c_prev_pil_epe_id;
8614 	     hr_utility.set_location('Prev Susp_chc='||l_prev_pil_sus_epe_id,9995);
8615 
8616 	     if(l_prev_pil_sus_epe_id is not null) then
8617 		 open c_interim_bnft(l_prev_pil_sus_epe_id);
8618 		 fetch c_interim_bnft into l_prev_sus_bnft_amt,l_prev_sus_bnf_id;
8619 		 close c_interim_bnft;
8620 		 hr_utility.set_location('Prev Susp bnft amt='||l_prev_sus_bnft_amt,9995);
8621 		      if( nvl(l_prev_sus_bnft_amt,-1) = nvl(l_sus_bnft_amt.bnft_amt,-1) ) then
8622 
8623 			     /* Get new and old interim epe id */
8624 			     open c_get_epe_id(l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID,l_bckdt_pen_rec.per_in_ler_id);
8625 			     fetch c_get_epe_id into g_reinstate_interim_chc_id;
8626 			     close c_get_epe_id;
8627 
8628 			     open c_get_new_epe_id(g_reinstate_interim_chc_id);
8629 			     fetch c_get_new_epe_id into l_interim_chc_id;
8630 			     close c_get_new_epe_id;
8631 			     g_reinstate_interim_chc_id := l_interim_chc_id;
8632 			     hr_utility.set_location('New interim_chc='||g_reinstate_interim_chc_id,9995);
8633 
8634 				 --Bug 14059090
8635                  if l_interim_chc_id = l_new_susp_epe_id
8636                  then
8637                      l_susp_interim_same_epe := 'Y';
8638                  end if;
8639 				 --Bug 14059090
8640 
8641 			     open c_interim_bnft(l_interim_chc_id/*ben_lf_evt_clps_restore.g_reinstate_interim_chc_id*/ );
8642 			     fetch c_interim_bnft into l_int_bnft_amt;
8643 			     close c_interim_bnft;
8644 
8645 			     open c_prev_pil_epe_id(l_interim_chc_id,l_prev_pil_id);
8646 			     fetch c_prev_pil_epe_id into l_prev_pil_int_epe_id;
8647 			     close c_prev_pil_epe_id;
8648 			     hr_utility.set_location('Prev epe id='||l_prev_pil_int_epe_id,9995);
8649 
8650 			     if(l_prev_pil_int_epe_id is not null) then
8651 				 open c_interim_bnft(l_prev_pil_int_epe_id);
8652 				 fetch c_interim_bnft into l_prev_int_bnft_amt,l_prev_int_bnf_id;
8653 				 close c_interim_bnft;
8654 				 hr_utility.set_location('Prev bnft amt='||l_prev_int_bnft_amt,9995);
8655 				      if( nvl(l_prev_int_bnft_amt,-1) = nvl(l_int_bnft_amt.bnft_amt,-1) ) then
8656 					  ben_lf_evt_clps_restore.g_reinstate_interim_flag := true;
8657 					  hr_utility.set_location('Value set to true ',9995);
8658 				       end if;
8659 			     end if;
8660 				 l_susp_interim_same_epe := 'N'; --Bug 14059090
8661           		 end if;
8662               	 end if;
8663 	   hr_utility.set_location('Interim chc id  ' ||g_reinstate_interim_chc_id,60);
8664        end if;
8665        /*Ended for Bug 7426609 */
8666        --
8667 
8668        /* Bug 9538592:In a case where epe table has only one record for the plan and interim and suspended enrollments corresponds to same plan and opton,
8669        resinstating the enrollments of the backedout life event, pen_id in epe table is set with the suspended enrollment result of the previous life event.
8670        Set the pen_id to interim enrollment result*/
8671        if(l_bckdt_pen_rec.SSPNDD_FLAG <> 'Y') then
8672           hr_utility.set_location('Inside if cond  ',909);
8673 	  open c_prev_pil;
8674 	  fetch c_prev_pil into l_prev_pil_id;
8675 	  close c_prev_pil;
8676 	  hr_utility.set_location('Prev per_in_ler_id='||l_prev_pil_id,909);
8677 	  open c_prev_pil_epe_id1(l_prev_pil_id,l_epe_pen_rec.elig_per_elctbl_chc_id);
8678 	  fetch c_prev_pil_epe_id1 into l_prev_pil_epe_id1;
8679 	  if(c_prev_pil_epe_id1%found and l_bnft_rec.val = l_prev_pil_epe_id1.bnft_amt) then
8680 	     hr_utility.set_location('Before updating epe ',909);
8681              hr_utility.set_location('prev pen_id '||l_prev_pil_epe_id1.prtt_enrt_rslt_id,909);
8682 	     ben_ELIG_PER_ELC_CHC_api.update_ELIG_PER_ELC_CHC
8683 			(p_validate                => FALSE
8684 			 ,p_elig_per_elctbl_chc_id  => l_epe_pen_rec.elig_per_elctbl_chc_id
8685 			 ,p_prtt_enrt_rslt_id       => l_prev_pil_epe_id1.prtt_enrt_rslt_id
8686 			 ,p_object_version_number   => l_prev_pil_epe_id1.object_version_number
8687 			 ,p_effective_date          => g_sys_date
8688 			 );
8689 
8690 			 g_create_new_result := 'Y';
8691 	  end if;
8692 	  close c_prev_pil_epe_id1;
8693        end if;
8694        /*End of Bug 9538592*/
8695 
8696        ben_election_information.election_information
8697           (p_elig_per_elctbl_chc_id => l_epe_pen_rec.elig_per_elctbl_chc_id,
8698            p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,-- l_epe_pen_rec.prtt_enrt_rslt_id,
8699            p_effective_date         => g_sys_date,
8700            p_enrt_mthd_cd           => l_bckdt_pen_rec.enrt_mthd_cd,
8701            p_business_group_id      => p_business_group_id,
8702            p_enrt_bnft_id           => l_bnft_rec.enrt_bnft_id,
8703            p_bnft_val               => l_bnft_rec.val,
8704 	       p_enrt_cvg_strt_dt       => l_enrt_cvg_strt_dt, -- 5746429
8705            p_enrt_rt_id1            => l_rt_table(1).enrt_rt_id,
8706            p_rt_val1                => l_rt_table(1).dflt_val,
8707            p_ann_rt_val1            => l_rt_table(1).ann_rt_val,
8708            p_enrt_rt_id2            => l_rt_table(2).enrt_rt_id,
8709            p_rt_val2                => l_rt_table(2).dflt_val,
8710            p_ann_rt_val2            => l_rt_table(2).ann_rt_val,
8711            p_enrt_rt_id3            => l_rt_table(3).enrt_rt_id,
8712            p_rt_val3                => l_rt_table(3).dflt_val,
8713            p_ann_rt_val3            => l_rt_table(3).ann_rt_val,
8714            p_enrt_rt_id4            => l_rt_table(4).enrt_rt_id,
8715            p_rt_val4                => l_rt_table(4).dflt_val,
8716            p_ann_rt_val4            => l_rt_table(4).ann_rt_val,
8717            p_enrt_rt_id5            => l_rt_table(5).enrt_rt_id,
8718            p_rt_val5                => l_rt_table(5).dflt_val,
8719            p_ann_rt_val5            => l_rt_table(5).ann_rt_val,
8720            p_enrt_rt_id6            => l_rt_table(6).enrt_rt_id,
8721            p_rt_val6                => l_rt_table(6).dflt_val,
8722            p_ann_rt_val6            => l_rt_table(6).ann_rt_val,
8723            p_enrt_rt_id7            => l_rt_table(7).enrt_rt_id,
8724            p_rt_val7                => l_rt_table(7).dflt_val,
8725            p_ann_rt_val7            => l_rt_table(7).ann_rt_val,
8726            p_enrt_rt_id8            => l_rt_table(8).enrt_rt_id,
8727            p_rt_val8                => l_rt_table(8).dflt_val,
8728            p_ann_rt_val8            => l_rt_table(8).ann_rt_val,
8729            p_enrt_rt_id9            => l_rt_table(9).enrt_rt_id,
8730            p_rt_val9                => l_rt_table(9).dflt_val,
8731            p_ann_rt_val9            => l_rt_table(9).ann_rt_val,
8732            p_enrt_rt_id10           => l_rt_table(10).enrt_rt_id,
8733            p_rt_val10               => l_rt_table(10).dflt_val,
8734            p_ann_rt_val10           => l_rt_table(10).ann_rt_val,
8735            p_datetrack_mode         => hr_api.g_insert,
8736            p_suspend_flag           => l_suspend_flag,
8737            p_called_from_sspnd      => 'N',
8738            p_prtt_enrt_interim_id   => l_prtt_enrt_interim_id,
8739            p_prtt_rt_val_id1        => l_prtt_rt_val_id1,
8740            p_prtt_rt_val_id2        => l_prtt_rt_val_id2,
8741            p_prtt_rt_val_id3        => l_prtt_rt_val_id3,
8742            p_prtt_rt_val_id4        => l_prtt_rt_val_id4,
8743            p_prtt_rt_val_id5        => l_prtt_rt_val_id5,
8744            p_prtt_rt_val_id6        => l_prtt_rt_val_id6,
8745            p_prtt_rt_val_id7        => l_prtt_rt_val_id7,
8746            p_prtt_rt_val_id8        => l_prtt_rt_val_id8,
8747            p_prtt_rt_val_id9        => l_prtt_rt_val_id9,
8748            p_prtt_rt_val_id10       => l_prtt_rt_val_id10,
8749            -- 6131609 : reinstate DFF values
8750             p_pen_attribute_category => l_bckdt_pen_rec.pen_attribute_category,
8751             p_pen_attribute1  => l_bckdt_pen_rec.pen_attribute1,
8752             p_pen_attribute2  => l_bckdt_pen_rec.pen_attribute2,
8753             p_pen_attribute3  => l_bckdt_pen_rec.pen_attribute3,
8754             p_pen_attribute4  => l_bckdt_pen_rec.pen_attribute4,
8755             p_pen_attribute5  => l_bckdt_pen_rec.pen_attribute5,
8756             p_pen_attribute6  => l_bckdt_pen_rec.pen_attribute6,
8757             p_pen_attribute7  => l_bckdt_pen_rec.pen_attribute7,
8758             p_pen_attribute8  => l_bckdt_pen_rec.pen_attribute8,
8759             p_pen_attribute9  => l_bckdt_pen_rec.pen_attribute9,
8760             p_pen_attribute10 => l_bckdt_pen_rec.pen_attribute10,
8761             p_pen_attribute11 => l_bckdt_pen_rec.pen_attribute11,
8762             p_pen_attribute12 => l_bckdt_pen_rec.pen_attribute12,
8763             p_pen_attribute13 => l_bckdt_pen_rec.pen_attribute13,
8764             p_pen_attribute14 => l_bckdt_pen_rec.pen_attribute14,
8765             p_pen_attribute15 => l_bckdt_pen_rec.pen_attribute15,
8766             p_pen_attribute16 => l_bckdt_pen_rec.pen_attribute16,
8767             p_pen_attribute17 => l_bckdt_pen_rec.pen_attribute17,
8768             p_pen_attribute18 => l_bckdt_pen_rec.pen_attribute18,
8769             p_pen_attribute19 => l_bckdt_pen_rec.pen_attribute19,
8770             p_pen_attribute20 => l_bckdt_pen_rec.pen_attribute20,
8771             p_pen_attribute21 => l_bckdt_pen_rec.pen_attribute21,
8772             p_pen_attribute22 => l_bckdt_pen_rec.pen_attribute22,
8773             p_pen_attribute23 => l_bckdt_pen_rec.pen_attribute23,
8774             p_pen_attribute24 => l_bckdt_pen_rec.pen_attribute24,
8775             p_pen_attribute25 => l_bckdt_pen_rec.pen_attribute25,
8776             p_pen_attribute26 => l_bckdt_pen_rec.pen_attribute26,
8777             p_pen_attribute27 => l_bckdt_pen_rec.pen_attribute27,
8778             p_pen_attribute28 => l_bckdt_pen_rec.pen_attribute28,
8779             p_pen_attribute29 => l_bckdt_pen_rec.pen_attribute29,
8780             p_pen_attribute30 => l_bckdt_pen_rec.pen_attribute30,
8781             --
8782            p_object_version_number  => l_object_version_number,
8783            p_effective_start_date   => l_effective_start_date,
8784            p_effective_end_date     => l_effective_end_date,
8785            p_dpnt_actn_warning      => l_dpnt_actn_warning,
8786            p_bnf_actn_warning       => l_bnf_actn_warning,
8787            p_ctfn_actn_warning      => l_ctfn_actn_warning);
8788        --
8789        -- changed 7176884 begin
8790        delete from ben_le_clsn_n_rstr
8791        where  bkup_tbl_id = l_bckdt_pen_rec.prtt_enrt_rslt_id
8792        and    per_in_ler_id = p_bckdt_per_in_ler_id
8793        and    bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_RSLT_F'
8794        and    person_id = p_person_id;
8795        -- changed 7176884 end
8796        --
8797        l_prtt_rt_val_table(1)       := l_prtt_rt_val_id1;
8798        l_prtt_rt_val_table(2)       := l_prtt_rt_val_id2;
8799        l_prtt_rt_val_table(3)       := l_prtt_rt_val_id3;
8800        l_prtt_rt_val_table(4)       := l_prtt_rt_val_id4;
8801        l_prtt_rt_val_table(5)       := l_prtt_rt_val_id5;
8802        l_prtt_rt_val_table(6)       := l_prtt_rt_val_id6;
8803        l_prtt_rt_val_table(7)       := l_prtt_rt_val_id7;
8804        l_prtt_rt_val_table(8)       := l_prtt_rt_val_id8;
8805        l_prtt_rt_val_table(9)       := l_prtt_rt_val_id9;
8806        l_prtt_rt_val_table(10)      := l_prtt_rt_val_id10;
8807 
8808 
8809        -- if rate is enter value at enrollment and calculation method is like multiple and
8810        -- calculate flag is on, first the prtt_rt_val is created with default value and
8811        -- subsequently the calculated value is updated by taking values from backedout rows
8812        for i  in 1..l_count loop
8813           l_upd_rt_val  := FALSE;
8814           open c_prv_ovn (l_prtt_rt_val_table(i));
8815           fetch c_prv_ovn into l_prv_ovn;
8816           if c_prv_ovn%found then
8817               if l_prv_ovn.rt_val <>l_rt_table(i).calc_val  then
8818                  l_upd_rt_val := TRUE;
8819               end if;
8820           end if;
8821           close c_prv_ovn;
8822           if l_upd_rt_val then
8823               ben_prtt_rt_val_api.update_prtt_rt_val
8824                 (p_prtt_rt_val_id        => l_prtt_rt_val_table(i)
8825                 ,p_person_id             => p_person_id
8826                 ,p_rt_val                => l_rt_table(i).calc_val
8827                 ,p_acty_ref_perd_cd      => l_prv_ovn.acty_ref_perd_cd
8828                 ,p_cmcd_rt_val           => l_rt_table(i).cmcd_rt_val
8829                 ,p_cmcd_ref_perd_cd      => l_prv_ovn.cmcd_ref_perd_cd
8830                 ,p_ann_rt_val            => l_rt_table(i).ann_rt_val
8831                 ,p_business_group_id     => p_business_group_id
8832                 ,p_object_version_number => l_prv_ovn.object_version_number
8833                 ,p_effective_date        => g_sys_date);
8834               --
8835           end if;
8836        end loop;
8837 
8838 
8839 
8840        -- Populate the enrollment results electble choice data
8841        -- to be used for dependents and beneficiaries restoration.
8842        -- the reinstate beneficiaries and dependents processes
8843        -- from hare as multi row edit process may create
8844        -- these records as part of recycle. So reinstate beneficiaries
8845        -- and dependents processes should be called after multi row edits.
8846        --
8847        l_found := FALSE;
8848        if nvl(l_enrt_table.LAST, 0) > 0 then
8849           for l_cnt in 1..l_enrt_table.LAST loop
8850               --
8851               if l_enrt_table(l_cnt).prtt_enrt_rslt_id = l_prtt_enrt_rslt_id
8852               then
8853                  l_found := TRUE;
8854                  exit;
8855               end if;
8856               --
8857            end loop;
8858        end if;
8859        --
8860        if not l_found then
8861           --
8862           --
8863           l_enrt_count := nvl(l_enrt_table.LAST, 0) + 1;
8864           l_enrt_table(l_enrt_count).prtt_enrt_rslt_id := l_prtt_enrt_rslt_id;
8865           l_enrt_table(l_enrt_count).effective_start_date := l_effective_start_date;
8866 	  l_enrt_table(l_enrt_count).bckdt_sspndd_flag := l_bckdt_pen_rec.sspndd_flag;
8867           l_enrt_table(l_enrt_count).bckdt_RPLCS_SSPNDD_RSLT_ID := l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID;
8868           l_enrt_table(l_enrt_count).bckdt_prtt_enrt_rslt_id
8869                                            := l_bckdt_pen_rec.prtt_enrt_rslt_id;
8870           l_enrt_table(l_enrt_count).bckdt_enrt_ovridn_flag
8871                                            := l_bckdt_pen_rec.enrt_ovridn_flag;
8872           l_enrt_table(l_enrt_count).bckdt_enrt_cvg_strt_dt
8873                                            := l_bckdt_pen_rec.enrt_cvg_strt_dt;
8874           l_enrt_table(l_enrt_count).bckdt_enrt_cvg_thru_dt
8875                                            := l_bckdt_pen_rec.enrt_cvg_thru_dt;
8876           l_enrt_table(l_enrt_count).enrt_ovrid_thru_dt
8877                                            := l_bckdt_pen_rec.enrt_ovrid_thru_dt;
8878           l_enrt_table(l_enrt_count).enrt_ovrid_rsn_cd
8879                                            := l_bckdt_pen_rec.enrt_ovrid_rsn_cd;
8880           l_enrt_table(l_enrt_count).g_sys_date := g_sys_date;
8881           l_enrt_table(l_enrt_count).pen_ovn_number := l_object_version_number;
8882           l_enrt_table(l_enrt_count).old_pl_id := l_bckdt_pen_rec.pl_id;
8883           l_enrt_table(l_enrt_count).new_pl_id := l_bckdt_pen_rec.pl_id;
8884           l_enrt_table(l_enrt_count).old_oipl_id := l_bckdt_pen_rec.oipl_id;
8885           l_enrt_table(l_enrt_count).new_oipl_id := l_bckdt_pen_rec.oipl_id;
8886           l_enrt_table(l_enrt_count).old_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
8887           l_enrt_table(l_enrt_count).new_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
8888           l_enrt_table(l_enrt_count).pgm_id := l_bckdt_pen_rec.pgm_id;
8889           l_enrt_table(l_enrt_count).ler_id := null;
8890           l_enrt_table(l_enrt_count).elig_per_elctbl_chc_id
8891                                            := l_epe_pen_rec.elig_per_elctbl_chc_id;
8892           l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_cd
8893                                            := l_epe_pen_rec.dpnt_cvg_strt_dt_cd;
8894           l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_rl
8895                                            := l_epe_pen_rec.dpnt_cvg_strt_dt_rl;
8896 	  l_enrt_table(l_enrt_count).enrt_mthd_cd := l_bckdt_pen_rec.enrt_mthd_cd; -- Bug 9045559
8897           --
8898        end if;
8899        --
8900        if l_epe_pen_rec.pgm_id is null then
8901           --
8902           l_found := FALSE;
8903           if nvl(l_pl_table.LAST, 0) > 0 then
8904              --
8905              --
8906              for l_cnt in 1..l_pl_table.LAST loop
8907                  --
8908 	         --
8909                  if l_pl_table(l_cnt).pl_id = l_epe_pen_rec.pl_id /* and  -- Bug 5685222
8910                     l_pl_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd */
8911                  then
8912                     l_found := TRUE;
8913                     l_pl_table(l_cnt).max_enrt_esd := greatest(l_pl_table(l_cnt).max_enrt_esd,
8914                                                                g_sys_date);
8915                     exit;
8916                  end if;
8917                  --
8918              end loop;
8919           end if;
8920           --
8921           if not l_found then
8922              --
8923              --
8924              l_pl_count := nvl(l_pl_table.LAST, 0) + 1;
8925              l_pl_table(l_pl_count).pl_id            := l_epe_pen_rec.pl_id;
8926              l_pl_table(l_pl_count).enrt_mthd_cd     := l_bckdt_pen_rec.enrt_mthd_cd;
8927              l_pl_table(l_pl_count).multi_row_edit_done := FALSE;
8928              l_pl_table(l_pl_count).max_enrt_esd := g_sys_date;
8929              --
8930           end if;
8931        else
8932           --
8933           l_found := FALSE;
8934           if nvl(l_pgm_table.LAST, 0) > 0 then
8935              for l_cnt in 1..l_pgm_table.LAST loop
8936                  --
8937                  if l_pgm_table(l_cnt).pgm_id = l_epe_pen_rec.pgm_id /* and
8938                     l_pgm_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd */
8939                  then
8940                     l_found := TRUE;
8941                     l_pgm_table(l_cnt).max_enrt_esd := greatest(l_pgm_table(l_cnt).max_enrt_esd,
8942                                                                g_sys_date);
8943                     exit;
8944                  end if;
8945                  --
8946              end loop;
8947           end if;
8948           --
8949           if not l_found then
8950              --
8951              --
8952              l_pgm_count := nvl(l_pgm_table.LAST, 0) + 1;
8953              l_pgm_table(l_pgm_count).pgm_id         := l_epe_pen_rec.pgm_id;
8954              l_pgm_table(l_pgm_count).enrt_mthd_cd   := l_bckdt_pen_rec.enrt_mthd_cd;
8955              l_pgm_table(l_pgm_count).multi_row_edit_done := FALSE;
8956              l_pgm_table(l_pgm_count).max_enrt_esd := g_sys_date;
8957              --
8958           end if;
8959           --
8960        end if;
8961        --
8962     end if;
8963     --
8964   end loop;
8965   --
8966   -- Apply the multi row edits.
8967   --
8968   if nvl(l_pgm_table.LAST, 0) > 0 then
8969      for l_cnt in 1..l_pgm_table.LAST loop
8970         --
8971         -- First see multi row edits are already checked.
8972         --
8973         l_found  := FALSE;
8974         for l_inn_cnt in 1..l_cnt loop
8975           if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
8976              l_pgm_table(l_inn_cnt).multi_row_edit_done
8977           then
8978              l_found  := TRUE;
8979              exit;
8980           end if;
8981         end loop;
8982         --
8983         if not l_found then
8984            --
8985            --
8986            -- Now see if there are non automatic enrollments
8987            --
8988            if l_bckdt_pil_prev_stat_cd='STRTD' then
8989              l_found_non_automatics:=FALSE;
8990              /* Bug 9045559: Instead of checking the enrollment code at the program level, check whether any
8991 	     explicit or default enrollments from the reinstated enrollment list. Commented the below loop.
8992 	     Check for explicit or default enrollments from l_enrt_table instead checking the code set at l_pgm_table level.
8993 	     For few customers Automatic enrollment record is picked up first for reinstatement and enrt_mthd_cd is set to 'A' at the
8994 	     program level. Becuase of this multi_rows_edit is not called even though default and explicit enrollments exist*/
8995              /*for l_inn_cnt in 1..l_pgm_table.last loop
8996                hr_utility.set_location('enrt mthd code'||l_pgm_table(l_inn_cnt).enrt_mthd_cd,43333);
8997                hr_utility.set_location('pgm_id '||l_pgm_table(l_inn_cnt).pgm_id,43333);
8998                if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
8999                   l_pgm_table(l_inn_cnt).enrt_mthd_cd<>'A'
9000                then
9001                   l_found_non_automatics  := TRUE;
9002                   exit;
9003                end if;
9004              end loop;*/
9005 	     /* added for Bug 9045559*/
9006              for l_inn_cnt in 1..l_enrt_table.last loop
9007                hr_utility.set_location('enrt mthd code'||l_enrt_table(l_inn_cnt).enrt_mthd_cd,43333);
9008                hr_utility.set_location('pgm table pgm_id '||l_pgm_table(l_cnt).pgm_id,43333);
9009 	       hr_utility.set_location('enrt pgm_id '||l_enrt_table(l_inn_cnt).pgm_id,43333);
9010                if l_enrt_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
9011                   l_enrt_table(l_inn_cnt).enrt_mthd_cd <> 'A'
9012                then
9013                   l_found_non_automatics  := TRUE;
9014                   exit;
9015                end if;
9016 	     end loop;
9017 	     /* End of Bug 9045559*/
9018            end if;
9019            --
9020            if l_bckdt_pil_prev_stat_cd<>'STRTD' or
9021               l_found_non_automatics then
9022              hr_utility.set_location('Date for multi row edits = ' ||
9023                                       l_pgm_table(l_cnt).max_enrt_esd || '  ' || ' pgm = ' ||
9024                                       l_pgm_table(l_cnt).pgm_id, 333);
9025              ben_prtt_enrt_result_api.multi_rows_edit
9026               (p_person_id         => p_person_id,
9027                p_effective_date    => l_pgm_table(l_cnt).max_enrt_esd,
9028                p_business_group_id => p_business_group_id,
9029                p_per_in_ler_id     => p_per_in_ler_id,
9030                p_pgm_id            => l_pgm_table(l_cnt).pgm_id);
9031              --
9032            end if;
9033            l_pgm_table(l_cnt).multi_row_edit_done := TRUE;
9034            --
9035         end if;
9036         --
9037      end loop;
9038   end if;
9039     --
9040     p_pgm_table := l_pgm_table ;
9041     p_pl_table := l_pl_table ;
9042     p_enrt_table := l_enrt_table ;
9043     p_max_enrt_esd := l_max_enrt_esd ;
9044     --
9045     hr_utility.set_location ('Leaving '||l_proc,10);
9046     --
9047   end reinstate_prev_enrt_for_popl ;
9048     --
9049   procedure reinstate_post_enrt(
9050                              p_pgm_table           in g_pgm_table
9051                             ,p_pl_table            in g_pl_table
9052                             ,p_enrt_table      in out nocopy g_enrt_table
9053                             ,p_max_enrt_esd        in date
9054                             ,p_person_id           in number
9055                             ,p_business_group_id   in number
9056                             ,p_effective_date      in date
9057                             ,p_per_in_ler_id       in number
9058                             ,p_bckdt_per_in_ler_id in number
9059                             ,p_cls_enrt_flag       in boolean default false
9060     ) is
9061     --
9062     l_proc                  varchar2(72) := g_package||'.reinstate_post_enrt';
9063     --
9064     l_proc_cd               varchar2(30);
9065     l_procd_dt              date;
9066     l_strtd_dt              date;
9067     l_voidd_dt              date;
9068     l_esd_out               date;
9069     l_eed_out               date;
9070     l_ovn                   number(15);
9071     l_enrt_mthd_cd          ben_prtt_enrt_rslt_f.enrt_mthd_cd%type;
9072 
9073 /* Bug 10072439: For the backed out Life event if elections are made through
9074 Self Service, on reprocessing the backed out life event, communications of
9075 triggers configured for Web Enrollments should be reinstated.*/
9076 cursor c_chk_web_enrt_exists is
9077 select 'Y'
9078   from ben_per_cm_f pcf,
9079        ben_per_cm_trgr_f pctf,
9080        ben_cm_trgr bct
9081 where pcf.per_in_ler_id = p_bckdt_per_in_ler_id
9082 and pcf.person_id = p_person_id
9083 and pcf.per_cm_id = pctf.per_cm_id
9084 and bct.CM_TRGR_ID = pctf.CM_TRGR_ID
9085 and bct.PROC_CD = 'WEBENRT' ;
9086 
9087 l_comm_exists varchar2(1) default 'N';
9088 
9089 /* Bug 13355114: Check whether the reinstated enrollment is a an suspended enrollment
9090 and interim should be same as previous interim before backing out*/
9091 cursor c_interim_enrt(c_sus_pen_id number,
9092                       c_bckdt_prtt_enrt_rslt_id number,
9093                       c_bckdt_per_in_ler_id number ) is
9094 select pen_int.* from
9095 ben_prtt_enrt_rslt_f pen_curr,
9096 ben_prtt_enrt_rslt_f pen_int
9097 where pen_curr.prtt_enrt_rslt_id = c_sus_pen_id
9098 and pen_curr.prtt_enrt_rslt_stat_cd is NULL
9099 and pen_curr.per_in_ler_id = p_per_in_ler_id
9100 and pen_curr.SSPNDD_FLAG = 'Y'
9101 and pen_curr.RPLCS_SSPNDD_RSLT_ID is not NULL
9102 and pen_int.prtt_enrt_rslt_stat_cd is NULL
9103 and pen_int.per_in_ler_id = p_per_in_ler_id
9104 and pen_curr.RPLCS_SSPNDD_RSLT_ID = pen_int.prtt_enrt_rslt_id
9105 and pen_curr.effective_end_date = hr_api.g_eot
9106 and pen_int.effective_end_date = hr_api.g_eot
9107 and exists
9108 (select '1' from ben_prtt_enrt_rslt_f pen_bckdt,
9109 ben_prtt_enrt_rslt_f pen_int_bckdt
9110 where pen_bckdt.prtt_enrt_rslt_id = c_bckdt_prtt_enrt_rslt_id
9111 and pen_bckdt.per_in_ler_id = c_bckdt_per_in_ler_id
9112 and pen_bckdt.SSPNDD_FLAG = 'Y'
9113 and pen_bckdt.RPLCS_SSPNDD_RSLT_ID is not NULL
9114 and pen_int_bckdt.per_in_ler_id = c_bckdt_per_in_ler_id
9115 and pen_bckdt.RPLCS_SSPNDD_RSLT_ID = pen_int_bckdt.prtt_enrt_rslt_id
9116 and nvl(pen_int_bckdt.pgm_id,-1) = nvl(pen_int.pgm_id,-1)
9117 and nvl(pen_int_bckdt.pl_id,-1) = nvl(pen_int.pl_id,-1)
9118 and nvl(pen_int_bckdt.oipl_id,-1) = nvl(pen_int.oipl_id,-1)
9119 union
9120 select '1' from ben_le_clsn_n_rstr pen_bckdt,
9121 ben_le_clsn_n_rstr pen_int_bckdt
9122 where pen_bckdt.BKUP_TBL_ID = c_bckdt_prtt_enrt_rslt_id
9123 and pen_bckdt.per_in_ler_id = c_bckdt_per_in_ler_id
9124 and pen_bckdt.SSPNDD_FLAG = 'Y'
9125 and pen_bckdt.RPLCS_SSPNDD_RSLT_ID is not NULL
9126 and pen_int_bckdt.per_in_ler_id = c_bckdt_per_in_ler_id
9127 and pen_bckdt.RPLCS_SSPNDD_RSLT_ID = pen_int_bckdt.BKUP_TBL_ID
9128 and nvl(pen_int_bckdt.pgm_id,-1) = nvl(pen_int.pgm_id,-1)
9129 and nvl(pen_int_bckdt.pl_id,-1) = nvl(pen_int.pl_id,-1)
9130 and nvl(pen_int_bckdt.oipl_id,-1) = nvl(pen_int.oipl_id,-1)
9131 and pen_bckdt.bkup_tbl_typ_cd like 'BEN_PRTT_ENRT_RSLT%'
9132 and pen_int_bckdt.bkup_tbl_typ_cd like 'BEN_PRTT_ENRT_RSLT%');
9133     --
9134   begin
9135     --
9136     hr_utility.set_location ('Entering '||l_proc,10);
9137     hr_utility.set_location ('p_max_enrt_esd '||p_max_enrt_esd,10);
9138 
9139     /* Bug Bug 10072439 */
9140     open c_chk_web_enrt_exists;
9141     fetch c_chk_web_enrt_exists into l_comm_exists;
9142     if(c_chk_web_enrt_exists%found) then
9143       hr_utility.set_location ('Web Enrollment found ',10);
9144       l_comm_exists := 'Y';
9145     else
9146       hr_utility.set_location ('Web Enrollment not found ',10);
9147       l_comm_exists := 'N';
9148     end if;
9149     close c_chk_web_enrt_exists;
9150     /* End of Bug 10072439*/
9151     --
9152     ben_prtt_enrt_result_api.multi_rows_edit
9153       (p_person_id         => p_person_id,
9154        p_effective_date    => p_max_enrt_esd,
9155        p_business_group_id => p_business_group_id,
9156        p_per_in_ler_id     => p_per_in_ler_id,
9157        p_pgm_id            => null);
9158     --
9159     -- Invoke post result process once for Explicit/Automatic/ Default.
9160     --
9161     ben_proc_common_enrt_rslt.process_post_results
9162       (p_person_id          => p_person_id,
9163        p_enrt_mthd_cd       => 'E',
9164        p_effective_date     => p_max_enrt_esd,
9165        p_business_group_id  => p_business_group_id,
9166        p_per_in_ler_id      => p_per_in_ler_id);
9167     --
9168     ben_proc_common_enrt_rslt.process_post_results
9169       (p_person_id          => p_person_id,
9170        p_enrt_mthd_cd       => 'D',
9171        p_effective_date     => p_max_enrt_esd,
9172        p_business_group_id  => p_business_group_id,
9173        p_per_in_ler_id      => p_per_in_ler_id);
9174     --
9175     ben_proc_common_enrt_rslt.process_post_results
9176       (p_person_id          => p_person_id,
9177        p_enrt_mthd_cd       => 'A',
9178        p_effective_date     => p_max_enrt_esd,
9179        p_business_group_id  => p_business_group_id,
9180        p_per_in_ler_id      => p_per_in_ler_id);
9181     --
9182   -- end if;
9183   --
9184   -- Apply process post enrollments once for each program.
9185   --
9186   if nvl(p_pgm_table.LAST, 0) > 0 then
9187      for l_cnt in 1..p_pgm_table.LAST loop
9188      --
9189         -- Bug 5623259.
9190         --
9191 	/*Bug 10072439: Added If..Else condition. If
9192 	any Web Enrollments exists for the backed out life event, then set the
9193 	l_proc_cd to 'WEBENRT'*/
9194         if(l_comm_exists = 'Y')  then
9195          l_proc_cd := 'WEBENRT';
9196        else
9197         if p_pgm_table(l_cnt).enrt_mthd_cd = 'E' then
9198            l_proc_cd := 'FORMENRT';
9199         elsif p_pgm_table(l_cnt).enrt_mthd_cd = 'D' then
9200            l_proc_cd := 'DFLTENRT';
9201         else
9202            l_proc_cd := NULL;
9203         end if;
9204        end if;
9205      --
9206      -- 9575477 -  If explicit elections were made, pass
9207      --            the correct enrollment method code to post enrollment.
9208      --
9209      --
9210      l_enrt_mthd_cd := p_pgm_table(l_cnt).enrt_mthd_cd;
9211      --
9212      for l_enrt_cnt in 1..p_enrt_table.last loop
9213        hr_utility.set_location('enrt mthd code'||p_enrt_table(l_enrt_cnt).enrt_mthd_cd,43333);
9214        --
9215        if p_enrt_table(l_enrt_cnt).pgm_id = p_pgm_table(l_cnt).pgm_id and
9216           p_enrt_table(l_enrt_cnt).enrt_mthd_cd = 'E' then
9217           l_enrt_mthd_cd  := p_enrt_table(l_enrt_cnt).enrt_mthd_cd;
9218           exit;
9219         end if;
9220      end loop;
9221      --
9222      --  end 9575477
9223      --
9224      hr_utility.set_location('enrt mthd cd ' || p_pgm_table(l_cnt).enrt_mthd_cd, 310);
9225         ben_proc_common_enrt_rslt.process_post_enrollment
9226           (p_per_in_ler_id     => p_per_in_ler_id,
9227            p_pgm_id            => p_pgm_table(l_cnt).pgm_id,
9228            p_pl_id             => null,
9229            p_enrt_mthd_cd      => l_enrt_mthd_cd, -- 9575477
9230            p_cls_enrt_flag     => FALSE,
9231            --RCHASE
9232            p_proc_cd           => l_proc_cd,
9233            p_person_id         => p_person_id,
9234            p_business_group_id => p_business_group_id,
9235            p_effective_date    => p_pgm_table(l_cnt).max_enrt_esd );
9236         --
9237       end loop;
9238   end if;
9239   --
9240   -- Apply process post enrollments once for each program.
9241   --
9242   if nvl(p_pl_table.LAST, 0) > 0 then
9243      for l_cnt in 1..p_pl_table.LAST loop
9244         --
9245         -- Invoke post result process
9246         --
9247         hr_utility.set_location('Date = ' || p_pl_table(l_cnt).max_enrt_esd, 333);
9248         hr_utility.set_location('PL = ' || p_pl_table(l_cnt).pl_id, 333);
9249         --
9250         -- Bug 5623259.
9251         --
9252 	/*Bug 10072439: Added If..Else condition. If
9253 	any Web Enrollments exists for the backed out life event, then set the
9254 	l_proc_cd to 'WEBENRT'*/
9255         if(l_comm_exists = 'Y')  then
9256          l_proc_cd := 'WEBENRT';
9257        else
9258 	if p_pl_table(l_cnt).enrt_mthd_cd = 'E' then	--Bug# 11067360
9259 	   l_proc_cd := 'FORMENRT';
9260 	elsif p_pl_table(l_cnt).enrt_mthd_cd = 'D' then	--Bug# 11067360
9261 	   l_proc_cd := 'DFLTENRT';
9262 	else
9263 	   l_proc_cd := NULL;
9264 	end if;
9265        end if;
9266         --
9267         ben_proc_common_enrt_rslt.process_post_enrollment
9268           (p_per_in_ler_id     => p_per_in_ler_id,
9269            p_pgm_id            => null,
9270            p_pl_id             => p_pl_table(l_cnt).pl_id,
9271            p_enrt_mthd_cd      => p_pl_table(l_cnt).enrt_mthd_cd,
9272            p_cls_enrt_flag     => FALSE,
9273            p_proc_cd           => l_proc_cd,
9274            p_person_id         => p_person_id,
9275            p_business_group_id => p_business_group_id,
9276            p_effective_date    => p_pl_table(l_cnt).max_enrt_esd );
9277         --
9278       end loop;
9279   end if;
9280   --
9281   --
9282   --
9283   if nvl(p_enrt_table.LAST, 0) > 0 then
9284      --
9285      -- Reinstate the ledgers if any created.
9286      --
9287      reinstate_bpl_per_pen(
9288          p_person_id              => p_person_id
9289          ,p_business_group_id      => p_business_group_id
9290          ,p_effective_date         => p_effective_date
9291          ,p_per_in_ler_id          => p_per_in_ler_id
9292          ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
9293          );
9294      --
9295      for l_cnt in 1..p_enrt_table.LAST loop
9296        --
9297        -- Reinstate the enrollment beneficiary rows.
9298        --
9299        hr_utility.set_location('Enrt Date = ' ||
9300                                 p_enrt_table(l_cnt).effective_start_date, 333);
9301 hr_utility.set_location('Reinstate the enrollment beneficiary rows',13);
9302        reinstate_pbn_per_pen(
9303          p_person_id                => p_person_id
9304          ,p_bckdt_prtt_enrt_rslt_id
9305                                     => p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
9306          ,p_prtt_enrt_rslt_id       => p_enrt_table(l_cnt).prtt_enrt_rslt_id
9307          ,p_rslt_object_version_number => p_enrt_table(l_cnt).pen_ovn_number
9308          ,p_business_group_id        => p_business_group_id
9309          ,p_per_in_ler_id            => p_per_in_ler_id
9310          ,p_effective_date           => nvl(p_enrt_table(l_cnt).effective_start_date,
9311                                             g_sys_date)
9312          ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
9313          );
9314 
9315 	  /* Bug 13355114: If enrollment that is reinstated is Suspended, then call reinstate procedure
9316 	 to reinstate beneficiary designations for the interim*/
9317          if(p_enrt_table(l_cnt).bckdt_sspndd_flag = 'Y') then
9318                  for int_bnf in c_interim_enrt(p_enrt_table(l_cnt).prtt_enrt_rslt_id,
9319                                                p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id,
9320                                                p_bckdt_per_in_ler_id ) loop
9321                 hr_utility.set_location('Reinstating  interim enrollment beneficiary rows',13);
9322                 hr_utility.set_location('int_bnf.prtt_enrt_rslt_id '||int_bnf.prtt_enrt_rslt_id,13);
9323                 hr_utility.set_location('bckdt int id '||p_enrt_table(l_cnt).bckdt_RPLCS_SSPNDD_RSLT_ID,13);
9324                 reinstate_pbn_per_pen(
9325 			 p_person_id                => p_person_id
9326 			 ,p_bckdt_prtt_enrt_rslt_id
9327 						    => p_enrt_table(l_cnt).bckdt_RPLCS_SSPNDD_RSLT_ID
9328 			 ,p_prtt_enrt_rslt_id       => int_bnf.prtt_enrt_rslt_id
9329 			 ,p_rslt_object_version_number => int_bnf.object_version_number
9330 			 ,p_business_group_id        => p_business_group_id
9331 			 ,p_per_in_ler_id            => p_per_in_ler_id
9332 			 ,p_effective_date           => nvl(p_enrt_table(l_cnt).effective_start_date,
9333 							    g_sys_date)
9334 			 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
9335 			 );
9336                  end loop;
9337          end if;
9338        --
9339       --Bug 3709516 to reinstate participant PCP
9340         reinstate_ppr_per_pen(
9341            p_person_id                => p_person_id
9342           ,p_bckdt_prtt_enrt_rslt_id => p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
9343           ,p_prtt_enrt_rslt_id       => p_enrt_table(l_cnt).prtt_enrt_rslt_id
9344           ,p_business_group_id       => p_business_group_id
9345           ,p_elig_cvrd_dpnt_id       => NULL
9346           ,p_effective_date          =>  nvl(p_enrt_table(l_cnt).effective_start_date,
9347                                                    nvl(g_sys_date, p_effective_date) ) -- bug 5344392
9348           ,p_bckdt_elig_cvrd_dpnt_id => NULL
9349           );
9350        -- Reinstate the covered dependents.
9351        --
9352        reinstate_dpnts_per_pen(
9353                p_person_id                 => p_person_id
9354                ,p_bckdt_prtt_enrt_rslt_id  => p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
9355                ,p_prtt_enrt_rslt_id        => p_enrt_table(l_cnt).prtt_enrt_rslt_id
9356                ,p_pen_ovn_number           => p_enrt_table(l_cnt).pen_ovn_number
9357                ,p_old_pl_id                => p_enrt_table(l_cnt).old_pl_id
9358                ,p_new_pl_id                => p_enrt_table(l_cnt).new_pl_id
9359                ,p_old_oipl_id              => p_enrt_table(l_cnt).old_oipl_id
9360                ,p_new_oipl_id              => p_enrt_table(l_cnt).new_oipl_id
9361                ,p_old_pl_typ_id            => p_enrt_table(l_cnt).old_pl_typ_id
9362                ,p_new_pl_typ_id            => p_enrt_table(l_cnt).new_pl_typ_id
9363                ,p_pgm_id                   => p_enrt_table(l_cnt).pgm_id
9364                ,p_ler_id                   => p_enrt_table(l_cnt).ler_id
9365                ,p_elig_per_elctbl_chc_id   => p_enrt_table(l_cnt).elig_per_elctbl_chc_id
9366                ,p_business_group_id        => p_business_group_id
9367                ,p_effective_date           => nvl(p_enrt_table(l_cnt).effective_start_date,
9368                                                     p_effective_date)
9369                ,p_per_in_ler_id            => p_per_in_ler_id
9370                ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
9371                ,p_dpnt_cvg_strt_dt_cd      => p_enrt_table(l_cnt).dpnt_cvg_strt_dt_cd
9372                ,p_dpnt_cvg_strt_dt_rl      => p_enrt_table(l_cnt).dpnt_cvg_strt_dt_rl
9373                ,p_enrt_cvg_strt_dt         => null
9374                );
9375         --
9376         -- Reinstate the enrollment certifications.
9377         --
9378         reinstate_pcs_per_pen(
9379                p_person_id                 => p_person_id
9380                ,p_bckdt_prtt_enrt_rslt_id  => p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
9381                ,p_prtt_enrt_rslt_id        => p_enrt_table(l_cnt).prtt_enrt_rslt_id
9382                ,p_rslt_object_version_number => p_enrt_table(l_cnt).pen_ovn_number -- prtt_enrt_rslt_id
9383                ,p_business_group_id        => p_business_group_id
9384                ,p_prtt_enrt_actn_id        => null
9385                ,p_effective_date           => p_enrt_table(l_cnt).effective_start_date
9386                ,p_bckdt_prtt_enrt_actn_id  => null
9387                -- CFW
9388                ,p_per_in_ler_id            => p_per_in_ler_id
9389                ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
9390                );
9391        --
9392        -- Reinstate the action items.
9393        --
9394        reinstate_pea_per_pen(
9395                  p_person_id                => p_person_id
9396                 ,p_bckdt_prtt_enrt_rslt_id  => p_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
9397                 ,p_prtt_enrt_rslt_id        => p_enrt_table(l_cnt).prtt_enrt_rslt_id
9398                 ,p_rslt_object_version_number => p_enrt_table(l_cnt).pen_ovn_number
9399                 ,p_business_group_id        => p_business_group_id
9400                 ,p_per_in_ler_id            => p_per_in_ler_id
9401                 ,p_effective_date           => p_enrt_table(l_cnt).effective_start_date
9402                 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
9403                 );
9404      end loop;
9405   end if;
9406   --
9407 end reinstate_post_enrt;
9408 --
9409 procedure reinstate_override(
9410                              p_pgm_table           in g_pgm_table
9411                             ,p_pl_table            in g_pl_table
9412                             ,p_enrt_table      in out nocopy g_enrt_table
9413                             ,p_max_enrt_esd        in date
9414                             ,p_person_id           in number
9415                             ,p_business_group_id   in number
9416                             ,p_effective_date      in date
9417                             ,p_per_in_ler_id       in number
9418                             ,p_bckdt_per_in_ler_id in number
9419                             ,p_cls_enrt_flag       in boolean default false
9420     ) is
9421     --
9422     l_proc                  varchar2(72) := g_package||'.reinstate_override';
9423     --
9424     cursor c_pel(c_per_in_ler_id in number,
9425                  c_pgm_id           number,
9426                  c_pl_id            number ) is
9427     select pel.pil_elctbl_chc_popl_id,
9428            pel.pgm_id,
9429            pel.pl_id,
9430            pel.reinstate_cd,
9431            pel.reinstate_ovrdn_cd,
9432            pel.enrt_perd_strt_dt
9433     from   ben_pil_elctbl_chc_popl pel
9434     where  pel.per_in_ler_id = c_per_in_ler_id
9435       and  ((pel.pgm_id = c_pgm_id and
9436              pel.pl_id is null ) or
9437             (pel.pl_id = c_pl_id and
9438              pel.pgm_id is null ));
9439     --
9440     l_pel     c_pel%rowtype;
9441     --
9442     cursor c_ovridn_rt(v_bckdt_pen_id number
9443                       ,v_new_pen_id   number ) is
9444     select prv2.prtt_rt_val_id new_prv_id,
9445            prv2.object_version_number new_prv_ovn,
9446            prv1.*
9447       from ben_prtt_rt_val prv1, --backed out
9448            ben_prtt_rt_val prv2  --current
9449      where prv1.prtt_enrt_rslt_id = v_bckdt_pen_id
9450        and prv2.prtt_enrt_rslt_id = v_new_pen_id
9451        and prv1.acty_base_rt_id = prv2.acty_base_rt_id
9452        and prv1.rt_ovridn_flag = 'Y'
9453        and nvl(prv1.rt_ovridn_thru_dt,hr_api.g_eot) >= prv2.rt_strt_dt -- Bug 4384574
9454        and prv1.prtt_rt_val_stat_cd = 'BCKDT'
9455        and prv2.prtt_rt_val_stat_cd is null
9456        and prv2.per_in_ler_id = p_per_in_ler_id
9457        and prv1.per_in_ler_id = p_bckdt_per_in_ler_id ;
9458   --
9459     cursor c_ovridn_dpnt(v_bckdt_pen_id number
9460                         ,v_new_pen_id   number
9461                         ,v_effective_date date) is
9462     select pdp2.elig_cvrd_dpnt_id new_pdp_id,
9463            pdp2.object_version_number new_pdp_ovn,
9464            pdp1.*
9465       from ben_elig_cvrd_dpnt_f pdp1,
9466            ben_elig_cvrd_dpnt_f pdp2
9467      where pdp1.prtt_enrt_rslt_id = v_bckdt_pen_id
9468        and pdp2.prtt_enrt_rslt_id = v_new_pen_id
9469        and pdp1.dpnt_person_id = pdp2.dpnt_person_id
9470        and pdp1.ovrdn_flag = 'Y'
9471        and v_effective_date between pdp1.effective_start_date
9472                                 and pdp1.effective_end_date
9473        and v_effective_date between pdp2.effective_start_date
9474                               and pdp2.effective_end_date;
9475     --
9476     cursor c_ovn(v_prtt_enrt_rslt_id number) is
9477     select object_version_number
9478       from ben_prtt_enrt_rslt_f
9479      where prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
9480        and effective_end_date = hr_api.g_eot;
9481     --
9482     cursor c_epe_enrt_rt(v_elig_per_elctbl_chc_id number,
9483                          v_acty_base_rt_id number) is
9484     select ecr.elig_per_elctbl_chc_id
9485       from ben_enrt_rt ecr
9486      where ecr.elig_per_elctbl_chc_id = v_elig_per_elctbl_chc_id
9487        and ecr.acty_base_rt_id        = v_acty_base_rt_id ;
9488     --
9489     cursor c_enb_enrt_rt(v_elig_per_elctbl_chc_id number,
9490                          v_acty_base_rt_id number) is
9491     select ecr.enrt_bnft_id
9492       from ben_enrt_rt ecr,
9493            ben_enrt_bnft enb
9494      where enb.elig_per_elctbl_chc_id = v_elig_per_elctbl_chc_id
9495        and enb.ordr_num > 0  --9999 Need to check this
9496        and ecr.enrt_bnft_id           = enb.enrt_bnft_id
9497        and ecr.acty_base_rt_id        = v_acty_base_rt_id ;
9498     --
9499     cursor c_flx_pen(c_person_id number,c_per_in_ler_id number,c_effective_date date ) is
9500        select pen.prtt_enrt_rslt_id,pen.pgm_id,pen.pl_id
9501        from   ben_prtt_enrt_rslt_f pen,
9502               ben_pl_f pln
9503        where  pen.person_id           = c_person_id
9504          and  pen.per_in_ler_id       = c_per_in_ler_id
9505          and  pen.pl_id               = pln.pl_id
9506          and  pln.invk_flx_cr_pl_flag = 'Y'
9507          and  c_effective_date between pen.effective_start_date
9508                                    and pen.effective_end_date
9509          and  c_effective_date between pln.effective_start_date
9510                                    and pln.effective_end_date;
9511     --
9512     cursor c_flx_pgm(c_pgm_id number,c_effective_date date ) is
9513             select decode(pgm_typ_cd,'COBRAFLX','Y',
9514                                      'FLEX','Y',
9515                                      'FPC','Y','N') pgm_typ_cd
9516             from  ben_pgm_f pgm
9517             where pgm.pgm_id  = c_pgm_id
9518               and c_effective_date between pgm.effective_start_date
9519                                        and pgm.effective_end_date ;
9520     --
9521     cursor c_abp(c_acty_base_rt_id number,c_pgm_id number,c_effective_date date ) is
9522         select bpp.bnft_prvdr_pool_id
9523         from
9524                ben_aplcn_to_bnft_pool_f abp,
9525                ben_bnft_prvdr_pool_f bpp
9526         where
9527                abp.acty_base_rt_id    = c_acty_base_rt_id
9528         and    abp.bnft_prvdr_pool_id = bpp.bnft_prvdr_pool_id
9529         and    bpp.pgm_id             = c_pgm_id
9530         and    c_effective_date between abp.effective_start_date
9531                                    and abp.effective_end_date
9532         and    c_effective_date between bpp.effective_start_date
9533                                    and bpp.effective_end_date ;
9534     --
9535     cursor c_flex_epe(c_per_in_ler_id number,c_pgm_id number, c_pl_id number)  is
9536         select elig_per_elctbl_chc_id
9537           from ben_elig_per_elctbl_chc epe
9538          where epe.per_in_ler_id = c_per_in_ler_id
9539            and epe.pl_id = c_pl_id
9540            and epe.pgm_id = c_pgm_id ;
9541     --
9542     l_flex_elig_per_elctbl_chc_id NUMBER;
9543     l_proc_cd                     varchar2(30);
9544     l_procd_dt                    date;
9545     l_strtd_dt                    date;
9546     l_voidd_dt                    date;
9547     l_esd_out                     date;
9548     l_eed_out                     date;
9549     l_ovn                         number(15);
9550     l_bckdt_epe_id                number(15);
9551     l_elig_per_elctbl_chc_id      number(15);
9552     l_bckdt_enrt_bnft_id          number(15);
9553     l_enrt_bnft_id                number(15);
9554     l_pgm_id                      number(15) := -1;
9555     l_pl_id                       number(15) := -1;
9556     l_reinstate_cd                varchar2(30);
9557     l_reinstate_ovrdn_cd          varchar2(30);
9558     l_enb_ecr_differ              varchar2(30) := 'N';
9559     l_epe_ecr_differ              varchar2(30) := 'N';
9560     l_override                    varchar2(30) := 'Y';
9561     l_flex_program_flag           varchar2(30) := 'N';
9562     l_flex_prtt_enrt_rslt_id      number ;
9563     l_flex_pgm_id                 number ;
9564     l_flex_pl_id                  number ;
9565     l_bnft_prvdr_pool_id          number ;
9566     l_bnft_prvdd_ldgr_id          number ;
9567     l_bpl_used_val                number ;
9568     --
9569     l_acty_ref_perd_cd            varchar2(80);
9570     l_acty_base_rt_id             number;
9571     l_rt_strt_dt                  date;
9572     l_rt_val                      number;
9573     l_element_type_id             number ;
9574     l_sh_prtt_rt_val_id           number := null;
9575     l_rate_flex_ovrrd_exists      varchar2(30):= 'N';
9576     --
9577   begin
9578     --
9579     hr_utility.set_location ('Entering '||l_proc,10);
9580   -- If any of the backed out enrt rslts were overriden, then update the new
9581   -- rslts with the overriden data.
9582   --
9583   if nvl(p_enrt_table.last, 0) > 0 then
9584     --
9585     for i in 1..p_enrt_table.last loop
9586       --
9587       l_elig_per_elctbl_chc_id := p_enrt_table(i).elig_per_elctbl_chc_id;
9588       --
9589       l_bckdt_epe_id := get_epe(p_per_in_ler_id  => p_bckdt_per_in_ler_id
9590                                ,p_pgm_id         => p_enrt_table(i).pgm_id
9591                                ,p_pl_id          => p_enrt_table(i).old_pl_id
9592                                ,p_oipl_id        => p_enrt_table(i).old_oipl_id
9593                                );
9594       --
9595       hr_utility.set_location('p_per_in_ler_id '||p_per_in_ler_id,178);
9596       hr_utility.set_location('p_enrt_table(i).pgm_id '||p_enrt_table(i).pgm_id,178);
9597       hr_utility.set_location('p_enrt_table(i).new_pl_id '||p_enrt_table(i).new_pl_id,178);
9598       hr_utility.set_location('l_pgm_id '||l_pgm_id,178);
9599       hr_utility.set_location('l_pl_id '||l_pl_id,178);
9600       --
9601       if l_pgm_id <> nvl(p_enrt_table(i).pgm_id,l_pgm_id) or
9602          l_pl_id  <> nvl(p_enrt_table(i).new_pl_id,l_pl_id)
9603       then
9604         --
9605         open c_pel(p_per_in_ler_id,p_enrt_table(i).pgm_id,p_enrt_table(i).new_pl_id);
9606         fetch c_pel into l_pel;
9607           --
9608           l_pgm_id := l_pel.pgm_id; -- p_enrt_table(i).pgm_id ;
9609           l_pl_id  := l_pel.pl_id; -- p_enrt_table(i).new_pl_id ;
9610           l_reinstate_cd := l_pel.reinstate_cd;
9611           l_reinstate_ovrdn_cd := l_pel.reinstate_ovrdn_cd;
9612           --
9613           hr_utility.set_location('l_pgm_id '||l_pgm_id,168);
9614           hr_utility.set_location('l_pl_id '||l_pl_id,168);
9615           --
9616         close c_pel;
9617         --
9618       end if;
9619       --
9620       --Check if the program is a flex credits one.
9621       --
9622       --hr_utility.set_location('l_pl_id '||l_pl_id,199);
9623       --hr_utility.set_location('p_enrt_table(i).new_pl_id '||p_enrt_table(i).new_pl_id,199);
9624       --hr_utility.set_location('p_enrt_table(i).pgm_id '||p_enrt_table(i).pgm_id,199);
9625       --hr_utility.set_location('l_pgm_id '||l_pgm_id,199);
9626       --hr_utility.set_location('p_enrt_table(i).g_sys_date '||p_enrt_table(i).g_sys_date,199);
9627       --
9628       open c_flx_pgm(p_enrt_table(i).pgm_id,p_enrt_table(i).g_sys_date );
9629         fetch c_flx_pgm into l_flex_program_flag ;
9630       close c_flx_pgm ;
9631       --
9632       if l_flex_program_flag = 'Y' then
9633         --
9634         open c_flx_pen(p_person_id,p_per_in_ler_id,p_enrt_table(i).g_sys_date );
9635         fetch c_flx_pen into l_flex_prtt_enrt_rslt_id,l_flex_pgm_id,l_flex_pl_id;
9636         close c_flx_pen;
9637         --
9638       end if;
9639       --
9640       if p_enrt_table(i).bckdt_enrt_ovridn_flag = 'Y' then
9641         --
9642         hr_utility.set_location('Restoring the overriden result: ' ||
9643                                 p_enrt_table(i).bckdt_prtt_enrt_rslt_id, 72);
9644         -- 9999Why we are not updating the override thru date  and
9645         -- and all other information on pen record which can be overriden ?
9646         -- Get the latest object version number as the post enrollment process
9647         -- may have updated the new enrt result.
9648         --
9649         open c_ovn(p_enrt_table(i).prtt_enrt_rslt_id);
9650         fetch c_ovn into l_ovn;
9651         close c_ovn;
9652         --
9653         ben_prtt_enrt_result_api.update_prtt_enrt_result
9654           (p_prtt_enrt_rslt_id      => p_enrt_table(i).prtt_enrt_rslt_id
9655           ,p_effective_start_date   => l_esd_out
9656           ,p_effective_end_date     => l_eed_out
9657           ,p_enrt_cvg_strt_dt       => p_enrt_table(i).bckdt_enrt_cvg_strt_dt
9658           ,p_enrt_cvg_thru_dt       => p_enrt_table(i).bckdt_enrt_cvg_thru_dt
9659           ,p_enrt_ovrid_thru_dt       => p_enrt_table(i).enrt_ovrid_thru_dt
9660           ,p_enrt_ovrid_rsn_cd        => p_enrt_table(i).enrt_ovrid_rsn_cd
9661           ,p_enrt_ovridn_flag       => 'Y'
9662           ,p_object_version_number  => l_ovn
9663           ,p_effective_date         => p_enrt_table(i).g_sys_date
9664           ,p_datetrack_mode         => hr_api.g_correction
9665           ,p_multi_row_validate     => FALSE);
9666         --
9667       end if;
9668       --
9669       -- Check if any of the rates have been overriden and update the new
9670       -- rates with the overriden values.
9671       -- Bug 2677804 changed the cursor
9672       -- We need to see the overriden thru date also.
9673       --
9674       l_override := 'Y';
9675       --
9676       for l_rt_rec in c_ovridn_rt(p_enrt_table(i).bckdt_prtt_enrt_rslt_id
9677                                  ,p_enrt_table(i).prtt_enrt_rslt_id )
9678       loop
9679         --
9680         hr_utility.set_location('Updating new prv: ' || l_rt_rec.new_prv_id ||
9681                                 ' with overriden prv_id: ' || l_rt_rec.prtt_rt_val_id, 72);
9682         --
9683         if l_reinstate_cd = 'VALIDATE_RESULT' and
9684            l_reinstate_ovrdn_cd = 'OVERRIDE_IF_NO_CHANGE' then
9685           open c_epe_enrt_rt(l_elig_per_elctbl_chc_id,l_rt_rec.acty_base_rt_id);
9686             fetch c_epe_enrt_rt into l_elig_per_elctbl_chc_id ;
9687           close c_epe_enrt_rt ;
9688           --
9689           open c_epe_enrt_rt(l_bckdt_epe_id,l_rt_rec.acty_base_rt_id);
9690             fetch c_epe_enrt_rt into l_bckdt_epe_id ;
9691           close c_epe_enrt_rt ;
9692           --
9693           if l_elig_per_elctbl_chc_id IS NOT NULL and
9694              l_bckdt_epe_id           IS NOT NULL then
9695             --
9696              l_epe_ecr_differ := comp_ori_new_epe_ecr(
9697                  p_person_id              => p_person_id
9698                 ,p_business_group_id      => p_business_group_id
9699                 ,p_effective_date         => p_effective_date
9700                 ,p_per_in_ler_id          => p_per_in_ler_id
9701                 ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
9702                 ,p_curr_epe_id            => l_elig_per_elctbl_chc_id
9703                 ,p_bckdt_epe_id           => l_bckdt_epe_id
9704                 );
9705             --
9706             hr_utility.set_location('l_epe_ecr_differ '||l_epe_ecr_differ,20);
9707             if l_epe_ecr_differ = 'Y' then
9708               l_override := 'N';
9709             end if;
9710             --
9711           else
9712             --
9713             open c_enb_enrt_rt(l_elig_per_elctbl_chc_id,l_rt_rec.acty_base_rt_id);
9714               fetch c_enb_enrt_rt into l_enrt_bnft_id ;
9715             close c_enb_enrt_rt ;
9716             --
9717             open c_enb_enrt_rt(l_bckdt_epe_id,l_rt_rec.acty_base_rt_id);
9718               fetch c_enb_enrt_rt into l_bckdt_enrt_bnft_id ;
9719             close c_enb_enrt_rt ;
9720             --
9721             if l_enrt_bnft_id IS NOT NULL and
9722                l_bckdt_enrt_bnft_id IS NOT NULL then
9723               --
9724               l_enb_ecr_differ := comp_ori_new_enb_ecr(
9725                 p_person_id              => p_person_id
9726                 ,p_business_group_id     => p_business_group_id
9727                 ,p_effective_date        => p_effective_date
9728                 ,p_per_in_ler_id         => p_per_in_ler_id
9729                 ,p_bckdt_per_in_ler_id   => p_bckdt_per_in_ler_id
9730                 ,p_curr_enb_id           => l_enrt_bnft_id
9731                 ,p_bckdt_enb_id          => l_bckdt_enrt_bnft_id
9732                 );
9733               --
9734               hr_utility.set_location('l_enb_ecr_differ '||l_enb_ecr_differ,20);
9735               --
9736               if l_enb_ecr_differ = 'Y' then
9737                 l_override := 'N';
9738               end if;
9739             end if;
9740             --
9741           end if;
9742           --
9743         end if;
9744         --
9745         hr_utility.set_location(' l_override '||l_override,199);
9746         --
9747         if l_override = 'Y' then
9748           --
9749           l_rate_flex_ovrrd_exists := 'Y';
9750           --
9751           ben_prtt_rt_val_api.update_prtt_rt_val
9752             (p_prtt_rt_val_id        => l_rt_rec.new_prv_id
9753             ,p_person_id             => p_person_id
9754             ,p_rt_strt_dt            => l_rt_rec.rt_strt_dt
9755             ,p_rt_val                => l_rt_rec.rt_val
9756             ,p_acty_ref_perd_cd      => l_rt_rec.acty_ref_perd_cd
9757             ,p_cmcd_rt_val           => l_rt_rec.cmcd_rt_val
9758             ,p_cmcd_ref_perd_cd      => l_rt_rec.cmcd_ref_perd_cd
9759             ,p_ann_rt_val            => l_rt_rec.ann_rt_val
9760             ,p_rt_ovridn_flag        => l_rt_rec.rt_ovridn_flag
9761             ,p_rt_ovridn_thru_dt     => l_rt_rec.rt_ovridn_thru_dt
9762             ,p_business_group_id     => p_business_group_id
9763             ,p_object_version_number => l_rt_rec.new_prv_ovn
9764             ,p_effective_date        => p_enrt_table(i).g_sys_date);
9765           --
9766           --Call Override Routines for flex credits
9767           --Bug 4384574 we need to handle the ledger entries also when the rates are
9768           --overriden
9769           hr_utility.set_location(' l_flex_program_flag '||l_flex_program_flag,199);
9770           hr_utility.set_location(' l_flex_prtt_enrt_rslt_id '||l_flex_prtt_enrt_rslt_id,199);
9771           --
9772           if l_flex_program_flag = 'Y' and l_flex_prtt_enrt_rslt_id is not null then
9773             --
9774             open c_abp(l_rt_rec.acty_base_rt_id,p_enrt_table(i).pgm_id,p_enrt_table(i).g_sys_date) ;
9775               fetch c_abp into l_bnft_prvdr_pool_id ;
9776               hr_utility.set_location(' l_bnft_prvdr_pool_id '||l_bnft_prvdr_pool_id,199);
9777               --
9778               if c_abp%found then
9779                 --
9780                 ben_manage_override.override_debit_ledger_entry
9781                  (p_validate                => false
9782                  ,p_calculate_only_mode     => false
9783                  ,p_person_id               => p_person_id
9784                  ,p_per_in_ler_id           => p_per_in_ler_id
9785                  ,p_elig_per_elctbl_chc_id  => l_elig_per_elctbl_chc_id
9786                  ,p_prtt_enrt_rslt_id       => l_flex_prtt_enrt_rslt_id
9787                  ,p_decr_bnft_prvdr_pool_id => l_bnft_prvdr_pool_id
9788                  ,p_acty_base_rt_id         => l_rt_rec.acty_base_rt_id
9789                  ,p_prtt_rt_val_id          => l_rt_rec.new_prv_id
9790                  ,p_enrt_mthd_cd            => 'O'
9791                  ,p_val                     => l_rt_rec.rt_val
9792                  ,p_bnft_prvdd_ldgr_id      => l_bnft_prvdd_ldgr_id -- in out number
9793                  ,p_business_group_id       => p_business_group_id
9794                  ,p_effective_date          => p_enrt_table(i).g_sys_date
9795                  ,p_bpl_used_val            => l_bpl_used_val --    out number
9796                  );
9797                 --
9798               end if;
9799             --
9800           end if;
9801           --
9802         end if;
9803         --
9804       end loop;
9805       --
9806       -- Check if there are any dependents that are overriden and update the new
9807       -- elig_cvrd_dpnt records with the overriden values.
9808       --
9809       for l_dpnt_rec in c_ovridn_dpnt(p_enrt_table(i).bckdt_prtt_enrt_rslt_id
9810                                      ,p_enrt_table(i).prtt_enrt_rslt_id
9811                                      ,p_enrt_table(i).g_sys_date)
9812       loop
9813         --
9814         hr_utility.set_location('Updating new ecd with overriden ecd_id: ' ||
9815                                 l_dpnt_rec.elig_cvrd_dpnt_id, 72);
9816         --
9817         ben_elig_cvrd_dpnt_api.update_elig_cvrd_dpnt
9818           (p_elig_cvrd_dpnt_id     => l_dpnt_rec.new_pdp_id
9819           ,p_effective_start_date  => l_esd_out
9820           ,p_effective_end_date    => l_eed_out
9821           ,p_cvg_strt_dt           => l_dpnt_rec.cvg_strt_dt
9822           ,p_cvg_thru_dt           => l_dpnt_rec.cvg_thru_dt
9823           ,p_ovrdn_flag            => l_dpnt_rec.ovrdn_flag
9824           ,p_ovrdn_thru_dt         => l_dpnt_rec.ovrdn_thru_dt
9825           ,p_object_version_number => l_dpnt_rec.new_pdp_ovn
9826           ,p_datetrack_mode        => hr_api.g_correction
9827           ,p_effective_date        => p_enrt_table(i).g_sys_date);
9828         --
9829       end loop;
9830       --
9831     end loop;
9832     --
9833     --program level changes for override flex credits
9834     --Need to process only when there is atleast one rate override happened
9835     l_pgm_id := -1;
9836     --
9837     if l_rate_flex_ovrrd_exists = 'Y' and nvl(p_pgm_table.LAST, 0) > 0 then
9838       for l_cnt in 1..p_pgm_table.LAST loop
9839         --
9840         hr_utility.set_location('p_pgm_table(l_cnt).pgm_id '||p_pgm_table(l_cnt).pgm_id,166);
9841         hr_utility.set_location('p_pgm_table(l_cnt).max_enrt_esd '||p_pgm_table(l_cnt).max_enrt_esd,166);
9842         --
9843         l_flex_prtt_enrt_rslt_id:= null;
9844         l_flex_elig_per_elctbl_chc_id:=null;
9845         l_flex_pgm_id:=null;
9846         l_flex_pl_id:=null;
9847         --
9848         if l_pgm_id <> p_pgm_table(l_cnt).pgm_id then
9849           --
9850           l_pgm_id := p_pgm_table(l_cnt).pgm_id ;
9851           --
9852           open c_flx_pgm(l_pgm_id,p_pgm_table(l_cnt).max_enrt_esd );
9853             fetch c_flx_pgm into l_flex_program_flag ;
9854           close c_flx_pgm ;
9855           --
9856           if l_flex_program_flag = 'Y' then
9857             --
9858             open c_flx_pen(p_person_id,p_per_in_ler_id,p_pgm_table(l_cnt).max_enrt_esd);
9859             fetch c_flx_pen into l_flex_prtt_enrt_rslt_id,l_flex_pgm_id,l_flex_pl_id;
9860             close c_flx_pen;
9861             --
9862             open c_flex_epe(p_per_in_ler_id,l_flex_pgm_id, l_flex_pl_id) ;
9863             fetch c_flex_epe into l_flex_elig_per_elctbl_chc_id ;
9864             close c_flex_epe ;
9865             --
9866           end if;
9867            --
9868            --
9869            if l_flex_elig_per_elctbl_chc_id is not null and
9870               l_flex_prtt_enrt_rslt_id is not null then
9871              ben_provider_pools.accumulate_pools
9872                (p_validate               => false
9873                ,p_person_id              => p_person_id
9874                ,p_elig_per_elctbl_chc_id => l_flex_elig_per_elctbl_chc_id
9875                ,p_business_group_id      => p_business_group_id
9876                ,p_enrt_mthd_cd           => 'O'
9877                ,p_effective_date         => p_pgm_table(l_cnt).max_enrt_esd
9878               );
9879              --
9880              ben_provider_pools.cleanup_invalid_ledger_entries(
9881                 p_validate           => false
9882                ,p_person_id          => p_person_id
9883                ,p_per_in_ler_id      => p_per_in_ler_id
9884                ,p_effective_date     => p_pgm_table(l_cnt).max_enrt_esd
9885                ,p_business_group_id  => p_business_group_id
9886                );
9887              --
9888              -- To compute the balance entries and get the prv for flex shell plan.
9889              --
9890              ben_provider_pools.total_pools
9891                     (p_validate          => FALSE
9892                      ,p_prtt_enrt_rslt_id => l_flex_prtt_enrt_rslt_id
9893                      ,p_prtt_rt_val_id    => l_sh_prtt_rt_val_id --dummy
9894                      ,p_acty_ref_perd_cd  => l_acty_ref_perd_cd --dummy
9895                      ,p_acty_base_rt_id   => l_acty_base_rt_id --dummy
9896                      ,p_rt_strt_dt        => l_rt_strt_dt --dummy
9897                      ,p_rt_val            => l_rt_val --dummy
9898                      ,p_element_type_id   => l_element_type_id --dummy
9899                      ,p_person_id         => p_person_id
9900                      ,p_per_in_ler_id     => p_per_in_ler_id
9901                      ,p_enrt_mthd_cd      => 'O'
9902                      ,p_effective_date    => p_pgm_table(l_cnt).max_enrt_esd
9903                      ,p_business_group_id => p_business_group_id
9904                      ,p_pgm_id            => l_pgm_id
9905                      );
9906            end if;
9907         end if;
9908         --
9909       end loop;
9910     end if;
9911     --
9912   end if;
9913   --
9914   hr_utility.set_location ('Leaving '||l_proc,10);
9915   --
9916 end reinstate_override;
9917 -- ----------------------------------------------------------------------------
9918 -- |------------------------< p_lf_evt_clps_restore_new >-------------------------|
9919 -- ----------------------------------------------------------------------------
9920 procedure p_lf_evt_clps_restore(
9921                            p_validate               in boolean default false
9922                           ,p_person_id              in number
9923                           ,p_business_group_id      in number
9924                           ,p_effective_date         in date
9925                           ,p_per_in_ler_id          in number
9926                           ,p_bckdt_per_in_ler_id    in number
9927                           ) is
9928   --
9929   cursor c_pel(p_per_in_ler_id in number) is
9930     select pel.pil_elctbl_chc_popl_id,
9931            pel.pgm_id,
9932            pel.pl_id,
9933            pel.reinstate_cd,
9934            pel.reinstate_ovrdn_cd,
9935            pel.enrt_perd_strt_dt
9936     from   ben_pil_elctbl_chc_popl pel
9937     where  pel.per_in_ler_id = p_per_in_ler_id;
9938   --
9939   cursor c_multiple_rate is
9940     select null
9941     from   ben_le_clsn_n_rstr
9942     where  BKUP_TBL_TYP_CD = 'MULTIPLE_RATE'
9943     and    per_in_ler_id  = p_bckdt_per_in_ler_id;
9944   --
9945   cursor c_bckdt_pil is
9946     select ler.name, pil.PRVS_STAT_CD, pil.object_version_number, pil.BCKT_PER_IN_LER_ID
9947     from ben_per_in_ler pil,
9948          ben_ler_f ler
9949     where pil.per_in_ler_id = p_bckdt_per_in_ler_id
9950       and ler.ler_id = pil.ler_id
9951       and p_effective_date between ler.effective_start_date
9952                                and ler.effective_end_date ;
9953 
9954 -----------------------------------------------------------------------------------
9955   l_pl_typ_id number;
9956   l_prev_pil_id number;
9957   l_def_plus_reinsate_flag varchar2(1) default 'N';
9958 
9959 cursor c_pl_typ_id(c_pl_id number) is
9960   select pl_typ_id from
9961          ben_pl_f
9962    where pl_id = c_pl_id
9963    and p_effective_date between effective_start_date
9964                      and effective_end_date ;
9965 
9966 
9967 cursor c_exp_enrt_exists(c_per_in_ler_id number,c_pgm_id number,c_pl_typ_id number) is
9968   select 'Y' from
9969       ben_prtt_enrt_rslt_f pen
9970   where pen.per_in_ler_id = c_per_in_ler_id
9971   and   nvl(pen.pgm_id,-1) = nvl(c_pgm_id,-1)
9972   and   pen.pl_typ_id = c_pl_typ_id
9973   and   pen.enrt_mthd_cd = 'E'
9974   and   pen.prtt_enrt_rslt_stat_cd is null
9975   and   pen.enrt_cvg_thru_dt = hr_api.g_eot
9976   and   pen.enrt_cvg_thru_dt >= pen.enrt_cvg_strt_dt ;
9977 
9978 cursor c_chk_exp_inter_pil is
9979     select 'Y'
9980     from   ben_prtt_enrt_rslt_f pen,
9981            ben_ler_f ler
9982     where  pen.per_in_ler_id not in (p_per_in_ler_id,p_bckdt_per_in_ler_id)
9983     and    pen.person_id           = p_person_id
9984     and    pen.prtt_enrt_rslt_stat_cd is null
9985     and    pen.enrt_cvg_thru_dt = hr_api.g_eot
9986     and    pen.effective_end_date = hr_api.g_eot
9987     and    pen.ler_id = ler.ler_id
9988     and    p_effective_date between ler.effective_start_date and
9989                                     ler.effective_end_date
9990     and    ler.typ_cd not in  ('IREC','SCHEDDU', 'COMP', 'GSP', 'ABS')
9991     and  pen.per_in_ler_id= l_prev_pil_id
9992     and  pen.enrt_mthd_cd = 'E'
9993     /* Bug 12688164 : To check whether elections are made for intervening LE, enrollment should
9994     not be either suspended or interim*/
9995     and  nvl(pen.sspndd_flag,'N') = 'N'
9996     and  not exists
9997          (select '1' from ben_prtt_enrt_rslt_f pen1
9998 	  where pen1.RPLCS_SSPNDD_RSLT_ID = pen.prtt_enrt_rslt_id
9999 	  and pen1.per_in_ler_id = pen.per_in_ler_id)
10000     and exists
10001         (select 'Y' from ben_elig_per_elctbl_chc epe1
10002                     where epe1.elctbl_flag = 'Y'
10003                           and epe1.per_in_ler_id = l_prev_pil_id)
10004     and rownum =  1 ;
10005 
10006  l_int_pil_id number;
10007 
10008  cursor c_int_pil_id is
10009   select bckt_per_in_ler_id
10010         from ben_per_in_ler pil
10011 	where pil.per_in_ler_id = p_bckdt_per_in_ler_id;
10012 
10013  cursor c_chk_intevent_bckdt(c_pil_id number) is
10014   select 'Y'
10015         from ben_per_in_ler pil
10016 	where pil.per_in_ler_id = c_pil_id
10017 	      and pil.per_in_ler_stat_cd in('BCKDT', 'VOIDD');
10018 
10019 cursor c_future_pil is
10020        select pil.per_in_ler_id
10021     from   ben_per_in_ler pil,
10022            ben_ler_f ler
10023     where  pil.per_in_ler_id not in (p_per_in_ler_id,p_bckdt_per_in_ler_id)
10024     and    pil.person_id     = p_person_id
10025     and    pil.ler_id        = ler.ler_id
10026     and    p_effective_date between
10027            ler.effective_start_date and ler.effective_end_date
10028     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
10029     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
10030     and    pil.lf_evt_ocrd_dt in (select lf_evt_ocrd_dt
10031 				 from ben_per_in_ler pil2,
10032 				      ben_ler_f ler1
10033 				 where pil2.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD')
10034 				    and pil2.person_id = p_person_id
10035 				    and    pil2.ler_id        = ler1.ler_id
10036 				    and    p_effective_date between
10037 					   ler1.effective_start_date and ler1.effective_end_date
10038 				    and    ler1.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
10039 				    and pil2.lf_evt_ocrd_dt > (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
10040 							      per_in_ler_id = l_int_pil_id)
10041 				    and pil2.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
10042 							      per_in_ler_id = p_bckdt_per_in_ler_id)
10043                                 )
10044    order by pil.lf_evt_ocrd_dt desc;
10045 
10046  cursor c_ler_id is
10047  select le.ler_id
10048         from ben_ler_f le,ben_per_in_ler pil
10049         where pil.ler_id=le.ler_id
10050 	and p_effective_date between le.effective_start_date and le.effective_end_date
10051 	and pil.per_in_ler_id = p_bckdt_per_in_ler_id;
10052 
10053  l_ler_id number;
10054  l_default varchar2(1) default 'N';
10055  l_reinstate_def varchar2(1) default 'N';
10056  l_def_applied varchar2(1) default 'N';
10057 
10058  l_env_obj ben_env_object.g_global_env_rec_type;
10059 
10060   /*Bug 13711703 */
10061  cursor c_reopen_le is
10062  select '1' from dual where exists
10063  (select '1' from ben_pil_elctbl_chc_popl pel
10064     where  pel.per_in_ler_id = p_per_in_ler_id
10065     and pel.reopen_le_on_reprocess = 'Y');
10066   l_reopen_le_on_reprocess  varchar2(30);
10067 
10068 
10069   --
10070   l_bckdt_pil              c_bckdt_pil%rowtype;
10071   l_dummy     varchar2(30) default 'N';
10072   --
10073   l_pel                     c_pel%rowtype;
10074   --
10075   l_proc                    varchar2(72) := g_package||'.p_lf_evt_clps_restore';
10076   l_chages_ocrd_flag        varchar2(30) := 'N';
10077   l_rslt_exist_flag         varchar2(30) := 'N';
10078   l_int_rslts_exist_flag    varchar2(30) := 'N';
10079   l_date                    date;
10080   l_resnd_cmnt_txt          fnd_new_messages.message_text%type;
10081   l_reinstate_cd            varchar2(30);
10082   l_reinstate_ovrdn_cd      varchar2(30);
10083   l_susp_flag               boolean ;
10084   l_batch_flag              boolean := FALSE ; ---99999 When called from benmngle batch it needs to be TRUE
10085   l_bckdt_pilepe_table      ben_reinstate_epe_cache.g_pilepe_inst_tbl;
10086   l_bckdt_pen_table         g_bckdt_pen_tbl;
10087   l_bckdt_pilepe_inst_row   ben_reinstate_epe_cache.g_pilepe_inst_row;
10088   l_bckdt_epe_count         number;
10089   l_pilepe_inst_row         ben_reinstate_epe_cache.g_pilepe_inst_row;
10090   --
10091   --To reinstate
10092   --
10093   l_valid_count             number;
10094   l_valid_pen_table         g_bckdt_pen_tbl;
10095   l_valid_epe_table         ben_reinstate_epe_cache.g_pilepe_inst_tbl;
10096   --
10097   --To report non-reinstating results info
10098   --
10099   l_invalid_pen_table       g_bckdt_pen_tbl;
10100   l_invalid_count           number;
10101   l_invalid_epe_table       ben_reinstate_epe_cache.g_pilepe_inst_tbl;
10102   --
10103   l_pgm_table               g_pgm_table;
10104   l_pl_table                g_pl_table;
10105   l_enrt_table              g_enrt_table;
10106   l_max_enrt_esd            date;
10107   l_max_enrt_esd_out        date;
10108   l_not_reinstate           number := 1 ;
10109   l_procd_dt                date;
10110   l_strtd_dt                date;
10111   l_voidd_dt                date;
10112   --
10113   l_status		    varchar2(1);
10114   l_industry		    varchar2(1);
10115   l_oracle_schema	    varchar2(30);
10116   --
10117   /*  -- commented against bug 7679297
10118   -- Bug 6328780
10119   cursor c_en_dtd_pen_bckdt_pil
10120     is
10121      SELECT pen_inner.bkup_tbl_id,
10122       pen_inner.effective_start_date,
10123       pen_inner.effective_end_date,
10124       pen_inner.enrt_cvg_strt_dt,
10125       pen_inner.enrt_cvg_thru_dt,
10126       pen_inner.object_version_number
10127    FROM ben_le_clsn_n_rstr pen_inner,
10128         ben_per_in_ler pil_inner
10129    WHERE pil_inner.per_in_ler_id = p_bckdt_per_in_ler_id
10130    AND pil_inner.person_id = p_person_id
10131    AND pil_inner.business_group_id = p_business_group_id
10132    AND pil_inner.per_in_ler_id = pen_inner.per_in_ler_id
10133    AND pen_inner.bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_RSLT_F'
10134    AND ( (pen_inner.enrt_cvg_thru_dt IS NOT NULL and pen_inner.enrt_cvg_thru_dt <> hr_api.g_eot )
10135            and pen_inner.effective_end_date  = hr_api.g_eot
10136         )
10137    AND pen_inner.comp_lvl_cd NOT IN('PLANFC','PLANIMP');
10138   --
10139  l_en_dtd_pen_bckdt_pil c_en_dtd_pen_bckdt_pil%ROWTYPE;
10140  l_effective_start_date date;
10141  l_effective_end_date  date;
10142   --
10143  -- Bug 6328780
10144 
10145   cursor c_unres_per_in_ler
10146     is
10147 	select 'x'
10148 	from ben_ler_f ler, ben_per_in_ler pil
10149 	where ler.ler_id = pil.ler_id
10150         and ler.business_group_id = pil.business_group_id
10151 	and pil.per_in_ler_id = p_per_in_ler_id
10152         and pil.business_group_id = p_business_group_id
10153 	and ler.typ_cd = 'SCHEDDU';
10154 
10155   l_unres_per_in_ler c_unres_per_in_ler%ROWTYPE;
10156 
10157   */
10158 
10159   /*Bug 13079111 */
10160    cursor c_popl_rec(c_per_in_ler_id number,p_pgm_id number,p_pl_id number) is
10161 	  select *  from ben_pil_elctbl_chc_popl pel
10162 	  where per_in_ler_id = c_per_in_ler_id
10163     --Bug 13940072 added pgm_id and pl_id check to fetch correct record
10164     and (
10165 		    (p_pl_id is null and pgm_id = p_pgm_id) or
10166              (p_pgm_id is null and pl_id = p_pl_id) or (p_pl_id is NULL and p_pgm_id is NULL)
10167 			 )	;
10168 
10169   l_popl_rec c_popl_rec%rowtype;
10170   l_ele_date date;
10171 
10172 begin
10173   --
10174   hr_utility.set_location ('Entering '||l_proc,10);
10175   hr_utility.set_location('p_bckdt_per_in_ler_id '||p_bckdt_per_in_ler_id,30);
10176   --
10177   -- Remove it after complete test.
10178   --
10179   g_dflt_during_reinstate := 'N';
10180   l_pgm_table.delete;
10181   l_pl_table.delete;
10182   l_enrt_table.delete;
10183   -- bug 4615207 : added GHR product installation chk -Multiple Rate chk to be performed only for GHR
10184   IF (fnd_installation.get_app_info('GHR',l_status, l_industry, l_oracle_schema)) THEN
10185    if l_status = 'I' then
10186     open c_multiple_rate;
10187     fetch c_multiple_rate into l_dummy;
10188     if c_multiple_rate%found then
10189      close c_multiple_rate;
10190       -- Multiple rate is found and no reinstate
10191       hr_utility.set_location ('Multiple rate found and no reinstate done',11);
10192       return;
10193     end if;
10194      close c_multiple_rate;
10195    end if;  --if l_status
10196   end if;
10197   --
10198   open c_bckdt_pil ;
10199     fetch c_bckdt_pil into l_bckdt_pil ;
10200   close c_bckdt_pil ;
10201   --
10202   --Check if there are Enrollment results for intervening life event
10203   --
10204   --Get the Reinstate Codes
10205   --LOOP THRU ALL PROGRAM AND PLANS NOT IN PROGRAMS IN PEL Table
10206   --
10207   --CASE 1 No Reinstate
10208   --   RETURN
10209   --CASE 2 If intervening LE exists
10210   --   PROCESS DEFAULTS
10211   --   RETURN
10212   --CASE 3 Complete Validate
10213   --   Existing functionality
10214   --CASE 4 Validate ONLY Backed out results
10215   --
10216   --CASE 5 enroll into backed out compensation objects
10217   --
10218   --END CASE
10219   --
10220   --END LOOP
10221   --
10222   /* Bug Bug 12871602: Commented the below function call*/
10223   /* l_int_rslts_exist_flag := ele_made_for_inter_pil(
10224                               p_per_in_ler_id        => p_per_in_ler_id,
10225                               p_bckdt_per_in_ler_id  => p_bckdt_per_in_ler_id,
10226                               p_person_id            => p_person_id,
10227                               p_business_group_id    => p_business_group_id,
10228                               p_effective_date       => p_effective_date
10229                               ); */
10230   --
10231   --hr_utility.set_location ('l_int_rslts_exist_flag '||l_int_rslts_exist_flag,15);
10232   --
10233   l_invalid_count := 0;
10234   l_invalid_pen_table.delete;
10235   l_invalid_epe_table.delete;
10236 
10237   /*Bug 13711703 */
10238   open c_reopen_le;
10239   fetch c_reopen_le into l_reopen_le_on_reprocess ;
10240   if(c_reopen_le%found) then
10241   close c_reopen_le;
10242      l_reopen_le_on_reprocess := 'Y';
10243   else
10244   close c_reopen_le;
10245   l_reopen_le_on_reprocess := 'N';
10246   end if;
10247   --
10248   for r_pel in c_pel(p_per_in_ler_id) loop
10249     --
10250     l_valid_count := 0;
10251     l_valid_pen_table.delete;
10252     l_valid_epe_table.delete;
10253 
10254      /* Bug Bug 12871602: Commented the call to 'ele_made_for_inter_pil' and moved the call inside the loop
10255      so that p_reinstate_cd paramter can be passed to the function call*/
10256      l_int_rslts_exist_flag := ele_made_for_inter_pil(
10257                               p_per_in_ler_id        => p_per_in_ler_id,
10258                               p_bckdt_per_in_ler_id  => p_bckdt_per_in_ler_id,
10259                               p_person_id            => p_person_id,
10260                               p_business_group_id    => p_business_group_id,
10261                               p_effective_date       => p_effective_date,
10262 			      p_reinstate_cd         => r_pel.reinstate_cd
10263                               );
10264 
10265     hr_utility.set_location ('l_int_rslts_exist_flag '||l_int_rslts_exist_flag,15);
10266     --
10267     hr_utility.set_location ('r_pel.pgm_id :'||r_pel.pgm_id,20);
10268     hr_utility.set_location ('r_pel.pl_id :'||r_pel.pl_id,20);
10269     hr_utility.set_location ('r_pel.reinstate_cd :'||r_pel.reinstate_cd,20);
10270     --
10271     if l_int_rslts_exist_flag = 'Y' then
10272        if r_pel.reinstate_cd = 'DONOT_REINSTATE' then
10273          --
10274          hr_utility.set_location('reinstate_cd '||r_pel.reinstate_cd,30);
10275          hr_utility.set_location('Leaving:'|| l_proc, 30);
10276          exit ;
10277          --
10278 
10279 	/* Added for Enhancement Bug :8716679 */
10280         elsif  r_pel.reinstate_cd = 'VALIDATE_EXPLICIT_ENRT' then
10281 
10282 	   hr_utility.set_location('reinstate_cd '||r_pel.reinstate_cd,30);
10283 	   hr_utility.set_location('p_bckdt_per_in_ler_id '||p_bckdt_per_in_ler_id,30);
10284 	   l_default := 'N';
10285 	   l_reinstate_def := 'Y';
10286 
10287            /* Get the per_in_ler_id of the Intervening  LE*/
10288            open c_int_pil_id;
10289 	   fetch c_int_pil_id into l_int_pil_id;
10290 	   close c_int_pil_id;
10291 	   hr_utility.set_location('l_int_pil_id '||l_int_pil_id,30);
10292 
10293 	   /* Bug 12688164 : If LE is not backed out because of intervening LE, defaults should not be applied*/
10294 	   if(l_int_pil_id is not NULL) then
10295 		   /* Get the latest processed per_in_ler_id of the intervening LE's */
10296 		   open c_future_pil;
10297 		   fetch c_future_pil into l_prev_pil_id;
10298 		   if(c_future_pil%notfound) then
10299 		     hr_utility.set_location('cursor not foind ',30);
10300 		     l_prev_pil_id := l_int_pil_id;
10301 		   end if;
10302 		   close c_future_pil;
10303 		   hr_utility.set_location('l_prev_pil_id '||l_prev_pil_id,30);
10304 
10305 
10306 
10307 		      if(l_prev_pil_id <> l_int_pil_id) then
10308 			hr_utility.set_location('cond 1 ',30);
10309 			l_default := 'Y';
10310 		     else
10311 		       open c_chk_intevent_bckdt(l_int_pil_id);
10312 		       fetch c_chk_intevent_bckdt into l_dummy;
10313 		       if(c_chk_intevent_bckdt%notfound) then
10314 			  close c_chk_intevent_bckdt;
10315 			  hr_utility.set_location('cond 2 ',30);
10316 			  l_default := 'Y';
10317 		       else
10318 			  close c_chk_intevent_bckdt;
10319 			  hr_utility.set_location('cond 2 ',30);
10320 			  l_default := 'N';
10321 		       end if;
10322 		     end if;
10323 	 else
10324 	    l_default := 'N';
10325 	 end if;
10326 
10327          if(l_default = 'Y') then
10328 
10329 	      /*open c_prev_pil;
10330               fetch c_prev_pil into l_prev_pil_id;
10331               close c_prev_pil;*/
10332                      g_reinstated_defaults.delete;
10333 
10334                      /* Check explicit elections made for intervening LE*/
10335 		     open c_chk_exp_inter_pil;
10336 		     fetch c_chk_exp_inter_pil into l_dummy;
10337 		     close c_chk_exp_inter_pil;
10338 		     hr_utility.set_location('l_dummy value '||l_dummy,30);
10339 
10340 		      open c_ler_id;
10341 		      fetch c_ler_id into l_ler_id;
10342 		      close c_ler_id;
10343 
10344                       if(l_dummy = 'Y') then
10345 
10346 			      ben_env_object.get(l_env_obj);
10347                               hr_utility.set_location('Mode '||l_env_obj.mode_cd,30);
10348 
10349                               /* Carry Forward the suspended enrollments*/
10350 			      ben_carry_forward_items.carry_farward_results(
10351 				p_person_id           => p_person_id
10352 			       ,p_per_in_ler_id       => p_per_in_ler_id
10353 			       ,p_ler_id              => l_ler_id
10354 			       ,p_business_group_id   => p_business_group_id
10355 			       ,p_mode                => l_env_obj.mode_cd --'L'
10356 			       ,p_effective_date      => p_effective_date
10357 				);
10358 
10359 		   /* Reinstating Defaults of Intervening lifevent elections.
10360 		      Reinstate only if Explicit Enrollments exist for intervening LE*/
10361 
10362 		              l_def_applied := 'Y';
10363 			      g_dflt_during_reinstate := 'Y'; -- Bug 14119948
10364 			      default_comp_obj
10365 					  (p_validate           => p_validate
10366 					  ,p_per_in_ler_id      => p_per_in_ler_id
10367 					  ,p_person_id          => p_person_id
10368 					  ,p_business_group_id  => p_business_group_id
10369 					  ,p_effective_date     => p_effective_date
10370 					  ,p_pgm_id             => r_pel.pgm_id
10371 					  ,p_pl_nip_id          => r_pel.pl_id
10372 					  ,p_susp_flag          => l_susp_flag
10373 					  ,p_batch_flag         => l_batch_flag
10374 					  ,p_cls_enrt_flag      => FALSE
10375 					  ,p_called_frm_ss      => FALSE
10376 					  ,p_reinstate_dflts_flag => 'Y'
10377 					  ,p_prev_per_in_ler_id => l_prev_pil_id
10378 					 );
10379 		      end if;
10380            end if;
10381 
10382 	     /* Reinstate enrollments of backedout LifeEvent is no enrollments found for the plantype
10383 	        in intervening lifevent and reinstating the enrollments of backeout LE which are
10384 		explicitly elected and defaulted in intervening LE*/
10385 		 l_rslt_exist_flag  := ele_made_for_bckdt_pil (
10386                            p_bckdt_per_in_ler_id     => p_bckdt_per_in_ler_id
10387                           ,p_person_id               => p_person_id
10388                           ,p_business_group_id       => p_business_group_id
10389                           ,p_effective_date          => p_effective_date
10390                           );
10391 		      --
10392 		      hr_utility.set_location('l_rslt_exist_flag '||l_rslt_exist_flag,140);
10393 		      hr_utility.set_location('reinstate_cd '||r_pel.reinstate_cd,50);
10394 
10395 		      get_backedout_results(
10396                              p_person_id              => p_person_id
10397                             ,p_pgm_id                 => r_pel.pgm_id
10398                             ,p_pl_id                  => r_pel.pl_id
10399                             ,p_effective_date         => p_effective_date
10400                             ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
10401                             ,p_pilepe_inst_table      => l_bckdt_pilepe_table
10402                             ,p_bckdt_pen_table        => l_bckdt_pen_table
10403                       );
10404                       l_bckdt_epe_count := l_bckdt_pilepe_table.COUNT;
10405 
10406 		     /* Loop thru the backedout results*/
10407 		     for l_bckdt_epe in 1..l_bckdt_epe_count loop
10408 
10409 		             l_bckdt_pilepe_inst_row := l_bckdt_pilepe_table(l_bckdt_epe);
10410 		             hr_utility.set_location(' Reinstate '||l_bckdt_pen_table(l_bckdt_epe).pgm_id
10411 					      ||' PLN '||l_bckdt_pen_table(l_bckdt_epe).pl_id||' OIPL '
10412 					      ||l_bckdt_pen_table(l_bckdt_epe).oipl_id,175);
10413 			     ben_reinstate_epe_cache.get_pilcobjepe_dets(
10414 					    p_per_in_ler_id => p_per_in_ler_id
10415 					   ,p_pgm_id        => l_bckdt_pen_table(l_bckdt_epe).pgm_id
10416 					   ,p_pl_id         => l_bckdt_pen_table(l_bckdt_epe).pl_id
10417 					   ,p_oipl_id       => l_bckdt_pen_table(l_bckdt_epe).oipl_id
10418 					   ,p_inst_row      => l_pilepe_inst_row
10419 					    );
10420 
10421 			    --if epe record found in the latest PIL then go ahead and compare the results
10422 			    --otherwise go to next backedout epe.. but at the same time record the non-backed out
10423 			    --epe records
10424 			    if l_pilepe_inst_row.elig_per_elctbl_chc_id is not null then
10425 			       hr_utility.set_location('l_pilepe_inst_row.pgm_id  '||l_pilepe_inst_row.pgm_id,117);
10426 			       hr_utility.set_location('l_pilepe_inst_row.pl_typ_id  '||l_pilepe_inst_row.pl_typ_id,117);
10427 			       hr_utility.set_location('l_pilepe_inst_row.epe_id  '||l_pilepe_inst_row.elig_per_elctbl_chc_id,117);
10428 
10429 			       /*Added to the resintate if the enrollment is not either carry forwarded or defaulted*/
10430 				if(g_reinstated_defaults.COUNT > 0
10431 				   and check_pl_typ_defaulted(l_pilepe_inst_row.pl_typ_id,l_pilepe_inst_row.pgm_id) = 'Y' ) then
10432 					 hr_utility.set_location('Plan Already Defaulted ',117);
10433 					 hr_utility.set_location('Plan Not Added to Reinstate list  ',117);
10434 					 l_invalid_count := l_invalid_count + 1 ;
10435 					 l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10436 					 l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10437 				else
10438 				       hr_utility.set_location('Plan Added to Reinstate list ',117);
10439 				       l_valid_count := l_valid_count + 1 ;
10440 				       l_valid_epe_table(l_valid_count) := l_pilepe_inst_row ;
10441 				       l_valid_pen_table(l_valid_count) := l_bckdt_pen_table(l_bckdt_epe);
10442 				end if;
10443 			       --
10444 			    else
10445 			      --
10446 			      l_invalid_count := l_invalid_count + 1 ;
10447 			      l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10448 			      l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10449 			      --
10450 			      hr_utility.set_location('NO EPE '||l_bckdt_pilepe_inst_row.elig_per_elctbl_chc_id,250);
10451 			      --
10452 			    end if ;
10453 		    --
10454 		  end loop;
10455 
10456                   /* Now call the reinstate logic*/
10457 		  if l_valid_pen_table.COUNT > 0 and l_valid_epe_table.COUNT > 0 then
10458 			hr_utility.set_location('Calling reinstate_prev_enrt_for_popl '
10459 						   ||r_pel.pgm_id||' PLN '||r_pel.pl_id,300);
10460 
10461                         /* Added for Bug 13079111 */
10462 						--Bug 13940072 added pgm_id and pl_id check to fetch correct record
10463 			        open c_popl_rec(p_bckdt_per_in_ler_id,r_pel.pgm_id,r_pel.pl_id);
10464 			       fetch c_popl_rec into l_popl_rec;
10465 			       if(c_popl_rec%found) then
10466 				 l_ele_date := l_popl_rec.elcns_made_dt;
10467 				 close c_popl_rec;
10468                  --Bug 13940072 added pgm_id and pl_id check to fetch correct record
10469 				 open c_popl_rec(p_per_in_ler_id,r_pel.pgm_id,r_pel.pl_id);
10470 				 fetch c_popl_rec into l_popl_rec;
10471 				 close c_popl_rec;
10472 				  hr_utility.set_location('Setting elections made date to old date ',400);
10473 				  ben_Pil_Elctbl_chc_Popl_api.update_Pil_Elctbl_chc_Popl
10474 						(p_validate               => p_validate
10475 						,p_pil_elctbl_chc_popl_id => l_popl_rec.PIL_ELCTBL_CHC_POPL_ID
10476 						,p_elcns_made_dt          => l_ele_date
10477 						,p_object_version_number  => l_popl_rec.object_version_number
10478 						,p_effective_date         => p_effective_date
10479 						,p_business_group_id      => p_business_group_id
10480 						);
10481 			      else
10482 				close c_popl_rec;
10483 			       end if;
10484 			       /*End of code changes for Bug 13079111 */
10485 
10486 			--
10487 			   l_def_plus_reinsate_flag := 'Y';
10488 			   reinstate_prev_enrt_for_popl(
10489 			     p_bckdt_pen_table          => l_valid_pen_table
10490 			    ,p_epe_table                => l_valid_epe_table
10491 			    ,p_pgm_table                => l_pgm_table
10492 			    ,p_pl_table                 => l_pl_table
10493 			    ,p_enrt_table               => l_enrt_table
10494 			    ,p_person_id                => p_person_id
10495 			    ,p_pgm_id                   => r_pel.pgm_id
10496 			    ,p_pl_id                    => r_pel.pl_id
10497 			    ,p_business_group_id        => p_business_group_id
10498 			    ,p_effective_date           => p_effective_date
10499 			    ,p_per_in_ler_id            => p_per_in_ler_id
10500 			    ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
10501 			    ,p_enrt_perd_strt_dt        => r_pel.enrt_perd_strt_dt
10502 			    ,p_max_enrt_esd             => l_max_enrt_esd_out
10503 			);
10504 
10505 			 if l_max_enrt_esd_out >= nvl(l_max_enrt_esd,l_max_enrt_esd_out) then
10506 				l_max_enrt_esd := l_max_enrt_esd_out ;
10507 		         end if;
10508 		  else
10509 		        /* Bug 12688164 : If only defaults are applied, then the procedures called from default
10510 			enrollment process should be called now as these calls are skipped while creating
10511 			the enrollment results for defaults. Added else condition*/
10512 		        hr_utility.set_location(' Doing multirow edit for Defaults ',260);
10513 		        ben_proc_common_enrt_rslt.set_elcn_made_or_asnd_dt(
10514 			     p_per_in_ler_id     => p_per_in_ler_id
10515 			    ,p_pgm_id            => r_pel.pgm_id
10516 			    ,p_pl_id             => r_pel.pl_id
10517 			    ,p_enrt_mthd_cd      => 'D'
10518 			    ,p_business_group_id => p_business_group_id
10519 			    ,p_effective_date    => p_effective_date
10520 			    ,p_validate          => FALSE
10521 			     );
10522 
10523 			  -- Check data to make sure multi-rows adit passed.  This section is used
10524 			  -- for the last program ID.
10525 			  --
10526 			    Ben_PRTT_ENRT_RESULT_api.multi_rows_edit
10527 						(p_person_id           => p_person_id
10528 						 ,p_effective_date     => p_effective_date
10529 						 ,p_business_group_id  => p_business_group_id
10530 						 ,p_pgm_id 	       => r_pel.pgm_id
10531 						 ,p_per_in_ler_id      => p_per_in_ler_id
10532 						 ,p_called_frm_ss      => FALSE
10533 						 );
10534 			  -- End if;
10535 			  --
10536 			  -- Invoke post result process.
10537 			  --
10538 			  Ben_proc_common_enrt_rslt.process_post_results
10539 			    (p_person_id          => p_person_id
10540 			    ,p_enrt_mthd_cd       => 'D'
10541 			    ,p_effective_date     => p_effective_date
10542 			    ,p_business_group_id  => p_business_group_id
10543 			    ,p_validate           => FALSE
10544 			    ,p_per_in_ler_id      => p_per_in_ler_id
10545 			    ,p_called_frm_ss      => FALSE
10546 			    );
10547 			  --
10548 			  -- Invoke process_post_enrollment.
10549 			  --
10550 			  Ben_proc_common_enrt_rslt.process_post_enrollment
10551 			    (p_per_in_ler_id     => p_per_in_ler_id
10552 			    ,p_pgm_id            => r_pel.pgm_id
10553 			    ,p_pl_id             => r_pel.pl_id
10554 			    ,p_enrt_mthd_cd      => 'D'
10555 			    ,p_proc_cd           => 'DFLTENRT'
10556 			    ,p_person_id         => p_person_id
10557 			    ,p_business_group_id => p_business_group_id
10558 			    ,p_effective_date    => p_effective_date
10559 			    ,p_validate          => FALSE
10560 			    ,p_cls_enrt_flag     => FALSE
10561 			    );
10562                   end if;
10563 		  hr_utility.set_location(' l_invalid_count '||l_invalid_count,260);
10564 		  hr_utility.set_location(' l_valid_count '||l_valid_count,260);
10565 		  /* End of enhancement bug 8716679*/
10566 
10567              else
10568 			 --Call the default process for the program or plan not in program
10569 			 hr_utility.set_location ('Before call to default_comp_obj '||l_proc,40);
10570 			 --
10571 			 if fnd_global.conc_request_id in (0,-1) then
10572 			   --
10573 			   l_batch_flag := FALSE ;
10574 			   --
10575 			 else
10576 			   --
10577 			   l_batch_flag := TRUE ;
10578 			   --
10579 			 end if;
10580 			 --
10581 			 g_dflt_during_reinstate := 'Y'; -- Bug 14119948
10582 			 default_comp_obj
10583 				  (p_validate           => p_validate
10584 				  ,p_per_in_ler_id      => p_per_in_ler_id
10585 				  ,p_person_id          => p_person_id
10586 				  ,p_business_group_id  => p_business_group_id
10587 				  ,p_effective_date     => p_effective_date
10588 				  ,p_pgm_id             => r_pel.pgm_id
10589 				  ,p_pl_nip_id          => r_pel.pl_id
10590 				  ,p_susp_flag          => l_susp_flag
10591 				  ,p_batch_flag         => l_batch_flag
10592 				  ,p_cls_enrt_flag      => FALSE
10593 				  ,p_called_frm_ss      => FALSE
10594 				 );
10595 			 --
10596 			 if fnd_global.conc_request_id in (0,-1) then
10597 			   --if called from benauthe
10598 			   g_bckdt_pil_restored_flag := 'Y';
10599 			   g_bckdt_pil_restored_cd   := 'DEFAULT';
10600 			   --
10601 			 else
10602 			   --if called from batch concurrent program
10603 			   fnd_message.set_name('BEN','BEN_94226_APPLIED_DEFAULTS');
10604 			   fnd_message.set_token('LER_NAME',l_bckdt_pil.name);
10605 			   benutils.write(p_text => fnd_message.get);
10606 			   --
10607 			 end if;
10608          --
10609          hr_utility.set_location ('After call to default_comp_obj '||l_proc,40);
10610          --
10611        end if;
10612     else
10613       --Now see other reinstate codes and process accordingly.
10614       --
10615       l_rslt_exist_flag  := ele_made_for_bckdt_pil (
10616                            p_bckdt_per_in_ler_id     => p_bckdt_per_in_ler_id
10617                           ,p_person_id               => p_person_id
10618                           ,p_business_group_id       => p_business_group_id
10619                           ,p_effective_date          => p_effective_date
10620                           );
10621       --
10622       hr_utility.set_location('l_rslt_exist_flag '||l_rslt_exist_flag,140);
10623 
10624       hr_utility.set_location('reinstate_cd '||r_pel.reinstate_cd,50);
10625       --
10626       if r_pel.reinstate_cd = 'DONOT_REINSTATE' then
10627         --
10628         hr_utility.set_location('Leaving:'|| l_proc, 60);
10629         exit ;
10630         --
10631       elsif NVL(r_pel.reinstate_cd,'VALIDATE_ALL') = 'VALIDATE_ALL' then
10632         ---
10633         --This needs to be changed to validate for each program or plan not in program
10634         --
10635         hr_utility.set_location('Before call to l_chages_ocrd_flag',70);
10636         --
10637         l_chages_ocrd_flag := comp_ori_new_pil_for_popl(
10638                             p_person_id           => p_person_id
10639                            ,p_business_group_id   => p_business_group_id
10640                            ,p_ler_id              => null
10641                            ,p_effective_date      => p_effective_date
10642                            ,p_per_in_ler_id       => p_per_in_ler_id
10643                            ,p_bckdt_per_in_ler_id => p_bckdt_per_in_ler_id
10644                            ,p_pgm_id              => r_pel.pgm_id
10645                            ,p_pl_id               => r_pel.pl_id
10646                           );
10647         --
10648         hr_utility.set_location(' l_chages_ocrd_flag '||l_chages_ocrd_flag,80);
10649         --
10650         if l_chages_ocrd_flag = 'N' then
10651           --
10652           --Now Reinstate all the results
10653           --
10654           hr_utility.set_location('Before call to get_backedout_results ',90);
10655           --
10656           get_backedout_results(
10657                              p_person_id              => p_person_id
10658                             ,p_pgm_id                 => r_pel.pgm_id
10659                             ,p_pl_id                  => r_pel.pl_id
10660                             ,p_effective_date         => p_effective_date
10661                             ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
10662                             ,p_pilepe_inst_table      => l_bckdt_pilepe_table
10663                             ,p_bckdt_pen_table        => l_bckdt_pen_table
10664           );
10665           --
10666           hr_utility.set_location('After call to get_backedout_results ',90);
10667           --
10668           l_bckdt_epe_count := l_bckdt_pilepe_table.COUNT;
10669           hr_utility.set_location(' l_bckdt_epe_count '||l_bckdt_epe_count,90);
10670           --
10671           for l_bckdt_epe in 1..l_bckdt_epe_count loop
10672             --
10673             --Get the current per_in_ler info
10674             --
10675             l_bckdt_pilepe_inst_row := l_bckdt_pilepe_table(l_bckdt_epe);
10676             --
10677             hr_utility.set_location('Calling ben_reinstate_epe_cache.get_pilcobjepe_dets',100);
10678             hr_utility.set_location('pgm '||l_bckdt_pen_table(l_bckdt_epe).pgm_id,100);
10679             hr_utility.set_location('pln '||l_bckdt_pen_table(l_bckdt_epe).pl_id,100);
10680             hr_utility.set_location('oipl '||l_bckdt_pen_table(l_bckdt_epe).oipl_id,100);
10681             --
10682             ben_reinstate_epe_cache.get_pilcobjepe_dets(
10683                             p_per_in_ler_id => p_per_in_ler_id
10684                            ,p_pgm_id        => l_bckdt_pen_table(l_bckdt_epe).pgm_id
10685                            ,p_pl_id         => l_bckdt_pen_table(l_bckdt_epe).pl_id
10686                            ,p_oipl_id       => l_bckdt_pen_table(l_bckdt_epe).oipl_id
10687                            ,p_inst_row      => l_pilepe_inst_row
10688                             );
10689             --
10690             hr_utility.set_location('from l_pilepe_inst_row EPE'||
10691                                        l_pilepe_inst_row.elig_per_elctbl_chc_id,110);
10692             --
10693             if l_pilepe_inst_row.elig_per_elctbl_chc_id is not null then
10694                --Lucky Guy found a choice ... You are going be reinstated.
10695                --for l_pilepe_inst_row record
10696                l_valid_count := l_valid_count + 1 ;
10697                l_valid_epe_table(l_valid_count) := l_pilepe_inst_row ;
10698                l_valid_pen_table(l_valid_count) := l_bckdt_pen_table(l_bckdt_epe);
10699                --
10700             else
10701               --This should not happen as the records were already compared and there was a match for
10702               --all the backed out and current electable choices
10703               --
10704               l_invalid_count := l_invalid_count + 1 ;
10705               l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10706               l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10707               --
10708             end if ;
10709             --
10710           end loop;
10711           --
10712           hr_utility.set_location('Valid results '||l_valid_count,120);
10713           hr_utility.set_location('Invalid results '||l_invalid_count,120);
10714           --
10715           --
10716         else
10717           --
10718           hr_utility.set_location('Not Reinstating - changes occured ' ,125);
10719           l_not_reinstate := 2 ;
10720           --
10721         end if;
10722         --
10723       else
10724         --Now get all the Backedout results and thier associated EPE records
10725         get_backedout_results(
10726                              p_person_id              => p_person_id
10727                             ,p_pgm_id                 => r_pel.pgm_id
10728                             ,p_pl_id                  => r_pel.pl_id
10729                             ,p_effective_date         => p_effective_date
10730                             ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
10731                             ,p_pilepe_inst_table      => l_bckdt_pilepe_table
10732                             ,p_bckdt_pen_table        => l_bckdt_pen_table
10733         );
10734         --
10735         hr_utility.set_location('Got get_backedout_results '||l_bckdt_pilepe_table.COUNT ,130);
10736         --
10737         l_bckdt_epe_count := l_bckdt_pilepe_table.COUNT;
10738         --
10739         if r_pel.reinstate_cd = 'VALIDATE_RESULT_ALL' then
10740           --In this routine compare all old and new Choice data and if it matches then reinstate else no
10741           --return
10742           --
10743           hr_utility.set_location('Entering VALIDATE_RESULT_ALL',140);
10744           --
10745           for l_bckdt_epe in 1..l_bckdt_epe_count loop
10746             --Get the current per_in_ler info
10747             --
10748             l_bckdt_pilepe_inst_row := l_bckdt_pilepe_table(l_bckdt_epe);
10749             --
10750             hr_utility.set_location(' Calling ben_reinstate_epe_cache.get_pilcobjepe_dets '||l_bckdt_pen_table(l_bckdt_epe).pgm_id
10751                                       ||' PLN '||l_bckdt_pen_table(l_bckdt_epe).pl_id||' OIPL '
10752                                       ||l_bckdt_pen_table(l_bckdt_epe).oipl_id,145);
10753             ben_reinstate_epe_cache.get_pilcobjepe_dets(
10754                             p_per_in_ler_id => p_per_in_ler_id
10755                            ,p_pgm_id        => l_bckdt_pen_table(l_bckdt_epe).pgm_id
10756                            ,p_pl_id         => l_bckdt_pen_table(l_bckdt_epe).pl_id
10757                            ,p_oipl_id       => l_bckdt_pen_table(l_bckdt_epe).oipl_id
10758                            ,p_inst_row      => l_pilepe_inst_row
10759                             );
10760             --
10761             --if epe record found in the latest PIL then go ahead and compare the results
10762             --otherwise go to next backedout epe.. but at the same time record the non-backed out
10763             --epe records
10764             if l_pilepe_inst_row.elig_per_elctbl_chc_id is not null then
10765               --Call compare process for backed out and new epe records
10766               l_chages_ocrd_flag :=  comp_ori_new_epe(
10767                             p_bckdt_epe_row        => l_bckdt_pilepe_inst_row
10768                            ,p_current_epe_row      => l_pilepe_inst_row
10769                            ,p_per_in_ler_id        => p_per_in_ler_id
10770                            ,p_bckdt_per_in_ler_id  => p_bckdt_per_in_ler_id
10771                            ,p_person_id            => p_person_id
10772                            ,p_business_group_id    => p_business_group_id
10773                            ,p_effective_date       => p_effective_date
10774                            );
10775               --
10776               hr_utility.set_location(' l_pilepe_inst_row.elig_per_elctbl_chc_id '||l_pilepe_inst_row.elig_per_elctbl_chc_id,150);
10777               hr_utility.set_location(' l_chages_ocrd_flag '||l_chages_ocrd_flag,150);
10778               --
10779               if l_chages_ocrd_flag = 'N' then
10780                 --Lucky Guy No Changes... You are going be reinstated.
10781                 --
10782                 l_valid_count := l_valid_count + 1 ;
10783                 l_valid_epe_table(l_valid_count) := l_pilepe_inst_row ;
10784                 l_valid_pen_table(l_valid_count) := l_bckdt_pen_table(l_bckdt_epe);
10785                 --
10786               else
10787                 --Change occured for the choice. Dont reinstate
10788                 l_invalid_count := l_invalid_count + 1 ;
10789                 l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10790                 l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10791                 --
10792               end if ;
10793               --
10794             else
10795               --Record the non copied epe records into a pl/sql table since
10796               --Reason NO EPE Available in current life event.
10797               l_invalid_count := l_invalid_count + 1 ;
10798               l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10799               l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10800               --
10801               hr_utility.set_location('NO EPE '||l_bckdt_pilepe_inst_row.elig_per_elctbl_chc_id,160);
10802               --
10803             end if;
10804             --
10805           end loop;
10806           --
10807           hr_utility.set_location(' l_invalid_count '||l_invalid_count,160);
10808           hr_utility.set_location(' l_valid_count '||l_valid_count,160);
10809           --
10810         elsif r_pel.reinstate_cd = 'VALIDATE_RESULT' or r_pel.reinstate_cd = 'VALIDATE_EXPLICIT_ENRT' then
10811           --If you get a hit for EPE ENB ECR in the NEW PIL then enroll in the new EPE ENB ECR
10812           --
10813           hr_utility.set_location('Entering '||r_pel.reinstate_cd,170);
10814 
10815           /* Added for Enhancement Bug 8716679*/
10816 	  if(r_pel.reinstate_cd = 'VALIDATE_EXPLICIT_ENRT') then
10817 	   if( call_defaults(p_per_in_ler_id,p_bckdt_per_in_ler_id,p_effective_date,p_person_id) = 'Y' ) then
10818 	       hr_utility.set_location(' Calling defaults second part '||r_pel.reinstate_cd,1999);
10819 	       g_dflt_during_reinstate := 'Y'; -- Bug 14119948
10820 	       default_comp_obj
10821 		  (p_validate           => p_validate
10822 		  ,p_per_in_ler_id      => p_per_in_ler_id
10823 		  ,p_person_id          => p_person_id
10824 		  ,p_business_group_id  => p_business_group_id
10825 		  ,p_effective_date     => p_effective_date
10826 		  ,p_pgm_id             => r_pel.pgm_id
10827 		  ,p_pl_nip_id          => r_pel.pl_id
10828 		  ,p_susp_flag          => l_susp_flag
10829 		  ,p_batch_flag         => l_batch_flag
10830 		  ,p_cls_enrt_flag      => FALSE
10831 		  ,p_called_frm_ss      => FALSE
10832 		 );
10833 		 return;
10834 	   end if;
10835 	  end if;
10836 	  /* End Enhancement Bug 8716679*/
10837           --
10838           for l_bckdt_epe in 1..l_bckdt_epe_count loop
10839             --Get the current per_in_ler info
10840             --
10841             l_bckdt_pilepe_inst_row := l_bckdt_pilepe_table(l_bckdt_epe);
10842             --
10843             hr_utility.set_location(' Calling ben_reinstate_epe_cache.get_pilcobjepe_dets '||l_bckdt_pen_table(l_bckdt_epe).pgm_id
10844                                       ||' PLN '||l_bckdt_pen_table(l_bckdt_epe).pl_id||' OIPL '
10845                                       ||l_bckdt_pen_table(l_bckdt_epe).oipl_id,175);
10846             --
10847             ben_reinstate_epe_cache.get_pilcobjepe_dets(
10848                             p_per_in_ler_id => p_per_in_ler_id
10849                            ,p_pgm_id        => l_bckdt_pen_table(l_bckdt_epe).pgm_id
10850                            ,p_pl_id         => l_bckdt_pen_table(l_bckdt_epe).pl_id
10851                            ,p_oipl_id       => l_bckdt_pen_table(l_bckdt_epe).oipl_id
10852                            ,p_inst_row      => l_pilepe_inst_row
10853                             );
10854             --
10855             --if epe record found in the latest PIL then go ahead and compare the results
10856             --otherwise go to next backedout epe.. but at the same time record the non-backed out
10857             --epe records
10858             if l_pilepe_inst_row.elig_per_elctbl_chc_id is not null then
10859                --Lucky Guy found a choice ... You are going be reinstated.
10860                --for l_pilepe_inst_row record
10861                l_valid_count := l_valid_count + 1 ;
10862                l_valid_epe_table(l_valid_count) := l_pilepe_inst_row ;
10863                l_valid_pen_table(l_valid_count) := l_bckdt_pen_table(l_bckdt_epe);
10864                --
10865             else
10866               --
10867               l_invalid_count := l_invalid_count + 1 ;
10868               l_invalid_epe_table(l_invalid_count) := l_pilepe_inst_row ;
10869               l_invalid_pen_table(l_invalid_count) := l_bckdt_pen_table(l_bckdt_epe);
10870               --
10871               hr_utility.set_location('NO EPE '||l_bckdt_pilepe_inst_row.elig_per_elctbl_chc_id,250);
10872               --
10873             end if ;
10874             --
10875           end loop;
10876           hr_utility.set_location(' l_invalid_count '||l_invalid_count,260);
10877           hr_utility.set_location(' l_valid_count '||l_valid_count,260);
10878           --
10879         end if;
10880         --
10881       end if;  -- Else for VALIDATE_ALL
10882       --This is the right place call reinstate results for the valid epe table
10883       --
10884 
10885     /* commented against bug 7679297
10886 
10887     -- Bug 6328780 -- First we need to end date the enrollments end dated by Open
10888     open c_unres_per_in_ler;
10889     fetch c_unres_per_in_ler into l_unres_per_in_ler;
10890     if c_unres_per_in_ler%NOTFOUND then
10891 
10892      open c_en_dtd_pen_bckdt_pil;
10893       loop
10894 	 fetch c_en_dtd_pen_bckdt_pil into l_en_dtd_pen_bckdt_pil;
10895 	 exit when c_en_dtd_pen_bckdt_pil%NOTFOUND;
10896 	--
10897         hr_utility.set_location('PEN'||l_en_dtd_pen_bckdt_pil.bkup_tbl_id,234234);
10898         --
10899 	ben_prtt_enrt_result_api.delete_enrollment(
10900              p_validate              => false,
10901              p_per_in_ler_id         => p_per_in_ler_id,
10902              p_prtt_enrt_rslt_id     => l_en_dtd_pen_bckdt_pil.bkup_tbl_id,
10903              p_effective_start_date  => l_effective_start_date,
10904              p_effective_end_date    => l_effective_end_date,
10905              p_object_version_number => l_en_dtd_pen_bckdt_pil.object_version_number,
10906              p_business_group_id     => p_business_group_id,
10907              p_effective_date        => p_effective_date,
10908              p_datetrack_mode        => 'DELETE',
10909              p_multi_row_validate    => false);
10910       --
10911       end loop;
10912       --
10913      close c_en_dtd_pen_bckdt_pil;
10914      --
10915     end if;
10916     close c_unres_per_in_ler;
10917 
10918     */
10919 
10920       if l_valid_pen_table.COUNT > 0 and l_valid_epe_table.COUNT > 0 then
10921         hr_utility.set_location('Calling reinstate_prev_enrt_for_popl '
10922                                    ||r_pel.pgm_id||' PLN '||r_pel.pl_id,300);
10923         --
10924             /* Added for Bug 13079111 */
10925 			--Bug 13940072 added pgm_id and pl_id check to fetch correct record
10926                open c_popl_rec(p_bckdt_per_in_ler_id,r_pel.pgm_id,r_pel.pl_id);
10927 	       fetch c_popl_rec into l_popl_rec;
10928 	       if(c_popl_rec%found) then
10929                  l_ele_date := l_popl_rec.elcns_made_dt;
10930                  close c_popl_rec;
10931                 --Bug 13940072 added pgm_id and pl_id check to fetch correct record
10932                  open c_popl_rec(p_per_in_ler_id,r_pel.pgm_id,r_pel.pl_id);
10933 	         fetch c_popl_rec into l_popl_rec;
10934                  close c_popl_rec;
10935 	          hr_utility.set_location('Setting elections made date to old date ',400);
10936                   ben_Pil_Elctbl_chc_Popl_api.update_Pil_Elctbl_chc_Popl
10937 				(p_validate               => p_validate
10938 				,p_pil_elctbl_chc_popl_id => l_popl_rec.PIL_ELCTBL_CHC_POPL_ID
10939 				,p_elcns_made_dt          => l_ele_date
10940 				,p_object_version_number  => l_popl_rec.object_version_number
10941 				,p_effective_date         => p_effective_date
10942 				,p_business_group_id      => p_business_group_id
10943 				);
10944                else
10945                 close c_popl_rec;
10946 	       end if;
10947                /*End of code changes for Bug 13079111 */
10948 
10949            reinstate_prev_enrt_for_popl(
10950              p_bckdt_pen_table          => l_valid_pen_table
10951             ,p_epe_table                => l_valid_epe_table
10952             ,p_pgm_table                => l_pgm_table
10953             ,p_pl_table                 => l_pl_table
10954             ,p_enrt_table               => l_enrt_table
10955             ,p_person_id                => p_person_id
10956             ,p_pgm_id                   => r_pel.pgm_id
10957             ,p_pl_id                    => r_pel.pl_id
10958             ,p_business_group_id        => p_business_group_id
10959             ,p_effective_date           => p_effective_date
10960             ,p_per_in_ler_id            => p_per_in_ler_id
10961             ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
10962             ,p_enrt_perd_strt_dt        => r_pel.enrt_perd_strt_dt
10963             ,p_max_enrt_esd             => l_max_enrt_esd_out
10964         );
10965         --
10966         hr_utility.set_location('Done reinstate_prev_enrt_for_popl',310);
10967         --
10968       else
10969         --
10970         hr_utility.set_location('Not Calling reinstate_prev_enrt_for_popl ',310);
10971         --
10972       end if;
10973       --
10974       if l_max_enrt_esd_out >= nvl(l_max_enrt_esd,l_max_enrt_esd_out) then
10975         --
10976         l_max_enrt_esd := l_max_enrt_esd_out ;
10977         --
10978       end if;
10979       --
10980     end if;
10981     --
10982   end loop;
10983   --
10984   --Now for the new enrollments, we need to reinstate rates, flex credits and overrides.
10985   --Also we will make the multirow edits for plans not in process and process post enrollment
10986   --
10987   --
10988   hr_utility.set_location('Reinstate  ',610.2);
10989   hr_utility.set_location('prev stad cd  '||  l_bckdt_pil.prvs_stat_cd ,610.2);
10990   /* Bug 8900007: Fetch the carry forwarded enrollments from the backedout LE. First reinstate is called and
10991  then carry forward logic. After carry forwarding the enrollments, then the action items and certifications
10992  will be restored.*/
10993  if(l_int_rslts_exist_flag = 'N' and l_enrt_table.COUNT is not null and l_enrt_table.COUNT = 0) then
10994          hr_utility.set_location('Populating g_bckdt_sspndd_pen_list',310);
10995 
10996 	 open g_bckdt_pen_sspnd_rslt(p_bckdt_per_in_ler_id,
10997 	                             p_person_id,
10998 				     p_effective_date);
10999 	 fetch g_bckdt_pen_sspnd_rslt BULK COLLECT into g_bckdt_sspndd_pen_list;
11000          close g_bckdt_pen_sspnd_rslt;
11001 	 hr_utility.set_location('g_bckdt_sspndd_pen_list.count'||g_bckdt_sspndd_pen_list.count,310);
11002  end if;
11003  /* End Bug 8900007*/
11004 
11005   /* Added for Enhancement Bug :8716679 */
11006   /* Message after reinstating the explicit elections for the Reinstatement code VALIDATE_EXPLICIT_ENRT*/
11007    if(l_reinstate_def = 'Y' and l_def_plus_reinsate_flag = 'N') then
11008            if fnd_global.conc_request_id in (0,-1) then
11009 		--if called from benauthe
11010 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11011 		  g_bckdt_pil_restored_cd := 'DEFAULT_PART' ;
11012 		  g_bckdt_pil_restored_flag := 'Y';
11013 		else
11014 		  g_bckdt_pil_restored_cd := 'DEFAULT_PART_RPN' ;
11015 		  g_bckdt_pil_restored_flag := 'Y';
11016 		end if;
11017 		--
11018 	      else
11019 		--if called from batch concurrent program
11020 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11021 		  fnd_message.set_name('BEN','BEN_94907_RSTRD_EXPL_ELCT');
11022 		  fnd_message.set_token('RPN_LE',' ');
11023 	          benutils.write(p_text => fnd_message.get);
11024 		else
11025 		  fnd_message.set_name('BEN','BEN_94907_RSTRD_EXPL_ELCT');
11026 		  fnd_message.set_token('RPN_LE','Enrollment reopened for changes.');
11027 	          benutils.write(p_text => fnd_message.get);
11028 		end if;
11029 		--
11030 	      end if;
11031 
11032 	 hr_utility.set_location('Entered the cond ',810);
11033    end if;
11034    /* End of Enhancement Bug :8716679 */
11035 
11036   /* Bug 9006088: If previous state of the backedout life event is 'PROCD', on reprocessing the
11037   LE, life event should be closed */
11038   /* Bug 9710653: Modified conditions for the fix done for Bug 9006088*/
11039   /* Bug 12688164 : Close the LE only when defaults are applied*/
11040   if( l_bckdt_pil.prvs_stat_cd = 'PROCD' and (l_def_plus_reinsate_flag = 'N' and l_def_applied = 'Y')
11041                         and l_reinstate_def = 'Y' ) then
11042 
11043         /*Bug 13711703 */
11044       if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11045 	      hr_utility.set_location('Calling close_single_enrollment ',609);
11046 	      --
11047 	      ben_close_enrollment.close_single_enrollment
11048 			      (p_per_in_ler_id        => p_per_in_ler_id
11049 			      ,p_effective_date       => nvl(l_max_enrt_esd,p_effective_date)
11050 			      ,p_business_group_id    => p_business_group_id
11051 			      ,p_close_cd             => 'FORCE'
11052 			      ,p_validate             => FALSE
11053 			      ,p_close_uneai_flag     => NULL
11054 			      ,p_uneai_effective_date => NULL);
11055 	      --
11056 	      hr_utility.set_location('Done close_single_enrollment ',609);
11057       end if;
11058   end if;
11059   /*End Bug 9006088 */
11060 
11061  /* Bug 12688164 : Call other procedures for the enrollments that are reinstated and then close the LE.*/
11062   if ( ( l_int_rslts_exist_flag = 'N' or (l_def_plus_reinsate_flag = 'Y' and l_reinstate_def = 'Y') ) and l_enrt_table.COUNT > 0) then
11063     --
11064     open c_bckdt_pil ;
11065       fetch c_bckdt_pil into l_bckdt_pil ;
11066     close c_bckdt_pil ;
11067     --
11068     hr_utility.set_location('Calling reinstate_post_enrt ',400);
11069     reinstate_post_enrt(
11070             p_pgm_table               => l_pgm_table
11071            ,p_pl_table                => l_pl_table
11072            ,p_enrt_table              => l_enrt_table
11073            ,p_max_enrt_esd            => l_max_enrt_esd
11074            ,p_person_id               => p_person_id
11075            ,p_business_group_id       => p_business_group_id
11076            ,p_effective_date          => p_effective_date
11077            ,p_per_in_ler_id           => p_per_in_ler_id
11078            ,p_bckdt_per_in_ler_id     => p_bckdt_per_in_ler_id
11079            ,p_cls_enrt_flag           => false --999
11080            );
11081     --
11082     hr_utility.set_location('Done reinstate_post_enrt ',410);
11083     --
11084     -- This needs to be handled for new codes
11085     --
11086     hr_utility.set_location('Calling reinstate_override ',500);
11087     --
11088     reinstate_override(
11089             p_pgm_table               => l_pgm_table
11090            ,p_pl_table                => l_pl_table
11091            ,p_enrt_table              => l_enrt_table
11092            ,p_max_enrt_esd            => l_max_enrt_esd
11093            ,p_person_id               => p_person_id
11094            ,p_business_group_id       => p_business_group_id
11095            ,p_effective_date          => p_effective_date
11096            ,p_per_in_ler_id           => p_per_in_ler_id
11097            ,p_bckdt_per_in_ler_id     => p_bckdt_per_in_ler_id
11098            ,p_cls_enrt_flag           => false --999
11099            );
11100     --
11101     hr_utility.set_location('Done reinstate_override ',510);
11102 
11103         /* Bug 13800755:Restore the old elections made date after reprocessing the LE.If Elections made is not restored to old date, successive
11104 	reprocessing of the LE will see drop in Coverage for the coverage code set to 'Elections'*/
11105 	open c_popl_rec(p_bckdt_per_in_ler_id,null,null);
11106 	fetch c_popl_rec into l_popl_rec;
11107 	if(c_popl_rec%found) then
11108 	 l_ele_date := l_popl_rec.elcns_made_dt;
11109 	 close c_popl_rec;
11110 
11111 	  hr_utility.set_location('Setting elections made date to old date ',400);
11112 	  ben_Pil_Elctbl_chc_Popl_api.update_Pil_Elctbl_chc_Popl
11113 			(p_validate               => p_validate
11114 			,p_pil_elctbl_chc_popl_id => l_popl_rec.PIL_ELCTBL_CHC_POPL_ID
11115 			,p_elcns_made_dt          => l_ele_date
11116 			,p_object_version_number  => l_popl_rec.object_version_number
11117 			,p_effective_date         => p_effective_date
11118 			,p_business_group_id      => p_business_group_id
11119 			);
11120 	else
11121 	close c_popl_rec;
11122 	end if;
11123 
11124     --
11125     --
11126     --Now Determine the logic for close enrollment process.
11127     --to call close enrollment all of the following conditions must satisfy
11128     --backedout enrollment must be in closed status
11129     --all the enrollments should be reinstated
11130     --
11131     if l_bckdt_pil.prvs_stat_cd = 'PROCD' and l_reinstate_def = 'N' and ( nvl(l_invalid_pen_table.COUNT,0) = 0 )  then
11132       --
11133         /*Bug 13711703 */
11134       if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11135 	      hr_utility.set_location('Calling close_single_enrollment ',610);
11136 	      --
11137 	      ben_close_enrollment.close_single_enrollment
11138 			      (p_per_in_ler_id        => p_per_in_ler_id
11139 			      ,p_effective_date       => nvl(l_max_enrt_esd,p_effective_date)
11140 			      ,p_business_group_id    => p_business_group_id
11141 			      ,p_close_cd             => 'FORCE'
11142 			      ,p_validate             => FALSE
11143 			      ,p_close_uneai_flag     => NULL
11144 			      ,p_uneai_effective_date => NULL);
11145 	      --
11146 	      hr_utility.set_location('Done close_single_enrollment ',610);
11147        end if;
11148       --
11149     end if;
11150     --
11151     --
11152     /*
11153     hr_utility.set_location('Calling Void update_person_life_event' ,700);
11154     --
11155     ben_Person_Life_Event_api.update_person_life_event
11156              (p_per_in_ler_id         => p_bckdt_per_in_ler_id
11157              ,p_per_in_ler_stat_cd    => 'VOIDD'
11158              ,p_object_version_number => l_bckdt_pil.object_version_number
11159              ,p_effective_date        => nvl(l_max_enrt_esd,p_effective_date)
11160              ,P_PROCD_DT              => l_procd_dt  -- outputs
11161              ,P_STRTD_DT              => l_strtd_dt
11162              ,P_VOIDD_DT              => l_voidd_dt  );
11163     */
11164     --
11165     hr_utility.set_location('Done update_person_life_event',710);
11166     --
11167     /* Added for Enhancement Bug :8716679. Added If..Else condition */
11168     /* Message after reinstating the explicit elections for the Reinstatement code VALIDATE_EXPLICIT_ENRT*/
11169     if(l_reinstate_def = 'Y') then
11170           if fnd_global.conc_request_id in (0,-1) then
11171 		--if called from benauthe
11172 	    if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11173                 g_bckdt_pil_restored_cd := 'DEFAULT_PART' ;
11174 		g_bckdt_pil_restored_flag := 'Y';
11175 	    else
11176 		g_bckdt_pil_restored_cd := 'DEFAULT_PART_RPN' ;
11177 		g_bckdt_pil_restored_flag := 'Y';
11178 	    end if;
11179 		--
11180 	    else
11181 		--if called from batch concurrent program
11182 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11183 		  fnd_message.set_name('BEN','BEN_94907_RSTRD_EXPL_ELCT');
11184 		  fnd_message.set_token('RPN_LE',' ');
11185 	          benutils.write(p_text => fnd_message.get);
11186 		else
11187 		  fnd_message.set_name('BEN','BEN_94907_RSTRD_EXPL_ELCT');
11188 		  fnd_message.set_token('RPN_LE','Enrollment reopened for changes.');
11189 	          benutils.write(p_text => fnd_message.get);
11190 		end if;
11191 		--
11192 	  end if;
11193        /* End of Enhancement Bug :8716679. */
11194     else
11195 	    if l_invalid_pen_table.COUNT > 0 then
11196 	      --
11197 	      if fnd_global.conc_request_id in (0,-1) then
11198 		--if called from benauthe
11199 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11200 			g_bckdt_pil_restored_cd := 'PART' ;
11201 			g_bckdt_pil_restored_flag := 'Y';
11202 	        else
11203 		   g_bckdt_pil_restored_cd := 'PART_RPN' ;
11204 		   g_bckdt_pil_restored_flag := 'Y';
11205 		end if;
11206 		--
11207 	      else
11208 		--if called from batch concurrent program
11209 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11210 			fnd_message.set_name('BEN','BEN_94225_PARTIAL_REINSTATE');
11211 			fnd_message.set_token('LER_NAME',l_bckdt_pil.name);
11212 			fnd_message.set_token('RPN_LE',' ');
11213 			benutils.write(p_text => fnd_message.get);
11214 		else
11215 		  	fnd_message.set_name('BEN','BEN_94225_PARTIAL_REINSTATE');
11216 			fnd_message.set_token('LER_NAME',l_bckdt_pil.name);
11217 			fnd_message.set_token('RPN_LE','Enrollment reopened for changes.');
11218 			benutils.write(p_text => fnd_message.get);
11219 		end if;
11220 		--
11221 	      end if;
11222 	      --
11223 	    else
11224 	      --
11225 	      if fnd_global.conc_request_id in (0,-1) then
11226 		--if called from benauthe
11227 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11228 			g_bckdt_pil_restored_cd := 'ALL' ;
11229 			g_bckdt_pil_restored_flag := 'Y';
11230 	       else
11231 			g_bckdt_pil_restored_cd := 'ALL_RPN' ;
11232 			g_bckdt_pil_restored_flag := 'Y';
11233 	       end if;
11234 		--
11235 	      else
11236 		--if called from batch concurrent program
11237 		if( nvl(l_reopen_le_on_reprocess,'N') = 'N') then
11238 			fnd_message.set_name('BEN','BEN_92256_BCKDT_PIL_RSTRD');
11239 			fnd_message.set_token('LER_NAME',l_bckdt_pil.name);
11240 			fnd_message.set_token('RPN_LE',' ');
11241 			benutils.write(p_text => fnd_message.get);
11242 		else
11243 			fnd_message.set_name('BEN','BEN_92256_BCKDT_PIL_RSTRD');
11244 			fnd_message.set_token('LER_NAME',l_bckdt_pil.name);
11245 			fnd_message.set_token('RPN_LE','Enrollment reopened for changes.');
11246 			benutils.write(p_text => fnd_message.get);
11247 		end if;
11248 		--
11249 	      end if;
11250 	      --
11251 	    end if;
11252     end if;
11253 
11254     -- Void the communications created to new per_in ler.
11255     --
11256     hr_utility.set_location('Calling void_literature ',800);
11257     --
11258     void_literature(p_person_id         => p_person_id
11259                  ,p_business_group_id   => p_business_group_id
11260                  ,p_effective_date      => nvl(l_max_enrt_esd,p_effective_date)
11261                  ,p_ler_id              => null
11262                  ,p_per_in_ler_id       => p_per_in_ler_id
11263                  );
11264     --
11265     hr_utility.set_location('Done void_literature ',810);
11266     --
11267   end if;
11268   --
11269   --
11270   hr_utility.set_location('Calling Void update_person_life_event' ,700);
11271   --
11272   open c_bckdt_pil ;
11273     fetch c_bckdt_pil into l_bckdt_pil ;
11274   close c_bckdt_pil ;
11275   --
11276   ben_Person_Life_Event_api.update_person_life_event
11277              (p_per_in_ler_id         => p_bckdt_per_in_ler_id
11278              ,p_per_in_ler_stat_cd    => 'VOIDD'
11279              ,p_object_version_number => l_bckdt_pil.object_version_number
11280              ,p_effective_date        => nvl(l_max_enrt_esd,p_effective_date)
11281              ,P_PROCD_DT              => l_procd_dt  -- outputs
11282              ,P_STRTD_DT              => l_strtd_dt
11283              ,P_VOIDD_DT              => l_voidd_dt  );
11284   --
11285   if (l_int_rslts_exist_flag = 'N' or l_def_plus_reinsate_flag = 'Y')  and
11286      ( l_enrt_table.COUNT = 0 or l_not_reinstate  = 2 ) then
11287     --
11288     hr_utility.set_location(' Inside l_int_rslts_exist_flag pad_cmnt_to_rsnd_lit '||l_not_reinstate,820);
11289     hr_utility.set_location(' l_invalid_count '||l_invalid_count,820);
11290     hr_utility.set_location(' l_int_rslts_exist_flag '||l_int_rslts_exist_flag,820);
11291     --
11292     if l_rslt_exist_flag = 'Y' then
11293       -- Add comments to new literature sent out
11294       -- Comment Ex: Because you have experienced another enrollment, your
11295       -- originlal elections have been voided. You must call benefits centre
11296       -- to re-elect.
11297       --
11298       fnd_message.set_name('BEN','BEN_91283_ORI_ELE_VOID_CMNT');
11299       fnd_message.set_token('LER_NAME', ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
11300       l_resnd_cmnt_txt :=  fnd_message.get;
11301       --
11302       pad_cmnt_to_rsnd_lit(
11303                           p_person_id            => p_person_id
11304                           ,p_business_group_id   => p_business_group_id
11305                           ,p_effective_date      => p_effective_date
11306                           ,p_ler_id              => null
11307                           ,p_per_in_ler_id       => p_per_in_ler_id
11308                           ,p_cmnt_txt            => l_resnd_cmnt_txt
11309                          );
11310     else
11311       --
11312       -- Add comments to new literature sent out
11313       -- Comment Ex: This is a replacement PFS generated as a result of the
11314       --    { name of the new event }
11315       --
11316       fnd_message.set_name('BEN','BEN_92284_RESND_LIT_CMNT');
11317       fnd_message.set_token('LER_NAME', ben_lf_evt_clps_restore.g_ler_name_cs_bckdt);
11318       l_resnd_cmnt_txt :=  fnd_message.get;
11319       --
11320       pad_cmnt_to_rsnd_lit(
11321                           p_person_id            => p_person_id
11322                           ,p_business_group_id   => p_business_group_id
11323                           ,p_effective_date      => p_effective_date
11324                           ,p_ler_id              => null
11325                           ,p_per_in_ler_id       => p_per_in_ler_id
11326                           ,p_cmnt_txt            => l_resnd_cmnt_txt
11327                          );
11328       --
11329     end if;
11330     --
11331     --we need to log the enrollments which were not being reinstated into the log file here
11332     --from l_invalid_pen_table table
11333     --
11334     hr_utility.set_location('Done calls to pad_cmnt_to_rsnd_lit ',850);
11335     --
11336   end if;
11337   --
11338   hr_utility.set_location('Completed all PEL records',90);
11339   --
11340   hr_utility.set_location('Leaving:'|| l_proc, 10);
11341   --
11342 end p_lf_evt_clps_restore;
11343 -- ----------------------------------------------------------------------------
11344 -- |------------------------< update_ptnl_per_for_ler >-------------------------|
11345 -- ----------------------------------------------------------------------------
11346 --
11347 -- This procedure is called from the BENAUTHE to void the potential by the
11348 -- user.
11349 procedure update_ptnl_per_for_ler(p_ptnl_ler_for_per_id       in number
11350                           ,p_business_group_id        in number
11351                           ,p_ptnl_ler_for_per_stat_cd in varchar2
11352                           ,p_effective_date           in date) is
11353   --
11354   l_proc                    varchar2(72) := g_package||'.update_ptnl_per_for_ler';
11355   --
11356   cursor c_ptnl is
11357     select *
11358     from   ben_ptnl_ler_for_per ptn
11359     where  ptn.ptnl_ler_for_per_id = p_ptnl_ler_for_per_id
11360       and  ptn.business_group_id   = p_business_group_id;
11361   --
11362   l_ptnl_rec          c_ptnl%rowtype;
11363   l_mnl_dt            date;
11364   l_dtctd_dt          date;
11365   l_procd_dt          date;
11366   l_unprocd_dt        date;
11367   l_voidd_dt          date;
11368   --
11369 begin
11370   --
11371   hr_utility.set_location('Entering:'|| l_proc, 10);
11372   --
11373   if p_ptnl_ler_for_per_stat_cd = 'MNL' then
11374      --
11375      l_mnl_dt := p_effective_date;
11376      --
11377   end if;
11378   --
11379   open  c_ptnl;
11380   fetch c_ptnl into l_ptnl_rec;
11381   if c_ptnl%found then
11382      --
11383      hr_utility.set_location('Voiding  '||p_ptnl_ler_for_per_id,10);
11384      --
11385      ben_ptnl_ler_for_per_api.update_ptnl_ler_for_per
11386            (p_validate                 => false
11387            ,p_ptnl_ler_for_per_id      => l_ptnl_rec.ptnl_ler_for_per_id
11388            ,p_ptnl_ler_for_per_stat_cd => nvl(p_ptnl_ler_for_per_stat_cd,'VOIDD')
11389            ,p_object_version_number    => l_ptnl_rec.object_version_number
11390            ,p_effective_date           => p_effective_date
11391            ,p_mnl_dt                   => l_mnl_dt
11392            ,p_program_application_id   => null
11393            ,p_program_id               => null
11394            ,p_request_id               => null
11395            ,p_program_update_date      => sysdate
11396            ,p_voidd_dt                 => p_effective_date);
11397      --
11398   end if;
11399   close c_ptnl;
11400   --
11401   hr_utility.set_location('Leaving:'|| l_proc, 10);
11402   --
11403 end update_ptnl_per_for_ler;
11404 --
11405 procedure p_reinstate_info_to_form (
11406                            p_pil_restored_flag out nocopy varchar2,
11407                            p_pil_restored_cd   out nocopy varchar2,
11408                            p_bckdt_ler_name    out nocopy varchar2) is
11409 begin
11410    --
11411    p_pil_restored_flag := g_bckdt_pil_restored_flag;
11412    p_pil_restored_cd   := g_bckdt_pil_restored_cd;
11413    p_bckdt_ler_name    := g_bckdt_ler_name;
11414    --
11415 end p_reinstate_info_to_form;
11416 --
11417 
11418 procedure reinstate_the_prev_enrt_rslt(
11419                              p_person_id            in number
11420                             ,p_business_group_id   in number
11421                             ,p_ler_id              in number
11422                             ,p_effective_date      in date
11423                             ,p_per_in_ler_id       in number
11424                             ,p_bckdt_per_in_ler_id in number
11425                            ) is
11426   --
11427   l_proc                    varchar2(72) := g_package||'.reinstate_the_prev_enrt_rslt';
11428   --
11429   l_bckt_csd_per_in_ler_id  number;
11430   l_bckdt_pil_prev_stat_cd  varchar2(80);
11431   l_bckdt_pil_ovn           number;
11432   l_bckdt_lf_evt_ocrd_dt    date ;
11433   l_date                    date;
11434   l_procd_dt                date;
11435   l_strtd_dt                date;
11436   l_voidd_dt                date;
11437 
11438   --
11439   cursor c_bckdt_pil is
11440     select pil.PER_IN_LER_STAT_CD, pil.object_version_number,
11441            pil.lf_evt_ocrd_dt
11442     from ben_per_in_ler pil
11443     where pil.per_in_ler_id = p_bckdt_per_in_ler_id
11444       and pil.business_group_id = p_business_group_id;
11445 
11446 
11447   -- Get the enrollment results from the backup table for backed out pil.
11448   --
11449   -- 9999 need to union to pen to get the results which are backed out status.
11450   -- 9999 should not select PLANFC, PLANIMP
11451   cursor c_bckdt_pen is
11452    select
11453           pen.EFFECTIVE_END_DATE,
11454           pen.ASSIGNMENT_ID,
11455           pen.BNFT_AMT,
11456           pen.BNFT_NNMNTRY_UOM,
11457           pen.BNFT_ORDR_NUM,
11458           pen.BNFT_TYP_CD,
11459           pen.BUSINESS_GROUP_ID,
11460           pen.COMP_LVL_CD,
11461           pen.CREATED_BY,
11462           pen.CREATION_DATE,
11463           pen.EFFECTIVE_START_DATE,
11464           pen.ENRT_CVG_STRT_DT,
11465           pen.ENRT_CVG_THRU_DT,
11466           pen.ENRT_MTHD_CD,
11467           pen.ENRT_OVRIDN_FLAG,
11468           pen.ENRT_OVRID_RSN_CD,
11469           pen.ENRT_OVRID_THRU_DT,
11470           pen.ERLST_DEENRT_DT,
11471           pen.LAST_UPDATED_BY,
11472           pen.LAST_UPDATE_DATE,
11473           pen.LAST_UPDATE_LOGIN,
11474           pen.LER_ID,
11475           pen.NO_LNGR_ELIG_FLAG,
11476           pen.OBJECT_VERSION_NUMBER,
11477           pen.OIPL_ID,
11478           pen.OIPL_ORDR_NUM,
11479           pen.ORGNL_ENRT_DT,
11480           pen.LCR_ATTRIBUTE1,
11481           pen.LCR_ATTRIBUTE10,
11482           pen.LCR_ATTRIBUTE11,
11483           pen.LCR_ATTRIBUTE12,
11484           pen.LCR_ATTRIBUTE13,
11485           pen.LCR_ATTRIBUTE14,
11486           pen.LCR_ATTRIBUTE15,
11487           pen.LCR_ATTRIBUTE16,
11488           pen.LCR_ATTRIBUTE17,
11489           pen.LCR_ATTRIBUTE18,
11490           pen.LCR_ATTRIBUTE19,
11491           pen.LCR_ATTRIBUTE2,
11492           pen.LCR_ATTRIBUTE20,
11493           pen.LCR_ATTRIBUTE21,
11494           pen.LCR_ATTRIBUTE22,
11495           pen.LCR_ATTRIBUTE23,
11496           pen.LCR_ATTRIBUTE24,
11497           pen.LCR_ATTRIBUTE25,
11498           pen.LCR_ATTRIBUTE26,
11499           pen.LCR_ATTRIBUTE27,
11500           pen.LCR_ATTRIBUTE28,
11501           pen.LCR_ATTRIBUTE29,
11502           pen.LCR_ATTRIBUTE3,
11503           pen.LCR_ATTRIBUTE30,
11504           pen.LCR_ATTRIBUTE4,
11505           pen.LCR_ATTRIBUTE5,
11506           pen.LCR_ATTRIBUTE6,
11507           pen.LCR_ATTRIBUTE7,
11508           pen.LCR_ATTRIBUTE8,
11509           pen.LCR_ATTRIBUTE9,
11510           pen.LCR_ATTRIBUTE_CATEGORY,
11511           pen.PERSON_ID,
11512           pen.PER_IN_LER_ID,
11513           pen.PGM_ID,
11514           pen.PLIP_ORDR_NUM,
11515           pen.PL_ID,
11516           pen.PL_ORDR_NUM,
11517           pen.PL_TYP_ID,
11518           pen.PROGRAM_APPLICATION_ID,
11519           pen.PROGRAM_ID,
11520           pen.PROGRAM_UPDATE_DATE,
11521           pen.bkup_tbl_id  PRTT_ENRT_RSLT_ID,
11522           pen.PRTT_ENRT_RSLT_STAT_CD,
11523           pen.PRTT_IS_CVRD_FLAG,
11524           pen.PTIP_ID,
11525           pen.PTIP_ORDR_NUM,
11526           pen.REQUEST_ID,
11527           pen.RPLCS_SSPNDD_RSLT_ID,
11528           pen.SSPNDD_FLAG,
11529           pen.UOM
11530     from  ben_le_clsn_n_rstr  pen,
11531            ben_per_in_ler pil
11532     where  pil.per_in_ler_id       = p_bckdt_per_in_ler_id
11533     and    pil.person_id           = p_person_id
11534     and    pil.business_group_id   = p_business_group_id
11535     AND    pil.per_in_ler_id       = pen.per_in_ler_id
11536     and    pen.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
11537     and    ((pen.enrt_cvg_thru_dt is null or
11538             pen.enrt_cvg_thru_dt    = hr_api.g_eot)  and
11539 --bug#2604375 - added to control updated result rows for the same per_in_ler
11540             pen.effective_end_date  = hr_api.g_eot
11541            )
11542     and    pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
11543     and pen.bkup_tbl_id not in (
11544          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
11545            from   ben_prtt_enrt_rslt_f pen_inner,
11546                   ben_per_in_ler pil_inner
11547            where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
11548            and    pil_inner.person_id           = p_person_id
11549            and    pil_inner.business_group_id = p_business_group_id
11550            and    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
11551            and    (pen_inner.enrt_cvg_thru_dt is null or
11552                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
11553                   )
11554            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
11555          union
11556          select nvl(pen_inner.RPLCS_SSPNDD_RSLT_ID, -1)
11557              from  ben_le_clsn_n_rstr  pen_inner,
11558                     ben_per_in_ler pil_inner
11559              where  pil_inner.per_in_ler_id       = p_bckdt_per_in_ler_id
11560              and    pil_inner.person_id           = p_person_id
11561              and    pil_inner.business_group_id   = p_business_group_id
11562              AND    pil_inner.per_in_ler_id       = pen_inner.per_in_ler_id
11563              and    pen_inner.bkup_tbl_typ_cd     = 'BEN_PRTT_ENRT_RSLT_F'
11564            and    (pen_inner.enrt_cvg_thru_dt is null or
11565                    pen_inner.enrt_cvg_thru_dt    = hr_api.g_eot
11566                   )
11567            and    pen_inner.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
11568        )
11569     order by 1; -- pen.effective_end_date; -- Low to High
11570   --
11571   -- Get the electable choice data.
11572   --
11573   cursor c_epe_pen(cp_pl_id in number,
11574                    cp_pgm_id in number,
11575                    cp_oipl_id in number,
11576                    cp_per_in_ler_id in number ) is
11577     select epe.*,
11578            pel.enrt_typ_cycl_cd,
11579            pel.enrt_perd_end_dt,
11580            pel.enrt_perd_strt_dt,
11581            to_date('31-12-4712','DD-MM-YYYY') enrt_cvg_end_dt,
11582            pel.dflt_enrt_dt
11583     from   ben_elig_per_elctbl_chc epe,
11584            ben_per_in_ler pil,
11585            ben_pil_elctbl_chc_popl pel
11586     where  epe.per_in_ler_id     = cp_per_in_ler_id
11587       and  epe.business_group_id = p_business_group_id
11588       and  epe.pl_id             = cp_pl_id
11589       and  nvl(epe.pgm_id, -1)   = nvl(cp_pgm_id, -1)
11590       and  nvl(epe.oipl_id, -1)  = nvl(cp_oipl_id, -1)
11591       and  pil.business_group_id = p_business_group_id
11592       and  pel.business_group_id = epe.business_group_id
11593       and  pil.person_id = p_person_id
11594       and  epe.per_in_ler_id = pil.per_in_ler_id
11595       and  pel.per_in_ler_id = epe.per_in_ler_id
11596       and  pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id;
11597   --
11598   l_epe_pen_rec c_epe_pen%rowtype;
11599   --
11600   cursor c_bnft(cp_elig_per_elctbl_chc_id in number,cp_ordr_num number ) is
11601      select enb.enrt_bnft_id,
11602             enb.entr_val_at_enrt_flag,
11603             enb.dflt_val,
11604             enb.val,
11605             enb.dflt_flag,
11606             enb.object_version_number,
11607             enb.prtt_enrt_rslt_id,
11608             enb.cvg_mlt_cd          --Bug 3315323
11609       from  ben_enrt_bnft enb
11610       where enb.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
11611   -- Bug  2526994 we need take the right one
11612   --    and   nvl(enb.mx_wo_ctfn_flag,'N') = 'N' ;
11613         and enb.ordr_num = cp_ordr_num ; --This is more accurate
11614   --
11615   l_bnft_rec            c_bnft%rowtype;
11616   l_bnft_rec_reset      c_bnft%rowtype;
11617   l_bnft_entr_val_found boolean;
11618   l_num_bnft_recs       number := 0;
11619   --
11620   --
11621   cursor c_rt(cp_elig_per_elctbl_chc_id number,
11622               cp_enrt_bnft_id           number) is
11623       select ecr.enrt_rt_id,
11624              ecr.dflt_val,
11625              ecr.val,
11626              ecr.entr_val_at_enrt_flag,
11627              ecr.acty_base_rt_id
11628       from   ben_enrt_rt ecr
11629       where  ecr.elig_per_elctbl_chc_id = cp_elig_per_elctbl_chc_id
11630       and    ecr.business_group_id = p_business_group_id
11631       and    ecr.entr_val_at_enrt_flag = 'Y'
11632       and    ecr.spcl_rt_enrt_rt_id is null
11633   --    and    ecr.prtt_rt_val_id is null
11634       union
11635       select ecr.enrt_rt_id,
11636              ecr.dflt_val,
11637              ecr.val,
11638              ecr.entr_val_at_enrt_flag,
11639              ecr.acty_base_rt_id
11640       from   ben_enrt_rt ecr
11641       where  ecr.enrt_bnft_id = cp_enrt_bnft_id
11642       and    ecr.business_group_id = p_business_group_id
11643       and    ecr.entr_val_at_enrt_flag = 'Y'
11644       and    ecr.spcl_rt_enrt_rt_id is null;
11645   --    and    ecr.prtt_rt_val_id is null;
11646   --
11647   l_rt c_rt%rowtype;
11648   --
11649   type g_rt_rec is record
11650       (enrt_rt_id ben_enrt_rt.enrt_rt_id%type,
11651        dflt_val   ben_enrt_rt.dflt_val%type,
11652        calc_val   ben_enrt_rt.dflt_val%type,
11653        cmcd_rt_val number,
11654        ann_rt_val  number);
11655   --
11656   type g_rt_table is table of g_rt_rec index by binary_integer;
11657   --
11658   --
11659   l_rt_table g_rt_table;
11660   l_count    number;
11661   --
11662   type pgm_rec is record
11663        (pgm_id        ben_pgm_f.pgm_id%type,
11664         enrt_mthd_cd  ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
11665         multi_row_edit_done boolean,
11666         non_automatics_flag boolean,
11667         max_enrt_esd  date);
11668   --
11669   type pl_rec is record
11670        (pl_id         ben_pl_f.pl_id%type,
11671         enrt_mthd_cd  ben_prtt_enrt_rslt_f.enrt_mthd_cd%type,
11672         multi_row_edit_done boolean,
11673         max_enrt_esd  date);
11674   --
11675   type enrt_rec is record
11676        (prtt_enrt_rslt_id        ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
11677         bckdt_prtt_enrt_rslt_id  ben_prtt_enrt_rslt_f.prtt_enrt_rslt_id%type,
11678         bckdt_enrt_ovridn_flag    varchar2(1),
11679         bckdt_enrt_cvg_strt_dt   date,
11680         bckdt_enrt_cvg_thru_dt   date,
11681         g_sys_date               date,
11682         pen_ovn_number           ben_prtt_enrt_rslt_f.object_version_number%type,
11683         old_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
11684         new_pl_id                ben_prtt_enrt_rslt_f.pl_id%type,
11685         old_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
11686         new_oipl_id              ben_prtt_enrt_rslt_f.oipl_id%type,
11687         old_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
11688         new_pl_typ_id            ben_prtt_enrt_rslt_f.pl_typ_id%type,
11689         pgm_id                   ben_prtt_enrt_rslt_f.pgm_id%type,
11690         ler_id                   ben_ler_f.ler_id%type,
11691         elig_per_elctbl_chc_id   ben_elig_per_elctbl_chc.elig_per_elctbl_chc_id%type,
11692         dpnt_cvg_strt_dt_cd      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_cd%type,
11693         dpnt_cvg_strt_dt_rl      ben_elig_per_elctbl_chc.dpnt_cvg_strt_dt_rl%type,
11694         effective_start_date     ben_prtt_enrt_rslt_f.effective_start_date%type
11695         );
11696   --
11697   --
11698   type t_pgm_table is table of pgm_rec index by binary_integer;
11699   type t_pl_table is table of pl_rec index by binary_integer;
11700   type t_enrt_table is table of enrt_rec index by binary_integer;
11701   type t_prtt_rt_val_table is table of number index by binary_integer;
11702   l_pgm_table     t_pgm_table;
11703   l_pl_table      t_pl_table;
11704   l_enrt_table    t_enrt_table;
11705   l_pgm_count     number;
11706   l_pl_count      number;
11707   l_enrt_count    number;
11708   l_prtt_rt_val_table t_prtt_rt_val_table;
11709   --
11710   cursor c_prv(cv_prtt_enrt_rslt_id in number,
11711                cv_acty_base_rt_id   in number) is
11712          select  prv.*
11713          from ben_prtt_rt_val prv
11714          where prv.prtt_enrt_rslt_id      = cv_prtt_enrt_rslt_id
11715            and prv.per_in_ler_id     = p_bckdt_per_in_ler_id
11716            and prv.business_group_id = p_business_group_id
11717            and prv.acty_base_rt_id   = cv_acty_base_rt_id;
11718   --
11719   -- 9999 do I need to use rt_strt_dt or rt_end_date etc.,
11720   --
11721   l_prv_rec c_prv%rowtype;
11722   l_prv_rec_nulls c_prv%rowtype;
11723   --
11724   cursor c_bckt_csd_pen(cv_per_in_ler_id in number) is
11725          select pen.*, pil.lf_evt_ocrd_dt
11726          from ben_prtt_enrt_rslt_f pen,
11727               ben_per_in_ler pil
11728          where pen.per_in_ler_id = cv_per_in_ler_id
11729            and pen.per_in_ler_id = pil.per_in_ler_id
11730            and pen.business_group_id = p_business_group_id
11731            and pil.business_group_id = p_business_group_id
11732            and pen.prtt_enrt_rslt_stat_cd is null
11733            and pen.effective_end_date = hr_api.g_eot
11734            and pen.comp_lvl_cd         not in ('PLANFC', 'PLANIMP')
11735            and (pen.enrt_cvg_thru_dt is null or
11736                 pen.enrt_cvg_thru_dt    = hr_api.g_eot
11737                );
11738   type t_bckt_csd_pen_table is table of c_bckt_csd_pen%rowtype index by binary_integer;
11739   l_bckt_csd_pil_enrt_table t_bckt_csd_pen_table;
11740   l_bckt_csd_pen_esd        date;
11741   l_bckt_csd_pil_leod       date;
11742   -- Bug 2677804 Added new parameter to see the thru date
11743   cursor c_ovridn_rt(v_bckdt_pen_id number
11744                     ,v_new_pen_id   number ) is
11745   select prv2.prtt_rt_val_id new_prv_id,
11746          prv2.object_version_number new_prv_ovn,
11747          prv1.*
11748     from ben_prtt_rt_val prv1, ben_prtt_rt_val prv2
11749    where prv1.prtt_enrt_rslt_id = v_bckdt_pen_id
11750      and prv2.prtt_enrt_rslt_id = v_new_pen_id
11751      and prv1.acty_base_rt_id = prv2.acty_base_rt_id
11752      and prv1.rt_ovridn_flag = 'Y'
11753      and prv1.rt_end_dt <> hr_api.g_eot
11754      and prv1.rt_ovridn_thru_dt >= prv2.rt_strt_dt
11755 --     and prv1.prtt_rt_val_stat_cd is null
11756      and prv2.prtt_rt_val_stat_cd is null
11757      and prv2.per_in_ler_id = p_per_in_ler_id ;
11758   --
11759   cursor c_ovridn_dpnt(v_bckdt_pen_id number
11760                       ,v_new_pen_id   number
11761                       ,v_effective_date date) is
11762   select pdp2.elig_cvrd_dpnt_id new_pdp_id,
11763          pdp2.object_version_number new_pdp_ovn,
11764          pdp1.*
11765     from ben_elig_cvrd_dpnt_f pdp1,
11766          ben_elig_cvrd_dpnt_f pdp2
11767    where pdp1.prtt_enrt_rslt_id = v_bckdt_pen_id
11768      and pdp2.prtt_enrt_rslt_id = v_new_pen_id
11769      and pdp1.dpnt_person_id = pdp2.dpnt_person_id
11770      and pdp1.ovrdn_flag = 'Y'
11771      and v_effective_date between pdp1.effective_start_date
11772                             and pdp1.effective_end_date
11773      and v_effective_date between pdp2.effective_start_date
11774                             and pdp2.effective_end_date;
11775   --
11776   cursor c_ovn(v_prtt_enrt_rslt_id number) is
11777   select object_version_number
11778     from ben_prtt_enrt_rslt_f
11779    where prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
11780      and effective_end_date = hr_api.g_eot;
11781   --
11782   cursor c_prv_ovn (v_prtt_rt_val_id number) is
11783     select prv.*
11784           ,abr.input_value_id
11785           ,abr.element_type_id
11786     from   ben_prtt_rt_val  prv,
11787            ben_acty_base_rt_f abr
11788     where  prtt_rt_val_id = v_prtt_rt_val_id
11789        and abr.acty_base_rt_id=prv.acty_base_rt_id
11790        and abr.business_group_id = p_business_group_id
11791        and p_effective_date between
11792              abr.effective_start_date and abr.effective_end_date;
11793   --
11794    cursor c_rslt_exists (p_person_id number,
11795                         p_pl_id     number,
11796                         p_oipl_id   number,
11797                         p_per_in_ler_id number)  is -- 8626297
11798     select 'Y'
11799     from ben_prtt_enrt_rslt_f pen
11800     where pen.person_id = p_person_id
11801     and   pen.pl_id     = p_pl_id
11802     and   nvl(pen.oipl_id,-9999)   = nvl(p_oipl_id,-9999)  --5287988
11803      and   pen.per_in_ler_id = p_per_in_ler_id -- 8626297
11804     and   pen.prtt_enrt_rslt_stat_cd is null
11805     and   pen.enrt_cvg_thru_dt = hr_api.g_eot
11806     and   pen.effective_end_date = hr_api.g_eot;
11807 
11808   /* Bug 8863079: Added cursor c_get_epe_id to determine the interim epe record */
11809   cursor c_get_epe_id(c_prtt_enrt_rslt_id number,c_per_in_ler_id number) is
11810     select elig_per_elctbl_chc_id from ben_elig_per_elctbl_chc epe,
11811 		ben_prtt_enrt_rslt_f pen
11812 		where pen.prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
11813 		and epe.per_in_ler_id = c_per_in_ler_id
11814 		and epe.pl_id = pen.pl_id
11815                 and epe.pl_typ_id = pen.pl_typ_id
11816 		and nvl(epe.pgm_id,-1) = nvl(pen.pgm_id,-1)
11817 		and nvl(epe.oipl_id,-1) = nvl(pen.oipl_id,-1);
11818    l_interim_epe_id number;
11819   --
11820   l_rslt_exists    varchar2(30);
11821   --
11822   l_upd_rt_val            boolean;
11823   l_prv_ovn               c_prv_ovn%rowtype;
11824   l_suspend_flag          varchar2(30);
11825   l_prtt_rt_val_id1       number;
11826   l_prtt_rt_val_id2       number;
11827   l_prtt_rt_val_id3       number;
11828   l_prtt_rt_val_id4       number;
11829   l_prtt_rt_val_id5       number;
11830   l_prtt_rt_val_id6       number;
11831   l_prtt_rt_val_id7       number;
11832   l_prtt_rt_val_id8       number;
11833   l_prtt_rt_val_id9       number;
11834   l_prtt_rt_val_id10      number;
11835   l_effective_start_date  date;
11836   l_effective_end_date    date;
11837   l_dpnt_actn_warning     boolean;
11838   l_bnf_actn_warning      boolean;
11839   l_ctfn_actn_warning     boolean;
11840   l_prtt_enrt_interim_id  number;
11841   l_prtt_enrt_rslt_id     number;
11842   l_object_version_number number;
11843   l_cls_enrt_flag         boolean := FALSE;
11844   l_prev_pgm_id           number := NULL; -- Do not change it
11845   l_enrt_mthd_cd          varchar2(30);
11846   l_found                 boolean;
11847   l_enrt_cnt              number := 1;
11848   l_max_enrt_esd          date;
11849   l_esd_out               date;
11850   l_eed_out               date;
11851   l_ovn                   number(15);
11852   --RCHASE - ensure automatics are handled differently than
11853   --         form enrollments by process_post_enrollment
11854   l_proc_cd               varchar2(30);
11855   --
11856   l_found_non_automatics  boolean;
11857   l_dummy_number          number;
11858   --
11859   l_enrt_cvg_strt_dt      date;
11860   --
11861 begin
11862   --
11863   hr_utility.set_location('Entering ' || l_proc,10);
11864   --
11865   open c_bckdt_pil;
11866   fetch c_bckdt_pil into l_bckdt_pil_prev_stat_cd, l_bckdt_pil_ovn, l_bckdt_lf_evt_ocrd_dt ;
11867   close c_bckdt_pil;
11868   l_bckt_csd_per_in_ler_id   := p_bckdt_per_in_ler_id ;
11869 
11870   hr_utility.set_location( ' p_bckdt_per_in_ler_id'||p_bckdt_per_in_ler_id,99) ;
11871   hr_utility.set_location( ' l_bckt_csd_per_in_ler_id ' || l_bckt_csd_per_in_ler_id, 99 );
11872 
11873   ben_close_enrollment.reopen_single_life_event
11874       (p_per_in_ler_id         =>  p_bckdt_per_in_ler_id
11875       ,p_person_id             =>  p_person_id
11876       ,p_lf_evt_ocrd_dt        =>  l_bckdt_lf_evt_ocrd_dt
11877       ,p_effective_date        =>  p_effective_date
11878       ,p_business_group_id     =>  p_business_group_id
11879       ,p_object_version_number =>  l_bckdt_pil_ovn
11880       ,p_source                =>  'backout'  --Bug 5929635 Call reopen_single_life_event in backout routine
11881       ) ;
11882 
11883 
11884   --
11885   l_cls_enrt_flag := TRUE;
11886   ---
11887   l_pgm_table.delete;
11888   l_pl_table.delete;
11889   l_enrt_table.delete;
11890   l_bckt_csd_pil_enrt_table.delete;
11891   --
11892   -- Get the enrollment results attached to per in ler which
11893   -- caused the back out of currenlty backed out per in ler.
11894   --
11895   if l_bckt_csd_per_in_ler_id is not null then
11896      --
11897      for l_bckt_csd_pen_rec in c_bckt_csd_pen(l_bckt_csd_per_in_ler_id) loop
11898          --
11899          l_bckt_csd_pil_enrt_table(l_enrt_cnt) := l_bckt_csd_pen_rec;
11900          l_enrt_cnt := l_enrt_cnt + 1;
11901          --
11902      end loop;
11903      --
11904   end if;
11905   --
11906   -- For each of the enrollment result in back up table, create
11907   -- a enrollment.
11908   --
11909   FOR l_bckdt_pen_rec in c_bckdt_pen loop
11910     --
11911     -- If the enrollment record is valid for the current
11912     -- effective_date then recreate the enrollment.
11913     --
11914     hr_utility.set_location('Inside BCKDT pen loop ' || l_proc,20);
11915     hr_utility.set_location('prtt rslt id ' || l_bckdt_pen_rec.prtt_enrt_rslt_id,20);
11916     --
11917     -- 9999 modify the if clause to look at effective_end_date
11918     -- Why this condition? Is it to look at only the enrollments
11919     -- which are valid as of benmngle run date? If so then should it
11920     -- be sysdate as the results are reinstated as of sysdate.
11921     -- or should it be l_bckdt_pen_rec.effective_end_date = EOT
11922     --
11923     -- if p_effective_date <= l_bckdt_pen_rec.effective_end_date
11924     --
11925     l_rslt_exists := 'N';
11926     open c_rslt_exists (l_bckdt_pen_rec.person_id,
11927                         l_bckdt_pen_rec.pl_id,
11928                         l_bckdt_pen_rec.oipl_id,
11929                         l_bckdt_pen_rec.per_in_ler_id); -- 8626297
11930     fetch c_rslt_exists into l_rslt_exists;
11931     close c_rslt_exists;
11932     --
11933     if l_rslt_exists = 'N' then
11934       l_bckt_csd_pen_esd  := null;
11935       l_bckt_csd_pil_leod := null;
11936       if nvl(l_bckt_csd_pil_enrt_table.last,0) > 0 then
11937          --
11938          for l_cnt in 1..l_bckt_csd_pil_enrt_table.LAST loop
11939              --
11940              if nvl(l_bckt_csd_pil_enrt_table(l_cnt).pl_id, -1) = nvl(l_bckdt_pen_rec.pl_id, -1) and
11941                 nvl(l_bckt_csd_pil_enrt_table(l_cnt).pgm_id, -1) = nvl(l_bckdt_pen_rec.pgm_id, -1) and
11942                 nvl(l_bckt_csd_pil_enrt_table(l_cnt).oipl_id, -1) = nvl(l_bckdt_pen_rec.oipl_id, -1)
11943              then
11944                    l_bckt_csd_pen_esd := l_bckt_csd_pil_enrt_table(l_cnt).effective_start_date;
11945                    l_bckt_csd_pil_leod := l_bckt_csd_pil_enrt_table(l_cnt).lf_evt_ocrd_dt;
11946                    exit;
11947              end if;
11948              --
11949          end loop;
11950          --
11951       end if;
11952       --
11953       g_sys_date := greatest(trunc(sysdate),
11954                       nvl(nvl(l_bckt_csd_pen_esd, g_bckt_csd_lf_evt_ocrd_dt), hr_api.g_sot) + 1,
11955                       l_bckdt_pen_rec.effective_start_date);
11956       --
11957       l_max_enrt_esd := greatest(g_sys_date, nvl(l_max_enrt_esd, hr_api.g_sot));
11958       --
11959       hr_utility.set_location('Date used to reinstate the enrollment = ' || g_sys_date, 333);
11960       if g_sys_date <= l_bckdt_pen_rec.effective_end_date
11961       then
11962          --
11963          -- Get the electable choice data to create enrollment row.
11964          --
11965          hr_utility.set_location('epe fetch pl ' || l_bckdt_pen_rec.pl_id,30);
11966          hr_utility.set_location('epe fetch  pgm ' || l_bckdt_pen_rec.pgm_id,30);
11967          hr_utility.set_location('epe fetch oipl ' || l_bckdt_pen_rec.oipl_id,30);
11968          hr_utility.set_location('epe fetch pil ' || l_bckt_csd_per_in_ler_id,30);
11969          open c_epe_pen(l_bckdt_pen_rec.pl_id,
11970                         l_bckdt_pen_rec.pgm_id,
11971                         l_bckdt_pen_rec.oipl_id,
11972                         l_bckt_csd_per_in_ler_id);
11973          fetch c_epe_pen into l_epe_pen_rec;
11974          close c_epe_pen;
11975          hr_utility.set_location('After epe fetch ' || l_proc,30);
11976          hr_utility.set_location('After epe epe ' || l_epe_pen_rec.elig_per_elctbl_chc_id,30);
11977          --
11978          --
11979          l_num_bnft_recs := 0;
11980          l_bnft_entr_val_found := FALSE;
11981          l_bnft_rec := l_bnft_rec_reset;
11982          --
11983          open c_bnft(l_epe_pen_rec.elig_per_elctbl_chc_id,l_bckdt_pen_rec.bnft_ordr_num );
11984          loop
11985            --
11986            hr_utility.set_location('Inside bnft loop ' || l_proc,40);
11987            -- BUG 3315323
11988            --
11989            fetch c_bnft into l_bnft_rec;
11990            exit when c_bnft%notfound;
11991            if l_bnft_rec.entr_val_at_enrt_flag = 'Y' OR l_bnft_rec.cvg_mlt_cd = 'SAAEAR' then
11992               l_bnft_entr_val_found := TRUE;
11993            end if;
11994            l_num_bnft_recs := l_num_bnft_recs + 1;
11995            --
11996            if l_bckdt_pen_rec.BNFT_AMT = l_bnft_rec.VAL then
11997               --
11998               -- Found the benefit we are looking for, so exit.
11999               --
12000               exit;
12001               --
12002            end if;
12003            --
12004          end loop;
12005          --
12006          -- Bug 5282 :  When a backed out life event is repeocessed
12007          -- plans with enter 'enter val at enrollment' coverage amount
12008          -- previous amount is not used when enrollments reinstated.
12009          --
12010          if l_bnft_entr_val_found
12011          then
12012            if l_num_bnft_recs =  0 then
12013               null;
12014               -- This is a error condition, so rollback all the reinstate process.
12015            else
12016               --
12017              l_bnft_rec.val := l_bckdt_pen_rec.BNFT_AMT;
12018               --
12019            end if;
12020          end if;
12021          hr_utility.set_location(l_proc,50);
12022          close c_bnft;
12023          --
12024          for l_count in 1..10 loop
12025             --
12026             -- Initialise array to null
12027             --
12028             l_rt_table(l_count).enrt_rt_id := null;
12029             l_rt_table(l_count).dflt_val := null;
12030             --
12031          end loop;
12032          --
12033          -- Now get the rates.
12034          --
12035          l_count:= 0;
12036          --
12037          for l_rec in c_rt(l_epe_pen_rec.elig_per_elctbl_chc_id,
12038                            l_bnft_rec.enrt_bnft_id)
12039          loop
12040             --
12041             hr_utility.set_location('Inside rate loop ' ||l_proc,50);
12042             --
12043             -- Get the prtt rate val for this enrollment result.
12044             -- Use to pass to the enrollment process.
12045             --
12046             -- Bug : 1634870 : If the user not selected the rate before backout
12047             -- then do not pass it to the reinstate process.
12048             --
12049             hr_utility.set_location('enrt_rt_id : dflt_val : val : entr_val' ||
12050                                     '_at_enrt_flag : acty_base_rt_id : ' , 501);
12051             hr_utility.set_location(l_rec.enrt_rt_id || ' : ' || l_rec.dflt_val || ' : ' || l_rec.val || '
12052   : '
12053                                     || l_rec.entr_val_at_enrt_flag || ' : ' ||
12054                                     l_rec.acty_base_rt_id, 501);
12055            --
12056             l_prv_rec := l_prv_rec_nulls;
12057             open c_prv(l_bckdt_pen_rec.prtt_enrt_rslt_id ,
12058                        l_rec.acty_base_rt_id);
12059             fetch c_prv into l_prv_rec;
12060             if c_prv%found then -- l_prv_rec.prtt_rt_val_id is not null then
12061                --
12062                l_count := l_count+1;
12063                hr_utility.set_location('prtt_rt_val_id : rt_val : ' ||
12064                        l_prv_rec.prtt_rt_val_id ||  ' : ' || l_prv_rec.rt_val
12065                        || ' : ' || l_prv_rec.acty_base_rt_id , 502);
12066                l_rt_table(l_count).enrt_rt_id := l_rec.enrt_rt_id;
12067                if l_prv_rec.mlt_cd in ('CL','CVG','AP','PRNT','CLANDCVG','APANDCVG','PRNTANDCVG') then
12068                   l_rt_table(l_count).dflt_val := l_rec.dflt_val;
12069                   l_rt_table(l_count).calc_val := l_prv_rec.rt_val;
12070                   l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
12071                   l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
12072                else
12073                   l_rt_table(l_count).dflt_val   := l_prv_rec.rt_val;
12074                   l_rt_table(l_count).calc_val   := l_prv_rec.rt_val;
12075                   l_rt_table(l_count).cmcd_rt_val := l_prv_rec.cmcd_rt_val;
12076                   l_rt_table(l_count).ann_rt_val  := l_prv_rec.ann_rt_val;
12077                end if;
12078                --
12079             end if;
12080             close c_prv;
12081             --
12082          end loop;
12083          --
12084          -- Call election information batch process
12085          --
12086          -- 99999 Study all the parameters passed.
12087          --
12088          -- initialize all the out parameters.
12089          l_suspend_flag          := null;
12090          l_prtt_rt_val_id1       := null;
12091          l_prtt_rt_val_id2       := null;
12092          l_prtt_rt_val_id3       := null;
12093          l_prtt_rt_val_id4       := null;
12094          l_prtt_rt_val_id5       := null;
12095          l_prtt_rt_val_id6       := null;
12096          l_prtt_rt_val_id7       := null;
12097          l_prtt_rt_val_id8       := null;
12098          l_prtt_rt_val_id9       := null;
12099          l_prtt_rt_val_id10      := null;
12100          l_effective_start_date  := null;
12101          l_effective_end_date    := null;
12102          l_dpnt_actn_warning     := null;
12103          l_bnf_actn_warning      := null;
12104          l_ctfn_actn_warning     := null;
12105          l_prtt_enrt_interim_id  := null;
12106          l_prtt_enrt_rslt_id     := null;
12107          l_object_version_number := null;
12108 	 l_enrt_cvg_strt_dt      := null;
12109 
12110        -- if cvg_st_dt_cd is enterable then copy the l_bckdt_pen_rec.enrt_cvg_strt_dt
12111        -- 5746429 starts
12112 
12113        if  l_epe_pen_rec.enrt_cvg_strt_dt_cd = 'ENTRBL'
12114         then
12115 	      l_enrt_cvg_strt_dt := l_bckdt_pen_rec.enrt_cvg_strt_dt ;
12116        end if ;
12117        -- 5746429 ends
12118 
12119          hr_utility.set_location('Calling ben_election_information ' ||l_proc,60);
12120          hr_utility.set_location('Calling l_bnft_rec.val ' ||l_bnft_rec.val,60);
12121          hr_utility.set_location('Calling l_epe_pen_rec.prtt_enrt_rslt_id ' ||l_epe_pen_rec.prtt_enrt_rslt_id,60);
12122          hr_utility.set_location('Calling l_bnft_rec.prtt_enrt_rslt_id ' ||l_bnft_rec.prtt_enrt_rslt_id,60);
12123 	     hr_utility.set_location('Calling l_enrt_cvg_strt_dt ' ||l_enrt_cvg_strt_dt,60);
12124 
12125          -- since it is the result  level backout  the result id are nullified so
12126          -- Election information wont look for the result id to get the old result information
12127 
12128          if l_epe_pen_rec.prtt_enrt_rslt_id is not null  then
12129 
12130             l_object_version_number := l_epe_pen_rec.object_version_number ;
12131             ben_ELIG_PER_ELC_CHC_api.update_ELIG_PER_ELC_CHC
12132                        (p_validate                => FALSE
12133                        ,p_elig_per_elctbl_chc_id  => l_epe_pen_rec.elig_per_elctbl_chc_id
12134                        ,p_prtt_enrt_rslt_id       => NULL
12135                        ,p_object_version_number   => l_object_version_number
12136                        ,p_effective_date          => p_effective_date
12137                        );
12138             l_object_version_number := null;
12139 
12140         end if ;
12141 
12142         if l_bnft_rec.prtt_enrt_rslt_id is not null then
12143               l_object_version_number := l_bnft_rec.object_version_number ;
12144               ben_enrt_bnft_api.update_enrt_bnft
12145                   (p_enrt_bnft_id           => l_bnft_rec.enrt_bnft_id
12146                   ,p_effective_date         => p_effective_date
12147                   ,p_object_version_number  => l_object_version_number
12148                   ,p_business_group_id      => p_business_group_id
12149                   ,p_prtt_enrt_rslt_id      => NULL
12150                   );
12151         end if ;
12152         --
12153         --
12154 
12155        /* Bug 8863079: When a Life Event is backedout,while reopening the results of the previous enrollment and
12156 	   if the life event has no electability, do not determine the interim again. Instead use the old interim
12157 	   pen id(from backed out result) record and then determine the interim epe record. Interim record fetched by cursor c_get_epe_id
12158 	   assign to g_reinstate_interim_chc_id which will be used in bensuenr.pkb to determine the interim*/
12159              g_reinstate_interim_flag := false;
12160              g_reinstate_interim_chc_id := null;
12161 	     hr_utility.set_location('Suspended Flag  ' ||l_bckdt_pen_rec.SSPNDD_FLAG,60);
12162              hr_utility.set_location('Interim Rslt Id  ' ||l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID,60);
12163              hr_utility.set_location('P_per_in_ler_id  ' ||p_per_in_ler_id,60);
12164 	     hr_utility.set_location('p_bckdt_per_in_ler_id  ' ||p_bckdt_per_in_ler_id,60);
12165              if(l_bckdt_pen_rec.SSPNDD_FLAG = 'Y' and l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID is not NULL) then
12166 	        if(l_epe_pen_rec.elctbl_flag = 'N') then
12167 		 open c_get_epe_id(l_bckdt_pen_rec.RPLCS_SSPNDD_RSLT_ID,p_bckdt_per_in_ler_id);
12168 	         fetch c_get_epe_id into l_interim_epe_id;
12169 	         close c_get_epe_id;
12170 	         hr_utility.set_location('Interim epe id '||l_interim_epe_id,9995);
12171 		 g_reinstate_interim_flag := true;
12172 		 g_reinstate_interim_chc_id := l_interim_epe_id;
12173 		end if;
12174 	     end if;
12175          /* End of Bug 8863079 */
12176 
12177        ben_election_information.election_information
12178             (p_elig_per_elctbl_chc_id => l_epe_pen_rec.elig_per_elctbl_chc_id,
12179              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,-- l_epe_pen_rec.prtt_enrt_rslt_id,
12180              p_effective_date         => g_sys_date,
12181              p_enrt_mthd_cd           => l_bckdt_pen_rec.enrt_mthd_cd,
12182              p_business_group_id      => p_business_group_id,
12183              p_enrt_bnft_id           => l_bnft_rec.enrt_bnft_id,
12184              p_bnft_val               => l_bnft_rec.val,
12185 	         p_enrt_cvg_strt_dt       => l_enrt_cvg_strt_dt, -- 5746429
12186              p_enrt_rt_id1            => l_rt_table(1).enrt_rt_id,
12187              p_rt_val1                => l_rt_table(1).dflt_val,
12188              p_ann_rt_val1            => l_rt_table(1).ann_rt_val,
12189              p_enrt_rt_id2            => l_rt_table(2).enrt_rt_id,
12190              p_rt_val2                => l_rt_table(2).dflt_val,
12191              p_ann_rt_val2            => l_rt_table(2).ann_rt_val,
12192              p_enrt_rt_id3            => l_rt_table(3).enrt_rt_id,
12193              p_rt_val3                => l_rt_table(3).dflt_val,
12194              p_ann_rt_val3            => l_rt_table(3).ann_rt_val,
12195              p_enrt_rt_id4            => l_rt_table(4).enrt_rt_id,
12196              p_rt_val4                => l_rt_table(4).dflt_val,
12197              p_ann_rt_val4            => l_rt_table(4).ann_rt_val,
12198              p_enrt_rt_id5            => l_rt_table(5).enrt_rt_id,
12199              p_rt_val5                => l_rt_table(5).dflt_val,
12200              p_ann_rt_val5            => l_rt_table(5).ann_rt_val,
12201              p_enrt_rt_id6            => l_rt_table(6).enrt_rt_id,
12202              p_rt_val6                => l_rt_table(6).dflt_val,
12203              p_ann_rt_val6            => l_rt_table(6).ann_rt_val,
12204              p_enrt_rt_id7            => l_rt_table(7).enrt_rt_id,
12205              p_rt_val7                => l_rt_table(7).dflt_val,
12206              p_ann_rt_val7            => l_rt_table(7).ann_rt_val,
12207              p_enrt_rt_id8            => l_rt_table(8).enrt_rt_id,
12208              p_rt_val8                => l_rt_table(8).dflt_val,
12209              p_ann_rt_val8            => l_rt_table(8).ann_rt_val,
12210              p_enrt_rt_id9            => l_rt_table(9).enrt_rt_id,
12211              p_rt_val9                => l_rt_table(9).dflt_val,
12212              p_ann_rt_val9            => l_rt_table(9).ann_rt_val,
12213              p_enrt_rt_id10           => l_rt_table(10).enrt_rt_id,
12214              p_rt_val10               => l_rt_table(10).dflt_val,
12215              p_ann_rt_val10           => l_rt_table(10).ann_rt_val,
12216              p_datetrack_mode         => hr_api.g_insert, -- 99999 l_datetrack_mode,
12217              p_suspend_flag           => l_suspend_flag,
12218              p_called_from_sspnd      => 'N',
12219              p_prtt_enrt_interim_id   => l_prtt_enrt_interim_id,
12220              p_prtt_rt_val_id1        => l_prtt_rt_val_id1,
12221              p_prtt_rt_val_id2        => l_prtt_rt_val_id2,
12222              p_prtt_rt_val_id3        => l_prtt_rt_val_id3,
12223              p_prtt_rt_val_id4        => l_prtt_rt_val_id4,
12224              p_prtt_rt_val_id5        => l_prtt_rt_val_id5,
12225              p_prtt_rt_val_id6        => l_prtt_rt_val_id6,
12226              p_prtt_rt_val_id7        => l_prtt_rt_val_id7,
12227              p_prtt_rt_val_id8        => l_prtt_rt_val_id8,
12228              p_prtt_rt_val_id9        => l_prtt_rt_val_id9,
12229              p_prtt_rt_val_id10       => l_prtt_rt_val_id10,
12230            -- 6131609 : reinstate DFF values
12231             p_pen_attribute_category => l_bckdt_pen_rec.lcr_attribute_category,
12232             p_pen_attribute1  => l_bckdt_pen_rec.lcr_attribute1,
12233             p_pen_attribute2  => l_bckdt_pen_rec.lcr_attribute2,
12234             p_pen_attribute3  => l_bckdt_pen_rec.lcr_attribute3,
12235             p_pen_attribute4  => l_bckdt_pen_rec.lcr_attribute4,
12236             p_pen_attribute5  => l_bckdt_pen_rec.lcr_attribute5,
12237             p_pen_attribute6  => l_bckdt_pen_rec.lcr_attribute6,
12238             p_pen_attribute7  => l_bckdt_pen_rec.lcr_attribute7,
12239             p_pen_attribute8  => l_bckdt_pen_rec.lcr_attribute8,
12240             p_pen_attribute9  => l_bckdt_pen_rec.lcr_attribute9,
12241             p_pen_attribute10 => l_bckdt_pen_rec.lcr_attribute10,
12242             p_pen_attribute11 => l_bckdt_pen_rec.lcr_attribute11,
12243             p_pen_attribute12 => l_bckdt_pen_rec.lcr_attribute12,
12244             p_pen_attribute13 => l_bckdt_pen_rec.lcr_attribute13,
12245             p_pen_attribute14 => l_bckdt_pen_rec.lcr_attribute14,
12246             p_pen_attribute15 => l_bckdt_pen_rec.lcr_attribute15,
12247             p_pen_attribute16 => l_bckdt_pen_rec.lcr_attribute16,
12248             p_pen_attribute17 => l_bckdt_pen_rec.lcr_attribute17,
12249             p_pen_attribute18 => l_bckdt_pen_rec.lcr_attribute18,
12250             p_pen_attribute19 => l_bckdt_pen_rec.lcr_attribute19,
12251             p_pen_attribute20 => l_bckdt_pen_rec.lcr_attribute20,
12252             p_pen_attribute21 => l_bckdt_pen_rec.lcr_attribute21,
12253             p_pen_attribute22 => l_bckdt_pen_rec.lcr_attribute22,
12254             p_pen_attribute23 => l_bckdt_pen_rec.lcr_attribute23,
12255             p_pen_attribute24 => l_bckdt_pen_rec.lcr_attribute24,
12256             p_pen_attribute25 => l_bckdt_pen_rec.lcr_attribute25,
12257             p_pen_attribute26 => l_bckdt_pen_rec.lcr_attribute26,
12258             p_pen_attribute27 => l_bckdt_pen_rec.lcr_attribute27,
12259             p_pen_attribute28 => l_bckdt_pen_rec.lcr_attribute28,
12260             p_pen_attribute29 => l_bckdt_pen_rec.lcr_attribute29,
12261             p_pen_attribute30 => l_bckdt_pen_rec.lcr_attribute30,
12262             --
12263              p_object_version_number  => l_object_version_number,
12264              p_effective_start_date   => l_effective_start_date,
12265              p_effective_end_date     => l_effective_end_date,
12266              p_dpnt_actn_warning      => l_dpnt_actn_warning,
12267              p_bnf_actn_warning       => l_bnf_actn_warning,
12268              p_ctfn_actn_warning      => l_ctfn_actn_warning);
12269          --
12270 
12271          l_prtt_rt_val_table(1)       := l_prtt_rt_val_id1;
12272          l_prtt_rt_val_table(2)       := l_prtt_rt_val_id2;
12273          l_prtt_rt_val_table(3)       := l_prtt_rt_val_id3;
12274          l_prtt_rt_val_table(4)       := l_prtt_rt_val_id4;
12275          l_prtt_rt_val_table(5)       := l_prtt_rt_val_id5;
12276          l_prtt_rt_val_table(6)       := l_prtt_rt_val_id6;
12277          l_prtt_rt_val_table(7)       := l_prtt_rt_val_id7;
12278          l_prtt_rt_val_table(8)       := l_prtt_rt_val_id8;
12279          l_prtt_rt_val_table(9)       := l_prtt_rt_val_id9;
12280          l_prtt_rt_val_table(10)      := l_prtt_rt_val_id10;
12281 
12282          -- if rate is enter value at enrollment and calculation method is like multiple and
12283          -- calculate flag is on, first the prtt_rt_val is created with default value and
12284          -- subsequently the calculated value is updated by taking values from backedout rows
12285          for i  in 1..l_count loop
12286             l_upd_rt_val  := FALSE;
12287             open c_prv_ovn (l_prtt_rt_val_table(i));
12288             fetch c_prv_ovn into l_prv_ovn;
12289             if c_prv_ovn%found then
12290                 if l_prv_ovn.rt_val <>l_rt_table(i).calc_val  then
12291                    l_upd_rt_val := TRUE;
12292                 end if;
12293             end if;
12294             close c_prv_ovn;
12295             if l_upd_rt_val then
12296                 ben_prtt_rt_val_api.update_prtt_rt_val
12297                   (p_prtt_rt_val_id        => l_prtt_rt_val_table(i)
12298                   ,p_person_id             => p_person_id
12299                   ,p_rt_val                => l_rt_table(i).calc_val
12300                   ,p_acty_ref_perd_cd      => l_prv_ovn.acty_ref_perd_cd
12301                   ,p_cmcd_rt_val           => l_rt_table(i).cmcd_rt_val
12302                   ,p_cmcd_ref_perd_cd      => l_prv_ovn.cmcd_ref_perd_cd
12303                   ,p_ann_rt_val            => l_rt_table(i).ann_rt_val
12304                   ,p_business_group_id     => p_business_group_id
12305                   ,p_object_version_number => l_prv_ovn.object_version_number
12306                   ,p_effective_date        => g_sys_date);
12307                 --
12308             end if;
12309          end loop;
12310 
12311 
12312 
12313          -- Populate the enrollment results electble choice data
12314          -- to be used for dependents and beneficiaries restoration.
12315          -- the reinstate beneficiaries and dependents processes
12316          -- from hare as multi row edit process may create
12317          -- these records as part of recycle. So reinstate beneficiaries
12318          -- and dependents processes should be called after multi row edits.
12319          --
12320          --
12321          l_found := FALSE;
12322          if nvl(l_enrt_table.LAST, 0) > 0 then
12323             for l_cnt in 1..l_enrt_table.LAST loop
12324                 --
12325                 if l_enrt_table(l_cnt).prtt_enrt_rslt_id = l_prtt_enrt_rslt_id
12326                 then
12327                    l_found := TRUE;
12328                    exit;
12329                 end if;
12330                 --
12331              end loop;
12332          end if;
12333          --
12334          if not l_found then
12335             --
12336             --
12337             l_enrt_count := nvl(l_enrt_table.LAST, 0) + 1;
12338             l_enrt_table(l_enrt_count).prtt_enrt_rslt_id := l_prtt_enrt_rslt_id;
12339             l_enrt_table(l_enrt_count).effective_start_date := l_effective_start_date;
12340             l_enrt_table(l_enrt_count).bckdt_prtt_enrt_rslt_id
12341                                              := l_bckdt_pen_rec.prtt_enrt_rslt_id;
12342             l_enrt_table(l_enrt_count).bckdt_enrt_ovridn_flag
12343                                              := l_bckdt_pen_rec.enrt_ovridn_flag;
12344             l_enrt_table(l_enrt_count).bckdt_enrt_cvg_strt_dt
12345                                              := l_bckdt_pen_rec.enrt_cvg_strt_dt;
12346             l_enrt_table(l_enrt_count).bckdt_enrt_cvg_thru_dt
12347                                              := l_bckdt_pen_rec.enrt_cvg_thru_dt;
12348             l_enrt_table(l_enrt_count).g_sys_date := g_sys_date;
12349             l_enrt_table(l_enrt_count).pen_ovn_number := l_object_version_number;
12350             l_enrt_table(l_enrt_count).old_pl_id := l_bckdt_pen_rec.pl_id;
12351             l_enrt_table(l_enrt_count).new_pl_id := l_bckdt_pen_rec.pl_id;
12352             l_enrt_table(l_enrt_count).old_oipl_id := l_bckdt_pen_rec.oipl_id;
12353             l_enrt_table(l_enrt_count).new_oipl_id := l_bckdt_pen_rec.oipl_id;
12354             l_enrt_table(l_enrt_count).old_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
12355             l_enrt_table(l_enrt_count).new_pl_typ_id := l_bckdt_pen_rec.pl_typ_id;
12356             l_enrt_table(l_enrt_count).pgm_id := l_bckdt_pen_rec.pgm_id;
12357             l_enrt_table(l_enrt_count).ler_id := null;
12358             l_enrt_table(l_enrt_count).elig_per_elctbl_chc_id
12359                                              := l_epe_pen_rec.elig_per_elctbl_chc_id;
12360            l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_cd
12361                                              := l_epe_pen_rec.dpnt_cvg_strt_dt_cd;
12362             l_enrt_table(l_enrt_count).dpnt_cvg_strt_dt_rl
12363                                              := l_epe_pen_rec.dpnt_cvg_strt_dt_rl;
12364             /* Trace messages for the enrollments, uncomment for tracing bugs */
12365             hr_utility.set_location('prtt_enrt_rslt_id = ' ||
12366                        l_enrt_table(l_enrt_count).prtt_enrt_rslt_id, 9999);
12367             hr_utility.set_location('bckdt_prtt_enrt_rslt_id = ' ||
12368                        l_enrt_table(l_enrt_count).bckdt_prtt_enrt_rslt_id, 9999);
12369             hr_utility.set_location('bckdt_enrt_ovridn_flag = ' ||
12370                        l_enrt_table(l_enrt_count).bckdt_enrt_ovridn_flag, 72);
12371             hr_utility.set_location('bckdt_enrt_cvg_strt_dt = ' ||
12372                        l_enrt_table(l_enrt_count).bckdt_enrt_cvg_strt_dt, 72);
12373             hr_utility.set_location('pen_ovn_number = ' ||
12374                        l_enrt_table(l_enrt_count).pen_ovn_number, 9999);
12375             hr_utility.set_location('old_pl_id = ' ||
12376                        l_enrt_table(l_enrt_count).old_pl_id, 9999);
12377             hr_utility.set_location('new_pl_id = ' ||
12378                        l_enrt_table(l_enrt_count).new_pl_id, 9999);
12379             hr_utility.set_location('old_oipl_id = ' ||
12380                        l_enrt_table(l_enrt_count).old_oipl_id, 9999);
12381             hr_utility.set_location('new_oipl_id = ' ||
12382                        l_enrt_table(l_enrt_count).new_oipl_id, 9999);
12383             hr_utility.set_location('old_pl_typ_id = ' ||
12384                        l_enrt_table(l_enrt_count).old_pl_typ_id, 9999);
12385             hr_utility.set_location('new_pl_typ_id = ' ||
12386                        l_enrt_table(l_enrt_count).new_pl_typ_id, 9999);
12387             hr_utility.set_location('pgm_id = ' ||
12388                        l_enrt_table(l_enrt_count).pgm_id, 9999);
12389             hr_utility.set_location('elig_per_elctbl_chc_id = ' ||
12390                        l_enrt_table(l_enrt_count).elig_per_elctbl_chc_id, 9999);
12391             /**/
12392             --
12393          end if;
12394          --
12395          -- Populate the pgm and pl tables, to pocess post results.
12396          --
12397          if l_epe_pen_rec.pgm_id is null then
12398             --
12399             l_found := FALSE;
12400             if nvl(l_pl_table.LAST, 0) > 0 then
12401                for l_cnt in 1..l_pl_table.LAST loop
12402                    --
12403                    if l_pl_table(l_cnt).pl_id = l_epe_pen_rec.pl_id and
12404                       l_pl_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd
12405                    then
12406                       l_found := TRUE;
12407                       l_pl_table(l_cnt).max_enrt_esd := greatest(l_pl_table(l_cnt).max_enrt_esd,
12408                                                                  g_sys_date);
12409                       exit;
12410                    end if;
12411                    --
12412                end loop;
12413             end if;
12414             --
12415             if not l_found then
12416                --
12417                --
12418                l_pl_count := nvl(l_pl_table.LAST, 0) + 1;
12419                l_pl_table(l_pl_count).pl_id            := l_epe_pen_rec.pl_id;
12420                l_pl_table(l_pl_count).enrt_mthd_cd     := l_bckdt_pen_rec.enrt_mthd_cd;
12421                l_pl_table(l_pl_count).multi_row_edit_done := FALSE;
12422                l_pl_table(l_pl_count).max_enrt_esd := g_sys_date;
12423                --
12424             end if;
12425          else
12426             --
12427             --
12428             l_found := FALSE;
12429             if nvl(l_pgm_table.LAST, 0) > 0 then
12430                for l_cnt in 1..l_pgm_table.LAST loop
12431                    --
12432                    if l_pgm_table(l_cnt).pgm_id = l_epe_pen_rec.pgm_id and
12433                       l_pgm_table(l_cnt).enrt_mthd_cd = l_bckdt_pen_rec.enrt_mthd_cd
12434                    then
12435                       l_found := TRUE;
12436                       l_pgm_table(l_cnt).max_enrt_esd := greatest(l_pgm_table(l_cnt).max_enrt_esd,
12437                                                                  g_sys_date);
12438                       exit;
12439                    end if;
12440                    --
12441                end loop;
12442             end if;
12443             --
12444             if not l_found then
12445                --
12446                --
12447                l_pgm_count := nvl(l_pgm_table.LAST, 0) + 1;
12448                l_pgm_table(l_pgm_count).pgm_id         := l_epe_pen_rec.pgm_id;
12449                l_pgm_table(l_pgm_count).enrt_mthd_cd   := l_bckdt_pen_rec.enrt_mthd_cd;
12450                l_pgm_table(l_pgm_count).multi_row_edit_done := FALSE;
12451                l_pgm_table(l_pgm_count).max_enrt_esd := g_sys_date;
12452                --
12453             end if;
12454             --
12455          end if;
12456          --
12457       end if;
12458       --
12459     end if;  -- l rstl exists
12460       --
12461   end loop;
12462   --
12463   -- Apply the multi row edits.
12464   --
12465   --
12466   if nvl(l_pgm_table.LAST, 0) > 0 then
12467      for l_cnt in 1..l_pgm_table.LAST loop
12468         --
12469         -- First see multi row edits are already checked.
12470         --
12471         l_found  := FALSE;
12472         for l_inn_cnt in 1..l_cnt loop
12473           if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
12474              l_pgm_table(l_inn_cnt).multi_row_edit_done
12475           then
12476              l_found  := TRUE;
12477              exit;
12478           end if;
12479         end loop;
12480         --
12481         if not l_found then
12482            --
12483            --
12484            -- Now see if there are non automatic enrollments
12485            --
12486            if l_bckdt_pil_prev_stat_cd='STRTD' then
12487              l_found_non_automatics:=FALSE;
12488              for l_inn_cnt in 1..l_pgm_table.last loop
12489                if l_pgm_table(l_inn_cnt).pgm_id = l_pgm_table(l_cnt).pgm_id and
12490                   l_pgm_table(l_inn_cnt).enrt_mthd_cd<>'A'
12491                then
12492                   l_found_non_automatics  := TRUE;
12493                   exit;
12494                end if;
12495              end loop;
12496            end if;
12497            --
12498            if l_bckdt_pil_prev_stat_cd<>'STRTD' or
12499               l_found_non_automatics then
12500              hr_utility.set_location('Date for multi row edits = ' ||
12501                                       l_pgm_table(l_cnt).max_enrt_esd || '  ' || ' pgm = ' ||
12502 
12503                                       l_pgm_table(l_cnt).pgm_id, 333);
12504              ben_prtt_enrt_result_api.multi_rows_edit
12505               (p_person_id         => p_person_id,
12506                p_effective_date    => l_pgm_table(l_cnt).max_enrt_esd,
12507                p_business_group_id => p_business_group_id,
12508                p_per_in_ler_id     => p_per_in_ler_id,
12509                p_pgm_id            => l_pgm_table(l_cnt).pgm_id);
12510              --
12511            end if;
12512            l_pgm_table(l_cnt).multi_row_edit_done := TRUE;
12513            --
12514         end if;
12515         --
12516      end loop;
12517   end if;
12518   --
12519   -- Call multi_rows_edit, process_post_results, reinstate_bpl_per_pen
12520   -- Only if the enrollments are reinstated.
12521   --
12522   if nvl(l_enrt_table.LAST, 0) > 0 then
12523      --
12524      -- Call multi row edits and post results only if enrollments are
12525      -- created.
12526      --
12527      -- Call multi row edits just as miscellanious form calls.
12528      --
12529      hr_utility.set_location('Date for multi row edits = ' ||
12530                               l_max_enrt_esd , 333);
12531      ben_prtt_enrt_result_api.multi_rows_edit
12532       (p_person_id         => p_person_id,
12533        p_effective_date    => l_max_enrt_esd,
12534        p_business_group_id => p_business_group_id,
12535        p_per_in_ler_id     => p_per_in_ler_id,
12536        p_pgm_id            => null);
12537      --
12538      -- Invoke post result process once for Explicit/Automatic/ Default.
12539      --
12540      ben_proc_common_enrt_rslt.process_post_results
12541       (p_person_id          => p_person_id,
12542        p_enrt_mthd_cd       => 'E',
12543        p_effective_date     => l_max_enrt_esd,
12544        p_business_group_id  => p_business_group_id,
12545        p_per_in_ler_id      => p_per_in_ler_id);
12546      --
12547      ben_proc_common_enrt_rslt.process_post_results
12548       (p_person_id          => p_person_id,
12549        p_enrt_mthd_cd       => 'D',
12550        p_effective_date     => l_max_enrt_esd,
12551        p_business_group_id  => p_business_group_id,
12552        p_per_in_ler_id      => p_per_in_ler_id);
12553      --
12554      ben_proc_common_enrt_rslt.process_post_results
12555       (p_person_id          => p_person_id,
12556        p_enrt_mthd_cd       => 'A',
12557        p_effective_date     => l_max_enrt_esd,
12558        p_business_group_id  => p_business_group_id,
12559        p_per_in_ler_id      => p_per_in_ler_id);
12560      --
12561   end if;
12562   --
12563   -- Apply process post enrollments once for each program.
12564   --
12565  -- Apply process post enrollments once for each program.
12566   --
12567   if nvl(l_pgm_table.LAST, 0) > 0 then
12568      for l_cnt in 1..l_pgm_table.LAST loop
12569         --
12570         --RCHASE - ensure automatics are handled differently than
12571         --         form enrollments by process_post_enrollment
12572         -- Bug 5623259.
12573         --
12574         if l_pgm_table(l_cnt).enrt_mthd_cd = 'E' then
12575            l_proc_cd := 'FORMENRT';
12576         elsif l_pgm_table(l_cnt).enrt_mthd_cd = 'D' then
12577            l_proc_cd := 'DFLTENRT';
12578         else
12579            l_proc_cd := NULL;
12580         end if;
12581         ben_proc_common_enrt_rslt.process_post_enrollment
12582           (p_per_in_ler_id     => p_per_in_ler_id,
12583            p_pgm_id            => l_pgm_table(l_cnt).pgm_id,
12584            p_pl_id             => null,
12585            p_enrt_mthd_cd      => l_pgm_table(l_cnt).enrt_mthd_cd,
12586            p_cls_enrt_flag     => FALSE,
12587            --RCHASE
12588            p_proc_cd           => l_proc_cd,--'FORMENRT',
12589            p_person_id         => p_person_id,
12590            p_business_group_id => p_business_group_id,
12591            p_effective_date    => l_pgm_table(l_cnt).max_enrt_esd );
12592         --
12593       end loop;
12594   end if;
12595   --
12596   -- Apply process post enrollments once for each program.
12597   --
12598   --
12599   if nvl(l_pl_table.LAST, 0) > 0 then
12600      for l_cnt in 1..l_pl_table.LAST loop
12601         --
12602         -- Invoke post result process
12603         --
12604         hr_utility.set_location('Date = ' || l_pl_table(l_cnt).max_enrt_esd, 333);
12605         hr_utility.set_location('PL = ' || l_pl_table(l_cnt).pl_id, 333);
12606         --RCHASE - ensure automatics are handled differently than
12607         --         form enrollments by process_post_enrollment
12608         -- Bug 5623259.
12609         --
12610         if l_pl_table(l_cnt).enrt_mthd_cd = 'E' then
12611            l_proc_cd := 'FORMENRT';
12612         elsif l_pl_table(l_cnt).enrt_mthd_cd = 'D' then
12613            l_proc_cd := 'DFLTENRT';
12614         else
12615            l_proc_cd := NULL;
12616         end if;
12617         ben_proc_common_enrt_rslt.process_post_enrollment
12618           (p_per_in_ler_id     => p_per_in_ler_id,
12619            p_pgm_id            => null,
12620            p_pl_id             => l_pl_table(l_cnt).pl_id,
12621            p_enrt_mthd_cd      => l_pl_table(l_cnt).enrt_mthd_cd,
12622            p_cls_enrt_flag     => FALSE,
12623            --RCHASE
12624            p_proc_cd           => l_proc_cd,--'FORMENRT',
12625            p_person_id         => p_person_id,
12626            p_business_group_id => p_business_group_id,
12627            p_effective_date    => l_pl_table(l_cnt).max_enrt_esd );
12628         --
12629       end loop;
12630   end if;
12631   if nvl(l_enrt_table.LAST, 0) > 0 then
12632      --
12633      -- Reinstate the ledgers if any created.
12634      --
12635      reinstate_bpl_per_pen(
12636          p_person_id              => p_person_id
12637          ,p_business_group_id      => p_business_group_id
12638          ,p_effective_date         => p_effective_date
12639          ,p_per_in_ler_id          => p_per_in_ler_id
12640          ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
12641          );
12642      --
12643      for l_cnt in 1..l_enrt_table.LAST loop
12644        --
12645        -- Reinstate the enrollment beneficiary rows.
12646        --
12647        hr_utility.set_location('Enrt Date = ' ||
12648                                 l_enrt_table(l_cnt).effective_start_date, 333);
12649 hr_utility.set_location('Reinstate the enrollment beneficiary rows',14);
12650        reinstate_pbn_per_pen(
12651          p_person_id                => p_person_id
12652          ,p_bckdt_prtt_enrt_rslt_id
12653                                     => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
12654          ,p_prtt_enrt_rslt_id       => l_enrt_table(l_cnt).prtt_enrt_rslt_id
12655          ,p_rslt_object_version_number => l_enrt_table(l_cnt).pen_ovn_number
12656          ,p_business_group_id        => p_business_group_id
12657          ,p_per_in_ler_id            => p_per_in_ler_id
12658          ,p_effective_date           => l_enrt_table(l_cnt).effective_start_date
12659          ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
12660          );
12661        --
12662        -- Reinstate the covered dependents.
12663        --
12664        reinstate_dpnts_per_pen(
12665                p_person_id                 => p_person_id
12666                ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
12667                ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).prtt_enrt_rslt_id
12668                ,p_pen_ovn_number           => l_enrt_table(l_cnt).pen_ovn_number
12669                ,p_old_pl_id                => l_enrt_table(l_cnt).old_pl_id
12670                ,p_new_pl_id                => l_enrt_table(l_cnt).new_pl_id
12671                ,p_old_oipl_id              => l_enrt_table(l_cnt).old_oipl_id
12672                ,p_new_oipl_id              => l_enrt_table(l_cnt).new_oipl_id
12673                ,p_old_pl_typ_id            => l_enrt_table(l_cnt).old_pl_typ_id
12674                ,p_new_pl_typ_id            => l_enrt_table(l_cnt).new_pl_typ_id
12675                ,p_pgm_id                   => l_enrt_table(l_cnt).pgm_id
12676                ,p_ler_id                   => l_enrt_table(l_cnt).ler_id
12677                ,p_elig_per_elctbl_chc_id   => l_enrt_table(l_cnt).elig_per_elctbl_chc_id
12678                ,p_business_group_id        => p_business_group_id
12679                -- # 2508745
12680                ,p_effective_date           => nvl(l_enrt_table(l_cnt).effective_start_date,
12681                                                     p_effective_date)
12682                ,p_per_in_ler_id            => p_per_in_ler_id
12683                ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
12684                ,p_dpnt_cvg_strt_dt_cd      => l_enrt_table(l_cnt).dpnt_cvg_strt_dt_cd
12685                ,p_dpnt_cvg_strt_dt_rl      => l_enrt_table(l_cnt).dpnt_cvg_strt_dt_rl
12686                ,p_enrt_cvg_strt_dt         => null -- 9999 this should be fetched from base table
12687                );
12688         --
12689         -- Reinstate the enrollment certifications.
12690         --
12691        -- Reinstate the enrollment certifications.
12692         --
12693         reinstate_pcs_per_pen(
12694                p_person_id                 => p_person_id
12695                ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
12696                ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).prtt_enrt_rslt_id
12697                ,p_rslt_object_version_number => l_enrt_table(l_cnt).prtt_enrt_rslt_id
12698                ,p_business_group_id        => p_business_group_id
12699                ,p_prtt_enrt_actn_id        => null
12700                ,p_effective_date           => l_enrt_table(l_cnt).effective_start_date
12701                ,p_bckdt_prtt_enrt_actn_id  => null
12702                ,p_per_in_ler_id          => p_per_in_ler_id
12703                ,p_bckdt_per_in_ler_id    => p_bckdt_per_in_ler_id
12704                );
12705        --
12706        -- Reinstate the action items.
12707        --
12708        reinstate_pea_per_pen(
12709                  p_person_id                => p_person_id
12710                 ,p_bckdt_prtt_enrt_rslt_id  => l_enrt_table(l_cnt).bckdt_prtt_enrt_rslt_id
12711                 ,p_prtt_enrt_rslt_id        => l_enrt_table(l_cnt).pen_ovn_number
12712                 ,p_rslt_object_version_number => l_enrt_table(l_cnt).prtt_enrt_rslt_id
12713                 ,p_business_group_id        => p_business_group_id
12714                 ,p_per_in_ler_id            => p_per_in_ler_id
12715                 ,p_effective_date           => l_enrt_table(l_cnt).effective_start_date
12716                 ,p_bckdt_per_in_ler_id      => p_bckdt_per_in_ler_id
12717                 );
12718      end loop;
12719   end if;
12720  -- If any of the backed out enrt rslts were overriden, then update the new
12721   -- rslts with the overriden data.
12722   --
12723   if nvl(l_enrt_table.last, 0) > 0 then
12724     --
12725     for i in 1..l_enrt_table.last loop
12726       --
12727       if l_enrt_table(i).bckdt_enrt_ovridn_flag = 'Y' then
12728         --
12729         hr_utility.set_location('Restoring the overriden result: ' ||
12730                                 l_enrt_table(i).bckdt_prtt_enrt_rslt_id, 72);
12731         --
12732         -- Get the latest object version number as the post enrollment process
12733         -- may have updated the new enrt result.
12734         --
12735         open c_ovn(l_enrt_table(i).prtt_enrt_rslt_id);
12736         fetch c_ovn into l_ovn;
12737         close c_ovn;
12738         --
12739         ben_prtt_enrt_result_api.update_prtt_enrt_result
12740           (p_prtt_enrt_rslt_id      => l_enrt_table(i).prtt_enrt_rslt_id
12741           ,p_effective_start_date   => l_esd_out
12742           ,p_effective_end_date     => l_eed_out
12743           ,p_enrt_cvg_strt_dt       => l_enrt_table(i).bckdt_enrt_cvg_strt_dt
12744           ,p_enrt_cvg_thru_dt       => l_enrt_table(i).bckdt_enrt_cvg_thru_dt
12745           ,p_enrt_ovridn_flag       => 'Y'
12746           ,p_object_version_number  => l_ovn
12747           ,p_effective_date         => l_enrt_table(i).g_sys_date
12748           ,p_datetrack_mode         => hr_api.g_correction
12749           ,p_multi_row_validate     => FALSE);
12750         --
12751       end if;
12752       --
12753     -- Bug 2677804 changed the cursor
12754       -- We need to see the overriden thru date also.
12755       for l_rt_rec in c_ovridn_rt(l_enrt_table(i).bckdt_prtt_enrt_rslt_id
12756                                  ,l_enrt_table(i).prtt_enrt_rslt_id )
12757       loop
12758         --
12759         hr_utility.set_location('Updating new prv: ' || l_rt_rec.new_prv_id ||
12760                                 ' with overriden prv_id: ' ||
12761                                 l_rt_rec.prtt_rt_val_id, 72);
12762         --
12763         ben_prtt_rt_val_api.update_prtt_rt_val
12764           (p_prtt_rt_val_id        => l_rt_rec.new_prv_id
12765           ,p_person_id             => p_person_id
12766           ,p_rt_strt_dt            => l_rt_rec.rt_strt_dt
12767           ,p_rt_val                => l_rt_rec.rt_val
12768           ,p_acty_ref_perd_cd      => l_rt_rec.acty_ref_perd_cd
12769           ,p_cmcd_rt_val           => l_rt_rec.cmcd_rt_val
12770           ,p_cmcd_ref_perd_cd      => l_rt_rec.cmcd_ref_perd_cd
12771           ,p_ann_rt_val            => l_rt_rec.ann_rt_val
12772           ,p_rt_ovridn_flag        => l_rt_rec.rt_ovridn_flag
12773           ,p_rt_ovridn_thru_dt     => l_rt_rec.rt_ovridn_thru_dt
12774           ,p_business_group_id     => p_business_group_id
12775           ,p_object_version_number => l_rt_rec.new_prv_ovn
12776           ,p_effective_date        => l_enrt_table(i).g_sys_date);
12777         --
12778       end loop;
12779     -- Check if there are any dependents that are overriden and update the new
12780       -- elig_cvrd_dpnt records with the overriden values.
12781       --
12782       for l_dpnt_rec in c_ovridn_dpnt(l_enrt_table(i).bckdt_prtt_enrt_rslt_id
12783                                      ,l_enrt_table(i).prtt_enrt_rslt_id
12784                                      ,l_enrt_table(i).g_sys_date)
12785       loop
12786         --
12787         hr_utility.set_location('Updating new ecd with overriden ecd_id: ' ||
12788                                 l_dpnt_rec.elig_cvrd_dpnt_id, 72);
12789         --
12790         ben_elig_cvrd_dpnt_api.update_elig_cvrd_dpnt
12791           (p_elig_cvrd_dpnt_id     => l_dpnt_rec.new_pdp_id
12792           ,p_effective_start_date  => l_esd_out
12793           ,p_effective_end_date    => l_eed_out
12794           ,p_cvg_strt_dt           => l_dpnt_rec.cvg_strt_dt
12795           ,p_cvg_thru_dt           => l_dpnt_rec.cvg_thru_dt
12796           ,p_ovrdn_flag            => l_dpnt_rec.ovrdn_flag
12797           ,p_ovrdn_thru_dt         => l_dpnt_rec.ovrdn_thru_dt
12798           ,p_object_version_number => l_dpnt_rec.new_pdp_ovn
12799           ,p_datetrack_mode        => hr_api.g_correction
12800           ,p_effective_date        => l_enrt_table(i).g_sys_date);
12801         --
12802       end loop;
12803       --
12804     end loop;
12805     --
12806   end if;
12807   --
12808   -- Call the Close enrollement process if the
12809   -- backed out pil's status is PROCD.
12810   -- backed out pil's status is PROCD.
12811   --
12812   --if l_cls_enrt_flag then
12813    /*Bug 8807327: Added 'if' condition. While backing out the LE,if previous LE does not have
12814    electability and no enrollments results then previous LE status will not be updated to 'STRTD' status.
12815    So there is no need to force close the previous LE*/
12816       if ( ben_back_out_life_event.g_no_reopen_flag = 'N') then
12817         ben_close_enrollment.close_single_enrollment
12818                       (p_per_in_ler_id      => p_per_in_ler_id
12819                       ,p_effective_date     => nvl(l_max_enrt_esd,p_effective_date)
12820                       ,p_business_group_id  => p_business_group_id
12821                       ,p_close_cd           => 'FORCE'
12822                       ,p_validate           => FALSE
12823                       ,p_close_uneai_flag     => NULL
12824                       ,p_uneai_effective_date => NULL);
12825      end if;
12826      --
12827   --end if;
12828   --
12829   hr_utility.set_location ('Leaving '||l_proc,10);
12830   --
12831   --
12832 end reinstate_the_prev_enrt_rslt;
12833 --
12834 
12835 
12836 /*Enhancement Bug No: 8716679:  Added Function
12837 to check whether the enrollment that is being reinstated is already
12838 defaulted or carry forwarded. If function returns 'Y', then the enrollment
12839 will not reinstated*/
12840 function check_pl_typ_defaulted(p_pl_typ_id in number,
12841                                p_pgm_id in number
12842 			       ) return varchar2 is
12843 
12844  l_proc  varchar2(72) := g_package||'.check_pl_typ_defaulted';
12845 l_flag varchar2(1) := 'N';
12846 cursor c_epe_det(c_elig_per_elctbl_chc_id number) is
12847 select pgm_id,pl_typ_id from
12848 	ben_elig_per_elctbl_chc
12849 	where elig_per_elctbl_chc_id = c_elig_per_elctbl_chc_id;
12850 l_epe_rec c_epe_det%rowtype;
12851 begin
12852     hr_utility.set_location ('Entering '||l_proc,10);
12853     hr_utility.set_location ('p_pl_typ_id '||p_pl_typ_id,10);
12854     hr_utility.set_location ('p_pgm_id '||p_pgm_id,10);
12855     for l_cnt in 1..g_reinstated_defaults.LAST loop
12856 	    open c_epe_det(g_reinstated_defaults(l_cnt));
12857 	    fetch c_epe_det into l_epe_rec;
12858 	    close c_epe_det;
12859 
12860 	    if( nvl(l_epe_rec.pgm_id,-1) = nvl(p_pgm_id,-1) and l_epe_rec.pl_typ_id = p_pl_typ_id) then
12861 	     l_flag := 'Y' ;
12862 	     hr_utility.set_location ('Leaving '||l_proc,11);
12863 	     return l_flag;
12864 	     exit;
12865 	    end if;
12866    end loop;
12867    hr_utility.set_location ('Leaving '||l_proc,12);
12868    return l_flag;
12869 end check_pl_typ_defaulted;
12870 
12871 /*Enhancement Bug No: 8716679:  Added Function to
12872 determine whether to call defaults of not.
12873 Reprocess the backedout LE. Now backout the LE to Unprocessed state,
12874 backout the intervening LE and now reprocess the backed LE. In this case
12875 defaults should be applied. Reinstating the enrollments doesn't make
12876 sense as it was an election that was reversed/backed out.
12877 */
12878 function call_defaults(p_per_in_ler_id in number,
12879                        p_bckdt_per_in_ler_id in number,
12880 		       p_effective_date date,
12881 		       p_person_id number
12882 			       ) return varchar2 is
12883 
12884 l_proc  varchar2(72) := g_package||'call_defaults';
12885 l_flag varchar2(1) := 'N';
12886 l_intv_pil_id number;
12887 
12888  cursor c_int_pil_id is
12889   select pil1.bckt_per_in_ler_id
12890          from ben_per_in_ler pil,ben_per_in_ler pil1
12891          where pil.per_in_ler_id = p_bckdt_per_in_ler_id
12892                and pil.ptnl_ler_for_per_id = pil1.ptnl_ler_for_per_id
12893                and pil1.bckt_per_in_ler_id is not null
12894 	       order by pil.lf_evt_ocrd_dt asc;
12895 
12896 cursor c_bckdt_pil_id is
12897 select pil.bckt_per_in_ler_id
12898          from ben_per_in_ler pil
12899          where pil.per_in_ler_id = p_bckdt_per_in_ler_id;
12900 
12901 l_bckdt_pil_id number;
12902 
12903 cursor c_future_pil is
12904        select pil.per_in_ler_id
12905     from   ben_per_in_ler pil,
12906            ben_ler_f ler
12907     where  pil.per_in_ler_id not in (p_per_in_ler_id,p_bckdt_per_in_ler_id)
12908     and    pil.person_id     = p_person_id
12909     and    pil.ler_id        = ler.ler_id
12910     and    p_effective_date between
12911            ler.effective_start_date and ler.effective_end_date
12912     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
12913     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
12914     and    pil.lf_evt_ocrd_dt in (select lf_evt_ocrd_dt
12915 				 from ben_per_in_ler pil2,
12916 				      ben_ler_f ler1
12917 				 where pil2.per_in_ler_stat_cd not in ('BCKDT', 'VOIDD')
12918 				    and pil2.person_id = p_person_id
12919 				    and    pil2.ler_id        = ler1.ler_id
12920 				    and    p_effective_date between
12921 					   ler1.effective_start_date and ler1.effective_end_date
12922 				    and    ler1.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
12923 				    and pil2.lf_evt_ocrd_dt > (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
12924 							      per_in_ler_id = l_intv_pil_id)
12925 				    and pil2.lf_evt_ocrd_dt < (select lf_evt_ocrd_dt from ben_per_in_ler pil3 where
12926 							      per_in_ler_id = p_bckdt_per_in_ler_id)
12927                                 )
12928    order by pil.lf_evt_ocrd_dt desc;
12929 
12930   cursor c_chk_intevent_bckdt(c_pil_id number) is
12931   select 'Y'
12932         from ben_per_in_ler pil
12933 	where pil.per_in_ler_id = c_pil_id
12934 	      and pil.per_in_ler_stat_cd in('BCKDT', 'VOIDD');
12935 
12936 
12937 l_bckdt_flag varchar2(1) default 'N';
12938 l_lt_prev_pil number;
12939 l_dummy varchar2(1);
12940 
12941 begin
12942 hr_utility.set_location ('Entering '||l_proc,10);
12943 
12944 open c_int_pil_id;
12945 fetch c_int_pil_id into l_intv_pil_id;
12946 close c_int_pil_id;
12947 hr_utility.set_location ('l_intv_pil_id '||l_intv_pil_id,10);
12948 
12949 open c_bckdt_pil_id;
12950 fetch c_bckdt_pil_id into l_bckdt_pil_id;
12951 close c_bckdt_pil_id;
12952 
12953 if(l_bckdt_pil_id is not null) then
12954   hr_utility.set_location ('Backedout and reporcessing ',10);
12955   return 'N';
12956 end if;
12957 
12958 if(l_intv_pil_id is null) then
12959    hr_utility.set_location ('leaving4 '||l_proc,10);
12960   return 'N';
12961  else
12962    open c_future_pil;
12963    fetch c_future_pil into l_lt_prev_pil;
12964    hr_utility.set_location ('l_lt_prev_pil '||l_lt_prev_pil,10);
12965    if(c_future_pil%notfound) then
12966       close c_future_pil;
12967       open c_chk_intevent_bckdt(l_intv_pil_id);
12968       fetch c_chk_intevent_bckdt into l_dummy;
12969       if(c_chk_intevent_bckdt%notfound) then
12970         close c_chk_intevent_bckdt;
12971         l_flag := 'N';
12972       else
12973         close c_chk_intevent_bckdt;
12974 	hr_utility.set_location ('leaving2 '||l_proc,10);
12975         l_flag := 'Y';
12976       end if;
12977     else
12978       close c_future_pil;
12979       hr_utility.set_location ('leaving3 '||l_proc,10);
12980       l_flag := 'N';
12981    end if;
12982  end if;
12983 hr_utility.set_location ('leaving '||l_proc,10);
12984 return l_flag;
12985 end call_defaults;
12986 
12987 end ben_lf_evt_clps_restore;