BF [2989137] - Critical failure when adding physical inventory lines
http://sourceforge.net/tracker/?func=detail&atid=879332&aid=2989137&group_id=176962
This commit is contained in:
parent
f14bf2fbec
commit
b0ac11d60a
|
@ -50,9 +50,35 @@ public class CalloutInventory extends CalloutEngine
|
||||||
if (isCalloutActive())
|
if (isCalloutActive())
|
||||||
return "";
|
return "";
|
||||||
Integer InventoryLine = (Integer)mTab.getValue("M_InventoryLine_ID");
|
Integer InventoryLine = (Integer)mTab.getValue("M_InventoryLine_ID");
|
||||||
if (InventoryLine != null && InventoryLine.intValue() != 0)
|
BigDecimal bd = null;
|
||||||
return "";
|
|
||||||
|
if (InventoryLine != null && InventoryLine.intValue() != 0) {
|
||||||
|
MInventoryLine _ILine = new MInventoryLine(ctx, InventoryLine, null);
|
||||||
|
Integer M_Product_ID = (Integer)mTab.getValue("M_Product_ID");
|
||||||
|
Integer M_Locator_ID = (Integer)mTab.getValue("M_Locator_ID");
|
||||||
|
Integer M_AttributeSetInstance_ID = 0;
|
||||||
|
// if product or locator has changed recalculate Book Qty
|
||||||
|
if ((M_Product_ID != null && M_Product_ID != _ILine.getM_Product_ID()) ||
|
||||||
|
(M_Locator_ID !=null && M_Locator_ID != _ILine.getM_Locator_ID())) {
|
||||||
|
|
||||||
|
// Check ASI - if product has been changed remove old ASI
|
||||||
|
if (M_Product_ID == _ILine.getM_Product_ID()) {
|
||||||
|
M_AttributeSetInstance_ID = (Integer)mTab.getValue("M_AttributeSetInstance_ID");
|
||||||
|
if( M_AttributeSetInstance_ID == null )
|
||||||
|
M_AttributeSetInstance_ID = 0;
|
||||||
|
} else {
|
||||||
|
mTab.setValue("M_AttributeSetInstance_ID", null);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
bd = setQtyBook(M_AttributeSetInstance_ID, M_Product_ID, M_Locator_ID);
|
||||||
|
mTab.setValue("QtyBook", bd);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return mTab.setValue("QtyBook", bd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
// New Line - Get Book Value
|
// New Line - Get Book Value
|
||||||
int M_Product_ID = 0;
|
int M_Product_ID = 0;
|
||||||
Integer Product = (Integer)mTab.getValue("M_Product_ID");
|
Integer Product = (Integer)mTab.getValue("M_Product_ID");
|
||||||
|
@ -89,6 +115,36 @@ public class CalloutInventory extends CalloutEngine
|
||||||
mTab.setValue(MInventoryLine.COLUMNNAME_M_AttributeSetInstance_ID, null);
|
mTab.setValue(MInventoryLine.COLUMNNAME_M_AttributeSetInstance_ID, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set QtyBook from first storage location
|
||||||
|
// kviiksaar: Call's now the extracted function
|
||||||
|
try {
|
||||||
|
bd = setQtyBook(M_AttributeSetInstance_ID, M_Product_ID, M_Locator_ID);
|
||||||
|
mTab.setValue("QtyBook", bd);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return mTab.setValue("QtyBook", bd);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
log.info("M_Product_ID=" + M_Product_ID
|
||||||
|
+ ", M_Locator_ID=" + M_Locator_ID
|
||||||
|
+ ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID
|
||||||
|
+ " - QtyBook=" + bd);
|
||||||
|
return "";
|
||||||
|
} // product
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* kviiksaar
|
||||||
|
*
|
||||||
|
* Returns the current Book Qty for given parameters or 0
|
||||||
|
*
|
||||||
|
* @param M_AttributeSetInstance_ID
|
||||||
|
* @param M_Product_ID
|
||||||
|
* @param M_Locator_ID
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private BigDecimal setQtyBook (int M_AttributeSetInstance_ID, int M_Product_ID, int M_Locator_ID) throws Exception {
|
||||||
// Set QtyBook from first storage location
|
// Set QtyBook from first storage location
|
||||||
BigDecimal bd = null;
|
BigDecimal bd = null;
|
||||||
String sql = "SELECT QtyOnHand FROM M_Storage "
|
String sql = "SELECT QtyOnHand FROM M_Storage "
|
||||||
|
@ -99,40 +155,35 @@ public class CalloutInventory extends CalloutEngine
|
||||||
sql = "SELECT SUM(QtyOnHand) FROM M_Storage "
|
sql = "SELECT SUM(QtyOnHand) FROM M_Storage "
|
||||||
+ "WHERE M_Product_ID=?" // 1
|
+ "WHERE M_Product_ID=?" // 1
|
||||||
+ " AND M_Locator_ID=?"; // 2
|
+ " AND M_Locator_ID=?"; // 2
|
||||||
PreparedStatement pstmt = null;
|
|
||||||
ResultSet rs = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
pstmt = DB.prepareStatement(sql, null);
|
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, M_Product_ID);
|
pstmt.setInt(1, M_Product_ID);
|
||||||
pstmt.setInt(2, M_Locator_ID);
|
pstmt.setInt(2, M_Locator_ID);
|
||||||
if (M_AttributeSetInstance_ID != 0)
|
if (M_AttributeSetInstance_ID != 0)
|
||||||
pstmt.setInt(3, M_AttributeSetInstance_ID);
|
pstmt.setInt(3, M_AttributeSetInstance_ID);
|
||||||
rs = pstmt.executeQuery();
|
ResultSet rs = pstmt.executeQuery();
|
||||||
mTab.setValue("QtyBook", Env.ZERO);
|
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
bd = rs.getBigDecimal(1);
|
bd = rs.getBigDecimal(1);
|
||||||
if (bd != null)
|
if (bd != null)
|
||||||
mTab.setValue("QtyBook", bd);
|
return bd;
|
||||||
|
} else {
|
||||||
|
// gwu: 1719401: clear Booked Quantity to zero first in case the query returns no rows,
|
||||||
|
// for example when the locator has never stored a particular product.
|
||||||
|
return new BigDecimal(0);
|
||||||
}
|
}
|
||||||
|
rs.close();
|
||||||
|
pstmt.close();
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, sql, e);
|
log.log(Level.SEVERE, sql, e);
|
||||||
return e.getLocalizedMessage();
|
throw new Exception(e.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
finally
|
return new BigDecimal(0);
|
||||||
{
|
}
|
||||||
DB.close(rs, pstmt);
|
|
||||||
rs = null; pstmt = null;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
log.info("M_Product_ID=" + M_Product_ID
|
|
||||||
+ ", M_Locator_ID=" + M_Locator_ID
|
|
||||||
+ ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID
|
|
||||||
+ " - QtyBook=" + bd);
|
|
||||||
return "";
|
|
||||||
} // product
|
|
||||||
|
|
||||||
} // CalloutInventory
|
} // CalloutInventory
|
||||||
|
|
Loading…
Reference in New Issue