From c066a0c3e96075101015b7c7bb2037d20704b34a Mon Sep 17 00:00:00 2001 From: "Owner.Owner-PC" Date: Tue, 23 Oct 2012 11:31:40 +0700 Subject: [PATCH] Merge --- .../src/org/compiere/model/MProduct.java | 20 ++++-- .../compiere/model/MStorageReservation.java | 71 +++++++++++++------ 2 files changed, 66 insertions(+), 25 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/MProduct.java b/org.adempiere.base/src/org/compiere/model/MProduct.java index 99c4f55024..0c7e35bd4d 100644 --- a/org.adempiere.base/src/org/compiere/model/MProduct.java +++ b/org.adempiere.base/src/org/compiere/model/MProduct.java @@ -720,16 +720,26 @@ public class MProduct extends X_M_Product // Check Storage 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 Ordered = 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()); - //Ordered = OnHand.add(storages[i].getQtyOrdered()); - //Reserved = OnHand.add(storages[i].getQtyReserved()); + OnHand = OnHand.add(onHandStorages[i].getQtyOnHand()); + //Ordered = Ordered.add(storages[i].getQtyOrdered()); + //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 = ""; if (OnHand.signum() != 0) errMsg = "@QtyOnHand@ = " + OnHand; diff --git a/org.adempiere.base/src/org/compiere/model/MStorageReservation.java b/org.adempiere.base/src/org/compiere/model/MStorageReservation.java index fbd07fe5fc..2abe17891a 100644 --- a/org.adempiere.base/src/org/compiere/model/MStorageReservation.java +++ b/org.adempiere.base/src/org/compiere/model/MStorageReservation.java @@ -9,6 +9,7 @@ import java.util.Properties; import org.compiere.util.CLogMgt; import org.compiere.util.CLogger; import org.compiere.util.DB; +import org.compiere.util.Env; 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) { ArrayList params = new ArrayList(); - StringBuffer sql = new StringBuffer("SELECT COALESCE(SUM(COALESCE(SUM(s.QtyOnHand),0)-COALESCE(SUM(r.Qty),0),0)") - .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"); + StringBuffer sql = new StringBuffer(""); - params.add(M_Product_ID, M_Product_ID); - // Warehouse level - if (M_Locator_ID == 0) { - sql.append(" AND l.M_Warehouse_ID=?)"); - params.add(M_Warehouse_ID); - } - // Locator level - else { - sql.append(" AND s.M_Locator_ID=?)"); - params.add(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); + if (M_Locator_ID != 0) { + MLocator locator = new MLocator(Env.getCtx(), M_Locator_ID, trxName); + MWarehouse wh = new MWarehouse(Env.getCtx(), locator.getM_Warehouse_ID(), trxName); + if (wh.get_ValueAsInt("M_ReserveLocator_ID") != M_Locator_ID) { + sql.append("SELECT COALESCE(SUM(s.QtyOnHand),0)") + .append(" FROM M_StorageOnHand s") + .append(" WHERE s.M_Product_ID=? AND s.M_Locator_ID=?"); + + params.add(M_Product_ID, M_Locator_ID); + + // With ASI + if (M_AttributeSetInstance_ID != 0) { + sql.append(" AND s.M_AttributeSetInstance_ID=?"); + params.add(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); if (CLogMgt.isLevelFine())