BrightSide Workbench Full Report + Source Code
CartAmounts.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 
25 public class CartAmounts {
26 
27  private final Cart cart;
28  private CartTaxableSet taxables;
29 
30  public CartAmounts(Cart cart) {
31  this.cart = cart;
32  createAmounts();
33  }
34 
36  return taxables;
37  }
38 
39  public double getAmount() {
40  double amount = 0.0;
41  for(CartTaxable at : taxables) {
42  amount += at.getAmount();
43  }
44  return amount;
45  }
46 
47  public double getDiscount() {
48  double amount = 0.0;
49  for(CartTaxable at : taxables) {
50  amount += at.getDiscount();
51  }
52  return amount;
53  }
54 
55  public double getTotal() {
56  double amount = 0.0;
57  for(CartTaxable at : taxables) {
58  if(at.isPerCent(0.0)) {
59  amount += at.getTaxable();
60  } else {
61  amount += at.getTotal();
62  }
63  }
64  return amount;
65  }
66 
67  private void createAmounts() {
68  taxables = new CartTaxableSet();
69  for(CartItem dl : cart.getItems()) {
70  double tax = dl.getTax();
71  taxables.add(tax, dl.getTax(), dl.getTaxAmount(), dl.getAmount(), dl.getTaxable());
72  }
73  taxables.clearEmpty();
74  }
75 
76 }
boolean add(Double perCent, Double tax, Double taxValue, Double subtotal, Double taxable)
CartItemSet getItems()
Definition: Cart.java:54