📄 pricelist.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 and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.wstore;
import java.util.*;
import java.sql.*;
import org.apache.log4j.Logger;
import org.compiere.model.*;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.www.*;
/**
* Price List.
* ArrayList of PriceListProduct
*
* @author Jorg Janke
* @version $Id: PriceList.java,v 1.5 2003/04/28 04:20:25 jjanke Exp $
*/
public class PriceList
{
/**
* Get Price List
* @param AD_Client_ID client
* @param M_PriceList_ID price list
* @return Price list
*/
public static PriceList get (int AD_Client_ID, int M_PriceList_ID)
{
PriceList retValue = null;
for (int i = 0; i < s_cache.size(); i++)
{
PriceList pl = (PriceList)s_cache.get(i);
if (pl.getParameter()[0] == AD_Client_ID && pl.getParameter()[1] == M_PriceList_ID)
{
retValue = pl;
break;
}
}
// create New
if (retValue == null)
{
retValue = new PriceList (AD_Client_ID, M_PriceList_ID);
s_cache.add(retValue);
}
return retValue;
} // get
/**
* Clear cache
*/
public static void clearCache ()
{
s_cache.clear();
} // clearCache
/** Cache */
private static ArrayList s_cache = new ArrayList();
/**
* PriceList constructor
* @param AD_Client_ID client
* @param M_PriceList_ID optional price list
*/
private PriceList (int AD_Client_ID, int M_PriceList_ID)
{
log.info("AD_Client_ID=" + AD_Client_ID + ", M_PriceList_ID=" + M_PriceList_ID);
m_parameter = new int[] {AD_Client_ID, M_PriceList_ID};
initialize (AD_Client_ID, M_PriceList_ID);
} // PriceList
/** Attribute Name - also in JSPs */
public static final String NAME = "priceList";
/** Logging */
private Logger log = Logger.getLogger(getClass());
private int[] m_parameter;
private String m_name = "Not found";
private String m_description;
private String m_currency;
private String m_AD_Language;
private boolean m_taxIncluded;
private int m_PriceList_ID = 0;
private int m_PriceList_Version_ID = 0;
private ArrayList m_prices = new ArrayList();
/**
* Get Parameter
* @return Parameter
*/
private int[] getParameter()
{
return m_parameter;
} // getParameter
/**
* Find Price List
* @param AD_Client_ID client
* @param M_PriceList_ID optional price list
*/
private void initialize (int AD_Client_ID, int M_PriceList_ID)
{
// Get Price List
if (getM_PriceList_ID(AD_Client_ID, M_PriceList_ID) == 0)
if (getM_PriceList_ID(AD_Client_ID, 0) == 0)
return;
// Get Price List Version
getM_PriceList_Version_ID(m_PriceList_ID, new Timestamp(System.currentTimeMillis()));
log.debug("AD_Client_ID=" + AD_Client_ID + ", M_PriceList_ID=" + m_PriceList_ID
+ ", M_PriceList_Version_ID=" + m_PriceList_Version_ID);
load ();
} // initialize
/**
* Find Price List
* @param AD_Client_ID client
* @param M_PriceList_ID optional price list
* @return M_PriceList_ID
*/
private int getM_PriceList_ID (int AD_Client_ID, int M_PriceList_ID)
{
String sql = "SELECT M_PriceList_ID, pl.Name, pl.Description, pl.IsTaxIncluded," // 1..4
+ " c.ISO_Code, cc.AD_Language " // 5..6
+ "FROM M_PriceList pl"
+ " INNER JOIN C_Currency c ON (pl.C_Currency_ID=c.C_Currency_ID)"
+ " LEFT OUTER JOIN C_Country cc ON (c.C_Currency_ID=cc.C_Currency_ID AND ROWNUM=1) "
+ "WHERE pl.IsActive='Y'"
+ " AND pl.AD_Client_ID=?"; // #1
if (M_PriceList_ID != 0)
sql += " AND pl.M_PriceList_ID=?"; // #2
else
sql += " ORDER BY pl.IsDefault DESC";
m_PriceList_ID = 0;
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, AD_Client_ID);
if (M_PriceList_ID != 0)
pstmt.setInt(2, M_PriceList_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_PriceList_ID = rs.getInt(1);
m_name = rs.getString(2);
m_description = rs.getString(3);
m_taxIncluded = "Y".equals(rs.getString(4));
m_currency = rs.getString(5);
m_AD_Language = rs.getString(6);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.error("getM_PriceList_ID", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return m_PriceList_ID;
} // getM_PriceList_ID
/**
* Get PL Version
* @param M_PriceList_ID price list
* @param day valid day
* @return M_PriceList_Version_ID
*/
private int getM_PriceList_Version_ID (int M_PriceList_ID, Timestamp day)
{
String sql = "SELECT M_PriceList_Version_ID, Name, Description, ValidFrom "
+ "FROM M_PriceList_Version "
+ "WHERE M_PriceList_ID=?"
+ " AND ValidFrom <=? "
+ "ORDER BY ValidFrom DESC";
PreparedStatement pstmt = null;
m_PriceList_Version_ID = 0;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, M_PriceList_ID);
pstmt.setTimestamp(2, day);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_PriceList_Version_ID = rs.getInt(1);
m_name = rs.getString(2);
m_description = rs.getString(3);
// m_validFrom = rs.getTimestamp(4);
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.error("getM_PriceList_Version_ID", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
return m_PriceList_Version_ID;
} // getM_PriceList_Version_ID
/**
* Load From Product Price
*/
private void load ()
{
String sql = "SELECT p.M_Product_ID, p.Value, p.Name, p.Description," // 1..4
+ " pp.PriceStd, uom.Name, uom.UOMSymbol " // 5..7
+ "FROM M_ProductPrice pp"
+ " INNER JOIN M_Product p ON (pp.M_Product_ID=p.M_Product_ID AND p.IsActive='Y' AND p.IsSold='Y')"
+ " INNER JOIN C_UOM uom ON (p.C_UOM_ID=uom.C_UOM_ID) "
+ "WHERE M_PriceList_Version_ID=?"
+ " AND pp.PriceStd > 0 "
+ "ORDER BY p.M_Product_Category_ID, p.Value";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, m_PriceList_Version_ID);
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
m_prices.add (new PriceListProduct(
rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
rs.getBigDecimal(5), rs.getString(6) ));
}
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.error("load", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
log.debug("load #" + m_prices.size());
} // load
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("PriceList[");
sb.append(m_prices.size())
.append("]");
return sb.toString();
} // toString
/**
* Get Count
* @return size
*/
public int getPriceCount()
{
return m_prices.size();
} // getPriceCount
/**
* Get Prices
* @return Price Array List
*/
public ArrayList getPrices()
{
return m_prices;
} // getPrices
/*************************************************************************/
/**
* Get Name
* @return Price List Name
*/
public String getName()
{
return m_name;
}
public String getDescription()
{
return m_description;
}
public String getCurrency()
{
return m_currency;
}
public String getAD_Language()
{
return m_AD_Language;
}
public boolean isTaxIncluded()
{
return m_taxIncluded;
}
public int getPriceList_ID()
{
return m_PriceList_ID;
}
public int getPriceList_Version_ID()
{
return m_PriceList_Version_ID;
}
} // PriceList
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -