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