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