DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_US_INV_DED_FORMULAS

Source


1 PACKAGE BODY PAY_US_INV_DED_FORMULAS AS
2 /* $Header: pyusgrfm.pkb 120.63.12020000.13 2013/03/11 10:25:55 rgottipa ship $ */
3 /*
4    ******************************************************************
5    *                                                                *
6    *  Copyright (C) 1993 Oracle Corporation.                        *
7    *  All rights reserved.                                          *
8    *                                                                *
9    *  This material has been provided pursuant to an agreement      *
10    *  containing restrictions on its use.  The material is also     *
11    *  protected by copyright law.  No part of this material may     *
12    *  be copied or distributed, transmitted or transcribed, in      *
13    *  any form or by any means, electronic, mechanical, magnetic,   *
14    *  manual, or otherwise, or disclosed to third parties without   *
15    *  the express written permission of Oracle Corporation,         *
16    *  500 Oracle Parkway, Redwood City, CA, 94065.                  *
17    *                                                                *
18    ******************************************************************
19 
20     Name        : pay_us_inv_ded_formulas
21 
22     Description : This package is used by fast formulas of involuntary
23                   deduction elements to calculate deduction amounts.
24                   Different functions cater to different categories of
25                   involuntary deduction.
26 
27     Change List
28     -----------
29     Date        Name       Vers    Bug No   Description
30     ----------- ---------- ------  -------  -------------------------------
31     23-APR-2004 sdahiya    115.0            Created.
32     12-MAY-2004 sdahiya    115.1            Modified phase to plb.
33     17-MAY-2004 sdahiya    115.2   3622290  Added fnd_date.canonical_to_date
34                                             while converting varchar to date.
35     18-MAY-2004 sdahiya    115.3   2658290, - Moved dedn amount calculation
36                                    1481913,   from cal_formula_bo to
37                                               base_formula.
38                                    2992741  - Enabled proration rules fori
39                                               cal_formula_bo.
40                                             - Modified proration algorithm
41                                               so that current
42                                               support orders are prorated
43                                               before the arrears.
44                                             - Modified usage of global
45                                               variables as PL/SQL tables
46                                               instead of scalar variables.
47     01-JUN-2004 sdahiya    115.4   3549207  - Removed VOLDEDNS_AT_WRIT
48                                               and VOL_DEDNS_ASG_GRE_LTD
49                                               parameters from BASE_FORMULA.
50     17-JUN-2004 kvsankar   115.5   3692468  Removed the check for
51                                             days_in_arrears
52                                             from CAL_FORMULA_SS
53     22-JUN-2004 kvsankar   115.6   3704744  Modified CAL_FORMULA_SS to
54                                             use the overriden Proration
55                                             rule instead of the seeded
56                                             rule(if overriden).
57     28-JUN-2004 kvsankar   115.7   3715182  Included a new cursor
58                                              c_garn_max_fee_amt in
59                                    3719168  CAL_FORMULA_SS and
60                                             CAL_FORMULA_BO to set the
61                                    3722152  value of GARN_FEE_MAX_FEE_AMOUNT
62                                             to 99999999 if the it is defaulted
63                                             to ZERO in the formula.
64                                             File Arch in for KVSANKAR by
65                                             djoshi
66     29-JUN-2004 kvsankar   115.8   3718454  Added 1 to the calculation of
67                                             garn_days as the both
68                                             PAY_EARNED_END_DATE and VF_DATE_SERVED
69                                             should be included for calculating
70                                             the STOP_ENTRY value
71     30-JUN-2004 kvsankar   115.9   3718454  Added a new IF condition to check
72                                    3734415  whether deduction amount needs to
73                                             taken if the Ending payroll was skipped
74                                             in cases where Max Withholding days
75                                             comes into picture.
76     30-JUN-2004 kvsankar   115.10           Added code for deleting the Global
77                                             tables once an Employee is processed.
78     02-JUL-2004 kvsankar   115.11  1481913  Removed the STOP_ENTRY = 'Y' from the
79                                             solution earlier provided for 1481913.
80     06-JUL-2004 kvsankar   115.12  3734557  Added the condition so that Proration
81                                             rules are applied only if DI is less.
82     08-JUL-2004 kvsankar   115.13  3749162  Rewrote the IF condition checking
83                                             for Monthly_Cap_Amount <> 0 and
84                                             Period_Cap_Amount <> 0 in
85                                             CAL_FORMULA_TL
86                                             Created a new procedure 'RESET_GLOBAL_VAR'
87                                             for the deletion of Global tables and
88                                             for resetting Global variables to NULL.
89                                    2992741  Modified the calculation of DI for
90                                             arrears in case of Child Support
91                                             elements. Also added an IF condition
92                                             to set FEE to ZERO in case of Proration.
93     08-JUL-2004 kvsankar   115.14  2992741  Added an IF condition to take arrears
94                                             only if VF_DI_SUBJ_ARR > 0.
95     08-JUL-2004 kvsankar   115.15  3737081  Modified the IF condition in function
96                                             CAL_FORMULA_BO to correctly calculate
97                                             the value of DI_state_exemption_amt
98     20-JUL-2004 kvsankar   115.16  3777900  Removed '=' sign from the fix
99                                             for 3718454
100     08-NOV-2004 kvsankar   115.17  3549298  Made changes for Initial Fee Flag
101                                             No Initial fee is taken if the
102                                             Initial Fee Flag is set.
103     09-DEC-2004 kvsankar   115.18  3650283  Added paramters to BASE_FORMULA
104                                             and CAL_FORMULA_BO for DCIA category.
105     20-DEC-2004 kvsankar   115.19  4072103  Modified the calculation of the amount
106                                             to be deducted for each element in the
107                                             BASE_FORMULA
108                                    4079142  Removed calculation of State Exempt
109                                             amount for DCIA as it is a Federal
110                                             Level deduction.
111                                             Modified the code to not to calculate
112                                             fees for DCIA.
113                                             Added Cdde to limit DCIA to 25% of
114                                             of disposable income if we have DCIA
115                                             along with Support or Other Elements
116     31-JAN-2005 kvsankar   115.21  4143803  Added code to correctly default
117                                             Allowances and Filing Status if
118                                             defaulted in the BALANCE_SETUP
119                                             formula for Tax Levy Category
120     03-FEB-2005 kvsankar   115.22           Introduced a new function
121                                             GET_CCPA_PROTECTION for the
122                                             calculation of CCPA Protection value.
123     03-FEB-2005 kvsankar   115.23  4145789  Modified the code to override the
124                                             CCPA Protection value if the
125                                             Exemption percenatge overridden makes
126                                             the DI value to be more than CCPA
127                                             value.
128     04-FEB-2005 kvsankar   115.24  4145789  Modified the comment.
129     18-FEB-2005 kvsankar   115.25  4154950  Modified the BASE_FORMULA definition
130                                             to use _ASG dimension instead of _ASG_GRE
131                                             becuase of the the Bug fix made to the
132                                             'BALANCE_SETUP_FORMULA' for all categories.
133                                             The following are the parameters modified: -
134                                               i. ACCRUED_ASG_GRE_LTD
135                                              ii. ACCRUED_FEES_ASG_GRE_LTD
136                                             iii. ASG_GRE_MONTH
137                                              iv. ASG_GRE_PTD
138                                             The formula text is also modified to use
139                                             the corresponding new paramter name.
140     24-FEB-2005 kvsankar   115.26  4107302  Commented the code that sets STOP_ENTRY
141                                             based on the Termination Status of
142                                             Employee. The reason being Involuntary
143                                             Deduction elements are subjected to
144                                             Severance payments too.
145     03-MAR-2005 kvsankar   115.27  4104842  Modified the BASE_FORMULA to calculate
146                                             Gross Earnings that is later used to
147                                             calculate Tax Levy.
148                                    4234046  Added code to set the Fee Amount to
149                                             ZERO when no deduction is taken.
150     16-MAR-2005 kvsankar   115.28   NILL    Modified the code where there is an
151                                             NVL condition using 0 to use
152                                             'default_number' for the same.
153     04-APR-2005 kvsankar   115.29  3800845  Modified the cursor 'csr_get_ovrd_values'
154                                             and 'csr_exmpt_ovrd' to use 'Date
155                                             Earned' instead of 'Start Date'.
156     13-JUN-2005 kvsankar   115.30  4318944  Modified the Federal and State Exemption
157                                             calculation part for Hawaii State
158     18-AUG-2005 kvsankar   115.31  3528349  Modified the formula CAL_FORMULA_TL
159                                             for getting the Fed Exemption
160                                             amounts based on the overridden
161                                             Year specified.
162     14-NOV-2005 kvsankar   115.32  4556146  Changes made to CAL_FORMULA_BO
163                                             for the amendments made to Illinois
164                                             Garnishment law
165     29-NOV-2005 kvsankar   115.33  4758841  We default value of GLB_ALLOWS to
166                                               i. '1' if Filing Status was
167                                                  defaulted too
168                                              ii. '0' if Filing Status was
169                                                  not defaulted
170     08-DEC-2005 kvsankar   115.34  4710692  Modified the IF condition that
171                                             defaults GLB_ALLOWS
172     12-DEC-2005 kvsankar   115.35  4881680  Modified the way PL/SQL tables
173                                             are accessed for performance
174     16-DEC-2005 kvsankar   115.36  4748532  Modified the package to correctly
175                                             deduct garnishment when the Fast
176                                             Formula is modified by customer to
177                                             look into PTD values
178     20-DEC-2005 kvsankar  115.37   4748532  Modifed the package for the above
179                                             multiple payment garnishment
180     06-JAN-2006 kvsankar  115.38   4858720  Modified the caluclation for all
181                                             Involuntary Deduction elements to
182                                             take 'EIC Advance' into account
183     19-JAN-2006 kvsankar  115.39   4924454  Modified CAL_FORMULA_TL to
184                                             take no deduction when Net Salary
185                                             is Negative.
186     15-Feb-2006 kvsankar  115.40   4309544  Modified the formula
187                                             CAL_FORMULA_BO to take fees during
188                                             Proration only if 'Take Fee On
189                                             Proration' checkbox is checked.
190     17-Mar-2006 kvsankar  115.41   5098366  Added NVL condition to make Exemption
191                                             Override work
192                                    5095823  Added a new Global variable
193                                             GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN
194                                             to sum up the Support Fees
195     07-APR-2006 kvsankar  115.42   4858720  Added a new parameter 'EIC_ADVANCE_ASG_GRE_RUN'
196                                             to BASE_FORMULA
197     12-APR-2006 kvsankar  115.43   5149450  Added a new global variable
198                                             'GLB_AMT_NOT_SPEC' for correctly
199                                             calculating Arrears balance value
200                                             when no amount is specified
201     17-APR-2006 kvsankar  115.44   5165704  Modified the code to use PL/SQL
202                                             table values while calculating
203                                             prorated amount in PRORATION section
204     27-APR-2006 kvsankar  115.45   5189256  Modified the package to correctly
205                                             deduct fees
206     21-Jun-2006 sudedas   115.46   5150447  Modified CAL_FORMULA_BO to incorporate
207                                             90% exemption of DI in case of Missouri Head of Household.
208                                             Also added changes to keep Subject Disposable Income constant.
209                                    5249037  Modified CAL_FORMULA_SS, replaced TOTAL_WITHHELD_FEE_ASG_GRE_ITD
210                                             by vf_accrued_fees.
211     11-Jul-2006 sudedas   115.47   5295813  Added Function GET_PRORATED_DEDN_AMOUNT and
212                                             modified CAL_FORMULA_SS and RESET_GLOBAL_VAR
213                                             for Proration Rule set to EQUAL.
214     11-Aug-2006 sudedas   115.49   4676867  Added parameters VOL_DEDN_ROTH_ASG_GRE_RUN,
215                                             VOL_DEDN_SB_TX_ASG_GRE_RUN,
216                                             VOL_DEDN_SB_TX_JD_ASG_GRE_RUN INTO BASE_FORMULA,
217                                             CAL_FORMULA_SS, CAL_FORMULA_BO and
218                                             changed c_Balance_Subject_to_Garn .
219                                    5111601  Modified CAL_FORMULA_TL to take care of
220                                             Addl Exemption Amt for 65 Yr Old / Blind case.
221     21-Sep-2006 sudedas   115.50            Modified CAL_FORMULA_TL (removed nvl from
222                                             csr_get_blind_65_flag) .
223     06-Dec-2006 sudedas   115.51   5688488  Restricting Garn Category to CD and G
224                                             For 90% Exemption in Missouri HOH Issue.
225     11-Dec-2006 sudedas   115.52   5706544  Commenting 90% exemption for Filing Status
226                                             Code ('04') for State of Missouri.
227     19-Dec-2006 sudedas   115.53   5672067  Modified BASE_FORMULA to add cursor to fetch
228                                             Screen Entry Values for 'Amount' and 'Percentage'
229                                             Input Value.
230                                    5701665  cal_formula_bo in Modified for New York
231                                             For Garn category Educational Loan.
232     02-Feb-2007 sudedas   115.54            Reverting back the changes for Bug# 5672067
233     05-Apr-2007 sudedas   115.55   5672067  Modified BASE_FORMULA to add cursor to fetch
234                                             Screen Entry Value for 'Replace Amt' of SI Element.
235     13-Apr-2007 sudedas   115.56            Added Assignment ID, dates join condition in
236                                             the cursor c_get_Replace_Amount_val.
237     07-Jun-2007 sudedas   115.57   6063353  Cal_Formula_BO Changed For Nebraska HOH
238                                    6043168  Cal_Formula_SS Changed to stop dedn
239                                             at Monthly Max with arrearage.
240                                    6085139  Federal Minimum Wage Changed to $5.85
241     20-Jun-2007 sudedas   115.58            Reverting Back Changes for Bug# 6085139
242                                    5520471  Modified Function GET_GARN_LIMIT_MAX_DURATION
243                                             to check Element Level Limit Rule Override.
244                                    6132855  Federal Minimum Wage now stored in JIT Table.
245                                             This is addressing Bug# 6085139 too.
246     04-Jul-2007 sudedas   115.59   6140374  Corrected CAL_FORMULA_BO to remove Inconsistency.
247     14-Jul-2007 sudedas   115.60            Changed GET_GARN_LIMIT_MAX_DURATION
248                                             to add a check for Base Element instead of Calculator.
249     27-Aug-2007 sudedas   115.61   6339209  Changed GET_GARN_LIMIT_MAX_DURATION
250                                             to take care of Old Arch Elements.
251                                    6068769  Modified cal_formula_bo for processing
252                                             Multiple Educational Loans.
253     19-sep-2007 sudedas   115.62   6194070  Change For Maine state Min Wage.
254     31-MAR-2008 vmkulkar  115.64   6683994  Maine State Exemption amount changes
255     31-MAR-2008 vmkulkar  115.65   6678760  Credit Debt Deduction amount changes for
256 					    Delaware
257     31-MAR-2008 vmkulkar  115.66   6678760  Garnishment Deduction amount changes for
258 					    Delaware
259     23-APR-2008 vmkulkar  115.67   6683994  Modified the user table name from
260 					    'Garnishment State Exemptions Table' to
261 					    'Wage Attach State Exemptions Table'
262     23-APR-2008 vmkulkar  115.69   6678760  Garnishment Deduction amount changes for
263 					    Delaware
264     31-Jul-2008 sudedas   115.70   6133337  Provided Flexibility to define Fed / State
265                                             Min Wage Rule / Factor at Element Extra
266                                             Information Level and use that to Override
267                                             any Statutory (Fed / State) Rules.
268                                    7268701  Added Colorado State Min Wage Change.
269     19-Sep-2008 sudedas    115.71  6818016  Base_Formula and Cal_Formula_BO modified
270                                             to pass 2 extra parameters NET_ASG_RUN
271                                             and NET_ASG_PTD.
272     27-Nov-2008 sudedas    115.72  7600041  Changed Cal_Formula_BO for Edu Loan.
273     17-Dec-2008 sudedas    115.73  7596224  Changed Function Convert_Period_Type.
274                                             Removed call to package hr_us_ff_udfs
275     13-Jan-2008 sudedas    115.74  7589784  Changed Cal_Formula_BO for Bug 7589784
276     15-Jan-2009 sudedas    115.75  7674615  Changed cal_formula_bo for multiple
277                                             Educational Loan.
278     10-Apr-2009 sudedas    115.76  8343866  Changed Cal_Formula_BO for Alaska.
279     22-Jun-2009 sudedas    115.77  8556724  Modified RESET_GLOBAL_VAR.
280     14-Aug-2009 asgugupt   115.78  8607790  Modified CAL_FORMULA_TL
281     26-Aug-2009 asgugupt   115.79  8754824  Modified CAL_FORMULA_BO
282     11-Sep-2009 asgugupt   115.81  8898635  Modified CAL_FORMULA_BO
283     22-Sep-2009 asgugupt   115.82  8673016  Modified CAL_FORMULA_BO
284     21-Jan-2010 nkjaladi   115.83  9284206  Modified CAL_FORMULA_BO for education
285                                             loan deduction of Illinois state.
286     15-Jun-2009 asgugupt   115.84  9490973  Modified BASE_FORMULA
287     10-Dec-2010 asgugupt   115.84  10359431 Modified CAL_FORMULA_BO for CO
288     06-Jan-2010 asgugupt   115.84  10359431 Modified condition in BASE_FORMULA
289     29-Jun-2011 abellur    115.87  12529733 Modified CAL_FORMULA_BO for MA
290     18-Jul-2011 abellur    115.88  9788510  Updated CAL_FORMULA_BO for NY, now
291                                              only one garnishment will be processed
292                                              in a run.
293     07-Sep-2011 abellur    115.89 12767090  Updated CAL_FORMULA_BO to include CA
294                                              for one garnishment deduction per
295                                              run.
296     04-Sep-2011 abellur    115.90 12795985  Updated CAL_FORMULA_BO for MA.
297     31-Oct-2011 abellur    115.91 12795985  Updated CAL_FORMULA_BO for MA.
298     01-Jan-2012 abellur    115.92 13546097  Updated CAL_FORMULA_BO for CO
299     22-Feb-2012 abellur    115.93 13727976  Updated CAL_FORMULA_SS child support
300                                              fee calculation stays with in limit.
301     28-May-2012 rgottipa   115.94 13694776  Updated CAL_FORMULA_BO to include GA
302                                              for one garnishment deduction per
303                                              run.
304     27-Jun-2012 abellur    115.95 14032248  Updated BASE_FORMULA, CAL_FORMULA_SS
305                                              and CAL_FORMULA_BO for Voluntary
306                                              deduction, so state level selection
307                                              needs to work for earnings rules.
308     19-Jul-2012 abellur    115.96 14265307  Updated BASE_FORMULA, CAL_FORMULA_SS
309                                              to include the global variable
310                                              GLB_TOTAL_WHLD_SUPPP_FEE_MNTH
311                                              This addresses multiple deductions
312                                              fee aspect overriding max limit.
313     21-Aug-2012 sbachu     115.97 14324196  Initialized the local variables
314                                              so that null is not returned to
315                                              fast formula and Quick pay does not
316                                              error out.
317     21-Aug-2012 rgottipa   115.98 14357293  The logic for
318                                              DI_total_state_exemption is
319                                              modified in Cal_Formula_BO if two
320                                              payments happened in the same
321                                              pay period.
322     10-Oct-2012 abellur    115.99 14265244  Updated BASE_FORMULA, fee is not
323                                              made to zero if dedn is zero for
324                                              support. It is handled in calc
325                                              formula, to process arrears.
326     12-Oct-2012 rgottipa  115.100 14357621  Updated CAL_FORMULA_BO, fee should
327                                             be deducted if there is
328                                             no mulitple deductions and
329                                             Subject_DISPOSABLE_INCOME - dedn_amt
330                                             is greater than zero.
331     19-Oct-2012 abellur   115.101 13976486 Updated CAL_FORMULA_BO, the logic
332                                   13246850  introduced for the bug 7674615, is
333                                             and checking for federal minimum wages
334                                             when DCIA is present is updated.
335                                             Federal exemption now excludes
336                                             the categories AY,BO,CS,SS and TL.
337     01-Jan-2013 abellur   115.102 15844070 Updated BASE_FORMULA, the percentage
338                                             entered at element entry will be
339                                             considered against Gross Wages
340                                             for Illinois, categories CD and G.
341     15-Feb-2013 rgottipa  115.103 16212524  If FEE is rule is defined for 'EL'
342                                             category (either seed or custom defined)
343                                             fee should deduct for that state.
344     11-Mar-2013 rgottipa  115.104 14726857  Modified CAL_FORMULA_BO for CA,
345                                             caliculation for DI_state_exemption_amt
346 ..****************************************************************************/
347 
348 -- New Function added (Reference Bug# 5295813)
349 /****************************************************************************
350     Name        : GET_PRORATED_DEDN_AMOUNT
351     Description : This Function Prorates the Deduction Amount in case one or
352                   more Actual Deduction Amount expects less than the Divide
353                   Equally Amount.
354 *****************************************************************************/
355 
356 FUNCTION GET_PRORATED_DEDN_AMOUNT
357   (
358   DI_subj                 number,
359   P_CTX_ORIGINAL_ENTRY_ID number
360 
361   ) RETURN NUMBER IS
362 
363   cntr                 number ;
364   ln_counter           number ;
365   ln_xtra              number ;
366   ln_counter_iterative number ;
367   ln_counter_lwrdedn   number ;
368   ln_iterative_flag    boolean ;
369   cntr_iterative       number ;
370   ln_xtra_iterative    number ;
371   equal_dedn_amt       number ;
372   tmp_dedn_amt         number ;
373   mod_dedn_amt         number ;
374 
375   BEGIN
376 
377   hr_utility.trace('Entering into PAY_US_INV_DED_FORMULAS.GET_PRORATED_DEDN_AMOUNT.') ;
378 
379   IF mod_dedn_tab.count = 0 THEN
380 
381   ln_counter := 0 ;
382   ln_xtra := 0 ;
383   /* Getting the Equal Deduction Amount for Rule Divide Equally */
384   equal_dedn_amt := DI_subj / dedn_tab.count ;
385   cntr := dedn_tab.first ;
386 
387     /* Looping through the Deduction Table and checking the existence of any
388        Deduction Amount that is less than Equal Deduction (Divide Equally) Amount
389        And populating another Table mod_dedn_tab with the Modified Amount */
390 
391     WHILE cntr is not null LOOP
392        hr_utility.trace('Original Deduction('||cntr||') = '||dedn_tab(cntr));
393        IF dedn_tab(cntr) < equal_dedn_amt THEN
394           ln_counter := ln_counter + 1 ;
395           ln_xtra := ln_xtra + (equal_dedn_amt - dedn_tab(cntr)) ;
396           mod_dedn_tab(cntr) := dedn_tab(cntr) ;
397        ELSE
398           mod_dedn_tab(cntr) := equal_dedn_amt ;
399        END IF ;
400        hr_utility.trace('1st Iteration Deduction('||cntr||') = '||mod_dedn_tab(cntr)) ;
401        cntr := dedn_tab.NEXT(cntr) ;
402     END LOOP;
403 
404     /* If there exist any Deduction Amount that expects less than Equal Deduction one
405        setting Iterative Flag to True and recalculating Equal Deduction Amount */
406 
407     IF ln_counter > 0 THEN
408        ln_iterative_flag := TRUE ;
409        equal_dedn_amt := equal_dedn_amt + ( ln_xtra / (mod_dedn_tab.count - ln_counter)) ;
410     END IF ;
411     cntr_iterative := mod_dedn_tab.first ;
412 
413     While ln_iterative_flag LOOP
414     /* Repeat Iteration as long as Iterative Flag is True */
415       ln_xtra_iterative := 0 ;
416       ln_counter_iterative := 0 ;
417       ln_counter_lwrdedn := 0 ;
418       ln_iterative_flag := FALSE ;
419 
420       cntr_iterative := mod_dedn_tab.FIRST ;
421 
422       WHILE cntr_iterative is not null LOOP
423 
424        tmp_dedn_amt := ( mod_dedn_tab(cntr_iterative) + ( ln_xtra / (dedn_tab.count - ln_counter)) ) ;
425 
426        IF ( dedn_tab(cntr_iterative) >= tmp_dedn_amt )
427          OR  ( tmp_dedn_amt > dedn_tab(cntr_iterative)
428              AND   tmp_dedn_amt = equal_dedn_amt ) THEN
429 
430           mod_dedn_tab(cntr_iterative) := tmp_dedn_amt ;
431 
432           IF mod_dedn_tab(cntr_iterative) > dedn_tab(cntr_iterative) THEN
433              ln_xtra_iterative := ln_xtra_iterative + ( mod_dedn_tab(cntr_iterative) - dedn_tab(cntr_iterative) ) ;
434              ln_counter_iterative := ln_counter_iterative + 1 ;
435              ln_iterative_flag := TRUE ;
436              mod_dedn_tab(cntr_iterative) := dedn_tab(cntr_iterative) ;
437              hr_utility.trace('Modified Nth Deduction('||cntr_iterative||') = '||mod_dedn_tab(cntr_iterative)) ;
438           END IF ;
439 
440         ELSIF mod_dedn_tab(cntr_iterative) = dedn_tab(cntr_iterative) THEN
441               ln_counter_lwrdedn := ln_counter_lwrdedn + 1 ;
442               hr_utility.trace('Original Deduction is less and Modified Deduction Table is Updated already, Counter := '||ln_counter_lwrdedn) ;
443         END IF ;
444 
445         /* Setting Equal Dedn Amt when it reaches Last */
446         IF cntr_iterative = mod_dedn_tab.last THEN
447 
448            ln_xtra := ln_xtra_iterative ;
449            ln_counter := ln_counter_iterative + ln_counter_lwrdedn ;
450 
451            equal_dedn_amt := equal_dedn_amt + ( ln_xtra / (mod_dedn_tab.count - ln_counter)) ;
452 
453            hr_utility.trace('Equal Dedn Amt := '||equal_dedn_amt) ;
454 
455            IF ln_iterative_flag THEN
456               hr_utility.trace('Iterative Flag Value := '||'TRUE') ;
457            END IF ;
458         END IF ; -- Reaches Last Record
459 
460         cntr_iterative := mod_dedn_tab.NEXT(cntr_iterative) ;
461       END LOOP ; -- Modified Deduction Table Looped through
462 
463     END LOOP ; -- As long as Iterative Flag True
464   END IF ;  -- End of population of mod_dedn_tab when tab count = 0
465 
466   mod_dedn_amt := mod_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) ;
467   hr_utility.trace('Final Deduction Amount for the Inv Dedn Element ('||to_char(P_CTX_ORIGINAL_ENTRY_ID)||') := '||to_char(mod_dedn_amt)) ;
468 
469   RETURN mod_dedn_amt ;
470 
471   hr_utility.trace('Leaving PAY_US_INV_DED_FORMULAS.GET_PRORATED_DEDN_AMOUNT.') ;
472 
473 END GET_PRORATED_DEDN_AMOUNT ;
474 
475   /****************************************************************************
476     Name        : BASE_FORMULA
477     Description : This function calculates deduction amount and fees claimed by
478                   each involuntary deduction element. It also initializes input
479                   values of calculator element. these input values are later
480                   sent as indirect inputs.
481   *****************************************************************************/
482 
483 FUNCTION BASE_FORMULA(
484     P_CTX_DATE_EARNED                   date,
485     P_CTX_ELEMENT_ENTRY_ID              number,
486     P_CTX_JURISDICTION_CODE             varchar2,
487     P_CTX_ORIGINAL_ENTRY_ID             number,
488     ADDITIONAL_ASG_GRE_LTD              IN OUT NOCOPY number,
489     REPLACEMENT_ASG_GRE_LTD             IN OUT NOCOPY number,
490     ACCRUED_ASG_LTD                     IN OUT NOCOPY number,
491     ACCRUED_FEES_ASG_LTD                number,
492     FEES_ENTRY_PTD                      IN OUT NOCOPY number,
493     FEES_ENTRY_ITD                      IN OUT NOCOPY number,
494     FEES_ENTRY_MONTH                    IN OUT NOCOPY number,
495     ASG_MONTH                           number,
496     ASG_PTD                             number,
497     /*VOL_DEDNS_ASG_GRE_LTD               number,*/
498     VOL_DED_ASG_GRE_LASTRUN             number,
499     PRE_TAX_DED_ASG_GRE_LASTRUN         number,
500     ASG_WORK_AT_HOME                    varchar2,
501     OVERRIDE_PER_ADR_REGION_2           varchar2,
502     OVERRIDE_PER_ADR_REGION_1           varchar2,
503     OVERRIDE_PER_ADR_CITY               varchar2,
504     OVERRIDE_PER_ADR_POSTAL_CODE        varchar2,
505     OVERRIDE_LOC_ADR_REGION_2           varchar2,
506     OVERRIDE_LOC_ADR_REGION_1           varchar2,
507     OVERRIDE_LOC_ADR_CITY               varchar2,
508     OVERRIDE_LOC_ADR_POSTAL_CODE        varchar2,
509     AMOUNT                              number,
510     JURISDICTION                        IN OUT NOCOPY varchar2,
511     DATE_SERVED                         IN OUT NOCOPY date,
512     DEDNS_AT_TIME_OF_WRIT               number,
513     PAY_EARNED_END_DATE                 date,
514     EXEMPT_AMOUNT                       number,
515     ARREARS_DATE                        date,
516     NUM_DEPS                            number,
517     FIL_STAT                            varchar2,
518     ALLOWS                              number,
519     /*VOLDEDNS_AT_WRIT                    OUT NOCOPY number,*/
520     CALC_SUBPRIO                        OUT NOCOPY number,
521     REGULAR_EARNINGS_ASG_GRE_RUN        number,
522     DI_SUBJ_TAX_JD_ASG_GRE_RUN          number,
523     DI_SUBJ_TAX_ASG_GRE_RUN             number,
524     TAX_DEDUCTIONS_ASG_GRE_RUN          number,
525     PRE_TAX_DEDUCTIONS_ASG_GRE_RUN      number,
526     PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN      number,
527     PRE_TAX_SUBJ_TX_ASG_GRE_RUN         number,
528     ARREARS_OVERRIDE                    number,
529     PERCENTAGE                          number,
530     MONTHLY_CAP_AMOUNT                  number,
531     PERIOD_CAP_AMOUNT                   number,
532     GARN_FEE_FEE_RULE                   varchar2,
533     GARN_FEE_FEE_AMOUNT                 number,
534     GARN_FEE_MAX_FEE_AMOUNT             number,
535     ACCRUED_FEES                        number,
536     GARN_FEE_PCT_CURRENT                number,
537     GARN_FEE_ADDL_GARN_FEE_AMOUNT       number,
538     TOTAL_OWED                          number,
539     GARN_TOTAL_FEES_ASG_GRE_RUN         number,
540     GRN_DI_SUBJ_TX_ASG_GRE_RUN          number,
541     GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN       number,
542     PR_TX_DED_SBJ_TX_ASG_GRE_RN         number,
543     PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN      number,
544     GARN_EXEMPTION_CALC_RULE            varchar2,
545     GARN_TOTAL_DEDNS_ASG_GRE_RUN        number,
546     DCIA_DI_SUBJ_TX_ASG_GRE_RUN         number default 0,
547     DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN      number default 0,
548     PR_TX_DCIA_SB_TX_ASG_GRE_RN         number default 0,
549     PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN      number default 0,
550     FEES_ASG_GRE_PTD                    number default -9999,
551     EIC_ADVANCE_ASG_GRE_RUN             number default 0,
552     VOL_DEDN_ROTH_ASG_GRE_RUN           number  default 0,
553     VOL_DEDN_SB_TX_ASG_GRE_RUN          number  default 0,
554     VOL_DEDN_SB_TX_JD_ASG_GRE_RUN       number  default 0,
555     NET_ASG_RUN                         number  default 0,
556     NET_ASG_PTD                         number  default 0
557 
558 ) RETURN number IS
559 
560 default_number number;
561 default_string varchar2(11);
562 default_date date;
563 garn_category varchar2(5);
564 c_Gross_Subject_to_Garn number;
565 c_balance_Subject_to_Garn number;
566 dedn_amt number;
567 calcd_fee number;
568 l_total_owed number;
569 sub_prio_max number;
570 amt number;
571 dedn_override number;
572 exempt_amt number;
573 to_accrued_fees number;
574 l_garn_fee_max_fee_amt number;
575 
576 l_debug_on varchar2(1);
577 l_proc_name varchar2(50);
578 l_ini_fee_flag varchar2(10);
579 lv_allow_value varchar2(10);
580 lv_filing_status varchar2(10);
581 
582 -- Bug# 5672067
583 ln_SI_Replace_Amt      number ;
584 
585 b_default_flag boolean;
586 
587     CURSOR cur_debug is
588     SELECT parameter_value
589       FROM pay_action_parameters
590      WHERE parameter_name = 'GARN_DEBUG_ON';
591 
592     /* Cursor for Bug 3715182 and 3719168 */
593     CURSOR c_garn_max_fee_amt is
594     select target.MAX_FEE_AMOUNT from
595            PAY_US_GARN_FEE_RULES_F target,
596            PAY_ELEMENT_TYPES_F pet,
597            PAY_ELEMENT_ENTRIES_F pee
598     WHERE target.state_code = substr(P_CTX_JURISDICTION_CODE,1,2)
599       AND target.garn_category = pet.element_information1
600       AND P_CTX_DATE_EARNED BETWEEN target.effective_start_date
601                                 AND target.effective_end_date
602       AND pet.element_type_id = pee.element_type_id
603       AND pee.element_entry_id = P_CTX_ELEMENT_ENTRY_ID
604       AND P_CTX_DATE_EARNED BETWEEN pet.effective_start_date
605                                 AND pet.effective_end_date;
606 
607     /* Cursot to return the Initial Fee Flag value Bug 3549298 */
608     CURSOR csr_get_ini_fee_flag is
609     SELECT nvl(entry_information9, 'N')
610       FROM pay_element_entries_f
611      WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
612        AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
613        AND P_CTX_DATE_EARNED BETWEEN effective_start_date and effective_end_date;
614 
615     -- Get the value entered for Allowances Input Value
616     CURSOR c_get_allowance_value(c_input_value_name varchar2) IS
617     select peev.screen_entry_value
618       from pay_element_entries_f peef,
619            pay_element_entry_values_f peev,
620            pay_input_values_f pivf
621      where peef.element_entry_id = P_CTX_ELEMENT_ENTRY_ID
622        and peev.element_entry_id = peef.element_entry_id
623        and pivf.element_type_id = peef.element_type_id
624        and pivf.name = c_input_value_name
625        and peev.input_value_id = pivf.input_value_id
626        and P_CTX_DATE_EARNED between peev.effective_start_date
627                                  and peev.effective_end_date;
628 
629     -- Bug# 5672067
630     -- Get the Screen Entry Value for 'Replace Amt' Input Values
631     CURSOR c_get_Replace_Amount_val(c_input_value_name varchar2) IS
632     select peev_si.screen_entry_value
633       from pay_element_entries_f peef_base,
634            pay_element_entries_f peef_si,
635            pay_element_entry_values_f peev_si,
636            pay_input_values_f pivf_si,
637            pay_element_types_f pet_base,
638            pay_element_types_f pet_si
639      where peef_base.element_entry_id = P_CTX_ELEMENT_ENTRY_ID
640        and peef_base.element_type_id = pet_base.element_type_id
641        and pet_base.element_information18 = pet_si.element_type_id
642        and peef_base.assignment_id = peef_si.assignment_id
643        and peef_si.element_type_id = pet_si.element_type_id
644        and peev_si.element_entry_id = peef_si.element_entry_id
645        and pivf_si.element_type_id = peef_si.element_type_id
646        and pivf_si.name = c_input_value_name
647        and peev_si.input_value_id = pivf_si.input_value_id
648        and P_CTX_DATE_EARNED between peev_si.effective_start_date
649                                  and peev_si.effective_end_date
650        and P_CTX_DATE_EARNED between peef_si.effective_start_date
651                                  and peef_si.effective_end_date
652        and P_CTX_DATE_EARNED between pivf_si.effective_start_date
653                                  and pivf_si.effective_end_date
654        and P_CTX_DATE_EARNED between pet_si.effective_start_date
655                                  and pet_si.effective_end_date ;
656 
657 BEGIN
658 
659     l_package_name := 'PAY_US_INV_DED_FORMULAS.';
660     l_proc_name := l_package_name||'BASE_FORMULA';
661 
662     default_number := -9999;
663     default_string := 'NOT ENTERED';
664     default_date := fnd_date.canonical_to_date('0001/01/01');
665     sub_prio_max := 9999;
666     l_garn_fee_max_fee_amt := NULL;
667     GLB_NUM_ELEM := nvl(GLB_NUM_ELEM ,0);
668       --bug 9788510
669 	     if GLB_MULTIPLE_GARN is NULL then
670 		     GLB_MULTIPLE_GARN:=FALSE;
671          end if;
672       --bug 9788510
673     lv_allow_value := NULL;
674     lv_filing_status := NULL;
675     b_default_flag := FALSE;
676 
677     -- Bug 4079142
678     if GLB_OTHER_DI_FLAG is NULL then
679         GLB_OTHER_DI_FLAG := FALSE;
680     end if;
681 
682     if GLB_DCIA_EXIST_FLAG is NULL then
683         GLB_DCIA_EXIST_FLAG := FALSE;
684     end if;
685 
686     OPEN cur_debug;
687         FETCH cur_debug into l_debug_on;
688     CLOSE cur_debug;
689 
690     /*
691      * Fetch the value of Initial Fee Flag. Bug 3549298
692      */
693     open csr_get_ini_fee_flag;
694     fetch csr_get_ini_fee_flag into l_ini_fee_flag;
695     close csr_get_ini_fee_flag;
696 
697     IF l_debug_on = 'Y' THEN
698         hr_utility.trace_on(NULL, 'GARN');
699         hr_utility.trace('Entering '||l_proc_name);
700         hr_utility.trace('Input parameters ....');
701         hr_utility.trace('P_CTX_DATE_EARNED = '||P_CTX_DATE_EARNED);
702         hr_utility.trace('P_CTX_ELEMENT_ENTRY_ID = '||P_CTX_ELEMENT_ENTRY_ID);
703         hr_utility.trace('P_CTX_JURISDICTION_CODE = '||P_CTX_JURISDICTION_CODE);
704         hr_utility.trace('P_CTX_ORIGINAL_ENTRY_ID = '||P_CTX_ORIGINAL_ENTRY_ID);
705         hr_utility.trace('ADDITIONAL_ASG_GRE_LTD = '||ADDITIONAL_ASG_GRE_LTD);
706         hr_utility.trace('REPLACEMENT_ASG_GRE_LTD = '||REPLACEMENT_ASG_GRE_LTD);
707         hr_utility.trace('ACCRUED_ASG_LTD = '||ACCRUED_ASG_LTD);
708         hr_utility.trace('ACCRUED_FEES_ASG_LTD = '||ACCRUED_FEES_ASG_LTD);
709         hr_utility.trace('FEES_ENTRY_PTD = '||FEES_ENTRY_PTD);
710         hr_utility.trace('FEES_ENTRY_ITD = '||FEES_ENTRY_ITD);
711         hr_utility.trace('FEES_ENTRY_MONTH = '||FEES_ENTRY_MONTH);
712         hr_utility.trace('ASG_MONTH = '||ASG_MONTH);
713         hr_utility.trace('ASG_PTD = '||ASG_PTD);
714         --hr_utility.trace('VOL_DEDNS_ASG_GRE_LTD = '||VOL_DEDNS_ASG_GRE_LTD);
715         hr_utility.trace('VOL_DED_ASG_GRE_LASTRUN = '||VOL_DED_ASG_GRE_LASTRUN);
716         hr_utility.trace('PRE_TAX_DED_ASG_GRE_LASTRUN = '||PRE_TAX_DED_ASG_GRE_LASTRUN);
717         hr_utility.trace('ASG_WORK_AT_HOME = '||ASG_WORK_AT_HOME);
718         hr_utility.trace('OVERRIDE_PER_ADR_REGION_2 = '||OVERRIDE_PER_ADR_REGION_2);
719         hr_utility.trace('OVERRIDE_PER_ADR_REGION_1 = '||OVERRIDE_PER_ADR_REGION_1);
720         hr_utility.trace('OVERRIDE_PER_ADR_CITY = '||OVERRIDE_PER_ADR_CITY);
721         hr_utility.trace('OVERRIDE_PER_ADR_POSTAL_CODE = '||OVERRIDE_PER_ADR_POSTAL_CODE);
722         hr_utility.trace('OVERRIDE_LOC_ADR_REGION_2 = '||OVERRIDE_LOC_ADR_REGION_2);
723         hr_utility.trace('OVERRIDE_LOC_ADR_REGION_1 = '||OVERRIDE_LOC_ADR_REGION_1);
724         hr_utility.trace('OVERRIDE_LOC_ADR_CITY = '||OVERRIDE_LOC_ADR_CITY);
725         hr_utility.trace('OVERRIDE_LOC_ADR_POSTAL_CODE = '||OVERRIDE_LOC_ADR_POSTAL_CODE);
726         hr_utility.trace('AMOUNT = '||AMOUNT);
727         hr_utility.trace('JURISDICTION = '||JURISDICTION);
728         hr_utility.trace('DATE_SERVED = '||DATE_SERVED);
729         hr_utility.trace('DEDNS_AT_TIME_OF_WRIT = '||DEDNS_AT_TIME_OF_WRIT);
730         hr_utility.trace('PAY_EARNED_END_DATE = '||PAY_EARNED_END_DATE);
731         hr_utility.trace('EXEMPT_AMOUNT = '||EXEMPT_AMOUNT);
732         hr_utility.trace('ARREARS_DATE = '||ARREARS_DATE);
733         hr_utility.trace('NUM_DEPS = '||NUM_DEPS);
734         hr_utility.trace('FIL_STAT = '||FIL_STAT);
735         hr_utility.trace('ALLOWS = '||ALLOWS);
736         --hr_utility.trace('VOLDEDNS_AT_WRIT = '||VOLDEDNS_AT_WRIT);
737         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
738         hr_utility.trace('REGULAR_EARNINGS_ASG_GRE_RUN = '||REGULAR_EARNINGS_ASG_GRE_RUN);
739         hr_utility.trace('DI_SUBJ_TAX_JD_ASG_GRE_RUN = '||DI_SUBJ_TAX_JD_ASG_GRE_RUN);
740         hr_utility.trace('DI_SUBJ_TAX_ASG_GRE_RUN = '||DI_SUBJ_TAX_ASG_GRE_RUN);
741         hr_utility.trace('TAX_DEDUCTIONS_ASG_GRE_RUN = '||TAX_DEDUCTIONS_ASG_GRE_RUN);
742         hr_utility.trace('PRE_TAX_DEDUCTIONS_ASG_GRE_RUN = '||PRE_TAX_DEDUCTIONS_ASG_GRE_RUN);
743         hr_utility.trace('PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN = '||PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN);
744         hr_utility.trace('PRE_TAX_SUBJ_TX_ASG_GRE_RUN = '||PRE_TAX_SUBJ_TX_ASG_GRE_RUN);
745         hr_utility.trace('ARREARS_OVERRIDE = '||ARREARS_OVERRIDE);
746         hr_utility.trace('PERCENTAGE = '||PERCENTAGE);
747         hr_utility.trace('MONTHLY_CAP_AMOUNT = '||MONTHLY_CAP_AMOUNT);
748         hr_utility.trace('PERIOD_CAP_AMOUNT = '||PERIOD_CAP_AMOUNT);
749         hr_utility.trace('GARN_FEE_FEE_RULE = '||GARN_FEE_FEE_RULE);
750         hr_utility.trace('GARN_FEE_FEE_AMOUNT = '||GARN_FEE_FEE_AMOUNT);
751         hr_utility.trace('GARN_FEE_MAX_FEE_AMOUNT = '||GARN_FEE_MAX_FEE_AMOUNT);
752         hr_utility.trace('ACCRUED_FEES = '||ACCRUED_FEES);
753         hr_utility.trace('GARN_FEE_PCT_CURRENT = '||GARN_FEE_PCT_CURRENT);
754         hr_utility.trace('GARN_FEE_ADDL_GARN_FEE_AMOUNT = '||GARN_FEE_ADDL_GARN_FEE_AMOUNT);
755         hr_utility.trace('TOTAL_OWED = '||TOTAL_OWED);
756         hr_utility.trace('GARN_TOTAL_FEES_ASG_GRE_RUN = '||GARN_TOTAL_FEES_ASG_GRE_RUN);
757         hr_utility.trace('GRN_DI_SUBJ_TX_ASG_GRE_RUN = '||GRN_DI_SUBJ_TX_ASG_GRE_RUN);
758         hr_utility.trace('GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN = '||GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN);
759         hr_utility.trace('PR_TX_DED_SBJ_TX_ASG_GRE_RN = '||PR_TX_DED_SBJ_TX_ASG_GRE_RN);
760         hr_utility.trace('PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN = '||PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN);
761         hr_utility.trace('GARN_EXEMPTION_CALC_RULE = '||GARN_EXEMPTION_CALC_RULE);
762         hr_utility.trace('GARN_TOTAL_DEDNS_ASG_GRE_RUN = '||GARN_TOTAL_DEDNS_ASG_GRE_RUN);
763         hr_utility.trace('DCIA_DI_SUBJ_TX_ASG_GRE_RUN = '||DCIA_DI_SUBJ_TX_ASG_GRE_RUN);
764         hr_utility.trace('DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN = '||DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN);
765         hr_utility.trace('PR_TX_DCIA_SB_TX_ASG_GRE_RN = '||PR_TX_DCIA_SB_TX_ASG_GRE_RN);
766         hr_utility.trace('PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN = '||PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN);
767         hr_utility.trace('INITIAL FEE FLAG = ' || l_ini_fee_flag);
768         hr_utility.trace('FEES_ASG_GRE_PTD = ' || FEES_ASG_GRE_PTD);
769         hr_utility.trace('EIC_ADVANCE_ASG_GRE_RUN = ' || EIC_ADVANCE_ASG_GRE_RUN);
770         hr_utility.trace('VOL_DEDN_ROTH_ASG_GRE_RUN = ' || VOL_DEDN_ROTH_ASG_GRE_RUN);
771         hr_utility.trace('VOL_DEDN_SB_TX_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_ASG_GRE_RUN);
772         hr_utility.trace('VOL_DEDN_SB_TX_JD_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_JD_ASG_GRE_RUN);
773         hr_utility.trace('NET_ASG_RUN = ' || NET_ASG_RUN);
774         hr_utility.trace('NET_ASG_PTD = ' || NET_ASG_PTD);
775     END IF;
776 
777     -- Bug 4154950
778     -- Modified the paramter name from ACCRUED_FEES_ASG_GRE_LTD to
779     -- ACCRUED_FEES_ASG_LTD
780     IF ACCRUED_FEES_ASG_LTD = FEES_ENTRY_ITD THEN
781         to_accrued_fees := 0;
782     ELSE
783         to_accrued_fees := FEES_ENTRY_ITD - ACCRUED_FEES_ASG_LTD;
784     END IF;
785 
786     -- Bug 5095823
787     IF GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN IS NULL THEN
788        GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN := 0;
789     END IF;
790 
791     --Bug 14265307
792     IF GLB_TOTAL_WHLD_SUPPP_FEE_MNTH IS NULL THEN
793        GLB_TOTAL_WHLD_SUPPP_FEE_MNTH := 0;
794     END IF;
795     /*---- SET CONTEXTS -----*/
796     CTX_DATE_EARNED := P_CTX_DATE_EARNED;
797     CTX_ELEMENT_ENTRY_ID := P_CTX_ELEMENT_ENTRY_ID;
798     CTX_JURISDICTION_CODE := P_CTX_JURISDICTION_CODE;
799     /*-----------------------*/
800 
801     GLB_NUM_ELEM := GLB_NUM_ELEM + 1;
802     hr_utility.trace('GLB_NUM_ELEM = '|| GLB_NUM_ELEM);
803 
804     -- Bug 4748532
805     GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) := FEES_ASG_GRE_PTD;
806     GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) := ASG_PTD;
807     GLB_AMT_NOT_SPEC(P_CTX_ORIGINAL_ENTRY_ID)     := FALSE;
808 
809     amt := NVL(amount,0);
810     calc_subprio := entry_subpriority;
811 
812 /*    IF ACCRUED_ASG_GRE_LTD = 0 THEN
813 
814         voldedns_at_writ := VOL_DED_ASG_GRE_LASTRUN
815                             + PRE_TAX_DED_ASG_GRE_LASTRUN;
816     END IF;*/
817 
818     IF Dedns_at_Time_of_Writ <> default_number THEN
819         dedn_override := Dedns_at_Time_of_Writ;
820 
821     /* Commented because Vol Dedns At Writ input value no longer exists
822       ELSE
823         IF ACCRUED_ASG_GRE_LTD = 0 THEN
824             dedn_override := voldedns_at_writ;
825   		ELSIF VOL_DEDNS_ASG_GRE_LTD <> default_number THEN
826             dedn_override := VOL_DEDNS_ASG_GRE_LTD;
827         END IF;*/
828     END IF;
829 
830     IF calc_subprio = 1 THEN
831 	    IF date_served <> default_date THEN
832 		    calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - Date_Served);
833         END IF;
834     END IF;
835 
836     garn_category := garn_cat;
837 
838     IF Exempt_Amount  <> default_number THEN
839         IF garn_category = 'BO' THEN
840             Exempt_Amt := Exempt_Amount;
841         ELSE
842             Exempt_Amt := 0;
843         END IF;
844     ELSE
845         exempt_amt := 0;
846     END IF;
847 
848     IF garn_category in ('AY','CS','SS') THEN
849     /*------ Support Deduction amount calculation starts -----------*/
850 
851         c_Gross_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN
852     	                	       +LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN,
853                                           DI_SUBJ_TAX_ASG_GRE_RUN));
854         -- Bug# 4676867
855         --Added the below if for bug 14032248 State level inclusion of earnings for DI
856         IF VOL_DEDN_SB_TX_JD_ASG_GRE_RUN <> 0 and VOL_DEDN_SB_TX_ASG_GRE_RUN = 0 THEN
857          c_Balance_Subject_to_Garn :=
858                                  (REGULAR_EARNINGS_ASG_GRE_RUN +
859                                    LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN,
860                                          DI_SUBJ_TAX_ASG_GRE_RUN)) -
861                                   ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
862                                    + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
863                                      (LEAST(PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN,
864                                       PRE_TAX_SUBJ_TX_ASG_GRE_RUN )))
865                                    + (VOL_DEDN_ROTH_ASG_GRE_RUN - VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)
866                                       );
867         ELSE
868          c_Balance_Subject_to_Garn :=
869                                  (REGULAR_EARNINGS_ASG_GRE_RUN +
870                                    LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN,
871                                          DI_SUBJ_TAX_ASG_GRE_RUN)) -
872                                   ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
873                                    + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
874                                      (LEAST(PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN,
875                                       PRE_TAX_SUBJ_TX_ASG_GRE_RUN )))
876                                    + (VOL_DEDN_ROTH_ASG_GRE_RUN -
877                                       (LEAST(VOL_DEDN_SB_TX_ASG_GRE_RUN,
878                                              VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)))
879                                       );
880         END IF;
881 
882         hr_utility.trace('c_Gross_Subject_to_Garn = '||c_Gross_Subject_to_Garn);
883         hr_utility.trace('c_Balance_Subject_to_Garn = '||c_Balance_Subject_to_Garn);
884 
885         IF calc_subprio = 1 THEN
886             IF date_served <> default_date THEN
887                 calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - Date_Served);
888             END IF;
889         END IF;
890 
891         -- Bug# 5672067
892         -- Reverting Back the Changes
893         -- Changing for Special Input Element
894         OPEN c_get_Replace_Amount_val('Replace Amt') ;
895         FETCH c_get_Replace_Amount_val INTO ln_SI_Replace_Amt ;
896         CLOSE c_get_Replace_Amount_val ;
897 
898         hr_utility.trace('ln_SI_Replace_Amt := '||ln_SI_Replace_Amt) ;
899 
900         IF ln_SI_Replace_Amt IS NOT NULL THEN
901             dedn_amt := ln_SI_Replace_Amt ;
902             IF dedn_amt < 0 THEN
903                dedn_amt := 0 ;
904             END IF ;
905         ELSIF Amount <> 0 THEN
906             dedn_amt := Amount;
907         ELSIF Percentage <> 0 THEN
908             IF SUBSTR(Jurisdiction,1,2) = '50' THEN
909                 dedn_amt := (Percentage * c_Gross_Subject_to_Garn) / 100;
910             ELSE
911                 dedn_amt := (Percentage * c_Balance_Subject_to_Garn) / 100;
912             END IF;
913         ELSE
914             dedn_amt :=  c_Balance_Subject_to_Garn;  /* total_owed */
915             GLB_AMT_NOT_SPEC(P_CTX_ORIGINAL_ENTRY_ID) := TRUE;
916         END IF;
917 
918         IF ADDITIONAL_ASG_GRE_LTD <> 0 THEN
919             dedn_amt := dedn_amt + ADDITIONAL_ASG_GRE_LTD;
920         END IF;
921 
922         -- Bug 4072103
923         -- Added code to recalculate DEDN_AMT if amount to be deducted
924         -- overshoots TOTAL_OWED
925 
926         actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := DEDN_AMT;
927         -- Bug 4154950
928         -- Modified the paramter name from ACCRUED_ASG_GRE_LTD to
929         -- ACCRUED_ASG_LTD
930         IF TOTAL_OWED > 0 THEN
931            IF ACCRUED_ASG_LTD + DEDN_AMT > TOTAL_OWED THEN
932               -- Bug 4748532
933               IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
934                  actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := TOTAL_OWED - ACCRUED_ASG_LTD;
935                  hr_utility.trace('Actual Deduction Amount(TO) = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
936                  hr_utility.trace('Deduction Amount(TO) = ' || DEDN_AMT);
937               ELSE
938                  DEDN_AMT := TOTAL_OWED - ACCRUED_ASG_LTD;
939               END IF;
940            END IF;
941         END IF;
942     /* *** Calculation Section END *** */
943 
944         /*IF arrears_override <> default_number THEN
945             dedn_amt := dedn_amt + arrears_override;
946         END IF;*/
947         hr_utility.set_location(l_proc_name,10);
948         hr_utility.trace('dedn_amt = '||dedn_amt);
949         IF arrears_override <> default_number THEN
950             arrears_tab(P_CTX_ORIGINAL_ENTRY_ID) := arrears_override; /* Bug 2992741 */
951         END IF;
952 
953         hr_utility.trace('Dedn_amt before cap adjustments = '||dedn_amt);
954         hr_utility.trace('Monthly_Cap_Amount = '||Monthly_Cap_Amount);
955 
956 
957         IF Monthly_Cap_Amount <> 0  THEN
958             -- Bug 4154950
959             -- Modified the paramter name from ASG_GRE_MONTH to
960             -- ASG_MONTH
961             IF Monthly_Cap_Amount - ASG_MONTH >= 0 THEN
962                -- Bug 4748532
963                IF dedn_amt + ASG_MONTH > Monthly_Cap_Amount THEN
964                   IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
965                      IF actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) > (Monthly_Cap_Amount - ASG_MONTH) THEN
966                         actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := Monthly_Cap_Amount - ASG_MONTH;
967                      END IF;
968                      hr_utility.trace('Actual Deduction Amount(MTD) = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
969                      hr_utility.trace('Deduction Amount(MTD) = ' || DEDN_AMT);
970                   ELSE
971                      dedn_amt := Monthly_Cap_Amount - ASG_MONTH;
972                   END IF;
973                END IF;
974             END IF;
975         END IF;
976 
977         hr_utility.trace('Period_Cap_Amount = '||Period_Cap_Amount); /* Max_Per_Period */
978         IF Period_Cap_Amount <> 0  THEN
979             -- Bug 4154950
980             -- Modified the paramter name from ASG_GRE_PTD to
981             -- ASG_PTD
982             IF Period_Cap_Amount - ASG_PTD >= 0 THEN
983                 IF dedn_amt + ASG_PTD > Period_Cap_Amount THEN
984                    -- Bug 4748532
985                    IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
986                       IF actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) > (Period_Cap_Amount - ASG_PTD) THEN
987                          actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := Period_Cap_Amount - ASG_PTD;
988                       END IF;
989                       hr_utility.trace('Actual Deduction Amount(PTD) = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
990                       hr_utility.trace('Deduction Amount(PTD) = ' || DEDN_AMT);
991                    ELSE
992                       dedn_amt := Period_Cap_Amount - ASG_PTD;
993                    END IF;
994                 END IF;
995             END IF;
996         END IF;
997         hr_utility.trace('Dedn_amt after cap adjustments = '||dedn_amt);
998         IF Amount = 0 and arrears_override <> default_number THEN
999             dedn_amt := dedn_amt - arrears_override; /* For Bug 2992741, we need Arrears Dedn Amount and dedn_amt in separate
1000                                                         PL/SQL tables. But the above Max Per Period adjustment tends to merge the
1001                                                         dedn_amt and Arrears Dedn Amount (arrears_override). Hence dedn_amt is
1002                                                         brought down to a value which does not contain Arrears Dedn Amount. */
1003         END IF;
1004 
1005     /* *** Fee processing BEGIN. *** */
1006         calcd_fee := 0;
1007     /* 01-FEB-1999 ***********
1008        If the amount deducted for Child support is ZERO
1009        then the fee amount to be deducted should be set to ZERO
1010        If the Child support amount to be deducted is less than ZERO
1011        then also set the dedn_amt to 0
1012     */
1013 
1014     /* Bug 3715182 and 3719168
1015      * Get the GARN_FEE_MAX_FEE_AMOUNT
1016      */
1017     open c_garn_max_fee_amt;
1018     fetch c_garn_max_fee_amt into l_garn_fee_max_fee_amt;
1019     close c_garn_max_fee_amt;
1020 
1021     if l_garn_fee_max_fee_amt is NULL then
1022        l_garn_fee_max_fee_amt := 99999999;
1023     else
1024        l_garn_fee_max_fee_amt := GARN_FEE_MAX_FEE_AMOUNT;
1025     end if;
1026     hr_utility.trace('Modified GARN_FEE_MAX_FEE_AMOUNT = '||l_garn_fee_max_fee_amt);
1027 
1028 
1029         -- Updated the below IF for 14265244
1030         IF dedn_amt < 0 THEN
1031             dedn_amt := 0;
1032         END IF;
1033 
1034             IF GARN_FEE_FEE_RULE <> default_string THEN
1035                 IF GARN_FEE_FEE_RULE = 'AMT_OR_PCT_PER_GARN' THEN
1036                     IF total_owed = default_number THEN
1037                         l_total_owed := 0;
1038                     ELSE
1039                         l_total_owed := total_owed;
1040                     END IF;
1041                     calcd_fee := FNC_FEE_CALCULATION(GARN_FEE_FEE_RULE,
1042                                                      GARN_FEE_FEE_AMOUNT,
1043                                                      GARN_FEE_PCT_CURRENT,
1044                                                      l_total_owed,
1045                                                      ACCRUED_ASG_LTD,
1046                                                      GARN_FEE_ADDL_GARN_FEE_AMOUNT,
1047                                                      l_garn_fee_max_fee_amt,
1048                                                      FEES_ENTRY_PTD,
1049                                                      GARN_TOTAL_FEES_ASG_GRE_RUN,
1050                                                      dedn_amt,
1051                                                      FEES_ENTRY_MONTH,
1052                                                      Accrued_fees);
1053 
1054                 ELSIF GARN_FEE_FEE_RULE = 'AMT_OR_PCT' THEN
1055                     calcd_fee := GREATEST(GARN_FEE_FEE_AMOUNT,
1056                     GARN_FEE_PCT_CURRENT * dedn_amt);
1057                 ELSIF GARN_FEE_FEE_RULE = 'PCT_PER_MONTH' OR
1058                     GARN_FEE_FEE_RULE = 'PCT_PER_PERIOD' OR
1059                     GARN_FEE_FEE_RULE = 'PCT_PER_RUN' THEN
1060                     calcd_fee := LEAST(l_garn_fee_max_fee_amt, GARN_FEE_PCT_CURRENT * dedn_amt);
1061                 ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_GARN' OR
1062                     GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD' OR
1063                     GARN_FEE_FEE_RULE = 'AMT_PER_MONTH' OR
1064                     GARN_FEE_FEE_RULE = 'AMT_PER_RUN' THEN
1065                     calcd_fee := GARN_FEE_FEE_AMOUNT;
1066                 ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_GARN_ADDL' OR
1067                     GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD_ADDL' OR
1068                     GARN_FEE_FEE_RULE = 'AMT_PER_MONTH_ADDL' OR
1069                     GARN_FEE_FEE_RULE = 'AMT_PER_RUN_ADDL' THEN
1070                     IF Accrued_Fees = 0 THEN
1071                         calcd_fee := GARN_FEE_FEE_AMOUNT;
1072                     ELSIF Accrued_Fees >= GARN_FEE_FEE_AMOUNT THEN
1073                         calcd_fee := GARN_FEE_ADDL_GARN_FEE_AMOUNT;
1074                     -- Bug 4748532
1075                     ELSIF Accrued_Fees = FEES_ENTRY_PTD THEN
1076                         calcd_fee := GARN_FEE_FEE_AMOUNT;
1077                     ELSE
1078                         calcd_fee := GARN_FEE_FEE_AMOUNT - Accrued_Fees + GARN_FEE_ADDL_GARN_FEE_AMOUNT;
1079                     END IF;
1080                 END IF;
1081                 /*
1082                  * Check for Initial Fee Flag set. If yes then do not take the initial fee.
1083                  * Only take the Additional Fee if specified. Bug 3549298
1084                  */
1085                 if l_ini_fee_flag = 'Y' then
1086                     if (GARN_FEE_FEE_RULE = 'AMT_PER_GARN_ADDL' OR
1087                         GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD_ADDL' OR
1088                         GARN_FEE_FEE_RULE = 'AMT_PER_MONTH_ADDL' OR
1089                         GARN_FEE_FEE_RULE = 'AMT_PER_RUN_ADDL') then
1090                         calcd_fee := GARN_FEE_ADDL_GARN_FEE_AMOUNT;
1091                     else
1092                         -- Initial Fee Taken
1093                         calcd_fee := 0;
1094                     end if;
1095                 end if;
1096             END IF;
1097         --END IF; --Commented for 14265244
1098 
1099 
1100     /* *** Fee processing END. *** */
1101 
1102         hr_utility.trace('Storing deduction and fees values at index '||p_ctx_original_entry_id);
1103         dedn_tab(p_ctx_original_entry_id) := dedn_amt;
1104         fees_tab(p_ctx_original_entry_id) := calcd_fee;
1105 
1106         hr_utility.trace('Deduction Count = '||dedn_tab.count());
1107         hr_utility.trace('Fees Count = '||fees_tab.count());
1108         hr_utility.trace('Current deduction value = '||dedn_tab(p_ctx_original_entry_id));
1109         hr_utility.trace('Current fees value = '||fees_tab(p_ctx_original_entry_id));
1110 
1111     END IF;
1112 
1113     IF garn_category in ('BO','CD','G','EL','ER', 'DCIA') THEN
1114         /* -- Calculation for Garnishments' Deduction amount --*/
1115        IF garn_category = 'EL' THEN
1116             -- Bug# 4676867
1117             c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1118                                             GRN_DI_SUBJ_TX_ASG_GRE_RUN)
1119                                             - ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1120                                                + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN
1121                                                   - PR_TX_DED_SBJ_TX_ASG_GRE_RN)
1122                                             + (VOL_DEDN_ROTH_ASG_GRE_RUN
1123                                                - VOL_DEDN_SB_TX_ASG_GRE_RUN)
1124                                               );
1125            -- Bug 4079142
1126            -- Set flag to indicate Other Garnishment Deductions being taken
1127            GLB_OTHER_DI_FLAG := TRUE;
1128         ELSIF garn_category = 'DCIA' THEN
1129             GLB_DCIA_EXIST_FLAG := TRUE;
1130             -- Bug# 4676867
1131             c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1132                                             DCIA_DI_SUBJ_TX_ASG_GRE_RUN)
1133                                             - ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1134                                             + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN
1135                                                - PR_TX_DCIA_SB_TX_ASG_GRE_RN)
1136                                             + (VOL_DEDN_ROTH_ASG_GRE_RUN
1137                                                - VOL_DEDN_SB_TX_ASG_GRE_RUN)
1138                                             );
1139         ELSE
1140             -- Bug# 4676867
1141             --Added the below if for bug 14032248 State level inclusion of earnings for DI
1142             IF VOL_DEDN_SB_TX_JD_ASG_GRE_RUN <> 0 and VOL_DEDN_SB_TX_ASG_GRE_RUN = 0 THEN
1143              c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1144                                          LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
1145                                          ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1146                                          + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
1147                                            (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
1148                                          + (VOL_DEDN_ROTH_ASG_GRE_RUN - VOL_DEDN_SB_TX_JD_ASG_GRE_RUN )
1149                                           );
1150             ELSE
1151              c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1152                                          LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
1153                                          ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1154                                          + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
1155                                            (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
1156                                          + (VOL_DEDN_ROTH_ASG_GRE_RUN -
1157                                            (LEAST(VOL_DEDN_SB_TX_ASG_GRE_RUN,
1158                                                   VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)))
1159                                           );
1160             END IF;
1161            -- Bug 4079142
1162            -- Set flag to indicate Other Garnishment Deductions being taken
1163            GLB_OTHER_DI_FLAG := TRUE;
1164         END IF;
1165 
1166         calc_subprio := entry_subpriority;
1167         IF calc_subprio = 1 THEN
1168             IF date_served <> default_date THEN
1169                 calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - Date_Served);
1170             END IF;
1171         END IF;
1172 
1173         /* *** Calculation Section BEGIN *** */
1174         /*IF GARN_EXEMPTION_CALC_RULE = 'ONE_FED' OR
1175               GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_AMT' OR
1176               GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_PCT' OR
1177               GARN_EXEMPTION_CALC_RULE = 'ONE_MARSTAT_RULE' OR
1178               GARN_EXEMPTION_CALC_RULE = 'ONE_EXEMPT_BALANCE' THEN
1179             IF GARN_TOTAL_DEDNS_ASG_GRE_RUN = 0 THEN
1180                 IF REPLACEMENT_ASG_GRE_LTD <> 0 THEN
1181                     dedn_amt := REPLACEMENT_ASG_GRE_LTD;
1182                 ELSIF Amount <> 0 THEN
1183                     dedn_amt := Amount;
1184                 ELSIF Percentage <> 0 THEN
1185                     dedn_amt := (Percentage * c_Balance_Subject_to_Garn) / 100;
1186                 ELSE
1187                     dedn_amt := c_Balance_Subject_to_Garn;
1188                 END IF;
1189             ELSE
1190                 dedn_amt := 0;
1191                 STOP_ENTRY := 'Y';
1192                 calcd_dedn_amt := dedn_amt;
1193             END IF;*/
1194 
1195         /* *** Check for override to wage attachment deduction amount. *** */
1196 
1197         -- Bug# 5672067
1198         -- Reverting Back the Changes
1199         -- Changing for Special Input Element
1200 
1201         OPEN c_get_Replace_Amount_val('Replace Amt') ;
1202         FETCH c_get_Replace_Amount_val INTO ln_SI_Replace_Amt ;
1203         CLOSE c_get_Replace_Amount_val ;
1204         hr_utility.trace('ln_SI_Replace_Amt := '||ln_SI_Replace_Amt) ;
1205 
1206         IF ln_SI_Replace_Amt IS NOT NULL THEN
1207             dedn_amt := ln_SI_Replace_Amt ;
1208             IF dedn_amt < 0 THEN
1209                dedn_amt := 0 ;
1210             END IF ;
1211         ELSIF Amount <> 0 THEN
1212             dedn_amt := Amount;
1213 
1214         ELSIF Percentage <> 0 THEN
1215             -- Bug # 15844070, Percentage entered at element entry must be against the Gross Wages for IL - CD and G.
1216             IF SUBSTR(Jurisdiction,1,2) = '14' and garn_category in ('CD','G') THEN
1217                c_Gross_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN
1218                                            +LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN,
1219                                             DI_SUBJ_TAX_ASG_GRE_RUN));
1220                dedn_amt := (Percentage * c_Gross_Subject_to_Garn) / 100;
1221             ELSE
1222                dedn_amt := (Percentage * c_Balance_Subject_to_Garn) / 100;
1223             END IF;
1224         ELSE
1225             dedn_amt := c_Balance_Subject_to_Garn;
1226             GLB_AMT_NOT_SPEC(P_CTX_ORIGINAL_ENTRY_ID) := TRUE;
1227         END IF;
1228 
1229         /* *** Add in any adjustments. *** */
1230         IF ADDITIONAL_ASG_GRE_LTD <> 0 THEN
1231             dedn_amt := dedn_amt + ADDITIONAL_ASG_GRE_LTD;
1232         END IF;
1233 
1234         -- Bug 4072103
1235         -- Added code to recalculate DEDN_AMT if amount to be deducted
1236         -- overshoots TOTAL_OWED
1237         actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := dedn_amt;
1238 --changes for bug 9490973
1239     if not (SUBSTR(Jurisdiction,1,2) ='35' and garn_category in ('CD','G')) then
1240 --changes for bug 9490973
1241         IF TOTAL_OWED > 0 THEN
1242            IF ACCRUED_ASG_LTD + dedn_amt > TOTAL_OWED THEN
1243               -- Bug 4748532
1244               IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
1245                  actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := TOTAL_OWED - ACCRUED_ASG_LTD;
1246                  hr_utility.trace('Actual Deduction Amount = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
1247                  hr_utility.trace('Deduction Amount = ' || DEDN_AMT);
1248               ELSE
1249                  DEDN_AMT := TOTAL_OWED - ACCRUED_ASG_LTD;
1250               END IF;
1251            END IF;
1252         END IF;
1253     end if;
1254         gar_dedn_tab (P_CTX_ORIGINAL_ENTRY_ID) := dedn_amt;
1255 
1256     END IF;
1257     /*-----------------------------------------------------*/
1258 
1259     /*----------- Transfer input values to global variables --------------*/
1260     GLB_AMT(P_CTX_ORIGINAL_ENTRY_ID) := AMT;                             -- Amount
1261     GLB_ARREARS_OVERRIDE(P_CTX_ORIGINAL_ENTRY_ID) := ARREARS_OVERRIDE;   -- Arrears Dedn Amount
1262     GLB_ARREARS_DATE(P_CTX_ORIGINAL_ENTRY_ID) := ARREARS_DATE;           -- Date In Arrears
1263     GLB_NUM_DEPS(P_CTX_ORIGINAL_ENTRY_ID) := NUM_DEPS;                   -- Num Dependents
1264     GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) := FIL_STAT;                   -- Filing Status
1265     GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID) := ALLOWS;                       -- Allowances
1266     GLB_DEDN_OVERRIDE(P_CTX_ORIGINAL_ENTRY_ID) := DEDN_OVERRIDE;         -- Dedns at Time of Writ
1267     GLB_PCT(P_CTX_ORIGINAL_ENTRY_ID) := PERCENTAGE;                      -- Percentage
1268     GLB_MONTH_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID) := MONTHLY_CAP_AMOUNT;    -- Monthly Cap Amount
1269     GLB_MTD_BAL(P_CTX_ORIGINAL_ENTRY_ID) := ASG_MONTH;               -- Month To Date Balance
1270     GLB_EXEMPT_AMT(P_CTX_ORIGINAL_ENTRY_ID) := EXEMPT_AMT;               -- Exempt Amt BO
1271     GLB_PTD_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID) := PERIOD_CAP_AMOUNT;       -- Period Cap Amount
1272     GLB_PTD_BAL(P_CTX_ORIGINAL_ENTRY_ID) := ASG_PTD;                 -- Period To Date Balance
1273     GLB_TO_ACCRUED_FEES(P_CTX_ORIGINAL_ENTRY_ID) := TO_ACCRUED_FEES;     -- Accrued Fee Correction
1274     /*---------------------------------------------------------------------*/
1275     -- Fix for Bug 4143803 Starts here
1276     if garn_category = 'TL' then
1277 
1278         -- Bug 4104842
1279         -- Calculating the Gross earnings that can be used to calculate
1280         -- Tax Levy. This Gross amount becomes the maximum amount that Tax
1281         -- Levy can take. This is different from the GROSS_EARNINGS_ASG_GRE_RUN
1282         -- passed in the CAL_FORMULA_TL parameters as it calculates the
1283         -- Income that can be subjected for Tax Levy based on the Earning rules.
1284 
1285         c_Gross_Subject_to_Garn := REGULAR_EARNINGS_ASG_GRE_RUN
1286                                    + LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN);
1287 
1288         GLB_TL_GROSS_EARNINGS := c_Gross_Subject_to_Garn;
1289 
1290        -- Bug 4143803
1291        -- Get the value entered for the Input Value "Filing Status"
1292        -- in the element entry screen.
1293        -- If Filing Status is defaulted to 'XX' or '01',
1294        -- we need to correctly default the values
1295        --    i. '01' for elements created before the fix for 4143803
1296        --   ii. 'XX' for elements created after the fix for 4143803
1297        -- We correct the value of GLB_FIL_STAT to '01', if defaulted wrongly.
1298         b_default_flag := FALSE;
1299         open c_get_allowance_value('Filing Status');
1300         fetch c_get_allowance_value into lv_filing_status;
1301         close c_get_allowance_value;
1302         if FIL_STAT = '01' then
1303             -- If Allowances was defaulted then correct the default value to 1
1304             if lv_filing_status is NULL then
1305                 b_default_flag := TRUE;
1306             end if;
1307         elsif FIL_STAT = 'XX' then
1308             b_default_flag := TRUE;
1309         end if;
1310 
1311         -- Default value for Allowances. Modify here if the default value
1312         -- changes in future for Allowances
1313         if b_default_flag then
1314             GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) := '01';
1315             hr_utility.trace('Defaulting Filing Status for Tax Levy to ' || GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID));
1316         end if;
1317 
1318        -- Get the value entered for the Input Value "Allowances" and
1319        -- in the element entry screen.
1320        -- If Allowances is defaulted to '0' or '-9', we need to correctly
1321        -- default the values.
1322        --    i. '0' for elements created before the fix for 4143803
1323        --   ii. '-9' for elements created after the fix for 4143803
1324        -- Bug 4758841
1325        -- We correct the value of GLB_ALLOWS to
1326        --    i. '1' if Filing Status was defaulted too
1327        --   ii. '0' if Filing Status was not defaulted
1328 
1329         b_default_flag := FALSE;
1330         if ALLOWS = 0 then
1331             open c_get_allowance_value('Allowances');
1332             fetch c_get_allowance_value into lv_allow_value;
1333             close c_get_allowance_value;
1334 
1335             -- If Allowances was defaulted then correct the default value to 1
1336             if lv_allow_value is NULL then
1337                 b_default_flag := TRUE;
1338             end if;
1339         elsif ALLOWS = -9 then
1340             b_default_flag := TRUE;
1341         end if;
1342 
1343         -- Default value for Allowances. Modify here if the default value
1344         -- changes in future for Allowances
1345         -- Bug 4710692
1346         if b_default_flag then
1347            if lv_filing_status is NULL then
1348                GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID) := 1;
1349                hr_utility.trace('Defaulting Allowances for Tax Levy to ' || GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID));
1350            else
1351                GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID) := 0;
1352                hr_utility.trace('Defaulting Allowances for Tax Levy to ' || GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID));
1353            end if; -- if lv_filing_status
1354         end if; -- if b_default_flag
1355 
1356     end if;
1357 
1358     IF l_debug_on = 'Y' THEN
1359         hr_utility.trace('Return values ....');
1360         hr_utility.trace('ADDITIONAL_ASG_GRE_LTD = '||ADDITIONAL_ASG_GRE_LTD);
1361         hr_utility.trace('REPLACEMENT_ASG_GRE_LTD = '||REPLACEMENT_ASG_GRE_LTD);
1362         hr_utility.trace('ACCRUED_ASG_LTD = '||ACCRUED_ASG_LTD);
1363         hr_utility.trace('FEES_ENTRY_PTD = '||FEES_ENTRY_PTD);
1364         hr_utility.trace('FEES_ENTRY_ITD = '||FEES_ENTRY_ITD);
1365         hr_utility.trace('FEES_ENTRY_MONTH = '||FEES_ENTRY_MONTH);
1366         hr_utility.trace('DATE_SERVED = '||DATE_SERVED);
1367         --hr_utility.trace('VOLDEDNS_AT_WRIT = '||VOLDEDNS_AT_WRIT);
1368         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
1369     END IF;
1370 
1371     hr_utility.trace('Leaving '||l_proc_name);
1372     RETURN (0);
1373 END BASE_FORMULA;
1374 
1375 
1376   /****************************************************************************
1377     Name        : CAL_FORMULA_SS
1378     Description : This function performs DI calculation for involuntary
1379                   deduction elements of type AY/CS/SS. This function also
1380                   distributes the deducted amount over different elements
1381                   according to the proration rule defined.
1382   *****************************************************************************/
1383 
1384 FUNCTION CAL_FORMULA_SS
1385 (
1386     P_CTX_BUSINESS_GROUP_ID number,
1387     P_CTX_PAYROLL_ID number,
1388     P_CTX_ELEMENT_TYPE_ID number,
1389     P_CTX_ORIGINAL_ENTRY_ID number,
1390     P_CTX_DATE_EARNED date,
1391     P_CTX_JURISDICTION_CODE varchar2,
1392     P_CTX_ELEMENT_ENTRY_ID number,
1393     GARN_EXEMPTION_CALC_RULE varchar2,
1394     GARN_EXMPT_DEP_CALC_RULE varchar2,
1395     GARN_EXEMPTION_DI_PCT number,
1396     GARN_EXMPT_DI_PCT_IN_ARR number,
1397     GARN_EXMPT_DI_PCT_DEP number,
1398     GARN_EXMPT_DI_PCT_DEP_IN_ARR number,
1399     GARN_EXEMPTION_MIN_WAGE_FACTOR number,
1400     GARN_EXEMPTION_AMOUNT_VALUE number,
1401     GARN_EXMPT_DEP_AMT_VAL number,
1402     GARN_EXMPT_ADDL_DEP_AMT_VAL number,
1403     GARN_EXEMPTION_PRORATION_RULE varchar2,
1404     GARN_FEE_FEE_RULE varchar2,
1405     GARN_FEE_FEE_AMOUNT number,
1406     GARN_FEE_ADDL_GARN_FEE_AMOUNT number,
1407     GARN_FEE_PCT_CURRENT number,
1408     GARN_FEE_MAX_FEE_AMOUNT number,
1409     PAY_EARNED_START_DATE date,
1410     PAY_EARNED_END_DATE  date,
1411     SCL_ASG_US_WORK_SCHEDULE varchar2,
1412     ASG_HOURS number,
1413     ASG_FREQ varchar2,
1414     REGULAR_EARNINGS_ASG_GRE_RUN number,
1415     NET_ASG_GRE_RUN number,
1416     DI_SUBJ_TAX_JD_ASG_GRE_RUN number,
1417     PRE_TAX_DEDUCTIONS_ASG_GRE_RUN number,
1418     DI_SUBJ_TAX_ASG_GRE_RUN number,
1419     PRE_TAX_SUBJ_TX_ASG_GRE_RUN number,
1420     PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN number,
1421     TAX_DEDUCTIONS_ASG_GRE_RUN number,
1422     GARN_TOTAL_FEES_ASG_GRE_RUN number,
1423     JURISDICTION varchar2,
1424     TOTAL_OWED number,
1425     DATE_SERVED date,
1426     ADDITIONAL_AMOUNT_BALANCE number,
1427     REPLACEMENT_AMOUNT_BALANCE number,
1428     PRIMARY_AMOUNT_BALANCE number,
1429     ARREARS_AMOUNT_BALANCE number,
1430     SUPPORT_OTHER_FAMILY varchar2,
1431     ACCRUED_FEES number,
1432     PTD_FEE_BALANCE number,
1433     MONTH_FEE_BALANCE number,
1434     TAX_LEVIES_ASG_GRE_RUN number,
1435     TERMINATED_EMPLOYEE varchar2,
1436     FINAL_PAY_PROCESSED varchar2,
1437     CHILD_SUPP_COUNT_ASG_GRE_RUN number,
1438     CHILD_SUPP_TOT_DED_ASG_GRE_RUN IN OUT NOCOPY number,
1439     CHILD_SUPP_TOT_FEE_ASG_GRE_RUN number,
1440     TOTAL_WITHHELD_FEE_ASG_GRE_RUN number,
1441     TOTAL_WITHHELD_FEE_ASG_GRE_ITD number,
1442     TOT_WHLD_SUPP_ASG_GRE_RUN number,
1443     GARN_FEE_TAKE_FEE_ON_PRORATION varchar2,
1444     ARREARS_AMT IN OUT NOCOPY number,
1445     DIFF_DEDN_AMT IN OUT NOCOPY number,
1446     DIFF_FEE_AMT IN OUT NOCOPY number,
1447     NOT_TAKEN IN OUT NOCOPY number,
1448     SF_ACCRUED_FEES IN OUT NOCOPY number,
1449     STOP_ENTRY IN OUT NOCOPY varchar2,
1450     TO_COUNT IN OUT NOCOPY number,
1451     TO_TOTAL_OWED IN OUT NOCOPY number,
1452     WH_DEDN_AMT IN OUT NOCOPY number,
1453     WH_FEE_AMT IN OUT NOCOPY number,
1454     FATAL_MESG IN OUT NOCOPY varchar2,
1455     MESG IN OUT NOCOPY varchar2,
1456     CALC_SUBPRIO OUT NOCOPY number,
1457     TO_REPL OUT NOCOPY number,
1458     TO_ADDL OUT NOCOPY number,
1459     EIC_ADVANCE_ASG_GRE_RUN number default 0,
1460     VOL_DEDN_ROTH_ASG_GRE_RUN        number  default 0,
1461     VOL_DEDN_SB_TX_ASG_GRE_RUN       number  default 0,
1462     VOL_DEDN_SB_TX_JD_ASG_GRE_RUN    number  default 0
1463 
1464 ) RETURN number IS
1465 
1466     default_date date;
1467     default_string varchar2(11);
1468     default_number number;
1469     default_fee    number;
1470     c_Gross_Subject_to_Garn number;
1471     c_Balance_Subject_to_Garn number;
1472     c_Fed_Supp_xmpt_wks_in_Arrs number;
1473     c_Federal_Minimum_Wage number;
1474     dedn_amt number;
1475     calcd_arrears number;
1476     Total_DI number;
1477     fed_criteria_pct_prd_di_xmpt number;
1478     days_in_arrears number;
1479     fed_criteria_minwage_exemption number;
1480     fed_criteria_exemption number;
1481     DI_state_exemption_amt number;
1482     DI_state_dependents_exemption number;
1483     DI_state_weekly_exemption_amt number;
1484     DI_state_addl_pct_exempt number;
1485     DI_total_state_exemption number;
1486     DI_total_exemption number;
1487     DI_NC_exemption_amt_55 number;
1488     di_subj_NC45 number;
1489     DI_NC_exemption_amt_50 number;
1490     di_subj_nc50 number;
1491     supp_other_family varchar2(5);
1492     subject_disposable_income number;
1493     calcd_dedn_amt number;
1494     proration_rule varchar2(100);
1495     verify_dedn_amt number;
1496     verify_fee_amt number;
1497     verify_arrears_amt number;
1498     di_subj number;
1499     verify_jd_code varchar2(20);
1500     prim_bal number;
1501     total_owed_amt number;
1502     verif_date_served date;
1503     pr_accrued_fees number;
1504     pr_ptd_fee_bal number;
1505     pr_month_fee_bal number;
1506     dedn_ok varchar2(5);
1507     total_fees_run number;
1508     total_support_run number;
1509     total_child_supp_deduction number;
1510     excess_amt number;
1511     equal_dedn_amounts number;
1512     proportional_dedn_amount number;
1513     garn_days number;
1514     garn_days_end_per number;
1515     vf_calc_subprio number;
1516     vf_dedn_amt number;
1517     vf_di_subj number;
1518     vf_jd_code varchar2(20);
1519     vf_arrears_amount number;
1520     vf_fee_amt number;
1521     vf_prim_bal number;
1522     vf_total_owed_amt number;
1523     vf_date_served date;
1524     vf_di_subject_45 number;
1525     vf_di_subject_50 number;
1526     vf_supp_other_family varchar2(1);
1527     vf_accrued_fees number;
1528     vf_month_fee_bal number;
1529     vf_ptd_fee_bal number;
1530     fed_criteria_pct_wk_di_xmpt number;
1531     DI_state_wk_dep_exmpt number;
1532     DI_NC_weekly_exemption_amt_55 number;
1533     DI_NC_tot_prd_exmpt_55 number;
1534     DI_NC_weekly_exemption_amt_50 number;
1535     DI_NC_tot_prd_exmpt_50 number;
1536     DI_total_period_exemption number;
1537     calcd_fee number;
1538     garn_limit_days number;
1539     weekly_total_di number;
1540     vf_di_subj_arr number;
1541     total_support_run_arr number;
1542     wh_dedn_amt_arr number;
1543     vf_dedn_amt_arr number;
1544     INV_DED_OVR_GRN_EX_DI_PCT number;
1545     INV_DED_OVR_GRN_EX_DI_PCT_ARR number;
1546     INV_DED_OVR_GRN_EX_DI_PCT_DEP number;
1547     INV_DED_GRN_EX_DI_PCT_DEP_ARR number;
1548 
1549     amount number;
1550     arrears_dedn_amount number;
1551     date_in_arrears date;
1552     num_dependents number;
1553     filing_status varchar2(10);
1554     allowances number;
1555     dedns_at_time_of_writ number;
1556     percentage number;
1557     monthly_cap_amount number;
1558     month_to_date_balance number;
1559     period_cap_amount number;
1560     period_to_date_balance number;
1561     accrued_fee_correction number;
1562     cntr number;
1563 
1564     sub_prio_max number;
1565     calc_subprio_max number;
1566     l_debug_on varchar2(1);
1567     l_proc_name varchar2(50);
1568     l_proration_ovrd varchar2(15);
1569     l_garn_fee_max_fee_amt number;
1570     l_ini_fee_flag varchar2(10);
1571     lv_ele_name varchar2(100);
1572     ld_override_date date;
1573 
1574     CURSOR cur_debug is
1575         SELECT parameter_value
1576           FROM pay_action_parameters
1577          WHERE parameter_name = 'GARN_DEBUG_ON';
1578 
1579     CURSOR csr_get_ovrd_values(c_override_date date) is
1580         SELECT nvl(entry_information4, default_number),
1581                nvl(entry_information5, default_number),
1582                nvl(entry_information6, default_number),
1583                nvl(entry_information7, default_number)
1584           FROM pay_element_entries_f
1585          WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
1586            AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
1587            AND c_override_date BETWEEN effective_start_date and effective_end_date;
1588 
1589     /*-- Cursor for Bug 3704744 --*/
1590     CURSOR csr_get_proration_ovrd is
1591         select aei.aei_information3
1592           from per_assignment_extra_info aei,
1593                pay_element_entries_f pee
1594          where aei.assignment_id = pee.assignment_id
1595            and aei.information_type = 'US_PRORATION_RULE'
1596            and aei.aei_information_category = 'US_PRORATION_RULE'
1597            and aei.aei_information2 = garn_cat
1598            and substr(aei.aei_information1, 1, 2) = substr(P_CTX_JURISDICTION_CODE, 1, 2)
1599            and pee.element_entry_id = P_CTX_ORIGINAL_ENTRY_ID ;
1600 
1601     /* Cursot to return the Initial Fee Flag value Bug 3549298 */
1602     CURSOR csr_get_ini_fee_flag is
1603     SELECT nvl(entry_information9, 'N')
1604       FROM pay_element_entries_f
1605      WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
1606        AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
1607        AND P_CTX_DATE_EARNED BETWEEN effective_start_date and effective_end_date;
1608 
1609 
1610     /* Cursor for Bug 3715182 and 3719168 */
1611     CURSOR c_garn_max_fee_amt is
1612     select target.MAX_FEE_AMOUNT from
1613            PAY_US_GARN_FEE_RULES_F target,
1614            PAY_ELEMENT_TYPES_F pet
1615     WHERE target.state_code = substr(P_CTX_JURISDICTION_CODE,1,2)
1616       AND target.garn_category = pet.element_information1
1617       AND P_CTX_DATE_EARNED BETWEEN target.effective_start_date
1618                                 AND target.effective_end_date
1619       AND pet.element_type_id = P_CTX_ELEMENT_TYPE_ID
1620       AND P_CTX_DATE_EARNED BETWEEN pet.effective_start_date
1621                                 AND pet.effective_end_date;
1622 
1623 
1624     -- Bug 4079142
1625     -- Cursor to get the element name to be used in the message.
1626     CURSOR csr_get_ele_name (p_ele_type_id number) is
1627     select rtrim(element_name,' Calculator' )
1628       from pay_element_types_f
1629      where element_type_id = p_ele_type_id;
1630 
1631      -- Bug# 6132855
1632      -- Federal Minimum Wage now is stored in JIT table
1633      CURSOR c_get_federal_min_wage IS
1634      SELECT fed_information1
1635        FROM pay_us_federal_tax_info_f
1636       WHERE fed_information_category = 'WAGEATTACH LIMIT'
1637         AND P_CTX_DATE_EARNED BETWEEN effective_start_date
1638                                   AND effective_end_date;
1639 
1640 BEGIN
1641     l_proc_name := l_package_name||'CAL_FORMULA_SS';
1642     hr_utility.trace('Entering '||l_proc_name);
1643 
1644     default_date := fnd_date.canonical_to_date('0001/01/01');
1645     default_string := 'NOT ENTERED';
1646     default_number := -9999;
1647     INV_DED_OVR_GRN_EX_DI_PCT := default_number;
1648     INV_DED_OVR_GRN_EX_DI_PCT_ARR := default_number;
1649     INV_DED_OVR_GRN_EX_DI_PCT_DEP := default_number;
1650     INV_DED_GRN_EX_DI_PCT_DEP_ARR := default_number;
1651     amount := GLB_AMT(P_CTX_ORIGINAL_ENTRY_ID);
1652     arrears_dedn_amount := GLB_ARREARS_OVERRIDE(P_CTX_ORIGINAL_ENTRY_ID);
1653     date_in_arrears := GLB_ARREARS_DATE(P_CTX_ORIGINAL_ENTRY_ID);
1654     num_dependents := GLB_NUM_DEPS(P_CTX_ORIGINAL_ENTRY_ID);
1655     filing_status := GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID);
1656     allowances := GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID);
1657     dedns_at_time_of_writ := GLB_DEDN_OVERRIDE(P_CTX_ORIGINAL_ENTRY_ID);
1658     percentage := GLB_PCT(P_CTX_ORIGINAL_ENTRY_ID);
1659     monthly_cap_amount := GLB_MONTH_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
1660     month_to_date_balance := GLB_MTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
1661     period_cap_amount := GLB_PTD_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
1662     period_to_date_balance := GLB_PTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
1663     accrued_fee_correction := GLB_TO_ACCRUED_FEES(P_CTX_ORIGINAL_ENTRY_ID);
1664     sub_prio_max := 9999;
1665     calc_subprio_max := 1000000;
1666     l_garn_fee_max_fee_amt := NULL;
1667     default_fee := 99999999;
1668 
1669     OPEN cur_debug;
1670         FETCH cur_debug into l_debug_on;
1671     CLOSE cur_debug;
1672 
1673     /* Fetch the value of Initial Fee Flag value. Bug 3549298 */
1674     open csr_get_ini_fee_flag;
1675     fetch csr_get_ini_fee_flag into l_ini_fee_flag;
1676     close csr_get_ini_fee_flag;
1677 
1678     -- Fetching Federal Minimum Wage Value from JIT table
1679     OPEN c_get_federal_min_wage;
1680     FETCH c_get_federal_min_wage INTO c_Federal_Minimum_Wage;
1681     CLOSE c_get_federal_min_wage;
1682 
1683     IF l_debug_on = 'Y' THEN
1684         hr_utility.trace('Input parameters....');
1685         hr_utility.trace('P_CTX_BUSINESS_GROUP_ID = '||P_CTX_BUSINESS_GROUP_ID);
1686         hr_utility.trace('P_CTX_PAYROLL_ID = '||P_CTX_PAYROLL_ID);
1687         hr_utility.trace('P_CTX_ELEMENT_TYPE_ID = '||P_CTX_ELEMENT_TYPE_ID);
1688         hr_utility.trace('P_CTX_ORIGINAL_ENTRY_ID = '||P_CTX_ORIGINAL_ENTRY_ID);
1689         hr_utility.trace('P_CTX_DATE_EARNED = '||P_CTX_DATE_EARNED);
1690         hr_utility.trace('P_CTX_JURISDICTION_CODE = '||P_CTX_JURISDICTION_CODE);
1691         hr_utility.trace('P_CTX_ELEMENT_ENTRY_ID = '||P_CTX_ELEMENT_ENTRY_ID);
1692         hr_utility.trace('GARN_EXEMPTION_CALC_RULE = '||GARN_EXEMPTION_CALC_RULE);
1693         hr_utility.trace('GARN_EXMPT_DEP_CALC_RULE = '||GARN_EXMPT_DEP_CALC_RULE);
1694         hr_utility.trace('GARN_EXEMPTION_DI_PCT = '||GARN_EXEMPTION_DI_PCT);
1695         hr_utility.trace('GARN_EXMPT_DI_PCT_IN_ARR = '||GARN_EXMPT_DI_PCT_IN_ARR);
1696         hr_utility.trace('GARN_EXMPT_DI_PCT_DEP = '||GARN_EXMPT_DI_PCT_DEP);
1697         hr_utility.trace('GARN_EXMPT_DI_PCT_DEP_IN_ARR = '||GARN_EXMPT_DI_PCT_DEP_IN_ARR);
1698         hr_utility.trace('GARN_EXEMPTION_MIN_WAGE_FACTOR = '||GARN_EXEMPTION_MIN_WAGE_FACTOR);
1699         hr_utility.trace('GARN_EXEMPTION_AMOUNT_VALUE = '||GARN_EXEMPTION_AMOUNT_VALUE);
1700         hr_utility.trace('GARN_EXMPT_DEP_AMT_VAL = '||GARN_EXMPT_DEP_AMT_VAL);
1701         hr_utility.trace('GARN_EXMPT_ADDL_DEP_AMT_VAL = '||GARN_EXMPT_ADDL_DEP_AMT_VAL);
1702         hr_utility.trace('GARN_EXEMPTION_PRORATION_RULE = '||GARN_EXEMPTION_PRORATION_RULE);
1703         hr_utility.trace('GARN_FEE_FEE_RULE = '||GARN_FEE_FEE_RULE);
1704         hr_utility.trace('GARN_FEE_FEE_AMOUNT = '||GARN_FEE_FEE_AMOUNT);
1705         hr_utility.trace('GARN_FEE_ADDL_GARN_FEE_AMOUNT = '||GARN_FEE_ADDL_GARN_FEE_AMOUNT);
1706         hr_utility.trace('GARN_FEE_PCT_CURRENT = '||GARN_FEE_PCT_CURRENT);
1707         hr_utility.trace('GARN_FEE_MAX_FEE_AMOUNT = '||GARN_FEE_MAX_FEE_AMOUNT);
1708         hr_utility.trace('PAY_EARNED_START_DATE = '||PAY_EARNED_START_DATE);
1709         hr_utility.trace('PAY_EARNED_END_DATE = '||PAY_EARNED_END_DATE);
1710         hr_utility.trace('SCL_ASG_US_WORK_SCHEDULE = '||SCL_ASG_US_WORK_SCHEDULE);
1711         hr_utility.trace('ASG_HOURS = '||ASG_HOURS);
1712         hr_utility.trace('ASG_FREQ = '||ASG_FREQ);
1713         hr_utility.trace('REGULAR_EARNINGS_ASG_GRE_RUN = '||REGULAR_EARNINGS_ASG_GRE_RUN);
1714         hr_utility.trace('NET_ASG_GRE_RUN = '||NET_ASG_GRE_RUN);
1715         hr_utility.trace('DI_SUBJ_TAX_JD_ASG_GRE_RUN = '||DI_SUBJ_TAX_JD_ASG_GRE_RUN);
1716         hr_utility.trace('PRE_TAX_DEDUCTIONS_ASG_GRE_RUN = '||PRE_TAX_DEDUCTIONS_ASG_GRE_RUN);
1717         hr_utility.trace('DI_SUBJ_TAX_ASG_GRE_RUN = '||DI_SUBJ_TAX_ASG_GRE_RUN);
1718         hr_utility.trace('PRE_TAX_SUBJ_TX_ASG_GRE_RUN = '||PRE_TAX_SUBJ_TX_ASG_GRE_RUN);
1719         hr_utility.trace('PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN = '||PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN);
1720         hr_utility.trace('TAX_DEDUCTIONS_ASG_GRE_RUN = '||TAX_DEDUCTIONS_ASG_GRE_RUN);
1721         hr_utility.trace('GARN_TOTAL_FEES_ASG_GRE_RUN = '||GARN_TOTAL_FEES_ASG_GRE_RUN);
1722         hr_utility.trace('JURISDICTION = '||JURISDICTION);
1723         hr_utility.trace('TOTAL_OWED = '||TOTAL_OWED);
1724         hr_utility.trace('DATE_SERVED = '||DATE_SERVED);
1725         hr_utility.trace('ADDITIONAL_AMOUNT_BALANCE = '||ADDITIONAL_AMOUNT_BALANCE);
1726         hr_utility.trace('REPLACEMENT_AMOUNT_BALANCE = '||REPLACEMENT_AMOUNT_BALANCE);
1727         hr_utility.trace('PRIMARY_AMOUNT_BALANCE = '||PRIMARY_AMOUNT_BALANCE);
1728         hr_utility.trace('ARREARS_AMOUNT_BALANCE = '||ARREARS_AMOUNT_BALANCE);
1729         hr_utility.trace('SUPPORT_OTHER_FAMILY = '||SUPPORT_OTHER_FAMILY);
1730         hr_utility.trace('ACCRUED_FEES = '||ACCRUED_FEES);
1731         hr_utility.trace('PTD_FEE_BALANCE = '||PTD_FEE_BALANCE);
1732         hr_utility.trace('MONTH_FEE_BALANCE = '||MONTH_FEE_BALANCE);
1733         hr_utility.trace('TAX_LEVIES_ASG_GRE_RUN = '||TAX_LEVIES_ASG_GRE_RUN);
1734         hr_utility.trace('TERMINATED_EMPLOYEE = '||TERMINATED_EMPLOYEE);
1735         hr_utility.trace('FINAL_PAY_PROCESSED = '||FINAL_PAY_PROCESSED);
1736         hr_utility.trace('CHILD_SUPP_COUNT_ASG_GRE_RUN = '||CHILD_SUPP_COUNT_ASG_GRE_RUN);
1737         hr_utility.trace('CHILD_SUPP_TOT_DED_ASG_GRE_RUN = '||CHILD_SUPP_TOT_DED_ASG_GRE_RUN);
1738         hr_utility.trace('CHILD_SUPP_TOT_FEE_ASG_GRE_RUN = '||CHILD_SUPP_TOT_FEE_ASG_GRE_RUN);
1739         hr_utility.trace('TOTAL_WITHHELD_FEE_ASG_GRE_RUN = '||GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN);
1740         hr_utility.trace('TOTAL_WITHHELD_FEE_ASG_GRE_ITD = '||TOTAL_WITHHELD_FEE_ASG_GRE_ITD);
1741         hr_utility.trace('TOT_WHLD_SUPP_ASG_GRE_RUN = '||TOT_WHLD_SUPP_ASG_GRE_RUN);
1742         hr_utility.trace('GARN_FEE_TAKE_FEE_ON_PRORATION = '||GARN_FEE_TAKE_FEE_ON_PRORATION);
1743         hr_utility.trace('ARREARS_AMT = '||ARREARS_AMT);
1744         hr_utility.trace('DIFF_DEDN_AMT = '||DIFF_DEDN_AMT);
1745         hr_utility.trace('DIFF_FEE_AMT = '||DIFF_FEE_AMT);
1746         hr_utility.trace('NOT_TAKEN = '||NOT_TAKEN);
1747         hr_utility.trace('SF_ACCRUED_FEES = '||SF_ACCRUED_FEES);
1748         hr_utility.trace('STOP_ENTRY = '||STOP_ENTRY);
1749         hr_utility.trace('TO_COUNT = '||TO_COUNT);
1750         hr_utility.trace('TO_TOTAL_OWED = '||TO_TOTAL_OWED);
1751         hr_utility.trace('WH_DEDN_AMT = '||WH_DEDN_AMT);
1752         hr_utility.trace('WH_FEE_AMT = '||WH_FEE_AMT);
1753         hr_utility.trace('FATAL_MESG = '||FATAL_MESG);
1754         hr_utility.trace('MESG = '||MESG);
1755         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
1756         hr_utility.trace('TO_REPL = '||TO_REPL);
1757         hr_utility.trace('TO_ADDL = '||TO_ADDL);
1758         hr_utility.trace('EIC_ADVANCE_ASG_GRE_RUN = ' || EIC_ADVANCE_ASG_GRE_RUN);
1759         hr_utility.trace('INITIAL FEE FLAG ' || l_ini_fee_flag);
1760         hr_utility.trace('VOL_DEDN_ROTH_ASG_GRE_RUN = ' || VOL_DEDN_ROTH_ASG_GRE_RUN);
1761         hr_utility.trace('VOL_DEDN_SB_TX_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_ASG_GRE_RUN);
1762         hr_utility.trace('VOL_DEDN_SB_TX_JD_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_JD_ASG_GRE_RUN);
1763         hr_utility.trace('c_Federal_Minimum_Wage = ' || c_Federal_Minimum_Wage);
1764     END IF;
1765 
1766 
1767     /*--------- Set Contexts -------------*/
1768     CTX_BUSINESS_GROUP_ID := P_CTX_BUSINESS_GROUP_ID;
1769     CTX_PAYROLL_ID        := P_CTX_PAYROLL_ID;
1770     CTX_ELEMENT_TYPE_ID   := P_CTX_ELEMENT_TYPE_ID;
1771     CTX_ORIGINAL_ENTRY_ID := P_CTX_ORIGINAL_ENTRY_ID;
1772     CTX_DATE_EARNED       := P_CTX_DATE_EARNED;
1773     CTX_JURISDICTION_CODE := P_CTX_JURISDICTION_CODE;
1774     CTX_ELEMENT_ENTRY_ID  := P_CTX_ELEMENT_ENTRY_ID;
1775     /*------------------------------------*/
1776 
1777     GLB_NUM_ELEM := GLB_NUM_ELEM - 1;
1778     hr_utility.trace('GLB_NUM_ELEM = '|| GLB_NUM_ELEM);
1779 
1780     calc_subprio := entry_subpriority;
1781 
1782     c_Gross_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN
1783 	                	       +LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN, DI_SUBJ_TAX_ASG_GRE_RUN));
1784 
1785     -- Bug 4858720
1786     -- Use EIC_ADVANCE_ASG_GRE_RUN for calculatin the Deduction amount
1787     -- Bug# 4676867
1788     --Added the below if for bug 14032248 State level inclusion of earnings for DI
1789     IF VOL_DEDN_SB_TX_JD_ASG_GRE_RUN <> 0 and VOL_DEDN_SB_TX_ASG_GRE_RUN = 0 THEN
1790      c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1791                                    LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN, DI_SUBJ_TAX_ASG_GRE_RUN)) -
1792                                   ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1793                                   + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
1794                                   (LEAST(PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN,
1795                                    PRE_TAX_SUBJ_TX_ASG_GRE_RUN )))
1796                                   + (VOL_DEDN_ROTH_ASG_GRE_RUN - VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)
1797                                    );
1798     ELSE
1799      c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
1800                                    LEAST(DI_SUBJ_TAX_JD_ASG_GRE_RUN, DI_SUBJ_TAX_ASG_GRE_RUN)) -
1801                                   ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
1802                                   + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
1803                                   (LEAST(PRE_TAX_SUBJ_TX_JD_ASG_GRE_RUN,
1804                                    PRE_TAX_SUBJ_TX_ASG_GRE_RUN )))
1805                                   + (VOL_DEDN_ROTH_ASG_GRE_RUN -
1806                                     (LEAST(VOL_DEDN_SB_TX_ASG_GRE_RUN,
1807                                           VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)))
1808                                    );
1809 	END IF;
1810 
1811     c_Fed_Supp_xmpt_wks_in_Arrs := 12;  /* Multiply times 7 for days. */
1812     --c_Federal_Minimum_Wage := 5.15;  /* Current as of July 1996 */
1813 
1814     -- Bug 3800845
1815     -- Use the maximum of the 'Date Earned' and 'End Date' for finding
1816     -- the override values
1817     if P_CTX_DATE_EARNED > PAY_EARNED_END_DATE then
1818         ld_override_date := P_CTX_DATE_EARNED;
1819     else
1820         ld_override_date := PAY_EARNED_END_DATE;
1821     end if;
1822 
1823     /*-- Obtain overriding values --*/
1824     OPEN csr_get_ovrd_values(ld_override_date);
1825         FETCH csr_get_ovrd_values INTO
1826             INV_DED_OVR_GRN_EX_DI_PCT,
1827             INV_DED_OVR_GRN_EX_DI_PCT_ARR,
1828             INV_DED_OVR_GRN_EX_DI_PCT_DEP,
1829             INV_DED_GRN_EX_DI_PCT_DEP_ARR;
1830     CLOSE csr_get_ovrd_values;
1831 
1832     -- Bug 4079142
1833     -- Get the element name to be used in the message.
1834     open csr_get_ele_name(CTX_ELEMENT_TYPE_ID);
1835     fetch csr_get_ele_name into lv_ele_name;
1836     close csr_get_ele_name;
1837 
1838     /* Bug 3715182 and 3719168
1839      * Get the GARN_FEE_MAX_FEE_AMOUNT
1840      */
1841     open c_garn_max_fee_amt;
1842     fetch c_garn_max_fee_amt into l_garn_fee_max_fee_amt;
1843     close c_garn_max_fee_amt;
1844 
1845     if l_garn_fee_max_fee_amt is NULL then
1846        l_garn_fee_max_fee_amt := default_fee;
1847     else
1848        l_garn_fee_max_fee_amt := GARN_FEE_MAX_FEE_AMOUNT;
1849     end if;
1850 
1851 /* *** Support calculation section BEGIN *** */
1852 /*
1853    1. Find DISPOSABLE INCOME
1854       Calculate DI balance for child support according to current
1855       earnings and subject rules (ie. implemented via taxability rules).
1856    2. Calculate disposable income exemption according to:
1857       2.1 Standard federal criteria, ie. % Weekly DI and factor of minwage
1858           unless override exemption percentage is entered through
1859           element entries. Then use override exemption percentage.
1860       2.2 State specific legislation.
1861       2.3 Calculate disposable income exemption resulting from dependents.
1862       2.4 The most favorable exemption to employee is used.
1863    3. Calculate Subject_DISPOSABLE_INCOME = DI(#1) - #2 - #3 - Levies in place.
1864    4. Calculate total_child_supp_deduction = dedn_amt +
1865                                               CHILD_SUPP_TOT_DED_ASG_GRE_RUN
1866 */
1867 
1868     /* Step #1 */
1869 
1870     Total_DI := c_Balance_Subject_to_Garn;
1871 
1872     -- Bug 4079142
1873     -- Saving Total DI for use in DCIA deduction calculation
1874     if GLB_SUPPORT_DI is NULL then
1875        GLB_SUPPORT_DI := Total_DI;
1876     end if;
1877 
1878     /* Step #2 */
1879     /* NOTE: 95% child support exemptions are calculated by fed criteria only. */
1880     /* Step #2.1 Child support exemption by federal criteria. */
1881 
1882     IF Arrears_Amount_Balance = 0 THEN
1883         IF Support_Other_Family = 'N' THEN
1884             IF INV_DED_OVR_GRN_EX_DI_PCT = default_number THEN
1885                 fed_criteria_pct_prd_di_xmpt := (GARN_EXEMPTION_DI_PCT / 100) * Total_DI;
1886             ELSE
1887                 fed_criteria_pct_prd_di_xmpt := (TO_NUMBER(INV_DED_OVR_GRN_EX_DI_PCT) / 100) * Total_DI;
1888             END IF;
1889 
1890         ELSE
1891             IF INV_DED_OVR_GRN_EX_DI_PCT_DEP = default_number THEN
1892                 fed_criteria_pct_prd_di_xmpt := (GARN_EXMPT_DI_PCT_DEP / 100) * Total_DI;
1893             ELSE
1894                 fed_criteria_pct_prd_di_xmpt := (TO_NUMBER(INV_DED_OVR_GRN_EX_DI_PCT_DEP) / 100) * Total_DI;
1895             END IF;
1896         END IF;
1897 /*
1898     Else need to check balance in arrears against 12 weeks normal support payments.
1899     Are we sure this is the federal requirement?
1900     We could document NOT TO ENTER an arrears balance unless it were 12 weeks or more,
1901     in which case the current code would suffice...otherwise, convert the current period Amount
1902     (if any) to a weekly amount and multiply by 12; compare this figure with arrearage, make
1903     exemption percentage decision based on this comparison.
1904 */
1905     ELSIF Support_Other_Family = 'N' THEN
1906     -- Removed the Arrears date check as now court determines when arrears exist and
1907     -- issue a new order to the employer
1908     -- Bug 3692468
1909        IF INV_DED_OVR_GRN_EX_DI_PCT_ARR = default_number THEN
1910           fed_criteria_pct_prd_di_xmpt := (GARN_EXMPT_DI_PCT_IN_ARR / 100) * Total_DI;
1911        ELSE
1912           fed_criteria_pct_prd_di_xmpt := (TO_NUMBER(INV_DED_OVR_GRN_EX_DI_PCT_ARR) / 100) * Total_DI;
1913        END IF;
1914     ELSE
1915     -- Removed the Arrears date check as now court determines when arrears exist and
1916     -- issue a new order to the employer
1917     -- Bug 3692468
1918        IF INV_DED_GRN_EX_DI_PCT_DEP_ARR = default_number THEN
1919           fed_criteria_pct_prd_di_xmpt := (GARN_EXMPT_DI_PCT_DEP_IN_ARR / 100) * Total_DI;
1920        ELSE
1921           fed_criteria_pct_prd_di_xmpt := (TO_NUMBER(INV_DED_GRN_EX_DI_PCT_DEP_ARR) / 100) * Total_DI;
1922        END IF;
1923     END IF;
1924 
1925     fed_criteria_pct_wk_di_xmpt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
1926                                                         ASG_HOURS,
1927                                                         fed_criteria_pct_prd_di_xmpt,
1928                                                         'NOT ENTERED',
1929                                                         'WEEK',
1930                                                         PAY_EARNED_START_DATE,
1931                                                         PAY_EARNED_END_DATE,
1932                                                         ASG_FREQ);
1933 
1934     fed_criteria_minwage_exemption := GARN_EXEMPTION_MIN_WAGE_FACTOR * c_Federal_Minimum_Wage;
1935 
1936     fed_criteria_exemption := GREATEST(fed_criteria_pct_wk_di_xmpt, fed_criteria_minwage_exemption);
1937 
1938     hr_utility.trace('fed_criteria_pct_wk_di_xmpt = '||fed_criteria_pct_wk_di_xmpt);
1939     hr_utility.trace('fed_criteria_minwage_exemption = '||fed_criteria_minwage_exemption);
1940 
1941     /* Step #2.2 Child support exemption by state specific criteria. */
1942 
1943     DI_state_exemption_amt := 0;
1944     DI_state_dependents_exemption := 0;
1945     DI_state_weekly_exemption_amt := 0;
1946     DI_state_wk_dep_exmpt := 0;
1947 
1948     IF GARN_EXEMPTION_CALC_RULE = 'FEDRULE' THEN
1949         DI_state_weekly_exemption_amt := 0;
1950     ELSIF GARN_EXEMPTION_CALC_RULE = 'FLAT_AMT' THEN
1951         weekly_total_di := 0;
1952         IF SUBSTR(Jurisdiction, 1, 2) = '07' THEN
1953             /*weekly_total_DI calculated for  Bug 3561416*/
1954             weekly_total_di := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
1955                                                    ASG_HOURS,
1956                                                    Total_DI,
1957                                                    'NOT ENTERED',
1958                                                    'WEEK',
1959                                                    PAY_EARNED_START_DATE,
1960                                                    PAY_EARNED_END_DATE,
1961 	                                               ASG_FREQ);
1962 
1963             IF weekly_total_di  <= GARN_EXEMPTION_AMOUNT_VALUE THEN
1964                 DI_state_weekly_exemption_amt := ( weekly_total_di * 85 /100 );
1965             ELSE
1966                 DI_state_weekly_exemption_amt := ( GARN_EXEMPTION_AMOUNT_VALUE * 85 /100 );
1967             END IF;
1968         END IF;
1969     END IF;
1970 
1971     IF SUBSTR(Jurisdiction,1,2) <> '07' /*not equal to Connecticut*/ THEN
1972      /* This is quite exceptional case
1973        - ie. only CT specifies a $ amount exemption!
1974      */
1975         DI_state_weekly_exemption_amt := GARN_EXEMPTION_AMOUNT_VALUE;
1976     END IF;
1977 
1978 /* Step #2.3 : Note for child supports, this is also quite exceptional
1979                processing; currently only Deleware and Washington grant
1980                additional exemption amounts for having dependents.
1981 */
1982 
1983     IF GARN_EXMPT_DEP_CALC_RULE <> 'NONE' THEN
1984         IF GARN_EXMPT_DEP_CALC_RULE = 'FLAT_PCT' THEN
1985             DI_state_addl_pct_exempt := GARN_EXMPT_DEP_AMT_VAL * Num_Dependents;
1986             DI_state_dependents_exemption := (DI_state_addl_pct_exempt / 100) * Total_DI;
1987             DI_state_wk_dep_exmpt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
1988                                                          ASG_HOURS,
1989                                                          DI_state_dependents_exemption,
1990                                                          'NOT ENTERED',
1991                                                          'WEEK',
1992                                                          PAY_EARNED_START_DATE,
1993                                                          PAY_EARNED_END_DATE,
1994                                                          ASG_FREQ);
1995         ELSIF GARN_EXMPT_DEP_CALC_RULE = 'FLAT_AMT' THEN
1996             DI_state_wk_dep_exmpt := GARN_EXMPT_DEP_AMT_VAL * Num_Dependents;
1997 
1998         ELSIF GARN_EXMPT_DEP_CALC_RULE = 'FLAT_AMT_ADDL' THEN
1999             DI_state_wk_dep_exmpt := GARN_EXMPT_DEP_AMT_VAL +
2000                                     (GARN_EXMPT_ADDL_DEP_AMT_VAL *
2001                                     (Num_Dependents - 1));
2002 
2003         ELSIF GARN_EXMPT_DEP_CALC_RULE = 'FLAT_PCT_ADDL' THEN
2004             DI_state_addl_pct_exempt := GARN_EXMPT_DEP_AMT_VAL +
2005                                        (GARN_EXMPT_ADDL_DEP_AMT_VAL *
2006                                        (Num_Dependents - 1));
2007             DI_state_dependents_exemption := (DI_state_addl_pct_exempt / 100) * Total_DI;
2008             DI_state_wk_dep_exmpt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2009                                                          ASG_HOURS,
2010                                                          DI_state_dependents_exemption,
2011                                                          'NOT ENTERED',
2012                                                          'WEEK',
2013                                                          PAY_EARNED_START_DATE,
2014                                                          PAY_EARNED_END_DATE,
2015                                                          ASG_FREQ);
2016         END IF;
2017     END IF;
2018 
2019 
2020     DI_total_state_exemption := DI_state_weekly_exemption_amt +
2021                                 DI_state_wk_dep_exmpt;
2022 
2023 /* Step #2.4 */
2024 
2025     DI_total_exemption := GREATEST(fed_criteria_exemption,
2026                                    DI_total_state_exemption);
2027 
2028     hr_utility.trace('fed_criteria_exemption = '||fed_criteria_exemption);
2029     hr_utility.trace('DI_total_state_exemption = '||DI_total_state_exemption);
2030 
2031     IF SUBSTR(Jurisdiction, 1, 2) = '34' THEN
2032   /* Special state exemption calculation for North Carolina */
2033         DI_NC_exemption_amt_55 := (55 / 100) * Total_DI;
2034         DI_NC_weekly_exemption_amt_55 := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2035                                                              ASG_HOURS,
2036                                                              DI_NC_exemption_amt_55,
2037                                                              'NOT ENTERED',
2038                                                              'WEEK',
2039                                                              PAY_EARNED_START_DATE,
2040                                                              PAY_EARNED_END_DATE,
2041                                                              ASG_FREQ);
2042 
2043         DI_NC_tot_prd_exmpt_55 := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2044                                                       ASG_HOURS,
2045                                                       DI_NC_weekly_exemption_amt_55,
2046                                                       'WEEK',
2047                                                       'NOT ENTERED',
2048                                                       PAY_EARNED_START_DATE,
2049                                                       PAY_EARNED_END_DATE,
2050                                                       ASG_FREQ);
2051 
2052         di_subj_NC45 := Total_DI - DI_NC_tot_prd_exmpt_55;
2053         DI_NC_exemption_amt_50 := (50 / 100) * Total_DI;
2054 
2055         DI_NC_weekly_exemption_amt_50 := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2056                                                              ASG_HOURS,
2057                                                              DI_NC_exemption_amt_50,
2058                                                              'NOT ENTERED',
2059                                                              'WEEK',
2060                                                              PAY_EARNED_START_DATE,
2061                                                              PAY_EARNED_END_DATE,
2062                                                              ASG_FREQ);
2063 
2064         DI_NC_tot_prd_exmpt_50 := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2065                                                       ASG_HOURS,
2066                                                       DI_NC_weekly_exemption_amt_50,
2067                                                       'WEEK',
2068                                                       'NOT ENTERED',
2069                                                       PAY_EARNED_START_DATE,
2070                                                       PAY_EARNED_END_DATE,
2071                                                       ASG_FREQ);
2072 
2073         di_subj_NC50 := Total_DI - DI_NC_tot_prd_exmpt_50;
2074     END IF;
2075 /* Step #3 */
2076     supp_other_family := Support_Other_Family;
2077 
2078     /* The exemption amount so far is the amount exempt PER WEEK!
2079        So we convert it to a PER PAY PERIOD figure for calculating Subject DI. */
2080 
2081     DI_total_period_exemption := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
2082                                                      ASG_HOURS,
2083                                                      DI_total_exemption,
2084                                                      'WEEK',
2085                                                      'NOT ENTERED',
2086                                                      PAY_EARNED_START_DATE,
2087                                                      PAY_EARNED_END_DATE,
2088                                                      ASG_FREQ);
2089 
2090     hr_utility.trace('DI_total_period_exemption = '||DI_total_period_exemption);
2091     hr_utility.trace('DI_total_exemption = '||DI_total_exemption);
2092 
2093     Subject_DISPOSABLE_INCOME := Total_DI - DI_total_period_exemption;
2094 
2095     IF Total_Owed <> 0 THEN
2096         IF Primary_Amount_Balance - Period_to_date_balance < 0 THEN
2097             mesg := 'Total Owed already reached, no child support being withheld for ' || lv_ele_name || '.';
2098             dedn_amt := 0;
2099             calcd_dedn_amt := dedn_amt;
2100             calcd_fee := 0;
2101             calcd_arrears := 0;
2102             not_taken := 0;
2103             Subject_DISPOSABLE_INCOME := 0;
2104             di_subj_NC45 := 0;
2105             di_subj_NC50 := 0;
2106             to_count := 1;
2107 
2108             proration_rule := GARN_EXEMPTION_PRORATION_RULE;
2109             verify_dedn_amt := dedn_amt;
2110             verify_fee_amt := calcd_fee;
2111             verify_arrears_amt := 0;
2112             di_subj := Subject_DISPOSABLE_INCOME;
2113             verify_jd_code := Jurisdiction;
2114             prim_bal := Primary_Amount_Balance;
2115             total_owed_amt := Total_Owed;
2116             verif_date_served := Date_Served;
2117             sf_accrued_fees := accrued_fee_correction;
2118         END IF;
2119     END IF;
2120 
2121     IF Subject_DISPOSABLE_INCOME <= 0 THEN
2122         mesg := 'Disposable income is less than federal exemption, no child support being withheld for ' || lv_ele_name || '.';
2123         dedn_amt := 0;
2124         calcd_dedn_amt := dedn_amt;
2125         calcd_fee := 0;
2126         calcd_arrears := 0;
2127         not_taken := 0;
2128         Subject_DISPOSABLE_INCOME := 0;
2129         di_subj_NC45 := 0;
2130         di_subj_NC50 := 0;
2131         to_count := 1;
2132 
2133         proration_rule := GARN_EXEMPTION_PRORATION_RULE;
2134         verify_dedn_amt := dedn_amt;
2135         verify_fee_amt := calcd_fee;
2136         verify_arrears_amt := 0;
2137         di_subj := Subject_DISPOSABLE_INCOME;
2138         verify_jd_code := Jurisdiction;
2139         prim_bal := Primary_Amount_Balance;
2140         total_owed_amt := Total_Owed;
2141         verif_date_served := Date_Served;
2142         sf_accrued_fees := accrued_fee_correction;
2143 END IF;
2144 
2145 /* *** Support calculation section BEGIN *** */
2146 
2147 
2148 /* 15TH JULY 1996 : NOTICE!!!
2149 NOW that we have both dedn and fee amounts CALCULATED, need to
2150 pass to verification formula for legislative limit checks...
2151 When that is complete, the dedn amount and fee amounts can be
2152 fixed and returned appropriately...ie. to base element pay value
2153 and to fee element primary balance (ie. NOT via pay value for
2154 third party payment reasons).
2155 
2156 ALSO need to move negative net and stop entry checks into verification
2157 formula...ie. we can stop the base ele entry via the verifier just as
2158 easily as from the calculator.
2159 
2160 THIS IS A CONFIGURATION CHANGE!!!
2161 
2162 Total Owed change also...
2163 */
2164 
2165     to_count := 1;
2166 
2167     calcd_dedn_amt := dedn_tab(P_CTX_ORIGINAL_ENTRY_ID);
2168     verify_dedn_amt:= dedn_tab(P_CTX_ORIGINAL_ENTRY_ID);
2169     -- Bug 5149450
2170     -- Set the value of calcd_dedn_amt and verify_dedn_amt to the
2171     -- correct value. BASE_FORMULA only calculates an estimated value
2172     if GLB_AMT_NOT_SPEC(P_CTX_ORIGINAL_ENTRY_ID) then
2173        if dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) > Subject_DISPOSABLE_INCOME then
2174           calcd_dedn_amt := Subject_DISPOSABLE_INCOME;
2175           verify_dedn_amt:= Subject_DISPOSABLE_INCOME;
2176        end if; -- if
2177     end if;
2178     verify_arrears_amt := 0;
2179     verify_fee_amt := fees_tab(P_CTX_ORIGINAL_ENTRY_ID);
2180     di_subj := Subject_DISPOSABLE_INCOME;
2181     verify_jd_code := Jurisdiction;
2182     prim_bal := Primary_Amount_Balance;
2183     total_owed_amt := Total_Owed;
2184     verif_date_served := Date_Served;
2185 
2186     IF Accrued_Fees <> default_number THEN
2187         PR_Accrued_Fees := Accrued_Fees;
2188     ELSE
2189         PR_Accrued_Fees := 0;
2190     END IF;
2191 
2192     IF PTD_Fee_Balance <> default_number THEN
2193         PR_PTD_Fee_Bal := PTD_Fee_Balance;
2194     ELSE
2195         PR_PTD_Fee_Bal := 0;
2196     END IF;
2197 
2198     IF Month_Fee_Balance <> default_number THEN
2199         PR_Month_Fee_Bal := Month_Fee_Balance;
2200     ELSE
2201         PR_Month_Fee_Bal := 0;
2202     END IF;
2203 
2204     sf_accrued_fees := accrued_fee_correction;
2205 
2206     IF DI_SUBJ < CHILD_SUPP_TOT_DED_ASG_GRE_RUN AND
2207        GARN_EXEMPTION_PRORATION_RULE = 'EQUAL' THEN
2208         vf_calc_subprio := calc_subprio_max + (VERIFY_DEDN_AMT - DI_SUBJ);
2209     ELSE
2210         vf_calc_subprio := CALC_SUBPRIO;
2211     END IF;
2212 
2213     IF SUBSTR(VERIFY_JD_CODE,1,2) = '34' THEN
2214         IF CHILD_SUPP_COUNT_ASG_GRE_RUN > 1 THEN
2215             IF SUPP_OTHER_FAMILY = 'Y' THEN
2216                 DI_SUBJ := DI_SUBJ_NC45;
2217             ELSE
2218                 DI_SUBJ := DI_SUBJ_NC50;
2219             END IF;
2220         END IF;
2221     END IF;
2222 
2223     DI_SUBJ := DI_SUBJ - TAX_LEVIES_ASG_GRE_RUN;
2224 
2225     IF DI_SUBJ <= 0 THEN
2226         DI_SUBJ := 0;
2227     END IF;
2228 
2229     vf_dedn_amt          := VERIFY_DEDN_AMT;
2230     vf_di_subj           := DI_SUBJ;
2231     vf_jd_code           := VERIFY_JD_CODE;
2232     vf_arrears_amount    := VERIFY_ARREARS_AMT;
2233     vf_fee_amt           := VERIFY_FEE_AMT;
2234     vf_prim_bal          := PRIM_BAL;
2235     vf_total_owed_amt    := TOTAL_OWED_AMT;
2236     vf_date_served       := VERIF_DATE_SERVED;
2237     vf_di_subject_45     := DI_SUBJ_NC45;
2238     vf_di_subject_50     := DI_SUBJ_NC50;
2239     vf_supp_other_family := SUPP_OTHER_FAMILY;
2240 
2241     IF PR_ACCRUED_FEES <> default_number THEN
2242         VF_Accrued_Fees := PR_ACCRUED_FEES;
2243     ELSE
2244         VF_Accrued_Fees := 0;
2245     END IF;
2246 
2247     IF PR_PTD_FEE_BAL <> default_number THEN
2248         VF_PTD_Fee_Bal := PR_PTD_FEE_BAL;
2249     ELSE
2250         VF_PTD_Fee_Bal := 0;
2251     END IF;
2252 
2253     IF PR_MONTH_FEE_BAL <> default_number THEN
2254         VF_Month_Fee_Bal := PR_MONTH_FEE_BAL;
2255     ELSE
2256         VF_Month_Fee_Bal := 0;
2257     END IF;
2258 
2259 /*Algorithm:
2260 1.  Check individual support and total support deduction amounts against
2261     legislative limits.  Also perform negative net checks.
2262 2.  If necessary, check proration rule to recalculate child support
2263     deductions to either proportionally or equally share available
2264     disposable income.
2265 3.  Equally: divide available disposable income (ie. Subject_DI) by total
2266              number of child support payments to be made...
2267 4.  Proportionally: apportion Subject_DI into proportional amounts according
2268                     to scheduled child support deduction amounts...
2269                     ie. Subject_DI = 1000; childsupp A = 750;
2270                         childsupp B = 500;
2271 			Total child supp scheduled = 750 + 500 = 1250.
2272 			Childsupp A's proportion = 750 / 1250 = 60%
2273 			Childsupp B's proportion = 500 / 1250 = 40%
2274 			So divide available DI proportionally makes:
2275 			Childsupp A = 60% of 1000 = 600
2276 			Childsupp B = 40% of 1000 = 400
2277 			Make adjustments to originally calculated amounts as
2278 			appropriate.*/
2279 
2280 
2281 /* *** Legislative limit verification BEGIN *** */
2282 
2283 /*
2284    Fees have their own legislative limits...check these first
2285    then check that child support deduction plus fee amount
2286    is within legislative limits: ie. deduction + fees < DI_Subject
2287 
2288 */
2289     diff_dedn_amt :=0;
2290     diff_fee_amt :=0;
2291     dedn_ok := 'No';
2292 
2293 /* Check fee against leg limits... */
2294 
2295 /* Check child support fee against legislative maximum for time period. */
2296 
2297     calc_subprio := entry_subpriority;
2298     IF calc_subprio = 1 THEN
2299         IF VF_DATE_SERVED <> default_date THEN
2300             calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - VF_DATE_SERVED);
2301         END IF;
2302     END IF;
2303 
2304     wh_fee_amt := VF_FEE_AMT;
2305     --total_fees_run := CHILD_SUPP_TOT_FEE_ASG_GRE_RUN;
2306     total_fees_run := 0;
2307     cntr := fees_tab.first;
2308     WHILE cntr is not null LOOP
2309        total_fees_run := total_fees_run + fees_tab(cntr);
2310        cntr := fees_tab.NEXT(cntr);
2311     END LOOP;
2312 
2313     hr_utility.trace('GARN_FEE_MAX_FEE_AMOUNT = '||l_garn_fee_max_fee_amt);
2314     hr_utility.trace('GARN_FEE_FEE_RULE = '||GARN_FEE_FEE_RULE);
2315     hr_utility.trace('VF_ACCRUED_FEES ' || VF_ACCRUED_FEES);
2316 
2317 
2318     IF GARN_FEE_FEE_RULE = 'AMT_PER_GARN' OR
2319        GARN_FEE_FEE_RULE = 'AMT_PER_GARN_ADDL' OR
2320        GARN_FEE_FEE_RULE = 'PCT_PER_GARN' OR
2321        GARN_FEE_FEE_RULE = 'AMT_OR_PCT'  THEN
2322         IF l_garn_fee_max_fee_amt <> default_fee THEN
2323         /* Check that total fees collected are within legislative limit. */
2324             IF ( vf_accrued_fees + VF_FEE_AMT ) > l_garn_fee_max_fee_amt THEN /* 5249037 */
2325            /* Recalculate fee amount */
2326                 wh_fee_amt := l_garn_fee_max_fee_amt - vf_accrued_fees ; /* 5249037 */
2327                 IF wh_fee_amt < 0 THEN
2328                     wh_fee_amt := 0;
2329                 END IF;
2330                 total_fees_run := total_fees_run - VF_FEE_AMT + wh_fee_amt;
2331             END IF;
2332         ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_GARN_ADDL' THEN
2333             -- Bug 4748532
2334             wh_fee_amt := VF_FEE_AMT;
2335         END IF;
2336     ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD' OR
2337           GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD_ADDL' OR
2338           GARN_FEE_FEE_RULE = 'PCT_PER_PERIOD' THEN
2339         IF l_garn_fee_max_fee_amt <> default_number THEN
2340         /* Check that total fees collected are within legislative limit. */
2341             IF (VF_PTD_FEE_BAL + VF_FEE_AMT)  > l_garn_fee_max_fee_amt THEN
2342            /* Recalculate fee amount */
2343                 wh_fee_amt := l_garn_fee_max_fee_amt - VF_PTD_FEE_BAL;
2344                 IF wh_fee_amt < 0 THEN
2345                     wh_fee_amt := 0;
2346                 END IF;
2347                 total_fees_run := total_fees_run - VF_FEE_AMT + wh_fee_amt;
2348             END IF;
2349         END IF;
2350     ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_MONTH' OR
2351           GARN_FEE_FEE_RULE = 'AMT_PER_MONTH_ADDL' OR
2352           GARN_FEE_FEE_RULE = 'PCT_PER_MONTH' THEN
2353         IF l_garn_fee_max_fee_amt <> default_number THEN
2354             IF (VF_MONTH_FEE_BAL + VF_FEE_AMT + GLB_TOTAL_WHLD_SUPPP_FEE_MNTH)  > l_garn_fee_max_fee_amt THEN
2355            /* Recalculate fee amount */
2356                 wh_fee_amt := l_garn_fee_max_fee_amt - ( VF_MONTH_FEE_BAL + GLB_TOTAL_WHLD_SUPPP_FEE_MNTH );
2357                 IF wh_fee_amt < 0 THEN
2358                     wh_fee_amt := 0;
2359                 END IF;
2360                 total_fees_run := total_fees_run - VF_FEE_AMT + wh_fee_amt;
2361             END IF;
2362         END IF;
2363          GLB_TOTAL_WHLD_SUPPP_FEE_MNTH := GLB_TOTAL_WHLD_SUPPP_FEE_MNTH + VF_MONTH_FEE_BAL;
2364          /*  Variable GLB_TOTAL_WHLD_SUPPP_FEE_MNTH  captures the individual monthly balance for each
2365               garnishment fetched from the VF_MONTH_FEE_BAL parameter. This is to fix multiple garnishments
2366               and fee rule is per month.*/
2367     ELSIF GARN_FEE_FEE_RULE = 'AMT_PER_RUN' OR
2368           GARN_FEE_FEE_RULE = 'AMT_PER_RUN_ADDL' OR
2369           GARN_FEE_FEE_RULE = 'PCT_PER_RUN' THEN
2370         IF l_garn_fee_max_fee_amt <> default_number THEN
2371             --IF CHILD_SUPP_TOT_FEE_ASG_GRE_RUN > l_garn_fee_max_fee_amt THEN
2372             IF total_fees_run > l_garn_fee_max_fee_amt THEN
2373            /* Recalculate fee amount */
2374 	        -- Bug 5095823
2375                 wh_fee_amt := l_garn_fee_max_fee_amt - GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN;
2376                 IF wh_fee_amt < 0 THEN
2377                     wh_fee_amt := 0;
2378                 END IF;
2379                 total_fees_run := total_fees_run - VF_FEE_AMT + wh_fee_amt;
2380             END IF;
2381         END IF;
2382     END IF;
2383 
2384 /* Check against legislative limits for child support deduction:
2385 
2386    1. Check that total_child_supp_deduction + total fees
2387        is less than Subject_DISPOSABLE_INCOME
2388    2. If so, then dedn amounts ok
2389    3. If not, then
2390       3.1 Check GARN_EXEMPTION_PRORATION_RULE
2391       3.2 If rule is 'NONE' or 'ORDER_RECEIVED' then take dedns in
2392           order of receipt (ie. by subpriority until total dedns hits
2393           Subject_DISPOSABLE_INCOME.  Also have to adjust for current
2394           fees as well...then do we have to check fees against limits again!?
2395       3.3 If rule is 'PROPORTION' or 'EQUAL' then recalc appropriately.
2396 
2397 NOTE: We do not currently make any provisions for withholding all current
2398 support before arrearages, or alternatively all current plus support in
2399 order of receipt.  We do not make the distinction between current and
2400 arrearage withholding currently.  We could possibly using the arrears
2401 deduction amount input value...
2402 */
2403 
2404 
2405     --total_support_run := CHILD_SUPP_TOT_DED_ASG_GRE_RUN;
2406     total_support_run := 0;
2407     cntr := dedn_tab.first;
2408     WHILE cntr is not null LOOP
2409        hr_utility.trace('Deduction('||cntr||') = '||dedn_tab(cntr));
2410        total_support_run := total_support_run + dedn_tab(cntr);
2411        cntr := dedn_tab.NEXT(cntr);
2412     END LOOP; -- While Cntr is not null
2413 
2414     total_child_supp_deduction := total_support_run + total_fees_run;
2415 
2416     wh_dedn_amt := VF_DEDN_AMT;
2417     IF GLB_TOT_WHLD_SUPP_ASG_GRE_RUN IS NULL THEN
2418         GLB_TOT_WHLD_SUPP_ASG_GRE_RUN := 0;
2419     END IF;
2420 
2421     IF GLB_TOT_WHLD_ARR_ASG_GRE_RUN IS NULL THEN
2422         GLB_TOT_WHLD_ARR_ASG_GRE_RUN := 0;
2423     END IF;
2424 
2425     --hr_utility.trace('Total withheld fees = '|| GLB_TOT_WHLD_SUPP_ASG_GRE_RUN);
2426     hr_utility.trace('Current deduction amount = '|| vf_dedn_amt);
2427     hr_utility.trace('DI Subject = '|| vf_di_subj);
2428     hr_utility.trace('Proration Rule = '|| GARN_EXEMPTION_PRORATION_RULE);
2429 
2430     IF total_child_supp_deduction < VF_DI_SUBJ THEN
2431         dedn_ok := 'YES';
2432         wh_dedn_amt := VF_DEDN_AMT;
2433     ELSE
2434         IF total_support_run < VF_DI_SUBJ THEN
2435             dedn_ok := 'YES';
2436             wh_dedn_amt := VF_DEDN_AMT;
2437 	    -- Bug 5095823
2438             IF total_support_run + wh_fee_amt + GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN > VF_DI_SUBJ
2439                 AND GARN_FEE_TAKE_FEE_ON_PRORATION <> 'Y' THEN
2440                 wh_fee_amt := VF_DI_SUBJ - (total_support_run + GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN);
2441                 IF wh_fee_amt < 0 THEN
2442                     wh_fee_amt := 0;
2443                 END IF;
2444             END IF;
2445 
2446             -- Bug 5095823
2447             IF total_support_run + wh_fee_amt + GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN > VF_DI_SUBJ
2448                 AND GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2449                 excess_amt := VF_DI_SUBJ - (total_support_run + GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN);
2450                 IF excess_amt < 0 THEN
2451                     excess_amt := 0;
2452                 END IF;
2453                 IF wh_dedn_amt+excess_amt - wh_fee_amt > 0 THEN
2454                     not_taken := wh_dedn_amt - (wh_dedn_amt + excess_amt - wh_fee_amt);
2455                     wh_dedn_amt := wh_dedn_amt+excess_amt - wh_fee_amt;
2456                 ELSE
2457                     wh_fee_amt := 0;
2458                 END IF;
2459             END IF;
2460         ELSE
2461         -- Bug 3704744
2462         -- Use the overriden proration rule if overrided.
2463            OPEN csr_get_proration_ovrd;
2464               FETCH csr_get_proration_ovrd INTO l_proration_ovrd;
2465            CLOSE csr_get_proration_ovrd;
2466 
2467            IF l_proration_ovrd is null then
2468               l_proration_ovrd := GARN_EXEMPTION_PRORATION_RULE;
2469               hr_utility.trace ('Proration rule not overriden. Proceeding with proration rule = '||l_proration_ovrd);
2470            ELSE
2471               hr_utility.trace ('Proration rule overriden to '||l_proration_ovrd);
2472            END IF;
2473 
2474             /* total_support_run >= VF_DI_SUBJ */
2475                 IF l_proration_ovrd = 'NONE' OR
2476                    l_proration_ovrd = 'ORDER' THEN
2477                     wh_dedn_amt := VF_DEDN_AMT;
2478                 /*
2479                 Check when current deduction amounts exceed VF_DI_SUBJ...ie. withhold
2480                 in order received until di subject is reached, then shortpay any
2481                 remaining support payments.
2482                 */
2483 		    -- Bug 5095823
2484                     IF GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
2485                        GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN+
2486                        wh_dedn_amt > VF_DI_SUBJ THEN
2487                         wh_dedn_amt := VF_DI_SUBJ - ( GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
2488                                                       GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN );
2489                         IF wh_dedn_amt <= 0 THEN
2490                             wh_dedn_amt := 0;
2491                             wh_fee_amt := 0;
2492                             not_taken := VF_DI_SUBJ;
2493                             arrears_amt := not_taken;
2494                         ELSE
2495                             not_taken := VF_DI_SUBJ - wh_dedn_amt;
2496                             IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2497                                 IF wh_dedn_amt - wh_fee_amt > 0 THEN
2498                                     wh_dedn_amt := wh_dedn_amt - wh_fee_amt;
2499                                     not_taken := VF_DI_SUBJ - wh_dedn_amt;
2500                                 ELSE
2501                                     wh_fee_amt := 0;
2502                                 END IF;
2503                             ELSE
2504                                 wh_fee_amt := 0;
2505                             END IF;
2506                         END IF;
2507                     ELSE
2508 		        -- Bug 5095823
2509                         IF GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
2510                            GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN +
2511                            wh_dedn_amt +
2512                            wh_fee_amt > VF_DI_SUBJ THEN
2513                             IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2514                                 IF wh_dedn_amt - wh_fee_amt > 0 THEN
2515                                     wh_dedn_amt := wh_dedn_amt - wh_fee_amt;
2516                                     not_taken := VF_DI_SUBJ - wh_dedn_amt;
2517                                 ELSE
2518 				    -- Bug 5095823
2519                                     wh_fee_amt := VF_DI_SUBJ - ( GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
2520                                                                  GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN +
2521                                                                  wh_dedn_amt);
2522                                 END IF;
2523                             ELSE
2524 			        -- Bug 5095823
2525                                 wh_fee_amt := VF_DI_SUBJ - ( GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
2526                                                              GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN +
2527                                                              wh_dedn_amt);
2528                             END IF;
2529                         END IF;
2530                     END IF;
2531                 ELSE
2532                 IF l_proration_ovrd = 'EQUAL' THEN
2533                 -- Bug 3704744
2534                 -- Removed GLB_TOT_WHLD_SUPP_ASG_GRE_RUN from the calculation of dedn_amt to be
2535                 -- deducted as it will result in lesser amount to be deducted for every
2536                 -- further element processed
2537                 --  equal_dedn_amounts := (vf_di_subj - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN)/dedn_tab.count();
2538                     equal_dedn_amounts := vf_di_subj/dedn_tab.count();
2539                     IF VF_DI_SUBJ - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN <= 0 THEN
2540                         equal_dedn_amounts := 0 ;
2541                     ELSE
2542                         IF VF_DI_SUBJ-TOT_WHLD_SUPP_ASG_GRE_RUN-equal_dedn_amounts < 0 THEN
2543                             equal_dedn_amounts :=VF_DI_SUBJ -TOT_WHLD_SUPP_ASG_GRE_RUN;
2544                         END IF;
2545                     END IF;
2546                     -- Calling Function to get Prorated Amount (Reference Bug# 5295813)
2547 
2548                      wh_dedn_amt := GET_PRORATED_DEDN_AMOUNT(vf_di_subj, P_CTX_ORIGINAL_ENTRY_ID) ;
2549 
2550                     -- Commenting following part
2551                     --wh_dedn_amt := LEAST(equal_dedn_amounts,wh_dedn_amt);
2552                     not_taken := VF_DI_SUBJ - wh_dedn_amt;
2553                     arrears_amt := not_taken;
2554 
2555                     IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2556                         IF wh_dedn_amt - wh_fee_amt > 0 THEN
2557                             wh_dedn_amt := wh_dedn_amt - wh_fee_amt;
2558                             not_taken := VF_DI_SUBJ - wh_dedn_amt;
2559                         ELSE
2560                             wh_fee_amt := 0;
2561                         END IF;
2562                     ELSE
2563                         wh_fee_amt := 0;
2564                     END IF;
2565                 ELSE
2566                     IF l_proration_ovrd = 'PROPORTION' AND
2567                         total_support_run <> 0 THEN
2568                         -- Bug 5165704
2569                         -- Used dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) instead of
2570                         -- VF_DEDN_AMT for calculating the Proportional amount
2571                         -- VF_DEDN_AMT gets modified and as a result the proportional
2572                         -- amount gets incorrectly calculated
2573                         proportional_dedn_amount := (dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) / total_support_run) * VF_DI_SUBJ;
2574                         IF VF_DI_SUBJ - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN <= 0 THEN
2575                             proportional_dedn_amount := 0;
2576                         ELSE
2577                             IF VF_DI_SUBJ
2578                                 - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN
2579                                 - proportional_dedn_amount < 0 THEN
2580                                 proportional_dedn_amount := VF_DI_SUBJ - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN;
2581                             END IF;
2582                         END IF;
2583 
2584                         wh_dedn_amt := proportional_dedn_amount;
2585                         not_taken := VF_DI_SUBJ - wh_dedn_amt;
2586                         arrears_amt := not_taken;
2587 
2588                         hr_utility.trace ('DI Subject = "'||vf_di_subj||'"');
2589                         hr_utility.trace ('Deduction amount = "'||wh_dedn_amt||'"');
2590                         hr_utility.trace ('Not taken amount = "'||not_taken||'"');
2591                         hr_utility.trace ('Arrears amount = "'||arrears_amt||'"');
2592 
2593                         IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2594                             IF wh_dedn_amt - Wh_fee_amt > 0 THEN
2595                                 wh_dedn_amt := wh_dedn_amt - wh_fee_amt;
2596                                 not_taken := VF_DI_SUBJ - wh_dedn_amt;
2597                             ELSE
2598                                 wh_fee_amt := 0;
2599                             END IF;
2600                         ELSE
2601                                 wh_fee_amt := 0;
2602                         END IF;
2603                     END IF;
2604                 END IF;
2605             END IF;
2606         END IF;
2607     END IF;
2608 
2609     /* Proration for arrears (Bug 2992741) */
2610     IF arrears_tab.exists(P_CTX_ORIGINAL_ENTRY_ID) THEN
2611         VF_DEDN_AMT_ARR := arrears_tab(P_CTX_ORIGINAL_ENTRY_ID);
2612     ELSE
2613         VF_DEDN_AMT_ARR := 0;
2614     END IF;
2615 
2616     IF VF_DEDN_AMT_ARR > 0 THEN
2617         total_support_run_arr := 0;
2618         cntr := arrears_tab.first;
2619         WHILE cntr is not null LOOP
2620            hr_utility.trace('Arrears ('||cntr||') = '||arrears_tab(cntr));
2621            total_support_run_arr := total_support_run_arr + arrears_tab(cntr);
2622            cntr := arrears_tab.NEXT(cntr);
2623         END LOOP;
2624 
2625        -- Bug 2992741
2626        -- VF_DI_SUBJ_ARR := VF_DI_SUBJ - wh_dedn_amt - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN + GLB_TOT_WHLD_ARR_ASG_GRE_RUN;
2627           VF_DI_SUBJ_ARR := VF_DI_SUBJ - total_support_run;
2628 
2629             IF total_support_run_arr < VF_DI_SUBJ_ARR THEN
2630                 wh_dedn_amt_arr := VF_DEDN_AMT_ARR;
2631                 /*IF total_support_run_arr + wh_fee_amt + TOTAL_WITHHELD_FEE_ASG_GRE_RUN > VF_DI_SUBJ_ARR
2632                     AND GARN_FEE_TAKE_FEE_ON_PRORATION <> 'Y' THEN
2633                     wh_fee_amt := VF_DI_SUBJ_ARR - (total_support_run_arr + TOTAL_WITHHELD_FEE_ASG_GRE_RUN);
2634                     IF wh_fee_amt < 0 THEN
2635                         wh_fee_amt := 0;
2636                     END IF;
2637                 END IF;*/
2638 
2639                 /*IF total_support_run_arr + wh_fee_amt + TOTAL_WITHHELD_FEE_ASG_GRE_RUN > VF_DI_SUBJ_ARR
2640                     AND GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
2641                     excess_amt := VF_DI_SUBJ_ARR - (total_support_run_arr + TOTAL_WITHHELD_FEE_ASG_GRE_RUN);
2642                     IF excess_amt < 0 THEN
2643                         excess_amt := 0;
2644                     END IF;
2645                     IF wh_dedn_amt_arr+excess_amt - wh_fee_amt > 0 THEN
2646                         not_taken := wh_dedn_amt_arr - (wh_dedn_amt_arr + excess_amt - wh_fee_amt);
2647                         wh_dedn_amt_arr := wh_dedn_amt_arr+excess_amt - wh_fee_amt;
2648                     ELSE
2649                         wh_fee_amt := 0;
2650                     END IF;
2651                 END IF;*/
2652             ELSE
2653                 /* total_support_run_arr >= VF_DI_SUBJ_ARR */
2654                 -- Bug 2992741
2655                 IF VF_DI_SUBJ_ARR > 0 THEN
2656                    IF GARN_EXEMPTION_PRORATION_RULE = 'NONE' OR
2657                           GARN_EXEMPTION_PRORATION_RULE = 'ORDER' THEN
2658 
2659                            wh_dedn_amt_arr := VF_DEDN_AMT_ARR;
2660                            IF wh_dedn_amt_arr > VF_DI_SUBJ_ARR THEN
2661                                wh_dedn_amt_arr := VF_DI_SUBJ_ARR;
2662                            END IF;
2663                        ELSE
2664                        IF GARN_EXEMPTION_PRORATION_RULE = 'EQUAL' THEN
2665                            equal_dedn_amounts := VF_DI_SUBJ_ARR/arrears_tab.count();
2666                            wh_dedn_amt_arr := equal_dedn_amounts;
2667                        ELSE
2668                            IF GARN_EXEMPTION_PRORATION_RULE = 'PROPORTION' AND
2669                                total_support_run_arr <> 0 THEN
2670                                proportional_dedn_amount := (VF_DEDN_AMT_ARR / total_support_run_arr) * VF_DI_SUBJ_ARR;
2671                                /*IF VF_DI_SUBJ_ARR - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN <= 0 THEN
2672                                    proportional_dedn_amount := 0;
2673                                ELSE
2674                                    IF VF_DI_SUBJ_ARR
2675                                        - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN
2676                                        - proportional_dedn_amount < 0 THEN
2677                                        proportional_dedn_amount := VF_DI_SUBJ_ARR - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN;
2678                                    END IF;
2679                                END IF;*/
2680 
2681                                wh_dedn_amt_arr := proportional_dedn_amount;
2682 
2683                                hr_utility.trace ('Arrears DI Subject = "'||VF_DI_SUBJ_ARR||'"');
2684                                hr_utility.trace ('Arrears Deduction amount = "'||wh_dedn_amt_arr||'"');
2685                            END IF;
2686                        END IF;
2687                    END IF;
2688                 ELSE
2689                    wh_dedn_amt_arr := 0;
2690                 END IF;
2691                 -- Bug 2992741
2692                 -- Set the fee amount to ZERO in case of Proration
2693                 IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'N' then
2694                     wh_fee_amt := 0;
2695                     hr_utility.trace ('Setting Fee to Zero as GARN_FEE_TAKE_FEE_ON_PRORATION is N');
2696                 END IF;
2697             END IF;
2698     wh_dedn_amt := wh_dedn_amt + wh_dedn_amt_arr;
2699     hr_utility.trace('wh_dedn_amt = '||wh_dedn_amt);
2700     END IF;
2701 
2702     /*-----------------------*/
2703 
2704     -- Bug 4748532
2705     -- Deduct PTD amount for Garnishment and Fees if the value of
2706     -- GLB_FEES_ASG_GRE_PTD is not set to -9999(default_number) in BASE_FORMULA
2707     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
2708        hr_utility.trace('Deduction that can be taken = ' || WH_DEDN_AMT);
2709        hr_utility.trace('Deduction already taken     = ' || GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID));
2710        hr_utility.trace('Fees That can be taken      = ' || WH_FEE_AMT);
2711        hr_utility.trace('Fees already taken          = ' || GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID));
2712        IF WH_DEDN_AMT <= 0 THEN
2713            WH_FEE_AMT := 0;
2714        ELSIF WH_DEDN_AMT >= GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) THEN
2715           WH_DEDN_AMT := WH_DEDN_AMT - GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
2716        ELSE
2717           WH_DEDN_AMT := 0;
2718        END IF;
2719 
2720        IF WH_DEDN_AMT > actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) THEN
2721           WH_DEDN_AMT := actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID);
2722        END IF;
2723        IF WH_FEE_AMT >= 0 AND WH_FEE_AMT >= GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) THEN
2724           WH_FEE_AMT := WH_FEE_AMT - GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
2725        ELSE
2726           WH_FEE_AMT := 0;
2727        END IF;
2728     END IF; -- IF GLB_FEES_ASG_GRE_PTD
2729 
2730    -- Adding condition for checking wh_dedn_amt Against Monthly Cap
2731    hr_utility.trace('monthly_cap_amount := '||monthly_cap_amount);
2732    hr_utility.trace('month_to_date_balance := '||month_to_date_balance);
2733    IF monthly_cap_amount <> 0 THEN
2734       IF (monthly_cap_amount - month_to_date_balance) >= 0 THEN
2735            IF WH_DEDN_AMT > (monthly_cap_amount - month_to_date_balance) THEN
2736               WH_DEDN_AMT := monthly_cap_amount - month_to_date_balance;
2737            END IF;
2738       END IF;
2739    END IF;
2740    -- End of Addition for checking wh_dedn_amt Against Monthly Cap
2741 
2742    -- Adding condition for checking wh_dedn_amt Against Period Cap
2743    hr_utility.trace('period_cap_amount := '||monthly_cap_amount);
2744    hr_utility.trace('period_to_date_balance := '||month_to_date_balance);
2745    IF period_cap_amount <> 0 THEN
2746       IF (period_cap_amount - period_to_date_balance) >= 0 THEN
2747            IF WH_DEDN_AMT > (period_cap_amount - period_to_date_balance) THEN
2748               WH_DEDN_AMT := period_cap_amount - period_to_date_balance;
2749            END IF;
2750       END IF;
2751    END IF;
2752    -- End of Addition for checking wh_dedn_amt Against Period Cap
2753 
2754     /* *** Negative Net checks *** */
2755 
2756     IF NET_ASG_GRE_RUN - wh_dedn_amt - wh_fee_amt < 0 THEN
2757         IF NET_ASG_GRE_RUN - wh_dedn_amt > 0 THEN
2758       /* Part of fee makes net go negative, charge enough
2759          to make net = 0 */
2760             wh_fee_amt := NET_ASG_GRE_RUN - wh_dedn_amt;
2761             not_taken := VF_DI_SUBJ - wh_dedn_amt;
2762             arrears_amt := not_taken;
2763 
2764         ELSIF NET_ASG_GRE_RUN - wh_dedn_amt = 0 THEN
2765          /* Fee causes net to go negative, don't charge fee. */
2766             wh_fee_amt := 0;
2767             not_taken := VF_DI_SUBJ - wh_dedn_amt;
2768             arrears_amt := not_taken;
2769 
2770         ELSIF (NET_ASG_GRE_RUN - wh_dedn_amt < 0) AND (NET_ASG_GRE_RUN > 0) THEN
2771          /* Dedn amount itself causes net to go negative (? how ?),
2772             so don't charge a fee and take max available.
2773          */
2774             wh_fee_amt := 0;
2775             wh_dedn_amt := NET_ASG_GRE_RUN;
2776             not_taken := VF_DI_SUBJ - wh_dedn_amt;
2777             arrears_amt := not_taken;
2778         END IF;
2779     END IF;
2780 
2781 
2782 /* *** Negative Net checks end *** */
2783 
2784 -- Added below if for bug 13727976
2785 
2786 /* ***  Check if dedn + fee is > DI   ***    */
2787     IF vf_di_subj - wh_dedn_amt - wh_fee_amt < 0 THEN
2788       /* Part of fee makes total DI > subject DI,
2789       take enough to match total with DI */
2790 		wh_fee_amt := vf_di_subj - wh_dedn_amt;
2791 		hr_utility.trace('Fee is adjusted to match withholding limit : Deduction + Fee.');
2792     END IF;
2793 /* ***  Check if dedn + fee is > DI   ends ***    */
2794 
2795 /* *** Stop Rule Processing BEGIN *** */
2796 
2797     IF VF_TOTAL_OWED_AMT <> 0 THEN
2798         IF VF_TOTAL_OWED_AMT - VF_PRIM_BAL < 0 THEN
2799             fatal_mesg := 'Deduction Balance > Total Owed by $' ||TO_CHAR(VF_PRIM_BAL - VF_TOTAL_OWED_AMT ) || '. Adjust Balance for ' ||  lv_ele_name || '.';
2800             reset_global_var;
2801             RETURN (-1);
2802         ELSE
2803             IF VF_PRIM_BAL + wh_dedn_amt >= VF_TOTAL_OWED_AMT THEN
2804                 wh_dedn_amt := VF_TOTAL_OWED_AMT - VF_PRIM_BAL;
2805                     STOP_ENTRY := 'Y';
2806                     mesg := 'Support obligation has been satisfied because of Total Owed Reached for ' || lv_ele_name || '.';
2807                     IF VF_PRIM_BAL <> 0 THEN
2808                         to_total_owed := -1 * VF_PRIM_BAL;
2809                     ELSE
2810                         to_total_owed := 0;
2811                     END IF;
2812             ELSE
2813                     to_total_owed := wh_dedn_amt;
2814             END IF;
2815         END IF;
2816     ELSE
2817         to_total_owed := wh_dedn_amt;
2818     END IF;
2819 
2820     garn_limit_days := get_garn_limit_max_duration(PAY_EARNED_START_DATE);
2821 
2822    /*
2823     * Bug 3718454
2824     * Added 1 to the calculation of garn_days as the both
2825     * PAY_EARNED_END_DATE and VF_DATE_SERVED should be included for
2826     * calculating the STOP_ENTRY value.
2827     */
2828     IF garn_limit_days > 0 THEN
2829         garn_days := PAY_EARNED_END_DATE - VF_DATE_SERVED + 1;
2830         IF garn_days >= garn_limit_days THEN
2831             garn_days_end_per := PAY_EARNED_START_DATE - Date_Served + 1;
2832             /*
2833              * Added the IF condition te determine whether any amount needs
2834              * to be deducted.(Bug 3718454 and 3734415)
2835              * Bug 3777900 : Removed '=' sign from the IF condition below
2836              */
2837             IF garn_days_end_per > garn_limit_days THEN
2838                 STOP_ENTRY := 'Y';
2839                 WH_DEDN_AMT := 0;
2840                 WH_FEE_AMT := 0;
2841                 mesg := garn_limit_days || ' days Limit for element was reached before current pay period. No Deduction will be taken for ' || lv_ele_name || '. Element will be end dated';
2842                 IF VF_PRIM_BAL <> 0 THEN
2843                    to_total_owed := -1 * VF_PRIM_BAL;
2844                 ELSE
2845                    to_total_owed := 0;
2846                 END IF;
2847             ELSE
2848                 STOP_ENTRY := 'Y';
2849                 /* BUG 1752791 Added the following to reset the balance */
2850                 mesg := 'Support obligation has been satisfied for ' || lv_ele_name || ' because of Max Withholding Days Limit Reached.';
2851                 to_total_owed := -1 * Primary_Amount_Balance;
2852                 IF VF_PRIM_BAL <> 0 THEN
2853                    to_total_owed := -1 * VF_PRIM_BAL;
2854                 ELSE
2855                    to_total_owed := 0;
2856                 END IF;
2857             END IF;
2858         END IF;
2859     END IF;
2860 
2861 /* *** Stop Rule Processing END *** */
2862 
2863 -- Commented the following Final Pay section for Bug 4107302
2864 /* *** Final Pay Section BEGIN *** */
2865 /*
2866     IF (TERMINATED_EMPLOYEE = 'Y' AND FINAL_PAY_PROCESSED = 'N') THEN
2867         STOP_ENTRY := 'Y';
2868     END IF;
2869 */
2870 /* *** Final Pay Section END *** */
2871 
2872     -- Bug 4234046 and 4748532
2873     -- Set Fee Amount to ZERO when
2874     --- * No deduction is taken
2875     --  * We are not looking at PTD values for deducting Garnishment
2876     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) = default_number THEN
2877        IF WH_DEDN_AMT <= 0 THEN
2878            WH_FEE_AMT := 0;
2879        END IF;
2880     END IF;
2881 
2882 
2883     to_count := -1;
2884     SF_Accrued_Fees := wh_fee_amt;
2885 
2886     /*Bug 3500570*/
2887     IF NET_ASG_GRE_RUN > (VF_DI_SUBJ - GLB_TOT_WHLD_SUPP_ASG_GRE_RUN) AND total_support_run <> 0 THEN
2888         not_taken := 0;
2889     END IF;
2890 
2891     -- Bug 5095823
2892     GLB_TOT_WHLD_SUPP_ASG_GRE_RUN := GLB_TOT_WHLD_SUPP_ASG_GRE_RUN + wh_dedn_amt;
2893     GLB_TOT_WHLD_ARR_ASG_GRE_RUN := GLB_TOT_WHLD_ARR_ASG_GRE_RUN + wh_dedn_amt_arr;
2894     GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN := GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN + WH_FEE_AMT;
2895 
2896     -- Bug 14265307
2897     GLB_TOTAL_WHLD_SUPPP_FEE_MNTH := GLB_TOTAL_WHLD_SUPPP_FEE_MNTH + WH_FEE_AMT;
2898     IF l_debug_on = 'Y' THEN
2899         hr_utility.trace('Return values...');
2900         hr_utility.trace('CHILD_SUPP_TOT_DED_ASG_GRE_RUN = '||CHILD_SUPP_TOT_DED_ASG_GRE_RUN);
2901         hr_utility.trace('ARREARS_AMT = '||ARREARS_AMT);
2902         hr_utility.trace('DIFF_DEDN_AMT = '||DIFF_DEDN_AMT);
2903         hr_utility.trace('DIFF_FEE_AMT = '||DIFF_FEE_AMT);
2904         hr_utility.trace('NOT_TAKEN = '||NOT_TAKEN);
2905         hr_utility.trace('SF_ACCRUED_FEES = '||SF_ACCRUED_FEES);
2906         hr_utility.trace('STOP_ENTRY = '||STOP_ENTRY);
2907         hr_utility.trace('TO_COUNT = '||TO_COUNT);
2908         hr_utility.trace('TO_TOTAL_OWED = '||TO_TOTAL_OWED);
2909         hr_utility.trace('WH_DEDN_AMT = '||WH_DEDN_AMT);
2910         hr_utility.trace('WH_FEE_AMT = '||WH_FEE_AMT);
2911         hr_utility.trace('FATAL_MESG = '||FATAL_MESG);
2912         hr_utility.trace('MESG = '||MESG);
2913         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
2914         hr_utility.trace('TO_REPL = '||TO_REPL);
2915         hr_utility.trace('TO_ADDL = '||TO_ADDL);
2916     END IF;
2917 
2918     /*
2919      * Delete the GLOBAL tables once an employee is procesed
2920      */
2921     if GLB_NUM_ELEM = 0 then
2922        reset_global_var;
2923     end if;
2924     hr_utility.trace('Leaving '||l_proc_name);
2925     RETURN (0);
2926 
2927 END CAL_FORMULA_SS;
2928 
2929 
2930   /****************************************************************************
2931     Name        : ENTRY_SUBPRIORITY
2932     Description : This function return sub-priority of specified
2933                   element_entry_id.
2934   *****************************************************************************/
2935 
2936 FUNCTION ENTRY_SUBPRIORITY RETURN number IS
2937 BEGIN
2938     RETURN (pay_wat_udfs.entry_subpriority(CTX_DATE_EARNED, CTX_ELEMENT_ENTRY_ID));
2939 END ENTRY_SUBPRIORITY;
2940 
2941   /****************************************************************************
2942     Name        : CONVERT_PERIOD_TYPE
2943     Description : This function converts amount according to the time units
2944                   specified.
2945   *****************************************************************************/
2946 
2947 FUNCTION CONVERT_PERIOD_TYPE
2948 (
2949     SCL_ASG_US_WORK_SCHEDULE varchar2,
2950     ASG_HOURS number,
2951     FED_CRITERIA_PCT_PRD_DI_XMPT number,
2952     P_FROM_FREQ varchar2,
2953     P_TO_FREQ varchar2,
2954     PAY_EARNED_START_DATE date,
2955     PAY_EARNED_END_DATE date,
2956     P_ASST_STD_FREQ varchar2
2957 )
2958 RETURN number IS
2959 
2960 -- **********************************************************************
2961 -- **********************************************************************
2962 
2963 /* Introducing following Private function to be used to
2964    replace hr_us_ff_udfs.convert_period_type function call
2965 */
2966 
2967 FUNCTION Garn_Convert_Period_Type(
2968 		p_bus_grp_id		in NUMBER,
2969 		p_payroll_id		in NUMBER,
2970 		p_asst_work_schedule	in VARCHAR2,
2971 		p_asst_std_hours	      in NUMBER,
2972 		p_figure		      in NUMBER,
2973 		p_from_freq		      in VARCHAR2,
2974 		p_to_freq		      in VARCHAR2,
2975 		p_period_start_date	in DATE,
2976 		p_period_end_date	      in DATE,
2977 		p_asst_std_freq		in VARCHAR2)
2978 
2979 RETURN NUMBER IS
2980 
2981 -- local variables
2982 v_calc_type                  VARCHAR2(50);
2983 v_from_stnd_factor           NUMBER(30,7);
2984 v_stnd_start_date            DATE;
2985 v_converted_figure           NUMBER(27,7);
2986 v_from_annualizing_factor    NUMBER(30,7);
2987 v_to_annualizing_factor	     NUMBER(30,7);
2988 
2989 CURSOR get_asg_hours_freq(cp_date_earned date,
2990                         cp_assignment_id number) IS
2991   SELECT hr_general.decode_lookup('FREQUENCY', ASSIGN.frequency)
2992         ,ASSIGN.normal_hours
2993   FROM  per_all_assignments_f ASSIGN
2994   where cp_date_earned BETWEEN ASSIGN.effective_start_date
2995   AND ASSIGN.effective_end_date
2996   and ASSIGN.assignment_id = cp_assignment_id
2997   and UPPER(ASSIGN.frequency) = 'W';
2998 
2999 -- local functions
3000 
3001 FUNCTION Get_Annualizing_Factor(p_bg	in NUMBER,
3002 				p_payroll		in NUMBER,
3003 				p_freq		in VARCHAR2,
3004 				p_asg_work_sched	in VARCHAR2,
3005 				p_asg_std_hrs	in NUMBER,
3006 				p_asg_std_freq	in VARCHAR2)
3007 RETURN NUMBER IS
3008 
3009 -- local constants
3010 
3011 c_weeks_per_year	NUMBER(3);
3012 c_days_per_year	NUMBER(3);
3013 c_months_per_year	NUMBER(3);
3014 
3015 -- local variables
3016 /* 353434, 368242 : Fixed number width for total hours variables */
3017 
3018 v_annualizing_factor	NUMBER(30,7);
3019 v_periods_per_fiscal_yr	NUMBER(5);
3020 v_hrs_per_wk		NUMBER(15,7);
3021 v_hrs_per_range		NUMBER(15,7);
3022 v_use_pay_basis	NUMBER(1);
3023 v_pay_basis		VARCHAR2(80);
3024 v_range_start		DATE;
3025 v_range_end		DATE;
3026 v_work_sched_name	VARCHAR2(80);
3027 v_ws_id			NUMBER(9);
3028 v_period_hours		BOOLEAN;
3029 
3030 BEGIN -- Get_Annualizing_Factor
3031 
3032   /* Init */
3033 
3034 c_weeks_per_year   := 52;
3035 c_days_per_year    := 200;
3036 c_months_per_year  := 12;
3037 v_use_pay_basis	   := 0;
3038 --
3039 -- Check for use of salary admin (ie. pay basis) as frequency.
3040 -- Selecting "count" because we want to continue processing even if
3041 -- the from_freq is not a pay basis.
3042 --
3043 
3044  hr_utility.trace('  Entered  Get_Annualizing_Factor ');
3045 
3046  BEGIN	-- Is Freq pay basis?
3047 
3048   --
3049   -- Decode pay basis and set v_annualizing_factor accordingly.
3050   -- PAY_BASIS "Meaning" is passed from FF !
3051   --
3052 
3053   hr_utility.trace('  Getting lookup code for lookup_type = PAY_BASIS');
3054   hr_utility.trace('  p_freq ='||p_freq);
3055 
3056   SELECT	lookup_code
3057   INTO		v_pay_basis
3058   FROM		hr_lookups	 	lkp
3059   WHERE 	lkp.application_id	= 800
3060   AND		lkp.lookup_type		= 'PAY_BASIS'
3061   AND		lkp.meaning		= p_freq;
3062 
3063   hr_utility.trace('  Lookup_code ie v_pay_basis ='||v_pay_basis);
3064   v_use_pay_basis := 1;
3065 
3066   IF v_pay_basis = 'MONTHLY' THEN
3067 
3068     hr_utility.trace('  Entered for MONTHLY v_pay_basis');
3069 
3070     v_annualizing_factor := 12;
3071 
3072     hr_utility.trace(' v_annualizing_factor = 12 ');
3073   ELSIF v_pay_basis = 'HOURLY' THEN
3074 
3075       hr_utility.trace('  Entered for HOURLY v_pay_basis');
3076 
3077       IF p_period_start_date IS NOT NULL THEN
3078 
3079       hr_utility.trace('  p_period_start_date IS NOT NULL v_period_hours=T');
3080         v_range_start 	:= p_period_start_date;
3081         v_range_end	:= p_period_end_date;
3082         v_period_hours	:= TRUE;
3083       ELSE
3084 
3085       hr_utility.trace('  p_period_start_date IS NULL');
3086 
3087         v_range_start 	:= sysdate;
3088         v_range_end	:= sysdate + 6;
3089         v_period_hours 	:= FALSE;
3090       END IF;
3091 
3092       IF UPPER(p_asg_work_sched) <> 'NOT ENTERED' THEN
3093 
3094       -- Hourly employee using work schedule.
3095       -- Get work schedule name
3096 
3097       hr_utility.trace('  Hourly employee using work schedule');
3098       hr_utility.trace('  Get work schedule name');
3099 
3100          v_ws_id := fnd_number.canonical_to_number(p_asg_work_sched);
3101 
3102       hr_utility.trace('  v_ws_id ='||to_number(v_ws_id));
3103 
3104 
3105         SELECT	user_column_name
3106         INTO	v_work_sched_name
3107         FROM	pay_user_columns
3108         WHERE	user_column_id 			= v_ws_id
3109         AND	NVL(business_group_id, p_bg) 	= p_bg
3110   	AND     NVL(legislation_code,'US')      = 'US';
3111 
3112          hr_utility.trace('  v_work_sched_name ='||v_work_sched_name);
3113          hr_utility.trace('  Calling hr_us_ff_udfs.Work_Schedule_Total_Hours');
3114 
3115          v_hrs_per_range := hr_us_ff_udfs.Work_Schedule_Total_Hours(	p_bg,
3116 							v_work_sched_name,
3117 							v_range_start,
3118 							v_range_end);
3119 
3120       ELSE-- Hourly emp using Standard Hours on asg.
3121 
3122          hr_utility.trace('  Hourly emp using Standard Hours on asg');
3123 
3124 
3125          hr_utility.trace('  calling hr_us_ff_udfs.Standard_Hours_Worked');
3126          v_hrs_per_range := hr_us_ff_udfs.Standard_Hours_Worked(	p_asg_std_hrs,
3127 						v_range_start,
3128 						v_range_end,
3129 						p_asg_std_freq);
3130 
3131       END IF;
3132 
3133       IF v_period_hours THEN
3134 
3135          hr_utility.trace('  v_period_hours is TRUE');
3136 
3137          select TPT.number_per_fiscal_year
3138           into    v_periods_per_fiscal_yr
3139           from   pay_payrolls_f  PPF,
3140                  per_time_period_types TPT,
3141                  fnd_sessions fs
3142          where  PPF.payroll_id = p_payroll
3143          and    fs.session_id = USERENV('SESSIONID')
3144          and    fs.effective_date between PPF.effective_start_date and PPF.effective_end_date
3145             and   TPT.period_type = PPF.period_type;
3146 
3147          v_annualizing_factor := v_hrs_per_range * v_periods_per_fiscal_yr;
3148 
3149       ELSE
3150 
3151          v_annualizing_factor := v_hrs_per_range * c_weeks_per_year;
3152 
3153       END IF;
3154 
3155   ELSIF v_pay_basis = 'PERIOD' THEN
3156 
3157     hr_utility.trace('  v_pay_basis = PERIOD');
3158 
3159     SELECT  TPT.number_per_fiscal_year
3160     INTO        v_annualizing_factor
3161     FROM    pay_payrolls_f          PRL,
3162             per_time_period_types   TPT,
3163             fnd_sessions            fs
3164     WHERE   TPT.period_type         = PRL.period_type
3165     and     fs.session_id = USERENV('SESSIONID')
3166     and     fs.effective_date  BETWEEN PRL.effective_start_date
3167                           AND PRL.effective_end_date
3168     AND     PRL.payroll_id          = p_payroll
3169     AND     PRL.business_group_id + 0   = p_bg;
3170 
3171 
3172   ELSIF v_pay_basis = 'ANNUAL' THEN
3173 
3174 
3175     hr_utility.trace('  v_pay_basis = ANNUAL');
3176     v_annualizing_factor := 1;
3177 
3178   ELSE
3179 
3180     -- Did not recognize "pay basis", return -999 as annualizing factor.
3181     -- Remember this for debugging when zeroes come out as results!!!
3182 
3183     hr_utility.trace('  Did not recognize pay basis');
3184 
3185     v_annualizing_factor := 0;
3186     RETURN v_annualizing_factor;
3187 
3188   END IF;
3189 
3190  EXCEPTION
3191 
3192   WHEN NO_DATA_FOUND THEN
3193 
3194     hr_utility.trace('  When no data found' );
3195     v_use_pay_basis := 0;
3196 
3197  END; /* SELECT LOOKUP CODE */
3198 
3199 IF v_use_pay_basis = 0 THEN
3200 
3201     hr_utility.trace('  Not using pay basis as frequency');
3202 
3203   -- Not using pay basis as frequency...
3204 
3205   IF (p_freq IS NULL) 			OR
3206      (UPPER(p_freq) = 'PERIOD') 		OR
3207      (UPPER(p_freq) = 'NOT ENTERED') 	THEN
3208 
3209     -- Get "annuallizing factor" from period type of the payroll.
3210 
3211     hr_utility.trace('Get annuallizing factor from period type of the payroll');
3212 
3213     SELECT  TPT.number_per_fiscal_year
3214     INTO    v_annualizing_factor
3215     FROM    pay_payrolls_f          PRL,
3216             per_time_period_types   TPT,
3217             fnd_sessions            fs
3218     WHERE   TPT.period_type         = PRL.period_type
3219     and     fs.session_id = USERENV('SESSIONID')
3220     and     fs.effective_date  BETWEEN PRL.effective_start_date
3221                           AND PRL.effective_end_date
3222     AND     PRL.payroll_id          = p_payroll
3223     AND     PRL.business_group_id + 0   = p_bg;
3224 
3225     hr_utility.trace('v_annualizing_factor ='||to_number(v_annualizing_factor));
3226 
3227   ELSIF UPPER(p_freq) <> 'HOURLY' THEN
3228 
3229     -- Not hourly, an actual time period type!
3230    hr_utility.trace('Not hourly - an actual time period type');
3231 
3232    BEGIN
3233 
3234     hr_utility.trace(' selecting from per_time_period_types');
3235 
3236     SELECT	PT.number_per_fiscal_year
3237     INTO		v_annualizing_factor
3238     FROM	per_time_period_types 	PT
3239     WHERE	UPPER(PT.period_type) 	= UPPER(p_freq);
3240 
3241     hr_utility.trace('v_annualizing_factor ='||to_number(v_annualizing_factor));
3242 
3243    EXCEPTION when NO_DATA_FOUND then
3244 
3245      -- Added as part of SALLY CLEANUP.
3246      -- Could have been passed in an ASG_FREQ dbi which might have the values of
3247      -- 'Day' or 'Month' which do not map to a time period type.  So we'll do these by hand.
3248 
3249       IF UPPER(p_freq) = 'DAY' THEN
3250         hr_utility.trace('  p_freq = DAY');
3251         v_annualizing_factor := c_days_per_year;
3252       ELSIF UPPER(p_freq) = 'MONTH' THEN
3253         v_annualizing_factor := c_months_per_year;
3254         hr_utility.trace('  p_freq = MONTH');
3255       END IF;
3256 
3257     END;
3258 
3259   ELSE  -- Hourly employee...
3260      hr_utility.trace('  Hourly Employee');
3261 
3262      IF p_period_start_date IS NOT NULL THEN
3263         v_range_start 	:= p_period_start_date;
3264         v_range_end	:= p_period_end_date;
3265         v_period_hours	:= TRUE;
3266      ELSE
3267         v_range_start 	:= sysdate;
3268         v_range_end	:= sysdate + 6;
3269         v_period_hours 	:= FALSE;
3270      END IF;
3271 
3272      IF UPPER(p_asg_work_sched) <> 'NOT ENTERED' THEN
3273 
3274     -- Hourly emp using work schedule.
3275     -- Get work schedule name:
3276 
3277         v_ws_id := fnd_number.canonical_to_number(p_asg_work_sched);
3278 
3279         SELECT	user_column_name
3280         INTO	v_work_sched_name
3281         FROM	pay_user_columns
3282         WHERE	user_column_id 			= v_ws_id
3283         AND	NVL(business_group_id, p_bg) 	= p_bg
3284   	AND     NVL(legislation_code,'US')      = 'US';
3285 
3286 
3287         v_hrs_per_range := hr_us_ff_udfs.WORK_SCHEDULE_TOTAL_HOURS(	p_bg,
3288 							v_work_sched_name,
3289 							v_range_start,
3290 							v_range_end);
3291 
3292      ELSE-- Hourly emp using Standard Hours on asg.
3293 
3294          hr_utility.trace('  Hourly emp using Standard Hours on asg');
3295 
3296          hr_utility.trace('calling hr_us_ff_udfs.Standard_Hours_Worked');
3297 
3298          v_hrs_per_range := hr_us_ff_udfs.Standard_Hours_Worked(p_asg_std_hrs,
3299 						v_range_start,
3300 						v_range_end,
3301 						p_asg_std_freq);
3302 
3303          hr_utility.trace('returned hr_us_ff_udfs.Standard_Hours_Worked');
3304      END IF;
3305 
3306 
3307       IF v_period_hours THEN
3308 
3309          hr_utility.trace('v_period_hours = TRUE');
3310 
3311          select TPT.number_per_fiscal_year
3312           into    v_periods_per_fiscal_yr
3313           from   pay_payrolls_f        PPF,
3314                  per_time_period_types TPT,
3315                  fnd_sessions          fs
3316          where  PPF.payroll_id = p_payroll
3317          and    fs.session_id = USERENV('SESSIONID')
3318          and    fs.effective_date  between PPF.effective_start_date and PPF.effective_end_date
3319          and   TPT.period_type = PPF.period_type;
3320 
3321          v_annualizing_factor := v_hrs_per_range * v_periods_per_fiscal_yr;
3322          hr_utility.trace('v_hrs_per_range ='||to_number(v_hrs_per_range));
3323          hr_utility.trace('v_periods_per_fiscal_yr ='||to_number(v_periods_per_fiscal_yr));
3324          hr_utility.trace('v_annualizing_factor ='||to_number(v_annualizing_factor));
3325 
3326       ELSE
3327 
3328          hr_utility.trace('v_period_hours = FALSE');
3329 
3330          v_annualizing_factor := v_hrs_per_range * c_weeks_per_year;
3331 
3332          hr_utility.trace('v_hrs_per_range ='||to_number(v_hrs_per_range));
3333          hr_utility.trace('c_weeks_per_year ='||to_number(c_weeks_per_year));
3334          hr_utility.trace('v_annualizing_factor ='||to_number(v_annualizing_factor));
3335 
3336       END IF;
3337 
3338   END IF;
3339 
3340 END IF;	-- (v_use_pay_basis = 0)
3341 
3342 
3343     hr_utility.trace('  Getting out of Get_Annualizing_Factor for '||v_pay_basis);
3344 RETURN v_annualizing_factor;
3345 
3346 END Get_Annualizing_Factor;
3347 
3348 
3349 BEGIN -- begin Garn_Convert_Period_Type
3350 -- begin Garn_Convert_Period_Type
3351 
3352 hr_utility.trace('Entered Garn_Convert_Period_Type');
3353 
3354 hr_utility.trace('  p_bus_grp_id: '|| p_bus_grp_id);
3355 hr_utility.trace('  p_payroll_id: '||p_payroll_id);
3356 hr_utility.trace('  p_asst_work_schedule: '||p_asst_work_schedule);
3357 hr_utility.trace('  p_asst_std_hours: '||p_asst_std_hours);
3358 hr_utility.trace('  p_figure: '||p_figure);
3359 hr_utility.trace('  p_from_freq : '||p_from_freq);
3360 hr_utility.trace('  p_to_freq: '||p_to_freq);
3361 hr_utility.trace('  p_period_start_date: '||to_char(p_period_start_date));
3362 hr_utility.trace('  p_period_end_date: '||to_char(p_period_end_date));
3363 hr_utility.trace('  p_asst_std_freq: '||p_asst_std_freq);
3364 
3365 
3366   --
3367   -- If From_Freq and To_Freq are the same, then we're done.
3368   --
3369 
3370   IF NVL(p_from_freq, 'NOT ENTERED') = NVL(p_to_freq, 'NOT ENTERED') THEN
3371 
3372     RETURN p_figure;
3373 
3374   END IF;
3375   hr_utility.trace('Calling Get_Annualizing_Factor for FROM case');
3376   v_from_annualizing_factor := Get_Annualizing_Factor(
3377 			p_bg			=> p_bus_grp_id,
3378 			p_payroll		=> p_payroll_id,
3379 			p_freq		=> p_from_freq,
3380 			p_asg_work_sched	=> p_asst_work_schedule,
3381 			p_asg_std_hrs	=> p_asst_std_hours,
3382 			p_asg_std_freq	=> p_asst_std_freq);
3383 
3384   hr_utility.trace('Calling Get_Annualizing_Factor for TO case');
3385 
3386   v_to_annualizing_factor := Get_Annualizing_Factor(
3387 			p_bg			=> p_bus_grp_id,
3388 			p_payroll		=> p_payroll_id,
3389 			p_freq		=> p_to_freq,
3390 			p_asg_work_sched	=> p_asst_work_schedule,
3391 			p_asg_std_hrs	=> p_asst_std_hours,
3392 			p_asg_std_freq	=> p_asst_std_freq);
3393 
3394   --
3395   -- Annualize "Figure" and convert to To_Freq.
3396   --
3397  hr_utility.trace('v_from_annualizing_factor ='||to_char(v_from_annualizing_factor));
3398  hr_utility.trace('v_to_annualizing_factor ='||to_char(v_to_annualizing_factor));
3399 
3400   IF v_to_annualizing_factor = 0 	OR
3401      v_to_annualizing_factor = -999	OR
3402      v_from_annualizing_factor = -999	THEN
3403 
3404     hr_utility.trace(' v_to_ann =0 or -999 or v_from = -999');
3405 
3406     v_converted_figure := 0;
3407     RETURN v_converted_figure;
3408 
3409   ELSE
3410 
3411     hr_utility.trace(' v_to_ann NOT 0 or -999 or v_from = -999');
3412 
3413     hr_utility.trace('p_figure Monthly Salary = '||p_figure);
3414     hr_utility.trace('v_from_annualizing_factor = '||v_from_annualizing_factor);
3415     hr_utility.trace('v_to_annualizing_factor   = '||v_to_annualizing_factor);
3416 
3417     v_converted_figure := (p_figure * v_from_annualizing_factor) / v_to_annualizing_factor;
3418     hr_utility.trace('conv figure is monthly_sal * ann_from div by ann to');
3419 
3420     hr_utility.trace('UDFS v_converted_figure := '||v_converted_figure);
3421 
3422   END IF;
3423 
3424   /* Removed the logic to return the converted figure based on
3425      Payroll level 'Hours Calculation Type'. This should not matter
3426      in case of conversion from weekly to period figure and vice
3427      versa for involuntary deduction elements.
3428   */
3429 
3430 -- Done
3431 
3432 RETURN v_converted_figure;
3433 
3434 END Garn_Convert_Period_Type; -- End of Garn_Convert_Period_Type
3435 
3436 BEGIN -- Begin of CONVERT_PERIOD_TYPE
3437 
3438 /* Instead of directly calling hr_us_ff_udfs, introducing an internal
3439    (Private) Function Call to be used within pay_us_inv_ded_formulas.
3440    hr_us_ff_udfs.convert_period_type fails to convert 'weekly' figure
3441    to 'period' one and vica-versa in case 'Hours Calculation Type'
3442    is set to 'Standard' at Payroll definition level.
3443    Irrespective of Payroll level 'Hours Calculation Type',
3444    (Annualized or Standard) system should be able to convert
3445    weekly to period figure correctly and vice-versa.
3446 */
3447 /*
3448     RETURN (hr_us_ff_udfs.convert_period_type(CTX_BUSINESS_GROUP_ID,
3449                                               CTX_PAYROLL_ID,
3450                                               SCL_ASG_US_WORK_SCHEDULE,
3451                                               ASG_HOURS,
3452                                               FED_CRITERIA_PCT_PRD_DI_XMPT,
3453                                               P_FROM_FREQ,
3454                                               P_TO_FREQ,
3455                                               PAY_EARNED_START_DATE,
3456                                               PAY_EARNED_END_DATE,
3457                                               P_ASST_STD_FREQ)
3458            );
3459 */
3460 
3461 RETURN (Garn_Convert_Period_Type(
3462 		p_bus_grp_id => ctx_business_group_id
3463 	     ,p_payroll_id => ctx_payroll_id
3464 	     ,p_asst_work_schedule => scl_asg_us_work_schedule
3465 	     ,p_asst_std_hours => asg_hours
3466 	     ,p_figure => fed_criteria_pct_prd_di_xmpt
3467 	     ,p_from_freq => p_from_freq
3468 	     ,p_to_freq => p_to_freq
3469 	     ,p_period_start_date => pay_earned_start_date
3470 	     ,p_period_end_date => pay_earned_end_date
3471 	     ,p_asst_std_freq => p_asst_std_freq
3472             )
3473        );
3474 
3475 END CONVERT_PERIOD_TYPE;
3476 
3477   /****************************************************************************
3478     Name        : FNC_FEE_CALCULATION
3479     Description : This function calculates fees amount for different categories
3480                   of involuntary deductions.
3481   *****************************************************************************/
3482 
3483 FUNCTION FNC_FEE_CALCULATION
3484 (
3485     GARN_FEE_FEE_RULE varchar2,
3486     GARN_FEE_FEE_AMOUNT number,
3487     GARN_FEE_PCT_CURRENT number,
3488     TOTAL_OWED number,
3489     PRIMARY_AMOUNT_BALANCE number,
3490     GARN_FEE_ADDL_GARN_FEE_AMOUNT number,
3491     GARN_FEE_MAX_FEE_AMOUNT number,
3492     PTD_FEE_BALANCE number,
3493     GARN_TOTAL_FEES_ASG_GRE_RUN number,
3494     DEDN_AMT number,
3495     MONTH_FEE_BALANCE number,
3496     ACCRUED_FEES number
3497 )
3498 RETURN number IS
3499 BEGIN
3500 RETURN (pay_wat_udfs.fnc_fee_calculation(CTX_JURISDICTION_CODE,
3501                                         GARN_FEE_FEE_RULE,
3502                                         GARN_FEE_FEE_AMOUNT,
3503                                         GARN_FEE_PCT_CURRENT,
3504                                         TOTAL_OWED,
3505                                         PRIMARY_AMOUNT_BALANCE,
3506                                         GARN_FEE_ADDL_GARN_FEE_AMOUNT,
3507                                         GARN_FEE_MAX_FEE_AMOUNT,
3508                                         PTD_FEE_BALANCE,
3509                                         GARN_TOTAL_FEES_ASG_GRE_RUN,
3510                                         DEDN_AMT,
3511                                         MONTH_FEE_BALANCE,
3512                                         ACCRUED_FEES)
3513       );
3514 END FNC_FEE_CALCULATION;
3515 
3516 
3517   /****************************************************************************
3518     Name        : GET_GARN_LIMIT_MAX_DURATION
3519     Description : This function returns the maximum duration, in
3520                   number of days, for which a particular garnishment can be
3521                   taken in a particular state. The duration is obtained with
3522                   respect to the 'Date Served' of the garnishment.
3523   *****************************************************************************/
3524 
3525 FUNCTION GET_GARN_LIMIT_MAX_DURATION(PAY_EARNED_START_DATE DATE)
3526 RETURN number IS
3527     CURSOR csr_ovrd_duration IS
3528         SELECT entry_information8
3529           FROM pay_element_entries_f
3530          WHERE element_entry_id = CTX_ORIGINAL_ENTRY_ID
3531            AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
3532            AND PAY_EARNED_START_DATE BETWEEN effective_start_date AND effective_end_date;
3533 
3534     -- Checking Element level Override
3535     CURSOR csr_elem_ovrd_duration IS
3536          SELECT petei.eei_information12
3537          FROM   pay_element_entries_f peef,
3538                 pay_element_types_f petf,
3539                 pay_element_types_f petf_calc,
3540                 pay_element_type_extra_info petei
3541          WHERE  peef.element_entry_id = CTX_ORIGINAL_ENTRY_ID
3542          AND    petf.element_type_id = peef.element_type_id
3543          AND    petf_calc.element_type_id = CTX_ELEMENT_TYPE_ID
3544          AND    petf_calc.element_type_id = petf.element_information5
3545          AND    petf.element_type_id = petei.element_type_id
3546          AND    petei.information_type = 'PAY_US_GARN_PROCESSING_RULE'
3547          AND    petei.eei_information11 = substr(CTX_JURISDICTION_CODE, 1, 2) ;
3548 
3549     l_ovrd_duration number;
3550     default_number number;
3551     ln_elem_ovrd_duration number ;
3552 BEGIN
3553 
3554     default_number := -9999;
3555 
3556     OPEN csr_ovrd_duration;
3557         FETCH csr_ovrd_duration into l_ovrd_duration;
3558     CLOSE csr_ovrd_duration;
3559 
3560     -- If Element Entry level override is not there then check for Element level override
3561     IF nvl(l_ovrd_duration,default_number) = default_number THEN
3562        OPEN csr_elem_ovrd_duration ;
3563        FETCH csr_elem_ovrd_duration into ln_elem_ovrd_duration ;
3564        CLOSE csr_elem_ovrd_duration ;
3565        l_ovrd_duration := ln_elem_ovrd_duration ;
3566     END IF ;
3567 
3568     /* If exists, return the override value. Bug 3549191. */
3569     IF nvl(l_ovrd_duration,default_number) = default_number THEN
3570         RETURN (pay_wat_udfs.get_garn_limit_max_duration(CTX_ELEMENT_TYPE_ID,
3571                                                          CTX_ORIGINAL_ENTRY_ID,
3572                                                          CTX_DATE_EARNED,
3573                                                          CTX_JURISDICTION_CODE));
3574     ELSE
3575         RETURN (l_ovrd_duration);
3576     END IF;
3577 END GET_GARN_LIMIT_MAX_DURATION;
3578 
3579 
3580   /****************************************************************************
3581     Name        : GET_GEOCODE
3582     Description : This function returns the geocode corresponding to inputs
3583                   specified.
3584   *****************************************************************************/
3585 
3586 
3587 FUNCTION GET_GEOCODE
3588 (
3589 OVERRIDE_ADR_REGION_2 varchar2,
3590 OVERRIDE_ADR_REGION_1 varchar2,
3591 OVERRIDE_ADR_CITY varchar2,
3592 OVERRIDE_ADR_POSTAL_CODE varchar2
3593 ) RETURN varchar2 IS
3594 BEGIN
3595     RETURN hr_us_ff_udfs.addr_val (OVERRIDE_ADR_REGION_2,
3596                                    OVERRIDE_ADR_REGION_1,
3597                                    OVERRIDE_ADR_CITY,
3598                                    OVERRIDE_ADR_POSTAL_CODE);
3599 END GET_GEOCODE;
3600 
3601 
3602   /****************************************************************************
3603     Name        : GARN_CAT
3604     Description : This function returns garnishment category of the specified
3605                   element_entry_id.
3606   *****************************************************************************/
3607 
3608 FUNCTION GARN_CAT RETURN varchar2 IS
3609 BEGIN
3610     RETURN(pay_wat_udfs.garn_cat (CTX_DATE_EARNED,
3611                                   CTX_ELEMENT_ENTRY_ID));
3612 END GARN_CAT;
3613 
3614   /****************************************************************************
3615     Name        : CAL_FORMULA_BO
3616     Description : This function calculates amount to be withheld for BO, CD, G,
3617                   EL, ER and DCIA categories.
3618   *****************************************************************************/
3619 
3620 
3621 FUNCTION CAL_FORMULA_BO
3622 (
3623     P_CTX_BUSINESS_GROUP_ID number,
3624     P_CTX_PAYROLL_ID number,
3625     P_CTX_ELEMENT_TYPE_ID number,
3626     P_CTX_ORIGINAL_ENTRY_ID number,
3627     P_CTX_DATE_EARNED date,
3628     P_CTX_JURISDICTION_CODE varchar2,
3629     P_CTX_ELEMENT_ENTRY_ID number,
3630     GARN_EXEMPTION_CALC_RULE varchar2,
3631     GRN_EXMPT_DEP_CALC_RULE varchar2,
3632     GARN_EXEMPTION_DI_PCT number,
3633     GARN_EXEMPTION_MIN_WAGE_FACTOR number,
3634     GARN_EXEMPTION_AMOUNT_VALUE number,
3635     GRN_EXMPT_DEP_AMT_VAL number,
3636     GRN_EXMPT_ADDL_DEP_AMT_VAL number,
3637     GARN_FEE_FEE_RULE varchar2,
3638     GARN_FEE_ADDL_GARN_FEE_AMOUNT number,
3639     GARN_FEE_FEE_AMOUNT number,
3640     GARN_FEE_TAKE_FEE_ON_PRORATION varchar2,
3641     GARN_FEE_PCT_CURRENT number,
3642     GARN_FEE_MAX_FEE_AMOUNT number,
3643     PAY_EARNED_START_DATE date,
3644     PAY_EARNED_END_DATE date,
3645     SCL_ASG_US_WORK_SCHEDULE varchar2,
3646     ASG_HOURS number,
3647     STATE_MIN_WAGE number,
3648     ASG_FREQ varchar2,
3649     TERMINATED_EMPLOYEE varchar2,
3650     FINAL_PAY_PROCESSED varchar2,
3651     GARN_TOTAL_FEES_ASG_GRE_RUN number,
3652     GARN_TOTAL_DEDNS_ASG_GRE_RUN number,
3653     GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN number,
3654     GROSS_EARNINGS_ASG_GRE_MONTH number,
3655     GROSS_EARNINGS_ASG_GRE_RUN number,
3656     REGULAR_EARNINGS_ASG_GRE_RUN number,
3657     NET_ASG_GRE_RUN number,
3658     TAX_DEDUCTIONS_ASG_GRE_RUN number,
3659     TAX_LEVIES_ASG_GRE_RUN number,
3660     GRN_DI_SUBJ_TX_ASG_GRE_RUN number,
3661     PRE_TAX_DEDUCTIONS_ASG_GRE_RUN number,
3662     PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN number,
3663     PR_TX_DED_SBJ_TX_ASG_GRE_RN number,
3664     TOT_WHLD_SUPP_ASG_GRE_RUN number,
3665     TOTAL_WITHHELD_FEE_ASG_GRE_RUN number,
3666     JURISDICTION varchar2,
3667     TOTAL_OWED number,
3668     DATE_SERVED date,
3669     ADDITIONAL_AMOUNT_BALANCE number,
3670     REPLACEMENT_AMOUNT_BALANCE number,
3671     PRIMARY_AMOUNT_BALANCE number,
3672     ACCRUED_FEES number,
3673     PTD_FEE_BALANCE number,
3674     MONTH_FEE_BALANCE number,
3675     GARN_EXEMPTION_PRORATION_RULE varchar2,
3676     CALCD_ARREARS OUT NOCOPY number,
3677     CALCD_DEDN_AMT OUT NOCOPY number,
3678     CALCD_FEE OUT NOCOPY number,
3679     FATAL_MESG OUT NOCOPY varchar2,
3680     GARN_FEE OUT NOCOPY number,
3681     MESG OUT NOCOPY varchar2,
3682     MESG1 OUT NOCOPY varchar2,
3683     NOT_TAKEN OUT NOCOPY number,
3684     SF_ACCRUED_FEES OUT NOCOPY number,
3685     STOP_ENTRY OUT NOCOPY varchar2,
3686     TO_ADDL OUT NOCOPY number,
3687     TO_REPL OUT NOCOPY number,
3688     TO_TOTAL_OWED OUT NOCOPY number,
3689     calc_subprio OUT NOCOPY number,
3690     DCIA_DI_SUBJ_TX_ASG_GRE_RUN number default 0,
3691     DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN number default 0,
3692     PR_TX_DCIA_SB_TX_ASG_GRE_RN number default 0,
3693     PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN number default 0,
3694     EIC_ADVANCE_ASG_GRE_RUN number default 0,
3695     VOL_DEDN_ROTH_ASG_GRE_RUN     number default 0,
3696     VOL_DEDN_SB_TX_ASG_GRE_RUN    number default 0,
3697     VOL_DEDN_SB_TX_JD_ASG_GRE_RUN number default 0,
3698     NET_ASG_RUN                   number default 0,
3699     NET_ASG_PTD                   number default 0
3700 
3701 ) RETURN number IS
3702 
3703     default_number number;
3704     default_date date;
3705     di_subj number;
3706     inv_dedn_in_run number;
3707     garn_category varchar2(10);
3708     dedn_amt number;
3709     dedn_amt_cp number;
3710     c_Balance_Subject_to_Garn number;
3711     c_Hawaii_Pct_Exempt_Range_1 number;
3712     c_Hawaii_Pct_Exempt_Range_2 number;
3713     c_Hawaii_Pct_Exempt_Range_3 number;
3714     c_hawaii_range_1_mnth_erngs number;
3715     c_hawaii_range_2_mnth_erngs number;
3716     c_ny_minwage_multpl_range_1 number;
3717     c_ny_gross_erngs_exmpt_pct number;
3718     c_ny_minwage_exmpt_multpl_1 number;
3719     c_ny_minwage_exmpt_multpl_2 number;
3720     c_ny_di_exmpt_pct number;
3721     c_ok_range_1_wkly_erngs number;
3722     c_ok_range_2_wkly_erngs number;
3723     c_Oklahoma_earnings_exempt_pct number;
3724     c_Federal_Minimum_Wage number;
3725 --Bug 6678760 VMKULKAR
3726     l_fed_criteria_minwage_dl number;
3727     c_dl_gross_erngs_exmpt_pct number;
3728 --Bug 6678760 VMKULKAR
3729     c_State_Minimum_Wage number; -- Bug 4556146
3730     ccpa_protection number;
3731     total_di number;
3732     Total_DI_per_week number;
3733     diff number;
3734     fed_criteria_pct_prd_di_xmpt number;
3735     fed_criteria_wk_prd_di_xmpt number;
3736     fed_criteria_minwage_exemption number;
3737     fed_criteria_exemption number;
3738     DI_state_exemption_amt number;
3739     di_state_dependents_exemption number;
3740     max_garn number;
3741     earnings_per_week number;
3742     OK_weekly_state_exemption_amt number;
3743     di_state_addl_pct_exempt number;
3744     di_total_state_exemption number;
3745     di_total_exemption number;
3746     di_total_period_exemption number;
3747     di_total_week number;
3748     di_hawaii_max_cd number;
3749     di_hawaii_max_cd_month number;
3750     total_di_month number;
3751     Subject_DISPOSABLE_INCOME number;
3752     IN_GARN_FEE_MAX_FEE_AMOUNT number;
3753     t_dedn_amt number;
3754     l_exmpt_ovrd number;
3755     garn_limit_days number;
3756     garn_days number;
3757     garn_days_end_per number;
3758     total_garn_run number;
3759     proportional_dedn_amount number;
3760     equal_dedn_amounts number;
3761     l_proration_ovrd varchar2(15);
3762     sub_prio_max number;
3763     equal_DI number;
3764     calcd_fee_rec number;
3765 
3766     amount number;
3767     percentage number;
3768     num_dependents number;
3769     filing_status varchar2(10);
3770     exempt_amt_bo number;
3771     monthly_cap_amount number;
3772     month_to_date_balance number;
3773     period_cap_amount number;
3774     period_to_date_balance number;
3775     accrued_fee_correction number;
3776     cntr number;
3777 
3778     l_debug_on varchar2(1);
3779     l_proc_name varchar2(50);
3780     l_garn_fee_max_fee_amt number;
3781     l_ini_fee_flag varchar2(10);
3782     lv_ele_name varchar2(100);
3783 
3784     ln_others_di number;
3785     ld_override_date date;
3786     ld_entry_start_date   date;
3787     lb_use_state_min_wage boolean;
3788 
3789     ln_assignment_id        Number ; -- Bug# 5150447
3790     ln_resident_state_code  Varchar2(30) ;
3791     ln_filing_status_code   Varchar2(30) ;
3792     l_garn_exemption_amount_value number;
3793 
3794     -- VMKULKAR
3795 
3796     l_pay_period_length varchar2(30);
3797     l_state_period_exemption_amt number;
3798 
3799     -- VMKULKAR
3800 
3801     -- Bug# 6133337
3802     lv_M_rule          VARCHAR2(100);
3803     ln_M_factor        NUMBER(2);
3804     ln_M_F_factor      NUMBER(2);
3805     ln_M_S_factor      NUMBER(2);
3806     ln_ovrd_cnt        NUMBER(2);
3807 
3808     -- Bug 6818016
3809     tmp_DI_total_week_exempt        NUMBER;
3810     tmp_fed_state_week_exemption    NUMBER;
3811     tmp_net_asg_run_prd             NUMBER;
3812     tmp_net_asg_ptd_week            NUMBER;
3813     tmp_net_asg_run_week            NUMBER;
3814 
3815     -- Bug# 7589784
3816     tmp_dedn_amt                    NUMBER;
3817     tmp_calc_fee                    NUMBER;
3818     tmp_not_taken                   NUMBER;
3819 
3820     -- Bug 7674615
3821     lb_EL_reduce_di                 BOOLEAN DEFAULT FALSE;
3822     fed_min_wage_prd_exempt         NUMBER;
3823 
3824     -- Bug 12795985
3825      c_MA_gross_erngs_exmpt_pct number;
3826      c_MA_minwage_exmpt_multpl number;
3827 
3828 
3829 
3830 
3831     CURSOR cur_debug is
3832         SELECT parameter_value
3833           FROM pay_action_parameters
3834          WHERE parameter_name = 'GARN_DEBUG_ON';
3835 
3836 
3837     /*-- Cursor for Bug 3520523 --*/
3838     CURSOR csr_exmpt_ovrd(c_override_date date) is
3839         SELECT entry_information4
3840           FROM pay_element_entries_f
3841          WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
3842            AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
3843            AND c_override_date BETWEEN effective_start_date and effective_end_date;
3844 
3845 
3846     /* Cursot to return the Initial Fee Flag value Bug 3549298 */
3847     CURSOR csr_get_ini_fee_flag is
3848     SELECT nvl(entry_information9, 'N')
3849       FROM pay_element_entries_f
3850      WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
3851        AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
3852        AND P_CTX_DATE_EARNED BETWEEN effective_start_date and effective_end_date;
3853 
3854     /*-- Cursor for Bug 2658290 --*/
3855     CURSOR csr_get_proration_ovrd is
3856         select aei.aei_information3
3857           from per_assignment_extra_info aei,
3858                pay_element_entries_f pee
3859          where aei.assignment_id = pee.assignment_id
3860            and aei.information_type = 'US_PRORATION_RULE'
3861            and aei.aei_information_category = 'US_PRORATION_RULE'
3862            and aei.aei_information2 = garn_cat
3863            and substr(aei.aei_information1, 1, 2) = substr(P_CTX_JURISDICTION_CODE, 1, 2)
3864            and pee.element_entry_id = P_CTX_ORIGINAL_ENTRY_ID ;
3865 
3866     /* Bug 3722152 */
3867     CURSOR c_garn_max_fee_amt is
3868     select target.MAX_FEE_AMOUNT from
3869            PAY_US_GARN_FEE_RULES_F target,
3870            PAY_ELEMENT_TYPES_F pet
3871     WHERE target.state_code = substr(P_CTX_JURISDICTION_CODE,1,2)
3872       AND target.garn_category = pet.element_information1
3873       AND P_CTX_DATE_EARNED BETWEEN target.effective_start_date
3874                                 AND target.effective_end_date
3875       AND pet.element_type_id = P_CTX_ELEMENT_TYPE_ID
3876       AND P_CTX_DATE_EARNED BETWEEN pet.effective_start_date
3877                                 AND pet.effective_end_date;
3878 
3879     -- Bug 4079142
3880     -- Cursor to get the element name to be used in the message.
3881     CURSOR csr_get_ele_name (p_ele_type_id number) is
3882     select rtrim(element_name,' Calculator' )
3883       from pay_element_types_f
3884      where element_type_id = p_ele_type_id;
3885 
3886     -- Bug 4556146
3887     CURSOR csr_get_entry_start_date is
3888     select min(effective_start_date)
3889       from pay_element_entries_f
3890      where element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
3891      group by element_entry_id;
3892 
3893     -- Added for Bug# 5150447
3894     CURSOR c_get_res_state_code(p_element_entry_id in number) is
3895 	select 	paf.assignment_id,
3896 	        pus.state_code
3897 	  from 	pay_element_entries_f pee,
3898 		per_all_assignments_f paf,
3899 		per_all_people_f ppf,
3900 		per_addresses pa,
3901 		pay_us_states pus
3902 	 where	pee.element_entry_id = p_element_entry_id
3903 	   and  pee.assignment_id = paf.assignment_id
3904 	   and  paf.person_id = ppf.person_id
3905 	   and  ppf.person_id = pa.person_id
3906 	   and  pa.primary_flag = 'Y'
3907 	   and  trim(pa.region_2) = pus.state_abbrev ;
3908 
3909     CURSOR c_get_filing_status(p_assignment_id in number) is
3910     select  filing_status_code
3911 	from    pay_us_emp_state_tax_rules_f pestr,
3912 	        per_all_assignments_f paf,
3913      		hr_locations hl,
3914 		    pay_us_states pus
3915 	where   pestr.assignment_id = p_assignment_id
3916 	and     pestr.assignment_id = paf.assignment_id
3917 	and     paf.location_id = hl.location_id
3918 	and     pus.state_abbrev = nvl(loc_information17,region_2) ;
3919 
3920     CURSOR c_get_allowance_value(c_input_value_name varchar2) IS
3921     select peev.screen_entry_value
3922       from pay_element_entries_f peef,
3923            pay_element_entry_values_f peev,
3924            pay_input_values_f pivf
3925      where peef.element_entry_id = P_CTX_ELEMENT_ENTRY_ID
3926        and peev.element_entry_id = peef.element_entry_id
3927        and pivf.element_type_id = peef.element_type_id
3928        and pivf.name = c_input_value_name
3929        and peev.input_value_id = pivf.input_value_id
3930        and P_CTX_DATE_EARNED between peev.effective_start_date
3931                                  and peev.effective_end_date;
3932      -- Bug# 6132855
3933      -- Federal Minimum Wage now is stored in JIT table
3934      CURSOR c_get_federal_min_wage IS
3935      SELECT fed_information1
3936        FROM pay_us_federal_tax_info_f
3937       WHERE fed_information_category = 'WAGEATTACH LIMIT'
3938         AND P_CTX_DATE_EARNED BETWEEN effective_start_date
3939                                   AND effective_end_date;
3940 
3941 -- VMKULKAR
3942      CURSOR c_get_state_garn_exemption_amt(p_column_name varchar2, p_row_name varchar2) IS
3943 	select puci.value
3944 	from pay_user_column_instances_f puci,
3945 	   pay_user_tables put,
3946 	   pay_user_rows_f pur,
3947 	   pay_user_columns puc
3948 	where puci.user_column_id = puc.user_column_id
3949 	and puci.user_row_id = pur.user_row_id
3950 	and put.user_table_id = puc.user_table_id
3951 	and put.user_table_id = pur.user_table_id
3952 	and put.user_table_name = 'Wage Attach State Exemptions Table'
3953 	and pur.row_low_range_or_name = p_row_name
3954 	and puc.user_column_name = p_column_name
3955 	and p_ctx_date_earned between puci.effective_start_date
3956                                   and puci.effective_end_date;
3957 
3958 
3959      CURSOR c_get_pay_period_length(p_payroll_id number) IS
3960 	select period_type
3961 	   from pay_all_payrolls_f
3962 	 where payroll_id = p_payroll_id
3963 	 and p_ctx_date_earned between effective_start_date
3964                                   and effective_end_date;
3965 
3966 -- VMKULKAR
3967 
3968     -- Bug# 6133337
3969     -- Checking If Multiple Element level Overrides exist
3970     CURSOR csr_elem_ovrd_fed_stat_M_count IS
3971          SELECT count(petei.eei_information13)
3972          FROM   pay_element_entries_f peef,
3973                 pay_element_types_f petf,
3974                 pay_element_types_f petf_calc,
3975                 pay_element_type_extra_info petei
3976          WHERE  peef.element_entry_id = CTX_ORIGINAL_ENTRY_ID
3977          AND    petf.element_type_id = peef.element_type_id
3978          AND    petf_calc.element_type_id = CTX_ELEMENT_TYPE_ID
3979          AND    petf_calc.element_type_id = petf.element_information5
3980          AND    petf.element_type_id = petei.element_type_id
3981          AND    petei.information_type = 'PAY_US_GARN_PROCESSING_RULE'
3982          AND    petei.eei_information11 = substr(CTX_JURISDICTION_CODE, 1, 2)
3983          GROUP BY petei.information_type
3984                  ,petei.eei_information11;
3985 
3986     -- Checking Element level Override
3987     CURSOR csr_elem_ovrd_fed_stat_M IS
3988          SELECT petei.eei_information13
3989                ,petei.eei_information14
3990          FROM   pay_element_entries_f peef,
3991                 pay_element_types_f petf,
3992                 pay_element_types_f petf_calc,
3993                 pay_element_type_extra_info petei
3994          WHERE  peef.element_entry_id = CTX_ORIGINAL_ENTRY_ID
3995          AND    petf.element_type_id = peef.element_type_id
3996          AND    petf_calc.element_type_id = CTX_ELEMENT_TYPE_ID
3997          AND    petf_calc.element_type_id = petf.element_information5
3998          AND    petf.element_type_id = petei.element_type_id
3999          AND    petei.information_type = 'PAY_US_GARN_PROCESSING_RULE'
4000          AND    petei.eei_information11 = substr(CTX_JURISDICTION_CODE, 1, 2) ;
4001 
4002 BEGIN
4003     l_proc_name := l_package_name||'CAL_FORMULA_BO';
4004     hr_utility.trace('Entering '||l_proc_name);
4005 
4006     default_number := -9999;
4007     default_date := fnd_date.canonical_to_date('0001/01/01');
4008     sub_prio_max := 9999;
4009     amount := GLB_AMT(P_CTX_ORIGINAL_ENTRY_ID);
4010     percentage := GLB_PCT(P_CTX_ORIGINAL_ENTRY_ID);
4011     num_dependents := GLB_NUM_DEPS(P_CTX_ORIGINAL_ENTRY_ID);
4012     filing_status := GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID);
4013     exempt_amt_bo := GLB_EXEMPT_AMT(P_CTX_ORIGINAL_ENTRY_ID);
4014     monthly_cap_amount := GLB_MONTH_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
4015     month_to_date_balance := GLB_MTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
4016     period_cap_amount := GLB_PTD_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
4017     period_to_date_balance := GLB_PTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
4018     accrued_fee_correction := GLB_TO_ACCRUED_FEES(P_CTX_ORIGINAL_ENTRY_ID);
4019     l_garn_fee_max_fee_amt := NULL;
4020 
4021     --Bug 6678760 VMKULKAR
4022     l_fed_criteria_minwage_dl:=0;
4023     --Bug 6678760 VMKULKAR
4024 
4025     /* Bug 14324196 sbachu*/
4026     tmp_dedn_amt:=0;
4027     tmp_calc_fee:=0;
4028     tmp_not_taken:=0;
4029     t_dedn_amt:=0;
4030 
4031     OPEN cur_debug;
4032         FETCH cur_debug into l_debug_on;
4033     CLOSE cur_debug;
4034 
4035     /*
4036      * Fetch the value of Initial Fee Flag. Bug 3549298
4037      */
4038 
4039     open csr_get_ini_fee_flag;
4040     fetch csr_get_ini_fee_flag into l_ini_fee_flag;
4041     close csr_get_ini_fee_flag;
4042 
4043     -- Fetching Federal Minimum Wage Value from JIT table
4044     OPEN c_get_federal_min_wage;
4045     FETCH c_get_federal_min_wage INTO c_Federal_Minimum_Wage;
4046     CLOSE c_get_federal_min_wage;
4047 
4048     IF l_debug_on = 'Y' THEN
4049         hr_utility.trace('Input parameters....');
4050         hr_utility.trace('P_CTX_BUSINESS_GROUP_ID = '||P_CTX_BUSINESS_GROUP_ID);
4051         hr_utility.trace('P_CTX_PAYROLL_ID = '||P_CTX_PAYROLL_ID);
4052         hr_utility.trace('P_CTX_ELEMENT_TYPE_ID = '||P_CTX_ELEMENT_TYPE_ID);
4053         hr_utility.trace('P_CTX_ORIGINAL_ENTRY_ID = '||P_CTX_ORIGINAL_ENTRY_ID);
4054         hr_utility.trace('P_CTX_DATE_EARNED = '||P_CTX_DATE_EARNED);
4055         hr_utility.trace('P_CTX_JURISDICTION_CODE = '||P_CTX_JURISDICTION_CODE);
4056         hr_utility.trace('P_CTX_ELEMENT_ENTRY_ID = '||P_CTX_ELEMENT_ENTRY_ID);
4057         hr_utility.trace('GARN_EXEMPTION_CALC_RULE = '||GARN_EXEMPTION_CALC_RULE);
4058         hr_utility.trace('GRN_EXMPT_DEP_CALC_RULE = '||GRN_EXMPT_DEP_CALC_RULE);
4059         hr_utility.trace('GARN_EXEMPTION_DI_PCT = '||GARN_EXEMPTION_DI_PCT);
4060         hr_utility.trace('GARN_EXEMPTION_MIN_WAGE_FACTOR = '||GARN_EXEMPTION_MIN_WAGE_FACTOR);
4061         hr_utility.trace('GARN_EXEMPTION_AMOUNT_VALUE = '||GARN_EXEMPTION_AMOUNT_VALUE);
4062         hr_utility.trace('GRN_EXMPT_DEP_AMT_VAL = '||GRN_EXMPT_DEP_AMT_VAL);
4063         hr_utility.trace('GRN_EXMPT_ADDL_DEP_AMT_VAL = '||GRN_EXMPT_ADDL_DEP_AMT_VAL);
4064         hr_utility.trace('GARN_FEE_FEE_RULE = '||GARN_FEE_FEE_RULE);
4065         hr_utility.trace('GARN_FEE_ADDL_GARN_FEE_AMOUNT = '||GARN_FEE_ADDL_GARN_FEE_AMOUNT);
4066         hr_utility.trace('GARN_FEE_FEE_AMOUNT = '||GARN_FEE_FEE_AMOUNT);
4067         hr_utility.trace('GARN_FEE_TAKE_FEE_ON_PRORATION = '||GARN_FEE_TAKE_FEE_ON_PRORATION);
4068         hr_utility.trace('GARN_FEE_PCT_CURRENT = '||GARN_FEE_PCT_CURRENT);
4069         hr_utility.trace('GARN_FEE_MAX_FEE_AMOUNT = '||GARN_FEE_MAX_FEE_AMOUNT);
4070         hr_utility.trace('PAY_EARNED_START_DATE = '||PAY_EARNED_START_DATE);
4071         hr_utility.trace('PAY_EARNED_END_DATE = '||PAY_EARNED_END_DATE);
4072         hr_utility.trace('SCL_ASG_US_WORK_SCHEDULE = '||SCL_ASG_US_WORK_SCHEDULE);
4073         hr_utility.trace('ASG_HOURS = '||ASG_HOURS);
4074         hr_utility.trace('STATE_MIN_WAGE = '||STATE_MIN_WAGE);
4075         hr_utility.trace('ASG_FREQ = '||ASG_FREQ);
4076         hr_utility.trace('TERMINATED_EMPLOYEE = '||TERMINATED_EMPLOYEE);
4077         hr_utility.trace('FINAL_PAY_PROCESSED = '||FINAL_PAY_PROCESSED);
4078         hr_utility.trace('GARN_TOTAL_FEES_ASG_GRE_RUN = '||GARN_TOTAL_FEES_ASG_GRE_RUN);
4079         hr_utility.trace('GARN_TOTAL_DEDNS_ASG_GRE_RUN = '||GARN_TOTAL_DEDNS_ASG_GRE_RUN);
4080         hr_utility.trace('GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN = '||GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN);
4081         hr_utility.trace('GROSS_EARNINGS_ASG_GRE_MONTH = '||GROSS_EARNINGS_ASG_GRE_MONTH);
4082         hr_utility.trace('GROSS_EARNINGS_ASG_GRE_RUN = '||GROSS_EARNINGS_ASG_GRE_RUN);
4083         hr_utility.trace('REGULAR_EARNINGS_ASG_GRE_RUN = '||REGULAR_EARNINGS_ASG_GRE_RUN);
4084         hr_utility.trace('NET_ASG_GRE_RUN = '||NET_ASG_GRE_RUN);
4085         hr_utility.trace('TAX_DEDUCTIONS_ASG_GRE_RUN = '||TAX_DEDUCTIONS_ASG_GRE_RUN);
4086         hr_utility.trace('TAX_LEVIES_ASG_GRE_RUN = '||TAX_LEVIES_ASG_GRE_RUN);
4087         hr_utility.trace('GRN_DI_SUBJ_TX_ASG_GRE_RUN = '||GRN_DI_SUBJ_TX_ASG_GRE_RUN);
4088         hr_utility.trace('PRE_TAX_DEDUCTIONS_ASG_GRE_RUN = '||PRE_TAX_DEDUCTIONS_ASG_GRE_RUN);
4089         hr_utility.trace('PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN = '||PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN);
4090         hr_utility.trace('PR_TX_DED_SBJ_TX_ASG_GRE_RN = '||PR_TX_DED_SBJ_TX_ASG_GRE_RN);
4091         hr_utility.trace('TOT_WHLD_SUPP_ASG_GRE_RUN = '||TOT_WHLD_SUPP_ASG_GRE_RUN);
4092         hr_utility.trace('TOTAL_WITHHELD_FEE_ASG_GRE_RUN = '||TOTAL_WITHHELD_FEE_ASG_GRE_RUN);
4093         hr_utility.trace('JURISDICTION = '||JURISDICTION);
4094         hr_utility.trace('TOTAL_OWED = '||TOTAL_OWED);
4095         hr_utility.trace('DATE_SERVED = '||DATE_SERVED);
4096         hr_utility.trace('ADDITIONAL_AMOUNT_BALANCE = '||ADDITIONAL_AMOUNT_BALANCE);
4097         hr_utility.trace('REPLACEMENT_AMOUNT_BALANCE = '||REPLACEMENT_AMOUNT_BALANCE);
4098         hr_utility.trace('PRIMARY_AMOUNT_BALANCE = '||PRIMARY_AMOUNT_BALANCE);
4099         hr_utility.trace('ACCRUED_FEES = '||ACCRUED_FEES);
4100         hr_utility.trace('PTD_FEE_BALANCE = '||PTD_FEE_BALANCE);
4101         hr_utility.trace('MONTH_FEE_BALANCE = '||MONTH_FEE_BALANCE);
4102         hr_utility.trace('GARN_EXEMPTION_PRORATION_RULE = '||GARN_EXEMPTION_PRORATION_RULE);
4103         hr_utility.trace('DCIA_DI_SUBJ_TX_ASG_GRE_RUN = '||DCIA_DI_SUBJ_TX_ASG_GRE_RUN);
4104         hr_utility.trace('DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN = '||DCIA_DI_SUBJ_TX_JD_ASG_GRE_RUN);
4105         hr_utility.trace('PR_TX_DCIA_SB_TX_ASG_GRE_RN = '||PR_TX_DCIA_SB_TX_ASG_GRE_RN);
4106         hr_utility.trace('PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN = '||PR_TX_DCIA_SB_TX_JD_ASG_GRE_RN);
4107         hr_utility.trace('EIC_ADVANCE_ASG_GRE_RUN = ' || EIC_ADVANCE_ASG_GRE_RUN);
4108         hr_utility.trace('INITIAL FEE FLAG ' || l_ini_fee_flag);
4109         hr_utility.trace('VOL_DEDN_ROTH_ASG_GRE_RUN = ' || VOL_DEDN_ROTH_ASG_GRE_RUN);
4110         hr_utility.trace('VOL_DEDN_SB_TX_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_ASG_GRE_RUN);
4111         hr_utility.trace('VOL_DEDN_SB_TX_JD_ASG_GRE_RUN = ' || VOL_DEDN_SB_TX_JD_ASG_GRE_RUN);
4112         hr_utility.trace('c_Federal_Minimum_Wage = ' || c_Federal_Minimum_Wage);
4113         hr_utility.trace('NET_ASG_RUN = ' || NET_ASG_RUN);
4114         hr_utility.trace('NET_ASG_PTD = ' || NET_ASG_PTD);
4115     END IF;
4116 
4117 
4118     /*--------- Set Contexts -------------*/
4119     CTX_BUSINESS_GROUP_ID := P_CTX_BUSINESS_GROUP_ID;
4120     CTX_PAYROLL_ID        := P_CTX_PAYROLL_ID;
4121     CTX_ELEMENT_TYPE_ID   := P_CTX_ELEMENT_TYPE_ID;
4122     CTX_ORIGINAL_ENTRY_ID := P_CTX_ORIGINAL_ENTRY_ID;
4123     CTX_DATE_EARNED       := P_CTX_DATE_EARNED;
4124     CTX_JURISDICTION_CODE := P_CTX_JURISDICTION_CODE;
4125     CTX_ELEMENT_ENTRY_ID  := P_CTX_ELEMENT_ENTRY_ID;
4126     /*------------------------------------*/
4127 
4128     garn_fee:=0;
4129     inv_dedn_in_run := TAX_LEVIES_ASG_GRE_RUN
4130                            + TOT_WHLD_SUPP_ASG_GRE_RUN
4131                            + TOTAL_WITHHELD_FEE_ASG_GRE_RUN
4132                            + GARN_TOTAL_DEDNS_ASG_GRE_RUN
4133                            + GARN_TOTAL_FEES_ASG_GRE_RUN;
4134     garn_category := garn_cat;
4135 
4136     GLB_NUM_ELEM := GLB_NUM_ELEM - 1;
4137     hr_utility.trace('GLB_NUM_ELEM = '|| GLB_NUM_ELEM);
4138 
4139     IF Accrued_Fees <> default_number THEN
4140         SF_Accrued_Fees := Accrued_Fees;
4141     ELSE
4142         SF_Accrued_Fees := 0;
4143     END IF;
4144 
4145     -- Bug 4079142
4146     -- Get the element name to be used in the message.
4147     open csr_get_ele_name(CTX_ELEMENT_TYPE_ID);
4148     fetch csr_get_ele_name into lv_ele_name;
4149     close csr_get_ele_name;
4150 
4151     /*
4152      * Bug 3722152
4153      * Get the GARN_FEE_MAX_FEE_AMOUNT
4154      */
4155     open c_garn_max_fee_amt;
4156     fetch c_garn_max_fee_amt into l_garn_fee_max_fee_amt;
4157     close c_garn_max_fee_amt;
4158 
4159     if l_garn_fee_max_fee_amt is NULL then
4160        l_garn_fee_max_fee_amt := 99999999;
4161     else
4162        l_garn_fee_max_fee_amt := GARN_FEE_MAX_FEE_AMOUNT;
4163     end if;
4164 
4165     -- Bug 4858720
4166     -- Use EIC_ADVANCE_ASG_GRE_RUN for calculatin the Deduction amount
4167     IF garn_category = 'EL' THEN
4168         -- Bug# 4676867
4169         c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
4170                                         GRN_DI_SUBJ_TX_ASG_GRE_RUN)
4171                                         - ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4172                                            + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN
4173                                               - PR_TX_DED_SBJ_TX_ASG_GRE_RN)
4174                                            + (VOL_DEDN_ROTH_ASG_GRE_RUN
4175                                              - VOL_DEDN_SB_TX_ASG_GRE_RUN)
4176                                            );
4177     ELSIF garn_category = 'DCIA' THEN
4178         -- Bug# 4676867
4179         c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
4180                                         DCIA_DI_SUBJ_TX_ASG_GRE_RUN)
4181                                         - ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4182                                            + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN
4183                                               - PR_TX_DCIA_SB_TX_ASG_GRE_RN)
4184                                            + (VOL_DEDN_ROTH_ASG_GRE_RUN
4185                                              - VOL_DEDN_SB_TX_ASG_GRE_RUN)
4186                                            );
4187     ELSE
4188         -- Bug# 4676867
4189         --Added the below if for bug 14032248 State level inclusion of earnings for DI
4190         IF VOL_DEDN_SB_TX_JD_ASG_GRE_RUN <> 0 and VOL_DEDN_SB_TX_ASG_GRE_RUN = 0 THEN
4191             c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
4192                                         LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
4193                                         ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4194                                          + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
4195                                         (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
4196                                          + (VOL_DEDN_ROTH_ASG_GRE_RUN - VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)
4197                                         );
4198         ELSE
4199             c_Balance_Subject_to_Garn := (REGULAR_EARNINGS_ASG_GRE_RUN +
4200                                         LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
4201                                         ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4202                                          + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
4203                                         (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
4204                                          + (VOL_DEDN_ROTH_ASG_GRE_RUN -
4205                                             LEAST(VOL_DEDN_SB_TX_ASG_GRE_RUN,VOL_DEDN_SB_TX_JD_ASG_GRE_RUN))
4206                                         );
4207         END IF;
4208     END IF;
4209 
4210     -- This DI is used for the calculation of CCPA Protection
4211     -- if DCIA is processed along with Non Support elements.
4212     -- Bug 4858720
4213     -- Use EIC_ADVANCE_ASG_GRE_RUN for calculatin the Deduction amount
4214     -- Bug# 4676867
4215     --Added the below if for bug 14032248 State level inclusion of earnings for DI
4216     IF VOL_DEDN_SB_TX_JD_ASG_GRE_RUN <> 0 and VOL_DEDN_SB_TX_ASG_GRE_RUN = 0 THEN
4217      ln_others_di := (REGULAR_EARNINGS_ASG_GRE_RUN +
4218                     LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
4219                     ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4220                      + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
4221                     (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
4222                      + (VOL_DEDN_ROTH_ASG_GRE_RUN - VOL_DEDN_SB_TX_JD_ASG_GRE_RUN)
4223                     );
4224     ELSE
4225      ln_others_di := (REGULAR_EARNINGS_ASG_GRE_RUN +
4226                     LEAST(GRN_DI_SUBJ_TX_JD_ASG_GRE_RUN, GRN_DI_SUBJ_TX_ASG_GRE_RUN)) -
4227                     ((TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN)
4228                      + (PRE_TAX_DEDUCTIONS_ASG_GRE_RUN -
4229                     (LEAST(PR_TX_DED_SBJ_TX_JD_ASG_GRE_RN, PR_TX_DED_SBJ_TX_ASG_GRE_RN )))
4230                      + (VOL_DEDN_ROTH_ASG_GRE_RUN -
4231                         LEAST(VOL_DEDN_SB_TX_ASG_GRE_RUN, VOL_DEDN_SB_TX_JD_ASG_GRE_RUN))
4232                     );
4233 	END IF;
4234 
4235     calc_subprio := entry_subpriority;
4236     IF calc_subprio = 1 THEN
4237         IF date_served <> default_date THEN
4238             calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - Date_Served);
4239         END IF;
4240     END IF;
4241     c_Hawaii_Pct_Exempt_Range_1 := .95;
4242     c_Hawaii_Pct_Exempt_Range_2 := .90;
4243     c_Hawaii_Pct_Exempt_Range_3 := .80;
4244     c_hawaii_range_1_mnth_erngs := 100;
4245     c_hawaii_range_2_mnth_erngs := 200;
4246     c_ny_minwage_multpl_range_1 := 30;
4247     c_ny_minwage_multpl_range_1 := 40;
4248     c_ny_gross_erngs_exmpt_pct := .90;
4249     c_ny_minwage_exmpt_multpl_1 := 30;
4250     c_ny_minwage_exmpt_multpl_2 := 40;
4251     c_ny_di_exmpt_pct := .75;
4252     c_ok_range_1_wkly_erngs := 48;
4253     c_ok_range_2_wkly_erngs := 64;
4254     c_Oklahoma_earnings_exempt_pct := .75;
4255 
4256 --bug 6678760 VMKULKAR
4257     c_dl_gross_erngs_exmpt_pct :=.85;
4258 --bug 6678760 VMKULKAR
4259 
4260 
4261     -- Bug 12795985
4262      c_MA_gross_erngs_exmpt_pct := .85;
4263      c_MA_minwage_exmpt_multpl := 50;
4264     -- Bug 12795985
4265 
4266 
4267     --c_Federal_Minimum_Wage := 5.15;  /* Current as of September 1997. */
4268     ln_M_F_Factor := GARN_EXEMPTION_MIN_WAGE_FACTOR;
4269     ln_M_S_Factor := NULL;
4270 
4271     -- Bug 4556146
4272     IF SUBSTR(Jurisdiction,1,2) = '07' THEN
4273         c_Federal_Minimum_Wage := STATE_MIN_WAGE;
4274     ELSIF (SUBSTR(Jurisdiction,1,2) = '14'
4275            AND (garn_category = 'G' OR garn_category = 'CD')) THEN
4276         c_State_Minimum_Wage := STATE_MIN_WAGE;
4277         hr_utility.trace('Setting State Minimum Wage for Illinois to ' || c_State_Minimum_Wage);
4278     -- Adding State Minimum Wage for Maine
4279     ELSIF (SUBSTR(Jurisdiction,1,2) = '20'
4280            AND (garn_category = 'G' OR garn_category = 'CD')) THEN
4281 	c_State_Minimum_Wage := STATE_MIN_WAGE;
4282         hr_utility.trace('Setting State Minimum Wage for Maine to : ' || c_State_Minimum_Wage);
4283     ELSIF (SUBSTR(Jurisdiction,1,2) = '06'
4284            AND (garn_category = 'G' OR garn_category = 'CD')) THEN
4285         c_State_Minimum_Wage := STATE_MIN_WAGE;
4286         hr_utility.trace('Setting State Minimum Wage for Colorado := ' || c_State_Minimum_Wage);
4287     END IF;
4288     --mesg1 := 'STATE_MIN_WAGE = '||TO_CHAR(STATE_MIN_WAGE);
4289 
4290     IF NVL(STATE_MIN_WAGE, 0) <> 0 AND (garn_category = 'G' OR garn_category = 'CD') THEN
4291        c_State_Minimum_Wage := STATE_MIN_WAGE;
4292        hr_utility.trace('For Garn Category CD and G State Min Wage to be used := '||c_State_Minimum_Wage);
4293     END IF;
4294 
4295     OPEN csr_elem_ovrd_fed_stat_M_count;
4296     FETCH csr_elem_ovrd_fed_stat_M_count INTO ln_ovrd_cnt;
4297     CLOSE csr_elem_ovrd_fed_stat_M_count;
4298 
4299     -- Checking Count()
4300     IF NVL(ln_ovrd_cnt,0) > 1 THEN
4301         STOP_ENTRY := 'Y';
4302         mesg := 'Multiple overrides for the same state exist at Element Extra Information level for '|| lv_ele_name
4303                 ||' in US Garnishment Processing Rules. Please correct your setup before running payroll.';
4304         to_total_owed := 0;
4305         if GLB_NUM_ELEM = 0 then
4306            GLB_SUPPORT_DI := NULL;
4307            GLB_OTHER_DI_FLAG := NULL;
4308            reset_global_var;
4309         end if;
4310         RETURN (1);
4311     END IF;
4312 
4313     OPEN csr_elem_ovrd_fed_stat_M;
4314     FETCH csr_elem_ovrd_fed_stat_M INTO lv_M_rule, ln_M_factor;
4315     CLOSE csr_elem_ovrd_fed_stat_M;
4316 
4317     hr_utility.trace('lv_M_rule := ' || lv_M_rule);
4318     hr_utility.trace('ln_M_F_factor := ' || ln_M_F_factor);
4319     hr_utility.trace('ln_M_S_factor := ' || ln_M_S_factor);
4320 
4321 
4322     IF lv_M_rule IS NOT NULL THEN
4323        IF lv_M_rule = 'H' THEN
4324           c_State_Minimum_Wage := GREATEST(c_Federal_Minimum_Wage, NVL(STATE_MIN_WAGE,0));
4325           IF ln_M_factor IS NOT NULL THEN
4326              ln_M_S_factor := ln_M_factor;
4327           ELSE
4328              ln_M_S_factor := GARN_EXEMPTION_MIN_WAGE_FACTOR;
4329           END IF;
4330        ELSIF lv_M_rule = 'S' THEN
4331           c_State_Minimum_Wage := NVL(STATE_MIN_WAGE, c_Federal_Minimum_Wage);
4332           IF ln_M_factor IS NOT NULL THEN
4333              ln_M_S_factor := ln_M_factor;
4334           ELSE
4335              ln_M_S_factor := GARN_EXEMPTION_MIN_WAGE_FACTOR;
4336           END IF;
4337        ELSIF lv_M_rule = 'F' THEN
4338           c_State_Minimum_Wage := c_Federal_Minimum_Wage;
4339           IF ln_M_factor IS NOT NULL THEN
4340              ln_M_F_factor := ln_M_factor;
4341           END IF;
4342        END IF;
4343     END IF;
4344 
4345     IF NVL(c_State_Minimum_Wage, 0) = 0 THEN
4346        c_State_Minimum_Wage := c_Federal_Minimum_Wage;
4347     END IF;
4348 
4349     /* Adding for Bug# 7600041 */
4350 
4351     IF NVL(ln_M_S_factor, 0) = 0 THEN
4352        IF NVL(ln_M_F_factor, 0) = 0 THEN
4353           ln_M_F_factor := 30;
4354        END IF;
4355     END IF;
4356 
4357 
4358     /* *** Calculation Section BEGIN *** */
4359     IF GARN_EXEMPTION_CALC_RULE = 'NOT_ALLOWED' THEN
4360         STOP_ENTRY := 'Y';
4361         mesg := 'This type of garnishment is not allowed in this state.';
4362         to_total_owed := 0;
4363         if GLB_NUM_ELEM = 0 then
4364            GLB_SUPPORT_DI := NULL;
4365            GLB_OTHER_DI_FLAG := NULL;
4366            reset_global_var;
4367         end if;
4368         RETURN (1);
4369     ELSIF GARN_EXEMPTION_CALC_RULE = 'ONE_FED' OR
4370           GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_AMT' OR
4371           GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_PCT' OR
4372           GARN_EXEMPTION_CALC_RULE = 'ONE_MARSTAT_RULE' OR
4373           GARN_EXEMPTION_CALC_RULE = 'ONE_EXEMPT_BALANCE' THEN
4374         IF GARN_TOTAL_DEDNS_ASG_GRE_RUN = 0 THEN
4375             IF Replacement_Amount_Balance <> 0 THEN
4376                 --dedn_amt := Replacement_Amount_Balance;
4377                 to_repl := -1 * Replacement_Amount_Balance;
4378             /*ELSIF Amount <> 0 THEN
4379                 dedn_amt := Amount;
4380             ELSIF Percentage <> 0 THEN
4381                 dedn_amt := (Percentage * c_Balance_Subject_to_Garn) / 100;
4382             ELSE
4383                 dedn_amt := c_Balance_Subject_to_Garn;*/
4384             END IF;
4385         ELSIF NOT GLB_ALLOW_MULT_DEDN THEN /* Bug 1481913 */
4386             dedn_amt := 0;
4387             calcd_dedn_amt := dedn_amt;
4388             to_total_owed := 0;
4389             mesg := 'Element ' || lv_ele_name || ' will not be processed as there is no Garnishment amount to be taken.';
4390             if GLB_NUM_ELEM = 0 then
4391                 GLB_SUPPORT_DI := NULL;
4392                 GLB_OTHER_DI_FLAG := NULL;
4393                 GLB_DCIA_EXIST_FLAG := NULL;
4394                 reset_global_var;
4395             end if;
4396             RETURN (2);
4397         END IF;
4398         GLB_ALLOW_MULT_DEDN := FALSE; /* Bug 1481913 */
4399 
4400     /* *** Check for override to wage attachment deduction amount. *** */
4401     ELSIF Replacement_Amount_Balance <> 0 THEN
4402         --dedn_amt := Replacement_Amount_Balance;
4403         to_repl := -1 * Replacement_Amount_Balance;
4404 
4405     /*ELSIF Amount <> 0 THEN
4406         dedn_amt := Amount;
4407 
4408     ELSIF Percentage <> 0 THEN
4409         dedn_amt := (Percentage * c_Balance_Subject_to_Garn) / 100;
4410     ELSE
4411         dedn_amt := c_Balance_Subject_to_Garn;*/
4412     END IF;
4413 
4414     /* *** Add in any adjustments. *** */
4415     IF Additional_Amount_Balance <> 0 THEN
4416         --dedn_amt := dedn_amt + Additional_Amount_Balance;
4417         to_addl := -1 * Additional_Amount_Balance;
4418     END IF;
4419 
4420     dedn_amt := gar_dedn_tab (P_CTX_ORIGINAL_ENTRY_ID);
4421     dedn_amt_cp := dedn_amt;
4422     total_garn_run := 0;
4423     cntr := gar_dedn_tab.first;
4424     WHILE cntr is not null LOOP
4425        hr_utility.trace('Garnishment deduction ('||cntr||') = '||gar_dedn_tab(cntr));
4426        total_garn_run := total_garn_run + gar_dedn_tab(cntr);
4427        cntr := gar_dedn_tab.NEXT(cntr);
4428     END LOOP;
4429 
4430 /* *** Arrears processing BEGIN *** */
4431 
4432     IF Monthly_Cap_Amount <> 0  THEN
4433         IF Monthly_Cap_Amount - Month_To_Date_Balance < 0 THEN
4434             fatal_mesg := 'MTD Balance > Monthly Cap by $' ||
4435                             TO_CHAR(Month_To_Date_Balance - Monthly_Cap_Amount ) ||
4436                             '. Adjust Balance for ' || lv_ele_name || '.';
4437             GLB_SUPPORT_DI := NULL;
4438             GLB_OTHER_DI_FLAG := NULL;
4439             GLB_DCIA_EXIST_FLAG := NULL;
4440             reset_global_var;
4441             RETURN (3);
4442         ELSIF dedn_amt + Month_To_Date_Balance > Monthly_Cap_Amount THEN
4443             -- Bug 4748532
4444             IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
4445                IF actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) > (Monthly_Cap_Amount - Month_To_Date_Balance) THEN
4446                   actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := Monthly_Cap_Amount - Month_To_Date_Balance;
4447                END IF;
4448                hr_utility.trace('Actual Deduction Amount(MTD) = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
4449                hr_utility.trace('Deduction Amount(MTD) = ' || DEDN_AMT);
4450             ELSE
4451                dedn_amt := Monthly_Cap_Amount - Month_To_Date_Balance;
4452             END IF;
4453         END IF;
4454     END IF;
4455 
4456     IF Period_Cap_Amount <> 0  THEN
4457         IF Period_Cap_Amount - Period_To_Date_Balance < 0 THEN
4458             fatal_mesg := 'PTD Balance > Period Cap by $' ||
4459 							 TO_CHAR(Period_To_Date_Balance - Period_Cap_Amount ) ||
4460                              '. Adjust Balance for ' || lv_ele_name || '.';
4461             GLB_SUPPORT_DI := NULL;
4462             GLB_OTHER_DI_FLAG := NULL;
4463             GLB_DCIA_EXIST_FLAG := NULL;
4464             reset_global_var;
4465             RETURN (4);
4466         ELSIF dedn_amt + Period_To_Date_Balance > Period_Cap_Amount THEN
4467             -- Bug 4748532
4468             IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
4469                IF actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) > (Period_Cap_Amount - Period_To_Date_Balance) THEN
4470                   actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) := Period_Cap_Amount - Period_To_Date_Balance;
4471                END IF;
4472                hr_utility.trace('Actual Deduction Amount(PTD) = ' || actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID));
4473                hr_utility.trace('Deduction Amount(PTD) = ' || DEDN_AMT);
4474             ELSE
4475                dedn_amt := Period_Cap_Amount - Period_To_Date_Balance;
4476             END IF;
4477         END IF;
4478     END IF;
4479 
4480     /**** Legislative limit verification BEGIN *****/
4481 
4482     Total_DI := c_Balance_Subject_to_Garn; /* Step #2 */
4483     ccpa_protection  := GET_CCPA_PROTECTION(Total_DI,
4484                                             ln_others_di,
4485                                             GLB_SUPPORT_DI,
4486                                             .25);
4487 
4488     /*-- Bug 3520523. Obtain the exemption percentage override value, if exists. --*/
4489     -- Bug 3800845
4490     -- Use the maximum of the 'Date Earned' and 'End Date' for finding
4491     -- the override values
4492     if P_CTX_DATE_EARNED > PAY_EARNED_END_DATE then
4493         ld_override_date := P_CTX_DATE_EARNED;
4494     else
4495         ld_override_date := PAY_EARNED_END_DATE;
4496     end if;
4497 
4498     FOR csr_exmpt_ovrd_rec IN csr_exmpt_ovrd(ld_override_date) LOOP
4499         l_exmpt_ovrd := csr_exmpt_ovrd_rec.entry_information4;
4500     END LOOP;
4501 
4502     /* Garnishment exemption by federal criteria. */
4503     IF GARN_EXEMPTION_DI_PCT = 0 AND (garn_category = 'EL' OR garn_category = 'DCIA') THEN
4504         fed_criteria_pct_prd_di_xmpt := .75 * Total_DI;
4505     ELSE
4506         IF nvl(l_exmpt_ovrd,default_number) = default_number THEN
4507            -- Bug 4318944 For Hawaii
4508            -- Convert the DI to PER Week DI and if calculate the Federal
4509            -- Exemption amount based on the Weekly DI
4510            IF SUBSTR(Jurisdiction,1,2) = '12' AND garn_category = 'CD' THEN
4511               di_total_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4512                                                    ASG_HOURS,
4513                                                    Total_DI,
4514                                                    'NOT ENTERED',
4515                                                    'WEEK',
4516                                                    PAY_EARNED_START_DATE,
4517                                                    PAY_EARNED_END_DATE,
4518                                                    ASG_FREQ);
4519 
4520               -- If DI is > 206 then 75% of the amount is exempted
4521               -- If it is < 206 and > 154.50 then the whole 154.5 is exempted
4522               IF di_total_week  > 206 THEN
4523                  fed_criteria_wk_prd_di_xmpt := 0.75 * di_total_week;
4524               ELSIF di_total_week  > 154.50 THEN
4525                  fed_criteria_wk_prd_di_xmpt := 154.50;
4526               ELSE
4527                  fed_criteria_wk_prd_di_xmpt := di_total_week;
4528               END IF;
4529               fed_criteria_pct_prd_di_xmpt := Convert_Period_Type(
4530                                                       SCL_ASG_US_WORK_SCHEDULE,
4531                                                       ASG_HOURS,
4532                                                       fed_criteria_wk_prd_di_xmpt,
4533                                                       'WEEK',
4534                                                       'NOT ENTERED',
4535                                                       PAY_EARNED_START_DATE,
4536                                                       PAY_EARNED_END_DATE,
4537                                                       ASG_FREQ);
4538               hr_utility.trace('Hawaii Credit Debt Federal Exemption Calculation');
4539               hr_utility.trace('Total Period DI = ' || Total_DI);
4540               hr_utility.trace('Total Weekly DI = ' || di_total_week);
4541               hr_utility.trace('Federal Weekly Exemption = ' || fed_criteria_wk_prd_di_xmpt);
4542               hr_utility.trace('Federal Period Exemption = ' || fed_criteria_pct_prd_di_xmpt);
4543            ELSE
4544               fed_criteria_pct_prd_di_xmpt := (GARN_EXEMPTION_DI_PCT / 100) * Total_DI;
4545            END IF;
4546         ELSE
4547             hr_utility.trace('Overriding exemption percentage = '||l_exmpt_ovrd);
4548             fed_criteria_pct_prd_di_xmpt := (l_exmpt_ovrd / 100) * Total_DI;
4549             -- Bug 4145789
4550             -- We override the CCPA value, if the Exemption percenatge
4551             -- overridden makes the DI value to be more than CCPA value
4552             -- therby allowing to deduct according to the Exemption percentage
4553             -- specified
4554             IF (Total_DI - fed_criteria_pct_prd_di_xmpt) > ccpa_protection THEN
4555                 ccpa_protection := Total_DI - fed_criteria_pct_prd_di_xmpt;
4556                 hr_utility.trace('New CCPA Value : ' || ccpa_protection);
4557             END IF;
4558         END IF;
4559     END IF;
4560 
4561     /* The period DI exemption must be converted to a Weekly figure. */
4562     fed_criteria_wk_prd_di_xmpt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,ASG_HOURS,
4563                                                         fed_criteria_pct_prd_di_xmpt,
4564                                                         'NOT ENTERED',
4565                                                         'WEEK',
4566                                                          PAY_EARNED_START_DATE,
4567                                                          PAY_EARNED_END_DATE,
4568                                                          ASG_FREQ);
4569 
4570     hr_utility.trace('fed_criteria_pct_prd_di_xmpt = '||fed_criteria_pct_prd_di_xmpt);
4571     IF GARN_EXEMPTION_MIN_WAGE_FACTOR = 0 AND (garn_category = 'EL' or garn_category = 'DCIA') THEN
4572 
4573         /* Adding for Bug# 7600041 */
4574         IF NVL(ln_M_F_Factor, 0) = 0 THEN
4575            ln_M_F_Factor := 30;
4576         END IF;
4577 
4578         fed_criteria_minwage_exemption := NVL(ln_M_F_Factor, 30) * c_Federal_Minimum_Wage;
4579     ELSE
4580         fed_criteria_minwage_exemption := NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage;
4581     END IF;
4582 
4583     fed_criteria_exemption := GREATEST(fed_criteria_wk_prd_di_xmpt,
4584                                        fed_criteria_minwage_exemption);
4585     hr_utility.trace('fed_criteria_wk_prd_di_xmpt = '||fed_criteria_wk_prd_di_xmpt);
4586     hr_utility.trace('fed_criteria_minwage_exemption = '||fed_criteria_minwage_exemption);
4587     /* Garnishment exemption by state specific criteria. */
4588     DI_state_exemption_amt := 0;
4589     DI_state_dependents_exemption := 0;
4590 
4591     -- Bug 4079142
4592     -- Added the IF condition as State Exemption Calculation as DCIA is
4593     -- Federal Involuntary Deduction
4594 
4595 --    VMKULKAR
4596 
4597     l_garn_exemption_amount_value := GARN_EXEMPTION_AMOUNT_VALUE;
4598 
4599     hr_utility.trace('Before l_garn_exemption_amount_value = '||l_garn_exemption_amount_value);
4600 
4601 
4602     hr_utility.trace('Vallabh Jurisdiction = '||Jurisdiction);
4603 
4604     hr_utility.trace('Vallabh garn_category = '||garn_category);
4605 
4606     IF SUBSTR(Jurisdiction,1,2) = '38' AND garn_category in ('CD','G') THEN
4607 
4608     hr_utility.trace('Inside Vallabh IF');
4609 
4610     hr_utility.trace('P_CTX_PAYROLL_ID = '||P_CTX_PAYROLL_ID);
4611     hr_utility.trace('p_ctx_date_earned = '||p_ctx_date_earned);
4612 
4613 
4614     -- Get the pay period length
4615 	OPEN c_get_pay_period_length(P_CTX_PAYROLL_ID);
4616 	fetch c_get_pay_period_length into l_pay_period_length;
4617 	close c_get_pay_period_length;
4618 
4619     hr_utility.trace('l_pay_period_length = '||l_pay_period_length);
4620 
4621     -- Get the exemption amount
4622 
4623 	OPEN c_get_state_garn_exemption_amt(l_pay_period_length,'Oregon');
4624 	fetch c_get_state_garn_exemption_amt into l_state_period_exemption_amt;
4625 	close c_get_state_garn_exemption_amt;
4626 
4627     hr_utility.trace('l_state_period_exemption_amt = '||l_state_period_exemption_amt);
4628 
4629 
4630         l_garn_exemption_amount_value := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4631                                               ASG_HOURS,
4632                                               l_state_period_exemption_amt,
4633                                               'NOT ENTERED',
4634                                               'WEEK',
4635                                               PAY_EARNED_START_DATE,
4636                                               PAY_EARNED_END_DATE,
4637                                               ASG_FREQ);
4638 
4639     hr_utility.trace('GARN_EXEMPTION_AMOUNT_VALUE = '||GARN_EXEMPTION_AMOUNT_VALUE);
4640     hr_utility.trace('Leaving Vallabh IF');
4641 
4642 
4643     END IF;
4644 
4645 --    VMKULKAR
4646 
4647     hr_utility.trace('After l_garn_exemption_amount_value = '||l_garn_exemption_amount_value);
4648 
4649 
4650     IF GARN_CATEGORY <> 'DCIA' THEN -- Bug# 6068769
4651        IF GARN_EXEMPTION_CALC_RULE = 'FEDRULE' OR
4652            GARN_EXEMPTION_CALC_RULE = 'ONE_FED' THEN
4653              DI_state_exemption_amt := 0;
4654        ELSIF GARN_EXEMPTION_CALC_RULE = 'FLAT_AMT' OR
4655            GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_AMT' THEN
4656            DI_state_exemption_amt := l_garn_exemption_amount_value;
4657        ELSIF GARN_EXEMPTION_CALC_RULE = 'FLAT_PCT' OR
4658            GARN_EXEMPTION_CALC_RULE = 'ONE_FLAT_PCT' THEN
4659            hr_utility.trace('inv_dedn_in_run = '||inv_dedn_in_run);
4660 
4661            -- Bug 4318944 For Hawaii
4662            -- Convert the DI calculated to monthly DI value for Hawaii
4663            -- and then calculate the exemption amount on it.
4664            IF SUBSTR(Jurisdiction,1,2) = '12' AND garn_category = 'CD' THEN
4665               total_di_month := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4666                                                     ASG_HOURS,
4667                                                     Total_DI,
4668                                                     'NOT ENTERED',
4669                                                     'MONTH',
4670                                                     PAY_EARNED_START_DATE,
4671                                                     PAY_EARNED_END_DATE,
4672                                                     ASG_FREQ);
4673               IF total_di_month > 200 THEN
4674                  DI_hawaii_max_cd_month := 5 + 10 + ((100 - GARN_EXEMPTION_AMOUNT_VALUE)/100) * (total_di_month - 200);
4675               ELSIF total_di_month > 100 THEN
4676                  DI_hawaii_max_cd_month := 5 + 0.1 * (total_di_month - 100);
4677               ELSE
4678                  DI_hawaii_max_cd_month := 0.05 * total_di_month;
4679               END IF;
4680               DI_hawaii_max_cd := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4681                                                       ASG_HOURS,
4682                                                       DI_hawaii_max_cd_month,
4683                                                       'MONTH',
4684                                                       'NOT ENTERED',
4685                                                       PAY_EARNED_START_DATE,
4686                                                       PAY_EARNED_END_DATE,
4687                                                       ASG_FREQ);
4688               hr_utility.trace('Hawaii Credit Debt Calculation');
4689               hr_utility.trace('Total Period DI = ' || Total_DI);
4690               hr_utility.trace('Total Monthly DI = ' || total_di_month);
4691               hr_utility.trace('Max Monthly CD deduction = ' || DI_hawaii_max_cd_month);
4692               hr_utility.trace('Max Period CD deduction = ' || DI_hawaii_max_cd);
4693            END IF;
4694 
4695            IF inv_dedn_in_run > 0 THEN
4696                diff := ccpa_protection - inv_dedn_in_run;
4697                hr_utility.trace('ccpa_protection = ' || ccpa_protection);
4698                hr_utility.trace('GARN_EXEMPTION_AMOUNT_VALUE = ' || GARN_EXEMPTION_AMOUNT_VALUE);
4699                hr_utility.trace('Total_DI = ' || Total_DI);
4700                max_garn := ((100 - GARN_EXEMPTION_AMOUNT_VALUE) / 100 ) * Total_DI;
4701                -- Bug 4318944 For Hawaii Credit Debt
4702                IF SUBSTR(Jurisdiction,1,2) = '12' AND garn_category = 'CD' THEN
4703                   max_garn := DI_hawaii_max_cd;
4704                END IF;
4705                IF diff >= 0 THEN
4706                    IF diff >= max_garn THEN
4707                        diff := max_garn;
4708                        DI_state_exemption_amt := Total_DI-(inv_dedn_in_run+diff);
4709                    END IF;
4710                ELSE
4711                    -- Bug 4318944 For Hawaii Credit Debt
4712                    IF SUBSTR(Jurisdiction,1,2) = '12' AND garn_category = 'CD' THEN
4713                       DI_state_exemption_amt := Total_DI - DI_hawaii_max_cd;
4714                    ELSE
4715                       DI_state_exemption_amt := (GARN_EXEMPTION_AMOUNT_VALUE / 100) * Total_DI;
4716                    END IF;
4717                END IF;
4718            ELSE
4719                IF SUBSTR(Jurisdiction,1,2) = '12' AND garn_category = 'CD' THEN
4720                   DI_state_exemption_amt := Total_DI - DI_hawaii_max_cd;
4721                ELSE
4722                   DI_state_exemption_amt := (GARN_EXEMPTION_AMOUNT_VALUE / 100) * Total_DI;
4723                END IF;
4724            END IF;
4725 
4726            -- If DCIA element is processed then CCPA Protection is taken care by the
4727            -- code written for DCIA.
4728            -- Handling CCPA Protection here results in incorrect calculations when
4729            -- handled later.
4730            if GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' then -- Bug# 6068769
4731                DI_state_exemption_amt := (GARN_EXEMPTION_AMOUNT_VALUE / 100) * Total_DI;
4732            end if;
4733            hr_utility.trace('FLAT_PCT => EL DI_state_exemption_amt := '||DI_state_exemption_amt);
4734 
4735            /*
4736             * Moved the calculation of 'DI_state_exemption_amt' from the
4737             * ELSE part above to outside the IF condition for the same. (3737081)
4738             */
4739            DI_state_exemption_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4740                                                          ASG_HOURS,
4741                                                          DI_state_exemption_amt,
4742                                                          'NOT ENTERED',
4743                                                          'WEEK',
4744                                                          PAY_EARNED_START_DATE,
4745                                                          PAY_EARNED_END_DATE,
4746                                                          ASG_FREQ);
4747            hr_utility.trace('Weekly DI_state_exemption_amt := '||DI_state_exemption_amt);
4748 
4749        ELSIF GARN_EXEMPTION_CALC_RULE = 'MARSTAT_RULE' OR
4750              GARN_EXEMPTION_CALC_RULE = 'ONE_MARSTAT_RULE' THEN
4751            IF SUBSTR(Jurisdiction,1,2) = '02' /* Alaska */  THEN
4752 
4753              IF P_CTX_DATE_EARNED < fnd_date.canonical_to_date('2009/01/01') THEN
4754                 IF Filing_Status = '01' THEN  /* SINGLE */
4755                     DI_state_exemption_amt := 420;
4756                 ELSE /* otherwise considered H OF H */
4757                    DI_state_exemption_amt := 660;
4758                 END IF;
4759              ELSE
4760                 DI_state_exemption_amt := 456; -- Alaska changes effective 1st Jan, 2009
4761              END IF;
4762 
4763            ELSIF SUBSTR(Jurisdiction,1,2) = '04' /* Arkansas */  THEN
4764                IF Filing_Status = '01' THEN  /* SINGLE */
4765                    DI_state_exemption_amt := 200;
4766                ELSE /* otherwise considered H OF H */
4767                    DI_state_exemption_amt := 500;
4768                END IF;
4769            ELSIF SUBSTR(Jurisdiction,1,2) = '10' /* Florida */  THEN
4770                IF Filing_Status = '04' THEN  /* HEAD OF HOUSEHOLD */
4771                    DI_state_exemption_amt := 500;
4772                END IF;
4773            -- Commenting for Bug# 5706544
4774            --ELSIF SUBSTR(Jurisdiction,1,2) = '26' /* Missouri */  THEN
4775                --IF Filing_Status = '04' THEN  /* HEAD OF HOUSEHOLD */
4776                    --DI_state_exemption_amt := .9 * Total_DI;
4777                --END IF;
4778            ELSIF SUBSTR(Jurisdiction,1,2) = '28' /* Nebraska */  THEN
4779                -- Bug# 6063353 (Filing Status '04' is not for HOH)
4780                IF Filing_Status = '03' THEN  /* HEAD OF HOUSEHOLD */
4781                    DI_state_exemption_amt := .85 * Total_DI;
4782                END IF;
4783                hr_utility.trace('Converting into Weekly Figure.') ;
4784 
4785                DI_state_exemption_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4786                                                              ASG_HOURS,
4787                                                              DI_state_exemption_amt,
4788                                                              'NOT ENTERED',
4789                                                              'WEEK',
4790                                                              PAY_EARNED_START_DATE,
4791                                                              PAY_EARNED_END_DATE,
4792                                                              ASG_FREQ);
4793                hr_utility.trace('DI_state_exemption_amt (Weekly) := '||DI_state_exemption_amt) ;
4794 
4795            END IF;
4796        ELSIF GARN_EXEMPTION_CALC_RULE = 'EXEMPT_BALANCE' OR
4797              GARN_EXEMPTION_CALC_RULE = 'ONE_EXEMPT_BALANCE' THEN
4798            IF SUBSTR(Jurisdiction,1,2) = '12' /* Hawaii */  THEN
4799                IF GROSS_EARNINGS_ASG_GRE_MONTH < c_hawaii_range_1_mnth_erngs THEN
4800                    DI_state_exemption_amt := c_Hawaii_Pct_Exempt_Range_1 *
4801                                              GROSS_EARNINGS_ASG_GRE_MONTH;
4802                ELSIF GROSS_EARNINGS_ASG_GRE_MONTH < c_hawaii_range_2_mnth_erngs THEN
4803                    DI_state_exemption_amt := (c_Hawaii_Pct_Exempt_Range_1 *
4804                                               c_hawaii_range_1_mnth_erngs) +
4805                                                  (c_Hawaii_Pct_Exempt_Range_2 *
4806                                                    ( c_hawaii_range_2_mnth_erngs -
4807                                                      c_hawaii_range_1_mnth_erngs));
4808                ELSE
4809                    DI_state_exemption_amt := (c_Hawaii_Pct_Exempt_Range_1 *
4810                                               c_hawaii_range_1_mnth_erngs) +
4811                                                    (c_Hawaii_Pct_Exempt_Range_2 *
4812                                                        (c_hawaii_range_2_mnth_erngs -
4813                                                         c_hawaii_range_1_mnth_erngs)) +
4814                                                        (c_Hawaii_Pct_Exempt_Range_3 *
4815                                                            (GROSS_EARNINGS_ASG_GRE_MONTH -
4816                                                        c_hawaii_range_2_mnth_erngs));
4817                END IF;
4818            ELSIF SUBSTR(Jurisdiction,1,2) = '14' /* Illinois */  THEN
4819                Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4820                                                         ASG_HOURS,
4821                                                         Total_DI,
4822                                                         'NOT ENTERED',
4823                                                         'WEEK',
4824                                                         PAY_EARNED_START_DATE,
4825                                                         PAY_EARNED_END_DATE,
4826                                                         ASG_FREQ);
4827                earnings_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4828                                                         ASG_HOURS,
4829                                                         GROSS_EARNINGS_ASG_GRE_RUN,
4830                                                         'NOT ENTERED',
4831                                                         'WEEK',
4832                                                         PAY_EARNED_START_DATE,
4833                                                         PAY_EARNED_END_DATE,
4834                                                         ASG_FREQ);
4835                DI_state_exemption_amt := GREATEST((0.85 * earnings_per_week),
4836                                                        NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4837                                                        NVL(c_State_Minimum_Wage,c_Federal_Minimum_Wage));
4838                hr_utility.trace('Total_DI_per_week = ' || Total_DI_per_week);
4839                hr_utility.trace('earnings_per_week = ' || earnings_per_week);
4840                hr_utility.trace('DI_state_exemption_amt per week = ' || DI_state_exemption_amt);
4841 
4842                -- Bug 4556146
4843                IF (garn_category = 'G' OR garn_category = 'CD') THEN
4844                   lb_use_state_min_wage := FALSE;
4845                   IF date_served = default_date THEN
4846                      open csr_get_entry_start_date;
4847                      fetch csr_get_entry_start_date into ld_entry_start_date;
4848                      close csr_get_entry_start_date;
4849                      IF ld_entry_start_date >= fnd_date.canonical_to_date('2006/01/01') THEN
4850                         lb_use_state_min_wage := TRUE;
4851                         DI_state_exemption_amt := GREATEST(DI_state_exemption_amt,
4852                                                            NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * NVL(c_State_Minimum_Wage, c_Federal_Minimum_Wage));
4853                      END IF;
4854                   ELSIF date_served >= fnd_date.canonical_to_date('2006/01/01') THEN
4855                      lb_use_state_min_wage := TRUE;
4856                      DI_state_exemption_amt := GREATEST(DI_state_exemption_amt,
4857                                                         NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * NVL(c_State_Minimum_Wage, c_Federal_Minimum_Wage));
4858                   END IF;
4859 
4860                   IF DI_state_exemption_amt = 0.85 * earnings_per_week THEN
4861                     if lv_M_rule is not null then
4862                         DI_state_exemption_amt := Total_DI_per_week -
4863                                                 (LEAST ( 0.15 * earnings_per_week ,
4864                                                 ( Total_DI_per_week -  NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4865                                                 c_Federal_Minimum_Wage),( Total_DI_per_week -  NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4866                                                 c_State_Minimum_Wage)));
4867                     else
4868                      IF lb_use_state_min_wage THEN
4869                         DI_state_exemption_amt := Total_DI_per_week -
4870                                                 (LEAST ( 0.15 * earnings_per_week ,
4871                                                 ( Total_DI_per_week -  NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4872                                                 c_Federal_Minimum_Wage),( Total_DI_per_week -  NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4873                                                 c_State_Minimum_Wage)));
4874                      ELSE
4875                         DI_state_exemption_amt := Total_DI_per_week -
4876                                                 (LEAST ( 0.15 * earnings_per_week ,
4877                                                 ( Total_DI_per_week -  GARN_EXEMPTION_MIN_WAGE_FACTOR *
4878                                                 c_Federal_Minimum_Wage)));
4879                      END IF;
4880                     end if;
4881                   END IF;
4882                ELSE
4883                   IF DI_state_exemption_amt = 0.85 * earnings_per_week THEN
4884                       DI_state_exemption_amt := Total_DI_per_week -
4885                                               (LEAST ( 0.15 * earnings_per_week ,
4886                                               ( Total_DI_per_week -  NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4887                                               c_Federal_Minimum_Wage),
4888                                               ( Total_DI_per_week -  NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) *
4889                                               c_State_Minimum_Wage)));
4890                   END IF;
4891                END IF; -- IF garn_category = 'G' OR
4892            ELSIF SUBSTR(Jurisdiction,1,2) = '31' /* New Jersey */  THEN
4893                Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4894                                                         ASG_HOURS,Total_DI,
4895                                                         'NOT ENTERED',
4896                                                         'WEEK',
4897                                                         PAY_EARNED_START_DATE,
4898                                                         PAY_EARNED_END_DATE,
4899                                                         ASG_FREQ);
4900                earnings_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4901                                                         ASG_HOURS,
4902                                                         GROSS_EARNINGS_ASG_GRE_RUN,
4903                                                         'NOT ENTERED',
4904                                                         'WEEK',
4905                                                         PAY_EARNED_START_DATE,
4906                                                         PAY_EARNED_END_DATE,
4907                                                         ASG_FREQ);
4908                /*-- Bug 3520523 --*/
4909                IF nvl(l_exmpt_ovrd,0) = 0 THEN
4910                    DI_state_exemption_amt := GREATEST((GARN_EXEMPTION_DI_PCT/100) * Total_DI_per_week,
4911                                                       Total_DI_per_week - (0.10 * earnings_per_week),
4912                                                       NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage,
4913                                                       NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage);
4914                ELSE
4915                    DI_state_exemption_amt := GREATEST((l_exmpt_ovrd/100) * Total_DI_per_week,
4916                                                       Total_DI_per_week - (0.10 * earnings_per_week),
4917                                                       NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage,
4918                                                       NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage);
4919                END IF;
4920 
4921            ELSIF SUBSTR(Jurisdiction,1,2) = '33' /* New York */  THEN
4922                Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4923                                                         ASG_HOURS,Total_DI,
4924                                                         'NOT ENTERED',
4925                                                         'WEEK',
4926                                                         PAY_EARNED_START_DATE,
4927                                                         PAY_EARNED_END_DATE,
4928                                                         ASG_FREQ);
4929 
4930                earnings_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4931                                                         ASG_HOURS,
4932                                                         GROSS_EARNINGS_ASG_GRE_RUN,
4933                                                         'NOT ENTERED',
4934                                                         'WEEK',
4935                                                         PAY_EARNED_START_DATE,
4936                                                         PAY_EARNED_END_DATE,
4937                                                         ASG_FREQ);
4938 
4939                IF Total_DI_per_week <
4940                   GREATEST((c_ny_minwage_exmpt_multpl_1 * c_Federal_Minimum_Wage)
4941                           ,NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage
4942                           ,NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage)  THEN
4943                    DI_state_exemption_amt := Total_DI_per_week;
4944                ELSE
4945                    DI_state_exemption_amt := c_ny_di_exmpt_pct * Total_DI_per_week;
4946                END IF;
4947 
4948            ELSIF SUBSTR(Jurisdiction,1,2) = '37' /* Oklahoma */  THEN
4949                earnings_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4950                                                         ASG_HOURS,
4951                                                         GROSS_EARNINGS_ASG_GRE_RUN,
4952                                                         'NOT ENTERED',
4953                                                         'WEEK',
4954                                                         PAY_EARNED_START_DATE,
4955                                                         PAY_EARNED_END_DATE,
4956                                                         ASG_FREQ);
4957                IF earnings_per_week < c_ok_range_1_wkly_erngs THEN
4958                    DI_state_exemption_amt := GROSS_EARNINGS_ASG_GRE_RUN;
4959                ELSIF earnings_per_week < c_ok_range_2_wkly_erngs THEN
4960                    OK_weekly_state_exemption_amt := earnings_per_week - c_ok_range_1_wkly_erngs;
4961                    DI_state_exemption_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4962                                                                  ASG_HOURS,
4963                                                                  OK_weekly_state_exemption_amt,
4964                                                                  'NOT ENTERED',
4965                                                                  'WEEK',
4966                                                                  PAY_EARNED_START_DATE,
4967                                                                  PAY_EARNED_END_DATE,
4968                                                                  ASG_FREQ);
4969                ELSE
4970                    DI_state_exemption_amt := c_Oklahoma_earnings_exempt_pct * GROSS_EARNINGS_ASG_GRE_RUN;
4971                END IF;
4972                DI_state_exemption_amt := GREATEST(DI_state_exemption_amt,
4973                                                   NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage
4974                                                  ,NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage);
4975            END IF;
4976        END IF;
4977        -- Bug# 6194070
4978        -- For State of Maine 'Garnishment' and 'Credit Debt'
4979        -- Higher of 25% weekly DI or Factor of Federal or State Min Wage
4980        IF (SUBSTR(Jurisdiction,1,2) = '20'
4981             AND garn_category IN ('CD', 'G')) THEN
4982               Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
4983                                                         ASG_HOURS,
4984                                                         Total_DI,
4985                                                         'NOT ENTERED',
4986                                                         'WEEK',
4987                                                         PAY_EARNED_START_DATE,
4988                                                         PAY_EARNED_END_DATE,
4989                                                         ASG_FREQ);
4990 	       hr_utility.trace('For Maine CD or G Total_DI_per_week := '||Total_DI_per_week);
4991 	       hr_utility.trace('0.75 * Total_DI_per_week := '||(0.75 * Total_DI_per_week));
4992 	       hr_utility.trace('Federal Exemption := '||(NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage));
4993 	       hr_utility.trace('State Exemption := '||(NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage));
4994 
4995                DI_state_exemption_amt := GREATEST((0.75 * Total_DI_per_week),
4996                                                   (NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage),
4997 						  (NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage));
4998 
4999                hr_utility.trace('DI_state_exemption_amt For maine  CD / G := '||DI_state_exemption_amt);
5000 
5001        END IF;
5002 
5003     END IF; /* IF GARN_CATEGORY <> 'DCIA' */
5004 
5005     -- 4079142
5006     -- Added the IF condition as State Dependents Exemption Calculation as DCIA is
5007     -- Federal Involuntary Deduction
5008 
5009     IF GARN_CATEGORY <> 'DCIA' THEN -- No Change needed for Bug# 6068769 ?
5010        IF GRN_EXMPT_DEP_CALC_RULE <> 'NONE' THEN
5011            IF GRN_EXMPT_DEP_CALC_RULE = 'FLAT_AMT' THEN
5012                IF SUBSTR(Jurisdiction,1,2) = '23' /* Michigan */  THEN
5013                    IF Filing_Status = '04' THEN  /* Head of Household gets dep exemption */
5014                        DI_state_dependents_exemption := GRN_EXMPT_DEP_AMT_VAL *
5015                                                         Num_Dependents;
5016                    ELSE
5017                        DI_state_dependents_exemption := GRN_EXMPT_DEP_AMT_VAL *
5018                                                         Num_Dependents;
5019                    END IF;
5020                END IF;
5021            ELSIF GRN_EXMPT_DEP_CALC_RULE = 'FLAT_AMT_ADDL' THEN
5022                DI_state_dependents_exemption := GRN_EXMPT_DEP_AMT_VAL +
5023                                                 (GRN_EXMPT_ADDL_DEP_AMT_VAL *
5024                                                 (Num_Dependents - 1));
5025            ELSIF GRN_EXMPT_DEP_CALC_RULE = 'FLAT_PCT' THEN
5026                DI_state_addl_pct_exempt := GRN_EXMPT_DEP_AMT_VAL * Num_Dependents;
5027                DI_state_dependents_exemption := (DI_state_addl_pct_exempt / 100) * Total_DI;
5028                DI_state_dependents_exemption := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5029                                                                     ASG_HOURS,
5030                                                                     DI_state_dependents_exemption,
5031                                                                     'NOT ENTERED',
5032                                                                     'WEEK',
5033                                                                     PAY_EARNED_START_DATE,
5034                                                                     PAY_EARNED_END_DATE,
5035                                                                     ASG_FREQ);
5036            ELSIF GRN_EXMPT_DEP_CALC_RULE = 'FLAT_PCT_ADDL' THEN
5037                DI_state_addl_pct_exempt := GRN_EXMPT_DEP_AMT_VAL +
5038                                           (GRN_EXMPT_ADDL_DEP_AMT_VAL * (Num_Dependents - 1));
5039                DI_state_dependents_exemption := (DI_state_addl_pct_exempt / 100) * Total_DI;
5040                DI_state_dependents_exemption := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5041                                                                     ASG_HOURS,
5042                                                                     DI_state_dependents_exemption,
5043                                                                     'NOT ENTERED',
5044                                                                     'WEEK',
5045                                                                     PAY_EARNED_START_DATE,
5046                                                                     PAY_EARNED_END_DATE,
5047                                                                     ASG_FREQ);
5048            END IF;
5049        END IF;
5050     END IF; /* IF GARN_CATEGORY <> 'DCIA' */
5051 
5052 --bug 10359431 changes starts here
5053 IF SUBSTR(Jurisdiction,1,2) = '06' and garn_category IN ('CD', 'G') then
5054     DI_state_exemption_amt:=GARN_EXEMPTION_MIN_WAGE_FACTOR * c_State_Minimum_Wage;
5055      /*Commented this code for bug 13546097
5056        period type conversion call is not required, calculation is weekly.
5057      DI_state_exemption_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5058                                                   ASG_HOURS,
5059                                                   DI_state_exemption_amt,
5060                                                   'NOT ENTERED',
5061                                                   'WEEK',
5062                                                   PAY_EARNED_START_DATE,
5063                                                   PAY_EARNED_END_DATE,
5064                                                   ASG_FREQ);*/
5065 end if;
5066 --bug 10359431 ends starts here
5067 
5068 
5069 /*Below code added for 12529733, changed for 12795985. It is gross wage that
5070   needs to be considered and not DI.
5071   Bug 12529733, 12795985 changes starts here*/
5072 IF SUBSTR(Jurisdiction,1,2) = '22' and garn_category IN ('CD', 'G') then
5073    IF P_CTX_DATE_EARNED > fnd_date.canonical_to_date('2011/04/06') THEN
5074     DI_state_exemption_amt := c_MA_gross_erngs_exmpt_pct * GROSS_EARNINGS_ASG_GRE_RUN;
5075     DI_state_exemption_amt := Total_DI - (GROSS_EARNINGS_ASG_GRE_RUN - DI_state_exemption_amt);
5076    	DI_state_exemption_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5077                                                   ASG_HOURS,
5078                                                   DI_state_exemption_amt,
5079                                                   'NOT ENTERED',
5080                                                   'WEEK',
5081                                                   PAY_EARNED_START_DATE,
5082                                                   PAY_EARNED_END_DATE,
5083                                                   ASG_FREQ);
5084     DI_state_exemption_amt := GREATEST( DI_state_exemption_amt,
5085                                        ( c_MA_minwage_exmpt_multpl * c_State_Minimum_Wage )
5086                                       );
5087    END IF;
5088 END IF;
5089 --Bug 12529733, 12795985 ends here
5090 
5091 --bug 14726857 changes starts here
5092 IF SUBSTR(Jurisdiction,1,2) = '05' and garn_category IN ('CD', 'G') then
5093     DI_state_exemption_amt:=GARN_EXEMPTION_MIN_WAGE_FACTOR * c_State_Minimum_Wage;
5094 end if;
5095 --bug 14726857 ends starts here
5096 
5097     DI_total_state_exemption := DI_state_exemption_amt + DI_state_dependents_exemption;
5098     hr_utility.trace('DI_state_exemption_amt = '||DI_state_exemption_amt);
5099     hr_utility.trace('DI_state_dependents_exemption = '||DI_state_dependents_exemption);
5100     hr_utility.trace('DI_total_state_exemption = '||DI_total_state_exemption);
5101 
5102     -- Change for Bug# 5150447
5103     -- Change Garn Category for Bug# 5688488
5104     --IF garn_category <> 'BO' THEN
5105     IF garn_category IN ('CD', 'G') THEN
5106 
5107        IF Substr(Jurisdiction,1,2) = '26' THEN
5108 
5109           open c_get_res_state_code(ctx_element_entry_id) ;
5110           fetch c_get_res_state_code into ln_assignment_id, ln_resident_state_code ;
5111           IF c_get_res_state_code%notfound THEN
5112              close c_get_res_state_code ;
5113            END IF ;
5114            hr_utility.trace('ln_assignment_id '|| to_char(ln_assignment_id)) ;
5115            hr_utility.trace('ln_resident_state_code '|| ln_resident_state_code) ;
5116 
5117            open c_get_allowance_value('Filing Status');
5118            fetch c_get_allowance_value into ln_filing_status_code;
5119            close c_get_allowance_value;
5120 
5121            hr_utility.trace('Element Level: ln_filing_status_code := '|| ln_filing_status_code) ;
5122 
5123            IF ln_filing_status_code IS NULL THEN
5124               open c_get_filing_status(ln_assignment_id) ;
5125               fetch c_get_filing_status into ln_filing_status_code ;
5126               IF c_get_filing_status%notfound THEN
5127                  close c_get_filing_status ;
5128               END IF ;
5129            END IF ;
5130            hr_utility.trace('ln_filing_status_code '|| ln_filing_status_code) ;
5131 
5132            IF ln_resident_state_code = '26'
5133               and ln_filing_status_code = '03' THEN
5134 
5135               Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5136                                                         ASG_HOURS,
5137                                                         Total_DI,
5138                                                         'NOT ENTERED',
5139                                                         'WEEK',
5140                                                         PAY_EARNED_START_DATE,
5141                                                         PAY_EARNED_END_DATE,
5142                                                         ASG_FREQ);
5143 
5144               DI_total_state_exemption := GREATEST(DI_total_state_exemption,
5145 	                                           0.9 * Total_DI_per_week) ;
5146               hr_utility.trace('DI_total_state_exemption '|| to_char(DI_total_state_exemption)) ;
5147 
5148            END IF ;
5149         END IF ;
5150     END IF ;
5151     -- End of Change for Bug# 5150447
5152     /*
5153     DI_total_state_exemption := GREATEST(DI_total_state_exemption,
5154                                         NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage,
5155                                         NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage);
5156     */
5157     -- Bug 4079142
5158     ---Bug #9284206 Added the Category 'EL' to the if condition so that for Education loan
5159     --- of illinois state is deducted as per the federal minimum wage.
5160     ---
5161     IF ((SUBSTR(Jurisdiction,1,2) = '14') and (GARN_CATEGORY NOT IN ('DCIA','EL'))) THEN -- No Change Neede for Bug# 6068769 ?
5162         DI_total_exemption := DI_total_state_exemption;
5163     ELSE
5164         DI_total_exemption := GREATEST(fed_criteria_exemption,
5165                                        DI_total_state_exemption);
5166     END IF;
5167     hr_utility.trace('fed_criteria_exemption = '||fed_criteria_exemption);
5168     hr_utility.trace('DI_total_exemption = '||DI_total_exemption);
5169 
5170 --  Code change to be started here for Bug# 6818016
5171     IF GARN_CATEGORY IN ('CD', 'G') THEN
5172 
5173        IF (NET_ASG_PTD - NET_ASG_RUN) > 0 THEN
5174        -- added for bug#14357293
5175 	       if NET_ASG_PTD > DI_total_state_exemption then
5176 	         DI_total_state_exemption := 0;
5177 	       else
5178 	         DI_total_state_exemption := DI_total_state_exemption - NET_ASG_PTD;
5179 	       end if;
5180 	     -- ended 14357293
5181        tmp_DI_total_week_exempt := GREATEST(fed_criteria_wk_prd_di_xmpt, DI_total_state_exemption);
5182        tmp_fed_state_week_exemption := GREATEST(NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage,
5183                                                 NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage);
5184 
5185        hr_utility.trace('tmp_DI_total_week_exempt := ' || tmp_DI_total_week_exempt);
5186        hr_utility.trace('tmp_fed_state_week_exemption := ' || tmp_fed_state_week_exemption);
5187 
5188        IF tmp_fed_state_week_exemption > tmp_DI_total_week_exempt THEN
5189 
5190          -- Temporary Calculation for NET_ASG_PTD per week
5191          tmp_net_asg_ptd_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5192                                                         ASG_HOURS,
5193                                                         (NET_ASG_PTD - NET_ASG_RUN),
5194                                                         'NOT ENTERED',
5195                                                         'WEEK',
5196                                                         PAY_EARNED_START_DATE,
5197                                                         PAY_EARNED_END_DATE,
5198                                                         ASG_FREQ);
5199 
5200             hr_utility.trace('tmp_net_asg_ptd_week := ' || tmp_net_asg_ptd_week);
5201 
5202             -- Should it be tmp_net_asg_ptd_week
5203             -- Or, Aggregate DI for all Previous Runs for the Period
5204             -- But no way to get Aggregate DI as there is No Balance
5205             -- Following would be Most probable case
5206 
5207             IF (tmp_net_asg_ptd_week + tmp_DI_total_week_exempt) >= tmp_fed_state_week_exemption THEN
5208                DI_total_exemption := tmp_DI_total_week_exempt;
5209             ELSE
5210                -- Temporary Calculation for NET_ASG_RUN per week
5211                tmp_net_asg_run_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5212                                                         ASG_HOURS,
5213                                                         NET_ASG_RUN,
5214                                                         'NOT ENTERED',
5215                                                         'WEEK',
5216                                                         PAY_EARNED_START_DATE,
5217                                                         PAY_EARNED_END_DATE,
5218                                                         ASG_FREQ);
5219 
5220                hr_utility.trace('tmp_net_asg_run_week := ' || tmp_net_asg_run_week);
5221 
5222                IF tmp_fed_state_week_exemption > tmp_net_asg_run_week THEN
5223                   IF (tmp_net_asg_ptd_week + tmp_net_asg_run_week) >= tmp_fed_state_week_exemption THEN
5224                      DI_total_exemption := (tmp_fed_state_week_exemption - tmp_net_asg_ptd_week);
5225                   ELSE
5226                      DI_total_exemption := tmp_fed_state_week_exemption;
5227                   END IF;
5228                ELSE
5229                   DI_total_exemption := tmp_fed_state_week_exemption;
5230                END IF;
5231             END IF;
5232             hr_utility.trace('DI_total_exemption (For G , CD NAP - NAR > 0) := ' || DI_total_exemption);
5233        ELSE
5234             DI_total_exemption := GREATEST(tmp_DI_total_week_exempt, tmp_fed_state_week_exemption);
5235        END IF;
5236 
5237      --  Code change to be ended here for Bug# 6818016
5238      ELSE
5239       if lv_M_rule is not null then
5240         DI_total_exemption := GREATEST(DI_total_exemption,
5241                                    NVL(ln_M_S_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage,
5242                                    NVL(ln_M_F_Factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage);
5243       end if;
5244      END IF;
5245    END IF; -- garn_category G or CD
5246 
5247    /* -- Introduced for Bug# 7674615, Commented for 13976486
5248    IF GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' THEN
5249       IF DI_total_exemption = fed_criteria_exemption and GARN_CATEGORY = 'EL' THEN
5250          lb_EL_reduce_di := FALSE;
5251       ELSE
5252          lb_EL_reduce_di := TRUE;
5253       END IF;
5254    END IF; */
5255 
5256 /* The exemption amount so far is the amount exempt PER WEEK
5257    So we convert it to a PER PAY PERIOD figure for calculating Subject DI. */
5258 
5259     DI_total_period_exemption := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5260                                                      ASG_HOURS,
5261                                                      DI_total_exemption,
5262                                                      'WEEK',
5263                                                      'NOT ENTERED',
5264                                                      PAY_EARNED_START_DATE,
5265                                                      PAY_EARNED_END_DATE,
5266                                                      ASG_FREQ);
5267 
5268     hr_utility.trace('DI_total_period_exemption = ' || DI_total_period_exemption);
5269 
5270     IF garn_category = 'BO' THEN /* Step #4 */
5271         DI_total_period_exemption := Exempt_Amt_BO;
5272     END IF;
5273 
5274 
5275     Subject_DISPOSABLE_INCOME := Total_DI  - DI_total_period_exemption
5276                                            - TAX_LEVIES_ASG_GRE_RUN
5277                                            - TOT_WHLD_SUPP_ASG_GRE_RUN
5278                                            - TOTAL_WITHHELD_FEE_ASG_GRE_RUN
5279                                            - GARN_TOTAL_DEDNS_ASG_GRE_RUN
5280                                            - GARN_TOTAL_FEES_ASG_GRE_RUN;
5281     hr_utility.trace('Initial Subject Disposable Income = ' || Subject_DISPOSABLE_INCOME);
5282 
5283     -- Bug 5149450
5284     -- Set the value of calcd_dedn_amt and verify_dedn_amt to the
5285     -- correct value. BASE_FORMULA only calculates an estimated value
5286     if GLB_AMT_NOT_SPEC(P_CTX_ORIGINAL_ENTRY_ID) then
5287        if dedn_amt > (Total_DI - DI_total_period_exemption) then
5288           dedn_amt := Total_DI - DI_total_period_exemption;
5289        end if; -- if
5290     end if;
5291 
5292 
5293     -- Bug 4079142
5294     -- Do not reduce DI with the Involunatry Deductions already deducted.
5295     -- This is because in presence of DCIA element, we can take upto 25% of Total DI.
5296     -- Reducing DI here with the Involuntary Deductions deducted might make Subject DI
5297     -- to be lesser than ZERO resulting in no deduction of the current element.
5298     -- A check later makes sure that the Total Deductions is not more than 25% of
5299     -- Total DI. So we can safely ignore the other deductions here in case of
5300     -- DCIA element also processed in the Payroll.
5301 
5302     if GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' then
5303       -- Introduced for Bug# 7674615, later commented for 13976486
5304       --if lb_EL_reduce_di then
5305         Subject_DISPOSABLE_INCOME := Total_DI  - DI_total_period_exemption;
5306       --end if;
5307       hr_utility.trace('Modified Initial Subject Disposable Income = ' || Subject_DISPOSABLE_INCOME);
5308     end if;
5309 
5310     /* Need a check here that Subject DI is not less than or equal to zero!  If it is, then DI is
5311     below the federal minimum allowable - so do not withhold anything!*/
5312     calcd_arrears := 0;
5313     not_taken := 0;
5314     IF Subject_DISPOSABLE_INCOME <= 0 THEN
5315         calcd_arrears := dedn_amt;
5316         not_taken := 0;
5317         dedn_amt := 0;
5318         to_total_owed := 0;
5319         calcd_dedn_amt := 0;
5320         calcd_fee := 0;
5321         garn_fee := 0;
5322         Subject_DISPOSABLE_INCOME := 0;
5323         mesg := 'Not enough money to take garnishment for the element ' || lv_ele_name || '.';
5324         SF_Accrued_Fees := SF_Accrued_Fees + accrued_fee_correction;
5325         if GLB_NUM_ELEM = 0 then
5326            GLB_SUPPORT_DI := NULL;
5327            GLB_OTHER_DI_FLAG := NULL;
5328            GLB_DCIA_EXIST_FLAG := NULL;
5329            reset_global_var;
5330         end if;
5331         RETURN(5);
5332     END IF;
5333 
5334 
5335     --Added the below if for the 9788510 bugs and 12767090.
5336     --NY and CA need only one dedn to be processed at once.
5337     /* GA also only one deduction to be processed at once for 'CD' and 'G'
5338        garnishment categories, bug 13694776 */
5339     IF SUBSTR(Jurisdiction,1,2) in ('33','05','11') AND garn_category in ('CD','G') THEN
5340       IF GLB_MULTIPLE_GARN THEN
5341         dedn_amt := 0;
5342 				GLB_ALLOW_MULT_DEDN := FALSE; -- bug 14357621
5343       ELSE
5344         GLB_MULTIPLE_GARN :=TRUE;
5345       end if;
5346     end if;
5347 
5348 
5349     -- 'EL' Added for Bug# 5701665
5350     IF SUBSTR(Jurisdiction,1,2) = '33' AND garn_category <> 'BO' AND garn_category <> 'DCIA' AND garn_category <> 'EL'/* New York */ THEN
5351         dedn_amt := LEAST(LEAST(Subject_DISPOSABLE_INCOME,
5352                                 ((1 - c_ny_gross_erngs_exmpt_pct) *
5353                                 GROSS_EARNINGS_ASG_GRE_RUN)),dedn_amt);
5354     END IF;
5355 
5356 --Bug 6678760 VMKULKAR
5357     IF SUBSTR(Jurisdiction,1,2) = '08' AND garn_category in ('G','CD') /* Delaware */ THEN
5358     l_fed_criteria_minwage_dl := GREATEST(30 * c_Federal_Minimum_Wage
5359                                          ,NVL(ln_M_F_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_Federal_Minimum_Wage
5360                                          ,NVL(ln_M_S_factor, GARN_EXEMPTION_MIN_WAGE_FACTOR) * c_State_Minimum_Wage
5361                                          );
5362 
5363      Total_DI_per_week := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5364                                                         ASG_HOURS,Total_DI,
5365                                                         'NOT ENTERED',
5366                                                         'WEEK',
5367                                                         PAY_EARNED_START_DATE,
5368                                                         PAY_EARNED_END_DATE,
5369                                                         ASG_FREQ);
5370 
5371     dedn_amt := LEAST((1-c_dl_gross_erngs_exmpt_pct)* Total_DI_per_week,
5372                  Total_DI_per_week - l_fed_criteria_minwage_dl);
5373     /*    converting dedn_amt to period amount  */
5374 
5375     dedn_amt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5376                                                         ASG_HOURS,dedn_amt,
5377                                                         'WEEK',
5378                                                         'NOT ENTERED',
5379                                                         PAY_EARNED_START_DATE,
5380                                                         PAY_EARNED_END_DATE,
5381                                                         ASG_FREQ);
5382 
5383 
5384     END IF;
5385 --Bug 6678760 VMKULKAR
5386 
5387     -- Bug 5098366
5388     -- Added the NVL condition to override the .25 condition if
5389     -- Exemption percentage is overridden at Employee level
5390     IF garn_category <> 'BO'AND garn_category <> 'DCIA' AND GARN_CATEGORY <> 'EL' AND
5391        SUBSTR(Jurisdiction,1,2) <> '14' AND
5392        SUBSTR(Jurisdiction,1,2) <> '06' AND
5393        nvl(l_exmpt_ovrd,default_number) = default_number THEN
5394         IF Subject_DISPOSABLE_INCOME > Total_DI * .25 THEN
5395             Subject_DISPOSABLE_INCOME := Total_DI * .25;
5396         END IF;
5397     END IF;
5398     hr_utility.trace('Subject_Disposable_Income = '||Subject_Disposable_Income);
5399 
5400     /*
5401      * Bug 3734557
5402      * Added the condition so that Proration rules are applied only if
5403      * DI is less.
5404      */
5405     if total_garn_run > Subject_DISPOSABLE_INCOME then -- 6140374
5406        /*-- Proration rules for states which allow more than one garnishments to be processed (Bug 2658290). ---*/
5407        IF GARN_EXEMPTION_CALC_RULE <> 'ONE_FED' AND
5408              GARN_EXEMPTION_CALC_RULE <> 'ONE_FLAT_AMT' AND
5409              GARN_EXEMPTION_CALC_RULE <> 'ONE_FLAT_PCT' AND
5410              GARN_EXEMPTION_CALC_RULE <> 'ONE_MARSTAT_RULE' AND
5411              GARN_EXEMPTION_CALC_RULE <> 'ONE_EXEMPT_BALANCE' THEN
5412 
5413            OPEN csr_get_proration_ovrd;
5414                FETCH csr_get_proration_ovrd INTO l_proration_ovrd;
5415            CLOSE csr_get_proration_ovrd;
5416 
5417            IF l_proration_ovrd is null then
5418                l_proration_ovrd := GARN_EXEMPTION_PRORATION_RULE;
5419                hr_utility.trace ('Proration rule not overriden. Proceeding with proration rule = '||l_proration_ovrd);
5420            ELSE
5421                hr_utility.trace ('Proration rule overriden to '||l_proration_ovrd);
5422            END IF;
5423 
5424            IF l_proration_ovrd = 'NONE' OR
5425               l_proration_ovrd = 'ORDER' THEN
5426                    IF dedn_amt > Subject_DISPOSABLE_INCOME THEN
5427                        calcd_arrears := dedn_amt - Subject_DISPOSABLE_INCOME;
5428                        dedn_amt      := Subject_DISPOSABLE_INCOME;
5429                        not_taken     := Subject_DISPOSABLE_INCOME - dedn_amt;
5430                    END IF;
5431 
5432 
5433                    /*IF (GARN_TOTAL_DEDNS_ASG_GRE_RUN + dedn_amt) > subject_disposable_income THEN
5434                        dedn_amt := subject_disposable_income - GARN_TOTAL_DEDNS_ASG_GRE_RUN;
5435                        IF dedn_amt <= 0 THEN
5436                            dedn_amt := 0;
5437                            not_taken := subject_disposable_income;
5438                        ELSE
5439                            not_taken := dedn_amt - subject_disposable_income;
5440                        END IF;
5441                    ELSE
5442                        IF GARN_TOTAL_DEDNS_ASG_GRE_RUN +
5443                           GARN_TOTAL_FEES_ASG_GRE_RUN +
5444                           dedn_amt +
5445                           wh_fee_amt > VF_DI_SUBJ THEN
5446                            IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
5447                                   IF wh_dedn_amt - wh_fee_amt > 0 THEN
5448                                    wh_dedn_amt := wh_dedn_amt - wh_fee_amt;
5449                                    not_taken := VF_DI_SUBJ - wh_dedn_amt;
5450                                ELSE
5451                                    wh_fee_amt := VF_DI_SUBJ - ( GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
5452                                                                 TOTAL_WITHHELD_FEE_ASG_GRE_RUN +
5453                                                                 wh_dedn_amt);
5454                                END IF;
5455                        ELSE
5456                                wh_fee_amt := VF_DI_SUBJ - ( GLB_TOT_WHLD_SUPP_ASG_GRE_RUN +
5457                                                             TOTAL_WITHHELD_FEE_ASG_GRE_RUN +
5458                                                             wh_dedn_amt);
5459                        END IF;
5460                    END IF;
5461                END IF;*/
5462            ELSE
5463             /* For calculating "equal" and "proportionate" amounts, DI should remain same for
5464                all deduction elements. But subject_disposable_income reduces each time an element
5465                is processed. Hence, introducing equal_DI to bring subject_disposable_income to
5466                correct value for calculations. */
5467 
5468                -- In the presence of DCIA, Subject Disposable Income does not reduce
5469                -- each time an element is processed. So we do not nned to correct
5470                -- the value for calculation
5471                IF GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' THEN
5472                   equal_DI := subject_disposable_income;
5473                ELSE
5474                   equal_DI := subject_disposable_income +
5475                               GARN_TOTAL_DEDNS_ASG_GRE_RUN +
5476                               GARN_TOTAL_FEES_ASG_GRE_RUN;
5477                END IF;
5478                IF l_proration_ovrd = 'EQUAL' THEN
5479                    equal_dedn_amounts := equal_DI /gar_dedn_tab.count();
5480                    --not_taken := subject_disposable_income - dedn_amt;
5481                    not_taken := equal_DI - equal_dedn_amounts;
5482                    dedn_amt := equal_dedn_amounts;
5483 --changes for bug 8673016
5484                    IF dedn_amt > Subject_DISPOSABLE_INCOME THEN
5485                        calcd_arrears := dedn_amt - Subject_DISPOSABLE_INCOME;
5486                        dedn_amt      := Subject_DISPOSABLE_INCOME;
5487                        not_taken     := Subject_DISPOSABLE_INCOME - dedn_amt;
5488                    END IF;
5489 --changes for bug 8673016
5490                ELSIF l_proration_ovrd = 'PROPORTION' AND
5491                    total_garn_run <> 0 THEN
5492                    -- Bug 5165704
5493                    -- Used gar_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID) instead of
5494                    -- DEDN_AMT for calculating the Proportional amount
5495                    -- DEDN_AMT gets modified and as a result the proportional
5496                    -- amount gets incorrectly calculated
5497                    proportional_dedn_amount := (gar_dedn_tab (P_CTX_ORIGINAL_ENTRY_ID) / total_garn_run) * equal_DI;
5498                    not_taken := equal_DI - proportional_dedn_amount;
5499                    dedn_amt := proportional_dedn_amount;
5500                END IF;
5501            END IF;
5502        ELSE
5503            /* Only one garnishment allowed for current state and category. */
5504            IF dedn_amt > Subject_DISPOSABLE_INCOME THEN
5505                calcd_arrears := dedn_amt - Subject_DISPOSABLE_INCOME;
5506                dedn_amt      := Subject_DISPOSABLE_INCOME;
5507                not_taken     := Subject_DISPOSABLE_INCOME - dedn_amt;
5508            END IF;
5509        END IF;
5510     END IF;
5511 
5512     -- Bug 4079142
5513     -- Checking for Federal Consumer Credit Protection Act in case of DCIA
5514     -- using the following rule
5515 
5516     IF GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' THEN -- Bug# 6068769
5517        hr_utility.trace('Deductions Amount Before CCPA check = ' || dedn_amt);
5518 
5519        -- Check for DCIA limit to 25% of DI when combined with other Involuntary Deductions
5520        -- or with itself.
5521        diff := ccpa_protection - inv_dedn_in_run;
5522        hr_utility.trace('Garnishment Deductions For the Run = ' || inv_dedn_in_run);
5523        if diff <= 0 then
5524            calcd_arrears := dedn_amt;
5525            dedn_amt := 0;
5526        elsif dedn_amt > diff then
5527           calcd_arrears := dedn_amt - diff;
5528           dedn_amt := diff;
5529           not_taken := Subject_DISPOSABLE_INCOME - dedn_amt;
5530        end if;
5531        hr_utility.trace('Deductions Amount After CCPA check = ' || dedn_amt);
5532 
5533        -- Introduced for Bug# 7674615, updated for 13976486
5534        -- Period figure of Federal Min Wage exemption
5535     if ( GARN_CATEGORY NOT IN ('AY','BO','CS','SS','TL') ) then --not lb_EL_reduce_di then
5536        fed_min_wage_prd_exempt := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
5537                                                      ASG_HOURS,
5538                                                      greatest(fed_criteria_minwage_exemption, GARN_EXEMPTION_MIN_WAGE_FACTOR * nvl(c_State_Minimum_Wage,0) ),
5539                                                      'WEEK',
5540                                                      'NOT ENTERED',
5541                                                      PAY_EARNED_START_DATE,
5542                                                      PAY_EARNED_END_DATE,
5543                                                      ASG_FREQ);
5544        hr_utility.trace('fed_min_wage_prd_exempt := ' || fed_min_wage_prd_exempt);
5545        hr_utility.trace('Total_DI := ' || Total_DI);
5546        hr_utility.trace('dedn_amt := ' || dedn_amt);
5547        hr_utility.trace('inv_dedn_in_run := ' || inv_dedn_in_run);
5548 
5549        if (Total_DI - (dedn_amt + inv_dedn_in_run)) < fed_min_wage_prd_exempt then
5550           calcd_arrears := dedn_amt - (Total_DI - inv_dedn_in_run - fed_min_wage_prd_exempt);
5551           dedn_amt := Total_DI - inv_dedn_in_run - fed_min_wage_prd_exempt;
5552        end if;
5553 
5554        hr_utility.trace('calcd_arrears := ' || calcd_arrears);
5555        hr_utility.trace('dedn_amt := ' || dedn_amt);
5556     end if;
5557        -- End of change for Bug# 7674615
5558 
5559        /* Need a check here that Deductions AMount calculated is not less than or equal to zero!
5560        If it is, then  so do not withhold anything!*/
5561        IF dedn_amt <= 0 THEN
5562            to_total_owed := 0;
5563            not_taken := 0;
5564            dedn_amt := 0;
5565            calcd_dedn_amt := 0;
5566            calcd_fee := 0;
5567            garn_fee := 0;
5568            Subject_DISPOSABLE_INCOME := 0;
5569            mesg := 'Not enough money to take garnishment for the element ' || lv_ele_name || '.';
5570            SF_Accrued_Fees := SF_Accrued_Fees + accrued_fee_correction;
5571            if GLB_NUM_ELEM = 0 then
5572               GLB_SUPPORT_DI := NULL;
5573               GLB_OTHER_DI_FLAG := NULL;
5574               GLB_DCIA_EXIST_FLAG := NULL;
5575               reset_global_var;
5576            end if;
5577            RETURN(5);
5578        END IF;
5579 
5580     END IF;
5581     /*----------------------*/
5582 
5583 
5584     -- Bug 4748532
5585     -- Deduct PTD amount for Garnishment and Fees if the value of
5586     -- GLB_FEES_ASG_GRE_PTD is not set to -9999(default_number) in BASE_FORMULA
5587     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
5588        hr_utility.trace('Deduction that can be taken = ' || dedn_amt_cp);
5589        hr_utility.trace('Deduction already taken     = ' || GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID));
5590 
5591        IF dedn_amt <= 0 THEN
5592           dedn_amt := 0;
5593        ELSIF (dedn_amt + GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID)) > dedn_amt_cp THEN
5594           dedn_amt := dedn_amt_cp - GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
5595        END IF;
5596 
5597        IF (dedn_amt > actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID)) THEN
5598           dedn_amt := actual_dedn_tab(P_CTX_ORIGINAL_ENTRY_ID);
5599        END IF;
5600     END IF;
5601 
5602     /* *** limit verification END ***
5603 
5604 
5605     *** Fee processing BEGIN *** */
5606     calcd_fee := 0;
5607     calcd_fee_rec := 0;
5608     /* Fee Calculation is done in a function.Accrued_Fee,PTD_Fee_Balance and
5609     Month_Fee_Balance are passed as parameters to the function*/
5610 
5611     -- Bug 4079142
5612     -- Added the IF condition as DCIA does not have any fees associated
5613     -- with it.
5614 
5615     IF GARN_CATEGORY <> 'DCIA' THEN
5616 
5617        -- DCIA elements presence overrides the Subject Disposabel Income for CCPA
5618        -- check. We set the DI to the (CCPA value - the Inv Deductions deducted).
5619        -- From here we make sure that the dedn_amt for the current element + Fee
5620        -- should not be more than the DI calculated making the total deduction
5621        -- to be 25% of DI
5622        IF GLB_DCIA_EXIST_FLAG OR GARN_CATEGORY = 'EL' THEN -- Bug# 6068769
5623           Subject_DISPOSABLE_INCOME := ccpa_protection - inv_dedn_in_run;
5624           hr_utility.trace('Subject_DISPOSABLE_INCOME Modified To ' || Subject_DISPOSABLE_INCOME);
5625        END IF;
5626 
5627        IF l_garn_fee_max_fee_amt <> default_number THEN
5628            IN_GARN_FEE_MAX_FEE_AMOUNT := l_garn_fee_max_fee_amt;
5629        ELSE
5630            IN_GARN_FEE_MAX_FEE_AMOUNT :=-99999;
5631        END IF;
5632 
5633        hr_utility.trace('Modified GARN_FEE_MAX_FEE_AMOUNT = '||l_garn_fee_max_fee_amt);
5634 
5635        calcd_fee := FNC_FEE_CALCULATION(GARN_FEE_FEE_RULE,
5636                                         GARN_FEE_FEE_AMOUNT,
5637                                         GARN_FEE_PCT_CURRENT,
5638                                         total_owed,
5639                                         Primary_Amount_Balance,
5640                                         GARN_FEE_ADDL_GARN_FEE_AMOUNT,
5641                                         IN_GARN_FEE_MAX_FEE_AMOUNT,
5642                                         PTD_Fee_Balance,
5643                                         GARN_TOTAL_FEES_ASG_GRE_RUN,
5644                                         dedn_amt,
5645                                         Month_Fee_Balance,
5646                                         ACCRUED_FEES);
5647 
5648        /*
5649         * Check if Initial Fee Flag is set. Bug 3549298
5650         */
5651        IF calcd_fee < 0 THEN
5652            calcd_fee := 0;
5653        ELSIF l_ini_fee_flag = 'Y' THEN
5654            IF GARN_FEE_FEE_RULE = 'AMT_PER_GARN_ADDL' OR
5655               GARN_FEE_FEE_RULE = 'AMT_PER_PERIOD_ADDL' OR
5656               GARN_FEE_FEE_RULE = 'AMT_PER_MONTH_ADDL' OR
5657               GARN_FEE_FEE_RULE = 'AMT_PER_RUN_ADDL' THEN
5658               IF calcd_fee > GARN_FEE_ADDL_GARN_FEE_AMOUNT THEN
5659                   calcd_fee := GARN_FEE_ADDL_GARN_FEE_AMOUNT;
5660               END IF;
5661            ELSE
5662               calcd_fee := 0;
5663            END IF;
5664        END IF;
5665        /* Suppress fee result when no fees charged.  */
5666        /* Check for dedn_amt+fee crossing legislative limits of fed/state */
5667        -- Bug 4309544
5668        -- During Proration fee should be taken only if 'Take Fee On Proration'
5669        -- is set to Yes
5670        IF total_garn_run > Subject_DISPOSABLE_INCOME THEN -- 6140374
5671 
5672           -- During Proration take fees only if 'Take Fee On Proration' is
5673           -- checked
5674           IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
5675             /* Introduced for Bug 7589784 */
5676              hr_utility.trace('Take Fee on Proration.');
5677              IF dedn_amt > 0 THEN
5678                 tmp_dedn_amt := dedn_amt;
5679                 tmp_calc_fee := calcd_fee;
5680                 tmp_not_taken := not_taken;
5681                 dedn_amt  := dedn_amt - calcd_fee;
5682                 not_taken := not_taken + (Subject_DISPOSABLE_INCOME - dedn_amt);
5683                 calcd_fee_rec := calcd_fee;
5684              END IF;
5685              IF dedn_amt <= 0 THEN
5686                 dedn_amt := tmp_dedn_amt;
5687                 calcd_fee := 0;
5688                 calcd_fee_rec := calcd_fee;
5689                 not_taken := tmp_not_taken + (Subject_DISPOSABLE_INCOME - dedn_amt);
5690              END IF;
5691             -- bug 14357621
5692             /* fee should be deducted if there is no mulitple deductions and
5693                Subject_DISPOSABLE_INCOME - dedn_amt is greater than zero */
5694             ELSIF NOT GLB_ALLOW_MULT_DEDN then
5695                if calcd_fee  > Subject_DISPOSABLE_INCOME - dedn_amt then
5696                  if Subject_DISPOSABLE_INCOME - dedn_amt > 0 then
5697                    calcd_fee := Subject_DISPOSABLE_INCOME - dedn_amt;
5698                  else
5699                   calcd_fee := 0;
5700                  end if;
5701                 end if;
5702             ELSE
5703               calcd_fee := 0;
5704           END IF; -- IF
5705        ELSE
5706           IF calcd_fee > Subject_DISPOSABLE_INCOME - dedn_amt THEN
5707               IF GARN_FEE_TAKE_FEE_ON_PRORATION = 'Y' THEN
5708                   IF Subject_DISPOSABLE_INCOME - calcd_fee > 0 THEN
5709                       t_dedn_amt := Subject_DISPOSABLE_INCOME - calcd_fee;
5710                       dedn_amt   := t_dedn_amt;   /*Fee is taken initially by reducing the deduction amount */
5711                       not_taken := not_taken + (Subject_DISPOSABLE_INCOME - dedn_amt);
5712                       -- Bug 4748532
5713                       calcd_fee_rec := calcd_fee;
5714                   ELSE
5715                       calcd_fee := 0;
5716                   END IF;
5717               ELSE
5718                   IF Subject_DISPOSABLE_INCOME - dedn_amt > 0 THEN
5719                       calcd_fee := Subject_DISPOSABLE_INCOME - dedn_amt;
5720                   ELSE
5721                       calcd_fee := 0;
5722                   END IF;
5723               END IF;
5724           END IF;
5725        END IF;
5726     END IF; /*  IF GARN_CATEGORY <> 'DCIA'  */
5727 
5728     -- Bug 4748532
5729     -- Deduct PTD amount for Garnishment and Fees if the value of
5730     -- GLB_FEES_ASG_GRE_PTD is not set to -9999(default_number) in BASE_FORMULA
5731     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
5732        hr_utility.trace('Fees That can be taken      = ' || calcd_fee);
5733        hr_utility.trace('Fees already taken          = ' || GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID));
5734 
5735        IF calcd_fee >= 0 THEN
5736           IF calcd_fee >= GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) THEN
5737              calcd_fee := calcd_fee - GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
5738            END IF;
5739        ELSE
5740           calcd_fee := 0;
5741        END IF;
5742        -- To recover Dedn Amoutn if Fees was reset to Zero here
5743        IF calcd_fee_rec > 0 THEN
5744           dedn_amt  := dedn_amt + calcd_fee_rec - calcd_fee;
5745        END IF;
5746     END IF;
5747 
5748 
5749     /**** Negative Net checks *** */
5750     IF NET_ASG_GRE_RUN - dedn_amt - calcd_fee < 0 THEN
5751         IF NET_ASG_GRE_RUN - dedn_amt > 0 THEN
5752             calcd_fee := NET_ASG_GRE_RUN - dedn_amt;
5753         ELSE
5754             IF NET_ASG_GRE_RUN - dedn_amt = 0 THEN
5755                 /* Fee causes net to go negative, don't charge fee. */
5756                 calcd_fee := 0;
5757             ELSIF NET_ASG_GRE_RUN - dedn_amt < 0 THEN
5758                 calcd_fee     := 0;
5759                 calcd_arrears :=  calcd_arrears + (dedn_amt-NET_ASG_GRE_RUN);
5760                 dedn_amt      := NET_ASG_GRE_RUN;
5761                 not_taken     := not_taken  + (Subject_DISPOSABLE_INCOME - dedn_amt);
5762             END IF;
5763         END IF;
5764     END IF;
5765 
5766     /* Check for G or CD and North Dekota (35) or South Dakota (42) or Tennessee (43)
5767        and then check for the Total Owed
5768     */
5769     calcd_dedn_amt := dedn_amt;
5770     IF garn_category = 'G' OR
5771         garn_category = 'CD' THEN
5772         IF SUBSTR(Jurisdiction,1,2) = '35' OR
5773            SUBSTR(Jurisdiction,1,2) = '42' OR
5774            SUBSTR(Jurisdiction,1,2) = '43' THEN
5775             IF num_dependents > 0 THEN
5776                 calcd_dedn_amt := calcd_dedn_amt - (GRN_EXMPT_DEP_AMT_VAL * num_dependents);
5777             END IF;
5778         END IF;
5779     END IF;
5780     dedn_amt := calcd_dedn_amt;
5781 
5782     /* *** Negative Net checks end ***/
5783 
5784     /*** Stop Rule Processing BEGIN *** */
5785     IF Total_Owed <> 0 THEN
5786         IF Primary_Amount_Balance - Period_to_Date_Balance < 0 THEN
5787             dedn_amt := 0;
5788             mesg := 'Total Owed already reached, so no garnishment being withheld for ' || lv_ele_name || '.';
5789             to_total_owed := 0;
5790         ELSE
5791             IF Total_Owed - Primary_Amount_Balance < 0 THEN
5792                 fatal_mesg := 'Accrued Deduction Balance > Total Owed by $' ||
5793                               to_char(Primary_Amount_Balance - Total_Owed ) || '. Adjust Balance for ' || lv_ele_name || '.';
5794                 GLB_SUPPORT_DI := NULL;
5795                 GLB_OTHER_DI_FLAG := NULL;
5796                 GLB_DCIA_EXIST_FLAG := NULL;
5797                 reset_global_var;
5798                 RETURN (6);
5799             ELSIF Primary_Amount_Balance + dedn_amt >= Total_Owed THEN
5800                 dedn_amt := Total_Owed - Primary_Amount_Balance;
5801                 to_total_owed := -1 * Primary_Amount_Balance;
5802                 STOP_ENTRY := 'Y';
5803                 mesg := 'Garnishment obligation has been satisfied for ' || lv_ele_name || ' because of Total Owed Reached.';
5804                 /*-- (Bug 1481913) Set a boolean flag to indicate that subsequent garnishments are allowed
5805                      to be processed. --*/
5806                 GLB_ALLOW_MULT_DEDN := TRUE;
5807             ELSE
5808                 to_total_owed := dedn_amt;
5809                 --to_fees_accrued :=  calcd_fee;
5810             END IF;
5811         END IF;
5812 
5813     ELSE
5814         to_total_owed := 0;
5815     END IF;
5816 
5817     calcd_dedn_amt := dedn_amt;
5818 
5819     garn_limit_days := get_garn_limit_max_duration(PAY_EARNED_START_DATE);
5820 
5821    /*
5822     * Bug 3718454
5823     * Added 1 to the calculation of garn_days as the both
5824     * PAY_EARNED_END_DATE and VF_DATE_SERVED should be included for
5825     * calculating the STOP_ENTRY value
5826     */
5827 
5828     IF garn_limit_days > 0 THEN
5829         garn_days := PAY_EARNED_END_DATE - Date_Served + 1;
5830         IF garn_days >= garn_limit_days THEN
5831             garn_days_end_per := PAY_EARNED_START_DATE - Date_Served + 1;
5832             /*
5833              * Added the IF condition te determine whether any amount needs
5834              * to be deducted.(Bug 3718454 and 3734415)
5835 	     * Bug 3777900 : Removed '=' sign from the IF condition below
5836              */
5837             IF garn_days_end_per > garn_limit_days THEN
5838                 STOP_ENTRY := 'Y';
5839                 CALCD_DEDN_AMT := 0;
5840                 CALCD_FEE := 0;
5841                 mesg := garn_limit_days || ' days Limit for element ' || lv_ele_name || ' was reached before current pay period. No Deduction will be taken. Element will be end dated';
5842             ELSE
5843                 STOP_ENTRY := 'Y';
5844                 mesg := 'Garnishment obligation has been satisfied for ' || lv_ele_name || ' because of Max Withholding Days Limit Reached.';
5845                 to_total_owed := -1 * Primary_Amount_Balance;
5846             END IF;
5847         END IF;
5848     END IF;
5849     /* *** Stop Rule Processing END ***/
5850 
5851 -- Commented the following Final Pay section for Bug 4107302
5852     /*** Final Pay Section BEGIN *** */
5853     /*
5854     IF (TERMINATED_EMPLOYEE = 'Y' AND FINAL_PAY_PROCESSED = 'N') THEN
5855         STOP_ENTRY := 'Y';
5856     END IF;
5857     */
5858     /**** Final Pay Section END ****/
5859 
5860     /* Bankrupcy Order and DCIA does not have fees */
5861     -- Bug 4079142
5862     IF garn_category = 'BO' or garn_category = 'DCIA' THEN -- Bug# 6068769
5863         calcd_fee:= 0;
5864     END IF;
5865 
5866     /* Check for negative for dedn_amt and fees */
5867     IF calcd_fee < 0 THEN
5868         calcd_fee := 0;
5869     END IF;
5870 
5871     -- Bug 4234046 and 4748532
5872     -- Set Fee Amount to ZERO when
5873     --- * No deduction is taken
5874     --  * We are not looking at PTD values for deducting Garnishment
5875     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) = default_number THEN
5876        IF calcd_dedn_amt <= 0 THEN
5877            calcd_dedn_amt := 0;
5878            calcd_fee := 0;
5879            to_total_owed := 0;
5880        END IF;
5881     ELSIF calcd_dedn_amt <= 0 THEN
5882            calcd_dedn_amt := 0;
5883            to_total_owed := 0;
5884     END IF;
5885 
5886     garn_fee:=calcd_fee;
5887     SF_Accrued_fees := calcd_fee;
5888     SF_Accrued_Fees := SF_Accrued_Fees + accrued_fee_correction;
5889 
5890     -- Bug 3500570
5891     IF NET_ASG_GRE_RUN > subject_disposable_income AND dedn_amt <> 0 THEN
5892         not_taken := 0;
5893     END IF;
5894 
5895     IF l_debug_on = 'Y' THEN
5896         hr_utility.trace('Return values....');
5897         hr_utility.trace('CALCD_ARREARS = '||CALCD_ARREARS);
5898         hr_utility.trace('CALCD_DEDN_AMT = '||CALCD_DEDN_AMT);
5899         hr_utility.trace('CALCD_FEE = '||CALCD_FEE);
5900         hr_utility.trace('FATAL_MESG = '||FATAL_MESG);
5901         hr_utility.trace('GARN_FEE = '||GARN_FEE);
5902         hr_utility.trace('MESG = '||MESG);
5903         hr_utility.trace('MESG1 = '||MESG1);
5904         hr_utility.trace('NOT_TAKEN = '||NOT_TAKEN);
5905         hr_utility.trace('SF_ACCRUED_FEES = '||SF_ACCRUED_FEES);
5906         hr_utility.trace('STOP_ENTRY = '||STOP_ENTRY);
5907         hr_utility.trace('TO_ADDL = '||TO_ADDL);
5908         hr_utility.trace('TO_REPL = '||TO_REPL);
5909         hr_utility.trace('TO_TOTAL_OWED = '||TO_TOTAL_OWED);
5910         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
5911     END IF;
5912 
5913     if GLB_NUM_ELEM = 0 then
5914        GLB_SUPPORT_DI := NULL;
5915        GLB_OTHER_DI_FLAG := NULL;
5916        GLB_DCIA_EXIST_FLAG := NULL;
5917        reset_global_var;
5918     end if;
5919 
5920     hr_utility.trace('Leaving '||l_proc_name);
5921     IF calcd_fee = 0 THEN
5922         RETURN(7);
5923     ELSE
5924         RETURN(8);
5925     END IF;
5926 END CAL_FORMULA_BO;
5927 
5928 
5929   /****************************************************************************
5930     Name        : CAL_FORMULA_TL
5931     Description : This function calculates amount to be withheld for TL
5932                   category.
5933   *****************************************************************************/
5934 FUNCTION CAL_FORMULA_TL
5935 (
5936     P_CTX_BUSINESS_GROUP_ID number,
5937     P_CTX_PAYROLL_ID number,
5938     P_CTX_ELEMENT_TYPE_ID number,
5939     P_CTX_ORIGINAL_ENTRY_ID number,
5940     P_CTX_DATE_EARNED date,
5941     P_CTX_JURISDICTION_CODE varchar2,
5942     P_CTX_ELEMENT_ENTRY_ID number,
5943     PAY_EARNED_START_DATE date,
5944     PAY_EARNED_END_DATE date,
5945     TOTAL_WITHHELD_FEE_ASG_GRE_RUN number,
5946     TOT_WHLD_SUPP_ASG_GRE_RUN number,
5947     SCL_ASG_US_WORK_SCHEDULE varchar2,
5948     ASG_HOURS number,
5949     ASG_FREQ varchar2,
5950     TERMINATED_EMPLOYEE varchar2,
5951     FINAL_PAY_PROCESSED varchar2,
5952     GROSS_EARNINGS_ASG_GRE_RUN number,
5953     TAX_DEDUCTIONS_ASG_GRE_RUN number,
5954     NET_ASG_GRE_RUN number,
5955     NET_ASG_RUN number,
5956     TOTAL_OWED number,
5957     DATE_SERVED date,
5958     ADDITIONAL_AMOUNT_BALANCE number,
5959     REPLACEMENT_AMOUNT_BALANCE number,
5960     PRIMARY_AMOUNT_BALANCE number,
5961     TAX_LEVIES_ASG_GRE_PTD number,
5962     CALCD_DEDN_AMT OUT NOCOPY number,
5963     NOT_TAKEN OUT NOCOPY number,
5964     TO_ARREARS OUT NOCOPY number,
5965     TO_TOTAL_OWED OUT NOCOPY number,
5966     TO_ADDL OUT NOCOPY number,
5967     TO_REPL OUT NOCOPY number,
5968     FATAL_MESG OUT NOCOPY varchar2,
5969     MESG OUT NOCOPY varchar2,
5970     CALC_SUBPRIO OUT NOCOPY number,
5971     STOP_ENTRY OUT NOCOPY varchar2,
5972     EIC_ADVANCE_ASG_GRE_RUN number default 0
5973 ) RETURN number IS
5974 
5975     dedn_amt number;
5976     default_date date;
5977     c_Fed_Levy_Exemption_Table varchar2(100);
5978     c_fed_levy_xmpt_tab_col varchar2(100);
5979     c_fed_levy_xmpt_per_xmpt_row varchar2(100);
5980     c_federal_minimum_wage number;
5981     take_home_pay number;
5982     standard_deduction pay_user_column_instances_f.value%TYPE;
5983     allowance_per_exemption pay_user_column_instances_f.value%TYPE;
5984     personal_exemption_allowance number;
5985     fed_levy_annual_exemption number;
5986     fed_levy_exemption number;
5987     amt_at_hand number;
5988     garn_limit_days number;
5989     garn_days number;
5990     garn_days_end_per number;
5991     sub_prio_max number;
5992     actual_dedn number;
5993 
5994     amount number;
5995     filing_status varchar2(10);
5996     allowances number;
5997     dedns_at_time_of_writ number;
5998     monthly_cap_amount number;
5999     month_to_date_balance number;
6000     period_cap_amount number;
6001     period_to_date_balance number;
6002     ld_entry_start_date   date;
6003     ld_filing_status_date date;
6004     ld_filing_status_year number;
6005     default_number number;
6006 
6007     l_debug_on varchar2(1);
6008     l_proc_name varchar2(50);
6009     lv_ele_name varchar2(100);
6010 
6011     CURSOR cur_debug is
6012         SELECT parameter_value
6013           FROM pay_action_parameters
6014          WHERE parameter_name = 'GARN_DEBUG_ON';
6015 
6016     -- Bug 4079142
6017     -- Cursor to get the element name to be used in the message.
6018     CURSOR csr_get_ele_name (p_ele_type_id number) is
6019     select rtrim(element_name,' Calculator' )
6020       from pay_element_types_f
6021      where element_type_id = p_ele_type_id;
6022 
6023     -- Bug 3528349
6024     -- Cursor to fetch the Filing Status year for the person if specified
6025     CURSOR csr_get_filing_status_year is
6026     select ppei.pei_information1
6027       from per_people_extra_info ppei,
6028            pay_element_entries_f peef,
6029            per_all_assignments_f paaf
6030      where peef.element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
6031        and peef.assignment_id = paaf.assignment_id
6032        and paaf.person_id = ppei.person_id
6033        and ppei.information_type = 'US_FED_LEVY_FIL_STATUS_YEAR';
6034 
6035     -- Bug 3528349
6036     -- Cursor to get the start date of the element
6037     CURSOR csr_get_entry_start_date is
6038     select min(effective_start_date)
6039       from pay_element_entries_f
6040      where element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
6041      group by element_entry_id;
6042 
6043     -- 5111601
6044     -- Cursor to Fetch whether the EE or Spouse is Blind / Age >= 65
6045     CURSOR csr_get_blind_65_flag is
6046     SELECT entry_information10
6047       FROM pay_element_entries_f
6048      WHERE element_entry_id = P_CTX_ORIGINAL_ENTRY_ID
6049        AND entry_information_category = 'US_INVOLUNTARY DEDUCTIONS'
6050        AND P_CTX_DATE_EARNED BETWEEN effective_start_date and effective_end_date;
6051 
6052      -- Bug# 6132855
6053      -- Federal Minimum Wage now is stored in JIT table
6054      CURSOR c_get_federal_min_wage IS
6055      SELECT fed_information1
6056        FROM pay_us_federal_tax_info_f
6057       WHERE fed_information_category = 'WAGEATTACH LIMIT'
6058         AND P_CTX_DATE_EARNED BETWEEN effective_start_date
6059                                   AND effective_end_date;
6060 
6061     c_Fed_65_Blind_Exemption_Table         varchar2(100) ;
6062     c_Fed_65_Blind_Xmpt_tab_col            varchar2(100) ;
6063     lv_65_blind                            number ;
6064     lv_temp_Filing_Status                  varchar2(100) ;
6065     lv_Filing_Status_name                  varchar2(100) ;
6066     exemption_for_age_65_or_blind          pay_user_column_instances_f.value%TYPE ;
6067 
6068 BEGIN
6069 
6070     l_proc_name := l_package_name||'CAL_FORMULA_TL';
6071     hr_utility.trace('Entering '||l_proc_name);
6072 
6073     default_date := fnd_date.canonical_to_date('0001/01/01');
6074     sub_prio_max := 9999;
6075     default_number := -9999;
6076     amount := GLB_AMT(P_CTX_ORIGINAL_ENTRY_ID);
6077     filing_status := GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID);
6078     allowances := GLB_ALLOWS(P_CTX_ORIGINAL_ENTRY_ID);
6079     dedns_at_time_of_writ := GLB_DEDN_OVERRIDE(P_CTX_ORIGINAL_ENTRY_ID);
6080     monthly_cap_amount := GLB_MONTH_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
6081     month_to_date_balance := GLB_MTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
6082     period_cap_amount := GLB_PTD_CAP_AMT(P_CTX_ORIGINAL_ENTRY_ID);
6083     period_to_date_balance := GLB_PTD_BAL(P_CTX_ORIGINAL_ENTRY_ID);
6084 
6085     OPEN cur_debug;
6086         FETCH cur_debug into l_debug_on;
6087     CLOSE cur_debug;
6088 
6089     -- Fetching Federal Minimum Wage Value from JIT table
6090     OPEN c_get_federal_min_wage;
6091     FETCH c_get_federal_min_wage INTO c_Federal_Minimum_Wage;
6092     CLOSE c_get_federal_min_wage;
6093 
6094     IF l_debug_on = 'Y' THEN
6095         hr_utility.trace('Input parameters....');
6096         hr_utility.trace('P_CTX_BUSINESS_GROUP_ID = '||P_CTX_BUSINESS_GROUP_ID);
6097         hr_utility.trace('P_CTX_PAYROLL_ID = '||P_CTX_PAYROLL_ID);
6098         hr_utility.trace('P_CTX_ELEMENT_TYPE_ID = '||P_CTX_ELEMENT_TYPE_ID);
6099         hr_utility.trace('P_CTX_ORIGINAL_ENTRY_ID = '||P_CTX_ORIGINAL_ENTRY_ID);
6100         hr_utility.trace('P_CTX_DATE_EARNED = '||P_CTX_DATE_EARNED);
6101         hr_utility.trace('P_CTX_JURISDICTION_CODE = '||P_CTX_JURISDICTION_CODE);
6102         hr_utility.trace('P_CTX_ELEMENT_ENTRY_ID = '||P_CTX_ELEMENT_ENTRY_ID);
6103         hr_utility.trace('PAY_EARNED_START_DATE = '||PAY_EARNED_START_DATE);
6104         hr_utility.trace('PAY_EARNED_END_DATE = '||PAY_EARNED_END_DATE);
6105         hr_utility.trace('TOTAL_WITHHELD_FEE_ASG_GRE_RUN = '||TOTAL_WITHHELD_FEE_ASG_GRE_RUN);
6106         hr_utility.trace('TOT_WHLD_SUPP_ASG_GRE_RUN = '||TOT_WHLD_SUPP_ASG_GRE_RUN);
6107         hr_utility.trace('SCL_ASG_US_WORK_SCHEDULE = '||SCL_ASG_US_WORK_SCHEDULE);
6108         hr_utility.trace('ASG_HOURS = '||ASG_HOURS);
6109         hr_utility.trace('ASG_FREQ = '||ASG_FREQ);
6110         hr_utility.trace('TERMINATED_EMPLOYEE = '||TERMINATED_EMPLOYEE);
6111         hr_utility.trace('FINAL_PAY_PROCESSED = '||FINAL_PAY_PROCESSED);
6112         hr_utility.trace('GROSS_EARNINGS_ASG_GRE_RUN = '||GROSS_EARNINGS_ASG_GRE_RUN);
6113         hr_utility.trace('TAX_DEDUCTIONS_ASG_GRE_RUN = '||TAX_DEDUCTIONS_ASG_GRE_RUN);
6114         hr_utility.trace('NET_ASG_GRE_RUN = '||NET_ASG_GRE_RUN);
6115         hr_utility.trace('NET_ASG_RUN = '||NET_ASG_RUN);
6116         hr_utility.trace('TOTAL_OWED = '||TOTAL_OWED);
6117         hr_utility.trace('DATE_SERVED = '||DATE_SERVED);
6118         hr_utility.trace('ADDITIONAL_AMOUNT_BALANCE = '||ADDITIONAL_AMOUNT_BALANCE);
6119         hr_utility.trace('REPLACEMENT_AMOUNT_BALANCE = '||REPLACEMENT_AMOUNT_BALANCE);
6120         hr_utility.trace('PRIMARY_AMOUNT_BALANCE = '||PRIMARY_AMOUNT_BALANCE);
6121         hr_utility.trace('TAX_LEVIES_ASG_GRE_PTD = '||TAX_LEVIES_ASG_GRE_PTD);
6122         hr_utility.trace('EIC_ADVANCE_ASG_GRE_RUN = ' || EIC_ADVANCE_ASG_GRE_RUN);
6123         hr_utility.trace('c_Federal_Minimum_Wage = ' || c_Federal_Minimum_Wage);
6124     END IF;
6125     /*
6126     Algorithm: Federal Tax Levies are calculated according to the following:
6127     1. Calculate Take Home Pay which equals gross earnings less taxes and deductions in
6128        effect prior to the date of levy.
6129     2. Calculate Fed levy exemption as the employees standard deduction for fed
6130        income tax purposes; plus the personal exemption allowance.
6131        Convert this annual figure to the payroll period type of the employee.
6132     3. The difference between Take Home Pay and the fed levy exemption is the
6133        amount to withhold - ie. everything!
6134 
6135     NOTE: The filing status and allowances to be used to compute standard and
6136           personal exemption MUST BE ENTERED, we will not use W-4 for this info.
6137 
6138     */
6139 
6140 
6141     /*--------- Set Contexts -------------*/
6142     CTX_BUSINESS_GROUP_ID := P_CTX_BUSINESS_GROUP_ID;
6143     CTX_PAYROLL_ID        := P_CTX_PAYROLL_ID;
6144     CTX_ELEMENT_TYPE_ID   := P_CTX_ELEMENT_TYPE_ID;
6145     CTX_ORIGINAL_ENTRY_ID := P_CTX_ORIGINAL_ENTRY_ID;
6146     CTX_DATE_EARNED       := P_CTX_DATE_EARNED;
6147     CTX_JURISDICTION_CODE := P_CTX_JURISDICTION_CODE;
6148     CTX_ELEMENT_ENTRY_ID  := P_CTX_ELEMENT_ENTRY_ID;
6149     /*------------------------------------*/
6150 
6151 
6152     dedn_amt := 0;
6153     not_taken := 0;
6154     calc_subprio := entry_subpriority;
6155     ld_filing_status_year := NULL;
6156 
6157     GLB_NUM_ELEM := GLB_NUM_ELEM - 1;
6158     hr_utility.trace('GLB_NUM_ELEM = '|| GLB_NUM_ELEM);
6159 
6160 
6161     -- Bug 4079142
6162     -- Get the element name to be used in the message.
6163     open csr_get_ele_name(CTX_ELEMENT_TYPE_ID);
6164     fetch csr_get_ele_name into lv_ele_name;
6165     close csr_get_ele_name;
6166 
6167     open csr_get_filing_status_year;
6168     fetch csr_get_filing_status_year into ld_filing_status_year;
6169     close csr_get_filing_status_year;
6170 
6171     IF ld_filing_status_year is not NULL THEN
6172        ld_filing_status_date := trunc(to_date(ld_filing_status_year,'YYYY')
6173                                       , 'Y');
6174     ELSE
6175        hr_utility.trace('Getting the Element Entry Start Date');
6176        open csr_get_entry_start_date;
6177        fetch csr_get_entry_start_date into ld_entry_start_date;
6178        close csr_get_entry_start_date;
6179 
6180        ld_filing_status_date := trunc(ld_entry_start_date,'Y');
6181     END IF;
6182 
6183     IF calc_subprio = 1 THEN
6184         IF date_served <> default_date THEN
6185             calc_subprio :=  sub_prio_max  - (PAY_EARNED_END_DATE - Date_Served);
6186         END IF;
6187     END IF;
6188 
6189     c_Fed_Levy_Exemption_Table := 'Federal Tax Standard Deduction Table';
6190     c_fed_levy_xmpt_tab_col := 'Exemption Amount';
6191     c_fed_levy_xmpt_per_xmpt_row := 'Personal Exemption';
6192 
6193     -- 5111601
6194     c_Fed_65_Blind_Exemption_Table := 'Federal Tax Additional Exemption Table' ;
6195     c_Fed_65_Blind_Xmpt_tab_col := 'Exemption Amount' ;
6196 
6197     --c_Federal_Minimum_Wage := 5.15;  /* Current as of Septemerr 1997. */
6198 
6199   /* *** Step #1 *** */
6200     -- Bug 4104842
6201     -- Use GLB_TL_GROSS_EARNINGS instead of GROSS_EARNINGS_ASG_GRE_RUN
6202     -- as GROSS_EARNINGS_ASG_GRE_RUN sums up Imputed Earnings too.
6203     -- Disposable Income calculation of Tax Levy does not include
6204     -- the same. THis will also ensure that the take_home_pay calculated for
6205     -- TL is based on the Earning Rules specified.
6206     -- Bug 4858720
6207     -- Use EIC_ADVANCE_ASG_GRE_RUN for calculatin the Deduction amount
6208     -- Bug 5095823
6209     take_home_pay := GLB_TL_GROSS_EARNINGS -
6210                      (TAX_DEDUCTIONS_ASG_GRE_RUN - EIC_ADVANCE_ASG_GRE_RUN) -
6211                      TOT_WHLD_SUPP_ASG_GRE_RUN -
6212                      GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN -
6213                      Dedns_at_Time_of_Writ;
6214 
6215   /* *** Step #2 *** */
6216 
6217     standard_deduction := get_table_value(c_Fed_Levy_Exemption_Table,
6218                                           c_fed_levy_xmpt_tab_col,
6219                                           Filing_Status,
6220                                           ld_filing_status_date);
6221 
6222     allowance_per_exemption := get_table_value(c_Fed_Levy_Exemption_Table,
6223                                                c_fed_levy_xmpt_tab_col,
6224                                                c_fed_levy_xmpt_per_xmpt_row,
6225                                                ld_filing_status_date);
6226 
6227     hr_utility.trace('Year of Exemption '|| to_char(ld_filing_status_date,
6228                                                     'DD-MON-YYYY'));
6229     hr_utility.trace('Exemption Amount '|| standard_deduction);
6230     hr_utility.trace('Personal Exemption '|| allowance_per_exemption);
6231 
6232 
6233     personal_exemption_allowance := TO_NUMBER(allowance_per_exemption) * Allowances;
6234 
6235     -- 5111601
6236     OPEN csr_get_blind_65_flag ;
6237     FETCH csr_get_blind_65_flag INTO lv_65_blind ;
6238     CLOSE csr_get_blind_65_flag ;
6239 
6240 
6241     IF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '01', '03' ) AND lv_65_blind = 1 THEN
6242        lv_temp_Filing_Status := 'Single 01' ;
6243     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '01', '03' ) AND lv_65_blind = 2 THEN
6244        lv_temp_Filing_Status := 'Single 02' ;
6245     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '02', '04' ) AND lv_65_blind = 1 THEN
6246        lv_temp_Filing_Status := 'Married 01' ;
6247     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '02', '04' ) AND lv_65_blind = 2 THEN
6248        lv_temp_Filing_Status := 'Married 02' ;
6249     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '02', '04' ) AND lv_65_blind = 3 THEN
6250        lv_temp_Filing_Status := 'Married 03' ;
6251     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '02', '04' ) AND lv_65_blind = 4 THEN
6252        lv_temp_Filing_Status := 'Married 04' ;
6253     ELSIF GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID) IN ( '01', '03' ) AND lv_65_blind in ( 3 , 4 ) THEN
6254        lv_temp_Filing_Status := 'Single 02' ;
6255 
6256        select decode(GLB_FIL_STAT(P_CTX_ORIGINAL_ENTRY_ID),'01','Single','03','Head Of HouseHold')
6257        into   lv_Filing_Status_name
6258        from   dual ;
6259        mesg := 'The value '|| to_char(lv_65_blind) ||' for EE or Spouse Blind / Age >= 65 is invalid '||
6260                'for the Filing Status '|| lv_Filing_Status_name || ' and has been overridden to 2. ' ||
6261                'Please correct the same before the next run.' ;
6262     ELSE
6263        lv_temp_Filing_Status := NULL ;
6264     END IF ;
6265 
6266     IF lv_temp_Filing_Status IS NOT NULL THEN
6267        exemption_for_age_65_or_blind := get_table_value(c_Fed_65_Blind_Exemption_Table,
6268                                                         c_Fed_65_Blind_Xmpt_tab_col,
6269                                                         lv_temp_Filing_Status,
6270                                                         ld_filing_status_date) ;
6271 
6272     ELSE
6273        exemption_for_age_65_or_blind := 0 ;
6274     END IF ;
6275     hr_utility.trace('Exemption Amount for Age >= 65 or Blind '||to_char(exemption_for_age_65_or_blind)) ;
6276 
6277     fed_levy_annual_exemption := TO_NUMBER(standard_deduction) +
6278                                  personal_exemption_allowance  +
6279                                  exemption_for_age_65_or_blind ;
6280 
6281     hr_utility.trace('Federal Levy Annual Exemption '||to_char(fed_levy_annual_exemption)) ;
6282 
6283     fed_levy_exemption := Convert_Period_Type(SCL_ASG_US_WORK_SCHEDULE,
6284                                               ASG_HOURS,
6285                                               fed_levy_annual_exemption,
6286                                               'YEAR',
6287                                               'NOT ENTERED',
6288                                               PAY_EARNED_START_DATE,
6289                                               PAY_EARNED_END_DATE,
6290                                               ASG_FREQ);
6291 
6292     hr_utility.trace('Federal Levy Exemption '||to_char(fed_levy_exemption)) ;
6293 
6294     IF TAX_LEVIES_ASG_GRE_PTD > 0 THEN
6295         fed_levy_exemption := 0;
6296     END IF;
6297 
6298     amt_at_hand := take_home_pay - fed_levy_exemption;
6299 
6300     IF Replacement_Amount_Balance = 0 AND Amount = 0 THEN
6301         dedn_amt := take_home_pay - fed_levy_exemption;
6302         IF dedn_amt < 0 THEN
6303             dedn_amt := 0;
6304         END IF;
6305     ELSE
6306         IF Replacement_Amount_Balance <> 0 THEN
6307             dedn_amt := Replacement_Amount_Balance;
6308             IF amt_at_hand < dedn_amt THEN
6309                 to_arrears := dedn_amt - amt_at_hand;
6310                 dedn_amt := take_home_pay - fed_levy_exemption;
6311                 not_taken := amt_at_hand - dedn_amt;
6312                 IF dedn_amt < 0 THEN
6313                     dedn_amt := 0;
6314                 END IF;
6315             END IF;
6316 
6317             to_repl := -1 * Replacement_Amount_Balance;
6318         ELSE
6319             dedn_amt := Amount;
6320             IF amt_at_hand < dedn_amt THEN
6321                 to_arrears := dedn_amt - amt_at_hand;
6322                 dedn_amt := take_home_pay - fed_levy_exemption;
6323                 not_taken :=  amt_at_hand - dedn_amt;
6324                 IF dedn_amt < 0 THEN
6325                     dedn_amt := 0;
6326                 END IF;
6327             END IF;
6328         END IF;
6329     END IF;
6330 
6331 
6332   /* *** Add in any adjustments. *** */
6333 
6334 
6335     IF Additional_Amount_Balance <> 0 THEN
6336        dedn_amt := dedn_amt + Additional_Amount_Balance;
6337        IF amt_at_hand < dedn_amt THEN
6338           not_taken := not_taken + Additional_Amount_Balance;
6339           to_arrears := not_taken + Additional_Amount_Balance;
6340           dedn_amt := take_home_pay - fed_levy_exemption;
6341           IF dedn_amt < 0 THEN
6342              dedn_amt := 0;
6343           END IF;
6344        END IF;
6345        to_addl := -1 * Additional_Amount_Balance;
6346     END IF;
6347 
6348 /* Start Cap functionality */
6349 -- Bug 3749162
6350     actual_dedn := dedn_amt;
6351     IF Monthly_Cap_Amount <> 0  THEN
6352         IF Monthly_Cap_Amount - Month_To_Date_Balance < 0 THEN
6353             fatal_mesg := 'MTD Balance > Monthly Cap by $' ||
6354                           TO_CHAR(Month_To_Date_Balance - Monthly_Cap_Amount ) ||
6355                           '. Adjust Balance for ' || lv_ele_name || '.';
6356             reset_global_var;
6357             RETURN(1);
6358         ELSE
6359             IF dedn_amt + Month_To_Date_Balance > Monthly_Cap_Amount THEN
6360                IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
6361                   actual_dedn := Monthly_Cap_Amount - Month_To_Date_Balance;
6362                   hr_utility.trace('Actual Deduction Amount(MTD) = ' || actual_dedn);
6363                   hr_utility.trace('Deduction Amount(MTD) = ' || dedn_amt);
6364                ELSE
6365                   dedn_amt := Monthly_Cap_Amount - Month_To_Date_Balance;
6366                END IF;
6367 
6368 	    END IF;
6369         END IF;
6370     END IF;
6371 
6372 -- Bug 3749162
6373     IF Period_Cap_Amount <> 0  THEN
6374         IF Period_Cap_Amount - Period_To_Date_Balance < 0 THEN
6375             fatal_mesg := 'PTD Balance > Period Cap by $' ||
6376                            TO_CHAR(Period_To_Date_Balance - Period_Cap_Amount ) ||
6377                           '. Adjust Balance for ' || lv_ele_name || '.';
6378             reset_global_var;
6379             RETURN(2);
6380         ELSE
6381             IF dedn_amt + Period_To_Date_Balance > Period_Cap_Amount THEN
6382                IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
6383                   IF actual_dedn > Period_Cap_Amount - Period_To_Date_Balance THEN
6384                      actual_dedn := Period_Cap_Amount - Period_To_Date_Balance;
6385                   END IF;
6386                   hr_utility.trace('Actual Deduction Amount(PTD) = ' || actual_dedn);
6387                   hr_utility.trace('Deduction Amount(PTD) = ' || dedn_amt);
6388                ELSE
6389                   dedn_amt := Period_Cap_Amount - Period_To_Date_Balance;
6390                END IF;
6391             END IF;
6392         END IF;
6393     END IF;
6394 
6395 /* End Cap functionality */
6396 
6397     -- Bug 4748532
6398     -- Deduct PTD amount for Garnishment and Fees if the value of
6399     -- GLB_FEES_ASG_GRE_PTD is not set to -9999(default_number) in BASE_FORMULA
6400     IF GLB_FEES_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) <> default_number THEN
6401        if Amount <> 0 then
6402           hr_utility.trace('Deduction that can be taken = ' || DEDN_AMT);
6403           hr_utility.trace('Deduction already taken     = ' || GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID));
6404           IF (dedn_amt + GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID)) > Amount THEN
6405              dedn_amt := Amount - GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
6406           END IF;
6407        elsif dedn_amt > GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID) then
6408           dedn_amt := dedn_amt - GLB_BASE_ASG_GRE_PTD(P_CTX_ORIGINAL_ENTRY_ID);
6409        else
6410           dedn_amt := 0;
6411        end if; -- if
6412 
6413         IF dedn_amt > actual_dedn THEN
6414            dedn_amt := actual_dedn;
6415         END IF;
6416     END IF; -- IF GLB_FEES_ASG_GRE_PTD
6417 
6418      -- Bug 4924454
6419      -- Take no deduction when Net Salary < 0
6420      --Bug 8607790 moving this after IF Total_Owed <> 0
6421 /*     IF NET_ASG_GRE_RUN < 0 THEN
6422         not_taken := 0;
6423         to_arrears := 0;
6424         dedn_amt := 0;
6425      ELSIF NET_ASG_GRE_RUN - dedn_amt < 0 THEN
6426          not_taken := dedn_amt - NET_ASG_RUN;
6427          to_arrears := dedn_amt - NET_ASG_RUN;
6428          dedn_amt := NET_ASG_GRE_RUN;
6429      END IF;*/
6430 
6431 
6432 /* *** Stop Rule Processing BEGIN *** */
6433 
6434     IF Total_Owed <> 0 THEN
6435         IF Primary_Amount_Balance - Period_to_Date_Balance < 0 THEN
6436             dedn_amt := 0;
6437             mesg := 'Total Owed already reached, so no federal tax levy being withheld for ' || lv_ele_name || '.';
6438             to_total_owed := 0;
6439         ELSE
6440             IF Total_Owed - Primary_Amount_Balance < 0 THEN
6441                 fatal_mesg := 'Deduction Balance > Total Owed by $' ||
6442                               TO_CHAR(Primary_Amount_Balance - Total_Owed ) || '. Adjust Balance for ' || lv_ele_name || '.';
6443                 reset_global_var;
6444                 RETURN(3);
6445             ELSE
6446                 IF Primary_Amount_Balance + dedn_amt >= Total_Owed THEN
6447                     dedn_amt := Total_Owed - Primary_Amount_Balance;
6448                     STOP_ENTRY := 'Y';
6449                     mesg := 'Federal tax levy obligation has been satisfied for ' || lv_ele_name || ' because of Total Owed Reached.';
6450                     IF Primary_Amount_Balance <> 0 THEN
6451                         to_total_owed := -1 * Primary_Amount_Balance;
6452                     ELSE
6453                         to_total_owed := 0;
6454                     END IF;
6455                 ELSE
6456                     to_total_owed := dedn_amt;
6457                 END IF;
6458             END IF;
6459         END IF;
6460     ELSE
6461         to_total_owed := dedn_amt;
6462     END IF;
6463 --moved this for resoving bug 8607790
6464      IF NET_ASG_GRE_RUN < 0 THEN
6465         not_taken := 0;
6466         to_arrears := 0;
6467         dedn_amt := 0;
6468      ELSIF NET_ASG_GRE_RUN - dedn_amt < 0 THEN
6469          not_taken := dedn_amt - NET_ASG_RUN;
6470          to_arrears := dedn_amt - NET_ASG_RUN;
6471          dedn_amt := NET_ASG_GRE_RUN;
6472      END IF;
6473 --bug 8607790 fix ends here
6474 
6475     garn_limit_days := get_garn_limit_max_duration(PAY_EARNED_START_DATE);
6476 
6477    /*
6478     * Bug 3718454
6479     * Added 1 to the calculation of garn_days as the both
6480     * PAY_EARNED_END_DATE and VF_DATE_SERVED should be included for
6481     * calculating the STOP_ENTRY value
6482     */
6483 
6484     IF garn_limit_days > 0 THEN
6485         garn_days := PAY_EARNED_END_DATE - Date_Served + 1;
6486         IF garn_days >= garn_limit_days THEN
6487             garn_days_end_per := PAY_EARNED_START_DATE - Date_Served + 1;
6488             /*
6489              * Added the IF condition te determine whether any amount needs
6490              * to be deducted.(Bug 3718454 and 3734415)
6491 	     * Bug 3777900 : Removed '=' sign from the IF condition below
6492              */
6493             IF garn_days_end_per > garn_limit_days THEN
6494                 STOP_ENTRY := 'Y';
6495                 DEDN_AMT := 0;
6496                 mesg := garn_limit_days || ' days Limit for element ' || lv_ele_name || ' was reached before current pay period. No Deduction will be taken. Element will be end dated';
6497                 IF Primary_Amount_Balance <> 0 THEN
6498                     to_total_owed := -1 * Primary_Amount_Balance;
6499                 ELSE
6500                     to_total_owed := 0;
6501                 END IF;
6502             ELSE
6503                 STOP_ENTRY := 'Y';
6504                 mesg := 'Federal tax levy obligation has been satisfied for ' || lv_ele_name || ' because of Max Withholding Days Limit Reached.';
6505                 IF Primary_Amount_Balance <> 0 THEN
6506                     to_total_owed := -1 * Primary_Amount_Balance;
6507                 ELSE
6508                     to_total_owed := 0;
6509                 END IF;
6510             END IF;
6511         END IF;
6512     END IF;
6513 
6514 -- Commented the following Final Pay section for Bug 4107302
6515 /* *** Final Pay Section BEGIN *** */
6516     /*
6517     IF (TERMINATED_EMPLOYEE = 'Y' AND FINAL_PAY_PROCESSED = 'N') THEN
6518         STOP_ENTRY := 'Y';
6519     END IF;
6520     */
6521 /* *** Final Pay Section END *** */
6522 
6523     calcd_dedn_amt := dedn_amt;
6524 
6525     -- Bug 3500570
6526     IF NET_ASG_GRE_RUN > amt_at_hand THEN
6527     	not_taken := 0;
6528     END IF;
6529 
6530     IF l_debug_on = 'Y' THEN
6531         hr_utility.trace('Values returned ...');
6532         hr_utility.trace('CALCD_DEDN_AMT = '||CALCD_DEDN_AMT);
6533         hr_utility.trace('NOT_TAKEN = '||NOT_TAKEN);
6534         hr_utility.trace('TO_ARREARS = '||TO_ARREARS);
6535         hr_utility.trace('TO_TOTAL_OWED = '||TO_TOTAL_OWED);
6536         hr_utility.trace('TO_ADDL = '||TO_ADDL);
6537         hr_utility.trace('TO_REPL = '||TO_REPL);
6538         hr_utility.trace('FATAL_MESG = '||FATAL_MESG);
6539         hr_utility.trace('MESG = '||MESG);
6540         hr_utility.trace('CALC_SUBPRIO = '||CALC_SUBPRIO);
6541         hr_utility.trace('STOP_ENTRY = '||STOP_ENTRY);
6542     END IF;
6543 
6544     if GLB_NUM_ELEM = 0 then
6545        reset_global_var;
6546     end if;
6547 
6548     hr_utility.trace('Leaving '||l_proc_name);
6549 
6550     RETURN(4);
6551 END cal_formula_tl;
6552 
6553 
6554   /****************************************************************************
6555     Name        : GET_TABLE_VALUE
6556     Description : This function returns the value stored by specified column in
6557                   the specified table.
6558   *****************************************************************************/
6559 
6560 
6561 FUNCTION GET_TABLE_VALUE
6562 (
6563 C_FED_LEVY_EXEMPTION_TABLE varchar2,
6564 C_FED_LEVY_XMPT_TAB_COL varchar2,
6565 FILING_STATUS varchar2,
6566 FILING_STATUS_YEAR date
6567 ) RETURN pay_user_column_instances_f.value%TYPE IS
6568 BEGIN
6569     RETURN(hruserdt.get_table_value(
6570                                     CTX_BUSINESS_GROUP_ID,
6571                                     C_FED_LEVY_EXEMPTION_TABLE,
6572                                     C_FED_LEVY_XMPT_TAB_COL,
6573                                     FILING_STATUS,
6574                                     FILING_STATUS_YEAR
6575                                     ));
6576 END GET_TABLE_VALUE;
6577 
6578   /****************************************************************************
6579     Name        : GET_CCPA_PROTECTION
6580     Description : This function returns CCPA Protectiosn value which is then
6581                   serves as an upper limit of amount that can be deducted.
6582   *****************************************************************************/
6583 
6584 
6585 FUNCTION GET_CCPA_PROTECTION
6586 (
6587 TOTAL_DI number,
6588 OTHERS_DI number,
6589 SUPPORT_DI number,
6590 CCPA_PROT_PERC number
6591 ) RETURN number IS
6592 
6593     ln_ccpa_protection number;
6594     l_proc_name varchar2(50);
6595 
6596 BEGIN
6597 
6598      -- Initialization Code
6599      ln_ccpa_protection := 0;
6600      l_proc_name := l_package_name||'GET_CCPA_PROTECTION';
6601 
6602      hr_utility.trace('Entering '||l_proc_name);
6603 
6604      IF GLB_DCIA_EXIST_FLAG THEN
6605          -- Bug 4079142
6606          -- Checking for Federal Consumer Credit Protection Act in case of DCIA
6607          -- using the following rule
6608          -- 1. Total deduction should not go beyond 25% of 'Others DI' in case of
6609          --    DCIA along with Other Deductions
6610          -- 2. Total deduction should not go beyond 25% of 'Supp DI' in case of
6611          --    DCIA along with Support Deductions
6612          -- 3. Total deduction should not go beyond 25% of 'Others DI' in case of
6613          --    DCIA along with Other Deductions and Support Deductions
6614          IF GLB_OTHER_DI_FLAG THEN
6615              ln_ccpa_protection := CCPA_PROT_PERC * OTHERS_DI;
6616              hr_utility.trace('Others DI = ' || OTHERS_DI);
6617              hr_utility.trace('CCPA Protection = ' || ln_ccpa_protection);
6618          ELSIF GLB_SUPPORT_DI is not NULL THEN
6619              ln_ccpa_protection := .25 * GLB_SUPPORT_DI;
6620              hr_utility.trace('Support DI = ' || GLB_SUPPORT_DI);
6621              hr_utility.trace('CCPA Protection = ' || ln_ccpa_protection);
6622          ELSE
6623              ln_ccpa_protection := CCPA_PROT_PERC * TOTAL_DI;
6624              hr_utility.trace('Total DI = ' || TOTAL_DI);
6625              hr_utility.trace('CCPA Protection = ' || ln_ccpa_protection);
6626          END IF;
6627      ELSE
6628          -- If DCIA element is not processed then CCPA value is
6629          -- calculated the current DI value.
6630          ln_ccpa_protection := CCPA_PROT_PERC * TOTAL_DI;
6631          hr_utility.trace('Total DI = ' || TOTAL_DI);
6632          hr_utility.trace('CCPA Protection = ' || ln_ccpa_protection);
6633      END IF;
6634 
6635      hr_utility.trace('Leaving '||l_proc_name);
6636 
6637      RETURN ln_ccpa_protection;
6638 
6639 END GET_CCPA_PROTECTION;
6640 
6641 
6642 /****************************************************************************
6643     Name        : RESET_GLOBAL_VAR
6644     Description : This procedure deletes all Global tables created and
6645                   resets the value of other Global variables.
6646 *****************************************************************************/
6647 PROCEDURE RESET_GLOBAL_VAR IS
6648    l_proc_name varchar2(50);
6649 BEGIN
6650     l_proc_name := l_package_name || 'RESET_GLOBAL_VAR';
6651     hr_utility.trace('Entering '||l_proc_name);
6652 
6653     dedn_tab.delete;
6654     gar_dedn_tab.delete;
6655     fees_tab.delete;
6656     arrears_tab.delete;
6657     actual_dedn_tab.delete;
6658     mod_dedn_tab.delete ; /* Bug# 5295813 */
6659     GLB_AMT.delete;
6660     GLB_ARREARS_OVERRIDE.delete;
6661     GLB_ARREARS_DATE.delete;
6662     GLB_NUM_DEPS.delete;
6663     GLB_FIL_STAT.delete;
6664     GLB_ALLOWS.delete;
6665     GLB_DEDN_OVERRIDE.delete;
6666     GLB_PCT.delete;
6667     GLB_MTD_BAL.delete;
6668     GLB_EXEMPT_AMT.delete;
6669     GLB_PTD_CAP_AMT.delete;
6670     GLB_PTD_BAL.delete;
6671     GLB_TO_ACCRUED_FEES.delete;
6672     GLB_MONTH_CAP_AMT.delete;
6673     GLB_FEES_ASG_GRE_PTD.delete;
6674     GLB_BASE_ASG_GRE_PTD.delete;
6675     GLB_TOT_WHLD_SUPP_ASG_GRE_RUN := NULL;
6676     GLB_TOT_WHLD_ARR_ASG_GRE_RUN := NULL;
6677     GLB_ALLOW_MULT_DEDN := NULL;
6678     GLB_NUM_ELEM := NULL;
6679     GLB_TL_GROSS_EARNINGS := NULL;
6680     GLB_TOTAL_WHLD_FEE_ASG_GRE_RUN := NULL;
6681     GLB_SUPPORT_DI := NULL;  /* Bug# 8556724 */
6682     --bug 9788510
6683     GLB_MULTIPLE_GARN:=NULL;
6684     --bug 9788510
6685     -- Bug 14265307
6686     GLB_TOTAL_WHLD_SUPPP_FEE_MNTH := NULL;
6687     hr_utility.trace('Global Tables Deleted');
6688     hr_utility.trace('Leaving '||l_proc_name);
6689 
6690 EXCEPTION
6691     WHEN OTHERS THEN
6692     NULL;
6693 
6694 END;
6695 
6696 END PAY_US_INV_DED_FORMULAS;