BrightSide Workbench Full Report + Source Code
InactiveProspects.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.crm.search;
20 
21 import org.turro.crm.db.CrmPU;
22 import org.turro.crm.entity.ProspectStage;
23 import org.turro.crm.entity.SaleProspect;
24 import org.turro.crm.entity.Vendor;
25 import org.turro.elephant.context.Application;
26 import org.turro.elephant.db.WhereClause;
27 import org.turro.vendor.VendorUtil;
28 
33 public class InactiveProspects {
34 
35  public InactiveProspects() {
36  }
37 
38  public java.util.List<SaleProspect> getObjectValues(Vendor vendor) {
39  return new CrmPU().getResultList(createCriteria(vendor));
40  }
41 
43  WhereClause wc = new WhereClause();
44  wc.addClause("select distinct salep from SaleProspect as salep");
45  if(!Application.getApplication().isInRole("sale-prospect:all")) {
46  vendor = vendor == null ? VendorUtil.getCurrent() : vendor;
47  if(vendor == null) {
48  wc.addClause("where 1=2");
49  return wc;
50  }
51  }
52  if(vendor != null) {
53  wc.addClause("left join salep.vendorProspects vendorp");
54  wc.addClause("left join salep.customer.ownedBy vendoro");
55  wc.addClause("where (vendorp.vendor = :vendorlimp");
56  wc.addClause("or vendoro.vendor = :vendorlimo)");
57  wc.addNamedValue("vendorlimp", vendor);
58  wc.addNamedValue("vendorlimo", vendor);
59  } else {
60  wc.addClause("where 1=1");
61  }
62  wc.addClause("and salep.stage <> :close_won");
63  wc.addNamedValue("close_won", ProspectStage.CLOSED_WON);
64  wc.addClause("and salep.stage <> :close_lost");
65  wc.addNamedValue("close_lost", ProspectStage.CLOSED_LOST);
66  wc.addClause("and not exists (");
67  wc.addClause("select sa from SaleAction sa");
68  wc.addClause("where sa.vendorProspect.saleProspect = salep");
69  wc.addClause("and sa.status = 0");
70  wc.addClause(")");
71  wc.addClause("order by salep.prospectDate");
72  return wc;
73  }
74 
75 }
java.util.List< SaleProspect > getObjectValues(Vendor vendor)
WhereClause createCriteria(Vendor vendor)
void addNamedValue(String name, Object value)
static Vendor getCurrent()
Definition: VendorUtil.java:32