Пример #1
0
        public ActionResult GetReport(int id)
        {
            var reportInfo = ReportService.GetReportInfoById(id);
            BaseReportViewModel viewModel = null;

            var viewModelType = reportInfo == null ? null : Type.GetType(reportInfo.ViewModelName);

            if (viewModelType != null && viewModelType == typeof(StatisticalReportViewModel))
            {
                var reportData = ReportService.GetReportById(reportInfo.ReportId, new ReportParameter {
                    TableName = reportInfo.TableName, ColumnList = reportInfo.ColumnList ?? "a.*"
                });
                viewModel = new StatisticalReportViewModel(reportInfo.ReportId, (StandardReport)reportData,
                                                           (StandardReport)
                                                           ReportService.GetReportById(reportInfo.ReportId, new ReportParameter {
                    RowName = "1", TableName = reportInfo.TableName, ColumnList = reportInfo.ColumnList
                }));
            }
            else
            {
                viewModel = new BasicReportViewModel(reportInfo.ReportId, new StandardReport(id));
            }

            viewModel.Name = reportInfo.DisplayName;
            viewModel.Initialization();

            if (viewModel is StatisticalReportViewModel)
            {
                ViewData["IsStatisticReport_" + reportInfo.ReportId] = false;
                var themeName = ThemeHelper.GetTheme(Request);
                ((StatisticalReportViewModel)viewModel).TopChartModel.Theme    = themeName;
                ((StatisticalReportViewModel)viewModel).BottomChartModel.Theme = themeName;
            }
            return(View(reportInfo == null ? "BasicReport" : reportInfo.ViewName, viewModel));
        }
        public void Models_BaseReportViewModel_Default_Instantiate_Should_Pass()
        {
            // Act
            var result = new BaseReportViewModel();

            // Assert
            Assert.IsNotNull(result, TestContext.TestName);
        }
        public void Models_BaseReportViewModel_Get_Set_Check_All_Fields_Should_Pass()
        {
            // Arrange



            // Act
            // Set all the fields for a BaseReportViewModel
            var test = new BaseReportViewModel
            {
                StudentId          = DataSourceBackend.Instance.StudentBackend.GetDefault().Id,
                Student            = DataSourceBackend.Instance.StudentBackend.GetDefault(),
                DateStart          = new DateTime(2000, 12, 30),
                DateEnd            = new DateTime(2018, 8, 7),
                AttendanceList     = new List <AttendanceReportViewModel>(),
                Stats              = new StudentReportStatsModel(),
                Goal               = 100,
                YearArray          = "2018, 2018",
                MonthArray         = "1, 1",
                DayArray           = "1, 1",
                PerfectValues      = "100, 200",
                GoalValues         = "80, 160",
                ActualValues       = "50, 100",
                EmotionLevelValues = "1, 3"
            };

            var expectedStudentId          = DataSourceBackend.Instance.StudentBackend.GetDefault().Id;
            var expectedStudent            = DataSourceBackend.Instance.StudentBackend.GetDefault();
            var expectedDateStart          = new DateTime(2000, 12, 30);
            var expectedDateEnd            = new DateTime(2018, 8, 7);
            var expectedGoal               = 100;
            var expectedYearArray          = "2018, 2018";
            var expectedMonthArray         = "1, 1";
            var expectedDayArray           = "1, 1";
            var expectedPerfectValues      = "100, 200";
            var expectedGoalValues         = "80, 160";
            var expectedActualValues       = "50, 100";
            var expectedEmotionLevelValues = "1, 3";

            // Assert

            //Check each value
            Assert.AreEqual(test.StudentId, expectedStudentId, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.Student, expectedStudent, "Student " + TestContext.TestName);
            Assert.AreEqual(test.DateStart, expectedDateStart, "DateStart " + TestContext.TestName);
            Assert.AreEqual(test.DateEnd, expectedDateEnd, "DateEnd " + TestContext.TestName);
            Assert.AreEqual(test.Goal, expectedGoal, "Goal " + TestContext.TestName);
            Assert.IsNotNull(test.AttendanceList, "AttendanceList " + TestContext.TestName);
            Assert.IsNotNull(test.Stats, "Stats " + TestContext.TestName);
            Assert.AreEqual(test.YearArray, expectedYearArray, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.MonthArray, expectedMonthArray, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.DayArray, expectedDayArray, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.PerfectValues, expectedPerfectValues, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.GoalValues, expectedGoalValues, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.ActualValues, expectedActualValues, "StudentId " + TestContext.TestName);
            Assert.AreEqual(test.EmotionLevelValues, expectedEmotionLevelValues, "StudentId " + TestContext.TestName);
        }
Пример #4
0
        /// <summary>
        /// Generate overall report
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        public BaseReportViewModel GenerateOverallReport(BaseReportViewModel report)
        {
            //set student
            report.Student = DataSourceBackend.Instance.StudentBackend.Read(report.StudentId);

            //set start date and end date according to school dismissal settings
            report.DateStart = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayFirst.Date;
            report.DateEnd   = DataSourceBackend.Instance.SchoolDismissalSettingsBackend.GetDefault().DayLast.Date;


            GenerateReportFromStartToEnd(report);

            return(report);
        }
        public ActionResult SolucionesAr(BaseReportViewModel reportViewModel)
        {
            var transactionsList = _transactionsManagement.GetTransactions(reportViewModel.BeginningDate,
                                                                           reportViewModel.EndingDate);
            var tList = ReportInfoFromList(transactionsList);

            using (var excelPackage = new ExcelPackage())
            {
                var worksheet = excelPackage.Workbook.Worksheets.Add("Primera Hoja");

                //Here we have to select one of the following options: Manual or Auto writting
                //With the auto option, we should create a new class to avoid the complex objects mapping problems
                //instead of using the simple Transaction Class

                //1. Manual

                worksheet.Cells["A1"].Value = CODIGO_FACTURA;
                worksheet.Cells["B1"].Value = MONTO;
                worksheet.Cells["C1"].Value = PUNTOS;
                worksheet.Cells["D1"].Value = CODIGO_SAR;
                worksheet.Cells["E1"].Value = NOMBRE_VENDEDOR;
                worksheet.Cells["F1"].Value = FECHA;
                //worksheet.Cells["G1"].Value = TIENDA;
                worksheet.Cells["G1"].Value = COMPANIA;

                /*
                 * int i = 2;
                 * foreach (var transaction in transactionsList)
                 * {
                 *  worksheet.Cells["A" + i].Value = transaction.Amount;
                 *  worksheet.Cells["B" + i].Value = transaction.Amount;
                 *  i++;
                 * }
                 */
                //2. Automatic
                if (tList != null && tList.Count() != 0)
                {
                    worksheet.Cells["A2"].LoadFromCollection(tList);
                }

                return(File(excelPackage.GetAsByteArray(), "application/vnd.ms-excel", "a_cool_name.xls"));
            }
        }
Пример #6
0
        public virtual ActionResult GetReport(int id)
        {
            var reportInfo = ReportService.GetReportInfoById(id);
            BaseReportViewModel viewModel = null;
            var viewModelType             = System.Type.GetType(reportInfo.ViewModelName);

            if (viewModelType != null)
            {
                viewModel      = (BaseReportViewModel)Activator.CreateInstance(viewModelType, new object[] { reportInfo.ReportId, UserSettingHelper.GetUserId(Request) });
                viewModel.ID   = reportInfo.ReportId;
                viewModel.Name = reportInfo.DisplayName;
                viewModel.Initialization(Request);
            }
            else
            {
                ViewBag.ID   = reportInfo.ReportId;
                ViewBag.Name = reportInfo.DisplayName;
            }
            return(PartialView(reportInfo.ViewName, viewModel));
        }
 public ActionResult Application(BaseReportViewModel reportViewModel)
 {
     return(View());
 }
Пример #8
0
        /// <summary>
        /// Generate the report from the start date to the end date
        /// </summary>
        /// <param name="report"></param>
        /// <returns></returns>
        private void GenerateReportFromStartToEnd(BaseReportViewModel report)
        {
            var myDateNow = UTCConversionsBackend.UtcToKioskTime(DateTimeHelper.Instance.GetDateTimeNowUTC()).Date; //today's date in kiosk time zone

            // Don't go beyond today
            if (report.DateEnd.CompareTo(myDateNow) > 0)
            {
                report.DateEnd = myDateNow;
            }

            var currentDate = report.DateStart;                    //loop variable

            TimeSpan accumlatedTotalHoursExpected = TimeSpan.Zero; //current accumulated total hours expected
            TimeSpan accumlatedTotalHours         = TimeSpan.Zero; //current accululated total hours attended
            int      emotionLevel = 0;                             //current emotion level

            while (currentDate.CompareTo(report.DateEnd) <= 0)     //loop until last date, include last date
            {
                //create a new AttendanceReportViewmodel for each day
                var temp = new AttendanceReportViewModel
                {
                    Date = currentDate
                };

                // Hold the emotion for the null condition
                temp.EmotionUri = "/content/img/placeholder.png";

                //get today's school calendar model
                var myToday = DataSourceBackend.Instance.SchoolCalendarBackend.ReadDate(currentDate);

                // if the day is not a school day, set IsSchoolDay to false
                if (myToday == null || myToday.SchoolDay == false)
                {
                    temp.IsSchoolDay = false;
                }

                // if the day is a school day, perform calculations
                else
                {
                    temp.HoursExpected = myToday.TimeDuration;

                    // Find out if the student attended that day, and add that in.  Because the student can check in/out multiple times add them together.
                    var myRange = report.Student.Attendance.Where(m => UTCConversionsBackend.UtcToKioskTime(m.In).Date == currentDate.Date).OrderBy(m => m.In).ToList();

                    //if no attendance record on this day, set attendance status to absent
                    if (!myRange.Any())
                    {
                        temp.AttendanceStatus = AttendanceStatusEnum.AbsentUnexcused;
                        report.Stats.DaysAbsentUnexcused++;
                    }
                    else
                    {
                        temp.AttendanceStatus = AttendanceStatusEnum.Present;

                        //set TimeIn to be the first check-in time in the list, so that if there are multiple check-ins,
                        //the TimeIn is set to the first check-in time. Same for emotion.
                        temp.TimeIn     = UTCConversionsBackend.UtcToKioskTime(myRange.First().In);
                        temp.Emotion    = myRange.First().Emotion;
                        temp.EmotionUri = Emotion.GetEmotionURI(temp.Emotion);

                        //determine whether is on time or late
                        if (temp.TimeIn.TimeOfDay > myToday.TimeStart)
                        {
                            temp.CheckInStatus = CheckInStatusEnum.ArriveLate;
                        }
                        else
                        {
                            temp.CheckInStatus = CheckInStatusEnum.ArriveOnTime;
                        }

                        // a list containing all intervals in this day
                        List <Interval> intervals = new List <Interval>();

                        //loop through all attendance records in my range
                        foreach (var item in myRange)
                        {
                            TimeSpan timeIn  = UTCConversionsBackend.UtcToKioskTime(item.In).TimeOfDay;
                            TimeSpan timeOut = UTCConversionsBackend.UtcToKioskTime(item.Out).TimeOfDay;
                            Interval inter   = new Interval(timeIn, timeOut);

                            intervals.Add(inter);

                            //update the checkout time for this attendance report view model
                            temp.TimeOut = UTCConversionsBackend.UtcToKioskTime(item.Out);

                            //determine whether left early or not
                            if (temp.TimeOut.TimeOfDay < myToday.TimeEnd)
                            {
                                temp.CheckOutStatus = CheckOutStatusEnum.DoneEarly;
                            }
                            else
                            {
                                temp.CheckOutStatus = CheckOutStatusEnum.DoneAuto;
                            }
                        }

                        report.Stats.DaysPresent++;  //increase number of days present

                        var earlyWindow = SchoolDismissalSettingsBackend.Instance.GetDefault().EarlyWindow;
                        var lateWindow  = SchoolDismissalSettingsBackend.Instance.GetDefault().LateWindow;
                        //the time from which duration starts to count
                        var start = myToday.TimeStart.Add(-earlyWindow);
                        //the time that duration counts until
                        var end = myToday.TimeEnd.Add(lateWindow);

                        //Calculate hours attended on this day
                        temp.HoursAttended = CalculateHoursAttended(intervals, start, end);

                        temp.PercentAttended = (int)(temp.HoursAttended.TotalMinutes * 100 / temp.HoursExpected.TotalMinutes);  //calculate percentage of attended time

                        if (temp.CheckInStatus == CheckInStatusEnum.ArriveLate)
                        {
                            report.Stats.DaysLate++;
                        }

                        report.Stats.DaysOnTime = report.Stats.DaysPresent - report.Stats.DaysLate;

                        if (temp.CheckOutStatus == CheckOutStatusEnum.DoneEarly)
                        {
                            report.Stats.DaysOutEarly++;
                        }

                        report.Stats.DaysOutAuto = report.Stats.DaysPresent - report.Stats.DaysOutEarly;
                    }

                    switch (temp.Emotion)
                    {
                    case EmotionStatusEnum.VeryHappy:
                        temp.EmotionLevel = emotionLevel + 2;
                        report.Stats.DaysVeryHappy++;
                        break;

                    case EmotionStatusEnum.Happy:
                        temp.EmotionLevel = emotionLevel + 1;
                        report.Stats.DaysHappy++;
                        break;

                    case EmotionStatusEnum.Neutral:
                        temp.EmotionLevel = emotionLevel;
                        report.Stats.DaysNeutral++;
                        break;

                    case EmotionStatusEnum.Sad:
                        temp.EmotionLevel = emotionLevel - 1;
                        report.Stats.DaysSad++;
                        break;

                    case EmotionStatusEnum.VerySad:
                        temp.EmotionLevel = emotionLevel - 2;
                        report.Stats.DaysVerySad++;
                        break;

                    default:
                        temp.EmotionLevel = emotionLevel;
                        break;
                    }

                    emotionLevel = temp.EmotionLevel;
                    //calculations for both absent and present records
                    //calculations for both absent and present records
                    report.Stats.NumOfSchoolDays++;
                    accumlatedTotalHoursExpected += temp.HoursExpected;
                    accumlatedTotalHours         += temp.HoursAttended;

                    // Need to add the totals back to the temp, because the temp is new each iteration
                    temp.TotalHoursExpected += accumlatedTotalHoursExpected;
                    temp.TotalHours          = accumlatedTotalHours;
                }

                //add this attendance report to the attendance list
                report.AttendanceList.Add(temp);

                currentDate = currentDate.AddDays(1);
            }

            report.Stats.AccumlatedTotalHoursExpected = accumlatedTotalHoursExpected;
            report.Stats.AccumlatedTotalHours         = accumlatedTotalHours;

            //if there is at least one school days in this report, calculate the following stats
            if (report.Stats.NumOfSchoolDays > 0)
            {
                report.Stats.PercPresent       = (int)Math.Round((double)report.Stats.DaysPresent * 100 / report.Stats.NumOfSchoolDays);
                report.Stats.PercAttendedHours =
                    (int)Math.Round(report.Stats.AccumlatedTotalHours.TotalHours * 100 / report.Stats.AccumlatedTotalHoursExpected.TotalHours);
                report.Stats.PercExcused   = (int)Math.Round((double)report.Stats.DaysAbsentExcused * 100 / report.Stats.NumOfSchoolDays);
                report.Stats.PercUnexcused = (int)Math.Round((double)report.Stats.DaysAbsentUnexcused * 100 / report.Stats.NumOfSchoolDays);
                if (report.Stats.DaysPresent > 0)
                {
                    report.Stats.PercInLate   = (int)Math.Round((double)report.Stats.DaysLate * 100 / report.Stats.DaysPresent);
                    report.Stats.PercOutEarly = (int)Math.Round((double)report.Stats.DaysOutEarly * 100 / report.Stats.DaysPresent);
                }
            }

            //set the attendance goal percent according to school dismissal settings
            report.Goal = SchoolDismissalSettingsBackend.Instance.GetDefault().Goal;

            //set the date array, ideal value array and actual value array for line chart
            report.YearArray    = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Year.ToString()).ToArray());
            report.MonthArray   = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Month.ToString()).ToArray());
            report.DayArray     = @String.Join(", ", report.AttendanceList.Where(m => m.IsSchoolDay).ToList().Select(m => m.Date.Day.ToString()).ToArray());
            report.ActualValues = @String.Join(", ",
                                               report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                               .Select(m => m.TotalHours.TotalHours.ToString("0.#")).ToArray());
            report.PerfectValues = @String.Join(", ",
                                                report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                                .Select(m => m.TotalHoursExpected.TotalHours.ToString("0.#")).ToArray());
            report.GoalValues = @String.Join(", ",
                                             report.AttendanceList.Where(m => m.IsSchoolDay).ToList()
                                             .Select(m => (m.TotalHoursExpected.TotalHours * (report.Goal) / 100).ToString("0.#")).ToArray());
            report.EmotionLevelValues = @String.Join(", ",
                                                     report.AttendanceList.Where(m => m.IsSchoolDay).Select(m => m.EmotionLevel).ToArray());
        }