MPPProductBOM:

* organized imports
* fixed indentation
This commit is contained in:
teo_sarca 2008-08-08 10:44:28 +00:00
parent ed095deea5
commit 0544b26115
1 changed files with 192 additions and 185 deletions

View File

@ -16,12 +16,19 @@
//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.util.*; import org.compiere.model.MProduct;
import org.compiere.model.*; import org.compiere.model.PO;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Order Model. * Order Model.
@ -36,7 +43,7 @@ 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
@ -150,42 +157,42 @@ public class MPPProductBOM extends X_PP_Product_BOM
/*************************************************************************/ /*************************************************************************/
/** /**
* BUG #104 * BUG #104
* @param lines * @param lines
*/ */
List lines = null; List lines = null;
public void setLines(List lines) { public void setLines(List lines) {
this.lines = lines; this.lines = lines;
} }
/** /**
* BUG #? - Does not persist objects! * BUG #? - Does not persist objects!
* @param ctx * @param ctx
* @param from * @param from
* @param copyLines * @param copyLines
* @return * @return
*/ */
public static MPPProductBOM copyFrom(Properties ctx, MPPProductBOM from, boolean copyLines) { public static MPPProductBOM copyFrom(Properties ctx, MPPProductBOM from, boolean copyLines) {
MPPProductBOM newBom = new MPPProductBOM(ctx, 0,null); MPPProductBOM newBom = new MPPProductBOM(ctx, 0,null);
PO.copyValues(from, newBom, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx)); PO.copyValues(from, newBom, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
newBom.setDocumentNo(null); newBom.setDocumentNo(null);
if (copyLines) { if (copyLines) {
List newLines = new ArrayList(); List newLines = new ArrayList();
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);
PO.copyValues(fromLines[i], line, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx)); PO.copyValues(fromLines[i], line, Env.getAD_Client_ID(ctx), Env.getAD_Org_ID(ctx));
newLines.add(line); newLines.add(line);
} }
newBom.setLines(newLines); newBom.setLines(newLines);
} }
return newBom; 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
@ -327,56 +334,56 @@ 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
@ -385,47 +392,47 @@ public class MPPProductBOM extends X_PP_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
@ -483,18 +490,18 @@ 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);
@ -526,7 +533,7 @@ public class MPPProductBOM extends X_PP_Product_BOM
pstmt = null; pstmt = null;
} }
return 0; return 0;
} }
} // MPP_ProductBOM } // MPP_ProductBOM