Revert revision 8248 because it was a bad merge.
Manual merge is needed.
This commit is contained in:
parent
3fc69673b4
commit
d1c1d8996a
|
@ -1654,6 +1654,7 @@ public class MInOut extends X_M_InOut implements DocAction
|
|||
|
||||
|
||||
boolean needSave = false;
|
||||
BigDecimal qtyASI = Env.ZERO ;
|
||||
|
||||
MProduct product = line.getProduct();
|
||||
|
||||
|
@ -1693,12 +1694,65 @@ public class MInOut extends X_M_InOut implements DocAction
|
|||
else if(getMovementType().compareTo(MInOut.MOVEMENTTYPE_VendorReturns) == 0 || getMovementType().compareTo(MInOut.MOVEMENTTYPE_CustomerShipment) == 0)
|
||||
{
|
||||
String MMPolicy = product.getMMPolicy();
|
||||
Timestamp minGuaranteeDate = getMovementDate();
|
||||
MStorage[] storages = MStorage.getWarehouse(getCtx(), getM_Warehouse_ID(), line.getM_Product_ID(), line.getM_AttributeSetInstance_ID(),
|
||||
minGuaranteeDate, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
|
||||
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
||||
line.getM_Product_ID(), line.getM_Locator_ID(),
|
||||
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
|
||||
BigDecimal qtyToDeliver = line.getMovementQty();
|
||||
/*for (int ii = 0; ii < storages.length; ii++)
|
||||
{
|
||||
MStorage storage = storages[ii];
|
||||
if (ii == 0)
|
||||
{
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
|
||||
needSave = true;
|
||||
log.config("Direct - " + line);
|
||||
qtyToDeliver = Env.ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.config("Split - " + line);
|
||||
MInOutLineMA ma = new MInOutLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
;
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
}
|
||||
else // create addl material allocation
|
||||
{
|
||||
MInOutLineMA ma = new MInOutLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
qtyToDeliver);
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
qtyToDeliver = Env.ZERO;
|
||||
else
|
||||
{
|
||||
ma.setMovementQty(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
}
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
if (qtyToDeliver.signum() == 0)
|
||||
break;
|
||||
} // for all storages
|
||||
*/
|
||||
|
||||
for (MStorage storage: storages)
|
||||
{
|
||||
//consume ASI Zero
|
||||
if (storage.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
qtyASI = qtyASI.add(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
MInOutLineMA ma = new MInOutLineMA (line,
|
||||
|
@ -1725,11 +1779,11 @@ public class MInOut extends X_M_InOut implements DocAction
|
|||
}
|
||||
|
||||
// No AttributeSetInstance found for remainder
|
||||
if (qtyToDeliver.signum() != 0)
|
||||
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
|
||||
{
|
||||
MInOutLineMA ma = new MInOutLineMA (line, 0, qtyToDeliver);
|
||||
MInOutLineMA ma = new MInOutLineMA (line, 0, qtyToDeliver.add(qtyASI));
|
||||
if (!ma.save())
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
;
|
||||
log.fine("##: " + ma);
|
||||
}
|
||||
} // outgoing Trx
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -658,19 +658,81 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
//{
|
||||
// MMovementLine line = lines[i];
|
||||
boolean needSave = false;
|
||||
BigDecimal qtyASI = Env.ZERO ;
|
||||
|
||||
// Attribute Set Instance
|
||||
if (line.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
MProduct product = MProduct.get(getCtx(), line.getM_Product_ID());
|
||||
String MMPolicy = product.getMMPolicy();
|
||||
MStorage[] storages = MStorage.getWarehouse(getCtx(), 0, line.getM_Product_ID(), 0,
|
||||
null, MClient.MMPOLICY_FiFo.equals(MMPolicy), true, line.getM_Locator_ID(), get_TrxName());
|
||||
|
||||
MStorage[] storages = MStorage.getAllWithASI(getCtx(),
|
||||
line.getM_Product_ID(), line.getM_Locator_ID(),
|
||||
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
|
||||
BigDecimal qtyToDeliver = line.getMovementQty();
|
||||
|
||||
|
||||
/*for (int ii = 0; ii < storages.length; ii++)
|
||||
{
|
||||
MStorage storage = storages[ii];
|
||||
if (ii == 0)
|
||||
{
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
|
||||
needSave = true;
|
||||
log.config("Direct - " + line);
|
||||
qtyToDeliver = Env.ZERO;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.config("Split - " + line);
|
||||
MMovementLineMA ma = new MMovementLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
storage.getQtyOnHand());
|
||||
if (!ma.save())
|
||||
;
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
}
|
||||
else // create addl material allocation
|
||||
{
|
||||
MMovementLineMA ma = new MMovementLineMA (line,
|
||||
storage.getM_AttributeSetInstance_ID(),
|
||||
qtyToDeliver);
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
qtyToDeliver = Env.ZERO;
|
||||
else
|
||||
{
|
||||
ma.setMovementQty(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
}
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("#" + ii + ": " + ma + ", QtyToDeliver=" + qtyToDeliver);
|
||||
}
|
||||
if (qtyToDeliver.signum() == 0)
|
||||
break;
|
||||
} // for all storages
|
||||
|
||||
// No AttributeSetInstance found for remainder
|
||||
if (qtyToDeliver.signum() != 0)
|
||||
{
|
||||
MMovementLineMA ma = new MMovementLineMA (line,
|
||||
0, qtyToDeliver);
|
||||
if (!ma.save())
|
||||
;
|
||||
log.fine("##: " + ma);
|
||||
}*/
|
||||
for (MStorage storage: storages)
|
||||
{
|
||||
//consume ASI Zero
|
||||
if (storage.getM_AttributeSetInstance_ID() == 0)
|
||||
{
|
||||
qtyASI = qtyASI.add(storage.getQtyOnHand());
|
||||
qtyToDeliver = qtyToDeliver.subtract(storage.getQtyOnHand());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (storage.getQtyOnHand().compareTo(qtyToDeliver) >= 0)
|
||||
{
|
||||
MMovementLineMA ma = new MMovementLineMA (line,
|
||||
|
@ -699,12 +761,12 @@ public class MMovement extends X_M_Movement implements DocAction
|
|||
}
|
||||
|
||||
// No AttributeSetInstance found for remainder
|
||||
if (qtyToDeliver.signum() != 0)
|
||||
if (qtyToDeliver.signum() != 0 || qtyASI.signum() != 0)
|
||||
{
|
||||
MMovementLineMA ma = new MMovementLineMA (line, 0 , qtyToDeliver);
|
||||
MMovementLineMA ma = new MMovementLineMA (line, 0 , qtyToDeliver.add(qtyASI));
|
||||
|
||||
if (!ma.save())
|
||||
throw new IllegalStateException("Error try create ASI Reservation");
|
||||
;
|
||||
log.fine("##: " + ma);
|
||||
}
|
||||
} // attributeSetInstance
|
||||
|
|
|
@ -78,6 +78,7 @@ public class MStorage extends X_M_Storage
|
|||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
pstmt = null;
|
||||
if (retValue == null)
|
||||
s_log.fine("Not Found - M_Locator_ID=" + M_Locator_ID
|
||||
+ ", M_Product_ID=" + M_Product_ID + ", M_AttributeSetInstance_ID=" + M_AttributeSetInstance_ID);
|
||||
|
@ -88,7 +89,7 @@ public class MStorage extends X_M_Storage
|
|||
} // get
|
||||
|
||||
/**
|
||||
* Get all Storages for Product with ASI and QtyOnHand <> 0
|
||||
* Get all Storages for Product with ASI and QtyOnHand > 0
|
||||
* @param ctx context
|
||||
* @param M_Product_ID product
|
||||
* @param M_Locator_ID locator
|
||||
|
@ -102,9 +103,13 @@ public class MStorage extends X_M_Storage
|
|||
ArrayList<MStorage> list = new ArrayList<MStorage>();
|
||||
String sql = "SELECT * FROM M_Storage "
|
||||
+ "WHERE M_Product_ID=? AND M_Locator_ID=?"
|
||||
+ " AND M_AttributeSetInstance_ID > 0 "
|
||||
+ " AND QtyOnHand <> 0 "
|
||||
// Remove for management rightly FIFO/LIFO now you can consume a layer with ASI ID = zero and Qty onhand in negative
|
||||
// + " AND M_AttributeSetInstance_ID > 0"
|
||||
// + " AND QtyOnHand > 0 "
|
||||
+ " AND QtyOnHand <> 0 "
|
||||
+ "ORDER BY M_AttributeSetInstance_ID";
|
||||
if (!FiFo)
|
||||
sql += " DESC";
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
|
@ -125,13 +130,14 @@ public class MStorage extends X_M_Storage
|
|||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
pstmt = null;
|
||||
MStorage[] retValue = new MStorage[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
} // getAllWithASI
|
||||
|
||||
/**
|
||||
* Get all Storages for Product where QtyOnHand <> 0
|
||||
* Get all Storages for Product
|
||||
* @param ctx context
|
||||
* @param M_Product_ID product
|
||||
* @param M_Locator_ID locator
|
||||
|
@ -166,6 +172,7 @@ public class MStorage extends X_M_Storage
|
|||
DB.close(rs, pstmt);
|
||||
rs = null; pstmt = null;
|
||||
}
|
||||
pstmt = null;
|
||||
MStorage[] retValue = new MStorage[list.size()];
|
||||
list.toArray(retValue);
|
||||
return retValue;
|
||||
|
@ -220,41 +227,23 @@ public class MStorage extends X_M_Storage
|
|||
* @param FiFo first in-first-out
|
||||
* @param trxName transaction
|
||||
* @return existing - ordered by location priority (desc) and/or guarantee date
|
||||
*
|
||||
* @deprecated
|
||||
*/
|
||||
public static MStorage[] getWarehouse (Properties ctx, int M_Warehouse_ID,
|
||||
int M_Product_ID, int M_AttributeSetInstance_ID, int M_AttributeSet_ID,
|
||||
boolean allAttributeInstances, Timestamp minGuaranteeDate,
|
||||
boolean FiFo, String trxName)
|
||||
{
|
||||
return getWarehouse(ctx, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
|
||||
minGuaranteeDate, FiFo, false, 0, trxName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Storage Info for Warehouse or locator
|
||||
* @param ctx context
|
||||
* @param M_Warehouse_ID ignore if M_Locator_ID > 0
|
||||
* @param M_Product_ID product
|
||||
* @param M_AttributeSetInstance_ID instance id, 0 to retrieve all instance
|
||||
* @param minGuaranteeDate optional minimum guarantee date if all attribute instances
|
||||
* @param FiFo first in-first-out
|
||||
* @param positiveOnly if true, only return storage records with qtyOnHand > 0
|
||||
* @param M_Locator_ID optional locator id
|
||||
* @param trxName transaction
|
||||
* @return existing - ordered by location priority (desc) and/or guarantee date
|
||||
*/
|
||||
public static MStorage[] getWarehouse (Properties ctx, int M_Warehouse_ID,
|
||||
int M_Product_ID, int M_AttributeSetInstance_ID, Timestamp minGuaranteeDate,
|
||||
boolean FiFo, boolean positiveOnly, int M_Locator_ID, String trxName)
|
||||
{
|
||||
if ((M_Warehouse_ID == 0 && M_Locator_ID == 0) || M_Product_ID == 0)
|
||||
if (M_Warehouse_ID == 0 || M_Product_ID == 0)
|
||||
return new MStorage[0];
|
||||
|
||||
boolean allAttributeInstances = false;
|
||||
if (M_AttributeSetInstance_ID == 0)
|
||||
allAttributeInstances = true;
|
||||
if (M_AttributeSet_ID == 0)
|
||||
allAttributeInstances = true;
|
||||
else
|
||||
{
|
||||
MAttributeSet mas = MAttributeSet.get(ctx, M_AttributeSet_ID);
|
||||
if (!mas.isInstanceAttribute())
|
||||
allAttributeInstances = true;
|
||||
}
|
||||
|
||||
ArrayList<MStorage> list = new ArrayList<MStorage>();
|
||||
// Specific Attribute Set Instance
|
||||
|
@ -262,18 +251,11 @@ public class MStorage extends X_M_Storage
|
|||
+ "s.AD_Client_ID,s.AD_Org_ID,s.IsActive,s.Created,s.CreatedBy,s.Updated,s.UpdatedBy,"
|
||||
+ "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory "
|
||||
+ "FROM M_Storage s"
|
||||
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) ";
|
||||
if (M_Locator_ID > 0)
|
||||
sql += "WHERE l.M_Locator_ID = ?";
|
||||
else
|
||||
sql += "WHERE l.M_Warehouse_ID=?";
|
||||
sql += " AND s.M_Product_ID=?"
|
||||
+ " AND COALESCE(s.M_AttributeSetInstance_ID,0)=? ";
|
||||
if (positiveOnly)
|
||||
{
|
||||
sql += " AND s.QtyOnHand > 0 ";
|
||||
}
|
||||
sql += "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
|
||||
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
|
||||
+ "WHERE l.M_Warehouse_ID=?"
|
||||
+ " AND s.M_Product_ID=?"
|
||||
+ " AND COALESCE(s.M_AttributeSetInstance_ID,0)=? "
|
||||
+ "ORDER BY l.PriorityNo DESC, M_AttributeSetInstance_ID";
|
||||
if (!FiFo)
|
||||
sql += " DESC";
|
||||
// All Attribute Set Instances
|
||||
|
@ -284,31 +266,19 @@ public class MStorage extends X_M_Storage
|
|||
+ "s.QtyOnHand,s.QtyReserved,s.QtyOrdered,s.DateLastInventory "
|
||||
+ "FROM M_Storage s"
|
||||
+ " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID)"
|
||||
+ " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) ";
|
||||
if (M_Locator_ID > 0)
|
||||
sql += "WHERE l.M_Locator_ID = ?";
|
||||
else
|
||||
sql += "WHERE l.M_Warehouse_ID=?";
|
||||
sql += " AND s.M_Product_ID=? ";
|
||||
+ " LEFT OUTER JOIN M_AttributeSetInstance asi ON (s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID) "
|
||||
+ "WHERE l.M_Warehouse_ID=?"
|
||||
+ " AND s.M_Product_ID=? ";
|
||||
if (minGuaranteeDate != null)
|
||||
{
|
||||
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) ";
|
||||
if (positiveOnly)
|
||||
{
|
||||
sql += " AND s.QtyOnHand > 0 ";
|
||||
}
|
||||
sql += "ORDER BY l.PriorityNo DESC, " +
|
||||
"asi.GuaranteeDate, M_AttributeSetInstance_ID";
|
||||
sql += "AND (asi.GuaranteeDate IS NULL OR asi.GuaranteeDate>?) "
|
||||
+ "ORDER BY asi.GuaranteeDate, M_AttributeSetInstance_ID";
|
||||
if (!FiFo)
|
||||
sql += " DESC";
|
||||
sql += ", s.QtyOnHand DESC";
|
||||
sql += ", l.PriorityNo DESC, s.QtyOnHand DESC";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (positiveOnly)
|
||||
{
|
||||
sql += " AND s.QtyOnHand > 0 ";
|
||||
}
|
||||
sql += "ORDER BY l.PriorityNo DESC, l.M_Locator_ID, s.M_AttributeSetInstance_ID";
|
||||
if (!FiFo)
|
||||
sql += " DESC";
|
||||
|
@ -320,16 +290,12 @@ public class MStorage extends X_M_Storage
|
|||
try
|
||||
{
|
||||
pstmt = DB.prepareStatement(sql, trxName);
|
||||
pstmt.setInt(1, M_Locator_ID > 0 ? M_Locator_ID : M_Warehouse_ID);
|
||||
pstmt.setInt(1, M_Warehouse_ID);
|
||||
pstmt.setInt(2, M_Product_ID);
|
||||
if (!allAttributeInstances)
|
||||
{
|
||||
pstmt.setInt(3, M_AttributeSetInstance_ID);
|
||||
}
|
||||
else if (minGuaranteeDate != null)
|
||||
{
|
||||
pstmt.setTimestamp(3, minGuaranteeDate);
|
||||
}
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next())
|
||||
list.add (new MStorage (ctx, rs, trxName));
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue