BrightSide Workbench Full Report + Source Code
CampaignProspectsGrid.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.zul.sale;
20 
21 import org.turro.command.Command;
22 import org.turro.command.CommandUtil;
23 import org.turro.command.Context;
24 import org.turro.contacts.organigram.TargetFinder;
25 import org.turro.crm.entity.Campaign;
26 import org.turro.crm.entity.CampaignVendor;
27 import org.turro.crm.entity.Customer;
28 import org.turro.crm.entity.CustomerOwner;
29 import org.turro.crm.entity.ProspectStage;
30 import org.turro.crm.entity.ProspectType;
31 import org.turro.crm.entity.SaleAction;
32 import org.turro.crm.entity.SaleProspect;
33 import org.turro.crm.entity.TouchPoint;
34 import org.turro.crm.entity.VendorProspect;
35 import org.turro.crm.zul.customer.CustomerFilter;
36 import org.turro.crm.zul.customer.CustomerFilterGrid;
37 import org.turro.crm.zul.customer.CustomerListbox;
38 import org.turro.i18n.I_;
39 import org.turro.plugin.contacts.IContact;
40 import org.turro.util.Chars;
41 import org.turro.util.PhraseBuilder;
42 import org.turro.zkoss.filter.GenericFilterListbox;
43 import org.turro.zkoss.grid.PagingGrid;
44 import org.turro.zkoss.label.LabelTypes;
45 import org.zkoss.zk.ui.HtmlBasedComponent;
46 import org.zkoss.zk.ui.ext.AfterCompose;
47 import org.zkoss.zul.Column;
48 import org.zkoss.zul.Columns;
49 import org.zkoss.zul.Label;
50 import org.zkoss.zul.Row;
51 import org.zkoss.zul.Rows;
52 import org.zkoss.zul.Vlayout;
53 
58 public class CampaignProspectsGrid extends PagingGrid implements AfterCompose {
59 
60  private Rows rows;
61  private Campaign campaign;
62 
63  public Campaign getCampaign() {
64  return campaign;
65  }
66 
67  public void setCampaign(Campaign campaign) {
68  this.campaign = campaign;
69  }
70 
71  public void addCustomers() {
74 
75  customers.show(I_.get("Customers"), "800px", "600px", new Command() {
76  @Override
77  public Object execute(Context context) {
78  if(customers != null) {
79  for(Customer customer : customers.getObjectValues()) {
80  SaleProspect sp = campaign.customerExists(customer);
81  if(sp == null) {
82  sp = new SaleProspect();
83  sp.setCampaign(campaign);
84  sp.setCustomer(customer);
87  campaign.getSaleProspects().add(sp);
88  }
89  sp.setProspectDate(campaign.getCampaignDate());
90  sp.setClosingDate(campaign.getClosingDate());
91  sp.setDescription(campaign.getDescription());
93  if(campaign.getCampaignVendors().isEmpty()) {
94  for(CustomerOwner co : customer.getOwnedBy()) {
95  sp.addCustomerOwner(co);
96  }
97  } else {
98  for(CampaignVendor cv : campaign.getCampaignVendors()) {
99  if(!cv.isEmpty()) {
100  sp.addCampaignVendor(cv);
101  }
102  }
103  }
104  }
105  refresh();
106  }
107  return null;
108  }
109  });
110  }
111 
112  private void addRows() {
113 
114  setRowCount(campaign.getSaleProspects().size());
115 
116  if(rows != null) removeChild(rows);
117 
118  rows = new Rows();
119  appendChild(rows);
120 
121  for(SaleProspect sp : campaign.getSaleProspects()) {
122  Row row = new Row();
123 
124  HtmlBasedComponent comp = null;
125  if(sp.getId() == 0L) {
126  comp = new Label(sp.getFullDescription());
127  } else {
128  comp = CommandUtil.getLink(sp);
129  }
130  if(comp != null) {
131  rows.appendChild(row);
132  if(sp.getVendorProspects().isEmpty()) {
133  comp.setStyle("color:red;");
134  }
135  row.appendChild(comp);
136  row.setValue(sp);
137 
138  Vlayout vbox = new Vlayout();
139  row.appendChild(vbox);
140  vbox.appendChild(new Label(sp.getSaleActions().size() + ""));
141 
142  vbox = new Vlayout();
143  row.appendChild(vbox);
144  SaleAction sa = sp.getLastSaleAction();
145  if(sa != null) {
146  for(TouchPoint tp : sa.getProcessTouchPoints()) {
147  vbox.appendChild(LabelTypes.getSoftLabel(tp.getName()));
148  }
149  TouchPoint tp = sa.getEndingTouchPoint();
150  if(tp != null) {
151  vbox.appendChild(LabelTypes.getCaptionLabel(tp.getName()));
152  }
153  }
154 
155  PhraseBuilder pb = new PhraseBuilder();
156  for(VendorProspect vp : sp.getVendorProspects()) {
157  pb.addWord(vp.getVendor().getName());
158  pb.addPendingSeparator(", ");
159  }
160  pb.addPendingSeparator(" " + Chars.forward() + " ");
161  for(IContact contact : sp.getIAttendees()) {
162  pb.addWord(contact.getName());
163  pb.addPendingSeparator(", ");
164  }
165  row.appendChild(LabelTypes.getSoftLabel(pb.toString()));
166  }
167 
168  }
169  }
170 
171  public void refresh() {
172  addRows();
173  }
174 
175  @Override
176  public void afterCompose() {
177  addColumns();
178  addRows();
179  }
180 
181  private void addColumns() {
182  Columns cols = new Columns();
183  appendChild(cols);
184 
185  Column col = new Column(I_.get("Sale prospect"));
186  cols.appendChild(col);
187 
188  col = new Column(I_.get("Sale actions"), null, "150px");
189  col.setAlign("right");
190  cols.appendChild(col);
191 
192  col = new Column(I_.get("Touch points"), null, "30%");
193  cols.appendChild(col);
194 
195  col = new Column(I_.get("Participants"), null, "20%");
196  cols.appendChild(col);
197  }
198 
199 }
ContactList find(TargetArray targets)
SaleProspect customerExists(Customer customer)
Definition: Campaign.java:149
Set< CampaignVendor > getCampaignVendors()
Definition: Campaign.java:106
Set< SaleProspect > getSaleProspects()
Definition: Campaign.java:114
void setStage(ProspectStage stage)
void setIAttendees(Collection< IContact > contacts)
void setClosingDate(Date closingDate)
void setCampaign(Campaign campaign)
void addCampaignVendor(CampaignVendor campaignVendor)
void setType(ProspectType type)
void setCustomer(Customer customer)
void setDescription(String description)
void setProspectDate(Date prospectDate)
void addCustomerOwner(CustomerOwner customerOwner)
static String get(String msg)
Definition: I_.java:41
void show(String title, String width, String height, Command command)