18 package org.turro.financials.entity;
21 import javax.persistence.*;
22 import org.amic.util.date.CheckDate;
23 import org.turro.elephant.db.IdUtils;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.model.Amount;
26 import org.turro.financials.model.AmountSet;
27 import org.turro.financials.model.document.DocumentAmounts;
28 import org.turro.jpa.entity.IDaoEntity;
29 import org.turro.reflection.MappingSet;
37 @Index(name=
"IndexRegister", columnList=
"idRegister"),
38 @Index(name=
"IndexDate", columnList=
"registerDate")
43 @GeneratedValue(strategy=GenerationType.IDENTITY)
44 @Column(name=
"IDENTIFIER")
47 @Column(nullable=false)
48 @Temporal(value = TemporalType.DATE)
49 private Date registerDate;
51 @Column(nullable=false)
52 private
long idRegister;
57 private
boolean exclude;
59 private
boolean closing;
61 private
boolean regularizeVAT;
63 private
boolean regularizeIRPF;
68 @OneToMany(mappedBy = "register", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
71 @OneToMany(mappedBy = "register", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval=true)
80 this.bookRegisters = bookRegisters;
88 this.closing = closing;
96 this.document = document;
104 this.exclude = exclude;
120 this.idRegister = idRegister;
128 if(this.registerDate !=
null && !
new CheckDate(this.registerDate).sameYear(registerDate)) {
129 bookRegisters.clear();
132 this.registerDate = registerDate;
136 return registerEntries;
140 this.registerEntries = registerEntries;
144 return regularizeIRPF;
148 this.regularizeIRPF = regularizeIRPF;
152 return regularizeVAT;
156 this.regularizeVAT = regularizeVAT;
177 return registerEntries.isEmpty() ||
179 registerDate ==
null;
185 if(idRegister == 0) {
189 "year(registerDate) = " +
new CheckDate(registerDate).getYear(),
190 "view.id = " + view.getId()
197 return List.of(getBookRegisters(), getRegisterEntries());
219 Iterator<RegisterEntry> it1 = getRegisterEntries().iterator();
220 Iterator<RegisterEntry> it2 = entries.iterator();
222 while(it1.hasNext()) {
243 registerEntries.add(re1);
245 while(it2.hasNext()) {
250 registerEntries.add(re1);
257 Iterator<BookRegister> it = getBookRegisters().iterator();
258 while(it.hasNext()) {
259 boolean used =
false;
261 for(
long bd : bookDefs) {
274 StringBuilder sb =
new StringBuilder();
276 if(sb.length() > 0) {
279 sb.append(br.getBookDefinition().getDescription());
280 sb.append(
" [" + (br.getBookOrder() == 0 ?
"<auto>" : br.getBookOrder()) +
"]");
282 return sb.toString();
290 if(document !=
null) {
293 for(String major : majors) {
294 if(acc.
getId().startsWith(major)) {
295 double tax = Integer.valueOf(acc.
getId().substring(5)) / 10.0;
297 double amount = re.getDebit() + re.getCredit();
313 if(document !=
null) {
314 da = document.getAmounts();
323 MappingSet
set =
new MappingSet();
325 new String[] {
"idRegister",
"registerDate" },
326 new String[] {
"view",
"registerEntries" });
328 new String[] {
"id",
"name" },
331 new String[] {
"debit",
"credit",
"approved",
"conciliated" },
332 new String[] {
"account" } );
333 set.addMapping(
Account.class, 3,
334 new String[] {
"id",
"description" },
static long getMaxLongIdFromLong(Dao dao, String table, String field)
BookDefinition getBookDefinition()
void assignValuesFrom(RegisterEntry registerEntry)
void setRegister(Register register)
MappingSet getSerializerMappings()
boolean isRegularizeIRPF()
void reuseLines(Collection< RegisterEntry > entries)
void setRegularizeIRPF(boolean regularizeIRPF)
Collection< Collection > collections()
void setExclude(boolean exclude)
AmountSet getAmounts(Collection< String > majors)
void setView(RegisterView view)
void setRegularizeVAT(boolean regularizeVAT)
void setRegisterEntries(Set< RegisterEntry > registerEntries)
Set< RegisterEntry > getRegisterEntries()
void setIdRegister(long idRegister)
void killUnusedBooks(Set< Long > bookDefs)
boolean isRegularizeVAT()
void setClosing(boolean closing)
void setBookRegisters(Set< BookRegister > bookRegisters)
void setDocument(Document document)
DocumentAmounts getDocumentAmounts()
void setRegisterDate(Date registerDate)
default void prepareSave()