BrightSide Workbench Full Report + Source Code
DocumentAmounts.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.Currency;
22 import org.turro.financials.entity.Document;
23 import org.turro.financials.entity.DocumentLine;
24 import org.turro.zkoss.locale.Currencies;
25 
30 public class DocumentAmounts {
31 
32  private final Document document;
33  private AmountTaxableSet taxables;
34  private AmountRetainedSet retentions;
35 
36  public DocumentAmounts(Document document) {
37  this.document = document;
38  createAmounts();
39  }
40 
42  return taxables;
43  }
44 
46  return retentions;
47  }
48 
49  public double getAmount() {
50  double amount = 0.0;
51  for(AmountTaxable at : taxables) {
52  amount += at.getAmount();
53  }
54  return amount;
55  }
56 
57  public double getDiscount() {
58  double amount = 0.0;
59  for(AmountTaxable at : taxables) {
60  amount += at.getDiscount();
61  }
62  return amount;
63  }
64 
65  public double getTotal() {
66  double amount = 0.0;
67  for(AmountTaxable at : taxables) {
68  if(at.isPerCent(0.0)) { //Contract operating modifier was set
69  amount += at.getTaxable();
70  } else {
71  amount += at.getTotal();
72  }
73  }
74  for(AmountRetained ar : retentions) {
75  amount -= ar.getRetained();
76  }
77  return amount;
78  }
79 
80  public boolean hasReq() {
81  return document.getContract() != null &&
83  }
84 
85  private void createAmounts() {
86  taxables = new AmountTaxableSet();
87  retentions = new AmountRetainedSet();
88  if(getCurrency() != null) {
89  int fractionDigits = getCurrency().getDefaultFractionDigits();
90  if(document.getContract() != null) {
91  int count = 0;
92  for(DocumentLine dl : document.getDocumentLines()) {
93  dl.setLineOrder(count++);
94  double tax = dl.getFullTax();
95  if(!document.getContract().getOperatingModifier().isSumTax(dl)) {
96  tax = 0.0; // Contract operating modifier was set
97  }
98  taxables.add(tax, dl.getTax(), dl.getEquivalenceSurcharge(),
99  dl.getTaxValue(), dl.getRealTaxValue(), dl.getEquivalenceSurchargeValue(),
100  dl.getSubtotal(), dl.getTaxable(), fractionDigits);
101  if(dl.getRetention() != 0.0) {
102  retentions.add(dl.getRetention(), dl.getTaxable(), fractionDigits);
103  }
104  }
105  taxables.clearEmpty();
106  retentions.clearEmpty();
107  }
108  }
109  }
110 
111  private Currency currency;
112 
113  public Currency getCurrency() {
114  if(currency == null && document.getContract() != null) {
115  currency = document.getContract().getCurrency();
116  }
117  return currency == null ? Currencies.getDefault() : currency;
118  }
119 
120 }
OperatingModifier getOperatingModifier()
Definition: Contract.java:228
Set< DocumentLine > getDocumentLines()
Definition: Document.java:180
boolean add(Double perCent, Double taxable, int fractionDigits)
boolean add(Double perCent, Double tax, Double req, Double taxValue, Double taxRealValue, Double reqValue, Double subtotal, Double taxable, int fractionDigits)