Exemple #1
0
        public static MStorageDetail GetCreate(Ctx ctx, int M_Locator_ID,
                                               int M_Product_ID, int M_AttributeSetInstance_ID, String type, Trx trx)
        {
            if (M_Locator_ID == 0)
            {
                throw new ArgumentException("M_Locator_ID=0");
            }
            if (M_Product_ID == 0)
            {
                throw new ArgumentException("M_Product_ID=0");
            }
            MStorageDetail retValue = GetForUpdate(ctx, M_Locator_ID, M_Product_ID,
                                                   M_AttributeSetInstance_ID, type, trx);

            if (retValue != null)
            {
                return(retValue);
            }
            // Insert row based on locator
            MLocator locator = new MLocator(ctx, M_Locator_ID, trx);

            if (locator.Get_ID() != M_Locator_ID)
            {
                throw new ArgumentException("Not found M_Locator_ID="
                                            + M_Locator_ID);
            }
            //
            retValue = new MStorageDetail(locator, M_Product_ID,
                                          M_AttributeSetInstance_ID, type);
            retValue.Save(trx);
            s_log.Fine("New " + retValue);
            return(retValue);
        }
Exemple #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);
        }