This commit is contained in:
Owner.Owner-PC 2012-10-23 11:31:40 +07:00
parent bdf902535e
commit c066a0c3e9
2 changed files with 66 additions and 25 deletions

View File

@ -720,16 +720,26 @@ public class MProduct extends X_M_Product
// Check Storage // Check Storage
if (isStocked() || PRODUCTTYPE_Item.equals(getProductType())) if (isStocked() || PRODUCTTYPE_Item.equals(getProductType()))
{ {
MStorageOnHand[] storages = MStorageOnHand.getOfProduct(getCtx(), get_ID(), get_TrxName()); // large modified related to storages by zuhri
MStorageOnHand[] onHandStorages = MStorageOnHand.getOfProduct(getCtx(), get_ID(), get_TrxName());
MStorageReservation[] reservationStorages = MStorageReservation.getOfProduct(getCtx(), get_ID(), get_TrxName());
BigDecimal OnHand = Env.ZERO; BigDecimal OnHand = Env.ZERO;
BigDecimal Ordered = Env.ZERO; BigDecimal Ordered = Env.ZERO;
BigDecimal Reserved = Env.ZERO; BigDecimal Reserved = Env.ZERO;
for (int i = 0; i < storages.length; i++) for (int i = 0; i < onHandStorages.length; i++)
{ {
OnHand = OnHand.add(storages[i].getQtyOnHand()); OnHand = OnHand.add(onHandStorages[i].getQtyOnHand());
//Ordered = OnHand.add(storages[i].getQtyOrdered()); //Ordered = Ordered.add(storages[i].getQtyOrdered());
//Reserved = OnHand.add(storages[i].getQtyReserved()); //Reserved = Reserved.add(storages[i].getQtyReserved());
} }
for (int i = 0; i < reservationStorages.length; i++)
{
if(reservationStorages[i].isSOTrx())
Reserved = Reserved.add(reservationStorages[i].getQty());
else
Ordered = Ordered.add(reservationStorages[i].getQty());
}
// end large modified related to storages by zuhri
String errMsg = ""; String errMsg = "";
if (OnHand.signum() != 0) if (OnHand.signum() != 0)
errMsg = "@QtyOnHand@ = " + OnHand; errMsg = "@QtyOnHand@ = " + OnHand;

View File

@ -9,6 +9,7 @@ import java.util.Properties;
import org.compiere.util.CLogMgt; import org.compiere.util.CLogMgt;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
import org.compiere.util.DB; import org.compiere.util.DB;
import org.compiere.util.Env;
public class MStorageReservation extends X_M_StorageReservation { public class MStorageReservation extends X_M_StorageReservation {
@ -105,28 +106,58 @@ public class MStorageReservation extends X_M_StorageReservation {
int M_Product_ID, int M_AttributeSetInstance_ID, String trxName) int M_Product_ID, int M_AttributeSetInstance_ID, String trxName)
{ {
ArrayList<Object> params = new ArrayList<Object>(); ArrayList<Object> params = new ArrayList<Object>();
StringBuffer sql = new StringBuffer("SELECT COALESCE(SUM(COALESCE(SUM(s.QtyOnHand),0)-COALESCE(SUM(r.Qty),0),0)") StringBuffer sql = new StringBuffer("");
.append(" FROM M_StorageOnHand s")
.append(" JOIN M_StorageReservation r ON s.M_Product_ID=r.M_Product_ID")
.append(" WHERE s.M_Product_ID=?")
.append(" AND EXISTS (SELECT 1 FROM M_Locator l WHERE s.M_Locator_ID=l.M_Locator_ID AND l.M_Warehouse_ID=r.M_Warehouse_ID");
params.add(M_Product_ID, M_Product_ID); if (M_Locator_ID != 0) {
// Warehouse level MLocator locator = new MLocator(Env.getCtx(), M_Locator_ID, trxName);
if (M_Locator_ID == 0) { MWarehouse wh = new MWarehouse(Env.getCtx(), locator.getM_Warehouse_ID(), trxName);
sql.append(" AND l.M_Warehouse_ID=?)"); if (wh.get_ValueAsInt("M_ReserveLocator_ID") != M_Locator_ID) {
params.add(M_Warehouse_ID); sql.append("SELECT COALESCE(SUM(s.QtyOnHand),0)")
} .append(" FROM M_StorageOnHand s")
// Locator level .append(" WHERE s.M_Product_ID=? AND s.M_Locator_ID=?");
else {
sql.append(" AND s.M_Locator_ID=?)"); params.add(M_Product_ID, M_Locator_ID);
params.add(M_Locator_ID);
} // With ASI
// With ASI if (M_AttributeSetInstance_ID != 0) {
if (M_AttributeSetInstance_ID != 0) { sql.append(" AND s.M_AttributeSetInstance_ID=?");
sql.append(" AND s.M_AttributeSetInstance_ID=? AND r.M_AttributeSetInstance_ID=?"); params.add(M_AttributeSetInstance_ID);
params.add(M_AttributeSetInstance_ID, M_AttributeSetInstance_ID); }
}
else {
sql.append("SELECT COALESCE(SUM(s.QtyOnHand),0)-COALESCE(SUM(r.Qty),0)")
.append(" FROM M_StorageOnHand s")
.append(" LEFT JOIN M_StorageReservation r ON s.M_Product_ID=r.M_Product_ID")
.append(" WHERE s.M_Product_ID=? AND AND s.M_Locator_ID=?")
.append(" AND EXISTS (SELECT 1 FROM M_Locator l JOIN M_Warehouse w ON w.M_ReserveLocator_ID=l.M_Locator_ID")
.append(" WHERE s.M_Locator_ID=l.M_Locator_ID AND l.M_Warehouse_ID=r.M_Warehouse_ID");
params.add(M_Product_ID, M_Locator_ID);
// With ASI
if (M_AttributeSetInstance_ID != 0) {
sql.append(" AND s.M_AttributeSetInstance_ID=? AND r.M_AttributeSetInstance_ID=?");
params.add(M_AttributeSetInstance_ID, M_AttributeSetInstance_ID);
}
}
} else {
sql.append("SELECT COALESCE(SUM(s.QtyOnHand),0)-COALESCE(SUM(r.Qty),0)")
.append(" FROM M_StorageOnHand s")
.append(" LEFT JOIN M_StorageReservation r ON s.M_Product_ID=r.M_Product_ID")
.append(" WHERE s.M_Product_ID=?")
.append(" AND EXISTS (SELECT 1 FROM M_Locator l")
.append(" WHERE s.M_Locator_ID=l.M_Locator_ID AND l.M_Warehouse_ID=r.M_Warehouse_ID")
.append(" AND l.M_Warehouse_ID=?)");
params.add(M_Product_ID, M_Warehouse_ID);
// With ASI
if (M_AttributeSetInstance_ID != 0) {
sql.append(" AND s.M_AttributeSetInstance_ID=? AND r.M_AttributeSetInstance_ID=?");
params.add(M_AttributeSetInstance_ID, M_AttributeSetInstance_ID);
}
} }
// //
BigDecimal retValue = DB.getSQLValueBD(trxName, sql.toString(), params); BigDecimal retValue = DB.getSQLValueBD(trxName, sql.toString(), params);
if (CLogMgt.isLevelFine()) if (CLogMgt.isLevelFine())