Exemple #1
0
        private DisplayKpiInformationViewModel GetGeneralDerKpiInformations(int numberOfKpi, GetDerLayoutitemResponse layout, DateTime date, PeriodeType periodeType)
        {
            var viewModel = new DisplayKpiInformationViewModel();

            for (int i = 0; i < numberOfKpi; i++)
            {
                var kpiInformationVm = new DisplayKpiInformationViewModel.KpiInformationViewModel { Position = i };
                var item = layout.KpiInformations.FirstOrDefault(x => x.Position == i) ??
                           new GetDerLayoutitemResponse.KpiInformationResponse { Position = i };
                if (item.Kpi != null)
                {
                    kpiInformationVm = item.MapTo<DisplayKpiInformationViewModel.KpiInformationViewModel>();
                    //var achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, periodeType);
                    //kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                    if (item.ConfigType.Equals(ConfigType.KpiAchievement))
                    {
                        var achievement = new Services.Responses.KpiAchievement.GetKpiAchievementResponse();
                        if (item.Kpi.Id == 62)
                        {
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, new DateTime(date.Year, date.Month, 1), PeriodeType.Monthly);
                        }
                        else if (item.Kpi.Id == 385)
                        {
                            var prevMonth = date.AddMonths(-1);
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, new DateTime(prevMonth.Year, prevMonth.Month, 1), PeriodeType.Monthly);
                        }
                        else
                        {
                            achievement = _kpiAchievementService.GetKpiAchievement(item.Kpi.Id, date, periodeType);
                        }
                        kpiInformationVm.DerItemValue = achievement.MapTo<DerItemValueViewModel>();
                    }
                    else if (item.ConfigType.Equals(ConfigType.KpiTarget))
                    {
                        var target = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue { Kpi_Id = item.Kpi.Id, periode = date, PeriodeType = periodeType.ToString() });
                        kpiInformationVm.DerItemValue = target.MapTo<DerItemValueViewModel>();
                    }
                }

                viewModel.KpiInformationViewModels.Add(kpiInformationVm);
            }

            return viewModel;
        }
Exemple #2
0
        public GetDerLayoutitemResponse GetDerLayoutItem(int id)
        {
            var response = new GetDerLayoutitemResponse();
            try
            {
                var derLayoutItem = DataContext
                    .DerLayoutItems
                    .Include(x => x.DerLayout)
                    .Include(x => x.Artifact)
                    .Include(x => x.Artifact.Measurement)
                    .Include(x => x.Artifact.Series)
                    .Include(x => x.Artifact.Series.Select(y => y.Kpi))
                    /*.Include(x => x.Artifact.Charts)
                    .Include(x => x.Artifact.Charts.Select(y => y.Series))*/
                    .Include(x => x.Artifact.Charts.Select(y => y.Series.Select(z => z.Kpi)))
                    .Include(x => x.Artifact.Charts.Select(y => y.Measurement))
                    .Include(x => x.Artifact.Tank)
                    .Include(x => x.Artifact.Tank.VolumeInventory)
                    .Include(x => x.Artifact.Tank.DaysToTankTop)
                    .Include(x => x.Artifact.Tank.VolumeInventory.Measurement)
                    .Include(x => x.Artifact.Tank.DaysToTankTop.Measurement)
                    .Include(x => x.Highlight)
                    .Include(x => x.Highlight.SelectOption)
                    .Include(x => x.KpiInformations.Select(y => y.SelectOption))
                    .Include(x => x.KpiInformations.Select(y => y.Kpi.Measurement))
                    .Single(x => x.Id == id);

                response = derLayoutItem.MapTo<GetDerLayoutitemResponse>();
                response.IsSuccess = true;
            }
            catch (Exception exception)
            {
                response.Message = exception.Message;
            }

            return response;
        }
Exemple #3
0
        private DisplayKpiInformationViewModel.KpiInformationViewModel AddTarget(int position, GetDerLayoutitemResponse.KpiInformationResponse target, DateTime date)
        {
            var kpiInformationVm = new DisplayKpiInformationViewModel.KpiInformationViewModel { Position = position };

            if (target != null)
            {
                kpiInformationVm.DerItemValue = new DerItemValueViewModel();
                var daily = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = date,
                    PeriodeType = PeriodeType.Daily.ToString()
                });
                var mtd = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = new DateTime(date.Year, date.Month, 1),
                    PeriodeType = PeriodeType.Monthly.ToString()
                });

                var ytd = _kpiTargetService.GetKpiTargetByValue(new GetKpiTargetRequestByValue
                {
                    Kpi_Id = target.Kpi.Id,
                    periode = new DateTime(date.Year, 1, 1),
                    PeriodeType = PeriodeType.Yearly.ToString()
                });
                kpiInformationVm.DerItemValue.Value = daily.Value.ToString(); ;
                kpiInformationVm.DerItemValue.Mtd = mtd.Value.ToString(); ;
                kpiInformationVm.DerItemValue.Ytd = ytd.Value.ToString(); ;
                var obj = new
                {
                    daily = daily.Remark,
                    mtd = mtd.Remark,
                    ytd = ytd.Remark
                };
                var json = new JavaScriptSerializer().Serialize(obj);
                kpiInformationVm.DerItemValue.Remark = json;

            }

            return kpiInformationVm;
        }