📄 mproduct.java
字号:
}
//
return changed;
} // setResource
/** UOM Precision */
private Integer m_precision = null;
/**
* Get UOM Standard Precision
* @return UOM Standard Precision
*/
public int getStandardPrecision()
{
if (m_precision == null)
{
MUOM uom = MUOM.get(getCtx(), getC_UOM_ID());
m_precision = new Integer (uom.getStdPrecision());
}
return m_precision.intValue();
} // getStandardPrecision
/**
* Create Asset Group for this product
* @return asset group id
*/
public int getA_Asset_Group_ID()
{
MProductCategory pc = MProductCategory.get(getCtx(), getM_Product_Category_ID());
return pc.getA_Asset_Group_ID();
} // getA_Asset_Group_ID
/**
* Create Asset for this product
* @return true if asset is created
*/
public boolean isCreateAsset()
{
MProductCategory pc = MProductCategory.get(getCtx(), getM_Product_Category_ID());
return pc.getA_Asset_Group_ID() != 0;
} // isCreated
/**
* Get Attribute Set
* @return set or null
*/
public MAttributeSet getAttributeSet()
{
if (getM_AttributeSet_ID() != 0)
return MAttributeSet.get(getCtx(), getM_AttributeSet_ID());
return null;
} // getAttributeSet
/**
* Has the Product Instance Attribute
* @return true if instance attributes
*/
public boolean isInstanceAttribute()
{
if (getM_AttributeSet_ID() == 0)
return false;
MAttributeSet mas = MAttributeSet.get(getCtx(), getM_AttributeSet_ID());
return mas.isInstanceAttribute();
} // isInstanceAttribute
/**
* Create One Asset Per UOM
* @return individual asset
*/
public boolean isOneAssetPerUOM()
{
MProductCategory pc = MProductCategory.get(getCtx(), getM_Product_Category_ID());
if (pc.getA_Asset_Group_ID() == 0)
return false;
MAssetGroup ag = MAssetGroup.get(getCtx(), pc.getA_Asset_Group_ID());
return ag.isOneAssetPerUOM();
} // isOneAssetPerUOM
/**
* Product is Item
* @return true if item
*/
public boolean isItem()
{
return PRODUCTTYPE_Item.equals(getProductType());
} // isItem
/**
* Product is an Item and Stocked
* @return true if stocked and item
*/
public boolean isStocked ()
{
return super.isStocked() && isItem();
} // isStocked
/**
* Is Service
* @return true if service (resource, online)
*/
public boolean isService()
{
// PRODUCTTYPE_Service, PRODUCTTYPE_Resource, PRODUCTTYPE_Online
return !isItem(); //
} // isService
/**
* Get UOM Symbol
* @return UOM Sumbol
*/
public String getUOMSymbol()
{
return MUOM.get(getCtx(), getC_UOM_ID()).getUOMSymbol();
} // getUOMSymbol
/**
* Get Active(!) Product Downloads
* @return array of downloads
*/
public MProductDownload[] getProductDownloads (boolean requery)
{
if (m_downloads != null && !requery)
return m_downloads;
//
ArrayList<MProductDownload> list = new ArrayList<MProductDownload>();
String sql = "SELECT * FROM M_ProductDownload "
+ "WHERE M_Product_ID=? AND IsActive='Y' ORDER BY Name";
//
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getM_Product_ID());
ResultSet rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MProductDownload (getCtx(), rs, get_TrxName()));
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
//
m_downloads = new MProductDownload[list.size ()];
list.toArray (m_downloads);
return m_downloads;
} // getProductDownloads
/**
* Does the product have downloads
* @return true if downloads exists
*/
public boolean hasDownloads()
{
getProductDownloads(false);
return m_downloads != null && m_downloads.length > 0;
} // hasDownloads
/**
* String Representation
* @return info
*/
public String toString()
{
StringBuffer sb = new StringBuffer("MProduct[");
sb.append(get_ID()).append("-").append(getValue())
.append("]");
return sb.toString();
} // toString
/**
* Before Save
* @param newRecord new
* @return true
*/
protected boolean beforeSave (boolean newRecord)
{
// Check Storage
if (!newRecord && //
((is_ValueChanged("IsActive") && !isActive()) // now not active
|| (is_ValueChanged("IsStocked") && !isStocked()) // now not stocked
|| (is_ValueChanged("ProductType") // from Item
&& PRODUCTTYPE_Item.equals(get_ValueOld("ProductType")))))
{
MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
BigDecimal OnHand = Env.ZERO;
BigDecimal Ordered = Env.ZERO;
BigDecimal Reserved = Env.ZERO;
for (int i = 0; i < storages.length; i++)
{
OnHand = OnHand.add(storages[i].getQtyOnHand());
Ordered = OnHand.add(storages[i].getQtyOrdered());
Reserved = OnHand.add(storages[i].getQtyReserved());
}
String errMsg = "";
if (OnHand.signum() != 0)
errMsg = "@QtyOnHand@ = " + OnHand;
if (Ordered.signum() != 0)
errMsg += " - @QtyOrdered@ = " + Ordered;
if (Reserved.signum() != 0)
errMsg += " - @QtyReserved@" + Reserved;
if (errMsg.length() > 0)
{
log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
return false;
}
}
// Reset Stocked if not Item
if (isStocked() && !PRODUCTTYPE_Item.equals(getProductType()))
setIsStocked(false);
return true;
} // beforeSave
/**
* After Save
* @param newRecord new
* @param success success
* @return success
*/
protected boolean afterSave (boolean newRecord, boolean success)
{
if (!success)
return success;
// Value/Name change in Account
if (!newRecord && (is_ValueChanged("Value") || is_ValueChanged("Name")))
MAccount.updateValueDescription(getCtx(), "M_Product_ID=" + getM_Product_ID(), get_TrxName());
// Name/Description Change in Asset MAsset.setValueNameDescription
if (!newRecord && (is_ValueChanged("Name") || is_ValueChanged("Description")))
{
String sql = "UPDATE A_Asset a "
+ "SET (Name, Description)="
+ "(SELECT SUBSTR(bp.Name || ' - ' || p.Name,1,60), p.Description "
+ "FROM M_Product p, C_BPartner bp "
+ "WHERE p.M_Product_ID=a.M_Product_ID AND bp.C_BPartner_ID=a.C_BPartner_ID) "
+ "WHERE IsActive='Y'"
// + " AND GuaranteeDate > SysDate"
+ " AND M_Product_ID=" + getM_Product_ID();
int no = DB.executeUpdate(sql, get_TrxName());
log.fine("Asset Description updated #" + no);
}
// New - Acct, Tree, Costing
if (newRecord & success)
{
insert_Accounting("M_Product_Acct", "M_Product_Category_Acct",
"p.M_Product_Category_ID=" + getM_Product_Category_ID());
insert_Tree(MTree_Base.TREETYPE_Product);
MAcctSchema[] mass = MAcctSchema.getClientAcctSchema(getCtx(), getAD_Client_ID(), get_TrxName());
for (int i = 0; i < mass.length; i++)
{
MProductCosting pc = new MProductCosting(this, mass[i].getC_AcctSchema_ID());
pc.save();
}
}
return success;
} // afterSave
/**
* Before Delete
* @return true if it can be deleted
*/
protected boolean beforeDelete ()
{
// Check Storage
if (isStocked() || PRODUCTTYPE_Item.equals(getProductType()))
{
MStorage[] storages = MStorage.getOfProduct(getCtx(), get_ID(), get_TrxName());
BigDecimal OnHand = Env.ZERO;
BigDecimal Ordered = Env.ZERO;
BigDecimal Reserved = Env.ZERO;
for (int i = 0; i < storages.length; i++)
{
OnHand = OnHand.add(storages[i].getQtyOnHand());
Ordered = OnHand.add(storages[i].getQtyOrdered());
Reserved = OnHand.add(storages[i].getQtyReserved());
}
String errMsg = "";
if (OnHand.signum() != 0)
errMsg = "@QtyOnHand@ = " + OnHand;
if (Ordered.signum() != 0)
errMsg += " - @QtyOrdered@ = " + Ordered;
if (Reserved.signum() != 0)
errMsg += " - @QtyReserved@" + Reserved;
if (errMsg.length() > 0)
{
log.saveError("Error", Msg.parseTranslation(getCtx(), errMsg));
return false;
}
}
// delete costing
MProductCosting[] costings = MProductCosting.getOfProduct(getCtx(), get_ID(), get_TrxName());
for (int i = 0; i < costings.length; i++)
costings[i].delete(true, get_TrxName());
//
return delete_Accounting("M_Product_Acct");
} // beforeDelete
/**
* After Delete
* @param success
* @return deleted
*/
protected boolean afterDelete (boolean success)
{
if (success)
delete_Tree(MTree_Base.TREETYPE_Product);
return success;
} // afterDelete
} // MProduct
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -