BrightSide Workbench Full Report + Source Code
CartTaxable.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2016 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.cart;
20 
21 import org.turro.math.Round;
22 
27 public class CartTaxable implements Comparable<CartTaxable> {
28 
29  private Double perCent, tax, taxValue, amount, taxable;
30 
31  public CartTaxable(Double perCent, Double tax) {
32  this.perCent = perCent;
33  this.tax = tax;
34  taxValue = 0.0;
35  amount = 0.0;
36  taxable = 0.0;
37  }
38 
39  public void add(Double taxValue, Double amount, Double taxable) {
40  this.taxValue += taxValue;
41  this.amount += amount;
42  this.taxable += taxable;
43  }
44 
45  public boolean isPerCent(Double perCent) {
46  return this.perCent.equals(perCent);
47  }
48 
49  public Double getTax() {
50  return tax;
51  }
52 
53  public Double getDiscount() {
54  return new Round(amount - taxable).decimals(2).value();
55  }
56 
57  public Double getAmount() {
58  return amount;
59  }
60 
61  public Double getTaxable() {
62  return taxable;
63  }
64 
65  public Double getTaxAmount() {
66  return taxValue;
67  }
68 
69  public Double getTotal() {
70  if(tax == 0.0) {
71  return taxable;
72  }
73  return taxable + taxValue;
74  }
75 
76  public boolean isEmpty() {
77  return amount == null || amount == 0 || amount.isNaN();
78  }
79 
80  @Override
81  public int hashCode() {
82  int hash = 7;
83  hash = 23 * hash + (this.perCent != null ? this.perCent.hashCode() : 0);
84  return hash;
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 CartTaxable other = (CartTaxable) obj;
96  if (this.perCent != other.perCent && (this.perCent == null || !this.perCent.equals(other.perCent))) {
97  return false;
98  }
99  return true;
100  }
101 
102  @Override
103  public int compareTo(CartTaxable o) {
104  return perCent.compareTo(o.perCent);
105  }
106 
107 }
CartTaxable(Double perCent, Double tax)
void add(Double taxValue, Double amount, Double taxable)
boolean isPerCent(Double perCent)
Round decimals(int digits)
Definition: Round.java:32