Exemplo n.º 1
0
        protected override bool AfterDelete(bool success)
        {
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (GetM_RequisitionLine_ID() != 0)
                {
                    MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null);
                    requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() - qtyReserved);
                    if (!requisition.Save())
                    {
                        return(false);
                    }
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null);
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null);
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved);
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 /// <summary>
 /// After Delete
 /// </summary>
 /// <param name="sucess">new</param>
 /// <returns>true if can be deleted</returns>
 /// SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
 protected override bool AfterDelete(bool success)
 {
     if (Env.IsModuleInstalled("DTD001_") && IsInternalUse())
     {
         if (GetM_RequisitionLine_ID() != 0)
         {
             MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
             requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() - qtyReserved);
             if (!requisition.Save())
             {
                 return(false);
             }
             storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());      // Trx used to handle query stuck problem
             if (storage == null)
             {
                 storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());         // Trx used to handle query stuck problem
             }
             storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved);
             if (!storage.Save())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 public Record(List <MStorage> storageDetails)
 {
     foreach (MStorage storage in storageDetails)
     {
         storageMap[X_Ref_Quantity_Type.GetEnum(storage.GetQtyType())] = storage;
         refDetail = storage;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Eliminate Reserved/Ordered
 /// </summary>
 /// <param name="target">target Storage</param>
 private void EliminateReservation(MStorage target)
 {
     //	Negative Ordered / Reserved Qty
     if (Env.Signum(target.GetQtyReserved()) != 0 || Env.Signum(target.GetQtyOrdered()) != 0)
     {
         int      M_Locator_ID = target.GetM_Locator_ID();
         MStorage storage0     = MStorage.Get(GetCtx(), M_Locator_ID,
                                              target.GetM_Product_ID(), 0, Get_Trx());
         if (storage0 == null)
         {
             MLocator defaultLoc = MLocator.GetDefault(GetCtx(), M_Locator_ID);
             if (M_Locator_ID != defaultLoc.GetM_Locator_ID())
             {
                 M_Locator_ID = defaultLoc.GetM_Locator_ID();
                 storage0     = MStorage.Get(GetCtx(), M_Locator_ID,
                                             target.GetM_Product_ID(), 0, Get_Trx());
             }
         }
         if (storage0 != null)
         {
             Decimal reserved = Env.ZERO;
             Decimal ordered  = Env.ZERO;
             if (Env.Signum(Decimal.Add(target.GetQtyReserved(), storage0.GetQtyReserved())) >= 0)
             {
                 reserved = target.GetQtyReserved();             //	negative
             }
             if (Env.Signum(Decimal.Add(target.GetQtyOrdered(), storage0.GetQtyOrdered())) >= 0)
             {
                 ordered = target.GetQtyOrdered();               //	negative
             }
             //	Eliminate Reservation
             if (Env.Signum(reserved) != 0 || Env.Signum(ordered) != 0)
             {
                 if (MStorage.Add(GetCtx(), target.GetM_Warehouse_ID(), target.GetM_Locator_ID(),
                                  target.GetM_Product_ID(),
                                  target.GetM_AttributeSetInstance_ID(), target.GetM_AttributeSetInstance_ID(),
                                  Env.ZERO, Decimal.Negate(reserved), Decimal.Negate(ordered), Get_Trx()))
                 {
                     if (MStorage.Add(GetCtx(), storage0.GetM_Warehouse_ID(), storage0.GetM_Locator_ID(),
                                      storage0.GetM_Product_ID(),
                                      storage0.GetM_AttributeSetInstance_ID(), storage0.GetM_AttributeSetInstance_ID(),
                                      Env.ZERO, reserved, ordered, Get_Trx()))
                     {
                         log.Info("Reserved=" + reserved + ",Ordered=" + ordered);
                     }
                     else
                     {
                         log.Warning("Failed Storage0 Update");
                     }
                 }
                 else
                 {
                     log.Warning("Failed Target Update");
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Create Material Allocations for new Instances
        /// </summary>
        /// <param name="updateQtyBooked"></param>
        public void CreateMA(bool updateQtyBooked)
        {
            VAdvantage.Model.MInventoryLine INVLine = new VAdvantage.Model.MInventoryLine(GetCtx(), GetM_InventoryLine_ID(), Get_TrxName());
            int delMA = MInventoryLineMA.DeleteInventoryLineMA(GetM_InventoryLine_ID(), Get_TrxName());

            log.Info("DeletedMA=" + delMA);

            MStorage[] storages = MStorage.GetAll(GetCtx(), GetM_Product_ID(),
                                                  GetM_Locator_ID(), Get_TrxName());
            bool allZeroASI = true;

            for (int i = 0; i < storages.Length; i++)
            {
                if (storages[i].GetM_AttributeSetInstance_ID() != 0)
                {
                    allZeroASI = false;
                    break;
                }
            }
            if (allZeroASI)
            {
                return;
            }

            MInventoryLineMA ma  = null;
            Decimal          sum = Env.ZERO;

            for (int i = 0; i < storages.Length; i++)
            {
                MStorage storage = storages[i];
                // nnayak - ignore negative layers
                if (Env.Signum(storage.GetQtyOnHand()) <= 0)
                {
                    continue;
                }
                if (ma != null &&
                    ma.GetM_AttributeSetInstance_ID() == storage.GetM_AttributeSetInstance_ID())
                {
                    ma.SetMovementQty(Decimal.Add(ma.GetMovementQty(), storage.GetQtyOnHand()));
                }
                else
                {
                    ma = new MInventoryLineMA(INVLine,
                                              storage.GetM_AttributeSetInstance_ID(), storage.GetQtyOnHand());
                }
                if (!ma.Save())
                {
                    ;
                }
                sum = Decimal.Add(sum, storage.GetQtyOnHand());
            }
            if (updateQtyBooked && sum.CompareTo(GetQtyBook()) != 0)
            {
                log.Warning("QtyBook=" + GetQtyBook() + " corrected to Sum of MA=" + sum);
                SetQtyBook(sum);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Update Inventory Lines With Material Allocation
        /// </summary>
        /// <returns>no update</returns>
        private int UpdateWithMA()
        {
            int no = 0;
            //
            String sql = "SELECT * FROM M_InventoryLine WHERE M_Inventory_ID=@iid AND COALESCE(M_AttributeSetInstance_ID,0)=0 ";

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@iid", _m_Inventory_ID);
                DataSet ds = DataBase.DB.ExecuteDataset(sql, param, null);
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    MInventoryLine   il       = new MInventoryLine(GetCtx(), dr, Get_TrxName());
                    Decimal          onHand   = Env.ZERO;
                    MStorage[]       storages = MStorage.GetAll(GetCtx(), il.GetM_Product_ID(), il.GetM_Locator_ID(), Get_TrxName());
                    MInventoryLineMA ma       = null;
                    for (int i = 0; i < storages.Length; i++)
                    {
                        MStorage storage = storages[i];
                        if (Env.Signum(storage.GetQtyOnHand()) == 0)
                        {
                            continue;
                        }
                        onHand = Decimal.Add(onHand, storage.GetQtyOnHand());
                        //	No ASI
                        if (storage.GetM_AttributeSetInstance_ID() == 0 &&
                            storages.Length == 1)
                        {
                            continue;
                        }
                        //	Save ASI
                        ma = new MInventoryLineMA(il,
                                                  storage.GetM_AttributeSetInstance_ID(), storage.GetQtyOnHand());
                        if (!ma.Save())
                        {
                            ;
                        }
                    }
                    il.SetQtyBook(onHand);
                    il.SetQtyCount(onHand);
                    if (il.Save())
                    {
                        no++;
                    }
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
            }
            //
            log.Info("#" + no);
            return(no);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get Storage Sources
        /// </summary>
        /// <param name="M_Product_ID">product</param>
        /// <param name="M_Locator_ID">locator</param>
        /// <returns>sources</returns>
        private MStorage[] GetSources(int M_Product_ID, int M_Locator_ID)
        {
            List <MStorage> list = new List <MStorage>();
            String          sql  = "SELECT * "
                                   + "FROM M_Storage s "
                                   + "WHERE QtyOnHand > 0"
                                   + " AND M_Product_ID=" + M_Product_ID
                                   //	Empty ASI
                                   + " AND (M_AttributeSetInstance_ID=0"
                                   + " OR EXISTS (SELECT * FROM M_AttributeSetInstance asi "
                                   + "WHERE s.M_AttributeSetInstance_ID=asi.M_AttributeSetInstance_ID"
                                   + " AND asi.Description IS NULL) )"
                                   //	Stock in same Warehouse
                                   + " AND EXISTS (SELECT * FROM M_Locator sl, M_Locator x "
                                   + "WHERE s.M_Locator_ID=sl.M_Locator_ID"
                                   + " AND x.M_Locator_ID=" + M_Locator_ID
                                   + " AND sl.M_Warehouse_ID=x.M_Warehouse_ID) "
                                   + "ORDER BY M_AttributeSetInstance_ID";
            DataTable   dt  = null;
            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, Get_Trx());

                dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MStorage(GetCtx(), dr, Get_Trx()));
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
                if (idr != null)
                {
                    idr.Close();
                }
            }

            MStorage[] retValue = new MStorage[list.Count];
            retValue = list.ToArray();
            return(retValue);
        }
Exemplo n.º 9
0
        /// <summary>
        /// GetQtyAvailable
        /// </summary>
        /// <param name="fields"></param>
        /// <returns></returns>
        public Decimal?GetQtyAvailable(Ctx ctx, string fields)
        {
            string[] paramValue = fields.Split(',');

            //Assign parameter value
            int M_Warehouse_ID            = Util.GetValueOfInt(paramValue[0].ToString());
            int M_Product_ID              = Util.GetValueOfInt(paramValue[1].ToString());
            int M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[2].ToString());

            //End Assign parameter value

            return(MStorage.GetQtyAvailable(M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, null));
        }
Exemplo n.º 10
0
        /**
         *  Before Delete
         *	@return true if it can be deleted
         */
        protected override bool BeforeDelete()
        {
            //	Check Storage
            if (IsStocked() || PRODUCTTYPE_Item.Equals(GetProductType()))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal    OnHand   = Env.ZERO;
                Decimal    Ordered  = Env.ZERO;
                Decimal    Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand   = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered  = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                {
                    errMsg = "@QtyOnHand@ = " + OnHand;
                }
                if (Env.Signum(Ordered) != 0)
                {
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                }
                if (Env.Signum(Reserved) != 0)
                {
                    errMsg += " - @QtyReserved@" + Reserved;
                }
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return(false);
                }
            }
            //	delete costing
            MProductCosting[] costings = MProductCosting.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
            for (int i = 0; i < costings.Length; i++)
            {
                costings[i].Delete(true, Get_TrxName());
            }
            string sql = "DELETE FROM M_Cost WHERE M_Product_ID = " + Get_ID();
            int    no  = DB.ExecuteQuery(sql, null, Get_TrxName());

            if (no < 0)
            {
                return(false);
            }
            return(Delete_Accounting("M_Product_Acct"));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create storage for qty types that don't exist and return specified qty type
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Locator_ID"></param>
        /// <param name="M_Product_ID"></param>
        /// <param name="M_AttributeSetInstance_ID"></param>
        /// <param name="trx"></param>
        /// <returns></returns>
        public static Storage.Record GetCreateRecord(Ctx ctx, int M_Locator_ID,
                                                     int M_Product_ID, int M_AttributeSetInstance_ID, Trx trx)
        {
            List <MStorage> details = new List <MStorage>();

            // create storage for all qty types
            foreach (var qtyType in X_Ref_Quantity_Type.Get())
            {
                MStorage detail = MStorage.GetCreate(ctx, M_Locator_ID, M_Product_ID,
                                                     M_AttributeSetInstance_ID, trx);//M_AttributeSetInstance_ID, qtyType, trx);
                detail.Save(trx);
                details.Add(detail);
            }
            return(new Storage.Record(details));
        }
Exemplo n.º 12
0
            public Record(Ctx ctx, int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID,
                          List <String> types, Trx trx)
            {
                if ((types == null) || types.Count < 1)
                {
                    throw new Exception("Quantity types must not be null or empty");
                }
                List <MStorage> storages = MStorage.GetMultipleForUpdate(ctx, M_Locator_ID, M_Product_ID, M_AttributeSetInstance_ID, types, trx);

                foreach (MStorage storage in storages)
                {
                    //storageMap.put(X_Ref_Quantity_Type.getEnum(storage.getQtyType()), storage);
                    storageMap[X_Ref_Quantity_Type.GetEnum(storage.GetQtyType())] = storage;
                    refDetail = storage;
                }
            }
        /**
         * verifyQuantity - checks that the warehouse specified in the work order transaction
         * has sufficient quantity of the product
         * @param product
         * @param wot
         * @param qty
         * @param asiID
         * @return error message if any, else Quantity Available
         */
        private String VerifyQuantity(VAdvantage.Model.MProduct product, ViennaAdvantage.Model.MVAMFGMWrkOdrTransaction wot, Decimal qty, int asiID)
        {
            if (product.IsStocked())
            {
                ViennaAdvantage.Model.MVAMFGMWorkOrder wo = new ViennaAdvantage.Model.MVAMFGMWorkOrder(wot.GetCtx(), wot.GetVAMFG_M_WorkOrder_ID(), wot.Get_TrxName());
                int M_Warehouse_ID = wo.GetM_Warehouse_ID();

                //logic change by Raghu
                //Decimal available = ViennaAdvantage.Model.Storage.GetQtyAvailable
                //(M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);

                // during creation of production execution line, reserverd qty to be checked or not
                Decimal?available = 0.0M;
                if (VAdvantage.Utility.Util.GetValueOfString(wot.GetConsiderReservedQty()) == "N")
                {
                    try
                    {
                        available = MStorage.GetQtyAvailableWithoutReserved
                                        (M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);
                    }
                    catch
                    {
                        return(Msg.GetMsg(wot.GetCtx(), "PleaseUpdateVAFramework"));
                    }
                }
                else
                {
                    available = MStorage.GetQtyAvailable
                                    (M_Warehouse_ID, product.GetM_Product_ID(), asiID, null);
                }

                if (available == null)
                {
                    available = Env.ZERO;
                }
                if (Env.Signum(available.Value) == 0)
                {
                    return(Msg.GetMsg(wot.GetCtx(), "NoQtyAvailable", "0"));
                }
                else if (available.Value.CompareTo(qty) < 0)
                {
                    return(Msg.GetMsg(wot.GetCtx(), "InsufficientQtyAvailable", available.ToString()));
                }
            }
            return(Msg.GetMsg(wot.GetCtx(), "QtyAvailable"));
        } // verifyQuantity
Exemplo n.º 14
0
        /// <summary>
        /// Create storage for qty types that don't exist and return specified qty type
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Locator_ID"></param>
        /// <param name="M_Product_ID"></param>
        /// <param name="M_AttributeSetInstance_ID"></param>
        /// <param name="qtyTypeToGet"></param>
        /// <param name="trx"></param>
        /// <returns></returns>
        public static MStorage GetCreateDetails(Ctx ctx, int M_Locator_ID,
                                                int M_Product_ID, int M_AttributeSetInstance_ID, String qtyTypeToGet, Trx trx)
        {
            MStorage detailToGet = null;

            // create storage for all qty types
            foreach (var qtyType in X_Ref_Quantity_Type.Get())
            {
                MStorage detail = MStorage.GetCreate(ctx, M_Locator_ID, M_Product_ID,
                                                     M_AttributeSetInstance_ID, trx);// M_AttributeSetInstance_ID, qtyType, trx);
                detail.Save(trx);
                if (qtyType == qtyTypeToGet)
                {
                    detailToGet = detail;
                }
            }
            return(detailToGet);
        }
Exemplo n.º 15
0
        public JsonResult GetQtyInfo(string fields)
        {
            string retError = "";
            string retJSON  = "";

            if (Session["ctx"] != null)
            {
                VAdvantage.Utility.Ctx ctx = Session["ctx"] as Ctx;
                string[] paramValue = fields.Split(',');
                int      M_Product_ID, M_Warehouse_ID, M_AttributeSetInstance_ID, C_OrderLine_ID;

                //Assign parameter value
                M_Product_ID              = Util.GetValueOfInt(paramValue[0].ToString());
                M_Warehouse_ID            = Util.GetValueOfInt(paramValue[1].ToString());
                M_AttributeSetInstance_ID = Util.GetValueOfInt(paramValue[2].ToString());
                C_OrderLine_ID            = Util.GetValueOfInt(paramValue[3].ToString());

                //End Assign parameter value
                //var QtyOrdered = Utility.Util.getValueOfDecimal(mTab.getValue("QtyOrdered"));
                //var M_Warehouse_ID = ctx.getContextAsInt(WindowNo, "M_Warehouse_ID");
                //var M_AttributeSetInstance_ID = ctx.getContextAsInt(WindowNo, "M_AttributeSetInstance_ID");
                Decimal?available = MStorage.GetQtyAvailable(M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID, null);

                Decimal notReserved = MOrderLine.GetNotReserved(ctx,
                                                                M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
                                                                C_OrderLine_ID);

                List <Decimal?> retVal = new List <Decimal?>();

                retVal.Add(available);

                retVal.Add(notReserved);


                retJSON = JsonConvert.SerializeObject(retVal);
            }
            else
            {
                retError = "Session Expired";
            }
            return(Json(new { result = retJSON, error = retError }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 16
0
            /// <summary>
            /// Gets a storage detail of specificied qty type
            /// </summary>
            /// <param name="qtyType">Quantity type to get</param>
            /// <param name="toCreate">if true, create detail if not found</param>
            /// <returns>storage detail for the quantity type</returns>
            public MStorage GetDetail(String qtyType, Boolean toCreate)
            {
                MStorage detail = storageMap[qtyType];

                if (detail == null)
                {
                    detail = MStorage.GetForRead(refDetail.GetCtx(), refDetail.GetM_Locator_ID(),
                                                 refDetail.GetM_Product_ID(), refDetail.GetM_AttributeSetInstance_ID(),
                                                 qtyType, refDetail.Get_Trx());

                    if (detail == null && toCreate)
                    {
                        detail = MStorage.GetCreate(refDetail.GetCtx(), refDetail.GetM_Locator_ID(),
                                                    refDetail.GetM_Product_ID(), refDetail.GetM_AttributeSetInstance_ID(),
                                                    refDetail.Get_Trx());// qtyType, refDetail.Get_Trx());
                    }
                    storageMap[qtyType] = detail;
                }
                return(detail);
            }
Exemplo n.º 17
0
 private void UpdateStorage(int M_Product_ID, int M_Locator_ID, int M_AttributeInstance_ID, decimal QtyOnHand)
 {
     storage = MStorage.Get(GetCtx(), M_Locator_ID,
                            M_Product_ID, M_AttributeInstance_ID, Get_Trx());
     if (storage == null)
     {
         storage = MStorage.GetCreate(GetCtx(), M_Locator_ID,
                                      M_Product_ID, 0, Get_Trx());
     }
     storage.SetQtyOnHand(QtyOnHand);
     if (!storage.Save())
     {
         log.Info("Onhand Quantity Not Updated at Storage");
         Rollback();
     }
     else
     {
         log.Info("Onhand Quantity  Updated at Storage");
         Commit();
     }
 }
Exemplo n.º 18
0
        /// <summary>
        /// Get Storages
        /// </summary>
        /// <param name="M_Warehouse_ID">Ware House ID</param>
        /// <param name="M_Product_ID">Product id</param>
        /// <param name="M_AttributeSetInstance_ID">Attribute Set instance</param>
        /// <param name="M_AttributeSet_ID">attribute id</param>
        /// <param name="allAttributeInstances">all atribute</param>
        /// <param name="minGuaranteeDate"></param>
        /// <param name="FiFo"></param>
        /// <returns>storages</returns>
        private MStorage[] GetStorages(int M_Warehouse_ID,
                                       int M_Product_ID, int M_AttributeSetInstance_ID, int M_AttributeSet_ID,
                                       bool allAttributeInstances, DateTime?minGuaranteeDate,
                                       bool FiFo)
        {
            _lastPP = new SParameter(M_Warehouse_ID,
                                     M_Product_ID, M_AttributeSetInstance_ID, M_AttributeSet_ID,
                                     allAttributeInstances, minGuaranteeDate, FiFo);
            //m_lastStorages = m_map.get(m_lastPP);
            if (_map.ContainsKey(_lastPP))
            {
                _lastStorages = _map[_lastPP];
            }
            else
            {
                _lastStorages = null;
            }

            if (_lastStorages == null)
            {
                _lastStorages = MStorage.GetWarehouse(GetCtx(),
                                                      M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,
                                                      M_AttributeSet_ID, allAttributeInstances, minGuaranteeDate,
                                                      FiFo, Get_TrxName());

                try
                {
                    _map.Add(_lastPP, _lastStorages);
                }
                catch (Exception exp)
                {
                    //// MessageBox.Show(exp.ToString());
                    log.Severe(exp.ToString());
                }
            }

            return(_lastStorages);
        }
Exemplo n.º 19
0
        protected override bool AfterSave(bool newRecord, bool success)
        {
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && GetM_RequisitionLine_ID() != 0 && GetConfirmedQty() == 0)
                {
                    MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null);
                    requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetMovementQty() - qtyReserved));
                    if (!requisition.Save())
                    {
                        return(false);
                    }
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null);
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null);
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + (GetMovementQty() - qtyReserved));
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }
                //vikas 11/21/2014
                _mvlNewAttId = GetM_AttributeSetInstance_ID();
                if (_mvlOldAttId != _mvlNewAttId && !newRecord)
                {
                    //  Set QtyReserved On Storage Correspng to New attributesetinstc_id
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null);
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null);
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + qtyReserved);
                    if (!storage.Save())
                    {
                        return(false);
                    }

                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, null);
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null);
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved);
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }//vikas

                if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC")
                {
                    MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null);
                    requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetMovementQty());
                    if (!requisition.Save())
                    {
                        return(false);
                    }
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), null);
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), 0, null);
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + GetMovementQty());
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
        protected override bool AfterSave(bool newRecord, bool success)
        {
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                // JID_0657: Requistion is without ASI but on move selected the ASI system is minus the Reserved qty from ASI field but not removing the reserved qty without ASI
                _mvlNewAttId = GetM_AttributeSetInstance_ID();
                if (_mvlOldAttId != _mvlNewAttId && !newRecord && GetM_RequisitionLine_ID() != 0)
                {
                    //  Set QtyReserved On Storage Correspng to New attributesetinstc_id
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());      // Trx used to handle query stuck problem
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());     // Trx used to handle query stuck problem
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + qtyReserved);
                    if (!storage.Save())
                    {
                        return(false);
                    }

                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, Get_Trx());            // Trx used to handle query stuck problem
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), _mvlOldAttId, Get_Trx());             // Trx used to handle query stuck problem
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() - qtyReserved);
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }//vikas

                if (!newRecord && GetM_RequisitionLine_ID() != 0 && GetConfirmedQty() == 0 && String.IsNullOrEmpty(GetDescription()))
                {
                    MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
                    requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetMovementQty() - qtyReserved));
                    if (!requisition.Save())
                    {
                        return(false);
                    }
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());      // Trx used to handle query stuck problem
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());             // Trx used to handle query stuck problem
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + (GetMovementQty() - qtyReserved));
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }

                if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC")
                {
                    MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());            // Trx used to handle query stuck problem
                    requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetMovementQty());
                    if (!requisition.Save())
                    {
                        return(false);
                    }
                    storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());      // Trx used to handle query stuck problem
                    if (storage == null)
                    {
                        storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());         // Trx used to handle query stuck problem
                    }
                    storage.SetQtyReserved(storage.GetQtyReserved() + GetMovementQty());
                    if (!storage.Save())
                    {
                        return(false);
                    }
                }
            }

            // 17-April-2017 Amit
            // If Provision already occured against any product then need to give message to client that
            //Inventory Provision on the selected Product/s is/are done with the Specific Organization.
            if (Env.IsModuleInstalled("VA024_"))
            {
                // checking are we moving product from one warehouse to other warehouse
                if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT CASE WHEN ((SELECT CASE WHEN o.IsLegalEntity = 'Y' THEN w.AD_Org_ID
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o.LegalEntityOrg ) END
                 FROM m_warehouse w INNER JOIN ad_org o ON o.AD_Org_ID = w.AD_Org_ID WHERE w.m_warehouse_id = m.DTD001_MWarehouseSource_ID)) =
                 (SELECT  CASE WHEN o2.IsLegalEntity = 'Y' THEN w2.AD_Org_ID 
                 ELSE (SELECT AD_Org_ID FROM AD_Org WHERE Ad_Org_id = o2.LegalEntityOrg) END
                 FROM m_warehouse w2 INNER JOIN ad_org o2 ON o2.AD_Org_ID = w2.AD_Org_ID WHERE M_Warehouse_ID = m.M_Warehouse_ID )
                 THEN 0 ELSE (SELECT ad_org_id FROM m_warehouse WHERE M_Warehouse_ID = m.M_Warehouse_ID ) END AS result FROM m_movement m WHERE m_movement_id = " + GetM_Movement_ID(), null, Get_Trx())) > 0)
                {
                    //checking product is provisioned or not
                    if (Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT COUNT(*) FROM va024_t_obsoleteinventory WHERE ISACTIVE = 'Y' AND  AD_Org_ID = " + GetAD_Org_ID() +
                                                            @" AND M_Product_ID = " + GetM_Product_ID() + "  AND NVL(M_AttributeSetInstance_ID , 0) = " + Util.GetValueOfInt(GetM_AttributeSetInstance_ID()))) > 0)
                    {
                        log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "VA024_AlreadyProvisionConvey"));
                    }
                }
            }
            return(true);
        }
        /**
         * 	Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            // Set Search Key from Serial No defined on Product Category.
            MProductCategory pc = new MProductCategory(GetCtx(), GetM_Product_Category_ID(), Get_TrxName());
            if (newRecord && pc.Get_ColumnIndex("M_SerNoCtl_ID") >= 0 && pc.GetM_SerNoCtl_ID() > 0)
            {
                string name = "";
                MSerNoCtl ctl = new MSerNoCtl(GetCtx(), pc.GetM_SerNoCtl_ID(), Get_TrxName());

                // if Organization level check box is true on Serila No Control, then Get Current next from Serila No tab.
                if (ctl.Get_ColumnIndex("IsOrgLevelSequence") >= 0)
                {
                    name = ctl.CreateDefiniteSerNo(this);
                }
                else
                {
                    name = ctl.CreateSerNo();
                }
                SetValue(name);
            }

            //	Check Storage
            if (!newRecord && 	//
                ((Is_ValueChanged("IsActive") && !IsActive())		//	now not active
                || (Is_ValueChanged("IsStocked") && !IsStocked())	//	now not stocked
                || (Is_ValueChanged("ProductType") 					//	from Item
                    && PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType")))))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal OnHand = Env.ZERO;
                Decimal Ordered = Env.ZERO;
                Decimal Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                    errMsg = "@QtyOnHand@ = " + OnHand;
                if (Env.Signum(Ordered) != 0)
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                if (Env.Signum(Reserved) != 0)
                    errMsg += " - @QtyReserved@" + Reserved;
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return false;
                }
            }	//	storage

            //	Reset Stocked if not Item
            if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType()))
                SetIsStocked(false);

            //	UOM reset
            if (_precision != null && Is_ValueChanged("C_UOM_ID"))
                _precision = null;
            if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100)
            {
                if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID"))
                {
                    string uqry = "SELECT SUM(cc) as count FROM  (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @"  UNION
                SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() +
                    " UNION  SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ") t";
                    int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    if (no == 0 || IsBOM())
                    {
                        uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID();
                        no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    }
                    if (no > 0)
                    {
                        log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System."));
                        return false;
                    }
                }
            }
            if (newRecord)
            {
                //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));

                int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                if (manu_ID > 0)
                {
                    _log.SaveError("UPCUnique", "");
                    return false;
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(GetUPC()) &&
                   Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC())
                {
                    //string sql = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                    //int manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                    //if (manu_ID != 0 && manu_ID != GetM_Product_ID())

                    int manu_ID = UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                    if (manu_ID > 0)
                    {
                        _log.SaveError("UPCUnique", "");
                        return false;
                    }
                }
            }
            return true;
        }
Exemplo n.º 22
0
 /**
  *  Close Document.
  *  Cancel not delivered Qunatities
  *  @return true if success
  */
 public bool CloseIt()
 {
     try
     {
         log.Info("closeIt - " + ToString());
         //	Close Not delivered Qty
         MRequisitionLine[] lines      = GetLines();
         Decimal            totalLines = Env.ZERO;
         for (int i = 0; i < lines.Length; i++)
         {
             MRequisitionLine line     = lines[i];
             Decimal          finalQty = line.GetQty();
             if (line.GetC_OrderLine_ID() == 0)
             {
                 finalQty = Env.ZERO;
             }
             else
             {
                 MOrderLine ol = new MOrderLine(GetCtx(), line.GetC_OrderLine_ID(), Get_TrxName());
                 finalQty = ol.GetQtyOrdered();
             }
             Tuple <String, String, String> mInfo = null;
             if (Env.HasModulePrefix("DTD001_", out mInfo))
             {
                 int quant = Util.GetValueOfInt(line.GetQty() - line.GetDTD001_DeliveredQty());
                 //Update storage requisition reserved qty
                 if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
                 {
                     if (GetDocAction() != "VO" && GetDocStatus() != "DR")
                     {
                         if (quant > 0)
                         {
                             int loc_id = GetLocation(GetM_Warehouse_ID());
                             storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                             if (storage == null)
                             {
                                 storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                             }
                             storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                             storage.Save();
                         }
                     }
                 }
                 else if (GetDocAction() != "VO" && GetDocStatus() != "DR")
                 {
                     if (quant > 0)
                     {
                         int loc_id = GetLocation(GetM_Warehouse_ID());
                         storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null);
                         if (storage == null)
                         {
                             storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null);
                         }
                         storage.SetDTD001_QtyReserved((Decimal.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                         storage.Save();
                     }
                 }
             }
             //	final qty is not line qty
             if (finalQty.CompareTo(line.GetQty()) != 0)
             {
                 String description = line.GetDescription();
                 if (description == null)
                 {
                     description = "";
                 }
                 description += " [" + line.GetQty() + "]";
                 line.SetDescription(description);
                 // Amit 9-feb-2015
                 // line.SetQty(finalQty);
                 //Amit
                 line.SetLineNetAmt();
                 line.Save();
             }
             //get Grand Total or SubTotal
             totalLines = Decimal.Add(totalLines, line.GetLineNetAmt());
         }
         if (totalLines.CompareTo(GetTotalLines()) != 0)
         {
             SetTotalLines(totalLines);
             Save();
         }
     }
     catch (Exception ex)
     {
         // MessageBox.Show("MRequisition--CloseIt");
         log.Severe(ex.ToString());
     }
     return(true);
 }
Exemplo n.º 23
0
        /**
         *  Complete Document
         *  @return new status (Complete, In Progress, Invalid, Waiting ..)
         */
        public String CompleteIt()
        {
            try
            {
                //	Re-Check
                if (!_justPrepared)
                {
                    String status = PrepareIt();
                    if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                    {
                        return(status);
                    }
                }
                //	Implicit Approval
                if (!IsApproved())
                {
                    ApproveIt();
                }
                log.Info(ToString());

                //	User Validation
                String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE);
                if (valid != null)
                {
                    _processMsg = valid;
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                SetProcessed(true);
                SetDocAction(DocActionVariables.ACTION_CLOSE);
                /**************************************************************************************************************/
                Tuple <String, String, String> mInfo = null;
                if (Env.HasModulePrefix("DTD001_", out mInfo))
                {
                    MRequisitionLine[] lines = GetLines();
                    for (int i = 0; i < lines.Length; i++)
                    {
                        MRequisitionLine line = lines[i];
                        int loc_id            = GetLocation(GetM_Warehouse_ID());
                        if (loc_id == 0)
                        {
                            //return Msg.GetMsg(GetCtx(),"MMPM_DefineLocator");
                            _processMsg = "Define Locator For That Warehouse";
                            return(DocActionVariables.STATUS_INVALID);
                        }
                        if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
                        {
                            storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                            if (storage == null)
                            {
                                storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), null);
                            }
                            storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty())));
                            if (!storage.Save())
                            {
                                log.Info("Requisition Reserverd Quantity not saved at storage at locator " + loc_id + " and product is " + line.GetM_Product_ID());
                            }
                        }
                        else
                        {
                            storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), 0, null);
                            if (storage == null)
                            {
                                //MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, 0, 0, line.GetQty(), null);
                                MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, (Decimal)0, (Decimal)0, (Decimal)0, line.GetQty(), null);
                            }
                            else
                            {
                                storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty())));
                                storage.Save();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("MRequisition--CompleteIt");
                log.Severe(ex.ToString());
            }
            return(DocActionVariables.STATUS_COMPLETED);
        }
Exemplo n.º 24
0
            public Decimal GetQty(String qtyType)
            {
                MStorage detail = storageMap[qtyType];

                return((detail == null) ? Env.ZERO : detail.GetQty());
            }
        /// <summary>
        /// After Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <param name="success">success</param>
        /// <returns>true</returns>
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            //	Create MA
            if (newRecord && success &&
                _isManualEntry && GetM_AttributeSetInstance_ID() == 0)
            {
                CreateMA(true);
            }

            if (!IsInternalUse())
            {
                MInventory inv = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
                inv.SetIsAdjusted(false);
                if (!inv.Save())
                {
                }
            }
            else                // SI_0682_1 Need to update the reserved qty on requisition line by internal use line save aslo and should work as work in inventory move.
            {
                if (Env.IsModuleInstalled("DTD001_"))
                {
                    if (!newRecord && GetM_RequisitionLine_ID() != 0)
                    {
                        MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());
                        requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + (GetQtyInternalUse() - qtyReserved));
                        if (!requisition.Save())
                        {
                            return(false);
                        }
                        storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        if (storage == null)
                        {
                            storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        }
                        storage.SetQtyReserved(storage.GetQtyReserved() + (GetQtyInternalUse() - qtyReserved));
                        if (!storage.Save())
                        {
                            return(false);
                        }
                    }

                    if (newRecord && GetM_RequisitionLine_ID() != 0 && GetDescription() != "RC")
                    {
                        MRequisitionLine requisition = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());
                        requisition.SetDTD001_ReservedQty(requisition.GetDTD001_ReservedQty() + GetQtyInternalUse());
                        if (!requisition.Save())
                        {
                            return(false);
                        }
                        storage = MStorage.Get(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        if (storage == null)
                        {
                            storage = MStorage.GetCreate(GetCtx(), GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(), Get_Trx());
                        }
                        storage.SetQtyReserved(storage.GetQtyReserved() + GetQtyInternalUse());
                        if (!storage.Save())
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Get all Storages for Product with ASI
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="M_Product_ID">product</param>
        /// <param name="M_Locator_ID">locator</param>
        /// <param name="FiFo">first in-first-out</param>
        /// <param name="qtyToDeliver">the quantity to deliver, or null if no limit</param>
        /// <param name="trx">transaction</param>
        /// <returns>existing or null</returns>
        public static List <Storage.Record> GetAllWithASI(Ctx ctx, int M_Product_ID, int M_Locator_ID,
                                                          Boolean FiFo, Decimal qtyToDeliver, Trx trx)
        {
            List <MStorage>       details  = new List <MStorage>();
            List <Storage.Record> storages = new List <Storage.Record>();
            //String sql = "select s.* "
            //    + " from M_STORAGEDETAIL  s "
            //    + " where s.M_PRODUCT_ID =" + M_Product_ID + "  and s.M_LOCATOR_ID =" + M_Locator_ID
            //    + " and s.QTYTYPE in ('H','A','D') "
            //    + " and s.M_AttributeSetInstance_ID > 0 "
            //    + " and exists (select 1 from M_STORAGEDETAIL t "
            //                    + " where t.QTYTYPE = 'H' "
            //                    + " and t.QTY <> 0 "
            //                    + " and s.AD_CLIENT_ID = t.AD_CLIENT_ID "
            //                    + " and s.AD_ORG_ID    = t.AD_ORG_ID "
            //                    + " and s.M_PRODUCT_ID = t.M_PRODUCT_ID "
            //                    + " and s.M_LOCATOR_ID = t.M_LOCATOR_ID  "
            //                    + " and s.M_AttributeSetInstance_ID = t.M_AttributeSetInstance_ID ) "
            //    + " order by s.M_ATTRIBUTESETINSTANCE_ID ";
            String sql = " SELECT s.*" +
                         " FROM M_STORAGE s" +
                         " where s.M_PRODUCT_ID =" + M_Product_ID + "  and s.M_LOCATOR_ID =" + M_Locator_ID +
                         " AND s.M_AttributeSetInstance_ID > 0 " +
                         " AND EXISTS  (SELECT 1     FROM M_STORAGE t WHERE t.qtyonhand <> 0" +
                         " AND s.AD_CLIENT_ID              = t.AD_CLIENT_ID" +
                         " AND s.AD_ORG_ID                 = t.AD_ORG_ID" +
                         " AND s.M_PRODUCT_ID              = t.M_PRODUCT_ID" +
                         " AND s.M_LOCATOR_ID              = t.M_LOCATOR_ID" +
                         " AND s.M_AttributeSetInstance_ID = t.M_AttributeSetInstance_ID" +
                         " )ORDER BY s.M_ATTRIBUTESETINSTANCE_ID";

            if (!FiFo)
            {
                sql += " DESC ";
            }
            if (DB.IsOracle())
            {
                //sql += " FOR UPDATE of s.QTY ";
                sql += " FOR UPDATE of s.qtyonhand ";//for Storage test
            }
            else
            {
                sql += " FOR UPDATE of s";
            }

            IDataReader idr = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, trx);
                DataTable dt = new DataTable();
                dt.Load(idr);
                idr.Close();
                int prevASI = -1;
                foreach (DataRow dr in dt.Rows)
                {
                    //MStorage detail = new MStorage(ctx, dr, trx);
                    //if (prevASI == -1)
                    //{
                    //    prevASI = detail.GetM_AttributeSetInstance_ID();
                    //}

                    //if (detail.GetM_AttributeSetInstance_ID() != prevASI)
                    //{
                    //    Storage.Record record = new Storage.Record(details);
                    //    storages.Add(record);
                    //    details.Clear();
                    //    prevASI = detail.GetM_AttributeSetInstance_ID();
                    //}
                    //details.Add(detail);
                    MStorage detail = new MStorage(ctx, dr, trx);
                    if (prevASI == -1)
                    {
                        prevASI = detail.GetM_AttributeSetInstance_ID();
                    }

                    if (detail.GetM_AttributeSetInstance_ID() != prevASI)
                    {
                        Storage.Record record = new Storage.Record(details);
                        storages.Add(record);
                        details.Clear();
                        prevASI = detail.GetM_AttributeSetInstance_ID();
                    }
                    details.Add(detail);
                }
                if (details.Count > 0)
                {
                    Storage.Record record = new Storage.Record(details);
                    storages.Add(record);
                    details.Clear();
                }
            }
            catch (Exception ex)
            {
                _log.Log(Level.SEVERE, sql, ex);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
            }

            List <Storage.Record> availableStorages = new List <Storage.Record>();

            foreach (Storage.Record storage in storages)
            {
                if (storage.GetAvailableQty().CompareTo(Env.ZERO) <= 0)
                {
                    continue;
                }
                availableStorages.Add(storage);
                // if (qtyToDeliver != null)
                {
                    qtyToDeliver = Decimal.Subtract(qtyToDeliver, storage.GetAvailableQty());
                    if (qtyToDeliver.CompareTo(Env.ZERO) <= 0)
                    {
                        break;
                    }
                }
            }
            return(availableStorages);
        }
Exemplo n.º 27
0
        /**
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            //	Check Storage
            if (!newRecord &&                                      //
                ((Is_ValueChanged("IsActive") && !IsActive()) ||   //	now not active
                 (Is_ValueChanged("IsStocked") && !IsStocked()) || //	now not stocked
                 (Is_ValueChanged("ProductType") &&                //	from Item
                  PRODUCTTYPE_Item.Equals(Get_ValueOld("ProductType")))))
            {
                MStorage[] storages = MStorage.GetOfProduct(GetCtx(), Get_ID(), Get_TrxName());
                Decimal    OnHand   = Env.ZERO;
                Decimal    Ordered  = Env.ZERO;
                Decimal    Reserved = Env.ZERO;
                for (int i = 0; i < storages.Length; i++)
                {
                    OnHand   = Decimal.Add(OnHand, (storages[i].GetQtyOnHand()));
                    Ordered  = Decimal.Add(OnHand, (storages[i].GetQtyOrdered()));
                    Reserved = Decimal.Add(OnHand, (storages[i].GetQtyReserved()));
                }
                String errMsg = "";
                if (Env.Signum(OnHand) != 0)
                {
                    errMsg = "@QtyOnHand@ = " + OnHand;
                }
                if (Env.Signum(Ordered) != 0)
                {
                    errMsg += " - @QtyOrdered@ = " + Ordered;
                }
                if (Env.Signum(Reserved) != 0)
                {
                    errMsg += " - @QtyReserved@" + Reserved;
                }
                if (errMsg.Length > 0)
                {
                    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), errMsg));
                    return(false);
                }
            }   //	storage

            //	Reset Stocked if not Item
            if (IsStocked() && !PRODUCTTYPE_Item.Equals(GetProductType()))
            {
                SetIsStocked(false);
            }

            //	UOM reset
            if (_precision != null && Is_ValueChanged("C_UOM_ID"))
            {
                _precision = null;
            }
            if (Util.GetValueOfInt(Env.GetCtx().GetContext("#AD_User_ID")) != 100)
            {
                if (Is_ValueChanged("C_UOM_ID") || Is_ValueChanged("M_AttributeSet_ID"))
                {
                    string uqry = "SELECT SUM(cc) as count FROM  (SELECT COUNT(*) AS cc FROM M_MovementLine WHERE M_Product_ID = " + GetM_Product_ID() + @"  UNION
                SELECT COUNT(*) AS cc FROM M_InventoryLine WHERE M_Product_ID = " + GetM_Product_ID() + " UNION SELECT COUNT(*) AS cc FROM C_OrderLine WHERE M_Product_ID = " + GetM_Product_ID() +
                                  " UNION  SELECT COUNT(*) AS cc FROM M_InOutLine WHERE M_Product_ID = " + GetM_Product_ID() + ")";
                    int no = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    if (no == 0 || IsBOM())
                    {
                        uqry = "SELECT count(*) FROM M_ProductionPlan WHERE M_Product_ID = " + GetM_Product_ID();
                        no   = Util.GetValueOfInt(DB.ExecuteScalar(uqry));
                    }
                    if (no > 0)
                    {
                        log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "Could not Save Record. Transactions available in System."));
                        return(false);
                    }
                }
            }
            if (newRecord)
            {
                string sql     = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                int    manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                if (manu_ID > 0)
                {
                    _log.SaveError("UPC is Unique", "");
                    return(false);
                }
            }
            else
            {
                if (!String.IsNullOrEmpty(GetUPC()) &&
                    Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC())
                {
                    string sql     = "SELECT UPCUNIQUE('p','" + GetUPC() + "') as productID FROM Dual";
                    int    manu_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, null));
                    //if (manu_ID != 0 && manu_ID != GetM_Product_ID())
                    if (manu_ID > 0)
                    {
                        _log.SaveError("UPC is Unique", "");
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 28
0
 public static Boolean AddQtys(Ctx ctx, int M_Warehouse_ID,
                               int M_Locator_ID, int M_Product_ID, int M_AttributeSetInstance_ID,
                               int reservationAttributeSetInstance_ID, Decimal diffQtyOnHand,
                               Decimal diffQtyReserved, Decimal diffQtyOrdered,
                               Decimal diffQtyDedicated, Decimal diffQtyExpected,
                               Decimal diffQtyAllocated, Trx trx)
 {
     if (diffQtyOnHand.CompareTo(Env.ZERO) != 0)
     {
         if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
                           M_AttributeSetInstance_ID,
                           reservationAttributeSetInstance_ID, diffQtyOnHand, 0, 0
                           , trx))
         {
             return(false);
         }
     }
     if (diffQtyReserved.CompareTo(Env.ZERO) != 0)
     {
         if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
                           M_AttributeSetInstance_ID,
                           reservationAttributeSetInstance_ID, 0, diffQtyReserved, 0
                           , trx))
         {
             return(false);
         }
     }
     if (diffQtyOrdered.CompareTo(Env.ZERO) != 0)
     {
         if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
                           M_AttributeSetInstance_ID,
                           reservationAttributeSetInstance_ID, 0, 0, diffQtyOrdered,
                           trx))
         {
             return(false);
         }
     }
     if (diffQtyDedicated.CompareTo(Env.ZERO) != 0)
     {
         //if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
         //        M_AttributeSetInstance_ID,
         //        reservationAttributeSetInstance_ID, diffQtyDedicated,
         //        X_Ref_Quantity_Type.DEDICATED, trx))
         //    return false;
         MessageBox.Show("Storage-AddQtys-if (diffQtyDedicated != null && diffQtyDedicated.CompareTo(Env.ZERO) != 0)");
     }
     if (diffQtyAllocated.CompareTo(Env.ZERO) != 0)
     {
         //if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
         //        M_AttributeSetInstance_ID,
         //        reservationAttributeSetInstance_ID, diffQtyAllocated,
         //        X_Ref_Quantity_Type.ALLOCATED, trx))
         //    return false;
         MessageBox.Show("Storage-AddQtys-if (diffQtyAllocated != null && diffQtyAllocated.CompareTo(Env.ZERO) != 0)");
     }
     if (diffQtyExpected.CompareTo(Env.ZERO) != 0)
     {
         //if (!MStorage.Add(ctx, M_Warehouse_ID, M_Locator_ID, M_Product_ID,
         //        M_AttributeSetInstance_ID,
         //        reservationAttributeSetInstance_ID, diffQtyExpected,
         //        X_Ref_Quantity_Type.EXPECTED, trx))
         //    return false;
         MessageBox.Show("Storage-AddQtys- if (diffQtyExpected != null && diffQtyExpected.CompareTo(Env.ZERO) != 0)");
     }
     return(true);
 }
Exemplo n.º 29
0
        /// <summary>
        /// Complete Document
        /// </summary>
        /// <returns>new status (Complete, In Progress, Invalid, Waiting ..)</returns>
        public String CompleteIt()
        {
            //	Re-Check
            if (!_justPrepared)
            {
                String status = PrepareIt();
                if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                {
                    return(status);
                }
            }
            //	Implicit Approval
            if (!IsApproved())
            {
                ApproveIt();
            }
            log.Info("CompleteIt - " + ToString());
            //
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());

            MMovementLineConfirm[] lines = GetLines(false);
            for (int i = 0; i < lines.Length; i++)
            {
                MMovementLineConfirm confirm = lines[i];
                confirm.Set_TrxName(Get_TrxName());
                if (!confirm.ProcessLine())
                {
                    _processMsg = "ShipLine not saved - " + confirm;
                    return(DocActionVariables.STATUS_INVALID);
                }
                if (confirm.IsFullyConfirmed())
                {
                    confirm.SetProcessed(true);
                    confirm.Save(Get_TrxName());
                }
                else
                {
                    if (CreateDifferenceDoc(move, confirm))
                    {
                        confirm.SetProcessed(true);
                        confirm.Save(Get_TrxName());
                    }
                    else
                    {
                        log.Log(Level.SEVERE, "completeIt - Scrapped=" + confirm.GetScrappedQty()
                                + " - Difference=" + confirm.GetDifferenceQty());

                        _processMsg = "Differnce Doc not created";
                        return(DocActionVariables.STATUS_INVALID);
                    }
                }
            }   //	for all lines

            if (_inventoryInfo != null)
            {
                _processMsg = " @M_Inventory_ID@: " + _inventoryInfo;
                AddDescription(Msg.Translate(GetCtx(), "M_Inventory_ID")
                               + ": " + _inventoryInfo);
            }
            //Amit 21-nov-2014 (Reduce reserved quantity from requisition and warehouse distribution center)
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                MMovementLine    movementLine    = null;
                MRequisitionLine requisitionLine = null;
                MStorage         storage         = null;
                for (int i = 0; i < lines.Length; i++)
                {
                    MMovementLineConfirm confirm = lines[i];
                    if (confirm.GetDifferenceQty() > 0)
                    {
                        movementLine = new MMovementLine(GetCtx(), confirm.GetM_MovementLine_ID(), Get_Trx());
                        if (movementLine.GetM_RequisitionLine_ID() > 0)
                        {
                            requisitionLine = new MRequisitionLine(GetCtx(), movementLine.GetM_RequisitionLine_ID(), Get_Trx());
                            requisitionLine.SetDTD001_ReservedQty(decimal.Subtract(requisitionLine.GetDTD001_ReservedQty(), confirm.GetDifferenceQty()));
                            if (!requisitionLine.Save(Get_Trx()))
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_ReqNotUpdate");
                                // _processMsg = "Requisitionline not updated";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                            storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), movementLine.GetM_AttributeSetInstance_ID(), Get_Trx());
                            if (storage == null)
                            {
                                storage = MStorage.Get(GetCtx(), movementLine.GetM_Locator_ID(), movementLine.GetM_Product_ID(), 0, Get_Trx());
                            }
                            storage.SetQtyReserved(decimal.Subtract(storage.GetQtyReserved(), confirm.GetDifferenceQty()));
                            if (!storage.Save(Get_Trx()))
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "DTD001_StorageNotUpdate");
                                //_processMsg = "Storage From not updated (MA)";
                                return(DocActionVariables.STATUS_INVALID);
                            }
                        }
                    }
                }
            }
            //Amit
            SetProcessed(true);
            SetDocAction(DOCACTION_Close);
            return(DocActionVariables.STATUS_COMPLETED);
        }
        /**
         *  Complete Document
         *  @return new status (Complete, In Progress, Invalid, Waiting ..)
         */
        public String CompleteIt()
        {
            try
            {
                //	Re-Check
                if (!_justPrepared)
                {
                    String status = PrepareIt();
                    if (!DocActionVariables.STATUS_INPROGRESS.Equals(status))
                    {
                        return(status);
                    }
                }

                // JID_1290: Set the document number from completed document sequence after completed (if needed)
                SetCompletedDocumentNo();

                //	Implicit Approval
                if (!IsApproved())
                {
                    ApproveIt();
                }
                log.Info(ToString());

                //	User Validation
                String valid = ModelValidationEngine.Get().FireDocValidate(this, ModalValidatorVariables.DOCTIMING_AFTER_COMPLETE);
                if (valid != null)
                {
                    _processMsg = valid;
                    return(DocActionVariables.STATUS_INVALID);
                }
                //
                SetProcessed(true);
                SetDocAction(DocActionVariables.ACTION_CLOSE);
                /**************************************************************************************************************/
                // Check Column Name  new 6jan 0 vikas
                int _count = Util.GetValueOfInt(DB.ExecuteScalar(" SELECT Count(*) FROM AD_Column WHERE columnname = 'DTD001_SourceReserve' "));

                Tuple <String, String, String> mInfo = null;
                if (Env.HasModulePrefix("DTD001_", out mInfo))
                {
                    MRequisitionLine[] lines   = GetLines();
                    MProduct           product = null;
                    for (int i = 0; i < lines.Length; i++)
                    {
                        MRequisitionLine line = lines[i];
                        if (line.GetM_Product_ID() > 0)
                        {
                            product = MProduct.Get(GetCtx(), line.GetM_Product_ID());
                        }

                        int loc_id = GetLocation(GetM_Warehouse_ID());
                        //new 6jan 1
                        int Sourcewhloc_id = GetSwhLocation(GetDTD001_MWarehouseSource_ID());
                        if (Sourcewhloc_id == 0)
                        {                                                                  // JID_1098: done by Bharat on 31 Jan 2019, need to correct these messages
                            _processMsg = Msg.GetMsg(GetCtx(), "DTD001_DefineSrcLocator"); //"Define Locator For That SourceWarehouse";
                            return(DocActionVariables.STATUS_INVALID);
                        }
                        //End
                        if (loc_id == 0)
                        {
                            //return Msg.GetMsg(GetCtx(),"MMPM_DefineLocator");
                            _processMsg = Msg.GetMsg(GetCtx(), "DTD001_DefineLocator"); //"Define Locator For That Warehouse";
                            return(DocActionVariables.STATUS_INVALID);
                        }
                        if (line.Get_ColumnIndex("OrderLocator_ID") > 0)
                        {
                            line.SetOrderLocator_ID(loc_id);
                            line.SetReserveLocator_ID(Sourcewhloc_id);
                            if (!line.Save())
                            {
                                _processMsg = Msg.GetMsg(GetCtx(), "ReqLineNotSaved");
                                return(DocActionVariables.STATUS_INVALID);
                            }
                        }
                        //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
                        // SI_0686_2 :  storage should not update in case of product is other than item type.
                        if (Env.IsModuleInstalled("VA203_") && product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item)
                        {
                            storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                            if (storage == null)
                            {
                                storage = MStorage.GetCreate(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                            }
                            storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty())));
                            if (!storage.Save())
                            {
                                log.Info("Requisition Reserverd Quantity not saved at storage at locator " + loc_id + " and product is " + line.GetM_Product_ID());
                            }
                            ///new 6jan 2
                            if (_count > 0)
                            {
                                Swhstorage = MStorage.Get(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                if (Swhstorage == null)
                                {
                                    Swhstorage = MStorage.GetCreate(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                }
                                Swhstorage.SetDTD001_SourceReserve((Decimal.Add(Swhstorage.GetDTD001_SourceReserve(), (Decimal)line.GetQty())));
                                if (!Swhstorage.Save())
                                {
                                    log.Info("Requisition Reserverd Quantity not saved at storage at locator " + Sourcewhloc_id + " and product is " + line.GetM_Product_ID());
                                }
                            }
                            //End
                        }
                        else if (product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item)
                        {
                            // SI_0657: consider Attribute also
                            storage = MStorage.Get(GetCtx(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                            if (storage == null)
                            {
                                //MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), 0, 0, 0, 0, line.GetQty(), null);
                                MStorage.Add(GetCtx(), GetM_Warehouse_ID(), loc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.GetM_AttributeSetInstance_ID(), (Decimal)0, (Decimal)0, (Decimal)0, line.GetQty(), Get_Trx());
                            }
                            else
                            {
                                storage.SetDTD001_QtyReserved((Decimal.Add(storage.GetDTD001_QtyReserved(), (Decimal)line.GetQty())));
                                storage.Save();
                            }
                            //new 6jan 3
                            if (_count > 0)
                            {
                                Swhstorage = MStorage.Get(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                if (Swhstorage == null)
                                {
                                    MStorage.Add(GetCtx(), GetDTD001_MWarehouseSource_ID(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), line.GetM_AttributeSetInstance_ID(), (Decimal)0, (Decimal)0, (Decimal)0, 0, Get_Trx());
                                    MStorage StrgResrvQty = null;
                                    StrgResrvQty = MStorage.GetCreate(GetCtx(), Sourcewhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                    StrgResrvQty.SetDTD001_SourceReserve(Decimal.Add(StrgResrvQty.GetDTD001_SourceReserve(), line.GetQty()));
                                    StrgResrvQty.Save();
                                }
                                else
                                {
                                    Swhstorage.SetDTD001_SourceReserve((Decimal.Add(Swhstorage.GetDTD001_SourceReserve(), (Decimal)line.GetQty())));
                                    Swhstorage.Save();
                                }
                            }
                            //End
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("MRequisition--CompleteIt");
                log.Severe(ex.ToString());
            }
            return(DocActionVariables.STATUS_COMPLETED);
        }