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