BrightSide Workbench Full Report + Source Code
DocumentLine.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.entity;
19 
20 import javax.persistence.*;
21 import org.turro.string.Strings;
22 import org.turro.math.Round;
23 
28 @Entity
29 public class DocumentLine implements java.io.Serializable {
30 
31  @Id
32  @GeneratedValue(strategy=GenerationType.IDENTITY)
33  @Column(name="IDENTIFIER")
34  private long id;
35 
36  @ManyToOne
37  private Document document;
38 
39  @ManyToOne
40  private Contract store;
41 
42  private int lineOrder;
43 
44  @ManyToOne
45  private Product product;
46 
47  @ManyToOne
48  private ProductByContractor productByContractor;
49 
50  private String concept;
51 
52  private double quantity;
53  private double price;
54  private double tax;
55  private double equivalenceSurcharge;
56  private double discountPerCent;
57  private double discountMoney;
58  private double retention;
59 
60  @ManyToOne
61  private LineType lineType;
62 
63  @ManyToOne
64  private ContractPreference contractPreference;
65 
66  public String getConcept() {
67  return concept;
68  }
69 
70  public void setConcept(String concept) {
71  if(!Strings.isBlank(concept)) {
72  if(concept.length() > 255) {
73  concept = concept.substring(0, 255);
74  }
75  }
76  this.concept = concept;
77  }
78 
80  return contractPreference;
81  }
82 
83  public void setContractPreference(ContractPreference contractPreference) {
84  this.contractPreference = contractPreference;
85  }
86 
87  public double getDiscountMoney() {
88  return discountMoney;
89  }
90 
91  public void setDiscountMoney(double discountMoney) {
92  this.discountMoney = discountMoney;
93  }
94 
95  public double getDiscountPerCent() {
96  return discountPerCent;
97  }
98 
99  public void setDiscountPerCent(double discountPerCent) {
100  this.discountPerCent = discountPerCent;
101  }
102 
104  return document;
105  }
106 
107  public void setDocument(Document document) {
108  this.document = document;
109  }
110 
111  public long getId() {
112  return id;
113  }
114 
115  public void setId(long id) {
116  this.id = id;
117  }
118 
119  public int getLineOrder() {
120  return lineOrder;
121  }
122 
123  public void setLineOrder(int lineOrder) {
124  this.lineOrder = lineOrder;
125  }
126 
128  if(lineType != null) {
129  lineType.setContractPreference(contractPreference);
130  }
131  return lineType;
132  }
133 
134  public void setLineType(LineType lineType) {
135  this.lineType = lineType;
136  if(lineType != null && lineType.getContractPreference() != null) {
137  contractPreference = lineType.getContractPreference();
138  }
139  }
140 
141  public double getPrice() {
142  return price;
143  }
144 
145  public void setPrice(double price) {
146  this.price = price;
147  }
148 
149  public Product getProduct() {
150  return product;
151  }
152 
153  public void setProduct(Product product) {
154  this.product = product;
155  }
156 
158  return productByContractor;
159  }
160 
161  public void setProductByContractor(ProductByContractor productByContractor) {
162  this.productByContractor = productByContractor;
163  }
164 
165  public double getQuantity() {
166  return quantity;
167  }
168 
169  public void setQuantity(double quantity) {
170  this.quantity = quantity;
171  }
172 
173  public double getRetention() {
174  return retention;
175  }
176 
177  public void setRetention(double retention) {
178  this.retention = retention;
179  }
180 
181  public Contract getStore() {
182  return store;
183  }
184 
185  public void setStore(Contract store) {
186  this.store = store;
187  }
188 
189  public double getTax() {
190  return tax;
191  }
192 
193  public void setTax(double tax) {
194  this.tax = tax;
195  }
196 
197  public double getEquivalenceSurcharge() {
198  return equivalenceSurcharge;
199  }
200 
201  public void setEquivalenceSurcharge(double equivalenceSurcharge) {
202  this.equivalenceSurcharge = equivalenceSurcharge;
203  }
204 
205  /* Helpers */
206 
207  public boolean isEmpty() {
208  return (Strings.isBlank(concept) &&
209  getSubtotal() == 0) ||
210  store == null;
211  }
212 
213  public void clearLine() {
214  setProduct(null);
216  setConcept(null);
217  setQuantity(0);
218  setPrice(0);
219  setTax(0);
221  setDiscountMoney(0);
222  }
223 
224  public String getDescription() {
225  if(product != null) {
226  return product.getDescription();
227  }
228  if(productByContractor != null && productByContractor.getProduct() != null) {
229  return productByContractor.getProduct().getDescription();
230  }
231  return null;
232  }
233 
234  public double getSubtotal() {
235  int fractions = document.getCurrency() == null ? 2 : document.getCurrency().getDefaultFractionDigits();
236  return new Round(quantity == 0 ? price : price * quantity).decimals(fractions).value();
237  }
238 
239  public double getRetained() {
240  return new Round((getSubtotal() - getDiscount()) * (retention / 100.0)).decimals(document.getCurrency().getDefaultFractionDigits()).value();
241  }
242 
243  public double getDiscount() {
244  return new Round(((getSubtotal() - discountMoney) * (discountPerCent / 100.0)) + discountMoney).decimals(document.getCurrency().getDefaultFractionDigits()).value();
245  }
246 
247  public Double getTaxable() {
248  return new Round(getSubtotal() - getDiscount()).decimals(document.getCurrency().getDefaultFractionDigits()).value();
249  }
250 
251  public Double getFullTaxValue() {
252  return (getAmount() + getRetained()) - getTaxable();
253  }
254 
255  public Double getTaxValue() {
256  if(document.getContract().getOperatingModifier().isSumTax(this)) {
257  return getFullTaxValue();
258  } else {
259  Double taxable = getTaxable();
260  return new Round((taxable * (1.0 + getFullTax() / 100.0)) - getRetained())
261  .decimals(document.getCurrency().getDefaultFractionDigits())
262  .value() - taxable;
263  }
264  }
265 
266  public Double getRealTaxValue() {
267  if(tax != 0) {
268  if(equivalenceSurcharge != 0) {
269  return new Round(getFullTaxValue() * tax / getFullTax()).decimals(document.getCurrency().getDefaultFractionDigits()).value();
270  } else {
271  return getTaxValue();
272  }
273  }
274  return 0.0;
275  }
276 
278  if(equivalenceSurcharge > 0) {
279  return getFullTaxValue() - getRealTaxValue();
280  }
281  return 0.0;
282  }
283 
284  public Double getAmount() {
285  if(document.getContract().getOperatingModifier().isSumTax(this)) {
286  return new Round((getTaxable() * (1.0 + getFullTax() / 100.0)) - getRetained()).decimals(document.getCurrency().getDefaultFractionDigits()).value();
287  } else {
288  return getTaxable() - getRetained();
289  }
290  }
291 
292  public Double getToDeclare() {
293  if(document.getContract().getOperatingModifier().isSumTax(this)) {
294  return new Round((getTaxable() * (1.0 + getFullTax() / 100.0))).decimals(document.getCurrency().getDefaultFractionDigits()).value();
295  } else {
296  return getTaxable();
297  }
298  }
299 
300  public Double getFullTax() {
301  return tax + equivalenceSurcharge;
302  }
303 
304  public void assignValuesFrom(DocumentLine documentLine) {
305  setDocument(documentLine.getDocument());
306  setStore(documentLine.getStore());
307  setProduct(documentLine.getProduct());
309  setConcept(documentLine.getConcept());
310  setQuantity(documentLine.getQuantity());
311  setPrice(documentLine.getPrice());
312  setTax(documentLine.getTax());
314  setRetention(documentLine.getRetention());
315  setDiscountPerCent(documentLine.getDiscountPerCent());
316  setDiscountMoney(documentLine.getDiscountMoney());
317  setLineType(documentLine.getLineType());
319  }
320 
321 }
void setEquivalenceSurcharge(double equivalenceSurcharge)
void setContractPreference(ContractPreference contractPreference)
void setDiscountMoney(double discountMoney)
void setDiscountPerCent(double discountPerCent)
void assignValuesFrom(DocumentLine documentLine)
void setProductByContractor(ProductByContractor productByContractor)
ProductByContractor getProductByContractor()
ContractPreference getContractPreference()
Definition: LineType.java:77
void setContractPreference(ContractPreference contractPreference)
Definition: LineType.java:81
Round decimals(int digits)
Definition: Round.java:32