18 package org.turro.financials.register;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
23 import org.turro.elephant.context.Application;
24 import org.turro.elephant.context.ElephantContext;
25 import org.turro.elephant.util.DateFormats;
26 import org.turro.elephant.util.Messages;
27 import org.turro.financials.account.AccountCombobox;
28 import org.turro.financials.entity.Account;
29 import org.turro.financials.entity.Register;
30 import org.turro.financials.entity.RegisterEntry;
31 import org.turro.financials.entity.RegisterView;
32 import org.turro.financials.model.AccountCreator;
33 import org.turro.financials.model.AccountSet;
34 import org.turro.financials.model.business.CompanyWrapper;
35 import org.turro.financials.model.register.AccountStringWrapper;
36 import org.turro.financials.model.register.MultiRegisterEntry;
37 import org.turro.financials.model.register.RegisterWrapper;
38 import org.turro.financials.model.register.ViewWrapper;
39 import org.turro.financials.view.ViewListbox;
40 import org.turro.i18n.I_;
41 import org.turro.math.Zero;
42 import org.turro.util.PhraseBuilder;
43 import org.turro.zkoss.grid.CollectionGrid;
44 import org.turro.zkoss.grid.EditableCell;
45 import org.turro.zkoss.grid.EditableColumn;
46 import org.turro.zul.frame.Framework;
47 import org.zkoss.zk.ui.HtmlBasedComponent;
48 import org.zkoss.zul.Row;
57 private Date lastDate =
new Date();
59 private boolean autocheck =
true, regularizeVAT =
false, regularizeIRPF =
false;
62 super(
new TreeSet<MultiRegisterEntry>());
66 this.
register =
register;
67 if(this.
register !=
null) {
68 for(
RegisterEntry entry : this.
register.getRegisterEntries()) {
71 regularizeVAT =
register.isRegularizeVAT();
72 regularizeIRPF =
register.isRegularizeIRPF();
81 this.autocheck = autocheck;
85 return regularizeIRPF;
89 this.regularizeIRPF = regularizeIRPF;
97 this.regularizeVAT = regularizeVAT;
104 public void save(
final boolean close) {
105 if(
register !=
null) {
106 register.setRegularizeVAT(regularizeVAT);
107 register.setRegularizeIRPF(regularizeIRPF);
113 PhraseBuilder pb =
new PhraseBuilder(
I_.
get(
"Closing date"));
117 pb.addWord(
I_.
get(
"Proceed anyway"));
129 final HashSet<Register> regs =
new HashSet<>();
131 for(Object obj :
getRows().getChildren()) {
132 if(obj instanceof Row) {
135 if(lastEntry !=
null && lastEntry.
isValid()) {
154 boolean isSafe =
true;
162 PhraseBuilder pb =
new PhraseBuilder(
I_.
get(
"Closing date"));
166 pb.addWord(
I_.
get(
"Proceed anyway"));
169 r.setRegularizeVAT(regularizeVAT);
170 r.setRegularizeIRPF(regularizeIRPF);
180 r.setRegularizeVAT(regularizeVAT);
181 r.setRegularizeIRPF(regularizeIRPF);
189 public void delete(
final boolean close) {
193 if(wReg.delete() && close) Framework.getCurrent().closeSelected();
204 if(
register !=
null) {
206 register.getRegisterEntries().add(re);
221 if(
register !=
null) {
223 register.getRegisterEntries().add(re);
236 row.setSclass(
"invalid");
238 if(
register ==
null) {
261 super.cellChanged(editableCell, value);
263 if(value instanceof Double) {
271 if(
register !=
null) {
272 register.setView(lastView);
273 setAllValuesAsRegister();
275 }
else if(value instanceof Date) {
276 lastDate = (Date) value;
277 if(
register !=
null) {
278 register.setRegisterDate(lastDate);
279 setAllValuesAsRegister();
289 super.rowChanged(row);
297 }
else if(value instanceof
Account) {
301 return super.formatCell(editableCell, value);
311 vl.setMold(
"select");
323 return super.createEditor(editableCell);
330 }
catch (ClassNotFoundException ex) {
333 super.afterCompose();
336 private void addColumns() throws ClassNotFoundException {
339 "view",
null, 0,
false,
false).setWidth(
"110px");
341 "date",
null, fractionDigits,
true,
false).setWidth(
"100px");
343 "newRegister",
null, 0,
false,
register !=
null).setWidth(
"35px");
345 "account",
null, 0,
false,
false).setWidth(
"350px");
347 "concept",
null, 0,
false,
false);
349 "debit",
null, fractionDigits,
false,
false).setWidth(
"100px");
351 "credit",
null, fractionDigits,
false,
false).setWidth(
"100px");
353 "balance",
null, fractionDigits,
false,
true).setWidth(
"100px");
355 "accountBalance",
null, fractionDigits,
false,
true).setWidth(
"100px");
358 private void checkValues() {
359 MultiRegisterEntry lastEntry =
null;
362 Map<String, Double> accBal =
new HashMap<>();
363 for(Object obj :
getRows().getChildren()) {
364 if(obj instanceof Row) {
366 MultiRegisterEntry rentry = (MultiRegisterEntry) ((Row) obj).getValue();
368 if(rentry.isValid()) {
369 if(lastEntry !=
null && lastEntry.isValid()) {
370 if(!rentry.isSameRegister(lastEntry)) {
372 accBal =
new HashMap<>();
374 if(Zero.near(lastEntry.getBalance(), 2)) {
375 lastRow.setSclass(
"endRegister");
377 lastRow.setSclass(
"endBadRegister");
384 Double accB = accBal.get(rentry.getAccount().getId());
386 accB =
new AccountStringWrapper(rentry.getAccount().getId())
387 .getBalance(rentry.getView(), rentry.getDate());
392 rentry.setAccountBalance(accB + rentry.getDebit() - rentry.getCredit());
393 accBal.put(rentry.getAccount().getId(), rentry.getAccountBalance());
394 balance += rentry.getDebit() - rentry.getCredit();
395 rentry.setBalance(balance);
397 row.setSclass(
"invalid");
401 if(lastEntry !=
null && lastEntry.isValid()) {
403 if(Zero.near(lastEntry.getBalance(), 2)) {
404 lastRow.setSclass(
"endRegister");
406 lastRow.setSclass(
"endBadRegister");
413 private void setAllValuesAsRegister() {
414 if(
register !=
null) {
415 for(Object obj :
getRows().getChildren()) {
416 if(obj instanceof Row) {
417 MultiRegisterEntry rentry = (MultiRegisterEntry) ((Row) obj).getValue();
418 rentry.setView(
register.getView());
419 rentry.setDate(
register.getRegisterDate());
boolean isInRole(String role)
static Application getApplication()
static String logMsg(String msg)
static Messages question()
static Messages confirmDeletion()
Messages add(String word)
void setAllowNewAccount(boolean allowNewAccount)
String getFullDescription()
void setAccount(Account account)
void setRegister(Register register)
void setEntryOrder(long entryOrder)
void setView(RegisterView view)
Set< RegisterEntry > getRegisterEntries()
void setRegisterDate(Date registerDate)
static AccountSet getOnUseAccounts()
static AccountSet getPosibleAccounts()
static Currency getCompanyCurrency()
static Date getCompanyClosingDate()
void setView(RegisterView view)
boolean isSameRegister(MultiRegisterEntry newEntry)
void checkValues(int cellIndex)
static RegisterView getFormalView()
void loadPosibleAccounts()
void setAutocheck(boolean autocheck)
void setRegister(Register register)
boolean deleteRow(Row row)
boolean isValid(MultiRegisterEntry v)
boolean isRegularizeVAT()
void initiateRow(Row row, MultiRegisterEntry value)
void save(final boolean close)
void cellChanged(EditableCell editableCell, Object value)
HtmlBasedComponent createEditor(EditableCell editableCell)
void setRegularizeVAT(boolean regularizeVAT)
void setRegularizeIRPF(boolean regularizeIRPF)
boolean isRegularizeIRPF()
String formatCell(EditableCell editableCell, Object value)
static String get(String msg)
Collection< V > getCollection()
EditableColumn addColumn(String label, Class javaClass, String property, String format, int scale, boolean onlyDate, boolean readOnly)
Object getCellValue(EditableCell editableCell)
Rows getRows(boolean create)
static Framework getCurrent()