Esempio n. 1
0
        public ActionResult GetSummary(int id)
        {
            var Header = _JobReceiveHeaderService.Find(id);

            var JobReceives = (from p in db.JobReceiveLine
                               join t in db.JobOrderLine on p.JobOrderLineId equals t.JobOrderLineId
                               join RetLine in db.JobReturnLine on p.JobReceiveLineId equals RetLine.JobReceiveLineId
                               into ReturnLine
                               from RetLin in ReturnLine.DefaultIfEmpty()
                               join t2 in db.ViewRugArea on t.ProductId equals t2.ProductId into table
                               from tab in table.DefaultIfEmpty()
                               join t4 in db.Product on tab.ProductId equals t4.ProductId
                               join t6 in db.ProductGroups on t4.ProductGroupId equals t6.ProductGroupId
                               join t5 in db.Units on t4.UnitId equals t5.UnitId
                               where p.JobReceiveHeaderId == id && p.PassQty > 0
                               group new { t, p, tab, t5, t6, RetLin } by new { t.ProductId, t.JobOrderHeaderId } into g
                               orderby g.Max(m => m.t6.ProductGroupName), g.Max(m => m.t.UnitConversionMultiplier)
                               select new JobReceiveSummaryViewModel
            {
                ProductName = g.Max(m => m.t.Product.ProductName),
                JobOrderHeaderId = g.Key.JobOrderHeaderId,
                JobOrderNo = g.Max(m => m.t.JobOrderHeader.DocNo),
                CostCenterName = g.Max(m => m.t.JobOrderHeader.CostCenter.CostCenterName),
                ProductId = g.Key.ProductId,
                Weight = (g.Sum(m => m.p.Weight) - g.Sum(m => m.RetLin == null ? 0 : (m.RetLin.Weight))),
                Qty = g.Sum(m => m.p.PassQty),
                ReturnQty = g.Sum(m => m.RetLin == null ? 0 : (m.RetLin.Qty)),
                UnitName = g.Max(m => m.t5.UnitName),
                MaxDecPlaces = g.Max(m => m.t5.DecimalPlaces),
                DealQty = g.Sum(m => m.p.PassQty * m.t.UnitConversionMultiplier),
                DealQtyPP = g.Max(m => m.t.UnitConversionMultiplier),
                MaxDealUnitDecPlaces = g.Max(m => m.t.DealUnit.DecimalPlaces),
                DealUnitName = g.Max(m => m.t.DealUnit.UnitName),
                ValidationError = (g.Where(m => m.p.Weight > 0 && m.RetLin == null).Any() && g.Where(m => m.p.Weight == 0 && m.RetLin == null).Any()),
                Penalty = g.Sum(m => m.p.PenaltyAmt) - (g.Sum(m => m.p.IncentiveAmt) ?? 0),
            }).ToList();

            JobReceiveSummaryDetailViewModel vm = new JobReceiveSummaryDetailViewModel();

            vm.JobReceiveHeaderId         = id;
            vm.DocData                    = Header.DocDate;
            vm.JobWorkerId                = Header.JobWorkerId;
            vm.JobReceiveSummaryViewModel = JobReceives;
            PrepareViewBag(id);

            if (JobReceives.Count == 0)
            {
                return(Redirect(System.Configuration.ConfigurationManager.AppSettings["JobsDomain"] + "/JobReceiveHeader/Index/" + Header.DocTypeId));
            }
            else
            {
                return(View("Summary", vm));
            }
        }
Esempio n. 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 }));
        }