using System; using System.Collections.Generic; using BeWo.Data.Entities; using BeWo.Data.Access; using System.Linq; using BS.Shared.DataContracts; using BS.Shared.DataContracts.Compact; namespace BeWo.Report.ReportObjects { public class AbsenceRO : AbstractBeWoReportObject { public AbsenceOverviewFilterDC ReportFilter { get; set; } public List AbsenceReportRows { get; set; } public List Teams { get; set; } public List Feiertage { get; set; } public static AbsenceRO Create(List employees, AbsenceOverviewFilterDC filter, List teams, List feiertage) { var res = new AbsenceRO() { ReportFilter = filter, AbsenceReportRows = new List() }; var dt = new DateTime(filter.Year, filter.Month, 1); res.Teams = teams; res.Feiertage = feiertage; foreach (var emp in employees) { var row = new AbsenceReportRow { Employee = emp.LastNameFirstName }; var absenceTimes = emp.AbsenceTimes .OrderByDescending(x => x.End ?? DateTime.MaxValue) .OrderBy(x => x.Start) .ToArray(); int dayInMonth = 0; int absNum = 0; if (absenceTimes != null && absenceTimes.Length > 0) { var abs = absenceTimes[0]; while (dayInMonth < DateTime.DaysInMonth(filter.Year, filter.Month)) { if (abs.Start.Value > dt.AddDays(dayInMonth)) { dayInMonth++; continue; } if ((abs.End ?? DateTime.MaxValue) < dt.AddDays(dayInMonth)) { absNum++; if (absNum >= absenceTimes.Length) break; abs = absenceTimes[absNum]; continue; } row.Days[dayInMonth++] = new CellValue() { Value = abs.Reason.Description.Substring(0, 3), Color = abs.Reason.Color //Color = "#FFFFFF00" }; } } res.AbsenceReportRows.Add(row); } return res; } } public class AbsenceReportRow { public AbsenceReportRow() { Days = new CellValue[31]; } public string Employee { get; set; } public int Position { get; set; } public CellValue[] Days { get; private set; } public CellValue Day1 => Days[0]; public CellValue Day2 => Days[1]; public CellValue Day3 => Days[2]; public CellValue Day4 => Days[3]; public CellValue Day5 => Days[4]; public CellValue Day6 => Days[5]; public CellValue Day7 => Days[6]; public CellValue Day8 => Days[7]; public CellValue Day9 => Days[8]; public CellValue Day10 => Days[9]; public CellValue Day11 => Days[10]; public CellValue Day12 => Days[11]; public CellValue Day13 => Days[12]; public CellValue Day14 => Days[13]; public CellValue Day15 => Days[14]; public CellValue Day16 => Days[15]; public CellValue Day17 => Days[16]; public CellValue Day18 => Days[17]; public CellValue Day19 => Days[18]; public CellValue Day20 => Days[19]; public CellValue Day21 => Days[20]; public CellValue Day22 => Days[21]; public CellValue Day23 => Days[22]; public CellValue Day24 => Days[23]; public CellValue Day25 => Days[24]; public CellValue Day26 => Days[25]; public CellValue Day27 => Days[26]; public CellValue Day28 => Days[27]; public CellValue Day29 => Days[28]; public CellValue Day30 => Days[29]; public CellValue Day31 => Days[30]; } public class CellValue { public string Value { get; set; } public string Color { get; set; } public override string ToString() { return Value; } } }