public JsonResult jsonData(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId)
        {
            //add summary data
            List<DeliveredOntimeChartMonthlyViewModels> viewSummaryModel = new List<DeliveredOntimeChartMonthlyViewModels>();

            // filter by department
            var q = objBs.ontimeDeliveryMonthBs.GetAll().Where(x => !String.IsNullOrEmpty(x.DepartmentName)
                                               && !String.IsNullOrEmpty(x.SectionName)
                                               && !String.IsNullOrEmpty(x.MatName)
                                               && x.Year == YearId);
            //&& x.DepartmentId == DepartmentId
            //filter Department
            if (!String.IsNullOrEmpty(DepartmentId))
                q = q.Where(x => x.DepartmentId == DepartmentId);

            //filter Section
            if (!String.IsNullOrEmpty(SectionId))
                q = q.Where(x => x.SectionId == SectionId);

            //filter matname
            if (!String.IsNullOrEmpty(MatNameId))
                q = q.Where(x => x.MatFriGrp == MatNameId);

            //filter month
            if (!String.IsNullOrEmpty(MonthId))
                q = q.Where(x => x.Month == MonthId);

            // DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(Convert.ToInt32(m.Month)).ToString()
            var results = (from c in q
                           group c by new { c.Month } into g
                           select new {
                               Month = g.Key.Month,
                               Plan = 98.0,
                               Actual = ((double)g.Sum(x => x.OnTime) / (double)g.Sum(x => x.SumOfDelivery)) * 100,
                               Adjust = (((double)g.Sum(x => x.OnTime) + (double)g.Sum(x => x.AdjustDelivery))
                                        / (double)g.Sum(x => x.SumOfDelivery)) * 100,
                               SumOfDelivery = g.Sum(x => x.SumOfDelivery)
                           }).ToList().OrderBy(x => int.Parse(x.Month)); ;

            foreach (var item in results) {
                DeliveredOntimeChartMonthlyViewModels model = new DeliveredOntimeChartMonthlyViewModels();
                model.Month = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(Convert.ToInt32(item.Month));
                model.Plan = item.Plan;
                model.Actual = Math.Round(item.Actual, 2);
                model.Adjust = Math.Round(item.Adjust, 2);
                model.PlanOfDelivery = 500;
                model.SumOfDelivery = item.SumOfDelivery;
                viewSummaryModel.Add(model);
            }

            return Json(viewSummaryModel, JsonRequestBehavior.AllowGet);
        }
예제 #2
0
        public JsonResult jsonData(string DepartmentId, string SectionId, string YearId, string MonthId, string MatNameId)
        {
            //add summary data
            List <DeliveredOntimeChartMonthlyViewModels> viewSummaryModel = new List <DeliveredOntimeChartMonthlyViewModels>();

            // filter by department
            var q = objBs.ontimeDeliveryMonthBs.GetAll().Where(x => !String.IsNullOrEmpty(x.DepartmentName) &&
                                                               !String.IsNullOrEmpty(x.SectionName) &&
                                                               !String.IsNullOrEmpty(x.MatName) &&
                                                               x.Year == YearId);

            //&& x.DepartmentId == DepartmentId
            //filter Department
            if (!String.IsNullOrEmpty(DepartmentId))
            {
                q = q.Where(x => x.DepartmentId == DepartmentId);
            }

            //filter Section
            if (!String.IsNullOrEmpty(SectionId))
            {
                q = q.Where(x => x.SectionId == SectionId);
            }

            //filter matname
            if (!String.IsNullOrEmpty(MatNameId))
            {
                q = q.Where(x => x.MatFriGrp == MatNameId);
            }

            //filter month
            if (!String.IsNullOrEmpty(MonthId))
            {
                q = q.Where(x => x.Month == MonthId);
            }

            // DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(Convert.ToInt32(m.Month)).ToString()
            var results = (from c in q
                           group c by new { c.Month } into g
                           select new {
                Month = g.Key.Month,
                Plan = 98.0,
                Actual = ((double)g.Sum(x => x.OnTime) / (double)g.Sum(x => x.SumOfDelivery)) * 100,
                Adjust = (((double)g.Sum(x => x.OnTime) + (double)g.Sum(x => x.AdjustDelivery))
                          / (double)g.Sum(x => x.SumOfDelivery)) * 100,
                SumOfDelivery = g.Sum(x => x.SumOfDelivery)
            }).ToList().OrderBy(x => int.Parse(x.Month));;

            foreach (var item in results)
            {
                DeliveredOntimeChartMonthlyViewModels model = new DeliveredOntimeChartMonthlyViewModels();
                model.Month          = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(Convert.ToInt32(item.Month));
                model.Plan           = item.Plan;
                model.Actual         = Math.Round(item.Actual, 2);
                model.Adjust         = Math.Round(item.Adjust, 2);
                model.PlanOfDelivery = 500;
                model.SumOfDelivery  = item.SumOfDelivery;
                viewSummaryModel.Add(model);
            }

            return(Json(viewSummaryModel, JsonRequestBehavior.AllowGet));
        }