예제 #1
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">newRecord new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            //	From - To is the same
            if (GetC_UOM_ID() == GetC_UOM_To_ID())
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@C_UOM_ID@ = @C_UOM_ID@"));
                return(false);
            }
            //	Nothing to convert
            if (GetMultiplyRate().CompareTo(Env.ZERO) <= 0)
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@MultiplyRate@ <= 0"));
                return(false);
            }
            //	Enforce Product UOM
            if (GetM_Product_ID() != 0 && (newRecord || Is_ValueChanged("M_Product_ID")))
            {
                MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());
                if (product.GetC_UOM_ID() != GetC_UOM_ID())
                {
                    MUOM uom = MUOM.Get(GetCtx(), product.GetC_UOM_ID());
                    log.SaveError("ProductUOMConversionUOMError", uom.GetName());
                    return(false);
                }
            }

            //	The Product UoM needs to be the smallest UoM - Multiplier  must be > 0
            if (GetM_Product_ID() != 0 && GetDivideRate().CompareTo(Env.ONE) < 0)
            {
                log.SaveError("ProductUOMConversionRateError", "");
                return(false);
            }
            return(true);
        }
예제 #2
0
 /// <summary>
 /// Parent Constructor
 /// </summary>
 /// <param name="parent"></param>
 public MUOMConversion(MProduct parent)
     : this(parent.GetCtx(), 0, parent.Get_TrxName())
 {
     SetClientOrg(parent);
     SetC_UOM_ID(parent.GetC_UOM_ID());
     SetM_Product_ID(parent.GetM_Product_ID());
     SetC_UOM_To_ID(parent.GetC_UOM_ID());
     SetMultiplyRate(Env.ONE);
     SetDivideRate(Env.ONE);
 }
예제 #3
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">newRecord new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            //	From - To is the same
            //Commented by arpit asked by sachin Sir 29 Jan,2018--to save records with same UOM also
            //if (GetC_UOM_ID() == GetC_UOM_To_ID())
            //{
            //    log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "@C_UOM_ID@ = @C_UOM_ID@"));
            //    return false;
            //}
            //	Nothing to convert
            //Getting the message from messagewindow for UOM conversion
            if (GetMultiplyRate().CompareTo(Env.ZERO) <= 0)
            {
                log.SaveError("", Msg.GetMsg(GetCtx(), "ProductUOMConversionRateError"));
                return(false);
            }
            //	Enforce Product UOM
            if (GetM_Product_ID() != 0 && (newRecord || Is_ValueChanged("M_Product_ID")))
            {
                MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());
                if (product.GetC_UOM_ID() != GetC_UOM_ID())
                {
                    MUOM uom = MUOM.Get(GetCtx(), product.GetC_UOM_ID());
                    log.SaveError("ProductUOMConversionUOMError", uom.GetName());
                    return(false);
                }
            }

            //	The Product UoM needs to be the smallest UoM - Multiplier  must be > 0
            if (GetM_Product_ID() != 0 && GetDivideRate().CompareTo(Env.ONE) < 0)
            {
                // JID_0239: Currenly system show message when multiple rate is less than one like below "Product UOM Coversion rate error"
                log.SaveError("", Msg.GetMsg(GetCtx(), "ProductUOMConversionRateError"));
                return(false);
            }
            if (!String.IsNullOrEmpty(GetUPC()) &&
                Util.GetValueOfString(Get_ValueOld("UPC")) != GetUPC())
            {
                //string sql = "SELECT UPCUNIQUE('c','" + 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 = MProduct.UpcUniqueClientWise(GetAD_Client_ID(), GetUPC());
                if (manu_ID > 0)
                {
                    _log.SaveError("UPCUnique", "");
                    return(false);
                }
            }
            return(true);
        }
예제 #4
0
        /// <summary>
        /// Get Limit Price if exists
        /// </summary>
        /// <returns>limit</returns>
        public Decimal GetLimitPrice()
        {
            Decimal limitPrice = GetPlannedPrice();

            if (GetM_Product_ID() == 0)
            {
                return(limitPrice);
            }
            if (GetProject() == null)
            {
                return(limitPrice);
            }
            bool            isSOTrx = true;
            MProduct        prd     = new MProduct(GetCtx(), GetM_Product_ID(), null);
            MProductPricing pp      = new MProductPricing(GetAD_Client_ID(), GetAD_Org_ID(),
                                                          GetM_Product_ID(), _parent.GetC_BPartner_ID(), GetPlannedQty(), isSOTrx);

            pp.SetM_PriceList_ID(_parent.GetM_PriceList_ID());
            pp.SetM_PriceList_Version_ID(_parent.GetM_PriceList_Version_ID());
            pp.SetC_UOM_ID(prd.GetC_UOM_ID());
            if (pp.CalculatePrice())
            {
                limitPrice = pp.GetPriceLimit();
            }
            return(limitPrice);
        }
        /// <summary>
        /// Get Limit Price if exists
        /// </summary>
        /// <returns>limit</returns>
        public Decimal GetLimitPrice()
        {
            Decimal limitPrice = GetPlannedPrice();

            if (GetM_Product_ID() == 0)
            {
                return(limitPrice);
            }
            if (GetProject() == null)
            {
                return(limitPrice);
            }
            bool            isSOTrx = true;
            MProduct        prd     = new MProduct(GetCtx(), GetM_Product_ID(), null);
            MProductPricing pp      = new MProductPricing(GetAD_Client_ID(), GetAD_Org_ID(),
                                                          GetM_Product_ID(), _parent.GetC_BPartner_ID(), GetPlannedQty(), isSOTrx);

            pp.SetM_PriceList_ID(_parent.GetM_PriceList_ID());
            pp.SetM_PriceList_Version_ID(_parent.GetM_PriceList_Version_ID());

            // Get Price according to Attribute set instance if selected on Project line
            if (Get_ColumnIndex("M_AttributeSetInstance_ID") >= 0)
            {
                pp.SetM_AttributeSetInstance_ID(GetM_AttributeSetInstance_ID());
            }

            pp.SetC_UOM_ID(prd.GetC_UOM_ID());
            if (pp.CalculatePrice())
            {
                limitPrice = pp.GetPriceLimit();
            }
            return(limitPrice);
        }
        /// <summary>
        /// Process Confirmation Line.
        ///	- Update Movement Line
        /// </summary>
        /// <returns>success</returns>
        public Boolean ProcessLine()
        {
            MMovementLine line = GetLine();

            //Lakhwinder
            //Apply UOM Conversion Logic
            MProduct _Pro = new MProduct(GetCtx(), line.GetM_Product_ID(), Get_TrxName());

            if (GetC_UOM_ID() != _Pro.GetC_UOM_ID())
            {
                line.SetTargetQty(Util.GetValueOfDecimal(MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetTargetQty())));
                line.SetMovementQty(Util.GetValueOfDecimal(MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetConfirmedQty())));
                line.SetConfirmedQty(Util.GetValueOfDecimal(MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetConfirmedQty())));
                line.SetScrappedQty(Util.GetValueOfDecimal(MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetScrappedQty())));
            }
            else
            {
                line.SetTargetQty(GetTargetQty());
                line.SetMovementQty(GetConfirmedQty());
                line.SetConfirmedQty(GetConfirmedQty());
                line.SetScrappedQty(GetScrappedQty());
            }

            return(line.Save(Get_TrxName()));
        }
예제 #7
0
        /*
         *  Before Save
         *	@param newRecord new
         *	@return true
         */
        protected override bool BeforeSave(bool newRecord)
        {
            try
            {
                MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());
                if (GetLine() == 0)
                {
                    String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM M_RequisitionLine WHERE M_Requisition_ID=@param1";
                    int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql, GetM_Requisition_ID());
                    SetLine(ii);
                }

                // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line
                if (GetM_Product_ID() > 0 && Get_ColumnIndex("QtyEntered") > 0 && (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID")))
                {
                    Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                    if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                    {
                        SetQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))));
                    }
                }

                // SI_0657_3 - precision of Qty should be according to the precision of UOM attached.
                if (newRecord || Is_ValueChanged("Qty"))
                {
                    if (product != null)
                    {
                        int precision = product.GetUOMPrecision();
                        SetQty(Decimal.Round(GetQty(), precision, MidpointRounding.AwayFromZero));
                    }
                }

                //	Product & ASI - Charge
                if (GetM_Product_ID() != 0 && GetC_Charge_ID() != 0)
                {
                    SetC_Charge_ID(0);
                }
                if (GetM_AttributeSetInstance_ID() != 0 && GetC_Charge_ID() != 0)
                {
                    SetM_AttributeSetInstance_ID(0);
                }
                //
                if (GetPriceActual().CompareTo(Env.ZERO) == 0)
                {
                    SetPrice();
                }
                SetLineNetAmt();
            }
            catch
            {
            }
            return(true);
        }
 /// <summary>
 /// Set Product
 /// </summary>
 /// <param name="product">product product</param>
 public void SetProduct(VAdvantage.Model.MProduct product)
 {
     if (product != null)
     {
         SetM_Product_ID(product.GetM_Product_ID());
         SetC_UOM_ID(product.GetC_UOM_ID());
     }
     else
     {
         SetM_Product_ID(0);
         Set_ValueNoCheck("C_UOM_ID", null);
     }
     SetM_AttributeSetInstance_ID(0);
 }       //	setProduct
        /// <summary>
        /// Get Purchase Price if exists
        /// </summary>
        /// <returns>limit</returns>
        public Decimal GetPurchasePrice()
        {
            //VA077_PurchasePrice
            Decimal purchasePrice = 0;

            if (GetM_Product_ID() == 0)
            {
                return(purchasePrice);
            }
            bool            isSOTrx = false;
            MProduct        prd     = new MProduct(GetCtx(), GetM_Product_ID(), null);
            MProductPricing pp      = new MProductPricing(GetAD_Client_ID(), GetAD_Org_ID(),
                                                          GetM_Product_ID(), _parent.GetC_BPartner_ID(), GetPlannedQty(), isSOTrx);

            pp.SetM_PriceList_ID(Util.GetValueOfInt(_parent.Get_Value("PO_PriceList_ID")));

            DateTime?validFrom = null;      // _parent.GetDateContract();

            if (validFrom == null)
            {
                validFrom = DateTime.Now.Date;
            }

            int M_PriceList_Version_ID = Util.GetValueOfInt(DB.ExecuteScalar(@"SELECT M_PriceList_Version_ID FROM M_PriceList_Version WHERE IsActive = 'Y' 
                        AND M_PriceList_ID = " + Util.GetValueOfInt(_parent.Get_Value("PO_PriceList_ID")) + @" AND ValidFrom <= "
                                                                             + DB.TO_DATE(validFrom, true) + " ORDER BY ValidFrom DESC"));

            pp.SetM_PriceList_Version_ID(M_PriceList_Version_ID);

            // Get Price according to Attribute set instance if selected on Project line
            if (Get_ColumnIndex("M_AttributeSetInstance_ID") >= 0)
            {
                pp.SetM_AttributeSetInstance_ID(GetM_AttributeSetInstance_ID());
            }

            // Get Price according to UOM if selected on Project line
            if (Get_ColumnIndex("C_UOM_ID") >= 0)
            {
                pp.SetC_UOM_ID(Util.GetValueOfInt(Get_Value("C_UOM_ID")));
            }
            else
            {
                pp.SetC_UOM_ID(prd.GetC_UOM_ID());
            }
            if (pp.CalculatePrice())
            {
                purchasePrice = pp.GetPriceStd();
            }
            return(purchasePrice);
        }
예제 #10
0
 /*	Set Product
  *	@param product product
  */
 public void SetProduct(MProduct product)
 {
     _product = product;
     if (_product != null)
     {
         SetM_Product_ID(_product.GetM_Product_ID());
         SetC_UOM_ID(_product.GetC_UOM_ID());
     }
     else
     {
         SetM_Product_ID(0);
         SetC_UOM_ID(0);
     }
     SetM_AttributeSetInstance_ID(0);
 }
예제 #11
0
        } // beforeSave

        /// <summary>
        /// Set Product - Callout
        /// </summary>
        /// <param name="oldM_Product_ID"></param>
        /// <param name="newM_Product_ID"></param>
        /// <param name="windowNo"></param>
        public void SetM_Product_ID(String oldM_Product_ID,
                                    String newM_Product_ID, int windowNo)
        {
            // If Product is set to null, reset BOM.
            if (newM_Product_ID == null || newM_Product_ID.Length == 0)
            {
                Set_ValueNoCheck("C_UOM_ID", null);
                return;
            }
            int M_Product_ID = VAdvantage.Utility.Util.GetValueOfInt(newM_Product_ID);

            if (M_Product_ID == 0)
            {
                Set_ValueNoCheck("C_UOM_ID", null);
                return;
            }

            // Set UOM from Product
            VAdvantage.Model.MProduct product = new VAdvantage.Model.MProduct(Env.GetCtx(), M_Product_ID, null);
            SetC_UOM_ID(product.GetC_UOM_ID());
        }       //	setM_Product_ID
        } // setRequiredColumns

        /// <summary>
        /// Set Product - Callout
        /// </summary>
        ///  <param name="oldM_Product_ID"> oldM_Product_ID old value</param>
        ///  <param name="newM_Product_ID">newM_Product_ID new value</param>
        /// <param name="windowNo">windowNo window</param>

        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)
            {
                SetM_AttributeSetInstance_ID(0);
                return;
            }
            int M_Product_ID = VAdvantage.Utility.Util.GetValueOfInt(newM_Product_ID);

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

            //	Set Attribute
            int M_AttributeSetInstance_ID = GetCtx().GetContextAsInt(EnvConstants.WINDOW_INFO, EnvConstants.TAB_INFO, "M_AttributeSetInstance_ID");

            if (GetCtx().GetContextAsInt(EnvConstants.WINDOW_INFO, EnvConstants.TAB_INFO, "M_Product_ID") == M_Product_ID &&
                M_AttributeSetInstance_ID != 0)
            {
                SetM_AttributeSetInstance_ID(M_AttributeSetInstance_ID);
            }
            else
            {
                SetM_AttributeSetInstance_ID(0);
            }

            VAdvantage.Model.MProduct product = VAdvantage.Model.MProduct.Get(GetCtx(), M_Product_ID);

            //
            SetC_UOM_ID(product.GetC_UOM_ID());
        }       //	setM_Product_ID
예제 #13
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());
                }
            }
        }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            Decimal    VA024_ProvisionPrice = 0;
            MInventory inventory            = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
            MProduct   product = MProduct.Get(GetCtx(), GetM_Product_ID());

            if (newRecord && _isManualEntry)
            {
                //	Product requires ASI
                if (GetM_AttributeSetInstance_ID() == 0)
                {
                    if (product.GetM_AttributeSet_ID() != 0)
                    {
                        MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                        //uncomment by Amit on behalf of Mandeep 7-3-2016
                        //if (mas.IsInstanceAttribute()
                        //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                        if (mas.IsMandatory() || mas.IsMandatoryAlways())
                        {
                            log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID"));
                            return(false);
                        }
                    }
                } //	No ASI
            }     //	new or manual

            // not to create Internal use Inventory with -ve qty -- but during reversal system will create record with -ve qty
            // duing reversal -- ReversalDoc_ID contain refernce o  orignal record id
            if (IsInternalUse() && Get_ColumnIndex("ReversalDoc_ID") > 0 && GetReversalDoc_ID() == 0 && GetQtyInternalUse() < 0)
            {
                log.SaveError("", Msg.GetMsg(GetCtx(), "VIS_CantbeNegative"));
                return(false);
            }

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_InventoryLine WHERE M_Inventory_ID=" + GetM_Inventory_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // SI_0644.1 : Enforce UOM Precision - Rounding Quantities
            if (newRecord || Is_ValueChanged("QtyInternalUse"))
            {
                SetQtyInternalUse(GetQtyInternalUse());
            }

            // change to set Converted Quantity in Internal Use Qty and AsonDateQty and difference qty if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    qty = MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered")));
                    if (IsInternalUse())
                    {
                        SetQtyInternalUse(qty);
                    }
                    else
                    {
                        SetAsOnDateCount(qty);
                        SetDifferenceQty(qty);
                    }
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("AsOnDateCount"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetAsOnDateCount(Decimal.Round(GetAsOnDateCount(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // SI_0644 - As on date and difference should be according to the precision of UOM attached.
            if (newRecord || Is_ValueChanged("DifferenceQty"))
            {
                if (product != null)
                {
                    int precision = product.GetUOMPrecision();
                    SetDifferenceQty(Decimal.Round(GetDifferenceQty(), precision, MidpointRounding.AwayFromZero));
                }
            }

            // 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_") && IsInternalUse())
            {
                qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("QtyInternalUse"));
            }

            int    M_Warehouse_ID = 0; MWarehouse wh = null;
            string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();

            M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, Get_TrxName()));

            wh  = MWarehouse.Get(GetCtx(), M_Warehouse_ID);
            qry = "SELECT QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry, null, Get_TrxName()));
            // when record is in completed & closed stage - then no need to check qty availablity in warehouse
            if (wh.IsDisallowNegativeInv() == true &&
                (!(inventory.GetDocStatus() == "CO" || inventory.GetDocStatus() == "CL" ||
                   inventory.GetDocStatus() == "RE" || inventory.GetDocStatus() == "VO")))
            {
                #region DisallowNegativeInv = True
                if (!IsInternalUse() && GetDifferenceQty() > 0)
                {
                    if ((OnHandQty - GetDifferenceQty()) < 0)
                    {
                        log.SaveError("Info", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                }
                else if (IsInternalUse())
                {
                    if ((OnHandQty - GetQtyInternalUse()) < 0)
                    {
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                }
                #endregion
            }
            //	Enforce Qty UOM
            if (newRecord || Is_ValueChanged("QtyCount"))
            {
                SetQtyCount(GetQtyCount());
            }

            //	InternalUse Inventory
            if (IsInternalUse() && Env.Signum(GetQtyInternalUse()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "QtyInternalUse"));
                return(false);
            }
            if (Env.Signum(GetQtyInternalUse()) != 0)
            {
                if (!INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
                {
                    SetInventoryType(INVENTORYTYPE_ChargeAccount);
                }
                //
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("Error", Msg.GetMsg(GetCtx(), "InternalUseNeedsCharge"));
                    return(false);
                }
            }
            else if (INVENTORYTYPE_ChargeAccount.Equals(GetInventoryType()))
            {
                if (GetC_Charge_ID() == 0)
                {
                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "C_Charge_ID"));
                    return(false);
                }
            }
            else if (GetC_Charge_ID() != 0)
            {
                SetC_Charge_ID(0);
            }

            //	Set AD_Org to parent if not charge
            if (GetC_Charge_ID() == 0)
            {
                SetAD_Org_ID(GetParent().GetAD_Org_ID());
            }

            // By Amit for Obsolete Inventory - 25-May-2016
            if (Env.IsModuleInstalled("VA024_"))
            {
                //MInventory inventory = new MInventory(GetCtx(), GetM_Inventory_ID(), Get_Trx());
                //shipment and Return to vendor
                if (inventory.IsInternalUse() || (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0))
                {
                    try
                    {
                        string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                      " AND o.AD_Org_ID = " + GetAD_Org_ID();
                        //+" AND M_Warehouse_ID = " + inventory.GetM_Warehouse_ID();
                        VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * (GetQtyBook() - GetQtyCount())));
                        }
                        else
                        {
                            SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetQtyInternalUse()));
                        }

                        if (!inventory.IsInternalUse() && (GetQtyBook() - GetQtyCount()) > 0)
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + (GetQtyBook() - GetQtyCount());
                        }
                        else
                        {
                            qry1 = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetQtyInternalUse();
                        }
                        qry1 += @" FROM m_product p  INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID
                                 INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID
                                 INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID   INNER JOIN AD_ClientInfo ci  ON c.AD_Client_ID = ci.Ad_Client_ID
                                 INNER JOIN m_cost ct ON ( p.M_Product_ID     = ct.M_Product_ID  AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID )
                                 INNER JOIN c_acctschema asch  ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID)
                                 INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID ";
                        qry1 += @"    WHERE ct.AD_Org_ID =  
                          CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'B')) THEN 0 
                               WHEN (pc.costinglevel IS NULL AND asch.costinglevel  = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'B')) THEN 0  END
                          AND ct.m_costelement_id =  
                          CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement  
                                     WHERE m_costelement.costingmethod =pc.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  ) 
                                WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN  pc.m_costelement_id 
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement 
                                     WHERE m_costelement.costingmethod = asch.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  )
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  = 'C') THEN asch.m_costelement_id  END 
                         AND NVL(ct.M_Attributesetinstance_ID , 0) =  
                         CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" 
                              WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'O')) THEN 0 
                              WHEN ( pc.costinglevel IS NULL AND asch.costinglevel  = 'B') THEN " + GetM_AttributeSetInstance_ID() + @"
                              WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'O')) THEN 0  END 
                         AND p.M_Product_ID = " + GetM_Product_ID();
                        SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())));
                    }
                    catch { }
                }
            }

            return(true);
        }
        /// <summary>
        ///      Process Confirmation Line.
        ///     - Update InOut Line
        /// </summary>
        /// <param name="isSOTrx">sales order</param>
        /// <param name="confirmType">type</param>
        /// <returns>success</returns>
        public Boolean ProcessLine(bool isSOTrx, String confirmType)
        {
            MInOutLine line = GetLine();

            //	Customer
            if (MInOutConfirm.CONFIRMTYPE_CustomerConfirmation.Equals(confirmType))
            {
                line.SetConfirmedQty(GetConfirmedQty());
            }

            //	Drop Ship
            else if (MInOutConfirm.CONFIRMTYPE_DropShipConfirm.Equals(confirmType))
            {
            }

            //	Pick or QA
            else if (MInOutConfirm.CONFIRMTYPE_PickQAConfirm.Equals(confirmType))
            {
                line.SetTargetQty(GetTargetQty());
                line.SetMovementQty(GetConfirmedQty()); //	Entered NOT changed
                line.SetPickedQty(GetConfirmedQty());
                //
                line.SetScrappedQty(GetScrappedQty());
            }

            //	Ship or Receipt
            else if (MInOutConfirm.CONFIRMTYPE_ShipReceiptConfirm.Equals(confirmType))
            {
                //Arpit
                if (GetDifferenceQty() > 0)
                {
                    GetCtx().SetContext("DifferenceQty_", VAdvantage.Utility.Util.GetValueOfString(GetDifferenceQty()));
                }
                MProduct _pro = new MProduct(GetCtx(), line.GetM_Product_ID(), Get_TrxName());
                if (_pro.GetC_UOM_ID() != line.GetC_UOM_ID())
                {
                    decimal?pc = null;
                    pc = MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetTargetQty());
                    line.SetTargetQty(Util.GetValueOfDecimal(pc));  //TargetQty

                    Decimal qty         = GetConfirmedQty();
                    Boolean isReturnTrx = line.GetParent().IsReturnTrx();

                    /* In PO receipts and SO Returns, we have the responsibility
                     * for scrapped quantity
                     */
                    if ((!isSOTrx && !isReturnTrx) || (isSOTrx && isReturnTrx))
                    {
                        qty = Decimal.Add(qty, GetScrappedQty());
                    }
                    pc = MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), qty);
                    line.SetMovementQty(Util.GetValueOfDecimal(pc)); //MovementQty

                    pc = MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetScrappedQty());
                    line.SetScrappedQty(Util.GetValueOfDecimal(pc));  //ScrappedQty

                    pc = MUOMConversion.ConvertProductFrom(GetCtx(), line.GetM_Product_ID(), GetC_UOM_ID(), GetConfirmedQty());
                    line.SetConfirmedQty(Util.GetValueOfDecimal(pc)); //confirm Qty
                }
                else
                {
                    line.SetTargetQty(GetTargetQty());
                    Decimal qty         = GetConfirmedQty();
                    Boolean isReturnTrx = line.GetParent().IsReturnTrx();

                    /* In PO receipts and SO Returns, we have the responsibility
                     * for scrapped quantity
                     */
                    if ((!isSOTrx && !isReturnTrx) || (isSOTrx && isReturnTrx))
                    {
                        qty = Decimal.Add(qty, GetScrappedQty());
                    }
                    line.SetMovementQty(qty);                           //	Entered NOT changed
                    //
                    line.SetScrappedQty(GetScrappedQty());
                    // vikas 12/28/2015 Mantis Issue (0000335)
                    line.SetConfirmedQty(GetConfirmedQty());
                }
            }
            //	Vendor
            else if (MInOutConfirm.CONFIRMTYPE_VendorConfirmation.Equals(confirmType))
            {
                line.SetConfirmedQty(GetConfirmedQty());
            }

            return(line.Save(Get_TrxName()));
        }
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            Decimal  VA024_ProvisionPrice = 0;
            MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());

            // chck pallet Functionality applicable or not
            bool isContainrApplicable = MTransaction.ProductContainerApplicable(GetCtx());

            // Get Old Value of AttributeSetInstance_ID
            _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID"));

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // JID_0775: System is not checking on move line that the attribute set instance is mandatory.
            if (GetM_AttributeSetInstance_ID() == 0)
            {
                if (product != null && product.GetM_AttributeSet_ID() != 0)
                {
                    MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                    if (mas.IsMandatory() || mas.IsMandatoryAlways())
                    {
                        log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstance_ID"));
                        return(false);
                    }
                }
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());
            MLocator  loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName());
            Tuple <string, string, string> aInfo = null;

            if (Env.HasModulePrefix("DTD001_", out aInfo))
            {
                if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID())
                {
                }
                else
                {
                    String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'";
                    int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                    SetM_Locator_ID(ii);
                }
            }

            // when we try to move product from container to container which are in same locator then no need to check this case
            if (GetM_Locator_ID() == GetM_LocatorTo_ID() &&
                (Get_ColumnIndex("M_ProductContainer_ID") > 0 && Get_ColumnIndex("Ref_M_ProductContainerTo_ID") > 0 &&
                 !(GetM_ProductContainer_ID() > 0 || GetRef_M_ProductContainerTo_ID() > 0)))
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement
                return(false);
            }

            if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty"));
                return(false);
            }

            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged"));
                    return(false);
                }
            }
            //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
            if (Env.IsModuleInstalled("VA203_"))
            {
                if (GetM_RequisitionLine_ID() > 0)
                {
                    MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
                    if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID())
                    {
                        log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame"));
                        return(false);
                    }
                }
            }
            // IF Doc Status = InProgress then No record Save
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());        // Trx used to handle query stuck problem

            if (newRecord && move.GetDocStatus() == "IP")
            {
                log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate"));
                return(false);
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetQtyEntered(GetQtyEntered());
            }

            // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))));
                }
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }

            string qry;

            if (!mov.IsProcessing() || newRecord)
            {
                MWarehouse wh = null; MWarehouse whTo = null;
                wh   = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID());
                whTo = MWarehouse.Get(GetCtx(), MLocator.Get(GetCtx(), GetM_LocatorTo_ID()).GetM_Warehouse_ID());

                qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0)
                {
                    qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID();
                }
                OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));

                qry         = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID();
                qry        += " AND NVL(M_AttributeSetInstance_ID, 0) =" + GetM_AttributeSetInstance_ID();
                OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry));

                // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse
                // when record is in completed & closed stage - then no need to check qty availablity in warehouse
                if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) &&
                    (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO")))
                {
                    // pick container current qty from transaction based on locator / product / ASI / Container / Movement Date
                    if (isContainrApplicable && Get_ColumnIndex("M_ProductContainer_ID") >= 0)
                    {
                        //                    qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t
                        //                            INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                        //                                " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                        //                                @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_LocatorTo_ID() : GetM_Locator_ID()) +
                        //                                " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                        //                                " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetRef_M_ProductContainerTo_ID() : GetM_ProductContainer_ID());
                        //                    containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        //                    qry = @"SELECT SUM(t.ContainerCurrentQty) keep (dense_rank last ORDER BY t.MovementDate, t.M_Transaction_ID) AS CurrentQty FROM m_transaction t
                        //                            INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                        //                               " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                        //                               @" AND t.M_Locator_ID = " + (move.IsReversal() && GetMovementQty() < 0 ? GetM_Locator_ID() : GetM_LocatorTo_ID()) +
                        //                               " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                        //                               " AND NVL(t.M_ProductContainer_ID, 0) = " + (move.IsReversal() && !IsMoveFullContainer() && GetMovementQty() < 0 ? GetM_ProductContainer_ID() : GetRef_M_ProductContainerTo_ID());
                        //                    containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC) AS CurrentQty FROM m_transaction t 
                                                INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                              " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                              @" AND t.M_Locator_ID = " + GetM_Locator_ID() +
                              " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_ProductContainer_ID, 0) = " + GetM_ProductContainer_ID();

                        // In Case of Attribute Number do not check qty with attribute from storage
                        if (GetDTD001_AttributeNumber() == null || GetM_AttributeSetInstance_ID() > 0)
                        {
                            qry += " AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID();
                        }

                        containerQty = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion

                        qry = @"SELECT DISTINCT First_VALUE(t.ContainerCurrentQty) OVER (PARTITION BY t.M_Product_ID, t.M_AttributeSetInstance_ID ORDER BY t.MovementDate DESC, t.M_Transaction_ID DESC)  AS CurrentQty FROM m_transaction t 
                                                INNER JOIN M_Locator l ON t.M_Locator_ID = l.M_Locator_ID WHERE t.MovementDate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) +
                              " AND t.AD_Client_ID = " + GetAD_Client_ID() +
                              @" AND t.M_Locator_ID = " + GetM_LocatorTo_ID() +
                              " AND t.M_Product_ID = " + GetM_Product_ID() + " AND NVL(t.M_AttributeSetInstance_ID,0) = " + GetM_AttributeSetInstance_ID() +
                              " AND NVL(t.M_ProductContainer_ID, 0) = " + GetRef_M_ProductContainerTo_ID();
                        containerQtyTo = Util.GetValueOfDecimal(DB.ExecuteScalar(qry.ToString(), null, null));  // dont use Transaction here - otherwise impact goes wrong on completion
                    }

                    if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0)
                    {
                        // check for From Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                        return(false);
                    }
                    else if (isContainrApplicable && wh.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQty - GetMovementQty()) < 0)
                    {
                        // check container qty -  for From Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainer") + containerQty);
                        return(false);
                    }
                    else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0)
                    {
                        // check for To Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo);
                        return(false);
                    }
                    else if (isContainrApplicable && whTo.IsDisallowNegativeInv() && Get_ColumnIndex("M_ProductContainer_ID") >= 0 && (containerQtyTo + GetMovementQty()) < 0)
                    {
                        // check for To Locator
                        log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQtyContainerTo") + containerQtyTo);
                        return(false);
                    }
                }
            }

            if (Env.IsModuleInstalled("DTD001_"))
            {
                // not used this variable, that why commented
                //qry = "SELECT   NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable  FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                //if (GetM_AttributeSetInstance_ID() != 0)
                //{
                //    qry += " AND NVL(M_AttributeSetInstance_ID , 0) = " + GetM_AttributeSetInstance_ID();
                //}
                //qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry));
                qtyReserved = Util.GetValueOfDecimal(Get_ValueOld("MovementQty"));
                //if (wh.IsDisallowNegativeInv() == true)
                //{
                //    if ((qtyAvailable < (GetMovementQty() - qtyReserved)))
                //    {
                //        log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable"));
                //        return false;
                //    }
                //}
            }

            //By Amit - 17-April-2017
            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)
                {
                    string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                  " AND o.AD_Org_ID = " + GetAD_Org_ID();
                    VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                    SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty()));

                    // is used to get cost of binded cost method / costing level of primary accounting schema
                    Decimal cost = MCost.GetproductCosts(move.GetAD_Client_ID(), move.GetAD_Org_ID(), GetM_Product_ID(),
                                                         GetM_AttributeSetInstance_ID(), Get_Trx(), move.GetDTD001_MWarehouseSource_ID());
                    SetVA024_CostPrice((cost - VA024_ProvisionPrice) * GetMovementQty());
                }
            }

            //	Mandatory Instance
            if (GetM_AttributeSetInstanceTo_ID() == 0)
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    if (Env.HasModulePrefix("DTD001_", out mInfo))
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            //if (mas.IsInstanceAttribute()
                            //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            //{
                            //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                            //    return false;
                            //}

                            // Code Addeded by Bharat as Discussed with Mukesh Sir
                            if (String.IsNullOrEmpty(GetDTD001_AttributeNumber()))
                            {
                                return(true);
                            }
                            else
                            {
                                if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)
                                {
                                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));

                                    return(false);
                                }
                            }

                            //JID_1422: Check No Of Attributes Are Equal To Quantity Or Less Than

                            int Count = CountAttributes(GetDTD001_AttributeNumber());
                            if (Count != GetQtyEntered())
                            {
                                if (Count > GetQtyEntered())
                                {
                                    log.SaveError("DTD001_MovementAttrbtGreater", "");
                                    return(false);
                                }
                                else
                                {
                                    log.SaveError("DTD001_MovementAttrbtLess", "");
                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (product != null)
                            {
                                if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null))
                                {
                                    return(true);
                                }
                                else
                                {
                                    //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                    log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    return(false);
                                }

                                //Check No Of Attributes Are Equal To Quantity Or Less Than

                                //int Count = CountAttributes(GetDTD001_AttributeNumber());
                                //if (Count != GetMovementQty())
                                //{
                                //    if (Count > GetMovementQty())
                                //    {
                                //        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater"));
                                //        return false;
                                //    }
                                //    else
                                //    {
                                //        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess"));
                                //        return false;
                                //    }
                                //}
                            }
                        }
                    }
                    else
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            if (mas.IsInstanceAttribute() &&
                                (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                                return(false);
                            }
                        }
                    }
                }
            }    //	ASI
            return(true);
        }
예제 #17
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            Decimal  VA024_ProvisionPrice = 0;
            MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());

            // By vikas
            // Get Old Value of AttributeSetInstance_ID
            _mvlOldAttId = Util.GetValueOfInt(Get_ValueOld("M_AttributeSetInstance_ID"));

            //	Set Line No
            if (GetLine() == 0)
            {
                String sql = "SELECT COALESCE(MAX(Line),0)+10 AS DefaultValue FROM M_MovementLine WHERE M_Movement_ID=" + GetM_Movement_ID();
                int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());
            MLocator  loc = new MLocator(GetCtx(), GetM_Locator_ID(), Get_TrxName());
            Tuple <string, string, string> aInfo = null;

            if (Env.HasModulePrefix("DTD001_", out aInfo))
            {
                if (mov.GetDTD001_MWarehouseSource_ID() == loc.GetM_Warehouse_ID())
                {
                }
                else
                {
                    String sql = "SELECT M_Locator_ID FROM M_Locator WHERE M_Warehouse_ID=" + mov.GetDTD001_MWarehouseSource_ID() + " AND IsDefault = 'Y'";
                    int    ii  = DataBase.DB.GetSQLValue(Get_TrxName(), sql);
                    SetM_Locator_ID(ii);
                }
            }

            if (GetM_Locator_ID() == GetM_LocatorTo_ID())
            {
                log.SaveError("Error", Msg.ParseTranslation(GetCtx(), "'From @M_Locator_ID@' and '@M_LocatorTo_ID@' cannot be same."));//change message according to requirement
                return(false);
            }

            if (Env.Signum(GetMovementQty()) == 0 && Util.GetValueOfInt(GetTargetQty()) == 0)
            {
                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "MovementQty"));
                return(false);
            }
            //Amit
            Tuple <String, String, String> mInfo = null;

            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Product_ID")) != GetM_Product_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ProdNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_Locator_ID")) != GetM_Locator_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_LocatorNotChanged"));
                    return(false);
                }
                if (!newRecord && Util.GetValueOfInt(Get_ValueOld("M_RequisitionLine_ID")) != GetM_RequisitionLine_ID())
                {
                    log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_ReqNotChanged"));
                    return(false);
                }
            }
            //if (Util.GetValueOfInt(DB.ExecuteScalar("SELECT COUNT(AD_MODULEINFO_ID) FROM AD_MODULEINFO WHERE PREFIX='VA203_'", null, null)) > 0)
            if (Env.IsModuleInstalled("VA203_"))
            {
                if (GetM_RequisitionLine_ID() > 0)
                {
                    MRequisitionLine reqline = new MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), Get_Trx());        // Trx used to handle query stuck problem
                    if (GetM_AttributeSetInstance_ID() != reqline.GetM_AttributeSetInstance_ID())
                    {
                        log.SaveError("Message", Msg.GetMsg(GetCtx(), "VA203_AttributeInstanceMustBeSame"));
                        return(false);
                    }
                }
            }
            // IF Doc Status = InProgress then No record Save
            MMovement move = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());        // Trx used to handle query stuck problem

            if (newRecord && move.GetDocStatus() == "IP")
            {
                log.SaveError("Message", Msg.GetMsg(GetCtx(), "DTD001_CannotCreate"));
                return(false);
            }

            // change to set Converted Quantity in Movement quantity if there is differnce in UOM of Base Product and UOM Selected on line
            if (newRecord || Is_ValueChanged("QtyEntered") || Is_ValueChanged("C_UOM_ID"))
            {
                Decimal?qty = Util.GetValueOfDecimal(Get_Value("QtyEntered"));
                if (product.GetC_UOM_ID() != Util.GetValueOfInt(Get_Value("C_UOM_ID")))
                {
                    SetMovementQty(MUOMConversion.ConvertProductFrom(GetCtx(), GetM_Product_ID(), Util.GetValueOfInt(Get_Value("C_UOM_ID")), Util.GetValueOfDecimal(Get_Value("QtyEntered"))));
                }
            }

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }
            MWarehouse wh = null; MWarehouse whTo = null;

            //string qry = "select m_warehouse_id from m_locator where m_locator_id=" + GetM_Locator_ID();
            //M_Warehouse_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry));

            wh   = MWarehouse.Get(GetCtx(), mov.GetDTD001_MWarehouseSource_ID());
            whTo = MWarehouse.Get(GetCtx(), mov.GetM_Warehouse_ID());

            string qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();

            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));

            qry = "SELECT NVL(SUM(NVL(QtyOnHand,0)),0) AS QtyOnHand FROM M_Storage where m_locator_id=" + GetM_LocatorTo_ID() + " and m_product_id=" + GetM_Product_ID();
            if (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQtyTo = Convert.ToDecimal(DB.ExecuteScalar(qry));

            // SI_0635 : System is giving error of insufficient qty if disallow is true in TO warehouse and false in From warehouse
            // when record is in completed & closed stage - then no need to check qty availablity in warehouse
            if ((wh.IsDisallowNegativeInv() || whTo.IsDisallowNegativeInv()) &&
                (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE" || move.GetDocStatus() == "VO")))
            {
                if (wh.IsDisallowNegativeInv() && (OnHandQty - GetMovementQty()) < 0)
                {
                    // check for From Locator
                    log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                    return(false);
                }
                else if (whTo.IsDisallowNegativeInv() && (OnHandQtyTo + GetMovementQty()) < 0)
                {
                    // check for To Locator
                    log.SaveError("Info", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQtyTo);
                    return(false);
                }
            }
            if (Env.HasModulePrefix("DTD001_", out mInfo))
            {
                qry = "SELECT   NVL(SUM(NVL(QtyOnHand,0)- qtyreserved),0) AS QtyAvailable  FROM M_Storage where m_locator_id=" + GetM_Locator_ID() + " and m_product_id=" + GetM_Product_ID();
                if (GetM_AttributeSetInstance_ID() != 0)
                {
                    qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
                }
                qtyAvailable = Convert.ToDecimal(DB.ExecuteScalar(qry));
                qtyReserved  = Util.GetValueOfDecimal(Get_ValueOld("MovementQty"));
                //if (wh.IsDisallowNegativeInv() == true)
                //{
                //    if ((qtyAvailable < (GetMovementQty() - qtyReserved)))
                //    {
                //        log.SaveError("Message", product.GetName() + " , " + Msg.GetMsg(GetCtx(), "DTD001_QtyNotAvailable"));
                //        return false;
                //    }
                //}
            }

            //By Amit - 17-April-2017
            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)
                {
                    MMovement inventory = new MMovement(GetCtx(), GetM_Movement_ID(), Get_Trx());
                    try
                    {
                        string qry1 = @"SELECT  SUM(o.VA024_UnitPrice)   FROM VA024_t_ObsoleteInventory o 
                                  WHERE o.IsActive = 'Y' AND  o.M_Product_ID = " + GetM_Product_ID() + @" and 
                                  ( o.M_AttributeSetInstance_ID = " + GetM_AttributeSetInstance_ID() + @" OR o.M_AttributeSetInstance_ID IS NULL )" +
                                      " AND o.AD_Org_ID = " + GetAD_Org_ID();
                        VA024_ProvisionPrice = Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx()));
                        SetVA024_UnitPrice(Util.GetValueOfDecimal(VA024_ProvisionPrice * GetMovementQty()));

                        qry1  = @"SELECT (ct.currentcostprice - " + VA024_ProvisionPrice + ") * " + GetMovementQty();
                        qry1 += @" FROM m_product p  INNER JOIN va024_t_obsoleteinventory oi ON p.m_product_id = oi.M_product_ID
                                 INNER JOIN m_product_category pc ON pc.m_product_category_ID = p.m_product_category_ID
                                 INNER JOIN AD_client c ON c.AD_Client_ID = p.Ad_Client_ID   INNER JOIN AD_ClientInfo ci  ON c.AD_Client_ID = ci.Ad_Client_ID
                                 INNER JOIN m_cost ct ON ( p.M_Product_ID     = ct.M_Product_ID  AND ci.C_AcctSchema1_ID = ct.C_AcctSchema_ID )
                                 INNER JOIN c_acctschema asch  ON (asch.C_AcctSchema_ID = ci.C_AcctSchema1_ID)
                                 INNER JOIN va024_obsoleteinvline oil ON oil.va024_obsoleteinvline_ID = oi.va024_obsoleteinvline_ID ";
                        qry1 += @"    WHERE ct.AD_Org_ID =  
                          CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'B')) THEN 0 
                               WHEN (pc.costinglevel IS NULL AND asch.costinglevel  = 'O') THEN " + GetAD_Org_ID() + @" 
                               WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'B')) THEN 0  END
                          AND ct.m_costelement_id =  
                          CASE WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement  
                                     WHERE m_costelement.costingmethod =pc.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  ) 
                                WHEN ( pc.costingmethod IS NOT NULL AND pc.costingmethod = 'C' ) THEN  pc.m_costelement_id 
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  != 'C') THEN  (SELECT MIN(m_costelement_id)  FROM m_costelement 
                                     WHERE m_costelement.costingmethod = asch.costingmethod  AND m_costelement.Ad_Client_ID  = oi.ad_client_id  )
                                WHEN ( pc.costingmethod IS NULL AND asch.costingmethod  = 'C') THEN asch.m_costelement_id  END 
                         AND NVL(ct.M_Attributesetinstance_ID , 0) =  
                         CASE WHEN ( pc.costinglevel IS NOT NULL AND pc.costinglevel = 'B') THEN " + GetM_AttributeSetInstance_ID() + @" 
                              WHEN ( pc.costinglevel IS NOT NULL AND (pc.costinglevel  = 'C' OR pc.costinglevel = 'O')) THEN 0 
                              WHEN ( pc.costinglevel IS NULL AND asch.costinglevel  = 'B') THEN " + GetM_AttributeSetInstance_ID() + @"
                              WHEN ( pc.costinglevel IS NULL AND (asch.costinglevel  = 'C' OR asch.costinglevel   = 'O')) THEN 0  END 
                         AND p.M_Product_ID = " + GetM_Product_ID();
                        SetVA024_CostPrice(Util.GetValueOfDecimal(DB.ExecuteScalar(qry1, null, Get_Trx())));
                    }
                    catch { }
                }
            }

            //	Mandatory Instance
            if (GetM_AttributeSetInstanceTo_ID() == 0)
            {
                if (GetM_AttributeSetInstance_ID() != 0)        //	Set to from
                {
                    SetM_AttributeSetInstanceTo_ID(GetM_AttributeSetInstance_ID());
                }
                else
                {
                    if (Env.HasModulePrefix("DTD001_", out mInfo))
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            //MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            //if (mas.IsInstanceAttribute()
                            //    && (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            //{
                            //    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                            //    return false;
                            //}

                            // Code Addeded by Bharat as Discussed with Mukesh Sir
                            if (String.IsNullOrEmpty(GetDTD001_AttributeNumber()))
                            {
                                return(true);
                            }
                            else
                            {
                                if (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null)
                                {
                                    log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));

                                    return(false);
                                }
                            }
                        }
                        else
                        {
                            if (product != null)
                            {
                                if (product.GetM_AttributeSet_ID() == 0 && (GetDTD001_AttributeNumber() == "" || GetDTD001_AttributeNumber() == null))
                                {
                                    return(true);
                                }
                                else
                                {
                                    //log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    //ShowMessage.Info("a", true, "Product is not of Attribute Type", null);
                                    log.SaveError("Product is not of Attribute Type", Msg.GetElement(GetCtx(), "DTD001_AttributeNumber"));
                                    return(false);
                                }

                                //Check No Of Attributes Are Equal To Quantity Or Less Than

                                int Count = CountAttributes(GetDTD001_AttributeNumber());
                                if (Count != GetMovementQty())
                                {
                                    if (Count > GetMovementQty())
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtGreater"));
                                        return(false);
                                    }
                                    else
                                    {
                                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "DTD001_MovementAttrbtLess"));
                                        return(false);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        //MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            MAttributeSet mas = MAttributeSet.Get(GetCtx(), product.GetM_AttributeSet_ID());
                            if (mas.IsInstanceAttribute() &&
                                (mas.IsMandatory() || mas.IsMandatoryAlways()))
                            {
                                log.SaveError("FillMandatory", Msg.GetElement(GetCtx(), "M_AttributeSetInstanceTo_ID"));
                                return(false);
                            }
                        }
                    }
                }
            }   //	ASI
            return(true);
        }