BrightSide Workbench Full Report + Source Code
OrderEdit.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 package org.turro.erp.purchase;
19 
20 import org.turro.elephant.context.Application;
21 import org.turro.erp.db.ErpPU;
22 import org.turro.erp.entity.OrderItem;
23 import org.turro.financials.contract.ProviderCombobox;
24 import org.turro.financials.db.FinancialsPU;
25 import org.turro.financials.entity.Contract;
26 import org.turro.financials.product.MovementButton;
27 import org.turro.zkoss.input.ExpressionInput;
28 import org.turro.zkoss.input.Percentbox;
29 import org.zkoss.zk.ui.event.Event;
30 import org.zkoss.zk.ui.util.GenericForwardComposer;
31 import org.zkoss.zul.*;
32 
37 public class OrderEdit extends GenericForwardComposer {
38 
39  private OrderItem orderItem;
40  private Window oiForm;
41  private Textbox description, docnumber;
42  private Datebox docdate, delivery;
43  private ExpressionInput units, cost, tax;
44  private Percentbox dedication;
45  private ProviderCombobox provider;
46  private Row provrow, costrow, dedicrow;
47  private Label reslabel, resvalue;
48  private MovementButton movbutton;
49 
50  public void onUser(Event event) {
51  orderItem = (OrderItem) event.getData();
52  docdate.setValue(orderItem.getDocumentDate());
53  docnumber.setValue(orderItem.getDocumentNumber());
54  description.setValue(orderItem.getDescription());
55  cost.setValue(orderItem.getCost());
56  tax.setValue(orderItem.getTax());
57  costrow.setVisible(true);
58  units.setValue(orderItem.getUnits());
59  delivery.setValue(orderItem.getDelivery());
60  if(orderItem.getHumanResource() != null) {
61  reslabel.setValue(Application.getString("lHumanResource"));
62  resvalue.setValue(orderItem.getHumanResource().getName());
63  provrow.setVisible(false);
64  dedication.setValue(orderItem.getDedication());
65  dedicrow.setVisible(true);
66  movbutton.setVisible(false);
67  if(!orderItem.getHumanResource().isInternal()) {
68  costrow.setVisible(true);
69  }
70  } else if(orderItem.getResource() != null) {
71  reslabel.setValue(Application.getString("lResource"));
72  resvalue.setValue(orderItem.getResource().getName());
73  provrow.setVisible(false);
74  dedicrow.setVisible(false);
75  movbutton.setVisible(false);
76  if(!orderItem.getResource().isInternal()) {
77  costrow.setVisible(true);
78  }
79  } else {
80  reslabel.setValue(Application.getString("lProduct"));
81  resvalue.setValue(orderItem.getIProduct().getProductName());
82  provider.setObjectValue(new FinancialsPU().find(Contract.class, orderItem.getProviderId()));
83  provrow.setVisible(true);
84  dedicrow.setVisible(false);
85  movbutton.setVisible(true);
86  movbutton.setIProduct(orderItem.getRequiredUsage().getIProduct());
87  costrow.setVisible(true);
88  provider.setReadonly(orderItem.isProviderFixed());
89  }
90  }
91 
92  public void onOK() {
93  onSave();
94  }
95 
96  public void onSave() {
97  orderItem.setDocumentDate(docdate.getValue());
98  orderItem.setDocumentNumber(docnumber.getValue());
99  orderItem.setDescription(description.getValue());
100  orderItem.setUnits(((Number) units.getNumber()).doubleValue());
101  orderItem.setCost(((Number) cost.getNumber()).doubleValue());
102  orderItem.setTax(((Number) tax.getNumber()).doubleValue());
103  orderItem.setDelivery(delivery.getValue());
104  if(orderItem.getHumanResource() != null) {
105  orderItem.setDedication(dedication.getValue());
106  } else if(orderItem.getResource() != null) {
107  orderItem.setDedication(1);
108  } else {
109  orderItem.setDedication(1);
110  orderItem.setProvider(provider.getObjectValue());
111  }
112  new ErpPU().saveObject(orderItem);
113  oiForm.detach();
114  }
115 
116  public void onCancel() {
117  oiForm.detach();
118  }
119 
120  public void onChange$pgprovider() {
121  Contract ctc = provider.getObjectValue();
122  costrow.setVisible(ctc != null);
123  }
124 
125  public void onChange$cost() {
126  if(orderItem.isCostMaximum()) {
127  if(((Number) cost.getNumber()).doubleValue() > orderItem.getMaxCost()) {
128  cost.setValue(orderItem.getMaxCost());
129  }
130  }
131  }
132 
133 }
static String getString(String key)
void setProvider(Contract provider)
Definition: OrderItem.java:341
HumanResource getHumanResource()
Definition: OrderItem.java:157
void setDocumentDate(Date documentDate)
Definition: OrderItem.java:129
void setDescription(String description)
Definition: OrderItem.java:121
void setCost(double cost)
Definition: OrderItem.java:89
void setDocumentNumber(String documentNumber)
Definition: OrderItem.java:145
void setDelivery(Date delivery)
Definition: OrderItem.java:113
void setUnits(double units)
Definition: OrderItem.java:153
RequiredUsage getRequiredUsage()
Definition: OrderItem.java:249
void setDedication(double dedication)
Definition: OrderItem.java:105