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.atlas.data.analysis.buckets;
18  
19  import io.github.tonywasher.joceanus.oceanus.date.OceanusDate;
20  import io.github.tonywasher.joceanus.oceanus.date.OceanusDateRange;
21  import io.github.tonywasher.joceanus.oceanus.decimal.OceanusMoney;
22  import io.github.tonywasher.joceanus.oceanus.format.OceanusDataFormatter;
23  import io.github.tonywasher.joceanus.oceanus.logger.OceanusLogManager;
24  import io.github.tonywasher.joceanus.oceanus.logger.OceanusLogger;
25  import io.github.tonywasher.joceanus.metis.field.MetisFieldItem;
26  import io.github.tonywasher.joceanus.metis.field.MetisFieldSet;
27  import io.github.tonywasher.joceanus.metis.preference.MetisPreferenceManager;
28  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.base.MoneyWiseXAnalysisEventList;
29  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisCashBucket.MoneyWiseXAnalysisCashBucketList;
30  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisCashCategoryBucket.MoneyWiseXAnalysisCashCategoryBucketList;
31  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisDepositBucket.MoneyWiseXAnalysisDepositBucketList;
32  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisDepositCategoryBucket.MoneyWiseXAnalysisDepositCategoryBucketList;
33  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisInterfaces.MoneyWiseXAnalysisCursor;
34  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisLoanBucket.MoneyWiseXAnalysisLoanBucketList;
35  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisLoanCategoryBucket.MoneyWiseXAnalysisLoanCategoryBucketList;
36  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisPayeeBucket.MoneyWiseXAnalysisPayeeBucketList;
37  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisPortfolioBucket.MoneyWiseXAnalysisPortfolioBucketList;
38  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisTaxBasisBucket.MoneyWiseXAnalysisTaxBasisBucketList;
39  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisTransCategoryBucket.MoneyWiseXAnalysisTransCategoryBucketList;
40  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.buckets.MoneyWiseXAnalysisTransTagBucket.MoneyWiseXAnalysisTransTagBucketList;
41  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisAccountAttr;
42  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisPayeeAttr;
43  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisSecurityAttr;
44  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisTaxBasisAttr;
45  import io.github.tonywasher.joceanus.moneywise.atlas.data.analysis.values.MoneyWiseXAnalysisTransAttr;
46  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicDataType;
47  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseBasicResource;
48  import io.github.tonywasher.joceanus.moneywise.data.basic.MoneyWiseDataSet;
49  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseCurrency;
50  import io.github.tonywasher.joceanus.moneywise.data.statics.MoneyWiseStaticDataType;
51  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxAnalysis;
52  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxYear;
53  import io.github.tonywasher.joceanus.moneywise.tax.MoneyWiseTaxYearCache;
54  import io.github.tonywasher.joceanus.moneywise.tax.uk.MoneyWiseUKTaxYearCache;
55  import io.github.tonywasher.joceanus.prometheus.views.PrometheusEditSet;
56  
57  /**
58   * Data Analysis.
59   *
60   * @author Tony Washer
61   */
62  public class MoneyWiseXAnalysis
63          implements MetisFieldItem {
64      /**
65       * Logger.
66       */
67      private static final OceanusLogger LOGGER = OceanusLogManager.getLogger(MoneyWiseXAnalysis.class);
68  
69      /**
70       * Local Report fields.
71       */
72      private static final MetisFieldSet<MoneyWiseXAnalysis> FIELD_DEFS = MetisFieldSet.newFieldSet(MoneyWiseXAnalysis.class);
73  
74      /*
75       * Declare Fields.
76       */
77      static {
78          FIELD_DEFS.declareLocalField(MoneyWiseBasicResource.MONEYWISEDATA_RANGE, MoneyWiseXAnalysis::getDateRange);
79          FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.TAX_YEARS, MoneyWiseXAnalysis::getTaxYearCache);
80          FIELD_DEFS.declareLocalField(MoneyWiseStaticDataType.CURRENCY, MoneyWiseXAnalysis::getCurrency);
81          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.DEPOSIT.getListId(), MoneyWiseXAnalysis::getDeposits);
82          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.CASH.getListId(), MoneyWiseXAnalysis::getCash);
83          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.LOAN.getListId(), MoneyWiseXAnalysis::getLoans);
84          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.PAYEE.getListId(), MoneyWiseXAnalysis::getPayees);
85          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.PORTFOLIO.getListId(), MoneyWiseXAnalysis::getPortfolios);
86          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.DEPOSITCATEGORY.getListId(), MoneyWiseXAnalysis::getDepositCategories);
87          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.CASHCATEGORY.getListId(), MoneyWiseXAnalysis::getCashCategories);
88          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.LOANCATEGORY.getListId(), MoneyWiseXAnalysis::getLoanCategories);
89          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.TRANSCATEGORY.getListId(), MoneyWiseXAnalysis::getTransCategories);
90          FIELD_DEFS.declareLocalField(MoneyWiseBasicDataType.TRANSTAG.getListId(), MoneyWiseXAnalysis::getTransactionTags);
91          FIELD_DEFS.declareLocalField(MoneyWiseStaticDataType.TAXBASIS.getListId(), MoneyWiseXAnalysis::getTaxBasis);
92          FIELD_DEFS.declareLocalField(MoneyWiseXAnalysisBucketResource.TAX_CALCULATION, MoneyWiseXAnalysis::getTaxAnalysis);
93      }
94  
95      /**
96       * The EditSet.
97       */
98      private final PrometheusEditSet theEditSet;
99  
100     /**
101      * The Cursor.
102      */
103     private final MoneyWiseXAnalysisCursor theCursor;
104 
105     /**
106      * The taxYear cache.
107      */
108     private final MoneyWiseTaxYearCache theTaxYearCache;
109 
110     /**
111      * The Currency.
112      */
113     private final MoneyWiseCurrency theCurrency;
114 
115     /**
116      * The Preference Manager.
117      */
118     private final MetisPreferenceManager thePreferences;
119 
120     /**
121      * The DataRange.
122      */
123     private final OceanusDateRange theDateRange;
124 
125     /**
126      * The deposit buckets.
127      */
128     private final MoneyWiseXAnalysisDepositBucketList theDeposits;
129 
130     /**
131      * The cash buckets.
132      */
133     private final MoneyWiseXAnalysisCashBucketList theCash;
134 
135     /**
136      * The loan buckets.
137      */
138     private final MoneyWiseXAnalysisLoanBucketList theLoans;
139 
140     /**
141      * The payee buckets.
142      */
143     private final MoneyWiseXAnalysisPayeeBucketList thePayees;
144 
145     /**
146      * The portfolio buckets.
147      */
148     private final MoneyWiseXAnalysisPortfolioBucketList thePortfolios;
149 
150     /**
151      * The deposit category buckets.
152      */
153     private final MoneyWiseXAnalysisDepositCategoryBucketList theDepositCategories;
154 
155     /**
156      * The cash category buckets.
157      */
158     private final MoneyWiseXAnalysisCashCategoryBucketList theCashCategories;
159 
160     /**
161      * The loan category buckets.
162      */
163     private final MoneyWiseXAnalysisLoanCategoryBucketList theLoanCategories;
164 
165     /**
166      * The transaction category buckets.
167      */
168     private final MoneyWiseXAnalysisTransCategoryBucketList theTransCategories;
169 
170     /**
171      * The TransactionTag buckets.
172      */
173     private final MoneyWiseXAnalysisTransTagBucketList theTransTags;
174 
175     /**
176      * The tax basis buckets.
177      */
178     private final MoneyWiseXAnalysisTaxBasisBucketList theTaxBasis;
179 
180     /**
181      * The new tax calculations.
182      */
183     private final MoneyWiseTaxAnalysis theTaxAnalysis;
184 
185     /**
186      * The Events.
187      */
188     private MoneyWiseXAnalysisEventList theEvents;
189 
190     /**
191      * Do we have active securities?
192      */
193     private Boolean haveActiveSecurities = Boolean.FALSE;
194 
195     /**
196      * Do we have a foreign account?
197      */
198     private Boolean haveForeignCurrency = Boolean.FALSE;
199 
200     /**
201      * Constructor for a full analysis.
202      *
203      * @param pEditSet       the editSet to analyse events for
204      * @param pCursor        the cursor
205      * @param pPreferenceMgr the preference manager
206      */
207     public MoneyWiseXAnalysis(final PrometheusEditSet pEditSet,
208                               final MoneyWiseXAnalysisCursor pCursor,
209                               final MetisPreferenceManager pPreferenceMgr) {
210         /* Store the data */
211         theEditSet = pEditSet;
212         theCursor = pCursor;
213         final MoneyWiseDataSet myDataSet = getData();
214         theCurrency = myDataSet.getReportingCurrency();
215         thePreferences = pPreferenceMgr;
216         theDateRange = myDataSet.getDateRange();
217 
218         /* Access the TaxYearCache */
219         theTaxYearCache = (MoneyWiseUKTaxYearCache) myDataSet.getTaxFactory();
220 
221         /* Create a new set of buckets */
222         theDeposits = new MoneyWiseXAnalysisDepositBucketList(this);
223         theCash = new MoneyWiseXAnalysisCashBucketList(this);
224         theLoans = new MoneyWiseXAnalysisLoanBucketList(this);
225         thePortfolios = new MoneyWiseXAnalysisPortfolioBucketList(this);
226         thePayees = new MoneyWiseXAnalysisPayeeBucketList(this);
227         theTaxBasis = new MoneyWiseXAnalysisTaxBasisBucketList(this);
228         theTransCategories = new MoneyWiseXAnalysisTransCategoryBucketList(this);
229         theTransTags = new MoneyWiseXAnalysisTransTagBucketList(this);
230 
231         /* Create totalling buckets */
232         theDepositCategories = new MoneyWiseXAnalysisDepositCategoryBucketList(this);
233         theCashCategories = new MoneyWiseXAnalysisCashCategoryBucketList(this);
234         theLoanCategories = new MoneyWiseXAnalysisLoanCategoryBucketList(this);
235         theTaxAnalysis = null;
236     }
237 
238     /**
239      * Constructor for a dated analysis.
240      *
241      * @param pBase the base analysis
242      * @param pDate the date for the analysis
243      */
244     public MoneyWiseXAnalysis(final MoneyWiseXAnalysis pBase,
245                               final OceanusDate pDate) {
246         /* Store the data */
247         theEditSet = pBase.getEditSet();
248         final MoneyWiseDataSet myDataSet = getData();
249         theCurrency = pBase.getCurrency();
250         thePreferences = pBase.getPreferenceMgr();
251         theDateRange = new OceanusDateRange(myDataSet.getDateRange().getStart(), pDate);
252         theEvents = pBase.getEvents();
253         theCursor = null;
254 
255         /* Access the TaxYearCache */
256         theTaxYearCache = (MoneyWiseUKTaxYearCache) myDataSet.getTaxFactory();
257 
258         /* Create a new set of buckets */
259         theDeposits = new MoneyWiseXAnalysisDepositBucketList(this, pBase.getDeposits(), pDate);
260         theCash = new MoneyWiseXAnalysisCashBucketList(this, pBase.getCash(), pDate);
261         theLoans = new MoneyWiseXAnalysisLoanBucketList(this, pBase.getLoans(), pDate);
262         thePortfolios = new MoneyWiseXAnalysisPortfolioBucketList(this, pBase.getPortfolios(), pDate);
263         thePayees = new MoneyWiseXAnalysisPayeeBucketList(this, pBase.getPayees(), pDate);
264         theTaxBasis = new MoneyWiseXAnalysisTaxBasisBucketList(this, pBase.getTaxBasis(), pDate);
265         theTransCategories = new MoneyWiseXAnalysisTransCategoryBucketList(this, pBase.getTransCategories(), pDate);
266         theTransTags = new MoneyWiseXAnalysisTransTagBucketList(this, pBase.getTransactionTags(), pDate);
267 
268         /* Create totalling buckets */
269         theDepositCategories = new MoneyWiseXAnalysisDepositCategoryBucketList(this);
270         theCashCategories = new MoneyWiseXAnalysisCashCategoryBucketList(this);
271         theLoanCategories = new MoneyWiseXAnalysisLoanCategoryBucketList(this);
272         theTaxAnalysis = null;
273     }
274 
275     /**
276      * Constructor for a ranged analysis.
277      *
278      * @param pBase  the base analysis
279      * @param pRange the range for the analysis
280      */
281     public MoneyWiseXAnalysis(final MoneyWiseXAnalysis pBase,
282                               final OceanusDateRange pRange) {
283         /* Store the data */
284         theEditSet = pBase.getEditSet();
285         final MoneyWiseDataSet myDataSet = getData();
286         theCurrency = pBase.getCurrency();
287         thePreferences = pBase.getPreferenceMgr();
288         theDateRange = pRange;
289         theEvents = pBase.getEvents();
290         theCursor = null;
291 
292         /* Access the TaxYearCache */
293         theTaxYearCache = (MoneyWiseUKTaxYearCache) myDataSet.getTaxFactory();
294 
295         /* Create a new set of buckets */
296         theDeposits = new MoneyWiseXAnalysisDepositBucketList(this, pBase.getDeposits(), pRange);
297         theCash = new MoneyWiseXAnalysisCashBucketList(this, pBase.getCash(), pRange);
298         theLoans = new MoneyWiseXAnalysisLoanBucketList(this, pBase.getLoans(), pRange);
299         thePortfolios = new MoneyWiseXAnalysisPortfolioBucketList(this, pBase.getPortfolios(), pRange);
300         thePayees = new MoneyWiseXAnalysisPayeeBucketList(this, pBase.getPayees(), pRange);
301         theTaxBasis = new MoneyWiseXAnalysisTaxBasisBucketList(this, pBase.getTaxBasis(), pRange);
302         theTransCategories = new MoneyWiseXAnalysisTransCategoryBucketList(this, pBase.getTransCategories(), pRange);
303         theTransTags = new MoneyWiseXAnalysisTransTagBucketList(this, pBase.getTransactionTags(), pRange);
304 
305         /* Create totalling buckets */
306         theDepositCategories = new MoneyWiseXAnalysisDepositCategoryBucketList(this);
307         theCashCategories = new MoneyWiseXAnalysisCashCategoryBucketList(this);
308         theLoanCategories = new MoneyWiseXAnalysisLoanCategoryBucketList(this);
309 
310         /* Handle new tax calculations */
311         final MoneyWiseTaxYear myYear = (MoneyWiseTaxYear) theTaxYearCache.findTaxYearForRange(theDateRange);
312         theTaxAnalysis = myYear != null
313                 ? myYear.analyseTaxYear(thePreferences, theTaxBasis)
314                 : null;
315     }
316 
317     /**
318      * Is the analysis manager idle?
319      *
320      * @return true/false
321      */
322     public boolean isIdle() {
323         return theCurrency == null;
324     }
325 
326     @Override
327     public MetisFieldSet<MoneyWiseXAnalysis> getDataFieldSet() {
328         return FIELD_DEFS;
329     }
330 
331     @Override
332     public String formatObject(final OceanusDataFormatter pFormatter) {
333         return FIELD_DEFS.getName();
334     }
335 
336     /**
337      * Do we have a foreign currency?
338      *
339      * @return true/false
340      */
341     public Boolean haveForeignCurrency() {
342         return haveForeignCurrency;
343     }
344 
345     /**
346      * Do we have active securities?
347      *
348      * @return true/false
349      */
350     public Boolean haveActiveSecurities() {
351         return haveActiveSecurities;
352     }
353 
354     /**
355      * Obtain the editSet.
356      *
357      * @return the editSet
358      */
359     public PrometheusEditSet getEditSet() {
360         return theEditSet;
361     }
362 
363     /**
364      * Obtain the events.
365      *
366      * @return the events
367      */
368     public MoneyWiseXAnalysisEventList getEvents() {
369         return theEvents;
370     }
371 
372     /**
373      * Set the events.
374      *
375      * @param pEvents the events
376      */
377     public void setEvents(final MoneyWiseXAnalysisEventList pEvents) {
378         theEvents = pEvents;
379     }
380 
381     /**
382      * Obtain the cursor.
383      *
384      * @return the cursor
385      */
386     public MoneyWiseXAnalysisCursor getCursor() {
387         return theCursor;
388     }
389 
390     /**
391      * Obtain the data.
392      *
393      * @return the data
394      */
395     public MoneyWiseDataSet getData() {
396         return (MoneyWiseDataSet) theEditSet.getDataSet();
397     }
398 
399     /**
400      * Obtain the currency.
401      *
402      * @return the currency
403      */
404     private MoneyWiseTaxYearCache getTaxYearCache() {
405         return theTaxYearCache;
406     }
407 
408     /**
409      * Obtain the currency.
410      *
411      * @return the currency
412      */
413     public MoneyWiseCurrency getCurrency() {
414         return theCurrency;
415     }
416 
417     /**
418      * Obtain the preference manager.
419      *
420      * @return the data
421      */
422     public MetisPreferenceManager getPreferenceMgr() {
423         return thePreferences;
424     }
425 
426     /**
427      * Obtain the date range.
428      *
429      * @return the date range
430      */
431     public OceanusDateRange getDateRange() {
432         return theDateRange;
433     }
434 
435     /**
436      * Is this a ranged analysis?
437      *
438      * @return true/false
439      */
440     public boolean isRangedAnalysis() {
441         return theDateRange.getStart() == null;
442     }
443 
444     /**
445      * Obtain the deposit buckets list.
446      *
447      * @return the list
448      */
449     public MoneyWiseXAnalysisDepositBucketList getDeposits() {
450         return theDeposits;
451     }
452 
453     /**
454      * Obtain the cash buckets list.
455      *
456      * @return the list
457      */
458     public MoneyWiseXAnalysisCashBucketList getCash() {
459         return theCash;
460     }
461 
462     /**
463      * Obtain the loan buckets list.
464      *
465      * @return the list
466      */
467     public MoneyWiseXAnalysisLoanBucketList getLoans() {
468         return theLoans;
469     }
470 
471     /**
472      * Obtain the portfolio buckets list.
473      *
474      * @return the list
475      */
476     public MoneyWiseXAnalysisPortfolioBucketList getPortfolios() {
477         return thePortfolios;
478     }
479 
480     /**
481      * Obtain the payee buckets list.
482      *
483      * @return the list
484      */
485     public MoneyWiseXAnalysisPayeeBucketList getPayees() {
486         return thePayees;
487     }
488 
489     /**
490      * Obtain the deposit categories list.
491      *
492      * @return the list
493      */
494     public MoneyWiseXAnalysisDepositCategoryBucketList getDepositCategories() {
495         return theDepositCategories;
496     }
497 
498     /**
499      * Obtain the cash categories list.
500      *
501      * @return the list
502      */
503     public MoneyWiseXAnalysisCashCategoryBucketList getCashCategories() {
504         return theCashCategories;
505     }
506 
507     /**
508      * Obtain the loan categories list.
509      *
510      * @return the list
511      */
512     public MoneyWiseXAnalysisLoanCategoryBucketList getLoanCategories() {
513         return theLoanCategories;
514     }
515 
516     /**
517      * Obtain the transaction categories list.
518      *
519      * @return the list
520      */
521     public MoneyWiseXAnalysisTransCategoryBucketList getTransCategories() {
522         return theTransCategories;
523     }
524 
525     /**
526      * Obtain the transactionTag list.
527      *
528      * @return the list
529      */
530     public MoneyWiseXAnalysisTransTagBucketList getTransactionTags() {
531         return theTransTags;
532     }
533 
534     /**
535      * Obtain the tax basis list.
536      *
537      * @return the list
538      */
539     public MoneyWiseXAnalysisTaxBasisBucketList getTaxBasis() {
540         return theTaxBasis;
541     }
542 
543     /**
544      * Obtain the tax analysis.
545      *
546      * @return the analysis
547      */
548     public MoneyWiseTaxAnalysis getTaxAnalysis() {
549         return theTaxAnalysis;
550     }
551 
552     /**
553      * Produce Totals.
554      */
555     public void produceTotals() {
556         /* Analyse the deposits */
557         theDepositCategories.analyseDeposits(theDeposits);
558         theDepositCategories.produceTotals();
559         haveForeignCurrency = theDepositCategories.haveForeignCurrency();
560 
561         /* Analyse the cash */
562         theCashCategories.analyseCash(theCash);
563         theCashCategories.produceTotals();
564         haveForeignCurrency |= theCashCategories.haveForeignCurrency();
565 
566         /* Analyse the loans */
567         theLoanCategories.analyseLoans(theLoans);
568         theLoanCategories.produceTotals();
569         haveForeignCurrency |= theLoanCategories.haveForeignCurrency();
570 
571         /* Analyse the securities */
572         thePortfolios.analyseSecurities();
573         haveForeignCurrency |= thePortfolios.haveForeignCurrency();
574         haveActiveSecurities = thePortfolios.haveActiveSecurities();
575 
576         /* Analyse the Payees */
577         thePayees.produceTotals();
578 
579         /* Analyse the TransactionCategories */
580         theTransCategories.produceTotals();
581 
582         /* Analyse the TaxBasis */
583         theTaxBasis.produceTotals();
584 
585         /* Sort the transaction Tag list */
586         theTransTags.sortBuckets();
587     }
588 
589     /**
590      * Check totals.
591      */
592     public void checkTotals() {
593         /* Obtain Totals bucket */
594         final MoneyWiseXAnalysisDepositCategoryBucket myDepCat = theDepositCategories.getTotals();
595         final MoneyWiseXAnalysisCashCategoryBucket myCashCat = theCashCategories.getTotals();
596         final MoneyWiseXAnalysisLoanCategoryBucket myLoanCat = theLoanCategories.getTotals();
597         final MoneyWiseXAnalysisPortfolioBucket myPort = thePortfolios.getTotals();
598         final MoneyWiseXAnalysisPayeeBucket myPayee = thePayees.getTotals();
599         final MoneyWiseXAnalysisTransCategoryBucket myTrans = theTransCategories.getTotals();
600         final MoneyWiseXAnalysisTaxBasisBucket myTax = theTaxBasis.getTotals();
601 
602         /* Handle null data */
603         if (myDepCat == null) {
604             return;
605         }
606 
607         /* Access totals */
608         OceanusMoney myDepTotal = myDepCat.getValues().getMoneyValue(MoneyWiseXAnalysisAccountAttr.VALUEDELTA);
609         final OceanusMoney myCashTotal = myCashCat.getValues().getMoneyValue(MoneyWiseXAnalysisAccountAttr.VALUEDELTA);
610         final OceanusMoney myLoanTotal = myLoanCat.getValues().getMoneyValue(MoneyWiseXAnalysisAccountAttr.VALUEDELTA);
611         final OceanusMoney myPortTotal = myPort.getValues().getMoneyValue(MoneyWiseXAnalysisSecurityAttr.VALUEDELTA);
612         final OceanusMoney myPayTotal = myPayee.getValues().getMoneyValue(MoneyWiseXAnalysisPayeeAttr.PROFIT);
613         final OceanusMoney myEvtTotal = myTrans.getValues().getMoneyValue(MoneyWiseXAnalysisTransAttr.PROFIT);
614         final OceanusMoney myTaxTotal = myTax.getValues().getMoneyValue(MoneyWiseXAnalysisTaxBasisAttr.GROSS);
615 
616         /* Create a copy */
617         myDepTotal = new OceanusMoney(myDepTotal);
618 
619         /* Add sub-accounts */
620         myDepTotal.addAmount(myCashTotal);
621         myDepTotal.addAmount(myLoanTotal);
622         myDepTotal.addAmount(myPortTotal);
623 
624         /* Check identities */
625         if (!myDepTotal.equals(myPayTotal)) {
626             LOGGER.error("Payee total mismatch");
627         }
628         if (!myDepTotal.equals(myEvtTotal)) {
629             LOGGER.error("TransactionCategory total mismatch");
630         }
631         if (!myDepTotal.equals(myTaxTotal)) {
632             LOGGER.error("TaxBasis total mismatch");
633         }
634     }
635 }