BrightSide Workbench Full Report + Source Code
RegisterEntry.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.financials.db.FinancialsPU;
22 import org.turro.jpa.Dao;
23 import org.turro.jpa.entity.IDaoEntity;
24 import org.turro.math.Round;
25 import org.turro.math.Zero;
26 
31 @Entity
32 public class RegisterEntry implements java.io.Serializable, IDaoEntity {
33 
34  @Id
35  @GeneratedValue(strategy=GenerationType.IDENTITY)
36  @Column(name="IDENTIFIER")
37  private long id;
38 
39  @ManyToOne
40  private Register register;
41 
42  private long entryOrder;
43 
44  @ManyToOne
45  private Account account;
46 
47  private String concept;
48  private String path;
49 
50  private double debit;
51  private double credit;
52 
53  private boolean approved;
54  private boolean conciliated;
55 
56  public Account getAccount() {
57  return account;
58  }
59 
60  public void setAccount(Account account) {
61  this.account = account;
62  }
63 
64  public boolean isApproved() {
65  return approved;
66  }
67 
68  public void setApproved(boolean approved) {
69  this.approved = approved;
70  }
71 
72  public String getConcept() {
73  return concept;
74  }
75 
76  public void setConcept(String concept) {
77  this.concept = concept;
78  }
79 
80  public boolean isConciliated() {
81  return conciliated;
82  }
83 
84  public void setConciliated(boolean conciliated) {
85  this.conciliated = conciliated;
86  }
87 
88  public double getCredit() {
89  return credit;
90  }
91 
92  public void setCredit(double credit) {
93  this.credit = credit;
94  }
95 
96  public double getDebit() {
97  return debit;
98  }
99 
100  public void setDebit(double debit) {
101  this.debit = debit;
102  }
103 
104  public long getEntryOrder() {
105  return entryOrder;
106  }
107 
108  public void setEntryOrder(long entryOrder) {
109  this.entryOrder = entryOrder;
110  }
111 
112  public long getId() {
113  return id;
114  }
115 
116  public void setId(long id) {
117  this.id = id;
118  }
119 
120  public String getPath() {
121  return path;
122  }
123 
124  public void setPath(String path) {
125  this.path = path;
126  }
127 
129  return register;
130  }
131 
132  public void setRegister(Register register) {
133  this.register = register;
134  }
135 
136  /* IDaoEntity */
137 
138  @Override
139  public boolean isEmpty() {
140  return account == null ||
141  (Zero.near(debit, 2) &&
142  Zero.near(credit, 2));
143  }
144 
145  @Override
146  public Object entityId() {
147  return id;
148  }
149 
150  @Override
151  public void prepareSave() {
152  IDaoEntity.super.prepareSave();
153  Dao dao = new FinancialsPU();
154  Account a = dao.find(Account.class, account.getId());
155  if(a == null || !(a.getDescription().equals(account.getDescription()))) {
156  dao.saveObject(account);
157  }
158  if(register.getDocument() != null && register.getDocument().conciliateRegister) {
159  setConciliated(true);
160  }
161  }
162 
163  /* Helpers */
164 
165  public String getAccountString() {
166  return account.getDescription() + " (" + concept + ")";
167  }
168 
169  public void clearLine() {
170  setAccount(null);
171  setConcept(null);
172  setDebit(0);
173  setCredit(0);
174  setApproved(false);
175  setConciliated(false);
176  }
177 
178  public void assignValuesFrom(RegisterEntry registerEntry) {
179  setRegister(registerEntry.getRegister());
180  setAccount(registerEntry.getAccount());
181  setConcept(registerEntry.getConcept());
182  setDebit(registerEntry.getDebit());
183  setCredit(registerEntry.getCredit());
184  setApproved(registerEntry.isApproved());
185  setConciliated(registerEntry.isConciliated());
186  }
187 
188  public void roundIt(int fractionDigits) {
189  debit = new Round(debit).decimals(fractionDigits).value();
190  credit = new Round(credit).decimals(fractionDigits).value();
191  }
192 }
void setConciliated(boolean conciliated)
void assignValuesFrom(RegisterEntry registerEntry)
Round decimals(int digits)
Definition: Round.java:32
static boolean near(double value, int digits)
Definition: Zero.java:30