intermediate posteritaPOS commit.

This commit is contained in:
trifonnt 2008-10-21 15:17:19 +00:00
parent 9e48aeb32d
commit 8ec68cbfa3
2 changed files with 217 additions and 211 deletions

View File

@ -776,7 +776,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
* Is Reversal * Is Reversal
* @return reversal * @return reversal
*/ */
private boolean isReversal() public boolean isReversal()
{ {
return m_reversal; return m_reversal;
} // isReversal } // isReversal
@ -1100,11 +1100,12 @@ public class MInvoice extends X_C_Invoice implements DocAction
+ "WHERE al.C_Invoice_ID=?" + "WHERE al.C_Invoice_ID=?"
+ " AND ah.IsActive='Y' AND al.IsActive='Y'"; + " AND ah.IsActive='Y' AND al.IsActive='Y'";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement(sql, get_TrxName()); pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, getC_Invoice_ID()); pstmt.setInt(1, getC_Invoice_ID());
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
if (rs.next()) if (rs.next())
retValue = rs.getBigDecimal(1); retValue = rs.getBigDecimal(1);
rs.close(); rs.close();
@ -1115,15 +1116,10 @@ public class MInvoice extends X_C_Invoice implements DocAction
{ {
log.log(Level.SEVERE, sql, e); log.log(Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close(); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
// log.fine("getAllocatedAmt - " + retValue); // log.fine("getAllocatedAmt - " + retValue);
// ? ROUND(NVL(v_AllocatedAmt,0), 2); // ? ROUND(NVL(v_AllocatedAmt,0), 2);
@ -1289,7 +1285,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
*/ */
public File createPDF (File file) public File createPDF (File file)
{ {
ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.INVOICE, getC_Invoice_ID()); ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.INVOICE, getC_Invoice_ID(), get_TrxName());
if (re == null) if (re == null)
return null; return null;
return re.getPDF(file); return re.getPDF(file);
@ -1478,7 +1474,30 @@ public class MInvoice extends X_C_Invoice implements DocAction
log.fine(product.getName()); log.fine(product.getName());
// New Lines // New Lines
int lineNo = line.getLine (); int lineNo = line.getLine ();
MProductBOM[] boms = MProductBOM.getBOMLines (product);
//find default BOM with valid dates and to this product
MPPProductBOM bom = MPPProductBOM.get(product, getAD_Org_ID(),getDateInvoiced(), get_TrxName());
if(bom != null)
{
MPPProductBOMLine[] bomlines = bom.getLines(getDateInvoiced());
for (int j = 0; j < bomlines.length; j++)
{
MPPProductBOMLine bomline = bomlines[j];
MInvoiceLine newLine = new MInvoiceLine (this);
newLine.setLine (++lineNo);
newLine.setM_Product_ID (bomline.getM_Product_ID ());
newLine.setC_UOM_ID (bomline.getC_UOM_ID ());
newLine.setQty (line.getQtyInvoiced().multiply(
bomline.getQtyBOM ())); // Invoiced/Entered
if (bomline.getDescription () != null)
newLine.setDescription (bomline.getDescription ());
//
newLine.setPrice ();
newLine.save (get_TrxName());
}
}
/*MProductBOM[] boms = MProductBOM.getBOMLines (product);
for (int j = 0; j < boms.length; j++) for (int j = 0; j < boms.length; j++)
{ {
MProductBOM bom = boms[j]; MProductBOM bom = boms[j];
@ -1493,7 +1512,8 @@ public class MInvoice extends X_C_Invoice implements DocAction
// //
newLine.setPrice (); newLine.setPrice ();
newLine.save (get_TrxName()); newLine.save (get_TrxName());
} }*/
// Convert into Comment Line // Convert into Comment Line
line.setM_Product_ID (0); line.setM_Product_ID (0);
line.setM_AttributeSetInstance_ID (0); line.setM_AttributeSetInstance_ID (0);
@ -1665,7 +1685,6 @@ public class MInvoice extends X_C_Invoice implements DocAction
log.info(toString()); log.info(toString());
StringBuffer info = new StringBuffer(); StringBuffer info = new StringBuffer();
//Modifications for cash payment
/* /*
// Create Cash // Create Cash
if (PAYMENTRULE_Cash.equals(getPaymentRule())) if (PAYMENTRULE_Cash.equals(getPaymentRule()))
@ -1768,7 +1787,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
MMatchInv inv = new MMatchInv(line, getDateInvoiced(), matchQty); MMatchInv inv = new MMatchInv(line, getDateInvoiced(), matchQty);
if (!inv.save(get_TrxName())) if (!inv.save(get_TrxName()))
{ {
m_processMsg = "Could not create Invoice Matching"; m_processMsg = CLogger.retrieveErrorString("Could not create Invoice Matching");
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
} }
else else
@ -1786,7 +1805,7 @@ public class MInvoice extends X_C_Invoice implements DocAction
MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName()); MBPartner bp = new MBPartner (getCtx(), getC_BPartner_ID(), get_TrxName());
// Update total revenue and balance / credit limit (reversed on AllocationLine.processIt) // Update total revenue and balance / credit limit (reversed on AllocationLine.processIt)
BigDecimal invAmt = MConversionRate.convertBase(getCtx(), getGrandTotal(true), // CM adjusted BigDecimal invAmt = MConversionRate.convertBase(getCtx(), getGrandTotal(true), // CM adjusted
getC_Currency_ID(), getDateAcct(), 0, getAD_Client_ID(), getAD_Org_ID()); getC_Currency_ID(), getDateAcct(), getC_ConversionType_ID(), getAD_Client_ID(), getAD_Org_ID());
if (invAmt == null) if (invAmt == null)
{ {
m_processMsg = "Could not convert C_Currency_ID=" + getC_Currency_ID() m_processMsg = "Could not convert C_Currency_ID=" + getC_Currency_ID()
@ -2177,6 +2196,8 @@ public class MInvoice extends X_C_Invoice implements DocAction
return false; return false;
} }
reversal.setC_Payment_ID(0); reversal.setC_Payment_ID(0);
//FR1948157
reversal.setReversal_ID(getC_Invoice_ID());
reversal.setIsPaid(true); reversal.setIsPaid(true);
reversal.closeIt(); reversal.closeIt();
reversal.setProcessing (false); reversal.setProcessing (false);
@ -2203,6 +2224,8 @@ public class MInvoice extends X_C_Invoice implements DocAction
} }
} }
setProcessed(true); setProcessed(true);
//FR1948157
setReversal_ID(reversal.getC_Invoice_ID());
setDocStatus(DOCSTATUS_Reversed); // may come from void setDocStatus(DOCSTATUS_Reversed); // may come from void
setDocAction(DOCACTION_None); setDocAction(DOCACTION_None);
setC_Payment_ID(0); setC_Payment_ID(0);

View File

@ -18,19 +18,24 @@ 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;
import java.util.List;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
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;
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; import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.eevolution.model.MPPProductBOM;
import org.eevolution.model.MPPProductBOMLine;
/** /**
* Order Model. * Order Model.
@ -43,6 +48,8 @@ import org.compiere.util.Msg;
*/ */
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
@ -571,7 +578,7 @@ public class MOrder extends X_C_Order implements DocAction
*/ */
public File createPDF (File file) public File createPDF (File file)
{ {
ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, getC_Order_ID()); ReportEngine re = ReportEngine.get (getCtx(), ReportEngine.ORDER, getC_Order_ID(), get_TrxName());
if (re == null) if (re == null)
return null; return null;
return re.getPDF(file); return re.getPDF(file);
@ -601,39 +608,22 @@ public class MOrder extends X_C_Order implements DocAction
*/ */
public MOrderLine[] getLines (String whereClause, String orderClause) public MOrderLine[] getLines (String whereClause, String orderClause)
{ {
ArrayList<MOrderLine> list = new ArrayList<MOrderLine> (); //red1 - using new Query class from Teo / Victor's MDDOrder.java implementation
StringBuffer sql = new StringBuffer("SELECT * FROM C_OrderLine WHERE C_Order_ID=? "); StringBuffer whereClauseFinal = new StringBuffer(MOrderLine.COLUMNNAME_C_Order_ID+"=?");
if (whereClause != null) if (!Util.isEmpty(whereClause, true))
sql.append(whereClause); whereClauseFinal.append(whereClause);
if (orderClause != null) if (orderClause.length() == 0)
sql.append(" ").append(orderClause); orderClause = MOrderLine.COLUMNNAME_Line;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
pstmt.setInt(1, getC_Order_ID());
rs = pstmt.executeQuery();
while (rs.next())
{
MOrderLine ol = new MOrderLine(getCtx(), rs, get_TrxName());
ol.setHeaderInfo (this);
list.add(ol);
}
}
catch (Exception e)
{
log.log(Level.SEVERE, sql.toString(), e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
// //
MOrderLine[] lines = new MOrderLine[list.size ()]; List<MOrderLine> list = new Query(getCtx(), MOrderLine.Table_Name, whereClauseFinal.toString(), get_TrxName())
list.toArray (lines); .setParameters(new Object[]{get_ID()})
return lines; .setOrderBy(orderClause)
.list();
for (MOrderLine ol : list) {
ol.setHeaderInfo (this);
}
//
return list.toArray(new MOrderLine[list.size()]);
} // getLines } // getLines
/** /**
@ -649,7 +639,7 @@ public class MOrder extends X_C_Order implements DocAction
return m_lines; return m_lines;
} }
// //
String orderClause = "ORDER BY "; String orderClause = "";
if (orderBy != null && orderBy.length() > 0) if (orderBy != null && orderBy.length() > 0)
orderClause += orderBy; orderClause += orderBy;
else else
@ -711,38 +701,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
@ -753,36 +715,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
/** /**
@ -791,29 +732,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
@ -824,37 +746,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 M_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
/** /**
@ -917,8 +817,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);
@ -961,8 +861,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
@ -1069,7 +968,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);
} }
@ -1089,32 +988,39 @@ public class MOrder extends X_C_Order implements DocAction
} }
// Sync Lines // Sync Lines
afterSaveSync("AD_Org_ID"); if ( is_ValueChanged("AD_Org_ID")
afterSaveSync("C_BPartner_ID"); || is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID)
afterSaveSync("C_BPartner_Location_ID"); || is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_Location_ID)
afterSaveSync("DateOrdered"); || is_ValueChanged(MOrder.COLUMNNAME_DateOrdered)
afterSaveSync("DatePromised"); || is_ValueChanged(MOrder.COLUMNNAME_DatePromised)
afterSaveSync("M_Warehouse_ID"); || is_ValueChanged(MOrder.COLUMNNAME_M_Warehouse_ID)
afterSaveSync("M_Shipper_ID"); || is_ValueChanged(MOrder.COLUMNNAME_M_Shipper_ID)
afterSaveSync("C_Currency_ID"); || is_ValueChanged(MOrder.COLUMNNAME_C_Currency_ID)) {
MOrderLine[] lines = getLines();
for (MOrderLine line : lines) {
if (is_ValueChanged("AD_Org_ID"))
line.setAD_Org_ID(getAD_Org_ID());
if (is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_ID))
line.setC_BPartner_ID(getC_BPartner_ID());
if (is_ValueChanged(MOrder.COLUMNNAME_C_BPartner_Location_ID))
line.setC_BPartner_Location_ID(getC_BPartner_Location_ID());
if (is_ValueChanged(MOrder.COLUMNNAME_DateOrdered))
line.setDateOrdered(getDateOrdered());
if (is_ValueChanged(MOrder.COLUMNNAME_DatePromised))
line.setDatePromised(getDatePromised());
if (is_ValueChanged(MOrder.COLUMNNAME_M_Warehouse_ID))
line.setM_Warehouse_ID(getM_Warehouse_ID());
if (is_ValueChanged(MOrder.COLUMNNAME_M_Shipper_ID))
line.setM_Shipper_ID(getM_Shipper_ID());
if (is_ValueChanged(MOrder.COLUMNNAME_C_Currency_ID))
line.setC_Currency_ID(getC_Currency_ID());
line.saveEx();
}
}
// //
return true; return true;
} // afterSave } // afterSave
private void afterSaveSync (String columnName)
{
if (is_ValueChanged(columnName))
{
String sql = "UPDATE C_OrderLine ol"
+ " SET " + columnName + " ="
+ "(SELECT " + columnName
+ " FROM C_Order o WHERE ol.C_Order_ID=o.C_Order_ID) "
+ "WHERE C_Order_ID=" + getC_Order_ID();
int no = DB.executeUpdate(sql, get_TrxName());
log.fine(columnName + " Lines -> #" + no);
}
} // afterSaveSync
/** /**
* Before Delete * Before Delete
* @return true of it can be deleted * @return true of it can be deleted
@ -1124,11 +1030,8 @@ public class MOrder extends X_C_Order implements DocAction
if (isProcessed()) if (isProcessed())
return false; return false;
getLines(); for (MOrderLine line : getLines()) {
for (int i = 0; i < m_lines.length; i++) line.deleteEx(true);
{
if (!m_lines[i].beforeDelete())
return false;
} }
return true; return true;
} // beforeDelete } // beforeDelete
@ -1193,7 +1096,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@";
@ -1275,7 +1178,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";
@ -1347,7 +1250,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, "ORDER BY 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];
@ -1355,23 +1258,51 @@ public class MOrder extends X_C_Order implements DocAction
log.fine(product.getName()); log.fine(product.getName());
// New Lines // New Lines
int lineNo = line.getLine (); int lineNo = line.getLine ();
MProductBOM[] boms = MProductBOM.getBOMLines (product); //find default BOM with valid dates and to this product
MPPProductBOM bom = MPPProductBOM.get(product, getAD_Org_ID(),getDatePromised(), get_TrxName());
if(bom != null)
{
MPPProductBOMLine[] bomlines = bom.getLines(getDatePromised());
for (int j = 0; j < bomlines.length; j++)
{
MPPProductBOMLine bomline = bomlines[j];
MOrderLine newLine = new MOrderLine (this);
newLine.setLine (++lineNo);
newLine.setM_Product_ID (bomline.getM_Product_ID ());
newLine.setC_UOM_ID (bomline.getC_UOM_ID ());
newLine.setQty (line.getQtyOrdered ().multiply (
bomline.getQtyBOM()));
if (bomline.getDescription () != null)
newLine.setDescription (bomline.getDescription ());
//
newLine.setPrice ();
newLine.save (get_TrxName());
}
}
/*MProductBOM[] boms = MProductBOM.getBOMLines (product);
for (int j = 0; j < boms.length; j++) for (int j = 0; j < boms.length; j++)
{ {
MProductBOM bom = boms[j]; //MProductBOM bom = boms[j];
MPPProductBOMLine bom = boms[j];
MOrderLine newLine = new MOrderLine (this); MOrderLine newLine = new MOrderLine (this);
newLine.setLine (++lineNo); newLine.setLine (++lineNo);
newLine.setM_Product_ID (bom.getProduct () //newLine.setM_Product_ID (bom.getProduct ()
.getM_Product_ID ()); // .getM_Product_ID ());
newLine.setC_UOM_ID (bom.getProduct ().getC_UOM_ID ()); newLine.setM_Product_ID (bom.getM_Product_ID ());
//newLine.setC_UOM_ID (bom.getProduct ().getC_UOM_ID ());
newLine.setC_UOM_ID (bom.getC_UOM_ID ());
//newLine.setQty (line.getQtyOrdered ().multiply (
// bom.getBOMQty ()));
newLine.setQty (line.getQtyOrdered ().multiply ( newLine.setQty (line.getQtyOrdered ().multiply (
bom.getBOMQty ())); bom.getQtyBOM()));
if (bom.getDescription () != null) if (bom.getDescription () != null)
newLine.setDescription (bom.getDescription ()); newLine.setDescription (bom.getDescription ());
// //
newLine.setPrice (); newLine.setPrice ();
newLine.save (get_TrxName()); newLine.save (get_TrxName());
} }*/
// Convert into Comment Line // Convert into Comment Line
line.setM_Product_ID (0); line.setM_Product_ID (0);
line.setM_AttributeSetInstance_ID (0); line.setM_AttributeSetInstance_ID (0);
@ -1520,11 +1451,11 @@ public class MOrder extends X_C_Order implements DocAction
* Calculate Tax and Total * Calculate Tax and Total
* @return true if tax total calculated * @return true if tax total calculated
*/ */
private boolean calculateTaxTotal() public boolean calculateTaxTotal()
{ {
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
@ -1640,7 +1571,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;
@ -1993,7 +1924,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];
@ -2148,7 +2079,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];
@ -2178,6 +2109,58 @@ public class MOrder extends X_C_Order implements DocAction
return true; return true;
} // closeIt } // closeIt
/**
* @author: phib
* re-open a closed order
* (reverse steps of close())
*/
public String reopenIt() {
log.info(toString());
if (!MOrder.DOCSTATUS_Closed.equals(getDocStatus()))
{
return "Not closed - can't reopen";
}
//
MOrderLine[] lines = getLines(true, MOrderLine.COLUMNNAME_M_Product_ID);
for (int i = 0; i < lines.length; i++)
{
MOrderLine line = lines[i];
if (Env.ZERO.compareTo(line.getQtyLostSales()) != 0)
{
line.setQtyOrdered(line.getQtyLostSales().add(line.getQtyDelivered()));
line.setQtyLostSales(Env.ZERO);
// QtyEntered unchanged
// Strip Close() tags from description
String desc = line.getDescription();
if (desc == null)
desc = "";
Pattern pattern = Pattern.compile("( \\| )?Close \\(.*\\)");
String[] parts = pattern.split(desc);
desc = "";
for (String s : parts) {
desc = desc.concat(s);
}
line.setDescription(desc);
if (!line.save(get_TrxName()))
return "Couldn't save orderline";
}
}
// Clear Reservations
if (!reserveStock(null, lines))
{
m_processMsg = "Cannot unreserve Stock (close)";
return "Failed to update reservations";
}
setDocStatus(MOrder.DOCSTATUS_Completed);
setDocAction(DOCACTION_Close);
if (!this.save(get_TrxName()))
return "Couldn't save reopened order";
else
return "";
} // reopenIt
/** /**
* Reverse Correction - same void * Reverse Correction - same void
* @return true if success * @return true if success