BrightSide Workbench Full Report + Source Code
CrmSelfSummary.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2012 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.command;
20 
21 import java.util.Collection;
22 import org.turro.annotation.ElephantPlugin;
23 import org.turro.auth.Authentication;
24 import org.turro.crm.db.CrmPU;
25 import org.turro.crm.entity.VendorProspect;
26 import org.turro.crm.zul.menu.CrmMenu;
27 import org.turro.elephant.context.Application;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.util.Images;
30 import org.turro.i18n.I_;
31 import org.turro.jpa.Dao;
32 import org.turro.plugin.command.SelfSummaryPlugin;
33 import org.turro.zkoss.label.LabelTypes;
34 import org.turro.zkoss.layout.GroupboxArrow;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.EventListener;
37 import org.zkoss.zk.ui.event.Events;
38 import org.zkoss.zul.Button;
39 import org.zkoss.zul.Hlayout;
40 import org.zkoss.zul.Image;
41 import org.zkoss.zul.Include;
42 import org.zkoss.zul.Space;
43 
48 @ElephantPlugin
49 public class CrmSelfSummary extends SelfSummaryPlugin {
50 
51  private Collection<VendorProspect> assigned;
52 
53  @Override
54  protected void executePlugin() {
56  assignedSales();
57  if(!assigned.isEmpty()) {
58  GroupboxArrow gba = new GroupboxArrow() {
59  @Override
60  protected void doFillContent() {
61  }
62  };
63  Hlayout hbox = new Hlayout();
64  gba.setCaption(hbox);
65  hbox.setSclass("z-valign-middle");
66  hbox.setValign("middle");
67  hbox.appendChild(new Image(Images.getImage("sale")));
68  hbox.appendChild(LabelTypes.getSoftLabel(I_.get("Sale prospects") + ":"));
69  hbox.appendChild(LabelTypes.getPreLabel(assigned.size() + " " + I_.get("Opened")));
70  hbox.appendChild(new Space());
71  Button visit = new Button(I_.get("Sale actions"));
72  visit.addEventListener(Events.ON_CLICK, new EventListener<Event>() {
73  @Override
74  public void onEvent(Event event) throws Exception {
75  CrmMenu.showSaleActions(null, null);
76  }
77  });
78  hbox.appendChild(visit);
79  Include report = new Include("/WEB-INF/_zul/crm/crmSummary.zul");
80  report.setDynamicProperty("assigned", assigned);
81  gba.appendChild(report);
82  gba.setOpen(false);
83  addResult("crm", gba);
84  }
85  }
86 
87  private void assignedSales() {
88  Dao dao = new CrmPU();
89  WhereClause wc = new WhereClause();
90  wc.addClause("select distinct vendorp from VendorProspect as vendorp");
91  wc.addClause("where vendorp.vendor.idContact = :contact");
92  wc.addClause("and vendorp.saleProspect.closingDate is null");
93  wc.addNamedValue("contact", Authentication.getIContact().getId());
94  assigned = dao.getResultList(wc);
95  }
96 
97 }
Object addResult(String key, Object value)
static String getImage(String image)
Definition: Images.java:36
static String get(String msg)
Definition: I_.java:41
static Label getPreLabel(String value)
Definition: LabelTypes.java:52
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28