19 package org.turro.crm.zul.activity;
21 import java.util.Collection;
22 import java.util.HashMap;
23 import org.amic.util.date.CheckDate;
24 import org.turro.action.Contacts;
25 import org.turro.crm.db.CrmPU;
26 import org.turro.crm.entity.Customer;
27 import org.turro.crm.entity.SaleAction;
28 import org.turro.crm.entity.SaleProspect;
29 import org.turro.crm.entity.Vendor;
30 import org.turro.crm.zul.customer.CustomerCombobox;
31 import org.turro.crm.zul.sale.ActionStatus;
32 import org.turro.crm.zul.sale.ActionTypeBox;
33 import org.turro.crm.zul.sale.SaleProspectCombobox;
34 import org.turro.crm.zul.vendor.VendorCombobox;
35 import org.turro.elephant.context.Application;
36 import org.turro.jpa.Dao;
37 import org.turro.plugin.contacts.IContact;
38 import org.turro.vendor.VendorUtil;
39 import org.zkoss.zk.ui.Component;
40 import org.zkoss.zk.ui.Executions;
41 import org.zkoss.zk.ui.util.GenericForwardComposer;
42 import org.zkoss.zul.Chart;
43 import org.zkoss.zul.Datebox;
44 import org.zkoss.zul.SimplePieModel;
56 private Datebox begin, end;
59 private Chart byVendor, byCustomer, byParticipant, byType, byStatus;
87 public void onChange
$end() {
88 activity.
setEnd(end.getValue());
94 super.doAfterCompose(comp);
95 begin.setValue(
new CheckDate().addMonths(-2).getDate());
100 vendor.setDisabled(
true);
102 v = (
Vendor) Executions.getCurrent().getAttribute(
"vendor");
122 private void reload() {
128 private void fillCharts(Collection<SaleAction> saleActions) {
129 Dao dao =
new CrmPU();
130 HashMap<Long, Long> vendorData =
new HashMap<Long, Long>();
131 HashMap<Long, Long> customerData =
new HashMap<Long, Long>();
132 HashMap<String, Long> attData =
new HashMap<String, Long>();
133 HashMap<String, Long> typeData =
new HashMap<String, Long>();
134 HashMap<Integer, Long> statusData =
new HashMap<Integer, Long>();
135 for(SaleAction sa : saleActions) {
136 Long vendorCount = vendorData.get(sa.getVendorProspect().getVendor().getId());
137 vendorCount = vendorCount ==
null ? 1 : vendorCount + 1;
138 vendorData.put(sa.getVendorProspect().getVendor().getId(), vendorCount);
139 Long customerCount = customerData.get(sa.getVendorProspect().getSaleProspect().getCustomer().getId());
140 customerCount = customerCount ==
null ? 1 : customerCount + 1;
141 customerData.put(sa.getVendorProspect().getSaleProspect().getCustomer().getId(), customerCount);
142 for(String attendee : sa.getAttendees()) {
143 Long attCount = attData.get(attendee);
144 attCount = attCount ==
null ? 1 : attCount + 1;
145 attData.put(attendee, attCount);
147 for(String typ : sa.getActionType()) {
148 Long typeCount = typeData.get(typ);
149 typeCount = typeCount ==
null ? 1 : typeCount + 1;
150 typeData.put(typ, typeCount);
152 Long statusCount = statusData.get(sa.getStatus());
153 statusCount = statusCount ==
null ? 1 : statusCount + 1;
154 statusData.put(sa.getStatus(), statusCount);
156 byVendor.setType(Chart.PIE);
157 SimplePieModel vendorModel =
new SimplePieModel();
158 for(Long vid : vendorData.keySet()) {
159 vendorModel.setValue(dao.find(Vendor.class, vid).getName(), vendorData.get(vid));
161 byVendor.setModel(vendorModel);
162 byCustomer.setType(Chart.PIE);
163 SimplePieModel customerModel =
new SimplePieModel();
164 for(Long cid : customerData.keySet()) {
165 customerModel.setValue(dao.find(Customer.class, cid).getName(), customerData.get(cid));
167 byCustomer.setModel(customerModel);
168 byParticipant.setType(Chart.PIE);
169 IContact contact = Contacts.getEmpty();
170 SimplePieModel attModel =
new SimplePieModel();
171 for(String aid : attData.keySet()) {
172 contact.loadById(aid);
173 if(contact.isValid()) {
174 attModel.setValue(contact.getName(), attData.get(aid));
177 byParticipant.setModel(attModel);
178 byType.setType(Chart.PIE);
179 SimplePieModel typeModel =
new SimplePieModel();
180 for(String tid : typeData.keySet()) {
181 typeModel.setValue(tid, typeData.get(tid));
183 byType.setModel(typeModel);
184 byStatus.setType(Chart.PIE);
185 SimplePieModel statusModel =
new SimplePieModel();
186 for(
int sid : statusData.keySet()) {
187 statusModel.setValue(ActionStatus.getStringStatus(sid), statusData.get(sid));
189 byStatus.setModel(statusModel);
void doAfterCompose(Component comp)
void onSelect $customer()
void onSelect $saleProspect()
Collection< SaleAction > getSaleActions()
void setSaleProspect(SaleProspect saleProspect)
void setVendor(Vendor vendor)
void setCustomer(Customer customer)
void setBegin(Date begin)
void setTypes(Collection< String > types)
void setVendor(Vendor vendor)
Collection< String > getTypes()
boolean isInRole(String role)
static Application getApplication()
static Vendor getCurrent()