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