Пример #1
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,
            }));
        }
Пример #2
0
        public ActionResult PostSummary(JobReceiveSummaryDetailViewModel vm)
        {
            //TempData["CSEXC"] = "Customize Test Exception";

            List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();
            bool Modified = false;
            int  Id       = vm.JobReceiveHeaderId;

            var Header = _JobReceiveHeaderService.Find(Id);

            var JobReceives = (from p in db.JobReceiveLine
                               join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                               where p.JobReceiveHeaderId == Id
                               group t by new { t.ProductId, t.JobOrderHeaderId } into g
                               select g.Key).ToList();

            foreach (var item in vm.JobReceiveSummaryViewModel)
            {
                // Receive Line which has return also and return has no weight then receive weight should be 0.
                //var ReceiveWithReturnLines = from p in db.JobReceiveLine
                //                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                //                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                //                    from tab in table.DefaultIfEmpty()
                //                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId
                //                    && (p.PassQty - (tab.ReturnQty ?? 0)) == 0
                //                    select p;


                //foreach (var item3 in ReceiveWithReturnLines)
                //{

                //    item3.Weight = 0;
                //    item3.ObjectState = Model.ObjectState.Modified;
                //    _JobReceiveLineService.Update(item3);
                //}



                var ReceiveLines = (from p in db.JobReceiveLine
                                    join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                                    join t2 in db.JobReceiveLineStatus on p.JobReceiveLineId equals t2.JobReceiveLineId into table
                                    from tab in table.DefaultIfEmpty()
                                    where t.JobOrderHeaderId == item.JobOrderHeaderId && p.PassQty > 0 && p.JobReceiveHeaderId == Id && t.ProductId == item.ProductId &&
                                    (p.PassQty - (tab.ReturnQty ?? 0)) > 0
                                    select p).ToList();

                bool ValidationError = ReceiveLines.Where(m => m.Weight > 0).Any() && ReceiveLines.Where(m => m.Weight == 0).Any();

                if (ReceiveLines != null && ReceiveLines.Count > 0)
                {
                    decimal Weight = item.Weight;

                    decimal XWeight = ReceiveLines.Sum(m => m.Weight);

                    decimal PassQty = ReceiveLines.Sum(m => m.PassQty);


                    if (Weight != XWeight)
                    {
                        int     i = 0;
                        decimal WeightShortage   = 0;
                        decimal IndividualWeight = Math.Round((Weight / PassQty), 2);
                        if (i == 0 && IndividualWeight * PassQty != Weight)
                        {
                            WeightShortage = (Weight - (IndividualWeight * PassQty));
                        }

                        foreach (var item2 in ReceiveLines)
                        {
                            JobReceiveLine ExRec = new JobReceiveLine();
                            ExRec = Mapper.Map <JobReceiveLine>(item2);

                            item2.Weight       = IndividualWeight * item2.PassQty + (i == 0 ? WeightShortage : 0);
                            item2.ModifiedBy   = User.Identity.Name;
                            item2.ModifiedDate = DateTime.Now;
                            item2.ObjectState  = Model.ObjectState.Modified;

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

                            _JobReceiveLineService.Update(item2);
                            i++;

                            Modified = true;
                        }
                    }
                }
            }

            if ((Header.Status != (int)StatusConstants.Drafted && Header.Status != (int)StatusConstants.Import) && Modified)
            {
                Header.Status     = (int)StatusConstants.Modified;
                Header.ModifiedBy = User.Identity.Name;
            }

            Header.ModifiedDate = DateTime.Now;
            Header.ObjectState  = Model.ObjectState.Modified;
            new JobReceiveHeaderService(_unitOfWork).Update(Header);

            XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

            try
            {
                _unitOfWork.Save();
            }

            catch (Exception ex)
            {
                string message = _exception.HandleException(ex);
                ModelState.AddModelError("", message);
                PrepareViewBag(vm.JobReceiveHeaderId);
                return(Json(new { Success = false }));
            }

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

            string RetUrl = "";


            if (Header.Status == (int)StatusConstants.Drafted || Header.Status == (int)StatusConstants.Import)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Modify/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Submitted || Header.Status == (int)StatusConstants.ModificationSubmitted || Header.Status == (int)StatusConstants.Modified)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Submit/" + Header.JobReceiveHeaderId;
            }
            else if (Header.Status == (int)StatusConstants.Approved || Header.Status == (int)StatusConstants.Closed)
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/ModifyAfter_Approve/" + Header.JobReceiveHeaderId;
            }
            else
            {
                RetUrl = System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + Header.DocTypeId;
            }

            return(Json(new { Success = true, Url = RetUrl }));
        }