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