BrightSide Workbench Full Report + Source Code
StatementFirst.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 javax.persistence.NoResultException;
22 import org.turro.financials.entity.RegisterView;
23 import org.turro.i18n.I_;
24 import org.turro.jpa.Dao;
25 
30 public class StatementFirst extends StatementEntry {
31 
32  protected double initialDebit, initialCredit;
33  private Date fromDate;
34  private String accountSearch;
35  private RegisterView view;
36 
37  public StatementFirst() {
38  super(null);
39  }
40 
41  public StatementFirst(double initialDebit, double initialCredit) {
42  super(null);
43  this.initialDebit = initialDebit;
44  this.initialCredit = initialCredit;
46  }
47 
48  @Override
49  public String getId() {
50  return "00";
51  }
52 
53  @Override
54  public String getAccount() {
55  return I_.get("Accumulated");
56  }
57 
58  @Override
59  public double getBalance() {
60  return getDebit() - getCredit();
61  }
62 
63  @Override
64  public double getCredit() {
65  return initialCredit;
66  }
67 
68  @Override
69  public double getDebit() {
70  return initialDebit;
71  }
72 
73  @Override
74  public Date getDate() {
75  return getFromDate();
76  }
77 
78  public String getAccountSearch() {
79  return accountSearch;
80  }
81 
82  public void setAccountSearch(String accountSearch) {
83  this.accountSearch = accountSearch;
84  }
85 
86  public Date getFromDate() {
87  return fromDate;
88  }
89 
90  public void setFromDate(Date fromDate) {
91  this.fromDate = fromDate;
92  }
93 
94  @Override
95  public String getDescription() {
96  return null;
97  }
98 
99  @Override
100  public String getConcept() {
101  return null;
102  }
103 
104  @Override
106  return view;
107  }
108 
109  public void setView(RegisterView view) {
110  this.view = view;
111  }
112 
113  public void refreshData(Dao dao) {
114  initialDebit = 0.0;
115  initialCredit = 0.0;
116  Date init = getInitialDate(dao, fromDate);
117  Object[] pars = view != null ?
118  new Object[] {
119  accountSearch.replaceAll("\\*", "%"),
120  fromDate,
121  init,
122  view
123  } :
124  new Object[] {
125  accountSearch.replaceAll("\\*", "%"),
126  fromDate,
127  init
128  };
129  Object[] o = (Object[]) dao.getSingleResult(
130  "select sum(entry.debit), sum(entry.credit) " +
131  "from RegisterEntry as entry " +
132  "where entry.account.id like ? " +
133  "and entry.register.registerDate < ? " +
134  (init != null ? "and entry.register.registerDate >= ? " : "and ? is null ") +
135  (view != null ? "and entry.register.view = ? " : ""),
136  pars);
137  if(o != null && o.length == 2) {
138  initialDebit = (Double) (o[0] == null ? 0.0 : o[0]);
139  initialCredit = (Double) (o[1] == null ? 0.0 : o[1]);
140  }
141  }
142 
143  public Date getInitialDate(Dao dao, Date fromDate) {
144  try {
145  return (Date) dao.getSingleResult(
146  "select max(r.registerDate) from Register r " +
147  "where r.registerDate < ? " +
148  "and r.closing = TRUE " +
149  "and day(r.registerDate) = 1 " +
150  "and month(r.registerDate) = 1",
151  new Object[] { fromDate });
152  } catch(NoResultException ex) {
153  return null;
154  }
155  }
156 
157 }
StatementFirst(double initialDebit, double initialCredit)
static String get(String msg)
Definition: I_.java:41
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380