BrightSide Workbench Full Report + Source Code
m303/ModelSet.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.Collection;
21 import java.util.TreeSet;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Account;
24 import org.turro.financials.entity.RegisterView;
25 import org.turro.financials.menu.FinancialsMenu;
26 import org.turro.financials.model.register.RegisterGenerator;
27 import org.turro.financials.model.register.ViewWrapper;
28 import org.turro.jpa.Dao;
29 
34 public class ModelSet extends TreeSet<ModelEntry> {
35 
36  private int exercise;
37  private Dao dao;
38  private DeclaredQuarter[] declaredQuarter = new DeclaredQuarter[4];
39 
40  public ModelSet(int exercise) {
41  this.exercise = exercise;
42  createEntries();
43  declaredQuarter[0] = new DeclaredQuarter(this, 1);
44  declaredQuarter[1] = new DeclaredQuarter(this, 2);
45  declaredQuarter[2] = new DeclaredQuarter(this, 3);
46  declaredQuarter[3] = new DeclaredQuarter(this, 4);
47  }
48 
49  public double getTotalInputVat(int quarter) {
50  double result = 0.0;
51  for(ModelEntry me : this) {
52  result += me.getQuarter(quarter).getTotalInputVat();
53  }
54  return result;
55  }
56 
57  public double getTotalOutputVat(int quarter) {
58  double result = 0.0;
59  for(ModelEntry me : this) {
60  result += me.getQuarter(quarter).getTotalOutputVat();
61  }
62  return result;
63  }
64 
65  public int getExercise() {
66  return exercise;
67  }
68 
69  public String getDeclaredPositiveAccount() {
70  return "4750000000";
71  }
72 
73  public String getDeclaredNegativeAccount() {
74  return "4700000000";
75  }
76 
77  public DeclaredQuarter getDeclaredQuarter(int quarter) {
78  return declaredQuarter[quarter];
79  }
80 
81  public Dao getDao() {
82  if(dao == null) {
83  dao = new FinancialsPU();
84  }
85  return dao;
86  }
87 
88  public void generateRegister(int quarter) {
90  RegisterView formalView = ViewWrapper.getFormalView();
91  reg.getRegister().setView(formalView);
92  reg.getRegister().setRegisterDate(getDeclaredQuarter(quarter).getRegisterDate());
93 
94  double total = 0.0;
95 
96  for(ModelEntry me : this) {
97  Collection<VatEntry> vats = me.getQuarter(quarter).getVatMap().values();
98  for(VatEntry ve : vats) {
99  Account acc = new Account();
100  acc.setId(ve.getAccount());
101  if(ve.getQuarter().getEntry().getType().getBookId() == 2L) {
102  reg.addAccount(acc, "Mod. 303 Q" + (quarter+1), ve.getToDeclareAmountVat(), 0.0);
103  total -= ve.getToDeclareAmountVat();
104  } else {
105  reg.addAccount(acc, "Mod. 303 Q" + (quarter+1), 0.0, ve.getToDeclareAmountVat());
106  total += ve.getToDeclareAmountVat();
107  }
108  }
109  }
110 
111  if(total < 0) {
112  Account acc = new Account();
114  reg.addAccount(acc, "Mod. 303 Q" + (quarter+1), 0.0, -total);
115  } else {
116  Account acc = new Account();
118  reg.addAccount(acc, "Mod. 303 Q" + (quarter+1), total, 0.0);
119  }
120 
122  }
123 
124  private void createEntries() {
125  for(ModelType mt : ModelType.values()) {
126  add(new ModelEntry(this, mt, exercise));
127  }
128  for(ModelEntry me : this) {
129  for(int quarter = 0; quarter < 4; quarter++) {
130  for(VatEntry ve : me.getQuarter(quarter).getVatMap().values()) {
131  if(quarter > 0) {
132  VatEntry prev = me.getQuarter(quarter - 1).getVatMap().get((int) ve.getVat() * 10);
133  if(prev != null) {
134  ve.setPendingVat(prev.getDeclaredVat() - prev.getAmountVat() + prev.getPendingVat());
135  }
136  }
137  me.getQuarter(quarter).addToDeclareOp(ve.getToDeclareAmountOp());
138  me.getQuarter(quarter).addToDeclareVat(ve.getToDeclareAmountVat());
139  }
140  }
141  }
142  }
143 
144 }
void setView(RegisterView view)
Definition: Register.java:163
void setRegisterDate(Date registerDate)
Definition: Register.java:127
void addAccount(Account account, String concept, double balance)
DeclaredQuarter getDeclaredQuarter(int quarter)