BrightSide Workbench Full Report + Source Code
DeclaredQuarter.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.treasury.m303;
19 
20 import java.util.Date;
21 import org.amic.util.date.CheckDate;
22 import org.turro.jpa.Dao;
23 
28 public class DeclaredQuarter {
29 
30  private ModelSet set;
31  private int quarter;
32  private Double amountDeclared;
33 
34  public DeclaredQuarter(ModelSet set, int quarter) {
35  this.set = set;
36  this.quarter = quarter;
37  fillData();
38  }
39 
40  public double getAmountDeclared() {
41  return amountDeclared == null ? 0 : amountDeclared;
42  }
43 
44  public int getQuarter() {
45  return quarter;
46  }
47 
48  public Dao getDao() {
49  return set.getDao();
50  }
51 
52  private void fillData() {
53  amountDeclared = (Double) getDao().getSingleResult(
54  "select sum(e.credit) from RegisterEntry e " +
55  "where e.register.registerDate <= ? " +
56  "and e.register.registerDate >= ? " +
57  "and e.register.view.id = 1 " +
58  "and (e.register.exclude = FALSE and e.register.closing = FALSE and e.register.regularizeVAT = FALSE) " +
59  //"and e.register.exclude = FALSE " +
60  "and e.account.id = ?",
61  new Object[] { getFinalDate(), getInitialDate(), set.getDeclaredPositiveAccount() });
62  if(amountDeclared == null || amountDeclared == 0) {
63  amountDeclared = (Double) getDao().getSingleResult(
64  "select sum(e.debit) from RegisterEntry e " +
65  "where e.register.registerDate <= ? " +
66  "and e.register.registerDate >= ? " +
67  "and e.register.view.id = 1 " +
68  "and (e.register.exclude = FALSE and e.register.closing = FALSE and e.register.regularizeVAT = FALSE) " +
69  //"and e.register.exclude = FALSE " +
70  "and e.account.id = ?",
71  new Object[] { getFinalDate(), getInitialDate(), set.getDeclaredNegativeAccount() });
72 
73  if(amountDeclared != null) {
74  amountDeclared = -amountDeclared;
75  }
76  }
77  }
78 
79  public Date getInitialDate() {
80  return new CheckDate(set.getExercise(), ((quarter - 1) * 3) + 1, 1, 0, 0, 0).addDays(26).getDate();
81  }
82 
83  public Date getFinalDate() {
84  return new CheckDate(set.getExercise(), ((quarter - 1) * 3) + 4, 1, 0, 0, 0).addDays(-1).addDays(25).getDate();
85  }
86 
87  public Date getRegisterDate() {
88  return new CheckDate(set.getExercise(), ((quarter - 1) * 3) + 4, 1, 0, 0, 0).addDays(-1).getDate();
89  }
90 
91 }
Object getSingleResult(WhereClause wc)
Definition: Dao.java:380