BrightSide Workbench Full Report + Source Code
CompanyComposer.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.financials.business;
20 
21 import java.util.Date;
22 import java.util.List;
23 import org.amic.util.date.CheckDate;
24 import org.turro.financials.entity.Contract;
25 import org.turro.financials.operating.ContractItemSet;
26 import org.zkoss.zk.ui.Component;
27 import org.zkoss.zk.ui.event.Event;
28 import org.zkoss.zk.ui.select.SelectorComposer;
29 import org.zkoss.zk.ui.select.annotation.Listen;
30 import org.zkoss.zk.ui.select.annotation.Wire;
31 import org.zkoss.zul.Chart;
32 import org.zkoss.zul.Datebox;
33 import org.zkoss.zul.Tab;
34 
39 public class CompanyComposer extends SelectorComposer<Component> {
40 
41  private ContractItemSet items;
42 
43  @Wire("#companyTree")
44  private CompanyTree companyTree;
45 
46  @Wire("#fromDate")
47  private Datebox fromDate;
48 
49  @Wire("#toDate")
50  private Datebox toDate;
51 
52  @Wire("#tabSalesExpenses")
53  private Tab tabSalesExpenses;
54 
55  @Wire("#tabStores")
56  private Tab tabStores;
57 
58  @Wire("#tabParticipants")
59  private Tab tabParticipants;
60 
61  @Wire("#tabSaleStores")
62  private Tab tabSaleStores;
63 
64  @Wire("#tabExpenseStores")
65  private Tab tabExpenseStores;
66 
67  @Wire("#tabProviders")
68  private Tab tabProviders;
69 
70  @Wire("#tabCustomers")
71  private Tab tabCustomers;
72 
73  @Wire("#salesExpenses")
74  private Chart salesExpenses;
75 
76  @Wire("#stores")
77  private Chart stores;
78 
79  @Wire("#participants")
80  private Chart participants;
81 
82  @Wire("#saleStores")
83  private Chart saleStores;
84 
85  @Wire("#expenseStores")
86  private Chart expenseStores;
87 
88  @Wire("#providers")
89  private Chart providers;
90 
91  @Wire("#customers")
92  private Chart customers;
93 
94  @Listen("onSelect = #companyTree; onSelect = #tabSalesExpenses; "
95  + "onSelect = #tabStores; onSelect = #tabParticipants; "
96  + "onSelect = #tabSaleStores; onSelect = #tabExpenseStores; "
97  + "onSelect = #tabCustomers; onSelect = #tabProviders")
98  public void onSelect(Event event) {
99  fillCurrentChart(companyTree.getContracts());
100  }
101 
102  @Override
103  public void doFinally() throws Exception {
104  super.doFinally();
105  Date now = new Date();
106  fromDate.setValue(new CheckDate(now).addMonths(-6).setDay(1).getDate());
107  toDate.setValue(new CheckDate(now).setDay(31).getDate());
108  fillCurrentChart(companyTree.getContracts());
109  }
110 
111  private void fillCurrentChart(List<Contract> contracts) {
112  if(items == null) {
113  items = new ContractItemSet();
114  }
115  items.loadPeriod(fromDate.getValue(), toDate.getValue());
116  if(tabSalesExpenses.isSelected()) {
117  salesExpenses.setType(Chart.LINE);
118  salesExpenses.setEngine(new CompanyChartEngine());
119  salesExpenses.setModel(new CompanyModelWrapper(items).getSalesExpensesModel(contracts));
120 // cchartse.setContent(executeJavaScript("chartse", cchartse.getUuid()));
121  } else if(tabStores.isSelected()) {
122  stores.setType(Chart.BAR);
123  stores.setThreeD(true);
124  stores.setModel(new CompanyModelWrapper(items).getStoresModel(contracts));
125  } else if(tabParticipants.isSelected()) {
126  participants.setType(Chart.BAR);
127  participants.setThreeD(true);
128  participants.setModel(new CompanyModelWrapper(items).getParticipantsModel(contracts));
129  } else if(tabSaleStores.isSelected()) {
130  saleStores.setType(Chart.BAR);
131  saleStores.setThreeD(true);
132  saleStores.setModel(new CompanyModelWrapper(items).getSaleStoresModel(contracts));
133  } else if(tabExpenseStores.isSelected()) {
134  expenseStores.setType(Chart.BAR);
135  expenseStores.setThreeD(true);
136  expenseStores.setModel(new CompanyModelWrapper(items).getExpenseStoresModel(contracts));
137  } else if(tabCustomers.isSelected()) {
138  customers.setType(Chart.BAR);
139  customers.setThreeD(true);
140  customers.setModel(new CompanyModelWrapper(items).getCustomersModel(contracts));
141  } else if(tabProviders.isSelected()) {
142  providers.setType(Chart.BAR);
143  providers.setThreeD(true);
144  providers.setModel(new CompanyModelWrapper(items).getProvidersModel(contracts));
145  }
146  }
147 
148 // public String executeJavaScript(String chartName, String id) {
149 // CategoryModel model = new CompanyModelWrapper(items).getSalesExpensesModel(companyTree.getContracts());
150 // org.turro.charts.Chart chart = new org.turro.charts.Chart(Application.getApplication().getConstructor());
151 // for(Comparable<?> serie : model.getSeries()) {
152 // Series s = chart.addSeries((String) serie);
153 // for(Comparable<?> category : model.getCategories()) {
154 // Data data = s.addData((String) category);
155 // data.setValue(model.getValue(serie, category));
156 // }
157 // break;
158 // }
159 // return
160 //" <script defer=\"true\">\n" +
162 //" var fchar = function() {\n" +
163 //" var vchart = jq(\"<svg id='" + chartName + "' style='width:100%;height:100%;'></svg>\");\n" +
164 //" jq(\"#" + id + "\").append(vchart);\n" +
165 //" var chart = nv.models.pieChart()\n" +
166 //" .x(function(d) { return d.key; })\n" +
167 //" .y(function(d) { return d.y; })\n" +
168 //" .color(d3.scale.category20().range());\n" +
169 //"\n" +
170 //" d3.select(vchart)\n" +
171 //" .datum(" + chart.getPieData() + ")\n" +
172 //" .transition().duration(1200)\n" +
173 //" .call(chart);\n" +
174 //" return chart;\n" +
175 //" };\n" +
176 //" nv.addGraph(fchar);\n" +
178 //" </script>\n" +
179 //"";
180 // //return "f" + chartName + "(" + chart.getPieData() + ");";
181 // }
182 }