BrightSide Workbench Full Report + Source Code
AmountTaxable.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.financials.model.document;
20 
21 import org.turro.math.Round;
22 
27 public class AmountTaxable implements Comparable<AmountTaxable> {
28 
29  private Double perCent, tax, req, taxValue, taxRealValue, reqValue, amount, taxable;
30  private int fractionDigits;
31 
32  public AmountTaxable(Double perCent, Double tax, Double req) {
33  this.perCent = perCent;
34  this.tax = tax;
35  this.req = req;
36  taxValue = 0.0;
37  taxRealValue = 0.0;
38  reqValue = 0.0;
39  amount = 0.0;
40  taxable = 0.0;
41  }
42 
43  public void add(Double taxValue, Double taxRealValue, Double reqValue, Double amount, Double taxable) {
44  this.taxValue += taxValue;
45  this.taxRealValue += taxRealValue;
46  this.reqValue += reqValue;
47  this.amount += amount;
48  this.taxable += taxable;
49  }
50 
51  public boolean isPerCent(Double perCent) {
52  return this.perCent.equals(perCent);
53  }
54 
55  public void setFractionDigits(int fractionDigits) {
56  this.fractionDigits = fractionDigits;
57  }
58 
59  public Double getTax() {
60  return tax;
61  }
62 
63  public Double getReq() {
64  return req;
65  }
66 
67  public Double getDiscount() {
68  return new Round(amount - taxable).decimals(fractionDigits).value();
69  }
70 
71  public Double getAmount() {
72  return amount;
73  }
74 
75  public Double getTaxable() {
76  return taxable;
77  }
78 
79  public Double getTaxAmount() {
80 // if(tax != 0) {
81 // if(req != 0) {
82 // return new Round(getFullTaxAmount() * tax / perCent).decimals(fractionDigits).value();
83 // } else {
84 // return getFullTaxAmount();
85 // }
86 // }
87 // return 0.0;
88  return taxValue;
89  }
90 
91  public Double getTaxRealAmount() {
92  return taxRealValue;
93  }
94 
95  public Double getReqAmount() {
96 // if(req > 0) {
97 // return getFullTaxAmount() - getTaxAmount();
98 // }
99 // return 0.0;
100  return reqValue;
101  }
102 
103  public Double getFullTaxAmount() {
104  return getTotal() - getTaxable();
105  }
106 
107  public Double getTotal() {
108  if(tax == 0.0) {
109  return taxable; // Contract operating modifier was set
110  }
111  return taxable + taxValue;
112  }
113 
114  public boolean isEmpty() {
115  return amount == null || amount == 0 || amount.isNaN();
116  }
117 
118  @Override
119  public int hashCode() {
120  int hash = 7;
121  hash = 23 * hash + (this.perCent != null ? this.perCent.hashCode() : 0);
122  return hash;
123  }
124 
125  @Override
126  public boolean equals(Object obj) {
127  if (obj == null) {
128  return false;
129  }
130  if (getClass() != obj.getClass()) {
131  return false;
132  }
133  final AmountTaxable other = (AmountTaxable) obj;
134  if (this.perCent != other.perCent && (this.perCent == null || !this.perCent.equals(other.perCent))) {
135  return false;
136  }
137  return true;
138  }
139 
140  @Override
141  public int compareTo(AmountTaxable o) {
142  return perCent.compareTo(o.perCent);
143  }
144 
145 }
void add(Double taxValue, Double taxRealValue, Double reqValue, Double amount, Double taxable)
AmountTaxable(Double perCent, Double tax, Double req)
Round decimals(int digits)
Definition: Round.java:32