18 package org.turro.financials.model.document;
21 import org.turro.financials.db.FinancialsPU;
22 import org.turro.financials.entity.*;
23 import org.turro.financials.model.contract.ContractWrapper;
24 import org.turro.financials.model.register.RegisterWrapper;
25 import org.turro.financials.model.register.ViewWrapper;
26 import org.turro.jpa.Dao;
27 import org.turro.jpa.entity.DaoEntity;
28 import org.turro.usual.UsualUsages;
36 private List<DocumentLine> lines;
37 private List<DocumentRelation> descendants;
42 entity.setRegularizeVAT(r.isRegularizeVAT());
43 entity.setRegularizeIRPF(r.isRegularizeIRPF());
53 Set<RegisterWrapper> s =
new HashSet<RegisterWrapper>();
57 if(r.getView().getId() == rv.getId()) {
58 r.setRegisterDate(
entity.getReceiptDate());
69 entity.getRegisters().add(r);
78 this.descendants = descendants;
83 return save(lines, descendants);
86 public Document save(List<DocumentLine> lines, List<DocumentRelation> descendants) {
91 if(descendants !=
null) {
95 if(!dr.getDescendant().isEmpty()) {
96 dr.getDescendant().setForcedView(
entity.getForcedView());
97 if(dr.getDescendant().getId() == 0) {
99 dr.getDescendant().setDraft(
true);
103 dr.getDescendant().setDraft(
false);
106 for(
DocumentLine l : dr.getDescendant().getDocumentLines()) {
107 if(!l.isEmpty() && l.getStore() !=
null) {
114 dr.setDescendant(dw.
save(
null,
null));
120 entity.assignTableOrder(lines);
122 if(!l.isEmpty() && l.getStore() !=
null) {
130 entity.getRegisters().clear();
133 Iterator<Register> ir =
entity.getRegisters().iterator();
134 while(ir.hasNext()) {
141 }
else if(
entity.getForcedView() !=
null) {
151 ArrayList<DocumentRelation> relancestors =
new ArrayList<DocumentRelation>(
entity.getAncestors());
152 ArrayList<DocumentRelation> reldescendants =
new ArrayList<DocumentRelation>(
entity.getDescendants());
153 entity.getAncestors().clear();
154 entity.getDescendants().clear();
168 if(!dr.isEmpty() && dr.getDescendant().getId() != 0) {
178 public boolean delete() {
181 "delete from DocumentRelation " +
182 "where ancestor = ? " +
185 entity.getAncestors().clear();
186 entity.getDescendants().clear();
187 return super.delete();
196 return getDao().getResultList(
197 "select doc from Document as doc " +
198 "where doc.descendants is empty " +
199 "and doc.documentDefinition = ? " +
200 "and doc.contract = ?",
201 new Object[] { documentDefinition,
entity.getContract() });
205 return getDao().getResultList(
206 "select doc from Document as doc " +
207 "where doc.ancestors is empty " +
208 "and doc.documentDefinition = ? " +
209 "and doc.contract = ?",
210 new Object[] { documentDefinition,
entity.getContract() });
214 if(
entity.getContract() !=
null) {
void setView(RegisterView view)
void setIdRegister(long idRegister)
void setDocument(Document document)
void setRegisterDate(Date registerDate)
double getAdvance(RegisterView view)
void setPriorSavingValues(List< DocumentLine > lines, List< DocumentRelation > descendants)
List< Document > getRelatedDescendant(DocumentDefinition documentDefinition)
List< Document > getRelatedAncestor(DocumentDefinition documentDefinition)
Set< RegisterWrapper > getRegisters()
DocumentWrapper(Document entity)
Document save(List< DocumentLine > lines, List< DocumentRelation > descendants)
static List< RegisterView > getViews()
int executeUpdate(String query)
static Usually addUsage(String path)
default void removeEmpties()