MInventory:

[ 2616330 ] Use MPeriod.testPeriodOpen instead of isOpen
https://sourceforge.net/tracker/?func=detail&atid=879335&aid=2616330&group_id=176962

* better exception handling - use saveEx
* use parametrized SQL queries
This commit is contained in:
teo_sarca 2009-02-26 09:57:59 +00:00
parent 054d256ac3
commit 7611d6b602
1 changed files with 16 additions and 53 deletions

View File

@ -137,30 +137,11 @@ public class MInventory extends X_M_Inventory implements DocAction
return m_lines; return m_lines;
} }
// //
ArrayList<MInventoryLine> list = new ArrayList<MInventoryLine>(); List<MInventoryLine> list = new Query(getCtx(), MInventoryLine.Table_Name, "M_Inventory_ID=?", get_TrxName())
String sql = "SELECT * FROM M_InventoryLine WHERE M_Inventory_ID=? ORDER BY Line"; .setParameters(new Object[]{get_ID()})
PreparedStatement pstmt = null; .setOrderBy(MInventoryLine.COLUMNNAME_Line)
ResultSet rs = null; .list();
try m_lines = list.toArray(new MInventoryLine[list.size()]);
{
pstmt = DB.prepareStatement (sql, get_TrxName());
pstmt.setInt (1, getM_Inventory_ID());
rs = pstmt.executeQuery ();
while (rs.next ())
list.add (new MInventoryLine (getCtx(), rs, get_TrxName()));
}
catch (Exception e)
{
log.log(Level.SEVERE, sql, e);
}
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
m_lines = new MInventoryLine[list.size ()];
list.toArray (m_lines);
return m_lines; return m_lines;
} // getLines } // getLines
@ -275,10 +256,9 @@ public class MInventory extends X_M_Inventory implements DocAction
super.setProcessed (processed); super.setProcessed (processed);
if (get_ID() == 0) if (get_ID() == 0)
return; return;
String sql = "UPDATE M_InventoryLine SET Processed='" //
+ (processed ? "Y" : "N") final String sql = "UPDATE M_InventoryLine SET Processed=? WHERE M_Inventory_ID=?";
+ "' WHERE M_Inventory_ID=" + getM_Inventory_ID(); int noLine = DB.executeUpdateEx(sql, new Object[]{processed, getM_Inventory_ID()}, get_TrxName());
int noLine = DB.executeUpdate(sql, get_TrxName());
m_lines = null; m_lines = null;
log.fine("Processed=" + processed + " - Lines=" + noLine); log.fine("Processed=" + processed + " - Lines=" + noLine);
} // setProcessed } // setProcessed
@ -335,11 +315,7 @@ public class MInventory extends X_M_Inventory implements DocAction
return DocAction.STATUS_Invalid; return DocAction.STATUS_Invalid;
// Std Period open? // Std Period open?
if (!MPeriod.isOpen(getCtx(), getMovementDate(), MDocType.DOCBASETYPE_MaterialPhysicalInventory, getAD_Org_ID())) MPeriod.testPeriodOpen(getCtx(), getMovementDate(), MDocType.DOCBASETYPE_MaterialPhysicalInventory, getAD_Org_ID());
{
m_processMsg = "@PeriodClosed@";
return DocAction.STATUS_Invalid;
}
MInventoryLine[] lines = getLines(false); MInventoryLine[] lines = getLines(false);
if (lines.length == 0) if (lines.length == 0)
{ {
@ -523,7 +499,7 @@ public class MInventory extends X_M_Inventory implements DocAction
} }
} }
String m_MovementType =null; String m_MovementType = null;
if(qtyDiff.compareTo(Env.ZERO) > 0 ) if(qtyDiff.compareTo(Env.ZERO) > 0 )
m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn; m_MovementType = MTransaction.MOVEMENTTYPE_InventoryIn;
else else
@ -761,11 +737,7 @@ public class MInventory extends X_M_Inventory implements DocAction
return false; return false;
MDocType dt = MDocType.get(getCtx(), getC_DocType_ID()); MDocType dt = MDocType.get(getCtx(), getC_DocType_ID());
if (!MPeriod.isOpen(getCtx(), getMovementDate(), dt.getDocBaseType(), getAD_Org_ID())) MPeriod.testPeriodOpen(getCtx(), getMovementDate(), dt.getDocBaseType(), getAD_Org_ID());
{
m_processMsg = "@PeriodClosed@";
return false;
}
// Deep Copy // Deep Copy
MInventory reversal = new MInventory(getCtx(), 0, get_TrxName()); MInventory reversal = new MInventory(getCtx(), 0, get_TrxName());
@ -778,11 +750,7 @@ public class MInventory extends X_M_Inventory implements DocAction
reversal.addDescription("{->" + getDocumentNo() + ")"); reversal.addDescription("{->" + getDocumentNo() + ")");
//FR1948157 //FR1948157
reversal.setReversal_ID(getM_Inventory_ID()); reversal.setReversal_ID(getM_Inventory_ID());
if (!reversal.save()) reversal.saveEx();
{
m_processMsg = "Could not create Inventory Reversal";
return false;
}
reversal.setReversal(true); reversal.setReversal(true);
// Reverse Line Qty // Reverse Line Qty
@ -802,11 +770,7 @@ public class MInventory extends X_M_Inventory implements DocAction
rLine.setQtyCount (oLine.getQtyBook()); rLine.setQtyCount (oLine.getQtyBook());
rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate()); rLine.setQtyInternalUse (oLine.getQtyInternalUse().negate());
if (!rLine.save()) rLine.saveEx();
{
m_processMsg = "Could not create Inventory Reversal Line";
return false;
}
//We need to copy MA //We need to copy MA
if (rLine.getM_AttributeSetInstance_ID() == 0) if (rLine.getM_AttributeSetInstance_ID() == 0)
@ -818,8 +782,7 @@ public class MInventory extends X_M_Inventory implements DocAction
MInventoryLineMA ma = new MInventoryLineMA (rLine, MInventoryLineMA ma = new MInventoryLineMA (rLine,
mas[j].getM_AttributeSetInstance_ID(), mas[j].getM_AttributeSetInstance_ID(),
mas[j].getMovementQty().negate()); mas[j].getMovementQty().negate());
if (!ma.save()) ma.saveEx();
throw new IllegalStateException("Error try create ASI Reservation");
} }
} }
} }
@ -832,7 +795,7 @@ public class MInventory extends X_M_Inventory implements DocAction
reversal.closeIt(); reversal.closeIt();
reversal.setDocStatus(DOCSTATUS_Reversed); reversal.setDocStatus(DOCSTATUS_Reversed);
reversal.setDocAction(DOCACTION_None); reversal.setDocAction(DOCACTION_None);
reversal.save(); reversal.saveEx();
m_processMsg = reversal.getDocumentNo(); m_processMsg = reversal.getDocumentNo();
// Update Reversed (this) // Update Reversed (this)