* fixed some issues introduced in rev.6325
* use new Query API
* improved exception handling
This commit is contained in:
teo_sarca 2008-09-03 08:42:33 +00:00
parent 991c4a50c6
commit c8afc0d1e2
1 changed files with 49 additions and 135 deletions

View File

@ -18,7 +18,6 @@ package org.compiere.model;
import java.io.File; import java.io.File;
import java.math.BigDecimal; import java.math.BigDecimal;
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;
@ -27,6 +26,7 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.adempiere.exceptions.FillMandatoryException;
import org.compiere.print.ReportEngine; import org.compiere.print.ReportEngine;
import org.compiere.process.DocAction; import org.compiere.process.DocAction;
import org.compiere.process.DocumentEngine; import org.compiere.process.DocumentEngine;
@ -34,9 +34,8 @@ import org.compiere.util.DB;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Msg; import org.compiere.util.Msg;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.eevolution.model.MDDOrderLine;
import org.eevolution.model.MPPProductBOMLine;
import org.eevolution.model.MPPProductBOM; import org.eevolution.model.MPPProductBOM;
import org.eevolution.model.MPPProductBOMLine;
/** /**
@ -50,6 +49,8 @@ import org.eevolution.model.MPPProductBOM;
*/ */
public class MOrder extends X_C_Order implements DocAction public class MOrder extends X_C_Order implements DocAction
{ {
private static final long serialVersionUID = 1L;
/** /**
* Create new Order by copying * Create new Order by copying
* @param from order * @param from order
@ -609,16 +610,20 @@ public class MOrder extends X_C_Order implements DocAction
public MOrderLine[] getLines (String whereClause, String orderClause) public MOrderLine[] getLines (String whereClause, String orderClause)
{ {
//red1 - using new Query class from Teo / Victor's MDDOrder.java implementation //red1 - using new Query class from Teo / Victor's MDDOrder.java implementation
StringBuffer whereClauseFinal = new StringBuffer("C_Order_ID =?"); StringBuffer whereClauseFinal = new StringBuffer(MOrderLine.COLUMNNAME_C_Order_ID+"=?");
if (!Util.isEmpty(whereClause, true)) if (!Util.isEmpty(whereClause, true))
whereClauseFinal.append(whereClause); whereClauseFinal.append(whereClause);
if (orderClause.length() == 0) if (orderClause.length() == 0)
orderClause = "Line"; orderClause = MOrderLine.COLUMNNAME_Line;
// //
List<MOrderLine> list = new Query(getCtx(), MOrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName()) List<MOrderLine> list = new Query(getCtx(), MOrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName())
.setParameters(new Object[]{getC_Order_ID()}) .setParameters(new Object[]{get_ID()})
.setOrderBy(orderClause) .setOrderBy(orderClause)
.list(); .list();
for (MOrderLine ol : list) {
ol.setHeaderInfo(this);
}
//
return list.toArray(new MOrderLine[list.size()]); return list.toArray(new MOrderLine[list.size()]);
} // getLines } // getLines
@ -697,38 +702,10 @@ public class MOrder extends X_C_Order implements DocAction
if (m_taxes != null && !requery) if (m_taxes != null && !requery)
return m_taxes; return m_taxes;
// //
ArrayList<MOrderTax> list = new ArrayList<MOrderTax>(); List<MOrderTax> list = new Query(getCtx(), MOrderTax.Table_Name, "C_Order_ID=?", get_TrxName())
String sql = "SELECT * FROM C_OrderTax WHERE C_Order_ID=?"; .setParameters(new Object[]{get_ID()})
PreparedStatement pstmt = null; .list();
try m_taxes = list.toArray(new MOrderTax[list.size()]);
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Order_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MOrderTax(getCtx(), rs, get_TrxName()));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
log.log(Level.SEVERE, "getTaxes", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
//
m_taxes = new MOrderTax[list.size ()];
list.toArray (m_taxes);
return m_taxes; return m_taxes;
} // getTaxes } // getTaxes
@ -739,36 +716,15 @@ public class MOrder extends X_C_Order implements DocAction
*/ */
public MInvoice[] getInvoices() public MInvoice[] getInvoices()
{ {
ArrayList<MInvoice> list = new ArrayList<MInvoice>(); final String whereClause = "EXISTS (SELECT 1 FROM C_InvoiceLine il, C_OrderLine ol"
String sql = " SELECT DISTINCT i.* FROM C_InvoiceLine il " + +" WHERE il.C_Invoice_ID=C_Invoice.C_Invoice_ID"
"INNER JOIN C_OrderLine ol ON (ol.C_OrderLine_ID = il.C_OrderLine_ID) " + +" AND il.C_OrderLine_ID=ol.C_OrderLine_ID"
"INNER JOIN C_Order o ON (o.C_Order_ID = ol.C_Order_ID) " + +" AND ol.C_Order_ID=?)";
"INNER JOIN C_Invoice i ON (i.C_Invoice_ID = il.C_Invoice_ID) " + List<MInvoice> list = new Query(getCtx(), MInvoice.Table_Name, whereClause, get_TrxName())
"WHERE o.C_Order_ID=? " + .setParameters(new Object[]{get_ID()})
"ORDER BY i.Created DESC"; .setOrderBy("C_Invoice_ID DESC")
PreparedStatement pstmt = null; .list();
ResultSet rs = null; return list.toArray(new MInvoice[list.size()]);
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Order_ID());
rs = pstmt.executeQuery();
while (rs.next())
list.add(new MInvoice(getCtx(), rs, get_TrxName()));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
//
MInvoice[] retValue = new MInvoice[list.size()];
list.toArray(retValue);
return retValue;
} // getInvoices } // getInvoices
/** /**
@ -777,29 +733,10 @@ public class MOrder extends X_C_Order implements DocAction
*/ */
public int getC_Invoice_ID() public int getC_Invoice_ID()
{ {
int C_Invoice_ID = 0;
String sql = "SELECT C_Invoice_ID FROM C_Invoice " String sql = "SELECT C_Invoice_ID FROM C_Invoice "
+ "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') " + "WHERE C_Order_ID=? AND DocStatus IN ('CO','CL') "
+ "ORDER BY Created DESC"; + "ORDER BY C_Invoice_ID DESC";
PreparedStatement pstmt = null; int C_Invoice_ID = DB.getSQLValue(get_TrxName(), sql, get_ID());
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Order_ID());
rs = pstmt.executeQuery();
if (rs.next())
C_Invoice_ID = rs.getInt(1);
}
catch (Exception e)
{
log.log(Level.SEVERE, "getC_Invoice_ID", e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
return C_Invoice_ID; return C_Invoice_ID;
} // getC_Invoice_ID } // getC_Invoice_ID
@ -810,37 +747,15 @@ public class MOrder extends X_C_Order implements DocAction
*/ */
public MInOut[] getShipments() public MInOut[] getShipments()
{ {
ArrayList<MInOut> list = new ArrayList<MInOut>(); final String whereClause = "EXISTS (SELECT 1 FROM C_InOutLine iol, C_OrderLine ol"
String sql = "SELECT DISTINCT io.* FROM M_InOutLine iol " + +" WHERE iol.M_InOut_ID=M_InOut.M_InOut_ID"
"INNER JOIN M_InOut io ON (io.M_InOut_ID = iol.M_InOut_ID) " + +" AND iol.C_OrderLine_ID=ol.C_OrderLine_ID"
"INNER JOIN C_ORDERLINE ol ON (ol.C_ORDERLINE_ID=iol.C_ORDERLINE_ID) " + +" AND ol.C_Order_ID=?)";
"INNER JOIN C_ORDER o ON (o.C_ORDER_ID=ol.C_ORDER_ID) " + List<MInvoice> list = new Query(getCtx(), MInOut.Table_Name, whereClause, get_TrxName())
"WHERE o.C_ORDER_ID=? " + .setParameters(new Object[]{get_ID()})
"ORDER BY io.Created DESC"; .setOrderBy("M_InOut_ID DESC")
.list();
PreparedStatement pstmt = null; return list.toArray(new MInOut[list.size()]);
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Order_ID());
rs = pstmt.executeQuery();
while (rs.next())
list.add(new MInOut(getCtx(), rs, get_TrxName()));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
//
MInOut[] retValue = new MInOut[list.size()];
list.toArray(retValue);
return retValue;
} // getShipments } // getShipments
/** /**
@ -903,8 +818,8 @@ public class MOrder extends X_C_Order implements DocAction
String set = "SET Processed='" String set = "SET Processed='"
+ (processed ? "Y" : "N") + (processed ? "Y" : "N")
+ "' WHERE C_Order_ID=" + getC_Order_ID(); + "' WHERE C_Order_ID=" + getC_Order_ID();
int noLine = DB.executeUpdate("UPDATE C_OrderLine " + set, get_TrxName()); int noLine = DB.executeUpdateEx("UPDATE C_OrderLine " + set, get_TrxName());
int noTax = DB.executeUpdate("UPDATE C_OrderTax " + set, get_TrxName()); int noTax = DB.executeUpdateEx("UPDATE C_OrderTax " + set, get_TrxName());
m_lines = null; m_lines = null;
m_taxes = null; m_taxes = null;
log.fine("setProcessed - " + processed + " - Lines=" + noLine + ", Tax=" + noTax); log.fine("setProcessed - " + processed + " - Lines=" + noLine + ", Tax=" + noTax);
@ -947,8 +862,7 @@ public class MOrder extends X_C_Order implements DocAction
setM_Warehouse_ID(ii); setM_Warehouse_ID(ii);
else else
{ {
log.saveError("FillMandatory", Msg.getElement(getCtx(), "M_Warehouse_ID")); throw new FillMandatoryException(COLUMNNAME_M_Warehouse_ID);
return false;
} }
} }
// Warehouse Org // Warehouse Org
@ -1055,7 +969,7 @@ public class MOrder extends X_C_Order implements DocAction
+ "(SELECT Description,POReference " + "(SELECT Description,POReference "
+ "FROM C_Order o WHERE i.C_Order_ID=o.C_Order_ID) " + "FROM C_Order o WHERE i.C_Order_ID=o.C_Order_ID) "
+ "WHERE DocStatus NOT IN ('RE','CL') AND C_Order_ID=" + getC_Order_ID(); + "WHERE DocStatus NOT IN ('RE','CL') AND C_Order_ID=" + getC_Order_ID();
int no = DB.executeUpdate(sql, get_TrxName()); int no = DB.executeUpdateEx(sql, get_TrxName());
log.fine("Description -> #" + no); log.fine("Description -> #" + no);
} }
@ -1166,7 +1080,7 @@ public class MOrder extends X_C_Order implements DocAction
} }
// Lines // Lines
MOrderLine[] lines = getLines(true, "M_Product_ID"); MOrderLine[] lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
if (lines.length == 0) if (lines.length == 0)
{ {
m_processMsg = "@NoLines@"; m_processMsg = "@NoLines@";
@ -1248,7 +1162,7 @@ public class MOrder extends X_C_Order implements DocAction
// Lines // Lines
if (explodeBOM()) if (explodeBOM())
lines = getLines(true, "M_Product_ID"); lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
if (!reserveStock(dt, lines)) if (!reserveStock(dt, lines))
{ {
m_processMsg = "Cannot reserve Stock"; m_processMsg = "Cannot reserve Stock";
@ -1320,7 +1234,7 @@ public class MOrder extends X_C_Order implements DocAction
renumberLines (1000); // max 999 bom items renumberLines (1000); // max 999 bom items
// Order Lines with non-stocked BOMs // Order Lines with non-stocked BOMs
MOrderLine[] lines = getLines (where, " Line"); MOrderLine[] lines = getLines (where, MOrderLine.COLUMNNAME_Line);
for (int i = 0; i < lines.length; i++) for (int i = 0; i < lines.length; i++)
{ {
MOrderLine line = lines[i]; MOrderLine line = lines[i];
@ -1525,7 +1439,7 @@ public class MOrder extends X_C_Order implements DocAction
{ {
log.fine(""); log.fine("");
// Delete Taxes // Delete Taxes
DB.executeUpdate("DELETE C_OrderTax WHERE C_Order_ID=" + getC_Order_ID(), get_TrxName()); DB.executeUpdateEx("DELETE C_OrderTax WHERE C_Order_ID=" + getC_Order_ID(), get_TrxName());
m_taxes = null; m_taxes = null;
// Lines // Lines
@ -1641,7 +1555,7 @@ public class MOrder extends X_C_Order implements DocAction
{ {
// Binding // Binding
if (MDocType.DOCSUBTYPESO_Quotation.equals(DocSubTypeSO)) if (MDocType.DOCSUBTYPESO_Quotation.equals(DocSubTypeSO))
reserveStock(dt, getLines(true, "M_Product_ID")); reserveStock(dt, getLines(true, MOrderLine.COLUMNNAME_M_Product_ID));
m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE); m_processMsg = ModelValidationEngine.get().fireDocValidate(this, ModelValidator.TIMING_BEFORE_COMPLETE);
if (m_processMsg != null) if (m_processMsg != null)
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
@ -1994,7 +1908,7 @@ public class MOrder extends X_C_Order implements DocAction
if (m_processMsg != null) if (m_processMsg != null)
return false; return false;
MOrderLine[] lines = getLines(true, "M_Product_ID"); MOrderLine[] lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
for (int i = 0; i < lines.length; i++) for (int i = 0; i < lines.length; i++)
{ {
MOrderLine line = lines[i]; MOrderLine line = lines[i];
@ -2149,7 +2063,7 @@ public class MOrder extends X_C_Order implements DocAction
return false; return false;
// Close Not delivered Qty - SO/PO // Close Not delivered Qty - SO/PO
MOrderLine[] lines = getLines(true, "M_Product_ID"); MOrderLine[] lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
for (int i = 0; i < lines.length; i++) for (int i = 0; i < lines.length; i++)
{ {
MOrderLine line = lines[i]; MOrderLine line = lines[i];
@ -2192,7 +2106,7 @@ public class MOrder extends X_C_Order implements DocAction
} }
// //
MOrderLine[] lines = getLines(true, "M_Product_ID"); MOrderLine[] lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
for (int i = 0; i < lines.length; i++) for (int i = 0; i < lines.length; i++)
{ {
MOrderLine line = lines[i]; MOrderLine line = lines[i];