MPPProductBOM, MPPProductBOMLine, CalculateLowLevel, PP_Product_BOM_Check:
BF [ 1874419 ] JDBC Statement not close in a finally block BF [ 2041456 ] Don't use Env.getCtx in base project * added cache support (MPPProductBOM.get()) * refactored a lot of code * removed static and pseudo-static methods and properties (like getLines, getLowLevel) * removed deprecated and not used code (too much code to maintain) * better exception handling support
This commit is contained in:
parent
0544b26115
commit
b4f4756a4e
|
@ -31,6 +31,9 @@ import org.compiere.util.Env;
|
||||||
*/
|
*/
|
||||||
public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -92,26 +95,23 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
||||||
return success;
|
return success;
|
||||||
//Qty Ordered to Phantom
|
//Qty Ordered to Phantom
|
||||||
BigDecimal QtyOrdered = getQtyRequiered();
|
BigDecimal QtyOrdered = getQtyRequiered();
|
||||||
System.out.println(" Padre Product" + getM_Product_ID() + " getQtyBatch" + getQtyBatch() + " getQtyRequiered" + getQtyRequiered() + " QtyScrap" + getQtyScrap());
|
log.fine(" Parent Product" + getM_Product_ID() + " getQtyBatch" + getQtyBatch() + " getQtyRequiered" + getQtyRequiered() + " QtyScrap" + getQtyScrap());
|
||||||
//Phantom
|
//Phantom
|
||||||
if(getComponentType().equals(MPPProductBOMLine.COMPONENTTYPE_Phantom))
|
if(getComponentType().equals(MPPProductBOMLine.COMPONENTTYPE_Phantom))
|
||||||
{
|
{
|
||||||
|
|
||||||
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(getM_Product_ID());
|
int PP_Product_BOM_ID = MPPProductBOM.getBOMSearchKey(getCtx(), getM_Product_ID());
|
||||||
if (PP_Product_BOM_ID==0)
|
if (PP_Product_BOM_ID <= 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
MPPProductBOM bom = new MPPProductBOM(getCtx(),PP_Product_BOM_ID,get_TrxName());
|
MPPProductBOM bom = MPPProductBOM.get(getCtx(), PP_Product_BOM_ID);
|
||||||
if (bom!= null)
|
if (bom != null)
|
||||||
{
|
{
|
||||||
MPPProductBOMLine[] PP_Product_BOMline = bom.getLines();
|
MPPProductBOMLine[] PP_Product_BOMline = bom.getLines();
|
||||||
|
|
||||||
if (PP_Product_BOMline == null)
|
|
||||||
return true;
|
|
||||||
for(int i = 0 ; i < PP_Product_BOMline.length ; i++ )
|
for(int i = 0 ; i < PP_Product_BOMline.length ; i++ )
|
||||||
{
|
{
|
||||||
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(getCtx(),0,get_TrxName());
|
MPPOrderBOMLine PP_Order_BOMLine = new MPPOrderBOMLine(getCtx(), 0, get_TrxName());
|
||||||
MProduct product = new MProduct(getCtx(),PP_Product_BOMline[i].getM_Product_ID(),get_TrxName());
|
MProduct product = MProduct.get(getCtx(),PP_Product_BOMline[i].getM_Product_ID());
|
||||||
PP_Order_BOMLine.setDescription(PP_Product_BOMline[i].getDescription());
|
PP_Order_BOMLine.setDescription(PP_Product_BOMline[i].getDescription());
|
||||||
PP_Order_BOMLine.setHelp(PP_Product_BOMline[i].getHelp());
|
PP_Order_BOMLine.setHelp(PP_Product_BOMline[i].getHelp());
|
||||||
PP_Order_BOMLine.setM_ChangeNotice_ID(PP_Product_BOMline[i].getM_ChangeNotice_ID());
|
PP_Order_BOMLine.setM_ChangeNotice_ID(PP_Product_BOMline[i].getM_ChangeNotice_ID());
|
||||||
|
@ -137,7 +137,7 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
||||||
if (PP_Order_BOMLine.isQtyPercentage())
|
if (PP_Order_BOMLine.isQtyPercentage())
|
||||||
{
|
{
|
||||||
BigDecimal qty = PP_Order_BOMLine.getQtyBatch().multiply(QtyOrdered);
|
BigDecimal qty = PP_Order_BOMLine.getQtyBatch().multiply(QtyOrdered);
|
||||||
System.out.println("product:"+product.getName() +" Qty:"+qty + " QtyOrdered:"+ QtyOrdered + " PP_Order_BOMLine.getQtyBatch():" + PP_Order_BOMLine.getQtyBatch());
|
log.fine("product:"+product.getName() +" Qty:"+qty + " QtyOrdered:"+ QtyOrdered + " PP_Order_BOMLine.getQtyBatch():" + PP_Order_BOMLine.getQtyBatch());
|
||||||
if(PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Packing))
|
if(PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Packing))
|
||||||
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,BigDecimal.ROUND_UP));
|
PP_Order_BOMLine.setQtyRequiered(qty.divide(new BigDecimal(100),8,BigDecimal.ROUND_UP));
|
||||||
else if (PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Phantom))
|
else if (PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Component) || PP_Order_BOMLine.getComponentType().equals(COMPONENTTYPE_Phantom))
|
||||||
|
@ -166,7 +166,7 @@ public class MPPOrderBOMLine extends X_PP_Order_BOMLine
|
||||||
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyRequiered().divide( Env.ONE.subtract(Scrap) , 8 ,BigDecimal.ROUND_HALF_UP ));
|
PP_Order_BOMLine.setQtyRequiered(PP_Order_BOMLine.getQtyRequiered().divide( Env.ONE.subtract(Scrap) , 8 ,BigDecimal.ROUND_HALF_UP ));
|
||||||
}
|
}
|
||||||
System.out.println("Cantidad Requerida" + PP_Order_BOMLine.getQtyRequiered());
|
System.out.println("Cantidad Requerida" + PP_Order_BOMLine.getQtyRequiered());
|
||||||
PP_Order_BOMLine.save();
|
PP_Order_BOMLine.saveEx();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
//package org.compiere.mfg.model;
|
//package org.compiere.mfg.model;
|
||||||
package org.eevolution.model;
|
package org.eevolution.model;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -26,24 +25,51 @@ import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.model.PO;
|
import org.compiere.model.PO;
|
||||||
|
import org.compiere.model.Query;
|
||||||
|
import org.compiere.util.CCache;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Model.
|
* PP Product BOM Model.
|
||||||
* Please do not set DocStatus and C_DocType_ID directly.
|
|
||||||
* They are set in the process() method.
|
|
||||||
* Use DocAction and C_DocTypeTarget_ID instead.
|
|
||||||
*
|
*
|
||||||
* @author Victor Perez www.e-evolution.com
|
* @author Victor Perez www.e-evolution.com
|
||||||
* @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $
|
* @version $Id: MOrder.java,v 1.40 2004/04/13 04:19:30 vpj-cd Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*/
|
*/
|
||||||
public class MPPProductBOM extends X_PP_Product_BOM
|
public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** Static Logger */
|
||||||
private static CLogger log = CLogger.getCLogger(MPPProductBOM.class);
|
private static CLogger log = CLogger.getCLogger(MPPProductBOM.class);
|
||||||
|
/** Cache */
|
||||||
|
private static CCache<Integer,MPPProductBOM> s_cache = new CCache<Integer,MPPProductBOM>(Table_Name, 40, 5); // 5 minutes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load/Get Product BOM by ID (cached)
|
||||||
|
* @param ctx
|
||||||
|
* @param PP_Product_BOM_ID
|
||||||
|
* @return product bom
|
||||||
|
*/
|
||||||
|
public static MPPProductBOM get(Properties ctx, int PP_Product_BOM_ID)
|
||||||
|
{
|
||||||
|
if (PP_Product_BOM_ID <= 0)
|
||||||
|
return null;
|
||||||
|
MPPProductBOM bom = s_cache.get(PP_Product_BOM_ID);
|
||||||
|
if (bom != null)
|
||||||
|
return bom;
|
||||||
|
bom = new MPPProductBOM(ctx, PP_Product_BOM_ID, null);
|
||||||
|
if (bom.get_ID() == PP_Product_BOM_ID) {
|
||||||
|
s_cache.put(PP_Product_BOM_ID, bom);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bom = null;
|
||||||
|
}
|
||||||
|
return bom;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
|
@ -161,13 +187,12 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
* BUG #104
|
* BUG #104
|
||||||
* @param lines
|
* @param lines
|
||||||
*/
|
*/
|
||||||
|
private void setLines(List<MPPProductBOMLine> lines) {
|
||||||
List lines = null;
|
|
||||||
|
|
||||||
public void setLines(List lines) {
|
|
||||||
this.lines = lines;
|
this.lines = lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<MPPProductBOMLine> lines = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BUG #? - Does not persist objects!
|
* BUG #? - Does not persist objects!
|
||||||
* @param ctx
|
* @param ctx
|
||||||
|
@ -181,7 +206,7 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
newBom.setDocumentNo(null);
|
newBom.setDocumentNo(null);
|
||||||
|
|
||||||
if (copyLines) {
|
if (copyLines) {
|
||||||
List newLines = new ArrayList();
|
List<MPPProductBOMLine> newLines = new ArrayList<MPPProductBOMLine>();
|
||||||
MPPProductBOMLine[] fromLines = from.getLines();
|
MPPProductBOMLine[] fromLines = from.getLines();
|
||||||
for (int i = 0; i < fromLines.length; i++) {
|
for (int i = 0; i < fromLines.length; i++) {
|
||||||
MPPProductBOMLine line = new MPPProductBOMLine(ctx, 0,null);
|
MPPProductBOMLine line = new MPPProductBOMLine(ctx, 0,null);
|
||||||
|
@ -206,7 +231,6 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
return sb.toString ();
|
return sb.toString ();
|
||||||
} // toString
|
} // toString
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BOM for Product
|
* Get BOM for Product
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -214,32 +238,25 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
* @param trxName Transaction Name
|
* @param trxName Transaction Name
|
||||||
* @return BOM
|
* @return BOM
|
||||||
*/
|
*/
|
||||||
public static MPPProductBOM get(MProduct product , int ad_org_id, String trxName)
|
public static MPPProductBOM get(MProduct product, int ad_org_id, String trxName)
|
||||||
{
|
{
|
||||||
|
|
||||||
MPPProductBOM bom = null;
|
MPPProductBOM bom = null;
|
||||||
|
|
||||||
Properties ctx = product.getCtx();
|
Properties ctx = product.getCtx();
|
||||||
// find Default BOM in Product Data Planning
|
// find Default BOM in Product Data Planning
|
||||||
if (ad_org_id > 0 )
|
if (ad_org_id > 0 )
|
||||||
{
|
{
|
||||||
MPPProductPlanning pp = MPPProductPlanning.get(ctx, product.getAD_Client_ID(),ad_org_id, product.getM_Product_ID(), trxName);
|
MPPProductPlanning pp = MPPProductPlanning.get(ctx, product.getAD_Client_ID(),ad_org_id, product.getM_Product_ID(), trxName);
|
||||||
|
if(pp != null && pp.getPP_Product_BOM_ID() > 0 )
|
||||||
if(pp!= null && pp.getPP_Product_BOM_ID() > 0 )
|
|
||||||
{
|
{
|
||||||
bom = new MPPProductBOM(ctx, pp.getPP_Product_BOM_ID(),trxName);
|
bom = new MPPProductBOM(ctx, pp.getPP_Product_BOM_ID(),trxName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (bom == null)
|
||||||
if (bom == null)
|
|
||||||
{
|
{
|
||||||
//Find BOM with Default Logic where product = bom product and bom value = value
|
//Find BOM with Default Logic where product = bom product and bom value = value
|
||||||
String sql = "SELECT PP_Product_BOM_ID FROM PP_Product_BOM WHERE M_Product_ID=? AND Value=?";
|
bom = getDefault(product, trxName);
|
||||||
int m_PP_Product_BOM_ID = DB.getSQLValue(trxName, sql, product.getM_Product_ID(), product.getValue());
|
|
||||||
bom = new MPPProductBOM(product.getCtx(), m_PP_Product_BOM_ID ,product.get_TableName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return bom;
|
return bom;
|
||||||
|
|
||||||
} // getBOM
|
} // getBOM
|
||||||
|
@ -252,46 +269,23 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
* @param trxName Transaction Name
|
* @param trxName Transaction Name
|
||||||
* @return BOM
|
* @return BOM
|
||||||
*/
|
*/
|
||||||
public static MPPProductBOM get(MProduct product , int ad_org_id, Timestamp valid , String trxName)
|
public static MPPProductBOM get(MProduct product, int ad_org_id, Timestamp valid, String trxName)
|
||||||
{
|
{
|
||||||
|
MPPProductBOM bom = get(product, ad_org_id, trxName);
|
||||||
MPPProductBOM bom = null;
|
//
|
||||||
|
// Validate date
|
||||||
Properties ctx = product.getCtx();
|
|
||||||
// find Default BOM in Product Data Planning
|
|
||||||
if (ad_org_id > 0 )
|
|
||||||
{
|
|
||||||
MPPProductPlanning pp = MPPProductPlanning.get(ctx, product.getAD_Client_ID() ,ad_org_id, product.getM_Product_ID(), trxName);
|
|
||||||
|
|
||||||
if(pp!= null && pp.getPP_Product_BOM_ID() > 0 )
|
|
||||||
{
|
|
||||||
bom = new MPPProductBOM(ctx, pp.getPP_Product_BOM_ID(),trxName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bom == null)
|
|
||||||
{
|
|
||||||
//Find BOM with Default Logic where product = bom product and bom value = value
|
|
||||||
String sql = "SELECT PP_Product_BOM_ID FROM PP_Product_BOM WHERE M_Product_ID=? AND Value=?";
|
|
||||||
int m_PP_Product_BOM_ID = DB.getSQLValue(trxName, sql, product.getM_Product_ID(), product.getValue());
|
|
||||||
bom = new MPPProductBOM(product.getCtx(), m_PP_Product_BOM_ID ,product.get_TableName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bom != null)
|
if (bom != null)
|
||||||
{
|
{
|
||||||
boolean ValidFromBOM = true;
|
boolean ValidFromBOM = true;
|
||||||
boolean ValidToBOM = true;
|
boolean ValidToBOM = true;
|
||||||
|
|
||||||
if (bom.getValidFrom() != null)
|
if (bom.getValidFrom() != null)
|
||||||
{
|
{
|
||||||
ValidFromBOM = valid.compareTo(bom.getValidFrom()) >= 0 ? true : false;
|
ValidFromBOM = valid.compareTo(bom.getValidFrom()) >= 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bom.getValidTo() != null )
|
if (bom.getValidTo() != null )
|
||||||
{
|
{
|
||||||
ValidToBOM = valid.compareTo(bom.getValidTo()) <= 0 ? true : false;
|
ValidToBOM = valid.compareTo(bom.getValidTo()) <= 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ValidFromBOM && ValidToBOM)
|
if(ValidFromBOM && ValidToBOM)
|
||||||
{
|
{
|
||||||
return bom;
|
return bom;
|
||||||
|
@ -304,236 +298,75 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
|
|
||||||
} // getBOM
|
} // getBOM
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Get BOM lines
|
|
||||||
* @return Array of BOM Lines
|
|
||||||
*/
|
|
||||||
public MPPProductBOMLine[] getLines()
|
|
||||||
{
|
|
||||||
return getLines (getPP_Product_BOM_ID());
|
|
||||||
} // getLines
|
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* Get BOM lines
|
|
||||||
* @param valid date to validate
|
|
||||||
* @return Array of BOM Lines
|
|
||||||
*/
|
|
||||||
public MPPProductBOMLine[] getLines(Timestamp valid)
|
|
||||||
{
|
|
||||||
return getLines (getPP_Product_BOM_ID(), valid);
|
|
||||||
} // getLines
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BOM Lines valid date for Product BOM
|
* Get BOM Lines valid date for Product BOM
|
||||||
* @param pp_product_bom_id BOM ID
|
|
||||||
* @param valid Date to Validate
|
* @param valid Date to Validate
|
||||||
* @return BOM Lines
|
* @return BOM Lines
|
||||||
*/
|
*/
|
||||||
public MPPProductBOMLine[] getLines (int pp_product_bom_id , Timestamp valid)
|
public MPPProductBOMLine[] getLines (Timestamp valid)
|
||||||
{
|
{
|
||||||
|
MPPProductBOMLine[] bomlines = getLines(); // All BOM Lines
|
||||||
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
List<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine>(); // Selected BOM Lines Only
|
||||||
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
for (MPPProductBOMLine bl : bomlines) {
|
||||||
PreparedStatement pstmt = null;
|
boolean ValidFromBOMLine = true;
|
||||||
try
|
boolean ValidToBOMLine = true;
|
||||||
{
|
if (bl.getValidFrom() != null)
|
||||||
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
|
||||||
pstmt.setInt(1, pp_product_bom_id);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
{
|
||||||
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
ValidFromBOMLine = valid.compareTo(bl.getValidFrom()) >= 0 ? true : false;
|
||||||
boolean ValidFromBOMLine = true;
|
|
||||||
boolean ValidToBOMLine = true;
|
|
||||||
if (bl.getValidFrom() != null)
|
|
||||||
{
|
|
||||||
ValidFromBOMLine = valid.compareTo(bl.getValidFrom()) >= 0 ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bl.getValidTo() != null )
|
|
||||||
{
|
|
||||||
ValidToBOMLine = valid.compareTo(bl.getValidTo()) <= 0 ? true : false;
|
|
||||||
}
|
|
||||||
if(ValidFromBOMLine && ValidToBOMLine)
|
|
||||||
{
|
|
||||||
list.add(bl);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rs.close();
|
if (bl.getValidTo() != null )
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
ValidToBOMLine = valid.compareTo(bl.getValidTo()) <= 0 ? true : false;
|
||||||
pstmt.close ();
|
}
|
||||||
|
if(ValidFromBOMLine && ValidToBOMLine)
|
||||||
|
{
|
||||||
|
list.add(bl);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{}
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
return list.toArray(new MPPProductBOMLine[list.size()]);
|
||||||
list.toArray (lines);
|
|
||||||
return lines;
|
|
||||||
|
|
||||||
} // getLines
|
} // getLines
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BOM Lines for Product BOM
|
* Get BOM Lines for Product BOM
|
||||||
* @param pp_product_bom_id BOM ID
|
|
||||||
* @return BOM Lines
|
* @return BOM Lines
|
||||||
*/
|
*/
|
||||||
public MPPProductBOMLine[] getLines (int PP_Product_BOM_ID)
|
public MPPProductBOMLine[] getLines()
|
||||||
{
|
{
|
||||||
|
// TODO: add caching support
|
||||||
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
String whereClause = MPPProductBOMLine.COLUMNNAME_PP_Product_BOM_ID+"=?";
|
||||||
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
List<MPPProductBOMLine> list = new Query(getCtx(), MPPProductBOMLine.Table_Name, whereClause, get_TrxName())
|
||||||
PreparedStatement pstmt = null;
|
.setParameters(new Object[]{getPP_Product_BOM_ID()})
|
||||||
try
|
.list();
|
||||||
{
|
return list.toArray(new MPPProductBOMLine[list.size()]);
|
||||||
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
|
||||||
pstmt.setInt(1, PP_Product_BOM_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
|
||||||
list.add(bl);
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{}
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
|
||||||
list.toArray (lines);
|
|
||||||
return lines;
|
|
||||||
|
|
||||||
} // getLines
|
} // getLines
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new Order by copying
|
* Get PP_Product_BOM_ID for given M_Product_ID
|
||||||
* @param ctx context
|
* @param M_Product_ID
|
||||||
* @param C_Order_ID invoice
|
* @return PP_Product_BOM_ID
|
||||||
* @param dateDoc date of the document date
|
|
||||||
* @return Order
|
|
||||||
*/
|
*/
|
||||||
public static MPPProductBOM copyFrom (Properties ctx, int PP_Product_BOM_ID, Timestamp dateDoc)
|
public static int getBOMSearchKey(Properties ctx, int M_Product_ID)
|
||||||
{
|
{
|
||||||
MPPProductBOM from = new MPPProductBOM (ctx, PP_Product_BOM_ID,"PP_Product_BOM");
|
int AD_Client_ID = Env.getAD_Client_ID(ctx);
|
||||||
if (from.getPP_Product_BOM_ID() == 0)
|
|
||||||
throw new IllegalArgumentException ("From Invoice not found C_Invoice_ID=" + PP_Product_BOM_ID);
|
|
||||||
//
|
|
||||||
MPPProductBOM to = new MPPProductBOM (ctx, 0,"PP_Product_BOM");
|
|
||||||
PO.copyValues(from, to, from.getAD_Client_ID(), from.getAD_Org_ID());
|
|
||||||
to.setPP_Product_BOM_ID(0);
|
|
||||||
//to.set_ValueNoCheck ("DocumentNo", null);
|
|
||||||
//
|
|
||||||
//to.setDocStatus (DOCSTATUS_Drafted); // Draft
|
|
||||||
//to.setDocAction(DOCACTION_Prepare);
|
|
||||||
//to.setC_DocTypeTarget_ID(to.getC_DocType_ID());
|
|
||||||
//to.setC_DocType_ID(0);
|
|
||||||
//to.setIsSelected (false);
|
|
||||||
//to.setDateOrdered (dateDoc);
|
|
||||||
//to.setDateAcct (dateDoc);
|
|
||||||
//to.setDatePromised (dateDoc);
|
|
||||||
//
|
|
||||||
//to.setIsApproved (false);
|
|
||||||
//to.setIsCreditApproved(false);
|
|
||||||
//to.setC_Payment_ID(0);
|
|
||||||
//to.setC_CashLine_ID(0);
|
|
||||||
// Amounts are updated by trigger when adding lines
|
|
||||||
//to.setGrandTotal(Env.ZERO);
|
|
||||||
//to.setTotalLines(Env.ZERO);
|
|
||||||
//
|
|
||||||
//to.setIsDelivered(false);
|
|
||||||
//to.setIsInvoiced(false);
|
|
||||||
//to.setIsSelfService(false);
|
|
||||||
//to.setDatePrinted(null);
|
|
||||||
//to.setIsPrinted (false);
|
|
||||||
//to.setIsTransferred (false);
|
|
||||||
//to.setPosted (false);
|
|
||||||
//to.setProcessed (false);
|
|
||||||
//
|
|
||||||
if (!to.save())
|
|
||||||
throw new IllegalStateException("Could not create Order");
|
|
||||||
|
|
||||||
if (to.copyLinesFrom(from) == 0)
|
MProduct product = MProduct.get(ctx, M_Product_ID);
|
||||||
throw new IllegalStateException("Could not create Order Lines");
|
String sql = "SELECT pb.PP_Product_BOM_ID FROM PP_Product_BOM pb"
|
||||||
|
+" WHERE pb.Value = ? AND pb.AD_Client_ID = ?";
|
||||||
return to;
|
return DB.getSQLValue(null, sql, product.getValue(), AD_Client_ID);
|
||||||
} // copyFrom
|
|
||||||
|
|
||||||
public static int getBOMSearchKey(int M_Product_ID)
|
|
||||||
{
|
|
||||||
|
|
||||||
int PP_Product_BOM_ID = 0;
|
|
||||||
int AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
|
|
||||||
|
|
||||||
MProduct product = new MProduct(Env.getCtx(), M_Product_ID, "M_Product");
|
|
||||||
String sql = "SELECT pb.PP_Product_BOM_ID FROM PP_Product_BOM pb WHERE pb.Value = ? AND pb.AD_Client_ID = ?";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql);
|
|
||||||
pstmt.setString(1, product.getValue());
|
|
||||||
pstmt.setInt(2, AD_Client_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
PP_Product_BOM_ID = rs.getInt(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
return PP_Product_BOM_ID;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE,"getProductPlanning", e);
|
|
||||||
}
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // MPP_ProductBOM
|
/**
|
||||||
|
* Get BOM with Default Logic (Product = BOM Product and BOM Value = Product Value)
|
||||||
|
* @param product
|
||||||
|
* @param trxName
|
||||||
|
* @return product BOM
|
||||||
|
*/
|
||||||
|
public static MPPProductBOM getDefault(MProduct product, String trxName) {
|
||||||
|
return new Query(product.getCtx(), Table_Name, "M_Product_ID=? AND Value=?", trxName)
|
||||||
|
.setParameters(new Object[]{product.getM_Product_ID(), product.getValue()})
|
||||||
|
.first();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} // MPPProductBOM
|
||||||
|
|
|
@ -20,35 +20,31 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
|
||||||
|
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.tree.DefaultMutableTreeNode;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.adempiere.exceptions.DBException;
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.model.X_M_Product;
|
|
||||||
import org.compiere.util.CLogger;
|
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manufacturing Order Line Model.
|
* PP Product BOM Line Model.
|
||||||
* <code>
|
* <code>
|
||||||
* MPPProductBOMLine l = new MPPProductBOMLine(bom);
|
* MPPProductBOMLine l = new MPPProductBOMLine(bom);
|
||||||
l.setM_Product_ID(wbl.getM_Product_ID());
|
* l.setM_Product_ID(wbl.getM_Product_ID());
|
||||||
l.setQty(wbl.getQuantity());;
|
* l.setQty(wbl.getQuantity());;
|
||||||
l.save();
|
* l.saveEx();
|
||||||
* </code>
|
* </code>
|
||||||
* @author Victor Perez www.e-evolution.com
|
* @author Victor Perez www.e-evolution.com
|
||||||
* @version $Id: MOrderLine.java,v 1.22 2004/03/22 07:15:03 vpj-cd Exp $
|
* @version $Id: MOrderLine.java,v 1.22 2004/03/22 07:15:03 vpj-cd Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*/
|
*/
|
||||||
public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
{
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
static private int AD_Client_ID = 0;
|
|
||||||
static Hashtable<Integer, Integer> tableproduct = new Hashtable<Integer, Integer>();
|
|
||||||
private static CLogger s_log = CLogger.getCLogger(MPPProductBOMLine.class);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
|
@ -63,18 +59,13 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent Constructor.
|
* Parent Constructor.
|
||||||
ol.setM_Product_ID(wbl.getM_Product_ID());
|
* @param bom parent BOM
|
||||||
ol.setQtyOrdered(wbl.getQuantity());
|
|
||||||
ol.setPrice();
|
|
||||||
ol.setPriceActual(wbl.getPrice());
|
|
||||||
ol.setTax();
|
|
||||||
ol.save();
|
|
||||||
* @param order parent order
|
|
||||||
*/
|
*/
|
||||||
public MPPProductBOMLine(MPPProductBOM bom)
|
public MPPProductBOMLine(MPPProductBOM bom)
|
||||||
{
|
{
|
||||||
super(bom.getCtx(), 0, bom.get_TableName());
|
super(bom.getCtx(), 0, bom.get_TableName());
|
||||||
if (bom.get_ID() == 0) throw new IllegalArgumentException("Header not saved");
|
if (bom.get_ID() == 0)
|
||||||
|
throw new IllegalArgumentException("Header not saved");
|
||||||
setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); // parent
|
setPP_Product_BOM_ID(bom.getPP_Product_BOM_ID()); // parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,162 +80,78 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
} // MPPProductBOMLine
|
} // MPPProductBOMLine
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Defaults from BOM.
|
* Calculate Low Level of a Product
|
||||||
* Does not set Parent !!
|
* @param ID Product
|
||||||
* @param BOM BOM
|
* @return int low level
|
||||||
*/
|
*/
|
||||||
public void setMPPProductBOM(MPPProductBOM bom)
|
public int getLowLevel()
|
||||||
{
|
{
|
||||||
setClientOrg(bom);
|
return new ProductLowLevelCalculator(getCtx(), get_TrxName()).getLowLevel(getM_Product_ID());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* Calculate Low Level of a Product
|
||||||
* @return info
|
* @param ID Product
|
||||||
|
* @return int low level
|
||||||
*/
|
*/
|
||||||
public String toString()
|
public static int getLowLevel(Properties ctx, int M_Product_ID, String trxName)
|
||||||
{
|
{
|
||||||
StringBuffer sb = new StringBuffer("MPPProductBOMLine[").append(get_ID()).append("]");
|
return new ProductLowLevelCalculator(ctx, trxName).getLowLevel(M_Product_ID);
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**************************************************************************
|
||||||
* String Description
|
* After Save
|
||||||
* @return info
|
* @param newRecord new
|
||||||
|
* @return save
|
||||||
*/
|
*/
|
||||||
public String getDescriptionText()
|
protected boolean afterSave(boolean newRecord, boolean success)
|
||||||
{
|
{
|
||||||
return super.getDescription();
|
if (success)
|
||||||
} // getDescriptionText
|
{
|
||||||
|
int lowlevel = getLowLevel();
|
||||||
|
MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
|
||||||
|
product.setLowLevel(lowlevel); //update lowlevel
|
||||||
|
product.saveEx();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProductLowLevelCalculator {
|
||||||
|
private Hashtable<Integer, Integer> tableproduct = new Hashtable<Integer, Integer>();
|
||||||
|
private Properties m_ctx = null;
|
||||||
|
private String m_trxName = null;
|
||||||
|
|
||||||
|
public ProductLowLevelCalculator(Properties ctx, String trxName)
|
||||||
|
{
|
||||||
|
m_ctx = ctx;
|
||||||
|
m_trxName = trxName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get low level of a Product
|
* get low level of a Product
|
||||||
* @param ID Product
|
* @param ID Product
|
||||||
* @return int low level
|
* @return int low level
|
||||||
*/
|
*/
|
||||||
public int getLowLevel(int M_Product_ID) throws Exception
|
public int getLowLevel(int M_Product_ID)
|
||||||
{
|
{
|
||||||
AD_Client_ID = Integer.valueOf(getCtx().getProperty("#AD_Client_ID"));
|
int AD_Client_ID = Env.getAD_Client_ID(m_ctx);
|
||||||
tableproduct.clear(); //reset tableproduct cache
|
tableproduct.clear(); //reset tableproduct cache
|
||||||
DefaultMutableTreeNode ibom = null;
|
DefaultMutableTreeNode ibom = null;
|
||||||
|
|
||||||
tableproduct.put(M_Product_ID, 0); //insert parent into cache
|
tableproduct.put(M_Product_ID, 0); //insert parent into cache
|
||||||
ibom = iparent(M_Product_ID, 0); //start traversing tree
|
ibom = iparent(AD_Client_ID, M_Product_ID, 0); //start traversing tree
|
||||||
|
|
||||||
return ibom.getDepth();
|
return ibom.getDepth();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* get a implotion the a prduct
|
|
||||||
* @param ID Product
|
|
||||||
* @param ID BOM
|
|
||||||
* @return DefaultMutableTreeNode Tree with all parent product
|
|
||||||
*/
|
|
||||||
private DefaultMutableTreeNode parent(int M_Product_ID, int PP_Product_BOM_ID)
|
|
||||||
{
|
|
||||||
|
|
||||||
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
|
|
||||||
|
|
||||||
String sql = new String(
|
|
||||||
"SELECT pbom.PP_Product_BOM_ID FROM PP_Product_BOM pbom WHERE pbom.IsActive = 'Y' AND pbom.AD_Client_ID= ? AND pbom.M_Product_ID = ? ");
|
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
|
||||||
pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
|
|
||||||
pstmt.setInt(2, M_Product_ID);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
DefaultMutableTreeNode bom = component(rs.getInt(1), M_Product_ID, parent);
|
|
||||||
if (bom != null)
|
|
||||||
{
|
|
||||||
parent.add(bom);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, "doIt - " + sql + e);
|
|
||||||
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
return parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* get a explotion the a product
|
|
||||||
* @param ID BOM
|
|
||||||
* @param ID Product
|
|
||||||
* @param DefaultMutableTreeNode Tree BOM
|
|
||||||
* @return DefaultMutableTreeNode Tree with all components product
|
|
||||||
*/
|
|
||||||
private DefaultMutableTreeNode component(int M_Product_BOM_ID, int M_Product_ID, DefaultMutableTreeNode bom)
|
|
||||||
{
|
|
||||||
|
|
||||||
String sql = new String(
|
|
||||||
"SELECT pboml.M_Product_ID , pbom.Value , pboml.PP_Product_BOMLine_ID , pbom.PP_Product_BOM_ID FROM"
|
|
||||||
+ " PP_Product_BOM pbom INNER JOIN PP_Product_BOMLine pboml ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
|
|
||||||
+ " WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pbom.AD_Client_ID= ? AND pbom.PP_Product_BOM_ID = ? ");
|
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
|
||||||
pstmt.setInt(1, Env.getAD_Client_ID(Env.getCtx()));
|
|
||||||
pstmt.setInt(2, M_Product_BOM_ID);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
while (rs.next())
|
|
||||||
{
|
|
||||||
if (M_Product_ID != rs.getInt(1))
|
|
||||||
{
|
|
||||||
bom.add(parent(rs.getInt(1), rs.getInt(4)));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(null, "Componet will be deactivated for BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3)
|
|
||||||
+ ")", "Error Cycle BOM", JOptionPane.ERROR_MESSAGE);
|
|
||||||
MPPProductBOMLine PP_Product_BOMLine = new MPPProductBOMLine(Env.getCtx(), rs.getInt(3), get_TrxName());
|
|
||||||
PP_Product_BOMLine.setIsActive(false);
|
|
||||||
PP_Product_BOMLine.save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (rs.getRow() == 0)
|
|
||||||
{
|
|
||||||
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|0");
|
|
||||||
bom.add(parent);
|
|
||||||
return bom;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
s_log.log(Level.SEVERE, "doIt - " + sql + e);
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get an implotion the product
|
* get an implotion the product
|
||||||
* @param ID Product
|
* @param ID Product
|
||||||
* @param ID BOM
|
* @param ID BOM
|
||||||
* @return DefaultMutableTreeNode Tree with all parent product
|
* @return DefaultMutableTreeNode Tree with all parent product
|
||||||
*/
|
*/
|
||||||
private DefaultMutableTreeNode iparent(int M_Product_ID, int PP_Product_BOM_ID) throws Exception
|
private DefaultMutableTreeNode iparent(int AD_Client_ID, int M_Product_ID, int PP_Product_BOM_ID)
|
||||||
{
|
{
|
||||||
|
|
||||||
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
|
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(Integer.toString(M_Product_ID) + "|" + Integer.toString(PP_Product_BOM_ID));
|
||||||
|
@ -257,7 +164,7 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
pstmt = DB.prepareStatement(sql, m_trxName);
|
||||||
pstmt.setInt(1, AD_Client_ID);
|
pstmt.setInt(1, AD_Client_ID);
|
||||||
pstmt.setInt(2, M_Product_ID);
|
pstmt.setInt(2, M_Product_ID);
|
||||||
rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
@ -270,17 +177,16 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
tableproduct.clear();
|
tableproduct.clear();
|
||||||
tableproduct.put(M_Product_ID, PP_Product_BOM_ID); //insert parent into cache
|
tableproduct.put(M_Product_ID, PP_Product_BOM_ID); //insert parent into cache
|
||||||
}
|
}
|
||||||
DefaultMutableTreeNode bom = icomponent(rs.getInt(1), M_Product_ID, parent);
|
DefaultMutableTreeNode bom = icomponent(AD_Client_ID, rs.getInt(1), M_Product_ID, parent);
|
||||||
if (bom != null)
|
if (bom != null)
|
||||||
{
|
{
|
||||||
parent.add(bom);
|
parent.add(bom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parent;
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, "iparent - " + sql + e);
|
throw new DBException(e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
|
@ -296,17 +202,17 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
* @param ID BOM
|
* @param ID BOM
|
||||||
* @return DefaultMutableTreeNode Tree with all parent product
|
* @return DefaultMutableTreeNode Tree with all parent product
|
||||||
*/
|
*/
|
||||||
private DefaultMutableTreeNode icomponent(int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom) throws Exception
|
private DefaultMutableTreeNode icomponent(int AD_Client_ID, int PP_Product_BOMLine_ID, int M_Product_ID, DefaultMutableTreeNode bom)
|
||||||
{
|
{
|
||||||
String sql = new String(
|
String sql =
|
||||||
"SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml"
|
"SELECT pbom.M_Product_ID , pbom.Value , pbom.PP_Product_BOM_ID FROM PP_Product_BOMLine pboml"
|
||||||
+ " INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
|
+ " INNER JOIN PP_Product_BOM pbom ON (pbom.PP_Product_BOM_ID = pboml.PP_Product_BOM_ID)"
|
||||||
+ " WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pboml.AD_Client_ID =? AND pboml.PP_Product_BOMLine_ID = ? ");
|
+ " WHERE pbom.IsActive= 'Y' AND pboml.IsActive= 'Y' AND pboml.AD_Client_ID =? AND pboml.PP_Product_BOMLine_ID = ? ";
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
pstmt = DB.prepareStatement(sql, m_trxName);
|
||||||
pstmt.setInt(1, AD_Client_ID);
|
pstmt.setInt(1, AD_Client_ID);
|
||||||
pstmt.setInt(2, PP_Product_BOMLine_ID);
|
pstmt.setInt(2, PP_Product_BOMLine_ID);
|
||||||
rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
@ -316,26 +222,24 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
{
|
{
|
||||||
//BOM Loop Error
|
//BOM Loop Error
|
||||||
if (!tableproduct(rs.getInt(1), rs.getInt(3)))
|
if (!tableproduct(rs.getInt(1), rs.getInt(3)))
|
||||||
bom.add(iparent(rs.getInt(1), rs.getInt(3)));
|
bom.add(iparent(AD_Client_ID, rs.getInt(1), rs.getInt(3)));
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s_log.saveError("Error", "Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")");
|
throw new AdempiereException("Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ")");
|
||||||
throw new Exception(CLogger.retrieveError().toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Child = Parent error
|
//Child = Parent error
|
||||||
X_M_Product product = new X_M_Product(getCtx(), M_Product_ID, null);
|
MProduct product = MProduct.get(m_ctx, M_Product_ID);
|
||||||
s_log.saveError("Error", "Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) + ") - Component: "
|
throw new AdempiereException("Cycle BOM & Formula:" + rs.getString(2) + "(" + rs.getString(3) +")"
|
||||||
+ product.getValue() + "(" + product.getM_Product_ID() + ")");
|
+ " - Component: " + product.getValue() + "(" + product.getM_Product_ID() + ")");
|
||||||
throw new Exception(CLogger.retrieveError().toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
s_log.log(Level.SEVERE, "doIt - " + sql + e);
|
throw new DBException(e);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
DB.close(rs, pstmt);
|
DB.close(rs, pstmt);
|
||||||
|
@ -351,7 +255,7 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
* @param ID BOM
|
* @param ID BOM
|
||||||
* @return true if product is found
|
* @return true if product is found
|
||||||
*/
|
*/
|
||||||
private static boolean tableproduct(int M_Product_ID, int PP_Product_BOM_ID)
|
private boolean tableproduct(int M_Product_ID, int PP_Product_BOM_ID)
|
||||||
{
|
{
|
||||||
Integer p = new Integer(M_Product_ID);
|
Integer p = new Integer(M_Product_ID);
|
||||||
Integer bom = new Integer(PP_Product_BOM_ID);
|
Integer bom = new Integer(PP_Product_BOM_ID);
|
||||||
|
@ -363,30 +267,4 @@ public class MPPProductBOMLine extends X_PP_Product_BOMLine
|
||||||
tableproduct.put(p, bom);
|
tableproduct.put(p, bom);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
* After Save
|
|
||||||
* @param newRecord new
|
|
||||||
* @return save
|
|
||||||
*/
|
|
||||||
protected boolean afterSave(boolean newRecord, boolean success)
|
|
||||||
{
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
MProduct product = new MProduct(getCtx(), getM_Product_ID(), get_TrxName());
|
|
||||||
int lowlevel = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lowlevel = getLowLevel(getM_Product_ID());
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.saveError("Error", Msg.parseTranslation(getCtx(), e.getMessage()), false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
product.setLowLevel(lowlevel); //update lowlevel
|
|
||||||
product.save(get_TrxName());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,14 +16,12 @@
|
||||||
|
|
||||||
package org.eevolution.process;
|
package org.eevolution.process;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.util.logging.Level;
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import org.compiere.model.MProduct;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.process.ProcessInfoParameter;
|
import org.compiere.model.POResultSet;
|
||||||
|
import org.compiere.model.Query;
|
||||||
import org.compiere.process.SvrProcess;
|
import org.compiere.process.SvrProcess;
|
||||||
import org.compiere.util.DB;
|
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.eevolution.model.MPPProductBOMLine;
|
import org.eevolution.model.MPPProductBOMLine;
|
||||||
|
|
||||||
|
@ -32,63 +30,43 @@ import org.eevolution.model.MPPProductBOMLine;
|
||||||
*
|
*
|
||||||
* @author Victor Perez, e-Evolution, S.C.
|
* @author Victor Perez, e-Evolution, S.C.
|
||||||
* @version $Id: CalculateLowLevel.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $
|
* @version $Id: CalculateLowLevel.java,v 1.1 2004/06/22 05:24:03 vpj-cd Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*/
|
*/
|
||||||
public class CalculateLowLevel extends SvrProcess
|
public class CalculateLowLevel extends SvrProcess
|
||||||
{
|
{
|
||||||
/** */
|
|
||||||
|
|
||||||
private int AD_Client_ID = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare - e.g., get Parameters.
|
* Prepare - e.g., get Parameters.
|
||||||
*/
|
*/
|
||||||
protected void prepare()
|
protected void prepare()
|
||||||
{
|
{
|
||||||
AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
|
|
||||||
ProcessInfoParameter[] para = getParameter();
|
|
||||||
} // prepare
|
} // prepare
|
||||||
|
|
||||||
protected String doIt() throws Exception
|
protected String doIt() throws Exception
|
||||||
{
|
{
|
||||||
|
int count_ok = 0;
|
||||||
String sql = "SELECT p.M_Product_ID FROM M_Product p WHERE AD_Client_ID = " + AD_Client_ID;
|
int count_err = 0;
|
||||||
PreparedStatement pstmt = null;
|
//
|
||||||
ResultSet rs = null;
|
POResultSet<MProduct> rs = new Query(getCtx(), MProduct.Table_Name, "AD_Client_ID=?", get_TrxName())
|
||||||
try
|
.setParameters(new Object[]{Env.getAD_Client_ID(getCtx())})
|
||||||
{
|
.setOrderBy(MProduct.COLUMNNAME_M_Product_ID)
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
.scroll();
|
||||||
rs = pstmt.executeQuery();
|
rs.setCloseOnError(true);
|
||||||
while (rs.next())
|
while(rs.hasNext()) {
|
||||||
{
|
MProduct product = rs.next();
|
||||||
|
try {
|
||||||
int m_M_Product_ID = rs.getInt(1);
|
int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), product.get_ID(), get_TrxName());
|
||||||
if (m_M_Product_ID != 0)
|
product.setLowLevel(lowlevel);
|
||||||
{
|
product.saveEx();
|
||||||
MProduct product = new MProduct(getCtx(), m_M_Product_ID, get_TrxName());
|
count_ok++;
|
||||||
MPPProductBOMLine bomline = new MPPProductBOMLine(getCtx(), 0, get_TrxName());
|
}
|
||||||
int lowlevel = bomline.getLowLevel(m_M_Product_ID);
|
catch(Exception e) {
|
||||||
product.setLowLevel(lowlevel);
|
log.log(Level.SEVERE, e.getLocalizedMessage(), e);
|
||||||
product.save();
|
count_err++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
rs.close();
|
||||||
{
|
|
||||||
log.severe("Error: " + e.getLocalizedMessage() + sql);
|
|
||||||
return "@Error@";
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
log.severe("Error: " + e.getLocalizedMessage());
|
|
||||||
return "@Error@";
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null;
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return "OK";
|
return "@Ok@ #"+count_ok+" @Error@ #"+count_err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -514,7 +514,7 @@ public class MRP extends SvrProcess
|
||||||
//Find the BOM to this Product
|
//Find the BOM to this Product
|
||||||
if (m_product_planning.getPP_Product_BOM_ID() == 0 && product.isBOM())
|
if (m_product_planning.getPP_Product_BOM_ID() == 0 && product.isBOM())
|
||||||
{
|
{
|
||||||
m_product_planning.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(m_product_planning.getM_Product_ID()));
|
m_product_planning.setPP_Product_BOM_ID(MPPProductBOM.getBOMSearchKey(getCtx(), m_product_planning.getM_Product_ID()));
|
||||||
}
|
}
|
||||||
if (m_product_planning.getPlanner_ID() == 0 )
|
if (m_product_planning.getPlanner_ID() == 0 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,12 +18,9 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.eevolution.process;
|
package org.eevolution.process;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.model.X_M_Product;
|
import org.compiere.model.MProduct;
|
||||||
import org.compiere.process.ProcessInfoParameter;
|
import org.compiere.process.ProcessInfoParameter;
|
||||||
import org.compiere.process.SvrProcess;
|
import org.compiere.process.SvrProcess;
|
||||||
import org.compiere.util.AdempiereUserError;
|
import org.compiere.util.AdempiereUserError;
|
||||||
|
@ -39,7 +36,7 @@ import org.eevolution.model.MPPProductBOMLine;
|
||||||
* BOMs which are already referenced
|
* BOMs which are already referenced
|
||||||
*
|
*
|
||||||
* @author Tony Snook (tspc)
|
* @author Tony Snook (tspc)
|
||||||
*
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
*/
|
*/
|
||||||
public class PP_Product_BOM_Check extends SvrProcess
|
public class PP_Product_BOM_Check extends SvrProcess
|
||||||
{
|
{
|
||||||
|
@ -72,14 +69,10 @@ public class PP_Product_BOM_Check extends SvrProcess
|
||||||
*/
|
*/
|
||||||
protected String doIt() throws Exception
|
protected String doIt() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
int bomid = 0;
|
|
||||||
int lowlevel = 0;
|
|
||||||
|
|
||||||
log.info("Check BOM Structure");
|
log.info("Check BOM Structure");
|
||||||
|
|
||||||
// Record ID is M_Product_ID of product to be tested
|
// Record ID is M_Product_ID of product to be tested
|
||||||
X_M_Product xp = new X_M_Product(Env.getCtx(), p_Record_ID, get_TrxName());
|
MProduct xp = new MProduct(Env.getCtx(), p_Record_ID, get_TrxName());
|
||||||
|
|
||||||
if (!xp.isBOM())
|
if (!xp.isBOM())
|
||||||
{
|
{
|
||||||
|
@ -89,67 +82,28 @@ public class PP_Product_BOM_Check extends SvrProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check Parent Level
|
// Check Parent Level
|
||||||
MPPProductBOMLine bomline = new MPPProductBOMLine(getCtx(), 0, get_TrxName());
|
int lowlevel = MPPProductBOMLine.getLowLevel(getCtx(), p_Record_ID, get_TrxName());
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lowlevel = bomline.getLowLevel(p_Record_ID);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
raiseError("BOM Loop Error: ", e.getCause().getLocalizedMessage());
|
|
||||||
}
|
|
||||||
xp.setLowLevel(lowlevel);
|
xp.setLowLevel(lowlevel);
|
||||||
xp.setIsVerified(true);
|
xp.setIsVerified(true);
|
||||||
xp.save(get_TrxName());
|
xp.saveEx();
|
||||||
|
|
||||||
// Get BOM ID for default BOM (where BOM search key equals Product
|
// Get Default BOM from this product
|
||||||
// search key)
|
MPPProductBOM tbom = MPPProductBOM.getDefault(xp, get_TrxName());
|
||||||
String sql = new String("SELECT PP_Product_BOM_ID FROM PP_Product_BOM pb " + "LEFT JOIN M_Product p ON pb.M_Product_ID = p.M_Product_ID "
|
if (tbom == null) {
|
||||||
+ "WHERE pb.M_Product_ID = ? AND pb.value = p.value ");
|
raiseError("No Default BOM found: ", "Check BOM Parent search key");
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
pstmt = DB.prepareStatement(sql, get_TrxName());
|
|
||||||
pstmt.setInt(1, p_Record_ID);
|
|
||||||
rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
bomid = rs.getInt(1);
|
|
||||||
else
|
|
||||||
raiseError("No Default BOM found: ", "Check BOM Parent search key");
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.severe("Error getting BOM_ID for product: " + e + "\n" + sql);
|
|
||||||
return "@Error@";
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check All BOM Lines
|
// Check All BOM Lines
|
||||||
MPPProductBOM tbom = new MPPProductBOM(getCtx(), bomid, get_TrxName());
|
|
||||||
if (tbom.getM_Product_ID() != 0)
|
if (tbom.getM_Product_ID() != 0)
|
||||||
{
|
{
|
||||||
MPPProductBOMLine[] tbomlines = tbom.getLines();
|
MPPProductBOMLine[] tbomlines = tbom.getLines();
|
||||||
for (MPPProductBOMLine tbomline : tbomlines)
|
for (MPPProductBOMLine tbomline : tbomlines)
|
||||||
{
|
{
|
||||||
xp = new X_M_Product(Env.getCtx(), tbomline.getM_Product_ID(), get_TrxName());
|
lowlevel = tbomline.getLowLevel();
|
||||||
lowlevel = 0;
|
MProduct p = new MProduct(getCtx(), tbomline.getM_Product_ID(), get_TrxName());
|
||||||
try
|
p.setLowLevel(lowlevel);
|
||||||
{
|
p.setIsVerified(true);
|
||||||
lowlevel = bomline.getLowLevel(tbomline.getM_Product_ID());
|
p.saveEx();
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
raiseError("BOM Loop Error: ", e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
xp.setLowLevel(lowlevel);
|
|
||||||
xp.setIsVerified(true);
|
|
||||||
xp.save(get_TrxName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "OK";
|
return "OK";
|
||||||
|
@ -158,12 +112,13 @@ public class PP_Product_BOM_Check extends SvrProcess
|
||||||
private void raiseError(String string, String hint) throws Exception
|
private void raiseError(String string, String hint) throws Exception
|
||||||
{
|
{
|
||||||
DB.rollback(false, get_TrxName());
|
DB.rollback(false, get_TrxName());
|
||||||
X_M_Product xp = new X_M_Product(getCtx(), p_Record_ID, null); // parent
|
MProduct xp = new MProduct(getCtx(), p_Record_ID, null); // parent
|
||||||
xp.setIsVerified(false); // set BOM not verified
|
xp.setIsVerified(false); // set BOM not verified
|
||||||
xp.save();
|
xp.save();
|
||||||
String msg = string;
|
String msg = string;
|
||||||
ValueNamePair pp = CLogger.retrieveError();
|
ValueNamePair pp = CLogger.retrieveError();
|
||||||
if (pp != null) msg = pp.getName() + " - ";
|
if (pp != null)
|
||||||
|
msg = pp.getName() + " - ";
|
||||||
msg += hint;
|
msg += hint;
|
||||||
throw new AdempiereUserError(msg);
|
throw new AdempiereUserError(msg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue