DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_DERIVE_PART_AND_RATE_FACTS

Source


1 PACKAGE BODY ben_derive_part_and_rate_facts AS
2 /* $Header: bendrpar.pkb 120.8 2009/05/01 18:35:07 stee ship $ */
3 /*
4 +==============================================================================+
5 |            Copyright (c) 1997 Oracle Corporation                            |
6 |               Redwood Shores, California, USA                               |
7 |                    All rights reserved.                                     |
8 +==============================================================================+
9 --
10 Name
11     Derive participation and rate factors
12 Purpose
13         This package is used to derive the participation and rate factors
14         that are applicable to a person who is eligible for a particular
15         comp object.
16 History
17         Date             Who        Version    What?
18         ----             ---        -------    -----
19         14 Dec 97        G Perry    110.0      Created.
20         15 Dec 97        G Perry    110.1      Changed how we handle a breach
21                                                and moved the cache structure to
22                                                the header thus making it more
23                                                accessible.
24         04 Jan 98        G Perry    110.2      Corrections following review
25                                                with DW, TM, WS. Added logging
26                                                information.
27         05 Jan 98        G Perry    110.3      Changed references of
28                                                ben_derive_part_rate_and_facts.
29                                                g_record_error to
30                                                ben_manage_life_events.
31                                                g_record_error.
32         06 Jan 98        G Perry    110.4      No changes, someone arcsed this
33                                                in as gperry, probably udatta.
34         13 Jan 98        G Perry    110.5      Commented out nocopy certain sections
35                                                as these will be corrected for
36                                                beta drop 2.
37         18 Jan 98        G Perry    110.6      Added in real error messages
38                                                which are seeded in seed11.
39         20 Jan 98        G Perry    110.7      Changed 805 application_id to use
40                                                'BEN' for fnd_message.set_name.
41         21 Jan 98        G Perry    110.8      Made caching more efficent such
42                                                that it doesn't bother recaching
43                                                when person hasn't changed.
44         21 Jan 98        G Perry    110.9      Fixed calls to do_rounding so
45                                                they use genutils function.
46         24 Jan 98        G Perry    110.10     Added in extra cache details
47                                                and added in extra codes for
48                                                derivable factor processing.
49         25 Jan 98        G Perry    110.11     Using lf_evt_ocrd_dt instead
50                                                of strt_dt for c_le_date cursor.
51         25 Jan 98        G Perry    110.12     Changed l_result to number so
52                                                formula calls handle correctly.
53         25 Jan 98        G Perry    110.13     Added call to do_uom to round by
54                                                uom code.
55         25 Jan 98        G Perry    110.14     Corrected logic in calculate_los.
56         02 Feb 98        G Perry    110.15     Added real message for get_ler_id
57                                                function.
58         03 Feb 98        G Perry    110.16     Fixed period of service stuff so
59                                                it creates a message in the log
60                                                and sets the value of the los to
61                                                null. Also added logic so that a
62                                                derivable factor only gets added
63                                                once.
64         06 Mar 98        G Perry    110.17     Added new caching functions in
65                                                order to minimize database hits.
66                                                Additionally changed life events
67                                                so they only fire once per person
68         08 Apr 98        G Perry    110.18     Added get_calculated_age proc
69                                                and added parameter to cache
70                                                _data_structures.
71         09 Apr 98        G Perry    110.19     Backport for BD2.
72         13 Apr 98        G Perry    110.20     Changed do_uom call to genutils.
73                                                Default calculations to months
74                                                when no uom supplied.
75         20 Apr 98        G Perry    110.21     Added in logic so we can trap
76                                                cache retrieval bugs and also
77                                                added in error messages where
78                                                person has no DOB.
79         22-Apr-98        THAYDEN    110.22     Rounding_uom to Rounding_cd
80         29-Apr-98        G Perry    110.23     Derived values written to the
81                                                log every time even when a
82                                                temporal life event does not
83                                                take place.
84         18-May-98        G Perry    110.24     dbsynch up.
85         27-May-98        G Perry    110.25     Added formula cover calls.
86         03-Jun-98        G Perry    110.26     Corrected formula return types
87                                                following meeting with WDS.
88         04-Jun-98        G Perry    110.27     Fixed percent_fulltime so it
89                                                uses budget_values correctly.
90         11-Jun-98        G Perry    110.28     Added cache structures to
91                                                handle temporal life events
92                                                correctly so we only create
93                                                them once.
94         07-Jul-98        J Mohapatra 110.29    Added batch who cols to call
95                                                of ben_ptnl_ler_for_per_api.creat
96                                                e_ptnl_ler_for_per
97         30-Jul-98        G Perry    110.30     Fixed error in calculate_percent
98                                                _fulltime procedure.
99         24-Aug-98        G Perry    110.31     Fixed 'STTDCOMP' for calulating
100                                                comp level. Reorganised some
101                                                code, improved calling to use
102                                                ben_determine_date.
103         26-Aug-98        G Perry    115.12     Changed comb_age_and_los to
104                                                return cache structure frozen
105                                                value.
106         28-Aug-98        G Perry    115.13     Removed storing of old temporal
107                                                life event dates. Used new logic
108                                                per WDS. Now only create life
109                                                events if prev elig per f rec.
110                                                Uses real life event occured
111                                                dates except for cmbn which
112                                                has to compare to current life
113                                                event and see if same scenario
114                                                unfolds, i.e. same boundary
115                                                broken.
116         24-Oct-98        G Perry    115.14     Added c_elig_per_opt cursor
117                                                for particpation override stuff
118                                                for oipls.
119         25-Oct-98        G Perry    115.15     Added support for benefits
120                                                balance.
121         26-Oct-98        G Perry    115.16     Fixed c_elig_per cursor
122                                                so it uses parent for pgm
123                                                where plan is in program.
124         30-Oct-98        G Perry    115.17     Added fix to get a comp
125                                                value at effective date if it
126                                                does not exist for calculated
127                                                date.
128         23-Nov-98        G Perry    115.18     Added in caching routines for
129                                                all factors and rates.
130         24-Nov-98        G Perry    115.19     Added in routines to put
131                                                derived factors to the log file.
132                                                Fixed bug 1230.
133         20-Dec-98        G Perry    115.20     Support for hours worked.
134         18-Jan-99        G Perry    115.21     LED V ED
135         08-Feb-99        G Perry    115.22     Added in ptnl_ler_trtmt_cd for
136                                                when life events are created.
137                                                Fixed logic per LM and WDS.
138         15-Feb-99        G Perry    115.23     Changed way dates are calculated
139                                                so that the calculated date for
140                                                a temporal life event will always
141                                                cross the boundary. This is used
142                                                for codes APOCT1, AFDCM, AFDCPPY
143                                                which can cause dates to be
144                                                calced incorrectly.
145         17-Feb-99        G Perry    115.24     Added columns ben_once_r_cntug_cd
146                                                and elig_flag to allow once or
147                                                continuing eligiblity to work.
148         09-APR-99        mhoyes     115.26     Un-datetrack per_in_ler_f changes
149         14-Apr-99        G Perry    115.27     Changed salary routine to
150                                                reflect HR model changes.
151         21-Apr-99        G Perry    115.28     Changes for temporal mode.
152                                                set_temporal_ler_id
153                                                get_temporal_ler_id
154                                                Proc and Function above used in
155                                                create_ptl_ler procedure.
156         21-APR-1999      mhoyes     115.29   - Modified call to
157                                                create_ptnl_ler_for_per.
158         28-APR-1999      shdas      115.30     Added contexts to rule calls.
159                                                (genutils.formula)
160         05-MAY-1999      G Perry    115.31     Added support for PTIP and PLIP
161                                                Added ben_comp_object calls.
162         07-May-1999      T Guy      115.32     backport for Fidelity.
163         07-May-1999      T Guy      115.33     Leapfrog
164         06-MAY-1999      shdas      115.34     Added jurisdiction code and
165                                                set_location messages before all
166                                                rule calls.
167         17-May-1999      bbulusu    115.35     Modified calls to ben_determine
168                                                _date to pass in comp obj ids.
169         17-May-1999      G Perry    115.36     Fixed bug 2027.
170                                                LOS Calculation now uses ASD
171                                                but if there is not one it uses
172                                                DOH.
173         18-Jun-1999      G Perry    115.37     Performance fixes.
174                                                Added calls to ben_person_object
175                                                and ben_seeddata_object.
176         23-Jun-1999      G Perry    115.38     Added calls to ben_env_object
177                                                so we no longer need g_last_pgm
178                                                _id.
179         01-Jul-1999      maagrawa   115.39     Modified min_max_breach procedure
180                                                to check minimum and maximum
181                                                boundary crossing from both
182                                                sides. Also made changes in
183                                                genutils.min_max_breach to
184                                                check the same.
185         09-Jul-1999      jcarpent   115.40     Added per_in_ler_restriction to
186                                                elig_per(_opt) queries.
187         20-JUL-1999      Gperry     115.41     genutils -> benutils package
188                                                rename.
189         22-JUL-1999      mhoyes     115.42   - Added new trace messages.
190                                              - Replaced +0s.
191         12-AUG-1999      tguy       115.43     Sync of version numbers
192         12-AUG-1999      tguy       115.44     Added spouse/dependent age calc
193                                                for imputed income
194         18-AUG-1999      Gperry     115.45     Bug fix for bug 216.
195         23-AUG-1999      Gperry     115.46     Performance fixes.
196         26-AUG-1999      Gperry     115.47     Added benefits assignment calls
197                                                when no employee assignment
198                                                is found.
199         31-AUG-1999      Pbodla     115.48     When called as part of what if
200                                                analysis for compensation calc,
201                                                hours worked return user entered
202                                                values and do not call min_max_*
203         15-SEP-1999      Gperry     115.49     Removed rates and factors from
204                                                log. Performance increase.
205         15-SEP-1999      Gperry     115.50     Added in use of environment
206                                                program for cases where we are
207                                                deriving dates at PLIP and PTIP
208                                                levels.
209         02-OCT-1999      Stee       115.51     Added new COBRA temporal events.
210         07-OCT-1999      Stee       115.52     Added COBRA temporal event for
211                                                disablity rate change.
212         07-OCT-1999      Stee       115.53     Close c_get_dsblity_evt cursor.
213         11-OCT-1999      Stee       115.54     Added a temporal event for cobra
214                                                non-payment.
215         03-NOV-1999      Tguy       115.55     Changes for added date codes for
216                                                determining factors.
217         09-NOV-1999      GPerry     115.56     Fix for bug 3855.
218                                                Returns a null when a persons
219                                                dob can not be found thus the
220                                                error is hanlded by eligibility.
221         09-NOV-1999      STee       115.57     Trigger cobra life events
222                                                based on the cbr_inelg_rsn_cd
223                                                if applicable. Fixed to only
224                                                process COBRA temporal events if
225                                                effective_date is <= to today's
226                                                date.  Add temporal event for non
227                                                or late first payment.
228         15-NOV-1999      STee       115.58     Fix due date for subsequent
229                                                payments.
230         19-NOV-1999      GPERRY     115.59     Added new flags.
231         22-NOV-1999      pbodla     115.60     Bug 3299 : Passed bnfts_bal_id to
232                                                ben_determine_date.main when
233                                                comp_lvl_det_cd, hrs_wkd_det_cd
234                                                are evaluated.
235         09-DEC-1999      pbodla     115.61   - Bug 3034 : When age, los, hwf, comp
236                                                are calculated the rules are passed
237                                                to ben_determine_date.main.
238                                              - min_max_breach : added formula_id
239                                                parameter.
240         22-Dec-1999     lmcdonal    115.62     Add comment and remove duplicate
241                                                join in get_pymt.
242         10-jan-2000     pbodla      115.63   - run_rule function added to evaluate
243                                                los_calc_rl. Code added to evaluate
244                                                los_calc_rl.
245         24-Jan-2000     lmcdonal    115.64     Add:
246                                                los ohd calc, Bug 4069.
247                                                los los_dt_to_use_cd rule call.
248                                                hrs_wkd_calc_rl, Bug 1118113.
249                                                comp_calc_rl, Bug 118118.
250                                                Modify run_rule to handle dates.
251         26-Jan-2000     stee        115.65     COBRA: Change the period of
252                                                enrollment reached life event
253                                                occurred date to be the day
254                                                after the cobra eligibility end
255                                                date. WWBUG# 1166172
256         29-Jan-2000     lmcdonal    115.66     Determine_date.main needs person_id
257                                                passed in.  Bug 1155064.
258         04-Feb-2000     gperry      115.67     Moved cache_data_structures
259                                                above the flags_exist call.
260                                                This sets the ovridn_thru_dt so
261                                                that override works when
262                                                derivable factors do not exist.
263                                                Fix for WWBUG 1169423.
264         11-Feb-2000     jcarpent    115.68   - Pass los_dt_to_use_rl to rule fn
265         14-Feb-2000     stee        115.69   - Added check when selecting
266                                                cobra qualified beneficiary
267                                                to ignore backed out nocopy event.
268                                                bug# 1178633.
269         18-Feb-2000     mhoyes      115.70   - Fixed bugs 4707 and 4708.
270                                                Synched up nullification
271                                                of LOS and AGE values and
272                                                UOMs.
273         22-Feb-2000     gperry      115.71     Fixed WWBUG 1118118.
274         23-Feb-00       tguy        115.72     Fixed WWBUG 1178659,1161287,1120685
275         23-Feb-00       gperry      115.73     Fixed WWBUG 1118113.
276         26-Feb-00       mhoyes      115.74   - Added p_comp_obj_tree_row parameter
277                                                to derive_rates_and_factors.
278                                              - Phased out nocopy ben_env_object for comp
279                                                object values.
280         28-Feb-00       stee        115.75   - Added p_cbr_tmprl_evt_flag
281                                                parameter.
282         28-Feb-00       tguy        115.76     Fixed WWBUG 1179545.
283         03-Mar-00       gperry      115.77     Fixed bugs caused by 115.76
284         04-Mar-00       stee        115.78     Added ptip_id to
285                                                determine_cobra_eligibility.
286                                                COBRA by plan type.
287         07-Mar-00       tguy        115.79     Fixed Inherited codes in LOS
288                                                determination
289         07-Mar-00       gperry      115.80     Fixed WWBUG 1195803.
290         09-Mar-00       gperry      115.81     Added flag bit val for
291                                                performance.
292         23-Mar-00       gperry      115.82     Added in rate derivation for
293                                                coverages and premiums.
294         24-Mar-00       gperry      115.83     Added in handling for min and
295                                                max cases where the min is null
296                                                or max is null i.e. no max or
297                                                no min flag has been set.
298                                                Fix for WWBUG 1173013.
299         31-Mar-00       gperry      115.84     Added oiplip support.
300         04-Apr-00       mmogel      115.85     Added a token to message
301                                                BEN_91340_CREATE_PTNL_LER
302         05-Apr-00       stee        115.86     COBRA: get program type
303                                                is program id is passed in.
304         06-Apr-00       lmcdonal    115.87     debugging messages.
305         06-Apr-00       gperry      115.88     Return the comp_rec and the
306                                                oiplip_rec when no derivable
307                                                factors exists. (1169423)
308         13-Apr-00       pbodla      115.89   - Bug 5093 : p_ntfn_dt populated
309                                                when the potential le is created.
310         17-Apr-00       stee        115.90   - Trigger a period of
311                                                enrollment change event
312                                                when person is disabled at the
313                                                time of the qualifying event.
314                                                wwbug(1274212).
315         03-May-00       stee        115.91   - Trigger the voluntary end
316                                                of coverage event 2 days later
317                                                if an event exist on the day
318                                                after the cobra eligibiliy end
319                                                date wwbug(1274211).
320         22-May-00       mhoyes      115.92   - Added profiling messages.
321         06-Jun-00       stee        115.93   - Trigger non-late payment event
322                                                for cobra by plan type.
323                                                Bug 5261.
324         14-Jun-00       stee        115.94   - Use the system date to Trigger
325                                                the cobra ineligible to
326                                                participate event if this
327                                                process is run ahead of time.
328                                                bug #5263.
329         20-Jun-00       stee        115.95   - Check derived factors based on
330                                                a code selected by the user.
331                                                Split cobra events into
332                                                payments and non-payment events.
333         27-Jun-00       mhoyes      115.96   - Removed nvls from c_elig_per_opt.
334                                              - Reduced sysdate references.
335                                              - Cached c_elig_per_opt for oiplips
336                                                and plan in programs.
337                                              - Cached c_elig_per for plips
338                                                and plan in programs.
339         27-Jun-00       gperry      115.97     Added age_calc_rl
340         28-Jun-00       stee        115.98     COBRA: for first payment,
341                                                check that the person paid
342                                                within 45 days i.e. the due
343                                                date is >= the date earned
344                                                (date payment made).
345         29-Jun-00       mhoyes      115.99   - Fixed numeric or value error
346                                                problem for contacts who have no
347                                                assignments.
348                                              - Added context parameters.
349         06-Jul-00       mhoyes      115.100  - Fixed null assignment id
350                                                problem from 115.99.
351         10-Jul-00       mhoyes      115.101  - p_oiplip_rec problem in
352                                                cache_data_structures.
353                                              - Passed in person context row.
354         03-Aug-00       dharris     115.102  - modified create_ptl_ler to
355                                                get the g_temp_ler_id instead of
356                                                calling the fuction
357                                                get_temporal_ler_id
358                                              - Removed get_temporal_ler_id.
359         18-Aug-00       jcarpent    115.103  - Fixed formula context to
360                                                los_dt_to_use_rl.
361                                                Tar 1052406.996.
362         19-Aug-00       jcarpent    115.104  - 1385506. (same as above bug)
363                                                but ptip level was not working.
364                                                added cursor to run_rule.
365         05-Sep-00       rchase      115.105  - Included person_id as an input
366                                                to formual calls.  This resolves
367                                                issues when processing dependents
368                                                without assignment_ids. 1396949.
369         14-SEP-00       gperry      115.106    Fixed bug 1237211 where combo
370                                                age and los was not working.
371         14-SEP-00       gperry      115.107    Fixed comp error.
372         11-OCT-00       rchase      115.108  - Added the parameter pl typ id
373                                                for context passing to underlying
374                                                formula calls.
375         06-NOV-00       rchase      115.109  - Added parameters to cvg and prem cache
376                                                calls to trigger lf_evts.
377                                                Bug 1433338 + 1350957.
378         17-jan-01       tilak       115.110    derived facor calidation changed from
379                                                < max to < max +1
380         06-Apr-01       mhoyes      115.111  - Added p_calculate_only_mode for EFC.
381         27-Aug-01       ikasire     115.113    Bug 1949361 fixes
382         05-Sep-01       ikasire     115.114    Bug 1927010 Fixes
383                                                1. calculate_age is modified completely.
384                                                The existing process was checking
385                                                the following execution order for
386                                                derived factors in the rt_age_val
387                                                calculation process.
388                                                Rate->Coverage->Premium.
389                                                When we found a df at rate and even if
390                                                doesn't cross the boundary, we are then
391                                                ignoring the dfs defined at Coverage and
392                                                Premiums. Similary if there is one
393                                                defined at coverage level, the process
394                                                ignores the dfs defined at premium level.
395                                                -- This is now fixed.
396                                                2. age determination Code AFDCM.
397                                                We were adding a month for the derived date
398                                                in certain cases. Now that condition has
399                                                been removed as it is not correct.
400                                                3.We need to fix other procedures also,
401                                                see bug for more details.
402         10-Sep-01       ikasire     115.115    Bug 1977901 fixing the process as noted in
403                                                115.114 modifications for the following
404                                                derived factors.
405                                                1. Length of Service
406                                                2. Compensation Level
407                                                3. Combined age and los
408                                                4. Percent Full time
409                                                5. Hours Worked
410                                                Added the following new private procedures
411                                                comp_level_min_max, percent_fulltime_min_max and
412                                                hours_worked_min_max
413         13-Sep-01       ikasire     115.116    Bug 1977901 to avoid getting the salary from
414                                                the future records chages are made to the
415                                                cursor in procedure - get_persons_salary
416         18-Sep-01       ikasire     115.117    Bug 1977901 fixed the percent full time parttime
417         09-Oct-01       kmahendr    115.118    Bug#2034617 - wrong assignment value fixed at line
418                                                p_comp_rec.rt_age_uom - l_rate_prem_rec.age_uom
419         17-Nov-01       ikasire     115.119    Bug2101937 fixed the calls to coverage
420                                                and premium routines in calculate_age
421                                                procedures.
422         03-Dec-2001     ikasire     115.120    Bug 2101937 changed the group function min to max
423                                                in the four cursors of get_salary_date function,
424                                                as we always want only the record changed recently.
425                                                Also added ppp.change_date <= p_effective_date
426                                                to avoid getting the future dated salary rows.
427         06-dec-01      tjesumic     115.121     Salary calcualtion date determination changed ,
428                                                 bug 2124453, first look for date of code
429                                                 then for join date  then effective date
430         07-dec-01      tjesumic     115.122     dbdrv fixed
431         12-dec-01      tjesumic     115.123     changed the condition to ppp.approved='Y'
432                                                 in cursor c1 to fetch approved salary
433         16-dec-01     tjesumic      115.124     cwb changes
434         20-dec-01      ikasire      115.125     Bug 2145966 formula type hours worked not
435                                                 triggering temporal life event
436                                                 added code for rule in calculate_hours_worked
437         09-jan-02     tjesumic      115.126     bug 2169319 Salary calcualtion date determination changed
438         30-jan-02     tjesumic      115.127     bug 2180602 new procedure added to set the tax_unit_id
439                                                 context before calling get_value
440         01-feb-02     tjesumic      115.128     dbdrv fixed
441         14-Mar-02     pabodla       115.129     UTF8 Changes Bug 2254683
442         03-Jun-02     pabodla       115.130     Bug 2367556 : Changed STANDARD.bitand to just bitand
443         08-Jun-02     pabodla       115.131     Do not select the contingent worker
444                                                 assignment when assignment data is
445                                                 fetched.
446         19-Jun-02     ikasire       115.132     In call to to comp_level_min_max for Coverage
447                                                 l_rate_result was passed instead of
448                                                 passing l_rate_cvg_result
449                                                 which results in passing null to new_val
450         08-Oct-02     kmahendr      115.133     Bug#2613307-added codes in calculate_los proc.
451         18-Oct-02     kmahendr      115.134     Added to codes in other calculate factors
452         22-Oct-02     ikasire       115.135     Bug 2502763 Changes to get_salary_date function
453                                                 to compute with right boundaries.
454                                                 Added parameter to comp_level_min_max.
455                                                 Removed the calls to hr_ and
456                                                 using the call to
457                                                  BEN_DERIVE_FACTORS.determine_compensation to
458                                                 determine compensation.
459 
460         31-Mar-02     pbodla/       115.138     Bug 2881136 Pass formula id in
461                       ikasire                   min_max_breach routine. Also
462                                                 pass correct rule id while
463                                                 calling min_max_breach.
464         14-Apr-03     kmahendra     115.139     Bug#2507053 - the condition to check min_max breach
465                                                 for only Person is removed in age_calculation.
466         08-may-2003   nhunur        115.40      Bug - 2946985 passed the oipl_id retrieved from the oiplip record
467                                                 structure to ben_derive_factors.determine_compensation call.
468         01-jul-03     pabodla       115.141    Grade/Step Added code, variables
469                                                to support grade/step life event
470                                                triggering.
471         28-aug-03      rpillay       115.142   Bug 3097501 - Cobra - Changed
472                                                cursors getting payment and
473                                                amount due to sum up values
474                                                in determine_cobra_payments
475         02-sep-03      rpillay       115.143   Bug 3097501- changed l_pymt_amt
476                                                to data type number in
477                                                determine_cobra_payments
478         03-sep-03      rpillay       115.144   Bug 3125085 - check if all dues
479                                                upto previous month have been paid
480         25-Sep-03      rpillay       115.145   Bug 3097501 - Changes to make
481                                                NOLP work for all payrolls
482         03-Oct-03      ikasire       115.146   Bug 3174453 we need to pass pgm/pl/oipl
483                                                to ben_derive_factors.determine_compensation
484         13-Oct-03      rpillay       115.147   Bug 3097501 - Changes to handle FSA rates
485                                                and rounding issues
486         15-Oct-03      rpillay       115.148   Bug 3097501 - Changes to handle enrollment
487                                                and rate changes
488         22-Oct-03      rpillay       115.149   Bug 3097501 - Added p_element_entry_value_id
489                                                in call to get_amount_due
490         29-Oct-03      rpillay       115.150   Bug 3097501 - Changes to
491                                                determine_cobra_payments to not
492                                                check for payments not yet due
493         04-Nov-03      rpillay       115.151   Bug 3235738 - Undo changes made
494                                                for Bug 3097501 for PF.G
495         11-Nov-03      ikasire       115.152   Using filter g_no_ptnl_ler_id for
496                                                not to trigger potentials as part of
497                                                Unrestricted U,W,M,I,P,A BUG 3243960
498         11-Nov-03      rpillay       115.153   Added back changes for Bug 3097501
499                                                (from v115.150)
500         13-Nov-03      rpillay       115.154   Bug 3097501 - Changes for insignificant
501                                                underpayments
502         01-Dec-03      rpillay       115.155   Bug 3097501 -Changed DFF context
503                                                to 'BENEFIT UNDERPAY' in cursor
504                                                c_allwd_underpymt
505         01-Dec-03      kmahendr      115.156   Bug#3274130 - added date condition to
506                                                cursor c_per_spouse.
507         02-Dec-03      ikasire       115.157   Bug 3291639 temporal not detected for
508                                                combined LOS and Age derived factor
509         05-Dec-03      ikasire       115.158   Bug 3275501 New Code introduced to supress
510                                                firing of temporals - IGNRALL
511         19-Jan-04      rpillay       115.159   Bug 3097501 - Set LE Ocrd Date to COBRA
512                                                Due Date when triggering NOLP for first
513                                                payment
514         17-Dec-03   vvprabhu         115.32    Added the assignment for g_debug at the start
515                                                of each public procedure
516         05-Jan-04      ikasire       115.161   Bug 3275501 Added new Code IGNRTHIS
517                                                Never to detect a potential for
518                                                potential life event
519         11-mar-04      nhunur        115.162   added business_group_id clause for c_get_gsp_ler
520         09-apr-04      ikasire       115.163   fonm changes
521         16-apr-04      ikasire       115.164   more fonm changes
522         05-Aug-04      tjesumic      115.165   fonm changes
523         16-Aug-04      tjesumic      115.167   fonm changes
524         27-Sep-04      tjesumic      115.168   new param p_cvrd_today added in chk_enrld_or_cvrd
525         12-Oct04       nhunur        115.169   pl_id needs to be passed as context for derived factor rules
526                                                based elpros set at plip,oipl levels. Bug - 3944795
527         21-Oct-04       bmanyam     115.170    Bug: 3962514, In los_calculation
528                                                for coverages l_rate_cvg_result is
529                                                passed to min_max_breach() as parameter
530                                                [ previously l_rate_result was
531                                                  passed, as a result temporal was not getting deducted ].
532         26-oct-04       pbodla      115.171    Merging the code from version
533                                                115.161.11510.5. As pkh have the function
534                                                get_latest_paa_id
535                        mmudigon                Bug 3818453. Added funcion
536                                                get_latest_paa_id()
537         27-oct-04      nhunur       115.173    moved get_latest_paa_id() to the top.
538         07-apr-05      nhunur       115.174    apply fnd_number on what FF returns in run_rule.
539         24-May-2004    bmanyam      115.175    BUG: 4380180. IF l_lf_evt_ocrd_dt IS NULL,
540                                                avoid determining the date
541         08-Jun-05      kmahendr     115.176    Bug#4393676 - nvl added to old value in
542                                                hoursworked min/max breach
543         12-Dec-05      stee         115.177    Bug#4338471 - COBRA: get the most recent
544                                                enrollment period when evaluating
545                                                loss of eligibility event.
546        28-Mar-06       kmahendr     115.178    Bug#5044005 - recompute lf_evt_ocr_dt
547                                                if the code is AFDECY
548        24-Apr-06       abparekh     115.179    No changes - ver same as 178
549        17-Jul-06       abparekh     115.180    Bug 5392019 : For LOS Date to use codes like 'Inherited%'
550                                                              use benefits assignment
551        25-Aug-06         swjain     115.181    Bug 5478918 : Added function skip_min_max_le_calc and called
552                                                it from different calculate procedures. If true, then all the min
553 					       max calculations and LE creation would be skipped.
554        09-Jan-07         stee       115.182    Bug 5731828: If date determination
555                                                code is 'End of Calendar Year'(ALDECLY').
556                                                Trigger the event as of January 1.
557        28-Apr-09         stee       115.183    ARRA COBRA changes.
558 */
559 --------------------------------------------------------------------------------
560 --
561 --
562   g_package     VARCHAR2(80)             := 'ben_derive_part_and_rate_facts';
563   g_debug  boolean := hr_utility.debug_enabled;
564   g_rec         benutils.g_batch_ler_rec;
565   g_lf_evt_exists         boolean;
566   --
567   --FONM
568   g_fonm_cvg_strt_dt DATE ;
569   --END FONM
570   --
571   -- Returns the latest assignment_action_id
572   -- Set tax_unit_id context before calling this function
573   --
574   function get_latest_paa_id
575   (p_person_id           in     number
576   ,p_business_group_id   in     number
577   ,p_effective_date      in     date
578   ) return number
579   is
580     --
581     l_package              varchar2(80)   := g_package||'.get_latest_paa_id';
582     l_assignment_action_id number;
583     l_tax_unit_id          number;
584     --
585     cursor c_paa is
586     select paa.assignment_action_id
587       from pay_assignment_actions     paa,
588            per_all_assignments_f      paf,
589            pay_payroll_actions        ppa,
590            pay_action_classifications pac
591      where paf.person_id     = p_person_id
592        and paa.assignment_id = paf.assignment_id
593        and paa.tax_unit_id   = l_tax_unit_id
594        and paa.payroll_action_id = ppa.payroll_action_id
595        and ppa.action_type = pac.action_type
596        and pac.classification_name = 'SEQUENCED'
597        and ppa.effective_date between paf.effective_start_date
598                                   and paf.effective_end_date
599        and ppa.effective_date <= p_effective_date
600        and ((nvl(paa.run_type_id, ppa.run_type_id) is null
601        and  paa.source_action_id is null)
602         or (nvl(paa.run_type_id, ppa.run_type_id) is not null
603        and paa.source_action_id is not null )
604        or (ppa.action_type = 'V' and ppa.run_type_id is null
605             and paa.run_type_id is not null
606             and paa.source_action_id is null))
607        order by ppa.effective_date desc,paa.action_sequence desc;
608 
609   begin
610     --
611     if g_debug then
612        hr_utility.set_location('Entering ' || l_package,10);
613     end if;
614 
615     l_tax_unit_id := pay_balance_pkg.get_context ('TAX_UNIT_ID');
616 
617     open c_paa ;
618     fetch c_paa into  l_assignment_action_id ;
619     close c_paa ;
620 
621     if g_debug then
622        hr_utility.set_location('paa id ' || l_assignment_action_id,10);
623        hr_utility.set_location('Leaving ' || l_package,10);
624     end if;
625 
626     return l_assignment_action_id;
627 
628   end get_latest_paa_id;
629 
630 --
631   /* Bug 5478918
632    To check if all the min max breach conditions can be skipped */
633 FUNCTION skip_min_max_le_calc (p_ler_id              IN     NUMBER default null
634                               ,p_business_group_id   IN     NUMBER
635                               ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
636                               ,p_effective_date      IN     DATE)
637 RETURN BOOLEAN is
638     --
639     CURSOR c1 IS
640       SELECT   ler.name,
641                ler.ptnl_ler_trtmt_cd
642       FROM     ben_ler_f ler
643       WHERE    ler.ler_id = p_ler_id
644       AND      ler.business_group_id = p_business_group_id
645       AND      p_effective_date BETWEEN ler.effective_start_date
646                AND ler.effective_end_date;
647     l_ler_name              VARCHAR2(240);
648     l_ptnl_ler_trtmt_cd     VARCHAR2(30);
649     l_package               VARCHAR2(80)        := g_package || '.skip_min_max_le_calc';
650 --
651 BEGIN
652 --
653     if g_debug then
654       hr_utility.set_location('Entering ' || l_package,10);
655     end if;
656     hr_utility.set_location('p_ptnl_ler_trtmt_cd '||p_ptnl_ler_trtmt_cd , 99);
657     hr_utility.set_location('p_ler_id '||p_ler_id ,99) ;
658     hr_utility.set_location('p_effective_date '||p_effective_date ,99);
659     hr_utility.set_location('p_business_group_id '||p_business_group_id ,99);
660     --
661     -- Test to make sure we are only creating life events of a
662     -- certain type. This is specifically for temporal mode.
663     -- Dont trigger Potential if called from Unrestricted U,W,M,I,P,A
664     --
665     IF (NVL(ben_derive_part_and_rate_facts.g_temp_ler_id,p_ler_id) <> p_ler_id ) OR
666        (NVL(g_pgm_typ_cd, 'KKKK') = 'GSP' and
667         (NVL(ben_derive_part_and_rate_facts.g_temp_ler_id,g_gsp_ler_id) <> g_gsp_ler_id )) OR
668         (NVL(ben_derive_part_and_rate_facts.g_no_ptnl_ler_id,p_ler_id) <> p_ler_id )
669     THEN
670       --
671       hr_utility.set_location('Dont trigger Potential if called from Unrestricted U,W,M,I,P,A.',11);
672       RETURN TRUE;
673       --
674     END IF;
675     --
676 
677     IF(NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
678      --
679       hr_utility.set_location('Life Event Treatment code set to IGNR.',11);
680       RETURN TRUE;
681       --
682     END IF;
683 
684    if(p_ler_id is not null) then
685     --
686     OPEN c1;
687     FETCH c1 INTO l_ler_name,l_ptnl_ler_trtmt_cd ;
688     CLOSE c1;
689     --
690     IF (NVL(l_ptnl_ler_trtmt_cd ,'-1') in ('IGNRTHIS','IGNRALL')) THEN
691      --
692       hr_utility.set_location('Life Event Treatment code for '|| l_ler_name ||' set to IGNRTHIS/IGNRALL.',11);
693       RETURN TRUE;
694       --
695     END IF;
696     --
697    end if;
698    --
699     if g_debug then
700       hr_utility.set_location('Leaving ' || l_package,10);
701     end if;
702     --
703     RETURN FALSE;
704     --
705 END skip_min_max_le_calc;
706 /* End Bug 5478918 */
707 --
708 
709   PROCEDURE run_rule(
710     p_formula_id        IN     NUMBER
711    --
712    ,p_empasg_row        IN     per_all_assignments_f%ROWTYPE
713    ,p_benasg_row        IN     per_all_assignments_f%ROWTYPE
714    ,p_pil_row           IN     ben_per_in_ler%ROWTYPE
715    --
716    ,p_curroipl_row      IN     ben_cobj_cache.g_oipl_inst_row
717    ,p_curroiplip_row    IN     ben_cobj_cache.g_oiplip_inst_row
718    --
719    ,p_rule_type         IN     VARCHAR2 DEFAULT 'NUMBER'
720    ,p_effective_date    IN     DATE
721    ,p_lf_evt_ocrd_dt    IN     DATE
722    ,p_business_group_id IN     NUMBER
723    ,p_person_id         IN     NUMBER
724    ,p_pgm_id            IN     NUMBER
725    ,p_pl_id             IN     NUMBER
726    ,p_oipl_id           IN     NUMBER
727    ,p_plip_id           IN     NUMBER
728    ,p_ptip_id           IN     NUMBER
729    ,p_oiplip_id         IN     NUMBER
730    ,p_ret_date          OUT NOCOPY    DATE
731    ,p_ret_val           OUT NOCOPY    NUMBER) IS
732     --
733     l_package           VARCHAR2(80)               := g_package || '.run_rule';
734     l_result            NUMBER;
735     l_outputs           ff_exec.outputs_t;
736     l_loc_rec           hr_locations_all%ROWTYPE;
737     l_ass_rec           per_all_assignments_f%ROWTYPE;
738     l_pl_rec            ben_pl_f%ROWTYPE;
739     l_oipl_rec          ben_oipl_f%ROWTYPE;
740     l_oiplip_rec        ben_cobj_cache.g_oiplip_inst_row;
741     l_effective_date   date ;
742     l_jurisdiction_code VARCHAR2(30);
743     cursor c_ptip(p_effective_date date) is
744       select pl_typ_id
745       from ben_ptip_f
746       where ptip_id=p_ptip_id and
747             business_group_id=p_business_group_id and
748             p_effective_date between
749               effective_start_date and effective_end_date;
750     cursor c_plip(p_effective_date date) is
751       select pl.pl_typ_id , pl.pl_id
752       from ben_plip_f plip,
753            ben_pl_f pl
754       where plip.plip_id=p_plip_id and
755             plip.business_group_id=p_business_group_id and
756             p_effective_date between
757               plip.effective_start_date and plip.effective_end_date
758             and pl.pl_id = plip.pl_id and
759             pl.business_group_id=p_business_group_id and
760             p_effective_date between
761               pl.effective_start_date and pl.effective_end_date;
762     cursor c_oipl(p_effective_date date) is
763       select pl.pl_typ_id , pl.pl_id
764       from ben_oipl_f oipl,
765            ben_pl_f pl
766       where oipl.oipl_id=p_oipl_id and
767             oipl.business_group_id=p_business_group_id and
768             p_effective_date between
769               oipl.effective_start_date and oipl.effective_end_date
770             and pl.pl_id = oipl.pl_id and
771             pl.business_group_id=p_business_group_id and
772             p_effective_date between
773               pl.effective_start_date and pl.effective_end_date;
774     cursor c_oiplip(p_effective_date date) is
775       select pl.pl_typ_id , pl.pl_id
776       from ben_oiplip_f oiplip,
777            ben_oipl_f oipl,
778            ben_pl_f pl
779       where oiplip.oiplip_id=p_oiplip_id and
780             oiplip.business_group_id=p_business_group_id and
781             p_effective_date between
782               oiplip.effective_start_date and oiplip.effective_end_date
783             and oipl.oipl_id = oiplip.oipl_id and
784             oipl.business_group_id=p_business_group_id and
785             p_effective_date between
786               oipl.effective_start_date and oipl.effective_end_date
787             and pl.pl_id = oipl.pl_id and
788             pl.business_group_id=p_business_group_id and
789             p_effective_date between
790               pl.effective_start_date and pl.effective_end_date;
791     cursor c_pl(p_effective_date date) is
792       select pl_typ_id
793       from ben_pl_f
794       where pl_id=p_pl_id and
795             business_group_id=p_business_group_id and
796             p_effective_date between
797               effective_start_date and effective_end_date;
798   --
799   BEGIN
800     --
801    if g_debug then
802       hr_utility.set_location('Entering ' || l_package,10);
803    end if;
804 
805    l_effective_date  := nvl(g_fonm_cvg_strt_dt , p_effective_date );
806     --
807     IF p_pl_id IS NOT NULL THEN
808       --
809       ben_comp_object.get_object(p_rec=> l_pl_rec
810        ,p_pl_id => p_pl_id);
811       if l_pl_rec.pl_typ_id is null then
812         open c_pl(l_effective_date);
813         fetch c_pl into l_pl_rec.pl_typ_id;
814         close c_pl;
815       end if;
816     elsif p_ptip_id is not null then
817       open c_ptip(l_effective_date);
818       fetch c_ptip into l_pl_rec.pl_typ_id;
819       close c_ptip;
820     elsif p_plip_id is not null then
821       open c_plip(l_effective_date);
822       fetch c_plip into l_pl_rec.pl_typ_id, l_pl_rec.pl_id; -- 3944795
823       close c_plip;
824     elsif p_oipl_id is not null then
825       open c_oipl(l_effective_date);
826       fetch c_oipl into l_pl_rec.pl_typ_id , l_pl_rec.pl_id;
827       close c_oipl;
828     elsif p_oiplip_id is not null then
829       open c_oiplip(l_effective_date);
830       fetch c_oiplip into l_pl_rec.pl_typ_id , l_pl_rec.pl_id;
831       close c_oiplip;
832     END IF;
833       hr_utility.set_location(' pl_id ' || l_pl_rec.pl_id ,10);
834       hr_utility.set_location(' pl_typ_id ' || l_pl_rec.pl_typ_id ,10);
835     --
836     -- Call formula initialise routine
837     --
838     l_ass_rec  := p_empasg_row;
839     --
840     IF l_ass_rec.assignment_id IS NULL THEN
841       --
842       l_ass_rec  := p_benasg_row;
843     --
844     END IF;
845     --
846     IF l_ass_rec.location_id IS NOT NULL THEN
847       --
848       ben_location_object.get_object(p_location_id=> l_ass_rec.location_id
849        ,p_rec         => l_loc_rec);
850       --
851     --Bug 1949361 fixes
852 /*
853       IF l_loc_rec.region_2 IS NOT NULL THEN
854         --
855         l_jurisdiction_code  :=
856           pay_mag_utils.lookup_jurisdiction_code(p_state=> l_loc_rec.region_2);
857       --
858       END IF;
859 */
860     --
861     END IF;
862     --
863     l_outputs  :=
864       benutils.formula(p_formula_id=> p_formula_id
865        ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
866                                 ,p_effective_date)
867        ,p_assignment_id     => l_ass_rec.assignment_id
868        ,p_organization_id   => l_ass_rec.organization_id
869        ,p_business_group_id => p_business_group_id
870        ,p_pgm_id            => p_pgm_id
871        ,p_pl_id             => nvl(p_pl_id, l_pl_rec.pl_id )
872        ,p_pl_typ_id         => l_pl_rec.pl_typ_id
873        ,p_opt_id            => p_curroipl_row.opt_id
874        ,p_ler_id            => p_pil_row.ler_id
875        ,p_jurisdiction_code => l_jurisdiction_code
876        --RCHASE Bug#Fix - pass PERSON_ID
877        ,p_param1            => 'PERSON_ID'
878        ,p_param1_value      => to_char(nvl(p_person_id,-1))
879        ,p_param2             => 'BEN_IV_RT_STRT_DT'
880        ,p_param2_value       => fnd_date.date_to_canonical(ben_manage_life_events.g_fonm_rt_strt_dt)
881        ,p_param3             => 'BEN_IV_CVG_STRT_DT'
882        ,p_param3_value       => fnd_date.date_to_canonical(g_fonm_cvg_strt_dt)
883        );
884     --
885     IF p_rule_type = 'NUMBER' THEN
886       --
887       -- Test for type casting exceptions
888       --
889       BEGIN
890         --
891         p_ret_val   := fnd_number.canonical_to_number(l_outputs(l_outputs.FIRST).VALUE);
892         p_ret_date  := NULL;
893       --
894       EXCEPTION
895         --
896         WHEN OTHERS THEN
897           --
898           fnd_message.set_name('BEN'
899            ,'BEN_92311_FORMULA_VAL_PARAM');
900           fnd_message.set_token('PROC'
901            ,l_package);
902           fnd_message.set_token('FORMULA'
903            ,p_formula_id);
904           fnd_message.set_token('PARAMETER'
905            ,l_outputs(l_outputs.FIRST).name);
906           fnd_message.raise_error;
907       --
908       END;
909     --
910     ELSIF p_rule_type = 'DATE' THEN
911       --
912       -- Test for type casting exceptions
913       --
914       BEGIN
915         --
916         p_ret_date  :=
917                  fnd_date.canonical_to_date(l_outputs(l_outputs.FIRST).VALUE);
918         p_ret_val   := NULL;
919       --
920       EXCEPTION
921         --
922         WHEN OTHERS THEN
923           --
924           fnd_message.set_name('BEN'
925            ,'BEN_92311_FORMULA_VAL_PARAM');
926           fnd_message.set_token('PROC'
927            ,l_package);
928           fnd_message.set_token('FORMULA'
929            ,p_formula_id);
930           fnd_message.set_token('PARAMETER'
931            ,l_outputs(l_outputs.FIRST).name);
932           fnd_message.raise_error;
933       --
934       END;
935     --
936     ELSE
937       --
938        if g_debug then
939          hr_utility.set_location('INV RULE TYPE PASSED: '||p_rule_type||' '||l_package,99);
940        end if;
941     --
942     END IF;
943     --
944    -- hr_utility.set_location('Leaving ' || l_package,99);
945   --
946   END run_rule;
947 --
948 -- This procedure has to be called first in order to initialise the data
949 -- structures that the code requires.
950 --
951   PROCEDURE cache_data_structures(
952     p_comp_obj_tree_row IN OUT NOCOPY ben_manage_life_events.g_cache_proc_objects_rec
953    ,p_empasg_row        IN OUT NOCOPY per_all_assignments_f%ROWTYPE
954    ,p_benasg_row        IN OUT NOCOPY per_all_assignments_f%ROWTYPE
955    ,p_pil_row           IN OUT NOCOPY ben_per_in_ler%ROWTYPE
956    ,p_business_group_id IN            NUMBER
957    ,p_effective_date    IN            DATE
958    ,p_person_id         IN            NUMBER
959    ,p_pgm_id            IN            NUMBER
960    ,p_pl_id             IN            NUMBER
961    ,p_oipl_id           IN            NUMBER
962    ,p_plip_id           IN            NUMBER
963    ,p_ptip_id           IN            NUMBER
964    ,p_comp_rec          IN OUT NOCOPY g_cache_structure
965    ,p_oiplip_rec        IN OUT NOCOPY g_cache_structure) IS
966     --
967     l_package    VARCHAR2(80)         := g_package || '.cache_data_structures';
968     --
969     l_comp_rec   g_cache_structure;
970     l_oiplip_rec g_cache_structure;
971     --
972     l_pl_id      NUMBER;
973     l_opt_id     NUMBER;
974     l_oipl_rec   ben_oipl_f%ROWTYPE;
975     l_epo_row    ben_derive_part_and_rate_facts.g_cache_structure;
976     --
977     -- Cursor to get eligible option details
978     --
979     CURSOR c_elig_per_opt(
980       c_effective_date IN DATE
981      ,c_person_id      IN NUMBER
982      ,c_pgm_id         IN NUMBER
983      ,c_pl_id          IN NUMBER
984      ,c_plip_id        IN NUMBER
985      ,c_opt_id         IN NUMBER) IS
986       SELECT   epo.los_val
987               ,epo.age_val
988               ,epo.comp_ref_amt
989               ,epo.hrs_wkd_val
990               ,epo.pct_fl_tm_val
991               ,epo.cmbn_age_n_los_val
992               ,epo.age_uom
993               ,epo.los_uom
994               ,epo.comp_ref_uom
995               ,epo.hrs_wkd_bndry_perd_cd
996               ,epo.frz_los_flag
997               ,epo.frz_age_flag
998               ,epo.frz_hrs_wkd_flag
999               ,epo.frz_cmp_lvl_flag
1000               ,epo.frz_pct_fl_tm_flag
1001               ,epo.frz_comb_age_and_los_flag
1002               ,epo.rt_los_val
1003               ,epo.rt_age_val
1004               ,epo.rt_comp_ref_amt
1005               ,epo.rt_hrs_wkd_val
1006               ,epo.rt_pct_fl_tm_val
1007               ,epo.rt_cmbn_age_n_los_val
1008               ,epo.rt_age_uom
1009               ,epo.rt_los_uom
1010               ,epo.rt_comp_ref_uom
1011               ,epo.rt_hrs_wkd_bndry_perd_cd
1012               ,epo.rt_frz_los_flag
1013               ,epo.rt_frz_age_flag
1014               ,epo.rt_frz_hrs_wkd_flag
1015               ,epo.rt_frz_cmp_lvl_flag
1016               ,epo.rt_frz_pct_fl_tm_flag
1017               ,epo.rt_frz_comb_age_and_los_flag
1018               ,epo.ovrid_svc_dt
1019               ,epo.prtn_ovridn_flag
1020               ,epo.prtn_ovridn_thru_dt
1021               ,NULL
1022               ,NULL
1023               ,NULL
1024               ,NULL
1025               ,epo.once_r_cntug_cd
1026               ,epo.elig_flag
1027               ,NULL
1028               ,NULL
1029               ,NULL
1030               ,NULL
1031               ,NULL
1032               ,NULL
1033               ,NULL
1034               ,NULL
1035               ,NULL
1036               ,NULL
1037               ,NULL
1038               ,NULL
1039               ,NULL
1040       FROM     ben_elig_per_opt_f epo, ben_elig_per_f pep, ben_per_in_ler pil
1041       WHERE    epo.elig_per_id = pep.elig_per_id
1042       AND      pep.person_id = c_person_id
1043       AND      NVL(pep.pl_id
1044                 ,-1) = c_pl_id
1045       AND      NVL(pep.plip_id
1046                 ,-1) = c_plip_id
1047       AND      NVL(pep.pgm_id
1048                 ,-1) = c_pgm_id
1049       AND      c_effective_date BETWEEN pep.effective_start_date
1050                    AND pep.effective_end_date
1051       AND      epo.opt_id = c_opt_id
1052       AND      c_effective_date BETWEEN epo.effective_start_date
1053                    AND epo.effective_end_date
1054       AND      pil.per_in_ler_id (+) = epo.per_in_ler_id
1055     --  AND      pil.business_group_id (+) = epo.business_group_id
1056       AND      (
1057                     pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
1058                  OR pil.per_in_ler_stat_cd IS NULL);
1059     --
1060     -- Cursor to get eligible person details
1061     --
1062     CURSOR c_elig_per(
1063       c_effective_date IN DATE
1064      ,c_person_id      IN NUMBER
1065      ,c_pgm_id         IN NUMBER
1066      ,c_plip_id        IN NUMBER
1067      ,c_pl_id          IN NUMBER) IS
1068       SELECT   pep.los_val
1069               ,pep.age_val
1070               ,pep.comp_ref_amt
1071               ,pep.hrs_wkd_val
1072               ,pep.pct_fl_tm_val
1073               ,pep.cmbn_age_n_los_val
1074               ,pep.age_uom
1075               ,pep.los_uom
1076               ,pep.comp_ref_uom
1077               ,pep.hrs_wkd_bndry_perd_cd
1078               ,pep.frz_los_flag
1079               ,pep.frz_age_flag
1080               ,pep.frz_hrs_wkd_flag
1081               ,pep.frz_cmp_lvl_flag
1082               ,pep.frz_pct_fl_tm_flag
1083               ,pep.frz_comb_age_and_los_flag
1084               ,pep.rt_los_val
1085               ,pep.rt_age_val
1086               ,pep.rt_comp_ref_amt
1087               ,pep.rt_hrs_wkd_val
1088               ,pep.rt_pct_fl_tm_val
1089               ,pep.rt_cmbn_age_n_los_val
1090               ,pep.rt_age_uom
1091               ,pep.rt_los_uom
1092               ,pep.rt_comp_ref_uom
1093               ,pep.rt_hrs_wkd_bndry_perd_cd
1094               ,pep.rt_frz_los_flag
1095               ,pep.rt_frz_age_flag
1096               ,pep.rt_frz_hrs_wkd_flag
1097               ,pep.rt_frz_cmp_lvl_flag
1098               ,pep.rt_frz_pct_fl_tm_flag
1099               ,pep.rt_frz_comb_age_and_los_flag
1100               ,pep.ovrid_svc_dt
1101               ,pep.prtn_ovridn_flag
1102               ,pep.prtn_ovridn_thru_dt
1103               ,NULL
1104               ,NULL
1105               ,NULL
1106               ,NULL
1107               ,pep.once_r_cntug_cd
1108               ,pep.elig_flag
1109               ,NULL
1110               ,NULL
1111               ,NULL
1112               ,NULL
1113               ,NULL
1114               ,NULL
1115               ,NULL
1116               ,NULL
1117               ,NULL
1118               ,NULL
1119               ,NULL
1120               ,NULL
1121               ,NULL
1122       FROM     ben_elig_per_f pep, ben_per_in_ler pil
1123       WHERE    pep.person_id = c_person_id
1124       AND      NVL(pep.pl_id
1125                 ,-1) = c_pl_id
1126       AND      NVL(pep.plip_id
1127                 ,-1) = c_plip_id
1128       AND      pep.ptip_id IS NULL
1129       AND      NVL(pep.pgm_id
1130                 ,-1) = c_pgm_id
1131       AND      c_effective_date BETWEEN pep.effective_start_date
1132                    AND pep.effective_end_date
1133       AND      pil.per_in_ler_id (+) = pep.per_in_ler_id
1134      -- AND      pil.business_group_id (+) = pep.business_group_id
1135       AND      (
1136                     pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
1137                  OR pil.per_in_ler_stat_cd IS NULL);
1138   --
1139   BEGIN
1140   g_debug := hr_utility.debug_enabled;
1141   -- hr_utility.set_location('Entering ' || l_package,10);
1142     --
1143     -- This cursor caches all the elig per information that
1144     -- is used by the derivable factor functions
1145     --
1146     p_oiplip_rec  := l_oiplip_rec;
1147     --
1148     IF p_oipl_id IS NOT NULL THEN
1149       --
1150       -- Check for option in a program
1151       --
1152       IF p_comp_obj_tree_row.par_pgm_id IS NOT NULL THEN
1153         --
1154         ben_pep_cache.get_pilepo_dets(p_person_id=> p_person_id
1155          ,p_business_group_id => p_business_group_id
1156          ,p_effective_date    => p_effective_date
1157          ,p_pgm_id            => p_comp_obj_tree_row.par_pgm_id
1158          ,p_pl_id             => p_comp_obj_tree_row.par_pl_id
1159          ,p_opt_id            => p_comp_obj_tree_row.par_opt_id
1160          ,p_inst_row          => p_comp_rec);
1161        -- hr_utility.set_location('Dn PILEPO ' || l_package,10);
1162       --
1163       -- Plan not in a program
1164       --
1165       ELSE
1166         --
1167         OPEN c_elig_per_opt(c_effective_date=> p_effective_date
1168          ,c_person_id      => p_person_id
1169          ,c_pgm_id         => NVL(p_comp_obj_tree_row.par_pgm_id
1170                                ,-1)
1171          ,c_pl_id          => NVL(p_comp_obj_tree_row.par_pl_id
1172                                ,-1)
1173          ,c_plip_id        => -1
1174          ,c_opt_id         => p_comp_obj_tree_row.par_opt_id);
1175         FETCH c_elig_per_opt INTO p_comp_rec;
1176         CLOSE c_elig_per_opt;
1177        -- hr_utility.set_location('Dn c_elig_per_opt ' || l_package,10);
1178       --
1179       END IF;
1180       --
1181       IF p_comp_obj_tree_row.oiplip_id IS NOT NULL THEN
1182         --
1183         ben_pep_cache.get_pilepo_dets(p_person_id=> p_person_id
1184          ,p_business_group_id => p_business_group_id
1185          ,p_effective_date    => p_effective_date
1186          ,p_pgm_id            => p_comp_obj_tree_row.par_pgm_id
1187          ,p_plip_id           => p_comp_obj_tree_row.par_plip_id
1188          ,p_opt_id            => p_comp_obj_tree_row.par_opt_id
1189          ,p_inst_row          => p_oiplip_rec);
1190        -- hr_utility.set_location('Dn OIPLIP PILEPO ' || l_package,10);
1191       --
1192       END IF;
1193     --
1194     ELSE
1195       --
1196       -- Plan in program or plip
1197       --
1198       IF p_comp_obj_tree_row.par_pgm_id IS NOT NULL THEN
1199         --
1200         ben_pep_cache.get_pilpep_dets(p_person_id=> p_person_id
1201          ,p_business_group_id => p_business_group_id
1202          ,p_effective_date    => p_effective_date
1203          ,p_pgm_id            => p_comp_obj_tree_row.par_pgm_id
1204          ,p_pl_id             => p_pl_id
1205          ,p_plip_id           => p_plip_id
1206          ,p_ptip_id           => p_ptip_id
1207          ,p_inst_row          => p_comp_rec);
1208        -- hr_utility.set_location('Dn PILPEP ' || l_package,10);
1209       --
1210       ELSE
1211         --
1212         OPEN c_elig_per(c_effective_date=> p_effective_date
1213          ,c_person_id      => p_person_id
1214          ,c_pgm_id         => NVL(p_pgm_id
1215                                ,NVL(p_comp_obj_tree_row.par_pgm_id
1216                                  ,-1))
1217          ,c_plip_id        => NVL(p_plip_id
1218                                ,-1)
1219          ,c_pl_id          => NVL(p_pl_id
1220                                ,-1));
1221         FETCH c_elig_per INTO p_comp_rec;
1222         CLOSE c_elig_per;
1223        -- hr_utility.set_location('Dn c_elig_per ' || l_package,10);
1224       --
1225       END IF;
1226     --
1227     END IF;
1228     --
1229    -- hr_utility.set_location('Leaving ' || l_package,10);
1230   END cache_data_structures;
1231 --
1232   PROCEDURE clear_down_cache IS
1233     --
1234     l_package       VARCHAR2(80)      := g_package || '.clear_down_cache';
1235     l_cache_details g_cache_structure;
1236   --
1237   BEGIN
1238     --
1239    -- hr_utility.set_location('Entering ' || l_package,10);
1240     --
1241     -- Set cache structure to null
1242     --
1243     g_cache_details  := l_cache_details;
1244     --
1245    -- hr_utility.set_location('Leaving ' || l_package,10);
1246   --
1247   END;
1248 --
1249   FUNCTION get_balance_date(
1250     p_effective_date IN DATE
1251    ,p_bnfts_bal_id   IN NUMBER
1252    ,p_person_id      IN NUMBER
1253    ,p_min            IN NUMBER
1254    ,p_max            IN NUMBER
1255    ,p_break          IN VARCHAR2)
1256     RETURN DATE IS
1257     --
1258     l_package VARCHAR2(80) := g_package || '.get_balance_date';
1259     l_salary  DATE;
1260     --
1261     -- Cursors to bring back first occurence where min or max was crossed
1262     --
1263     CURSOR c_gt_min IS
1264       SELECT   MIN(pbb.effective_start_date)
1265       FROM     ben_per_bnfts_bal_f pbb
1266       WHERE    pbb.val >= p_min
1267       AND      pbb.bnfts_bal_id = p_bnfts_bal_id
1268       AND      p_effective_date BETWEEN pbb.effective_start_date
1269                    AND pbb.effective_end_date
1270       AND      pbb.person_id = p_person_id;
1271     --
1272     CURSOR c_gt_max IS
1273       SELECT   MIN(pbb.effective_start_date)
1274       FROM     ben_per_bnfts_bal_f pbb
1275       WHERE    pbb.val > p_max
1276       AND      pbb.bnfts_bal_id = p_bnfts_bal_id
1277       AND      p_effective_date BETWEEN pbb.effective_start_date
1278                    AND pbb.effective_end_date
1279       AND      pbb.person_id = p_person_id;
1280     --
1281     CURSOR c_lt_max IS
1282       SELECT   MIN(pbb.effective_start_date)
1283       FROM     ben_per_bnfts_bal_f pbb
1284       WHERE    pbb.val <= p_max
1285       AND      pbb.bnfts_bal_id = p_bnfts_bal_id
1286       AND      p_effective_date BETWEEN pbb.effective_start_date
1287                    AND pbb.effective_end_date
1288       AND      pbb.person_id = p_person_id;
1289     --
1290     CURSOR c_lt_min IS
1291       SELECT   MIN(pbb.effective_start_date)
1292       FROM     ben_per_bnfts_bal_f pbb
1293       WHERE    pbb.val < p_min
1294       AND      pbb.bnfts_bal_id = p_bnfts_bal_id
1295       AND      p_effective_date BETWEEN pbb.effective_start_date
1296                    AND pbb.effective_end_date
1297       AND      pbb.person_id = p_person_id;
1298   --
1299   BEGIN
1300     --
1301    -- hr_utility.set_location('Entering ' || l_package,10);
1302     --
1303     IF p_break = 'GT_MIN' THEN
1304       --
1305       OPEN c_gt_min;
1306       FETCH c_gt_min INTO l_salary;
1307       CLOSE c_gt_min;
1308     --
1309     ELSIF p_break = 'GT_MAX' THEN
1310       --
1311       OPEN c_gt_max;
1312       FETCH c_gt_max INTO l_salary;
1313       CLOSE c_gt_max;
1314     --
1315     ELSIF p_break = 'LT_MAX' THEN
1316       --
1317       OPEN c_lt_max;
1318       FETCH c_lt_max INTO l_salary;
1319       CLOSE c_lt_max;
1320     --
1321     ELSIF p_break = 'LT_MIN' THEN
1322       --
1323       OPEN c_lt_min;
1324       FETCH c_lt_min INTO l_salary;
1325       CLOSE c_lt_min;
1326     --
1327     END IF;
1328     --
1329     RETURN l_salary;
1330     --
1331    -- hr_utility.set_location('Entering ' || l_package,10);
1332   --
1333   END get_balance_date;
1334 --
1335   FUNCTION get_salary_date(
1336     p_empasg_row     IN per_all_assignments_f%ROWTYPE
1337    ,p_benasg_row     IN per_all_assignments_f%ROWTYPE
1338    ,p_rec            IN ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
1339    ,p_person_id      IN NUMBER
1340    ,p_effective_date IN DATE
1341    ,p_min            IN NUMBER
1342    ,p_max            IN NUMBER
1343    ,p_break          IN VARCHAR2)
1344     RETURN DATE IS
1345     --
1346     l_package VARCHAR2(80)                  := g_package || '.get_salary_date';
1347     l_salary  DATE;
1348     l_ass_rec per_all_assignments_f%ROWTYPE;
1349     -- New
1350     l_pay_annualization_factor  number ;
1351     l_rate_flag   varchar2(200) := 'N';
1352     l_not_found boolean := false;
1353     l_primary_flag   varchar2(1):= 'Y';
1354     l_assignment_id  number := 0;
1355     l_min            number ;
1356     l_max            number ;
1357     l_input          number ;
1358     l_output         number ;
1359   --
1360   cursor c_stated_salary (v_assignment_id number,v_effective_date date) is
1361     select ppb.pay_basis,
1362            ppb.pay_annualization_factor,
1363            asg.normal_hours,
1364            asg.frequency,
1365            asg.assignment_id
1366     from   per_all_assignments_f asg,
1367            per_pay_bases ppb
1368     where  asg.assignment_type <> 'C'
1369     and    asg.assignment_id = v_assignment_id
1370     and    ppb.pay_basis_id = asg.pay_basis_id
1371     and    v_effective_date
1372            between asg.effective_start_date
1373            and     asg.effective_end_date
1374     order  by asg.assignment_id;
1375   --
1376   l_stated_salary c_stated_salary%rowtype;
1377   --
1378   cursor c_opt_typ_cd (v_effective_date date) is
1379    select opt.OPT_TYP_CD
1380    from BEN_PL_F pln, BEN_PL_TYP_f opt
1381    where opt.pl_typ_id = pln.pl_typ_id
1382    and   opt.OPT_TYP_CD = 'CWB'
1383    and   v_effective_date
1384          between pln.effective_start_date
1385          and     pln.effective_end_date
1386    and   v_effective_date
1387          between opt.effective_start_date
1388    and   opt.effective_end_date;
1389    --
1390    l_opt_typ_cd c_opt_typ_cd%rowtype;
1391  --
1392     --
1393     -- Bug 2101937 changed the min group function to max in the following four
1394     -- cursors as we always want only the record changed recently.
1395     -- Also added ppp.change_date <= p_effective_date to avoid getting the
1396     -- future dated salary rows.
1397     CURSOR c_gt_min IS
1398       SELECT   MAX(ppp.change_date)
1399       FROM     per_pay_proposals ppp, per_all_assignments_f paf
1400       WHERE    paf.assignment_id = l_ass_rec.assignment_id
1401       and      paf.assignment_type <> 'C'
1402       AND      p_effective_date BETWEEN paf.effective_start_date
1403                    AND paf.effective_end_date
1404       AND      paf.assignment_id = ppp.assignment_id
1405       AND      ppp.change_date BETWEEN paf.effective_start_date
1406                    AND paf.effective_end_date
1407       AND      ppp.proposed_salary_n >= l_output -- p_min
1408       AND      ppp.change_date <= p_effective_date ;
1409     --
1410     CURSOR c_gt_max IS
1411       SELECT   MAX(ppp.change_date)
1412       FROM     per_pay_proposals ppp, per_all_assignments_f paf
1413       WHERE    paf.assignment_id = l_ass_rec.assignment_id
1414       and      paf.assignment_type <> 'C'
1415       AND      p_effective_date BETWEEN paf.effective_start_date
1416                    AND paf.effective_end_date
1417       AND      paf.assignment_id = ppp.assignment_id
1418       AND      ppp.change_date BETWEEN paf.effective_start_date
1419                    AND paf.effective_end_date
1420       AND      ppp.proposed_salary_n > l_output -- p_max
1421       AND      ppp.change_date <= p_effective_date;
1422     --
1423     CURSOR c_lt_max IS
1424       SELECT   MAX(ppp.change_date)
1425       FROM     per_pay_proposals ppp, per_all_assignments_f paf
1426       WHERE    paf.assignment_id = l_ass_rec.assignment_id
1427       and      paf.assignment_type <> 'C'
1428       AND      p_effective_date BETWEEN paf.effective_start_date
1429                    AND paf.effective_end_date
1430       AND      paf.assignment_id = ppp.assignment_id
1431       AND      ppp.change_date BETWEEN paf.effective_start_date
1432                    AND paf.effective_end_date
1433       AND      ppp.proposed_salary_n <= l_output -- p_max
1434       AND      ppp.change_date <= p_effective_date;
1435     --
1436     CURSOR c_lt_min IS
1437       SELECT   MAX(ppp.change_date)
1438       FROM     per_pay_proposals ppp, per_all_assignments_f paf
1439       WHERE    paf.assignment_id = l_ass_rec.assignment_id
1440       and      paf.assignment_type <> 'C'
1441       AND      p_effective_date BETWEEN paf.effective_start_date
1442                    AND paf.effective_end_date
1443       AND      paf.assignment_id = ppp.assignment_id
1444       AND      ppp.change_date BETWEEN paf.effective_start_date
1445                    AND paf.effective_end_date
1446       AND      ppp.proposed_salary_n < l_output -- p_min
1447       AND      ppp.change_date <= p_effective_date;
1448   --
1449   BEGIN
1450     --
1451    -- hr_utility.set_location('Entering ' || l_package,10);
1452     --
1453     IF p_empasg_row.assignment_id IS NULL THEN
1454       --
1455       l_ass_rec  := p_benasg_row;
1456     --
1457     ELSE
1458       --
1459       l_ass_rec  := p_empasg_row;
1460     --
1461     END IF;
1462     --
1463     IF p_break = 'GT_MIN' THEN
1464       --
1465       l_input := p_min ;
1466     --
1467     ELSIF p_break = 'GT_MAX' THEN
1468       --
1469       l_input := p_max ;
1470     --
1471     ELSIF p_break = 'LT_MAX' THEN
1472       --
1473       l_input := p_max ;
1474     --
1475     ELSIF p_break = 'LT_MIN' THEN
1476       --
1477       l_input := p_min ;
1478     --
1479     END IF;
1480 
1481     open c_stated_salary (l_ass_rec.assignment_id,p_effective_date);
1482       --
1483       fetch c_stated_salary into l_stated_salary;
1484       --
1485       if c_stated_salary%NOTFOUND then
1486         --
1487         /*
1488         l_opt_typ_cd.opt_typ_cd := 'YYY';
1489         open c_opt_typ_cd(p_effective_date);
1490         fetch c_opt_typ_cd into l_opt_typ_cd;
1491         close c_opt_typ_cd;
1492         if nvl(l_opt_typ_cd.opt_typ_cd, 'YYY') ='CWB' then
1493           l_value := 0;
1494           l_salary.proposed_salary := 0;
1495         else
1496           fnd_message.set_name('BEN','BEN_91833_CURSOR_RETURN_NO_ROW');
1497           fnd_message.set_token('PACKAGE',l_proc);
1498           fnd_message.set_token('CURSOR','c_stated_salary');
1499           fnd_message.raise_error;
1500         end if;
1501         */
1502         return l_salary ;
1503       --
1504       end if;
1505       --
1506     close c_stated_salary;
1507     --
1508     if l_stated_salary.pay_basis is not null then
1509       l_pay_annualization_factor  := l_stated_salary.pay_annualization_factor;
1510     end if;
1511     if l_pay_annualization_factor is null then
1512       l_pay_annualization_factor := to_number(fnd_profile.value('BEN_HRLY_ANAL_FCTR'));
1513       if l_pay_annualization_factor is null then
1514         l_pay_annualization_factor := 2080;
1515       end if;
1516     end if;
1517     if g_debug then
1518       hr_utility.set_location('p_rec.sttd_sal_prdcty_cd :'||p_rec.sttd_sal_prdcty_cd,18);
1519     end if;
1520     --
1521     if p_rec.sttd_sal_prdcty_cd = 'PWK' then
1522       --
1523       -- l_value := l_value/52;
1524       --
1525       l_output := l_input*52 ;
1526       --  Bi-Weekly
1527       --
1528     elsif p_rec.sttd_sal_prdcty_cd = 'BWK' then
1529       --
1530       --l_value := l_value/26;
1531       l_output := l_input*26;
1532       --
1533       --  Semi-Monthly
1534       --
1535     elsif p_rec.sttd_sal_prdcty_cd = 'SMO' then
1536       --
1537       -- l_value := l_value/24;
1538       l_output := l_input*24;
1539       --
1540       --  Per Quarter
1541       --
1542     elsif p_rec.sttd_sal_prdcty_cd = 'PQU' then
1543       --
1544       --l_value := l_value/4;
1545       l_output := l_input*4;
1546       --
1547       --  Per Year
1548       --   don't really need to do this since l_value is already periodized,
1549       --   but to make it easier to read we'll go ahead and go through the
1550       --   motions.
1551       --
1552     elsif p_rec.sttd_sal_prdcty_cd = 'PYR' then
1553       --
1554       --l_value := l_value;
1555       l_output := l_input;
1556       --
1557       --  Semi-Annual
1558       --
1559     elsif p_rec.sttd_sal_prdcty_cd = 'SAN' then
1560       --
1561       -- l_value := l_value/2;
1562       l_output := l_input*2;
1563       --
1564       --  Monthly
1565       --
1566     elsif p_rec.sttd_sal_prdcty_cd = 'MO' then
1567       --
1568       --l_value := l_value/12;
1569       l_output := l_input*12;
1570       --
1571       --
1572     elsif p_rec.sttd_sal_prdcty_cd = 'PHR' then
1573        --
1574        -- l_value := l_value/l_pay_annualization_factor;
1575        l_output := l_input*l_pay_annualization_factor;
1576        --
1577     end if;
1578     --  Now take annualized salary and translate it into the appropriate
1579     --  acty ref period as defined by the plan or program
1580     if l_stated_salary.pay_basis is not null then
1581       --
1582       -- Assumption no multi assignment for annualization factor
1583             l_pay_annualization_factor  := l_stated_salary.pay_annualization_factor;
1584             -- l_value := l_stated_salary.proposed_salary * nvl(l_stated_salary.pay_annualization_factor,1);
1585             l_output:= l_input/l_pay_annualization_factor ;
1586             --
1587     elsif l_stated_salary.frequency is not null and l_stated_salary.normal_hours is not null then
1588       --
1589       if l_stated_salary.frequency = 'D' then
1590         --
1591         -- assumption is 5 days a week * 52 weeks in a year = 260 working days
1592         --
1593         --l_value := l_stated_salary.proposed_salary * (l_stated_salary.normal_hours*260) + nvl(l_value,0);
1594         l_output := l_input/(l_stated_salary.normal_hours*260);
1595         --
1596       elsif l_stated_salary.frequency = 'W' then
1597         --
1598         --l_value := l_stated_salary.proposed_salary * (l_stated_salary.normal_hours*52) + nvl(l_value,0);
1599         l_output := l_input/(l_stated_salary.normal_hours*52);
1600              --
1601       elsif l_stated_salary.frequency = 'M' then
1602         --
1603         --l_value := l_stated_salary.proposed_salary * (l_stated_salary.normal_hours*12) + nvl(l_value,0);
1604         l_output := l_input/ (l_stated_salary.normal_hours*12);
1605         --
1606       elsif l_stated_salary.frequency = 'Y' then
1607         --
1608         --l_value := l_stated_salary.proposed_salary + nvl(l_value,0);
1609         l_output := l_input ;
1610         --
1611       end if;
1612     end if;
1613     --
1614     if g_debug then
1615       hr_utility.set_location('Input Value  '||l_input ,100);
1616     end if;
1617     if g_debug then
1618       hr_utility.set_location('Output Value '||l_output,100);
1619     end if;
1620     --
1621     IF p_break = 'GT_MIN' THEN
1622       --
1623       OPEN c_gt_min;
1624       FETCH c_gt_min INTO l_salary;
1625       CLOSE c_gt_min;
1626     --
1627     ELSIF p_break = 'GT_MAX' THEN
1628       --
1629       OPEN c_gt_max;
1630       FETCH c_gt_max INTO l_salary;
1631       CLOSE c_gt_max;
1632     --
1633     ELSIF p_break = 'LT_MAX' THEN
1634       --
1635       OPEN c_lt_max;
1636       FETCH c_lt_max INTO l_salary;
1637       CLOSE c_lt_max;
1638     --
1639     ELSIF p_break = 'LT_MIN' THEN
1640       --
1641       OPEN c_lt_min;
1642       FETCH c_lt_min INTO l_salary;
1643       CLOSE c_lt_min;
1644     --
1645     END IF;
1646     --
1647     RETURN l_salary;
1648     --
1649    -- hr_utility.set_location('Entering ' || l_package,10);
1650   --
1651   END get_salary_date;
1652 --
1653   FUNCTION get_percent_date(
1654     p_empasg_row     IN per_all_assignments_f%ROWTYPE
1655    ,p_benasg_row     IN per_all_assignments_f%ROWTYPE
1656    ,p_person_id      IN NUMBER
1657    ,p_percent        IN NUMBER
1658    ,p_effective_date IN DATE
1659    ,p_min            IN NUMBER
1660    ,p_max            IN NUMBER
1661    ,p_break          IN VARCHAR2)
1662     RETURN DATE IS
1663     --
1664     l_package VARCHAR2(80)                 := g_package || '.get_percent_date';
1665     l_percent DATE;
1666     l_ass_rec per_all_assignments_f%ROWTYPE;
1667     --
1668     -- Assignment has been validated as primary already therefore no need
1669     -- to include join to per_assignments_f
1670     --
1671     CURSOR c_gt_min IS
1672       SELECT   MIN(pab.effective_start_date)
1673       FROM     per_assignment_budget_values_f pab
1674       WHERE    pab.assignment_id = l_ass_rec.assignment_id
1675       AND      pab.effective_start_date BETWEEN l_ass_rec.effective_start_date
1676                    AND l_ass_rec.effective_end_date
1677       AND      pab.unit = 'FTE'
1678       AND      pab.VALUE >= p_min;
1679     --
1680     CURSOR c_gt_max IS
1681       SELECT   MIN(pab.effective_start_date)
1682       FROM     per_assignment_budget_values_f pab
1683       WHERE    pab.assignment_id = l_ass_rec.assignment_id
1684       AND      pab.effective_start_date BETWEEN l_ass_rec.effective_start_date
1685                    AND l_ass_rec.effective_end_date
1686       AND      pab.unit = 'FTE'
1687       AND      pab.VALUE > p_max;
1688     --
1689     CURSOR c_lt_max IS
1690       SELECT   MIN(pab.effective_start_date)
1691       FROM     per_assignment_budget_values_f pab
1692       WHERE    pab.assignment_id = l_ass_rec.assignment_id
1693       AND      pab.effective_start_date BETWEEN l_ass_rec.effective_start_date
1694                    AND l_ass_rec.effective_end_date
1695       AND      pab.unit = 'FTE'
1696       AND      pab.VALUE <= p_max;
1697     --
1698     CURSOR c_lt_min IS
1699       SELECT   MIN(pab.effective_start_date)
1700       FROM     per_assignment_budget_values_f pab
1701       WHERE    pab.assignment_id = l_ass_rec.assignment_id
1702       AND      pab.effective_start_date BETWEEN l_ass_rec.effective_start_date
1703                    AND l_ass_rec.effective_end_date
1704       AND      pab.unit = 'FTE'
1705       AND      pab.VALUE < p_min;
1706   --
1707   BEGIN
1708     --
1709    -- hr_utility.set_location('Entering ' || l_package,10);
1710     --
1711     IF p_empasg_row.assignment_id IS NULL THEN
1712       --
1713       l_ass_rec  := p_benasg_row;
1714     --
1715     ELSE
1716       --
1717       l_ass_rec  := p_empasg_row;
1718     --
1719     END IF;
1720     --
1721     IF p_break = 'GT_MIN' THEN
1722       --
1723       OPEN c_gt_min;
1724       FETCH c_gt_min INTO l_percent;
1725       CLOSE c_gt_min;
1726     --
1727     ELSIF p_break = 'GT_MAX' THEN
1728       --
1729       OPEN c_gt_max;
1730       FETCH c_gt_max INTO l_percent;
1731       CLOSE c_gt_max;
1732     --
1733     ELSIF p_break = 'LT_MAX' THEN
1734       --
1735       OPEN c_lt_max;
1736       FETCH c_lt_max INTO l_percent;
1737       CLOSE c_lt_max;
1738     --
1739     ELSIF p_break = 'LT_MIN' THEN
1740       --
1741       OPEN c_lt_min;
1742       FETCH c_lt_min INTO l_percent;
1743       CLOSE c_lt_min;
1744     --
1745     END IF;
1746     --
1747     RETURN l_percent;
1748     --
1749    -- hr_utility.set_location('Leaving ' || l_package,10);
1750   --
1751   END get_percent_date;
1752 --
1753   FUNCTION get_persons_salary(
1754     p_empasg_row        IN per_all_assignments_f%ROWTYPE
1755    ,p_benasg_row        IN per_all_assignments_f%ROWTYPE
1756    ,p_person_id         IN NUMBER
1757    ,p_business_group_id IN NUMBER
1758    ,p_effective_date    IN DATE)
1759     RETURN NUMBER IS
1760     --
1761     l_package VARCHAR2(80)               := g_package || '.get_persons_salary';
1762     l_salary  NUMBER(38);
1763     l_ass_rec per_all_assignments_f%ROWTYPE;
1764     --
1765     CURSOR c1 IS
1766       SELECT   ppp.proposed_salary_n
1767       FROM     per_pay_proposals ppp, per_all_assignments_f paf
1768       WHERE    paf.assignment_id = l_ass_rec.assignment_id
1769       and      paf.assignment_type <> 'C'
1770       AND      paf.business_group_id = p_business_group_id
1771       AND      p_effective_date BETWEEN paf.effective_start_date
1772                    AND paf.effective_end_date
1773       AND      paf.assignment_id = ppp.assignment_id
1774       AND      paf.business_group_id = ppp.business_group_id
1775       AND      ppp.change_date BETWEEN paf.effective_start_date
1776                    AND paf.effective_end_date
1777       --AND      ppp.approved IN ('Y', 'A', 'P')
1778       --approved is check box accpet Y/N
1779       and nvl(ppp.approved,'N')  = 'Y'
1780      -- Bug 1977901  added the following condition
1781      -- otherwise we get the future salaries also which we should not do
1782       AND      ppp.change_date <= p_effective_date
1783        ORDER BY ppp.change_date DESC;
1784   --
1785   BEGIN
1786     --
1787     if g_debug then
1788       hr_utility.set_location('Leaving ' || l_package,10);
1789     end if;
1790     --
1791     IF p_empasg_row.assignment_id IS NULL THEN
1792       --
1793       l_ass_rec  := p_benasg_row;
1794     --
1795     ELSE
1796       --
1797       l_ass_rec  := p_empasg_row;
1798     --
1799     END IF;
1800     --
1801     -- Get persons salary and return value
1802     --
1803     OPEN c1;
1804     --
1805     FETCH c1 INTO l_salary;
1806     --
1807     -- note we don't care if we can't find a salary we just return a null
1808     --
1809     if g_debug then
1810       hr_utility.set_location('Salary is ' || l_salary,10);
1811     end if;
1812     --
1813     CLOSE c1;
1814     --
1815     RETURN l_salary;
1816   --
1817   END get_persons_salary;
1818 --
1819   PROCEDURE create_ptl_ler
1820     (p_calculate_only_mode in     boolean default false
1821     ,p_ler_id              IN     NUMBER
1822     ,p_lf_evt_ocrd_dt      IN     DATE
1823     ,p_person_id           IN     NUMBER
1824     ,p_business_group_id   IN     NUMBER
1825     ,p_effective_date      IN     DATE
1826     )
1827   IS
1828     --
1829     CURSOR c1 IS
1830       SELECT   ler.name,
1831                ler.ptnl_ler_trtmt_cd
1832       FROM     ben_ler_f ler
1833       WHERE    ler.ler_id = p_ler_id
1834       AND      ler.business_group_id = p_business_group_id
1835       AND      p_effective_date BETWEEN ler.effective_start_date
1836                    AND ler.effective_end_date;
1837     --
1838     -- Create local variables required for API call
1839     --
1840     l_ptnl_ler_for_per_id   ben_ptnl_ler_for_per.ptnl_ler_for_per_id%TYPE;
1841     l_object_version_number ben_ptnl_ler_for_per.object_version_number%TYPE;
1842     --
1843     l_package               VARCHAR2(80)     := g_package || '.create_ptl_ler';
1844     --
1845     l_ler_name              VARCHAR2(240);
1846     l_ptnl_ler_trtmt_cd     VARCHAR2(30);
1847     l_ler_id                number;
1848     l_mnl_dt                DATE;
1849     l_dtctd_dt              DATE;
1850     l_procd_dt              DATE;
1851     l_unprocd_dt            DATE;
1852     l_voidd_dt              DATE;
1853     --
1854     l_sysdate               DATE;
1855   --
1856   BEGIN
1857     --
1858     -- Set sysdate to local
1859     --
1860     l_sysdate                 := SYSDATE;
1861     --
1862     hr_utility.set_location('Entering ' || l_package,10);
1863     --
1864     -- Quick test to make sure we are only creating life events of a
1865     -- certain type. This is specifically for temporal mode.
1866     --
1867     -- GRADE/STEP : Added or condition for GSP
1868     -- Dont trigget Potential if called from Unrestricted U,W,M,I,P,A
1869     --
1870     IF (NVL(ben_derive_part_and_rate_facts.g_temp_ler_id,p_ler_id) <> p_ler_id ) OR
1871        (NVL(g_pgm_typ_cd, 'KKKK') = 'GSP' and
1872         (NVL(ben_derive_part_and_rate_facts.g_temp_ler_id,g_gsp_ler_id) <> g_gsp_ler_id )) OR
1873         (NVL(ben_derive_part_and_rate_facts.g_no_ptnl_ler_id,p_ler_id) <> p_ler_id )
1874     THEN
1875       --
1876       -- We are creating life events of this type.
1877       --
1878     hr_utility.set_location('Entering ' || l_package,11);
1879       RETURN;
1880     --
1881     END IF;
1882     --
1883     -- Added if condition for GSP.
1884     --
1885     if g_pgm_typ_cd = 'GSP' then
1886        --
1887     hr_utility.set_location('Entering GSP ' || l_package,11);
1888        l_ler_id   := g_gsp_ler_id;
1889        l_ler_name := g_gsp_ler_name;
1890        --
1891     else
1892        --
1893     hr_utility.set_location('Entering Normal ' || l_package,11);
1894        l_ler_id   := p_ler_id;
1895        OPEN c1;
1896        FETCH c1 INTO l_ler_name,l_ptnl_ler_trtmt_cd ;
1897        CLOSE c1;
1898        --
1899       -- BUG 3275501 fixes
1900       --
1901       IF NVL(l_ptnl_ler_trtmt_cd ,'-1') = 'IGNRTHIS'  THEN
1902         --
1903         if g_debug then
1904           hr_utility.set_location('IGNRTHIS l_ptnl_ler_trtmt_cd '||l_ptnl_ler_trtmt_cd, 80);
1905         end if;
1906         --
1907         -- We are not creating life events or for IGNRTHIS cases
1908         --
1909         RETURN;
1910         --
1911       END IF;
1912       --
1913     end if;
1914     --
1915     -- We need to create a life event for the min max breach that
1916     -- has occured.
1917     --
1918     fnd_message.set_name('BEN'
1919      ,'BEN_91340_CREATE_PTNL_LER');
1920     fnd_message.set_token('LF_EVT'
1921      ,l_ler_name);
1922     benutils.write(p_text=> fnd_message.get);
1923     --
1924     if not p_calculate_only_mode then
1925       --
1926       ben_ptnl_ler_for_per_api.create_ptnl_ler_for_per_perf(p_validate=> FALSE
1927        ,p_ptnl_ler_for_per_id      => l_ptnl_ler_for_per_id
1928        ,p_lf_evt_ocrd_dt           => p_lf_evt_ocrd_dt
1929        ,p_ptnl_ler_for_per_stat_cd => 'DTCTD'
1930        ,p_ler_id                   => l_ler_id
1931        ,p_person_id                => p_person_id
1932        ,p_business_group_id        => p_business_group_id
1933        ,p_object_version_number    => l_object_version_number
1934        ,p_effective_date           => p_effective_date
1935        ,p_program_application_id   => fnd_global.prog_appl_id
1936        ,p_program_id               => fnd_global.conc_program_id
1937        ,p_request_id               => fnd_global.conc_request_id
1938        ,p_program_update_date      => l_sysdate
1939        ,p_ntfn_dt                  => TRUNC(l_sysdate)
1940        ,p_dtctd_dt                 => p_effective_date
1941        );
1942       --
1943     end if;
1944     --
1945     g_rec.person_id           := p_person_id;
1946     g_rec.ler_id              := l_ler_id;
1947     g_rec.lf_evt_ocrd_dt      := p_lf_evt_ocrd_dt;
1948     g_rec.replcd_flag         := 'N';
1949     g_rec.crtd_flag           := 'N';
1950     g_rec.tmprl_flag          := 'Y';
1951     g_rec.dltd_flag           := 'N';
1952     g_rec.open_and_clsd_flag  := 'N';
1953     g_rec.clsd_flag           := 'N';
1954     g_rec.not_crtd_flag       := 'N';
1955     g_rec.stl_actv_flag       := 'N';
1956     g_rec.clpsd_flag          := 'N';
1957     g_rec.clsn_flag           := 'N';
1958     g_rec.no_effect_flag      := 'N';
1959     g_rec.cvrge_rt_prem_flag  := 'N';
1960     g_rec.business_group_id   := p_business_group_id;
1961     g_rec.per_in_ler_id       := NULL;
1962     g_rec.effective_date      := p_effective_date;
1963     --
1964     benutils.write(p_rec=> g_rec);
1965     --
1966    -- hr_utility.set_location('Leaving ' || l_package,10);
1967   --
1968   END create_ptl_ler;
1969 --
1970   FUNCTION no_life_event(
1971     p_lf_evt_ocrd_dt IN DATE
1972    ,p_person_id      IN NUMBER
1973    ,p_ler_id         IN NUMBER
1974    ,p_effective_date IN DATE)
1975     RETURN BOOLEAN IS
1976     --
1977     l_package VARCHAR2(80) := g_package || '.no_life_event';
1978     l_dummy   VARCHAR2(1);
1979     l_ler_id  number := p_ler_id;
1980     --
1981     -- Note this cursor should not consider dates or status of the potential
1982     -- life event as it could be someone was running in the past or future.
1983     --
1984     CURSOR c1 IS
1985       SELECT   NULL
1986       FROM     ben_ptnl_ler_for_per pil
1987       WHERE    pil.person_id = p_person_id
1988       AND      pil.ler_id = l_ler_id
1989       AND      pil.lf_evt_ocrd_dt = p_lf_evt_ocrd_dt;
1990   --
1991   BEGIN
1992     --
1993    -- hr_utility.set_location('Entering ' || l_package,10);
1994     --
1995     -- GRADE/STEP : check for grade/step le in case of GSP program.
1996     --
1997     if g_pgm_typ_cd = 'GSP' then
1998        l_ler_id := g_gsp_ler_id;
1999     end if;
2000     --
2001     OPEN c1;
2002     --
2003     FETCH c1 INTO l_dummy;
2004     IF c1%FOUND THEN
2005       --
2006       CLOSE c1;
2007      -- hr_utility.set_location('Life event exists ' || l_package,10);
2008       RETURN FALSE;
2009     --
2010     END IF;
2011     --
2012     CLOSE c1;
2013     --
2014    -- hr_utility.set_location('No Life event exists ' || l_package,10);
2015     --
2016     RETURN TRUE;
2017     --
2018    -- hr_utility.set_location('Leaving ' || l_package,10);
2019   --
2020   END no_life_event;
2021 --
2022   PROCEDURE min_max_breach
2023     (p_calculate_only_mode in     boolean default false
2024     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
2025     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
2026     ,p_person_id           IN     NUMBER
2027     ,p_pgm_id              IN     NUMBER
2028     ,p_pl_id               IN     NUMBER
2029     ,p_oipl_id             IN     NUMBER
2030     ,p_oiplip_id           IN     NUMBER
2031     ,p_plip_id             IN     NUMBER
2032     ,p_ptip_id             IN     NUMBER
2033     ,p_business_group_id   IN     NUMBER
2034     ,p_ler_id              IN     NUMBER
2035     ,p_min_value           IN     NUMBER
2036     ,p_max_value           IN     NUMBER
2037     ,p_new_value           IN     NUMBER
2038     ,p_old_value           IN     NUMBER
2039     ,p_uom                 IN     VARCHAR2
2040     ,p_subtract_date       IN     DATE
2041     ,p_det_cd              IN     VARCHAR2
2042     ,p_formula_id          IN     NUMBER DEFAULT NULL
2043     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
2044     ,p_effective_date      IN     DATE
2045     )
2046   IS
2047     --
2048     l_package            VARCHAR2(80)        := g_package || '.min_max_breach';
2049     l_break              VARCHAR2(30);
2050     l_det_cd             VARCHAR2(30);
2051     l_lf_evt_ocrd_dt     DATE;
2052     l_new_lf_evt_ocrd_dt DATE;
2053     l_start_date         DATE;
2054     l_rec                ben_person_object.g_person_date_info_rec;
2055     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
2056   --
2057   BEGIN
2058     --
2059     if g_debug then
2060       hr_utility.set_location('Entering ' || l_package,10);
2061     end if;
2062     --
2063     -- Check if we break a boundary
2064     --
2065     if g_debug then
2066       hr_utility.set_location('min_max_breach '||p_max_value , 99);
2067     end if;
2068     if g_debug then
2069       hr_utility.set_location('p_new_value '||p_new_value ,99) ;
2070     end if;
2071     if g_debug then
2072       hr_utility.set_location('p_old_value '||p_old_value ,99);
2073     end if;
2074     hr_utility.set_location('pgm id = ' || p_pgm_id, 9876);
2075     hr_utility.set_location('pgm id = ' ||p_comp_obj_tree_row.par_pgm_id, 9876);
2076     --
2077     /* Bug 5478918 */
2078     if (skip_min_max_le_calc(p_ler_id,
2079                              p_business_group_id,
2080                              p_ptnl_ler_trtmt_cd,
2081                              p_effective_date)) THEN
2082        --
2083        /* Simply return as no further calculations need to be done */
2084        hr_utility.set_location(l_package||' Returning from here.', 9877);
2085        RETURN;
2086        --
2087     end if;
2088     /* End Bug 5478918 */
2089     --
2090     IF benutils.min_max_breach(p_min_value=> NVL(p_min_value
2091                                               ,-1)
2092         ,p_max_value => NVL(p_max_value
2093                          ,99999999)
2094         ,p_new_value => p_new_value
2095         ,p_old_value => p_old_value
2096         ,p_break     => l_break) THEN
2097       --
2098       -- Derive life event occured date based on the value of l_break
2099       -- This will return either the min or max evaluated date.
2100       --
2101       IF p_oiplip_id IS NOT NULL THEN
2102         --
2103         l_oiplip_rec  := p_curroiplip_row;
2104       --
2105       END IF;
2106       --
2107       l_lf_evt_ocrd_dt      :=
2108         benutils.derive_date(p_date=> p_subtract_date
2109          ,p_uom   => p_uom
2110          ,p_min   => p_min_value
2111          ,p_max   => p_max_value
2112          ,p_value => l_break);
2113 
2114       l_new_lf_evt_ocrd_dt  := l_lf_evt_ocrd_dt;
2115       --
2116       --hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt , 30);
2117       --hr_utility.set_location(' l_new_lf_evt_ocrd_dt'||l_new_lf_evt_ocrd_dt,40);
2118       --
2119       -- Now apply the date mask on top of the derived life event occured date
2120       -- E.G. This could mean that we calculate the Previous October 1 of the
2121       -- derived life event occured date. Do not do this if the det_cd = 'AED'
2122       -- as it will reset the date to the life event occured on date.
2123       --
2124       IF p_det_cd <> 'AED' THEN
2125         --
2126         ben_determine_date.main(p_date_cd=> p_det_cd
2127          ,p_formula_id        => p_formula_id
2128          ,p_person_id         => p_person_id
2129          ,p_pgm_id            => NVL(p_pgm_id
2130                                   ,p_comp_obj_tree_row.par_pgm_id)
2131          ,p_pl_id             => p_pl_id
2132          ,p_oipl_id           => NVL(p_oipl_id
2133                                   ,l_oiplip_rec.oipl_id)
2134          ,p_business_group_id => p_business_group_id
2135          ,p_returned_date     => l_new_lf_evt_ocrd_dt
2136          ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
2137          ,p_effective_date    => l_lf_evt_ocrd_dt);
2138         --
2139         hr_utility.set_location(' l_new_lf_evt_ocrd_dt'||l_new_lf_evt_ocrd_dt,50);
2140         --
2141         -- The derived life event occured date must be greater than the
2142         -- life event occured date as otherwise in reality a boundary has not
2143         -- been passed.
2144         -- This can only happen if the det_cd is one of the following :
2145         -- AFDCPPY = As of first day of current program or plan year
2146         -- APOCT1 = As of previous october 1st
2147         -- AFDCM = As of first day of the current month
2148         --
2149         IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
2150            AND p_det_cd IN ('AFDCPPY', 'APOCT1', 'AFDCM','AFDECY') THEN
2151           --
2152           -- These are special cases where we need to rederive the LED
2153           -- so that we are actually still passing the correct boundary
2154           --
2155           l_det_cd  := p_det_cd;
2156           --
2157           IF p_det_cd = 'APOCT1' or p_det_cd = 'AFDECY' THEN
2158             --
2159             l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
2160                                   ,12);
2161           --
2162           ELSIF p_det_cd = 'AFDCM' THEN
2163             --
2164             -- Why this is required ??? causing Bug 1927010
2165             --
2166             -- l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
2167             null ;
2168             --hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt , 60);
2169           --
2170           ELSIF p_det_cd = 'AFDCPPY' THEN
2171             --
2172             l_det_cd  := 'AFDFPPY';
2173           --
2174           END IF;
2175           --
2176           -- Reapply logic back to determination of date routine.
2177           --
2178           ben_determine_date.main(p_date_cd=> l_det_cd
2179            ,p_formula_id        => p_formula_id
2180            ,p_person_id         => p_person_id
2181            ,p_pgm_id            => NVL(p_pgm_id
2182                                     ,p_comp_obj_tree_row.par_pgm_id)
2183            ,p_pl_id             => p_pl_id
2184            ,p_oipl_id           => NVL(p_oipl_id
2185                                     ,l_oiplip_rec.oipl_id)
2186            ,p_business_group_id => p_business_group_id
2187            ,p_returned_date     => l_new_lf_evt_ocrd_dt
2188            ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
2189            ,p_effective_date    => l_lf_evt_ocrd_dt);
2190          --
2191          hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt ,70);
2192          hr_utility.set_location(' l_new_lf_evt_ocrd_dt'||l_new_lf_evt_ocrd_dt,80);
2193         --
2194         END IF;
2195       --
2196       END IF;
2197       --
2198       --  If date determination code is ALDECLY (End of Calendar Year), set
2199       --  the life event occurred date to the start of the calendar year.
2200       --  Bug 5731828.
2201       IF p_det_cd = 'ALDECLY' then
2202         l_new_lf_evt_ocrd_dt := trunc(l_new_lf_evt_ocrd_dt, 'YYYY');
2203         --
2204         ben_person_object.get_object(p_person_id=> p_person_id
2205          ,p_rec       => l_rec);
2206         --
2207         --  If the person is hired after Jan 1, then set the occurred date
2208         --  to the effective start date.
2209         --
2210         if l_new_lf_evt_ocrd_dt < l_rec.min_per_effective_start_date THEN
2211            l_new_lf_evt_ocrd_dt := l_rec.min_per_effective_start_date;
2212         end if;
2213       end if;
2214       --
2215       -- Check if we can ignore the life event that is attempted to be created
2216       --
2217       if g_debug then
2218         hr_utility.set_location(' l_new_lf_evt_ocrd_dt'||l_new_lf_evt_ocrd_dt,90);
2219         hr_utility.set_location(' p_effective_date'||p_effective_date,100);
2220       end if;
2221       --
2222       IF   (  l_new_lf_evt_ocrd_dt < p_effective_date
2223          AND NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNR')  THEN
2224         --
2225         -- We ignore life events that are to be created in the past
2226         --
2227         RETURN;
2228       --
2229       END IF;
2230       --
2231       -- We need to work out if the life event date is valid.
2232       -- The following rules apply.
2233       -- 1) Determined date must exist
2234       -- 2) Minimum life event occured dates are as follows :
2235       --    AGE - LED must be greater than min(effective_start_date) of person
2236       --    LOS - LED must be greater than min(effective_start_date) of person
2237       --
2238       IF l_new_lf_evt_ocrd_dt IS NOT NULL THEN
2239         --
2240         ben_person_object.get_object(p_person_id=> p_person_id
2241          ,p_rec       => l_rec);
2242         --
2243         IF l_new_lf_evt_ocrd_dt < l_rec.min_per_effective_start_date THEN
2244           --
2245           RETURN;
2246         --
2247         END IF;
2248       --
2249       ELSE
2250         --
2251         -- Defensive in case the date routine returned a null
2252         --
2253         RETURN;
2254       --
2255       END IF;
2256       --
2257       -- At this point we need to check whether there is an existing life
2258       -- event out there with the same life event occured date.
2259       -- If not we create a life event only if the person has an elig per
2260       -- f record.
2261       --
2262       if g_debug then
2263         hr_utility.set_location(' no_life_event ',110);
2264       end if;
2265       --
2266       IF no_life_event(p_lf_evt_ocrd_dt=> l_new_lf_evt_ocrd_dt
2267           ,p_person_id      => p_person_id
2268           ,p_ler_id         => p_ler_id
2269           ,p_effective_date => p_effective_date) THEN
2270         --
2271         if g_debug then
2272           hr_utility.set_location(' call to create_ptl_ler' , 120);
2273         end if;
2274         create_ptl_ler
2275           (p_calculate_only_mode => p_calculate_only_mode
2276           ,p_ler_id              => p_ler_id
2277           ,p_lf_evt_ocrd_dt      => l_new_lf_evt_ocrd_dt
2278           ,p_person_id           => p_person_id
2279           ,p_business_group_id   => p_business_group_id
2280           ,p_effective_date      => p_effective_date
2281           );
2282       Else
2283          --
2284          g_lf_evt_exists  := true;
2285       --
2286       END IF;
2287     --
2288     END IF;
2289     --
2290    if g_debug then
2291      hr_utility.set_location('Leaving ' || l_package,10);
2292    end if;
2293   --
2294   END min_max_breach;
2295 --
2296   FUNCTION los_calculation(
2297     p_comp_obj_tree_row IN            ben_manage_life_events.g_cache_proc_objects_rec
2298    ,p_empasg_row        IN            per_all_assignments_f%ROWTYPE
2299    ,p_benasg_row        IN            per_all_assignments_f%ROWTYPE
2300    ,p_pil_row           IN            ben_per_in_ler%ROWTYPE
2301    ,p_curroipl_row      IN            ben_cobj_cache.g_oipl_inst_row
2302    ,p_curroiplip_row    IN            ben_cobj_cache.g_oiplip_inst_row
2303    ,p_rec               IN            ben_derive_part_and_rate_cache.g_cache_los_rec_obj
2304    ,p_comp_rec          IN OUT NOCOPY g_cache_structure
2305    ,p_effective_date    IN            DATE
2306    ,p_lf_evt_ocrd_dt    IN            DATE
2307    ,p_business_group_id IN            NUMBER
2308    ,p_person_id         IN            NUMBER
2309    ,p_pgm_id            IN            NUMBER
2310    ,p_pl_id             IN            NUMBER
2311    ,p_oipl_id           IN            NUMBER
2312    ,p_oiplip_id         IN            NUMBER
2313    ,p_plip_id           IN            NUMBER
2314    ,p_ptip_id           IN            NUMBER
2315    ,p_subtract_date     OUT NOCOPY    DATE
2316    ,p_fonm_cvg_strt_dt  IN            Date default null)
2317     RETURN NUMBER IS
2318     --
2319     l_package       VARCHAR2(80)            := g_package || '.los_calculation';
2320     l_subtract_date DATE;
2321     l_start_date    DATE;
2322     l_result        NUMBER;
2323     l_pps_rec       per_periods_of_service%ROWTYPE;
2324     l_per_rec       per_all_people_f%ROWTYPE;
2325     l_dummy_num     NUMBER;
2326     l_aei_rec       per_assignment_extra_info%ROWTYPE;
2327     l_ass_rec       per_all_assignments_f%ROWTYPE;
2328     l_oiplip_rec    ben_cobj_cache.g_oiplip_inst_row;
2329   --
2330   BEGIN
2331    -- hr_utility.set_location('Entering ' || l_package,10);
2332     --
2333     -- Steps to perform process
2334     --
2335     -- 1) Work out the start date
2336     -- 2) Work out the date we are subtracting
2337     -- 3) Perform subtraction using correct unit of measure
2338     -- 4) Perform Rounding
2339     -- 5) Check if a boundary has been broken
2340     --
2341     IF p_oiplip_id IS NOT NULL THEN
2342       --
2343       l_oiplip_rec  := p_curroiplip_row;
2344     --
2345     END IF;
2346     --
2347     ben_determine_date.main(p_date_cd=> p_rec.los_det_cd
2348      ,p_formula_id        => p_rec.los_det_rl
2349      ,p_person_id         => p_person_id
2350      ,p_pgm_id            => NVL(p_pgm_id
2351                               ,p_comp_obj_tree_row.par_pgm_id)
2352      ,p_pl_id             => p_pl_id
2353      ,p_oipl_id           => NVL(p_oipl_id
2354                               ,l_oiplip_rec.oipl_id)
2355      ,p_business_group_id => p_business_group_id
2356      ,p_returned_date     => l_start_date
2357       --fonm2
2358      ,p_lf_evt_ocrd_dt    =>  p_lf_evt_ocrd_dt
2359      ,p_effective_date    =>  nvl(p_lf_evt_ocrd_dt,p_effective_date)
2360      ,p_fonm_cvg_strt_dt  => p_fonm_cvg_strt_dt
2361      );
2362     --
2363     ben_person_object.get_object(p_person_id=> p_person_id
2364      ,p_rec       => l_pps_rec);
2365     --
2366     -- Bug 5392019 : For Date to use codes like 'Inherited%' use benefits assignment
2367     --
2368     if p_rec.los_dt_to_use_cd in ('IASD', 'IDOH', 'IOHD')
2369     then
2370       l_ass_rec := p_benasg_row;
2371     else
2372       l_ass_rec := p_empasg_row;
2373     end if;
2374     --
2375     IF l_ass_rec.assignment_id IS NOT NULL THEN
2376      -- hr_utility.set_location('get extra info',10);
2377       --
2378       -- Fix for 115.77
2379       --
2380       ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
2381        ,p_rec           => l_aei_rec);
2382     --
2383     END IF;
2384     --
2385     IF p_rec.los_dt_to_use_cd = 'OHD' THEN
2386       -- Original hire date
2387       ben_person_object.get_object(p_person_id=> p_person_id
2388        ,p_rec       => l_per_rec);
2389       --
2390       IF l_per_rec.original_date_of_hire IS NOT NULL THEN
2391         --
2392         l_subtract_date  := l_per_rec.original_date_of_hire;
2393       --
2394       ELSE
2395         --
2396         l_subtract_date  := l_pps_rec.date_start;
2397       --
2398       END IF;
2399     --
2400     ELSIF p_rec.los_dt_to_use_cd = 'DOH' THEN
2401       -- Get the persons hire date only if the override service date flag is 'N'
2402       IF p_rec.use_overid_svc_dt_flag = 'N' THEN
2403         -- Get the persons hire date
2404         l_subtract_date  := l_pps_rec.date_start;
2405       --
2406       ELSIF p_comp_rec.ovrid_svc_dt IS NULL THEN
2407         --
2408         l_subtract_date  := l_pps_rec.date_start;
2409       --
2410       ELSE
2411         --
2412         l_subtract_date  := p_comp_rec.ovrid_svc_dt;
2413       --
2414       END IF;
2415     --
2416     ELSIF p_rec.los_dt_to_use_cd = 'ASD' THEN
2417       --
2418       -- Get the persons adjusted service date
2419       -- only if the override service date flag is 'N'
2420       --
2421       IF p_rec.use_overid_svc_dt_flag = 'N' THEN
2422         -- get person adjusted start date if its not null
2423         IF l_pps_rec.adjusted_svc_date IS NULL THEN
2424           --
2425           l_subtract_date  := l_pps_rec.date_start;
2426         --
2427         ELSE
2428           --
2429           l_subtract_date  := l_pps_rec.adjusted_svc_date;
2430         --
2431         END IF;
2432       --
2433       ELSE
2434         --
2435         -- We set the start date to the override value
2436         --
2437         IF p_comp_rec.ovrid_svc_dt IS NOT NULL THEN
2438           --
2439           l_subtract_date  := p_comp_rec.ovrid_svc_dt;
2440         --
2441         ELSE
2442           --
2443           l_subtract_date  := l_pps_rec.date_start;
2444         --
2445         END IF;
2446       --
2447       END IF;
2448     --
2449     ELSIF p_rec.los_dt_to_use_cd = 'IASD' THEN
2450       --
2451       -- inherited adjusted start date
2452       --
2453       IF p_rec.use_overid_svc_dt_flag = 'Y' THEN
2454         --
2455         l_subtract_date  := p_comp_rec.ovrid_svc_dt;
2456         --
2457         IF l_subtract_date IS NULL THEN
2458           --
2459           l_subtract_date  :=
2460                        fnd_date.canonical_to_date(l_aei_rec.aei_information2);
2461         --
2462         END IF;
2463       --
2464       ELSE
2465         --
2466         l_subtract_date  :=
2467                        fnd_date.canonical_to_date(l_aei_rec.aei_information2);
2468       --
2469       END IF;
2470     --
2471     ELSIF p_rec.los_dt_to_use_cd = 'IDOH' THEN
2472       --
2473       -- inherited date of hire
2474       --
2475       IF p_rec.use_overid_svc_dt_flag = 'Y' THEN
2476         --
2477         l_subtract_date  := p_comp_rec.ovrid_svc_dt;
2478         --
2479         IF l_subtract_date IS NULL THEN
2480           --
2481           l_subtract_date  :=
2482                       fnd_date.canonical_to_date(l_aei_rec.aei_information13);
2483         --
2484         END IF;
2485       --
2486       ELSE
2487         --
2488         l_subtract_date  :=
2489                       fnd_date.canonical_to_date(l_aei_rec.aei_information13);
2490       --
2491       END IF;
2492     --
2493     ELSIF p_rec.los_dt_to_use_cd = 'IOHD' THEN
2494       --
2495       -- inherited original hire date
2496       --
2497       l_subtract_date  :=
2498                        fnd_date.canonical_to_date(l_aei_rec.aei_information3);
2499     --
2500     ELSIF p_rec.los_dt_to_use_cd = 'RL' THEN
2501       --
2502       run_rule(p_formula_id => p_rec.los_dt_to_use_rl
2503        ,p_empasg_row        => p_empasg_row
2504        ,p_benasg_row        => p_benasg_row
2505        ,p_pil_row           => p_pil_row
2506        ,p_curroipl_row      => p_curroipl_row
2507        ,p_curroiplip_row    => p_curroiplip_row
2508        ,p_rule_type         => 'DATE'
2509        ,p_effective_date    => p_effective_date
2510        ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2511        ,p_business_group_id => p_business_group_id
2512        ,p_person_id         => p_person_id
2513        ,p_pgm_id            => nvl(p_pgm_id,
2514                                    p_comp_obj_tree_row.par_pgm_id)
2515        ,p_pl_id             => nvl(p_pl_id,
2516                                    p_comp_obj_tree_row.par_pl_id)
2517        ,p_oipl_id           => p_oipl_id
2518        ,p_oiplip_id         => p_oiplip_id
2519        ,p_plip_id           => nvl(p_plip_id,
2520                                    p_comp_obj_tree_row.par_plip_id)
2521        ,p_ptip_id           => nvl(p_ptip_id,
2522                                    p_comp_obj_tree_row.par_ptip_id)
2523        ,p_ret_date          => l_subtract_date
2524        ,p_ret_val           => l_dummy_num);
2525     --
2526     ELSE
2527       --
2528       fnd_message.set_name('BEN'
2529        ,'BEN_91342_UNKNOWN_CODE_1');
2530       fnd_message.set_token('PROC'
2531        ,l_package);
2532       fnd_message.set_token('CODE1'
2533        ,p_rec.los_dt_to_use_cd);
2534       RAISE ben_manage_life_events.g_record_error;
2535     --
2536     END IF;
2537     --
2538     -- Account for case where person is not an employee thus has
2539     -- no override_service_date, hire_date or adjusted_service_date
2540     --
2541     IF l_subtract_date IS NULL THEN
2542       --
2543      -- hr_utility.set_location('Leaving ' || l_package,10);
2544       RETURN NULL;
2545     --
2546     END IF;
2547     --
2548     IF p_rec.los_uom IS NOT NULL THEN
2549       --
2550       l_result  :=
2551         benutils.do_uom(p_date1=> l_start_date
2552          ,p_date2 => l_subtract_date
2553          ,p_uom   => p_rec.los_uom);
2554     --
2555     ELSE
2556       --
2557       l_result  := MONTHS_BETWEEN(l_start_date
2558                     ,l_subtract_date);
2559     --
2560     END IF;
2561     --
2562     IF    p_rec.rndg_cd IS NOT NULL
2563        OR p_rec.rndg_rl IS NOT NULL THEN
2564       -- dont use fonm date , the date only used for formula
2565       l_result  :=
2566         benutils.do_rounding(p_rounding_cd=> p_rec.rndg_cd
2567          ,p_rounding_rl    => p_rec.rndg_rl
2568          ,p_value          => l_result
2569          ,p_effective_date => NVL(p_lf_evt_ocrd_dt
2570                                ,p_effective_date) );
2571     --
2572     END IF;
2573     --
2574     hr_utility.set_location('p_subtract_date -> ' || p_subtract_date,99);
2575     --
2576     p_subtract_date  := l_subtract_date;
2577     hr_utility.set_location('Leaving ' || l_package,99);
2578     RETURN l_result;
2579   --
2580   END los_calculation;
2581 --
2582   FUNCTION age_calculation(
2583     p_comp_obj_tree_row IN     ben_manage_life_events.g_cache_proc_objects_rec
2584    ,p_per_row           IN     per_all_people_f%ROWTYPE
2585    ,p_empasg_row        IN     per_all_assignments_f%ROWTYPE
2586    ,p_benasg_row        IN     per_all_assignments_f%ROWTYPE
2587    ,p_pil_row           IN     ben_per_in_ler%ROWTYPE
2588    ,p_curroipl_row      IN     ben_cobj_cache.g_oipl_inst_row
2589    ,p_curroiplip_row    IN     ben_cobj_cache.g_oiplip_inst_row
2590    ,p_rec               IN     ben_derive_part_and_rate_cache.g_cache_age_rec_obj
2591    ,p_effective_date    IN     DATE
2592    ,p_lf_evt_ocrd_dt    IN     DATE
2593    ,p_business_group_id IN     NUMBER
2594    ,p_person_id         IN     NUMBER
2595    ,p_pgm_id            IN     NUMBER
2596    ,p_pl_id             IN     NUMBER
2597    ,p_oipl_id           IN     NUMBER
2598    ,p_oiplip_id         IN     NUMBER
2599    ,p_plip_id           IN     NUMBER
2600    ,p_ptip_id           IN     NUMBER
2601    ,p_subtract_date     OUT NOCOPY    DATE
2602    ,p_fonm_cvg_strt_dt  IN     date default null  )
2603     RETURN NUMBER IS
2604     --
2605     l_package           VARCHAR2(80)        := g_package || '.age_calculation';
2606     --
2607     l_effective_date    DATE;
2608     l_proc              VARCHAR2(80)                      := 'age_calculation';
2609     l_subtract_date     DATE;
2610     l_start_date        DATE;
2611     l_result            NUMBER;
2612     l_dummy_num         NUMBER;
2613     l_outputs           ff_exec.outputs_t;
2614     l_pil_rec           ben_per_in_ler%ROWTYPE;
2615     l_pl_rec            ben_pl_f%ROWTYPE;
2616     l_oipl_rec          ben_oipl_f%ROWTYPE;
2617     l_oiplip_rec        ben_cobj_cache.g_oiplip_inst_row;
2618     l_ass_rec           per_all_assignments_f%ROWTYPE;
2619     l_loc_rec           hr_locations_all%ROWTYPE;
2620     l_per_rec           per_all_people_f%ROWTYPE;
2621     l_person_id         NUMBER;
2622     l_jurisdiction_code VARCHAR2(30);
2623     l_aei_rec           per_assignment_extra_info%ROWTYPE;
2624     --
2625     --bug#3274130 - added date condition for relationship to pick the right spouse
2626     CURSOR c_per_spouse IS
2627       SELECT   per.person_id
2628               ,per.date_of_birth
2629       FROM     per_contact_relationships ctr, per_all_people_f per
2630       WHERE    ctr.person_id = p_person_id
2631       AND      per.person_id = ctr.contact_person_id
2632       AND      ctr.personal_flag = 'Y'
2633       AND      ctr.contact_type = 'S'
2634       and      l_effective_date between nvl(ctr.date_start, hr_api.g_sot)
2635                and  nvl(ctr.date_end, hr_api.g_eot)
2636       AND      l_effective_date BETWEEN per.effective_start_date
2637                    AND per.effective_end_date;
2638     --
2639     CURSOR c_per_depen_first IS
2640       SELECT   per.person_id
2641               ,per.date_of_birth
2642       FROM     per_contact_relationships ctr, per_all_people_f per
2643       WHERE    ctr.person_id = p_person_id
2644       AND      per.person_id = ctr.contact_person_id
2645       AND      ctr.personal_flag = 'Y'
2646       AND      ctr.dependent_flag = 'Y'
2647       AND      l_effective_date BETWEEN per.effective_start_date
2648                    AND per.effective_end_date;
2649     --
2650     CURSOR c_per_child_first IS
2651       SELECT   per.person_id
2652               ,per.date_of_birth
2653       FROM     per_contact_relationships ctr, per_all_people_f per
2654       WHERE    ctr.person_id = p_person_id
2655       AND      per.person_id = ctr.contact_person_id
2656       AND      ctr.personal_flag = 'Y'
2657       AND      ctr.contact_type IN ('C', 'O', 'A', 'T')
2658       AND      l_effective_date BETWEEN per.effective_start_date
2659                    AND per.effective_end_date;
2660     --
2661     CURSOR c_per_depen_oldest IS
2662       SELECT   per.person_id
2663               ,per.date_of_birth
2664       FROM     per_contact_relationships ctr, per_all_people_f per
2665       WHERE    ctr.person_id = p_person_id
2666       AND      per.person_id = ctr.contact_person_id
2667       AND      ctr.personal_flag = 'Y'
2668       AND      ctr.dependent_flag = 'Y'
2669       AND      l_effective_date BETWEEN per.effective_start_date
2670                    AND per.effective_end_date
2671        ORDER BY per.date_of_birth;
2672     --
2673     CURSOR c_per_child_oldest IS
2674       SELECT   per.person_id
2675               ,per.date_of_birth
2676       FROM     per_contact_relationships ctr, per_all_people_f per
2677       WHERE    ctr.person_id = p_person_id
2678       AND      per.person_id = ctr.contact_person_id
2679       AND      ctr.personal_flag = 'Y'
2680       AND      ctr.contact_type IN ('C', 'O', 'A', 'T')
2681       AND      l_effective_date BETWEEN per.effective_start_date
2682                    AND per.effective_end_date
2683        ORDER BY per.date_of_birth;
2684     --
2685     CURSOR c_per_depen_young IS
2686       SELECT   per.person_id
2687               ,per.date_of_birth
2688       FROM     per_contact_relationships ctr, per_all_people_f per
2689       WHERE    ctr.person_id = p_person_id
2690       AND      per.person_id = ctr.contact_person_id
2691       AND      ctr.personal_flag = 'Y'
2692       AND      ctr.dependent_flag = 'Y'
2693       AND      l_effective_date BETWEEN per.effective_start_date
2694                    AND per.effective_end_date
2695        ORDER BY per.date_of_birth DESC;
2696     --
2697     CURSOR c_per_child_young IS
2698       SELECT   per.person_id
2699               ,per.date_of_birth
2700       FROM     per_contact_relationships ctr, per_all_people_f per
2701       WHERE    ctr.person_id = p_person_id
2702       AND      per.person_id = ctr.contact_person_id
2703       AND      ctr.personal_flag = 'Y'
2704       AND      ctr.contact_type IN ('C', 'O', 'A', 'T')
2705       AND      l_effective_date BETWEEN per.effective_start_date
2706                    AND per.effective_end_date
2707        ORDER BY per.date_of_birth DESC;
2708     --
2709     l_per               c_per_spouse%ROWTYPE;
2710   --
2711   BEGIN
2712     --
2713    -- hr_utility.set_location('Entering ' || l_package,10);
2714     --
2715     -- Steps to perform process
2716     --
2717     -- 1) Work out the start date
2718     -- 2) Work out the date we are subtracting
2719     -- 3) Perform subtraction using correct unit of measure
2720     -- 4) Perform Rounding
2721     -- 5) Check if a boundary has been broken
2722     --
2723     IF p_lf_evt_ocrd_dt IS NOT NULL THEN
2724       --
2725       l_effective_date  := p_lf_evt_ocrd_dt;
2726     --
2727     ELSE
2728       --
2729       l_effective_date  := p_effective_date;
2730     --
2731     END IF;
2732 
2733     -- fonm2
2734     l_effective_date := NVL(g_fonm_cvg_strt_dt,l_effective_date);
2735     --
2736     IF p_oiplip_id IS NOT NULL THEN
2737       --
2738       l_oiplip_rec  := p_curroiplip_row;
2739     --
2740     END IF;
2741   --
2742 -- -- hr_utility.set_location('Age to use code '||p_rec.age_to_use_cd,10);
2743   --
2744     IF    p_rec.age_to_use_cd = 'P'
2745        OR (    p_rec.age_to_use_cd IS NULL
2746            AND p_rec.age_calc_rl IS NULL) THEN
2747       --  we already have the person_id so use it
2748       l_person_id  := p_person_id;
2749     --
2750     ELSIF p_rec.age_calc_rl IS NOT NULL THEN
2751       --
2752       run_rule(p_formula_id => p_rec.age_calc_rl
2753        ,p_empasg_row        => p_empasg_row
2754        ,p_benasg_row        => p_benasg_row
2755        ,p_pil_row           => p_pil_row
2756        ,p_curroipl_row      => p_curroipl_row
2757        ,p_curroiplip_row    => p_curroiplip_row
2758        ,p_rule_type         => 'DATE'
2759        ,p_effective_date    => p_effective_date
2760        ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2761        ,p_business_group_id => p_business_group_id
2762        ,p_person_id         => p_person_id
2763        ,p_pgm_id            => p_pgm_id
2764        ,p_pl_id             => p_pl_id
2765        ,p_oipl_id           => p_oipl_id
2766        ,p_oiplip_id         => p_oiplip_id
2767        ,p_plip_id           => p_plip_id
2768        ,p_ptip_id           => p_ptip_id
2769        ,p_ret_date          => l_per.date_of_birth
2770        ,p_ret_val           => l_dummy_num);
2771       --
2772       IF l_per.date_of_birth IS NULL THEN
2773         --
2774         RETURN NULL;
2775       --
2776       END IF;
2777       --
2778       l_per_rec.date_of_birth  := l_per.date_of_birth;
2779     --
2780     ELSIF p_rec.age_to_use_cd = 'PS' THEN
2781       --
2782       OPEN c_per_spouse;
2783       --
2784       FETCH c_per_spouse INTO l_per;
2785       --
2786       CLOSE c_per_spouse;
2787       --
2788       IF l_per.date_of_birth IS NOT NULL THEN
2789         --
2790         l_person_id  := l_per.person_id;
2791       --
2792       ELSE
2793         --
2794         RETURN NULL;
2795       --
2796       END IF;
2797       --
2798       l_per_rec.date_of_birth  := l_per.date_of_birth;
2799     --
2800     ELSIF p_rec.age_to_use_cd = 'PD1' THEN
2801       --
2802       OPEN c_per_depen_first;
2803       --
2804       FETCH c_per_depen_first INTO l_per;
2805       --
2806       CLOSE c_per_depen_first;
2807       --
2808       IF l_per.date_of_birth IS NOT NULL THEN
2809         --
2810         l_person_id  := l_per.person_id;
2811       --
2812       ELSE
2813         --
2814         RETURN NULL;
2815       --
2816       END IF;
2817       --
2818       l_per_rec.date_of_birth  := l_per.date_of_birth;
2819     --
2820     ELSIF p_rec.age_to_use_cd = 'PDO' THEN
2821       --
2822       OPEN c_per_depen_oldest;
2823       --
2824       FETCH c_per_depen_oldest INTO l_per;
2825       --
2826       CLOSE c_per_depen_oldest;
2827       --
2828       IF l_per.date_of_birth IS NOT NULL THEN
2829         --
2830         l_person_id  := l_per.person_id;
2831       --
2832       ELSE
2833         --
2834         RETURN NULL;
2835       --
2836       END IF;
2837       --
2838       l_per_rec.date_of_birth  := l_per.date_of_birth;
2839     --
2840     ELSIF p_rec.age_to_use_cd = 'PC1' THEN
2841       --
2842       OPEN c_per_child_first;
2843       --
2844       FETCH c_per_child_first INTO l_per;
2845       --
2846       CLOSE c_per_child_first;
2847       --
2848       IF l_per.date_of_birth IS NOT NULL THEN
2849         --
2850         l_person_id  := l_per.person_id;
2851       --
2852       ELSE
2853         --
2854         RETURN NULL;
2855       --
2856       END IF;
2857       --
2858       l_per_rec.date_of_birth  := l_per.date_of_birth;
2859     --
2860     ELSIF p_rec.age_to_use_cd = 'PCO' THEN
2861       --
2862       OPEN c_per_child_oldest;
2863       --
2864       FETCH c_per_child_oldest INTO l_per;
2865       --
2866       CLOSE c_per_child_oldest;
2867       --
2868       IF l_per.date_of_birth IS NOT NULL THEN
2869         --
2870         l_person_id  := l_per.person_id;
2871       --
2872       ELSE
2873         --
2874         RETURN NULL;
2875       --
2876       END IF;
2877       --
2878       l_per_rec.date_of_birth  := l_per.date_of_birth;
2879     --
2880     ELSIF p_rec.age_to_use_cd = 'PCY' THEN
2881       --
2882       OPEN c_per_child_young;
2883       --
2884       FETCH c_per_child_young INTO l_per;
2885       --
2886       CLOSE c_per_child_young;
2887       --
2888       IF l_per.date_of_birth IS NOT NULL THEN
2889         --
2890         l_person_id  := l_per.person_id;
2891       --
2892       ELSE
2893         --
2894         RETURN NULL;
2895       --
2896       END IF;
2897       --
2898       l_per_rec.date_of_birth  := l_per.date_of_birth;
2899     --
2900     ELSIF p_rec.age_to_use_cd = 'PDY' THEN
2901       --
2902       OPEN c_per_depen_young;
2903       --
2904       FETCH c_per_depen_young INTO l_per;
2905       --
2906       CLOSE c_per_depen_young;
2907       --
2908       IF l_per.date_of_birth IS NOT NULL THEN
2909         --
2910         l_person_id  := l_per.person_id;
2911       --
2912       ELSE
2913         --
2914         RETURN NULL;
2915       --
2916       END IF;
2917       --
2918       l_per_rec.date_of_birth  := l_per.date_of_birth;
2919     --
2920     ELSIF p_rec.age_to_use_cd = 'IA' THEN
2921       --
2922       l_ass_rec  := p_benasg_row;
2923       --
2924       IF l_ass_rec.assignment_id IS NOT NULL THEN
2925         --
2926         ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
2927          ,p_rec           => l_aei_rec);
2928       --
2929       END IF;
2930       --
2931       IF l_aei_rec.aei_information1 IS NULL THEN
2932         --
2933         RETURN NULL;
2934       --
2935       ELSE
2936         --
2937         IF p_rec.age_uom = 'YR' THEN
2938           l_result  := TO_NUMBER(l_aei_rec.aei_information1);
2939         ELSIF p_rec.age_uom = 'MO' THEN
2940           l_result  := TO_NUMBER(l_aei_rec.aei_information1) * 12;
2941         ELSIF p_rec.age_uom = 'WK' THEN
2942           l_result  := (TO_NUMBER(l_aei_rec.aei_information1) * 365) / 7;
2943         ELSIF p_rec.age_uom = 'DY' THEN
2944           l_result  := TO_NUMBER(l_aei_rec.aei_information1) * 365;
2945         ELSE
2946           l_result  := TO_NUMBER(l_aei_rec.aei_information1);
2947         END IF;
2948       --
2949       END IF;
2950     --
2951     END IF;
2952     --
2953     IF    p_rec.age_to_use_cd <> 'IA'
2954        OR p_rec.age_calc_rl IS NOT NULL THEN
2955       --
2956       if g_debug then
2957         hr_utility.set_location(' BDD_Mn ' || l_package,10);
2958       end if;
2959       ben_determine_date.main(p_date_cd=> p_rec.age_det_cd
2960        ,p_formula_id        => p_rec.age_det_rl
2961        ,p_person_id         => p_person_id
2962        ,p_pgm_id            => NVL(p_pgm_id
2963                                 ,p_comp_obj_tree_row.par_pgm_id)
2964        ,p_pl_id             => p_pl_id
2965        ,p_oipl_id           => NVL(p_oipl_id
2966                                 ,l_oiplip_rec.oipl_id)
2967        ,p_returned_date     => l_start_date
2968        -- fonm2
2969        ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
2970        ,p_business_group_id => p_business_group_id
2971        ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date )
2972        ,p_fonm_cvg_strt_dt  => p_fonm_cvg_strt_dt );
2973       --
2974       IF p_rec.age_to_use_cd = 'P' THEN
2975         --
2976         l_per_rec  := p_per_row;
2977       --
2978 /*
2979       ben_person_object.get_object(p_person_id => l_person_id,
2980                                    p_rec       => l_per_rec);
2981       --
2982 */
2983       --hr_utility.set_location(' Dn BPO_GO ' || l_package,10);
2984       END IF;
2985       --
2986       l_subtract_date  := l_per_rec.date_of_birth;
2987       --
2988       IF l_subtract_date IS NULL THEN
2989         --
2990         RETURN NULL;
2991       --
2992       END IF;
2993       --
2994       IF p_rec.age_uom IS NOT NULL THEN
2995         --
2996         l_result  :=
2997           benutils.do_uom(p_date1=> l_start_date
2998            ,p_date2 => l_subtract_date
2999            ,p_uom   => p_rec.age_uom);
3000       --
3001       ELSE
3002         --
3003         l_result  := MONTHS_BETWEEN(l_start_date
3004                       ,l_subtract_date);
3005       --
3006       END IF;
3007       --
3008       --hr_utility.set_location(' Dn <> IA ' ||l_result,10);
3009     END IF;
3010     --
3011     IF    p_rec.rndg_cd IS NOT NULL
3012        OR p_rec.rndg_rl IS NOT NULL THEN
3013       --
3014       l_result  :=
3015         benutils.do_rounding(p_rounding_cd=> p_rec.rndg_cd
3016          ,p_rounding_rl    => p_rec.rndg_rl
3017          ,p_value          => l_result
3018          ,p_effective_date =>  NVL(p_lf_evt_ocrd_dt
3019                                ,p_effective_date));
3020     --
3021     END IF;
3022     --
3023    hr_utility.set_location('return  ' || l_subtract_date,10);
3024    hr_utility.set_location('Leaving ' || l_package,10);
3025     --
3026     p_subtract_date  := l_subtract_date;
3027     RETURN l_result;
3028   --
3029   END age_calculation;
3030 --
3031   FUNCTION hours_calculation(
3032     p_comp_obj_tree_row IN ben_manage_life_events.g_cache_proc_objects_rec
3033    ,p_empasg_row        IN per_all_assignments_f%ROWTYPE
3034    ,p_benasg_row        IN per_all_assignments_f%ROWTYPE
3035    ,p_curroiplip_row    IN ben_cobj_cache.g_oiplip_inst_row
3036    ,p_rec               IN ben_derive_part_and_rate_cache.g_cache_hwf_rec_obj
3037    ,p_business_group_id IN NUMBER
3038    ,p_person_id         IN NUMBER
3039    ,p_pgm_id            IN NUMBER
3040    ,p_pl_id             IN NUMBER
3041    ,p_oipl_id           IN NUMBER
3042    ,p_oiplip_id         IN NUMBER
3043    ,p_plip_id           IN NUMBER
3044    ,p_ptip_id           IN NUMBER
3045    ,p_effective_date    IN DATE
3046    ,p_lf_evt_ocrd_dt    IN DATE)
3047     RETURN NUMBER IS
3048     --
3049     l_package           VARCHAR2(80)      := g_package || '.hours_calculation';
3050     l_start_date        DATE;
3051     l_result            NUMBER;
3052     l_outputs           ff_exec.outputs_t;
3053     l_pil_rec           ben_per_in_ler%ROWTYPE;
3054     l_pl_rec            ben_pl_f%ROWTYPE;
3055     l_oipl_rec          ben_oipl_f%ROWTYPE;
3056     l_oiplip_rec        ben_cobj_cache.g_oiplip_inst_row;
3057     l_loc_rec           hr_locations_all%ROWTYPE;
3058     l_ass_rec           per_all_assignments_f%ROWTYPE;
3059     l_bal_rec           ben_per_bnfts_bal_f%ROWTYPE;
3060     l_bnb_rec           ben_bnfts_bal_f%ROWTYPE;
3061     l_jurisdiction_code VARCHAR2(30);
3062     l_assignment_action_id  number;
3063 
3064 
3065     Cursor c_ass is
3066       select min(effective_start_date)
3067       From  per_all_assignments_f ass
3068       where person_id = p_person_id
3069       and   ass.assignment_type <> 'C'
3070       and primary_flag = 'Y' ;
3071 
3072     l_min_ass_date date ;
3073 
3074   --
3075   BEGIN
3076     --
3077     if g_debug then
3078       hr_utility.set_location('Entering ' || l_package,10);
3079     end if;
3080     --
3081     -- Steps to perform process
3082     --
3083     -- 1) Work out the start date
3084     -- 2) Perform Rounding
3085     --
3086     IF p_oiplip_id IS NOT NULL THEN
3087       --
3088       l_oiplip_rec  := p_curroiplip_row;
3089     --
3090     END IF;
3091     --
3092     ben_determine_date.main(p_date_cd=> p_rec.hrs_wkd_det_cd
3093      ,p_formula_id        => p_rec.hrs_wkd_det_rl
3094      ,p_person_id         => p_person_id
3095      ,p_bnfts_bal_id      => p_rec.bnfts_bal_id
3096      ,p_pgm_id            => NVL(p_pgm_id
3097                               ,p_comp_obj_tree_row.par_pgm_id)
3098      ,p_pl_id             => p_pl_id
3099      ,p_oipl_id           => NVL(p_oipl_id
3100                               ,l_oiplip_rec.oipl_id)
3101      ,p_business_group_id => p_business_group_id
3102      ,p_returned_date     => l_start_date
3103      ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3104      ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date)
3105      ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
3106     --
3107     if g_debug then
3108       hr_utility.set_location('p_rec.hrs_src_cd '||p_rec.hrs_src_cd ,20);
3109     end if;
3110     IF p_rec.hrs_src_cd = 'BNFTBALTYP' THEN
3111       --
3112       IF ben_whatif_elig.g_bnft_bal_hwf_val IS NOT NULL THEN
3113         --
3114         -- This is the case where benmngle is called from the
3115         -- watif form and user wants to simulate hours worked
3116         -- changed. Use the user supplied simulate hours value rather
3117         -- than the fetched value.
3118         --
3119         l_result  := ben_whatif_elig.g_bnft_bal_hwf_val;
3120       --
3121       ELSE
3122         --
3123         -- Get the persons balance
3124         if g_debug then
3125           hr_utility.set_location(' p_rec.bnfts_bal_id '||p_rec.bnfts_bal_id , 30);
3126         end if;
3127         if g_debug then
3128           hr_utility.set_location(' p_person_id '||p_person_id , 30);
3129         end if;
3130         if g_debug then
3131           hr_utility.set_location(' l_start_date '||l_start_date, 30);
3132         end if;
3133         --
3134         ben_person_object.get_object(p_person_id=> p_person_id
3135          ,p_effective_date => l_start_date
3136          ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3137          ,p_rec            => l_bal_rec);
3138         --
3139         l_result  := l_bal_rec.val;
3140         --
3141         IF l_result IS NULL THEN
3142 
3143            if p_rec.hrs_wkd_det_cd in
3144               ('AFDCPPY','AFDCSPPY','AFDCPPQ','AFDCM','AFDCSM','APOCT1','AFDECY' ) then
3145 
3146               open c_ass ;
3147               fetch c_ass into l_min_ass_date ;
3148               close c_ass ;
3149 
3150               if g_debug then
3151                 hr_utility.set_location (' l_min_ass_date ' || l_min_ass_date, 1999);
3152               end if;
3153               if l_min_ass_date  is not null then
3154                  ben_person_object.get_object(p_person_id=> p_person_id
3155                        ,p_effective_date => l_min_ass_date
3156                        ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3157                        ,p_rec            => l_bal_rec);
3158                  --
3159                  l_result  := l_bal_rec.val;
3160               end if ;
3161            end if ;
3162 
3163         end if ;
3164 
3165         IF l_result IS NULL THEN
3166           --
3167           if g_debug then
3168             hr_utility.set_location(' Person does not have a balance ',40);
3169           end if;
3170           --
3171           -- Person does not have a balance, recheck if they have a balance
3172           -- as of the life event occurred date or effective date.
3173           -- Fix for bug 216.
3174           --
3175           ben_person_object.get_object(p_bnfts_bal_id=> p_rec.bnfts_bal_id
3176            ,p_rec          => l_bnb_rec);
3177           --
3178           fnd_message.set_name('BEN'
3179            ,'BEN_92317_PER_BALANCE_NULL');
3180           fnd_message.set_token('NAME'
3181            ,l_bnb_rec.name);
3182           fnd_message.set_token('DATE'
3183            ,l_start_date);
3184           benutils.write(p_text=> fnd_message.get);
3185           --
3186           ben_person_object.get_object(p_person_id=> p_person_id
3187            ,p_effective_date => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
3188                                  ,p_effective_date))
3189            ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3190            ,p_rec            => l_bal_rec);
3191           --
3192           l_result  := l_bal_rec.val;
3193           if g_debug then
3194             hr_utility.set_location(' Person does not l_bal_rec.val  '||l_bal_rec.val ,50);
3195           end if;
3196           --
3197           IF l_result IS NULL THEN
3198             --
3199             fnd_message.set_name('BEN'
3200              ,'BEN_92317_PER_BALANCE_NULL');
3201             fnd_message.set_token('NAME'
3202              ,l_bnb_rec.name);
3203             fnd_message.set_token('DATE'
3204              ,NVL(p_lf_evt_ocrd_dt
3205                ,p_effective_date));
3206             benutils.write(p_text=> fnd_message.get);
3207             RETURN NULL;
3208           --
3209           END IF;
3210         --
3211         END IF;
3212       --
3213       END IF;                           -- whatif hours worked existence check
3214     --
3215     ELSIF p_rec.hrs_src_cd = 'BALTYP' THEN
3216       --
3217       IF ben_whatif_elig.g_bal_hwf_val IS NOT NULL THEN
3218         --
3219         -- This is the case where benmngle is called from the
3220         -- watif form and user wants to simulate hours worked
3221         -- changed. Use the user supplied simulate hours value rather
3222         -- than the fetched value.
3223         --
3224         l_result  := ben_whatif_elig.g_bal_hwf_val;
3225       --
3226       ELSE
3227         --
3228         -- Get the persons balance
3229         --
3230         IF p_empasg_row.assignment_id IS NULL THEN
3231           --
3232           l_ass_rec  := p_benasg_row;
3233         --
3234         ELSE
3235           --
3236           l_ass_rec  := p_empasg_row;
3237         --
3238         END IF;
3239         -- before calling the get_value set the tax_unit_id context
3240         set_taxunit_context
3241             (p_person_id           =>     p_person_id
3242             ,p_business_group_id   =>     p_business_group_id
3243             ,p_effective_date      =>     nvl(g_fonm_cvg_strt_dt,p_effective_date)
3244              ) ;
3245         --
3246         -- Bug 3818453. Pass assignment_action_id to get_value() to
3247         -- improve performance
3248         --
3249         l_assignment_action_id :=
3250                           get_latest_paa_id
3251                           (p_person_id         => p_person_id
3252                           ,p_business_group_id => p_business_group_id
3253                           ,p_effective_date    => l_start_date);
3254 
3255         if l_assignment_action_id is not null then
3256            --
3257            begin
3258               l_result  :=
3259               pay_balance_pkg.get_value(p_rec.defined_balance_id
3260               ,l_assignment_action_id);
3261            exception
3262              when others then
3263              l_result := null ;
3264            end ;
3265            --
3266         end if;
3267         if l_result is null then
3268            fnd_message.set_name('BEN' ,'BEN_92318_BEN_BALANCE_NULL');
3269            fnd_message.set_token('DATE' ,l_start_date);
3270            benutils.write(p_text=> fnd_message.get);
3271            return null;
3272         end if;
3273 
3274         --
3275         -- old code prior to 3818453
3276         --
3277 /*        --
3278         begin
3279            l_result  :=
3280            pay_balance_pkg.get_value(p_rec.defined_balance_id
3281            ,l_ass_rec.assignment_id
3282            ,l_start_date);
3283         exception
3284           when others then
3285           l_result := null ;
3286         end ;
3287 
3288         IF l_result IS NULL THEN
3289             if p_rec.hrs_wkd_det_cd in
3290                  ('AFDCPPY','AFDCSPPY','AFDCPPQ','AFDCM','AFDCSM','APOCT1','AFDECY' ) then
3291                  open c_ass ;
3292                  fetch c_ass into l_min_ass_date ;
3293                  close c_ass ;
3294                  if g_debug then
3295                    hr_utility.set_location (' l_min_ass_date ' || l_min_ass_date, 1999);
3296                  end if;
3297                  l_result  :=
3298                      pay_balance_pkg.get_value(p_rec.defined_balance_id
3299                     ,l_ass_rec.assignment_id
3300                     ,l_min_ass_date);
3301 
3302               end if ;
3303         end if ;
3304 
3305         --
3306         IF l_result IS NULL THEN
3307           --
3308           -- Person does not have a balance, recheck if they have a balance
3309           -- as of the life event occurred date or effective date.
3310           -- Fix for bug 216.
3311           --
3312           fnd_message.set_name('BEN'
3313            ,'BEN_92318_BEN_BALANCE_NULL');
3314           fnd_message.set_token('DATE'
3315            ,l_start_date);
3316           benutils.write(p_text=> fnd_message.get);
3317           --
3318           l_result  :=
3319             pay_balance_pkg.get_value(p_rec.defined_balance_id
3320              ,l_ass_rec.assignment_id
3321              ,NVL(p_lf_evt_ocrd_dt
3322                ,p_effective_date));
3323           --
3324           IF l_result IS NULL THEN
3325             --
3326             fnd_message.set_name('BEN'
3327              ,'BEN_92318_BEN_BALANCE_NULL');
3328             fnd_message.set_token('DATE'
3329              ,NVL(p_lf_evt_ocrd_dt
3330                ,p_effective_date));
3331             benutils.write(p_text=> fnd_message.get);
3332             RETURN NULL;
3333           --
3334           END IF;
3335         --
3336         END IF; */
3337       --
3338       END IF;                          -- whatif hours worked existence check.
3339     --
3340     END IF;
3341     --
3342     IF    p_rec.rndg_cd IS NOT NULL
3343        OR p_rec.rndg_rl IS NOT NULL THEN
3344       --
3345       l_result  :=
3346         benutils.do_rounding(p_rounding_cd=> p_rec.rndg_cd
3347          ,p_rounding_rl    => p_rec.rndg_rl
3348          ,p_value          => l_result
3349          ,p_effective_date => NVL(p_lf_evt_ocrd_dt
3350                                ,p_effective_date));
3351     --
3352     END IF;
3353     --
3354     if g_debug then
3355       hr_utility.set_location(' End of hours_calculation l_result '||l_result, 50);
3356     end if;
3357     --
3358     RETURN l_result;
3359   --
3360   END hours_calculation;
3361   ------------------------------------------------------------------------------
3362   -- ******THIS IS NOW OBSOLETED ***********************************************
3363   -- We are now using the call to BEN_DERIVE_FACTORS.determine_compensation
3364   -- to determine the compensation to avoid maitening the similar code at two
3365   -- different places.
3366   -------------------------------------------------------------------------------
3367   FUNCTION comp_calculation(
3368     p_comp_obj_tree_row IN ben_manage_life_events.g_cache_proc_objects_rec
3369    ,p_empasg_row        IN per_all_assignments_f%ROWTYPE
3370    ,p_benasg_row        IN per_all_assignments_f%ROWTYPE
3371    ,p_curroiplip_row    IN ben_cobj_cache.g_oiplip_inst_row
3372    ,p_rec               IN ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
3373    ,p_person_id         IN NUMBER
3374    ,p_business_group_id IN NUMBER
3375    ,p_pgm_id            IN NUMBER
3376    ,p_pl_id             IN NUMBER
3377    ,p_oipl_id           IN NUMBER
3378    ,p_oiplip_id         IN NUMBER
3379    ,p_plip_id           IN NUMBER
3380    ,p_ptip_id           IN NUMBER
3381    ,p_effective_date    IN DATE
3382    ,p_lf_evt_ocrd_dt    IN DATE)
3383     RETURN NUMBER IS
3384 
3385    ---
3386    Cursor c_ass is
3387       select min(effective_start_date)
3388       From  per_all_assignments_f ass
3389       where person_id = p_person_id
3390       and   ass.assignment_type <> 'C'
3391       and primary_flag = 'Y' ;
3392 
3393     l_min_ass_date date ;
3394 
3395     --
3396     l_package           VARCHAR2(80)       := g_package || '.comp_calculation';
3397     l_start_date        DATE;
3398     l_result            NUMBER;
3399     l_outputs           ff_exec.outputs_t;
3400     l_pil_rec           ben_per_in_ler%ROWTYPE;
3401     l_pl_rec            ben_pl_f%ROWTYPE;
3402     l_oipl_rec          ben_oipl_f%ROWTYPE;
3403     l_oiplip_rec        ben_cobj_cache.g_oiplip_inst_row;
3404     l_loc_rec           hr_locations_all%ROWTYPE;
3405     l_ass_rec           per_all_assignments_f%ROWTYPE;
3406     l_bal_rec           ben_per_bnfts_bal_f%ROWTYPE;
3407     l_bnb_rec           ben_bnfts_bal_f%ROWTYPE;
3408     l_jurisdiction_code VARCHAR2(30);
3409     l_assignment_action_id  number;
3410   --
3411   BEGIN
3412    g_debug := hr_utility.debug_enabled;
3413    --
3414    -- hr_utility.set_location('Entering ' || l_package,10);
3415     --
3416     -- Steps to perform process
3417     --
3418     -- 1) Work out the start date
3419     -- 2) Perform Rounding
3420     --
3421    --FONM2
3422    if ben_manage_life_events.fonm = 'Y'
3423       and ben_manage_life_events.g_fonm_cvg_strt_dt  is not null then
3424      --
3425      g_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt ;
3426      --
3427    else
3428     g_fonm_cvg_strt_dt := null ;
3429    end if;
3430    -- fonm
3431 
3432 
3433     IF p_oiplip_id IS NOT NULL THEN
3434       --
3435       l_oiplip_rec  := p_curroiplip_row;
3436     --
3437     END IF;
3438     --
3439     ben_determine_date.main(p_date_cd=> p_rec.comp_lvl_det_cd
3440      ,p_formula_id        => p_rec.comp_lvl_det_rl
3441      ,p_person_id         => p_person_id
3442      ,p_pgm_id            => NVL(p_pgm_id
3443                               ,p_comp_obj_tree_row.par_pgm_id)
3444      ,p_bnfts_bal_id      => p_rec.bnfts_bal_id
3445      ,p_pl_id             => p_pl_id
3446      ,p_oipl_id           => NVL(p_oipl_id
3447                               ,l_oiplip_rec.oipl_id)
3448      ,p_business_group_id => p_business_group_id
3449      ,p_returned_date     => l_start_date
3450      ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3451      ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date)
3452      ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
3453     --
3454     IF p_rec.comp_src_cd = 'STTDCOMP' THEN
3455       --
3456       IF ben_whatif_elig.g_stat_comp IS NOT NULL THEN
3457         --
3458         -- This is the case where benmngle is called from the
3459         -- watif form and user wants to simulate compensation level
3460         -- changed. Use the user supplied compensation value rather
3461         -- than the fetched value.
3462         --
3463         l_result  := ben_whatif_elig.g_stat_comp;
3464       --
3465       ELSE
3466         --
3467         -- Get the persons salary
3468         --
3469         l_result  :=
3470           get_persons_salary(p_empasg_row=> p_empasg_row
3471            ,p_benasg_row        => p_benasg_row
3472            ,p_person_id         => p_person_id
3473            ,p_business_group_id => p_business_group_id
3474            ,p_effective_date    => l_start_date);
3475         --
3476         IF l_result IS NULL THEN
3477           --
3478           -- Person does not have a balance, recheck if they have a balance
3479           -- as of the life event occurred date or effective date.
3480           -- Fix for bug 216.
3481           --
3482           fnd_message.set_name('BEN'
3483            ,'BEN_92319_SAL_BALANCE_NULL');
3484           fnd_message.set_token('DATE'
3485            ,l_start_date);
3486           benutils.write(p_text=> fnd_message.get);
3487           ---if date code is
3488           -- first of year,half year,quarter,month,semi month,previos oct 1
3489           -- then take the firstist salary
3490           if p_rec.comp_lvl_det_cd in
3491               ('AFDCPPY','AFDCSPPY','AFDCPPQ','AFDCM','AFDCSM','APOCT1','AFDECY' ) then
3492               open c_ass ;
3493               fetch c_ass into l_min_ass_date ;
3494               close c_ass ;
3495               if g_debug then
3496                 hr_utility.set_location (' l_min_ass_date ' || l_min_ass_date, 1999);
3497               end if;
3498               if l_min_ass_date  is not null then
3499                  l_result  :=
3500                  get_persons_salary(p_empasg_row=> p_empasg_row
3501                       ,p_benasg_row        => p_benasg_row
3502                       ,p_person_id         => p_person_id
3503                       ,p_business_group_id => p_business_group_id
3504                       ,p_effective_date    => l_min_ass_date);
3505                   if g_debug then
3506                     hr_utility.set_location ('result ' || l_result , 1999);
3507                   end if;
3508                end if ;
3509            end if ;
3510         End if ;
3511 
3512         IF l_result IS NULL THEN
3513            --
3514            l_result  :=
3515             get_persons_salary(p_empasg_row=> p_empasg_row
3516              ,p_benasg_row        => p_benasg_row
3517              ,p_person_id         => p_person_id
3518              ,p_business_group_id => p_business_group_id
3519              ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
3520                                       ,p_effective_date));
3521           --
3522            IF l_result IS NULL THEN
3523             --
3524             fnd_message.set_name('BEN'
3525              ,'BEN_92319_SAL_BALANCE_NULL');
3526             fnd_message.set_token('DATE'
3527              ,NVL(p_lf_evt_ocrd_dt
3528                ,p_effective_date));
3529             benutils.write(p_text=> fnd_message.get);
3530             RETURN NULL;
3531             --
3532            END IF;
3533         --
3534         END IF;
3535       --
3536       END IF;                          -- whatif compensation existence check.
3537     --
3538     ELSIF p_rec.comp_src_cd = 'BNFTBALTYP' THEN
3539       --
3540       IF ben_whatif_elig.g_bnft_bal_comp IS NOT NULL THEN
3541         --
3542         -- This is the case where benmngle is called from the
3543         -- watif form and user wants to simulate compensation level
3544         -- changed. Use the user supplied compensation value rather
3545         -- than the fetched value.
3546         --
3547         l_result  := ben_whatif_elig.g_bnft_bal_comp;
3548       --
3549       ELSE
3550         --
3551         -- Get the persons balance
3552         --
3553         ben_person_object.get_object(p_person_id=> p_person_id
3554          ,p_effective_date => l_start_date
3555          ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3556          ,p_rec            => l_bal_rec);
3557         --
3558         l_result  := l_bal_rec.val;
3559         --
3560         IF l_result IS NULL THEN
3561            if p_rec.comp_lvl_det_cd in
3562               ('AFDCPPY','AFDCSPPY','AFDCPPQ','AFDCM','AFDCSM','APOCT1','AFDECY' ) then
3563 
3564               open c_ass ;
3565               fetch c_ass into l_min_ass_date ;
3566               close c_ass ;
3567 
3568               if g_debug then
3569                 hr_utility.set_location (' l_min_ass_date ' || l_min_ass_date, 1999);
3570               end if;
3571               if l_min_ass_date  is not null then
3572                  ben_person_object.get_object(p_person_id=> p_person_id
3573                        ,p_effective_date => l_min_ass_date
3574                        ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3575                        ,p_rec            => l_bal_rec);
3576                  --
3577                  l_result  := l_bal_rec.val;
3578               end if ;
3579           end if ;
3580           IF l_result IS NULL THEN
3581               --
3582               -- Person does not have a balance, recheck if they have a balance
3583               -- as of the life event occurred date or effective date.
3584               -- Fix for bug 216.
3585               --
3586               ben_person_object.get_object(p_bnfts_bal_id=> p_rec.bnfts_bal_id
3587                ,p_rec          => l_bnb_rec);
3588               --
3589               fnd_message.set_name('BEN'
3590                ,'BEN_92317_PER_BALANCE_NULL');
3591               fnd_message.set_token('NAME'
3592                ,l_bnb_rec.name);
3593               fnd_message.set_token('DATE'
3594                ,l_start_date);
3595               benutils.write(p_text=> fnd_message.get);
3596               --
3597               ben_person_object.get_object(p_person_id=> p_person_id
3598                ,p_effective_date => p_effective_date
3599                ,p_bnfts_bal_id   => p_rec.bnfts_bal_id
3600                ,p_rec            => l_bal_rec);
3601               --
3602               l_result  := l_bal_rec.val;
3603               --
3604               IF l_result IS NULL THEN
3605                 --
3606                 fnd_message.set_name('BEN'
3607                  ,'BEN_92317_PER_BALANCE_NULL');
3608                 fnd_message.set_token('NAME'
3609                  ,l_bnb_rec.name);
3610                 fnd_message.set_token('DATE'
3611                  ,NVL(p_lf_evt_ocrd_dt
3612                    ,p_effective_date));
3613                 benutils.write(p_text=> fnd_message.get);
3614                 RETURN NULL;
3615               --
3616               END IF;
3617             --
3618             END IF;
3619           --
3620         End if ;
3621       END IF;                          -- whatif compensation existence check.
3622     --
3623     ELSIF p_rec.comp_src_cd = 'BALTYP' THEN
3624       --
3625       IF ben_whatif_elig.g_bal_comp IS NOT NULL THEN
3626         --
3627         -- This is the case where benmngle is called from the
3628         -- watif form and user wants to simulate compensation level
3629         -- changed. Use the user supplied compensation value rather
3630         -- than the fetched value.
3631         --
3632         l_result  := ben_whatif_elig.g_bal_comp;
3633       --
3634       ELSE
3635         --
3636         -- Get the persons balance
3637         --
3638         IF p_empasg_row.assignment_id IS NULL THEN
3639           --
3640           l_ass_rec  := p_benasg_row;
3641         --
3642         ELSE
3643           --
3644           l_ass_rec  := p_empasg_row;
3645         --
3646         END IF;
3647           -- before calling the get_value set the tax_unit_id context
3648         set_taxunit_context
3649             (p_person_id           =>     p_person_id
3650             ,p_business_group_id   =>     p_business_group_id
3651             ,p_effective_date      =>     nvl(g_fonm_cvg_strt_dt,p_effective_date)
3652              ) ;
3653         --
3654         -- Bug 3818453. Pass assignment_action_id to get_value() to
3655         -- improve performance
3656         --
3657         l_assignment_action_id :=
3658                           get_latest_paa_id
3659                           (p_person_id         => p_person_id
3660                           ,p_business_group_id => p_business_group_id
3661                           ,p_effective_date    => l_start_date);
3662 
3663         if l_assignment_action_id is not null then
3664            --
3665            begin
3666               l_result  :=
3667               pay_balance_pkg.get_value(p_rec.defined_balance_id
3668               ,l_assignment_action_id);
3669            exception
3670              when others then
3671              l_result := null ;
3672            end ;
3673            --
3674         end if ;
3675 
3676         if l_result is null then
3677            fnd_message.set_name('BEN' ,'BEN_92318_BEN_BALANCE_NULL');
3678            fnd_message.set_token('DATE' ,l_start_date);
3679            benutils.write(p_text=> fnd_message.get);
3680            return null;
3681         end if;
3682         --
3683         --
3684         -- old code prior to 3818453
3685         --
3686 /*
3687         --
3688         l_result  :=
3689           pay_balance_pkg.get_value(p_rec.defined_balance_id
3690            ,l_ass_rec.assignment_id
3691            ,l_start_date);
3692 
3693         IF l_result IS NULL THEN
3694             if p_rec.comp_lvl_det_cd in
3695                ('AFDCPPY','AFDCSPPY','AFDCPPQ','AFDCM','AFDCSM','APOCT1','AFDECY' ) then
3696 
3697                open c_ass ;
3698                fetch c_ass into l_min_ass_date ;
3699                close c_ass ;
3700 
3701                if g_debug then
3702                  hr_utility.set_location (' l_min_ass_date ' || l_min_ass_date, 1999);
3703                end if;
3704                if l_min_ass_date  is not null then
3705                   l_result  :=
3706                      pay_balance_pkg.get_value(p_rec.defined_balance_id
3707                      ,l_ass_rec.assignment_id
3708                      ,l_min_ass_date);
3709 
3710                end if ;
3711                --
3712             end if ;
3713             IF l_result IS NULL THEN
3714                --
3715                -- Person does not have a balance, recheck if they have a balance
3716                -- as of the life event occurred date or effective date.
3717                -- Fix for bug 216.
3718                --
3719                fnd_message.set_name('BEN'
3720                 ,'BEN_92318_BEN_BALANCE_NULL');
3721                fnd_message.set_token('DATE'
3722                 ,l_start_date);
3723                benutils.write(p_text=> fnd_message.get);
3724                l_result  :=
3725                  pay_balance_pkg.get_value(p_rec.defined_balance_id
3726                   ,l_ass_rec.assignment_id
3727                   ,NVL(p_lf_evt_ocrd_dt
3728                     ,p_effective_date));
3729                --
3730                IF l_result IS NULL THEN
3731                  --
3732                  fnd_message.set_name('BEN'
3733                   ,'BEN_92318_BEN_BALANCE_NULL');
3734                  fnd_message.set_token('DATE'
3735                   ,NVL(p_lf_evt_ocrd_dt
3736                     ,p_effective_date));
3737                  benutils.write(p_text=> fnd_message.get);
3738                  RETURN NULL;
3739                  --
3740                END IF;
3741                --
3742             END IF;
3743             --
3744          End If ; */
3745       END IF;                          -- whatif compensation existence check.
3746     --
3747     END IF;
3748     --
3749     IF    p_rec.rndg_cd IS NOT NULL
3750        OR p_rec.rndg_rl IS NOT NULL THEN
3751       --
3752       l_result  :=
3753         benutils.do_rounding(p_rounding_cd=> p_rec.rndg_cd
3754          ,p_rounding_rl    => p_rec.rndg_rl
3755          ,p_value          => l_result
3756          ,p_effective_date => NVL(p_lf_evt_ocrd_dt
3757                                ,p_effective_date));
3758     --
3759     END IF;
3760     --
3761     RETURN l_result;
3762     --
3763    -- hr_utility.set_location('Entering ' || l_package,10);
3764   --
3765   END comp_calculation;
3766 --
3767   PROCEDURE calculate_los
3768     (p_calculate_only_mode in     boolean default false
3769     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
3770     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
3771     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
3772     ,p_pil_row             IN     ben_per_in_ler%ROWTYPE
3773     ,p_curroipl_row        IN     ben_cobj_cache.g_oipl_inst_row
3774     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
3775     ,p_person_id           IN     NUMBER
3776     ,p_business_group_id   IN     NUMBER
3777     ,p_pgm_id              IN     NUMBER
3778     ,p_pl_id               IN     NUMBER
3779     ,p_oipl_id             IN     NUMBER
3780     ,p_plip_id             IN     NUMBER
3781     ,p_ptip_id             IN     NUMBER
3782     ,p_oiplip_id           IN     NUMBER
3783     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
3784     ,p_los_fctr_id         IN     NUMBER DEFAULT NULL
3785     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
3786     ,p_effective_date      IN     DATE
3787     ,p_lf_evt_ocrd_dt      IN     DATE
3788     )
3789   IS
3790     --
3791     l_package        VARCHAR2(80)             := g_package || '.calculate_los';
3792     --
3793     l_rate_result    NUMBER;
3794     l_rate_cvg_result NUMBER;
3795     l_rate_prem_result NUMBER;
3796     l_elig_result    NUMBER;
3797     l_subtract_date  DATE;
3798     l_start_date     DATE;
3799     l_elig_rec       ben_derive_part_and_rate_cache.g_cache_los_rec_obj;
3800     l_rate_rec       ben_derive_part_and_rate_cache.g_cache_los_rec_obj;
3801     l_rate_cvg_rec   ben_derive_part_and_rate_cache.g_cache_los_rec_obj;
3802     l_rate_prem_rec  ben_derive_part_and_rate_cache.g_cache_los_rec_obj;
3803     l_der_cvg_rec    ben_seeddata_object.g_derived_factor_info_rec;
3804     l_der_prem_rec   ben_seeddata_object.g_derived_factor_info_rec;
3805     l_der_rec        ben_seeddata_object.g_derived_factor_info_rec;
3806     l_effective_date DATE          := NVL(p_lf_evt_ocrd_dt
3807                                        ,p_effective_date);
3808     l_dummy_date     DATE;
3809     l_rate           BOOLEAN                                         := FALSE;
3810     l_cvg            BOOLEAN                                         := FALSE;
3811     l_prem           BOOLEAN                                         := FALSE;
3812     l_oiplip_rec     ben_cobj_cache.g_oiplip_inst_row;
3813     l_los_val        number;
3814     --FONM
3815     --g_fonm_cvg_strt_dt DATE ;
3816     --END FONM
3817   --
3818   BEGIN
3819    --
3820    --
3821 --
3822 -- Calculate LOS process
3823 -- =====================
3824 -- This process will calculate the LOS value for rates and eligibility
3825 -- The sequence of operations is as follows :
3826 -- 1) First check if freeze LOS flag is on in which case
3827 --    we ignore the calculation and just return the frozen values
3828 -- 2) Calculate for eligibility derivable factors
3829 -- 3) Calculate for rate derivable factors
3830 -- 3) Perform rounding
3831 -- 4) Test for min/max breach
3832 -- 5) If a breach did occur then create a ptnl_ler_for_per.
3833     --
3834     IF bitand(p_comp_obj_tree_row.flag_bit_val
3835            ,ben_manage_life_events.g_los_flag) <> 0
3836        OR     p_los_fctr_id IS NOT NULL
3837           AND bitand(p_comp_obj_tree_row.flag_bit_val
3838                ,ben_manage_life_events.g_cal_flag) <> 0 THEN
3839       --
3840      -- hr_utility.set_location('LOS for ELIG',10);
3841       IF p_comp_rec.frz_los_flag = 'Y' THEN
3842         --
3843         -- No calulation required just return the frozen value
3844         --
3845         NULL;
3846       --
3847       ELSE
3848         --
3849         IF p_los_fctr_id IS NOT NULL THEN
3850           --
3851           ben_derive_part_and_rate_cache.get_los_stated(p_los_fctr_id=> p_los_fctr_id
3852            ,p_business_group_id => p_business_group_id
3853            ,p_rec               => l_elig_rec);
3854         --
3855         ELSE
3856           --
3857           ben_derive_part_and_rate_cache.get_los_elig(p_pgm_id=> p_pgm_id
3858            ,p_pl_id             => p_pl_id
3859            ,p_oipl_id           => p_oipl_id
3860            ,p_plip_id           => p_plip_id
3861            ,p_ptip_id           => p_ptip_id
3862            ,p_business_group_id => p_business_group_id
3863            ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
3864            ,p_rec               => l_elig_rec);
3865         --
3866         END IF;
3867         --
3868         IF l_elig_rec.exist = 'Y' THEN
3869           -- los based on los_calc_rl takes precedence
3870           IF l_elig_rec.los_calc_rl IS NOT NULL THEN
3871             --
3872             ben_determine_date.main(p_date_cd=> l_elig_rec.los_det_cd
3873              ,p_formula_id        => l_elig_rec.los_det_rl
3874              ,p_person_id         => p_person_id
3875              ,p_pgm_id            => NVL(p_pgm_id
3876                                       ,p_comp_obj_tree_row.par_pgm_id)
3877              ,p_pl_id             => p_pl_id
3878              ,p_oipl_id           => p_oipl_id
3879              ,p_business_group_id => p_business_group_id
3880              ,p_returned_date     => l_start_date
3881              ,p_lf_evt_ocrd_dt    =>  p_lf_evt_ocrd_dt
3882              ,p_effective_date    =>  NVL(p_lf_evt_ocrd_dt ,p_effective_date)
3883             );
3884             --
3885             run_rule(p_formula_id => l_elig_rec.los_calc_rl
3886              ,p_empasg_row        => p_empasg_row
3887              ,p_benasg_row        => p_benasg_row
3888              ,p_pil_row           => p_pil_row
3889              ,p_curroipl_row      => p_curroipl_row
3890              ,p_curroiplip_row    => p_curroiplip_row
3891              ,p_effective_date    => l_start_date
3892              ,p_lf_evt_ocrd_dt    => l_start_date
3893              ,p_business_group_id => p_business_group_id
3894              ,p_person_id         => p_person_id
3895              ,p_pgm_id            => p_pgm_id
3896              ,p_pl_id             => p_pl_id
3897              ,p_oipl_id           => p_oipl_id
3898              ,p_oiplip_id         => p_oiplip_id
3899              ,p_plip_id           => p_plip_id
3900              ,p_ptip_id           => p_ptip_id
3901              ,p_ret_date          => l_dummy_date
3902              ,p_ret_val           => l_elig_result);
3903             --
3904             -- Round value if rounding needed
3905             --
3906             IF    l_elig_rec.rndg_cd IS NOT NULL
3907                OR l_elig_rec.rndg_rl IS NOT NULL THEN
3908               --
3909               l_elig_result  :=
3910                 benutils.do_rounding(p_rounding_cd=> l_elig_rec.rndg_cd
3911                  ,p_rounding_rl    => l_elig_rec.rndg_rl
3912                  ,p_value          => l_elig_result
3913                  ,p_effective_date => NVL(g_fonm_cvg_strt_dt,
3914                                           NVL(p_lf_evt_ocrd_dt ,p_effective_date))
3915                );
3916             --
3917             END IF;
3918           --
3919           ELSE
3920             l_elig_result  :=
3921               los_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
3922                ,p_empasg_row        => p_empasg_row
3923                ,p_benasg_row        => p_benasg_row
3924                ,p_pil_row           => p_pil_row
3925                ,p_curroipl_row      => p_curroipl_row
3926                ,p_curroiplip_row    => p_curroiplip_row
3927                ,p_rec               => l_elig_rec
3928                ,p_comp_rec          => p_comp_rec
3929                ,p_effective_date    => p_effective_date
3930                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
3931                ,p_business_group_id => p_business_group_id
3932                ,p_person_id         => p_person_id
3933                ,p_pgm_id            => p_pgm_id
3934                ,p_pl_id             => p_pl_id
3935                ,p_oipl_id           => p_oipl_id
3936                ,p_oiplip_id         => p_oiplip_id
3937                ,p_plip_id           => p_plip_id
3938                ,p_ptip_id           => p_ptip_id
3939                ,p_subtract_date     => l_subtract_date
3940                ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
3941           END IF;
3942           --
3943           IF     l_elig_result IS NOT NULL
3944              AND p_los_fctr_id IS NULL THEN
3945              --
3946              --
3947              -- if person is still ineligible elig_per rows are not updated - to simulate the
3948              -- elig_per data the old val is assigned the min value if the temporal life event
3949              -- was created before for the same breach
3950              l_los_val         := p_comp_rec.los_val;
3951              Loop
3952                g_lf_evt_exists   := false;
3953                ben_derive_part_and_rate_cache.get_los_elig(p_pgm_id=> p_pgm_id
3954               ,p_pl_id             => p_pl_id
3955               ,p_oipl_id           => p_oipl_id
3956               ,p_plip_id           => p_plip_id
3957               ,p_ptip_id           => p_ptip_id
3958               ,p_new_val           => l_elig_result
3959               ,p_old_val           => l_los_val
3960               ,p_business_group_id => p_business_group_id
3961               ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
3962               ,p_rec               => l_elig_rec);
3963             --
3964 
3965             ben_seeddata_object.get_object(p_rec=> l_der_rec);
3966             --
3967             min_max_breach
3968               (p_calculate_only_mode => p_calculate_only_mode
3969               ,p_comp_obj_tree_row   => p_comp_obj_tree_row
3970               ,p_curroiplip_row      => p_curroiplip_row
3971               ,p_person_id           => p_person_id
3972               ,p_pgm_id              => p_pgm_id
3973               ,p_pl_id               => p_pl_id
3974               ,p_oipl_id             => p_oipl_id
3975               ,p_oiplip_id           => p_oiplip_id
3976               ,p_plip_id             => p_plip_id
3977               ,p_ptip_id             => p_ptip_id
3978               ,p_business_group_id   => p_business_group_id
3979               ,p_ler_id              => l_der_rec.drvdlos_id
3980               ,p_min_value           => l_elig_rec.mn_los_num
3981               ,p_max_value           => l_elig_rec.mx_los_num
3982               ,p_new_value           => l_elig_result
3983               ,p_old_value           => l_los_val
3984               ,p_uom                 => l_elig_rec.los_uom
3985               ,p_subtract_date       => l_subtract_date
3986               ,p_det_cd              => l_elig_rec.los_det_cd
3987               ,p_formula_id          => l_elig_rec.los_det_rl
3988               ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
3989               ,p_effective_date      => p_effective_date
3990               );
3991             --
3992               if not g_lf_evt_exists or l_los_val = l_elig_rec.mn_los_num or
3993                     l_elig_rec.mn_los_num is null then
3994                  exit;
3995               else
3996                  l_los_val := l_elig_rec.mn_los_num;
3997               end if;
3998             End Loop;
3999             g_lf_evt_exists := false;
4000             p_comp_rec.los_val  := l_elig_result;
4001             p_comp_rec.los_uom  := l_elig_rec.los_uom;
4002           --
4003           ELSIF l_elig_result IS NULL THEN
4004             --
4005             p_comp_rec.los_val  := NULL;
4006             p_comp_rec.los_uom  := NULL;
4007           --
4008           ELSE
4009             --
4010             p_comp_rec.los_val  := l_elig_result;
4011             p_comp_rec.los_uom  := l_elig_rec.los_uom;
4012           --
4013           END IF;
4014         --
4015         ELSE
4016           --
4017           p_comp_rec.los_val  := NULL;
4018           p_comp_rec.los_uom  := NULL;
4019         --
4020         END IF;
4021       --
4022       END IF;
4023     --
4024     END IF;
4025     --
4026     IF    bitand(p_comp_obj_tree_row.flag_bit_val
4027            ,ben_manage_life_events.g_los_rt_flag) <> 0
4028        OR     p_los_fctr_id IS NOT NULL
4029           AND bitand(p_comp_obj_tree_row.flag_bit_val
4030                ,ben_manage_life_events.g_cal_rt_flag) <> 0
4031        OR     p_oiplip_id IS NOT NULL
4032           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
4033                ,ben_manage_life_events.g_los_rt_flag) <> 0 THEN
4034       --
4035      -- hr_utility.set_location('LOS for RT',10);
4036       IF p_comp_rec.rt_frz_los_flag = 'Y' THEN
4037         --
4038         -- No calulation required just return the frozen value
4039         --
4040         NULL;
4041       --
4042       ELSE
4043         --
4044         IF p_los_fctr_id IS NOT NULL THEN
4045           --
4046           ben_derive_part_and_rate_cache.get_los_stated(p_los_fctr_id=> p_los_fctr_id
4047            ,p_business_group_id => p_business_group_id
4048            ,p_rec               => l_rate_rec);
4049         --
4050         ELSE
4051           --
4052           ben_derive_part_and_rate_cache.get_los_rate(p_pgm_id=> p_pgm_id
4053            ,p_pl_id             => p_pl_id
4054            ,p_oipl_id           => p_oipl_id
4055            ,p_plip_id           => p_plip_id
4056            ,p_ptip_id           => p_ptip_id
4057            ,p_oiplip_id         => p_oiplip_id
4058            ,p_business_group_id => p_business_group_id
4059            ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
4060            ,p_rec               => l_rate_rec);
4061           --
4062           IF l_rate_rec.exist = 'Y' THEN
4063             --
4064             l_rate  := TRUE;
4065             --
4066             IF p_oiplip_id IS NOT NULL THEN
4067               --
4068               l_oiplip_rec  := p_curroiplip_row;
4069             --
4070             END IF;
4071             --
4072                      -- los based on los_calc_rl takes precedence
4073             IF l_rate_rec.los_calc_rl IS NOT NULL THEN
4074               --
4075               ben_determine_date.main(p_date_cd=> l_rate_rec.los_det_cd
4076                ,p_formula_id        => l_rate_rec.los_det_rl
4077                ,p_person_id         => p_person_id
4078                ,p_pgm_id            => NVL(p_pgm_id
4079                                         ,p_comp_obj_tree_row.par_pgm_id)
4080                ,p_pl_id             => p_pl_id
4081                ,p_oipl_id           => NVL(p_oipl_id
4082                                         ,l_oiplip_rec.oipl_id)
4083                ,p_business_group_id => p_business_group_id
4084                ,p_returned_date     => l_start_date
4085                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4086                ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date));
4087               --
4088               run_rule(p_formula_id => l_rate_rec.los_calc_rl
4089                ,p_empasg_row        => p_empasg_row
4090                ,p_benasg_row        => p_benasg_row
4091                ,p_pil_row           => p_pil_row
4092                ,p_curroipl_row      => p_curroipl_row
4093                ,p_curroiplip_row    => p_curroiplip_row
4094                ,p_effective_date    => p_effective_date
4095                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4096                ,p_business_group_id => p_business_group_id
4097                ,p_person_id         => p_person_id
4098                ,p_pgm_id            => p_pgm_id
4099                ,p_pl_id             => p_pl_id
4100                ,p_oipl_id           => NVL(p_oipl_id
4101                                         ,l_oiplip_rec.oipl_id)
4102                ,p_oiplip_id         => p_oiplip_id
4103                ,p_plip_id           => p_plip_id
4104                ,p_ptip_id           => p_ptip_id
4105                ,p_ret_date          => l_dummy_date
4106                ,p_ret_val           => l_rate_result);
4107                 --
4108                IF    l_rate_rec.rndg_cd IS NOT NULL
4109                  OR l_rate_rec.rndg_rl IS NOT NULL THEN
4110                  --
4111                  l_rate_result  :=
4112                       benutils.do_rounding(p_rounding_cd=> l_rate_rec.rndg_cd
4113                        ,p_rounding_rl    => l_rate_rec.rndg_rl
4114                        ,p_value          => l_rate_result
4115                        ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4116                                           ,p_effective_date)));
4117                  --
4118                END IF;
4119              ELSE   -- l_rate_rec.los_calc_rl
4120                --
4121                l_rate_result  :=
4122                  los_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4123                   ,p_empasg_row        => p_empasg_row
4124                   ,p_benasg_row        => p_benasg_row
4125                   ,p_pil_row           => p_pil_row
4126                   ,p_curroipl_row      => p_curroipl_row
4127                   ,p_curroiplip_row    => p_curroiplip_row
4128                   ,p_rec               => l_rate_rec
4129                   ,p_comp_rec          => p_comp_rec
4130                   ,p_effective_date    => p_effective_date
4131                   ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4132                   ,p_business_group_id => p_business_group_id
4133                   ,p_person_id         => p_person_id
4134                   ,p_pgm_id            => p_pgm_id
4135                   ,p_pl_id             => p_pl_id
4136                   ,p_oipl_id           => p_oipl_id
4137                   ,p_oiplip_id         => p_oiplip_id
4138                   ,p_plip_id           => p_plip_id
4139                   ,p_ptip_id           => p_ptip_id
4140                   ,p_subtract_date     => l_subtract_date
4141                   ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
4142 
4143                   --
4144                IF l_rate_result is not null THEN
4145                  --
4146                  ben_derive_part_and_rate_cache.get_los_rate(p_pgm_id=> p_pgm_id
4147                   ,p_pl_id             => p_pl_id
4148                   ,p_oipl_id           => p_oipl_id
4149                   ,p_plip_id           => p_plip_id
4150                   ,p_ptip_id           => p_ptip_id
4151                   ,p_oiplip_id         => p_oiplip_id
4152                   ,p_new_val           => l_rate_result
4153                   ,p_old_val           => p_comp_rec.rt_los_val
4154                   ,p_business_group_id => p_business_group_id
4155                   ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
4156                   ,p_rec               => l_rate_rec);
4157                  --
4158                  ben_seeddata_object.get_object(p_rec=> l_der_rec);
4159                  --
4160                  min_max_breach
4161                    (p_calculate_only_mode => p_calculate_only_mode
4162                    ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4163                    ,p_curroiplip_row      => p_curroiplip_row
4164                    ,p_person_id           => p_person_id
4165                    ,p_pgm_id              => p_pgm_id
4166                    ,p_pl_id               => p_pl_id
4167                    ,p_oipl_id             => p_oipl_id
4168                    ,p_oiplip_id           => p_oiplip_id
4169                    ,p_plip_id             => p_plip_id
4170                    ,p_ptip_id             => p_ptip_id
4171                    ,p_business_group_id   => p_business_group_id
4172                    ,p_ler_id              => l_der_rec.drvdlos_id
4173                    ,p_min_value           => l_rate_rec.mn_los_num
4174                    ,p_max_value           => l_rate_rec.mx_los_num
4175                    ,p_new_value           => l_rate_result
4176                    ,p_old_value           => p_comp_rec.rt_los_val
4177                    ,p_uom                 => l_rate_rec.los_uom
4178                    ,p_subtract_date       => l_subtract_date
4179                    ,p_det_cd              => l_rate_rec.los_det_cd
4180                    ,p_formula_id          => l_rate_rec.los_det_rl
4181                    ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4182                    ,p_effective_date      => p_effective_date
4183                         );
4184                 END IF ; -- l_rate_result
4185                 --
4186               END IF; -- l_rate_rec.los_calc_rl
4187               --
4188            END IF ; -- l_rate_rec.exist
4189            --
4190            -- Try and find a coverage first
4191            --
4192            IF    p_oipl_id IS NOT NULL
4193                OR p_pl_id IS NOT NULL
4194                OR p_plip_id IS NOT NULL THEN
4195               --
4196               ben_derive_part_and_rate_cvg.get_los_rate(p_pl_id=> p_pl_id
4197                ,p_oipl_id           => p_oipl_id
4198                ,p_plip_id           => p_plip_id
4199                ,p_business_group_id => p_business_group_id
4200                ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
4201                ,p_rec               => l_rate_cvg_rec);
4202               --
4203              IF l_rate_cvg_rec.exist = 'Y' THEN
4204                --
4205                l_cvg  := TRUE;
4206                --
4207                -- los based on los_calc_rl takes precedence
4208                IF l_rate_cvg_rec.los_calc_rl IS NOT NULL THEN
4209                  --
4210                  ben_determine_date.main(p_date_cd=> l_rate_cvg_rec.los_det_cd
4211                   ,p_formula_id        => l_rate_cvg_rec.los_det_rl
4212                   ,p_person_id         => p_person_id
4213                   ,p_pgm_id            => NVL(p_pgm_id
4214                                       ,p_comp_obj_tree_row.par_pgm_id)
4215                   ,p_pl_id             => p_pl_id
4216                   ,p_oipl_id           => NVL(p_oipl_id
4217                                            ,l_oiplip_rec.oipl_id)
4218                   ,p_business_group_id => p_business_group_id
4219                   ,p_returned_date     => l_start_date
4220                   ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4221                   ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date));
4222                   --
4223                   run_rule(p_formula_id => l_rate_cvg_rec.los_calc_rl
4224                   ,p_empasg_row        => p_empasg_row
4225                   ,p_benasg_row        => p_benasg_row
4226                   ,p_pil_row           => p_pil_row
4227                   ,p_curroipl_row      => p_curroipl_row
4228                   ,p_curroiplip_row    => p_curroiplip_row
4229                   ,p_effective_date    => p_effective_date
4230                   ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4231                   ,p_business_group_id => p_business_group_id
4232                   ,p_person_id         => p_person_id
4233                   ,p_pgm_id            => p_pgm_id
4234                   ,p_pl_id             => p_pl_id
4235                   ,p_oipl_id           => NVL(p_oipl_id
4236                                       ,l_oiplip_rec.oipl_id)
4237                   ,p_oiplip_id         => p_oiplip_id
4238                   ,p_plip_id           => p_plip_id
4239                   ,p_ptip_id           => p_ptip_id
4240                   ,p_ret_date          => l_dummy_date
4241                   ,p_ret_val           => l_rate_cvg_result);
4242                   --
4243                   -- Round value if rounding needed
4244                   --
4245                  IF    l_rate_cvg_rec.rndg_cd IS NOT NULL
4246                      OR l_rate_cvg_rec.rndg_rl IS NOT NULL THEN
4247                     --
4248                     l_rate_cvg_result  :=
4249                       benutils.do_rounding(p_rounding_cd=> l_rate_cvg_rec.rndg_cd
4250                        ,p_rounding_rl    => l_rate_cvg_rec.rndg_rl
4251                        ,p_value          => l_rate_cvg_result
4252                        ,p_effective_date => NVL(g_fonm_cvg_strt_dt,
4253                                               NVL(p_lf_evt_ocrd_dt,p_effective_date)));
4254                         --
4255                  END IF;
4256                  --
4257                ELSE -- l_rate_rec.los_calc_rl
4258                  --
4259                  l_rate_cvg_result  :=
4260                    los_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4261                     ,p_empasg_row        => p_empasg_row
4262                     ,p_benasg_row        => p_benasg_row
4263                     ,p_pil_row           => p_pil_row
4264                     ,p_curroipl_row      => p_curroipl_row
4265                     ,p_curroiplip_row    => p_curroiplip_row
4266                     ,p_rec               => l_rate_cvg_rec
4267                     ,p_comp_rec          => p_comp_rec
4268                     ,p_effective_date    => p_effective_date
4269                     ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4270                     ,p_business_group_id => p_business_group_id
4271                     ,p_person_id         => p_person_id
4272                     ,p_pgm_id            => p_pgm_id
4273                     ,p_pl_id             => p_pl_id
4274                     ,p_oipl_id           => p_oipl_id
4275                     ,p_oiplip_id         => p_oiplip_id
4276                     ,p_plip_id           => p_plip_id
4277                     ,p_ptip_id           => p_ptip_id
4278                     ,p_subtract_date     => l_subtract_date
4279                     ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt) ;
4280                  --
4281                  IF l_rate_cvg_result is not null THEN
4282                    --
4283                    -- RCHASE added old and new values
4284                    ben_derive_part_and_rate_cvg.get_los_rate(p_pl_id=> p_pl_id
4285                                                 ,p_oipl_id           => p_oipl_id
4286                                                 ,p_plip_id           => p_plip_id
4287                                                 ,p_business_group_id => p_business_group_id
4288                                                 ,p_new_val           => l_rate_cvg_result
4289                                                 ,p_old_val           => p_comp_rec.rt_los_val
4290                                                 ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,
4291                                                                         l_effective_date)
4292                                                 ,p_rec               => l_rate_cvg_rec);
4293                    --
4294                    ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
4295                    --
4296                    -- BUG: 3962514: Corrected the parameter below from l_rate_result to l_rate_cvg_rec
4297                    min_max_breach
4298                      (p_calculate_only_mode => p_calculate_only_mode
4299                      ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4300                      ,p_curroiplip_row      => p_curroiplip_row
4301                      ,p_person_id           => p_person_id
4302                      ,p_pgm_id              => p_pgm_id
4303                      ,p_pl_id               => p_pl_id
4304                      ,p_oipl_id             => p_oipl_id
4305                      ,p_oiplip_id           => p_oiplip_id
4306                      ,p_plip_id             => p_plip_id
4307                      ,p_ptip_id             => p_ptip_id
4308                      ,p_business_group_id   => p_business_group_id
4309                      ,p_ler_id              => l_der_cvg_rec.drvdlos_id
4310                      ,p_min_value           => l_rate_cvg_rec.mn_los_num
4311                      ,p_max_value           => l_rate_cvg_rec.mx_los_num
4312                      ,p_new_value           => l_rate_cvg_result
4313                      ,p_old_value           => p_comp_rec.rt_los_val
4314                      ,p_uom                 => l_rate_cvg_rec.los_uom
4315                      ,p_subtract_date       => l_subtract_date
4316                      ,p_det_cd              => l_rate_cvg_rec.los_det_cd
4317                      ,p_formula_id          => l_rate_cvg_rec.los_det_rl
4318                      ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4319                      ,p_effective_date      => p_effective_date
4320                      );
4321                     --
4322                  END IF ; -- l_rate_cvg_result
4323                  --
4324                END IF ; --   l_rate_rec.los_calc_rl
4325                --
4326              END IF ; -- l_rate_cvg_rec.exist
4327 
4328              --
4329              ben_derive_part_and_rate_prem.get_los_rate(
4330                   p_pl_id             => p_pl_id
4331                  ,p_oipl_id           => p_oipl_id
4332                  ,p_business_group_id => p_business_group_id
4333                  ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
4334                  ,p_rec               => l_rate_prem_rec);
4335                --
4336              IF l_rate_prem_rec.exist = 'Y' THEN
4337                --
4338                l_prem  := TRUE;
4339                -- los based on los_calc_rl takes precedence
4340                IF l_rate_prem_rec.los_calc_rl IS NOT NULL THEN
4341                  --
4342                  ben_determine_date.main(p_date_cd=> l_rate_prem_rec.los_det_cd
4343                   ,p_formula_id        => l_rate_prem_rec.los_det_rl
4344                   ,p_person_id         => p_person_id
4345                   ,p_pgm_id            => NVL(p_pgm_id
4346                                            ,p_comp_obj_tree_row.par_pgm_id)
4347                   ,p_pl_id             => p_pl_id
4348                   ,p_oipl_id           => NVL(p_oipl_id
4349                                            ,l_oiplip_rec.oipl_id)
4350                   ,p_business_group_id => p_business_group_id
4351                   ,p_returned_date     => l_start_date
4352                   ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4353                   ,p_effective_date    => NVL(p_lf_evt_ocrd_dt ,p_effective_date));
4354                  --
4355                  run_rule(p_formula_id => l_rate_prem_rec.los_calc_rl
4356                   ,p_empasg_row        => p_empasg_row
4357                   ,p_benasg_row        => p_benasg_row
4358                   ,p_pil_row           => p_pil_row
4359                   ,p_curroipl_row      => p_curroipl_row
4360                   ,p_curroiplip_row    => p_curroiplip_row
4361                   ,p_effective_date    => p_effective_date
4362                   ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4363                   ,p_business_group_id => p_business_group_id
4364                   ,p_person_id         => p_person_id
4365                   ,p_pgm_id            => p_pgm_id
4366                   ,p_pl_id             => p_pl_id
4367                   ,p_oipl_id           => NVL(p_oipl_id
4368                                       ,l_oiplip_rec.oipl_id)
4369                   ,p_oiplip_id         => p_oiplip_id
4370                   ,p_plip_id           => p_plip_id
4371                   ,p_ptip_id           => p_ptip_id
4372                   ,p_ret_date          => l_dummy_date
4373                   ,p_ret_val           => l_rate_prem_result);
4374                  --
4375                  -- Round value if rounding needed
4376                  --
4377                  IF    l_rate_prem_rec.rndg_cd IS NOT NULL
4378                  OR l_rate_prem_rec.rndg_rl IS NOT NULL THEN
4379                    --
4380                    l_rate_prem_result  :=
4381                      benutils.do_rounding(p_rounding_cd=> l_rate_prem_rec.rndg_cd
4382                       ,p_rounding_rl    => l_rate_prem_rec.rndg_rl
4383                       ,p_value          => l_rate_prem_result
4384                       ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4385                                             ,p_effective_date)));
4386                    --
4387                  END IF;
4388                  --
4389                ELSE -- l_rate_prem_rec.los_calc_rl
4390                  --
4391                  l_rate_prem_result  :=
4392                     los_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4393                    ,p_empasg_row        => p_empasg_row
4394                    ,p_benasg_row        => p_benasg_row
4395                    ,p_pil_row           => p_pil_row
4396                    ,p_curroipl_row      => p_curroipl_row
4397                    ,p_curroiplip_row    => p_curroiplip_row
4398                    ,p_rec               => l_rate_prem_rec
4399                    ,p_comp_rec          => p_comp_rec
4400                    ,p_effective_date    => p_effective_date
4401                    ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4402                    ,p_business_group_id => p_business_group_id
4403                    ,p_person_id         => p_person_id
4404                    ,p_pgm_id            => p_pgm_id
4405                    ,p_pl_id             => p_pl_id
4406                    ,p_oipl_id           => p_oipl_id
4407                    ,p_oiplip_id         => p_oiplip_id
4408                    ,p_plip_id           => p_plip_id
4409                    ,p_ptip_id           => p_ptip_id
4410                    ,p_subtract_date     => l_subtract_date
4411                    ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
4412                  --
4413                  IF l_rate_prem_result is not null THEN
4414                    --
4415                    ben_derive_part_and_rate_prem.get_los_rate(p_pl_id=> p_pl_id
4416                      ,p_oipl_id           => p_oipl_id
4417                      ,p_business_group_id => p_business_group_id
4418                      ,p_new_val           => l_rate_prem_result
4419                      ,p_old_val           => p_comp_rec.rt_los_val
4420                      ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,l_effective_date)
4421                      ,p_rec               => l_rate_prem_rec);
4422                    --
4423                    ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
4424                    --
4425                    min_max_breach
4426                      (p_calculate_only_mode => p_calculate_only_mode
4427                      ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4428                      ,p_curroiplip_row      => p_curroiplip_row
4429                      ,p_person_id           => p_person_id
4430                      ,p_pgm_id              => p_pgm_id
4431                      ,p_pl_id               => p_pl_id
4432                      ,p_oipl_id             => p_oipl_id
4433                      ,p_oiplip_id           => p_oiplip_id
4434                      ,p_plip_id             => p_plip_id
4435                      ,p_ptip_id             => p_ptip_id
4436                      ,p_business_group_id   => p_business_group_id
4437                      ,p_ler_id              => l_der_prem_rec.drvdlos_id
4438                      ,p_min_value           => l_rate_prem_rec.mn_los_num
4439                      ,p_max_value           => l_rate_prem_rec.mx_los_num
4440                      ,p_new_value           => l_rate_prem_result
4441                      ,p_old_value           => p_comp_rec.rt_los_val
4442                      ,p_uom                 => l_rate_prem_rec.los_uom
4443                      ,p_subtract_date       => l_subtract_date
4444                      ,p_det_cd              => l_rate_prem_rec.los_det_cd
4445                      ,p_formula_id          => l_rate_prem_rec.los_det_rl
4446                      ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4447                      ,p_effective_date      => p_effective_date
4448                      );
4449                    --
4450                  END IF; -- l_rate_prem_result
4451                  --
4452                END IF; -- l_rate_prem_rec.los_calc_rl
4453                --
4454              END IF; -- l_rate_prem_rec.exist
4455              --
4456            END IF; -- p_oipl_id
4457            --
4458            IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
4459              --
4460              p_comp_rec.rt_los_val  := NULL;
4461              p_comp_rec.rt_los_uom  := NULL;
4462              --
4463            ELSIF l_rate_result is NOT NULL THEN
4464              --hr_utility.set_location(' Step 28',10);
4465              p_comp_rec.rt_los_val  := l_rate_result;
4466              p_comp_rec.rt_los_uom  := l_rate_rec.los_uom;
4467              --
4468            ELSIF l_rate_cvg_result is NOT NULL then
4469              --
4470              p_comp_rec.rt_los_val  := l_rate_cvg_result;
4471              p_comp_rec.rt_los_uom  := l_rate_cvg_rec.los_uom;
4472              --hr_utility.set_location(' Step 29',10);
4473            ELSIF l_rate_prem_result is NOT NULL THEN
4474              --
4475              p_comp_rec.rt_los_val  := l_rate_prem_result;
4476              p_comp_rec.rt_los_uom  := l_rate_prem_rec.los_uom;
4477              --hr_utility.set_location(' Step 30',10);
4478            END IF;
4479            --
4480            --hr_utility.set_location(' Step 31',10);
4481          END IF;  -- p_age_fctr_id
4482 --
4483       --
4484       END IF;
4485     --
4486     END IF;
4487     --
4488    -- hr_utility.set_location('Leaving ' || l_package,10);
4489   --
4490   END calculate_los;
4491 --
4492 -- Calculate AGE
4493 --
4494   PROCEDURE calculate_age
4495     (p_calculate_only_mode in     boolean default false
4496     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
4497     ,p_per_row             IN     per_all_people_f%ROWTYPE
4498     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
4499     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
4500     ,p_pil_row             IN     ben_per_in_ler%ROWTYPE
4501     ,p_curroipl_row        IN     ben_cobj_cache.g_oipl_inst_row
4502     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
4503     ,p_person_id           IN     NUMBER
4504     ,p_business_group_id   IN     NUMBER
4505     ,p_pgm_id              IN     NUMBER
4506     ,p_pl_id               IN     NUMBER
4507     ,p_oipl_id             IN     NUMBER
4508     ,p_plip_id             IN     NUMBER
4509     ,p_ptip_id             IN     NUMBER
4510     ,p_oiplip_id           IN     NUMBER
4511     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
4512     ,p_age_fctr_id         IN     NUMBER DEFAULT NULL
4513     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
4514     ,p_effective_date      IN     DATE
4515     ,p_lf_evt_ocrd_dt      IN     DATE
4516     )
4517   IS
4518     --
4519     l_package       VARCHAR2(80)              := g_package || '.calculate_age';
4520     l_rate_result   NUMBER;
4521     l_rate_cvg_result NUMBER;
4522     l_rate_prem_result NUMBER;
4523     l_elig_result   NUMBER;
4524     l_subtract_date DATE;
4525     l_elig_rec      ben_derive_part_and_rate_cache.g_cache_age_rec_obj;
4526     l_rate_rec      ben_derive_part_and_rate_cache.g_cache_age_rec_obj;
4527     l_rate_cvg_rec  ben_derive_part_and_rate_cache.g_cache_age_rec_obj;
4528     l_rate_prem_rec ben_derive_part_and_rate_cache.g_cache_age_rec_obj;
4529     l_der_rec       ben_seeddata_object.g_derived_factor_info_rec;
4530     l_der_cvg_rec   ben_seeddata_object.g_derived_factor_info_rec;
4531     l_der_prem_rec  ben_seeddata_object.g_derived_factor_info_rec;
4532     l_rate          BOOLEAN                                          := FALSE;
4533     l_cvg           BOOLEAN                                          := FALSE;
4534     l_prem          BOOLEAN                                          := FALSE;
4535     l_age_val       number;
4536   --
4537   BEGIN
4538     --
4539     if g_debug then
4540       hr_utility.set_location('Entering ' || l_package,10);
4541     end if;
4542     if g_debug then
4543       hr_utility.set_location('Start p_oipl_id '||p_oipl_id,15);
4544     end if;
4545     if g_debug then
4546       hr_utility.set_location('Start p_plip_id'||p_plip_id,15);
4547     end if;
4548     if g_debug then
4549       hr_utility.set_location('Start p_ptip_id'||p_ptip_id,15);
4550     end if;
4551     if g_debug then
4552       hr_utility.set_location('Start p_oiplip_id'||p_oiplip_id,15);
4553     end if;
4554     if g_debug then
4555       hr_utility.set_location('Start p_pl_id '||p_pl_id,15);
4556     end if;
4557     if g_debug then
4558       hr_utility.set_location('Start p_pgm_id '||p_pgm_id,15);
4559     end if;
4560     if g_debug then
4561       hr_utility.set_location('p_age_fctr_id '||p_age_fctr_id,15);
4562     end if;
4563 
4564 --
4565 -- Calculate AGE process
4566 -- =====================
4567 -- This process will calculate the AGE value for rates and eligibility.
4568 -- The sequence of operations is as follows :
4569 -- 1) First check if freeze AGE flag is on in which case
4570 --    we ignore the calculation and just return the frozen values
4571 -- 2) Check for eligibility derivable factors
4572 -- 3) Check for rate derivable factors
4573 -- 4) Perform rounding
4574 -- 5) Test for min/max breach
4575 -- 6) If a breach did occur then create a ptl_ler_for_per.
4576 --
4577     IF    bitand(p_comp_obj_tree_row.flag_bit_val
4578            ,ben_manage_life_events.g_age_flag) <> 0
4579        OR     p_age_fctr_id IS NOT NULL
4580           AND bitand(p_comp_obj_tree_row.flag_bit_val
4581                ,ben_manage_life_events.g_cal_flag) <> 0 THEN
4582       --
4583       --hr_utility.set_location('AGE for ELIG',10);
4584       IF p_comp_rec.frz_age_flag = 'Y' THEN
4585         --
4586         -- No calulation required just return the frozen value
4587         --
4588         NULL;
4589       --
4590       ELSE
4591         --
4592         -- OK we have to calculate the AGE value
4593         -- so go and grab the values from the ben_age_fctr table
4594         --
4595         IF p_age_fctr_id IS NOT NULL THEN
4596           --
4597           ben_derive_part_and_rate_cache.get_age_stated(p_age_fctr_id=> p_age_fctr_id
4598            ,p_business_group_id => p_business_group_id
4599            ,p_rec               => l_elig_rec);
4600         --
4601         ELSE
4602           --
4603           ben_derive_part_and_rate_cache.get_age_elig(p_pgm_id=> p_pgm_id
4604            ,p_pl_id             => p_pl_id
4605            ,p_oipl_id           => p_oipl_id
4606            ,p_plip_id           => p_plip_id
4607            ,p_ptip_id           => p_ptip_id
4608            ,p_business_group_id => p_business_group_id
4609            ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4610                                     ,p_effective_date))
4611            ,p_rec               => l_elig_rec);
4612         --
4613         END IF;
4614         --
4615         --hr_utility.set_location('EREX=Y ' || l_package,10);
4616         IF l_elig_rec.exist = 'Y' THEN
4617           --
4618           l_elig_result  :=
4619             age_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4620              ,p_per_row           => p_per_row
4621              ,p_empasg_row        => p_empasg_row
4622              ,p_benasg_row        => p_benasg_row
4623              ,p_pil_row           => p_pil_row
4624              ,p_curroipl_row      => p_curroipl_row
4625              ,p_curroiplip_row    => p_curroiplip_row
4626              ,p_rec               => l_elig_rec
4627              ,p_effective_date    => p_effective_date
4628              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4629              ,p_business_group_id => p_business_group_id
4630              ,p_pgm_id            => p_pgm_id
4631              ,p_person_id         => p_person_id
4632              ,p_pl_id             => p_pl_id
4633              ,p_oipl_id           => p_oipl_id
4634              ,p_oiplip_id         => p_oiplip_id
4635              ,p_plip_id           => p_plip_id
4636              ,p_ptip_id           => p_ptip_id
4637              ,p_subtract_date     => l_subtract_date
4638              ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
4639           --
4640           IF     l_elig_result IS NOT NULL
4641              AND p_age_fctr_id IS NULL THEN
4642             --
4643             l_age_val         := p_comp_rec.age_val;
4644             Loop
4645               g_lf_evt_exists   := false;
4646               ben_derive_part_and_rate_cache.get_age_elig(p_pgm_id=> p_pgm_id
4647                ,p_pl_id             => p_pl_id
4648                ,p_oipl_id           => p_oipl_id
4649                ,p_plip_id           => p_plip_id
4650                ,p_ptip_id           => p_ptip_id
4651                ,p_new_val           => l_elig_result
4652                ,p_old_val           => l_age_val
4653                ,p_business_group_id => p_business_group_id
4654                ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4655                                         ,p_effective_date))
4656                ,p_rec               => l_elig_rec);
4657         --
4658 
4659             ben_seeddata_object.get_object(p_rec=> l_der_rec);
4660             --
4661     --          IF    l_elig_rec.age_to_use_cd = 'P'
4662     --             OR l_elig_rec.age_calc_rl IS NOT NULL THEN
4663               --
4664                 min_max_breach
4665                   (p_calculate_only_mode => p_calculate_only_mode
4666                   ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4667                   ,p_curroiplip_row      => p_curroiplip_row
4668                   ,p_person_id           => p_person_id
4669                   ,p_pgm_id              => p_pgm_id
4670                   ,p_pl_id               => p_pl_id
4671                   ,p_oipl_id             => p_oipl_id
4672                   ,p_oiplip_id           => p_oiplip_id
4673                   ,p_plip_id             => p_plip_id
4674                   ,p_ptip_id             => p_ptip_id
4675                   ,p_business_group_id   => p_business_group_id
4676                   ,p_ler_id              => l_der_rec.drvdage_id
4677                   ,p_min_value           => l_elig_rec.mn_age_num
4678                   ,p_max_value           => l_elig_rec.mx_age_num
4679                   ,p_new_value           => l_elig_result
4680                   ,p_old_value           => l_age_val
4681                   ,p_uom                 => l_elig_rec.age_uom
4682                   ,p_subtract_date       => l_subtract_date
4683                   ,p_det_cd              => l_elig_rec.age_det_cd
4684                   ,p_formula_id          => l_elig_rec.age_det_rl
4685                   ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4686                   ,p_effective_date      => p_effective_date
4687                   );
4688               --
4689    --           END IF;
4690             --
4691               if not g_lf_evt_exists or l_age_val = l_elig_rec.mn_age_num or
4692                     l_elig_rec.mn_age_num is null then
4693                    exit;
4694               else
4695                    l_age_val := l_elig_rec.mn_age_num;
4696               end if;
4697             End Loop;
4698             g_lf_evt_exists := false;
4699 
4700             p_comp_rec.age_val  := l_elig_result;
4701             p_comp_rec.age_uom  := l_elig_rec.age_uom;
4702           --
4703           ELSIF l_elig_result IS NULL THEN
4704             --
4705             -- Bug 4708
4706             --
4707             p_comp_rec.age_val  := NULL;
4708             p_comp_rec.age_uom  := NULL;
4709           --
4710           ELSE
4711             --
4712             p_comp_rec.age_val  := l_elig_result;
4713             p_comp_rec.age_uom  := l_elig_rec.age_uom;
4714           --
4715           END IF;
4716         --
4717         ELSE
4718           --
4719           p_comp_rec.age_val  := NULL;
4720           p_comp_rec.age_uom  := NULL;
4721         --
4722         END IF;
4723       --
4724       END IF;
4725     --
4726     END IF;
4727     --
4728     hr_utility.set_location('Plip_id '||p_plip_id,9);
4729     hr_utility.set_location('age_val ' || p_comp_rec.age_val,10);
4730     --
4731     --
4732     IF    bitand(p_comp_obj_tree_row.flag_bit_val
4733            ,ben_manage_life_events.g_age_rt_flag) <> 0
4734        OR     p_age_fctr_id IS NOT NULL
4735           AND bitand(p_comp_obj_tree_row.flag_bit_val
4736                ,ben_manage_life_events.g_cal_rt_flag) <> 0
4737        OR     p_oiplip_id IS NOT NULL
4738           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
4739                ,ben_manage_life_events.g_age_rt_flag) <> 0 THEN
4740       --
4741       --hr_utility.set_location('AGE for RT',10);
4742       IF p_comp_rec.rt_frz_age_flag = 'Y' THEN
4743         --
4744         -- No calulation required just return the frozen value
4745          --hr_utility.set_location(' rt_frz_age_flag '||p_comp_rec.rt_frz_age_flag ,22);
4746         --
4747         NULL;
4748       --
4749       ELSE
4750         --
4751         IF p_age_fctr_id IS NOT NULL THEN
4752           --
4753           --hr_utility.set_location(' p_age_fctr_id '||p_age_fctr_id,23);
4754           ben_derive_part_and_rate_cache.get_age_stated(p_age_fctr_id=> p_age_fctr_id
4755            ,p_business_group_id => p_business_group_id
4756            ,p_rec               => l_rate_rec);
4757         --
4758         ELSE
4759           --
4760           if g_debug then
4761             hr_utility.set_location('Getting Age for Rate',10);
4762           end if;
4763           --
4764           ben_derive_part_and_rate_cache.get_age_rate(p_pgm_id=> p_pgm_id
4765            ,p_pl_id             => p_pl_id
4766            ,p_oipl_id           => p_oipl_id
4767            ,p_plip_id           => p_plip_id
4768            ,p_ptip_id           => p_ptip_id
4769            ,p_oiplip_id         => p_oiplip_id
4770            ,p_business_group_id => p_business_group_id
4771            ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4772                                     ,p_effective_date))
4773            ,p_rec               => l_rate_rec);
4774           --
4775            --hr_utility.set_location(' Rate l_rate_rec.exist '||l_rate_rec.exist,33);
4776           IF l_rate_rec.exist = 'Y' THEN
4777             --
4778             --hr_utility.set_location(' l_rate_rec.exist true ' , 34);
4779             l_rate  := TRUE;
4780 
4781             l_rate_result  :=
4782             age_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4783              ,p_per_row           => p_per_row
4784              ,p_empasg_row        => p_empasg_row
4785              ,p_benasg_row        => p_benasg_row
4786              ,p_pil_row           => p_pil_row
4787              ,p_curroipl_row      => p_curroipl_row
4788              ,p_curroiplip_row    => p_curroiplip_row
4789              ,p_rec               => l_rate_rec
4790              ,p_effective_date    => p_effective_date
4791              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4792              ,p_business_group_id => p_business_group_id
4793              ,p_person_id         => p_person_id
4794              ,p_pgm_id            => p_pgm_id
4795              ,p_pl_id             => p_pl_id
4796              ,p_oipl_id           => p_oipl_id
4797              ,p_oiplip_id         => p_oiplip_id
4798              ,p_plip_id           => p_plip_id
4799              ,p_ptip_id           => p_ptip_id
4800              ,p_subtract_date     => l_subtract_date
4801              ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
4802 
4803              --hr_utility.set_location(' Step 10 ',10);
4804              --
4805              IF l_rate_result is not null THEN
4806                --
4807                --hr_utility.set_location(' Step 11',10 );
4808                ben_derive_part_and_rate_cache.get_age_rate(
4809                   p_pgm_id            => p_pgm_id
4810                  ,p_pl_id             => p_pl_id
4811                  ,p_oipl_id           => p_oipl_id
4812                  ,p_plip_id           => p_plip_id
4813                  ,p_ptip_id           => p_ptip_id
4814                  ,p_oiplip_id         => p_oiplip_id
4815                  ,p_new_val           => l_rate_result
4816                  ,p_old_val           => p_comp_rec.rt_age_val
4817                  ,p_business_group_id => p_business_group_id
4818                  ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4819                                         ,p_effective_date))
4820                  ,p_rec               => l_rate_rec);
4821                --
4822            --    IF    l_rate_rec.age_to_use_cd = 'P'
4823            --       OR l_elig_rec.age_calc_rl IS NOT NULL THEN
4824                  --
4825                  ben_seeddata_object.get_object(p_rec=> l_der_rec);
4826                  --
4827                  --hr_utility.set_location(' Step 12 ',10 );
4828                  min_max_breach
4829                    (p_calculate_only_mode => p_calculate_only_mode
4830                    ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4831                    ,p_curroiplip_row      => p_curroiplip_row
4832                    ,p_person_id           => p_person_id
4833                    ,p_pgm_id              => p_pgm_id
4834                    ,p_pl_id               => p_pl_id
4835                    ,p_oipl_id             => p_oipl_id
4836                    ,p_oiplip_id           => p_oiplip_id
4837                    ,p_plip_id             => p_plip_id
4838                    ,p_ptip_id             => p_ptip_id
4839                    ,p_business_group_id   => p_business_group_id
4840                    ,p_ler_id              => l_der_rec.drvdage_id
4841                    ,p_min_value           => l_rate_rec.mn_age_num
4842                    ,p_max_value           => l_rate_rec.mx_age_num
4843                    ,p_new_value           => l_rate_result
4844                    ,p_old_value           => p_comp_rec.rt_age_val
4845                    ,p_uom                 => l_rate_rec.age_uom
4846                    ,p_subtract_date       => l_subtract_date
4847                    ,p_det_cd              => l_rate_rec.age_det_cd
4848                    ,p_formula_id          => l_rate_rec.age_det_rl
4849                    ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4850                    ,p_effective_date      => p_effective_date
4851                    );
4852                  --
4853             --   END IF;  -- Breach
4854                --
4855                --p_comp_rec.rt_age_val  := l_rate_result;
4856                --p_comp_rec.rt_age_uom  := l_rate_rec.age_uom;
4857                --hr_utility.set_location(' Step 13 ',10);
4858                --
4859              END IF; -- l_rate_result
4860              --hr_utility.set_location(' Step 14 ',10 );
4861             --
4862           END IF ;  --l_rate_rec.exist
4863           --
4864           --hr_utility.set_location(' Step 15 ',10 );
4865           -- Try and find a coverage first
4866           --
4867           IF    p_oipl_id IS NOT NULL
4868             OR p_pl_id IS NOT NULL
4869             OR p_plip_id IS NOT NULL THEN
4870               --
4871               --hr_utility.set_location('Getting Age for CVG',10);
4872               --
4873               ben_derive_part_and_rate_cvg.get_age_rate(
4874                 p_pl_id             => p_pl_id
4875                ,p_oipl_id           => p_oipl_id
4876                ,p_plip_id           => p_plip_id
4877                ,p_business_group_id => p_business_group_id
4878                ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4879                                         ,p_effective_date))
4880                ,p_rec               => l_rate_cvg_rec);
4881               --
4882             IF l_rate_cvg_rec.exist = 'Y' THEN
4883               --
4884               --hr_utility.set_location(' Step 16 ',10 );
4885               l_cvg  := TRUE;
4886               l_rate_cvg_result  :=
4887             	age_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4888                 ,p_per_row           => p_per_row
4889              	,p_empasg_row        => p_empasg_row
4890                 ,p_benasg_row        => p_benasg_row
4891                 ,p_pil_row           => p_pil_row
4892                 ,p_curroipl_row      => p_curroipl_row
4893                 ,p_curroiplip_row    => p_curroiplip_row
4894                 ,p_rec               => l_rate_cvg_rec
4895                 ,p_effective_date    => p_effective_date
4896                 ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4897                 ,p_business_group_id => p_business_group_id
4898                 ,p_person_id         => p_person_id
4899                 ,p_pgm_id            => p_pgm_id
4900                 ,p_pl_id             => p_pl_id
4901                 ,p_oipl_id           => p_oipl_id
4902                 ,p_oiplip_id         => p_oiplip_id
4903                 ,p_plip_id           => p_plip_id
4904                 ,p_ptip_id           => p_ptip_id
4905                 ,p_subtract_date     => l_subtract_date
4906                 ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt );
4907 
4908               --
4909               IF l_rate_cvg_result is not null THEN
4910                 --
4911                 --hr_utility.set_location(' Step 17' ,10);
4912                 ben_derive_part_and_rate_cvg.get_age_rate(
4913                   p_pl_id             => p_pl_id
4914                  ,p_oipl_id           => p_oipl_id
4915                  ,p_plip_id           => p_plip_id
4916                  ,p_business_group_id => p_business_group_id
4917                  ,p_new_val           => l_rate_cvg_result
4918                  ,p_old_val           => p_comp_rec.rt_age_val
4919                  ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,
4920                                             NVL(p_lf_evt_ocrd_dt ,p_effective_date))
4921                  ,p_rec               => l_rate_cvg_rec );
4922                 --
4923         --        IF    l_rate_cvg_rec.age_to_use_cd = 'P'
4924         --            OR l_elig_rec.age_calc_rl IS NOT NULL THEN
4925                   --
4926                   ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
4927                   --
4928                   --hr_utility.set_location(' Step 18' , 10);
4929                   min_max_breach
4930                      (p_calculate_only_mode => p_calculate_only_mode
4931                      ,p_comp_obj_tree_row   => p_comp_obj_tree_row
4932                      ,p_curroiplip_row      => p_curroiplip_row
4933                      ,p_person_id           => p_person_id
4934                      ,p_pgm_id              => p_pgm_id
4935                      ,p_pl_id               => p_pl_id
4936                      ,p_oipl_id             => p_oipl_id
4937                      ,p_oiplip_id           => p_oiplip_id
4938                      ,p_plip_id             => p_plip_id
4939                      ,p_ptip_id             => p_ptip_id
4940                      ,p_business_group_id   => p_business_group_id
4941                      ,p_ler_id              => l_der_cvg_rec.drvdage_id
4942                      ,p_min_value           => l_rate_cvg_rec.mn_age_num
4943                      ,p_max_value           => l_rate_cvg_rec.mx_age_num
4944                      ,p_new_value           => l_rate_cvg_result
4945                      ,p_old_value           => p_comp_rec.rt_age_val
4946                      ,p_uom                 => l_rate_cvg_rec.age_uom
4947                      ,p_subtract_date       => l_subtract_date
4948                      ,p_det_cd              => l_rate_cvg_rec.age_det_cd
4949                      ,p_formula_id          => l_rate_cvg_rec.age_det_rl
4950                      ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
4951                      ,p_effective_date      => p_effective_date
4952                      );
4953                  --
4954          --      END IF;  -- Breach
4955                --
4956                -- p_comp_rec.rt_age_val  := l_rate_cvg_result;
4957                -- p_comp_rec.rt_age_uom  := l_rate_cvg_rec.age_uom;
4958                --hr_utility.set_location(' Step 19',10);
4959 
4960               END IF ; -- l_rate_cvg_result
4961               --
4962               --hr_utility.set_location(' Step 20',10);
4963             END IF; --l_rate_cvg_rec.exist
4964             --
4965             -- Try and find a premium
4966             --
4967             --hr_utility.set_location('Getting Age for Prem',10);
4968             ben_derive_part_and_rate_prem.get_age_rate(
4969                   p_pl_id             => p_pl_id
4970                  ,p_oipl_id           => p_oipl_id
4971                  ,p_business_group_id => p_business_group_id
4972                  ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
4973                                           ,p_effective_date))
4974                  ,p_rec               => l_rate_prem_rec);
4975                 --
4976               IF l_rate_prem_rec.exist = 'Y' THEN
4977                 --
4978                 l_prem  := TRUE;
4979                 --
4980                 --hr_utility.set_location(' Step 21',10);
4981                 l_rate_prem_result  :=
4982                   age_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
4983                    ,p_per_row           => p_per_row
4984                    ,p_empasg_row        => p_empasg_row
4985                    ,p_benasg_row        => p_benasg_row
4986                    ,p_pil_row           => p_pil_row
4987                    ,p_curroipl_row      => p_curroipl_row
4988                    ,p_curroiplip_row    => p_curroiplip_row
4989                    ,p_rec               => l_rate_prem_rec
4990                    ,p_effective_date    => p_effective_date
4991                    ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
4992                    ,p_business_group_id => p_business_group_id
4993                    ,p_person_id         => p_person_id
4994                    ,p_pgm_id            => p_pgm_id
4995                    ,p_pl_id             => p_pl_id
4996                    ,p_oipl_id           => p_oipl_id
4997                    ,p_oiplip_id         => p_oiplip_id
4998                    ,p_plip_id           => p_plip_id
4999                    ,p_ptip_id           => p_ptip_id
5000                    ,p_subtract_date     => l_subtract_date
5001                    ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
5002                  --
5003                  --hr_utility.set_location('  l_rate_prem_result '||l_rate_prem_result ,123);
5004                  --
5005                  IF l_rate_prem_result is not null THEN
5006                  --
5007                    --hr_utility.set_location(' in l_prem ' ,133);
5008                    ben_derive_part_and_rate_prem.get_age_rate(
5009                      p_pl_id             => p_pl_id
5010                     ,p_oipl_id           => p_oipl_id
5011                     ,p_business_group_id => p_business_group_id
5012                     ,p_new_val           => l_rate_prem_result
5013                     ,p_old_val           => p_comp_rec.rt_age_val
5014                     ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,
5015                                               NVL(p_lf_evt_ocrd_dt ,p_effective_date))
5016                     ,p_rec               => l_rate_prem_rec);
5017                  --
5018          --          IF    l_rate_prem_rec.age_to_use_cd = 'P'
5019          --            OR l_elig_rec.age_calc_rl IS NOT NULL THEN
5020                      --
5021                      ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
5022                      --
5023                      --hr_utility.set_location(' Step 22',10);
5024                      min_max_breach
5025                          (p_calculate_only_mode => p_calculate_only_mode
5026                          ,p_comp_obj_tree_row   => p_comp_obj_tree_row
5027                          ,p_curroiplip_row      => p_curroiplip_row
5028                          ,p_person_id           => p_person_id
5029                          ,p_pgm_id              => p_pgm_id
5030                          ,p_pl_id               => p_pl_id
5031                          ,p_oipl_id             => p_oipl_id
5032                          ,p_oiplip_id           => p_oiplip_id
5033                          ,p_plip_id             => p_plip_id
5034                          ,p_ptip_id             => p_ptip_id
5035                          ,p_business_group_id   => p_business_group_id
5036                          ,p_ler_id              => l_der_prem_rec.drvdage_id
5037                          ,p_min_value           => l_rate_prem_rec.mn_age_num
5038                          ,p_max_value           => l_rate_prem_rec.mx_age_num
5039                          ,p_new_value           => l_rate_prem_result
5040                          ,p_old_value           => p_comp_rec.rt_age_val
5041                          ,p_uom                 => l_rate_prem_rec.age_uom
5042                          ,p_subtract_date       => l_subtract_date
5043                          ,p_det_cd              => l_rate_prem_rec.age_det_cd
5044                          ,p_formula_id          => l_rate_prem_rec.age_det_rl
5045                          ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
5046                          ,p_effective_date      => p_effective_date
5047                          );
5048                       --
5049           --          END IF;  -- Breach
5050                     --
5051                     --p_comp_rec.rt_age_val  := l_rate_prem_result;
5052                     --p_comp_rec.rt_age_uom  := l_rate_prem_rec.age_uom;
5053                     --hr_utility.set_location(' Step 23',10);
5054                     --
5055                  END IF; -- l_rate_prem_result
5056                  --
5057                  --hr_utility.set_location(' Step 24',10);
5058               END IF; -- l_rate_prem_rec.exist
5059               --
5060               --hr_utility.set_location(' Step 25',10);
5061           END IF;  -- p_oipl_id
5062           --
5063           --hr_utility.set_location(' Step 26',10);
5064           IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
5065             --
5066             p_comp_rec.rt_age_val  := NULL;
5067             p_comp_rec.rt_age_uom  := NULL;
5068             --hr_utility.set_location(' Step 27',10);
5069             --
5070           --
5071           ELSIF l_rate_result is NOT NULL THEN
5072             --
5073             --hr_utility.set_location(' Step 28',10);
5074             p_comp_rec.rt_age_val := l_rate_result;
5075             p_comp_rec.rt_age_uom  := l_rate_rec.age_uom;
5076             --
5077           --
5078           ELSIF l_rate_cvg_result is NOT NULL then
5079             --
5080             --hr_utility.set_location(' Step 29',10);
5081             p_comp_rec.rt_age_val := l_rate_cvg_result;
5082             p_comp_rec.rt_age_uom  := l_rate_cvg_rec.age_uom;
5083           --
5084           ELSIF l_rate_prem_result is NOT NULL THEN
5085             --
5086             --hr_utility.set_location(' Step 30',10);
5087             p_comp_rec.rt_age_val := l_rate_prem_result;
5088             p_comp_rec.rt_age_uom := l_rate_prem_rec.age_uom;
5089             --
5090           END IF;
5091           --
5092           --hr_utility.set_location(' Step 31',10);
5093         END IF;  -- p_age_fctr_id
5094         --
5095         --
5096         --hr_utility.set_location('Dn AF NN ' ||l_rate_rec.exist,123);
5097       --
5098       END IF;  -- p_comp_rec.rt_frz_age_flag
5099     --
5100     END IF;  -- STANDARD.bitand
5101     --
5102    if g_debug then
5103      hr_utility.set_location('Leaving ' || l_package,10);
5104    end if;
5105   --
5106   END calculate_age;
5107 --
5108   --
5109   PROCEDURE comp_level_min_max
5110     (p_calculate_only_mode in     boolean default false
5111     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
5112     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
5113     ,p_rec                 IN     ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
5114    -- ,p_rate_rec          IN OUT ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
5115    -- ,p_comp_rec          IN OUT NOCOPY g_cache_structure
5116     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
5117     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
5118     ,p_person_id           IN     NUMBER
5119     ,p_pgm_id              IN     NUMBER
5120     ,p_pl_id               IN     NUMBER
5121     ,p_oipl_id             IN     NUMBER
5122     ,p_oiplip_id           IN     NUMBER
5123     ,p_plip_id             IN     NUMBER
5124     ,p_ptip_id             IN     NUMBER
5125     ,p_business_group_id   IN     NUMBER
5126     ,p_ler_id              IN     NUMBER
5127     ,p_min_value           IN     NUMBER
5128     ,p_max_value           IN     NUMBER
5129     ,p_new_value           IN     NUMBER
5130     ,p_old_value           IN     NUMBER
5131     ,p_uom                 IN     VARCHAR2
5132     ,p_subtract_date       IN     DATE
5133     ,p_det_cd              IN     VARCHAR2
5134     ,p_formula_id          IN     NUMBER DEFAULT NULL
5135     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
5136     ,p_effective_date      IN     DATE
5137     ,p_lf_evt_ocrd_dt      IN     DATE
5138     ,p_comp_src_cd         IN     VARCHAR2
5139     ,p_bnfts_bal_id        IN     NUMBER
5140     )
5141   IS
5142     --
5143     l_package            VARCHAR2(80)        := g_package || '.comp_level_min_max';
5144     l_break              VARCHAR2(30);
5145     l_det_cd             VARCHAR2(30);
5146     l_lf_evt_ocrd_dt     DATE;
5147     l_new_lf_evt_ocrd_dt DATE;
5148     l_start_date         DATE;
5149     l_rec                ben_person_object.g_person_date_info_rec;
5150     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
5151     --
5152   BEGIN
5153       if g_debug then
5154         hr_utility.set_location('Entering comp_level_min_max ', 10 );
5155       end if;
5156       /* Bug 5478918 */
5157         if (skip_min_max_le_calc(p_ler_id,
5158 	                         p_business_group_id,
5159                                  p_ptnl_ler_trtmt_cd,
5160                                  p_effective_date)) THEN
5161         --
5162         /* Simply return as no further calculations need to be done */
5163           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
5164           RETURN;
5165         end if;
5166       /* End Bug 5478918 */
5167       if g_debug then
5168         hr_utility.set_location('p_max_value '||p_max_value,10);
5169       end if;
5170       if g_debug then
5171         hr_utility.set_location('p_min_value '||p_min_value,10);
5172       end if;
5173       if g_debug then
5174         hr_utility.set_location('p_new_value '||p_new_value,10);
5175       end if;
5176       if g_debug then
5177         hr_utility.set_location('p_old_value '||p_old_value,10);
5178       end if;
5179             --
5180             IF benutils.min_max_breach(p_min_value=> NVL(p_min_value
5181                                                       ,-1)
5182                 ,p_max_value => NVL(p_max_value
5183                                  ,99999999)
5184                 ,p_new_value => p_new_value
5185                 ,p_old_value => p_old_value
5186                 ,p_break     => l_break) THEN
5187               --
5188               -- Derive life event occured date based on the value of l_break
5189               --
5190               if g_debug then
5191                 hr_utility.set_location(' l_break '||l_break , 10);
5192               end if;
5193               --
5194               IF p_comp_src_cd = 'STTDCOMP' THEN
5195                 --
5196                 l_lf_evt_ocrd_dt  :=
5197                   get_salary_date(p_empasg_row=> p_empasg_row
5198                    ,p_benasg_row     => p_benasg_row
5199                    ,p_rec            => p_rec
5200                    ,p_person_id      => p_person_id
5201                    ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt ,p_effective_date))
5202                    ,p_min            => p_min_value
5203                    ,p_max            => p_max_value
5204                    ,p_break          => l_break);
5205                 --
5206                 if g_debug then
5207                   hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt , 20);
5208                 end if;
5209                 --
5210                 /* BUG: 4380180. IF l_lf_evt_ocrd_dt IS NULL, avoid determining the date */
5211                 IF (p_det_cd <> 'AED' AND l_lf_evt_ocrd_dt IS NOT NULL) THEN
5212                   --
5213 
5214                   ben_determine_date.main(p_date_cd=> p_det_cd
5215                    ,p_formula_id        => p_formula_id
5216                    ,p_person_id         => p_person_id
5217                    ,p_bnfts_bal_id      => p_bnfts_bal_id
5218                    ,p_pgm_id            => NVL(p_pgm_id
5219                                             ,p_comp_obj_tree_row.par_pgm_id)
5220                    ,p_pl_id             => p_pl_id
5221                    ,p_oipl_id           => NVL(p_oipl_id
5222                                             ,l_oiplip_rec.oipl_id)
5223                    ,p_business_group_id => p_business_group_id
5224                    ,p_returned_date     => l_new_lf_evt_ocrd_dt
5225                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5226                    ,p_effective_date    => l_lf_evt_ocrd_dt);
5227                   if g_debug then
5228                     hr_utility.set_location('  l_new_lf_evt_ocrd_dt '||l_new_lf_evt_ocrd_dt , 30);
5229                   end if;
5230                   --
5231                   -- The derived life event occured date must be greater than the
5232                   -- life event occured date as otherwise in reality a boundary
5233                   -- has not been passed.
5234                   -- This can only happen if the det_cd is one of the following :
5235                   -- AFDCPPY = As of first day of current program or plan year
5236                   -- APOCT1 = As of previous october 1st
5237                   -- AFDCM = As of first day of the current month
5238                   --
5239                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
5240                      AND p_det_cd IN (
5241                                                          'AFDCPPY'
5242                                                         ,'APOCT1'
5243                                                         ,'AFDCM') THEN
5244                     --
5245                     -- These are special cases where we need to rederive the LED
5246                     -- so that we are actually still passing the correct boundary
5247                     --
5248                     l_det_cd := p_det_cd ;
5249                     --
5250                     IF p_det_cd = 'APOCT1' THEN
5251                       --
5252                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
5253                                             ,12);
5254                     --
5255                     ELSIF p_det_cd = 'AFDCM' THEN
5256                       --
5257                       --l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
5258                       -- Bug 1927010. Commented the above manipulation
5259                       null ;
5260                       --
5261                     ELSIF p_det_cd = 'AFDCPPY' THEN
5262                       --
5263                       l_det_cd  := 'AFDFPPY';
5264                     --
5265                     END IF;
5266                     --
5267                     -- Reapply logic back to determination of date routine.
5268                     --
5269                     ben_determine_date.main(p_date_cd=> l_det_cd
5270                      ,p_bnfts_bal_id      => p_bnfts_bal_id
5271                      ,p_person_id         => p_person_id
5272                      ,p_pgm_id            => NVL(p_pgm_id
5273                                               ,p_comp_obj_tree_row.par_pgm_id)
5274                      ,p_pl_id             => p_pl_id
5275                      ,p_oipl_id           => NVL(p_oipl_id
5276                                               ,l_oiplip_rec.oipl_id)
5277                      ,p_business_group_id => p_business_group_id
5278                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
5279                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5280                      ,p_effective_date    => l_lf_evt_ocrd_dt);
5281                   --
5282                   END IF;
5283                   --
5284                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
5285                 --
5286                 END IF;
5287                 --
5288                 if g_debug then
5289                   hr_utility.set_location('  l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt , 40);
5290                 end if;
5291                 --
5292               ELSIF p_comp_src_cd = 'BNFTBALTYP' THEN
5293                 --
5294                 l_lf_evt_ocrd_dt  :=
5295                   get_balance_date(p_effective_date=> nvl(g_fonm_cvg_strt_dt,p_effective_date)
5296                    ,p_bnfts_bal_id   => p_bnfts_bal_id
5297                    ,p_person_id      => p_person_id
5298                    ,p_min            => p_min_value
5299                    ,p_max            => p_max_value
5300                    ,p_break          => l_break);
5301                 --
5302                 IF p_det_cd <> 'AED' THEN
5303                   --
5304                   ben_determine_date.main(p_date_cd=> p_det_cd
5305                    ,p_formula_id        => p_formula_id
5306                    ,p_person_id         => p_person_id
5307                    ,p_bnfts_bal_id      => p_bnfts_bal_id
5308                    ,p_pgm_id            => NVL(p_pgm_id
5309                                             ,p_comp_obj_tree_row.par_pgm_id)
5310                    ,p_pl_id             => p_pl_id
5311                    ,p_oipl_id           => NVL(p_oipl_id
5312                                             ,l_oiplip_rec.oipl_id)
5313                    ,p_business_group_id => p_business_group_id
5314                    ,p_returned_date     => l_new_lf_evt_ocrd_dt
5315                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5316                    ,p_effective_date    => l_lf_evt_ocrd_dt);
5317                   --
5318                   -- The derived life event occured date must be greater than the
5319                   -- life event occured date as otherwise in reality a boundary
5320                   -- has not been passed.
5321                   -- This can only happen if the det_cd is one of the following :
5322                   -- AFDCPPY = As of first day of current program or plan year
5323                   -- APOCT1 = As of previous october 1st
5324                   -- AFDCM = As of first day of the current month
5325                   --
5326                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
5327                      AND p_det_cd IN (
5328                                                          'AFDCPPY'
5329                                                         ,'APOCT1'
5330                                                         ,'AFDCM') THEN
5331                     --
5332                     -- These are special cases where we need to rederive the LED
5333                     -- so that we are actually still passing the correct boundary
5334                     --
5335                     l_det_cd := p_det_cd ;
5336                     --
5337                     IF p_det_cd = 'APOCT1' THEN
5338                       --
5339                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
5340                                             ,12);
5341                     --
5342                     ELSIF p_det_cd = 'AFDCM' THEN
5343                       --
5344                       --l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
5345                       -- Bug 1927010. Commented the above manipulation
5346                       null ;
5347                       --
5348                     ELSIF p_det_cd = 'AFDCPPY' THEN
5349                       --
5350                       l_det_cd   := 'AFDFPPY';
5351                     --
5352                     END IF;
5353                     --
5354                     -- Reapply logic back to determination of date routine.
5355                     --
5356                     ben_determine_date.main(p_date_cd=> l_det_cd
5357                      ,p_bnfts_bal_id      => p_bnfts_bal_id
5358                      ,p_person_id         => p_person_id
5359                      ,p_pgm_id            => NVL(p_pgm_id
5360                                               ,p_comp_obj_tree_row.par_pgm_id)
5361                      ,p_pl_id             => p_pl_id
5362                      ,p_oipl_id           => NVL(p_oipl_id
5363                                               ,l_oiplip_rec.oipl_id)
5364                      ,p_business_group_id => p_business_group_id
5365                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
5366                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5367                      ,p_effective_date    => l_lf_evt_ocrd_dt);
5368                   --
5369                   END IF;
5370                   --
5371                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
5372                 --
5373                 END IF;
5374               --
5375               ELSIF p_comp_src_cd = 'BALTYP' THEN
5376                 --
5377                 l_lf_evt_ocrd_dt  := p_effective_date;
5378               --
5379               END IF;
5380               --
5381               -- Check if the calculated life event occured date breaks the
5382               -- min assignment date for the person.
5383               --
5384               ben_person_object.get_object(p_person_id=> p_person_id
5385                ,p_rec       => l_rec);
5386               --
5387               if g_debug then
5388               hr_utility.set_location(' l_rec.min_ass_effective_start_date ' ||l_rec.min_ass_effective_start_date, 50);
5389               end if;
5390               if g_debug then
5391                 hr_utility.set_location(' l_lf_evt_ocrd_dt '||l_lf_evt_ocrd_dt , 51);
5392               end if;
5393               --
5394               IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
5395                 --
5396                 -- ben_seeddata_object.get_object(p_rec=> p_ler_id);
5397                 --
5398                 if g_debug then
5399                   hr_utility.set_location(' Before no_life_event ',60);
5400                 end if;
5401                 --
5402                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
5403                     ,p_person_id      => p_person_id
5404                     ,p_ler_id         => p_ler_id
5405                     ,p_effective_date => p_effective_date) THEN
5406                   --
5407                   if g_debug then
5408                     hr_utility.set_location(' No Life Event ',70);
5409                   end if;
5410                   --
5411                   IF    ( l_lf_evt_ocrd_dt < p_effective_date
5412                      AND NVL(p_ptnl_ler_trtmt_cd
5413                           ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
5414                     --
5415                     if g_debug then
5416                       hr_utility.set_location('IGNR ' , 80);
5417                     end if;
5418                     -- We are not creating past life events
5419                     --
5420                     RETURN;
5421                     --
5422                   END IF;
5423                     --
5424                     if g_debug then
5425                       hr_utility.set_location('Call create_ptl_ler ' ,90);
5426                     end if;
5427                     --
5428                     create_ptl_ler
5429                       (p_calculate_only_mode => p_calculate_only_mode
5430                       ,p_ler_id              => p_ler_id
5431                       ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
5432                       ,p_person_id           => p_person_id
5433                       ,p_business_group_id   => p_business_group_id
5434                       ,p_effective_date      => p_effective_date
5435                       );
5436                   --
5437                 END IF; -- no_life_event
5438               --
5439               END IF; -- l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date
5440             --
5441             END IF;
5442             --
5443             if g_debug then
5444               hr_utility.set_location(' Leaving comp_level_min_max ',100);
5445             end if;
5446             --
5447   END comp_level_min_max ;
5448 
5449 -- Calculate compensation level
5450 --
5451 PROCEDURE calculate_compensation_level
5452   (p_calculate_only_mode in            boolean default false
5453   ,p_comp_obj_tree_row   in            ben_manage_life_events.g_cache_proc_objects_rec
5454   ,p_empasg_row          IN            per_all_assignments_f%ROWTYPE
5455   ,p_benasg_row          IN            per_all_assignments_f%ROWTYPE
5456   ,p_pil_row             IN            ben_per_in_ler%ROWTYPE
5457   ,p_curroipl_row        IN            ben_cobj_cache.g_oipl_inst_row
5458   ,p_curroiplip_row      IN            ben_cobj_cache.g_oiplip_inst_row
5459   ,p_person_id           IN            NUMBER
5460   ,p_business_group_id   IN            NUMBER
5461   ,p_pgm_id              IN            NUMBER
5462   ,p_pl_id               IN            NUMBER
5463   ,p_oipl_id             IN            NUMBER
5464   ,p_plip_id             IN            NUMBER
5465   ,p_ptip_id             IN            NUMBER
5466   ,p_oiplip_id           IN            NUMBER
5467   ,p_ptnl_ler_trtmt_cd   IN            VARCHAR2
5468   ,p_comp_rec            IN OUT NOCOPY g_cache_structure
5469   ,p_effective_date      IN            DATE
5470   ,p_lf_evt_ocrd_dt      IN            DATE
5471   )
5472 IS
5473     --
5474     l_package            VARCHAR2(80)
5475                                := g_package || '.calculate_compensation_level';
5476     l_rate_result        NUMBER;
5477     l_rate_cvg_result    NUMBER;
5478     l_rate_prem_result   NUMBER;
5479     l_elig_result        NUMBER;
5480     l_subtract_date      DATE;
5481     l_lf_evt_ocrd_dt     DATE;
5482     l_new_lf_evt_ocrd_dt DATE;
5483     l_elig_rec           ben_derive_part_and_rate_cache.g_cache_clf_rec_obj;
5484     l_rate_rec           ben_derive_part_and_rate_cache.g_cache_clf_rec_obj;
5485     l_rate_cvg_rec       ben_derive_part_and_rate_cache.g_cache_clf_rec_obj;
5486     l_rate_prem_rec      ben_derive_part_and_rate_cache.g_cache_clf_rec_obj;
5487     l_break              VARCHAR2(30);
5488     l_ok                 BOOLEAN;
5489     l_rec                ben_person_object.g_person_date_info_rec;
5490     l_der_rec            ben_seeddata_object.g_derived_factor_info_rec;
5491     l_der_cvg_rec        ben_seeddata_object.g_derived_factor_info_rec;
5492     l_der_prem_rec       ben_seeddata_object.g_derived_factor_info_rec;
5493     l_dummy_date         DATE;
5494     l_start_date         DATE;
5495     l_rate               BOOLEAN                                     := FALSE;
5496     l_cvg                BOOLEAN                                     := FALSE;
5497     l_prem               BOOLEAN                                     := FALSE;
5498     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
5499     --BUG 3174453
5500     l_pgm_id             number(15) := p_pgm_id;
5501     l_pl_id              number(15) := p_pl_id;
5502     l_oipl_id            number(15) := p_oipl_id;
5503     --
5504     procedure get_comp_objects(p_comp_obj_tree_row in ben_manage_life_events.g_cache_proc_objects_rec,
5505                                p_ptip_id         IN number,
5506                                p_plip_id         IN number,
5507                                p_oiplip_id       IN number,
5508                                p_effective_date  IN date,
5509                                p_pgm_id      IN OUT NOCOPY number,
5510                                p_pl_id       IN OUT NOCOPY number,
5511                                p_oipl_id     IN OUT NOCOPY number) is
5512       --
5513       l_package            VARCHAR2(80)
5514                                := g_package || '.get_comp_objects';
5515       cursor c_ptip is
5516        select pgm_id
5517          from ben_ptip_f ptip
5518         where ptip.ptip_id = p_ptip_id
5519           and nvl(g_fonm_cvg_strt_dt,p_effective_date)
5520                  between ptip.effective_start_date and ptip.effective_end_date ;
5521       --
5522       cursor c_plip is
5523        select pl_id
5524          from ben_plip_f plip
5525         where plip.plip_id = p_plip_id
5526           and nvl(g_fonm_cvg_strt_dt,p_effective_date)
5527                   between plip.effective_start_date
5528                                    and plip.effective_end_date;
5529       --
5530       cursor c_oipl is
5531        select oipl_id
5532          from ben_oiplip_f oiplip
5533         where oiplip.oiplip_id = p_oiplip_id
5534           and nvl(g_fonm_cvg_strt_dt,p_effective_date)
5535                   between oiplip.effective_start_date
5536                                    and oiplip.effective_end_date;
5537       --
5538       l_pgm_id             number(15) := p_pgm_id;
5539       l_pl_id              number(15) := p_pl_id;
5540       l_oipl_id            number(15) := p_oipl_id;
5541     begin
5542       --
5543       --BUG 3174453. If we don't have pgmid,plid or oipld we need to get them
5544       --from the p_comp_obj_tree_row cache to pass to determine_compensation
5545       --in bendefct.pkb
5546       g_debug := hr_utility.debug_enabled;
5547       if g_debug then
5548         hr_utility.set_location('Entering ' || l_package,10);
5549         hr_utility.set_location('p_pgm_id '||p_pgm_id,20);
5550         hr_utility.set_location('p_pl_id  '||p_pl_id,20);
5551         hr_utility.set_location('p_oipl_id '||p_oipl_id,20);
5552         hr_utility.set_location('p_plip_id '||p_plip_id,20);
5553         hr_utility.set_location('p_ptip_id '||p_ptip_id,20);
5554         hr_utility.set_location('p_oiplip_id'||p_oiplip_id,20);
5555         hr_utility.set_location('p_comp_obj_tree_row.OIPL_ID'||p_comp_obj_tree_row.OIPL_ID,20);
5556         hr_utility.set_location('p_comp_obj_tree_row.PL_ID'||p_comp_obj_tree_row.PL_ID,20);
5557         hr_utility.set_location('p_comp_obj_tree_row.PGM_ID'||p_comp_obj_tree_row.PGM_ID,20);
5558         hr_utility.set_location('p_comp_obj_tree_row.PLIPID'||p_comp_obj_tree_row.PLIP_ID,20);
5559         hr_utility.set_location('p_comp_obj_tree_row.PTIPID'||p_comp_obj_tree_row.PTIP_ID,20);
5560         hr_utility.set_location('p_comp_obj_tree_row.OIPLIP'||p_comp_obj_tree_row.OIPLIP_ID,20);
5561         --
5562       end if;
5563       --
5564       if p_pgm_id IS NULL AND p_pl_id IS NULL AND p_oipl_id IS NULL then
5565         --
5566         if p_OIPLIP_id is NOT NULL THEN
5567           --
5568           if p_comp_obj_tree_row.OIPL_ID is NOT NULL then
5569             --
5570             l_oipl_id := p_comp_obj_tree_row.OIPL_ID;
5571             --
5572           else
5573             --
5574             open c_oipl ;
5575             fetch c_oipl into l_oipl_id;
5576             close c_oipl;
5577             --
5578           end if;
5579           --
5580         elsif p_PLIP_ID is NOT NULL THEN
5581           --
5582           if p_comp_obj_tree_row.PL_ID is NOT NULL then
5583             --
5584             l_pl_id := p_comp_obj_tree_row.PL_ID;
5585             --
5586           else
5587             --
5588             open c_plip;
5589             fetch c_plip into l_pl_id;
5590             close c_plip;
5591           end if;
5592           --
5593         elsif p_PTIP_ID is NOT NULL THEN
5594           --
5595           if p_comp_obj_tree_row.PGM_ID is NOT NULL then
5596             --
5597             l_pgm_id :=  p_comp_obj_tree_row.PGM_ID;
5598           else
5599             --
5600             open c_ptip ;
5601             fetch c_ptip into l_pgm_id;
5602             close c_ptip;
5603             --
5604           end if;
5605           --
5606         end if;
5607         --
5608       end if;
5609       --
5610       p_pgm_id := l_pgm_id ;
5611       p_pl_id  := l_pl_id;
5612       p_oipl_id:= l_oipl_id;
5613       --
5614       if g_debug then
5615         hr_utility.set_location('p_pgm_id '||p_pgm_id,20);
5616         hr_utility.set_location('p_pl_id  '||p_pl_id,20);
5617         hr_utility.set_location('p_oipl_id '||p_oipl_id,20);
5618         hr_utility.set_location('Leaving ' || l_package,10);
5619         --
5620       end if;
5621       --
5622     end get_comp_objects;
5623     --
5624   --
5625   BEGIN
5626     --
5627     if g_debug then
5628       hr_utility.set_location('Entering ' || l_package,10);
5629     end if;
5630 --
5631 -- Calculate CLVL process
5632 -- =====================
5633 -- The sequence of operations is as follows :
5634 -- 1) First check if freeze flag is on in which case
5635 --    we ignore the calculation and just return the values
5636 -- 2) Calculate eligibility derivable factors
5637 -- 3) Calculate rate derivable factors
5638 -- 4) Perform rounding
5639 -- 5) Test for min/max breach
5640 -- 6) If a breach did occur then create a ptl_ler_for_per.
5641 --
5642     IF bitand(p_comp_obj_tree_row.flag_bit_val
5643         ,ben_manage_life_events.g_cmp_flag) <> 0 THEN
5644       --
5645      -- hr_utility.set_location('COMP for ELIG',10);
5646       IF p_comp_rec.frz_cmp_lvl_flag = 'Y' THEN
5647         --
5648         -- No calulation required just return the frozen value
5649         --
5650         NULL;
5651       --
5652       ELSE
5653         --
5654         ben_derive_part_and_rate_cache.get_comp_elig(p_pgm_id=> p_pgm_id
5655          ,p_pl_id             => p_pl_id
5656          ,p_oipl_id           => p_oipl_id
5657          ,p_plip_id           => p_plip_id
5658          ,p_ptip_id           => p_ptip_id
5659          ,p_business_group_id => p_business_group_id
5660          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
5661                                   ,p_effective_date))
5662          ,p_rec               => l_elig_rec);
5663         --
5664         l_ok  := TRUE;
5665         --
5666         IF l_elig_rec.exist = 'Y' THEN
5667           -- Rule takes precedence
5668          -- hr_utility.set_location(' Elig exists ' || l_package,10);
5669           IF l_elig_rec.comp_calc_rl IS NOT NULL THEN
5670             --
5671             ben_determine_date.main(p_date_cd=> l_elig_rec.comp_lvl_det_cd
5672              ,p_formula_id        => l_elig_rec.comp_lvl_det_rl
5673              ,p_person_id         => p_person_id
5674              ,p_pgm_id            => NVL(p_pgm_id
5675                                       ,p_comp_obj_tree_row.par_pgm_id)
5676              ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
5677              ,p_pl_id             => p_pl_id
5678              ,p_oipl_id           => p_oipl_id
5679              ,p_business_group_id => p_business_group_id
5680              ,p_returned_date     => l_start_date
5681              ,p_lf_evt_ocrd_dt    =>  p_lf_evt_ocrd_dt
5682              ,p_effective_date    =>  NVL(p_lf_evt_ocrd_dt ,p_effective_date)
5683              );
5684             --
5685             run_rule(p_formula_id => l_elig_rec.comp_calc_rl
5686              ,p_empasg_row        => p_empasg_row
5687              ,p_benasg_row        => p_benasg_row
5688              ,p_pil_row           => p_pil_row
5689              ,p_curroipl_row      => p_curroipl_row
5690              ,p_curroiplip_row    => p_curroiplip_row
5691              ,p_effective_date    => l_start_date
5692              ,p_lf_evt_ocrd_dt    => l_start_date
5693              ,p_business_group_id => p_business_group_id
5694              ,p_person_id         => p_person_id
5695              ,p_pgm_id            => p_pgm_id
5696              ,p_pl_id             => p_pl_id
5697              ,p_oipl_id           => p_oipl_id
5698              ,p_oiplip_id         => p_oiplip_id
5699              ,p_plip_id           => p_plip_id
5700              ,p_ptip_id           => p_ptip_id
5701              ,p_ret_date          => l_dummy_date
5702              ,p_ret_val           => l_elig_result);
5703             --
5704             -- Round value if rounding needed
5705             --
5706             IF    l_elig_rec.rndg_cd IS NOT NULL
5707                OR l_elig_rec.rndg_rl IS NOT NULL THEN
5708               --
5709               l_elig_result  :=
5710                 benutils.do_rounding(p_rounding_cd=> l_elig_rec.rndg_cd
5711                  ,p_rounding_rl    => l_elig_rec.rndg_rl
5712                  ,p_value          => l_elig_result
5713                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
5714                                        ,p_effective_date));
5715             --
5716             END IF;
5717           --
5718           ELSE
5719             --
5720             /*
5721             l_elig_result  :=
5722               comp_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
5723                ,p_empasg_row        => p_empasg_row
5724                ,p_benasg_row        => p_benasg_row
5725                ,p_curroiplip_row    => p_curroiplip_row
5726                ,p_rec               => l_elig_rec
5727                ,p_person_id         => p_person_id
5728                ,p_business_group_id => p_business_group_id
5729                ,p_pgm_id            => p_pgm_id
5730                ,p_pl_id             => p_pl_id
5731                ,p_oipl_id           => p_oipl_id
5732                ,p_oiplip_id         => p_oiplip_id
5733                ,p_plip_id           => p_plip_id
5734                ,p_ptip_id           => p_ptip_id
5735                ,p_effective_date    => p_effective_date
5736                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
5737              */
5738               --
5739               -- passing the oipl_id from the oiplip record, incase p_oipl_id is null.
5740               -- passing the oipl_id from the oiplip record, incase p_oipl_id is null.
5741               -- BUG 3174453
5742               get_comp_objects( p_comp_obj_tree_row=>p_comp_obj_tree_row
5743                                ,p_effective_date   => nvl(g_fonm_cvg_strt_dt, p_effective_date)
5744                                ,p_ptip_id   =>p_ptip_id
5745                                ,p_plip_id   =>p_plip_id
5746                                ,p_oiplip_id =>p_oiplip_id
5747                                ,p_pgm_id    =>l_pgm_id
5748                                ,p_pl_id     =>l_pl_id
5749                                ,p_oipl_id   =>l_oipl_id );
5750               --
5751               --
5752               BEN_DERIVE_FACTORS.determine_compensation
5753               ( p_comp_lvl_fctr_id     => l_elig_rec.comp_lvl_fctr_id -- in number,
5754                ,p_person_id            => p_person_id            -- in number,
5755                ,p_pgm_id               => l_pgm_id               -- in number    default null,
5756                ,p_pl_id                => l_pl_id                -- in number    default null,
5757                ,p_oipl_id              => l_oipl_id
5758                ,p_per_in_ler_id        => p_pil_row.per_in_ler_id-- in number,
5759                ,p_business_group_id    => p_business_group_id    -- in number,
5760              --   ,p_perform_rounding_flg in boolean default true,
5761                ,p_effective_date       => p_effective_date      -- in date,
5762                ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt       -- in date default null,
5763              --  ,p_calc_bal_to_date     in date default null,
5764              --  ,p_cal_for              in varchar2  default null,
5765                ,p_value                => l_elig_result
5766                ,p_fonm_cvg_strt_dt     => g_fonm_cvg_strt_dt );
5767               --
5768            -- hr_utility.set_location(' Dn comp calc ' || l_package,10);
5769           --
5770           END IF;
5771         --
5772         /* Bug 5478918 */
5773           --
5774           ben_seeddata_object.get_object(p_rec=> l_der_rec);
5775 	  if (skip_min_max_le_calc(l_der_rec.drvdcmp_id,
5776 	                           p_business_group_id,
5777                                    p_ptnl_ler_trtmt_cd,
5778                                    p_effective_date)) THEN
5779             --
5780             /* Simply return as no further calculations need to be done */
5781             hr_utility.set_location(l_package||' Do Nothing here.', 9877);
5782             null;
5783             --
5784           else
5785           --
5786           -- In case called from watif benmngle then need not create
5787           -- temporals for any min, max breaches.
5788           --
5789           IF     l_elig_result IS NOT NULL
5790              AND (
5791                        ben_whatif_elig.g_stat_comp IS NULL
5792                    AND ben_whatif_elig.g_bnft_bal_comp IS NULL
5793                    AND ben_whatif_elig.g_bal_comp IS NULL) THEN
5794             --
5795                  ben_derive_part_and_rate_cache.get_comp_elig(p_pgm_id=> p_pgm_id
5796                      ,p_pl_id             => p_pl_id
5797                      ,p_oipl_id           => p_oipl_id
5798                      ,p_plip_id           => p_plip_id
5799                      ,p_ptip_id           => p_ptip_id
5800                      ,p_new_val           => l_elig_result
5801                      ,p_old_val           => p_comp_rec.comp_ref_amt
5802                      ,p_business_group_id => p_business_group_id
5803                      ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
5804                                               ,p_effective_date))
5805                      ,p_rec               => l_elig_rec);
5806         --
5807             IF benutils.min_max_breach(p_min_value=> NVL(l_elig_rec.mn_comp_val
5808                                                       ,-1)
5809                 ,p_max_value => NVL(l_elig_rec.mx_comp_val
5810                                  ,99999999)
5811                 ,p_new_value => l_elig_result
5812                 ,p_old_value => p_comp_rec.comp_ref_amt
5813                 ,p_break     => l_break) THEN
5814               --
5815               -- Derive life event occured date based on the value of l_break
5816               --
5817               IF l_elig_rec.comp_src_cd = 'STTDCOMP' THEN
5818                 --
5819                 l_lf_evt_ocrd_dt  :=
5820                   get_salary_date(p_empasg_row=> p_empasg_row
5821                    ,p_benasg_row     => p_benasg_row
5822                    ,p_rec            => l_elig_rec
5823                    ,p_person_id      => p_person_id
5824                    ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
5825                                          ,p_effective_date))
5826                    ,p_min            => l_elig_rec.mn_comp_val
5827                    ,p_max            => l_elig_rec.mx_comp_val
5828                    ,p_break          => l_break);
5829                 --
5830                 -- Reapply life event date logic to derived date
5831                 --
5832                 IF l_elig_rec.comp_lvl_det_cd <> 'AED' THEN
5833                   --
5834                   ben_determine_date.main(p_date_cd=> l_elig_rec.comp_lvl_det_cd
5835                    ,p_formula_id        => l_elig_rec.comp_lvl_det_rl
5836                    ,p_person_id         => p_person_id
5837                    ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
5838                    ,p_pgm_id            => NVL(p_pgm_id
5839                                             ,p_comp_obj_tree_row.par_pgm_id)
5840                    ,p_pl_id             => p_pl_id
5841                    ,p_oipl_id           => p_oipl_id
5842                    ,p_business_group_id => p_business_group_id
5843                    ,p_returned_date     => l_lf_evt_ocrd_dt
5844                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5845                    ,p_effective_date    => l_lf_evt_ocrd_dt
5846                    );
5847                   --
5848                   -- The derived life event occured date must be greater than the
5849                   -- life event occured date as otherwise in reality a boundary
5850                   -- has not been passed.
5851                   -- This can only happen if the det_cd is one of the following :
5852                   -- AFDCPPY = As of first day of current program oreplan year
5853                   -- APOCT1 = As of previous october 1st
5854                   -- AFDCM = As of first day of the current month
5855                   --
5856                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
5857                      AND l_elig_rec.comp_lvl_det_cd IN (
5858                                                          'AFDCPPY'
5859                                                         ,'APOCT1'
5860                                                         ,'AFDCM') THEN
5861                     --
5862                     -- These are special cases where we need to rederive the LED
5863                     -- so that we are actually still passing the correct boundary
5864                     --
5865                     IF l_elig_rec.comp_lvl_det_cd = 'APOCT1' THEN
5866                       --
5867                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
5868                                             ,12);
5869                     --
5870                     ELSIF l_elig_rec.comp_lvl_det_cd = 'AFDCM' THEN
5871                       --
5872                       --l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
5873                       -- Bug 1927010. Commented the above manipulation
5874                       null ;
5875                     --
5876                     ELSIF l_elig_rec.comp_lvl_det_cd = 'AFDCPPY' THEN
5877                       --
5878                       l_elig_rec.comp_lvl_det_cd  := 'AFDFPPY';
5879                     --
5880                     END IF;
5881                     --
5882                     -- Reapply logic back to determination of date routine.
5883                     --
5884                     ben_determine_date.main(p_date_cd=> l_elig_rec.comp_lvl_det_cd
5885                      ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
5886                      ,p_person_id         => p_person_id
5887                      ,p_pgm_id            => NVL(p_pgm_id
5888                                               ,p_comp_obj_tree_row.par_pgm_id)
5889                      ,p_pl_id             => p_pl_id
5890                      ,p_oipl_id           => p_oipl_id
5891                      ,p_business_group_id => p_business_group_id
5892                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
5893                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5894                      ,p_effective_date    => l_lf_evt_ocrd_dt
5895                      );
5896                   --
5897                   END IF;
5898                   --
5899                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
5900                 --
5901                 END IF;
5902               --
5903               ELSIF l_elig_rec.comp_src_cd = 'BNFTBALTYP' THEN
5904                 --
5905                 l_lf_evt_ocrd_dt  :=
5906                   get_balance_date(p_effective_date=> NVL(g_fonm_cvg_strt_dt,
5907                                                           NVL(p_lf_evt_ocrd_dt,p_effective_date))
5908                    ,p_bnfts_bal_id   => l_elig_rec.bnfts_bal_id
5909                    ,p_person_id      => p_person_id
5910                    ,p_min            => l_elig_rec.mn_comp_val
5911                    ,p_max            => l_elig_rec.mx_comp_val
5912                    ,p_break          => l_break);
5913                 --
5914                 IF l_elig_rec.comp_lvl_det_cd <> 'AED' THEN
5915                   --
5916                   ben_determine_date.main(p_date_cd=> l_elig_rec.comp_lvl_det_cd
5917                    ,p_formula_id        => l_elig_rec.comp_lvl_det_rl
5918                    ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
5919                    ,p_person_id         => p_person_id
5920                    ,p_pgm_id            => NVL(p_pgm_id
5921                                             ,p_comp_obj_tree_row.par_pgm_id)
5922                    ,p_pl_id             => p_pl_id
5923                    ,p_oipl_id           => p_oipl_id
5924                    ,p_business_group_id => p_business_group_id
5925                    ,p_returned_date     => l_new_lf_evt_ocrd_dt
5926                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5927                    ,p_effective_date    => l_lf_evt_ocrd_dt
5928                    );
5929                   --
5930                   -- The derived life event occured date must be greater than the
5931                   -- life event occured date as otherwise in reality a boundary
5932                   -- has not been passed.
5933                   -- This can only happen if the det_cd is one of the following :
5934                   -- AFDCPPY = As of first day of current program or plan year
5935                   -- APOCT1 = As of previous october 1st
5936                   -- AFDCM = As of first day of the current month
5937                   --
5938                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
5939                      AND l_elig_rec.comp_lvl_det_cd IN (
5940                                                          'AFDCPPY'
5941                                                         ,'APOCT1'
5942                                                         ,'AFDCM') THEN
5943                     --
5944                     -- These are special cases where we need to rederive the LED
5945                     -- so that we are actually still passing the correct boundary
5946                     --
5947                     IF l_elig_rec.comp_lvl_det_cd = 'APOCT1' THEN
5948                       --
5949                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
5950                                             ,12);
5951                     --
5952                     ELSIF l_elig_rec.comp_lvl_det_cd = 'AFDCM' THEN
5953                       --
5954                       -- l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
5955                       -- Bug 1927010. Commented the above manipulation
5956                       null ;
5957                     --
5958                     ELSIF l_elig_rec.comp_lvl_det_cd = 'AFDCPPY' THEN
5959                       --
5960                       l_elig_rec.comp_lvl_det_cd  := 'AFDFPPY';
5961                     --
5962                     END IF;
5963                     --
5964                     -- Reapply logic back to determination of date routine.
5965                     --
5966                     ben_determine_date.main(p_date_cd=> l_elig_rec.comp_lvl_det_cd
5967                      ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
5968                      ,p_person_id         => p_person_id
5969                      ,p_pgm_id            => NVL(p_pgm_id
5970                                               ,p_comp_obj_tree_row.par_pgm_id)
5971                      ,p_pl_id             => p_pl_id
5972                      ,p_oipl_id           => p_oipl_id
5973                      ,p_business_group_id => p_business_group_id
5974                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
5975                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
5976                      ,p_effective_date    => l_lf_evt_ocrd_dt
5977                      );
5978                   --
5979                   END IF;
5980                   --
5981                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
5982                 --
5983                 END IF;
5984               --
5985               ELSIF l_elig_rec.comp_src_cd = 'BALTYP' THEN
5986                 --
5987                 l_lf_evt_ocrd_dt  := p_effective_date;
5988               --
5989               END IF;
5990               --
5991               -- Check if the calculated life event occured date breaks the
5992               -- min assignment date for the person.
5993               --
5994               ben_person_object.get_object(p_person_id=> p_person_id
5995                ,p_rec       => l_rec);
5996               --
5997               IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
5998                 --
5999                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
6000                     ,p_person_id      => p_person_id
6001                     ,p_ler_id         => l_der_rec.drvdcmp_id
6002                     ,p_effective_date => p_effective_date) THEN
6003                   --
6004                   IF   (  l_lf_evt_ocrd_dt < p_effective_date
6005                      AND NVL(p_ptnl_ler_trtmt_cd
6006                           ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL')  THEN
6007                     --
6008                     -- We are not creating past life events
6009                     --
6010                     NULL;
6011                   --
6012                   ELSIF l_ok THEN
6013                     --
6014                     if not p_calculate_only_mode then
6015                       --
6016                       create_ptl_ler
6017                         (p_calculate_only_mode => p_calculate_only_mode
6018                         ,p_ler_id              => l_der_rec.drvdcmp_id
6019                         ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
6020                         ,p_person_id           => p_person_id
6021                         ,p_business_group_id   => p_business_group_id
6022                         ,p_effective_date      => p_effective_date
6023                         );
6024                       --
6025                     end if;
6026                     --
6027                   END IF;
6028                 --
6029                 END IF;
6030               --
6031               END IF;
6032             --
6033             END IF;
6034           --
6035           END IF;
6036           --
6037        END IF; /* End Bug 5478918 */
6038        --
6039           p_comp_rec.comp_ref_amt  := l_elig_result;
6040           p_comp_rec.comp_ref_uom  := l_elig_rec.comp_lvl_uom;
6041           --
6042           IF l_elig_result IS NULL THEN
6043             --
6044             p_comp_rec.comp_ref_uom  := NULL;
6045           --
6046           END IF;
6047         --
6048         ELSE
6049           --
6050           p_comp_rec.comp_ref_amt  := NULL;
6051           p_comp_rec.comp_ref_uom  := NULL;
6052         --
6053         END IF;
6054       --
6055       END IF;
6056       --
6057      -- hr_utility.set_location('RFCLF=Y ' || l_package,10);
6058     --
6059     END IF;
6060     --
6061     if g_debug then
6062       hr_utility.set_location(' Before entering into Rate Factors ', 15);
6063     end if;
6064     IF    bitand(p_comp_obj_tree_row.flag_bit_val
6065            ,ben_manage_life_events.g_cmp_rt_flag) <> 0
6066        OR     p_oiplip_id IS NOT NULL
6067           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
6068                ,ben_manage_life_events.g_cmp_rt_flag) <> 0 THEN
6069       --
6070       if g_debug then
6071         hr_utility.set_location('COMP for RT',10);
6072       end if;
6073       IF p_comp_rec.rt_frz_cmp_lvl_flag = 'Y' THEN
6074         --
6075         -- No calulation required just return the frozen value
6076         --
6077         NULL;
6078       --
6079       ELSE
6080         --
6081         if g_debug then
6082           hr_utility.set_location('ben_derive_part_and_rate_cache '||p_oipl_id , 20);
6083         end if;
6084         --
6085         ben_derive_part_and_rate_cache.get_comp_rate(p_pgm_id=> p_pgm_id
6086          ,p_pl_id             => p_pl_id
6087          ,p_oipl_id           => p_oipl_id
6088          ,p_plip_id           => p_plip_id
6089          ,p_ptip_id           => p_ptip_id
6090          ,p_oiplip_id         => p_oiplip_id
6091          ,p_business_group_id => p_business_group_id
6092          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,
6093                                      NVL(p_lf_evt_ocrd_dt,p_effective_date))
6094          ,p_rec               => l_rate_rec);
6095         --
6096         IF l_rate_rec.exist = 'Y' THEN
6097           --
6098           if g_debug then
6099             hr_utility.set_location(' l_rate_rec.exist ' ,25);
6100           end if;
6101           l_rate  := TRUE;
6102           --
6103           IF p_oiplip_id IS NOT NULL THEN
6104             --
6105             if g_debug then
6106               hr_utility.set_location(' p_curroiplip_row ',25);
6107             end if;
6108             l_oiplip_rec  := p_curroiplip_row;
6109           --
6110           END IF;
6111           --
6112           IF l_rate_rec.comp_calc_rl IS NOT NULL THEN
6113             --
6114             if g_debug then
6115               hr_utility.set_location('in the comp_calc_rl ' ,30);
6116             end if;
6117             --
6118             ben_determine_date.main(p_date_cd=> l_rate_rec.comp_lvl_det_cd
6119              ,p_formula_id        => l_rate_rec.comp_lvl_det_rl
6120              ,p_person_id         => p_person_id
6121              ,p_pgm_id            => NVL(p_pgm_id
6122                                       ,p_comp_obj_tree_row.par_pgm_id)
6123              ,p_bnfts_bal_id      => l_rate_rec.bnfts_bal_id
6124              ,p_pl_id             => p_pl_id
6125              ,p_oipl_id           => NVL(p_oipl_id
6126                                       ,l_oiplip_rec.oipl_id)
6127              ,p_business_group_id => p_business_group_id
6128              ,p_returned_date     => l_start_date
6129              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6130              ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
6131                                       ,p_effective_date)
6132              );
6133             --
6134             run_rule(p_formula_id => l_rate_rec.comp_calc_rl
6135              ,p_empasg_row        => p_empasg_row
6136              ,p_benasg_row        => p_benasg_row
6137              ,p_pil_row           => p_pil_row
6138              ,p_curroipl_row      => p_curroipl_row
6139              ,p_curroiplip_row    => p_curroiplip_row
6140              ,p_effective_date    => p_effective_date
6141              ,p_lf_evt_ocrd_dt    => l_start_date
6142              ,p_business_group_id => p_business_group_id
6143              ,p_person_id         => p_person_id
6144              ,p_pgm_id            => p_pgm_id
6145              ,p_pl_id             => p_pl_id
6146              ,p_oipl_id           => p_oipl_id
6147              ,p_oiplip_id         => p_oiplip_id
6148              ,p_plip_id           => p_plip_id
6149              ,p_ptip_id           => p_ptip_id
6150              ,p_ret_date          => l_dummy_date
6151              ,p_ret_val           => l_rate_result);
6152             --
6153             -- Round value if rounding needed
6154             --
6155             IF    l_rate_rec.rndg_cd IS NOT NULL
6156                OR l_rate_rec.rndg_rl IS NOT NULL THEN
6157               --
6158               if g_debug then
6159                 hr_utility.set_location('in the comp_calc_rl rndg_cd ' ,35 );
6160               end if;
6161               --
6162               l_rate_result  :=
6163                 benutils.do_rounding(p_rounding_cd=> l_rate_rec.rndg_cd
6164                  ,p_rounding_rl    => l_rate_rec.rndg_rl
6165                  ,p_value          => l_rate_result
6166                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
6167                                        ,p_effective_date));
6168             --
6169             END IF;
6170             --
6171           ELSE -- l_rate_rec.comp_calc_rl
6172             --
6173             if g_debug then
6174               hr_utility.set_location('not rule -  l_rate_result ',30);
6175             end if;
6176             /*
6177             l_rate_result  :=
6178               comp_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
6179                ,p_empasg_row        => p_empasg_row
6180                ,p_benasg_row        => p_benasg_row
6181                ,p_curroiplip_row    => p_curroiplip_row
6182                ,p_rec               => l_rate_rec
6183                ,p_person_id         => p_person_id
6184                ,p_business_group_id => p_business_group_id
6185                ,p_pgm_id            => p_pgm_id
6186                ,p_pl_id             => p_pl_id
6187                ,p_oipl_id           => p_oipl_id
6188                ,p_oiplip_id         => p_oiplip_id
6189                ,p_plip_id           => p_plip_id
6190                ,p_ptip_id           => p_ptip_id
6191                ,p_effective_date    => p_effective_date
6192                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
6193              */
6194               --
6195               -- BUG 3174453
6196               get_comp_objects( p_comp_obj_tree_row=>p_comp_obj_tree_row
6197                                ,p_effective_date   => nvl(g_fonm_cvg_strt_dt,p_effective_date)
6198                                ,p_ptip_id   =>p_ptip_id
6199                                ,p_plip_id   =>p_plip_id
6200                                ,p_oiplip_id =>p_oiplip_id
6201                                ,p_pgm_id    =>l_pgm_id
6202                                ,p_pl_id     =>l_pl_id
6203                                ,p_oipl_id   =>l_oipl_id );
6204               --
6205               BEN_DERIVE_FACTORS.determine_compensation
6206               ( p_comp_lvl_fctr_id     => l_rate_rec.comp_lvl_fctr_id -- in number,
6207                ,p_person_id            => p_person_id            -- in number,
6208                ,p_pgm_id               => l_pgm_id               -- in number    default null,
6209                ,p_pl_id                => l_pl_id                -- in number    default null,
6210                ,p_oipl_id              => nvl(p_oipl_id,l_oiplip_rec.oipl_id)  -- 2946985  -- in number    default null,
6211                ,p_per_in_ler_id        => p_pil_row.per_in_ler_id-- in number,
6212                ,p_business_group_id    => p_business_group_id    -- in number,
6213              --   ,p_perform_rounding_flg in boolean default true,
6214                ,p_effective_date       => p_effective_date       -- in date,
6215                ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt       -- in date default null,
6216              --  ,p_calc_bal_to_date     in date default null,
6217              --  ,p_cal_for              => 'R'                    -- in varchar2  default null,
6218                ,p_value                => l_rate_result
6219                 ,p_fonm_cvg_strt_dt     => g_fonm_cvg_strt_dt);
6220 
6221             --
6222             IF l_rate_result is not null THEN
6223               --
6224               --
6225               ben_derive_part_and_rate_cache.get_comp_rate(p_pgm_id=> p_pgm_id
6226                 ,p_pl_id             => p_pl_id
6227                 ,p_oipl_id           => p_oipl_id
6228                 ,p_plip_id           => p_plip_id
6229                 ,p_ptip_id           => p_ptip_id
6230                 ,p_oiplip_id         => p_oiplip_id
6231                 ,p_new_val           => l_rate_result
6232                 ,p_old_val           => p_comp_rec.rt_comp_ref_amt
6233                 ,p_business_group_id => p_business_group_id
6234                 ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,
6235                                            NVL(p_lf_evt_ocrd_dt ,p_effective_date))
6236                 ,p_rec               => l_rate_rec);
6237                --
6238               IF ( ben_whatif_elig.g_stat_comp IS NULL
6239                    AND ben_whatif_elig.g_bnft_bal_comp IS NULL
6240                    AND ben_whatif_elig.g_bal_comp IS NULL)     THEN
6241                 --
6242                 ben_seeddata_object.get_object(p_rec=> l_der_rec);
6243                 --
6244                 if g_debug then
6245                   hr_utility.set_location(' Call to comp_level_min_max ' ,45 );
6246                 end if;
6247 
6248                 comp_level_min_max
6249                    (p_calculate_only_mode =>p_calculate_only_mode
6250                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
6251                    ,p_curroiplip_row      =>p_curroiplip_row
6252                    ,p_rec                 => l_rate_rec
6253                     --,p_rate_rec            =>l_rate_rec
6254                     --,p_comp_rec            =>p_comp_rec
6255                    ,p_empasg_row          =>p_empasg_row
6256                    ,p_benasg_row          =>p_benasg_row
6257                    ,p_person_id           =>p_person_id
6258                    ,p_pgm_id              =>p_pgm_id
6259                    ,p_pl_id               =>p_pl_id
6260                    ,p_oipl_id             =>p_oipl_id
6261                    ,p_oiplip_id           =>p_oiplip_id
6262                    ,p_plip_id             =>p_plip_id
6263                    ,p_ptip_id             =>p_ptip_id
6264                    ,p_business_group_id   =>p_business_group_id
6265                    ,p_ler_id              =>l_der_rec.drvdcmp_id
6266                    ,p_min_value           =>l_rate_rec.mn_comp_val
6267                    ,p_max_value           =>l_rate_rec.mx_comp_val
6268                    ,p_new_value           =>l_rate_result
6269                    ,p_old_value           =>p_comp_rec.rt_comp_ref_amt
6270                    ,p_uom                 =>l_rate_rec.comp_lvl_uom
6271                    ,p_subtract_date       =>l_subtract_date
6272                    ,p_det_cd              =>l_rate_rec.comp_lvl_det_cd
6273                    ,p_formula_id          =>l_rate_rec.comp_lvl_det_rl
6274                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
6275                    ,p_effective_date      =>p_effective_date
6276                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
6277                    ,p_comp_src_cd         =>l_rate_rec.comp_src_cd
6278                    ,p_bnfts_bal_id        =>l_rate_rec.bnfts_bal_id
6279                   ) ;
6280                 --
6281               END IF; -- ben_whatif_elig
6282               --
6283             END IF; -- l_rate_result
6284             --
6285           END IF; -- l_rate_rec.los_calc_rl
6286           --
6287         END IF ; -- l_rate_rec.exist
6288         -- Try and find a coverage first
6289         --
6290         if g_debug then
6291           hr_utility.set_location(' Now check for Coverage and Premium' ,50 );
6292         end if;
6293         --
6294         IF    p_oipl_id IS NOT NULL
6295             OR p_pl_id IS NOT NULL
6296             OR p_plip_id IS NOT NULL THEN
6297           --
6298           if g_debug then
6299             hr_utility.set_location(' ben_derive_part_and_rate_cvg ' , 55);
6300           end if;
6301           --
6302           ben_derive_part_and_rate_cvg.get_comp_rate(p_pl_id=> p_pl_id
6303              ,p_oipl_id           => p_oipl_id
6304              ,p_plip_id           => p_plip_id
6305              ,p_business_group_id => p_business_group_id
6306              ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,
6307                                         NVL(p_lf_evt_ocrd_dt ,p_effective_date))
6308              ,p_rec               => l_rate_cvg_rec);
6309           --
6310           IF l_rate_cvg_rec.exist = 'Y' THEN
6311             --
6312             if g_debug then
6313               hr_utility.set_location(' l_rate_cvg_rec.exist' , 60);
6314             end if;
6315             l_cvg  := TRUE;
6316             --
6317             IF l_rate_cvg_rec.comp_calc_rl IS NOT NULL THEN
6318             --
6319 
6320               ben_determine_date.main(p_date_cd=> l_rate_cvg_rec.comp_lvl_det_cd
6321                ,p_formula_id        => l_rate_cvg_rec.comp_lvl_det_rl
6322                ,p_person_id         => p_person_id
6323                ,p_pgm_id            => NVL(p_pgm_id
6324                                         ,p_comp_obj_tree_row.par_pgm_id)
6325                ,p_bnfts_bal_id      => l_rate_cvg_rec.bnfts_bal_id
6326                ,p_pl_id             => p_pl_id
6327                ,p_oipl_id           => NVL(p_oipl_id
6328                                         ,l_oiplip_rec.oipl_id)
6329                ,p_business_group_id => p_business_group_id
6330                ,p_returned_date     => l_start_date
6331                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6332                ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
6333                                       ,p_effective_date)
6334                ) ;
6335               --
6336               run_rule(p_formula_id => l_rate_cvg_rec.comp_calc_rl
6337                ,p_empasg_row        => p_empasg_row
6338                ,p_benasg_row        => p_benasg_row
6339                ,p_pil_row           => p_pil_row
6340                ,p_curroipl_row      => p_curroipl_row
6341                ,p_curroiplip_row    => p_curroiplip_row
6342                ,p_effective_date    => p_effective_date
6343                ,p_lf_evt_ocrd_dt    => l_start_date
6344                ,p_business_group_id => p_business_group_id
6345                ,p_person_id         => p_person_id
6346                ,p_pgm_id            => p_pgm_id
6347                ,p_pl_id             => p_pl_id
6348                ,p_oipl_id           => p_oipl_id
6349                ,p_oiplip_id         => p_oiplip_id
6350                ,p_plip_id           => p_plip_id
6351                ,p_ptip_id           => p_ptip_id
6352                ,p_ret_date          => l_dummy_date
6353                ,p_ret_val           => l_rate_cvg_result);
6354               --
6355               -- Round value if rounding needed
6356               --
6357               IF    l_rate_cvg_rec.rndg_cd IS NOT NULL
6358                OR l_rate_cvg_rec.rndg_rl IS NOT NULL THEN
6359                 --
6360                 l_rate_cvg_result  :=
6361                   benutils.do_rounding(p_rounding_cd=> l_rate_cvg_rec.rndg_cd
6362                    ,p_rounding_rl    => l_rate_cvg_rec.rndg_rl
6363                    ,p_value          => l_rate_cvg_result
6364                    ,p_effective_date => NVL(p_lf_evt_ocrd_dt
6365                                          ,p_effective_date));
6366                   --
6367               END IF;
6368             --
6369           ELSE -- l_rate_cvg_rec.comp_calc_rl
6370             --
6371             if g_debug then
6372               hr_utility.set_location(' call to comp_calculation ' , 65 );
6373             end if;
6374             /*
6375             l_rate_cvg_result  :=
6376               comp_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
6377                ,p_empasg_row        => p_empasg_row
6378                ,p_benasg_row        => p_benasg_row
6379                ,p_curroiplip_row    => p_curroiplip_row
6380                ,p_rec               => l_rate_cvg_rec
6381                ,p_person_id         => p_person_id
6382                ,p_business_group_id => p_business_group_id
6383                ,p_pgm_id            => p_pgm_id
6384                ,p_pl_id             => p_pl_id
6385                ,p_oipl_id           => p_oipl_id
6386                ,p_oiplip_id         => p_oiplip_id
6387                ,p_plip_id           => p_plip_id
6388                ,p_ptip_id           => p_ptip_id
6389                ,p_effective_date    => p_effective_date
6390                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
6391             */
6392             --
6393               -- BUG 3174453
6394               get_comp_objects( p_comp_obj_tree_row=>p_comp_obj_tree_row
6395                                ,p_effective_date   =>nvl(g_fonm_cvg_strt_dt,p_effective_date)
6396                                ,p_ptip_id   =>p_ptip_id
6397                                ,p_plip_id   =>p_plip_id
6398                                ,p_oiplip_id =>p_oiplip_id
6399                                ,p_pgm_id    =>l_pgm_id
6400                                ,p_pl_id     =>l_pl_id
6401                                ,p_oipl_id   =>l_oipl_id );
6402 
6403               --
6404               BEN_DERIVE_FACTORS.determine_compensation
6405               ( p_comp_lvl_fctr_id     => l_rate_cvg_rec.comp_lvl_fctr_id -- in number,
6406                ,p_person_id            => p_person_id            -- in number,
6407                ,p_pgm_id               => l_pgm_id               -- in number    default null,
6408                ,p_pl_id                => l_pl_id                -- in number    default null,
6409                ,p_oipl_id              => l_oipl_id              -- in number    default null,
6410                ,p_per_in_ler_id        => p_pil_row.per_in_ler_id-- in number,
6411                ,p_business_group_id    => p_business_group_id    -- in number,
6412              --   ,p_perform_rounding_flg in boolean default true,
6413                ,p_effective_date       => p_effective_date       -- in date,
6414                ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt       -- in date default null,
6415              --  ,p_calc_bal_to_date     in date default null,
6416              --  ,p_cal_for              => 'R'                    -- in varchar2  default null,
6417                ,p_value                => l_rate_cvg_result
6418                 ,p_fonm_cvg_strt_dt    => g_fonm_cvg_strt_dt);
6419               ---
6420               if g_debug then
6421                 hr_utility.set_location('  l_rate_cvg_result ' ,70);
6422               end if;
6423             IF l_rate_cvg_result is not null THEN
6424               --
6425               ben_derive_part_and_rate_cvg.get_comp_rate(p_pl_id=> p_pl_id
6426                 ,p_oipl_id           => p_oipl_id
6427                 ,p_plip_id           => p_plip_id
6428                 ,p_old_val           => p_comp_rec.rt_comp_ref_amt
6429                 ,p_new_val           => l_rate_cvg_result
6430                 ,p_business_group_id => p_business_group_id
6431                 ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,
6432                                             NVL(p_lf_evt_ocrd_dt ,p_effective_date))
6433                 ,p_rec               => l_rate_cvg_rec);
6434 
6435               --
6436               IF ( ben_whatif_elig.g_stat_comp IS NULL
6437                    AND ben_whatif_elig.g_bnft_bal_comp IS NULL
6438                    AND ben_whatif_elig.g_bal_comp IS NULL)     THEN
6439 
6440                  ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
6441                  --
6442                  if g_debug then
6443                    hr_utility.set_location('  call comp_level_min_max ' ,75);
6444                  end if;
6445                  comp_level_min_max
6446                    (p_calculate_only_mode =>p_calculate_only_mode
6447                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
6448                    ,p_curroiplip_row      =>p_curroiplip_row
6449                    ,p_rec                 =>l_rate_cvg_rec
6450                 --   ,p_rate_rec            =>l_rate_cvg_rec
6451                 --   ,p_comp_rec            =>p_comp_rec
6452                    ,p_empasg_row          =>p_empasg_row
6453                    ,p_benasg_row          =>p_benasg_row
6454                    ,p_person_id           =>p_person_id
6455                    ,p_pgm_id              =>p_pgm_id
6456                    ,p_pl_id               =>p_pl_id
6457                    ,p_oipl_id             =>p_oipl_id
6458                    ,p_oiplip_id           =>p_oiplip_id
6459                    ,p_plip_id             =>p_plip_id
6460                    ,p_ptip_id             =>p_ptip_id
6461                    ,p_business_group_id   =>p_business_group_id
6462                    ,p_ler_id              =>l_der_cvg_rec.drvdcmp_id
6463                    ,p_min_value           =>l_rate_cvg_rec.mn_comp_val
6464                    ,p_max_value           =>l_rate_cvg_rec.mx_comp_val
6465                    ,p_new_value           =>l_rate_cvg_result -- l_rate_result
6466                    ,p_old_value           =>p_comp_rec.rt_comp_ref_amt
6467                    ,p_uom                 =>l_rate_cvg_rec.comp_lvl_uom
6468                    ,p_subtract_date       =>l_subtract_date
6469                    ,p_det_cd              =>l_rate_cvg_rec.comp_lvl_det_cd
6470                    ,p_formula_id          =>l_rate_cvg_rec.comp_lvl_det_rl
6471                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
6472                    ,p_effective_date      =>p_effective_date
6473                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
6474                    ,p_comp_src_cd         =>l_rate_cvg_rec.comp_src_cd
6475                    ,p_bnfts_bal_id        =>l_rate_cvg_rec.bnfts_bal_id
6476                   ) ;
6477               END IF; -- ben_whatif_elig
6478               --
6479             END IF; -- l_rate_cvg_result
6480             --
6481           END IF; -- l_rate_cvg_rec.los_calc_rl
6482           --
6483         END IF; -- l_rate_cvg_rec.exist
6484         --
6485       END IF ; -- oipl for Coverage
6486       --
6487       IF p_oipl_id IS NOT NULL
6488         OR p_pl_id IS NOT NULL THEN
6489         --
6490         if g_debug then
6491           hr_utility.set_location(' Now call ben_derive_part_and_rate_prem ' , 80);
6492         end if;
6493         --
6494         ben_derive_part_and_rate_prem.get_comp_rate(
6495               p_pl_id             => p_pl_id
6496              ,p_oipl_id           => p_oipl_id
6497              ,p_business_group_id => p_business_group_id
6498              ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
6499                                       ,p_effective_date))
6500              ,p_rec               => l_rate_prem_rec);
6501               --
6502         IF l_rate_prem_rec.exist = 'Y' THEN
6503           --
6504           if g_debug then
6505             hr_utility.set_location(' l_rate_prem_rec.exist Y ',85);
6506           end if;
6507           l_prem  := TRUE;
6508           --
6509           IF l_rate_prem_rec.comp_calc_rl IS NOT NULL THEN
6510             --
6511             ben_determine_date.main(p_date_cd=> l_rate_prem_rec.comp_lvl_det_cd
6512                       ,p_formula_id        => l_rate_prem_rec.comp_lvl_det_rl
6513                       ,p_person_id         => p_person_id
6514                       ,p_pgm_id            => NVL(p_pgm_id
6515                                                ,p_comp_obj_tree_row.par_pgm_id)
6516                       ,p_bnfts_bal_id      => l_rate_prem_rec.bnfts_bal_id
6517                       ,p_pl_id             => p_pl_id
6518                       ,p_oipl_id           => NVL(p_oipl_id
6519                                                ,l_oiplip_rec.oipl_id)
6520                       ,p_business_group_id => p_business_group_id
6521                       ,p_returned_date     => l_start_date
6522                       ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
6523                       ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
6524                                                ,p_effective_date)
6525                       ) ;
6526                   --
6527                   run_rule(p_formula_id => l_rate_prem_rec.comp_calc_rl
6528                      ,p_empasg_row        => p_empasg_row
6529                      ,p_benasg_row        => p_benasg_row
6530                      ,p_pil_row           => p_pil_row
6531                      ,p_curroipl_row      => p_curroipl_row
6532                      ,p_curroiplip_row    => p_curroiplip_row
6533                      ,p_effective_date    => p_effective_date
6534                      ,p_lf_evt_ocrd_dt    => l_start_date
6535                      ,p_business_group_id => p_business_group_id
6536                      ,p_person_id         => p_person_id
6537                      ,p_pgm_id            => p_pgm_id
6538                      ,p_pl_id             => p_pl_id
6539                      ,p_oipl_id           => p_oipl_id
6540                      ,p_oiplip_id         => p_oiplip_id
6541                      ,p_plip_id           => p_plip_id
6542                      ,p_ptip_id           => p_ptip_id
6543                      ,p_ret_date          => l_dummy_date
6544                      ,p_ret_val           => l_rate_prem_result);
6545                     --
6546                     -- Round value if rounding needed
6547                     --
6548             IF    l_rate_prem_rec.rndg_cd IS NOT NULL
6549                OR l_rate_prem_rec.rndg_rl IS NOT NULL THEN
6550               --
6551               l_rate_prem_result  :=
6552                 benutils.do_rounding(p_rounding_cd=> l_rate_prem_rec.rndg_cd
6553                  ,p_rounding_rl    => l_rate_prem_rec.rndg_rl
6554                  ,p_value          => l_rate_prem_result
6555                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
6556                                        ,p_effective_date));
6557             --
6558             END IF;
6559             --
6560           ELSE -- l_rate_prem_rec.comp_calc_rl
6561             --
6562             if g_debug then
6563               hr_utility.set_location(' call to comp_calculation ' , 90);
6564             end if;
6565           /*
6566             l_rate_prem_result  :=
6567               comp_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
6568                ,p_empasg_row        => p_empasg_row
6569                ,p_benasg_row        => p_benasg_row
6570                ,p_curroiplip_row    => p_curroiplip_row
6571                ,p_rec               => l_rate_prem_rec
6572                ,p_person_id         => p_person_id
6573                ,p_business_group_id => p_business_group_id
6574                ,p_pgm_id            => p_pgm_id
6575                ,p_pl_id             => p_pl_id
6576                ,p_oipl_id           => p_oipl_id
6577                ,p_oiplip_id         => p_oiplip_id
6578                ,p_plip_id           => p_plip_id
6579                ,p_ptip_id           => p_ptip_id
6580                ,p_effective_date    => p_effective_date
6581                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
6582             */
6583               -- BUG 3174453
6584               get_comp_objects( p_comp_obj_tree_row=>p_comp_obj_tree_row
6585                                ,p_effective_date   => nvl(g_fonm_cvg_strt_dt,p_effective_date)
6586                                , p_ptip_id   =>p_ptip_id
6587                                ,p_plip_id   =>p_plip_id
6588                                ,p_oiplip_id =>p_oiplip_id
6589                                ,p_pgm_id    =>l_pgm_id
6590                                ,p_pl_id     =>l_pl_id
6591                                ,p_oipl_id   =>l_oipl_id );
6592               --
6593               BEN_DERIVE_FACTORS.determine_compensation
6594               ( p_comp_lvl_fctr_id     => l_rate_prem_rec.comp_lvl_fctr_id -- in number,
6595                ,p_person_id            => p_person_id            -- in number,
6596                ,p_pgm_id               => l_pgm_id               -- in number    default null,
6597                ,p_pl_id                => l_pl_id                -- in number    default null,
6598                ,p_oipl_id              => l_oipl_id              -- in number    default null,
6599                ,p_per_in_ler_id        => p_pil_row.per_in_ler_id-- in number,
6600                ,p_business_group_id    => p_business_group_id    -- in number,
6601              --   ,p_perform_rounding_flg in boolean default true,
6602                ,p_effective_date       => p_effective_date       -- in date,
6603                ,p_lf_evt_ocrd_dt       => p_lf_evt_ocrd_dt       -- in date default null,
6604              --  ,p_calc_bal_to_date     in date default null,
6605              --  ,p_cal_for              => 'R'                    -- in varchar2  default null,
6606                ,p_value                => l_rate_prem_result
6607                ,p_fonm_cvg_strt_dt     => g_fonm_cvg_strt_dt);
6608               --
6609               if g_debug then
6610                 hr_utility.set_location(' l_rate_prem_result '||l_rate_prem_result ,95);
6611               end if;
6612               if g_debug then
6613                 hr_utility.set_location(' p_old_val '||p_comp_rec.rt_comp_ref_amt,95);
6614               end if;
6615               if g_debug then
6616                 hr_utility.set_location(' p_new_val '||l_rate_prem_result,95);
6617               end if;
6618               if g_debug then
6619                 hr_utility.set_location(' p_pl_id  '||p_pl_id,95);
6620               end if;
6621               if g_debug then
6622                 hr_utility.set_location(' p_oipl_id '||p_oipl_id,95);
6623               end if;
6624               if g_debug then
6625                 hr_utility.set_location(' p_effective_date '||NVL(p_lf_evt_ocrd_dt,p_effective_date) ,95);
6626               end if;
6627               --
6628               IF l_rate_prem_result is not null THEN
6629                 --
6630                 ben_derive_part_and_rate_prem.get_comp_rate(
6631                     p_pl_id             => p_pl_id
6632                    ,p_oipl_id           => p_oipl_id
6633                    ,p_old_val           => p_comp_rec.rt_comp_ref_amt
6634                    ,p_new_val           => l_rate_prem_result
6635                    ,p_business_group_id => p_business_group_id
6636                    ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,
6637                                                 NVL(p_lf_evt_ocrd_dt ,p_effective_date))
6638                    ,p_rec               => l_rate_prem_rec);
6639                  --
6640                  IF ( ben_whatif_elig.g_stat_comp IS NULL
6641                      AND ben_whatif_elig.g_bnft_bal_comp IS NULL
6642                      AND ben_whatif_elig.g_bal_comp IS NULL)     THEN
6643                    --
6644                    ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
6645                    --
6646                    if g_debug then
6647                      hr_utility.set_location(' call to comp_level_min_max ' ,100);
6648                    end if;
6649                    comp_level_min_max
6650                      (p_calculate_only_mode =>p_calculate_only_mode
6651                      ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
6652                      ,p_curroiplip_row      =>p_curroiplip_row
6653                      ,p_rec                 =>l_rate_prem_rec
6654                  --      ,p_rate_rec            =>l_rate_prem_rec
6655                  --    ,p_comp_rec            =>p_comp_rec
6656                      ,p_empasg_row          =>p_empasg_row
6657                      ,p_benasg_row          =>p_benasg_row
6658                      ,p_person_id           =>p_person_id
6659                      ,p_pgm_id              =>p_pgm_id
6660                      ,p_pl_id               =>p_pl_id
6661                      ,p_oipl_id             =>p_oipl_id
6662                      ,p_oiplip_id           =>p_oiplip_id
6663                      ,p_plip_id             =>p_plip_id
6664                      ,p_ptip_id             =>p_ptip_id
6665                      ,p_business_group_id   =>p_business_group_id
6666                      ,p_ler_id              =>l_der_prem_rec.drvdcmp_id
6667                      ,p_min_value           =>l_rate_prem_rec.mn_comp_val
6668                      ,p_max_value           =>l_rate_prem_rec.mx_comp_val
6669                      ,p_new_value           =>l_rate_prem_result
6670                      ,p_old_value           =>p_comp_rec.rt_comp_ref_amt
6671                      ,p_uom                 =>l_rate_prem_rec.comp_lvl_uom
6672                      ,p_subtract_date       =>l_subtract_date
6673                      ,p_det_cd              =>l_rate_prem_rec.comp_lvl_det_cd
6674                      ,p_formula_id          =>l_rate_prem_rec.comp_lvl_det_rl
6675                      ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
6676                      ,p_effective_date      =>p_effective_date
6677                      ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
6678                      ,p_comp_src_cd         =>l_rate_prem_rec.comp_src_cd
6679                      ,p_bnfts_bal_id        =>l_rate_prem_rec.bnfts_bal_id
6680                       ) ;
6681                      --
6682                  END IF; --ben_whatif_elig
6683                  --
6684                END IF; -- l_rate_prem_result
6685                --
6686              END IF; -- l_rate_prem_rec.los_calc_rl
6687              --
6688            END IF; -- l_rate_prem_rec.exist
6689            --
6690          END IF; -- p_oipl_id for Premium
6691          --
6692          if g_debug then
6693            hr_utility.set_location(' Done with Rate, Cvg and Prem ', 110);
6694          end if;
6695          --
6696          IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
6697           --
6698           if g_debug then
6699             hr_utility.set_location('No record found ' ,120);
6700           end if;
6701           --
6702           p_comp_rec.rt_comp_ref_amt  := NULL;
6703           p_comp_rec.rt_comp_ref_uom  := NULL;
6704           --
6705         ELSIF l_rate_result is NOT NULL THEN
6706           if g_debug then
6707             hr_utility.set_location(' Step 28',10);
6708           end if;
6709           p_comp_rec.rt_comp_ref_amt  := l_rate_result;
6710           p_comp_rec.rt_comp_ref_uom  := l_rate_rec.comp_lvl_uom;
6711           --
6712         ELSIF l_rate_cvg_result is NOT NULL then
6713           --
6714           p_comp_rec.rt_comp_ref_amt  := l_rate_cvg_result;
6715           p_comp_rec.rt_comp_ref_uom  := l_rate_cvg_rec.comp_lvl_uom;
6716           if g_debug then
6717             hr_utility.set_location(' Step 29',10);
6718           end if;
6719         ELSIF l_rate_prem_result is NOT NULL THEN
6720           --
6721           p_comp_rec.rt_comp_ref_amt  := l_rate_prem_result;
6722           p_comp_rec.rt_comp_ref_uom  := l_rate_prem_rec.comp_lvl_uom;
6723           if g_debug then
6724             hr_utility.set_location(' Step 30',10);
6725           end if;
6726         END IF;
6727 /*
6728           p_comp_rec.rt_comp_ref_amt  := l_rate_result;
6729           p_comp_rec.rt_comp_ref_uom  := l_rate_rec.comp_lvl_uom;
6730           --
6731          IF l_rate_result IS NULL THEN
6732            --
6733            p_comp_rec.rt_comp_ref_uom  := NULL;
6734            --
6735          END IF;
6736         --
6737         ELSE
6738           --
6739           p_comp_rec.rt_comp_ref_amt  := NULL;
6740           p_comp_rec.rt_comp_ref_uom  := NULL;
6741         --
6742 */
6743       --
6744       END IF;
6745     --
6746     END IF;
6747     --
6748     if g_debug then
6749       hr_utility.set_location('Leaving ' || l_package,10);
6750     end if;
6751   --
6752   END calculate_compensation_level;
6753   --
6754   --
6755   PROCEDURE calculate_comb_age_and_los
6756     (p_calculate_only_mode in     boolean default false
6757     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
6758     ,p_per_row             IN     per_all_people_f%ROWTYPE
6759     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
6760     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
6761     ,p_pil_row             IN     ben_per_in_ler%ROWTYPE
6762     ,p_curroipl_row        IN     ben_cobj_cache.g_oipl_inst_row
6763     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
6764     ,p_person_id           IN     NUMBER
6765     ,p_business_group_id   IN     NUMBER
6766     ,p_pgm_id              IN     NUMBER
6767     ,p_pl_id               IN     NUMBER
6768     ,p_oipl_id             IN     NUMBER
6769     ,p_plip_id             IN     NUMBER
6770     ,p_ptip_id             IN     NUMBER
6771     ,p_oiplip_id           IN     NUMBER
6772     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
6773     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
6774     ,p_effective_date      IN     DATE
6775     ,p_lf_evt_ocrd_dt      IN     DATE
6776     )
6777   IS
6778     --
6779     l_package     VARCHAR2(80)   := g_package || '.calculate_comb_age_and_los';
6780     l_rate_result NUMBER;
6781     l_rate_cvg_result  NUMBER;
6782     l_rate_prem_result NUMBER;
6783     l_elig_result NUMBER;
6784     l_result      NUMBER;
6785     l_age         NUMBER;
6786     l_age_uom     VARCHAR2(30);
6787     l_rt_age      NUMBER;
6788     l_rt_age_uom  VARCHAR2(30);
6789     l_los         NUMBER;
6790     l_los_uom     VARCHAR2(30);
6791     l_rt_los      NUMBER;
6792     l_rt_los_uom  VARCHAR2(30);
6793     l_ok          BOOLEAN                                            := TRUE;
6794     l_break       VARCHAR2(30);
6795     l_elig_rec       ben_derive_part_and_rate_cache.g_cache_cla_rec_obj;
6796     l_rate_rec       ben_derive_part_and_rate_cache.g_cache_cla_rec_obj;
6797     l_rate_cvg_rec   ben_derive_part_and_rate_cache.g_cache_cla_rec_obj;
6798     l_rate_prem_rec  ben_derive_part_and_rate_cache.g_cache_cla_rec_obj;
6799     l_der_rec        ben_seeddata_object.g_derived_factor_info_rec;
6800     l_der_cvg_rec    ben_seeddata_object.g_derived_factor_info_rec;
6801     l_der_prem_rec   ben_seeddata_object.g_derived_factor_info_rec;
6802     l_rate        BOOLEAN                                            := FALSE;
6803     l_cvg         BOOLEAN                                            := FALSE;
6804     l_prem        BOOLEAN                                            := FALSE;
6805   --
6806   BEGIN
6807     --
6808    -- hr_utility.set_location('Entering ' || l_package,10);
6809 --
6810 -- Calculate Comb AGE LOS process
6811 -- ==============================
6812 -- The sequence of operations is as follows :
6813 -- 1) First check if freeze comb AGE LOS flag is on in which case
6814 --    we ignore the calculation and just return the values
6815 -- 2) Calculate eligibility derivable factors
6816 -- 3) Calculate rate derivable factors
6817 -- 3) Perform rounding
6818 -- 4) Test for min/max breach
6819 -- 5) If a breach did occur then create a ptl_ler_for_per.
6820 --
6821     IF bitand(p_comp_obj_tree_row.flag_bit_val
6822         ,ben_manage_life_events.g_cal_flag) <> 0 THEN
6823       --
6824      -- hr_utility.set_location('CAL for ELIG',10);
6825       IF p_comp_rec.frz_comb_age_and_los_flag = 'Y' THEN
6826         --
6827         -- No calculation required just return the frozen value
6828         --
6829         NULL;
6830       --
6831       ELSE
6832         --
6833         ben_derive_part_and_rate_cache.get_comb_elig(p_pgm_id=> p_pgm_id
6834          ,p_pl_id             => p_pl_id
6835          ,p_oipl_id           => p_oipl_id
6836          ,p_plip_id           => p_plip_id
6837          ,p_ptip_id           => p_ptip_id
6838          ,p_business_group_id => p_business_group_id
6839          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
6840                                   ,p_effective_date))
6841          ,p_rec               => l_elig_rec);
6842         --
6843         IF l_elig_rec.exist = 'Y' THEN
6844           --
6845           -- Eligibility stuff first
6846           --
6847           calculate_los
6848             (p_calculate_only_mode => p_calculate_only_mode
6849             ,p_comp_obj_tree_row   => p_comp_obj_tree_row
6850             ,p_empasg_row          => p_empasg_row
6851             ,p_benasg_row          => p_benasg_row
6852             ,p_pil_row             => p_pil_row
6853             ,p_curroipl_row        => p_curroipl_row
6854             ,p_curroiplip_row      => p_curroiplip_row
6855             ,p_person_id           => p_person_id
6856             ,p_business_group_id   => p_business_group_id
6857             ,p_pgm_id              => p_pgm_id
6858             ,p_pl_id               => p_pl_id
6859             ,p_oipl_id             => p_oipl_id
6860             ,p_plip_id             => p_plip_id
6861             ,p_ptip_id             => p_ptip_id
6862             ,p_oiplip_id           => p_oiplip_id
6863             ,p_los_fctr_id         => l_elig_rec.los_fctr_id
6864             ,p_comp_rec            => p_comp_rec
6865             ,p_effective_date      => p_effective_date
6866             ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
6867             ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
6868             );
6869           --
6870           calculate_age(p_comp_obj_tree_row=> p_comp_obj_tree_row
6871            ,p_per_row           => p_per_row
6872            ,p_empasg_row        => p_empasg_row
6873            ,p_benasg_row        => p_benasg_row
6874            ,p_pil_row           => p_pil_row
6875            ,p_curroipl_row      => p_curroipl_row
6876            ,p_curroiplip_row    => p_curroiplip_row
6877            ,p_person_id         => p_person_id
6878            ,p_business_group_id => p_business_group_id
6879            ,p_pgm_id            => p_pgm_id
6880            ,p_pl_id             => p_pl_id
6881            ,p_oipl_id           => p_oipl_id
6882            ,p_plip_id           => p_plip_id
6883            ,p_ptip_id           => p_ptip_id
6884            ,p_oiplip_id         => p_oiplip_id
6885            ,p_age_fctr_id       => l_elig_rec.age_fctr_id
6886            ,p_comp_rec          => p_comp_rec
6887            ,p_effective_date    => p_effective_date
6888            ,p_ptnl_ler_trtmt_cd => p_ptnl_ler_trtmt_cd
6889            ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
6890           --
6891           p_comp_rec.comb_los            := p_comp_rec.los_val;
6892           p_comp_rec.comb_age            := p_comp_rec.age_val;
6893           --
6894           l_elig_result                  := p_comp_rec.age_val + p_comp_rec.los_val;
6895           --
6896         --  p_comp_rec.cmbn_age_n_los_val  := l_elig_result;
6897           if g_debug then
6898             hr_utility.set_location('Combined value'||l_elig_result,100);
6899           end if;
6900           --
6901           IF p_comp_rec.cmbn_age_n_los_val IS NOT NULL THEN
6902             --
6903             --
6904            /* Bug 5478918 */
6905 	   ben_seeddata_object.get_object(p_rec=> l_der_rec);
6906            if (skip_min_max_le_calc(l_der_rec.drvdcal_id,
6907 	                         p_business_group_id,
6908                                  p_ptnl_ler_trtmt_cd,
6909                                  p_effective_date)) THEN
6910             --
6911            /* Simply return as no further calculations need to be done */
6912            hr_utility.set_location(l_package||' Do Nothing here.', 9877);
6913            null;
6914             --
6915            else
6916             --
6917              ben_derive_part_and_rate_cache.get_comb_elig(p_pgm_id=> p_pgm_id
6918               ,p_pl_id             => p_pl_id
6919               ,p_oipl_id           => p_oipl_id
6920               ,p_plip_id           => p_plip_id
6921               ,p_ptip_id           => p_ptip_id
6922               ,p_new_val           => l_elig_result
6923               ,p_old_val           => p_comp_rec.cmbn_age_n_los_val
6924               ,p_business_group_id => p_business_group_id
6925               ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
6926                                        ,p_effective_date))
6927               ,p_rec               => l_elig_rec);
6928         --
6929             IF benutils.min_max_breach(p_min_value=> NVL(l_elig_rec.cmbnd_min_val
6930                                                       ,-1)
6931                 ,p_max_value => NVL(l_elig_rec.cmbnd_max_val
6932                                  ,99999999)
6933                 ,p_new_value => l_elig_result
6934                 ,p_old_value => p_comp_rec.cmbn_age_n_los_val
6935                 ,p_break     => l_break) THEN
6936               --
6937               -- Now test if cached value breaks same boundary
6938               --
6939               l_ok  := TRUE;
6940               --
6941               IF     l_ok
6942                  AND no_life_event(p_lf_evt_ocrd_dt=> p_effective_date
6943                       ,p_person_id      => p_person_id
6944                       ,p_ler_id         => l_der_rec.drvdcal_id
6945                       ,p_effective_date => p_effective_date)
6946               THEN
6947                 --
6948                 --IF NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL'  THEN
6949                   --
6950                   -- We are not creating past life events
6951                   --
6952                  -- NULL;
6953                   --
6954               --  ELSE
6955                   create_ptl_ler
6956                     (p_calculate_only_mode => p_calculate_only_mode
6957                     ,p_ler_id=> l_der_rec.drvdcal_id
6958                     ,p_lf_evt_ocrd_dt    => p_effective_date
6959                     ,p_person_id         => p_person_id
6960                     ,p_business_group_id => p_business_group_id
6961                     ,p_effective_date    => p_effective_date
6962                     );
6963               --  END IF;
6964                 --
6965               END IF;
6966             --
6967             END IF;
6968            --
6969 	   END IF;  /* End Bug 5478918 */
6970            --
6971           END IF;
6972           --
6973           --Bug 3291639
6974           --
6975           p_comp_rec.cmbn_age_n_los_val  := l_elig_result;
6976         --
6977         END IF;
6978       --
6979       END IF;
6980     --
6981     END IF;
6982     --
6983    -- hr_utility.set_location('p_comp_rec ' || p_comp_rec.cmbn_age_n_los_val,10);
6984     --
6985     IF    bitand(p_comp_obj_tree_row.flag_bit_val
6986            ,ben_manage_life_events.g_cal_rt_flag) <> 0
6987        OR     p_oiplip_id IS NOT NULL
6988           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
6989                ,ben_manage_life_events.g_cal_rt_flag) <> 0 THEN
6990       --
6991      -- hr_utility.set_location('CAL for RT',10);
6992       IF p_comp_rec.rt_frz_comb_age_and_los_flag = 'Y' THEN
6993         --
6994         -- No calculation required just return the frozen value
6995         --
6996         NULL;
6997       --
6998       ELSE
6999         -- Rate calculation
7000         --
7001         ben_derive_part_and_rate_cache.get_comb_rate(p_pgm_id=> p_pgm_id
7002          ,p_pl_id             => p_pl_id
7003          ,p_oipl_id           => p_oipl_id
7004          ,p_plip_id           => p_plip_id
7005          ,p_ptip_id           => p_ptip_id
7006          ,p_oiplip_id         => p_oiplip_id
7007          ,p_business_group_id => p_business_group_id
7008          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7009                                   ,p_effective_date))
7010          ,p_rec               => l_rate_rec);
7011         --
7012         IF l_rate_rec.exist = 'Y' THEN
7013           --
7014           l_rate  := TRUE;
7015           --
7016           -- Rate stuff next
7017           --
7018           calculate_los
7019             (p_calculate_only_mode => p_calculate_only_mode
7020             ,p_comp_obj_tree_row   => p_comp_obj_tree_row
7021             ,p_empasg_row          => p_empasg_row
7022             ,p_benasg_row          => p_benasg_row
7023             ,p_pil_row             => p_pil_row
7024             ,p_curroipl_row        => p_curroipl_row
7025             ,p_curroiplip_row      => p_curroiplip_row
7026             ,p_person_id           => p_person_id
7027             ,p_business_group_id   => p_business_group_id
7028             ,p_pgm_id              => p_pgm_id
7029             ,p_pl_id               => p_pl_id
7030             ,p_oipl_id             => p_oipl_id
7031             ,p_plip_id             => p_plip_id
7032             ,p_ptip_id             => p_ptip_id
7033             ,p_oiplip_id           => p_oiplip_id
7034             ,p_los_fctr_id         => l_rate_rec.los_fctr_id
7035             ,p_comp_rec            => p_comp_rec
7036             ,p_effective_date      => p_effective_date
7037             ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
7038             ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
7039             );
7040           --
7041           calculate_age(p_comp_obj_tree_row=> p_comp_obj_tree_row
7042            ,p_per_row           => p_per_row
7043            ,p_empasg_row        => p_empasg_row
7044            ,p_benasg_row        => p_benasg_row
7045            ,p_pil_row           => p_pil_row
7046            ,p_curroipl_row      => p_curroipl_row
7047            ,p_curroiplip_row    => p_curroiplip_row
7048            ,p_person_id         => p_person_id
7049            ,p_business_group_id => p_business_group_id
7050            ,p_pgm_id            => p_pgm_id
7051            ,p_pl_id             => p_pl_id
7052            ,p_oipl_id           => p_oipl_id
7053            ,p_plip_id           => p_plip_id
7054            ,p_ptip_id           => p_ptip_id
7055            ,p_oiplip_id         => p_oiplip_id
7056            ,p_age_fctr_id       => l_rate_rec.age_fctr_id
7057            ,p_comp_rec          => p_comp_rec
7058            ,p_effective_date    => p_effective_date
7059            ,p_ptnl_ler_trtmt_cd => p_ptnl_ler_trtmt_cd
7060            ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
7061           --
7062           p_comp_rec.comb_rt_los            := p_comp_rec.rt_los_val;
7063           p_comp_rec.comb_rt_age            := p_comp_rec.rt_age_val;
7064           --
7065           l_rate_result                     := p_comp_rec.rt_los_val + p_comp_rec.rt_age_val;
7066           --
7067           -- p_comp_rec.rt_cmbn_age_n_los_val  := l_rate_result;
7068         --
7069         --
7070           ben_derive_part_and_rate_cache.get_comb_rate(p_pgm_id=> p_pgm_id
7071            ,p_pl_id             => p_pl_id
7072            ,p_oipl_id           => p_oipl_id
7073            ,p_plip_id           => p_plip_id
7074            ,p_ptip_id           => p_ptip_id
7075            ,p_oiplip_id         => p_oiplip_id
7076            ,p_new_val           => l_rate_result
7077            ,p_old_val           => p_comp_rec.rt_cmbn_age_n_los_val
7078            ,p_business_group_id => p_business_group_id
7079            ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7080                                     ,p_effective_date))
7081            ,p_rec               => l_rate_rec);
7082         --
7083         --
7084         END IF; -- l_rate_rec.exist
7085         --
7086         IF p_comp_rec.rt_cmbn_age_n_los_val IS NOT NULL THEN
7087           --
7088         /* Bug 5478918 */
7089 	ben_seeddata_object.get_object(p_rec=> l_der_rec);
7090         if (skip_min_max_le_calc(l_der_rec.drvdcal_id,
7091 	                         p_business_group_id,
7092                                  p_ptnl_ler_trtmt_cd,
7093                                  p_effective_date)) THEN
7094         --
7095         /* Simply return as no further calculations need to be done */
7096           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
7097           null;
7098         --
7099         else
7100         --
7101           IF benutils.min_max_breach(p_min_value=> NVL(l_rate_rec.cmbnd_min_val
7102                                                     ,-1)
7103               ,p_max_value => NVL(l_rate_rec.cmbnd_max_val
7104                                ,99999999)
7105               ,p_new_value => l_rate_result
7106               ,p_old_value => p_comp_rec.rt_cmbn_age_n_los_val
7107               ,p_break     => l_break) THEN
7108             --
7109             --
7110             IF  no_life_event(p_lf_evt_ocrd_dt=>nvl(g_fonm_cvg_strt_dt, p_effective_date)
7111                     ,p_person_id      => p_person_id
7112                     ,p_ler_id         => l_der_rec.drvdcal_id
7113                     ,p_effective_date => p_effective_date)
7114             THEN
7115               --
7116              -- IF NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL'  THEN
7117                 --
7118                 -- We are not creating past life events
7119                 --
7120               --  NULL;
7121                 --
7122              -- ELSE
7123                 -- tilak to be discussed about date
7124                 create_ptl_ler
7125                 (p_calculate_only_mode => p_calculate_only_mode
7126                 ,p_ler_id              => l_der_rec.drvdcal_id
7127                 ,p_lf_evt_ocrd_dt      => nvl(g_fonm_cvg_strt_dt,p_effective_date)
7128                 ,p_person_id           => p_person_id
7129                 ,p_business_group_id   => p_business_group_id
7130                 ,p_effective_date      => p_effective_date
7131                 );
7132                 --
7133             --  END IF;
7134               --
7135             END IF;
7136           --
7137           END IF;
7138          --
7139 	 END IF;  /* End Bug 5478918 */
7140          --
7141         END IF; --p_comp_rec.rt_cmbn_age_n_los_val
7142         --
7143         -- End of Rate routine
7144         --
7145         -- Try and find a coverage
7146         --
7147         IF    p_oipl_id IS NOT NULL
7148              OR p_pl_id IS NOT NULL
7149              OR p_plip_id IS NOT NULL THEN
7150           --
7151           ben_derive_part_and_rate_cvg.get_comb_rate(p_pl_id=> p_pl_id
7152              ,p_oipl_id           => p_oipl_id
7153              ,p_plip_id           => p_plip_id
7154              ,p_business_group_id => p_business_group_id
7155              ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7156                                       ,p_effective_date))
7157              ,p_rec               => l_rate_cvg_rec);
7158             --
7159           IF l_rate_cvg_rec.exist = 'Y' THEN
7160             --
7161             calculate_los
7162               (p_calculate_only_mode => p_calculate_only_mode
7163               ,p_comp_obj_tree_row   => p_comp_obj_tree_row
7164               ,p_empasg_row          => p_empasg_row
7165               ,p_benasg_row          => p_benasg_row
7166               ,p_pil_row             => p_pil_row
7167               ,p_curroipl_row        => p_curroipl_row
7168               ,p_curroiplip_row      => p_curroiplip_row
7169               ,p_person_id           => p_person_id
7170               ,p_business_group_id   => p_business_group_id
7171               ,p_pgm_id              => p_pgm_id
7172               ,p_pl_id               => p_pl_id
7173               ,p_oipl_id             => p_oipl_id
7174               ,p_plip_id             => p_plip_id
7175               ,p_ptip_id             => p_ptip_id
7176               ,p_oiplip_id           => p_oiplip_id
7177               ,p_los_fctr_id         => l_rate_cvg_rec.los_fctr_id
7178               ,p_comp_rec            => p_comp_rec
7179               ,p_effective_date      => p_effective_date
7180               ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
7181               ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
7182               );
7183               --
7184             calculate_age(p_comp_obj_tree_row=> p_comp_obj_tree_row
7185               ,p_per_row           => p_per_row
7186               ,p_empasg_row        => p_empasg_row
7187               ,p_benasg_row        => p_benasg_row
7188               ,p_pil_row           => p_pil_row
7189               ,p_curroipl_row      => p_curroipl_row
7190               ,p_curroiplip_row    => p_curroiplip_row
7191               ,p_person_id         => p_person_id
7192               ,p_business_group_id => p_business_group_id
7193               ,p_pgm_id            => p_pgm_id
7194               ,p_pl_id             => p_pl_id
7195               ,p_oipl_id           => p_oipl_id
7196               ,p_plip_id           => p_plip_id
7197               ,p_ptip_id           => p_ptip_id
7198               ,p_oiplip_id         => p_oiplip_id
7199               ,p_age_fctr_id       => l_rate_cvg_rec.age_fctr_id
7200               ,p_comp_rec          => p_comp_rec
7201               ,p_effective_date    => p_effective_date
7202               ,p_ptnl_ler_trtmt_cd => p_ptnl_ler_trtmt_cd
7203               ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
7204              --
7205             p_comp_rec.comb_rt_los            := p_comp_rec.rt_los_val;
7206             p_comp_rec.comb_rt_age            := p_comp_rec.rt_age_val;
7207             --
7208             l_rate_cvg_result                     := p_comp_rec.rt_los_val + p_comp_rec.rt_age_val;
7209             --
7210             -- p_comp_rec.rt_cmbn_age_n_los_val  := l_rate_cvg_result;
7211             --
7212             --
7213             ben_derive_part_and_rate_cvg.get_comb_rate(p_pl_id=> p_pl_id
7214              ,p_oipl_id           => p_oipl_id
7215              ,p_plip_id           => p_plip_id
7216              ,p_old_val           => p_comp_rec.rt_cmbn_age_n_los_val
7217              ,p_new_val           => l_rate_cvg_result
7218              ,p_business_group_id => p_business_group_id
7219              ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7220                                       ,p_effective_date))
7221              ,p_rec               => l_rate_cvg_rec);
7222             --
7223           END IF; -- l_rate_cvg_rec.exist
7224           --
7225         END IF ; -- oipl_id for coverage
7226         --
7227         IF p_comp_rec.rt_cmbn_age_n_los_val IS NOT NULL THEN
7228           --
7229         /* Bug 5478918 */
7230 	ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
7231         if (skip_min_max_le_calc(l_der_cvg_rec.drvdcal_id,
7232 	                         p_business_group_id,
7233                                  p_ptnl_ler_trtmt_cd,
7234                                  p_effective_date)) THEN
7235         --
7236         /* Simply return as no further calculations need to be done */
7237           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
7238           null;
7239         --
7240         else
7241         --
7242           IF benutils.min_max_breach(p_min_value=> NVL(l_rate_cvg_rec.cmbnd_min_val
7243                                                     ,-1)
7244               ,p_max_value => NVL(l_rate_cvg_rec.cmbnd_max_val
7245                                ,99999999)
7246               ,p_new_value => l_rate_cvg_result
7247               ,p_old_value => p_comp_rec.rt_cmbn_age_n_los_val
7248               ,p_break     => l_break) THEN
7249             --
7250             IF no_life_event(p_lf_evt_ocrd_dt=> nvl(g_fonm_cvg_strt_dt,p_effective_date)
7251                     ,p_person_id      => p_person_id
7252                     ,p_ler_id         => l_der_cvg_rec.drvdcal_id
7253                     ,p_effective_date => p_effective_date)
7254             THEN
7255               --
7256               --
7257              -- IF NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL'  THEN
7258                 --
7259                 -- We are not creating past life events
7260                 --
7261              --   NULL;
7262                 --
7263              -- ELSE
7264                 --
7265                 create_ptl_ler
7266                   (p_calculate_only_mode => p_calculate_only_mode
7267                   ,p_ler_id              => l_der_cvg_rec.drvdcal_id
7268                   ,p_lf_evt_ocrd_dt      => nvl(g_fonm_cvg_strt_dt,p_effective_date)
7269                   ,p_person_id           => p_person_id
7270                   ,p_business_group_id   => p_business_group_id
7271                   ,p_effective_date      => p_effective_date
7272                   );
7273              -- END IF;
7274               --
7275             END IF;
7276           --
7277           END IF;
7278          --
7279 	 END IF;  /* End Bug 5478918 */
7280          --
7281         END IF;
7282         --
7283         -- End of coverage
7284         -- Start of Premium
7285         --
7286         IF  p_oipl_id IS NOT NULL
7287             OR p_pl_id IS NOT NULL THEN
7288           --
7289           -- Try and find a premium
7290           --
7291           ben_derive_part_and_rate_prem.get_comb_rate(
7292                 p_pl_id             => p_pl_id
7293                ,p_oipl_id           => p_oipl_id
7294                ,p_business_group_id => p_business_group_id
7295                ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7296                                         ,p_effective_date))
7297                ,p_rec               => l_rate_prem_rec);
7298               --
7299           IF l_rate_prem_rec.exist = 'Y' THEN
7300             --
7301             calculate_los
7302               (p_calculate_only_mode => p_calculate_only_mode
7303               ,p_comp_obj_tree_row   => p_comp_obj_tree_row
7304               ,p_empasg_row          => p_empasg_row
7305               ,p_benasg_row          => p_benasg_row
7306               ,p_pil_row             => p_pil_row
7307               ,p_curroipl_row        => p_curroipl_row
7308               ,p_curroiplip_row      => p_curroiplip_row
7309               ,p_person_id           => p_person_id
7310               ,p_business_group_id   => p_business_group_id
7311               ,p_pgm_id              => p_pgm_id
7312               ,p_pl_id               => p_pl_id
7313               ,p_oipl_id             => p_oipl_id
7314               ,p_plip_id             => p_plip_id
7315               ,p_ptip_id             => p_ptip_id
7316               ,p_oiplip_id           => p_oiplip_id
7317               ,p_los_fctr_id         => l_rate_prem_rec.los_fctr_id
7318               ,p_comp_rec            => p_comp_rec
7319               ,p_effective_date      => p_effective_date
7320               ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
7321               ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
7322               );
7323             --
7324             calculate_age(p_comp_obj_tree_row=> p_comp_obj_tree_row
7325              ,p_per_row           => p_per_row
7326              ,p_empasg_row        => p_empasg_row
7327              ,p_benasg_row        => p_benasg_row
7328              ,p_pil_row           => p_pil_row
7329              ,p_curroipl_row      => p_curroipl_row
7330              ,p_curroiplip_row    => p_curroiplip_row
7331              ,p_person_id         => p_person_id
7332              ,p_business_group_id => p_business_group_id
7333              ,p_pgm_id            => p_pgm_id
7334              ,p_pl_id             => p_pl_id
7335              ,p_oipl_id           => p_oipl_id
7336              ,p_plip_id           => p_plip_id
7337              ,p_ptip_id           => p_ptip_id
7338              ,p_oiplip_id         => p_oiplip_id
7339              ,p_age_fctr_id       => l_rate_prem_rec.age_fctr_id
7340              ,p_comp_rec          => p_comp_rec
7341              ,p_effective_date    => p_effective_date
7342              ,p_ptnl_ler_trtmt_cd => p_ptnl_ler_trtmt_cd
7343              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
7344             --
7345             p_comp_rec.comb_rt_los            := p_comp_rec.rt_los_val;
7346             p_comp_rec.comb_rt_age            := p_comp_rec.rt_age_val;
7347             --
7348             l_rate_prem_result                     := p_comp_rec.rt_los_val + p_comp_rec.rt_age_val;
7349             --
7350             -- p_comp_rec.rt_cmbn_age_n_los_val  := l_rate_prem_result;
7351             --
7352             --
7353             ben_derive_part_and_rate_prem.get_comb_rate(
7354               p_pl_id             => p_pl_id
7355              ,p_oipl_id           => p_oipl_id
7356              ,p_new_val           => l_rate_prem_result
7357              ,p_old_val           => p_comp_rec.rt_cmbn_age_n_los_val
7358              ,p_business_group_id => p_business_group_id
7359              ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7360                                       ,p_effective_date))
7361              ,p_rec               => l_rate_prem_rec);
7362             --
7363           END IF; -- l_rate_prem_rec.exist
7364           --
7365         END IF ; -- oipl_id for premium
7366         --
7367         IF p_comp_rec.rt_cmbn_age_n_los_val IS NOT NULL THEN
7368           --
7369         /* Bug 5478918 */
7370 	ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
7371         if (skip_min_max_le_calc(l_der_prem_rec.drvdcal_id,
7372 	                         p_business_group_id,
7373                                  p_ptnl_ler_trtmt_cd,
7374                                  p_effective_date)) THEN
7375         --
7376         /* Simply return as no further calculations need to be done */
7377           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
7378           null;
7379         --
7380         else
7381         --
7382           IF benutils.min_max_breach(p_min_value=> NVL(l_rate_prem_rec.cmbnd_min_val
7383                                                     ,-1)
7384               ,p_max_value => NVL(l_rate_prem_rec.cmbnd_max_val
7385                                ,99999999)
7386               ,p_new_value => l_rate_prem_result
7387               ,p_old_value => p_comp_rec.rt_cmbn_age_n_los_val
7388               ,p_break     => l_break) THEN
7389             --
7390             IF  no_life_event(p_lf_evt_ocrd_dt=> nvl(g_fonm_cvg_strt_dt,p_effective_date)
7391                     ,p_person_id      => p_person_id
7392                     ,p_ler_id         => l_der_prem_rec.drvdcal_id
7393                     ,p_effective_date => p_effective_date)
7394             THEN
7395               --
7396               --
7397               --IF NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL'  THEN
7398                 --
7399                 -- We are not creating past life events
7400                 --
7401               -- NULL;
7402                 --
7403               -- ELSE
7404                 --
7405                 create_ptl_ler
7406                   (p_calculate_only_mode => p_calculate_only_mode
7407                   ,p_ler_id              => l_der_prem_rec.drvdcal_id
7408                   ,p_lf_evt_ocrd_dt      => nvl(g_fonm_cvg_strt_dt,p_effective_date)
7409                   ,p_person_id           => p_person_id
7410                   ,p_business_group_id   => p_business_group_id
7411                   ,p_effective_date      => p_effective_date
7412                   );
7413               --END IF;
7414               --
7415             END IF;
7416           --
7417           END IF;
7418          --
7419 	 END IF;  /* End Bug 5478918 */
7420          --
7421         END IF;
7422         --
7423         IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
7424             --
7425             p_comp_rec.rt_cmbn_age_n_los_val  := NULL;
7426             --hr_utility.set_location(' Step 27',10);
7427             --
7428           --
7429         ELSIF l_rate_result is NOT NULL THEN
7430             --
7431             --hr_utility.set_location(' Step 28',10);
7432             p_comp_rec.rt_cmbn_age_n_los_val := l_rate_result;
7433             --
7434           --
7435         ELSIF l_rate_cvg_result is NOT NULL then
7436             --
7437             --hr_utility.set_location(' Step 29',10);
7438             p_comp_rec.rt_cmbn_age_n_los_val := l_rate_cvg_result;
7439           --
7440         ELSIF l_rate_prem_result is NOT NULL THEN
7441             --
7442             --hr_utility.set_location(' Step 30',10);
7443             p_comp_rec.rt_cmbn_age_n_los_val:= l_rate_prem_result;
7444             --
7445         END IF;
7446       --
7447       END IF; --  p_comp_rec.rt_frz_comb_age_and_los_flag
7448     --
7449     END IF;
7450     --
7451    -- hr_utility.set_location('Leaving ' || l_package,10);
7452   --
7453   END calculate_comb_age_and_los;
7454 --
7455   PROCEDURE percent_fulltime_min_max
7456     (p_calculate_only_mode in     boolean default false
7457     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
7458     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
7459    --,p_rate_rec           IN OUT ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
7460     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
7461     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
7462     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
7463     ,p_person_id           IN     NUMBER
7464     ,p_pgm_id              IN     NUMBER
7465     ,p_pl_id               IN     NUMBER
7466     ,p_oipl_id             IN     NUMBER
7467     ,p_oiplip_id           IN     NUMBER
7468     ,p_plip_id             IN     NUMBER
7469     ,p_ptip_id             IN     NUMBER
7470     ,p_business_group_id   IN     NUMBER
7471     ,p_ler_id              IN     NUMBER
7472     ,p_min_value           IN     NUMBER
7473     ,p_max_value           IN     NUMBER
7474     ,p_new_value           IN     NUMBER
7475     ,p_old_value           IN     NUMBER
7476   --  ,p_uom                 IN     VARCHAR2
7477  --   ,p_subtract_date       IN     DATE
7478  --   ,p_det_cd              IN     VARCHAR2
7479  --   ,p_formula_id          IN     NUMBER DEFAULT NULL
7480     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
7481     ,p_effective_date      IN     DATE
7482     ,p_lf_evt_ocrd_dt      IN     DATE
7483     --,p_comp_src_cd         IN     VARCHAR2
7484     --,p_bnfts_bal_id        IN     NUMBER
7485     )
7486     IS
7487     --
7488     l_package            VARCHAR2(80)        := g_package || '.percent_fulltime_min_max';
7489     l_break              VARCHAR2(30);
7490     l_det_cd             VARCHAR2(30);
7491     l_lf_evt_ocrd_dt     DATE;
7492     l_new_lf_evt_ocrd_dt DATE;
7493     l_start_date         DATE;
7494     l_rec                ben_person_object.g_person_date_info_rec;
7495     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
7496     --
7497   BEGIN
7498       if g_debug then
7499         hr_utility.set_location('Entering percent_fulltime_min_max ', 10 );
7500       end if;
7501       /* Bug 5478918 */
7502         if (skip_min_max_le_calc(p_ler_id,
7503 	                         p_business_group_id,
7504                                  p_ptnl_ler_trtmt_cd,
7505                                  p_effective_date)) THEN
7506         --
7507         /* Simply return as no further calculations need to be done */
7508           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
7509           RETURN;
7510         end if;
7511       /* End Bug 5478918 */
7512       if g_debug then
7513         hr_utility.set_location('p_max_value '||p_max_value,10);
7514       end if;
7515       if g_debug then
7516         hr_utility.set_location('p_min_value '||p_min_value,10);
7517       end if;
7518       if g_debug then
7519         hr_utility.set_location('p_new_value '||p_new_value,10);
7520       end if;
7521       if g_debug then
7522         hr_utility.set_location('p_old_value '||p_old_value,10);
7523       end if;
7524           --
7525       IF benutils.min_max_breach(p_min_value=> NVL( p_min_value
7526                                                     ,-1)
7527               ,p_max_value => NVL( p_max_value
7528                                ,99999999)
7529               ,p_new_value => p_new_value
7530               ,p_old_value => p_old_value
7531               ,p_break     => l_break
7532               ,p_decimal_level => 'Y') THEN
7533             --
7534             -- Create potential ler for per if the min_max_breach occured
7535             --
7536             l_lf_evt_ocrd_dt  :=
7537               get_percent_date(p_empasg_row=> p_empasg_row
7538                ,p_benasg_row     => p_benasg_row
7539                ,p_person_id      => p_person_id
7540                ,p_percent        => p_new_value
7541                ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7542                                      ,p_effective_date))
7543                ,p_min            => p_min_value
7544                ,p_max            => p_max_value
7545                ,p_break          => l_break);
7546             --
7547             IF   (  l_lf_evt_ocrd_dt < p_effective_date
7548                AND NVL(p_ptnl_ler_trtmt_cd
7549                     ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
7550               --
7551               -- We are not creating life events in this case
7552               --
7553               NULL;
7554             --
7555             ELSE
7556               --
7557               --ben_seeddata_object.get_object(p_rec=> l_der_rec);
7558               --
7559               IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
7560                   ,p_person_id      => p_person_id
7561                   ,p_ler_id         => p_ler_id
7562                   ,p_effective_date => p_effective_date)
7563               THEN
7564                 --
7565                 --
7566                 IF NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL'  THEN
7567                   --
7568                   -- We are not creating past life events
7569                   --
7570                   NULL;
7571                   --
7572                 ELSE
7573                   --
7574                   create_ptl_ler
7575                     (p_calculate_only_mode => p_calculate_only_mode
7576                     ,p_ler_id              => p_ler_id
7577                     ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
7578                     ,p_person_id           => p_person_id
7579                     ,p_business_group_id   => p_business_group_id
7580                     ,p_effective_date      => p_effective_date
7581                     );
7582                   --
7583                 END IF;
7584                 --
7585               END IF;
7586             --
7587             END IF;
7588           --
7589           END IF;
7590   END percent_fulltime_min_max ;
7591 
7592   PROCEDURE calculate_percent_fulltime
7593     (p_calculate_only_mode in            boolean default false
7594     ,p_comp_obj_tree_row   IN            ben_manage_life_events.g_cache_proc_objects_rec
7595     ,p_empasg_row          IN            per_all_assignments_f%ROWTYPE
7596     ,p_benasg_row          IN            per_all_assignments_f%ROWTYPE
7597     ,p_pil_row             IN            ben_per_in_ler%ROWTYPE
7598     ,p_curroipl_row        IN            ben_cobj_cache.g_oipl_inst_row
7599     ,p_curroiplip_row      IN            ben_cobj_cache.g_oiplip_inst_row
7600     ,p_person_id           IN            NUMBER
7601     ,p_business_group_id   IN            NUMBER
7602     ,p_pgm_id              IN            NUMBER
7603     ,p_pl_id               IN            NUMBER
7604     ,p_oipl_id             IN            NUMBER
7605     ,p_plip_id             IN            NUMBER
7606     ,p_ptip_id             IN            NUMBER
7607     ,p_oiplip_id           IN            NUMBER
7608     ,p_ptnl_ler_trtmt_cd   IN            VARCHAR2
7609     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
7610     ,p_effective_date      IN            DATE
7611     ,p_lf_evt_ocrd_dt      IN            DATE
7612     )
7613   IS
7614     --
7615     l_package        VARCHAR2(80)
7616                                  := g_package || '.calculate_percent_fulltime';
7617     l_elig_result    NUMBER;
7618     l_rate_result    NUMBER;
7619     l_rate_cvg_result    NUMBER;
7620     l_rate_prem_result   NUMBER;
7621     l_break          VARCHAR2(30);
7622     l_lf_evt_ocrd_dt DATE;
7623     l_elig_rec       ben_derive_part_and_rate_cache.g_cache_pff_rec_obj;
7624     l_rate_rec       ben_derive_part_and_rate_cache.g_cache_pff_rec_obj;
7625     l_rate_cvg_rec   ben_derive_part_and_rate_cache.g_cache_pff_rec_obj;
7626     l_rate_prem_rec  ben_derive_part_and_rate_cache.g_cache_pff_rec_obj;
7627     l_rec            ben_person_object.g_person_fte_info_rec;
7628     l_der_rec        ben_seeddata_object.g_derived_factor_info_rec;
7629     l_der_cvg_rec    ben_seeddata_object.g_derived_factor_info_rec;
7630     l_der_prem_rec   ben_seeddata_object.g_derived_factor_info_rec;
7631     l_ass_rec        per_all_assignments_f%ROWTYPE;
7632     l_rate           BOOLEAN                                         := FALSE;
7633     l_cvg            BOOLEAN                                         := FALSE;
7634     l_prem           BOOLEAN                                         := FALSE;
7635   --
7636   BEGIN
7637     --
7638     hr_utility.set_location('Entering ' || l_package,10);
7639 --
7640 -- Calculate PCT FT process
7641 -- =====================
7642 -- The sequence of operations is as follows :
7643 -- 1) First check if freeze PCT FT flag is on in which case
7644 --    we ignore the calculation and just return the values
7645 -- 2) Calculate eligibility derivable factors
7646 -- 3) Calculate rate derivable factors
7647 -- 3) Sum assignment FTE information
7648 -- 4) Perform rounding
7649 -- 5) Test for min/max breach
7650 -- 6) If a breach did occur then create a ptl_ler_for_per.
7651 --
7652     IF bitand(p_comp_obj_tree_row.flag_bit_val
7653         ,ben_manage_life_events.g_pft_flag) <> 0 THEN
7654       --
7655      -- hr_utility.set_location('PFT for ELIG',10);
7656       IF p_comp_rec.frz_pct_fl_tm_flag = 'Y' THEN
7657         --
7658         -- No calulation required just return the frozen value
7659         --
7660         NULL;
7661       --
7662       ELSE
7663         --
7664         ben_derive_part_and_rate_cache.get_pct_elig(p_pgm_id=> p_pgm_id
7665          ,p_pl_id             => p_pl_id
7666          ,p_oipl_id           => p_oipl_id
7667          ,p_plip_id           => p_plip_id
7668          ,p_ptip_id           => p_ptip_id
7669          ,p_business_group_id => p_business_group_id
7670          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7671                                   ,p_effective_date))
7672          ,p_rec               => l_elig_rec);
7673         --
7674         IF l_elig_rec.exist = 'Y' THEN
7675           --
7676           IF p_empasg_row.assignment_id IS NULL THEN
7677             --
7678             l_ass_rec  := p_benasg_row;
7679           --
7680           ELSE
7681             --
7682             l_ass_rec  := p_empasg_row;
7683           --
7684           END IF;
7685           --
7686           -- Check if any assignment exists
7687           --
7688           IF l_ass_rec.assignment_id IS NOT NULL THEN
7689             --
7690             ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
7691              ,p_rec           => l_rec);
7692             --
7693             IF l_elig_rec.use_prmry_asnt_only_flag = 'Y' THEN
7694               --
7695               -- Get percent fulltime value for persons primary assignment
7696               --
7697               l_elig_result  := l_rec.fte;
7698             --
7699             ELSIF l_elig_rec.use_sum_of_all_asnts_flag = 'Y' THEN
7700               --
7701               -- Get percent fulltime figure for all persons assignments
7702               --
7703               l_elig_result  := l_rec.total_fte;
7704             --
7705             END IF;
7706             --
7707             IF    l_elig_rec.rndg_cd IS NOT NULL
7708                OR l_elig_rec.rndg_rl IS NOT NULL THEN
7709               --
7710               l_elig_result  :=
7711                 benutils.do_rounding(p_rounding_cd=> l_elig_rec.rndg_cd
7712                  ,p_rounding_rl    => l_elig_rec.rndg_rl
7713                  ,p_value          => l_elig_result
7714                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
7715                                        ,p_effective_date));
7716             --
7717             END IF;
7718             --
7719          /* Bug 5478918 */
7720           --
7721           ben_seeddata_object.get_object(p_rec=> l_der_rec);
7722 	  if (skip_min_max_le_calc(l_der_rec.drvdtpf_id,
7723 	                           p_business_group_id,
7724                                    p_ptnl_ler_trtmt_cd,
7725                                    p_effective_date)) THEN
7726             --
7727             /* Simply return as no further calculations need to be done */
7728             hr_utility.set_location(l_package||' Do Nothing here.', 9877);
7729             null;
7730             --
7731           else
7732 	    --
7733             ben_derive_part_and_rate_cache.get_pct_elig(p_pgm_id=> p_pgm_id
7734              ,p_pl_id             => p_pl_id
7735              ,p_oipl_id           => p_oipl_id
7736              ,p_plip_id           => p_plip_id
7737              ,p_ptip_id           => p_ptip_id
7738              ,p_new_val           => l_elig_result
7739              ,p_old_val           => p_comp_rec.pct_fl_tm_val
7740              ,p_business_group_id => p_business_group_id
7741              ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7742                                       ,p_effective_date))
7743              ,p_rec               => l_elig_rec);
7744         --
7745             IF benutils.min_max_breach(p_min_value=> NVL(l_elig_rec.mn_pct_val
7746                                                       ,-1)
7747                 ,p_max_value => NVL(l_elig_rec.mx_pct_val
7748                                  ,99999999)
7749                 ,p_new_value => l_elig_result
7750                 ,p_old_value => p_comp_rec.pct_fl_tm_val
7751                 ,p_break     => l_break
7752                 ,p_decimal_level => 'Y') THEN
7753               --
7754               l_lf_evt_ocrd_dt  :=
7755                 get_percent_date(p_empasg_row=> p_empasg_row
7756                  ,p_benasg_row     => p_benasg_row
7757                  ,p_person_id      => p_person_id
7758                  ,p_percent        => l_elig_result
7759                  ,p_effective_date => NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7760                                        ,p_effective_date))
7761                  ,p_min            => l_elig_rec.mn_pct_val
7762                  ,p_max            => l_elig_rec.mx_pct_val
7763                  ,p_break          => l_break);
7764               --
7765               IF   (  l_lf_evt_ocrd_dt < p_effective_date
7766                  AND NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNR') THEN
7767                 --
7768                 -- We are not creating life events in this case
7769                 --
7770                 NULL;
7771               --
7772               ELSE
7773                 --
7774                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
7775                     ,p_person_id      => p_person_id
7776                     ,p_ler_id         => l_der_rec.drvdtpf_id
7777                     ,p_effective_date => p_effective_date)
7778                 THEN
7779                   --
7780                   create_ptl_ler
7781                     (p_calculate_only_mode => p_calculate_only_mode
7782                     ,p_ler_id              => l_der_rec.drvdtpf_id
7783                     ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
7784                     ,p_person_id           => p_person_id
7785                     ,p_business_group_id   => p_business_group_id
7786                     ,p_effective_date      => p_effective_date
7787                     );
7788                   --
7789                 END IF;
7790               --
7791               END IF;
7792             --
7793             END IF;
7794             --
7795           END IF;   /* End Bug 5478918 */
7796 	  --
7797             p_comp_rec.pct_fl_tm_val  := l_elig_result;
7798           --
7799           ELSE
7800             --
7801             p_comp_rec.pct_fl_tm_val  := NULL;
7802           --
7803           END IF;
7804         --
7805         ELSE
7806           --
7807           p_comp_rec.pct_fl_tm_val  := NULL;
7808         --
7809         END IF;
7810       --
7811       END IF;
7812     --
7813     END IF;
7814     --
7815     IF    bitand(p_comp_obj_tree_row.flag_bit_val
7816            ,ben_manage_life_events.g_pft_rt_flag) <> 0
7817        OR     p_oiplip_id IS NOT NULL
7818           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
7819                ,ben_manage_life_events.g_pft_rt_flag) <> 0 THEN
7820       --
7821      -- hr_utility.set_location('PFT for RT',10);
7822       IF p_comp_rec.rt_frz_pct_fl_tm_flag = 'Y' THEN
7823         --
7824         -- No calulation required just return the frozen value
7825         --
7826         NULL;
7827       --
7828       ELSE
7829         --
7830         ben_derive_part_and_rate_cache.get_pct_rate(p_pgm_id=> p_pgm_id
7831          ,p_pl_id             => p_pl_id
7832          ,p_oipl_id           => p_oipl_id
7833          ,p_plip_id           => p_plip_id
7834          ,p_ptip_id           => p_ptip_id
7835          ,p_oiplip_id         => p_oiplip_id
7836          ,p_business_group_id => p_business_group_id
7837          ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7838                                   ,p_effective_date))
7839          ,p_rec               => l_rate_rec);
7840         --
7841         IF l_rate_rec.exist = 'Y' THEN
7842           --
7843           l_rate  := TRUE;
7844           --
7845           IF p_empasg_row.assignment_id IS NULL THEN
7846             --
7847             l_ass_rec  := p_benasg_row;
7848           --
7849           ELSE
7850             --
7851             l_ass_rec  := p_empasg_row;
7852           --
7853           END IF;
7854           --
7855           ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
7856            ,p_rec           => l_rec);
7857 
7858           IF l_rate_rec.use_prmry_asnt_only_flag = 'Y' THEN
7859             --
7860             -- Get percent fulltime value for persons primary assignment
7861             --
7862             l_rate_result  := l_rec.fte;
7863           --
7864           ELSIF l_rate_rec.use_sum_of_all_asnts_flag = 'Y' THEN
7865             --
7866             -- Get percent fulltime figure for all persons assignments
7867             --
7868             l_rate_result  := l_rec.total_fte;
7869           --
7870           END IF;
7871           --
7872           IF    l_rate_rec.rndg_cd IS NOT NULL
7873              OR l_rate_rec.rndg_rl IS NOT NULL THEN
7874             --
7875             l_rate_result  :=
7876               benutils.do_rounding(p_rounding_cd=> l_rate_rec.rndg_cd
7877                ,p_rounding_rl    => l_rate_rec.rndg_rl
7878                ,p_value          => l_rate_result
7879                ,p_effective_date => NVL(p_lf_evt_ocrd_dt
7880                                      ,p_effective_date));
7881           --
7882           END IF;
7883           --
7884           IF l_rate_result is not null THEN
7885             --
7886             ben_derive_part_and_rate_cache.get_pct_rate(p_pgm_id=> p_pgm_id
7887              ,p_pl_id             => p_pl_id
7888              ,p_oipl_id           => p_oipl_id
7889              ,p_plip_id           => p_plip_id
7890              ,p_ptip_id           => p_ptip_id
7891              ,p_oiplip_id         => p_oiplip_id
7892              ,p_new_val           => l_rate_result
7893              ,p_old_val           => p_comp_rec.rt_pct_fl_tm_val
7894              ,p_business_group_id => p_business_group_id
7895              ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7896                                       ,p_effective_date))
7897              ,p_rec               => l_rate_rec);
7898             --
7899             ben_seeddata_object.get_object(p_rec=> l_der_rec);
7900             --
7901             percent_fulltime_min_max
7902                    (p_calculate_only_mode =>p_calculate_only_mode
7903                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
7904                    ,p_curroiplip_row      =>p_curroiplip_row
7905                    ,p_comp_rec            =>p_comp_rec
7906                    ,p_empasg_row          =>p_empasg_row
7907                    ,p_benasg_row          =>p_benasg_row
7908                    ,p_person_id           =>p_person_id
7909                    ,p_pgm_id              =>p_pgm_id
7910                    ,p_pl_id               =>p_pl_id
7911                    ,p_oipl_id             =>p_oipl_id
7912                    ,p_oiplip_id           =>p_oiplip_id
7913                    ,p_plip_id             =>p_plip_id
7914                    ,p_ptip_id             =>p_ptip_id
7915                    ,p_business_group_id   =>p_business_group_id
7916                    ,p_ler_id              =>l_der_rec.drvdtpf_id
7917                    ,p_min_value           =>l_rate_rec.mn_pct_val
7918                    ,p_max_value           =>l_rate_rec.mx_pct_val
7919                    ,p_new_value           =>l_rate_result
7920                    ,p_old_value           =>p_comp_rec.rt_pct_fl_tm_val
7921                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
7922                    ,p_effective_date      =>p_effective_date
7923                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
7924                   ) ;
7925           END IF; -- l_rate_result
7926           --
7927         END IF ; -- l_rate_rec.exist
7928         --
7929         -- Try and find a coverage first
7930         --
7931         IF    p_oipl_id IS NOT NULL
7932           OR p_pl_id IS NOT NULL
7933           OR p_plip_id IS NOT NULL THEN
7934           --
7935           ben_derive_part_and_rate_cvg.get_pct_rate(p_pl_id=> p_pl_id
7936              ,p_oipl_id           => p_oipl_id
7937              ,p_plip_id           => p_plip_id
7938              ,p_business_group_id => p_business_group_id
7939              ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7940                                       ,p_effective_date))
7941              ,p_rec               => l_rate_cvg_rec);
7942             --
7943           IF l_rate_cvg_rec.exist = 'Y' THEN
7944             --
7945             l_cvg  := TRUE;
7946             --
7947             IF p_empasg_row.assignment_id IS NULL THEN
7948               --
7949               l_ass_rec  := p_benasg_row;
7950               --
7951             ELSE
7952               --
7953               l_ass_rec  := p_empasg_row;
7954               --
7955             END IF;
7956             --
7957             ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
7958                                        ,p_rec           => l_rec);
7959 
7960             IF l_rate_cvg_rec.use_prmry_asnt_only_flag = 'Y' THEN
7961               --
7962               -- Get percent fulltime value for persons primary assignment
7963               --
7964               l_rate_cvg_result  := l_rec.fte;
7965               --
7966             ELSIF l_rate_rec.use_sum_of_all_asnts_flag = 'Y' THEN
7967               --
7968               -- Get percent fulltime figure for all persons assignments
7969               --
7970               l_rate_cvg_result  := l_rec.total_fte;
7971               --
7972             END IF;
7973             --
7974             IF    l_rate_cvg_rec.rndg_cd IS NOT NULL
7975                OR l_rate_cvg_rec.rndg_rl IS NOT NULL THEN
7976               --
7977               l_rate_cvg_result  :=
7978                 benutils.do_rounding(p_rounding_cd=> l_rate_cvg_rec.rndg_cd
7979                  ,p_rounding_rl    => l_rate_cvg_rec.rndg_rl
7980                  ,p_value          => l_rate_cvg_result
7981                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
7982                                        ,p_effective_date));
7983               --
7984             END IF; -- l_rate_cvg_rec.rndg_cd
7985             --
7986             IF l_rate_cvg_result is not null THEN
7987               --
7988               ben_derive_part_and_rate_cvg.get_pct_rate(p_pl_id=> p_pl_id
7989                ,p_oipl_id           => p_oipl_id
7990                ,p_plip_id           => p_plip_id
7991                ,p_business_group_id => p_business_group_id
7992                ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
7993                                         ,p_effective_date))
7994                ,p_rec               => l_rate_cvg_rec);
7995               --
7996               ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
7997               --
7998               percent_fulltime_min_max
7999                    (p_calculate_only_mode =>p_calculate_only_mode
8000                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
8001                    ,p_curroiplip_row      =>p_curroiplip_row
8002                    ,p_comp_rec            =>p_comp_rec
8003                    ,p_empasg_row          =>p_empasg_row
8004                    ,p_benasg_row          =>p_benasg_row
8005                    ,p_person_id           =>p_person_id
8006                    ,p_pgm_id              =>p_pgm_id
8007                    ,p_pl_id               =>p_pl_id
8008                    ,p_oipl_id             =>p_oipl_id
8009                    ,p_oiplip_id           =>p_oiplip_id
8010                    ,p_plip_id             =>p_plip_id
8011                    ,p_ptip_id             =>p_ptip_id
8012                    ,p_business_group_id   =>p_business_group_id
8013                    ,p_ler_id              =>l_der_cvg_rec.drvdtpf_id
8014                    ,p_min_value           =>l_rate_cvg_rec.mn_pct_val
8015                    ,p_max_value           =>l_rate_cvg_rec.mx_pct_val
8016                    ,p_new_value           =>l_rate_cvg_result
8017                    ,p_old_value           =>p_comp_rec.rt_pct_fl_tm_val
8018                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
8019                    ,p_effective_date      =>p_effective_date
8020                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
8021                   ) ;
8022               --
8023             END IF; --l_rate_cvg_result
8024             --
8025           END IF; -- l_rate_cvg_rec.exist
8026           --
8027         END IF; --p_oipl_id coverage
8028         -- Now try Premiums
8029         --
8030         if g_debug then
8031           hr_utility.set_location('Entering into premium process ' , 20);
8032         end if;
8033         --
8034         IF  p_oipl_id IS NOT NULL
8035             OR p_pl_id IS NOT NULL THEN
8036           --
8037           -- Try and find a premium
8038           --
8039           ben_derive_part_and_rate_prem.get_pct_rate(
8040                 p_pl_id             => p_pl_id
8041                ,p_oipl_id           => p_oipl_id
8042                ,p_business_group_id => p_business_group_id
8043                ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8044                                         ,p_effective_date))
8045                ,p_rec               => l_rate_prem_rec);
8046               --
8047           IF l_rate_prem_rec.exist = 'Y' THEN
8048             --
8049             l_prem  := TRUE;
8050             --
8051             IF p_empasg_row.assignment_id IS NULL THEN
8052               --
8053               l_ass_rec  := p_benasg_row;
8054               --
8055             ELSE
8056               --
8057               l_ass_rec  := p_empasg_row;
8058               --
8059             END IF;
8060             --
8061 
8062             if g_debug then
8063               hr_utility.set_location(' l_ass_rec.assignment_id '||l_ass_rec.assignment_id, 30);
8064             end if;
8065             ben_person_object.get_object(p_assignment_id=> l_ass_rec.assignment_id
8066                                        ,p_rec           => l_rec);
8067 
8068             IF l_rate_prem_rec.use_prmry_asnt_only_flag = 'Y' THEN
8069               --
8070               -- Get percent fulltime value for persons primary assignment
8071               --
8072               if g_debug then
8073                 hr_utility.set_location(' l_rec.fte '||l_rec.fte ,40);
8074               end if;
8075               l_rate_prem_result  := l_rec.fte;
8076               --
8077             ELSIF l_rate_prem_rec.use_sum_of_all_asnts_flag = 'Y' THEN
8078               --
8079               -- Get percent fulltime figure for all persons assignments
8080               --
8081               if g_debug then
8082                 hr_utility.set_location(' l_rec.total_fte '||l_rec.total_fte , 50);
8083               end if;
8084               l_rate_prem_result  := l_rec.total_fte;
8085               --
8086             END IF;
8087             --
8088             IF    l_rate_prem_rec.rndg_cd IS NOT NULL
8089                OR l_rate_prem_rec.rndg_rl IS NOT NULL THEN
8090               --
8091               l_rate_prem_result  :=
8092                 benutils.do_rounding(p_rounding_cd=> l_rate_prem_rec.rndg_cd
8093                  ,p_rounding_rl    => l_rate_prem_rec.rndg_rl
8094                  ,p_value          => l_rate_prem_result
8095                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
8096                                        ,p_effective_date));
8097               --
8098             END IF; -- l_rate_prem_rec.rndg_cd
8099             --
8100             IF l_rate_prem_result is not null THEN
8101               --
8102               ben_derive_part_and_rate_prem.get_pct_rate(
8103                 p_pl_id             => p_pl_id
8104                ,p_oipl_id           => p_oipl_id
8105                ,p_new_val           => l_rate_prem_result
8106                ,p_old_val           => p_comp_rec.rt_pct_fl_tm_val
8107                ,p_business_group_id => p_business_group_id
8108                ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8109                                         ,p_effective_date))
8110                ,p_rec               => l_rate_prem_rec);
8111               --
8112               ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
8113               --
8114               percent_fulltime_min_max
8115                    (p_calculate_only_mode =>p_calculate_only_mode
8116                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
8117                    ,p_curroiplip_row      =>p_curroiplip_row
8118                    ,p_comp_rec            =>p_comp_rec
8119                    ,p_empasg_row          =>p_empasg_row
8120                    ,p_benasg_row          =>p_benasg_row
8121                    ,p_person_id           =>p_person_id
8122                    ,p_pgm_id              =>p_pgm_id
8123                    ,p_pl_id               =>p_pl_id
8124                    ,p_oipl_id             =>p_oipl_id
8125                    ,p_oiplip_id           =>p_oiplip_id
8126                    ,p_plip_id             =>p_plip_id
8127                    ,p_ptip_id             =>p_ptip_id
8128                    ,p_business_group_id   =>p_business_group_id
8129                    ,p_ler_id              =>l_der_prem_rec.drvdtpf_id
8130                    ,p_min_value           =>l_rate_prem_rec.mn_pct_val
8131                    ,p_max_value           =>l_rate_prem_rec.mx_pct_val
8132                    ,p_new_value           =>l_rate_prem_result
8133                    ,p_old_value           =>p_comp_rec.rt_pct_fl_tm_val
8134                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
8135                    ,p_effective_date      =>p_effective_date
8136                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
8137                   ) ;
8138               --
8139             END IF; -- l_rate_prem_result
8140             --
8141           END IF; -- l_rate_prem_rec.exist
8142           --
8143         END IF; -- p_oipl_id prem
8144         --
8145         IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
8146           --
8147           p_comp_rec.rt_pct_fl_tm_val  := NULL;
8148           --
8149         ELSIF l_rate_result is NOT NULL THEN
8150           if g_debug then
8151             hr_utility.set_location(' Step 28',10);
8152           end if;
8153           p_comp_rec.rt_pct_fl_tm_val  := l_rate_result;
8154           --
8155         ELSIF l_rate_cvg_result is NOT NULL then
8156           --
8157           p_comp_rec.rt_pct_fl_tm_val  := l_rate_cvg_result;
8158           if g_debug then
8159             hr_utility.set_location(' Step 29',10);
8160           end if;
8161         ELSIF l_rate_prem_result is NOT NULL THEN
8162           --
8163           p_comp_rec.rt_pct_fl_tm_val  := l_rate_prem_result;
8164           if g_debug then
8165             hr_utility.set_location(' Step 30',10);
8166           end if;
8167         END IF;
8168         --
8169       END IF;
8170       --
8171     END IF;
8172     --
8173 
8174     -- p_comp_rec.rt_pct_fl_tm_val  := l_rate_result ;
8175 
8176     if g_debug then
8177       hr_utility.set_location('Leaving ' || l_package,10);
8178     end if;
8179     --
8180   END calculate_percent_fulltime;
8181 --
8182   PROCEDURE hours_worked_min_max
8183     (p_calculate_only_mode in     boolean default false
8184     ,p_comp_obj_tree_row   IN     ben_manage_life_events.g_cache_proc_objects_rec
8185     ,p_curroiplip_row      IN     ben_cobj_cache.g_oiplip_inst_row
8186    --,p_rate_rec           IN OUT ben_derive_part_and_rate_cache.g_cache_clf_rec_obj
8187     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
8188     ,p_empasg_row          IN     per_all_assignments_f%ROWTYPE
8189     ,p_benasg_row          IN     per_all_assignments_f%ROWTYPE
8190     ,p_person_id           IN     NUMBER
8191     ,p_pgm_id              IN     NUMBER
8192     ,p_pl_id               IN     NUMBER
8193     ,p_oipl_id             IN     NUMBER
8194     ,p_oiplip_id           IN     NUMBER
8195     ,p_plip_id             IN     NUMBER
8196     ,p_ptip_id             IN     NUMBER
8197     ,p_business_group_id   IN     NUMBER
8198     ,p_ler_id              IN     NUMBER
8199     ,p_min_value           IN     NUMBER
8200     ,p_max_value           IN     NUMBER
8201     ,p_new_value           IN     NUMBER
8202     ,p_old_value           IN     NUMBER
8203   --  ,p_uom                 IN     VARCHAR2
8204     ,p_subtract_date       IN     DATE
8205     ,p_det_cd              IN     VARCHAR2
8206     ,p_formula_id          IN     NUMBER DEFAULT NULL
8207     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
8208     ,p_effective_date      IN     DATE
8209     ,p_lf_evt_ocrd_dt      IN     DATE
8210     ,p_hrs_src_cd          IN     VARCHAR2
8211     ,p_bnfts_bal_id        IN     NUMBER )
8212 
8213   IS
8214     --
8215     l_package            VARCHAR2(80)        := g_package || '.hours_worked_min_max';
8216     l_break              VARCHAR2(30);
8217     l_det_cd             VARCHAR2(30);
8218     l_lf_evt_ocrd_dt     DATE;
8219     l_new_lf_evt_ocrd_dt DATE;
8220     l_start_date         DATE;
8221     l_rec                ben_person_object.g_person_date_info_rec;
8222     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
8223     --
8224   BEGIN
8225       hr_utility.set_location('Entering hours_worked_min_max ', 10 );
8226       /* Bug 5478918 */
8227         if (skip_min_max_le_calc(p_ler_id,
8228 	                         p_business_group_id,
8229                                  p_ptnl_ler_trtmt_cd,
8230                                  p_effective_date)) THEN
8231         --
8232         /* Simply return as no further calculations need to be done */
8233           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
8234           RETURN;
8235         end if;
8236 	/* End Bug 5478918 */
8237       hr_utility.set_location('p_max_value '||p_max_value,10);
8238       hr_utility.set_location('p_min_value '||p_min_value,10);
8239       hr_utility.set_location('p_new_value '||p_new_value,10);
8240       hr_utility.set_location('p_old_value '||p_old_value,10);
8241             --
8242             IF benutils.min_max_breach(p_min_value=> NVL(p_min_value
8243                                                       ,-1)
8244                 ,p_max_value => NVL(p_max_value
8245                                  ,99999999)
8246                 ,p_new_value => p_new_value
8247                 ,p_old_value => nvl(p_old_value,0)
8248                 ,p_break     => l_break) THEN
8249               --
8250               -- Derive life event occured date based on the value of l_break
8251               -- Bug 2145966 added Rule
8252               IF p_hrs_src_cd = 'BNFTBALTYP' OR p_hrs_src_cd = 'RL'  THEN
8253                 --
8254                 IF p_hrs_src_cd = 'BNFTBALTYP' THEN
8255                   --
8256                   l_lf_evt_ocrd_dt  :=
8257                     get_balance_date(p_effective_date=> NVL(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8258                                                          ,p_effective_date))
8259                      ,p_bnfts_bal_id   => p_bnfts_bal_id
8260                      ,p_person_id      => p_person_id
8261                      ,p_min            => p_min_value
8262                      ,p_max            => p_max_value
8263                      ,p_break          => l_break);
8264                   --
8265                 ELSE -- For Rulew
8266                   --
8267                   l_lf_evt_ocrd_dt := NVL(p_lf_evt_ocrd_dt,p_effective_date);
8268                   --
8269                 END IF;
8270                   -- Reapply calculated life event occured date
8271                   --
8272                 IF p_det_cd <> 'AED' THEN
8273                   --
8274                   ben_determine_date.main(p_date_cd=> p_det_cd
8275                    ,p_formula_id        => p_formula_id
8276                    ,p_person_id         => p_person_id
8277                    ,p_bnfts_bal_id      => p_bnfts_bal_id
8278                    ,p_pgm_id            => NVL(p_pgm_id
8279                                             ,p_comp_obj_tree_row.par_pgm_id)
8280                    ,p_pl_id             => p_pl_id
8281                    ,p_oipl_id           => NVL(p_oipl_id
8282                                             ,l_oiplip_rec.oipl_id)
8283                    ,p_business_group_id => p_business_group_id
8284                    ,p_returned_date     => l_new_lf_evt_ocrd_dt
8285                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
8286                    ,p_effective_date    => l_lf_evt_ocrd_dt);
8287                   --
8288                   -- The derived life event occured date must be greater than the
8289                   -- life event occured date as otherwise in reality a boundary
8290                   -- has not been passed.
8291                   -- This can only happen if the det_cd is one of the following :
8292                   -- AFDCPPY = As of first day of current program or plan year
8293                   -- APOCT1 = As of previous october 1st
8294                   -- AFDCM = As of first day of the current month
8295                   --
8296                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
8297                      AND p_det_cd  IN (
8298                                                         'AFDCPPY'
8299                                                        ,'APOCT1'
8300                                                        ,'AFDCM') THEN
8301                     --
8302                     -- These are special cases where we need to rederive the LED
8303                     -- so that we are actually still passing the correct boundary
8304                     --
8305                     l_det_cd := p_det_cd ;
8306                     --
8307                     IF p_det_cd = 'APOCT1' THEN
8308                       --
8309                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
8310                                             ,12);
8311                     --
8312                     ELSIF p_det_cd = 'AFDCM' THEN
8313                       --
8314                       -- l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
8315                       -- Bug 1927010. Commented the above manipulation
8316                       null ;
8317                       --
8318                     ELSIF p_det_cd = 'AFDCPPY' THEN
8319                       --
8320                       l_det_cd  := 'AFDFPPY';
8321                     --
8322                     END IF;
8323                     --
8324                     -- Reapply logic back to determination of date routine.
8325                     --
8326                     ben_determine_date.main(p_date_cd=> l_det_cd
8327                      ,p_bnfts_bal_id      => p_bnfts_bal_id
8328                      ,p_person_id         => p_person_id
8329                      ,p_pgm_id            => NVL(p_pgm_id
8330                                               ,p_comp_obj_tree_row.par_pgm_id)
8331                      ,p_pl_id             => p_pl_id
8332                      ,p_oipl_id           => NVL(p_oipl_id
8333                                               ,l_oiplip_rec.oipl_id)
8334                      ,p_business_group_id => p_business_group_id
8335                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
8336                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
8337                      ,p_effective_date    => l_lf_evt_ocrd_dt);
8338                   --
8339                   END IF;
8340                   --
8341                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
8342                 --
8343                 END IF;
8344               --
8345               ELSIF p_hrs_src_cd = 'BALTYP' THEN
8346                 --
8347                 l_lf_evt_ocrd_dt  := p_effective_date;
8348               --
8349               END IF;
8350               --
8351               -- Life event occured date must be less than the minimum
8352               -- assignment effective start date
8353               --
8354               ben_person_object.get_object(p_person_id=> p_person_id
8355                ,p_rec       => l_rec);
8356               --
8357               IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
8358                 --
8359                 IF   (  l_lf_evt_ocrd_dt < p_effective_date
8360                    AND NVL(p_ptnl_ler_trtmt_cd
8361                         ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
8362                   --
8363                   -- We do not create past life events
8364                   --
8365                   RETURN ;
8366                 --
8367                 END IF;
8368                 --
8369                 hr_utility.set_location('Got the dates. Now creating the LE',10);
8370                 --
8371                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
8372                       ,p_person_id      => p_person_id
8373                       ,p_ler_id         => p_ler_id
8374                       ,p_effective_date => p_effective_date)
8375                 THEN
8376                     --
8377                     create_ptl_ler
8378                       (p_calculate_only_mode => p_calculate_only_mode
8379                       ,p_ler_id              => p_ler_id
8380                       ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
8381                       ,p_person_id           => p_person_id
8382                       ,p_business_group_id   => p_business_group_id
8383                       ,p_effective_date      => p_effective_date
8384                       );
8385                     --
8386                 END IF;  -- no_life_event
8387                   --
8388               END IF; -- l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date
8389               --
8390             END IF; --  benutils.min_max_breach
8391             --
8392   END hours_worked_min_max ;
8393   --
8394   PROCEDURE calculate_hours_worked
8395     (p_calculate_only_mode in            boolean default false
8396     ,p_comp_obj_tree_row   IN            ben_manage_life_events.g_cache_proc_objects_rec
8397     ,p_empasg_row          IN            per_all_assignments_f%ROWTYPE
8398     ,p_benasg_row          IN            per_all_assignments_f%ROWTYPE
8399     ,p_pil_row             IN            ben_per_in_ler%ROWTYPE
8400     ,p_curroipl_row        IN            ben_cobj_cache.g_oipl_inst_row
8401     ,p_curroiplip_row      IN            ben_cobj_cache.g_oiplip_inst_row
8402     ,p_person_id           IN            NUMBER
8403     ,p_business_group_id   IN            NUMBER
8404     ,p_pgm_id              IN            NUMBER
8405     ,p_pl_id               IN            NUMBER
8406     ,p_oipl_id             IN            NUMBER
8407     ,p_plip_id             IN            NUMBER
8408     ,p_ptip_id             IN            NUMBER
8409     ,p_oiplip_id           IN            NUMBER
8410     ,p_ptnl_ler_trtmt_cd   IN            VARCHAR2
8411     ,p_comp_rec            IN OUT NOCOPY g_cache_structure
8412     ,p_effective_date      IN            DATE
8413     ,p_lf_evt_ocrd_dt      IN            DATE
8414     )
8415   IS
8416     --
8417     l_package            VARCHAR2(80)
8418                                      := g_package || '.calculate_hours_worked';
8419     l_break              VARCHAR2(30);
8420     l_elig_result        NUMBER;
8421     l_rate_result        NUMBER;
8422     l_rate_cvg_result NUMBER;
8423     l_rate_prem_result NUMBER;
8424     l_lf_evt_ocrd_dt     DATE;
8425     l_new_lf_evt_ocrd_dt DATE;
8426     l_start_date         DATE;
8427     l_subtract_date      DATE;
8428     l_ok                 BOOLEAN;
8429     l_elig_rec           ben_derive_part_and_rate_cache.g_cache_hwf_rec_obj;
8430     l_rate_rec           ben_derive_part_and_rate_cache.g_cache_hwf_rec_obj;
8431     l_rate_cvg_rec       ben_derive_part_and_rate_cache.g_cache_hwf_rec_obj;
8432     l_rate_prem_rec      ben_derive_part_and_rate_cache.g_cache_hwf_rec_obj;
8433     l_rec                ben_person_object.g_person_date_info_rec;
8434     l_der_rec            ben_seeddata_object.g_derived_factor_info_rec;
8435     l_der_cvg_rec        ben_seeddata_object.g_derived_factor_info_rec;
8436     l_der_prem_rec       ben_seeddata_object.g_derived_factor_info_rec;
8437     l_dummy_date         DATE;
8438     l_rate               BOOLEAN                                     := FALSE;
8439     l_cvg                BOOLEAN                                     := FALSE;
8440     l_prem               BOOLEAN                                     := FALSE;
8441     l_oiplip_rec         ben_cobj_cache.g_oiplip_inst_row;
8442   --
8443   BEGIN
8444     --
8445     if g_debug then
8446       hr_utility.set_location('Entering ' || l_package,10);
8447     end if;
8448 --
8449 -- Calculate HRS WKD process
8450 -- =========================
8451 -- 1) First check if freeze HRS WKD flag is on in which case
8452 --    we ignore the calculation and just return the frozen values
8453 -- 2) Calculate eligibility derivable factors
8454 -- 3) Calculate rate derivable factors
8455 -- 3) Perform rounding
8456 -- 4) Test for min/max breach
8457 -- 5) If a breach did occur then create a ptl_ler_for_per.
8458 --
8459     IF bitand(p_comp_obj_tree_row.flag_bit_val
8460         ,ben_manage_life_events.g_hrw_flag) <> 0 THEN
8461       --
8462      -- hr_utility.set_location('HRW for ELIG',10);
8463       IF p_comp_rec.frz_hrs_wkd_flag = 'Y' THEN
8464         --
8465         -- No calulation required just return the frozen value
8466         --
8467         NULL;
8468       --
8469       ELSE
8470         --
8471         ben_derive_part_and_rate_cache.get_hours_elig(p_pgm_id=> p_pgm_id
8472          ,p_pl_id             => p_pl_id
8473          ,p_oipl_id           => p_oipl_id
8474          ,p_plip_id           => p_plip_id
8475          ,p_ptip_id           => p_ptip_id
8476          ,p_business_group_id => p_business_group_id
8477          ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8478                                   ,p_effective_date))
8479          ,p_rec               => l_elig_rec);
8480         --
8481         l_ok  := TRUE;
8482         --
8483         IF     l_elig_rec.exist = 'Y'
8484            AND NVL(l_elig_rec.once_r_cntug_cd
8485                 ,'-1') = 'ONCE'
8486            AND NVL(p_comp_rec.once_r_cntug_cd
8487                 ,'-1') = 'ONCE'
8488            AND p_comp_rec.elig_flag = 'Y' THEN
8489           --
8490           -- In this case we do not have to derive the hours worked as the
8491           -- eligibility has been met, just return the frozen values and
8492           -- ignore the business rule check for the eligbility profile
8493           --
8494           NULL;
8495         --
8496         ELSIF l_elig_rec.exist = 'Y' THEN
8497           --
8498           if g_debug then
8499             hr_utility.set_location(' l_elig_rec.hrs_wkd_calc_rl '||l_elig_rec.hrs_wkd_calc_rl , 99);
8500           end if;
8501           --
8502           IF l_elig_rec.hrs_wkd_calc_rl IS NOT NULL THEN
8503             --
8504             if g_debug then
8505               hr_utility.set_location(' l_elig_rec.hrs_wkd_calc_rl '||l_elig_rec.hrs_wkd_calc_rl , 99);
8506             end if;
8507             --
8508             ben_determine_date.main(p_date_cd=> l_elig_rec.hrs_wkd_det_cd
8509              ,p_formula_id        => l_elig_rec.hrs_wkd_calc_rl
8510              ,p_person_id         => p_person_id
8511              ,p_pgm_id            => NVL(p_pgm_id
8512                                       ,p_comp_obj_tree_row.par_pgm_id)
8513              ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
8514              ,p_pl_id             => p_pl_id
8515              ,p_oipl_id           => p_oipl_id
8516              ,p_business_group_id => p_business_group_id
8517              ,p_returned_date     => l_start_date
8518              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
8519              ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
8520                                       ,p_effective_date)
8521              ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt );
8522             --
8523             if g_debug then
8524               hr_utility.set_location(' l_start_date '||l_start_date ,99);
8525             end if;
8526             --
8527             run_rule(p_formula_id => l_elig_rec.hrs_wkd_calc_rl
8528              ,p_empasg_row        => p_empasg_row
8529              ,p_benasg_row        => p_benasg_row
8530              ,p_pil_row           => p_pil_row
8531              ,p_curroipl_row      => p_curroipl_row
8532              ,p_curroiplip_row    => p_curroiplip_row
8533              ,p_effective_date    => l_start_date
8534              ,p_lf_evt_ocrd_dt    => l_start_date
8535              ,p_business_group_id => p_business_group_id
8536              ,p_person_id         => p_person_id
8537              ,p_pgm_id            => p_pgm_id
8538              ,p_pl_id             => p_pl_id
8539              ,p_oipl_id           => p_oipl_id
8540              ,p_oiplip_id         => p_oiplip_id
8541              ,p_plip_id           => p_plip_id
8542              ,p_ptip_id           => p_ptip_id
8543              ,p_ret_date          => l_dummy_date
8544              ,p_ret_val           => l_elig_result);
8545             --
8546             if g_debug then
8547               hr_utility.set_location(' l_elig_result '||l_elig_result ,99);
8548             end if;
8549             --
8550             -- Round value if rounding needed
8551             --
8552             IF    l_elig_rec.rndg_cd IS NOT NULL
8553                OR l_elig_rec.rndg_rl IS NOT NULL THEN
8554               --
8555               l_elig_result  :=
8556                 benutils.do_rounding(p_rounding_cd=> l_elig_rec.rndg_cd
8557                  ,p_rounding_rl    => l_elig_rec.rndg_rl
8558                  ,p_value          => l_elig_result
8559                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
8560                                        ,p_effective_date));
8561             --
8562             END IF;
8563           --
8564           ELSE
8565             l_elig_result  :=
8566               hours_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
8567                ,p_empasg_row        => p_empasg_row
8568                ,p_benasg_row        => p_benasg_row
8569                ,p_curroiplip_row    => p_curroiplip_row
8570                ,p_rec               => l_elig_rec
8571                ,p_business_group_id => p_business_group_id
8572                ,p_person_id         => p_person_id
8573                ,p_pgm_id            => p_pgm_id
8574                ,p_pl_id             => p_pl_id
8575                ,p_oipl_id           => p_oipl_id
8576                ,p_oiplip_id         => p_oiplip_id
8577                ,p_plip_id           => p_plip_id
8578                ,p_ptip_id           => p_ptip_id
8579                ,p_effective_date    => p_effective_date
8580                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
8581           END IF;
8582           -- In case called from watif benmngle then need not create
8583           -- temporals for any min, max breaches.
8584           --
8585           --hr_utility.set_location(' p_min_value '||l_elig_rec.mn_hrs_num ,99);
8586           --hr_utility.set_location(' p_max_value '||l_elig_rec.mx_hrs_num ,99);
8587           --hr_utility.set_location(' p_new_value '||l_elig_result ,99);
8588           --hr_utility.set_location(' p_old_value '||p_comp_rec.hrs_wkd_val ,99);
8589           --hr_utility.set_location(' p_break '||l_break,99);
8590           --
8591         /* Bug 5478918 */
8592 	ben_seeddata_object.get_object(p_rec=> l_der_rec);
8593         if (skip_min_max_le_calc(l_der_rec.drvdhrw_id,
8594 	                         p_business_group_id,
8595                                  p_ptnl_ler_trtmt_cd,
8596                                  p_effective_date)) THEN
8597         --
8598         /* Simply return as no further calculations need to be done */
8599           hr_utility.set_location(l_package||' Do Nothing here.', 9877);
8600           null;
8601         --
8602         else
8603 	--
8604           IF     l_elig_result IS NOT NULL
8605              AND (
8606                        ben_whatif_elig.g_bal_hwf_val IS NULL
8607                    AND ben_whatif_elig.g_bnft_bal_hwf_val IS NULL) THEN
8608             --
8609                 ben_derive_part_and_rate_cache.get_hours_elig(p_pgm_id=> p_pgm_id
8610                  ,p_pl_id             => p_pl_id
8611                  ,p_oipl_id           => p_oipl_id
8612                  ,p_plip_id           => p_plip_id
8613                  ,p_ptip_id           => p_ptip_id
8614                  ,p_new_val           => l_elig_result
8615                  ,p_old_val           => nvl(p_comp_rec.hrs_wkd_val,0)
8616                  ,p_business_group_id => p_business_group_id
8617                  ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8618                                           ,p_effective_date))
8619                  ,p_rec               => l_elig_rec);
8620         --
8621             IF benutils.min_max_breach(p_min_value=> NVL(l_elig_rec.mn_hrs_num
8622                                                       ,-1)
8623                 ,p_max_value => NVL(l_elig_rec.mx_hrs_num
8624                                  ,99999999)
8625                 ,p_new_value => l_elig_result
8626                 ,p_old_value => nvl(p_comp_rec.hrs_wkd_val,0)
8627                 ,p_break     => l_break) THEN
8628               --
8629               -- Derive life event occured date based on the value of l_break
8630               -- Bug 2145966 Formula not working for Hours worked derived factor
8631               --
8632               IF l_elig_rec.hrs_src_cd = 'BNFTBALTYP' OR l_elig_rec.hrs_src_cd = 'RL' THEN
8633                 --
8634                 IF l_elig_rec.hrs_src_cd = 'BNFTBALTYP' then
8635                 --
8636                 l_lf_evt_ocrd_dt  :=
8637                   get_balance_date(p_effective_date=> NVL(g_fonm_cvg_strt_dt,
8638                                                           NVL(p_lf_evt_ocrd_dt ,p_effective_date))
8639                    ,p_bnfts_bal_id   => l_elig_rec.bnfts_bal_id
8640                    ,p_person_id      => p_person_id
8641                    ,p_min            => l_elig_rec.mn_hrs_num
8642                    ,p_max            => l_elig_rec.mx_hrs_num
8643                    ,p_break          => l_break);
8644                 --
8645                 ELSE -- For Rule
8646                   --
8647                   l_lf_evt_ocrd_dt  := NVL(p_lf_evt_ocrd_dt,p_effective_date) ;
8648                   --
8649                 END IF;
8650                 --
8651                 -- Reapply calculated life event occured date
8652                 --
8653                 IF l_elig_rec.hrs_wkd_det_cd <> 'AED' THEN
8654                   --
8655                   ben_determine_date.main(p_date_cd=> l_elig_rec.hrs_wkd_det_cd
8656                    ,p_formula_id        => l_elig_rec.hrs_wkd_det_rl
8657                    ,p_person_id         => p_person_id
8658                    ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
8659                    ,p_pgm_id            => NVL(p_pgm_id
8660                                             ,p_comp_obj_tree_row.par_pgm_id)
8661                    ,p_pl_id             => p_pl_id
8662                    ,p_oipl_id           => p_oipl_id
8663                    ,p_business_group_id => p_business_group_id
8664                    ,p_returned_date     => l_new_lf_evt_ocrd_dt
8665                    ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
8666                    ,p_effective_date    => l_lf_evt_ocrd_dt);
8667                   --
8668                   -- The derived life event occured date must be greater than the
8669                   -- life event occured date as otherwise in reality a boundary
8670                   -- has not been passed.
8671                   -- This can only happen if the det_cd is one of the following :
8672                   -- AFDCPPY = As of first day of current program or plan year
8673                   -- APOCT1 = As of previous october 1st
8674                   -- AFDCM = As of first day of the current month
8675                   --
8676                   IF     l_new_lf_evt_ocrd_dt < l_lf_evt_ocrd_dt
8677                      AND l_elig_rec.hrs_wkd_det_cd IN (
8678                                                         'AFDCPPY'
8679                                                        ,'APOCT1'
8680                                                        ,'AFDCM') THEN
8681                     --
8682                     -- These are special cases where we need to rederive the LED
8683                     -- so that we are actually still passing the correct boundary
8684                     --
8685                     IF l_elig_rec.hrs_wkd_det_cd = 'APOCT1' THEN
8686                       --
8687                       l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt
8688                                             ,12);
8689                     --
8690                     ELSIF l_elig_rec.hrs_wkd_det_cd = 'AFDCM' THEN
8691                       --
8692                       -- l_lf_evt_ocrd_dt  := ADD_MONTHS(l_lf_evt_ocrd_dt ,1);
8693                       -- Bug 1927010. Commented the above manipulation
8694                       null ;
8695                     --
8696                     ELSIF l_elig_rec.hrs_wkd_det_cd = 'AFDCPPY' THEN
8697                       --
8698                       l_elig_rec.hrs_wkd_det_cd  := 'AFDFPPY';
8699                     --
8700                     END IF;
8701                     --
8702                     -- Reapply logic back to determination of date routine.
8703                     --
8704                     ben_determine_date.main(p_date_cd=> l_elig_rec.hrs_wkd_det_cd
8705                      ,p_bnfts_bal_id      => l_elig_rec.bnfts_bal_id
8706                      ,p_person_id         => p_person_id
8707                      ,p_pgm_id            => NVL(p_pgm_id
8708                                               ,p_comp_obj_tree_row.par_pgm_id)
8709                      ,p_pl_id             => p_pl_id
8710                      ,p_oipl_id           => p_oipl_id
8711                      ,p_business_group_id => p_business_group_id
8712                      ,p_returned_date     => l_new_lf_evt_ocrd_dt
8713                      ,p_lf_evt_ocrd_dt    => l_lf_evt_ocrd_dt
8714                      ,p_effective_date    => l_lf_evt_ocrd_dt);
8715                   --
8716                   END IF;
8717                   --
8718                   l_lf_evt_ocrd_dt  := l_new_lf_evt_ocrd_dt;
8719                 --
8720                 END IF;
8721               --
8722               ELSIF l_elig_rec.hrs_src_cd = 'BALTYP' THEN
8723                 --
8724                 l_lf_evt_ocrd_dt  := p_effective_date;
8725               --
8726               END IF;
8727               --
8728               -- Life event occured date must be less than the minimum
8729               -- assignment effective start date
8730               --
8731               ben_person_object.get_object(p_person_id=> p_person_id
8732                ,p_rec       => l_rec);
8733               --
8734               IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
8735                 --
8736                 IF   (  l_lf_evt_ocrd_dt < p_effective_date
8737                    AND NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNR') THEN
8738                   --
8739                   -- We are not creating past life events
8740                   --
8741                   NULL;
8742                 --
8743                 ELSIF l_ok THEN
8744                   --
8745                   IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
8746                       ,p_person_id      => p_person_id
8747                       ,p_ler_id         => l_der_rec.drvdhrw_id
8748                       ,p_effective_date => p_effective_date)
8749                   THEN
8750                     --
8751                     create_ptl_ler
8752                       (p_calculate_only_mode => p_calculate_only_mode
8753                       ,p_ler_id              => l_der_rec.drvdhrw_id
8754                       ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
8755                       ,p_person_id           => p_person_id
8756                       ,p_business_group_id   => p_business_group_id
8757                       ,p_effective_date      => p_effective_date
8758                       );
8759                     --
8760                   END IF;
8761                 --
8762                 END IF;
8763               --
8764               END IF;
8765             --
8766             END IF;
8767           --
8768 	  END IF;
8769           --
8770           END IF; /* End Bug 5478918 */
8771           --
8772           p_comp_rec.hrs_wkd_val            := l_elig_result;
8773           p_comp_rec.hrs_wkd_bndry_perd_cd  := NULL;
8774           --
8775           -- This only applies to eligibility
8776           --
8777           IF l_elig_result IS NULL THEN
8778             --
8779             p_comp_rec.hrs_wkd_bndry_perd_cd  := NULL;
8780           --
8781           END IF;
8782         --
8783         ELSE
8784           --
8785           p_comp_rec.hrs_wkd_val            := NULL;
8786           p_comp_rec.hrs_wkd_bndry_perd_cd  := NULL;
8787         --
8788         END IF;
8789       --
8790       END IF;
8791     --
8792     END IF;
8793     --
8794    -- hr_utility.set_location('RFHWF=Y ' || l_package,10);
8795     --9999
8796     IF    bitand(p_comp_obj_tree_row.flag_bit_val
8797            ,ben_manage_life_events.g_hrw_rt_flag) <> 0
8798        OR     p_oiplip_id IS NOT NULL
8799           AND bitand(p_comp_obj_tree_row.oiplip_flag_bit_val
8800                ,ben_manage_life_events.g_hrw_rt_flag) <> 0 THEN
8801       --
8802       if g_debug then
8803         hr_utility.set_location('HRW for RT',10);
8804       end if;
8805       IF    p_comp_rec.rt_frz_hrs_wkd_flag = 'Y'
8806          OR (
8807                   NVL(p_comp_rec.once_r_cntug_cd
8808                    ,'-1') = 'ONCE'
8809               AND p_comp_rec.elig_flag = 'Y') THEN
8810         --
8811         -- No calulation required just return the frozen value
8812         --
8813         NULL;
8814       --
8815       ELSE
8816         --
8817         if g_debug then
8818           hr_utility.set_location('ben_derive_part_and_rate_cache '||p_oipl_id , 20);
8819         end if;
8820         --
8821         ben_derive_part_and_rate_cache.get_hours_rate(p_pgm_id=> p_pgm_id
8822          ,p_pl_id             => p_pl_id
8823          ,p_oipl_id           => p_oipl_id
8824          ,p_plip_id           => p_plip_id
8825          ,p_ptip_id           => p_ptip_id
8826          ,p_oiplip_id         => p_oiplip_id
8827          ,p_business_group_id => p_business_group_id
8828          ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8829                                   ,p_effective_date))
8830          ,p_rec               => l_rate_rec);
8831         --
8832         IF    NVL(l_rate_rec.once_r_cntug_cd ,'-1') = 'ONCE'
8833             AND NVL(p_comp_rec.once_r_cntug_cd ,'-1') = 'ONCE'
8834             AND p_comp_rec.elig_flag = 'Y'   THEN
8835           --
8836           -- In this case we do not have to derive the hours worked as the
8837           -- eligibility has been met, just return the frozen values and
8838           -- ignore the business rule check for the eligbility profile
8839           --
8840           null ;
8841           --
8842         ELSIF l_rate_rec.exist = 'Y' THEN
8843           --
8844           if g_debug then
8845             hr_utility.set_location(' l_rate_rec.exist ' ,25);
8846           end if;
8847           l_rate  := TRUE;
8848           --
8849           IF p_oiplip_id IS NOT NULL THEN
8850             --
8851             if g_debug then
8852               hr_utility.set_location(' p_curroiplip_row ',25);
8853             end if;
8854             l_oiplip_rec  := p_curroiplip_row;
8855           --
8856           END IF;
8857           --
8858           IF l_rate_rec.hrs_wkd_calc_rl IS NOT NULL THEN
8859             --
8860             if g_debug then
8861               hr_utility.set_location('in the comp_calc_rl ' ,30);
8862             end if;
8863             ben_determine_date.main(p_date_cd=> l_rate_rec.hrs_wkd_det_cd
8864              ,p_formula_id        => l_rate_rec.hrs_wkd_calc_rl
8865              ,p_person_id         => p_person_id
8866              ,p_pgm_id            => NVL(p_pgm_id
8867                                       ,p_comp_obj_tree_row.par_pgm_id)
8868              ,p_bnfts_bal_id      => l_rate_rec.bnfts_bal_id
8869              ,p_pl_id             => p_pl_id
8870              ,p_oipl_id           => NVL(p_oipl_id
8871                                       ,l_oiplip_rec.oipl_id)
8872              ,p_business_group_id => p_business_group_id
8873              ,p_returned_date     => l_start_date
8874              ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
8875              ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
8876                                       ,p_effective_date)
8877              ,p_fonm_cvg_strt_dt  => g_fonm_cvg_strt_dt);
8878             --
8879             run_rule(p_formula_id => l_rate_rec.hrs_wkd_calc_rl
8880              ,p_empasg_row        => p_empasg_row
8881              ,p_benasg_row        => p_benasg_row
8882              ,p_pil_row           => p_pil_row
8883              ,p_curroipl_row      => p_curroipl_row
8884              ,p_curroiplip_row    => p_curroiplip_row
8885              ,p_effective_date    => l_start_date
8886              ,p_lf_evt_ocrd_dt    => l_start_date
8887              ,p_business_group_id => p_business_group_id
8888              ,p_person_id         => p_person_id
8889              ,p_pgm_id            => p_pgm_id
8890              ,p_pl_id             => p_pl_id
8891              ,p_oipl_id           => p_oipl_id
8892              ,p_oiplip_id         => p_oiplip_id
8893              ,p_plip_id           => p_plip_id
8894              ,p_ptip_id           => p_ptip_id
8895              ,p_ret_date          => l_dummy_date
8896              ,p_ret_val           => l_rate_result);
8897             --
8898             -- Round value if rounding needed
8899             --
8900             --
8901             IF    l_rate_rec.rndg_cd IS NOT NULL
8902                OR l_rate_rec.rndg_rl IS NOT NULL THEN
8903               --
8904               l_rate_result  :=
8905                 benutils.do_rounding(p_rounding_cd=> l_rate_rec.rndg_cd
8906                  ,p_rounding_rl    => l_rate_rec.rndg_rl
8907                  ,p_value          => l_rate_result
8908                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
8909                                        ,p_effective_date));
8910               if g_debug then
8911                 hr_utility.set_location('in the l_rate_rec.rndg_cd ' , 35 );
8912               end if;
8913             --
8914             END IF;
8915           --
8916           ELSE
8917           --
8918             if g_debug then
8919               hr_utility.set_location('not rule -  l_rate_result ',30);
8920             end if;
8921             l_rate_result  :=
8922               hours_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
8923                ,p_empasg_row        => p_empasg_row
8924                ,p_benasg_row        => p_benasg_row
8925                ,p_curroiplip_row    => p_curroiplip_row
8926                ,p_rec               => l_rate_rec
8927                ,p_business_group_id => p_business_group_id
8928                ,p_person_id         => p_person_id
8929                ,p_pgm_id            => p_pgm_id
8930                ,p_pl_id             => p_pl_id
8931                ,p_oipl_id           => p_oipl_id
8932                ,p_oiplip_id         => p_oiplip_id
8933                ,p_plip_id           => p_plip_id
8934                ,p_ptip_id           => p_ptip_id
8935                ,p_effective_date    => p_effective_date
8936                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
8937              --
8938              IF l_rate_result is not null THEN
8939                --
8940                if g_debug then
8941                  hr_utility.set_location(' l_rate_result found '||l_rate_result , 40);
8942                end if;
8943                --
8944                ben_derive_part_and_rate_cache.get_hours_rate(p_pgm_id=> p_pgm_id
8945                 ,p_pl_id             => p_pl_id
8946                 ,p_oipl_id           => p_oipl_id
8947                 ,p_plip_id           => p_plip_id
8948                 ,p_ptip_id           => p_ptip_id
8949                 ,p_oiplip_id         => p_oiplip_id
8950                 ,p_new_val           => l_rate_result
8951                 ,p_old_val           => p_comp_rec.rt_hrs_wkd_val
8952                 ,p_business_group_id => p_business_group_id
8953                 ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
8954                                          ,p_effective_date))
8955                 ,p_rec               => l_rate_rec);
8956                --
8957                IF ( ben_whatif_elig.g_bal_hwf_val IS NULL
8958                    AND ben_whatif_elig.g_bnft_bal_hwf_val IS NULL) THEN
8959                  --
8960                  ben_seeddata_object.get_object(p_rec=> l_der_rec);
8961                  --
8962                  if g_debug then
8963                    hr_utility.set_location(' Call to hours_worked_min_max ' ,45 );
8964                  end if;
8965                  hours_worked_min_max
8966                    (p_calculate_only_mode =>p_calculate_only_mode
8967                    ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
8968                    ,p_curroiplip_row      =>p_curroiplip_row
8969                 --   ,p_rate_rec            =>l_rate_rec
8970                    ,p_comp_rec            =>p_comp_rec
8971                    ,p_empasg_row          =>p_empasg_row
8972                    ,p_benasg_row          =>p_benasg_row
8973                    ,p_person_id           =>p_person_id
8974                    ,p_pgm_id              =>p_pgm_id
8975                    ,p_pl_id               =>p_pl_id
8976                    ,p_oipl_id             =>p_oipl_id
8977                    ,p_oiplip_id           =>p_oiplip_id
8978                    ,p_plip_id             =>p_plip_id
8979                    ,p_ptip_id             =>p_ptip_id
8980                    ,p_business_group_id   =>p_business_group_id
8981                    ,p_ler_id              =>l_der_rec.drvdhrw_id
8982                    ,p_min_value           =>l_rate_rec.mn_hrs_num
8983                    ,p_max_value           =>l_rate_rec.mx_hrs_num
8984                    ,p_new_value           =>l_rate_result
8985                    ,p_old_value           =>p_comp_rec.rt_hrs_wkd_val
8986                    ,p_subtract_date       =>l_subtract_date
8987                    ,p_det_cd              =>l_rate_rec.hrs_wkd_det_cd
8988                    ,p_formula_id          =>l_rate_rec.hrs_wkd_det_rl
8989                    ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
8990                    ,p_effective_date      =>p_effective_date
8991                    ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
8992                    ,p_hrs_src_cd          =>l_rate_rec.hrs_src_cd
8993                    ,p_bnfts_bal_id        =>l_rate_rec.bnfts_bal_id
8994                   ) ;
8995                 --
8996               END IF; -- ben_whatif_elig
8997               --
8998             END IF; -- l_rate_result
8999             --
9000           END IF; -- l_rate_rec.los_calc_rl
9001           --
9002         END IF ; -- l_rate_rec.exist
9003         -- Try and find a coverage first
9004         --
9005         if g_debug then
9006           hr_utility.set_location(' Now check for Coverage and Premium' ,50 );
9007         end if;
9008         --
9009         IF    p_oipl_id IS NOT NULL
9010            OR p_pl_id IS NOT NULL
9011            OR p_plip_id IS NOT NULL THEN
9012             --
9013             ben_derive_part_and_rate_cvg.get_hours_rate(p_pl_id=> p_pl_id
9014              ,p_oipl_id           => p_oipl_id
9015              ,p_plip_id           => p_plip_id
9016              ,p_business_group_id => p_business_group_id
9017              ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
9018                                       ,p_effective_date))
9019              ,p_rec               => l_rate_cvg_rec);
9020           --
9021 
9022           IF   NVL(l_rate_cvg_rec.once_r_cntug_cd ,'-1') = 'ONCE'
9023                AND NVL(p_comp_rec.once_r_cntug_cd ,'-1') = 'ONCE'
9024                AND p_comp_rec.elig_flag = 'Y'   THEN
9025             --
9026             -- In this case we do not have to derive the hours worked as the
9027             -- eligibility has been met, just return the frozen values and
9028             -- ignore the business rule check for the eligbility profile
9029             --
9030             null ;
9031             --
9032           ELSIF l_rate_cvg_rec.exist = 'Y' THEN     /* Changed from l_rate_rec to l_rate_cvg_rec */
9033             --
9034             if g_debug then
9035               hr_utility.set_location(' l_rate_cvg_rec.exist' , 60);
9036             end if;
9037             --
9038             l_cvg  := TRUE;
9039             --
9040 
9041             IF l_rate_cvg_rec.hrs_wkd_calc_rl IS NOT NULL THEN
9042               ben_determine_date.main(p_date_cd=> l_rate_cvg_rec.hrs_wkd_det_cd
9043                ,p_formula_id        => l_rate_cvg_rec.hrs_wkd_calc_rl
9044                ,p_person_id         => p_person_id
9045                ,p_pgm_id            => NVL(p_pgm_id
9046                                         ,p_comp_obj_tree_row.par_pgm_id)
9047                ,p_bnfts_bal_id      => l_rate_cvg_rec.bnfts_bal_id
9048                ,p_pl_id             => p_pl_id
9049                ,p_oipl_id           => NVL(p_oipl_id
9050                                         ,l_oiplip_rec.oipl_id)
9051                ,p_business_group_id => p_business_group_id
9052                ,p_returned_date     => l_start_date
9053                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
9054                ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
9055                                         ,p_effective_date));
9056                 --
9057                 run_rule(p_formula_id => l_rate_cvg_rec.hrs_wkd_calc_rl
9058                  ,p_empasg_row        => p_empasg_row
9059                ,p_benasg_row        => p_benasg_row
9060                ,p_pil_row           => p_pil_row
9061                ,p_curroipl_row      => p_curroipl_row
9062                ,p_curroiplip_row    => p_curroiplip_row
9063                ,p_effective_date    => l_start_date
9064                ,p_lf_evt_ocrd_dt    => l_start_date
9065                ,p_business_group_id => p_business_group_id
9066                ,p_person_id         => p_person_id
9067                ,p_pgm_id            => p_pgm_id
9068                ,p_pl_id             => p_pl_id
9069                ,p_oipl_id           => p_oipl_id
9070                ,p_oiplip_id         => p_oiplip_id
9071                ,p_plip_id           => p_plip_id
9072                ,p_ptip_id           => p_ptip_id
9073                ,p_ret_date          => l_dummy_date
9074                ,p_ret_val           => l_rate_cvg_result);
9075                 --
9076                 -- Round value if rounding needed
9077                 --
9078                 --
9079               IF    l_rate_cvg_rec.rndg_cd IS NOT NULL
9080                OR l_rate_cvg_rec.rndg_rl IS NOT NULL THEN
9081                 --
9082                 l_rate_cvg_result  :=
9083                   benutils.do_rounding(p_rounding_cd=> l_rate_cvg_rec.rndg_cd
9084                  ,p_rounding_rl    => l_rate_cvg_rec.rndg_rl
9085                  ,p_value          => l_rate_cvg_result
9086                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
9087                                        ,p_effective_date));
9088                 --
9089               END IF;
9090             --
9091             ELSE
9092               --
9093               if g_debug then
9094                 hr_utility.set_location(' call to hours_calculation ' , 65 );
9095               end if;
9096               l_rate_cvg_result  :=
9097                hours_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
9098                ,p_empasg_row        => p_empasg_row
9099                ,p_benasg_row        => p_benasg_row
9100                ,p_curroiplip_row    => p_curroiplip_row
9101                ,p_rec               => l_rate_cvg_rec
9102                ,p_business_group_id => p_business_group_id
9103                ,p_person_id         => p_person_id
9104                ,p_pgm_id            => p_pgm_id
9105                ,p_pl_id             => p_pl_id
9106                ,p_oipl_id           => p_oipl_id
9107                ,p_oiplip_id         => p_oiplip_id
9108                ,p_plip_id           => p_plip_id
9109                ,p_ptip_id           => p_ptip_id
9110                ,p_effective_date    => p_effective_date
9111                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
9112                --
9113               IF l_rate_cvg_result is not null THEN
9114                 --
9115                 --
9116                 ben_derive_part_and_rate_cvg.get_hours_rate(p_pl_id=> p_pl_id
9117                  ,p_oipl_id           => p_oipl_id
9118                  ,p_plip_id           => p_plip_id
9119                  ,p_business_group_id => p_business_group_id
9120                  ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,NVL(p_lf_evt_ocrd_dt
9121                                           ,p_effective_date))
9122                  ,p_rec               => l_rate_cvg_rec);
9123                 --
9124                 --
9125                 IF ( ben_whatif_elig.g_bal_hwf_val IS NULL
9126                    AND ben_whatif_elig.g_bnft_bal_hwf_val IS NULL) THEN
9127                   --
9128                   ben_seeddata_object.get_object(p_rec=> l_der_cvg_rec);
9129                   --
9130                   if g_debug then
9131                     hr_utility.set_location('  call hours_worked_min_max ' ,75);
9132                   end if;
9133                   hours_worked_min_max
9134                     (p_calculate_only_mode =>p_calculate_only_mode
9135                     ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
9136                     ,p_curroiplip_row      =>p_curroiplip_row
9137                  --   ,p_rate_rec            =>l_rate_rec
9138                     ,p_comp_rec            =>p_comp_rec
9139                     ,p_empasg_row          =>p_empasg_row
9140                     ,p_benasg_row          =>p_benasg_row
9141                     ,p_person_id           =>p_person_id
9142                     ,p_pgm_id              =>p_pgm_id
9143                     ,p_pl_id               =>p_pl_id
9144                     ,p_oipl_id             =>p_oipl_id
9145                     ,p_oiplip_id           =>p_oiplip_id
9146                     ,p_plip_id             =>p_plip_id
9147                     ,p_ptip_id             =>p_ptip_id
9148                     ,p_business_group_id   =>p_business_group_id
9149                     ,p_ler_id              =>l_der_cvg_rec.drvdhrw_id
9150                     ,p_min_value           =>l_rate_cvg_rec.mn_hrs_num
9151                     ,p_max_value           =>l_rate_cvg_rec.mx_hrs_num
9152                     ,p_new_value           =>l_rate_cvg_result
9153                     ,p_old_value           =>p_comp_rec.rt_hrs_wkd_val
9154                     ,p_subtract_date       =>l_subtract_date
9155                     ,p_det_cd              =>l_rate_cvg_rec.hrs_wkd_det_cd
9156                     ,p_formula_id          =>l_rate_cvg_rec.hrs_wkd_det_rl
9157                     ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
9158                     ,p_effective_date      =>p_effective_date
9159                     ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
9160                     ,p_hrs_src_cd          =>l_rate_cvg_rec.hrs_src_cd
9161                     ,p_bnfts_bal_id        =>l_rate_cvg_rec.bnfts_bal_id
9162                   ) ;
9163                 END IF; -- ben_whatif_elig
9164                 --
9165               END IF; -- l_rate_cvg_result
9166               --
9167             END IF; -- l_rate_cvg_rec.los_calc_rl
9168             --
9169           END IF; -- l_rate_cvg_rec.exist
9170         --
9171         END IF ; -- oipl_id
9172         --
9173         if g_debug then
9174           hr_utility.set_location(' Now call ben_derive_part_and_rate_prem ' , 80);
9175         end if;
9176         IF  p_oipl_id IS NOT NULL
9177             OR p_pl_id IS NOT NULL THEN
9178           --
9179           -- Try and find a premium
9180           --
9181           ben_derive_part_and_rate_prem.get_hours_rate(p_pl_id=> p_pl_id
9182                ,p_oipl_id           => p_oipl_id
9183                ,p_business_group_id => p_business_group_id
9184                ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,
9185                                             NVL(p_lf_evt_ocrd_dt ,p_effective_date))
9186                ,p_rec               => l_rate_prem_rec);
9187               --
9188           IF   NVL(l_rate_prem_rec.once_r_cntug_cd ,'-1') = 'ONCE'
9189                AND NVL(p_comp_rec.once_r_cntug_cd ,'-1') = 'ONCE'
9190                AND p_comp_rec.elig_flag = 'Y'   THEN
9191              --
9192              null ;
9193              --
9194              -- In this case we do not have to derive the hours worked as the
9195              -- eligibility has been met, just return the frozen values and
9196              -- ignore the business rule check for the eligbility profile
9197              --
9198           ELSIF l_rate_prem_rec.exist = 'Y'  THEN
9199             --
9200             if g_debug then
9201               hr_utility.set_location(' l_rate_prem_rec.exist Y ',85);
9202             end if;
9203             l_prem  := TRUE;
9204             --
9205             IF l_rate_prem_rec.hrs_wkd_calc_rl IS NOT NULL THEN
9206               --
9207               ben_determine_date.main(p_date_cd=> l_rate_prem_rec.hrs_wkd_det_cd
9208                ,p_formula_id        => l_rate_prem_rec.hrs_wkd_calc_rl
9209                ,p_person_id         => p_person_id
9210                ,p_pgm_id            => NVL(p_pgm_id
9211                                         ,p_comp_obj_tree_row.par_pgm_id)
9212                ,p_bnfts_bal_id      => l_rate_prem_rec.bnfts_bal_id
9213                ,p_pl_id             => p_pl_id
9214                ,p_oipl_id           => NVL(p_oipl_id
9215                                         ,l_oiplip_rec.oipl_id)
9216                ,p_business_group_id => p_business_group_id
9217                ,p_returned_date     => l_start_date
9218                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
9219                ,p_effective_date    => NVL(p_lf_evt_ocrd_dt
9220                                         ,p_effective_date));
9221                 --
9222                 run_rule(p_formula_id => l_rate_prem_rec.hrs_wkd_calc_rl
9223                  ,p_empasg_row        => p_empasg_row
9224                ,p_benasg_row        => p_benasg_row
9225                ,p_pil_row           => p_pil_row
9226                ,p_curroipl_row      => p_curroipl_row
9227                ,p_curroiplip_row    => p_curroiplip_row
9228                ,p_effective_date    => l_start_date
9229                ,p_lf_evt_ocrd_dt    => l_start_date
9230                ,p_business_group_id => p_business_group_id
9231                ,p_person_id         => p_person_id
9232                ,p_pgm_id            => p_pgm_id
9233                ,p_pl_id             => p_pl_id
9234                ,p_oipl_id           => p_oipl_id
9235                ,p_oiplip_id         => p_oiplip_id
9236                ,p_plip_id           => p_plip_id
9237                ,p_ptip_id           => p_ptip_id
9238                ,p_ret_date          => l_dummy_date
9239                ,p_ret_val           => l_rate_prem_result);
9240                 --
9241                 -- Round value if rounding needed
9242                 --
9243                 --
9244               IF    l_rate_prem_rec.rndg_cd IS NOT NULL
9245                OR l_rate_prem_rec.rndg_rl IS NOT NULL THEN
9246                 --
9247                 l_rate_prem_result  :=
9248                   benutils.do_rounding(p_rounding_cd=> l_rate_prem_rec.rndg_cd
9249                  ,p_rounding_rl    => l_rate_prem_rec.rndg_rl
9250                  ,p_value          => l_rate_prem_result
9251                  ,p_effective_date => NVL(p_lf_evt_ocrd_dt
9252                                        ,p_effective_date));
9253                 --
9254               END IF;
9255             --
9256             ELSE
9257               --
9258               if g_debug then
9259                 hr_utility.set_location(' call to hours_calculation ' , 90);
9260               end if;
9261               l_rate_prem_result  :=
9262                hours_calculation(p_comp_obj_tree_row=> p_comp_obj_tree_row
9263                ,p_empasg_row        => p_empasg_row
9264                ,p_benasg_row        => p_benasg_row
9265                ,p_curroiplip_row    => p_curroiplip_row
9266                ,p_rec               => l_rate_prem_rec
9267                ,p_business_group_id => p_business_group_id
9268                ,p_person_id         => p_person_id
9269                ,p_pgm_id            => p_pgm_id
9270                ,p_pl_id             => p_pl_id
9271                ,p_oipl_id           => p_oipl_id
9272                ,p_oiplip_id         => p_oiplip_id
9273                ,p_plip_id           => p_plip_id
9274                ,p_ptip_id           => p_ptip_id
9275                ,p_effective_date    => p_effective_date
9276                ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt);
9277                --
9278                if g_debug then
9279                  hr_utility.set_location(' l_rate_prem_result '||l_rate_prem_result ,95);
9280                end if;
9281               --
9282               IF l_rate_prem_result is not null THEN
9283                 --
9284                 --
9285                 ben_derive_part_and_rate_prem.get_hours_rate(
9286                   p_pl_id             => p_pl_id
9287                  ,p_oipl_id           => p_oipl_id
9288                  ,p_old_val           => p_comp_rec.rt_hrs_wkd_val
9289                  ,p_new_val           => l_rate_prem_result
9290                  ,p_business_group_id => p_business_group_id
9291                  ,p_effective_date    =>  nvl(g_fonm_cvg_strt_dt,
9292                                               NVL(p_lf_evt_ocrd_dt ,p_effective_date))
9293                  ,p_rec               => l_rate_prem_rec);
9294                 --
9295                 IF ( ben_whatif_elig.g_bal_hwf_val IS NULL
9296                    AND ben_whatif_elig.g_bnft_bal_hwf_val IS NULL) THEN
9297                   --
9298                   ben_seeddata_object.get_object(p_rec=> l_der_prem_rec);
9299                   --
9300                   if g_debug then
9301                     hr_utility.set_location(' call to comp_level_min_max ' ,100);
9302                   end if;
9303                   --
9304                   hours_worked_min_max
9305                     (p_calculate_only_mode =>p_calculate_only_mode
9306                     ,p_comp_obj_tree_row   =>p_comp_obj_tree_row
9307                     ,p_curroiplip_row      =>p_curroiplip_row
9308                  --   ,p_rate_rec            =>l_rate_rec
9309                     ,p_comp_rec            =>p_comp_rec
9310                     ,p_empasg_row          =>p_empasg_row
9311                     ,p_benasg_row          =>p_benasg_row
9312                     ,p_person_id           =>p_person_id
9313                     ,p_pgm_id              =>p_pgm_id
9314                     ,p_pl_id               =>p_pl_id
9315                     ,p_oipl_id             =>p_oipl_id
9316                     ,p_oiplip_id           =>p_oiplip_id
9317                     ,p_plip_id             =>p_plip_id
9318                     ,p_ptip_id             =>p_ptip_id
9319                     ,p_business_group_id   =>p_business_group_id
9320                     ,p_ler_id              =>l_der_prem_rec.drvdhrw_id
9321                     ,p_min_value           =>l_rate_prem_rec.mn_hrs_num
9322                     ,p_max_value           =>l_rate_prem_rec.mx_hrs_num
9323                     ,p_new_value           =>l_rate_prem_result
9324                     ,p_old_value           =>p_comp_rec.rt_hrs_wkd_val
9325                     ,p_subtract_date       =>l_subtract_date
9326                     ,p_det_cd              =>l_rate_prem_rec.hrs_wkd_det_cd
9327                     ,p_formula_id          =>l_rate_prem_rec.hrs_wkd_det_rl
9328                     ,p_ptnl_ler_trtmt_cd   =>p_ptnl_ler_trtmt_cd
9329                     ,p_effective_date      =>p_effective_date
9330                     ,p_lf_evt_ocrd_dt      =>p_lf_evt_ocrd_dt
9331                     ,p_hrs_src_cd          =>l_rate_prem_rec.hrs_src_cd
9332                     ,p_bnfts_bal_id        =>l_rate_prem_rec.bnfts_bal_id
9333                   ) ;
9334                 END IF; -- ben_whatif_elig
9335                 --
9336               END IF; -- l_rate_cvg_result
9337               --
9338             END IF; -- l_rate_prem_rec.los_calc_rl
9339             --
9340           END IF; -- l_rate_prem_rec.exist
9341         --
9342         END IF ; -- oipl_id
9343 --
9344         IF l_rate_result IS NULL and l_rate_cvg_result IS NULL and  l_rate_prem_result IS NULL THEN
9345           --
9346           p_comp_rec.rt_hrs_wkd_val  := NULL;
9347           p_comp_rec.rt_hrs_wkd_bndry_perd_cd  := NULL;
9348           --
9349         ELSIF l_rate_result is NOT NULL THEN
9350           if g_debug then
9351             hr_utility.set_location(' Step 28',10);
9352           end if;
9353           p_comp_rec.rt_hrs_wkd_val  := l_rate_result;
9354           p_comp_rec.rt_hrs_wkd_bndry_perd_cd  :=  NULL ;
9355           --
9356         ELSIF l_rate_cvg_result is NOT NULL then
9357           --
9358           p_comp_rec.rt_hrs_wkd_val  := l_rate_cvg_result;
9359           p_comp_rec.rt_hrs_wkd_bndry_perd_cd  := NULL ;
9360           if g_debug then
9361             hr_utility.set_location(' Step 29',10);
9362           end if;
9363         ELSIF l_rate_prem_result is NOT NULL THEN
9364           --
9365           p_comp_rec.rt_hrs_wkd_val  := l_rate_prem_result;
9366           p_comp_rec.rt_hrs_wkd_bndry_perd_cd  :=  NULL ;
9367           if g_debug then
9368             hr_utility.set_location(' Step 30',10);
9369           end if;
9370         END IF;
9371       --
9372       END IF;
9373     --
9374     END IF;
9375     --
9376     -- Set value of once_r_cntug_cd as this is what will be updated and passed
9377     -- bendetel.pkb
9378     --
9379     IF l_elig_rec.exist = 'Y' THEN
9380       --
9381       IF     NVL(l_elig_rec.once_r_cntug_cd
9382               ,'-1') = 'CNTNG'
9383          AND NVL(p_comp_rec.once_r_cntug_cd
9384               ,'-1') = 'ONCE' THEN
9385         --
9386         p_comp_rec.once_r_cntug_cd  := 'CNTNG';
9387       --
9388       ELSIF     NVL(l_elig_rec.once_r_cntug_cd
9389                  ,'-1') = 'ONCE'
9390             AND NVL(p_comp_rec.once_r_cntug_cd
9391                  ,'-1') = 'CNTNG' THEN
9392         --
9393         p_comp_rec.once_r_cntug_cd  := 'ONCE';
9394         --
9395         -- Override the elig flag to force the check on bendetel.pkb
9396         --
9397         p_comp_rec.elig_flag        := 'N';
9398       --
9399       ELSIF     NVL(l_elig_rec.once_r_cntug_cd
9400                  ,'-1') = 'CNTNG'
9401             AND NVL(p_comp_rec.once_r_cntug_cd
9402                  ,'-1') = 'CNTNG' THEN
9403         --
9404         p_comp_rec.once_r_cntug_cd  := 'CNTNG';
9405       --
9406       ELSIF NVL(l_elig_rec.once_r_cntug_cd
9407              ,'-1') = '-1' THEN
9408         --
9409         p_comp_rec.once_r_cntug_cd  := NULL;
9410       --
9411       END IF;
9412     --
9413     END IF;
9414     --
9415     if g_debug then
9416       hr_utility.set_location('Leaving ' || l_package,10);
9417     end if;
9418   --
9419   END calculate_hours_worked;
9420 --
9421   FUNCTION is_payment_late
9422            (p_amt_due               in number
9423            ,p_shortfall_amt         in number
9424            ,p_allwd_underpymt_value in number
9425            ,p_allwd_underpymt_pct   in number)
9426   RETURN boolean IS
9427     l_allwd_underpymt_amt number;
9428     l_late_pymt_evt       boolean := FALSE;
9429   BEGIN
9430     l_allwd_underpymt_amt := (p_allwd_underpymt_pct/100) * p_amt_due;
9431 
9432     l_allwd_underpymt_amt := round(l_allwd_underpymt_amt,2);
9433 
9434     if l_allwd_underpymt_amt > p_allwd_underpymt_value then
9435       l_allwd_underpymt_amt := p_allwd_underpymt_value;
9436     end if;
9437 
9438     if g_debug then
9439       hr_utility.set_location('total amt due'||p_amt_due,11);
9440       hr_utility.set_location('total shortfall'||p_shortfall_amt,11);
9441       hr_utility.set_location('allowed underpayment amt'||l_allwd_underpymt_amt,11);
9442     end if;
9443 
9444     if  p_shortfall_amt > l_allwd_underpymt_amt then
9445       l_late_pymt_evt := TRUE;
9446     end if;
9447 
9448     return l_late_pymt_evt;
9449 
9450   END is_payment_late;
9451   --
9452   PROCEDURE get_amt_due_and_shortfall
9453           (p_acty_base_rt_id        in number
9454           ,p_assignment_id          in number
9455           ,p_payroll_id             in number
9456           ,p_due_date               in date
9457           ,p_effective_date         in date
9458           ,p_business_group_id      in number
9459           ,p_from_date              in date
9460           ,p_to_date                in date
9461           ,p_ann_rt_val             in number
9462           ,p_person_id              in number
9463           ,p_organization_id        in number
9464           ,p_prtt_enrt_rslt_id      in number
9465           ,p_rt_strt_dt             in date
9466           ,p_rt_end_dt              in date
9467           ,p_rt_mlt_cd              in varchar2
9468           ,p_amt_due                out nocopy number
9469           ,p_shortfall_amt          out nocopy number
9470           ,p_pymt_short             out nocopy boolean
9471           )
9472   IS
9473 
9474     CURSOR c_get_pymt(
9475       c_effective_date    IN DATE
9476      ,c_business_group_id IN NUMBER
9477      ,c_acty_base_rt_id   IN NUMBER
9478      ,c_assignment_id     IN NUMBER
9479      ,c_payroll_id        IN NUMBER
9480      ,c_from_date         IN DATE
9481      ,c_to_date           IN DATE) IS
9482       SELECT   NVL(SUM(a.result_value),0) result_value
9483       FROM     pay_run_result_values a
9484               ,pay_element_types_f b
9485               ,pay_assignment_actions d
9486               ,pay_payroll_actions e
9487               ,per_time_periods g
9488               ,pay_run_results h
9489               ,ben_acty_base_rt_f i
9490               ,pay_input_values_f j
9491       WHERE    d.assignment_id = c_assignment_id
9492       AND      d.payroll_action_id = e.payroll_action_id
9493       AND      i.input_value_id = j.input_value_id
9494       AND      i.element_type_id = b.element_type_id
9495       AND      i.acty_base_rt_id = c_acty_base_rt_id
9496       AND      c_effective_date BETWEEN i.effective_start_date
9497                    AND i.effective_end_date
9498       AND      i.business_group_id = c_business_group_id
9499       AND      g.payroll_id = c_payroll_id
9500       AND      b.element_type_id = h.element_type_id
9501       AND      d.assignment_action_id = h.assignment_action_id
9502       AND      e.date_earned BETWEEN g.start_date AND g.end_date
9503       AND      e.date_earned BETWEEN c_from_date AND c_to_date
9504       AND      a.input_value_id = j.input_value_id
9505       AND      a.run_result_id = h.run_result_id
9506       AND      j.element_type_id = b.element_type_id
9507       AND      c_effective_date BETWEEN b.effective_start_date
9508                    AND b.effective_end_date
9509       AND      c_effective_date BETWEEN j.effective_start_date
9510                    AND j.effective_end_date;
9511 
9512 
9513       l_pymt_amt      number := 0;
9514       l_amt_due       number := 0;
9515       l_shortfall_amt number := 0;
9516       l_pymt_short    boolean := FALSE;
9517 
9518       l_per_month_amt      number;
9519       l_first_month_amt    number;
9520       l_last_month_amt     number;
9521 
9522   BEGIN
9523 
9524     OPEN c_get_pymt
9525       (c_effective_date    => nvl(g_fonm_cvg_strt_dt,p_effective_date)
9526       ,c_business_group_id => p_business_group_id
9527       ,c_acty_base_rt_id   => p_acty_base_rt_id
9528       ,c_assignment_id     => p_assignment_id
9529       ,c_payroll_id        => p_payroll_id
9530       ,c_from_date         => p_from_date
9531       ,c_to_date           => p_to_date);
9532     FETCH c_get_pymt INTO l_pymt_amt;
9533     IF c_get_pymt%NOTFOUND THEN
9534       l_pymt_amt := 0;
9535     END IF;
9536     CLOSE c_get_pymt;
9537 
9538     -- Check if payment is for full amount
9539     --
9540     -- Fetch Amount Due
9541     --
9542 
9543     ben_cobra_requirements.get_amount_due
9544             (p_person_id         => p_person_id
9545             ,p_business_group_id => p_business_group_id
9546             ,p_assignment_id     => p_assignment_id
9547             ,p_payroll_id        => p_payroll_id
9548             ,p_organization_id   => p_organization_id
9549             ,p_effective_date    => nvl(g_fonm_cvg_strt_dt,p_effective_date)
9550             ,p_prtt_enrt_rslt_id => p_prtt_enrt_rslt_id
9551             ,p_acty_base_rt_id   => p_acty_base_rt_id
9552             ,p_ann_rt_val        => p_ann_rt_val
9553             ,p_mlt_cd            => p_rt_mlt_cd
9554             ,p_rt_strt_dt        => p_rt_strt_dt
9555             ,p_rt_end_dt         => p_rt_end_dt
9556             ,p_first_month_amt   => l_first_month_amt
9557             ,p_per_month_amt     => l_per_month_amt
9558             ,p_last_month_amt    => l_last_month_amt);
9559 
9560     --
9561     -- For first month, the amount due = l_first_month_amt
9562     -- For subsequent months, the amount due = l_per_month_amt * No. of months
9563     -- For last month, the amount due = l_last_month_amt
9564     --
9565 
9566     if (p_from_date = p_rt_strt_dt) then -- First month
9567       l_amt_due := l_first_month_amt;
9568     elsif (p_to_date = p_rt_end_dt) then -- Last month
9569       l_amt_due := l_last_month_amt;
9570     else
9571       l_amt_due := l_per_month_amt;
9572     end if;
9573 
9574     if g_debug then
9575       hr_utility.set_location('amt due'||l_amt_due,11);
9576       hr_utility.set_location('pymt_amt'||l_pymt_amt,11);
9577       hr_utility.set_location('p_from_date'||p_from_date,11);
9578       hr_utility.set_location('p_to_date'||p_to_date,11);
9579     end if;
9580 
9581     IF l_amt_due > l_pymt_amt THEN
9582       l_shortfall_amt := l_amt_due - l_pymt_amt;
9583       l_pymt_short :=TRUE;
9584     END IF;
9585 
9586     -- Set Out variables
9587     p_amt_due := NVL(l_amt_due,0);
9588     p_shortfall_amt := NVL(l_shortfall_amt,0);
9589     p_pymt_short := l_pymt_short;
9590 
9591   END get_amt_due_and_shortfall;
9592   --
9593   PROCEDURE get_allowed_underpayment
9594     (p_pgm_id                in number
9595     ,p_business_group_id     in number
9596     ,p_effective_date        in date
9597     ,p_allwd_underpymt_value out nocopy number
9598     ,p_allwd_underpymt_pct   out nocopy number
9599     )
9600   IS
9601 
9602     CURSOR c_allwd_underpymt(c_effective_date in date) is
9603      select  NVL(to_number(fti.FED_INFORMATION1),0) allwd_underpymt_value
9604             ,NVL(to_number(fti.FED_INFORMATION2),0) allwd_underpymt_pct
9605      from   pay_us_federal_tax_info_f fti
9606      where  fti.fed_information_category = 'BENEFIT UNDERPAY'
9607      and    c_effective_date between fti.effective_start_date
9608             and fti.effective_end_date;
9609 
9610     l_allwd_underpymt_value number;
9611     l_allwd_underpymt_pct   number;
9612   BEGIN
9613 
9614     open c_allwd_underpymt(c_effective_date =>  nvl(g_fonm_cvg_strt_dt,p_effective_date));
9615     fetch c_allwd_underpymt into l_allwd_underpymt_value,l_allwd_underpymt_pct;
9616     if c_allwd_underpymt%notfound then
9617       l_allwd_underpymt_value := 0;
9618       l_allwd_underpymt_pct   := 0;
9619     end if;
9620     close c_allwd_underpymt;
9621 
9622     -- Set out variables
9623     p_allwd_underpymt_value := l_allwd_underpymt_value;
9624     p_allwd_underpymt_pct := l_allwd_underpymt_pct;
9625 
9626   END get_allowed_underpayment;
9627   --
9628   PROCEDURE determine_cobra_payments
9629     (p_calculate_only_mode in     boolean default false
9630     ,p_person_id           IN     NUMBER
9631     ,p_business_group_id   IN     NUMBER
9632     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
9633     ,p_effective_date      IN     DATE
9634     ,p_pgm_id              IN     NUMBER
9635     ,p_ptip_id             IN     NUMBER
9636     ,p_cbr_quald_bnf_id    IN     NUMBER
9637     )
9638   IS
9639     --
9640     l_package               VARCHAR2(80)
9641                                    := g_package || '.determine_cobra_payments';
9642     l_lf_evt_ocrd_dt        DATE;
9643     l_ok                    BOOLEAN;
9644     l_exists                VARCHAR2(1);
9645     l_der_rec               ben_seeddata_object.g_derived_factor_info_rec;
9646     l_rec                   ben_person_object.g_person_date_info_rec;
9647     l_due_date              DATE;
9648     l_eff_due_date          DATE;
9649     l_elcns_made_dt         DATE;
9650     l_pymt_amt              number;
9651     l_amt_due               number;
9652     l_late_pymt_evt         BOOLEAN                                  := FALSE;
9653     l_cobra_pymt_due_dy_num ben_pl_f.cobra_pymt_due_dy_num%TYPE;
9654     l_organization_id       NUMBER;
9655     l_assignment_id         per_all_assignments_f.assignment_id%TYPE;
9656     l_payroll_id            per_all_assignments_f.payroll_id%TYPE;
9657     --
9658     CURSOR c_get_cbr_due_day(
9659       p_pl_id NUMBER) IS
9660       SELECT   pln.cobra_pymt_due_dy_num
9661       FROM     ben_pl_f pln
9662       WHERE    pln.pl_id = p_pl_id
9663       AND       nvl(g_fonm_cvg_strt_dt,p_effective_date)  BETWEEN pln.effective_start_date
9664                    AND pln.effective_end_date
9665       AND      pln.business_group_id = p_business_group_id;
9666 --
9667 -- -------------------------------------------------------------
9668 -- If this cursor needs to change, check benelmen.pkb: c_get_end_dt
9669 -- And there is a form that displays payments that uses it too.
9670 -- see oab/flow_charts/run_results.vsd
9671 -- -------------------------------------------------------------
9672 
9673   /* Bug 3097501
9674 
9675     CURSOR c_get_pymt(
9676       p_acty_base_rt_id IN NUMBER
9677      ,p_assignment_id   IN NUMBER
9678      ,p_payroll_id      IN NUMBER
9679      ,p_first_pymt      IN VARCHAR2) IS
9680       SELECT   a.result_value
9681       FROM     pay_run_result_values a
9682               ,pay_element_types_f b
9683               ,pay_assignment_actions d
9684               ,pay_payroll_actions e
9685               ,per_time_periods g
9686               ,pay_run_results h
9687               ,ben_acty_base_rt_f i
9688               ,pay_input_values_f j
9689       WHERE    d.assignment_id = p_assignment_id
9690       AND      d.payroll_action_id = e.payroll_action_id
9691       AND      i.input_value_id = j.input_value_id
9692       AND      i.element_type_id = b.element_type_id
9693       AND      i.acty_base_rt_id = p_acty_base_rt_id
9694       AND       nvl(g_fonm_cvg_strt_dt,p_effective_date) BETWEEN i.effective_start_date
9695                    AND i.effective_end_date
9696       AND      i.business_group_id = p_business_group_id
9697       AND      g.payroll_id = p_payroll_id
9698       AND      l_due_date BETWEEN g.start_date AND g.end_date
9699       AND      b.element_type_id = h.element_type_id
9700       AND      d.assignment_action_id = h.assignment_action_id
9701       AND      e.date_earned BETWEEN g.start_date AND g.end_date
9702       AND      (
9703                     (    p_first_pymt = 'Y'
9704                      AND l_due_date >= e.date_earned)
9705                  OR p_first_pymt = 'N')
9706       AND      a.input_value_id = j.input_value_id
9707       AND      a.run_result_id = h.run_result_id
9708       AND      j.element_type_id = b.element_type_id
9709       AND       nvl(g_fonm_cvg_strt_dt,p_effective_date) BETWEEN b.effective_start_date
9710                    AND b.effective_end_date
9711       AND      p_effective_date BETWEEN j.effective_start_date
9712                    AND j.effective_end_date;
9713     --
9714     CURSOR c_get_element_entry_values(
9715       p_element_entry_value_id IN NUMBER) IS
9716       SELECT   eev.screen_entry_value
9717       FROM     pay_element_entry_values_f eev
9718       WHERE    eev.element_entry_value_id = p_element_entry_value_id
9719       AND       nvl(g_fonm_cvg_strt_dt,p_effective_date) BETWEEN eev.effective_start_date
9720                  AND eev.effective_end_date;
9721   */
9722 
9723     l_from_date date;
9724     l_to_date date;
9725     l_strt_dt date;
9726 
9727     -- Bug 3097501 : End
9728 
9729     --
9730     CURSOR c_get_prtt_enrt_rslt IS
9731       SELECT   pen.pl_id
9732               ,prv.element_entry_value_id
9733               ,prv.acty_base_rt_id
9734               ,prv.rt_strt_dt
9735               ,prv.rt_end_dt
9736               ,prv.ann_rt_val
9737               ,pen.prtt_enrt_rslt_id
9738               ,prv.mlt_cd
9739               ,prv.per_in_ler_id
9740               ,pen.enrt_cvg_strt_dt
9741       FROM     ben_prtt_enrt_rslt_f pen
9742               ,ben_prtt_rt_val prv
9743       WHERE    pen.person_id = p_person_id
9744       AND      pen.pgm_id = p_pgm_id
9745       AND      pen.prtt_enrt_rslt_stat_cd IS NULL
9746       AND      pen.sspndd_flag = 'N'
9747       AND      pen.business_group_id = p_business_group_id
9748       AND      pen.prtt_enrt_rslt_id = prv.prtt_enrt_rslt_id
9749       AND      prv.business_group_id = pen.business_group_id
9750       AND      prv.prtt_rt_val_stat_cd IS NULL
9751       AND      prv.acty_typ_cd LIKE 'PBC%'
9752       AND      pen.effective_end_date = hr_api.g_eot
9753       ORDER BY prv.rt_strt_dt;
9754 
9755     --
9756     CURSOR c_get_elcns_made_dt IS
9757       SELECT   pel.elcns_made_dt
9758               ,crp.per_in_ler_id
9759       FROM     ben_cbr_per_in_ler crp, ben_pil_elctbl_chc_popl pel
9760       WHERE    crp.cbr_quald_bnf_id = p_cbr_quald_bnf_id
9761       AND      crp.init_evt_flag = 'Y'
9762       AND      crp.business_group_id = p_business_group_id
9763       AND      crp.per_in_ler_id = pel.per_in_ler_id
9764       AND      pel.pgm_id = p_pgm_id
9765       AND      pel.business_group_id = crp.business_group_id;
9766     --
9767     l_pen_rec               c_get_prtt_enrt_rslt%ROWTYPE;
9768     l_date                  date;
9769     l_cbr_per_in_ler_id     ben_per_in_ler.per_in_ler_id%type;
9770     l_month_last_day        date;
9771     l_allwd_underpymt_value number;
9772     l_allwd_underpymt_pct   number;
9773 
9774     l_first_pymt_shortfall_amt  number;
9775     l_subseq_pymt_shortfall_amt number;
9776     l_first_pymt_amt_due        number;
9777     l_subseq_pymt_amt_due       number;
9778     l_first_pymt_short          boolean;
9779     l_subseq_pymt_short         boolean;
9780     l_first_pymt_due_date       date;
9781     l_subseq_pymt_due_date      date;
9782     l_check_first_pymt          boolean := FALSE;
9783     l_check_subseq_pymt         boolean := FALSE;
9784     l_shortfall_amt             number;
9785     l_pymt_due_date             date;
9786   BEGIN
9787     g_debug := hr_utility.debug_enabled;
9788     --
9789     if g_debug then
9790       hr_utility.set_location('Entering ' || l_package,10);
9791     end if;
9792     --
9793     --
9794     --  If the person has not made a payment within the a grace period
9795     --  generate a late or non-payment life event.
9796     --
9797     ben_person_object.get_object(p_person_id=> p_person_id
9798      ,p_rec       => l_rec);
9799     --
9800     --  Check if the person is late with his/her payment.
9801     --
9802 
9803     -- Bug 3097501 : Start
9804 
9805     get_allowed_underpayment
9806       (p_pgm_id                => p_pgm_id
9807       ,p_business_group_id     => p_business_group_id
9808       ,p_effective_date        => p_effective_date
9809       ,p_allwd_underpymt_value => l_allwd_underpymt_value
9810       ,p_allwd_underpymt_pct   => l_allwd_underpymt_pct
9811       );
9812 
9813     l_first_pymt_shortfall_amt := 0;
9814     l_subseq_pymt_shortfall_amt := 0;
9815     l_first_pymt_amt_due := 0;
9816     l_subseq_pymt_amt_due := 0;
9817 
9818     -- Bug 3097501 : End
9819 
9820     FOR l_pen_rec IN c_get_prtt_enrt_rslt LOOP
9821       --
9822       -- hr_utility.set_location('Found results' || l_pen_rec.pl_id,10);
9823       --
9824       --  Check if it is the first payment.
9825       --
9826       OPEN c_get_elcns_made_dt;
9827       FETCH c_get_elcns_made_dt INTO l_elcns_made_dt,l_cbr_per_in_ler_id;
9828       CLOSE c_get_elcns_made_dt;
9829       --
9830       -- hr_utility.set_location('l_elcns_made_dt' || l_elcns_made_dt,10);
9831       --
9832       l_due_date  := l_elcns_made_dt + 45;
9833       --
9834       -- hr_utility.set_location('l_due_date' || l_due_date,10);
9835       --
9836       IF p_effective_date > l_due_date THEN
9837         --
9838         --  Get the assignment to use.
9839         --
9840         ben_element_entry.get_abr_assignment(p_person_id=> p_person_id
9841          ,p_effective_date  =>  nvl(g_fonm_cvg_strt_dt,p_effective_date)
9842          ,p_acty_base_rt_id => l_pen_rec.acty_base_rt_id
9843          ,p_organization_id => l_organization_id
9844          ,p_payroll_id      => l_payroll_id
9845          ,p_assignment_id   => l_assignment_id);
9846         --
9847         --  Check if a payment has been made.
9848         --
9849 
9850         -- Bug 3097501 : Start
9851 
9852         OPEN c_get_cbr_due_day(l_pen_rec.pl_id);
9853         FETCH c_get_cbr_due_day INTO l_cobra_pymt_due_dy_num;
9854         CLOSE c_get_cbr_due_day;
9855 
9856         -- Check first payment only if its the initial COBRA qualifying event
9857         IF l_cbr_per_in_ler_id = l_pen_rec.per_in_ler_id then
9858 
9859           l_check_first_pymt := TRUE;
9860 
9861           l_from_date := l_pen_rec.rt_strt_dt; --Rate Start Date
9862           l_to_date :=   LEAST(l_pen_rec.rt_end_dt,LAST_DAY(l_pen_rec.rt_strt_dt)); --Last day of month
9863 
9864           get_amt_due_and_shortfall (
9865              p_acty_base_rt_id        => l_pen_rec.acty_base_rt_id
9866             ,p_assignment_id          => l_assignment_id
9867             ,p_payroll_id             => l_payroll_id
9868             ,p_due_date               => l_due_date
9869             ,p_effective_date         => p_effective_date
9870             ,p_business_group_id      => p_business_group_id
9871             ,p_from_date              => l_from_date
9872             ,p_to_date                => l_to_date
9873             ,p_ann_rt_val             => l_pen_rec.ann_rt_val
9874             ,p_person_id              => p_person_id
9875             ,p_organization_id        => l_organization_id
9876             ,p_prtt_enrt_rslt_id      => l_pen_rec.prtt_enrt_rslt_id
9877             ,p_rt_strt_dt             => l_pen_rec.rt_strt_dt
9878             ,p_rt_end_dt              => l_pen_rec.rt_end_dt
9879             ,p_rt_mlt_cd              => l_pen_rec.mlt_cd
9880             ,p_shortfall_amt          => l_shortfall_amt
9881             ,p_amt_due                => l_amt_due
9882             ,p_pymt_short             => l_first_pymt_short);
9883 
9884           l_first_pymt_shortfall_amt := l_first_pymt_shortfall_amt + l_shortfall_amt;
9885           l_first_pymt_amt_due       := l_first_pymt_amt_due + l_amt_due;
9886 
9887           l_pymt_due_date := LAST_DAY(ADD_MONTHS(l_pen_rec.rt_strt_dt,-1))
9888                              + NVL(l_cobra_pymt_due_dy_num,1);
9889 
9890           -- Life Event Occured Date for NOLP event triggered for the first payment
9891           -- is to be set to the greater of First Month COBRA Due Date and
9892           -- Coverage Start Date
9893           l_pymt_due_date := GREATEST(l_pymt_due_date,l_pen_rec.enrt_cvg_strt_dt);
9894 
9895           IF l_first_pymt_short THEN
9896             IF l_first_pymt_due_date IS NULL THEN
9897               l_first_pymt_due_date := l_pymt_due_date;
9898             ELSIF l_pymt_due_date < l_first_pymt_due_date THEN
9899               l_first_pymt_due_date := l_pymt_due_date;
9900             END IF;
9901           END IF;
9902 
9903         END IF;
9904 
9905         --
9906         -- if it is not the first payment, check if a payment is
9907         -- due.
9908         --
9909         IF l_cobra_pymt_due_dy_num IS NOT NULL THEN
9910 
9911          -- hr_utility.set_location('Found due day' || l_cobra_pymt_due_dy_num,10);
9912           -- Get the last due date to check if the person is late with
9913           --  his/her payment.
9914           --
9915           l_due_date := LAST_DAY(ADD_MONTHS(p_effective_date,-2)) +
9916                       l_cobra_pymt_due_dy_num;
9917 
9918           -- Bug 3208938
9919           -- If COBRA due day falls outside the month, use last day of month
9920 
9921           l_month_last_day := LAST_DAY(ADD_MONTHS(p_effective_date,-1));
9922 
9923           if l_due_date > l_month_last_day then
9924             l_due_date := l_month_last_day;
9925           end if;
9926 
9927           -- Bug 3208938
9928 
9929           l_eff_due_date  := l_due_date + 30;
9930           --
9931           -- hr_utility.set_location('l_due_date' || l_due_date,10);
9932           -- hr_utility.set_location('l_eff_due_date' || l_eff_due_date,10);
9933           --
9934           --  if the person has not made a payment by the due date, create
9935           --  a potential life event.
9936           --
9937 
9938           if l_cbr_per_in_ler_id = l_pen_rec.per_in_ler_id then
9939             l_strt_dt := LAST_DAY(l_pen_rec.rt_strt_dt) + 1;
9940           else
9941             l_strt_dt := LAST_DAY(ADD_MONTHS(l_pen_rec.rt_strt_dt,-1)) + 1;
9942           end if;
9943 
9944           IF p_effective_date <= l_eff_due_date THEN
9945             -- Bug 3125085 - If the temporal process is run before the
9946             -- last month's payment has become overdue, then
9947             -- check if payment for month prior to the last
9948             -- month is paid in full
9949             l_due_date :=  LAST_DAY(ADD_MONTHS(p_effective_date,-3)) +
9950                           l_cobra_pymt_due_dy_num;
9951 
9952             -- Bug 3208938
9953             -- If COBRA due day falls outside the month, use last day of month
9954 
9955             l_month_last_day := LAST_DAY(ADD_MONTHS(p_effective_date,-2));
9956 
9957             if l_due_date > l_month_last_day then
9958               l_due_date := l_month_last_day;
9959             end if;
9960 
9961             -- Bug 3208938
9962 
9963             l_eff_due_date  := l_due_date + 30;
9964           END IF;
9965 
9966           if g_debug then
9967             hr_utility.set_location('l_due_date '||l_due_date,11);
9968             hr_utility.set_location('l_strt_dt'||l_strt_dt,11);
9969           end if;
9970 
9971           IF (l_due_date >= l_strt_dt) AND (l_due_date <= LAST_DAY(l_pen_rec.rt_end_dt)) THEN
9972 
9973             l_check_subseq_pymt := TRUE;
9974 
9975             l_from_date := GREATEST((LAST_DAY(ADD_MONTHS(l_due_date,-1)) + 1),l_pen_rec.rt_strt_dt); --Month Start Date
9976             l_to_date :=   LEAST(l_pen_rec.rt_end_dt,LAST_DAY(l_due_date)); --Last day of month
9977 
9978             get_amt_due_and_shortfall(
9979                 p_acty_base_rt_id        => l_pen_rec.acty_base_rt_id
9980                ,p_assignment_id          => l_assignment_id
9981                ,p_payroll_id             => l_payroll_id
9982                ,p_due_date               => l_eff_due_date
9983                ,p_effective_date         => p_effective_date
9984                ,p_business_group_id      => p_business_group_id
9985                ,p_from_date              => l_from_date
9986                ,p_to_date                => l_to_date
9987                ,p_ann_rt_val             => l_pen_rec.ann_rt_val
9988                ,p_person_id              => p_person_id
9989                ,p_organization_id        => l_organization_id
9990                ,p_prtt_enrt_rslt_id      => l_pen_rec.prtt_enrt_rslt_id
9991                ,p_rt_strt_dt             => l_pen_rec.rt_strt_dt
9992                ,p_rt_end_dt              => l_pen_rec.rt_end_dt
9993                ,p_rt_mlt_cd              => l_pen_rec.mlt_cd
9994                ,p_shortfall_amt          => l_shortfall_amt
9995                ,p_amt_due                => l_amt_due
9996                ,p_pymt_short             => l_subseq_pymt_short);
9997 
9998 
9999             l_subseq_pymt_shortfall_amt := l_subseq_pymt_shortfall_amt + l_shortfall_amt;
10000             l_subseq_pymt_amt_due       := l_subseq_pymt_amt_due + l_amt_due;
10001 
10002             IF l_subseq_pymt_short THEN
10003               IF l_subseq_pymt_due_date IS NULL THEN
10004                 l_subseq_pymt_due_date := l_due_date;
10005               ELSIF l_due_date < l_subseq_pymt_due_date THEN
10006                 l_subseq_pymt_due_date := l_due_date;
10007               END IF;
10008             END IF;
10009 
10010           END IF;
10011         END IF;
10012       END IF;
10013     END LOOP;
10014 
10015     IF l_check_first_pymt THEN
10016       l_late_pymt_evt := is_payment_late
10017                            (p_amt_due               => l_first_pymt_amt_due
10018                            ,p_shortfall_amt         => l_first_pymt_shortfall_amt
10019                            ,p_allwd_underpymt_value => l_allwd_underpymt_value
10020                            ,p_allwd_underpymt_pct   => l_allwd_underpymt_pct);
10021 
10022       l_lf_evt_ocrd_dt := l_first_pymt_due_date;
10023     END IF;
10024 
10025     IF (NOT l_late_pymt_evt) AND (l_check_subseq_pymt) THEN
10026       l_late_pymt_evt := is_payment_late
10027                            (p_amt_due               => l_subseq_pymt_amt_due
10028                            ,p_shortfall_amt         => l_subseq_pymt_shortfall_amt
10029                            ,p_allwd_underpymt_value => l_allwd_underpymt_value
10030                            ,p_allwd_underpymt_pct   => l_allwd_underpymt_pct);
10031 
10032       l_lf_evt_ocrd_dt := l_subseq_pymt_due_date;
10033     END IF;
10034 
10035     -- Bug 3097501: End
10036     --
10037     -- hr_utility.set_location('l_due_date' || l_due_date,10);
10038     --
10039     IF l_late_pymt_evt THEN
10040       --
10041       IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
10042         --
10043         IF  (   l_lf_evt_ocrd_dt < p_effective_date
10044            AND NVL(p_ptnl_ler_trtmt_cd
10045                 ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
10046           --
10047           -- We are not creating past life events
10048           --
10049           NULL;
10050         --
10051         ELSE
10052           --
10053           ben_seeddata_object.get_object(p_rec=> l_der_rec);
10054           --
10055           IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10056               ,p_person_id      => p_person_id
10057               ,p_ler_id         => l_der_rec.drvdnlp_id
10058               ,p_effective_date => p_effective_date)
10059           THEN
10060             --
10061             create_ptl_ler
10062               (p_calculate_only_mode => p_calculate_only_mode
10063               ,p_ler_id              => l_der_rec.drvdnlp_id
10064               ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10065               ,p_person_id           => p_person_id
10066               ,p_business_group_id   => p_business_group_id
10067               ,p_effective_date      => p_effective_date
10068               );
10069           --
10070           END IF;
10071         --
10072         END IF;
10073       --
10074       END IF;
10075     --
10076     END IF;                                                    -- late payment
10077     --
10078     if g_debug then
10079       hr_utility.set_location('Leaving ' || l_package,10);
10080     end if;
10081   --
10082   END determine_cobra_payments;
10083 --
10084 --
10085   PROCEDURE determine_cobra_eligibility
10086     (p_calculate_only_mode in     boolean default false
10087     ,p_person_id           IN     NUMBER
10088     ,p_business_group_id   IN     NUMBER
10089     ,p_pgm_id              IN     NUMBER
10090     ,p_ptip_id             IN     NUMBER DEFAULT NULL
10091     ,p_ptnl_ler_trtmt_cd   IN     VARCHAR2
10092     ,p_effective_date      IN     DATE
10093     ,p_lf_evt_ocrd_dt      IN     DATE
10094     ,p_derivable_factors   IN     VARCHAR2
10095     )
10096   IS
10097     --
10098     l_package                  VARCHAR2(80)
10099                                 := g_package || '.determine_cobra_eligibility';
10100     l_lf_evt_ocrd_dt           DATE;
10101     l_end_elig_date            DATE;
10102     l_dsbld                    BOOLEAN                               := FALSE;
10103     l_ok                       BOOLEAN;
10104     l_exists                   VARCHAR2(1);
10105     l_der_rec                  ben_seeddata_object.g_derived_factor_info_rec;
10106     l_dys_no_enrl_not_elig_num ben_lee_rsn_f.dys_no_enrl_not_elig_num%TYPE;
10107     l_rec                      ben_person_object.g_person_date_info_rec;
10108     l_per_in_ler_id            ben_per_in_ler.per_in_ler_id%TYPE;
10109     l_object_version_number    ben_cbr_quald_bnf.object_version_number%TYPE;
10110     l_effective_date           DATE;
10111     l_due_date                 DATE;
10112     l_eff_due_date             DATE;
10113     l_elcns_made_dt            DATE;
10114     l_cbr_elig_perd_end_dt     ben_cbr_quald_bnf.cbr_elig_perd_end_dt%TYPE;
10115     l_init_lf_evt_ocrd_dt      ben_per_in_ler.lf_evt_ocrd_dt%TYPE;
10116     l_ler_id                   ben_per_in_ler.ler_id%TYPE;
10117     --
10118     CURSOR c_get_cbr_elig_dates IS
10119       SELECT   cqb.*
10120               ,crp.per_in_ler_id
10121               ,pil.ler_id
10122       FROM     ben_cbr_quald_bnf cqb
10123               ,ben_cbr_per_in_ler crp
10124               ,ben_per_in_ler pil
10125       WHERE    cqb.quald_bnf_person_id = p_person_id
10126       AND      cqb.quald_bnf_flag = 'Y'
10127       AND      cqb.pgm_id = NVL(p_pgm_id
10128                              ,cqb.pgm_id)
10129       AND      NVL(cqb.ptip_id
10130                 ,NVL(p_ptip_id
10131                   ,-1)) = NVL(p_ptip_id
10132                            ,-1)
10133       AND      cqb.business_group_id = p_business_group_id
10134       AND      cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
10135       AND      crp.init_evt_flag = 'Y'
10136       AND      crp.per_in_ler_id = pil.per_in_ler_id
10137       AND      crp.business_group_id = cqb.business_group_id
10138      -- AND      crp.business_group_id = pil.business_group_id
10139       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT');
10140     --
10141     -- Check if it is not initial event.
10142     --
10143     CURSOR c_get_init_evt(
10144       p_cbr_quald_bnf_id IN NUMBER) IS
10145       SELECT   NULL
10146       FROM     ben_cbr_per_in_ler crp, ben_per_in_ler pil
10147       WHERE    crp.cbr_quald_bnf_id = p_cbr_quald_bnf_id
10148       AND      crp.per_in_ler_id = pil.per_in_ler_id
10149       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10150       AND      crp.business_group_id = pil.business_group_id
10151       AND      crp.business_group_id = p_business_group_id
10152       AND      crp.init_evt_flag = 'N';
10153     CURSOR c_get_per_in_ler(
10154       p_cbr_quald_bnf_id IN NUMBER) IS
10155       SELECT   crp.per_in_ler_id
10156       FROM     ben_cbr_per_in_ler crp, ben_per_in_ler pil
10157       WHERE    crp.cbr_quald_bnf_id = p_cbr_quald_bnf_id
10158       AND      crp.per_in_ler_id = pil.per_in_ler_id
10159       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10160     -- AND      crp.business_group_id = pil.business_group_id
10161       AND      crp.business_group_id = p_business_group_id
10162       AND      crp.init_evt_flag = 'Y';
10163     --
10164     CURSOR c_get_enrt_perd_dates(
10165      p_pgm_id        IN NUMBER) IS
10166       SELECT   pel.*
10167       FROM     ben_pil_elctbl_chc_popl pel
10168               ,ben_per_in_ler pil
10169       WHERE    pel.pgm_id = p_pgm_id
10170       AND      pel.per_in_ler_id = pil.per_in_ler_id
10171       and      pil.person_id = p_person_id
10172       AND      pel.business_group_id = p_business_group_id
10173       AND      pel.business_group_id = pil.business_group_id
10174       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10175       ORDER BY pel.enrt_perd_end_dt desc;
10176     --
10177     CURSOR c_get_elig_days(
10178       p_lee_rsn_id NUMBER) IS
10179       SELECT   len.dys_no_enrl_not_elig_num
10180       FROM     ben_lee_rsn_f len
10181       WHERE    len.lee_rsn_id = p_lee_rsn_id
10182       AND      len.business_group_id = p_business_group_id
10183       AND      NVL(p_lf_evt_ocrd_dt
10184                 ,p_effective_date) BETWEEN len.effective_start_date
10185                    AND len.effective_end_date;
10186     --
10187     CURSOR c_get_dsblity_evt(
10188       p_cbr_quald_bnf_id NUMBER) IS
10189       SELECT   crp.*
10190       FROM     ben_cbr_per_in_ler crp, ben_ler_f ler, ben_per_in_ler pil
10191       WHERE    crp.cbr_quald_bnf_id = p_cbr_quald_bnf_id
10192       AND      crp.per_in_ler_id = pil.per_in_ler_id
10193       AND      pil.ler_id = ler.ler_id
10194       AND      ler.typ_cd = 'DSBLTY'
10195       AND      ler.qualg_evt_flag = 'Y'
10196       AND      NVL(p_lf_evt_ocrd_dt
10197                 ,p_effective_date) BETWEEN ler.effective_start_date
10198                    AND ler.effective_end_date
10199       AND      ler.business_group_id = p_business_group_id
10200       AND      ler.business_group_id = pil.business_group_id
10201       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10202       AND      crp.cnt_num =
10203                (SELECT   MAX(cnt_num)
10204                 FROM     ben_cbr_per_in_ler crp2, ben_per_in_ler pil2
10205                 WHERE    crp2.cbr_quald_bnf_id = p_cbr_quald_bnf_id
10206                 AND      crp2.per_in_ler_id = pil2.per_in_ler_id
10207                 AND      pil2.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10208                 AND      crp2.business_group_id = p_business_group_id
10209                -- AND      crp2.business_group_id = pil2.business_group_id
10210                );
10211     --
10212     CURSOR c_get_all_quald_bnf(
10213       p_cvrd_emp_person_id IN NUMBER
10214      ,p_pgm_id             IN NUMBER
10215      ,p_ptip_id            IN NUMBER) IS
10216       SELECT   cqb.*
10217       FROM     ben_cbr_quald_bnf cqb
10218               ,ben_cbr_per_in_ler crp
10219               ,ben_per_in_ler pil
10220       WHERE    cqb.cvrd_emp_person_id = p_cvrd_emp_person_id
10221       AND      cqb.quald_bnf_flag = 'Y'
10222       AND      l_effective_date BETWEEN cqb.cbr_elig_perd_strt_dt
10223                    AND cqb.cbr_elig_perd_end_dt
10224       AND      cqb.business_group_id = p_business_group_id
10225       AND      cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
10226       AND      cqb.pgm_id = p_pgm_id
10227       AND      NVL(cqb.ptip_id
10228                 ,-1) = NVL(p_ptip_id
10229                         ,-1)
10230       AND      crp.per_in_ler_id = pil.per_in_ler_id
10231       AND      crp.business_group_id = cqb.business_group_id
10232       --AND      pil.business_group_id = crp.business_group_id
10233       AND      crp.init_evt_flag = 'Y'
10234       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT');
10235     --
10236     CURSOR c_get_max_poe(
10237       p_ler_id  IN NUMBER
10238      ,p_pgm_id  IN NUMBER
10239      ,p_ptip_id IN NUMBER) IS
10240       SELECT   peo.*
10241       FROM     ben_elig_to_prte_rsn_f peo
10242       WHERE    peo.ler_id = p_ler_id
10243       AND      peo.business_group_id = p_business_group_id
10244       AND      NVL(p_lf_evt_ocrd_dt
10245                 ,p_effective_date) BETWEEN peo.effective_start_date
10246                    AND peo.effective_end_date
10247       AND      NVL(peo.pgm_id
10248                 ,p_pgm_id) = p_pgm_id
10249       AND      NVL(peo.ptip_id
10250                 ,-1) = NVL(p_ptip_id
10251                         ,-1)
10252       AND      (   peo.mx_poe_val IS NOT NULL
10253                 OR peo.mx_poe_rl IS NOT NULL);
10254     --
10255     CURSOR c_chk_lf_evt IS
10256       SELECT   NULL
10257       FROM     ben_per_in_ler pil
10258       WHERE    pil.person_id = p_person_id
10259       AND      pil.business_group_id = p_business_group_id
10260       AND      pil.lf_evt_ocrd_dt = l_lf_evt_ocrd_dt
10261       AND      pil.ler_id <> l_ler_id
10262       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT');
10263     --
10264     CURSOR c_cbr_quald_bnf IS
10265       SELECT   cqb.cbr_quald_bnf_id
10266               ,cqb.pgm_id
10267               ,cqb.ptip_id
10268               ,crp.per_in_ler_id
10269               ,pil.ler_id
10270       FROM     ben_cbr_quald_bnf cqb
10271               ,ben_cbr_per_in_ler crp
10272               ,ben_per_in_ler pil
10273       WHERE    cqb.quald_bnf_person_id = p_person_id
10274       AND      cqb.quald_bnf_flag = 'Y'
10275       AND      cqb.pgm_id = p_pgm_id
10276       AND      cqb.business_group_id = p_business_group_id
10277       AND      cqb.cbr_quald_bnf_id = crp.cbr_quald_bnf_id
10278       AND      crp.init_evt_flag = 'Y'
10279       AND      crp.per_in_ler_id = pil.per_in_ler_id
10280       AND      crp.business_group_id = cqb.business_group_id
10281       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT');
10282     --
10283     CURSOR c_get_ler_info(p_cbr_elig_strt_dt in date
10284                          ,p_cbr_elig_end_dt  in date
10285                          )
10286     IS
10287       SELECT   ler.*, pil.lf_evt_ocrd_dt
10288       FROM     ben_per_in_ler pil
10289               ,ben_ler_f ler
10290       WHERE    pil.ler_id = ler.ler_id
10291       AND      pil.business_group_id = p_business_group_id
10292       AND      ler.name  = 'Assistance Eligible Individual'
10293       AND      pil.per_in_ler_stat_cd NOT IN ('VOIDD', 'BCKDT')
10294       AND      pil.lf_evt_ocrd_dt
10295                between  p_cbr_elig_strt_dt
10296                and      p_cbr_elig_end_dt
10297       AND      p_effective_date
10298       between  ler.effective_start_date
10299       and      ler.effective_end_date;
10300     --
10301     l_cqb_rec                  c_get_cbr_elig_dates%ROWTYPE;
10302     l_pel_rec                  c_get_enrt_perd_dates%ROWTYPE;
10303     l_crp_rec                  c_get_dsblity_evt%ROWTYPE;
10304     l_poe_rec                  c_get_max_poe%ROWTYPE;
10305     l_cbr_quald_bnf            c_cbr_quald_bnf%ROWTYPE;
10306     l_ler_rec                  c_get_ler_info%ROWTYPE;
10307   BEGIN
10308     --
10309    -- hr_utility.set_location('Entering ' || l_package,10);
10310    -- hr_utility.set_location('p_pgm_id ' || p_pgm_id,10);
10311    -- hr_utility.set_location('p_ptip_id ' || p_ptip_id,10);
10312     --
10313     --
10314     l_effective_date  := NVL(p_lf_evt_ocrd_dt
10315                           ,p_effective_date);
10316     --
10317     -- 1) If person has reached the maximum allowable period of enrollment in
10318     --    a COBRA program, then create a ptnl_per_in_ler
10319     -- 2) If a person does not enroll in the COBRA program or waives coverage,
10320     --    create a potential per_in_ler.
10321     -- 3) If the person is disabled, check if process needs to recalculate
10322     --    the rates. For disablity, the rates for the extended period can
10323     --    be 150% of premium as opposed to 102% of premium for the first 18
10324     --    months. This is at the discretion of the employer.
10325     --
10326     ben_person_object.get_object(p_person_id=> p_person_id
10327      ,p_rec       => l_rec);
10328     --
10329     OPEN c_get_cbr_elig_dates;
10330     FETCH c_get_cbr_elig_dates INTO l_cqb_rec;
10331     IF c_get_cbr_elig_dates%FOUND THEN
10332       CLOSE c_get_cbr_elig_dates;
10333       --
10334       IF p_derivable_factors IN ('ALL', 'PBEV', 'BEV', 'BEVASC') THEN
10335         --
10336        -- hr_utility.set_location('found ' || l_cqb_rec.cbr_elig_perd_end_dt,10);
10337        -- hr_utility.set_location('ALL PBEV BEV BEVASC' ||l_cqb_rec.cbr_elig_perd_end_dt,10);
10338         --
10339         IF l_effective_date >= l_cqb_rec.cbr_elig_perd_end_dt THEN
10340           --
10341          -- hr_utility.set_location('Found ' || l_cqb_rec.cbr_elig_perd_end_dt,10);
10342           --
10343           --  WWBUG# 1166172 - Change the life event occurred date to one
10344           --  day after the date reached.
10345           --
10346           l_lf_evt_ocrd_dt  := l_cqb_rec.cbr_elig_perd_end_dt + 1;
10347           --
10348           IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
10349             --
10350             IF   (  l_lf_evt_ocrd_dt < p_effective_date
10351                AND NVL(p_ptnl_ler_trtmt_cd
10352                     ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
10353               --
10354               -- We are not creating past life events
10355               --
10356               NULL;
10357             --
10358             ELSE
10359               --
10360               ben_seeddata_object.get_object(p_rec=> l_der_rec);
10361               --
10362               --  If cobra ineligible reason is null or if
10363               --  the reason code is Maximum Period of Enrollment reached.
10364               --  The cobra ineligible reason code is updated on the COBRA
10365               --  qualified beneficiary form and would be specified if a
10366               --  user change the cobra eligibility end date for the qualified
10367               --  beneficiary.
10368               --
10369               IF (
10370                       l_cqb_rec.cbr_inelg_rsn_cd IS NULL
10371                    OR l_cqb_rec.cbr_inelg_rsn_cd = 'POE') THEN
10372                 --
10373                -- hr_utility.set_location('POE ' || l_der_rec.drvdpoeelg_id,10);
10374                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10375                     ,p_person_id      => p_person_id
10376                     ,p_ler_id         => l_der_rec.drvdpoeelg_id
10377                     ,p_effective_date => p_effective_date)
10378                 THEN
10379                   --
10380                   create_ptl_ler
10381                     (p_calculate_only_mode => p_calculate_only_mode
10382                     ,p_ler_id              => l_der_rec.drvdpoeelg_id
10383                     ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10384                     ,p_person_id           => p_person_id
10385                     ,p_business_group_id   => p_business_group_id
10386                     ,p_effective_date      => p_effective_date
10387                     );
10388                   --
10389                 END IF;
10390               --
10391               ELSIF l_cqb_rec.cbr_inelg_rsn_cd = 'NLP' THEN
10392                 --
10393                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10394                     ,p_person_id      => p_person_id
10395                     ,p_ler_id         => l_der_rec.drvdnlp_id
10396                     ,p_effective_date => p_effective_date)
10397                 THEN
10398                   --
10399                  -- hr_utility.set_location('NLP ' || l_der_rec.drvdnlp_id,10);
10400                   --
10401                   create_ptl_ler
10402                     (p_calculate_only_mode => p_calculate_only_mode
10403                     ,p_ler_id              => l_der_rec.drvdnlp_id
10404                     ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10405                     ,p_person_id           => p_person_id
10406                     ,p_business_group_id   => p_business_group_id
10407                     ,p_effective_date      => p_effective_date
10408                     );
10409                   --
10410                 END IF;
10411               --
10412               --  Voluntary End of Coverage.
10413               --
10414               ELSIF l_cqb_rec.cbr_inelg_rsn_cd = 'VEC' THEN
10415                -- hr_utility.set_location('VEC ' || l_der_rec.drvdvec_id,10);
10416                 --
10417                 -- Check if a life event exist on the same day.
10418                 --
10419                 l_ler_id  := l_der_rec.drvdvec_id;
10420                 --
10421                 OPEN c_chk_lf_evt;
10422                 FETCH c_chk_lf_evt INTO l_exists;
10423                 IF c_chk_lf_evt%FOUND THEN
10424                   l_lf_evt_ocrd_dt  := l_lf_evt_ocrd_dt + 1;
10425                 END IF;
10426                 --
10427                 CLOSE c_chk_lf_evt;
10428                 --
10429                 IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10430                     ,p_person_id      => p_person_id
10431                     ,p_ler_id         => l_der_rec.drvdvec_id
10432                     ,p_effective_date => p_effective_date)
10433                 THEN
10434                   --
10435                   create_ptl_ler
10436                     (p_calculate_only_mode => p_calculate_only_mode
10437                     ,p_ler_id              => l_der_rec.drvdvec_id
10438                     ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10439                     ,p_person_id           => p_person_id
10440                     ,p_business_group_id   => p_business_group_id
10441                     ,p_effective_date      => p_effective_date
10442                     );
10443                   --
10444                 END IF;
10445               END IF;
10446             --
10447             END IF;
10448           --
10449           END IF;
10450         --
10451         ELSE                            -- If we have not reached the max poe.
10452           --
10453           --  Check if this is the initial event and the person did not enroll
10454           --  in the cobra program.
10455           --
10456           OPEN c_get_init_evt(l_cqb_rec.cbr_quald_bnf_id);
10457           FETCH c_get_init_evt INTO l_exists;
10458           IF c_get_init_evt%NOTFOUND THEN
10459             -- hr_utility.set_location('pgm_id ' || l_cqb_rec.pgm_id,10);
10460             -- hr_utility.set_location('ptip_id ' || l_cqb_rec.ptip_id,10);
10461             --
10462             --  Get the most recent enrollment period.
10463             --
10464             OPEN c_get_enrt_perd_dates(l_cqb_rec.pgm_id);
10465             FETCH c_get_enrt_perd_dates INTO l_pel_rec;
10466             IF c_get_enrt_perd_dates%FOUND THEN
10467               -- hr_utility.set_location('found enrt perd ' ||l_pel_rec.enrt_perd_end_dt,10);
10468               CLOSE c_get_enrt_perd_dates;
10469               --
10470               --  Get the number days from the start of the enrollment
10471               --  period before the person is found ineligible.
10472               --
10473               OPEN c_get_elig_days(l_pel_rec.lee_rsn_id);
10474               FETCH c_get_elig_days INTO l_dys_no_enrl_not_elig_num;
10475               CLOSE c_get_elig_days;
10476               IF l_dys_no_enrl_not_elig_num IS NULL THEN
10477                 --
10478                 --  If not found, use enrollment period end date.
10479                 --
10480                 l_end_elig_date  := l_pel_rec.enrt_perd_end_dt;
10481               ELSE
10482                 l_end_elig_date  :=
10483                    l_pel_rec.enrt_perd_strt_dt + l_dys_no_enrl_not_elig_num;
10484               END IF;
10485               --
10486               -- If running this process ahead of time, the ineligible to
10487               -- event cannot be triggered. Check if the enrollment period
10488               -- has passed using the system date.
10489               --
10490               -- hr_utility.set_location('l_end_elig_date ' || l_end_elig_date,10);
10491               --
10492               -- hr_utility.set_location('effective_date ' ||l_effective_date,10);
10493               IF LEAST(SYSDATE
10494                   ,l_effective_date) > l_end_elig_date THEN
10495                 IF (
10496                   ben_cobra_requirements.chk_enrld_or_cvrd(p_pgm_id=> l_cqb_rec.pgm_id
10497                  ,p_ptip_id           => l_cqb_rec.ptip_id
10498                  ,p_person_id         => p_person_id
10499                  ,p_effective_date    => p_effective_date
10500                  ,p_business_group_id => p_business_group_id
10501                  ,p_cvrd_today        => 'Y'
10502                 )) = FALSE THEN
10503                   --
10504                   --  If enrollment period has passed,
10505                   --  created a loss of eligibility
10506                   --  potential per in ler.
10507                   --
10508                   -- hr_utility.set_location('trigger inelig event ',10);
10509                   --
10510                   --  Set the COBRA qualified beneficiary flag to 'N' as the
10511                   --  person is no longer a COBRA qualified beneficiary.
10512                   --
10513                   l_object_version_number  := l_cqb_rec.object_version_number;
10514                   --
10515                   ben_cbr_quald_bnf_api.update_cbr_quald_bnf
10516                    (p_cbr_quald_bnf_id=> l_cqb_rec.cbr_quald_bnf_id
10517                    ,p_quald_bnf_flag        => 'N'
10518                    ,p_business_group_id     => p_business_group_id
10519                    ,p_object_version_number => l_object_version_number
10520                    ,p_effective_date        => p_effective_date);
10521                   --
10522                   l_lf_evt_ocrd_dt         := l_end_elig_date + 1;
10523                   --
10524                   IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
10525                     --
10526                     IF   (  l_lf_evt_ocrd_dt < p_effective_date
10527                        AND NVL(p_ptnl_ler_trtmt_cd
10528                             ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
10529                       --
10530                       -- We are not creating past life events
10531                       --
10532                       NULL;
10533                     --
10534                     ELSE
10535                       --
10536                       ben_seeddata_object.get_object(p_rec=> l_der_rec);
10537                       --
10538                       IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10539                           ,p_person_id      => p_person_id
10540                           ,p_ler_id         => l_der_rec.drvdlselg_id
10541                           ,p_effective_date => p_effective_date)
10542                       THEN
10543                         --
10544                         create_ptl_ler
10545                           (p_calculate_only_mode => p_calculate_only_mode
10546                           ,p_ler_id              => l_der_rec.drvdlselg_id
10547                           ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10548                           ,p_person_id           => p_person_id
10549                           ,p_business_group_id   => p_business_group_id
10550                           ,p_effective_date      => p_effective_date
10551                           );
10552                         --
10553                       END IF;
10554                     --
10555                     END IF;
10556                   --
10557                   END IF;
10558                 END IF; -- End Enrollment check.
10559               END IF; -- End date check.
10560             ELSE
10561               CLOSE c_get_enrt_perd_dates;
10562             END IF;
10563           END IF;
10564           --
10565           --  Check if we need to trigger an event for a Disability rate change.
10566           --
10567           --  Check if any of the qualified beneficiaries are currently disabled.
10568           --
10569           FOR l_cqb2_rec IN c_get_all_quald_bnf(l_cqb_rec.cvrd_emp_person_id
10570                              ,l_cqb_rec.pgm_id
10571                              ,l_cqb_rec.ptip_id) LOOP
10572             IF ben_cobra_requirements.chk_dsbld(p_person_id=> l_cqb2_rec.quald_bnf_person_id
10573                 ,p_lf_evt_ocrd_dt    => l_effective_date
10574                 ,p_effective_date    => p_effective_date
10575                 ,p_business_group_id => p_business_group_id) = TRUE THEN
10576               --
10577               --  Check if person was disabled at the time of the initial
10578               --  qualifying event.
10579               --
10580               l_init_lf_evt_ocrd_dt  :=
10581                 ben_cobra_requirements.get_lf_evt_ocrd_dt(p_per_in_ler_id=> l_cqb_rec.per_in_ler_id
10582                  ,p_business_group_id => p_business_group_id);
10583               --
10584               IF ben_cobra_requirements.chk_dsbld(p_person_id=> l_cqb2_rec.quald_bnf_person_id
10585                   ,p_lf_evt_ocrd_dt    => l_init_lf_evt_ocrd_dt
10586                   ,p_effective_date    => p_effective_date
10587                   ,p_business_group_id => p_business_group_id) = TRUE THEN
10588                 --
10589                 --   Calculate the original eligibility end date.
10590                 --
10591                 OPEN c_get_max_poe(l_cqb_rec.ler_id
10592                  ,l_cqb_rec.pgm_id
10593                  ,l_cqb_rec.ptip_id);
10594                 FETCH c_get_max_poe INTO l_poe_rec;
10595                 IF c_get_max_poe%FOUND THEN
10596                   --
10597                   l_dsbld                 := TRUE;
10598                   --
10599                   CLOSE c_get_max_poe;
10600                   l_cbr_elig_perd_end_dt  :=
10601                     ben_cobra_requirements.get_cbr_elig_end_dt(p_cbr_elig_perd_strt_dt=> l_cqb_rec.cbr_elig_perd_strt_dt
10602                      ,p_person_id             => p_person_id
10603                      --RCHASE pass pl typ id
10604                      ,p_pl_typ_id             => l_cqb_rec.pl_typ_id
10605                      --RCHASE end
10606                      ,p_mx_poe_uom            => l_poe_rec.mx_poe_uom
10607                      ,p_mx_poe_val            => l_poe_rec.mx_poe_val
10608                      ,p_mx_poe_rl             => l_poe_rec.mx_poe_rl
10609                      ,p_pgm_id                => l_cqb_rec.pgm_id
10610                      ,p_effective_date        => l_effective_date
10611                      ,p_business_group_id     => p_business_group_id
10612                      ,p_ler_id                => l_poe_rec.ler_id);
10613                 ELSE
10614                   CLOSE c_get_max_poe;
10615                 END IF;
10616               --
10617               -- Check if we are currently in the extended period.
10618               --
10619               ELSE
10620                 --
10621                 --  Check if person was disabled within the first 60 days
10622                 --  of the qualifying event.
10623                 --
10624                 OPEN c_get_dsblity_evt(l_cqb_rec.cbr_quald_bnf_id);
10625                 FETCH c_get_dsblity_evt INTO l_crp_rec;
10626                 IF c_get_dsblity_evt%FOUND THEN
10627                   CLOSE c_get_dsblity_evt;
10628                   l_dsbld                 := TRUE;
10629                   l_cbr_elig_perd_end_dt  := l_crp_rec.prvs_elig_perd_end_dt;
10630                 ELSE
10631                   CLOSE c_get_dsblity_evt;
10632                 END IF;
10633               --
10634               END IF;
10635               --
10636               IF l_dsbld THEN
10637                 --
10638                 -- If we are currently in the extended period, trigger
10639                 -- a ptnl life event.
10640                 --
10641                 IF l_effective_date > l_cbr_elig_perd_end_dt THEN
10642                   --
10643                   l_lf_evt_ocrd_dt  := l_cbr_elig_perd_end_dt + 1;
10644                   --
10645                   IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
10646                     --
10647                     IF   (  l_lf_evt_ocrd_dt < p_effective_date
10648                        AND NVL(p_ptnl_ler_trtmt_cd
10649                             ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
10650                       --
10651                       -- We are not creating past life events
10652                       --
10653                       NULL;
10654                     --
10655                     ELSE
10656                       --
10657                       ben_seeddata_object.get_object(p_rec=> l_der_rec);
10658                       --
10659                       IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10660                           ,p_person_id      => p_person_id
10661                           ,p_ler_id         => l_der_rec.drvdpoert_id
10662                           ,p_effective_date => p_effective_date)
10663                       THEN
10664                         --
10665                         create_ptl_ler
10666                           (p_calculate_only_mode => p_calculate_only_mode
10667                           ,p_ler_id              => l_der_rec.drvdpoert_id
10668                           ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10669                           ,p_person_id           => p_person_id
10670                           ,p_business_group_id   => p_business_group_id
10671                           ,p_effective_date      => p_effective_date
10672                           );
10673                         --
10674                       END IF;
10675                     --
10676                     END IF;
10677                   --
10678                   END IF;
10679                 --
10680                 END IF;
10681                 --
10682                 EXIT;
10683               END IF;                                       -- l_dsbld is true
10684             --
10685             END IF;
10686           END LOOP;
10687           --
10688           --  check if the person has an arra event
10689           --
10690           open c_get_ler_info(l_cqb_rec.cbr_elig_perd_strt_dt
10691                              ,l_cqb_rec.cbr_elig_perd_end_dt
10692                              );
10693           fetch c_get_ler_info into l_ler_rec;
10694           if c_get_ler_info%found then
10695             close c_get_ler_info;
10696             --
10697             -- Trigger a life event to change the rates if past
10698             -- the nine month period.
10699             --
10700             l_lf_evt_ocrd_dt := add_months(l_ler_rec.lf_evt_ocrd_dt, 9);
10701             --
10702             if l_effective_date >= l_lf_evt_ocrd_dt then
10703                   --
10704               IF l_lf_evt_ocrd_dt >= l_rec.min_ass_effective_start_date THEN
10705                 --
10706                 IF   (  l_lf_evt_ocrd_dt < p_effective_date
10707                        AND NVL(p_ptnl_ler_trtmt_cd
10708                             ,'-1') = 'IGNR' OR NVL(p_ptnl_ler_trtmt_cd,'-1') = 'IGNRALL') THEN
10709                   --
10710                   -- We are not creating past life events
10711                   --
10712                   NULL;
10713                   --
10714                 ELSE
10715                       --
10716                   ben_seeddata_object.get_object(p_rec=> l_der_rec);
10717                   --
10718                   IF no_life_event(p_lf_evt_ocrd_dt=> l_lf_evt_ocrd_dt
10719                           ,p_person_id      => p_person_id
10720                           ,p_ler_id         => l_der_rec.drvdpoert_id
10721                           ,p_effective_date => p_effective_date)
10722                      THEN
10723                         --
10724                         create_ptl_ler
10725                           (p_calculate_only_mode => p_calculate_only_mode
10726                           ,p_ler_id              => l_der_rec.drvdpoert_id
10727                           ,p_lf_evt_ocrd_dt      => l_lf_evt_ocrd_dt
10728                           ,p_person_id           => p_person_id
10729                           ,p_business_group_id   => p_business_group_id
10730                           ,p_effective_date      => p_effective_date
10731                           );
10732                         --
10733                   END IF;
10734                 END IF;
10735               END IF;
10736             END IF;  -- l_effective_date >= ocrd_dt
10737             ---
10738             else
10739               close c_get_ler_info;
10740           END IF; -- end arra event
10741         END IF;                                    --  end cbr_elig_date found
10742       END IF;                          -- p_derivable_factors in 'ALL' etc.. .
10743       --
10744     --
10745     ELSE                             -- cobra qualified beneficiary not found.
10746      -- hr_utility.set_location('not found ',10);
10747       CLOSE c_get_cbr_elig_dates;
10748     END IF;
10749 
10750     -- Bug 3097501
10751     -- Call determine_cobra_payments only once for the COBRA program
10752     -- All Plans in the Program will be checked for NOLP in this call
10753     -- This is required for handling Insignificant Underpayments
10754     IF p_pgm_id IS NOT NULL THEN
10755 
10756       IF p_derivable_factors IN ('ALL', 'P', 'PASC', 'PBEV') THEN
10757         OPEN c_cbr_quald_bnf;
10758         FETCH c_cbr_quald_bnf INTO l_cbr_quald_bnf;
10759         IF c_cbr_quald_bnf%FOUND THEN
10760           --
10761           --  Check if the person is late with his/her payment.
10762           --
10763           determine_cobra_payments
10764             (p_calculate_only_mode => p_calculate_only_mode
10765             ,p_person_id           => p_person_id
10766             ,p_business_group_id   => p_business_group_id
10767             ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
10768             ,p_effective_date      => l_effective_date
10769             ,p_pgm_id              => l_cbr_quald_bnf.pgm_id
10770             ,p_ptip_id             => l_cbr_quald_bnf.ptip_id
10771             ,p_cbr_quald_bnf_id    => l_cbr_quald_bnf.cbr_quald_bnf_id
10772             );
10773         END IF;
10774         CLOSE c_cbr_quald_bnf;
10775       END IF;
10776     END IF;
10777 
10778     --
10779    -- hr_utility.set_location('Leaving ' || l_package,10);
10780   --
10781   END determine_cobra_eligibility;
10782 --
10783   PROCEDURE derive_rates_and_factors
10784     (p_calculate_only_mode in     boolean default false
10785     ,p_comp_obj_tree_row   IN OUT NOCOPY ben_manage_life_events.g_cache_proc_objects_rec
10786     --
10787     -- Context info
10788     --
10789     ,p_per_row           IN OUT NOCOPY per_all_people_f%ROWTYPE
10790     ,p_empasg_row        IN OUT NOCOPY per_all_assignments_f%ROWTYPE
10791     ,p_benasg_row        IN OUT NOCOPY per_all_assignments_f%ROWTYPE
10792     ,p_pil_row           IN OUT NOCOPY ben_per_in_ler%ROWTYPE
10793     --
10794     ,p_mode              IN            VARCHAR2 DEFAULT NULL
10795     --
10796     ,p_effective_date    IN            DATE
10797     ,p_lf_evt_ocrd_dt    IN            DATE
10798     ,p_person_id         IN            NUMBER
10799     ,p_business_group_id IN            NUMBER
10800     ,p_pgm_id            IN            NUMBER DEFAULT NULL
10801     ,p_pl_id             IN            NUMBER DEFAULT NULL
10802     ,p_oipl_id           IN            NUMBER DEFAULT NULL
10803     ,p_plip_id           IN            NUMBER DEFAULT NULL
10804     ,p_ptip_id           IN            NUMBER DEFAULT NULL
10805     ,p_ptnl_ler_trtmt_cd IN            VARCHAR2 DEFAULT NULL
10806     ,p_derivable_factors IN            VARCHAR2 DEFAULT 'ASC'
10807     ,p_comp_rec          IN OUT NOCOPY g_cache_structure
10808     ,p_oiplip_rec        IN OUT NOCOPY g_cache_structure
10809     )
10810 IS
10811    --
10812    cursor c_get_pgm_typ(cv_pgm_id in number,
10813                         cv_effective_date in date ) is
10814      select pgm_typ_cd
10815      from ben_pgm_f
10816      where pgm_id = cv_pgm_id
10817        and cv_effective_date between effective_start_date
10818                                  and effective_end_date;
10819    --
10820    cursor c_get_gsp_ler(cv_effective_date in date ) is
10821      select ler_id, name
10822      from ben_ler_f
10823      where typ_cd = 'GSP'
10824        and business_group_id = p_business_group_id
10825        and cv_effective_date between effective_start_date
10826                                  and effective_end_date;
10827     --
10828     l_package        VARCHAR2(80)   := g_package || '.derive_rate_and_factors';
10829     --
10830     l_pgm_rec        ben_pgm_f%ROWTYPE;
10831     l_ptip_rec       ben_ptip_f%ROWTYPE;
10832     l_comp_rec       g_cache_structure;
10833     l_oiplip_rec     g_cache_structure;
10834     l_curroipl_row   ben_cobj_cache.g_oipl_inst_row;
10835     l_curroiplip_row ben_cobj_cache.g_oiplip_inst_row;
10836     l_oipl_id        NUMBER;
10837     l_oiplip_id      NUMBER;
10838     l_loop_count     NUMBER                           := 1;
10839     --FONM
10840     -- g_fonm_cvg_strt_dt      DATE ;
10841     --END FONM
10842   --
10843   BEGIN
10844     --
10845     g_debug := hr_utility.debug_enabled;
10846     if g_debug then
10847       hr_utility.set_location('Entering ' || l_package,10);
10848     end if;
10849     --FONM This will be implemented as a parameter.
10850     --only for testing purpose we are using the global
10851     --variable and needs to be removed.
10852     --
10853     g_fonm_cvg_strt_dt := null ;
10854     if ben_manage_life_events.fonm = 'Y'
10855        and ben_manage_life_events.g_fonm_cvg_strt_dt  is not null then
10856       --
10857       g_fonm_cvg_strt_dt := ben_manage_life_events.g_fonm_cvg_strt_dt ;
10858       --
10859     end if;
10860     --
10861     --END FONM
10862     --
10863     hr_utility.set_location(' drpar main p_pl_id '||p_pl_id, 44);
10864     --hr_utility.set_location(' drpar main p_oipl_id '||p_oipl_id,44);
10865     hr_utility.set_location(' drpar main p_plip_id '||p_plip_id,44);
10866     --hr_utility.set_location(' drpar main p_ptip_id '||p_ptip_id,44);
10867     --hr_utility.set_location(' drpar main p_pgm_id '||p_pgm_id,44);
10868     --hr_utility.set_location(' p_derivable_factors '||p_derivable_factors,44);
10869 
10870     --  Check if person is still eligible to participate in
10871     --  the COBRA program.  He/she may have reached the maximum
10872     --  period of enrollment or decided not to enroll anymore in
10873     --  the COBRA program. COBRA eligibility is only checked if
10874     --  the BENMNGLE effective date is prior to or equal to today's date
10875     --  as the events are time sensitive.
10876     --
10877     IF     (   p_pgm_id IS NOT NULL
10878             OR p_ptip_id IS NOT NULL)
10879        AND (p_derivable_factors <> 'ASC') THEN
10880       --hr_utility.set_location(' COBRA logic  ' || l_package,10);
10881       --
10882       IF p_pgm_id IS NULL THEN
10883         --
10884         ben_comp_object.get_object(p_ptip_id=> p_ptip_id
10885          ,p_rec     => l_ptip_rec);
10886         --
10887         ben_comp_object.get_object(p_pgm_id=> l_ptip_rec.pgm_id
10888          ,p_rec    => l_pgm_rec);
10889       --
10890       ELSE
10891         ben_comp_object.get_object(p_pgm_id=> p_pgm_id
10892          ,p_rec    => l_pgm_rec);
10893       END IF;
10894       --
10895       IF l_pgm_rec.pgm_typ_cd LIKE 'COBRA%' THEN
10896         --
10897         determine_cobra_eligibility
10898           (p_calculate_only_mode => p_calculate_only_mode
10899           ,p_person_id           => p_person_id
10900           ,p_business_group_id   => p_business_group_id
10901           ,p_pgm_id              => p_pgm_id
10902           ,p_ptip_id             => p_ptip_id
10903           ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
10904           ,p_effective_date      => p_effective_date
10905           ,p_lf_evt_ocrd_dt      => NVL(g_fonm_cvg_strt_dt,p_lf_evt_ocrd_dt)
10906           ,p_derivable_factors   => p_derivable_factors
10907           );
10908         --
10909       END IF;
10910       --
10911       --hr_utility.set_location(' Dn COBRA logic  ' || l_package,10);
10912     END IF;
10913     --
10914     -- Check if we can drop out early. Do not need to calculate oipl
10915     -- and oiplip values for temporal mode
10916     --
10917     IF     (
10918                 (
10919                       p_comp_obj_tree_row.flag_bit_val = 0
10920                   AND p_comp_obj_tree_row.oiplip_flag_bit_val = 0)
10921              OR (p_derivable_factors IN ('P', 'PBEV', 'BEV')))
10922        AND NVL(p_mode,'Z') = 'T' THEN
10923       --
10924       hr_utility.set_location(' Dn RETURN temporal mode ' ,45);
10925       RETURN;
10926     --
10927     -- Need to calculate oipl and oiplip values for any other mode
10928     -- before we drop out
10929     --
10930     ELSIF     (
10931                    (
10932                          p_comp_obj_tree_row.flag_bit_val = 0
10933                      AND p_comp_obj_tree_row.oiplip_flag_bit_val = 0)
10934                 OR (p_derivable_factors IN ('P', 'PBEV', 'BEV')))
10935           AND NVL(p_mode
10936                ,'Z') <> 'T' THEN
10937       hr_utility.set_location(' CDS Not Temp  ' || l_package,10);
10938       --
10939       -- exit process as no derivable factors exist!
10940       -- or no need to check these factors.
10941       --
10942       -- Cache all the data values we use in our derivable factor functions
10943       --
10944       cache_data_structures(p_comp_obj_tree_row=> p_comp_obj_tree_row
10945        ,p_empasg_row        => p_empasg_row
10946        ,p_benasg_row        => p_benasg_row
10947        ,p_pil_row           => p_pil_row
10948        ,p_business_group_id => p_business_group_id
10949        ,p_person_id         => p_person_id
10950        ,p_pgm_id            => p_pgm_id
10951        ,p_pl_id             => p_pl_id
10952        ,p_oipl_id           => p_oipl_id
10953        ,p_plip_id           => p_plip_id
10954        ,p_ptip_id           => p_ptip_id
10955        ,p_comp_rec          => p_comp_rec
10956        ,p_oiplip_rec        => p_oiplip_rec
10957        ,p_effective_date    => NVL(g_fonm_cvg_strt_dt, p_effective_date)
10958        );
10959       hr_utility.set_location(' Dn CDS Not Temp  ' || l_package,10);
10960       --
10961       RETURN;
10962     --
10963     ELSE
10964       --
10965       hr_utility.set_location(' CDS Other  ' || l_package,10);
10966       cache_data_structures(p_comp_obj_tree_row=> p_comp_obj_tree_row
10967        ,p_empasg_row        => p_empasg_row
10968        ,p_benasg_row        => p_benasg_row
10969        ,p_pil_row           => p_pil_row
10970        ,p_business_group_id => p_business_group_id
10971        ,p_person_id         => p_person_id
10972        ,p_pgm_id            => p_pgm_id
10973        ,p_pl_id             => p_pl_id
10974        ,p_oipl_id           => p_oipl_id
10975        ,p_plip_id           => p_plip_id
10976        ,p_ptip_id           => p_ptip_id
10977        ,p_comp_rec          => l_comp_rec
10978        ,p_oiplip_rec        => l_oiplip_rec
10979        ,p_effective_date    => NVL(g_fonm_cvg_strt_dt,p_effective_date)
10980       );
10981     --
10982     END IF;
10983     hr_utility.set_location('Factors defined ' || l_package,10);
10984     --
10985     -- Get context row information from comp object caches
10986     --
10987     --hr_utility.set_location(' p_comp_obj_tree_row.oipl_id '||p_comp_obj_tree_row.oipl_id ,55);
10988     IF p_comp_obj_tree_row.oipl_id IS NOT NULL THEN
10989       --
10990       ben_cobj_cache.get_oipl_dets(p_business_group_id=> p_business_group_id
10991        ,p_effective_date    => g_fonm_cvg_strt_dt -- FONM p_effective_date
10992        ,p_oipl_id           => p_comp_obj_tree_row.oipl_id
10993        ,p_inst_row          => l_curroipl_row);
10994       --
10995       -- Check oiplip stuff
10996       --
10997       --hr_utility.set_location(' p_comp_obj_tree_row.oiplip_id '||p_comp_obj_tree_row.oiplip_id ,55);
10998       --
10999       IF p_comp_obj_tree_row.oiplip_id IS NOT NULL THEN
11000         --
11001         ben_cobj_cache.get_oiplip_dets(p_business_group_id=> p_business_group_id
11002          ,p_effective_date    => NVL(g_fonm_cvg_strt_dt, p_effective_date)
11003          ,p_oiplip_id         => p_comp_obj_tree_row.oiplip_id
11004          ,p_inst_row          => l_curroiplip_row);
11005       --
11006       END IF;
11007       --
11008       --hr_utility.set_location('Dn OIPL details ' || l_package,10);
11009     END IF;
11010     --
11011     -- If we are dealing with an oipl that has an oiplip then the count should
11012     -- be two since we will be looping once for oipl and once for oiplip.
11013     --
11014     IF p_comp_obj_tree_row.oiplip_id IS NOT NULL THEN
11015       --
11016       l_loop_count  := 2;
11017     --
11018     END IF;
11019     --
11020     --hr_utility.set_location(' l_loop_count '||l_loop_count ,55);
11021     --
11022     FOR l_count IN 1 .. l_loop_count LOOP
11023       --
11024       IF l_count = 1 THEN
11025         --
11026         l_oipl_id    := p_oipl_id;
11027         l_oiplip_id  := NULL;
11028       --
11029       ELSIF l_count = 2 THEN
11030         --
11031         l_oipl_id    := NULL;
11032         l_oiplip_id  := p_comp_obj_tree_row.oiplip_id;
11033         l_comp_rec   := l_oiplip_rec;
11034       --
11035       END IF;
11036       --
11037       -- GADE/STEP : Code to support grade/step le
11038       --
11039       if nvl(g_prev_pgm_id, -1) <> nvl(p_pgm_id
11040                                   ,p_comp_obj_tree_row.par_pgm_id) then
11041          --
11042          hr_utility.set_location('GSP pgm id = ' || p_pgm_id, 9876);
11043          hr_utility.set_location('GSP pgm id = ' ||p_comp_obj_tree_row.par_pgm_id, 9876);
11044          g_prev_pgm_id      := nvl(p_pgm_id
11045                                   ,p_comp_obj_tree_row.par_pgm_id);
11046          --
11047          g_pgm_typ_cd := null;
11048          open c_get_pgm_typ(g_prev_pgm_id, p_effective_date);
11049          fetch c_get_pgm_typ into g_pgm_typ_cd;
11050          close c_get_pgm_typ;
11051          --
11052       end if;
11053          if g_pgm_typ_cd = 'GSP' and g_gsp_ler_id is null then
11054             --
11055             open c_get_gsp_ler(p_effective_date);
11056             fetch c_get_gsp_ler into g_gsp_ler_id, g_gsp_ler_name;
11057             close c_get_gsp_ler;
11058             --
11059          end if;
11060          --
11061          hr_utility.set_location('GSP ler_name  = ' || g_gsp_ler_name, 9876);
11062       --
11063       -- END : GADE/STEP : Code to support grade/step le
11064       --
11065       -- Get LOS value
11066       --
11067       calculate_los
11068         (p_calculate_only_mode => p_calculate_only_mode
11069         ,p_comp_obj_tree_row   => p_comp_obj_tree_row
11070         ,p_empasg_row          => p_empasg_row
11071         ,p_benasg_row          => p_benasg_row
11072         ,p_pil_row             => p_pil_row
11073         ,p_curroipl_row        => l_curroipl_row
11074         ,p_curroiplip_row      => l_curroiplip_row
11075         ,p_person_id           => p_person_id
11076         ,p_business_group_id   => p_business_group_id
11077         ,p_pgm_id              => p_pgm_id
11078         ,p_pl_id               => p_pl_id
11079         ,p_oipl_id             => l_oipl_id
11080         ,p_plip_id             => p_plip_id
11081         ,p_ptip_id             => p_ptip_id
11082         ,p_oiplip_id           => l_oiplip_id
11083         ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
11084         ,p_comp_rec            => l_comp_rec
11085         ,p_effective_date      => p_effective_date
11086         ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
11087         );
11088       --
11089       -- Get Age value
11090       --
11091      hr_utility.set_location('pl_id '||p_pl_id , 55);
11092      hr_utility.set_location('Before call to calculate_age p_plip_id '||p_plip_id,55);
11093       calculate_age
11094         (p_calculate_only_mode => p_calculate_only_mode
11095         ,p_comp_obj_tree_row   => p_comp_obj_tree_row
11096         ,p_per_row             => p_per_row
11097         ,p_empasg_row          => p_empasg_row
11098         ,p_benasg_row          => p_benasg_row
11099         ,p_pil_row             => p_pil_row
11100         ,p_curroipl_row        => l_curroipl_row
11101         ,p_curroiplip_row      => l_curroiplip_row
11102         ,p_person_id           => p_person_id
11103         ,p_business_group_id   => p_business_group_id
11104         ,p_pgm_id              => p_pgm_id
11105         ,p_pl_id               => p_pl_id
11106         ,p_oipl_id             => l_oipl_id
11107         ,p_plip_id             => p_plip_id
11108         ,p_ptip_id             => p_ptip_id
11109         ,p_oiplip_id           => l_oiplip_id
11110         ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
11111         ,p_comp_rec            => l_comp_rec
11112         ,p_effective_date      => p_effective_date
11113         ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
11114         );
11115       --hr_utility.set_location('After call to calculate_age ' ,55);
11116       --
11117       -- Get hours worked
11118       --
11119       calculate_hours_worked
11120         (p_calculate_only_mode => p_calculate_only_mode
11121         ,p_comp_obj_tree_row=> p_comp_obj_tree_row
11122         ,p_empasg_row        => p_empasg_row
11123         ,p_benasg_row        => p_benasg_row
11124         ,p_pil_row           => p_pil_row
11125         ,p_curroipl_row      => l_curroipl_row
11126         ,p_curroiplip_row    => l_curroiplip_row
11127         ,p_person_id         => p_person_id
11128         ,p_business_group_id => p_business_group_id
11129         ,p_pgm_id            => p_pgm_id
11130         ,p_pl_id             => p_pl_id
11131         ,p_oipl_id           => l_oipl_id
11132         ,p_plip_id           => p_plip_id
11133         ,p_ptip_id           => p_ptip_id
11134         ,p_oiplip_id         => l_oiplip_id
11135         ,p_ptnl_ler_trtmt_cd => p_ptnl_ler_trtmt_cd
11136         ,p_comp_rec          => l_comp_rec
11137         ,p_effective_date    => p_effective_date
11138         ,p_lf_evt_ocrd_dt    => p_lf_evt_ocrd_dt
11139         );
11140       --
11141       -- Get percent fulltime
11142       --
11143       calculate_percent_fulltime
11144         (p_calculate_only_mode => p_calculate_only_mode
11145         ,p_comp_obj_tree_row   => p_comp_obj_tree_row
11146         ,p_empasg_row          => p_empasg_row
11147         ,p_benasg_row          => p_benasg_row
11148         ,p_pil_row             => p_pil_row
11149         ,p_curroipl_row        => l_curroipl_row
11150         ,p_curroiplip_row      => l_curroiplip_row
11151         ,p_person_id           => p_person_id
11152         ,p_business_group_id   => p_business_group_id
11153         ,p_pgm_id              => p_pgm_id
11154         ,p_pl_id               => p_pl_id
11155         ,p_oipl_id             => l_oipl_id
11156         ,p_plip_id             => p_plip_id
11157         ,p_ptip_id             => p_ptip_id
11158         ,p_oiplip_id           => l_oiplip_id
11159         ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
11160         ,p_comp_rec            => l_comp_rec
11161         ,p_effective_date      => p_effective_date
11162         ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
11163         );
11164       --
11165       -- Get combination age and los values
11166       --
11167       calculate_comb_age_and_los
11168         (p_calculate_only_mode => p_calculate_only_mode
11169         ,p_comp_obj_tree_row   => p_comp_obj_tree_row
11170         ,p_per_row             => p_per_row
11171         ,p_empasg_row          => p_empasg_row
11172         ,p_benasg_row          => p_benasg_row
11173         ,p_pil_row             => p_pil_row
11174         ,p_curroipl_row        => l_curroipl_row
11175         ,p_curroiplip_row      => l_curroiplip_row
11176         ,p_person_id           => p_person_id
11177         ,p_business_group_id   => p_business_group_id
11178         ,p_pgm_id              => p_pgm_id
11179         ,p_pl_id               => p_pl_id
11180         ,p_oipl_id             => l_oipl_id
11181         ,p_plip_id             => p_plip_id
11182         ,p_ptip_id             => p_ptip_id
11183         ,p_oiplip_id           => l_oiplip_id
11184         ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
11185         ,p_comp_rec            => l_comp_rec
11186         ,p_effective_date      => p_effective_date
11187         ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
11188         );
11189       --
11190       -- Get compensation value
11191       --
11192       calculate_compensation_level
11193         (p_calculate_only_mode => p_calculate_only_mode
11194         ,p_comp_obj_tree_row   => p_comp_obj_tree_row
11195         ,p_empasg_row          => p_empasg_row
11196         ,p_benasg_row          => p_benasg_row
11197         ,p_pil_row             => p_pil_row
11198         ,p_curroipl_row        => l_curroipl_row
11199         ,p_curroiplip_row      => l_curroiplip_row
11200         ,p_person_id           => p_person_id
11201         ,p_business_group_id   => p_business_group_id
11202         ,p_pgm_id              => p_pgm_id
11203         ,p_pl_id               => p_pl_id
11204         ,p_oipl_id             => l_oipl_id
11205         ,p_plip_id             => p_plip_id
11206         ,p_ptip_id             => p_ptip_id
11207         ,p_oiplip_id           => l_oiplip_id
11208         ,p_ptnl_ler_trtmt_cd   => p_ptnl_ler_trtmt_cd
11209         ,p_comp_rec            => l_comp_rec
11210         ,p_effective_date      => p_effective_date
11211         ,p_lf_evt_ocrd_dt      => p_lf_evt_ocrd_dt
11212         );
11213       --
11214       -- Set output values for once_r_cntg_cd and elig_flag
11215       --
11216       IF l_count = 1 THEN
11217         --
11218         p_comp_rec  := l_comp_rec;
11219          --hr_utility.set_location('Out p_comp_Rec'||p_comp_rec.cmbn_age_n_los_val,10);
11220       --
11221       ELSIF l_count = 2 THEN
11222         --
11223         p_oiplip_rec  := l_comp_rec;
11224       --
11225       END IF;
11226     --
11227     END LOOP;
11228     --
11229     --hr_utility.set_location('Leaving ' || l_package,10);
11230   --
11231   END derive_rates_and_factors;
11232 --
11233  --- this procedure set the context_id to tax_unit_id
11234  --- this avoid the error from the pay_balance_pkg.get_value
11235 
11236   procedure set_taxunit_context
11237   (p_person_id           in     number
11238   ,p_business_group_id   in     number
11239   ,p_effective_date      in     date
11240   )
11241   is
11242     l_package        VARCHAR2(80)   := g_package || '.set_taxunit_context';
11243     --
11244     l_tax_unit_id    hr_soft_coding_keyflex.segment1%type ;
11245     --
11246     cursor c_tax is
11247     select cfk.segment1
11248     from per_all_assignments_f asg, hr_soft_coding_keyflex cfk
11249     where asg.person_id  = p_person_id
11250      and   asg.assignment_type <> 'C'
11251      and  asg.primary_flag = 'Y'
11252       AND p_effective_date BETWEEN asg.effective_start_date
11253                    AND asg.effective_end_date
11254      and asg.soft_coding_keyflex_id = cfk.soft_coding_keyflex_id
11255      order by asg.effective_start_date ;
11256 
11257 
11258 
11259   BEGIN
11260     --
11261     if g_debug then
11262       hr_utility.set_location('Entering ' || l_package,10);
11263     end if;
11264     open c_tax ;
11265     fetch c_tax into  l_tax_unit_id ;
11266     close c_tax ;
11267 
11268     if g_debug then
11269       hr_utility.set_location('tax_unit_id' || l_tax_unit_id , 10);
11270     end if;
11271     if l_tax_unit_id is not null then
11272        pay_balance_pkg.set_context ('TAX_UNIT_ID',  l_tax_unit_id );
11273     end if ;
11274 
11275     if g_debug then
11276       hr_utility.set_location('Leaving ' || l_package,10);
11277     end if;
11278   end set_taxunit_context ;
11279 --
11280 END ben_derive_part_and_rate_facts;