BrightSide Workbench Full Report + Source Code
AmountTaxableSet.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 java.util.Iterator;
22 import java.util.TreeSet;
23 
28 public class AmountTaxableSet extends TreeSet<AmountTaxable> {
29 
30  public boolean add(Double perCent, Double tax, Double req, Double taxValue, Double taxRealValue, Double reqValue,
31  Double subtotal, Double taxable, int fractionDigits) {
32  AmountTaxable at = getPercent(perCent, tax, req);
33  at.setFractionDigits(fractionDigits);
34  at.add(taxValue, taxRealValue, reqValue, subtotal, taxable);
35  return super.add(at);
36  }
37 
38  public AmountTaxable getPercent(Double perCent, Double tax, Double req) {
39  for(AmountTaxable at : this) {
40  if(at.isPerCent(perCent)) {
41  return at;
42  }
43  }
44  return new AmountTaxable(perCent, tax, req);
45  }
46 
47  public double getTaxable() {
48  double amount = 0;
49  for(AmountTaxable a : this) {
50  amount += a.getTaxable();
51  }
52  return amount;
53  }
54 
55  public double getTaxAmount() {
56  double amount = 0;
57  for(AmountTaxable a : this) {
58  amount += a.getTaxAmount();
59  }
60  return amount;
61  }
62 
63  public double getTaxRealAmount() {
64  double amount = 0;
65  for(AmountTaxable a : this) {
66  amount += a.getTaxRealAmount();
67  }
68  return amount;
69  }
70 
71  public double getTotal() {
72  double amount = 0;
73  for(AmountTaxable a : this) {
74  amount += a.getTotal();
75  }
76  return amount;
77  }
78 
79  public void clearEmpty() {
80  Iterator<AmountTaxable> it = iterator();
81  while(it.hasNext()) {
82  if(it.next().isEmpty()) {
83  it.remove();
84  }
85  }
86  }
87 
88 }
AmountTaxable getPercent(Double perCent, Double tax, Double req)
boolean add(Double perCent, Double tax, Double req, Double taxValue, Double taxRealValue, Double reqValue, Double subtotal, Double taxable, int fractionDigits)
void add(Double taxValue, Double taxRealValue, Double reqValue, Double amount, Double taxable)