Пример #1
0
        public ActionResult Submit(int id, string IndexType, string TransactionType)
        {
            #region DocTypeTimeLineValidation
            JobReceiveHeader s = _DyeingService.Find(id);

            try
            {
                TimePlanValidation = _documentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(s), DocumentTimePlanTypeConstants.Submit, User.Identity.Name, out ExceptionMsg, out Continue);
                TempData["CSEXC"] += ExceptionMsg;
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation && !Continue)
            {
                return(RedirectToAction("Index", new { id = s.DocTypeId, IndexType = IndexType }));
            }
            #endregion

            return(RedirectToAction("Detail", new { id = id, IndexType = IndexType, transactionType = string.IsNullOrEmpty(TransactionType) ? "submit" : TransactionType }));
        }
        public void UpdateProdUidJobWorkers(ref ApplicationDbContext context, JobReceiveHeader Header)
        {
            var Lines = (from p in context.JobReceiveLine
                         where p.JobReceiveHeaderId == Header.JobReceiveHeaderId
                         select p).ToList();

            if (Lines.Count() > 0)
            {
                if (Lines.Where(m => m.ProductUidId != null).Count() > 0)
                {
                    var ProductUids = Lines.Select(m => m.ProductUidId).ToArray();

                    var ProductUidRecords = (from p in context.ProductUid
                                             where ProductUids.Contains(p.ProductUIDId) &&
                                             p.LastTransactionDocId == Header.JobReceiveHeaderId
                                             select p).ToList();

                    foreach (var item in ProductUidRecords)
                    {
                        item.LastTransactionPersonId = Header.JobWorkerId;
                        item.LastTransactionDocNo    = Header.DocNo;
                        item.LastTransactionDocDate  = Header.DocDate;
                        item.CurrenctGodownId        = Header.GodownId;
                        item.ObjectState             = Model.ObjectState.Modified;

                        context.ProductUid.Add(item);
                    }
                }
            }
        }
Пример #3
0
        public ActionResult DeleteAfter_Approve(int id)
        {
            JobReceiveHeader header = _DyeingService.Find(id);

            if (header.Status == (int)StatusConstants.Approved)
            {
                return(Remove(id));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Пример #4
0
        public ActionResult ModifyAfter_Approve(int id, string IndexType)
        {
            JobReceiveHeader header = _DyeingService.Find(id);

            if (header.Status == (int)StatusConstants.Approved)
            {
                return(Edit(id, IndexType));
            }
            else
            {
                return(HttpNotFound());
            }
        }
Пример #5
0
        private ActionResult Remove(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            JobReceiveHeader JobReceiveHeader = _DyeingService.Find(id);

            if (JobReceiveHeader == null)
            {
                return(HttpNotFound());
            }

            #region DocTypeTimeLineValidation

            try
            {
                TimePlanValidation = _documentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(JobReceiveHeader), DocumentTimePlanTypeConstants.Delete, User.Identity.Name, out ExceptionMsg, out Continue);
                TempData["CSEXC"] += ExceptionMsg;
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation && !Continue)
            {
                return(PartialView("AjaxError"));
            }
            #endregion

            ReasonViewModel rvm = new ReasonViewModel()
            {
                id = id,
            };
            return(PartialView("_Reason", rvm));
        }
 public void Update(JobReceiveHeader s)
 {
     s.ObjectState = ObjectState.Modified;
     _unitOfWork.Repository <JobReceiveHeader>().Update(s);
 }
 public void Delete(JobReceiveHeader s)
 {
     _unitOfWork.Repository <JobReceiveHeader>().Delete(s);
 }
 public JobReceiveHeader Create(JobReceiveHeader s)
 {
     s.ObjectState = ObjectState.Added;
     _unitOfWork.Repository <JobReceiveHeader>().Insert(s);
     return(s);
 }
Пример #9
0
        public void Update(DyeingViewModel vmDyeing, string UserName)
        {
            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

            JobReceiveHeader temp = Find(vmDyeing.JobReceiveHeaderId);
            JobReceiveLine   line = _JobReceiveLineService.GetJobReceiveLineListForHeader(vmDyeing.JobReceiveHeaderId).FirstOrDefault();

            JobReceiveHeader ExRec = Mapper.Map <JobReceiveHeader>(temp);

            int?PersonId = (from L in _unitOfWork.Repository <JobOrderLine>().Instance
                            join He in _unitOfWork.Repository <JobOrderHeaderExtended>().Instance on L.JobOrderHeaderId equals He.JobOrderHeaderId
                            where L.JobOrderLineId == vmDyeing.JobOrderLineId
                            select He).FirstOrDefault().PersonId;

            int status = temp.Status;

            if (temp.Status != (int)StatusConstants.Drafted && temp.Status != (int)StatusConstants.Import)
            {
                temp.Status = (int)StatusConstants.Modified;
            }


            temp.DocDate        = vmDyeing.DocDate;
            temp.ProcessId      = vmDyeing.ProcessId;
            temp.JobWorkerId    = vmDyeing.JobWorkerId;
            temp.MachineId      = vmDyeing.MachineId;
            temp.JobReceiveById = vmDyeing.JobReceiveById;
            temp.DocNo          = vmDyeing.DocNo;
            temp.Remark         = vmDyeing.Remark;
            temp.ModifiedDate   = DateTime.Now;
            temp.ModifiedBy     = UserName;
            temp.ObjectState    = Model.ObjectState.Modified;
            Update(temp);



            StockViewModel StockViewModel = new StockViewModel();

            //Posting in Stock
            StockViewModel.StockHeaderId      = temp.StockHeaderId ?? 0;
            StockViewModel.StockId            = line.StockId ?? 0;
            StockViewModel.DocHeaderId        = temp.JobReceiveHeaderId;
            StockViewModel.DocLineId          = null;
            StockViewModel.DocTypeId          = temp.DocTypeId;
            StockViewModel.StockHeaderDocDate = temp.DocDate;
            StockViewModel.StockDocDate       = temp.DocDate;
            StockViewModel.DocNo              = temp.DocNo;
            StockViewModel.DivisionId         = temp.DivisionId;
            StockViewModel.SiteId             = temp.SiteId;
            StockViewModel.CurrencyId         = null;
            StockViewModel.HeaderProcessId    = null;
            StockViewModel.PersonId           = PersonId;
            StockViewModel.ProductId          = vmDyeing.ProductId;
            StockViewModel.HeaderFromGodownId = null;
            StockViewModel.HeaderGodownId     = null;
            StockViewModel.GodownId           = vmDyeing.GodownId;
            StockViewModel.ProcessId          = null;
            StockViewModel.LotNo              = vmDyeing.LotNo;
            StockViewModel.CostCenterId       = null;
            StockViewModel.Qty_Iss            = 0;
            StockViewModel.Qty_Rec            = vmDyeing.Qty;
            StockViewModel.Rate          = 0;
            StockViewModel.ExpiryDate    = null;
            StockViewModel.Specification = null;
            StockViewModel.Dimension1Id  = vmDyeing.Dimension1Id;
            StockViewModel.Dimension2Id  = vmDyeing.Dimension2Id;
            StockViewModel.Remark        = temp.Remark;
            StockViewModel.ProductUidId  = null;
            StockViewModel.Status        = 0;
            StockViewModel.CreatedBy     = UserName;
            StockViewModel.CreatedDate   = DateTime.Now;
            StockViewModel.ModifiedBy    = UserName;
            StockViewModel.ModifiedDate  = DateTime.Now;

            string StockPostingError = "";

            StockPostingError = _stockService.StockPostDB(ref StockViewModel);

            LogList.Add(new LogTypeViewModel
            {
                ExObj = ExRec,
                Obj   = temp,
            });

            if (temp.StockHeaderId != null && temp.StockHeaderId != 0)
            {
                StockHeader StockHeader = new StockHeaderService(_unitOfWork).Find((int)temp.StockHeaderId);
                StockHeader.DocDate = temp.DocDate;
                StockHeader.DocNo   = temp.DocNo;
                new StockHeaderService(_unitOfWork).Update(StockHeader);
            }



            line.JobReceiveHeaderId = temp.JobReceiveHeaderId;
            line.JobOrderLineId     = vmDyeing.JobOrderLineId;
            line.JobOrderLineId     = vmDyeing.JobOrderLineId;
            line.Qty        = vmDyeing.Qty;
            line.Sr         = 1;
            line.LossQty    = 0;
            line.DealQty    = vmDyeing.Qty;
            line.DealUnitId = vmDyeing.UnitId;
            line.UnitConversionMultiplier = 1;
            line.CreatedDate  = DateTime.Now;
            line.ModifiedDate = DateTime.Now;
            line.CreatedBy    = UserName;
            line.ModifiedBy   = UserName;
            line.ObjectState  = Model.ObjectState.Modified;

            _JobReceiveLineService.Update(line);


            JobReceiveHeaderExtended HeaderExtended = _JobReceiveHeaderExtendedService.Find(temp.JobReceiveHeaderId);

            HeaderExtended.JobReceiveHeaderId = temp.JobReceiveHeaderId;
            HeaderExtended.StartDateTime      = vmDyeing.StartDateTime.Value.AddHours(vmDyeing.StartDateTimeHour).AddMinutes(vmDyeing.StartDateTimeMinute);
            if (vmDyeing.CompletedDateTime != null)
            {
                HeaderExtended.CompletedDateTime = vmDyeing.CompletedDateTime.Value.AddHours(vmDyeing.CompletedDateTimeHour).AddMinutes(vmDyeing.CompletedDateTimeMinute);
            }
            HeaderExtended.LoadingTime  = vmDyeing.LoadingTime;
            HeaderExtended.IsQCRequired = vmDyeing.IsQCRequired;
            HeaderExtended.DyeingType   = vmDyeing.DyeingType;
            HeaderExtended.ObjectState  = Model.ObjectState.Modified;
            _JobReceiveHeaderExtendedService.Update(HeaderExtended);

            XElement Modifications = _modificationCheck.CheckChanges(LogList);

            _unitOfWork.Save();

            _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId       = temp.DocTypeId,
                DocId           = temp.JobReceiveHeaderId,
                ActivityType    = (int)ActivityTypeContants.Modified,
                DocNo           = temp.DocNo,
                xEModifications = Modifications,
                DocDate         = temp.DocDate,
                DocStatus       = temp.Status,
            }));
        }
Пример #10
0
        public DyeingViewModel Create(DyeingViewModel vmDyeing, string UserName)
        {
            JobReceiveHeader s = Mapper.Map <DyeingViewModel, JobReceiveHeader>(vmDyeing);

            int?PersonId = (from L in _unitOfWork.Repository <JobOrderLine>().Instance
                            join He in _unitOfWork.Repository <JobOrderHeaderExtended>().Instance on L.JobOrderHeaderId equals He.JobOrderHeaderId
                            where L.JobOrderLineId == vmDyeing.JobOrderLineId
                            select He).FirstOrDefault().PersonId;



            s.CreatedDate  = DateTime.Now;
            s.ModifiedDate = DateTime.Now;
            s.CreatedBy    = UserName;
            s.ModifiedBy   = UserName;
            s.Status       = (int)StatusConstants.Drafted;



            StockViewModel StockViewModel = new StockViewModel();

            //Posting in Stock
            StockViewModel.StockHeaderId      = s.StockHeaderId ?? 0;
            StockViewModel.DocHeaderId        = s.JobReceiveHeaderId;
            StockViewModel.DocLineId          = null;
            StockViewModel.DocTypeId          = s.DocTypeId;
            StockViewModel.StockHeaderDocDate = s.DocDate;
            StockViewModel.StockDocDate       = DateTime.Now.Date;
            StockViewModel.DocNo              = s.DocNo;
            StockViewModel.DivisionId         = s.DivisionId;
            StockViewModel.SiteId             = s.SiteId;
            StockViewModel.CurrencyId         = null;
            StockViewModel.HeaderProcessId    = null;
            StockViewModel.PersonId           = PersonId;
            StockViewModel.ProductId          = vmDyeing.ProductId;
            StockViewModel.HeaderFromGodownId = null;
            StockViewModel.HeaderGodownId     = null;
            StockViewModel.GodownId           = vmDyeing.GodownId;
            StockViewModel.ProcessId          = null;
            StockViewModel.LotNo              = vmDyeing.LotNo;
            StockViewModel.CostCenterId       = null;
            StockViewModel.Qty_Iss            = 0;
            StockViewModel.Qty_Rec            = vmDyeing.Qty;
            StockViewModel.Rate          = 0;
            StockViewModel.ExpiryDate    = null;
            StockViewModel.Specification = null;
            StockViewModel.Dimension1Id  = vmDyeing.Dimension1Id;
            StockViewModel.Dimension2Id  = vmDyeing.Dimension2Id;
            StockViewModel.Remark        = s.Remark;
            StockViewModel.ProductUidId  = null;
            StockViewModel.Status        = 0;
            StockViewModel.CreatedBy     = UserName;
            StockViewModel.CreatedDate   = DateTime.Now;
            StockViewModel.ModifiedBy    = UserName;
            StockViewModel.ModifiedDate  = DateTime.Now;

            string StockPostingError = "";

            StockPostingError = _stockService.StockPostDB(ref StockViewModel);



            if (s.StockHeaderId == null)
            {
                s.StockHeaderId = StockViewModel.StockHeaderId;
            }


            s.ObjectState = Model.ObjectState.Added;
            Create(s);
            //Line Save


            JobReceiveLine line = new JobReceiveLine();

            line.JobReceiveHeaderId = s.JobReceiveHeaderId;
            line.JobOrderLineId     = vmDyeing.JobOrderLineId;
            line.Qty        = vmDyeing.Qty;
            line.PassQty    = vmDyeing.Qty;
            line.Sr         = 1;
            line.LotNo      = vmDyeing.LotNo;
            line.LossQty    = 0;
            line.DealQty    = vmDyeing.Qty;
            line.DealUnitId = vmDyeing.UnitId;
            line.UnitConversionMultiplier = 1;
            line.CreatedDate  = DateTime.Now;
            line.ModifiedDate = DateTime.Now;
            line.CreatedBy    = UserName;
            line.ModifiedBy   = UserName;
            line.StockId      = StockViewModel.StockId;
            line.ObjectState  = Model.ObjectState.Added;

            _JobReceiveLineService.Create(line);



            _JobReceiveLineStatusService.CreateLineStatus(line.JobReceiveLineId);

            JobReceiveHeaderExtended HeaderExtended = new JobReceiveHeaderExtended();

            HeaderExtended.JobReceiveHeaderId = s.JobReceiveHeaderId;
            HeaderExtended.StartDateTime      = vmDyeing.StartDateTime.Value.AddHours(vmDyeing.StartDateTimeHour).AddMinutes(vmDyeing.StartDateTimeMinute);
            if (vmDyeing.CompletedDateTime != null)
            {
                HeaderExtended.CompletedDateTime = vmDyeing.CompletedDateTime.Value.AddHours(vmDyeing.CompletedDateTimeHour).AddMinutes(vmDyeing.CompletedDateTimeMinute);
            }
            HeaderExtended.LoadingTime  = vmDyeing.LoadingTime;
            HeaderExtended.IsQCRequired = vmDyeing.IsQCRequired;
            HeaderExtended.DyeingType   = vmDyeing.DyeingType;
            HeaderExtended.ObjectState  = Model.ObjectState.Added;
            _JobReceiveHeaderExtendedService.Create(HeaderExtended);


            //End Line Save


            _unitOfWork.Save();

            vmDyeing.JobReceiveHeaderId = s.JobReceiveHeaderId;

            _logger.LogActivityDetail(logVm.Map(new ActiivtyLogViewModel
            {
                DocTypeId    = s.DocTypeId,
                DocId        = s.JobReceiveHeaderId,
                ActivityType = (int)ActivityTypeContants.Added,
                DocNo        = s.DocNo,
                DocDate      = s.DocDate,
                DocStatus    = s.Status,
            }));



            return(vmDyeing);
        }
 public JobReceiveHeader Add(JobReceiveHeader pt)
 {
     _unitOfWork.Repository <JobReceiveHeader>().Insert(pt);
     return(pt);
 }
        public ActionResult Post(JobReceiveHeaderViewModel svm)
        {
            bool   TimePlanValidation = true;
            string ExceptionMsg       = "";
            bool   Continue           = true;

            JobReceiveHeader s = Mapper.Map <JobReceiveHeaderViewModel, JobReceiveHeader>(svm);
            List <WeavingReceiveWizardViewModel> JobOrdersAndQtys = (List <WeavingReceiveWizardViewModel>)System.Web.HttpContext.Current.Session["BarCodesWeavingWizardJobOrder"];



            if (JobOrdersAndQtys.Count() <= 0)
            {
                ModelState.AddModelError("", "No Records Selected");
            }

            int JobWorkerCnt = (from l in JobOrdersAndQtys
                                group l by l.JobWorkerId into g
                                select new
            {
                JobWorkerId = g.Key,
            }).Distinct().Count();

            if (JobWorkerCnt > 1)
            {
                ModelState.AddModelError("", "Select any one Job Worker Orders.");
            }



            s.JobWorkerId   = JobOrdersAndQtys.FirstOrDefault().JobWorkerId;
            svm.JobWorkerId = JobOrdersAndQtys.FirstOrDefault().JobWorkerId;


            #region DocTypeTimeLineValidation

            try
            {
                if (svm.JobReceiveHeaderId <= 0)
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Create, User.Identity.Name, out ExceptionMsg, out Continue);
                }
                else
                {
                    TimePlanValidation = DocumentValidation.ValidateDocument(Mapper.Map <DocumentUniqueId>(svm), DocumentTimePlanTypeConstants.Modify, User.Identity.Name, out ExceptionMsg, out Continue);
                }
            }
            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                TempData["CSEXC"] += message;
                TimePlanValidation = false;
            }

            if (!TimePlanValidation)
            {
                TempData["CSEXC"] += ExceptionMsg;
            }

            #endregion

            if (ModelState.IsValid && (TimePlanValidation || Continue))
            {
                if (svm.JobReceiveHeaderId <= 0)
                {
                    if (JobOrdersAndQtys.Count() > 0)
                    {
                        s.CreatedDate  = DateTime.Now;
                        s.ModifiedDate = DateTime.Now;
                        s.CreatedBy    = User.Identity.Name;
                        s.ModifiedBy   = User.Identity.Name;
                        s.Status       = (int)StatusConstants.Drafted;
                        _JobReceiveHeaderService.Create(s);


                        int Cnt = 0;
                        int Sr  = 0;


                        JobReceiveSettings Settings = new JobReceiveSettingsService(_unitOfWork).GetJobReceiveSettingsForDocument(s.DocTypeId, s.DivisionId, s.SiteId);

                        int ProductUidCountForJobOrderLine = 0;
                        int pk = 0;

                        var JobOrderLineIds = JobOrdersAndQtys.Select(m => m.JobOrderLineId).ToArray();

                        var BalQtyandUnits = (from p in db.ViewJobOrderBalance
                                              join t in db.Product on p.ProductId equals t.ProductId
                                              where JobOrderLineIds.Contains(p.JobOrderLineId)
                                              select new
                        {
                            BalQty = p.BalanceQty,
                            JobOrderLineId = p.JobOrderLineId,
                            UnitId = t.UnitId,
                        }).ToList();

                        if (ModelState.IsValid)
                        {
                            foreach (var SelectedJobOrderLine in JobOrdersAndQtys)
                            {
                                if (SelectedJobOrderLine.JobOrderLineId > 0)
                                {
                                    if (SelectedJobOrderLine.ToProductUidName != "" && SelectedJobOrderLine.ToProductUidName != null && SelectedJobOrderLine.FromProductUidName != "" && SelectedJobOrderLine.FromProductUidName != null)
                                    {
                                        if (SelectedJobOrderLine.Qty != (Convert.ToInt32(SelectedJobOrderLine.ToProductUidName) - Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + 1))
                                        {
                                            string Msg = "";
                                            Msg = "Qty and Barcode series does not match.";
                                            ModelState.AddModelError("", Msg);
                                            PrepareViewBag();
                                            ViewBag.Mode = "Add";
                                            return(View("Create", svm));
                                        }
                                    }



                                    ProductUidCountForJobOrderLine = 0;
                                    var JobOrderLine = new JobOrderLineService(_unitOfWork).Find((SelectedJobOrderLine.JobOrderLineId));
                                    var Product      = new ProductService(_unitOfWork).Find(JobOrderLine.ProductId);

                                    var bal = BalQtyandUnits.Where(m => m.JobOrderLineId == SelectedJobOrderLine.JobOrderLineId).FirstOrDefault();

                                    if (SelectedJobOrderLine.Qty <= bal.BalQty)
                                    {
                                        for (int i = 0; i <= SelectedJobOrderLine.Qty - 1; i++)
                                        {
                                            int?ProductUidHeaderId = null;
                                            int?ProductUidId       = null;


                                            var SisterSite = (from S in db.Site where S.PersonId == s.JobWorkerId select S).FirstOrDefault();

                                            //if (!string.IsNullOrEmpty(Settings.SqlProcGenProductUID))
                                            if (SisterSite == null)
                                            {
                                                ProductUidHeader ProdUidHeader = new ProductUidHeader();

                                                ProdUidHeader.ProductUidHeaderId = Cnt;
                                                ProdUidHeader.ProductId          = JobOrderLine.ProductId;
                                                ProdUidHeader.Dimension1Id       = JobOrderLine.Dimension1Id;
                                                ProdUidHeader.Dimension2Id       = JobOrderLine.Dimension2Id;
                                                ProdUidHeader.GenDocId           = s.JobReceiveHeaderId;
                                                ProdUidHeader.GenDocNo           = s.DocNo;
                                                ProdUidHeader.GenDocTypeId       = s.DocTypeId;
                                                ProdUidHeader.GenDocDate         = s.DocDate;
                                                ProdUidHeader.GenPersonId        = s.JobWorkerId;
                                                ProdUidHeader.CreatedBy          = User.Identity.Name;
                                                ProdUidHeader.CreatedDate        = DateTime.Now;
                                                ProdUidHeader.ModifiedBy         = User.Identity.Name;
                                                ProdUidHeader.ModifiedDate       = DateTime.Now;
                                                ProdUidHeader.ObjectState        = Model.ObjectState.Added;
                                                new ProductUidHeaderService(_unitOfWork).Create(ProdUidHeader);
                                                ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId;


                                                string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString();

                                                ProductUid ProdUid = new ProductUid();
                                                ProdUid.ProductUidHeaderId       = ProdUidHeader.ProductUidHeaderId;
                                                ProdUid.ProductUidName           = ProductUidName;
                                                ProdUid.ProductId                = JobOrderLine.ProductId;
                                                ProdUid.IsActive                 = true;
                                                ProdUid.CreatedBy                = User.Identity.Name;
                                                ProdUid.CreatedDate              = DateTime.Now;
                                                ProdUid.ModifiedBy               = User.Identity.Name;
                                                ProdUid.ModifiedDate             = DateTime.Now;
                                                ProdUid.GenLineId                = null;
                                                ProdUid.GenDocId                 = s.JobReceiveHeaderId;
                                                ProdUid.GenDocNo                 = s.DocNo;
                                                ProdUid.GenDocTypeId             = s.DocTypeId;
                                                ProdUid.GenDocDate               = s.DocDate;
                                                ProdUid.GenPersonId              = s.JobWorkerId;
                                                ProdUid.Dimension1Id             = JobOrderLine.Dimension1Id;
                                                ProdUid.Dimension2Id             = JobOrderLine.Dimension2Id;
                                                ProdUid.CurrenctProcessId        = s.ProcessId;
                                                ProdUid.CurrenctGodownId         = s.GodownId;
                                                ProdUid.Status                   = "Receive";
                                                ProdUid.LastTransactionDocId     = s.JobReceiveHeaderId;
                                                ProdUid.LastTransactionDocNo     = s.DocNo;
                                                ProdUid.LastTransactionDocTypeId = s.DocTypeId;
                                                ProdUid.LastTransactionDocDate   = s.DocDate;
                                                ProdUid.LastTransactionPersonId  = s.JobWorkerId;
                                                ProdUid.LastTransactionLineId    = null;
                                                ProdUid.ProductUIDId             = pk;
                                                new ProductUidService(_unitOfWork).Create(ProdUid);
                                                ProductUidId = ProdUid.ProductUIDId;
                                            }

                                            if (ProductUidId == null)
                                            {
                                                string ProductUidName = (Convert.ToInt32(SelectedJobOrderLine.FromProductUidName) + ProductUidCountForJobOrderLine).ToString();
                                                var    temp           = new ProductUidService(_unitOfWork).Find(ProductUidName);
                                                if (temp != null)
                                                {
                                                    ProductUidId = temp.ProductUIDId;
                                                }
                                                else
                                                {
                                                    string Msg = ProductUidName + " is not a valid barcode.";
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }

                                                if (temp.CurrenctGodownId != null)
                                                {
                                                    string Msg = ProductUidName + " is already in Stock at Godown " + new GodownService(_unitOfWork).Find(temp.CurrenctGodownId ?? 0).GodownName;
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }

                                                if (temp.LastTransactionPersonId != s.JobWorkerId)
                                                {
                                                    string Msg = ProductUidName + ProductUidName + " does not belong to this Job Worker";
                                                    ModelState.AddModelError("", Msg);
                                                    PrepareViewBag();
                                                    ViewBag.Mode = "Add";
                                                    return(View("Create", svm));
                                                }
                                            }


                                            StockViewModel StockViewModel = new StockViewModel();
                                            if (Cnt == 0)
                                            {
                                                StockViewModel.StockHeaderId = s.StockHeaderId ?? 0;
                                            }
                                            else
                                            {
                                                if (s.StockHeaderId != null && s.StockHeaderId != 0)
                                                {
                                                    StockViewModel.StockHeaderId = (int)s.StockHeaderId;
                                                }
                                                else
                                                {
                                                    StockViewModel.StockHeaderId = -1;
                                                }
                                            }

                                            StockViewModel.StockId            = -Cnt;
                                            StockViewModel.DocHeaderId        = s.JobReceiveHeaderId;
                                            StockViewModel.DocLineId          = null;
                                            StockViewModel.DocTypeId          = s.DocTypeId;
                                            StockViewModel.StockHeaderDocDate = s.DocDate;
                                            StockViewModel.StockDocDate       = s.DocDate;
                                            StockViewModel.DocNo      = s.DocNo;
                                            StockViewModel.DivisionId = s.DivisionId;
                                            StockViewModel.SiteId     = s.SiteId;
                                            StockViewModel.CurrencyId = null;
                                            StockViewModel.PersonId   = s.JobWorkerId;
                                            StockViewModel.ProductId  = JobOrderLine.ProductId;
                                            //StockViewModel.ProductUidId = ProdUid.ProductUIDId;
                                            StockViewModel.ProductUidId       = ProductUidId;
                                            StockViewModel.HeaderFromGodownId = null;
                                            StockViewModel.HeaderGodownId     = s.GodownId;
                                            StockViewModel.HeaderProcessId    = s.ProcessId;
                                            StockViewModel.GodownId           = (int)s.GodownId;
                                            StockViewModel.Remark             = s.Remark;
                                            StockViewModel.Status             = s.Status;
                                            StockViewModel.ProcessId          = s.ProcessId;
                                            StockViewModel.LotNo         = null;
                                            StockViewModel.CostCenterId  = SelectedJobOrderLine.CostCenterId;
                                            StockViewModel.Qty_Iss       = 0;
                                            StockViewModel.Qty_Rec       = 1;
                                            StockViewModel.Rate          = SelectedJobOrderLine.Rate;
                                            StockViewModel.ExpiryDate    = null;
                                            StockViewModel.Specification = JobOrderLine.Specification;
                                            StockViewModel.Dimension1Id  = JobOrderLine.Dimension1Id;
                                            StockViewModel.Dimension2Id  = JobOrderLine.Dimension2Id;
                                            StockViewModel.CreatedBy     = User.Identity.Name;
                                            StockViewModel.CreatedDate   = DateTime.Now;
                                            StockViewModel.ModifiedBy    = User.Identity.Name;
                                            StockViewModel.ModifiedDate  = DateTime.Now;

                                            string StockPostingError = "";
                                            StockPostingError = new StockService(_unitOfWork).StockPost(ref StockViewModel);

                                            if (StockPostingError != "")
                                            {
                                                string message = StockPostingError;
                                                ModelState.AddModelError("", message);
                                                return(View("Create", svm));
                                            }

                                            if (Cnt == 0)
                                            {
                                                s.StockHeaderId = StockViewModel.StockHeaderId;
                                            }


                                            JobReceiveLine line = new JobReceiveLine();
                                            line.StockId = StockViewModel.StockId;
                                            //line.ProductUidHeaderId = ProdUidHeader.ProductUidHeaderId;
                                            line.ProductUidHeaderId = ProductUidHeaderId;
                                            //line.ProductUidId = ProdUid.ProductUIDId;
                                            line.ProductUidId       = ProductUidId;
                                            line.JobReceiveHeaderId = s.JobReceiveHeaderId;
                                            line.JobOrderLineId     = JobOrderLine.JobOrderLineId;
                                            line.Qty     = 1;
                                            line.PassQty = 1;
                                            line.LossQty = 0;
                                            line.UnitConversionMultiplier = JobOrderLine.UnitConversionMultiplier;
                                            line.DealQty          = 1 * JobOrderLine.UnitConversionMultiplier;
                                            line.DealUnitId       = JobOrderLine.DealUnitId;
                                            line.Sr               = Sr++;
                                            line.CreatedDate      = DateTime.Now;
                                            line.ModifiedDate     = DateTime.Now;
                                            line.CreatedBy        = User.Identity.Name;
                                            line.ModifiedBy       = User.Identity.Name;
                                            line.JobReceiveLineId = pk;
                                            line.ObjectState      = Model.ObjectState.Added;
                                            new JobReceiveLineService(_unitOfWork).Create(line);

                                            new JobReceiveLineStatusService(_unitOfWork).CreateLineStatus(line.JobReceiveLineId, ref db, false);


                                            pk++;
                                            Cnt = Cnt + 1;
                                            ProductUidCountForJobOrderLine++;
                                        }
                                    }
                                }
                            }
                        }
                        string Errormessage = "";
                        try
                        {
                            _unitOfWork.Save();
                        }

                        catch (Exception ex)
                        {
                            Errormessage = _exception.HandleException(ex);
                            ModelState.AddModelError("", Errormessage);
                            PrepareViewBag();
                            ViewBag.Mode = "Add";
                            return(View("Create", svm));
                        }



                        IEnumerable <JobReceiveLine> JobReceiveLineList = new JobReceiveLineService(_unitOfWork).GetJobReceiveLineList(s.JobReceiveHeaderId);

                        foreach (JobReceiveLine Line in JobReceiveLineList)
                        {
                            if (Line.ProductUidId != null)
                            {
                                ProductUid ProductUid = new ProductUidService(_unitOfWork).Find((int)Line.ProductUidId);
                                ProductUid.GenDocId              = Line.JobReceiveHeaderId;
                                ProductUid.LastTransactionDocId  = Line.JobReceiveHeaderId;
                                ProductUid.GenLineId             = Line.JobReceiveLineId;
                                ProductUid.LastTransactionLineId = Line.JobReceiveLineId;
                                new ProductUidService(_unitOfWork).Update(ProductUid);
                            }
                        }

                        try
                        {
                            _unitOfWork.Save();
                        }

                        catch (Exception ex)
                        {
                            Errormessage = _exception.HandleException(ex);
                            ModelState.AddModelError("", Errormessage);
                            PrepareViewBag();
                            ViewBag.Mode = "Add";
                            return(View("Create", svm));
                        }

                        LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                        {
                            DocTypeId    = s.DocTypeId,
                            DocId        = s.JobReceiveHeaderId,
                            ActivityType = (int)ActivityTypeContants.WizardCreate,
                            DocNo        = s.DocNo,
                            DocDate      = s.DocDate,
                            DocStatus    = s.Status,
                        }));

                        System.Web.HttpContext.Current.Session.Remove("BarCodesWeavingWizardJobOrder");

                        return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + s.JobReceiveHeaderId));
                    }
                    else
                    {
                        return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + s.DocTypeId));
                    }
                }
                else
                {
                }
            }
            PrepareViewBag();
            ViewBag.Mode = "Add";
            //return Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Submit/"+s.JobReceiveHeaderId);
            return(View("Create", svm));
        }