📄 mproduct.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.model;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Product Model
*
* @author Jorg Janke
* @version $Id: MProduct.java,v 1.36 2005/11/09 17:38:39 jjanke Exp $
*/
public class MProduct extends X_M_Product
{
/**
* Get MProduct from Cache
* @param ctx context
* @param M_Product_ID id
* @return MProduct
*/
public static MProduct get (Properties ctx, int M_Product_ID)
{
Integer key = new Integer (M_Product_ID);
MProduct retValue = (MProduct) s_cache.get (key);
if (retValue != null)
return retValue;
retValue = new MProduct (ctx, M_Product_ID, null);
if (retValue.get_ID () != 0)
s_cache.put (key, retValue);
return retValue;
} // get
/**
* Get MProduct from Cache
* @param ctx context
* @param whereClause sql where clause
* @param trxName trx
* @return MProduct
*/
public static MProduct[] get (Properties ctx, String whereClause, String trxName)
{
String sql = "SELECT * FROM M_Product";
if (whereClause != null && whereClause.length() > 0)
sql += " WHERE AD_Client_ID=? AND " + whereClause;
ArrayList<MProduct> list = new ArrayList<MProduct>();
int AD_Client_ID = Env.getAD_Client_ID(ctx);
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt(1, AD_Client_ID);
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MProduct (ctx, rs, trxName));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log(Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
MProduct[] retValue = new MProduct[list.size ()];
list.toArray (retValue);
return retValue;
} // get
/**
* Is Product Stocked
* @param M_Product_ID id
* @return true if found and stocked - false otherwise
*/
public static boolean isProductStocked (Properties ctx, int M_Product_ID)
{
boolean retValue = false;
MProduct product = get (ctx, M_Product_ID);
return product.isStocked();
} // isProductStocked
/** Cache */
private static CCache<Integer,MProduct> s_cache = new CCache<Integer,MProduct>("M_Product", 40, 5); // 5 minutes
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MProduct.class);
/**************************************************************************
* Standard Constructor
* @param ctx context
* @param M_Product_ID id
*/
public MProduct (Properties ctx, int M_Product_ID, String trxName)
{
super (ctx, M_Product_ID, trxName);
if (M_Product_ID == 0)
{
// setValue (null);
// setName (null);
// setM_Product_Category_ID (0);
// setC_TaxCategory_ID (0);
// setC_UOM_ID (0);
//
setProductType (PRODUCTTYPE_Item); // I
setIsBOM (false); // N
setIsInvoicePrintDetails (false);
setIsPickListPrintDetails (false);
setIsPurchased (true); // Y
setIsSold (true); // Y
setIsStocked (true); // Y
setIsSummary (false);
setIsVerified (false); // N
setIsWebStoreFeatured (false);
setIsSelfService(true);
setIsExcludeAutoDelivery(false);
setProcessing (false); // N
}
} // MProduct
/**
* Load constructor
* @param ctx context
* @param rs result set
*/
public MProduct (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MProduct
/**
* Parent Constructor
* @param et parent
*/
public MProduct (MExpenseType et)
{
this (et.getCtx(), 0, et.get_TrxName());
setProductType(MProduct.PRODUCTTYPE_ExpenseType);
setExpenseType(et);
} // MProduct
/**
* Parent Constructor
* @param resource parent
*/
public MProduct (MResource resource, MResourceType resourceType)
{
this (resource.getCtx(), 0, resource.get_TrxName());
setProductType(MProduct.PRODUCTTYPE_Resource);
setResource(resource);
setResource(resourceType);
} // MProduct
/**
* Import Constructor
* @param impP import
*/
public MProduct (X_I_Product impP)
{
this (impP.getCtx(), 0, impP.get_TrxName());
setClientOrg(impP);
setUpdatedBy(impP.getUpdatedBy());
//
setValue(impP.getValue());
setName(impP.getName());
setDescription(impP.getDescription());
setDocumentNote(impP.getDocumentNote());
setHelp(impP.getHelp());
setUPC(impP.getUPC());
setSKU(impP.getSKU());
setC_UOM_ID(impP.getC_UOM_ID());
setM_Product_Category_ID(impP.getM_Product_Category_ID());
setProductType(impP.getProductType());
setImageURL(impP.getImageURL());
setDescriptionURL(impP.getDescriptionURL());
} // MProduct
/** Additional Downloads */
private MProductDownload[] m_downloads = null;
/**
* Set Expense Type
* @param parent expense type
* @return true if changed
*/
public boolean setExpenseType (MExpenseType parent)
{
boolean changed = false;
if (!PRODUCTTYPE_ExpenseType.equals(getProductType()))
{
setProductType(PRODUCTTYPE_ExpenseType);
changed = true;
}
if (parent.getS_ExpenseType_ID() != getS_ExpenseType_ID())
{
setS_ExpenseType_ID(parent.getS_ExpenseType_ID());
changed = true;
}
if (parent.isActive() != isActive())
{
setIsActive(parent.isActive());
changed = true;
}
//
if (!parent.getValue().equals(getValue()))
{
setValue(parent.getValue());
changed = true;
}
if (!parent.getName().equals(getName()))
{
setName(parent.getName());
changed = true;
}
if ((parent.getDescription() == null && getDescription() != null)
|| (parent.getDescription() != null && !parent.getDescription().equals(getDescription())))
{
setDescription(parent.getDescription());
changed = true;
}
if (parent.getC_UOM_ID() != getC_UOM_ID())
{
setC_UOM_ID(parent.getC_UOM_ID());
changed = true;
}
if (parent.getM_Product_Category_ID() != getM_Product_Category_ID())
{
setM_Product_Category_ID(parent.getM_Product_Category_ID());
changed = true;
}
if (parent.getC_TaxCategory_ID() != getC_TaxCategory_ID())
{
setC_TaxCategory_ID(parent.getC_TaxCategory_ID());
changed = true;
}
//
return changed;
} // setExpenseType
/**
* Set Resource
* @param parent resource
* @return true if changed
*/
public boolean setResource (MResource parent)
{
boolean changed = false;
if (!PRODUCTTYPE_Resource.equals(getProductType()))
{
setProductType(PRODUCTTYPE_Resource);
changed = true;
}
if (parent.getS_Resource_ID() != getS_Resource_ID())
{
setS_Resource_ID(parent.getS_Resource_ID());
changed = true;
}
if (parent.isActive() != isActive())
{
setIsActive(parent.isActive());
changed = true;
}
//
if (!parent.getValue().equals(getValue()))
{
setValue(parent.getValue());
changed = true;
}
if (!parent.getName().equals(getName()))
{
setName(parent.getName());
changed = true;
}
if ((parent.getDescription() == null && getDescription() != null)
|| (parent.getDescription() != null && !parent.getDescription().equals(getDescription())))
{
setDescription(parent.getDescription());
changed = true;
}
//
return changed;
} // setResource
/**
* Set Resource Type
* @param parent resource type
* @return true if changed
*/
public boolean setResource (MResourceType parent)
{
boolean changed = false;
if (PRODUCTTYPE_Resource.equals(getProductType()))
{
setProductType(PRODUCTTYPE_Resource);
changed = true;
}
//
if (parent.getC_UOM_ID() != getC_UOM_ID())
{
setC_UOM_ID(parent.getC_UOM_ID());
changed = true;
}
if (parent.getM_Product_Category_ID() != getM_Product_Category_ID())
{
setM_Product_Category_ID(parent.getM_Product_Category_ID());
changed = true;
}
if (parent.getC_TaxCategory_ID() != getC_TaxCategory_ID())
{
setC_TaxCategory_ID(parent.getC_TaxCategory_ID());
changed = true;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -