diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java index e302895d53..7d971758fa 100644 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java +++ b/zkwebui/WEB-INF/src/org/adempiere/webui/util/ADClassNameMap.java @@ -14,7 +14,6 @@ public class ADClassNameMap { map.put("org.compiere.process.InvoicePrint", "org.adempiere.webui.process.InvoicePrint"); map.put("org.compiere.process.CacheReset", "org.adempiere.webui.process.CacheReset"); map.put("org.adempiere.apps.graph.ViewPI", "org.adempiere.webui.apps.graph.WViewPI"); - map.put("org.eevolution.form.VOrderReceiptIssue", "org.adempiere.webui.window.WOrderReceiptIssue"); } /** diff --git a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WOrderReceiptIssue.java b/zkwebui/WEB-INF/src/org/adempiere/webui/window/WOrderReceiptIssue.java deleted file mode 100644 index ede5de5fbe..0000000000 --- a/zkwebui/WEB-INF/src/org/adempiere/webui/window/WOrderReceiptIssue.java +++ /dev/null @@ -1,1490 +0,0 @@ -/****************************************************************************** - * Product: Adempiere ERP & CRM Smart Business Solution * - * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it * - * under the terms version 2 of the GNU General Public License as published * - * by the Free Software Foundation. This program is distributed in the hope * - * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * - * See the GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License along * - * with this program; if not, write to the Free Software Foundation, Inc., * - * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * - * For the text or an alternative of this public license, you may reach us * - * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA * - * or via info@compiere.org or http://www.compiere.org/license.html * - *****************************************************************************/ -package org.adempiere.webui.window; - - -import java.io.Serializable; -import java.math.BigDecimal; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Properties; - -import org.adempiere.exceptions.AdempiereException; -import org.adempiere.exceptions.DBException; -import org.adempiere.webui.component.Button; -import org.adempiere.webui.component.Combobox; -import org.adempiere.webui.component.Grid; -import org.adempiere.webui.component.GridFactory; -import org.adempiere.webui.component.Label; -import org.adempiere.webui.component.ListboxFactory; -import org.adempiere.webui.component.Panel; -import org.adempiere.webui.component.Rows; -import org.adempiere.webui.component.Tab; -import org.adempiere.webui.component.Tabbox; -import org.adempiere.webui.component.Tabs; -import org.adempiere.webui.component.Textbox; -import org.adempiere.webui.component.WListbox; -import org.adempiere.webui.editor.WDateEditor; -import org.adempiere.webui.editor.WLocatorEditor; -import org.adempiere.webui.editor.WNumberEditor; -import org.adempiere.webui.editor.WPAttributeEditor; -import org.adempiere.webui.editor.WSearchEditor; -import org.adempiere.webui.event.ValueChangeEvent; -import org.adempiere.webui.event.ValueChangeListener; -import org.adempiere.webui.event.WTableModelEvent; -import org.adempiere.webui.event.WTableModelListener; -import org.adempiere.webui.panel.ADForm; -import org.adempiere.webui.panel.CustomForm; -import org.adempiere.webui.panel.IFormController; -import org.adempiere.webui.session.SessionManager; -import org.compiere.minigrid.ColumnInfo; -import org.compiere.minigrid.IDColumn; -import org.compiere.minigrid.IMiniTable; -import org.compiere.model.GridField; -import org.compiere.model.GridFieldVO; -import org.compiere.model.MAttributeSetInstance; -import org.compiere.model.MColumn; -import org.compiere.model.MLocator; -import org.compiere.model.MLocatorLookup; -import org.compiere.model.MLookup; -import org.compiere.model.MLookupFactory; -import org.compiere.model.MProduct; -import org.compiere.model.MStorage; -import org.compiere.model.MTab; -import org.compiere.model.MWindow; -import org.compiere.util.DB; -import org.compiere.util.DisplayType; -import org.compiere.util.Env; -import org.compiere.util.KeyNamePair; -import org.compiere.util.Language; -import org.compiere.util.Msg; -import org.compiere.util.Trx; -import org.compiere.util.TrxRunnable; -import org.eevolution.model.MPPOrder; -import org.eevolution.model.MPPOrderBOMLine; -import org.eevolution.model.MPPProductBOMLine; -import org.zkoss.zk.ui.event.Event; -import org.zkoss.zk.ui.event.EventListener; -import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.util.Clients; -import org.zkoss.zkex.zul.Borderlayout; -import org.zkoss.zkex.zul.Center; -import org.zkoss.zkex.zul.North; -import org.zkoss.zkex.zul.South; -import org.zkoss.zul.Html; -import org.zkoss.zul.Messagebox; -import org.zkoss.zul.Row; -import org.zkoss.zul.Space; -import org.zkoss.zul.Tabpanel; -import org.zkoss.zul.Tabpanels; - -/** - * @author Cristina Ghita, www.arhipac.ro - * @author Adi Takacs, www.arhipac.ro - */ - -public class WOrderReceiptIssue implements IFormController, EventListener, -ValueChangeListener,Serializable,WTableModelListener -{ - - private static final long serialVersionUID = 1544662359277562456L; - - /** Window No */ - private int m_WindowNo = 0; - private String m_sql; - private MPPOrder m_PP_order = null; - - private Panel Generate = new Panel(); - private Panel PanelBottom = new Panel(); - private Panel mainPanel = new Panel(); - private Panel northPanel = new Panel(); - private Button Process = new Button(); - - - - private Label attributeLabel = new Label(); - private Label orderedQtyLabel = new Label(); - private Label deliveredQtyLabel = new Label(); - private Label openQtyLabel = new Label(); - private Label orderLabel = new Label(); - private Label toDeliverQtyLabel = new Label(); - private Label movementDateLabel = new Label(); - private Label rejectQtyLabel = new Label(); - private Label resourceLabel = new Label(); - - - private CustomForm form = new CustomForm(); - private Borderlayout ReceiptIssueOrder = new Borderlayout(); - private Tabbox TabsReceiptsIssue = new Tabbox(); - private Html info = new Html(); - private Grid fieldGrid = GridFactory.newGridLayout(); - private WPAttributeEditor attribute = null; - - private Label warehouseLabel = new Label(); - private Label scrapQtyLabel = new Label(); - private Label productLabel = new Label(Msg.translate(Env.getCtx(),"M_Product_ID")); - private Label uomLabel = new Label(Msg.translate(Env.getCtx(), "C_UOM_ID")); - private Label uomorderLabel = new Label(Msg.translate(Env.getCtx(), "Altert UOM")); - private Label locatorLabel = new Label(Msg.translate(Env.getCtx(), "M_Locator_ID")); - private Label backflushGroupLabel = new Label(Msg.translate(Env.getCtx(), "BackflushGroup")); - private Label labelcombo = new Label(Msg.translate(Env.getCtx(), "DeliveryRule")); - private Label QtyBatchsLabel = new Label(); - private Label QtyBatchSizeLabel = new Label(); - - private Textbox backflushGroup = new Textbox(); - - private WNumberEditor orderedQtyField = new WNumberEditor("QtyOrdered", false, false, false, DisplayType.Quantity, "QtyOrdered"); - private WNumberEditor deliveredQtyField = new WNumberEditor("QtyDelivered", false, false, false, DisplayType.Quantity, "QtyDelivered"); - private WNumberEditor openQtyField = new WNumberEditor("QtyOpen", false, false, false, DisplayType.Quantity, "QtyOpen"); - private WNumberEditor toDeliverQty = new WNumberEditor("QtyToDeliver", true, false, true, DisplayType.Quantity, "QtyToDeliver"); - private WNumberEditor rejectQty = new WNumberEditor("Qtyreject", false, false, true, DisplayType.Quantity, "QtyReject"); - private WNumberEditor scrapQtyField = new WNumberEditor("Qtyscrap", false, false, true, DisplayType.Quantity, "Qtyscrap"); - private WNumberEditor qtyBatchsField = new WNumberEditor("QtyBatchs", false, false, false, DisplayType.Quantity, "QtyBatchs"); - private WNumberEditor qtyBatchSizeField = new WNumberEditor("QtyBatchSize", false, false, false, DisplayType.Quantity, "QtyBatchSize"); - - private WSearchEditor orderField = null; - private WSearchEditor resourceField = null; - private WSearchEditor warehouseField = null; - private WSearchEditor productField = null; - private WSearchEditor uomField = null; - private WSearchEditor uomorderField = null; - - private WListbox issue = ListboxFactory.newDataTable(); - private WDateEditor movementDateField = new WDateEditor("MovementDate", true, false, true, "MovementDate"); - - private WLocatorEditor locatorField = null; - - private Combobox pickcombo = new Combobox(); - - - /** - * Initialize Panel - * @param WindowNo window - * @param frame frame - */ - - public WOrderReceiptIssue() - { - Env.setContext(Env.getCtx(), form.getWindowNo(), "IsSOTrx", "Y"); - try - { - // UI - fillPicks(); - jbInit(); - // - dynInit(); - pickcombo.addEventListener(Events.ON_CHANGE, this); - - } - catch (Exception e) - { - throw new AdempiereException(e); - } - } // init - - /** - * Fill Picks - * Column_ID from C_Order - * This is only run as part of the windows initialization process - * @throws Exception if Lookups cannot be initialized - */ - private void fillPicks() throws Exception - { - - Properties ctx = Env.getCtx(); - Language language = Language.getLoginLanguage(); // Base Language - MLookup orderLookup = MLookupFactory.get(ctx, m_WindowNo, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_PP_Order_ID), - DisplayType.Search, language, "PP_Order_ID", 0, false, - "PP_Order.DocStatus = '" + MPPOrder.DOCACTION_Complete + "'"); - - orderField = new WSearchEditor(MPPOrder.COLUMNNAME_PP_Order_ID, false, false, true, orderLookup); - orderField.addValueChangeListener(this); - - MLookup resourceLookup = MLookupFactory.get(ctx, m_WindowNo, 0, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_S_Resource_ID), - DisplayType.TableDir); - resourceField = new WSearchEditor(MPPOrder.COLUMNNAME_S_Resource_ID, false, false, false, resourceLookup); - - MLookup warehouseLookup = MLookupFactory.get(ctx, m_WindowNo, 0, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Warehouse_ID), - DisplayType.TableDir); - warehouseField = new WSearchEditor(MPPOrder.COLUMNNAME_M_Warehouse_ID, false, false, false, warehouseLookup); - - MLookup productLookup = MLookupFactory.get(ctx, m_WindowNo, 0, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_Product_ID), - DisplayType.TableDir); - productField = new WSearchEditor(MPPOrder.COLUMNNAME_M_Product_ID, false, false, false, productLookup); - - MLookup uomLookup = MLookupFactory.get(ctx, m_WindowNo, 0, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), - DisplayType.TableDir); - uomField = new WSearchEditor(MPPOrder.COLUMNNAME_C_UOM_ID, false, false, false, uomLookup); - - MLookup uomOrderLookup = MLookupFactory.get(ctx, m_WindowNo, 0, - MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_C_UOM_ID), - DisplayType.TableDir); - uomorderField = new WSearchEditor(MPPOrder.COLUMNNAME_C_UOM_ID, false, false, false, uomOrderLookup); - - MLocatorLookup locatorL = new MLocatorLookup(ctx, m_WindowNo); - locatorField = new WLocatorEditor(MLocator.COLUMNNAME_M_Locator_ID, true, false, true, locatorL, m_WindowNo); - - - // Tab, Window - int m_Window = MWindow.getWindow_ID("Manufacturing Order"); - GridFieldVO vo = GridFieldVO.createStdField(ctx, m_WindowNo, 0,m_Window, MTab.getTab_ID(m_Window, "Order"), - false, false, false); - vo.AD_Column_ID = MColumn.getColumn_ID(MPPOrder.Table_Name, MPPOrder.COLUMNNAME_M_AttributeSetInstance_ID); - - GridField field = new GridField(vo); - // M_AttributeSetInstance_ID - attribute = new WPAttributeEditor(field.getGridTab(),field); - attribute.setValue(0); - // 4Layers - Further init - scrapQtyField.setValue(Env.ZERO); - rejectQty.setValue(Env.ZERO); - // 4Layers - end - pickcombo.appendItem(Msg.translate(Env.getCtx(),"IsBackflush"), 1); - pickcombo.appendItem(Msg.translate(Env.getCtx(),"OnlyIssue"),2); - pickcombo.appendItem(Msg.translate(Env.getCtx(),"OnlyReceipt"),3); - pickcombo.addEventListener(Events.ON_CHANGE, this); - Process.addActionListener(this); - toDeliverQty.addValueChangeListener(this); - scrapQtyField.addValueChangeListener(this); - } // fillPicks - - /** - * Static Init. - * Places static visual elements into the window. - * This is only run as part of the windows initialization process - *
- * mainPanel - * northPanel - * centerPanel - * xMatched - * xPanel - * xMathedTo - * southPanel - *- * @throws Exception - */ - private void jbInit() throws Exception - { - Center center = new Center(); - South south = new South(); - North north = new North(); - form.appendChild(mainPanel); - - mainPanel.appendChild(TabsReceiptsIssue); - mainPanel.setStyle("width: 100%; height: 100%; padding: 0; margin: 0"); - ReceiptIssueOrder.setWidth("100%"); - ReceiptIssueOrder.setHeight("99%"); - ReceiptIssueOrder.appendChild(north); - north.appendChild(northPanel); - northPanel.appendChild(fieldGrid); - orderLabel.setText(Msg.translate(Env.getCtx(), "PP_Order_ID")); - Rows tmpRows = fieldGrid.newRows(); - - // 1st - Row tmpRow = tmpRows.newRow(); - - tmpRow.appendChild(orderLabel); - tmpRow.appendChild(orderField.getComponent()); - resourceLabel.setText(Msg.translate(Env.getCtx(), "S_Resource_ID")); - tmpRow.appendChild(resourceLabel); - tmpRow.appendChild(resourceField.getComponent()); - warehouseLabel.setText(Msg.translate(Env.getCtx(), "M_Warehouse_ID")); - tmpRow.appendChild(warehouseLabel); - tmpRow.appendChild(warehouseField.getComponent()); - - // Product 2nd - tmpRow = tmpRows.newRow(); - - tmpRow.appendChild(productLabel); - tmpRow.appendChild(productField.getComponent()); - tmpRow.appendChild(uomLabel); - tmpRow.appendChild(uomField.getComponent()); - tmpRow.appendChild(uomorderLabel); - tmpRow.appendChild(uomorderField.getComponent()); - - tmpRow = tmpRows.newRow(); - - orderedQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyOrdered")); - tmpRow.appendChild(orderedQtyLabel); - tmpRow.appendChild(orderedQtyField.getComponent()); - deliveredQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyDelivered")); - tmpRow.appendChild(deliveredQtyLabel); - tmpRow.appendChild(deliveredQtyField.getComponent()); - openQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyOpen")); - tmpRow.appendChild(openQtyLabel); - tmpRow.appendChild(openQtyField.getComponent()); - //3rd - tmpRow = tmpRows.newRow(); - - tmpRow.appendChild(productLabel); - tmpRow.appendChild(productField.getComponent()); - tmpRow.appendChild(uomLabel); - tmpRow.appendChild(uomField.getComponent()); - tmpRow.appendChild(uomorderLabel); - tmpRow.appendChild(uomorderField.getComponent()); - //4th - tmpRow = tmpRows.newRow(); - - QtyBatchsLabel.setText(Msg.translate(Env.getCtx(), "QtyBatchs")); - tmpRow.appendChild(QtyBatchsLabel); - tmpRow.appendChild(qtyBatchsField.getComponent()); - QtyBatchSizeLabel.setText(Msg.translate(Env.getCtx(), "QtyBatchSize")); - tmpRow.appendChild(QtyBatchSizeLabel); - tmpRow.appendChild(qtyBatchSizeField.getComponent()); - openQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyOpen")); - tmpRow.appendChild(openQtyLabel); - tmpRow.appendChild(openQtyField.getComponent()); - //5th - tmpRow = tmpRows.newRow(); - - tmpRow.appendChild(labelcombo); - tmpRow.appendChild(pickcombo); - tmpRow.appendChild(backflushGroupLabel); - tmpRow.appendChild(backflushGroup); - tmpRow.appendChild(new Space()); - tmpRow.appendChild(new Space()); - //6th - tmpRow = tmpRows.newRow(); - - toDeliverQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyToDeliver")); - tmpRow.appendChild(toDeliverQtyLabel); - tmpRow.appendChild(toDeliverQty.getComponent()); - scrapQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyScrap")); - tmpRow.appendChild(scrapQtyLabel); - tmpRow.appendChild(scrapQtyField.getComponent()); - rejectQtyLabel.setText(Msg.translate(Env.getCtx(), "QtyReject")); - tmpRow.appendChild(rejectQtyLabel); - tmpRow.appendChild(rejectQty.getComponent()); - //7th - tmpRow = tmpRows.newRow(); - - movementDateLabel.setText(Msg.translate(Env.getCtx(), "MovementDate")); - tmpRow.appendChild(movementDateLabel); - tmpRow.appendChild(movementDateField.getComponent()); - locatorLabel.setText(Msg.translate(Env.getCtx(), "M_Locator_ID")); - tmpRow.appendChild(locatorLabel); - tmpRow.appendChild(locatorField.getComponent()); - attributeLabel.setText(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID")); - tmpRow.appendChild(attributeLabel); - tmpRow.appendChild(attribute.getComponent()); - ReceiptIssueOrder.appendChild(center); - center.appendChild(issue); - ReceiptIssueOrder.appendChild(south); - south.appendChild(PanelBottom); - - Process.setLabel(Msg.translate(Env.getCtx(), "OK")); - PanelBottom.appendChild(Process); - - - Tabs tabs = new Tabs(); - Tab tab1 =new Tab(); - Tab tab2 =new Tab(); - tab1.setLabel(Msg.translate(Env.getCtx(), "IsShipConfirm")); - tab2.setLabel(Msg.translate(Env.getCtx(), "Generate")); - tabs.appendChild(tab1); - tabs.appendChild(tab2); - - TabsReceiptsIssue.appendChild(tabs); - Tabpanels tabps = new Tabpanels(); - Tabpanel tabp1 = new Tabpanel(); - Tabpanel tabp2 = new Tabpanel(); - TabsReceiptsIssue.appendChild(tabps); - TabsReceiptsIssue.setWidth("100%"); - TabsReceiptsIssue.setHeight("100%"); - tabps.appendChild(tabp1); - tabps.appendChild(tabp2); - tabp1.appendChild(ReceiptIssueOrder); - tabp1.setWidth("100%"); - tabp1.setHeight("100%"); - tabp2.appendChild(Generate); - tabp2.setWidth("100%"); - tabp2.setHeight("100%"); - Generate.appendChild(info); - Generate.setVisible(true); - info.setVisible(true); - TabsReceiptsIssue.addEventListener(Events.ON_CHANGE, this); - } // jbInit - - /** - * Dynamic Init. - * Table Layout, Visual, Listener - * This is only run as part of the windows initialization process - */ - public void dynInit() - { - disableToDeliver(); - prepareTable(issue); - issue.autoSize(); - issue.getModel().addTableModelListener(this); - issue.setRowCount(0); - } // dynInit - - public void prepareTable(IMiniTable miniTable) - { - m_sql=issue.prepareTable(new ColumnInfo[] - { - new ColumnInfo(" ", "obl.PP_Order_BOMLine_ID as id", IDColumn.class, false, false, null), - new ColumnInfo(Msg.translate(Env.getCtx(), "IsCritical"),"obl.IsCritical as isCritical",Boolean.class,true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "Value"),"p.Value as Value",String.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"),"obl.M_Product_ID as id_p,p.Name as name_p",KeyNamePair.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "C_UOM_ID"),"p.C_UOM_ID as id_u ,u.Name as name_u",KeyNamePair.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"),"obl.ComponentType as componentType",String.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyRequired"),"obl.QtyRequiered as qtyRequired",BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyDelivered"),"obl.QtyDelivered as qtyDelivered",BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyToDeliver"),"obl.QtyRequiered - QtyDelivered AS qtyOpen",BigDecimal.class, false,false,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyScrap"),MPPOrderBOMLine.COLUMNNAME_QtyScrap,BigDecimal.class, false,false,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"),"bomQtyOnHand(obl.M_Product_ID,obl.M_Warehouse_ID,0) AS qtyOnHand", BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"),"obl.QtyReserved as QtyReserved", BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"),"bomQtyAvailable(obl.M_Product_ID,obl.M_Warehouse_ID,0 ) AS QtyAvailable", BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "M_Locator_ID"),"p.M_Locator_ID", String.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "M_Warehouse_ID"),"obl.M_Warehouse_ID as id_w,w.Name as name_w", KeyNamePair.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyBom"),"obl.QtyBom as qtyBom", BigDecimal.class, true,true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "IsQtyPercentage"),"obl.isQtyPercentage as isQtyPercentage", Boolean.class, true, true,null), - new ColumnInfo(Msg.translate(Env.getCtx(), "QtyBatch"),"obl.QtyBatch as qtyBatch", BigDecimal.class, true,true,null) - }, - "PP_Order_BOMLine obl" - + " INNER JOIN M_Product p ON (obl.M_Product_ID = p.M_Product_ID) " - + " INNER JOIN C_UOM u ON (p.C_UOM_ID = u.C_UOM_ID) " - + " INNER JOIN M_Warehouse w ON (w.M_Warehouse_ID = obl.M_Warehouse_ID) ", " obl.PP_Order_ID = ?", - true, "obl"); - } - - /** - * Called when events occur in the window - */ - @Override - public void onEvent(Event e) throws Exception - { - if (e.getName().equals(Events.ON_CANCEL)) - { - dispose(); - return; - } - - if (e.getTarget().equals(Process)) - { - if (getMovementDate() == null) - { - try - { - Messagebox.show( Msg.getMsg(Env.getCtx(), "NoDate"), "Info",Messagebox.OK, Messagebox.INFORMATION); - } - catch (InterruptedException ex) - { - throw new AdempiereException (ex); - } - return; - } - - if ((isOnlyReceipt() || isBackflush()) && getM_Locator_ID() <= 0) - { - try - { - Messagebox.show(Msg.getMsg(Env.getCtx(), "NoLocator"),"Info", Messagebox.OK, Messagebox.INFORMATION); - } - catch (InterruptedException ex) - { - throw new AdempiereException (ex); - } - return; - } - - // Switch Tabs - TabsReceiptsIssue.setSelectedIndex(1); - - generateSummaryTable(); - int result = -1; - try - { - result = Messagebox.show(Msg.getMsg(Env.getCtx(), "Update"),"",Messagebox.OK|Messagebox.CANCEL,Messagebox.QUESTION); - } - catch (InterruptedException ex) - { - throw new AdempiereException(ex); - } - if ( result == Messagebox.OK) - { - try - { - if (cmd_process()) - { - dispose(); - return; - } - } - catch (InterruptedException ex) - { - throw new AdempiereException(ex); - } - Clients.showBusy(null, false); - } - TabsReceiptsIssue.setSelectedIndex(0); - } - - if (e.getTarget().equals(toDeliverQty) || e.getTarget().equals(scrapQtyField)) - { - if (getPP_Order_ID() > 0 && isBackflush()) - { - executeQuery(); - } - } - - if (e.getTarget().equals(pickcombo)) - { - if (isOnlyReceipt()) - { - enableToDeliver(); - locatorLabel.setVisible(true); - locatorField.setVisible(true); - attribute.setVisible(true); - attributeLabel.setVisible(true); - issue.setVisible(false); - } - else if (isOnlyIssue()) - { - disableToDeliver(); - locatorLabel.setVisible(false); - locatorField.setVisible(false); - attribute.setVisible(false); - attributeLabel.setVisible(false); - issue.setVisible(true); - executeQuery(); - } - else if (isBackflush()) - { - enableToDeliver(); - locatorLabel.setVisible(true); - locatorField.setVisible(true); - attribute.setVisible(true); - attributeLabel.setVisible(true); - issue.setVisible(true); - executeQuery(); - } - setToDeliverQty(getOpenQty()); //reset toDeliverQty to openQty - } - } - - public void enableToDeliver() - { - setToDeliver(true); - } - - public void disableToDeliver() - { - setToDeliver(false); - } - - private void setToDeliver(Boolean state) - { - toDeliverQty.getComponent().setEnabled(state); - scrapQtyLabel.setVisible(state); - scrapQtyField.setVisible(state); - rejectQtyLabel.setVisible(state); - rejectQty.setVisible(state); - } - - /** - * Queries for and fills the table in the lower half of the screen - * This is only run if isBackflush() or isOnlyIssue - */ - public void executeQuery() - { - - final String sql = m_sql + " ORDER BY obl."+MPPOrderBOMLine.COLUMNNAME_Line; - - // reset table - issue.clearTable(); - int row = 0; - issue.setRowCount(row); - // Execute - PreparedStatement pstmt = null; - ResultSet rs = null; - - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, getPP_Order_ID()); - - rs = pstmt.executeQuery(); - - while (rs.next()) - { - // extend table - issue.setRowCount(row + 1); - // set values - //issue. - IDColumn id = new IDColumn(rs.getInt("id")); - BigDecimal qtyBom = rs.getBigDecimal("qtyBom"); - Boolean isQtyPercentage = rs.getString("isQtyPercentage").equals("Y"); - Boolean isCritical = rs.getString("isCritical").equals("Y"); - BigDecimal qtyBatch = rs.getBigDecimal("qtyBatch"); - BigDecimal qtyRequired = rs.getBigDecimal("qtyRequired"); - BigDecimal qtyOnHand = rs.getBigDecimal("qtyOnHand"); - BigDecimal qtyOpen = rs.getBigDecimal("qtyOpen"); - BigDecimal qtyDelivered = rs.getBigDecimal("qtyDelivered"); - String componentType = rs.getString("componentType"); - BigDecimal toDeliverQty = getToDeliverQty(); - BigDecimal openQty = getOpenQty(); - BigDecimal scrapQty = getScrapQty(); - BigDecimal componentToDeliverQty = Env.ZERO; - BigDecimal componentScrapQty = Env.ZERO; - BigDecimal componentQtyReq = Env.ZERO; - BigDecimal componentQtyToDel = Env.ZERO; - - id.setSelected(isOnlyReceipt()); - - issue.setValueAt(id, row, 0); // PP_OrderBOMLine_ID - issue.setValueAt(isCritical, row, 1); // IsCritical - issue.setValueAt(rs.getString("Value"), row, 2); // Product's Search key - issue.setValueAt(new KeyNamePair(rs.getInt("id_p"), rs.getString("name_p")), row, 3); // Product - issue.setValueAt(new KeyNamePair(rs.getInt("id_u"), rs.getString("name_u")), row, 4); // UOM - // ... 5 - ASI - issue.setValueAt(qtyRequired, row, 6); // QtyRequiered - issue.setValueAt(qtyDelivered, row, 7); // QtyDelivered - - // ... 8, 9, 10 - QtyToDeliver, QtyScrap, QtyOnHand - issue.setValueAt(qtyOnHand, row, 10); // OnHand - issue.setValueAt(rs.getBigDecimal("QtyReserved"), row, 11); // QtyReserved - issue.setValueAt(rs.getBigDecimal("QtyAvailable"), row, 12); // QtyAvailable - // ... 13 - M_Locator_ID - issue.setValueAt(new KeyNamePair(rs.getInt("id_w"), rs.getString("name_w")), row, 14); // Warehouse - issue.setValueAt(qtyBom, row, 15); // QtyBom - issue.setValueAt(isQtyPercentage, row, 16); // isQtyPercentage - issue.setValueAt(qtyBatch, row, 17); // QtyBatch - - if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Component) - || componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Packing)) - { - // If the there is product on hand and product is required the product should be selected - id.setSelected(qtyOnHand.signum() > 0 && qtyRequired.signum() > 0); - - if (isQtyPercentage) - { - // If the quantity of product is calculated as a percentage - BigDecimal qtyBatchPerc = qtyBatch.divide(Env.ONEHUNDRED, 8, BigDecimal.ROUND_HALF_UP); - - if (isBackflush()) - { // Is Backflush - Calculate Component from Qty To Deliver - if (qtyRequired.signum() == 0 || qtyOpen.signum() == 0) - { - componentToDeliverQty = Env.ZERO; - } - else - { - componentToDeliverQty = toDeliverQty.multiply(qtyBatchPerc); - - if(qtyRequired.subtract(qtyDelivered).signum() < 0 | componentToDeliverQty.signum() == 0) - componentToDeliverQty = qtyRequired.subtract(qtyDelivered); - - } - - if (componentToDeliverQty.signum() != 0) - { - componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP); - issue.setValueAt(componentToDeliverQty, row, 8); // QtyToDelivery - - } - } - else - { - // Only Issue - Calculate Component from Open Qty - componentToDeliverQty = qtyOpen; - if (componentToDeliverQty.signum() != 0) - { - componentQtyReq = openQty.multiply(qtyBatchPerc); // scale 4 - componentQtyToDel = componentToDeliverQty.setScale(4, BigDecimal.ROUND_HALF_UP); - issue.setValueAt(componentToDeliverQty.setScale(8, BigDecimal.ROUND_HALF_UP), row, 8); // QtyToDelivery - issue.setValueAt(openQty.multiply(qtyBatchPerc), row, 6); // QtyRequiered - } - } - - if (scrapQty.signum() != 0) - { - componentScrapQty = scrapQty.multiply(qtyBatchPerc); - if (componentScrapQty.signum() != 0) - { - issue.setValueAt(componentScrapQty, row, 9); // QtyScrap - } - } - } - else - { - // Absolute Qtys (not Percentage) - if (isBackflush()) - { //Is Backflush - Calculate Component from Qty To Deliver - componentToDeliverQty = toDeliverQty.multiply(qtyBom); // TODO: set Number scale - if (componentToDeliverQty.signum() != 0) - { - componentQtyReq = toDeliverQty.multiply(qtyBom); - componentQtyToDel = componentToDeliverQty; - issue.setValueAt(componentQtyReq, row, 6); // QtyRequiered - issue.setValueAt(componentToDeliverQty, row, 8); // QtyToDelivery - } - } - else - { - // Only Issue - Calculate Component from Open Qty - componentToDeliverQty = qtyOpen; - if (componentToDeliverQty.signum() != 0) - { - componentQtyReq = openQty.multiply(qtyBom); - componentQtyToDel = componentToDeliverQty; - issue.setValueAt(componentQtyReq, row, 6); // QtyRequiered - issue.setValueAt(componentToDeliverQty, row, 8); // QtyToDelivery - } - } - - if (scrapQty.signum() != 0) - { - componentScrapQty = scrapQty.multiply(qtyBom); // TODO: set Number scale - if (componentScrapQty.signum() != 0) { - issue.setValueAt(componentScrapQty, row, 9); // ScrapQty - } - } - - } - } - else if (componentType.equals(MPPProductBOMLine.COMPONENTTYPE_Tools)) - { - componentToDeliverQty = qtyBom; // TODO; set Number scale - if (componentToDeliverQty.signum() != 0) - { - componentQtyReq = qtyBom; - componentQtyToDel = componentToDeliverQty; - issue.setValueAt(qtyBom, row, 6); // QtyRequiered - issue.setValueAt(componentToDeliverQty, row, 8); // QtyToDelivery - } - } - else - { - issue.setValueAt(Env.ZERO, row, 6); // QtyRequiered - issue.setValueAt(Env.ZERO, row, 8); // QtyToDelivery - } - if(issue.getValueAt(row, 9) == null ){ - issue.setValueAt(Env.ZERO, row, 9); - } - if(issue.getValueAt(row, 8) == null ){ - issue.setValueAt(Env.ZERO, row, 8); - } - row++; - - if (isOnlyIssue() || isBackflush()) - { - int warehouse_id = rs.getInt("id_w"); - int product_id = rs.getInt("id_p"); - row += lotes(row, id, warehouse_id, product_id, componentQtyReq, componentQtyToDel); - } - } // while - } - catch (SQLException e) - { - throw new DBException(e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - issue.repaint(); - } // executeQuery - - /** - * Adds Attribute Set Instances Quantities to table. - * Extension to {@link #executeQuery()} - * @return how many lines were added - */ - private int lotes (int row, IDColumn id, int Warehouse_ID, int M_Product_ID, - BigDecimal qtyRequired, BigDecimal qtyToDelivery) - { - int linesNo = 0; - BigDecimal qtyRequiredActual = qtyRequired; - - final String sql = "SELECT " - + "s.M_Product_ID , s.QtyOnHand, s.M_AttributeSetInstance_ID" - + ", p.Name, masi.Description, l.Value, w.Value, w.M_warehouse_ID,p.Value" - + " FROM M_Storage s " - + " INNER JOIN M_Product p ON (s.M_Product_ID = p.M_Product_ID) " - + " INNER JOIN C_UOM u ON (u.C_UOM_ID = p.C_UOM_ID) " - + " INNER JOIN M_AttributeSetInstance masi ON (masi.M_AttributeSetInstance_ID = s.M_AttributeSetInstance_ID) " - + " INNER JOIN M_Warehouse w ON (w.M_Warehouse_ID = ?) " - + " INNER JOIN M_Locator l ON(l.M_Warehouse_ID=w.M_Warehouse_ID and s.M_Locator_ID=l.M_Locator_ID) " - + " WHERE s.M_Product_ID = ? and s.QtyOnHand > 0 " - + " and s.M_AttributeSetInstance_ID <> 0 " - + " ORDER BY s.Created "; - - // Execute - PreparedStatement pstmt = null; - ResultSet rs = null; - try - { - pstmt = DB.prepareStatement(sql, null); - pstmt.setInt(1, Warehouse_ID); - pstmt.setInt(2, M_Product_ID); - rs = pstmt.executeQuery(); - while (rs.next()) - { - issue.setRowCount(row + 1); - - // Qty On Hand - final BigDecimal qtyOnHand = rs.getBigDecimal(2); - - // ID/M_AttributeSetInstance_ID - IDColumn id1 = new IDColumn(rs.getInt(3)); - id1.setSelected(false); - - issue.setValueAt(id1, row, 0); - // Product - KeyNamePair productkey = new KeyNamePair(rs.getInt(1), rs.getString(4)); - issue.setValueAt(productkey, row, 3); - // QtyOnHand - issue.setValueAt(qtyOnHand, row, 10); - // ASI - issue.setValueAt(rs.getString(5), row, 5); - // Locator - issue.setValueAt(rs.getString(6), row, 13); - // Warehouse - KeyNamePair m_warehousekey = new KeyNamePair(rs.getInt(8), rs.getString(7)); - issue.setValueAt(m_warehousekey, row, 14); - // Qty Required: - if (qtyRequiredActual.compareTo(qtyOnHand) < 0) - { - issue.setValueAt(qtyRequiredActual.signum() > 0 ? qtyRequiredActual : Env.ZERO, row, 6); - } - else - { - issue.setValueAt(qtyOnHand, row, 6); - } - - qtyRequiredActual = qtyRequiredActual.subtract(qtyOnHand); - - if(issue.getValueAt(row, 9) == null ) - { - issue.setValueAt(Env.ZERO, row, 9); - } - - if(issue.getValueAt(row, 8) == null ) - { - issue.setValueAt(Env.ZERO, row, 8); - } - - linesNo++; - row++; - } - } - catch (SQLException e) - { - throw new DBException(e); - } - finally - { - DB.close(rs, pstmt); - rs = null; pstmt = null; - } - - return linesNo; - } - - @Override - public void valueChange(ValueChangeEvent e) - { - String name = e.getPropertyName(); - Object value = e.getNewValue(); - - if (value == null) - return; - - // PP_Order_ID - if (name.equals("PP_Order_ID")) - { - orderField.setValue(value); - - MPPOrder pp_order = getPP_Order(); - if (pp_order != null) - { - setS_Resource_ID(pp_order.getS_Resource_ID()); - setM_Warehouse_ID(pp_order.getM_Warehouse_ID()); - setDeliveredQty(pp_order.getQtyDelivered()); - setOrderedQty(pp_order.getQtyOrdered()); - //m_PP_order.getQtyOrdered().subtract(m_PP_order.getQtyDelivered()); - setQtyBatchs(pp_order.getQtyBatchs()); - setQtyBatchSize(pp_order.getQtyBatchSize()); - setOpenQty(pp_order.getQtyOrdered().subtract(pp_order.getQtyDelivered())); - setToDeliverQty(getOpenQty()); - setM_Product_ID(pp_order.getM_Product_ID()); - MProduct m_product = MProduct.get(Env.getCtx(), pp_order.getM_Product_ID()); - setC_UOM_ID(m_product.getC_UOM_ID()); - setOrder_UOM_ID(pp_order.getC_UOM_ID()); - //Default ASI defined from the Parent BOM Order - setM_AttributeSetInstance_ID(pp_order.getMPPOrderBOM().getM_AttributeSetInstance_ID()); - pickcombo.setSelectedIndex(0); //default to first entry - isBackflush - Event ev = new Event(Events.ON_CHANGE,pickcombo); - try { - onEvent(ev); - } catch (Exception e1) { - throw new AdempiereException(e1); - } - } - } // PP_Order_ID - } - - /** - * Performs what ever task is attached to the combo box - * @return Whether the process was successful or not - * @throws InterruptedException - */ - private boolean cmd_process() throws InterruptedException - { - - if (isOnlyReceipt() || isBackflush()) - { - if (getM_Locator_ID() <= 0) - { - Messagebox.show( Msg.getMsg(Env.getCtx(), "NoLocator"), "Info",Messagebox.OK, Messagebox.INFORMATION); - } - } - if (getPP_Order() == null || getMovementDate() == null) - { - return false; - } - final boolean isCloseDocument = (Messagebox.show(Msg.parseTranslation(Env.getCtx(),"@IsCloseDocument@ : "+ getPP_Order().getDocumentNo()),"",Messagebox.OK|Messagebox.CANCEL,Messagebox.QUESTION) == Messagebox.OK); - - try - { - Trx.run(new TrxRunnable() - { - public void run(String trxName) - { - MPPOrder order = new MPPOrder(Env.getCtx(), getPP_Order_ID(), trxName); - if (isBackflush() || isOnlyIssue()) - { - createIssue(order); - } - if (isOnlyReceipt() || isBackflush()) - { - MPPOrder.createReceipt(order,getMovementDate(), - getDeliveredQty(),getToDeliverQty(), - getScrapQty(),getRejectQty(), - getM_Locator_ID(),getM_AttributeSetInstance_ID()); - if (isCloseDocument) - { - order.setDateFinish(getMovementDate()); - order.closeIt(); - order.saveEx(); - } - } - } - }); - } - catch (Exception e) - { - Messagebox.show(e.getLocalizedMessage(),"",Messagebox.OK,Messagebox.ERROR); - return false; - } - finally - { - m_PP_order = null; - } - - return true; - } - - @SuppressWarnings("unchecked") - private void createIssue(MPPOrder order) - { - Timestamp movementDate = getMovementDate(); - Timestamp minGuaranteeDate = movementDate; - boolean isCompleteQtyDeliver = false; - - ArrayList[][] m_issue = new ArrayList[issue.getRowCount()][1]; - - int row = 0; - // Check Available On Hand Qty - for (int i = 0; i < issue.getRowCount(); i++) - { - ArrayList