BF2033057 Error during test of Multi Level BOM & Formula Detail
This commit is contained in:
parent
daaca91362
commit
4cbb4cc005
|
@ -22,6 +22,8 @@ import java.sql.SQLException;
|
|||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import javax.sql.RowSet;
|
||||
|
||||
import org.compiere.model.MQuery;
|
||||
import org.compiere.model.PrintInfo;
|
||||
import org.compiere.print.MPrintFormat;
|
||||
|
@ -29,110 +31,133 @@ import org.compiere.print.ReportCtl;
|
|||
import org.compiere.print.ReportEngine;
|
||||
import org.compiere.process.ProcessInfoParameter;
|
||||
import org.compiere.process.SvrProcess;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.DB;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Language;
|
||||
import org.compiere.util.ValueNamePair;
|
||||
import org.eevolution.model.X_RV_PP_Product_BOMLine;
|
||||
import org.eevolution.model.X_T_BOMLine;
|
||||
|
||||
/**
|
||||
* BOM lines explosion for print
|
||||
*
|
||||
* @author victor.perez@e-evolution.com,Sergio Ramazzina
|
||||
* @version $Id: PrintBOM.java,v 1.2 2005/04/19 12:54:30 srama Exp $
|
||||
* Multi-Level BOM & Formula Detail
|
||||
*
|
||||
* @author victor.perez@e-evolution.com,Sergio Ramazzina
|
||||
* @version $Id: PrintBOM.java,v 1.2 2005/04/19 12:54:30 srama Exp $
|
||||
*
|
||||
*/
|
||||
public class PrintBOM extends SvrProcess {
|
||||
|
||||
public class PrintBOM extends SvrProcess
|
||||
{
|
||||
private static final Properties ctx = Env.getCtx();
|
||||
|
||||
private int p_M_Product_ID = 0;
|
||||
|
||||
private boolean p_implosion = false;
|
||||
|
||||
private int LevelNo = 1;
|
||||
|
||||
private int SeqNo = 0;
|
||||
|
||||
private String levels = new String("....................");
|
||||
|
||||
private int AD_PInstance_ID = 0;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
* Prepare - e.g., get Parameters.
|
||||
*/
|
||||
protected void prepare() {
|
||||
protected void prepare()
|
||||
{
|
||||
ProcessInfoParameter[] para = getParameter();
|
||||
|
||||
for (int i = 0; i < para.length; i++) {
|
||||
for (int i = 0; i < para.length; i++)
|
||||
{
|
||||
String name = para[i].getParameterName();
|
||||
|
||||
if (para[i].getParameter() == null)
|
||||
;
|
||||
else if (name.equals("M_Product_ID")) {
|
||||
p_M_Product_ID = ((BigDecimal) para[i].getParameter())
|
||||
.intValue();
|
||||
|
||||
} else if (name.equals("Implosion")) {
|
||||
p_implosion = ((String) para[i].getParameter()).equals("N") ? false
|
||||
: true;
|
||||
else if (name.equals("M_Product_ID"))
|
||||
{
|
||||
p_M_Product_ID = ((BigDecimal) para[i].getParameter()).intValue();
|
||||
}
|
||||
else if (name.equals("Implosion"))
|
||||
{
|
||||
p_implosion = ((String) para[i].getParameter()).equals("N") ? false : true;
|
||||
}
|
||||
|
||||
else
|
||||
log.log(Level.SEVERE, "prepare - Unknown Parameter: " + name);
|
||||
}
|
||||
} // prepare
|
||||
} // prepare
|
||||
|
||||
/**
|
||||
* Perform process.
|
||||
* @return Message (clear text)
|
||||
* @throws Exception if not successful
|
||||
* Perform process.
|
||||
*
|
||||
* @return Message (clear text)
|
||||
* @throws Exception
|
||||
* if not successful
|
||||
*/
|
||||
protected String doIt() throws Exception {
|
||||
|
||||
protected String doIt() throws Exception
|
||||
{
|
||||
AD_PInstance_ID = getAD_PInstance_ID();
|
||||
|
||||
loadBOM();
|
||||
try
|
||||
{
|
||||
loadBOM();
|
||||
print();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.log(Level.SEVERE, "PrintBOM", e.toString());
|
||||
throw new Exception(e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
String sql = "DELETE FROM T_BomLine WHERE AD_PInstance_ID = " + AD_PInstance_ID;
|
||||
DB.executeUpdate(sql, null);
|
||||
}
|
||||
|
||||
print();
|
||||
|
||||
return "@ProcessOK@";
|
||||
} // doIt
|
||||
return "@OK@";
|
||||
} // doIt
|
||||
|
||||
/**
|
||||
* Print result generate for this report
|
||||
*/
|
||||
void print() {
|
||||
Language language = Language.getLoginLanguage(); // Base Language
|
||||
//try current client first, then system
|
||||
int pfid = MPrintFormat.getPrintFormat_ID("Multi Level BOM & Formula Detail",
|
||||
X_RV_PP_Product_BOMLine.Table_ID, getAD_Client_ID());
|
||||
if (pfid < 0)
|
||||
pfid = MPrintFormat.getPrintFormat_ID("Multi Level BOM & Formula Detail",
|
||||
X_RV_PP_Product_BOMLine.Table_ID, 0);
|
||||
|
||||
MPrintFormat pf = MPrintFormat.get(getCtx(), pfid, false);
|
||||
void print() throws Exception
|
||||
{
|
||||
Language language = Language.getLoginLanguage(); // Base Language
|
||||
MPrintFormat pf = null;
|
||||
int pfid = 0;
|
||||
|
||||
// get print format for client, else copy system to client
|
||||
RowSet pfrs = MPrintFormat.getAccessiblePrintFormats(X_RV_PP_Product_BOMLine.Table_ID, -1, null);
|
||||
pfrs.next();
|
||||
pfid = pfrs.getInt("AD_PrintFormat_ID");
|
||||
|
||||
if(pfrs.getInt("AD_Client_ID") != 0) pf = MPrintFormat.get(getCtx(), pfid, false);
|
||||
else pf = MPrintFormat.copyToClient(getCtx(), pfid, getAD_Client_ID());
|
||||
pfrs.close();
|
||||
|
||||
if (pf == null) raiseError("Error: ","No Print Format");
|
||||
|
||||
pf.setLanguage(language);
|
||||
pf.setTranslationLanguage(language);
|
||||
// query
|
||||
MQuery query = MQuery.get(getCtx(), AD_PInstance_ID, "RV_PP_Product_BOMLine");
|
||||
// query
|
||||
MQuery query = MQuery.get(getCtx(), AD_PInstance_ID, X_RV_PP_Product_BOMLine.Table_Name);
|
||||
query.addRestriction("AD_PInstance_ID", MQuery.EQUAL, AD_PInstance_ID);
|
||||
// Engine
|
||||
PrintInfo info = new PrintInfo("RV_PP_Product_BOMLine", X_RV_PP_Product_BOMLine.Table_ID, getRecord_ID());
|
||||
ReportEngine re = new ReportEngine(getCtx(), pf, query, info);
|
||||
|
||||
ReportCtl.preview(re);
|
||||
|
||||
String sql = "DELETE FROM T_BomLine WHERE AD_PInstance_ID = " + AD_PInstance_ID;
|
||||
DB.executeUpdate(sql, get_TrxName());
|
||||
PrintInfo info = new PrintInfo(X_RV_PP_Product_BOMLine.Table_Name,
|
||||
X_RV_PP_Product_BOMLine.Table_ID, getRecord_ID());
|
||||
ReportEngine re = new ReportEngine(getCtx(), pf, query, info);
|
||||
|
||||
ReportCtl.preview(re);
|
||||
// wait for report window to be closed as t_bomline
|
||||
// records are deleted when process ends
|
||||
while (re.getView().isDisplayable())
|
||||
{
|
||||
Env.sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action: Fill Tree with all nodes
|
||||
* Action: Fill Tree with all nodes
|
||||
*/
|
||||
private void loadBOM() {
|
||||
|
||||
if (p_M_Product_ID == 0)
|
||||
return;
|
||||
private void loadBOM() throws Exception
|
||||
{
|
||||
int count = 0;
|
||||
if (p_M_Product_ID == 0)
|
||||
raiseError("Error: ","Product ID not found");
|
||||
|
||||
X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
|
||||
tboml.setPP_Product_BOM_ID(0);
|
||||
|
@ -146,61 +171,93 @@ public class PrintBOM extends SvrProcess {
|
|||
tboml.setAD_PInstance_ID(AD_PInstance_ID);
|
||||
tboml.save();
|
||||
|
||||
if (p_implosion) {
|
||||
if (p_implosion)
|
||||
{
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOMLine_ID FROM PP_Product_BOMLine WHERE IsActive = 'Y' AND M_Product_ID = ? ");
|
||||
try {
|
||||
String sql = "SELECT PP_Product_BOMLine_ID FROM PP_Product_BOMLine "
|
||||
+ "WHERE IsActive = 'Y' AND M_Product_ID = ? ";
|
||||
try
|
||||
{
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
stmt.setInt(1, p_M_Product_ID);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next())
|
||||
{
|
||||
parentImplotion(rs.getInt(1));
|
||||
++count;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
|
||||
if (count == 0)
|
||||
raiseError("Error: ","Product is not a component");
|
||||
}
|
||||
|
||||
} else {
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOM_ID FROM PP_Product_BOM WHERE IsActive = 'Y' AND M_Product_ID = ? ");
|
||||
try {
|
||||
String sql = "SELECT PP_Product_BOM_ID FROM PP_Product_BOM "
|
||||
+ "WHERE IsActive = 'Y' AND M_Product_ID = ? ";
|
||||
try
|
||||
{
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
stmt.setInt(1, p_M_Product_ID);
|
||||
rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
while (rs.next())
|
||||
{
|
||||
parentExplotion(rs.getInt(1));
|
||||
++count;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
|
||||
if (count == 0)
|
||||
raiseError("Error: ","Product is not a BOM");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an Implotion for this BOM Line
|
||||
* @param PP_Product_BOMLine_ID ID BOM Line
|
||||
*
|
||||
* @param PP_Product_BOMLine_ID
|
||||
* ID BOM Line
|
||||
*/
|
||||
public void parentImplotion(int PP_Product_BOMLine_ID) {
|
||||
|
||||
public void parentImplotion(int PP_Product_BOMLine_ID) throws Exception
|
||||
{
|
||||
int PP_Product_BOM_ID = 0;
|
||||
int M_Product_ID = 0;
|
||||
|
||||
X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
|
||||
int PP_Product_BOM_ID = DB
|
||||
.getSQLValue(
|
||||
null,
|
||||
"SELECT PP_Product_BOM_ID FROM PP_Product_BOMLine WHERE PP_Product_BOMLine_ID=?",
|
||||
PP_Product_BOMLine_ID);
|
||||
int M_Product_ID = DB
|
||||
.getSQLValue(
|
||||
null,
|
||||
"SELECT M_Product_ID FROM PP_Product_BOM WHERE PP_Product_BOM_ID=?",
|
||||
PP_Product_BOM_ID);
|
||||
|
||||
PP_Product_BOM_ID = DB.getSQLValue(null,
|
||||
"SELECT PP_Product_BOM_ID FROM PP_Product_BOMLine WHERE PP_Product_BOMLine_ID=?",PP_Product_BOMLine_ID);
|
||||
if (PP_Product_BOM_ID < 0)
|
||||
throw new Exception(CLogger.retrieveErrorString("Error: PrintBOM.parentImplotion()"));
|
||||
M_Product_ID = DB.getSQLValue(null,
|
||||
"SELECT M_Product_ID FROM PP_Product_BOM WHERE PP_Product_BOM_ID=?", PP_Product_BOM_ID);
|
||||
if (M_Product_ID < 0)
|
||||
throw new Exception(CLogger.retrieveErrorString("Error: PrintBOM.parentImplotion()"));
|
||||
|
||||
tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
|
||||
tboml.setPP_Product_BOMLine_ID(PP_Product_BOMLine_ID);
|
||||
tboml.setM_Product_ID(M_Product_ID);
|
||||
|
@ -210,8 +267,7 @@ public class PrintBOM extends SvrProcess {
|
|||
|
||||
if (LevelNo >= 11)
|
||||
tboml.setLevels(levels + ">" + LevelNo);
|
||||
else if (LevelNo >= 1)
|
||||
tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
|
||||
else if (LevelNo >= 1) tboml.setLevels(levels.substring(0, LevelNo) + LevelNo);
|
||||
|
||||
tboml.setSeqNo(SeqNo);
|
||||
tboml.setAD_PInstance_ID(AD_PInstance_ID);
|
||||
|
@ -219,41 +275,52 @@ public class PrintBOM extends SvrProcess {
|
|||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOM_ID, M_Product_ID FROM PP_Product_BOM WHERE IsActive = 'Y' AND M_Product_ID = ? ");
|
||||
try {
|
||||
String sql = "SELECT PP_Product_BOM_ID, M_Product_ID FROM PP_Product_BOM "
|
||||
+ "WHERE IsActive = 'Y' AND M_Product_ID = ? ";
|
||||
try
|
||||
{
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
stmt.setInt(1, M_Product_ID);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
while (rs.next())
|
||||
{
|
||||
SeqNo += 1;
|
||||
component(rs.getInt(2));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an Explotion for this BOM
|
||||
* @param PP_Product_BOMLine_ID ID BOM Line
|
||||
*
|
||||
* @param PP_Product_BOMLine_ID
|
||||
* ID BOM Line
|
||||
*/
|
||||
public void parentExplotion(int PP_Product_BOM_ID) {
|
||||
public void parentExplotion(int PP_Product_BOM_ID) throws Exception
|
||||
{
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOMLine_ID, M_Product_ID FROM PP_Product_BOMLine boml "
|
||||
+ "WHERE IsActive = 'Y' AND PP_Product_BOM_ID = ? ORDER BY Line ");
|
||||
try {
|
||||
String sql = "SELECT PP_Product_BOMLine_ID, M_Product_ID FROM PP_Product_BOMLine boml "
|
||||
+ "WHERE IsActive = 'Y' AND PP_Product_BOM_ID = ? ORDER BY Line ";
|
||||
try
|
||||
{
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
stmt.setInt(1, PP_Product_BOM_ID);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
while (rs.next())
|
||||
{
|
||||
SeqNo += 1;
|
||||
X_T_BOMLine tboml = new X_T_BOMLine(ctx, 0, null);
|
||||
tboml.setPP_Product_BOM_ID(PP_Product_BOM_ID);
|
||||
|
@ -268,75 +335,109 @@ public class PrintBOM extends SvrProcess {
|
|||
tboml.save();
|
||||
component(rs.getInt(2));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
}
|
||||
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if this product as component
|
||||
* @param M_Product_ID ID Component
|
||||
*
|
||||
* @param M_Product_ID
|
||||
* ID Component
|
||||
*/
|
||||
public void component(int M_Product_ID) {
|
||||
|
||||
if (p_implosion) {
|
||||
|
||||
public void component(int M_Product_ID) throws Exception
|
||||
{
|
||||
if (p_implosion)
|
||||
{
|
||||
LevelNo += 1;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOMLine_ID FROM PP_Product_BOMLine WHERE IsActive = 'Y' AND M_Product_ID = ? ");
|
||||
try {
|
||||
String sql = "SELECT PP_Product_BOMLine_ID FROM PP_Product_BOMLine "
|
||||
+ "WHERE IsActive = 'Y' AND M_Product_ID = ? ";
|
||||
try
|
||||
{
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
stmt.setInt(1, M_Product_ID);
|
||||
rs = stmt.executeQuery();
|
||||
boolean level = false;
|
||||
while (rs.next()) {
|
||||
while (rs.next())
|
||||
{
|
||||
parentImplotion(rs.getInt(1));
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
LevelNo -= 1;
|
||||
return;
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
String sql = "SELECT PP_Product_BOM_ID FROM PP_Product_BOM "
|
||||
+ "WHERE IsActive = 'Y' AND Value = ? ";
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
String sql = new String(
|
||||
"SELECT PP_Product_BOM_ID FROM PP_Product_BOM WHERE IsActive = 'Y' AND Value = ? ");
|
||||
try {
|
||||
try
|
||||
{
|
||||
String Value = DB.getSQLValueString(get_TrxName(),
|
||||
"SELECT Value FROM M_PRODUCT WHERE M_PRODUCT_ID=?", M_Product_ID);
|
||||
if (Value == null)
|
||||
{
|
||||
throw new Exception(CLogger.retrieveErrorString("Error: PrintBOM.component()"));
|
||||
}
|
||||
stmt = DB.prepareStatement(sql, get_TrxName());
|
||||
String Value = DB.getSQLValueString(null,
|
||||
"SELECT Value FROM M_PRODUCT WHERE M_PRODUCT_ID=?",
|
||||
M_Product_ID);
|
||||
stmt.setString(1, Value);
|
||||
rs = stmt.executeQuery();
|
||||
boolean level = false;
|
||||
while (rs.next()) {
|
||||
if (!level)
|
||||
LevelNo += 1;
|
||||
|
||||
while (rs.next())
|
||||
{
|
||||
if (!level) LevelNo += 1;
|
||||
level = true;
|
||||
parentExplotion(rs.getInt(1));
|
||||
LevelNo -= 1;
|
||||
}
|
||||
rs.close();
|
||||
stmt.close();
|
||||
return;
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.log(Level.SEVERE, "explodeBOM ", e);
|
||||
|
||||
}
|
||||
|
||||
catch (SQLException e)
|
||||
{
|
||||
log.log(Level.SEVERE, e.getLocalizedMessage() + sql, e);
|
||||
throw new Exception("SQLException: "+e.getLocalizedMessage());
|
||||
}
|
||||
finally
|
||||
{
|
||||
DB.close(rs, stmt);
|
||||
rs = null;
|
||||
stmt = null;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private void raiseError(String string, String hint) throws Exception
|
||||
{
|
||||
String msg = string;
|
||||
ValueNamePair pp = CLogger.retrieveError();
|
||||
if (pp != null) msg = pp.getName() + " - ";
|
||||
msg += hint;
|
||||
throw new Exception(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue