BrightSide Workbench Full Report + Source Code
PendingCustomerOrderListbox.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.sales;
20 
21 import org.turro.elephant.context.Application;
22 import org.turro.elephant.db.WhereClause;
23 import org.turro.elephant.util.DateFormats;
24 import org.turro.elephant.util.DecimalFormats;
25 import org.turro.erp.db.ErpPU;
26 import org.turro.erp.entity.CustomerOrder;
27 import org.turro.financials.entity.Contract;
28 import org.turro.zkoss.input.CollectionListbox;
29 import org.zkoss.zul.Listhead;
30 import org.zkoss.zul.Listheader;
31 
36 public class PendingCustomerOrderListbox extends CollectionListbox<CustomerOrder> {
37 
38  private Contract contract;
39 
40  public Contract getContract() {
41  return contract;
42  }
43 
44  public void setContract(Contract contract) {
45  this.contract = contract;
46  updateCollection(new ErpPU().getResultList(createCriteria(contract)));
47  }
48 
49  @Override
50  protected String convertToString(CustomerOrder v) {
51  if(v == null) return null;
52 
53  return v.getDescription() + ITEM_SEPARATOR +
54  DateFormats.formatNull(v.getOrderDate(), true) + SUBITEM_SEPARATOR +
58  }
59 
60  @Override
61  public void afterCompose() {
62  addHeaders();
63  super.afterCompose();
64  }
65 
66  private void addHeaders() {
67  if(getListhead() != null) return;
68  Listhead lh = new Listhead();
69  lh.setSizable(true);
70  lh.appendChild(new Listheader(Application.getString("lDescription"), null, "40%"));
71  lh.appendChild(new Listheader(Application.getString("lDate"), null, "20%"));
72  lh.appendChild(new Listheader(Application.getString("lNumber"), null, "20%"));
73  lh.appendChild(new Listheader(Application.getString("lAmount"), null, "20%"));
74  appendChild(lh);
75  }
76 
77  private WhereClause createCriteria(Contract contract) {
78  WhereClause wc = new WhereClause();
79  wc.addClause("select cu from CustomerOrder as cu");
80  wc.addClause("where not exists (select o from OrderReference as o where o.customerOrder = cu)");
81  if(contract != null) {
82  wc.addClause("and cu.customerId = :idContract");
83  wc.addNamedValue("idContract", contract.getId());
84  }
85  wc.addClause("order by cu.customerId, cu.orderDate, cu.orderId");
86  return wc;
87  }
88 
89 }
static String getString(String key)
static String formatNull(Date d, boolean dateOnly)
static String format(Number value, String pattern)