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.lethe.reports;
18  
19  import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
20  import io.github.tonywasher.joceanus.metis.report.MetisReportBase;
21  import io.github.tonywasher.joceanus.metis.report.MetisReportHTMLBuilder;
22  import io.github.tonywasher.joceanus.metis.report.MetisReportHTMLBuilder.MetisHTMLTable;
23  import io.github.tonywasher.joceanus.metis.report.MetisReportManager;
24  import io.github.tonywasher.joceanus.metis.report.MetisReportReferenceManager.DelayedTable;
25  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
26  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticResource;
27  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseTaxClass;
28  import io.github.tonywasher.joceanus.moneywise.lethe.data.analysis.data.MoneyWiseAnalysis;
29  import io.github.tonywasher.joceanus.moneywise.lethe.views.MoneyWiseAnalysisFilter;
30  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxAnalysis;
31  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxDueBucket;
32  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxDueBucket.MoneyWiseTaxBandBucket;
33  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxResource;
34  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxYear;
35  import org.w3c.dom.Document;
36  import org.w3c.dom.Element;
37  
38  import java.util.Iterator;
39  
40  /**
41   * TaxCalculation report builder.
42   */
43  public class MoneyWiseReportTaxCalculation
44          extends MetisReportBase<MoneyWiseAnalysis, MoneyWiseAnalysisFilter<?, ?>> {
45      /**
46       * The Title text.
47       */
48      private static final String TEXT_TITLE = MoneyWiseReportResource.TAXCALC_TITLE.getValue();
49  
50      /**
51       * The Income text.
52       */
53      private static final String TEXT_INCOME = MoneyWiseTaxResource.TAXBANDS_INCOME.getValue();
54  
55      /**
56       * The Rate text.
57       */
58      private static final String TEXT_RATE = MoneyWiseBasicResource.MONEYWISEDATA_FIELD_RATE.getValue();
59  
60      /**
61       * The TaxDue text.
62       */
63      private static final String TEXT_TAXDUE = MoneyWiseTaxResource.TAXBANDS_TAXDUE.getValue();
64  
65      /**
66       * The Profit text.
67       */
68      private static final String TEXT_PROFIT = MoneyWiseTaxResource.TAXYEAR_PROFIT.getValue();
69  
70      /**
71       * HTML builder.
72       */
73      private final MetisReportHTMLBuilder theBuilder;
74  
75      /**
76       * The Formatter.
77       */
78      private final OceanusDataFormatter theFormatter;
79  
80      /**
81       * Constructor.
82       *
83       * @param pManager the Report Manager
84       */
85      protected MoneyWiseReportTaxCalculation(final MetisReportManager<MoneyWiseAnalysisFilter<?, ?>> pManager) {
86          /* Access underlying utilities */
87          theBuilder = pManager.getBuilder();
88          theFormatter = theBuilder.getDataFormatter();
89      }
90  
91      /**
92       * Build a web output of the taxation report.
93       *
94       * @param pAnalysis the analysis
95       * @return Web output
96       */
97      @Override
98      public Document createReport(final MoneyWiseAnalysis pAnalysis) {
99          /* Access the bucket lists */
100         final MoneyWiseTaxAnalysis myTaxAnalysis = pAnalysis.getTaxAnalysis();
101         final MoneyWiseTaxYear myYear = myTaxAnalysis.getTaxYear();
102 
103         /* Start the report */
104         final Element myBody = theBuilder.startReport();
105         theBuilder.makeTitle(myBody, TEXT_TITLE, theFormatter.formatObject(myYear.getYearEnd()));
106 
107         /* Format the header */
108         final MetisHTMLTable myTable = theBuilder.startTable(myBody);
109         theBuilder.startHdrRow(myTable);
110         theBuilder.makeTitleCell(myTable, MoneyWiseStaticResource.TAXBASIS_NAME.getValue());
111         theBuilder.makeTitleCell(myTable, TEXT_INCOME);
112         theBuilder.makeTitleCell(myTable, TEXT_TAXDUE);
113 
114         /* Loop through the Tax Due Buckets */
115         final Iterator<MoneyWiseTaxDueBucket> myTaxIterator = myTaxAnalysis.taxDueIterator();
116         while (myTaxIterator.hasNext()) {
117             final MoneyWiseTaxDueBucket myBucket = myTaxIterator.next();
118 
119             /* Format the line */
120             theBuilder.startRow(myTable);
121             theBuilder.makeTableLinkCell(myTable, myBucket.getTaxBasis().toString());
122             theBuilder.makeValueCell(myTable, myBucket.getTaxableIncome());
123             theBuilder.makeValueCell(myTable, myBucket.getTaxDue());
124 
125             /* Format the detail */
126             makeTaxReport(myTable, myBucket);
127         }
128 
129         /* Access the Totals */
130         theBuilder.startTotalRow(myTable);
131         theBuilder.makeTotalCell(myTable, MoneyWiseReportBuilder.TEXT_TOTAL);
132         theBuilder.makeTotalCell(myTable, myTaxAnalysis.getTaxableIncome());
133         theBuilder.makeTotalCell(myTable, myTaxAnalysis.getTaxDue());
134         theBuilder.startTotalRow(myTable);
135         theBuilder.makeTotalCell(myTable, MoneyWiseTaxClass.TAXPAID.toString());
136         theBuilder.makeStretchedTotalCell(myTable, myTaxAnalysis.getTaxPaid());
137         theBuilder.startTotalRow(myTable);
138         theBuilder.makeTotalCell(myTable, TEXT_PROFIT);
139         theBuilder.makeStretchedTotalCell(myTable, myTaxAnalysis.getTaxProfit());
140 
141         /* Return the document */
142         return theBuilder.getDocument();
143     }
144 
145     /**
146      * Build a standard tax report element.
147      *
148      * @param pParent  the parent table
149      * @param pSummary the tax summary
150      */
151     public void makeTaxReport(final MetisHTMLTable pParent,
152                               final MoneyWiseTaxDueBucket pSummary) {
153         /* Format the detail */
154         final MetisHTMLTable myTable = theBuilder.createEmbeddedTable(pParent);
155         theBuilder.startRow(myTable);
156         theBuilder.makeTitleCell(myTable, TEXT_INCOME);
157         theBuilder.makeTitleCell(myTable, TEXT_RATE);
158         theBuilder.makeTitleCell(myTable, TEXT_TAXDUE);
159 
160         /* Loop through the Transaction Detail Buckets */
161         final Iterator<MoneyWiseTaxBandBucket> myIterator = pSummary.taxBandIterator();
162         while (myIterator.hasNext()) {
163             final MoneyWiseTaxBandBucket myBucket = myIterator.next();
164 
165             /* Format the detail */
166             theBuilder.startRow(myTable);
167             theBuilder.makeValueCell(myTable, myBucket.getAmount());
168             theBuilder.makeValueCell(myTable, myBucket.getRate());
169             theBuilder.makeValueCell(myTable, myBucket.getTaxDue());
170         }
171 
172         /* Embed the table correctly */
173         theBuilder.embedTable(myTable, pSummary.getTaxBasis().toString());
174     }
175 
176     @Override
177     public MoneyWiseAnalysisFilter<?, ?> processFilter(final Object pSource) {
178         return null;
179     }
180 
181     @Override
182     public MetisHTMLTable createDelayedTable(final DelayedTable pTable) {
183         return null;
184     }
185 }