📄 productinfo.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 Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
* created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.acct;
import java.sql.*;
import java.math.*;
import java.util.*;
import org.apache.log4j.Logger;
import org.compiere.util.Env;
import org.compiere.util.DB;
import org.compiere.model.*;
/**
* Product Information
*
* @author Jorg Janke
* @version $Id: ProductInfo.java,v 1.17 2003/04/09 05:26:43 jjanke Exp $
*/
public class ProductInfo
{
/**
* Constructor
* @param M_Product_ID Product
*/
public ProductInfo (int M_Product_ID)
{
init (M_Product_ID);
} // ProductInfo
/** The Product Key */
private int m_M_Product_ID = 0;
// Product Info
private int m_AD_Client_ID = 0;
private int m_AD_Org_ID = 0;
private String m_productType = null;
private String m_ProductCategory = null;
private int m_C_RevenueRecognition_ID = 0;
private int m_C_UOM_ID = 0;
private BigDecimal m_qty = Env.ZERO;
/** Logger */
protected Logger log = Logger.getLogger (getClass());
/**
* Get Product Info (Service, Revenue Recognition).
* automatically called by constructor
* @param M_Product_ID Product
*/
private void init (int M_Product_ID)
{
m_M_Product_ID = M_Product_ID;
if (m_M_Product_ID == 0)
return;
String sql = "SELECT p.ProductType, pc.Value, " // 1..2
+ "p.C_RevenueRecognition_ID,p.C_UOM_ID, " // 3..4
+ "p.AD_Client_ID,p.AD_Org_ID " // 5..6
+ "FROM M_Product_Category pc, M_Product p "
+ "WHERE pc.M_Product_Category_ID=p.M_Product_Category_ID"
+ " AND p.M_Product_ID=?"; // #1
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, m_M_Product_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
{
m_productType = rs.getString(1);
m_ProductCategory = rs.getString(2);
m_C_RevenueRecognition_ID = rs.getInt(3);
m_C_UOM_ID = rs.getInt(4);
// reference
m_AD_Client_ID = rs.getInt(5);
m_AD_Org_ID = rs.getInt(6);
}
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error ("init", e);
}
} // init
/**
* Is Product/Item
* @return true if product, false if service
*/
public boolean isProduct()
{
return "I".equals(m_productType);
} // isProduct
/**
* Is Service
* @return true if service, false if product
*/
public boolean isService()
{
return !isProduct();
} // isService
/**
* Get Product Category (Value)
* @return M_Product_Category_ID
*/
public String getProductCategory()
{
return m_ProductCategory;
} // getProductCategory
/**
* Has Revenue Recognition
* @return true if product/service has revenue recognition
*/
public boolean isRevenueRecognition()
{
return m_C_RevenueRecognition_ID != 0;
} // isRevenueRecognition
/**
* Get Revenue Recognition
* @return C_RevenueRecognition_ID
*/
public int getC_RevenueRecognition_ID()
{
return m_C_RevenueRecognition_ID;
} // getC_RevenueRecognition_ID
/**
* Quantity UOM
* @return C_UOM_ID
*/
public int getC_UOM_ID()
{
return m_C_UOM_ID;
} // getC_UOM_ID
/*************************************************************************/
/**
* Set Quantity in Storage UOM
* @param qty quantity
*/
public void setQty (BigDecimal qty)
{
m_qty = qty;
} // setQty
/**
* Set Quantity in UOM
* @param qty quantity
* @param C_UOM_ID UOM
*/
public void setQty (BigDecimal qty, int C_UOM_ID)
{
m_qty = UOMConversion.getConvertedQty(qty, C_UOM_ID, m_C_UOM_ID, true); // StdPrecision
if (qty != null && m_qty == null) // conversion error
{
log.error ("setQty - conversion error - set to " + qty);
m_qty = qty;
}
} // setQty
/**
* Get Qty in Storage UOM
* @return qty
*/
public BigDecimal getQty()
{
return m_qty;
} // getQty
/*************************************************************************/
/** Product Revenue Acct */
public static final int ACCTTYPE_P_Revenue = 1;
/** Product Expense Acct */
public static final int ACCTTYPE_P_Expense = 2;
/** Product Asset Acct */
public static final int ACCTTYPE_P_Asset = 3;
/** Product COGS Acct */
public static final int ACCTTYPE_P_Cogs = 4;
/** Purchase Price Variance */
public static final int ACCTTYPE_P_PPV = 5;
/** Invoice Price Variance */
public static final int ACCTTYPE_P_IPV = 6;
/** Trade Discount Revenue */
public static final int ACCTTYPE_P_TDiscountRec = 7;
/** Trade Discount Costs */
public static final int ACCTTYPE_P_TDiscountGrant = 8;
/**
* Line Account from Product
*
* @param AcctType see ACCTTYPE_* (1..8)
* @param as Accounting Schema
* @return Requested Product Account
*/
public Account getAccount(int AcctType, AcctSchema as)
{
if (AcctType < 1 || AcctType > 8)
return null;
// No Product - get Default from Product Category
if (m_M_Product_ID == 0)
return getAccountDefault(AcctType, as);
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, " // 1..4
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, " // 5..6
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct " // 7..8
+ "FROM M_Product_Acct "
+ "WHERE M_Product_ID=? AND C_AcctSchema_ID=?";
//
int validCombination_ID = 0;
try
{
PreparedStatement pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, m_M_Product_ID);
pstmt.setInt(2, as.getC_AcctSchema_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
validCombination_ID = rs.getInt(AcctType);
rs.close();
pstmt.close();
}
catch (SQLException e)
{
log.error ("getAccount", e);
}
if (validCombination_ID == 0)
return null;
return Account.getAccount(validCombination_ID);
} // getAccount
/**
* Account from Default Product Category
*
* @param AcctType see ACCTTYPE_* (1..8)
* @param as accounting schema
* @return Requested Product Account
*/
public Account getAccountDefault (int AcctType, AcctSchema as)
{
if (AcctType < 1 || AcctType > 8)
return null;
String sql = "SELECT P_Revenue_Acct, P_Expense_Acct, P_Asset_Acct, P_Cogs_Acct, "
+ "P_PurchasePriceVariance_Acct, P_InvoicePriceVariance_Acct, "
+ "P_TradeDiscountRec_Acct, P_TradeDiscountGrant_Acct "
+ "FROM M_Product_Category pc, M_Product_Category_Acct pca "
+ "WHERE pc.M_Product_Category_ID=pca.M_Product_Category_ID"
+ " AND pca.C_AcctSchema_ID=? "
+ "ORDER BY pc.IsDefault DESC, pc.Created";
//
int validCombination_ID = 0;
try
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -