View Javadoc
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.uk;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusFiscalYear;
21  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusRate;
22  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
23  import io.github.tonywasher.joceanus.metis.preference.MetisPreferenceManager;
24  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseTaxClass;
25  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxResource;
26  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxSource;
27  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxYear;
28  
29  import java.time.Month;
30  
31  /**
32   * The UK Tax Year.
33   */
34  public class MoneyWiseUKTaxYear
35          extends MoneyWiseTaxYear {
36      /**
37       * Local Report fields.
38       */
39      private static final MetisFieldSet<MoneyWiseUKTaxYear> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseUKTaxYear.class);
40  
41      /*
42       * Declare Fields.
43       */
44      static {
45          FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXYEAR_ALLOWANCES, MoneyWiseUKTaxYear::getAllowances);
46          FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXYEAR_BANDS, MoneyWiseUKTaxYear::getTaxBands);
47          FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXYEAR_INTEREST, MoneyWiseUKTaxYear::getInterestScheme);
48          FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXYEAR_DIVIDEND, MoneyWiseUKTaxYear::getDividendScheme);
49          FIELD_DEFS.declareLocalField(MoneyWiseTaxResource.TAXYEAR_CAPITAL, MoneyWiseUKTaxYear::getCapitalScheme);
50      }
51  
52      /**
53       * The Allowances.
54       */
55      private final MoneyWiseUKBasicAllowance theAllowances;
56  
57      /**
58       * The TaxBands.
59       */
60      private final MoneyWiseUKTaxBands theTaxBands;
61  
62      /**
63       * The Income Scheme.
64       */
65      private final MoneyWiseUKIncomeScheme theIncomeScheme;
66  
67      /**
68       * The Rental Scheme.
69       */
70      private final MoneyWiseUKRoomRentalScheme theRentalScheme;
71  
72      /**
73       * The Interest Scheme.
74       */
75      private final MoneyWiseUKInterestScheme theInterestScheme;
76  
77      /**
78       * The Dividends Scheme.
79       */
80      private final MoneyWiseUKDividendScheme theDividendScheme;
81  
82      /**
83       * The ChargeableGains Scheme.
84       */
85      private final MoneyWiseUKChargeableGainsScheme theChargeableGainsScheme;
86  
87      /**
88       * The Capital Gains Scheme.
89       */
90      private final MoneyWiseUKCapitalScheme theCapitalScheme;
91  
92      /**
93       * Constructor.
94       *
95       * @param pDate       the tax year end
96       * @param pAllowances the allowances
97       * @param pTaxBands   the standard tax bands
98       * @param pInterest   the interest scheme
99       * @param pDividend   the dividend scheme
100      * @param pCapital    the capital gains scheme
101      */
102     protected MoneyWiseUKTaxYear(final int pDate,
103                                  final MoneyWiseUKBasicAllowance pAllowances,
104                                  final MoneyWiseUKTaxBands pTaxBands,
105                                  final MoneyWiseUKInterestScheme pInterest,
106                                  final MoneyWiseUKDividendScheme pDividend,
107                                  final MoneyWiseUKCapitalScheme pCapital) {
108         super(getDate(pDate));
109         theAllowances = pAllowances;
110         theTaxBands = pTaxBands;
111         theIncomeScheme = new MoneyWiseUKIncomeScheme();
112         theRentalScheme = new MoneyWiseUKRoomRentalScheme();
113         theInterestScheme = pInterest;
114         theDividendScheme = pDividend;
115         theChargeableGainsScheme = new MoneyWiseUKChargeableGainsScheme();
116         theCapitalScheme = pCapital;
117     }
118 
119     /**
120      * Obtain the Allowances.
121      *
122      * @return the allowances
123      */
124     public MoneyWiseUKBasicAllowance getAllowances() {
125         return theAllowances;
126     }
127 
128     /**
129      * Obtain the Standard taxBands.
130      *
131      * @return the tax bands
132      */
133     public MoneyWiseUKTaxBands getTaxBands() {
134         return theTaxBands;
135     }
136 
137     /**
138      * Obtain the Interest TaxScheme.
139      *
140      * @return the tax scheme
141      */
142     private MoneyWiseUKInterestScheme getInterestScheme() {
143         return theInterestScheme;
144     }
145 
146     /**
147      * Obtain the Dividend TaxScheme.
148      *
149      * @return the tax scheme
150      */
151     private MoneyWiseUKDividendScheme getDividendScheme() {
152         return theDividendScheme;
153     }
154 
155     /**
156      * Obtain the Capital TaxScheme.
157      *
158      * @return the tax scheme
159      */
160     private MoneyWiseUKCapitalScheme getCapitalScheme() {
161         return theCapitalScheme;
162     }
163 
164     /**
165      * Determine the taxYear end.
166      *
167      * @param pYear the taxYear as an integer
168      * @return the amount
169      */
170     private static OceanusDate getDate(final int pYear) {
171         final OceanusDate myDate = new OceanusDate(pYear, Month.JANUARY, 1);
172         return OceanusFiscalYear.UK.endOfYear(myDate);
173     }
174 
175     @Override
176     public MetisFieldSet<MoneyWiseUKTaxYear> getDataFieldSet() {
177         return FIELD_DEFS;
178     }
179 
180     @Override
181     public boolean isTaxCreditRequired() {
182         return !(theAllowances instanceof MoneyWiseUKSavingsAllowance);
183     }
184 
185     @Override
186     public OceanusRate getTaxCreditRateForInterest() {
187         return theInterestScheme.getTaxCreditRate(this);
188     }
189 
190     @Override
191     public OceanusRate getTaxCreditRateForDividend() {
192         return theDividendScheme.getTaxCreditRate(this);
193     }
194 
195     @Override
196     public MoneyWiseUKTaxAnalysis analyseTaxYear(final MetisPreferenceManager pPreferences,
197                                                  final MoneyWiseTaxSource pTaxSource) {
198         /* Create a new analysis */
199         final MoneyWiseUKTaxAnalysis myAnalysis = new MoneyWiseUKTaxAnalysis(pTaxSource, pPreferences, this);
200 
201         /* Process the standard amounts */
202         myAnalysis.processItem(MoneyWiseTaxClass.SALARY, theIncomeScheme);
203         myAnalysis.processItem(MoneyWiseTaxClass.RENTALINCOME, theIncomeScheme);
204         myAnalysis.processItem(MoneyWiseTaxClass.ROOMRENTAL, theRentalScheme);
205         myAnalysis.processItem(MoneyWiseTaxClass.OTHERINCOME, theIncomeScheme);
206 
207         /* Process the interest */
208         myAnalysis.processItem(MoneyWiseTaxClass.TAXEDINTEREST, theInterestScheme);
209         myAnalysis.processItem(MoneyWiseTaxClass.UNTAXEDINTEREST, theInterestScheme);
210         myAnalysis.processItem(MoneyWiseTaxClass.PEER2PEERINTEREST, theInterestScheme);
211 
212         /* Process the dividends */
213         myAnalysis.processItem(MoneyWiseTaxClass.DIVIDEND, theDividendScheme);
214         myAnalysis.processItem(MoneyWiseTaxClass.UNITTRUSTDIVIDEND, theDividendScheme);
215         myAnalysis.processItem(MoneyWiseTaxClass.FOREIGNDIVIDEND, theDividendScheme);
216 
217         /* Process the chargeable Gains */
218         myAnalysis.processItem(MoneyWiseTaxClass.CHARGEABLEGAINS, theChargeableGainsScheme);
219 
220         /* Process the capital Gains */
221         myAnalysis.processItem(MoneyWiseTaxClass.RESIDENTIALGAINS, theCapitalScheme);
222         myAnalysis.processItem(MoneyWiseTaxClass.CAPITALGAINS, theCapitalScheme);
223 
224         /* Calculate the totals */
225         myAnalysis.calculateTaxDue();
226         myAnalysis.calculateTaxProfit();
227 
228         /* Return the analysis */
229         return myAnalysis;
230     }
231 }