* Initial implementation of Product attribute editor, working but need more fine tuning.

This commit is contained in:
Heng Sin Low 2008-07-14 09:29:04 +00:00
parent 6ecc91660a
commit 6cd8af5b79
7 changed files with 1615 additions and 1 deletions

View File

@ -0,0 +1,93 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin 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 *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/
package org.adempiere.webui.component;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Hbox;
/**
* Product Attribute Box
* @author Low Heng Sin
*/
public class PAttributebox extends Hbox
{
private static final long serialVersionUID = 1L;
private Textbox textBox;
private Button button;
public PAttributebox()
{
initComponents();
}
public PAttributebox(String description)
{
initComponents();
setText(description);
}
public void setButtonImage(String imageSrc)
{
button.setImage(imageSrc);
}
private void initComponents()
{
textBox = new Textbox();
textBox.setWidth("100%");
button = new Button();
button.setHeight("98%");
appendChild(textBox);
appendChild(button);
}
public void setText(String value)
{
textBox.setText(value);
}
public String getText()
{
return textBox.getText();
}
public void setEnabled(boolean enabled)
{
textBox.setReadonly(!enabled);
button.setEnabled(enabled);
}
public void setButtonEnabled(boolean enabled)
{
button.setEnabled(enabled);
}
public boolean addEventListener(String evtnm, EventListener listener)
{
if ("onClick".equals(evtnm))
return button.addEventListener(evtnm, listener);
else
return textBox.addEventListener(evtnm, listener);
}
public Textbox getTextbox() {
return textBox;
}
}

View File

@ -42,6 +42,8 @@ import org.compiere.util.Util;
import org.zkoss.zul.ListModel;
/**
* Replacement for the Swing client minigrid component
*
* ZK Listbox extension for Adempiere Web UI.
* The listbox contains a model and a renderer.
* The model holds the underlying data objects, while the

View File

@ -0,0 +1,282 @@
/******************************************************************************
* Copyright (C) 2008 Low Heng Sin 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 *
* Posterita Ltd., 3, Draper Avenue, Quatre Bornes, Mauritius *
* or via info@posterita.org or http://www.posterita.org/ *
*****************************************************************************/
package org.adempiere.webui.editor;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.PAttributebox;
import org.adempiere.webui.event.ContextMenuEvent;
import org.adempiere.webui.event.ContextMenuListener;
import org.adempiere.webui.event.ValueChangeEvent;
import org.adempiere.webui.window.WPAttributeDialog;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.Lookup;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MProduct;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.Events;
/**
*
* @author Low Heng Sin
*
*/
public class WPAttributeEditor extends WEditor implements ContextMenuListener
{
private static final String[] LISTENER_EVENTS = {Events.ON_CLICK, Events.ON_CHANGE};
private static final CLogger log = CLogger.getCLogger(WPAttributeEditor.class);
private int m_WindowNo;
private Lookup m_mPAttribute;
private int m_C_BPartner_ID;
private WEditorPopupMenu popupMenu;
private Object m_value;
private GridTab m_GridTab;
/** No Instance Key */
private static Integer NO_INSTANCE = new Integer(0);
public WPAttributeEditor(GridTab gridTab, GridField gridField)
{
super(new PAttributebox(), gridField);
m_GridTab = gridTab;
initComponents();
}
private void initComponents() {
getComponent().setButtonImage("images/PAttribute10.gif");
getComponent().addEventListener(Events.ON_CLICK, this);
m_WindowNo = gridField.getWindowNo();
m_mPAttribute = gridField.getLookup();
m_C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_BPartner_ID");
// Popup
popupMenu = new WEditorPopupMenu(true, false, false);
getComponent().getTextbox().setContext(popupMenu.getId());
}
@Override
public WEditorPopupMenu getPopupMenu() {
return popupMenu;
}
@Override
public PAttributebox getComponent()
{
return (PAttributebox) component;
}
@Override
public void setValue(Object value)
{
if (value == null || NO_INSTANCE.equals(value))
{
getComponent().setText("");
m_value = value;
return;
}
// The same
if (value.equals(m_value))
return;
// new value
log.fine("Value=" + value);
m_value = value;
getComponent().setText(m_mPAttribute.getDisplay(value)); // loads value
}
@Override
public Object getValue()
{
return m_value;
}
@Override
public String getDisplay()
{
return getComponent().getText();
}
public void onEvent(Event event)
{
if (Events.ON_CHANGE.equals(event.getName()))
{
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), getComponent().getText(), getComponent().getText());
fireValueChange(changeEvent);
}
else if (Events.ON_CLICK.equals(event.getName()))
{
cmd_dialog();
}
}
/**
* Start dialog
*/
private void cmd_dialog()
{
//
Integer oldValue = (Integer)getValue ();
int oldValueInt = oldValue == null ? 0 : oldValue.intValue ();
int M_AttributeSetInstance_ID = oldValueInt;
int M_Product_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Product_ID");
int M_ProductBOM_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_ProductBOM_ID");
log.config("M_Product_ID=" + M_Product_ID + "/" + M_ProductBOM_ID
+ ",M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID
+ ", AD_Column_ID=" + gridField.getAD_Column_ID());
// M_Product.M_AttributeSetInstance_ID = 8418
boolean productWindow = (gridField.getAD_Column_ID() == 8418); // HARDCODED
// Exclude ability to enter ASI
boolean exclude = true;
if (M_Product_ID != 0)
{
MProduct product = MProduct.get(Env.getCtx(), M_Product_ID);
int M_AttributeSet_ID = product.getM_AttributeSet_ID();
if (M_AttributeSet_ID != 0)
{
MAttributeSet mas = MAttributeSet.get(Env.getCtx(), M_AttributeSet_ID);
exclude = mas.excludeEntry(gridField.getAD_Column_ID(), Env.isSOTrx(Env.getCtx(), m_WindowNo));
}
}
boolean changed = false;
if (M_ProductBOM_ID != 0) // Use BOM Component
M_Product_ID = M_ProductBOM_ID;
//
if (!productWindow && (M_Product_ID == 0 || exclude))
{
changed = true;
getComponent().setText(null);
M_AttributeSetInstance_ID = 0;
}
else
{
WPAttributeDialog vad = new WPAttributeDialog (
M_AttributeSetInstance_ID, M_Product_ID, m_C_BPartner_ID,
productWindow, gridField.getAD_Column_ID(), m_WindowNo);
if (vad.isChanged())
{
getComponent().setText(vad.getM_AttributeSetInstanceName());
M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID();
if (m_GridTab != null && !productWindow)
m_GridTab.setValue("M_Locator_ID", vad.getM_Locator_ID());
changed = true;
}
}
/** Selection
{
// Get Model
MAttributeSetInstance masi = MAttributeSetInstance.get(Env.getCtx(), M_AttributeSetInstance_ID, M_Product_ID);
if (masi == null)
{
log.log(Level.SEVERE, "No Model for M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID + ", M_Product_ID=" + M_Product_ID);
}
else
{
Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", masi.getM_AttributeSet_ID());
// Get Attribute Set
MAttributeSet as = masi.getMAttributeSet();
// Product has no Attribute Set
if (as == null)
ADialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
// Product has no Instance Attributes
else if (!as.isInstanceAttribute())
ADialog.error(m_WindowNo, this, "PAttributeNoInstanceAttribute");
else
{
int M_Warehouse_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Warehouse_ID");
int M_Locator_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Locator_ID");
String title = "";
PAttributeInstance pai = new PAttributeInstance (
Env.getFrame(this), title,
M_Warehouse_ID, M_Locator_ID, M_Product_ID, m_C_BPartner_ID);
if (pai.getM_AttributeSetInstance_ID() != -1)
{
m_text.setText(pai.getM_AttributeSetInstanceName());
M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
changed = true;
}
}
}
}
**/
// Set Value
if (changed)
{
log.finest("Changed M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
m_value = new Object(); // force re-query display
if (M_AttributeSetInstance_ID == 0)
setValue(null);
else
setValue(new Integer(M_AttributeSetInstance_ID));
ValueChangeEvent vce = new ValueChangeEvent(this, gridField.getColumnName(), new Object(), getValue());
fireValueChange(vce);
if (M_AttributeSetInstance_ID == oldValueInt && m_GridTab != null && gridField != null)
{
// force Change - user does not realize that embedded object is already saved.
m_GridTab.processFieldChange(gridField);
}
} // change
} // cmd_file
public String[] getEvents()
{
return LISTENER_EVENTS;
}
public void onMenu(ContextMenuEvent evt)
{
if (WEditorPopupMenu.ZOOM_EVENT.equals(evt.getContextEvent()))
{
actionZoom();
}
}
public void actionZoom()
{
AEnv.actionZoom(m_mPAttribute, getValue());
}
@Override
public boolean isReadWrite() {
return !getComponent().getTextbox().isReadonly();
}
@Override
public void setReadWrite(boolean readWrite) {
getComponent().setEnabled(readWrite);
}
}

View File

@ -18,6 +18,7 @@
package org.adempiere.webui.editor;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.MLocationLookup;
import org.compiere.model.MLocatorLookup;
import org.compiere.util.CLogger;
@ -28,6 +29,9 @@ import org.compiere.util.DisplayType;
* @author <a href="mailto:agramdass@gmail.com">Ashley G Ramdass</a>
* @date Mar 12, 2007
* @version $Revision: 0.10 $
*
* @author Low Heng Sin
* @date July 14 2008
*/
public class WebEditorFactory
{
@ -40,6 +44,11 @@ public class WebEditorFactory
}
public static WEditor getEditor(GridField gridField, boolean tableEditor)
{
return getEditor(null, gridField, tableEditor);
}
public static WEditor getEditor(GridTab gridTab, GridField gridField, boolean tableEditor)
{
if (gridField == null)
{
@ -149,6 +158,10 @@ public class WebEditorFactory
{
editor = new WBinaryEditor(gridField);
}
else if (displayType == DisplayType.PAttribute)
{
editor = new WPAttributeEditor(gridTab, gridField);
}
else
{
editor = new WUnknownEditor(gridField);

View File

@ -259,7 +259,7 @@ DataStatusListener, ValueChangeListener
row = new Row();
}
WEditor comp = WebEditorFactory.getEditor(field, false);
WEditor comp = WebEditorFactory.getEditor(gridTab, field, false);
if (comp != null) // Not heading
{

View File

@ -0,0 +1,848 @@
/******************************************************************************
* 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.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.logging.Level;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Datebox;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.ListItem;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.NumberBox;
import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.session.SessionManager;
import org.compiere.model.MAttribute;
import org.compiere.model.MAttributeInstance;
import org.compiere.model.MAttributeSet;
import org.compiere.model.MAttributeSetInstance;
import org.compiere.model.MAttributeValue;
import org.compiere.model.MDocType;
import org.compiere.model.MLot;
import org.compiere.model.MLotCtl;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MSerNoCtl;
import org.compiere.model.X_M_MovementLine;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.HtmlBasedComponent;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkex.zul.Borderlayout;
import org.zkoss.zkex.zul.Center;
import org.zkoss.zkex.zul.South;
import org.zkoss.zul.Div;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menupopup;
import org.zkoss.zul.impl.InputElement;
/**
* Product Attribute Set Product/Instance Dialog Editor.
* Called from VPAttribute.actionPerformed
*
* @author Jorg Janke
*
* ZK Port
* @author Low Heng Sin
*/
public class WPAttributeDialog extends Window implements EventListener
{
/**
* Product Attribute Instance Dialog
* @param M_AttributeSetInstance_ID Product Attribute Set Instance id
* @param M_Product_ID Product id
* @param C_BPartner_ID b partner
* @param productWindow this is the product window (define Product Instance)
* @param AD_Column_ID column
* @param WindowNo window
*/
public WPAttributeDialog (int M_AttributeSetInstance_ID,
int M_Product_ID, int C_BPartner_ID,
boolean productWindow, int AD_Column_ID, int WindowNo)
{
super ();
this.setTitle(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"));
this.setAttribute("modal", Boolean.TRUE);
this.setBorder("normal");
this.setWidth("500px");
this.setHeight("600px");
this.setSizable(true);
log.config("M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID
+ ", M_Product_ID=" + M_Product_ID
+ ", C_BPartner_ID=" + C_BPartner_ID
+ ", ProductW=" + productWindow + ", Column=" + AD_Column_ID);
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
m_M_AttributeSetInstance_ID = M_AttributeSetInstance_ID;
m_M_Product_ID = M_Product_ID;
m_C_BPartner_ID = C_BPartner_ID;
m_productWindow = productWindow;
m_AD_Column_ID = AD_Column_ID;
m_WindowNoParent = WindowNo;
try
{
init();
}
catch(Exception ex)
{
log.log(Level.SEVERE, "VPAttributeDialog" + ex);
}
// Dynamic Init
if (!initAttributes ())
{
dispose();
return;
}
AEnv.showCenterScreen(this);
} // VPAttributeDialog
private int m_WindowNo;
private MAttributeSetInstance m_masi;
private int m_M_AttributeSetInstance_ID;
private int m_M_Locator_ID;
private String m_M_AttributeSetInstanceName;
private int m_M_Product_ID;
private int m_C_BPartner_ID;
private int m_AD_Column_ID;
private int m_WindowNoParent;
/** Enter Product Attributes */
private boolean m_productWindow = false;
/** Change */
private boolean m_changed = false;
private CLogger log = CLogger.getCLogger(getClass());
/** Row Counter */
private int m_row = 0;
/** List of Editors */
private ArrayList<HtmlBasedComponent> m_editors = new ArrayList<HtmlBasedComponent>();
/** Length of Instance value (40) */
private static final int INSTANCE_VALUE_LENGTH = 40;
private Checkbox cbNewEdit = new Checkbox();
private Button bSelect = new Button();
// Lot
// private VString fieldLotString = new VString ("Lot", false, false, true, 20, 20, null, null);
private Textbox fieldLotString = new Textbox();
private Listbox fieldLot = new Listbox();
private Button bLot = new Button(Msg.getMsg (Env.getCtx(), "New"));
// Lot Popup
Menupopup popupMenu = new Menupopup();
private Menuitem mZoom;
// Ser No
private Textbox fieldSerNo = new Textbox();
private Button bSerNo = new Button(Msg.getMsg (Env.getCtx(), "New"));
// Date
private Datebox fieldGuaranteeDate = new Datebox();
//
private Textbox fieldDescription = new Textbox(); //TODO: set length to 20
//
private Borderlayout mainLayout = new Borderlayout();
private Panel centerPanel = new Panel();
private Grid centerLayout = new Grid();
private ConfirmPanel confirmPanel = new ConfirmPanel (true);
/**
* Layout
* @throws Exception
*/
private void init () throws Exception
{
mainLayout.setParent(this);
mainLayout.setWidth("100%");
mainLayout.setHeight("100%");
Center center = new Center();
center.setParent(mainLayout);
center.setFlex(true);
center.appendChild(centerPanel);
South south = new South();
south.setParent(mainLayout);
south.appendChild(confirmPanel);
centerPanel.appendChild(centerLayout);
centerLayout.setOddRowSclass("even");
//
confirmPanel.addActionListener(Events.ON_CLICK, this);
} // init
/**
* Dyanmic Init.
* @return true if initialized
*/
private boolean initAttributes ()
{
Rows rows = new Rows();
rows.setParent(centerLayout);
if (m_M_Product_ID == 0 && !m_productWindow)
return false;
MAttributeSet as = null;
if (m_M_Product_ID != 0)
{
// Get Model
m_masi = MAttributeSetInstance.get(Env.getCtx(), m_M_AttributeSetInstance_ID, m_M_Product_ID);
if (m_masi == null)
{
log.severe ("No Model for M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID + ", M_Product_ID=" + m_M_Product_ID);
return false;
}
Env.setContext(Env.getCtx(), m_WindowNo, "M_AttributeSet_ID", m_masi.getM_AttributeSet_ID());
// Get Attribute Set
as = m_masi.getMAttributeSet();
}
else
{
int M_AttributeSet_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_AttributeSet_ID");
m_masi = new MAttributeSetInstance (Env.getCtx(), 0, M_AttributeSet_ID, null);
as = m_masi.getMAttributeSet();
}
// Product has no Attribute Set
if (as == null)
{
FDialog.error(m_WindowNo, this, "PAttributeNoAttributeSet");
return false;
}
// Product has no Instance Attributes
if (!m_productWindow && !as.isInstanceAttribute())
{
FDialog.error(m_WindowNo, this, "PAttributeNoInstanceAttribute");
return false;
}
// Show Product Attributes
if (m_productWindow)
{
MAttribute[] attributes = as.getMAttributes (false);
log.fine ("Product Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++)
addAttributeLine (rows, attributes[i], true, !m_productWindow);
}
else // Set Instance Attributes
{
Row row = new Row();
// New/Edit - Selection
if (m_M_AttributeSetInstance_ID == 0) // new
cbNewEdit.setLabel(Msg.getMsg(Env.getCtx(), "NewRecord"));
else
cbNewEdit.setLabel(Msg.getMsg(Env.getCtx(), "EditRecord"));
cbNewEdit.addEventListener(Events.ON_CHECK, this);
row.appendChild(cbNewEdit);
bSelect.setLabel(Msg.getMsg(Env.getCtx(), "SelectExisting"));
bSelect.setImage("images/PAttribute16.gif");
bSelect.addEventListener(Events.ON_CLICK, this);
row.appendChild(bSelect);
rows.appendChild(row);
// All Attributes
MAttribute[] attributes = as.getMAttributes (true);
log.fine ("Instance Attributes=" + attributes.length);
for (int i = 0; i < attributes.length; i++)
addAttributeLine (rows, attributes[i], false, false);
}
// Lot
if (!m_productWindow && as.isLot())
{
Row row = new Row();
row.setParent(rows);
m_row++;
Label label = new Label (Msg.translate(Env.getCtx(), "Lot"));
row.appendChild(label);
row.appendChild(fieldLotString);
fieldLotString.setText (m_masi.getLot());
// M_Lot_ID
// int AD_Column_ID = 9771; // M_AttributeSetInstance.M_Lot_ID
// fieldLot = new VLookup ("M_Lot_ID", false,false, true,
// MLookupFactory.get(Env.getCtx(), m_WindowNo, 0, AD_Column_ID, DisplayType.TableDir));
String sql = "SELECT M_Lot_ID, Name "
+ "FROM M_Lot l "
+ "WHERE EXISTS (SELECT M_Product_ID FROM M_Product p "
+ "WHERE p.M_AttributeSet_ID=" + m_masi.getM_AttributeSet_ID()
+ " AND p.M_Product_ID=l.M_Product_ID)";
fieldLot = new Listbox();
fieldLot.setMold("select");
KeyNamePair[] keyNamePairs = DB.getKeyNamePairs(sql, true);
for (KeyNamePair pair : keyNamePairs) {
fieldLot.appendItem(pair.getName(), pair.getKey());
}
label = new Label (Msg.translate(Env.getCtx(), "M_Lot_ID"));
row = new Row();
row.setParent(rows);
m_row++;
rows.appendChild(label);
row.appendChild(fieldLot);
if (m_masi.getM_Lot_ID() != 0)
{
for (int i = 1; i < fieldLot.getItemCount(); i++)
{
ListItem pp = fieldLot.getItemAtIndex(i);
if ((Integer)pp.getValue() == m_masi.getM_Lot_ID())
{
fieldLot.setSelectedIndex(i);
fieldLotString.setReadonly(true);
break;
}
}
}
fieldLot.addEventListener(Events.ON_SELECT, this);
// New Lot Button
if (m_masi.getMAttributeSet().getM_LotCtl_ID() != 0)
{
if (MRole.getDefault().isTableAccess(MLot.Table_ID, false)
&& MRole.getDefault().isTableAccess(MLotCtl.Table_ID, false)
&& !m_masi.isExcludeLot(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent)))
{
row = new Row();
row.setParent(rows);
m_row++;
row.appendChild(bLot);
bLot.addEventListener(Events.ON_CLICK, this);
}
}
// Popup
// fieldLot.addMouseListener(new VPAttributeDialog_mouseAdapter(this)); // popup
mZoom = new Menuitem(Msg.getMsg(Env.getCtx(), "Zoom"), "images/Zoom16.gif");
mZoom.addEventListener(Events.ON_CLICK, this);
popupMenu.appendChild(mZoom);
this.appendChild(popupMenu);
} // Lot
// SerNo
if (!m_productWindow && as.isSerNo())
{
Row row = new Row();
row.setParent(rows);
m_row++;
Label label = new Label (Msg.translate(Env.getCtx(), "SerNo"));
row.appendChild(label);
row.appendChild(fieldSerNo);
fieldSerNo.setText(m_masi.getSerNo());
// New SerNo Button
if (m_masi.getMAttributeSet().getM_SerNoCtl_ID() != 0)
{
if (MRole.getDefault().isTableAccess(MSerNoCtl.Table_ID, false)
&& !m_masi.isExcludeSerNo(m_AD_Column_ID, Env.isSOTrx(Env.getCtx(), m_WindowNoParent)))
{
row = new Row();
row.setParent(rows);
m_row++;
row.appendChild(bSerNo);
bSerNo.addEventListener(Events.ON_CLICK, this);
}
}
} // SerNo
// GuaranteeDate
if (!m_productWindow && as.isGuaranteeDate())
{
Row row = new Row();
row.setParent(rows);
m_row++;
Label label = new Label (Msg.translate(Env.getCtx(), "GuaranteeDate"));
if (m_M_AttributeSetInstance_ID == 0)
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate(true));
else
fieldGuaranteeDate.setValue(m_masi.getGuaranteeDate());
row.appendChild(label);
row.appendChild(fieldGuaranteeDate);
} // GuaranteeDate
if (m_row == 0)
{
FDialog.error(m_WindowNo, this, "PAttributeNoInfo");
return false;
}
// New/Edit Window
if (!m_productWindow)
{
cbNewEdit.setChecked(m_M_AttributeSetInstance_ID == 0);
cmd_newEdit();
}
// Attrribute Set Instance Description
Label label = new Label (Msg.translate(Env.getCtx(), "Description"));
// label.setLabelFor(fieldDescription);
fieldDescription.setText(m_masi.getDescription());
fieldDescription.setReadonly(true);
Row row = new Row();
row.setParent(rows);
row.appendChild(label);
row.appendChild(fieldDescription);
return true;
} // initAttribute
/**
* Add Attribute Line
* @param attribute attribute
* @param product product level attribute
* @param readOnly value is read only
*/
private void addAttributeLine (Rows rows, MAttribute attribute, boolean product, boolean readOnly)
{
log.fine(attribute + ", Product=" + product + ", R/O=" + readOnly);
m_row++;
Label label = new Label (attribute.getName());
if (product)
label.setStyle("font-weight: bold");
if (attribute.getDescription() != null)
label.setTooltip(attribute.getDescription());
Row row = new Row();
row.setParent(rows);
Div div = new Div();
div.setStyle("text-align: right");
div.appendChild(label);
row.appendChild(div);
//
MAttributeInstance instance = attribute.getMAttributeInstance (m_M_AttributeSetInstance_ID);
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attribute.getAttributeValueType()))
{
MAttributeValue[] values = attribute.getMAttributeValues(); // optional = null
Listbox editor = new Listbox();
editor.setMold("select");
for (MAttributeValue value : values)
{
ListItem item = new ListItem(value != null ? value.getName() : "", value);
editor.appendChild(item);
}
boolean found = false;
if (instance != null)
{
for (int i = 0; i < values.length; i++)
{
if (values[i] != null && values[i].getM_AttributeValue_ID () == instance.getM_AttributeValue_ID ())
{
editor.setSelectedIndex (i);
found = true;
break;
}
}
if (found)
log.fine("Attribute=" + attribute.getName() + " #" + values.length + " - found: " + instance);
else
log.warning("Attribute=" + attribute.getName() + " #" + values.length + " - NOT found: " + instance);
} // setComboBox
else
log.fine("Attribute=" + attribute.getName() + " #" + values.length + " no instance");
row.appendChild(editor);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add (editor);
}
else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attribute.getAttributeValueType()))
{
// VNumber editor = new VNumber(attribute.getName(), attribute.isMandatory(),
// false, true, DisplayType.Number, attribute.getName());
NumberBox editor = new NumberBox(true);
if (instance != null)
editor.setValue(instance.getValueNumber());
else
editor.setValue(Env.ZERO);
row.appendChild(editor);
if (readOnly)
editor.setReadonly(true);
else
m_editors.add (editor);
}
else // Text Field
{
// VString editor = new VString (attribute.getName(), attribute.isMandatory(),
// false, true, 20, INSTANCE_VALUE_LENGTH, null, null);
Textbox editor = new Textbox();
if (instance != null)
editor.setText(instance.getValue());
row.appendChild(editor);
if (readOnly)
editor.setEnabled(false);
else
m_editors.add (editor);
}
} // addAttributeLine
/**
* dispose
*/
public void dispose()
{
Env.clearWinContext(m_WindowNo);
//
Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID",
String.valueOf(m_M_AttributeSetInstance_ID));
Env.setContext(Env.getCtx(), Env.WINDOW_INFO, Env.TAB_INFO, "M_Locator_ID",
String.valueOf(m_M_Locator_ID));
//
this.detach();
} // dispose
public void onEvent(Event e) throws Exception
{
// Select Instance
if (e.getTarget() == bSelect)
{
if (cmd_select())
dispose();
}
// New/Edit
else if (e.getTarget() == cbNewEdit)
{
cmd_newEdit();
}
// Select Lot from existing
else if (e.getTarget() == fieldLot)
{
ListItem pp = fieldLot.getSelectedItem();
if (pp != null && (Integer)pp.getValue() != -1)
{
fieldLotString.setText(pp.getLabel());
fieldLotString.setReadonly(true);
m_masi.setM_Lot_ID((Integer)pp.getValue());
}
else
{
fieldLotString.setReadonly(false);
m_masi.setM_Lot_ID(0);
}
}
// Create New Lot
else if (e.getTarget() == bLot)
{
KeyNamePair pp = m_masi.createLot(m_M_Product_ID);
if (pp != null)
{
ListItem item = new ListItem(pp.getName(), pp.getKey());
fieldLot.appendChild(item);
fieldLot.setSelectedItem(item);
}
}
// Create New SerNo
else if (e.getTarget() == bSerNo)
{
fieldSerNo.setText(m_masi.getSerNo(true));
}
// OK
else if (e.getTarget().getId().equals("Ok"))
{
if (saveSelection())
dispose();
}
// Cancel
else if (e.getTarget().getId().equals("Cancel"))
{
m_changed = false;
m_M_AttributeSetInstance_ID = 0;
m_M_Locator_ID = 0;
dispose();
}
// Zoom M_Lot
else if (e.getTarget() == mZoom)
{
cmd_zoom();
}
else
log.log(Level.SEVERE, "not found - " + e);
} // actionPerformed
/**
* Instance Selection Button
* @return true if selected
*/
private boolean cmd_select()
{
log.config("");
int M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "M_Warehouse_ID");
int C_DocType_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, "C_DocType_ID");
if (C_DocType_ID > 0) {
MDocType doctype = new MDocType (Env.getCtx(), C_DocType_ID, null);
String docbase = doctype.getDocBaseType();
if (docbase.equals(MDocType.DOCBASETYPE_MaterialReceipt))
M_Warehouse_ID = 0;
}
// teo_sarca [ 1564520 ] Inventory Move: can't select existing attributes
int M_Locator_ID = 0;
if (m_AD_Column_ID == 8551) { // TODO: hardcoded: M_MovementLine[324].M_AttributeSetInstance_ID[8551]
M_Locator_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNoParent, X_M_MovementLine.COLUMNNAME_M_Locator_ID, true); // only window
}
String title = "";
// Get Text
String sql = "SELECT p.Name, w.Name, w.M_Warehouse_ID FROM M_Product p, M_Warehouse w "
+ "WHERE p.M_Product_ID=? AND w.M_Warehouse_ID"
+ (M_Locator_ID <= 0 ? "=?" : " IN (SELECT M_Warehouse_ID FROM M_Locator where M_Locator_ID=?)"); // teo_sarca [ 1564520 ]
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, M_Locator_ID <= 0 ? M_Warehouse_ID : M_Locator_ID);
rs = pstmt.executeQuery();
if (rs.next()) {
title = rs.getString(1) + " - " + rs.getString(2);
M_Warehouse_ID = rs.getInt(3); // fetch the actual warehouse - teo_sarca [ 1564520 ]
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
//
WPAttributeInstance pai = new WPAttributeInstance(title,
M_Warehouse_ID, M_Locator_ID, m_M_Product_ID, m_C_BPartner_ID);
if (pai.getM_AttributeSetInstance_ID() != -1)
{
m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
m_M_AttributeSetInstanceName = pai.getM_AttributeSetInstanceName();
m_M_Locator_ID = pai.getM_Locator_ID();
m_changed = true;
return true;
}
return false;
} // cmd_select
/**
* Instance New/Edit
*/
private void cmd_newEdit()
{
boolean rw = cbNewEdit.isChecked();
log.config("R/W=" + rw + " " + m_masi);
//
fieldLotString.setReadonly(!(rw && m_masi.getM_Lot_ID()==0));
if (fieldLot != null)
fieldLot.setEnabled(rw);
bLot.setEnabled(rw);
fieldSerNo.setReadonly(!rw);
bSerNo.setEnabled(rw);
fieldGuaranteeDate.setReadonly(!rw);
//
for (int i = 0; i < m_editors.size(); i++)
{
HtmlBasedComponent editor = m_editors.get(i);
if (editor instanceof InputElement)
((InputElement)editor).setReadonly(!rw);
else if (editor instanceof Listbox)
((Listbox)editor).setEnabled(rw);
}
} // cmd_newEdit
/**
* Zoom M_Lot
*/
private void cmd_zoom()
{
int M_Lot_ID = 0;
ListItem pp = fieldLot.getSelectedItem();
if (pp != null)
M_Lot_ID = (Integer) pp.getValue();
MQuery zoomQuery = new MQuery("M_Lot");
zoomQuery.addRestriction("M_Lot_ID", MQuery.EQUAL, M_Lot_ID);
log.info(zoomQuery.toString());
//
//TODO: to port
/*
int AD_Window_ID = 257; // Lot
AWindow frame = new AWindow();
if (frame.initWindow(AD_Window_ID, zoomQuery))
{
this.setVisible(false);
this.setModal (false); // otherwise blocked
this.setVisible(true);
AEnv.addToWindowManager(frame);
AEnv.showScreen(frame, SwingConstants.EAST);
}*/
} // cmd_zoom
/**
* Save Selection
* @return true if saved
*/
private boolean saveSelection()
{
log.info("");
MAttributeSet as = m_masi.getMAttributeSet();
if (as == null)
return true;
//
m_changed = false;
String mandatory = "";
if (!m_productWindow && as.isLot())
{
log.fine("Lot=" + fieldLotString.getText ());
String text = fieldLotString.getText();
m_masi.setLot (text);
if (as.isLotMandatory() && (text == null || text.length() == 0))
mandatory += " - " + Msg.translate(Env.getCtx(), "Lot");
m_changed = true;
} // Lot
if (!m_productWindow && as.isSerNo())
{
log.fine("SerNo=" + fieldSerNo.getText());
String text = fieldSerNo.getText();
m_masi.setSerNo(text);
if (as.isSerNoMandatory() && (text == null || text.length() == 0))
mandatory += " - " + Msg.translate(Env.getCtx(), "SerNo");
m_changed = true;
} // SerNo
if (!m_productWindow && as.isGuaranteeDate())
{
log.fine("GuaranteeDate=" + fieldGuaranteeDate.getValue());
Timestamp ts = (Timestamp)fieldGuaranteeDate.getValue();
m_masi.setGuaranteeDate(ts);
if (as.isGuaranteeDateMandatory() && ts == null)
mandatory += " - " + Msg.translate(Env.getCtx(), "GuaranteeDate");
m_changed = true;
} // GuaranteeDate
// *** Save Attributes ***
// New Instance
if (m_changed || m_masi.getM_AttributeSetInstance_ID() == 0)
{
m_masi.save ();
m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID ();
m_M_AttributeSetInstanceName = m_masi.getDescription();
}
// Save Instance Attributes
MAttribute[] attributes = as.getMAttributes(!m_productWindow);
for (int i = 0; i < attributes.length; i++)
{
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributes[i].getAttributeValueType()))
{
Listbox editor = (Listbox)m_editors.get(i);
MAttributeValue value = (MAttributeValue)editor.getSelectedItem().getValue();
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && value == null)
mandatory += " - " + attributes[i].getName();
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
}
else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributes[i].getAttributeValueType()))
{
NumberBox editor = (NumberBox)m_editors.get(i);
BigDecimal value = new BigDecimal(editor.getValue());
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && value == null)
mandatory += " - " + attributes[i].getName();
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
}
else
{
Textbox editor = (Textbox)m_editors.get(i);
String value = editor.getText();
log.fine(attributes[i].getName() + "=" + value);
if (attributes[i].isMandatory() && (value == null || value.length() == 0))
mandatory += " - " + attributes[i].getName();
attributes[i].setMAttributeInstance(m_M_AttributeSetInstance_ID, value);
}
m_changed = true;
} // for all attributes
// Save Model
if (m_changed)
{
m_masi.setDescription ();
m_masi.save ();
}
m_M_AttributeSetInstance_ID = m_masi.getM_AttributeSetInstance_ID ();
m_M_AttributeSetInstanceName = m_masi.getDescription();
//
if (mandatory.length() > 0)
{
FDialog.error(m_WindowNo, this, "FillMandatory", mandatory);
return false;
}
return true;
} // saveSelection
/**************************************************************************
* Get Instance ID
* @return Instance ID
*/
public int getM_AttributeSetInstance_ID()
{
return m_M_AttributeSetInstance_ID;
} // getM_AttributeSetInstance_ID
/**
* Get Instance Name
* @return Instance Name
*/
public String getM_AttributeSetInstanceName()
{
return m_M_AttributeSetInstanceName;
} // getM_AttributeSetInstanceName
/**
* Get Locator ID
* @return M_Locator_ID
*/
public int getM_Locator_ID()
{
return m_M_Locator_ID;
}
/**
* Value Changed
* @return true if changed
*/
public boolean isChanged()
{
return m_changed;
} // isChanged
} // WPAttributeDialog

View File

@ -0,0 +1,376 @@
/******************************************************************************
* 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.sql.*;
import java.util.logging.*;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.WListbox;
import org.adempiere.webui.component.Window;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.util.*;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
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.Hbox;
/**
* Display Product Attribute Instance Info
*
* @author Jorg Janke
* @version $Id: PAttributeInstance.java,v 1.3 2006/07/30 00:51:27 jjanke Exp $
*/
public class WPAttributeInstance extends Window implements EventListener
{
/**
* Constructor
* @param title title
* @param M_Warehouse_ID warehouse key name pair
* @param M_Locator_ID locator
* @param M_Product_ID product key name pair
* @param C_BPartner_ID bp
*/
public WPAttributeInstance(String title,
int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int C_BPartner_ID)
{
super ();
this.setTitle(Msg.getMsg(Env.getCtx(), "PAttributeInstance") + title);
this.setAttribute("modal", Boolean.TRUE);
this.setBorder("normal");
this.setWidth("500px");
this.setHeight("550px");
init (M_Warehouse_ID, M_Locator_ID, M_Product_ID, C_BPartner_ID);
AEnv.showCenterScreen(this);
} // PAttributeInstance
/**
* Initialization
* @param M_Warehouse_ID wh
* @param M_Locator_ID loc
* @param M_Product_ID product
* @param C_BPartner_ID partner
*/
private void init (int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int C_BPartner_ID)
{
log.info("M_Warehouse_ID=" + M_Warehouse_ID
+ ", M_Locator_ID=" + M_Locator_ID
+ ", M_Product_ID=" + M_Product_ID);
m_M_Warehouse_ID = M_Warehouse_ID;
m_M_Locator_ID = M_Locator_ID;
m_M_Product_ID = M_Product_ID;
try
{
init();
dynInit(C_BPartner_ID);
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
} // init
private Borderlayout mainLayout = new Borderlayout();
private Panel northPanel = new Panel();
private ConfirmPanel confirmPanel = new ConfirmPanel (true);
private Checkbox showAll = new Checkbox();
//
private WListbox m_table = new WListbox();
// Parameter
private int m_M_Warehouse_ID;
private int m_M_Locator_ID;
private int m_M_Product_ID;
//
private int m_M_AttributeSetInstance_ID = -1;
private String m_M_AttributeSetInstanceName = null;
private String m_sql;
/** Logger */
private static CLogger log = CLogger.getCLogger(WPAttributeInstance.class);
/**
* Static Init
* @throws Exception
*/
private void init() throws Exception
{
showAll.setLabel(Msg.getMsg(Env.getCtx(), "ShowAll"));
this.appendChild(mainLayout);
// North
Hbox box = new Hbox();
box.setParent(northPanel);
box.setPack("end");
box.appendChild(showAll);
showAll.addEventListener(Events.ON_CHECK, this);
North north = new North();
north.setParent(mainLayout);
north.appendChild(northPanel);
// Center
Center center = new Center();
center.setParent(mainLayout);
center.setFlex(true);
center.appendChild(m_table);
// South
South south = new South();
south.setParent(mainLayout);
south.appendChild(confirmPanel);
confirmPanel.addEventListener(Events.ON_CLICK, this);
} // jbInit
/** Table Column Layout Info */
private static ColumnInfo[] s_layout = new ColumnInfo[]
{
new ColumnInfo(" ", "s.M_AttributeSetInstance_ID", IDColumn.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Description"), "asi.Description", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Lot"), "asi.Lot", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "SerNo"), "asi.SerNo", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "GuaranteeDate"), "asi.GuaranteeDate", Timestamp.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "M_Locator_ID"), "l.Value", KeyNamePair.class, "s.M_Locator_ID"),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "s.QtyOnHand", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "s.QtyReserved", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOrdered"), "s.QtyOrdered", Double.class),
// See RV_Storage
new ColumnInfo(Msg.translate(Env.getCtx(), "GoodForDays"), "(TRUNC(asi.GuaranteeDate)-TRUNC(SysDate))-p.GuaranteeDaysMin", Integer.class, true, true, null),
new ColumnInfo(Msg.translate(Env.getCtx(), "ShelfLifeDays"), "TRUNC(asi.GuaranteeDate)-TRUNC(SysDate)", Integer.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "ShelfLifeRemainingPct"), "CASE WHEN p.GuaranteeDays > 0 THEN TRUNC(((TRUNC(asi.GuaranteeDate)-TRUNC(SysDate))/p.GuaranteeDays)*100) ELSE 0 END", Integer.class),
};
/** From Clause */
private static String s_sqlFrom = "M_Storage s"
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)"
+ " INNER JOIN M_Product p ON (s.M_Product_ID=p.M_Product_ID)"
+ " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID)";
/** Where Clause */
private static String s_sqlWhere = "s.M_Product_ID=? AND l.M_Warehouse_ID=?";
private static String s_sqlWhereWithoutWarehouse = " s.M_Product_ID=?";
private String m_sqlNonZero = " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)";
private String m_sqlMinLife = "";
/**
* Dynamic Init
* @param C_BPartner_ID BP
*/
private void dynInit(int C_BPartner_ID)
{
log.config("C_BPartner_ID=" + C_BPartner_ID);
if (C_BPartner_ID != 0)
{
int ShelfLifeMinPct = 0;
int ShelfLifeMinDays = 0;
String sql = "SELECT bp.ShelfLifeMinPct, bpp.ShelfLifeMinPct, bpp.ShelfLifeMinDays "
+ "FROM C_BPartner bp "
+ " LEFT OUTER JOIN C_BPartner_Product bpp"
+ " ON (bp.C_BPartner_ID=bpp.C_BPartner_ID AND bpp.M_Product_ID=?) "
+ "WHERE bp.C_BPartner_ID=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, C_BPartner_ID);
rs = pstmt.executeQuery();
if (rs.next())
{
ShelfLifeMinPct = rs.getInt(1); // BP
int pct = rs.getInt(2); // BP_P
if (pct > 0) // overwrite
ShelfLifeMinDays = pct;
ShelfLifeMinDays = rs.getInt(3);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
if (ShelfLifeMinPct > 0)
{
m_sqlMinLife = " AND COALESCE(TRUNC(((TRUNC(asi.GuaranteeDate)-TRUNC(SysDate))/p.GuaranteeDays)*100),0)>=" + ShelfLifeMinPct;
log.config( "PAttributeInstance.dynInit - ShelfLifeMinPct=" + ShelfLifeMinPct);
}
if (ShelfLifeMinDays > 0)
{
m_sqlMinLife += " AND COALESCE((TRUNC(asi.GuaranteeDate)-TRUNC(SysDate)),0)>=" + ShelfLifeMinDays;
log.config( "PAttributeInstance.dynInit - ShelfLifeMinDays=" + ShelfLifeMinDays);
}
} // BPartner != 0
m_sql = m_table.prepareTable (s_layout, s_sqlFrom,
m_M_Warehouse_ID == 0 ? s_sqlWhereWithoutWarehouse : s_sqlWhere, false, "s")
+ " ORDER BY asi.GuaranteeDate, s.QtyOnHand"; // oldest, smallest first
//
m_table.addEventListener(Events.ON_SELECT, this);
//
refresh();
} // dynInit
/**
* Refresh Query
*/
private void refresh()
{
String sql = m_sql;
int pos = m_sql.lastIndexOf(" ORDER BY ");
if (!showAll.isChecked())
{
sql = m_sql.substring(0, pos)
+ m_sqlNonZero;
if (m_sqlMinLife.length() > 0)
sql += m_sqlMinLife;
sql += m_sql.substring(pos);
}
//
log.finest(sql);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
if (m_M_Warehouse_ID != 0)
pstmt.setInt(2, m_M_Warehouse_ID);
rs = pstmt.executeQuery();
m_table.loadTable(rs);
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
enableButtons();
} // refresh
public void onEvent(Event e) throws Exception
{
if (e.getTarget().getId().equals("Ok"))
detach();
else if (e.getTarget().getId().equals("Cancel"))
{
detach();
m_M_AttributeSetInstance_ID = -1;
m_M_AttributeSetInstanceName = null;
}
else if (e.getTarget() == showAll)
{
refresh();
}
else if (e.getTarget() == m_table)
{
enableButtons();
}
} // actionPerformed
/**
* Enable/Set Buttons and set ID
*/
private void enableButtons()
{
m_M_AttributeSetInstance_ID = -1;
m_M_AttributeSetInstanceName = null;
m_M_Locator_ID = 0;
int row = m_table.getSelectedRow();
boolean enabled = row != -1;
if (enabled)
{
Integer ID = m_table.getSelectedRowKey();
if (ID != null)
{
m_M_AttributeSetInstance_ID = ID.intValue();
m_M_AttributeSetInstanceName = (String)m_table.getValueAt(row, 1);
//
Object oo = m_table.getValueAt(row, 5);
if (oo instanceof KeyNamePair)
{
KeyNamePair pp = (KeyNamePair)oo;
m_M_Locator_ID = pp.getKey();
}
}
}
confirmPanel.getButton("Ok").setEnabled(enabled);
log.fine("M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID
+ " - " + m_M_AttributeSetInstanceName
+ "; M_Locator_ID=" + m_M_Locator_ID);
} // enableButtons
//TODO: double click support for WListbox
/**
* Mouse Clicked
* @param e event
*/
/*
public void mouseClicked(MouseEvent e)
{
// Double click with selected row => exit
if (e.getClickCount() > 1 && m_table.getSelectedRow() != -1)
{
enableButtons();
dispose();
}
}*/ // mouseClicked
/**
* Get Attribute Set Instance
* @return M_AttributeSetInstance_ID or -1
*/
public int getM_AttributeSetInstance_ID()
{
return m_M_AttributeSetInstance_ID;
} // getM_AttributeSetInstance_ID
/**
* Get Instance Name
* @return Instance Name
*/
public String getM_AttributeSetInstanceName()
{
return m_M_AttributeSetInstanceName;
} // getM_AttributeSetInstanceName
/**
* Get Locator
* @return M_Locator_ID or 0
*/
public int getM_Locator_ID()
{
return m_M_Locator_ID;
} // getM_Locator_ID
} // PAttributeInstance