示例#1
0
        // GET: PickRawMtrl/Details/5
        public ActionResult Pick(Guid id, bool isFirstGet = true)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            List <PickRawMtrlModel> entitys   = (List <PickRawMtrlModel>)Session["PickRawMtrlModels"];
            PickRawMtrlModel        objEntity = entitys.Where(w => w.SysRowId == id).FirstOrDefault();

            //if (isFirstGet)
            //{
            objEntity.Qty = objEntity.ActQty;
            //Session["ScanLotPRMLst"] = null;
            //Testing purpose
            //objEntity.ConvFactor = 5;
            //}
            //else
            //{
            if (Session["ScanLotPRMLst"] != null)
            {
                List <PickRawMtrlModel> objScanLotPRMList = (List <PickRawMtrlModel>)Session["ScanLotPRMLst"];
                decimal scanqty = objScanLotPRMList.Sum(s => s.Qty);

                objEntity.Qty = objEntity.ActQty - scanqty;

                //remainConvFactor from prev
                foreach (var c in objScanLotPRMList)
                {
                    objEntity.ConvFactor = c.ConvFactor;
                }

                ViewBag.ScanListCount = objScanLotPRMList.Count;
            }
            //}



            //drop down data
            ViewBag.PalletTypeInfo = new SelectList(objEntity.PalletTypeInfo, "PartNum", "PartNum");
            //ViewBag.PalletTypeInfo = objEntity.PalletTypeInfo.Select(s => new SelectList(new[] { new { value = s.PartNum, text = s.PartNum } }));
            return(View(objEntity));
        }
示例#2
0
        // POST: api/PickRawMtrl
        public HttpResponseMessage Post([FromBody] PickRawMtrlModel objPickRawMtrlModel)
        {
            try
            {
                if (objPickRawMtrlModel != null)
                {
                    if (string.IsNullOrEmpty(objPickRawMtrlModel.ToBinNum))
                    {
                        throw new Exception("To Bin is required!"); //No Transit Bin
                    }

                    PickRawMtrl objPRM = new PickRawMtrl
                    {
                        Company     = objPickRawMtrlModel.Company,
                        Plant       = objPickRawMtrlModel.Plant,
                        JobNum      = objPickRawMtrlModel.JobNum,
                        RequestDate = objPickRawMtrlModel.RequestDate,
                        PartNum     = objPickRawMtrlModel.PartNum,
                        PartDesc    = objPickRawMtrlModel.PartDesc,
                        LotNo       = objPickRawMtrlModel.LotNo,
                        TuId        = objPickRawMtrlModel.TuId,
                        ActQty      = objPickRawMtrlModel.ActQty,
                        Qty         = objPickRawMtrlModel.Qty,
                        UOM         = objPickRawMtrlModel.UOM,
                        PickQty     = objPickRawMtrlModel.PickQty,
                        PickUOM     = objPickRawMtrlModel.PickUOM,
                        FromWarehse = objPickRawMtrlModel.FromWarehse, //Must from Transit Bin. To here is refer to UD21. ShortChar08
                        FromBinNum  = objPickRawMtrlModel.FromBinNum,  //Must from Transit Bin. To here is refer to UD21. ShortChar08
                        ToWarehse   = objPickRawMtrlModel.ToWarehse,   //To PMC Wh . Refer to UD21. ShortChar03
                        ToBinNum    = objPickRawMtrlModel.ToBinNum,    //TO PMC Bin . Refer to UD21. ShortChar04
                        //FromWarehse = objPickRawMtrlModel.FromWarehse,
                        //FromBinNum = objPickRawMtrlModel.FromBinNum,
                        //ToWarehse = objPickRawMtrlModel.ToWarehse,
                        //ToBinNum = objPickRawMtrlModel.ToBinNum,
                        PalletType  = objPickRawMtrlModel.PalletType,
                        PalletQty   = objPickRawMtrlModel.PalletQty,
                        UserId      = objPickRawMtrlModel.UserId,
                        SysRowId    = objPickRawMtrlModel.SysRowId,
                        CreatedUtc  = DateTime.Now,
                        ConvFactor  = objPickRawMtrlModel.ConvFactor,
                        DynamicPick = objPickRawMtrlModel.DynamicPick
                    };
                    //Validation
                    if (string.IsNullOrEmpty(objPRM.Company))
                    {
                        throw new Exception("Company is Require!");
                    }
                    if (string.IsNullOrEmpty(objPRM.PartNum))
                    {
                        throw new Exception("PartNum is Require!");
                    }
                    if (string.IsNullOrEmpty(objPRM.LotNo))
                    {
                        throw new Exception("LotNum is Require!");
                    }
                    if (string.IsNullOrEmpty(objPRM.FromWarehse))
                    {
                        throw new Exception("FromWarehse is Require!");
                    }
                    if (string.IsNullOrEmpty(objPRM.FromBinNum))
                    {
                        throw new Exception("FromBinNum is Require!");
                    }
                    if (objPRM.Qty <= 0)
                    {
                        throw new Exception("Qty is Require!");
                    }
                    if (string.IsNullOrEmpty(objPRM.PalletType))
                    {
                        //throw new Exception("PalletType is Require!");
                    }
                    if (!string.IsNullOrEmpty(objPRM.PalletType) && objPRM.PalletQty <= 0)
                    {
                        throw new Exception("PalletQty is Require!");
                    }
                    EpicorDbContext epicorDbContext = new EpicorDbContext();
                    //DBValidation for (Lot,FromWH and FromBin,OnHandQty,ToWH ,ToBin) And Also for (PalletType and Qty)
                    StringBuilder sbVQry = new StringBuilder();
                    sbVQry.Append(" select case ");
                    sbVQry.Append($" When (select top 1 LotNum from PartLot where Company='{objPRM.Company}' and PartNum='{objPRM.PartNum}' and LotNum='{objPRM.LotNo}'  ) is null then 'LotNum {objPRM.LotNo} was not found!' ");
                    sbVQry.Append($" When (select top 1 WarehouseCode as FromWH from erp.PartWhse where Company='{objPRM.Company}' and PartNum='{objPRM.PartNum}' and WarehouseCode='{objPRM.FromWarehse}'  ) is null then 'FromWarehouse {objPRM.FromWarehse} not found!' ");
                    sbVQry.Append($" When (select top 1 b.BinNum as FromBin from erp.PartWhse a inner join WhseBin b on a.Company=b.Company and a.WarehouseCode=b.WarehouseCode where a.Company='{objPRM.Company}' and a.PartNum='{objPRM.PartNum}' and a.WarehouseCode='{objPRM.FromWarehse}' and b.BinNum='{objPRM.FromBinNum}'  ) is null then 'FromBinNum {objPRM.FromBinNum} not found!' ");
                    sbVQry.Append($" When (select Top 1 (OnhandQty-AllocatedQty) as Qty from erp.PartBin where Company='{objPRM.Company}' and PartNum='{objPRM.PartNum}' and LotNum='{objPRM.LotNo}' and OnhandQty-AllocatedQty >= {objPRM.Qty} ) is null then 'OnHandQty not Enough!' ");
                    sbVQry.Append($" When (select top 1 WarehouseCode as ToWH from erp.PartWhse where Company='{objPRM.Company}' and PartNum='{objPRM.PartNum}' and WarehouseCode='{objPRM.ToWarehse}' ) is null then 'ToWarehouse {objPRM.ToWarehse} not found!' ");
                    sbVQry.Append($" When (select top 1 b.BinNum as ToBin from erp.PartWhse a inner join WhseBin b on a.Company=b.Company and a.WarehouseCode=b.WarehouseCode where a.Company='{objPRM.Company}' and a.PartNum='{objPRM.PartNum}' and a.WarehouseCode='{objPRM.ToWarehse}' and b.BinNum='{objPRM.ToBinNum}' ) is null then 'ToBinNum {objPRM.ToBinNum} not found!' ");
                    sbVQry.Append(" else '0' end ");
                    string errMsg = epicorDbContext.Database.SqlQuery <string>(sbVQry.ToString()).SingleOrDefault();
                    if (errMsg != "0")
                    {
                        throw new Exception(errMsg);
                    }
                    //Validation of SysRevId
                    //string revQry = "Select SysRevId from erp.JobMtl Where SysRowId=@SysRowId";
                    //EpicorDbContext epicorDbContext = new EpicorDbContext();
                    //Type obj=null;
                    //epicorDbContext.Database.SqlQuery(obj, revQry, new SqlParameter("@SysRowId", objPickRawMtrlModel.SysRowId.ToString()));
                    //string epiSysRevId = obj.ToString();

                    //Do Inventory Transfer to PMC Warehouse Transit Bin (Table WhseBin, Column FS_PMCTransit_c)
                    InvTransfer objInvTran = new InvTransfer();
                    objInvTran.company      = objPickRawMtrlModel.Company;
                    objInvTran.frmBinNum    = objPickRawMtrlModel.FromBinNum;
                    objInvTran.frmLotNum    = objPickRawMtrlModel.LotNo;
                    objInvTran.frmWarehouse = objPickRawMtrlModel.FromWarehse;
                    objInvTran.toBinNum     = objPickRawMtrlModel.ToBinNum; //move to transit bin
                    objInvTran.toLotNum     = objPickRawMtrlModel.LotNo;
                    objInvTran.toWarehouse  = objPickRawMtrlModel.ToWarehse;
                    objInvTran.partNum      = objPickRawMtrlModel.PartNum;
                    objInvTran.plant        = objPickRawMtrlModel.Plant;
                    objInvTran.qty          = objPickRawMtrlModel.Qty;
                    objInvTran.uom          = objPickRawMtrlModel.UOM;

                    objInvTran.id = "PickRawMtl";

                    InventoryTransferServices objInvTranService = new InventoryTransferServices();
                    objInvTranService.doInvTransfer(objInvTran);
                    //Inventory Transfer End


                    StagingDbContext stagingDbContext = new StagingDbContext();
                    PickRawMtrl      objNewPRM        = stagingDbContext.PickRawMtrls.Add(objPRM);
                    stagingDbContext.SaveChanges();

                    string  QryCheckQty = $"IF NOT EXISTS (Select Top 1 Qty from dbo.vwHH_WIPickRawMtrl Where SysRowID='{objPickRawMtrlModel.SysRowId}' ) BEGIN Select 0.0 as Qty END ELSE (Select Top 1 Qty from dbo.vwHH_WIPickRawMtrl Where SysRowID='{objPickRawMtrlModel.SysRowId}')";
                    decimal pickedQty   = epicorDbContext.Database.SqlQuery <decimal>(QryCheckQty.ToString()).SingleOrDefault();

                    if (pickedQty - objPRM.Qty <= 0)
                    {
                        string Qry = $"Update [Ice].[UD21] Set [CheckBox01]=1  Where SysRowID='{objPickRawMtrlModel.SysRowId}' ";
                        int    i   = epicorDbContext.Database.ExecuteSqlCommand(Qry);
                    }


                    return(Request.CreateResponse(HttpStatusCode.OK, pickedQty - objPRM.Qty));
                }
                else
                {
                    throw new Exception("PickRawMtrl is Null!");
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message.ToString()));
            }
        }
        // GET: PickRawMtrl/Details/5
        public ActionResult Pick(Guid id, bool isFirstGet = true)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            List <PickRawMtrlModel> entitys   = (List <PickRawMtrlModel>)Session["PickRawMtrlModels"];
            PickRawMtrlModel        objEntity = entitys.Where(w => w.SysRowId == id).FirstOrDefault();

            //if (isFirstGet)
            //{
            objEntity.Qty = objEntity.ActQty;
            //Session["ScanLotPRMLst"] = null;
            //Testing purpose
            //objEntity.ConvFactor = 5;
            //}
            //else
            //{
            if (Session["ScanLotPRMLst"] != null)
            {
                List <PickRawMtrlModel> objScanLotPRMList = (List <PickRawMtrlModel>)Session["ScanLotPRMLst"];
                decimal scanqty = objScanLotPRMList.Sum(s => s.Qty);

                objEntity.Qty = objEntity.ActQty - scanqty;

                //remainConvFactor from prev
                foreach (var c in objScanLotPRMList)
                {
                    objEntity.ConvFactor = c.ConvFactor;
                }

                ViewBag.ScanListCount = objScanLotPRMList.Count;
            }
            //}



            //drop down data
            ViewBag.PalletTypeInfo = new SelectList(objEntity.PalletTypeInfo, "PartNum", "PartNum");
            //testing
            //PickRawMtrlModel objEntity = new PickRawMtrlModel();
            //objEntity.UOMDecPoint = 2;
            //objEntity.Qty = 2.25M;
            //objEntity.ActQty = 2.25M;
            //objEntity.PalletQty = 2.25M;
            //objEntity.PickQty = 2.25M;
            //objEntity.UOM = "BAG";
            //objEntity.ConvFactor = 1;
            //objEntity.PickUOM = "BAG";

            List <LotNumSuggestion> lotNums = new List <LotNumSuggestion>();

            lotNums = GetSuggestionLotNum(objEntity.Company, objEntity.PartNum);
            if (lotNums != null && lotNums.Count > 0)
            {
                //Display in the modal
                TempData["LotNums"] = lotNums;
            }


            //ViewBag.PalletTypeInfo = objEntity.PalletTypeInfo.Select(s => new SelectList(new[] { new { value = s.PartNum, text = s.PartNum } }));
            return(View(objEntity));
        }
        public ActionResult Pick(PickRawMtrlModel obj)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            string msg        = "";
            bool   _isFinish  = false;
            bool   _isSuccess = false;

            try
            {
                HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("PickRawMtrl", obj).Result;
                if (response.IsSuccessStatusCode)
                {
                    msg = response.Content.ReadAsStringAsync().Result;

                    _isSuccess = true;

                    decimal newBalQty = Convert.ToDecimal(msg);

                    if (newBalQty <= 0)
                    {
                        _isFinish = true;
                    }
                    else
                    {
                        _isFinish = false;
                    }

                    List <PickRawMtrlModel> entitys   = (List <PickRawMtrlModel>)Session["PickRawMtrlModels"];
                    PickRawMtrlModel        objEntity = entitys.Where(w => w.SysRowId == obj.SysRowId).FirstOrDefault(x => x.Qty == newBalQty);
                    Session["PickRawMtrlModels"] = entitys;
                }
                else
                {
                    string msgJson = response.Content.ReadAsStringAsync().Result;

                    try
                    {
                        JObject jObject = JObject.Parse(msgJson);
                        string  msgJ    = (string)jObject.SelectToken("Message");
                        string  msgDtl  = (string)jObject.SelectToken("MessageDetail");
                        if (msgDtl == null)
                        {
                            msg = msgJ;
                        }
                        else
                        {
                            msg = msgDtl;
                        }
                    }
                    catch (Exception ex)
                    {
                        msg = msgJson;
                    }

                    _isFinish  = true;
                    _isSuccess = false;
                }
                return(Json(new { isFinish = _isFinish, Success = _isSuccess, Message = msg }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                //ViewBag.Status = ex.Message.ToString();
                msg = ex.Message.ToString();
                return(Json(new { isFinish = true, Success = false, Message = msg }, JsonRequestBehavior.AllowGet));
            }
        }
示例#5
0
        public ActionResult Pick(PickRawMtrlModel obj)
        {
            if (Session["User"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            List <PickRawMtrlModel> objScanLotPRMList = new List <PickRawMtrlModel>();

            if (Session["ScanLotPRMLst"] != null)
            {
                objScanLotPRMList = (List <PickRawMtrlModel>)Session["ScanLotPRMLst"];
            }
            else
            {
                objScanLotPRMList = new List <PickRawMtrlModel>();
            }

            if (obj.isFinish == false)
            {
                objScanLotPRMList.Add(obj);
            }

            Session["ScanLotPRMLst"] = objScanLotPRMList;
            //objScanLotPRMList.ForEach(s => s.UserId = obj.UserId);
            decimal qty    = objScanLotPRMList.Sum(s => s.Qty);
            decimal actQty = obj.ActQty;

            //List<PickRawMtrlModel> objPRMEntitys = (List<PickRawMtrlModel>)TempData["PickRawMtrlModels"];
            //PickRawMtrlModel objEntity = objPRMEntitys.Where(w => w.SysRowId == obj.SysRowId).FirstOrDefault();
            //objEntity.Qty = 0;
            if (qty < actQty)
            {
                //objEntity.Qty = actQty - qty;
                //return RedirectToAction("Pick", new { id = obj.SysRowId, isFirstGet = false });
                return(Json(new { isFinish = false, Success = false, Message = "" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                //bool isSuccessStatusCode = false;
                string msg = "";

                try
                {
                    //Session["ScanLotPRMLst"] = null;
                    obj.isFinish = true;
                    foreach (PickRawMtrlModel item in objScanLotPRMList)
                    {
                        HttpResponseMessage response = GlobalVariables.WebApiClient.PostAsJsonAsync("PickRawMtrl", item).Result;
                        if (response.IsSuccessStatusCode)
                        {
                            //msg = response.Content.ReadAsStringAsync().Result;
                            msg = "";
                        }
                        else
                        {
                            //isSuccessStatusCode = false;

                            string msgJson = response.Content.ReadAsStringAsync().Result;

                            try
                            {
                                JObject jObject = JObject.Parse(msgJson);
                                string  msgJ    = (string)jObject.SelectToken("Message");
                                string  msgDtl  = (string)jObject.SelectToken("MessageDetail");
                                if (msgDtl == null)
                                {
                                    msg = msgJ;
                                }
                                else
                                {
                                    msg = msgDtl;
                                }
                            }
                            catch (Exception ex)
                            {
                                msg = msgJson;
                            }

                            return(Json(new { isFinish = true, Success = false, Message = msg }, JsonRequestBehavior.AllowGet));
                        }
                    }

                    //isSuccessStatusCode = true;

                    //ViewBag.Status = "Inserted Sucessfully!";
                    string Company = "";
                    string UserId  = "";

                    if (!string.IsNullOrEmpty(Session["Company"] as string))
                    {
                        Company = Session["Company"] as string;
                    }
                    if (!string.IsNullOrEmpty(Session["User"] as string))
                    {
                        UserId = Session["User"].ToString();
                    }
                    return(Json(new { isFinish = true, Success = true, Message = msg }, JsonRequestBehavior.AllowGet));
                    //return RedirectToAction($"Index", new { Company = Company, UserId = UserId });
                }
                catch (Exception ex)
                {
                    //ViewBag.Status = ex.Message.ToString();
                    msg = ex.Message.ToString();
                    return(Json(new { isFinish = true, Success = false, Message = msg }, JsonRequestBehavior.AllowGet));
                }
            }

            //drop down data
            //List<PickRawMtrlModel> entitys = (List<PickRawMtrlModel>)TempData["PickRawMtrlModels"];
            //PickRawMtrlModel objEntity = entitys.Where(w => w.SysRowId == obj.SysRowId).FirstOrDefault();
            //if (objEntity != null)
            //{
            //    ViewBag.PalletTypeInfo = new SelectList(objEntity.PalletTypeInfo, "PartNum", "PartNum");
            //}

            //return View(obj);
        }