BrightSide Workbench Full Report + Source Code
sales/CustomerOrderEdit.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.string.Strings;
22 import org.turro.erp.db.ErpPU;
23 import org.turro.erp.entity.CustomerOrder;
24 import org.turro.financials.contract.ContractCombobox;
25 import org.turro.jpa.Dao;
26 import org.turro.zul.frame.Framework;
27 import org.zkoss.zk.ui.Component;
28 import org.zkoss.zk.ui.util.GenericForwardComposer;
29 import org.zkoss.zul.Datebox;
30 import org.zkoss.zul.Textbox;
31 import org.zkoss.zul.Toolbarbutton;
32 
37 public class CustomerOrderEdit extends GenericForwardComposer {
38 
39  private ContractCombobox customer;
40  private Textbox orderId;
41  private Datebox orderDate;
42  private Toolbarbutton save, delete;
43  private CustomerOrderLinesGrid lines;
44 
45  @Override
46  public void doAfterCompose(Component comp) throws Exception {
47  super.doAfterCompose(comp);
48  CustomerOrder customerOrder = lines.getCustomerOrder();
49  customer.setObjectValue(customerOrder.getCustomer());
50  orderId.setValue(customerOrder.getOrderId());
51  orderDate.setValue(customerOrder.getOrderDate());
52  if(customerOrder.getCustomerId() > 0) {
53  customer.setReadonly(true);
54  orderId.setReadonly(true);
55  orderDate.setReadonly(true);
56  }
57  updateButtons();
58  }
59 
60  public void onClick$save() {
61  Dao dao = new ErpPU();
62  for(CustomerOrder co : lines.getValues()) {
63  co.setCustomer(customer.getObjectValue());
64  co.setOrderId(orderId.getValue());
65  co.setOrderDate(orderDate.getValue());
66  dao.saveObject(co);
67  }
69  }
70 
71  public void onClick$delete() {
72  Dao dao = new ErpPU();
73  for(CustomerOrder co : lines.getValues()) {
74  dao.deleteObject(co);
75  }
77  }
78 
79  public void onChange$customer() {
80  updateLines();
81  updateButtons();
82  }
83 
84  public void onChange$orderId() {
85  updateLines();
86  updateButtons();
87  }
88 
89  public void onChange$orderDate() {
90  updateLines();
91  updateButtons();
92  }
93 
94  private void updateLines() {
95  for(CustomerOrder co : lines.getAllValues()) {
96  co.setCustomer(customer.getObjectValue());
97  co.setOrderId(orderId.getValue());
98  co.setOrderDate(orderDate.getValue());
99  lines.setNewValues(co);
100  }
101  }
102 
103  private void updateButtons() {
104  save.setDisabled(!isValid());
105  delete.setDisabled(save.isDisabled());
106  }
107 
108  private boolean isValid() {
109  return customer.getObjectValue() != null &&
110  !Strings.isBlank(orderId.getValue()) &&
111  orderDate.getValue() != null;
112 
113  }
114 }
void setNewValues(CustomerOrder customerOrder)
void deleteObject(Object obj)
Definition: Dao.java:162
static Framework getCurrent()
Definition: Framework.java:203