BrightSide Workbench Full Report + Source Code
SaleActionResults.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 SaleActionResults {
18 
19  private Application app = Application.getApplication();
20 
21  private boolean ckOthers, ckDone;
22  private String saleActionValue = "*";
23  private IContact byParticipant;
24  private SaleProspect saleProspect;
25 
26  public SaleActionResults() {
27  }
28 
29  public java.util.List getSaleActionList() {
30  Dao dao = new CrmPU();
31  return dao.getResultList(createCriteria());
32  }
33 
35  WhereClause wc = new WhereClause();
36 
37  wc.addClause("select distinct saleAction");
38  wc.addClause("from SaleAction as saleAction");
39  wc.addClause("where 1=1");
40 
41  if(Strings.isEmpty(saleActionValue) || (ckOthers && !app.isInRole("sale-prospect:all"))) {
42  //TODO: check if necessary wc.addClause("and 0=1");
43  wc.addClause("order by saleAction.actionDate");
44  return wc;
45  }
46 
47  if(byParticipant == null) {
48  byParticipant = Authentication.getIContact();
49  }
50 
51  wc = SQLHelper.getWhereClause(wc, new String[] {
52  "saleAction.comment"
53  }, (saleActionValue == null ? "" : saleActionValue.replaceAll("\\*", "%")));
54 
55  if(!(ckOthers && app.isInRole("sale-prospect:all"))) {
56  wc.addClause("and ( exists (");
57 
58  wc.addClause(
59  "select co from CustomerOwner as co where co.vendor.idContact = :idOwner " +
60  "and co.customer = saleAction.vendorProspect.saleProspect.customer"
61  );
62  wc.addNamedValue("idOwner", byParticipant.getId());
63 
64  wc.addClause(") or exists (");
65 
66  wc.addClause(
67  "select vp from VendorProspect as vp where vp.vendor.idContact = :idVendor " +
68  "and vp.saleProspect = saleAction.vendorProspect.saleProspect"
69  );
70  wc.addNamedValue("idVendor", byParticipant.getId());
71 
72  wc.addClause("))");
73  }
74 
75  if(!ckDone) {
76  wc.addClause("and saleAction.done = FALSE");
77  }
78 
79  if(saleProspect != null) {
80  wc.addClause("and saleAction.vendorProspect.saleProspect = :saleProspect");
81  wc.addNamedValue("saleProspect", saleProspect);
82  }
83 
84  wc.addClause("order by saleAction.actionDate");
85 
86  return wc;
87  }
88 
90  return byParticipant;
91  }
92 
93  public void setByParticipant(IContact byParticipant) {
94  this.byParticipant = byParticipant;
95  }
96 
97  public boolean isCkDone() {
98  return ckDone;
99  }
100 
101  public void setCkDone(boolean ckDone) {
102  this.ckDone = ckDone;
103  }
104 
105  public boolean isCkOthers() {
106  return ckOthers;
107  }
108 
109  public void setCkOthers(boolean ckOthers) {
110  this.ckOthers = ckOthers;
111  }
112 
113  public String getSaleActionValue() {
114  return saleActionValue;
115  }
116 
117  public void setSaleActionValue(String saleActionValue) {
118  this.saleActionValue = saleActionValue;
119  }
120 
122  return saleProspect;
123  }
124 
125  public void setSaleProspect(SaleProspect saleProspect) {
126  this.saleProspect = saleProspect;
127  }
128 
129 }
void setSaleActionValue(String saleActionValue)
void setByParticipant(IContact byParticipant)
void setSaleProspect(SaleProspect saleProspect)
static WhereClause getWhereClause(String[] fields, String value)
Definition: SQLHelper.java:64
void addNamedValue(String name, Object value)