BrightSide Workbench Full Report + Source Code
SaleProspectResults.java
Go to the documentation of this file.
1 package org.turro.crm.search;
2 
3 import org.turro.auth.Authentication;
4 import org.turro.crm.db.CrmPU;
5 import org.turro.crm.entity.SaleProspect;
6 import org.turro.elephant.context.Application;
7 import org.turro.elephant.db.SQLHelper;
8 import org.turro.elephant.db.WhereClause;
9 import org.turro.jpa.Dao;
10 import org.turro.plugin.contacts.IContact;
11 import org.zkoss.lang.Strings;
12 
17 public class SaleProspectResults {
18 
19  private Application app = Application.getApplication();
20 
21  private boolean ckOthers;
22  private String saleProspectValue = "*";
23  private IContact byParticipant;
24 
26  }
27 
28  public java.util.List<SaleProspect> getSaleProspectList() {
29  Dao dao = new CrmPU();
30  return dao.getResultList(createCriteria());
31  }
32 
34  WhereClause wc = new WhereClause();
35 
36  wc.addClause("select distinct saleProspect from SaleProspect as saleProspect");
37  wc.addClause("where 1=1");
38 
39  if(Strings.isEmpty(saleProspectValue) || (ckOthers && !app.isInRole("sale-prospect:all"))) {
40  wc.addClause("order by saleProspect.prospectDate");
41  return wc;
42  }
43 
44  if(byParticipant == null) {
45  byParticipant = Authentication.getIContact();
46  }
47 
48  wc = SQLHelper.getWhereClause(wc, new String[] {
49  "saleProspect.description"
50  }, (saleProspectValue == null ? "" : saleProspectValue.replaceAll("\\*", "%")));
51 
52  if(!(ckOthers && app.isInRole("sale-prospect:all"))) {
53  wc.addClause("and ( exists (");
54 
55  wc.addClause(
56  "select co from CustomerOwner as co where co.vendor.idContact = :idOwner " +
57  "and co.customer = saleProspect.customer"
58  );
59  wc.addNamedValue("idOwner", byParticipant.getId());
60 
61  wc.addClause(") or exists (");
62 
63  wc.addClause(
64  "select vp from VendorProspect as vp where vp.vendor.idContact = :idVendor " +
65  "and vp.saleProspect = saleProspect"
66  );
67  wc.addNamedValue("idVendor", byParticipant.getId());
68 
69  wc.addClause("))");
70  }
71 
72  wc.addClause("order by saleProspect.prospectDate");
73 
74  return wc;
75  }
76 
78  return byParticipant;
79  }
80 
81  public void setByParticipant(IContact byParticipant) {
82  this.byParticipant = byParticipant;
83  }
84 
85  public boolean isCkOthers() {
86  return ckOthers;
87  }
88 
89  public void setCkOthers(boolean ckOthers) {
90  this.ckOthers = ckOthers;
91  }
92 
93  public String getSaleProspectValue() {
94  return saleProspectValue;
95  }
96 
97  public void setSaleProspectValue(String saleProspectValue) {
98  this.saleProspectValue = saleProspectValue;
99  }
100 
101 }
java.util.List< SaleProspect > getSaleProspectList()
void setByParticipant(IContact byParticipant)
void setSaleProspectValue(String saleProspectValue)
static WhereClause getWhereClause(String[] fields, String value)
Definition: SQLHelper.java:64
void addNamedValue(String name, Object value)