DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_ENROLMENT_REQUIREMENTS

Source


1 PACKAGE BODY ben_enrolment_requirements AS
2 /* $Header: bendenrr.pkb 120.24 2007/12/20 15:32:41 sagnanas ship $ */
3 -------------------------------------------------------------------------------
4 /*
5 +=============================================================================+
6 |                       Copyright (c) 1998 Oracle Corporation                 |
7 |                          Redwood Shores, California, USA                    |
8 |                               All rights reserved.                          |
9 +=============================================================================+
10 --
11 Name
12   Determine Enrolment Requirements
13 Purpose
14   This package is used to create enrolment choice entries for all choices
15   which a person may elect.
16 History
17      Date       Who          Version   What?
18      ----       ---          -------   -----
19      18 Mar 98  jcarpent     110.0     Created
20      05 Jun 98  jcarpent     110.1     Compensated for null pl_id
21      06 Jun 98  jcarpent     110.2     Changed order of heirarchy for date cd
22                                        Save pl_typ_cd in epe.
23      08 Jun 98  jcarpent     110.3     Changed default_flag processing
24                                        added new dflt_enrt_cd code hanlers
25      09 Jun 98  thayden      110.4     Added batch who columns.
26      10 Jun 98  jcarpent     110.5     Changed rule execution routines
27      11 Jun 98  jcarpent     110.6     Fixed wrong error messag for rt_strt_dt
28      17 Jun 98  jcarpent     110.7     Some business_group_id checks added
29      29 Jun 98  jcarpent     110.8     Check invk_imptd/flxcr flag
30                                        nvl on dys_aftr_end_to_dflt
31                                        nvl on addit_procg_dys_num
32                                        Changed tco_chg_enrt to check enrt
33      01 Jul 98  jcarpent     110.9     Added return to determine
34                                        erlst_deenrt_dt
35      01 Jul 98  jcarpent     110.10    Changed enrt_cd handling for unenrolled
36      08 Jul 98  jcarpent     110.11    Fixed pgm level sched enrt perd
37                                        added p_popl_enrt_typ_cycl_id arg
38      21 Jul 98  jcarpent     110.12    Added/changed some messages
39      18 Aug 98  jcarpent     110.13    Put in substr on write calls
40      27 Aug 98  G Perry      115.12    Formatted and used values from benmngle
41                                        global structures
42      27 Aug 98  jcarpent     115.14    Create plan choice if elig and oipl
43                                        created. If plan has oipls then
44                                        create no choice.
45      28 Aug 98  G Perry      115.15    Added use of global
46                                        g_electable_choice_created to test when
47                                        an electable choice has been created.
48      22 Sep 98  jcarpent     115.16    added 'STRTD' restriction
49      25 Sep 98  jcarpent     115.17    added ler_chg_ptip.
50                                        look at ler_chc* for open enrt
51                                        enrt_perd+lee_rsn passed to epe api
52                                        handle plans in multiple programs
53                                        removed rt_strt_dt form epe api call
54      15 Oct 98  G Perry      115.21    Added in auto enrt stuff, corrected a
55                                        few cursor bugs.
56      15 Oct 98  G Perry      115.22    Defaulted mndtry_flag.
57      16 Oct 98  jcarpent     115.23    Fixed auto_enrt_flag or oipls
58      19 Oct 98  jcarpent     115.24    Use plip enrt info. Use pl.enrt_rl.
59                                        Provide acty_ref_perd_cd/uom.
60      20 Oct 98  jcarpent     115.25    default oipl_auto_flag to 'N'
61      21 Oct 98  jcarpent     115.26    Added l_rec_auto_enrt_flag
62                                        Support for unrestricted enrt.
63                                        Removed all rt_strt_dt logic.
64                                        use enrt_perd_for_pl_f for csd calc.
65      28 Oct 98  jcarpent     115.27    Set l_rec_cls_enrt_dt_to_use_cd
66                                        Check pgm_id on all ben_elig_per_f sql
67      28 Oct 98  G Perry      115.28    Fixed all ben_elig_per_f references in
68                                        cursors as they were all ropey.
69      30 Oct 98  G Perry      115.30    Fixed how parameter
70                                        popl_enrt_typ_cycl_id works to support
71                                        multiple scheduled enrollment.
72      12 Dec 98  jcarpent     115.31    Create epe when dependent change
73                                        allowed.  Changed all pen cursors to
74                                        check csd+ced
75      15 Dec 98  G Perry      115.32    Added in call to electbl choice
76                                        reporting stuff for the audit log.
77      18 Dec 98  jcarpent     115.33    Changed ler_chg_enrt heirarchy.
78      20 Dec 98  G Perry      115.34    Plan electablce cache entry no longer
79                                        contains option details.
80      23 Dec 98  jcarpent     115.35    Handle overridden results.
81                                        Fixed c_oipl_enrolment_info cursor
82                                        to check cvg dates.
83                                        Changed default enrt cd processing
84      04 Jan 99  jcarpent     115.36    Return value for all functions.
85      14 Jan 99  jcarpent     115.37    Use current enrt_cvg_strt_dt if !null
86      18 Jan 99  G Perry      115.38    LED V ED
87      27 Jan 99  jcarpent     115.39    Changed erlst_deenrt_dt logic.
88      03 Feb 99  jcarpent     115.40    Support for Level jumping restrictions
89                                        Get erlst_deenrt_dt from opt,pl,oipl too
90      25 Mar 99  jcarpent     115.42    Added assignment_id to rule contexts
91      01 Apr 99  jcarpent     115.43    Remove exit point when currently enrd,
92                                        no dpnt chg allowed, not electable.
93      09 Apr 99  stee         115.44    Change ben_per_in_ler_f to
94                                        ben_per_in_ler.
95      28 Apr 99  shdas	     115.45    Added more contexts in rule calls.
96      28 Apr 99  jcarpent     115.46    When no lee_rsn exists exist don't error
97                                        exit without creating choice.
98      28 Apr 99  jcarpent     115.47    Init perd_for_pgm_found to 'N'
99      29 Apr 99  lmcdonal     115.48    prtt_enrt_rslt now has a status code.
100      04 May 99  shdas	     115.49    Added jurisdiction code.
101      06 May 99  jcarpent     115.50    Fork off version 115.39 to do below chg
102      06 May 99  jcarpent     115.51    Call new hashing procedure
103      07 May 99  jcarpent     115.52    Pass greater(elig_strt_dt,lf_evt_oc_dt)
104                                        into start date routines.
105      11 May 99  jcarpent     115.53    Made all lf_evt_ocrd_dt change.
106      20 May 99  jcarpent     115.54    Backed out nocopy lf_evt chg for enrollment.
107                                        because eff dates based on eff dt.
108      21 May 99  jcarpent     115.55    Error if cls_enrt_dt_to_use_cd is null
109                                        fix assignment messages.
110      24 May 99  jcarpent     115.56    Make sure comp objects exist as of
111                                        enrt_perd_strt_dt.  Pgm,pl_typ,pl,opt,
112                                        oipl,plip,ptip,lee_rsn,ler.
113      24 Jun 99  maagrawa     115.57    invk_imptd_incm_pl_flag changed to
114                                        imptd_incm_calc_cd.
115      24 Jun 99  maagrawa     115.57    invk_imptd_incm_pl_flag changed to
116                                        imptd_incm_calc_cd.
117      05 Jul 99  stee         115.58    COBRA changes.  Check for coverage
118                                        in a plan when evaluating enrollment
119                                        code.  Also evaluate the
120                                        cvg_incr_r_decr_only_code at the plip
121                                        level.
122      12 Jul 99  jcarpent     115.59    Added checks for backed out nocopy pil.
123      12 Jul 99  moyes        115.60  - Added trace messages.
124                                      - Removed + 0s from all cursors.
125      20-JUL-99  Gperry       115.61    genutils -> benutils package rename.
126      21-JUL-99  mhoyes       115.62  - Added trace messages.
127      30-JUL-99  mhoyes       115.63  - Added trace messages.
128      02-Aug-99  tguy         115.64    Added spouse and dependent for imputed
129                                        incomes.
130      04-Aug-99  jcarpent     115.65  - Fixed level jumping signs
131      10-Aug-99  tmathers     115.66  - Fixed formula returning date
132                                        code.
133      23-Aug-99  shdas        115.67  - Added codes for pl_ordr_num,plip_ordr_num,
134                                        ptip_ordr_num,oipl_ordr_num.
135      31-Aug-99  jcarpent     115.68  - Update to look at ptip enrollment cols.
136                                        Use new ler_chg_pgm_enrt_f table.
137                                        Added dflt_enrt_cd/rl hierarchy.
138      07-Sep-99  tguy         115.69    fixed call to pay_mag_util
139      09-Sep-99  jcarpent     115.70  - Turn off auto flag for plan choices
140                                        created due to auto oipl.
141      09-Sep-99  stee         115.71  - Add new cvg_incr_r_decr_only codes
142                                        MNAVLO and MXAVLO.
143      21-Sep-99  jcarpent     115.72  - Added dflt_enrt_cds nncsedr, ndcsedr
144      22-Sep-99  jcarpent     115.73  - Changed calls to auto_enrt_(mthd)_rl
145                                        Combined calls for ler_chg and non-ler
146                                        chg to call determine_enrolment once.
147      23-Sep-99  jcarpent     115.74  - Renamed l_enrt_rl to l_ler_enrt_rl.
148      24-Sep-99  jcarpent     115.75  - Changed auto_enrt_cd/flag processing.
149                                        Consolidated *electable_flag variables
150                                        and parameters to be more consistent.
151      25-Sep-99  stee         115.76  - Added pgm_typ_cd to elctbl_chc_api.
152      01-Oct-99  tguy         115.77  - Fixed level jumping issues
153      01-Oct-99  jcarpent     115.78  - Added oipl.enrt_cd/rl
154      03-Oct-99  tguy         115.79  - New fixes to level jumping.
155      06-Oct-99  tguy         115.80  - added new checks for level jumping.
156      14-Oct-99  jcarpent     115.81  - Allow enrt_cd to control elctbl_flag
157                                        for automatic enrollments.
158      19-Oct-99  pbodla       115.82  - At Level : Period for program found
159                                        in call to ben_determine_date.main
160                                        l_pgme_enrt_perd_end_dt_rl is modified
161                                        to l_pgme_enrt_perd_strt_dt_rl
162      26-Oct-99  maagrawa     115.83  - Level jumping fixed for persons, who
163                                        are not previously enrolled. i.e. when
164                                        enrd_ordr_num is null.
165      02-Nov-99  maagrawa     115.84  - Level jumping restrictions removed at
166                                        plip level.
167      12-Nov-99  mhoyes       115.85  - Fixed bug 3630. Invalid number problem
168                                        in cursor c_ler_chg_enrt_info.
169      16-Nov-99  jcarpent     115.86  - Changed c_ler_chg_enrt_info again
170                                        problem was with decode for dflt_enrt_rl
171                                      - Also Added determine_dflt_enrt_cd
172                                      - Also added new global
173                                      - Fixed auto enrt rule execution.
174                                        was never running auto enrt rule.
175      03-Dec-99 lmcdonal      115.87    stl_elig...flag was being passed
176                                        incorrectly to determine_enrollment.
177      08-Dec-99 jcarpent      115.88  - Change hierarchy for enrt_mthd_cd/rl.
178                                      - Fix oipl enrt_cd bug. Rl overwrote cd.
179      01-Jan-00 pbodla        115.89  - Automatic enrollment rule is executed,
180                                        even if the enrt_mthd_cd is null.
181      05-Jan-00 jcarpent      115.90  - Added procs find_rqd_perd_enrt and
182                                        find_enrt_at_same_level
183      13-Jan-00 shdas         115.91  - added code so that choices for flx and
184                                        imptd inc plans are created irrespective
185                                        of whether they are configured  to be
186                                        electable for each life event or not.
187      21-Jan-00 pbodla        115.92  - p_elig-per_id is added to
188                                        execute_enrt_rule, determine_enrolment
189                                        and passes to benutils.formula
190      05-Jan-00 maagrawa      115.93  - Get the auto enrollment flag from oipl's
191                                        ler record, if availabe (Bug 4290).
192                                      - If the choice is automatic, it cannot
193                                        be default. (Bug 1175262).
194      07-Jan-00 jcarpent      115.94  - Subtract 1 day from date when checking
195                                        prev enrollment for tco-chg logic.
196                                        (bug 1120686/4145)
197      15-Feb-00 jcarpent      115.95  - Subtract 1 day from all enrollment chks
198                                      - Added plip level jumping restrictsions
199                                        back in. (bug 1146785/4153)
200      07-Mar-00 jcarpent      115.96  - De-enroll if "Lose only". bug 1217196
201      16-Mar-00 stee          115.97  - Remove program restriction if
202                                        cvg_incr_r_decr_only_cd is specified at
203                                        the plip level.
204      23-Mar-00 jcarpent      115.98  - Fix enrt_mthd_rule use.  Removed
205                                        l_auto_enrt_rl (use l_ler_auto_enrt_rl)
206                                        Bug 1246785/4922.
207      29-Mar-00  lmcdonal   115.66    Bug 1247115 - do not subtract 1 from
208                                           life event ocrd dt when looking for
209                                           esd/eed.  Only when looking for cvg
210                                           strt/end dates.  Did this to all
211                                           cursors that had the -1 except those
212                                           looking at elig_per tables.
213      06-Apr-00  mmogel       115.100 - Added tokens to message calls to make
214                                        the messages more meaningful to the user
215      11-Apr-00  maagrawa     115.101 - Start the enrollment period on the
216                                        effective date if there is an conflicting
217                                        life event between the enrollment period
218                                        start date and the effective date.
219                                        Bug 4988.
220      18-Apr-00  maagrawa     115.102   Backport to 115.100
221      18-Apr-00  lmcdonal     115.103   Fido Bug 6176:  When looking for current
222                                        enrollments, no longer look for
223                                        nvl(lf_evt_orcd_dt, eff dt) between esd and eed
224                                        instead look for eed = eot.
225      20-Apr-00  mhoyes       115.104 - Added profiling messages.
226      03-May-00  pbodla       115.105 - Task 131 : execute_enrt_rule modified
227                                      - If elig dependent rows are already created
228                                        then pass the elig dependent id as input
229                                        values to rule.
230      12-May-00  mhoyes       115.106 - Added profiling messages.
231      13-May-00  jcarpent     115.107 - Modified enrt_perd_strt_dt logic for
232                                        reinstated le's (4988,1269016)
233      15-May-00  mhoyes       115.108 - Called create EPE performance cover.
234      16-May-00  mhoyes       115.109 - Added profiling messages.
235      18-May-00  jcarpent     115.110 - Modified c_get_latest_procd_dt to
236                                        ignore backed out nocopy pils (4988,1269016)
237      23-May-00  mhoyes       115.113 - General tuning of SQL by dharris.
238                                      - Added p_comp_obj_tree_row to
239                                        enrolment_requirements.
240      24-May-00  mhoyes       115.114 - Added/removed trace messages.
241                                      - Enabled cache mode for rates_and_coverage
242                                        dates. This caches the per in ler.
243      25-May-00  jcarpent     115.115 - Added logic to have crnt_enrt_prclds_chg
244                                        work for entire ptip. (5216,1308627)
245      29-May-00  mhoyes       115.116 - Commented out nocopy hr_utility calls for
246                                        performance in highly executed logic.
247                                      - Tuning by dharris.
248      31-May-00  mhoyes       115.117 - Passed through current comp object
249                                        row parameters to avoid cache calls.
250                                      - Passed comp object rows to
251                                        rate_and_coverage_dates to avoid cursor
252                                        executions.
253      09-Jun-00  pbodla       115.118 - Bug 5272 : A fix to cursors
254                                        c_sched_enrol_period_for_plan,
255                                        c_sched_enrol_period_for_pgm in version
256                                        115.113 caused this bug. These cursors
257                                        are fixed.
258      23-Jun-00  pbodla       115.119 - Fix to check enrollment results as
259                                        of the life event occurred date instead
260                                        of life event occurred -1 when
261                                        determining the default flag. Bug 5241.
262      28-Jun-00  shdas        115.120 - Added procedure execute_auto_dflt_enrt_rule.
263      28-Jun-00  jcarpent     115.121 - Bug 4936: Use new cvg_strt_dt if sched
264                                        enrt and plan is for 125 or 129
265                                        regulation.
266      29-Jun-00  mhoyes       115.122 - Reworked cursors c_nenrt and c_pl_bnft_rstrn
267                                        as PLSQL.
268      30-Jun-00  mhoyes       115.123 - Fired cursor c_nenrt when context parameters
269                                        are not set.
270      05-Jul-00  mhoyes       115.124 - Added context parameters.
271      13-Jul-00  mhoyes       115.125 - Removed context parameters.
272      19-Jul-00  jcarpent     115.126 - 5241,1343362. Added update_defaults
273      03-Aug-00  jcarpent     115.127 - 5429. Fixed reinstate dependent logic.
274      04-Aug-00  pbodla       115.128 - 4871(1255493) : After mndtry_rl executed
275                                        it's out nocopy put is not used.
276      31-Aug-00  jcarpent     115.129 - Comp object changes were causing
277                                        non-date effective error.  Added
278                                        requery logic.  WWbug 1394507.
279      05-sep-00  pbodla       115.130 - Bug 5422 : Allow different enrollment periods
280                                        for programs for a scheduled  enrollment.
281                                        p_popl_enrt_typ_cycl_id is removed.
282      14-Sep-00  jcarpent     115.131 - Leapfrog version based on 115.129.
283                                        Bug 1401098.  Added logic to update_
284                                        defaults to change elctbl_flag also.
285                                        Needed for rules which use enrol/elig
286                                        in other plans for electablility.
287      14-Sep-00  jcarpent     115.132 - Merged version of 115.131 with 130.
288      25-Sep-00  mhoyes       115.133 - Removed hr_utility.set_locations.
289      07-Nov-00  mhoyes       115.134 - Added hr_utility.set_locations for
290                                        profiling.
291                                      - Modified update_defaults to use the
292                                        electable choice performance API.
293     15-dec-00   tilak        115.135   bug: 1527086 early denenrollment date carried forward
294                                        for future enrolment ,oipl_id condtion addded in cursor wich
295                                        take the information ofexisting enrolment for OPT level
296     04-jan-01   jcarpent     115.136 - Bug 1568555.  Removed +1 from enrt
297                                        period logic.
298     01-feb-01   kmahendr     115.137 - Bug 1621593 - If plan is savings and has options attached
299                                        then previous enrollment is checked and prtt_enrt_rslt_id
300                                        is assigned
301     08-feb-01   tilak        115.138   find_enrt_at_same_level changed to return the correct row
302                                        bug : 1620161
303     26-feb-01   kmahendr     115.139 - unrestricted process changes - if future enrollments exists
304                                        then treat it as not currently enrolled
305     27-feb-01   thayden     115.140  - change unrestricted enrolment period end date to end of time.
306     08-jun-01   kmahendr    115.141  - Bug#1811636 - For level jumping logical order number is used
307                                        in place of database ordr_num
308     08-jun-01   kmahendr    115.142  - Effective date condition added to cursor c_opt_level
309     26-jul-01   ikasire     115.143    bug1895874 added new nip_dflt_flag to ben_pl_f table.
310                                        In the internal procedure determine_dflt_enrt_cd
311                                        added to parameters p_pgm_rec,p_ptip_rec,p_plip_rec,
312                                        p_oipl_rec,p_pl_rec to get the data from the already
313                                        cached records. Also removed the calls to ben_cobj_cache
314                                        from internal determine_dflt_enrt_cd procedure as this
315                                        can not be used here.
316     27-aug-01  tilak        115.144   bug:1949361 jurisdiction code is
317                                       derived inside benutils.formula.
318     13-Nov-01  kmahendr     115.145   bug#2080856 - in determine_dflt_flag procedure, coverage is
319                                       checked at ptip level if plan level fails.
320     15-Nov-01  kmahendr     115.146   Bug#2080856 - if dflt_enrt_cd is null then default flag
321                                       is set to 'N' - changed the assignment in determine_dflt_flag
322     07-Dec-01  mhoyes       115.146  - Added p_per_in_ler_id to enrolment_requirements.
323     11-Dec-01  mhoyes       115.147  - Added p_per_in_ler_id to update_defaults.
324     18-Dec-01  kmahendr     115.148  - Comp. work bench changes
325     19-Dec-01  kmahendr     115.149  - put the end if before elig_flag for p_run_mode = 'W'
326     29-Dec-01  pbodla       115.152  - CWB Changes : Initialised package
327                                        globals g_ple_hrchy_to_use_cd,
328                                        g_ple_pos_structure_version_id
329                                        to use later in benmngle.
330     29-Dec-01  pbodla       115.153  - CWB Changes : hierarchy to use code
331                                        lookup codes changed to match ones in
332                                        seed115, extended C mode to W.
333     03-Jan-02  rpillay      115.154  - Applied nvl function to all flag-type parameters
334                                        passed in the call to create_perf_elig_per_elc_chc
335                                        from enrolment_requirements Bug# 2141756
336     04-jan-02  pbodla       115.155  - CWB Changes : hierarchy table is
337                                        populated after epe row is created.
338     11-Jan-02  ikasire      115.156    CWB Changes Bug 2172036 addition of new column
339                                        assignment_id to epe table
340     29-Jan-02  kmahendr     115.157    Bug#2108168 - Added a cursor c_ptip_waive_enrolment_info
341                                        in the procedure - determine_enrollment to check for
342                                        current enrollment in a waive plan
343     12-feb-02  pbodla       115.158  - CWB Changes : 2213828 - No need to
344                                        determine the enrt_perd_strt_dt,
345                                        enrt_perd_end_dt if the mode is W.
346     12-feb-02  pbodla       115.159  - CWB Changes : 2230922 : If ws manager id
347                                        not found then default to supervisor if
348                                        position heirarchy is used.
349     27-Feb-02  rpillay      115.160  - CWB Bug 2241010 Made changes to set elctbl_flag
350                                        and elig_flag to 'N' when person is ineligible
351     01-Apr-02  ikasire      115.161    Bug 229032 if the enrollment starts in a future
352                                        date, for unrestricted, user cannot get the enrollment
353                                        record for correction causing problems.
354     17-Apr-02  kmahendr     115.162    Bug#2328029 - previous eligibility must be arrived based
355                                        on life event occurred date or effective date-changed
356                                        l_effective_date_1 in enrollment_requirements and update
357                                        default procedures.
358     02-May-02  hnarayan     115.163    bug 2008871 - commented the return and included it
359                                        inside the requery cursor if block
360     				       since it affects positive cases of electability
361     14-May-02  ikasire      115.164    Bug 2374403 electable choices for the imputed
362                                        income type of spouse is not getting created
363                                        properly. IMPTD_INCM_CALC_CD of SPSL is used
364                                        instead of using SPS
365     19-May-02  ikasire      115.165    Bug 2200139 Override Enrollment changes
366     08-Jun-02  pabodla      115.164    Do not select the contingent worker
367                                        assignment when assignment data is
368                                        fetched.
369     20-Jun-02  ikasire      115.167    Bug 2404008 fixed by passing lf_evt_ocrd_dt rather
370                                        than p_effective_date to determine_dflt_enrt_cd call
371     14-Jul-02  pbodla       115.168    ABSENCES - Added absences mode M.
372                                        This mode is similar to mode L.
373     05-Aug-02  mmudigon     115.169    ABSENCES - do not look at backed out nocopy and
374                                        processed lers for determining enrollment
375                                        period
376    08-Aug-02  tjesumic      115.170    # 2500805 certain situation,where  2 option in same plan
377                                        became defaulted if the coverage start date is not controlled
378                                        Pls See the bug for the test case.
379                                        cursors c_plan_enrolment_info,c_oipl_enrolment_info in
380                                        procedure determine_dflt_flag validatd for cvg_strt_dt
381    21-Aug-02  pbodla        115.171    Bug 2503570 - CWB electable flag always set Y
382    29-Aug-02  kmahendr      115.172    Bug#2207956 - new enrollment code added and references
383                                        to sec129 or 125 is removed.
384    13-Sep-02  tjesumic      115.173    # 2534744  to fix the issue of defaulting past enrolled
385                                        elected value  new retutn values introduced in formula
386                                        AUTO_DFLT_ELCN_VAL in  execute_auto_dflt_enrt_rule
387                                        formula type auto enrollment
388                                        Which return elected value which is used by bencvrge to
389                                        populated the default benefit
390    28-Sep-02 pbodla         115.174    Bug 2600087 added order by clause to
391                                        c_oipl_enrolment_info and c_plan_enrolment_info
392    20-Oct-02  mhoyes        115.175  - Phased in call to ben_pep_cache.get_currpepepo_dets.
393                                      - Phased out nocopy previous eligibility cursors and
394                                        pointed to the previous eligibility cache.
395    01-Nov-02  mmudigon      115.176  - CWB: Bug 2526595 Bypass creation of epe
396                                        if trk_inelig is set to No and the person
397                                        is not eligible
398    01-Nov-02  tjesumic      115.177  - # 2542162 enrt_perd_strt_dt send  as param to the rule which
399                                        Calculate the enrt_perd_end_dt
400    01-Dec-02  pabodla       115.178  - Arcsing the file with CWB itemization code as commented.
401    04-Dec-02  rpillay       115.179  - CWB: Bug 2684227 - If a position is vacant climb the
402                                        position hierarchy till a person is found
403    09-Dec-02  mmudigon      115.180  - CWB itemization code uncommented.
404    16 Dec 02  hnarayan      115.181    Added NOCOPY hint
405    27 Dec 02  ikasire       115.182    Bug 2677804 changes.for Override thru date
406    03 Jan 03  tjesumic      115.183    bug # 2685018 if the formula return the result  id then
407                                        the result id will be catcated wiht dpnt carry forawrd  to store
408    07 Dec 03  tjesumic      115.184    New return value added in default enrollment formula 'PREV_PRTT_ENRT_RSLT_ID'
409                                        This value  added to the value of CARRY_FORWARD_ELIG_DPNT for storage
410    10 jan 03  pbodla        115.18?    GRADE/STEP : Added code to support
411                                        grade step progression process.
412    24-Feb-03  mmudigon      115.185  - CWB itemization : implement trk_inelig
413                                        flag at oipl level
414    12-Mar-03  ikasire       115.186    Bug 2827121 Contingent worker issue for
415                                        cwb
416    17-Mar-03  vsethi        115.187  - Bug 2650247 -passing the value for inelg_rsn_cd in call to
417   				       elig per elctbl chc api
418    10-Apr-03  rpgupta       115.188  - Bug 2746865
419    				       Enrollment period window enhancement
420    				       Changed the logic for arriving at the enrollment period start
421    				       and end dates
422    20-Jun-03  kmahendr      115.189  - Bug#2980560 - date passed to get_pilepo was changed to
423                                        l_effective_date_1
424    14-Jul-03  ikasire       115.190  - Bug 3044311 to get valid manager
425                                        for cwb position hierarchy.
426    11-Aug-03  ikasire       115.191    Bug 3058189 use l_lf_evt_ocrd_dt for the unrestricted cursors
427                                        while getting the pen info.
428    11-Aug-03  tjesumic      115.192    # 3086161 whne the LE reprocedd ,the Enrt Dt determined as of the
429                                        Previous LE Processed Date. if the nerollment made on the same date
430                                        the Exisiting results are updated in correction mode(same date).
431                                        Whne the cirrent LE backedout the previous LE results are lost
432                                        because the per_in_ler id updated in correction mode updated
433                                        This is fixed : if the  max enrollment date is  higer than the
434                                        max processed date then  max enrollment dt + 1 used for enrt_prd_strt_dt
435    12-Aug-03  vsethi        115.193    Bug 3063867, Changed enrt_perd_strt_dt When a prior life event has been
436    				       VOIDD, the enrollment period start date should not be set as the last
437    				       backed out date instead retain the original enrt window.
438    28-Aug-03  tjesumic      115.194    115.192 fix is reversed for # 3086161
439    25-Sep-03  rpillay       115.195    GRADE/STEP: Changes to enrolment_requirements
440                                        to not throw error for G mode when year periods
441                                        are not set up
442    07-oct-03  hmani         115.196    Bug 3137519 - Modified the c_get_latest_enrt_dt cursor
443    21-oct-03  hmani         115.197    Bug 3177401 - Changed p_date_mandatory_flag to 'Y'
444    28-Oct-03  tjesumic      115.198    #  2982606 when the coverage start date of the prev LE is in future
445                                        and current LE is current or earlier than previous one
446                                        create new result and set  currently enrolled flag to 'N'
447                                        related changes in  benbolfe  , benelinf ,benleclr
448    11-oct-03  hmani	    115.199    reversing the change done in 115.197. Changing the flag again.
449    18-Nov-03  tjesumic      115.200    # 3248770 Voided per in ler is not considered to find the enrollment period date
450    14-Jan-04  pbodla        115.201    GLOBALCWB : moved the heirarchy data
451                                        population to benptnle (on to ben_per_in_ler)
452    15-Mar-04  pbodla        115.202    GLOBALCWB : Bug 3502094  : For FP-F trk
453                                        inelig flag do not have any significance.
454                                        For july FP : final functionality will be
455                                        decided later.
456    15-Mar-04  pbodla        115.203    GLOBALCWB : Bug 3502094  : Commented end if
457                                        properly
458    18-Mar-04  rpgupta       115.204    3510229 - Allow system to pick up the
459    					default enrollment code from higher
460    					levels if not found in the lowest level
461    13-Apr-04  kmahendr      115.205    FONM changes.
462    29-Apr-04  mmudigon      115.206    Bug 3595902. Changes to cursors
463                                        c_plan_enrolment_info_unrst and
464                                        c_plan_enrolment_info in proc
465                                        enrolment_requirements
466    15-Jun-04  mmudigon      115.207    Bug 3685228. Merged cursors
467                                        c_plan_enrolment_info_unrst and
468                                        c_plan_enrolment_info in proc
469                                        enrolment_requirements. Treating 'M'
470                                        mode similar to 'U' mode for these
471                                        cursors.
472    29-Jun-04  kmahendr      115.208    Bug#3726552 - added call for updating dflt flag on
473                                        enrt bnft in update_defaults
474    13-Jul-04  kmahendr      115.209    Bug#3697378 - modified cursor-c_get_latest_enrt_dt
475    23-Aug-04  mmudigon      115.210    CFW : 2534391 :NEED TO LEAVE ACTION ITEMS
476                                        CERTIFICATIONS on subsequent events
477    27-Sep-04  pbodla        115.211    iRec : Avoid iRec life events similar to
478                                        gsp events.
479    30-Sep-04  abparekh      115.212    iRec : While picking assignments for iRec do not compare
480                                        primary flag. Extend / Exclude processing for iRec like GSP.
481    21-Oct-04  tjesumic      115.213    # 3936695 Enrollment_cd fixed by cheking the level of the setup
482    26-Oct-04  tjesumic      115.214    # 3936695
483    29-Oct-04  ikasire       115.215    Bugs 3972973 and 3978745 fixes
484    15-nov-04  kmahendr      115.216    Unrest. enh changes
485    17-Nov-04  tjesumic      115.217    # 4008380 fixed. fixed default flag validations
486    22-Nov-04 abparekh       115.218    Bug 4023880 : Fixed code to create elctbl chc at PLAN level if
487                                        they dont exist while creating elctbl chc at OIPL level.
488    01-Dec-04  kmahendr      115.219    Unrest. enh changes
489    30-dec-04    nhunur      115.49     4031733 - No need to open cursor c_state.
490    04-Jan-04  kmahendr      115.221   Bug#4096382 - condition added to return if comp.
491                                       objects are in pending or suspended in U or R mode
492    05-Jan-05  ikasire       115.222   Bug 4106760 fix
493    11-Jan-05  ikasire       115.223   BUG 4064635 CF Suspended Interim Changes
494    26-Jan-05  ikasire       115.224   BUG 4064635 CF Suspended Interim Changes
495    02-Feb-05  ikasire       115.225   BUG 4064635 CF Suspended Interim Changes
496    18-Apr-05  tjesumic      115.226   GHR enhancement to add number of days in enrt perd codeds
497    29-Apr-05  kmahendr      115.227   Added a parameter - update_def_elct_flag to
498                                       determine_enrolment - bug#4338685
499    24-May-05  bmanyam       115.228   Bug 4388226 : Changed c_get_latest_enrt_dt to
500                                       pick up valid enrollments only.
501    08-Jul-05  rbingi        115.229   Bug 4447114 : assigning Global value of
502                                       ben_evaluate_elig_profiles.g_inelg_rsn_cd
503                                       to l_inelg_rsn_cd in case of CWB run mode
504    12-Jul-05  pbodla        115.230   Populating data into ben_cwb_hrchy is
505                                       completely removed.
506    21-Jul-05  kmahendr      115.231   Bug#4478186 - added codes to procedure
507                                       enrt_perd_strt_dt
508    10-Nov-05  tjesumic      115.233   fix 115.232 (4571771) is reversed as the benauten  electable flag
509                                       validation is reverted
510    18-Jan-06  rbingi        115.234   Bug-4717052: Calling update_elig_per_elctbl when epe
511                                       existing for PLAN record for update of pen_id.
512    15-Feb-06  rbingi        115.235   Bug-5035423: contd from prev fix, calling Update_epe
513                                        only when epe exists for PLAN
514    03-Mar-06  kmahendr      115.236   Added new enrollment codes
515    14-Mar-06  ssarkar       115.237   5092244 - populating g_egd_table in update_defaults
516    04-Apr-06  rbingi        115.238   5029028: Added UNIONs to select the enrolment codes
517                                        from respective tables if ler_chg records not defined
518    26-Jun-06  swjain        115.239   5331889 - Added person_id param in calls to benutils.formula
519    30-Jun-06  swjain        115.240   Commented out show errors
520    01-sep-06  ssarkar       115.241   Bug 5491475 - reverted 5029028 fix
521    26-Sep-06  abparekh      115.242   Bug 5555402 - While determining DFLT_ENRT_CD, consider code
522                                                     at PL_NIP level for enrollment at PLIP level
523    28-Sep-06  abparekh      115.243   Bug 5569758 - Get OIPL details correctly in procedure
524                                                     DETERMINE_DFLT_ENRT_CD (1)
525    27-Sep-06  stee          115.244   Bug 5650482  - For scheduled mode, change the processing
526                                       end date to not slide if the event is backed out and
527                                       reprocessed at a later date.
528    05-Dec-06  stee          115.245   Bug 5650482  - If ENRT_PERD_DET_OVRLP_BCKDT_CD
529                                       = L_EPSD_PEPD then slide the processing date.
530    06-Jan-06  bmanyam       115.246   5736589: Increase/Decrease Requires certification
531                                       for Option Restrictions
532    08-Jan-06  bmanyam       115.247   5736589: Increase/Decrease Requires certification
533                                       for Option Restrictions
534    12-Jan-07  gsehgal       115.248   Bug 5644451 - Defaults are not getting created properly.
535 				                              See bug details for test case. Also local procedure
536 				                              determine_dflt_enrt_cd moved at top of the package as this
537 				                              is now used in ben_enrolment_requirements.enrolment_requirements
538    10-Feb-07  stee           115.249   Added a check for g_debug for trace statements.
539    22-Jan-07  rtagarra      115.249   -- ICM Changes for 'D' Mode.
540    28-May-07 rgajula        115.250   Bug 6061856 -- Modified the procedure determine_dflt_enrt_cd such that
541                                       Default Enrollment Codes at LER level Override Default Enrollment Codes at OIPL level.
542    20-Dec-07 sagnanas		      Included fix 6281735 and 6519487 for 12.1
543 */
544 ---------------------------------------------------------------------------------------------------
545   g_package VARCHAR2(80)                := 'ben_enrolment_requirements';
546   g_rec     benutils.g_batch_elctbl_rec;
547   g_ptip_id NUMBER;
548 --
549 --
550 -- internal version below for update_defaults
551 -- bug 5644451. Move at top of the package
552 procedure determine_dflt_enrt_cd
553   (p_oipl_id           in     number
554   ,p_oipl_rec          in     ben_oipl_f%rowtype
555   ,p_plip_id           in     number
556   ,p_plip_rec          in     ben_plip_f%rowtype
557   ,p_pl_id             in     number
558   ,p_pl_rec            in     ben_pl_f%rowtype
559   ,p_ptip_id           in     number
560   ,p_ptip_rec          in     ben_ptip_f%rowtype
561   ,p_pgm_id            in     number
562   ,p_pgm_rec           in     ben_pgm_f%rowtype
563   ,p_ler_id            in     number
564   ,p_business_group_id in     number
565   ,p_effective_date    in     date
566   ,p_dflt_enrt_cd         out nocopy varchar2
567   ,p_dflt_enrt_rl         out nocopy number
568   ,p_level                out nocopy varchar2
569   ,p_ler_dflt_flag   out nocopy varchar2
570   )
571 IS
572     --
573     -- NOTE:
574     --
575     --   This procedure is also callable from other RCOs
576     --   Please do not remove get_object calls since they
577     --   may be needed if not called from bendenrr.
578     --
579     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
580     --
581     CURSOR c_ler_oipl_dflt_cd IS
582       SELECT   leo.dflt_enrt_cd,
583                leo.dflt_enrt_rl,
584                leo.dflt_flag
585       FROM     ben_ler_chg_oipl_enrt_f leo
586       WHERE    p_oipl_id = leo.oipl_id
587       AND      p_ler_id = leo.ler_id
588       AND      p_effective_date BETWEEN leo.effective_start_date
589                    AND leo.effective_end_date;
590     --
591     -- Use cache for oipl, don't need cursor
592     --
593     CURSOR c_ler_pl_nip_dflt_cd IS
594       SELECT   len.dflt_enrt_cd,
595                len.dflt_enrt_rl,
596                len.dflt_flag
597       FROM     ben_ler_chg_pl_nip_enrt_f len
598       WHERE    p_pl_id = len.pl_id
599       AND      p_ler_id = len.ler_id
600       AND      p_effective_date BETWEEN len.effective_start_date
601                    AND len.effective_end_date;
602     --
603     CURSOR c_ler_plip_dflt_cd IS
604       SELECT   lep.dflt_enrt_cd,
605                lep.dflt_enrt_rl,
606                lep.dflt_flag
607       FROM     ben_ler_chg_plip_enrt_f lep
608       WHERE    p_plip_id = lep.plip_id
609       AND      p_ler_id = lep.ler_id
610       AND      p_effective_date BETWEEN lep.effective_start_date
611                    AND lep.effective_end_date;
612     --
613     CURSOR c_ler_ptip_dflt_cd IS
614       SELECT   lep.dflt_enrt_cd,
615                lep.dflt_enrt_rl
616       FROM     ben_ler_chg_ptip_enrt_f lep
617       WHERE    p_ptip_id = lep.ptip_id
618       AND      p_ler_id = lep.ler_id
619       AND      p_effective_date BETWEEN lep.effective_start_date
620                    AND lep.effective_end_date;
621     --
622     CURSOR c_ler_pgm_dflt_cd IS
623       SELECT   lep.dflt_enrt_cd,
624                lep.dflt_enrt_rl
625       FROM     ben_ler_chg_pgm_enrt_f lep
626       WHERE    p_pgm_id = lep.pgm_id
627       AND      p_ler_id = lep.ler_id
628       AND      p_effective_date BETWEEN lep.effective_start_date
629                    AND lep.effective_end_date;
630     --
631     CURSOR c_pl_nip_dflt_cd IS
632       SELECT   pln.nip_dflt_enrt_cd,
633                pln.nip_dflt_enrt_det_rl,
634                pln.nip_dflt_flag
635       FROM     ben_pl_f pln
636       WHERE    p_pl_id = pln.pl_id
637       AND      p_effective_date BETWEEN pln.effective_start_date
638                    AND pln.effective_end_date;
639     --
640     CURSOR c_plip_dflt_cd IS
641       SELECT   plp.dflt_enrt_cd,
642                plp.dflt_enrt_det_rl
643       FROM     ben_plip_f plp
644       WHERE    p_plip_id = plp.plip_id
645       AND      p_effective_date BETWEEN plp.effective_start_date
646                    AND plp.effective_end_date;
647     --
648     CURSOR c_ptip_dflt_cd IS
649       SELECT   ptp.dflt_enrt_cd,
650                ptp.dflt_enrt_det_rl
651       FROM     ben_ptip_f ptp
652       WHERE    p_ptip_id = ptp.ptip_id
653       AND      p_effective_date BETWEEN ptp.effective_start_date
654                    AND ptp.effective_end_date;
655     --
656     l_dflt_enrt_cd VARCHAR2(30);
657     l_dflt_enrt_rl NUMBER;
658     l_plan_rec     ben_pl_f%ROWTYPE;
659     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
660     l_ler_dflt_flag varchar2(30); -- 3510229
661   BEGIN
662     --
663     g_debug := hr_utility.debug_enabled;
664     --
665     if g_debug then
666     hr_utility.set_location('Entering: ' || l_proc, 10);
667     end if;
668     --
669     l_dflt_enrt_cd :=  NULL;
670     --
671     --Start Bug 6061856 -- Modified the Ordering, moved oipl to 6
672     -- Hierarchy
673     --
674     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
675     -- 2  if no pgm   ben_ler_chg_pl_nip_enrt_f
676     -- 3  if pgm      ben_ler_chg_plip_enrt_f
677     -- 4  if pgm      ben_ler_chg_ptip_enrt_f
678     -- 5  if pgm      ben_ler_chg_pgm_enrt_f
679     --
680     -- 6  if oipl     ben_oipl_f (from cache)
681 
682     -- 7  if no pgm   ben_pl_f
683     -- 8  if pgm      ben_plip_f
684     -- 9  if pgm      ben_ptip_f
685     --
686 --End Bug 6061856
687     IF p_oipl_id IS NOT NULL THEN
688       --
689       -- 1
690       --
691       OPEN c_ler_oipl_dflt_cd;
692       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag;
693                                     --p_ler_dflt_flag; 3510229
694       CLOSE c_ler_oipl_dflt_cd;
695       if /*l_dflt_enrt_cd 3510229*/l_ler_dflt_flag is not null then
696         p_level:='LER_OIPL';
697         p_ler_dflt_flag := l_ler_dflt_flag; -- 3510229
698         l_ler_dflt_flag := null ; --3510229
699       end if;
700       --
701      /* IF l_dflt_enrt_cd IS NULL THEN
702         --
703         -- 2
704         --
705 	if g_debug then
706         hr_utility.set_location('In the case 2 ' , 100);
707 	end if;
708         --
709         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
710         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
711         --
712         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
713         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
714 
715         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
716         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
717         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
718         --
719       if l_dflt_enrt_cd is not null
720          and p_level is null then -- 3510229
721         p_level:='OIPL';
722       end if;
723       --
724       END IF;*/
725     END IF;
726 
727     IF     p_pgm_id IS NULL
728        AND l_dflt_enrt_cd IS NULL THEN
729       --
730       -- 2
731       --
732       OPEN c_ler_pl_nip_dflt_cd;
733       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag; --3510229
734                                     --p_ler_dflt_flag;
735       CLOSE c_ler_pl_nip_dflt_cd;
736       if l_dflt_enrt_cd is not null
737          and p_level is null then -- 3510229
738         p_level:='LER_PL_NIP';
739         -- 3510229 start
740         -- there could be default flag without default code , so this s moved down - 	4008380
741         --if p_ler_dflt_flag is null then
742         --  p_ler_dflt_flag := l_ler_dflt_flag;
743         --end if;
744         --l_ler_dflt_flag := null ;
745 	if g_debug then
746         hr_utility.set_location('after LER pNip chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
747 	end if;
748         -- 3510229 end
749 
750       end if;
751       -- there could be default flag without default code 4008380
752       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
753           p_ler_dflt_flag := l_ler_dflt_flag ;
754       end if ;
755       if g_debug then
756       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
757       hr_utility.set_location(l_dflt_enrt_cd,40);
758       end if;
759 
760     ELSIF     p_pgm_id IS NOT NULL
761           AND l_dflt_enrt_cd IS NULL THEN
762       --
763       -- 3
764       --
765       OPEN c_ler_plip_dflt_cd;
766       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag; --3510229
767                                     --p_ler_dflt_flag;
768       CLOSE c_ler_plip_dflt_cd;
769       if l_dflt_enrt_cd is not null
770          and p_level is null then -- 3510229
771         p_level:='LER_PLIP';
772 
773         -- 3510229 start
774         --  4008380
775         --if p_ler_dflt_flag is null then
776         --  p_ler_dflt_flag := l_ler_dflt_flag;
777         --end if;
778 	if g_debug then
779         hr_utility.set_location('after LER PLIP chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
780 	end if;
781         --l_ler_dflt_flag := null ;
782         -- 3510229 end
783 
784       end if;
785       --  4008380
786       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
787           p_ler_dflt_flag := l_ler_dflt_flag ;
788       end if ;
789       if g_debug then
790       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,50);
791       hr_utility.set_location(l_dflt_enrt_cd,50);
792       end if;
793       --  4008380
794       --  there could be plip but the setup may be in plan  ler level
795       IF l_dflt_enrt_cd IS NULL THEN
796 
797          OPEN c_ler_pl_nip_dflt_cd;
798          FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag;
799          CLOSE c_ler_pl_nip_dflt_cd;
800 
801          if l_dflt_enrt_cd is not null
802             and p_level is null then -- 3510229
803             p_level:='LER_PL';
804          if g_debug then
805             hr_utility.set_location('after LER Plan  chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
806          end if;
807          end if;
808          -- there could be default flag without default code 4008380
809          if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
810             p_ler_dflt_flag := l_ler_dflt_flag ;
811          end if ;
812 	 if g_debug then
813          hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
814          hr_utility.set_location(l_dflt_enrt_cd,40);
815 	 end if;
816       end if ;
817 
818 
819 
820       --- ptip level
821       IF l_dflt_enrt_cd IS NULL THEN
822         --
823         -- 4
824         --
825         OPEN c_ler_ptip_dflt_cd;
826         FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
827         CLOSE c_ler_ptip_dflt_cd;
828       if l_dflt_enrt_cd is not null
829          and p_level is null then -- 3510229
830         p_level:='LER_PTIP';
831       end if;
832         --  hr_utility.set_location(l_dflt_enrt_cd,60);
833         IF l_dflt_enrt_cd IS NULL THEN
834           --
835           -- 5
836           --
837           OPEN c_ler_pgm_dflt_cd;
838           FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
839           CLOSE c_ler_pgm_dflt_cd;
840       if l_dflt_enrt_cd is not null
841          and p_level is null then --3510229
842         p_level:='LER_PTIP'; --Bug 6281735
843       end if;
844         END IF;
845       END IF;
846     END IF;
847 --Start Bug 6061856
848 --Default Codes LER override OIPL Level
849     if p_oipl_id is not null then
850       IF l_dflt_enrt_cd IS NULL THEN
851         --
852         -- 6
853         --
854         hr_utility.set_location('In the case 2 ' , 100);
855         --
856         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
857         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
858         --
859         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
860         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
861 
862         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
863         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
864         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
865         --
866       if l_dflt_enrt_cd is not null
867          and p_level is null then -- 3510229
868         p_level:='OIPL';
869       end if;
870       --
871       END IF;
872      end if;
873 --End Bug 6061856
874 
875     --  hr_utility.set_location(l_dflt_enrt_cd,80);
876     IF     p_pgm_id IS NULL
877        AND l_dflt_enrt_cd IS NULL THEN
878       --
879       -- 7
880       --
881       -- Bug 1895874
882       -- l_dflt_enrt_cd :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_cd;
883       -- l_dflt_enrt_rl :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_det_rl;
884       --
885       if g_debug then
886       hr_utility.set_location(' p_pl_rec.pl_id '||p_oipl_rec.oipl_id ,110);
887       hr_utility.set_location(' p_pl_rec.nip_dflt_enrt_cd '||p_pl_rec.nip_dflt_enrt_cd ,110);
888       hr_utility.set_location(' p_pl_rec.nip_dflt_flag '||p_pl_rec.nip_dflt_flag, 110)  ;
889       end if;
890       --
891       l_dflt_enrt_cd := p_pl_rec.nip_dflt_enrt_cd ;
892       l_dflt_enrt_rl := p_pl_rec.nip_dflt_enrt_det_rl ;
893       if p_ler_dflt_flag is null then -- 3510229
894         p_ler_dflt_flag := p_pl_rec.nip_dflt_flag ;
895       end if;
896 
897 /*
898       OPEN c_pl_nip_dflt_cd;
899       FETCH c_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,
900                                     p_ler_dflt_flag;
901       CLOSE c_pl_nip_dflt_cd;
902 */
903       --
904       if l_dflt_enrt_cd is not null
905          and p_level is null then -- 3510229
906         p_level:='PL';
907       end if;
908       --
909     --  hr_utility.set_location(l_dflt_enrt_cd,90);
910 
911     ELSIF     p_pgm_id IS NOT NULL
912           AND l_dflt_enrt_cd IS NULL THEN
913       --
914       -- 8
915       --
916       l_dflt_enrt_cd := p_plip_rec.dflt_enrt_cd ;
917       l_dflt_enrt_rl := p_plip_rec.dflt_enrt_det_rl ;
918 /*
919       OPEN c_plip_dflt_cd;
920       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
921       CLOSE c_plip_dflt_cd;
922 */
923       if l_dflt_enrt_cd is not null
924          and p_level is null then -- 3510229
925         p_level:='PLIP';
926       end if;
927        if g_debug then
928        hr_utility.set_location(l_dflt_enrt_cd,100);
929        end if;
930         --
931       IF l_dflt_enrt_cd IS NULL THEN
932         --
933         -- 9
934         --
935       l_dflt_enrt_cd := p_ptip_rec.dflt_enrt_cd ;
936       l_dflt_enrt_rl := p_ptip_rec.dflt_enrt_det_rl ;
937 /*
938         OPEN c_ptip_dflt_cd;
939         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
940         CLOSE c_ptip_dflt_cd;
941 */
942       if l_dflt_enrt_cd is not null
943          and p_level is null then -- 3510229
944         p_level:='PTIP';
945       end if;
946       if g_debug then
947       hr_utility.set_location(l_dflt_enrt_cd,110);
948       end if;
949         --
950       END IF;
951     END IF;
952   --
953    if g_debug then
954     hr_utility.set_location(' p_pgm_id '||p_pgm_id||' pl_id '||p_pl_id||' oipl '||p_oipl_id||
955                             ' plip '||p_plip_id||' ptip '||p_ptip_id,130);
956     hr_utility.set_location('dflt_enrt_cd= '||l_dflt_enrt_cd,130);
957     hr_utility.set_location('dflt_enrt_rl= '||l_dflt_enrt_rl,140);
958     hr_utility.set_location('p_ler_dflt_flag= '||p_ler_dflt_flag ,140);
959    end if;
960     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
961     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
962     if g_debug then
963     hr_utility.set_location('Leaving: ' || l_proc, 150);
964     end if;
965   exception
966     --
967     when others then
968       --
969       p_dflt_enrt_cd        := null;
970       p_dflt_enrt_rl        := null;
971       p_level               := null;
972       p_ler_dflt_flag       := null;
973       raise;
974       --
975   END;
976 -- end internal determine_dflt_enrt_cd
977   PROCEDURE determine_ben_settings(
978     p_pl_id                     IN     ben_ler_chg_pl_nip_enrt_f.pl_id%TYPE,
979     p_ler_id                    IN     ben_ler_chg_pl_nip_enrt_f.ler_id%TYPE,
980     p_lf_evt_ocrd_dt            IN     DATE,
981     p_ptip_id                   IN     ben_ler_chg_ptip_enrt_f.ptip_id%TYPE,
982     p_pgm_id                    IN     ben_ler_chg_pgm_enrt_f.pgm_id%TYPE,
983     p_plip_id                   IN     ben_ler_chg_plip_enrt_f.plip_id%TYPE,
984     p_oipl_id                   IN     ben_ler_chg_oipl_enrt_f.oipl_id%TYPE,
985     p_just_prclds_chg_flag      IN     BOOLEAN DEFAULT FALSE,
986     p_enrt_cd                   OUT NOCOPY    ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE,
987     p_enrt_rl                   OUT NOCOPY    ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE,
988     p_auto_enrt_mthd_rl         OUT NOCOPY    ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE,
989     p_crnt_enrt_prclds_chg_flag OUT NOCOPY    ben_ler_chg_oipl_enrt_f.crnt_enrt_prclds_chg_flag%TYPE,
990     p_dflt_flag                 OUT NOCOPY    ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE,
991     p_enrt_mthd_cd              OUT NOCOPY    ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE,
992     p_stl_elig_cant_chg_flag    OUT NOCOPY    ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE,
993     p_tco_chg_enrt_cd           OUT NOCOPY    ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE,
994     p_ler_chg_oipl_found_flag   OUT NOCOPY    VARCHAR2,
995     p_ler_chg_found_flag        OUT NOCOPY    VARCHAR2,
996     p_enrt_cd_level             OUT NOCOPY    VARCHAR2 ) IS
997     -- ========================
998     -- define the local cursors
999     -- ========================
1000     -- Bug 5029028: Added UNIONs for all cursors to select the codes from respective
1001     -- tables if ler_chg records not defined.
1002    -- ssarkar 5491475 : roll back 5029028
1003     CURSOR csr_oipl IS
1004       SELECT   oipl.auto_enrt_flag,
1005                oipl.auto_enrt_mthd_rl,
1006                oipl.crnt_enrt_prclds_chg_flag,
1007                oipl.dflt_flag,
1008                oipl.enrt_cd,
1009                oipl.enrt_rl,
1010                oipl.ler_chg_oipl_enrt_id,
1011                oipl.stl_elig_cant_chg_flag
1012       FROM     ben_ler_chg_oipl_enrt_f oipl
1013       WHERE    oipl.oipl_id = p_oipl_id
1014       AND      oipl.ler_id = p_ler_id
1015       AND      p_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1016                    AND oipl.effective_end_date;
1017     --
1018     CURSOR csr_pgm IS
1019       SELECT   pgm.auto_enrt_mthd_rl,
1020                pgm.crnt_enrt_prclds_chg_flag,
1021                pgm.enrt_cd,
1022                pgm.enrt_mthd_cd,
1023                pgm.enrt_rl,
1024                pgm.ler_chg_pgm_enrt_id,
1025                pgm.stl_elig_cant_chg_flag
1026       FROM     ben_ler_chg_pgm_enrt_f pgm
1027       WHERE    pgm.pgm_id = p_pgm_id
1028       AND      pgm.ler_id = p_ler_id
1029       AND      p_lf_evt_ocrd_dt BETWEEN pgm.effective_start_date
1030                    AND pgm.effective_end_date;
1031     --
1032     CURSOR csr_ptip IS
1033       SELECT   ptip.crnt_enrt_prclds_chg_flag,
1034                ptip.enrt_cd,
1035                ptip.enrt_mthd_cd,
1036                ptip.enrt_rl,
1037                ptip.ler_chg_ptip_enrt_id,
1038                ptip.stl_elig_cant_chg_flag,
1039                ptip.tco_chg_enrt_cd
1040       FROM     ben_ler_chg_ptip_enrt_f ptip
1041       WHERE    ptip.ptip_id = p_ptip_id
1042       AND      ptip.ler_id = p_ler_id
1043       AND      p_lf_evt_ocrd_dt BETWEEN ptip.effective_start_date
1044                    AND ptip.effective_end_date;
1045     --
1046     CURSOR csr_plip IS
1047       SELECT   plip.auto_enrt_mthd_rl,
1048                plip.crnt_enrt_prclds_chg_flag,
1049                plip.dflt_flag,
1050                plip.enrt_cd,
1051                plip.enrt_mthd_cd,
1052                plip.enrt_rl,
1053                plip.ler_chg_plip_enrt_id,
1054                plip.stl_elig_cant_chg_flag,
1055                plip.tco_chg_enrt_cd
1056       FROM     ben_ler_chg_plip_enrt_f plip
1057       WHERE    plip.plip_id = p_plip_id
1058       AND      plip.ler_id = p_ler_id
1059       AND      p_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
1060                    AND plip.effective_end_date;
1061     --
1062     CURSOR csr_pl_nip IS
1063       SELECT   pl_nip.auto_enrt_mthd_rl,
1064                pl_nip.crnt_enrt_prclds_chg_flag,
1065                pl_nip.dflt_flag,
1066                pl_nip.enrt_cd,
1067                pl_nip.enrt_mthd_cd,
1068                pl_nip.enrt_rl,
1069                pl_nip.ler_chg_pl_nip_enrt_id,
1070                pl_nip.stl_elig_cant_chg_flag,
1071                pl_nip.tco_chg_enrt_cd
1072       FROM     ben_ler_chg_pl_nip_enrt_f pl_nip
1073       WHERE    pl_nip.pl_id = p_pl_id
1074       AND      pl_nip.ler_id = p_ler_id
1075       AND      p_lf_evt_ocrd_dt BETWEEN pl_nip.effective_start_date
1076                    AND pl_nip.effective_end_date;
1077     -- ======================
1078     -- define local variables
1079     -- ======================
1080     oipl_auto_enrt_flag            ben_ler_chg_oipl_enrt_f.auto_enrt_flag%TYPE;
1081     oipl_auto_enrt_mthd_rl         ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE;
1082     oipl_crnt_enrt_prclds_chg_flag ben_ler_chg_oipl_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1083     oipl_dflt_flag                 ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE;
1084     oipl_enrt_cd                   ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE;
1085     oipl_enrt_rl                   ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE;
1086     oipl_ler_chg_oipl_enrt_id      ben_ler_chg_oipl_enrt_f.ler_chg_oipl_enrt_id%TYPE;
1087     oipl_stl_elig_cant_chg_flag    ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE;
1088     pgm_auto_enrt_mthd_rl          ben_ler_chg_pgm_enrt_f.auto_enrt_mthd_rl%TYPE;
1089     pgm_crnt_enrt_prclds_chg_flag  ben_ler_chg_pgm_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1090     pgm_enrt_cd                    ben_ler_chg_pgm_enrt_f.enrt_cd%TYPE;
1091     pgm_enrt_mthd_cd               ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE;
1092     pgm_enrt_rl                    ben_ler_chg_pgm_enrt_f.enrt_rl%TYPE;
1093     pgm_ler_chg_pgm_enrt_id        ben_ler_chg_pgm_enrt_f.ler_chg_pgm_enrt_id%TYPE;
1094     pgm_stl_elig_cant_chg_flag     ben_ler_chg_pgm_enrt_f.stl_elig_cant_chg_flag%TYPE;
1095     pnip_auto_enrt_mthd_rl         ben_ler_chg_pl_nip_enrt_f.auto_enrt_mthd_rl%TYPE;
1096     pnip_crnt_enrt_prclds_chg_flag ben_ler_chg_pl_nip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1097     pnip_dflt_flag                 ben_ler_chg_pl_nip_enrt_f.dflt_flag%TYPE;
1098     pnip_enrt_cd                   ben_ler_chg_pl_nip_enrt_f.enrt_cd%TYPE;
1099     pnip_enrt_mthd_cd              ben_ler_chg_pl_nip_enrt_f.enrt_mthd_cd%TYPE;
1100     pnip_enrt_rl                   ben_ler_chg_pl_nip_enrt_f.enrt_rl%TYPE;
1101     pnip_ler_chg_pnip_enrt_id      ben_ler_chg_pl_nip_enrt_f.ler_chg_pl_nip_enrt_id%TYPE;
1102     pnip_stl_elig_cant_chg_flag    ben_ler_chg_pl_nip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1103     pnip_tco_chg_enrt_cd           ben_ler_chg_pl_nip_enrt_f.tco_chg_enrt_cd%TYPE;
1104     plip_auto_enrt_mthd_rl         ben_ler_chg_plip_enrt_f.auto_enrt_mthd_rl%TYPE;
1105     plip_crnt_enrt_prclds_chg_flag ben_ler_chg_plip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1106     plip_dflt_flag                 ben_ler_chg_plip_enrt_f.dflt_flag%TYPE;
1107     plip_enrt_cd                   ben_ler_chg_plip_enrt_f.enrt_cd%TYPE;
1108     plip_enrt_mthd_cd              ben_ler_chg_plip_enrt_f.enrt_mthd_cd%TYPE;
1109     plip_enrt_rl                   ben_ler_chg_plip_enrt_f.enrt_rl%TYPE;
1110     plip_ler_chg_plip_enrt_id      ben_ler_chg_plip_enrt_f.ler_chg_plip_enrt_id%TYPE;
1111     plip_stl_elig_cant_chg_flag    ben_ler_chg_plip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1112     plip_tco_chg_enrt_cd           ben_ler_chg_plip_enrt_f.tco_chg_enrt_cd%TYPE;
1113     ptip_crnt_enrt_prclds_chg_flag ben_ler_chg_ptip_enrt_f.crnt_enrt_prclds_chg_flag%TYPE;
1114     ptip_enrt_cd                   ben_ler_chg_ptip_enrt_f.enrt_cd%TYPE;
1115     ptip_enrt_mthd_cd              ben_ler_chg_ptip_enrt_f.enrt_mthd_cd%TYPE;
1116     ptip_enrt_rl                   ben_ler_chg_ptip_enrt_f.enrt_rl%TYPE;
1117     ptip_ler_chg_ptip_enrt_id      ben_ler_chg_ptip_enrt_f.ler_chg_ptip_enrt_id%TYPE;
1118     ptip_stl_elig_cant_chg_flag    ben_ler_chg_ptip_enrt_f.stl_elig_cant_chg_flag%TYPE;
1119     ptip_tco_chg_enrt_cd           ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE;
1120     l_temp                         number; -- 5029028
1121   BEGIN
1122   -- ============================================
1123   -- open,fetch and close each cursor if required
1124   -- ============================================
1125     IF p_ler_id IS NOT NULL THEN
1126       IF p_oipl_id IS NOT NULL THEN
1127         OPEN csr_oipl;
1128         FETCH csr_oipl INTO oipl_auto_enrt_flag,
1129                             oipl_auto_enrt_mthd_rl,
1130                             oipl_crnt_enrt_prclds_chg_flag,
1131                             oipl_dflt_flag,
1132                             oipl_enrt_cd,
1133                             oipl_enrt_rl,
1134                             oipl_ler_chg_oipl_enrt_id,
1135                             oipl_stl_elig_cant_chg_flag;
1136                             --l_temp;
1137         CLOSE csr_oipl;
1138       END IF;
1139       IF p_pl_id IS NOT NULL THEN
1140         OPEN csr_pl_nip;
1141         FETCH csr_pl_nip INTO pnip_auto_enrt_mthd_rl,
1142                               pnip_crnt_enrt_prclds_chg_flag,
1143                               pnip_dflt_flag,
1144                               pnip_enrt_cd,
1145                               pnip_enrt_mthd_cd,
1146                               pnip_enrt_rl,
1147                               pnip_ler_chg_pnip_enrt_id,
1148                               pnip_stl_elig_cant_chg_flag,
1149                               pnip_tco_chg_enrt_cd;
1150                               --l_temp;
1151         CLOSE csr_pl_nip;
1152       END IF;
1153       IF p_plip_id IS NOT NULL THEN
1154         OPEN csr_plip;
1155         FETCH csr_plip INTO plip_auto_enrt_mthd_rl,
1156                             plip_crnt_enrt_prclds_chg_flag,
1157                             plip_dflt_flag,
1158                             plip_enrt_cd,
1159                             plip_enrt_mthd_cd,
1160                             plip_enrt_rl,
1161                             plip_ler_chg_plip_enrt_id,
1162                             plip_stl_elig_cant_chg_flag,
1163                             plip_tco_chg_enrt_cd;
1164                             --l_temp;
1165         CLOSE csr_plip;
1166       END IF;
1167       IF p_ptip_id IS NOT NULL THEN
1168         OPEN csr_ptip;
1169         FETCH csr_ptip INTO ptip_crnt_enrt_prclds_chg_flag,
1170                             ptip_enrt_cd,
1171                             ptip_enrt_mthd_cd,
1172                             ptip_enrt_rl,
1173                             ptip_ler_chg_ptip_enrt_id,
1174                             ptip_stl_elig_cant_chg_flag,
1175                             ptip_tco_chg_enrt_cd;
1176                             --l_temp;
1177         CLOSE csr_ptip;
1178       END IF;
1179       IF p_pgm_id IS NOT NULL THEN
1180         OPEN csr_pgm;
1181         FETCH csr_pgm INTO pgm_auto_enrt_mthd_rl,
1182                            pgm_crnt_enrt_prclds_chg_flag,
1183                            pgm_enrt_cd,
1184                            pgm_enrt_mthd_cd,
1185                            pgm_enrt_rl,
1186                            pgm_ler_chg_pgm_enrt_id,
1187                            pgm_stl_elig_cant_chg_flag;
1188                            --l_temp;
1189         CLOSE csr_pgm;
1190       END IF;
1191       -- ==========================================
1192       -- determine and SET the OUT parameter values
1193       -- ==========================================
1194       -- --------------------------------
1195       -- set: p_crnt_enrt_prclds_chg_flag
1196       -- --------------------------------
1197       IF oipl_crnt_enrt_prclds_chg_flag IS NULL THEN
1198         IF pnip_crnt_enrt_prclds_chg_flag IS NULL THEN
1199           IF plip_crnt_enrt_prclds_chg_flag IS NULL THEN
1200             IF ptip_crnt_enrt_prclds_chg_flag IS NULL THEN
1201               p_crnt_enrt_prclds_chg_flag :=  pgm_crnt_enrt_prclds_chg_flag;
1202             ELSE
1203               p_crnt_enrt_prclds_chg_flag :=  ptip_crnt_enrt_prclds_chg_flag;
1204             END IF;
1205           ELSE
1206             p_crnt_enrt_prclds_chg_flag :=  plip_crnt_enrt_prclds_chg_flag;
1207           END IF;
1208         ELSE
1209           p_crnt_enrt_prclds_chg_flag :=  pnip_crnt_enrt_prclds_chg_flag;
1210         END IF;
1211       ELSE
1212         p_crnt_enrt_prclds_chg_flag :=  oipl_crnt_enrt_prclds_chg_flag;
1213       END IF;
1214       -- test to see if only the p_crnt_enrt_prclds_chg_flag is required
1215       --IF p_just_prclds_chg_flag THEN
1216       --  RETURN;
1217       --END IF;
1218       -- ----------------------------
1219       -- set: p_enrt_cd and p_enrt_rl
1220       -- ----------------------------
1221 
1222      ----
1223      hr_utility.set_location( 'oipl' || oipl_enrt_cd , 10) ;
1224      hr_utility.set_location( 'pl' || pnip_enrt_cd , 10) ;
1225      hr_utility.set_location( 'plip' || plip_enrt_cd , 10);
1226      hr_utility.set_location( 'ptip' || ptip_enrt_cd , 10) ;
1227 
1228 
1229 
1230      hr_utility.set_location( 'oipl id ' || p_oipl_id , 10) ;
1231      hr_utility.set_location( 'ptip id ' || p_ptip_id , 10) ;
1232      hr_utility.set_location( 'plip id ' || p_plip_id , 10) ;
1233      hr_utility.set_location( 'pl id   ' || p_pl_id   , 10) ;
1234      ---
1235 
1236 
1237       IF oipl_enrt_cd IS NULL THEN
1238         IF pnip_enrt_cd IS NULL THEN
1239           IF plip_enrt_cd IS NULL THEN
1240             IF ptip_enrt_cd IS NULL THEN
1241               p_enrt_cd      :=  pgm_enrt_cd;
1242               p_enrt_rl      :=  pgm_enrt_rl;
1243               p_enrt_cd_level:= 'PGM' ;
1244             ELSE
1245               p_enrt_cd :=  ptip_enrt_cd;
1246               p_enrt_rl :=  ptip_enrt_rl;
1247               p_enrt_cd_level := 'PTIP' ;
1248             END IF;
1249           ELSE
1250             p_enrt_cd :=  plip_enrt_cd;
1251             p_enrt_rl :=  plip_enrt_rl;
1252             p_enrt_cd_level := 'PLIP' ;
1253           END IF;
1254         ELSE
1255           p_enrt_cd :=  pnip_enrt_cd;
1256           p_enrt_rl :=  pnip_enrt_rl;
1257           p_enrt_cd_level := 'PL' ;
1258         END IF;
1259       ELSE
1260         p_enrt_cd :=  oipl_enrt_cd;
1261         p_enrt_rl :=  oipl_enrt_rl;
1262         p_enrt_cd_level := 'OIPL' ;
1263       END IF;
1264       hr_utility.set_location( 'p_enrt_cd_level  ' || p_enrt_cd_level , 10) ;
1265 
1266        IF p_just_prclds_chg_flag THEN
1267         RETURN;
1268       END IF;
1269 
1270 
1271 
1272       -- ------------------------
1273       -- set: p_auto_enrt_mthd_rl
1274       -- ------------------------
1275       IF oipl_auto_enrt_mthd_rl IS NULL THEN
1276         IF pnip_auto_enrt_mthd_rl IS NULL THEN
1277           IF plip_auto_enrt_mthd_rl IS NULL THEN
1278             p_auto_enrt_mthd_rl :=  pgm_auto_enrt_mthd_rl;
1279           ELSE
1280             p_auto_enrt_mthd_rl :=  plip_auto_enrt_mthd_rl;
1281           END IF;
1282         ELSE
1283           p_auto_enrt_mthd_rl :=  pnip_auto_enrt_mthd_rl;
1284         END IF;
1285       ELSE
1286         p_auto_enrt_mthd_rl :=  oipl_auto_enrt_mthd_rl;
1287       END IF;
1288       -- ----------------
1289       -- set: p_dflt_flag
1290       -- ----------------
1291       IF oipl_dflt_flag IS NULL THEN
1292         IF pnip_dflt_flag IS NULL THEN
1293           p_dflt_flag :=  plip_dflt_flag;
1294         ELSE
1295           p_dflt_flag :=  pnip_dflt_flag;
1296         END IF;
1297       ELSE
1298         p_dflt_flag :=  oipl_dflt_flag;
1299       END IF;
1300       -- -------------------
1301       -- set: p_enrt_mthd_cd
1302       -- -------------------
1303       IF oipl_auto_enrt_flag = 'Y' THEN
1304         p_enrt_mthd_cd :=  'A';
1305       ELSIF oipl_auto_enrt_flag = 'N' THEN
1306         p_enrt_mthd_cd :=  'E';
1307       ELSE
1308         IF pnip_enrt_mthd_cd IS NULL THEN
1309           IF plip_enrt_mthd_cd IS NULL THEN
1310             IF ptip_enrt_mthd_cd IS NULL THEN
1311               p_enrt_mthd_cd :=  pgm_enrt_mthd_cd;
1312             ELSE
1313               p_enrt_mthd_cd :=  ptip_enrt_mthd_cd;
1314             END IF;
1315           ELSE
1316             p_enrt_mthd_cd :=  plip_enrt_mthd_cd;
1317           END IF;
1318         ELSE
1319           p_enrt_mthd_cd :=  pnip_enrt_mthd_cd;
1320         END IF;
1321       END IF;
1322       -- -----------------------------
1323       -- set: p_stl_elig_cant_chg_flag
1324       -- -----------------------------
1325       IF oipl_stl_elig_cant_chg_flag IS NULL THEN
1326         IF pnip_stl_elig_cant_chg_flag IS NULL THEN
1327           IF plip_stl_elig_cant_chg_flag IS NULL THEN
1328             IF ptip_stl_elig_cant_chg_flag IS NULL THEN
1329               p_stl_elig_cant_chg_flag :=  pgm_stl_elig_cant_chg_flag;
1330             ELSE
1331               p_stl_elig_cant_chg_flag :=  ptip_stl_elig_cant_chg_flag;
1332             END IF;
1333           ELSE
1334             p_stl_elig_cant_chg_flag :=  plip_stl_elig_cant_chg_flag;
1335           END IF;
1336         ELSE
1337           p_stl_elig_cant_chg_flag :=  pnip_stl_elig_cant_chg_flag;
1338         END IF;
1339       ELSE
1340         p_stl_elig_cant_chg_flag :=  oipl_stl_elig_cant_chg_flag;
1341       END IF;
1342       -- ----------------------
1343       -- set: p_tco_chg_enrt_cd
1344       -- ----------------------
1345       IF pnip_tco_chg_enrt_cd IS NULL THEN
1346         IF plip_tco_chg_enrt_cd IS NULL THEN
1347           p_tco_chg_enrt_cd :=  ptip_tco_chg_enrt_cd;
1348         ELSE
1349           p_tco_chg_enrt_cd :=  plip_tco_chg_enrt_cd;
1350         END IF;
1351       ELSE
1352         p_tco_chg_enrt_cd :=  pnip_tco_chg_enrt_cd;
1353       END IF;
1354       -- -------------------------------------------------------
1355       -- set: p_ler_chg_oipl_found_flag and p_ler_chg_found_flag
1356       -- -------------------------------------------------------
1357       IF oipl_ler_chg_oipl_enrt_id IS NULL THEN
1358         p_ler_chg_oipl_found_flag :=  'N';
1359         IF     plip_ler_chg_plip_enrt_id IS NULL
1360            AND ptip_ler_chg_ptip_enrt_id IS NULL
1361            AND pnip_ler_chg_pnip_enrt_id IS NULL
1362            AND pgm_ler_chg_pgm_enrt_id IS NULL THEN
1363           p_ler_chg_found_flag :=  'N';
1364         ELSE
1365           p_ler_chg_found_flag :=  'Y';
1366         END IF;
1367       ELSE
1368         p_ler_chg_oipl_found_flag :=  'Y';
1369         p_ler_chg_found_flag :=       'Y';
1370       END IF;
1371     END IF;
1372     hr_utility.set_location( 'p_enrt_cd_level  ' || p_enrt_cd_level , 10) ;
1373   exception
1374     --
1375     when others then
1376       --
1377       p_enrt_cd                   := null;
1378       p_enrt_rl                   := null;
1379       p_auto_enrt_mthd_rl         := null;
1380       p_crnt_enrt_prclds_chg_flag := null;
1381       p_dflt_flag                 := null;
1382       p_enrt_mthd_cd              := null;
1383       p_stl_elig_cant_chg_flag    := null;
1384       p_tco_chg_enrt_cd           := null;
1385       p_ler_chg_oipl_found_flag   := null;
1386       p_ler_chg_found_flag        := null;
1387       raise;
1388       --
1389   END determine_ben_settings;
1390   --
1391   PROCEDURE determine_enrolment(
1392     p_previous_eligibility       VARCHAR2,
1393     p_crnt_enrt_cvg_strt_dt      DATE,
1394     p_dpnt_cvrd_flag             VARCHAR2,
1395     p_enrt_cd                    VARCHAR2,
1396     p_enrt_rl                    NUMBER,
1397     p_enrt_mthd_cd               VARCHAR2,
1398     p_auto_enrt_mthd_rl          NUMBER,
1399     p_effective_date             DATE,
1400     p_lf_evt_ocrd_dt             DATE DEFAULT NULL,
1401     p_elig_per_id                NUMBER DEFAULT NULL,
1402     p_enrt_prclds_chg_flag       VARCHAR2 DEFAULT 'N',
1403     p_stl_elig_cant_chg_flag     VARCHAR2 DEFAULT 'N',
1404     p_tco_chg_enrt_cd            VARCHAR2 DEFAULT 'CPOO',
1405     p_pl_id                      NUMBER,
1406     p_pgm_id                     NUMBER,
1407     p_oipl_id                    NUMBER,
1408     p_opt_id                     NUMBER,
1409     p_pl_typ_id                  NUMBER,
1410     p_person_id                  NUMBER,
1411     p_ler_id                     NUMBER,
1412     p_business_group_id          NUMBER,
1413     p_electable_flag         OUT NOCOPY VARCHAR2,
1414     p_assignment_id              NUMBER,
1415     p_run_mode                   varchar2 default null,  /* iRec : Added p_run_mode */
1416     p_update_def_elct_flag       varchar2) IS
1417     --
1418     l_proc                     VARCHAR2(80)
1419                                           := g_package ||
1420                                                '.determine_enrolment';
1421     --
1422     l_result_flag              VARCHAR2(30);
1423     l_crnt_pl_enrt_cvg_strt_dt DATE;
1424     l_crnt_opt_cvg_strt_dt     DATE;
1425     l_pgm_rec                  ben_pgm_f%ROWTYPE;
1426     l_jurisdiction_code        VARCHAR2(30);
1427     --
1428     l_lf_evt_ocrd_dt           DATE := NVL(p_lf_evt_ocrd_dt, p_effective_date);
1429     l_lf_evt_ocrd_dt_1         DATE                     := l_lf_evt_ocrd_dt -
1430                                                              1;
1431     l_enrt_cd                  ben_ler_chg_oipl_enrt_f.enrt_cd%TYPE;
1432     l_enrt_rl                  ben_ler_chg_oipl_enrt_f.enrt_rl%TYPE;
1433     l_auto_enrt_mthd_rl        ben_ler_chg_oipl_enrt_f.auto_enrt_mthd_rl%TYPE;
1434     l_dflt_flag                ben_ler_chg_oipl_enrt_f.dflt_flag%TYPE;
1435     l_enrt_mthd_cd             ben_ler_chg_pgm_enrt_f.enrt_mthd_cd%TYPE;
1436     l_stl_elig_cant_chg_flag   ben_ler_chg_oipl_enrt_f.stl_elig_cant_chg_flag%TYPE;
1437     l_tco_chg_enrt_cd          ben_ler_chg_ptip_enrt_f.tco_chg_enrt_cd%TYPE;
1438     l_ler_chg_oipl_found_flag  VARCHAR2(30);
1439     l_ler_chg_found_flag       VARCHAR2(30);
1440     --
1441     -- Gets the enrollments in the ptip and option
1442     --
1443     -- --
1444     CURSOR c_enrolled_opts_in_pl_typ IS
1445       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1446       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pl, ben_oipl_f oipl
1447       WHERE    pen.person_id = p_person_id
1448       AND      pen.business_group_id = p_business_group_id
1449       AND      pen.effective_end_date = hr_api.g_eot
1450       AND      l_lf_evt_ocrd_dt_1 BETWEEN pen.enrt_cvg_strt_dt
1451                    AND pen.enrt_cvg_thru_dt
1452       AND      pl.pl_id = pen.pl_id
1453       AND      pl.business_group_id = p_business_group_id
1454       AND      pl.pl_typ_id = p_pl_typ_id
1455       AND      oipl.oipl_id = pen.oipl_id
1456       AND      oipl.opt_id = p_opt_id
1457       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
1458                    AND pl.effective_end_date
1459       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1460                    AND oipl.effective_end_date
1461       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1462       AND      pen.sspndd_flag = 'N'
1463       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1464       AND      oipl.business_group_id = p_business_group_id
1465       AND      (
1466                     (    pen.pgm_id = p_pgm_id
1467                      AND p_pgm_id IS NOT NULL)
1468                  OR (    pen.pgm_id IS NULL
1469                      AND p_pgm_id IS NULL));
1470     --
1471     -- Gets the enrollments in the ptip and option
1472     --
1473     --
1474     CURSOR c_cvrd_opts_in_pl_typ IS
1475       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1476       FROM     ben_prtt_enrt_rslt_f pen,
1477                ben_pl_f pl,
1478                ben_oipl_f oipl,
1479                ben_elig_cvrd_dpnt_f pdp
1480       WHERE    pdp.dpnt_person_id = p_person_id
1481       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
1482       AND      pen.effective_end_date = hr_api.g_eot
1483       AND      pdp.effective_end_date = hr_api.g_eot
1484       AND      pdp.business_group_id = p_business_group_id
1485       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1486       AND      pen.business_group_id = p_business_group_id
1487       AND      l_lf_evt_ocrd_dt_1 BETWEEN pen.enrt_cvg_strt_dt
1488                    AND pen.enrt_cvg_thru_dt
1489       AND      pl.pl_id = pen.pl_id
1490       AND      pl.business_group_id = p_business_group_id
1491       AND      pl.pl_typ_id = p_pl_typ_id
1492       AND      oipl.oipl_id = pen.oipl_id
1493       AND      oipl.opt_id = p_opt_id
1494       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
1495                    AND pl.effective_end_date
1496       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
1497                    AND oipl.effective_end_date
1498       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1499       AND      pen.sspndd_flag = 'N'
1500       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1501       AND      oipl.business_group_id = p_business_group_id
1502       AND      (
1503                     (    pen.pgm_id = p_pgm_id
1504                      AND p_pgm_id IS NOT NULL)
1505                  OR (    pen.pgm_id IS NULL
1506                      AND p_pgm_id IS NULL));
1507     --
1508     --
1509     CURSOR c_state IS
1510       SELECT   loc.region_2
1511       FROM     hr_locations_all loc, per_all_assignments_f asg
1512       WHERE    loc.location_id = asg.location_id
1513       AND      asg.person_id = p_person_id
1514       and      asg.assignment_type <> 'C'
1515       AND      asg.primary_flag = 'Y'
1516       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
1517                    AND asg.effective_end_date
1518       AND      asg.business_group_id = p_business_group_id;
1519     --
1520     l_state                    c_state%ROWTYPE;
1521     --
1522     --
1523     CURSOR c_asg IS
1524       SELECT   asg.assignment_id,
1525                asg.organization_id
1526       FROM     per_all_assignments_f asg
1527       WHERE    person_id = p_person_id
1528       and      asg.assignment_type <> 'C'
1529       AND      asg.primary_flag = decode(p_run_mode, 'I',asg.primary_flag, 'Y')   -- iRec
1530       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
1531                    AND asg.effective_end_date;
1532     --
1533     l_asg                      c_asg%ROWTYPE;
1534     -- Gets the enrolment information for this plan
1535     --
1536     --
1537     CURSOR c_plan_enrolment_info IS
1538       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1539       FROM     ben_prtt_enrt_rslt_f pen
1540       WHERE    pen.person_id = p_person_id
1541       AND      pen.business_group_id = p_business_group_id
1542       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1543 --      AND      pen.sspndd_flag = 'N' --CFW
1544       AND      (pen.sspndd_flag = 'N' --CFW
1545                  OR (pen.sspndd_flag = 'Y' and
1546                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1547                     )
1548                )
1549       AND      pen.effective_end_date = hr_api.g_eot
1550       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1551       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1552       AND      p_pl_id = pen.pl_id
1553       AND      (
1554                     (    pen.pgm_id = p_pgm_id
1555                      AND p_pgm_id IS NOT NULL)
1556                  OR (    pen.pgm_id IS NULL
1557                      AND p_pgm_id IS NULL));
1558 
1559     -- added for level
1560 
1561      CURSOR c_plip_enrolment_info IS
1562       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1563       FROM     ben_prtt_enrt_rslt_f pen
1564       WHERE    pen.person_id = p_person_id
1565       AND      pen.business_group_id = p_business_group_id
1566       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1567 --      AND      pen.sspndd_flag = 'N' --CFW
1568       AND      (pen.sspndd_flag = 'N' --CFW
1569                  OR (pen.sspndd_flag = 'Y' and
1570                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1571                     )
1572                )
1573       AND      pen.effective_end_date = hr_api.g_eot
1574       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1575       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1576       AND      p_pl_id = pen.pl_id
1577       AND      pen.pgm_id = p_pgm_id ;
1578 
1579     --
1580 
1581      CURSOR c_ptip_2_enrolment_info IS
1582       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1583       FROM     ben_prtt_enrt_rslt_f pen
1584       WHERE    pen.person_id = p_person_id
1585       AND      pen.business_group_id = p_business_group_id
1586       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1587       AND      pen.effective_end_date = hr_api.g_eot
1588       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1589       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1590       AND      g_ptip_id   = pen.ptip_id
1591       AND      pen.pgm_id = p_pgm_id ;
1592 
1593    ---
1594 
1595      CURSOR c_pgm_enrolment_info IS
1596       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1597       FROM     ben_prtt_enrt_rslt_f pen
1598       WHERE    pen.person_id = p_person_id
1599       AND      pen.business_group_id = p_business_group_id
1600       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1601       AND      pen.effective_end_date = hr_api.g_eot
1602       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1603       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1604       AND      pen.pgm_id = p_pgm_id ;
1605 
1606 
1607     -- Bug#2108168 - Check for current enrollment in a waive plan
1608     CURSOR c_ptip_waive_enrolment_info IS
1609       SELECT   pen.enrt_cvg_strt_dt
1610       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pln
1611       WHERE    pen.person_id = p_person_id
1612       AND      pen.business_group_id = p_business_group_id
1613       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1614       AND      pen.sspndd_flag = 'N'
1615       AND      pen.effective_end_date = hr_api.g_eot
1616       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1617       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1618       AND      g_ptip_id = pen.ptip_id
1619       AND      pln.pl_id = pen.pl_id
1620       AND      pln.invk_dcln_prtn_pl_flag = 'Y'
1621       AND      l_lf_evt_ocrd_dt BETWEEN pln.effective_start_date
1622                    AND pln.effective_end_date;
1623 
1624     -- Gets the enrolment information for this plan
1625     --
1626     --
1627     CURSOR c_plan_cvg_info IS
1628       SELECT   pen.enrt_cvg_strt_dt enrt_cvg_strt_dt
1629       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
1630       WHERE    pdp.dpnt_person_id = p_person_id
1631       AND      pen.effective_end_date = hr_api.g_eot
1632       AND      pdp.effective_end_date = hr_api.g_eot
1633       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
1634       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1635       AND      pen.business_group_id = p_business_group_id
1636       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1637       -- AND      pen.sspndd_flag = 'N'
1638       AND      (pen.sspndd_flag = 'N' --CFW
1639                  OR (pen.sspndd_flag = 'Y' and
1640                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1641                     )
1642                )
1643       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1644       AND      pen.enrt_cvg_thru_dt < pen.effective_end_date
1645       AND      p_pl_id = pen.pl_id
1646       AND      (
1647                     (    pen.pgm_id = p_pgm_id
1648                      AND p_pgm_id IS NOT NULL)
1649                  OR (    pen.pgm_id IS NULL
1650                      AND p_pgm_id IS NULL));
1651     --
1652     -- Gets the enrolment information for the ptip in which the plan belongs
1653     --
1654     CURSOR c_ptip_enrolment_info IS
1655       SELECT   pen.pl_id,
1656                pen.oipl_id,
1657                plip.plip_id
1658       FROM     ben_prtt_enrt_rslt_f pen, ben_plip_f plip
1659       WHERE    pen.person_id = p_person_id
1660       AND      pen.business_group_id = p_business_group_id
1661       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
1662       --AND      pen.sspndd_flag = 'N'
1663       AND      (pen.sspndd_flag = 'N' --CFW
1664                  OR (pen.sspndd_flag = 'Y' and
1665                      pen.enrt_cvg_thru_dt = hr_api.g_eot
1666                     )
1667                )
1668       AND      pen.effective_end_date = hr_api.g_eot
1669       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
1670       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
1671       AND      g_ptip_id = pen.ptip_id
1672       AND      plip.pgm_id = pen.pgm_id
1673       AND      plip.pl_id = pen.pl_id
1674       AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
1675                    AND plip.effective_end_date;
1676     --
1677      CURSOR c_plip_info IS
1678       SELECT   bpf.plip_id
1679       FROM     ben_plip_f bpf
1680       WHERE    bpf.pl_id = p_pl_id
1681       AND      bpf.pgm_id = p_pgm_id
1682       AND      bpf.business_group_id = p_business_group_id
1683       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
1684                    AND bpf.effective_end_date;
1685 
1686     --
1687     l_plip_id                  number ;
1688     l_enrolled_ptip            c_ptip_enrolment_info%ROWTYPE;
1689     --
1690     /*
1691     cursor c_prclds_flag
1692     is
1693     select
1694            nvl(oipl.crnt_enrt_prclds_chg_flag,
1695              nvl(pl_nip.crnt_enrt_prclds_chg_flag,
1696                nvl(plip.crnt_enrt_prclds_chg_flag,
1697                  nvl(ptip.crnt_enrt_prclds_chg_flag,
1698                      pgm.crnt_enrt_prclds_chg_flag)))) crnt_enrt_prclds_chg_flag
1699     from   dual,
1700            ben_ler_chg_pl_nip_enrt_f pl_nip,
1701            ben_ler_chg_pgm_enrt_f    pgm,
1702            ben_ler_chg_ptip_enrt_f   ptip,
1703            ben_ler_chg_plip_enrt_f   plip,
1704            ben_ler_chg_oipl_enrt_f   oipl
1705     where
1706            pl_nip.pl_id(+)=l_enrolled_ptip.pl_id and
1707            pl_nip.business_group_id(+)=p_business_group_id and
1708            pl_nip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1709            l_lf_evt_ocrd_dt between
1710              pl_nip.effective_start_date(+) and pl_nip.effective_end_date(+) and
1711            ptip.ptip_id(+)=g_ptip_id and
1712            ptip.business_group_id(+)=p_business_group_id and
1713            ptip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1714            l_lf_evt_ocrd_dt between
1715              ptip.effective_start_date(+) and ptip.effective_end_date(+) and
1716            pgm.pgm_id(+)=p_pgm_id and
1717            pgm.business_group_id(+)=p_business_group_id and
1718            pgm.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1719            l_lf_evt_ocrd_dt between
1720              pgm.effective_start_date(+) and pgm.effective_end_date(+) and
1721            plip.plip_id(+)=l_enrolled_ptip.plip_id and
1722            plip.business_group_id(+)=p_business_group_id and
1723            plip.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1724            l_lf_evt_ocrd_dt between
1725              plip.effective_start_date(+) and plip.effective_end_date(+) and
1726            oipl.oipl_id(+) = l_enrolled_ptip.oipl_id and
1727            oipl.business_group_id(+) = p_business_group_id and
1728            oipl.ler_id(+)=decode(dual.dummy,dual.dummy,p_ler_id,dual.dummy) and
1729            l_lf_evt_ocrd_dt between
1730              oipl.effective_start_date(+) and oipl.effective_end_date(+);
1731     */
1732     l_ptip_prclds_flag         VARCHAR2(30);
1733     l_enrt_cd_level            VARCHAR2(30);
1734     l_enrt_cvg_date            date ;
1735 
1736     --- determine the current enrollment according to the level
1737 
1738 
1739   --
1740   BEGIN
1741   g_debug := hr_utility.debug_enabled;
1742   if g_debug then
1743     hr_utility.set_location('Entering: ' || l_proc, 10);
1744   end if;
1745 --  hr_utility.set_location('enrt_mthd_cd='||p_enrt_mthd_cd,11);
1746 --  hr_utility.set_location('auto_enrt_mthd_rl='||p_auto_enrt_mthd_rl,13);
1747 --  hr_utility.set_location('enrt_cd='||p_enrt_cd,12);
1748   --
1749   --  Get program record.
1750   --
1751     IF p_pgm_id IS NOT NULL THEN
1752       ben_comp_object.get_object(p_pgm_id => p_pgm_id, p_rec => l_pgm_rec);
1753       if g_debug then
1754       hr_utility.set_location('Done PGM NN: ' || l_proc, 10);
1755       end if;
1756     END IF;
1757 --
1758 -- Check the tco_chg_enrt_cd if this comp object can be changed
1759 --
1760 -- Note: "enrolled in option" only includes option within plans of
1761 --       the same plan type.
1762 --
1763 --              | Is enrolled | Is Not         | Is enrolled | Is not enrolled
1764 -- Level TCO_CD | in plan     | enrolled in pl | in option   | in option
1765 -- ----- -------+-------------+----------------+-------------+----------------
1766 -- oipl  CPOO   | Y           | Y              | Y           | Y
1767 -- oipl  CPNO   | n/a         | n/a            | Y           | N
1768 -- oipl  CONP   | Y           | N              | n/a         | n/a
1769 -- ----- -------+-------------+----------------+-------------+----------------
1770 -- pl    CPOO   | Y           | Y              | Y           | Y
1771 -- pl    CPNO   | Y           | Y              | Y           | Y
1772 -- pl    CONP   | Y           | N              | n/a         | n/a
1773 --
1774 /* -- 4031733 - Cursor c_state populates l_state variable which is no longer
1775    -- used in the package. Cursor can be commented
1776 
1777     IF p_person_id IS NOT NULL THEN
1778       OPEN c_state;
1779       FETCH c_state INTO l_state;
1780       CLOSE c_state;
1781       hr_utility.set_location('close c_state: ' || l_proc, 9999);
1782       --IF l_state.region_2 IS NOT NULL THEN
1783       --  l_jurisdiction_code :=
1784       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
1785       --END IF;
1786     END IF;
1787 */
1788 
1789     OPEN c_asg;
1790     FETCH c_asg INTO l_asg;
1791     IF c_asg%NOTFOUND THEN
1792       CLOSE c_asg;
1793       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
1794       fnd_message.set_token('PROC', l_proc);
1795       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
1796       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
1797       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
1798       RAISE ben_manage_life_events.g_record_error;
1799     END IF;
1800     CLOSE c_asg;
1801     if g_debug then
1802     hr_utility.set_location('close c_asg: ' || l_proc, 10);
1803     end if;
1804     IF p_oipl_id IS NOT NULL THEN
1805       IF p_tco_chg_enrt_cd = 'CONP' THEN
1806         --
1807         OPEN c_plan_enrolment_info;
1808         FETCH c_plan_enrolment_info INTO l_crnt_pl_enrt_cvg_strt_dt;
1809         IF c_plan_enrolment_info%NOTFOUND THEN
1810           --
1811           open c_ptip_waive_enrolment_info;
1812           fetch c_ptip_waive_enrolment_info into l_crnt_pl_enrt_cvg_strt_dt;
1813           if c_ptip_waive_enrolment_info%NOTFOUND then
1814             IF p_pgm_id IS NOT NULL THEN
1815                 --
1816                 --  When processing the COBRA, also check the elig_cvrd_dpnt
1817                 --  table as dependents can make independent elections.
1818                 --
1819               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
1820                 OPEN c_plan_cvg_info;
1821                 FETCH c_plan_cvg_info INTO l_crnt_pl_enrt_cvg_strt_dt;
1822                 CLOSE c_plan_cvg_info;
1823               END IF;
1824             END IF;
1825             --
1826           end if;
1827           close c_ptip_waive_enrolment_info;
1828         END IF;
1829         --
1830         CLOSE c_plan_enrolment_info;
1831       --
1832       ELSIF p_tco_chg_enrt_cd = 'CPNO' THEN
1833         --
1834 	if g_debug then
1835         hr_utility.set_location('pl_typ_id=' || p_pl_typ_id, 1963);
1836         hr_utility.set_location('opt_id=' || p_opt_id, 1963);
1837         hr_utility.set_location(
1838           'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1839           1963);
1840         end if;
1841         OPEN c_enrolled_opts_in_pl_typ;
1842         FETCH c_enrolled_opts_in_pl_typ INTO l_crnt_opt_cvg_strt_dt;
1843 	if g_debug then
1844         hr_utility.set_location(
1845           'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1846           1963);
1847         end if;
1848         IF c_enrolled_opts_in_pl_typ%NOTFOUND THEN
1849           IF p_pgm_id IS NOT NULL THEN
1850             --
1851             --  When processing the COBRA, also check the elig_cvrd_dpnt
1852             --  table as dependents can make independent elections.
1853             --
1854             IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
1855               OPEN c_cvrd_opts_in_pl_typ;
1856               FETCH c_cvrd_opts_in_pl_typ INTO l_crnt_opt_cvg_strt_dt;
1857 	      if g_debug then
1858               hr_utility.set_location(
1859                 'crnt_opt_cvg_strt_dt=' || l_crnt_opt_cvg_strt_dt,
1860                 1963);
1861               end if;
1862               CLOSE c_cvrd_opts_in_pl_typ;
1863             END IF;
1864           END IF;
1865         END IF;
1866         CLOSE c_enrolled_opts_in_pl_typ;
1867       END IF;
1868     --
1869     END IF;
1870     if g_debug then
1871     hr_utility.set_location('Done p_oipl NN ' || l_proc, 10);
1872     end if;
1873     --
1874     IF NOT (
1875                 (                                                  -- eval oipl
1876                       p_oipl_id IS NOT NULL
1877                   AND (                         -- can change plan or option or
1878                            p_tco_chg_enrt_cd = 'CPOO'
1879                         OR (           -- change plan only and enrolled in oipl
1880                                  p_tco_chg_enrt_cd = 'CPNO'
1881                              AND l_crnt_opt_cvg_strt_dt IS NOT NULL)
1882                         OR (         -- change option only and enrolled in plan
1883                                  p_tco_chg_enrt_cd = 'CONP'
1884                              AND l_crnt_pl_enrt_cvg_strt_dt IS NOT NULL)))
1885              OR (                                                    -- eval pl
1886                       p_oipl_id IS NULL
1887                   AND (                            -- change plan or/not option
1888                            p_tco_chg_enrt_cd IN ('CPOO', 'CPNO')
1889                         OR (         -- change option only and enrolled in plan
1890                                  p_tco_chg_enrt_cd = 'CONP'
1891                              AND (
1892                                       p_crnt_enrt_cvg_strt_dt IS NOT NULL
1893                                    OR p_dpnt_cvrd_flag = 'Y'))))) THEN
1894       --
1895       p_electable_flag :=  'N';
1896       --
1897       if g_debug then
1898       hr_utility.set_location(' Leaving:' || l_proc, 5);
1899       end if;
1900       --
1901       RETURN;
1902     --
1903     END IF;
1904     --
1905     -- If stl_elig_cant_chg_flag is set to Y and
1906     -- previous_eligibility is true, Done, not electable.
1907     --
1908     IF (    p_stl_elig_cant_chg_flag = 'Y'
1909         AND p_previous_eligibility = 'Y') THEN
1910       --
1911       p_electable_flag :=  'N';
1912       --
1913       if g_debug then
1914       hr_utility.set_location(' Leaving:' || l_proc, 10);
1915       end if;
1916       --
1917       RETURN;
1918     --
1919     END IF;
1920     -- if P_ENRT_PRCLDS_CHG_FLAG is true and person is
1921     -- currently enrolled, this choice is NOT electable.  DONE.
1922     -- bug 5216 - check across ptip for enrollment.  If enrolled
1923     -- in ptip then use this flag from that comp object.
1924     -- if set to Y then nothing in ptip is electable.
1925     --
1926     IF (    p_enrt_prclds_chg_flag = 'Y'
1927         AND p_crnt_enrt_cvg_strt_dt IS NOT NULL) THEN
1928       --
1929       p_electable_flag :=  'N';
1930       --
1931       if g_debug then
1932       hr_utility.set_location(' Returning:' || l_proc, 15);
1933       end if;
1934       --
1935       RETURN;
1936     --
1937     ELSE
1938       -- get the plip id from the pgm and pl not from the enrollment data
1939       open c_plip_info ;
1940       fetch c_plip_info into l_plip_id ;
1941       close c_plip_info ;
1942 
1943        determine_ben_settings(
1944           p_pl_id                     => p_pl_id,         --l_enrolled_ptip.pl_id,
1945           p_ler_id                    => p_ler_id,
1946           p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
1947           p_ptip_id                   => g_ptip_id,
1948           p_pgm_id                    => p_pgm_id,
1949           p_plip_id                   => l_plip_id ,     --l_enrolled_ptip.plip_id,
1950           p_oipl_id                   => p_oipl_id ,     --l_enrolled_ptip.oipl_id,
1951           p_just_prclds_chg_flag      => TRUE,
1952           p_enrt_cd                   => l_enrt_cd,
1953           p_enrt_rl                   => l_enrt_rl,
1954           p_auto_enrt_mthd_rl         => l_auto_enrt_mthd_rl,
1955           p_crnt_enrt_prclds_chg_flag => l_ptip_prclds_flag,
1956           p_dflt_flag                 => l_dflt_flag,
1957           p_enrt_mthd_cd              => l_enrt_mthd_cd,
1958           p_stl_elig_cant_chg_flag    => l_stl_elig_cant_chg_flag,
1959           p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
1960           p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
1961           p_ler_chg_found_flag        => l_ler_chg_found_flag,
1962           p_enrt_cd_level             => l_enrt_cd_level );
1963 
1964           if g_debug then
1965           hr_utility.set_location( 'l_enrt_cd_level ' || l_enrt_cd_level , 99 );
1966           hr_utility.set_location( 'enrt_cd ' || p_enrt_cd  , 99 );
1967           end if;
1968           --- check the level of enrollment code and intialise the coverage date
1969           if  l_enrt_cd_level = 'OIPL'   then
1970               l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
1971           elsif  l_enrt_cd_level = 'PL'  then
1972               if p_oipl_id is null then
1973                  l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
1974               else
1975                  OPEN c_plan_enrolment_info;
1976                  FETCH c_plan_enrolment_info INTO l_enrt_cvg_date;
1977                  close  c_plan_enrolment_info ;
1978               end if ;
1979           elsif  l_enrt_cd_level = 'PLIP'  then
1980                  OPEN  c_plip_enrolment_info;
1981                  FETCH c_plip_enrolment_info INTO l_enrt_cvg_date;
1982                  close c_plip_enrolment_info ;
1983           elsif  l_enrt_cd_level = 'PTIP'  then
1984                  OPEN  c_ptip_2_enrolment_info;
1985                  FETCH c_ptip_2_enrolment_info INTO l_enrt_cvg_date;
1986                  close c_ptip_2_enrolment_info ;
1987           elsif  l_enrt_cd_level = 'PGM'  then
1988                  OPEN  c_pgm_enrolment_info;
1989                  FETCH c_pgm_enrolment_info INTO l_enrt_cvg_date;
1990                  close c_pgm_enrolment_info ;
1991           else
1992                 l_enrt_cvg_date := p_crnt_enrt_cvg_strt_dt ;
1993           end if ;
1994 	  if g_debug then
1995           hr_utility.set_location( 'l_enrt_cvg_date ' || l_enrt_cvg_date , 99 );
1996 	  end if;
1997           ----
1998 
1999 
2000       -- check if enrolled in ptip
2001       if g_debug then
2002       hr_utility.set_location(' Op c_ptip_enr_inf'||l_proc, 15);
2003       end if;
2004       OPEN c_ptip_enrolment_info;
2005       FETCH c_ptip_enrolment_info INTO l_enrolled_ptip;
2006       if g_debug then
2007       hr_utility.set_location(' Dn Fet c_ptip_enr_inf'||l_proc, 15);
2008       end if;
2009       IF c_ptip_enrolment_info%FOUND THEN
2010       if g_debug then
2011          hr_utility.set_location('CHKPTIPENRT found', 10);
2012       end if;
2013          IF l_ptip_prclds_flag = 'Y' THEN
2014 	 if g_debug then
2015             hr_utility.set_location('CHKPTIPENRT prclds', 10);
2016          end if;
2017             p_electable_flag :=  'N';
2018             --
2019 	    if g_debug then
2020             hr_utility.set_location(' Leaving:' || l_proc, 19);
2021 	    end if;
2022             --
2023             RETURN;
2024             --
2025          END IF;
2026       END IF;
2027       CLOSE c_ptip_enrolment_info;
2028     END IF;
2029     -- If the enrt_cd is rule
2030     if g_debug then
2031     hr_utility.set_location('EC=RL: ' || l_proc, 10);
2032     end if;
2033     IF (p_enrt_cd = 'RL') THEN
2034       -- 5092244 : commented the following code
2035      /* if p_update_def_elct_flag is not null then -- don't reevaluate the rule again
2036         --
2037         p_electable_flag := p_update_def_elct_flag;
2038         RETURN;
2039         --
2040       end if;*/
2041       l_result_flag :=
2042        execute_enrt_rule(
2043          p_opt_id            => p_opt_id,
2044          p_pl_id             => p_pl_id,
2045          p_pgm_id            => p_pgm_id,
2046          p_rule_id           => p_enrt_rl,
2047          p_ler_id            => p_ler_id,
2048          p_pl_typ_id         => p_pl_typ_id,
2049          p_business_group_id => p_business_group_id,
2050          p_effective_date    => p_effective_date,
2051          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
2052          p_elig_per_id       => p_elig_per_id,
2053          p_assignment_id     => p_assignment_id,
2054          p_organization_id   => l_asg.organization_id,
2055          p_jurisdiction_code => l_jurisdiction_code,
2056 	 p_person_id         => p_person_id              -- Bug 5331889
2057 	 );
2058       --
2059       IF (l_result_flag = 'N') THEN
2060         --
2061         p_electable_flag :=  'N';
2062         --
2063 	if g_debug then
2064         hr_utility.set_location(' Leaving:' || l_proc, 20);
2065 	end if;
2066         --
2067         RETURN;
2068       --
2069       ELSIF l_result_flag = 'L' THEN
2070         --
2071         -- L will be used for Lose only functionality.
2072         --
2073         p_electable_flag :=  'L';
2074 	if g_debug then
2075         hr_utility.set_location(' Leaving:' || l_proc, 21);
2076 	end if;
2077         --
2078         RETURN;
2079       --
2080       END IF;
2081     --
2082     ELSIF    p_enrt_cd = 'CLONN'
2083           OR (
2084                    p_enrt_cd in ('CLNCC','CNNA')
2085                AND  l_enrt_cvg_date IS NOT NULL
2086                AND p_dpnt_cvrd_flag = 'N') THEN
2087       --
2088       -- Just return L.  This will trigger
2089       -- call to ben_newly_ineligible.
2090       -- which will either do nothing or deenroll
2091       --
2092       p_electable_flag :=  'L';
2093       --
2094       RETURN;
2095     --
2096     ELSE                                                    -- p_enrt_cd = 'RL'
2097     if g_debug then
2098       hr_utility.set_location('Else EC=RL: ' || l_proc, 10);
2099     end if;
2100 -- If the combination of enrt_cd and eligibility status is YES in the
2101 -- following matrix then the choice is electable
2102 -- (continue to create choice),
2103 -- else it is not electable.  (DONE).
2104 --
2105 --                   Create Choice?
2106 -- ENRT_CD     Not enrolled     Enrolled  Note
2107 -- CKNCC           YES             NO
2108 -- CCONCC          YES             YES    Duplicate with below
2109 -- CCKCNCC         YES             YES    Duplicate with above
2110 -- CCKCSNCC        YES             YES    Duplicate with above
2111 -- CLNCC           YES             NO     *Should not be eligible
2112 -- CCKCNN          NO              YES    Duplicate with below
2113 -- CCONN           NO              YES    Duplicate with above
2114 -- CKNN            NO              NO
2115 -- CLONN           NO              NO     *Should not be eligible
2116 --
2117 -- particles
2118 --
2119 -- Part   Description
2120 -- CCKC   current can keep or choose
2121 -- CCO    Same as above
2122 -- CK     current must keep
2123 -- CL     current will loose
2124 -- CLO    Same as above
2125 -- NCC    new can choose
2126 -- NN     new cannot choose
2127 --
2128       IF NOT (                               -- currently enrolled and eligible
2129                   (
2130                         (
2131                               l_enrt_cvg_date IS NOT NULL
2132                           OR p_dpnt_cvrd_flag = 'Y')
2133                     AND p_enrt_cd IN ('CCONCC', 'CCKCNN', 'CCONN', 'CCKCNCC','CCKCSNCC'))
2134                OR
2135                   -- not enrolled, but eligible
2136                   (
2137                         (
2138                                l_enrt_cvg_date IS NULL
2139                           AND p_dpnt_cvrd_flag = 'N')
2140                     AND p_enrt_cd IN ('CKNCC', 'CCONCC', 'CLNCC', 'CCKCNCC','CCKCSNCC'))) THEN
2141         --
2142         p_electable_flag :=  'N';
2143         --
2144 	if g_debug then
2145         hr_utility.set_location(' Leaving:' || l_proc, 25);
2146 	end if;
2147         --
2148         RETURN;
2149       --
2150       END IF;                                                  -- enrt_cd table
2151     --
2152     END IF;                                                     -- p_enrt_cd=RL
2153     --
2154     p_electable_flag :=  'Y';
2155     --
2156     if g_debug then
2157     hr_utility.set_location(' Leaving:' || l_proc, 30);
2158     end if;
2159     --
2160     RETURN;
2161   --
2162   exception  -- nocopy changes
2163     --
2164     when others then
2165       --
2166       p_electable_flag := null;
2167       raise;
2168       --
2169   END determine_enrolment;
2170 --
2171 -- cwb changes
2172 procedure get_cwb_manager_and_assignment
2173              (p_person_id in number,
2174               p_hrchy_to_use_cd in varchar2,
2175               p_pos_structure_version_id in number,
2176               p_effective_date in date,
2177               p_manager_id out nocopy number,
2178               p_assignment_id out nocopy number )
2179   is
2180   --
2181   --Bug 2827121 Manager can be a contingent worker also.
2182   cursor c_get_assignment is
2183     select assignment_id,
2184            position_id,
2185            supervisor_id
2186     from per_all_assignments_f
2187     where person_id = p_person_id
2188     and primary_flag = 'Y'
2189     and assignment_type in ( 'E','C' )  -- Bug 2827121
2190     and p_effective_date
2191       between effective_start_date and effective_end_date;
2192   --
2193   l_get_assignment   c_get_assignment%rowtype;
2194   --
2195   cursor c_parent_position_id (p_position_id number)
2196     is
2197     select parent_position_id
2198     from per_pos_structure_elements
2199     where subordinate_position_id = p_position_id
2200     and   pos_structure_version_id = p_pos_structure_version_id;
2201   --
2202   cursor c_manager_id (p_position_id number)
2203     is
2204     select person_id
2205     from per_all_assignments_f ass,
2206          per_assignment_status_types ast
2207     where  ass.position_id = p_position_id
2208     and    ass.primary_flag = 'Y'
2209     and ass.assignment_type in ( 'E' , 'C' ) -- Bug 2827121
2210     and p_effective_date
2211       between ass.effective_start_date and ass.effective_end_date
2212     --Bug 3044311 -- Need to verify what other system types should be considered.
2213     and ass.assignment_status_type_id = ast.assignment_status_type_id
2214     -- and ast.active_flag = 'Y'
2215     and ast.per_system_status in ('ACTIVE_ASSIGN','SUSP_ASSIGN') ;
2216     --
2217   --
2218   l_parent_position_id   number(15);
2219   l_manager_id           number(15);
2220   l_assignment_id        number(15);
2221 
2222   l_position_id          number(15);
2223 Begin
2224   --
2225   g_debug := hr_utility.debug_enabled;
2226   open c_get_assignment;
2227   fetch c_get_assignment into l_get_assignment;
2228   close c_get_assignment;
2229   --
2230   l_assignment_id := l_get_assignment.assignment_id;
2231   --
2232   if p_hrchy_to_use_cd = 'S' then
2233     l_manager_id := l_get_assignment.supervisor_id;
2234   elsif p_hrchy_to_use_cd = 'P' then
2235 
2236     -- Start Bug 2684227
2237     -- Upon a vacancy, continue to climb the position hierarchy
2238     -- until a person is found
2239 
2240     l_position_id :=  l_get_assignment.position_id;
2241 
2242     loop
2243       open c_parent_position_id(l_position_id);
2244       fetch c_parent_position_id into l_parent_position_id;
2245       exit when c_parent_position_id%notfound;
2246       close c_parent_position_id;
2247       if l_parent_position_id is not null then
2248         open c_manager_id (l_parent_position_id);
2249         fetch c_manager_id into l_manager_id;
2250         close c_manager_id;
2251         if  l_manager_id is not null then
2252           exit;
2253         end if;
2254       end if;
2255 
2256       l_position_id := l_parent_position_id;
2257     end loop;
2258 
2259     -- End Bug 2684227
2260     --
2261     --
2262     -- Bug 2230922 : If manager id not found then default to supervisor.
2263     --
2264     if l_manager_id is null then
2265        --
2266        l_manager_id := l_get_assignment.supervisor_id;
2267        --
2268     end if;
2269     --
2270  end if;
2271  --
2272  p_manager_id := l_manager_id;
2273  p_assignment_id := l_assignment_id;
2274  --
2275 exception  -- nocopy changes
2276   --
2277   when others then
2278     --
2279     p_manager_id:= null;
2280     p_assignment_id := null;
2281     raise;
2282     --
2283 end get_cwb_manager_and_assignment;
2284 -------------------------
2285 -- 2746865
2286 -- separate procedure instead of inline code
2287 procedure enrt_perd_strt_dt
2288   (p_person_id 				in 	number
2289    ,p_lf_evt_ocrd_dt 			in 	date
2290    ,p_enrt_perd_det_ovrlp_bckdt_cd 	in 	varchar2
2291    ,p_business_group_id                 in      number
2292    ,p_ler_id                            in      number
2293    ,p_effective_date                    in      date
2294    ,p_rec_enrt_perd_strt_dt 		in out 	nocopy date
2295    )
2296 IS
2297   -- local variables
2298   l_proc             varchar2 (72) := g_package || 'enrt_perd_strt_dt';
2299   l_latest_procd_dt  date;
2300   l_backed_out_date  date;
2301   l_latest_enrt_dt   date;
2302   l_lf_evt_ocrd_dt   date := NVL(p_lf_evt_ocrd_dt, p_effective_date);
2303   -- store sysdate sans the time component into a local variable for once
2304   l_sysdate          date := trunc(sysdate);
2305   -- define cursors
2306   CURSOR c_get_latest_procd_dt IS
2307     SELECT   MAX(pil.procd_dt)
2308     FROM     ben_per_in_ler pil
2309             -- CWB changes
2310             ,ben_ler_f      ler
2311     WHERE    pil.person_id = p_person_id
2312     AND      pil.ler_id    = ler.ler_id
2313     and      ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU')
2314     and      l_lf_evt_ocrd_dt between
2315              ler.effective_start_date and ler.effective_end_date
2316     AND      pil.business_group_id = p_business_group_id
2317     AND      pil.per_in_ler_stat_cd NOT IN ('BCKDT', 'VOIDD')
2318     AND      pil.procd_dt IS NOT NULL;
2319   --
2320   CURSOR c_backed_out_ler IS
2321     SELECT   MAX(pil.bckt_dt)
2322     FROM     ben_per_in_ler pil
2323             -- CWB changes
2324             ,ben_ler_f      ler
2325             ,ben_ptnl_ler_for_per  plr
2326     WHERE    pil.person_id = p_person_id
2327     AND      pil.ler_id    = ler.ler_id
2328     and      ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU')
2329     and      l_lf_evt_ocrd_dt between
2330              ler.effective_start_date and ler.effective_end_date
2331     AND      pil.business_group_id = p_business_group_id
2332     AND      pil.ler_id = p_ler_id
2333     AND      pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt
2334     AND      pil.bckt_dt IS NOT NULL
2335     and      pil.per_in_ler_stat_cd = 'BCKDT' -- 3063867
2336     and      pil.ptnl_ler_for_per_id   = plr.ptnl_ler_for_per_id  --3248770
2337     and      plr.ptnl_ler_for_per_stat_cd <> 'VOIDD' ;
2338   --
2339 
2340   -- 2746865
2341   -- cursor to select a person's maximum enrollment start date
2342   -- Changed the following cursor for bug 3137519 to exclude GSP/ABS/COMP ler types.
2343   -- Also included status no in backdt/voidd clause
2344   --bug#3697378 - discussed with Phil why we add + 1 to the latest enrollment
2345   --however he wanted this to be removed so that self service open enrollment
2346   --will not be impacted and asked find ways to show history on enrollment results later
2347   cursor c_get_latest_enrt_dt is
2348     select max(rslt.effective_start_date)
2349     from   ben_prtt_enrt_rslt_f rslt,ben_ler_f ler
2350      where  rslt.person_id = p_person_id
2351     and ler.ler_id=rslt.ler_id
2352   --  and rslt.prtt_enrt_rslt_stat_cd NOT IN ('BCKDT', 'VOIDD')
2353     and rslt.prtt_enrt_rslt_stat_cd is null
2354     and   ler.typ_cd   not in ('COMP','ABS', 'GSP', 'IREC','SCHEDDU' )
2355     and    rslt.business_group_id = p_business_group_id
2356     and rslt.enrt_cvg_thru_dt = hr_api.g_eot; -- Bug 4388226 - End-dated suspended enrl shudn't be picked up.
2357 
2358   --
2359 
2360   begin
2361 
2362   -- following are the 4 codes used for enrt. period determination
2363   -------------------------------------------------------------------------
2364   -- L_EPSD_PEPD 	- Later of Enrollment period start date and
2365   --		 	  prior event processed date
2366   -- L_EPSD_PEESD 	- Later of Enrollment period start date and
2367   --		 	  One day after prior event elections start date
2368   -- L_EPSD_PEESD_BCKDT - Later of Enrollment period start date and One
2369   --			  day after prior event elections start date and
2370   --			  current events backed out date
2371   -- L_EPSD_PEESD_SYSDT - Later of Enrollment period start date and One
2372   --			  day after prior event elections start date
2373   --			  and system date
2374   -------------------------------------------------------------------------
2375   -- if cd is L_EPSD_PEPD, use the old logic
2376   hr_utility.set_location(' Entering '||l_proc, 10);
2377   --
2378   -- remove all these debug messages
2379   hr_utility.set_location(' p_enrt_perd_det_ovrlp_bckdt_cd is  '||p_enrt_perd_det_ovrlp_bckdt_cd, 987);
2380   hr_utility.set_location(' p_person_id '||p_person_id, 10);
2381   hr_utility.set_location(' p_lf_evt_ocrd_dt '||p_lf_evt_ocrd_dt, 10);
2382   hr_utility.set_location(' p_ler_id '||p_ler_id, 10);
2383   hr_utility.set_location(' p_effective_date '||p_effective_date, 10);
2384   hr_utility.set_location(' p_rec_enrt_perd_strt_dt '||p_rec_enrt_perd_strt_dt, 10);
2385   --
2386 
2387   IF nvl(p_enrt_perd_det_ovrlp_bckdt_cd, 'L_EPSD_PEPD') = 'L_EPSD_PEPD' THEN
2388     --
2389     hr_utility.set_location(' L_EPSD_PEPD', 987);
2390     OPEN c_get_latest_procd_dt;
2391     FETCH c_get_latest_procd_dt INTO l_latest_procd_dt;
2392     -- new epsd is greater of epsd or latest_procd_dt
2393     -- IF c_get_latest_procd_dt%FOUND THEN
2394     IF l_latest_procd_dt IS NOT NULL THEN
2395       hr_utility.set_location(' c_get_latest_procd_dt%found', 987);
2396       hr_utility.set_location('l_latest_procd_dt is '||l_latest_procd_dt, 987);
2397       -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
2398       IF p_rec_enrt_perd_strt_dt < l_latest_procd_dt THEN
2399         hr_utility.set_location('l_latest_procd_dt made enrt strt dt ', 987);
2400         -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
2401         p_rec_enrt_perd_strt_dt :=  l_latest_procd_dt;
2402         -- if the enrollment  exist for the previous LE
2403         -- start the window latest_procd_dt + 1
2404         -- or the previous enrollment will be updated in correction mode
2405         -- and backout of this LE will remove the previous LE results
2406         --the  changes are backedout  3086161
2407         --
2408         --Bugs 3972973 and 3978745 fixes.
2409         --If the enrollment starts after the processed date we need to consider the
2410         --latest enrollment date.
2411         --
2412       End IF;
2413       --bug#4478186 - enrl start date should always be equal or greater to latest
2414       --enrt dt
2415       OPEN c_get_latest_enrt_dt;
2416       FETCH c_get_latest_enrt_dt into l_latest_enrt_dt;
2417       close c_get_latest_enrt_dt ;
2418       --
2419       if l_latest_enrt_dt is not null and  l_latest_enrt_dt > p_rec_enrt_perd_strt_dt then
2420          p_rec_enrt_perd_strt_dt := l_latest_enrt_dt ;
2421       end if ;
2422         --
2423     END IF;
2424     CLOSE c_get_latest_procd_dt;
2425     -- 4 is new epsd <= p_lf_evt_ocrd_dt?
2426     IF p_rec_enrt_perd_strt_dt <= p_lf_evt_ocrd_dt THEN
2427       -- 5 is there a backed out le for the current ler and ...
2428       OPEN c_backed_out_ler;
2429       FETCH c_backed_out_ler INTO l_backed_out_date;
2430       --IF c_backed_out_ler%FOUND THEN
2431       IF l_backed_out_date is NOT NULL THEN
2432         hr_utility.set_location(' c_backed_out_ler%found', 987);
2433         hr_utility.set_location('l_backed_out_date is '||l_backed_out_date, 987);
2434         -- 5a ... and is the backed-out date > than the new epsd?
2435         IF l_backed_out_date > p_rec_enrt_perd_strt_dt THEN
2436           hr_utility.set_location('l_backed_out_date made enrt strt dt ', 987);
2437           -- 6 it is the new epsd.
2438           p_rec_enrt_perd_strt_dt :=  l_backed_out_date;
2439         END IF;
2440       END IF;
2441       CLOSE c_backed_out_ler;
2442     END IF;
2443     -- 2746865
2444     -- if cd is L_EPSD_PEESD%, use the new logic
2445   ELSIF p_enrt_perd_det_ovrlp_bckdt_cd like  'L_EPSD_PEESD%' THEN
2446     hr_utility.set_location('  L_EPSD_PEESD%', 987);
2447     -- get the person's latest enrollment start date +1
2448     OPEN c_get_latest_enrt_dt;
2449       FETCH c_get_latest_enrt_dt into l_latest_enrt_dt;
2450       -- IF c_get_latest_enrt_dt%FOUND THEN --changed as its always found
2451       IF l_latest_enrt_dt is not null THEN
2452         hr_utility.set_location(' c_get_latest_enrt_dt%FOUND', 987);
2453         hr_utility.set_location('l_latest_enrt_dt is '||l_latest_enrt_dt, 987);
2454         -- if latest enrt dt is greater than epsd, make it the epsd
2455         IF l_latest_enrt_dt > p_rec_enrt_perd_strt_dt THEN
2456           p_rec_enrt_perd_strt_dt := l_latest_enrt_dt;
2457           hr_utility.set_location('l_latest_enrt_dt substituted', 987);
2458         END IF;
2459       END IF;
2460       CLOSE c_get_latest_enrt_dt;
2461       -- cd is 2 find the bckdt out dt
2462       IF p_enrt_perd_det_ovrlp_bckdt_cd = 'L_EPSD_PEESD_BCKDT' THEN
2463         hr_utility.set_location('L_EPSD_PEESD_BCKDT entered', 987);
2464         -- get the backed out date
2465         OPEN c_backed_out_ler;
2466         FETCH c_backed_out_ler INTO l_backed_out_date;
2467         hr_utility.set_location('l_backed_out_date is '||l_backed_out_date, 987);
2468         --IF c_backed_out_ler%FOUND THEN -- changed as its of no use
2469         IF l_backed_out_date is not null THEN
2470           hr_utility.set_location('bckdt%found', 987);
2471           -- if bckdt out dt is greater than epsd, make it the epsd
2472           IF l_backed_out_date > p_rec_enrt_perd_strt_dt THEN
2473             p_rec_enrt_perd_strt_dt := l_backed_out_date;
2474             hr_utility.set_location('l_backed_out_date substituted', 987);
2475           END IF;
2476         END IF;
2477         CLOSE c_backed_out_ler;
2478       -- if cd is 4, compare epsd with sysdate
2479       ELSIF p_enrt_perd_det_ovrlp_bckdt_cd = 'L_EPSD_PEESD_SYSDT' THEN
2480         hr_utility.set_location('L_EPSD_PEESD_SYSDT entered', 987);
2481         -- if sysdate is lis greater than epsd, make it the epsd
2482         IF l_sysdate > p_rec_enrt_perd_strt_dt THEN
2483           p_rec_enrt_perd_strt_dt := l_sysdate;
2484           hr_utility.set_location('sysdate substituted', 987);
2485         END IF;
2486       END IF;
2487     -- end 2746865
2488   END IF;
2489   end; --procedure
2490 --
2491 -------------------------
2492 
2493 procedure enrolment_requirements
2494   (p_comp_obj_tree_row      in     ben_manage_life_events.g_cache_proc_objects_rec
2495   ,p_run_mode               in     varchar2
2496   ,p_business_group_id      in     number
2497   ,p_effective_date         in     date
2498   ,p_lf_evt_ocrd_dt         in     date default null
2499   ,p_ler_id                 in     number
2500   ,p_per_in_ler_id          in     number
2501   ,p_person_id              in     number
2502   ,p_pl_id                  in     number
2503   ,p_pgm_id                 in     number default null
2504   ,p_oipl_id                in     number default null
2505   ,p_create_anyhow_flag     in     varchar2 default 'N'
2506   -- 5422 : PB ,p_popl_enrt_typ_cycl_id  in     number default null
2507   --
2508   ,p_asnd_lf_evt_dt         in     date default null
2509   ,p_electable_flag            out nocopy varchar2
2510   ,p_elig_per_elctbl_chc_id    out nocopy number
2511   )
2512 IS
2513   --
2514   l_currpep_dets     ben_pep_cache.g_pep_rec;
2515   l_currepe_dets ben_epe_cache.g_pilepe_inst_row;
2516   --
2517   l_prevepo_rec      ben_derive_part_and_rate_facts.g_cache_structure;
2518   l_prevpep_rec      ben_derive_part_and_rate_facts.g_cache_structure;
2519   --
2520     l_dummy                        varchar2(30);
2521     l_dummy_rt_strt_dt             DATE;
2522     l_dummy_rt_strt_dt_cd          VARCHAR2(30);
2523     l_dummy_rt_strt_dt_rl          NUMBER;
2524     l_dummy_enrt_cvg_end_dt        DATE;
2525     l_dummy_enrt_cvg_end_dt_cd     VARCHAR2(30);
2526     l_dummy_enrt_cvg_end_dt_rl     NUMBER;
2527     l_dummy_rt_end_dt              DATE;
2528     l_dummy_rt_end_dt_cd           VARCHAR2(30);
2529     l_dummy_rt_end_dt_rl           NUMBER;
2530     l_dummy_enrt_cvg_strt_dt_cd    VARCHAR2(30);
2531     l_dummy_enrt_cvg_strt_dt_rl    NUMBER;
2532 
2533 
2534 --l_overide_enrt_cvg_strt_dt_cd varchar2(30);
2535 --l_overide_enrt_cvg_strt_dt_rl number;
2536     l_pl_id                        NUMBER;
2537     l_prereq_electable_flag        VARCHAR2(30);
2538     l_oipl_name                    ben_opt_f.name%TYPE;
2539     l_pl_name                      ben_pl_f.name%TYPE;
2540     l_ler_name                     ben_ler_f.name%TYPE;
2541     l_must_enrl_anthr_pl_id        NUMBER;
2542     l_auto_enrt_flag               VARCHAR2(30)                 := 'N';
2543     l_rec_auto_enrt_flag           VARCHAR2(30)                 := 'N';
2544     l_comp_lvl_cd                  VARCHAR2(30);
2545     l_prtt_enrt_rslt_id            NUMBER;
2546     l_prtt_enrt_rslt_id_2          NUMBER;
2547     l_object_version_number        NUMBER;
2548     l_popl_yr_perd_id              NUMBER;
2549     l_yr_perd_strt_date            DATE;
2550     l_yr_perd_end_date             DATE;
2551     l_popl_yr_perd_ordr_num        NUMBER;
2552     l_yr_perd_id                   NUMBER;
2553     l_elig_per_elctbl_chc_id       NUMBER;
2554     l_tco_chg_enrt_cd              VARCHAR2(30)                 := 'CPOO';
2555     l_opt_id                       NUMBER;
2556     l_ptip_id                      NUMBER;
2557     l_ptip_ordr_num                NUMBER;
2558     l_plip_ordr_num                NUMBER;
2559     l_ptip_esd                     DATE;
2560     l_ptip_eed                     DATE;
2561     l_per_in_ler_id                NUMBER;
2562     l_alws_unrstrctd_enrt_flag     VARCHAR2(30)                 := 'N';
2563     l_plip_id                      NUMBER;
2564     l_plip_esd                     DATE;
2565     l_plip_eed                     DATE;
2566     l_plip_dflt_flag               VARCHAR2(30);
2567     l_plip_enrt_cd                 VARCHAR2(30);
2568     l_plip_enrt_rl                 NUMBER;
2569     l_oipl_dflt_flag               VARCHAR2(30);
2570     l_elig_per_id                  NUMBER;
2571     l_current_eligibility          VARCHAR2(30);
2572     l_prtn_strt_dt                 DATE;
2573     l_previous_eligibility         VARCHAR2(30);
2574     l_pl_typ_id                    NUMBER;
2575     l_proc                         VARCHAR2(72)
2576                                        := g_package ||
2577                                             '.enrolment_requirements';
2578     l_pl_enrt_cd                   VARCHAR2(30);
2579 --L_PL_ENRT_CVG_STRT_DT_CD      varchar2(30);
2580 --L_PL_ENRT_CVG_STRT_DT_RL      number;
2581     l_pl_enrt_mthd_cd              VARCHAR2(30);
2582     l_plip_enrt_mthd_cd            VARCHAR2(30);
2583     l_crnt_enrt_cvg_strt_dt        DATE;
2584     l_crnt_enrt_cvg_thru_dt        DATE;    --BUG 6519487 fix
2585     l_mndtry_flag                  VARCHAR2(30)                 := 'N';
2586     l_mndtry_rl                    NUMBER;
2587     l_choice_exists_flag           VARCHAR2(30);
2588     l_lf_evt_ocrd_dt_fetch         DATE;
2589     l_rqd_perd_enrt_nenrt_uom      VARCHAR2(30);
2590     l_ler_typ_cd                   VARCHAR2(30);
2591     l_ler_chg_found_flag           VARCHAR2(30);
2592     l_ler_chg_oipl_found_flag      VARCHAR2(30);
2593     l_ler_enrt_prclds_chg_flag     VARCHAR2(30);
2594     l_ler_dflt_flag                VARCHAR2(30);
2595     l_ler_enrt_cd                  VARCHAR2(30);
2596     l_ple_dys_aftr_end_to_dflt_num NUMBER;
2597     l_perd_for_plan_found          VARCHAR2(30)                 := 'N';
2598     l_rqd_perd_enrt_nenrt_val      NUMBER;
2599     l_rqd_perd_enrt_nenrt_rl       NUMBER;
2600     l_ler_enrt_mthd_cd             VARCHAR2(30);
2601     l_ler_enrt_rl                  NUMBER;
2602     l_ple_enrt_perd_end_dt_rl      NUMBER;
2603 --L_PLE_ENRT_CVG_STRT_DT_CD     varchar2(30);
2604     l_use_dflt_enrt_cd             VARCHAR2(30);
2605     l_use_dflt_enrt_rl             NUMBER;
2606     l_use_dflt_flag                VARCHAR2(30);
2607     l_ler_stl_elig_cant_chg_flag   VARCHAR2(30);
2608     l_pl_enrt_rl                   NUMBER;
2609     l_ple_enrt_perd_strt_dt_rl     NUMBER;
2610     l_ple_enrt_perd_strt_days     NUMBER;
2611     l_ple_enrt_perd_end_days     NUMBER;
2612     l_pgme_dys_aftr_end_to_dflt    NUMBER;
2613     l_perd_for_program_found       VARCHAR2(30)                 := 'N';
2614     l_ple_enrt_perd_end_dt_cd      VARCHAR2(30);
2615     l_pgme_enrt_perd_end_dt_rl     NUMBER;
2616     l_ple_enrt_perd_strt_dt        DATE;
2617     l_rec_enrt_cvg_strt_dt_cd      VARCHAR2(30);
2618     l_rec_enrt_cvg_strt_dt_rl      NUMBER;
2619     l_ple_enrt_perd_strt_dt_cd     VARCHAR2(30);
2620     l_pgme_enrt_perd_strt_dt_rl    NUMBER;
2621     l_pgme_enrt_perd_strt_days    NUMBER;
2622     l_pgme_enrt_perd_end_days    NUMBER;
2623     l_ple_enrt_perd_end_dt         DATE;
2624     l_pgme_enrt_perd_strt_dt       DATE;
2625     l_rec_enrt_cvg_strt_dt         DATE;
2626     l_pgme_enrt_perd_end_dt_cd     VARCHAR2(30);
2627     l_ple_procg_end_dt             DATE;
2628     l_pgme_enrt_perd_end_dt        DATE;
2629     l_rec_mndtry_flag              VARCHAR2(30)                 := 'N';
2630     l_rec_elctbl_flag              VARCHAR2(30)                 := 'Y';
2631     l_exists_flag                  VARCHAR2(30);
2632     l_pgme_enrt_perd_strt_dt_cd    VARCHAR2(30);
2633     l_ple_dflt_enrt_dt             DATE;
2634     l_pgme_procg_end_dt            DATE;
2635     l_ple_enrt_typ_cycl_cd         VARCHAR2(30);
2636     l_rec_crntly_enrd_flag         VARCHAR2(30);
2637     l_pgme_dflt_enrt_dt            DATE;
2638     l_rec_enrt_typ_cycl_cd         VARCHAR2(30);
2639     l_pgme_enrt_typ_cycl_cd        VARCHAR2(30);
2640     l_dflt_flag                    VARCHAR2(30);
2641     l_rec_enrt_perd_strt_dt        DATE;
2642     l_erlst_deenrt_calc_dt         date ;         /*used for determine erly_deenrt_dt accroing level */
2643     l_orgnl_enrt_dt                date ;
2644     l_rec_enrt_perd_end_dt         DATE;
2645     l_ple_addit_procg_dys_num      NUMBER;
2646     l_rec_dflt_asnmt_dt            DATE;
2647     l_rec_procg_end_dt             DATE;
2648     l_crnt_erlst_deenrt_dt         DATE;
2649     l_rec_roll_crs_only_flag       VARCHAR2(30);
2650     l_rec_elctns_made_flag         VARCHAR2(30);
2651     l_rec_assignment_id            NUMBER;
2652     l_rec_organization_id          NUMBER;
2653     l_pgme_addit_procg_dys_num     NUMBER;
2654     l_rec_erlst_deenrt_dt          DATE;
2655     l_plip_auto_enrt_rl            NUMBER;
2656     l_pl_auto_enrt_rl              NUMBER;
2657     l_ler_auto_enrt_rl             NUMBER;
2658     l_invk_flx_cr_pl_flag          VARCHAR2(30);
2659     l_imptd_incm_calc_cd           VARCHAR2(30);
2660     l_pl_trk_inelig_per_flag       VARCHAR2(30);
2661     l_oipl_trk_inelig_per_flag     VARCHAR2(30);
2662     l_ple_enrt_perd_id             NUMBER;
2663     l_pgme_enrt_perd_id            NUMBER;
2664     l_rec_enrt_perd_id             NUMBER;
2665     l_rec_lee_rsn_id               NUMBER;
2666     l_rec_lee_rsn_esd              DATE;
2667     l_rec_lee_rsn_eed              DATE;
2668     l_ple_lee_rsn_id               NUMBER;
2669     l_pgme_lee_rsn_id              NUMBER;
2670     l_rec_acty_ref_perd_cd         VARCHAR2(30);
2671     l_rec_cls_enrt_dt_to_use_cd    VARCHAR2(30);
2672     l_rec_uom                      VARCHAR2(30);
2673     l_oipl_auto_enrt_flag          VARCHAR2(30)                 := 'N';
2674     l_oipl_auto_enrt_mthd_rl       NUMBER;
2675     l_unrestricted_enrt_flag       VARCHAR2(30)                 := 'N';
2676     l_enrt_ovridn_flag             VARCHAR2(30);
2677     l_enrt_ovrid_thru_dt           DATE;
2678     l_oipl_ordr_num                NUMBER;
2679     l_boo_rstrctn_cd               VARCHAR2(30);
2680     l_mn_ordr_num                  ben_oipl_f.ordr_num%TYPE;
2681     l_mx_ordr_num                  ben_oipl_f.ordr_num%TYPE;
2682     l_enrd_ordr_num                NUMBER;
2683     l_level                        VARCHAR2(30);
2684     l_plan_rec                     ben_pl_f%ROWTYPE;
2685     l_pgm_rec                      ben_pgm_f%ROWTYPE;
2686     l_oipl_rec                     ben_cobj_cache.g_oipl_inst_row;
2687     l_pen_rec                      ben_prtt_enrt_rslt_f%ROWTYPE;
2688     l_pl_typ_esd                   DATE;
2689     l_pl_typ_eed                   DATE;
2690     l_ler_esd                      DATE;
2691     l_ler_eed                      DATE;
2692     l_dpnt_cvrd_flag               VARCHAR2(1)                  := 'N';
2693     l_ptip_enrt_cd                 VARCHAR2(30);
2694     l_ptip_enrt_rl                 NUMBER;
2695     l_ptip_enrt_mthd_cd            VARCHAR2(30);
2696     l_ptip_auto_enrt_rl            NUMBER;
2697     l_jurisdiction_code            VARCHAR2(30);
2698     l_ctfn_rqd_flag                VARCHAR2(30)                 := 'N';
2699     l_reinstt_flag                 VARCHAR2(30);
2700     l_reinstt_cd                   VARCHAR2(30);
2701     --
2702     l_cvg_incr_r_decr_only_cd      VARCHAR2(30);
2703     l_mx_cvg_mlt_incr_num          NUMBER;
2704     l_mx_cvg_mlt_incr_wcf_num      NUMBER;
2705     l_tmp_level                    VARCHAR2(30);
2706     l_restriction_pgm_id           NUMBER;
2707     l_regn_125_or_129_flag         varchar2(30);
2708     --
2709     l_lf_evt_ocrd_dt               DATE
2710                                     := NVL(p_lf_evt_ocrd_dt, p_effective_date);
2711     l_lf_evt_ocrd_dt_1             DATE                 := l_lf_evt_ocrd_dt - 1;
2712   --  l_effective_date_1             DATE                 := p_effective_date - --  1;
2713   --  Bug#2328029
2714     l_effective_date_1     date :=
2715            least(p_effective_date, nvl(p_lf_evt_ocrd_dt,p_effective_date)) -1;
2716     --
2717 
2718     --
2719     l_ple_hrchy_to_use_cd          varchar2(30);
2720     l_ple_pos_structure_version_id    number;
2721     l_ws_mgr_id                    number;
2722     l_elig_flag                    varchar2(30);
2723     l_assignment_id                number(15);
2724     -- 2746865 -- variable for new column
2725     l_enrt_perd_det_ovrlp_bckdt_cd varchar2(30);
2726     l_fonm_cvg_strt_dt             date;
2727     l_epe_exists                   number ;
2728     --
2729     -- bug: 5644451
2730     l_oipl_record   ben_oipl_f%ROWTYPE;
2731     l_plip_record   ben_plip_f%ROWTYPE;
2732     l_ptip_record   ben_ptip_f%ROWTYPE;
2733     l_dflt_level    varchar2(30);
2734     --
2735     -- define all cursors
2736     --
2737     --
2738     CURSOR c_pl_typ IS
2739       SELECT   bpt.effective_start_date,
2740                bpt.effective_end_date
2741       FROM     ben_pl_typ_f bpt
2742       WHERE    bpt.pl_typ_id = l_pl_typ_id
2743       AND      l_lf_evt_ocrd_dt BETWEEN bpt.effective_start_date
2744                    AND bpt.effective_end_date
2745       AND      bpt.business_group_id = p_business_group_id;
2746     --
2747     CURSOR c_state IS
2748       SELECT   loc.region_2
2749       FROM     hr_locations_all loc, per_all_assignments_f asg
2750       WHERE    loc.location_id = asg.location_id
2751       AND      asg.person_id = p_person_id
2752       and      asg.assignment_type <> 'C'
2753       AND      asg.primary_flag = 'Y'
2754       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
2755                    AND asg.effective_end_date
2756       AND      asg.business_group_id = p_business_group_id;
2757     --
2758     l_state                        c_state%ROWTYPE;
2759     --
2760     CURSOR c_asg IS
2761       SELECT   asg.assignment_id,
2762                asg.organization_id
2763       FROM     per_all_assignments_f asg
2764       WHERE    asg.person_id = p_person_id
2765       and      asg.assignment_type <> 'C'
2766       AND      asg.primary_flag = decode (p_run_mode, 'I', asg.primary_flag, 'Y')-- iREC
2767       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
2768                    AND asg.effective_end_date;
2769   --
2770   --
2771   -- Enrt_perd_for_pl info
2772   --
2773 --cursor c_enrt_perd_for_pl_info is
2774 --  select epp.enrt_cvg_strt_dt_cd,
2775 --         epp.enrt_cvg_strt_dt_rl
2776 --  from   ben_enrt_perd_for_pl_f epp
2777 --  where  epp.pl_id=l_pl_id and
2778 --         (epp.enrt_perd_id=l_pgme_enrt_perd_id or
2779 --          epp.lee_rsn_id=l_pgme_lee_rsn_id) and
2780 --         nvl(p_lf_evt_ocrd_dt,p_effective_date) between
2781 --           epp.effective_start_date and epp.effective_end_date and
2782 --         epp.business_group_id =p_business_group_id
2783 --  ;
2784   --
2785   -- Determine the current popl_yr_period
2786   --
2787     CURSOR c_pl_popl_yr_period_current IS
2788       SELECT   pyp.yr_perd_id,
2789                pyp.popl_yr_perd_id,
2790                yp.start_date,
2791                yp.end_date,
2792                pyp.ordr_num
2793       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
2794       WHERE    pyp.pl_id = l_pl_id
2795       AND      pyp.yr_perd_id = yp.yr_perd_id
2796       AND      pyp.business_group_id = p_business_group_id
2797       AND      l_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
2798       AND      yp.business_group_id = p_business_group_id;
2799     --
2800     -- see if the elig_per_elctbl_chc record already exists
2801     --
2802     --
2803     CURSOR c_choice_exists_for_option IS
2804       SELECT   NULL
2805       FROM     ben_elig_per_elctbl_chc epe
2806       WHERE    epe.oipl_id = p_oipl_id
2807       -- added 9/25/98 to handle plans in mult progs
2808       AND      (
2809                     (    epe.pgm_id = p_pgm_id
2810                      AND p_pgm_id IS NOT NULL)
2811                  OR (    epe.pgm_id IS NULL
2812                      AND p_pgm_id IS NULL))
2813       AND      epe.per_in_ler_id = l_per_in_ler_id
2814       AND      epe.business_group_id = p_business_group_id;
2815     --
2816     -- see if the elig_per_elctbl_chc record already exists
2817     --
2818     --
2819     CURSOR c_choice_exists_for_plan(pp_pl_id NUMBER) IS
2820       SELECT   elig_per_elctbl_chc_id
2821       FROM     ben_elig_per_elctbl_chc epe
2822       WHERE    epe.pl_id = pp_pl_id
2823       AND      epe.oipl_id IS NULL
2824       -- added 9/25/98 to handle plans in mult progs
2825       AND      (
2826                     (    epe.pgm_id = p_pgm_id
2827                      AND p_pgm_id IS NOT NULL)
2828                  OR (    epe.pgm_id IS NULL
2829                      AND p_pgm_id IS NULL))
2830       AND      epe.per_in_ler_id = l_per_in_ler_id
2831       AND      epe.business_group_id = p_business_group_id;
2832     --
2833     -- Gets the enrolment information for this plan
2834     --
2835     --
2836     CURSOR c_plan_enrolment_info(p_cvg_dt date) IS
2837       SELECT   pen.enrt_cvg_strt_dt,
2838                pen.erlst_deenrt_dt,
2839                pen.prtt_enrt_rslt_id,
2840                pen.enrt_ovridn_flag,
2841                pen.enrt_ovrid_thru_dt,
2842                pen.orgnl_enrt_dt,
2843                pen.enrt_cvg_thru_dt,
2844                pen.pl_typ_id
2845       FROM     ben_prtt_enrt_rslt_f pen
2846       WHERE    pen.person_id = p_person_id
2847       AND      pen.business_group_id = p_business_group_id
2848       AND      (pen.sspndd_flag = 'N' --CFW
2849                  OR (pen.sspndd_flag = 'Y' and
2850                      pen.enrt_cvg_thru_dt = hr_api.g_eot
2851                     )
2852                )
2853       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2854       AND      pen.effective_end_date = hr_api.g_eot
2855       AND      p_cvg_dt <= pen.enrt_cvg_thru_dt
2856       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2857       AND      pen.oipl_id IS NULL
2858       AND      l_pl_id = pen.pl_id
2859       AND      (
2860                     (    pen.pgm_id = p_pgm_id
2861                      AND p_pgm_id IS NOT NULL)
2862                  OR (    pen.pgm_id IS NULL
2863                      AND p_pgm_id IS NULL))
2864       order by pen.enrt_cvg_strt_dt,decode(pen.sspndd_flag,'Y',1,2) ;
2865     --
2866     -- Bug 2600087
2867     --
2868     -- Gets the enrolment information for this oipl
2869     --
2870     --
2871     CURSOR c_oipl_enrolment_info(p_cvg_dt date) IS
2872       SELECT   pen.enrt_cvg_strt_dt,
2873                pen.erlst_deenrt_dt,
2874                pen.prtt_enrt_rslt_id,
2875                pen.enrt_ovridn_flag,
2876                pen.enrt_ovrid_thru_dt,
2877                pen.enrt_cvg_thru_dt,
2878                pen.pl_typ_id
2879       FROM     ben_prtt_enrt_rslt_f pen
2880       WHERE    pen.person_id = p_person_id
2881       AND      pen.business_group_id = p_business_group_id
2882       AND      (pen.sspndd_flag = 'N' --CFW
2883                  OR (pen.sspndd_flag = 'Y' and
2884                      pen.enrt_cvg_thru_dt = hr_api.g_eot
2885                     )
2886                )
2887       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2888       AND      pen.effective_end_date = hr_api.g_eot
2889       AND      p_cvg_dt <= pen.enrt_cvg_thru_dt
2890       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2891       AND      p_oipl_id = pen.oipl_id
2892       AND      (
2893                     (    pen.pgm_id = p_pgm_id
2894                      AND p_pgm_id IS NOT NULL)
2895                  OR (    pen.pgm_id IS NULL
2896                      AND p_pgm_id IS NULL))
2897     -- Bug 2600087
2898     order by pen.enrt_cvg_strt_dt,decode(pen.sspndd_flag,'Y',1,2);
2899     --
2900     --BUG 6519487 fix
2901     --
2902     CURSOR c_future_results (p_person_id in number,
2903                              p_enrt_cvg_thru_dt  in date,
2904                              p_pgm_id            in number,
2905                              p_pl_typ_id         in number) is
2906    SELECT   'Y'
2907      FROM   ben_prtt_enrt_rslt_f pen
2908     WHERE   pen.person_id  = p_person_id
2909     AND     pen.effective_end_date = hr_api.g_eot
2910     AND     pen.enrt_cvg_strt_dt > p_enrt_cvg_thru_dt
2911     ANd     pen.pl_typ_id       = p_pl_typ_id
2912     AND    (
2913                     (    pen.pgm_id = p_pgm_id
2914                      AND p_pgm_id IS NOT NULL)
2915                  OR (    pen.pgm_id IS NULL
2916                      AND p_pgm_id IS NULL))
2917     AND     pen.prtt_enrt_rslt_stat_cd is null;
2918     --
2919     --BUG 6519487 fix
2920     --
2921     -- Gets the coverage information for this plan
2922     --
2923     --
2924     CURSOR c_plan_cvg_info IS
2925       SELECT   'Y'
2926       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
2927       WHERE    pdp.dpnt_person_id = p_person_id
2928       AND      pdp.effective_end_date = hr_api.g_eot
2929       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
2930       AND      pdp.business_group_id = p_business_group_id
2931       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
2932       AND      pen.business_group_id = p_business_group_id
2933       AND      pen.sspndd_flag = 'N'
2934       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2935       AND      pen.effective_end_date = hr_api.g_eot
2936       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
2937       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2938       AND      l_pl_id = pen.pl_id
2939       AND      (
2940                     (    pen.pgm_id = p_pgm_id
2941                      AND p_pgm_id IS NOT NULL)
2942                  OR (    pen.pgm_id IS NULL
2943                      AND p_pgm_id IS NULL));
2944     --
2945     -- Gets the coverage information for this oipl
2946     --
2947     --
2948     CURSOR c_oipl_cvg_info IS
2949       SELECT   'Y'
2950       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
2951       WHERE    pdp.dpnt_person_id = p_person_id
2952       AND      pdp.effective_end_date = hr_api.g_eot
2953       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
2954       AND      pdp.business_group_id = p_business_group_id
2955       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
2956       AND      pen.business_group_id = p_business_group_id
2957       AND      pen.sspndd_flag = 'N'
2958       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2959       AND      pen.effective_end_date = hr_api.g_eot
2960       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
2961       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2962       AND      p_oipl_id = pen.oipl_id
2963       AND      (
2964                     (    pen.pgm_id = p_pgm_id
2965                      AND p_pgm_id IS NOT NULL)
2966                  OR (    pen.pgm_id IS NULL
2967                      AND p_pgm_id IS NULL));
2968     --
2969     -- Determines the current eligibility for an option
2970     --
2971     CURSOR c_current_elig_for_option IS
2972       SELECT   ep.elig_per_id,
2973                epo.elig_flag,
2974                ep.must_enrl_anthr_pl_id,
2975                epo.prtn_strt_dt
2976       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
2977       WHERE    ep.person_id = p_person_id
2978       AND      ep.pl_id = l_pl_id
2979       AND      (
2980                     (    ep.pgm_id = p_pgm_id
2981                      AND p_pgm_id IS NOT NULL)
2982                  OR (    ep.pgm_id IS NULL
2983                      AND p_pgm_id IS NULL))
2984       AND      ep.business_group_id = p_business_group_id
2985       AND      p_effective_date BETWEEN ep.effective_start_date
2986                    AND ep.effective_end_date
2987       AND      ep.elig_per_id = epo.elig_per_id
2988       AND      epo.opt_id = l_opt_id
2989       AND      epo.business_group_id = p_business_group_id
2990       AND      p_effective_date BETWEEN epo.effective_start_date
2991                    AND epo.effective_end_date
2992       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
2993       AND      pil.business_group_id (+) = epo.business_group_id
2994       AND      (
2995                     pil.per_in_ler_stat_cd NOT IN
2996                                         (
2997                                           'VOIDD',
2998                                           'BCKDT')       -- found row condition
2999                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3000     -- Determines the previous eligibility for an option
3001     --
3002     CURSOR c_previous_elig_for_option IS
3003       SELECT   epo.elig_flag
3004       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
3005       WHERE    ep.person_id = p_person_id
3006       AND      ep.pl_id = l_pl_id
3007       AND      (
3008                     (    ep.pgm_id = p_pgm_id
3009                      AND p_pgm_id IS NOT NULL)
3010                  OR (    ep.pgm_id IS NULL
3011                      AND p_pgm_id IS NULL))
3012       AND      ep.business_group_id = p_business_group_id
3013       AND      p_effective_date - 1 BETWEEN ep.effective_start_date
3014                    AND ep.effective_end_date
3015       AND      ep.elig_per_id = epo.elig_per_id
3016       AND      epo.opt_id = l_opt_id
3017       AND      epo.business_group_id = p_business_group_id
3018       AND      l_effective_date_1 BETWEEN epo.effective_start_date
3019                    AND epo.effective_end_date
3020       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
3021       AND      pil.business_group_id (+) = epo.business_group_id
3022       AND      (
3023                     pil.per_in_ler_stat_cd NOT IN
3024                                         (
3025                                           'VOIDD',
3026                                           'BCKDT')       -- found row condition
3027                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3028     --
3029     -- Determines the current eligibility for a plan
3030     --
3031     CURSOR c_current_elig_for_plan
3032     is
3033       SELECT   pep.elig_per_id,
3034                pep.elig_flag,
3035                pep.must_enrl_anthr_pl_id,
3036                pep.prtn_strt_dt,
3037                pep.inelg_rsn_cd -- 2650247
3038       FROM     ben_elig_per_f pep, ben_per_in_ler pil
3039       WHERE    pep.person_id = p_person_id
3040       AND      pep.pl_id = l_pl_id
3041       AND      (
3042                     (    pep.pgm_id = p_pgm_id
3043                      AND p_pgm_id IS NOT NULL)
3044                  OR (    pep.pgm_id IS NULL
3045                      AND p_pgm_id IS NULL))
3046       AND      pep.business_group_id = p_business_group_id
3047       AND      p_effective_date BETWEEN pep.effective_start_date
3048                    AND pep.effective_end_date
3049       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
3050       AND      pil.business_group_id (+) = pep.business_group_id
3051       AND      (
3052                     pil.per_in_ler_stat_cd NOT IN
3053                                         (
3054                                           'VOIDD',
3055                                           'BCKDT')       -- found row condition
3056                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3057     --
3058     -- Determines the previous eligibility for a plan
3059     --
3060     CURSOR c_previous_elig_for_plan IS
3061       SELECT   pep.elig_flag
3062       FROM     ben_elig_per_f pep, ben_per_in_ler pil
3063       WHERE    pep.person_id = p_person_id
3064       AND      pep.pl_id = l_pl_id
3065       AND      (
3066                     (    pep.pgm_id = p_pgm_id
3067                      AND p_pgm_id IS NOT NULL)
3068                  OR (    pep.pgm_id IS NULL
3069                      AND p_pgm_id IS NULL))
3070       AND      pep.business_group_id = p_business_group_id
3071       AND      l_effective_date_1 BETWEEN pep.effective_start_date
3072                    AND pep.effective_end_date
3073       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
3074       AND      pil.business_group_id (+) = pep.business_group_id
3075       AND      (
3076                     pil.per_in_ler_stat_cd NOT IN
3077                                         (
3078                                           'VOIDD',
3079                                           'BCKDT')       -- found row condition
3080                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
3081     -- Determines the per_in_ler and gets associated info
3082     --
3083     CURSOR c_per_in_ler_info IS
3084       SELECT   pil.per_in_ler_id,
3085                ler.typ_cd,
3086                ler.name,
3087                pil.lf_evt_ocrd_dt,
3088                ler.effective_start_date,
3089                ler.effective_end_date
3090       FROM     ben_per_in_ler pil, ben_ler_f ler
3091       WHERE    pil.person_id = p_person_id
3092       AND      pil.business_group_id = p_business_group_id
3093       AND      pil.ler_id = p_ler_id
3094       AND      pil.per_in_ler_stat_cd = 'STRTD'
3095       AND      ler.business_group_id = p_business_group_id
3096       AND      pil.ler_id = ler.ler_id
3097       AND      l_lf_evt_ocrd_dt BETWEEN ler.effective_start_date
3098                    AND ler.effective_end_date
3099       and      nvl(pil.assignment_id, -9999) = decode (p_run_mode,
3100                                            'I',
3101 					   ben_manage_life_events.g_irec_ass_rec.assignment_id,
3102 					   nvl(pil.assignment_id, -9999) );            -- iRec
3103     --
3104     -- Bug 2200139 Get new the per_in_ler info for the Override Election.
3105     --
3106     CURSOR c_ovrd_per_in_ler_info IS
3107       SELECT   pil.per_in_ler_id,
3108                ler.typ_cd,
3109                ler.name,
3110                pil.lf_evt_ocrd_dt,
3111                ler.effective_start_date,
3112                ler.effective_end_date
3113       FROM     ben_per_in_ler pil, ben_ler_f ler
3114       WHERE    pil.per_in_ler_id = p_per_in_ler_id
3115       AND      pil.business_group_id = p_business_group_id
3116 --     AND      pil.ler_id = p_ler_id
3117 --     AND      pil.per_in_ler_stat_cd = 'STRTD'
3118       AND      ler.business_group_id = p_business_group_id
3119       AND      pil.ler_id = ler.ler_id
3120       AND      l_lf_evt_ocrd_dt BETWEEN ler.effective_start_date
3121                    AND ler.effective_end_date;
3122     -- end Override Election
3123     -- This cursor gets the enrolment period for scheduled
3124     -- elections for plan level
3125     --
3126     -- Bug 5272 : To get the enrolment period get the
3127     -- enrollment strt_dt and use it to get the programs enrollment
3128     -- period data.
3129     --
3130     CURSOR c_sched_enrol_period_for_plan IS
3131       SELECT   enrtp.enrt_perd_id,
3132                enrtp.strt_dt,
3133                enrtp.end_dt,
3134                enrtp.procg_end_dt,
3135                enrtp.dflt_enrt_dt,
3136                petc.enrt_typ_cycl_cd,
3137                enrtp.cls_enrt_dt_to_use_cd,
3138                enrtp.hrchy_to_use_cd,
3139                enrtp.pos_structure_version_id,
3140                /* bug 2746865  */
3141                enrtp.enrt_perd_det_ovrlp_bckdt_cd
3142       FROM     ben_popl_enrt_typ_cycl_f petc,
3143                ben_enrt_perd enrtp,
3144                 ben_ler_f ler
3145       WHERE    petc.pl_id = l_pl_id
3146       AND      petc.business_group_id = p_business_group_id
3147       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3148                    AND petc.effective_end_date
3149       AND      petc.enrt_typ_cycl_cd <> 'L'
3150       AND      enrtp.business_group_id = p_business_group_id
3151       AND      enrtp.asnd_lf_evt_dt  = p_lf_evt_ocrd_dt
3152       /* PB :5422 AND      enrtp.strt_dt=enrtp1.strt_dt
3153       AND      enrtp1.popl_enrt_typ_cycl_id = p_popl_enrt_typ_cycl_id
3154       AND      enrtp1.business_group_id     = p_business_group_id */
3155       AND      enrtp.popl_enrt_typ_cycl_id  = petc.popl_enrt_typ_cycl_id
3156       -- comp work bench changes
3157       and      ler.ler_id (+) = enrtp.ler_id
3158       and      ler.ler_id (+) = p_ler_id
3159       and      l_lf_evt_ocrd_dt between ler.effective_start_date (+)
3160                                     and ler.effective_end_date (+);
3161 
3162     -- This cursor gets the enrolment period for scheduled
3163     -- elections for program level
3164     --
3165     -- Bug 5272 : To get the enrolment period,  get the
3166     -- enrollment strt_dt and use it to get the plans enrollment
3167     -- period data.
3168     --
3169     CURSOR c_sched_enrol_period_for_pgm IS
3170       SELECT   enrtp.enrt_perd_id,
3171                enrtp.strt_dt,
3172                enrtp.end_dt,
3173                enrtp.procg_end_dt,
3174                enrtp.dflt_enrt_dt,
3175                petc.enrt_typ_cycl_cd,
3176                enrtp.cls_enrt_dt_to_use_cd,
3177                enrtp.hrchy_to_use_cd,
3178                enrtp.pos_structure_version_id,
3179                /* bug 2746865*/
3180                enrtp.enrt_perd_det_ovrlp_bckdt_cd
3181       FROM     ben_popl_enrt_typ_cycl_f petc,
3182                ben_enrt_perd enrtp,
3183                ben_ler_f ler
3184       WHERE    petc.pgm_id = p_pgm_id
3185       AND      petc.business_group_id = p_business_group_id
3186       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3187                    AND petc.effective_end_date
3188       AND      petc.enrt_typ_cycl_cd <> 'L'
3189       AND      enrtp.business_group_id = p_business_group_id
3190       AND      enrtp.asnd_lf_evt_dt  = p_lf_evt_ocrd_dt
3191       /* PB :5422 AND      enrtp1.business_group_id = p_business_group_id
3192       AND      enrtp.strt_dt= enrtp1.strt_dt
3193       AND      enrtp1.enrt_perd_id = p_popl_enrt_typ_cycl_id */
3194       AND      enrtp.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3195       -- comp work bench
3196       and      ler.ler_id (+) = enrtp.ler_id
3197       and      ler.ler_id (+) = p_ler_id
3198       and      l_lf_evt_ocrd_dt between ler.effective_start_date (+)
3199                                     and ler.effective_end_date (+);
3200 
3201     -- This cursor gets information used to determine the
3202     -- enrolment period for life event driven elections
3203     --
3204     CURSOR c_lee_period_for_plan IS
3205       SELECT   leer.dys_aftr_end_to_dflt_num,
3206                leer.enrt_perd_end_dt_rl,
3207                leer.enrt_perd_strt_dt_rl,
3208                leer.enrt_perd_end_dt_cd,
3209                leer.enrt_perd_strt_dt_cd,
3210                leer.addl_procg_dys_num,
3211                petc.enrt_typ_cycl_cd,
3212                leer.lee_rsn_id,
3213                leer.cls_enrt_dt_to_use_cd,
3214                leer.effective_start_date,
3215                leer.effective_end_date,
3216                leer.enrt_perd_strt_days,
3217                leer.enrt_perd_end_days,
3218                /* bug 2746865*/
3219                leer.enrt_perd_det_ovrlp_bckdt_cd
3220       FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
3221       WHERE    leer.ler_id = p_ler_id
3222       AND      leer.business_group_id = p_business_group_id
3223       AND      l_lf_evt_ocrd_dt BETWEEN leer.effective_start_date
3224                    AND leer.effective_end_date
3225       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3226       AND      petc.pl_id = l_pl_id
3227       AND      petc.enrt_typ_cycl_cd = 'L'                        -- life event
3228       AND      petc.business_group_id = p_business_group_id
3229       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3230                    AND petc.effective_end_date;
3231     -- This cursor gets information used to determine the
3232     -- enrolment period for life event driven elections
3233     --
3234     CURSOR c_lee_period_for_program IS
3235       SELECT   leer.dys_aftr_end_to_dflt_num,
3236                leer.enrt_perd_end_dt_rl,
3237                leer.enrt_perd_strt_dt_rl,
3238                leer.enrt_perd_end_dt_cd,
3239                leer.enrt_perd_strt_dt_cd,
3240                leer.addl_procg_dys_num,
3241                petc.enrt_typ_cycl_cd,
3242                leer.lee_rsn_id,
3243                leer.cls_enrt_dt_to_use_cd,
3244                leer.effective_start_date,
3245                leer.effective_end_date ,
3246                leer.enrt_perd_strt_days,
3247                leer.enrt_perd_end_days,
3248                /* bug 2746865*/
3249                leer.enrt_perd_det_ovrlp_bckdt_cd
3250       FROM     ben_lee_rsn_f leer, ben_popl_enrt_typ_cycl_f petc
3251       WHERE    leer.ler_id = p_ler_id
3252       AND      leer.business_group_id = p_business_group_id
3253       AND      l_lf_evt_ocrd_dt BETWEEN leer.effective_start_date
3254                    AND leer.effective_end_date
3255       AND      leer.popl_enrt_typ_cycl_id = petc.popl_enrt_typ_cycl_id
3256       AND      petc.pgm_id = p_pgm_id
3257       AND      petc.enrt_typ_cycl_cd = 'L'
3258       AND      petc.business_group_id = p_business_group_id
3259       AND      l_lf_evt_ocrd_dt BETWEEN petc.effective_start_date
3260                    AND petc.effective_end_date;
3261     -- Gets all information on the plip which is needed
3262     --
3263     CURSOR c_plip_info IS
3264       SELECT   bpf.plip_id,
3265                bpf.dflt_flag,
3266                bpf.enrt_cd,
3267                bpf.enrt_rl,
3268                bpf.enrt_mthd_cd,
3269                bpf.auto_enrt_mthd_rl,
3270                bpf.alws_unrstrctd_enrt_flag,
3271                bpf.effective_start_date,
3272                bpf.effective_end_date,
3273                bpf.ordr_num
3274       FROM     ben_plip_f bpf
3275       WHERE    bpf.pl_id = l_pl_id
3276       AND      bpf.pgm_id = p_pgm_id
3277       AND      bpf.business_group_id = p_business_group_id
3278       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
3279                    AND bpf.effective_end_date;
3280     -- Gets all information on the ptip which is needed
3281     --
3282     CURSOR c_ptip_info IS
3283       SELECT   ptip.ptip_id,
3284                ptip.enrt_cd,
3285                ptip.enrt_rl,
3286                ptip.enrt_mthd_cd,
3287                ptip.auto_enrt_mthd_rl,
3288                ptip.effective_start_date,
3289                ptip.effective_end_date,
3290                ptip.ordr_num
3291       FROM     ben_ptip_f ptip
3292       WHERE    ptip.pl_typ_id = l_pl_typ_id
3293       AND      ptip.pgm_id = p_pgm_id
3294       AND      ptip.business_group_id = p_business_group_id
3295       AND      l_lf_evt_ocrd_dt BETWEEN ptip.effective_start_date
3296                    AND ptip.effective_end_date;
3297     --
3298     -- Returns one row if any oipls exist for the plan
3299     --
3300     CURSOR c_any_oipl_for_plan IS                                -- oipl exists
3301       SELECT   NULL
3302       FROM     ben_oipl_f cop
3303       WHERE    cop.pl_id = l_pl_id
3304       AND      business_group_id = p_business_group_id
3305       AND      l_lf_evt_ocrd_dt BETWEEN cop.effective_start_date
3306                    AND cop.effective_end_date;
3307     --
3308     -- Get level restriction
3309     --
3310     --
3311     CURSOR c_ler_bnft_rstrn IS
3312       SELECT   '4',
3313                plip.pgm_id,
3314                oipl.ordr_num,
3315                plip.bnft_or_option_rstrctn_cd,
3316                lbr.cvg_incr_r_decr_only_cd,
3317                lbr.mx_cvg_mlt_incr_num,
3318                lbr.mx_cvg_mlt_incr_wcf_num
3319       FROM     ben_oipl_f oipl, ben_ler_bnft_rstrn_f lbr, ben_plip_f plip
3320       WHERE    plip.plip_id = l_plip_id
3321       AND      plip.business_group_id = p_business_group_id
3322       AND      plip.bnft_or_option_rstrctn_cd = 'OPT'
3323       AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
3324                    AND plip.effective_end_date
3325       AND      oipl.oipl_id = p_oipl_id
3326       AND      oipl.pl_id = plip.pl_id
3327       AND      oipl.business_group_id = p_business_group_id
3328       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3329                    AND oipl.effective_end_date
3330       AND      lbr.plip_id = plip.plip_id
3331       AND      lbr.ler_id = p_ler_id
3332       AND      lbr.business_group_id = p_business_group_id
3333       AND      l_lf_evt_ocrd_dt BETWEEN lbr.effective_start_date
3334                    AND lbr.effective_end_date
3335       UNION ALL
3336       SELECT   '3',
3337                TO_NUMBER(NULL),
3338                oipl.ordr_num,
3339                pl.bnft_or_option_rstrctn_cd,
3340                lbr.cvg_incr_r_decr_only_cd,
3341                lbr.mx_cvg_mlt_incr_num,
3342                lbr.mx_cvg_mlt_incr_wcf_num
3343       FROM     ben_oipl_f oipl, ben_ler_bnft_rstrn_f lbr, ben_pl_f pl
3344       WHERE    pl.pl_id = l_pl_id
3345       AND      pl.business_group_id = p_business_group_id
3346       AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
3347                    AND pl.effective_end_date
3348       AND      oipl.oipl_id = p_oipl_id
3349       AND      oipl.pl_id = pl.pl_id
3350       AND      oipl.business_group_id = p_business_group_id
3351       AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3352                    AND oipl.effective_end_date
3353       AND      lbr.pl_id = pl.pl_id
3354       AND      lbr.plip_id IS NULL
3355       AND      lbr.ler_id = p_ler_id
3356       AND      pl.bnft_or_option_rstrctn_cd = 'OPT'
3357       AND      lbr.business_group_id = p_business_group_id
3358       AND      l_lf_evt_ocrd_dt BETWEEN lbr.effective_start_date
3359                    AND lbr.effective_end_date;
3360     --
3361     --
3362     /*
3363         --
3364         CURSOR c_pl_bnft_rstrn IS
3365           SELECT   '2',
3366                    plip.pgm_id,
3367                    oipl.ordr_num,
3368                    plip.bnft_or_option_rstrctn_cd,
3369                    plip.cvg_incr_r_decr_only_cd,
3370                    plip.mx_cvg_mlt_incr_num,
3371                    plip.mx_cvg_mlt_incr_wcf_num
3372           FROM     ben_oipl_f oipl, ben_plip_f plip
3373           WHERE    plip.plip_id = l_plip_id
3374           AND      plip.bnft_or_option_rstrctn_cd = 'OPT'
3375           AND      plip.business_group_id = p_business_group_id
3376           AND      l_lf_evt_ocrd_dt BETWEEN plip.effective_start_date
3377                        AND plip.effective_end_date
3378           AND      oipl.oipl_id = p_oipl_id
3379           AND      oipl.pl_id = plip.pl_id
3380           AND      oipl.business_group_id = p_business_group_id
3381           AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3382                        AND oipl.effective_end_date
3383           UNION ALL
3384           SELECT   '1',
3385                    TO_NUMBER(NULL),
3386                    oipl.ordr_num,
3387                    pl.bnft_or_option_rstrctn_cd,
3388                    pl.cvg_incr_r_decr_only_cd,
3389                    pl.mx_cvg_mlt_incr_num,
3390                    pl.mx_cvg_mlt_incr_wcf_num
3391           FROM     ben_oipl_f oipl, ben_pl_f pl
3392           WHERE    pl.pl_id = l_pl_id
3393           AND      pl.bnft_or_option_rstrctn_cd = 'OPT'
3394           AND      pl.business_group_id = p_business_group_id
3395           AND      l_lf_evt_ocrd_dt BETWEEN pl.effective_start_date
3396                        AND pl.effective_end_date
3397           AND      oipl.oipl_id = p_oipl_id
3398           AND      oipl.pl_id = pl.pl_id
3399           AND      oipl.business_group_id = p_business_group_id
3400           AND      l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3401                        AND oipl.effective_end_date;
3402         --**
3403     */
3404 --**
3405   --
3406   -- get the oipl enrollment for this plan (may not be this oipl)
3407   --
3408   --
3409     CURSOR c_oipl_enrt_in_pl IS
3410       SELECT   enrd_oipl.ordr_num
3411       FROM     ben_prtt_enrt_rslt_f pen, ben_oipl_f enrd_oipl
3412       WHERE
3413                -- get result for plan if exists
3414                pen.person_id = p_person_id
3415       AND      pen.business_group_id = p_business_group_id
3416       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3417       AND      pen.sspndd_flag = 'N'
3418       AND      pen.effective_end_date = hr_api.g_eot
3419       AND      pen.enrt_cvg_thru_dt >= l_lf_evt_ocrd_dt_1
3420       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3421       AND      pen.pl_id = l_pl_id
3422       -- get enrolled oipl
3423       AND      enrd_oipl.oipl_id = pen.oipl_id
3424       AND      enrd_oipl.business_group_id = p_business_group_id
3425       AND      l_lf_evt_ocrd_dt BETWEEN enrd_oipl.effective_start_date
3426                    AND enrd_oipl.effective_end_date;
3427     --
3428     -- get the oipl coverage for this plan (may not be this oipl)
3429     --
3430     --
3431     CURSOR c_oipl_cvg_in_pl IS
3432       SELECT   enrd_oipl.ordr_num
3433       FROM     ben_prtt_enrt_rslt_f pen,
3434                ben_elig_cvrd_dpnt_f pdp,
3435                ben_oipl_f enrd_oipl
3436       WHERE    pdp.dpnt_person_id = p_person_id
3437       AND      pdp.effective_end_date = hr_api.g_eot
3438       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
3439       AND      pdp.business_group_id = p_business_group_id
3440       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
3441       -- get result for plan if exists
3442       AND      pen.business_group_id = p_business_group_id
3443       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
3444       AND      pen.sspndd_flag = 'N'
3445       AND      pen.effective_end_date = hr_api.g_eot
3446       AND      pen.enrt_cvg_thru_dt >= l_lf_evt_ocrd_dt_1
3447       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
3448       AND      pen.pl_id = l_pl_id
3449       -- get enrolled oipl
3450       AND      enrd_oipl.oipl_id = pen.oipl_id
3451       AND      enrd_oipl.business_group_id = p_business_group_id
3452       AND      l_lf_evt_ocrd_dt BETWEEN enrd_oipl.effective_start_date
3453                    AND enrd_oipl.effective_end_date;
3454     --
3455     --
3456     CURSOR c_get_min_max_ordr_num IS
3457       SELECT   MIN(cop.ordr_num),
3458                MAX(cop.ordr_num)
3459       FROM     ben_oipl_f cop
3460       WHERE    cop.pl_id = l_pl_id
3461       AND      l_lf_evt_ocrd_dt BETWEEN cop.effective_start_date
3462                    AND cop.effective_end_date
3463       AND      cop.business_group_id = p_business_group_id;
3464     --
3465     l_latest_procd_dt              DATE;
3466     l_backed_out_date              DATE;
3467     l_orig_epsd                    DATE;
3468     --
3469 /*
3470     cursor c_regn_125_or_129 is
3471       select   'Y'
3472       from     ben_pl_regn_f prg,
3473                ben_regn_f regn
3474       where    prg.pl_id=l_pl_id
3475            and p_effective_date between
3476                prg.effective_start_date and prg.effective_end_date
3477            and prg.business_group_id=p_business_group_id
3478            and regn.regn_id=prg.regn_id
3479            and regn.name in ('IRC Section 125','IRC Section 129')
3480            and p_effective_date between
3481                regn.effective_start_date and regn.effective_end_date
3482            and regn.business_group_id=p_business_group_id
3483       ;
3484 */
3485   --
3486   -- following requery logic added for bug 1394507 - 9 cursors
3487   --
3488   cursor c_pgm_requery(p_id number,p_ed date) is
3489     select 'Y'
3490     from ben_pgm_f pgm
3491     where pgm_id=p_id and
3492           business_group_id=p_business_group_id and
3493           p_ed between effective_start_date and effective_end_date
3494     ;
3495   --
3496   cursor c_plip_requery(p_id number,p_ed date) is
3497     select 'Y'
3498     from ben_plip_f plip
3499     where plip_id=p_id and
3500           business_group_id=p_business_group_id and
3501           p_ed between effective_start_date and effective_end_date
3502     ;
3503   --
3504   cursor c_ptip_requery(p_id number,p_ed date) is
3505     select 'Y'
3506     from ben_ptip_f ptip
3507     where ptip_id=p_id and
3508           business_group_id=p_business_group_id and
3509           p_ed between effective_start_date and effective_end_date
3510     ;
3511   --
3512   cursor c_oipl_requery(p_id number,p_ed date) is
3513     select 'Y'
3514     from ben_oipl_f oipl
3515     where oipl_id=p_id and
3516           business_group_id=p_business_group_id and
3517           p_ed between effective_start_date and effective_end_date
3518     ;
3519   --
3520   cursor c_opt_requery(p_id number,p_ed date) is
3521     select 'Y'
3522     from ben_opt_f opt
3523     where opt_id=p_id and
3524           business_group_id=p_business_group_id and
3525           p_ed between effective_start_date and effective_end_date
3526     ;
3527   --
3528   cursor c_plan_requery(p_id number,p_ed date) is
3529     select 'Y'
3530     from ben_pl_f plan
3531     where pl_id=p_id and
3532           business_group_id=p_business_group_id and
3533           p_ed between effective_start_date and effective_end_date
3534     ;
3535   --
3536   cursor c_pl_typ_requery(p_id number,p_ed date) is
3537     select 'Y'
3538     from ben_pl_typ_f pl_typ
3539     where pl_typ_id=p_id and
3540           business_group_id=p_business_group_id and
3541           p_ed between effective_start_date and effective_end_date
3542     ;
3543   --
3544   cursor c_lee_rsn_requery(p_id number,p_ed date) is
3545     select 'Y'
3546     from ben_lee_rsn_f lee_rsn
3547     where lee_rsn_id=p_id and
3548           business_group_id=p_business_group_id and
3549           p_ed between effective_start_date and effective_end_date
3550     ;
3551   --
3552   cursor c_ler_requery(p_id number,p_ed date) is
3553     select 'Y'
3554     from ben_ler_f ler
3555     where ler_id=p_id and
3556           business_group_id=p_business_group_id and
3557           p_ed between effective_start_date and effective_end_date
3558     ;
3559   --
3560   -- unrestricted process change
3561   cursor c_prtt_enrt_rslt(l_prtt_enrt_rslt_id number) is
3562     select min(effective_start_date)
3563     from   ben_prtt_enrt_rslt_f
3564     where  prtt_enrt_rslt_id = l_prtt_enrt_rslt_id;
3565   l_effective_start_date date;
3566   --
3567   cursor c_opt_level is
3568     select oipl2.ordr_num
3569     from   ben_oipl_f oipl,
3570            ben_oipl_f oipl2
3571     where  oipl.oipl_id  = p_oipl_id
3572     and    oipl.pl_id   = oipl2.pl_id
3573     and    oipl2.oipl_stat_cd = 'A'
3574     and    oipl.business_group_id = p_business_group_id
3575     and    l_lf_evt_ocrd_dt BETWEEN oipl.effective_start_date
3576                    AND oipl.effective_end_date
3577     and    oipl2.business_group_id = p_business_group_id
3578     and      l_lf_evt_ocrd_dt BETWEEN oipl2.effective_start_date
3579                    AND oipl2.effective_end_date
3580     order by 1;
3581   --
3582 
3583   --
3584   l_cnt          number := 0;
3585   l_oipl_seq_num number ;
3586   l_enrd_seq_num number ;
3587   l_found        boolean := FALSE;
3588   l_opt_level    number;
3589   l_new_cvg_strt  varchar2(1) := 'N';
3590   l_cvg_dt       date;
3591   l_enrt_cd_level varchar2(30);
3592 
3593 
3594   --
3595   -- CWB Chnages.
3596   --
3597   l_emp_epe_id   number;
3598   l_inelg_rsn_cd ben_elig_per_f.inelg_rsn_cd%type; -- 2650247
3599 
3600   -- CWBITEM
3601   l_emp_pel_id   number;
3602   l_pel_id       number;
3603   --
3604 
3605   -- CWBITEM
3606 /*  cursor c_cwb_hrchy(cv_emp_epe_id in number) is
3607    select emp_elig_per_elctbl_chc_id
3608    from ben_cwb_mgr_hrchy
3609    where emp_elig_per_elctbl_chc_id = cv_emp_epe_id; */
3610   --
3611   cursor c_hrchy(cv_emp_epe_id number) is
3612    select hrc.emp_pil_elctbl_chc_popl_id,
3613           pel.pil_elctbl_chc_popl_id
3614    from ben_elig_per_elctbl_chc epe,
3615         ben_pil_elctbl_chc_popl pel,
3616         ben_cwb_hrchy hrc
3617    where pel.pil_elctbl_chc_popl_id = epe.pil_elctbl_chc_popl_id
3618      and epe.elig_per_elctbl_chc_id = cv_emp_epe_id
3619      and hrc.emp_pil_elctbl_chc_popl_id(+) = pel.pil_elctbl_chc_popl_id;
3620   --
3621   -- BUG 6519487 fix
3622   l_dummy_varchar varchar2(30);
3623   l_current_pl_typ_id number;
3624   --END BUG 6519487 fix
3625   BEGIN
3626     --
3627     g_debug := hr_utility.debug_enabled;
3628     hr_utility.set_location('Entering:' || l_proc, 10);
3629     --
3630     -- If the run_mode is not "life event" or "scheduled" DONE
3631     -- Bug 2200139 Added 'V' mode for override
3632     -- ABSENCES - added absence mode. Added GRADE/STEP
3633     -- iRec - Added mode 'I'
3634     --
3635     IF p_run_mode NOT IN ('L', 'C', 'U','W','V', 'M','G', 'I','D') THEN
3636       --
3637       fnd_message.set_name('BEN', 'BEN_91458_DENRR_MODE_INVALID');
3638       fnd_message.set_token('PROC', l_proc);
3639       fnd_message.set_token('MODE', p_run_mode);
3640       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3641       RAISE ben_manage_life_events.g_record_error;
3642     --
3643     END IF;
3644     --
3645     -- Get option information if an oipl_id is passed,
3646     -- need to do this before getting oipl eligibility.
3647     --
3648     IF (p_oipl_id IS NOT NULL) THEN
3649       --
3650       -- get oipl information
3651       --
3652       if g_debug then
3653       hr_utility.set_location('OIPL NN: ' || l_proc, 10);
3654       end if;
3655       --
3656       -- Bug 2200139 For Override call the cache routine else call the benmnglecache
3657       -- this is not required as the data is fetched on the benovrrd.pkb
3658       --IF p_run_mode = 'V' THEN
3659       --  --
3660       --  ben_cobj_cache.get_oipl_dets (
3661       --     p_business_group_id => p_business_group_id
3662       --    ,p_effective_date    => p_effective_date
3663       --    ,p_oipl_id           => p_oipl_id
3664       --    ,p_inst_row          => l_oipl_rec
3665       --    ) ;
3666       --  --
3667       --ELSE
3668         --
3669         l_oipl_rec := ben_cobj_cache.g_oipl_currow;
3670         l_oipl_name :=               ben_cobj_cache.g_opt_currow.name;
3671         --
3672       --END IF;
3673       --
3674       l_pl_id :=                   l_oipl_rec.pl_id;
3675       l_oipl_dflt_flag :=          l_oipl_rec.dflt_flag;
3676       l_opt_id :=                  l_oipl_rec.opt_id;
3677       l_mndtry_flag :=             l_oipl_rec.mndtry_flag;
3678       l_mndtry_rl :=               l_oipl_rec.mndtry_rl;
3679       l_oipl_auto_enrt_flag :=     l_oipl_rec.auto_enrt_flag;
3680       l_oipl_auto_enrt_mthd_rl :=  l_oipl_rec.auto_enrt_mthd_rl;
3681       l_oipl_trk_inelig_per_flag := l_oipl_rec.trk_inelig_per_flag;
3682       --
3683       -- l_oipl_name :=               ben_cobj_cache.g_opt_currow.name;
3684       if g_debug then
3685       hr_utility.set_location('DONE OIPL NN: ' || l_proc, 10);
3686       end if;
3687     --
3688     ELSE
3689       --
3690       l_pl_id :=  p_pl_id;
3691     --
3692     END IF;
3693     --
3694     -- get plan cache row
3695     --
3696     ben_comp_object.get_object(p_pl_id => l_pl_id, p_rec => l_plan_rec);
3697     if g_debug then
3698     hr_utility.set_location('Done PLN cac: ' || l_proc, 10);
3699     hr_utility.set_location(
3700       'Plan name is ' || SUBSTR(l_plan_rec.name, 1, 30),
3701       17);
3702     end if;
3703     --
3704     -- Get pgm cache row if needed
3705     --
3706     IF p_pgm_id IS NOT NULL THEN
3707     if g_debug then
3708       hr_utility.set_location('PGM NN 2: ' || l_proc, 10);
3709     end if;
3710       ben_comp_object.get_object(p_pgm_id => p_pgm_id, p_rec => l_pgm_rec);
3711       if g_debug then
3712       hr_utility.set_location('Done PGM NN 2: ' || l_proc, 10);
3713       hr_utility.set_location(
3714         'Pgm name is ' || SUBSTR(l_pgm_rec.name, 1, 30),
3715         18);
3716       end if;
3717     END IF;
3718     --
3719     -- Check required parameters of run_mode, person_id, pl_id or oipl_id,
3720     -- business_group_id, and ler_id.
3721     --
3722     IF (
3723             p_run_mode IS NULL
3724          OR p_business_group_id IS NULL
3725          OR p_effective_date IS NULL
3726          OR p_ler_id IS NULL
3727          OR p_person_id IS NULL
3728          OR l_pl_id IS NULL) THEN
3729       --
3730       if g_debug then
3731       hr_utility.set_location('error', 19);
3732       end if;
3733       fnd_message.set_name('BEN', 'BEN_91737_ENRT_REQ_MISS_PARM');
3734       fnd_message.set_token('PROC', l_proc);
3735       fnd_message.set_token('MODE', p_run_mode);
3736       fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
3737       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
3738       fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
3739       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3740       fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
3741       RAISE ben_manage_life_events.g_record_error;
3742     --
3743     END IF;
3744     --
3745 /*  -- 4031733 - Cursor c_state populates l_state variable which is no longer
3746     -- used in the package. Cursor can be commented
3747 
3748     IF p_person_id IS NOT NULL THEN
3749       OPEN c_state;
3750       FETCH c_state INTO l_state;
3751       CLOSE c_state;
3752       hr_utility.set_location('close c_state: ' || l_proc, 10);
3753       --
3754       --IF l_state.region_2 IS NOT NULL THEN
3755         --
3756       --  l_jurisdiction_code :=
3757       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
3758       --
3759      -- END IF;
3760     --
3761     END IF;
3762 */
3763     --
3764     OPEN c_asg;
3765     FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
3766     IF c_asg%NOTFOUND THEN
3767       CLOSE c_asg;
3768       hr_utility.set_location('error', 20);
3769       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
3770       fnd_message.set_token('PROC', l_proc);
3771       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
3772       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
3773       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
3774       RAISE ben_manage_life_events.g_record_error;
3775     END IF;
3776     CLOSE c_asg;
3777     hr_utility.set_location('close c_asg: ' || l_proc, 10);
3778     --
3779     -- Determine if the person is currently enrolled and if so
3780     -- determine the coverage start date.
3781     --
3782     IF p_run_mode in ('M','U') then
3783        l_cvg_dt := l_lf_evt_ocrd_dt;
3784     ELSE
3785        l_cvg_dt := l_lf_evt_ocrd_dt_1;
3786     END IF;
3787 
3788   IF p_run_mode <> 'D' THEN
3789    --
3790     IF (p_oipl_id IS NULL)  THEN
3791       --
3792       OPEN c_plan_enrolment_info(l_cvg_dt);
3793       --
3794       FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
3795                                      l_crnt_erlst_deenrt_dt,
3796                                      l_prtt_enrt_rslt_id,
3797                                      l_enrt_ovridn_flag,
3798                                      l_enrt_ovrid_thru_dt,
3799                                      l_orgnl_enrt_dt,
3800                                      l_crnt_enrt_cvg_thru_dt,  --BUG 6519487 fix
3801                                      l_current_pl_typ_id ;  --BUG 6519487 fix
3802       --
3803       IF c_plan_enrolment_info%NOTFOUND THEN
3804         --
3805         l_crnt_enrt_cvg_strt_dt :=  NULL;
3806         --
3807         --  Check if person is a covered dependent - COBRA.
3808         --
3809         IF p_pgm_id IS NOT NULL THEN
3810           IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
3811             OPEN c_plan_cvg_info;
3812             FETCH c_plan_cvg_info INTO l_dpnt_cvrd_flag;
3813             CLOSE c_plan_cvg_info;
3814           END IF;
3815         END IF;
3816       --
3817       ELSE
3818         --BUG 6519487 fix
3819         IF l_crnt_enrt_cvg_thru_dt <> hr_api.g_eot THEN
3820           OPEN c_future_results (p_person_id ,
3821                              l_crnt_enrt_cvg_thru_dt,
3822                              p_pgm_id   ,
3823                              l_current_pl_typ_id) ;
3824           --
3825           FETCH c_future_results INTO l_dummy_varchar;
3826           IF c_future_results%FOUND THEN
3827              --
3828              l_crnt_enrt_cvg_strt_dt := null;
3829              l_crnt_erlst_deenrt_dt := null;
3830              l_prtt_enrt_rslt_id := null;
3831              l_enrt_ovridn_flag := null;
3832              l_enrt_ovrid_thru_dt := null;
3833              l_crnt_enrt_cvg_thru_dt := null;
3834              --
3835           END IF;
3836           --
3837           CLOSE c_future_results ;
3838         END IF;
3839         --END BUG 6519487 fix
3840         --
3841       END IF;
3842       --
3843       CLOSE c_plan_enrolment_info;
3844       if g_debug then
3845       hr_utility.set_location('close c_PEI: ' || l_proc, 10);
3846       end if;
3847     --
3848     ELSE
3849       --
3850       OPEN c_oipl_enrolment_info(l_cvg_dt);
3851       --
3852       FETCH c_oipl_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
3853                                        l_crnt_erlst_deenrt_dt,
3854                                        l_prtt_enrt_rslt_id,
3855                                        l_enrt_ovridn_flag,
3856                                        l_enrt_ovrid_thru_dt,
3857                                        l_crnt_enrt_cvg_thru_dt, --BUG 6519487 fix
3858                                        l_current_pl_typ_id;   --BUG 6519487 fix      --
3859       IF c_oipl_enrolment_info%NOTFOUND THEN
3860         --
3861         l_crnt_enrt_cvg_strt_dt :=  NULL;
3862         --
3863         --  Check if person is a covered dependent - COBRA.
3864         --
3865         IF p_pgm_id IS NOT NULL THEN
3866           IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
3867             OPEN c_oipl_cvg_info;
3868             FETCH c_oipl_cvg_info INTO l_dpnt_cvrd_flag;
3869             CLOSE c_oipl_cvg_info;
3870           END IF;
3871         END IF;
3872       --
3873       ELSE
3874       ----BUG 6519487 fix
3875         IF l_crnt_enrt_cvg_thru_dt <> hr_api.g_eot THEN
3876           OPEN c_future_results (p_person_id ,
3877                                l_crnt_enrt_cvg_thru_dt,
3878                                p_pgm_id   ,
3879                                l_current_pl_typ_id) ;
3880           --
3881           FETCH c_future_results INTO l_dummy_varchar;
3882           IF c_future_results%FOUND THEN
3883              --
3884              l_crnt_enrt_cvg_strt_dt := null;
3885              l_crnt_erlst_deenrt_dt := null;
3886              l_prtt_enrt_rslt_id := null;
3887              l_enrt_ovridn_flag := null;
3888              l_enrt_ovrid_thru_dt := null;
3889              l_crnt_enrt_cvg_thru_dt := null;
3890              --
3891           END IF;
3892           CLOSE c_future_results ;
3893         END IF;
3894         --END BUG 6519487 fix
3895       --
3896       END IF;
3897       --
3898       CLOSE c_oipl_enrolment_info;
3899       if g_debug then
3900       hr_utility.set_location('close c_OIEI: ' || l_proc, 10);
3901       end if;
3902     --
3903     END IF;
3904     --
3905   END IF;
3906     -- Bug 2200139 For Override don't associate the current enrollment
3907     --
3908     if p_run_mode = 'V' then
3909       --
3910       l_crnt_enrt_cvg_strt_dt := null;
3911       l_prtt_enrt_rslt_id := null;
3912       --
3913     end if;
3914     --
3915     -- unrestricted process changes
3916     -- if mode is unrestricted and crnt_enrt_strt_date > p_effective_date assign null
3917     -- as unrestricted may be processed before the previously processed life event
3918     --
3919     if p_run_mode = 'U' then
3920         --
3921         if l_crnt_enrt_cvg_strt_dt is not null  then
3922             --
3923             --  Bug 2290302 see the Bug for datails. We cann't have this
3924             -- condition as user may have the coverage started in future
3925             -- for the current enrollment.
3926             -- if l_crnt_enrt_cvg_strt_dt > p_effective_date then
3927             --    l_crnt_enrt_cvg_strt_dt := null;
3928             --    l_prtt_enrt_rslt_id := null;
3929             --
3930             -- else
3931                --
3932                open c_prtt_enrt_rslt(l_prtt_enrt_rslt_id);
3933                fetch c_prtt_enrt_rslt into l_effective_start_date;
3934                close c_prtt_enrt_rslt;
3935                --
3936                if l_effective_start_date > p_effective_date then
3937                   l_crnt_enrt_cvg_strt_dt := null;
3938                   l_prtt_enrt_rslt_id := null;
3939                end if;
3940               --
3941             --  end if;
3942         end if;
3943     end if;
3944     --
3945     -- Determine if the person is eligible for this compensation object.
3946     --
3947     ben_pep_cache.get_currpepepo_dets
3948       (p_comp_obj_tree_row => p_comp_obj_tree_row
3949       ,p_per_in_ler_id     => p_per_in_ler_id
3950       ,p_effective_date    => p_effective_date
3951       ,p_pgm_id            => p_pgm_id
3952       ,p_pl_id             => l_pl_id
3953       ,p_oipl_id           => p_oipl_id
3954       ,p_opt_id            => l_opt_id
3955       --
3956       ,p_inst_row          => l_currpep_dets
3957       );
3958     --
3959     IF l_currpep_dets.elig_per_id is null THEN
3960       --
3961       l_current_eligibility :=  'N';
3962       --
3963       If NVL(l_currpep_dets.inelg_rsn_cd, 'OTH') = 'OTH'
3964         and nvl(ben_evaluate_elig_profiles.g_inelg_rsn_cd,'OTH') <> 'OTH'
3965         and p_run_mode = 'W'
3966       then     -- Bug 4447114, If condition added
3967           l_inelg_rsn_cd	      := ben_evaluate_elig_profiles.g_inelg_rsn_cd ;
3968       else
3969           l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd ;
3970       end if;
3971       --
3972     else
3973       --
3974       l_elig_per_id           := l_currpep_dets.elig_per_id;
3975       l_current_eligibility   := l_currpep_dets.elig_flag;
3976       l_must_enrl_anthr_pl_id := l_currpep_dets.must_enrl_anthr_pl_id;
3977       l_prtn_strt_dt          := l_currpep_dets.prtn_strt_dt;
3978       --l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd;      -- 2650247
3979       --
3980       If NVL(l_currpep_dets.inelg_rsn_cd, 'OTH') = 'OTH'
3981         and nvl(ben_evaluate_elig_profiles.g_inelg_rsn_cd,'OTH') <> 'OTH'
3982         and p_run_mode = 'W'
3983       then  -- Bug 4447114, If condition added
3984           l_inelg_rsn_cd	      := ben_evaluate_elig_profiles.g_inelg_rsn_cd ;
3985       else
3986           l_inelg_rsn_cd	      := l_currpep_dets.inelg_rsn_cd ;
3987       end if;
3988       --
3989     END IF;
3990     if g_debug then
3991     hr_utility.set_location('Got passed initial comp loads', 21);
3992     end if;
3993     --
3994     -- If the current_eligibility is N, DONE, no choice is required.
3995     --  ...(12/23/1998 except when overridden, and thru date >= ed jcarpent)
3996     --
3997     -- combine both ovrid(n) fields into one as to simplify for use
3998     -- further down in the code.
3999     --
4000     IF (
4001              l_enrt_ovridn_flag = 'Y'
4002          AND l_enrt_ovrid_thru_dt >= NVL(p_lf_evt_ocrd_dt, p_effective_date)) THEN
4003       l_enrt_ovridn_flag :=  'Y';
4004     ELSE
4005       l_enrt_ovridn_flag :=  'N';
4006     END IF;
4007     --
4008     -- Now, can we elect?
4009     --
4010      --cwb changes
4011      --Bug 2200139 Override Enrollment Changes
4012     IF l_current_eligibility = 'N'
4013        AND l_enrt_ovridn_flag = 'N' and p_run_mode <> 'W' and p_run_mode <> 'V' THEN
4014       --
4015       p_electable_flag :=  'N';
4016       --
4017       if g_debug then
4018       hr_utility.set_location(' Leaving:' || l_proc, 15);
4019       end if;
4020       --
4021       RETURN;
4022     --
4023     END IF;
4024     --
4025     --
4026     -- Determine if the person was previously eligible for this comp object.
4027     --
4028   IF p_run_mode <> 'D' THEN
4029    --
4030     IF (p_oipl_id IS NULL) THEN
4031       --
4032       ben_pep_cache.get_pilpep_dets
4033         (p_person_id         => p_person_id
4034         ,p_business_group_id => p_business_group_id
4035         ,p_effective_date    => l_effective_date_1
4036         ,p_pgm_id            => p_pgm_id
4037         ,p_pl_id             => l_pl_id
4038         ,p_plip_id           => null
4039         ,p_ptip_id           => null
4040         ,p_inst_row          => l_prevpep_rec
4041         );
4042       --
4043       if l_prevpep_rec.elig_flag is null
4044       then
4045         --
4046         l_previous_eligibility := 'N';
4047         --
4048       else
4049         --
4050         l_previous_eligibility := l_prevpep_rec.elig_flag;
4051         --
4052       end if;
4053       --
4054       if g_debug then
4055       hr_utility.set_location('close c_PEFP: ' || l_proc, 10);
4056       end if;
4057       --
4058     ELSE
4059       --
4060       ben_pep_cache.get_pilepo_dets
4061         (p_person_id         => p_person_id
4062         ,p_business_group_id => p_business_group_id
4063         ,p_effective_date    => l_effective_date_1 --p_effective_date
4064         ,p_pgm_id            => p_comp_obj_tree_row.par_pgm_id
4065         ,p_pl_id             => p_comp_obj_tree_row.par_pl_id
4066         ,p_opt_id            => p_comp_obj_tree_row.par_opt_id
4067         --
4068         ,p_inst_row          => l_prevepo_rec
4069         );
4070       --
4071       if l_prevepo_rec.elig_flag is null
4072       then
4073         --
4074         l_previous_eligibility := 'N';
4075         --
4076       else
4077         --
4078         l_previous_eligibility := l_prevepo_rec.elig_flag;
4079         --
4080       end if;
4081       --
4082       if g_debug then
4083       hr_utility.set_location('close c_PEFO: ' || l_proc, 10);
4084       end if;
4085       --
4086     END IF;
4087     --
4088   END IF;  --'D' mode
4089   if g_debug then
4090     hr_utility.set_location('get plan info', 10);
4091   end if;
4092     --
4093     -- get plan_info
4094     --
4095     l_pl_name :=                  l_plan_rec.name;
4096     l_pl_typ_id :=                l_plan_rec.pl_typ_id;
4097     l_pl_enrt_cd :=               l_plan_rec.enrt_cd;
4098     l_pl_enrt_rl :=               l_plan_rec.enrt_rl;
4099     l_pl_enrt_mthd_cd :=          l_plan_rec.enrt_mthd_cd;
4100     l_pl_auto_enrt_rl :=          l_plan_rec.auto_enrt_mthd_rl;
4101     l_invk_flx_cr_pl_flag :=      l_plan_rec.invk_flx_cr_pl_flag;
4102     l_imptd_incm_calc_cd :=       l_plan_rec.imptd_incm_calc_cd;
4103     l_pl_trk_inelig_per_flag :=   l_plan_rec.trk_inelig_per_flag;
4104     --
4105     -- If a pgm_id was passed
4106     --
4107     IF (p_pgm_id IS NOT NULL) THEN
4108       --
4109       -- Find the plip and get its needed attributes.
4110       --
4111       OPEN c_plip_info;
4112       --
4113       FETCH c_plip_info INTO l_plip_id,
4114                              l_plip_dflt_flag,
4115                              l_plip_enrt_cd,
4116                              l_plip_enrt_rl,
4117                              l_plip_enrt_mthd_cd,
4118                              l_plip_auto_enrt_rl,
4119                              l_alws_unrstrctd_enrt_flag,
4120                              l_plip_esd,
4121                              l_plip_eed,
4122                              l_plip_ordr_num;
4123       IF c_plip_info%NOTFOUND THEN
4124         --
4125         fnd_message.set_name('BEN', 'BEN_91461_PLIP_MISSING');
4126         fnd_message.set_token('PROC', l_proc);
4127         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
4128         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
4129         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4130         RAISE ben_manage_life_events.g_record_error;
4131       --
4132       END IF;
4133       --
4134       CLOSE c_plip_info;
4135       if g_debug then
4136       hr_utility.set_location('close c_plip_info: ' || l_proc, 10);
4137       end if;
4138       --
4139       -- Find the ptip and get its needed attributes.
4140       --
4141       OPEN c_ptip_info;
4142       --
4143       FETCH c_ptip_info INTO l_ptip_id,
4144                              l_ptip_enrt_cd,
4145                              l_ptip_enrt_rl,
4146                              l_ptip_enrt_mthd_cd,
4147                              l_ptip_auto_enrt_rl,
4148                              l_ptip_esd,
4149                              l_ptip_eed,
4150                              l_ptip_ordr_num;
4151       --
4152       IF c_ptip_info%NOTFOUND THEN
4153         --
4154         fnd_message.set_name('BEN', 'BEN_91462_PTIP_MISSING');
4155         fnd_message.set_token('PROC', l_proc);
4156         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
4157         fnd_message.set_token('PL_TYP_ID', TO_CHAR(l_pl_typ_id));
4158         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4159         RAISE ben_manage_life_events.g_record_error;
4160       --
4161       END IF;
4162       --
4163       CLOSE c_ptip_info;
4164       if g_debug then
4165       hr_utility.set_location('close c_ptip_info: ' || l_proc, 10);
4166       end if;
4167     --
4168     END IF;
4169 --
4170 -- Unrestricted processing
4171 --   for mode of U only let qualified plans through
4172 --   for other modes if plan is unrestricted process
4173 --   as normally do (i.e. set l_unrestricted_enrt_flag
4174 --   to 'N')
4175 --
4176 -- mode=U   unres_flag=Y   set flag   return
4177 --    N          N            N          N
4178 --    N          Y            N          N
4179 --    Y          N            n/a        Y
4180 --    Y          Y            Y          N
4181 --
4182     IF (p_pgm_id IS NULL) THEN
4183       l_alws_unrstrctd_enrt_flag :=  l_plan_rec.alws_unrstrctd_enrt_flag;
4184       if g_debug then
4185       hr_utility.set_location(
4186         'alws_unres_flag=' || l_alws_unrstrctd_enrt_flag,
4187         10);
4188       end if;
4189     END IF;
4190     --
4191     -- all that to do this
4192     --
4193     IF p_run_mode in ('U','D') THEN
4194       IF l_alws_unrstrctd_enrt_flag = 'Y' THEN
4195         l_unrestricted_enrt_flag :=  'Y';
4196 	if g_debug then
4197         hr_utility.set_location(
4198           'Unrestricted mode in force for this plan',
4199           10);
4200         end if;
4201       ELSE
4202         p_electable_flag :=  'N';
4203 	if g_debug then
4204         hr_utility.set_location('Unrestricted mode not for regular plans', 10);
4205 	end if;
4206         RETURN;
4207       END IF;
4208     ELSE
4209       l_unrestricted_enrt_flag :=  'N';
4210     END IF;
4211     --
4212     if g_debug then
4213     hr_utility.set_location('per in ler info', 20);
4214     end if;
4215     --
4216     -- Bug 2200139  this cursor is getting the Started Perinler info.
4217     -- for Override Mode we get the info of the p_ler_in_ler_id
4218     if p_run_mode = 'V' then
4219       OPEN c_ovrd_per_in_ler_info;
4220       --
4221       FETCH c_ovrd_per_in_ler_info INTO l_per_in_ler_id,
4222                                    l_ler_typ_cd,
4223                                    l_ler_name,
4224                                    l_lf_evt_ocrd_dt_fetch,
4225                                    l_ler_esd,
4226                                    l_ler_eed;
4227       --
4228       IF c_ovrd_per_in_ler_info%NOTFOUND THEN
4229         --
4230         fnd_message.set_name('BEN', 'BEN_91272_PER_IN_LER_MISSING');
4231         fnd_message.set_token('PROC', l_proc);
4232         fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
4233         fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
4234         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
4235         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4236         RAISE ben_manage_life_events.g_record_error;
4237       --
4238       END IF;
4239       --
4240       CLOSE c_ovrd_per_in_ler_info;
4241       if g_debug then
4242       hr_utility.set_location('close c_PILI: ' || l_proc, 10);
4243       end if;
4244       --
4245     else
4246       --
4247       OPEN c_per_in_ler_info;
4248       --
4249       FETCH c_per_in_ler_info INTO l_per_in_ler_id,
4250                                  l_ler_typ_cd,
4251                                  l_ler_name,
4252                                  l_lf_evt_ocrd_dt_fetch,
4253                                  l_ler_esd,
4254                                  l_ler_eed;
4255       --
4256       IF c_per_in_ler_info%NOTFOUND THEN
4257         --
4258         fnd_message.set_name('BEN', 'BEN_91272_PER_IN_LER_MISSING');
4259         fnd_message.set_token('PROC', l_proc);
4260         fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
4261         fnd_message.set_token('LER_ID', TO_CHAR(p_ler_id));
4262         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
4263         fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
4264         RAISE ben_manage_life_events.g_record_error;
4265       --
4266       END IF;
4267       --
4268       CLOSE c_per_in_ler_info;
4269     end if;
4270     if g_debug then
4271     hr_utility.set_location('close c_PILI: ' || l_proc, 10);
4272     end if;
4273     --
4274 
4275     OPEN c_pl_popl_yr_period_current;
4276     --
4277     FETCH c_pl_popl_yr_period_current INTO l_yr_perd_id,
4278                                            l_popl_yr_perd_id,
4279                                            l_yr_perd_strt_date,
4280                                            l_yr_perd_end_date,
4281                                            l_popl_yr_perd_ordr_num;
4282     --
4283     IF ((c_pl_popl_yr_period_current%NOTFOUND) and (p_run_mode not in ('G','D'))) THEN
4284       --
4285       fnd_message.set_name('BEN', 'BEN_91334_PLAN_YR_PERD');
4286       fnd_message.set_token('PROC', l_proc);
4287       RAISE ben_manage_life_events.g_record_error;
4288     --
4289     END IF;
4290     --
4291     CLOSE c_pl_popl_yr_period_current;
4292     if g_debug then
4293     hr_utility.set_location('close c_PPYPC: ' || l_proc, 10);
4294     --
4295     hr_utility.set_location('oipl id is null', 20);
4296     end if;
4297     ben_epe_cache.get_pilcobjepe_dets
4298       (p_per_in_ler_id => p_per_in_ler_id
4299       ,p_pgm_id        => p_pgm_id
4300       ,p_pl_id         => l_pl_id
4301       ,p_oipl_id       => p_oipl_id
4302       --
4303       ,p_inst_row      => l_currepe_dets
4304       );
4305     --
4306     IF l_currepe_dets.elig_per_elctbl_chc_id is not null and
4307          p_run_mode not in ('U','R','D') THEN
4308       --
4309       fnd_message.set_name('BEN', 'BEN_91463_ELCTBL_CHC_EXISTS');
4310       fnd_message.set_token('PROC', l_proc);
4311       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
4312       if g_debug then
4313       hr_utility.set_location('Leaving: ' || l_proc, 20);
4314       end if;
4315       p_electable_flag :=  'N';
4316       RETURN;
4317       --
4318     --bug#4096382
4319     elsif  l_currepe_dets.elig_per_elctbl_chc_id is not null and
4320          p_run_mode in ('U','R') THEN
4321        --
4322        l_epe_exists :=  ben_manage_unres_life_events.epe_exists
4323                          (p_per_in_ler_id => l_per_in_ler_id,
4324                           p_pgm_id => p_pgm_id,
4325                           p_pl_id  => l_pl_id,
4326                           p_oipl_id =>p_oipl_id);
4327        --
4328        if l_epe_Exists is null then  -- comp object in pgm/plnot in pgm  is in pending or suspended status
4329          --
4330           p_electable_flag :=  'N';
4331           RETURN;
4332          --
4333        end if;
4334        --
4335     END IF;
4336     --
4337     -- do prerequisite check if not overridden.
4338     --
4339     if g_debug then
4340     hr_utility.set_location('enroll another plan', 20);
4341     end if;
4342     IF     l_must_enrl_anthr_pl_id IS NOT NULL
4343        AND l_enrt_ovridn_flag = 'N'
4344     THEN
4345       --
4346       -- Get the current electable choice info for the comp object
4347       --
4348       ben_epe_cache.get_pilcobjepe_dets
4349         (p_per_in_ler_id => p_per_in_ler_id
4350         ,p_pgm_id        => p_pgm_id
4351         ,p_pl_id         => l_must_enrl_anthr_pl_id
4352         ,p_oipl_id       => null
4353         --
4354         ,p_inst_row      => l_currepe_dets
4355         );
4356       --
4357       IF l_currepe_dets.elig_per_elctbl_chc_id is null THEN
4358         --
4359         -- prereq not found recurse.
4360         --
4361         enrolment_requirements
4362           (p_comp_obj_tree_row      => p_comp_obj_tree_row
4363           ,p_run_mode               => p_run_mode
4364           ,p_business_group_id      => p_business_group_id
4365           ,p_effective_date         => p_effective_date
4366           ,p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt
4367           ,p_ler_id                 => p_ler_id
4368           ,p_per_in_ler_id          => p_per_in_ler_id
4369           ,p_person_id              => p_person_id
4370           ,p_pl_id                  => l_must_enrl_anthr_pl_id
4371           ,p_pgm_id                 => p_pgm_id
4372           ,p_oipl_id                => NULL
4373           ,p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id
4374           ,p_electable_flag         => l_prereq_electable_flag
4375           -- ,p_popl_enrt_typ_cycl_id  => p_popl_enrt_typ_cycl_id
4376           );
4377       if g_debug then
4378         hr_utility.set_location('Dn Sub BENDENRR: ' || l_proc, 99);
4379       end if;
4380         --
4381         IF l_prereq_electable_flag = 'N' THEN
4382           --
4383           p_electable_flag :=  'N';
4384 	  if g_debug then
4385           hr_utility.set_location('Not electable since prereq is not.', 10);
4386 	  end if;
4387           RETURN;
4388         --
4389         END IF;
4390       --
4391       END IF;
4392       --
4393       if g_debug then
4394       hr_utility.set_location('close c_CHEFP: ' || l_proc, 10);
4395       --
4396       hr_utility.set_location('found prereq plan choice', 10);
4397     --
4398       end if;
4399     END IF;                                                   -- prereq exists.
4400     --
4401     -- Determine if the compensation object requires or allows an election change
4402     -- If life event mode
4403     --
4404     if g_debug then
4405     hr_utility.set_location('ler change stuff', 20);
4406     end if;
4407     l_ler_chg_found_flag :=       'N';
4408     l_ler_chg_oipl_found_flag :=  'N';
4409     --
4410     -- See if there is a life event reason to change
4411     --
4412     if g_debug then
4413     hr_utility.set_location('ler change stuff not null stuff', 20);
4414     hr_utility.set_location(' Op c_lce_info: ' || l_proc, 10);
4415     end if;
4416     --
4417  IF p_run_mode <> 'D' THEN
4418   --
4419     determine_ben_settings(
4420       p_pl_id                     => l_pl_id,
4421       p_ler_id                    => p_ler_id,
4422       p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
4423       p_ptip_id                   => l_ptip_id,
4424       p_pgm_id                    => p_pgm_id,
4425       p_plip_id                   => l_plip_id,
4426       p_oipl_id                   => p_oipl_id,
4427       p_just_prclds_chg_flag      => FALSE,
4428       p_enrt_cd                   => l_ler_enrt_cd,
4429       p_enrt_rl                   => l_ler_enrt_rl,
4430       p_auto_enrt_mthd_rl         => l_ler_auto_enrt_rl,
4431       p_crnt_enrt_prclds_chg_flag => l_ler_enrt_prclds_chg_flag,
4432       p_dflt_flag                 => l_ler_dflt_flag,
4433       p_enrt_mthd_cd              => l_ler_enrt_mthd_cd,
4434       p_stl_elig_cant_chg_flag    => l_ler_stl_elig_cant_chg_flag,
4435       p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
4436       p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
4437       p_ler_chg_found_flag        => l_ler_chg_found_flag,
4438       p_enrt_cd_level             => l_enrt_cd_level );
4439    --
4440    if g_debug then
4441     hr_utility.set_location(' Cl c_lce_info: ' || l_proc, 10);
4442    end if;
4443     --
4444       -- Determine enrt codes/rules method codes/rules then
4445     -- figure out if electable.
4446     --
4447     --
4448     -- Initially set to ler_chg values if not null
4449     --
4450     IF l_ler_enrt_cd IS NOT NULL THEN
4451       l_pl_enrt_cd :=  l_ler_enrt_cd;
4452       l_pl_enrt_rl :=  l_ler_enrt_rl;
4453     ELSIF l_oipl_rec.enrt_cd IS NOT NULL THEN
4454       l_pl_enrt_cd :=  l_oipl_rec.enrt_cd;
4455       l_pl_enrt_rl :=  l_oipl_rec.enrt_rl;
4456     END IF;
4457     IF p_oipl_id IS NULL THEN
4458       IF    l_ler_enrt_mthd_cd IS NOT NULL
4459          OR l_ler_auto_enrt_rl IS NOT NULL THEN
4460         l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
4461         l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
4462       END IF;
4463     ELSE
4464       --
4465       -- below, if ler_chg row found then code will always
4466       -- be not null since comes from a decode of the flag.
4467       --
4468       IF l_ler_chg_oipl_found_flag = 'Y' THEN
4469         l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
4470         l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
4471         --
4472         IF l_ler_enrt_mthd_cd = 'A' THEN
4473           --
4474           l_oipl_auto_enrt_flag :=  'Y';
4475         --
4476         ELSE
4477           --
4478           l_oipl_auto_enrt_flag :=  'N';
4479         --
4480         END IF;
4481       --
4482       ELSE
4483         IF l_oipl_auto_enrt_flag = 'Y' THEN
4484           l_pl_enrt_mthd_cd :=  'A';
4485         ELSE
4486           l_pl_enrt_mthd_cd :=  'E';
4487         END IF;
4488         l_pl_auto_enrt_rl :=  l_oipl_auto_enrt_mthd_rl;
4489       END IF;
4490     END IF;
4491     --
4492     -- If the ler_chg values were null then now have plan values
4493     --
4494     -- Update if still null with values from above in hierarchy
4495     --
4496     IF     l_pl_enrt_cd IS NULL
4497        AND p_pgm_id IS NOT NULL THEN
4498       l_pl_enrt_cd :=  l_plip_enrt_cd;
4499       l_pl_enrt_rl :=  l_plip_enrt_rl;
4500     END IF;
4501     IF     l_pl_enrt_mthd_cd IS NULL
4502        AND p_pgm_id IS NOT NULL THEN
4503       l_pl_enrt_mthd_cd :=  l_plip_enrt_mthd_cd;
4504       l_pl_auto_enrt_rl :=  l_plip_auto_enrt_rl;
4505     END IF;
4506     --
4507     -- overlay ptip if value is still null
4508     --
4509     IF     l_pl_enrt_cd IS NULL
4510        AND p_pgm_id IS NOT NULL THEN
4511       l_pl_enrt_cd :=  l_ptip_enrt_cd;
4512       l_pl_enrt_rl :=  l_ptip_enrt_rl;
4513     END IF;
4514     IF     l_pl_enrt_mthd_cd IS NULL
4515        AND p_pgm_id IS NOT NULL THEN
4516       l_pl_enrt_mthd_cd :=  l_ptip_enrt_mthd_cd;
4517       l_pl_auto_enrt_rl :=  l_ptip_auto_enrt_rl;
4518     END IF;
4519     --
4520     -- get from program level if not at plan or plip or ptip levels
4521     --
4522     IF     l_pl_enrt_cd IS NULL
4523        AND p_pgm_id IS NOT NULL THEN
4524       l_pl_enrt_cd :=  l_pgm_rec.enrt_cd;
4525       l_pl_enrt_rl :=  l_pgm_rec.enrt_rl;
4526     END IF;
4527     IF     l_pl_enrt_mthd_cd IS NULL
4528        AND p_pgm_id IS NOT NULL THEN
4529       l_pl_enrt_mthd_cd :=  l_pgm_rec.enrt_mthd_cd;
4530       l_pl_auto_enrt_rl :=  l_pgm_rec.auto_enrt_mthd_rl;
4531     END IF;
4532     --
4533     -- Catch all default to explicit
4534     --
4535     --
4536     -- evaluate the rule and see what it returns that
4537     -- will take precedence over previous value.
4538     --
4539     IF l_pl_auto_enrt_rl IS NOT NULL THEN
4540       --
4541       -- Use the results of the enrt_mthd_rl as the code
4542       --
4543       if g_debug then
4544       hr_utility.set_location(' Exe enrt rl: ' || l_proc, 10);
4545       end if;
4546        execute_auto_dflt_enrt_rule(
4547          p_opt_id            => l_opt_id,
4548          p_pl_id             => l_pl_id,
4549          p_pgm_id            => p_pgm_id,
4550          p_rule_id           => l_pl_auto_enrt_rl,
4551          p_ler_id            => p_ler_id,
4552          p_pl_typ_id         => l_pl_typ_id,
4553          p_business_group_id => p_business_group_id,
4554          p_effective_date    => p_effective_date,
4555          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
4556          p_elig_per_id       => l_elig_per_id,
4557          p_assignment_id     => l_rec_assignment_id,
4558          p_organization_id   => l_rec_organization_id,
4559          p_jurisdiction_code => l_jurisdiction_code,
4560 	 p_person_id         => p_person_id,            -- Bug 5331889
4561          p_enrt_mthd         => l_pl_enrt_mthd_cd,
4562          p_reinstt_dpnt      => l_reinstt_flag
4563          );
4564      if g_debug then
4565       hr_utility.set_location(' Dn Exe enrt rl: ' || l_proc, 10);
4566      end if;
4567         --
4568       l_reinstt_cd := l_reinstt_flag;
4569       --
4570       -- Following if for backward compatability only
4571       -- in future will return A/E.
4572       --
4573       IF l_pl_enrt_mthd_cd = 'N' THEN
4574         --
4575         l_pl_enrt_mthd_cd :=  'E';
4576       ELSIF l_pl_enrt_mthd_cd = 'Y' THEN
4577         l_pl_enrt_mthd_cd :=  'A';
4578       END IF;
4579       --
4580       IF p_oipl_id IS NOT NULL THEN
4581         IF l_pl_enrt_mthd_cd = 'A' THEN
4582           l_oipl_auto_enrt_flag :=  'Y';
4583         ELSE
4584           l_oipl_auto_enrt_flag :=  'N';
4585         END IF;
4586       END IF;
4587     END IF;
4588     --
4589     IF l_pl_enrt_mthd_cd IS NULL THEN
4590       l_pl_enrt_mthd_cd :=  'E';
4591     END IF;
4592     --
4593 END IF; -- 'D' Mode
4594     -- New Enrollment Code for changing coverage start date for currently enrolled comp.objects
4595     if l_pl_enrt_cd = 'CCKCSNCC' then
4596       l_new_cvg_strt := 'Y';
4597     end if;
4598     -- Don't check electability if automatic enrollment or
4599     --   only check it if explicit enrollment
4600     --
4601     -- Bug 2200139 for Override don't check electability but
4602     -- set the electable flag to 'N' so that users don't see these
4603     -- choices in the view person life events and enrollment forms.
4604     --
4605     if p_run_mode = 'V' then
4606       --
4607       l_rec_elctbl_flag := 'N' ;
4608       --
4609     else
4610       --
4611       --
4612       if g_debug then
4613       hr_utility.set_location('H', 20);
4614       hr_utility.set_location('Call detenr 2: ' || l_proc, 10);
4615       end if;
4616       g_ptip_id :=                  l_ptip_id;
4617       --
4618       --Bug 2677804 We dont need to get electable flag for the
4619       --pl/oipl if l_enrt_ovridn_flag is 'Y'
4620       --We need to make it electable
4621       --
4622       if l_enrt_ovridn_flag = 'Y' then
4623         --
4624 	if g_debug then
4625         hr_utility.set_location('First Electable Due to Override ' ,123);
4626 	end if;
4627         l_rec_elctbl_flag :=  'Y' ;
4628         --
4629       else
4630         --
4631         determine_enrolment(
4632           p_previous_eligibility   => l_previous_eligibility,
4633           p_crnt_enrt_cvg_strt_dt  => l_crnt_enrt_cvg_strt_dt,
4634           p_dpnt_cvrd_flag         => l_dpnt_cvrd_flag,
4635           p_person_id              => p_person_id,
4636           p_ler_id                 => p_ler_id,
4637           p_enrt_cd                => l_pl_enrt_cd,
4638           p_enrt_rl                => l_pl_enrt_rl,
4639           p_enrt_mthd_cd           => l_pl_enrt_mthd_cd,
4640           p_auto_enrt_mthd_rl      => l_pl_auto_enrt_rl,
4641           p_effective_date         => p_effective_date,
4642           p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4643           p_enrt_prclds_chg_flag   => NVL(l_ler_enrt_prclds_chg_flag, 'N'),
4644           p_stl_elig_cant_chg_flag => NVL(l_ler_stl_elig_cant_chg_flag, 'N'),
4645           p_tco_chg_enrt_cd        => NVL(l_tco_chg_enrt_cd, 'CPOO'),
4646           p_pl_id                  => l_pl_id,
4647           p_pgm_id                 => p_pgm_id,
4648           p_oipl_id                => p_oipl_id,
4649           p_opt_id                 => l_opt_id,
4650           p_pl_typ_id              => l_pl_typ_id,
4651           p_business_group_id      => p_business_group_id,
4652           p_electable_flag         => l_rec_elctbl_flag,
4653           p_assignment_id          => l_rec_assignment_id,
4654           p_run_mode               => p_run_mode);   -- iRec
4655      if g_debug then
4656         hr_utility.set_location('Dn detenr 2: ' || l_proc, 10);
4657      end if;
4658       end if;
4659       -- End Bug 2677804
4660       IF l_rec_elctbl_flag = 'Y' THEN
4661         --
4662         -- continue
4663         --
4664         NULL;
4665       --
4666       ELSIF l_rec_elctbl_flag = 'L' THEN
4667         --
4668         -- Lose only condition.
4669         -- If enrolled will deenroll.
4670         --
4671         ben_newly_ineligible.main(
4672           p_person_id         => p_person_id,
4673           p_pgm_id            => p_pgm_id,
4674           p_pl_id             => p_pl_id,
4675           p_oipl_id           => p_oipl_id,
4676           p_business_group_id => p_business_group_id,
4677           p_ler_id            => p_ler_id,
4678           p_effective_date    => p_effective_date);
4679         p_electable_flag :=  'N';
4680 	if g_debug then
4681         hr_utility.set_location('Dn BNI_MN: ' || l_proc, 10);
4682 	end if;
4683         RETURN;
4684         --
4685       ELSIF l_pl_enrt_mthd_cd = 'A' THEN
4686         --
4687         -- Leave as choice and use elctbl_flag
4688         --
4689         NULL;
4690         --
4691       ELSIF l_crnt_enrt_cvg_strt_dt IS NOT NULL THEN
4692         --
4693         -- if currently enrolled then create the choice
4694         -- and don't exit
4695         --
4696         l_rec_elctbl_flag :=  'N';
4697         --
4698       ELSIF    l_plan_rec.invk_flx_cr_pl_flag = 'Y'
4699             OR l_plan_rec.imptd_incm_calc_cd IN ('PRTT', 'DPNT', 'SPS') THEN
4700         l_rec_elctbl_flag :=  'N';
4701         --
4702       ELSE
4703         --
4704         p_electable_flag :=  'N';
4705         RETURN;
4706         --
4707       END IF;                                          -- determine_enrolment='Y'
4708       --
4709     end if;  -- Override Enrollment endif
4710     --
4711     -- Set p_electable flag back to 'N' if we are dealing with an automatic
4712     -- enrollment
4713     --
4714     IF l_pl_enrt_mthd_cd = 'A' THEN
4715       --
4716       l_auto_enrt_flag :=  'Y';
4717     --
4718     END IF;
4719     --
4720     -- Check level jumping restrictions
4721     --
4722     if g_debug then
4723     hr_utility.set_location(l_proc || ' Lev Jump OIPL ', 12);
4724     end if;
4725     IF p_oipl_id IS NOT NULL AND p_run_mode <> 'D' THEN
4726       --
4727       if g_debug then
4728       hr_utility.set_location('get ler bnft_rstrns ', 12);
4729       hr_utility.set_location(l_proc || ' Op c_ler_bnft_rstrn ', 12);
4730       end if;
4731       OPEN c_ler_bnft_rstrn;
4732       FETCH c_ler_bnft_rstrn INTO l_tmp_level,
4733                                   l_restriction_pgm_id,
4734                                   l_oipl_ordr_num,
4735                                   l_boo_rstrctn_cd,
4736                                   l_cvg_incr_r_decr_only_cd,
4737                                   l_mx_cvg_mlt_incr_num,
4738                                   l_mx_cvg_mlt_incr_wcf_num;
4739       --
4740       IF c_ler_bnft_rstrn%NOTFOUND THEN
4741         --
4742         CLOSE c_ler_bnft_rstrn;
4743         -- Romoved the commented code
4744         IF     ben_cobj_cache.g_plip_currow.plip_id = l_plip_id
4745            AND ben_cobj_cache.g_plip_currow.bnft_or_option_rstrctn_cd = 'OPT'
4746            AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_plip_currow.effective_start_date
4747            AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_plip_currow.effective_end_date
4748            AND ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
4749            AND ben_cobj_cache.g_oipl_currow.pl_id = ben_cobj_cache.g_plip_currow.pl_id
4750            AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_oipl_currow.effective_start_date
4751            AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_oipl_currow.effective_end_date THEN
4752           --
4753           l_tmp_level                := 2;
4754           l_restriction_pgm_id       := ben_cobj_cache.g_plip_currow.pgm_id;
4755           l_oipl_ordr_num            := ben_cobj_cache.g_oipl_currow.ordr_num;
4756           l_boo_rstrctn_cd           :=
4757                                        ben_cobj_cache.g_plip_currow.bnft_or_option_rstrctn_cd;
4758           l_cvg_incr_r_decr_only_cd  := ben_cobj_cache.g_plip_currow.cvg_incr_r_decr_only_cd;
4759           l_mx_cvg_mlt_incr_num      := ben_cobj_cache.g_plip_currow.mx_cvg_mlt_incr_num;
4760           l_mx_cvg_mlt_incr_wcf_num  := ben_cobj_cache.g_plip_currow.mx_cvg_mlt_incr_wcf_num;
4761         --
4762         ELSIF     ben_cobj_cache.g_pl_currow.pl_id = l_pl_id
4763               AND ben_cobj_cache.g_pl_currow.bnft_or_option_rstrctn_cd = 'OPT'
4764               AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_pl_currow.effective_start_date
4765               AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_pl_currow.effective_end_date
4766               AND ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
4767               AND ben_cobj_cache.g_oipl_currow.pl_id = ben_cobj_cache.g_pl_currow.pl_id
4768               AND l_lf_evt_ocrd_dt >= ben_cobj_cache.g_oipl_currow.effective_start_date
4769               AND l_lf_evt_ocrd_dt <= ben_cobj_cache.g_oipl_currow.effective_end_date THEN
4770           --
4771           l_tmp_level                := 1;
4772           l_restriction_pgm_id       := NULL;
4773           l_oipl_ordr_num            := ben_cobj_cache.g_oipl_currow.ordr_num;
4774           l_boo_rstrctn_cd           := ben_cobj_cache.g_pl_currow.bnft_or_option_rstrctn_cd;
4775           l_cvg_incr_r_decr_only_cd  := ben_cobj_cache.g_pl_currow.cvg_incr_r_decr_only_cd;
4776           l_mx_cvg_mlt_incr_num      := ben_cobj_cache.g_pl_currow.mx_cvg_mlt_incr_num;
4777           l_mx_cvg_mlt_incr_wcf_num  := ben_cobj_cache.g_pl_currow.mx_cvg_mlt_incr_wcf_num;
4778         --
4779         END IF;
4780       ELSE
4781         --
4782         CLOSE c_ler_bnft_rstrn;
4783       --
4784       END IF;
4785       if g_debug then
4786       hr_utility.set_location(l_proc || ' c_ler_bnft_rstrn ', 12);
4787       end if;
4788 /*  uncomment these for debuggin only
4789   hr_utility.set_location('l_plip_id -> '||l_plip_id,11);
4790   hr_utility.set_location('p_pgm_id -> '||p_pgm_id,11);
4791   hr_utility.set_location('l_restriction_pgm_id -> '||l_restriction_pgm_id,11);
4792   hr_utility.set_location('l_tmp_level -> '||l_tmp_level,11);
4793   hr_utility.set_location('l_oipl_ordr_num -> '||l_oipl_ordr_num,12);
4794   hr_utility.set_location('l_boo_rstrctn_cd -> '||l_boo_rstrctn_cd,12);
4795   hr_utility.set_location('l_cvg_incr_r_decr_only_cd -> '||l_cvg_incr_r_decr_only_cd,12);
4796   hr_utility.set_location('l_mx_cvg_mlt_incr_num -> '||l_mx_cvg_mlt_incr_num,12);
4797   hr_utility.set_location('l_mx_cvg_mlt_incr_wcf_num -> '||l_mx_cvg_mlt_incr_wcf_num,12);
4798 */
4799       IF l_boo_rstrctn_cd IS NOT NULL THEN
4800         --
4801         OPEN c_oipl_enrt_in_pl;
4802         FETCH c_oipl_enrt_in_pl INTO l_enrd_ordr_num;
4803         --
4804         --  For COBRA, also check elig_cvrd_dpnt as the person
4805         --  may be a dependent.
4806         --
4807         IF c_oipl_enrt_in_pl%NOTFOUND THEN
4808           IF p_pgm_id IS NOT NULL THEN
4809             IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
4810               OPEN c_oipl_cvg_in_pl;
4811               FETCH c_oipl_cvg_in_pl INTO l_enrd_ordr_num;
4812               CLOSE c_oipl_cvg_in_pl;
4813             END IF;
4814           END IF;
4815         END IF;
4816         CLOSE c_oipl_enrt_in_pl;
4817         --
4818         -- convert ordr_num to logical orD number
4819         l_cnt := 1;
4820         if l_oipl_ordr_num is not null then
4821           open c_opt_level;
4822           loop
4823             fetch c_opt_level into l_opt_level;
4824             if c_opt_level%Notfound then
4825                exit;
4826             end if;
4827          --   hr_utility.set_location('opt level'||l_opt_level,111);
4828 
4829             if l_opt_level = l_oipl_ordr_num then
4830                l_oipl_seq_num := l_cnt;
4831                l_found  := TRUE;
4832                exit;
4833             end if;
4834             l_cnt := l_cnt + 1;
4835           end loop;
4836           close c_opt_level;
4837           if not l_found then
4838              fnd_message.set_name('BEN','BEN_92699_SEQ_NUM_NOT_EXST');
4839              fnd_message.raise_error;
4840           end if;
4841         end if;
4842         --
4843         l_cnt := 1;
4844         l_found := FALSE;
4845         if l_enrd_ordr_num is not null then
4846           open c_opt_level;
4847           loop
4848             fetch c_opt_level into l_opt_level;
4849             if c_opt_level%Notfound then
4850                exit;
4851             end if;
4852          if g_debug then
4853             hr_utility.set_location('Enrd Ord'||l_enrd_ordr_num,113);
4854          end if;
4855             if l_opt_level = l_enrd_ordr_num then
4856                l_enrd_seq_num := l_cnt;
4857                l_found  := TRUE;
4858                exit;
4859             end if;
4860             l_cnt := l_cnt + 1;
4861           end loop;
4862           close c_opt_level;
4863           if not l_found then
4864              fnd_message.set_name('BEN','BEN_92699_SEQ_NUM_NOT_EXST');
4865              fnd_message.raise_error;
4866           end if;
4867         end if;
4868        --     End of Logical Ordr Num
4869 
4870         -- Check for conditions where no choice should be created (N above)
4871         --
4872         IF l_cvg_incr_r_decr_only_cd = 'MNAVLO' THEN
4873           --
4874           --  Minimum available.
4875           --
4876           OPEN c_get_min_max_ordr_num;
4877           FETCH c_get_min_max_ordr_num INTO l_mn_ordr_num, l_mx_ordr_num;
4878           CLOSE c_get_min_max_ordr_num;
4879           --
4880           IF l_oipl_ordr_num <> l_mn_ordr_num THEN
4881 	  if g_debug then
4882             hr_utility.set_location(
4883               'Level jumping to this object not allowed',
4884               12);
4885           end if;
4886             p_electable_flag :=  'N';
4887             RETURN;
4888           END IF;
4889 	  if g_debug then
4890           hr_utility.set_location('min avail', 12);
4891 	  end if;
4892         --
4893         ELSIF l_cvg_incr_r_decr_only_cd = 'MXAVLO' THEN
4894           --
4895           --  Maximum available.
4896           --
4897           OPEN c_get_min_max_ordr_num;
4898           FETCH c_get_min_max_ordr_num INTO l_mn_ordr_num, l_mx_ordr_num;
4899           CLOSE c_get_min_max_ordr_num;
4900           --
4901           IF l_oipl_ordr_num <> l_mx_ordr_num THEN
4902 	  if g_debug then
4903             hr_utility.set_location(
4904               'Level jumping to this object not allowed',
4905               12);
4906           end if;
4907             p_electable_flag :=  'N';
4908             RETURN;
4909           END IF;
4910 	  if g_debug then
4911           hr_utility.set_location('max avail', 12);
4912 	  end if;
4913         --
4914         ELSIF l_enrd_ordr_num IS NULL THEN
4915           --
4916           -- When person is not previously enrolled.
4917           --
4918 	  if g_debug then
4919           hr_utility.set_location('person not prev enrolled', 12);
4920 	  end if;
4921           p_electable_flag :=  'Y';
4922         --
4923         ELSIF (
4924                    (
4925                          l_cvg_incr_r_decr_only_cd = 'INCRO'
4926                      AND l_oipl_ordr_num <= l_enrd_ordr_num)
4927                 OR (
4928                          l_cvg_incr_r_decr_only_cd = 'EQINCR'
4929                      AND l_oipl_ordr_num < l_enrd_ordr_num)
4930                 OR (
4931                          l_cvg_incr_r_decr_only_cd = 'DECRO'
4932                      AND l_oipl_ordr_num >= l_enrd_ordr_num)
4933                 OR (
4934                          l_cvg_incr_r_decr_only_cd = 'EQDECR'
4935                      AND l_oipl_ordr_num > l_enrd_ordr_num)) THEN
4936           --
4937 	  if g_debug then
4938           hr_utility.set_location('incr or decr check failed, no choice', 12);
4939 	  end if;
4940           --
4941           p_electable_flag :=  'N';
4942           --
4943           RETURN;
4944         --
4945         ELSIF (
4946                    l_cvg_incr_r_decr_only_cd IS NULL
4947                 OR l_cvg_incr_r_decr_only_cd = 'NR'
4948                 OR (
4949                          l_cvg_incr_r_decr_only_cd = 'INCRO'
4950                      AND l_oipl_ordr_num > l_enrd_ordr_num)
4951                 OR (
4952                          l_cvg_incr_r_decr_only_cd = 'EQINCR'
4953                      AND l_oipl_ordr_num >= l_enrd_ordr_num)
4954                 OR (
4955                          l_cvg_incr_r_decr_only_cd = 'DECRO'
4956                      AND l_oipl_ordr_num < l_enrd_ordr_num)
4957                 OR (
4958                          l_cvg_incr_r_decr_only_cd = 'EQDECR'
4959                      AND l_oipl_ordr_num <= l_enrd_ordr_num)
4960                 OR l_cvg_incr_r_decr_only_cd IN ('INCRCTF', 'DECRCTF', 'DECINCCTF')) THEN
4961          --
4962 /*   uncomment these for debugging only
4963          hr_utility.set_location('Level jumping passed incr or decr check',12);
4964          hr_utility.set_location('now check max incr and max wctfn incr',12);
4965          hr_utility.set_location('l_mx_cvg_mlt_incr_wcf_num -> '||l_mx_cvg_mlt_incr_wcf_num,12);
4966          hr_utility.set_location('l_mx_cvg_mlt_incr_num -> '||l_mx_cvg_mlt_incr_num,12);
4967          hr_utility.set_location('current enrolled order num -> '||l_enrd_ordr_num,12);
4968 */
4969 -- logical ordr number is used rather database ordr num
4970           --
4971           IF     l_oipl_seq_num >
4972                                   (
4973                                     l_mx_cvg_mlt_incr_wcf_num +
4974                                       l_enrd_seq_num)
4975              AND l_mx_cvg_mlt_incr_wcf_num IS NOT NULL THEN
4976             --
4977 	    if g_debug then
4978             hr_utility.set_location('can not jump here 1', 12);
4979 	    end if;
4980             p_electable_flag :=  'N';
4981             RETURN;
4982           --
4983           ELSIF     (
4984                       l_oipl_seq_num >
4985                                       (
4986                                         l_mx_cvg_mlt_incr_num +
4987                                           l_enrd_seq_num))
4988                 AND l_mx_cvg_mlt_incr_num IS NOT NULL
4989                 AND l_mx_cvg_mlt_incr_wcf_num IS NULL THEN
4990             --
4991 	    if g_debug then
4992             hr_utility.set_location('can not jump here 2', 12);
4993 	    end if;
4994             p_electable_flag :=  'N';
4995             RETURN;
4996           --
4997           ELSIF     (
4998                       l_oipl_seq_num >
4999                               (
5000                                 NVL(l_mx_cvg_mlt_incr_num, 0) +
5001                                   l_enrd_seq_num))
5002                 AND (
5003                       l_oipl_seq_num <=
5004                                   (
5005                                     l_mx_cvg_mlt_incr_wcf_num +
5006                                       l_enrd_seq_num))
5007                 AND l_mx_cvg_mlt_incr_wcf_num IS NOT NULL THEN
5008             --
5009 	    if g_debug then
5010             hr_utility.set_location('set ctfn rqd flag to true ', 12);
5011 	    end if;
5012             p_electable_flag :=  'Y';
5013             l_ctfn_rqd_flag :=   'Y';
5014           ELSE
5015             --
5016             p_electable_flag :=  'Y';
5017             --
5018           END IF;
5019         --
5020           -- 5736589: Increase/Decrease Requires certification for Option Restrictions
5021 	  if g_debug then
5022             hr_utility.set_location('Opt.Rest. Incr/Dec.Req.Cert.  ' || l_cvg_incr_r_decr_only_cd, 12);
5023           end if;
5024             IF (l_cvg_incr_r_decr_only_cd  = 'INCRCTF'
5025                 and l_oipl_ordr_num > l_enrd_ordr_num) THEN
5026               --
5027               l_ctfn_rqd_flag :=  'Y';
5028           --
5029             ELSIF (l_cvg_incr_r_decr_only_cd  = 'DECRCTF'
5030                 and l_oipl_ordr_num < l_enrd_ordr_num) THEN
5031               --
5032               l_ctfn_rqd_flag :=  'Y';
5033               --
5034             ELSIF (l_cvg_incr_r_decr_only_cd  = 'DECINCCTF'
5035                 and l_oipl_ordr_num <> l_enrd_ordr_num) THEN
5036               --
5037               l_ctfn_rqd_flag :=  'Y';
5038           END IF;
5039         --
5040 	if g_debug then
5041             hr_utility.set_location('Opt.Rest. Cert Flag  ' || l_ctfn_rqd_flag, 12);
5042         end if;
5043           --
5044         ELSE
5045           --
5046         if g_debug then
5047           hr_utility.set_location('Level jumping success', 0);
5048         end if;
5049           p_electable_flag :=  'Y';
5050         --
5051         END IF;
5052       --
5053       END IF;
5054     --
5055     END IF;
5056     --
5057 
5058     -- Determine the enrt_cvg_strt_dt_cd and enrt_cvg_end_dt_cd
5059     -- (rules as well), and dates
5060     -- use the new determine date function
5061     -- Get it from the lee_rsn_f for the plan, if not set get it from the plan,
5062     -- if not set get it from the lee_rsn_f at the pgm level,
5063     -- if not set get it from the pgm, if not set report and error.
5064     -- (end date is optional is used at the same level as the start)
5065     --
5066     if g_debug then
5067     hr_utility.set_location('J', 20);
5068     hr_utility.set_location(l_proc || ' RMODE=L ', 12);
5069     end if;
5070     --
5071     -- ABSENCES : absence processing is similar to life event processing
5072     -- GRADE/STEP : GS progression process is similar to life event
5073     -- iREC : Added mode 'I'
5074     --
5075 -- IF p_run_mode <> 'D' then
5076   --
5077     IF (    p_run_mode in  ('L', 'M', 'G', 'I')
5078         AND l_unrestricted_enrt_flag = 'N') THEN
5079       --
5080       if g_debug then
5081       hr_utility.set_location('K', 20);
5082       hr_utility.set_location(l_proc || ' RMODE=L UEF=N ', 12);
5083       end if;
5084       OPEN c_lee_period_for_plan;
5085       --
5086       FETCH c_lee_period_for_plan INTO l_ple_dys_aftr_end_to_dflt_num,
5087                                        l_ple_enrt_perd_end_dt_rl,
5088                                        l_ple_enrt_perd_strt_dt_rl,
5089                                        l_ple_enrt_perd_end_dt_cd,
5090                                        l_ple_enrt_perd_strt_dt_cd,
5091 --                                     l_ple_enrt_cvg_strt_dt_cd,
5092 --                                     l_ple_enrt_cvg_strt_dt_rl,
5093                                        l_ple_addit_procg_dys_num,
5094                                        l_ple_enrt_typ_cycl_cd,
5095                                        l_ple_lee_rsn_id,
5096                                        l_rec_cls_enrt_dt_to_use_cd,
5097                                        l_rec_lee_rsn_esd,
5098                                        l_rec_lee_rsn_eed,
5099                                        l_ple_enrt_perd_strt_days,
5100                                        l_ple_enrt_perd_end_days,
5101                                        /* bug 2746865*/
5102                                        l_enrt_perd_det_ovrlp_bckdt_cd;
5103       --
5104       IF c_lee_period_for_plan%FOUND THEN
5105         --
5106         l_perd_for_plan_found :=  'Y';
5107       --
5108       ELSE
5109         --
5110         l_perd_for_plan_found :=  'N';
5111       --
5112       END IF;                                                          -- found
5113       --
5114       CLOSE c_lee_period_for_plan;
5115       if g_debug then
5116       hr_utility.set_location(l_proc || ' Cl c_lpfpln ', 12);
5117       --
5118       hr_utility.set_location('L', 20);
5119       end if;
5120       -- Get pgm level enrt period if it is needed
5121       -- Program must exist and
5122       -- Needed when can't find record at plan level or
5123       -- Need it to determine the enrt_perd_strt_dt_cd
5124       --
5125       IF (
5126                p_pgm_id IS NOT NULL
5127            AND (
5128                     l_perd_for_plan_found = 'N'
5129                  OR (l_ple_enrt_perd_strt_dt_cd IS NULL))) THEN
5130         --
5131         OPEN c_lee_period_for_program;
5132         --
5133         FETCH c_lee_period_for_program INTO l_pgme_dys_aftr_end_to_dflt,
5134                                             l_pgme_enrt_perd_end_dt_rl,
5135                                             l_pgme_enrt_perd_strt_dt_rl,
5136                                             l_pgme_enrt_perd_end_dt_cd,
5137                                             l_pgme_enrt_perd_strt_dt_cd,
5138 --                                            l_pgme_enrt_cvg_strt_dt_cd,
5139 --                                            l_pgme_enrt_cvg_strt_dt_rl,
5140                                             l_pgme_addit_procg_dys_num,
5141                                             l_pgme_enrt_typ_cycl_cd,
5142                                             l_pgme_lee_rsn_id,
5143                                             l_rec_cls_enrt_dt_to_use_cd,
5144                                             l_rec_lee_rsn_esd,
5145                                             l_rec_lee_rsn_eed,
5146                                             l_pgme_enrt_perd_strt_days,
5147                                             l_pgme_enrt_perd_end_days,
5148                                             /* bug 2746865 */
5149                                             l_enrt_perd_det_ovrlp_bckdt_cd;
5150         --
5151         IF c_lee_period_for_program%FOUND THEN
5152           --
5153           l_perd_for_program_found :=  'Y';
5154         --
5155         ELSE
5156           --
5157           l_perd_for_program_found :=  'N';
5158         --
5159         END IF;                                                        -- Found
5160         --
5161         CLOSE c_lee_period_for_program;
5162 	if g_debug then
5163         hr_utility.set_location(l_proc || ' Cl c_lpfprg ', 12);
5164 	end if;
5165       --
5166       -- If there is a plan level enrt_perd_for_pl use it's value (if not null)
5167       --
5168 --      open c_enrt_perd_for_pl_info;
5169 --      fetch c_enrt_perd_for_pl_info into
5170 --        l_overide_enrt_cvg_strt_dt_cd,
5171 --        l_overide_enrt_cvg_strt_dt_rl;
5172 --      close c_enrt_perd_for_pl_info;
5173 --      if l_overide_enrt_cvg_strt_dt_cd is not null then
5174 --        l_pgme_enrt_cvg_strt_dt_cd:=l_overide_enrt_cvg_strt_dt_cd;
5175 --        l_pgme_enrt_cvg_strt_dt_rl:=l_overide_enrt_cvg_strt_dt_rl;
5176 --      end if;
5177       --
5178       END IF;                -- Need to get program level enrolment period info
5179     --
5180     ELSIF (   ( p_run_mode = 'C'or p_run_mode = 'W')
5181            AND l_unrestricted_enrt_flag = 'N') THEN
5182       --
5183       if g_debug then
5184       hr_utility.set_location(l_proc || ' RMODE=C UEF=N ', 12);
5185       end if;
5186       OPEN c_sched_enrol_period_for_plan;
5187       --
5188       FETCH c_sched_enrol_period_for_plan INTO l_ple_enrt_perd_id,
5189                                                l_ple_enrt_perd_strt_dt,
5190                                                l_ple_enrt_perd_end_dt,
5191                                                l_ple_procg_end_dt,
5192                                                l_ple_dflt_enrt_dt,
5193 --                                             l_ple_enrt_cvg_strt_dt_cd,
5194 --                                             l_ple_enrt_cvg_strt_dt_rl,
5195                                                l_ple_enrt_typ_cycl_cd,
5196                                                l_rec_cls_enrt_dt_to_use_cd,
5197                                                l_ple_hrchy_to_use_cd,
5198                                                l_ple_pos_structure_version_id,
5199                                                /* bug 2746865 */
5200                                                l_enrt_perd_det_ovrlp_bckdt_cd;
5201 
5202       --
5203       IF c_sched_enrol_period_for_plan%FOUND THEN
5204         --
5205         l_perd_for_plan_found :=  'Y';
5206       --
5207       ELSE
5208         --
5209         l_perd_for_plan_found :=  'N';
5210       --
5211       END IF;                                                          -- found
5212       --
5213       CLOSE c_sched_enrol_period_for_plan;
5214       --
5215       -- Get pgm level enrt period if it is needed
5216       -- Program must exist and
5217       -- Needed when can't find record at plan level or
5218       -- Need it to determine the enrt_perd_strt_dt_cd
5219       --
5220       IF (
5221                p_pgm_id IS NOT NULL
5222            AND (
5223                     l_perd_for_plan_found = 'N'
5224                  OR (l_ple_enrt_perd_strt_dt IS NULL))) THEN
5225         --
5226         OPEN c_sched_enrol_period_for_pgm;
5227         --
5228         FETCH c_sched_enrol_period_for_pgm INTO l_pgme_enrt_perd_id,
5229                                                 l_pgme_enrt_perd_strt_dt,
5230                                                 l_pgme_enrt_perd_end_dt,
5231                                                 l_pgme_procg_end_dt,
5232                                                 l_pgme_dflt_enrt_dt,
5233 --                                                l_pgme_enrt_cvg_strt_dt_cd,
5234 --                                                l_pgme_enrt_cvg_strt_dt_rl,
5235                                                 l_pgme_enrt_typ_cycl_cd,
5236                                                 l_rec_cls_enrt_dt_to_use_cd,
5237                                                 l_ple_hrchy_to_use_cd,
5238                                                 l_ple_pos_structure_version_id,
5239                                                 /* bug 2746865 */
5240                                                 l_enrt_perd_det_ovrlp_bckdt_cd;
5241         --
5242         IF c_sched_enrol_period_for_pgm%FOUND THEN
5243           --
5244           l_perd_for_program_found :=  'Y';
5245         --
5246         ELSE
5247           --
5248           l_perd_for_program_found :=  'N';
5249         --
5250         END IF;                                                        -- Found
5251         --
5252         CLOSE c_sched_enrol_period_for_pgm;
5253       --
5254       -- If there is a plan level enrt_perd_for_pl use it's value (if not null)
5255       --
5256       --
5257       END IF;                -- Need to get program level enrolment period info
5258     -- Bug 2200139 Override Enrollments
5259     ELSIF l_unrestricted_enrt_flag = 'Y' OR p_run_mode = 'V'  THEN
5260       l_rec_enrt_perd_strt_dt :=      l_lf_evt_ocrd_dt_fetch;
5261       l_rec_enrt_perd_end_dt :=       hr_api.g_eot;
5262       l_rec_procg_end_dt :=           hr_api.g_eot;
5263       l_rec_dflt_asnmt_dt :=          l_lf_evt_ocrd_dt_fetch;
5264       l_rec_enrt_typ_cycl_cd :=       'U';
5265       l_rec_cls_enrt_dt_to_use_cd :=  'ELCNSMADE';
5266     END IF;                                                   -- run_mode cases
5267     --
5268     -- One of the levels must have been found
5269     --
5270     if g_debug then
5271     hr_utility.set_location('M', 20);
5272     hr_utility.set_location(
5273       'l_perd_for_plan_found=' || l_perd_for_plan_found,
5274       20);
5275     hr_utility.set_location(
5276       'l_perd_for_program_found=' || l_perd_for_program_found,
5277       20);
5278     hr_utility.set_location(
5279       'l_unrestricted_enrt_flag=' || l_unrestricted_enrt_flag,
5280       20);
5281     hr_utility.set_location('l_pfpf=N ' || l_proc, 10);
5282     end if;
5283     --Bug 2200139 Override Enrollment
5284     IF (
5285              l_perd_for_plan_found = 'N'
5286          AND l_perd_for_program_found = 'N'
5287          AND l_unrestricted_enrt_flag = 'N'
5288          AND nvl(p_run_mode,'X') not in ('V','D') ) THEN -- For 'D' Mode we dont set code for periods
5289       --
5290       -- ABSENCES : absence processing is similar to life event processing.
5291       -- iRec : Added mode 'I'
5292       IF p_run_mode in ('L', 'M','G', 'I') THEN
5293       if g_debug then
5294         hr_utility.set_location(' Leaving:' || l_proc, 981);
5295       end if;
5296         p_electable_flag :=  'N';
5297         RETURN;
5298       ELSE
5299       if g_debug then
5300         hr_utility.set_location('Did not find enrt_perd, raise error', 982);
5301       end if;
5302         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
5303         fnd_message.set_token('PROC', l_proc);
5304         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5305         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5306         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
5307         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
5308         RAISE ben_manage_life_events.g_record_error;
5309       END IF;
5310     --
5311     END IF;                                         -- no enrt_perd info found.
5312     --
5313     if g_debug then
5314     hr_utility.set_location('P', 20);
5315     --
5316     -- Determine the mndtry_flag
5317     -- If the comp object is an OIPL
5318     --
5319     hr_utility.set_location('Ch oipl_id NN ' || l_proc, 10);
5320     end if;
5321     IF (p_oipl_id IS NOT NULL AND p_run_mode <> 'D') THEN
5322       --
5323       -- If the mndtry_rl is not null, execute it to determine
5324       -- if the oipl is mandatory.
5325       --
5326       IF l_mndtry_rl IS NOT NULL THEN
5327         --
5328         l_mndtry_flag :=
5329          execute_enrt_rule(
5330            p_opt_id            => l_opt_id,
5331            p_pl_id             => l_pl_id,
5332            p_pgm_id            => p_pgm_id,
5333            p_rule_id           => l_mndtry_rl,
5334            p_ler_id            => p_ler_id,
5335            p_pl_typ_id         => l_pl_typ_id,
5336            p_business_group_id => p_business_group_id,
5337            p_effective_date    => p_effective_date,
5338            p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5339            p_assignment_id     => l_rec_assignment_id,
5340            p_organization_id   => l_rec_organization_id,
5341            p_jurisdiction_code => l_jurisdiction_code,
5342 	   p_person_id         => p_person_id);          -- Bug 5331889
5343         --
5344         l_rec_mndtry_flag :=  l_mndtry_flag;
5345         --
5346       --
5347       -- If the mndtry_rl is null, use the mndtry_flag to
5348       -- determine if the oipl is mandatory.
5349       --
5350       ELSE
5351         --
5352         l_rec_mndtry_flag :=  l_mndtry_flag;
5353       --
5354       END IF;
5355     --
5356     END IF;
5357     --
5358     -- Determine the elctbl_flag
5359     -- If the comp object is an OIPL
5360     --
5361     if g_debug then
5362     hr_utility.set_location('R', 20);
5363     hr_utility.set_location('Ch oipl_id1 NN ' || l_proc, 10);
5364     end if;
5365     --
5366     -- CWBITEM : do not check for CWB plans, goahead and create the epe.
5367     --
5368     IF (p_oipl_id IS NULL and p_run_mode not in ('W','D')) THEN
5369       --
5370       -- Only check to see if we have to create electable choice for plan if
5371       -- the enrt pl opt flag is set
5372       --
5373       IF l_plan_rec.enrt_pl_opt_flag = 'N' THEN
5374         --
5375         OPEN c_any_oipl_for_plan;
5376         --
5377         FETCH c_any_oipl_for_plan INTO l_exists_flag;
5378 	if g_debug then
5379         hr_utility.set_location('Fet c_aofp ' || l_proc, 10);
5380 	end if;
5381         --
5382         IF c_any_oipl_for_plan%FOUND THEN
5383           --
5384           p_electable_flag :=  'N';
5385           RETURN;
5386         --
5387         END IF;
5388         --
5389         CLOSE c_any_oipl_for_plan;
5390       --
5391       END IF;
5392     --
5393     END IF;
5394     --
5395     if g_debug then
5396     hr_utility.set_location('S', 20);
5397     -- Determine the enrt_typ_cycl_cd
5398     -- Find the lee_rsn_f and related popl_enrt_typ_cycl_f for the plan.
5399     --
5400     hr_utility.set_location('l_PFPF=Y ' || l_proc, 10);
5401     end if;
5402   IF p_run_mode <> 'D' THEN
5403     IF (    l_perd_for_plan_found = 'Y'
5404         AND l_ple_enrt_typ_cycl_cd IS NOT NULL) THEN
5405       -- If found use it's enrt_typ_cycl_cd
5406       l_rec_enrt_typ_cycl_cd :=  l_ple_enrt_typ_cycl_cd;
5407     -- If not found then find the lee_rsn_f and related
5408     -- popl_enrt_typ_cycl_f for the program.
5409     --
5410     ELSIF (
5411                 l_perd_for_program_found = 'Y'
5412             AND l_pgme_enrt_typ_cycl_cd IS NOT NULL) THEN
5413       -- If found use it's enrt_typ_cycl_cd
5414       l_rec_enrt_typ_cycl_cd :=  l_pgme_enrt_typ_cycl_cd;
5415     -- Bug 2200139 Override Enrollment
5416     ELSIF l_unrestricted_enrt_flag = 'N' and nvl(p_run_mode,'X') <> 'V' THEN
5417       -- If nothing found report an error.
5418       fnd_message.set_name('BEN', 'BEN_91464_ENRT_TYP_CYCL_CD');
5419       fnd_message.set_token('PROC', l_proc);
5420       fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5421       fnd_message.set_token('PGM_ENRT_TYP_CYCL_CD', l_pgme_enrt_typ_cycl_cd);
5422       fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5423       fnd_message.set_token('PL_ENRT_TYP_CYCL_CD', l_ple_enrt_typ_cycl_cd);
5424       RAISE ben_manage_life_events.g_record_error;
5425     --
5426     END IF;
5427     --
5428   END IF; -- 'D' Mode
5429     -- Determine the crntly_enrd_flag
5430     -- Set it to the currently_enrolled parameter.
5431     --
5432     IF l_crnt_enrt_cvg_strt_dt IS NOT NULL THEN
5433       --
5434       l_rec_crntly_enrd_flag :=  'Y';
5435     --
5436     ELSE
5437       --
5438       l_rec_crntly_enrd_flag :=  'N';
5439     --
5440     END IF;
5441     --
5442     -- get the dflt_enrt_cd/rule
5443     --
5444     if g_debug then
5445     hr_utility.set_location('DrtDEC ' || l_proc, 10);
5446     -- start bug 5644451
5447         hr_utility.set_location('Determine with new call 5644451 ' || l_proc, 10);
5448     end if;
5449 	IF (p_oipl_id IS NOT NULL)
5450 	THEN
5451 	-- get oipl information
5452 	ben_comp_object.get_object (p_oipl_id                     => p_oipl_id,
5453 				  p_rec                         => l_oipl_record);
5454 	l_oipl_auto_enrt_flag := l_oipl_rec.auto_enrt_flag;
5455 	END IF;
5456 	-- Get ptip cache row if needed
5457 	IF l_ptip_id IS NOT NULL
5458 	THEN
5459 	ben_comp_object.get_object (p_ptip_id                     => l_ptip_id,
5460 				  p_rec                         => l_ptip_record);
5461 	END IF;
5462 	-- Get plip cache row if needed
5463 	IF l_plip_id IS NOT NULL
5464 	THEN
5465 	ben_comp_object.get_object (p_plip_id                     => l_plip_id,
5466 				  p_rec                         => l_plip_record);
5467 	END IF;
5468 
5469 
5470     /*
5471     determine_dflt_enrt_cd
5472       (p_oipl_id           => p_oipl_id
5473       ,p_plip_id           => l_plip_id
5474       ,p_pl_id             => l_pl_id
5475       ,p_ptip_id           => l_ptip_id
5476       ,p_pgm_id            => p_pgm_id
5477       ,p_ler_id            => p_ler_id
5478       ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
5479       ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
5480       ,p_business_group_id => p_business_group_id
5481       ,p_effective_date    => p_effective_date
5482       );
5483       */
5484     IF p_run_mode <> 'D' THEN
5485      --
5486       determine_dflt_enrt_cd
5487         (p_oipl_id           => p_oipl_id
5488         ,p_oipl_rec          => l_oipl_record
5489         ,p_plip_id           => l_plip_id
5490         ,p_plip_rec          => l_plip_record
5491         ,p_pl_id             => l_pl_id
5492         ,p_pl_rec            => l_plan_rec
5493         ,p_ptip_id           => l_ptip_id
5494         ,p_ptip_rec          => l_ptip_record
5495         ,p_pgm_id            => p_pgm_id
5496         ,p_pgm_rec           => l_pgm_rec
5497         ,p_ler_id            => p_ler_id
5498         ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
5499         ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
5500         ,p_business_group_id => p_business_group_id
5501         ,p_effective_date    => l_lf_evt_ocrd_dt
5502         ,p_level             => l_dflt_level
5503         ,p_ler_dflt_flag     => l_ler_dflt_flag
5504       );
5505 
5506      -- end bug 5644451
5507    if g_debug then
5508     hr_utility.set_location('Dn DrtDEC ' || l_proc, 10);
5509    end if;
5510     --
5511     -- Set the values for the dflt_flag
5512     --
5513     l_use_dflt_flag :=            NULL;
5514     IF l_ler_chg_found_flag = 'Y' THEN
5515       IF    l_ler_chg_oipl_found_flag = 'Y'
5516          OR (    l_ler_chg_oipl_found_flag = 'N'
5517              AND p_oipl_id IS NULL) THEN
5518         --
5519         -- Use flag only if at appropriate level
5520         --
5521         l_use_dflt_flag :=  l_ler_dflt_flag;
5522       END IF;
5523     END IF;
5524   if g_debug then
5525     hr_utility.set_location('U', 20);
5526   end if;
5527     --
5528     -- oipl level default code/flag
5529     --
5530     IF p_oipl_id IS NOT NULL THEN
5531       IF l_use_dflt_flag IS NULL THEN
5532         --
5533         -- use oipl level flag
5534         --
5535         l_use_dflt_flag :=  l_oipl_dflt_flag;
5536       END IF;
5537     END IF;
5538   if g_debug then
5539     hr_utility.set_location('U3', 30);
5540   end if;
5541     --
5542     -- plip level default code/flag
5543     --
5544     IF l_plip_id IS NOT NULL THEN
5545       IF l_use_dflt_flag IS NULL THEN
5546         l_use_dflt_flag :=  l_plip_dflt_flag;
5547       END IF;
5548     END IF;
5549     --
5550     if g_debug then
5551     hr_utility.set_location('V', 20);
5552     end if;
5553     --
5554     -- If no default flag is set then make it not a default.
5555     --
5556     IF l_use_dflt_flag IS NULL THEN
5557       --
5558       l_use_dflt_flag :=  'N';
5559     --
5560     END IF;
5561     if g_debug then
5562     hr_utility.set_location('  l_use_dflt_flag  ' ||  l_use_dflt_flag, 10);
5563     end if;
5564      determine_dflt_flag(
5565        l_use_dflt_flag,
5566        l_use_dflt_enrt_cd,
5567        l_crnt_enrt_cvg_strt_dt,
5568        l_previous_eligibility,
5569        l_use_dflt_enrt_rl,
5570        p_oipl_id,
5571        l_pl_id,
5572        p_pgm_id,
5573        p_effective_date,
5574        p_lf_evt_ocrd_dt,
5575        p_ler_id,
5576        l_opt_id,
5577        l_pl_typ_id,
5578        l_ptip_id,
5579        p_person_id,
5580        p_business_group_id,
5581        l_rec_assignment_id,
5582        l_dflt_flag,
5583        l_reinstt_flag,
5584        -- bug 5644451
5585        l_dflt_level,
5586        p_run_mode           -- iRec
5587        );
5588      if l_reinstt_cd is null then
5589         l_reinstt_cd := l_reinstt_flag;
5590      end if;
5591    if g_debug then
5592     hr_utility.set_location(' Dn det_dflt_flag ' || l_proc, 10);
5593     hr_utility.set_location(' l_dflt_flag   ' ||  l_dflt_flag , 10);
5594    end if;
5595     --
5596     IF (l_dflt_flag = 'DEFER') THEN
5597       --
5598       l_dflt_flag :=  l_use_dflt_flag;
5599     --
5600     END IF;
5601     --Bug 2200139 Override Enrollment changes
5602     IF p_run_mode = 'V' then
5603       --
5604       l_dflt_flag := 'N' ;
5605       --
5606     end if;
5607     --
5608  END IF;
5609     -- Determine the enrt_perd_strt_dt and enrt_perd_end_dt.
5610     -- Determine the dflt_asnmt_dt
5611     -- Determine the procg_end_dt.
5612     -- GRADE/STEP : Extend L mode to cater Grade step process.
5613     -- iRec : Added mode 'I'
5614     --
5615     IF (p_run_mode in ('L', 'G', 'I')  AND p_run_mode <> 'D'
5616         AND l_unrestricted_enrt_flag = 'N') THEN
5617       --
5618       -- Get it from the lee_rsn_f for the plan (or program if not set)
5619       -- enrt_perd_strt_dt_cd and enrt_perd_end_dt_cd (and rules)
5620       -- What domain is this?  Determine the date using the code/rule.
5621       -- If Life event mode, set dflt_asnmt_dt to the
5622       -- enrt_perd_end_dt + dys_aftr_end_to_dflt_num.
5623       --
5624    if g_debug then
5625       hr_utility.set_location(' RM L UEF N ' || l_proc, 10);
5626    end if;
5627       IF (
5628                l_perd_for_plan_found = 'Y'
5629            AND l_ple_enrt_perd_strt_dt_cd IS NOT NULL) THEN
5630         --
5631         ben_determine_date.main(
5632           p_date_cd           => l_ple_enrt_perd_strt_dt_cd,
5633           p_per_in_ler_id     => l_per_in_ler_id,
5634           p_person_id         => p_person_id,
5635           p_pgm_id            => p_pgm_id,
5636           p_pl_id             => l_pl_id,
5637           p_oipl_id           => p_oipl_id,
5638           p_business_group_id => p_business_group_id,
5639           p_formula_id        => l_ple_enrt_perd_strt_dt_rl,
5640           p_effective_date    => p_effective_date,
5641           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5642           p_returned_date     => l_rec_enrt_perd_strt_dt);
5643 
5644          -- GHR enhancment
5645          if  l_ple_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5646              l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_ple_enrt_perd_strt_days,0) ;
5647          end if ;
5648         --
5649         -- The following logic was added by jcarpent for bug 4988/1269016
5650         -- based on tech design of maagrawa (1-6, 2 is done above)
5651         -- NOTE: please see identical logic for other modes.  Code added
5652         -- inline since we don't want to add additional function calls
5653         -- for performance reasons.
5654         --
5655       if g_debug then
5656         hr_utility.set_location(' PLS BLK 1 ' || l_proc, 10);
5657       end if;
5658         BEGIN
5659 	if g_debug then
5660           hr_utility.set_location(' entering ' || l_proc, 10);
5661         end if;
5662           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5663           -- 1 get latest processed date
5664           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5665           --
5666           -- GRADE/STEP  : Following code is only applicable for L mode
5667           --
5668           if p_run_mode  = 'L' then
5669             -- 2746865
5670             -- call the enrt_perd_strt_dt procedure to compute the epsd and eped
5671             -- according to the enrt. period determination code
5672             -- removed inline code and made it a procedure
5673 	    if g_debug then
5674             hr_utility.set_location(' calling new proc ' , 20);
5675 	    end if;
5676             enrt_perd_strt_dt
5677             ( p_person_id => p_person_id
5678               , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5679               , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5680               , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5681               , p_ler_id => p_ler_id
5682               , p_business_group_id => p_business_group_id
5683               , p_effective_date => p_effective_date
5684               );
5685           end if;
5686 	  if g_debug then
5687           hr_utility.set_location(' l_rec_enrt_perd_strt_dt is '|| l_rec_enrt_perd_strt_dt , 876);
5688 	  end if;
5689         END;                                           -- of special epsd logic
5690 	if g_debug then
5691         hr_utility.set_location(' Dn PLS BLK 1 ' || l_proc, 10);
5692 	end if;
5693         ben_determine_date.main(
5694           p_date_cd           => l_ple_enrt_perd_end_dt_cd,
5695           p_start_date        => l_orig_epsd,
5696           p_per_in_ler_id     => l_per_in_ler_id,
5697           p_person_id         => p_person_id,
5698           p_pgm_id            => p_pgm_id,
5699           p_pl_id             => l_pl_id,
5700           p_oipl_id           => p_oipl_id,
5701           p_business_group_id => p_business_group_id,
5702           p_formula_id        => l_ple_enrt_perd_end_dt_rl,
5703           p_effective_date    => p_effective_date,
5704           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5705           p_param1            => 'ENRT_PERD_START_DATE',
5706           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
5707           p_returned_date     => l_rec_enrt_perd_end_dt);
5708 
5709 
5710          -- GHR enhancment
5711          if  l_ple_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5712              l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_ple_enrt_perd_end_days,0) ;
5713          end if ;
5714 
5715         --
5716 	if g_debug then
5717           hr_utility.set_location(' l_rec_enrt_perd_end_dt is '|| l_rec_enrt_perd_end_dt , 876);
5718         end if;
5719        --
5720        -- 2746865
5721 
5722        -- if cd is L_EPSD_PEPD or null, proceed as before
5723        IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
5724            hr_utility.set_location('L_EPSD_PEPD' , 765);
5725          l_rec_enrt_perd_end_dt :=
5726                 l_rec_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5727        -- 2746865
5728        ELSE
5729          -- for other codes
5730          -- if end dt is less than the start dt, make the strt dt as the end dt
5731          IF l_rec_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
5732 	 if g_debug then
5733            hr_utility.set_location(' end dt < strt dt ', 876);
5734          end if;
5735          l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
5736          END IF;
5737        END IF;
5738 	--
5739         l_rec_dflt_asnmt_dt :=
5740               l_rec_enrt_perd_end_dt + NVL(l_ple_dys_aftr_end_to_dflt_num, 0);
5741         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
5742         l_rec_procg_end_dt :=
5743                    l_rec_enrt_perd_end_dt + NVL(l_ple_addit_procg_dys_num, 0);
5744         --
5745         l_rec_lee_rsn_id :=        l_ple_lee_rsn_id;
5746         --
5747 	if g_debug then
5748         hr_utility.set_location(' Dn RM L UEF N ' || l_proc, 10);
5749 	end if;
5750       ELSIF (
5751                   l_perd_for_program_found = 'Y'
5752               AND l_pgme_enrt_perd_strt_dt_cd IS NOT NULL) THEN
5753         --
5754 	if g_debug then
5755         hr_utility.set_location(' BDD_MN PFPF=Y ' || l_proc, 10);
5756 	end if;
5757         ben_determine_date.main(
5758           p_date_cd           => l_pgme_enrt_perd_strt_dt_cd,
5759           p_per_in_ler_id     => l_per_in_ler_id,
5760           p_person_id         => p_person_id,
5761           p_pgm_id            => p_pgm_id,
5762           p_pl_id             => l_pl_id,
5763           p_oipl_id           => p_oipl_id,
5764           p_business_group_id => p_business_group_id,
5765           p_formula_id        => l_pgme_enrt_perd_strt_dt_rl,
5766           p_effective_date    => p_effective_date,
5767           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5768           p_returned_date     => l_rec_enrt_perd_strt_dt);
5769 
5770 
5771         -- GHR enhancment
5772         if  l_pgme_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5773             l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_pgme_enrt_perd_strt_days,0) ;
5774         end if ;
5775 
5776         --
5777         -- The following logic was added by jcarpent for bug 4988/1269016
5778         -- based on tech design of maagrawa (1-6, 2 is done above)
5779         -- NOTE: please see identical logic for other modes.  Code added
5780         -- inline since we don't want to add additional function calls
5781         -- for performance reasons.
5782         --
5783         BEGIN
5784           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5785           -- 1 get latest processed date
5786           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5787           --
5788           if p_run_mode  = 'L' then
5789           -- 2746865
5790           -- call the enrt_perd_strt_dt procedure
5791 	  -- removed inline code and made it a procedure
5792 	     enrt_perd_strt_dt
5793 	                ( p_person_id => p_person_id
5794 	                , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5795 	                , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5796 	                , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5797 	                , p_ler_id => p_ler_id
5798                         , p_business_group_id => p_business_group_id
5799                         , p_effective_date => p_effective_date
5800                         );
5801           --
5802 	  end if;
5803         END;                                           -- of special epsd logic
5804 	if g_debug then
5805         hr_utility.set_location(' Bef BDD_Mn ' || l_proc, 10);
5806 	end if;
5807         ben_determine_date.main(
5808           p_date_cd           => l_pgme_enrt_perd_end_dt_cd,
5809           p_start_date        => l_orig_epsd,
5810           p_per_in_ler_id     => l_per_in_ler_id,
5811           p_person_id         => p_person_id,
5812           p_pgm_id            => p_pgm_id,
5813           p_pl_id             => l_pl_id,
5814           p_oipl_id           => p_oipl_id,
5815           p_business_group_id => p_business_group_id,
5816           p_formula_id        => l_pgme_enrt_perd_end_dt_rl,
5817           p_effective_date    => p_effective_date,
5818           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
5819           p_param1            => 'ENRT_PERD_START_DATE',
5820           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
5821           p_returned_date     => l_rec_enrt_perd_end_dt);
5822           --
5823 
5824           -- GHR enhancment
5825           if  l_pgme_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
5826               l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_pgme_enrt_perd_end_days,0) ;
5827           end if ;
5828 
5829 
5830           -- 2746865
5831           -- if cd is L_EPSD_PEPD, proceed as before
5832           IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
5833             hr_utility.set_location('L_EPSD_PEPD' , 765);
5834             l_rec_enrt_perd_end_dt :=
5835                    l_rec_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5836           -- 2746865
5837           ELSE
5838             -- for other codes
5839             -- if end dt is less than the start dt, make the strt dt as the end dt
5840             IF l_rec_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
5841 	    if g_debug then
5842               hr_utility.set_location(' end dt < strt dt ', 876);
5843             end if;
5844             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
5845             END IF;
5846           END IF;
5847 
5848         --
5849         l_rec_dflt_asnmt_dt :=
5850                  l_rec_enrt_perd_end_dt + NVL(l_pgme_dys_aftr_end_to_dflt, 0);
5851         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
5852         l_rec_procg_end_dt :=
5853                   l_rec_enrt_perd_end_dt + NVL(l_pgme_addit_procg_dys_num, 0);
5854         --
5855         l_rec_lee_rsn_id :=        l_pgme_lee_rsn_id;
5856         --
5857 	if g_debug then
5858         hr_utility.set_location(' Dn PFPF=Y ' || l_proc, 10);
5859 	end if;
5860       ELSE
5861         --
5862         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
5863         fnd_message.set_token('PROC', l_proc);
5864         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
5865         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
5866         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
5867         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
5868         RAISE ben_manage_life_events.g_record_error;
5869       --
5870       END IF;                             -- perd found and strt_dt_cd not null
5871     --
5872     ELSIF (    p_run_mode in ( 'C', 'W') AND p_run_mode <> 'D'
5873            AND l_unrestricted_enrt_flag = 'N') THEN
5874       -- If scheduled mode, use enrt_perd.dflt_enrt_dt to determine dflt_asnmt_dt.
5875       IF (    l_perd_for_plan_found = 'Y'
5876           AND l_ple_enrt_perd_strt_dt IS NOT NULL) THEN
5877         --
5878         l_rec_enrt_perd_strt_dt :=  l_ple_enrt_perd_strt_dt;
5879         --
5880         -- The following logic was added by jcarpent for bug 4988/1269016
5881         -- based on tech design of maagrawa (1-6, 2 is done above)
5882         -- NOTE: please see identical logic for other modes.  Code added
5883         -- inline since we don't want to add additional function calls
5884         -- for performance reasons.
5885         --
5886         BEGIN
5887          -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5888          -- 1 get latest processed date
5889          l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5890          --
5891          -- Comp work bench
5892          -- ABSENCES : do not reset the enrt perd.
5893          --
5894          if p_run_mode <> 'W' then
5895            --
5896            -- 2746865
5897 	   -- call the enrt_perd_strt_dt procedure
5898 	   -- removed inline code and made it a procedure
5899 	   enrt_perd_strt_dt
5900 	   ( p_person_id => p_person_id
5901 	   , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5902 	   , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5903 	   , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5904 	   , p_ler_id => p_ler_id
5905            , p_business_group_id => p_business_group_id
5906            , p_effective_date => p_effective_date
5907            );
5908            --
5909          end if; -- p_mode <> 'W'
5910         END;                                           -- of special epsd logic
5911         --
5912         -- 2746865
5913         -- if cd is L_EPSD_PEPD, proceed as before
5914 	if g_debug then
5915         hr_utility.set_location('l_ple_enrt_perd_end_dt ' ||l_ple_enrt_perd_end_dt, 765);
5916         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
5917 	end if;
5918 
5919         IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
5920 	if g_debug then
5921           hr_utility.set_location('L_EPSD_PEPD' , 765);
5922         end if;
5923           l_rec_enrt_perd_end_dt :=
5924                 l_ple_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5925           --
5926           l_rec_procg_end_dt :=
5927                   l_ple_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5928         -- 2746865
5929         ELSE
5930           -- for other codes
5931 
5932           -- end dt is the greatest of start date and orig. end date
5933           /*IF l_ple_enrt_perd_end_dt < l_rec_enrt_perd_strt_dt THEN
5934             hr_utility.set_location(' end dt < strt dt ', 876);
5935             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_strt_dt;
5936           ELSE
5937             l_rec_enrt_perd_end_dt := l_ple_enrt_perd_end_dt;
5938           END IF;
5939           */
5940 
5941           l_rec_enrt_perd_end_dt := greatest (l_rec_enrt_perd_strt_dt, l_ple_enrt_perd_end_dt);
5942 	  if g_debug then
5943           hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
5944 	  end if;
5945           --
5946           --  Bug 5650482.  If the enrollment period end date is greater that the
5947           --  processing end date, set processing end date to the enrollment
5948           --  period end date.
5949           --
5950           IF l_rec_enrt_perd_end_dt >=  l_ple_procg_end_dt then
5951             l_rec_procg_end_dt := l_rec_enrt_perd_end_dt;
5952           ELSE
5953             l_rec_procg_end_dt := l_ple_procg_end_dt;
5954           END IF;
5955           --
5956         END IF;
5957 	if g_debug then
5958         hr_utility.set_location('l_rec_procg_end_dt ' ||l_rec_procg_end_dt, 765);
5959 	end if;
5960         --
5961         l_rec_dflt_asnmt_dt :=
5962                   l_ple_dflt_enrt_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
5963         --
5964         /* l_rec_procg_end_dt :=
5965                   l_ple_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd); */
5966         l_rec_enrt_perd_id :=       l_ple_enrt_perd_id;
5967       --
5968       ELSIF (
5969                   l_perd_for_program_found = 'Y'
5970               AND l_pgme_enrt_perd_strt_dt IS NOT NULL) THEN
5971         --
5972         l_rec_enrt_perd_strt_dt :=  l_pgme_enrt_perd_strt_dt;
5973         --
5974         -- The following logic was added by jcarpent for bug 4988/1269016
5975         -- based on tech design of maagrawa (1-6, 2 is done above)
5976         -- NOTE: please see identical logic for other modes.  Code added
5977         -- inline since we don't want to add additional function calls
5978         -- for performance reasons.
5979         --
5980         BEGIN
5981           -- jcarpent 1/4/2001 bug 1568555, removed +1 from line below
5982           -- 1 get latest processed date
5983           l_orig_epsd :=  l_rec_enrt_perd_strt_dt;
5984           -- 2746865
5985 	  -- call the enrt_perd_strt_dt procedure
5986 	  -- removed inline code and made it a procedure
5987 	  enrt_perd_strt_dt
5988 	  ( p_person_id => p_person_id
5989 	  , p_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
5990 	  , p_enrt_perd_det_ovrlp_bckdt_cd => l_enrt_perd_det_ovrlp_bckdt_cd
5991 	  , p_rec_enrt_perd_strt_dt => l_rec_enrt_perd_strt_dt
5992 	  , p_ler_id => p_ler_id
5993           , p_business_group_id => p_business_group_id
5994           , p_effective_date => p_effective_date
5995 	  );
5996           --
5997         END;                                           -- of special epsd logic
5998 
5999         -- 2746865
6000         -- if cd is L_EPSD_PEPD, proceed as before
6001         if g_debug then
6002         hr_utility.set_location('l_ple_enrt_perd_end_dt ' ||l_ple_enrt_perd_end_dt, 765);
6003         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6004 	end if;
6005 
6006         IF ( nvl(l_enrt_perd_det_ovrlp_bckdt_cd,'L_EPSD_PEPD') = 'L_EPSD_PEPD') THEN
6007 	if g_debug then
6008           hr_utility.set_location('L_EPSD_PEPD' , 765);
6009         end if;
6010           l_rec_enrt_perd_end_dt :=
6011                l_pgme_enrt_perd_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6012           l_rec_procg_end_dt :=
6013                  l_pgme_procg_end_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6014         ELSE
6015           -- 2746865
6016           -- for other codes
6017           -- end dt is the greatest of start date and original end date
6018           l_rec_enrt_perd_end_dt := greatest ( l_pgme_enrt_perd_end_dt, l_rec_enrt_perd_strt_dt);
6019           --
6020           --  Bug 5650482.  If the enrollment period end date is greater that the
6021           --  processing end date, set processing end date to the enrollment
6022           --  period end date.
6023           --
6024           IF l_rec_enrt_perd_end_dt >=  l_pgme_procg_end_dt then
6025             l_rec_procg_end_dt := l_rec_enrt_perd_end_dt;
6026           ELSE
6027             l_rec_procg_end_dt := l_pgme_procg_end_dt;
6028           END IF;
6029           --
6030         END IF;
6031 	if g_debug then
6032         hr_utility.set_location('l_rec_procg_end_dt ' ||l_rec_procg_end_dt, 765);
6033         hr_utility.set_location('l_rec_enrt_perd_end_dt ' ||l_rec_enrt_perd_end_dt, 765);
6034 	end if;
6035         --
6036         l_rec_dflt_asnmt_dt :=
6037                  l_pgme_dflt_enrt_dt + (l_rec_enrt_perd_strt_dt - l_orig_epsd);
6038         --
6039         l_rec_enrt_perd_id :=       l_pgme_enrt_perd_id;
6040       --
6041       ELSE
6042         --
6043         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
6044         fnd_message.set_token('PROC', l_proc);
6045         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
6046         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
6047         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
6048         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
6049         RAISE ben_manage_life_events.g_record_error;
6050       --
6051       END IF;                             -- perd found and strt_dt_cd not null
6052     ELSIF (p_run_mode =  'M' AND l_unrestricted_enrt_flag = 'N') THEN  -- ABS processing
6053       --
6054       -- Get it from the lee_rsn_f for the plan
6055       -- enrt_perd_strt_dt_cd and enrt_perd_end_dt_cd (and rules)
6056       -- What domain is this?  Determine the date using the code/rule.
6057       -- set dflt_asnmt_dt to the
6058       -- enrt_perd_end_dt + dys_aftr_end_to_dflt_num.
6059       --
6060       if g_debug then
6061       hr_utility.set_location(' RM L UEF N ' || l_proc, 20);
6062       end if;
6063       IF ( l_perd_for_plan_found = 'Y'
6064            AND l_ple_enrt_perd_strt_dt_cd IS NOT NULL) THEN
6065         --
6066         ben_determine_date.main(
6067           p_date_cd           => l_ple_enrt_perd_strt_dt_cd,
6068           p_per_in_ler_id     => l_per_in_ler_id,
6069           p_person_id         => p_person_id,
6070           p_pgm_id            => p_pgm_id,
6071           p_pl_id             => l_pl_id,
6072           p_oipl_id           => p_oipl_id,
6073           p_business_group_id => p_business_group_id,
6074           p_formula_id        => l_ple_enrt_perd_strt_dt_rl,
6075           p_effective_date    => p_effective_date,
6076           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
6077           p_returned_date     => l_rec_enrt_perd_strt_dt);
6078 
6079         -- GHR enhancment
6080         if  l_ple_enrt_perd_strt_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
6081             l_rec_enrt_perd_strt_dt := l_rec_enrt_perd_strt_dt + nvl(l_ple_enrt_perd_strt_days,0) ;
6082         end if ;
6083         --
6084         ben_determine_date.main(
6085           p_date_cd           => l_ple_enrt_perd_end_dt_cd,
6086           p_start_date        => l_orig_epsd,
6087           p_per_in_ler_id     => l_per_in_ler_id,
6088           p_person_id         => p_person_id,
6089           p_pgm_id            => p_pgm_id,
6090           p_pl_id             => l_pl_id,
6091           p_oipl_id           => p_oipl_id,
6092           p_business_group_id => p_business_group_id,
6093           p_formula_id        => l_ple_enrt_perd_end_dt_rl,
6094           p_effective_date    => p_effective_date,
6095           p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
6096           p_param1            => 'ENRT_PERD_START_DATE',
6097           p_param1_value      => fnd_date.date_to_canonical(l_rec_enrt_perd_strt_dt),
6098           p_returned_date     => l_rec_enrt_perd_end_dt);
6099 
6100 
6101         -- GHR enhancment
6102         if  l_ple_enrt_perd_end_dt_cd  in ( 'NUMDOE', 'NUMDON','NUMDOEN') then
6103             l_rec_enrt_perd_end_dt := l_rec_enrt_perd_end_dt + nvl(l_ple_enrt_perd_end_days,0) ;
6104         end if ;
6105 
6106         --
6107         l_rec_dflt_asnmt_dt :=
6108               l_rec_enrt_perd_end_dt + NVL(l_ple_dys_aftr_end_to_dflt_num, 0);
6109         -- Set it to the enrt_perd_end_dt + addt_procg_dys_num.
6110         l_rec_procg_end_dt :=
6111                    l_rec_enrt_perd_end_dt + NVL(l_ple_addit_procg_dys_num, 0);
6112         --
6113         l_rec_lee_rsn_id :=        l_ple_lee_rsn_id;
6114         --
6115 	if g_debug then
6116         hr_utility.set_location(' Dn RM L UEF N ' || l_proc, 20);
6117 	end if;
6118       ELSE
6119         --
6120         fnd_message.set_name('BEN', 'BEN_91335_PLAN_YR_ENRT_PERD');
6121         fnd_message.set_token('PROC', l_proc);
6122         fnd_message.set_token('PGM_ID', TO_CHAR(p_pgm_id));
6123         fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
6124         fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
6125         fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
6126         RAISE ben_manage_life_events.g_record_error;
6127       --
6128       END IF;                             -- perd found and strt_dt_cd not null
6129     --
6130     END IF;                                                         -- run mode
6131 -- END IF;
6132   if g_debug then
6133     hr_utility.set_location(' start DATE  ' || l_rec_enrt_perd_strt_dt, 92);
6134     hr_utility.set_location(' END DATE  ' || l_rec_enrt_perd_end_dt, 92);
6135   end if;
6136     -- Check to see if the start date is before the end date
6137     IF l_rec_enrt_perd_strt_dt > l_rec_enrt_perd_end_dt THEN
6138       --
6139       fnd_message.set_name('BEN', 'BEN_91735_END_BEFORE_STRT_DT');
6140       fnd_message.set_token('PROC', l_proc);
6141       fnd_message.set_token(
6142         'ENRT_PERD_STRT_DT',
6143         TO_CHAR(l_rec_enrt_perd_strt_dt));
6144       fnd_message.set_token(
6145         'ENRT_PERD_END_DT',
6146         TO_CHAR(l_rec_enrt_perd_end_dt));
6147       RAISE ben_manage_life_events.g_record_error;
6148     --
6149     END IF;
6150     --
6151     -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
6152     -- see if plan has regulation of IRC Section 125 or 129.
6153     --
6154    /*
6155     l_regn_125_or_129_flag:='N';
6156     if p_run_mode='C' and
6157        l_crnt_enrt_cvg_strt_dt is not null then
6158       open c_regn_125_or_129;
6159       fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
6160       hr_utility.set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
6161       close c_regn_125_or_129;
6162     end if;
6163  */
6164 --hr_utility.set_location('p_run_mode='||p_run_mode,1776);
6165 --hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||l_crnt_enrt_cvg_strt_dt,1776);
6166 --hr_utility.set_location('l_regn_125_or_129_flag='||l_regn_125_or_129_flag,1776);
6167     --
6168     -- Determine the enrolment coverage codes/rules
6169     -- If currently enrolled get from old enrollment.
6170     --
6171     IF l_crnt_enrt_cvg_strt_dt IS NOT NULL and
6172        l_new_cvg_strt='N' THEN
6173       l_rec_enrt_cvg_strt_dt :=  l_crnt_enrt_cvg_strt_dt;
6174 
6175        -- 2982606 when the coverage start date of the prev LE is in future
6176        -- and current LE is current or earlier than previous one
6177        -- create new result and not currently enrolled - two plan
6178      if g_debug then
6179        hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||
6180                                 l_crnt_enrt_cvg_strt_dt,1777);
6181      end if;
6182        if l_crnt_enrt_cvg_strt_dt > p_lf_evt_ocrd_dt then
6183             ben_determine_date.rate_and_coverage_dates
6184              (p_cache_mode          => TRUE
6185              ,p_per_in_ler_id       => l_per_in_ler_id
6186              ,p_person_id           => p_person_id
6187              ,p_pgm_id              => p_pgm_id
6188              ,p_pl_id               => l_pl_id
6189              ,p_oipl_id             => p_oipl_id
6190              ,p_par_ptip_id         => p_comp_obj_tree_row.par_ptip_id
6191              ,p_par_plip_id         => p_comp_obj_tree_row.par_plip_id
6192              ,p_lee_rsn_id          => l_rec_lee_rsn_id
6193              ,p_enrt_perd_id        => l_rec_enrt_perd_id
6194              ,p_business_group_id   => p_business_group_id
6195              ,p_which_dates_cd      => 'C'
6196              ,p_date_mandatory_flag => 'N'
6197              ,p_compute_dates_flag  => 'Y'
6198              ,p_enrt_cvg_strt_dt    => l_rec_enrt_cvg_strt_dt
6199              ,p_enrt_cvg_strt_dt_cd => l_dummy_enrt_cvg_strt_dt_cd
6200              ,p_enrt_cvg_strt_dt_rl => l_dummy_enrt_cvg_strt_dt_rl
6201              ,p_rt_strt_dt          => l_dummy_rt_strt_dt
6202              ,p_rt_strt_dt_cd       => l_dummy_rt_strt_dt_cd
6203              ,p_rt_strt_dt_rl       => l_dummy_rt_strt_dt_rl
6204              ,p_enrt_cvg_end_dt     => l_dummy_enrt_cvg_end_dt
6205              ,p_enrt_cvg_end_dt_cd  => l_dummy_enrt_cvg_end_dt_cd
6206              ,p_enrt_cvg_end_dt_rl  => l_dummy_enrt_cvg_end_dt_rl
6207              ,p_rt_end_dt           => l_dummy_rt_end_dt
6208              ,p_rt_end_dt_cd        => l_dummy_rt_end_dt_cd
6209              ,p_rt_end_dt_rl        => l_dummy_rt_end_dt_rl
6210              ,p_effective_date      => p_effective_date
6211             ,p_lf_evt_ocrd_dt       => GREATEST(
6212                                         NVL(p_lf_evt_ocrd_dt, l_prtn_strt_dt),
6213                                         NVL(l_prtn_strt_dt, p_lf_evt_ocrd_dt))
6214              );
6215 	     if g_debug then
6216              hr_utility.set_location('Done RACD:' || l_proc, 11);
6217 	     end if;
6218 
6219 	     if  l_rec_enrt_cvg_strt_dt >=   l_crnt_enrt_cvg_strt_dt then
6220                  l_rec_enrt_cvg_strt_dt :=  l_crnt_enrt_cvg_strt_dt;
6221              else
6222                  l_rec_enrt_cvg_strt_dt_cd   := L_dummy_enrt_cvg_strt_dt_cd ;
6223                  l_rec_enrt_cvg_strt_dt_rl   := l_dummy_enrt_cvg_strt_dt_rl ;
6224                  l_rec_crntly_enrd_flag      := 'N' ;
6225             end if;
6226 	    if g_debug then
6227             hr_utility.set_location('l_rec_enrt_cvg_strt_dt RACD:'|| l_rec_enrt_cvg_strt_dt, 11);
6228 	    end if;
6229 
6230        end if ;
6231        ---2982606
6232 
6233     ELSE
6234     if g_debug then
6235       hr_utility.set_location(' RACD:' || l_proc, 10);
6236     end if;
6237       ben_determine_date.rate_and_coverage_dates
6238         (p_cache_mode          => TRUE
6239         ,p_per_in_ler_id       => l_per_in_ler_id
6240         ,p_person_id           => p_person_id
6241         ,p_pgm_id              => p_pgm_id
6242         ,p_pl_id               => l_pl_id
6243         ,p_oipl_id             => p_oipl_id
6244         ,p_par_ptip_id         => p_comp_obj_tree_row.par_ptip_id
6245         ,p_par_plip_id         => p_comp_obj_tree_row.par_plip_id
6246         ,p_lee_rsn_id          => l_rec_lee_rsn_id
6247         ,p_enrt_perd_id        => l_rec_enrt_perd_id
6248 
6249         ,p_business_group_id   => p_business_group_id
6250         ,p_which_dates_cd      => 'C'
6251         ,p_date_mandatory_flag => 'N'
6252         ,p_compute_dates_flag  => 'Y'
6253         ,p_enrt_cvg_strt_dt    => l_rec_enrt_cvg_strt_dt
6254         ,p_enrt_cvg_strt_dt_cd => l_rec_enrt_cvg_strt_dt_cd
6255         ,p_enrt_cvg_strt_dt_rl => l_rec_enrt_cvg_strt_dt_rl
6256         ,p_rt_strt_dt          => l_dummy_rt_strt_dt
6257         ,p_rt_strt_dt_cd       => l_dummy_rt_strt_dt_cd
6258         ,p_rt_strt_dt_rl       => l_dummy_rt_strt_dt_rl
6259         ,p_enrt_cvg_end_dt     => l_dummy_enrt_cvg_end_dt
6260         ,p_enrt_cvg_end_dt_cd  => l_dummy_enrt_cvg_end_dt_cd
6261         ,p_enrt_cvg_end_dt_rl  => l_dummy_enrt_cvg_end_dt_rl
6262         ,p_rt_end_dt           => l_dummy_rt_end_dt
6263         ,p_rt_end_dt_cd        => l_dummy_rt_end_dt_cd
6264         ,p_rt_end_dt_rl        => l_dummy_rt_end_dt_rl
6265         ,p_effective_date      => p_effective_date
6266         ,p_lf_evt_ocrd_dt      => GREATEST(
6267                                    NVL(p_lf_evt_ocrd_dt, l_prtn_strt_dt),
6268                                    NVL(l_prtn_strt_dt, p_lf_evt_ocrd_dt))
6269         );
6270    if g_debug then
6271       hr_utility.set_location('Done RACD:' || l_proc, 10);
6272    end if;
6273     END IF;
6274     --
6275     -- Determine the erlst_deenrt_dt
6276     --
6277     if g_debug then
6278     hr_utility.set_location('AB', 20);
6279     end if;
6280     --
6281  IF p_run_mode <> 'D' THEN
6282     -- Find the required period of enrollment code/rule/uom/level defined at
6283     --
6284     find_rqd_perd_enrt(
6285       p_oipl_id                 => p_oipl_id,
6286       p_opt_id                  => l_opt_id,
6287       p_pl_id                   => l_pl_id,
6288       p_ptip_id                 => l_ptip_id,
6289 /*
6290       p_parptip_row             => p_parptip_row,
6291       p_parpl_row               => p_parpl_row,
6292       p_paropt_row              => p_paropt_row,
6293       p_paroipl_row             => p_paroipl_row,
6294 */
6295       p_effective_date          => NVL(p_lf_evt_ocrd_dt, p_effective_date),
6296       p_business_group_id       => p_business_group_id,
6297       p_rqd_perd_enrt_nenrt_uom => l_rqd_perd_enrt_nenrt_uom,
6298       p_rqd_perd_enrt_nenrt_val => l_rqd_perd_enrt_nenrt_val,
6299       p_rqd_perd_enrt_nenrt_rl  => l_rqd_perd_enrt_nenrt_rl,
6300       p_level                   => l_level);
6301     --
6302     -- If don't have an existing erlst_deenrt_dt and
6303     -- there is a code defined at some level
6304     -- then see if the date is set on some pen row at that level
6305     -- levels are OIPL, OPT, PL, PTIP.
6306     --
6307     IF     l_crnt_erlst_deenrt_dt IS NULL
6308        AND l_level IS NOT NULL THEN
6309       find_enrt_at_same_level(
6310         p_person_id         => p_person_id,
6311         p_opt_id            => l_opt_id,
6312         p_oipl_id           => p_oipl_id,
6313         p_pl_id             => l_pl_id,
6314         p_ptip_id           => l_ptip_id,
6315         p_pl_typ_id         => l_pl_typ_id,
6316         p_pgm_id            => p_pgm_id,
6317         p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
6318         p_business_group_id => p_business_group_id,
6319         p_prtt_enrt_rslt_id => -1,
6320         p_level             => l_level,
6321         p_pen_rec           => l_pen_rec);
6322         l_crnt_erlst_deenrt_dt :=  l_pen_rec.erlst_deenrt_dt;
6323 	if g_debug then
6324         hr_utility.set_location('l_crnt_erlst_deenrt_dt' || l_crnt_erlst_deenrt_dt,8086.0);
6325 	end if;
6326     END IF;
6327     --if elst_deenrt_dt is plan leven use original entrol date or
6328     -- option level  use coverage date
6329     l_erlst_deenrt_calc_dt   := l_rec_enrt_cvg_strt_dt  ;
6330     if l_level is not null then
6331       if l_level not in ('OPT','OIPL') then
6332          l_erlst_deenrt_calc_dt   := nvl(l_orgnl_enrt_dt,l_rec_enrt_cvg_strt_dt );
6333       end if ;
6334     end if ;
6335     if g_debug then
6336     hr_utility.set_location('l_erlst_deenrt_calc_dt' || l_erlst_deenrt_calc_dt ,8086);
6337     hr_utility.set_location('l_rec_enrt_cvg_strt_dt' || l_rec_enrt_cvg_strt_dt ,8086);
6338     end if;
6339     --
6340     -- if the enrt_cvg_strt_dt cannot be determined or
6341     -- the current enrt erlst_deenrt_dt is not null then
6342     -- use the old one
6343     --
6344     --IF ( l_rec_enrt_cvg_strt_dt IS NULL
6345     IF ( l_erlst_deenrt_calc_dt IS NULL
6346         OR l_crnt_erlst_deenrt_dt IS NOT NULL) THEN
6347       -- use the erlst_deenrt_dt from the current enrolment
6348       l_rec_erlst_deenrt_dt :=  l_crnt_erlst_deenrt_dt;
6349       --
6350     --
6351     -- else if the new enrolment cvg_strt_dt is set
6352     -- and the ptip.rqd_perd_enrt_nenrt_val is set then
6353     -- compute a new value
6354     --
6355     ELSIF (
6356                 l_erlst_deenrt_calc_dt IS NOT NULL
6357             AND (
6358                      (
6359                            l_rqd_perd_enrt_nenrt_val IS NOT NULL
6360                        AND l_rqd_perd_enrt_nenrt_uom IS NOT NULL)
6361                   OR l_rqd_perd_enrt_nenrt_rl IS NOT NULL)) THEN
6362       --
6363       -- compute the date based on the enrt_cvg_strt_dt and the
6364       -- rqd_perd_enrt_nenrt_val/uom.
6365       --
6366       l_rec_erlst_deenrt_dt :=
6367        determine_erlst_deenrt_dt(
6368          l_erlst_deenrt_calc_dt,
6369          l_rqd_perd_enrt_nenrt_val,
6370          l_rqd_perd_enrt_nenrt_uom,
6371          l_rqd_perd_enrt_nenrt_rl,
6372          p_oipl_id,
6373          l_pl_id,
6374          l_pl_typ_id,
6375          l_opt_id,
6376          p_pgm_id,
6377          p_ler_id,
6378          l_popl_yr_perd_ordr_num,
6379          l_yr_perd_end_date,
6380          p_effective_date,
6381          p_lf_evt_ocrd_dt,
6382          p_person_id,
6383          p_business_group_id,
6384          l_rec_assignment_id,
6385          l_rec_organization_id,
6386          l_jurisdiction_code);
6387     --
6388     ELSE
6389       -- Leave it blank.
6390       l_rec_erlst_deenrt_dt :=  NULL;
6391     --
6392     END IF;
6393   if g_debug then
6394     hr_utility.set_location('l_rec_erlst_deenrt_dt' || l_rec_erlst_deenrt_dt  ,8086);
6395   end if;
6396     --
6397 END IF; --'D' Mode
6398     -- set the comp_lvl_cd
6399     --
6400     IF (p_oipl_id IS NULL) THEN
6401       --
6402       IF l_invk_flx_cr_pl_flag = 'Y' THEN
6403         --
6404         l_rec_elctbl_flag :=  'N';
6405         l_comp_lvl_cd :=      'PLANFC';
6406       --
6407       ELSIF l_imptd_incm_calc_cd IN ('PRTT', 'DPNT', 'SPS') THEN
6408         --
6409         l_rec_elctbl_flag :=  'N';
6410         l_comp_lvl_cd :=      'PLANIMP';
6411       --
6412       ELSE
6413         --
6414         l_comp_lvl_cd :=  'PLAN';
6415       --
6416       END IF;
6417     --
6418     ELSE
6419       --
6420       l_comp_lvl_cd :=  'OIPL';
6421     --
6422     END IF;
6423     --
6424     -- Default the remaining fields
6425     -- roll_crs_only_flag to N
6426     --
6427     l_rec_roll_crs_only_flag :=   'N';
6428     -- elctns_made_flag to N
6429     l_rec_elctns_made_flag :=     'N';
6430     --
6431     -- Check all comp objects for existance when enrt perd starts
6432     --
6433     -- Start with pgm related things
6434     --
6435     --
6436     -- following requery logic added for bug 1394507 - for all plan design
6437     -- objects
6438     --
6439     IF p_pgm_id IS NOT NULL THEN
6440       --
6441       -- check pgm
6442       --
6443       IF (
6444            l_rec_enrt_perd_strt_dt NOT BETWEEN l_pgm_rec.effective_start_date
6445                AND l_pgm_rec.effective_end_date) THEN
6446         open c_pgm_requery(p_pgm_id,l_rec_enrt_perd_strt_dt);
6447         fetch c_pgm_requery into l_dummy;
6448         if c_pgm_requery%notfound then
6449 	if g_debug then
6450           hr_utility.set_location(
6451             'Program not date effective on period start',
6452             10);
6453         end if;
6454           fnd_message.set_name('BEN', 'BEN_92214_PGM_NOT_EFF_ON_STRT');
6455           fnd_message.set_token('PROC', l_proc);
6456           fnd_message.set_token(
6457             'ENRT_PERD_STRT_DT',
6458             TO_CHAR(l_rec_enrt_perd_strt_dt));
6459           fnd_message.set_token(
6460             'PGM_STRT_DT',
6461             TO_CHAR(l_pgm_rec.effective_start_date));
6462           fnd_message.set_token(
6463             'PGM_END_DT',
6464             TO_CHAR(l_pgm_rec.effective_end_date));
6465           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6466           p_electable_flag :=  'N';
6467           RETURN;
6468         end if;
6469         close c_pgm_requery;
6470       END IF;
6471       --
6472       -- check plip
6473       --
6474       IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_plip_esd AND l_plip_eed) THEN
6475         open c_plip_requery(l_plip_id,l_rec_enrt_perd_strt_dt);
6476         fetch c_plip_requery into l_dummy;
6477         if c_plip_requery%notfound then
6478 	if g_debug then
6479           hr_utility.set_location('Plip not date effective on period start', 10);
6480         end if;
6481           fnd_message.set_name('BEN', 'BEN_92208_PLIP_NOT_EFF_ON_STRT');
6482           fnd_message.set_token('PROC', l_proc);
6483           fnd_message.set_token(
6484             'ENRT_PERD_STRT_DT',
6485             TO_CHAR(l_rec_enrt_perd_strt_dt));
6486           fnd_message.set_token('PLIP_STRT_DT', TO_CHAR(l_plip_esd));
6487           fnd_message.set_token('PLIP_END_DT', TO_CHAR(l_plip_eed));
6488           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6489           p_electable_flag :=  'N';
6490           RETURN;
6491         end if;
6492         close c_plip_requery;
6493       END IF;
6494 
6495    if g_debug then
6496       hr_utility.set_location('NHK: l_lf_evt_ocrd_dt ' || l_lf_evt_ocrd_dt , 10);
6497       hr_utility.set_location('NHK: l_rec_enrt_perd_strt_dt ' || l_rec_enrt_perd_strt_dt , 20);
6498       hr_utility.set_location('NHK: l_ptip_esd ' || l_ptip_esd , 30);
6499       hr_utility.set_location('NHK: l_ptip_eed ' || l_ptip_eed , 40);
6500       hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 50);
6501       --
6502    end if;
6503       -- check ptip
6504       --
6505       IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_ptip_esd AND l_ptip_eed) THEN
6506       if g_debug then
6507         hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 60);
6508 	end if;
6509         open c_ptip_requery(l_ptip_id,l_rec_enrt_perd_strt_dt);
6510         fetch c_ptip_requery into l_dummy;
6511         if c_ptip_requery%notfound then
6512 	if g_debug then
6513           hr_utility.set_location('Ptip not date effective on period start', 10);
6514         end if;
6515           fnd_message.set_name('BEN', 'BEN_92213_PTIP_NOT_EFF_ON_STRT');
6516           fnd_message.set_token('PROC', l_proc);
6517           fnd_message.set_token(
6518             'ENRT_PERD_STRT_DT',
6519             TO_CHAR(l_rec_enrt_perd_strt_dt));
6520           fnd_message.set_token('PTIP_STRT_DT', TO_CHAR(l_ptip_esd));
6521           fnd_message.set_token('PTIP_END_DT', TO_CHAR(l_ptip_eed));
6522           benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6523           p_electable_flag :=  'N';
6524           -- Bug fix 2008871 -- hnarayan
6525           close c_ptip_requery;
6526           RETURN;
6527           -- End fix 2008871
6528 	  if g_debug then
6529           hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 70);
6530 	  end if;
6531         end if;
6532         close c_ptip_requery;
6533 	if g_debug then
6534         hr_utility.set_location('NHK: p_electable_flag ' || p_electable_flag , 80);
6535 	end if;
6536         -- Bug fix 2008871 -- hnarayan -- commented the return and included it above
6537         --  			since it affects positive cases of electability
6538         --			when l_rec_enrt_perd_strt_dt is not between the
6539         --			active ptip record which is effective (retrieved in c_ptip_requery also)
6540         --			as per the l_lf_ocrd_dt.
6541         -- RETURN;
6542       END IF;
6543     END IF;
6544     --
6545     -- Continue with option related things
6546     --
6547     IF p_oipl_id IS NOT NULL THEN
6548       --
6549       -- check oipl
6550       --
6551       IF (
6552            l_rec_enrt_perd_strt_dt NOT BETWEEN l_oipl_rec.effective_start_date
6553                AND l_oipl_rec.effective_end_date) THEN
6554         open c_oipl_requery(p_oipl_id,l_rec_enrt_perd_strt_dt);
6555         fetch c_oipl_requery into l_dummy;
6556         if c_oipl_requery%notfound then
6557 	if g_debug then
6558         hr_utility.set_location('Oipl not date effective on period start', 10);
6559 	end if;
6560         fnd_message.set_name('BEN', 'BEN_92207_OIPL_NOT_EFF_ON_STRT');
6561         fnd_message.set_token('PROC', l_proc);
6562         fnd_message.set_token(
6563           'ENRT_PERD_STRT_DT',
6564           TO_CHAR(l_rec_enrt_perd_strt_dt));
6565         fnd_message.set_token(
6566           'OIPL_STRT_DT',
6567           TO_CHAR(l_oipl_rec.effective_start_date));
6568         fnd_message.set_token(
6569           'OIPL_END_DT',
6570           TO_CHAR(l_oipl_rec.effective_end_date));
6571         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6572         p_electable_flag :=  'N';
6573         RETURN;
6574         end if;
6575         close c_oipl_requery;
6576       END IF;
6577       --
6578       -- check opt
6579       --
6580       IF (
6581            l_rec_enrt_perd_strt_dt NOT BETWEEN ben_cobj_cache.g_opt_currow.effective_start_date
6582                AND ben_cobj_cache.g_opt_currow.effective_end_date) THEN
6583         open c_opt_requery(l_opt_id,l_rec_enrt_perd_strt_dt);
6584         fetch c_opt_requery into l_dummy;
6585         if c_opt_requery%notfound then
6586 	if g_debug then
6587         hr_utility.set_location(
6588           'Option not date effective on period start',
6589           10);
6590         end if;
6591         fnd_message.set_name('BEN', 'BEN_92212_OPT_NOT_EFF_ON_STRT');
6592         fnd_message.set_token('PROC', l_proc);
6593         fnd_message.set_token(
6594           'ENRT_PERD_STRT_DT',
6595           TO_CHAR(l_rec_enrt_perd_strt_dt));
6596         fnd_message.set_token(
6597           'OPT_STRT_DT',
6598           TO_CHAR(ben_cobj_cache.g_opt_currow.effective_start_date));
6599         fnd_message.set_token(
6600           'OPT_END_DT',
6601           TO_CHAR(ben_cobj_cache.g_opt_currow.effective_end_date));
6602         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6603         p_electable_flag :=  'N';
6604         RETURN;
6605         end if;
6606         close c_opt_requery;
6607       END IF;
6608     END IF;
6609     --
6610     -- check plan
6611     --
6612     IF (
6613          l_rec_enrt_perd_strt_dt NOT BETWEEN l_plan_rec.effective_start_date
6614              AND l_plan_rec.effective_end_date) THEN
6615         open c_plan_requery(l_pl_id,l_rec_enrt_perd_strt_dt);
6616         fetch c_plan_requery into l_dummy;
6617         if c_plan_requery%notfound then
6618      if g_debug then
6619       hr_utility.set_location('Plan not date effective on period start', 10);
6620       hr_utility.set_location('perd_strt_dt=' || l_rec_enrt_perd_strt_dt, 1);
6621       hr_utility.set_location('strt_dt=' || l_plan_rec.effective_start_date, 1);
6622       hr_utility.set_location('end_dt=' || l_plan_rec.effective_end_date, 1);
6623      end if;
6624       fnd_message.set_name('BEN', 'BEN_92211_PLAN_NOT_EFF_ON_STRT');
6625       fnd_message.set_token('PROC', l_proc);
6626       fnd_message.set_token(
6627         'ENRT_PERD_STRT_DT',
6628         TO_CHAR(l_rec_enrt_perd_strt_dt));
6629       fnd_message.set_token(
6630         'PL_STRT_DT',
6631         TO_CHAR(l_plan_rec.effective_start_date));
6632       fnd_message.set_token(
6633         'PL_END_DT',
6634         TO_CHAR(l_plan_rec.effective_end_date));
6635       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6636       p_electable_flag :=  'N';
6637       RETURN;
6638         end if;
6639         close c_plan_requery;
6640     END IF;
6641     --
6642     -- check pl_typ
6643     --
6644     OPEN c_pl_typ;
6645     FETCH c_pl_typ INTO l_pl_typ_esd, l_pl_typ_eed;
6646     CLOSE c_pl_typ;
6647     if g_debug then
6648     hr_utility.set_location('close c_pl_typ:' || l_proc, 10);
6649     end if;
6650     IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_pl_typ_esd AND l_pl_typ_eed) THEN
6651         open c_pl_typ_requery(l_pl_typ_id,l_rec_enrt_perd_strt_dt);
6652         fetch c_pl_typ_requery into l_dummy;
6653         if c_pl_typ_requery%notfound then
6654       if g_debug then
6655       hr_utility.set_location('Pl_typ not date effective on period start', 10);
6656       end if;
6657       fnd_message.set_name('BEN', 'BEN_92206_PL_TYP_NOT_EFF_ON_ST');
6658       fnd_message.set_token('PROC', l_proc);
6659       fnd_message.set_token(
6660         'ENRT_PERD_STRT_DT',
6661         TO_CHAR(l_rec_enrt_perd_strt_dt));
6662       fnd_message.set_token('PL_TYP_STRT_DT', TO_CHAR(l_pl_typ_esd));
6663       fnd_message.set_token('PL_TYP_END_DT', TO_CHAR(l_pl_typ_eed));
6664       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6665       p_electable_flag :=  'N';
6666       RETURN;
6667         end if;
6668         close c_pl_typ_requery;
6669     END IF;
6670     --
6671     -- check lee_rsn
6672     --
6673     IF (
6674          l_rec_enrt_perd_strt_dt NOT BETWEEN l_rec_lee_rsn_esd
6675              AND l_rec_lee_rsn_eed) THEN
6676         open c_lee_rsn_requery(l_rec_lee_rsn_id,l_rec_enrt_perd_strt_dt);
6677         fetch c_lee_rsn_requery into l_dummy;
6678         if c_lee_rsn_requery%notfound then
6679     if g_debug then
6680       hr_utility.set_location(
6681         'Lee_rsn not date effective on period start',
6682         10);
6683     end if;
6684       fnd_message.set_name('BEN', 'BEN_92210_LEE_RSN_NOT_EFF_ON_S');
6685       fnd_message.set_token('PROC', l_proc);
6686       fnd_message.set_token(
6687         'ENRT_PERD_STRT_DT',
6688         TO_CHAR(l_rec_enrt_perd_strt_dt));
6689       fnd_message.set_token('LEE_RSN_STRT_DT', TO_CHAR(l_rec_lee_rsn_esd));
6690       fnd_message.set_token('LEE_RSN_END_DT', TO_CHAR(l_rec_lee_rsn_eed));
6691       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6692       p_electable_flag :=  'N';
6693       RETURN;
6694         end if;
6695         close c_lee_rsn_requery;
6696     END IF;
6697     --
6698     -- check ler
6699     --
6700     IF (l_rec_enrt_perd_strt_dt NOT BETWEEN l_ler_esd AND l_ler_eed) THEN
6701         open c_ler_requery(p_ler_id,l_rec_enrt_perd_strt_dt);
6702         fetch c_ler_requery into l_dummy;
6703         if c_ler_requery%notfound then
6704     if g_debug then
6705       hr_utility.set_location('Ler not date effective on period start', 10);
6706     end if;
6707       fnd_message.set_name('BEN', 'BEN_92209_LER_NOT_EFF_ON_STRT');
6708       fnd_message.set_token('PROC', l_proc);
6709       fnd_message.set_token(
6710         'ENRT_PERD_STRT_DT',
6711         TO_CHAR(l_rec_enrt_perd_strt_dt));
6712       fnd_message.set_token('LER_STRT_DT', TO_CHAR(l_ler_esd));
6713       fnd_message.set_token('LER_END_DT', TO_CHAR(l_ler_eed));
6714       benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
6715       p_electable_flag :=  'N';
6716       RETURN;
6717         end if;
6718         close c_ler_requery;
6719     END IF;
6720     --
6721     -- set the acty_ref_perd_cd and uom
6722     --
6723     IF p_pgm_id IS NOT NULL THEN
6724       l_rec_acty_ref_perd_cd :=  l_pgm_rec.acty_ref_perd_cd;
6725       l_rec_uom :=               l_pgm_rec.pgm_uom;
6726     ELSE                                                        -- use the plan
6727       l_rec_acty_ref_perd_cd :=  l_plan_rec.nip_acty_ref_perd_cd;
6728       l_rec_uom :=               l_plan_rec.nip_pl_uom;
6729     END IF;
6730     --
6731     -- Set the auto_enrt_flag based on which comp level is being created
6732     --
6733     IF p_oipl_id IS NOT NULL THEN
6734       l_rec_auto_enrt_flag :=  l_oipl_auto_enrt_flag;
6735     ELSE
6736       l_rec_auto_enrt_flag :=  l_auto_enrt_flag;
6737     END IF;
6738     --
6739     --Based on automatic enrollment codes, the auto enrt flag needs to
6740     --be overridden
6741     If l_pl_enrt_cd = 'CANA' then
6742       --
6743       l_rec_auto_enrt_flag := 'Y' ;
6744       --
6745     elsif l_pl_enrt_cd = 'CANN' and l_rec_crntly_enrd_flag = 'Y' then
6746       --
6747       l_rec_auto_enrt_flag := 'Y' ;
6748       --
6749     elsif l_pl_enrt_cd = 'CANN' and l_rec_crntly_enrd_flag = 'N' then
6750       --
6751       l_rec_auto_enrt_flag := 'N';
6752       --
6753     elsif l_pl_enrt_cd = 'CNNA' and nvl(l_rec_crntly_enrd_flag,'N') = 'N' then
6754       --
6755       l_rec_auto_enrt_flag := 'Y';
6756       --
6757     elsif l_pl_enrt_cd = 'CNNA' and l_rec_crntly_enrd_flag = 'Y' then
6758       --
6759       l_rec_auto_enrt_flag := 'N';
6760       --
6761     end if;
6762 
6763       --
6764 
6765     -- Choice can be either automatic or default, not both.
6766     --
6767     IF l_rec_auto_enrt_flag = 'Y' THEN
6768       --
6769       l_dflt_flag :=  'N';
6770     --
6771     END IF;
6772     --
6773     -- Validate cls_enrt_dt_to_use_cd is defined
6774     --
6775     IF l_rec_cls_enrt_dt_to_use_cd IS NULL THEN
6776       --
6777 --      hr_utility.set_location('Invalid cls_enrt_dt_cd', 10);
6778       --
6779       fnd_message.set_name('BEN', 'BEN_91905_INVLD_CLS_ENRT_DT_CD');
6780       fnd_message.set_token('PROC', l_proc);
6781       fnd_message.set_token(
6782         'CLS_ENRT_DT_TO_USE_CD',
6783         l_rec_cls_enrt_dt_to_use_cd);
6784       RAISE ben_manage_life_events.g_record_error;
6785     --
6786     END IF;
6787     --
6788     -- We need to determine if an electable choice has been written or not
6789     --
6790 --    hr_utility.set_location('AG', 20);
6791     IF p_ler_id IS NOT NULL THEN
6792       --
6793       g_any_choice_created :=  TRUE;
6794       IF l_rec_elctbl_flag = 'Y' THEN
6795         g_electable_choice_created :=  TRUE;
6796       END IF;
6797       IF l_rec_auto_enrt_flag = 'Y' THEN
6798         g_auto_choice_created :=  TRUE;
6799       END IF;
6800     --
6801     END IF;
6802     -- cwb changes
6803     if p_run_mode = 'W' then
6804 
6805        g_ple_hrchy_to_use_cd       := l_ple_hrchy_to_use_cd;
6806        g_ple_pos_structure_version_id := l_ple_pos_structure_version_id;
6807        --
6808        /*
6809        -- For GLOBALCWB : this call is moved to benptnle
6810        get_cwb_manager_and_assignment(p_person_id => p_person_id,
6811                                       p_hrchy_to_use_cd => l_ple_hrchy_to_use_cd,
6812                                       p_pos_structure_version_id => l_ple_pos_structure_version_id,
6813                                       p_effective_date => p_effective_date,
6814                                       p_manager_id     => l_ws_mgr_id,
6815                                       p_assignment_id  => l_assignment_id ) ;
6816        */
6817        --
6818     end if;
6819 
6820     -- Bug 2503570
6821     -- 1. Irrespective of a person is eligible or not Elctble_flag is set to Y
6822     -- in case of CWB electable choices. Electable choices created for
6823     -- managers will always have Elctble_flag set to N.
6824     -- 2. If person is not eligible then elig_flag will be set to N else Y.
6825     --
6826     if p_run_mode = 'W' then
6827        l_rec_elctbl_flag := 'Y';
6828     end if;
6829 
6830     if l_current_eligibility = 'Y' then
6831        l_elig_flag := 'Y';
6832     else
6833        l_elig_flag  := 'N';
6834     end if;
6835 --
6836 --    hr_utility.set_location('Calling Create Api', 10);
6837 --    hr_utility.set_location('p_enrt_perd_id ' || l_rec_enrt_perd_id, 10);
6838 --    hr_utility.set_location('p_lee_rsn_id ' || l_rec_lee_rsn_id, 10);
6839 --    hr_utility.set_location('l_per_in_ler_id ' || l_per_in_ler_id, 10);
6840 --    hr_utility.set_location('l_prtt_enrt_rslt_id ' || l_prtt_enrt_rslt_id, 10);
6841     --
6842     /* if p_run_mode = 'W'
6843     then  Bug 3502094  : For FP-F this flag do not have any significance.
6844                            For july FP : final functionality will be decided.
6845       and l_elig_flag = 'N' and
6846        ( (p_oipl_id is null and
6847           nvl(l_pl_trk_inelig_per_flag,'N') = 'N') or
6848          (p_oipl_id is not null and
6849           nvl(l_oipl_trk_inelig_per_flag,'N') = 'N') ) then
6850        hr_utility.set_location('By passing creation of epe for CWB'||l_proc,10);
6851     else
6852     */
6853        if ben_manage_life_events.fonm = 'Y' then
6854        if g_debug then
6855           hr_utility.set_location('fonm cvr strt dt',100);
6856        end if;
6857           l_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt;
6858        end if;
6859        if g_debug then
6860        hr_utility.set_location('EPEC_CRE: ' || l_proc, 10);
6861        end if;
6862        /* unrestricted Enh*/
6863        if p_run_mode in ('U','R') then
6864        if g_debug then
6865           hr_utility.set_location('before epe exists',11);
6866        end if;
6867          --
6868          l_epe_exists :=  ben_manage_unres_life_events.epe_exists
6869                   (p_per_in_ler_id => l_per_in_ler_id,
6870                    p_pgm_id => p_pgm_id,
6871                    p_pl_id  => l_pl_id,
6872                    p_oipl_id =>p_oipl_id);
6873          if l_epe_exists is not null then
6874             ben_manage_unres_life_events.update_elig_per_elctbl_choice
6875             (
6876              p_elig_per_elctbl_chc_id => l_epe_exists,
6877              p_business_group_id      => p_business_group_id,
6878              p_auto_enrt_flag         => NVL(l_rec_auto_enrt_flag,'N'),
6879              p_per_in_ler_id          => l_per_in_ler_id,
6880              p_yr_perd_id             => l_yr_perd_id,
6881              p_pl_id                  => l_pl_id,
6882              p_pl_typ_id              => l_pl_typ_id,
6883              p_oipl_id                => p_oipl_id,
6884              p_pgm_id                 => p_pgm_id,
6885              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
6886              p_must_enrl_anthr_pl_id  => l_must_enrl_anthr_pl_id,
6887              p_plip_id                => l_plip_id,
6888              p_ptip_id                => l_ptip_id,
6889              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
6890              p_comp_lvl_cd            => l_comp_lvl_cd,
6891              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
6892              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
6893              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
6894              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
6895              p_roll_crs_flag          => 'N',
6896              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
6897              p_crntly_enrd_flag       => NVL(l_rec_crntly_enrd_flag,'N'),
6898              p_dflt_flag              => NVL(l_dflt_flag,'N'),
6899              p_elctbl_flag            => NVL(l_rec_elctbl_flag,'N'),
6900              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
6901              p_dflt_enrt_dt           => l_rec_dflt_asnmt_dt,
6902              p_dpnt_cvg_strt_dt_cd    => NULL,
6903              p_dpnt_cvg_strt_dt_rl    => NULL,
6904              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
6905              p_alws_dpnt_dsgn_flag    => 'N',
6906              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
6907              p_procg_end_dt           => l_rec_procg_end_dt,
6908              p_pl_ordr_num            => l_plan_rec.ordr_num,
6909              p_plip_ordr_num          => l_plip_ordr_num,
6910              p_ptip_ordr_num          => l_ptip_ordr_num,
6911              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
6912              --p_object_version_number  => l_object_version_number,
6913              p_effective_date         => p_effective_date,
6914              p_enrt_perd_id           => l_rec_enrt_perd_id,
6915              p_lee_rsn_id             => l_rec_lee_rsn_id,
6916              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
6917              p_uom                    => l_rec_uom,
6918              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
6919              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
6920              p_ws_mgr_id              => l_ws_mgr_id,
6921              p_elig_flag              => NVL(l_elig_flag,'Y'),
6922              p_assignment_id          => l_assignment_id ,
6923              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
6924              p_inelig_rsn_cd	  => l_inelg_rsn_cd);
6925              --
6926              l_elig_per_elctbl_chc_id := l_epe_exists;
6927           end if;
6928          --
6929        end if;
6930        if l_epe_exists is null then
6931          ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
6932          p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
6933          p_business_group_id      => p_business_group_id,
6934          p_auto_enrt_flag         => NVL(l_rec_auto_enrt_flag,'N'),
6935          p_per_in_ler_id          => l_per_in_ler_id,
6936          p_yr_perd_id             => l_yr_perd_id,
6937          p_pl_id                  => l_pl_id,
6938          p_pl_typ_id              => l_pl_typ_id,
6939          p_oipl_id                => p_oipl_id,
6940          p_pgm_id                 => p_pgm_id,
6941          p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
6942          p_must_enrl_anthr_pl_id  => l_must_enrl_anthr_pl_id,
6943          p_plip_id                => l_plip_id,
6944          p_ptip_id                => l_ptip_id,
6945          p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
6946          p_enrt_typ_cycl_cd       => l_rec_enrt_typ_cycl_cd,
6947          p_comp_lvl_cd            => l_comp_lvl_cd,
6948          p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
6949          p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
6950          p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
6951          p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
6952          p_roll_crs_flag          => 'N',
6953          p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
6954          p_crntly_enrd_flag       => NVL(l_rec_crntly_enrd_flag,'N'),
6955          p_dflt_flag              => NVL(l_dflt_flag,'N'),
6956          p_elctbl_flag            => NVL(l_rec_elctbl_flag,'N'),
6957          p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
6958          p_dflt_enrt_dt           => l_rec_dflt_asnmt_dt,
6959          p_dpnt_cvg_strt_dt_cd    => NULL,
6960          p_dpnt_cvg_strt_dt_rl    => NULL,
6961          p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
6962          p_alws_dpnt_dsgn_flag    => 'N',
6963          p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
6964          p_procg_end_dt           => l_rec_procg_end_dt,
6965          p_pl_ordr_num            => l_plan_rec.ordr_num,
6966          p_plip_ordr_num          => l_plip_ordr_num,
6967          p_ptip_ordr_num          => l_ptip_ordr_num,
6968          p_oipl_ordr_num          => l_oipl_rec.ordr_num,
6969          p_object_version_number  => l_object_version_number,
6970          p_effective_date         => p_effective_date,
6971          p_program_application_id => fnd_global.prog_appl_id,
6972          p_program_id             => fnd_global.conc_program_id,
6973          p_request_id             => fnd_global.conc_request_id,
6974          p_program_update_date    => SYSDATE,
6975          p_enrt_perd_id           => l_rec_enrt_perd_id,
6976          p_lee_rsn_id             => l_rec_lee_rsn_id,
6977          p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
6978          p_uom                    => l_rec_uom,
6979          p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
6980          p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
6981          -- added for cwb
6982          p_ws_mgr_id              => l_ws_mgr_id,
6983          p_elig_flag              => NVL(l_elig_flag,'Y'),
6984          p_assignment_id          => l_assignment_id ,
6985          p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
6986          p_inelig_rsn_cd	  => l_inelg_rsn_cd); -- 2650247
6987 
6988       if g_debug then
6989          hr_utility.set_location('Done EPEC_CRE: ' || l_proc, 10);
6990       end if;
6991        end if;
6992     --
6993     -- As part GLOBALCWB populating data into heirachy table
6994     -- is moved to per in ler table
6995     --
6996 /*
6997        --
6998        -- CWBITEM : Code moved to beepeapi.pkb
6999        --
7000     if p_run_mode = 'W' and l_elig_per_elctbl_chc_id is not null then
7001 
7002        --
7003        -- Populate the heirarchy table.
7004        --
7005        --
7006        open c_hrchy(l_elig_per_elctbl_chc_id);
7007        fetch c_hrchy into l_emp_pel_id, l_pel_id;
7008        --
7009        if l_pel_id is not null and l_emp_pel_id is null then
7010           --
7011           insert into ben_cwb_hrchy (
7012              emp_pil_elctbl_chc_popl_id,
7013              mgr_pil_elctbl_chc_popl_id,
7014              lvl_num  )
7015           values(
7016              l_pel_id,
7017              -1,
7018              -1);
7019           --
7020        end if;
7021        --
7022        close c_hrchy;
7023        --
7024     end if;
7025 */
7026     --
7027     p_elig_per_elctbl_chc_id :=   l_elig_per_elctbl_chc_id;
7028     --
7029     g_rec.person_id :=            p_person_id;
7030     g_rec.pgm_id :=               p_pgm_id;
7031     g_rec.pl_id :=                p_pl_id;
7032     g_rec.oipl_id :=              p_oipl_id;
7033     g_rec.enrt_cvg_strt_dt :=     l_rec_enrt_cvg_strt_dt;
7034     g_rec.enrt_perd_strt_dt :=    l_rec_enrt_perd_strt_dt;
7035     g_rec.enrt_perd_end_dt :=     l_rec_enrt_perd_end_dt;
7036     g_rec.erlst_deenrt_dt :=      l_rec_erlst_deenrt_dt;
7037     g_rec.dflt_enrt_dt :=         l_rec_dflt_asnmt_dt;
7038     g_rec.enrt_typ_cycl_cd :=     l_rec_enrt_typ_cycl_cd;
7039     g_rec.comp_lvl_cd :=          l_comp_lvl_cd;
7040     g_rec.mndtry_flag :=          l_rec_mndtry_flag;
7041     g_rec.dflt_flag :=            l_dflt_flag;
7042     g_rec.business_group_id :=    p_business_group_id;
7043     g_rec.effective_date :=       p_effective_date;
7044     --
7045     benutils.write(p_rec => g_rec);
7046     if g_debug then
7047     hr_utility.set_location('FND mess: ' || l_proc, 10);
7048     end if;
7049     --
7050     fnd_message.set_name('BEN', 'BEN_91736_EPE_CHC_CREATED');
7051     fnd_message.set_token('PERSON_ID', p_person_id);
7052     fnd_message.set_token('LER_NAME', l_ler_name);
7053     fnd_message.set_token('COMP_LVL_CD', l_comp_lvl_cd);
7054     fnd_message.set_token('PLAN_NAME', l_pl_name);
7055     fnd_message.set_token('OIPL_NAME', l_oipl_name);
7056     --
7057     if g_debug then
7058     hr_utility.set_location('Dn FND mess: ' || l_proc, 10);
7059     end if;
7060     benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
7061     --
7062     -- if choice is created for an oipl create one for plan it belongs to
7063     -- first find out if it already exists.
7064     --
7065     if g_debug then
7066     hr_utility.set_location('(p_oipl_id NN): ' || l_proc, 10);
7067     end if;
7068     IF (p_oipl_id IS NOT NULL) THEN
7069       --
7070       OPEN c_choice_exists_for_plan(l_pl_id);
7071       --
7072       FETCH c_choice_exists_for_plan INTO l_choice_exists_flag;
7073       --
7074       IF c_choice_exists_for_plan%NOTFOUND  or p_run_mode not in ('U','R') THEN
7075         --
7076         OPEN c_current_elig_for_plan;
7077         --
7078         FETCH c_current_elig_for_plan INTO l_elig_per_id,
7079                                            l_current_eligibility,
7080                                            l_must_enrl_anthr_pl_id,
7081                                            l_prtn_strt_dt,
7082                                            l_inelg_rsn_cd; -- 2650247
7083         --
7084         IF c_current_elig_for_plan%NOTFOUND THEN
7085           --
7086           l_current_eligibility :=  'N';
7087         --
7088         END IF;
7089         --
7090         CLOSE c_current_elig_for_plan;
7091       --
7092       END IF;
7093       --
7094       if g_debug then
7095       hr_utility.set_location('CREL=Y ' || l_proc, 10);
7096       end if;
7097       -- IF    ( c_choice_exists_for_plan%NOTFOUND or p_run_mode not in ('U','R')) /* Bug 4023880 : Commented */
7098       IF    ( c_choice_exists_for_plan%NOTFOUND  or l_plan_rec.svgs_pl_flag = 'Y') -- Bug 4717052 added or
7099          AND l_current_eligibility = 'Y' THEN
7100         --
7101 --  if the plan is savings , as it is electable even if the plan is having options, check for any previous
7102 --  enrollment
7103         --
7104         if l_plan_rec.svgs_pl_flag = 'Y' then
7105            --
7106            OPEN c_plan_enrolment_info(l_lf_evt_ocrd_dt_1);
7107            --
7108            FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
7109                                        l_crnt_erlst_deenrt_dt,
7110                                        l_prtt_enrt_rslt_id,
7111                                        l_enrt_ovridn_flag,
7112                                        l_enrt_ovrid_thru_dt,
7113                                        l_orgnl_enrt_dt,
7114                                        l_crnt_enrt_cvg_thru_dt,    --BUG 6519487 fix
7115                                        l_current_pl_typ_id ;   --BUG 6519487 fix
7116           if c_plan_enrolment_info%found then
7117              l_prtt_enrt_rslt_id_2 := l_prtt_enrt_rslt_id;
7118           end if;
7119           --
7120           CLOSE c_plan_enrolment_info;
7121           --
7122         end if;
7123         --
7124         l_epe_exists := null;
7125         if p_run_mode in ('U','R') then
7126 	if g_debug then
7127           hr_utility.set_location('before epe exists',11);
7128         end if;
7129          --
7130          l_epe_exists :=  ben_manage_unres_life_events.epe_exists
7131                   (p_per_in_ler_id => l_per_in_ler_id,
7132                    p_pgm_id => p_pgm_id,
7133                    p_pl_id  => l_pl_id,
7134                    p_oipl_id =>-1);
7135          if l_epe_exists is not null or (l_plan_rec.svgs_pl_flag = 'Y' and -- Bug 4717052 added or
7136                                           (--l_prtt_enrt_rslt_id_2 is not null or - bug 5035423
7137                                           c_choice_exists_for_plan%FOUND) )
7138           then
7139          --
7140          -- Bug 4717052, epe_exists will get from the global plsql table g_unrest_epe_instance
7141          -- which was populated during reuse of PIL,
7142          -- If its the new PIL, epe_exists will b null, but if exists in the DB,
7143          -- then just update it.
7144          -- for savings plan: PLAN epe shd be updated with pen_id
7145          --
7146             ben_manage_unres_life_events.update_elig_per_elctbl_choice
7147             (p_elig_per_elctbl_chc_id => nvl(l_epe_exists,l_choice_exists_flag),
7148              p_business_group_id      => p_business_group_id,
7149              p_auto_enrt_flag         => 'N',
7150              p_per_in_ler_id          => l_per_in_ler_id,
7151              p_yr_perd_id             => l_yr_perd_id,
7152              p_pl_id                  => l_pl_id,
7153              p_pl_typ_id              => l_pl_typ_id,
7154              p_oipl_id                => NULL,               -- this is the kicker
7155              p_pgm_id                 => p_pgm_id,
7156              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7157              p_must_enrl_anthr_pl_id  => NULL,
7158              p_plip_id                => l_plip_id,
7159              p_ptip_id                => l_ptip_id,
7160              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id_2,  -- NULL was before
7161              p_comp_lvl_cd            => 'PLAN',
7162              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7163              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7164              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7165              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7166              p_roll_crs_flag          => 'N',
7167              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7168              p_crntly_enrd_flag       => 'N',
7169              p_dflt_flag              => 'N',
7170              p_elctbl_flag            => 'N',
7171              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7172              p_dflt_enrt_dt           => NULL,
7173              p_dpnt_cvg_strt_dt_cd    => NULL,
7174              p_dpnt_cvg_strt_dt_rl    => NULL,
7175              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7176              p_alws_dpnt_dsgn_flag    => 'N',
7177              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7178              p_procg_end_dt           => l_rec_procg_end_dt,
7179              p_pl_ordr_num            => l_plan_rec.ordr_num,
7180              p_plip_ordr_num          => l_plip_ordr_num,
7181              p_ptip_ordr_num          => l_ptip_ordr_num,
7182              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7183              p_effective_date         => p_effective_date,
7184              p_enrt_perd_id           => l_rec_enrt_perd_id,
7185              p_lee_rsn_id             => l_rec_lee_rsn_id,
7186              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7187              p_uom                    => l_rec_uom,
7188              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7189              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7190              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7191              p_inelig_rsn_cd          => l_inelg_rsn_cd);
7192              --
7193              l_elig_per_elctbl_chc_id := nvl(l_epe_exists,l_choice_exists_flag);
7194           end if;
7195           --
7196         end if;
7197         --
7198         if l_epe_exists is null and c_choice_exists_for_plan%NOTFOUND then
7199             -- Bug4717052, added choices_exists_for_plan not found
7200              ben_elig_per_elc_chc_api.create_perf_elig_per_elc_chc(
7201              p_elig_per_elctbl_chc_id => l_elig_per_elctbl_chc_id,
7202              p_business_group_id      => p_business_group_id,
7203              p_auto_enrt_flag         => 'N',
7204              p_per_in_ler_id          => l_per_in_ler_id,
7205              p_yr_perd_id             => l_yr_perd_id,
7206              p_pl_id                  => l_pl_id,
7207              p_pl_typ_id              => l_pl_typ_id,
7208              p_oipl_id                => NULL,               -- this is the kicker
7209              p_pgm_id                 => p_pgm_id,
7210              p_pgm_typ_cd             => l_pgm_rec.pgm_typ_cd,
7211              p_must_enrl_anthr_pl_id  => NULL,
7212              p_plip_id                => l_plip_id,
7213              p_ptip_id                => l_ptip_id,
7214              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id_2,  -- NULL was before
7215              p_enrt_typ_cycl_cd       => l_rec_enrt_typ_cycl_cd,
7216              p_comp_lvl_cd            => 'PLAN',
7217              p_enrt_cvg_strt_dt_cd    => l_rec_enrt_cvg_strt_dt_cd,
7218              p_enrt_perd_end_dt       => l_rec_enrt_perd_end_dt,
7219              p_enrt_perd_strt_dt      => l_rec_enrt_perd_strt_dt,
7220              p_enrt_cvg_strt_dt_rl    => l_rec_enrt_cvg_strt_dt_rl,
7221              p_roll_crs_flag          => 'N',
7222              p_ctfn_rqd_flag          => NVL(l_ctfn_rqd_flag,'N'),
7223              p_crntly_enrd_flag       => 'N',
7224              p_dflt_flag              => 'N',
7225              p_elctbl_flag            => 'N',
7226              p_mndtry_flag            => NVL(l_rec_mndtry_flag,'N'),
7227              p_dflt_enrt_dt           => NULL,
7228              p_dpnt_cvg_strt_dt_cd    => NULL,
7229              p_dpnt_cvg_strt_dt_rl    => NULL,
7230              p_enrt_cvg_strt_dt       => l_rec_enrt_cvg_strt_dt,
7231              p_alws_dpnt_dsgn_flag    => 'N',
7232              p_erlst_deenrt_dt        => l_rec_erlst_deenrt_dt,
7233              p_procg_end_dt           => l_rec_procg_end_dt,
7234              p_pl_ordr_num            => l_plan_rec.ordr_num,
7235              p_plip_ordr_num          => l_plip_ordr_num,
7236              p_ptip_ordr_num          => l_ptip_ordr_num,
7237              p_oipl_ordr_num          => l_oipl_rec.ordr_num,
7238              p_object_version_number  => l_object_version_number,
7239              p_effective_date         => p_effective_date,
7240              p_program_application_id => fnd_global.prog_appl_id,
7241              p_program_id             => fnd_global.conc_program_id,
7242              p_request_id             => fnd_global.conc_request_id,
7243              p_program_update_date    => SYSDATE,
7244              p_enrt_perd_id           => l_rec_enrt_perd_id,
7245              p_lee_rsn_id             => l_rec_lee_rsn_id,
7246              p_cls_enrt_dt_to_use_cd  => l_rec_cls_enrt_dt_to_use_cd,
7247              p_uom                    => l_rec_uom,
7248              p_acty_ref_perd_cd       => l_rec_acty_ref_perd_cd,
7249              p_cryfwd_elig_dpnt_cd    => l_reinstt_cd,
7250              p_fonm_cvg_strt_dt       => l_fonm_cvg_strt_dt,
7251              p_inelig_rsn_cd	   => l_inelg_rsn_cd); -- 2650247
7252 	     if g_debug then
7253              hr_utility.set_location('Done EPEC_CRE1: ' || l_proc, 10);
7254 	     end if;
7255              --
7256         end if;
7257         --
7258         g_rec.person_id :=          p_person_id;
7259         g_rec.pgm_id :=             p_pgm_id;
7260         g_rec.pl_id :=              l_pl_id;
7261         g_rec.oipl_id :=            NULL;
7262         g_rec.enrt_cvg_strt_dt :=   l_rec_enrt_cvg_strt_dt;
7263         g_rec.enrt_perd_strt_dt :=  l_rec_enrt_perd_strt_dt;
7264         g_rec.enrt_perd_end_dt :=   l_rec_enrt_perd_end_dt;
7265         g_rec.erlst_deenrt_dt :=    l_rec_erlst_deenrt_dt;
7266         g_rec.dflt_enrt_dt :=       NULL;
7267         g_rec.enrt_typ_cycl_cd :=   l_rec_enrt_typ_cycl_cd;
7268         g_rec.comp_lvl_cd :=        'PLAN';
7269         g_rec.mndtry_flag :=        l_rec_mndtry_flag;
7270         g_rec.dflt_flag :=          'N';
7271         g_rec.business_group_id :=  p_business_group_id;
7272         g_rec.effective_date :=     p_effective_date;
7273         --
7274         benutils.write(p_rec => g_rec);
7275         --
7276 	if g_debug then
7277         hr_utility.set_location('FND Mess: ' || l_proc, 10);
7278 	end if;
7279         fnd_message.set_name('BEN', 'BEN_91736_EPE_CHC_CREATED');
7280         fnd_message.set_token('PERSON_ID', p_person_id);
7281         fnd_message.set_token('LER_NAME', l_ler_name);
7282         fnd_message.set_token('COMP_LVL_CD', l_comp_lvl_cd);
7283         fnd_message.set_token('PLAN_NAME', l_pl_name);
7284         fnd_message.set_token('OIPL_NAME', ' ');
7285 	if g_debug then
7286         hr_utility.set_location('Dn FND Mess: ' || l_proc, 10);
7287 	end if;
7288         benutils.write(p_text => SUBSTR(fnd_message.get, 1, 128));
7289 	if g_debug then
7290         hr_utility.set_location('Dn FND GetMess: ' || l_proc, 10);
7291 	end if;
7292       --
7293       END IF;                                                          -- found
7294       --
7295       CLOSE c_choice_exists_for_plan;
7296       if g_debug then
7297       hr_utility.set_location('close CEFP: ' || l_proc, 10);
7298       end if;
7299     --
7300     END IF;
7301     --
7302     --
7303     -- Set return value
7304     p_electable_flag := l_rec_elctbl_flag;
7305     --
7306     if g_debug then
7307     hr_utility.set_location(' Leaving:' || l_proc, 70);
7308     end if;
7309   --
7310   exception  -- nocopy changes
7311     --
7312     when others then
7313       --
7314       p_electable_flag := null;
7315       p_elig_per_elctbl_chc_id := null;
7316       raise;
7317       --
7318   END enrolment_requirements;
7319 
7320  PROCEDURE execute_auto_dflt_enrt_rule(
7321     p_opt_id            NUMBER,
7322     p_pl_id             NUMBER,
7323     p_pgm_id            NUMBER,
7324     p_rule_id           NUMBER,
7325     p_ler_id            NUMBER,
7326     p_pl_typ_id         NUMBER,
7327     p_business_group_id NUMBER,
7328     p_effective_date    DATE,
7329     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
7330     p_elig_per_id       NUMBER DEFAULT NULL,
7331     p_assignment_id     NUMBER,
7332     p_organization_id   NUMBER,
7333     p_jurisdiction_code VARCHAR2,
7334     p_person_id         NUMBER,               -- Bug 5331889
7335     p_enrt_mthd         out nocopy varchar2,
7336     p_reinstt_dpnt      out nocopy varchar2
7337     ) IS
7338     --
7339     l_package       VARCHAR2(80)      := g_package || '.execute_auto_dflt_enrt_rule';
7340     l_outputs       ff_exec.outputs_t;
7341     --
7342     l_param1        VARCHAR2(30);
7343     l_param1_value  VARCHAR2(30);
7344     l_param2        VARCHAR2(30);
7345     l_param2_value  VARCHAR2(30);
7346     l_param3        VARCHAR2(30);
7347     l_param3_value  VARCHAR2(30);
7348     l_param4        VARCHAR2(30);
7349     l_param4_value  VARCHAR2(30);
7350     l_param5        VARCHAR2(30);
7351     l_param5_value  VARCHAR2(30);
7352     l_param6        VARCHAR2(30);
7353     l_param6_value  VARCHAR2(30);
7354     l_param7        VARCHAR2(30);
7355     l_param7_value  VARCHAR2(30);
7356     l_param8        VARCHAR2(30);
7357     l_param8_value  VARCHAR2(30);
7358     l_param9        VARCHAR2(30);
7359     l_param9_value  VARCHAR2(30);
7360     l_param10       VARCHAR2(30);
7361     l_param10_value VARCHAR2(30);
7362     l_param11       VARCHAR2(30);
7363     l_param11_value VARCHAR2(30);
7364     l_param12       VARCHAR2(30);
7365     l_param12_value VARCHAR2(30);
7366     l_param13       VARCHAR2(30);
7367     l_param13_value VARCHAR2(30);
7368     l_param14       VARCHAR2(30);
7369     l_param14_value VARCHAR2(30);
7370     l_param15       VARCHAR2(30);
7371     l_param15_value VARCHAR2(30);
7372     l_param16       VARCHAR2(30);
7373     l_param16_value VARCHAR2(30);
7374     l_param17       VARCHAR2(30);
7375     l_param17_value VARCHAR2(30);
7376     l_param18       VARCHAR2(30);
7377     l_param18_value VARCHAR2(30);
7378     l_param19       VARCHAR2(30);
7379     l_param19_value VARCHAR2(30);
7380     l_param20       VARCHAR2(30);
7381     l_param20_value VARCHAR2(30);
7382     l_num_elig_dpnt NUMBER;
7383     l_prev_prtt_enrt_rslt_id  VARCHAR2(30);
7384   --
7385   BEGIN
7386     --
7387     g_debug := hr_utility.debug_enabled;
7388     if g_debug then
7389     hr_utility.set_location('Entering ' || l_package, 10);
7390     end if;
7391     --
7392     IF p_rule_id IS NULL THEN
7393       --
7394       p_enrt_mthd := 'Y';
7395       p_reinstt_dpnt := 'CFWP';
7396     --
7397     END IF;
7398     --
7399     if g_debug then
7400     hr_utility.set_location(
7401       'Organization_id ' || TO_CHAR(p_organization_id),
7402       10);
7403     hr_utility.set_location('assignment_id ' || TO_CHAR(p_assignment_id), 15);
7404     hr_utility.set_location(
7405       'Business_group_id ' || TO_CHAR(p_business_group_id),
7406       20);
7407     hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
7408     hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
7409     hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
7410     hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
7411     hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
7412     end if;
7413     --
7414     -- Task 131 :If elig dependent rows are already crteated then
7415     -- pass the elig dependent id as input values to
7416     -- rule.
7417     --
7418     l_num_elig_dpnt :=
7419                       NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0);
7420     --
7421     IF NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0) > 0 THEN
7422       FOR l_curr_count IN
7423         ben_determine_dpnt_eligibility.g_egd_table.FIRST .. ben_determine_dpnt_eligibility.g_egd_table.LAST LOOP
7424         --
7425         -- Currently we are passing only 20 input values.
7426         -- Only 20 elig_dpnt_id are passed as input values.
7427         --
7428         EXIT WHEN l_curr_count > 20;
7429         --
7430         -- Update the egd row with electable choice id.
7431         --
7432         IF l_curr_count = 1 THEN
7433           l_param1 :=        'ELIG_DPNT_ID1';
7434           l_param1_value :=
7435            TO_CHAR(
7436              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7437         ELSIF l_curr_count = 2 THEN
7438           l_param2 :=        'ELIG_DPNT_ID2';
7439           l_param2_value :=
7440            TO_CHAR(
7441              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7442         ELSIF l_curr_count = 3 THEN
7443           l_param3 :=        'ELIG_DPNT_ID3';
7444           l_param3_value :=
7445            TO_CHAR(
7446              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7447         ELSIF l_curr_count = 4 THEN
7448           l_param4 :=        'ELIG_DPNT_ID4';
7449           l_param4_value :=
7450            TO_CHAR(
7451              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7452         ELSIF l_curr_count = 5 THEN
7453            l_param5 :=        'ELIG_DPNT_ID5';
7454           l_param5_value :=
7455            TO_CHAR(
7456              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7457         ELSIF l_curr_count = 6 THEN
7458           l_param6 :=        'ELIG_DPNT_ID6';
7459           l_param6_value :=
7460            TO_CHAR(
7461              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7462         ELSIF l_curr_count = 7 THEN
7463           l_param7 :=        'ELIG_DPNT_ID7';
7464           l_param7_value :=
7465            TO_CHAR(
7466              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7467         ELSIF l_curr_count = 8 THEN
7468           l_param8 :=        'ELIG_DPNT_ID8';
7469           l_param8_value :=
7470            TO_CHAR(
7471              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7472         ELSIF l_curr_count = 9 THEN
7473           l_param9 :=        'ELIG_DPNT_ID9';
7474           l_param9_value :=
7475            TO_CHAR(
7476              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7477         ELSIF l_curr_count = 10 THEN
7478           l_param10 :=        'ELIG_DPNT_ID10';
7479           l_param10_value :=
7480             TO_CHAR(
7481              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7482         ELSIF l_curr_count = 11 THEN
7483           l_param11 :=        'ELIG_DPNT_ID11';
7484           l_param11_value :=
7485            TO_CHAR(
7486              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7487         ELSIF l_curr_count = 12 THEN
7488           l_param12 :=        'ELIG_DPNT_ID12';
7489           l_param12_value :=
7490            TO_CHAR(
7491              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7492         ELSIF l_curr_count = 13 THEN
7493           l_param13 :=        'ELIG_DPNT_ID13';
7494           l_param13_value :=
7495            TO_CHAR(
7496              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7497         ELSIF l_curr_count = 14 THEN
7498           l_param14 :=        'ELIG_DPNT_ID14';
7499           l_param14_value :=
7500            TO_CHAR(
7501              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7502         ELSIF l_curr_count = 15 THEN
7503           l_param15 :=        'ELIG_DPNT_ID15';
7504           l_param15_value :=
7505            TO_CHAR(
7506              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7507         ELSIF l_curr_count = 16 THEN
7508            l_param16 :=        'ELIG_DPNT_ID16';
7509           l_param16_value :=
7510            TO_CHAR(
7511              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7512         ELSIF l_curr_count = 17 THEN
7513           l_param17 :=        'ELIG_DPNT_ID17';
7514           l_param17_value :=
7515            TO_CHAR(
7516              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7517         ELSIF l_curr_count = 18 THEN
7518           l_param18 :=        'ELIG_DPNT_ID18';
7519           l_param18_value :=
7520            TO_CHAR(
7521              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7522         ELSIF l_curr_count = 19 THEN
7523           l_param19 :=        'ELIG_DPNT_ID19';
7524           l_param19_value :=
7525            TO_CHAR(
7526              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7527         ELSIF l_curr_count = 20 THEN
7528           l_param20 :=        'ELIG_DPNT_ID20';
7529           l_param20_value :=
7530            TO_CHAR(
7531              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7532         END IF;
7533       --
7534       END LOOP;
7535     --
7536     END IF;
7537     --
7538     if g_debug then
7539     hr_utility.set_location(' Fire Rule ' || l_package, 10);
7540     end if;
7541     l_outputs :=
7542      benutils.formula(
7543        p_opt_id            => p_opt_id,
7544        p_pl_id             => p_pl_id,
7545        p_pgm_id            => p_pgm_id,
7546        p_formula_id        => p_rule_id,
7547        p_ler_id            => p_ler_id,
7548        p_elig_per_id       => p_elig_per_id,
7549        p_pl_typ_id         => p_pl_typ_id,
7550        p_assignment_id     => p_assignment_id,
7551        p_business_group_id => p_business_group_id,
7552        p_organization_id   => p_organization_id,
7553        p_jurisdiction_code => p_jurisdiction_code,
7554        p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
7555        p_param1            => l_param1,
7556        p_param1_value      => l_param1_value,
7557        p_param2            => l_param2,
7558        p_param2_value      => l_param2_value,
7559        p_param3            => l_param3,
7560        p_param3_value      => l_param3_value,
7561        p_param4            => l_param4,
7562        p_param4_value      => l_param4_value,
7563        p_param5            => l_param5,
7564        p_param5_value      => l_param5_value,
7565        p_param6            => l_param6,
7566        p_param6_value      => l_param6_value,
7567        p_param7            => l_param7,
7568        p_param7_value      => l_param7_value,
7569        p_param8            => l_param8,
7570        p_param8_value      => l_param8_value,
7571        p_param9            => l_param9,
7572        p_param9_value      => l_param9_value,
7573        p_param10           => l_param10,
7574        p_param10_value     => l_param10_value,
7575        p_param11           => l_param11,
7576        p_param11_value     => l_param11_value,
7577        p_param12           => l_param12,
7578        p_param12_value     => l_param12_value,
7579        p_param13           => l_param13,
7580        p_param13_value     => l_param13_value,
7581        p_param14           => l_param14,
7582        p_param14_value     => l_param14_value,
7583        p_param15           => l_param15,
7584        p_param15_value     => l_param15_value,
7585        p_param16           => l_param16,
7586        p_param16_value     => l_param16_value,
7587        p_param17           => l_param17,
7588        p_param17_value     => l_param17_value,
7589        p_param18           => l_param18,
7590        p_param18_value     => l_param18_value,
7591        p_param19           => l_param19,
7592        p_param19_value     => l_param19_value,
7593        p_param20           => l_param20,
7594        p_param20_value     => l_param20_value,
7595        p_param21           => 'NUM_ELIG_DPNT',
7596        p_param21_value     => TO_CHAR(l_num_elig_dpnt),
7597        p_param22           => 'BEN_IV_PERSON_ID',            -- Bug 5331889 : Added person_id param as well
7598        p_param22_value     => to_char(p_person_id));
7599   if g_debug then
7600     hr_utility.set_location(' Dn Fire Rule ' || l_package, 10);
7601   end if;
7602     --
7603   for l_count in l_outputs.first..l_outputs.last loop
7604    begin
7605         --
7606         if l_outputs(l_count).name = 'AUTO_DFLT_VAL' then
7607            p_enrt_mthd := l_outputs(l_count).VALUE;
7608         elsif l_outputs(l_count).name = 'CARRY_FORWARD_ELIG_DPNT' then
7609            p_reinstt_dpnt := l_outputs(l_count).VALUE;
7610         elsif l_outputs(l_count).name = 'AUTO_DFLT_ELCN_VAL' then
7611            g_dflt_elcn_val := l_outputs(l_count).VALUE;
7612 	   if g_debug then
7613            hr_utility.set_location ('formula default='||g_dflt_elcn_val,744);
7614            hr_utility.set_location ('formula default='||p_opt_id,744);
7615            end if;
7616         elsif l_outputs(l_count).name =  'PREV_PRTT_ENRT_RSLT_ID' then
7617            l_prev_prtt_enrt_rslt_id   := l_outputs(l_count).VALUE ;
7618 	   if g_debug then
7619            hr_utility.set_location ('formula PREV_PRTT_ENRT_RSLT_ID ='||l_prev_prtt_enrt_rslt_id,744);
7620 	   end if;
7621 
7622         end if;
7623     end;
7624    end loop;
7625    --- if the formula return the result id , concate the result with p_reinstt_dpnt  # 2685018
7626    if l_prev_prtt_enrt_rslt_id is not null then
7627       p_reinstt_dpnt := nvl(p_reinstt_dpnt,'') ||'^'||l_prev_prtt_enrt_rslt_id ;
7628    end if ;
7629 
7630   --
7631   if g_debug then
7632     hr_utility.set_location(' Leaving ' || l_package, 10);
7633   end if;
7634 
7635   exception  -- nocopy changes
7636     --
7637     when others then
7638       --
7639       p_enrt_mthd := null;
7640       p_reinstt_dpnt := null;
7641       raise;
7642       --
7643   END execute_auto_dflt_enrt_rule;
7644 
7645   FUNCTION execute_enrt_rule(
7646     p_opt_id            NUMBER,
7647     p_pl_id             NUMBER,
7648     p_pgm_id            NUMBER,
7649     p_rule_id           NUMBER,
7650     p_ler_id            NUMBER,
7651     p_pl_typ_id         NUMBER,
7652     p_business_group_id NUMBER,
7653     p_effective_date    DATE,
7654     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
7655     p_elig_per_id       NUMBER DEFAULT NULL,
7656     p_assignment_id     NUMBER,
7657     p_organization_id   NUMBER,
7658     p_jurisdiction_code VARCHAR2,
7659     p_person_id         NUMBER)         -- Bug 5331889
7660     RETURN VARCHAR2 IS
7661     --
7662     l_package       VARCHAR2(80)      := g_package || '.execute_enrt_rule';
7663     l_outputs       ff_exec.outputs_t;
7664     --
7665     l_param1        VARCHAR2(30);
7666     l_param1_value  VARCHAR2(30);
7667     l_param2        VARCHAR2(30);
7668     l_param2_value  VARCHAR2(30);
7669     l_param3        VARCHAR2(30);
7670     l_param3_value  VARCHAR2(30);
7671     l_param4        VARCHAR2(30);
7672     l_param4_value  VARCHAR2(30);
7673     l_param5        VARCHAR2(30);
7674     l_param5_value  VARCHAR2(30);
7675     l_param6        VARCHAR2(30);
7676     l_param6_value  VARCHAR2(30);
7677     l_param7        VARCHAR2(30);
7678     l_param7_value  VARCHAR2(30);
7679     l_param8        VARCHAR2(30);
7680     l_param8_value  VARCHAR2(30);
7681     l_param9        VARCHAR2(30);
7682     l_param9_value  VARCHAR2(30);
7683     l_param10       VARCHAR2(30);
7684     l_param10_value VARCHAR2(30);
7685     l_param11       VARCHAR2(30);
7686     l_param11_value VARCHAR2(30);
7687     l_param12       VARCHAR2(30);
7688     l_param12_value VARCHAR2(30);
7689     l_param13       VARCHAR2(30);
7690     l_param13_value VARCHAR2(30);
7691     l_param14       VARCHAR2(30);
7692     l_param14_value VARCHAR2(30);
7693     l_param15       VARCHAR2(30);
7694     l_param15_value VARCHAR2(30);
7695     l_param16       VARCHAR2(30);
7696     l_param16_value VARCHAR2(30);
7697     l_param17       VARCHAR2(30);
7698     l_param17_value VARCHAR2(30);
7699     l_param18       VARCHAR2(30);
7700     l_param18_value VARCHAR2(30);
7701     l_param19       VARCHAR2(30);
7702     l_param19_value VARCHAR2(30);
7703     l_param20       VARCHAR2(30);
7704     l_param20_value VARCHAR2(30);
7705     l_num_elig_dpnt NUMBER;
7706   --
7707   BEGIN
7708     --
7709    if g_debug then
7710     hr_utility.set_location('Entering ' || l_package, 10);
7711    end if;
7712     --
7713     IF p_rule_id IS NULL THEN
7714       --
7715       RETURN 'Y';
7716     --
7717     END IF;
7718     --
7719     if g_debug then
7720     hr_utility.set_location(
7721       'Organization_id ' || TO_CHAR(p_organization_id),
7722       10);
7723     hr_utility.set_location('assignment_id ' || TO_CHAR(p_assignment_id), 15);
7724     hr_utility.set_location(
7725       'Business_group_id ' || TO_CHAR(p_business_group_id),
7726       20);
7727     hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
7728     hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
7729     hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
7730     hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
7731     hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
7732     end if;
7733     --
7734     -- Task 131 :If elig dependent rows are already crteated then
7735     -- pass the elig dependent id as input values to
7736     -- rule.
7737     --
7738     l_num_elig_dpnt :=
7739                       NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0);
7740     --
7741     IF NVL(ben_determine_dpnt_eligibility.g_egd_table.LAST, 0) > 0 THEN
7742       FOR l_curr_count IN
7743          ben_determine_dpnt_eligibility.g_egd_table.FIRST .. ben_determine_dpnt_eligibility.g_egd_table.LAST LOOP
7744         --
7745         -- Currently we are passing only 20 input values.
7746         -- Only 20 elig_dpnt_id are passed as input values.
7747         --
7748         EXIT WHEN l_curr_count > 20;
7749         --
7750         -- Update the egd row with electable choice id.
7751         --
7752         IF l_curr_count = 1 THEN
7753           l_param1 :=        'ELIG_DPNT_ID1';
7754           l_param1_value :=
7755            TO_CHAR(
7756              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7757         ELSIF l_curr_count = 2 THEN
7758           l_param2 :=        'ELIG_DPNT_ID2';
7759           l_param2_value :=
7760            TO_CHAR(
7761              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7762         ELSIF l_curr_count = 3 THEN
7763           l_param3 :=        'ELIG_DPNT_ID3';
7764           l_param3_value :=
7765            TO_CHAR(
7766              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7767         ELSIF l_curr_count = 4 THEN
7768           l_param4 :=        'ELIG_DPNT_ID4';
7769           l_param4_value :=
7770            TO_CHAR(
7771              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7772         ELSIF l_curr_count = 5 THEN
7773           l_param5 :=        'ELIG_DPNT_ID5';
7774           l_param5_value :=
7775            TO_CHAR(
7776              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7777         ELSIF l_curr_count = 6 THEN
7778           l_param6 :=        'ELIG_DPNT_ID6';
7779           l_param6_value :=
7780            TO_CHAR(
7781              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7782         ELSIF l_curr_count = 7 THEN
7783           l_param7 :=        'ELIG_DPNT_ID7';
7784           l_param7_value :=
7785            TO_CHAR(
7786              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7787         ELSIF l_curr_count = 8 THEN
7788           l_param8 :=        'ELIG_DPNT_ID8';
7789           l_param8_value :=
7790            TO_CHAR(
7791              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7792         ELSIF l_curr_count = 9 THEN
7793           l_param9 :=        'ELIG_DPNT_ID9';
7794           l_param9_value :=
7795            TO_CHAR(
7796              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7797         ELSIF l_curr_count = 10 THEN
7798           l_param10 :=        'ELIG_DPNT_ID10';
7799           l_param10_value :=
7800            TO_CHAR(
7801              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7802         ELSIF l_curr_count = 11 THEN
7803           l_param11 :=        'ELIG_DPNT_ID11';
7804           l_param11_value :=
7805            TO_CHAR(
7806              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7807         ELSIF l_curr_count = 12 THEN
7808           l_param12 :=        'ELIG_DPNT_ID12';
7809           l_param12_value :=
7810            TO_CHAR(
7811              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7812         ELSIF l_curr_count = 13 THEN
7813           l_param13 :=        'ELIG_DPNT_ID13';
7814           l_param13_value :=
7815            TO_CHAR(
7816              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7817         ELSIF l_curr_count = 14 THEN
7818           l_param14 :=        'ELIG_DPNT_ID14';
7819           l_param14_value :=
7820            TO_CHAR(
7821              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7822         ELSIF l_curr_count = 15 THEN
7823           l_param15 :=        'ELIG_DPNT_ID15';
7824           l_param15_value :=
7825            TO_CHAR(
7826              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7827         ELSIF l_curr_count = 16 THEN
7828           l_param16 :=        'ELIG_DPNT_ID16';
7829           l_param16_value :=
7830            TO_CHAR(
7831              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7832         ELSIF l_curr_count = 17 THEN
7833           l_param17 :=        'ELIG_DPNT_ID17';
7834           l_param17_value :=
7835            TO_CHAR(
7836              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7837         ELSIF l_curr_count = 18 THEN
7838           l_param18 :=        'ELIG_DPNT_ID18';
7839           l_param18_value :=
7840            TO_CHAR(
7841              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7842         ELSIF l_curr_count = 19 THEN
7843           l_param19 :=        'ELIG_DPNT_ID19';
7844           l_param19_value :=
7845            TO_CHAR(
7846              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7847         ELSIF l_curr_count = 20 THEN
7848           l_param20 :=        'ELIG_DPNT_ID20';
7849           l_param20_value :=
7850            TO_CHAR(
7851              ben_determine_dpnt_eligibility.g_egd_table(l_curr_count).elig_dpnt_id);
7852         END IF;
7853       --
7854       END LOOP;
7855     --
7856     END IF;
7857     --
7858     l_outputs :=
7859      benutils.formula(
7860        p_opt_id            => p_opt_id,
7861        p_pl_id             => p_pl_id,
7862        p_pgm_id            => p_pgm_id,
7863        p_formula_id        => p_rule_id,
7864        p_ler_id            => p_ler_id,
7865        p_elig_per_id       => p_elig_per_id,
7866        p_pl_typ_id         => p_pl_typ_id,
7867        p_assignment_id     => p_assignment_id,
7868        p_business_group_id => p_business_group_id,
7869        p_organization_id   => p_organization_id,
7870        p_jurisdiction_code => p_jurisdiction_code,
7871        p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
7872        p_param1            => l_param1,
7873        p_param1_value      => l_param1_value,
7874        p_param2            => l_param2,
7875        p_param2_value      => l_param2_value,
7876        p_param3            => l_param3,
7877        p_param3_value      => l_param3_value,
7878        p_param4            => l_param4,
7879        p_param4_value      => l_param4_value,
7880        p_param5            => l_param5,
7881        p_param5_value      => l_param5_value,
7882        p_param6            => l_param6,
7883        p_param6_value      => l_param6_value,
7884        p_param7            => l_param7,
7885        p_param7_value      => l_param7_value,
7886        p_param8            => l_param8,
7887        p_param8_value      => l_param8_value,
7888        p_param9            => l_param9,
7889        p_param9_value      => l_param9_value,
7890        p_param10           => l_param10,
7891        p_param10_value     => l_param10_value,
7892        p_param11           => l_param11,
7893        p_param11_value     => l_param11_value,
7894        p_param12           => l_param12,
7895        p_param12_value     => l_param12_value,
7896        p_param13           => l_param13,
7897        p_param13_value     => l_param13_value,
7898        p_param14           => l_param14,
7899        p_param14_value     => l_param14_value,
7900        p_param15           => l_param15,
7901        p_param15_value     => l_param15_value,
7902        p_param16           => l_param16,
7903        p_param16_value     => l_param16_value,
7904        p_param17           => l_param17,
7905        p_param17_value     => l_param17_value,
7906        p_param18           => l_param18,
7907        p_param18_value     => l_param18_value,
7908        p_param19           => l_param19,
7909        p_param19_value     => l_param19_value,
7910        p_param20           => l_param20,
7911        p_param20_value     => l_param20_value,
7912        p_param21           => 'NUM_ELIG_DPNT',
7913        p_param21_value     => TO_CHAR(l_num_elig_dpnt),
7914        p_param22           => 'BEN_IV_PERSON_ID',            -- Bug 5331889 : Added person_id param as well
7915        p_param22_value     => to_char(p_person_id));
7916     --
7917     RETURN l_outputs(l_outputs.FIRST).VALUE;
7918   --
7919   END execute_enrt_rule;
7920 --
7921   PROCEDURE determine_dflt_flag(
7922     p_dflt_flag             VARCHAR2,
7923     p_dflt_enrt_cd          VARCHAR2,
7924     p_crnt_enrt_cvg_strt_dt DATE,
7925     -- above is no longer used
7926     p_previous_eligibility  VARCHAR2,
7927     p_dflt_enrt_rl          NUMBER,
7928     p_oipl_id               NUMBER,
7929     p_pl_id                 NUMBER,
7930     p_pgm_id                NUMBER,
7931     p_effective_date        DATE,
7932     p_lf_evt_ocrd_dt        DATE DEFAULT NULL,
7933     p_ler_id                NUMBER,
7934     p_opt_id                NUMBER,
7935     p_pl_typ_id             NUMBER,
7936     p_ptip_id               NUMBER,
7937     p_person_id             NUMBER,
7938     p_business_group_id     NUMBER,
7939     p_assignment_id         NUMBER,
7940     p_deflt_flag            out nocopy VARCHAR2,
7941     p_reinstt_flag          out nocopy VARCHAR2,
7942     -- added bug 5644451
7943     p_default_level         VARCHAR2 default null,
7944     p_run_mode              varchar2 default null)   /* iRec : Added p_run_mode */
7945     IS
7946     --
7947     l_defer_flag           VARCHAR2(30)    := 'N';
7948     l_dflt_flag            VARCHAR2(30);
7949     l_reinstt_flag         VARCHAR2(30);
7950     l_next_level_enrt_flag VARCHAR2(30)    := 'N';
7951     l_jurisdiction_code    VARCHAR2(30);
7952     --
7953     l_lf_evt_ocrd_dt       DATE     := NVL(p_lf_evt_ocrd_dt, p_effective_date);
7954     l_lf_evt_ocrd_dt_1     DATE            := l_lf_evt_ocrd_dt - 1;
7955     l_covered_flag         varchar2(30):='N';
7956     --
7957     -- Gets the enrolment information for the plan in which the oipl belongs
7958     --
7959     --
7960     CURSOR c_plan_enrolment_info IS
7961       SELECT   'Y'
7962       FROM     ben_prtt_enrt_rslt_f pen
7963       WHERE    pen.person_id = p_person_id
7964       AND      pen.business_group_id = p_business_group_id
7965       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
7966 --      AND      pen.sspndd_flag = 'N' --CFW
7967       AND      (pen.sspndd_flag = 'N' --CFW
7968                  OR (pen.sspndd_flag = 'Y' and
7969                      pen.enrt_cvg_thru_dt = hr_api.g_eot
7970                     )
7971                )
7972       AND      pen.effective_end_date = hr_api.g_eot
7973       AND      l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
7974       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
7975       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
7976       AND      p_pl_id = pen.pl_id
7977       AND      (
7978                     (    pen.pgm_id = p_pgm_id
7979                      AND p_pgm_id IS NOT NULL)
7980                  OR (    pen.pgm_id IS NULL
7981                      AND p_pgm_id IS NULL));
7982     --
7983     -- Gets the enrolment information for this oipl
7984     --
7985     --
7986     CURSOR c_oipl_enrolment_info IS
7987       SELECT   'Y'
7988       FROM     ben_prtt_enrt_rslt_f pen
7989       WHERE    pen.person_id = p_person_id
7990       AND      pen.business_group_id = p_business_group_id
7991 --      AND      pen.sspndd_flag = 'N' --CFW
7992       AND      (pen.sspndd_flag = 'N' --CFW
7993                  OR (pen.sspndd_flag = 'Y' and
7994                      pen.enrt_cvg_thru_dt = hr_api.g_eot
7995                     )
7996                )
7997       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
7998       AND      pen.effective_end_date = hr_api.g_eot
7999       AND      l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
8000       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
8001       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
8002       AND      p_oipl_id = pen.oipl_id
8003       AND      (
8004                     (    pen.pgm_id = p_pgm_id
8005                      AND p_pgm_id IS NOT NULL)
8006                  OR (    pen.pgm_id IS NULL
8007                      AND p_pgm_id IS NULL));
8008     --
8009     -- Gets the enrolment information for the ptip in which the plan belongs
8010     --
8011     CURSOR c_ptip_enrolment_info IS
8012       SELECT   'Y'
8013       FROM     ben_prtt_enrt_rslt_f pen
8014       WHERE    pen.person_id = p_person_id
8015       AND      pen.business_group_id = p_business_group_id
8016       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
8017       -- AND      pen.sspndd_flag = 'N'
8018       AND      (pen.sspndd_flag = 'N' --CFW
8019                  OR (pen.sspndd_flag = 'Y' and
8020                      pen.enrt_cvg_thru_dt = hr_api.g_eot
8021                     )
8022                )
8023       AND      pen.effective_end_date = hr_api.g_eot
8024       AND
8025                --   nvl(p_lf_evt_ocrd_dt,p_effective_date) between
8026                --      pen.effective_start_date and pen.effective_end_date and
8027                l_lf_evt_ocrd_dt <= pen.enrt_cvg_thru_dt
8028       AND      l_lf_evt_ocrd_dt >= pen.enrt_cvg_strt_dt
8029       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
8030       AND      p_ptip_id = pen.ptip_id;
8031 
8032     --
8033     CURSOR c_state IS
8034       SELECT   loc.region_2
8035       FROM     hr_locations_all loc, per_all_assignments_f asg
8036       WHERE    loc.location_id = asg.location_id
8037       AND      asg.person_id = p_person_id
8038       and      asg.assignment_type <> 'C'
8039       AND      asg.primary_flag = 'Y'
8040       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
8041                    AND asg.effective_end_date
8042       AND      asg.business_group_id = p_business_group_id;
8043 
8044     l_state                c_state%ROWTYPE;
8045     CURSOR c_asg IS
8046       SELECT   asg.assignment_id,
8047                asg.organization_id
8048       FROM     per_all_assignments_f asg
8049       WHERE    asg.person_id = p_person_id
8050       and      asg.assignment_type <> 'C'
8051       AND      asg.primary_flag = decode(p_run_mode, 'I',asg.primary_flag, 'Y')  -- iRec
8052       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
8053                    AND asg.effective_end_date;
8054     l_asg                  c_asg%ROWTYPE;
8055     l_proc                 VARCHAR2(80)   := g_package ||
8056                                                '.determine_dflt_flag';
8057   --
8058   BEGIN
8059   g_debug := hr_utility.debug_enabled;
8060   if g_debug then
8061     hr_utility.set_location('Entering: ' || l_proc, 10);
8062     hr_utility.set_location('p_dflt_flag' || p_dflt_flag, 121.121);
8063     hr_utility.set_location('p_dflt_enrt_cd' || p_dflt_enrt_cd, 121.121);
8064     hr_utility.set_location('p_oipl_id' || p_oipl_id, 121.121);
8065     hr_utility.set_location('p_pl_id' || p_pl_id, 121.121);
8066     hr_utility.set_location('p_ptip_id' || p_ptip_id, 121.121);
8067     hr_utility.set_location('p_default_level' || p_default_level, 121.121);
8068   end if;
8069 
8070 -- If the dflt_enrt_cd and enrollment status combination in the following
8071 -- matrix is YES set the dflt_flag to Y, if it is NO set it to N,
8072 -- if it is Flag use the dflt_flag.
8073 --
8074 --
8075 -- For Plan
8076 --                                              enrd in ptip and
8077 -- DFLT_ENRT_CD    not enrd ptip   enrd pl      not enrd pl
8078 ---------------------------------------------------------------
8079 -- NSDCSD          Flag            Flag         Flag
8080 -- NSDCS           Flag            YES          NO(X)
8081 -- NDCSEDR         Flag            YES          NO(X)
8082 -- NNCS            NO              YES          NO
8083 -- NNCSEDR         NO              YES          NO
8084 -- NNCN            NO              NO           NO
8085 -- NNCD            NO              Flag         Flag(X)
8086 -- NDCN            Flag            NO           NO(X)
8087 --
8088 -- For Oipl
8089 --                                              enrd in pl and
8090 -- DFLT_ENRT_CD    not enrd pl     enrd oipl    not enrd oipl
8091 ---------------------------------------------------------------
8092 -- NSDCSD          Flag            Flag         Flag
8093 -- NSDCS           Flag            YES          NO(X)
8094 -- NDCSEDR         Flag            YES          NO(X)
8095 -- NNCS            NO              YES          NO
8096 -- NNCSEDR         NO              YES          NO
8097 -- NNCN            NO              NO           NO
8098 -- NNCD            NO              Flag         Flag(X)
8099 -- NDCN            Flag            NO           NO(X)
8100 --
8101 /*  -- 4031733 - Cursor c_state populates l_state variable which is no longer
8102     -- used in the package. Cursor can be commented
8103 
8104     IF p_person_id IS NOT NULL THEN
8105       OPEN c_state;
8106       FETCH c_state INTO l_state;
8107       CLOSE c_state;
8108       --IF l_state.region_2 IS NOT NULL THEN
8109       --  l_jurisdiction_code :=
8110       --    pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
8111       --END IF;
8112     END IF;
8113 */
8114     OPEN c_asg;
8115     FETCH c_asg INTO l_asg;
8116     IF c_asg%NOTFOUND THEN
8117       CLOSE c_asg;
8118       fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
8119       fnd_message.set_token('PROC', l_proc);
8120       fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
8121       fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
8122       fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
8123       RAISE ben_manage_life_events.g_record_error;
8124     END IF;
8125     CLOSE c_asg;
8126     IF (p_oipl_id IS NULL) THEN
8127       --
8128       OPEN c_plan_enrolment_info;
8129       --
8130       FETCH c_plan_enrolment_info INTO l_covered_flag;
8131       --
8132       CLOSE c_plan_enrolment_info;
8133     --
8134     ELSE
8135       --
8136       OPEN c_oipl_enrolment_info;
8137       --
8138       FETCH c_oipl_enrolment_info INTO l_covered_flag;
8139       --
8140       CLOSE c_oipl_enrolment_info;
8141     --
8142     END IF;
8143     IF l_covered_flag='Y' THEN
8144       --
8145       -- enrolled in oipl/pl
8146       --
8147       IF p_dflt_enrt_cd IN ('NSDCS', 'NDCSEDR', 'NNCS', 'NNCSEDR') THEN
8148         l_dflt_flag :=  'Y';
8149       ELSIF p_dflt_enrt_cd IN ('NNCN', 'NDCN') THEN
8150         l_dflt_flag :=  'N';
8151       ELSE
8152         l_defer_flag :=  'Y';
8153       END IF;
8154     ELSE
8155       --
8156       -- not enrolled in oipl/pl must check for plan/ptip enrt
8157       -- Note: to speed processing if enrt does not matter set
8158       --   l_next_level_enrt_flag='Y'
8159       -- Note: for plans not in program don't have next level so
8160       --   not enrolled means not enrolled, set next level='N'
8161       --
8162       if g_debug then
8163       hr_utility.set_location(l_proc, 50);
8164       end if;
8165 /*
8166       IF p_dflt_enrt_cd IN ('RL', 'NSDCSD', 'NNCS', 'NNCSEDR', 'NNCN') THEN
8167         l_next_level_enrt_flag :=  'Y';
8168       ELSIF p_oipl_id IS NOT NULL THEN
8169         OPEN c_plan_enrolment_info;
8170         FETCH c_plan_enrolment_info INTO l_next_level_enrt_flag;
8171         CLOSE c_plan_enrolment_info;
8172       ELSIF p_ptip_id IS NOT NULL THEN
8173         OPEN c_ptip_enrolment_info;
8174         FETCH c_ptip_enrolment_info INTO l_next_level_enrt_flag;
8175         CLOSE c_ptip_enrolment_info;
8176       ELSE
8177         l_next_level_enrt_flag :=  'N';
8178       END IF;
8179       --
8180 */
8181 --bug#2080856 - need to check at ptip level if not enrolled in plan- the above code was
8182 --skipping to check ptip level if oipl_id is not null
8183      IF p_dflt_enrt_cd IN ('RL', 'NSDCSD', 'NNCS', 'NNCSEDR', 'NNCN') THEN
8184         l_next_level_enrt_flag :=  'Y';
8185      ELSE
8186         if p_oipl_id IS NOT NULL THEN
8187 	if g_debug then
8188 	  hr_utility.set_location('p_oipl_id IS NOT NULL THEN',121.121);
8189         end if;
8190           OPEN c_plan_enrolment_info;
8191           FETCH c_plan_enrolment_info INTO l_next_level_enrt_flag;
8192           CLOSE c_plan_enrolment_info;
8193 	  if g_debug then
8194 	  hr_utility.set_location('l_next_level_enrt_flag '||nvl(l_next_level_enrt_flag,'-')|| '  ' ,121.121);
8195 	  end if;
8196         end if;
8197         if l_next_level_enrt_flag <>'Y' then
8198 	if g_debug then
8199 	   hr_utility.set_location('l_next_level_enrt_flag <>Y ',121.121);
8200         end if;
8201            if  p_ptip_id IS NOT NULL THEN
8202 	   if g_debug then
8203 	     hr_utility.set_location('p_ptip_id IS NOT NULL  ',121.121);
8204 	     hr_utility.set_location('Checking p_default level  ' || p_default_level,121.121);
8205 	     end if;
8206 	     IF p_default_level IN('PTIP','LER_PTIP')
8207 	     THEN
8208                OPEN c_ptip_enrolment_info;
8209                   FETCH c_ptip_enrolment_info INTO l_next_level_enrt_flag;
8210                CLOSE c_ptip_enrolment_info;
8211 	     END IF;
8212            ELSE
8213              l_next_level_enrt_flag :=  'N';
8214            end if;
8215          end if;
8216       END if;
8217 
8218 
8219       --
8220       IF l_next_level_enrt_flag = 'Y' THEN
8221         --
8222         -- Enrolled in plan/ptip and not oipl/plan
8223         --
8224 	if g_debug then
8225 	hr_utility.set_location('l_next_level_enrt_flag = Y 2 ',121.121);
8226 	end if;
8227         IF p_dflt_enrt_cd IN (
8228                                'NSDCS',
8229                                'NDCSEDR',
8230                                'NNCS',
8231                                'NNCSEDR',
8232                                'NNCN',
8233                                'NDCN') THEN
8234           l_dflt_flag :=  'N';
8235         ELSE
8236           l_defer_flag :=  'Y';
8237         END IF;
8238       ELSE
8239         --
8240         -- Not enrolled in plan/ptip
8241         --
8242         IF p_dflt_enrt_cd IN ('NNCS', 'NNCSEDR', 'NNCN', 'NNCD') THEN
8243           l_dflt_flag :=  'N';
8244         ELSE
8245           l_defer_flag :=  'Y';
8246         END IF;
8247       END IF;
8248     END IF;
8249     --
8250     -- If the dflt_enrt_cd is RL then execute the rule,
8251     -- it will determine the value for the dflt_flag.
8252     --
8253     IF p_dflt_enrt_cd = 'RL' THEN
8254       --
8255       if g_debug then
8256       hr_utility.set_location(' EER ' || l_proc, 190);
8257       end if;
8258        execute_auto_dflt_enrt_rule(
8259          p_opt_id            => p_opt_id,
8260          p_pl_id             => p_pl_id,
8261          p_pgm_id            => p_pgm_id,
8262          p_rule_id           => p_dflt_enrt_rl,
8263          p_ler_id            => p_ler_id,
8264          p_pl_typ_id         => p_pl_typ_id,
8265          p_business_group_id => p_business_group_id,
8266          p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8267          p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt,
8268          p_assignment_id     => p_assignment_id,
8269          p_organization_id   => l_asg.organization_id,
8270          p_jurisdiction_code => l_jurisdiction_code,
8271 	 p_person_id         => p_person_id,          -- Bug 5331889
8272          p_enrt_mthd         => l_dflt_flag,
8273          p_reinstt_dpnt      => l_reinstt_flag
8274          );
8275      if g_debug then
8276       hr_utility.set_location(' Dn EER ' || l_proc, 190);
8277      end if;
8278       --
8279       l_defer_flag :=  'N';
8280     ELSIF (    p_dflt_enrt_cd IS NULL
8281            AND p_dflt_flag IS NOT NULL) THEN
8282       --
8283       -- If the dflt_enrt_cd is null and the dflt_flag is not
8284       -- null set the dflt_flag to it's value.
8285       --
8286       l_dflt_flag :=  'N'; -- p_dflt_flag - Bug#2080856
8287       l_defer_flag :=  'N';
8288     --
8289     END IF;
8290    if g_debug then
8291     hr_utility.set_location(l_proc, 200);
8292    end if;
8293     --
8294     IF l_defer_flag = 'Y' THEN
8295       --
8296        l_dflt_flag := 'DEFER';
8297     --
8298     END IF;
8299     if g_debug then
8300     hr_utility.set_location('Leaving: ' || l_proc, 235);
8301     end if;
8302     --
8303     p_deflt_flag := l_dflt_flag;
8304     p_reinstt_flag := l_reinstt_flag;
8305   --
8306   exception  -- nocopy changes
8307     --
8308     when others then
8309       --
8310       p_deflt_flag := null;
8311       p_reinstt_flag := null;
8312       raise;
8313       --
8314   END;                                                              -- Function
8315 --
8316   FUNCTION determine_erlst_deenrt_dt(
8317     p_enrt_cvg_strt_dt           DATE,
8318     p_rqd_perd_enrt_nenrt_val    NUMBER,
8319     p_rqd_perd_enrt_nenrt_tm_uom VARCHAR2,
8320     p_rqd_perd_enrt_nenrt_rl     NUMBER,
8321     p_oipl_id                    NUMBER,
8322     p_pl_id                      NUMBER,
8323     p_pl_typ_id                  NUMBER,
8324     p_opt_id                     NUMBER,
8325     p_pgm_id                     NUMBER,
8326     p_ler_id                     NUMBER,
8327     p_popl_yr_perd_ordr_num      NUMBER,
8328     p_yr_end_dt                  DATE,
8329     p_effective_date             DATE,
8330     p_lf_evt_ocrd_dt             DATE DEFAULT NULL,
8331     p_person_id                  NUMBER,
8332     p_business_group_id          NUMBER,
8333     p_assignment_id              NUMBER,
8334     p_organization_id            NUMBER,
8335     p_jurisdiction_code          VARCHAR2)
8336     RETURN DATE IS
8337     --
8338     -- local variables
8339     --
8340     l_deenrt_dt       DATE;
8341     l_yr_perd_id      NUMBER;
8342     l_popl_yr_perd_id NUMBER;
8343     l_start_date      DATE;
8344     l_end_date        DATE;
8345     l_outputs         ff_exec.outputs_t;
8346     -- Determine a future popl_yr_period
8347     CURSOR c_pl_popl_yr_period_future(p_order_num NUMBER) IS
8348       SELECT   pyp.yr_perd_id,
8349                pyp.popl_yr_perd_id,
8350                yp.start_date,
8351                yp.end_date
8352       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
8353       WHERE    pyp.pl_id = p_pl_id
8354       AND      pyp.business_group_id = p_business_group_id
8355       AND      pyp.ordr_num = p_popl_yr_perd_ordr_num
8356       AND      yp.business_group_id = p_business_group_id
8357       AND      pyp.yr_perd_id = yp.yr_perd_id;
8358   --
8359   BEGIN
8360     IF p_rqd_perd_enrt_nenrt_rl IS NOT NULL THEN
8361     if g_debug then
8362       hr_utility.set_location(
8363         'Organization_id ' || TO_CHAR(p_organization_id),
8364         10);
8365       hr_utility.set_location(
8366         'assignment_id ' || TO_CHAR(p_assignment_id),
8367         15);
8368       hr_utility.set_location(
8369         'Business_group_id ' || TO_CHAR(p_business_group_id),
8370         20);
8371       hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
8372       hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
8373       hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
8374       hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
8375       hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
8376     end if;
8377       l_outputs :=
8378        benutils.formula(
8379          p_formula_id        => p_rqd_perd_enrt_nenrt_rl,
8380          p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8381          p_business_group_id => p_business_group_id,
8382          p_assignment_id     => p_assignment_id,
8383          p_organization_id   => p_organization_id,
8384          p_pl_id             => p_pl_id,
8385          p_pgm_id            => p_pgm_id,
8386          p_opt_id            => p_opt_id,
8387          p_pl_typ_id         => p_pl_typ_id,
8388          p_ler_id            => p_ler_id,
8389          p_jurisdiction_code => p_jurisdiction_code,
8390          p_param1            => 'BEN_IV_PERSON_ID',        -- Bug 5331889 : Added person_id param as well
8391          p_param1_value      => to_char(p_person_id));
8392       --
8393       -- Reformat Canonical Character output to be a date
8394       --
8395       l_deenrt_dt :=
8396                 fnd_date.canonical_to_date(l_outputs(l_outputs.FIRST).VALUE);
8397     ELSE
8398       -- Code     Meaning
8399       -- D     Days
8400       -- W     Weeks
8401       -- M     Months
8402       -- PPLYRQ     Program or Plan Year Quarters
8403       -- Q     Quarters
8404       -- Y     Years
8405       -- PPLYR     Program or Plan Years
8406       IF (p_rqd_perd_enrt_nenrt_tm_uom IN ('D', 'DY')) THEN
8407         --
8408         l_deenrt_dt :=  p_enrt_cvg_strt_dt + p_rqd_perd_enrt_nenrt_val - 1;
8409       --
8410       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('W', 'WK')) THEN
8411         --
8412         l_deenrt_dt :=  p_enrt_cvg_strt_dt + (p_rqd_perd_enrt_nenrt_val * 7) -
8413                           1;
8414       --
8415       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('M', 'MO')) THEN
8416         --
8417         l_deenrt_dt :=
8418                  ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val) - 1;
8419       --
8420       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('Q', 'QTR')) THEN
8421         --
8422         l_deenrt_dt :=
8423              ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val * 3) - 1;
8424       --
8425       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('PPLYR')) THEN
8426         --
8427         -- program/plan years based on passed in current popl_yr_perd
8428         --
8429         IF p_rqd_perd_enrt_nenrt_val = 1 THEN
8430           --
8431           l_deenrt_dt :=  p_yr_end_dt;
8432         --
8433         ELSE
8434           --
8435           OPEN c_pl_popl_yr_period_future(
8436             p_popl_yr_perd_ordr_num + p_rqd_perd_enrt_nenrt_val - 1);
8437           --
8438           FETCH c_pl_popl_yr_period_future INTO l_yr_perd_id,
8439                                                 l_popl_yr_perd_id,
8440                                                 l_start_date,
8441                                                 l_end_date;
8442           l_deenrt_dt :=  l_end_date;
8443           --
8444           CLOSE c_pl_popl_yr_period_future;
8445         --
8446         END IF;
8447       --
8448       ELSIF (p_rqd_perd_enrt_nenrt_tm_uom IN ('Y', 'YR')) THEN
8449         --
8450         l_deenrt_dt :=
8451                ADD_MONTHS(p_enrt_cvg_strt_dt, p_rqd_perd_enrt_nenrt_val * 12);
8452       --
8453       ELSE
8454         --
8455         l_deenrt_dt :=  NULL;
8456       --
8457       END IF;
8458     END IF;
8459     --
8460     RETURN l_deenrt_dt;
8461   --
8462   END;
8463 --
8464   FUNCTION should_create_dpnt_dummy(
8465     p_pl_id             NUMBER,
8466     p_pl_typ_id         NUMBER,
8467     p_opt_id            NUMBER,
8468     p_ler_id            NUMBER,
8469     p_ptip_id           NUMBER,
8470     p_effective_date    DATE,
8471     p_lf_evt_ocrd_dt    DATE DEFAULT NULL,
8472     p_pgm_id            NUMBER,
8473     p_person_id         NUMBER,
8474     p_business_group_id NUMBER,
8475     p_assignment_id     NUMBER,
8476     p_organization_id   NUMBER,
8477     p_jurisdiction_code VARCHAR2)
8478     RETURN BOOLEAN IS
8479     l_level          NUMBER;
8480     l_dpnt_cvg_cd    VARCHAR2(30);
8481     l_dpnt_cvg_rl    NUMBER;
8482     l_outputs        ff_exec.outputs_t;
8483     --
8484     l_lf_evt_ocrd_dt DATE           := NVL(p_lf_evt_ocrd_dt, p_effective_date);
8485     -- Cursor to get the ler_chg_dpnt_f row to
8486     --   see if the choice needs to be created
8487     --   for dpnt reasons
8488     -- Walk up heirarchy - pl, ptip, then pgm.
8489     --
8490     CURSOR c_ler_chg_dep IS
8491       SELECT   '1',
8492                ldc.ler_chg_dpnt_cvg_cd,
8493                ldc.ler_chg_dpnt_cvg_rl
8494       FROM     ben_ler_chg_dpnt_cvg_f ldc
8495       WHERE    ldc.ler_id = p_ler_id
8496       AND      ldc.business_group_id = p_business_group_id
8497       AND      ldc.pl_id = p_pl_id
8498       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8499                    AND ldc.effective_end_date
8500       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL
8501       UNION ALL
8502       SELECT   '2',
8503                ldc.ler_chg_dpnt_cvg_cd,
8504                ldc.ler_chg_dpnt_cvg_rl
8505       FROM     ben_ler_chg_dpnt_cvg_f ldc
8506       WHERE    ldc.ler_id = p_ler_id
8507       AND      ldc.business_group_id = p_business_group_id
8508       AND      ldc.ptip_id = p_ptip_id
8509       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8510                    AND ldc.effective_end_date
8511       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL
8512       UNION ALL
8513       SELECT   '3',
8514                ldc.ler_chg_dpnt_cvg_cd,
8515                ldc.ler_chg_dpnt_cvg_rl
8516       FROM     ben_ler_chg_dpnt_cvg_f ldc
8517       WHERE    ldc.ler_id = p_ler_id
8518       AND      ldc.business_group_id = p_business_group_id
8519       AND      ldc.pgm_id = p_pgm_id
8520       AND      l_lf_evt_ocrd_dt BETWEEN ldc.effective_start_date
8521                    AND ldc.effective_end_date
8522       AND      ldc.ler_chg_dpnt_cvg_cd IS NOT NULL;
8523   BEGIN
8524     OPEN c_ler_chg_dep;
8525     FETCH c_ler_chg_dep INTO l_level, l_dpnt_cvg_cd, l_dpnt_cvg_rl;
8526     IF c_ler_chg_dep%NOTFOUND THEN
8527       RETURN FALSE;
8528     ELSE
8529       IF l_dpnt_cvg_cd = 'RL' THEN
8530         -- Evaluate the rule
8531       if g_debug then
8532         hr_utility.set_location(
8533           'Organization_id ' || TO_CHAR(p_organization_id),
8534           10);
8535         hr_utility.set_location(
8536           'assignment_id ' || TO_CHAR(p_assignment_id),
8537           15);
8538         hr_utility.set_location(
8539           'Business_group_id ' || TO_CHAR(p_business_group_id),
8540           20);
8541         hr_utility.set_location('pgm_id ' || TO_CHAR(p_pgm_id), 30);
8542         hr_utility.set_location('pl_id ' || TO_CHAR(p_pl_id), 40);
8543         hr_utility.set_location('pl_typ_id ' || TO_CHAR(p_pl_typ_id), 50);
8544         hr_utility.set_location('opt_id ' || TO_CHAR(p_opt_id), 60);
8545         hr_utility.set_location('ler_id ' || TO_CHAR(p_ler_id), 70);
8546       end if;
8547         l_outputs :=
8548          benutils.formula(
8549            p_formula_id        => l_dpnt_cvg_rl,
8550            p_effective_date    => NVL(p_lf_evt_ocrd_dt, p_effective_date),
8551            p_business_group_id => p_business_group_id,
8552            p_assignment_id     => p_assignment_id,
8553            p_organization_id   => p_organization_id,
8554            p_pl_id             => p_pl_id,
8555            p_pgm_id            => p_pgm_id,
8556            p_opt_id            => p_opt_id,
8557            p_pl_typ_id         => p_pl_typ_id,
8558            p_ler_id            => p_ler_id,
8559            p_jurisdiction_code => p_jurisdiction_code);
8560         l_dpnt_cvg_cd :=  l_outputs(l_outputs.FIRST).VALUE;
8561       END IF;
8562       --
8563       -- For MNANRD (May not add nor removed dependents)
8564       -- don't need choice, all other codes do need it.
8565       --
8566       IF l_dpnt_cvg_cd = 'MNANRD' THEN
8567         RETURN FALSE;
8568       END IF;
8569     END IF;
8570     CLOSE c_ler_chg_dep;
8571     RETURN TRUE;
8572   END;
8573 --
8574 procedure determine_dflt_enrt_cd
8575   (p_oipl_id           in     number
8576   ,p_plip_id           in     number
8577   ,p_pl_id             in     number
8578   ,p_ptip_id           in     number
8579   ,p_pgm_id            in     number
8580   ,p_ler_id            in     number
8581   ,p_business_group_id in     number
8582   ,p_effective_date    in     date
8583   ,p_dflt_enrt_cd         out nocopy varchar2
8584   ,p_dflt_enrt_rl         out nocopy number
8585   )
8586 IS
8587     --
8588     -- NOTE:
8589     --
8590     --   This procedure is also callable from other RCOs
8591     --   Please do not remove get_object calls since they
8592     --   may be needed if not called from bendenrr.
8593     --
8594     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
8595     --
8596     CURSOR c_ler_oipl_dflt_cd IS
8597       SELECT   leo.dflt_enrt_cd,
8598                leo.dflt_enrt_rl
8599       FROM     ben_ler_chg_oipl_enrt_f leo
8600       WHERE    p_oipl_id = leo.oipl_id
8601       AND      p_ler_id = leo.ler_id
8602       AND      p_effective_date BETWEEN leo.effective_start_date
8603                    AND leo.effective_end_date;
8604     --
8605     -- Use cache for oipl, don't need cursor
8606     --
8607     CURSOR c_ler_pl_nip_dflt_cd IS
8608       SELECT   len.dflt_enrt_cd,
8609                len.dflt_enrt_rl
8610       FROM     ben_ler_chg_pl_nip_enrt_f len
8611       WHERE    p_pl_id = len.pl_id
8612       AND      p_ler_id = len.ler_id
8613       AND      p_effective_date BETWEEN len.effective_start_date
8614                    AND len.effective_end_date;
8615     --
8616     CURSOR c_ler_plip_dflt_cd IS
8617       SELECT   lep.dflt_enrt_cd,
8618                lep.dflt_enrt_rl
8619       FROM     ben_ler_chg_plip_enrt_f lep
8620       WHERE    p_plip_id = lep.plip_id
8621       AND      p_ler_id = lep.ler_id
8622       AND      p_effective_date BETWEEN lep.effective_start_date
8623                    AND lep.effective_end_date;
8624     --
8625     CURSOR c_ler_ptip_dflt_cd IS
8626       SELECT   lep.dflt_enrt_cd,
8627                lep.dflt_enrt_rl
8628       FROM     ben_ler_chg_ptip_enrt_f lep
8629       WHERE    p_ptip_id = lep.ptip_id
8630       AND      p_ler_id = lep.ler_id
8631       AND      p_effective_date BETWEEN lep.effective_start_date
8632                    AND lep.effective_end_date;
8633     --
8634     CURSOR c_ler_pgm_dflt_cd IS
8635       SELECT   lep.dflt_enrt_cd,
8636                lep.dflt_enrt_rl
8637       FROM     ben_ler_chg_pgm_enrt_f lep
8638       WHERE    p_pgm_id = lep.pgm_id
8639       AND      p_ler_id = lep.ler_id
8640       AND      p_effective_date BETWEEN lep.effective_start_date
8641                    AND lep.effective_end_date;
8642     --
8643     CURSOR c_pl_nip_dflt_cd IS
8644       SELECT   pln.nip_dflt_enrt_cd,
8645                pln.nip_dflt_enrt_det_rl
8646       FROM     ben_pl_f pln
8647       WHERE    p_pl_id = pln.pl_id
8648       AND      p_effective_date BETWEEN pln.effective_start_date
8649                    AND pln.effective_end_date;
8650     --
8651     CURSOR c_plip_dflt_cd IS
8652       SELECT   plp.dflt_enrt_cd,
8653                plp.dflt_enrt_det_rl
8654       FROM     ben_plip_f plp
8655       WHERE    p_plip_id = plp.plip_id
8656       AND      p_effective_date BETWEEN plp.effective_start_date
8657                    AND plp.effective_end_date;
8658     --
8659     CURSOR c_ptip_dflt_cd IS
8660       SELECT   ptp.dflt_enrt_cd,
8661                ptp.dflt_enrt_det_rl
8662       FROM     ben_ptip_f ptp
8663       WHERE    p_ptip_id = ptp.ptip_id
8664       AND      p_effective_date BETWEEN ptp.effective_start_date
8665                    AND ptp.effective_end_date;
8666     --
8667     l_dflt_enrt_cd VARCHAR2(30);
8668     l_dflt_enrt_rl NUMBER;
8669     l_plan_rec     ben_pl_f%ROWTYPE;
8670     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
8671     l_pl_rec       ben_cobj_cache.g_pl_inst_row;
8672   BEGIN
8673   g_debug := hr_utility.debug_enabled;
8674   if g_debug then
8675     hr_utility.set_location('Entering: ' || l_proc, 10);
8676   end if;
8677     --
8678     l_dflt_enrt_cd :=  NULL;
8679     --
8680     -- Hierarchy
8681     --
8682     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
8683     -- 2  if oipl     ben_oipl_f (from cache)
8684     --
8685     -- 3  if no pgm   ben_ler_chg_pl_nip_enrt_f
8686     -- 4  if pgm      ben_ler_chg_plip_enrt_f
8687     -- 4.5 if pgm     ben_ler_chg_pl_nip_enrt_f
8688     -- 5  if pgm      ben_ler_chg_ptip_enrt_f
8689     -- 6  if pgm      ben_ler_chg_pgm_enrt_f
8690     --
8691     -- 7  if no pgm   ben_pl_f
8692     -- 8  if pgm      ben_plip_f
8693     -- 9  if pgm      ben_ptip_f
8694     --
8695     IF p_oipl_id IS NOT NULL THEN
8696       --
8697       -- 1
8698       --
8699       OPEN c_ler_oipl_dflt_cd;
8700       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8701       CLOSE c_ler_oipl_dflt_cd;
8702       --
8703       -- hr_utility.set_location(l_dflt_enrt_cd,20);
8704       IF l_dflt_enrt_cd IS NULL THEN
8705         --
8706         -- 2
8707         -- Bug 5569758
8708         --
8709         ben_cobj_cache.get_oipl_dets (p_business_group_id => p_business_group_id,
8710                                       p_effective_date    => p_effective_date,
8711                                       p_oipl_id           => p_oipl_id,
8712                                       p_inst_row	  => l_oipl_rec
8713                                       );
8714         --
8715         l_dflt_enrt_cd :=  l_oipl_rec.dflt_enrt_cd;
8716         l_dflt_enrt_rl :=  l_oipl_rec.dflt_enrt_det_rl;
8717       --
8718       END IF;
8719     END IF;
8720     -- hr_utility.set_location(l_dflt_enrt_cd,30);
8721     IF     p_pgm_id IS NULL
8722        AND l_dflt_enrt_cd IS NULL THEN
8723       --
8724       -- 3
8725       --
8726       OPEN c_ler_pl_nip_dflt_cd;
8727       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8728       CLOSE c_ler_pl_nip_dflt_cd;
8729     --  hr_utility.set_location(l_dflt_enrt_cd,40);
8730     ELSIF     p_pgm_id IS NOT NULL
8731           AND l_dflt_enrt_cd IS NULL THEN
8732       --
8733       -- 4
8734       --
8735       OPEN c_ler_plip_dflt_cd;
8736       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8737       CLOSE c_ler_plip_dflt_cd;
8738       --  hr_utility.set_location(l_dflt_enrt_cd,50);
8739       -- Bug 5555402
8740       IF l_dflt_enrt_cd IS NULL THEN
8741         --
8742         -- 4.5
8743         --
8744         OPEN c_ler_pl_nip_dflt_cd;
8745         FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8746         CLOSE c_ler_pl_nip_dflt_cd;
8747         --
8748         IF l_dflt_enrt_cd IS NULL THEN
8749           --
8750           -- 5
8751           --
8752           OPEN c_ler_ptip_dflt_cd;
8753           FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8754           CLOSE c_ler_ptip_dflt_cd;
8755           --  hr_utility.set_location(l_dflt_enrt_cd,60);
8756           IF l_dflt_enrt_cd IS NULL THEN
8757             --
8758             -- 6
8759             --
8760             OPEN c_ler_pgm_dflt_cd;
8761             FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8762             CLOSE c_ler_pgm_dflt_cd;
8763           END IF;
8764         END IF;
8765         --
8766       END IF;
8767       --
8768     END IF;
8769     --  hr_utility.set_location(l_dflt_enrt_cd,80);
8770     IF     p_pgm_id IS NULL
8771        AND l_dflt_enrt_cd IS NULL THEN
8772       --
8773       -- 7
8774       --
8775       ben_cobj_cache.get_pl_dets (p_business_group_id => p_business_group_id,
8776                                     p_effective_date  => p_effective_date,
8777                                     p_pl_id           => p_pl_id,
8778                                     p_inst_row	      => l_pl_rec
8779                                     );
8780       --
8781       l_dflt_enrt_cd :=  l_pl_rec.nip_dflt_enrt_cd;
8782       l_dflt_enrt_rl :=  l_pl_rec.nip_dflt_enrt_det_rl;
8783       --
8784       --  hr_utility.set_location(l_dflt_enrt_cd,90);
8785     ELSIF     p_pgm_id IS NOT NULL
8786           AND l_dflt_enrt_cd IS NULL THEN
8787       --
8788       -- 8
8789       --
8790       OPEN c_plip_dflt_cd;
8791       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8792       CLOSE c_plip_dflt_cd;
8793       --  hr_utility.set_location(l_dflt_enrt_cd,100);
8794         --
8795       IF l_dflt_enrt_cd IS NULL THEN
8796         --
8797         -- 9
8798         --
8799         OPEN c_ptip_dflt_cd;
8800         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
8801         CLOSE c_ptip_dflt_cd;
8802      --  hr_utility.set_location(l_dflt_enrt_cd,110);
8803         --
8804       END IF;
8805     END IF;
8806     --
8807     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
8808     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
8809     --
8810     if g_debug then
8811     hr_utility.set_location(l_dflt_enrt_cd,145);
8812     hr_utility.set_location('Leaving: ' || l_proc, 150);
8813     end if;
8814     --
8815   exception
8816     --
8817     when others then
8818       --
8819       p_dflt_enrt_cd        := null;
8820       p_dflt_enrt_rl        := null;
8821       raise;
8822       --
8823   END;
8824 --
8825 /*
8826 This Procedure is moved at the top of the Package
8827 -- internal version below for update_defaults
8828 --
8829 procedure determine_dflt_enrt_cd
8830   (p_oipl_id           in     number
8831   ,p_oipl_rec          in     ben_oipl_f%rowtype
8832   ,p_plip_id           in     number
8833   ,p_plip_rec          in     ben_plip_f%rowtype
8834   ,p_pl_id             in     number
8835   ,p_pl_rec            in     ben_pl_f%rowtype
8836   ,p_ptip_id           in     number
8837   ,p_ptip_rec          in     ben_ptip_f%rowtype
8838   ,p_pgm_id            in     number
8839   ,p_pgm_rec           in     ben_pgm_f%rowtype
8840   ,p_ler_id            in     number
8841   ,p_business_group_id in     number
8842   ,p_effective_date    in     date
8843   ,p_dflt_enrt_cd         out nocopy varchar2
8844   ,p_dflt_enrt_rl         out nocopy number
8845   ,p_level                out nocopy varchar2
8846   ,p_ler_dflt_flag   out nocopy varchar2
8847   )
8848 IS
8849     --
8850     -- NOTE:
8851     --
8852     --   This procedure is also callable from other RCOs
8853     --   Please do not remove get_object calls since they
8854     --   may be needed if not called from bendenrr.
8855     --
8856     l_proc         VARCHAR2(80)       := g_package || '.determine_dflt_enrt_cd';
8857     --
8858     CURSOR c_ler_oipl_dflt_cd IS
8859       SELECT   leo.dflt_enrt_cd,
8860                leo.dflt_enrt_rl,
8861                leo.dflt_flag
8862       FROM     ben_ler_chg_oipl_enrt_f leo
8863       WHERE    p_oipl_id = leo.oipl_id
8864       AND      p_ler_id = leo.ler_id
8865       AND      p_effective_date BETWEEN leo.effective_start_date
8866                    AND leo.effective_end_date;
8867     --
8868     -- Use cache for oipl, don't need cursor
8869     --
8870     CURSOR c_ler_pl_nip_dflt_cd IS
8871       SELECT   len.dflt_enrt_cd,
8872                len.dflt_enrt_rl,
8873                len.dflt_flag
8874       FROM     ben_ler_chg_pl_nip_enrt_f len
8875       WHERE    p_pl_id = len.pl_id
8876       AND      p_ler_id = len.ler_id
8877       AND      p_effective_date BETWEEN len.effective_start_date
8878                    AND len.effective_end_date;
8879     --
8880     CURSOR c_ler_plip_dflt_cd IS
8881       SELECT   lep.dflt_enrt_cd,
8882                lep.dflt_enrt_rl,
8883                lep.dflt_flag
8884       FROM     ben_ler_chg_plip_enrt_f lep
8885       WHERE    p_plip_id = lep.plip_id
8886       AND      p_ler_id = lep.ler_id
8887       AND      p_effective_date BETWEEN lep.effective_start_date
8888                    AND lep.effective_end_date;
8889     --
8890     CURSOR c_ler_ptip_dflt_cd IS
8891       SELECT   lep.dflt_enrt_cd,
8892                lep.dflt_enrt_rl
8893       FROM     ben_ler_chg_ptip_enrt_f lep
8894       WHERE    p_ptip_id = lep.ptip_id
8895       AND      p_ler_id = lep.ler_id
8896       AND      p_effective_date BETWEEN lep.effective_start_date
8897                    AND lep.effective_end_date;
8898     --
8899     CURSOR c_ler_pgm_dflt_cd IS
8900       SELECT   lep.dflt_enrt_cd,
8901                lep.dflt_enrt_rl
8902       FROM     ben_ler_chg_pgm_enrt_f lep
8903       WHERE    p_pgm_id = lep.pgm_id
8904       AND      p_ler_id = lep.ler_id
8905       AND      p_effective_date BETWEEN lep.effective_start_date
8906                    AND lep.effective_end_date;
8907     --
8908     CURSOR c_pl_nip_dflt_cd IS
8909       SELECT   pln.nip_dflt_enrt_cd,
8910                pln.nip_dflt_enrt_det_rl,
8911                pln.nip_dflt_flag
8912       FROM     ben_pl_f pln
8913       WHERE    p_pl_id = pln.pl_id
8914       AND      p_effective_date BETWEEN pln.effective_start_date
8915                    AND pln.effective_end_date;
8916     --
8917     CURSOR c_plip_dflt_cd IS
8918       SELECT   plp.dflt_enrt_cd,
8919                plp.dflt_enrt_det_rl
8920       FROM     ben_plip_f plp
8921       WHERE    p_plip_id = plp.plip_id
8922       AND      p_effective_date BETWEEN plp.effective_start_date
8923                    AND plp.effective_end_date;
8924     --
8925     CURSOR c_ptip_dflt_cd IS
8926       SELECT   ptp.dflt_enrt_cd,
8927                ptp.dflt_enrt_det_rl
8928       FROM     ben_ptip_f ptp
8929       WHERE    p_ptip_id = ptp.ptip_id
8930       AND      p_effective_date BETWEEN ptp.effective_start_date
8931                    AND ptp.effective_end_date;
8932     --
8933     l_dflt_enrt_cd VARCHAR2(30);
8934     l_dflt_enrt_rl NUMBER;
8935     l_plan_rec     ben_pl_f%ROWTYPE;
8936     l_oipl_rec     ben_cobj_cache.g_oipl_inst_row;
8937     l_ler_dflt_flag varchar2(30); -- 3510229
8938   BEGIN
8939     hr_utility.set_location('Entering: ' || l_proc, 10);
8940     --
8941     l_dflt_enrt_cd :=  NULL;
8942     --
8943     -- Hierarchy
8944     --
8945     -- 1  if oipl     ben_ler_chg_oipl_enrt_f
8946     -- 2  if oipl     ben_oipl_f (from cache)
8947     --
8948     -- 3  if no pgm   ben_ler_chg_pl_nip_enrt_f
8949     -- 4  if pgm      ben_ler_chg_plip_enrt_f
8950     -- 5  if pgm      ben_ler_chg_ptip_enrt_f
8951     -- 6  if pgm      ben_ler_chg_pgm_enrt_f
8952     --
8953     -- 7  if no pgm   ben_pl_f
8954     -- 8  if pgm      ben_plip_f
8955     -- 9  if pgm      ben_ptip_f
8956     --
8957     IF p_oipl_id IS NOT NULL THEN
8958       --
8959       -- 1
8960       --
8961       OPEN c_ler_oipl_dflt_cd;
8962       FETCH c_ler_oipl_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag;
8963                                     --p_ler_dflt_flag; 3510229
8964       CLOSE c_ler_oipl_dflt_cd;
8965       if
8966 			-- l_dflt_enrt_cd 3510229
8967 			l_ler_dflt_flag is not null then
8968         p_level:='LER_OIPL';
8969         p_ler_dflt_flag := l_ler_dflt_flag; -- 3510229
8970         l_ler_dflt_flag := null ; --3510229
8971       end if;
8972       --
8973       IF l_dflt_enrt_cd IS NULL THEN
8974         --
8975         -- 2
8976         --
8977         hr_utility.set_location('In the case 2 ' , 100);
8978         --
8979         --l_dflt_enrt_cd :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_cd;
8980         --l_dflt_enrt_rl :=  ben_cobj_cache.g_oipl_currow.dflt_enrt_det_rl;
8981         --
8982         l_dflt_enrt_cd := p_oipl_rec.dflt_enrt_cd ;
8983         l_dflt_enrt_rl := p_oipl_rec.dflt_enrt_det_rl ;
8984 
8985         --hr_utility.set_location(' p_oipl_rec.oipl_id '||p_oipl_rec.oipl_id ,110);
8986         --hr_utility.set_location(' p_oipl_rec.dflt_enrt_cd '||p_oipl_rec.dflt_enrt_cd ,110);
8987         --hr_utility.set_location(' p_oipl_rec.dflt_flag '||p_oipl_rec.dflt_flag, 110)  ;
8988         --
8989       if l_dflt_enrt_cd is not null
8990          and p_level is null then -- 3510229
8991         p_level:='OIPL';
8992       end if;
8993       --
8994       END IF;
8995     END IF;
8996 
8997     IF     p_pgm_id IS NULL
8998        AND l_dflt_enrt_cd IS NULL THEN
8999       --
9000       -- 3
9001       --
9002       OPEN c_ler_pl_nip_dflt_cd;
9003       FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag; --3510229
9004                                     --p_ler_dflt_flag;
9005       CLOSE c_ler_pl_nip_dflt_cd;
9006       if l_dflt_enrt_cd is not null
9007          and p_level is null then -- 3510229
9008         p_level:='LER_PL_NIP';
9009         -- 3510229 start
9010         -- there could be default flag without default code , so this s moved down - 	4008380
9011         --if p_ler_dflt_flag is null then
9012         --  p_ler_dflt_flag := l_ler_dflt_flag;
9013         --end if;
9014         --l_ler_dflt_flag := null ;
9015         hr_utility.set_location('after LER pNip chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9016         -- 3510229 end
9017 
9018       end if;
9019       -- there could be default flag without default code 4008380
9020       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9021           p_ler_dflt_flag := l_ler_dflt_flag ;
9022       end if ;
9023       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
9024       hr_utility.set_location(l_dflt_enrt_cd,40);
9025 
9026 
9027     ELSIF     p_pgm_id IS NOT NULL
9028           AND l_dflt_enrt_cd IS NULL THEN
9029       --
9030       -- 4
9031       --
9032       OPEN c_ler_plip_dflt_cd;
9033       FETCH c_ler_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl, l_ler_dflt_flag; --3510229
9034                                     --p_ler_dflt_flag;
9035       CLOSE c_ler_plip_dflt_cd;
9036       if l_dflt_enrt_cd is not null
9037          and p_level is null then -- 3510229
9038         p_level:='LER_PLIP';
9039 
9040         -- 3510229 start
9041         --  4008380
9042         --if p_ler_dflt_flag is null then
9043         --  p_ler_dflt_flag := l_ler_dflt_flag;
9044         --end if;
9045         hr_utility.set_location('after LER PLIP chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9046         --l_ler_dflt_flag := null ;
9047         -- 3510229 end
9048 
9049       end if;
9050       --  4008380
9051       if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9052           p_ler_dflt_flag := l_ler_dflt_flag ;
9053       end if ;
9054       hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,50);
9055       hr_utility.set_location(l_dflt_enrt_cd,50);
9056 
9057       --  4008380
9058       --  there could be plip but the setup may be in plan  ler level
9059       IF l_dflt_enrt_cd IS NULL THEN
9060 
9061          OPEN c_ler_pl_nip_dflt_cd;
9062          FETCH c_ler_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,l_ler_dflt_flag;
9063          CLOSE c_ler_pl_nip_dflt_cd;
9064 
9065          if l_dflt_enrt_cd is not null
9066             and p_level is null then -- 3510229
9067             p_level:='LER_PL';
9068             hr_utility.set_location('after LER Plan  chk p_ler_dflt_flag:  '||p_ler_dflt_flag , 100);
9069          end if;
9070          -- there could be default flag without default code 4008380
9071          if p_ler_dflt_flag is null and l_ler_dflt_flag is not null  then
9072             p_ler_dflt_flag := l_ler_dflt_flag ;
9073          end if ;
9074          hr_utility.set_location('l_ler_dflt_flag ' || l_ler_dflt_flag ,40);
9075          hr_utility.set_location(l_dflt_enrt_cd,40);
9076       end if ;
9077 
9078 
9079 
9080       --- ptip level
9081       IF l_dflt_enrt_cd IS NULL THEN
9082         --
9083         -- 5
9084         --
9085         OPEN c_ler_ptip_dflt_cd;
9086         FETCH c_ler_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9087         CLOSE c_ler_ptip_dflt_cd;
9088       if l_dflt_enrt_cd is not null
9089          and p_level is null then -- 3510229
9090         p_level:='LER_PTIP';
9091       end if;
9092         --  hr_utility.set_location(l_dflt_enrt_cd,60);
9093         IF l_dflt_enrt_cd IS NULL THEN
9094           --
9095           -- 6
9096           --
9097           OPEN c_ler_pgm_dflt_cd;
9098           FETCH c_ler_pgm_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9099           CLOSE c_ler_pgm_dflt_cd;
9100       if l_dflt_enrt_cd is not null
9101          and p_level is null then --3510229
9102         p_level:='LER_PGM';
9103       end if;
9104         END IF;
9105       END IF;
9106     END IF;
9107     --  hr_utility.set_location(l_dflt_enrt_cd,80);
9108     IF     p_pgm_id IS NULL
9109        AND l_dflt_enrt_cd IS NULL THEN
9110       --
9111       -- 7
9112       --
9113       -- Bug 1895874
9114       -- l_dflt_enrt_cd :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_cd;
9115       -- l_dflt_enrt_rl :=  ben_cobj_cache.g_pl_currow.nip_dflt_enrt_det_rl;
9116       --
9117       hr_utility.set_location(' p_pl_rec.pl_id '||p_oipl_rec.oipl_id ,110);
9118       hr_utility.set_location(' p_pl_rec.nip_dflt_enrt_cd '||p_pl_rec.nip_dflt_enrt_cd ,110);
9119       hr_utility.set_location(' p_pl_rec.nip_dflt_flag '||p_pl_rec.nip_dflt_flag, 110)  ;
9120       --
9121       l_dflt_enrt_cd := p_pl_rec.nip_dflt_enrt_cd ;
9122       l_dflt_enrt_rl := p_pl_rec.nip_dflt_enrt_det_rl ;
9123       if p_ler_dflt_flag is null then -- 3510229
9124         p_ler_dflt_flag := p_pl_rec.nip_dflt_flag ;
9125       end if;
9126 
9127 /*
9128       OPEN c_pl_nip_dflt_cd;
9129       FETCH c_pl_nip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl,
9130                                     p_ler_dflt_flag;
9131       CLOSE c_pl_nip_dflt_cd;
9132 * /
9133       --
9134       if l_dflt_enrt_cd is not null
9135          and p_level is null then -- 3510229
9136         p_level:='PL';
9137       end if;
9138       --
9139     --  hr_utility.set_location(l_dflt_enrt_cd,90);
9140 
9141     ELSIF     p_pgm_id IS NOT NULL
9142           AND l_dflt_enrt_cd IS NULL THEN
9143       --
9144       -- 8
9145       --
9146       l_dflt_enrt_cd := p_plip_rec.dflt_enrt_cd ;
9147       l_dflt_enrt_rl := p_plip_rec.dflt_enrt_det_rl ;
9148 /*
9149       OPEN c_plip_dflt_cd;
9150       FETCH c_plip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9151       CLOSE c_plip_dflt_cd;
9152 * /
9153       if l_dflt_enrt_cd is not null
9154          and p_level is null then -- 3510229
9155         p_level:='PLIP';
9156       end if;
9157        hr_utility.set_location(l_dflt_enrt_cd,100);
9158         --
9159       IF l_dflt_enrt_cd IS NULL THEN
9160         --
9161         -- 9
9162         --
9163       l_dflt_enrt_cd := p_ptip_rec.dflt_enrt_cd ;
9164       l_dflt_enrt_rl := p_ptip_rec.dflt_enrt_det_rl ;
9165 /*
9166         OPEN c_ptip_dflt_cd;
9167         FETCH c_ptip_dflt_cd INTO l_dflt_enrt_cd, l_dflt_enrt_rl;
9168         CLOSE c_ptip_dflt_cd;
9169 * /
9170       if l_dflt_enrt_cd is not null
9171          and p_level is null then -- 3510229
9172         p_level:='PTIP';
9173       end if;
9174       hr_utility.set_location(l_dflt_enrt_cd,110);
9175         --
9176       END IF;
9177     END IF;
9178   --
9179     hr_utility.set_location(' p_pgm_id '||p_pgm_id||' pl_id '||p_pl_id||' oipl '||p_oipl_id||
9180                             ' plip '||p_plip_id||' ptip '||p_ptip_id,130);
9181     hr_utility.set_location('dflt_enrt_cd= '||l_dflt_enrt_cd,130);
9182     hr_utility.set_location('dflt_enrt_rl= '||l_dflt_enrt_rl,140);
9183     hr_utility.set_location('p_ler_dflt_flag= '||p_ler_dflt_flag ,140);
9184     p_dflt_enrt_cd :=  l_dflt_enrt_cd;
9185     p_dflt_enrt_rl :=  l_dflt_enrt_rl;
9186     hr_utility.set_location('Leaving: ' || l_proc, 150);
9187   exception
9188     --
9189     when others then
9190       --
9191       p_dflt_enrt_cd        := null;
9192       p_dflt_enrt_rl        := null;
9193       p_level               := null;
9194       p_ler_dflt_flag       := null;
9195       raise;
9196       --
9197   END;
9198   --
9199 */
9200 
9201   -- Find the required period of enrollment.  Code/rule/value and level.
9202   --
9203 procedure find_rqd_perd_enrt
9204   (p_oipl_id                 in     number
9205   ,p_opt_id                  in     number
9206   ,p_pl_id                   in     number
9207   ,p_ptip_id                 in     number
9208   ,p_effective_date          in     date
9209   ,p_business_group_id       in     number
9210   ,p_rqd_perd_enrt_nenrt_uom    out nocopy varchar2
9211   ,p_rqd_perd_enrt_nenrt_val    out nocopy number
9212   ,p_rqd_perd_enrt_nenrt_rl     out nocopy number
9213   ,p_level                      out nocopy varchar2
9214   )
9215 IS
9216     --
9217     -- THIS SQL STATEMENT HAS BEEN COMMENTED OUT AND REPLACED BY THE IF LOGIC
9218     --
9219     -- get rqd_perd_enrt_nenrt heirarchy
9220     --
9221     CURSOR c_nenrt IS
9222       SELECT   '1',
9223                bo.rqd_perd_enrt_nenrt_uom,
9224                bo.rqd_perd_enrt_nenrt_val,
9225                bo.rqd_perd_enrt_nenrt_rl
9226       FROM     ben_oipl_f bo
9227       WHERE    bo.oipl_id = p_oipl_id
9228       AND      p_effective_date BETWEEN bo.effective_start_date
9229                    AND bo.effective_end_date
9230       AND      bo.business_group_id = p_business_group_id
9231       AND      (
9232                     (
9233                           bo.rqd_perd_enrt_nenrt_uom IS NOT NULL
9234                       AND bo.rqd_perd_enrt_nenrt_val IS NOT NULL)
9235                  OR bo.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9236       UNION ALL
9237       SELECT   '2',
9238                bo.rqd_perd_enrt_nenrt_uom,
9239                bo.rqd_perd_enrt_nenrt_val,
9240                bo.rqd_perd_enrt_nenrt_rl
9241       FROM     ben_opt_f bo
9242       WHERE    bo.opt_id = p_opt_id
9243       AND      p_effective_date BETWEEN bo.effective_start_date
9244                    AND bo.effective_end_date
9245       AND      bo.business_group_id = p_business_group_id
9246       AND      (
9247                     (
9248                           bo.rqd_perd_enrt_nenrt_uom IS NOT NULL
9249                       AND bo.rqd_perd_enrt_nenrt_val IS NOT NULL)
9250                  OR bo.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9251       UNION ALL
9252       SELECT   '3',
9253                bp.rqd_perd_enrt_nenrt_uom,
9254                bp.rqd_perd_enrt_nenrt_val,
9255                bp.rqd_perd_enrt_nenrt_rl
9256       FROM     ben_pl_f bp
9257       WHERE    bp.pl_id = p_pl_id
9258       AND      p_effective_date BETWEEN bp.effective_start_date
9259                    AND bp.effective_end_date
9260       AND      bp.business_group_id = p_business_group_id
9261       AND      (
9262                     (
9263                           bp.rqd_perd_enrt_nenrt_uom IS NOT NULL
9264                       AND bp.rqd_perd_enrt_nenrt_val IS NOT NULL)
9265                  OR bp.rqd_perd_enrt_nenrt_rl IS NOT NULL)
9266       UNION ALL
9267       SELECT   '4',
9268                bp.rqd_perd_enrt_nenrt_tm_uom,
9269                bp.rqd_perd_enrt_nenrt_val,
9270                bp.rqd_perd_enrt_nenrt_rl
9271       FROM     ben_ptip_f bp
9272       WHERE    bp.ptip_id = p_ptip_id
9273       AND      p_effective_date BETWEEN bp.effective_start_date
9274                    AND bp.effective_end_date
9275       AND      bp.business_group_id = p_business_group_id
9276       AND      (
9277                     (
9278                           bp.rqd_perd_enrt_nenrt_tm_uom IS NOT NULL
9279                       AND bp.rqd_perd_enrt_nenrt_val IS NOT NULL)
9280                  OR bp.rqd_perd_enrt_nenrt_rl IS NOT NULL);
9281     l_level varchar2(30);
9282   BEGIN
9283     --
9284     -- Check if context parameters are set. When context parameters are
9285     -- not set then fire cursor
9286     --
9287     if ben_cobj_cache.g_ptip_currow.ptip_id is not null
9288       or ben_cobj_cache.g_pl_currow.pl_id is not null
9289       or ben_cobj_cache.g_opt_currow.opt_id is not null
9290       or ben_cobj_cache.g_oipl_currow.oipl_id is not null
9291     then
9292       --
9293       IF     ben_cobj_cache.g_oipl_currow.oipl_id = p_oipl_id
9294          AND (
9295                   (
9296                         ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9297                     AND ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9298                OR ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9299         --
9300         p_level                    := 'OIPL';
9301         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_uom;
9302         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_val;
9303         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_oipl_currow.rqd_perd_enrt_nenrt_rl;
9304       ELSIF     ben_cobj_cache.g_opt_currow.opt_id = p_opt_id
9305             AND (
9306                      (
9307                            ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9308                        AND ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9309                   OR ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9310         --
9311         p_level                    := 'OPT';
9312         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_uom;
9313         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_val;
9314         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_opt_currow.rqd_perd_enrt_nenrt_rl;
9315       ELSIF     ben_cobj_cache.g_pl_currow.pl_id = p_pl_id
9316             AND (
9317                      (
9318                            ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_uom IS NOT NULL
9319                        AND ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9320                   OR ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9321         --
9322         p_level                    := 'PL';
9323         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_uom;
9324         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_val;
9325         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_pl_currow.rqd_perd_enrt_nenrt_rl;
9326       ELSIF     ben_cobj_cache.g_ptip_currow.ptip_id = p_ptip_id
9327             AND (
9328                      (
9329                            ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_tm_uom IS NOT NULL
9330                        AND ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_val IS NOT NULL)
9331                   OR ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_rl IS NOT NULL) THEN
9332         --
9333         p_level                    := 'PTIP';
9334         p_rqd_perd_enrt_nenrt_uom  := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_tm_uom;
9335         p_rqd_perd_enrt_nenrt_val  := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_val;
9336         p_rqd_perd_enrt_nenrt_rl   := ben_cobj_cache.g_ptip_currow.rqd_perd_enrt_nenrt_rl;
9337       END IF;
9338       --
9339     else
9340       --
9341       OPEN c_nenrt;
9342       FETCH c_nenrt INTO l_level,
9343                          p_rqd_perd_enrt_nenrt_uom,
9344                          p_rqd_perd_enrt_nenrt_val,
9345                          p_rqd_perd_enrt_nenrt_rl;
9346       CLOSE c_nenrt;
9347       IF l_level IS NOT NULL THEN
9348         IF l_level = 1 THEN
9349           p_level  := 'OIPL';
9350         ELSIF l_level = 2 THEN
9351           p_level  := 'OPT';
9352         ELSIF l_level = 3 THEN
9353           p_level  := 'PL';
9354         ELSIF l_level = 4 THEN
9355           p_level  := 'PTIP';
9356         END IF;
9357       END IF;
9358       --
9359     end if;
9360     if g_debug then
9361     hr_utility.set_location('level ' ||  p_level , 8086);
9362     end if;
9363     --
9364   exception
9365     --
9366     when others then
9367       --
9368       p_rqd_perd_enrt_nenrt_uom   := null;
9369       p_rqd_perd_enrt_nenrt_val   := null;
9370       p_rqd_perd_enrt_nenrt_rl    := null;
9371       p_level                     := null;
9372       raise;
9373       --
9374   END find_rqd_perd_enrt;
9375 --
9376 -- find an enrollment at the give level.
9377 --
9378   PROCEDURE find_enrt_at_same_level(
9379     p_person_id         IN     NUMBER,
9380     p_opt_id            IN     NUMBER,
9381     p_oipl_id           IN     NUMBER,
9382     p_pl_id             IN     NUMBER,
9383     p_ptip_id           IN     NUMBER,
9384     p_pl_typ_id         IN     NUMBER,
9385     p_pgm_id            IN     NUMBER,
9386     p_effective_date    IN     DATE,
9387     p_business_group_id IN     NUMBER,
9388     p_prtt_enrt_rslt_id IN     NUMBER,
9389     p_level             IN     VARCHAR2,
9390     p_pen_rec           OUT NOCOPY    ben_prtt_enrt_rslt_f%ROWTYPE) IS
9391     --
9392     l_effective_date_1 DATE := p_effective_date - 1;
9393     --
9394     -- Gets the enrolment information for the ptip
9395     --
9396     -- Notes:
9397     --   <> pen_id checks are for enrollment time use not bendenrr use
9398     -- bug : 1620162 ig the send even the option saved then replaces with other option
9399     -- the chek l_effective_date_1 <= pen.enrt_cvg_thru_dt became true
9400     -- so changed to l_effective_date_1 < pen.enrt_cvg_thru_dt
9401     CURSOR c_ptip_enrolment_info IS
9402       SELECT   *
9403       FROM     ben_prtt_enrt_rslt_f pen
9404       WHERE    pen.person_id = p_person_id
9405       AND      pen.business_group_id = p_business_group_id
9406       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9407       AND      pen.sspndd_flag = 'N'
9408       AND      pen.effective_end_date = hr_api.g_eot
9409       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9410       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9411       AND      (
9412                     (    pen.pgm_id = p_pgm_id
9413                      AND p_pgm_id IS NOT NULL)
9414                  OR (    pen.pgm_id IS NULL
9415                      AND p_pgm_id IS NOT NULL))
9416       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9417       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9418       AND      pen.ptip_id = p_ptip_id;
9419     --
9420     -- Gets the enrolment information for the oipl
9421     --
9422     CURSOR c_oipl_enrolment_info IS
9423       SELECT   *
9424       FROM     ben_prtt_enrt_rslt_f pen
9425       WHERE    pen.person_id = p_person_id
9426       AND      pen.business_group_id = p_business_group_id
9427       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9428 --      AND      pen.sspndd_flag = 'N' --CFW
9429       AND      pen.effective_end_date = hr_api.g_eot
9430       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9431       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9432       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9433       AND      (
9434                     (    pen.pgm_id = p_pgm_id
9435                      AND p_pgm_id IS NOT NULL)
9436                  OR (    pen.pgm_id IS NULL
9437                      AND p_pgm_id IS NOT NULL))
9438       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9439       AND      pen.oipl_id = p_oipl_id;
9440     --
9441     -- Gets the enrolment information for the pl
9442     --
9443     CURSOR c_pl_enrolment_info IS
9444       SELECT   *
9445       FROM     ben_prtt_enrt_rslt_f pen
9446       WHERE    pen.person_id = p_person_id
9447       AND      pen.business_group_id = p_business_group_id
9448       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9449       AND      pen.sspndd_flag = 'N'
9450       AND      pen.effective_end_date = hr_api.g_eot
9451       AND      l_effective_date_1 < pen.enrt_cvg_thru_dt
9452       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9453       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9454       AND      (
9455                     (    pen.pgm_id = p_pgm_id
9456                      AND p_pgm_id IS NOT NULL)
9457                  OR (    pen.pgm_id IS NULL
9458                      AND p_pgm_id IS NOT NULL))
9459       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP')
9460       AND      pen.pl_id = p_pl_id;
9461     --
9462     -- Gets the enrolment information for the opt
9463     --
9464     CURSOR c_opt_enrolment_info IS
9465       SELECT   pen.*
9466       FROM     ben_prtt_enrt_rslt_f pen, ben_pl_f pl, ben_oipl_f oipl
9467       WHERE    pen.person_id = p_person_id
9468       AND      pen.business_group_id = p_business_group_id
9469       AND      pen.effective_end_date = hr_api.g_eot
9470       AND      l_effective_date_1 BETWEEN pen.enrt_cvg_strt_dt
9471                AND pen.enrt_cvg_thru_dt
9472       AND      pl.pl_id = pen.pl_id
9473       and      pen.oipl_id  = p_oipl_id       /* bug 1527086 */
9474       AND      pl.business_group_id = p_business_group_id
9475       AND      pl.pl_typ_id = p_pl_typ_id
9476       AND      oipl.pl_id = pl.pl_id
9477       AND      oipl.opt_id = p_opt_id
9478       AND      p_effective_date BETWEEN pl.effective_start_date
9479                    AND pl.effective_end_date
9480       AND      p_effective_date BETWEEN oipl.effective_start_date
9481                    AND oipl.effective_end_date
9482       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9483       AND      pen.sspndd_flag = 'N'
9484       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9485       AND      oipl.business_group_id = p_business_group_id
9486       AND      pen.prtt_enrt_rslt_id <> p_prtt_enrt_rslt_id
9487       AND      (
9488                     (    pen.pgm_id = p_pgm_id
9489                      AND p_pgm_id IS NOT NULL)
9490                  OR (    pen.pgm_id IS NULL
9491                      AND p_pgm_id IS NOT NULL))
9492       AND      pen.comp_lvl_cd NOT IN ('PLANFC', 'PLANIMP');
9493 
9494 
9495 
9496   BEGIN
9497     IF p_level = 'PL' THEN
9498       OPEN c_pl_enrolment_info;
9499       FETCH c_pl_enrolment_info INTO p_pen_rec;
9500       CLOSE c_pl_enrolment_info;
9501     ELSIF p_level = 'OPT' THEN
9502       OPEN c_opt_enrolment_info;
9503       FETCH c_opt_enrolment_info INTO p_pen_rec;
9504       CLOSE c_opt_enrolment_info;
9505     ELSIF p_level = 'OIPL' THEN
9506       OPEN c_oipl_enrolment_info;
9507       FETCH c_oipl_enrolment_info INTO p_pen_rec;
9508       CLOSE c_oipl_enrolment_info;
9509     ELSIF p_level = 'PTIP' THEN
9510       OPEN c_ptip_enrolment_info;
9511       FETCH c_ptip_enrolment_info INTO p_pen_rec;
9512       CLOSE c_ptip_enrolment_info;
9513     END IF;
9514   exception
9515     --
9516     when others then
9517       --
9518       p_pen_rec := null;
9519       raise;
9520       --
9521   END find_enrt_at_same_level;
9522 --
9523 procedure update_defaults
9524   (p_run_mode               in     varchar2
9525   ,p_business_group_id      in     number
9526   ,p_effective_date         in     date
9527   ,p_lf_evt_ocrd_dt         in     date default null
9528   ,p_ler_id                 in     number
9529   ,p_person_id              in     number
9530   ,p_per_in_ler_id          in     number
9531   )
9532 IS
9533   --
9534   l_oipl_id_va       benutils.g_number_table := benutils.g_number_table();
9535   l_pl_id_va         benutils.g_number_table := benutils.g_number_table();
9536   l_pgm_id_va        benutils.g_number_table := benutils.g_number_table();
9537   l_ptip_id_va       benutils.g_number_table := benutils.g_number_table();
9538   l_plip_id_va       benutils.g_number_table := benutils.g_number_table();
9539   l_epe_dflt_flag_va benutils.g_v2_30_table := benutils.g_v2_30_table();
9540   l_ELCTBL_FLAG_va   benutils.g_v2_30_table := benutils.g_v2_30_table();
9541   l_epe_id_va        benutils.g_number_table := benutils.g_number_table();
9542   l_epe_ovn_va       benutils.g_number_table := benutils.g_number_table();
9543   --
9544   l_prevepo_rec      ben_derive_part_and_rate_facts.g_cache_structure;
9545   l_prevpep_rec      ben_derive_part_and_rate_facts.g_cache_structure;
9546   --
9547   l_rec_assignment_id number;
9548   l_rec_organization_id number;
9549   l_dflt_flag      varchar2(30);
9550   l_use_dflt_flag  varchar2(30);
9551   l_oipl_rec ben_oipl_f%rowtype;
9552   l_empty_oipl ben_oipl_f%rowtype;
9553   l_plan_rec ben_pl_f%rowtype;
9554   l_pgm_rec  ben_pgm_f%rowtype;
9555   l_empty_pgm  ben_pgm_f%rowtype;
9556   l_plip_rec  ben_plip_f%rowtype;
9557   l_empty_plip  ben_plip_f%rowtype;
9558   l_ptip_rec  ben_ptip_f%rowtype;
9559   l_empty_ptip  ben_ptip_f%rowtype;
9560   l_use_dflt_enrt_cd varchar2(30);
9561   l_use_dflt_enrt_rl varchar2(30);
9562   l_reinstt_flag varchar2(30);
9563   l_dflt_level varchar2(30);
9564   l_lf_evt_ocrd_dt date;
9565   l_lf_evt_ocrd_dt_1 date;
9566   l_effective_date_1 date;
9567   l_ler_dflt_flag varchar2(30):=null;
9568   l_proc         VARCHAR2(80)       := g_package || '.update_defaults';
9569   --
9570   -- Choice population
9571   --   Auto enrollments are never defaulted.
9572   --
9573   cursor c_choices
9574     (c_lf_evt_ocrd_dt date
9575     ,c_per_in_ler_id  number
9576     )
9577   is
9578   select epe.oipl_id,
9579          epe.pl_id,
9580          epe.pgm_id,
9581          epe.ptip_id,
9582          epe.plip_id,
9583          epe.dflt_flag,
9584          epe.ELCTBL_FLAG,
9585          epe.ELIG_PER_ELCTBL_CHC_ID,
9586          epe.OBJECT_VERSION_NUMBER
9587   from   ben_elig_per_elctbl_chc epe,
9588 /*
9589          ben_per_in_ler pil,
9590 */
9591          ben_pl_f pln
9592   where  epe.auto_enrt_flag = 'N'
9593   and    epe.per_in_ler_id  = c_per_in_ler_id
9594 /*
9595     and  pil.person_id = p_person_id
9596     and  pil.per_in_ler_id = epe.per_in_ler_id
9597     and  pil.per_in_ler_stat_cd = 'STRTD'
9598 */
9599     and  pln.pl_id=epe.pl_id
9600     and  c_lf_evt_ocrd_dt
9601       between pln.effective_start_date and pln.effective_end_date
9602     and  nvl(pln.imptd_incm_calc_cd,'x') NOT IN ('PRTT', 'DPNT', 'SPS')
9603     and  invk_flx_cr_pl_flag='N'
9604     and  (epe.oipl_id is not null or
9605           not exists
9606             (select null
9607              from   ben_oipl_f oipl
9608              where  c_lf_evt_ocrd_dt
9609                between oipl.effective_start_date and oipl.effective_end_date
9610              and oipl.pl_id=epe.pl_id
9611             )
9612          );
9613   --
9614   -- Gets all information on the plip which is needed
9615   --
9616   CURSOR c_plip_info(p_pl_id number,p_pgm_id number) IS
9617       SELECT   bpf.dflt_flag
9618       FROM     ben_plip_f bpf
9619       WHERE    bpf.pl_id = p_pl_id
9620       AND      bpf.pgm_id = p_pgm_id
9621       AND      bpf.business_group_id = p_business_group_id
9622       AND      l_lf_evt_ocrd_dt BETWEEN bpf.effective_start_date
9623                    AND bpf.effective_end_date;
9624   CURSOR c_asg IS
9625       SELECT   asg.assignment_id,
9626                asg.organization_id
9627       FROM     per_all_assignments_f asg
9628       WHERE    asg.person_id = p_person_id
9629       and      asg.assignment_type <> 'C'
9630       AND      asg.primary_flag =  decode(p_run_mode, 'I',asg.primary_flag,'Y')  -- iRec
9631       AND      l_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
9632                    AND asg.effective_end_date
9633   ;
9634   l_new_elctbl_flag              VARCHAR2(30)                 := 'Y';
9635   l_tco_chg_enrt_cd              VARCHAR2(30)                 := 'CPOO';
9636   l_previous_eligibility         VARCHAR2(30);
9637   l_pl_enrt_cd                   VARCHAR2(30);
9638   l_crnt_enrt_cvg_strt_dt        DATE;
9639   l_ler_enrt_prclds_chg_flag     VARCHAR2(30);
9640   l_ler_stl_elig_cant_chg_flag   VARCHAR2(30);
9641   l_pl_enrt_rl                   NUMBER;
9642   l_dpnt_cvrd_flag               VARCHAR2(1)                  := 'N';
9643   l_crnt_erlst_deenrt_dt         date;
9644   l_prtt_enrt_rslt_id            number;
9645   l_enrt_ovridn_flag             varchar2(30);
9646   l_enrt_ovrid_thru_dt           date;
9647   l_ler_chg_found_flag           varchar2(30);
9648   l_ler_chg_oipl_found_flag      varchar2(30);
9649   --
9650   l_ler_enrt_cd                  varchar2(30);
9651   l_ler_enrt_rl                  number;
9652   l_ler_auto_enrt_rl             number;
9653   l_ler_enrt_mthd_cd             varchar2(30);
9654   l_oipl_auto_enrt_flag          varchar2(30);
9655   l_pl_enrt_mthd_cd              varchar2(30);
9656   l_pl_auto_enrt_rl              number;
9657   --
9658   l_oipl_id                      number;
9659   l_pl_id                        number;
9660   l_pgm_id                       number;
9661   l_ptip_id                      number;
9662   l_plip_id                      number;
9663   l_epe_dflt_flag                varchar2(30);
9664   l_ELCTBL_FLAG                  varchar2(30);
9665   l_epe_id                       number;
9666   l_epe_ovn                      number;
9667   --
9668     -- Gets the enrolment information for this plan
9669     --
9670     --
9671     CURSOR c_plan_enrolment_info IS
9672       SELECT   pen.enrt_cvg_strt_dt,
9673                pen.erlst_deenrt_dt,
9674                pen.prtt_enrt_rslt_id,
9675                pen.enrt_ovridn_flag,
9676                pen.enrt_ovrid_thru_dt
9677       FROM     ben_prtt_enrt_rslt_f pen
9678       WHERE    pen.person_id = p_person_id
9679       AND      pen.business_group_id = p_business_group_id
9680 --      AND      pen.sspndd_flag = 'N' --CFW
9681       AND      (pen.sspndd_flag = 'N' --CFW
9682                  OR (pen.sspndd_flag = 'Y' and
9683                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9684                     )
9685                )
9686       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9687       AND      pen.effective_end_date = hr_api.g_eot
9688       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9689       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9690       AND      l_plan_rec.pl_id = pen.pl_id
9691       AND      (
9692                     (    pen.pgm_id = l_pgm_rec.pgm_id
9693                      AND l_pgm_rec.pgm_id IS NOT NULL)
9694                  OR (    pen.pgm_id IS NULL
9695                      AND l_pgm_rec.pgm_id IS NULL));
9696     --
9697     -- Gets the enrolment information for this oipl
9698     --
9699     --
9700     CURSOR c_oipl_enrolment_info IS
9701       SELECT   pen.enrt_cvg_strt_dt,
9702                pen.erlst_deenrt_dt,
9703                pen.prtt_enrt_rslt_id,
9704                pen.enrt_ovridn_flag,
9705                pen.enrt_ovrid_thru_dt
9706       FROM     ben_prtt_enrt_rslt_f pen
9707       WHERE    pen.person_id = p_person_id
9708       AND      pen.business_group_id = p_business_group_id
9709 --      AND      pen.sspndd_flag = 'N' --CFW
9710       AND      (pen.sspndd_flag = 'N' --CFW
9711                  OR (pen.sspndd_flag = 'Y' and
9712                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9713                     )
9714                )
9715       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9716       AND      pen.effective_end_date = hr_api.g_eot
9717       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9718       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9719       AND      l_oipl_rec.oipl_id = pen.oipl_id
9720       AND      (
9721                     (    pen.pgm_id = l_pgm_rec.pgm_id
9722                      AND l_pgm_rec.pgm_id IS NOT NULL)
9723                  OR (    pen.pgm_id IS NULL
9724                      AND l_pgm_rec.pgm_id IS NULL));
9725     --
9726     -- Gets the coverage information for this plan
9727     --
9728     --
9729     CURSOR c_plan_cvg_info IS
9730       SELECT   'Y'
9731       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
9732       WHERE    pdp.dpnt_person_id = p_person_id
9733       AND      pdp.effective_end_date = hr_api.g_eot
9734       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
9735       AND      pdp.business_group_id = p_business_group_id
9736       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
9737       AND      pen.business_group_id = p_business_group_id
9738       AND      pen.sspndd_flag = 'N'
9739       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9740       AND      pen.effective_end_date = hr_api.g_eot
9741       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9742       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9743       AND      l_plan_rec.pl_id = pen.pl_id
9744       AND      (
9745                     (    pen.pgm_id = l_pgm_rec.pgm_id
9746                      AND l_pgm_rec.pgm_id IS NOT NULL)
9747                  OR (    pen.pgm_id IS NULL
9748                      AND l_pgm_rec.pgm_id IS NULL));
9749     --
9750     -- Gets the coverage information for this oipl
9751     --
9752     --
9753     CURSOR c_oipl_cvg_info IS
9754       SELECT   'Y'
9755       FROM     ben_prtt_enrt_rslt_f pen, ben_elig_cvrd_dpnt_f pdp
9756       WHERE    pdp.dpnt_person_id = p_person_id
9757       AND      pdp.effective_end_date = hr_api.g_eot
9758       AND      l_lf_evt_ocrd_dt_1 BETWEEN pdp.cvg_strt_dt AND pdp.cvg_thru_dt
9759       AND      pdp.business_group_id = p_business_group_id
9760       AND      pdp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
9761       AND      pen.business_group_id = p_business_group_id
9762 --      AND      pen.sspndd_flag = 'N'
9763       AND      (pen.sspndd_flag = 'N' --CFW
9764                  OR (pen.sspndd_flag = 'Y' and
9765                      pen.enrt_cvg_thru_dt = hr_api.g_eot
9766                     )
9767                )
9768       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9769       AND      pen.effective_end_date = hr_api.g_eot
9770       AND      l_lf_evt_ocrd_dt_1 <= pen.enrt_cvg_thru_dt
9771       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
9772       AND      l_oipl_rec.oipl_id = pen.oipl_id
9773       AND      (
9774                     (    pen.pgm_id = l_pgm_rec.pgm_id
9775                      AND l_pgm_rec.pgm_id IS NOT NULL)
9776                  OR (    pen.pgm_id IS NULL
9777                      AND l_pgm_rec.pgm_id IS NULL));
9778     -- Determines the previous eligibility for an option
9779     --
9780     CURSOR c_previous_elig_for_option IS
9781       SELECT   epo.elig_flag
9782       FROM     ben_elig_per_f ep, ben_elig_per_opt_f epo, ben_per_in_ler pil
9783       WHERE    ep.person_id = p_person_id
9784       AND      ep.pl_id = l_plan_rec.pl_id
9785       AND      (
9786                     (    ep.pgm_id = l_pgm_rec.pgm_id
9787                      AND l_pgm_rec.pgm_id IS NOT NULL)
9788                  OR (    ep.pgm_id IS NULL
9789                      AND l_pgm_rec.pgm_id IS NULL))
9790       AND      ep.business_group_id = p_business_group_id
9791       AND      p_effective_date - 1 BETWEEN ep.effective_start_date
9792                    AND ep.effective_end_date
9793       AND      ep.elig_per_id = epo.elig_per_id
9794       AND      epo.opt_id = l_oipl_rec.opt_id
9795       AND      epo.business_group_id = p_business_group_id
9796       AND      l_effective_date_1 BETWEEN epo.effective_start_date
9797                    AND epo.effective_end_date
9798       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
9799       AND      pil.business_group_id (+) = epo.business_group_id
9800       AND      (
9801                     pil.per_in_ler_stat_cd NOT IN
9802                                         (
9803                                           'VOIDD',
9804                                           'BCKDT')       -- found row condition
9805                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
9806     -- Determines the previous eligibility for a plan
9807     --
9808     CURSOR c_previous_elig_for_plan IS
9809       SELECT   pep.elig_flag
9810       FROM     ben_elig_per_f pep, ben_per_in_ler pil
9811       WHERE    pep.person_id = p_person_id
9812       AND      pep.pl_id = l_plan_rec.pl_id
9813       AND      (
9814                     (    pep.pgm_id = l_pgm_rec.pgm_id
9815                      AND l_pgm_rec.pgm_id IS NOT NULL)
9816                  OR (    pep.pgm_id IS NULL
9817                      AND l_pgm_rec.pgm_id IS NULL))
9818       AND      pep.business_group_id = p_business_group_id
9819       AND      l_effective_date_1 BETWEEN pep.effective_start_date
9820                    AND pep.effective_end_date
9821       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
9822       AND      pil.business_group_id (+) = pep.business_group_id
9823       AND      (
9824                     pil.per_in_ler_stat_cd NOT IN
9825                                         (
9826                                           'VOIDD',
9827                                           'BCKDT')       -- found row condition
9828                  OR pil.per_in_ler_stat_cd IS NULL);    -- outer join condition
9829   --
9830   cursor c_enrt_bnft (p_elctbl_chc_id number) is
9831     select enb.enrt_bnft_id,
9832            enb.object_version_number
9833     from   ben_enrt_bnft enb
9834     where  enb.elig_per_elctbl_chc_id = p_elctbl_chc_id
9835     and    enb.dflt_flag = 'N'
9836     and    (exists  (select null from
9837                     ben_enrt_bnft enb2
9838                     where enb2.enrt_bnft_id = enb.enrt_bnft_id
9839                     and   enb2.dflt_val = enb2.val)
9840            or enb.cvg_mlt_cd not in ('FLRNG', 'CLRNG','FLPCLRNG','CLPFLRNG'));
9841   l_enrt_bnft    c_enrt_bnft%rowtype;
9842   l_enrt_cd_level varchar2(30) ;
9843   -- 5092244
9844   CURSOR c_elig_dpnt (v_epe_id NUMBER)
9845    IS
9846       SELECT egd.elig_dpnt_id, egd.object_version_number
9847         FROM ben_elig_dpnt egd, ben_per_in_ler pil
9848        WHERE elig_per_elctbl_chc_id = v_epe_id
9849          AND pil.per_in_ler_id = egd.per_in_ler_id
9850          AND pil.per_in_ler_stat_cd = 'STRTD';
9851 
9852    l_elig_dpnt   c_elig_dpnt%ROWTYPE;
9853    l_next_row    NUMBER;
9854   --
9855 begin
9856   --
9857   g_debug := hr_utility.debug_enabled;
9858   --
9859 if g_debug then
9860   hr_utility.set_location('Entering: '||l_proc,10);
9861   end if;
9862   --l_effective_date_1:=p_effective_date-1;
9863   --Bug#2328029
9864   l_effective_date_1:=
9865            least(p_effective_date, nvl(p_lf_evt_ocrd_dt,p_effective_date)) -1;
9866   --
9867   if p_lf_evt_ocrd_dt is not null then
9868     l_lf_evt_ocrd_dt:=p_lf_evt_ocrd_dt;
9869   else
9870     l_lf_evt_ocrd_dt:=p_effective_date;
9871   end if;
9872   l_lf_evt_ocrd_dt_1:=l_lf_evt_ocrd_dt-1;
9873   --
9874   open c_choices
9875     (c_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
9876     ,c_per_in_ler_id  => p_per_in_ler_id
9877     );
9878   fetch c_choices BULK COLLECT INTO l_oipl_id_va,
9879                                     l_pl_id_va,
9880                                     l_pgm_id_va,
9881                                     l_ptip_id_va,
9882                                     l_plip_id_va,
9883                                     l_epe_dflt_flag_va,
9884                                     l_ELCTBL_FLAG_va,
9885                                     l_epe_id_va,
9886                                     l_epe_ovn_va;
9887   close c_choices;
9888   --
9889   if l_epe_id_va.count > 0 then
9890     --
9891     for epeele_num in l_epe_id_va.first..l_epe_id_va.last
9892     loop
9893       --
9894       l_oipl_id        := l_oipl_id_va(epeele_num);
9895       l_pl_id          := l_pl_id_va(epeele_num);
9896       l_pgm_id         := l_pgm_id_va(epeele_num);
9897       l_ptip_id        := l_ptip_id_va(epeele_num);
9898       l_plip_id        := l_plip_id_va(epeele_num);
9899       l_epe_dflt_flag  := l_epe_dflt_flag_va(epeele_num);
9900       l_ELCTBL_FLAG    := l_ELCTBL_FLAG_va(epeele_num);
9901       l_epe_id         := l_epe_id_va(epeele_num);
9902       l_epe_ovn        := l_epe_ovn_va(epeele_num);
9903       --
9904 /*
9905   for l_rec in c_choices
9906     (c_lf_evt_ocrd_dt => p_lf_evt_ocrd_dt
9907     ,c_per_in_ler_id  => p_per_in_ler_id
9908     )
9909   loop
9910 */
9911     if g_debug then
9912       hr_utility.set_location(l_proc||' ST c_choices loop: ',10);
9913     end if;
9914       --
9915       -- init flags
9916       --
9917       l_dflt_flag:='N';
9918       l_use_dflt_flag:='N';
9919       --
9920       -- Get option information if an oipl_id is passed,
9921       -- need to do this before getting oipl eligibility.
9922       --
9923       IF (l_oipl_id IS NOT NULL) THEN
9924         --
9925         -- get oipl information
9926         --
9927         ben_comp_object.get_object(p_oipl_id => l_oipl_id, p_rec =>l_oipl_rec);
9928         l_oipl_auto_enrt_flag:=l_oipl_rec.auto_enrt_flag;
9929       else
9930         l_oipl_rec:=l_empty_oipl;
9931       end if;
9932       --
9933       -- get plan cache row
9934       --
9935       ben_comp_object.get_object(p_pl_id => l_pl_id, p_rec => l_plan_rec);
9936       l_pl_enrt_mthd_cd :=          l_plan_rec.enrt_mthd_cd;
9937       l_pl_auto_enrt_rl :=          l_plan_rec.auto_enrt_mthd_rl;
9938       --
9939       -- Get pgm cache row if needed
9940       --
9941       IF l_pgm_id IS NOT NULL THEN
9942         ben_comp_object.get_object(p_pgm_id => l_pgm_id, p_rec => l_pgm_rec);
9943       else
9944         l_pgm_rec:=l_empty_pgm;
9945       END IF;
9946       --
9947       -- Get ptip cache row if needed
9948       --
9949       IF l_ptip_id IS NOT NULL THEN
9950         ben_comp_object.get_object(p_ptip_id => l_ptip_id,
9951                                    p_rec => l_ptip_rec);
9952       else
9953         l_ptip_rec:=l_empty_ptip;
9954       END IF;
9955       --
9956       -- Get plip cache row if needed
9957       --
9958       IF l_pgm_id IS NOT NULL THEN
9959         ben_comp_object.get_object(p_plip_id => l_plip_id,
9960                                    p_rec => l_plip_rec);
9961       else
9962         l_plip_rec:=l_empty_plip;
9963       END IF;
9964       --
9965       -- get the dflt_enrt_cd/rule
9966       --
9967       if g_debug then
9968       hr_utility.set_location('DDEC: '||l_proc,10);
9969       end if;
9970       determine_dflt_enrt_cd
9971         (p_oipl_id           => l_oipl_id
9972         ,p_oipl_rec          => l_oipl_rec
9973         ,p_plip_id           => l_plip_id
9974         ,p_plip_rec          => l_plip_rec
9975         ,p_pl_id             => l_pl_id
9976         ,p_pl_rec            => l_plan_rec
9977         ,p_ptip_id           => l_ptip_id
9978         ,p_ptip_rec          => l_ptip_rec
9979         ,p_pgm_id            => l_pgm_id
9980         ,p_pgm_rec           => l_pgm_rec
9981         ,p_ler_id            => p_ler_id
9982         ,p_dflt_enrt_cd      => l_use_dflt_enrt_cd
9983         ,p_dflt_enrt_rl      => l_use_dflt_enrt_rl
9984         ,p_business_group_id => p_business_group_id
9985         ,p_effective_date    => l_lf_evt_ocrd_dt -- Bug 2404008 p_effective_date
9986         ,p_level             => l_dflt_level
9987         ,p_ler_dflt_flag     => l_ler_dflt_flag
9988       );
9989       --hr_utility.set_location('After call to determine_dflt_enrt_cd ' , 5553);
9990       --hr_utility.set_location('l_pgm_id '||l_pgm_id,5554);
9991       if g_debug then
9992       hr_utility.set_location('l_oipl_id '||l_oipl_id ,5555);
9993       hr_utility.set_location('l_pl_id '||l_pl_id ,5556);
9994       --hr_utility.set_location('l_dflt_flag='||l_dflt_flag,5557);
9995       hr_utility.set_location('l_ler_dflt_flag '||l_ler_dflt_flag ,5555);
9996       hr_utility.set_location(' l_epe_dflt_flag='|| l_epe_dflt_flag,5558);
9997       hr_utility.set_location(' l_dflt_level ='|| l_dflt_level ,5558);
9998       end if;
9999       --hr_utility.set_location(' ---- ' ,5559);
10000       --
10001       -- Set the values for the dflt_flag
10002       --
10003       --
10004       l_use_dflt_flag :=            NULL;
10005       IF l_ler_dflt_flag is not null and
10006          (l_dflt_level='LER_OIPL' or
10007           l_oipl_id is null) then
10008         l_use_dflt_flag:=l_ler_dflt_flag;
10009       end if;
10010       --
10011       -- oipl level default code/flag
10012       --
10013       IF l_oipl_id IS NOT NULL THEN
10014         IF l_use_dflt_flag IS NULL THEN
10015           --
10016           -- use oipl level flag
10017           --
10018           l_use_dflt_flag :=  l_oipl_rec.dflt_flag;
10019         END IF;
10020       END IF;
10021       --
10022       -- plip level default code/flag
10023       --
10024       IF l_plip_id IS NOT NULL THEN
10025         IF l_use_dflt_flag IS NULL THEN
10026           --
10027           -- Find the plip and get its needed attributes.
10028           --
10029           OPEN c_plip_info(l_pl_id,l_pgm_id);
10030           --
10031           FETCH c_plip_info INTO l_use_dflt_flag;
10032           IF c_plip_info%NOTFOUND THEN
10033             --
10034             fnd_message.set_name('BEN', 'BEN_91461_PLIP_MISSING');
10035             fnd_message.set_token('PROC', l_proc);
10036             fnd_message.set_token('PGM_ID', TO_CHAR(l_pgm_id));
10037             fnd_message.set_token('PL_ID', TO_CHAR(l_pl_id));
10038             fnd_message.set_token('BG_ID', TO_CHAR(p_business_group_id));
10039             RAISE ben_manage_life_events.g_record_error;
10040           --
10041           END IF;
10042           --
10043           CLOSE c_plip_info;
10044         END IF;
10045       END IF;
10046       --
10047       -- If no default flag is set then make it not a default.
10048       --
10049       IF l_use_dflt_flag IS NULL THEN
10050         --
10051         l_use_dflt_flag :=  'N';
10052       --
10053       END IF;
10054       OPEN c_asg;
10055       FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
10056       IF c_asg%NOTFOUND THEN
10057           CLOSE c_asg;
10058 	  if g_debug then
10059           hr_utility.set_location('error', 20);
10060 	  end if;
10061           fnd_message.set_name('BEN', 'BEN_92106_PRTT_NO_ASGN');
10062           fnd_message.set_token('PROC', l_proc);
10063           fnd_message.set_token('PERSON_ID', TO_CHAR(p_person_id));
10064           fnd_message.set_token('LF_EVT_OCRD_DT', TO_CHAR(p_lf_evt_ocrd_dt));
10065           fnd_message.set_token('EFFECTIVE_DATE', TO_CHAR(p_effective_date));
10066           RAISE ben_manage_life_events.g_record_error;
10067       END IF;
10068       CLOSE c_asg;
10069       --hr_utility.set_location('Before call to l_use_dflt_flag ',5550);
10070       if g_debug then
10071       hr_utility.set_location(' l_use_dflt_flag ',5550);
10072       hr_utility.set_location(' l_use_dflt_enrt_cd ',5550);
10073       end if;
10074       determine_dflt_flag(
10075          l_use_dflt_flag,
10076          l_use_dflt_enrt_cd,
10077          null, --not used
10078          null, --not used
10079          l_use_dflt_enrt_rl,
10080          l_oipl_id,
10081          l_pl_id,
10082          l_pgm_id,
10083          p_effective_date,
10084          p_lf_evt_ocrd_dt,
10085          p_ler_id,
10086          l_oipl_rec.opt_id,
10087          l_plan_rec.pl_typ_id,
10088          l_ptip_id,
10089          p_person_id,
10090          p_business_group_id,
10091          l_rec_assignment_id,
10092          l_dflt_flag,
10093          l_reinstt_flag,
10094 	 -- added bug 5644451
10095 	 l_dflt_level,
10096 	 p_run_mode           /* iRec : Added p_run_mode */
10097       );
10098       --
10099       if g_debug then
10100       hr_utility.set_location(' l_dflt_flag '|| l_dflt_flag ,5550);
10101       end if;
10102       IF (l_dflt_flag = 'DEFER') THEN
10103         --
10104         l_dflt_flag :=  l_use_dflt_flag;
10105       --
10106       END IF;
10107       --hr_utility.set_location('After call to determine_dflt_flag ' , 5553);
10108       --hr_utility.set_location('l_pgm_id '||l_pgm_id,5554);
10109       --hr_utility.set_location('l_oipl_id '||l_oipl_id ,5555);
10110       if g_debug then
10111       hr_utility.set_location('l_pl_id '||l_pl_id ,5556);
10112       hr_utility.set_location('l_dflt_flag='||l_dflt_flag,5557);
10113       hr_utility.set_location(' l_epe_dflt_flag='|| l_epe_dflt_flag,5558);
10114       end if;
10115       --
10116       -- Done with default flag now see if electable flag should be changed
10117       --
10118       -- Determine if the person is currently enrolled and if so
10119       -- determine the coverage start date.
10120       --
10121       if ( l_ELCTBL_FLAG='Y') then
10122         IF (l_oipl_id IS NULL) THEN
10123           --
10124           OPEN c_plan_enrolment_info;
10125           --
10126           FETCH c_plan_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
10127                                            l_crnt_erlst_deenrt_dt,
10128                                            l_prtt_enrt_rslt_id,
10129                                            l_enrt_ovridn_flag,
10130                                            l_enrt_ovrid_thru_dt;
10131           --
10132           IF c_plan_enrolment_info%NOTFOUND THEN
10133             --
10134             l_crnt_enrt_cvg_strt_dt :=  NULL;
10135             --
10136             --  Check if person is a covered dependent - COBRA.
10137             --
10138             IF l_pgm_id IS NOT NULL THEN
10139               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
10140                 OPEN c_plan_cvg_info;
10141                 FETCH c_plan_cvg_info INTO l_dpnt_cvrd_flag;
10142                 CLOSE c_plan_cvg_info;
10143               END IF;
10144             END IF;
10145           --
10146           END IF;
10147           --
10148           CLOSE c_plan_enrolment_info;
10149 	  if g_debug then
10150           hr_utility.set_location('close c_PEI: ' || l_proc, 10);
10151 	  end if;
10152         --
10153         ELSE
10154           --
10155           OPEN c_oipl_enrolment_info;
10156           --
10157           FETCH c_oipl_enrolment_info INTO l_crnt_enrt_cvg_strt_dt,
10158                                            l_crnt_erlst_deenrt_dt,
10159                                            l_prtt_enrt_rslt_id,
10160                                            l_enrt_ovridn_flag,
10161                                            l_enrt_ovrid_thru_dt;
10162           --
10163           IF c_oipl_enrolment_info%NOTFOUND THEN
10164             --
10165             l_crnt_enrt_cvg_strt_dt :=  NULL;
10166             --
10167             --  Check if person is a covered dependent - COBRA.
10168             --
10169             IF l_pgm_id IS NOT NULL THEN
10170               IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
10171                 OPEN c_oipl_cvg_info;
10172                 FETCH c_oipl_cvg_info INTO l_dpnt_cvrd_flag;
10173                 CLOSE c_oipl_cvg_info;
10174               END IF;
10175             END IF;
10176           --
10177           END IF;
10178           --
10179           CLOSE c_oipl_enrolment_info;
10180 	  if g_debug then
10181           hr_utility.set_location('close c_OIEI: ' || l_proc, 10);
10182 	  end if;
10183         --
10184         END IF;
10185 	if g_debug then
10186         hr_utility.set_location('determine prev elig', 10);
10187 	end if;
10188         --
10189         -- Bug 2677804 We need to see the override case here.
10190         IF ( l_enrt_ovridn_flag = 'Y' AND l_enrt_ovrid_thru_dt >= l_lf_evt_ocrd_dt)  THEN
10191            l_enrt_ovridn_flag :=  'Y';
10192         ELSE
10193            l_enrt_ovridn_flag :=  'N';
10194         END IF;
10195         --
10196         -- Determine if the person was previously eligible for this comp object.
10197         --
10198         IF (l_oipl_id IS NULL) THEN
10199           --
10200           ben_pep_cache.get_pilpep_dets
10201             (p_person_id         => p_person_id
10202             ,p_business_group_id => p_business_group_id
10203             ,p_effective_date    => l_effective_date_1
10204             ,p_pgm_id            => l_pgm_rec.pgm_id
10205             ,p_pl_id             => l_plan_rec.pl_id
10206             ,p_plip_id           => null
10207             ,p_ptip_id           => null
10208             ,p_inst_row          => l_prevpep_rec
10209             );
10210           --
10211           if l_prevpep_rec.elig_flag is null
10212           then
10213             --
10214             l_previous_eligibility := 'N';
10215             --
10216           else
10217             --
10218             l_previous_eligibility := l_prevpep_rec.elig_flag;
10219             --
10220           end if;
10221           --
10222 	  if g_debug then
10223           hr_utility.set_location('close c_PEFP: ' || l_proc, 10);
10224 	  end if;
10225         --
10226         ELSE
10227           --
10228           ben_pep_cache.get_pilepo_dets
10229             (p_person_id         => p_person_id
10230             ,p_business_group_id => p_business_group_id
10231             ,p_effective_date    => l_effective_date_1 --p_effective_date
10232             ,p_pgm_id            => l_pgm_rec.pgm_id
10233             ,p_pl_id             => l_plan_rec.pl_id
10234             ,p_opt_id            => l_oipl_rec.opt_id
10235             --
10236             ,p_inst_row          => l_prevepo_rec
10237             );
10238           --
10239           if l_prevepo_rec.elig_flag is null
10240           then
10241             --
10242             l_previous_eligibility := 'N';
10243             --
10244           else
10245             --
10246             l_previous_eligibility := l_prevepo_rec.elig_flag;
10247             --
10248           end if;
10249           --
10250 	  if g_debug then
10251           hr_utility.set_location('close c_PEFO: ' || l_proc, 10);
10252 	  end if;
10253           --
10254         END IF;
10255         l_pl_enrt_cd :=               l_plan_rec.enrt_cd;
10256         l_pl_enrt_rl :=               l_plan_rec.enrt_rl;
10257         --
10258         -- Determine if the compensation object requires or allows
10259         -- an election change If life event mode
10260         --
10261 	if g_debug then
10262         hr_utility.set_location('ler change stuff', 20);
10263 	end if;
10264         l_ler_chg_found_flag :=       'N';
10265         l_ler_chg_oipl_found_flag :=  'N';
10266         --
10267         -- See if there is a life event reason to change
10268         --
10269 	if g_debug then
10270         hr_utility.set_location('ler change stuff not null stuff', 20);
10271         hr_utility.set_location(' Op c_lce_info: ' || l_proc, 10);
10272 	end if;
10273         --
10274         determine_ben_settings(
10275           p_pl_id                     => l_pl_id,
10276           p_ler_id                    => p_ler_id,
10277           p_lf_evt_ocrd_dt            => l_lf_evt_ocrd_dt,
10278           p_ptip_id                   => l_ptip_id,
10279           p_pgm_id                    => l_pgm_id,
10280           p_plip_id                   => l_plip_id,
10281           p_oipl_id                   => l_oipl_id,
10282           p_just_prclds_chg_flag      => FALSE,
10283           p_enrt_cd                   => l_ler_enrt_cd,
10284           p_enrt_rl                   => l_ler_enrt_rl,
10285           p_auto_enrt_mthd_rl         => l_ler_auto_enrt_rl,
10286           p_crnt_enrt_prclds_chg_flag => l_ler_enrt_prclds_chg_flag,
10287           p_dflt_flag                 => l_ler_dflt_flag,
10288           p_enrt_mthd_cd              => l_ler_enrt_mthd_cd,
10289           p_stl_elig_cant_chg_flag    => l_ler_stl_elig_cant_chg_flag,
10290           p_tco_chg_enrt_cd           => l_tco_chg_enrt_cd,
10291           p_ler_chg_oipl_found_flag   => l_ler_chg_oipl_found_flag,
10292           p_ler_chg_found_flag        => l_ler_chg_found_flag,
10293           p_enrt_cd_level             => l_enrt_cd_level);
10294       if g_debug then
10295         hr_utility.set_location(' Cl c_lce_info: ' || l_proc, 10);
10296       end if;
10297         --
10298         -- Determine enrt codes/rules method codes/rules then
10299         -- figure out if electable.
10300         --
10301         -- Initially set to ler_chg values if not null
10302         --
10303         IF l_ler_enrt_cd IS NOT NULL THEN
10304           l_pl_enrt_cd :=  l_ler_enrt_cd;
10305           l_pl_enrt_rl :=  l_ler_enrt_rl;
10306         ELSIF l_oipl_rec.enrt_cd IS NOT NULL THEN
10307           l_pl_enrt_cd :=  l_oipl_rec.enrt_cd;
10308           l_pl_enrt_rl :=  l_oipl_rec.enrt_rl;
10309         END IF;
10310         IF l_oipl_id IS NULL THEN
10311           IF    l_ler_enrt_mthd_cd IS NOT NULL
10312              OR l_ler_auto_enrt_rl IS NOT NULL THEN
10313             l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
10314             l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
10315           END IF;
10316         ELSE
10317           --
10318           -- below, if ler_chg row found then code will always
10319           -- be not null since comes from a decode of the flag.
10320           --
10321           IF l_ler_chg_oipl_found_flag = 'Y' THEN
10322             l_pl_enrt_mthd_cd :=  l_ler_enrt_mthd_cd;
10323             l_pl_auto_enrt_rl :=  l_ler_auto_enrt_rl;
10324             --
10325             IF l_ler_enrt_mthd_cd = 'A' THEN
10326               --
10327               l_oipl_auto_enrt_flag :=  'Y';
10328             --
10329             ELSE
10330               --
10331               l_oipl_auto_enrt_flag :=  'N';
10332             --
10333             END IF;
10334           --
10335           ELSE
10336             IF l_oipl_auto_enrt_flag = 'Y' THEN
10337               l_pl_enrt_mthd_cd :=  'A';
10338             ELSE
10339               l_pl_enrt_mthd_cd :=  'E';
10340             END IF;
10341             l_pl_auto_enrt_rl :=  l_oipl_rec.auto_enrt_mthd_rl;
10342           END IF;
10343         END IF;
10344         --
10345         -- If the ler_chg values were null then now have plan values
10346         --
10347         -- Update if still null with values from above in hierarchy
10348         --
10349         IF     l_pl_enrt_cd IS NULL
10350            AND l_pgm_id IS NOT NULL THEN
10351           l_pl_enrt_cd :=  l_plip_rec.enrt_cd;
10352           l_pl_enrt_rl :=  l_plip_rec.enrt_rl;
10353         END IF;
10354         IF     l_pl_enrt_mthd_cd IS NULL
10355            AND l_pgm_id IS NOT NULL THEN
10356           l_pl_enrt_mthd_cd :=  l_plip_rec.enrt_mthd_cd;
10357           l_pl_auto_enrt_rl :=  l_plip_rec.auto_enrt_mthd_rl;
10358         END IF;
10359         --
10360         -- overlay ptip if value is still null
10361         --
10362         IF     l_pl_enrt_cd IS NULL
10363            AND l_pgm_id IS NOT NULL THEN
10364           l_pl_enrt_cd :=  l_ptip_rec.enrt_cd;
10365           l_pl_enrt_rl :=  l_ptip_rec.enrt_rl;
10366         END IF;
10367         IF     l_pl_enrt_mthd_cd IS NULL
10368            AND l_pgm_id IS NOT NULL THEN
10369           l_pl_enrt_mthd_cd :=  l_ptip_rec.enrt_mthd_cd;
10370           l_pl_auto_enrt_rl :=  l_ptip_rec.auto_enrt_mthd_rl;
10371         END IF;
10372         --
10373         -- get from program level if not at plan or plip or ptip levels
10374         --
10375         IF     l_pl_enrt_cd IS NULL
10376            AND l_pgm_id IS NOT NULL THEN
10377           l_pl_enrt_cd :=  l_pgm_rec.enrt_cd;
10378           l_pl_enrt_rl :=  l_pgm_rec.enrt_rl;
10379         END IF;
10380         IF     l_pl_enrt_mthd_cd IS NULL
10381            AND l_pgm_id IS NOT NULL THEN
10382           l_pl_enrt_mthd_cd :=  l_pgm_rec.enrt_mthd_cd;
10383           l_pl_auto_enrt_rl :=  l_pgm_rec.auto_enrt_mthd_rl;
10384         END IF;
10385 
10386         g_ptip_id :=                  l_ptip_id;
10387   --  hr_utility.set_location('l_previous_eligibility='||l_previous_eligibility,1064);
10388   --  hr_utility.set_location('l_crnt_enrt_cvg_strt_dt='||l_crnt_enrt_cvg_strt_dt,1064);
10389   --  hr_utility.set_location('l_dpnt_cvrd_flag='||l_dpnt_cvrd_flag,1064);
10390   --  hr_utility.set_location('p_person_id='||p_person_id,1064);
10391   --  hr_utility.set_location('p_ler_id='||p_ler_id,1064);
10392   --  hr_utility.set_location('l_pl_enrt_cd='||l_pl_enrt_cd,1064);
10393   --  hr_utility.set_location('l_pl_enrt_rl='||l_pl_enrt_rl,1064);
10394   --  hr_utility.set_location('p_effective_date='||p_effective_date,1064);
10395   --  hr_utility.set_location('p_lf_evt_ocrd_dt='||p_lf_evt_ocrd_dt,1064);
10396   --  hr_utility.set_location('l_ler_enrt_prclds_chg_flag='||l_ler_enrt_prclds_chg_flag,1064);
10397   --  hr_utility.set_location('l_ler_stl_elig_cant_chg_flag='||l_ler_stl_elig_cant_chg_flag,1064);
10398   --  hr_utility.set_location('l_tco_chg_enrt_cd='||l_tco_chg_enrt_cd,1064);
10399   --  hr_utility.set_location('l_pl_id='||l_pl_id,1064);
10400   --  hr_utility.set_location('l_pgm_id='||l_pgm_id,1064);
10401   --  hr_utility.set_location('l_oipl_id='||l_oipl_id,1064);
10402   --  hr_utility.set_location('l_oipl_rec.opt_id='||l_oipl_rec.opt_id,1064);
10403   --  hr_utility.set_location('l_plan_rec.pl_typ_id='||l_plan_rec.pl_typ_id,1064);
10404   --  hr_utility.set_location('p_business_group_id='||p_business_group_id,1064);
10405   --  hr_utility.set_location('l_new_elctbl_flag='||l_new_elctbl_flag,1064);
10406   --  hr_utility.set_location('l_rec_assignment_id='||l_rec_assignment_id,1064);
10407   --      hr_utility.set_location('l_previous_eligibility='||l_previous_eligibility,1064);
10408        if g_debug then
10409         hr_utility.set_location(' Dn Det 1: ' || l_proc, 10);
10410        end if;
10411         -- Bug 2677804
10412         if l_enrt_ovridn_flag = 'Y' then
10413           --
10414 	  if g_debug then
10415           hr_utility.set_location(' Electable Due to Override ' ,123);
10416 	  end if;
10417           l_new_elctbl_flag := 'Y' ;
10418           --
10419         else
10420           -- start 5092244
10421 
10422           IF NVL (l_pl_enrt_cd, '-1') = 'RL'
10423           THEN
10424              ben_determine_dpnt_eligibility.g_egd_table.DELETE;
10425              ben_determine_dpnt_eligibility.g_egd_table :=
10426 			      ben_determine_dpnt_eligibility.g_egd_table_temp;
10427              OPEN c_elig_dpnt (l_epe_id);
10428 	     if g_debug then
10429              hr_utility.set_location('SS Populating g_egd_table',9909);
10430 	     end if;
10431              LOOP
10432 	        FETCH c_elig_dpnt INTO l_elig_dpnt;
10433 	        EXIT WHEN c_elig_dpnt%NOTFOUND;
10434 	        l_next_row :=
10435 		             NVL (ben_determine_dpnt_eligibility.g_egd_table.LAST, 0)
10436 		            + 1;
10437 	        ben_determine_dpnt_eligibility.g_egd_table (l_next_row).object_version_number :=
10438 					        l_elig_dpnt.object_version_number;
10439 	        ben_determine_dpnt_eligibility.g_egd_table (l_next_row).elig_dpnt_id :=
10440 						      l_elig_dpnt.elig_dpnt_id;
10441              END LOOP;
10442 
10443              CLOSE c_elig_dpnt;
10444          END IF;
10445          -- end 5092244
10446           determine_enrolment(
10447             p_previous_eligibility   => l_previous_eligibility,
10448             p_crnt_enrt_cvg_strt_dt  => l_crnt_enrt_cvg_strt_dt,
10449             p_dpnt_cvrd_flag         => l_dpnt_cvrd_flag,
10450             p_person_id              => p_person_id,
10451             p_ler_id                 => p_ler_id,
10452             p_enrt_cd                => l_pl_enrt_cd,
10453             p_enrt_rl                => l_pl_enrt_rl,
10454             p_enrt_mthd_cd           => null,
10455             p_auto_enrt_mthd_rl      => null,
10456             p_effective_date         => p_effective_date,
10457             p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
10458             p_enrt_prclds_chg_flag   => NVL(l_ler_enrt_prclds_chg_flag, 'N'),
10459             p_stl_elig_cant_chg_flag => NVL(l_ler_stl_elig_cant_chg_flag, 'N'),
10460             p_tco_chg_enrt_cd        => NVL(l_tco_chg_enrt_cd, 'CPOO'),
10461             p_pl_id                  => l_pl_id,
10462             p_pgm_id                 => l_pgm_id,
10463             p_oipl_id                => l_oipl_id,
10464             p_opt_id                 => l_oipl_rec.opt_id,
10465             p_pl_typ_id              => l_plan_rec.pl_typ_id,
10466             p_business_group_id      => p_business_group_id,
10467             p_electable_flag         => l_new_elctbl_flag,
10468             p_assignment_id          => l_rec_assignment_id,
10469 	    p_run_mode               => p_run_mode,            /* iRec : Added p_run_mode */
10470             p_update_def_elct_flag   => l_ELCTBL_FLAG -- 5092244 : this parameter is no longer needed.
10471           );
10472         end if ;
10473         --
10474 	if g_debug then
10475         hr_utility.set_location(' Dn Det Enr 1: ' || l_proc, 10);
10476 	end if;
10477         IF l_new_elctbl_flag = 'Y' THEN
10478           --
10479           -- continue
10480           --
10481           NULL;
10482         --
10483         ELSIF l_new_elctbl_flag = 'L' THEN
10484           --
10485           -- Lose only condition.
10486           -- If enrolled will deenroll.
10487           --
10488           ben_newly_ineligible.main(
10489             p_person_id         => p_person_id,
10490             p_pgm_id            => l_pgm_id,
10491             p_pl_id             => l_pl_id,
10492             p_oipl_id           => l_oipl_id,
10493             p_business_group_id => p_business_group_id,
10494             p_ler_id            => p_ler_id,
10495             p_effective_date    => p_effective_date);
10496         if g_debug then
10497           hr_utility.set_location(' BNI_MN 1: ' || l_proc, 10);
10498         end if;
10499           l_new_elctbl_flag :=  'N';
10500         end if;
10501       else
10502         l_new_elctbl_flag:='N';
10503       end if;
10504     if g_debug then
10505       hr_utility.set_location(' Bef dflt flag chk: ' || l_proc, 10);
10506     end if;
10507   --    hr_utility.set_location('l_new_elctbl_flag='||l_new_elctbl_flag,1064);
10508       --
10509       -- update the choice if it needs it.
10510       --
10511     if g_debug then
10512       hr_utility.set_location('Dflt flag is '|| l_epe_dflt_flag,2121);
10513       hr_utility.set_location('l_dflt_flag is '||l_dflt_flag,2121);
10514     end if;
10515       if l_dflt_flag<> l_epe_dflt_flag or
10516          l_new_elctbl_flag <>  l_ELCTBL_FLAG then
10517   --      hr_utility.set_location('Dflt flag changed to '||l_dflt_flag,2121);
10518   --      hr_utility.set_location('Elct flag changed to '||l_new_elctbl_flag,2121);
10519   --      hr_utility.set_location('l_pl_id='||l_pl_id,2121);
10520   --      hr_utility.set_location('l_oipl_id='||l_oipl_id,2121);
10521         IF p_ler_id IS NOT NULL and
10522            l_new_elctbl_flag = 'Y' and
10523             l_ELCTBL_FLAG = 'N' THEN
10524           g_electable_choice_created :=  TRUE;
10525         END IF;
10526 	if g_debug then
10527         hr_utility.set_location(' BEPECA_UEPEC 1: ' || l_proc, 10);
10528 	end if;
10529         ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc
10530           (p_elig_per_elctbl_chc_id  => l_epe_id,
10531            p_dflt_flag               => l_dflt_flag,
10532            p_elctbl_flag             => l_new_elctbl_flag,
10533            p_object_version_number   => l_epe_ovn,
10534            p_effective_date          => p_effective_date,
10535            p_program_application_id  => fnd_global.prog_appl_id,
10536            p_program_id              => fnd_global.conc_program_id,
10537            p_request_id              => fnd_global.conc_request_id,
10538            p_program_update_date     => sysdate
10539         );
10540 	if g_debug then
10541         hr_utility.set_location(' Dn BEPECA_UEPEC 1: ' || l_proc, 10);
10542 	end if;
10543         --
10544         --bug#3726552 - update the default flag on benefit row
10545         l_enrt_bnft.enrt_bnft_id  := null;
10546         open c_enrt_bnft(l_epe_id);
10547         fetch c_enrt_bnft into l_enrt_bnft;
10548         close c_enrt_bnft;
10549         if l_enrt_bnft.enrt_bnft_id is not null then
10550           --
10551           ben_enrt_bnft_api.update_enrt_bnft
10552             (p_enrt_bnft_id      => l_enrt_bnft.enrt_bnft_id
10553             ,p_dflt_flag         => 'Y'
10554             ,p_object_version_number => l_enrt_bnft.object_version_number
10555             ,p_effective_date        => p_effective_date);
10556         end if;
10557         --
10558       end if;
10559       if g_debug then
10560       hr_utility.set_location(l_proc||' End c_choices loop: ',10);
10561       end if;
10562     end loop;
10563     --
10564   end if;
10565   if g_debug then
10566   hr_utility.set_location('Leaving: '||l_proc,10);
10567   end if;
10568 END update_defaults;
10569 -- end of package, below
10570 END ben_enrolment_requirements;