19 package org.turro.entities;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
27 import org.turro.string.Strings;
28 import org.turro.action.IEntityCtrl;
29 import org.turro.annotation.ElephantEntity;
30 import org.turro.attach.www.AttachCtrl;
31 import org.turro.collections.KeyValueMap;
32 import org.turro.command.LabelControl;
33 import org.turro.elephant.db.WhereClause;
34 import org.turro.elephant.util.DateFormats;
35 import org.turro.file.util.FileAttach;
36 import org.turro.financials.command.DocumentLabel;
37 import org.turro.financials.db.FinancialsPU;
38 import org.turro.financials.entity.Account;
39 import org.turro.financials.entity.BatchOf;
40 import org.turro.financials.entity.Company;
41 import org.turro.financials.entity.Contract;
42 import org.turro.financials.entity.ContractInterventionType;
43 import org.turro.financials.entity.ContractParticipant;
44 import org.turro.financials.entity.Department;
45 import org.turro.financials.entity.Document;
46 import org.turro.financials.entity.FixedAsset;
47 import org.turro.financials.entity.Headquarters;
48 import org.turro.financials.entity.MajorAccount;
49 import org.turro.financials.entity.Product;
50 import org.turro.financials.entity.Register;
51 import org.turro.financials.entity.Service;
52 import org.turro.financials.menu.FinancialsMenu;
53 import org.turro.i18n.I_;
54 import org.turro.jpa.Dao;
55 import org.turro.path.Path;
56 import org.turro.plugin.contacts.IContact;
57 import org.turro.www.commentit.CommentItCtrl;
58 import org.turro.www.describeit.DescribeItCtrl;
83 if(
null !=
path.getRoot())
switch (
path.getRoot()) {
117 case "major-account":
164 String root =
path.getRoot();
165 if(
null != root)
switch (root) {
167 return I_.
get(
"Contract");
169 return I_.
get(
"Document");
171 return I_.
get(
"Batch of");
173 return I_.
get(
"Product");
175 return I_.
get(
"Fixed asset");
177 return I_.
get(
"Company");
179 return I_.
get(
"Headquarters");
181 return I_.
get(
"Department");
183 return I_.
get(
"Service");
185 return I_.
get(
"Register");
187 return I_.
get(
"Account");
188 case "major-account":
189 return I_.
get(
"Major account");
201 return ((
Contract)
entity).getContractDefinition().getDescription();
224 String root =
path.getRoot();
225 if(
null != root)
switch (root) {
227 return "/_zul/images/contract.png";
229 return "/_zul/images/document.png";
231 return "/_zul/images/batchof.png";
233 return "/_zul/images/product.png";
235 return "/_zul/images/asset.png";
237 return "/_zul/images/b_company.png";
239 return "/_zul/images/b_headquarters.png";
241 return "/_zul/images/b_department.png";
243 return "/_zul/images/b_service.png";
245 return "/_zul/images/register.png";
285 return Collections.EMPTY_LIST;
375 public Collection
getEntitites(String search,
int maxResults, KeyValueMap kvm) {
376 ArrayList<Object> list =
new ArrayList<>();
377 list.addAll(searchContracts(search, maxResults, kvm));
378 list.addAll(searchProducts(search, maxResults, kvm));
379 list.addAll(searchFixedAssets(search, maxResults, kvm));
384 public Collection
getEntitites(String root, String search,
int maxResults, KeyValueMap kvm) {
385 ArrayList<Object> list =
new ArrayList<>();
386 if(
null != root)
switch (root) {
388 list.addAll(searchContracts(search, maxResults, kvm));
391 list.addAll(searchProducts(search, maxResults, kvm));
394 list.addAll(searchFixedAssets(search, maxResults, kvm));
449 case SELF_AS_COMPANY_OWNER:
450 return getRelatedEntities(role, contact);
452 return Collections.EMPTY_LIST;
458 case SELF_AS_COMPANY_OWNER:
464 if(cp.isSignature() && cp.getIdContact().equals(contact.
getId())) {
479 return "/" + contract.
getId() +
480 "/" + Strings.unpunctuate(contract.
getName()).toLowerCase();
498 return super.itsMine(rootPath) ||
500 "account".equals(rootPath) ||
"major-account".equals(rootPath);
515 return Arrays.asList(
"contract",
"document",
"batchof",
"product",
"fixed-asset",
516 "company",
"headquarters",
"department",
"service",
"register");
534 private List<Object> searchContracts(String search,
int maxResults, KeyValueMap kvm) {
536 wc.
addClause(
"select c from Contract c");
537 wc.
addClause(
"where c.name like :search");
540 return getDao().getResultList(wc, maxResults);
543 private List<Object> searchProducts(String search,
int maxResults, KeyValueMap kvm) {
544 WhereClause wc =
new WhereClause();
545 wc.addClause(
"select c from Product c");
546 wc.addClause(
"where c.description like :search");
547 wc.addClause(
"order by c.description");
548 wc.addNamedValue(
"search",
"%" + search +
"%");
549 return getDao().getResultList(wc, maxResults);
552 private List<Object> searchFixedAssets(String search,
int maxResults, KeyValueMap kvm) {
553 WhereClause wc =
new WhereClause();
554 wc.addClause(
"select c from FixedAsset c");
555 wc.addClause(
"where c.name like :search");
556 wc.addClause(
"order by c.name");
557 wc.addNamedValue(
"search",
"%" + search +
"%");
558 return getDao().getResultList(wc, maxResults);
561 private Collection<Object> getRelatedEntities(EntityRole role, IContact contact) {
563 case SELF_AS_COMPANY_OWNER:
564 String idContact = contact.getId();
565 WhereClause wc =
new WhereClause();
566 wc.addClause(
"select distinct ctc from Contract ctc");
567 wc.addClause(
"left join ctc.participants par");
568 wc.addClause(
"where 1=1");
569 wc.addClause(
"and (ctc.contractor = :contractor");
570 wc.addNamedValue(
"contractor", idContact);
571 for(ContractInterventionType cit : ContractInterventionType.values()) {
572 if(cit.isSignature()) {
573 wc.addClause(
"or (par.interventionType = :cit" + cit.toString());
574 wc.addNamedValue(
"cit" + cit.toString(), cit);
575 wc.addClause(
"and par.idContact = :con" + cit.toString() +
")");
576 wc.addNamedValue(
"con" + cit.toString(), idContact);
580 return getDao().getResultList(wc);
582 return Collections.EMPTY_LIST;
void setPublicOnly(boolean publicOnly)
void setEntityPath(String entityPath)
void addClause(String clause)
void addNamedValue(String name, Object value)
boolean isValidLongEntity()
boolean equals(Object obj)
static IElephantEntity getController(String path)
boolean canShowInContext(IContact contact, Object relatedEntity)
boolean canEdit(IContact contact)
IElephantEntity createInstance(Object entity)
boolean itsMine(Object entity)
String getExtendedWebPath()
Collection getEntitites(String root, String search, int maxResults, KeyValueMap kvm)
IElephantEntity createInstance(String entityPath)
boolean canPublish(IContact contact)
IElephantEntity getParent()
Collection< String > getAllowedRoots()
boolean itsMine(String rootPath)
String getHierarchicalPath()
FinancialsEntities(String entityPath)
boolean hasRelatedRole(EntityRole role, IContact contact)
Collection< Object > getRelatedByRole(EntityRole role, IContact contact)
Collection getEntitites(String search, int maxResults, KeyValueMap kvm)
FinancialsEntities(Object entity)
Object configureCtrl(Object ctrl, IContact contact)
List< IElephantEntity > getChildren()
static String getObjectPath(Object object)
static String getObjectExtendedPath(Object object)
Collection< IContact > getIParticipants()
List< Document > getDocuments()
static String get(String msg)
boolean isInRole(String role)
void setEntityPath(String entityPath)
void setEntityPath(String entityPath)
static final String PATH_SEPARATOR