BrightSide Workbench Full Report + Source Code
Amount.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 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 package org.turro.financials.model;
19 
20 import org.turro.math.Round;
21 
26 public class Amount implements Comparable<Amount> {
27 
28  private Double tax, subtotal, discount, retained;
29  private int fractionDigits;
30  private AmountSet amountSet;
31 
32  public Amount(Double tax, Double subtotal, Double discount, Double retained, int fractionDigits) {
33  this.tax = tax;
34  this.subtotal = subtotal;
35  this.discount = discount;
36  this.retained = retained;
37  this.fractionDigits = fractionDigits;
38  }
39 
40  public void setAmountSet(AmountSet amountSet) {
41  this.amountSet = amountSet;
42  }
43 
44  public boolean isEmpty() {
45  return subtotal == null || subtotal == 0 || subtotal.isNaN();
46  }
47 
48  public void addTax(Double tax, Double subtotal, Double discount, Double retained) {
49  this.tax = tax;
50  this.subtotal += subtotal;
51  this.discount += discount;
52  this.retained += retained;
53  }
54 
55  public Double getTax() {
56  return tax;
57  }
58 
59  public Double getRetained() {
60  return retained;
61  }
62 
63  public Double getDiscount() {
64  return discount;
65  }
66 
67  public Double getSubtotal() {
68  return subtotal;
69  }
70 
71  public Double getTaxable() {
72  return new Round(subtotal - discount).decimals(fractionDigits).value();
73  }
74 
75  public Double getTaxValue() {
76  return (getAmount() + retained) - getTaxable();
77  }
78 
79  public Double getAmount() {
80 // if(amountSet.getOperatingModifier().isSumTax()) {
81  return new Round((getTaxable() * (1.0 + tax / 100.0))).decimals(fractionDigits).value() - retained;
82 // } else {
83 // return new Round(getTaxable() - retained).decimals(fractionDigits).value();
84 // }
85  }
86 
87  @Override
88  public boolean equals(Object obj) {
89  if (obj == null) {
90  return false;
91  }
92  if (getClass() != obj.getClass()) {
93  return false;
94  }
95  final Amount other = (Amount) obj;
96  if (this.tax != other.tax && (this.tax == null || !this.tax.equals(other.tax))) {
97  return false;
98  }
99  return true;
100  }
101 
102  @Override
103  public int hashCode() {
104  int hash = 3;
105  hash = 97 * hash + (this.tax != null ? this.tax.hashCode() : 0);
106  return hash;
107  }
108 
109  @Override
110  public int compareTo(Amount o) {
111  return tax.compareTo(o.getTax());
112  }
113 
114 }
void setAmountSet(AmountSet amountSet)
Definition: Amount.java:40
boolean equals(Object obj)
Definition: Amount.java:88
Amount(Double tax, Double subtotal, Double discount, Double retained, int fractionDigits)
Definition: Amount.java:32
void addTax(Double tax, Double subtotal, Double discount, Double retained)
Definition: Amount.java:48
Round decimals(int digits)
Definition: Round.java:32