[ 2135724 ] Product Info Screen Doesn't include avl in other warehouse

This commit is contained in:
Heng Sin Low 2008-11-28 03:26:06 +00:00
parent 4a9464266c
commit 09435bc9fa
4 changed files with 1618 additions and 37 deletions

View File

@ -0,0 +1,371 @@
/******************************************************************************
* Copyright (C) 2008 Elaine Tan *
* 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. *
*****************************************************************************/
package org.adempiere.webui.panel;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.logging.Level;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Checkbox;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.WListbox;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.event.WTableModelEvent;
import org.adempiere.webui.event.WTableModelListener;
import org.compiere.apps.search.PAttributeInstance;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
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.event.Event;
import org.zkoss.zk.ui.event.EventListener;
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.Div;
/**
* Display Product Attribute Instance Info
* This class is based on org.compiere.apps.search.PAttributeInstance written by Jorg Janke
* @author Elaine
*
*/
public class InfoPAttributeInstancePanel extends Window implements EventListener, WTableModelListener
{
private static final long serialVersionUID = 1L;
/**
* Constructor
* @param parent frame parent
* @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 InfoPAttributeInstancePanel(Window parent, String title,
int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int C_BPartner_ID)
{
super();
setTitle(Msg.getMsg(Env.getCtx(), "PAttributeInstance"));
init (M_Warehouse_ID, M_Locator_ID, M_Product_ID, C_BPartner_ID);
AEnv.showCenterWindow(parent, 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
{
jbInit();
dynInit(C_BPartner_ID);
}
catch (Exception e)
{
log.log(Level.SEVERE, "", e);
}
} // init
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(PAttributeInstance.class);
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
showAll.setText(Msg.getMsg(Env.getCtx(), "ShowAll"));
Borderlayout borderlayout = new Borderlayout();
borderlayout.setWidth("700px");
borderlayout.setHeight("400px");
borderlayout.setStyle("border: none; position: relative");
this.appendChild(borderlayout);
North north = new North();
borderlayout.appendChild(north);
Div div = new Div();
div.setAlign("right");
div.appendChild(showAll);
north.appendChild(div);
Center center = new Center();
center.setAutoscroll(true);
center.setFlex(true);
borderlayout.appendChild(center);
center.appendChild(m_table);
South south = new South();
borderlayout.appendChild(south);
south.appendChild(confirmPanel);
// ConfirmPanel
confirmPanel.addActionListener(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.setMultiSelection(false);
m_table.getModel().addTableModelListener(this);
//
refresh();
} // dynInit
/**
* Refresh Query
*/
private void refresh()
{
String sql = m_sql;
int pos = m_sql.lastIndexOf(" ORDER BY ");
if (!showAll.isSelected())
{
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
/**
* Action Listener
* @param e event
*/
public void onEvent(Event e) throws Exception
{
if (e.getTarget().getId().equals(ConfirmPanel.A_OK))
{
dispose();
}
else if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
{
dispose();
m_M_AttributeSetInstance_ID = -1;
m_M_AttributeSetInstanceName = null;
}
else if (e.getTarget() == showAll)
{
refresh();
}
}
/**
* Table selection changed
* @param e event
*/
public void tableChanged(WTableModelEvent e)
{
enableButtons();
}
/**
* 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.getOKButton().setEnabled(enabled);
log.fine("M_AttributeSetInstance_ID=" + m_M_AttributeSetInstance_ID
+ " - " + m_M_AttributeSetInstanceName
+ "; M_Locator_ID=" + m_M_Locator_ID);
} // enableButtons
/**
* 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

View File

@ -0,0 +1,630 @@
/******************************************************************************
* Copyright (C) 2008 Elaine Tan *
* 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. *
*****************************************************************************/
package org.adempiere.webui.panel;
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.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.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.editor.WNumberEditor;
import org.adempiere.webui.editor.WStringEditor;
import org.compiere.apps.search.InfoPAttribute;
import org.compiere.model.MAttribute;
import org.compiere.model.MRole;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zul.Div;
import org.zkoss.zul.Separator;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Vbox;
/**
* Search by Product Attribute.
* This class is based on org.compiere.apps.search.InfoPAttribute written by Jorg Janke
* @author Elaine
*
*/
public class InfoPAttributePanel extends Window implements EventListener
{
private static final long serialVersionUID = 1L;
/**
* Constructor.
* Called from InfoProduct,cmd_InfoPAttribute
* @param parent
*/
public InfoPAttributePanel(Window parent)
{
super();
setTitle(Msg.getMsg(Env.getCtx(), "InfoPAttribute"));
try
{
jbInit();
dynInit();
}
catch (Exception e)
{
log.log(Level.SEVERE, "InfoPAttribute", e);
}
AEnv.showCenterWindow(parent, this);
} // InfoPAttribute
/** Resulting Query */
private String m_query = "";
/** Product Attribure Editors */
private ArrayList<Component> m_productEditors = new ArrayList<Component>();
private ArrayList<Component> m_productEditorsTo = new ArrayList<Component>();
/** Instance Attribute Editors */
private ArrayList<Component> m_instanceEditors = new ArrayList<Component>();
private ArrayList<Component> m_instanceEditorsTo = new ArrayList<Component>();
/** Logger */
private static CLogger log = CLogger.getCLogger(InfoPAttribute.class);
private Rows rows = null;
private ConfirmPanel confirmPanel = new ConfirmPanel(true);
//
private Label serNoLabel = new Label(Msg.translate(Env.getCtx(), "SerNo"));
private WStringEditor serNoField = new WStringEditor("SerNo", false, false, true, 10, 20, null, null);
private Label lotLabel = new Label(Msg.translate(Env.getCtx(), "Lot"));
private WStringEditor lotField = new WStringEditor("Lot", false, false, true, 10, 20, null, null);
private Listbox guaranteeDateSelection = null;
private Datebox guaranteeDateField = new Datebox();
private Label lotLabel2 = new Label(Msg.translate(Env.getCtx(), "M_Lot_ID"));
private Listbox lotSelection = null;
//
/**
* Static Init
* @throws Exception
*/
private void jbInit() throws Exception
{
Vbox vbox = new Vbox();
this.appendChild(vbox);
Grid grid = new Grid();
grid.setWidth("400px");
grid.setStyle("margin:0; padding:0;");
grid.makeNoStrip();
grid.setOddRowSclass("even");
vbox.appendChild(grid);
rows = new Rows();
grid.appendChild(rows);
// ConfirmPanel
confirmPanel.addActionListener(this);
vbox.appendChild(confirmPanel);
} // jbInit
/**
* Dynamic Init of the Center Panel
*/
private void dynInit()
{
addAttributes();
//
String s = Msg.translate(Env.getCtx(), "GuaranteeDate");
guaranteeDateSelection = new Listbox();
guaranteeDateSelection.setRows(0);
guaranteeDateSelection.setMultiple(false);
guaranteeDateSelection.setMold("select");
guaranteeDateSelection.setWidth("150px");
guaranteeDateSelection.appendItem(s + " <", s + " <");
guaranteeDateSelection.appendItem(s + " =", s + " =");
guaranteeDateSelection.appendItem(s + " >", s + " >");
initLotSelection();
// Fixed Instance Selection Fields
Row row = new Row();
rows.appendChild(row);
Div div = new Div();
div.setAlign("right");
div.appendChild(serNoLabel);
row.appendChild(div);
row.appendChild(serNoField.getComponent());
serNoField.getComponent().setWidth("150px");
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel);
row.appendChild(div);
row.appendChild(lotField.getComponent());
lotField.getComponent().setWidth("150px");
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(lotLabel2);
row.appendChild(div);
row.appendChild(lotSelection);
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(guaranteeDateSelection);
row.appendChild(div);
row.appendChild(guaranteeDateField);
} // dynInit
/**
* Add Attributes
* @return rows
*/
private int addAttributes()
{
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Attribute_ID, Name, Description, AttributeValueType, IsInstanceAttribute "
+ "FROM M_Attribute "
+ "WHERE IsActive='Y' "
+ "ORDER BY IsInstanceAttribute, Name",
"M_Attribute", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
try
{
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
boolean instanceLine = false;
while (rs.next())
{
int attribute_ID = rs.getInt(1);
String name = rs.getString(2);
String description = rs.getString(3);
String attributeValueType = rs.getString(4);
boolean isInstanceAttribute = "Y".equals(rs.getString(5));
// Instance switch
if (!instanceLine && isInstanceAttribute)
{
Row row = new Row();
rows.appendChild(row);
row.setSpans("2");
Label group = new Label(Msg.translate(Env.getCtx(), "IsInstanceAttribute"));
row.appendChild(group);
rows.appendChild(row);
row = new Row();
rows.appendChild(row);
row.setSpans("2");
Separator separator = new Separator();
separator.setBar(true);
row.appendChild(separator);
rows.appendChild(row);
instanceLine = true;
}
//
Row row = new Row();
rows.appendChild(row);
Label label = new Label(name);
if (description != null && description.length() > 0)
label.setTooltiptext(description);
Div div = new Div();
div.setAlign("right");
div.appendChild(label);
row.appendChild(div);
Component field = null;
if (MAttribute.ATTRIBUTEVALUETYPE_List.equals(attributeValueType))
{
field = new Listbox();
((Listbox) field).setRows(0);
((Listbox) field).setMultiple(false);
((Listbox) field).setMold("select");
((Listbox) field).setWidth("150px");
KeyNamePair[] knp = getAttributeList(attribute_ID);
for(int i = 0; i < knp.length; i++)
((Listbox) field).appendItem(knp[i].getName(), knp[i]);
}
else if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
{
field = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
((NumberBox) field).setWidth("150px");
}
else
{
field = new WStringEditor(name, false, false, true, 10, 40, null, null).getComponent();
((Textbox) field).setWidth("150px");
}
row.appendChild(field);
//
field.setId(String.valueOf(attribute_ID));
if (isInstanceAttribute)
m_instanceEditors.add(field);
else
m_productEditors.add(field);
// To (numbers)
Component fieldTo = null;
if (MAttribute.ATTRIBUTEVALUETYPE_Number.equals(attributeValueType))
{
fieldTo = new WNumberEditor(name, false, false, true, DisplayType.Number, name).getComponent();
((NumberBox) fieldTo).setWidth("150px");
row = new Row();
rows.appendChild(row);
div = new Div();
div.setAlign("right");
div.appendChild(new Label("-"));
row.appendChild(div);
row.appendChild(fieldTo);
}
if (isInstanceAttribute)
m_instanceEditorsTo.add(fieldTo);
else
m_productEditorsTo.add(fieldTo);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return 0;
} // addProductAttributes
/**
* Get Attribute List
* @param M_Attribute_ID attribure
* @return array
*/
private KeyNamePair[] getAttributeList(int M_Attribute_ID)
{
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));
PreparedStatement pstmt = null;
ResultSet rs = null;
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_AttributeValue_ID, Value, Name "
+ "FROM M_AttributeValue "
+ "WHERE M_Attribute_ID=? "
+ "ORDER BY 2",
"M_AttributeValue", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_Attribute_ID);
rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(3)));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
KeyNamePair[] retValue = new KeyNamePair[list.size()];
list.toArray(retValue);
return retValue;
} // getAttributeList
/**
* Initialize Lot Selection
*/
private void initLotSelection()
{
ArrayList<KeyNamePair> list = new ArrayList<KeyNamePair>();
list.add(new KeyNamePair(-1, ""));
String sql = MRole.getDefault().addAccessSQL(
"SELECT M_Lot_ID, Name FROM M_Lot WHERE IsActive='Y' ORDER BY 2",
"M_Lot", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
rs = pstmt.executeQuery();
while (rs.next())
list.add(new KeyNamePair(rs.getInt(1), rs.getString(2)));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Create List
KeyNamePair[] items = new KeyNamePair[list.size()];
list.toArray(items);
lotSelection = new Listbox();
lotSelection.setRows(0);
lotSelection.setMultiple(false);
lotSelection.setMold("select");
lotSelection.setWidth("150px");
for(int i = 0; i < items.length; i++)
lotSelection.appendItem(items[i].getName(), items[i]);
} // initLotSelection
/**
* Action Listener
* @param e event
*/
public void onEvent(Event e) throws Exception
{
if (e.getTarget().getId().equals(ConfirmPanel.A_OK))
{
createQuery();
dispose();
}
else if (e.getTarget().getId().equals(ConfirmPanel.A_CANCEL))
{
m_query = null;
dispose();
}
} // actionPerformed
/**
* Create Query
* <code>
* Available synonyms:
* M_Product p
* M_ProductPrice pr
* M_AttributeSet pa
* </code>
* @return query
*/
private String createQuery()
{
/** Base Query
SELECT *
FROM M_Product p
INNER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID)
LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)
WHERE
**/
/*** Instance Attributes */
StringBuffer sb = new StringBuffer();
// Serial No
String s = serNoField.getComponent().getText();
if (s != null && s.length() > 0)
{
sb.append(" AND asi.SerNo");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot Number
s = lotField.getComponent().getText();
if (s != null && s.length() > 0)
{
sb.append(" AND asi.Lot");
if (s.indexOf('%') == -1 && s.indexOf('_') == 1)
sb.append("=");
else
sb.append(" LIKE ");
sb.append(DB.TO_STRING(s));
}
// Lot ID
ListItem li = lotSelection.getSelectedItem();
if(li != null && li.getValue() != null)
{
KeyNamePair pp = (KeyNamePair) li.getValue();
if (pp != null && pp.getKey() != -1)
{
int ID = pp.getKey();
sb.append(" AND asi.M_Lot_ID=").append(ID);
}
}
// Guarantee Date
Timestamp ts = (Timestamp)guaranteeDateField.getValue();
if (ts != null)
{
sb.append(" AND TRUNC(asi.GuaranteeDate)");
int index = guaranteeDateSelection.getSelectedIndex(); // < = >
if (index == 0)
sb.append("<");
else if (index == 1)
sb.append("=");
else
sb.append(">");
sb.append(DB.TO_DATE(ts,true));
}
// Instance Editors
for (int i = 0; i < m_instanceEditors.size(); i++)
{
StringBuffer iAttr = new StringBuffer();
Component c = (Component)m_instanceEditors.get(i);
Component cTo = (Component)m_instanceEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getId());
if (c instanceof Listbox)
{
Listbox field = (Listbox)c;
li = field.getSelectedItem();
if(li != null && li.getValue() != null)
{
KeyNamePair pp = (KeyNamePair)li.getValue();
if (pp != null && pp.getKey() != -1)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
}
}
else if (c instanceof NumberBox)
{
NumberBox field = (NumberBox)c;
BigDecimal value = (BigDecimal)field.getValue();
NumberBox fieldTo = (NumberBox)cTo;
BigDecimal valueTo = (BigDecimal)fieldTo.getValue();
if (value != null || valueTo != null)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND ValueNumber");
if (value != null && valueTo == null)
iAttr.append("=").append(value);
else if (value == null && valueTo != null)
iAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
iAttr.append(" BETWEEN ").append(value)
.append(" AND ").append(valueTo);
}
}
else
{
Textbox field = (Textbox)c;
String value = field.getText();
if (value != null && value.length() > 0)
{
iAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
iAttr.append("=");
else
iAttr.append(" LIKE ");
iAttr.append(DB.TO_STRING(value));
}
}
// Add to where
if (iAttr.length() > 0)
sb.append(" AND asi.M_AttributeSetInstance_ID IN "
+ "(SELECT M_AttributeSetInstance_ID FROM M_AttributeInstance "
+ "WHERE ")
.append(iAttr).append(")");
}
// finish Instance Attributes
if (sb.length() > 0)
{
sb.insert(0, " AND EXISTS (SELECT * FROM M_Storage s"
+ " INNER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) "
+ "WHERE s.M_Product_ID=p.M_Product_ID");
sb.append(")");
}
// Product Attributes
for (int i = 0; i < m_productEditors.size(); i++)
{
StringBuffer pAttr = new StringBuffer();
Component c = (Component)m_productEditors.get(i);
Component cTo = (Component)m_productEditorsTo.get(i);
int M_Attribute_ID = Integer.parseInt(c.getId());
if (c instanceof Listbox)
{
Listbox field = (Listbox)c;
li = field.getSelectedItem();
if(li != null && li.getValue() != null)
{
KeyNamePair pp = (KeyNamePair)li.getValue();
if (pp != null && pp.getKey() != -1)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND M_AttributeValue_ID=").append(pp.getKey());
}
}
}
else if (c instanceof NumberBox)
{
NumberBox field = (NumberBox)c;
BigDecimal value = (BigDecimal)field.getValue();
NumberBox fieldTo = (NumberBox)cTo;
BigDecimal valueTo = (BigDecimal)fieldTo.getValue();
if (value != null || valueTo != null)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND ValueNumber");
if (value != null && valueTo == null)
pAttr.append("=").append(value);
else if (value == null && valueTo != null)
pAttr.append("<=").append(valueTo);
else if (value != null && valueTo != null)
pAttr.append(" BETWEEN ").append(value)
.append(" AND ").append(valueTo);
}
}
else
{
Textbox field = (Textbox)c;
String value = field.getText();
if (value != null && value.length() > 0)
{
pAttr.append("M_Attribute_ID=").append(M_Attribute_ID)
.append(" AND Value");
if (value.indexOf('%') == -1 && value.indexOf('_') == -1)
pAttr.append("=");
else
pAttr.append(" LIKE ");
pAttr.append(DB.TO_STRING(value));
}
}
// Add to Where
if (pAttr.length() > 0)
sb.append(" AND p.M_AttributeSetInstance_ID IN "
+ "(SELECT M_AttributeSetInstance_ID "
+ "FROM M_AttributeInstance WHERE ")
.append(pAttr).append(")");
}
//
m_query = null;
if (sb.length() > 0)
m_query = sb.toString();
log.config(m_query);
return m_query;
} // createQuery
/**
* Get resulting Query WHERE
* @return query or null
*/
public String getWhereClause()
{
return m_query;
} // getQuery
}

View File

@ -34,6 +34,7 @@ import org.adempiere.webui.component.WListbox;
import org.adempiere.webui.component.Window;
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.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
@ -333,9 +334,6 @@ public abstract class InfoPanel extends Window implements EventListener, WTableM
statusBar.setStatusDB(text);
} // setStatusDB
protected void prepareTable (ColumnInfo[] layout,
String from,
String where,
@ -699,6 +697,25 @@ public abstract class InfoPanel extends Window implements EventListener, WTableM
{
return InfoPanel.lISTENER_EVENTS;
}
// Elaine 2008/11/28
/**
* Enable OK, History, Zoom if row/s selected
* ---
* Changes: Changed the logic for accomodating multiple selection
* @author ashley
*/
protected void enableButtons ()
{
boolean enable = (contentPanel.getSelectedCount() == 1);
confirmPanel.getOKButton().setEnabled(contentPanel.getSelectedCount() > 0);
if (hasHistory())
confirmPanel.getButton(ConfirmPanel.A_HISTORY).setEnabled(enable);
if (hasZoom())
confirmPanel.getButton(ConfirmPanel.A_ZOOM).setEnabled(enable);
} // enableButtons
//
/**************************************************************************
* Get dynamic WHERE part of SQL
@ -861,6 +878,11 @@ public abstract class InfoPanel extends Window implements EventListener, WTableM
}
} // onEvent
public void tableChanged(WTableModelEvent event)
{
enableButtons();
}
public void zoom()
{
if (listeners != null && listeners.size() > 0)

View File

@ -39,43 +39,54 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import org.adempiere.webui.component.Button;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Label;
import org.adempiere.webui.component.ListItem;
import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.ListboxFactory;
import org.adempiere.webui.component.Panel;
import org.adempiere.webui.component.Tab;
import org.adempiere.webui.component.Tabbox;
import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.Tabpanels;
import org.adempiere.webui.component.Tabs;
import org.adempiere.webui.component.Textbox;
import org.adempiere.webui.component.WListbox;
import org.adempiere.webui.event.WTableModelEvent;
import org.compiere.minigrid.ColumnInfo;
import org.compiere.minigrid.IDColumn;
import org.compiere.model.MClient;
import org.compiere.model.MDocType;
import org.compiere.model.MRole;
import org.compiere.util.CLogMgt;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.zkoss.zk.ui.Component;
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.Hbox;
import org.zkoss.zul.Separator;
import org.zkoss.zul.Vbox;
/**
* Search Product and return selection
* This class is based on org.compiere.apps.search.InfoProduct written by Jorg Janke
* @author Sendy Yagambrum
*
* Search Product and return selection
* This class is based on org.compiere.apps.search.InfoPAttribute written by Jorg Janke
* @author Elaine
*
*/
public final class InfoProductPanel extends InfoPanel implements EventListener
{
/**
*
**/
private static final long serialVersionUID = 1L;
private Label lblValue = new Label();
@ -92,7 +103,31 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
private Listbox pickWarehouse = new Listbox();
private Label lblVendor = new Label();
private Textbox fieldVendor = new Textbox();
private Button p_attributeInfo;
// Elaine 2008/11/21
private Label lblProductCategory = new Label();
private Listbox pickProductCategory = new Listbox();
//
// Elaine 2008/11/25
private Borderlayout borderlayout = new Borderlayout();
private Textbox fieldDescription = new Textbox();
Tabbox tabbedPane = new Tabbox();
WListbox warehouseTbl = ListboxFactory.newDataTable();
String m_sqlWarehouse;
WListbox substituteTbl = ListboxFactory.newDataTable();
String m_sqlSubstitute;
WListbox relatedTbl = ListboxFactory.newDataTable();
String m_sqlRelated;
//Available to Promise Tab
private WListbox m_tableAtp = ListboxFactory.newDataTable();
private int m_M_Product_ID = 0;
int mWindowNo = 0;
//
/** Search Button */
private Button m_InfoPAttributeButton = new Button();
/** Instance Button */
private Button m_PAttributeButton = null;
/** SQL From */
private static final String s_productFrom =
"M_Product p"
@ -145,12 +180,12 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
executeQuery();
renderItems();
}
tabbedPane.setSelectedIndex(0);
p_loadedOK = true;
} // InfoProductPanel
/**
* initialize fields
*/
@ -166,15 +201,18 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
lblSKU.setValue(Msg.translate(Env.getCtx(), "SKU"));
lblPriceList = new Label();
lblPriceList.setValue(Msg.getMsg(Env.getCtx(), "PriceListVersion"));
// Elaine 2008/11/21
lblProductCategory = new Label();
lblProductCategory.setValue(Msg.translate(Env.getCtx(), "M_Product_Category_ID"));
//
lblWarehouse = new Label();
lblWarehouse.setValue(Msg.getMsg(Env.getCtx(), "Warehouse").substring(1));
lblVendor = new Label();
lblVendor.setValue(Msg.translate(Env.getCtx(), "Vendor"));
/* p_attributeInfo = new Button();
p_attributeInfo.setImage("/images/PAttribute16.png");
p_attributeInfo.setTooltiptext("Poduct Atribute Info");
p_attributeInfo.addEventListener(Events.ON_CLICK,this);*/
m_InfoPAttributeButton.setImage("/images/PAttribute16.png");
m_InfoPAttributeButton.setTooltiptext(Msg.getMsg(Env.getCtx(), "PAttribute"));
m_InfoPAttributeButton.addEventListener(Events.ON_CLICK,this);
fieldValue = new Textbox();
fieldValue.setMaxlength(40);
@ -191,6 +229,15 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
pickPriceList.setWidth("150px");
pickPriceList.addEventListener(Events.ON_SELECT, this);
// Elaine 2008/11/21
pickProductCategory = new Listbox();
pickProductCategory.setRows(0);
pickProductCategory.setMultiple(false);
pickProductCategory.setMold("select");
pickProductCategory.setWidth("150px");
pickProductCategory.addEventListener(Events.ON_SELECT, this);
//
pickWarehouse = new Listbox();
pickWarehouse.setRows(0);
pickWarehouse.setMultiple(false);
@ -203,13 +250,11 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
contentPanel = new WListbox();
contentPanel.setWidth("99%");
contentPanel.setHeight("400px");
contentPanel.setVflex(true);
} // initComponents
private void init()
{
Panel pnlValue = new Panel();
pnlValue.appendChild(lblValue);
pnlValue.appendChild(fieldValue);
@ -235,6 +280,13 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
pnlPriceList.appendChild(pickPriceList);
pnlPriceList.setAlign("right");
// Elaine 2008/11/21
Panel pnlProductCategory = new Panel();
pnlProductCategory.appendChild(lblProductCategory);
pnlProductCategory.appendChild(pickProductCategory);
pnlProductCategory.setAlign("right");
//
Panel pnlWarehouse = new Panel();
pnlWarehouse.appendChild(lblWarehouse);
pnlWarehouse.appendChild(pickWarehouse);
@ -245,9 +297,9 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
pnlVendor.appendChild(fieldVendor);
pnlVendor.setAlign("right");
/*Panel pnlButton = new Panel();
pnlButton.appendChild(p_attributeInfo);
pnlButton.setAlign("left");*/
Panel pnlButton = new Panel();
pnlButton.appendChild(m_InfoPAttributeButton);
pnlButton.setAlign("left");
Vbox vbox1 = new Vbox();
vbox1.appendChild(pnlValue);
@ -262,28 +314,267 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
vbox3.appendChild(pnlVendor);
Vbox vbox4 = new Vbox();
/*vbox4.appendChild(pnlButton);*/
vbox4.appendChild(pnlPriceList);
vbox4.appendChild(pnlProductCategory); // Elaine 2008/11/21
Vbox vbox5 = new Vbox();
vbox5.appendChild(pnlButton);
Hbox parameterPanel = new Hbox();
parameterPanel.appendChild(vbox1);
parameterPanel.appendChild(vbox2);
parameterPanel.appendChild(vbox3);
parameterPanel.appendChild(vbox4);
parameterPanel.appendChild(vbox5);
// Product Attribute Instance
m_PAttributeButton = confirmPanel.createButton(ConfirmPanel.A_PATTRIBUTE);
confirmPanel.addComponentsLeft(m_PAttributeButton);
m_PAttributeButton.addActionListener(this);
m_PAttributeButton.setEnabled(false);
// Elaine 2008/11/25
fieldDescription.setMultiline(true);
fieldDescription.setReadonly(true);
//
ColumnInfo[] s_layoutWarehouse = new ColumnInfo[]{
new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "Warehouse", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "sum(QtyAvailable)", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "sum(QtyOnHand)", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "sum(QtyReserved)", Double.class)};
/** From Clause */
String s_sqlFrom = " M_PRODUCT_STOCK_V ";
/** Where Clause */
String s_sqlWhere = "Value = ?";
m_sqlWarehouse = warehouseTbl.prepareTable(s_layoutWarehouse, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_STOCK_V");
m_sqlWarehouse += " Group By Warehouse, documentnote ";
warehouseTbl.setMultiSelection(false);
warehouseTbl.autoSize();
warehouseTbl.getModel().addTableModelListener(this);
ColumnInfo[] s_layoutSubstitute = new ColumnInfo[]{
new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class),
new ColumnInfo(
Msg.translate(Env.getCtx(), "Value"),
"(Select Value from M_Product p where p.M_Product_ID=M_PRODUCT_SUBSTITUTERELATED_V.Substitute_ID)",
String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class)};
s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V";
s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'S'";
m_sqlSubstitute = substituteTbl.prepareTable(s_layoutSubstitute, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V");
substituteTbl.setMultiSelection(false);
substituteTbl.autoSize();
substituteTbl.getModel().addTableModelListener(this);
ColumnInfo[] s_layoutRelated = new ColumnInfo[]{
new ColumnInfo(Msg.translate(Env.getCtx(), "Warehouse"), "orgname", String.class),
new ColumnInfo(
Msg.translate(Env.getCtx(), "Value"),
"(Select Value from M_Product p where p.M_Product_ID=M_PRODUCT_SUBSTITUTERELATED_V.Substitute_ID)",
String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), "Name", String.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyAvailable"), "QtyAvailable", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyOnHand"), "QtyOnHand", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "QtyReserved"), "QtyReserved", Double.class),
new ColumnInfo(Msg.translate(Env.getCtx(), "PriceStd"), "PriceStd", Double.class)};
s_sqlFrom = "M_PRODUCT_SUBSTITUTERELATED_V";
s_sqlWhere = "M_Product_ID = ? AND M_PriceList_Version_ID = ? and RowType = 'R'";
m_sqlRelated = relatedTbl.prepareTable(s_layoutRelated, s_sqlFrom, s_sqlWhere, false, "M_PRODUCT_SUBSTITUTERELATED_V");
relatedTbl.setMultiSelection(false);
relatedTbl.autoSize();
relatedTbl.getModel().addTableModelListener(this);
//Available to Promise Tab
m_tableAtp.setMultiSelection(false);
tabbedPane.setHeight("100%");
Tabpanels tabPanels = new Tabpanels();
tabbedPane.appendChild(tabPanels);
Tabs tabs = new Tabs();
tabbedPane.appendChild(tabs);
Tab tab = new Tab(Msg.translate(Env.getCtx(), "Warehouse"));
tabs.appendChild(tab);
Tabpanel desktopTabPanel = new Tabpanel();
desktopTabPanel.setHeight("100%");
desktopTabPanel.appendChild(warehouseTbl);
tabPanels.appendChild(desktopTabPanel);
tab = new Tab(Msg.translate(Env.getCtx(), "Description"));
tabs.appendChild(tab);
desktopTabPanel = new Tabpanel();
desktopTabPanel.setHeight("100%");
fieldDescription.setWidth("99%");
fieldDescription.setHeight("99%");
desktopTabPanel.appendChild(fieldDescription);
tabPanels.appendChild(desktopTabPanel);
tab = new Tab(Msg.translate(Env.getCtx(), "Substitute_ID"));
tabs.appendChild(tab);
desktopTabPanel = new Tabpanel();
desktopTabPanel.setHeight("100%");
desktopTabPanel.appendChild(substituteTbl);
tabPanels.appendChild(desktopTabPanel);
tab = new Tab(Msg.translate(Env.getCtx(), "RelatedProduct_ID"));
tabs.appendChild(tab);
desktopTabPanel = new Tabpanel();
desktopTabPanel.setHeight("100%");
desktopTabPanel.appendChild(relatedTbl);
tabPanels.appendChild(desktopTabPanel);
tab = new Tab(Msg.getMsg(Env.getCtx(), "ATP"));
tabs.appendChild(tab);
desktopTabPanel = new Tabpanel();
desktopTabPanel.setHeight("100%");
desktopTabPanel.appendChild(m_tableAtp);
tabPanels.appendChild(desktopTabPanel);
//
borderlayout.setWidth("100%");
borderlayout.setHeight("400px");
borderlayout.setStyle("border: none; position: relative");
Center center = new Center();
center.setAutoscroll(true);
center.setFlex(true);
borderlayout.appendChild(center);
Div div = new Div();
div.appendChild(contentPanel);
center.appendChild(div);
South south = new South();
south.setHeight("120px");
south.setCollapsible(true);
south.setSplittable(true);
south.setFlex(true);
south.setTitle(Msg.translate(Env.getCtx(), "WarehouseStock"));
south.setTooltiptext(Msg.translate(Env.getCtx(), "WarehouseStock"));
borderlayout.appendChild(south);
south.appendChild(tabbedPane);
Panel mainPanel = new Panel();
mainPanel.setWidth("100%");
mainPanel.appendChild(parameterPanel);
mainPanel.appendChild(new Separator());
mainPanel.appendChild(contentPanel);
mainPanel.appendChild(borderlayout);
mainPanel.appendChild(new Separator());
mainPanel.appendChild(confirmPanel);
this.appendChild(mainPanel);
this.setBorder("normal");
this.setWidth("1000px");
contentPanel.addActionListener(new EventListener() {
public void onEvent(Event event) throws Exception {
int row = contentPanel.getSelectedRow();
int M_Warehouse_ID = 0;
ListItem listitem = pickWarehouse.getSelectedItem();
if (listitem != null)
M_Warehouse_ID = (Integer)listitem.getValue();
int M_PriceList_Version_ID = 0;
listitem = pickPriceList.getSelectedItem();
if (listitem != null)
M_PriceList_Version_ID = (Integer)listitem.getValue();
refresh(contentPanel.getValueAt(row,2), M_Warehouse_ID, M_PriceList_Version_ID);
borderlayout.getSouth().setOpen(true);
}
});
}
/**
* Refresh Query
*/
private void refresh(Object obj, int M_Warehouse_ID, int M_PriceList_Version_ID)
{
//int M_Product_ID = 0;
String sql = m_sqlWarehouse;
//Add description to the query
sql = sql.replace(" FROM", ", DocumentNote FROM");
log.finest(sql);
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, (String)obj);
rs = pstmt.executeQuery();
fieldDescription.setText("");
warehouseTbl.loadTable(rs);
rs = pstmt.executeQuery();
if(rs.next())
if(rs.getString("DocumentNote") != null)
fieldDescription.setText(rs.getString("DocumentNote"));
}
catch (Exception e)
{
log.log(Level.WARNING, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
try {
sql = "SELECT M_Product_ID FROM M_Product WHERE Value = ?";
pstmt = DB.prepareStatement(sql, null);
pstmt.setString(1, (String)obj);
rs = pstmt.executeQuery();
if(rs.next())
m_M_Product_ID = rs.getInt(1);
} catch (Exception e) {
log.log(Level.WARNING, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
sql = m_sqlSubstitute;
log.finest(sql);
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, M_PriceList_Version_ID);
rs = pstmt.executeQuery();
substituteTbl.loadTable(rs);
rs.close();
} catch (Exception e) {
log.log(Level.WARNING, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
sql = m_sqlRelated;
log.finest(sql);
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, M_PriceList_Version_ID);
rs = pstmt.executeQuery();
relatedTbl.loadTable(rs);
rs.close();
} catch (Exception e) {
log.log(Level.WARNING, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
initAtpTab(M_Warehouse_ID);
} // refresh
/**
* Dynamic Init
@ -329,6 +620,7 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
//
pickWarehouse.addEventListener(Events.ON_SELECT,this);
pickPriceList.addEventListener(Events.ON_SELECT,this);
pickProductCategory.addEventListener(Events.ON_SELECT, this); // Elaine 2008/11/21
} // initInfo
/**
@ -383,6 +675,17 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
}
rs.close();
pstmt.close();
// Elaine 2008/11/21
// Product Category
SQL = MRole.getDefault().addAccessSQL (
"SELECT M_Product_Category_ID, Value || ' - ' || Name FROM M_Product_Category WHERE IsActive='Y'",
"M_Product_Category", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
+ " ORDER BY Value";
for (KeyNamePair kn : DB.getKeyNamePairs(SQL, true)) {
pickProductCategory.addItem(kn);
}
//
}
catch (SQLException e)
{
@ -502,6 +805,13 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
if (M_PriceList_Version_ID != 0)
where.append(" AND pr.M_PriceList_Version_ID=?");
// Elaine 2008/11/29
// Optional Product Category
if (getM_Product_Category_ID() > 0) {
where.append(" AND p.M_Product_Category_ID=?");
}
//
// Product Attribute Search
if (m_pAttributeWhere != null)
{
@ -572,6 +882,14 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
pstmt.setInt(index++, M_PriceList_Version_ID);
log.fine("M_PriceList_Version_ID=" + M_PriceList_Version_ID);
}
// Elaine 2008/11/29
// => Product Category
int M_Product_Category_ID = getM_Product_Category_ID();
if (M_Product_Category_ID > 0) {
pstmt.setInt(index++, M_Product_Category_ID);
log.fine("M_Product_Category_ID=" + M_Product_Category_ID);
}
//
// Rest of Parameter in Query for Attribute Search
if (m_pAttributeWhere != null)
return;
@ -625,12 +943,8 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
pstmt.setString(index++, vendor);
log.fine("Vendor: " + vendor);
}
} // setParameters
/**
* Query per Product Attribute.
* <code>
@ -642,10 +956,10 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
*/
private void cmd_InfoPAttribute()
{
/*InfoPAttributePanel ia = new InfoPAttributePanel();
InfoPAttributePanel ia = new InfoPAttributePanel(this);
m_pAttributeWhere = ia.getWhereClause();
if (m_pAttributeWhere != null)
executeQuery();*/
executeQuery();
} // cmdInfoAttribute
/**
@ -822,12 +1136,256 @@ public final class InfoProductPanel extends InfoPanel implements EventListener
return no > 0;
} // isUnconfirmed
public void tableChanged(WTableModelEvent event)
public void onEvent(Event e)
{
// TODO Auto-generated method stub
Component component = e.getTarget();
if(component == m_InfoPAttributeButton)
{
cmd_InfoPAttribute();
}
m_pAttributeWhere = null;
// Query Product Attribure Instance
int row = contentPanel.getSelectedRow();
if (component.equals(m_PAttributeButton) && row != -1)
{
Integer productInteger = getSelectedRowKey();
String productName = (String)contentPanel.getValueAt(row, INDEX_NAME);
ListItem warehouse = pickWarehouse.getSelectedItem();
if (productInteger == null || productInteger.intValue() == 0 || warehouse == null)
return;
int M_Warehouse_ID = 0;
if(warehouse.getValue() != null)
M_Warehouse_ID = ((Integer)warehouse.getValue()).intValue();
String title = warehouse.getLabel() + " - " + productName;
InfoPAttributeInstancePanel pai = new InfoPAttributeInstancePanel(this, title,
M_Warehouse_ID, 0, productInteger.intValue(), m_C_BPartner_ID);
m_M_AttributeSetInstance_ID = pai.getM_AttributeSetInstance_ID();
m_M_Locator_ID = pai.getM_Locator_ID();
if (m_M_AttributeSetInstance_ID != -1)
dispose(true);
return;
}
//
super.onEvent(e);
}
/**
* Enable PAttribute if row selected/changed
*/
protected void enableButtons ()
{
m_M_AttributeSetInstance_ID = -1;
if (m_PAttributeButton != null)
{
int row = contentPanel.getSelectedRow();
boolean enabled = false;
if (row >= 0)
{
Object value = contentPanel.getValueAt(row, INDEX_PATTRIBUTE);
enabled = Boolean.TRUE.equals(value);
}
m_PAttributeButton.setEnabled(enabled);
}
super.enableButtons();
} // enableButtons
// Elaine 2008/11/26
/**
* Query ATP
*/
private void initAtpTab (int m_M_Warehouse_ID)
{
// Header
Vector<String> columnNames = new Vector<String>();
columnNames.add(Msg.translate(Env.getCtx(), "Date"));
columnNames.add(Msg.translate(Env.getCtx(), "QtyOnHand"));
columnNames.add(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
columnNames.add(Msg.translate(Env.getCtx(), "QtyOrdered"));
columnNames.add(Msg.translate(Env.getCtx(), "QtyReserved"));
columnNames.add(Msg.translate(Env.getCtx(), "M_Locator_ID"));
columnNames.add(Msg.translate(Env.getCtx(), "M_AttributeSetInstance_ID"));
columnNames.add(Msg.translate(Env.getCtx(), "DocumentNo"));
columnNames.add(Msg.translate(Env.getCtx(), "M_Warehouse_ID"));
// Fill Storage Data
boolean showDetail = CLogMgt.isLevelFine();
String sql = "SELECT s.QtyOnHand, s.QtyReserved, s.QtyOrdered,"
+ " productAttribute(s.M_AttributeSetInstance_ID), s.M_AttributeSetInstance_ID,";
if (!showDetail)
sql = "SELECT SUM(s.QtyOnHand), SUM(s.QtyReserved), SUM(s.QtyOrdered),"
+ " productAttribute(s.M_AttributeSetInstance_ID), 0,";
sql += " w.Name, l.Value "
+ "FROM M_Storage s"
+ " INNER JOIN M_Locator l ON (s.M_Locator_ID=l.M_Locator_ID)"
+ " INNER JOIN M_Warehouse w ON (l.M_Warehouse_ID=w.M_Warehouse_ID) "
+ "WHERE M_Product_ID=?";
if (m_M_Warehouse_ID != 0)
sql += " AND l.M_Warehouse_ID=?";
if (m_M_AttributeSetInstance_ID > 0)
sql += " AND s.M_AttributeSetInstance_ID=?";
sql += " AND (s.QtyOnHand<>0 OR s.QtyReserved<>0 OR s.QtyOrdered<>0)";
if (!showDetail)
sql += " GROUP BY productAttribute(s.M_AttributeSetInstance_ID), w.Name, l.Value";
sql += " ORDER BY l.Value";
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
double qty = 0;
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);
if (m_M_AttributeSetInstance_ID > 0)
pstmt.setInt(3, m_M_AttributeSetInstance_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(9);
line.add(null); // Date
double qtyOnHand = rs.getDouble(1);
qty += qtyOnHand;
line.add(new Double(qtyOnHand)); // Qty
line.add(null); // BPartner
line.add(new Double(rs.getDouble(3))); // QtyOrdered
line.add(new Double(rs.getDouble(2))); // QtyReserved
line.add(rs.getString(7)); // Locator
String asi = rs.getString(4);
if (showDetail && (asi == null || asi.length() == 0))
asi = "{" + rs.getInt(5) + "}";
line.add(asi); // ASI
line.add(null); // DocumentNo
line.add(rs.getString(6)); // Warehouse
data.add(line);
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Orders
sql = "SELECT o.DatePromised, ol.QtyReserved,"
+ " productAttribute(ol.M_AttributeSetInstance_ID), ol.M_AttributeSetInstance_ID,"
+ " dt.DocBaseType, bp.Name,"
+ " dt.PrintName || ' ' || o.DocumentNo As DocumentNo, w.Name "
+ "FROM C_Order o"
+ " INNER JOIN C_OrderLine ol ON (o.C_Order_ID=ol.C_Order_ID)"
+ " INNER JOIN C_DocType dt ON (o.C_DocType_ID=dt.C_DocType_ID)"
+ " INNER JOIN M_Warehouse w ON (ol.M_Warehouse_ID=w.M_Warehouse_ID)"
+ " INNER JOIN C_BPartner bp ON (o.C_BPartner_ID=bp.C_BPartner_ID) "
+ "WHERE ol.QtyReserved<>0"
+ " AND ol.M_Product_ID=?";
if (m_M_Warehouse_ID != 0)
sql += " AND ol.M_Warehouse_ID=?";
if (m_M_AttributeSetInstance_ID > 0)
sql += " AND ol.M_AttributeSetInstance_ID=?";
sql += " ORDER BY o.DatePromised";
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);
if (m_M_AttributeSetInstance_ID > 0)
pstmt.setInt(3, m_M_AttributeSetInstance_ID);
rs = pstmt.executeQuery();
while (rs.next())
{
Vector<Object> line = new Vector<Object>(9);
line.add(rs.getTimestamp(1)); // Date
double oq = rs.getDouble(2);
String DocBaseType = rs.getString(5);
Double qtyReserved = null;
Double qtyOrdered = null;
if (MDocType.DOCBASETYPE_PurchaseOrder.equals(DocBaseType))
{
qtyOrdered = new Double(oq);
qty += oq;
}
else
{
qtyReserved = new Double(oq);
qty -= oq;
}
line.add(new Double(qty)); // Qty
line.add(rs.getString(6)); // BPartner
line.add(qtyOrdered); // QtyOrdered
line.add(qtyReserved); // QtyReserved
line.add(null); // Locator
String asi = rs.getString(3);
if (showDetail && (asi == null || asi.length() == 0))
asi = "{" + rs.getInt(4) + "}";
line.add(asi); // ASI
line.add(rs.getString(7)); // DocumentNo
line.add(rs.getString(8)); // Warehouse
data.add(line);
}
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
finally {
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// Table
m_tableAtp = ListboxFactory.newDataTable();
m_tableAtp.setMultiSelection(false);
m_tableAtp.getModel().setNoColumns(columnNames.size());
for(int i = 0; i < columnNames.size(); i++)
m_tableAtp.addColumn(columnNames.get(i));
//
m_tableAtp.setColumnClass(0, Timestamp.class, true); // Date
m_tableAtp.setColumnClass(1, Double.class, true); // Quantity
m_tableAtp.setColumnClass(2, String.class, true); // Partner
m_tableAtp.setColumnClass(3, Double.class, true); // Quantity
m_tableAtp.setColumnClass(4, Double.class, true); // Quantity
m_tableAtp.setColumnClass(5, String.class, true); // Locator
m_tableAtp.setColumnClass(6, String.class, true); // ASI
m_tableAtp.setColumnClass(7, String.class, true); // DocNo
m_tableAtp.setColumnClass(8, String.class, true); // Warehouse
//
m_tableAtp.autoSize();
m_tableAtp.setRowCount(data.size());
for(int i = 0; i < data.size(); i++)
{
Vector<Object> record = data.get(i);
for(int j = 0; j < record.size(); j++)
{
Object value = record.get(j);
m_tableAtp.getModel().setDataAt(value, i, j);
}
}
} // initAtpTab
//
// Elaine 2008/11/21
public int getM_Product_Category_ID()
{
int M_Product_Category_ID = 0;
ListItem pickPC = (ListItem)pickProductCategory.getSelectedItem();
if (pickPC!=null)
M_Product_Category_ID = Integer.parseInt(pickPC.getValue().toString());
return M_Product_Category_ID;
}
//
} // InfoProduct