19 package org.turro.erp.purchase;
21 import java.util.Date;
22 import org.turro.string.Strings;
23 import org.turro.erp.db.ErpPU;
24 import org.turro.erp.entity.OrderItem;
25 import org.turro.erp.entity.PurchaseMode;
26 import org.turro.erp.entity.ReceiptItem;
27 import org.turro.erp.entity.RequiredUsage;
28 import org.turro.financials.contract.ProviderCombobox;
29 import org.turro.financials.entity.Contract;
30 import org.turro.jpa.Dao;
31 import org.turro.zkoss.grid.EditableCell;
32 import org.zkoss.zk.ui.Component;
33 import org.zkoss.zk.ui.util.GenericForwardComposer;
34 import org.zkoss.zul.Button;
35 import org.zkoss.zul.Datebox;
36 import org.zkoss.zul.Label;
37 import org.zkoss.zul.Textbox;
47 private Textbox docnumber;
48 private Datebox docdate;
49 private Button doccreate;
50 private Label lWorkOrder, lOrderReference;
56 createReceipt(provider.
getObjectValue(), docnumber.getValue(), docdate.getValue(), hi);
58 createOrder(provider.
getObjectValue(), docnumber.getValue(), docdate.getValue(), hi);
94 private void updateButton() {
95 doccreate.setDisabled(
97 Strings.isEmpty(docnumber.getValue()) ||
98 docdate.getValue() ==
null ||
105 super.doAfterCompose(comp);
106 docdate.setValue(
new Date());
107 doccreate.setDisabled(
true);
110 private void createOrder(
Contract provider, String documentNumber, Date documentDate,
ProductsItem pi) {
116 "select pu from RequiredUsage pu " +
118 "and description = ?",
122 "select pu from RequiredUsage pu " +
129 ru =
new RequiredUsage();
136 ru = dao.saveObject(ru);
141 dro.setDocumentNumber(
"*" + documentNumber);
142 dro.setProviderId(provider.
getId());
147 private void createReceipt(Contract provider, String documentNumber, Date documentDate, ProductsItem pi) {
148 Dao dao =
new ErpPU();
151 if(pi.getIProduct().isUncoded()) {
152 oi = (OrderItem) dao.getSingleResultOrNull(
153 "select dro from OrderItem dro " +
154 "where requiredUsage.task = ? " +
155 "and providerId = ? " +
156 "and requiredUsage.description = ?",
157 new Object[] { pi.getTask(), provider.getId(), pi.getIProduct().getProductCodeStr() });
159 oi = (OrderItem) dao.getSingleResultOrNull(
160 "select dro from OrderItem dro " +
161 "where requiredUsage.task = ? " +
162 "and providerId = ? " +
163 "and requiredUsage.productId = ?",
164 new Object[] { pi.getTask(), provider.getId(), pi.getIProduct().getProductId() });
169 if(pi.getIProduct().isUncoded()) {
170 pu = (RequiredUsage) dao.getSingleResultOrNull(
171 "select pu from RequiredUsage pu " +
172 "where requiredUsage.task = ? " +
173 "and description = ?",
174 new Object[] { pi.getTask(), pi.getIProduct().getProductCodeStr() });
176 pu = (RequiredUsage) dao.getSingleResultOrNull(
177 "select pu from RequiredUsage pu " +
178 "where requiredUsage.task = ? " +
180 new Object[] { pi.getTask(), pi.getIProduct().getProductId() });
184 pu =
new RequiredUsage();
185 pu.setTask(pi.getTask());
186 pu.getTask().getRequiredUsages().add(pu);
187 pu.setPurchaseMode(PurchaseMode.PURCHASE_IMMEDIATELY);
188 pu.setPurchaseLag(0);
189 pu.setIProduct(pi.getIProduct());
190 pu.setUnits(pi.getUnits());
191 pu = dao.saveObject(pu);
194 oi = pu.startOrder();
195 oi.setDocumentDate(documentDate);
196 oi.setDocumentNumber(
"*" + documentNumber);
197 oi.setProviderId(provider.getId());
201 ReceiptItem ri = oi.startReceipt(
null);
203 if(ri.getOrderItem().getRelated() !=
null) {
204 ri = ri.getOrderItem().getRelated().getReceiptItems().iterator().next();
void setDocumentDate(Date documentDate)
void setPurchaseMode(PurchaseMode purchaseMode)
void setUnits(double units)
void setPurchaseLag(double purchaseLag)
void setIProduct(IProduct product)
Set< RequiredUsage > getRequiredUsages()
String getSomeDescription()
void onChange $provider()
void doAfterCompose(Component comp)
void onClick $doccreate()
void onChange $productsGrid()
void onChanging $productsGrid()
void onChange $docnumber()
OrderReference getOrderReference()
Object getSingleResultOrNull(SqlClause sc)
EditableCell getCurrentCell()
String getProductCodeStr()