18 package org.turro.financials.portfolio;
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23 import java.util.TreeSet;
24 import org.turro.action.IAcceptances;
25 import org.turro.action.Plugins;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.financials.db.FinancialsPU;
28 import org.turro.financials.entity.Document;
29 import org.turro.financials.entity.DocumentDefinition;
30 import org.turro.financials.entity.DocumentWorkflow;
31 import org.turro.jpa.Dao;
32 import org.turro.plugin.filter.IFilterValue;
33 import org.turro.zkoss.grid.GroupExtended;
34 import org.zkoss.zul.Grid;
35 import org.zkoss.zul.Group;
44 private long lastContract = 0, lastDocDef = 0;
47 this.documentDefinition = documentDefinition;
51 ArrayList<Document> docs =
new ArrayList<Document>();
65 for(Object[] o : (List<Object[]>) dao.getResultList(wc)) {
95 grid.getRows().appendChild(group);
101 wc.
addClause(
"select doc, dw from Document as doc, DocumentWorkflow as dw");
104 if(!v.getLabel().equals(
"Document model")) {
108 wc.
addClause(
"and doc.contract.contractDefinition = dw.contractDefinition");
112 if(mode.equals(RelationMode.RELATE_FORWARD) || mode.equals(RelationMode.RELATE_BOTH)) {
116 wc.
addClause(
"doc.documentDefinition = dw.ancestor");
117 for(IFilterValue v : values) {
118 if(v.getLabel().equals(
"Document model")) {
123 if(documentDefinition !=
null) {
124 wc.
addClause(
"and dw.descendant = :docDefDes");
127 wc.
addClause(
"and doc.noDescendants = FALSE");
129 wc.
addClause(
"select dr from DocumentRelation as dr");
133 if(mode.equals(RelationMode.RELATE_BACKWARD) || mode.equals(RelationMode.RELATE_BOTH)) {
136 wc.
addClause(
"doc.documentDefinition = dw.descendant");
137 wc.
addClause(
"and dw.allowNewDescendants = TRUE");
138 for(IFilterValue v : values) {
139 if(v.getLabel().equals(
"Document model")) {
140 wc.
getAttributes().put(
"mode", RelationMode.RELATE_BACKWARD);
144 if(documentDefinition !=
null) {
145 wc.
addClause(
"and dw.ancestor = :docDefAnc");
148 wc.
addClause(
"and doc.noAncestors = FALSE");
150 wc.
addClause(
"select dr from DocumentRelation as dr");
151 wc.
addClause(
"where dr.descendant = doc");
156 wc.
addClause(
"order by doc.contract.id, doc.documentDefinition.id, doc.documentDate");
160 private PortfolioItem getItem(Document document) {
161 for(PortfolioItem item :
this) {
162 if(item.getDocument().getId() == document.getId()) {
static< T > T loadImplementation(Class< T > jclass)
Map< String, Object > getAttributes()
void addClause(String clause)
void addNamedValue(String name, Object value)
static String getObjectPath(Object object)
String getFullDescription()
DocumentDefinition getAncestor()
DocumentDefinition getDocumentDefinition()
void addForward(DocumentWorkflow dw)
void addBackward(DocumentWorkflow dw)
void checkGroup(Grid grid, Document document)
void load(RelationMode mode, List< IFilterValue > values)
void setDocumentDefinition(DocumentDefinition documentDefinition)
Collection< Document > getDocuments()
void addDocument(Document document, DocumentWorkflow workflow)
AcceptanceStatus getStatusFor(String path)