BrightSide Workbench Full Report + Source Code
ErpCustomerSummary.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.erp.command;
20 
21 import java.util.Collection;
22 import org.turro.annotation.ElephantPlugin;
23 import org.turro.collections.ItemOf;
24 import org.turro.collections.SetOf;
25 import org.turro.plugin.command.CustomerSummaryPlugin;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.db.SQLHelper;
28 import org.turro.elephant.db.WhereClause;
29 import org.turro.elephant.util.Images;
30 import org.turro.erp.db.ErpPU;
31 import org.turro.erp.entity.WorkOrder;
32 import org.turro.financials.contract.logic.ContractWrapper;
33 import org.turro.financials.entity.Contract;
34 import org.turro.zkoss.label.LabelTypes;
35 import org.turro.zkoss.layout.GroupboxArrow;
36 import org.zkoss.zul.Hlayout;
37 import org.zkoss.zul.Image;
38 import org.zkoss.zul.Include;
39 
44 @ElephantPlugin
46 
47  private Collection<WorkOrder> active;
48 
49  @Override
50  protected void executePlugin() {
52  activeWorkOrders();
53  if(!active.isEmpty()) {
54  GroupboxArrow gba = new GroupboxArrow() {
55  @Override
56  protected void doFillContent() {
57  }
58  };
59  Hlayout hbox = new Hlayout();
60  gba.setCaption(hbox);
61  hbox.setSclass("z-valign-middle");
62  hbox.setValign("middle");
63  hbox.appendChild(new Image(Images.getImage("workorder")));
64  hbox.appendChild(LabelTypes.getSoftLabel(Application.getString("lWorkOrders") + ":"));
65  hbox.appendChild(LabelTypes.getPreLabel(active.size() + ""));
66  Include report = new Include("/WEB-INF/_zul/erp/sales/customerSummary.zul");
67  report.setDynamicProperty("active", active);
68  gba.appendChild(report);
69  gba.setOpen(false);
70  addResult("erp", gba);
71  }
72  }
73 
74  private void activeWorkOrders() {
75  Collection<Contract> contracts = ContractWrapper.getContracts(contact);
76  String inCtc = SQLHelper.convertToIn(new SetOf<Contract, Long>(contracts, new ItemOf<Contract, Long>() {
77  @Override
78  public Long getFrom(Contract e) {
79  return e.getId();
80  }
81  }));
82  WhereClause wc = new WhereClause();
83  wc.addClause("select distinct workord from WorkOrder as workord");
84  wc.addClause("where workord.contractId in (" + inCtc + ")");
85  active = new ErpPU().getResultList(wc);
86  }
87 
88 }
Object addResult(String key, Object value)
static String getString(String key)
static String convertToIn(Collection collection)
Definition: SQLHelper.java:43
static String getImage(String image)
Definition: Images.java:36
static Label getPreLabel(String value)
Definition: LabelTypes.java:52
static Label getSoftLabel(String value)
Definition: LabelTypes.java:28