BrightSide Workbench Full Report + Source Code
UsageEdit.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.task.usage;
20 
21 import org.turro.erp.aptitude.AptitudeDegreeCombobox;
22 import org.turro.erp.entity.PurchaseMode;
23 import org.turro.erp.entity.RequiredUsage;
24 import org.turro.erp.entity.Resource;
25 import org.turro.erp.humanres.HumanResourceAptitudeCombobox;
26 import org.turro.erp.purchase.PurchaseModeListbox;
27 import org.turro.erp.resource.ResourceCombobox;
28 import org.turro.erp.task.ProductUsageValuation;
29 import org.turro.erp.task.ResourceUsageValuation;
30 import org.turro.erp.task.TaskListbox;
31 import org.turro.financials.contract.ProviderCombobox;
32 import org.turro.financials.entity.Contract;
33 import org.turro.financials.linetype.BillLineTypeListbox;
34 import org.turro.financials.product.IProduct;
35 import org.turro.financials.product.MovementButton;
36 import org.turro.financials.product.ProductExtendedCombobox;
37 import org.turro.financials.view.ViewListbox;
38 import org.turro.hr.humanres.HumanResourceAptitude;
39 import org.turro.zkoss.input.ExpressionInput;
40 import org.turro.zkoss.input.OverrideDouble;
41 import org.turro.zkoss.input.Percentbox;
42 import org.turro.zkoss.layout.GridLayout;
43 import org.zkoss.zk.ui.event.Event;
44 import org.zkoss.zk.ui.util.GenericForwardComposer;
45 import org.zkoss.zul.*;
46 
51 public class UsageEdit extends GenericForwardComposer {
52 
53  private Object object;
54  private Window usageForm;
55  private GridLayout humangroup, productgroup;
56  private HumanResourceAptitudeCombobox hghumanres;
57  private AptitudeDegreeCombobox assesment;
58  private ResourceCombobox hgresource;
59  private TaskListbox task, purchaseTask;
60  private PurchaseModeListbox purchaseMode;
61  private Datebox purchaseDate;
62  private Textbox description;
63  private ExpressionInput hghours, pgquantity, lag;
64  private OverrideDouble cost, price;
65  private Percentbox hgdedication;
66  private ProductExtendedCombobox pgproduct;
67  private ProviderCombobox pgprovider;
68  private Checkbox maximum, fixed, hgvariable;
69  private MovementButton movbutton;
70  private Image wrongapt;
71  private BillLineTypeListbox pgtype;
72  private ViewListbox view;
73 
74  public void onUser(Event event) {
75  object = event.getData();
76  if(object instanceof RequiredUsage) {
77  RequiredUsage ru = (RequiredUsage) object;
79  task.setObjectValue(ru.getTask());
80  purchaseMode.setObjectValue(ru.getPurchaseMode());
81  purchaseDate.setValue(ru.getPurchaseDate());
82  purchaseTask.setWorkOrder(ru.getTask().getOrderReference().getWorkOrder());
83  purchaseTask.setObjectValue(ru.getPurchaseTask());
84  lag.setValue(ru.getPurchaseLag());
85  description.setValue(ru.getDescription());
86  if(ru.isHumanResourceType()) {
87  hghumanres.setTask(ru.getTask());
89  hgresource.setObjectValue(ru.getResource());
90  assesment.setObjectValue(ru.getAptitudeAssesment());
91  hghours.setValue(ru.getUnits());
92  hgdedication.setValue(ru.getDedication());
93  hgvariable.setChecked(ru.isCanChange());
94  } else if(ru.isProductType()) {
95  pgquantity.setValue(ru.getUnits());
96  pgprovider.setObjectValue(ru.getProvider());
97  pgproduct.setContractorId(ru.getProviderId());
98  pgproduct.setObjectValue(ru.getIProduct());
99  fixed.setChecked(ru.isProviderFixed());
100  movbutton.setIProduct(ru.getIProduct());
101  pgtype.setData(ru.getProvider(), ru.getLineTypeId(), ru.getContractPreferenceId());
102  }
103  if(ru.getView() == null) {
105  } else {
106  view.setObjectValue(ru.getView());
107  }
108  cost.setValue(ru.getCost());
110  cost.updateStatus();
111  maximum.setChecked(ru.isCostMaximum());
112  price.setValue(ru.getPrice());
113  price.setEstimated(ru.getUnitPrice());
114  price.updateStatus();
115  humangroup.setVisible(ru.isHumanResourceType());
116  productgroup.setVisible(ru.isProductType());
117  }
118  onChange$hgresource();
119  onSelect$purchaseMode();
120  }
121 
122  public void onOK() {
123  onSave();
124  }
125 
126  public void onSave() {
127  if(object instanceof RequiredUsage) {
128  RequiredUsage ru = (RequiredUsage) object;
129  ru.setTask(task.getObjectValue());
130  ru.setPurchaseMode(purchaseMode.getObjectValue());
131  ru.setPurchaseDate(purchaseDate.getValue());
132  ru.setPurchaseTask(purchaseTask.getObjectValue());
133  ru.setPurchaseLag(((Number) lag.getNumber()).doubleValue());
134  ru.setDescription(description.getValue());
135  if(ru.isHumanResourceType()) {
136  ru.setHumanResourceAptitude(hghumanres.getObjectValue());
137  ru.setResource(hgresource.getObjectValue());
138  ru.setAptitudeAssesment(assesment.getObjectValue());
139  ru.setUnits(((Number) hghours.getNumber()).doubleValue());
140  ru.setDedication(hgdedication.getValue());
141  ru.setCanChange(hgvariable.isChecked());
142  } else if(ru.isProductType()) {
143  ru.setUnits(((Number) pgquantity.getNumber()).doubleValue());
144  ru.setProvider(pgprovider.getObjectValue());
145  ru.setIProduct(pgproduct.getObjectValue());
146  ru.setProviderFixed(fixed.isChecked());
147  if(pgtype.getObjectValue() != null) {
148  ru.setLineTypeId(pgtype.getObjectValue().getId());
149  ru.setContractPreferenceId(pgtype.getObjectValue().getContractPreference().getId());
150  } else {
151  ru.setLineTypeId(0L);
153  }
154  }
155  if(!cost.isCalculated() || maximum.isChecked()) {
156  ru.setCost(cost.getValue());
157  ru.setCostMaximum(maximum.isChecked());
158  }
159  if(!price.isCalculated()) {
160  ru.setPrice(price.getValue());
161  }
162  }
163  usageForm.detach();
164  }
165 
166  public void onCancel() {
167  usageForm.detach();
168  }
169 
170  public void onSelect$task() {
171  hghumanres.setTask(task.getObjectValue());
172  }
173 
174  public void onChange$hghumanres() {
175  onChange$hgresource();
176  }
177 
178  public void onChange$hgresource() {
179  HumanResourceAptitude hra = hghumanres.getObjectValue();
180  Resource ra = hgresource.getObjectValue();
181  wrongapt.setVisible(false);
182  if(hra != null && hra.getAptitudeDegree() != null &&
183  ra != null && ra.getAptitudeDegrees() != null) {
184  wrongapt.setVisible(!hra.getAptitudeDegree().isIn(ra.getAptitudeDegrees()));
185  }
186  if(hra != null) {
188  hra.getHumanResource(), ra, hra.getAptitudeDegree(),
189  assesment.getObjectValue(), hgdedication.getValue());
190  cost.setValue(ruv.getUnitCost());
191  cost.setEstimated(ruv.getUnitCost());
192  cost.updateStatus();
193  price.setValue(ruv.getUnitPrice());
194  price.setEstimated(ruv.getUnitPrice());
195  price.updateStatus();
196  }
197  }
198 
199  public void onChange$pgprovider() {
200  Contract ctc = pgprovider.getObjectValue();
201  if(ctc != null) {
202  pgproduct.setContractorId(ctc.getId());
203  pgtype.setData(ctc, 0, 0);
204  }
205  }
206 
207  public void onChange$pgproduct() {
208  IProduct product = pgproduct.getObjectValue();
209  movbutton.setIProduct(product);
210  if(product != null) {
211  if(product.getProductByContractor() != null) {
212  Contract ctc = product.getProductByContractor().getContract();
213  pgprovider.setObjectValue(ctc);
214  }
215  ProductUsageValuation puv = new ProductUsageValuation(product);
216  cost.setValue(puv.getUnitCost());
217  cost.setEstimated(puv.getUnitCost());
218  cost.updateStatus();
219  price.setValue(puv.getUnitPrice());
220  price.setEstimated(puv.getUnitPrice());
221  price.updateStatus();
222  }
223  }
224 
225  public void onSelect$purchaseMode() {
226  purchaseDate.setVisible(purchaseMode.getObjectValue().equals(PurchaseMode.PURCHASE_ON_DATE));
227  purchaseTask.setVisible(purchaseMode.getObjectValue().equals(PurchaseMode.PURCHASE_ON_TASK_START));
228  }
229 
230 }
231 
boolean isIn(Collection< AptitudeDegree > aptitudeDegrees)
void setResource(Resource resource)
void setCostMaximum(boolean costMaximum)
void setHumanResourceAptitude(HumanResourceAptitude hro)
void setProviderFixed(boolean providerFixed)
void setPurchaseDate(Date purchaseDate)
void setPurchaseMode(PurchaseMode purchaseMode)
void setAptitudeAssesment(AptitudeDegree aptitudeAssesment)
HumanResourceAptitude getHumanResourceAptitude()
void setDedication(double dedication)
void setPurchaseLag(double purchaseLag)
void setDescription(String description)
void setContractPreferenceId(long contractPreferenceId)
void setIProduct(IProduct product)
void setLineTypeId(long lineTypeId)
void setPurchaseTask(Task purchaseTask)
void setProvider(Contract provider)
void setCanChange(boolean canChange)
Set< AptitudeDegree > getAptitudeDegrees()
Definition: Resource.java:98
void setData(Contract contract, long lineTypeId, long contractPreferenceId)
ProductByContractor getProductByContractor()