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