/// <summary>
        /// Is Used to get Name of Warehouse and Locator
        /// </summary>
        /// <param name="fields">contain M_Locator_ID reference</param>
        /// <returns>Warehouse and Locator Name</returns>
        /// <writer>Amit Bansal</writer>
        public JsonResult GetWarehouseAndLocatorName(string fields)
        {
            var labelInfo = "";
            Ctx ctx       = Session["ctx"] as Ctx;

            VAdvantage.Model.MLocator loc = VAdvantage.Model.MLocator.Get(ctx, Util.GetValueOfInt(fields));
            if (loc != null && loc.GetM_Locator_ID() > 0)
            {
                labelInfo = Msg.GetMsg(ctx, "M_Warehouse_ID") + " : " + loc.GetWarehouseName() + " , " + Msg.GetMsg(ctx, "M_Locator_ID") + " : " + loc.GetValue();
            }
            return(Json(JsonConvert.SerializeObject(labelInfo), JsonRequestBehavior.AllowGet));
        }
示例#2
0
        /// <summary>
        /// Before Save
        /// </summary>
        /// <param name="newRecord">new</param>
        /// <returns>true</returns>
        protected override Boolean BeforeSave(Boolean newRecord)
        {
            // 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  = DB.GetSQLValue(Get_TrxName(), sql);
                SetLine(ii);
            }

            // Check Locator For Header Warehouse
            MMovement mov = new MMovement(GetCtx(), GetM_Movement_ID(), Get_TrxName());

            VAdvantage.Model.MLocator      loc   = new VAdvantage.Model.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  = 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 (GetM_RequisitionLine_ID() > 0)
                {
                    VAdvantage.Model.MRequisitionLine reqline = new VAdvantage.Model.MRequisitionLine(GetCtx(), GetM_RequisitionLine_ID(), null);
                    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(), null);

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

            //	Qty Precision
            if (newRecord || Is_ValueChanged("QtyEntered"))
            {
                SetMovementQty(GetMovementQty());
            }
            int    M_Warehouse_ID = 0; VAdvantage.Model.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  = VAdvantage.Model.MWarehouse.Get(GetCtx(), M_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 (GetM_AttributeSetInstance_ID() != 0)
            {
                qry += " AND M_AttributeSetInstance_ID=" + GetM_AttributeSetInstance_ID();
            }
            OnHandQty = Convert.ToDecimal(DB.ExecuteScalar(qry));
            // when record is in completed & closed & Reversed stage - then no need to check qty availablity in warehouse
            if (wh.IsDisallowNegativeInv() == true && (!(move.GetDocStatus() == "CO" || move.GetDocStatus() == "CL" || move.GetDocStatus() == "RE")))
            {
                if (GetDescription() != "RC")
                {
                    if (GetMovementQty() < 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty));
                        //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null);
                        return(false);
                    }
                    else if ((OnHandQty - GetMovementQty()) < 0)
                    {
                        log.SaveError("Error", Msg.GetMsg(GetCtx(), "Qty Available " + OnHandQty));
                        //ShowMessage.Info("Qty Available " + OnHandQty, true, null, null);
                        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", Msg.GetElement(GetCtx(), "DTD001_QtyNotAvailable"));
                        return(false);
                    }
                }
            }
            //	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))
                    {
                        VAdvantage.Model.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
                    {
                        VAdvantage.Model.MProduct product = GetProduct();
                        if (product != null &&
                            product.GetM_AttributeSet_ID() != 0)
                        {
                            VAdvantage.Model.MAttributeSet mas = VAdvantage.Model.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);
        }
示例#3
0
        /// <summary>
        /// Create Difference Document.
        ///	Creates one or two inventory lines
        /// </summary>
        /// <param name="move">movement</param>
        /// <param name="confirm">confirm line</param>
        /// <returns>true if created</returns>
        private Boolean CreateDifferenceDoc(MMovement move, MMovementLineConfirm confirm)
        {
            string        query      = "";
            int           result     = 0;
            decimal       currentQty = 0;
            MMovementLine mLine      = confirm.GetLine();

            //	Difference - Create Inventory Difference for Source Location
            if (Env.ZERO.CompareTo(confirm.GetDifferenceQty()) != 0)
            {
                //	Get Warehouse for Source
                VAdvantage.Model.MLocator loc = VAdvantage.Model.MLocator.Get(GetCtx(), mLine.GetM_Locator_ID());
                if (_inventoryFrom != null &&
                    _inventoryFrom.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID())
                {
                    _inventoryFrom = null;
                }

                if (_inventoryFrom == null)
                {
                    VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID());
                    _inventoryFrom = new VAdvantage.Model.MInventory(wh);
                    _inventoryFrom.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo());
                    if (!_inventoryFrom.Save(Get_TrxName()))
                    {
                        _processMsg += "Inventory not created";
                        return(false);
                    }
                    //	First Inventory
                    if (GetM_Inventory_ID() == 0)
                    {
                        SetM_Inventory_ID(_inventoryFrom.GetM_Inventory_ID());
                        _inventoryInfo = _inventoryFrom.GetDocumentNo();
                    }
                    else
                    {
                        _inventoryInfo += "," + _inventoryFrom.GetDocumentNo();
                    }
                }

                log.Info("createDifferenceDoc - Difference=" + confirm.GetDifferenceQty());
                VAdvantage.Model.MInventoryLine line = new VAdvantage.Model.MInventoryLine(_inventoryFrom,
                                                                                           mLine.GetM_Locator_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(),
                                                                                           confirm.GetDifferenceQty(), Env.ZERO);
                //Added By amit 11-jun-2015
                //Opening Stock , Qunatity Book => CurrentQty From Transaction of MovementDate
                //As On Date Count = Opening Stock - Diff Qty
                //Qty Count = Qty Book - Diff Qty
                query  = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate = " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                           AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                result = Util.GetValueOfInt(DB.ExecuteScalar(query));
                if (result > 0)
                {
                    query      = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID =
                            (SELECT MAX(M_Transaction_ID)   FROM M_Transaction
                            WHERE movementdate =     (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate <= " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                    currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query));
                }
                else
                {
                    query  = "SELECT COUNT(*) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                    result = Util.GetValueOfInt(DB.ExecuteScalar(query));
                    if (result > 0)
                    {
                        query      = @"SELECT currentqty FROM M_Transaction WHERE M_Transaction_ID =
                            (SELECT MAX(M_Transaction_ID)   FROM M_Transaction
                            WHERE movementdate =     (SELECT MAX(movementdate) FROM M_Transaction WHERE movementdate < " + GlobalVariable.TO_DATE(move.GetMovementDate(), true) + @" 
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID() + @")
                            AND  M_Product_ID = " + mLine.GetM_Product_ID() + " AND M_Locator_ID = " + mLine.GetM_Locator_ID() + " AND M_AttributeSetInstance_ID = " + mLine.GetM_AttributeSetInstance_ID();
                        currentQty = Util.GetValueOfDecimal(DB.ExecuteScalar(query));
                    }
                }
                //End
                line.SetAdjustmentType("D");
                line.SetDifferenceQty(Util.GetValueOfDecimal(confirm.GetDifferenceQty()));
                line.SetQtyBook(currentQty);
                line.SetOpeningStock(currentQty);
                line.SetAsOnDateCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetOpeningStock()), Util.GetValueOfDecimal(confirm.GetDifferenceQty())));
                line.SetQtyCount(Decimal.Subtract(Util.GetValueOfDecimal(line.GetQtyBook()), Util.GetValueOfDecimal(confirm.GetDifferenceQty())));
                line.SetDescription(Msg.Translate(GetCtx(), "DifferenceQty"));
                if (!line.Save(Get_TrxName()))
                {
                    _processMsg += "Inventory Line not created";
                    return(false);
                }
                confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID());
            }   //	Difference

            //	Scrapped - Create Inventory Difference for TarGet Location
            if (Env.ZERO.CompareTo(confirm.GetScrappedQty()) != 0)
            {
                //	Get Warehouse for TarGet
                VAdvantage.Model.MLocator loc = VAdvantage.Model.MLocator.Get(GetCtx(), mLine.GetM_LocatorTo_ID());
                if (_inventoryTo != null &&
                    _inventoryTo.GetM_Warehouse_ID() != loc.GetM_Warehouse_ID())
                {
                    _inventoryTo = null;
                }

                if (_inventoryTo == null)
                {
                    VAdvantage.Model.MWarehouse wh = VAdvantage.Model.MWarehouse.Get(GetCtx(), loc.GetM_Warehouse_ID());
                    _inventoryTo = new VAdvantage.Model.MInventory(wh);
                    _inventoryTo.SetDescription(Msg.Translate(GetCtx(), "M_MovementConfirm_ID") + " " + GetDocumentNo());
                    if (!_inventoryTo.Save(Get_TrxName()))
                    {
                        _processMsg += "Inventory not created";
                        return(false);
                    }
                    //	First Inventory
                    if (GetM_Inventory_ID() == 0)
                    {
                        SetM_Inventory_ID(_inventoryTo.GetM_Inventory_ID());
                        _inventoryInfo = _inventoryTo.GetDocumentNo();
                    }
                    else
                    {
                        _inventoryInfo += "," + _inventoryTo.GetDocumentNo();
                    }
                }

                log.Info("CreateDifferenceDoc - Scrapped=" + confirm.GetScrappedQty());
                VAdvantage.Model.MInventoryLine line = new VAdvantage.Model.MInventoryLine(_inventoryTo,
                                                                                           mLine.GetM_LocatorTo_ID(), mLine.GetM_Product_ID(), mLine.GetM_AttributeSetInstance_ID(),
                                                                                           confirm.GetScrappedQty(), Env.ZERO);
                line.SetDescription(Msg.Translate(GetCtx(), "ScrappedQty"));
                if (!line.Save(Get_TrxName()))
                {
                    _processMsg += "Inventory Line not created";
                    return(false);
                }
                confirm.SetM_InventoryLine_ID(line.GetM_InventoryLine_ID());
            }   //	Scrapped

            return(true);
        }