Example #1
0
 private List<ChartDataItem> CalculateChartDataList()
 {
     var result = new List<ChartDataItem>();
     var targetSumm = Target != null ? Convert.ToDouble(Target.Summ) : 0;
     double planSumm1, planSumm2, planSumm3;
     SplitSummByMonths(targetSumm, out planSumm1, out planSumm2, out planSumm3);
     var startMonth = (Quarter - 1) * 3;
     var totalFactSumm = 0.0; var prevTotalFactPercent = 0.0;
     var totalPlanSumm = 0.0; var prevTotalPlanPercent = 0.0;
     for (var i = startMonth + 1; i <= WorkDate.Month; i++)
     {
         var monthPlanSumm = i == startMonth + 1 ? planSumm1 : i == startMonth + 2 ? planSumm2 : planSumm3;
         var stopDay = i == WorkDate.Month ? WorkDate.Day : DateTime.DaysInMonth(WorkDate.Year, i);
         var days = GetMonthWorkDays(i);
         var dayCount = 0;
         foreach (var day in days)
         {
             if (day.Day <= stopDay)
             {
                 // Fact
                 var item = new ChartDataItem() { Day = day };
                 item.FactSumm = RealSales.ContainsKey(day) ? RealSales[day] : 0;
                 totalFactSumm = Math.Round(totalFactSumm + item.FactSumm, 2);
                 item.TotalFactSumm = totalFactSumm;
                 item.TotalFactPercent = targetSumm != 0 ? Math.Round(item.TotalFactSumm / targetSumm * 100, 2) : 0;
                 item.FactPercent = Math.Round(item.TotalFactPercent - prevTotalFactPercent, 2);
                 prevTotalFactPercent = item.TotalFactPercent;
                 // Plan
                 item.PlanSumm = Math.Round(monthPlanSumm / (days.Count - dayCount), 2);
                 monthPlanSumm = Math.Round(monthPlanSumm - item.PlanSumm, 2);
                 totalPlanSumm = Math.Round(totalPlanSumm + item.PlanSumm, 2);
                 item.TotalPlanSumm = totalPlanSumm;
                 item.TotalPlanPercent = targetSumm != 0 ? Math.Round(item.TotalPlanSumm / targetSumm * 100, 2) : 0;
                 item.PlanPercent = Math.Round(item.TotalPlanPercent - prevTotalPlanPercent, 2);
                 prevTotalPlanPercent = item.TotalPlanPercent;
                 // Target
                 FillTargetParams(item);
                 result.Add(item);
                 dayCount++;
             }
         }
     }
     return result;
 }
Example #2
0
 private void FillTargetParams(ChartDataItem item)
 {
     if (Target == null) return;
     item.TargetName = null; item.TargetColor = Colors.Transparent;
     var coeff = item.TotalFactSumm / item.TotalPlanSumm;
     foreach (var addTarget in TargetCharts.OrderByDescending(c => c.Coeff).ToList())
     {
         if (coeff >= addTarget.Coeff)
         {
             item.TargetName = addTarget.Name;
             item.TargetColor = CommonHelper.StringToColor(addTarget.Color);
             break;
         }
     }
 }