18 package org.turro.financials.model.register;
21 import org.amic.util.date.CheckDate;
22 import org.turro.financials.db.FinancialsPU;
23 import org.turro.financials.entity.Account;
24 import org.turro.financials.entity.Register;
25 import org.turro.financials.entity.RegisterView;
26 import org.turro.financials.model.AccountFormat;
27 import org.turro.jpa.Dao;
28 import org.turro.math.Round;
36 private final String startString, endString, operatingString;
37 private final Collection<AccountItem> toInsert =
new HashSet<>();
39 public ClosingRegisters(String startString, String endString, String operatingString) {
40 this.startString = startString;
41 this.endString = endString;
42 this.operatingString = operatingString;
47 return list !=
null && !(list.isEmpty());
66 List<Register> list =
new ArrayList<>();
67 Set amounts = getAmounts(exercise);
68 list.addAll(generateOperatingRegisters(exercise, amounts));
69 list.addAll(generateCloseAndStartRegisters(exercise, amounts));
76 "select new org.turro.financials.model.register.AccountItem(re.register.view.id, re.account.id, sum(round(re.debit - re.credit, 4) + 0.0)) " +
77 "from RegisterEntry as re " +
78 "where year(re.register.registerDate) = ? " +
79 "group by re.register.view.id, re.account.id " +
80 "having sum(round(re.debit - re.credit, 4) + 0.0) <> 0.0",
81 new Object[] { exercise}));
87 "select sum(round(re.debit - re.credit, 4) + 0.0) " +
88 "from RegisterEntry as re " +
89 "where year(re.register.registerDate) = ? " +
90 "and re.account.id = ?",
96 return dao.getResultList(
97 "select distinct year(reg.registerDate) from Register reg");
100 private Collection<Register> generateOperatingRegisters(
int exercise, Set<AccountItem> amounts) {
101 List<Register> list =
new ArrayList<>();
106 if(current ==
null) {
112 }
else if(current.
getId() != ai.view.getId()) {
116 acc.
setId(
"1290000000");
118 AccountItem ai129 = AccountItem.createAccountItem(current, acc, g129);
119 if(ai129 !=
null) toInsert.add(ai129);
124 reg =
new RegisterGenerator();
130 if(ai.account.getId().startsWith(
"6") || ai.account.getId().startsWith(
"7")) {
132 reg.
addAccount(ai.account, operatingString, -ai.balance);
138 Account acc =
new Account();
139 acc.setId(
"1290000000");
141 AccountItem ai129 = AccountItem.createAccountItem(current, acc, g129);
142 if(ai129 !=
null) toInsert.add(ai129);
145 amounts.addAll(toInsert);
149 private Collection<Register> generateCloseAndStartRegisters(
int exercise, Set<AccountItem> amounts) {
150 List<Register> list =
new ArrayList<>();
151 RegisterGenerator close =
new RegisterGenerator(), start =
new RegisterGenerator();
152 RegisterView current =
null;
153 for(AccountItem ai : amounts) {
154 if(current ==
null) {
156 close.getRegister().setClosing(
true);
157 close.getRegister().setExclude(
true);
158 close.getRegister().setView(current);
159 close.getRegister().setRegisterDate(
new CheckDate(exercise, 12, 31, 0, 0, 0).getDate());
160 start.getRegister().setClosing(
true);
161 start.getRegister().setExclude(
false);
162 start.getRegister().setView(current);
163 start.getRegister().setRegisterDate(
new CheckDate(exercise + 1, 1, 1, 0, 0, 0).getDate());
164 }
else if(current.getId() != ai.view.getId()) {
165 list.add(close.getRegister());
166 list.add(start.getRegister());
168 close =
new RegisterGenerator();
169 start =
new RegisterGenerator();
170 close.getRegister().setClosing(
true);
171 close.getRegister().setExclude(
true);
172 close.getRegister().setView(current);
173 close.getRegister().setRegisterDate(
new CheckDate(exercise, 12, 31, 0, 0, 0).getDate());
174 start.getRegister().setClosing(
true);
175 start.getRegister().setExclude(
false);
176 start.getRegister().setView(current);
177 start.getRegister().setRegisterDate(
new CheckDate(exercise + 1, 1, 1, 0, 0, 0).getDate());
179 close.addAccount(ai.account, endString, -ai.balance);
180 start.addAccount(ai.account, startString, ai.balance);
182 if(!(close.getRegister().isEmpty())) {
183 list.add(close.getRegister());
184 list.add(start.getRegister());
191 List<Register> list = dao.getResultList(
192 "select reg from Register reg " +
194 "year(reg.registerDate) = ? " +
195 "and month(reg.registerDate) = 12 " +
196 "and reg.exclude = TRUE and reg.closing = TRUE " +
198 "year(reg.registerDate) = ? " +
199 "and month(reg.registerDate) = 1 " +
200 "and reg.exclude = FALSE and reg.closing = TRUE " +
201 ") and reg.document is null",
202 new Object[] { exercise, exercise + 1});
206 private Set<AccountItem> getAmounts(
int exercise) {
209 "select new org.turro.financials.model.register.AccountItem(re.register.view.id, re.account.id, sum(round(re.debit - re.credit, 4) + 0.0)) " +
210 "from RegisterEntry as re " +
211 "where year(re.register.registerDate) = ? " +
212 "and re.register.exclude = FALSE " +
213 "group by re.register.view.id, re.account.id",
214 new Object[] { exercise}));
void setExclude(boolean exclude)
void setView(RegisterView view)
void setClosing(boolean closing)
void setRegisterDate(Date registerDate)
Set< AccountItem > getNotClosed(int exercise)
ClosingRegisters(String startString, String endString, String operatingString)
Collection< Register > getClosureRegisters(int exercise)
void deleteClosingRegisters(int exercise)
boolean existsClosingRegisters(int exercise)
Double get129(int exercise)
Collection< Register > generateClosingRegisters(int exercise)
Collection< Integer > getExercises()
void createClosingRegisters(int exercise)
void addAccount(Account account, String concept, double balance)
Object getSingleResultOrNull(SqlClause sc)