📄 infoproduct.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.apps.search;
import java.awt.*;
import java.awt.event.*;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
//
import org.compiere.apps.*;
import org.compiere.grid.ed.*;
import org.compiere.minigrid.*;
import org.compiere.model.*;
import org.compiere.plaf.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Search Product and return selection
*
* @author Jorg Janke
* @version $Id: InfoProduct.java,v 1.39 2005/12/09 05:17:54 jjanke Exp $
*/
public final class InfoProduct extends Info implements ActionListener
{
/**
* Standard Constructor
* @param frame frame
* @param modal modal
* @param WindowNo window no
* @param M_Warehouse_ID warehouse
* @param M_PriceList_ID price list
* @param value Query Value or Name if enclosed in @
* @param multiSelection multiple selections
* @param whereClause where clause
*/
public InfoProduct(Frame frame, boolean modal, int WindowNo,
int M_Warehouse_ID, int M_PriceList_ID, String value,
boolean multiSelection, String whereClause)
{
super (frame, modal, WindowNo, "p", "M_Product_ID", multiSelection, whereClause);
log.info(value + ", Wh=" + M_Warehouse_ID + ", PL=" + M_PriceList_ID + ", WHERE=" + whereClause);
setTitle(Msg.getMsg(Env.getCtx(), "InfoProduct"));
//
statInit();
initInfo (value, M_Warehouse_ID, M_PriceList_ID);
m_C_BPartner_ID = Env.getContextAsInt(Env.getCtx(), WindowNo, "C_BPartner_ID");
//
int no = p_table.getRowCount();
setStatusLine(Integer.toString(no) + " " + Msg.getMsg(Env.getCtx(), "SearchRows_EnterQuery"), false);
setStatusDB(Integer.toString(no));
// AutoQuery
if (value != null && value.length() > 0)
executeQuery();
p_loadedOK = true;
// Focus
fieldValue.requestFocus();
AEnv.positionCenterWindow(frame, this);
} // InfoProduct
/** SQL From */
private static final String s_productFrom =
"M_Product p"
+ " LEFT OUTER JOIN M_ProductPrice pr ON (p.M_Product_ID=pr.M_Product_ID AND pr.IsActive='Y')"
+ " LEFT OUTER JOIN M_AttributeSet pa ON (p.M_AttributeSet_ID=pa.M_AttributeSet_ID)";
/** Array of Column Info */
private static Info_Column[] s_productLayout = null;
private static int INDEX_NAME = 0;
private static int INDEX_PATTRIBUTE = 0;
//
private CLabel labelValue = new CLabel();
private CTextField fieldValue = new CTextField(10);
private CLabel labelName = new CLabel();
private CTextField fieldName = new CTextField(10);
private CLabel labelUPC = new CLabel();
private CTextField fieldUPC = new CTextField(10);
private CLabel labelSKU = new CLabel();
private CTextField fieldSKU = new CTextField(10);
private CLabel labelPriceList = new CLabel();
private VComboBox pickPriceList = new VComboBox();
private CLabel labelWarehouse = new CLabel();
private VComboBox pickWarehouse = new VComboBox();
/** Search Button */
private CButton m_InfoPAttributeButton = new CButton(Env.getImageIcon("PAttribute16.gif"));
/** Instance Button */
private CButton m_PAttributeButton = null;
private int m_M_AttributeSetInstance_ID = -1;
private String m_pAttributeWhere = null;
private int m_C_BPartner_ID = 0;
/**
* Static Setup - add fields to parameterPanel
*/
private void statInit()
{
labelValue.setText(Msg.getMsg(Env.getCtx(), "Value"));
fieldValue.setBackground(CompierePLAF.getInfoBackground());
fieldValue.addActionListener(this);
labelName.setText(Msg.getMsg(Env.getCtx(), "Name"));
fieldName.setBackground(CompierePLAF.getInfoBackground());
fieldName.addActionListener(this);
labelUPC.setText(Msg.translate(Env.getCtx(), "UPC"));
fieldUPC.setBackground(CompierePLAF.getInfoBackground());
fieldUPC.addActionListener(this);
labelSKU.setText(Msg.translate(Env.getCtx(), "SKU"));
fieldSKU.setBackground(CompierePLAF.getInfoBackground());
fieldSKU.addActionListener(this);
labelWarehouse.setText(Msg.getMsg(Env.getCtx(), "Warehouse"));
pickWarehouse.setBackground(CompierePLAF.getInfoBackground());
labelPriceList.setText(Msg.getMsg(Env.getCtx(), "PriceListVersion"));
pickPriceList.setBackground(CompierePLAF.getInfoBackground());
m_InfoPAttributeButton.setMargin(new Insets(2,2,2,2));
m_InfoPAttributeButton.setToolTipText(Msg.getMsg(Env.getCtx(), "InfoPAttribute"));
m_InfoPAttributeButton.addActionListener(this);
// Line 1
parameterPanel.setLayout(new ALayout());
parameterPanel.add(labelValue, new ALayoutConstraint(0,0));
parameterPanel.add(fieldValue, null);
parameterPanel.add(labelUPC, null);
parameterPanel.add(fieldUPC, null);
parameterPanel.add(labelWarehouse, null);
parameterPanel.add(pickWarehouse, null);
parameterPanel.add(m_InfoPAttributeButton);
// Line 2
parameterPanel.add(labelName, new ALayoutConstraint(1,0));
parameterPanel.add(fieldName, null);
parameterPanel.add(labelSKU, null);
parameterPanel.add(fieldSKU, null);
parameterPanel.add(labelPriceList, null);
parameterPanel.add(pickPriceList, null);
// Product Attribute Instance
m_PAttributeButton = ConfirmPanel.createPAttributeButton(true);
confirmPanel.addButton(m_PAttributeButton);
m_PAttributeButton.addActionListener(this);
m_PAttributeButton.setEnabled(false);
} // statInit
/**
* Dynamic Init
*
* @param value value
* @param M_Warehouse_ID warehouse
* @param M_PriceList_ID price list
*/
private void initInfo (String value, int M_Warehouse_ID, int M_PriceList_ID)
{
// Pick init
fillPicks(M_PriceList_ID);
int M_PriceList_Version_ID = findPLV (M_PriceList_ID);
// Set Value or Name
if (value.startsWith("@") && value.endsWith("@"))
fieldName.setText(value.substring(1,value.length()-1));
else
fieldValue.setText(value);
// Set Warehouse
if (M_Warehouse_ID == 0)
M_Warehouse_ID = Env.getContextAsInt(Env.getCtx(), "#M_Warehouse_ID");
if (M_Warehouse_ID != 0)
setWarehouse (M_Warehouse_ID);
// Set PriceList Version
if (M_PriceList_Version_ID != 0)
setPriceListVersion (M_PriceList_Version_ID);
// Create Grid
StringBuffer where = new StringBuffer();
where.append("p.IsActive='Y'");
if (M_Warehouse_ID != 0)
where.append(" AND p.IsSummary='N'");
// dynamic Where Clause
if (p_whereClause != null && p_whereClause.length() > 0)
where.append(" AND ") // replace fully qalified name with alias
.append(Util.replace(p_whereClause, "M_Product.", "p."));
//
prepareTable(getProductLayout(),
s_productFrom,
where.toString(),
"QtyAvailable DESC, Margin DESC");
//
pickWarehouse.addActionListener(this);
pickPriceList.addActionListener(this);
} // initInfo
/**
* Fill Picks with values
*
* @param M_PriceList_ID price list
*/
private void fillPicks (int M_PriceList_ID)
{
// Price List
String SQL = "SELECT M_PriceList_Version.M_PriceList_Version_ID,"
+ " M_PriceList_Version.Name || ' (' || c.Iso_Code || ')' AS ValueName "
+ "FROM M_PriceList_Version, M_PriceList pl, C_Currency c "
+ "WHERE M_PriceList_Version.M_PriceList_ID=pl.M_PriceList_ID"
+ " AND pl.C_Currency_ID=c.C_Currency_ID"
+ " AND M_PriceList_Version.IsActive='Y' AND pl.IsActive='Y'";
// Same PL currency as original one
if (M_PriceList_ID != 0)
SQL += " AND EXISTS (SELECT * FROM M_PriceList xp WHERE xp.M_PriceList_ID=" + M_PriceList_ID
+ " AND pl.C_Currency_ID=xp.C_Currency_ID)";
// Add Access & Order
SQL = MRole.getDefault().addAccessSQL (SQL, "M_PriceList_Version", true, false) // fully qualidfied - RO
+ " ORDER BY M_PriceList_Version.Name";
try
{
pickPriceList.addItem(new KeyNamePair (0, ""));
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
KeyNamePair kn = new KeyNamePair (rs.getInt(1), rs.getString(2));
pickPriceList.addItem(kn);
}
rs.close();
pstmt.close();
// Warehouse
SQL = MRole.getDefault().addAccessSQL (
"SELECT M_Warehouse_ID, Value || ' - ' || Name AS ValueName "
+ "FROM M_Warehouse "
+ "WHERE IsActive='Y'",
"M_Warehouse", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO)
+ " ORDER BY Value";
pickWarehouse.addItem(new KeyNamePair (0, ""));
pstmt = DB.prepareStatement(SQL, null);
rs = pstmt.executeQuery();
while (rs.next())
{
KeyNamePair kn = new KeyNamePair
(rs.getInt("M_Warehouse_ID"), rs.getString("ValueName"));
pickWarehouse.addItem(kn);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, SQL, e);
setStatusLine(e.getLocalizedMessage(), true);
}
} // fillPicks
/**
* Set Warehouse
*
* @param M_Warehouse_ID warehouse
*/
private void setWarehouse(int M_Warehouse_ID)
{
for (int i = 0; i < pickWarehouse.getItemCount(); i++)
{
KeyNamePair kn = (KeyNamePair)pickWarehouse.getItemAt(i);
if (kn.getKey() == M_Warehouse_ID)
{
pickWarehouse.setSelectedIndex(i);
return;
}
}
} // setWarehouse
/**
* Set PriceList
*
* @param M_PriceList_Version_ID price list
*/
private void setPriceListVersion(int M_PriceList_Version_ID)
{
log.config("M_PriceList_Version_ID=" + M_PriceList_Version_ID);
for (int i = 0; i < pickPriceList.getItemCount(); i++)
{
KeyNamePair kn = (KeyNamePair)pickPriceList.getItemAt(i);
if (kn.getKey() == M_PriceList_Version_ID)
{
pickPriceList.setSelectedIndex(i);
return;
}
}
log.fine("NOT found");
} // setPriceList
/**
* Find Price List Version and update context
*
* @param M_PriceList_ID price list
* @return M_PriceList_Version_ID price list version
*/
private int findPLV (int M_PriceList_ID)
{
Timestamp priceDate = null;
// Sales Order Date
String dateStr = Env.getContext(Env.getCtx(), p_WindowNo, "DateOrdered");
if (dateStr != null && dateStr.length() > 0)
priceDate = Env.getContextAsDate(Env.getCtx(), p_WindowNo, "DateOrdered");
else // Invoice Date
{
dateStr = Env.getContext(Env.getCtx(), p_WindowNo, "DateInvoiced");
if (dateStr != null && dateStr.length() > 0)
priceDate = Env.getContextAsDate(Env.getCtx(), p_WindowNo, "DateInvoiced");
}
// Today
if (priceDate == null)
priceDate = new Timestamp(System.currentTimeMillis());
//
log.config("M_PriceList_ID=" + M_PriceList_ID + " - " + priceDate);
int retValue = 0;
String sql = "SELECT plv.M_PriceList_Version_ID, plv.ValidFrom "
+ "FROM M_PriceList pl, M_PriceList_Version plv "
+ "WHERE pl.M_PriceList_ID=plv.M_PriceList_ID"
+ " AND plv.IsActive='Y'"
+ " AND pl.M_PriceList_ID=? " // 1
+ "ORDER BY plv.ValidFrom DESC";
// find newest one
try
{
PreparedStatement pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, M_PriceList_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next() && retValue == 0)
{
Timestamp plDate = rs.getTimestamp(2);
if (!priceDate.before(plDate))
retValue = rs.getInt(1);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.log(Level.SEVERE, sql, e);
}
Env.setContext(Env.getCtx(), p_WindowNo, "M_PriceList_Version_ID", retValue);
return retValue;
} // findPLV
/**************************************************************************
* Construct SQL Where Clause and define parameters
* (setParameters needs to set parameters)
* Includes first AND
* @return SQL WHERE clause
*/
String getSQLWhere()
{
StringBuffer where = new StringBuffer();
// Optional PLV
int M_PriceList_Version_ID = 0;
KeyNamePair pl = (KeyNamePair)pickPriceList.getSelectedItem();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -