/* public static Map<X_Ref_Quantity_Type, MStorageDetail> getAllForUpdate( * Ctx ctx, int M_Locator_ID, int M_Product_ID, * int M_AttributeSetInstance_ID, * Set<X_Ref_Quantity_Type> updateQtyTypes, Trx trx) { * Map<X_Ref_Quantity_Type, MStorageDetail> storageDetails = new HashMap<X_Ref_Quantity_Type, MStorageDetail>(); * for (X_Ref_Quantity_Type qtyType : X_Ref_Quantity_Type.values()) { * MStorageDetail store = MStorageDetail.Get(ctx, M_Locator_ID, * M_Product_ID, M_AttributeSetInstance_ID, qtyType, * (updateQtyTypes == null ? false : updateQtyTypes * .contains(qtyType)), trx); * storageDetails.put(qtyType, store); * } * return storageDetails; * }*/ public static Dictionary <String, MStorageDetail> GetAllForUpdate(Ctx ctx, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, List <String> updateQtyTypes, Trx trx) { Dictionary <String, MStorageDetail> storageDetails = new Dictionary <String, MStorageDetail>(); //Array qtyType = Enum.GetValues(typeof(X_Ref_Quantity_Type.X_Ref_Quantity_TypeEnum)); Array qtyType = X_Ref_Quantity_Type.Get().ToArray(); for (int i = 0; i < qtyType.Length; i++) { MStorageDetail store = MStorageDetail.Get(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, qtyType.GetValue(i).ToString(), (updateQtyTypes == null ? false : updateQtyTypes.Contains(qtyType.GetValue(i).ToString())), trx); //storageDetails.put(qtyType, store); storageDetails[qtyType.GetValue(i).ToString()] = store; } return(storageDetails); }
/// <summary> /// detail Add /// Warehouse must already be validated /// diffQty must always be positive; negative values are not processed /// </summary> /// <param name="ctx"></param> /// <param name="M_Warehouse_ID"></param> /// <param name="M_Locator_ID"></param> /// <param name="M_Product_ID"></param> /// <param name="M_AttributeSetInstance_ID"></param> /// <param name="reservationAttributeSetInstance_ID"></param> /// <param name="diffQty"></param> /// <param name="type"></param> /// <param name="trx"></param> /// <returns></returns> public static Boolean Add(Ctx ctx, int M_Warehouse_ID, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID, int reservationAttributeSetInstance_ID, Decimal diffQty, String type, Trx trx) { StringBuilder diffText = new StringBuilder("("); MStorageDetail storage = null; storage = MStorageDetail.GetCreate(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, type, trx); // Verify if (storage.GetM_Locator_ID() != M_Locator_ID && storage.GetM_Product_ID() != M_Product_ID && storage.GetM_AttributeSetInstance_ID() != M_AttributeSetInstance_ID) { s_log.Severe("No Storage found - M_Locator_ID=" + M_Locator_ID + ",M_Product_ID=" + M_Product_ID + ",ASI=" + M_AttributeSetInstance_ID); return(false); } MStorageDetail storageASI = null; if ((M_AttributeSetInstance_ID != reservationAttributeSetInstance_ID) && (type == X_Ref_Quantity_Type.RESERVED || type == X_Ref_Quantity_Type.ORDERED)) { int reservationM_Locator_ID = M_Locator_ID; if (reservationAttributeSetInstance_ID == 0) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); reservationM_Locator_ID = wh.GetDefaultM_Locator_ID(); } storageASI = MStorageDetail.Get(ctx, reservationM_Locator_ID, M_Product_ID, reservationAttributeSetInstance_ID, type, true, trx); if (storageASI == null) // create if not existing - should not happen { MProduct product = MProduct.Get(ctx, M_Product_ID); int xM_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID); if (xM_Locator_ID == 0) { MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID); xM_Locator_ID = wh.GetDefaultM_Locator_ID(); } storageASI = MStorageDetail.GetCreate(ctx, xM_Locator_ID, M_Product_ID, reservationAttributeSetInstance_ID, type, trx); } } Boolean changed = false; if (Env.Signum(diffQty) != 0) { if (storageASI == null) { storage.SetQty(Decimal.Add(storage.GetQty(), diffQty)); } else { storageASI.SetQty(Decimal.Add(storageASI.GetQty(), diffQty)); } diffText.Append(type.ToString()).Append("=").Append(diffQty); changed = true; } if (changed) { diffText.Append(") -> ").Append(storage.ToString()); s_log.Fine(diffText.ToString()); if (storageASI != null) { storageASI.Save(trx); // No AttributeSetInstance } // (reserved/ordered) return(storage.Save(trx)); } return(true); }