예제 #1
0
        /**
         *  After Save
         *	@param newRecord new
         *	@param success success
         *	@return true
         */
        protected override bool AfterSave(bool newRecord, bool success)
        {
            if (!success)
            {
                return(success);
            }

            //	Update Products
            if (!newRecord)
            {
                MProduct[] products = MProduct.Get(GetCtx(), "S_Resource_ID IN "
                                                   + "(SELECT S_Resource_ID FROM S_Resource WHERE S_ResourceType_ID="
                                                   + GetS_ResourceType_ID() + ")", Get_TrxName());
                for (int i = 0; i < products.Length; i++)
                {
                    MProduct product = products[i];
                    if (product.SetResource(this))
                    {
                        product.Save(Get_TrxName());
                    }
                }
            }

            return(success);
        }
예제 #2
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);
        }
예제 #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
            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);
        }
예제 #4
0
 /// <summary>
 /// Get Product
 /// </summary>
 /// <returns>product or null if not defined</returns>
 public MProduct GetProduct()
 {
     if (GetM_Product_ID() != 0)
     {
         return(MProduct.Get(GetCtx(), GetM_Product_ID()));
     }
     return(null);
 }
예제 #5
0
 /**
  *  Get BOM Product
  *	@return product
  */
 public MProduct GetProduct()
 {
     if (_product == null && GetM_ProductBOM_ID() != 0)
     {
         _product = MProduct.Get(GetCtx(), GetM_ProductBOM_ID());
     }
     return(_product);
 }
 /// <summary>
 /// Get Product
 /// </summary>
 /// <returns>product</returns>
 public MProduct GetProduct()
 {
     if (_product == null)
     {
         _product = MProduct.Get(GetCtx(), GetM_Product_ID());
     }
     return(_product);
 }
예제 #7
0
 /// <summary>
 /// Get included component
 /// </summary>
 /// <returns>product</returns>
 /// <writer>raghu</writer>
 /// <date>08-march-2011</date>
 public MProduct GetComponent()
 {
     if (_component == null && GetM_ProductBOM_ID() != 0)
     {
         _component = MProduct.Get(GetCtx(), GetM_ProductBOM_ID());
     }
     return(_component);
 }
예제 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="M_Product_ID"></param>
 /// <param name="M_AttributeSetInstance_ID"></param>
 /// <param name="trxName"></param>
 public ProductCost(Ctx ctx, int M_Product_ID, int M_AttributeSetInstance_ID, Trx trxName)
 {
     _M_Product_ID = M_Product_ID;
     if (_M_Product_ID != 0)
     {
         _product = MProduct.Get(ctx, M_Product_ID);
     }
     _M_AttributeSetInstance_ID = M_AttributeSetInstance_ID;
     _trx = trxName;
 }
 /**
  *  Get Product
  *	@return product
  */
 public MProduct GetProduct()
 {
     if (_product == null)
     {
         MProduct[] products = MProduct.Get(GetCtx(), "S_Resource_ID=" + GetS_Resource_ID(), Get_TrxName());
         if (products.Length > 0)
         {
             _product = products[0];
         }
     }
     return(_product);
 }
예제 #10
0
 /**
  *  Set M_Product_ID
  *	@param M_Product_ID product
  *	@param setUOM also set UOM from product
  */
 public void SetM_Product_ID(int M_Product_ID, bool setUOM)
 {
     if (setUOM)
     {
         SetProduct(MProduct.Get(GetCtx(), M_Product_ID));
     }
     else
     {
         base.SetM_Product_ID(M_Product_ID);
     }
     SetM_AttributeSetInstance_ID(0);
 }
예제 #11
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);
        }
예제 #12
0
        /// <summary>
        /// Is used to check costing method belongs to PO costing method  like (Average PO, Weighted Average PO or Last PO)
        /// Firts we check costing method on Product category, if not found then we will check on Primary Accounting Schema
        /// </summary>
        /// <param name="ctx">current context</param>
        /// <param name="AD_Client_ID">Client reference</param>
        /// <param name="M_Product_ID">Product whom costing method is to be determine</param>
        /// <param name="trxName">Transaction</param>
        /// <returns>True/False</returns>
        public static bool IsPOCostingmethod(Ctx ctx, int AD_Client_ID, int M_Product_ID, Trx trxName)
        {
            MProductCategory pc = null;
            bool             isPOcostingMethod = false;
            string           costingMethod     = null;
            MClient          client            = MClient.Get(ctx, AD_Client_ID);
            MProduct         product           = MProduct.Get(ctx, M_Product_ID);

            if (product != null)
            {
                pc = MProductCategory.Get(product.GetCtx(), product.GetM_Product_Category_ID());
                if (pc != null)
                {
                    // check costing method from product category
                    costingMethod = pc.GetCostingMethod();
                    if (costingMethod == "C")
                    {
                        costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + pc.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                    }
                }
                if (String.IsNullOrEmpty(costingMethod))
                {
                    // check costing method against primary accounting schema
                    MClientInfo clientInfo = MClientInfo.Get(ctx, AD_Client_ID);
                    MAcctSchema actSchema  = MAcctSchema.Get(ctx, clientInfo.GetC_AcctSchema1_ID());
                    if (actSchema != null)
                    {
                        costingMethod = actSchema.GetCostingMethod();
                        if (costingMethod == "C")
                        {
                            costingMethod = Util.GetValueOfString(DB.ExecuteScalar(@"SELECT costingmethod FROM M_CostElement WHERE M_CostElement_ID IN 
                                        (SELECT CAST(M_Ref_CostElement AS INTEGER) FROM M_CostElementLine WHERE M_CostElement_ID=" + actSchema.GetM_CostElement_ID() + @" )
                                        AND CostingMethod IS NOT NULL", null, trxName));
                        }
                    }
                }
            }
            if (costingMethod.Equals(COSTINGMETHOD_WeightedAveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_AveragePO) ||
                costingMethod.Equals(COSTINGMETHOD_LastPOPrice))
            {
                isPOcostingMethod = true;
            }
            else
            {
                isPOcostingMethod = false;
            }

            return(isPOcostingMethod);
        }
예제 #13
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);
        }
예제 #14
0
 //*****Manfacturing
 /// <summary>
 /// After Delete
 /// </summary>
 /// <param name="success">success</param>
 /// <returns>true</returns>
 /// <writer>raghu</writer>
 /// <date>08-march-2011</date>
 protected override Boolean AfterDelete(Boolean success)
 {
     MBOMProduct[] lines = MBOMProduct.GetBOMLines(GetBOM());
     if (lines == null || 0 == lines.Length || (1 == lines.Length && lines[0].GetM_BOMProduct_ID() == GetM_BOMProduct_ID()))
     {
         MProduct product = MProduct.Get(GetCtx(), _bom.GetM_Product_ID());
         product.SetIsVerified(false);
         if (!product.Save(Get_Trx()))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #15
0
        /// <summary>
        /// Get Product Details
        /// </summary>
        /// <returns>Product Name, etc.</returns>
        public String GetProductDetailHTML()
        {
            if (GetM_Product_ID() == 0)
            {
                return("");
            }
            StringBuilder sb      = new StringBuilder();
            MProduct      product = MProduct.Get(GetCtx(), GetM_Product_ID());

            sb.Append(product.GetName());
            if (product.GetDescription() != null && product.GetDescription().Length > 0)
            {
                sb.Append("<br><i>").Append(product.GetDescription()).Append("</i>");
            }
            return(sb.ToString());
        }
        //*****Manfacturing
        /// <summary>
        /// After Delete
        /// </summary>
        /// <param name="success">success</param>
        /// <returns>true</returns>
        /// <writer>raghu</writer>
        /// <date>08-march-2011</date>
        protected override Boolean AfterDelete(Boolean success)
        {
            //MBOMProduct[] lines = MBOMProduct.GetBOMLines(GetBOM());
            //if (lines == null || 0 == lines.Length || (1 == lines.Length && lines[0].GetM_BOMProduct_ID() == GetM_BOMProduct_ID()))
            //{
            // when we delete any record, then make isverfied as false on product
            MBOM     _bom    = new MBOM(GetCtx(), GetM_BOM_ID(), Get_Trx());
            MProduct product = MProduct.Get(GetCtx(), _bom.GetM_Product_ID());

            product.SetIsVerified(false);
            if (!product.Save(Get_Trx()))
            {
                return(false);
            }
            //}
            return(true);
        }
        /// <summary>
        /// Get Product
        /// </summary>
        /// <returns>product or null if not defined</returns>
        public MProduct GetProduct()
        {
            int M_Product_ID = GetM_Product_ID();

            if (M_Product_ID == 0)
            {
                return(null);
            }
            if (_product != null && _product.GetM_Product_ID() != M_Product_ID)
            {
                _product = null;        //	reset
            }
            if (_product == null)
            {
                _product = MProduct.Get(GetCtx(), M_Product_ID);
            }
            return(_product);
        }
        protected override bool BeforeSave(bool newRecord)
        {
            // Movement Quantity can not be less than 0 when planned is greater than 0
            if (GetPlannedQty() > 0 && GetMovementQty() < 0)
            {
                log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbelesszero"));
                return(false);
            }

            // Movement Quantity can not be greater than 0 when planned is less than 0
            if (GetPlannedQty() < 0 && GetMovementQty() > 0)
            {
                log.SaveWarning("Warning", Msg.GetMsg(GetCtx(), "MovementQtyCantbegrtzero"));
                return(false);
            }

            // when warehouse disallow negative inventory is false then on hand qty can't be in negative
            wh = MWarehouse.Get(GetCtx(), GetM_Warehouse_ID());
            if (wh.IsDisallowNegativeInv() && GetM_Product_ID() > 0)
            {
                product = MProduct.Get(GetCtx(), GetM_Product_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 NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID();
                //}
                Decimal?OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));

                qry = @"SELECT NVL(SUM(MovementQty) , 0) FROM M_ProductionLine WHERE IsActive = 'Y' AND  M_Locator_ID=" + GetM_Locator_ID() + @" AND m_product_id=" + GetM_Product_ID() +
                      @" AND NVL(M_AttributeSetInstance_ID , 0) =" + GetM_AttributeSetInstance_ID() + @" AND M_Production_ID = " + GetM_Production_ID();
                if (!newRecord)
                {
                    qry += @" AND M_ProductionLine_ID <> " + GetM_ProductionLine_ID();
                }
                Decimal?moveQty = Convert.ToDecimal(DB.ExecuteScalar(qry));
                if ((OnHandQty + GetMovementQty() + moveQty) < 0)
                {
                    log.SaveError("", product.GetName() + ", " + Msg.GetMsg(GetCtx(), "VIS_InsufficientQty") + OnHandQty);
                    return(false);
                }
            }

            return(true);
        }
예제 #19
0
        /// <summary>
        /// Get Product Conversions (cached)
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Product_ID"></param>
        /// <returns>array of conversions</returns>
        public static MUOMConversion[] GetProductConversions(Ctx ctx, int M_Product_ID)
        {
            if (M_Product_ID == 0)
            {
                return(new MUOMConversion[0]);
            }
            int key = M_Product_ID;

            MUOMConversion[] result = (MUOMConversion[])_conversionProduct[key];
            if (result != null)
            {
                return(result);
            }

            List <MUOMConversion> list = new List <MUOMConversion>();

            //
            String sql = "SELECT * FROM C_UOM_Conversion c "
                         + "WHERE c.M_Product_ID=" + M_Product_ID
                         + " AND EXISTS (SELECT * FROM M_Product p "
                         + "WHERE c.M_Product_ID=p.M_Product_ID AND c.C_UOM_ID=p.C_UOM_ID)"
                         + " AND c.IsActive='Y'";
            DataTable   dt   = null;
            IDataReader idr  = null;
            DataTable   dt1  = null;
            IDataReader idr1 = null;

            try
            {
                idr = DB.ExecuteReader(sql, null, null);
                dt  = new DataTable();
                dt.Load(idr);
                idr.Close();
                foreach (DataRow dr in dt.Rows)
                {
                    list.Add(new MUOMConversion(ctx, dr, null));
                }

                if (list.Count == 0)
                {
                    sql = "SELECT * FROM C_UOM_Conversion c "
                          + "WHERE EXISTS (SELECT * FROM M_Product p "
                          + "WHERE c.C_UOM_ID=p.C_UOM_ID AND p.M_Product_ID=" + M_Product_ID + ")"
                          + " AND c.IsActive='Y'";

                    idr1 = DB.ExecuteReader(sql, null, null);
                    dt1  = new DataTable();
                    dt1.Load(idr1);
                    idr1.Close();
                    foreach (DataRow dr1 in dt1.Rows)
                    {
                        list.Add(new MUOMConversion(ctx, dr1, null));
                    }
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                if (idr1 != null)
                {
                    idr1.Close();
                    idr1 = null;
                }
                _log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                if (idr != null)
                {
                    idr.Close();
                    idr = null;
                }
                if (idr1 != null)
                {
                    idr1.Close();
                    idr1 = null;
                }
                dt  = null;
                dt1 = null;
            }
            //	Add default conversion
            if (list.Count == 0)
            {
                MUOMConversion defRate = new MUOMConversion(MProduct.Get(ctx, M_Product_ID));
                list.Add(defRate);
            }

            //	Convert & save
            result = new MUOMConversion[list.Count];
            result = list.ToArray();
            _conversionProduct.Add(key, result);
            _log.Fine("GetProductConversions - M_Product_ID=" + M_Product_ID + " #" + result.Length);
            return(result);
        }
        /**
         *  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;
                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());
                    }

                    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());
                        // new 6jan  0
                        int _count = Util.GetValueOfInt(DB.ExecuteScalar(" SELECT Count(*) FROM AD_Column WHERE columnname = 'DTD001_SourceReserve' "));

                        //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 (Env.IsModuleInstalled("VA203_") && product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item)
                        {
                            if (GetDocAction() != "VO" && GetDocStatus() != "DR")
                            {
                                if (quant > 0)
                                {
                                    //int loc_id = GetLocation(GetM_Warehouse_ID());
                                    int loc_id = line.GetOrderLocator_ID();
                                    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.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                                    storage.Save();
                                    //new 6jan 5
                                    if (_count > 0)
                                    {
                                        //int Swhloc_id = GetSwhLocation(GetDTD001_MWarehouseSource_ID());
                                        int Swhloc_id = line.GetReserveLocator_ID();
                                        Swhstorage = MStorage.Get(GetCtx(), Swhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                        if (Swhstorage == null)
                                        {
                                            Swhstorage = MStorage.GetCreate(GetCtx(), Swhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                        }
                                        Swhstorage.SetDTD001_SourceReserve((Decimal.Subtract(Swhstorage.GetDTD001_SourceReserve(), (Decimal)quant)));
                                        Swhstorage.Save();
                                    }
                                    //end
                                }
                            }
                        }
                        else if (GetDocAction() != "VO" && GetDocStatus() != "DR" && product != null && product.GetProductType() == X_M_Product.PRODUCTTYPE_Item)
                        {
                            if (quant > 0)
                            {
                                int loc_id = 0;
                                if (line.Get_ColumnIndex("OrderLocator_ID") > 0)
                                {
                                    loc_id = line.GetOrderLocator_ID();
                                }
                                else
                                {
                                    loc_id = GetLocation(GetM_Warehouse_ID());
                                }
                                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.Subtract(storage.GetDTD001_QtyReserved(), (Decimal)quant)));
                                storage.Save();

                                //new 6jan 6
                                if (_count > 0)
                                {
                                    int Swhloc_id = 0;
                                    if (line.Get_ColumnIndex("ReserveLocator_ID") > 0)
                                    {
                                        Swhloc_id = line.GetReserveLocator_ID();
                                    }
                                    else
                                    {
                                        Swhloc_id = GetSwhLocation(GetM_Warehouse_ID());
                                    }
                                    Swhstorage = MStorage.Get(GetCtx(), Swhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                    if (Swhstorage == null)
                                    {
                                        Swhstorage = MStorage.GetCreate(GetCtx(), Swhloc_id, line.GetM_Product_ID(), line.GetM_AttributeSetInstance_ID(), Get_Trx());
                                    }
                                    Swhstorage.SetDTD001_SourceReserve((Decimal.Subtract(Swhstorage.GetDTD001_SourceReserve(), (Decimal)quant)));
                                    Swhstorage.Save();
                                }
                                //end
                            }
                        }
                    }
                    //	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);
        }
        /// <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);
        }
예제 #22
0
        /**
         *  Set Qty
         *	@param windowNo window
         *	@param columnName column
         */
        private void SetQty(int windowNo, String columnName)
        {
            int M_Product_ID = GetM_Product_ID();

            log.Log(Level.WARNING, "qty - init - M_Product_ID=" + M_Product_ID);
            Decimal MovementQty, QtyEntered;
            int     C_UOM_To_ID = GetC_UOM_ID();

            //	No Product
            if (M_Product_ID == 0)
            {
                QtyEntered = GetQtyEntered();
                SetMovementQty(QtyEntered);
            }
            //	UOM Changed - convert from Entered -> Product
            else if (columnName.Equals("C_UOM_ID"))
            {
                QtyEntered = GetQtyEntered();
                //Decimal QtyEntered1 = QtyEntered.setScale(MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), Decimal.ROUND_HALF_UP);
                Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero);
                if (QtyEntered.CompareTo(QtyEntered1) != 0)
                {
                    log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID
                             + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1);
                    QtyEntered = QtyEntered1;
                    SetQtyEntered(QtyEntered);
                }
                MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(), M_Product_ID, C_UOM_To_ID, QtyEntered);
                if (MovementQty == null)
                {
                    MovementQty = QtyEntered;
                }
                bool conversion = QtyEntered.CompareTo(MovementQty) != 0;

                log.Fine("UOM=" + C_UOM_To_ID
                         + ", QtyEntered=" + QtyEntered
                         + " -> " + conversion
                         + " MovementQty=" + MovementQty);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetMovementQty(MovementQty);
            }
            //	No UOM defined
            else if (C_UOM_To_ID == 0)
            {
                QtyEntered = GetQtyEntered();
                SetMovementQty(QtyEntered);
            }
            //	QtyEntered changed - calculate MovementQty
            else if (columnName.Equals("QtyEntered"))
            {
                QtyEntered = GetQtyEntered();
                Decimal QtyEntered1 = Decimal.Round(QtyEntered, MUOM.GetPrecision(GetCtx(), C_UOM_To_ID), MidpointRounding.AwayFromZero);
                if (QtyEntered.CompareTo(QtyEntered1) != 0)
                {
                    log.Fine("Corrected QtyEntered Scale UOM=" + C_UOM_To_ID
                             + "; QtyEntered=" + QtyEntered + "->" + QtyEntered1);
                    QtyEntered = QtyEntered1;
                    SetQtyEntered(QtyEntered);
                }
                MovementQty = (Decimal)MUOMConversion.ConvertProductFrom(GetCtx(),
                                                                         M_Product_ID, C_UOM_To_ID, QtyEntered);
                if (MovementQty == null)
                {
                    MovementQty = QtyEntered;
                }
                bool conversion = QtyEntered.CompareTo(MovementQty) != 0;

                log.Fine("UOM=" + C_UOM_To_ID
                         + ", QtyEntered=" + QtyEntered
                         + " -> " + conversion
                         + " MovementQty=" + MovementQty);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetMovementQty(MovementQty);
            }
            //	MovementQty changed - calculate QtyEntered (should not happen)
            else if (columnName.Equals("MovementQty"))
            {
                MovementQty = GetMovementQty();
                int precision = MProduct.Get(GetCtx(), M_Product_ID).GetUOMPrecision();
                //Decimal MovementQty1 = MovementQty.setScale(precision, Decimal.ROUND_HALF_UP);
                Decimal MovementQty1 = Decimal.Round(MovementQty, precision, MidpointRounding.AwayFromZero);// Env.Scale(MovementQty);
                if (MovementQty.CompareTo(MovementQty1) != 0)
                {
                    log.Fine("Corrected MovementQty "
                             + MovementQty + "->" + MovementQty1);
                    MovementQty = MovementQty1;
                    SetMovementQty(MovementQty);
                }
                QtyEntered = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID, C_UOM_To_ID, MovementQty);
                if (QtyEntered == null)
                {
                    QtyEntered = MovementQty;
                }
                bool conversion = MovementQty.CompareTo(QtyEntered) != 0;
                log.Fine("UOM=" + C_UOM_To_ID
                         + ", MovementQty=" + MovementQty
                         + " -> " + conversion
                         + " QtyEntered=" + QtyEntered);

                //p_changeVO.setContext(getCtx(), windowNo, "UOMConversion", conversion);
                SetQtyEntered(QtyEntered);
            }

            // RMA : Check qty returned is more than qty shipped
            bool IsReturnTrx = GetParent().IsReturnTrx();

            if (M_Product_ID != 0 && IsReturnTrx)
            {
                int        oLine_ID = GetC_OrderLine_ID();
                MOrderLine oLine    = new MOrderLine(GetCtx(), oLine_ID, null);
                if (oLine.Get_ID() != 0)
                {
                    int orig_IOLine_ID = oLine.GetOrig_InOutLine_ID();
                    if (orig_IOLine_ID != 0)
                    {
                        MInOutLine orig_IOLine = new MInOutLine(GetCtx(), orig_IOLine_ID, null);
                        Decimal    shippedQty  = orig_IOLine.GetMovementQty();
                        MovementQty = GetMovementQty();
                        if (shippedQty.CompareTo(MovementQty) < 0)
                        {
                            if (GetCtx().IsSOTrx(windowNo))
                            {
                                //   p_changeVO.addError(Msg.getMsg(getCtx(), "QtyShippedLessThanQtyReturned", shippedQty));
                            }
                            else
                            {
                                // p_changeVO.addError(Msg.getMsg(getCtx(), "QtyReceivedLessThanQtyReturned", shippedQty));
                            }

                            SetMovementQty(shippedQty);
                            MovementQty = shippedQty;
                            QtyEntered  = (Decimal)MUOMConversion.ConvertProductTo(GetCtx(), M_Product_ID,
                                                                                   C_UOM_To_ID, MovementQty);
                            if (QtyEntered == null)
                            {
                                QtyEntered = MovementQty;
                            }
                            SetQtyEntered(QtyEntered);
                            log.Fine("QtyEntered : " + QtyEntered.ToString() +
                                     "MovementQty : " + MovementQty.ToString());
                        }
                    }
                }
            }
        }
        /**
         *  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);
        }
예제 #24
0
        /// <summary>
        /// detail Add
        /// Warehouse must already be validated
        /// diffQty must always be positive; negative values are not processed
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="M_Warehouse_ID"></param>
        /// <param name="M_Locator_ID"></param>
        /// <param name="M_Product_ID"></param>
        /// <param name="M_AttributeSetInstance_ID"></param>
        /// <param name="reservationAttributeSetInstance_ID"></param>
        /// <param name="diffQty"></param>
        /// <param name="type"></param>
        /// <param name="trx"></param>
        /// <returns></returns>
        public static Boolean Add(Ctx ctx, int M_Warehouse_ID, int M_Locator_ID,
                                  int M_Product_ID, int M_AttributeSetInstance_ID,
                                  int reservationAttributeSetInstance_ID, Decimal diffQty,
                                  String type, Trx trx)
        {
            StringBuilder  diffText = new StringBuilder("(");
            MStorageDetail storage  = null;

            storage = MStorageDetail.GetCreate(ctx, M_Locator_ID, M_Product_ID,
                                               M_AttributeSetInstance_ID, type, trx);
            // Verify
            if (storage.GetM_Locator_ID() != M_Locator_ID &&
                storage.GetM_Product_ID() != M_Product_ID &&
                storage.GetM_AttributeSetInstance_ID() != M_AttributeSetInstance_ID)
            {
                s_log.Severe("No Storage found - M_Locator_ID=" + M_Locator_ID
                             + ",M_Product_ID=" + M_Product_ID + ",ASI="
                             + M_AttributeSetInstance_ID);
                return(false);
            }

            MStorageDetail storageASI = null;

            if ((M_AttributeSetInstance_ID != reservationAttributeSetInstance_ID) &&
                (type == X_Ref_Quantity_Type.RESERVED || type == X_Ref_Quantity_Type.ORDERED))
            {
                int reservationM_Locator_ID = M_Locator_ID;
                if (reservationAttributeSetInstance_ID == 0)
                {
                    MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID);
                    reservationM_Locator_ID = wh.GetDefaultM_Locator_ID();
                }
                storageASI = MStorageDetail.Get(ctx, reservationM_Locator_ID,
                                                M_Product_ID, reservationAttributeSetInstance_ID, type,
                                                true, trx);
                if (storageASI == null) // create if not existing - should not happen
                {
                    MProduct product       = MProduct.Get(ctx, M_Product_ID);
                    int      xM_Locator_ID = MProductLocator.GetFirstM_Locator_ID(product, M_Warehouse_ID);
                    if (xM_Locator_ID == 0)
                    {
                        MWarehouse wh = MWarehouse.Get(ctx, M_Warehouse_ID);
                        xM_Locator_ID = wh.GetDefaultM_Locator_ID();
                    }
                    storageASI = MStorageDetail.GetCreate(ctx, xM_Locator_ID,
                                                          M_Product_ID, reservationAttributeSetInstance_ID, type,
                                                          trx);
                }
            }
            Boolean changed = false;

            if (Env.Signum(diffQty) != 0)
            {
                if (storageASI == null)
                {
                    storage.SetQty(Decimal.Add(storage.GetQty(), diffQty));
                }
                else
                {
                    storageASI.SetQty(Decimal.Add(storageASI.GetQty(), diffQty));
                }
                diffText.Append(type.ToString()).Append("=").Append(diffQty);
                changed = true;
            }
            if (changed)
            {
                diffText.Append(") -> ").Append(storage.ToString());
                s_log.Fine(diffText.ToString());
                if (storageASI != null)
                {
                    storageASI.Save(trx); // No AttributeSetInstance
                }
                // (reserved/ordered)
                return(storage.Save(trx));
            }
            return(true);
        }
        /// <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);
        }
예제 #26
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);
        }
예제 #27
0
        /// <summary>
        /// Process Issue
        /// </summary>
        /// <returns>true if processed</returns>
        public bool Process()
        {
            if (!Save())
            {
                return(false);
            }
            if (GetM_Product_ID() == 0)
            {
                log.Log(Level.SEVERE, "No Product");
                return(false);
            }

            MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());

            //	If not a stocked Item nothing to do
            if (!product.IsStocked())
            {
                SetProcessed(true);
                return(Save());
            }

            /** @todo Transaction */

            //	**	Create Material Transactions **
            MTransaction mTrx = new MTransaction(GetCtx(), GetAD_Org_ID(),
                                                 MTransaction.MOVEMENTTYPE_WorkOrderPlus,
                                                 GetM_Locator_ID(), GetM_Product_ID(), GetM_AttributeSetInstance_ID(),
                                                 Decimal.Negate(GetMovementQty()), GetMovementDate(), Get_TrxName());

            mTrx.SetC_ProjectIssue_ID(GetC_ProjectIssue_ID());
            //
            MLocator loc = MLocator.Get(GetCtx(), GetM_Locator_ID());

            if (MStorage.Add(GetCtx(), loc.GetM_Warehouse_ID(), GetM_Locator_ID(),
                             GetM_Product_ID(), GetM_AttributeSetInstance_ID(), GetM_AttributeSetInstance_ID(),
                             Decimal.Negate(GetMovementQty()), null, null, Get_TrxName()))
            {
                if (mTrx.Save(Get_TrxName()))
                {
                    SetProcessed(true);
                    if (Save())
                    {
                        return(true);
                    }
                    else
                    {
                        log.Log(Level.SEVERE, "Issue not saved");               //	requires trx !!
                    }
                }
                else
                {
                    log.Log(Level.SEVERE, "Transaction not saved");     //	requires trx !!
                }
            }
            else
            {
                log.Log(Level.SEVERE, "Storage not updated");                   //	OK
            }
            //
            return(false);
        }
예제 #28
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true if can be saved</returns>
        protected override bool BeforeSave(bool newRecord)
        {
            if (newRecord && _isManualEntry)
            {
                //	Product requires ASI
                if (GetM_AttributeSetInstance_ID() == 0)
                {
                    MProduct product = MProduct.Get(GetCtx(), GetM_Product_ID());
                    if (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_AttributeSetInstance_ID"));
                            return(false);
                        }
                    }
                } //	No ASI
            }     //	new or manual

            //	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);
            }
            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));

            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));
            if (wh.IsDisallowNegativeInv() == true)
            {
                if (GetQtyCount() < 0)
                {
                    if (wh.IsDisallowNegativeInv() == true)
                    {
                        //ShowMessage.Info("Qty Available  " + OnHandQty, true, null, null);
                        return(false);
                    }
                }
                else if ((GetQtyInternalUse() > 0))
                {
                    if ((OnHandQty - GetQtyInternalUse()) < 0)
                    {
                        if (wh.IsDisallowNegativeInv() == true)
                        {
                            //ShowMessage.Info("Qty Available  " + OnHandQty, true, null, null);
                            return(false);
                        }
                    }
                }
                else if ((GetQtyInternalUse() < 0))
                {
                    if (wh.IsDisallowNegativeInv() == true)
                    {
                        //ShowMessage.Info("Qty Available  " + OnHandQty, true, null, null);
                        return(false);
                    }
                }
            }
            //	Enforce Qty UOM
            if (newRecord || Is_ValueChanged("QtyCount"))
            {
                SetQtyCount(GetQtyCount());
            }
            if (newRecord || Is_ValueChanged("QtyInternalUse"))
            {
                SetQtyInternalUse(GetQtyInternalUse());
            }

            //	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("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());
            }

            return(true);
        }