BrightSide Workbench Full Report + Source Code
MultiRegisterEntry.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.model.register;
19 
20 import java.util.Date;
21 import org.turro.financials.entity.Account;
22 import org.turro.financials.entity.Register;
23 import org.turro.financials.entity.RegisterEntry;
24 import org.turro.financials.entity.RegisterView;
25 import org.turro.math.Zero;
26 import org.turro.util.CompareUtil;
27 
32 public class MultiRegisterEntry implements Comparable<MultiRegisterEntry> {
33 
34  private RegisterEntry entry;
35 
36  private RegisterView view;
37  private Date date;
38  private double balance, accountBalance;
39  private boolean newRegister;
40  private int order;
41 
42  public MultiRegisterEntry(Register register) {
43  this((RegisterEntry) null);
44  if(register != null) {
45  entry.setRegister(register);
46  register.getRegisterEntries().add(entry);
47  date = register.getRegisterDate();
48  view = register.getView();
49  }
50  }
51 
53  this.entry = entry;
54  if(this.entry == null) {
55  this.entry = new RegisterEntry();
56  }
57  if(this.entry.getRegister() != null) {
58  date = this.entry.getRegister().getRegisterDate();
59  view = this.entry.getRegister().getView();
60  }
61  }
62 
63  public Account getAccount() {
64  return entry.getAccount();
65  }
66 
67  public void setAccount(Account account) {
68  this.entry.setAccount(account);
69  }
70 
71  public double getAccountBalance() {
72  return accountBalance;
73  }
74 
75  public void setAccountBalance(double accountBalance) {
76  this.accountBalance = accountBalance;
77  }
78 
79  public double getBalance() {
80  return balance;
81  }
82 
83  public void setBalance(double balance) {
84  this.balance = balance;
85  }
86 
87  public String getConcept() {
88  return entry.getConcept();
89  }
90 
91  public void setConcept(String concept) {
92  this.entry.setConcept(concept);
93  }
94 
95  public double getCredit() {
96  return entry.getCredit();
97  }
98 
99  public void setCredit(double credit) {
100  this.entry.setCredit(credit);
101  }
102 
103  public Date getDate() {
104  return date;
105  }
106 
107  public void setDate(Date date) {
108  this.date = date;
109  }
110 
111  public double getDebit() {
112  return entry.getDebit();
113  }
114 
115  public void setDebit(double debit) {
116  this.entry.setDebit(debit);
117  }
118 
120  return entry;
121  }
122 
123  public void setEntry(RegisterEntry entry) {
124  this.entry = entry;
125  }
126 
127  public boolean isNewRegister() {
128  return newRegister;
129  }
130 
131  public void setNewRegister(boolean newRegister) {
132  this.newRegister = newRegister;
133  }
134 
135  public int getOrder() {
136  return order;
137  }
138 
139  public void setOrder(int order) {
140  this.order = order;
141  }
142 
144  return view;
145  }
146 
147  public void setView(RegisterView view) {
148  this.view = view;
149  }
150 
151  public boolean isValid() {
152  return view != null &&
153  date != null &&
154  entry != null &&
155  !entry.isEmpty();
156  }
157 
158  public void deleteEntry() {
159  Register register = entry.getRegister();
160  if(register != null) {
161  register.getRegisterEntries().remove(entry);
162  entry.setRegister(null);
163  }
164  }
165 
166  public void checkValues(int cellIndex) {
167  if(cellIndex == 5 && !Zero.near(getDebit(), 2)) {
168  setCredit(0);
169  } else if(cellIndex == 6 && !Zero.near(getCredit(), 2)) {
170  setDebit(0);
171  }
172  }
173 
174  public boolean isSameRegister(MultiRegisterEntry newEntry) {
175  return !newRegister &&
176  newEntry.getDate().equals(date) &&
177  newEntry.getView().getId() == view.getId();
178  }
179 
180  @Override
182  int result = CompareUtil.compare(order, o.order);
183  if(result == 0) {
184  result = CompareUtil.compare(entry.getEntryOrder(), o.entry.getEntryOrder());
185  }
186  if(result == 0) {
187  result = CompareUtil.compare(date, o.date);
188  }
189  if(result == 0) {
190  result = CompareUtil.compare(view.getId(), o.view.getId());
191  }
192  if(result == 0 && getAccount() != null && o.getAccount() != null) {
193  result = CompareUtil.compare(getAccount().getId(), o.getAccount().getId());
194  }
195  if(result == 0) {
196  result = CompareUtil.compare(getConcept(), o.getConcept());
197  }
198  if(result == 0) {
199  result = CompareUtil.compare(getDebit(), o.getDebit());
200  }
201  if(result == 0) {
202  result = CompareUtil.compare(getCredit(), o.getCredit());
203  }
204  if(result == 0) {
205  result = CompareUtil.compare(entry.getId(), o.entry.getId());
206  }
207  return result;
208  }
209 
210 }
Set< RegisterEntry > getRegisterEntries()
Definition: Register.java:135
static boolean near(double value, int digits)
Definition: Zero.java:30