DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_ELECTION_INFORMATION

Source


1 package body ben_election_information as
2 /* $Header: benelinf.pkb 120.78.12020000.5 2013/03/09 05:50:36 pvelvano 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 Election Information
13 Purpose
14         This process creates or updates the participant's record with
15         information about plans and options elected.  This process
16         determines the effective date of new elections.  The enrollment
17         coverage end date for comp objects de-enrolled is in a later
18         function.
19 History
20      Date          Who          Version   What?
21      ----          ---          -------   -----
22      20 Apr 98     jcarpent     110.0     Created
23      06 Jun 98     jcarpent     110.1     Added call to manage_enrt_bnft
24      08 Jun 98     jcarpent     110.2     added busines group id to manage_enrt
25                                           _bnft
26      10 Jun 98     jcarpent     115.1     changed prtt_rt_val eff date to real
27                                           eff dt
28      11 Jun 98     jcarpent     115.2     On comp object ch do create then
29                                           delete enrt When delete use effective
30                                           _dt-1 for correctin
31      15 Jun 98     jcarpent     115.3     Added p_validate flag.
32                                           When delete use ed-1 for update not
33                                           correct. Make rt_strt_dt and cvg_strt
34                                           _dt required.
35      18 Jun 98     jcarpent     115.4     Added business group to everything
36                                           Changed out nocopy parameters
37      23 Jun 98     jcarpent     115.5     Check status code for per_in_ler.
38      08 Jul 98     Jmohapat     115.6     added batch who columns to api
39                                           calls(ben_prtt_enrt_result_api.
40                                           create/update_enrollment,
41                                           ben_enrt_bnft_api. updateenrt_bnft
42      24 Jul 98     jcarpent     115.7     Fixed message removed fnd_message.get
43      28 Jul 98     jcarpent     115.8     Added flex fields.
44      22 SEP 98     GPERRY       115.9     Corrected error messages
45      25 SEP 98     bbulusu      115.10    Added out nocopy parameters (warnings) at
46                                           end of election_information and in
47                                           the call to ben_ prtt_enrt_rslt_api.
48                                           create_enrollment
49      12 Oct 98     jcarpent     115.11    model changes to prv and pen
50      19 Oct 98     jcarpent     115.12    Moved rate start date calculation.
51      22 Oct 98     jcarpent     115.13    Handle SAAEAR cvg_mlt_cd
52                                           Update csd if bnft_amt changes.
53                                           Keep old orgnl_enrt_dt if plan stays
54                                           same
55      26 Oct 98     jcarpent     115.14    Updated prv to non-datetracked
56      27 Oct 98     jcarpent     115.15    Changed election_rate_information
57      29 Oct 98     jcarpent     115.16    Fixed calls to ben_prtt_rt_val_api.
58                                           Don't compare old elctns made date
59      29 Oct 98     stee         115.17    Get rt_typ_cd and rt_mlt_cd from
60                                           enrt_rt.
61      31 Oct 98     bbulusu      115.18    Added per_in_ler_d to delet_enrolment
62      04 Nov 98     jcarpent     115.19    Call annual_to_period/period_to_anual
63                                           Pass different OVN to create_enrt
64      05 Nov 98     jcarpent     115.20    Use prv_id from enrt_rt not one
65                                           passed
66      01 Dec 98     jcarpent     115.21    Made p_ovn optional (get it if null)
67      10 Dec 98     stee         115.22    Fixed bnf warning.
68      15 Dec 98     jcarpent     115.23    Added call to Create_debit_ledger..
69      31 Dec 98     lmcdonal     115.24    Better debug messages.
70      12 Jan 98     maagrawa     115.25    Modified calls to
71                                           ben_prtt_rt_val_api. (Column
72                                           acty_base_rt_id added to
73                                           table ben_prtt_rt_val).
74      01 Feb 99     jcarpent     115.26    Changed calls to update prv to use
75                                           ended_per_in_ler_id.
76      24 Feb 99     jcarpent     115.27    Changed rate cursor in ele_rt_info
77                                           to include union to join to choice
78      03 Mar 99     yrathman     115.28    Added bnft_ordr_num logic
79      04 Mar 99     jcarpent     115.29    Don't end old enrollment if it is
80                                           the interim enrollment.
81      24 Mar 99     jcarpent     115.31    Always call manage_enrt_bnft.
82                                           Delete/end date rate on bnft_amt chg
83      29 Mar 99     thayden      115.32    Added call to ben_ext_chlg.
84      05 Apr 99     mhoyes       115.33    Un-datetrack per_in_ler_f changes.
85      06 May 99     jcarpent     115.34    Write new prv if suspended
86      19 May 99     lmcdonal     115.35    Overloaded election_information to chg
87                                           which save point to set and rollback.
88                                           Because create_enrollment was also
89                                           changed, changed the call.
90      04 Jun 99     lmcdonal     115.36    Added loading of result.comp_lvl_cd
91      11 Jun 99     jcarpent     115.37    Fixed messages.
92      09 Jul 99     jcarpent     115.38    Added checks for backed out nocopy pil
93      20 Jul 99     jcarpent     115.39    New result for bnft amt change.
94      12 Aug 99     gperry       115.40    Added ben_env_object call for cases
95                                           when the process is being called
96                                           from forms. This makes all the
97                                           caching work correctly.
98      12 Aug 99     GPERRY       115.41    Backported 115.38 to add environment
99                                           package call.
100      24 Aug 99     GPERRY       115.42    Version 115.40 brought to top.
101      30 Aug 99     shdas        115.43    Added ordr_num columns to create_enrollment.
102      14 Sep 99     shdas        115.44    changed election_information to add bnft_val
103      29 Sep 99     jcarpent     115.45    If pen_id is null get from choice.
104      12 Oct 99     shdas        115.46    changed election information.
105      12-Nov-1999   jcarpent     115.47    Added enrt_bnft/choice globals
106      12-Nov-1999   jcarpent     115.48    Null out nocopy globals after calls.
107      12-Nov-1999   lmcdonal     115.49    Better debugging messages
108      17-Nov-1999   pbodla       115.50    l_acty_base_rt_id as passed to
109                                           ben_determine_date.rate_and_coverage_dates
110                                           ,ben_determine_date.main
111                                           which is used as context for rules.
112 
113      19-Nov-1999   pbodla       115.51    elig_per_elctbl_chc_id  passed to
114                                           benutils.formula.
115      29-Nov-1999   jcarpent     115.52  - Write new prv most of the time in
116                                           order to fix element entries.
117                                           bug 3556
118                                         - Write new enrollment result if bnft
119                                           amount changed, put back in because
120                                           removed in version 115.46.
121                                         - Added lee_rsn/enrt_perd to del_enrt.
122      14-Dec-1999   jcarpent     115.53  - Removed 'STRTD' restriction on pil.
123      16-Dec-1999   jcarpent     115.54  - Recompute cvg date if bnft amt chg
124      03-Jan-2000   lmcdonal     115.55    Bug 1121022. Do not re-calc rt-strt-dt
125                                           if a prtt-rt-val row exists.
126      20-Jan-2000   maagrawa     115.56   Pass payroll_id to ben_distribute_rates
127      21-Jan-2000   lmcdonal     115.57    If the rate is mult-of-cvg and cvg
128                                           can be entered at enrt, re-calc rate.
129                                           Bug 1118016.
130      25-Jan-2000   maagrawa     115.58    Pass per_in_ler_id to
131                                           create_debit_ledger_entry.
132      27-Jan-2000   thayden      115.59    New parameters for change event log.
133      02-Feb-2000   jcarpent     115.60    Remove l_effective_date adjustment.
134      24-Feb-2000   maagrawa     115.61    Re-open the rate only if the new
135                                           rate start date is before the old
136                                           rate end date.
137      26-Feb-2000   maagrawa     115.62    Added two parameters dpnt_actn_warning
138                                           and bnf_actn_warning to the procedure
139                                           update_enrollment.(1211553)
140      15-Mar-2000   shdas        115.63    Added parameters p_old_pl_id,p_old_oipl_id,
141                                           p_old_bnft_amt to log_benefit_chg(create portion)
142                                           for extract( bug 1187479).
143      20-Mar-2000   shdas        115.64    call create_debit_ledger_entry if result
144                                           is not suspndd(1217192).
145      23-Mar-2000  lmcdonal      115.65    Bug 1247110 - When calling update_
146                                           enrollment, pass eot as cvg_thru_dt.
147      30-Mar-2000  maagrawa      115.66    Re-use the enrollment result, if it
148                                           exists, when the choice is marked as
149                                           currently enrolled. (4875).
150      05-Apr-00  lmcdonal        115.67    Bug 1253007.  Using globals for epe, pil,
151                                           pel, pen, enb, asg data for performance.
152      06-Apr-2000  mmogel        115.68    Added tokens to message calls to make
153                                           the messages more meaningful
154      07-Apr-00  lmcdonal        115.69    Call 'clear_enb' procedure.
155      13-Apr-00  jcarpent        115.70    Call clear_enb cache procedure at end
156                                           and refetch after pen_api is called
157                                           to handle recursive calls.
158      13-Apr-00  lmcdonal        115.71    Change globals to locals
159      04-May-00  shdas           115.72    added parameters p_use_balance_flag
160                                           ,p_enrt_rt_id to period_to_annual and
161                                           changed cmplt_yr_flag to "N"(5043)
162      05-may-00  jcarpent        115.73    If form passes in wrong result_id,
163                                           (will somtimes pass in default/not
164                                           currently enrolled) use value from
165                                           epe.  (5073)
166      19-may-00  shdas           115.74    Always calculate period_to_annual.
167      22-May-00  lmcdonal        115.75    update enb globals right before call
168                                           to manage_enrt_bnft.
169      28-Jun-00  shdas           115.76    Alwayss calculate period to annual with
170                                           complt yr flag = yes.Calculate communicated
171                                           based on periodic value.
172      28-Jun-00  jcarpent        115.77    Bug 4936: Use new cvg_strt_dt if sched
173                                           enrt and plan is for 125 or 129
174                                           regulation.
175      19-Jul-00  rchase          115.78    Bug 5353: bug 5353 - iterim cvg not selecting
176                                           previous cvg if previous cvg exists in same
177                                           pl or pl_typ
178      20-jul-00  kmahendr        115.79    Bug5369 - Not able to save if the same plan is selected
179                                           in a new life event after electing a different plan
180                                           Result ID is assigned only when form is not sending any
181                                           result in election_information procedure
182      15-Aug-00  maagrawa        115.80    Added procedure election_information_w
183                                           (Wrapper for self-service).
184      07-Sep-00  maagrawa        115.81    Modified exception handling for
185                                           self-service wrapper.
186      09-Oct-00  maagrawa        115.82    Added checks for min/max benefit
187                                           amounts in self-service wrapper.
188                                           (1417250).
189      06-Nov-00  tilak           115.83    bug 1480407 when entr at enrl and calculation
190                                           cales the rate calculation for enterd value
191      16-Nov-00  jcarpent        115.84    Bug 1495632.  If no benefit amounts then
192                                           was always creating a new pen.
193      14-Dec-00  maagrawa        115.85    Overloaded the self-service wrapper.
194      15-dec-00  tilak           115.86    bug:1527086 funcation added to calculate the
195                                           erlst_deenrt_dt , this function called wheenever the coverage
196                                           date calcualted and the cvg date differ from cvg dt of ele_chc
197      02-Jan-01  Ikasire         115.87    Bug 1543438 Standart rate entered at enrollment is not
198                       saving inputed rate amount. Added rt_mlt_cd <> 'FLFX' for
199                                           the ben_determine_rate.main calling if condition in
200                                           election_rate_information procedure.
201      05-Jan-01  maagrawa        115.88    Added parameters p_enrt_cvg_strt_dt,
202                                           p_enrt_cvg_thru_dt for Individual
203                                           Compensation to allow user to
204                                           enter the coverage start date and
205                                           coverage through date when the codes
206                                           say they are enterable (ENTRBL).
207      08-Jan-01  maagrawa        115.89    Set the local variable
208                                           l_prtt_enrt_rslt_id to
209                                           l_global_epe_rec.epe.prtt_enrt_rslt_id
210      15-Jan-01  maagrawa        115.90    Modified the self-service wrapper
211                                           to handle multiple rates.
212      16-Jan-01  mhoyes          115.91  - Added calculate only mode parameter
213                                           to election_rate_information.
214      24-Jan-01  tilak           115.92    parent rate calucaltion is fixed
215                                           bug : 1555624
216      09-feb-01  ikasire         115.93    bug 1584238 and 1627373 remove the edit
217                                           checking rate start date always to
218                                           be after the coverage start date
219      09-feb-01  ikasire         115.94    correct the version number
220      23-Feb-01  maagrawa        115.95    Modified the error messages 92394,
221                                           92395 for self-service.
222      06-mar-01  ikasire         115.96    bug 1650517 remove the
223                                           p_complete_year_flag => 'Y' parameter
224                                           for SAREC condition for cmcd_val
225      09-Mar-01  maagrawa        115.97    Added rt_strt_dt and rt_end_dt
226                                           parameters to pass rate dates when
227                                           they are enterable.
228                                           Added support for rt_strt_dt_cd of
229                                           ENTRBL(Enterable) and rt_end_dt_cd of
230                                           WAENT(1 Prior or Enterable).
231      09-Mar-01  maagrawa        115.98    Create/Update the rate whenever the
232                                           per_in_ler_id changes.
233                                           Added check that the rate start date
234                                           should be less than or equal to rate
235                                           end date in election_rate_info...
236      17-May-01  maagrawa        115.99    Removed use of ben_comp_object and
237                                           replaced with ben_cobj_cache.
238                                           Modified calls to ben_global_enrt.
239      29-May-01  kmahendr        115.100   Modified cursor c_prv2 Bug#1771887
240      18-Jun-01  kmahendr        115.101   Bug#1830930-rate end date code is enterable
241                                           and rate start dt is not passed thro PUI then
242                                           end date is arrived as rate start dt - 1
243      20-Jun-01  ikasire         115.102   bug 1840961 added p_enrt_cvg_strt_dt and
244                                           p_enrt_cvg_thru_dt to the election_information
245                                           procedure call.
246      20-Jun-01  ikasire         115.104   this file is 115.102 after backporting version
247                                           115.103 for bug 1840961
248      25-Jun-01  kmahendr        115.105   The else condition in if code is WAENT is corrected
249      01-Jul-01  kmahendr        115.106   Unrestricted changes
250      23-Jul-01  kmahendr        115.107   Bug#1807450 - Coverage start date is not computed
251                                           if there is any waiting period attached
252      23-Jul-01  ikasire         115.108   Bug#1888085 fixed the issue of not calculating the
253                                           actual amount for 'Percent of' and
254                                           use_calc_acty_bs_rt_flag  is checked
255      24-Jul-01  mmorishi        115.109   Election_information_w: Added rt_strt_dt_cd
256                                           and person_id parms. Added call to prv_delete.
257      06-Aug-01  ikasire         115.110   Bug1913254 added a new cursor to handle the cases
258                                           for SAAEAR coverage code and the rate is not
259                                           entered at enrollment.
260      09-Aug-01  kmahendr        115.111   Bug#1890996 - Added cursor c_abr to check non recur-
261                                           ring rate and not to call update_prtt_rt_val to end
262                                           previous rate. Assign rate start date to rate end
263                                           date if the rate is non-recurring
264      17-Aug-01  maagrawa        115.112   Added parameter p_rt_update_mode
265                                           to election_information_w.
266      28-Aug-01  kmahendr        115.113   Added condition to check necessity to call update
267                                           prtt_rt_val
268      29-aug-01  tilak           115.114   bug:1949361 jurisdiction code is
269                                               derived inside benutils.formula.
270      30-aug-01  kmahendr        115.115   Already ended recurring rate is extended in the
271                                           subsequent rate - added condition to check old
272                                           rate end date
273      31-aug-01  pbodla          115.117   Version 116 is actually version 111 with changes
274                                           in version 114.
275      25-Oct-01  kmahendr        115.118   Bug#2055961-codes starting with 1 prior handled
276                                           before updating prtt_rt_val
277      5-Dec-01   dschwart        115.119   - Bug#2141172: changed call to ben_determine
278                                           _date.rate_and_coverage_dates to use life
279                                           event date.
280     18-dec-01   tjesumic        115.120   - cwb changes
281     20-dec-01   ikasire         115.121   added dbdrv lines
282     01-feb-02   ikasire         115.122   Bug 2172036 populate assignment_id in the pen records
283                                           the one available in epe record
284     12-Feb-02   ikasire         115.123   Bug 2212194 If there exist multiple rates while using
285                                           SAAREC code for Coverage Calculation.
286     12-Feb-02   ikasire         115.125   Bug 2212194 This is version 115.23 since we gave a
287                                           backport to ADS in 115.124
288     13-Feb-02   ikasire         115.126   Bug 2223694 When Rate code SAREC and the Coverage is
289                                           not enter value at enrollment, defined amount and
290                                           element entries not calculated.
291     26-Feb-02   rpillay         115.127   Bug 2093830 Changed from p_effective_date
292                                           to lf_evt_ocrd_dt in c_enrt_rt cursor
293     27-Feb-02   tjesumic        115.128   bug : 1794303 fixed by passing parameter
294                                           p_element_type_id  to annual_to_period
295     04-Mar-02   kmahendr        115.129   bug#2048236 - added cursors  - c_element_type and
296                                           if condition before update_prtt_rt_val -
297                                           removed changes made in 128 per Tilak.
298     14-Mar-02   rpillay         115.130   UTF8 Changes Bug 2254683
299     23-May-02   kmahendr        115.131   Changed logic for communicated value
300                                 115.132   No changes
301     04-Jun-02   kmahendr        115.133   Bug#2398448 and #2392732 - enrt_id is passed instead
302                                           of electable choice id for computing communicated
303                                           value.
304     08-Jun-02   pabodla         115.134   Do not select the contingent worker
305                                           assignment when assignment data is
306                                           fetched.
307     20-Jun-02   ikasire         115.135   Bug 2407041 wrong communication amount
308                                           when payroll changes.
309     06-Jun-02   ikasire         115.136   Bug 2483991 and Interim Ehancements.
310     07-Aug-02   ikasire         115.136   Bug 2483991 wrong datetrack mode was passed
311                                           to delete enrollment if the user replaces the
312                                           defaulted enrollment with the some other
313                                           compensation object.
314     08-Aug-02   ikasire         115.137   Bug 2502633 Interim enhancements.This needs to
315                                           go with the bensuenr.pkb/pkh as we are using a
316                                           package global variable here.
317     29-Aug-02   kmahendr        115.138   Bug#2207956 -sec 125 or 129 references removed and
318                                           codes added for starting a new result.
319     05-Sep-02   ikasire         115.140   Bug 2547005 and 2543071 for interim changes
320     28-Sep-02   ikasire         115.141   Bug 2600087 fixes for deenrolled result
321     28-Sep-02   ikasire         115.141   Bug 2600087 fixed error making infinit loop
322     10-Oct-02   shdas           115.143   Changed election_information_w for multirates
323     11-Oct-02   vsethi          115.144   Rates Sequence no enhancements. Modified to cater
324                                           to new column ord_num on ben_acty_base_rt_f
325     15-Oct-02   ikasire         115.145   Bug 2627078 fixes
326     28-Nov-02   lakrish         115.146   Bug 2499754, set tokens for error messages
327                                           BEN_91711_ENRT_RSLT_NOT_FND and
328                                           BEN_91453_CVG_STRT_DT_NOT_FOUN
329     02-Dec-02   kmullapu        115.147   out nocopy param added to election_information_w
330     13-Dec-02   ikasire         115.148   Bug 2675486 FSA Dont recmpute the fsa if
331                                           there is no change in the annual amount
332                                           within the plan year in the subsequent
333                                           life events
334     27-Dec-02   ikasire         115.149   Bug 2677804 override thru date changes
335     02-jan-03   hmani           115.149   Bug 2714383 - Passed pen_attributes
336        					  after checking whether its equalto hr_api.g_varchar2
337     					  Created a new function called 'decd_attribute'
338     09-jan-03   kmahendr        115.151   Bug#2734491 - Rates with child code is treated as
339                                           parent for annual target.
340     23-Jan-03   ikasire         115.152   Bug#2149438 Used the overloaded annual_to_period
341                                           procedure to determine the defined amount for
342                                           FSA calculations.
343     24-Jan-03   ikasire         115.153   Added nocopy changes
344     13-Feb-03   kmahendr        115.154   Added a parameter to call -acty_base_rt.main
345     13-feb-03   hnarayan	115.155   hr_utility.set_location - 'if g_debug' changes
346     06-Mar-03   ikasire         115.156   Bug2833116 rounding issue for FSA - annual rates
347     12-May-03   ikasire         115.157   Bug 2957028 nocopy bug fix for call to
348                                           ben_determine_activity_base_rt.main procedure
349     22-May-03   kmahendr        115.158   Fix for new rt mlt cd - ERL
350     29-May-03   ikasire         115.159   Bug 2976103 for nonrecurring element entries
351     22-Jul-03   tjesumic        115.160   rate start dt is passes as param to rate updated
352                                           when the rate strt dt is enterable
353     22-Jul-03   ikasire         115.161   brought forward 115.159 version.
354                                           DONT USE 115.160 -- BUG 3053267
355     13-Aug-03   kmahendr        115.162   Fix for new cvg_mlt_cd - ERL
356     26-Sep-03   kmahendr        115.163   Fix for new rt strt dt codes.
357     08-Oct-03   lakrish         115.164   Bug 3181158, for Enterable coverages
358                                           raise min-max error properly even if
359                                           default value is not defined for
360                                           Coverage.
361     15-Oct-03   mmudigon        115.165   Bug 2775742. Update rates for rt chg
362                                           process when element/input attached
363                                           to abr is changed.
364     30-Oct-03   tjesumic        115.165   #  2982606  new procedure backout_future_coverage added to
365                                 115.166    backout the future dated coverage and the plan in not continued
366                                           The backout caled for result level backed out
367                                           related changes in  benbolfe , bendenrr ,benleclr
368     14-Nov-03   ikasire         115.167   Bug 3253180 Get the right l_rt_val from the
369                                           annual value when p_rt_val is null for
370                                           l_enrt_rt.entr_ann_val_flag = 'Y'
371                                           also - if the same plan yr period if there is no change
372                                           in the annual contribution dont recompute the rates.
373     18-Nov-03   kmahendr        115.169   Bug#3260564 - added cursor c_future_rates to delete future
374                                           dated prtt_rt_val
375     20-Nov-03   mmudigon        115.170   Bug#3250360. Changes to
376                                           election_rate_information. cursors
377                                           c_prtt_rt_val_1 and c_prtt_rt_val_2
378                                           to pick the correct old prv
379    21-nov-03    nhunur         115.171    setting the flags to 'N' if the cursor
380                                           c_prtt_rt_val_2 does not return any rows.
381    25-nov-03    tjesumic       115.172     hr_utility.debug_enabled added to  all public procedure
382    16-Jan-04    kmahendr       115.173    Bug#3364910- added payroll change condition for
383                                           fSA plans
384    20-Jan-04    kmahendr       115.174    Bug#3378865 - added cursor c_abr to check for
385                                           ele_entry_val_cd change
386    21-Jan-04    mmudigon       115.175    Bug#3378865 - modified data type for
387                                           variable l_ele_entry_val_cd
388    03-Feb-04    kmahendr       115.176    Bug#3400822 - the subquery modified with                                                    effective_end_date condition to return only one
389                                           row - cursor c_enrt_rslt
390    16-Feb-04    mmudigon       115.177    Bug 3437083. Logic to determine abr
391                                           assignment changes
392    24-Feb-04    stee           115.178    Bug 3457483. Check the assignment to use code
393                                           in activity base rate when selecting the
394                                           assignment.
395    08-mar-04    hmani          115.179    Bug 3488286 - Added p_lf_evt_ocrd_date parameter to
396                                           BEN_DETERMINE_ACTIVITY_BASE_RT call
397    19-Mar-04    ikasire        115.180    Added new procedure call for rate_periodization_rl
398    23-Mar-04    ikasire        115.181    GSCC error
399    05-Apr-04    bmanyam        115.182    Bug: 3547233. Copied annual value to l_ann_rt_val variable
400                                           for prtt_enrt_rt record for 'Set Annual Value to Coverage'
401                     					  calculation method.
402   09-Apr-04     kmahendr       115.183    Bug#3540351 - rt_val and cmcd_val assigned
403                                           value 0 if the value is negative.
404   26-Apr-04     kmahendr       115.185    Bug#3510633 - person_id added to annual_to_period
405                                           function
406   07-jun-04      nhunur        115.186    bug 3602579 - original enrt date fix for waive oipls
407   08-jun-04     mmudigon       115.187    FONM
408   02-jul-04     rpgupt         115.188    3733745 - Do not delete future enrts. if it is an
409                                           interim.
410   15-Jul-04     kmahendr       115.189    Bug#3702090 - added enrt_mthd_cd condition while creating
411                                           new result - new flex plan enrollment is created when
412                                           override flex rate"
413   27-Jul-04     mmudigon       115.190    Bug 3797946. Logic to determine
414                                           change in extra input values
415   02-Aug-04     ikasire        115.191    Bug 3804813 to recompute the rates if
416                                           l_enrt_rt.entr_bnft_val_flag = 'Y'
417   23-Aug-04     mmudigon       115.192    CFW. Added p_act_item_flag
418                                           2534391 :NEED TO LEAVE ACTION ITEMS
419   09-sep-04     mmudigon       115.193    CFW. Continued
420   09-sep-04     mmudigon       115.194    CFW. p_act_item_flag no longer needed
421   20-Sep-04     ikasire        115.195    Bug 3787832 backout only the future results
422                                           of past life events.
423   30-sep-04     mmudigon       115.196    Bug 3854378. In proc
424                                           election_rate_information, old prv is
425                                           re-opened only when it is necessary
426  11-Oct-04     tjesumic        115.197    future backout only for a pgm, pgm_id added in validation
427  20-nov-04     nhunur          115.198    4020061 - bnft_val should be null if enrt_bnft_id is passed as null.
428  23-Nov-04     kmahendr        115.199    start_date passed for communicate val cal for fsa
429                                           to handle new rate codes
430  30-Nov-04     mmudigon        115.200    Bug 4018874. Changes to cursor
431                                           c_fut_pen in backout_future_coverage
432  01-Dec-04     ikasire         115.201    Bug 3988565 date type changed for a parameter  for SSBEN
433  12-Dec-04     vvprabhu        115.202    Bug 3980063. SSBEN Trace enhnacement. Changes to exception
434                                           handling in wrapper packages, addition of debug statements
435 					  and logic to enable trace based on profile value.
436  22-Dec-04     maagrawa        115.203    Added more parms to election_information_w
437                                           to have both procedures in sync.
438  23-Dec-04     tjesumic        115.204    new param p_prtt_enrt_rslt_id added backout_future_coverage
439                                           p_prtt_enrt_rslt_id nullified if the rslt is backedout
440  28-Dec-04     kmahendr        115.205    Bug#4078828 - element_type and input_value fetched
441                                           based on rate start date in case of start date code
442                                           based on election
443  29-Dec-04     tjesumic        115.206    continuation of 115.204 # 3945471 new cursor c_csr added
444                                           to validate the future cvrd results deleted
445  30-dec-2004    nhunur         115.207    4031733 - No need to open cursor c_state.
446  04-Jan-04     tjesumic        115.208    continuation of 115.204 # 3945471
447  04-Jan-04     tjesumic        115.209    continuation of 115.204  future backoit skipped for cwb,abs,comp ler
448  11-Jan-04     ikasire         115.210    CF Interim Suspended BUG 4064635
449  07-Feb-05     tjesumic        115.211    backout_future_result is removed, future cvg taken care
450                                           in delete_enrollment # 4118315
451  09-Feb-05     ikasire         115.212    Bug 4173505 Need to sspndd_flag to update_enrollment otherwise
452                                           suspended enrollment will be carried forward with suspend flag
453                                           checked even it is not required.
454  10-Feb-05     mmudigon         115.213   Bug 4157759. Added proc
455                                           handle_overlap_rates()
456  09-Mar-05     vvprabhu         115.214   Bug 4216475 changes to election_information_w to
457                                           validate coverage amount when default is outside
458 					  coverage range
459  13-Apr-05     ikasire          115.215   Added a new parameter to manage_enrt_bnft procedure
460  26-May-05     vborkar          115.216   Bug 4387247 : In wrapper method exception
461                                           handlers changes made to avoid null errors
462                                           on SS pages
463  01-Jun-05     vborkar          115.217   Bug 4387247 : Modifications to take care of
464                                           application exceptions.
465  17-Jun-05     vborkar          115.218   Bug 4436578 : In SS wrapper app exception
466                                           handler added generic(default) code.
467  12-jul-05     ssarkar          115.219   BUG 4203714 : Modified c_comp_obj_name for proc handle_overlap_rates.
468  29-jul-05     tjesumic         115.230   BUG 4510798 : fonm variable intialised on election information
469  11-aug-05     ssarkar          115.221   BUG 4203714 : Rtrim to chop off the trailing spaces
470  17-aug-05     kmahendr         115.222   Bug#4549089 - new result is created only
471                                           if the per_in_ler is different in sspd enroll
472  25-Aug-05     ikasire          115.223   Bug 4568911 fix
473  08-Sep-05     kmahendr         115.224   Bug#4555320 - new result is not created
474                                           if the per in ler ids are same
475  27-Sep-05     vborkar          115.225   Bug 4543745 : Avoid election-information call for
476 	                                        electable choices whose existing enrollments
477 																					cannot be changed in current LE.
478  03-Nov-05     rbingi           115.226   4710188: removed case entr_bnft_val='Y' in if condition of
479                                             call to Std rates proc. will be called only for Post-Enrollment
480  03-Nov-05     rbingi           115.227   reverted previous version changes
481  08-Nov-05     rbingi           115.228   4710188: Calling acty_base_rt proc for ERL case only if
482                                            rt value is not enterable
483  02-dec-05    ssarkar           115.229   4775760 : Creat prtt_rt_val not be to called if sspndd_flag = 'Y' and prtt_rt_val is already present.
484  12-dec-05    ssarkar           115.230   4775760,4871284 : rollback fix of 115.229 and commented the restrcition of Unrestricted.
485  11-jan-06    ikasire           115.231   4938498 fixed c_prv2 cursor to exclude voided and backedout
486                                           records.
487  16-Jan-06    abparekh          115.232   Bug 4954541 : If bnft_amt is nullified, create new enrollment
488  10-Feb-06    kmahendr          115.233   Bug#5032364 - before delete prtt row, it
489                                           is captured in ben_le_clsn_n_rstr table
490                                           for backout purpose
491  22-Mar-06    rtagarra          115.234   Bug#5099296 : Changed the sspndd_flag parameter passed to update_enrollment.
492  23-Mar-06    kmahendr          115.235   Bug#5105122 - coverage date is recomputed
493                                           before create_enrollment
494  16-Jun-06    rbingi            115.236   Bug#5259005-Moved code for calulating ann_rt_val, rt_val based in
495                                            entr_val flag to proc election_rate_information from pld.
496  09-Jul-06    rbingi            115.237   Bug#5303167-corrected if condition in proc elec_rt_info
497  17-jul-06    ssarkar           115.238   Bug 5375381 - ben_determine_activity_base_rt being called for interim.
498  03-aug-06    ssarkar           115.239   bug 5417132 - passing comp_lvl_cd to update_enrollment call
499  27-Sep-06    ikasired          115.240   Bug 5502202 fix for Interim Rule. We need to recompute the rates when
500                                           interim rule returs amounts.
501  10-Oct-06    abparekh          115.241   Bug 5572484 : Take backup in BEN_LE_CLSN_N_RSTR only if the correction
502                                                         is due to a new life event.
503  11-Oct-06    ssarkar           115.242   Bug 5555269 - commented out fix of bug 5032364 as well 5572484
504  12-Oct-06    gsehgal           115.243   Bug 5584813 - move the code to calculate rates to procedure
505 					  calc_rt_ann_rt_vals and also call this when cvg_mlt_cd='SAAEAR'
506  17-Oct-06    abparekh          115.244   Bug 5600697 - In procedure ELECTION_INFORMATION
507                                                         Set P_PRTT_ENRT_RSLT_ID only if
508                                                         PRTT_ENRT_RSLT_STAT_CD is NULL
509 20-Oct-06     bmanyam           115.245   5612091 cursor c_enrt_rt corrected.
510                                           join ecv with enb was incomplete. OR-ed with epe
511 26-Oct-06     ssarkar           115.246   5621049  : dont compare the cvg amt of option2 with option1
512 10-Nov-06     ssarkar           115.247   bug 5653168 : resetting g_use_new_result for any exception raised in election_information
513 18-nov-06     ssarkar           115.248   Bug 5717428 - passed life event occurred date to rate_and_coverage_dates
514 24-jan-07     stee              115.249   Bug 5766477 - Restore dependent
515                                           coverage when future enrollments
516                                           are deleted.
517 05-apr-07     ssarkar           115.250   bug 5942441 - overiding info to be passed to subsequent prv
518 08-may-07     gsehgal           115.251   bug 6022111 - wrong prv record was being fetched
519                                           for parent record in cursor c_prv2
520 11-May-07     ikasired          115.252   Bug 5985777. When action items are completed in future
521                                           we need to extend the suspended enrollments with future
522                                           delete store the future completed action items in
523                                           backup table for future reinstate in the event
524                                           the current life event backout.
525 25-May-07     bmanyam           115.253   6057157 : -- same as above--
526                                           Reopen future interim PRV records. This was
527                                           missed out in the prev version.
528 21-Jun-07     swjain		115.254   6067740 - Updated procedure election_rate_information for SAREC
529                                           cases.
530 26-Jun-07     sshetty		115.255   6132571--changed logic to detect the
531                                           payroll id changes by calling
532                                           get_abr_assignment for the old
533                                           rate start date
534 24-Aug-07     gsehgal           115.256   bug 6337803 - dont delete the enrollment if enrollment to be suspended has same
535                                           comp object as interim
536 05-Oct-07     swjain            115.258   Removing the fix in 6067740
537 23-Oct-07     rgajula           115.259   Bug 6503304 : Passed lf_evt_ocrd_dt instead of p_effective_date to procedures get_ptip_dets, get_plip_dets, get_oipl_dets,get_pl_dets
538                                            to get the details as of life event occured date (open life event case)
539 28-aug-08     bachakra          115.260   Bug 7206471: adjust the coverage and rates when event date life event
540                                           is processed after fonm life event in the same month.
541 06-Jan-09     sallumwa          115.261   Bug 7557403 : Modified procedure election_rate_information to set the
542 					  global cvg and rate start date variables.
543 10-Mar-09     krupani           115.264   BUG 8244388: When Child rate is multiple of parent, fetch the parent rate value
544                                           as of Child rate strat date
545 01-Apr-09     krupani           115.265   Bug 8374859: While calling ben_determine_activity_base_rt.main, ler_id was
546                                           getting passed from pen record. Now, passing it from ben_per_in_ler
547 29-Apr-09     velvanop          115.266   Bug 8300620: Fix of Bug 7206471 causing rate gap issues on processing the LifeEvent.
548                                           Cursor c_get_elctbl_chc fetches all the choices tied to the current PIL grouped by ptip_id.
549 					  As a result, besides the required plan type to be actually adjusted, all ptip's are picked up
550 					  and the rates are adjusted.So modified cursor to pick the correct ptip instead of pickingup
551 					  all the ptip's
552 25-May-09     velvanop          115.267   Bug 8507247: Fixes done on top of Bug 7206471
553 02-Aug-09     krupani           115.268   8716870: Imputed Income Enhancement. Added new parameter p_imp_cvg_strt_dt
554                                           which will have the coverage start date of the enrollment subject to imputed income
555 19-Aug-09     sallumwa          115.270   Bug 8596122 : Handled the overlap coverage case.Also,reverted the fix for 8312737.
556 05-Sep-09     velvanop          115.271   Bug 8871911 : Performance Bug. Modified cursor 'c_get_prior_per_in_ler' ,added a join condition
557                                           to avoid full table scan on pil table
558 29-Sep-09     velvanop          115.272   Bug 8945818 : Coverage overlap when FONM UnSuspended code and Event date
559                                           event processed in the same month
560 29-Oct-09     stee              115.273   Bug 9028102 : Fix cursor c_get_dpnt to check for an effective
561                                                         end date that is not equal to eot.
562 31-Oct-09     velvanop          115.274   Bug 9057101: Instead of passing p_effective_date, pass
563 					  effective start date of the pen_id when adjusting the future coverage
564 27-Jan-10     sallumwa          115.275   Bug 9309878: While determining the defined amount,pass the rate start date
565                                           to the procedure annual_to_period.
566 05-Feb-10     sallumwa          115.276   Bug 9139820 : When multiple changes to the elections are made in a life event,
567                                           then open up the enrollment result attached to the previous life event and update
568 					  the record with the new changes made in the current life event.
569 16-Feb-10     sagnanas          115.277   Bug 8589355 - Passed opt_id to get_extra_ele_inputs
570 02-Mar-10     sallumwa          115.278   Bug 9143356 - sarec_compute flag is set to true when there is a change in
571                                           assignment even though there is no change in payroll.
572 04-Mar-10     sallumwa          115.279   Bug 9430735 - Extended the fix done for the bug 9139820 to handle the case
573                                           where no elections are made against the previous life event.
574 03-May-10     velvanop          115.280   Bug 9538592: Basing upon the flag set in reinstate enrollments call, set l_start_new_result
575 19-May-10     stee              115.281   Bug 9593336: Do not recompute rate amounts
576                                           if annual amount did not change within the
577                                           payroll year.
578 26-Jul-10     sagnanas          115.282   Bug 9614678 - Fetch prv again as it might have been updated to avoid HR obj invalid issue
579 19-May-10     stee              115.283   Bug 10058794:  Fix cursor for bug 9593336 to use regular payment
580                                                          date instead of period_num.
581 30-Sep-10     velvanop          115.284   Bug 9758763: Reset the flag g_create_new_result in benleclr.pkb. Flag
582 	                                  will be reseted after the result is reinstated
583 22-Oct-10     velvanop          115.285	  Bug 10137678: While adjusting the rates for overlapping rates, check for any rates that are end dating in the future
584 			                  in addition to checking for the rates that are starting the future. Modified cursor 'c_get_prior_per_in_ler'.
585 11-Nov-10     stee              115.286	  Bug 9401100: Create a new enrollment result if the benefit amount
586                                           does not change but the enrollment is suspended in the current
587                                           event.
588 31-Dec-10     velvanop          115.287	  Bug 10419741  Continuation of Bug fix 10137678. While adjusting the rates, if there are no rate records for the previous life event
589                                           ,cursor c_get_prior_per_in_ler will not fetch any rate records for adjustment. Modified cursor 'c_get_prior_per_in_ler'.
590 07-Feb-10     krupani           115.288   Bug 10224915 - Code changes to prevent rate gap after imputed income enhancement
591 15-Mar-11     stee              115.289   Bug 11869699 - Added payroll_id to the period_to_annual function.
592 12-Apr-11     stee              115.290   Bug 10415806 - Delete future dated element
593                                           entries for unrestricted enrollment.
594 31-May-11     stee              115.291   Bug 12421421 -  If interim is what they were enrolled
595                                           in before, reinstate the prior enrollment if re-selected.
596 03-Aug-11     velvanop          115.292	  Bug 12576710 - Insert the future coverage and rate records into backup table before updating them with new values
597 07-Dec-11     velvanop          115.293	  Fixes for Bugs 13079111/13472223: If the coverage code is based on Rule, then consider the new value evaluated by rule
598                                           while saving the enrollments for cvg start date, instead of the old value evaluated when processing benmngle(stored in epe table)
599 15-Dec-11     usaraswa		115.294   Bug 13444556 - While adjusting the coverage for overlapping coverage, check for any coverage that are end dating in the future.
600 			                  Created cursor 'c_get_prior_per_in_ler_1'.
601 
602 16-Feb-2012   stee              115.295   Bug 13542327 - Added elig_per_elctbl_chc_id
603                                           to cursor c_get_ended_result.
604 01-May-12     stee		115.296   Bug 12583091  - Check for per_in_ler_id when
605                                           determining if enrollment is suspended.
606 9-Nov-12     velvanop           115.297   Bug 14803995 : Do not insert future coverage records in backup table if the Life event is Unrestricted
607 9-Mar-13     velvanop           115.298   Bug 16396102 : While inserting record into backup table ben_le_clsn_n_rstr for rate adjustment records 'BEN_PRTT_RT_VAL_ADJ', populate person_id
608                                           while inserting into the table
609 */
610 
611 -------------------------------------------------------------------------------
612 --
613 -- Package Variables
614 --
615 g_debug boolean := hr_utility.debug_enabled;
616 g_package varchar2(80):='ben_election_information.';
617 -- ---------------------------------------------------------------------------
618 -- |----------------------------< calc_rt_ann_rt_vals >---------------------|
619 -- Bug: 5584813 this is a private procedure that calculates the rate values --
620 -- ---------------------------------------------------------------------------
621 --
622 PROCEDURE calc_rt_ann_rt_vals (
623    p_rt_val                  IN OUT NOCOPY  NUMBER,
624    p_ann_rt_val              IN OUT NOCOPY  NUMBER,
625    p_person_id               IN       NUMBER,
626    p_effective_date          IN       DATE,
627    p_acty_base_rt_id         IN       NUMBER,
628    p_rate_periodization_rl   IN       NUMBER,
629    p_elig_per_elctbl_chc_id    IN       NUMBER,
630    p_business_group_id       IN       NUMBER,
631    p_enrt_rt_id              IN       NUMBER,
632    p_entr_ann_val_flag       IN       VARCHAR2,
633    p_entr_val_at_enrt_flag   IN       VARCHAR2)
634 IS
635    l_assignment_id     per_all_assignments_f.assignment_id%TYPE;
636    l_payroll_id        per_all_assignments_f.payroll_id%TYPE;
637    l_organization_id   per_all_assignments_f.organization_id%TYPE;
638    --GEVITY
639    l_dfnd_dummy        NUMBER;
640    l_ann_dummy         NUMBER;
641    l_cmcd_dummy        NUMBER;
642    l_compute_val       NUMBER;
643 
644 --END GEVITY
645    l_proc                 varchar2(72) := g_package||'calc_rt_ann_rt_vals';
646 BEGIN
647    hr_utility.set_location('Entering: '||l_proc, 10);
648    IF p_entr_ann_val_flag = 'Y'
649    THEN
650       -- Enter Annual Value
651       IF     p_rate_periodization_rl IS NOT NULL
652          AND p_acty_base_rt_id IS NOT NULL
653       THEN
654          --
655          ben_element_entry.get_abr_assignment
656                                      (p_person_id                   => p_person_id,
657                                       p_effective_date              => p_effective_date,
658                                       p_acty_base_rt_id             => p_acty_base_rt_id,
659                                       p_organization_id             => l_organization_id,
660                                       p_payroll_id                  => l_payroll_id,
661                                       p_assignment_id               => l_assignment_id);
662          --
663          l_ann_dummy := p_ann_rt_val;
664          ben_distribute_rates.periodize_with_rule
665                         (p_formula_id                  => p_rate_periodization_rl,
666                          p_effective_date              => p_effective_date,
667                          p_assignment_id               => l_assignment_id,
668                          p_convert_from_val            => l_ann_dummy,
669                          p_convert_from                => 'ANNUAL',
670                          p_elig_per_elctbl_chc_id      => p_elig_per_elctbl_chc_id,
671                          p_acty_base_rt_id             => p_acty_base_rt_id,
672                          p_business_group_id           => p_business_group_id,
673                          p_enrt_rt_id                  => p_enrt_rt_id,
674                          p_ann_val                     => l_dfnd_dummy,
675                          p_cmcd_val                    => l_cmcd_dummy,
676                          p_val                         => l_compute_val);
677       --
678       ELSE
679          l_compute_val :=
680             ben_distribute_rates.annual_to_period
681                                  (p_amount                      => p_ann_rt_val,
682                                   p_enrt_rt_id                  => p_enrt_rt_id,
683                                   p_elig_per_elctbl_chc_id      => NULL,
684                                   p_acty_ref_perd_cd            => NULL,
685                                   p_business_group_id           => p_business_group_id,
686                                   p_effective_date              => p_effective_date,
687                                   p_lf_evt_ocrd_dt              => NULL,
688                                   p_complete_year_flag          => 'Y',
689                                   p_use_balance_flag            => 'Y',
690                                   p_start_date                  => NULL,
691                                   p_end_date                    => NULL);
692       --
693       END IF;                                                         --GEVITY
694 
695       p_rt_val := l_compute_val;
696    ELSIF p_entr_val_at_enrt_flag = 'Y'
697    THEN
698       --
699       --  11869699
700       --
701       --  Get payroll and assignment id
702       --
703       ben_element_entry.get_abr_assignment
704                            (p_person_id                   => p_person_id,
705                             p_effective_date              => p_effective_date,
706                             p_acty_base_rt_id             => p_acty_base_rt_id,
707                             p_organization_id             => l_organization_id,
708                             p_payroll_id                  => l_payroll_id,
709                             p_assignment_id               => l_assignment_id);
710       --
711       IF     p_rate_periodization_rl IS NOT NULL
712          AND p_acty_base_rt_id IS NOT NULL
713       THEN
714          --
715        -- commented out 11869699
716       /*   ben_element_entry.get_abr_assignment
717                              (p_person_id                   => p_person_id,
718                               p_effective_date              => p_effective_date,
719                               p_acty_base_rt_id             => p_acty_base_rt_id,
720                               p_organization_id             => l_organization_id,
721                               p_payroll_id                  => l_payroll_id,
722                               p_assignment_id               => l_assignment_id); */
723          --
724          l_dfnd_dummy := p_rt_val;
725          --
726          ben_distribute_rates.periodize_with_rule
727                 (p_formula_id                  => p_rate_periodization_rl,
728                  p_effective_date              => p_effective_date,
729                  p_assignment_id               => l_assignment_id,
730                  p_convert_from_val            => l_dfnd_dummy,
731                  p_convert_from                => 'DEFINED',
732                  p_elig_per_elctbl_chc_id      => p_elig_per_elctbl_chc_id,
733                  p_acty_base_rt_id             => p_acty_base_rt_id,
734                  p_business_group_id           => p_business_group_id,
735                  p_enrt_rt_id                  => p_enrt_rt_id,
736                  p_ann_val                     => l_compute_val,
737                  p_cmcd_val                    => l_cmcd_dummy,
738                  p_val                         => l_cmcd_dummy);
739       --
740       ELSE
741          hr_utility.set_location('Calculate Annual value: '||l_payroll_id, 10);
742          l_compute_val :=
743             ben_distribute_rates.period_to_annual
744                                  (p_amount                      => p_rt_val,
745                                   p_enrt_rt_id                  => p_enrt_rt_id,
746                                   p_elig_per_elctbl_chc_id      => NULL,
747                                   p_acty_ref_perd_cd            => NULL,
748                                   p_business_group_id           => p_business_group_id,
749                                   p_effective_date              => p_effective_date,
750                                   p_lf_evt_ocrd_dt              => NULL,
751                                   p_complete_year_flag          => 'Y',
752                                   p_use_balance_flag            => 'Y',
753                                   p_start_date                  => NULL,
754                                   p_end_date                    => NULL,
755                                   p_payroll_id                  => l_payroll_id); -- 11869699
756       --
757       END IF;                                                         --GEVITY
758 
759       p_ann_rt_val := l_compute_val;
760    --
761    END IF;
762    hr_utility.set_location('Leaving: '||l_proc, 10);
763 END calc_rt_ann_rt_vals;
764 
765 
766 -- ---------------------------------------------------------------------------
767 -- |----------------------------< handle_overlap_rates >---------------------|
768 -- ---------------------------------------------------------------------------
769 --
770 procedure handle_overlap_rates
771   (p_acty_base_rt_id                in  number
772   ,p_prtt_enrt_rslt_id              in  number
773   ,p_prtt_rt_val_id                 in out nocopy  number
774   ,p_per_in_ler_id                  in  number
775   ,p_person_id                      in  number
776   ,p_element_type_id                in  number default null
777   ,p_element_entry_value_id         in  number
778   ,p_unrestricted                   in  varchar2 default 'N'
779   ,p_rt_strt_dt                     in  date
780   ,p_business_group_id              in  number
781   ,p_effective_date                 in  date
782   ) is
783 
784   --
785   -- pick overlapping rates for the same abr (and)
786   -- any future rates attached to the same element type
787   --
788   cursor c_future_prv(p_element_type_id number) is
789   select prv.prtt_rt_val_id,
790          prv.acty_base_rt_id,
791          prv.acty_ref_perd_cd,
792          prv.rt_strt_dt,
793          prv.prtt_enrt_rslt_id, -- 10415806
794          prv.rt_val, -- 10415806
795          prv.object_version_number
796     from ben_prtt_rt_val prv
797    where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
798      and ((prv.rt_strt_dt > p_rt_strt_dt) or -- old prv in future
799           (p_unrestricted = 'N' and          -- old prv on same date
800            prv.per_in_ler_id <> p_per_in_ler_id and
801            prv.rt_strt_dt = p_rt_strt_dt))
802      and prv.prtt_rt_val_stat_cd is null
803      and (prv.acty_base_rt_id = p_acty_base_rt_id
804           or exists
805                 (select 'x'
806                    from per_all_assignments_f asg,
807                         pay_element_links_f pel,
808                         pay_element_entries_f pee,
809                         pay_element_entry_values_f pev
810                   where pel.element_type_id = p_element_type_id
811                     and pee.element_entry_id = pev.element_entry_id
812                     and pev.element_entry_value_id = prv.element_entry_value_id
813                     and pee.element_link_id = pel.element_link_id
814                     and pee.assignment_id = asg.assignment_id
815                     and pee.creator_type ='F'
816                     and pee.creator_id = p_prtt_enrt_rslt_id
817                     and asg.person_id = p_person_id)
818          )
819   order by prv.rt_strt_dt desc;
820   --
821   l_future_prv      c_future_prv%ROWTYPE;
822   --
823   cursor c_current_prv is
824   select prtt_rt_val_id,
825          acty_base_rt_id,
826          rt_strt_dt,
827          rt_end_dt,
828          object_version_number
829     from ben_prtt_rt_val prv
830    where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
831      and p_rt_strt_dt between prv.rt_strt_dt
832      and prv.rt_end_dt
833      and prv.acty_base_rt_id = l_future_prv.acty_base_rt_id
834      and prv.prtt_rt_val_stat_cd is null;
835   --
836   l_current_prv      c_current_prv%ROWTYPE;
837   --
838   -- gets element_type_id from element_entry_value_id
839   --
840   cursor c_ele_entry (p_element_entry_value_id number) is
841   select elk.element_type_id
842     from pay_element_entry_values_f elv,
843          pay_element_entries_f ele,
844          pay_element_links_f elk
845    where elv.element_entry_value_id  = p_element_entry_value_id
846      and elv.element_entry_id = ele.element_entry_id
847      and elv.effective_start_date between ele.effective_start_date
848      and ele.effective_end_date
849      and ele.element_link_id   = elk.element_link_id
850      and ele.effective_start_date between elk.effective_start_date
851      and elk.effective_end_date;
852   --
853   cursor c_comp_obj_name (p_prtt_enrt_rslt_id number)  is
854   select rtrim(substr(pln.name||' '||opt.name,1,60)) -- 4203714 rtrim to chop off the trailing spaces
855     from ben_prtt_enrt_rslt_f pen,
856          ben_pl_f pln,
857          ben_oipl_f oipl,
858          ben_opt_f opt
859    where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
860      and pen.pl_id = pln.pl_id
861      and pen.oipl_id  = oipl.oipl_id(+)
862      and nvl(oipl.opt_id,0) = opt.opt_id (+)
863      and p_effective_date between pen.effective_start_date
864      and pen.effective_end_date
865      and p_effective_date between pln.effective_start_date
866      and pln.effective_end_date
867      and p_effective_date between nvl(oipl.effective_start_date,p_effective_date) --start 4203714
868      and nvl(oipl.effective_end_date,p_effective_date)
869      and p_effective_date between nvl(opt.effective_start_date,p_effective_date)
870      and nvl(opt.effective_end_date,p_effective_date); -- end 4203714
871 
872   --9614678
873   cursor c_prv(p_prtt_rt_val_id number) is
874   select prv.prtt_rt_val_id,
875          prv.acty_base_rt_id,
876          prv.acty_ref_perd_cd,
877          prv.rt_strt_dt,
878          prv.prtt_enrt_rslt_id, -- 10415806
879          prv.rt_val, -- 10415806
880          prv.object_version_number
881     from ben_prtt_rt_val prv
882   where prtt_rt_val_id = p_prtt_rt_val_id;
883   --9614678
884 
885   l_dummy                varchar2(1);
886   l_comp_obj_name        varchar2(60);
887   l_proc                 varchar2(72) ;
888   l_element_type_id      number;
889 
890   --9614678
891   l_found boolean := false;
892 
893   type prv_rec is record
894        (prtt_rt_val_id  ben_prtt_rt_val.prtt_rt_val_id%type);
895 
896   type prv_table is table of prv_rec index by binary_integer;
897   l_prv_table    prv_table;
898   l_prv_count number := 1;
899   --9614678
900 
901 begin
902   g_debug := hr_utility.debug_enabled;
903   if g_debug then
904     l_proc := g_package||'handle_overlap_rates';
905     hr_utility.set_location('Entering:'|| l_proc, 10);
906   end if;
907 
908   l_element_type_id := p_element_type_id;
909   if l_element_type_id is null then
910 
911      open c_ele_entry(p_element_entry_value_id);
912      fetch c_ele_entry into l_element_type_id ;
913      close c_ele_entry;
914 
915   end if;
916 
917 
918   open c_future_prv(l_element_type_id);
919   loop
920 
921      fetch c_future_prv into l_future_prv ;
922      if c_future_prv%notfound then
923         exit;
924      end if;
925 
926      if g_debug then
927         hr_utility.set_location('future prv='||l_future_prv.prtt_rt_val_id,15);
928      end if;
929 
930      --9614678
931      if l_found then
932         for l_in_cnt in 1..l_prv_table.last loop
933              if l_prv_table(l_in_cnt).prtt_rt_val_id = l_future_prv.prtt_rt_val_id then
934                 open c_prv(l_future_prv.prtt_rt_val_id);
935                 fetch c_prv into l_future_prv;
936    	        close c_prv;
937    	        exit;
938              end if;
939         end loop;
940      end if;
941      --9614678
942 
943      if fnd_global.conc_request_id in ( 0,-1) then
944         --
945         -- Lets us throw a warning about the deletion of the future rate.
946         --
947         open c_comp_obj_name (p_prtt_enrt_rslt_id);
948         fetch c_comp_obj_name into l_comp_obj_name;
949         close c_comp_obj_name;
950         --
951         -- Issue a warning to the user.  This will display on the enrt
952         -- forms.
953         --
954 
955         ben_warnings.load_warning
956          (p_application_short_name  => 'BEN',
957           p_message_name            => 'BEN_93369_DEL_FUT_RATE',
958           p_parma  => fnd_date.date_to_chardate(l_future_prv.rt_strt_dt),
959           p_parmb                   => l_comp_obj_name,
960           p_person_id               => p_person_id );
961 
962      end if;
963 
964      if p_prtt_rt_val_id = l_future_prv.prtt_rt_val_id then
965         p_prtt_rt_val_id := null;
966      end if;
967      --
968      -- Call delete prv if Unrestricted, else update prv
969      --
970      if p_unrestricted = 'Y' then
971         hr_utility.set_location('p_rt_strt_dt ='||p_rt_strt_dt,15);
972         --
973         --  bug 10415806 delete future dated element entries.
974         --
975         ben_element_entry.end_enrollment_element
976           (p_business_group_id        => p_business_group_id
977           ,p_person_id                => p_person_id
978           ,p_enrt_rslt_id             => l_future_prv.prtt_enrt_rslt_id
979           ,p_acty_ref_perd            => l_future_prv.acty_ref_perd_cd
980           ,p_element_link_id          => null
981           ,p_prtt_rt_val_id           => l_future_prv.prtt_rt_val_id
982           ,p_rt_end_date              => p_rt_strt_dt - 1
983           ,p_effective_date           => p_rt_strt_dt
984           ,p_dt_delete_mode           => hr_api.g_zap
985           ,p_acty_base_rt_id          => l_future_prv.acty_base_rt_id
986           ,p_amt                      => l_future_prv.rt_val);
987         --
988         ben_prtt_rt_val_api.delete_prtt_rt_val
989         (p_prtt_rt_val_id         => l_future_prv.prtt_rt_val_id
990         ,p_person_id              => p_person_id
991         ,p_business_group_id      => p_business_group_id
992         ,p_object_version_number  => l_future_prv.object_version_number
993         ,p_effective_date         => l_future_prv.rt_strt_dt);
994     else
995         ben_prtt_rt_val_api.update_prtt_rt_val
996         (p_validate                => false,
997          p_person_id               => p_person_id,
998          p_business_group_id       => p_business_group_id,
999          p_prtt_rt_val_id          => l_future_prv.prtt_rt_val_id,
1000          p_rt_end_dt               => l_future_prv.rt_strt_dt -1,
1001          p_prtt_rt_val_stat_cd     => 'BCKDT',
1002          p_ended_per_in_ler_id     => p_per_in_ler_id,
1003          p_object_version_number   => l_future_prv.object_version_number,
1004          p_effective_date          => l_future_prv.rt_strt_dt);
1005     end if;
1006     --
1007     -- open up the current rates that are attached to the same
1008     -- element type
1009     --
1010     if l_future_prv.acty_base_rt_id <> p_acty_base_rt_id then
1011 
1012        l_current_prv := null;
1013        open c_current_prv;
1014        fetch c_current_prv into l_current_prv;
1015        close c_current_prv;
1016 
1017        if g_debug then
1018           hr_utility.set_location('curr prv='||l_current_prv.prtt_rt_val_id,15);
1019        end if;
1020 
1021        if l_current_prv.rt_end_dt <> hr_api.g_eot then
1022 	  --9614678
1023 	  l_prv_table(l_prv_count).prtt_rt_val_id := l_current_prv.prtt_rt_val_id;
1024           l_prv_count := l_prv_count + 1;
1025 	  l_found := true;
1026 	  --9614678
1027 
1028           ben_prtt_rt_val_api.update_prtt_rt_val
1029           (p_prtt_rt_val_id         => l_current_prv.prtt_rt_val_id
1030           ,p_person_id              => p_person_id
1031           ,p_rt_end_dt              => hr_api.g_eot
1032           ,p_business_group_id      => p_business_group_id
1033           ,p_object_version_number  => l_current_prv.object_version_number
1034           ,p_effective_date         => p_effective_date);
1035           --
1036        end if;
1037        --
1038     end if;
1039 
1040   end loop;
1041   close c_future_prv ;
1042 
1043   if g_debug then
1044     hr_utility.set_location(' Leaving:'||l_proc, 20);
1045   end if;
1046 
1047 end handle_overlap_rates;
1048 --
1049 --
1050 -- ----------------------------------------------------------------------------
1051 -- |-------------------< election_rate_information >-------------------------|
1052 -- ----------------------------------------------------------------------------
1053 procedure election_rate_information
1054   (p_calculate_only_mode in     boolean default false
1055   ,p_enrt_mthd_cd        in     varchar2
1056   ,p_effective_date      in     date
1057   ,p_prtt_enrt_rslt_id   in     number
1058   ,p_per_in_ler_id       in     number
1059   ,p_person_id           in     number
1060   ,p_pgm_id              in     number
1061   ,p_pl_id               in     number
1062   ,p_oipl_id             in     number
1063   ,p_enrt_rt_id          in     number
1064   ,p_prtt_rt_val_id      in out nocopy number
1065   ,p_rt_val              in     number
1066   ,p_ann_rt_val          in     number
1067   ,p_enrt_cvg_strt_dt    in     date
1068   ,p_acty_ref_perd_cd    in     varchar2
1069   ,p_datetrack_mode      in     varchar2
1070   ,p_business_group_id   in     number
1071   ,p_bnft_amt_changed    in     boolean default false
1072   ,p_ele_changed         in     boolean default null
1073   ,p_rt_strt_dt          in     date    default null
1074   ,p_rt_end_dt           in     date    default null
1075   --
1076   ,p_prv_rt_val             out nocopy number
1077   ,p_prv_ann_rt_val         out nocopy number
1078   ,p_imp_cvg_strt_dt     in  date default NULL)    -- 8716870
1079 is
1080   --
1081   -- Local variable declarations
1082   --
1083   l_proc         varchar2(72) := g_package||'election_rate_information';
1084   --
1085 
1086         l_rt_val                        number;
1087         l_ann_rt_val                    number;
1088         l_calc_ann_val                  number;
1089         l_prnt_rt_val                   number;
1090         t_old_tx_typ_cd                 varchar2(30);
1091         l_old_tx_typ_cd                 varchar2(30);
1092         l_old_acty_typ_cd               varchar2(30);
1093         l_old_mlt_cd                    varchar2(30);
1094         l_old_acty_ref_perd_cd          varchar2(30);
1095         l_old_rt_val                    number;
1096         l_old_prtt_enrt_rslt_id         number;
1097         l_old_business_group_id         number;
1098         l_old_object_version_number     number;
1099         l_old_rt_typ_cd                 varchar2(30);
1100         l_old_rt_strt_dt                date;
1101         l_old_ann_rt_val                number;
1102         l_old_bnft_rt_typ_cd            varchar2(30);
1103         l_old_cmcd_ref_perd_cd          varchar2(30);
1104         l_old_cmcd_rt_val               number;
1105         l_old_dsply_on_enrt_flag        varchar2(30);
1106         l_old_cvg_amt_calc_mthd_id      number;
1107         l_old_actl_prem_id              number;
1108         l_old_comp_lvl_fctr_id          number;
1109         l_old_rt_end_dt                 date;
1110         l_old_per_in_ler_id             number := null;
1111         l_effective_start_date          date;
1112         l_effective_end_date            date;
1113         l_elctns_made_dt                date;
1114         l_rt_ovridn_flag                varchar2(30);
1115         l_rt_ovridn_thru_dt             date;
1116         l_element_entry_value_id        number;
1117         l_old_elctns_made_dt            date;
1118         l_period_type                   varchar2(30);
1119         l_xenrt_cvg_strt_dt             date;
1120         l_xenrt_cvg_strt_dt_cd          varchar2(30);
1121         l_xenrt_cvg_strt_dt_rl          number;
1122         l_xrt_strt_dt                   date;
1123         l_xrt_strt_dt_cd                varchar2(30);
1124         l_xrt_strt_dt_rl                number;
1125         l_xenrt_cvg_end_dt              date;
1126         l_xenrt_cvg_end_dt_cd           varchar2(30);
1127         l_xenrt_cvg_end_dt_rl           number;
1128         l_xrt_end_dt                    date;
1129         l_xrt_end_dt_cd                 varchar2(30);
1130         l_xrt_end_dt_rl                 number;
1131         l_bnft_prvdd_ldgr_id            number;
1132         l_dummy_num                     number;
1133         l_dummy_varchar2                varchar2(80);
1134         l_dummy_date                    date;
1135         l_dummy_number                  number;
1136 
1137         l_lf_evt_ocrd_dt                date;
1138         l_old_rt_ovridn_flag            varchar2(30) := 'N';
1139         l_old_rt_ovridn_thru_dt         date;
1140         l_effective_date                date ;
1141         l_yp_start_date                 date;
1142         l_yp_end_date                   date; -- 9593336
1143         l_pay_start_date                date; -- 9593336
1144         l_old_element_entry_value_id    number;
1145         l_element_changed               boolean := false;
1146         l_non_recurring_rt              boolean := false;
1147         l_no_end_element                boolean := false;
1148         l_processing_type               varchar2(30);
1149         l_rt_end_dt                     date := p_rt_end_dt;
1150         l_element_type_id               number;
1151         l_sarec_compute                 boolean := true ;
1152         l_prnt_ann_val                  number;
1153         l_prnt_ann_rt                   varchar2(1) := 'N';
1154         l_rounded_value                 number;
1155         l_cal_val_in                    number ;
1156         l_global_asg_rec ben_global_enrt.g_global_asg_rec_type;
1157         l_global_pen_rec ben_prtt_enrt_rslt_f%rowtype;
1158         l_ele_entry_val_cd              varchar2(30);
1159         l_new_assignment_id             number;
1160         l_new_payroll_id                number;
1161         l_new_organization_id           number;
1162         l_assignment_id                 per_all_assignments_f.assignment_id%type;
1163         l_payroll_id                    per_all_assignments_f.payroll_id%type;
1164         l_organization_id               per_all_assignments_f.organization_id%type;
1165         l_ext_inpval_tab                ben_element_entry.ext_inpval_tab_typ;
1166         l_inpval_tab                    ben_element_entry.inpval_tab_typ;
1167         l_jurisdiction_code             varchar2(30);
1168         l_subpriority                   number;
1169         l_ext_inp_changed               boolean;
1170         l_old_assignment_id             number;
1171         l_old_payroll_id                number;
1172         l_old_organization_id           number;
1173   --
1174 
1175   --
1176   -- Cursor declarations.
1177   --
1178   -- Get the enrolment rate and activity base rate values
1179   cursor c_enrt_rt is
1180         select  abr.acty_base_rt_id,
1181                 abr.ele_rqd_flag,
1182                 abr.element_type_id,
1183                 abr.input_value_id,
1184                 abr.rcrrg_cd,
1185                 abr.use_calc_Acty_bs_rt_flag,
1186                 abr.entr_val_At_enrt_flag ,
1187                 abr.rt_typ_cd abr_typ_cd,
1188                 abr.val  abr_val,
1189                 abr.rndg_cd,
1190                 abr.rndg_rl,
1191                 abr.ele_entry_val_cd,
1192                 abr.input_va_calc_rl,
1193                 abr.effective_start_date abr_esd,
1194                 abr.effective_end_date abr_eed,
1195                 er.rt_typ_cd,
1196                 er.tx_typ_cd,
1197                 er.acty_typ_cd,
1198                 er.rt_mlt_cd,
1199                 er.rt_strt_dt,
1200                 er.rt_strt_dt_cd,
1201                 er.rt_strt_dt_rl,
1202                 er.bnft_rt_typ_cd,
1203                 er.cmcd_acty_ref_perd_cd,
1204                 er.val,
1205                 er.ann_val,
1206                 er.cmcd_val,
1207                 er.dsply_on_enrt_flag,
1208                 er.cvg_amt_calc_mthd_id,
1209                 er.actl_prem_id,
1210                 er.comp_lvl_fctr_id,
1211                 er.business_group_id,
1212                 nvl(eb.elig_per_elctbl_chc_id,
1213                     er.elig_per_elctbl_chc_id) elig_per_elctbl_chc_id,
1214                 er.entr_ann_val_flag,
1215                 er.prtt_rt_val_id,
1216                 er.decr_bnft_prvdr_pool_id,
1217                 nvl(eb.enrt_bnft_id,0) enrt_bnft_id,
1218                 nvl(eb.entr_val_at_enrt_flag,'N') entr_bnft_val_flag,
1219                 er.pp_in_yr_used_num,
1220                 er.ordr_num,
1221                 eb.cvg_mlt_cd,
1222                 abr.rate_periodization_rl, --GEVITY
1223                 nvl(eb.mx_wo_ctfn_flag,'N') interim_flag  --BUG 5502202
1224         from    ben_enrt_rt er,
1225                 ben_enrt_bnft eb,
1226                 ben_acty_base_rt_f abr
1227         where   er.enrt_rt_id=p_enrt_rt_id
1228         and     eb.enrt_bnft_id(+)=er.enrt_bnft_id
1229         and     er.acty_base_rt_id=abr.acty_base_rt_id
1230         and     ( (ben_manage_life_events.fonm = 'Y' and
1231                  nvl(nvl(p_rt_strt_dt,er.rt_strt_dt),l_effective_date) between
1232                  abr.effective_start_date and  abr.effective_end_date) or
1233                   (nvl(ben_manage_life_events.fonm,'N') = 'N'
1234                    and l_effective_date between abr.effective_start_date
1235                    and  abr.effective_end_date) ) ;
1236   l_enrt_rt c_enrt_rt%rowtype;
1237 
1238   -- Get the participant rate record
1239 
1240   cursor c_prtt_rt_val_1 is
1241         select  prv.rt_typ_cd,
1242                 prv.tx_typ_cd,
1243                 prv.acty_typ_cd,
1244                 prv.mlt_cd,
1245                 prv.acty_ref_perd_cd,
1246                 prv.rt_val,
1247                 prv.prtt_enrt_rslt_id,
1248                 prv.business_group_id,
1249                 prv.object_version_number,
1250                 prv.rt_strt_dt,
1251                 prv.ann_rt_val,
1252                 prv.bnft_rt_typ_cd,
1253                 prv.cmcd_ref_perd_cd,
1254                 prv.cmcd_rt_val,
1255                 prv.dsply_on_enrt_flag,
1256                 prv.cvg_amt_calc_mthd_id,
1257                 prv.actl_prem_id,
1258                 prv.comp_lvl_fctr_id,
1259                 prv.rt_end_dt,
1260                 prv.per_in_ler_id,
1261                 prv.element_entry_value_id,
1262                 prv.elctns_made_dt,
1263                 prv.rt_ovridn_flag,
1264                 prv.rt_ovridn_thru_dt
1265         from    ben_prtt_rt_val prv
1266         where   prtt_rt_val_id=l_enrt_rt.prtt_rt_val_id and
1267                 p_business_group_id=business_group_id;
1268 
1269   cursor c_prtt_rt_val_2 is
1270         select  prv.prtt_rt_val_id,
1271                 prv.rt_typ_cd,
1272                 prv.tx_typ_cd,
1273                 prv.acty_typ_cd,
1274                 prv.mlt_cd,
1275                 prv.acty_ref_perd_cd,
1276                 prv.rt_val,
1277                 prv.prtt_enrt_rslt_id,
1278                 prv.business_group_id,
1279                 prv.object_version_number,
1280                 prv.rt_strt_dt,
1281                 prv.ann_rt_val,
1282                 prv.bnft_rt_typ_cd,
1283                 prv.cmcd_ref_perd_cd,
1284                 prv.cmcd_rt_val,
1285                 prv.dsply_on_enrt_flag,
1286                 prv.cvg_amt_calc_mthd_id,
1287                 prv.actl_prem_id,
1288                 prv.comp_lvl_fctr_id,
1289                 prv.rt_end_dt,
1290                 prv.per_in_ler_id,
1291                 prv.element_entry_value_id,
1292                 prv.elctns_made_dt,
1293                 prv.rt_ovridn_flag,
1294                 prv.rt_ovridn_thru_dt
1295          from   ben_prtt_rt_val prv
1296         where   prv.acty_base_rt_id = l_enrt_rt.acty_base_rt_id
1297           and   prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
1298           and   prv.prtt_rt_val_stat_cd is null
1299           and   l_enrt_rt.rt_strt_dt between prv.rt_strt_dt
1300           and   prv.rt_end_dt
1301           and   p_business_group_id=prv.business_group_id;
1302 
1303 
1304   -- Parent rate information
1305   cursor c_abr2
1306     (c_effective_date in date,
1307      c_acty_base_rt_id in number
1308     )
1309   is
1310     select abr2.entr_val_at_enrt_flag,
1311            abr2.use_calc_acty_bs_rt_flag,
1312            abr2.acty_base_rt_id,
1313            abr2.rt_mlt_cd,
1314            abr2.entr_ann_val_flag
1315     from   ben_acty_base_rt_f abr,
1316            ben_acty_base_rt_f abr2
1317     where  abr.acty_base_rt_id = c_acty_base_rt_id
1318     and    abr2.acty_base_rt_id = abr.parnt_acty_base_rt_id
1319     and    abr2.parnt_chld_cd = 'PARNT'
1320     and    c_effective_date
1321            between abr.effective_start_date
1322            and     abr.effective_end_date
1323     and    c_effective_date
1324            between abr2.effective_start_date
1325            and  abr2.effective_end_date;
1326 
1327    l_prnt_abr      c_abr2%rowtype ;
1328   --
1329   cursor c_prv2
1330     (c_prtt_enrt_rslt_id  number,
1331      c_acty_base_rt_id  number,
1332      c_effective_date date              -- BUG 8244388
1333     )
1334    is
1335      select rt_val,
1336             ann_rt_val
1337      from ben_prtt_rt_val
1338      where acty_base_rt_id = c_acty_base_rt_id
1339        and prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
1340        and per_in_ler_id     = p_per_in_ler_id
1341          -- bug 6022111
1342          AND (   (    c_effective_date BETWEEN rt_strt_dt AND rt_end_dt
1343                   -- for recurring rate
1344                   AND rt_strt_dt < rt_end_dt
1345                  )
1346               OR (                                   -- for non-recurring rate
1347                       rt_strt_dt = rt_end_dt
1348                   AND rt_strt_dt <= c_effective_date
1349                   AND rt_strt_dt =
1350                          (SELECT MAX (rt_strt_dt)
1351                             FROM ben_prtt_rt_val
1352                            WHERE acty_base_rt_id = c_acty_base_rt_id
1353                              AND prtt_enrt_rslt_id = c_prtt_enrt_rslt_id
1354                              AND per_in_ler_id = p_per_in_ler_id
1355                              AND rt_strt_dt = rt_end_dt
1356                              AND prtt_rt_val_stat_cd IS NULL)
1357                  )
1358              )
1359          -- end bug 6022111
1360        and prtt_rt_val_stat_cd IS NULL ;  --BUG 4938498
1361   --
1362   cursor c_unrestricted is
1363                    select null
1364                    from   ben_per_in_ler pil,
1365                           ben_ler_f ler
1366                    where  pil.per_in_ler_id = p_per_in_ler_id
1367                    and    pil.ler_id = ler.ler_id
1368                    and    ler.typ_cd = 'SCHEDDU'
1369                    and    ler.business_group_id = p_business_group_id
1370                    and    p_effective_date between ler.effective_start_date
1371                           and ler.effective_end_date;
1372   --
1373 
1374   -- Bug 8374859
1375   cursor c_ler_id is
1376                    select ler.ler_id
1377                    from   ben_per_in_ler pil,
1378                           ben_ler_f ler
1379                    where  pil.per_in_ler_id = p_per_in_ler_id
1380                    and    pil.ler_id = ler.ler_id
1381                    and    ler.business_group_id = p_business_group_id
1382                    and    p_effective_date between ler.effective_start_date
1383                           and ler.effective_end_date;
1384 
1385   l_ler_id   number;
1386   -- Bug 8374859
1387 
1388   cursor c_pet is
1389      select pet.processing_type
1390      from   pay_element_types_f pet
1391      where  pet.element_type_id = l_enrt_rt.element_type_id
1392      and    l_effective_date between pet.effective_start_date
1393             and pet.effective_end_date;
1394   --
1395    cursor c_element_info (p_element_entry_value_id number,
1396                           p_prtt_enrt_rslt_id      number) is
1397       select elk.element_type_id,
1398              eev.input_value_id,
1399             -- asg.payroll_id,
1400              pee.element_entry_id,
1401             -- pee.assignment_id,
1402              pee.effective_end_date
1403       from   pay_element_links_f elk,
1404              per_all_assignments_f asg,
1405              pay_element_entries_f pee,
1406              pay_element_entry_values_f eev
1407       where  eev.element_entry_value_id = p_element_entry_value_id
1408       and    eev.element_entry_id = pee.element_entry_id
1409       and    pee.element_link_id = elk.element_link_id
1410       and    pee.effective_start_date between elk.effective_start_date
1411              and elk.effective_end_date
1412       and    eev.effective_start_date between pee.effective_start_date
1413              and pee.effective_end_date
1414       and    pee.creator_type = 'F'
1415       and    pee.creator_id = p_prtt_enrt_rslt_id
1416       and    asg.assignment_id = pee.assignment_id
1417       and    pee.effective_start_date between asg.effective_start_date
1418       and    asg.effective_end_date
1419    order by pee.effective_end_date desc ;
1420    l_element_info   c_element_info%rowtype;
1421 
1422    -- Bug 2675486
1423    CURSOR c_pl_popl_yr_period_current(cv_pl_id number,
1424                                       cv_pgm_id number,
1425                                       cv_lf_evt_ocrd_dt date ) IS
1426       SELECT   distinct yp.start_date
1427       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
1428       WHERE    ( pyp.pl_id = cv_pl_id or pyp.pgm_id = cv_pgm_id )
1429       AND      pyp.yr_perd_id = yp.yr_perd_id
1430       AND      pyp.business_group_id = p_business_group_id
1431       AND      cv_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
1432       AND      yp.business_group_id = p_business_group_id ;
1433    --
1434    -- Bug 9593336
1435    --
1436    CURSOR c_pay_period_strt_dt(p_effective_start_date date
1437                               ) IS
1438       SELECT   ptp.start_date -- 10058794
1439       FROM     per_time_periods ptp
1440               ,per_all_assignments_f asg
1441       WHERE    ptp.regular_payment_date >= p_effective_start_date -- 10058794
1442       and      ptp.payroll_id = asg.payroll_id
1443       AND      ptp.start_date <= p_effective_start_date
1444       AND      p_business_group_id = asg.business_group_id
1445       AND      asg.primary_flag = 'Y'
1446       AND      asg.person_id = p_person_id
1447       AND      p_effective_start_date
1448                between asg.effective_start_date
1449                    and asg.effective_end_date
1450       order by ptp.regular_payment_date;
1451    --
1452    -- end 9593336
1453   --
1454    cursor c_payroll_type_changed(
1455             cp_person_id number,
1456             cp_business_group_id number,
1457             cp_effective_date date,
1458             cp_orig_effective_date date
1459    ) is
1460    select pay.period_type
1461    from   per_all_assignments_f asg,
1462           pay_payrolls_f pay,
1463           per_all_assignments_f asg2,
1464           pay_payrolls_f pay2
1465    where  asg.person_id = cp_person_id
1466       and asg.assignment_type <> 'C'
1467       and asg.business_group_id = cp_business_group_id
1468       and asg.primary_flag = 'Y'
1469       and cp_effective_date between
1470           asg.effective_start_date and asg.effective_end_date
1471       and pay.payroll_id=asg.payroll_id
1472       and pay.business_group_id = asg.business_group_id
1473       and cp_effective_date between
1474           pay.effective_start_date and pay.effective_end_date
1475       and asg2.person_id = cp_person_id
1476       and   asg2.assignment_type <> 'C'
1477       and asg2.business_group_id = cp_business_group_id
1478       and asg2.primary_flag = 'Y'
1479       and cp_orig_effective_date between
1480           asg2.effective_start_date and asg2.effective_end_date
1481       and pay2.payroll_id=asg2.payroll_id
1482       and pay2.business_group_id = asg2.business_group_id
1483       and cp_orig_effective_date between
1484           pay2.effective_start_date and pay2.effective_end_date
1485       and pay2.period_type <> pay.period_type
1486       and asg.assignment_type = asg2.assignment_type ;
1487   --bug#3260564 -
1488     -----Bug 9143356
1489    cursor c_assignment_changed(
1490             cp_person_id number,
1491             cp_business_group_id number,
1492             cp_effective_date date,
1493             cp_orig_effective_date date
1494    ) is
1495    select 1
1496    from   per_all_assignments_f asg,
1497           per_all_assignments_f asg2
1498    where  asg.person_id = cp_person_id
1499       and asg.assignment_type <> 'C'
1500       and asg.business_group_id = cp_business_group_id
1501       and asg.primary_flag = 'Y'
1502       and cp_effective_date between
1503           asg.effective_start_date and asg.effective_end_date
1504       and asg2.person_id = cp_person_id
1505       and   asg2.assignment_type <> 'C'
1506       and asg2.business_group_id = cp_business_group_id
1507       and asg2.primary_flag = 'Y'
1508       and cp_orig_effective_date between
1509           asg2.effective_start_date and asg2.effective_end_date
1510       and asg.assignment_id <> asg2.assignment_id
1511       ;
1512 
1513    l_assignment_changed   c_assignment_changed%rowtype;
1514    -----Bug 9143356
1515     cursor c_future_rates (p_prtt_enrt_rslt_id number,
1516                            p_acty_base_rt_id   number,
1517                            p_rt_strt_dt        date,
1518                            p_per_in_ler_id     number) is
1519       select prv.prtt_rt_val_id,
1520              prv.rt_strt_dt,
1521              prv.acty_ref_perd_cd,
1522              prv.object_version_number
1523       from   ben_prtt_rt_val prv
1524       where  prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
1525       and    prv.acty_base_rt_id   = p_acty_base_rt_id
1526       and    prv.rt_strt_dt >= p_rt_strt_dt
1527       and    prv.per_in_ler_id <> p_per_in_ler_id
1528       and    prv.prtt_rt_val_stat_cd is null
1529       order  by rt_strt_dt desc;
1530   --
1531   l_future_rates    c_future_rates%rowtype;
1532   --
1533   cursor c_abr (p_acty_base_rt_id number,
1534                 p_effective_date  date) is
1535     select abr.ele_entry_val_cd,
1536            abr.element_type_id,
1537            abr.input_value_id
1538     from   ben_acty_base_rt_f abr
1539     where  abr.acty_base_rt_id = p_acty_base_rt_id
1540     and    p_effective_date between abr.effective_start_date
1541            and abr.effective_end_date;
1542   --
1543   cursor c_pl_name (p_pl_id number) is
1544     select name
1545     from  ben_pl_f pln
1546     where pln.pl_id = p_pl_id
1547     and   l_effective_date between
1548           pln.effective_start_date and pln.effective_end_date;
1549   --
1550    cursor c_epe  is
1551    select epe.fonm_cvg_strt_dt
1552      from ben_elig_per_elctbl_chc epe
1553     where epe.prtt_enrt_rslt_id  = p_prtt_enrt_rslt_id
1554       and epe.per_in_ler_id = p_per_in_ler_id;
1555 
1556 --
1557       CURSOR c_sspnd_enrt_rt (cv_elig_per_elctbl_chc_id IN NUMBER)
1558       IS
1559          SELECT abr.entr_val_at_enrt_flag, er.rt_mlt_cd,
1560                 NVL (eb.entr_val_at_enrt_flag, 'N') entr_bnft_val_flag,
1561                 eb.cvg_mlt_cd
1562            FROM ben_enrt_rt er,
1563                 ben_enrt_bnft eb,
1564                 ben_acty_base_rt_f abr,
1565                 ben_prtt_enrt_rslt_f pen
1566           WHERE eb.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1567             AND pen.rplcs_sspndd_rslt_id = p_prtt_enrt_rslt_id
1568             AND eb.elig_per_elctbl_chc_id = cv_elig_per_elctbl_chc_id
1569             AND pen.per_in_ler_id = p_per_in_ler_id
1570             AND eb.enrt_bnft_id = er.enrt_bnft_id
1571             AND er.acty_base_rt_id = abr.acty_base_rt_id
1572             AND l_effective_date BETWEEN pen.effective_start_date
1573                                      AND pen.effective_end_date
1574             AND (   (    ben_manage_life_events.fonm = 'Y'
1575                      AND NVL (er.rt_strt_dt, l_effective_date)
1576                             BETWEEN abr.effective_start_date
1577                                 AND abr.effective_end_date
1578                     )
1579                  OR (    NVL (ben_manage_life_events.fonm, 'N') = 'N'
1580                      AND l_effective_date BETWEEN abr.effective_start_date
1581                                               AND abr.effective_end_date
1582                     )
1583                 );
1584   --
1585   -- 7206471
1586 
1587    /* Added cursor for Bug 8945818: Get the previous per_in_ler_id */
1588    cursor c_prev_per_in_ler is
1589     select pil.per_in_ler_id
1590     from   ben_per_in_ler pil,
1591            ben_per_in_ler pil1,
1592            ben_ler_f ler
1593     where  pil1.per_in_ler_id = p_per_in_ler_id
1594     and    pil1.person_id = pil.person_id
1595     and    pil1.per_in_ler_id <> pil.per_in_ler_id
1596     and    pil.ler_id  = ler.ler_id
1597     and    p_effective_date between
1598            ler.effective_start_date and ler.effective_end_date
1599     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
1600     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
1601     order by pil.lf_evt_ocrd_dt desc;
1602 
1603     l_prev_pil_id number;
1604 
1605   --
1606 
1607 cursor c_get_prior_per_in_ler(c_rt_strt_dt date) is
1608    select 'Y'
1609    from   ben_per_in_ler pil, ben_per_in_ler pil2
1610    where  pil.per_in_ler_id <> p_per_in_ler_id
1611    /* Bug 8945818: Added 'or' condition. Check for future rates for the previous life event */
1612    and    ( (trunc(pil.lf_evt_ocrd_dt, 'MM') = trunc(pil2.lf_evt_ocrd_dt, 'MM')) or
1613             ('Y' =  ( select 'Y' from ben_prtt_rt_val prv,
1614                                       ben_prtt_enrt_rslt_f pen_n,
1615                                       ben_prtt_enrt_rslt_f pen_o
1616                       where pen_n.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
1617                             and pen_n.prtt_enrt_rslt_stat_cd is null
1618                             and pen_n.per_in_ler_id = p_per_in_ler_id
1619 			    /* Bug 10419741; If for previous life event there are no rate records created, using the value returned
1620 			       by the cursor c_prev_per_in_ler will not fetch any values */
1621                             and pen_o.per_in_ler_id in (select prv3.per_in_ler_id
1622                                       from ben_prtt_rt_val prv3,ben_prtt_enrt_rslt_f pen3
1623                                       where prv3.ended_per_in_ler_id = p_per_in_ler_id
1624                                             and pen3.prtt_enrt_rslt_id = prv3.prtt_enrt_rslt_id
1625                                             and pen3.per_in_ler_id = prv3.per_in_ler_id
1626                                             and pen3.enrt_cvg_strt_dt <= pen3.enrt_cvg_thru_dt
1627                                             and pen3.pl_typ_id = pen_n.pl_typ_id
1628                                             and pen3.prtt_enrt_rslt_stat_cd is null
1629                                             and prv3.PRTT_RT_VAL_STAT_CD is null)
1630                             and pen_n.ptip_id = pen_o.ptip_id
1631                             and pen_o.prtt_enrt_rslt_stat_cd is null
1632                             and pen_o.enrt_cvg_strt_dt <= pen_o.enrt_cvg_thru_dt
1633                             and pen_o.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
1634 			    /* Bug 10419741; If for previous life event there are no rate records created, using the value returned
1635 			       by the cursor c_prev_per_in_ler will not fetch any values */
1636                             and prv.per_in_ler_id in (select prv3.per_in_ler_id
1637                                       from ben_prtt_rt_val prv3,ben_prtt_enrt_rslt_f pen3
1638                                       where prv3.ended_per_in_ler_id = p_per_in_ler_id
1639                                             and pen3.prtt_enrt_rslt_id = prv3.prtt_enrt_rslt_id
1640                                             and pen3.per_in_ler_id = prv3.per_in_ler_id
1641                                             and pen3.enrt_cvg_strt_dt <= pen3.enrt_cvg_thru_dt
1642                                             and pen3.pl_typ_id = pen_n.pl_typ_id
1643                                             and pen3.prtt_enrt_rslt_stat_cd is null
1644                                             and prv3.PRTT_RT_VAL_STAT_CD is null)
1645 			    /*Bug 10137678: While adjusting the rates for overlapping rates, check for any rates that are end dating in the future
1646 			    in addition to checking for the rates that are starting the future */
1647                             and ( (c_rt_strt_dt <= prv.rt_strt_dt)
1648                                  or (prv.rt_strt_dt <= prv.rt_end_dt and c_rt_strt_dt <= prv.rt_end_dt)
1649                                 )
1650 			    and rownum = 1
1651                     ))
1652           )
1653    and    pil2.per_in_ler_id = p_per_in_ler_id
1654    and    pil2.person_id = p_person_id
1655    and    pil.person_id = p_person_id
1656    and    pil.business_group_id = pil2.business_group_id
1657    and    pil.business_group_id = p_business_group_id
1658    and    pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
1659 
1660   l_exists varchar2(2);
1661   --
1662   cursor c_get_pgm_extra_info is
1663   select pgi_information1
1664   from ben_pgm_extra_info
1665   where information_type = 'ADJ_RATE_PREV_LF_EVT'
1666   and pgm_id = p_pgm_id;
1667   --
1668   l_adjust varchar2(2);
1669   --
1670   cursor c_get_elctbl_chc is
1671    select min(ecr.rt_strt_dt) rt_strt_dt
1672          ,epe.ptip_id
1673    from ben_elig_per_elctbl_chc  epe
1674        ,ben_enrt_rt ecr
1675        ,ben_enrt_bnft enb
1676    where epe.per_in_ler_id = p_per_in_ler_id
1677    and   epe.business_group_id = p_business_group_id
1678    and   ecr.enrt_rt_id = p_enrt_rt_id -- Bug 8300620
1679    and   decode(ecr.enrt_bnft_id, null, ecr.elig_per_elctbl_chc_id,
1680          enb.elig_per_elctbl_chc_id) = epe.elig_per_elctbl_chc_id
1681    and   enb.enrt_bnft_id (+) = ecr.enrt_bnft_id
1682    and   ecr.rt_strt_dt is not null
1683    and   ecr.business_group_id = p_business_group_id
1684    group by epe.ptip_id;
1685 
1686    /* Bug 8507247:  If the plan is non FONM(Ex:First of Pay Period after Effective Date	) the RT_STRT_DT gets recalculated again in
1687    election_rate_information and the same is not updated back to ben_enrt_rt table. So we cannot use the
1688    min(rt_strt_dt) from ben_enrt_rt table to adjust the rates since the actual RT_STRT_DT has changed.
1689    Instead since the adjustment is always done just before creating the new rate, we already know the new rt_strt_dt
1690    from which we are going to create the new rate i.e. the variable l_enrt_rt.rt_strt_dt passed to create_prtt_rt_val.
1691    The same should be used for adjusting the ended rates.*/
1692    cursor c_get_ptip_id is
1693 	   select epe.ptip_id
1694 	   from ben_elig_per_elctbl_chc  epe
1695 	       ,ben_enrt_rt ecr
1696 	       ,ben_enrt_bnft enb
1697 	   where epe.per_in_ler_id = p_per_in_ler_id
1698 	   and   epe.business_group_id = p_business_group_id
1699 	   and   ecr.enrt_rt_id = p_enrt_rt_id
1700 	   and   decode(ecr.enrt_bnft_id, null, ecr.elig_per_elctbl_chc_id,
1701 		 enb.elig_per_elctbl_chc_id) = epe.elig_per_elctbl_chc_id
1702 	   and   enb.enrt_bnft_id (+) = ecr.enrt_bnft_id
1703 	   and   ecr.rt_strt_dt is not null
1704 	   and   ecr.business_group_id = p_business_group_id;
1705 
1706    l_ptip_id number;
1707 
1708    /* End of Bug 8507247*/
1709    --
1710    cursor c_get_enrt_rslts(p_rt_end_dt date
1711                          ,p_ptip_id   number
1712                           ) is
1713    select prv.*
1714          ,abr.element_type_id
1715          ,abr.input_value_id
1716          ,pen.person_id
1717    from ben_prtt_enrt_rslt_f pen
1718        ,ben_prtt_rt_val prv
1719        ,ben_acty_base_rt_f abr
1720    where pen.effective_end_date = hr_api.g_eot
1721    and   pen.enrt_cvg_thru_dt <> hr_api.g_eot
1722    and   pen.prtt_enrt_rslt_stat_cd is null
1723    and   pen.person_id =  p_person_id
1724    and   pen.business_group_id = p_business_group_id
1725    and   pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
1726    and   pen.ptip_id = p_ptip_id
1727    and   prv.prtt_rt_val_stat_cd is null
1728    and   prv.rt_end_dt >=  p_rt_end_dt
1729    and   prv.acty_base_rt_id = abr.acty_base_rt_id
1730    and   p_effective_date between abr.effective_start_date
1731                   and abr.effective_end_date;
1732    --
1733    cursor c_prtt_rt_val_adj (p_per_in_ler_id number,
1734                             p_prtt_rt_val_id number) is
1735    select null
1736    from ben_le_clsn_n_rstr
1737    where BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
1738    AND   BKUP_TBL_ID = p_prtt_rt_val_id
1739    AND   PER_IN_LER_ID  = p_per_in_ler_id;
1740 
1741    /* added for Bug  12576710 */
1742    cursor c_future_ended_rates(c_prtt_rt_val_id number
1743                          ,c_per_in_ler_id number
1744 			 ,c_rt_end_dt date
1745 			 ,c_acty_base_rt_id number) is
1746    select prv.* from
1747           ben_prtt_rt_val prv
1748 	  where prv.prtt_rt_val_id = c_prtt_rt_val_id
1749 	  and prv.rt_end_dt > c_rt_end_dt
1750 	  --and prv.ENDED_PER_IN_LER_ID <> c_per_in_ler_id
1751 	  and prv.prtt_rt_val_stat_cd is null
1752 	  and prv.acty_base_rt_id = c_acty_base_rt_id
1753 	  and prv.rt_end_dt <> hr_api.g_eot
1754 	  and not exists
1755 	      (select '1' from  ben_le_clsn_n_rstr bkp
1756                       where BKUP_TBL_TYP_CD = 'BEN_PRTT_RT_VAL_ADJ'
1757 		      and   BKUP_TBL_ID = c_prtt_rt_val_id
1758 		      and bkp.PER_IN_LER_ENDED_ID = c_per_in_ler_id
1759 		      and bkp.acty_base_rt_id = c_acty_base_rt_id);
1760 
1761   l_future_end_rec c_future_ended_rates%rowtype;
1762    --
1763 
1764    --8589355
1765    cursor c_get_opt_id(p_oipl_id number, p_rt_strt_dt date)
1766    is
1767    select oipl.opt_id
1768      from ben_oipl_f oipl
1769     where oipl.oipl_id = p_oipl_id
1770       and business_group_id = p_business_group_id
1771       and p_rt_strt_dt between oipl.effective_start_date and oipl.effective_end_date;
1772 
1773    l_get_opt_id c_get_opt_id%rowtype;
1774    --8589355
1775 
1776    -- end 7206471
1777   l_sspnd_enrt_rt                c_sspnd_enrt_rt%ROWTYPE;
1778 
1779   l_ann_mn_elcn_val  number := 0;
1780   l_ann_mx_elcn_val  number := 0;
1781   l_ptd_balance      number := 0;
1782   l_clm_balance      number := 0;
1783   l_pl_name          varchar2(240);
1784   --GEVITY
1785   l_dfnd_dummy number;
1786   l_ann_dummy  number;
1787   l_cmcd_dummy number;
1788   --END GEVITY
1789   l_fonm_cvg_strt_dt  date;
1790   l_input_value_id    number;
1791   l_global_pil_rec    ben_global_enrt.g_global_pil_rec_type;
1792   l_unrestricted      varchar2(1) := 'N';
1793   l_compute_val       number; --
1794   l_rt_val_param      number; --| 5259005 -- New vars to hold p_rt_val, p_ann_rt_val
1795   l_ann_rt_val_param  number; --|
1796   --
1797   begin
1798 
1799     g_debug := hr_utility.debug_enabled;
1800     if g_debug then
1801        hr_utility.set_location('Entering:'||l_proc, 5);
1802        hr_utility.set_location('enrt_rt:'||p_enrt_rt_id, 5);
1803        hr_utility.set_location('p_prtt_rt_val_id:'||p_prtt_rt_val_id,5);
1804        hr_utility.set_location('p_per_in_ler_id:'||p_per_in_ler_id,5);
1805     end if;
1806     --
1807     --Bug 8374859
1808     open c_ler_id;
1809     fetch c_ler_id into l_ler_id;
1810     close c_ler_id;
1811 
1812     ben_global_enrt.get_pil  -- per in ler
1813     (p_per_in_ler_id          => p_per_in_ler_id
1814     ,p_global_pil_rec         => l_global_pil_rec);
1815 
1816     l_lf_evt_ocrd_dt := l_global_pil_rec.lf_evt_ocrd_dt;
1817     --
1818     l_effective_date := nvl(l_lf_evt_ocrd_dt,p_effective_date);
1819 
1820     if l_global_pil_rec.typ_cd = 'SCHEDDU' then
1821        l_unrestricted := 'Y';
1822     end if;
1823 
1824     if ben_manage_life_events.fonm is null then
1825 
1826        open  c_epe;
1827        fetch c_epe into l_fonm_cvg_strt_dt;
1828        close c_epe;
1829 
1830        if l_fonm_cvg_strt_dt is not null then
1831           ben_manage_life_events.fonm := 'Y';
1832           ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
1833          /* 8716870: Code added for Imp Inc Enh starts*/
1834          if p_imp_cvg_strt_dt is not NULL and p_imp_cvg_strt_dt > l_fonm_cvg_strt_dt then
1835             ben_manage_life_events.g_fonm_cvg_strt_dt := p_imp_cvg_strt_dt;
1836          end if;
1837          /* Code added for Imp Inc Enh ends */
1838 
1839        else
1840           ben_manage_life_events.fonm := 'N';
1841           ben_manage_life_events.g_fonm_cvg_strt_dt := null;
1842           ben_manage_life_events.g_fonm_rt_strt_dt := null;
1843        end if;
1844     else
1845       if ben_manage_life_events.g_fonm_cvg_strt_dt is null and  ben_manage_life_events.fonm = 'Y'  then
1846          open  c_epe;
1847          fetch c_epe into l_fonm_cvg_strt_dt;
1848          close c_epe;
1849          ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
1850          /* 8716870: Code added for Imp Inc Enh starts*/
1851          hr_utility.set_location('p_imp_cvg_strt_dt '||p_imp_cvg_strt_dt,5);
1852          if p_imp_cvg_strt_dt is not NULL and p_imp_cvg_strt_dt > l_fonm_cvg_strt_dt then
1853             ben_manage_life_events.g_fonm_cvg_strt_dt := p_imp_cvg_strt_dt;
1854          end if;
1855         /* Code added for Imp Inc Enh ends */
1856 
1857       end if ;
1858 
1859     end if;
1860     --
1861     if p_bnft_amt_changed then
1862       if g_debug then
1863         hr_utility.set_location('p_bnft_amt changed:',5);
1864       end if;
1865     end if;
1866     --
1867     ben_det_enrt_rates.set_global_enrt_rt
1868        (p_enrt_rt_id   => p_enrt_rt_id);
1869     --
1870     -- Get the new values to be stored or updated
1871     --
1872     p_prtt_rt_val_id:=null;
1873 
1874     open c_enrt_rt;
1875     fetch c_enrt_rt into l_enrt_rt;
1876     if c_enrt_rt%notfound then
1877       close c_enrt_rt;
1878       fnd_message.set_name('BEN','BEN_91825_ENRT_RT_NOT_FOUND');
1879       fnd_message.set_token('PROC',l_proc);
1880       fnd_message.set_token('ENRT_RT_ID',to_char(p_enrt_rt_id));
1881       fnd_message.set_token('BG_ID',to_char(p_business_group_id));
1882       if g_debug then
1883         hr_utility.set_location('BEN_91825_ENRT_RT_NOT_FOUND', 20);
1884       end if;
1885       fnd_message.raise_error;
1886     end if;  -- notfound
1887     close c_enrt_rt;
1888 
1889     if ben_manage_life_events.fonm = 'Y' then
1890        ----Bug 7557403
1891        ben_manage_life_events.g_fonm_rt_strt_dt := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,
1892                                                    nvl(p_rt_strt_dt,l_enrt_rt.rt_strt_dt));
1893        ----Bug 7557403
1894        /* 8716870: Code added for Imp Inc Enh starts*/
1895        hr_utility.set_location('p_imp_cvg_strt_dt '||p_imp_cvg_strt_dt,7);
1896        if p_imp_cvg_strt_dt is not NULL and p_imp_cvg_strt_dt > nvl(p_rt_strt_dt,l_enrt_rt.rt_strt_dt) then
1897          ben_manage_life_events.g_fonm_rt_strt_dt :=  p_imp_cvg_strt_dt;
1898        end if;
1899        /* Code added for Imp Inc Enh ends */
1900        l_effective_date := nvl(ben_manage_life_events.g_fonm_rt_strt_dt,l_effective_date);
1901     end if;
1902 
1903     if g_debug then
1904       hr_utility.set_location(l_proc, 30);
1905     end if;
1906     --
1907     -- bug fix 3457483
1908     --
1909     -- Get the payroll id to be passed to ben_distribute_rates.
1910     --
1911     ben_element_entry.get_abr_assignment
1912      (p_person_id       => p_person_id
1913      ,p_effective_date  => l_effective_date
1914      ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
1915      ,p_organization_id => l_organization_id
1916      ,p_payroll_id      => l_payroll_id
1917      ,p_assignment_id   => l_assignment_id
1918      );
1919     -- end bug fix 3457483
1920     --
1921     if l_enrt_rt.cmcd_acty_ref_perd_cd = 'PPF' then
1922        l_element_type_id := l_enrt_rt.element_type_id;
1923     end if;
1924     --
1925     open c_pet;
1926     fetch c_pet into l_processing_type;
1927     close c_pet;
1928     --
1929     -- for non recurring rates the rate end date is assigned the rate start date
1930     --
1931     if l_processing_type = 'N' or
1932        l_enrt_rt.rcrrg_cd = 'ONCE' then
1933 
1934        l_non_recurring_rt := true;
1935        l_rt_end_dt := p_rt_strt_dt;
1936 
1937     end if;
1938     --
1939     if p_rt_strt_dt is not null and
1940        l_rt_end_dt is not null  and
1941        p_rt_strt_dt > l_rt_end_dt then
1942       --
1943       fnd_message.set_name('BEN','BEN_92688_RT_STRT_DT_GT_END_DT');
1944       fnd_message.set_token('START',p_rt_strt_dt);
1945       fnd_message.set_token('END',l_rt_end_dt);
1946       fnd_message.raise_error;
1947       --
1948     end if;
1949     --
1950     -- Get data from old rate
1951     --
1952     hr_utility.set_location(' BKKKK l_enrt_rt.prtt_rt_val_id ' || l_enrt_rt.prtt_rt_val_id, 300);
1953     hr_utility.set_location(' BKKKK p_enrt_rt_id ' || p_enrt_rt_id, 300);
1954     hr_utility.set_location(' BKKKK p_business_group_id  ' || p_business_group_id, 300);
1955     hr_utility.set_location(' BKKKK l_enrt_rt.elig_per_elctbl_chc_id ' || l_enrt_rt.elig_per_elctbl_chc_id, 300);
1956     --
1957     if l_enrt_rt.prtt_rt_val_id is not null then
1958       -- Get data from old rate
1959       open c_prtt_rt_val_1;
1960       fetch c_prtt_rt_val_1 into
1961         l_old_rt_typ_cd,
1962         l_old_tx_typ_cd,
1963         l_old_acty_typ_cd,
1964         l_old_mlt_cd,
1965         l_old_acty_ref_perd_cd,
1966         l_old_rt_val,
1967         l_old_prtt_enrt_rslt_id,
1968         l_old_business_group_id,
1969         l_old_object_version_number,
1970         l_old_rt_strt_dt,
1971         l_old_ann_rt_val,
1972         l_old_bnft_rt_typ_cd,
1973         l_old_cmcd_ref_perd_cd,
1974         l_old_cmcd_rt_val,
1975         l_old_dsply_on_enrt_flag,
1976         l_old_cvg_amt_calc_mthd_id,
1977         l_old_actl_prem_id,
1978         l_old_comp_lvl_fctr_id,
1979         l_old_rt_end_dt,
1980         l_old_per_in_ler_id,
1981         l_old_element_entry_value_id,
1982         l_old_elctns_made_dt,
1983         l_old_rt_ovridn_flag,
1984         l_old_rt_ovridn_thru_dt ;
1985 
1986       if c_prtt_rt_val_1%notfound then
1987         close c_prtt_rt_val_1;
1988         if g_debug then
1989           hr_utility.set_location('BEN_92103_NO_PRTT_RT_VAL', 35);
1990         end if;
1991         fnd_message.set_name('BEN','BEN_92103_NO_PRTT_RT_VAL');
1992         fnd_message.set_token('PROC',l_proc);
1993         fnd_message.set_token('PRTT_RT_VAL_ID',to_char(l_enrt_rt.prtt_rt_val_id));
1994         fnd_message.raise_error;
1995       end if;
1996 
1997       if g_debug then
1998          hr_utility.set_location('ll_old_rt_strt_dt'||l_old_rt_strt_dt,99);
1999          hr_utility.set_location('l_old_per_in_ler_id'||l_old_per_in_ler_id,99);
2000          hr_utility.set_location('l_old_rt end date'||l_old_rt_end_dt,99);
2001       end if;
2002       close c_prtt_rt_val_1;
2003     end if;
2004     --
2005     -- Get result information
2006     --
2007     ben_global_enrt.get_pen  -- result
2008        (p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
2009        ,p_effective_date         => p_effective_date
2010        ,p_global_pen_rec         => l_global_pen_rec);
2011 
2012     hr_utility.set_location('l_global_pen_rec',99);
2013     --
2014     -- determine rate start date as long as there is not an existing prtt_rt_val
2015     -- record, or if there is an exising prtt_rt_val record, that the record was
2016     -- NOT updated during this per-in-ler (bensuenr updates the rt-strt-dt).
2017     -- part of bug 1121022
2018     --
2019     if l_enrt_rt.rt_strt_dt_cd = 'ENTRBL' and p_rt_strt_dt is not null then
2020       -- The rate start date is the parameter value if the date code
2021       -- is enterable.
2022       l_enrt_rt.rt_strt_dt := p_rt_strt_dt;
2023     elsif l_enrt_rt.prtt_rt_val_id is not null and
2024           l_old_per_in_ler_id = p_per_in_ler_id and
2025           l_unrestricted = 'N' then -- #5303167
2026           hr_utility.set_location('l_global_pen_rec2',99);
2027        -- check unrestricted life event
2028        -- if l_unrestricted = 'N' then #5303167 moved this condition to above elsif
2029          --
2030          -- we already have the correct prv created
2031          --
2032          p_prtt_rt_val_id := l_enrt_rt.prtt_rt_val_id;
2033          if l_enrt_rt.rt_strt_dt_cd in ('FDPPFED','FDPPOED') then
2034            hr_utility.set_location('l_global_pen_rec3',99);
2035            ben_determine_date.main(
2036                p_date_cd                => l_enrt_rt.rt_strt_dt_cd,
2037                p_per_in_ler_id          => p_per_in_ler_id,
2038                p_person_id              => p_person_id,
2039                p_pgm_id                 => p_pgm_id,
2040                p_pl_id                  => p_pl_id,
2041                p_oipl_id                => p_oipl_id,
2042                p_business_group_id      => p_business_group_id,
2043                p_formula_id             => l_enrt_rt.rt_strt_dt_rl,
2044                p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id,
2045                p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id,
2046                p_effective_date         => p_effective_date,
2047                p_returned_date          => l_enrt_rt.rt_strt_dt
2048              );
2049          else
2050           --
2051           l_enrt_rt.rt_strt_dt := l_old_rt_strt_dt;
2052           --
2053          end if;
2054          --
2055        -- end if; #5303167
2056        --
2057     elsif l_enrt_rt.rt_strt_dt_cd is not null then
2058       if g_debug then
2059         hr_utility.set_location(l_proc, 40);
2060       end if;
2061       ben_determine_date.main(
2062         p_date_cd                => l_enrt_rt.rt_strt_dt_cd,
2063         p_per_in_ler_id          => p_per_in_ler_id,
2064         p_person_id              => p_person_id,
2065         p_pgm_id                 => p_pgm_id,
2066         p_pl_id                  => p_pl_id,
2067         p_oipl_id                => p_oipl_id,
2068         p_business_group_id      => p_business_group_id,
2069         p_formula_id             => l_enrt_rt.rt_strt_dt_rl,
2070         p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id,
2071         p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id,
2072         p_effective_date         => p_effective_date,
2073         p_returned_date          => l_enrt_rt.rt_strt_dt
2074       );
2075       --bug#4078828 - rate start date gets changed because of rate code based on election
2076       open c_abr (l_enrt_rt.acty_base_rt_id,l_enrt_rt.rt_strt_dt);
2077       fetch c_abr into l_ele_entry_val_cd, l_enrt_rt.element_type_id,
2078                         l_enrt_rt.input_value_id;
2079       close c_abr;
2080       --
2081     end if;
2082     if g_debug then
2083       hr_utility.set_location(l_proc, 45);
2084     end if;
2085     if (l_enrt_rt.rt_strt_dt is null) then
2086       if g_debug then
2087         hr_utility.set_location('BEN_91455_RT_STRT_DT_NOT_FOUND id:'||
2088           to_char(p_pl_id), 50);
2089       end if;
2090       fnd_message.set_name('BEN','BEN_91455_RT_STRT_DT_NOT_FOUND');
2091       fnd_message.set_token('PROC',l_proc);
2092       fnd_message.set_token('PLAN_ID', to_char(p_pl_id));
2093       fnd_message.raise_error;
2094     end if; -- date is null
2095 
2096     if p_prtt_rt_val_id is null then
2097 
2098        if  l_enrt_rt.prtt_rt_val_id is null or
2099            l_enrt_rt.rt_strt_dt < l_old_rt_strt_dt or
2100            l_enrt_rt.rt_strt_dt > l_old_rt_end_dt then
2101 
2102            open c_prtt_rt_val_2;
2103            fetch c_prtt_rt_val_2 into
2104            p_prtt_rt_val_id,
2105            l_old_rt_typ_cd,
2106            l_old_tx_typ_cd,
2107            l_old_acty_typ_cd,
2108            l_old_mlt_cd,
2109            l_old_acty_ref_perd_cd,
2110            l_old_rt_val,
2111            l_old_prtt_enrt_rslt_id,
2112            l_old_business_group_id,
2113            l_old_object_version_number,
2114            l_old_rt_strt_dt,
2115            l_old_ann_rt_val,
2116            l_old_bnft_rt_typ_cd,
2117            l_old_cmcd_ref_perd_cd,
2118            l_old_cmcd_rt_val,
2119            l_old_dsply_on_enrt_flag,
2120            l_old_cvg_amt_calc_mthd_id,
2121            l_old_actl_prem_id,
2122            l_old_comp_lvl_fctr_id,
2123            l_old_rt_end_dt,
2124            l_old_per_in_ler_id,
2125            l_old_element_entry_value_id,
2126            l_old_elctns_made_dt,
2127            l_old_rt_ovridn_flag,
2128            l_old_rt_ovridn_thru_dt ;
2129 
2130            if c_prtt_rt_val_2%notfound then
2131               p_prtt_rt_val_id := null;
2132               l_old_rt_typ_cd := null;
2133               l_old_tx_typ_cd := null;
2134               l_old_acty_typ_cd := null;
2135               l_old_mlt_cd := null;
2136               l_old_acty_ref_perd_cd := null;
2137               l_old_rt_val := null;
2138               l_old_prtt_enrt_rslt_id := null;
2139               l_old_business_group_id := null;
2140               l_old_object_version_number := null;
2141               l_old_rt_strt_dt := null;
2142               l_old_ann_rt_val := null;
2143               l_old_bnft_rt_typ_cd := null;
2144               l_old_cmcd_ref_perd_cd := null;
2145               l_old_cmcd_rt_val := null;
2146               l_old_dsply_on_enrt_flag := 'N' ; -- null; # 3273247
2147               l_old_cvg_amt_calc_mthd_id := null;
2148               l_old_actl_prem_id := null;
2149               l_old_comp_lvl_fctr_id := null;
2150               l_old_rt_end_dt := null;
2151               l_old_per_in_ler_id := null;
2152               l_old_element_entry_value_id := null;
2153               l_old_elctns_made_dt := null;
2154               l_old_rt_ovridn_flag := 'N' ; -- null; # 3273247
2155               l_old_rt_ovridn_thru_dt := null;
2156            end if;
2157            close c_prtt_rt_val_2;
2158        else
2159           p_prtt_rt_val_id := l_enrt_rt.prtt_rt_val_id;
2160        end if;
2161 
2162     end if;
2163     if g_debug then
2164        hr_utility.set_location('p_prtt_rt_val_id:'||p_prtt_rt_val_id, 3);
2165     end if;
2166     --
2167     --Bug#2734491 - Child rate should behave the same way as parent
2168     --
2169     if l_enrt_rt.rt_mlt_cd = 'PRNT' and l_enrt_rt.use_calc_acty_bs_rt_flag = 'Y' then
2170        /* BUG 8244388 open c_abr2 and c_prv2 with l_enrt_rt.rt_strt_dt instead of l_effective_date */
2171        open c_abr2(l_enrt_rt.rt_strt_dt,l_enrt_rt.acty_base_rt_id ) ;
2172        fetch c_abr2 into l_prnt_abr ;
2173        if c_abr2%found then
2174          if l_prnt_abr.rt_mlt_cd = 'SAREC' or l_prnt_abr.entr_ann_val_flag = 'Y' then
2175         --- take the rate from the parent rcord
2176             l_prnt_ann_rt := 'Y';
2177             open c_prv2(p_prtt_enrt_rslt_id,l_prnt_abr.acty_base_rt_id, l_enrt_rt.rt_strt_dt);
2178             fetch  c_prv2 into l_prnt_rt_val ,l_prnt_ann_val;
2179             close  c_prv2 ;
2180          end if ;
2181        end if;
2182        close c_abr2;
2183     end if;
2184 
2185   -- determine new rate values
2186   -- rajkiran
2187   -- Moved part of code below from Enrollment forms PL/SQl Libraries
2188   -- to have calculated values for p_rt_val, p_ann_rt_val
2189   --
2190   -- When the user has changed the value in ann_val, (which
2191   -- is an annual value), we need to compute the per-period
2192   -- value and put it into either the pre-tax val or after
2193   -- tax val depending on which enter_val_flag is on.
2194   -- We know if the user entered the value because then the
2195   -- ann_val and ann_val_hide are different.
2196   --
2197    l_ann_rt_val_param := p_ann_rt_val ;
2198    l_rt_val_param     := p_rt_val ;
2199   --
2200   hr_utility.set_location('l_ann_rt_val_param ->'||l_ann_rt_val_param,9);
2201   hr_utility.set_location('l_rt_val_param     ->'||l_rt_val_param    ,9);
2202   hr_utility.set_location('p_ann_rt_val ->'||p_ann_rt_val,9);
2203   hr_utility.set_location('p_rt_val     ->'||p_rt_val    ,9);
2204   --
2205   hr_utility.set_location('entr_ann_val ->'||l_enrt_rt.entr_ann_val_flag, 9);
2206   hr_utility.set_location('entr_val     ->'||l_enrt_rt.entr_val_at_enrt_flag, 9);
2207   --
2208   /*
2209    -- commented for bug: 5584813
2210    -- this code moved to a procedure calc_rt_ann_rt_vals
2211   if l_enrt_rt.entr_ann_val_flag = 'Y' then
2212         -- Enter Annual Value
2213         IF l_enrt_rt.rate_periodization_rl  IS NOT NULL AND
2214            l_enrt_rt.acty_base_rt_id        IS NOT NULL THEN
2215           --
2216           ben_element_entry.get_abr_assignment
2217               (p_person_id       => p_person_id
2218               ,p_effective_date  => l_effective_date
2219               ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
2220               ,p_organization_id => l_organization_id
2221               ,p_payroll_id      => l_payroll_id
2222               ,p_assignment_id   => l_assignment_id
2223               );
2224           --
2225           l_ann_dummy := p_ann_rt_val;
2226           --
2227           ben_distribute_rates.periodize_with_rule(
2228               p_formula_id             => l_enrt_rt.rate_periodization_rl
2229              ,p_effective_date         => l_effective_date
2230              ,p_assignment_id          => l_assignment_id
2231              ,p_convert_from_val       => l_ann_dummy
2232              ,p_convert_from           => 'ANNUAL'
2233              ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2234              ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2235              ,p_business_group_id      => p_business_group_id
2236              ,p_enrt_rt_id             => p_enrt_rt_id
2237              ,p_ann_val                => l_dfnd_dummy
2238              ,p_cmcd_val               => l_cmcd_dummy
2239              ,p_val                    => l_compute_val
2240           );
2241           --
2242         ELSE
2243          l_compute_val := ben_distribute_rates.annual_to_period(
2244                             p_amount  => p_ann_rt_val
2245                            ,p_enrt_rt_id => p_enrt_rt_id
2246                            ,p_elig_per_elctbl_chc_id => null
2247                            ,p_acty_ref_perd_cd => null
2248                            ,p_business_group_id => p_business_group_id
2249                            ,p_effective_date => l_effective_date
2250                            ,p_lf_evt_ocrd_dt => null
2251                            ,p_complete_year_flag => 'Y'
2252                            ,p_use_balance_flag => 'Y'
2253                            ,p_start_date => null
2254                            ,p_end_date => null);
2255          --
2256         END IF; --GEVITY
2257 	   l_rt_val_param := l_compute_val ;
2258   --
2259   -- When the user has changed the value in the pre-tax or
2260   -- after-tax columns, we must compute the annual value
2261   -- which goes into the bnft_val column.
2262   --
2263   elsif l_enrt_rt.entr_val_at_enrt_flag = 'Y' then
2264      --
2265          IF l_enrt_rt.rate_periodization_rl  IS NOT NULL AND
2266             l_enrt_rt.acty_base_rt_id        IS NOT NULL THEN
2267              --
2268              ben_element_entry.get_abr_assignment
2269               (p_person_id       => p_person_id
2270               ,p_effective_date  => l_effective_date
2271               ,p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id
2272               ,p_organization_id => l_organization_id
2273               ,p_payroll_id      => l_payroll_id
2274               ,p_assignment_id   => l_assignment_id
2275               );
2276              --
2277              l_dfnd_dummy := p_rt_val;
2278              --
2279              ben_distribute_rates.periodize_with_rule(
2280                  p_formula_id             => l_enrt_rt.rate_periodization_rl
2281                 ,p_effective_date         => l_effective_date
2282                 ,p_assignment_id          => l_assignment_id
2283                 ,p_convert_from_val       => l_dfnd_dummy
2284                 ,p_convert_from           => 'DEFINED'
2285                 ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2286                 ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2287                 ,p_business_group_id      => p_business_group_id
2288                 ,p_enrt_rt_id             => p_enrt_rt_id
2289                 ,p_ann_val                => l_compute_val
2290                 ,p_cmcd_val               => l_cmcd_dummy
2291                 ,p_val                    => l_cmcd_dummy
2292              );
2293              --
2294          ELSE
2295            l_compute_val := ben_distribute_rates.period_to_annual(
2296                             p_amount                 => p_rt_val
2297                            ,p_enrt_rt_id             => p_enrt_rt_id
2298                            ,p_elig_per_elctbl_chc_id => null
2299                            ,p_acty_ref_perd_cd       => null
2300                            ,p_business_group_id      => p_business_group_id
2301                            ,p_effective_date         => l_effective_date
2302                            ,p_lf_evt_ocrd_dt         => null
2303                            ,p_complete_year_flag     => 'Y'
2304                            ,p_use_balance_flag       => 'Y'
2305                            ,p_start_date             => null
2306                            ,p_end_date               => null);
2307          --
2308          END IF; --GEVITY
2309 	   l_ann_rt_val_param := l_compute_val;
2310       --
2311   end if;
2312   */
2313 
2314   calc_rt_ann_rt_vals (
2315    p_rt_val                  => l_rt_val_param,
2316    p_ann_rt_val              => l_ann_rt_val_param,
2317    p_person_id               => p_person_id,
2318    p_effective_date          => l_effective_date,
2319    p_acty_base_rt_id         => l_enrt_rt.acty_base_rt_id,
2320    p_rate_periodization_rl   => l_enrt_rt.rate_periodization_rl,
2321    p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2322    p_business_group_id       => p_business_group_id,
2323    p_enrt_rt_id              => p_enrt_rt_id,
2324    p_entr_ann_val_flag       => l_enrt_rt.entr_ann_val_flag,
2325    p_entr_val_at_enrt_flag   => l_enrt_rt.entr_val_at_enrt_flag);
2326 
2327 
2328   hr_utility.set_location('l_ann_rt_val_param ->'||l_ann_rt_val_param,9);
2329   hr_utility.set_location('l_rt_val_param     ->'||l_rt_val_param    ,9);
2330   hr_utility.set_location('p_ann_rt_val ->'||p_ann_rt_val,9);
2331   hr_utility.set_location('p_rt_val     ->'||p_rt_val    ,9);
2332 
2333   -- rajkiran
2334 
2335     --
2336     --bug 1888085 we need to eliminate the following 'PCT' condition if
2337     --use_calc_acty_bs_rt_flag is set to 'Y'
2338     --
2339     if l_enrt_rt.rt_typ_cd = 'PCT' and l_enrt_rt.use_calc_acty_bs_rt_flag <> 'Y' then
2340       if l_enrt_rt.entr_ann_val_flag = 'Y' then
2341         --
2342         -- get values from annual value
2343         --
2344         l_ann_rt_val       := l_ann_rt_val_param; -- changed from p_ann_rt_val to l_ann_rt_val_param
2345         l_rt_val           := l_ann_rt_val_param;
2346         l_enrt_rt.cmcd_val := l_ann_rt_val_param;
2347       else
2348         --
2349         -- get values from periodic value
2350         --
2351         l_ann_rt_val       := l_rt_val_param; -- changed from p_rt_val to l_rt_val_param
2352         l_rt_val           := l_rt_val_param;
2353         l_enrt_rt.cmcd_val := l_rt_val_param;
2354         --
2355       end if;
2356       --
2357     else
2358       --
2359       if l_enrt_rt.entr_ann_val_flag = 'Y' or l_prnt_ann_rt = 'Y' then
2360         --
2361         if g_debug then
2362           hr_utility.set_location('enter annual value',100);
2363         end if;
2364         if l_rt_val_param is null then -- changed from p_rt_val to l_rt_val_param
2365           --
2366           --GEVITY
2367           --
2368           IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2369             --
2370             l_ann_dummy := l_ann_rt_val_param ; --p_ann_rt_val; 5259005
2371             --
2372             ben_distribute_rates.periodize_with_rule
2373                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2374                   ,p_effective_date         => l_effective_date
2375                   ,p_assignment_id          => l_assignment_id
2376                   ,p_convert_from_val       => l_ann_dummy
2377                   ,p_convert_from           => 'ANNUAL'
2378                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2379                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2380                   ,p_business_group_id      => p_business_group_id
2381                   ,p_enrt_rt_id             => p_enrt_rt_id
2382                   ,p_ann_val                => l_ann_rt_val
2383                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2384                   ,p_val                    => l_rt_val
2385             );
2386             --
2387           ELSE
2388             -- use ann_rt_val to drive other values
2389             --
2390             --
2391             l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2392                   (p_amount                  => l_ann_rt_val_param, -- p_ann_rt_val, 5259005
2393                    p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2394                    p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2395                    p_business_group_id       => p_business_group_id,
2396                    p_effective_date          => l_effective_date,
2397                    p_complete_year_flag      => 'Y',
2398                    p_payroll_id              => l_payroll_id,
2399                    p_element_type_id         => l_element_type_id,
2400                    p_person_id               => p_person_id
2401                    );
2402             --Bug#3540351
2403             if l_enrt_rt.cmcd_val < 0 then
2404                l_enrt_rt.cmcd_val := 0;
2405                l_rt_val := 0;
2406             else
2407               --Bug 3253180
2408               --l_rt_val:= l_enrt_rt.cmcd_val;
2409               --
2410               l_rt_val := ben_distribute_rates.annual_to_period
2411                       (p_amount                  => l_ann_rt_val_param, --p_ann_rt_val, 5259005
2412                        p_enrt_rt_id              => p_enrt_rt_id,
2413                        p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2414                        p_business_group_id       => p_business_group_id,
2415                        p_effective_date          => l_effective_date,
2416                        p_complete_year_flag      => 'Y',
2417                        p_use_balance_flag        => 'Y',
2418                        p_payroll_id              => l_payroll_id,
2419                        p_element_type_id         => l_element_type_id,
2420                        p_rounding_flag           => 'N',
2421                        p_person_id               => p_person_id
2422                        );
2423            end if;
2424             --
2425             l_rt_val := round(l_rt_val,4);
2426             l_ann_rt_val := l_ann_rt_val_param; --p_ann_rt_val; 5259005
2427             --
2428           END IF; --GEVITY
2429           --
2430           if g_debug then
2431             hr_utility.set_location('IK p_rt_val is null l_rt_val '||l_rt_val,101);
2432             hr_utility.set_location('IK p_rt_val is null l_ann_rt_val: '||l_ann_rt_val,101);
2433             hr_utility.set_location('IK p_rt_val is null l_enrt_rt.cmcd_val'||l_enrt_rt.cmcd_val,101);
2434           end if;
2435           --
2436         else
2437           --this condition added if the l_rt_val is not gone throu the post enrl calc
2438           -- then intialised here
2439           /*
2440           if l_rt_val is null then
2441              l_rt_val:=p_rt_val;
2442              l_ann_rt_val:=p_ann_rt_val;
2443           end if ;
2444           */
2445           --
2446           l_ann_rt_val := l_ann_rt_val_param; -- p_ann_rt_val; 5259005
2447           --
2448           -- calculate annual rate for the child
2449           if l_prnt_ann_rt = 'Y' then
2450              --
2451              if g_debug then
2452                hr_utility.set_location('Annual value'||l_prnt_ann_val,11);
2453              end if;
2454              benutils.rt_typ_calc
2455               (p_rt_typ_cd      => l_enrt_rt.abr_typ_cd
2456               ,p_val            => l_enrt_rt.abr_val
2457               ,p_val_2          => l_prnt_ann_val
2458               ,p_calculated_val => l_ann_rt_val);
2459              --
2460              if (l_enrt_rt.rndg_cd is not null or
2461                    l_enrt_rt.rndg_rl is not null) then
2462                --
2463                 l_rounded_value := benutils.do_rounding
2464                   (p_rounding_cd     => l_enrt_rt.rndg_cd,
2465                    p_rounding_rl     => l_enrt_rt.rndg_rl,
2466                    p_value           => l_ann_rt_val,
2467                    p_effective_date  => l_effective_date);
2468                 l_ann_rt_val := l_rounded_value;
2469              end if;
2470              --
2471              --GEVITY
2472              --
2473              IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2474                --
2475                l_ann_dummy := l_ann_rt_val;
2476                --
2477                ben_distribute_rates.periodize_with_rule
2478                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2479                   ,p_effective_date         => l_effective_date
2480                   ,p_assignment_id          => l_assignment_id
2481                   ,p_convert_from_val       => l_ann_dummy
2482                   ,p_convert_from           => 'ANNUAL'
2483                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2484                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2485                   ,p_business_group_id      => p_business_group_id
2486                   ,p_enrt_rt_id             => p_enrt_rt_id
2487                   ,p_ann_val                => l_ann_rt_val
2488                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2489                   ,p_val                    => l_rt_val
2490                );
2491                --
2492              ELSE
2493                --
2494                l_rt_val := ben_distribute_rates.annual_to_period(
2495                                       p_amount  => l_ann_rt_val
2496                                      ,p_enrt_rt_id =>p_enrt_rt_id
2497                                      ,p_elig_per_elctbl_chc_id => null
2498                                      ,p_acty_ref_perd_cd => null
2499                                      ,p_business_group_id =>p_business_group_id
2500                                      ,p_effective_date => l_effective_date
2501                                      ,p_lf_evt_ocrd_dt => null
2502                                      ,p_complete_year_flag => 'Y'
2503                                      ,p_use_balance_flag => 'Y'
2504                                      ,p_start_date => null
2505                                      ,p_end_date => null
2506                                      ,p_rounding_flag => 'N'
2507                                      ,p_person_id     => p_person_id); --Bug 2149438
2508                 --
2509                 -- Bug 2149438 I am doing it to 3 because right now we have 2 digit rouding for
2510                 -- the final value. Once we implement the rounding completely for the
2511                 -- rate value this needs to be atleast one digit more than the
2512                 -- actual rounding code dictates.
2513                 --
2514                 if l_rt_val < 0 then
2515                    l_rt_val := 0;
2516                    l_enrt_rt.cmcd_val := 0;
2517                 else
2518                   --
2519                   --
2520                   --
2521                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2522                       (p_amount                  => l_ann_rt_val,
2523                        --p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2524                        p_enrt_rt_id              => p_enrt_rt_id,
2525                        p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2526                        p_business_group_id       => p_business_group_id,
2527                        p_effective_date          => l_effective_date,
2528                        p_use_balance_flag        => 'Y',
2529                --      p_complete_year_flag      => 'Y',
2530                        p_start_date              => l_enrt_rt.rt_strt_dt,
2531                        p_payroll_id              => l_payroll_id,
2532                        p_element_type_id         => l_element_type_id,
2533                        p_person_id               => p_person_id
2534                        );
2535                 end if;
2536                 --
2537              END IF; --GEVITY
2538           else -- let us find the right l_rt_val for annual rate using proper rounding
2539             -- Bug 2833116
2540             -- Bug 2675486 fixes for FSA
2541             l_sarec_compute := true;
2542             if l_old_ann_rt_val = l_ann_rt_val and l_old_rt_strt_dt is not null
2543                and l_enrt_rt.rate_periodization_rl IS NULL then
2544               -- Case - Benefit amount not changed and currently enrolled case
2545               -- See if the current rate is started in the present popl yr period.
2546               -- If started in current yr_perd then DONT compute defined and comm amounts
2547               -- else compute the defined comm amounts.
2548               -- l_sarec_compute
2549               open c_pl_popl_yr_period_current(p_pl_id,p_pgm_id,l_effective_date);
2550                 fetch c_pl_popl_yr_period_current into l_yp_start_date;
2551               close c_pl_popl_yr_period_current ;
2552               --
2553               --  9593336 - Get the payroll year start date
2554               --
2555               open c_pay_period_strt_dt(l_yp_start_date
2556                                        );
2557               fetch c_pay_period_strt_dt into l_pay_start_date;
2558               close c_pay_period_strt_dt;
2559               hr_utility.set_location('Pay Period Start Date '||l_pay_start_date,123);
2560               hr_utility.set_location('l_old_rt_strt_dt '||l_old_rt_strt_dt,123);
2561               --
2562               -- End 9593336
2563               --
2564               if ((l_old_rt_strt_dt >= l_yp_start_date) or
2565                   (l_old_rt_strt_dt >= l_pay_start_date)) then -- 9593336
2566                 --
2567                 -- Already enrolled in the same yr_perd and amount not changed so
2568                 -- dont recompute the amounts
2569                   --bug#3364910 - check for payroll type change
2570                     l_period_type:=null;
2571                     open c_payroll_type_changed(
2572                           cp_person_id           =>p_person_id,
2573                           cp_business_group_id   =>p_business_group_id,
2574                           cp_effective_date      =>l_enrt_rt.rt_strt_dt,
2575                           cp_orig_effective_date =>l_old_rt_strt_dt);
2576                     fetch c_payroll_type_changed into l_period_type;
2577                     close c_payroll_type_changed;
2578                --      no change in payroll then dont recompute
2579                     if l_period_type is null then
2580 
2581                        if g_debug then
2582                          hr_utility.set_location('Same Yr Period and same rate ' ,123);
2583                        end if;
2584                        l_sarec_compute := false ;
2585                     end if;
2586               end if ;
2587               --
2588             end if ;
2589             --
2590             if l_sarec_compute then
2591               --GEVITY
2592               --
2593               IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
2594                 --
2595                 l_ann_dummy := l_ann_rt_val;
2596                 --
2597                 ben_distribute_rates.periodize_with_rule
2598                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
2599                   ,p_effective_date         => l_effective_date
2600                   ,p_assignment_id          => l_assignment_id
2601                   ,p_convert_from_val       => l_ann_dummy
2602                   ,p_convert_from           => 'ANNUAL'
2603                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
2604                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
2605                   ,p_business_group_id      => p_business_group_id
2606                   ,p_enrt_rt_id             => p_enrt_rt_id
2607                   ,p_ann_val                => l_ann_rt_val
2608                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
2609                   ,p_val                    => l_rt_val
2610                 );
2611                 --
2612               ELSE
2613                 --
2614                 l_rt_val := ben_distribute_rates.annual_to_period
2615                       (p_amount                  => l_ann_rt_val,
2616                        p_enrt_rt_id              => p_enrt_rt_id,
2617                        p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
2618                        p_business_group_id       => p_business_group_id,
2619                        p_effective_date          => l_effective_date,
2620                        p_complete_year_flag      => 'Y',
2621                        p_use_balance_flag        => 'Y',
2622                        p_payroll_id              => l_payroll_id,
2623                        p_element_type_id         => l_element_type_id,
2624                        p_rounding_flag           => 'N',
2625                        p_person_id               => p_person_id
2626                        );
2627                 --
2628                 if l_rt_val < 0 then
2629                    l_rt_val := 0;
2630                    l_enrt_rt.cmcd_val := 0;
2631                 else
2632                   --
2633                   l_rt_val := round(l_rt_val,4);
2634                   --
2635                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
2636                         (p_amount                  => l_ann_rt_val,
2637                          --p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
2638                          p_enrt_rt_id              => p_enrt_rt_id,
2639                          p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
2640                          p_business_group_id       => p_business_group_id,
2641                          p_effective_date          => l_effective_date,
2642                          p_use_balance_flag        => 'Y',
2643                          -- p_complete_year_flag      => 'Y',
2644                          p_start_date              => l_enrt_rt.rt_strt_dt,
2645                          p_payroll_id              => l_payroll_id,
2646                          p_element_type_id         => l_element_type_id,
2647                          p_person_id               => p_person_id
2648                          );
2649                   --
2650                 end if;
2651                 --
2652               END IF; --GEVITY
2653               --
2654               if g_debug then
2655                  hr_utility.set_location('IK p_rt_val is NOT null l_rt_val '||l_rt_val,101);
2656                  hr_utility.set_location('IK p_rt_val is NOT null l_ann_rt_val: '||l_ann_rt_val,101);
2657                  hr_utility.set_location('IK p_rt_val is NOT null l_enrt_rt.cmcd_val'||l_enrt_rt.cmcd_val,101);
2658               end if;
2659               --
2660             else
2661               --
2662               l_rt_val           := l_old_rt_val ;
2663               l_calc_ann_val     := l_ann_rt_val;
2664               l_enrt_rt.cmcd_val := l_old_cmcd_rt_val ;
2665               --
2666               if g_debug then
2667                 hr_utility.set_location('Continue old rate '||l_old_rt_val,123);
2668               end if;
2669               --
2670               if g_debug then
2671                 hr_utility.set_location(' l_old_cmcd_rt_val '||l_old_cmcd_rt_val,123);
2672               end if;
2673               --
2674             end if;  -- l_sarec_compute
2675             --
2676           end if;
2677           -- ann_rt_val and rt_val are set, set locals
2678           --
2679         end if;
2680       else
2681         --
2682         -- annual not entered
2683         --
2684        if l_enrt_rt.rt_mlt_cd <> 'SAREC' then
2685          --
2686          -- If the rate is based on coverage and the coverage value is entered
2687          -- at enrollment, we must re-calculate the rate value.
2688          --
2689          /*BUG 3804813 We don't need to check for l_enrt_rt.rt_mlt_cd <> 'FLFX'
2690            Lets recompute id entr_bnft_val_flag = 'Y' which makes perfect sense.
2691          if (l_enrt_rt.entr_bnft_val_flag = 'Y' and
2692             l_enrt_rt.rt_mlt_cd <> 'FLFX') or
2693              l_enrt_rt.rt_mlt_cd = 'ERL'or
2694              l_enrt_rt.cvg_mlt_cd = 'ERL'  then -- ERL added for canon fix
2695            if g_debug then
2696              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 312);
2697              hr_utility.set_location( 'l_global_pen_rec.bnft_am'||l_global_pen_rec.bnft_amt ,314);
2698            end if;
2699          --BUG 3804813  */
2700          --START BUG 3804813
2701          if (l_enrt_rt.entr_bnft_val_flag = 'Y' OR
2702              l_enrt_rt.interim_flag = 'Y' OR   --For Interim Rule BUG 5502202
2703              l_enrt_rt.rt_mlt_cd = 'ERL'or
2704              l_enrt_rt.cvg_mlt_cd = 'ERL') -- ERL added for canon fix
2705          and l_enrt_rt.entr_val_at_enrt_flag = 'N' then -- Bug 4710188, Calling rates pack
2706                                                         -- rate is not enterable only when
2707            if g_debug then
2708              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 312);
2709              hr_utility.set_location('l_rt_val_param'||to_char(l_rt_val_param), 312);
2710              hr_utility.set_location( 'l_global_pen_rec.bnft_am'||l_global_pen_rec.bnft_amt ,314);
2711            end if;
2712            --END BUG 3804813
2713            if l_enrt_rt.enrt_bnft_id = 0 then
2714              l_enrt_rt.enrt_bnft_id := null;
2715            end if;
2716            ben_determine_activity_base_rt.main
2717              (p_person_id                  => p_person_id
2718              ,p_elig_per_elctbl_chc_id      => l_enrt_rt.elig_per_elctbl_chc_id
2719              ,p_enrt_bnft_id                => l_enrt_rt.enrt_bnft_id
2720              ,p_acty_base_rt_id             => l_enrt_rt.acty_base_rt_id
2721              ,p_effective_date              => p_effective_date
2722              ,p_per_in_ler_id               => p_per_in_ler_id
2723              ,p_lf_evt_ocrd_dt              => l_lf_evt_ocrd_dt -- Added Bug 3488286
2724              ,p_pl_id                       => p_pl_id
2725              ,p_pgm_id                      => p_pgm_id
2726              ,p_oipl_id                     => p_oipl_id
2727              ,p_pl_typ_id                   => l_global_pen_rec.pl_typ_id
2728              ,p_ler_id                      => l_ler_id -- Bug 8374859
2729              ,p_business_group_id           => p_business_group_id
2730              ,p_perform_rounding_flg        => true
2731              ,p_calc_only_rt_val_flag       => true
2732              ,p_bnft_amt                    => l_global_pen_rec.bnft_amt
2733              -- the following are all out parms:  the only ones we want are rate values.
2734              ,p_val                         => l_rt_val
2735              ,p_mn_elcn_val                 => l_dummy_num
2736              ,p_mx_elcn_val                 => l_dummy_num
2737              ,p_ann_val                     => l_ann_rt_val
2738              ,p_ann_mn_elcn_val             => l_dummy_num
2739              ,p_ann_mx_elcn_val             => l_dummy_num
2740              ,p_cmcd_val                    => l_dummy_num
2741              ,p_cmcd_mn_elcn_val            => l_dummy_num
2742              ,p_cmcd_mx_elcn_val            => l_dummy_num
2743              ,p_cmcd_acty_ref_perd_cd       => l_dummy_varchar2
2744              ,p_incrmt_elcn_val             => l_dummy_num
2745              ,p_dflt_val                    => l_dummy_num
2746              ,p_tx_typ_cd                   => l_dummy_varchar2
2747              ,p_acty_typ_cd                 => l_dummy_varchar2
2748              ,p_nnmntry_uom                 => l_dummy_varchar2
2749              ,p_entr_val_at_enrt_flag       => l_dummy_varchar2
2750              ,p_dsply_on_enrt_flag          => l_dummy_varchar2
2751              ,p_use_to_calc_net_flx_cr_flag => l_dummy_varchar2
2752              ,p_rt_usg_cd                   => l_dummy_varchar2
2753              ,p_bnft_prvdr_pool_id          => l_dummy_num
2754              ,p_actl_prem_id                => l_dummy_num
2755              ,p_cvg_calc_amt_mthd_id        => l_dummy_num
2756              ,p_bnft_rt_typ_cd              => l_dummy_varchar2
2757              ,p_rt_typ_cd                   => l_dummy_varchar2
2758              ,p_rt_mlt_cd                   => l_dummy_varchar2
2759              ,p_comp_lvl_fctr_id            => l_dummy_num
2760              ,p_entr_ann_val_flag           => l_dummy_varchar2
2761              ,p_ptd_comp_lvl_fctr_id        => l_dummy_num
2762              ,p_clm_comp_lvl_fctr_id        => l_dummy_num
2763              ,p_ann_dflt_val                => l_dummy_num
2764              ,p_rt_strt_dt                  => l_dummy_date
2765              ,p_rt_strt_dt_cd               => l_dummy_varchar2
2766              ,p_rt_strt_dt_rl               => l_dummy_num
2767              ,p_prtt_rt_val_id              => l_dummy_num
2768              ,p_dsply_mn_elcn_val           => l_dummy_num
2769              ,p_dsply_mx_elcn_val           => l_dummy_num
2770              ,p_pp_in_yr_used_num           => l_dummy_num
2771              ,p_ordr_num                => l_dummy_num
2772              ,p_iss_val                     =>l_dummy_num
2773              );
2774            if g_debug then
2775              hr_utility.set_location('l_rt_val'||to_char(l_rt_val), 312);
2776            end if;
2777 
2778          ELSE -- 5375381 :Added else part
2779 	       /* This is purely for Interim pen which has has same epe as of its Sspndd pen.
2780 	        And sspndd pen has entr_bnft_val_flag = 'Y'
2781 	       */
2782                   OPEN c_sspnd_enrt_rt (l_enrt_rt.elig_per_elctbl_chc_id);
2783                   FETCH c_sspnd_enrt_rt INTO l_sspnd_enrt_rt;
2784                   CLOSE c_sspnd_enrt_rt;
2785 
2786                   IF     l_enrt_rt.entr_val_at_enrt_flag = 'N'
2787                      AND (    (   l_sspnd_enrt_rt.entr_bnft_val_flag = 'Y'
2788                                OR l_sspnd_enrt_rt.rt_mlt_cd = 'ERL'
2789                                OR l_sspnd_enrt_rt.cvg_mlt_cd = 'ERL'
2790                               )
2791                           AND l_sspnd_enrt_rt.entr_val_at_enrt_flag = 'N'
2792                          )
2793                   THEN
2794                      IF g_debug
2795                      THEN
2796                         hr_utility.set_location (   'p_rt_val'
2797                                                  || TO_CHAR (p_rt_val),
2798                                                  555
2799                                                 );
2800                         hr_utility.set_location (   'l_rt_val_param'
2801                                                  || TO_CHAR (l_rt_val_param),
2802                                                  555
2803                                                 );
2804                         hr_utility.set_location (   'l_global_pen_rec.bnft_am'
2805                                                  || l_global_pen_rec.bnft_amt,
2806                                                  555
2807                                                 );
2808                      END IF;
2809 
2810                      IF l_enrt_rt.enrt_bnft_id = 0
2811                      THEN
2812                         l_enrt_rt.enrt_bnft_id := NULL;
2813                      END IF;
2814 
2815                      ben_determine_activity_base_rt.main (p_person_id                        => p_person_id,
2816                                                           p_elig_per_elctbl_chc_id           => l_enrt_rt.elig_per_elctbl_chc_id,
2817                                                           p_enrt_bnft_id                     => l_enrt_rt.enrt_bnft_id,
2818                                                           p_acty_base_rt_id                  => l_enrt_rt.acty_base_rt_id,
2819                                                           p_effective_date                   => p_effective_date,
2820                                                           p_per_in_ler_id                    => p_per_in_ler_id,
2821                                                           p_lf_evt_ocrd_dt                   => l_lf_evt_ocrd_dt, -- Added Bug 3488286
2822 
2823                                                           p_pl_id                            => p_pl_id,
2824                                                           p_pgm_id                           => p_pgm_id,
2825                                                           p_oipl_id                          => p_oipl_id,
2826                                                           p_pl_typ_id                        => l_global_pen_rec.pl_typ_id,
2827                                                           p_ler_id                           => l_ler_id,  -- Bug 8374859
2828                                                           p_business_group_id                => p_business_group_id,
2829                                                           p_perform_rounding_flg             => TRUE,
2830                                                           p_calc_only_rt_val_flag            => TRUE,
2831                                                           p_bnft_amt                         => l_global_pen_rec.bnft_amt,-- the following are all out parms:  the only ones we want are rate values.
2832 
2833                                                           p_val                              => l_rt_val,
2834                                                           p_mn_elcn_val                      => l_dummy_num,
2835                                                           p_mx_elcn_val                      => l_dummy_num,
2836                                                           p_ann_val                          => l_ann_rt_val,
2837                                                           p_ann_mn_elcn_val                  => l_dummy_num,
2838                                                           p_ann_mx_elcn_val                  => l_dummy_num,
2839                                                           p_cmcd_val                         => l_dummy_num,
2840                                                           p_cmcd_mn_elcn_val                 => l_dummy_num,
2841                                                           p_cmcd_mx_elcn_val                 => l_dummy_num,
2842                                                           p_cmcd_acty_ref_perd_cd            => l_dummy_varchar2,
2843                                                           p_incrmt_elcn_val                  => l_dummy_num,
2844                                                           p_dflt_val                         => l_dummy_num,
2845                                                           p_tx_typ_cd                        => l_dummy_varchar2,
2846                                                           p_acty_typ_cd                      => l_dummy_varchar2,
2847                                                           p_nnmntry_uom                      => l_dummy_varchar2,
2848                                                           p_entr_val_at_enrt_flag            => l_dummy_varchar2,
2849                                                           p_dsply_on_enrt_flag               => l_dummy_varchar2,
2850                                                           p_use_to_calc_net_flx_cr_flag      => l_dummy_varchar2,
2851                                                           p_rt_usg_cd                        => l_dummy_varchar2,
2852                                                           p_bnft_prvdr_pool_id               => l_dummy_num,
2853                                                           p_actl_prem_id                     => l_dummy_num,
2854                                                           p_cvg_calc_amt_mthd_id             => l_dummy_num,
2855                                                           p_bnft_rt_typ_cd                   => l_dummy_varchar2,
2856                                                           p_rt_typ_cd                        => l_dummy_varchar2,
2857                                                           p_rt_mlt_cd                        => l_dummy_varchar2,
2858                                                           p_comp_lvl_fctr_id                 => l_dummy_num,
2859                                                           p_entr_ann_val_flag                => l_dummy_varchar2,
2860                                                           p_ptd_comp_lvl_fctr_id             => l_dummy_num,
2861                                                           p_clm_comp_lvl_fctr_id             => l_dummy_num,
2862                                                           p_ann_dflt_val                     => l_dummy_num,
2863                                                           p_rt_strt_dt                       => l_dummy_date,
2864                                                           p_rt_strt_dt_cd                    => l_dummy_varchar2,
2865                                                           p_rt_strt_dt_rl                    => l_dummy_num,
2866                                                           p_prtt_rt_val_id                   => l_dummy_num,
2867                                                           p_dsply_mn_elcn_val                => l_dummy_num,
2868                                                           p_dsply_mx_elcn_val                => l_dummy_num,
2869                                                           p_pp_in_yr_used_num                => l_dummy_num,
2870                                                           p_ordr_num                         => l_dummy_num,
2871                                                           p_iss_val                          => l_dummy_num
2872                                                          );
2873 
2874                      IF g_debug
2875                      THEN
2876                         hr_utility.set_location (   'l_rt_val'
2877                                                  || TO_CHAR (l_rt_val),
2878                                                  556
2879                                                 );
2880                      END IF;
2881                   ELSE
2882                      l_ann_rt_val := l_ann_rt_val_param; -- p_ann_rt_val; 5259005
2883                      l_rt_val := l_rt_val_param; --p_rt_val; 5259005
2884                   END IF;
2885          end if;
2886          --- bug : 1555624 if the parent defined as entr_val_At_enrt_flag and use_calc_acty_bs_rt_flag
2887          --- then call the rate calcualtion
2888          if l_enrt_rt.rt_mlt_cd in ('PRNT','PRNTANDCVG') then
2889 	     /* BUG 8244388 open c_abr2 and c_prv2 with l_enrt_rt.rt_strt_dt instead of l_effective_date */
2890              open c_abr2(l_enrt_rt.rt_strt_dt,l_enrt_rt.acty_base_rt_id ) ;
2891              fetch c_abr2 into l_prnt_abr ;
2892              --- take the rate from the parent rcord
2893              if c_abr2%found then
2894                 open c_prv2(p_prtt_enrt_rslt_id,l_prnt_abr.acty_base_rt_id,l_enrt_rt.rt_strt_dt );
2895                 fetch  c_prv2 into l_prnt_rt_val ,l_prnt_ann_val;
2896                 close  c_prv2 ;
2897              end if ;
2898              close c_abr2 ;
2899          end if ;
2900 
2901          --
2902          --  bug 1480407
2903          --
2904          if g_debug then
2905            hr_utility.set_location('entr_val_At_enrt_flag '||l_enrt_rt.entr_val_At_enrt_flag ,407);
2906            hr_utility.set_location('use_calc_acty_bs_rt_flag '||l_enrt_rt.use_calc_acty_bs_rt_flag ,407);
2907            hr_utility.set_location('l_enrt_rt.rt_mlt_cd' ||l_enrt_rt.rt_mlt_cd , 407);
2908          end if;
2909          --
2910          -- tilak :Rate calclation is called either the std rate  entr_val_At_enrt_flag is on and
2911          -- use_calc_acty_bs_rt_flag is on for coverage and other
2912          -- OR  std rate has parent and the parent's entr_val_At_enrt_flag is on
2913          -- and use_calc_acty_bs_rt_flag is on so the parent calcialted then the child
2914 
2915        if l_enrt_rt.entr_val_At_enrt_flag  = 'Y'
2916             or nvl(l_prnt_abr.entr_val_at_enrt_flag,'N')  = 'Y'  then
2917            --
2918            -- get values from annual value
2919            --
2920           If ( l_enrt_rt.entr_val_At_enrt_flag  = 'Y'
2921               and l_enrt_rt.use_calc_acty_bs_rt_flag = 'Y'
2922               and l_enrt_rt.rt_mlt_cd in('CVG','CL','PRNT','AP') )
2923              or
2924               (nvl(l_prnt_abr.entr_val_at_enrt_flag,'N')  = 'Y'
2925               and nvl(l_prnt_abr.use_calc_acty_bs_rt_flag,'N')  = 'Y'
2926               and l_enrt_rt.rt_mlt_cd in('PRNT','PRNTANDCVG')  ) then
2927 
2928              if g_debug then
2929                hr_utility.set_location(' calllign rate '||l_rt_val  ,407);
2930              end if;
2931              --
2932              -- NOCOPY ISSUE
2933              l_cal_val_in := l_rt_val ;
2934              -- END NOCOPY ISSUE
2935              --
2936              BEN_DETERMINE_ACTIVITY_BASE_RT.main
2937                (p_person_id                  => p_person_id
2938                ,p_elig_per_elctbl_chc_id      => l_enrt_rt.elig_per_elctbl_chc_id
2939                ,p_enrt_bnft_id                => l_enrt_rt.enrt_bnft_id
2940                ,p_acty_base_rt_id             => l_enrt_rt.acty_base_rt_id
2941                ,p_effective_date              => p_effective_date
2942                ,p_per_in_ler_id               => p_per_in_ler_id
2943                ,p_lf_evt_ocrd_dt              => l_lf_evt_ocrd_dt -- Added Bug 3488286
2944                ,p_pl_id                       => p_pl_id
2945                ,p_pgm_id                      => p_pgm_id
2946                ,p_oipl_id                     => p_oipl_id
2947                ,p_pl_typ_id                   => l_global_pen_rec.pl_typ_id
2948                ,p_ler_id                      => l_ler_id -- 8374859
2949                ,p_business_group_id           => p_business_group_id
2950                ,p_perform_rounding_flg        => true
2951                ,p_calc_only_rt_val_flag       => true
2952                ,p_bnft_amt                    => l_global_pen_rec.bnft_amt
2953                ,p_cal_val                     => l_cal_val_in -- NOCOPY ISSUE l_rt_val
2954                ,p_parent_val                  => l_prnt_rt_val
2955                ,p_val                         => l_rt_val
2956                ,p_mn_elcn_val                 => l_dummy_num
2957                ,p_mx_elcn_val                 => l_dummy_num
2958                ,p_ann_val                     => l_ann_rt_val
2959                ,p_ann_mn_elcn_val             => l_dummy_num
2960                ,p_ann_mx_elcn_val             => l_dummy_num
2961                ,p_cmcd_val                    => l_dummy_num
2962                ,p_cmcd_mn_elcn_val            => l_dummy_num
2963                ,p_cmcd_mx_elcn_val            => l_dummy_num
2964                ,p_cmcd_acty_ref_perd_cd       => l_dummy_varchar2
2965                ,p_incrmt_elcn_val             => l_dummy_num
2966                ,p_dflt_val                    => l_dummy_num
2967                ,p_tx_typ_cd                   => l_dummy_varchar2
2968                ,p_acty_typ_cd                 => l_dummy_varchar2
2969                ,p_nnmntry_uom                 => l_dummy_varchar2
2970                ,p_entr_val_at_enrt_flag       => l_dummy_varchar2
2971                ,p_dsply_on_enrt_flag          => l_dummy_varchar2
2972                ,p_use_to_calc_net_flx_cr_flag => l_dummy_varchar2
2973                ,p_rt_usg_cd                   => l_dummy_varchar2
2974                ,p_bnft_prvdr_pool_id          => l_dummy_num
2975                ,p_actl_prem_id                => l_dummy_num
2976                ,p_cvg_calc_amt_mthd_id        => l_dummy_num
2977                ,p_bnft_rt_typ_cd              => l_dummy_varchar2
2978                ,p_rt_typ_cd                   => l_dummy_varchar2
2979                ,p_rt_mlt_cd                   => l_dummy_varchar2
2980                ,p_comp_lvl_fctr_id            => l_dummy_num
2981                ,p_entr_ann_val_flag           => l_dummy_varchar2
2982                ,p_ptd_comp_lvl_fctr_id        => l_dummy_num
2983                ,p_clm_comp_lvl_fctr_id        => l_dummy_num
2984                ,p_ann_dflt_val                => l_dummy_num
2985                ,p_rt_strt_dt                  => l_dummy_date
2986                ,p_rt_strt_dt_cd               => l_dummy_varchar2
2987                ,p_rt_strt_dt_rl               => l_dummy_num
2988                ,p_prtt_rt_val_id              => l_dummy_num
2989                ,p_dsply_mn_elcn_val           => l_dummy_num
2990                ,p_dsply_mx_elcn_val           => l_dummy_num
2991                ,p_pp_in_yr_used_num           => l_dummy_num
2992                ,p_ordr_num                    => l_dummy_num
2993                ,p_iss_val                     => l_dummy_num
2994                );
2995              if g_debug then
2996                hr_utility.set_location(' rate ' ||l_rt_val,407);
2997              end if;
2998            End if ;
2999          end if;
3000          --
3001          --GEVITY
3002          --
3003          IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
3004            --
3005            l_dfnd_dummy := l_rt_val;
3006            --
3007            ben_distribute_rates.periodize_with_rule
3008                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
3009                   ,p_effective_date         => l_effective_date
3010                   ,p_assignment_id          => l_assignment_id
3011                   ,p_convert_from_val       => l_dfnd_dummy
3012                   ,p_convert_from           => 'DEFINED'
3013                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
3014                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3015                   ,p_business_group_id      => p_business_group_id
3016                   ,p_enrt_rt_id             => p_enrt_rt_id
3017                   ,p_ann_val                => l_ann_rt_val
3018                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
3019                   ,p_val                    => l_rt_val
3020             );
3021             --
3022          ELSE
3023            --
3024            l_ann_rt_val := ben_distribute_rates.period_to_annual
3025                            (p_amount                  => l_rt_val
3026                            ,p_enrt_rt_id              => p_enrt_rt_id
3027                            ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
3028                            ,p_acty_ref_perd_cd        => p_acty_ref_perd_cd
3029                            ,p_business_group_id       => p_business_group_id
3030                            ,p_effective_date          => l_effective_date
3031                            ,p_complete_year_flag      => 'Y'
3032                            ,p_use_balance_flag        => 'Y'
3033                            ,p_payroll_id              => l_payroll_id
3034                            );
3035            --
3036            -- always compute the cmcd rate based on the annual value
3037            --
3038            l_calc_ann_val := ben_distribute_rates.period_to_annual
3039                              (p_amount                  => l_rt_val
3040                              ,p_enrt_rt_id              => p_enrt_rt_id
3041                              ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
3042                              ,p_acty_ref_perd_cd        => p_acty_ref_perd_cd
3043                              ,p_business_group_id       => p_business_group_id
3044                              ,p_effective_date          => l_effective_date
3045                              ,p_complete_year_flag      => 'Y'
3046                              ,p_payroll_id              => l_payroll_id
3047                              );
3048            --
3049            l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
3050                                  (p_amount                  => l_calc_ann_val
3051                                  ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
3052                                  ,p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd
3053                                  ,p_business_group_id       => p_business_group_id
3054                                  ,p_effective_date          => l_effective_date
3055                                  ,p_complete_year_flag      => 'Y'
3056                                  ,p_payroll_id              => l_payroll_id
3057                                  ,p_element_type_id         => l_element_type_id
3058                                  ,p_person_id               => p_person_id
3059                                  );
3060            --
3061          END IF; --GEVITY
3062        if g_debug then
3063          hr_utility.set_location('ann val'||l_ann_rt_val||'cal ann val'||l_calc_ann_val,100);
3064           hr_utility.set_location('communicated val'||l_enrt_rt.cmcd_val,101);
3065        end if;
3066     else  --mlt_cd='SAREC'
3067         if l_enrt_rt.entr_bnft_val_flag = 'Y' then
3068            if g_debug then
3069              hr_utility.set_location('p_rt_val'||to_char(p_rt_val), 319);
3070              hr_utility.set_location('p_ann_rt_val'||to_char(p_ann_rt_val), 319);
3071              hr_utility.set_location('l_rt_val_param'||to_char(l_rt_val_param), 319);          -- 5259005
3072              hr_utility.set_location('l_ann_rt_val_param'||to_char(l_ann_rt_val_param), 319);  -- 5259005
3073              hr_utility.set_location('bnft_val'||to_char(l_global_pen_rec.bnft_amt), 319);
3074            end if;
3075           --
3076           l_ann_rt_val := l_global_pen_rec.bnft_amt;
3077           -- Bug 2675486 fixes for FSA
3078           if l_old_ann_rt_val = l_ann_rt_val and l_old_rt_strt_dt is not null then
3079             -- Case - Benefit amount not changed and currently enrolled case
3080             -- See if the current rate is started in the present popl yr period.
3081             -- If started in current yr_perd then DONT compute defined and comm amounts
3082             -- else compute the defined comm amounts.
3083             -- l_sarec_compute
3084             open c_pl_popl_yr_period_current(p_pl_id,p_pgm_id,l_effective_date);
3085               fetch c_pl_popl_yr_period_current into l_yp_start_date;
3086             close c_pl_popl_yr_period_current ;
3087             --
3088             --
3089             --  9593336 - Get the payroll year start date
3090             --
3091             open c_pay_period_strt_dt(l_yp_start_date
3092                                      );
3093             fetch c_pay_period_strt_dt into l_pay_start_date;
3094             close c_pay_period_strt_dt;
3095             hr_utility.set_location('Pay Period Start Date '||l_pay_start_date,123);
3096             hr_utility.set_location('l_old_rt_strt_dt '||l_old_rt_strt_dt,123);
3097             --
3098             -- End 9593336
3099             --
3100             if ((l_old_rt_strt_dt >= l_yp_start_date) or
3101                   (l_old_rt_strt_dt >= l_pay_start_date)) then -- 9593336
3102               -- Already enrolled in the same yr_perd and amount not changed so
3103               -- dont recompute the amounts
3104                   --bug#3364910 - check for payroll type change
3105                     l_period_type:=null;
3106                     open c_payroll_type_changed(
3107                           cp_person_id           =>p_person_id,
3108                           cp_business_group_id   =>p_business_group_id,
3109                           cp_effective_date      =>l_enrt_rt.rt_strt_dt,
3110                           cp_orig_effective_date =>l_old_rt_strt_dt);
3111                     fetch c_payroll_type_changed into l_period_type;
3112                     close c_payroll_type_changed;
3113                --      no change in payroll then dont recompute
3114                     if l_period_type is null then
3115 
3116                        if g_debug then
3117                          hr_utility.set_location('Same Yr Period and same rate ' ,124);
3118                        end if;
3119                        l_sarec_compute := false ;
3120 		       --Check if there is any change in the assignment,9143356
3121 		       hr_utility.set_location('Check for the assg change ' ,124);
3122                        open c_assignment_changed(
3123 		                cp_person_id           =>p_person_id,
3124 				cp_business_group_id   =>p_business_group_id,
3125 				cp_effective_date      =>l_enrt_rt.rt_strt_dt,
3126 				cp_orig_effective_date =>l_old_rt_strt_dt);
3127 		       fetch c_assignment_changed into l_assignment_changed;
3128 		       if c_assignment_changed%found then
3129 		         hr_utility.set_location('Assg change found ' ,124);
3130 			  hr_utility.set_location('sarec compute is set to true ' ,124);
3131 		         l_sarec_compute := true ;
3132 		       end if;
3133 		       close c_assignment_changed;
3134                     end if;
3135             end if ;
3136             --
3137           end if ;
3138           --
3139           --l_ann_rt_val := l_global_pen_rec.bnft_amt;
3140           -- ikasire commented p_complete_year_flag => 'Y' per Bug 1650517
3141           if l_sarec_compute then
3142             --GEVITY
3143             --
3144             IF l_enrt_rt.rate_periodization_rl IS NOT NULL THEN
3145               --
3146               l_ann_dummy := l_ann_rt_val;
3147               --
3148               ben_distribute_rates.periodize_with_rule
3149                   (p_formula_id             => l_enrt_rt.rate_periodization_rl
3150                   ,p_effective_date         => l_effective_date
3151                   ,p_assignment_id          => l_assignment_id
3152                   ,p_convert_from_val       => l_ann_dummy
3153                   ,p_convert_from           => 'ANNUAL'
3154                   ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
3155                   ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3156                   ,p_business_group_id      => p_business_group_id
3157                   ,p_enrt_rt_id             => p_enrt_rt_id
3158                   ,p_ann_val                => l_ann_rt_val
3159                   ,p_cmcd_val               => l_enrt_rt.cmcd_val
3160                   ,p_val                    => l_rt_val
3161                 );
3162                 --
3163             ELSE
3164                 --
3165               l_rt_val := ben_distribute_rates.annual_to_period
3166                     (p_amount                  => l_ann_rt_val,
3167                      p_enrt_rt_id              => p_enrt_rt_id,
3168                      p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
3169                      p_business_group_id       => p_business_group_id,
3170                      p_effective_date          => l_effective_date,
3171                      p_complete_year_flag      => 'Y',
3172                      p_use_balance_flag        => 'Y',
3173 		     p_start_date              => l_enrt_rt.rt_strt_dt,  ---Bug 9309878
3174                      p_payroll_id              => l_payroll_id,
3175                      p_element_type_id         => l_element_type_id,
3176                      p_rounding_flag           => 'N',
3177                      p_person_id               => p_person_id
3178                      );
3179               if g_debug then
3180                 hr_utility.set_location(' IK l_rt_val '||l_rt_val,123);
3181               end if;
3182               --
3183               -- Bug 2149438 I am doing it to 3 because right now we have 2 digit rouding for
3184               -- the final value. Once we implement the rounding completely for the
3185               -- rate value this needs to be atleast one digit more than the
3186               -- actual rounding code dictates.
3187               --
3188               l_rt_val := round(l_rt_val,4);
3189               --
3190               if g_debug then
3191                 hr_utility.set_location(' IK2 rounded l_rt_val '||l_rt_val,123);
3192               end if;
3193               /**
3194                when annual value is passed there is no need to compute the annual value
3195                from defined value - bug#2398448 and bug#2392732
3196               l_calc_ann_val := ben_distribute_rates.period_to_annual
3197                     (p_amount                  => l_rt_val,
3198                      p_enrt_rt_id              => p_enrt_rt_id,
3199                      p_acty_ref_perd_cd        => p_acty_ref_perd_cd,
3200                      p_business_group_id       => p_business_group_id,
3201                      p_effective_date          => l_effective_date,
3202                      p_complete_year_flag      => 'Y',
3203                      p_payroll_id              => l_payroll_id);
3204               **/
3205               l_calc_ann_val  := l_ann_rt_val;
3206                if g_debug then
3207                  hr_utility.set_location('annval'||to_char(l_calc_ann_val), 319);
3208                end if;
3209                if g_debug then
3210                  hr_utility.set_location('rt val'||l_rt_val, 319);
3211                end if;
3212                --Bug#3540351
3213                if l_rt_val < 0 then
3214                   l_rt_val := 0;
3215                   l_enrt_rt.cmcd_val := 0;
3216                   ben_distribute_rates.compare_balances
3217                     (p_person_id            => p_person_id
3218                     ,p_effective_date       => l_effective_date
3219                     ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
3220                     ,p_acty_base_rt_id      => l_enrt_rt.acty_base_rt_id
3221                     ,p_ann_mn_val           => l_ann_mn_elcn_val
3222                     ,p_ann_mx_val           => l_ann_mx_elcn_val
3223                     ,p_perform_edit_flag    => 'N'
3224                     ,p_entered_ann_val      => l_ann_rt_val
3225                     ,p_ptd_balance          => l_ptd_balance
3226                     ,p_clm_balance          => l_clm_balance ) ;
3227                  --
3228                  if l_ann_rt_val < l_ptd_balance then
3229                    --
3230                    open c_pl_name (p_pl_id);
3231                    fetch c_pl_name into l_pl_name;
3232                    close c_pl_name;
3233                    --
3234                    ben_warnings.load_warning
3235                      (p_application_short_name  => 'BEN',
3236                       p_message_name            => 'BEN_93951_BELOW_PTD',
3237                       p_parma => l_pl_name,
3238                       p_parm1 => l_ann_rt_val,
3239                       p_parm2 => l_ptd_balance,
3240                       p_person_id => p_person_id);
3241                  end if;
3242                else
3243                  --
3244                   l_enrt_rt.cmcd_val := ben_distribute_rates.annual_to_period
3245                     (p_amount                  => l_calc_ann_val,
3246                     -- p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id,
3247                      p_enrt_rt_id              => p_enrt_rt_id,
3248                      p_acty_ref_perd_cd        => l_enrt_rt.cmcd_acty_ref_perd_cd,
3249                      p_business_group_id       => p_business_group_id,
3250                      p_effective_date          => l_effective_date,
3251                      p_use_balance_flag        => 'Y',
3252                     -- p_complete_year_flag      => 'Y',
3253                      p_start_date              => l_enrt_rt.rt_strt_dt,
3254                      p_payroll_id              => l_payroll_id,
3255                      p_element_type_id         => l_element_type_id,
3256                      p_person_id               => p_person_id
3257                      );
3258                end if;
3259                --
3260             END IF; --GEVITY
3261           else
3262             --
3263             l_rt_val := l_old_rt_val ;
3264             l_calc_ann_val  := l_ann_rt_val;
3265             l_enrt_rt.cmcd_val := l_old_cmcd_rt_val ;
3266             if g_debug then
3267               hr_utility.set_location('Continue old rate '||l_old_rt_val,123);
3268             end if;
3269             if g_debug then
3270               hr_utility.set_location(' l_old_cmcd_rt_val '||l_old_cmcd_rt_val,123);
3271             end if;
3272             --
3273           end if ;
3274         else
3275           -- Bug 2223694 when the coverage is not enter value at enrollment
3276           -- we are not getting the defined amount and element entries.
3277           if g_debug then
3278             hr_utility.set_location('IK l_enrt_rt.val '||l_enrt_rt.val ,99);
3279             hr_utility.set_location('IK l_enrt_rt.ann_val '||l_enrt_rt.ann_val,99);
3280             hr_utility.set_location('IK l_enrt_rt.cmcd_val '||l_enrt_rt.cmcd_val,99);
3281           end if;
3282           l_rt_val  := l_enrt_rt.val ;
3283           l_calc_ann_val := l_enrt_rt.ann_val ;
3284           --  3547233. Copy annual value to l_ann_rt_val for prtt_rt_val record.
3285           l_ann_rt_val := l_enrt_rt.ann_val;
3286           --
3287        end if;
3288     end if;
3289    end if;
3290   end if;
3291   --
3292   -- determine if element type/input val changed
3293   --
3294   if p_prtt_rt_val_id is not null then
3295      if p_ele_changed is null then
3296 
3297         if l_old_element_entry_value_id is not null then
3298            open c_element_info (l_old_element_entry_value_id,
3299                                 p_prtt_enrt_rslt_id);
3300            fetch c_element_info into l_element_info;
3301            close c_element_info;
3302            --
3303            --bug#3378865
3304            --
3305            if not (l_old_rt_strt_dt between l_enrt_rt.abr_esd and
3306               l_enrt_rt.abr_eed) then
3307               open c_abr(l_enrt_rt.acty_base_rt_id, l_old_rt_strt_dt);
3308               fetch c_abr into l_ele_entry_val_cd,l_element_type_id,l_input_value_id;
3309               close c_abr;
3310            else
3311               l_ele_entry_val_cd := l_enrt_rt.ele_entry_val_cd;
3312            end if;
3313            --
3314         end if;
3315         --
3316         --get the new abr assignment and payroll
3317         --
3318         ben_element_entry.get_abr_assignment
3319         (p_person_id       => p_person_id,
3320          p_effective_date  => l_enrt_rt.rt_strt_dt,
3321          p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id,
3322          p_assignment_id   => l_new_assignment_id,
3323          p_payroll_id      => l_new_payroll_id,
3324          p_organization_id => l_new_organization_id);
3325 
3326  /* Adding this call below to fix a bug 6132571. When there are two
3327  * rates having same element type, the first input value is updated
3328  * with value zero along with element entry. This while processing the second
3329  * rate,the cursor c_element_info gets the latest payroll id, which while
3330  * processing the second rate does not set the flag l_element_changed
3331  * in the condition below, which impact all further processing */
3332 
3333         ben_element_entry.get_abr_assignment
3334         (p_person_id       => p_person_id,
3335          p_effective_date  => l_old_rt_strt_dt,
3336          p_acty_base_rt_id => l_enrt_rt.acty_base_rt_id,
3337          p_assignment_id   => l_old_assignment_id,
3338          p_payroll_id      => l_old_payroll_id,
3339          p_organization_id => l_old_organization_id);
3340 
3341 
3342         hr_utility.set_location('ben_element_entry.get_abr_assignment
3343                                 -Old Assignment Id' ||l_old_assignment_id ,101);
3344         hr_utility.set_location('ben_element_entry.get_abr_assignment
3345                                 -Old Payroll Id' ||l_old_payroll_id ,101);
3346         hr_utility.set_location('ben_element_entry.get_abr_assignment
3347                                 -Old Org Id' ||l_old_organization_id ,101);
3348 
3349         l_element_changed :=
3350             (l_old_element_entry_value_id is not null and
3351             l_enrt_rt.ele_rqd_flag = 'N') or
3352            (l_enrt_rt.ele_rqd_flag = 'Y' and
3353             ((nvl(l_element_info.input_value_id,-1) <>
3354               l_enrt_rt.input_value_id) or
3355              (nvl(l_element_info.element_type_id,-1) <>
3356               l_enrt_rt.element_type_id) or
3357              (not l_non_recurring_rt and
3358               l_element_info.effective_end_date < l_enrt_rt.rt_strt_dt) or
3359              (l_old_assignment_id <> nvl(l_new_assignment_id,-1)) or
3360              (nvl(l_old_payroll_id,-1) <> nvl(l_new_payroll_id,-1)) or
3361              (nvl(l_enrt_rt.ele_entry_val_cd,'PP') <>
3362                 nvl(l_ele_entry_val_cd,'PP'))));
3363         --
3364         -- determine if extra input values changed
3365         --
3366         if not l_element_changed then
3367 
3368 
3369            --8589355
3370 	   l_get_opt_id := null;
3371            hr_utility.set_location( 'l_global_pen_rec.oipl_id '||l_global_pen_rec.oipl_id, 20);
3372            if l_global_pen_rec.oipl_id is not null then
3373               open c_get_opt_id(l_global_pen_rec.oipl_id, l_enrt_rt.rt_strt_dt);
3374 	      fetch c_get_opt_id into l_get_opt_id;
3375 	      close c_get_opt_id;
3376            end if;
3377            hr_utility.set_location( 'l_get_opt_id.opt_id '||l_get_opt_id.opt_id, 20);
3378   	   --8589355
3379 
3380            l_ext_inpval_tab.delete;
3381            ben_element_entry.get_extra_ele_inputs
3382            (p_effective_date         => l_enrt_rt.rt_strt_dt
3383            ,p_person_id              => p_person_id
3384            ,p_business_group_id      => p_business_group_id
3385            ,p_assignment_id          => l_new_assignment_id
3386            ,p_element_link_id        => null
3387            ,p_entry_type             => 'E'
3388            ,p_input_value_id1        => null
3389            ,p_entry_value1           => null
3390            ,p_element_entry_id       => null
3391            ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3392            ,p_input_va_calc_rl       => l_enrt_rt.input_va_calc_rl
3393            ,p_abs_ler                => null
3394            ,p_organization_id        => l_new_organization_id
3395            ,p_payroll_id             => l_new_payroll_id
3396            ,p_pgm_id                 => l_global_pen_rec.pgm_id
3397            ,p_pl_id                  => l_global_pen_rec.pl_id
3398            ,p_pl_typ_id              => l_global_pen_rec.pl_typ_id
3399            ,p_opt_id                 => l_get_opt_id.opt_id --8589355
3400            ,p_ler_id                 => l_global_pen_rec.ler_id
3401            ,p_dml_typ                => 'C'
3402            ,p_jurisdiction_code      => l_jurisdiction_code
3403            ,p_ext_inpval_tab         => l_ext_inpval_tab
3404            ,p_subpriority            => l_subpriority
3405            );
3406 
3407            l_inpval_tab.delete;
3408            ben_element_entry.get_inpval_tab
3409            (p_element_entry_id   => l_element_info.element_entry_id
3410            ,p_effective_date     => l_enrt_rt.rt_strt_dt
3411            ,p_inpval_tab         => l_inpval_tab);
3412 
3413            l_ext_inp_changed := false;
3414            for i in 1..l_ext_inpval_tab.count
3415            loop
3416               for j in 1..l_inpval_tab.count
3417               loop
3418                   if (l_ext_inpval_tab(i).input_value_id =
3419                      l_inpval_tab(j).input_value_id) and
3420                      (nvl(l_ext_inpval_tab(i).return_value,'-1')  <>
3421                      nvl(l_inpval_tab(j).value,'-1')) then
3422                      l_ext_inp_changed := true;
3423                      exit;
3424                   end if;
3425               end loop;
3426               if l_ext_inp_changed then
3427                  exit;
3428               end if;
3429            end loop;
3430 
3431            l_element_changed := l_ext_inp_changed;
3432 
3433         end if;
3434      else
3435         l_element_changed := p_ele_changed;
3436      end if;
3437   end if;
3438   --
3439   -- delete any future dated rates
3440   --
3441   handle_overlap_rates
3442   (p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3443   ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
3444   ,p_prtt_rt_val_id                 => p_prtt_rt_val_id
3445   ,p_per_in_ler_id                  => p_per_in_ler_id
3446   ,p_person_id                      => p_person_id
3447   ,p_element_type_id                => l_element_info.element_type_id
3448   ,p_element_entry_value_id         => l_old_element_entry_value_id
3449   ,p_unrestricted                   => l_unrestricted
3450   ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
3451   ,p_business_group_id              => p_business_group_id
3452   ,p_effective_date                 => p_effective_date);
3453   --
3454   -- if a prtt_rt_val_id is found get the old values
3455   --
3456   /* 8716870: Code added for Imp Inc Enh starts*/
3457     hr_utility.set_location('p_imp_cvg_strt_dt '||p_imp_cvg_strt_dt,7007);
3458     if p_imp_cvg_strt_dt is not null and p_imp_cvg_strt_dt > l_enrt_rt.rt_strt_dt then
3459        l_enrt_rt.rt_strt_dt := p_imp_cvg_strt_dt;
3460        -- The rate end date for prev imputed income rate rec is set to the current rt_strt_dt - 1
3461        l_xrt_end_dt         := p_imp_cvg_strt_dt - 1;
3462        hr_utility.set_location('setting l_xrt_end_dt '||l_xrt_end_dt,7007);
3463     end if;
3464   /* Code added for Imp Inc Enh ends*/
3465 
3466   --
3467   if p_prtt_rt_val_id is not null then
3468      --
3469      if g_debug then
3470         hr_utility.set_location(l_proc, 85);
3471      end if;
3472       --
3473       -- compare old and new values if changed do update
3474       --
3475       --
3476       -- date compare below will fix bug 3556
3477       -- whenever the rate start date changes create a new prv
3478       -- this will force the element entries to be updated.
3479       --
3480       --
3481       -- Always update per_in_ler_id and create a new rate
3482       -- when per_in_ler_id changes.
3483       --
3484       if ((nvl(l_old_rt_typ_cd,hr_api.g_varchar2)<>
3485                 nvl(l_enrt_rt.rt_typ_cd,hr_api.g_varchar2)) or
3486         (nvl(l_old_tx_typ_cd,hr_api.g_varchar2)<>
3487                 nvl(l_enrt_rt.tx_typ_cd,hr_api.g_varchar2)) or
3488         (nvl(l_old_acty_typ_cd,hr_api.g_varchar2)<>
3489                 nvl(l_enrt_rt.acty_typ_cd,hr_api.g_varchar2)) or
3490         (nvl(l_old_mlt_cd,hr_api.g_varchar2)<>
3491                 nvl(l_enrt_rt.rt_mlt_cd,hr_api.g_varchar2)) or
3492         (nvl(l_old_acty_ref_perd_cd,hr_api.g_varchar2)<>
3493                 nvl(p_acty_ref_perd_cd,hr_api.g_varchar2)) or
3494         (nvl(l_old_rt_val,hr_api.g_number)<>
3495                 nvl(l_rt_val,hr_api.g_number)) or
3496         (nvl(l_old_ann_rt_val,hr_api.g_number) <>
3497                 nvl(l_ann_rt_val,hr_api.g_number)) or
3498         (nvl(l_old_bnft_rt_typ_cd,hr_api.g_varchar2) <>
3499                 nvl(l_enrt_rt.bnft_rt_typ_cd,hr_api.g_varchar2)) or
3500         (nvl(l_old_cmcd_ref_perd_cd,hr_api.g_varchar2) <>
3501                 nvl(l_enrt_rt.cmcd_acty_ref_perd_cd,hr_api.g_varchar2)) or
3502         (nvl(l_old_cmcd_rt_val,hr_api.g_number) <>
3503                 nvl(l_enrt_rt.cmcd_val,hr_api.g_number)) or
3504         (nvl(l_old_dsply_on_enrt_flag,hr_api.g_varchar2) <>
3505                 nvl(l_enrt_rt.dsply_on_enrt_flag,hr_api.g_varchar2)) or
3506         (nvl(l_old_cvg_amt_calc_mthd_id,hr_api.g_number) <>
3507                 nvl(l_enrt_rt.cvg_amt_calc_mthd_id,hr_api.g_number)) or
3508         (nvl(l_old_actl_prem_id,hr_api.g_number) <>
3509                 nvl(l_enrt_rt.actl_prem_id,hr_api.g_number)) or
3510         (nvl(l_old_comp_lvl_fctr_id,hr_api.g_number) <>
3511                 nvl(l_enrt_rt.comp_lvl_fctr_id,hr_api.g_number)) or
3512         (nvl(l_old_prtt_enrt_rslt_id,hr_api.g_number) <>
3513                 nvl(p_prtt_enrt_rslt_id,hr_api.g_number)) or
3514         (nvl(l_old_rt_strt_dt,hr_api.g_date) <>
3515                 nvl(l_enrt_rt.rt_strt_dt,hr_api.g_date)) or
3516         (nvl(l_old_per_in_ler_id,hr_api.g_number) <>
3517                 nvl(p_per_in_ler_id,hr_api.g_number)) or
3518         l_global_pen_rec.sspndd_flag = 'Y'  or /*4775760 */
3519         p_bnft_amt_changed=TRUE or
3520         l_element_changed ) then
3521         --
3522         -- handle old rate
3523        if g_debug then
3524          hr_utility.set_location(l_proc||'In the TRUE', 1330);
3525        end if;
3526         --
3527        -- if l_unrestricted = 'Y' and -- commented for 4775760,4871284
3528         if   l_old_rt_strt_dt >= l_enrt_rt.rt_strt_dt then
3529           --
3530           -- delete future dated rate
3531           --
3532           if not p_calculate_only_mode then
3533             --
3534             ben_prtt_rt_val_api.delete_prtt_rt_val
3535               (p_prtt_rt_val_id                => p_prtt_rt_val_id
3536               ,p_enrt_rt_id                    => p_enrt_rt_id
3537               ,p_person_id                     => p_person_id
3538               ,p_business_group_id             => l_enrt_rt.business_group_id
3539               ,p_object_version_number         => l_old_object_version_number
3540               ,p_effective_date                => p_effective_date
3541               );
3542             --
3543           end if;
3544           --
3545         else
3546           --
3547           -- set the rate end date on the old one
3548           --
3549           if g_debug then
3550              hr_utility.set_location('BEF ben_determine_date.rate_and_coverage_dates',1999);
3551              hr_utility.set_location('l_enrt_rt.elig_per_elctbl_chc_id'||l_enrt_rt.elig_per_elctbl_chc_id,1999);
3552              hr_utility.set_location('l_xenrt_cvg_strt_dt'||l_xenrt_cvg_strt_dt,1999);
3553              hr_utility.set_location('l_xenrt_cvg_strt_dt_cd'||l_xenrt_cvg_strt_dt_cd,1999);
3554              hr_utility.set_location('l_xenrt_cvg_strt_dt_rl'||l_xenrt_cvg_strt_dt_rl,1999);
3555              hr_utility.set_location('l_xrt_strt_dt'||l_xrt_strt_dt,1999);
3556              hr_utility.set_location('l_xrt_strt_dt_cd'||l_xrt_strt_dt_cd,1999);
3557              hr_utility.set_location('l_xenrt_cvg_end_dt'||l_xenrt_cvg_end_dt,1999);
3558              hr_utility.set_location('l_xenrt_cvg_end_dt_cd'||l_xenrt_cvg_end_dt_cd,1999);
3559              hr_utility.set_location('l_xrt_end_dt'||l_xrt_end_dt,1999);
3560              hr_utility.set_location('l_xrt_end_dt_cd'||l_xrt_end_dt_cd,1999);
3561              hr_utility.set_location('l_enrt_rt.acty_base_rt_id'||l_enrt_rt.acty_base_rt_id,1999);
3562             hr_utility.set_location('p_effective_date'||p_effective_date,1999);
3563           end if;
3564 
3565           ben_determine_date.rate_and_coverage_dates
3566             (p_which_dates_cd         => 'R'
3567             ,p_business_group_id      => p_business_group_id
3568             ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
3569             ,p_enrt_cvg_strt_dt       => l_xenrt_cvg_strt_dt
3570             ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
3571             ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
3572             ,p_rt_strt_dt             => l_xrt_strt_dt
3573             ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
3574             ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
3575             ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
3576             ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
3577             ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
3578             ,p_rt_end_dt              => l_xrt_end_dt
3579             ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
3580             ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
3581             ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
3582             ,p_effective_date         => p_effective_date
3583 	    ,p_lf_evt_ocrd_dt         => l_lf_evt_ocrd_dt); -- bug 5717428
3584           --
3585 
3586           -- If the rate end date code is '1 Prior or Enterable' (WAENT),
3587           -- then the rate end date is 1 Less than the rate start date.
3588           --
3589           if l_xrt_end_dt_cd = 'WAENT' and
3590              p_rt_strt_dt is not null then
3591              l_xrt_end_dt := p_rt_strt_dt -1;
3592           elsif l_xrt_end_dt_cd = 'WAENT' and p_rt_strt_dt is null then
3593              l_xrt_end_dt := l_xrt_strt_dt -1;
3594           end if;
3595           --
3596           -- If the rate end date code is '1 prior or Later of Event ..etc or
3597           -- codes start with W or LW need to be ended 1 day before rate start date
3598           -- bug#2055961
3599           if  (substr(nvl(l_xrt_end_dt_cd, 'X'), 1, 1) = 'W' or
3600                 substr(nvl(l_xrt_end_dt_cd, 'X'), 1, 2) = 'LW' or
3601                 l_xrt_end_dt_cd in ('LDPPFEFD','LDPPOEFD')) and
3602                 not (l_xrt_end_dt_cd = 'WAENT') then
3603               l_xrt_end_dt := l_xrt_strt_dt -1;
3604           end if;
3605 
3606           if g_debug then
3607             hr_utility.set_location('p rate strt date'||p_rt_strt_dt,111);
3608           end if;
3609           if p_rt_strt_dt > l_old_rt_end_dt then
3610              l_xrt_end_dt := l_old_rt_end_dt;
3611           end if;
3612 
3613           -- Bug 10224915: Moved the below piece of code to here
3614 
3615           /* 8716870: Code added for Imp Inc Enh begins*/
3616           if p_imp_cvg_strt_dt is not null and p_imp_cvg_strt_dt >= l_enrt_rt.rt_strt_dt then
3617           -- the rate_end_dt for prev imputed income rate rec is set to the current rt_strt_dt - 1
3618           l_xrt_end_dt         := p_imp_cvg_strt_dt - 1;
3619           hr_utility.set_location('setting l_xrt_end_dt '||l_xrt_end_dt,16);
3620           end if;
3621           /* 8716870: Code added for Imp Inc Enh ends*/
3622 
3623 
3624           --
3625           if g_debug then
3626              hr_utility.set_location('After call to ben_determine_date.rate_and_coverage_dates',1999);
3627              hr_utility.set_location('l_enrt_rt.elig_per_elctbl_chc_id'||l_enrt_rt.elig_per_elctbl_chc_id,1999);
3628              hr_utility.set_location('l_xenrt_cvg_strt_dt'||l_xenrt_cvg_strt_dt,1999);
3629              hr_utility.set_location('l_xenrt_cvg_strt_dt_cd'||l_xenrt_cvg_strt_dt_cd,1999);
3630              hr_utility.set_location('l_xenrt_cvg_strt_dt_rl'||l_xenrt_cvg_strt_dt_rl,1999);
3631              hr_utility.set_location('l_xrt_strt_dt'||l_xrt_strt_dt,1999);
3632              hr_utility.set_location('l_xrt_strt_dt_cd'||l_xrt_strt_dt_cd,1999);
3633              hr_utility.set_location('l_xenrt_cvg_end_dt'||l_xenrt_cvg_end_dt,1999);
3634              hr_utility.set_location('l_xenrt_cvg_end_dt_cd'||l_xenrt_cvg_end_dt_cd,1999);
3635              hr_utility.set_location('l_xrt_end_dt'||l_xrt_end_dt,1999);
3636              hr_utility.set_location('l_xrt_end_dt_cd'||l_xrt_end_dt_cd,1999);
3637              hr_utility.set_location('l_enrt_rt.acty_base_rt_id'||l_enrt_rt.acty_base_rt_id,1999);
3638              hr_utility.set_location('p_effective_date'||p_effective_date,1999);
3639           end if;
3640         --
3641         -- bnft amt changed and entr val flag is N then election rate
3642         -- information is called after delete enrollment
3643         --
3644         if l_old_rt_end_dt < l_xrt_end_dt then
3645           --
3646           if not p_calculate_only_mode then
3647             --
3648             --Bug 2976103 Non Recurring rates are getting opened when called
3649             --from benraten. This needs to happed only for recurring rates.
3650             --
3651             if not l_non_recurring_rt then
3652               --
3653               ben_prtt_rt_val_api.update_prtt_rt_val
3654               (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3655               ,p_rt_end_dt                      => hr_api.g_eot
3656               ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3657               ,p_input_value_id                 => l_enrt_rt.input_value_id
3658               ,p_element_type_id                => l_enrt_rt.element_type_id
3659               ,p_person_id                      => p_person_id
3660               ,p_ended_per_in_ler_id            => null
3661               ,p_business_group_id              => l_enrt_rt.business_group_id
3662               ,p_object_version_number          => l_old_object_version_number
3663               ,p_effective_date                 => p_effective_date
3664               );
3665               --
3666             end if;
3667             --
3668           end if;
3669           --
3670         end if;
3671 
3672         l_no_end_element := (not l_element_changed) and
3673                             (l_old_rt_val=l_rt_val);
3674 
3675         if p_bnft_amt_changed and l_enrt_rt.entr_val_At_enrt_flag = 'Y' then
3676 
3677           if g_debug then
3678             hr_utility.set_location('p_bnft_amt_changed',1999);
3679           end if;
3680           if not p_calculate_only_mode then
3681             --
3682              --
3683             ben_prtt_rt_val_api.update_prtt_rt_val
3684               (p_prtt_rt_val_id                => p_prtt_rt_val_id
3685               ,p_rt_end_dt                     => l_xrt_end_dt
3686               ,p_ended_per_in_ler_id           => p_per_in_ler_id
3687               ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
3688               ,p_input_value_id                => l_enrt_rt.input_value_id
3689               ,p_element_type_id               => l_enrt_rt.element_type_id
3690               ,p_person_id                     => p_person_id
3691               ,p_business_group_id             => l_enrt_rt.business_group_id
3692               ,p_object_version_number         => l_old_object_version_number
3693               ,p_effective_date                => p_effective_date
3694               ,p_no_end_element                => l_no_end_element
3695               );
3696             --
3697           end if;
3698           --
3699         elsif p_bnft_amt_changed = FALSE then
3700           --
3701           -- p_amt_changed is false
3702           --
3703           if g_debug then
3704             hr_utility.set_location('bnft amount false',1999);
3705           end if;
3706           if not p_calculate_only_mode then
3707             --
3708             if  not l_non_recurring_rt then
3709               if l_old_rt_end_dt <> l_xrt_end_dt then
3710                 if g_debug then
3711                   hr_utility.set_location('processing type recurring ',1999);
3712                 end if;
3713                 --
3714 
3715 		/* Added for Bug 12576710: Backup the future rate record before updating the
3716 		date to new value. */
3717 		open c_future_ended_rates(p_prtt_rt_val_id,
3718 		                    p_per_in_ler_id,
3719 				    l_xrt_end_dt,
3720 				    l_enrt_rt.acty_base_rt_id);
3721 		fetch c_future_ended_rates into l_future_end_rec;
3722 		if c_future_ended_rates%found then
3723 		       hr_utility.set_location('inserting into backup table ',1999);
3724 		       hr_utility.set_location('l_enrt_rt.acty_base_rt_id '||l_enrt_rt.acty_base_rt_id,1999);
3725 		       hr_utility.set_location('l_future_end_rec.per_in_ler_id '||l_future_end_rec.per_in_ler_id,1999);
3726 		       hr_utility.set_location('l_future_end_rec.rt_end_dt '||l_future_end_rec.rt_end_dt,1999);
3727                        insert into BEN_LE_CLSN_N_RSTR (
3728 		        person_id,
3729                         BKUP_TBL_TYP_CD,
3730                         BKUP_TBL_ID,
3731 			per_in_ler_id,
3732                         PER_IN_LER_ENDED_ID,
3733                         RT_END_DT,
3734                         business_group_id,
3735                         object_version_number)
3736                       values (
3737 		        p_person_id, -- Bug 16396102
3738                         'BEN_PRTT_RT_VAL_ADJ',
3739                         p_prtt_rt_val_id,
3740 			l_future_end_rec.per_in_ler_id,
3741                         p_per_in_ler_id,
3742                         l_future_end_rec.rt_end_dt,
3743                         p_business_group_id,
3744                         l_future_end_rec.object_version_number
3745                       );
3746 		end if;
3747 		close c_future_ended_rates;
3748 
3749                 ben_prtt_rt_val_api.update_prtt_rt_val
3750                   (p_prtt_rt_val_id                => p_prtt_rt_val_id
3751                   ,p_rt_end_dt                     => l_xrt_end_dt
3752                   ,p_ended_per_in_ler_id           => p_per_in_ler_id
3753                   ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
3754                   ,p_input_value_id                => l_enrt_rt.input_value_id
3755                   ,p_element_type_id               => l_enrt_rt.element_type_id
3756                   ,p_person_id                     => p_person_id
3757                   ,p_business_group_id             => l_enrt_rt.business_group_id
3758                   ,p_object_version_number         => l_old_object_version_number
3759                   ,p_effective_date                => p_effective_date
3760                   ,p_no_end_element                => l_no_end_element
3761                   );
3762                end if;
3763             --
3764             end if;
3765             --
3766           end if;
3767 
3768          end if;
3769         end if;
3770         --
3771         -- update rate
3772         --
3773         if g_debug then
3774           hr_utility.set_location(l_proc, 130);
3775         end if;
3776         --
3777         if not p_calculate_only_mode then
3778           --
3779           -- Bug 2677804 if the rate has override thru date in the previous
3780           -- prv and the thru date is on or after the l_enrt_rt.rt_strt_dt
3781           -- we need to carry forward the information for going forward
3782           --        l_old_rt_ovridn_flag            varchar2(30);
3783           --        l_old_rt_ovridn_thru_dt         date;
3784           if l_old_rt_ovridn_flag = 'Y' and
3785              nvl(l_old_rt_ovridn_thru_dt, l_enrt_rt.rt_strt_dt+1 ) < l_enrt_rt.rt_strt_dt  then -- bug 5942441
3786             --
3787             l_old_rt_ovridn_flag := 'N' ;
3788             l_old_rt_ovridn_thru_dt := null ;
3789             --
3790           end if ;
3791 
3792  -- 7206471 Check if the rates should be adjusted.
3793   --
3794   --
3795   --  Check if there is a life event in the same month.
3796   --
3797   /* Bug 8945818 */
3798   open c_prev_per_in_ler;
3799   fetch c_prev_per_in_ler into l_prev_pil_id;
3800   close c_prev_per_in_ler;
3801   /* End of Bug 8945818 */
3802   hr_utility.set_location('l_prev_pil_id '||l_prev_pil_id,1119);
3803   hr_utility.set_location('pen_id '||p_prtt_enrt_rslt_id,1119);
3804   hr_utility.set_location('l_enrt_rt.rt_strt_dt '||l_enrt_rt.rt_strt_dt,1119);
3805   open c_get_prior_per_in_ler(l_enrt_rt.rt_strt_dt);
3806   fetch c_get_prior_per_in_ler into l_exists;
3807   if c_get_prior_per_in_ler%found then
3808     --
3809       --
3810       open c_get_pgm_extra_info;
3811       fetch c_get_pgm_extra_info into l_adjust;
3812       if c_get_pgm_extra_info%found then
3813         --
3814         if l_adjust = 'Y' then
3815           --
3816           --  Get rt end dt
3817           --
3818           hr_utility.set_location('p_enrt_rt_id '||p_enrt_rt_id,1119);
3819           --for l_epe in c_get_elctbl_chc loop ---- Bug 8507247
3820             --
3821             --  Get all results that were de-enrolled for the event.
3822             --
3823 	    /* Added for Bug 8507247*/
3824 	    open c_get_ptip_id;
3825 	    fetch c_get_ptip_id into l_ptip_id;
3826 	    close c_get_ptip_id;
3827 	    hr_utility.set_location('Before Adjusting ',111);
3828 	    /* End of Bug 8507247*/
3829             for l_pen in c_get_enrt_rslts(l_enrt_rt.rt_strt_dt
3830                                        ,l_ptip_id) loop
3831               hr_utility.set_location('Adjusting rate '||l_enrt_rt.rt_strt_dt,111);
3832 	      open c_prtt_rt_val_adj(p_per_in_ler_id,l_pen.prtt_rt_val_id);
3833               fetch c_prtt_rt_val_adj into l_exists;
3834               if c_prtt_rt_val_adj%notfound then
3835                 insert into BEN_LE_CLSN_N_RSTR (
3836                         BKUP_TBL_TYP_CD,
3837                         BKUP_TBL_ID,
3838                         per_in_ler_id,
3839                         person_id,
3840                         RT_END_DT,
3841                         business_group_id,
3842                         object_version_number)
3843                       values (
3844                         'BEN_PRTT_RT_VAL_ADJ',
3845                         l_pen.prtt_rt_val_id,
3846                         p_per_in_ler_id,
3847                         l_pen.person_id,
3848                         l_pen.rt_end_dt,
3849                         p_business_group_id,
3850                         l_pen.object_version_number
3851                       );
3852               end if;
3853               close c_prtt_rt_val_adj;
3854                --
3855               ben_prtt_rt_val_api.update_prtt_rt_val
3856                (P_VALIDATE                => FALSE
3857                ,P_PRTT_RT_VAL_ID          => l_pen.prtt_rt_val_id
3858                ,P_RT_END_DT               => l_enrt_rt.rt_strt_dt - 1 --Bug 8507247
3859                ,p_person_id               => l_pen.person_id
3860                ,p_input_value_id          => l_pen.input_value_id
3861                ,p_element_type_id         => l_pen.element_type_id
3862                ,p_business_group_id       => p_business_group_id
3863                ,P_OBJECT_VERSION_NUMBER   => l_pen.object_version_number
3864                ,P_EFFECTIVE_DATE          => p_effective_date
3865                );
3866             end loop;  -- c_get_enrt_rslts
3867           --end loop; -- c_get_elctbl_chc -- Bug 8507247
3868         end if;  -- l_adjust = 'Y'
3869       end if;  -- c_get_pgm_extra_info
3870       close c_get_pgm_extra_info;
3871     end if;
3872     close c_get_prior_per_in_ler;
3873     -- end 7206471
3874 
3875           ben_prtt_rt_val_api.create_prtt_rt_val
3876             (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3877             ,p_enrt_rt_id                     => p_enrt_rt_id
3878             ,p_per_in_ler_id                  => p_per_in_ler_id
3879             ,p_rt_typ_cd                      => l_enrt_rt.rt_typ_cd
3880             ,p_tx_typ_cd                      => l_enrt_rt.tx_typ_cd
3881             ,p_acty_typ_cd                    => l_enrt_rt.acty_typ_cd
3882             ,p_mlt_cd                         => l_enrt_rt.rt_mlt_cd
3883             ,p_acty_ref_perd_cd               => p_acty_ref_perd_cd
3884             ,p_rt_val                         => l_rt_val
3885             ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
3886             ,p_rt_end_dt                      => hr_api.g_eot
3887             ,p_ann_rt_val                     => l_ann_rt_val
3888             ,p_bnft_rt_typ_cd                 => l_enrt_rt.bnft_rt_typ_cd
3889             ,p_cmcd_ref_perd_cd               => l_enrt_rt.cmcd_acty_ref_perd_cd
3890             ,p_cmcd_rt_val                    => l_enrt_rt.cmcd_val
3891             ,p_dsply_on_enrt_flag             => l_enrt_rt.dsply_on_enrt_flag
3892             ,p_elctns_made_dt                 => p_effective_date
3893             ,p_cvg_amt_calc_mthd_id           => l_enrt_rt.cvg_amt_calc_mthd_id
3894             ,p_actl_prem_id                   => l_enrt_rt.actl_prem_id
3895             ,p_comp_lvl_fctr_id               => l_enrt_rt.comp_lvl_fctr_id
3896             ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
3897             ,p_business_group_id              => l_enrt_rt.business_group_id
3898             ,p_object_version_number          => l_old_object_version_number
3899             ,p_effective_date                 => p_effective_date
3900             ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3901             ,p_input_value_id                 => l_enrt_rt.input_value_id
3902             ,p_element_type_id                => l_enrt_rt.element_type_id
3903             ,p_person_id                      => p_person_id
3904             ,p_pp_in_yr_used_num              => l_enrt_rt.pp_in_yr_used_num
3905             ,p_ordr_num                       => l_enrt_rt.ordr_num
3906             -- Bug 2677804
3907             ,p_rt_ovridn_flag                 => l_old_rt_ovridn_flag
3908             ,p_rt_ovridn_thru_dt              => l_old_rt_ovridn_thru_dt
3909             --
3910             );
3911           if g_debug then
3912             hr_utility.set_location(l_proc, 135);
3913           end if;
3914         end if;
3915         --
3916       else
3917         --
3918         -- Check for old rate being reused, set end dt to eot.
3919         -- Re-use the rate only if the rate is continuous (maagrawa 2/24/00)
3920         --
3921         if l_old_rt_end_dt is not null and
3922            l_old_rt_end_dt <> hr_api.g_eot and
3923            l_enrt_rt.rt_strt_dt <= l_old_rt_end_dt then
3924           --
3925           if not p_calculate_only_mode then
3926             --
3927             --Bug 2976103 Non Recurring rates are getting opened when called
3928             --from benraten. This needs to happed only for recurring rates.
3929             --
3930             if not l_non_recurring_rt then
3931               --
3932               ben_prtt_rt_val_api.update_prtt_rt_val
3933               (p_prtt_rt_val_id                 => p_prtt_rt_val_id
3934               ,p_rt_end_dt                      => hr_api.g_eot
3935               ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
3936               ,p_input_value_id                 => l_enrt_rt.input_value_id
3937               ,p_element_type_id                => l_enrt_rt.element_type_id
3938               ,p_person_id                      => p_person_id
3939               ,p_ended_per_in_ler_id            => null
3940               ,p_business_group_id              => l_enrt_rt.business_group_id
3941               ,p_object_version_number          => l_old_object_version_number
3942               ,p_effective_date                 => p_effective_date
3943               );
3944               --
3945             end if;
3946             --
3947           end if;
3948           --
3949         end if;
3950 
3951         if g_debug then
3952            hr_utility.set_location(l_proc||'Do nothing if old prv is fine ', 1330);
3953         end if;
3954 
3955       end if;
3956 
3957     else
3958       if g_debug then
3959         hr_utility.set_location(l_proc, 140);
3960       end if;
3961       --
3962       if not p_calculate_only_mode then
3963         --
3964         -- Bug 2677804 if the rate has override thru date in the previous
3965         -- prv and the thru date is on or after the l_enrt_rt.rt_strt_dt
3966         -- we need to carry forward the information for going forward
3967         --        l_old_rt_ovridn_flag            varchar2(30);
3968         --        l_old_rt_ovridn_thru_dt         date;
3969         if l_old_rt_ovridn_flag = 'Y' and
3970             nvl(l_old_rt_ovridn_thru_dt, l_enrt_rt.rt_strt_dt+1 ) < l_enrt_rt.rt_strt_dt then -- bug 5942441
3971           --
3972           l_old_rt_ovridn_flag := 'N' ;
3973           l_old_rt_ovridn_thru_dt := null ;
3974           --
3975         end if ;
3976 	-- 7206471 Check if the rates should be adjusted.
3977   --
3978   --
3979   --  Check if there is a life event in the same month.
3980   --
3981   /* Bug 8945818 */
3982   open c_prev_per_in_ler;
3983   fetch c_prev_per_in_ler into l_prev_pil_id;
3984   close c_prev_per_in_ler;
3985   /* End of Bug 8945818 */
3986   hr_utility.set_location('l_prev_pil_id '||l_prev_pil_id,1119);
3987   hr_utility.set_location('pen_id '||p_prtt_enrt_rslt_id,1119);
3988   hr_utility.set_location('l_enrt_rt.rt_strt_dt '||l_enrt_rt.rt_strt_dt,1119);
3989   open c_get_prior_per_in_ler(l_enrt_rt.rt_strt_dt);
3990   fetch c_get_prior_per_in_ler into l_exists;
3991   if c_get_prior_per_in_ler%found then
3992     --
3993       --
3994       open c_get_pgm_extra_info;
3995       fetch c_get_pgm_extra_info into l_adjust;
3996       if c_get_pgm_extra_info%found then
3997         --
3998         if l_adjust = 'Y' then
3999           --
4000           --  Get rt end dt
4001           --
4002           hr_utility.set_location('p_enrt_rt_id '||p_enrt_rt_id,1119);
4003           --for l_epe in c_get_elctbl_chc loop -- Bug 8507247
4004             --
4005             --  Get all results that were de-enrolled for the event.
4006             --
4007 	    /* Added for Bug 8507247*/
4008 	    open c_get_ptip_id;
4009 	    fetch c_get_ptip_id into l_ptip_id;
4010 	    close c_get_ptip_id;
4011 	    hr_utility.set_location('Before Adjusting rates ',1119);
4012 	    /* End of Bug 8507247*/
4013             for l_pen in c_get_enrt_rslts(l_enrt_rt.rt_strt_dt
4014                                        ,l_ptip_id) loop
4015               hr_utility.set_location('Adjusting rate '||l_enrt_rt.rt_strt_dt,111);
4016               open c_prtt_rt_val_adj(p_per_in_ler_id,l_pen.prtt_rt_val_id);
4017               fetch c_prtt_rt_val_adj into l_exists;
4018               if c_prtt_rt_val_adj%notfound then
4019                 insert into BEN_LE_CLSN_N_RSTR (
4020                         BKUP_TBL_TYP_CD,
4021                         BKUP_TBL_ID,
4022                         per_in_ler_id,
4023                         person_id,
4024                         RT_END_DT,
4025                         business_group_id,
4026                         object_version_number)
4027                       values (
4028                         'BEN_PRTT_RT_VAL_ADJ',
4029                         l_pen.prtt_rt_val_id,
4030                         p_per_in_ler_id,
4031                         l_pen.person_id,
4032                         l_pen.rt_end_dt,
4033                         p_business_group_id,
4034                         l_pen.object_version_number
4035                       );
4036               end if;
4037               close c_prtt_rt_val_adj;
4038                --
4039               ben_prtt_rt_val_api.update_prtt_rt_val
4040                (P_VALIDATE                => FALSE
4041                ,P_PRTT_RT_VAL_ID          => l_pen.prtt_rt_val_id
4042                ,P_RT_END_DT               => l_enrt_rt.rt_strt_dt - 1 --Bug 8507247
4043                ,p_person_id               => l_pen.person_id
4044                ,p_input_value_id          => l_pen.input_value_id
4045                ,p_element_type_id         => l_pen.element_type_id
4046                ,p_business_group_id       => p_business_group_id
4047                ,P_OBJECT_VERSION_NUMBER   => l_pen.object_version_number
4048                ,P_EFFECTIVE_DATE          => p_effective_date
4049                );
4050             end loop;  -- c_get_enrt_rslts
4051           --end loop; -- c_get_elctbl_chc --Bug 8507247
4052         end if;  -- l_adjust = 'Y'
4053       end if;  -- c_get_pgm_extra_info
4054       close c_get_pgm_extra_info;
4055     end if;
4056     close c_get_prior_per_in_ler;
4057     -- end 7206471
4058         -- if no prtt_rt_val_id passed do insert
4059         ben_prtt_rt_val_api.create_prtt_rt_val
4060           (p_prtt_rt_val_id                 => p_prtt_rt_val_id
4061           ,p_enrt_rt_id                     => p_enrt_rt_id
4062           ,p_per_in_ler_id                  => p_per_in_ler_id
4063           ,p_rt_typ_cd                      => l_enrt_rt.rt_typ_cd
4064           ,p_tx_typ_cd                      => l_enrt_rt.tx_typ_cd
4065           ,p_acty_typ_cd                    => l_enrt_rt.acty_typ_cd
4066           ,p_mlt_cd                         => l_enrt_rt.rt_mlt_cd
4067           ,p_acty_ref_perd_cd               => p_acty_ref_perd_cd
4068           ,p_rt_val                         => l_rt_val
4069           ,p_rt_strt_dt                     => l_enrt_rt.rt_strt_dt
4070           ,p_rt_end_dt                      => hr_api.g_eot
4071           ,p_ann_rt_val                     => l_ann_rt_val
4072           ,p_bnft_rt_typ_cd                 => l_enrt_rt.bnft_rt_typ_cd
4073           ,p_cmcd_ref_perd_cd               => l_enrt_rt.cmcd_acty_ref_perd_cd
4074           ,p_cmcd_rt_val                    => l_enrt_rt.cmcd_val
4075           ,p_dsply_on_enrt_flag             => l_enrt_rt.dsply_on_enrt_flag
4076           ,p_elctns_made_dt                 => p_effective_date
4077           ,p_cvg_amt_calc_mthd_id           => l_enrt_rt.cvg_amt_calc_mthd_id
4078           ,p_actl_prem_id                   => l_enrt_rt.actl_prem_id
4079           ,p_comp_lvl_fctr_id               => l_enrt_rt.comp_lvl_fctr_id
4080           ,p_prtt_enrt_rslt_id              => p_prtt_enrt_rslt_id
4081           ,p_business_group_id              => l_enrt_rt.business_group_id
4082           ,p_object_version_number          => l_old_object_version_number
4083           ,p_effective_date                 => p_effective_date
4084           ,p_acty_base_rt_id                => l_enrt_rt.acty_base_rt_id
4085           ,p_input_value_id                 => l_enrt_rt.input_value_id
4086           ,p_element_type_id                => l_enrt_rt.element_type_id
4087           ,p_person_id                      => p_person_id
4088           ,p_pp_in_yr_used_num              => l_enrt_rt.pp_in_yr_used_num
4089           ,p_ordr_num               => l_enrt_rt.ordr_num
4090           -- Bug 2677804
4091           ,p_rt_ovridn_flag                 => l_old_rt_ovridn_flag
4092           ,p_rt_ovridn_thru_dt              => l_old_rt_ovridn_thru_dt
4093           --
4094           );
4095         if g_debug then
4096           hr_utility.set_location(l_proc, 145);
4097         end if;
4098       end if;
4099     end if;
4100     --
4101     -- Check of the rate end date is passed in as parameter.
4102     -- If Yes, then check for the rate end date code.
4103     -- If it is WAENT, then the rate has to be ended with the
4104     -- parameter end date.
4105     --
4106     if not p_calculate_only_mode and
4107        l_rt_end_dt is not null and
4108        l_rt_end_dt <> hr_api.g_eot then
4109       --
4110       if l_xrt_end_dt_cd is null then
4111         ben_determine_date.rate_and_coverage_dates
4112           (p_which_dates_cd         => 'R'
4113           ,p_compute_dates_flag     => 'N'
4114           ,p_business_group_id      => p_business_group_id
4115           ,p_elig_per_elctbl_chc_id => l_enrt_rt.elig_per_elctbl_chc_id
4116           ,p_enrt_cvg_strt_dt       => l_xenrt_cvg_strt_dt
4117           ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
4118           ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
4119           ,p_rt_strt_dt             => l_xrt_strt_dt
4120           ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
4121           ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
4122           ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
4123           ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
4124           ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
4125           ,p_rt_end_dt              => l_xrt_end_dt
4126           ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
4127           ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
4128           ,p_acty_base_rt_id        => l_enrt_rt.acty_base_rt_id
4129           ,p_effective_date         => p_effective_date);
4130       end if;
4131       --
4132       if l_xrt_end_dt_cd = 'WAENT' then
4133         ben_prtt_rt_val_api.update_prtt_rt_val
4134           (p_prtt_rt_val_id                => p_prtt_rt_val_id
4135           ,p_rt_end_dt                     => l_rt_end_dt
4136           ,p_ended_per_in_ler_id           => p_per_in_ler_id
4137           ,p_acty_base_rt_id               => l_enrt_rt.acty_base_rt_id
4138           ,p_input_value_id                => l_enrt_rt.input_value_id
4139           ,p_element_type_id               => l_enrt_rt.element_type_id
4140           ,p_person_id                     => p_person_id
4141           ,p_business_group_id             => l_enrt_rt.business_group_id
4142           ,p_object_version_number         => l_old_object_version_number
4143           ,p_effective_date                => p_effective_date);
4144       end if;
4145       --
4146     end if;
4147 
4148     if l_enrt_rt.decr_bnft_prvdr_pool_id is not null
4149        and l_global_pen_rec.sspndd_flag = 'N' then
4150       --
4151       if not p_calculate_only_mode then
4152         --
4153         ben_provider_pools.create_debit_ledger_entry
4154           (p_person_id               => p_person_id
4155           ,p_per_in_ler_id           => p_per_in_ler_id
4156           ,p_elig_per_elctbl_chc_id  => l_enrt_rt.elig_per_elctbl_chc_id
4157           ,p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id
4158           ,p_decr_bnft_prvdr_pool_id => l_enrt_rt.decr_bnft_prvdr_pool_id
4159           ,p_acty_base_rt_id         => l_enrt_rt.acty_base_rt_id
4160           ,p_prtt_rt_val_id          => p_prtt_rt_val_id
4161           ,p_enrt_mthd_cd            => p_enrt_mthd_cd
4162           ,p_val                     => l_rt_val
4163           ,p_bnft_prvdd_ldgr_id      => l_bnft_prvdd_ldgr_id
4164           ,p_business_group_id       => p_business_group_id
4165           ,p_effective_date          => p_effective_date
4166           --
4167           ,p_bpl_used_val            => l_dummy_number
4168           );
4169         --
4170       end if;
4171       --
4172     end if;
4173     --
4174     if g_debug then
4175       hr_utility.set_location('Leaving:'||l_proc, 99);
4176     end if;
4177 
4178   ben_manage_life_events.fonm := null;
4179   ben_manage_life_events.g_fonm_cvg_strt_dt := null;
4180   ben_manage_life_events.g_fonm_rt_strt_dt := null;
4181   --
4182   -- Set OUT parameters
4183   --
4184   p_prv_rt_val     := l_rt_val;
4185   p_prv_ann_rt_val := l_ann_rt_val;
4186   --
4187 end election_rate_information;
4188 --
4189 -- ----------------------------------------------------------------------------
4190 -- |--------------------------< election_information >-------------------------|
4191 -- ----------------------------------------------------------------------------
4192 -- OVERLOADED, SEE BELOW.
4193 -- Do not add new flags to this procedure unless forms need to pass them.
4194 --
4195 procedure election_information
4196   (p_validate               in boolean default FALSE
4197   ,p_elig_per_elctbl_chc_id in number
4198   ,p_prtt_enrt_rslt_id      in out nocopy number
4199   ,p_effective_date         in date
4200   ,p_enrt_mthd_cd           in varchar2
4201   ,p_enrt_bnft_id           in number
4202   ,p_bnft_val               in number default null
4203   ,p_enrt_cvg_strt_dt       in  date  default null
4204   ,p_enrt_cvg_thru_dt       in  date  default null
4205   ,p_enrt_rt_id1            in number default null
4206   ,p_prtt_rt_val_id1        in out nocopy number
4207   ,p_rt_val1                in number default null
4208   ,p_ann_rt_val1            in number default null
4209   ,p_rt_strt_dt1            in date   default null
4210   ,p_rt_end_dt1             in date   default null
4211   ,p_enrt_rt_id2            in number default null
4212   ,p_prtt_rt_val_id2        in out nocopy number
4213   ,p_rt_val2                in number default null
4214   ,p_ann_rt_val2            in number default null
4215   ,p_rt_strt_dt2            in date   default null
4216   ,p_rt_end_dt2             in date   default null
4217   ,p_enrt_rt_id3            in number default null
4218   ,p_prtt_rt_val_id3        in out nocopy number
4219   ,p_rt_val3                in number default null
4220   ,p_ann_rt_val3            in number default null
4221   ,p_rt_strt_dt3            in date   default null
4222   ,p_rt_end_dt3             in date   default null
4223   ,p_enrt_rt_id4            in number default null
4224   ,p_prtt_rt_val_id4        in out nocopy number
4225   ,p_rt_val4                in number default null
4226   ,p_ann_rt_val4            in number default null
4227   ,p_rt_strt_dt4            in date   default null
4228   ,p_rt_end_dt4             in date   default null
4229   ,p_enrt_rt_id5            in number default null
4230   ,p_prtt_rt_val_id5        in out nocopy number
4231   ,p_rt_val5                in number default null
4232   ,p_ann_rt_val5            in number default null
4233   ,p_rt_strt_dt5            in date   default null
4234   ,p_rt_end_dt5             in date   default null
4235   ,p_enrt_rt_id6            in number default null
4236   ,p_prtt_rt_val_id6        in out nocopy number
4237   ,p_rt_val6                in number default null
4238   ,p_ann_rt_val6            in number default null
4239   ,p_rt_strt_dt6            in date   default null
4240   ,p_rt_end_dt6             in date   default null
4241   ,p_enrt_rt_id7            in number default null
4242   ,p_prtt_rt_val_id7        in out nocopy number
4243   ,p_rt_val7                in number default null
4244   ,p_ann_rt_val7            in number default null
4245   ,p_rt_strt_dt7            in date   default null
4246   ,p_rt_end_dt7             in date   default null
4247   ,p_enrt_rt_id8            in number default null
4248   ,p_prtt_rt_val_id8        in out nocopy number
4249   ,p_rt_val8                in number default null
4250   ,p_ann_rt_val8            in number default null
4251   ,p_rt_strt_dt8            in date   default null
4252   ,p_rt_end_dt8             in date   default null
4253   ,p_enrt_rt_id9            in number default null
4254   ,p_prtt_rt_val_id9        in out nocopy number
4255   ,p_rt_val9                in number default null
4256   ,p_ann_rt_val9            in number default null
4257   ,p_rt_strt_dt9            in date   default null
4258   ,p_rt_end_dt9             in date   default null
4259   ,p_enrt_rt_id10           in number default null
4260   ,p_prtt_rt_val_id10       in out nocopy number
4261   ,p_rt_val10               in number default null
4262   ,p_ann_rt_val10           in number default null
4263   ,p_rt_strt_dt10           in date   default null
4264   ,p_rt_end_dt10            in date   default null
4265   ,p_datetrack_mode         in varchar2
4266   ,p_suspend_flag           in out nocopy varchar2
4267   ,p_effective_start_date   out nocopy date
4268   ,p_effective_end_date     out nocopy date
4269   ,p_object_version_number  in out nocopy number
4270   ,p_prtt_enrt_interim_id   out nocopy number
4271   ,p_business_group_id      in  number
4272   ,p_pen_attribute_category in  varchar2  default hr_api.g_varchar2
4273   ,p_pen_attribute1         in  varchar2  default hr_api.g_varchar2
4274   ,p_pen_attribute2         in  varchar2  default hr_api.g_varchar2
4275   ,p_pen_attribute3         in  varchar2  default hr_api.g_varchar2
4276   ,p_pen_attribute4         in  varchar2  default hr_api.g_varchar2
4277   ,p_pen_attribute5         in  varchar2  default hr_api.g_varchar2
4278   ,p_pen_attribute6         in  varchar2  default hr_api.g_varchar2
4279   ,p_pen_attribute7         in  varchar2  default hr_api.g_varchar2
4280   ,p_pen_attribute8         in  varchar2  default hr_api.g_varchar2
4281   ,p_pen_attribute9         in  varchar2  default hr_api.g_varchar2
4282   ,p_pen_attribute10        in  varchar2  default hr_api.g_varchar2
4283   ,p_pen_attribute11        in  varchar2  default hr_api.g_varchar2
4284   ,p_pen_attribute12        in  varchar2  default hr_api.g_varchar2
4285   ,p_pen_attribute13        in  varchar2  default hr_api.g_varchar2
4286   ,p_pen_attribute14        in  varchar2  default hr_api.g_varchar2
4287   ,p_pen_attribute15        in  varchar2  default hr_api.g_varchar2
4288   ,p_pen_attribute16        in  varchar2  default hr_api.g_varchar2
4289   ,p_pen_attribute17        in  varchar2  default hr_api.g_varchar2
4290   ,p_pen_attribute18        in  varchar2  default hr_api.g_varchar2
4291   ,p_pen_attribute19        in  varchar2  default hr_api.g_varchar2
4292   ,p_pen_attribute20        in  varchar2  default hr_api.g_varchar2
4293   ,p_pen_attribute21        in  varchar2  default hr_api.g_varchar2
4294   ,p_pen_attribute22        in  varchar2  default hr_api.g_varchar2
4295   ,p_pen_attribute23        in  varchar2  default hr_api.g_varchar2
4296   ,p_pen_attribute24        in  varchar2  default hr_api.g_varchar2
4297   ,p_pen_attribute25        in  varchar2  default hr_api.g_varchar2
4298   ,p_pen_attribute26        in  varchar2  default hr_api.g_varchar2
4299   ,p_pen_attribute27        in  varchar2  default hr_api.g_varchar2
4300   ,p_pen_attribute28        in  varchar2  default hr_api.g_varchar2
4301   ,p_pen_attribute29        in  varchar2  default hr_api.g_varchar2
4302   ,p_pen_attribute30        in  varchar2  default hr_api.g_varchar2
4303   ,p_dpnt_actn_warning      out nocopy boolean
4304   ,p_bnf_actn_warning       out nocopy boolean
4305   ,p_ctfn_actn_warning      out nocopy boolean)
4306 is
4307 BEGIN
4308   --
4309   -- Created this procedure so we could add flags to the proc that the
4310   -- forms do not need to pass.  They will call this original spec'ed
4311   -- proc.  The batch processes can call the other one if new flags are needed.
4312   --
4313 
4314   g_debug := hr_utility.debug_enabled;
4315 --hr_utility. set_location( ' p_rt_val1 '||p_rt_val1 , 211);
4316 --hr_utility. set_location( ' p_ann_rt_val1 '||p_ann_rt_val1,211);
4317   -- please mark new flags with a comment.
4318  election_information
4319   (p_validate               => p_validate
4320   ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
4321   ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
4322   ,p_effective_date         => p_effective_date
4323   ,p_enrt_mthd_cd           => p_enrt_mthd_cd
4324   ,p_enrt_bnft_id           => p_enrt_bnft_id
4325   ,p_bnft_val               => p_bnft_val
4326   ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt -- bug 1840961
4327   ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt -- bug 1840961
4328   ,p_enrt_rt_id1            => p_enrt_rt_id1
4329   ,p_prtt_rt_val_id1        => p_prtt_rt_val_id1
4330   ,p_rt_val1                => p_rt_val1
4331   ,p_ann_rt_val1            => p_ann_rt_val1
4332   ,p_rt_strt_dt1            => p_rt_strt_dt1
4333   ,p_rt_end_dt1             => p_rt_end_dt1
4334   ,p_enrt_rt_id2            => p_enrt_rt_id2
4335   ,p_prtt_rt_val_id2        => p_prtt_rt_val_id2
4336   ,p_rt_val2                => p_rt_val2
4337   ,p_ann_rt_val2            => p_ann_rt_val2
4338   ,p_rt_strt_dt2            => p_rt_strt_dt2
4339   ,p_rt_end_dt2             => p_rt_end_dt2
4340   ,p_enrt_rt_id3            => p_enrt_rt_id3
4341   ,p_prtt_rt_val_id3        => p_prtt_rt_val_id3
4342   ,p_rt_val3                => p_rt_val3
4343   ,p_ann_rt_val3            => p_ann_rt_val3
4344   ,p_rt_strt_dt3            => p_rt_strt_dt3
4345   ,p_rt_end_dt3             => p_rt_end_dt3
4346   ,p_enrt_rt_id4            => p_enrt_rt_id4
4347   ,p_prtt_rt_val_id4        => p_prtt_rt_val_id4
4348   ,p_rt_val4                => p_rt_val4
4349   ,p_ann_rt_val4            => p_ann_rt_val4
4350   ,p_rt_strt_dt4            => p_rt_strt_dt4
4351   ,p_rt_end_dt4             => p_rt_end_dt4
4352   ,p_enrt_rt_id5            => p_enrt_rt_id5
4353   ,p_prtt_rt_val_id5        => p_prtt_rt_val_id5
4354   ,p_rt_val5                => p_rt_val5
4355   ,p_ann_rt_val5            => p_ann_rt_val5
4356   ,p_rt_strt_dt5            => p_rt_strt_dt5
4357   ,p_rt_end_dt5             => p_rt_end_dt5
4358   ,p_enrt_rt_id6            => p_enrt_rt_id6
4359   ,p_prtt_rt_val_id6        => p_prtt_rt_val_id6
4360   ,p_rt_val6                => p_rt_val6
4361   ,p_ann_rt_val6            => p_ann_rt_val6
4362   ,p_rt_strt_dt6            => p_rt_strt_dt6
4363   ,p_rt_end_dt6             => p_rt_end_dt6
4364   ,p_enrt_rt_id7            => p_enrt_rt_id7
4365   ,p_prtt_rt_val_id7        => p_prtt_rt_val_id7
4366   ,p_rt_val7                => p_rt_val7
4367   ,p_ann_rt_val7            => p_ann_rt_val7
4368   ,p_rt_strt_dt7            => p_rt_strt_dt7
4369   ,p_rt_end_dt7             => p_rt_end_dt7
4370   ,p_enrt_rt_id8            => p_enrt_rt_id8
4371   ,p_prtt_rt_val_id8        => p_prtt_rt_val_id8
4372   ,p_rt_val8                => p_rt_val8
4373   ,p_ann_rt_val8            => p_ann_rt_val8
4374   ,p_rt_strt_dt8            => p_rt_strt_dt8
4375   ,p_rt_end_dt8             => p_rt_end_dt8
4376   ,p_enrt_rt_id9            => p_enrt_rt_id9
4377   ,p_prtt_rt_val_id9        => p_prtt_rt_val_id9
4378   ,p_rt_val9                => p_rt_val9
4379   ,p_ann_rt_val9            => p_ann_rt_val9
4380   ,p_rt_strt_dt9            => p_rt_strt_dt9
4381   ,p_rt_end_dt9             => p_rt_end_dt9
4382   ,p_enrt_rt_id10           => p_enrt_rt_id10
4383   ,p_prtt_rt_val_id10       => p_prtt_rt_val_id10
4384   ,p_rt_val10               => p_rt_val10
4385   ,p_ann_rt_val10           => p_ann_rt_val10
4386   ,p_rt_strt_dt10           => p_rt_strt_dt10
4387   ,p_rt_end_dt10            => p_rt_end_dt10
4388   ,p_datetrack_mode         => p_datetrack_mode
4389   ,p_suspend_flag           => p_suspend_flag
4390   ,p_called_from_sspnd      => 'N'               -- flag not in this spec
4391   ,p_effective_start_date   => p_effective_start_date
4392   ,p_effective_end_date     => p_effective_end_date
4393   ,p_object_version_number  => p_object_version_number
4394   ,p_prtt_enrt_interim_id   => p_prtt_enrt_interim_id
4395   ,p_business_group_id      =>  p_business_group_id
4396   ,p_pen_attribute_category =>  p_pen_attribute_category
4397   ,p_pen_attribute1         =>  p_pen_attribute1
4398   ,p_pen_attribute2         =>  p_pen_attribute2
4399   ,p_pen_attribute3         =>  p_pen_attribute3
4400   ,p_pen_attribute4         =>  p_pen_attribute4
4401   ,p_pen_attribute5         =>  p_pen_attribute5
4402   ,p_pen_attribute6         =>  p_pen_attribute6
4403   ,p_pen_attribute7         =>  p_pen_attribute7
4404   ,p_pen_attribute8         =>  p_pen_attribute8
4405   ,p_pen_attribute9         =>  p_pen_attribute9
4406   ,p_pen_attribute10        =>  p_pen_attribute10
4407   ,p_pen_attribute11        =>  p_pen_attribute11
4408   ,p_pen_attribute12        =>  p_pen_attribute12
4409   ,p_pen_attribute13        =>  p_pen_attribute13
4410   ,p_pen_attribute14        =>  p_pen_attribute14
4411   ,p_pen_attribute15        =>  p_pen_attribute15
4412   ,p_pen_attribute16        =>  p_pen_attribute16
4413   ,p_pen_attribute17        =>  p_pen_attribute17
4414   ,p_pen_attribute18        =>  p_pen_attribute18
4415   ,p_pen_attribute19        =>  p_pen_attribute19
4416   ,p_pen_attribute20        =>  p_pen_attribute20
4417   ,p_pen_attribute21        =>  p_pen_attribute21
4418   ,p_pen_attribute22        =>  p_pen_attribute22
4419   ,p_pen_attribute23        =>  p_pen_attribute23
4420   ,p_pen_attribute24        =>  p_pen_attribute24
4421   ,p_pen_attribute25        =>  p_pen_attribute25
4422   ,p_pen_attribute26        =>  p_pen_attribute26
4423   ,p_pen_attribute27        =>  p_pen_attribute27
4424   ,p_pen_attribute28        =>  p_pen_attribute28
4425   ,p_pen_attribute29        =>  p_pen_attribute29
4426   ,p_pen_attribute30        =>  p_pen_attribute30
4427   ,p_dpnt_actn_warning      =>  p_dpnt_actn_warning
4428   ,p_bnf_actn_warning       =>  p_bnf_actn_warning
4429   ,p_ctfn_actn_warning      =>  p_ctfn_actn_warning);
4430 
4431 
4432 END election_information;
4433 -- ----------------------------------------------------------------------------
4434 -- |--------------------------< decd_attribute >-------------------------|
4435 -- ----------------------------------------------------------------------------
4436 -- This function is used to assign null value to attribute columns
4437 -- if it contains the value $Sys_Def$
4438 -- created for bug# 2714383
4439 function decd_attribute(l_attribute in varchar2) return varchar2 is
4440      begin
4441      if l_attribute = hr_api.g_varchar2 then
4442      	return null;
4443      else
4444      	return l_attribute;
4445      end if;
4446 end decd_attribute;
4447 
4448 -- ----------------------------------------------------------------------------
4449 -- |--------------------------< determine_erlst_deenrt_dt >-------------------------|
4450 -- ----------------------------------------------------------------------------
4451 
4452 
4453 procedure determine_erlst_deenrt_date(p_oipl_id            in   number,
4454                                  p_pl_id                 in   number  ,
4455                                  p_pl_typ_id             in   number  ,
4456                                  p_ptip_id               in   number  ,
4457                                  p_pgm_id                in   number  ,
4458                                  p_ler_id                in   number   ,
4459                                  p_effective_date        in   date  ,
4460                                  p_business_group_id     in   number    ,
4461                                  p_orgnl_enrt_dt         in   date   ,
4462                                  p_person_id             in   number   ,
4463                                  p_lf_evt_ocrd_dt        in   date   ,
4464                                  p_enrt_cvg_strt_dt      in   date  ,
4465                                  p_return_date           in out nocopy date   )
4466 
4467 is
4468 
4469 
4470     CURSOR c_pl_popl_yr_period_current IS
4471       SELECT   yp.end_date,
4472                pyp.ordr_num
4473       FROM     ben_popl_yr_perd pyp, ben_yr_perd yp
4474       WHERE    pyp.pl_id = p_pl_id
4475       AND      pyp.yr_perd_id = yp.yr_perd_id
4476       AND      pyp.business_group_id = p_business_group_id
4477       AND      p_lf_evt_ocrd_dt BETWEEN yp.start_date AND yp.end_date
4478       AND      yp.business_group_id = p_business_group_id;
4479 
4480 
4481     Cursor c_oipl is
4482        select opt_id
4483        from ben_oipl_f
4484        where oipl_id = p_oipl_id
4485         and  business_group_id = p_business_group_id
4486         and   p_effective_date between EFFECTIVE_START_DATE
4487         AND  EFFECTIVE_END_DATE;
4488 
4489     cursor c_asg is
4490     select asg.assignment_id ,
4491            asg.organization_id
4492     from   per_all_assignments_f asg
4493     where  asg.person_id    = p_person_id
4494     and    asg.assignment_type <> 'C'
4495     and    asg.primary_flag = 'Y'
4496     and    p_effective_date between
4497            asg.effective_start_date and asg.effective_end_date;
4498 
4499      CURSOR c_state IS
4500       SELECT   loc.region_2
4501       FROM     hr_locations_all loc, per_all_assignments_f asg
4502       WHERE    loc.location_id = asg.location_id
4503       AND      asg.person_id = p_person_id
4504       and      asg.assignment_type <> 'C'
4505       AND      asg.primary_flag = 'Y'
4506       AND      p_lf_evt_ocrd_dt BETWEEN asg.effective_start_date
4507                    AND asg.effective_end_date
4508       AND      asg.business_group_id = p_business_group_id;
4509     --
4510     l_state                    c_state%ROWTYPE;
4511 
4512 
4513      l_opt_id                       number(15) ;
4514      l_level                       varchar2(5) ;
4515      l_rqd_perd_enrt_nenrt_uom      VARCHAR2(30);
4516      l_rqd_perd_enrt_nenrt_val      NUMBER;
4517      l_rqd_perd_enrt_nenrt_rl       NUMBER;
4518      l_erlst_deenrt_calc_dt         date  ;
4519      l_jurisdiction_code            VARCHAR2(30);
4520      l_popl_yr_perd_ordr_num        NUMBER;
4521      l_yr_perd_end_date             DATE;
4522      l_rec_assignment_id            NUMBER;
4523      l_rec_organization_id          NUMBER;
4524 
4525 
4526 begin
4527 
4528   g_debug := hr_utility.debug_enabled;
4529   if p_oipl_id is not  null then
4530      open c_oipl ;
4531      fetch c_oipl  into l_opt_id ;
4532      close c_oipl ;
4533   end if ;
4534 
4535 -- 4031733 - Cursor c_state populates l_state variable which is no longer
4536 -- used in the package. Cursor can be commented
4537 /*
4538   OPEN c_state;
4539   FETCH c_state INTO l_state;
4540   CLOSE c_state;
4541 */
4542   --IF l_state.region_2 IS NOT NULL THEN
4543   --    l_jurisdiction_code :=
4544   --     pay_mag_utils.lookup_jurisdiction_code(p_state => l_state.region_2);
4545   --END IF;
4546 
4547   OPEN c_asg;
4548   FETCH c_asg INTO l_rec_assignment_id, l_rec_organization_id;
4549   close c_asg;
4550 
4551 
4552    OPEN c_pl_popl_yr_period_current;
4553     --
4554    FETCH c_pl_popl_yr_period_current INTO  l_yr_perd_end_date,
4555                                            l_popl_yr_perd_ordr_num;
4556    CLOSE c_pl_popl_yr_period_current;
4557 
4558 
4559   ben_enrolment_requirements.find_rqd_perd_enrt(
4560       p_oipl_id                 => p_oipl_id,
4561       p_opt_id                  => l_opt_id,
4562       p_pl_id                   => p_pl_id,
4563       p_ptip_id                 => p_ptip_id,
4564       p_effective_date          => p_effective_date,
4565       p_business_group_id       => p_business_group_id,
4566       p_rqd_perd_enrt_nenrt_uom => l_rqd_perd_enrt_nenrt_uom,
4567       p_rqd_perd_enrt_nenrt_val => l_rqd_perd_enrt_nenrt_val,
4568       p_rqd_perd_enrt_nenrt_rl  => l_rqd_perd_enrt_nenrt_rl,
4569       p_level                   => l_level);
4570 
4571 
4572      l_erlst_deenrt_calc_dt   :=   p_enrt_cvg_strt_dt ;
4573   If l_level is not null and l_level not in('OPT','OIPL') then
4574      l_erlst_deenrt_calc_dt := nvl(p_orgnl_enrt_dt,p_enrt_cvg_strt_dt );
4575   end if ;
4576 
4577   if g_debug then
4578     hr_utility.set_location('uom'||l_rqd_perd_enrt_nenrt_uom ,8086.1);
4579   end if;
4580   if g_debug then
4581     hr_utility.set_location('val'||l_rqd_perd_enrt_nenrt_val ,8086.1);
4582   end if;
4583   if g_debug then
4584     hr_utility.set_location('cvg_dt '||l_erlst_deenrt_calc_dt  ,8086.1);
4585   end if;
4586   if g_debug then
4587     hr_utility.set_location('date before calca'||p_return_date ,8086.1);
4588   end if;
4589   if (l_rqd_perd_enrt_nenrt_val is  not null and l_rqd_perd_enrt_nenrt_uom is not null )
4590      or l_rqd_perd_enrt_nenrt_rl is not null then
4591        p_return_date :=
4592        ben_enrolment_requirements.determine_erlst_deenrt_dt(
4593          l_erlst_deenrt_calc_dt,
4594          l_rqd_perd_enrt_nenrt_val,
4595          l_rqd_perd_enrt_nenrt_uom,
4596          l_rqd_perd_enrt_nenrt_rl,
4597          p_oipl_id,
4598          p_pl_id,
4599          p_pl_typ_id,
4600          l_opt_id,
4601          p_pgm_id,
4602          p_ler_id,
4603          l_popl_yr_perd_ordr_num,
4604          l_yr_perd_end_date,
4605          p_effective_date,
4606          p_lf_evt_ocrd_dt,
4607          p_person_id,
4608          p_business_group_id,
4609          l_rec_assignment_id,
4610          l_rec_organization_id,
4611          l_jurisdiction_code);
4612   end if ;
4613   if g_debug then
4614     hr_utility.set_location('date after  calca'||p_return_date ,8086.1);
4615   end if;
4616 
4617 END determine_erlst_deenrt_date ;
4618 
4619 
4620 
4621 
4622 
4623 
4624 -- ----------------------------------------------------------------------------
4625 -- |--------------------------< election_information >-------------------------|
4626 -- ----------------------------------------------------------------------------
4627 -- OVERLOADED, SEE ABOVE.
4628 -- If new flags are need for the rco flow and not needed => forms, add them to
4629 -- this procedure.
4630 --
4631 procedure election_information
4632   (p_validate               in boolean default FALSE
4633   ,p_elig_per_elctbl_chc_id in number
4634   ,p_prtt_enrt_rslt_id      in out nocopy number
4635   ,p_effective_date         in date
4636   ,p_enrt_mthd_cd           in varchar2
4637   ,p_enrt_bnft_id           in number
4638   ,p_bnft_val               in number default null
4639   ,p_enrt_cvg_strt_dt       in  date  default null
4640   ,p_enrt_cvg_thru_dt       in  date  default null
4641   ,p_enrt_rt_id1            in number default null
4642   ,p_prtt_rt_val_id1        in out nocopy number
4643   ,p_rt_val1                in number default null
4644   ,p_ann_rt_val1            in number default null
4645   ,p_rt_strt_dt1            in date   default null
4646   ,p_rt_end_dt1             in date   default null
4647   ,p_enrt_rt_id2            in number default null
4648   ,p_prtt_rt_val_id2        in out nocopy number
4649   ,p_rt_val2                in number default null
4650   ,p_ann_rt_val2            in number default null
4651   ,p_rt_strt_dt2            in date   default null
4652   ,p_rt_end_dt2             in date   default null
4653   ,p_enrt_rt_id3            in number default null
4654   ,p_prtt_rt_val_id3        in out nocopy number
4655   ,p_rt_val3                in number default null
4656   ,p_ann_rt_val3            in number default null
4657   ,p_rt_strt_dt3            in date   default null
4658   ,p_rt_end_dt3             in date   default null
4659   ,p_enrt_rt_id4            in number default null
4660   ,p_prtt_rt_val_id4        in out nocopy number
4661   ,p_rt_val4                in number default null
4662   ,p_ann_rt_val4            in number default null
4663   ,p_rt_strt_dt4            in date   default null
4664   ,p_rt_end_dt4             in date   default null
4665   ,p_enrt_rt_id5            in number default null
4666   ,p_prtt_rt_val_id5        in out nocopy number
4667   ,p_rt_val5                in number default null
4668   ,p_ann_rt_val5            in number default null
4669   ,p_rt_strt_dt5            in date   default null
4670   ,p_rt_end_dt5             in date   default null
4671   ,p_enrt_rt_id6            in number default null
4672   ,p_prtt_rt_val_id6        in out nocopy number
4673   ,p_rt_val6                in number default null
4674   ,p_ann_rt_val6            in number default null
4675   ,p_rt_strt_dt6            in date   default null
4676   ,p_rt_end_dt6             in date   default null
4677   ,p_enrt_rt_id7            in number default null
4678   ,p_prtt_rt_val_id7        in out nocopy number
4679   ,p_rt_val7                in number default null
4680   ,p_ann_rt_val7            in number default null
4681   ,p_rt_strt_dt7            in date   default null
4682   ,p_rt_end_dt7             in date   default null
4683   ,p_enrt_rt_id8            in number default null
4684   ,p_prtt_rt_val_id8        in out nocopy number
4685   ,p_rt_val8                in number default null
4686   ,p_ann_rt_val8            in number default null
4687   ,p_rt_strt_dt8            in date   default null
4688   ,p_rt_end_dt8             in date   default null
4689   ,p_enrt_rt_id9            in number default null
4690   ,p_prtt_rt_val_id9        in out nocopy number
4691   ,p_rt_val9                in number default null
4692   ,p_ann_rt_val9            in number default null
4693   ,p_rt_strt_dt9            in date   default null
4694   ,p_rt_end_dt9             in date   default null
4695   ,p_enrt_rt_id10           in number default null
4696   ,p_prtt_rt_val_id10       in out nocopy number
4697   ,p_rt_val10               in number default null
4698   ,p_ann_rt_val10           in number default null
4699   ,p_rt_strt_dt10           in date   default null
4700   ,p_rt_end_dt10            in date   default null
4701   ,p_datetrack_mode         in varchar2
4702   ,p_suspend_flag           in out nocopy varchar2
4703   ,p_called_from_sspnd      in varchar2          -- flag not other spec
4704   ,p_effective_start_date   out nocopy date
4705   ,p_effective_end_date     out nocopy date
4706   ,p_object_version_number  in out nocopy number
4707   ,p_prtt_enrt_interim_id   out nocopy number
4708   ,p_business_group_id      in  number
4709   ,p_pen_attribute_category in  varchar2  default hr_api.g_varchar2
4710   ,p_pen_attribute1         in  varchar2  default hr_api.g_varchar2
4711   ,p_pen_attribute2         in  varchar2  default hr_api.g_varchar2
4712   ,p_pen_attribute3         in  varchar2  default hr_api.g_varchar2
4713   ,p_pen_attribute4         in  varchar2  default hr_api.g_varchar2
4714   ,p_pen_attribute5         in  varchar2  default hr_api.g_varchar2
4715   ,p_pen_attribute6         in  varchar2  default hr_api.g_varchar2
4716   ,p_pen_attribute7         in  varchar2  default hr_api.g_varchar2
4717   ,p_pen_attribute8         in  varchar2  default hr_api.g_varchar2
4718   ,p_pen_attribute9         in  varchar2  default hr_api.g_varchar2
4719   ,p_pen_attribute10        in  varchar2  default hr_api.g_varchar2
4720   ,p_pen_attribute11        in  varchar2  default hr_api.g_varchar2
4721   ,p_pen_attribute12        in  varchar2  default hr_api.g_varchar2
4722   ,p_pen_attribute13        in  varchar2  default hr_api.g_varchar2
4723   ,p_pen_attribute14        in  varchar2  default hr_api.g_varchar2
4724   ,p_pen_attribute15        in  varchar2  default hr_api.g_varchar2
4725   ,p_pen_attribute16        in  varchar2  default hr_api.g_varchar2
4726   ,p_pen_attribute17        in  varchar2  default hr_api.g_varchar2
4727   ,p_pen_attribute18        in  varchar2  default hr_api.g_varchar2
4728   ,p_pen_attribute19        in  varchar2  default hr_api.g_varchar2
4729   ,p_pen_attribute20        in  varchar2  default hr_api.g_varchar2
4730   ,p_pen_attribute21        in  varchar2  default hr_api.g_varchar2
4731   ,p_pen_attribute22        in  varchar2  default hr_api.g_varchar2
4732   ,p_pen_attribute23        in  varchar2  default hr_api.g_varchar2
4733   ,p_pen_attribute24        in  varchar2  default hr_api.g_varchar2
4734   ,p_pen_attribute25        in  varchar2  default hr_api.g_varchar2
4735   ,p_pen_attribute26        in  varchar2  default hr_api.g_varchar2
4736   ,p_pen_attribute27        in  varchar2  default hr_api.g_varchar2
4737   ,p_pen_attribute28        in  varchar2  default hr_api.g_varchar2
4738   ,p_pen_attribute29        in  varchar2  default hr_api.g_varchar2
4739   ,p_pen_attribute30        in  varchar2  default hr_api.g_varchar2
4740   ,p_dpnt_actn_warning      out nocopy boolean
4741   ,p_bnf_actn_warning       out nocopy boolean
4742   ,p_ctfn_actn_warning      out nocopy boolean
4743   ,p_imp_cvg_strt_dt        in  date default NULL) -- 8716870
4744 is
4745   -- Local variable Declarations
4746 
4747   l_prtt_enrt_rslt_id                 number;
4748   l_old_bnft_val                      number;
4749   l_old_enrt_cvg_strt_dt              date;
4750   l_old_enrt_cvg_thru_dt              date;
4751   l_old_erlst_deenrt_dt               date ;
4752   l_old_pl_id                         number;
4753   l_old_oipl_id                       number;
4754   l_old_per_in_ler_id                 number;
4755   l_old_ovn                           number;
4756 --  l_prtt_is_cvrd_flag               varchar2(30);
4757   l_orgnl_enrt_dt                     date;
4758   l_old_orgnl_enrt_dt                 date;
4759   l_enrt_mthd_cd                      varchar2(30);
4760   l_enrt_ovridn_flag                  varchar2(30);
4761   l_enrt_ovrid_rsn_cd                 varchar2(30);
4762   l_enrt_ovrid_thru_dt                date;
4763   l_enrt_cvg_thru_dt                  date;
4764   l_enrt_cvg_strt_dt                  date;
4765 
4766 l_global_epe_rec ben_global_enrt.g_global_epe_rec_type;
4767 l_global_pel_rec ben_global_enrt.g_global_pel_rec_type;
4768 l_global_pil_rec ben_global_enrt.g_global_pil_rec_type;
4769 l_global_enb_rec ben_global_enrt.g_global_enb_rec_type;
4770 l_global_pen_rec ben_prtt_enrt_rslt_f%rowtype;
4771 
4772   l_xenrt_cvg_strt_dt                 date;
4773   l_xenrt_cvg_strt_dt_cd              varchar2(30);
4774   l_xenrt_cvg_strt_dt_rl              number;
4775   l_xrt_strt_dt                       date;
4776   l_xrt_strt_dt_cd                    varchar2(30);
4777   l_xrt_strt_dt_rl                    number;
4778   l_xenrt_cvg_end_dt                  date;
4779   l_xenrt_cvg_end_dt_cd               varchar2(30);
4780   l_xenrt_cvg_end_dt_rl               number;
4781   l_xrt_end_dt                        date;
4782   l_xrt_end_dt_cd                     varchar2(30);
4783   l_xrt_end_dt_rl                     number;
4784   l_prtt_enrt_interim_id              number;
4785   l_dpnt_actn_warning                 boolean := FALSE;
4786   l_bnf_actn_warning                  boolean := FALSE;
4787   l_ctfn_actn_warning                 boolean := FALSE;
4788   l_action                            varchar2(30);
4789   --
4790   l_pl_rec         ben_cobj_cache.g_pl_inst_row;
4791   l_oipl_rec       ben_cobj_cache.g_oipl_inst_row;
4792   l_plip_rec       ben_cobj_cache.g_plip_inst_row;
4793   l_ptip_rec       ben_cobj_cache.g_ptip_inst_row;
4794   --
4795   l_bnft_amt_changed                  boolean := FALSE;
4796   l_use_new_result                    boolean := FALSE;
4797   l_crntly_enrd_rslt_exists           boolean := false;
4798   l_elect_cvg_strt_dt                 date    ;
4799   l_datetrack_mode                    varchar2(30);
4800   --
4801   l_proc                              varchar2(72) :=
4802                                          g_package||'election_information';
4803   l_object_version_number             number;
4804   l_dummy_number                      number;
4805   --
4806   -- current result info
4807   -- ben_sspndd_enrollment.g_use_new_result
4808   --
4809   cursor c_current_result_info(v_prtt_enrt_rslt_id number) is
4810     select pen.enrt_cvg_strt_dt,
4811            pen.enrt_cvg_thru_dt,
4812            pen.bnft_amt,
4813            pen.pl_id,
4814            pen.oipl_id,
4815            pen.orgnl_enrt_dt,
4816            pen.per_in_ler_id,
4817            pen.object_version_number,
4818            pen.erlst_deenrt_dt ,
4819            pen.enrt_ovrid_thru_dt,
4820            pen.enrt_ovrid_rsn_cd,
4821            pen.enrt_ovridn_flag,
4822            pen.sspndd_flag
4823     from   ben_prtt_enrt_rslt_f pen
4824     where  pen.prtt_enrt_rslt_id=v_prtt_enrt_rslt_id and
4825            pen.business_group_id=p_business_group_id and
4826            pen.prtt_enrt_rslt_stat_cd is null        and
4827            p_effective_date between
4828              pen.effective_start_date and pen.effective_end_date
4829     ;
4830   --
4831   l_crntly_enrd_rslt_rec  c_current_result_info%rowtype;
4832   -- Bug 2627078 fixes
4833   cursor c_delink_interim(v_prtt_enrt_rslt_id number, v_sspnd_result_id number ) is
4834     select pen.prtt_enrt_rslt_id ,
4835            pen.object_version_number
4836     from   ben_prtt_enrt_rslt_f pen
4837     where  pen.rplcs_sspndd_rslt_id = v_prtt_enrt_rslt_id and
4838            pen.prtt_enrt_rslt_id = v_sspnd_result_id and
4839            p_effective_date between
4840              pen.effective_start_date and pen.effective_end_date
4841     ;
4842   --
4843   l_delink_interim    c_delink_interim%rowtype ;
4844   --
4845   cursor oipl_ordr_num_c (p_oipl_id number) is
4846      select ordr_num
4847        from ben_oipl_f
4848       where oipl_id = p_oipl_id and
4849             business_group_id   = p_business_group_id and
4850             p_effective_date between
4851                      effective_start_date and effective_end_date
4852     ;
4853     cursor c_regn_125_or_129 is
4854       select   'Y'
4855       from     ben_pl_regn_f prg,
4856                ben_regn_f regn
4857       where    prg.pl_id=l_global_epe_rec.pl_id
4858            and p_effective_date between
4859                prg.effective_start_date and prg.effective_end_date
4860            and prg.business_group_id=p_business_group_id
4861            and regn.regn_id=prg.regn_id
4862            and regn.name in ('IRC Section 125','IRC Section 129')
4863            and p_effective_date between
4864                regn.effective_start_date and regn.effective_end_date
4865            and regn.business_group_id=p_business_group_id
4866       ;
4867     l_regn_125_or_129_flag         varchar2(30);
4868     l_ret number;
4869     -- Bug 1913254
4870     -- Following cursor is for getting the annual val for
4871     -- cvg_mlt_cd of SAAEAR and enter value at enrollment is not checked.
4872 /*
4873     cursor c_ert is
4874       select  ann_val
4875       from    ben_enrt_rt ert
4876       where   ert.enrt_bnft_id = p_enrt_bnft_id
4877          and  ENTR_VAL_AT_ENRT_FLAG = 'N'
4878          and  ann_val is not null ;
4879     l_ann_enrt_rt number ;
4880 */
4881     -- Bug 2212194 to fix the issue of having multiple rates associated
4882     -- with the comp object.
4883     --
4884     -- changed, bug: 5584813
4885     cursor c_ert is
4886       select  ert.ann_val,ert.ENTR_VAL_AT_ENRT_FLAG,
4887 	      abr.acty_base_rt_id,
4888 	      abr.rate_periodization_rl,
4889 	      enb.elig_per_elctbl_chc_id,
4890 	      ert.entr_ann_val_flag
4891       from    ben_enrt_rt ert,
4892               ben_acty_base_rt_f abr,
4893 	      ben_enrt_bnft enb
4894       where  enb.enrt_bnft_id = p_enrt_bnft_id
4895          and ert.enrt_bnft_id = enb.enrt_bnft_id
4896          and nvl(abr.PARNT_CHLD_CD,'PARNT') = 'PARNT'
4897          and abr.acty_base_rt_id = ert.acty_base_rt_id
4898          and p_effective_date between abr.effective_start_date
4899              and abr.effective_end_date
4900          and ert.acty_typ_cd not like 'PRD%'
4901          and ert.acty_typ_cd <> 'PRFRFS' ;
4902          -- and  ENTR_VAL_AT_ENRT_FLAG = 'Y'
4903          -- and  ann_val is not null ;
4904     l_ert c_ert%rowtype;
4905     l_dummy_rt_val NUMBER;
4906     --
4907     --Bug 2172036 populating the assignment_id in the pen
4908     cursor c_epe is
4909       select epe.assignment_id ,
4910              epe.fonm_cvg_strt_dt
4911       from ben_elig_per_elctbl_chc epe
4912       where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id ;
4913     --
4914     cursor c_enb_pen is
4915       select enb.prtt_enrt_rslt_id
4916       from ben_enrt_bnft enb,
4917            ben_prtt_enrt_rslt_f pen
4918       where enb.enrt_bnft_id = p_enrt_bnft_id
4919         and enb.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
4920         and pen.effective_end_date = hr_api.g_eot
4921         and pen.enrt_cvg_thru_dt = hr_api.g_eot
4922         and pen.prtt_enrt_rslt_stat_cd is NULL
4923         ;
4924     --
4925     -- Bug 2600087 fixes to open future dated coverage
4926     cursor c_enrt_rslt is
4927       select pen.*
4928       from   ben_prtt_enrt_rslt_f pen
4929       where  pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4930       and    pen.prtt_enrt_rslt_stat_cd is null
4931       and    pen.effective_end_date = (select pen2.effective_start_date - 1
4932       from   ben_prtt_enrt_rslt_f pen2
4933       where    pen2.enrt_cvg_thru_dt <> hr_api.g_eot
4934       and    pen2.effective_end_date = hr_api.g_eot
4935       and    pen2.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4936       and    pen2.prtt_enrt_rslt_stat_cd is null);
4937 
4938 
4939   -- Bug 14803995
4940   cursor c_unrest(c_per_in_ler_id number) is
4941           select ler.typ_cd from
4942 	  ben_per_in_ler pil,ben_ler_f ler
4943 	  where pil.ler_id=ler.ler_id
4944 	  and p_effective_date between ler.effective_start_date
4945 	  and ler.effective_end_date
4946 	  and pil.per_in_ler_id=c_per_in_ler_id;
4947 
4948     l_typ_cd varchar2(10);
4949 
4950 
4951       /*Bug 12576710 */
4952    cursor c_bkp_enrt_rslt_exist is
4953       select pen.*
4954       from   ben_prtt_enrt_rslt_f pen
4955       where  pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4956       and    pen.prtt_enrt_rslt_stat_cd is null
4957       and    pen.effective_end_date = (select pen2.effective_start_date - 1
4958       from   ben_prtt_enrt_rslt_f pen2
4959       where    pen2.enrt_cvg_thru_dt <> hr_api.g_eot
4960       and    pen2.effective_end_date = hr_api.g_eot
4961       and    pen2.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4962       and    pen2.prtt_enrt_rslt_stat_cd is null)
4963       and not exists
4964           (select '1' from ben_le_clsn_n_rstr bkp where
4965             bkp.per_in_ler_id =  pen.per_in_ler_id
4966             and bkp.effective_end_date = pen.effective_end_date
4967             and bkp.BKUP_TBL_ID = pen.prtt_enrt_rslt_id
4968             and bkp.enrt_cvg_thru_dt = pen.enrt_cvg_thru_dt
4969             and bkp.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_ADJ');
4970 
4971   l_bkp_enrt c_bkp_enrt_rslt_exist%rowtype;
4972    --
4973    --bug#5032364
4974     cursor c_enrt_rslt2 is
4975       select pen.*
4976       from   ben_prtt_enrt_rslt_f pen
4977       where  pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4978       and    pen.prtt_enrt_rslt_stat_cd is null
4979       and    pen.effective_end_date = hr_api.g_eot;
4980    --
4981     l_enrt_rslt2   c_enrt_rslt2%rowtype;
4982    --
4983    -- 5612091 - Added OR condition with p_elig_per_elctbl_chc_id
4984     cursor c_enrt_rt (p_acty_base_rt_id number) is
4985       select enrt_rt_id
4986       from ben_enrt_rt ecr
4987       where (ecr.enrt_bnft_id = p_enrt_bnft_id
4988        or ecr.ELIG_PER_ELCTBL_CHC_ID = p_elig_per_elctbl_chc_id)
4989       and ecr.acty_base_rt_id = p_acty_base_rt_id;
4990    --
4991     cursor c_prtt_rt_val_id is
4992       select prv.prtt_rt_val_id,
4993              prv.acty_base_rt_id
4994       from ben_prtt_rt_val prv
4995       where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
4996         and prv.prtt_rt_val_stat_cd is null
4997         order by prv.rt_strt_dt asc;
4998     --
4999     -- Bug 5766477.
5000     --
5001     cursor c_get_dpnt(p_effective_date in date) is
5002       select pdp.*
5003       from   ben_elig_cvrd_dpnt_f pdp
5004       where  pdp.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5005       and    pdp.cvg_thru_dt is not null
5006       and    pdp.effective_end_date <> hr_api.g_eot
5007       and    p_effective_date
5008              between pdp.effective_start_date
5009              and pdp.effective_end_date;
5010     --
5011     cursor c_pen_exists(v_prtt_enrt_rslt_id number) is
5012       select 'x'
5013     from  ben_prtt_enrt_rslt_f pen
5014     where pen.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5015      and  pen.business_group_id = p_business_group_id
5016      and  p_effective_date between pen.effective_start_date
5017                   and pen.effective_end_date ;
5018 
5019     cursor c_wv_opt (p_oipl_id number ) is
5020        select opt.invk_wv_opt_flag
5021          from ben_opt_f opt , ben_oipl_f oipl
5022         where oipl.oipl_id = p_oipl_id
5023          and  oipl.opt_id = opt.opt_id
5024          and  oipl.business_group_id   = p_business_group_id
5025          and  p_effective_date between  oipl.effective_start_date and oipl.effective_end_date
5026          and  p_effective_date between  opt.effective_start_date and opt.effective_end_date ;
5027 
5028     -- to check the future coverage deleted
5029     l_wv_flag      varchar2(30);
5030     l_dummy_char   varchar2(30) ;
5031     l_enrt_rslt    c_enrt_rslt%rowtype;
5032     l_enrt_rt_id    number;
5033     l_prtt_rt_val_id  number;
5034     l_assignment_id number(15);
5035     l_start_new_result     boolean := false;
5036     l_object_version_number2 number := p_object_version_number;
5037     l_effective_start_date  date;
5038     l_effective_end_date    date;
5039     l_acty_base_rt_id2   number;
5040     l_dlink_effective_start_date  date;
5041     l_dlink_effective_end_date    date;
5042     l_old_enrt_ovrid_thru_dt      date;
5043     l_old_enrt_ovrid_rsn_cd       varchar2(30);
5044     l_old_enrt_ovridn_flag        varchar2(30) := 'N' ;
5045     l_old_sspndd_flag             varchar2(30);
5046     l_new_cvg_strt_dt             date;
5047     l_fonm_cvg_strt_dt            date ;
5048     l_fonm_flag                   varchar2(30) := 'N' ;
5049     l_interim                     varchar2(1); -- 12421421
5050     l_curr_enrt_cvg_strt_dt       date; -- 12421421
5051   --
5052     l_interim_count number;--3733745
5053     --
5054     l_enb_prtt_enrt_rslt_id number ;
5055     --
5056     -- Bug 5600697
5057     --
5058     cursor c_is_pen_valid(cv_prtt_enrt_rslt_id number) is
5059       select pen.prtt_enrt_Rslt_stat_Cd
5060       from   ben_prtt_enrt_rslt_f pen
5061       where  pen.prtt_enrt_rslt_id = cv_prtt_enrt_rslt_id and
5062              pen.business_group_id= p_business_group_id and
5063              p_effective_date between pen.effective_start_date and pen.effective_end_date;
5064     --
5065     l_pen_stat_cd varchar2(30);
5066     --
5067     cursor c_pen_curr(v_prtt_enrt_rslt_id number,
5068                          p_effective_date date,
5069                          p_per_in_ler_id number) is -- 12583091
5070       select pen.*
5071       from   ben_prtt_enrt_rslt_f pen
5072       where  pen.prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
5073       and    p_effective_date between
5074              pen.effective_start_date and pen.effective_end_date
5075       and    pen.effective_end_date <> hr_api.g_eot
5076       and    pen.per_in_ler_id <> p_per_in_ler_id -- 12583091
5077       and    pen.prtt_enrt_rslt_stat_cd is null
5078       and    pen.business_group_id = p_business_group_id
5079       order by pen.effective_start_date desc ;
5080     --
5081     l_pen_curr    c_pen_curr%rowtype;
5082     l_pen_curr_interim c_pen_curr%rowtype;
5083     --
5084     -- 12421421
5085     --
5086     cursor c_get_interim(v_prtt_enrt_rslt_id number
5087                         ,p_per_in_ler_id number
5088                         ,p_effective_date date
5089                         ,p_prtt_enrt_rslt_id number) is
5090       select null
5091       from   ben_prtt_enrt_rslt_f pen
5092       where  pen.prtt_enrt_rslt_id = v_prtt_enrt_rslt_id
5093       and    p_effective_date between
5094              pen.effective_start_date and pen.effective_end_date
5095       and    pen.per_in_ler_id = p_per_in_ler_id
5096       and    pen.sspndd_flag = 'Y'
5097       and    pen.prtt_enrt_rslt_stat_cd is null
5098       and    pen.rplcs_sspndd_rslt_id = p_prtt_enrt_rslt_id
5099       and    pen.business_group_id = p_business_group_id;
5100     --
5101     cursor c_get_ended_result(p_elig_per_elctbl_chc_id number
5102                              ,p_per_in_ler_id number
5103                              ) is
5104       select pen.*
5105       from   ben_prtt_enrt_rslt_f pen
5106             ,ben_elig_per_elctbl_chc epe
5107       where  nvl(epe.pgm_id, -1) = nvl(pen.pgm_id, -1)
5108       and    epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id -- 13542327
5109       and    epe.pl_id = pen.pl_id
5110       and    nvl(epe.oipl_id, -1) = nvl(pen.oipl_id, -1)
5111       and    pen.per_in_ler_id = p_per_in_ler_id
5112       and    pen.prtt_enrt_rslt_stat_cd is null
5113       and    pen.business_group_id = p_business_group_id
5114       and    pen.enrt_cvg_thru_dt <> hr_api.g_eot
5115       and    pen.effective_end_date = hr_api.g_eot;
5116     --
5117     l_ended_pen            c_get_ended_result%rowtype;
5118     --
5119     -- end 12421421
5120     --
5121     cursor c_prv(p_prtt_enrt_rslt_id number, p_per_in_ler_id number) is
5122     select prv.*
5123       from ben_prtt_rt_val prv
5124      where prv.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id
5125        and prv.per_in_ler_id = p_per_in_ler_id
5126        and prv.prtt_rt_val_stat_cd is NULL ;
5127     --
5128     cursor c_ecr(p_prtt_rt_val_id number) is
5129     select ecr.rt_strt_dt,
5130            ecr.rt_strt_dt_cd,
5131            ecr.rt_strt_dt_rl,
5132            nvl(ecr.elig_per_elctbl_chc_id,enb.elig_per_elctbl_chc_id) elig_per_elctbl_chc_id
5133      from ben_enrt_rt ecr,
5134           ben_enrt_bnft enb
5135     where ecr.prtt_rt_val_id = p_prtt_rt_val_id
5136       and ecr.enrt_bnft_id = enb.enrt_bnft_id (+) ;
5137     --
5138     l_ecr   c_ecr%rowtype;
5139     -- bug 5621049
5140      cursor c_validate_epe_pen(cv_elig_per_elctblc_chc_id number,cv_prtt_enrt_rslt_id number ) is
5141      select null
5142      from ben_elig_per_elctbl_chc
5143      where elig_per_elctbl_chc_id = cv_elig_per_elctblc_chc_id
5144      and prtt_enrt_rslt_id = cv_prtt_enrt_rslt_id;
5145 
5146    ------Bug 7374973
5147   cursor c_unrestricted(p_ler_id number) is
5148    select ler.typ_cd
5149      from ben_ler_f ler
5150     where ler_id = p_ler_id
5151       and ler.business_group_id = p_business_group_id;
5152    l_unrestricted c_unrestricted%rowtype;
5153 
5154      -- Added for bug 7206471
5155   --
5156    /* Added cursor for Bug 8945818: Get the previous per_in_ler_id */
5157 
5158    cursor c_prev_per_in_ler is
5159     select pil.per_in_ler_id
5160     from   ben_per_in_ler pil,
5161            ben_per_in_ler pil1,
5162            ben_ler_f ler,
5163 	   ben_elig_per_elctbl_chc epe
5164     where  pil1.per_in_ler_id = epe.per_in_ler_id
5165     and    epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5166     and    pil1.person_id = pil.person_id
5167     and    pil1.per_in_ler_id <> pil.per_in_ler_id
5168     and    pil.ler_id        = ler.ler_id
5169     and    p_effective_date between
5170            ler.effective_start_date and ler.effective_end_date
5171     and    ler.typ_cd not in ('IREC', 'SCHEDDU', 'COMP', 'GSP', 'ABS')
5172     and    pil.per_in_ler_stat_cd not in('BCKDT', 'VOIDD')
5173     order by pil.lf_evt_ocrd_dt desc;
5174 
5175     l_prev_pil_id number;
5176 
5177    cursor c_get_prior_per_in_ler(c_cvg_strt_dt date) is
5178    select 'Y'
5179    from   ben_elig_per_elctbl_chc epe, ben_per_in_ler pil,
5180           ben_per_in_ler pil2
5181    where  epe.elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id
5182    and    pil.per_in_ler_id <> epe.per_in_ler_id
5183    /* Bug 8945818: Added 'or' condition. Check for future coverage for the previous life event */
5184    and    ( (trunc(pil.lf_evt_ocrd_dt, 'MM') = trunc(pil2.lf_evt_ocrd_dt, 'MM')) or
5185           ('Y' = (select 'Y' from  ben_elig_per_elctbl_chc epe1,
5186                                   ben_elig_per_elctbl_chc epe2,
5187                                   ben_prtt_enrt_rslt_f pen
5188                  where epe1.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5189                        and epe1.per_in_ler_id <> epe2.per_in_ler_id
5190                        and epe2.per_in_ler_id = l_prev_pil_id
5191                        and epe1.ptip_id = epe2.ptip_id
5192                        and epe2.prtt_enrt_rslt_id is not null
5193                        and epe2.per_in_ler_id = pen.per_in_ler_id
5194 		       and pen.person_id = pil.person_id
5195                        and epe2.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
5196                        and c_cvg_strt_dt <= pen.enrt_cvg_strt_dt
5197 		       and rownum = 1) )
5198           )
5199    and    pil2.per_in_ler_id = epe.per_in_ler_id
5200    and    pil.person_id = pil2.person_id -- Bug 8871911: Performance Bug
5201    and    pil.business_group_id = pil2.business_group_id
5202    and    pil.business_group_id = p_business_group_id
5203    and    pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
5204 
5205    --
5206    l_exists varchar2(2);
5207    --
5208      --------------------------------------------------------------------------
5209    --Bug 13444556  changes start
5210    -- While adjusting the coverage for overlapping coverage,the above cursor c_get_prior_per_in_ler checks
5211    -- for the coverage that are starting the future.the below cursor c_get_prior_per_in_ler_1 checks
5212    -- for any coverage that are end dating in the future
5213    cursor c_get_prior_per_in_ler_1(c_cvg_strt_dt date) is
5214    select 'Y'
5215    from   ben_elig_per_elctbl_chc epe, ben_per_in_ler pil,
5216           ben_per_in_ler pil2
5217    where  epe.elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id
5218    and    pil.per_in_ler_id <> epe.per_in_ler_id
5219    /* Bug 8945818: Added 'or' condition. Check for future coverage for the previous life event */
5220    and    ( (trunc(pil.lf_evt_ocrd_dt, 'MM') = trunc(pil2.lf_evt_ocrd_dt, 'MM')) or
5221           ('Y' = (select 'Y' from  ben_elig_per_elctbl_chc epe1,
5222                                   ben_elig_per_elctbl_chc epe2,
5223                                   ben_prtt_enrt_rslt_f pen
5224                  where epe1.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5225                        and epe1.per_in_ler_id <> epe2.per_in_ler_id
5226                        and epe2.per_in_ler_id = l_prev_pil_id
5227                        and epe1.ptip_id = epe2.ptip_id
5228                        and epe2.prtt_enrt_rslt_id is not null
5229                        and epe2.per_in_ler_id = pen.per_in_ler_id
5230 		       and pen.person_id = pil.person_id
5231                        and epe2.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
5232                      --  and c_cvg_strt_dt <= pen.enrt_cvg_strt_dt
5233                   --ud changes start
5234                      and  (pen.enrt_cvg_strt_dt <= pen.enrt_cvg_thru_dt and c_cvg_strt_dt <= pen.enrt_cvg_thru_dt)
5235 
5236                   --ud changes end
5237 		       and rownum = 1) )
5238           )
5239    and    pil2.per_in_ler_id = epe.per_in_ler_id
5240    and    pil.person_id = pil2.person_id -- Bug 8871911: Performance Bug
5241    and    pil.business_group_id = pil2.business_group_id
5242    and    pil.business_group_id = p_business_group_id
5243    and    pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT');
5244 
5245    --
5246    l_exists_1 varchar2(2);
5247    --Bug 13444556 changes end
5248 --------------------------------------------------------------------------------
5249 
5250   cursor c_get_pgm is
5251   select distinct epe.pgm_id
5252   from ben_elig_per_elctbl_chc epe
5253   where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
5254   --
5255   cursor c_get_pgm_extra_info_cvg(p_pgm_id number) is
5256   select pgi_information1
5257   from ben_pgm_extra_info
5258   where information_type = 'ADJ_CVG_PREV_LF_EVT'
5259   and pgm_id = p_pgm_id;
5260   --
5261   l_cvg_adjust varchar2(2);
5262   --
5263   cursor c_get_elctbl_chc_for_cvg is
5264    select min(epe.enrt_cvg_strt_dt) enrt_cvg_strt_dt
5265          ,epe.ptip_id
5266    from ben_elig_per_elctbl_chc  epe
5267    where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5268    and   epe.business_group_id = p_business_group_id
5269    group by epe.ptip_id;
5270 
5271    /*Bug 8507247: The ended coverage should not be adjusted based on min(enrt_cvg_strt_dt) on the
5272    choice since the enrt_cvg_strt_dt is recalculated in election_information for NON FONM plans
5273    (Ex:First of Pay Period after Effective Date) before creating the new enrollment and is not updated to the choice.
5274    Since we already know of the new cvg_strt_dt from which we are going to create the new enrollment the same can be used to
5275    adjust the ended coverage. This will prevent any coverage gaps.*/
5276    cursor c_get_ptip_id is
5277       select epe.ptip_id
5278    from ben_elig_per_elctbl_chc  epe
5279    where epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5280    and   epe.business_group_id = p_business_group_id;
5281 
5282    l_ptip_id number;
5283    /*End Bug 8507247*/
5284    --
5285    cursor c_get_enrt_rslts_for_pen(p_cvg_end_dt date
5286                          ,p_ptip_id   number
5287                           ) is
5288    select pen.*, epe.per_in_ler_id pil_id
5289    from ben_prtt_enrt_rslt_f pen
5290        ,ben_ptip_f ptip
5291        ,ben_per_in_ler pil
5292        ,ben_elig_per_elctbl_chc epe
5293    where pen.effective_end_date = hr_api.g_eot -- '31-dec-4712'
5294    and   pen.enrt_cvg_thru_dt <> hr_api.g_eot -- '31-dec-4712'
5295    and   pen.prtt_enrt_rslt_stat_cd is null
5296    and   pen.person_id =  pil.person_id -- 318321
5297    and   pen.business_group_id = p_business_group_id -- 81545
5298    and   pen.ptip_id = p_ptip_id -- 54444
5299    and   pen.enrt_cvg_thru_dt >=  p_cvg_end_dt -- '20-jan-2008'
5300    and   pen.ptip_id = ptip.ptip_id
5301    and   pil.per_in_ler_id = epe.per_in_ler_id
5302    and   epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
5303    and   p_effective_date between ptip.effective_start_date
5304                   and ptip.effective_end_date;
5305    --
5306    cursor c_prtt_enrt_rslt_adj (p_prtt_enrt_rslt_id number) is
5307    select null
5308    from  ben_le_clsn_n_rstr leclr, ben_elig_per_elctbl_chc epe
5309    where leclr.BKUP_TBL_TYP_CD = 'BEN_PRTT_ENRT_RSLT_F_ADJ'
5310    AND   leclr.BKUP_TBL_ID = p_prtt_enrt_rslt_id
5311    AND   leclr.PER_IN_LER_ID  = epe.per_in_ler_id
5312    AND   epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
5313    --
5314    -- end 7206471
5315   --  ------------------------------------------------------------
5316   ---------Bug 9139820
5317    cursor c_get_pil_enrt(p_pen_id number,p_per_in_ler_id number,
5318                                p_cvg_strt_dt date) is
5319   SELECT *
5320   FROM ben_prtt_enrt_rslt_f pen
5321  WHERE pen.per_in_ler_id = p_per_in_ler_id
5322    AND pen.business_group_id = p_business_group_id
5323    and pen.prtt_enrt_rslt_id = p_pen_id
5324    AND pen.enrt_cvg_strt_dt =  p_cvg_strt_dt
5325    and pen.sspndd_flag <> 'Y'
5326    and not EXISTS(SELECT NULL
5327                     FROM ben_prtt_enrt_rslt_f pen2
5328                    WHERE pen2.per_in_ler_id = pen.per_in_ler_id
5329                      AND pen2.rplcs_sspndd_rslt_id = pen.prtt_enrt_rslt_id
5330                      AND pen2.sspndd_flag = 'Y'
5331 		     AND pen2.prtt_enrt_rslt_stat_cd IS NULL
5332                      AND pen2.business_group_id = pen.business_group_id)
5333    AND pen.prtt_enrt_rslt_stat_cd IS NULL
5334    order by pen.effective_start_date desc;
5335 
5336   l_get_prev_pil_enrt  c_get_pil_enrt%rowtype;
5337   l_check_enrt_same_pil  c_get_pil_enrt%rowtype;
5338   cursor c_bkup_pen_rec(p_pen_id number,p_pil_id number,p_person_id number,p_esd date,p_csd date) is
5339   SELECT bkup.*
5340   FROM ben_le_clsn_n_rstr bkup
5341  WHERE bkup.bkup_tbl_id = p_pen_id
5342    AND bkup_tbl_typ_cd = 'BEN_PRTT_ENRT_RSLT_F_CORR'
5343    AND bkup.per_in_ler_id = p_pil_id
5344    AND bkup.person_id = p_person_id
5345    AND bkup.business_group_id = p_business_group_id
5346    AND bkup.effective_start_date = p_esd
5347    AND bkup.enrt_cvg_strt_dt = p_csd
5348    AND bkup.effective_end_date = hr_api.g_eot
5349    AND bkup.enrt_cvg_thru_dt = hr_api.g_eot;
5350 
5351   l_bkup_pen_rec   c_bkup_pen_rec%rowtype;
5352   l_pil_id         number;
5353 
5354   cursor c_get_ovn(p_pen_id number,p_pil_id number,p_esd date) is
5355   select max(pen.object_version_number)
5356     from ben_prtt_enrt_rslt_f pen
5357    where pen.prtt_enrt_rslt_id = p_pen_id
5358      and pen.per_in_ler_id = p_pil_id
5359      and pen.business_group_id = p_business_group_id
5360      and pen.effective_start_date = p_esd
5361   order by pen.effective_start_date desc,pen.object_version_number desc;
5362   -----Enf of Bug 9139820
5363   ----Bug 8596122
5364   cursor c_prev_pil(p_person_id number) is
5365   SELECT pil.per_in_ler_id
5366   FROM ben_per_in_ler pil
5367  WHERE pil.business_group_id = p_business_group_id
5368    AND pil.person_id = p_person_id
5369    AND pil.per_in_ler_stat_cd = 'PROCD'
5370 ORDER BY pil.lf_evt_ocrd_dt DESC ;
5371 
5372   l_prev_pil    c_prev_pil%rowtype;
5373 
5374   ---Bug 9430735
5375   cursor c_prev_pil_with_pen(p_person_id number,p_pen_id number) is
5376   SELECT pil.per_in_ler_id
5377   FROM ben_per_in_ler pil
5378  WHERE pil.business_group_id = p_business_group_id
5379    AND pil.person_id = p_person_id
5380    AND pil.per_in_ler_stat_cd = 'PROCD'
5381    and exists(select null
5382                 from ben_prtt_enrt_rslt_f pen
5383 	       where pen.per_in_ler_id = pil.per_in_ler_id
5384 	         and pen.prtt_enrt_rslt_stat_cd is null
5385 		 and pen.prtt_enrt_rslt_id = p_pen_id)
5386 ORDER BY pil.lf_evt_ocrd_dt DESC ;
5387 
5388   ---Bug 9430735
5389 
5390   cursor c_check_int_enr(p_pil_id number,p_pgm_id number,p_pl_id number,p_oipl_id number) is
5391   SELECT *
5392   FROM ben_prtt_enrt_rslt_f pen
5393  WHERE pen.per_in_ler_id = p_pil_id
5394    AND nvl(pen.pgm_id,-1) = nvl(p_pgm_id,-1)
5395    AND pen.pl_id = p_pl_id
5396    AND Nvl(pen.oipl_id ,-1) = nvl(p_oipl_id,-1)
5397    AND pen.business_group_id = p_business_group_id
5398    and pen.enrt_cvg_thru_dt = hr_api.g_eot
5399    AND pen.prtt_enrt_rslt_stat_cd IS NULL
5400    AND EXISTS(SELECT NULL
5401                     FROM ben_prtt_enrt_rslt_f pen2
5402                    WHERE pen2.per_in_ler_id = pen.per_in_ler_id
5403                      AND pen2.rplcs_sspndd_rslt_id = pen.prtt_enrt_rslt_id
5404                      AND pen2.sspndd_flag = 'Y'
5405 		     AND pen2.prtt_enrt_rslt_stat_cd IS NULL
5406 		     and pen2.enrt_cvg_thru_dt = hr_api.g_eot
5407                      AND pen2.business_group_id = pen.business_group_id);
5408  l_check_int_enr   c_check_int_enr%rowtype;
5409 
5410  l_yenrt_cvg_strt_dt_cd     varchar2(30);
5411   l_yenrt_cvg_strt_dt_rl     number;
5412   l_yrt_strt_dt              date;
5413   l_yrt_strt_dt_cd           varchar2(30);
5414   l_yrt_strt_dt_rl           number;
5415   l_yenrt_cvg_end_dt         date;
5416   l_yenrt_cvg_end_dt_cd      varchar2(30);
5417   l_yenrt_cvg_end_dt_rl      number;
5418   l_yrt_end_dt               date;
5419   l_yrt_end_dt_cd            varchar2(10);
5420   l_yrt_end_dt_rl            number;
5421   l_interim_exists           boolean; -- 12421421
5422 
5423 BEGIN
5424     g_debug := hr_utility.debug_enabled;
5425     if g_debug then
5426       hr_utility.set_location('Entering:'||l_proc, 5);
5427     end if;
5428     if g_debug then
5429       hr_utility.set_location(' chc:'|| to_char(p_elig_per_elctbl_chc_id)||' rslt:'|| to_char(p_prtt_enrt_rslt_id), 5);
5430     end if;
5431     if g_debug then
5432       hr_utility.set_location('p_enrt_rt_id1'||p_enrt_rt_id1,1999);
5433     end if;
5434 
5435   --
5436   -- Work out if we are being called from a concurrent program
5437   -- otherwise we need to initialize the environment
5438   --
5439   if fnd_global.conc_request_id = -1 then
5440     --
5441     ben_env_object.init(p_business_group_id  => p_business_group_id,
5442                         p_effective_date     => p_effective_date,
5443                         p_thread_id          => 1,
5444                         p_chunk_size         => 1,
5445                         p_threads            => 1,
5446                         p_max_errors         => 1,
5447                         p_benefit_action_id  => null);
5448     --
5449   end if;
5450   --
5451   --
5452   -- Issue a savepoint depending on where we are called from.  We
5453   -- must do this because election_information calls create_enrollment
5454   -- which calls Determine_other_action_items which calls Suspend_enrollment
5455   -- Which might create an interim result by calling election_information.
5456   -- When it does, it would reset this save point.
5457   --
5458   -- This flag is also passed to create_enrollment
5459   --
5460   if p_called_from_sspnd = 'N' then
5461      savepoint election_information_savepoint;
5462   else
5463      savepoint election_information_sspnd;
5464   end if;
5465 
5466   --
5467   -- For the case where this is creating an interim enrollment
5468   -- and the interim choice is the same as the original then
5469   -- we should create a new result.
5470   --
5471   if p_called_from_sspnd = 'Y' then
5472     if g_elig_per_elctbl_chc_id=p_elig_per_elctbl_chc_id then
5473       if g_debug then
5474         hr_utility.set_location(' l_use_new_result:=true ',1223);
5475       end if;
5476       l_use_new_result:=true;
5477     end if;
5478   end if;
5479   --
5480   -- set globals to be used by bensuenr, suspend enrollment
5481   --
5482   g_enrt_bnft_id:=p_enrt_bnft_id;
5483   g_bnft_val:=p_bnft_val;
5484   g_elig_per_elctbl_chc_id:=p_elig_per_elctbl_chc_id;
5485   --
5486   -- begin by getting the choice, bnft, per in ler and pil popl information
5487   --
5488   ben_global_enrt.get_epe  -- choice
5489        (p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
5490        ,p_global_epe_rec         => l_global_epe_rec);
5491 
5492   ben_global_enrt.get_pel  -- pil popl
5493        (p_pil_elctbl_chc_popl_id => l_global_epe_rec.pil_elctbl_chc_popl_id
5494        ,p_global_pel_rec         => l_global_pel_rec);
5495 
5496   ben_global_enrt.get_pil  -- per in ler
5497        (p_per_in_ler_id          => l_global_epe_rec.per_in_ler_id
5498        ,p_global_pil_rec         => l_global_pil_rec);
5499 
5500 --Bug#5099296
5501   if l_global_epe_rec.prtt_enrt_rslt_id is not null then
5502     ben_global_enrt.get_pen
5503        (p_prtt_enrt_rslt_id      => l_global_epe_rec.prtt_enrt_rslt_id
5504        ,p_effective_date         => p_effective_date
5505        ,p_global_pen_rec         => l_global_pen_rec);
5506   end if;
5507 --Bug#5099296
5508 
5509   if p_enrt_bnft_id is not null then
5510      ben_global_enrt.get_enb   -- enrt bnft
5511        (p_enrt_bnft_id           => p_enrt_bnft_id
5512        ,p_global_enb_rec         => l_global_enb_rec);
5513   else
5514      ben_global_enrt.clear_enb
5515        (p_global_enb_rec         => l_global_enb_rec);
5516   end if;
5517 
5518   if l_global_epe_rec.oipl_id is not null and p_enrt_bnft_id is null then
5519         open oipl_ordr_num_c(p_oipl_id => l_global_epe_rec.oipl_id);
5520         fetch oipl_ordr_num_c into l_global_enb_rec.ordr_num;
5521         close oipl_ordr_num_c;
5522   end if;
5523 
5524   if g_debug then
5525     hr_utility.set_location(l_proc, 15);
5526   end if;
5527 
5528 
5529   --- determine FONM for election information  # 4510798
5530 
5531   open c_epe ;
5532   fetch c_epe into l_assignment_id ,
5533                     l_fonm_cvg_strt_dt;
5534   close c_epe ;
5535 
5536   if l_fonm_cvg_strt_dt is not null then
5537      l_fonm_flag :=  'Y'  ;
5538      ben_manage_life_events.fonm := 'Y';
5539      ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
5540      /* 8716870: Code added for Imp Inc Enh begins*/
5541      if p_imp_cvg_strt_dt is not NULL and p_imp_cvg_strt_dt > l_fonm_cvg_strt_dt then
5542         hr_utility.set_location('p_imp_cvg_strt_dt '||p_imp_cvg_strt_dt,20);
5543         ben_manage_life_events.g_fonm_cvg_strt_dt := p_imp_cvg_strt_dt;
5544         l_global_epe_rec.enrt_cvg_strt_dt := p_imp_cvg_strt_dt;
5545      end if;
5546      /* Code added for Imp Inc Enh ends*/
5547 
5548   else
5549       l_fonm_flag :=  'N'  ;
5550       ben_manage_life_events.fonm := 'N';
5551       ben_manage_life_events.g_fonm_cvg_strt_dt := null ;
5552   end if ;
5553   hr_utility.set_location (' FONM ' ||  ben_manage_life_events.fonm , 99 ) ;
5554   hr_utility.set_location (' FONM CVG  ' ||  ben_manage_life_events.g_fonm_cvg_strt_dt , 99 ) ;
5555 
5556   --
5557   -- If form code is too lazy to pass in the result id
5558   -- then get it from the choice.  Note will be null if
5559   -- the choice has not previously been enrolled in.
5560   --
5561   -- Assign only if result id is null - Bug#5369
5562   -- Bug 2547005 and 2543071 This needs to checked first. In Enter value at enrollment case
5563   -- with benefit restriction we get the right penid here.
5564   -- We may have two benefit rows one having the penid and other not. If
5565   -- we are using the one without penid we can not use the penid from epe
5566   -- which is not right.
5567   --
5568   if g_debug then
5569     hr_utility.set_location('p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id ,9999);
5570   end if;
5571   if g_debug then
5572     hr_utility.set_location('l_global_epe_rec.p_e_r_id '||l_global_epe_rec.prtt_enrt_rslt_id,9999);
5573   end if;
5574   if g_debug then
5575     hr_utility.set_location('p_enrt_bnft_id '||p_enrt_bnft_id,9999);
5576   end if;
5577   --
5578   if p_enrt_bnft_id is not null then
5579     open  c_enb_pen ;
5580     fetch c_enb_pen into l_enb_prtt_enrt_rslt_id;
5581     close c_enb_pen ;
5582   end if;
5583   --
5584   if p_enrt_bnft_id is not null and p_prtt_enrt_rslt_id is null then
5585     --
5586     p_prtt_enrt_rslt_id := l_enb_prtt_enrt_rslt_id ;
5587     --
5588   elsif l_global_epe_rec.prtt_enrt_rslt_id is not null and p_prtt_enrt_rslt_id is null then
5589     --
5590     -- Bug 5600697 - In cases like FONM, if we delete enrollment for a subsequent life event, then
5591     --               EPE would still hold the PEN_ID but with BCKDT status. So if we again decide
5592     --               to enrol then 91711 error would occur while querying cursor C_CURRENT_RESULT_INFO
5593     --               I believe we should set P_PRTT_ENRT_RSLT_ID only if PRTT_ENRT_RSLT_STAT_CD is NULL
5594     --
5595     open c_is_pen_valid(l_global_epe_rec.prtt_enrt_rslt_id);
5596       --
5597       fetch c_is_pen_valid into l_pen_stat_cd;
5598       --
5599       if c_is_pen_valid%found and l_pen_stat_cd is null
5600       then
5601         --
5602         p_prtt_enrt_rslt_id := l_global_epe_rec.prtt_enrt_rslt_id;
5603         --
5604       end if;
5605       --
5606     close c_is_pen_valid;
5607     --
5608     --
5609   end if;
5610   --
5611   if l_enb_prtt_enrt_rslt_id IS NOT NULL and l_global_epe_rec.prtt_enrt_rslt_id <> l_enb_prtt_enrt_rslt_id THEN
5612     --
5613     l_global_epe_rec.prtt_enrt_rslt_id := l_enb_prtt_enrt_rslt_id  ;
5614     --
5615   end if;
5616   --
5617   hr_utility.set_location('l_enb_prtt_enrt_rslt_id'||l_enb_prtt_enrt_rslt_id,222);
5618   hr_utility.set_location('l_global_epe_rec.prtt_enrt_rslt_id'||l_global_epe_rec.prtt_enrt_rslt_id,222);
5619   --
5620   -- bug 12421421.  Reinstate the current enrollment.  Suspended enrollment
5621   -- is deleted and the interim is the current enrollment.
5622   --
5623   hr_utility.set_location('l_global_epe_rec.crntly_enrd_flag : '||l_global_epe_rec.crntly_enrd_flag,99.1);
5624   if (l_global_epe_rec.crntly_enrd_flag = 'Y' and
5625       p_prtt_enrt_rslt_id <> nvl(l_global_epe_rec.prtt_enrt_rslt_id,-1)) then
5626     l_interim_exists := false;
5627     if l_global_epe_rec.prtt_enrt_rslt_id is not null then
5628       --
5629       --  Check if enrollment is previously an  interim.
5630       --
5631       open c_get_interim(p_prtt_enrt_rslt_id
5632                         ,l_global_epe_rec.per_in_ler_id
5633                         ,p_effective_date
5634                         ,l_global_epe_rec.prtt_enrt_rslt_id
5635                         );
5636       fetch c_get_interim into l_interim;
5637       if c_get_interim%found then
5638         hr_utility.set_location('interim found: '||l_global_epe_rec.prtt_enrt_rslt_id,1);
5639         l_interim_exists := true;
5640       else
5641         hr_utility.set_location('interim not found: '||l_global_epe_rec.prtt_enrt_rslt_id,1);
5642       end if;
5643       close c_get_interim;
5644     end if;
5645     --
5646     if (l_global_epe_rec.prtt_enrt_rslt_id is null or
5647         l_interim_exists ) then
5648       hr_utility.set_location('try to find the prior enrolment : '||p_prtt_enrt_rslt_id,99.1);
5649       --
5650       open c_get_ended_result(p_elig_per_elctbl_chc_id
5651                              ,l_global_epe_rec.per_in_ler_id
5652                              );
5653       fetch c_get_ended_result into l_ended_pen;
5654       if c_get_ended_result%found then
5655         l_global_epe_rec.prtt_enrt_rslt_id := l_ended_pen.prtt_enrt_rslt_id;
5656         hr_utility.set_location('found : '||l_ended_pen.prtt_enrt_rslt_id,99.1);
5657         --
5658         --  Update the electable choice with the enrollment result id.
5659         --
5660         ben_ELIG_PER_ELC_CHC_api.update_ELIG_PER_ELC_CHC
5661           (p_validate               => FALSE
5662           ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
5663           ,p_prtt_enrt_rslt_id      => l_ended_pen.prtt_enrt_rslt_id
5664           ,p_object_version_number  => l_global_epe_rec.object_version_number
5665           ,p_effective_date         => p_effective_date
5666           ,p_request_id             => fnd_global.conc_request_id
5667           ,p_program_application_id => fnd_global.prog_appl_id
5668           ,p_program_id             => fnd_global.conc_program_id
5669           ,p_program_update_date    => sysdate
5670           );
5671         --
5672         -- reload enrollment data
5673         --
5674         ben_global_enrt.get_pen  -- result
5675          (p_prtt_enrt_rslt_id      => l_global_epe_rec.prtt_enrt_rslt_id
5676          ,p_effective_date         => p_effective_date
5677          ,p_global_pen_rec         => l_global_pen_rec);
5678         --
5679       end if;
5680       close c_get_ended_result;
5681     end if;
5682   end if;  -- crntly enrld
5683   --
5684   --  end 12421421
5685   --
5686   l_prtt_enrt_rslt_id := l_global_epe_rec.prtt_enrt_rslt_id;
5687   if g_debug then
5688     hr_utility.set_location(l_proc, 16);
5689   end if;
5690   --
5691   -- override the bnft_val if it's annualized and entered at enrt
5692   --
5693   -- Bug 1913254 Present logic works only for enter value at enrollment is
5694   -- checked for rate. Now added a new cursor to get the annual value for
5695   -- SAAEAR if the rate is not entered at enrollment.
5696   --
5697   --hr_utility. set_location(' cvg_mlt_cd Code '||l_global_enb_rec.cvg_mlt_cd , 17);
5698   --hr_utility. set_location(' p_ann_rt_val1 '||p_ann_rt_val1 ,18);
5699   --hr_utility. set_location(' p_bnft_val '||p_bnft_val ,19);
5700   --hr_utility. set_location(' p_enrt_rt_id1 '||p_enrt_rt_id1 ,19);
5701   --hr_utility. set_location(' p_enrt_bnft_id '||p_enrt_bnft_id , 20);
5702   --
5703   -- Bug 2212194 fixes
5704   --
5705   if l_global_enb_rec.cvg_mlt_cd='SAAEAR' then
5706     --
5707     open c_ert ;
5708     fetch c_ert into l_ert ; --l_ann_enrt_rt ;
5709     if c_ert%found then
5710       --
5711       if l_ert.ENTR_VAL_AT_ENRT_FLAG = 'Y' then
5712         --
5713 	-- changed for bug: 5584813
5714 	  if l_ert.entr_ann_val_flag = 'Y' then
5715 		l_global_enb_rec.val:= p_ann_rt_val1;
5716           else
5717 	        l_dummy_rt_val := p_rt_val1;
5718 		calc_rt_ann_rt_vals (
5719 		   p_rt_val                  => l_dummy_rt_val,
5720 		   p_ann_rt_val              => l_global_enb_rec.val,
5721 		   p_person_id               => l_global_pil_rec.person_id,
5722 		   p_effective_date          => p_effective_date,
5723 		   p_acty_base_rt_id         => l_ert.acty_base_rt_id,
5724 		   p_rate_periodization_rl   => l_ert.rate_periodization_rl,
5725 		   p_elig_per_elctbl_chc_id  => l_ert.elig_per_elctbl_chc_id,
5726 		   p_business_group_id       => p_business_group_id,
5727 		   p_enrt_rt_id              => p_enrt_rt_id1,
5728 		   p_entr_ann_val_flag       => NULL,
5729 		   p_entr_val_at_enrt_flag   => l_ert.entr_val_at_enrt_flag);
5730           end if;
5731 
5732 	-- l_global_enb_rec.val:=p_ann_rt_val1;
5733         --
5734       else
5735         --
5736         l_global_enb_rec.val:= l_ert.ann_val ; -- l_ann_enrt_rt ;
5737 
5738         --
5739       end if;
5740       --
5741     /*
5742     open c_ert ;
5743     fetch c_ert into l_ann_enrt_rt ;
5744     if c_ert%found then
5745       --
5746       l_global_enb_rec.val:= l_ann_enrt_rt ;
5747       --
5748     */
5749     else
5750       --
5751       l_global_enb_rec.val:=p_ann_rt_val1;
5752       --
5753     end if;
5754     close c_ert ;
5755     --
5756   elsif p_bnft_val is not null then
5757     l_global_enb_rec.val := p_bnft_val;
5758   end if;
5759   -- Added for bug 4020061
5760   if p_bnft_val = 0 and p_enrt_bnft_id is null
5761   then
5762       l_global_enb_rec.val := null ;
5763       hr_utility.set_location(' new clause --- l_global_enb_rec.val' || l_global_enb_rec.val , 50);
5764   end if;
5765 
5766   if g_debug then
5767     hr_utility.set_location(l_proc, 50);
5768   end if;
5769   --
5770   -- if changing a result get old info
5771   --
5772   if g_debug then
5773     hr_utility.set_location('prtt_enrt_rslt_id'||p_prtt_enrt_rslt_id ,8086.1);
5774     hr_utility.set_location('new coverage date '||l_global_pil_rec.lf_evt_ocrd_dt ,8086.1);
5775   end if;
5776   if p_prtt_enrt_rslt_id is not null then
5777     if g_debug then
5778       hr_utility.set_location(l_proc,51);
5779     end if;
5780     open c_current_result_info(p_prtt_enrt_rslt_id);
5781     if g_debug then
5782       hr_utility.set_location(l_proc,52);
5783     end if;
5784     fetch c_current_result_info into
5785       l_old_enrt_cvg_strt_dt,
5786       l_old_enrt_cvg_thru_dt,
5787       l_old_bnft_val,
5788       l_old_pl_id,
5789       l_old_oipl_id,
5790       l_old_orgnl_enrt_dt,
5791       l_old_per_in_ler_id,
5792       l_old_ovn,
5793       l_old_erlst_deenrt_dt,
5794       l_old_enrt_ovrid_thru_dt,
5795       l_old_enrt_ovrid_rsn_cd,
5796       l_old_enrt_ovridn_flag,
5797       l_old_sspndd_flag ;
5798     if g_debug then
5799       hr_utility.set_location(l_proc,53);
5800       hr_utility.set_location(l_global_epe_rec.enrt_cvg_strt_dt,53);
5801     end if;
5802     if c_current_result_info%notfound then
5803        -- make sure it is not deleted for fiture coverage
5804           -- null globals to prevent bleeding
5805           --
5806           close c_current_result_info;
5807           --
5808           g_enrt_bnft_id:=null;
5809           g_bnft_val:=null;
5810           g_elig_per_elctbl_chc_id:=null;
5811           --
5812           if g_debug then
5813             hr_utility.set_location('BEN_91711_ENRT_RSLT_NOT_FND'|| to_char(p_prtt_enrt_rslt_id),54);
5814           end if;
5815           fnd_message.set_name('BEN','BEN_91711_ENRT_RSLT_NOT_FND');
5816           fnd_message.set_token('PROC',l_proc);
5817           fnd_message.set_token('ID', to_char(p_prtt_enrt_rslt_id));
5818           fnd_message.set_token('PERSON_ID', to_char(l_global_pil_rec.person_id));
5819           fnd_message.set_token('LER_ID', to_char(l_global_pil_rec.ler_id));
5820           fnd_message.set_token('EFFECTIVE_DATE',to_char(p_effective_date));
5821           fnd_message.raise_error;
5822     else
5823     --
5824     close c_current_result_info;
5825     --
5826     --IF NVL(ben_sspndd_enrollment.g_cfw_flag,'N') = 'N' THEN
5827       --
5828       -- BUG 5985777 This is the case where action items from the past life event
5829       -- are completed in future.
5830       --
5831       open c_pen_curr(p_prtt_enrt_rslt_id
5832                      ,l_global_pil_rec.lf_evt_ocrd_dt
5833                      ,l_global_epe_rec.per_in_ler_id); -- 12583091
5834         fetch c_pen_curr into l_pen_curr;
5835       close c_pen_curr ;
5836       --
5837       IF l_pen_curr.sspndd_flag='Y' AND l_old_sspndd_flag='N' THEN
5838         --
5839         --This is the action item completion in future case.
5840         --
5841         hr_utility.set_location('p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id,500);
5842         ben_prtt_enrt_result_api.delete_prtt_enrt_result
5843               (p_validate                => false,
5844                p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
5845                p_effective_start_date    => l_effective_start_date,
5846                p_effective_end_date      => l_effective_end_date,
5847                p_object_version_number   => l_pen_curr.object_version_number,
5848                p_effective_date          => l_pen_curr.effective_end_date,
5849                p_datetrack_mode          => hr_api.g_future_change,
5850                p_multi_row_validate      => FALSE);
5851         --
5852         for l_rec in c_prv(l_pen_curr.prtt_enrt_rslt_id,l_pen_curr.per_in_ler_id) loop
5853             --
5854             open c_ecr(l_rec.prtt_rt_val_id);
5855               fetch c_ecr into l_ecr;
5856             close c_ecr;
5857             -- if rate start date found.. use it else call bendetdt to compute the date
5858             IF l_ecr.rt_strt_dt IS NOT NULL THEN
5859               null ;
5860             ELSE
5861               --call bendetdt
5862               ben_determine_date.main(
5863                p_date_cd                => l_ecr.rt_strt_dt_cd,
5864                p_per_in_ler_id          => l_pen_curr.per_in_ler_id,  --Previous Per in ler
5865                p_person_id              => l_global_pil_rec.person_id,
5866                p_pgm_id                 => l_global_epe_rec.pgm_id,
5867                p_pl_id                  => l_global_epe_rec.pl_id,
5868                p_oipl_id                => l_global_epe_rec.oipl_id,
5869                p_business_group_id      => p_business_group_id,
5870                p_formula_id             => l_ecr.rt_strt_dt_rl,
5871                p_acty_base_rt_id        => l_rec.acty_base_rt_id,
5872                p_elig_per_elctbl_chc_id => l_ecr.elig_per_elctbl_chc_id,
5873                p_effective_date         => p_effective_date,
5874                p_returned_date          => l_ecr.rt_strt_dt
5875              );
5876               --
5877             END IF;
5878             --
5879             ben_prtt_rt_val_api.update_prtt_rt_val
5880               (p_validate                => false,
5881                p_person_id               => l_global_pil_rec.person_id,
5882                p_business_group_id       => p_business_group_id,
5883                p_prtt_rt_val_id          => l_rec.prtt_rt_val_id,
5884                p_rt_strt_dt              => nvl(l_ecr.rt_strt_dt,l_rec.rt_strt_dt),
5885                p_rt_end_dt               => hr_api.g_eot,
5886                p_object_version_number   => l_rec.object_version_number,
5887                p_effective_date          => p_effective_date );
5888             --
5889         end loop;
5890         --
5891         --Interim Enrollment
5892         --
5893         IF l_pen_curr.rplcs_sspndd_rslt_id is not null THEN
5894              --
5895              hr_utility.set_location(' Extend Interim Row',99);
5896              --
5897              open c_pen_curr(l_pen_curr.rplcs_sspndd_rslt_id
5898                             ,l_global_pil_rec.lf_evt_ocrd_dt
5899                             ,l_global_epe_rec.per_in_ler_id); -- 12583091
5900                 -- 6057157 : Changed the cursor variable to l_pen_curr_interim
5901                fetch c_pen_curr into l_pen_curr_interim;
5902              close c_pen_curr;
5903              --
5904              --
5905              hr_utility.set_location('l_pen_curr.prtt_enrt_rslt_id ' || l_pen_curr_interim.prtt_enrt_rslt_id,99);
5906              --
5907           IF l_pen_curr_interim.prtt_enrt_rslt_id IS NOT NULL THEN
5908                ben_prtt_enrt_result_api.delete_prtt_enrt_result
5909                 (p_validate                => false,
5910                  p_prtt_enrt_rslt_id       => l_pen_curr_interim.prtt_enrt_rslt_id,
5911                  p_effective_start_date    => l_effective_start_date,
5912                  p_effective_end_date      => l_effective_end_date,
5913                  p_object_version_number   => l_pen_curr_interim.object_version_number,
5914                  p_effective_date          => l_pen_curr_interim.effective_end_date,
5915                  p_datetrack_mode          => hr_api.g_future_change,
5916                  p_multi_row_validate      => FALSE);
5917           END IF;
5918           --
5919             -- 6057157 : Reset the Rate End to EOT, as PEN records are done similarly above.
5920             --
5921             for l_rec in c_prv(l_pen_curr_interim.prtt_enrt_rslt_id, l_pen_curr_interim.per_in_ler_id)
5922             loop
5923                 --
5924                 hr_utility.set_location('Interim l_rec.prtt_rt_val_id ' || l_rec.prtt_rt_val_id,99);
5925                 hr_utility.set_location('l_rec.rt_end_dt ' || l_rec.rt_end_dt,99);
5926                 --
5927                 ben_prtt_rt_val_api.update_prtt_rt_val
5928                   (p_validate                => false,
5929                    p_person_id               => l_global_pil_rec.person_id,
5930                    p_business_group_id       => p_business_group_id,
5931                    p_prtt_rt_val_id          => l_rec.prtt_rt_val_id,
5932                    p_rt_end_dt               => hr_api.g_eot,
5933                    p_object_version_number   => l_rec.object_version_number,
5934                    p_effective_date          => p_effective_date );
5935                 --
5936             end loop;
5937           --
5938         END IF ;
5939         --
5940         open c_current_result_info(p_prtt_enrt_rslt_id);
5941         if g_debug then
5942           hr_utility.set_location(l_proc,52.2);
5943         end if;
5944         fetch c_current_result_info into
5945           l_old_enrt_cvg_strt_dt,
5946           l_old_enrt_cvg_thru_dt,
5947           l_old_bnft_val,
5948           l_old_pl_id,
5949           l_old_oipl_id,
5950           l_old_orgnl_enrt_dt,
5951           l_old_per_in_ler_id,
5952           l_old_ovn,
5953           l_old_erlst_deenrt_dt,
5954           l_old_enrt_ovrid_thru_dt,
5955           l_old_enrt_ovrid_rsn_cd,
5956           l_old_enrt_ovridn_flag,
5957           l_old_sspndd_flag ;
5958         close c_current_result_info;
5959         --
5960       END IF;
5961     --END IF;
5962     --
5963     -- begin bug 5621049
5964     /* when u r changing from 'option1 to option2' or 'plan1 to plan2' and 'option1 nd opton2' ,or , 'plan1 nd plan2'
5965     have same benefit amount then we should not compare the bnft amount of option1 nd option2 . for this bug
5966     param p_elig_per_elctbl_chc_id belongs to option2/plan2 and
5967     param p_prtt_enrt_rslt_id belongs to option1/plan1
5968     */
5969      if l_old_bnft_val is not NULL
5970      then
5971          open c_validate_epe_pen(p_elig_per_elctbl_chc_id,p_prtt_enrt_rslt_id);
5972          fetch c_validate_epe_pen into l_dummy_char;
5973             if c_validate_epe_pen%notfound then
5974                l_old_bnft_val := null;
5975              end if ;
5976           close c_validate_epe_pen;
5977       end if ;
5978 
5979       -- end bug 5621049
5980 
5981      end if;
5982 
5983     if g_debug then
5984       hr_utility.set_location(  p_prtt_enrt_rslt_id || ' '|| l_proc,55);
5985     end if;
5986     if l_old_ovn is not null then
5987       if g_debug then
5988         hr_utility.set_location(l_proc,56);
5989       end if;
5990       p_object_version_number:=l_old_ovn;
5991     end if;
5992     if g_debug then
5993       hr_utility.set_location(l_proc,57);
5994     end if;
5995     -- close c_current_result_info;
5996     if g_debug then
5997       hr_utility.set_location(l_proc,58);
5998     end if;
5999   end if;
6000   hr_utility.set_location('l_global_enb_rec.val '||l_global_enb_rec.val,8082.1);
6001   hr_utility.set_location('l_old_bnft_val '||l_old_bnft_val,8082.1);
6002   hr_utility.set_location('l_global_epe_rec.ctfn_rqd_flag '||l_global_epe_rec.ctfn_rqd_flag,8082.1);
6003   hr_utility.set_location('l_old_sspndd_flag '||l_old_sspndd_flag,8082.1);
6004   --
6005   -- Replacing sec 129 logic to start a new enrollment if the enrollment code is CCKCSNCC
6006   -- bendenrr populates the new coverage start date
6007   --
6008    if (  p_prtt_enrt_rslt_id is not null and
6009         l_global_epe_rec.prtt_enrt_rslt_id is not null and
6010         l_global_epe_rec.prtt_enrt_rslt_id=p_prtt_enrt_rslt_id and
6011         (( ben_sspndd_enrollment.g_use_new_result=false and
6012         nvl(l_old_bnft_val,hr_api.g_number)=
6013            nvl(l_global_enb_rec.val,hr_api.g_number)) or
6014          l_old_sspndd_flag = 'Y')) then
6015       if g_debug then
6016         hr_utility.set_location('enrt cvg strt dt'||l_global_epe_rec.enrt_cvg_strt_dt,111);
6017       end if;
6018       --bug#3702090 - override enrollment not to create new result
6019       --bug#4549089 - added per in ler for suspended enrollment
6020       --bug#4555320 - added per in ler for cvg strt dt also
6021       if ( (l_global_epe_rec.enrt_cvg_strt_dt <> l_old_enrt_cvg_strt_dt and
6022             l_old_per_in_ler_id <> l_global_epe_rec.per_in_ler_id)
6023             OR
6024            (l_old_sspndd_flag = 'Y' and l_old_per_in_ler_id <>
6025              l_global_epe_rec.per_in_ler_id))
6026             and nvl(p_enrt_mthd_cd, 'z') <> 'O' then
6027          if g_debug then
6028            hr_utility.set_location('start new result',112);
6029          end if;
6030          l_start_new_result := true;
6031       --
6032       --  Bug 9401100
6033       --  If an enrollment that previously did not require certification and
6034       --  in the current event requires a certification, create a new enrollment
6035       --  result instead of updating the suspended flag on the current  enrollment.
6036       --  The benefit amount did not change.
6037       --
6038       elsif ((l_global_enb_rec.val is not null and
6039               l_global_enb_rec.val = nvl(l_old_bnft_val, hr_api.g_number)) and
6040              l_global_epe_rec.ctfn_rqd_flag = 'Y' and
6041              l_old_sspndd_flag = 'N') then
6042         l_start_new_result := true;
6043         hr_utility.set_location('start new result.',8086.1);
6044       --
6045       --  end 9401100
6046       --
6047 	 /*Bug 9538592: Basing upon the flag set in reinstate enrollments call, set l_start_new_result
6048 	 to true to create a new enrollment result*/
6049       else
6050            if(ben_lf_evt_clps_restore.g_create_new_result = 'Y' ) then
6051               hr_utility.set_location('start new result bcoz of reinstate',112);
6052               l_start_new_result := true;
6053 	      /*Bug 9758763: Reset the flag g_create_new_result in benleclr.pkb. Flag
6054 	        will be reseted after the result is reinstated*/
6055 	      --ben_lf_evt_clps_restore.g_create_new_result := 'N';
6056            end if;
6057       end if;
6058    end if;
6059 
6060   -- if currently enrolled do an update, else create a new result.
6061   -- If the particpant is staying in the same plan and option, i.e.
6062   -- (ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = Y) do not
6063   -- write a new row.  Do update the  PRTT ENRT RSLT: ENRT MTHD CD
6064   -- to ENRT MTHD CD parameter (Currently, Explicit if updating from
6065   -- form or  Default if updatingfrom the default process).
6066   --
6067   -- If benefit amount changed treat as comp object change
6068   --
6069     if g_debug then
6070       hr_utility.set_location('l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
6071     end if;
6072     if g_debug then
6073       hr_utility.set_location('l_old_enrt_cvg_strt_dt'||l_old_enrt_cvg_strt_dt,8086.1);
6074     end if;
6075     if g_debug then
6076       hr_utility.set_location('l_global_epe_rec.erslt_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,8086.1);
6077     end if;
6078     if g_debug then
6079       hr_utility.set_location('l_old_erlst_deenrt_dt '||l_old_erlst_deenrt_dt,8086.1);
6080     end if;
6081   if g_debug then
6082     hr_utility.set_location('l_old_bnft_val='||l_old_bnft_val,1963);
6083   end if;
6084   if g_debug then
6085     hr_utility.set_location('l_bnft_val='||l_global_enb_rec.val,1963);
6086   end if;
6087   --
6088   -- Added condition p_enrt_cvg_thru_dt is null. (maagrawa Jan 05,2001)
6089   -- p_enrt_cvg_thru_dt will be null in normal cases, but it will be populated
6090   -- when called from individual comp. api's when it is allowed to be enterable
6091   -- In such cases, we need to call delete_enrollment, to update the result
6092   -- with the new cvg_thru_dt.
6093   --
6094   if (  p_prtt_enrt_rslt_id is not null and
6095         l_global_epe_rec.prtt_enrt_rslt_id is not null and
6096         l_global_epe_rec.prtt_enrt_rslt_id=p_prtt_enrt_rslt_id and
6097         -- l_use_new_result=false and
6098         ben_sspndd_enrollment.g_use_new_result=false and /*ENH*/
6099         nvl(l_old_bnft_val,hr_api.g_number)= nvl(l_global_enb_rec.val,hr_api.g_number) and
6100         p_enrt_cvg_thru_dt is null  and
6101         l_start_new_result  = false ) then
6102     if g_debug then
6103       hr_utility.set_location(l_proc, 80);
6104     end if;
6105     --
6106     l_prtt_enrt_rslt_id:=p_prtt_enrt_rslt_id;
6107     --
6108     -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
6109     -- see if plan has regulation of IRC Section 125 or 129.
6110     --
6111 
6112     if g_debug then
6113       hr_utility.set_location('if part ' , 8086.1);
6114     end if;
6115 
6116     l_regn_125_or_129_flag:='N';
6117    /*
6118     if l_global_pel_rec.enrt_perd_id is not null and -- same as p_run_mode='C'
6119        l_old_enrt_cvg_strt_dt is not null then
6120       open c_regn_125_or_129;
6121       fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
6122       hr_utility. set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
6123       close c_regn_125_or_129;
6124     end if;
6125     */
6126     if l_regn_125_or_129_flag='N' then
6127       l_global_epe_rec.enrt_cvg_strt_dt:=l_old_enrt_cvg_strt_dt;
6128       l_global_epe_rec.erlst_deenrt_dt :=nvl(l_old_erlst_deenrt_dt,
6129                                              l_global_epe_rec.erlst_deenrt_dt);
6130     end if;
6131     --
6132     if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
6133        p_enrt_cvg_strt_dt is not null then
6134       l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
6135     end if;
6136 
6137     --
6138     --Bug 2600087
6139     open c_enrt_rslt;
6140     fetch c_enrt_rslt into l_enrt_rslt;
6141     if c_enrt_rslt%found then
6142        if g_debug then
6143          hr_utility.set_location('Effectve date'||l_enrt_rslt.effective_end_date,11);
6144        end if;
6145        if g_debug then
6146          hr_utility.set_location('object number '||l_enrt_rslt.object_version_number,11);
6147        end if;
6148        -- 3733745
6149        select count(*)
6150        into   l_interim_count
6151        from   ben_prtt_enrt_rslt_f pen
6152        where  pen.rplcs_sspndd_rslt_id = p_prtt_enrt_rslt_id
6153        and    nvl(pen.sspndd_flag , 'N') = 'Y'
6154        and    p_effective_date
6155              between pen.effective_start_date and pen.effective_end_date;
6156        if l_interim_count = 0 then
6157        -- end 3733745
6158        /* bug 5555269
6159        commented the 5032364 fix as well 5572484. This code became redundant after
6160        introduction of ben_reopen_ended_results.reopen_routine in benmngle
6161        package.
6162        */
6163        /*
6164        --bug#5032364
6165              open c_enrt_rslt2;
6166              fetch c_enrt_rslt2 into l_enrt_rslt2;
6167              close c_enrt_rslt2;
6168              --
6169              -- Bug 5572484 : Take backup in BEN_LE_CLSN_N_RSTR only if the correction
6170              --               is due to a new life event. E.g. If you de-enrol in a life
6171              --               event and again enrol in the same life event, then we need
6172              --               not take backup of the de-enrolled PEN
6173              --
6174              */
6175 
6176 	     /* added for Bug 12576710: Before deleting the future coverage,backup the record
6177 	     before deletion */
6178 
6179 	     open c_enrt_rslt2;
6180              fetch c_enrt_rslt2 into l_enrt_rslt2;
6181              close c_enrt_rslt2;
6182 
6183              hr_utility.set_location('l_enrt_rslt.per_in_ler_id '||l_enrt_rslt.per_in_ler_id,11);
6184              hr_utility.set_location('l_global_epe_rec.per_in_ler_id '||l_global_epe_rec.per_in_ler_id,11);
6185 
6186              /* Bug 14803995 : Do not insert future coverage records in backup table if the Life event is Unrestricted */
6187 	     open c_unrest(l_global_epe_rec.per_in_ler_id);
6188 	     fetch c_unrest into l_typ_cd;
6189 	     close c_unrest;
6190 	     hr_utility.set_location('l_typ_cd '||l_typ_cd,11);
6191 
6192 
6193              if l_typ_cd <> 'SCHEDDU' then
6194 		     if nvl(l_enrt_rslt2.per_in_ler_id, -999) <> l_global_epe_rec.per_in_ler_id
6195 		     then
6196 		       --
6197 		       open c_bkp_enrt_rslt_exist;
6198 		       fetch c_bkp_enrt_rslt_exist into l_bkp_enrt;
6199 		       if(c_bkp_enrt_rslt_exist%found) then
6200 			  hr_utility.set_location('inserting into backup table',11);
6201 				       insert into BEN_LE_CLSN_N_RSTR (
6202 					     BKUP_TBL_TYP_CD,
6203 					     COMP_LVL_CD,
6204 					     LCR_ATTRIBUTE16,
6205 					     LCR_ATTRIBUTE17,
6206 					     LCR_ATTRIBUTE18,
6207 					     LCR_ATTRIBUTE19,
6208 					     LCR_ATTRIBUTE20,
6209 					     LCR_ATTRIBUTE21,
6210 					     LCR_ATTRIBUTE22,
6211 					     LCR_ATTRIBUTE23,
6212 					     LCR_ATTRIBUTE24,
6213 					     LCR_ATTRIBUTE25,
6214 					     LCR_ATTRIBUTE26,
6215 					     LCR_ATTRIBUTE27,
6216 					     LCR_ATTRIBUTE28,
6217 					     LCR_ATTRIBUTE29,
6218 					     LCR_ATTRIBUTE30,
6219 					     LAST_UPDATE_DATE,
6220 					     LAST_UPDATED_BY,
6221 					     LAST_UPDATE_LOGIN,
6222 					     CREATED_BY,
6223 					     CREATION_DATE,
6224 					     REQUEST_ID,
6225 					     PROGRAM_APPLICATION_ID,
6226 					     PROGRAM_ID,
6227 					     PROGRAM_UPDATE_DATE,
6228 					     OBJECT_VERSION_NUMBER,
6229 					     BKUP_TBL_ID, -- PRTT_ENRT_RSLT_ID,
6230 					     EFFECTIVE_START_DATE,
6231 					     EFFECTIVE_END_DATE,
6232 					     ENRT_CVG_STRT_DT,
6233 					     ENRT_CVG_THRU_DT,
6234 					     SSPNDD_FLAG,
6235 					     PRTT_IS_CVRD_FLAG,
6236 					     BNFT_AMT,
6237 					     BNFT_NNMNTRY_UOM,
6238 					     BNFT_TYP_CD,
6239 					     UOM,
6240 					     ORGNL_ENRT_DT,
6241 					     ENRT_MTHD_CD,
6242 					     ENRT_OVRIDN_FLAG,
6243 					     ENRT_OVRID_RSN_CD,
6244 					     ERLST_DEENRT_DT,
6245 					     ENRT_OVRID_THRU_DT,
6246 					     NO_LNGR_ELIG_FLAG,
6247 					     BNFT_ORDR_NUM,
6248 					     PERSON_ID,
6249 					     ASSIGNMENT_ID,
6250 					     PGM_ID,
6251 					     PRTT_ENRT_RSLT_STAT_CD,
6252 					     PL_ID,
6253 					     OIPL_ID,
6254 					     PTIP_ID,
6255 					     PL_TYP_ID,
6256 					     LER_ID,
6257 					     PER_IN_LER_ID,
6258 					     RPLCS_SSPNDD_RSLT_ID,
6259 					     BUSINESS_GROUP_ID,
6260 					     LCR_ATTRIBUTE_CATEGORY,
6261 					     LCR_ATTRIBUTE1,
6262 					     LCR_ATTRIBUTE2,
6263 					     LCR_ATTRIBUTE3,
6264 					     LCR_ATTRIBUTE4,
6265 					     LCR_ATTRIBUTE5,
6266 					     LCR_ATTRIBUTE6,
6267 					     LCR_ATTRIBUTE7,
6268 					     LCR_ATTRIBUTE8,
6269 					     LCR_ATTRIBUTE9,
6270 					     LCR_ATTRIBUTE10,
6271 					     LCR_ATTRIBUTE11,
6272 					     LCR_ATTRIBUTE12,
6273 					     LCR_ATTRIBUTE13,
6274 					     LCR_ATTRIBUTE14,
6275 					     LCR_ATTRIBUTE15 ,
6276 					     PER_IN_LER_ENDED_ID,
6277 					     PL_ORDR_NUM,
6278 					     PLIP_ORDR_NUM,
6279 					     PTIP_ORDR_NUM,
6280 					     OIPL_ORDR_NUM)
6281 					   values (
6282 					    'BEN_PRTT_ENRT_RSLT_F_ADJ',
6283 					    l_enrt_rslt2.COMP_LVL_CD,
6284 					    l_enrt_rslt2.PEN_ATTRIBUTE16,
6285 					    l_enrt_rslt2.PEN_ATTRIBUTE17,
6286 					    l_enrt_rslt2.PEN_ATTRIBUTE18,
6287 					    l_enrt_rslt2.PEN_ATTRIBUTE19,
6288 					    l_enrt_rslt2.PEN_ATTRIBUTE20,
6289 					    l_enrt_rslt2.PEN_ATTRIBUTE21,
6290 					    l_enrt_rslt2.PEN_ATTRIBUTE22,
6291 					    l_enrt_rslt2.PEN_ATTRIBUTE23,
6292 					    l_enrt_rslt2.PEN_ATTRIBUTE24,
6293 					    l_enrt_rslt2.PEN_ATTRIBUTE25,
6294 					    l_enrt_rslt2.PEN_ATTRIBUTE26,
6295 					    l_enrt_rslt2.PEN_ATTRIBUTE27,
6296 					    l_enrt_rslt2.PEN_ATTRIBUTE28,
6297 					    l_enrt_rslt2.PEN_ATTRIBUTE29,
6298 					    l_enrt_rslt2.PEN_ATTRIBUTE30,
6299 					    l_enrt_rslt2.LAST_UPDATE_DATE,
6300 					    l_enrt_rslt2.LAST_UPDATED_BY,
6301 					    l_enrt_rslt2.LAST_UPDATE_LOGIN,
6302 					    l_enrt_rslt2.CREATED_BY,
6303 					    l_enrt_rslt2.CREATION_DATE,
6304 					    l_enrt_rslt2.REQUEST_ID,
6305 					    l_enrt_rslt2.PROGRAM_APPLICATION_ID,
6306 					    l_enrt_rslt2.PROGRAM_ID,
6307 					    l_enrt_rslt2.PROGRAM_UPDATE_DATE,
6308 					    l_enrt_rslt2.OBJECT_VERSION_NUMBER,
6309 					    l_enrt_rslt2.PRTT_ENRT_RSLT_ID,
6310 					    l_enrt_rslt2.EFFECTIVE_START_DATE,
6311 					    l_enrt_rslt2.EFFECTIVE_END_DATE,
6312 					    l_enrt_rslt2.ENRT_CVG_STRT_DT,
6313 					    l_enrt_rslt2.ENRT_CVG_THRU_DT,
6314 					    l_enrt_rslt2.SSPNDD_FLAG,
6315 					    l_enrt_rslt2.PRTT_IS_CVRD_FLAG,
6316 					    l_enrt_rslt2.BNFT_AMT,
6317 					    l_enrt_rslt2.BNFT_NNMNTRY_UOM,
6318 					    l_enrt_rslt2.BNFT_TYP_CD,
6319 					    l_enrt_rslt2.UOM,
6320 					    l_enrt_rslt2.ORGNL_ENRT_DT,
6321 					    l_enrt_rslt2.ENRT_MTHD_CD,
6322 					    l_enrt_rslt2.ENRT_OVRIDN_FLAG,
6323 					    l_enrt_rslt2.ENRT_OVRID_RSN_CD,
6324 					    l_enrt_rslt2.ERLST_DEENRT_DT,
6325 					    l_enrt_rslt2.ENRT_OVRID_THRU_DT,
6326 					    l_enrt_rslt2.NO_LNGR_ELIG_FLAG,
6327 					    l_enrt_rslt2.BNFT_ORDR_NUM,
6328 					    l_enrt_rslt2.PERSON_ID,
6329 					    l_enrt_rslt2.ASSIGNMENT_ID,
6330 					    l_enrt_rslt2.PGM_ID,
6331 					    l_enrt_rslt2.PRTT_ENRT_RSLT_STAT_CD,
6332 					    l_enrt_rslt2.PL_ID,
6333 					    l_enrt_rslt2.OIPL_ID,
6334 					    l_enrt_rslt2.PTIP_ID,
6335 					    l_enrt_rslt2.PL_TYP_ID,
6336 					    l_enrt_rslt2.LER_ID,
6337 					    l_enrt_rslt2.PER_IN_LER_ID,
6338 					    l_enrt_rslt2.RPLCS_SSPNDD_RSLT_ID,
6339 					    l_enrt_rslt2.BUSINESS_GROUP_ID,
6340 					    l_enrt_rslt2.PEN_ATTRIBUTE_CATEGORY,
6341 					    l_enrt_rslt2.PEN_ATTRIBUTE1,
6342 					    l_enrt_rslt2.PEN_ATTRIBUTE2,
6343 					    l_enrt_rslt2.PEN_ATTRIBUTE3,
6344 					    l_enrt_rslt2.PEN_ATTRIBUTE4,
6345 					    l_enrt_rslt2.PEN_ATTRIBUTE5,
6346 					    l_enrt_rslt2.PEN_ATTRIBUTE6,
6347 					    l_enrt_rslt2.PEN_ATTRIBUTE7,
6348 					    l_enrt_rslt2.PEN_ATTRIBUTE8,
6349 					    l_enrt_rslt2.PEN_ATTRIBUTE9,
6350 					    l_enrt_rslt2.PEN_ATTRIBUTE10,
6351 					    l_enrt_rslt2.PEN_ATTRIBUTE11,
6352 					    l_enrt_rslt2.PEN_ATTRIBUTE12,
6353 					    l_enrt_rslt2.PEN_ATTRIBUTE13,
6354 					    l_enrt_rslt2.PEN_ATTRIBUTE14,
6355 					    l_enrt_rslt2.PEN_ATTRIBUTE15,
6356 					    l_global_epe_rec.per_in_ler_id ,
6357 					    l_enrt_rslt2.PL_ORDR_NUM,
6358 					    l_enrt_rslt2.PLIP_ORDR_NUM,
6359 					    l_enrt_rslt2.PTIP_ORDR_NUM,
6360 					    l_enrt_rslt2.OIPL_ORDR_NUM
6361 					);
6362 		      end if;
6363 		      close c_bkp_enrt_rslt_exist;
6364 		       --
6365 		     end if;
6366 	      -- end of bug 5555269
6367 	      end if;
6368 
6369           ben_prtt_enrt_result_api.delete_prtt_enrt_result
6370               (p_validate                => false,
6371                p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
6372                p_effective_start_date    => l_effective_start_date,
6373                p_effective_end_date      => l_effective_end_date,
6374                p_object_version_number   => l_enrt_rslt.object_version_number,
6375                p_effective_date          => l_enrt_rslt.effective_end_date,
6376                p_datetrack_mode          => hr_api.g_future_change,
6377                p_multi_row_validate      => FALSE);
6378       p_object_version_number := l_enrt_rslt.object_version_number;
6379       --
6380       --  Bug 5766477  Also re-open dependent coverage.
6381       --
6382       for l_dpnt_rec in  c_get_dpnt(l_enrt_rslt.effective_end_date) loop
6383       ben_elig_cvrd_dpnt_api.delete_elig_cvrd_dpnt
6384         (p_validate                => false,
6385          p_elig_cvrd_dpnt_id       => l_dpnt_rec.elig_cvrd_dpnt_id,
6386          p_effective_start_date    => l_effective_start_date,
6387          p_effective_end_date      => l_effective_end_date,
6388          p_object_version_number   => l_dpnt_rec.object_version_number,
6389          p_business_group_id       => p_business_group_id,
6390          p_effective_date          => l_enrt_rslt.effective_end_date,
6391          p_datetrack_mode          => hr_api.g_future_change,
6392          p_multi_row_actn          => FALSE);
6393       end loop;
6394 
6395       if (g_debug) then
6396           hr_utility.set_location('BKKK p_prtt_enrt_rslt_id '|| p_prtt_enrt_rslt_id, 100);
6397       end if;
6398       --
6399       open c_prtt_rt_val_id;
6400       fetch c_prtt_rt_val_id into l_prtt_rt_val_id, l_acty_base_rt_id2;
6401       loop
6402         if c_prtt_rt_val_id%notfound then
6403            exit;
6404         end if;
6405         --
6406         if (g_debug) then
6407             hr_utility.set_location('BKKK l_prtt_rt_val_id '|| l_prtt_rt_val_id, 100);
6408             hr_utility.set_location('BKKK l_acty_base_rt_id2 '|| l_acty_base_rt_id2, 100);
6409             hr_utility.set_location('BKKK p_elig_per_elctbl_chc_id  '|| p_elig_per_elctbl_chc_id, 100);
6410             hr_utility.set_location('BKKK p_enrt_bnft_id '|| p_enrt_bnft_id, 100);
6411             hr_utility.set_location('BKKK l_enrt_rt_id '|| l_enrt_rt_id, 100);
6412         end if;
6413         --
6414         open c_enrt_rt(l_acty_base_rt_id2);
6415         fetch c_enrt_rt into l_enrt_rt_id;
6416         if c_enrt_rt%found then
6417           update ben_enrt_rt
6418                set prtt_rt_val_id = l_prtt_rt_val_id
6419           where enrt_rt_id = l_enrt_rt_id;
6420           --
6421           if (g_debug) then
6422             hr_utility.set_location('BKKK l_enrt_rt_id '|| l_enrt_rt_id, 200);
6423           end if;
6424           --
6425         end if;
6426         close c_enrt_rt;
6427         fetch c_prtt_rt_val_id into l_prtt_rt_val_id, l_acty_base_rt_id2;
6428       end loop;
6429 
6430       close c_prtt_rt_val_id;
6431       --
6432       --
6433       end if ;--l_interim_count > 0--3733745
6434     end if;
6435     close c_enrt_rslt;
6436     --
6437     if g_debug then
6438       hr_utility.set_location('bef update cvg '|| l_global_epe_rec.enrt_cvg_strt_dt,8086.2);
6439     end if;
6440     if g_debug then
6441       hr_utility.set_location('bef update erly '||l_global_epe_rec.erlst_deenrt_dt,8086.2);
6442     end if;
6443     --Override code
6444     if l_old_enrt_ovrid_thru_dt is not null then
6445       --
6446       if g_debug then
6447         hr_utility.set_location(' enrt_cvg_strt_dt_cd '||l_global_epe_rec.enrt_cvg_strt_dt_cd,123);
6448       end if;
6449       if g_debug then
6450         hr_utility.set_location(' p_elig_per_elctbl_chc_id '||p_elig_per_elctbl_chc_id,123);
6451       end if;
6452       if l_global_epe_rec.enrt_cvg_strt_dt_cd is not null then
6453         ben_determine_date.main(
6454           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
6455           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
6456           p_person_id          => l_global_pil_rec.person_id,
6457           p_pgm_id             => l_global_epe_rec.pgm_id,
6458           p_pl_id              => l_global_epe_rec.pl_id,
6459           p_oipl_id            => l_global_epe_rec.oipl_id,
6460           p_business_group_id  => l_global_epe_rec.business_group_id,
6461           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
6462           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
6463           p_effective_date     => p_effective_date,
6464           p_returned_date      => l_new_cvg_strt_dt
6465           );
6466       else
6467         --
6468         l_new_cvg_strt_dt := l_global_pil_rec.lf_evt_ocrd_dt ;
6469         --
6470       end if;
6471       --
6472       if l_new_cvg_strt_dt > l_old_enrt_ovrid_thru_dt then
6473         --
6474         l_old_enrt_ovrid_thru_dt := null;
6475         l_old_enrt_ovrid_rsn_cd  := null;
6476         l_old_enrt_ovridn_flag   := 'N';
6477         --
6478       end if;
6479     end if;
6480     -- end overrdie code
6481 
6482     ----------Bug 7374973
6483     open c_unrestricted(l_global_pil_rec.ler_id);
6484     fetch c_unrestricted into l_unrestricted;
6485     close c_unrestricted;
6486     ------write to extract log
6487     hr_utility.set_location('l_unrestricted : '||l_unrestricted.typ_cd,1);
6488     if l_unrestricted.typ_cd = 'SCHEDDU' then
6489     ben_ext_chlg.log_benefit_chg
6490           (p_action                      =>  'REINSTATE'
6491           ,p_pl_id                       =>  l_global_epe_rec.pl_id
6492           ,p_old_pl_id                   =>  l_old_pl_id
6493           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
6494           ,p_old_oipl_id                 =>  l_old_oipl_id
6495           ,p_old_bnft_amt                =>  l_old_bnft_val
6496           ,p_bnft_amt                    =>  l_global_enb_rec.val
6497           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
6498           ,p_enrt_cvg_end_dt             =>  hr_api.g_eot
6499           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
6500           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
6501           ,p_person_id                   =>  l_global_pil_rec.person_id
6502           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
6503           ,p_effective_date              =>  p_effective_date
6504           );
6505     end if;
6506     -----Bug 7374973
6507     ben_PRTT_ENRT_RESULT_api.update_enrollment(
6508           p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id
6509         ,p_effective_start_date      => p_effective_start_date
6510         ,p_effective_end_date        => p_effective_end_date
6511         ,p_enrt_mthd_cd              => p_enrt_mthd_cd
6512         ,p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt
6513         ,p_enrt_cvg_thru_dt          => hr_api.g_eot
6514         ,p_enrt_ovrid_thru_dt        => l_old_enrt_ovrid_thru_dt
6515         ,p_enrt_ovrid_rsn_cd         => l_old_enrt_ovrid_rsn_cd
6516         ,p_enrt_ovridn_flag          => l_old_enrt_ovridn_flag
6517         ,p_object_version_number     => p_object_version_number
6518         ,p_effective_date            => p_effective_date
6519         ,p_datetrack_mode            => p_datetrack_mode
6520         ,p_pgm_id                    => l_global_epe_rec.pgm_id
6521         ,p_ptip_id                   => l_global_epe_rec.ptip_id
6522         ,p_pl_typ_id                 => l_global_epe_rec.pl_typ_id
6523         ,p_pl_id                     => l_global_epe_rec.pl_id
6524         ,p_oipl_id                   => l_global_epe_rec.oipl_id
6525         ,p_enrt_bnft_id              => p_enrt_bnft_id
6526         ,p_business_group_id         => p_business_group_id
6527         ,p_erlst_deenrt_dt           => l_global_epe_rec.erlst_deenrt_dt
6528         ,p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id
6529 --        ,p_sspndd_flag               => nvl(l_old_sspndd_flag,'N')          --Bug#5099296
6530         ,p_sspndd_flag               => nvl(l_global_pen_rec.sspndd_flag,'N') --Bug#5099296
6531         ,p_multi_row_validate        => FALSE
6532 
6533       -- derive from per_in_ler_id
6534         ,p_ler_id                    =>  l_global_pil_rec.ler_id
6535         ,p_person_id                 =>  l_global_pil_rec.person_id
6536         ,p_bnft_amt                  =>  l_global_enb_rec.val
6537         ,p_uom                       =>  l_global_pel_rec.uom
6538         ,p_bnft_nnmntry_uom          =>  l_global_enb_rec.nnmntry_uom
6539         ,p_bnft_typ_cd               =>  l_global_enb_rec.bnft_typ_cd
6540         ,p_bnft_ordr_num             =>  l_global_enb_rec.ordr_num
6541         ,p_suspend_flag              =>  p_suspend_flag
6542         ,p_prtt_enrt_interim_id      =>  l_prtt_enrt_interim_id
6543 	,p_comp_lvl_cd               =>  l_global_pen_rec.comp_lvl_cd -- bug 5417132
6544         ,p_program_application_id    => fnd_global.prog_appl_id
6545         ,p_program_id                => fnd_global.conc_program_id
6546         ,p_request_id                => fnd_global.conc_request_id
6547         ,p_program_update_date       => sysdate
6548         ,p_pen_attribute_category    => p_pen_attribute_category
6549         ,p_pen_attribute1            => p_pen_attribute1
6550         ,p_pen_attribute2            => p_pen_attribute2
6551         ,p_pen_attribute3            => p_pen_attribute3
6552         ,p_pen_attribute4            => p_pen_attribute4
6553         ,p_pen_attribute5            => p_pen_attribute5
6554         ,p_pen_attribute6            => p_pen_attribute6
6555         ,p_pen_attribute7            => p_pen_attribute7
6556         ,p_pen_attribute8            => p_pen_attribute8
6557         ,p_pen_attribute9            => p_pen_attribute9
6558         ,p_pen_attribute10           => p_pen_attribute10
6559         ,p_pen_attribute11           => p_pen_attribute11
6560         ,p_pen_attribute12           => p_pen_attribute12
6561         ,p_pen_attribute13           => p_pen_attribute13
6562         ,p_pen_attribute14           => p_pen_attribute14
6563         ,p_pen_attribute15           => p_pen_attribute15
6564         ,p_pen_attribute16           => p_pen_attribute16
6565         ,p_pen_attribute17           => p_pen_attribute17
6566         ,p_pen_attribute18           => p_pen_attribute18
6567         ,p_pen_attribute19           => p_pen_attribute19
6568         ,p_pen_attribute20           => p_pen_attribute20
6569         ,p_pen_attribute21           => p_pen_attribute21
6570         ,p_pen_attribute22           => p_pen_attribute22
6571         ,p_pen_attribute23           => p_pen_attribute23
6572         ,p_pen_attribute24           => p_pen_attribute24
6573         ,p_pen_attribute25           => p_pen_attribute25
6574         ,p_pen_attribute26           => p_pen_attribute26
6575         ,p_pen_attribute27           => p_pen_attribute27
6576         ,p_pen_attribute28           => p_pen_attribute28
6577         ,p_pen_attribute29           => p_pen_attribute29
6578         ,p_pen_attribute30           => p_pen_attribute30
6579         ,p_dpnt_actn_warning         => l_dpnt_actn_warning
6580         ,p_bnf_actn_warning          => l_bnf_actn_warning
6581         ,p_ctfn_actn_warning         => l_ctfn_actn_warning
6582     );
6583     p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id;
6584     if g_debug then
6585       hr_utility.set_location(l_proc, 90);
6586     end if;
6587   --
6588   -- (maagrawa Jan 05,2001).
6589   -- Replaced this else with elsif. Normal processing will go as normal as
6590   -- the p_enrt_cvg_thru_dt will be null.
6591   -- The additional condition has been added to handle special case in
6592   -- Individual Comp. when the user enters both the coverage start date
6593   -- and the coverage through date when creating the result for the
6594   -- first time. In this case, we want to create a new enrollment and
6595   -- call delete enrollment in the end to update the coverage through date.
6596   -- If the result_id already exists and the enrt_thru_dt is not null, it means
6597   -- we do not have to create a new result, we need to just update the
6598   -- result record with the entered coverage through date, which will be
6599   -- done when delete_enrollment is called at the end.
6600   --
6601   elsif (l_global_epe_rec.prtt_enrt_rslt_id is null or
6602          p_enrt_cvg_thru_dt is null) then
6603     --
6604     if g_debug then
6605       hr_utility.set_location('elese part ' , 8086.1);
6606     end if;
6607     l_crntly_enrd_rslt_exists := false;
6608     --
6609     if l_global_epe_rec.prtt_enrt_rslt_id is not null then
6610       open  c_current_result_info(l_global_epe_rec.prtt_enrt_rslt_id);
6611       fetch c_current_result_info into l_crntly_enrd_rslt_rec;
6612       if c_current_result_info%found then
6613         l_crntly_enrd_rslt_exists := true;
6614       end if;
6615       close c_current_result_info;
6616     end if;
6617     --
6618     --Override code
6619     if l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt is not null then
6620       --
6621       if l_global_epe_rec.enrt_cvg_strt_dt_cd is not null then
6622         --
6623         ben_determine_date.main(
6624           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
6625           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
6626           p_person_id          => l_global_pil_rec.person_id,
6627           p_pgm_id             => l_global_epe_rec.pgm_id,
6628           p_pl_id              => l_global_epe_rec.pl_id,
6629           p_oipl_id            => l_global_epe_rec.oipl_id,
6630           p_business_group_id  => l_global_epe_rec.business_group_id,
6631           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
6632           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
6633           p_effective_date     => p_effective_date,
6634           p_returned_date      => l_new_cvg_strt_dt
6635         );
6636         --
6637       else
6638         --
6639         l_new_cvg_strt_dt := l_global_pil_rec.lf_evt_ocrd_dt ;
6640         --
6641       end if;
6642       --
6643       if l_new_cvg_strt_dt > l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt then
6644         --
6645         l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt := null;
6646         l_crntly_enrd_rslt_rec.enrt_ovrid_rsn_cd  := null;
6647         l_crntly_enrd_rslt_rec.enrt_ovridn_flag   := 'N';
6648         --
6649       end if;
6650       --
6651     end if;
6652     -- end overrdie code
6653     --
6654     if l_global_epe_rec.crntly_enrd_flag = 'Y' and
6655        l_global_epe_rec.prtt_enrt_rslt_id is not null and
6656        l_crntly_enrd_rslt_exists and
6657        -- l_use_new_result=false and
6658        ben_sspndd_enrollment.g_use_new_result=false and /*ENH*/
6659        nvl(l_crntly_enrd_rslt_rec.bnft_amt,hr_api.g_number)=
6660            nvl(l_global_enb_rec.val,hr_api.g_number) and
6661        /* Bug 4954541 - We also need to check if old coverage was non-null and new coverage is null
6662        nvl(l_crntly_enrd_rslt_rec.bnft_amt,hr_api.g_number)=
6663            nvl(l_global_enb_rec.val,nvl(l_crntly_enrd_rslt_rec.bnft_amt,
6664                                             hr_api.g_number)) and
6665        */
6666        l_start_new_result = false and
6667        l_global_epe_rec.enrt_cvg_strt_dt = l_crntly_enrd_rslt_rec.enrt_cvg_strt_dt then  --BUG 4568911
6668       -- RCHASE Bug#5353 alteration
6669       --     nvl(l_global_enb_rec.val,hr_api.g_number) then
6670       --
6671       -- If they are not staying in the same plan and option
6672       --  and ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = Y  then
6673       -- re-use the enrollment result.
6674       --
6675       if g_debug then
6676         hr_utility.set_location(l_proc, 95);
6677       end if;
6678       --
6679       l_prtt_enrt_rslt_id     := l_global_epe_rec.prtt_enrt_rslt_id;
6680       --
6681       -- if sched mode and l_crnt_enrt_cvg_strt_dt is not null then
6682       -- see if plan has regulation of IRC Section 125 or 129.
6683       --
6684       l_regn_125_or_129_flag:='N';
6685      /*
6686       if l_global_pel_rec.enrt_perd_id is not null and -- same as p_run_mode='C'
6687          l_old_enrt_cvg_strt_dt is not null then
6688         open c_regn_125_or_129;
6689         fetch c_regn_125_or_129 into l_regn_125_or_129_flag;
6690         hr_utility. set_location('regn_125_or_129='||l_regn_125_or_129_flag,10);
6691         close c_regn_125_or_129;
6692       end if;
6693     */
6694       if l_regn_125_or_129_flag='N' then
6695         l_global_epe_rec.enrt_cvg_strt_dt:= l_crntly_enrd_rslt_rec.enrt_cvg_strt_dt;
6696         l_global_epe_rec.erlst_deenrt_dt := nvl(l_crntly_enrd_rslt_rec.erlst_deenrt_dt,
6697                                                 l_global_epe_rec.erlst_deenrt_dt);
6698       end if;
6699       --
6700       if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
6701          p_enrt_cvg_strt_dt is not null then
6702         l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
6703       end if;
6704       --
6705       l_object_version_number := l_crntly_enrd_rslt_rec.object_version_number;
6706       --
6707       if g_debug then
6708         hr_utility.set_location('bef update cvg '|| l_global_epe_rec.enrt_cvg_strt_dt,8086.2);
6709       end if;
6710       if g_debug then
6711         hr_utility.set_location('bef update erly '||l_global_epe_rec.erlst_deenrt_dt,8086.2);
6712       end if;
6713       ----Bug 9139820
6714       open c_get_pil_enrt( l_global_epe_rec.prtt_enrt_rslt_id,l_global_epe_rec.per_in_ler_id,
6715                                   l_global_epe_rec.enrt_cvg_strt_dt);
6716       fetch c_get_pil_enrt into l_check_enrt_same_pil;
6717       close c_get_pil_enrt;
6718       hr_utility.set_location('l_check_enrt_same_pil.pen ID '||l_check_enrt_same_pil.prtt_enrt_rslt_id,8086.2);
6719       if l_check_enrt_same_pil.prtt_enrt_rslt_id is not null then
6720             ---- Bug 9430735,fetch the per_in_ler_id which has the enrt rslt corresponding to pen.
6721       /*   open c_prev_pil(l_global_pil_rec.person_id);
6722 	 fetch c_prev_pil into l_prev_pil;
6723 	 if c_prev_pil%found then*/
6724 	 open c_prev_pil_with_pen(l_global_pil_rec.person_id,l_check_enrt_same_pil.prtt_enrt_rslt_id);
6725 	 fetch c_prev_pil_with_pen into l_prev_pil;
6726 	 if c_prev_pil_with_pen%found then
6727 	    hr_utility.set_location('previous pil found',2);
6728 	    open c_get_pil_enrt(l_check_enrt_same_pil.prtt_enrt_rslt_id,l_prev_pil.per_in_ler_id,l_check_enrt_same_pil.enrt_cvg_strt_dt);
6729 	    fetch c_get_pil_enrt into l_get_prev_pil_enrt;
6730 	    if c_get_pil_enrt%found then
6731 	       hr_utility.set_location('previous enr found',2);
6732 	       hr_utility.set_location('previous prtt_enrt_rslt ' ||l_get_prev_pil_enrt.prtt_enrt_rslt_id,2);
6733                ben_prtt_enrt_result_api.delete_prtt_enrt_result
6734                 (p_validate                => false,
6735                  p_prtt_enrt_rslt_id       => l_get_prev_pil_enrt.prtt_enrt_rslt_id,
6736                  p_effective_start_date    => l_effective_start_date,
6737                  p_effective_end_date      => l_effective_end_date,
6738                  p_object_version_number   => l_get_prev_pil_enrt.object_version_number,
6739                  p_effective_date          => l_get_prev_pil_enrt.effective_start_date,
6740                  p_datetrack_mode          => hr_api.g_future_change,
6741                  p_multi_row_validate      => FALSE);
6742 
6743 	    ---Refetch the enrollment result for the Object version number.
6744 	       open c_get_ovn(l_check_enrt_same_pil.prtt_enrt_rslt_id,l_prev_pil.per_in_ler_id,l_get_prev_pil_enrt.effective_start_date);
6745 	       fetch c_get_ovn into l_object_version_number;
6746 	       close c_get_ovn;
6747 	       hr_utility.set_location('l_object_version_number,del pen : '||l_object_version_number,99.3);
6748 
6749 	  else
6750 	       --check if any correction record exists in the back-up table.
6751 	       hr_utility.set_location('else part prev enr',99);
6752                open c_bkup_pen_rec(l_check_enrt_same_pil.prtt_enrt_rslt_id,l_prev_pil.per_in_ler_id,l_check_enrt_same_pil.person_id,
6753 	                           l_check_enrt_same_pil.effective_start_date,l_check_enrt_same_pil.enrt_cvg_strt_dt);
6754 	       fetch c_bkup_pen_rec into l_bkup_pen_rec;
6755 	       if c_bkup_pen_rec%found then
6756 	          hr_utility.set_location('bkup record found : ' || l_object_version_number,99);
6757 
6758 		  --Update the pen record with the current pil to previous pil
6759 	          ben_prtt_enrt_result_api.update_prtt_enrt_result
6760 			(p_validate                => FALSE
6761 			,p_prtt_enrt_rslt_id       => l_check_enrt_same_pil.prtt_enrt_rslt_id
6762 			,p_effective_start_date    => l_effective_start_date
6763 			,p_effective_end_date      => l_effective_end_date
6764 			,p_per_in_ler_id           => l_bkup_pen_rec.per_in_ler_id
6765 			,p_enrt_cvg_thru_dt        => l_bkup_pen_rec.enrt_cvg_thru_dt
6766 			,p_object_version_number   => l_check_enrt_same_pil.object_version_number
6767 			,p_effective_date          => l_bkup_pen_rec.effective_start_date
6768 			,p_datetrack_mode          => 'CORRECTION'
6769 			,p_business_group_id       => p_business_group_id
6770 			,p_multi_row_validate      => FALSE );
6771 		  ---Refetch the enrollment result for the Object version number.
6772 	       open c_get_ovn(l_check_enrt_same_pil.prtt_enrt_rslt_id,l_prev_pil.per_in_ler_id,l_check_enrt_same_pil.effective_start_date);
6773 	       fetch c_get_ovn into l_object_version_number;
6774 	       close c_get_ovn;
6775 	       hr_utility.set_location('l_object_version_number,upd pen : '||l_object_version_number,99.1);
6776 	       end if;
6777 	       close c_bkup_pen_rec;
6778 	     end if;
6779 	    close c_get_pil_enrt;
6780 
6781 	 end if;
6782 	 /*close c_prev_pil; */ ---Bug 9430735
6783 	 close c_prev_pil_with_pen;
6784         end if;
6785       ----End of Bug 9139820
6786       --
6787        hr_utility.set_location('l_global_epe_rec.enrt_cvg_strt_dt' ||l_global_epe_rec.enrt_cvg_strt_dt,2);
6788       ben_PRTT_ENRT_RESULT_api.update_enrollment(
6789            p_prtt_enrt_rslt_id         => l_prtt_enrt_rslt_id
6790           ,p_effective_start_date      => p_effective_start_date
6791           ,p_effective_end_date        => p_effective_end_date
6792           ,p_enrt_mthd_cd              => p_enrt_mthd_cd
6793           ,p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt
6794           ,p_enrt_cvg_thru_dt          => hr_api.g_eot
6795           ,p_enrt_ovrid_thru_dt        => l_crntly_enrd_rslt_rec.enrt_ovrid_thru_dt
6796           ,p_enrt_ovrid_rsn_cd         => l_crntly_enrd_rslt_rec.enrt_ovrid_rsn_cd
6797           ,p_enrt_ovridn_flag          => l_crntly_enrd_rslt_rec.enrt_ovridn_flag
6798           ,p_object_version_number     => l_object_version_number
6799           ,p_effective_date            => p_effective_date
6800           ,p_datetrack_mode            => p_datetrack_mode
6801           ,p_pgm_id                    => l_global_epe_rec.pgm_id
6802           ,p_ptip_id                   => l_global_epe_rec.ptip_id
6803           ,p_pl_typ_id                 => l_global_epe_rec.pl_typ_id
6804           ,p_pl_id                     => l_global_epe_rec.pl_id
6805           ,p_oipl_id                   => l_global_epe_rec.oipl_id
6806           ,p_enrt_bnft_id              => p_enrt_bnft_id
6807           ,p_business_group_id         => l_global_epe_rec.business_group_id
6808           ,p_erlst_deenrt_dt           => l_global_epe_rec.erlst_deenrt_dt
6809           ,p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id
6810 --          ,p_sspndd_flag               => nvl(l_old_sspndd_flag,'N')        --Bug#5099296
6811         ,p_sspndd_flag               => nvl(l_global_pen_rec.sspndd_flag,'N') --Bug#5099296
6812           ,p_multi_row_validate        => FALSE
6813 
6814         -- derive from per_in_ler_id
6815           ,p_ler_id                    =>  l_global_pil_rec.ler_id
6816           ,p_person_id                 =>  l_global_pil_rec.person_id
6817           ,p_bnft_amt                  =>  l_global_enb_rec.val
6818         ,p_uom                       =>  l_global_pel_rec.uom
6819         ,p_bnft_nnmntry_uom          =>  l_global_enb_rec.nnmntry_uom
6820         ,p_bnft_typ_cd               =>  l_global_enb_rec.bnft_typ_cd
6821         ,p_bnft_ordr_num             =>  l_global_enb_rec.ordr_num
6822           ,p_suspend_flag              =>  p_suspend_flag
6823           ,p_prtt_enrt_interim_id      =>  l_prtt_enrt_interim_id
6824 	  ,p_comp_lvl_cd               =>  l_global_pen_rec.comp_lvl_cd  -- 5417132
6825           ,p_program_application_id    => fnd_global.prog_appl_id
6826           ,p_program_id                => fnd_global.conc_program_id
6827           ,p_request_id                => fnd_global.conc_request_id
6828           ,p_program_update_date       => sysdate
6829           ,p_pen_attribute_category    => p_pen_attribute_category
6830           ,p_pen_attribute1            => p_pen_attribute1
6831           ,p_pen_attribute2            => p_pen_attribute2
6832           ,p_pen_attribute3            => p_pen_attribute3
6833           ,p_pen_attribute4            => p_pen_attribute4
6834           ,p_pen_attribute5            => p_pen_attribute5
6835           ,p_pen_attribute6            => p_pen_attribute6
6836           ,p_pen_attribute7            => p_pen_attribute7
6837           ,p_pen_attribute8            => p_pen_attribute8
6838           ,p_pen_attribute9            => p_pen_attribute9
6839           ,p_pen_attribute10           => p_pen_attribute10
6840           ,p_pen_attribute11           => p_pen_attribute11
6841           ,p_pen_attribute12           => p_pen_attribute12
6842           ,p_pen_attribute13           => p_pen_attribute13
6843           ,p_pen_attribute14           => p_pen_attribute14
6844           ,p_pen_attribute15           => p_pen_attribute15
6845           ,p_pen_attribute16           => p_pen_attribute16
6846           ,p_pen_attribute17           => p_pen_attribute17
6847           ,p_pen_attribute18           => p_pen_attribute18
6848           ,p_pen_attribute19           => p_pen_attribute19
6849           ,p_pen_attribute20           => p_pen_attribute20
6850           ,p_pen_attribute21           => p_pen_attribute21
6851           ,p_pen_attribute22           => p_pen_attribute22
6852           ,p_pen_attribute23           => p_pen_attribute23
6853           ,p_pen_attribute24           => p_pen_attribute24
6854           ,p_pen_attribute25           => p_pen_attribute25
6855           ,p_pen_attribute26           => p_pen_attribute26
6856           ,p_pen_attribute27           => p_pen_attribute27
6857           ,p_pen_attribute28           => p_pen_attribute28
6858           ,p_pen_attribute29           => p_pen_attribute29
6859           ,p_pen_attribute30           => p_pen_attribute30
6860           ,p_dpnt_actn_warning         => l_dpnt_actn_warning
6861           ,p_bnf_actn_warning          => l_bnf_actn_warning
6862           ,p_ctfn_actn_warning         => l_ctfn_actn_warning
6863       );
6864       p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id; --CFW
6865       -- RCHASE Bug#5353 No interim is being passed back
6866       l_prtt_enrt_interim_id:=nvl(l_prtt_enrt_interim_id,l_prtt_enrt_rslt_id); --CFW
6867       if g_debug then
6868         hr_utility.set_location(l_proc, 97);
6869       end if;
6870       -- Bug 2627078 fixes
6871       -- Now If the User selected the Interim as the Main enrollment while
6872       -- replacing the suspended enrollment, delink the interim from the
6873       -- suspended enrollment which is going to get deleted. So that it
6874       -- can become the original enrollment
6875       open c_delink_interim(l_global_epe_rec.prtt_enrt_rslt_id,p_prtt_enrt_rslt_id );
6876         fetch c_delink_interim into
6877               l_delink_interim.prtt_enrt_rslt_id,
6878               l_delink_interim.object_version_number ;
6879         if c_delink_interim%found then
6880             ben_prtt_enrt_result_api.update_prtt_enrt_result
6881               (p_validate                 => FALSE,
6882                p_prtt_enrt_rslt_id        => l_delink_interim.prtt_enrt_rslt_id,
6883                p_effective_start_date     => l_dlink_effective_start_date,
6884                p_effective_end_date       => l_dlink_effective_end_date,
6885                p_business_group_id        => p_business_group_id,
6886                p_RPLCS_SSPNDD_RSLT_ID     => null,
6887                p_object_version_number    => l_delink_interim.object_version_number,
6888                p_effective_date           => p_effective_date,
6889                p_datetrack_mode           => hr_api.g_correction,
6890                p_multi_row_validate       => FALSE,
6891                p_program_application_id   => fnd_global.prog_appl_id,
6892                p_program_id               => fnd_global.conc_program_id,
6893                p_request_id               => fnd_global.conc_request_id,
6894                p_program_update_date      => sysdate);
6895             --
6896             p_object_version_number := l_delink_interim.object_version_number ;
6897         end if ;
6898       close c_delink_interim ;
6899     else
6900       if g_debug then
6901         hr_utility.set_location(l_proc, 100);
6902       end if;
6903       -- If they are not staying in the same plan and option
6904       -- (ELIG PER ELCTBL CHC: CRNTLY ENRD FLAG = N) and
6905       -- no replacement result is specified, then create a new
6906       -- enrolment.
6907 
6908       -- need to create a new result
6909 
6910       -- first, resolve previously unknown values.
6911 
6912       if (l_global_epe_rec.enrt_cvg_strt_dt_cd is not null) then
6913         if g_debug then
6914           hr_utility.set_location(l_proc, 130);
6915         end if;
6916         l_elect_cvg_strt_dt   := l_global_epe_rec.enrt_cvg_strt_dt    ;
6917         --
6918         if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
6919            p_enrt_cvg_strt_dt is not null then
6920           l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
6921         end if;
6922         --
6923 
6924 
6925         ben_determine_date.main(
6926           p_date_cd            => l_global_epe_rec.enrt_cvg_strt_dt_cd,
6927           p_per_in_ler_id      => l_global_epe_rec.per_in_ler_id,
6928           p_person_id          => l_global_pil_rec.person_id,
6929           p_pgm_id             => l_global_epe_rec.pgm_id,
6930           p_pl_id              => l_global_epe_rec.pl_id,
6931           p_oipl_id            => l_global_epe_rec.oipl_id,
6932           p_business_group_id  => l_global_epe_rec.business_group_id,
6933           p_formula_id         => l_global_epe_rec.enrt_cvg_strt_dt_rl,
6934           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
6935           p_effective_date     => p_effective_date,
6936         --  p_returned_date      => l_global_epe_rec.enrt_cvg_strt_dt
6937           p_returned_date      => l_enrt_cvg_strt_dt
6938         );
6939 
6940        if g_debug then
6941            hr_utility.set_location('calc date' || l_enrt_cvg_strt_dt,8086.1);
6942            hr_utility.set_location('prev calc date' || l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
6943        end if;
6944        -- 2982606 when the first time enrolled in waiting plan,after save thge enrollment the date changed back to
6945        --even date
6946        if l_enrt_cvg_strt_dt > l_global_epe_rec.enrt_cvg_strt_dt
6947           -- if the coverage start dt code is election then take the current cacluated code
6948           OR l_global_epe_rec.enrt_cvg_strt_dt_cd in  ('ODEWM','AFDELD','FDMELD')
6949 	  OR (l_global_epe_rec.enrt_cvg_strt_dt_cd in  ('RL') )  then -- Bug 13079111/13472223
6950            l_global_epe_rec.enrt_cvg_strt_dt := l_enrt_cvg_strt_dt;
6951            hr_utility.set_location('after comparison  calc date' || l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
6952        end if;
6953 
6954 
6955         if g_debug then
6956            hr_utility.set_location('denrt at elec' ||l_global_epe_rec.erlst_deenrt_dt,8086.1);
6957          end if;
6958          if g_debug then
6959            hr_utility.set_location('prt rslt deent '||l_old_erlst_deenrt_dt , 8086.1);
6960          end if;
6961          if g_debug then
6962            hr_utility.set_location('before calc cvg'||l_elect_cvg_strt_dt,8086.1);
6963          end if;
6964 
6965         ---calcualte the function to call the erls_denrt_dt
6966         --- l_old_erlst_deenrt_dt is decide the previous enrolment
6967         -- bal_epe_rec.epe.erlst_deenrt_dt decide the whether erlst_deenrt_dt is to be calc
6968         if l_old_erlst_deenrt_dt is null and
6969            l_global_epe_rec.erlst_deenrt_dt is not null and
6970            nvl(l_elect_cvg_strt_dt,hr_api.g_eot)
6971                   <> l_global_epe_rec.enrt_cvg_strt_dt  then
6972            if g_debug then
6973              hr_utility.set_location('CALLINGH ERLST DATE ' , 8086.1);
6974            end if;
6975            determine_erlst_deenrt_date(p_oipl_id        => l_global_epe_rec.oipl_id,
6976                                  p_pl_id                => l_global_epe_rec.pl_id,
6977                                  p_pl_typ_id            => l_global_epe_rec.pl_typ_id ,
6978                                  p_ptip_id              => l_global_epe_rec.ptip_id,
6979                                  p_pgm_id               => l_global_epe_rec.pgm_id,
6980                                  p_ler_id               => l_global_pil_rec.ler_id ,
6981                                  p_effective_date       => p_effective_date,
6982                                  p_business_group_id    => p_business_group_id,
6983                                  p_orgnl_enrt_dt        => l_old_orgnl_enrt_dt,
6984                                  p_person_id            => l_global_pil_rec.person_id,
6985                                  p_lf_evt_ocrd_dt       => p_effective_date,
6986                                  p_enrt_cvg_strt_dt     => l_global_epe_rec.enrt_cvg_strt_dt,
6987                                  p_return_date          => l_global_epe_rec.erlst_deenrt_dt);
6988         else
6989             l_global_epe_rec.erlst_deenrt_dt := nvl(l_old_erlst_deenrt_dt,
6990                                                         l_global_epe_rec.erlst_deenrt_dt) ;
6991         end if ;
6992       end if;
6993 
6994       if g_debug then
6995         hr_utility.set_location('l_global_epe_recerslt_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,8086.1);
6996       end if;
6997       if g_debug then
6998         hr_utility.set_location('l_global_epe_recerslt_deenrt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,8086.1);
6999       end if;
7000       if g_debug then
7001         hr_utility.set_location('l_old_erlst_deenrt_dt '||l_old_erlst_deenrt_dt,8086.1);
7002       end if;
7003       if g_debug then
7004         hr_utility.set_location(l_proc, 150);
7005       end if;
7006       if (l_global_epe_rec.enrt_cvg_strt_dt is null) then
7007         --
7008         -- null globals to prevent bleeding
7009         --
7010         g_enrt_bnft_id:=null;
7011         g_bnft_val:=null;
7012         g_elig_per_elctbl_chc_id:=null;
7013         --
7014         if g_debug then
7015           hr_utility.set_location('BEN_91453_CVG_STRT_DT_NOT_FOUN id:'|| to_char(l_global_epe_rec.pl_id), 169);
7016         end if;
7017         fnd_message.set_name('BEN','BEN_91453_CVG_STRT_DT_NOT_FOUN');
7018         fnd_message.set_token('PROC',l_proc);
7019         fnd_message.set_token('PERSON_ID',to_char(l_global_pil_rec.person_id));
7020         fnd_message.set_token('PGM_ID',to_char(l_global_epe_rec.pgm_id));
7021         fnd_message.set_token('PLAN_ID',to_char(l_global_epe_rec.pl_id));
7022         fnd_message.set_token('OIPL_ID',to_char(l_global_epe_rec.oipl_id));
7023         fnd_message.raise_error;
7024       end if; -- date is null
7025       if g_debug then
7026         hr_utility.set_location(l_proc, 170);
7027       end if;
7028       if (nvl(l_old_bnft_val,hr_api.g_number)<>
7029              nvl(l_global_enb_rec.val,hr_api.g_number)
7030          -- Bug#1807450 added and condition
7031           and p_prtt_enrt_rslt_id is not null) or
7032          -- Added for Interim Coverage /*ENH*/
7033          ben_sspndd_enrollment.g_use_new_result  or
7034          (l_global_epe_rec.crntly_enrd_flag = 'Y' and
7035              p_prtt_enrt_rslt_id is null) or  -- bug#5105122-called from backout
7036          l_start_new_result  then
7037         l_bnft_amt_changed:= TRUE;
7038         ben_determine_date.rate_and_coverage_dates
7039               (p_which_dates_cd         => 'C'
7040               ,p_business_group_id      => l_global_epe_rec.business_group_id
7041               ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
7042    --           ,p_enrt_cvg_strt_dt       => l_global_epe_rec.enrt_cvg_strt_dt
7043               ,p_enrt_cvg_strt_dt       =>l_enrt_cvg_strt_dt
7044               ,p_enrt_cvg_strt_dt_cd    => l_xenrt_cvg_strt_dt_cd
7045               ,p_enrt_cvg_strt_dt_rl    => l_xenrt_cvg_strt_dt_rl
7046               ,p_rt_strt_dt             => l_xrt_strt_dt
7047               ,p_rt_strt_dt_cd          => l_xrt_strt_dt_cd
7048               ,p_rt_strt_dt_rl          => l_xrt_strt_dt_rl
7049               ,p_enrt_cvg_end_dt        => l_xenrt_cvg_end_dt
7050               ,p_enrt_cvg_end_dt_cd     => l_xenrt_cvg_end_dt_cd
7051               ,p_enrt_cvg_end_dt_rl     => l_xenrt_cvg_end_dt_rl
7052               ,p_rt_end_dt              => l_xrt_end_dt
7053               ,p_rt_end_dt_cd           => l_xrt_end_dt_cd
7054               ,p_rt_end_dt_rl           => l_xrt_end_dt_rl
7055               ,p_acty_base_rt_id        => null
7056               ,p_effective_date         => p_effective_date
7057               /* Start of Changes for WWBUG: 2141172: added line                */
7058               ,p_lf_evt_ocrd_dt         => l_global_pil_rec.lf_evt_ocrd_dt
7059               /* End of Changes for WWBUG: 2141172: added line                  */
7060         );
7061         -- if there is any waiting period, the start date returned above override the coverage
7062         -- start date arrived in the benmngle - bug#1807450
7063         --
7064        hr_utility.set_location( 'l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,444);
7065        hr_utility.set_location( 'l_enrt_cvg_strt_dt'||l_enrt_cvg_strt_dt,444);
7066         if l_enrt_cvg_strt_dt > l_global_epe_rec.enrt_cvg_strt_dt then
7067            l_global_epe_rec.enrt_cvg_strt_dt := l_enrt_cvg_strt_dt;
7068         end if;
7069         --
7070       end if;
7071       --
7072       if l_global_epe_rec.enrt_cvg_strt_dt_cd = 'ENTRBL' and
7073          p_enrt_cvg_strt_dt is not null then
7074         l_global_epe_rec.enrt_cvg_strt_dt := p_enrt_cvg_strt_dt;
7075       end if;
7076       --
7077       --
7078       -- if staying in same plan use the old original enrt date
7079       --
7080       if (l_old_pl_id=l_global_epe_rec.pl_id) then
7081         l_orgnl_enrt_dt:=l_old_orgnl_enrt_dt;
7082           -- Bug 3602579 - now check if previous enrollment was in waive option
7083          if l_old_oipl_id is not null and l_global_epe_rec.oipl_id is not null then
7084             hr_utility.set_location( 'Into the new clause l_old_oipl_id '|| l_old_oipl_id ,999);
7085             hr_utility.set_location( 'Into the new clause l_global_epe_rec.oipl_id '|| l_global_epe_rec.oipl_id ,999);
7086            if (l_old_oipl_id <> l_global_epe_rec.oipl_id) then
7087                hr_utility.set_location( 'Into the new clause ',999);
7088                -- check if old oipl is waive.
7089                open c_wv_opt (l_old_oipl_id);
7090                fetch c_wv_opt into l_wv_flag ;
7091                close  c_wv_opt ;
7092                hr_utility.set_location( 'Into the new clause l_wv_flag '|| l_wv_flag ,999);
7093                if nvl(l_wv_flag,'N') = 'Y' then
7094                   l_wv_flag := 'N' ;
7095                   l_orgnl_enrt_dt := l_global_epe_rec.enrt_cvg_strt_dt;
7096                end if ;
7097            end if ;
7098          end if ;
7099       else
7100         l_orgnl_enrt_dt:=l_global_epe_rec.enrt_cvg_strt_dt;
7101       end if;
7102       --
7103       hr_utility.set_location( 'l_global_pil_rec.lf_evt_ocrd_dt '|| l_global_pil_rec.lf_evt_ocrd_dt ,999);
7104 
7105       -- create the enrolment result
7106       if l_global_epe_rec.ptip_id is not null then
7107         ben_cobj_cache.get_ptip_dets
7108           (p_business_group_id => p_business_group_id
7109           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
7110           ,p_ptip_id           => l_global_epe_rec.ptip_id
7111           ,p_inst_row          => l_ptip_rec);
7112       end if;
7113       if l_global_epe_rec.plip_id is not null then
7114         ben_cobj_cache.get_plip_dets
7115           (p_business_group_id => p_business_group_id
7116           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
7117           ,p_plip_id           => l_global_epe_rec.plip_id
7118           ,p_inst_row          => l_plip_rec);
7119       end if;
7120       if l_global_epe_rec.oipl_id is not null then
7121         ben_cobj_cache.get_oipl_dets
7122            (p_business_group_id => p_business_group_id
7123            ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
7124            ,p_oipl_id           => l_global_epe_rec.oipl_id
7125            ,p_inst_row          => l_oipl_rec);
7126       end if;
7127       if l_global_epe_rec.pl_id is not null then
7128         ben_cobj_cache.get_pl_dets
7129           (p_business_group_id => p_business_group_id
7130           ,p_effective_date    => l_global_pil_rec.lf_evt_ocrd_dt --Bug 6503304
7131           ,p_pl_id             => l_global_epe_rec.pl_id
7132           ,p_inst_row          => l_pl_rec);
7133       end if;
7134   --
7135   -- unrestricted changes
7136 
7137      if p_prtt_enrt_rslt_id is not null then
7138         l_datetrack_mode := hr_api.g_update;
7139      else
7140         l_datetrack_mode := p_datetrack_mode;
7141      end if;
7142      -- Bug 2172036 pass assignment_id also to create pen
7143      -- cursor moved 4510798
7144      --open c_epe ;
7145      --fetch c_epe into l_assignment_id;
7146      --close c_epe ;
7147      if g_debug then
7148        hr_utility.set_location( 'l_assignment_id '||l_assignment_id,12);
7149        hr_utility.set_location( 'l_global_epe_rec.enrt_cvg_strt_dt'||l_global_epe_rec.enrt_cvg_strt_dt,12);
7150      end if;
7151      --
7152      --  Bug 7206471. Check if the coverage should be adjusted.
7153     --
7154     /* Bug 8945818 */
7155     open c_prev_per_in_ler;
7156     fetch c_prev_per_in_ler into l_prev_pil_id;
7157     close c_prev_per_in_ler;
7158     /* End of Bug 8945818 */
7159 
7160     open c_get_prior_per_in_ler(l_global_epe_rec.enrt_cvg_strt_dt);
7161     fetch c_get_prior_per_in_ler into l_exists;
7162     if c_get_prior_per_in_ler%found then
7163   --
7164      for l_pgm in c_get_pgm loop
7165       --
7166       open c_get_pgm_extra_info_cvg(l_pgm.pgm_id);
7167       fetch c_get_pgm_extra_info_cvg into l_cvg_adjust;
7168       if c_get_pgm_extra_info_cvg%found then
7169         --
7170         if l_cvg_adjust = 'Y' then
7171           --
7172 	  hr_utility.set_location('l_cvg_adjust '||l_cvg_adjust,44333);
7173 	  --
7174           --  Get cvg end dt
7175 	  -- for l_get_elctbl_chc_for_cvg in c_get_elctbl_chc_for_cvg loop -- Bug 8507247
7176 	  --
7177           --  Get all results that were de-enrolled for the event.
7178 	  --
7179 	  /*Added for Bug 8507247*/
7180 	  open c_get_ptip_id;
7181 	  fetch c_get_ptip_id into l_ptip_id;
7182 	  close c_get_ptip_id;
7183 	  /*End of Bug 8507247*/
7184           for l_get_enrt_rslts_for_pen in c_get_enrt_rslts_for_pen(l_global_epe_rec.enrt_cvg_strt_dt
7185                                        ,l_ptip_id ) loop
7186               hr_utility.set_location('Adjusting Coverage for '||l_global_epe_rec.enrt_cvg_strt_dt,44333);
7187               --
7188 	      open c_prtt_enrt_rslt_adj(l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id);
7189               fetch c_prtt_enrt_rslt_adj into l_exists;
7190               if c_prtt_enrt_rslt_adj%notfound then
7191                 insert into BEN_LE_CLSN_N_RSTR (
7192                         BKUP_TBL_TYP_CD,
7193                         BKUP_TBL_ID,
7194                         per_in_ler_id,
7195                         person_id,
7196                         ENRT_CVG_THRU_DT,
7197                         business_group_id,
7198                         object_version_number)
7199                       values (
7200                         'BEN_PRTT_ENRT_RSLT_F_ADJ',
7201                         l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id,
7202                         l_get_enrt_rslts_for_pen.pil_id,
7203                         l_get_enrt_rslts_for_pen.person_id,
7204                         l_get_enrt_rslts_for_pen.enrt_cvg_thru_dt,
7205                         p_business_group_id,
7206                         l_get_enrt_rslts_for_pen.object_version_number
7207                       );
7208               end if;
7209               close c_prtt_enrt_rslt_adj;
7210                --
7211 	        ben_prtt_enrt_result_api.update_prtt_enrt_result
7212                (p_validate                 => FALSE,
7213                p_prtt_enrt_rslt_id        => l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id,
7214                p_effective_start_date     => l_effective_start_date,
7215                p_effective_end_date       => l_effective_end_date,
7216                p_business_group_id        => p_business_group_id,
7217                p_object_version_number    => l_get_enrt_rslts_for_pen.object_version_number,
7218                p_effective_date           => l_get_enrt_rslts_for_pen.effective_start_date,--p_effective_date,
7219 	                                     /*Bug 9057101: Instead of passing p_effective_date, pass
7220 					      effective start date of the pen_id*/
7221                p_datetrack_mode           => hr_api.g_correction,
7222                p_multi_row_validate       => FALSE,
7223 	       p_enrt_cvg_thru_dt         => l_global_epe_rec.enrt_cvg_strt_dt - 1 -- Bug 8507247
7224                );
7225             end loop;  -- c_get_enrt_rslts_for_pen
7226          -- end loop; -- c_get_elctbl_chc_for_cvg  -- Bug 8507247
7227         end if;  -- l_cvg_adjust = 'Y'
7228       end if;  -- c_get_pgm_extra_info_cvg
7229       close c_get_pgm_extra_info_cvg;
7230     end loop; -- c_get_pgm
7231     end if;
7232     close c_get_prior_per_in_ler;
7233     --
7234     -- End bug 7206471
7235     --
7236 	-----------------------------------------------------------------------
7237 --Bug 13444556 changes start
7238 open c_get_prior_per_in_ler_1(l_global_epe_rec.enrt_cvg_strt_dt);
7239   fetch c_get_prior_per_in_ler_1 into l_exists_1;
7240     if c_get_prior_per_in_ler_1%found then
7241   --
7242       hr_utility.set_location('uxx have cvg thru date after present start',44332);
7243       for l_pgm in c_get_pgm loop
7244       --
7245       open c_get_pgm_extra_info_cvg(l_pgm.pgm_id);
7246         fetch c_get_pgm_extra_info_cvg into l_cvg_adjust;
7247           if c_get_pgm_extra_info_cvg%found then
7248         --
7249           hr_utility.set_location('l_cvg_adjust '||l_cvg_adjust,44332);
7250             if l_cvg_adjust = 'Y' then
7251           --
7252 	            hr_utility.set_location('l_cvg_adjust '||l_cvg_adjust,44333);
7253             --
7254 	          open c_get_ptip_id;
7255 	          fetch c_get_ptip_id into l_ptip_id;
7256 	          close c_get_ptip_id;
7257 
7258             for l_get_enrt_rslts_for_pen in c_get_enrt_rslts_for_pen(l_global_epe_rec.enrt_cvg_strt_dt
7259                                        ,l_ptip_id ) loop
7260               hr_utility.set_location('uxx Adjusting Coverage for '||l_global_epe_rec.enrt_cvg_strt_dt,10);
7261               --
7262               --
7263 	        ben_prtt_enrt_result_api.update_prtt_enrt_result
7264                (p_validate                 => FALSE,
7265                p_prtt_enrt_rslt_id        => l_get_enrt_rslts_for_pen.prtt_enrt_rslt_id,
7266                p_effective_start_date     => l_effective_start_date,
7267                p_effective_end_date       => l_effective_end_date,
7268                p_business_group_id        => p_business_group_id,
7269                p_object_version_number    => l_get_enrt_rslts_for_pen.object_version_number,
7270                p_effective_date           => l_get_enrt_rslts_for_pen.effective_start_date,--p_effective_date,
7271                p_datetrack_mode           => hr_api.g_correction,
7272                p_multi_row_validate       => FALSE,
7273 	           p_enrt_cvg_thru_dt         => l_global_epe_rec.enrt_cvg_strt_dt - 1
7274                );
7275             end loop;  -- c_get_enrt_rslts_for_pen
7276          -- end loop; -- c_get_elctbl_chc_for_cvg
7277         end if;  -- l_cvg_adjust = 'Y'
7278       end if;  -- c_get_pgm_extra_info_cvg
7279       close c_get_pgm_extra_info_cvg;
7280     end loop; -- c_get_pgm
7281     end if;
7282     close c_get_prior_per_in_ler_1;
7283 --Bug 13444556 changes end
7284 -------------------------------------------------------------------------------
7285     -----Bug 8596122
7286     hr_utility.set_location('l_global_epe_rec.enrt_cvg_strt_dt : '||l_global_epe_rec.enrt_cvg_strt_dt,1);
7287     open c_prev_pil(l_global_pil_rec.person_id);
7288     fetch c_prev_pil into l_prev_pil;
7289     if c_prev_pil%found then
7290        hr_utility.set_location('prev pil Id : '||l_prev_pil.per_in_ler_id,1);
7291        hr_utility.set_location('l_global_epe_rec.pl_id : '||l_global_epe_rec.pl_id,1);
7292        hr_utility.set_location('l_global_epe_rec.oipl_id : '||l_global_epe_rec.oipl_id,1);
7293        open c_check_int_enr(l_prev_pil.per_in_ler_id,l_global_epe_rec.pgm_id,l_global_epe_rec.pl_id,l_global_epe_rec.oipl_id);
7294        fetch c_check_int_enr into l_check_int_enr;
7295        if c_check_int_enr%found then
7296 	  ben_determine_date.rate_and_coverage_dates
7297               (p_which_dates_cd         => 'C'
7298               ,p_business_group_id      => l_global_epe_rec.business_group_id
7299               ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
7300               ,p_enrt_cvg_strt_dt       => l_global_epe_rec.enrt_cvg_strt_dt
7301               ,p_enrt_cvg_strt_dt_cd    => l_yenrt_cvg_strt_dt_cd
7302               ,p_enrt_cvg_strt_dt_rl    => l_yenrt_cvg_strt_dt_rl
7303               ,p_rt_strt_dt             => l_yrt_strt_dt
7304               ,p_rt_strt_dt_cd          => l_yrt_strt_dt_cd
7305               ,p_rt_strt_dt_rl          => l_yrt_strt_dt_rl
7306               ,p_enrt_cvg_end_dt        => l_yenrt_cvg_end_dt
7307               ,p_enrt_cvg_end_dt_cd     => l_yenrt_cvg_end_dt_cd
7308               ,p_enrt_cvg_end_dt_rl     => l_yenrt_cvg_end_dt_rl
7309               ,p_rt_end_dt              => l_yrt_end_dt
7310               ,p_rt_end_dt_cd           => l_yrt_end_dt_cd
7311               ,p_rt_end_dt_rl           => l_yrt_end_dt_rl
7312               ,p_acty_base_rt_id        => null
7313               ,p_effective_date         => p_effective_date
7314               ,p_lf_evt_ocrd_dt         => l_global_pil_rec.lf_evt_ocrd_dt
7315         );
7316 	 hr_utility.set_location('l_global_epe_rec.enrt_cvg_strt_dt : '||l_global_epe_rec.enrt_cvg_strt_dt,1);
7317 	  hr_utility.set_location('int enr found',1);
7318        end if;
7319        close c_check_int_enr;
7320     end if;
7321     close c_prev_pil;
7322      --
7323      hr_utility.set_location('l_prtt_enrt_rslt_id: '||l_prtt_enrt_rslt_id,1);
7324      hr_utility.set_location('l_enrt_cvg_strt_dt: '||l_enrt_cvg_strt_dt,1);
7325      hr_utility.set_location('p_prtt_enrt_rslt_id: '||p_prtt_enrt_rslt_id,1);
7326      hr_utility.set_location('p_elig_per_elctbl_chc_id: '||p_elig_per_elctbl_chc_id,1);
7327      hr_utility.set_location('p_called_from sspnd: '||p_called_from_sspnd,1);
7328      hr_utility.set_location('l_prtt_enrt_interim_id : '||l_prtt_enrt_interim_id,1);
7329      hr_utility.set_location('l_curr_enrt_cvg_strt_dt: '||l_curr_enrt_cvg_strt_dt,2);
7330     ------Bug 8596122
7331       ben_PRTT_ENRT_RESULT_api.create_enrollment
7332         (p_prtt_enrt_rslt_id              =>  l_prtt_enrt_rslt_id
7333         ,P_prtt_enrt_rslt_id_o            =>  p_prtt_enrt_rslt_id
7334         ,p_elig_per_elctbl_chc_id         =>  p_elig_per_elctbl_chc_id
7335         ,p_assignment_id                  =>  l_assignment_id  --Bug 2172036
7336         ,p_effective_start_date           =>  p_effective_start_date
7337         ,p_effective_end_date             =>  p_effective_end_date
7338         ,p_pgm_id                         =>  l_global_epe_rec.pgm_id
7339         ,p_ptip_id                        =>  l_global_epe_rec.ptip_id
7340         ,p_pl_typ_id                      =>  l_global_epe_rec.pl_typ_id
7341         ,p_pl_id                          =>  l_global_epe_rec.pl_id
7342         ,p_oipl_id                        =>  l_global_epe_rec.oipl_id
7343         ,p_pl_ordr_num                    =>  l_pl_rec.ordr_num
7344         ,p_plip_ordr_num                  =>  l_plip_rec.ordr_num
7345         ,p_ptip_ordr_num                  =>  l_ptip_rec.ordr_num
7346         ,p_oipl_ordr_num                  =>  l_oipl_rec.ordr_num
7347         ,p_business_group_id              =>  l_global_epe_rec.business_group_id
7348         ,p_erlst_deenrt_dt                =>  l_global_epe_rec.erlst_deenrt_dt
7349         ,p_enrt_mthd_cd                   =>  p_enrt_mthd_cd
7350         --
7351         -- derive from per_in_ler_id
7352         --
7353         ,p_ler_id                         =>  l_global_pil_rec.ler_id
7354         ,p_person_id                      =>  l_global_pil_rec.person_id
7355         ,p_per_in_ler_id                  =>  l_global_epe_rec.per_in_ler_id
7356         ,p_bnft_amt                     =>  l_global_enb_rec.val
7357         ,p_uom                          =>  l_global_pel_rec.uom
7358         ,p_bnft_nnmntry_uom             =>  l_global_enb_rec.nnmntry_uom
7359         ,p_comp_lvl_cd                  =>  l_global_epe_rec.comp_lvl_cd
7360         ,p_bnft_typ_cd                  =>  l_global_enb_rec.bnft_typ_cd
7361         ,p_bnft_ordr_num                =>  l_global_enb_rec.ordr_num
7362         ,p_enrt_cvg_strt_dt             =>  l_global_epe_rec.enrt_cvg_strt_dt
7363         ,p_orgnl_enrt_dt                =>  l_orgnl_enrt_dt
7364         ,p_object_version_number        =>  l_object_version_number
7365         ,p_effective_date               =>  p_effective_date
7366         ,p_suspend_flag                 =>  p_suspend_flag
7367         ,p_called_from_sspnd            => p_called_from_sspnd
7368         ,p_prtt_enrt_interim_id         =>  l_prtt_enrt_interim_id
7369         ,p_datetrack_mode               =>  l_datetrack_mode
7370         ,p_multi_row_validate           => FALSE
7371         ,p_program_application_id       => fnd_global.prog_appl_id
7372         ,p_program_id                   => fnd_global.conc_program_id
7373         ,p_request_id                   => fnd_global.conc_request_id
7374         ,p_program_update_date          => sysdate
7375          -- Bug #2714383
7376       -- Passing null if the attribute value is $Sys_Def$
7377         ,p_pen_attribute_category       => decd_attribute(p_pen_attribute_category)
7378         ,p_pen_attribute1               => decd_attribute(p_pen_attribute1)
7379         ,p_pen_attribute2               => decd_attribute(p_pen_attribute2)
7380         ,p_pen_attribute3               => decd_attribute(p_pen_attribute3)
7381         ,p_pen_attribute4               => decd_attribute(p_pen_attribute4)
7382         ,p_pen_attribute5               => decd_attribute(p_pen_attribute5)
7383         ,p_pen_attribute6               => decd_attribute(p_pen_attribute6)
7384         ,p_pen_attribute7               => decd_attribute(p_pen_attribute7)
7385         ,p_pen_attribute8               => decd_attribute(p_pen_attribute8)
7386         ,p_pen_attribute9               => decd_attribute(p_pen_attribute9)
7387         ,p_pen_attribute10              => decd_attribute(p_pen_attribute10)
7388         ,p_pen_attribute11              => decd_attribute(p_pen_attribute11)
7389         ,p_pen_attribute12              => decd_attribute(p_pen_attribute12)
7390         ,p_pen_attribute13              => decd_attribute(p_pen_attribute13)
7391         ,p_pen_attribute14              => decd_attribute(p_pen_attribute14)
7392         ,p_pen_attribute15              => decd_attribute(p_pen_attribute15)
7393         ,p_pen_attribute16              => decd_attribute(p_pen_attribute16)
7394         ,p_pen_attribute17              => decd_attribute(p_pen_attribute17)
7395         ,p_pen_attribute18              => decd_attribute(p_pen_attribute18)
7396         ,p_pen_attribute19              => decd_attribute(p_pen_attribute19)
7397         ,p_pen_attribute20              => decd_attribute(p_pen_attribute20)
7398         ,p_pen_attribute21              => decd_attribute(p_pen_attribute21)
7399         ,p_pen_attribute22              => decd_attribute(p_pen_attribute22)
7400         ,p_pen_attribute23              => decd_attribute(p_pen_attribute23)
7401         ,p_pen_attribute24              => decd_attribute(p_pen_attribute24)
7402         ,p_pen_attribute25              => decd_attribute(p_pen_attribute25)
7403         ,p_pen_attribute26              => decd_attribute(p_pen_attribute26)
7404         ,p_pen_attribute27              => decd_attribute(p_pen_attribute27)
7405         ,p_pen_attribute28              => decd_attribute(p_pen_attribute28)
7406         ,p_pen_attribute29              => decd_attribute(p_pen_attribute29)
7407         ,p_pen_attribute30              => decd_attribute(p_pen_attribute30)
7408         ,p_dpnt_actn_warning            => l_dpnt_actn_warning
7409         ,p_bnf_actn_warning             => l_bnf_actn_warning
7410         ,p_ctfn_actn_warning            => l_ctfn_actn_warning
7411         ,p_enrt_bnft_id                 => p_enrt_bnft_id
7412         ,p_source                       => 'benelinf'
7413       );
7414         if g_debug then
7415           hr_utility.set_location( 'l_global_epe_rec.erlst_deenrt_dt'||l_global_epe_rec.erlst_deenrt_dt,1233);
7416           hr_utility.set_location( 'l_global_epe_rec.per_in_ler_id'||l_global_epe_rec.per_in_ler_id,1233);
7417           hr_utility.set_location( 'l_prtt_enrt_rslt_id '||l_prtt_enrt_rslt_id,1233);
7418           hr_utility.set_location( 'p_prtt_enrt_rslt_id '||p_prtt_enrt_rslt_id,1233);
7419           hr_utility.set_location( 'p_datetrack_mode '||p_datetrack_mode,1233);
7420           hr_utility.set_location( 'p_effective_date '||p_effective_date,1233);
7421         end if;
7422         --
7423         -- write to the change event log.  thayden.  such a mess!
7424         --
7425         if l_global_epe_rec.pl_id <> nvl(l_old_pl_id,l_global_epe_rec.pl_id) or
7426            l_global_epe_rec.oipl_id <>
7427            nvl(l_old_oipl_id,l_global_epe_rec.oipl_id) then
7428           ben_ext_chlg.log_benefit_chg
7429           (p_action                      =>  'UPDATE' --plan and option changes
7430           ,p_pl_id                       =>  l_global_epe_rec.pl_id
7431           ,p_old_pl_id                   =>  l_old_pl_id
7432           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
7433           ,p_old_oipl_id                 =>  l_old_oipl_id
7434           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
7435           ,p_old_enrt_cvg_strt_dt        =>  l_old_enrt_cvg_strt_dt
7436           ,p_old_enrt_cvg_end_dt         =>  l_old_enrt_cvg_thru_dt
7437           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
7438           ,p_old_prtt_enrt_rslt_id       =>  p_prtt_enrt_rslt_id
7439           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
7440           ,p_old_per_in_ler_id           =>  l_old_per_in_ler_id
7441           ,p_person_id                   =>  l_global_pil_rec.person_id
7442           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
7443           ,p_effective_date              =>  p_effective_date
7444           );
7445         else
7446           ben_ext_chlg.log_benefit_chg
7447           (p_action                      =>  'CREATE'  -- new enrollment
7448           ,p_pl_id                       =>  l_global_epe_rec.pl_id
7449           ,p_old_pl_id                   =>  l_old_pl_id
7450           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
7451           ,p_old_oipl_id                 =>  l_old_oipl_id
7452           ,p_old_bnft_amt                =>  l_old_bnft_val
7453           ,p_bnft_amt                    =>  l_global_enb_rec.val
7454           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
7455           ,p_enrt_cvg_end_dt             =>  hr_api.g_eot  --?
7456           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
7457           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
7458           ,p_person_id                   =>  l_global_pil_rec.person_id
7459           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
7460           ,p_effective_date              =>  p_effective_date
7461           );
7462         end if;
7463         --
7464         ben_ext_chlg.log_benefit_chg
7465           (p_action                      =>  l_action
7466           ,p_pl_id                       =>  l_global_epe_rec.pl_id
7467           ,p_old_pl_id                   =>  l_old_pl_id
7468           ,p_oipl_id                     =>  l_global_epe_rec.oipl_id
7469           ,p_old_oipl_id                 =>  l_old_oipl_id
7470           ,p_enrt_cvg_strt_dt            =>  l_global_epe_rec.enrt_cvg_strt_dt
7471           ,p_old_enrt_cvg_strt_dt        =>  l_old_enrt_cvg_strt_dt
7472           ,p_old_enrt_cvg_end_dt         =>  l_old_enrt_cvg_thru_dt
7473           ,p_prtt_enrt_rslt_id           =>  l_prtt_enrt_rslt_id
7474           ,p_old_prtt_enrt_rslt_id       =>  p_prtt_enrt_rslt_id
7475           ,p_per_in_ler_id               =>  l_global_epe_rec.per_in_ler_id
7476           ,p_person_id                   =>  l_global_pil_rec.person_id
7477           ,p_business_group_id           =>  l_global_epe_rec.business_group_id
7478           ,p_effective_date              =>  p_effective_date
7479           );
7480 
7481       p_prtt_enrt_interim_id:=l_prtt_enrt_interim_id;
7482       --
7483     end if;
7484     --
7485     if g_debug then
7486       hr_utility.set_location(l_proc, 330);
7487     end if;
7488     --
7489     if p_prtt_enrt_rslt_id is not null -- and
7490        -- l_use_new_result=false then
7491        -- ben_sspndd_enrollment.g_use_new_result=false) Bug 2543071 Needs to delete if the interim
7492        -- is the old enrollment.We create a new enrollment for interim.
7493        or l_start_new_result then /*ENH*/
7494       --
7495       -- If the old enrollment is now the interim coverage
7496       -- then don't end it, leave it be.
7497       --
7498       hr_utility.set_location('ben_sspndd_enrollment.g_sspnded_rslt_id ' || ben_sspndd_enrollment.g_sspnded_rslt_id, 1212);
7499       hr_utility.set_location('l_prtt_enrt_interim_id ' || l_prtt_enrt_interim_id, 1212);
7500       hr_utility.set_location('p_prtt_enrt_rslt_id ' || p_prtt_enrt_rslt_id, 1212);
7501       if (l_prtt_enrt_interim_id is null or
7502          l_prtt_enrt_interim_id <> p_prtt_enrt_rslt_id)
7503          -- 6337803
7504          and p_prtt_enrt_rslt_id <> nvl(ben_sspndd_enrollment.g_sspnded_rslt_id,-1)
7505          then
7506         --
7507         -- deenrol
7508         --
7509         if g_debug then
7510           hr_utility.set_location(l_proc, 115);
7511         end if;
7512         if g_debug then
7513           hr_utility.set_location( 'p_datetrack_mode '||p_datetrack_mode,1234);
7514         end if;
7515         if g_debug then
7516           hr_utility.set_location( 'p_effective_date '||p_effective_date,1234);
7517         end if;
7518         -- Bug 2627078 fixes
7519         -- Don't try to delete if the result is already got deleted by the earlier
7520         -- process.
7521         open c_pen_exists(p_prtt_enrt_rslt_id);
7522         fetch c_pen_exists into l_dummy_char ;
7523         if c_pen_exists%found then
7524           --
7525           ben_PRTT_ENRT_RESULT_api.delete_enrollment(
7526              p_prtt_enrt_rslt_id          => p_prtt_enrt_rslt_id
7527             ,p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id
7528             ,p_business_group_id          => l_global_epe_rec.business_group_id
7529             ,p_effective_start_date       => p_effective_start_date
7530             ,p_effective_end_date         => p_effective_end_date
7531             ,p_object_version_number      => p_object_version_number
7532             ,p_effective_date             => p_effective_date
7533             ,p_datetrack_mode             => nvl(l_datetrack_mode, p_datetrack_mode) /*2483991*/
7534             ,p_multi_row_validate         => FALSE
7535             ,p_source                     => 'benelinf'
7536             ,p_lee_rsn_id                 => l_global_pel_rec.lee_rsn_id
7537             ,p_enrt_perd_id               => l_global_pel_rec.enrt_perd_id
7538           );
7539           --
7540           -- after delete enrollment the fonm flag back
7541           -- when the plan replcaed  the dele_enroll might have reset the fonm flag
7542           ben_manage_life_events.fonm := l_fonm_flag ;
7543           ben_manage_life_events.g_fonm_cvg_strt_dt := l_fonm_cvg_strt_dt;
7544 
7545           hr_utility.set_location (' aftr del_enrl  FONM ' ||  ben_manage_life_events.fonm , 99 ) ;
7546           hr_utility.set_location (' FONM CVG  ' ||  ben_manage_life_events.g_fonm_cvg_strt_dt , 99 ) ;
7547 
7548 
7549         end if;
7550         --
7551         close c_pen_exists ;
7552         if g_debug then
7553           hr_utility.set_location(l_proc, 109);
7554         end if;
7555       end if;
7556       if g_debug then
7557         hr_utility.set_location(l_proc, 110);
7558       end if;
7559       -- 6337803 unsetting the pen id to be suspended
7560       ben_sspndd_enrollment.g_sspnded_rslt_id := null;
7561       --
7562     end if;
7563     --
7564     -- For the create return the new ovn
7565     --
7566     p_object_version_number:=l_object_version_number;
7567   end if;
7568   if g_debug then
7569     hr_utility.set_location(l_proc, 340);
7570   end if;
7571 
7572   p_prtt_enrt_rslt_id:=l_prtt_enrt_rslt_id;
7573 
7574   -- update, create and delete enrolloment may all change the enrt_bnft row.
7575   if p_enrt_bnft_id is not null then
7576      ben_global_enrt.get_enb -- enrt bnft  --CHANGE TO RELOAD_ENB if it's created.
7577         (p_enrt_bnft_id           => p_enrt_bnft_id
7578         ,p_global_enb_rec         => l_global_enb_rec);
7579   else ben_global_enrt.clear_enb
7580         (p_global_enb_rec         => l_global_enb_rec);
7581   end if;
7582 
7583   -- update benefit fk in enrt_bnft
7584   if g_debug then
7585     hr_utility.set_location(l_proc, 342);
7586   end if;
7587   manage_enrt_bnft(
7588         p_enrt_bnft_id               => p_enrt_bnft_id,
7589         p_effective_date             => p_effective_date,
7590         p_object_version_number      => l_global_enb_rec.object_version_number,
7591         p_business_group_id          => p_business_group_id,
7592         p_prtt_enrt_rslt_id          => l_prtt_enrt_rslt_id,
7593         p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id,
7594         p_creation_date              => null,
7595         p_created_by                 => null
7596   );
7597   if g_debug then
7598     hr_utility.set_location(l_proc, 346);
7599   end if;
7600 
7601   -- process all rates
7602 
7603   if p_enrt_rt_id1 is not null then
7604     if g_debug then
7605       hr_utility.set_location(l_proc, 350);
7606     end if;
7607     election_rate_information(
7608         p_enrt_mthd_cd            => p_enrt_mthd_cd,
7609         p_effective_date          => p_effective_date,
7610         p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
7611         p_per_in_ler_id           => l_global_epe_rec.per_in_ler_id,
7612         p_person_id               => l_global_pil_rec.person_id,
7613         p_pgm_id                  => l_global_epe_rec.pgm_id,
7614         p_pl_id                   => l_global_epe_rec.pl_id,
7615         p_oipl_id                 => l_global_epe_rec.oipl_id,
7616         p_enrt_rt_id              => p_enrt_rt_id1,
7617         p_prtt_rt_val_id          => p_prtt_rt_val_id1,
7618         p_rt_val                  => p_rt_val1,
7619         p_ann_rt_val              => p_ann_rt_val1,
7620         p_enrt_cvg_strt_dt        => l_global_epe_rec.enrt_cvg_strt_dt,
7621         p_acty_ref_perd_cd        => l_global_pel_rec.acty_ref_perd_cd,
7622         p_datetrack_mode          => p_datetrack_mode,
7623         p_business_group_id       => p_business_group_id,
7624         p_bnft_amt_changed        => l_bnft_amt_changed,
7625         p_rt_strt_dt              => p_rt_strt_dt1,
7626         p_rt_end_dt               => p_rt_end_dt1,
7627         --
7628         p_prv_rt_val              => l_dummy_number,
7629         p_prv_ann_rt_val          => l_dummy_number,
7630         p_imp_cvg_strt_dt         => p_imp_cvg_strt_dt); -- 8716870
7631     if g_debug then
7632       hr_utility.set_location(l_proc, 360);
7633     end if;
7634   end if;
7635 
7636   if g_debug then
7637     hr_utility.set_location(l_proc, 370);
7638   end if;
7639 
7640   if p_enrt_rt_id2 is not null then
7641     if g_debug then
7642       hr_utility.set_location(l_proc, 380);
7643     end if;
7644     election_rate_information(
7645         p_enrt_mthd_cd           => p_enrt_mthd_cd,
7646         p_effective_date         => p_effective_date,
7647         p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id,
7648         p_per_in_ler_id          => l_global_epe_rec.per_in_ler_id,
7649         p_person_id              => l_global_pil_rec.person_id,
7650         p_pgm_id                 => l_global_epe_rec.pgm_id,
7651         p_pl_id                  => l_global_epe_rec.pl_id,
7652         p_oipl_id                => l_global_epe_rec.oipl_id,
7653         p_enrt_rt_id             => p_enrt_rt_id2,
7654         p_prtt_rt_val_id         => p_prtt_rt_val_id2,
7655         p_rt_val                 => p_rt_val2,
7656         p_ann_rt_val             => p_ann_rt_val2,
7657         p_enrt_cvg_strt_dt       => l_global_epe_rec.enrt_cvg_strt_dt,
7658         p_acty_ref_perd_cd       => l_global_pel_rec.acty_ref_perd_cd,
7659         p_datetrack_mode         => p_datetrack_mode,
7660         p_business_group_id      => p_business_group_id,
7661         p_bnft_amt_changed       => l_bnft_amt_changed,
7662         p_rt_strt_dt             => p_rt_strt_dt2,
7663         p_rt_end_dt              => p_rt_end_dt2,
7664         --
7665         p_prv_rt_val             => l_dummy_number,
7666         p_prv_ann_rt_val         => l_dummy_number,
7667         p_imp_cvg_strt_dt        => p_imp_cvg_strt_dt); -- 8716870
7668     if g_debug then
7669       hr_utility.set_location(l_proc, 390);
7670     end if;
7671   end if;
7672   if g_debug then
7673     hr_utility.set_location(l_proc, 395);
7674   end if;
7675 
7676 
7677   if p_enrt_rt_id3 is not null then
7678     if g_debug then
7679       hr_utility.set_location(l_proc, 400);
7680     end if;
7681     election_rate_information(
7682         p_enrt_mthd_cd            => p_enrt_mthd_cd,
7683         p_effective_date          => p_effective_date,
7684         p_prtt_enrt_rslt_id       => p_prtt_enrt_rslt_id,
7685         p_per_in_ler_id           => l_global_epe_rec.per_in_ler_id,
7686         p_person_id               => l_global_pil_rec.person_id,
7687         p_pgm_id                  => l_global_epe_rec.pgm_id,
7688         p_pl_id                   => l_global_epe_rec.pl_id,
7689         p_oipl_id                 => l_global_epe_rec.oipl_id,
7690         p_enrt_rt_id              => p_enrt_rt_id3,
7691         p_prtt_rt_val_id          => p_prtt_rt_val_id3,
7692         p_rt_val                  => p_rt_val3,
7693         p_ann_rt_val              => p_ann_rt_val3,
7694         p_enrt_cvg_strt_dt        => l_global_epe_rec.enrt_cvg_strt_dt,
7695         p_acty_ref_perd_cd        => l_global_pel_rec.acty_ref_perd_cd,
7696         p_datetrack_mode          => p_datetrack_mode,
7697         p_business_group_id       => p_business_group_id,
7698         p_bnft_amt_changed        => l_bnft_amt_changed,
7699         p_rt_strt_dt              => p_rt_strt_dt3,
7700         p_rt_end_dt               => p_rt_end_dt3,
7701         --
7702         p_prv_rt_val              => l_dummy_number,
7703         p_prv_ann_rt_val          => l_dummy_number,
7704         p_imp_cvg_strt_dt         => p_imp_cvg_strt_dt); -- 8716870
7705     if g_debug then
7706       hr_utility.set_location(l_proc, 410);
7707     end if;
7708   end if;
7709   if g_debug then
7710     hr_utility.set_location(l_proc, 420);
7711   end if;
7712 
7713 
7714   if p_enrt_rt_id4 is not null then
7715     if g_debug then
7716       hr_utility.set_location(l_proc, 430);
7717     end if;
7718     election_rate_information(
7719         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7720         p_effective_date           => p_effective_date,
7721         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7722         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7723         p_person_id                => l_global_pil_rec.person_id,
7724         p_pgm_id                   => l_global_epe_rec.pgm_id,
7725         p_pl_id                    => l_global_epe_rec.pl_id,
7726         p_oipl_id                  => l_global_epe_rec.oipl_id,
7727         p_enrt_rt_id               => p_enrt_rt_id4,
7728         p_prtt_rt_val_id           => p_prtt_rt_val_id4,
7729         p_rt_val                   => p_rt_val4,
7730         p_ann_rt_val               => p_ann_rt_val4,
7731         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7732         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7733         p_datetrack_mode           => p_datetrack_mode,
7734         p_business_group_id        => p_business_group_id,
7735         p_bnft_amt_changed         => l_bnft_amt_changed,
7736         p_rt_strt_dt               => p_rt_strt_dt4,
7737         p_rt_end_dt                => p_rt_end_dt4,
7738         --
7739         p_prv_rt_val               => l_dummy_number,
7740         p_prv_ann_rt_val           => l_dummy_number,
7741         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt); -- 8716870
7742     if g_debug then
7743       hr_utility.set_location(l_proc, 440);
7744     end if;
7745   end if;
7746   if g_debug then
7747     hr_utility.set_location(l_proc, 450);
7748   end if;
7749 
7750 
7751   if p_enrt_rt_id5 is not null then
7752     if g_debug then
7753       hr_utility.set_location(l_proc, 460);
7754     end if;
7755     election_rate_information(
7756         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7757         p_effective_date           => p_effective_date,
7758         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7759         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7760         p_person_id                => l_global_pil_rec.person_id,
7761         p_pgm_id                   => l_global_epe_rec.pgm_id,
7762         p_pl_id                    => l_global_epe_rec.pl_id,
7763         p_oipl_id                  => l_global_epe_rec.oipl_id,
7764         p_enrt_rt_id               => p_enrt_rt_id5,
7765         p_prtt_rt_val_id           => p_prtt_rt_val_id5,
7766         p_rt_val                   => p_rt_val5,
7767         p_ann_rt_val               => p_ann_rt_val5,
7768         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7769         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7770         p_datetrack_mode           => p_datetrack_mode,
7771         p_business_group_id        => p_business_group_id,
7772         p_bnft_amt_changed         => l_bnft_amt_changed,
7773         p_rt_strt_dt               => p_rt_strt_dt5,
7774         p_rt_end_dt                => p_rt_end_dt5,
7775         --
7776         p_prv_rt_val               => l_dummy_number,
7777         p_prv_ann_rt_val           => l_dummy_number,
7778         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt); -- 8716870
7779     if g_debug then
7780       hr_utility.set_location(l_proc, 470);
7781     end if;
7782   end if;
7783   if g_debug then
7784     hr_utility.set_location(l_proc, 480);
7785   end if;
7786 
7787 
7788   if p_enrt_rt_id6 is not null then
7789     if g_debug then
7790       hr_utility.set_location(l_proc, 490);
7791     end if;
7792     election_rate_information(
7793         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7794         p_effective_date           => p_effective_date,
7795         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7796         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7797         p_person_id                => l_global_pil_rec.person_id,
7798         p_pgm_id                   => l_global_epe_rec.pgm_id,
7799         p_pl_id                    => l_global_epe_rec.pl_id,
7800         p_oipl_id                  => l_global_epe_rec.oipl_id,
7801         p_enrt_rt_id               => p_enrt_rt_id6,
7802         p_prtt_rt_val_id           => p_prtt_rt_val_id6,
7803         p_rt_val                   => p_rt_val6,
7804         p_ann_rt_val               => p_ann_rt_val6,
7805         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7806         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7807         p_datetrack_mode           => p_datetrack_mode,
7808         p_business_group_id        => p_business_group_id,
7809         p_bnft_amt_changed         => l_bnft_amt_changed,
7810         p_rt_strt_dt               => p_rt_strt_dt6,
7811         p_rt_end_dt                => p_rt_end_dt6,
7812         --
7813         p_prv_rt_val               => l_dummy_number,
7814         p_prv_ann_rt_val           => l_dummy_number,
7815         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt); -- 8716870
7816     if g_debug then
7817       hr_utility.set_location(l_proc, 500);
7818     end if;
7819   end if;
7820   if g_debug then
7821     hr_utility.set_location(l_proc, 510);
7822   end if;
7823 
7824 
7825   if p_enrt_rt_id7 is not null then
7826     if g_debug then
7827       hr_utility.set_location(l_proc, 520);
7828     end if;
7829     election_rate_information(
7830         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7831         p_effective_date           => p_effective_date,
7832         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7833         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7834         p_person_id                => l_global_pil_rec.person_id,
7835         p_pgm_id                   => l_global_epe_rec.pgm_id,
7836         p_pl_id                    => l_global_epe_rec.pl_id,
7837         p_oipl_id                  => l_global_epe_rec.oipl_id,
7838         p_enrt_rt_id               => p_enrt_rt_id7,
7839         p_prtt_rt_val_id           => p_prtt_rt_val_id7,
7840         p_rt_val                   => p_rt_val7,
7841         p_ann_rt_val               => p_ann_rt_val7,
7842         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7843         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7844         p_datetrack_mode           => p_datetrack_mode,
7845         p_business_group_id        => p_business_group_id,
7846         p_bnft_amt_changed         => l_bnft_amt_changed,
7847         p_rt_strt_dt               => p_rt_strt_dt7,
7848         p_rt_end_dt                => p_rt_end_dt7,
7849         --
7850         p_prv_rt_val               => l_dummy_number,
7851         p_prv_ann_rt_val           => l_dummy_number,
7852         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt); -- 8716870
7853     if g_debug then
7854       hr_utility.set_location(l_proc, 530);
7855     end if;
7856   end if;
7857   if g_debug then
7858     hr_utility.set_location(l_proc, 540);
7859   end if;
7860 
7861 
7862   if p_enrt_rt_id8 is not null then
7863     if g_debug then
7864       hr_utility.set_location(l_proc, 550);
7865     end if;
7866     election_rate_information(
7867         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7868         p_effective_date           => p_effective_date,
7869         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7870         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7871         p_person_id                => l_global_pil_rec.person_id,
7872         p_pgm_id                   => l_global_epe_rec.pgm_id,
7873         p_pl_id                    => l_global_epe_rec.pl_id,
7874         p_oipl_id                  => l_global_epe_rec.oipl_id,
7875         p_enrt_rt_id               => p_enrt_rt_id8,
7876         p_prtt_rt_val_id           => p_prtt_rt_val_id8,
7877         p_rt_val                   => p_rt_val8,
7878         p_ann_rt_val               => p_ann_rt_val8,
7879         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7880         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7881         p_datetrack_mode           => p_datetrack_mode,
7882         p_business_group_id        => p_business_group_id,
7883         p_bnft_amt_changed         => l_bnft_amt_changed,
7884         p_rt_strt_dt               => p_rt_strt_dt8,
7885         p_rt_end_dt                => p_rt_end_dt8,
7886         --
7887         p_prv_rt_val               => l_dummy_number,
7888         p_prv_ann_rt_val           => l_dummy_number,
7889         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt); -- 8716870
7890     if g_debug then
7891       hr_utility.set_location(l_proc, 560);
7892     end if;
7893   end if;
7894   if g_debug then
7895     hr_utility.set_location(l_proc, 570);
7896   end if;
7897 
7898 
7899   if p_enrt_rt_id9 is not null then
7900     if g_debug then
7901       hr_utility.set_location(l_proc, 580);
7902     end if;
7903     election_rate_information(
7904         p_enrt_mthd_cd             => p_enrt_mthd_cd,
7905         p_effective_date           => p_effective_date,
7906         p_prtt_enrt_rslt_id        => p_prtt_enrt_rslt_id,
7907         p_per_in_ler_id            => l_global_epe_rec.per_in_ler_id,
7908         p_person_id                => l_global_pil_rec.person_id,
7909         p_pgm_id                   => l_global_epe_rec.pgm_id,
7910         p_pl_id                    => l_global_epe_rec.pl_id,
7911         p_oipl_id                  => l_global_epe_rec.oipl_id,
7912         p_enrt_rt_id               => p_enrt_rt_id9,
7913         p_prtt_rt_val_id           => p_prtt_rt_val_id9,
7914         p_rt_val                   => p_rt_val9,
7915         p_ann_rt_val               => p_ann_rt_val9,
7916         p_enrt_cvg_strt_dt         => l_global_epe_rec.enrt_cvg_strt_dt,
7917         p_acty_ref_perd_cd         => l_global_pel_rec.acty_ref_perd_cd,
7918         p_datetrack_mode           => p_datetrack_mode,
7919         p_business_group_id        => p_business_group_id,
7920         p_bnft_amt_changed         => l_bnft_amt_changed,
7921         p_rt_strt_dt               => p_rt_strt_dt9,
7922         p_rt_end_dt                => p_rt_end_dt9,
7923         --
7924         p_prv_rt_val               => l_dummy_number,
7925         p_prv_ann_rt_val           => l_dummy_number,
7926         p_imp_cvg_strt_dt          => p_imp_cvg_strt_dt);  -- 8716870
7927     if g_debug then
7928       hr_utility.set_location(l_proc, 590);
7929     end if;
7930   end if;
7931   if g_debug then
7932     hr_utility.set_location(l_proc, 600);
7933   end if;
7934 
7935 
7936   if p_enrt_rt_id10 is not null then
7937     if g_debug then
7938       hr_utility.set_location(l_proc, 610);
7939     end if;
7940     election_rate_information(
7941         p_enrt_mthd_cd              => p_enrt_mthd_cd,
7942         p_effective_date            => p_effective_date,
7943         p_prtt_enrt_rslt_id         => p_prtt_enrt_rslt_id,
7944         p_per_in_ler_id             => l_global_epe_rec.per_in_ler_id,
7945         p_person_id                 => l_global_pil_rec.person_id,
7946         p_pgm_id                    => l_global_epe_rec.pgm_id,
7947         p_pl_id                     => l_global_epe_rec.pl_id,
7948         p_oipl_id                   => l_global_epe_rec.oipl_id,
7949         p_enrt_rt_id                => p_enrt_rt_id10,
7950         p_prtt_rt_val_id            => p_prtt_rt_val_id10,
7951         p_rt_val                    => p_rt_val10,
7952         p_ann_rt_val                => p_ann_rt_val10,
7953         p_enrt_cvg_strt_dt          => l_global_epe_rec.enrt_cvg_strt_dt,
7954         p_acty_ref_perd_cd          => l_global_pel_rec.acty_ref_perd_cd,
7955         p_datetrack_mode            => p_datetrack_mode,
7956         p_business_group_id         => p_business_group_id,
7957         p_bnft_amt_changed          => l_bnft_amt_changed,
7958         p_rt_strt_dt                => p_rt_strt_dt10,
7959         p_rt_end_dt                 => p_rt_end_dt10,
7960         --
7961         p_prv_rt_val                => l_dummy_number,
7962         p_prv_ann_rt_val            => l_dummy_number,
7963         p_imp_cvg_strt_dt           => p_imp_cvg_strt_dt); -- 8716870
7964     if g_debug then
7965       hr_utility.set_location(l_proc, 620);
7966     end if;
7967   end if;
7968   --
7969   -- If the coverage through date has been passed in, it means we have to update
7970   -- the result record with the same.
7971   --
7972   if p_enrt_cvg_thru_dt is not null and
7973      p_prtt_enrt_rslt_id is not null then
7974      --
7975      -- If the result was created in the same run, then the mode will be insert.
7976      -- In this case, we can only do update in correction mode.
7977      --
7978      if p_datetrack_mode = hr_api.g_insert then
7979         l_datetrack_mode := hr_api.g_correction;
7980      else
7981         l_datetrack_mode := p_datetrack_mode;
7982      end if;
7983      --
7984      ben_PRTT_ENRT_RESULT_api.delete_enrollment(
7985         p_prtt_enrt_rslt_id          => p_prtt_enrt_rslt_id
7986        ,p_per_in_ler_id              => l_global_epe_rec.per_in_ler_id
7987        ,p_business_group_id          => l_global_epe_rec.business_group_id
7988        ,p_effective_start_date       => p_effective_start_date
7989        ,p_effective_end_date         => p_effective_end_date
7990        ,p_object_version_number      => p_object_version_number
7991        ,p_effective_date             => p_effective_date
7992        ,p_datetrack_mode             => p_datetrack_mode
7993        ,p_multi_row_validate         => FALSE
7994        ,p_source                     => 'benelinf'
7995        ,p_lee_rsn_id                 => l_global_pel_rec.lee_rsn_id
7996        ,p_enrt_perd_id               => l_global_pel_rec.enrt_perd_id
7997        ,p_enrt_cvg_thru_dt           => p_enrt_cvg_thru_dt
7998        ,p_mode                       => 'CVG_END_DATE_ENTERABLE'
7999      );
8000   end if;
8001   --
8002   ben_det_enrt_rates.set_global_enrt_rslt
8003      (p_prtt_enrt_rslt_id         => p_prtt_enrt_rslt_id);
8004   --
8005   -- Set the out parameters
8006   --
8007   p_dpnt_actn_warning := l_dpnt_actn_warning;
8008   p_bnf_actn_warning := l_bnf_actn_warning;
8009   p_ctfn_actn_warning := l_ctfn_actn_warning;
8010   --
8011   -- null globals to prevent bleeding
8012   --
8013   g_enrt_bnft_id:=null;
8014   g_bnft_val:=null;
8015   g_elig_per_elctbl_chc_id:=null;
8016   ben_global_enrt.clear_enb
8017        (p_global_enb_rec         => l_global_enb_rec);
8018   --
8019   -- When in validation only mode raise the Validate_Enabled exception
8020   --
8021   if p_validate then
8022     raise hr_api.validate_enabled;
8023   end if;
8024 
8025   if g_debug then
8026     hr_utility.set_location('Leaving:'||l_proc, 999);
8027   end if;
8028 
8029 exception
8030   --
8031   when hr_api.validate_enabled then
8032     --
8033     -- As the Validate_Enabled exception has been raised
8034     -- we must rollback to the savepoint
8035     --
8036     if p_called_from_sspnd = 'N' then
8037        ROLLBACK TO election_information_savepoint;
8038     else
8039        ROLLBACK TO election_information_sspnd;
8040     end if;
8041 
8042     --
8043     -- Only set output warning arguments
8044     -- (Any key or derived arguments must be set to null
8045     -- when validation only mode is being used.)
8046     --
8047     p_prtt_enrt_interim_id:=null;
8048    ben_sspndd_enrollment.g_use_new_result :=false  ; -- bug 5653168
8049 
8050     if g_debug then
8051       hr_utility.set_location(' Leaving:'||l_proc, 80);
8052     end if;
8053     --
8054   when others then
8055     --
8056     -- A validation or unexpected error has occured
8057     --
8058     --
8059     -- null globals to prevent bleeding
8060     --
8061     g_enrt_bnft_id:=null;
8062     g_bnft_val:=null;
8063     g_elig_per_elctbl_chc_id:=null;
8064     ben_sspndd_enrollment.g_use_new_result:=false;   -- bug 5653168
8065     --
8066     if p_called_from_sspnd = 'N' then
8067        ROLLBACK TO election_information_savepoint;
8068     else
8069        ROLLBACK TO election_information_sspnd;
8070     end if;
8071     raise;
8072     --
8073 
8074 end election_information;
8075 -- ----------------------------------------------------------------------------
8076 -- |-----------------------------< MANAGE_ENRT_BNFT >-------------------------|
8077 -- ----------------------------------------------------------------------------
8078 procedure MANAGE_ENRT_BNFT
8079               (p_prtt_enrt_rslt_id     IN     number
8080               ,p_enrt_bnft_id          IN     number default null
8081               ,p_object_version_number in out nocopy number
8082               ,p_business_group_id     in     number
8083               ,p_effective_date        in     date
8084               ,p_per_in_ler_id         in     number
8085               ,p_created_by            in     varchar2 default null
8086               ,p_creation_date         in     date     default null
8087               )IS
8088   l_proc         varchar2(72) ;
8089   cursor c1 is
8090         select ebr.enrt_bnft_id,
8091                ebr.object_version_number
8092           from ben_enrt_bnft ebr,
8093                ben_elig_per_elctbl_chc epe,
8094                ben_per_in_ler pil
8095          where ebr.prtt_enrt_rslt_id = p_prtt_enrt_rslt_id and
8096                ( p_enrt_bnft_id is null OR
8097                  ebr.enrt_bnft_id <> p_enrt_bnft_id )
8098                and epe.elig_per_elctbl_chc_id=ebr.elig_per_elctbl_chc_id
8099                and pil.per_in_ler_id=epe.per_in_ler_id
8100                and pil.per_in_ler_stat_cd not in ('VOIDD','BCKDT')
8101                and pil.per_in_ler_id = p_per_in_ler_id ;
8102   BEGIN
8103     g_debug := hr_utility.debug_enabled;
8104     if g_debug then
8105       l_proc          := g_package||'manage_enrt_bnft';
8106       hr_utility.set_location('Entering:'||l_proc, 5);
8107     end if;
8108     if g_debug then
8109       hr_utility.set_location(' bnft:'|| to_char(p_enrt_bnft_id), 5);
8110     end if;
8111     if g_debug then
8112       hr_utility.set_location(' rslt:'|| to_char(p_prtt_enrt_rslt_id), 15);
8113     end if;
8114     if g_debug then
8115       hr_utility.set_location(' enb_ovn:'|| to_char(p_object_version_number), 15);
8116     end if;
8117 
8118     for rec in c1 loop
8119         if g_debug then
8120           hr_utility.set_location(l_proc, 10);
8121         end if;
8122         -- Update any enrollment benefit records that may have had the result id
8123         -- on them from previous enrollments.  Set rslt id = null.
8124         ben_enrt_bnft_api.update_enrt_bnft
8125                 (p_enrt_bnft_id           => rec.enrt_bnft_id
8126                 ,p_effective_date         => p_effective_date
8127                 ,p_object_version_number  => rec.object_version_number
8128                 ,p_business_group_id      => p_business_group_id
8129                 ,p_prtt_enrt_rslt_id      => NULL
8130                 ,p_program_application_id =>fnd_global.prog_appl_id
8131                 ,p_program_id             =>fnd_global.conc_program_id
8132                 ,p_request_id             =>fnd_global.conc_request_id
8133                 ,p_program_update_date    =>sysdate
8134                 );
8135         if g_debug then
8136           hr_utility.set_location(l_proc, 15);
8137         end if;
8138     end loop;
8139     if g_debug then
8140       hr_utility.set_location(l_proc, 20);
8141     end if;
8142 
8143     -- need this for the new enrolment
8144 
8145     if (p_enrt_bnft_id is not NULL) then
8146         if g_debug then
8147           hr_utility.set_location(l_proc, 30);
8148         end if;
8149         ben_enrt_bnft_api.update_enrt_bnft
8150                 (p_enrt_bnft_id           => p_enrt_bnft_id
8151                 ,p_effective_date         => p_effective_date
8152                 ,p_object_version_number  => p_object_version_number
8153                 ,p_business_group_id      => p_business_group_id
8154                 ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
8155                 ,p_program_application_id => fnd_global.prog_appl_id
8156                 ,p_program_id             => fnd_global.conc_program_id
8157                 ,p_request_id             => fnd_global.conc_request_id
8158                 ,p_program_update_date    => sysdate
8159                 );
8160         if g_debug then
8161           hr_utility.set_location(l_proc, 40);
8162         end if;
8163     end if;
8164     if g_debug then
8165       hr_utility.set_location('Leaving:'||l_proc, 99);
8166     end if;
8167 END MANAGE_ENRT_BNFT;
8168 --
8169 --
8170 procedure election_information_w
8171   (p_validate               in varchar2 default 'N'
8172   ,p_elig_per_elctbl_chc_id in number
8173   ,p_prtt_enrt_rslt_id      in number
8174   ,p_effective_date         in date
8175   ,p_enrt_mthd_cd           in varchar2
8176   ,p_enrt_bnft_id           in number
8177   ,p_bnft_val               in number default null
8178   ,p_enrt_rt_id             in number default null
8179   ,p_prtt_rt_val_id         in number
8180   ,p_rt_val                 in number default null
8181   ,p_ann_rt_val             in number default null
8182   ,p_datetrack_mode         in varchar2
8183   ,p_suspend_flag           in varchar2
8184   ,p_effective_start_date   in date
8185   ,p_object_version_number  in number
8186   ,p_business_group_id      in  number
8187   ,p_enrt_rt_id2            in number default null
8188   ,p_prtt_rt_val_id2        in number
8189   ,p_rt_val2                in number default null
8190   ,p_ann_rt_val2            in number default null
8191   ,p_enrt_rt_id3            in number default null
8192   ,p_prtt_rt_val_id3        in number
8193   ,p_rt_val3                in number default null
8194   ,p_ann_rt_val3            in number default null
8195   ,p_enrt_rt_id4            in number default null
8196   ,p_prtt_rt_val_id4        in number
8197   ,p_rt_val4                in number default null
8198   ,p_ann_rt_val4            in number default null
8199   ,p_person_id              in number default null
8200   ,p_enrt_cvg_strt_dt       in date   default null
8201   ,p_enrt_cvg_thru_dt       in date   default null
8202   ,p_rt_update_mode         in varchar2 default null
8203   ,p_rt_strt_dt1            in date   default null
8204   ,p_rt_end_dt1             in date   default null
8205   ,p_rt_strt_dt_cd1         in varchar2 default null
8206   ,p_return_status          out nocopy varchar2
8207   ) is
8208 
8209   --
8210   l_effective_date       date := trunc(sysdate);
8211   l_effective_start_date date := p_effective_start_date;
8212   l_api_error            boolean;
8213   l_proc                 varchar2(60) := 'ben_election_information.election_information_w outer';
8214   l_trace_param          varchar2(30);
8215   l_trace_on             boolean;
8216 
8217   --
8218 begin
8219   l_trace_param := null;
8220   l_trace_on := false;
8221   --
8222   fnd_msg_pub.initialize;
8223 --  hr_utility.trace_on(null,'BENELINF');
8224 
8225   l_trace_param := fnd_profile.value('BEN_SS_TRACE_VALUE');
8226 
8227   --
8228   if l_trace_param = 'BENELINF' then
8229      l_trace_on := true;
8230   else
8231      l_trace_on := false;
8232   end if;
8233   --
8234   if l_trace_on then
8235     hr_utility.trace_on(null,'BENELINF');
8236   end if;
8237   --
8238   hr_utility.set_location('Entering:'||l_proc, 5);
8239   hr_utility.set_location('l_trace_param : '|| l_trace_param, 5);
8240   --
8241   if p_effective_date is not null then
8242   --  l_effective_date := to_date(p_effective_date, 'YYYY/MM/DD');
8243     l_effective_date := p_effective_date;
8244   end if;
8245   --
8246   election_information_w
8247    (p_validate               => p_validate
8248    ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8249    ,p_prtt_enrt_rslt_id      => p_prtt_enrt_rslt_id
8250    ,p_effective_date         => l_effective_date
8251    ,p_enrt_mthd_cd           => p_enrt_mthd_cd
8252    ,p_enrt_bnft_id           => p_enrt_bnft_id
8253    ,p_bnft_val               => p_bnft_val
8254    ,p_enrt_rt_id1            => p_enrt_rt_id
8255    ,p_prtt_rt_val_id1        => p_prtt_rt_val_id
8256    ,p_rt_val1                => p_rt_val
8257    ,p_ann_rt_val1            => p_ann_rt_val
8258    ,p_enrt_rt_id2            => p_enrt_rt_id2
8259    ,p_prtt_rt_val_id2        => p_prtt_rt_val_id2
8260    ,p_rt_val2                => p_rt_val2
8261    ,p_ann_rt_val2            => p_ann_rt_val2
8262    ,p_enrt_rt_id3            => p_enrt_rt_id3
8263    ,p_prtt_rt_val_id3        => p_prtt_rt_val_id3
8264    ,p_rt_val3                => p_rt_val3
8265    ,p_ann_rt_val3            => p_ann_rt_val3
8266    ,p_enrt_rt_id4            => p_enrt_rt_id4
8267    ,p_prtt_rt_val_id4        => p_prtt_rt_val_id4
8268    ,p_rt_val4                => p_rt_val4
8269    ,p_ann_rt_val4            => p_ann_rt_val4
8270    ,p_datetrack_mode         => p_datetrack_mode
8271    ,p_suspend_flag           => p_suspend_flag
8272    ,p_effective_start_date   => l_effective_start_date
8273    ,p_object_version_number  => p_object_version_number
8274    ,p_business_group_id      => p_business_group_id
8275    ,p_person_id              => p_person_id
8276    ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt
8277    ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt
8278    ,p_rt_update_mode         => p_rt_update_mode
8279    ,p_rt_strt_dt1            => p_rt_strt_dt1
8280    ,p_rt_end_dt1             => p_rt_end_dt1
8281    ,p_rt_strt_dt_cd1         => p_rt_strt_dt_cd1
8282    ,p_api_error              => l_api_error);
8283 
8284    IF (l_api_error)
8285     THEN
8286       p_return_status :='E';
8287    ELSE
8288       p_return_status :='S';
8289    END IF;
8290    --
8291    hr_utility.set_location('Leaving:'||l_proc, 10);
8292    --
8293    if l_trace_on then
8294      hr_utility.trace_off;
8295      l_trace_param := null;
8296      l_trace_on := false;
8297    end if;
8298 --
8299 exception
8300   --
8301   when app_exception.application_exception then	--Bug 4387247
8302     p_return_status := 'E';
8303     fnd_msg_pub.add;
8304     --Bug 4436578
8305     ben_det_enrt_rates.clear_globals;
8306     if l_trace_on then
8307       hr_utility.trace_off;
8308       l_trace_on := false;
8309       l_trace_param := null;
8310     end if;
8311   when others then
8312     p_return_status := 'E';
8313     --Bug 4387247
8314     fnd_message.set_name('PER','FFU10_GENERAL_ORACLE_ERROR');
8315     fnd_message.set_token('2',substr(sqlerrm,1,200));
8316     fnd_msg_pub.add;
8317     ben_det_enrt_rates.clear_globals;
8318     if l_trace_on then
8319       hr_utility.trace_off;
8320       l_trace_on := false;
8321       l_trace_param := null;
8322     end if;
8323 end election_information_w;
8324 --
8325 --
8326 procedure election_information_w
8327   (p_validate               in varchar2 default 'N'
8328   ,p_elig_per_elctbl_chc_id in number
8329   ,p_prtt_enrt_rslt_id      in number
8330   ,p_effective_date         in date
8331   ,p_person_id              in number default null
8332   ,p_enrt_mthd_cd           in varchar2
8333   ,p_enrt_bnft_id           in number
8334   ,p_bnft_val               in number default null
8335   ,p_enrt_rt_id1            in number default null
8336   ,p_prtt_rt_val_id1        in number default null
8337   ,p_rt_val1                in number default null
8338   ,p_ann_rt_val1            in number default null
8339   ,p_rt_strt_dt1            in date   default null
8340   ,p_rt_end_dt1             in date   default null
8341   ,p_rt_strt_dt_cd1         in varchar2 default null
8342   ,p_enrt_rt_id2            in number default null
8343   ,p_prtt_rt_val_id2        in number default null
8344   ,p_rt_val2                in number default null
8345   ,p_ann_rt_val2            in number default null
8346   ,p_rt_strt_dt2            in date   default null
8347   ,p_rt_end_dt2             in date   default null
8348   ,p_enrt_rt_id3            in number default null
8349   ,p_prtt_rt_val_id3        in number default null
8350   ,p_rt_val3                in number default null
8351   ,p_ann_rt_val3            in number default null
8352   ,p_rt_strt_dt3            in date   default null
8353   ,p_rt_end_dt3             in date   default null
8354   ,p_enrt_rt_id4            in number default null
8355   ,p_prtt_rt_val_id4        in number default null
8356   ,p_rt_val4                in number default null
8357   ,p_ann_rt_val4            in number default null
8358   ,p_rt_strt_dt4            in date   default null
8359   ,p_rt_end_dt4             in date   default null
8360   ,p_datetrack_mode         in varchar2
8361   ,p_suspend_flag           in varchar2
8362   ,p_effective_start_date   in date
8363   ,p_object_version_number  in number
8364   ,p_business_group_id      in number
8365   ,p_enrt_cvg_strt_dt       in date
8366   ,p_enrt_cvg_thru_dt       in date
8367   ,p_rt_update_mode         in varchar2 default null
8368   ,p_api_error              out nocopy boolean)
8369 is
8370   l_validate boolean := false;
8371   l_datetrack_mode   varchar2(30) := p_datetrack_mode;
8372   l_suspend_flag     varchar2(30) := p_suspend_flag;
8373   l_dpnt_actn_warning boolean;
8374   l_bnf_actn_warning  boolean;
8375   l_ctfn_actn_warning boolean;
8376   l_object_version_number number := p_object_version_number;
8377   l_prtt_enrt_rslt_id number := p_prtt_enrt_rslt_id;
8378   l_prtt_rt_val_id1   number := p_prtt_rt_val_id1;
8379   l_prtt_rt_val_id2   number := p_prtt_rt_val_id2;
8380   l_prtt_rt_val_id3   number := p_prtt_rt_val_id3;
8381   l_prtt_rt_val_id4   number;
8382   l_prtt_rt_val_id5   number;
8383   l_prtt_rt_val_id6   number;
8384   l_prtt_rt_val_id7   number;
8385   l_prtt_rt_val_id8   number;
8386   l_prtt_rt_val_id9   number;
8387   l_prtt_rt_val_id10  number;
8388   l_prtt_enrt_interim_id number;
8389   l_effective_start_date date;
8390   l_effective_end_date   date;
8391   --
8392     -- Bug 4216475
8393   -- Changing the cursor to bring up val alone for validation
8394   -- to handle cases where the default is outside the coverage
8395   -- range and the benefit val is not defined (Enterable)
8396 
8397   cursor c_bnft is
8398      select enb.val val,-- nvl(enb.val, enb.dflt_val) val, Bug 4216475
8399             enb.mn_val,
8400             enb.mx_val,
8401             enb.incrmt_val
8402      from   ben_enrt_bnft enb
8403      where  enb.enrt_bnft_id = p_enrt_bnft_id;
8404   --
8405   -- open c_pl_opt_name cursor only if error needs to be displayed.
8406   --
8407   cursor c_pl_opt_name is
8408      select pln.name || ' '|| opt.name
8409      from   ben_elig_per_elctbl_chc epe,
8410             ben_pl_f                pln,
8411             ben_oipl_f              oipl,
8412             ben_opt_f               opt
8413      where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
8414      and    epe.pl_id                  = pln.pl_id
8415      and    epe.oipl_id                = oipl.oipl_id(+)
8416      and    oipl.opt_id                = opt.opt_id(+)
8417      and    p_effective_date between
8418             pln.effective_start_date and pln.effective_end_date
8419      and    p_effective_date between
8420             oipl.effective_start_date(+) and oipl.effective_end_date(+)
8421      and    p_effective_date between
8422             opt.effective_start_date(+) and opt.effective_end_date(+);
8423 	--
8424 	-- 4543745
8425 	cursor c_elinf is
8426 	   select epe.crntly_enrd_flag
8427            ,epe.elctbl_flag
8428            ,epe.mndtry_flag
8429 		 from		ben_elig_per_elctbl_chc epe
8430 		 where	epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
8431   --
8432   l_bnft              c_bnft%rowtype;
8433 	l_elinf							c_elinf%rowtype;
8434   l_pl_opt_name       varchar2(600) := null; -- UTF8 Change Bug 2254683
8435   l_proc              varchar2(60)  := 'ben_election_information.election_information_w inner';
8436   --
8437 begin
8438   --
8439   hr_utility.set_location('Entering : '||l_proc, 10);
8440   p_api_error := false;
8441   --
8442 	-- 4543745
8443 	--
8444 	open c_elinf;
8445 	fetch c_elinf into l_elinf;
8446   close c_elinf;
8447 
8448 	if (l_elinf.crntly_enrd_flag = 'Y' and l_elinf.elctbl_flag = 'N' and l_elinf.mndtry_flag = 'N') then
8449     hr_utility.set_location('Returning without calling election_information for cannot change enrollment', 80.1);
8450 	  return;
8451 	end if;
8452 
8453   if p_validate = 'Y' then
8454     l_validate := true;
8455   end if;
8456   --
8457   if l_datetrack_mode = hr_api.g_correction then
8458     if p_effective_date = p_effective_start_date then
8459       null;
8460     else
8461       l_datetrack_mode := hr_api.g_update;
8462     end if;
8463   end if;
8464   --
8465   ben_env_object.init(p_business_group_id  => p_business_group_id,
8466                         p_effective_date     => p_effective_date,
8467                         p_thread_id          => 1,
8468                         p_chunk_size         => 1,
8469                         p_threads            => 1,
8470                         p_max_errors         => 1,
8471                         p_benefit_action_id  => null);
8472 
8473   --
8474   if p_enrt_bnft_id is not null and p_bnft_val is not null then
8475     --
8476     open c_bnft;
8477     fetch c_bnft into l_bnft;
8478     close c_bnft;
8479     --
8480     if nvl(l_bnft.val,-999) <> p_bnft_val then
8481       --
8482       --  Bug 3181158, added nvl in 'if' to handle
8483       --  'EnrtValAtEnrt + no default value' condition
8484       --
8485       if ((l_bnft.mn_val is not null and p_bnft_val < l_bnft.mn_val) or
8486           (l_bnft.mx_val is not null and p_bnft_val > l_bnft.mx_val)) then
8487         --
8488         -- Open the c_pl_opt_name cursor only if error needs to be displayed.
8489         --
8490         open  c_pl_opt_name;
8491         fetch c_pl_opt_name into l_pl_opt_name;
8492         close c_pl_opt_name;
8493         --
8494         fnd_message.set_name('BEN','BEN_92394_OUT_OF_RANGE');
8495         fnd_message.set_token('MINIMUM', l_bnft.mn_val);
8496         fnd_message.set_token('MAXIMUM', l_bnft.mx_val);
8497         fnd_message.set_token('PLAN', l_pl_opt_name);
8498         fnd_message.raise_error;
8499         --
8500       end if;
8501       --
8502       if l_bnft.mn_val is not null and
8503          l_bnft.incrmt_val is not null and
8504          mod(p_bnft_val-l_bnft.mn_val, l_bnft.incrmt_val) <> 0 then
8505         --
8506         -- Open the c_pl_opt_name cursor only if error needs to be displayed.
8507         --
8508         open  c_pl_opt_name;
8509         fetch c_pl_opt_name into l_pl_opt_name;
8510         close c_pl_opt_name;
8511         --
8512         fnd_message.set_name('BEN','BEN_92395_NOT_IN_INCR');
8513         fnd_message.set_token('INCREMENT', l_bnft.incrmt_val);
8514         fnd_message.set_token('PLAN', l_pl_opt_name);
8515         fnd_message.raise_error;
8516         --
8517       end if;
8518       --
8519     end if;
8520     --
8521   end if;
8522   --
8523 
8524  if p_prtt_rt_val_id1 is not null and
8525      p_rt_strt_dt_cd1 is not null and
8526      p_rt_strt_dt_cd1 = 'ENTRBL'        then
8527 
8528     ben_determine_rate_chg.prv_delete
8529       (p_prtt_rt_val_id     => p_prtt_rt_val_id1
8530       ,p_enrt_rt_id         => p_enrt_rt_id1
8531       ,p_rt_val             => p_rt_val1
8532       ,p_rt_strt_dt         => p_rt_strt_dt1
8533       ,p_business_group_id  => p_business_group_id
8534       ,p_prtt_enrt_rslt_id  => p_prtt_enrt_rslt_id
8535       ,p_person_id          => p_person_id
8536       ,p_effective_date     => p_effective_date
8537       ,p_mode               => p_rt_update_mode);
8538  end if;
8539  --
8540  ben_election_information.election_information
8541   (p_validate               => l_validate
8542   ,p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id
8543   ,p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id
8544   ,p_effective_date         => p_effective_date
8545   ,p_enrt_mthd_cd           => p_enrt_mthd_cd
8546   ,p_enrt_bnft_id           => p_enrt_bnft_id
8547   ,p_bnft_val               => p_bnft_val
8548   ,p_enrt_cvg_strt_dt       => p_enrt_cvg_strt_dt
8549   ,p_enrt_cvg_thru_dt       => p_enrt_cvg_thru_dt
8550   ,p_enrt_rt_id1            => p_enrt_rt_id1
8551   ,p_prtt_rt_val_id1        => l_prtt_rt_val_id1
8552   ,p_rt_val1                => p_rt_val1
8553   ,p_ann_rt_val1            => p_ann_rt_val1
8554   ,p_rt_strt_dt1            => p_rt_strt_dt1
8555   ,p_rt_end_dt1             => p_rt_end_dt1
8556   ,p_enrt_rt_id2            => p_enrt_rt_id2
8557   ,p_prtt_rt_val_id2        => l_prtt_rt_val_id2
8558   ,p_rt_val2                => p_rt_val2
8559   ,p_ann_rt_val2            => p_ann_rt_val2
8560   ,p_rt_strt_dt2            => p_rt_strt_dt2
8561   ,p_rt_end_dt2             => p_rt_end_dt2
8562   ,p_enrt_rt_id3            => p_enrt_rt_id3
8563   ,p_prtt_rt_val_id3        => l_prtt_rt_val_id3
8564   ,p_rt_val3                => p_rt_val3
8565   ,p_ann_rt_val3            => p_ann_rt_val3
8566   ,p_rt_strt_dt3            => p_rt_strt_dt3
8567   ,p_rt_end_dt3             => p_rt_end_dt3
8568   ,p_enrt_rt_id4            => p_enrt_rt_id4
8569   ,p_prtt_rt_val_id4        => l_prtt_rt_val_id4
8570   ,p_rt_val4                => p_rt_val4
8571   ,p_ann_rt_val4            => p_ann_rt_val4
8572   ,p_rt_strt_dt4            => p_rt_strt_dt4
8573   ,p_rt_end_dt4             => p_rt_end_dt4
8574   ,p_enrt_rt_id5            => null
8575   ,p_prtt_rt_val_id5        => l_prtt_rt_val_id5
8576   ,p_rt_val5                => null
8577   ,p_ann_rt_val5            => null
8578   ,p_enrt_rt_id6            => null
8579   ,p_prtt_rt_val_id6        => l_prtt_rt_val_id6
8580   ,p_rt_val6                => null
8581   ,p_ann_rt_val6            => null
8582   ,p_enrt_rt_id7            => null
8583   ,p_prtt_rt_val_id7        => l_prtt_rt_val_id7
8584   ,p_rt_val7                => null
8585   ,p_ann_rt_val7            => null
8586   ,p_enrt_rt_id8            => null
8587   ,p_prtt_rt_val_id8        => l_prtt_rt_val_id8
8588   ,p_rt_val8                => null
8589   ,p_ann_rt_val8            => null
8590   ,p_enrt_rt_id9            => null
8591   ,p_prtt_rt_val_id9        => l_prtt_rt_val_id9
8592   ,p_rt_val9                => null
8593   ,p_ann_rt_val9            => null
8594   ,p_enrt_rt_id10           => null
8595   ,p_prtt_rt_val_id10       => l_prtt_rt_val_id10
8596   ,p_rt_val10               => null
8597   ,p_ann_rt_val10           => null
8598   ,p_datetrack_mode         => l_datetrack_mode
8599   ,p_suspend_flag           => l_suspend_flag
8600   ,p_called_from_sspnd      => 'N'
8601   ,p_effective_start_date   => l_effective_start_date
8602   ,p_effective_end_date     => l_effective_end_date
8603   ,p_object_version_number  => l_object_version_number
8604   ,p_prtt_enrt_interim_id   => l_prtt_enrt_interim_id
8605   ,p_business_group_id      => p_business_group_id
8606   ,p_pen_attribute_category =>  null
8607   ,p_pen_attribute1         =>  null
8608   ,p_pen_attribute2         =>  null
8609   ,p_pen_attribute3         =>  null
8610   ,p_pen_attribute4         =>  null
8611   ,p_pen_attribute5         =>  null
8612   ,p_pen_attribute6         =>  null
8613   ,p_pen_attribute7         =>  null
8614   ,p_pen_attribute8         =>  null
8615   ,p_pen_attribute9         =>  null
8616   ,p_pen_attribute10        =>  null
8617   ,p_pen_attribute11        =>  null
8618   ,p_pen_attribute12        =>  null
8619   ,p_pen_attribute13        =>  null
8620   ,p_pen_attribute14        =>  null
8621   ,p_pen_attribute15        =>  null
8622   ,p_pen_attribute16        =>  null
8623   ,p_pen_attribute17        =>  null
8624   ,p_pen_attribute18        =>  null
8625   ,p_pen_attribute19        =>  null
8626   ,p_pen_attribute20        =>  null
8627   ,p_pen_attribute21        =>  null
8628   ,p_pen_attribute22        =>  null
8629   ,p_pen_attribute23        =>  null
8630   ,p_pen_attribute24        =>  null
8631   ,p_pen_attribute25        =>  null
8632   ,p_pen_attribute26        =>  null
8633   ,p_pen_attribute27        =>  null
8634   ,p_pen_attribute28        =>  null
8635   ,p_pen_attribute29        =>  null
8636   ,p_pen_attribute30        =>  null
8637   ,p_dpnt_actn_warning      =>  l_dpnt_actn_warning
8638   ,p_bnf_actn_warning       =>  l_bnf_actn_warning
8639   ,p_ctfn_actn_warning      =>  l_ctfn_actn_warning);
8640 
8641   hr_utility.set_location('Leaving:'||l_proc, 20);
8642   --
8643 end election_information_w;
8644 
8645 end ben_election_information;