BrightSide Workbench Full Report + Source Code
StatementEntry.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.account.logic;
19 
20 import java.util.Date;
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.entity.Document;
23 import org.turro.financials.entity.MajorAccount;
24 import org.turro.financials.entity.Register;
25 import org.turro.financials.entity.RegisterEntry;
26 import org.turro.financials.entity.RegisterView;
27 import org.turro.util.CompareUtil;
28 import org.turro.util.PhraseBuilder;
29 
34 public class StatementEntry implements Comparable<StatementEntry> {
35 
36  protected double balance, inheritedBalance;
37  protected RegisterEntry entry;
38 
40  this.entry = entry;
41  }
42 
43  public String getId() {
44  if(entry != null) {
45  return "99" + entry.getId();
46  }
47  return null;
48  }
49 
50  public double getBalance() {
51  return inheritedBalance + getDebit() - getCredit();
52  }
53 
54  public double getCredit() {
55  if(entry != null) {
56  return entry.getCredit();
57  }
58  return 0.0;
59  }
60 
61  public double getDebit() {
62  if(entry != null) {
63  return entry.getDebit();
64  }
65  return 0.0;
66  }
67 
68  public Date getDate() {
69  if(entry != null) {
71  }
72  return null;
73  }
74 
75  public long getOrder() {
76  return 0;
77  }
78 
79  public String getAccount() {
80  if(entry != null) {
81  return entry.getAccount().getId();
82  }
83  return null;
84  }
85 
86  public String getDescription() {
87  if(entry != null && entry.getAccount() != null) {
89  return entry.getAccount().getDescription() + " " +
90  getConcept() +
91  (ma != null ? " - " + ma.getDescription() : "");
92  }
93  return null;
94  }
95 
96  // TODO: Canviar per DocumentString
97  public String getConcept() {
98  if(entry != null) {
99  PhraseBuilder sb = new PhraseBuilder(entry.getConcept());
100  Document document = entry.getRegister().getDocument();
101  if(document != null) {
102  sb.addWord("(");
103  sb.addWord(document.getDocumentDefinition().getName());
104  sb.addWord(document.getDocumentNumber());
105  sb.addWord(")", false);
106  }
107  return sb.toString();
108  }
109  return null;
110  }
111 
113  if(entry != null) {
114  return entry.getRegister().getView();
115  }
116  return null;
117  }
118 
120  return entry;
121  }
122 
124  if(entry != null) {
125  return entry.getRegister();
126  }
127  return null;
128  }
129 
131  if(getRegister() != null) {
132  return getRegister().getDocument();
133  }
134  return null;
135  }
136 
137  public void setInheritedBalance(double inheritedBalance) {
138  this.inheritedBalance = inheritedBalance;
139  }
140 
141  public boolean isConciliated() {
142  if(entry != null) {
143  return entry.isConciliated();
144  }
145  return false;
146  }
147 
148  public void setConciliated(boolean value) {
149  if(entry != null) {
150  entry.setConciliated(value);
151  new FinancialsPU().saveObject(entry);
152  }
153  }
154 
155  public boolean isBank() {
156  return false;
157  }
158 
159  @Override
160  public int compareTo(StatementEntry o) {
161  if(this instanceof StatementFirst) {
162  return -1;
163  } else if(o instanceof StatementFirst) {
164  return 1;
165  }
166  int r = getDate().compareTo(o.getDate());
167  if(r == 0) {
168  r = CompareUtil.compare(getOrder(), o.getOrder());
169  }
170  if(r == 0) {
171  r = getAccount().compareTo(o.getAccount());
172  }
173  if(entry != null) {
174  if(r == 0) {
175  r = Long.valueOf(entry.getRegister().getIdRegister()).compareTo(
177  }
178  }
179  if(r == 0) {
180  r = getId().compareTo(o.getId());
181  }
182  return r;
183  }
184 
185 }
DocumentDefinition getDocumentDefinition()
Definition: Document.java:167
void setConciliated(boolean conciliated)