19 package org.turro.crm.zul.activity;
21 import java.text.DateFormat;
22 import java.util.Collection;
23 import java.util.Date;
24 import org.amic.util.date.DateFormats;
25 import org.turro.contacts.zul.label.ContactInfo;
26 import org.turro.crm.db.CrmPU;
27 import org.turro.crm.entity.Customer;
28 import org.turro.crm.entity.SaleAction;
29 import org.turro.crm.entity.SaleProspect;
30 import org.turro.crm.entity.TouchPoint;
31 import org.turro.crm.entity.Vendor;
32 import org.turro.crm.zul.sale.ActionStatus;
33 import org.turro.elephant.context.Application;
34 import org.turro.elephant.db.SQLHelper;
35 import org.turro.elephant.db.WhereClause;
36 import org.turro.elephant.util.DurationFormats;
37 import org.turro.i18n.I_;
38 import org.turro.jpa.Dao;
39 import org.turro.zkoss.grid.GroupExtended;
40 import org.turro.zkoss.grid.PagingGrid;
41 import org.turro.zkoss.label.LabelTypes;
42 import org.turro.zkoss.label.PreLabel;
43 import org.zkoss.zk.ui.ext.AfterCompose;
44 import org.zkoss.zul.Column;
45 import org.zkoss.zul.Columns;
46 import org.zkoss.zul.Group;
47 import org.zkoss.zul.Hlayout;
48 import org.zkoss.zul.Label;
49 import org.zkoss.zul.Row;
50 import org.zkoss.zul.Rows;
51 import org.zkoss.zul.Space;
52 import org.zkoss.zul.Vlayout;
63 private Collection<String> types, attendees;
64 private Date begin, end;
65 private Collection<SaleAction> saleActions;
72 this.customer = customer;
80 this.saleProspect = saleProspect;
95 public void setTypes(Collection<String> types) {
104 this.attendees = attendees;
139 private void addRows() {
140 saleActions = getActivity();
142 Rows rows =
new Rows();
148 if(lastSaleProspect ==
null || sa.getVendorProspect().getSaleProspect().getId() != lastSaleProspect.
getId()) {
149 lastSaleProspect = sa.getVendorProspect().getSaleProspect();
151 rows.appendChild(group);
154 row.setValign(
"top");
155 rows.appendChild(row);
156 Vlayout vbox =
new Vlayout();
157 Hlayout hbox =
new Hlayout();
158 hbox.setSpacing(
"10px");
159 hbox.appendChild(
new Label(DateFormats.format(sa.getActionDate(),
160 DateFormat.SHORT, DateFormat.SHORT, Application.getUsedLocale())));
161 hbox.appendChild(LabelTypes.getSoftLabel(DurationFormats.format(sa.getActionDate(), sa.getFinalDate())));
162 for(String actionType : sa.getActionType()) {
163 hbox.appendChild(LabelTypes.getSoftLabel(actionType));
165 hbox.appendChild(LabelTypes.getSoftLabel(ActionStatus.getStringStatus(sa)));
166 vbox.appendChild(hbox);
167 vbox.appendChild(
new Space());
168 vbox.appendChild(
new ContactInfo(sa.getVendorProspect().getVendor().getIdContact()));
169 for(String attendee : sa.getAttendees()) {
170 vbox.appendChild(
new ContactInfo(attendee));
172 row.appendChild(vbox);
173 vbox =
new Vlayout();
174 vbox.appendChild(
new PreLabel(sa.getComment()));
175 vbox.appendChild(
new Space());
176 for(TouchPoint tp : sa.getTouchPoints()) {
177 vbox.appendChild(LabelTypes.getSoftLabel(tp.getName()));
179 row.appendChild(vbox);
185 private void addColumns() {
186 Columns cols =
new Columns();
189 Column col =
new Column(I_.get(
"Participants"),
null,
"40%");
190 cols.appendChild(col);
192 col =
new Column(I_.get(
"Description"),
null,
"60%");
193 cols.appendChild(col);
197 private Collection<SaleAction> getActivity() {
198 Dao dao =
new CrmPU();
199 return dao.getResultList(getCriteria());
202 private WhereClause getCriteria() {
203 WhereClause wc =
new WhereClause();
204 wc.addClause(
"select distinct sa from SaleAction sa");
205 wc.addClause(
"left join sa.vendorProspect vp");
206 wc.addClause(
"left join vp.saleProspect sp");
207 wc.addClause(
"left join sa.actionType at");
208 wc.addClause(
"left join sa.attendees pa");
209 wc.addClause(
"where 1=1");
211 wc.addClause(
"and sa.actionDate >= :begin");
212 wc.addNamedValue(
"begin", begin);
215 wc.addClause(
"and sa.actionDate <= :end");
216 wc.addNamedValue(
"end", end);
218 if(customer !=
null) {
219 wc.addClause(
"and sp.customer = :customer");
220 wc.addNamedValue(
"customer", customer);
223 wc.addClause(
"and vp.vendor = :vendor");
224 wc.addNamedValue(
"vendor", vendor);
226 if(saleProspect !=
null) {
227 wc.addClause(
"and sp = :saleProspect");
228 wc.addNamedValue(
"saleProspect", saleProspect);
230 if(types !=
null && !types.isEmpty()) {
231 wc.addClause(
"and at in (" + SQLHelper.convertToIn(types) +
")");
233 if(attendees !=
null && !attendees.isEmpty()) {
234 wc.addClause(
"and pa in (" + SQLHelper.convertToIn(attendees) +
")");
236 wc.addClause(
"order by sa.actionDate");
String getFullDescription()
void setAttendees(Collection< String > attendees)
Collection< SaleAction > getSaleActions()
void setSaleProspect(SaleProspect saleProspect)
void setVendor(Vendor vendor)
Collection< String > getTypes()
void setCustomer(Customer customer)
void setBegin(Date begin)
void setTypes(Collection< String > types)
Collection< String > getAttendees()
SaleProspect getSaleProspect()
Rows getRows(boolean create)
void setRowCount(int rows)