18 package org.turro.financials.model.register;
20 import java.util.HashSet;
21 import java.util.Iterator;
23 import org.turro.financials.db.FinancialsPU;
24 import org.turro.financials.entity.*;
25 import org.turro.financials.model.AccountsForDocumentLine;
26 import org.turro.financials.model.business.CompanyWrapper;
27 import org.turro.jpa.Dao;
28 import org.turro.jpa.entity.XMLSerializer;
29 import org.turro.log.SystemLogType;
30 import org.turro.log.SystemLogger;
39 private Set<Long> bookDefs;
40 private boolean generate;
47 this.
register =
register;
48 this.generate = generate;
49 bookDefs =
new HashSet<Long>();
58 return generateEntries();
63 if(generate &&
register.getDocument() !=
null) {
64 register.setRegularizeVAT(
register.getDocument().isRegularizeVAT());
65 register.setRegularizeIRPF(
register.getDocument().isRegularizeIRPF());
67 if(
register.getDocument().getForcedView() !=
null) {
69 if(
register.getDocument().getForcedView().getId() !=
register.getView().getId()) {
75 for(
DocumentLine dl :
register.getDocument().getDocumentLines()) {
76 if(dl.getSubtotal() != 0) {
82 es.
roundEntries(
register.getDocument().getCurrency().getDefaultFractionDigits());
83 new RegisterAssuredBalance(es,
register.getDocument()).normalize();
86 register.killUnusedBooks(bookDefs);
90 if(re.getDebit() != 0 || re.getCredit() != 0) {
95 bookDefs.add(bf.
getId());
108 Iterator<BookRegister> itbr =
register.getBookRegisters().iterator();
110 while(itbr.hasNext()) {
112 boolean found =
false;
113 for(Long idBd : bookDefs) {
119 if(!found && br.
getId() == 0) {
124 StringBuilder sb =
new StringBuilder();
125 for(Long idBd : bookDefs) {
126 boolean found =
false;
128 if(br.getBookDefinition().getId() == idBd) {
129 if(sb.length() > 0) {
132 sb.append(br.getBookDefinition().getDescription());
133 sb.append(
" [" + (br.getBookOrder() == 0 ?
"<auto>" : br.getBookOrder()) +
"]");
144 register.getBookRegisters().add(br);
145 if(sb.length() > 0) {
149 sb.append(
" [<auto>]");
153 return sb.toString();
163 public boolean delete() {
164 if(
register.getDocument() ==
null) {
174 Set<Long> bookDefs =
new HashSet<Long>();
176 if(re.getDebit() != 0 || re.getCredit() != 0) {
181 bookDefs.add(bf.
getId());
186 for(Long bookDef : bookDefs) {
190 register.getBookRegisters().add(br);
192 register.prepareSave();
void setRegister(Register register)
BookDefinition getBookDefinition()
void setBookDefinition(BookDefinition bookDefinition)
BookDefinition getBookDefinition()
static boolean isValidDate(Date date)
void addEntry(RegisterEntry entry)
void roundEntries(int fractionDigits)
Collection< RegisterEntry > getRegisterEntries()
static Register prepareBookRegister(Register register)
RegisterWrapper(Register register)
RegisterWrapper(Register register, boolean generate)
void deleteObject(Object obj)
static ISystemLogger getInstance()
void doLog(SystemLogType type, Object entity, String comment, Serializable data)