1 /*
2 * MoneyWise: Finance Application
3 * Copyright 2012-2026. Tony Washer
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17 package io.github.tonywasher.joceanus.moneywise.tax;
18
19 import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
20
21 import java.util.Currency;
22
23 /**
24 * Marginal allowance reduction.
25 */
26 public enum MoneyWiseMarginalReduction {
27 /**
28 * Half.
29 */
30 ONEINTWO(1, 2),
31
32 /**
33 * TwoThirds.
34 */
35 TWOINTHREE(2, 3);
36
37 /**
38 * The String name.
39 */
40 private String theName;
41
42 /**
43 * The multiplier.
44 */
45 private final int theMultiplier;
46
47 /**
48 * The quotient.
49 */
50 private final int theQuotient;
51
52 /**
53 * Constructor.
54 *
55 * @param pMultiplier the multiplier
56 * @param pQuotient the quotient
57 */
58 MoneyWiseMarginalReduction(final int pMultiplier,
59 final int pQuotient) {
60 theMultiplier = pMultiplier;
61 theQuotient = pQuotient;
62 }
63
64 @Override
65 public String toString() {
66 /* If we have not yet loaded the name */
67 if (theName == null) {
68 /* Load the name */
69 theName = MoneyWiseTaxResource.getKeyForMarginalReduction(this).getValue();
70 }
71
72 /* return the name */
73 return theName;
74 }
75
76 /**
77 * Calculate the allowance reduction.
78 *
79 * @param pGrossTaxable the gross taxable income
80 * @param pLimit the allowance limit
81 * @return the reduction
82 */
83 public OceanusMoney calculateReduction(final OceanusMoney pGrossTaxable,
84 final OceanusMoney pLimit) {
85 /* Determine the amount by which we are over the limit */
86 final OceanusMoney myExcess = new OceanusMoney(pGrossTaxable);
87 myExcess.subtractAmount(pLimit);
88
89 /* Determine the quotient and multiplier in the required currency */
90 final Currency myCurrency = myExcess.getCurrency();
91 final OceanusMoney myQuotient = OceanusMoney.getWholeUnits(theQuotient, myCurrency);
92 final OceanusMoney myMultiplier = OceanusMoney.getWholeUnits(theMultiplier, myCurrency);
93
94 /* Calculate the reduction */
95 myExcess.divide(myQuotient.unscaledValue());
96 myExcess.multiply(myMultiplier.unscaledValue());
97
98 /* return the reduction */
99 return myExcess;
100 }
101 }