parent
ed095deea5
commit
0544b26115
|
@ -16,13 +16,20 @@
|
||||||
//package org.compiere.mfg.model;
|
//package org.compiere.mfg.model;
|
||||||
package org.eevolution.model;
|
package org.eevolution.model;
|
||||||
|
|
||||||
import java.util.*;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.*;
|
import java.sql.ResultSet;
|
||||||
import java.util.logging.*;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import org.compiere.model.MProduct;
|
||||||
|
import org.compiere.model.PO;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
import org.compiere.util.*;
|
|
||||||
import org.compiere.model.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Model.
|
* Order Model.
|
||||||
* Please do not set DocStatus and C_DocType_ID directly.
|
* Please do not set DocStatus and C_DocType_ID directly.
|
||||||
|
@ -34,10 +41,10 @@ import org.compiere.model.*;
|
||||||
*/
|
*/
|
||||||
public class MPPProductBOM extends X_PP_Product_BOM
|
public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private static CLogger log = CLogger.getCLogger(MPPProductBOM.class);
|
private static CLogger log = CLogger.getCLogger(MPPProductBOM.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -89,7 +96,7 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
}
|
}
|
||||||
} // MOrder
|
} // MOrder
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load Constructor
|
* Load Constructor
|
||||||
* @param ctx context
|
* @param ctx context
|
||||||
|
@ -99,10 +106,10 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
{
|
{
|
||||||
super (ctx, rs,trxName);
|
super (ctx, rs,trxName);
|
||||||
} // MOrder
|
} // MOrder
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overwrite Client/Org if required
|
* Overwrite Client/Org if required
|
||||||
|
@ -149,43 +156,43 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
} // copyLinesFrom
|
} // copyLinesFrom
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
/**
|
|
||||||
* BUG #104
|
|
||||||
* @param lines
|
|
||||||
*/
|
|
||||||
|
|
||||||
List lines = null;
|
|
||||||
|
|
||||||
public void setLines(List lines) {
|
|
||||||
this.lines = lines;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BUG #? - Does not persist objects!
|
* BUG #104
|
||||||
* @param ctx
|
* @param lines
|
||||||
* @param from
|
*/
|
||||||
* @param copyLines
|
|
||||||
* @return
|
List lines = null;
|
||||||
*/
|
|
||||||
public static MPPProductBOM copyFrom(Properties ctx, MPPProductBOM from, boolean copyLines) {
|
public void setLines(List lines) {
|
||||||
MPPProductBOM newBom = new MPPProductBOM(ctx, 0,null);
|
this.lines = lines;
|
||||||
PO.copyValues(from, newBom, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
|
}
|
||||||
newBom.setDocumentNo(null);
|
|
||||||
|
/**
|
||||||
if (copyLines) {
|
* BUG #? - Does not persist objects!
|
||||||
List newLines = new ArrayList();
|
* @param ctx
|
||||||
MPPProductBOMLine[] fromLines = from.getLines();
|
* @param from
|
||||||
for (int i = 0; i < fromLines.length; i++) {
|
* @param copyLines
|
||||||
MPPProductBOMLine line = new MPPProductBOMLine(ctx, 0,null);
|
* @return
|
||||||
PO.copyValues(fromLines[i], line, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
|
*/
|
||||||
newLines.add(line);
|
public static MPPProductBOM copyFrom(Properties ctx, MPPProductBOM from, boolean copyLines) {
|
||||||
}
|
MPPProductBOM newBom = new MPPProductBOM(ctx, 0,null);
|
||||||
newBom.setLines(newLines);
|
PO.copyValues(from, newBom, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
|
||||||
}
|
newBom.setDocumentNo(null);
|
||||||
|
|
||||||
return newBom;
|
if (copyLines) {
|
||||||
}
|
List newLines = new ArrayList();
|
||||||
|
MPPProductBOMLine[] fromLines = from.getLines();
|
||||||
|
for (int i = 0; i < fromLines.length; i++) {
|
||||||
|
MPPProductBOMLine line = new MPPProductBOMLine(ctx, 0,null);
|
||||||
|
PO.copyValues(fromLines[i], line, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
|
||||||
|
newLines.add(line);
|
||||||
|
}
|
||||||
|
newBom.setLines(newLines);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newBom;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String Representation
|
* String Representation
|
||||||
|
@ -194,8 +201,8 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
public String toString ()
|
public String toString ()
|
||||||
{
|
{
|
||||||
StringBuffer sb = new StringBuffer ("MPP_ProductBOM[")
|
StringBuffer sb = new StringBuffer ("MPP_ProductBOM[")
|
||||||
.append(get_ID()).append("-").append(getDocumentNo())
|
.append(get_ID()).append("-").append(getDocumentNo())
|
||||||
.append ("]");
|
.append ("]");
|
||||||
return sb.toString ();
|
return sb.toString ();
|
||||||
} // toString
|
} // toString
|
||||||
|
|
||||||
|
@ -209,21 +216,21 @@ public class MPPProductBOM extends X_PP_Product_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
|
||||||
|
@ -231,12 +238,12 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
int m_PP_Product_BOM_ID = DB.getSQLValue(trxName, sql, product.getM_Product_ID(), product.getValue());
|
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());
|
bom = new MPPProductBOM(product.getCtx(), m_PP_Product_BOM_ID ,product.get_TableName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return bom;
|
return bom;
|
||||||
|
|
||||||
} // getBOM
|
} // getBOM
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BOM with valid dates for Product
|
* Get BOM with valid dates for Product
|
||||||
* @param product product
|
* @param product product
|
||||||
|
@ -247,21 +254,21 @@ public class MPPProductBOM extends X_PP_Product_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 = 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
|
||||||
|
@ -269,22 +276,22 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
int m_PP_Product_BOM_ID = DB.getSQLValue(trxName, sql, product.getM_Product_ID(), product.getValue());
|
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());
|
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;
|
||||||
|
@ -292,12 +299,12 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
} // getBOM
|
} // getBOM
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get BOM lines
|
* Get BOM lines
|
||||||
* @return Array of BOM Lines
|
* @return Array of BOM Lines
|
||||||
|
@ -306,8 +313,8 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
{
|
{
|
||||||
return getLines (getPP_Product_BOM_ID());
|
return getLines (getPP_Product_BOM_ID());
|
||||||
} // getLines
|
} // getLines
|
||||||
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
* Get BOM lines
|
* Get BOM lines
|
||||||
* @param valid date to validate
|
* @param valid date to validate
|
||||||
|
@ -326,108 +333,108 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
*/
|
*/
|
||||||
public MPPProductBOMLine[] getLines (int pp_product_bom_id , Timestamp valid)
|
public MPPProductBOMLine[] getLines (int pp_product_bom_id , Timestamp valid)
|
||||||
{
|
{
|
||||||
|
|
||||||
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
||||||
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
pstmt.setInt(1, pp_product_bom_id);
|
pstmt.setInt(1, pp_product_bom_id);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
ResultSet rs = pstmt.executeQuery();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
||||||
boolean ValidFromBOMLine = true;
|
boolean ValidFromBOMLine = true;
|
||||||
boolean ValidToBOMLine = true;
|
boolean ValidToBOMLine = true;
|
||||||
if (bl.getValidFrom() != null)
|
if (bl.getValidFrom() != null)
|
||||||
{
|
{
|
||||||
ValidFromBOMLine = valid.compareTo(bl.getValidFrom()) >= 0 ? true : false;
|
ValidFromBOMLine = valid.compareTo(bl.getValidFrom()) >= 0 ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bl.getValidTo() != null )
|
if (bl.getValidTo() != null )
|
||||||
{
|
{
|
||||||
ValidToBOMLine = valid.compareTo(bl.getValidTo()) <= 0 ? true : false;
|
ValidToBOMLine = valid.compareTo(bl.getValidTo()) <= 0 ? true : false;
|
||||||
}
|
}
|
||||||
if(ValidFromBOMLine && ValidToBOMLine)
|
if(ValidFromBOMLine && ValidToBOMLine)
|
||||||
{
|
{
|
||||||
list.add(bl);
|
list.add(bl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
log.log(Level.SEVERE, sql.toString(), e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
if (pstmt != null)
|
||||||
pstmt.close ();
|
pstmt.close ();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{}
|
{}
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
||||||
list.toArray (lines);
|
list.toArray (lines);
|
||||||
return lines;
|
return lines;
|
||||||
|
|
||||||
} // getLines
|
} // getLines
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get BOM Lines for Product BOM
|
* Get BOM Lines for Product BOM
|
||||||
* @param pp_product_bom_id BOM ID
|
* @param pp_product_bom_id BOM ID
|
||||||
* @return BOM Lines
|
* @return BOM Lines
|
||||||
*/
|
*/
|
||||||
public MPPProductBOMLine[] getLines (int PP_Product_BOM_ID)
|
public MPPProductBOMLine[] getLines (int PP_Product_BOM_ID)
|
||||||
{
|
{
|
||||||
|
|
||||||
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
ArrayList<MPPProductBOMLine> list = new ArrayList<MPPProductBOMLine> ();
|
||||||
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
StringBuffer sql = new StringBuffer("SELECT * FROM PP_Product_BOMLine WHERE PP_Product_BOM_ID=? ");
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
|
||||||
pstmt.setInt(1, PP_Product_BOM_ID);
|
pstmt.setInt(1, PP_Product_BOM_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
ResultSet rs = pstmt.executeQuery();
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
MPPProductBOMLine bl = new MPPProductBOMLine(getCtx(), rs, get_TrxName());
|
||||||
list.add(bl);
|
list.add(bl);
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql.toString(), e);
|
log.log(Level.SEVERE, sql.toString(), e);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pstmt != null)
|
if (pstmt != null)
|
||||||
pstmt.close ();
|
pstmt.close ();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{}
|
{}
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
MPPProductBOMLine[] lines = new MPPProductBOMLine[list.size ()];
|
||||||
list.toArray (lines);
|
list.toArray (lines);
|
||||||
return lines;
|
return lines;
|
||||||
|
|
||||||
|
} // getLines
|
||||||
|
|
||||||
|
|
||||||
} // getLines
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -482,19 +489,19 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
|
|
||||||
return to;
|
return to;
|
||||||
} // copyFrom
|
} // copyFrom
|
||||||
|
|
||||||
public static int getBOMSearchKey(int M_Product_ID)
|
public static int getBOMSearchKey(int M_Product_ID)
|
||||||
{
|
{
|
||||||
|
|
||||||
int PP_Product_BOM_ID = 0;
|
int PP_Product_BOM_ID = 0;
|
||||||
int AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
|
int AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
|
||||||
|
|
||||||
MProduct product = new MProduct(Env.getCtx(), M_Product_ID, "M_Product");
|
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 = ?";
|
String sql = "SELECT pb.PP_Product_BOM_ID FROM PP_Product_BOM pb WHERE pb.Value = ? AND pb.AD_Client_ID = ?";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
PreparedStatement pstmt = null;
|
PreparedStatement pstmt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql);
|
pstmt = DB.prepareStatement(sql);
|
||||||
|
@ -525,8 +532,8 @@ public class MPPProductBOM extends X_PP_Product_BOM
|
||||||
{
|
{
|
||||||
pstmt = null;
|
pstmt = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // MPP_ProductBOM
|
} // MPP_ProductBOM
|
||||||
|
|
Loading…
Reference in New Issue