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.data.statics;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  import io.github.tonywasher.joceanus.moneywise.exc.MoneyWiseDataException;
21  
22  /**
23   * Enumeration of TransactionCategory Classes.
24   */
25  public enum MoneyWiseTransCategoryClass
26          implements MoneyWiseCategoryInterface {
27      /**
28       * Taxed Salary Income.
29       */
30      TAXEDINCOME(1, 4),
31  
32      /**
33       * Rental Income.
34       */
35      RENTALINCOME(2, 5),
36  
37      /**
38       * RoomRental Income.
39       */
40      ROOMRENTALINCOME(3, 6),
41  
42      /**
43       * Interest Income.
44       */
45      INTEREST(4, 7),
46  
47      /**
48       * Dividend Income.
49       */
50      DIVIDEND(5, 8),
51  
52      /**
53       * Virtual Income.
54       */
55      VIRTUALINCOME(6, 9),
56  
57      /**
58       * GrossIncome.
59       */
60      GROSSINCOME(7, 10),
61  
62      /**
63       * PensionContribution.
64       */
65      PENSIONCONTRIB(8, 11),
66  
67      /**
68       * Gifted Income.
69       */
70      GIFTEDINCOME(9, 12),
71  
72      /**
73       * Inheritance.
74       */
75      INHERITED(10, 13),
76  
77      /**
78       * Interest earned on Loans.
79       */
80      LOANINTERESTEARNED(11, 14),
81  
82      /**
83       * Loyalty Bonus.
84       */
85      LOYALTYBONUS(12, 15),
86  
87      /**
88       * CashBack.
89       */
90      CASHBACK(13, 16),
91  
92      /**
93       * Recovered Expenses.
94       */
95      RECOVEREDEXPENSES(14, 17),
96  
97      /**
98       * Other Income.
99       */
100     OTHERINCOME(15, 18),
101 
102     /**
103      * Stock Options Exercised.
104      */
105     OPTIONSEXERCISE(16, 19),
106 
107     /**
108      * Stock Units Adjustment.
109      */
110     UNITSADJUST(17, 20),
111 
112     /**
113      * Stock Split.
114      */
115     STOCKSPLIT(18, 21),
116 
117     /**
118      * Stock DeMerger.
119      */
120     STOCKDEMERGER(19, 22),
121 
122     /**
123      * Security Replacement.
124      */
125     SECURITYREPLACE(20, 23),
126 
127     /**
128      * Security Closure.
129      */
130     SECURITYCLOSURE(21, 24),
131 
132     /**
133      * Stock TakeOver.
134      */
135     STOCKTAKEOVER(22, 25),
136 
137     /**
138      * Stock Rights Issue.
139      */
140     STOCKRIGHTSISSUE(23, 26),
141 
142     /**
143      * PortfolioXfer.
144      */
145     PORTFOLIOXFER(24, 27),
146 
147     /**
148      * Stock Options Granted.
149      */
150     OPTIONSGRANT(25, 28),
151 
152     /**
153      * Stock Options Vested.
154      */
155     OPTIONSVEST(26, 29),
156 
157     /**
158      * Stock Options Expired.
159      */
160     OPTIONSEXPIRE(27, 30),
161 
162     /**
163      * Pension Drawdown.
164      */
165     PENSIONDRAWDOWN(28, 31),
166 
167     /**
168      * Pension TaxFree.
169      */
170     PENSIONTAXFREE(29, 32),
171 
172     /**
173      * Transfer.
174      */
175     TRANSFER(30, 33),
176 
177     /**
178      * Expense.
179      */
180     EXPENSE(31, 34),
181 
182     /**
183      * BadDebtCapital.
184      */
185     BADDEBTCAPITAL(32, 35),
186 
187     /**
188      * BadDebtInterest.
189      */
190     BADDEBTINTEREST(33, 36),
191 
192     /**
193      * LocalTaxes.
194      */
195     LOCALTAXES(34, 37),
196 
197     /**
198      * Write Off.
199      */
200     WRITEOFF(35, 38),
201 
202     /**
203      * Interest charged on Loans.
204      */
205     LOANINTERESTCHARGED(36, 39),
206 
207     /**
208      * Rental Expense.
209      */
210     RENTALEXPENSE(37, 40),
211 
212     /**
213      * AnnuityPurchase.
214      */
215     ANNUITYPURCHASE(38, 41),
216 
217     /**
218      * Tax Relief.
219      */
220     TAXRELIEF(39, 42),
221 
222     /**
223      * IncomeTax.
224      */
225     INCOMETAX(40, 43),
226 
227     /**
228      * Taxed Interest.
229      */
230     TAXEDINTEREST(41, 44),
231 
232     /**
233      * Gross Interest.
234      */
235     GROSSINTEREST(42, 45),
236 
237     /**
238      * Tax Free Interest.
239      */
240     TAXFREEINTEREST(43, 46),
241 
242     /**
243      * Peer2Peer Interest.
244      */
245     PEER2PEERINTEREST(44, 47),
246 
247     /**
248      * Share Dividend Income.
249      */
250     SHAREDIVIDEND(45, 48),
251 
252     /**
253      * Unit Trust Dividend Income.
254      */
255     UNITTRUSTDIVIDEND(46, 49),
256 
257     /**
258      * Foreign Dividend.
259      */
260     FOREIGNDIVIDEND(47, 50),
261 
262     /**
263      * Tax Free Dividend.
264      */
265     TAXFREEDIVIDEND(48, 51),
266 
267     /**
268      * Taxed Loyalty Bonus.
269      */
270     TAXEDLOYALTYBONUS(49, 52),
271 
272     /**
273      * Gross LoyaltyBonus.
274      */
275     GROSSLOYALTYBONUS(50, 53),
276 
277     /**
278      * Tax Free LoyaltyBonus.
279      */
280     TAXFREELOYALTYBONUS(51, 54),
281 
282     /**
283      * Chargeable Gain.
284      */
285     CHARGEABLEGAIN(52, 55),
286 
287     /**
288      * Residential Gain.
289      */
290     RESIDENTIALGAIN(53, 56),
291 
292     /**
293      * Capital Gain.
294      */
295     CAPITALGAIN(54, 57),
296 
297     /**
298      * TaxFreeCapital Gain.
299      */
300     TAXFREEGAIN(55, 58),
301 
302     /**
303      * Market Growth.
304      */
305     MARKETGROWTH(56, 59),
306 
307     /**
308      * CurrencyFluctuation.
309      */
310     CURRENCYFLUCTUATION(57, 60),
311 
312     /**
313      * Withheld.
314      * <p>
315      * This is a singular category catching withheld items such as charity donations associated with
316      * interest.
317      */
318     WITHHELD(58, 61),
319 
320     /**
321      * OpeningBalance.
322      * <p>
323      * This is a singular category catching opening balances.
324      */
325     OPENINGBALANCE(59, 62),
326 
327     /**
328      * EmployeeNatInsurance.
329      * <p>
330      * This is a singular category catching opening balances.
331      */
332     EMPLOYEENATINS(60, 63),
333 
334     /**
335      * EmployeeNatInsurance.
336      * <p>
337      * This is a singular category catching opening balances.
338      */
339     EMPLOYERNATINS(61, 64),
340 
341     /**
342      * Income Totals.
343      * <p>
344      * This is used for categories which simply own a set of income sub-categories and is used
345      * purely for reporting purposes.
346      */
347     INCOMETOTALS(62, 1),
348 
349     /**
350      * Expense Totals.
351      * <p>
352      * This is used for categories which simply own a set of expense sub-categories and is used
353      * purely for reporting purposes.
354      */
355     EXPENSETOTALS(63, 2),
356 
357     /**
358      * Security Parent.
359      * <p>
360      * This is used for categories which simply own a set of security transfer sub-categories and is
361      * used purely for holding purposes.
362      */
363     SECURITYPARENT(64, 3),
364 
365     /**
366      * Totals.
367      * <p>
368      * This is used for the total of all non-transfer categories and is used purely for reporting
369      * purposes.
370      */
371     TOTALS(65, 0);
372 
373     /**
374      * The String name.
375      */
376     private String theName;
377 
378     /**
379      * Class Id.
380      */
381     private final int theId;
382 
383     /**
384      * Class Order.
385      */
386     private final int theOrder;
387 
388     /**
389      * Constructor.
390      *
391      * @param uId    the id
392      * @param uOrder the default order.
393      */
394     MoneyWiseTransCategoryClass(final int uId,
395                                 final int uOrder) {
396         theId = uId;
397         theOrder = uOrder;
398     }
399 
400     @Override
401     public int getClassId() {
402         return theId;
403     }
404 
405     @Override
406     public int getOrder() {
407         return theOrder;
408     }
409 
410     @Override
411     public String toString() {
412         /* If we have not yet loaded the name */
413         if (theName == null) {
414             /* Load the name */
415             theName = MoneyWiseStaticResource.getKeyForTransType(this).getValue();
416         }
417 
418         /* return the name */
419         return theName;
420     }
421 
422     /**
423      * get value from id.
424      *
425      * @param id the id value
426      * @return the corresponding enum object
427      * @throws OceanusException on error
428      */
429     public static MoneyWiseTransCategoryClass fromId(final int id) throws OceanusException {
430         for (MoneyWiseTransCategoryClass myClass : values()) {
431             if (myClass.getClassId() == id) {
432                 return myClass;
433             }
434         }
435         throw new MoneyWiseDataException("Invalid ClassId for " + MoneyWiseStaticDataType.TRANSTYPE.toString() + ":" + id);
436     }
437 
438     /**
439      * Determine whether the CategoryType is hidden type.
440      *
441      * @return <code>true</code> if the category is hidden, <code>false</code> otherwise.
442      */
443     public boolean isHiddenType() {
444         switch (this) {
445             case SHAREDIVIDEND:
446             case UNITTRUSTDIVIDEND:
447             case FOREIGNDIVIDEND:
448             case TAXFREEDIVIDEND:
449             case TAXEDINTEREST:
450             case GROSSINTEREST:
451             case TAXFREEINTEREST:
452             case PEER2PEERINTEREST:
453             case TAXEDLOYALTYBONUS:
454             case GROSSLOYALTYBONUS:
455             case TAXFREELOYALTYBONUS:
456             case MARKETGROWTH:
457             case CURRENCYFLUCTUATION:
458             case WITHHELD:
459             case TAXRELIEF:
460             case CHARGEABLEGAIN:
461             case RESIDENTIALGAIN:
462             case CAPITALGAIN:
463             case TAXFREEGAIN:
464             case VIRTUALINCOME:
465             case EMPLOYEENATINS:
466             case EMPLOYERNATINS:
467             case OPENINGBALANCE:
468             case TOTALS:
469                 return true;
470             default:
471                 return false;
472         }
473     }
474 
475     /**
476      * Determine whether the Account is a secret payee.
477      *
478      * @return <code>true</code> if the category uses parent payee, <code>false</code> otherwise.
479      */
480     public boolean isSecretPayee() {
481         switch (this) {
482             case INTEREST:
483             case DIVIDEND:
484             case CASHBACK:
485             case LOYALTYBONUS:
486             case LOANINTERESTEARNED:
487             case RENTALINCOME:
488             case ROOMRENTALINCOME:
489             case WRITEOFF:
490             case LOANINTERESTCHARGED:
491             case OPTIONSEXERCISE:
492                 return true;
493             default:
494                 return false;
495         }
496     }
497 
498     /**
499      * Determine whether the Account is a secret payee.
500      *
501      * @return <code>true</code> if the category uses parent payee, <code>false</code> otherwise.
502      */
503     public boolean isSwitchDirection() {
504         switch (this) {
505             case INTEREST:
506             case DIVIDEND:
507             case CASHBACK:
508             case LOYALTYBONUS:
509             case RENTALINCOME:
510             case ROOMRENTALINCOME:
511             case WRITEOFF:
512             case LOANINTERESTCHARGED:
513             case TRANSFER:
514                 return true;
515             default:
516                 return false;
517         }
518     }
519 
520     /**
521      * Determine whether the category type is singular.
522      *
523      * @return <code>true</code> if the event category type is singular, <code>false</code>
524      * otherwise.
525      */
526     public boolean isSingular() {
527         return INCOMETAX.equals(this) || isHiddenType();
528     }
529 
530     /**
531      * Determine whether the CategoryType is an income.
532      *
533      * @return <code>true</code> if the category is income, <code>false</code> otherwise.
534      */
535     public boolean isIncome() {
536         switch (this) {
537             case TAXEDINCOME:
538             case VIRTUALINCOME:
539             case GROSSINCOME:
540             case PENSIONCONTRIB:
541             case LOYALTYBONUS:
542             case CASHBACK:
543             case OTHERINCOME:
544             case RECOVEREDEXPENSES:
545             case GIFTEDINCOME:
546             case INTEREST:
547             case TAXEDINTEREST:
548             case GROSSINTEREST:
549             case TAXFREEINTEREST:
550             case PEER2PEERINTEREST:
551             case DIVIDEND:
552             case SHAREDIVIDEND:
553             case UNITTRUSTDIVIDEND:
554             case FOREIGNDIVIDEND:
555             case TAXFREEDIVIDEND:
556             case TAXEDLOYALTYBONUS:
557             case GROSSLOYALTYBONUS:
558             case TAXFREELOYALTYBONUS:
559             case INHERITED:
560             case LOANINTERESTEARNED:
561             case RENTALINCOME:
562             case ROOMRENTALINCOME:
563             case OPTIONSEXERCISE:
564             case EMPLOYEENATINS:
565             case EMPLOYERNATINS:
566             case OPENINGBALANCE:
567             case INCOMETOTALS:
568                 return true;
569             default:
570                 return false;
571         }
572     }
573 
574     /**
575      * Determine whether the CategoryType is an expense.
576      *
577      * @return <code>true</code> if the category is expense, <code>false</code> otherwise.
578      */
579     public boolean isExpense() {
580         return !isIncome() && !isTransfer();
581     }
582 
583     /**
584      * Determine whether the CategoryType is dilutable.
585      *
586      * @return <code>true</code> if the category is dilutable, <code>false</code> otherwise.
587      */
588     public boolean isDilutable() {
589         switch (this) {
590             case STOCKSPLIT:
591             case STOCKDEMERGER:
592                 return true;
593             default:
594                 return false;
595         }
596     }
597 
598     /**
599      * Determine whether the CategoryType is dividend.
600      *
601      * @return <code>true</code> if the category is dividend, <code>false</code> otherwise.
602      */
603     public boolean isDividend() {
604         switch (this) {
605             case DIVIDEND:
606             case SHAREDIVIDEND:
607             case UNITTRUSTDIVIDEND:
608             case FOREIGNDIVIDEND:
609             case TAXFREEDIVIDEND:
610                 return true;
611             default:
612                 return false;
613         }
614     }
615 
616     /**
617      * Determine whether the CategoryType is interest.
618      *
619      * @return <code>true</code> if the category is interest, <code>false</code> otherwise.
620      */
621     public boolean isInterest() {
622         switch (this) {
623             case INTEREST:
624             case TAXEDINTEREST:
625             case GROSSINTEREST:
626             case TAXFREEINTEREST:
627             case PEER2PEERINTEREST:
628                 return true;
629             default:
630                 return false;
631         }
632     }
633 
634     /**
635      * Determine whether the CategoryType needs debit and credit both to have units.
636      *
637      * @return <code>true</code> if the category needs dual units, <code>false</code> otherwise.
638      */
639     public boolean isStockAdjustment() {
640         switch (this) {
641             case STOCKSPLIT:
642             case UNITSADJUST:
643             case STOCKDEMERGER:
644             case SECURITYREPLACE:
645             case STOCKTAKEOVER:
646             case PORTFOLIOXFER:
647             case OPTIONSGRANT:
648             case OPTIONSVEST:
649             case OPTIONSEXPIRE:
650                 return true;
651             default:
652                 return false;
653         }
654     }
655 
656     /**
657      * Determine whether the CategoryType has null Amount.
658      *
659      * @return <code>true</code> if the category needs null amount, <code>false</code> otherwise.
660      */
661     public boolean needsNullAmount() {
662         switch (this) {
663             case STOCKSPLIT:
664             case UNITSADJUST:
665             case STOCKDEMERGER:
666             case STOCKTAKEOVER:
667             case PORTFOLIOXFER:
668             case OPTIONSGRANT:
669             case OPTIONSVEST:
670             case OPTIONSEXPIRE:
671             case SECURITYREPLACE:
672                 return true;
673             default:
674                 return false;
675         }
676     }
677 
678     /**
679      * Determine whether the EventCategoryType can be parent categories.
680      *
681      * @return <code>true</code> if the event category type can parent categories,
682      * <code>false</code> otherwise.
683      */
684     public boolean canParentCategory() {
685         switch (this) {
686             case INCOMETOTALS:
687             case EXPENSETOTALS:
688             case SECURITYPARENT:
689             case TOTALS:
690                 return true;
691             default:
692                 return false;
693         }
694     }
695 
696     /**
697      * Determine whether the EventCategoryType is a subTotal.
698      *
699      * @return <code>true</code> if the event category type is a subTotal, <code>false</code>
700      * otherwise.
701      */
702     public boolean isSubTotal() {
703         switch (this) {
704             case INCOMETOTALS:
705             case EXPENSETOTALS:
706             case SECURITYPARENT:
707                 return true;
708             default:
709                 return false;
710         }
711     }
712 
713     /**
714      * Is this event category a transfer?
715      *
716      * @return true/false
717      */
718     public boolean isTransfer() {
719         return this == TRANSFER || isSecurityTransfer();
720     }
721 
722     /**
723      * Is this event category a NatInsurance event?
724      *
725      * @return true/false
726      */
727     public boolean isNatInsurance() {
728         switch (this) {
729             case TAXEDINCOME:
730             case PENSIONCONTRIB:
731                 return true;
732             default:
733                 return false;
734         }
735     }
736 
737     /**
738      * Is this event category a security transfer?
739      *
740      * @return true/false
741      */
742     public boolean isSecurityTransfer() {
743         switch (this) {
744             case UNITSADJUST:
745             case STOCKSPLIT:
746             case STOCKDEMERGER:
747             case SECURITYREPLACE:
748             case STOCKTAKEOVER:
749             case STOCKRIGHTSISSUE:
750             case PORTFOLIOXFER:
751             case OPTIONSGRANT:
752             case OPTIONSVEST:
753             case OPTIONSEXPIRE:
754             case SECURITYCLOSURE:
755             case SECURITYPARENT:
756             case PENSIONDRAWDOWN:
757             case PENSIONTAXFREE:
758                 return true;
759             default:
760                 return false;
761         }
762     }
763 
764     /**
765      * Is this event category a security closure?
766      *
767      * @return true/false
768      */
769     public boolean isSecurityClosure() {
770         return this == SECURITYCLOSURE;
771     }
772 
773     @Override
774     public boolean isTotals() {
775         return this == TOTALS;
776     }
777 }