DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_DETERMINE_COVERAGE

Source


1 Package Body BEN_DETERMINE_COVERAGE as
2 /* $Header: bencvrge.pkb 120.45.12020000.2 2012/07/03 12:18:11 amnaraya ship $ */
3 --------------------------------------------------------------------------------
4 /*
5 +==============================================================================+
6 |                        Copyright (c) 1997 Oracle Corporation                 |
7 |                          Redwood Shores, California, USA                     |
8 |                               All rights reserved.                           |
9 +==============================================================================+
10 Name:
11    Determine Coverage
12 
13 Purpose:
14    Determines proper coverages based on mlt_cd.  Writes to BEN_ENRT_BNFT table.
15 
16 History:
17 
18         Date             Who        Version    What?
19         ----             ---        -------    -----
20         7 May 98        Ty Hayden   110.0      Created.
21        16 Jun 98        Ty Hayden   110.1      Do not error when coverage
22                                                not found.
23        16 Jun 98        T Guy       110.2      Removed other exception.
24        22 Jun 98        Ty Hayden   110.3      Added Mn,Mx,Incr,and Val edits.
25        25 Jun 98        T Guy       110.4      Replaced all occurrences of
26                                                PER10 with PERTEN.
27        11 Aug 98        Ty Hayden   110.5      Added mlt cd NSVU
28        08 Oct 98        T Guy       115.3      Added schema changes for ben_enrt_bnft
29                                                Added message numbers and debugging
30                                                messages.
31        12 Oct 98        T Guy       115.4      Added mlt cd SAAEAR.  Added dflt_val
32                                                logic.
33        22 Oct 98        T Guy       115.5      removed show errors statement
34        23 Oct 98        T Guy       115.6      added new column for write coverage
35                                                p_comp_lvl_fctr_id
36                                                p_cvg_mlt_cd
37                                                p_entr_val_at_enrt_flag
38                                                p_mx_val
39                                                p_mn_val
40                                                p_incrmt_val
41                                                p_rt_typ_cd
42        04 Nov 98        T Guy       115.7      fixed SAEER mlt_cd and local variable
43                                                assignment in calculate_val (val2).
44                                                Added g_record_error if person does
45                                                not have compensation.  This will role
46                                                back all records associated with this
47                                                person.
48       05 Nov 98         T Guy       115.8      Added logic to treat %RNG% mlt cd as
49                                                FLFX when vr trtmnt cd is RPLC.
50       16 Nov 98         T Guy       115.9      Added lower/upper limit value and rule
51                                                checking.  Removed post_write Procedure
52                                                as this logic has been added to the
53                                                write_coverage procedure.
54       24 Nov 98         T Guy       115.10     Fixed undefined upr/lwr rule checking
55       02 Dec 98         T Guy       115.11     Fixed set_token error for null
56                                                compensation
57       16 Dec 98         T Guy       115.12     No Change.
58       18 Dec 98         T Guy       115.13     Restructured looping for RNG cvg mlt cds
59                                                Fixes bug 1568.
60       18 Dec 98         T Guy       115.14     Removed ^m characters.
61       22 Dec 98         T Guy       115.15     Fixed bug 1563. when val is null added
62                                                check for entr_val_at_enrt_flag being off
63       18 Jan 99         G Perry     115.16     LED V ED
64       16 Feb 99         T Guy       115.17     Fixed bugs 1819, 1820
65       16 Feb 99         T Guy       115.18     Took out nocopy show errors statement
66       24 Feb 99         T Guy       115.19     Added level jumping and ctfn checking
67       26 Feb 99         T Guy       115.20     Fixed NSVU for bug 1820.
68       26 Feb 99         T Guy       115.21     Fixed error with ordr_num values
69       09 Mar 99         G Perry     115.23     IS to AS.
70       29 Mar 99         T Guy       115.24     Added default val to write_coverage
71       28 Apr 99         Shdas       115.25     Added contexts to rule
72                                                calls(genutils.formula).
73       29 Apr 99         lmcdonal    115.26     prtt_enrt_rslt now has status code.
74       07 may 99         Shdas       115.27     Added calls(genutils.formula) to
75                                                mn_cvg_rl,mx_cvg_rl.
76       14 May 99         G Perry     115.28     Added logic to check for PLIP
77                                                and then PL if PLIP not found.
78       17 May 99         T Guy       115.29     Fixed call to elctbl_chc_ctfn_api.
79       19 May 99         T Guy       115.30     Make version match header. removed
80                                                entr_val_at_enrt check for %RNG% codes
81       19 May 99         T Guy       115.31     Write DFLT_VAL only when entr_val_at_enrt
82                                                Fixed cursor to pick up dflt_flag from
83                                                chc instead of cvg_calc_mthd.
84        1 Jul 99         T Guy       115.32     Added rt_typ_cd of PERHNDRD
85        1 Jul 99         lmcdonal    115.33     Moved check_val (limit_checks) and
86                                                calcuate_val (rt_typ_calc)
87                                                to genutils.
88        9 Jul 99         mhoyes      115.34     Added trace messages.
89       16 Jul 99        lmcdonal     115.35     limit_checks parms changed.
90       20-JUL-99         Gperry      115.36     genutils -> benutils package
91                                                rename.
92       22-JUL-99         mhoyes      115.37   - Added new trace messages.
93                                              - Replaced all + 0s.
94       07-Sep-99         tguy        115.38     fixed calls to pay_mag_util
95       21-sep-99         tguy        115.39     added check for dflt_enrt_cd for
96                                                dflt_val assignemnt
97       04-OCT-99         mhoyes      115.40   - Modified code BENEFIT to BNFT.
98                                              - Tuned cursors. Replaced
99                                                c_cvg_plip, c_cvg_pln and
100                                                c_cvg_oipl with calls to
101                                                ben_cvg_cache.epeplncvg_getdets.
102       04-OCT-99         tguy        115.41   - added call to dt_fndate.
103       13-OCT-99         tguy        115.42   - moved increment value outside of
104                                                if statement. this fixed bug 3692
105       14-OCT-99         maagrawa    115.43   Modified level jumping logic.
106                                              Major change in chk_bnft_ctfn
107                                              procedure.
108       02-Nov-99         maagrawa    115.44   Made call to BEN_DETERMINE_CHC_CTFN
109                                              .write_ctfn to write level jumping
110                                              ctfns for the benefit records.
111       15-Nov-99         mhoyes      115.45 - Added trace messages.
112       19-Nov-99         pbodla      115.46 -  p_elig_per_elctbl_chc_id parameter
113                                              passed to benutils.limit_checks
114                                            - p_elig_per_elctbl_chc_id parameter
115                                              added to chk_bnft_ctfn proc and all
116                                              it's calls.
117                                            - Passed p_elig_per_elctbl_chc_id to
118                                              all benutils.formula calls.
119       29-Nov-99         jcarpent    115.47 - Added call to det._dflt_enrt_cd
120       07-Dec-99         jcarpent    115.48 - Assign defaults for flat fixed.
121       06-Jan-00         maagrawa    115.49 Modified chk_bnft_ctfn to look for
122                                            mx_cvg_alwd_amt for ctfns.(1142060)
123       19-Jan-00         tguy        115.50   Added check for rounding when vrbl
124                                              rt trtmt cd = rplc do not round at
125                                              value at this level.  Fixed error
126                                              message for null or zero comp.
127       20-Jan-00         thayden     115.51   Added prtt_enrt_rslt_id. bug 1146784
128       05-Feb-00         maagrawa    115.52   Fixed chk_bnft_ctfn (4392)
129                                              shdas-(1166169)
130       18-Feb-00         jcarpent    115.53   Make choice not eligible if bnft
131                                              is at max. and already have bnft.
132       22-Feb-00         shdas       115.54   Added codes for crntly_enrld_flag(1198551)
133       25-Feb-00         jcarpent    115.55   Close cursor problem c_other_pl_cvg.
134       26-Feb-00         thayden     115.56   If mlt_cd is Range, don't copy min,max,
135                                              incrmt,dflt to enrt benefit.
136       03-Mar-00         maagrawa    115.57   Created a new procedure write_ctfn
137                                              within the procedure main.
138                                              Always check for certs. when the
139                                              min. and max. benefit amounts are
140                                              defined.(1198549).
141       16-Mar-00         jcarpent    115.58   Added logic to handle ptips which
142                                              have plans with options and
143                                              maximums are reached. (1238601)
144       30-Mar-00         jcarpent    115.59   Cvg_mlt_cd's of saaear and nsvu
145                                              always had dflt_flag of N, changed
146                                              to use l_epe.dflt_flag.  Also
147                                              was giving two default sometimes
148                                              changed default conditions.
149                                              bug 1252087/4983.
150       31-Mar-00         mmogel      115.60   Added tokens to messages to make the
151                                              messages more meaningful to the user
152       14-Apr-00         jcarpent    115.61   For all but RNG, write coverage if
153                                              it's above the max but then update
154                                              the choice to be not electable. (5095)
155       09-May-00         lmcdonal    115.62   ctfn's at the option level are written
156                                              in benchctf.pkb. don't write them at
157                                              the bnft level too.  Bug 1277371.
158       12-May-00         lmcdonal    115.63   Bug 1249901 - when coverage is entered
159                                              at enrollment, we don't know if ctfns
160                                              are required until during enrt.  Write
161                                              ctfn records, load new mx_wout_ctfn
162                                              field.  Also override cvg-calc-mx
163                                              with rstrn-mx-with-ctfn val when writing
164                                              enrt-bnft row.
165      14-May-00          shdas       115.64   Bug 5152.Moved rounding function from
166                                              write coverage  to main so that cvg value gets
167                                              rounded before applying variable profile.
168      18-May-00          jcarpent    115.65   Bug 5209. If choice is updated to be
169                                              not electable also make not the default.
170                                              Also, deenroll from the result if
171                                              above the max.
172      24-May-00          tmicheal    115.66   bug 4844  fixd
173      05-Jun-00          stee        115.67   When writing certifications, do
174                                              not restrict by the
175                                              bnft_or_option_retrctn_cd.  There
176                                              is a check in the write_ctfn
177                                              procedure for duplicate
178                                              certification. wwbug #1308629.
179     20-Jul-00           bbulusu     115.68   Bug Fix 5368. Was not checking
180                                              for enter at enrollment when
181                                              comparing enrolled benefit amount
182                                              to null computed value.
183     25 Sep 00           mhoyes      115.69 - Commented out nocopy highly executed hr_utility
184                                              .set_locations.
185     07 Nov 00           mhoyes      115.70 - Referenced electable choice performance
186                                              APIs.
187                                            - Referenced comp object loop electable
188                                              choice context globals.
189     22 Nov 00           mhoyes      115.71 - Forward port of 1473060 on 115.69.
190     22 Nov 00           mhoyes      115.72 - Reinstated 115.70.
191     21 Nov 00           jcarpent    115.73 - bug 1470467. Check for provided
192                                              ctfns if over max.  Leapfrog
193                                              based on 115.69
194     22 Nov 00           jcarpent    115.74 - Merged version with 115.70 and 115.71.
195     23-Jan-01           mhoyes      115.75 - Added calculate only mode for EFC.
196     21-Feb-01           kmahendr    115.76 - Bug#1569790 - Benefit row is inserted
197                                              for interim coverage if multi_cd is Flat
198                                              amt with enter value at enrollment flag on
199     22-Mar-01           mhoyes      115.77 - Called epecobjtree_getcvgdets to get l_cvg.
200     27-mar-01           tilak       115.78 - bug : 1433393 ,ultm lwr limit and upr limit
201                                              column added in vapro
202                                              the resilt of vapro and cvg validated against the
203                                              ultiamte limit
204    03-apr-01           tilak        115.79   bug : 1712464 ultm lwr limit rl,and upr limit rl
205                                              added
206    02-Aug-01           ikasire      115.80   Bug 1895846 fixes for suspended enrollments
207    02-Aug-01           ikasire      115.81   to add modification history for 115.80
208    28-Aug-01           kmahendr     115.82   Bug#1936976-result_id is populated based on
209                                              benefit amount
210    29-aug-01           tilak        115.83   bug:1949361 jurisdiction code is
211                                               derived inside benutils.formula.
212    27-Sep-01           kmahendr     115.84   Bug#1981673-Added parameter ann_mn_elcn_val and
213                                              ann_mx_elcn_val to ben_determine_variable_rates
214                                              call
215    02-nov-01           tjesumic     115.85   bug :  2083726 fixed , if variable rate define
216                                              and the treatment code is replace then
217                                             default valu , increment value , min , max taken from
218                                             variable rate
219    14-nov-01           tjesumic     115.86  DBDRV added
220    21-nov-01           tjesumic     115.87  default valu , increment value , min , max taken from
221                                             variable rat for REPLC , SF ,  ADDTO,MB
222    21-nov-01           tjesumic     115.88  correction in REPLC , SF ,  ADDTO,MB calculation
223    28-Dec-01           jcarpent     115.89 - Bug:2157614: Altered cursor
224                                              c_other_oipls_in_plan_type for
225                                              performance issue.
226    28-Dec-01           jcarpent     115.90 - Bug#1910867: Fixed code to handle
227                        dschwart/cdaniels     condition when the maximum amount is NULL.
228 
229    28-Dec-01           dschwart/    115.91 - Bug#2054078: Max Coverage without certification
230                        BBurns/jcarpent       was not showing up on form because it was not
231                                              being written to ben_enrt_bnft.  Made modifications
232                                              to chk_bnft_ctfn_val parameters + related code to
233                                              fix this.
234    26-Mar-02           kmahendr     115.92 - Bug#1833008 - Added parameter p_cal_for to the call
235                                              determine_compensation to handle multi-assignment.
236    22-Apr-02           hnarayan     115.92   Bug 2319790 - changed chk_bnft_ctfn procedure
237    29-May-02           shdas        115.93   Bug 2325109 - Message token not sho                                             wing values.
238    08-Jun-02           pabodla      115.94   Do not select the contingent worker
239                                              assignment when assignment data is
240                                              fetched.
241    08-AUg-02           ikasire      115.95   Bug 2502633 Interim Enhancements
242                                              Added logic to create additional benefit
243                                              row for the purpose of interim enrollment.
244    03-Sep-02           ikasire      115.96   Bug 2543071 interim codes Current Same Option
245                                              in plan typo.wrong parameter passed.
246    05-Sep-02           ikasire      115.97   Bug 2551711 Getting default amount instead of
247                                              getting min amount for interim
248    06-Sep-02           ikasire      115.98   need to populate current pen_id on the
249                                              enb record created for SAME case
250    13-Sep-02           tjesumic     115.99   if the dflt enrt cd is rule and global variable
251                                              g_dflt_elctn_val has the value  then the global
252                                              value is used for default value,global value
253                                              is populated in bendenrr # 2534744
254    17-Sep-02           hnarayan     115.100  bug 2560721 - added code for setting dflt_flag
255                          when coverage is Flat Range , for new enrollments
256    28-Sep-02           ikasire      115.101  Bug 2600087 added nvl(p_lf_evt_ocrd_dt,
257                                              p_effective_date) to the cursors
258    18-Dec-02           mmudigon     115.102  Bug 2708100 Changes to Flat Range
259                                              (FLRNG) calculations.
260                                              Old Flat Rng :
261                                              Min ---> Max
262                                              New Flat Rng :
263                                              Lower Limit --> Upper Limit
264    23-DEC-02           lakrish      115.104  NOCOPY changes
265    03-Jan-03           kmahendr     115.105  Bug#2708285 - the limit is checked after adding
266                                              the flat amount for CLPFLRNG calculation
267    15-Jan-03           tjesumic     115.106  bug#2736519 new parameter added in chk_bnft_ctfn
268                                               p_no_mn_cvg_amt_apls_flag,p_no_mx_cvg_amt_apls_flag
269                                              if the max is 'Y' the l_mx_amt is not validated
270    10-Mar-03           pbodla       115.107  If the coverage calculation method
271                                              is rule then pass the option id
272                                              by fetching it if it's not already
273                                              fetched.
274    13-Aug-03           kmahendr     115.108  Added cvg_mlt_cd ERL
275    14-Aug-03           vsethi       115.109  Bug#3095224 - the limit is checked after adding
276                                              the flat amount for FLFXPCL, FLPCLRNG calculation
277    25-Aug-03           kmahendr     115.111  Bug#3108422 - ctfn calls made for RL and ERL
278    26-Aug-03           kmahendr     115.112  Bug#3108422 - ctfn_rqd_flag changed for ERL
279    02-Oct-03           ikasire      115.113  Bug#3132792 - Enrollment is not suspending if
280                                              certification was received for the plan in
281                                              lower amount.
282    31-Oct-03           kmahendr     115.114  Bug#3230649 - added primary_flag condition and
283                                              order by in cursors c_asg.
284    15-Mar-04           rpgupta      115.115  Bug 3497676 - Allow a 0 coverage to be created
285    08-Apr-04           kmahendr     115.116  Bug3560065 - check for other_pl_cvg removed
286 
287    17-Mar-04           pbodla       115.117  FONM : use cvg_strt_dt changes .
288    22-Apr-04           kmahendr     115.118  Bug#3585768 - limitation check removed
289    01-Jul-04           ikasire      115.119  Bug 3695079 We need to take the min of
290                                              mx with cert and increases plus current benefit
291                                              amount in deriving the max with cert amount
292    09-Aug-04           kmahendr     115.120  Bug#3772179 - Max without certification is
293                                              assigned a value in chk_bnft_ctfn.
294    05-Aug-04           tjesumic     115.121  FONM for ben_derive_factors fonm date paseed as param
295    17-Aug-04           hmani        115.122  Added newly added lookup codes 3806262
296    23-Aug-04           mmudigon     115.123  Excluding sspndd enrollmets in
297                                              cursor c_current_enrt
298                                              2534391 :NEED TO LEAVE ACTION ITEMS
299    15-Nov-04           kmahendr     115.124  Unrest. enh changes
300    01-Dec-04           abparekh     115.125  Bug 3828288 : For Flat Amount Calc Method consider Max Amount
301                                              as minimum of CCM Max, PLN Max WCfn, ( Current + PLN Max Incr WCfn )
302   01-dec-04            kmahendr     115.126  Unrest. enh changes
303    27-Dec-04           abparekh     115.127  Bug 3828288 : For Flat Amount Calc Method consider Max Increase
304                                              Amount only for Currently Enrolled records.
305    11-Jan-05           ikasire      115.128  CF Interim Suspended BUG 4064635 Multiple Changes
306    18-Jan-05           ikasire      115.129  CF Interim Suspended more changes
307    01-Feb-05           ikasire      115.130  CF Changes for 'SM' case
308    23-Feb-05           kmahendr     115.131  p_calculate_only_mode added not to
309                                              create_enrt_bnft when the value is false
310    07-Mar-05           ikasire      115.132  Bug 4223840 Flat Fixed Enter Value at enrollment
311                                              issue with mx_wout_ctfn_val issue
312    25-Mar-05           ikasire      115.133  Bug 4262970. Default is not identified properly in the
313                                              subsequent life event.
314    27-Mar-05           ikasire      115.134  Bug 4262970 - extend the fix to other flat range codes
315    28-Mar-05           kmahendr     115.135  Bug#4256191 - least of max, upper_limit_value
316                                              sent to get_least_val procedure
317    30-Mar-05           kmahendr     115.136  Bug#4256191 - rule evaluated before
318                                              determining the least amount
319    18-Apr-05           ssarkar      115.137  Bug# 4275929 : max_witout_cert is passed to max_with_cert ,
320                                              when null, while calling get_least_value proc.
321    06-jun-05           nhunur       115.138  4383988 - apply fnd_number on what FF returns in numeric variable.
322    30-Jun-05           ikasire      115.139  BUG 4449437 always setting the default flag to N for FLFXPCL
323    19-jul-05	       rgajula      115.140  Bug 4436573 Added a new parameter p_cvg_mlt_cd to the
324                                              ben_determine_coverage.chk_bnft_ctfn to perform few more
325                                              validations to set the certification required flag of ben_enrt_bnft.
326    25-Sep-05           kmahendr     115.141  Bug#4630782 - in unrestricted mode inelig
327                                              process not called
328    27-Sep-05           ikasire      115.142  Bug 4627840
329    04-Oct-05           ikasire      115.143  Bug 4649262 ERL fix regression from 4436573
330    20-oct-05           rgajula      115.144  Bug 4644489 Added an additional parameter p_rstrn_mn_cvg_rqd_amt
331 					     ben_determine_coverage.chk_bnft_ctfn to return the minimum coverage amount
332 					     as calculated by the minium rule in coverage restrictions, the out parameter will
333 					     will return the amount as calculated by the rule or the min value in the min feild in retrictions.
334 					     This returned value is used in the write record for Flat Amount Calculation method as
335 					     max(cvg_rstrn_amount,cvg_calc_mthd_min_amnt).
336    16-Jan-06           abparekh     115.145  Bug 4954541 : Unrestricted : If coverage does not exist, then delete
337                                                            corresponding BEN_ENRT_BNFT record
338    11-Apr-06           bmanyam     115.147  5105118 changes (115.146) are undone
339                                             This is leapfrog of 115.145.
340                                             5105118 is not-a-bug.
341    May 24, 2006        rgajula     115.148  Bug 5236985 Added the l_cvg_rstn_max_with_cert not null condition
342   					    This necessary if the l_rstrn.mx_cvg_wcfn_amt is
343 					    made null in the subsequent life event
344    28-Jun-2006         swjain      115.149  Bug 5331889 Added person_id param to mn_cvg_rl and mx_cvg_rl
345                                             in procedure chk_bnft_ctfn
346    11-Aug-2006         nhunur      115.150  Ult Lower limit value rule is not honoured
347    28-sep-2006         ssarkar     115.151 bug 5529258 : interim rule to be evaluated
348    29-sep-2006         ssarkar     115.152 5529258 : more fix
349    4-Oct-2006          rgajula     115.154 Bug 5573274 : Populated the mx_wout_ctfn value for Flat Range.
350    12-Oct-2006         ikasired    115.154 Bug 5596918 fix for 'SAME' part in carryforward. bnft amt null issue
351    12-Oct-2006         ikasired    115.154 Bug 5596907 fix for carryforward to use right bnft record
352    3-Nov-2006          rgajula     115.156 Bug 5637851 : Added nvl clauses in chk_bnft_ctfn.
353    27-Nov-2006         rgajula     115.157 Bug 5679097: Fix of regression for bug 5637851
354    23-Feb-2007         swjain      115.158 Bug 5887665: Passed ctfn_determine_cd in call to
355                                            ben_determine_chc_ctfn.write_ctfn in procedure main
356    02-Mar-2007         ssarkar     115.159 Bug 5900235 : write_ctfn to be called for RL if ctfn_rqd is true
357    22-Mar-2007         rgajula     115.161 Bug 5942733 : Removed the NVL clause which was causing the max_wout_cert to be set to max and causing unnecessary UI issues.
358    28-Mar-2007         swjain      115.162 Bug 5933576 : Added code in procedure main to check benefit certifications for 'NSVU' calculation method as well
359    30-Mar-2007         swjain      115.163 Bug 5933576 : When vr_val is null, then set it to default val in procedure main
360    17-May-2007         rtagarra    115.164 Bug 6054310 : Moved the condition added in 115.163 to NSVU Case only.
361    22-may-2007         nhunur      115.165 6066580: FLFXPCL do rounding after addition of flat amount
362    20-Jun-2007         rtagarra    115.166 Bug 6068097 : Made changes for the code NSDCS and NNCS.
363    04-Jul-2007         rtagarra    115.167 Bug 6164688 : For codes 'INCRCTF','DECRCTF' no need to check for order_number for calculation.
364    24-Oct-2007         bmanyam     115.168 6502657 :
365                                    If Coverage of more than one option
366                                    in same Plan is reduced due to
367                                    Upper Limit, then only one of
368                                    them is retained as Electable.
369    25-Oct-2007         sshetty     Fixed bug 6523477
370    12-May-2008                     For bug 7004909, changed the default value of coverage amount that was being passed to write coverages function for the type
371                                     Multiple of compensation
372    23-Jan-2009         sallumwa    Bug 7490759 :Modified the cursor c_cf_bnft_result to fetch the correct suspended
373                                    result ID when FONM and Event date LE's are processed in the same month.
374    02-Feb-2009         sallumwa    115.172    Bug 7704956 : Modified the procedure main to update the
375                                               currently_enrld_flag in ben_enrt_bnft table to 'Y' when the
376 					      benefit amount matches if multiple rows are set to 'Y' corresponding
377 					      to one elig_per_elctbl_chc_id.
378    11-Feb-2009         velvanop    115.173    Bug 7414757: Added parameter p_entr_val_at_enrt_flag.
379 	                                      VAPRO rates which are 'Enter value at Enrollment', Form field
380 					      should allow the user to enter a value during enrollment.
381    04-May-2009	       sallumwa    115.174    Bug 8453712 : Modified cursor c_cf_bnft_result to carry forward the latest pen row.
382    02-Jun-2009         sagnanas    115.175    8567963 - Modified cursor c_cf_bnft_result
383    09-Jun-2009         krupani     115.176    Bug 8568862 : For NSVU, default cvg value was not getting considered. Fixed the same.
384    29-Jun-2009         sallumwa  120.31.12010000.9             Bug 8716693 : Enhancement
385                                               EOI Does not Carry Forward for Life Events that Dont have EOI Configuration
386    05-Aug-2009         sallumwa  120.31.12010000.10   Bug 8767376 : Handled the Flat Range cases for the coverage for the above Enhancement
387    20-Oct-2009         krupani   120.31.12010000.11   Bug 9008389 : 12.1 forward port of 8940075
388    07-Feb-2009         sallumwa  120.31.12010000.12   Bug 9308931 : Extended the fix done for the bug 7704956 to
389                                                       OAB life events also.
390    10-Mar-2010         sagnanas  120.31.12010000.13   Bug 9434155 : Handled currently_enrld_flag and defaulting case for CLRNG
391     01-Jul-2010        velvanop  120.31.12010000.14    Bug 9774647:When salary change event occurs, update the coverage amount of the interim with the newly calculated value
392    17-Feb-2011	       amnaraya  120.31.12010000.15   Bug #8501248: Set the min, max, increment and default values as well as the enter value at enrollment flag for the variable
393 						      coverage profile with calculation method NSVU
394    06-Jun-2011         usaraswa  120.31.12010000.16   Bug 14137476: If the benefit amount is enter value at enrollment then for the elig_per_elctbl_chc_id there should be a record
395                                                                     present in ben_elctbl_chc_ctfn table.
396 */
397 -------------------------------------------------------------------------------------------------------------------------------------------------
398 --
399 g_package varchar2(80) := 'ben_determine_coverage';
400 g_old_val number;
401 --
402 --
403 FUNCTION round_val
404      (p_val                   in number,
405      p_effective_date         in date,
406      p_lf_evt_ocrd_dt         in date,
407      p_rndg_cd                in varchar2,
408      p_rndg_rl                in number) return number is
409 --
410   l_package varchar2(80) := g_package||'.round_val';
411   l_val number;
412 BEGIN
413    --
414    hr_utility.set_location ('Entering '||l_package,10);
415    --
416    if (p_rndg_cd is not null  or
417        p_rndg_rl is not null) then
418       --
419       l_val := benutils.do_rounding
420         (p_rounding_cd     => p_rndg_cd,
421          p_rounding_rl     => p_rndg_rl,
422          p_value           => p_val,
423          p_effective_date  => nvl(p_lf_evt_ocrd_dt,p_effective_date));
424      --
425    else
426      --
427      l_val := p_val;
428      --
429    end if;
430    return l_val;
431    hr_utility.set_location ('Leaving '||l_package,10);
432    --
433 END round_val;
434 --
435 ------------------------------------------------------------------------------
436 --
437 -- PROCEDURE GET_LEAST_VALUE
438 -- Bug 3828288
439 -- This procedure will return following values :
440 --    p_mx_val_wcfn := Minimum ( p_ccm_max_val, p_cvg_rstn_max_with_cert, p_cvg_rstn_max_incr_with_cert  )
441 --    p_mx_val_wo_cfn := Minimum ( p_ccm_max_val, p_cvg_rstn_max_wout_cert, p_cvg_rstn_max_incr_wout_cert  )
442 --
443 ------------------------------------------------------------------------------
444 PROCEDURE get_least_value ( p_ccm_max_val                 in number,
445                   p_cvg_rstn_max_incr_with_cert in number,
446                   p_cvg_rstn_max_with_cert      in number,
447                   p_cvg_rstn_max_incr_wout_cert in number,
448                   p_cvg_rstn_max_wout_cert      in number,
449                   p_mx_val_wcfn                 out nocopy number,
450                   p_mx_val_wo_cfn               out nocopy number
451                  )
452 IS
453 BEGIN
454   --
455   --
456   if p_ccm_max_val is not null
457   then
458     p_mx_val_wcfn := nvl ( least ( p_ccm_max_val, p_cvg_rstn_max_with_cert, p_cvg_rstn_max_incr_with_cert  ),
459                            nvl ( least ( p_ccm_max_val, p_cvg_rstn_max_incr_with_cert ) ,
460                                  nvl ( least ( p_ccm_max_val, p_cvg_rstn_max_with_cert ) ,
461                                        p_ccm_max_val
462                                      )
463                                 )
464                           );
465     p_mx_val_wo_cfn := nvl ( least ( p_ccm_max_val, p_cvg_rstn_max_wout_cert, p_cvg_rstn_max_incr_wout_cert  ),
466                            nvl ( least ( p_ccm_max_val, p_cvg_rstn_max_incr_wout_cert ) ,
467                                   least ( p_ccm_max_val, p_cvg_rstn_max_wout_cert )  -- Bug 5942733
468                                 )
469                           );
470   else
471     p_mx_val_wcfn := nvl ( least ( p_cvg_rstn_max_with_cert, p_cvg_rstn_max_incr_with_cert  ),
472                            nvl ( p_cvg_rstn_max_with_cert,
473                                  p_cvg_rstn_max_incr_with_cert
474                                 )
475                           );
476     p_mx_val_wo_cfn := nvl ( least ( p_cvg_rstn_max_wout_cert, p_cvg_rstn_max_incr_wout_cert  ),
477                            nvl ( p_cvg_rstn_max_wout_cert,
478                                  p_cvg_rstn_max_incr_wout_cert
479                                 )
480                           );
481   end if;
482   --
483 END;
484 
485 ---------------------------------------------------
486 --
487 --  Write ben_enrt_bnft
488 --
489 ---------------------------------------------------
490 --
491 PROCEDURE write_coverage
492   (p_calculate_only_mode    in     boolean default false
493   ,p_bndry_perd_cd          in     varchar2
494   ,p_bnft_typ_cd            in     varchar2
495   ,p_val                    in     number
496   ,p_dflt_flag              in     varchar2
497   ,p_nnmntry_uom            in     varchar2
498   ,p_elig_per_elctbl_chc_id in     number
499   ,p_business_group_id      in     number
500   ,p_effective_date         in     date
501   ,p_lf_evt_ocrd_dt         in     date
502   ,p_person_id              in     number
503   ,p_lwr_lmt_val            in     number
504   ,p_lwr_lmt_calc_rl        in     number
505   ,p_upr_lmt_val            in     number
506   ,p_upr_lmt_calc_rl        in     number
507   ,p_rndg_cd                in     varchar2
508   ,p_rndg_rl                in     number
509   ,p_comp_lvl_fctr_id       in     number
510   ,p_cvg_mlt_cd             in     varchar2
511   ,p_entr_val_at_enrt_flag  in     varchar2
512   ,p_mx_val                 in     number
513   ,p_mx_wout_ctfn_val       in     number
514   ,p_mn_val                 in     number
515   ,p_incrmt_val             in     number
516   ,p_dflt_val               in     number
517   ,p_rt_typ_cd              in     varchar2
518   ,p_perform_rounding_flg   in     boolean
519   ,p_ordr_num               in     number
520   ,p_ctfn_rqd_flag          in     varchar2
521   --
522   ,p_enrt_bnft_id              out nocopy number
523   ,p_enb_valrow                out nocopy ben_determine_coverage.ENBValType
524   --
525   ,p_ultmt_upr_lmt          in    number   default null
526   ,p_ultmt_lwr_lmt          in    number   default null
527   ,p_ultmt_upr_lmt_calc_rl  in    number   default null
528   ,p_ultmt_lwr_lmt_calc_rl  in    number   default null
529   ,p_bnft_amount            in    number   default null
530   ,p_vapro_exist            in    varchar2 default null
531   )
532 is
533   --
534   l_enrt_bnft_id number;
535   l_object_version_number number;
536   l_package varchar2(80) := g_package||'.write_coverage';
537   l_old_val number;
538   l_val number;
539   l_other_cvg number;
540   --
541   cursor c_asg(cv_effective_date date) is -- FONM
542     select asg.assignment_id,asg.organization_id
543     from   per_all_assignments_f asg
544     where  asg.person_id = p_person_id
545     and    asg.primary_flag = 'Y'
546     and    asg.assignment_type <> 'C'
547     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
548            between asg.effective_start_date
549            and    asg.effective_end_date
550     order  by decode(asg.assignment_type, 'E',1,'B',2,3);
551   --
552   l_asg c_asg%rowtype;
553   --
554   cursor c_epe is
555     select epe.business_group_id,
556            epe.pgm_id,
557            epe.pl_id,
558            epe.pl_typ_id,
559            epe.ptip_id,
560            epe.plip_id,
561            epe.oipl_id,
562            epe.prtt_enrt_rslt_id,
563            pil.ler_id,
564            epe.object_version_number,
565            epe.elctbl_flag,
566            epe.per_in_ler_id
567     from   ben_elig_per_elctbl_chc epe,
568            ben_per_in_ler pil
569     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
570     and    epe.per_in_ler_id = pil.per_in_ler_id;
571   --
572   l_epe c_epe%rowtype;
573   --
574   /*
575   cursor c_det_crnt_enrt(l_rslt_id number) is
576      select pen.bnft_amt,
577             pen.bnft_ordr_num
578      from ben_prtt_enrt_rslt_f pen,
579           ben_elig_per_elctbl_chc epe
580      where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
581      and    epe.prtt_enrt_rslt_id = l_rslt_id
582      and    pen.prtt_enrt_rslt_id = l_rslt_id;
583   --
584   -- l_det_crnt_enrt c_det_crnt_enrt%rowtype;
585   */
586   l_crnt_enrld_flag varchar2(30) := 'N';
587   --
588   -- FONM
589   cursor c_opt(cv_oipl_id number, cv_effective_date date) is
590     select oipl.opt_id
591     from   ben_oipl_f oipl
592     where  oipl.oipl_id = cv_oipl_id
593     and    cv_effective_date
594            between oipl.effective_start_date
595            and    oipl.effective_end_date;
596   --
597   l_opt c_opt%rowtype;
598   --
599   cursor c_state(cv_effective_date date) is -- FONM
600     select region_2
601     from   hr_locations_all loc,
602            per_all_assignments_f asg
603     where  loc.location_id = asg.location_id
604     and    asg.person_id = p_person_id
605     and    asg.primary_flag = 'Y'
606     and    asg.assignment_type <> 'C'
607     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
608            between asg.effective_start_date
609            and     asg.effective_end_date
610     and    asg.business_group_id =p_business_group_id
611     order  by decode(asg.assignment_type, 'E',1,'B',2,3);
612   --
613   l_state c_state%rowtype;
614   --
615   cursor c_other_oipl_cvg is
616     select enb.val
617     from   ben_elig_per_elctbl_chc epe,
618            ben_enrt_bnft enb
619     where  epe.pl_id=l_epe.pl_id
620        and nvl(epe.pgm_id,-1)=nvl(l_epe.pgm_id,-1)
621        and epe.per_in_ler_id=l_epe.per_in_ler_id
622        and epe.business_group_id=l_epe.business_group_id
623        and enb.elig_per_elctbl_chc_id=epe.elig_per_elctbl_chc_id
624        and enb.cvg_mlt_cd=p_cvg_mlt_cd
625        and enb.business_group_id=epe.business_group_id
626        and enb.val=l_val
627     ;
628   --
629   cursor c_other_pl_cvg is
630     select enb.val
631     from   ben_elig_per_elctbl_chc epe,
632            ben_enrt_bnft enb
633     where  epe.ptip_id=l_epe.ptip_id
634        and nvl(epe.pgm_id,-1)=nvl(l_epe.pgm_id,-1)
635        and epe.per_in_ler_id=l_epe.per_in_ler_id
636        and epe.business_group_id=l_epe.business_group_id
637        and enb.elig_per_elctbl_chc_id=epe.elig_per_elctbl_chc_id
638        and enb.cvg_mlt_cd=p_cvg_mlt_cd
639        and enb.business_group_id=epe.business_group_id
640        and enb.val=l_val
641     ;
642   --
643   cursor c_other_pl_in_ptip_cvg(cv_effective_date date) is
644     select enb.val
645     from   ben_elig_per_elctbl_chc epe,
646            ben_oipl_f oipl,
647            ben_oipl_f oipl2,
648            ben_enrt_bnft enb
649     where  epe.ptip_id=l_epe.ptip_id
650        and nvl(epe.pgm_id,-1)=nvl(l_epe.pgm_id,-1)
651        and epe.pl_typ_id=l_epe.pl_typ_id
652        and epe.per_in_ler_id=l_epe.per_in_ler_id
653        and epe.business_group_id=l_epe.business_group_id
654        and oipl.oipl_id=epe.oipl_id
655        and oipl.business_group_id=epe.business_group_id
656        and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
657            between
658            oipl.effective_start_date and oipl.effective_end_date
659        and oipl2.oipl_id=l_epe.oipl_id
660        and oipl2.business_group_id=p_business_group_id
661        and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
662            between
663            oipl2.effective_start_date and oipl2.effective_end_date
664        and oipl2.opt_id=oipl.opt_id  -- why we join to oipls
665        and enb.elig_per_elctbl_chc_id=epe.elig_per_elctbl_chc_id
666        and enb.cvg_mlt_cd=p_cvg_mlt_cd
667        and enb.business_group_id=epe.business_group_id
668        and enb.val=l_val
669     ;
670   --
671   cursor c_pl_typ_plip_enrt_limit(cv_effective_date date) is
672     select '1', mx_enrd_alwd_ovrid_num
673     from ben_ptip_f
674     where ptip_id=l_epe.ptip_id
675       and business_group_id=l_epe.business_group_id
676       and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
677            between
678           effective_start_date and effective_end_date
679       and mx_enrd_alwd_ovrid_num is not null
680     union
681     select '2', mx_enrl_alwd_num
682     from ben_pl_typ_f
683     where pl_typ_id=l_epe.pl_typ_id
684       and business_group_id=l_epe.business_group_id
685       and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
686           between
687           effective_start_date and effective_end_date
688       and mx_enrl_alwd_num is not null
689     order by 1
690     ;
691   /*********************************
692         CODE PRIOR TO WWBUG: 2157614
693   cursor c_other_oipls_in_plan_type is
694     select 'Y'
695     from   ben_elig_per_elctbl_chc epe
696     where  epe.pl_typ_id=l_epe.pl_typ_id
697       and  epe.pl_id<>l_epe.pl_id
698       and  nvl(epe.pgm_id,-1)=nvl(l_epe.pgm_id,-1)
699       and  epe.oipl_id is not null
700       and  epe.business_group_id=p_business_group_id
701     ;
702    ***************************/
703   /* Start of Changes for WWBUG: 2157614                */
704   cursor c_other_oipls_in_plan_type(cv_effective_date date) is
705     select 'Y'
706     from   ben_pl_f pln,
707            ben_oipl_f oipl
708     where  pln.pl_typ_id=l_epe.pl_typ_id
709       and  pln.pl_id<>l_epe.pl_id
710       and  cv_effective_date between -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date) between
711               pln.effective_start_date and pln.effective_end_date
712       and  pln.business_group_id=p_business_group_id
713       and  oipl.pl_id=pln.pl_id
714       and  oipl.business_group_id=p_business_group_id
715       and  cv_effective_date between -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date) between
716               oipl.effective_start_date and oipl.effective_end_date
717     ;
718   /* End of Changes for WWBUG: 2157614          */
719   --Unrestricted enh
720   cursor c_unrest(p_ler_id  number)  is
721     select 'Y'
722     from ben_ler_f ler
723     where ler.typ_cd = 'SCHEDDU'
724     and   ler.ler_id = p_ler_id
725     and   p_effective_date between ler.effective_start_date
726          and ler.effective_end_date;
727   --
728   --CF Susp Interim Enhancement
729   --
730   cursor c_cf_bnft_result(cv_effective_date date) is
731   SELECT  pen.prtt_enrt_rslt_id,
732           pen.bnft_amt,
733           pen.bnft_ordr_num
734       FROM     ben_prtt_enrt_rslt_f pen,
735                ben_ler_f ler
736       WHERE    pen.ler_id = ler.ler_id
737       AND      pen.person_id = p_person_id
738       AND      pen.business_group_id = p_business_group_id
739       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
740       --AND      pen.effective_end_date = hr_api.g_eot
741       --8567963
742       AND      ((pen.effective_end_date = hr_api.g_eot
743       and      ler.typ_cd <> 'SCHEDDU')
744        or      ( cv_effective_date between pen.effective_start_date and pen.effective_end_date
745       and       ler.typ_cd = 'SCHEDDU'))
746       --8567963
747       AND      cv_effective_date <= pen.enrt_cvg_thru_dt
748       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
749       AND      NVL(l_epe.oipl_id,-1) = NVL(pen.oipl_id,-1)
750       AND      l_epe.pl_id   = pen.pl_id
751       AND      NVL(l_epe.pgm_id,-1)  = NVL(pen.pgm_id,-1)
752       AND      ( pen.bnft_ordr_num = p_ordr_num OR
753                  pen.bnft_amt = p_val )
754       ----------Bug 7490759
755       AND      (pen.sspndd_flag = 'N' --CFW
756                  OR (pen.sspndd_flag = 'Y' and
757                      pen.enrt_cvg_thru_dt = hr_api.g_eot
758                     )
759                )
760   --  order by pen.enrt_cvg_strt_dt,decode(pen.sspndd_flag,'Y',1,2);  --Bug 8453712
761   order by pen.enrt_cvg_strt_dt desc,decode(pen.sspndd_flag,'Y',1,2);
762   --
763   l_cf_bnft_result  c_cf_bnft_result%ROWTYPE;
764   --
765   l_dummy             varchar2(1);
766   l_other_oipls_exist varchar2(30);
767   l_enrt_limit        number;
768   l_level             varchar2(30);
769   l_over_max_level    boolean  := false ;
770   l_prtt_enrt_rslt_id  number;
771   -- FONM
772   l_fonm_cvg_strt_dt   date;
773 
774 
775 BEGIN
776    --
777    hr_utility.set_location ('Entering '||l_package,10);
778    --
779    -- FONM
780    if ben_manage_life_events.fonm = 'Y' then
781      --
782      l_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt;
783      --
784    end if;
785    --
786    l_val := p_val;
787    --
788    open c_state(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
789      --
790      fetch c_state into l_state;
791      --
792    close c_state;
793    hr_utility.set_location ('close c_state ',10);
794    --
795    open c_asg(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
796      --
797      fetch c_asg into l_asg;  -- doesn't matter if null
798      --
799    close c_asg;
800    hr_utility.set_location ('close c_asg ',10);
801    --
802    if p_elig_per_elctbl_chc_id is not null then
803      --
804      open c_epe;
805        --
806        fetch c_epe into l_epe;
807        --
808      close c_epe;
809      hr_utility.set_location ('close c_epe ',10);
810      --
811    end if;
812    --
813    if l_epe.oipl_id is not null then
814      --
815      open c_opt(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
816        --
817        fetch c_opt into l_opt;
818        --
819      close c_opt;
820      hr_utility.set_location ('close c_opt ',10);
821      --
822    end if;
823    --
824    -- check boundaries
825    --
826    hr_utility.set_location ('limit_checks ',10);
827    l_old_val:=l_val;
828    --- bug:1433393 when the vapro not exist then the benefir amount assigned to the
829    --- old_val,
830    --- whne there is no vapro the max limit of benefit is validated to decide
831    --- whether the electable is allowd or not
832    --- the benefit amount (l_val) is after the limit_check so the beneft amount
833    --- (before limit check) assigned to old val
834    if nvl(p_vapro_exist,'N') <> 'Y' then
835      l_old_val := p_bnft_amount ;
836    end if ;
837    ---
838    ---validatiting ultmt lowr limit and ultimate upper limit
839    if p_ultmt_lwr_lmt is not null or p_ultmt_upr_lmt is not null
840      OR p_ultmt_lwr_lmt_calc_rl is not null or p_ultmt_upr_lmt_calc_rl is not null  then
841       benutils.limit_checks
842         (p_lwr_lmt_val       => p_ultmt_lwr_lmt,
843          p_lwr_lmt_calc_rl   => p_ultmt_lwr_lmt_calc_rl,
844          p_upr_lmt_val       => p_ultmt_upr_lmt,
845          p_upr_lmt_calc_rl   => p_ultmt_upr_lmt_calc_rl,
846          p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date), -- FONM : no need to pass the cvg or rt dates.
847          p_assignment_id     => l_asg.assignment_id,
848          p_organization_id   => l_asg.organization_id,
849          p_business_group_id => l_epe.business_group_id,
850          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
851          p_pgm_id            => l_epe.pgm_id,
852          p_pl_id             => l_epe.pl_id,
853          p_pl_typ_id         => l_epe.pl_typ_id,
854          p_opt_id            => l_opt.opt_id,
855          p_ler_id            => l_epe.ler_id,
856          p_val               => l_val,
857          p_state             => l_state.region_2);
858         hr_utility.set_location ('Dn limit_checks ',10);
859     end if ;
860    --
861    -- If the value has been changed due to limits
862    -- and the value has been lowered then we have
863    -- hit the max.  Check if another benefit has been
864    -- written at this same level.  If so make this electable
865    -- choice not electable.  Do this only for the non Range
866    -- cvg_mlt_cd's.
867    --
868    hr_utility.set_location('old='||l_old_val||' new='||
869                            l_val||' limit='|| p_ultmt_upr_lmt,31);
870    hr_utility.set_location('per in ler id '|| l_epe.per_in_ler_id,31);
871    hr_utility.set_location('mult code '|| p_cvg_mlt_cd,31);
872    hr_utility.set_location('pl  '|| l_epe.pl_id,31);
873    hr_utility.set_location('pgm  '|| l_epe.pgm_id,31);
874 
875    if l_val<l_old_val and
876       p_cvg_mlt_cd not like '%RNG' and
877       l_epe.elctbl_flag='Y' then
878 
879      if l_epe.plip_id is not null or
880         l_epe.oipl_id is not null then
881        if l_epe.oipl_id is not null then
882          --
883          -- Check if it is the only plan within the plan type that has opts
884          --
885          -- 6502657 The c_other_oipls_in_plan_type check is not correct.
886          -- It checks on ben_pl_f and ben_oipl_f tables only
887          -- and this does not ensure Active/ Eligible/Electable Plans.
888          -- A better approach is to check for options only in current Plan
889          /*
890          l_other_oipls_exist:='N';
891          open c_other_oipls_in_plan_type(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM;
892          fetch c_other_oipls_in_plan_type into l_other_oipls_exist;
893          close c_other_oipls_in_plan_type;
894          if l_other_oipls_exist<>'Y' then
895          */
896            --
897            -- Case of one plan with options
898            --
899           -- 6502657 : This check will ensure, if Coverage of
900           -- more than one option in same Plan is reduced
901           -- due to Upper Limit, then only one of them is retained
902           -- as Electable.
903           --
904           hr_utility.set_location('other oipl ' ,90);
905            open c_other_oipl_cvg;
906            fetch c_other_oipl_cvg into l_other_cvg;
907            close c_other_oipl_cvg;
908          /* Bug#3585768 - Enrollment limitation will be enforced at the time of enrollment
909          else
910            l_enrt_limit:=null;
911            open c_pl_typ_plip_enrt_limit(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM;
912            fetch c_pl_typ_plip_enrt_limit into l_level,l_enrt_limit;
913            close c_pl_typ_plip_enrt_limit;
914            if l_enrt_limit>1 then
915              --
916              -- Case of can enroll in many plans
917              -- Note: same logic as one plan with options
918              --
919              open c_other_oipl_cvg;
920              fetch c_other_oipl_cvg into l_other_cvg;
921              close c_other_oipl_cvg;
922            elsif l_enrt_limit=1 then
923              --
924              -- Case of many plans same options and can only choose one
925              --
926              open c_other_pl_in_ptip_cvg(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
927              fetch c_other_pl_in_ptip_cvg into l_other_cvg;
928              close c_other_pl_in_ptip_cvg;
929            else
930              --
931              -- No limits no restriction
932              --
933              null;
934            end if;
935          */
936         --  end if; 6502657
937        /* Bug3560065 : If there are setups to have two plans with same coverage,
938           this fails
939        elsif l_epe.plip_id is not null then
940          --
941          -- Case of no options
942          --
943          open c_other_pl_cvg;
944          fetch c_other_pl_cvg into l_other_cvg;
945          close c_other_pl_cvg;
946        */
947        end if;
948        hr_utility.set_location(' other cal ' || l_other_cvg,99);
949        if l_other_cvg=l_val then
950          --
951          open c_unrest(l_epe.ler_id);
952          fetch c_unrest into l_dummy;
953          close c_unrest;
954          if l_dummy = 'Y' then
955            null;
956          else
957            --
958            if not p_calculate_only_mode then
959              --
960              -- This coverage is above the max
961              -- Update the electable choice to be not electable
962              --
963              ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc(
964                p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id,
965                p_elctbl_flag             => 'N',
966                p_dflt_flag               => 'N',
967                p_object_version_number   => l_epe.object_version_number,
968                p_effective_date          => p_effective_date, -- FONM : no need to send the cvg strt dt
969                p_program_application_id  => fnd_global.prog_appl_id,
970                p_program_id              => fnd_global.conc_program_id,
971                p_request_id              => fnd_global.conc_request_id,
972                p_program_update_date     => sysdate
973              );
974              --
975              -- If enrolled will deenroll.
976              --
977              ben_newly_ineligible.main(
978                 p_person_id           => p_person_id,
979                 p_pgm_id              => l_epe.pgm_id,
980                 p_pl_id               => l_epe.pl_id,
981                 p_oipl_id             => l_epe.oipl_id,
982                 p_business_group_id   => p_business_group_id,
983                 p_ler_id              => l_epe.ler_id,
984                 p_effective_date      => p_effective_date -- FONM : no need to pass cvg or rt dates.
985              );
986             --
987             l_epe.elctbl_flag:='N';
988             hr_utility.set_location('Electable choice was made not electable by bencvrge',29);
989            end if;
990           end if;
991        end if;
992      end if;
993    end if;
994    --
995    -- Note: g_old_val is for RNG cvg_mlt_cd's, withing comp objects.
996    --       l_old_val and l_other_cvg are used for non RNG types
997    --       i.e., across oipls or plips.
998    --
999    open c_cf_bnft_result(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))) ;
1000      fetch c_cf_bnft_result into l_cf_bnft_result ;
1001    close c_cf_bnft_result ;
1002    hr_utility.set_location('l_cf_bnft_result.prtt_enrt_rslt_id '||l_cf_bnft_result.prtt_enrt_rslt_id,39);
1003    hr_utility.set_location('l_epe.prtt_enrt_rslt_id '||l_epe.prtt_enrt_rslt_id,39);
1004    --
1005    l_prtt_enrt_rslt_id := NVL(l_cf_bnft_result.prtt_enrt_rslt_id,l_epe.prtt_enrt_rslt_id);
1006    --
1007    if g_old_val <> nvl(l_val,-1) or
1008       l_epe.elctbl_flag='N'
1009       -- ERL changes
1010       or p_cvg_mlt_cd = 'ERL' then
1011       --
1012       -- if l_epe.prtt_enrt_rslt_id is not null then
1013       /* NEED TO BE TRASHED NEVER WORKS FOR FLAT RANGE
1014       if l_prtt_enrt_rslt_id is not null then
1015          open c_det_crnt_enrt(l_prtt_enrt_rslt_id);
1016          fetch c_det_crnt_enrt into l_det_crnt_enrt;
1017          if c_det_crnt_enrt%notfound then
1018             l_crnt_enrld_flag := 'N';
1019          else
1020             if(l_val = l_det_crnt_enrt.bnft_amt or
1021                p_entr_val_at_enrt_flag = 'Y'or l_det_crnt_enrt.bnft_ordr_num = p_ordr_num) then
1022                l_crnt_enrld_flag := 'Y';
1023             else
1024                l_crnt_enrld_flag := 'N';
1025                l_prtt_enrt_rslt_id := null;
1026             end if;
1027          end if;
1028          close c_det_crnt_enrt;
1029       end if;
1030       */
1031       if l_cf_bnft_result.prtt_enrt_rslt_id is not null then
1032         --
1033         if (l_val = l_cf_bnft_result.bnft_amt or
1034             p_entr_val_at_enrt_flag = 'Y'or
1035             l_cf_bnft_result.bnft_ordr_num = p_ordr_num) then
1036           --
1037           l_crnt_enrld_flag := 'Y';
1038           --
1039         else
1040           --
1041           l_crnt_enrld_flag := 'N';
1042           l_prtt_enrt_rslt_id := null;
1043           --
1044         end if;
1045         --
1046       else
1047         --
1048         l_crnt_enrld_flag := 'N';
1049         l_prtt_enrt_rslt_id := null;
1050         --
1051       end if;
1052       --
1053       hr_utility.set_location('l_prtt_enrt_rslt_id '||l_prtt_enrt_rslt_id,39);
1054       hr_utility.set_location('l_crnt_enrld_flag'||l_crnt_enrld_flag,39);
1055       --
1056       if not p_calculate_only_mode then
1057         --
1058         open c_unrest(l_epe.ler_id);
1059         fetch c_unrest into l_dummy;
1060         close c_unrest;
1061         if l_dummy = 'Y' then
1062           l_enrt_bnft_id := ben_manage_unres_life_events.enb_exists
1063                             (p_elig_per_elctbl_chc_id,p_ordr_num);
1064         end if;
1065         if l_enrt_bnft_id is not null then
1066           ben_manage_unres_life_events.update_enrt_bnft
1067            (
1068              p_dflt_flag              => p_dflt_flag,
1069              p_val_has_bn_prortd_flag => 'N',
1070              p_bndry_perd_cd          => p_bndry_perd_cd,
1071              p_bnft_typ_cd            => p_bnft_typ_cd,
1072              p_val                    => l_val,
1073              p_nnmntry_uom            => p_nnmntry_uom,
1074              p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
1075              p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id,
1076              p_business_group_id      => p_business_group_id,
1077              p_effective_date         => nvl(p_lf_evt_ocrd_dt,p_effective_date),
1078              p_program_application_id => fnd_global.prog_appl_id,
1079              p_program_id             => fnd_global.conc_program_id,
1080              p_request_id             => fnd_global.conc_request_id,
1081              p_comp_lvl_fctr_id       => p_comp_lvl_fctr_id,
1082              p_cvg_mlt_cd             => p_cvg_mlt_cd,
1083              p_crntly_enrld_flag      => l_crnt_enrld_flag,
1084              p_ctfn_rqd_flag          => p_ctfn_rqd_flag,
1085              p_entr_val_at_enrt_flag  => p_entr_val_at_enrt_flag,
1086              p_mx_val                 => p_mx_val,
1087              p_mx_wout_ctfn_val       => p_mx_wout_ctfn_val,
1088              p_mn_val                 => p_mn_val,
1089              p_incrmt_val             => p_incrmt_val,
1090              p_dflt_val               => p_dflt_val,
1091              p_rt_typ_cd              => p_rt_typ_cd,
1092              p_program_update_date    => sysdate,
1093              p_enrt_bnft_id           => l_enrt_bnft_id,
1094              p_ordr_num               => p_ordr_num);
1095         else
1096           --
1097           ben_enrt_bnft_api.create_enrt_bnft
1098          (p_validate               => false,
1099           p_dflt_flag              => p_dflt_flag,
1100           p_val_has_bn_prortd_flag => 'N',        -- change when prorating
1101           p_bndry_perd_cd          => p_bndry_perd_cd,
1102           p_bnft_typ_cd            => p_bnft_typ_cd,
1103           p_val                    => l_val,
1104           p_nnmntry_uom            => p_nnmntry_uom,
1105           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
1106           p_prtt_enrt_rslt_id      => l_prtt_enrt_rslt_id, --l_epe.prtt_enrt_rslt_id,
1107           p_business_group_id      => p_business_group_id,
1108           p_effective_date         => nvl(p_lf_evt_ocrd_dt,p_effective_date), -- FONM : No need to pass the cvg date.
1109           p_program_application_id => fnd_global.prog_appl_id,
1110           p_program_id             => fnd_global.conc_program_id,
1111           p_request_id             => fnd_global.conc_request_id,
1112           p_comp_lvl_fctr_id       => p_comp_lvl_fctr_id,
1113           p_cvg_mlt_cd             => p_cvg_mlt_cd,
1114           p_crntly_enrld_flag      => l_crnt_enrld_flag,
1115           p_ctfn_rqd_flag          => p_ctfn_rqd_flag,
1116           p_entr_val_at_enrt_flag  => p_entr_val_at_enrt_flag,
1117           p_mx_val                 => p_mx_val,  -- max with ctfn
1118           p_mx_wout_ctfn_val       => p_mx_wout_ctfn_val,  -- max without ctfn
1119           p_mn_val                 => p_mn_val,
1120           p_incrmt_val             => p_incrmt_val,
1121           p_dflt_val               => p_dflt_val,
1122           p_rt_typ_cd              => p_rt_typ_cd,
1123           p_program_update_date    => sysdate,
1124           p_enrt_bnft_id           => l_enrt_bnft_id,
1125           p_object_version_number  => l_object_version_number,
1126           p_ordr_num               => p_ordr_num);
1127         --
1128          end if;
1129       end if;
1130       --
1131    end if;
1132    --
1133    -- Set OUT parameters
1134    --
1135    g_old_val := l_val;
1136    p_enrt_bnft_id := l_enrt_bnft_id;
1137    --
1138    p_enb_valrow.enrt_bnft_id     := l_enrt_bnft_id;
1139    p_enb_valrow.val              := l_val;
1140    p_enb_valrow.mn_val           := p_mn_val;
1141    p_enb_valrow.mx_val           := p_mx_val;
1142    p_enb_valrow.mx_wout_ctfn_val := p_mx_wout_ctfn_val;
1143    p_enb_valrow.incrmt_val       := p_incrmt_val;
1144    p_enb_valrow.dflt_val         := p_dflt_val;
1145    --
1146    hr_utility.set_location ('Leaving '||l_package,10);
1147    --
1148 END write_coverage;
1149 --
1150 ------------------------------------------------------------------------
1151 PROCEDURE combine_with_variable_val
1152             (p_vr_val           in number,
1153              p_val              in number,
1154              p_vr_trtmt_cd      in varchar2,
1155              p_combined_val     out nocopy number) is
1156   --
1157   l_package varchar2(80) := g_package||'.combine_with_variable_val';
1158   --
1159 BEGIN
1160   --
1161   hr_utility.set_location ('Entering '||l_package,10);
1162   --
1163   if p_vr_val is null then
1164     --
1165     p_combined_val := p_val;
1166     return;
1167     --
1168   end if;
1169   --
1170   if p_val is null then
1171     --
1172     p_combined_val := p_vr_val;
1173     return;
1174     --
1175   end if;
1176   --
1177   -- Replace
1178   --
1179   if p_vr_trtmt_cd = 'RPLC' then
1180     --
1181     p_combined_val := p_vr_val;
1182     --
1183     -- Multiply By
1184     --
1185   elsif p_vr_trtmt_cd = 'MB' then
1186     --
1187     p_combined_val := p_val * p_vr_val;
1188     --
1189     -- Subtract From
1190     --
1191   elsif p_vr_trtmt_cd = 'SF' then
1192     --
1193     p_combined_val := p_val - p_vr_val;
1194     --
1195     -- Add To
1196     --
1197   elsif p_vr_trtmt_cd = 'ADDTO' then
1198     --
1199     p_combined_val := p_val + p_vr_val;
1200     --
1201   else -- Replace
1202     --
1203     p_combined_val := p_vr_val;
1204     --
1205   end if;
1206   --
1207   hr_utility.set_location ('Leaving '||l_package,10);
1208   --
1209 END combine_with_variable_val;
1210 --
1211 ----------------------------------------------------------------------------
1212 --
1213 procedure chk_bnft_ctfn(p_mx_cvg_wcfn_amt          in  number default null,
1214                         p_mx_cvg_wcfn_mlt_num      in  number default null,
1215                         p_mx_cvg_mlt_incr_num      in  number default null,
1216                         p_mx_cvg_mlt_incr_wcf_num  in  number default null,
1217                         p_mx_cvg_incr_alwd_amt     in  number default null,
1218                         p_mx_cvg_incr_wcf_alwd_amt in  number default null,
1219                         p_mn_cvg_rqd_amt           in  number default null,
1220                         p_mx_cvg_alwd_amt          in  number default null,
1221                         p_mx_cvg_rl                in  number default null,
1222                         p_mn_cvg_rl                in  number default null,
1223                         p_combined_val             in  number default null,
1224                         p_crnt_bnft_amt            in  number default null,
1225                         p_ordr_num                 in  number default null,
1226                         p_crnt_ordr_num            in  number default null,
1227                         p_no_mn_cvg_amt_apls_flag  in  varchar2 default null,
1228                         p_no_mx_cvg_amt_apls_flag  in  varchar2 default null,
1229                         p_effective_date           in  date,
1230                         p_assignment_id            in  number default null,
1231                         p_organization_id          in  number default null,
1232                         p_business_group_id        in  number default null,
1233                         p_pgm_id                   in  number default null,
1234                         p_pl_id                    in  number default null,
1235                         p_pl_typ_id                in  number default null,
1236                         p_opt_id                   in  number default null,
1237                         p_ler_id                   in  number default null,
1238                         p_elig_per_elctbl_chc_id   in  number default null,
1239                         p_entr_val_at_enrt_flag    in  varchar2 default null,
1240                         p_jurisdiction_code        in  varchar2 default null,
1241 --Bug No:4436573 Created another default null parameter for passing the  p_cvg_mlt_cd
1242 -- to perform the necessary validation
1243 			p_cvg_mlt_cd		   in  varchar2 default null,
1244 --End Bug No:4436573
1245                         p_ctfn_rqd                 out nocopy varchar2,
1246                         p_write_rec                out nocopy boolean,
1247                         p_check_received           out nocopy boolean,
1248                         /* Start of Changes for WWBUG: 2054078: added parameter */
1249                         p_mx_cvg_wout_ctfn_val     out nocopy number,
1250                         /* End of Changes for WWBUG: 2054078: added parameter */
1251 			p_rstrn_mn_cvg_rqd_amt     out nocopy number)
1252 			/*Bug 4644489 - parameter to return the minimum coverage required amount as calculated by the
1253 			minimum rule of static value defined in the min field in coverage restrictions*/
1254 is
1255   --
1256   l_package           varchar2(80) := g_package||'.chk_bnft_ctfn';
1257   l_max_possible_amt  number := null;
1258   l_mn_amt            number := null;
1259   l_mx_amt            number := null;
1260   --
1261   l_mn_outputs ff_exec.outputs_t;
1262   l_mx_outputs ff_exec.outputs_t;
1263   --Bug No:4436573 Creating another variable to concatenate
1264   -- all the feilds in PLN and LBR blocks of coverage restriction form
1265   l_pln_lbr_itms varchar2(500) := null;
1266   --End Bug No:4436573
1267   --
1268   /* Bug 5331889 */
1269   cursor fetch_person_id is
1270   select person_id
1271     from per_all_assignments_f
1272       where assignment_id = p_assignment_id;
1273   l_person_id number;
1274 
1275 BEGIN
1276   --
1277   hr_utility.set_location ('Entering '||l_package,10);
1278   --
1279   l_max_possible_amt := p_mx_cvg_wcfn_amt;
1280   l_mn_amt           := p_mn_cvg_rqd_amt;
1281   l_mx_amt           := p_mx_cvg_alwd_amt;
1282   --bug#3772179
1283   if ((l_mx_amt is null) and ((p_mx_cvg_incr_alwd_amt is not null) or (p_mx_cvg_wcfn_amt is not null) ) )then --Bug 5679097
1284     l_mx_amt := p_crnt_bnft_amt + nvl(p_mx_cvg_incr_alwd_amt,0);    /* Bug 3828288 */  -- Bug 5637851
1285   end if;
1286   p_mx_cvg_wout_ctfn_val  := l_mx_amt;
1287   --
1288   --Bug 3695079
1289   --l_max_possible_amt amount should be the min of p_mx_cvg_wcfn_amt and  p_mx_cvg_incr_wcf_alwd_amt
1290   --p_mx_cvg_incr_wcf_alwd_amt is defined otherwise we need to take only p_mx_cvg_wcfn_amt
1291   --
1292   hr_utility.set_location ('l_max_possible_amt '||l_max_possible_amt,111);
1293   hr_utility.set_location ('p_mx_cvg_incr_wcf_alwd_amt '||p_mx_cvg_incr_wcf_alwd_amt,111);
1294   if p_mx_cvg_incr_wcf_alwd_amt IS NOT NULL then
1295     --
1296     if l_max_possible_amt IS NULL OR
1297        nvl(l_max_possible_amt,0) > (p_mx_cvg_incr_wcf_alwd_amt + nvl(p_crnt_bnft_amt,0)) then
1298       l_max_possible_amt := p_mx_cvg_incr_wcf_alwd_amt + nvl(p_crnt_bnft_amt,0);
1299       hr_utility.set_location ('l_max_possible_amt inside '||l_max_possible_amt,111);
1300     end if;
1301     --
1302   end if;
1303   --
1304   open fetch_person_id;       -- Bug 5331889
1305   fetch fetch_person_id into l_person_id;
1306   close fetch_person_id;
1307   --
1308   if p_mn_cvg_rl is not NULL then
1309    --
1310    l_mn_outputs := benutils.formula
1311                     (p_formula_id          => p_mn_cvg_rl,
1312                      p_effective_date      => p_effective_date,
1313                      p_assignment_id       => p_assignment_id,
1314                      p_organization_id     => p_organization_id,
1315                      p_business_group_id   => p_business_group_id,
1316                      p_pgm_id              => p_pgm_id,
1317                      p_pl_id               => p_pl_id,
1318                      p_pl_typ_id           => p_pl_typ_id,
1319                      p_opt_id              => p_opt_id,
1320                      p_ler_id              => p_ler_id,
1321                      p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
1322                      -- FONM
1323                      p_param1             => 'BEN_IV_RT_STRT_DT',
1324                      p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
1325                      p_param2             => 'BEN_IV_CVG_STRT_DT',
1326                      p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
1327 		     p_param3             => 'BEN_IV_PERSON_ID',           -- Bug 5331889
1328                      p_param3_value       => to_char(l_person_id),
1329                      p_jurisdiction_code  => p_jurisdiction_code);
1330     --
1331     if l_mn_outputs(l_mn_outputs.first).value is not null then
1332        --
1333        l_mn_amt := fnd_number.canonical_to_number(l_mn_outputs(l_mn_outputs.first).value);
1334        --
1335 --Bug 4644489
1336        p_rstrn_mn_cvg_rqd_amt := l_mn_amt;
1337 -- Returing the mn_cvg_rqd_amt as defined by the rule
1338 --End Bug 4644489
1339     end if;
1340     --
1341   end if;
1342   --
1343   if p_mx_cvg_rl is not NULL then
1344     --
1345     l_mx_outputs := benutils.formula
1346                      (p_formula_id          => p_mx_cvg_rl,
1347                       p_effective_date      => p_effective_date,
1348                       p_assignment_id       => p_assignment_id,
1349                       p_organization_id     => p_organization_id,
1350                       p_business_group_id   => p_business_group_id,
1351                       p_pgm_id              => p_pgm_id,
1352                       p_pl_id               => p_pl_id,
1353                       p_pl_typ_id           => p_pl_typ_id,
1354                       p_opt_id              => p_opt_id,
1355                       p_ler_id              => p_ler_id,
1356                       p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
1357                       -- FONM
1358                       p_param1             => 'BEN_IV_RT_STRT_DT',
1359                       p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
1360                       p_param2             => 'BEN_IV_CVG_STRT_DT',
1361                       p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
1362        		      p_param3             => 'BEN_IV_PERSON_ID',           -- Bug 5331889
1363                       p_param3_value       => to_char(l_person_id),
1364                       p_jurisdiction_code   => p_jurisdiction_code);
1365     --
1366     if l_mx_outputs(l_mx_outputs.first).value is not null then
1367        --
1368        l_mx_amt := fnd_number.canonical_to_number(l_mx_outputs(l_mx_outputs.first).value);
1369        --
1370       /* Start of Changes for WWBUG: 2054078: added             */
1371        p_mx_cvg_wout_ctfn_val := l_mx_amt;
1372       /* Ended of Changes for WWBUG: 2054078: added             */
1373        --
1374     end if;
1375     --
1376   end if;
1377   --
1378 
1379   hr_utility.set_location ('Plan PL_ID                 -> '||p_pl_id                  ,33);
1380   hr_utility.set_location ('p_mx_cvg_wcfn_amt          -> '||p_mx_cvg_wcfn_amt         ,33);
1381   hr_utility.set_location ('p_mx_cvg_wcfn_mlt_num      -> '||p_mx_cvg_wcfn_mlt_num     ,33);
1382   hr_utility.set_location ('p_mx_cvg_mlt_incr_num      -> '||p_mx_cvg_mlt_incr_num     ,33);
1383   hr_utility.set_location ('p_mx_cvg_mlt_incr_wcf_num  -> '||p_mx_cvg_mlt_incr_wcf_num ,33);
1384   hr_utility.set_location ('p_mx_cvg_incr_alwd_amt     -> '||p_mx_cvg_incr_alwd_amt    ,33);
1385   hr_utility.set_location ('p_mx_cvg_incr_wcf_alwd_amt -> '||p_mx_cvg_incr_wcf_alwd_amt,33);
1386   hr_utility.set_location ('p_mx_cvg_rl                -> '||p_mx_cvg_rl               ,33);
1387   hr_utility.set_location ('p_mn_cvg_rl                -> '||p_mn_cvg_rl               ,33);
1388   hr_utility.set_location ('p_combined_val             -> '||p_combined_val            ,33);
1389   hr_utility.set_location ('p_crnt_bnft_amt            -> '||p_crnt_bnft_amt           ,33);
1390   hr_utility.set_location ('p_ordr_num                 -> '||p_ordr_num                ,33);
1391   hr_utility.set_location ('p_crnt_ordr_num            -> '||p_crnt_ordr_num           ,33);
1392   --Bug No:4436573 Debugging purpose
1393   hr_utility.set_location ('p_cvg_mlt_cd               -> '||p_cvg_mlt_cd              ,33);
1394   --End Bug No:4436573
1395   --
1396   if p_combined_val is null then
1397      --
1398      p_ctfn_rqd  := 'N';
1399      p_write_rec := true;
1400      --
1401   elsif p_combined_val > l_max_possible_amt then
1402      --
1403      p_ctfn_rqd  := 'N';
1404      p_write_rec := false;
1405      --
1406   elsif p_ordr_num > p_mx_cvg_wcfn_mlt_num then
1407      --
1408      p_ctfn_rqd  := 'N';
1409      p_write_rec := false;
1410      --
1411   elsif p_combined_val < l_mn_amt then
1412      --
1413      p_ctfn_rqd  := 'N';
1414      p_write_rec := false;
1415      --
1416   elsif p_crnt_bnft_amt is null and
1417         p_crnt_ordr_num is null then
1418      --
1419      p_ctfn_rqd  := 'N';
1420      p_write_rec := true;
1421      --
1422   elsif (p_combined_val - nvl(p_crnt_bnft_amt,0))
1423                           > p_mx_cvg_incr_wcf_alwd_amt then
1424     --
1425     p_ctfn_rqd  := 'N';
1426     p_write_rec := false;
1427     --
1428   elsif (p_ordr_num - nvl(p_crnt_ordr_num,0)) > p_mx_cvg_mlt_incr_wcf_num then
1429     --
1430     p_ctfn_rqd  := 'N';
1431     p_write_rec := false;
1432     --
1433   elsif (p_combined_val - nvl(p_crnt_bnft_amt,0))
1434                          <= p_mx_cvg_incr_alwd_amt then
1435      --
1436      p_ctfn_rqd  := 'N';
1437      p_write_rec := true;
1438      --
1439   elsif (p_ordr_num - nvl(p_crnt_ordr_num,0)) <= p_mx_cvg_mlt_incr_num then
1440     --
1441     p_ctfn_rqd  := 'N';
1442     p_write_rec := true;
1443     --
1444   elsif (p_combined_val - nvl(p_crnt_bnft_amt,0))
1445                            <= p_mx_cvg_incr_wcf_alwd_amt then
1446     --
1447     hr_utility.set_location(' IK1 p_combined_val - nvl(p_crnt_bnft_amt,0))'||(p_combined_val - nvl(p_crnt_bnft_amt,0)),99);
1448      hr_utility.set_location('IK1 p_mx_cvg_incr_wcf_alwd_amt'||p_mx_cvg_incr_wcf_alwd_amt,99);
1449     p_ctfn_rqd  := 'Y';
1450     p_write_rec := true;
1451     --
1452   elsif (p_ordr_num - nvl(p_crnt_ordr_num,0))<= p_mx_cvg_mlt_incr_wcf_num then
1453     --
1454     p_ctfn_rqd  := 'Y';
1455     p_write_rec := true;
1456     --
1457   else
1458     --
1459     p_ctfn_rqd  := 'N';
1460     p_write_rec := true;
1461     --
1462   end if;
1463   --
1464   if p_write_rec  then
1465      hr_utility.set_location (' p_write_rec  ',10);
1466   end if ;
1467 
1468   hr_utility.set_location (' p_no_mx_cvg_amt_apls_flag'|| p_no_mx_cvg_amt_apls_flag,10);
1469 
1470   -- This Certification condition is not based on increases,
1471   -- but based on a fixed amount. (Bug 1142060)
1472   -- no max flag is validated for # 2736519
1473   --
1474   -- Bug 3132792 if certifications is already provided for a benefit amount
1475   -- we don't need certifications upto that amount.
1476   -- Max without cert 50,000. Max with Cert is 100,000.
1477   -- In the first life event customer provided a certification for the
1478   -- benefit amount of 75,000. Now we need certification only for the
1479   -- amount more than 75,000 even if there are no increases defined by
1480   -- the customer.
1481   --
1482   hr_utility.set_location ('IK l_mx_amt '||l_mx_amt,20);
1483   hr_utility.set_location ('IK p_crnt_bnft_amt '||p_crnt_bnft_amt,20);
1484   --
1485   if p_entr_val_at_enrt_flag = 'N' then
1486     --
1487     l_mx_amt := greatest(l_mx_amt,nvl(p_crnt_bnft_amt,0));
1488     --
1489   end if;
1490   --
1491   if p_write_rec and
1492      ( p_combined_val > l_mx_amt or p_no_mx_cvg_amt_apls_flag = 'Y')  then
1493      --
1494      hr_utility.set_location ('IK I am Here'||p_combined_val,99);
1495      hr_utility.set_location ('IK l_mx_amt'||l_mx_amt ,99);
1496      p_check_received:=true;
1497      p_ctfn_rqd := 'Y';
1498      --
1499   end if;
1500   --
1501   hr_utility.set_location ('p_ctfn_rqd '||p_ctfn_rqd,09);
1502   --
1503   if p_write_rec and p_entr_val_at_enrt_flag = 'Y' and
1504      (l_mx_amt < l_max_possible_amt
1505      or l_max_possible_amt is not null)
1506      then
1507       hr_utility.set_location ('IK ENTRVALENRT case',99);
1508      p_ctfn_rqd := 'Y';
1509   end if;
1510   --
1511   if p_cvg_mlt_cd = 'ERL' then
1512      l_pln_lbr_itms := p_mx_cvg_wcfn_amt ||p_mx_cvg_wcfn_mlt_num || p_mx_cvg_mlt_incr_num;
1513      l_pln_lbr_itms := l_pln_lbr_itms ||  p_mx_cvg_mlt_incr_wcf_num || p_mx_cvg_incr_alwd_amt;
1514      l_pln_lbr_itms := l_pln_lbr_itms || p_mx_cvg_incr_wcf_alwd_amt || p_mn_cvg_rqd_amt;
1515      l_pln_lbr_itms := l_pln_lbr_itms || p_mx_cvg_alwd_amt || p_mx_cvg_rl ||p_mn_cvg_rl ;
1516      --
1517      IF l_pln_lbr_itms is not null then
1518        p_ctfn_rqd := 'Y';
1519      ELSE
1520        p_ctfn_rqd :='N';
1521      END if;
1522      --
1523   END if;
1524   --
1525   hr_utility.set_location ('p_ctfn_rqd '||p_ctfn_rqd,10);
1526   hr_utility.set_location ('Leaving '||l_package,10);
1527   --
1528 END chk_bnft_ctfn;
1529 --
1530 ------------------------------------------------------------------------------
1531 --
1532 PROCEDURE main
1533   (p_calculate_only_mode    in     boolean
1534   ,p_elig_per_elctbl_chc_id IN     number
1535   ,p_effective_date         IN     date
1536   ,p_lf_evt_ocrd_dt         IN     date
1537   ,p_perform_rounding_flg   IN     boolean
1538   --
1539   ,p_enb_valrow                out nocopy ben_determine_coverage.ENBValType
1540   )
1541 is
1542   --
1543   l_package varchar2(80) := g_package||'.main';
1544   l_object_version_number number;
1545   l_value number;
1546   l_compensation_value number;
1547   l_dummy_number number;
1548   l_dummy_char varchar2(30);
1549   l_combined_val number;
1550   l_calculated_val number;
1551   l_vr_val number;
1552   l_vr_trtmt_cd varchar2(30);
1553   l_outputs  ff_exec.outputs_t;
1554   l_dflt_flag varchar2(30) := 'N';
1555   i number;
1556   l_incr_r_decr_cd varchar2(15);
1557   l_order_number number := 1;
1558   l_crnt_ordr_num number := null;
1559   l_bnft_amt number := null;
1560   l_write_rec boolean := true;
1561   l_ctfn_rqd varchar2(15) := 'N';
1562   l_ctfn_rqd2 varchar2(15) := 'N';
1563   l_elctbl_chc_ctfn_id    number;
1564   l_rstrn_found boolean := false;
1565   l_oipl_id varchar2(30);
1566   l_business_group_id varchar2(30);
1567   l_pl_id varchar2(30);
1568   l_ler_id varchar2(30);
1569   l_ler_bnft_rstrn_id varchar2(30);
1570   l_person_id varchar2(30);
1571   l_enrt_bnft_id number;
1572   l_dflt_val number;
1573   l_dflt_enrt_cd varchar2(30);
1574   l_dflt_enrt_rl number;
1575   l_jurisdiction_code     varchar2(30);
1576   l_effective_date        date;
1577   -- FONM
1578   l_fonm_cvg_strt_dt          date;
1579   l_perform_rounding_flg boolean := p_perform_rounding_flg;
1580   l_ultmt_upr_lmt         number ;
1581   l_ultmt_lwr_lmt         number ;
1582   l_ultmt_upr_lmt_calc_rl number ;
1583   l_ultmt_lwr_lmt_calc_rl number ;
1584   l_vapro_exist           varchar2(30) ;
1585   l_cvg_amount            number ;
1586   l_vr_ann_mn_elcn_val    number;
1587   l_vr_ann_mx_elcn_val    number;
1588   l_mn_elcn_val           number;
1589   l_mx_elcn_val           number;
1590   l_incrmnt_elcn_val      number;
1591   l_dflt_elcn_val         number;
1592   l_interim_bnft_val      number; /*ENH*/
1593   l_upr_val               number;
1594   l_lwr_val               number;
1595   l_upr_outputs           ff_exec.outputs_t;
1596   l_lwr_outputs           ff_exec.outputs_t;
1597   l_ult_lwr_outputs       ff_exec.outputs_t;
1598   --
1599   /* Start of Changes for WWBUG: 2054078                */
1600   l_mx_cvg_wout_ctfn_val  number;
1601   /* End of Changes for WWBUG: 2054078                  */
1602   --
1603   l_inst_count pls_integer;
1604 
1605   --Bug 4644489
1606   l_rstrn_mn_cvg_rqd_amt number;
1607 --End Bug 4644489
1608 
1609 -- 5529258
1610      l_dflt_to_asn_pndg_ctfn_cd  ben_pl_f.DFLT_TO_ASN_PNDG_CTFN_CD%type;
1611      l_INTERIM_ELCTBL_CHC_ID number;
1612      l_INTERIM_BNFT_AMT number;
1613 
1614 -- ends 5529258
1615   --
1616   cursor c_epe is
1617     select pil.person_id,
1618            epe.prtt_enrt_rslt_id, --5529258
1619            epe.pgm_id,
1620            epe.pl_id,
1621            epe.pl_typ_id,
1622            epe.oipl_id,
1623            epe.plip_id,
1624            epe.ptip_id,
1625            epe.dflt_flag,
1626            pil.per_in_ler_id,
1627            pil.ler_id,
1628            epe.business_group_id,
1629            epe.crntly_enrd_flag,
1630            epe.elctbl_flag,
1631            epe.object_version_number
1632     from   ben_elig_per_elctbl_chc epe,
1633            ben_per_in_ler pil
1634     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
1635     and    epe.per_in_ler_id = pil.per_in_ler_id ;
1636   --
1637   --bug 1895846 to check for the pending work flow or suspended enrollment results
1638   --
1639   cursor c_epe_in_pndg is
1640     select null
1641     from   ben_elig_per_elctbl_chc epe,
1642            ben_per_in_ler pil
1643     where  epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
1644     and    epe.per_in_ler_id = pil.per_in_ler_id
1645     and    nvl(epe.in_pndg_wkflow_flag,'N') <> 'N' ;
1646   --
1647   l_dummy  varchar2(30):= null ;
1648 
1649   l_epe c_epe%rowtype;
1650   --
1651   -- FONM
1652   cursor c_opt(rqd_oipl_id number, cv_effective_date date) is
1653     select opt_id
1654     from   ben_oipl_f
1655     where  oipl_id = rqd_oipl_id
1656     and    cv_effective_date -- nvl(p_lf_evt_ocrd_dt,p_effective_date)
1657            between effective_start_date
1658            and     effective_end_date;
1659   --
1660   l_opt c_opt%rowtype;
1661   --
1662 
1663 
1664   cursor c_ler_rstrn(cv_effective_date date) is -- FONM
1665     select rstrn.ler_bnft_rstrn_id,
1666            rstrn.pl_id,
1667            rstrn.cvg_incr_r_decr_only_cd,
1668            rstrn.mx_cvg_wcfn_amt,
1669            rstrn.mx_cvg_wcfn_mlt_num,
1670            rstrn.mx_cvg_mlt_incr_num,
1671            rstrn.mx_cvg_mlt_incr_wcf_num,
1672            rstrn.mx_cvg_incr_alwd_amt,
1673            rstrn.mx_cvg_incr_wcf_alwd_amt,
1674            rstrn.mn_cvg_amt mn_cvg_rqd_amt,
1675            rstrn.mx_cvg_alwd_amt,
1676            rstrn.mx_cvg_rl,
1677            rstrn.mn_cvg_rl,
1678            rstrn.no_mn_cvg_incr_apls_flag no_mn_cvg_amt_apls_flag,
1679            rstrn.no_mx_cvg_amt_apls_flag no_mx_cvg_amt_apls_flag,
1680            rstrn.dflt_to_asn_pndg_ctfn_cd, /*ENH*/
1681            rstrn.dflt_to_asn_pndg_ctfn_rl -- 5529258
1682     from   ben_ler_bnft_rstrn_f rstrn
1683     where  rstrn.ler_id = l_ler_id
1684     and    rstrn.pl_id  = l_pl_id
1685     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1686            between rstrn.effective_start_date
1687            and     rstrn.effective_end_date;
1688   --
1689   cursor c_pl_rstrn(cv_effective_date date) is -- FONM
1690     select null ler_bnft_rstrn_id,
1691            pln.pl_id,
1692            pln.cvg_incr_r_decr_only_cd,
1693            pln.mx_cvg_wcfn_amt,
1694            pln.mx_cvg_wcfn_mlt_num,
1695            pln.mx_cvg_mlt_incr_num,
1696            pln.mx_cvg_mlt_incr_wcf_num,
1697            pln.mx_cvg_incr_alwd_amt,
1698            pln.mx_cvg_incr_wcf_alwd_amt,
1699            pln.mn_cvg_rqd_amt,
1700            pln.mx_cvg_alwd_amt,
1701            pln.mx_cvg_rl,
1702            pln.mn_cvg_rl,
1703            pln.no_mn_cvg_amt_apls_flag,
1704            pln.no_mx_cvg_amt_apls_flag,
1705            pln.dflt_to_asn_pndg_ctfn_cd, /*ENH*/
1706 	   pln.dflt_to_asn_pndg_ctfn_rl  --5529258
1707     from   ben_pl_f pln
1708     where  pln.pl_id = l_pl_id
1709     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1710            between pln.effective_start_date
1711            and     pln.effective_end_date;
1712   --
1713   l_rstrn c_ler_rstrn%rowtype;
1714   --
1715   cursor c_ler_rstrn_ctfn(cv_effective_date date) is -- FONM
1716     select ctfn.rqd_flag,
1717            ctfn.enrt_ctfn_typ_cd,
1718            ctfn.ctfn_rqd_when_rl,
1719            lbr.ctfn_determine_cd
1720     from   ben_ler_bnft_rstrn_ctfn_f ctfn, ben_ler_bnft_rstrn_f lbr     -- Bug 5887665
1721     where  ctfn.ler_bnft_rstrn_id = l_ler_bnft_rstrn_id
1722     and    ctfn.ler_bnft_rstrn_id = lbr.ler_bnft_rstrn_id
1723     and    ctfn.business_group_id = l_business_group_id
1724     and    lbr.business_group_id = l_business_group_id
1725     and    cv_effective_date
1726            between lbr.effective_start_date
1727            and     lbr.effective_end_date
1728     and    cv_effective_date      -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1729            between ctfn.effective_start_date
1730            and     ctfn.effective_end_date;
1731   --
1732   cursor c_pl_rstrn_ctfn(cv_effective_date date) is -- FONM
1733     select ctfn.rqd_flag,
1734            ctfn.enrt_ctfn_typ_cd,
1735            ctfn.ctfn_rqd_when_rl,
1736            pln.ctfn_determine_cd
1737     from   ben_bnft_rstrn_ctfn_f ctfn, ben_pl_f pln       -- Bug 5887675
1738     where  ctfn.pl_id = l_pl_id
1739     and    ctfn.pl_id = pln.pl_id
1740     and    ctfn.business_group_id = l_business_group_id
1741     and    pln.business_group_id = l_business_group_id
1742     and    cv_effective_date
1743            between pln.effective_start_date
1744            and     pln.effective_end_date
1745     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1746            between ctfn.effective_start_date
1747            and     ctfn.effective_end_date;
1748   --
1749   l_cvg    ben_cvg_cache.g_epeplncvg_cache;
1750   --
1751   cursor c_asg(cv_effective_date date) is -- FONM
1752     select asg.assignment_id,asg.organization_id
1753     from   per_all_assignments_f asg
1754     where  asg.person_id = l_epe.person_id
1755     and    asg.primary_flag = 'Y'
1756     and    asg.assignment_type <> 'C'
1757     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1758            between asg.effective_start_date
1759            and    asg.effective_end_date
1760     order  by decode(asg.assignment_type, 'E',1,'B',2,3);
1761   --
1762   l_asg c_asg%rowtype;
1763   --
1764   cursor c_state (cv_effective_date date) is -- FONM
1765     select region_2
1766     from   hr_locations_all loc,
1767            per_all_assignments_f asg
1768     where  loc.location_id = asg.location_id
1769     and    asg.person_id = l_epe.person_id
1770     and    asg.primary_flag = 'Y'
1771     and    asg.assignment_type <> 'C'
1772     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1773            between asg.effective_start_date
1774            and     asg.effective_end_date
1775     order  by decode(asg.assignment_type, 'E',1,'B',2,3);
1776   --
1777   l_state c_state%rowtype;
1778   --
1779   -- bug 2560721 - added another return value from the cursor c_current_enrt to determine
1780   -- if the person is previously enrolled or New enrollment, becos bnft_amt and bnft_ordr_num
1781   -- can both be null even if the person is enrolled. This might occur when the coverage is
1782   -- not defined for the plan during his previous enrollment.
1783   --
1784   l_current_enrt_present char;
1785   --
1786   cursor c_current_enrt(cv_effective_date date) is -- FONM
1787     select bnft_ordr_num,
1788            bnft_amt,
1789            'Y'
1790     from   ben_prtt_enrt_rslt_f
1791     where  business_group_id = l_business_group_id
1792     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1793            between enrt_cvg_strt_dt
1794            and     enrt_cvg_thru_dt
1795     and    enrt_cvg_thru_dt <= effective_end_date
1796     and    prtt_enrt_rslt_stat_cd is null
1797     and    sspndd_flag = 'N'
1798     and    l_person_id = person_id
1799     and    l_pl_id = pl_id
1800     and    ((l_oipl_id is null and oipl_id is null) or
1801             l_oipl_id = oipl_id)
1802     order by decode(sspndd_flag,'Y',1,2) ; --CF Changes
1803   --
1804   cursor c_current_enrt_sspndd(cv_effective_date date) is -- FONM
1805     select bnft_ordr_num,
1806            bnft_amt,
1807            'Y'
1808     from   ben_prtt_enrt_rslt_f
1809     where  business_group_id = l_business_group_id
1810     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1811            between enrt_cvg_strt_dt
1812            and     enrt_cvg_thru_dt
1813     and    enrt_cvg_thru_dt <= effective_end_date
1814     and    prtt_enrt_rslt_stat_cd is null
1815     and    sspndd_flag = 'Y'
1816     and    l_person_id = person_id
1817     and    l_pl_id = pl_id
1818     and    ((l_oipl_id is null and oipl_id is null) or
1819             l_oipl_id = oipl_id)
1820     order by decode(sspndd_flag,'Y',1,2) ; --CF Changes
1821   --
1822   l_current_enrt_sspndd c_current_enrt_sspndd%rowtype;
1823   --
1824   /*ENH*/
1825   cursor c_current_enrt_in_pl_typ(c_pl_typ_id number,cv_effective_date date) is -- FONM
1826     select pl_id,oipl_id
1827     from   ben_prtt_enrt_rslt_f
1828     where  business_group_id = l_business_group_id
1829     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1830            between enrt_cvg_strt_dt
1831            and     enrt_cvg_thru_dt
1832     and    enrt_cvg_thru_dt <= effective_end_date
1833     and    sspndd_flag = 'N'
1834     and    prtt_enrt_rslt_stat_cd is null
1835     and    l_person_id = person_id
1836     and    c_pl_typ_id = pl_typ_id ;
1837   --
1838   cursor c_current_enrt_in_pln( c_pl_id number,cv_effective_date date ) is -- FONM
1839     select pl_id,oipl_id
1840     from   ben_prtt_enrt_rslt_f
1841     where  business_group_id = l_business_group_id
1842     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1843            between enrt_cvg_strt_dt
1844            and     enrt_cvg_thru_dt
1845     and    enrt_cvg_thru_dt <= effective_end_date
1846     and    sspndd_flag = 'N'
1847     and    prtt_enrt_rslt_stat_cd is null
1848     and    l_person_id = person_id
1849     and    c_pl_id = pl_id ;
1850   --
1851   cursor c_current_enrt_in_oipl( c_oipl_id number, cv_effective_date date ) is -- FONM
1852     select pl_id,oipl_id
1853     from   ben_prtt_enrt_rslt_f
1854     where  business_group_id = l_business_group_id
1855     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1856            between enrt_cvg_strt_dt
1857            and     enrt_cvg_thru_dt
1858     and    enrt_cvg_thru_dt <= effective_end_date
1859     and    sspndd_flag = 'N'
1860     and    prtt_enrt_rslt_stat_cd is null
1861     and    l_person_id = person_id
1862     and    c_oipl_id = oipl_id ;
1863   --
1864   -- CF Changes
1865   cursor c_current_enb(c_pl_id number,c_oipl_id number, cv_effective_date date ) is -- FONM
1866     select
1867            pen.bnft_amt,
1868            enb.*
1869     from   ben_prtt_enrt_rslt_f pen,
1870            ben_enrt_bnft enb,
1871            ben_elig_per_elctbl_chc epe,
1872            ben_per_in_ler pil
1873     where  pen.business_group_id = l_business_group_id
1874     and    cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1875            between pen.enrt_cvg_strt_dt
1876            and     pen.enrt_cvg_thru_dt
1877     and    pen.enrt_cvg_thru_dt <= pen.effective_end_date
1878     and    pen.prtt_enrt_rslt_stat_cd is null
1879     and    pen.sspndd_flag = 'N' ---CF Changes
1880     and    l_person_id = pen.person_id
1881     and    c_pl_id = pen.pl_id
1882     and    ((c_oipl_id is null and pen.oipl_id is null) or
1883             c_oipl_id = pen.oipl_id)
1884     and    pen.prtt_enrt_rslt_id = enb.prtt_enrt_rslt_id
1885     and    pen.bnft_ordr_num     = enb.ordr_num
1886     and    enb.elig_per_elctbl_chc_id = epe.elig_per_elctbl_chc_id
1887     and    epe.per_in_ler_id  = pil.per_in_ler_id
1888     and    pil.per_in_ler_stat_cd = 'PROCD'
1889     and    pil.person_id = l_person_id ;
1890   --
1891   l_current_enb   c_current_enb%rowtype;
1892   --
1893   cursor c_clf(p_comp_lvl_fctr_id in number) is
1894     select clf.comp_src_cd,
1895            clf.name
1896     from   ben_comp_lvl_fctr clf
1897     where  p_comp_lvl_fctr_id = clf.comp_lvl_fctr_id;
1898   --
1899   l_clf c_clf%rowtype;
1900   --
1901   l_not_found boolean;
1902   --
1903   l_commit number;
1904   l_val number;
1905   --
1906   l_check_received boolean:=false;
1907   l_ctfn_received varchar2(30) := 'N';
1908   l_interim_cd varchar2(30) :=  'DF' ;  /*ENH I am defaulting to Default Val */
1909   l_current_level_cd varchar2(30) := null;
1910   l_create_current_enb boolean := false ;
1911   l_current_plan_id   number := null;
1912   l_current_oipl_id number := null;
1913   l_entr_val_at_enrt_flag  varchar2(10); -- Bug 7414757
1914 
1915   --
1916 cursor c_ctfn_received(
1917             p_pgm_id           in number,
1918             p_pl_id            in number,
1919             p_enrt_ctfn_typ_cd in varchar2,
1920             p_person_id        in number,
1921             cv_effective_date   in date ) is -- FONM
1922     select 'Y'
1923     from
1924          ben_prtt_enrt_rslt_f pen,
1925          ben_prtt_enrt_actn_f pea,
1926          ben_per_in_ler pil,
1927          ben_prtt_enrt_ctfn_prvdd_f ecp
1928    where
1929           -- pen
1930           pen.person_id=p_person_id
1931       and pen.business_group_id = l_business_group_id
1932       and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date) between
1933           between pen.effective_start_date and pen.effective_end_date
1934       and pen.pl_id=p_pl_id
1935       and nvl(pen.pgm_id,-1)=nvl(p_pgm_id,-1)
1936       and pen.prtt_enrt_rslt_stat_cd is null
1937           -- pea
1938       and pea.prtt_enrt_rslt_id=pen.prtt_enrt_rslt_id
1939       and pea.business_group_id=pen.business_group_id
1940       and pea.pl_bnf_id is null
1941       and pea.elig_cvrd_dpnt_id is null
1942       and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1943           between pea.effective_start_date
1944           and pea.effective_end_date
1945           -- pil
1946       and pil.per_in_ler_id=pea.per_in_ler_id
1947       and pil.business_group_id=pea.business_group_id
1948       and pil.per_in_ler_stat_cd not in ('VOIDD', 'BCKDT')
1949           -- ecp
1950       and ecp.prtt_enrt_rslt_id = pen.prtt_enrt_rslt_id
1951       and ecp.prtt_enrt_actn_id=pea.prtt_enrt_actn_id
1952       and ecp.enrt_ctfn_recd_dt is not null
1953       and ecp.business_group_id = pen.business_group_id
1954       and cv_effective_date -- FONM nvl(p_lf_evt_ocrd_dt,p_effective_date)
1955           between ecp.effective_start_date
1956                                and ecp.effective_end_date
1957       and ecp.enrt_ctfn_typ_cd=p_enrt_ctfn_typ_cd
1958       --Bug 3132792 only if the benefit amount is more that the combined value
1959       -- we need to return 'Y' for the certification received flag
1960       and pen.bnft_amt >= l_combined_val
1961     ;
1962    l_tot_val number;
1963     --Unrestricted enh
1964   cursor c_unrest(p_ler_id  number)  is
1965     select 'Y'
1966     from ben_ler_f ler
1967     where ler.typ_cd = 'SCHEDDU'
1968     and   ler.ler_id = p_ler_id
1969     and   p_effective_date between ler.effective_start_date
1970          and ler.effective_end_date;
1971   --
1972   -- Bug 3828288
1973   l_mx_val_wcfn                 number;
1974   l_mx_val_wo_cfn               number;
1975   l_ccm_max_val                 number;
1976   l_cvg_rstn_max_incr_wout_cert number;
1977   l_cvg_rstn_max_incr_with_cert number;
1978   l_cvg_rstn_max_wout_cert      number;
1979   l_cvg_rstn_max_with_cert      number;
1980   -- Bug 3828288
1981   --
1982   ----Bug 7704956
1983   cursor c_check_dup_enb_enr(p_epe_id number) is
1984   SELECT enb.*
1985   FROM ben_enrt_bnft enb
1986  WHERE  elig_per_elctbl_chc_id = p_epe_id
1987    AND crntly_enrld_flag = 'Y';
1988 
1989   l_check_dup_enb_enr   c_check_dup_enb_enr%rowtype;
1990   l_dup_enr_count  number := 0;
1991   l_chk_bnft_id    number;
1992 
1993   cursor c_get_prev_bnft(cv_effective_date date) is
1994   SELECT  pen.prtt_enrt_rslt_id,
1995           pen.bnft_amt,
1996           pen.bnft_ordr_num
1997       FROM     ben_prtt_enrt_rslt_f pen
1998       WHERE    pen.prtt_enrt_rslt_id = l_epe.prtt_enrt_rslt_id
1999       and      pen.business_group_id = l_epe.business_group_id
2000       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
2001       AND      pen.effective_end_date = hr_api.g_eot
2002       AND      cv_effective_date <= pen.enrt_cvg_thru_dt
2003       AND      pen.enrt_cvg_strt_dt < pen.effective_end_date
2004       AND      NVL(l_epe.oipl_id,-1) = NVL(pen.oipl_id,-1)
2005       AND      l_epe.pl_id   = pen.pl_id
2006       AND      NVL(l_epe.pgm_id,-1)  = NVL(pen.pgm_id,-1)
2007       AND      (pen.sspndd_flag = 'N'
2008                  OR (pen.sspndd_flag = 'Y' and
2009                      pen.enrt_cvg_thru_dt = hr_api.g_eot
2010                     )
2011                )
2012     order by pen.enrt_cvg_strt_dt;
2013   l_get_prev_bnft  c_get_prev_bnft%rowtype;
2014 
2015   ---------Enhancement	8716693
2016   cursor c_get_pil_elctbl is
2017   SELECT pil.per_in_ler_id,
2018          epe.pl_id,
2019 	 epe.oipl_id,
2020 	 epe.pgm_id,
2021 	 epe.pl_typ_id
2022   FROM ben_per_in_ler pil,
2023        ben_elig_per_elctbl_chc epe
2024  WHERE pil.business_group_id = epe.business_group_id
2025    AND pil.per_in_ler_id = epe.per_in_ler_id
2026    AND epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
2027    AND epe.crntly_enrd_flag = 'Y';
2028 
2029   l_get_pil_elctbl   c_get_pil_elctbl%rowtype;
2030 
2031   cursor c_get_prev_pil(p_person_id number) is
2032   SELECT pil.*
2033     FROM ben_per_in_ler pil,
2034          ben_ler_f ler
2035    WHERE pil.person_id = p_person_id
2036      AND pil.ler_id = ler.ler_id
2037      AND ler.business_group_id = pil.business_group_id
2038      AND ler.typ_cd NOT IN ('IREC','GSP','COMP','ABS','SCHEDDU')
2039      AND pil.per_in_ler_stat_cd = 'PROCD'
2040      AND pil.lf_evt_ocrd_dt < p_lf_evt_ocrd_dt
2041  ORDER BY pil.lf_evt_ocrd_dt  desc;
2042 
2043   l_get_prev_pil   c_get_prev_pil%rowtype;
2044 
2045   cursor c_chk_prev_sus_enr( p_pil_id number,
2046                              p_pgm_id number,
2047 			     p_pl_id number,
2048 			     p_oipl_id number) is
2049   SELECT null
2050   FROM ben_prtt_enrt_rslt_f pen
2051  WHERE pen.per_in_ler_id = p_pil_id
2052    AND pen.sspndd_flag = 'Y'
2053    AND pen.prtt_enrt_rslt_stat_cd IS NULL
2054    AND Nvl(pen.pgm_id,-1) = nvl(p_pgm_id,-1)
2055    AND pen.pl_id = p_pl_id
2056    AND Nvl(pen.oipl_id,-1) = nvl(p_oipl_id,-1)
2057    and pen.enrt_cvg_thru_dt = hr_api.g_eot
2058    and pen.effective_end_date  = hr_api.g_eot;
2059 
2060   l_chk_prev_sus_enr   c_chk_prev_sus_enr%rowtype;
2061 
2062   cursor c_get_cvg_rstr(p_prev_pil_id number) is
2063   SELECT enb1.*
2064     FROM ben_elig_per_elctbl_chc epe,
2065          ben_elig_per_elctbl_chc epe1,
2066          ben_enrt_bnft enb1
2067    WHERE epe.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
2068      AND epe.crntly_enrd_flag = 'Y'
2069      AND epe1.per_in_ler_id = p_prev_pil_id
2070      AND epe1.pl_id = epe.pl_id
2071      AND Nvl(epe1.oipl_id,-1) = Nvl(epe.oipl_id,-1)
2072      AND epe1.pgm_id = epe.pgm_id
2073      AND epe1.business_group_id = epe.business_group_id
2074      AND enb1.elig_per_elctbl_chc_id = epe1.elig_per_elctbl_chc_id
2075      AND enb1.business_group_id = epe.business_group_id;
2076 
2077    l_get_cvg_rstr  c_get_cvg_rstr%rowtype;
2078    l_force_rstr    boolean := false;
2079    l_cert_rstr  c_ler_rstrn_ctfn%rowtype;
2080 
2081   -- cursor c_prev_le_cert(p_business_group_id number,p_epe_id number) is
2082   ---Bug 8767376
2083   cursor c_prev_le_cert(p_business_group_id number,p_epe_id number,p_val number) is
2084    SELECT ecc.*
2085     FROM ben_elctbl_chc_ctfn ecc
2086    WHERE ecc.business_group_id = p_business_group_id
2087      AND ecc.elig_per_elctbl_chc_id = p_epe_id
2088      ---Added for the bug 8767376
2089      and l_cvg(0).cvg_mlt_cd not in  ('CLRNG','FLPCLRNG','CLPFLRNG','FLRNG')
2090    union
2091    SELECT ecc.*
2092     FROM ben_elctbl_chc_ctfn ecc,
2093          ben_enrt_bnft enb
2094    WHERE ecc.elig_per_elctbl_chc_id = p_epe_id
2095      AND ecc.business_group_id = p_business_group_id
2096      AND enb.business_group_id = ecc.business_group_id
2097      AND enb.elig_per_elctbl_chc_id = ecc.elig_per_elctbl_chc_id
2098      AND enb.enrt_bnft_id = ecc.enrt_bnft_id
2099      AND nvl(enb.val,-1) = nvl(p_val,-1)
2100      AND ecc.enrt_bnft_id IS NOT NULL
2101      and  l_cvg(0).cvg_mlt_cd in ('CLRNG','FLPCLRNG','CLPFLRNG','FLRNG');
2102 
2103    l_prev_le_cert   c_prev_le_cert%rowtype;
2104 
2105    cursor c_chk_bnft_cert(p_business_group_id number) is
2106    SELECT NULL
2107     FROM ben_elctbl_chc_ctfn ecc,
2108          ben_enrt_bnft enb   ---Added for the bug 8767376
2109    WHERE ecc.elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id
2110      AND ecc.business_group_id = p_business_group_id
2111       ---Added for the bug 8767376
2112      AND enb.business_group_id = ecc.business_group_id
2113      AND enb.elig_per_elctbl_chc_id = ecc.elig_per_elctbl_chc_id
2114      AND enb.enrt_bnft_id = ecc.enrt_bnft_id
2115      AND enb.crntly_enrld_flag = 'Y'
2116      AND ecc.enrt_bnft_id IS NOT NULL;
2117 
2118    l_chk_bnft_cert   c_chk_bnft_cert%rowtype;
2119    l_carry_fwd_cert   varchar2(1) := 'N';
2120   ---------------Enhancement 8716693
2121 
2122   procedure write_ctfn is
2123 
2124   --Bug 14137476
2125 
2126   cursor c is
2127     select ENTR_VAL_AT_ENRT_FLAG
2128       from ben_enrt_bnft
2129      where enrt_bnft_id = l_enrt_bnft_id;
2130 
2131   l_proc varchar2(70) :='ben_determine_coverage.write_ctfn';
2132   l_entr_val_at_enrt_flag varchar2(1):= 'N';
2133 
2134   --Bug 14137476
2135   begin
2136     --
2137     -- ctfn's at the option level are written in benchctf.pkb
2138     -- don't write them at the bnft level too.  Bug 1277371.
2139 	hr_utility.set_location('Entering '||l_proc,10);
2140 	--Bug 14137476
2141     if l_enrt_bnft_id is not null
2142     then
2143         open c;
2144         fetch c into l_entr_val_at_enrt_flag;
2145         close c;
2146     end if;
2147 	--Bug 14137476
2148     --
2149     hr_utility.set_location('IK l_combined_val '||l_combined_val,20);
2150     hr_utility.set_location('IK l_enrt_bnft_id '||l_enrt_bnft_id,20);
2151     hr_utility.set_location('IK p_elig_per_elctbl_chc_id '||p_elig_per_elctbl_chc_id,20);
2152     --
2153     if l_ler_bnft_rstrn_id is not null  then
2154       for l_ctfn in c_ler_rstrn_ctfn(nvl(l_fonm_cvg_strt_dt,l_effective_date)) loop -- FONM
2155         l_ctfn_received:='N';
2156         if l_check_received then
2157           open c_ctfn_received(
2158             p_pgm_id           =>l_epe.pgm_id,
2159             p_pl_id            =>l_epe.pl_id,
2160             p_enrt_ctfn_typ_cd =>l_ctfn.enrt_ctfn_typ_cd,
2161             p_person_id        =>l_epe.person_id,
2162             cv_effective_date   =>nvl(l_fonm_cvg_strt_dt, l_effective_date) -- FONM
2163           );
2164           fetch c_ctfn_received into l_ctfn_received;
2165           close c_ctfn_received;
2166         end if;
2167 
2168         --Bug 14137476
2169         if (l_ctfn_received = 'Y' and l_entr_val_at_enrt_flag = 'Y')
2170         then
2171             l_ctfn_received := 'N';
2172         end if ;
2173 		--Bug 14137476
2174 
2175         if l_ctfn_received='N' then
2176           ben_determine_chc_ctfn.write_ctfn
2177            (p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
2178             p_enrt_bnft_id           => l_enrt_bnft_id,
2179             p_enrt_ctfn_typ_cd       => l_ctfn.enrt_ctfn_typ_cd,
2180             p_rqd_flag               => l_ctfn.rqd_flag,
2181             p_ctfn_rqd_when_rl       => l_ctfn.ctfn_rqd_when_rl,
2182             p_business_group_id      => l_epe.business_group_id,
2183             p_effective_date         => l_effective_date, -- FONM  nvl(p_lf_evt_ocrd_dt,p_effective_date),
2184             p_assignment_id          => l_asg.assignment_id,
2185             p_organization_id        => l_asg.organization_id,
2186             p_jurisdiction_code      => l_jurisdiction_code,
2187             p_pgm_id                 => l_epe.pgm_id,
2188             p_pl_id                  => l_epe.pl_id,
2189             p_pl_typ_id              => l_epe.pl_typ_id,
2190             p_opt_id                 => l_opt.opt_id,
2191             p_ler_id                 => l_epe.ler_id,
2192 	    p_ctfn_determine_cd      => l_ctfn.ctfn_determine_cd);     -- Bug 5887665
2193         end if;
2194       end loop;
2195       --
2196     else
2197       hr_utility.set_location('IK Else Write CTFN',99);
2198       --
2199       for l_ctfn in c_pl_rstrn_ctfn ( nvl(l_fonm_cvg_strt_dt, l_effective_date)) loop -- FONM
2200         l_ctfn_received:='N';
2201         if l_check_received then
2202           hr_utility.set_location('IK Check ctfn TRUE',89);
2203           open c_ctfn_received(
2204             p_pgm_id           =>l_epe.pgm_id,
2205             p_pl_id            =>l_epe.pl_id,
2206             p_enrt_ctfn_typ_cd =>l_ctfn.enrt_ctfn_typ_cd,
2207             p_person_id        =>l_epe.person_id,
2208             cv_effective_date  => nvl(l_fonm_cvg_strt_dt,l_effective_date) -- FONM
2209           );
2210           fetch c_ctfn_received into l_ctfn_received;
2211           close c_ctfn_received;
2212         end if;
2213         if l_ctfn_received='N' then
2214           --
2215           hr_utility.set_location('IK l_ctfn_received=N',99) ;
2216           --
2217           ben_determine_chc_ctfn.write_ctfn
2218            (p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
2219             p_enrt_bnft_id           => l_enrt_bnft_id,
2220             p_enrt_ctfn_typ_cd       => l_ctfn.enrt_ctfn_typ_cd,
2221             p_rqd_flag               => l_ctfn.rqd_flag,
2222             p_ctfn_rqd_when_rl       => l_ctfn.ctfn_rqd_when_rl,
2223             p_business_group_id      => l_epe.business_group_id,
2224             p_effective_date         => l_effective_date, -- FONM  nvl(p_lf_evt_ocrd_dt,p_effective_date),
2225             p_assignment_id          => l_asg.assignment_id,
2226             p_organization_id        => l_asg.organization_id,
2227             p_jurisdiction_code      => l_jurisdiction_code,
2228             p_pgm_id                 => l_epe.pgm_id,
2229             p_pl_id                  => l_epe.pl_id,
2230             p_pl_typ_id              => l_epe.pl_typ_id,
2231             p_opt_id                 => l_opt.opt_id,
2232             p_ler_id                 => l_epe.ler_id,
2233 	    p_ctfn_determine_cd      => l_ctfn.ctfn_determine_cd);     -- Bug 5887665
2234          end if;
2235        end loop;
2236     end if;
2237     ----Enhancement 8716693
2238 
2239     if l_force_rstr and nvl(l_carry_fwd_cert,'N') = 'Y' then
2240        ---Check if there is any electable choice certification created for the current epe
2241        open c_chk_bnft_cert(l_epe.business_group_id);
2242        fetch c_chk_bnft_cert into l_chk_bnft_cert;
2243        if c_chk_bnft_cert%notfound then
2244           hr_utility.set_location('bnft cert not found',99) ;
2245 	  hr_utility.set_location('get the previous LE cert',99) ;
2246           for l_prev_le_cert in c_prev_le_cert( l_get_cvg_rstr.business_group_id,
2247 	                                        l_get_cvg_rstr.elig_per_elctbl_chc_id,l_combined_val) loop --Bug 8767376
2248 	     hr_utility.set_location('l_get_cvg_rstr.elig_per_elctbl_chc_id : '||l_get_cvg_rstr.elig_per_elctbl_chc_id,99) ;
2249 
2250 	     l_ctfn_received:='N';
2251 	     open c_ctfn_received(
2252                  p_pgm_id           =>l_epe.pgm_id,
2253 		 p_pl_id            =>l_epe.pl_id,
2254 		 p_enrt_ctfn_typ_cd =>l_prev_le_cert.enrt_ctfn_typ_cd,
2255 		 p_person_id        =>l_epe.person_id,
2256 		 cv_effective_date   =>nvl(l_fonm_cvg_strt_dt, l_effective_date) -- FONM
2257 				   );
2258 	      fetch c_ctfn_received into l_ctfn_received;
2259               close c_ctfn_received;
2260 	      hr_utility.set_location('l_ctfn_received : '||l_ctfn_received,99) ;
2261               if l_ctfn_received='N' then
2262 
2263 		 hr_utility.set_location('IK l_ctfn_received=N',99) ;
2264                  --
2265 		 hr_utility.set_location('p_elig_per_elctbl_chc_id : '||p_elig_per_elctbl_chc_id,99) ;
2266 		 hr_utility.set_location('l_prev_le_cert.enrt_ctfn_typ_cd : '||l_prev_le_cert.enrt_ctfn_typ_cd,99) ;
2267 		 hr_utility.set_location('l_enrt_bnft_id : '||l_enrt_bnft_id,99) ;
2268 		 hr_utility.set_location('l_prev_le_cert.enrt_ctfn_typ_cd : '||l_prev_le_cert.enrt_ctfn_typ_cd,99) ;
2269 		 ben_determine_chc_ctfn.write_ctfn
2270 			(p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
2271 			 p_enrt_bnft_id           => l_enrt_bnft_id,
2272 			p_enrt_ctfn_typ_cd       => l_prev_le_cert.enrt_ctfn_typ_cd,
2273 			p_rqd_flag               => l_prev_le_cert.rqd_flag,
2274 			p_ctfn_rqd_when_rl       => null,
2275 			p_business_group_id      => l_epe.business_group_id,
2276 			p_effective_date         => l_effective_date,
2277 			p_assignment_id          => l_asg.assignment_id,
2278 			p_organization_id        => l_asg.organization_id,
2279 			p_jurisdiction_code      => l_jurisdiction_code,
2280 			p_pgm_id                 => l_epe.pgm_id,
2281 			p_pl_id                  => l_epe.pl_id,
2282 			p_pl_typ_id              => l_epe.pl_typ_id,
2283 			p_opt_id                 => l_opt.opt_id,
2284 			p_ler_id                 => l_epe.ler_id,
2285 			p_ctfn_determine_cd      => l_prev_le_cert.ctfn_determine_cd);
2286 	      end if;
2287 	  end loop;
2288        end if;
2289        close c_chk_bnft_cert;
2290     end if;
2291     --------Enhancement	8716693
2292 
2293   end write_ctfn;
2294   --
2295 BEGIN
2296   --
2297   hr_utility.set_location ('Entering '||l_package,10);
2298   --
2299   --
2300   -- Bug 1895846
2301   open c_epe_in_pndg ;
2302     --
2303     fetch c_epe_in_pndg into l_dummy ;
2304     if c_epe_in_pndg%found then
2305       --
2306       hr_utility.set_location ('Suspended or Pending work flow records exist ' , 10);
2307       hr_utility.set_location ('Leaving '||l_package,10);
2308       close c_epe_in_pndg ;
2309       return ;
2310       --
2311     end if;
2312     close c_epe_in_pndg ;
2313     --
2314   -- put a row in fnd_sessions
2315   --
2316   g_old_val := hr_api.g_number; /*0;changed for 3497676 */
2317 
2318       /* when the 1st coverage is calculated as 0, the enrt bnft row was not
2319       being created because g_old_val is initialised to 0 */
2320   --
2321   -- Edit to insure that the input p_effective_date has a value
2322   --
2323   If (p_effective_date is null) then
2324     --
2325     fnd_message.set_name('BEN','BEN_91837_BENCVRGE_INPT_EFFDT');
2326     fnd_message.set_token('PACKAGE',l_package);
2327     fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',
2328                            to_char(p_elig_per_elctbl_chc_id));
2329     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
2330     fnd_message.raise_error;
2331     --
2332   end if;
2333   --
2334   -- Edit to insure that the input p_elig_per_elctbl_chc_id has a value
2335   --
2336   If (p_elig_per_elctbl_chc_id is null) then
2337     --
2338     fnd_message.set_name('BEN','BEN_91838_BENCVRGE_INPT_EC');
2339     fnd_message.set_token('PACKAGE',l_package);
2340     fnd_message.set_token('EFFECTIVE_DATE',p_effective_date);
2341     fnd_message.set_token('LF_EVT_OCRD_DT',p_lf_evt_ocrd_dt);
2342     fnd_message.raise_error;
2343     --
2344   end if;
2345   --
2346   -- Deduce effective date
2347   --
2348   if p_lf_evt_ocrd_dt is not null then
2349     --
2350     l_effective_date := p_lf_evt_ocrd_dt;
2351     --
2352   else
2353     --
2354     l_effective_date := p_effective_date;
2355     --
2356   end if;
2357   -- FONM
2358   if ben_manage_life_events.fonm = 'Y' then
2359      --
2360      l_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt;
2361      --
2362   end if;
2363   --
2364   -- put a row into fnd_sessions
2365   --
2366   dt_fndate.change_ses_date
2367     (p_ses_date => p_effective_date,
2368      p_commit   => l_commit);
2369   --
2370   l_not_found := false;
2371   --
2372   -- Walk the comp object tree for the electable choice and get
2373   -- the appropriate coverage details
2374   --
2375   hr_utility.set_location ('pl_id  '||ben_epe_cache.g_currcobjepe_row.pl_id,10);
2376   hr_utility.set_location ('elig choice id'||p_elig_per_elctbl_chc_id,11);
2377   ben_cvg_cache.epecobjtree_getcvgdets
2378     (p_epe_id         => p_elig_per_elctbl_chc_id
2379     ,p_epe_pl_id      => ben_epe_cache.g_currcobjepe_row.pl_id
2380     ,p_epe_plip_id    => ben_epe_cache.g_currcobjepe_row.plip_id
2381     ,p_epe_oipl_id    => ben_epe_cache.g_currcobjepe_row.oipl_id
2382     ,p_effective_date => nvl(l_fonm_cvg_strt_dt, l_effective_date) -- FONM  need to use new date
2383     --
2384     ,p_cvg_set        => l_cvg
2385     );
2386   --
2387 /*  if l_cvg.count = 0 then
2388     --
2389     return;
2390     --
2391   end if;
2392 */
2393   --
2394   hr_utility.set_location ('open c_epe ',10);
2395   open c_epe;
2396     --
2397     fetch c_epe into l_epe;
2398     --
2399     if c_epe%notfound then
2400       --
2401       close c_epe;
2402       fnd_message.set_name('BEN','BEN_91839_BENCVRGE_EPE_NF');
2403       fnd_message.set_token('PACKAGE',l_package);
2404       fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',
2405                              to_char(p_elig_per_elctbl_chc_id));
2406       fnd_message.raise_error;
2407       --
2408     end if;
2409     --
2410   close c_epe;
2411   hr_utility.set_location ('close c_epe ',10);
2412   hr_utility.set_location ('pl_id'||l_epe.pl_id,10);
2413   if p_calculate_only_mode then
2414     ben_cvg_cache.epecobjtree_getcvgdets
2415       (p_epe_id         => p_elig_per_elctbl_chc_id
2416       ,p_epe_pl_id      => l_epe.pl_id
2417       ,p_epe_plip_id    => l_epe.plip_id
2418       ,p_epe_oipl_id    => l_epe.oipl_id
2419       ,p_effective_date => nvl(l_fonm_cvg_strt_dt, l_effective_date) -- FONM need to pass new date
2420       ,p_cvg_set        => l_cvg
2421       );
2422   end if;
2423       --
2424   if l_cvg.count = 0 then
2425     --
2426     -- Bug 4954541 - For unrestricted, if no coverage found, then we should delete ENB record
2427     --               which we would have reused otherwise. If we dont delete ENB, then the rate
2428     --               gets tied to the ENB (which gets deleted later in bebmures.clear_cache()
2429     --               This leads to dangling ECR.
2430     --
2431     l_dummy := null;
2432     open c_unrest(l_epe.ler_id);
2433        fetch c_unrest into l_dummy;
2434     close c_unrest;
2435     --
2436     if l_dummy = 'Y'
2437     then
2438       --
2439       hr_utility.set_location('No Coverage For EPE_ID = ' || p_elig_per_elctbl_chc_id, 8787);
2440       l_enrt_bnft_id := ben_manage_unres_life_events.enb_exists(p_elig_per_elctbl_chc_id,1);
2441       hr_utility.set_location('l_enrt_bnft_id = ' || l_enrt_bnft_id, 8787);
2442       --
2443       IF l_enrt_bnft_id is not null
2444       THEN
2445          --
2446          delete from ben_enrt_Bnft
2447          where elig_per_elctbl_chc_id = p_elig_per_elctbl_chc_id;
2448          --
2449       END IF;
2450       --
2451     end if;
2452     --
2453     return;
2454     --
2455   end if;
2456   --
2457   l_person_id := l_epe.person_id;
2458   --
2459   if l_cvg(0).cvg_mlt_cd is null then
2460     --
2461     fnd_message.set_name('BEN','BEN_91840_BENCVRGE_MLT_CD_RQD');
2462     fnd_message.set_token('PACKAGE',l_package);
2463     fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
2464     fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
2465     fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
2466     fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
2467     fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
2468     fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
2469     fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
2470     fnd_message.set_token('ELIG_PER_ELCTBL_CHC_ID',
2471                            to_char(p_elig_per_elctbl_chc_id));
2472     fnd_message.raise_error;
2473     --
2474   end if;
2475   --
2476   if l_cvg(0).cvg_mlt_cd in ('FLFX','CL','FLPCLRNG','CLPFLRNG','FLFXPCL') then
2477     --
2478     if l_cvg(0).val is null and l_cvg(0).entr_val_at_enrt_flag = 'N' then
2479       --
2480       fnd_message.set_name('BEN','BEN_91841_BENCVRGE_VAL_RQD');
2481       fnd_message.set_token('PACKAGE',l_package);
2482       fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
2483       fnd_message.set_token('CALC_MTHD',l_cvg(0).cvg_mlt_cd);
2484       fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
2485       fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
2486       fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
2487       fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
2488       fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
2489       fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
2490       fnd_message.raise_error;
2491       --
2492     end if;
2493     --
2494   end if;
2495   --
2496   if l_cvg(0).cvg_mlt_cd in ('CLRNG','FLPCLRNG','CLPFLRNG','FLRNG') then
2497     --
2498     if l_cvg(0).mn_val is null or
2499        l_cvg(0).mx_val is null or
2500        l_cvg(0).incrmt_val is null then
2501       --
2502       fnd_message.set_name('BEN','BEN_91842_BENCVRGE_MX_MN_INC_R');
2503       fnd_message.set_token('PACKAGE',l_package);
2504       fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
2505       fnd_message.set_token('CALC_MTHD',l_cvg(0).cvg_mlt_cd);
2506       fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
2507       fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
2508       fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
2509       fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
2510       fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
2511       fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
2512       fnd_message.raise_error;
2513       --
2514     end if;
2515     --
2516   end if;
2517   --
2518   if l_cvg(0).cvg_mlt_cd in ('CL','CLRNG','FLFXPCL','FLPCLRNG','CLPFLRNG') then
2519     --
2520     if l_cvg(0).comp_lvl_fctr_id is null then
2521       --
2522       fnd_message.set_name('BEN','BEN_91843_BENCVRGE_NULL_CLF');
2523       fnd_message.set_token('PACKAGE',l_package);
2524       fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
2525       fnd_message.set_token('CALC_MTHD',l_cvg(0).cvg_mlt_cd);
2526       fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
2527       fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
2528       fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
2529       fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
2530       fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
2531       fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
2532       fnd_message.raise_error;
2533       --
2534     end if;
2535     --
2536     ben_derive_factors.determine_compensation
2537      (p_comp_lvl_fctr_id     => l_cvg(0).comp_lvl_fctr_id,
2538       p_person_id            => l_epe.person_id,
2539       p_pgm_id               => l_epe.pgm_id ,
2540       p_pl_id                => l_epe.pl_id,
2541       p_oipl_id              => l_epe.oipl_id,
2542       p_per_in_ler_id        => l_epe.per_in_ler_id,
2543       p_business_group_id    => l_epe.business_group_id,
2544       p_perform_rounding_flg => true,
2545       p_effective_date       => nvl(p_lf_evt_ocrd_dt,p_effective_date),
2546       p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt,
2547       p_calc_bal_to_date     => null ,
2548       p_cal_for              => 'R',
2549       p_value                => l_compensation_value,
2550       p_fonm_cvg_strt_dt     => l_fonm_cvg_strt_dt);
2551     --
2552     if l_compensation_value is null /*or l_compensation_value = 0 commented for 3497676 */ then
2553       --
2554       open c_clf(l_cvg(0).comp_lvl_fctr_id);
2555       fetch c_clf into l_clf;
2556       close c_clf;
2557 
2558       --
2559       fnd_message.set_name('BEN','BEN_92488_BENCVRGE_INVALID_VAL');
2560       fnd_message.set_token('PERSON_ID',l_epe.person_id);
2561       /*
2562       if l_clf.comp_src_cd = 'STTDCOMP' then
2563 
2564          fnd_message.set_token('COMP_CODE',' stated Salary, '||l_clf.name);
2565 
2566       elsif l_clf.comp_src_cd = 'BALTYP' then
2567 
2568          fnd_message.set_token('COMP_CODE',' benefits balance, '||l_clf.name);
2569 
2570       elsif  l_clf.comp_src_cd = 'BNFTBALTYP' then
2571 
2572          fnd_message.set_token('COMP_CODE',' defined balance, '||l_clf.name);
2573 
2574       end if;
2575       */
2576       --
2577       fnd_message.set_token('COMP_FCTR',hr_general.decode_lookup
2578                                            ( p_lookup_type => 'BEN_COMP_SRC' ,
2579                                              p_lookup_code => l_clf.comp_src_cd
2580                                              )
2581                                 );
2582 
2583       fnd_message.set_token('COMP_CODE',l_clf.name);
2584       fnd_message.set_token('PACKAGE',l_package);
2585       raise ben_manage_life_events.g_record_error;
2586       --
2587     end if;
2588     --
2589   end if;
2590   --
2591   hr_utility.set_location (' BDVR_MN ',10);
2592 
2593   ben_determine_variable_rates.main -- FONM procedure have to take care of it
2594     (p_person_id              => l_epe.person_id,
2595      p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
2596      p_cvg_amt_calc_mthd_id   => l_cvg(0).cvg_amt_calc_mthd_id,
2597      p_effective_date         => p_effective_date,
2598      p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
2599      p_entr_val_at_enrt_flag  => l_entr_val_at_enrt_flag, -- Bug 7414757
2600      p_val                    => l_vr_val,        -- output
2601      p_mn_elcn_val            => l_mn_elcn_val ,
2602      p_mx_elcn_val            => l_mx_elcn_val,
2603      p_incrmnt_elcn_val       => l_incrmnt_elcn_val,
2604      p_dflt_elcn_val          => l_dflt_elcn_val ,  -- in coverage
2605      p_tx_typ_cd              => l_dummy_char,
2606      p_acty_typ_cd            => l_dummy_char,
2607      p_vrbl_rt_trtmt_cd       => l_vr_trtmt_cd,
2608      p_ann_mn_elcn_val        => l_vr_ann_mn_elcn_val,
2609      p_ann_mx_elcn_val        => l_vr_ann_mx_elcn_val,
2610      p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
2611      p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
2612      p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
2613      p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl );  -- output
2614      hr_utility.set_location (' Dn BDVR_MN ',10);
2615   -- this variabl intialisation used to chek whether the benefit crossed the max limit
2616   -- in benefit write. if the vapro defined then then ultimate level is used
2617   -- if there is no vapro then benefit level used for the validation bug:1433393
2618 
2619   hr_utility.set_location(' treatment code ' || l_vr_trtmt_cd  ||' ' || l_vr_val , 999);
2620 
2621   l_entr_val_at_enrt_flag := CASE l_entr_val_at_enrt_flag WHEN 'Y' then 'Y' else l_cvg(0).entr_val_at_enrt_flag END;--Bug #8501248
2622 
2623   if l_vr_val is not null  or l_vr_trtmt_cd is not null  then
2624      l_vapro_exist := 'Y' ;
2625      --- Tilak : this code is not validating whether the enter at enrollemt is defined
2626      --- in either side ,(Coverage,VAPRO), this just work on the treatment code
2627      ---  the User has to make sure both the side has the same setup like enter at enrollemt
2628      --
2629      if l_vr_trtmt_cd = 'RPLC' then
2630         l_perform_rounding_flg := false;
2631         l_mn_elcn_val      := nvl(l_mn_elcn_val,l_cvg(0).mn_val) ;
2632         l_mx_elcn_val      := nvl(l_mx_elcn_val,l_cvg(0).mx_val) ;
2633         l_incrmnt_elcn_val := nvl(l_incrmnt_elcn_val,l_cvg(0).incrmt_val );
2634         l_dflt_elcn_val    := nvl(l_dflt_elcn_val , l_cvg(0).dflt_val );
2635 
2636      elsif  l_vr_trtmt_cd = 'ADDTO' then
2637 
2638         l_mn_elcn_val      := nvl(l_mn_elcn_val,0)+ nvl(l_cvg(0).mn_val,0) ;
2639         l_mx_elcn_val      := nvl(l_mx_elcn_val,0)+ nvl(l_cvg(0).mx_val,0) ;
2640         l_incrmnt_elcn_val := nvl(l_incrmnt_elcn_val,0)+ nvl(l_cvg(0).incrmt_val,0);
2641         l_dflt_elcn_val    := nvl(l_dflt_elcn_val,0)+ nvl(l_cvg(0).dflt_val,0 );
2642      elsif l_vr_trtmt_cd = 'SF' then
2643         l_mn_elcn_val      := nvl(l_cvg(0).mn_val,0)-nvl(l_mn_elcn_val,0) ;
2644         l_mx_elcn_val      := nvl(l_cvg(0).mx_val,0)-nvl(l_mx_elcn_val,0) ;
2645         l_incrmnt_elcn_val := nvl(l_cvg(0).incrmt_val,0)-nvl(l_incrmnt_elcn_val,0);
2646         l_dflt_elcn_val    := nvl(l_cvg(0).dflt_val,0 )-nvl(l_dflt_elcn_val,0);
2647      elsif l_vr_trtmt_cd = 'MB' then
2648         -- here the code doesnt bother to check values are defined in both
2649         -- coverage and vapro, if the value are not defined either side
2650         -- multiply will return 0 , consider as setup error
2651 
2652         l_mn_elcn_val      := nvl(l_cvg(0).mn_val,0)*nvl(l_mn_elcn_val,0) ;
2653         l_mx_elcn_val      := nvl(l_cvg(0).mx_val,0)*nvl(l_mx_elcn_val,0) ;
2654         l_incrmnt_elcn_val := nvl(l_cvg(0).incrmt_val,0)*nvl(l_incrmnt_elcn_val,0);
2655         l_dflt_elcn_val    := nvl(l_cvg(0).dflt_val,0 )*nvl(l_dflt_elcn_val,0);
2656      else
2657         l_mn_elcn_val      := l_cvg(0).mn_val ;
2658         l_mx_elcn_val      := l_cvg(0).mx_val ;
2659         l_dflt_elcn_val    := l_cvg(0).dflt_val ;
2660         l_incrmnt_elcn_val := l_cvg(0).incrmt_val ;
2661      end if;
2662   else
2663         l_mn_elcn_val      := l_cvg(0).mn_val ;
2664         l_mx_elcn_val      := l_cvg(0).mx_val ;
2665         l_dflt_elcn_val    := l_cvg(0).dflt_val ;
2666         l_incrmnt_elcn_val := l_cvg(0).incrmt_val ;
2667 
2668      ---
2669   end if ;
2670 
2671   hr_utility.set_location('min max ' || l_mn_elcn_val  ||' ' || l_mx_elcn_val|| ' '|| l_vapro_exist , 999);
2672   --
2673   l_ccm_max_val := l_mx_elcn_val; /* Bug 3828288 */
2674   --
2675 --Bug 6054310 -- This condition should only be there for NSVU
2676   --l_vr_val := nvl(l_vr_val, l_dflt_elcn_val);      /* 5933576 - When vr_val is null, then set it to default val */
2677 --Bug 6054310
2678   --
2679   open c_asg(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date)));
2680   fetch c_asg into l_asg;
2681   close c_asg;
2682 
2683   open c_state(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date)));
2684   fetch c_state into l_state;
2685   close c_state;
2686 
2687 --  if l_state.region_2 is not null then
2688 --    l_jurisdiction_code :=
2689 --       pay_mag_utils.lookup_jurisdiction_code
2690 --         (p_state => l_state.region_2);
2691 --  end if;
2692 
2693   hr_utility.set_location ('l_ler_id '||l_ler_id,55);
2694   hr_utility.set_location ('l_pl_id '||l_pl_id,55);
2695   hr_utility.set_location ('l_oipl_id '||l_oipl_id,55);
2696   hr_utility.set_location ('l_business_group_id '||l_business_group_id,55);
2697   hr_utility.set_location ('l_cvg(0).bnft_or_option_rstrctn_cd '||
2698   l_cvg(0).bnft_or_option_rstrctn_cd,33);
2699 
2700   l_pl_id             := l_epe.pl_id;
2701   l_ler_id            := l_epe.ler_id;
2702   l_oipl_id           := l_epe.oipl_id;
2703   l_business_group_id := l_epe.business_group_id;
2704   --
2705   -- We fetch Restrictions of both types 'BNFT' and 'OPT' as we always want
2706   -- to check the min/max benefit amount, even if the restriction says
2707   -- "Option Restriction Applies". (1198549)
2708   --
2709   open c_ler_rstrn( nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
2710   fetch c_ler_rstrn into l_rstrn;
2711   if c_ler_rstrn%notfound then
2712     hr_utility.set_location ('c_ler_rstrn not found ',33);
2713     close c_ler_rstrn;
2714 
2715     open c_pl_rstrn( nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM;
2716     fetch c_pl_rstrn into l_rstrn;
2717 
2718     if c_pl_rstrn%notfound then
2719       hr_utility.set_location ('c_pl_rstrn not found ',33);
2720       l_rstrn_found := false;
2721     else
2722       hr_utility.set_location ('c_pl_rstrn found ',33);
2723       hr_utility.set_location ('l_rstrn.ler_bnft_rstrn_id '||l_rstrn.ler_bnft_rstrn_id,33);
2724       l_rstrn_found := true;
2725     end if;
2726     close c_pl_rstrn;
2727   else
2728     hr_utility.set_location ('c_ler_rstrn found ',33);
2729     hr_utility.set_location ('l_rstrn.ler_bnft_rstrn_id '||l_rstrn.ler_bnft_rstrn_id,33);
2730     l_ler_bnft_rstrn_id := l_rstrn.ler_bnft_rstrn_id;
2731     l_rstrn_found := true;
2732     close c_ler_rstrn;
2733   end if;
2734   --
2735   -----------------Enhancement	8716693
2736    ----Get the profile value
2737    l_carry_fwd_cert := 'N';
2738    l_carry_fwd_cert := fnd_profile.value('BEN_CARRY_FWD_CERT');
2739    hr_utility.set_location ('l_carry_fwd_cert,enh : '||l_carry_fwd_cert,5345324);
2740    if nvl(l_carry_fwd_cert,'N') = 'Y' then
2741      l_force_rstr := false;
2742      hr_utility.set_location ('enh',5345324);
2743      hr_utility.set_location ('l_rstrn.mx_cvg_wcfn_amt : '||l_rstrn.mx_cvg_wcfn_amt,5345324);
2744      hr_utility.set_location ('l_rstrn.mx_cvg_alwd_amt : '||l_rstrn.mx_cvg_alwd_amt,5345324);
2745      -------check if the current LE has electability or not
2746      open c_get_pil_elctbl;
2747      fetch c_get_pil_elctbl into l_get_pil_elctbl;
2748      if c_get_pil_elctbl%found then  ---Fetch the electable choice info.
2749         if l_rstrn.mx_cvg_alwd_amt is null and l_rstrn.mx_cvg_wcfn_amt is null then
2750 
2751      open c_get_prev_pil(l_person_id);
2752      fetch c_get_prev_pil into l_get_prev_pil;
2753      if c_get_prev_pil%found then
2754         hr_utility.set_location ('prev pil found',53453245);
2755 	hr_utility.set_location ('l_get_prev_pil.per_in_ler_id : '||l_get_prev_pil.per_in_ler_id,5345324);
2756 	---Check if the election is suspended in the Prev LE or not.
2757         open c_chk_prev_sus_enr(l_get_prev_pil.per_in_ler_id,l_get_pil_elctbl.pgm_id,l_get_pil_elctbl.pl_id,l_get_pil_elctbl.oipl_id);
2758 	fetch c_chk_prev_sus_enr into l_chk_prev_sus_enr;
2759 	   if c_chk_prev_sus_enr%found then
2760 	   hr_utility.set_location ('prev election suspended',5345324);
2761 	   ---If suspended,then get the previous LE cvg restrictions.
2762 	   open c_get_cvg_rstr(l_get_prev_pil.per_in_ler_id);
2763 	   fetch c_get_cvg_rstr into l_get_cvg_rstr;
2764 	   ---get the LE which has cvg set-up
2765             hr_utility.set_location ('cvg rstr found',53453245);
2766 	    l_rstrn_found := true;
2767 	    l_force_rstr := true;
2768             l_rstrn.mx_cvg_wcfn_amt := l_get_cvg_rstr.MX_VAL;
2769             l_rstrn.mx_cvg_alwd_amt := l_get_cvg_rstr.MX_WOUT_CTFN_VAL;
2770 	    hr_utility.set_location ('l_rstrn.dflt_to_asn_pndg_ctfn_cd : '||l_rstrn.dflt_to_asn_pndg_ctfn_cd,53453245);
2771 	    hr_utility.set_location ('l_rstrn.mx_cvg_wcfn_amt : '||l_get_cvg_rstr.MX_VAL,53453245);
2772 	    hr_utility.set_location ('l_rstrn.mx_cvg_alwd_amt : '||l_get_cvg_rstr.MX_WOUT_CTFN_VAL,53453245);
2773 	    close c_get_cvg_rstr;
2774 	   -- close c_ler_rstrn;
2775            end if;
2776 	close c_chk_prev_sus_enr;
2777 
2778      end if;
2779      close c_get_prev_pil;
2780      end if;
2781      end if;
2782      close c_get_pil_elctbl;
2783 
2784    end if;
2785      -------------------Enhancement 8716693
2786   --
2787   /*
2788   l_cvg_rstn_max_wout_cert := l_rstrn.mx_cvg_alwd_amt;   Bug 3828288
2789   l_cvg_rstn_max_with_cert := l_rstrn.mx_cvg_wcfn_amt;   Bug 3828288
2790   */
2791   --
2792    /* Supriya Starts bug 5529258 */
2793 
2794   l_DFLT_TO_ASN_PNDG_CTFN_CD := l_rstrn.dflt_to_asn_pndg_ctfn_cd;
2795 
2796   If (l_DFLT_TO_ASN_PNDG_CTFN_CD = 'RL') then
2797 
2798     if l_epe.oipl_id is not null
2799     then
2800 
2801        open c_opt(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
2802        fetch c_opt into l_opt;
2803        close c_opt;
2804     end if;
2805 
2806 
2807 
2808       l_dflt_to_asn_pndg_ctfn_cd :=
2809         ben_sspndd_enrollment.get_dflt_to_asn_pndg_ctfn_cd
2810           (p_dflt_to_asn_pndg_ctfn_rl => l_rstrn.dflt_to_asn_pndg_ctfn_rl
2811           ,p_person_id                => l_epe.person_id
2812           ,p_per_in_ler_id            => l_epe.per_in_ler_id
2813           ,p_assignment_id            => l_asg.assignment_id
2814           ,p_organization_id          => l_asg.organization_id
2815           ,p_business_group_id        => l_epe.business_group_id
2816           ,p_pgm_id                   => l_epe.pgm_id
2817           ,p_pl_id                    => l_epe.pl_id
2818           ,p_pl_typ_id                => l_epe.pl_typ_id
2819           ,p_opt_id                   => l_opt.opt_id
2820           ,p_ler_id                   => l_epe.ler_id
2821           ,p_jurisdiction_code        => l_jurisdiction_code  -- not needed just dummy
2822           ,p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id
2823           ,p_effective_date           => p_effective_date
2824           ,p_prtt_enrt_rslt_id        => l_epe.prtt_enrt_rslt_id
2825           ,p_interim_epe_id           => l_interim_elctbl_chc_id
2826           ,p_interim_bnft_amt         => l_interim_bnft_amt
2827           );
2828 
2829       hr_utility.set_location(' l_dflt_to_asn_pndg_ctfn_cd ' || l_dflt_to_asn_pndg_ctfn_cd,99095);
2830 
2831        IF l_interim_elctbl_chc_id IS NOT NULL THEN
2832         --
2833           l_dflt_to_asn_pndg_ctfn_cd := null;
2834 	   hr_utility.set_location(' l_dflt_to_asn_pndg_ctfn_cd ' || l_dflt_to_asn_pndg_ctfn_cd,99096);
2835         --
2836        END IF;
2837        --
2838      l_rstrn.dflt_to_asn_pndg_ctfn_cd  := l_DFLT_TO_ASN_PNDG_CTFN_CD ;
2839 
2840       hr_utility.set_location('SSARAKR l_dflt_to_asn_pndg_ctfn_cd ' || l_rstrn.dflt_to_asn_pndg_ctfn_cd,99097);
2841 
2842     End if;
2843 
2844   /* Supriya Ends bug 5529258  */
2845 
2846   if l_rstrn_found and l_rstrn.cvg_incr_r_decr_only_cd is not null then
2847     l_incr_r_decr_cd := l_rstrn.cvg_incr_r_decr_only_cd;
2848   else
2849     l_incr_r_decr_cd := l_cvg(0).cvg_incr_r_decr_only_cd;
2850   end if;
2851 
2852   hr_utility.set_location ('l_incr_r_decr_cd '||l_incr_r_decr_cd,33);
2853   --
2854   -- We check increases only if the restriction code is 'BNFT', so make
2855   -- the "increases" values nulll.
2856   --
2857   if l_rstrn_found and
2858      (l_cvg(0).bnft_or_option_rstrctn_cd is null or
2859       l_cvg(0).bnft_or_option_rstrctn_cd = 'OPT') then
2860     --
2861     l_rstrn.mx_cvg_mlt_incr_num      := null;
2862     l_rstrn.mx_cvg_mlt_incr_wcf_num  := null;
2863     l_rstrn.mx_cvg_incr_alwd_amt     := null;
2864     l_rstrn.mx_cvg_incr_wcf_alwd_amt := null;
2865     --
2866   end if;
2867   --
2868   hr_utility.set_location (' open c_current_enrt ',10);
2869   open c_current_enrt(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM;
2870   fetch c_current_enrt into l_crnt_ordr_num,
2871                                l_bnft_amt,
2872                                l_current_enrt_present;
2873   close c_current_enrt;
2874   --
2875   if NVL(l_current_enrt_present,'N') = 'N' then
2876     --
2877     open c_current_enrt_sspndd(nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date)));
2878     fetch c_current_enrt_sspndd into l_current_enrt_sspndd ;
2879     close c_current_enrt_sspndd;
2880     --
2881   end if;
2882   -- get the dflt_enrt_cd/rule
2883   --
2884   ben_enrolment_requirements.determine_dflt_enrt_cd(
2885       p_oipl_id           =>l_epe.oipl_id,
2886       p_plip_id           =>l_epe.plip_id,
2887       p_pl_id             =>l_epe.pl_id,
2888       p_ptip_id           =>l_epe.ptip_id,
2889       p_pgm_id            =>l_epe.pgm_id,
2890       p_ler_id            =>l_epe.ler_id,
2891       p_dflt_enrt_cd      =>l_dflt_enrt_cd,
2892       p_dflt_enrt_rl      =>l_dflt_enrt_rl,
2893       p_business_group_id =>l_epe.business_group_id,
2894       p_effective_date    => nvl(l_fonm_cvg_strt_dt, l_effective_date) -- FONM how this is used.
2895   );
2896 
2897   --- the dflt_enrt_cd is rule and global variable g_dflt_elcn_val has got value
2898   --- then use the value for l_dflt_elcn_val
2899   if l_dflt_enrt_cd = 'RL'  and ben_enrolment_requirements.g_dflt_elcn_val is not null then
2900      l_dflt_elcn_val:=ben_enrolment_requirements.g_dflt_elcn_val;
2901      --- once the value used nullify the value
2902      hr_utility.set_location ('formula default='||ben_enrolment_requirements.g_dflt_elcn_val,744);
2903      ben_enrolment_requirements.g_dflt_elcn_val := null ;
2904   end if ;
2905   --
2906   -- if this choice is a default and dflt_enrt_cd says
2907   -- keep same coverage then use the current benefit amount
2908   -- as the default.
2909   --
2910   if (l_dflt_enrt_cd in ('NSDCS','NNCS') and
2911       l_epe.dflt_flag='Y' and
2912       l_bnft_amt is not null) then
2913     hr_utility.set_location ('dflt_val='||l_bnft_amt,10);
2914     l_dflt_elcn_val:= l_bnft_amt;
2915   end if;
2916   --
2917   l_cvg_amount  := l_bnft_amt;
2918   hr_utility.set_location (' Dn EPE ELSIFs ',10);
2919   if l_cvg(0).cvg_mlt_cd = 'FLFX' then
2920     --
2921     l_ctfn_rqd  := 'N';
2922     l_write_rec := true;
2923     --
2924     l_val := round_val(
2925               p_val                    => l_cvg(0).val,
2926               p_effective_date         => p_effective_date,
2927               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
2928               p_rndg_cd                => l_cvg(0).rndg_cd,
2929               p_rndg_rl                => l_cvg(0).rndg_rl
2930               );
2931     l_cvg_amount := l_val ;
2932     --
2933     ---bug validate the limit for benefir amount
2934     hr_utility.set_location ('limit_checks ' ,10);
2935     benutils.limit_checks
2936       (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
2937        p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
2938        p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
2939        p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
2940        p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
2941        p_assignment_id     => l_asg.assignment_id,
2942        p_organization_id   => l_asg.organization_id,
2943        p_business_group_id => l_epe.business_group_id,
2944        p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
2945        p_pgm_id            => l_epe.pgm_id,
2946        p_pl_id             => l_epe.pl_id,
2947        p_pl_typ_id         => l_epe.pl_typ_id,
2948        p_opt_id            => l_opt.opt_id,
2949        p_ler_id            => l_epe.ler_id,
2950        p_val               => l_val,
2951        p_state             => l_state.region_2);
2952 
2953     hr_utility.set_location (' CMC FLFX ',10);
2954     --
2955     ben_determine_coverage.combine_with_variable_val
2956       (p_vr_val           => l_vr_val,
2957        p_val              => l_val,
2958        p_vr_trtmt_cd      => l_vr_trtmt_cd,
2959        p_combined_val     => l_combined_val);
2960     --
2961 --rtagarra
2962     --
2963     hr_utility.set_location ('l_dflt_enrt_cd'||l_dflt_enrt_cd,353235);
2964     hr_utility.set_location ('FLAG' || l_cvg(0).entr_val_at_enrt_flag,23542345);
2965     hr_utility.set_location ('l_bnft_amt ' ||l_bnft_amt,34534);
2966     hr_utility.set_location ('l_combined_val ' || l_combined_val,345345);
2967     --
2968     if l_dflt_enrt_cd in ('NSDCS','NNCS','NDCSEDR','NNCSEDR') and l_cvg(0).entr_val_at_enrt_flag = 'Y'  then
2969      --
2970      	hr_utility.set_location ('INSIDE 1 IF',53453245);
2971      --
2972       if l_bnft_amt is not null then
2973        --
2974 	hr_utility.set_location ('INSIDE 2 IF',53453245);
2975 	if l_bnft_amt between l_cvg(0).mn_val and l_cvg(0).mx_val then
2976 	--
2977 	hr_utility.set_location ('INSIDE 3 IF',53453245);
2978 	  l_combined_val := l_bnft_amt ;
2979         --
2980         end if;
2981       --
2982      end if;
2983      --
2984    end if;
2985 --rtagarra
2986     if l_rstrn_found then
2987       --
2988       ben_determine_coverage.chk_bnft_ctfn
2989          (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
2990           p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
2991           p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
2992           p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
2993           p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
2994           p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
2995           p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
2996           p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
2997           p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
2998           p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
2999           p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
3000           p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
3001           p_combined_val             => l_combined_val,
3002           p_crnt_bnft_amt            => l_bnft_amt,
3003           p_ordr_num                 => l_order_number,
3004           p_crnt_ordr_num            => l_crnt_ordr_num,
3005           p_ctfn_rqd                 => l_ctfn_rqd,
3006           p_write_rec                => l_write_rec,
3007           p_effective_date           => nvl(p_lf_evt_ocrd_dt,
3008                                             p_effective_date),
3009           p_assignment_id            => l_asg.assignment_id,
3010           p_organization_id          => l_asg.organization_id,
3011           p_business_group_id        => l_epe.business_group_id,
3012           p_pgm_id                   => l_epe.pgm_id,
3013           p_pl_id                    => l_epe.pl_id,
3014           p_pl_typ_id                => l_epe.pl_typ_id,
3015           p_opt_id                   => l_opt.opt_id,
3016           p_ler_id                   => l_epe.ler_id,
3017           p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
3018           p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
3019           p_jurisdiction_code        => l_jurisdiction_code,
3020           p_check_received           => l_check_received,
3021           /* Start of Changes for WWBUG: 2054708    added parameter   */
3022           p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
3023           /* End of Changes for WWBUG: 2054708    added parameter   */
3024 --Bug 4644489
3025   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
3026 --End Bug 4644489
3027        --
3028     end if;
3029     --
3030     --BUG 4627840 -- We are ignoring the rule here.
3031     --
3032     hr_utility.set_location(' l_rstrn.mx_cvg_alwd_amt '||l_rstrn.mx_cvg_alwd_amt,189);
3033     hr_utility.set_location(' l_mx_cvg_wout_ctfn_val '||l_mx_cvg_wout_ctfn_val,189);
3034     hr_utility.set_location(' l_rstrn.mx_cvg_wcfn_amt '||l_rstrn.mx_cvg_wcfn_amt,189);
3035     --
3036     l_cvg_rstn_max_wout_cert := nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val);
3037     l_cvg_rstn_max_with_cert := l_rstrn.mx_cvg_wcfn_amt;
3038     --
3039 /* if already enrolled, check there is any increases restriction */
3040     if l_write_rec then
3041        if l_bnft_amt is not null then
3042           --BUG 4223840
3043 
3044           --Bug 5236985 Added the l_cvg_rstn_max_with_cert not null condition
3045           --This necessary if the l_rstrn.mx_cvg_wcfn_amt is made null in the subsequent life events
3046           if l_cvg(0).entr_val_at_enrt_flag = 'Y' and l_bnft_amt > l_cvg_rstn_max_wout_cert and l_cvg_rstn_max_with_cert is not null then
3047             l_cvg_rstn_max_wout_cert := l_bnft_amt ;
3048             hr_utility.set_location('l_bnft_amt '||l_bnft_amt,188);
3049             hr_utility.set_location('l_cvg_rstn_max_wout_cert '||l_cvg_rstn_max_wout_cert,188);
3050           end if;
3051           --
3052           if l_rstrn.mx_cvg_incr_alwd_amt is not null then
3053              l_cvg_rstn_max_wout_cert  := l_bnft_amt + l_rstrn.mx_cvg_incr_alwd_amt;
3054              l_cvg_rstn_max_incr_wout_cert := l_bnft_amt + l_rstrn.mx_cvg_incr_alwd_amt;     /* Bug 3828288 */
3055           end if;
3056           if l_rstrn.mx_cvg_incr_wcf_alwd_amt is not null then
3057              l_rstrn.mx_cvg_wcfn_amt := l_bnft_amt + l_rstrn.mx_cvg_incr_wcf_alwd_amt ;
3058 	     l_cvg_rstn_max_with_cert := l_rstrn.mx_cvg_wcfn_amt; ----Enhancement 8716693
3059              l_cvg_rstn_max_incr_with_cert := l_bnft_amt + l_rstrn.mx_cvg_incr_wcf_alwd_amt ; /* Bug 3828288 */
3060           end if;
3061        end if;
3062     end if;
3063     hr_utility.set_location('crtfn  ' || l_rstrn.mx_cvg_wcfn_amt,199);
3064     hr_utility.set_location('min val ' || l_mn_elcn_val,199);
3065     hr_utility.set_location('max val ' || l_mx_elcn_val,199);
3066     --
3067     if l_write_rec then
3068       --
3069       -- Bug 3828288
3070       -- For Flat Amount Calc Method consider
3071       --  Max Amount (L_MX_VAL_WO_CFN) as minimum of
3072       --      (1) P_CCM_MAX_VAL - Coverage Calc Method Max Value
3073       --      (2) P_CVG_RSTN_MAX_WOUT_CERT - Plan Coverage Restrictions - Max ,
3074       --      (3) P_CVG_RSTN_MAX_INCR_WOUT_CERT - Current + Plan Coverage Restriction Max Increase
3075       --  Max Amount With Certification (L_MX_VAL_WCFN) as minimum of
3076       --      (1) P_CCM_MAX_VAL - Coverage Calc Method Max Value
3077       --      (2) P_CVG_RSTN_MAX_WITH_CERT - Plan Coverage Restrictions - Max with Certification ,
3078       --      (3) P_CVG_RSTN_MAX_INCR_WITH_CERT - Current + Plan Coverage Restriction Max Increase with Certification
3079       --
3080       --bug#4256191 least of ultmt_upr_lmt, max value passed
3081       if l_ultmt_upr_lmt_calc_rl is not null then
3082         --
3083         l_upr_outputs := benutils.formula
3084                    (p_formula_id        => l_ultmt_upr_lmt_calc_rl,
3085                     p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3086                     p_assignment_id     => l_asg.assignment_id,
3087                     p_organization_id   => l_asg.organization_id,
3088                     p_business_group_id => l_epe.business_group_id,
3089                     p_pgm_id            => l_epe.pgm_id,
3090                     p_pl_id             => l_epe.pl_id,
3091                     p_pl_typ_id         => l_epe.pl_typ_id,
3092                     p_opt_id            => l_opt.opt_id,
3093                     p_ler_id            => l_epe.ler_id,
3094                     -- FONM
3095                     p_param1             => 'BEN_IV_RT_STRT_DT',
3096                     p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
3097                     p_param2             => 'BEN_IV_CVG_STRT_DT',
3098                     p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
3099                     p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id);
3100         --
3101         if l_upr_outputs(l_upr_outputs.first).value is not null then
3102           --
3103           l_ultmt_upr_lmt := fnd_number.canonical_to_number(l_upr_outputs(l_upr_outputs.first).value);
3104           --
3105         end if;
3106         --
3107 
3108       end if;
3109       get_least_value ( p_ccm_max_val                 =>
3110                                    least(l_ccm_max_val,nvl(l_ultmt_upr_lmt,l_ccm_max_val)),
3111                         p_cvg_rstn_max_incr_with_cert => nvl(l_cvg_rstn_max_incr_with_cert,l_cvg_rstn_max_incr_wout_cert),/* bug 4275929 ::max_incr_with_cert= max_incr_wout_certificate when max_incr_with_certificate is NUll */
3112                         p_cvg_rstn_max_with_cert      => nvl(l_cvg_rstn_max_with_cert,l_cvg_rstn_max_wout_cert),/* bug 4275929 :: max_with_certificate= max_wout_certificate when max_with_certificate is NUll */
3113                         p_cvg_rstn_max_incr_wout_cert => l_cvg_rstn_max_incr_wout_cert,
3114                         p_cvg_rstn_max_wout_cert      => l_cvg_rstn_max_wout_cert,
3115                         p_mx_val_wcfn                 => l_mx_val_wcfn,
3116                         p_mx_val_wo_cfn               => l_mx_val_wo_cfn
3117                        );
3118       hr_utility.set_location('l_ultmt_lwr_lmt_calc_rl = ' || l_ultmt_lwr_lmt_calc_rl, 9999);
3119       if l_ultmt_lwr_lmt_calc_rl is not null then
3120         --
3121         l_ult_lwr_outputs := benutils.formula
3122                    (p_formula_id        => l_ultmt_lwr_lmt_calc_rl,
3123                     p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3124                     p_assignment_id     => l_asg.assignment_id,
3125                     p_organization_id   => l_asg.organization_id,
3126                     p_business_group_id => l_epe.business_group_id,
3127                     p_pgm_id            => l_epe.pgm_id,
3128                     p_pl_id             => l_epe.pl_id,
3129                     p_pl_typ_id         => l_epe.pl_typ_id,
3130                     p_opt_id            => l_opt.opt_id,
3131                     p_ler_id            => l_epe.ler_id,
3132                     -- FONM
3133                     p_param1             => 'BEN_IV_RT_STRT_DT',
3134                     p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
3135                     p_param2             => 'BEN_IV_CVG_STRT_DT',
3136                     p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
3137                     p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id);
3138         --
3139         if l_ult_lwr_outputs(l_ult_lwr_outputs.first).value is not null then
3140           --
3141           l_ultmt_lwr_lmt := fnd_number.canonical_to_number(l_ult_lwr_outputs(l_ult_lwr_outputs.first).value);
3142           --
3143         end if;
3144         --
3145       end if;
3146 
3147       l_mn_elcn_val :=
3148 	  greatest(l_mn_elcn_val, greatest(nvl(l_rstrn_mn_cvg_rqd_amt,l_mn_elcn_val),nvl(l_ultmt_lwr_lmt,l_mn_elcn_val)));
3149 
3150 --Bug 4644489
3151 --Write to the Benifts record the minimum coverage value as max(cvg_restrn_mn_amnt,cvg_calc_method)
3152 	-- if (l_rstrn_mn_cvg_rqd_amt > l_mn_elcn_val) then
3153 	--	l_mn_elcn_val := l_rstrn_mn_cvg_rqd_amt;
3154 	-- end if;
3155 --End Bug 4644489
3156       hr_utility.set_location('l_mn_elcn_val = ' || l_mn_elcn_val, 9999);
3157       hr_utility.set_location('l_ultmt_lwr_lmt = ' || l_ultmt_lwr_lmt, 9999);
3158       hr_utility.set_location('l_rstrn_mn_cvg_rqd_amt = ' || l_rstrn_mn_cvg_rqd_amt, 9999);
3159       hr_utility.set_location('l_mx_val_wcfn = ' || l_mx_val_wcfn, 9999);
3160       hr_utility.set_location('l_mx_val_wo_cfn = ' || l_mx_val_wo_cfn, 9999);
3161       -- Bug 3828288
3162       hr_utility.set_location('l_combined_val = ' || l_combined_val, 9999);
3163       hr_utility.set_location('l_cvg_amount = ' || l_cvg_amount, 9999);
3164       hr_utility.set_location('l_dflt_elcn_val = ' || l_dflt_elcn_val, 9999);
3165       --
3166       ben_determine_coverage.write_coverage
3167         (p_calculate_only_mode    => p_calculate_only_mode,
3168          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3169          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3170          p_val                    => l_combined_val,
3171          p_dflt_flag              => l_epe.dflt_flag,
3172          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3173          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3174          p_business_group_id      => l_cvg(0).business_group_id,
3175          p_effective_date         => p_effective_date,
3176          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3177          p_person_id              => l_epe.person_id,
3178          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
3179          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
3180          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
3181          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
3182          p_rndg_cd                => l_cvg(0).rndg_cd,
3183          p_rndg_rl                => l_cvg(0).rndg_rl,
3184          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3185          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3186          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
3187          /* Code Prior To 3828288 Fix
3188          p_mx_val                 => nvl(l_rstrn.mx_cvg_wcfn_amt,l_mx_elcn_val),--mx withctfn,vapro
3189          */
3190          p_mx_val                 => l_mx_val_wcfn,                      /* Bug 3828288 */
3191          /*
3192                 CODE PRIOR TO WWBUG: 2054078
3193          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
3194          */
3195          /* Start of Changes for WWBUG: 2054078         */
3196          /* Code Prior To 3828288 Fix
3197          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
3198          */
3199          p_mx_wout_ctfn_val       => l_mx_val_wo_cfn,                    /* Bug 3828288 */
3200          /* End of Changes for WWBUG: 2054078           */
3201          p_mn_val                 => l_mn_elcn_val,
3202          p_incrmt_val             => l_incrmnt_elcn_val,
3203          p_dflt_val               => l_dflt_elcn_val,
3204          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3205          p_perform_rounding_flg   => l_perform_rounding_flg,
3206          p_ordr_num               => l_order_number,
3207          p_ctfn_rqd_flag          => l_ctfn_rqd,
3208          p_enrt_bnft_id           => l_enrt_bnft_id,
3209          p_enb_valrow             => p_enb_valrow,
3210          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
3211          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
3212          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
3213          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
3214          p_bnft_amount            => l_cvg_amount,
3215          p_vapro_exist            => l_vapro_exist
3216          );
3217       --
3218       if l_ctfn_rqd = 'Y' then
3219         --
3220         write_ctfn;
3221         --
3222       end if;
3223 
3224 
3225            hr_utility.set_location('benefit row'||l_cvg(0).bnft_or_option_rstrctn_cd,111);
3226            hr_utility.set_location('oipl id '||l_epe.oipl_id,111);
3227 
3228       if l_rstrn_found and l_cvg(0).bnft_or_option_rstrctn_cd = 'BNFT' and
3229          l_cvg(0).entr_val_at_enrt_flag = 'Y' then
3230        --  if l_epe.oipl_id is null then /*ENH*/
3231            -- This is required only for enter value at enrollment case
3232            -- ENH We need to populate the right bnft_amout depending on the
3233            -- Interim Codes Min,Next Lower and Default Codes defined at the
3234            -- Plan Level . We will determine
3235            --
3236          l_interim_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,4,2) ;
3237          l_current_level_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,2,2);
3238          --
3239          l_current_plan_id := null ;
3240          l_current_oipl_id := null ;
3241          l_create_current_enb := false ;
3242              --
3243              if l_current_level_cd = 'AS' then
3244                --
3245                open c_current_enrt_in_pl_typ(l_epe.pl_typ_id,
3246                  nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
3247                fetch c_current_enrt_in_pl_typ into l_current_plan_id,l_current_oipl_id ;
3248                if c_current_enrt_in_pl_typ%found then
3249                  l_create_current_enb := true ;
3250                end if;
3251                close c_current_enrt_in_pl_typ;
3252                --
3253              elsif l_current_level_cd = 'SE' then
3254                open c_current_enrt_in_pln(l_epe.pl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
3255                fetch c_current_enrt_in_pln into l_current_plan_id,l_current_oipl_id ;
3256                if c_current_enrt_in_pln%found then
3257                  l_create_current_enb := true ;
3258                end if;
3259                close c_current_enrt_in_pln;
3260              elsif l_current_level_cd = 'SO' then
3261                -- Bug 2543071 changed the l_epe.pl_id to l_epe.oipl_id and added
3262                -- the if condition.
3263                if l_epe.oipl_id is not null then
3264                  open c_current_enrt_in_oipl(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
3265                  fetch c_current_enrt_in_oipl into l_current_plan_id,l_current_oipl_id ;
3266                  if c_current_enrt_in_oipl%found then
3267                    l_create_current_enb := true ;
3268                  end if;
3269                  close c_current_enrt_in_oipl;
3270                end if;
3271              end if;
3272            ---------------
3273            hr_utility.set_location (' open c_current_enrt ',10);
3274            --open c_current_enrt_in_pln(l_epe.pl_id) ;
3275            --  fetch c_current_enrt_in_pln into l_current_plan_id,l_current_oipl_id ;
3276              --
3277              -- if c_current_enrt_in_pln%found then
3278              if l_create_current_enb then
3279                -- Take the current case
3280                l_interim_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,4,2);
3281              else
3282                -- Take the new case
3283                l_interim_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,7,2);
3284              end if;
3285              --
3286              if l_interim_cd = 'MN' then
3287                l_interim_bnft_val :=  l_mn_elcn_val ;
3288              elsif l_interim_cd = 'NL' then
3289                l_interim_bnft_val := nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val) ;
3290              elsif l_interim_cd = 'DF' then
3291                l_interim_bnft_val := l_dflt_elcn_val ;
3292              else -- for Same and Nothing we need not populate this amount
3293                l_interim_bnft_val := null ; -- l_dflt_elcn_val ;
3294              end if ;
3295            --close c_current_enrt_in_pln;
3296            --
3297            hr_utility.set_location('interim row',111);
3298            --CF Changes
3299            --
3300            if l_current_plan_id = l_epe.pl_id and
3301               nvl(l_current_oipl_id,-1) = nvl(l_epe.oipl_id,-1) then
3302              --
3303              open c_current_enb(l_epe.pl_id,l_epe.oipl_id,
3304                                 nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ;
3305                fetch c_current_enb into l_current_enb ;
3306              --
3307              close c_current_enb ;
3308              --
3309            end if;
3310            --
3311            l_enrt_bnft_id :=  null;
3312            open c_unrest(l_epe.ler_id);
3313            fetch c_unrest into l_dummy;
3314            close c_unrest;
3315            if l_dummy = 'Y' then
3316              l_enrt_bnft_id := ben_manage_unres_life_events.enb_exists
3317                             (p_elig_per_elctbl_chc_id,0);
3318            end if;
3319            if not p_calculate_only_mode then
3320             --
3321              if l_enrt_bnft_id is not null then
3322              --
3323                ben_manage_unres_life_events.update_enrt_bnft
3324               (p_dflt_flag              => 'N',
3325                p_val_has_bn_prortd_flag => 'N',        -- change when prorating
3326                p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3327                p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3328                p_val                    => l_interim_bnft_val, -- l_rstrn.mx_cvg_alwd_amt, /*ENH */
3329                p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3330                p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3331                p_prtt_enrt_rslt_id      => null,
3332                p_business_group_id      => l_cvg(0).business_group_id,
3333                p_effective_date         => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3334                p_program_application_id => fnd_global.prog_appl_id,
3335                p_program_id             => fnd_global.conc_program_id,
3336                p_request_id             => fnd_global.conc_request_id,
3337                p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3338                p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3339                p_crntly_enrld_flag      => 'N',
3340                p_ctfn_rqd_flag          => 'N',
3341                p_entr_val_at_enrt_flag  => 'N',
3342                p_mx_val                 => null,  -- max with ctfn
3343                p_mx_wout_ctfn_val       => null,  -- max without ctfn
3344                p_mn_val                 => null,
3345                p_incrmt_val             => null,
3346                p_dflt_val               => null,
3347                p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3348                p_mx_wo_ctfn_flag        => 'Y',
3349                p_program_update_date    => sysdate,
3350                p_enrt_bnft_id           => l_enrt_bnft_id,
3351                p_ordr_num               => 0);
3352               --
3353              else
3354                --
3355                ben_enrt_bnft_api.create_enrt_bnft
3356               (p_validate               => false,
3357                p_dflt_flag              => 'N',
3358                p_val_has_bn_prortd_flag => 'N',        -- change when prorating
3359                p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3360                p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3361                p_val                    => l_interim_bnft_val, -- l_rstrn.mx_cvg_alwd_amt, /*ENH */
3362                p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3363                p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3364                p_prtt_enrt_rslt_id      => l_current_enb.prtt_enrt_rslt_id , -- CF null,
3365                p_business_group_id      => l_cvg(0).business_group_id,
3366                p_effective_date         => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3367                p_program_application_id => fnd_global.prog_appl_id,
3368                p_program_id             => fnd_global.conc_program_id,
3369                p_request_id             => fnd_global.conc_request_id,
3370                p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3371                p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3372                p_crntly_enrld_flag      => 'N',
3373                p_ctfn_rqd_flag          => 'N',
3374                p_entr_val_at_enrt_flag  => 'N',
3375                p_mx_val                 => null,  -- max with ctfn
3376                p_mx_wout_ctfn_val       => null,  -- max without ctfn
3377                p_mn_val                 => null,
3378                p_incrmt_val             => null,
3379                p_dflt_val               => null,
3380                p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3381                p_mx_wo_ctfn_flag        => 'Y',
3382                p_program_update_date    => sysdate,
3383                p_enrt_bnft_id           => l_enrt_bnft_id,
3384                p_object_version_number  => l_object_version_number,
3385                p_ordr_num               => 0);
3386               --
3387              end if;
3388              --
3389             end if;
3390           --
3391      end if;
3392       --
3393       l_current_enb := null ;
3394       --
3395     else
3396       --
3397       -- Update the electable choice to be not electable
3398       --
3399       if l_epe.elctbl_flag='Y' then
3400         --
3401         -- Check for calculate only mode
3402         --
3403         if not p_calculate_only_mode then
3404           --
3405           ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc(
3406              p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id,
3407              p_elctbl_flag             => 'N',
3408              p_dflt_flag               => 'N',
3409              p_object_version_number   => l_epe.object_version_number,
3410              p_effective_date          => p_effective_date,
3411              p_program_application_id  => fnd_global.prog_appl_id,
3412              p_program_id              => fnd_global.conc_program_id,
3413              p_request_id              => fnd_global.conc_request_id,
3414              p_program_update_date     => sysdate
3415           );
3416            --
3417            -- If enrolled will deenroll.
3418            --
3419            ben_newly_ineligible.main(
3420               p_person_id           => l_epe.person_id,
3421               p_pgm_id              => l_epe.pgm_id,
3422               p_pl_id               => l_epe.pl_id,
3423               p_oipl_id             => l_epe.oipl_id,
3424               p_business_group_id   => l_epe.business_group_id,
3425               p_ler_id              => l_epe.ler_id,
3426               p_effective_date      => p_effective_date -- FONM proc take care of it.
3427            );
3428           --
3429         end if;
3430         l_epe.elctbl_flag:='N';
3431         hr_utility.set_location('Electable choice was made not electable by bencvrge',29);
3432       end if;
3433       ben_determine_coverage.write_coverage
3434         (p_calculate_only_mode    => p_calculate_only_mode,
3435          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3436          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3437          p_val                    => l_combined_val,
3438          p_dflt_flag              => l_epe.dflt_flag,
3439          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3440          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3441          p_business_group_id      => l_cvg(0).business_group_id,
3442          p_effective_date         => p_effective_date,
3443          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3444          p_person_id              => l_epe.person_id,
3445          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
3446          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
3447          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
3448          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
3449          p_rndg_cd                => l_cvg(0).rndg_cd,
3450          p_rndg_rl                => l_cvg(0).rndg_rl,
3451          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3452          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3453          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
3454          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_mx_elcn_val),  -- mx with ctfn
3455          /*
3456               CODE PRIOR TO WWBUG: 2054078
3457          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
3458          */
3459          /* Start of Changes for WWBUG: 2054078         */
3460          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
3461          /* End of Changes for WWBUG: 2054078           */
3462          p_mn_val                 => l_mn_elcn_val,
3463          p_incrmt_val             => l_incrmnt_elcn_val,
3464          p_dflt_val               => l_dflt_elcn_val,
3465          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3466          p_perform_rounding_flg   => l_perform_rounding_flg,
3467          p_ordr_num               => l_order_number,
3468          p_ctfn_rqd_flag          => l_ctfn_rqd,
3469          p_enrt_bnft_id           => l_enrt_bnft_id,
3470          p_enb_valrow             => p_enb_valrow,
3471          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
3472          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
3473          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
3474          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
3475          p_bnft_amount            => l_cvg_amount,
3476          p_vapro_exist            => l_vapro_exist
3477          );
3478       --
3479     end if;
3480     --
3481   elsif l_cvg(0).cvg_mlt_cd = 'CL' then
3482     --
3483     l_ctfn_rqd  := 'N';
3484     l_write_rec := true;
3485     --
3486     hr_utility.set_location (' CMC CL ',10);
3487     benutils.rt_typ_calc
3488       (p_val                    => l_cvg(0).val,
3489        p_val_2                  => l_compensation_value,
3490        p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3491        p_calculated_val         => l_calculated_val);
3492     --
3493     l_val := round_val(
3494               p_val                    => l_calculated_val,
3495               p_effective_date         => p_effective_date,
3496               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3497               p_rndg_cd                => l_cvg(0).rndg_cd,
3498               p_rndg_rl                => l_cvg(0).rndg_rl
3499               );
3500     --
3501      l_cvg_amount := l_val ;
3502     ---bug validate the limit for benefir amount
3503     hr_utility.set_location ('limit_checks ',10);
3504     benutils.limit_checks
3505       (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
3506        p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
3507        p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
3508        p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
3509        p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3510        p_assignment_id     => l_asg.assignment_id,
3511        p_organization_id   => l_asg.organization_id,
3512        p_business_group_id => l_epe.business_group_id,
3513        p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3514        p_pgm_id            => l_epe.pgm_id,
3515        p_pl_id             => l_epe.pl_id,
3516        p_pl_typ_id         => l_epe.pl_typ_id,
3517        p_opt_id            => l_opt.opt_id,
3518        p_ler_id            => l_epe.ler_id,
3519        p_val               => l_val,
3520        p_state             => l_state.region_2);
3521 
3522     ---
3523     hr_utility.set_location (' rndg is'||l_val,10);
3524     ben_determine_coverage.combine_with_variable_val
3525       (p_vr_val                 => l_vr_val,
3526        p_val                    => l_val,
3527        p_vr_trtmt_cd            => l_vr_trtmt_cd,
3528        p_combined_val           => l_combined_val);
3529     --
3530     hr_utility.set_location (' varb is'||l_combined_val,10);
3531     --
3532     if l_rstrn_found then
3533       --
3534       ben_determine_coverage.chk_bnft_ctfn
3535          (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
3536           p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
3537           p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
3538           p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
3539           p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
3540           p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
3541           p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
3542           p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
3543           p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
3544           p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
3545           p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
3546           p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
3547           p_combined_val             => l_combined_val,
3548           p_crnt_bnft_amt            => l_bnft_amt,
3549           p_ordr_num                 => l_order_number,
3550           p_crnt_ordr_num            => l_crnt_ordr_num,
3551           p_ctfn_rqd                 => l_ctfn_rqd,
3552           p_write_rec                => l_write_rec,
3553           p_effective_date           => nvl(p_lf_evt_ocrd_dt,
3554                                             p_effective_date),
3555           p_assignment_id            => l_asg.assignment_id,
3556           p_organization_id          => l_asg.organization_id,
3557           p_business_group_id        => l_epe.business_group_id,
3558           p_pgm_id                   => l_epe.pgm_id,
3559           p_pl_id                    => l_epe.pl_id,
3560           p_pl_typ_id                => l_epe.pl_typ_id,
3561           p_opt_id                   => l_opt.opt_id,
3562           p_ler_id                   => l_epe.ler_id,
3563           p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
3564           p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
3565           p_jurisdiction_code        => l_jurisdiction_code,
3566           p_check_received           => l_check_received,
3567           /* Start of Changes for WWBUG: 2054078   added parameter */
3568           p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
3569           /* End of Changes for WWBUG: 2054078   added parameter */
3570 --Bug 4644489
3571   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
3572 --End Bug 4644489
3573        --
3574     end if;
3575     --
3576     if l_write_rec then
3577       --
3578       ben_determine_coverage.write_coverage
3579         (p_calculate_only_mode    => p_calculate_only_mode,
3580          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3581          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3582          p_val                    => l_combined_val,
3583          p_dflt_flag              => l_epe.dflt_flag,
3584          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3585          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3586          p_business_group_id      => l_cvg(0).business_group_id,
3587          p_effective_date         => p_effective_date,
3588          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3589          p_person_id              => l_epe.person_id,
3590          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
3591          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
3592          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
3593          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
3594          p_rndg_cd                => l_cvg(0).rndg_cd,
3595          p_rndg_rl                => l_cvg(0).rndg_rl,
3596          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3597          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3598          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
3599          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
3600          /*
3601              CODE PRIOR TO WWBUG: 2054078
3602          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
3603          */
3604          /* Start of Changes for WWBUG: 2054078   */
3605          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
3606          /* End of Changes for WWBUG: 2054078   */
3607          p_mn_val                 => l_cvg(0).mn_val,
3608          p_incrmt_val             => l_cvg(0).incrmt_val,
3609          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3610          p_dflt_val               => NVL(l_dflt_elcn_val,l_cvg(0).dflt_val),
3611          p_perform_rounding_flg   => l_perform_rounding_flg,
3612          p_ordr_num               => l_order_number,
3613          p_ctfn_rqd_flag          => l_ctfn_rqd,
3614          p_enrt_bnft_id           => l_enrt_bnft_id,
3615          p_enb_valrow             => p_enb_valrow,
3616          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
3617          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
3618          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
3619          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
3620          p_bnft_amount            => l_cvg_amount,
3621          p_vapro_exist            => l_vapro_exist
3622          );
3623       --
3624       if l_ctfn_rqd = 'Y'
3625         and not p_calculate_only_mode
3626       then
3627         --
3628         write_ctfn;
3629         --
3630       end if;
3631       --
3632     else
3633       --
3634       -- Update the electable choice to be not electable
3635       --
3636       if l_epe.elctbl_flag='Y' then
3637         --
3638         if not p_calculate_only_mode then
3639           --
3640           ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc(
3641              p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id,
3642              p_elctbl_flag             => 'N',
3643              p_dflt_flag               => 'N',
3644              p_object_version_number   => l_epe.object_version_number,
3645              p_effective_date          => p_effective_date,
3646              p_program_application_id  => fnd_global.prog_appl_id,
3647              p_program_id              => fnd_global.conc_program_id,
3648              p_request_id              => fnd_global.conc_request_id,
3649              p_program_update_date     => sysdate
3650           );
3651            --
3652            -- If enrolled will deenroll.
3653            --
3654            ben_newly_ineligible.main(
3655               p_person_id           => l_epe.person_id,
3656               p_pgm_id              => l_epe.pgm_id,
3657               p_pl_id               => l_epe.pl_id,
3658               p_oipl_id             => l_epe.oipl_id,
3659               p_business_group_id   => l_epe.business_group_id,
3660               p_ler_id              => l_epe.ler_id,
3661               p_effective_date      => p_effective_date
3662            );
3663           --
3664         end if;
3665         --
3666         l_epe.elctbl_flag:='N';
3667         hr_utility.set_location('Electable choice was made not electable by bencvrge',29);
3668       end if;
3669       ben_determine_coverage.write_coverage
3670         (p_calculate_only_mode    => p_calculate_only_mode,
3671          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3672          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3673          p_val                    => l_combined_val,
3674          p_dflt_flag              => l_epe.dflt_flag,
3675          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3676          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3677          p_business_group_id      => l_cvg(0).business_group_id,
3678          p_effective_date         => p_effective_date,
3679          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3680          p_person_id              => l_epe.person_id,
3681          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
3682          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
3683          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
3684          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
3685          p_rndg_cd                => l_cvg(0).rndg_cd,
3686          p_rndg_rl                => l_cvg(0).rndg_rl,
3687          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3688          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3689          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
3690          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
3691          /*
3692               CODE PRIOR TO WWBUG: 2054078
3693          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
3694          */
3695          /*   Start of Changes for WWBUG: 2054078               */
3696          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
3697          /*   End of Changes for WWBUG: 2054078         */
3698          p_mn_val                 => l_cvg(0).mn_val,
3699          p_incrmt_val             => l_cvg(0).incrmt_val,
3700          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3701          p_dflt_val               => l_cvg(0).dflt_val,
3702          p_perform_rounding_flg   => l_perform_rounding_flg,
3703          p_ordr_num               => l_order_number,
3704          p_ctfn_rqd_flag          => l_ctfn_rqd,
3705          p_enrt_bnft_id           => l_enrt_bnft_id,
3706          p_enb_valrow             => p_enb_valrow,
3707          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
3708          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
3709          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
3710          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
3711          p_bnft_amount            => l_cvg_amount,
3712          p_vapro_exist            => l_vapro_exist
3713          );
3714       --
3715     end if;
3716     --
3717   elsif l_cvg(0).cvg_mlt_cd = 'FLRNG' then
3718     --
3719       hr_utility.set_location (' CMC FLRNG ',10);
3720     --
3721     hr_utility.set_location ('l_cvg-0.mx_val '||l_cvg(0).mx_val,33);
3722     hr_utility.set_location ('l_cvg-0.mn_val '||l_cvg(0).mn_val,33);
3723     --
3724     if l_cvg(0).lwr_lmt_calc_rl is not NULL then
3725       --
3726       l_lwr_outputs := benutils.formula
3727                    (p_formula_id        => l_cvg(0).lwr_lmt_calc_rl,
3728                     p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3729                     p_assignment_id     => l_asg.assignment_id,
3730                     p_organization_id   => l_asg.organization_id,
3731                     p_business_group_id => l_epe.business_group_id,
3732                     p_pgm_id            => l_epe.pgm_id,
3733                     p_pl_id             => l_epe.pl_id,
3734                     p_pl_typ_id         => l_epe.pl_typ_id,
3735                     p_opt_id            => l_opt.opt_id,
3736                     p_ler_id            => l_epe.ler_id,
3737                     -- FONM
3738                     p_param1             => 'BEN_IV_RT_STRT_DT',
3739                     p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
3740                     p_param2             => 'BEN_IV_CVG_STRT_DT',
3741                     p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
3742                     p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id);
3743       l_lwr_val := fnd_number.canonical_to_number(l_lwr_outputs(l_lwr_outputs.first).value);
3744       --
3745     elsif l_cvg(0).lwr_lmt_val is not null then
3746       l_lwr_val := l_cvg(0).lwr_lmt_val;
3747     end if;
3748 
3749     if l_cvg(0).upr_lmt_calc_rl is not NULL then
3750       --
3751       l_upr_outputs := benutils.formula
3752                    (p_formula_id        => l_cvg(0).upr_lmt_calc_rl,
3753                     p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3754                     p_assignment_id     => l_asg.assignment_id,
3755                     p_organization_id   => l_asg.organization_id,
3756                     p_business_group_id => l_epe.business_group_id,
3757                     p_pgm_id            => l_epe.pgm_id,
3758                     p_pl_id             => l_epe.pl_id,
3759                     p_pl_typ_id         => l_epe.pl_typ_id,
3760                     p_opt_id            => l_opt.opt_id,
3761                     p_ler_id            => l_epe.ler_id,
3762                     -- FONM
3763                     p_param1             => 'BEN_IV_RT_STRT_DT',
3764                     p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
3765                     p_param2             => 'BEN_IV_CVG_STRT_DT',
3766                     p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
3767                     p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id);
3768       l_upr_val := fnd_number.canonical_to_number(l_upr_outputs(l_upr_outputs.first).value);
3769       --
3770     elsif l_cvg(0).upr_lmt_val is not null then
3771       l_upr_val := l_cvg(0).upr_lmt_val;
3772     end if;
3773 
3774     i := nvl(l_lwr_val,l_cvg(0).mn_val);
3775 
3776     hr_utility.set_location ('l_lwr_val :'||l_lwr_val,32);
3777     hr_utility.set_location ('l_upr_val :'||l_upr_val,32);
3778 
3779     while i <= nvl(l_upr_val,l_cvg(0).mx_val) loop
3780       --
3781       hr_utility.set_location ('i = '||i,33);
3782       --
3783       l_ctfn_rqd  := 'N';
3784       l_write_rec := true;
3785       --
3786       if l_incr_r_decr_cd is null or
3787         ((l_incr_r_decr_cd='INCRO' and
3788           l_order_number > nvl(l_crnt_ordr_num,0)) or
3789          (l_incr_r_decr_cd='EQINCR' and
3790           l_order_number >=  nvl(l_crnt_ordr_num,0)) or
3791          (l_incr_r_decr_cd='DECRO' and
3792           l_order_number < nvl(l_crnt_ordr_num,0)) or
3793          (l_incr_r_decr_cd='EQDECR' and
3794           l_order_number <=  nvl(l_crnt_ordr_num,0))  or
3795           -- Start of 3806262
3796           l_incr_r_decr_cd='INCRCTF' or
3797 	  --and l_order_number >  nvl(l_crnt_ordr_num,0)) or  -- Bug 6164688
3798           l_incr_r_decr_cd='DECRCTF'
3799 	  --and l_order_number < nvl(l_crnt_ordr_num,0))      -- Bug 6164688
3800           ) then
3801           -- End of 3806262
3802           l_val := round_val(
3803               p_val                    => i,
3804               p_effective_date         => p_effective_date,
3805               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3806               p_rndg_cd                => l_cvg(0).rndg_cd,
3807               p_rndg_rl                => l_cvg(0).rndg_rl
3808               );
3809            l_cvg_amount := l_val ;
3810           --validate the limit for benefir amount
3811           hr_utility.set_location ('limit_checks ',10);
3812           benutils.limit_checks
3813           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
3814               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
3815               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
3816               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
3817               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
3818               p_assignment_id     => l_asg.assignment_id,
3819               p_organization_id   => l_asg.organization_id,
3820               p_business_group_id => l_epe.business_group_id,
3821               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3822               p_pgm_id            => l_epe.pgm_id,
3823               p_pl_id             => l_epe.pl_id,
3824               p_pl_typ_id         => l_epe.pl_typ_id,
3825               p_opt_id            => l_opt.opt_id,
3826               p_ler_id            => l_epe.ler_id,
3827               p_val               => l_val,
3828               p_state             => l_state.region_2);
3829 
3830          --
3831          ben_determine_coverage.combine_with_variable_val
3832            (p_vr_val             => l_vr_val,
3833             p_val                => l_val,
3834             p_vr_trtmt_cd        => l_vr_trtmt_cd,
3835             p_combined_val       => l_combined_val);
3836          --
3837 	 -- Bug 8940075 / 9008389 : Exchanged the code between if and the first elsif below
3838 
3839          if (l_dflt_enrt_cd in ('NSDCS','NNCS')
3840 --                and i = nvl(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
3841                   and l_combined_val = nvl(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
3842                (l_dflt_enrt_cd in ('NSDCS','NNCS')
3843                              and l_crnt_ordr_num = l_order_number) then
3844              l_dflt_flag := 'Y';
3845             --
3846          --
3847          -- bug fix 2560721
3848          -- for New Enrollments the bnft row corresponding to dflt_val should have
3849          -- the dflt_flag set to Y, when default enrollment code is 'NSDCS'.
3850          -- l_current_enrt_present will be null if the enrollment is New, refer to
3851          -- c_current_enrt cursor above
3852          --
3853          elsif (l_dflt_enrt_cd in ('NSDCS','NNCS') and
3854 --                            i <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
3855                 l_combined_val <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
3856                (l_dflt_enrt_cd in ('NSDCS','NNCS') and
3857                             l_crnt_ordr_num <> l_order_number) then
3858              l_dflt_flag := 'N';
3859          elsif l_dflt_enrt_cd in ('NSDCS') and
3860             nvl(l_current_enrt_present,'N') = 'N' and
3861             i = l_cvg(0).dflt_val then
3862             --
3863             l_dflt_flag := 'Y';
3864             --
3865          --
3866          -- end fix 2560721
3867          --
3868          elsif l_dflt_enrt_cd not in ('NSDCS','NNCS') and
3869                i = l_cvg(0).dflt_val then
3870             --
3871             l_dflt_flag := 'Y';
3872             --
3873          else
3874             l_dflt_flag := 'N';
3875 
3876          end if;
3877 
3878          if l_rstrn_found then
3879 
3880            ben_determine_coverage.chk_bnft_ctfn
3881             (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
3882              p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
3883              p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
3884              p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
3885              p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
3886              p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
3887              p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
3888              p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
3889              p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
3890              p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
3891              p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
3892              p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
3893              p_combined_val             => l_combined_val,
3894              p_crnt_bnft_amt            => l_bnft_amt,
3895              p_ordr_num                 => l_order_number,
3896              p_crnt_ordr_num            => l_crnt_ordr_num,
3897              p_ctfn_rqd                 => l_ctfn_rqd,
3898              p_write_rec                => l_write_rec,
3899              p_effective_date           => nvl(p_lf_evt_ocrd_dt,
3900                                                p_effective_date),
3901              p_assignment_id            => l_asg.assignment_id,
3902              p_organization_id          => l_asg.organization_id,
3903              p_business_group_id        => l_epe.business_group_id,
3904              p_pgm_id                   => l_epe.pgm_id,
3905              p_pl_id                    => l_epe.pl_id,
3906              p_pl_typ_id                => l_epe.pl_typ_id,
3907              p_opt_id                   => l_opt.opt_id,
3908              p_ler_id                   => l_epe.ler_id,
3909              p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
3910              p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
3911              p_jurisdiction_code        => l_jurisdiction_code,
3912              p_check_received           => l_check_received,
3913              /* Start of Changes for WWBUG: 2054078             */
3914              p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
3915              /* End of Changes for WWBUG: 2054078               */
3916 --Bug 4644489
3917   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
3918 --End Bug 4644489
3919            --
3920          end if;
3921          --
3922          if l_write_rec then
3923            --
3924            hr_utility.set_location('Writing coverage ',35);
3925            --
3926            ben_determine_coverage.write_coverage
3927              (p_calculate_only_mode    => p_calculate_only_mode,
3928               p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
3929               p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
3930               p_val                    => l_combined_val,
3931               p_dflt_flag              => l_dflt_flag,
3932               p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
3933               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
3934               p_business_group_id      => l_cvg(0).business_group_id,
3935               p_effective_date         => p_effective_date,
3936               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
3937               p_person_id              => l_epe.person_id,
3938               p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
3939               p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
3940               p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
3941               p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
3942               p_rndg_cd                => l_cvg(0).rndg_cd,
3943               p_rndg_rl                => l_cvg(0).rndg_rl,
3944               p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
3945               p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
3946               p_entr_val_at_enrt_flag  => 'N',--l_cvg(0).entr_val_at_enrt_flag,
3947   --Bug 5573274
3948          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
3949          /*
3950              CODE PRIOR TO WWBUG: 2054078
3951          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
3952          */
3953          /* Start of Changes for WWBUG: 2054078   */
3954          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
3955          /* End of Changes for WWBUG: 2054078   */
3956   --End Bug 5573274
3957               p_mn_val                 => null, --l_cvg(0).mn_val,
3958               p_incrmt_val             => null, --l_cvg(0).incrmt_val,
3959               p_dflt_val               => null, --l_cvg(0).dflt_val,
3960               p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
3961               p_perform_rounding_flg   => l_perform_rounding_flg,
3962               p_ordr_num               => l_order_number,
3963               p_ctfn_rqd_flag          => l_ctfn_rqd,
3964               p_enrt_bnft_id           => l_enrt_bnft_id,
3965               p_enb_valrow             => p_enb_valrow,
3966               p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
3967               p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
3968               p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
3969               p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
3970               p_bnft_amount            => l_cvg_amount,
3971               p_vapro_exist            => l_vapro_exist
3972               );
3973            --
3974            if l_ctfn_rqd = 'Y'
3975              and not p_calculate_only_mode
3976            then
3977              --
3978              write_ctfn;
3979              --
3980            end if;
3981            --
3982          end if;
3983          --
3984          --  if l_vr_trtmt_cd is RPLC treat as FLFX
3985          --
3986          if l_vr_trtmt_cd = 'RPLC' then
3987            --
3988            exit;
3989            --
3990          end if;
3991 
3992       end if;
3993       --
3994       i := i + l_cvg(0).incrmt_val;
3995       l_order_number := l_order_number + 1;
3996       --
3997     end loop;
3998     --
3999     open c_unrest(l_epe.ler_id);
4000        fetch c_unrest into l_dummy;
4001     close c_unrest;
4002     -----Bug 7704956
4003       --Bug 9308931,Fix for the bug 7704596 is extended for the OAB life events also.
4004  --   if l_dummy = 'Y' then
4005        l_dup_enr_count := 0;
4006        for l_check in c_check_dup_enb_enr(p_elig_per_elctbl_chc_id) loop
4007        l_dup_enr_count := l_dup_enr_count + 1;
4008        hr_utility.set_location ('count : '||l_dup_enr_count,10);
4009        if l_dup_enr_count > 1 then
4010           exit;
4011        end if;
4012        end loop;
4013 
4014        if (l_dup_enr_count > 1) then
4015           --fetch the bnft amount
4016 	  open c_get_prev_bnft(p_effective_date);
4017 	  fetch c_get_prev_bnft into l_get_prev_bnft;
4018 	  close c_get_prev_bnft;
4019           for l_check in c_check_dup_enb_enr(p_elig_per_elctbl_chc_id) loop
4020 	     --update enb table if order number matches.
4021              if l_get_prev_bnft.bnft_amt <> l_check.val then
4022 		ben_enrt_bnft_api.update_enrt_bnft
4023 				 (p_enrt_bnft_id                  => l_check.enrt_bnft_id
4024                                  ,p_dflt_flag                     => 'N'   ---l_check.dflt_flag,Bug 9308931
4025                                  ,p_val_has_bn_prortd_flag        => l_check.val_has_bn_prortd_flag
4026                                  ,p_bndry_perd_cd                 => l_check.bndry_perd_cd
4027                                  ,p_val                           => l_check.val
4028                                  ,p_nnmntry_uom                   => l_check.nnmntry_uom
4029                                  ,p_bnft_typ_cd                   => l_check.bnft_typ_cd
4030                                  ,p_entr_val_at_enrt_flag         => l_check.entr_val_at_enrt_flag
4031                                  ,p_mn_val                        => l_check.mn_val
4032                                  ,p_mx_val                        => l_check.mx_val
4033                                  ,p_incrmt_val                    => l_check.incrmt_val
4034                                  ,p_dflt_val                      => l_check.dflt_val
4035                                  ,p_rt_typ_cd                     => l_check.rt_typ_cd
4036                                  ,p_cvg_mlt_cd                    => l_check.cvg_mlt_cd
4037                                  ,p_ctfn_rqd_flag                 => l_check.ctfn_rqd_flag
4038                                  ,p_ordr_num                      => l_check.ordr_num
4039                                  ,p_crntly_enrld_flag             => 'N'
4040                                  ,p_elig_per_elctbl_chc_id        => l_check.elig_per_elctbl_chc_id
4041                                  ,p_prtt_enrt_rslt_id             => null
4042                                  ,p_comp_lvl_fctr_id              => l_check.comp_lvl_fctr_id
4043                                  ,p_business_group_id             => l_check.business_group_id
4044                                  ,p_enb_attribute_category        => l_check.enb_attribute_category
4045                                  ,p_enb_attribute1                => l_check.enb_attribute1
4046                                  ,p_enb_attribute2                => l_check.enb_attribute2
4047                                  ,p_enb_attribute3                => l_check.enb_attribute3
4048                                  ,p_enb_attribute4                => l_check.enb_attribute4
4049                                  ,p_enb_attribute5                => l_check.enb_attribute5
4050                                  ,p_enb_attribute6                => l_check.enb_attribute6
4051                                  ,p_enb_attribute7                => l_check.enb_attribute7
4052                                  ,p_enb_attribute8                => l_check.enb_attribute8
4053                                  ,p_enb_attribute9                => l_check.enb_attribute9
4054                                  ,p_enb_attribute10               => l_check.enb_attribute10
4055                                  ,p_enb_attribute11               => l_check.enb_attribute11
4056                                  ,p_enb_attribute12               => l_check.enb_attribute12
4057                                  ,p_enb_attribute13               => l_check.enb_attribute13
4058                                  ,p_enb_attribute14               => l_check.enb_attribute14
4059                                  ,p_enb_attribute15               => l_check.enb_attribute15
4060                                  ,p_enb_attribute16               => l_check.enb_attribute16
4061                                  ,p_enb_attribute17               => l_check.enb_attribute17
4062                                  ,p_enb_attribute18               => l_check.enb_attribute18
4063                                  ,p_enb_attribute19               => l_check.enb_attribute19
4064                                  ,p_enb_attribute20               => l_check.enb_attribute20
4065                                  ,p_enb_attribute21               => l_check.enb_attribute21
4066                                  ,p_enb_attribute22               => l_check.enb_attribute22
4067                                  ,p_enb_attribute23               => l_check.enb_attribute23
4068                                  ,p_enb_attribute24               => l_check.enb_attribute24
4069                                  ,p_enb_attribute25               => l_check.enb_attribute25
4070                                  ,p_enb_attribute26               => l_check.enb_attribute26
4071                                  ,p_enb_attribute27               => l_check.enb_attribute27
4072                                  ,p_enb_attribute28               => l_check.enb_attribute28
4073                                  ,p_enb_attribute29               => l_check.enb_attribute29
4074                                  ,p_enb_attribute30               => l_check.enb_attribute30
4075                                  ,p_request_id                    => l_check.request_id
4076                                  ,p_program_application_id        => l_check.program_application_id
4077                                  ,p_program_id                    => l_check.program_id
4078                                  ,p_program_update_date           => l_check.program_update_date
4079                                  ,p_mx_wout_ctfn_val              => l_check.mx_wout_ctfn_val
4080                                  ,p_mx_wo_ctfn_flag               => l_check.mx_wo_ctfn_flag
4081                                  ,p_object_version_number         => l_check.object_version_number
4082                                  ,p_effective_date                => trunc(p_effective_date));
4083 	     end if;
4084 	  end loop;
4085 	  end if;
4086    -- end if;  Bug 9308931
4087 
4088   elsif l_cvg(0).cvg_mlt_cd = 'CLRNG' then
4089     --
4090       hr_utility.set_location (' CMC CLRNG ',10);
4091     i := l_cvg(0).mn_val;
4092     --
4093     while i <= l_cvg(0).mx_val loop
4094       --
4095       l_ctfn_rqd := 'N';
4096       l_write_rec := true;
4097       --
4098       if l_incr_r_decr_cd is null or
4099           ((l_incr_r_decr_cd='INCRO' and
4100             l_order_number > nvl(l_crnt_ordr_num,0)) or
4101            (l_incr_r_decr_cd='EQINCR' and
4102             l_order_number >=  nvl(l_crnt_ordr_num,0)) or
4103            (l_incr_r_decr_cd='DECRO' and
4104             l_order_number < nvl(l_crnt_ordr_num,0)) or
4105            (l_incr_r_decr_cd='EQDECR' and
4106             l_order_number <=  nvl(l_crnt_ordr_num,0))) then
4107         --
4108         benutils.rt_typ_calc
4109           (p_val              => i,
4110            p_val_2            => l_compensation_value,
4111            p_rt_typ_cd        => l_cvg(0).rt_typ_cd,
4112            p_calculated_val   => l_calculated_val);
4113         --
4114           l_val := round_val(
4115               p_val                    => l_calculated_val,
4116               p_effective_date         => p_effective_date,
4117               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4118               p_rndg_cd                => l_cvg(0).rndg_cd,
4119               p_rndg_rl                => l_cvg(0).rndg_rl
4120               );
4121           l_cvg_amount := l_val ;
4122          --validate the limit for benefir amount
4123          hr_utility.set_location ('limit_checks ',10);
4124          benutils.limit_checks
4125         (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
4126            p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
4127            p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
4128            p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
4129            p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4130            p_assignment_id     => l_asg.assignment_id,
4131            p_organization_id   => l_asg.organization_id,
4132            p_business_group_id => l_epe.business_group_id,
4133            p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4134            p_pgm_id            => l_epe.pgm_id,
4135            p_pl_id             => l_epe.pl_id,
4136            p_pl_typ_id         => l_epe.pl_typ_id,
4137            p_opt_id            => l_opt.opt_id,
4138            p_ler_id            => l_epe.ler_id,
4139            p_val               => l_val,
4140            p_state             => l_state.region_2);
4141 
4142         ben_determine_coverage.combine_with_variable_val
4143           (p_vr_val           => l_vr_val,
4144            p_val              => l_val,
4145            p_vr_trtmt_cd      => l_vr_trtmt_cd,
4146            p_combined_val     => l_combined_val);
4147         --
4148 	--9434155
4149            if (l_dflt_enrt_cd in ('NSDCS','NNCS')
4150 --                  and i <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4151                   and l_combined_val = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or --Bug 6068097
4152               (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num = l_order_number)
4153            then
4154              l_dflt_flag := 'Y';
4155 
4156            elsif (l_dflt_enrt_cd in ('NSDCS','NNCS')
4157 --                  and i = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4158                   and l_combined_val <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or --Bug 6068097
4159                  (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num <> l_order_number)
4160            then
4161              l_dflt_flag := 'N';
4162 
4163            elsif l_dflt_enrt_cd not in ('NSDCS','NNCS') and
4164                  i = l_cvg(0).dflt_val then
4165 
4166              l_dflt_flag := 'Y';
4167 
4168            else
4169 
4170              l_dflt_flag := 'N';
4171 
4172            end if;
4173 
4174         if l_rstrn_found then
4175           --
4176           ben_determine_coverage.chk_bnft_ctfn
4177             (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
4178              p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
4179              p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
4180              p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
4181              p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
4182              p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
4183              p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
4184              p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
4185              p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
4186              p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
4187              p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
4188              p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
4189              p_combined_val             => l_combined_val,
4190              p_crnt_bnft_amt            => l_bnft_amt,
4191              p_ordr_num                 => l_order_number,
4192              p_crnt_ordr_num            => l_crnt_ordr_num,
4193              p_ctfn_rqd                 => l_ctfn_rqd,
4194              p_write_rec                => l_write_rec,
4195              p_effective_date           => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4196              p_assignment_id            => l_asg.assignment_id,
4197              p_organization_id          => l_asg.organization_id,
4198              p_business_group_id        => l_epe.business_group_id,
4199              p_pgm_id                   => l_epe.pgm_id,
4200              p_pl_id                    => l_epe.pl_id,
4201              p_pl_typ_id                => l_epe.pl_typ_id,
4202              p_opt_id                   => l_opt.opt_id,
4203              p_ler_id                   => l_epe.ler_id,
4204              p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
4205              p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
4206              p_jurisdiction_code        => l_jurisdiction_code,
4207              p_check_received           => l_check_received,
4208              /* Start of Changes for WWBUG: 2054078  added parameter */
4209              p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
4210              /* End of Changes for WWBUG: 2054078  added parameter */
4211 --Bug 4644489
4212   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
4213 --End Bug 4644489
4214           --
4215         end if;
4216         --
4217         if l_write_rec then
4218           --
4219           if l_epe.oipl_id is not null then
4220             --
4221             open c_opt(l_epe.oipl_id,
4222               nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
4223               --
4224               fetch c_opt into l_opt;
4225               --
4226             close c_opt;
4227             --
4228           end if;
4229           --
4230           ben_determine_coverage.write_coverage
4231             (p_calculate_only_mode    => p_calculate_only_mode,
4232              p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
4233              p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
4234              p_val                    => l_combined_val,
4235              p_dflt_flag              => l_dflt_flag,
4236              p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
4237              p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4238              p_business_group_id      => l_cvg(0).business_group_id,
4239              p_effective_date         => p_effective_date,
4240              p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4241              p_person_id              => l_epe.person_id,
4242              p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
4243              p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
4244              p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
4245              p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
4246              p_rndg_cd                => l_cvg(0).rndg_cd,
4247              p_rndg_rl                => l_cvg(0).rndg_rl,
4248              p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
4249              p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
4250              p_entr_val_at_enrt_flag  => 'N',--l_cvg(0).entr_val_at_enrt_flag,
4251              p_mx_val                 => null,--l_cvg(0).mx_val,
4252              p_mx_wout_ctfn_val       => null, --l_rstrn.mx_cvg_alwd_amt
4253              p_mn_val                 => null,--l_cvg(0).mn_val,
4254              p_dflt_val               => null,--l_dflt_val,
4255              p_incrmt_val             => null,--l_cvg(0).incrmt_val,
4256              p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
4257              p_perform_rounding_flg   => l_perform_rounding_flg,
4258              p_ordr_num               => l_order_number,
4259              p_ctfn_rqd_flag          => l_ctfn_rqd,
4260              p_enrt_bnft_id           => l_enrt_bnft_id,
4261              p_enb_valrow             => p_enb_valrow,
4262              p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
4263              p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
4264              p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
4265              p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
4266              p_bnft_amount            => l_cvg_amount,
4267              p_vapro_exist            => l_vapro_exist
4268              );
4269 
4270           if l_ctfn_rqd = 'Y'
4271             and not p_calculate_only_mode
4272           then
4273             --
4274             write_ctfn;
4275             --
4276           end if;
4277           --
4278         end if;
4279         --
4280         --  if l_vr_trtmt_cd is RPLC treat as FLFX
4281         --
4282         if l_vr_trtmt_cd = 'RPLC' then
4283           --
4284           exit;
4285           --
4286         end if;
4287         --
4288       end if;
4289       --
4290       i := i + l_cvg(0).incrmt_val;
4291       l_order_number := l_order_number + 1;
4292       --
4293     end loop;
4294     --
4295            --9434155
4296 
4297        l_dup_enr_count := 0;
4298        for l_check in c_check_dup_enb_enr(p_elig_per_elctbl_chc_id) loop
4299        l_dup_enr_count := l_dup_enr_count + 1;
4300        hr_utility.set_location ('count : '||l_dup_enr_count,10);
4301        if l_dup_enr_count > 1 then
4302           exit;
4303        end if;
4304        end loop;
4305 
4306        if (l_dup_enr_count > 1) then
4307 	  open c_get_prev_bnft(p_effective_date);
4308 	  fetch c_get_prev_bnft into l_get_prev_bnft;
4309 	  close c_get_prev_bnft;
4310           for l_check in c_check_dup_enb_enr(p_elig_per_elctbl_chc_id) loop
4311              if l_get_prev_bnft.bnft_amt <> l_check.val then
4312 		ben_enrt_bnft_api.update_enrt_bnft
4313 				 (p_enrt_bnft_id                  => l_check.enrt_bnft_id
4314                                  ,p_dflt_flag                     => 'N'
4315                                  ,p_val_has_bn_prortd_flag        => l_check.val_has_bn_prortd_flag
4316                                  ,p_bndry_perd_cd                 => l_check.bndry_perd_cd
4317                                  ,p_val                           => l_check.val
4318                                  ,p_nnmntry_uom                   => l_check.nnmntry_uom
4319                                  ,p_bnft_typ_cd                   => l_check.bnft_typ_cd
4320                                  ,p_entr_val_at_enrt_flag         => l_check.entr_val_at_enrt_flag
4321                                  ,p_mn_val                        => l_check.mn_val
4322                                  ,p_mx_val                        => l_check.mx_val
4323                                  ,p_incrmt_val                    => l_check.incrmt_val
4324                                  ,p_dflt_val                      => l_check.dflt_val
4325                                  ,p_rt_typ_cd                     => l_check.rt_typ_cd
4326                                  ,p_cvg_mlt_cd                    => l_check.cvg_mlt_cd
4327                                  ,p_ctfn_rqd_flag                 => l_check.ctfn_rqd_flag
4328                                  ,p_ordr_num                      => l_check.ordr_num
4329                                  ,p_crntly_enrld_flag             => 'N'
4330                                  ,p_elig_per_elctbl_chc_id        => l_check.elig_per_elctbl_chc_id
4331                                  ,p_prtt_enrt_rslt_id             => null
4332                                  ,p_comp_lvl_fctr_id              => l_check.comp_lvl_fctr_id
4333                                  ,p_business_group_id             => l_check.business_group_id
4334                                  ,p_enb_attribute_category        => l_check.enb_attribute_category
4335                                  ,p_enb_attribute1                => l_check.enb_attribute1
4336                                  ,p_enb_attribute2                => l_check.enb_attribute2
4337                                  ,p_enb_attribute3                => l_check.enb_attribute3
4338                                  ,p_enb_attribute4                => l_check.enb_attribute4
4339                                  ,p_enb_attribute5                => l_check.enb_attribute5
4340                                  ,p_enb_attribute6                => l_check.enb_attribute6
4341                                  ,p_enb_attribute7                => l_check.enb_attribute7
4342                                  ,p_enb_attribute8                => l_check.enb_attribute8
4343                                  ,p_enb_attribute9                => l_check.enb_attribute9
4344                                  ,p_enb_attribute10               => l_check.enb_attribute10
4345                                  ,p_enb_attribute11               => l_check.enb_attribute11
4346                                  ,p_enb_attribute12               => l_check.enb_attribute12
4347                                  ,p_enb_attribute13               => l_check.enb_attribute13
4348                                  ,p_enb_attribute14               => l_check.enb_attribute14
4349                                  ,p_enb_attribute15               => l_check.enb_attribute15
4350                                  ,p_enb_attribute16               => l_check.enb_attribute16
4351                                  ,p_enb_attribute17               => l_check.enb_attribute17
4352                                  ,p_enb_attribute18               => l_check.enb_attribute18
4353                                  ,p_enb_attribute19               => l_check.enb_attribute19
4354                                  ,p_enb_attribute20               => l_check.enb_attribute20
4355                                  ,p_enb_attribute21               => l_check.enb_attribute21
4356                                  ,p_enb_attribute22               => l_check.enb_attribute22
4357                                  ,p_enb_attribute23               => l_check.enb_attribute23
4358                                  ,p_enb_attribute24               => l_check.enb_attribute24
4359                                  ,p_enb_attribute25               => l_check.enb_attribute25
4360                                  ,p_enb_attribute26               => l_check.enb_attribute26
4361                                  ,p_enb_attribute27               => l_check.enb_attribute27
4362                                  ,p_enb_attribute28               => l_check.enb_attribute28
4363                                  ,p_enb_attribute29               => l_check.enb_attribute29
4364                                  ,p_enb_attribute30               => l_check.enb_attribute30
4365                                  ,p_request_id                    => l_check.request_id
4366                                  ,p_program_application_id        => l_check.program_application_id
4367                                  ,p_program_id                    => l_check.program_id
4368                                  ,p_program_update_date           => l_check.program_update_date
4369                                  ,p_mx_wout_ctfn_val              => l_check.mx_wout_ctfn_val
4370                                  ,p_mx_wo_ctfn_flag               => l_check.mx_wo_ctfn_flag
4371                                  ,p_object_version_number         => l_check.object_version_number
4372                                  ,p_effective_date                => trunc(p_effective_date));
4373 	     end if;
4374 	  end loop;
4375 	  end if;
4376     --9434155
4377   elsif l_cvg(0).cvg_mlt_cd = 'FLFXPCL' then
4378       hr_utility.set_location (' CMC FLFXPCL ',10);
4379     --
4380     l_ctfn_rqd := 'N';
4381     l_write_rec := true;
4382     --
4383     benutils.rt_typ_calc
4384       (p_val              => l_cvg(0).mn_val,
4385        p_val_2            => l_compensation_value,
4386        p_rt_typ_cd        => l_cvg(0).rt_typ_cd,
4387        p_calculated_val   => l_calculated_val);
4388     --
4389        hr_utility.set_location (' l_calculated_val ' || l_calculated_val,10);
4390        hr_utility.set_location (' l_cvg(0).val '|| l_cvg(0).val,10);
4391     --
4392        l_calculated_val := l_calculated_val + l_cvg(0).val;
4393     --
4394        l_val := round_val(
4395               p_val                    => l_calculated_val,
4396               p_effective_date         => p_effective_date,
4397               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4398               p_rndg_cd                => l_cvg(0).rndg_cd,
4399               p_rndg_rl                => l_cvg(0).rndg_rl
4400               );
4401           l_cvg_amount := l_val ;
4402           --validate the limit for benefir amount
4403           hr_utility.set_location ('limit_checks ',10);
4404 
4405           l_tot_val := l_val ;
4406           --
4407           hr_utility.set_location (' l_tot_val ' || l_tot_val,10);
4408           --
4409           benutils.limit_checks
4410           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
4411               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
4412               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
4413               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
4414               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4415               p_assignment_id     => l_asg.assignment_id,
4416               p_organization_id   => l_asg.organization_id,
4417               p_business_group_id => l_epe.business_group_id,
4418               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4419               p_pgm_id            => l_epe.pgm_id,
4420               p_pl_id             => l_epe.pl_id,
4421               p_pl_typ_id         => l_epe.pl_typ_id,
4422               p_opt_id            => l_opt.opt_id,
4423               p_ler_id            => l_epe.ler_id,
4424               p_val               => l_tot_val,   -- 3095224,
4425               p_state             => l_state.region_2);
4426 
4427     ben_determine_coverage.combine_with_variable_val
4428       (p_vr_val           => l_vr_val,
4429        p_val              => l_tot_val, -- 3095224 l_val+l_cvg(0).val,
4430        p_vr_trtmt_cd      => l_vr_trtmt_cd,
4431        p_combined_val     => l_combined_val);
4432     --
4433     if l_rstrn_found then
4434       --
4435       ben_determine_coverage.chk_bnft_ctfn
4436          (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
4437           p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
4438           p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
4439           p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
4440           p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
4441           p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
4442           p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
4443           p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
4444           p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
4445           p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
4446           p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
4447           p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
4448           p_combined_val             => l_combined_val,
4449           p_crnt_bnft_amt            => l_bnft_amt,
4450           p_ordr_num                 => l_order_number,
4451           p_crnt_ordr_num            => l_crnt_ordr_num,
4452           p_ctfn_rqd                 => l_ctfn_rqd,
4453           p_write_rec                => l_write_rec,
4454           p_effective_date           => nvl(p_lf_evt_ocrd_dt,
4455                                             p_effective_date),
4456           p_assignment_id            => l_asg.assignment_id,
4457           p_organization_id          => l_asg.organization_id,
4458           p_business_group_id        => l_epe.business_group_id,
4459           p_pgm_id                   => l_epe.pgm_id,
4460           p_pl_id                    => l_epe.pl_id,
4461           p_pl_typ_id                => l_epe.pl_typ_id,
4462           p_opt_id                   => l_opt.opt_id,
4463           p_ler_id                   => l_epe.ler_id,
4464           p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
4465           p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
4466           p_jurisdiction_code        => l_jurisdiction_code,
4467           p_check_received           => l_check_received,
4468           /* Start of Changes for WWBUG: 2054078  added parameter */
4469           p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
4470           /* End of Changes for WWBUG: 2054078  added parameter */
4471 --Bug 4644489
4472   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
4473 --End Bug 4644489
4474        --
4475     end if;
4476     --
4477     if l_write_rec then
4478       --
4479       ben_determine_coverage.write_coverage
4480         (p_calculate_only_mode    => p_calculate_only_mode,
4481          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
4482          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
4483          p_val                    => l_combined_val,
4484          p_dflt_flag              => l_epe.dflt_flag,  --BUG 4449437
4485          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
4486          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4487          p_business_group_id      => l_cvg(0).business_group_id,
4488          p_effective_date         => p_effective_date,
4489          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4490          p_person_id              => l_epe.person_id,
4491          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
4492          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
4493          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
4494          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
4495          p_rndg_cd                => l_cvg(0).rndg_cd,
4496          p_rndg_rl                => l_cvg(0).rndg_rl,
4497          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
4498          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
4499          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
4500          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
4501          /* CODE PRIOR TO WWBUG: 2054078
4502          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
4503          */
4504          /* Start of Changes for WWBUG: 2054078         */
4505          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
4506          /* End of Changes for WWBUG: 2054078           */
4507          p_mn_val                 => null, -- l_cvg(0).mn_val, Commented for bug 3102355
4508          p_dflt_val               => l_cvg(0).dflt_val,
4509          p_incrmt_val             => l_cvg(0).incrmt_val,
4510          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
4511          p_perform_rounding_flg   => l_perform_rounding_flg,
4512          p_ordr_num               => l_order_number,
4513          p_ctfn_rqd_flag          => l_ctfn_rqd,
4514          p_enrt_bnft_id           => l_enrt_bnft_id,
4515          p_enb_valrow             => p_enb_valrow ,
4516          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
4517          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
4518          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
4519          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
4520          p_bnft_amount            => l_cvg_amount,
4521          p_vapro_exist            => l_vapro_exist
4522          );
4523       --
4524       if l_ctfn_rqd = 'Y'
4525         and not p_calculate_only_mode
4526       then
4527         --
4528         write_ctfn;
4529         --
4530       end if;
4531       --
4532     else
4533       --
4534       -- Update the electable choice to be not electable
4535       --
4536       if l_epe.elctbl_flag='Y' then
4537         --
4538         if not p_calculate_only_mode then
4539           --
4540           ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc(
4541              p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id,
4542              p_elctbl_flag             => 'N',
4543              p_dflt_flag               => 'N',
4544              p_object_version_number   => l_epe.object_version_number,
4545              p_effective_date          => p_effective_date,
4546              p_program_application_id  => fnd_global.prog_appl_id,
4547              p_program_id              => fnd_global.conc_program_id,
4548              p_request_id              => fnd_global.conc_request_id,
4549              p_program_update_date     => sysdate
4550              );
4551            --
4552            -- If enrolled will deenroll.
4553            --
4554            ben_newly_ineligible.main(
4555               p_person_id           => l_epe.person_id,
4556               p_pgm_id              => l_epe.pgm_id,
4557               p_pl_id               => l_epe.pl_id,
4558               p_oipl_id             => l_epe.oipl_id,
4559               p_business_group_id   => l_epe.business_group_id,
4560               p_ler_id              => l_epe.ler_id,
4561               p_effective_date      => p_effective_date
4562            );
4563           --
4564         end if;
4565         l_epe.elctbl_flag:='N';
4566         hr_utility.set_location('Electable choice was made not electable by bencvrge',29);
4567       end if;
4568       ben_determine_coverage.write_coverage
4569         (p_calculate_only_mode    => p_calculate_only_mode,
4570          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
4571          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
4572          p_val                    => l_combined_val,
4573          p_dflt_flag              => l_dflt_flag,
4574          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
4575          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4576          p_business_group_id      => l_cvg(0).business_group_id,
4577          p_effective_date         => p_effective_date,
4578          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4579          p_person_id              => l_epe.person_id,
4580          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
4581          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
4582          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
4583          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
4584          p_rndg_cd                => l_cvg(0).rndg_cd,
4585          p_rndg_rl                => l_cvg(0).rndg_rl,
4586          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
4587          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
4588          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
4589          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
4590          /*
4591             CODE PRIOR TO WWBUG: 2054078
4592          p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
4593          */
4594          /* Start of Changes for WWBUG: 2054078         */
4595          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
4596          /* End of Changes for WWBUG: 2054078           */
4597          p_mn_val                 => null, -- l_cvg(0).mn_val, For Bug 3102355
4598          p_dflt_val               => l_cvg(0).dflt_val,
4599          p_incrmt_val             => l_cvg(0).incrmt_val,
4600          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
4601          p_perform_rounding_flg   => l_perform_rounding_flg,
4602          p_ordr_num               => l_order_number,
4603          p_ctfn_rqd_flag          => l_ctfn_rqd,
4604          p_enrt_bnft_id           => l_enrt_bnft_id,
4605          p_enb_valrow             => p_enb_valrow ,
4606          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
4607          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
4608          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
4609          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
4610          p_bnft_amount            => l_cvg_amount,
4611          p_vapro_exist            => l_vapro_exist
4612          );
4613       --
4614     end if;
4615     --
4616   elsif l_cvg(0).cvg_mlt_cd = 'FLPCLRNG' then
4617       hr_utility.set_location (' CMC FLPCLRNG ',10);
4618   --
4619      i := l_cvg(0).mn_val;
4620      --
4621      while i <= l_cvg(0).mx_val loop
4622        --
4623        l_ctfn_rqd := 'N';
4624        l_write_rec := true;
4625        --
4626        if l_incr_r_decr_cd is null or
4627           ((l_incr_r_decr_cd='INCRO' and
4628             l_order_number > nvl(l_crnt_ordr_num,0)) or
4629            (l_incr_r_decr_cd='EQINCR' and
4630             l_order_number >=  nvl(l_crnt_ordr_num,0)) or
4631            (l_incr_r_decr_cd='DECRO' and
4632             l_order_number < nvl(l_crnt_ordr_num,0)) or
4633            (l_incr_r_decr_cd='EQDECR' and
4634             l_order_number <=  nvl(l_crnt_ordr_num,0))) then
4635          --
4636          benutils.rt_typ_calc
4637            (p_val              => i,
4638             p_val_2            => l_compensation_value,
4639             p_rt_typ_cd        => l_cvg(0).rt_typ_cd,
4640             p_calculated_val   => l_calculated_val);
4641          --_
4642          l_val := round_val(
4643               p_val                    => l_calculated_val,
4644               p_effective_date         => p_effective_date,
4645               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4646               p_rndg_cd                => l_cvg(0).rndg_cd,
4647               p_rndg_rl                => l_cvg(0).rndg_rl
4648               );
4649           l_cvg_amount := l_val ;
4650           --validate the limit for benefir amount
4651 
4652           l_tot_val := l_val+l_cvg(0).val; -- 3095224
4653 
4654 
4655           hr_utility.set_location ('limit_checks ',10);
4656           benutils.limit_checks
4657           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
4658               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
4659               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
4660               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
4661               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4662               p_assignment_id     => l_asg.assignment_id,
4663               p_organization_id   => l_asg.organization_id,
4664               p_business_group_id => l_epe.business_group_id,
4665               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4666               p_pgm_id            => l_epe.pgm_id,
4667               p_pl_id             => l_epe.pl_id,
4668               p_pl_typ_id         => l_epe.pl_typ_id,
4669               p_opt_id            => l_opt.opt_id,
4670               p_ler_id            => l_epe.ler_id,
4671               p_val               => l_tot_val , -- 3095224 l_val,
4672               p_state             => l_state.region_2);
4673 
4674 
4675 
4676          ben_determine_coverage.combine_with_variable_val
4677            (p_vr_val           => l_vr_val,
4678             p_val              => l_tot_val, -- 3095224 l_val+l_cvg(0).val,
4679             p_vr_trtmt_cd      => l_vr_trtmt_cd,
4680             p_combined_val     => l_combined_val);
4681          --
4682            if (l_dflt_enrt_cd in ('NSDCS','NNCS')
4683 --                 and i <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4684                    and l_combined_val <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
4685               (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num <> l_order_number)
4686            then
4687              l_dflt_flag := 'N';
4688 
4689            elsif (l_dflt_enrt_cd in ('NSDCS','NNCS')
4690 --                    and i = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4691                     and l_combined_val = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
4692                  (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num = l_order_number)
4693            then
4694 
4695              l_dflt_flag := 'Y';
4696 
4697            elsif l_dflt_enrt_cd not in ('NSDCS','NNCS') and
4698                  i = l_cvg(0).dflt_val then
4699 
4700              l_dflt_flag := 'Y';
4701 
4702            else
4703 
4704              l_dflt_flag := 'N';
4705 
4706            end if;
4707 
4708          if l_rstrn_found then
4709            --
4710            ben_determine_coverage.chk_bnft_ctfn
4711              (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
4712               p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
4713               p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
4714               p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
4715               p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
4716               p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
4717               p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
4718               p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
4719               p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
4720               p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
4721               p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
4722               p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
4723               p_combined_val             => l_combined_val,
4724               p_crnt_bnft_amt            => l_bnft_amt,
4725               p_ordr_num                 => l_order_number,
4726               p_crnt_ordr_num            => l_crnt_ordr_num,
4727               p_ctfn_rqd                 => l_ctfn_rqd,
4728               p_write_rec                => l_write_rec,
4729               p_effective_date           => nvl(p_lf_evt_ocrd_dt,
4730                                                 p_effective_date),
4731               p_assignment_id            => l_asg.assignment_id,
4732               p_organization_id          => l_asg.organization_id,
4733               p_business_group_id        => l_epe.business_group_id,
4734               p_pgm_id                   => l_epe.pgm_id,
4735               p_pl_id                    => l_epe.pl_id,
4736               p_pl_typ_id                => l_epe.pl_typ_id,
4737               p_opt_id                   => l_opt.opt_id,
4738               p_ler_id                   => l_epe.ler_id,
4739               p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
4740               p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
4741               p_jurisdiction_code        => l_jurisdiction_code,
4742               p_check_received           => l_check_received,
4743               /* Start of Changes for WWBUG: 2054078            */
4744               p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
4745               /* End of Changes for WWBUG: 2054078              */
4746 --Bug 4644489
4747   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
4748 --End Bug 4644489
4749            --
4750          end if;
4751          --
4752          if l_write_rec then
4753            --
4754            if l_epe.oipl_id is not null then
4755              --
4756              open c_opt(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
4757                --
4758                fetch c_opt into l_opt;
4759                --
4760              close c_opt;
4761              --
4762            end if;
4763            --
4764            ben_determine_coverage.write_coverage
4765              (p_calculate_only_mode    => p_calculate_only_mode,
4766               p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
4767               p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
4768               p_val                    => l_combined_val,
4769               p_dflt_flag              => l_dflt_flag,
4770               p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
4771               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4772               p_business_group_id      => l_cvg(0).business_group_id,
4773               p_effective_date         => p_effective_date,
4774               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4775               p_person_id              => l_epe.person_id,
4776               p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
4777               p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
4778               p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
4779               p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
4780               p_rndg_cd                => l_cvg(0).rndg_cd,
4781               p_rndg_rl                => l_cvg(0).rndg_rl,
4782               p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
4783               p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
4784               p_entr_val_at_enrt_flag  => 'N',--l_cvg(0).entr_val_at_enrt_flag,
4785               p_mx_val                 => null,--l_cvg(0).mx_val,
4786               p_mx_wout_ctfn_val       => null, --l_rstrn.mx_cvg_alwd_amt
4787               p_mn_val                 => null,--l_cvg(0).mn_val,
4788               p_incrmt_val             => null,--l_cvg(0).incrmt_val,
4789               p_dflt_val               => null,--l_dflt_val,
4790               p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
4791               p_perform_rounding_flg   => l_perform_rounding_flg,
4792               p_ordr_num               => l_order_number,
4793               p_ctfn_rqd_flag          => l_ctfn_rqd,
4794               p_enrt_bnft_id           => l_enrt_bnft_id,
4795               p_enb_valrow             => p_enb_valrow,
4796               p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
4797               p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
4798               p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
4799               p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
4800               p_bnft_amount            => l_cvg_amount,
4801               p_vapro_exist            => l_vapro_exist
4802               );
4803            --
4804            if l_ctfn_rqd = 'Y'
4805              and not p_calculate_only_mode
4806            then
4807              --
4808              write_ctfn;
4809              --
4810            end if;
4811            --
4812          end if;
4813          --
4814          --  if l_vr_trtmt_cd is RPLC treat as FLFX
4815          --
4816          if l_vr_trtmt_cd = 'RPLC' then
4817            --
4818            exit;
4819            --
4820          end if;
4821          --
4822        end if;
4823        --
4824        i := i + l_cvg(0).incrmt_val;
4825        l_order_number := l_order_number + 1;
4826        --
4827      end loop;
4828     --
4829   elsif l_cvg(0).cvg_mlt_cd = 'CLPFLRNG' then
4830       hr_utility.set_location (' CMC CLPFLRNG ',10);
4831     --
4832     benutils.rt_typ_calc
4833       (p_val              => l_cvg(0).val,
4834        p_val_2            => l_compensation_value,
4835        p_rt_typ_cd        => l_cvg(0).rt_typ_cd,
4836        p_calculated_val   => l_calculated_val);
4837     --
4838     l_val := round_val(
4839               p_val                    => l_calculated_val,
4840               p_effective_date         => p_effective_date,
4841               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
4842               p_rndg_cd                => l_cvg(0).rndg_cd,
4843               p_rndg_rl                => l_cvg(0).rndg_rl
4844               );
4845      i := l_cvg(0).mn_val;
4846      l_cvg_amount := l_val ;
4847 
4848       /*  moved the limit check to inside the loop to enforce the limit on compensation + range
4849           --validate the limit for benefir amount
4850           hr_utility.set_location ('limit_checks ',10);
4851           benutils.limit_checks
4852           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
4853               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
4854               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
4855               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
4856               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4857               p_assignment_id     => l_asg.assignment_id,
4858               p_organization_id   => l_asg.organization_id,
4859               p_business_group_id => l_epe.business_group_id,
4860               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4861               p_pgm_id            => l_epe.pgm_id,
4862               p_pl_id             => l_epe.pl_id,
4863               p_pl_typ_id         => l_epe.pl_typ_id,
4864               p_opt_id            => l_opt.opt_id,
4865               p_ler_id            => l_epe.ler_id,
4866               p_val               => l_val,
4867               p_state             => l_state.region_2);
4868        */
4869 
4870     --
4871     while i <= l_cvg(0).mx_val loop
4872       --
4873       l_ctfn_rqd := 'N';
4874       l_write_rec := true;
4875       --
4876       if l_incr_r_decr_cd is null or
4877           ((l_incr_r_decr_cd='INCRO' and
4878             l_order_number > nvl(l_crnt_ordr_num,0)) or
4879            (l_incr_r_decr_cd='EQINCR' and
4880             l_order_number >=  nvl(l_crnt_ordr_num,0)) or
4881            (l_incr_r_decr_cd='DECRO' and
4882             l_order_number < nvl(l_crnt_ordr_num,0)) or
4883            (l_incr_r_decr_cd='EQDECR' and
4884             l_order_number <=  nvl(l_crnt_ordr_num,0))) then
4885         --bug#2708285 - limit checked for the compensation plus flat amount
4886           l_tot_val  := l_val + i;
4887           benutils.limit_checks
4888           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
4889               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
4890               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
4891               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
4892               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4893               p_assignment_id     => l_asg.assignment_id,
4894               p_organization_id   => l_asg.organization_id,
4895               p_business_group_id => l_epe.business_group_id,
4896               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4897               p_pgm_id            => l_epe.pgm_id,
4898               p_pl_id             => l_epe.pl_id,
4899               p_pl_typ_id         => l_epe.pl_typ_id,
4900               p_opt_id            => l_opt.opt_id,
4901               p_ler_id            => l_epe.ler_id,
4902               p_val               => l_tot_val,
4903               p_state             => l_state.region_2);
4904 
4905 
4906 
4907         ben_determine_coverage.combine_with_variable_val
4908           (p_vr_val           => l_vr_val,
4909            p_val              => l_tot_val, --l_val+i,
4910            p_vr_trtmt_cd      => l_vr_trtmt_cd,
4911            p_combined_val     => l_combined_val);
4912         --
4913            if (l_dflt_enrt_cd in ('NSDCS','NNCS')
4914 --                      and i <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4915                         and  l_combined_val <> NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
4916               (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num <> l_order_number)
4917            then
4918              l_dflt_flag := 'N';
4919 
4920            elsif (l_dflt_enrt_cd in ('NSDCS','NNCS')
4921 --                       and i = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or
4922                          and l_combined_val = NVL(l_bnft_amt,l_current_enrt_sspndd.bnft_amt)) or -- Bug 6068097
4923                  (l_dflt_enrt_cd in ('NSDCS','NNCS') and l_crnt_ordr_num = l_order_number)
4924            then
4925 
4926              l_dflt_flag := 'Y';
4927 
4928            elsif l_dflt_enrt_cd not in ('NSDCS','NNCS') and
4929                  i = l_cvg(0).dflt_val then
4930 
4931              l_dflt_flag := 'Y';
4932 
4933            else
4934 
4935              l_dflt_flag := 'N';
4936 
4937            end if;
4938 
4939         if l_rstrn_found then
4940           --
4941           ben_determine_coverage.chk_bnft_ctfn
4942             (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
4943              p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
4944              p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
4945              p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
4946              p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
4947              p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
4948              p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
4949              p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
4950              p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
4951              p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
4952              p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
4953              p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
4954              p_combined_val             => l_combined_val,
4955              p_crnt_bnft_amt            => l_bnft_amt,
4956              p_ordr_num                 => l_order_number,
4957              p_crnt_ordr_num            => l_crnt_ordr_num,
4958              p_ctfn_rqd                 => l_ctfn_rqd,
4959              p_write_rec                => l_write_rec,
4960              p_effective_date           => nvl(p_lf_evt_ocrd_dt,p_effective_date),
4961              p_assignment_id            => l_asg.assignment_id,
4962              p_organization_id          => l_asg.organization_id,
4963              p_business_group_id        => l_epe.business_group_id,
4964              p_pgm_id                   => l_epe.pgm_id,
4965              p_pl_id                    => l_epe.pl_id,
4966              p_pl_typ_id                => l_epe.pl_typ_id,
4967              p_opt_id                   => l_opt.opt_id,
4968              p_ler_id                   => l_epe.ler_id,
4969              p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
4970              p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
4971              p_jurisdiction_code        => l_jurisdiction_code,
4972              p_check_received           => l_check_received,
4973              /* Start of Changes for WWBUG: 2054078:  added parameter   */
4974              p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
4975              /* End of Changes for WWBUG: 2054078:  added parameter     */
4976 --Bug 4644489
4977   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
4978 --End Bug 4644489
4979           --
4980         end if;
4981 
4982         if l_write_rec then
4983           if l_epe.oipl_id is not null then
4984             open c_opt(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
4985             fetch c_opt into l_opt;
4986             close c_opt;
4987           end if;
4988 
4989           ben_determine_coverage.write_coverage
4990             (p_calculate_only_mode    => p_calculate_only_mode,
4991              p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
4992              p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
4993              p_val                    => l_combined_val,
4994              p_dflt_flag              => l_dflt_flag,
4995              p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
4996              p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
4997              p_business_group_id      => l_cvg(0).business_group_id,
4998              p_effective_date         => p_effective_date,
4999              p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5000              p_person_id              => l_epe.person_id,
5001              p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
5002              p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
5003              p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
5004              p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
5005              p_rndg_cd                => l_cvg(0).rndg_cd,
5006              p_rndg_rl                => l_cvg(0).rndg_rl,
5007              p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
5008              p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
5009              p_entr_val_at_enrt_flag  => 'N',--l_cvg(0).entr_val_at_enrt_flag,
5010              p_mx_val                 => null,--l_cvg(0).mx_val,
5011              p_mx_wout_ctfn_val       => null, --l_rstrn.mx_cvg_alwd_amt
5012              p_mn_val                 => null,--l_cvg(0).mn_val,
5013              p_dflt_val               => null,--l_dflt_val,
5014              p_incrmt_val             => null,--l_cvg(0).incrmt_val,
5015              p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
5016              p_perform_rounding_flg   => l_perform_rounding_flg,
5017              p_ordr_num               => l_order_number,
5018              p_ctfn_rqd_flag          => l_ctfn_rqd,
5019              p_enrt_bnft_id           => l_enrt_bnft_id,
5020              p_enb_valrow             => p_enb_valrow,
5021              p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
5022              p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
5023              p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
5024              p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
5025              p_bnft_amount            => l_cvg_amount,
5026              p_vapro_exist            => l_vapro_exist
5027              );
5028 
5029           if l_ctfn_rqd = 'Y'
5030             and not p_calculate_only_mode
5031           then
5032             write_ctfn;
5033           end if;
5034 
5035         end if;
5036         --
5037         --  if l_vr_trtmt_cd is RPLC treat as FLFX
5038         --
5039         if l_vr_trtmt_cd = 'RPLC' then
5040           exit;
5041         end if;
5042 
5043       end if;
5044       i := i + l_cvg(0).incrmt_val;
5045       l_order_number := l_order_number + 1;
5046 
5047     end loop;
5048 
5049   elsif l_cvg(0).cvg_mlt_cd = 'SAAEAR' then
5050     hr_utility.set_location (' CMC SAAEAR ',10);
5051     l_ctfn_rqd := 'N';
5052     l_write_rec := true;
5053 
5054     ben_determine_coverage.write_coverage
5055       (p_calculate_only_mode    => p_calculate_only_mode,
5056        p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
5057        p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
5058        p_val                    => null,
5059        p_dflt_flag              => l_epe.dflt_flag,
5060        p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
5061        p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5062        p_business_group_id      => l_cvg(0).business_group_id,
5063        p_effective_date         => p_effective_date,
5064        p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5065        p_person_id              => l_epe.person_id,
5066        p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
5067        p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
5068        p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
5069        p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
5070        p_rndg_cd                => l_cvg(0).rndg_cd,
5071        p_rndg_rl                => l_cvg(0).rndg_rl,
5072        p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
5073        p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
5074        p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
5075          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
5076        /*
5077              CODE PRIOR TO WWBUG: 2054078
5078        p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
5079        */
5080        /* Start of Changes for WWBUG: 2054078   */
5081        p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
5082        /* End of Changes for WWBUG: 2054078     */
5083        p_mn_val                 => l_cvg(0).mn_val,
5084        p_dflt_val               => l_cvg(0).dflt_val,
5085        p_incrmt_val             => l_cvg(0).incrmt_val,
5086        p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
5087        p_perform_rounding_flg   => l_perform_rounding_flg,
5088        p_ordr_num               => l_order_number,
5089        p_ctfn_rqd_flag          => l_ctfn_rqd,
5090        p_enrt_bnft_id           => l_enrt_bnft_id,
5091        p_enb_valrow             => p_enb_valrow,
5092        p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
5093        p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
5094        p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
5095        p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
5096        p_bnft_amount            => l_cvg_amount,
5097        p_vapro_exist            => l_vapro_exist
5098        );
5099     --
5100   elsif l_cvg(0).cvg_mlt_cd = 'NSVU' then
5101     --
5102     hr_utility.set_location (' CMC NSVU ',10);
5103     --
5104     l_ctfn_rqd := 'N';
5105     l_write_rec := true;
5106     --
5107 --Bug 6054310
5108     l_vr_val := nvl(l_vr_val, l_dflt_elcn_val);
5109     --
5110 --Bug 6054310
5111     ben_determine_coverage.combine_with_variable_val
5112       (p_vr_val           => l_vr_val,
5113        p_val              => l_cvg(0).val,    -- 5933576 Removed l_calculated_val from here
5114        p_vr_trtmt_cd      => l_vr_trtmt_cd,
5115        p_combined_val     => l_combined_val);
5116     --
5117     if l_combined_val is null or l_combined_val = 0 then
5118       --
5119       fnd_message.set_name('BEN','BEN_91841_BENCVRGE_VAL_RQD');
5120       fnd_message.set_token('PACKAGE',l_package);
5121       fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
5122       fnd_message.set_token('CALC_MTHD',l_cvg(0).cvg_mlt_cd);
5123       fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
5124       fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
5125       fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
5126       fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
5127       fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
5128       fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
5129       fnd_message.raise_error;
5130       --
5131     end if;
5132     --
5133     --Bug 5933576 Adding chk_bnft_ctfn for NSVU as well
5134     --
5135     if l_rstrn_found then
5136       --
5137       ben_determine_coverage.chk_bnft_ctfn
5138          (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
5139           p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
5140           p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
5141           p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
5142           p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
5143           p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
5144           p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
5145           p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
5146           p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
5147           p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
5148           p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
5149           p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
5150           p_combined_val             => l_combined_val,
5151           p_crnt_bnft_amt            => l_bnft_amt,
5152           p_ordr_num                 => l_order_number,
5153           p_crnt_ordr_num            => l_crnt_ordr_num,
5154           p_ctfn_rqd                 => l_ctfn_rqd,
5155           p_write_rec                => l_write_rec,
5156           p_effective_date           => nvl(p_lf_evt_ocrd_dt, p_effective_date),
5157           p_assignment_id            => l_asg.assignment_id,
5158           p_organization_id          => l_asg.organization_id,
5159           p_business_group_id        => l_epe.business_group_id,
5160           p_pgm_id                   => l_epe.pgm_id,
5161           p_pl_id                    => l_epe.pl_id,
5162           p_pl_typ_id                => l_epe.pl_typ_id,
5163           p_opt_id                   => l_opt.opt_id,
5164           p_ler_id                   => l_epe.ler_id,
5165           p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
5166           p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
5167           p_jurisdiction_code        => l_jurisdiction_code,
5168           p_check_received           => l_check_received,
5169           p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
5170           p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
5171       --
5172     end if;
5173     --
5174     if l_write_rec then
5175     --
5176     ben_determine_coverage.write_coverage
5177       (p_calculate_only_mode    => p_calculate_only_mode,
5178        p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
5179        p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
5180        p_val                    => l_combined_val,
5181        p_dflt_flag              => l_epe.dflt_flag,
5182        p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
5183        p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5184        p_business_group_id      => l_cvg(0).business_group_id,
5185        p_effective_date         => p_effective_date,
5186        p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5187        p_person_id              => l_epe.person_id,
5188        p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
5189        p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
5190        p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
5191        p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
5192        p_rndg_cd                => l_cvg(0).rndg_cd,
5193        p_rndg_rl                => l_cvg(0).rndg_rl,
5194        p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
5195        p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
5196        p_entr_val_at_enrt_flag  => l_entr_val_at_enrt_flag,--Bug #8501248 l_cvg(0).entr_val_at_enrt_flag,
5197        p_mx_val                 => nvl(l_rstrn.mx_cvg_wcfn_amt, l_mx_elcn_val),--Bug #8501248 nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
5198        p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
5199        p_mn_val                 => l_mn_elcn_val,--Bug #8501248 l_cvg(0).mn_val,
5200        p_dflt_val               => l_dflt_elcn_val,--Bug #8501248 NVL(l_dflt_elcn_val,l_cvg(0).dflt_val),  -- bug 8568862
5201        p_incrmt_val             => l_incrmnt_elcn_val,--Bug #8501248 l_cvg(0).incrmt_val,
5202        p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
5203        p_perform_rounding_flg   => l_perform_rounding_flg,
5204        p_ordr_num               => l_order_number,
5205        p_ctfn_rqd_flag          => l_ctfn_rqd,
5206        p_enrt_bnft_id           => l_enrt_bnft_id,
5207        p_enb_valrow             => p_enb_valrow,
5208        p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
5209        p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
5210        p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
5211        p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
5212        p_bnft_amount            => l_cvg_amount,
5213        p_vapro_exist            => l_vapro_exist
5214        );
5215       --
5216       if l_ctfn_rqd = 'Y' and not p_calculate_only_mode then
5217         --
5218         write_ctfn;
5219         --
5220       end if;
5221       --
5222     else
5223       --
5224       -- Update the electable choice to be not electable
5225       --
5226       if l_epe.elctbl_flag='Y' then
5227         --
5228         if not p_calculate_only_mode then
5229           --
5230           ben_elig_per_elc_chc_api.update_perf_elig_per_elc_chc(
5231              p_elig_per_elctbl_chc_id  => p_elig_per_elctbl_chc_id,
5232              p_elctbl_flag             => 'N',
5233              p_dflt_flag               => 'N',
5234              p_object_version_number   => l_epe.object_version_number,
5235              p_effective_date          => p_effective_date,
5236              p_program_application_id  => fnd_global.prog_appl_id,
5237              p_program_id              => fnd_global.conc_program_id,
5238              p_request_id              => fnd_global.conc_request_id,
5239              p_program_update_date     => sysdate
5240           );
5241            --
5242            -- If enrolled will deenroll.
5243            --
5244            ben_newly_ineligible.main(
5245               p_person_id           => l_epe.person_id,
5246               p_pgm_id              => l_epe.pgm_id,
5247               p_pl_id               => l_epe.pl_id,
5248               p_oipl_id             => l_epe.oipl_id,
5249               p_business_group_id   => l_epe.business_group_id,
5250               p_ler_id              => l_epe.ler_id,
5251               p_effective_date      => p_effective_date
5252            );
5253           --
5254         end if;
5255         --
5256         l_epe.elctbl_flag:='N';
5257         hr_utility.set_location('Electable choice was made not electable by bencvrge',29);
5258       end if;
5259       ben_determine_coverage.write_coverage
5260         (p_calculate_only_mode    => p_calculate_only_mode,
5261          p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
5262          p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
5263          p_val                    => l_combined_val,
5264          p_dflt_flag              => l_epe.dflt_flag,
5265          p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
5266          p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5267          p_business_group_id      => l_cvg(0).business_group_id,
5268          p_effective_date         => p_effective_date,
5269          p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5270          p_person_id              => l_epe.person_id,
5271          p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
5272          p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
5273          p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
5274          p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
5275          p_rndg_cd                => l_cvg(0).rndg_cd,
5276          p_rndg_rl                => l_cvg(0).rndg_rl,
5277          p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
5278          p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
5279          p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
5280          p_mx_val                 => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
5281          p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
5282          p_mn_val                 => l_cvg(0).mn_val,
5283          p_incrmt_val             => l_cvg(0).incrmt_val,
5284          p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
5285          p_dflt_val               => l_cvg(0).dflt_val,
5286          p_perform_rounding_flg   => l_perform_rounding_flg,
5287          p_ordr_num               => l_order_number,
5288          p_ctfn_rqd_flag          => l_ctfn_rqd,
5289          p_enrt_bnft_id           => l_enrt_bnft_id,
5290          p_enb_valrow             => p_enb_valrow,
5291          p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
5292          p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
5293          p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
5294          p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
5295          p_bnft_amount            => l_cvg_amount,
5296          p_vapro_exist            => l_vapro_exist
5297          );
5298       --
5299     end if;
5300   --
5301   --End Bug 5933576
5302   --
5303   elsif l_cvg(0).cvg_mlt_cd in ('RL','ERL') then
5304       hr_utility.set_location (' CMC RL ',10);
5305     --
5306     if l_epe.oipl_id is not null and l_opt.opt_id is null
5307     then
5308        open c_opt(l_epe.oipl_id, nvl(l_fonm_cvg_strt_dt, nvl(p_lf_evt_ocrd_dt,p_effective_date))); -- FONM
5309        fetch c_opt into l_opt;
5310        close c_opt;
5311     end if;
5312     --
5313     l_ctfn_rqd := 'N';
5314     l_write_rec := true;
5315     --
5316     -- Call formula initialise routine
5317     --
5318     l_outputs := benutils.formula
5319          (p_formula_id        => l_cvg(0).val_calc_rl,
5320           p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5321           p_business_group_id => l_epe.business_group_id,
5322           p_assignment_id     => l_asg.assignment_id,
5323           p_organization_id   => l_asg.organization_id,
5324           p_pgm_id            => l_epe.pgm_id,
5325           p_pl_id             => l_epe.pl_id,
5326           p_pl_typ_id         => l_epe.pl_typ_id,
5327           p_opt_id            => l_opt.opt_id,
5328           p_ler_id            => l_epe.ler_id,
5329           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5330           -- FONM
5331           p_param1             => 'BEN_IV_RT_STRT_DT',
5332           p_param1_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt),
5333           p_param2             => 'BEN_IV_CVG_STRT_DT',
5334           p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_cvg_strt_dt),
5335           p_jurisdiction_code => l_jurisdiction_code);
5336     --
5337     l_value := fnd_number.canonical_to_number(l_outputs(l_outputs.first).value);
5338     --
5339     l_val := round_val(
5340               p_val                    => l_value,
5341               p_effective_date         => p_effective_date,
5342               p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5343               p_rndg_cd                => l_cvg(0).rndg_cd,
5344               p_rndg_rl                => l_cvg(0).rndg_rl
5345               );
5346     l_cvg_amount := l_val ;
5347           --validate the limit for benefir amount
5348           hr_utility.set_location ('limit_checks ',10);
5349           benutils.limit_checks
5350           (p_lwr_lmt_val       => l_cvg(0).lwr_lmt_val,
5351               p_lwr_lmt_calc_rl   => l_cvg(0).lwr_lmt_calc_rl,
5352               p_upr_lmt_val       => l_cvg(0).upr_lmt_val,
5353               p_upr_lmt_calc_rl   => l_cvg(0).upr_lmt_calc_rl,
5354               p_effective_date    => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5355               p_assignment_id     => l_asg.assignment_id,
5356               p_organization_id   => l_asg.organization_id,
5357               p_business_group_id => l_epe.business_group_id,
5358               p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5359               p_pgm_id            => l_epe.pgm_id,
5360               p_pl_id             => l_epe.pl_id,
5361               p_pl_typ_id         => l_epe.pl_typ_id,
5362               p_opt_id            => l_opt.opt_id,
5363               p_ler_id            => l_epe.ler_id,
5364               p_val               => l_val,
5365               p_state             => l_state.region_2);
5366 
5367 
5368 
5369 
5370     ben_determine_coverage.combine_with_variable_val
5371       (p_vr_val           => l_vr_val,
5372        p_val              => l_val,
5373        p_vr_trtmt_cd      => l_vr_trtmt_cd,
5374        p_combined_val     => l_combined_val);
5375     --
5376 
5377     if l_rstrn_found then
5378           --
5379           ben_determine_coverage.chk_bnft_ctfn
5380             (p_mx_cvg_wcfn_amt          => l_rstrn.mx_cvg_wcfn_amt,
5381              p_mx_cvg_wcfn_mlt_num      => l_rstrn.mx_cvg_wcfn_mlt_num,
5382              p_mx_cvg_mlt_incr_num      => l_rstrn.mx_cvg_mlt_incr_num,
5383              p_mx_cvg_mlt_incr_wcf_num  => l_rstrn.mx_cvg_mlt_incr_wcf_num,
5384              p_mx_cvg_incr_alwd_amt     => l_rstrn.mx_cvg_incr_alwd_amt,
5385              p_mx_cvg_incr_wcf_alwd_amt => l_rstrn.mx_cvg_incr_wcf_alwd_amt,
5386              p_mn_cvg_rqd_amt           => l_rstrn.mn_cvg_rqd_amt,
5387              p_mx_cvg_alwd_amt          => l_rstrn.mx_cvg_alwd_amt,
5388              p_mx_cvg_rl                => l_rstrn.mx_cvg_rl,
5389              p_mn_cvg_rl                => l_rstrn.mn_cvg_rl,
5390              p_no_mn_cvg_amt_apls_flag  => l_rstrn.no_mn_cvg_amt_apls_flag,
5391              p_no_mx_cvg_amt_apls_flag  => l_rstrn.no_mx_cvg_amt_apls_flag,
5392              p_combined_val             => l_combined_val,
5393              p_crnt_bnft_amt            => l_bnft_amt,
5394              p_ordr_num                 => l_order_number,
5395              p_crnt_ordr_num            => l_crnt_ordr_num,
5396              p_ctfn_rqd                 => l_ctfn_rqd,
5397              p_write_rec                => l_write_rec,
5398              p_effective_date           => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5399              p_assignment_id            => l_asg.assignment_id,
5400              p_organization_id          => l_asg.organization_id,
5401              p_business_group_id        => l_epe.business_group_id,
5402              p_pgm_id                   => l_epe.pgm_id,
5403              p_pl_id                    => l_epe.pl_id,
5404              p_pl_typ_id                => l_epe.pl_typ_id,
5405              p_opt_id                   => l_opt.opt_id,
5406              p_ler_id                   => l_epe.ler_id,
5407              p_elig_per_elctbl_chc_id   => p_elig_per_elctbl_chc_id,
5408              p_entr_val_at_enrt_flag    => l_cvg(0).entr_val_at_enrt_flag,
5409              p_jurisdiction_code        => l_jurisdiction_code,
5410              p_check_received           => l_check_received,
5411              p_mx_cvg_wout_ctfn_val     => l_mx_cvg_wout_ctfn_val,
5412 	     p_cvg_mlt_cd		=> l_cvg(0).cvg_mlt_cd,
5413 	     --Bug 4644489
5414   	  p_rstrn_mn_cvg_rqd_amt => l_rstrn_mn_cvg_rqd_amt);
5415 --End Bug 4644489
5416              --
5417     end if;
5418     --
5419     ben_determine_coverage.write_coverage
5420       (p_calculate_only_mode    => p_calculate_only_mode,
5421        p_bndry_perd_cd          => l_cvg(0).bndry_perd_cd,
5422        p_bnft_typ_cd            => l_cvg(0).bnft_typ_cd,
5423        p_val                    => l_combined_val,
5424        p_dflt_flag              => l_epe.dflt_flag,
5425        p_nnmntry_uom            => l_cvg(0).nnmntry_uom,
5426        p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5427        p_business_group_id      => l_cvg(0).business_group_id,
5428        p_effective_date         => p_effective_date,
5429        p_lf_evt_ocrd_dt         => p_lf_evt_ocrd_dt,
5430        p_person_id              => l_epe.person_id,
5431        p_lwr_lmt_val            => l_cvg(0).lwr_lmt_val,
5432        p_lwr_lmt_calc_rl        => l_cvg(0).lwr_lmt_calc_rl,
5433        p_upr_lmt_val            => l_cvg(0).upr_lmt_val,
5434        p_upr_lmt_calc_rl        => l_cvg(0).upr_lmt_calc_rl,
5435        p_rndg_cd                => l_cvg(0).rndg_cd,
5436        p_rndg_rl                => l_cvg(0).rndg_rl,
5437        p_comp_lvl_fctr_id       => l_cvg(0).comp_lvl_fctr_id,
5438        p_cvg_mlt_cd             => l_cvg(0).cvg_mlt_cd,
5439        p_entr_val_at_enrt_flag  => l_cvg(0).entr_val_at_enrt_flag,
5440          p_mx_val      => nvl(l_rstrn.mx_cvg_wcfn_amt, l_cvg(0).mx_val),  -- mx with ctfn
5441        /*
5442            CODE PRIOR TO WWBUG: 2054078
5443        p_mx_wout_ctfn_val       => l_rstrn.mx_cvg_alwd_amt,
5444        */
5445        /* Start of Changes for WWBUG: 2054078           */
5446        p_mx_wout_ctfn_val       => nvl(l_rstrn.mx_cvg_alwd_amt,l_mx_cvg_wout_ctfn_val),
5447        /* End of Changes for WWBUG: 2054078             */
5448        p_mn_val                 => l_cvg(0).mn_val,
5449        p_dflt_val               => l_cvg(0).dflt_val,
5450        p_incrmt_val             => l_cvg(0).incrmt_val,
5451        p_rt_typ_cd              => l_cvg(0).rt_typ_cd,
5452        p_perform_rounding_flg   => l_perform_rounding_flg,
5453        p_ordr_num               => l_order_number,
5454        p_ctfn_rqd_flag          => l_ctfn_rqd,
5455        p_enrt_bnft_id           => l_enrt_bnft_id,
5456        p_enb_valrow             => p_enb_valrow,
5457        p_ultmt_upr_lmt          => l_ultmt_upr_lmt,
5458        p_ultmt_lwr_lmt          => l_ultmt_lwr_lmt,
5459        p_ultmt_upr_lmt_calc_rl  => l_ultmt_upr_lmt_calc_rl,
5460        p_ultmt_lwr_lmt_calc_rl  => l_ultmt_lwr_lmt_calc_rl,
5461        p_bnft_amount            => l_cvg_amount,
5462        p_vapro_exist            => l_vapro_exist
5463        );
5464     -- bug 5900235
5465     if l_cvg(0).cvg_mlt_cd = 'RL'
5466      then
5467 
5468       if  l_ctfn_rqd = 'Y'  and not p_calculate_only_mode
5469            then
5470           --
5471 
5472           write_ctfn;
5473           --
5474        end if;  -- end 5900235
5475     else
5476        if not p_calculate_only_mode and l_rstrn_found
5477            then
5478           --
5479           write_ctfn;
5480           --
5481        end if;
5482     end if;
5483   --
5484   else
5485     --
5486     fnd_message.set_name('BEN','BEN_91844_BENCVRGE_MLT_CD');
5487     fnd_message.set_token('PACKAGE',l_package);
5488     fnd_message.set_token('PERSON_ID',to_char(l_epe.person_id));
5489     fnd_message.set_token('CALC_MTHD',l_cvg(0).cvg_mlt_cd);
5490     fnd_message.set_token('PGM_ID',to_char(l_epe.pgm_id));
5491     fnd_message.set_token('PL_ID',to_char(l_epe.pl_id));
5492     fnd_message.set_token('PL_TYP_ID',to_char(l_epe.pl_typ_id));
5493     fnd_message.set_token('OIPL_ID',to_char(l_epe.oipl_id));
5494     fnd_message.set_token('PLIP_ID',to_char(l_epe.plip_id));
5495     fnd_message.set_token('PTIP_ID',to_char(l_epe.ptip_id));
5496     fnd_message.raise_error;
5497     --
5498   end if;
5499   --
5500   -- This following routine need to create an additional benefit row, if
5501   -- tne interim enrollment code is 'Same'
5502   -- this row will be used for assigning the interim coverage
5503   --
5504   hr_utility.set_location (' Current Same Calculations ',10);
5505 
5506   l_interim_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,4,2) ;
5507   l_current_level_cd := substr(l_rstrn.dflt_to_asn_pndg_ctfn_cd,2,2);
5508   --
5509   hr_utility.set_location (' l_interim_cd '||l_interim_cd,22);
5510   hr_utility.set_location (' l_current_level_cd '||l_current_level_cd,22);
5511   --
5512   l_current_plan_id := null ;
5513   l_current_oipl_id := null ;
5514   --
5515   if l_interim_cd = 'SM' then
5516     --
5517     if l_current_level_cd = 'AS' then
5518       --
5519       open c_current_enrt_in_pl_typ(l_epe.pl_typ_id,
5520                  nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
5521       fetch c_current_enrt_in_pl_typ into l_current_plan_id,l_current_oipl_id ;
5522       if c_current_enrt_in_pl_typ%found then
5523         hr_utility.set_location(' l_create_current_enb := true PLTYP',222);
5524         l_create_current_enb := true ;
5525       end if;
5526       close c_current_enrt_in_pl_typ;
5527       --
5528     elsif l_current_level_cd = 'SE' then
5529       open c_current_enrt_in_pln(l_epe.pl_id,
5530                  nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
5531       fetch c_current_enrt_in_pln into l_current_plan_id,l_current_oipl_id ;
5532       if c_current_enrt_in_pln%found then
5533         l_create_current_enb := true ;
5534       end if;
5535       close c_current_enrt_in_pln;
5536     elsif l_current_level_cd = 'SO' then
5537       -- Bug 2543071 changed the l_epe.pl_id to l_epe.oipl_id and added
5538       -- the if condition.
5539       if l_epe.oipl_id is not null then
5540         open c_current_enrt_in_oipl(l_epe.oipl_id,
5541                  nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
5542         fetch c_current_enrt_in_oipl into l_current_plan_id,l_current_oipl_id ;
5543         if c_current_enrt_in_oipl%found then
5544           l_create_current_enb := true ;
5545         end if;
5546         close c_current_enrt_in_oipl;
5547       end if;
5548     end if;
5549     --
5550     hr_utility.set_location (' l_current_plan_id '||l_current_plan_id,222);
5551     hr_utility.set_location (' l_epe.pl_id '||l_epe.pl_id,222);
5552     hr_utility.set_location (' l_current_oipl_id '||l_current_oipl_id,222);
5553     hr_utility.set_location (' l_epe.oipl_id '||l_epe.oipl_id,222);
5554     hr_utility.set_location (' Date '||nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date)),222);
5555     --
5556     if l_create_current_enb and l_current_plan_id = l_epe.pl_id
5557                             and nvl(l_current_oipl_id,-1) = nvl(l_epe.oipl_id,-1) then
5558       --
5559       hr_utility.set_location ('l_person_id '||l_person_id,222);
5560       --
5561       open c_current_enb(l_epe.pl_id,l_epe.oipl_id,
5562                  nvl(l_fonm_cvg_strt_dt,nvl(p_lf_evt_ocrd_dt,p_effective_date))) ; -- FONM
5563       fetch c_current_enb into l_current_enb ;
5564       if c_current_enb%found  and not p_calculate_only_mode then
5565         hr_utility.set_location('SAME  interim row',111);
5566         ben_enrt_bnft_api.create_enrt_bnft
5567          (p_validate               => false,
5568           p_dflt_flag              => 'N',
5569           p_val_has_bn_prortd_flag => 'N',        -- change when prorating
5570           p_bndry_perd_cd          => l_current_enb.bndry_perd_cd, -- l_cvg(0).bndry_perd_cd,
5571           p_bnft_typ_cd            => l_current_enb.bnft_typ_cd,   -- l_cvg(0).bnft_typ_cd,
5572           p_val                    => l_combined_val, --l_current_enb.bnft_amt,  -- l_rstrn.mx_cvg_alwd_amt, /*ENH */
5573 	                              /*Bug 9774647:When salary change event occurs, update the coverage amount of the interim with the newly calculated value */
5574           p_nnmntry_uom            => l_current_enb.nnmntry_uom, -- l_cvg(0).nnmntry_uom,
5575           p_elig_per_elctbl_chc_id => p_elig_per_elctbl_chc_id,
5576           p_prtt_enrt_rslt_id      => l_current_enb.prtt_enrt_rslt_id,
5577           p_business_group_id      => l_current_enb.business_group_id, -- l_cvg(0).business_group_id,
5578           p_effective_date         => nvl(p_lf_evt_ocrd_dt,p_effective_date),
5579           p_program_application_id => fnd_global.prog_appl_id,
5580           p_program_id             => fnd_global.conc_program_id,
5581           p_request_id             => fnd_global.conc_request_id,
5582           p_comp_lvl_fctr_id       => l_current_enb.comp_lvl_fctr_id, --l_cvg(0).comp_lvl_fctr_id,
5583           p_cvg_mlt_cd             => l_current_enb.cvg_mlt_cd,       -- l_cvg(0).cvg_mlt_cd,
5584           p_crntly_enrld_flag      => 'N',
5585           p_ctfn_rqd_flag          => 'N',
5586           p_entr_val_at_enrt_flag  => 'N',
5587           p_mx_val                 => null,  -- max with ctfn
5588           p_mx_wout_ctfn_val       => null,  -- max without ctfn
5589           p_mn_val                 => null,
5590           p_incrmt_val             => null,
5591           p_dflt_val               => null,
5592           p_rt_typ_cd              => l_current_enb.rt_typ_cd, -- l_cvg(0).rt_typ_cd,
5593           p_mx_wo_ctfn_flag        => 'Y',
5594           p_program_update_date    => sysdate,
5595           p_enrt_bnft_id           => l_enrt_bnft_id,
5596           p_object_version_number  => l_object_version_number,
5597           p_ordr_num               => -1);
5598       end if;
5599       close c_current_enb ;
5600     end if;
5601     --
5602   end if;
5603   hr_utility.set_location ('Leaving '||l_package,10);
5604   --
5605  end main;
5606  --
5607 end ben_determine_coverage;