コード例 #1
0
        /**
         *  Set (default) Locator based on qty.
         *  @param Qty quantity
         *  Assumes Warehouse is set
         */
        public void SetM_Locator_ID(Decimal Qty)
        {
            //	Locator esatblished
            if (GetM_Locator_ID() != 0)
            {
                return;
            }
            //	No Product
            if (GetM_Product_ID() == 0)
            {
                Set_ValueNoCheck("M_Locator_ID", null);
                return;
            }

            //	Get existing Location
            int M_Locator_ID = MStorage.GetM_Locator_ID(GetM_Warehouse_ID(),
                                                        GetM_Product_ID(), GetM_AttributeSetInstance_ID(),
                                                        Qty, Get_TrxName());

            //	Get default Location
            if (M_Locator_ID == 0)
            {
                MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());
                M_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, GetM_Warehouse_ID());
                if (M_Locator_ID == 0)
                {
                    MWarehouse wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID());
                    M_Locator_ID = wh.GetDefaultM_Locator_ID();
                }
            }
            SetM_Locator_ID(M_Locator_ID);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /**
         *  Set Product - Callout
         *	@param oldM_Product_ID old value
         *	@param newM_Product_ID new value
         *	@param windowNo window
         *	@throws Exception
         */
        //@UICallout
        public void SetM_Product_ID(String oldM_Product_ID, String newM_Product_ID, int windowNo)
        {
            if (newM_Product_ID == null || newM_Product_ID.Length == 0)
            {
                return;
            }
            int M_Product_ID = int.Parse(newM_Product_ID);

            if (M_Product_ID == 0)
            {
                SetM_AttributeSetInstance_ID(0);
                return;
            }
            //
            base.SetM_Product_ID(M_Product_ID);
            SetC_Charge_ID(0);

            //	Set Attribute & Locator
            int M_Locator_ID = 0;

            if (GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_Product_ID") == M_Product_ID &&
                GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID") != 0)
            {
                SetM_AttributeSetInstance_ID(GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_AttributeSetInstance_ID"));
                //	Locator from Info Window - ASI
                M_Locator_ID = GetCtx().GetContextAsInt(Env.WINDOW_INFO, Env.TAB_INFO, "M_Locator_ID");
                if (M_Locator_ID != 0)
                {
                    SetM_Locator_ID(M_Locator_ID);
                }
            }
            else
            {
                SetM_AttributeSetInstance_ID(0);
            }
            //
            bool IsSOTrx = GetCtx().IsSOTrx(windowNo);

            if (IsSOTrx)
            {
                return;
            }

            //	PO - Set UOM/Locator/Qty
            MProduct product = GetProduct();

            SetC_UOM_ID(product.GetC_UOM_ID());
            Decimal QtyEntered = GetQtyEntered();

            SetMovementQty(QtyEntered);
            if (M_Locator_ID != 0)
            {
                ;               //	already set via ASI
            }
            else
            {
                int M_Warehouse_ID = GetCtx().GetContextAsInt(windowNo, "M_Warehouse_ID");
                M_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID);
                if (M_Locator_ID != 0)
                {
                    SetM_Locator_ID(M_Locator_ID);
                }
                else
                {
                    MWarehouse wh = MWarehouse.Get(GetCtx(), M_Warehouse_ID);
                    SetM_Locator_ID(wh.GetDefaultM_Locator_ID());
                }
            }
        }