428 lines
15 KiB
C#
428 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using BS.Shared;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using DevExpress.Entity.Model;
|
|
|
|
|
|
namespace BeWo.Report.ReportObjects
|
|
{
|
|
public class AdditionalServiceBookingRO : AbstractBeWoReportObject<AdditionalServiceBookingRO>
|
|
{
|
|
public String Month { get; set; }
|
|
|
|
public int MonthInt { get; set; }
|
|
|
|
public int Year { get; set; }
|
|
|
|
public String AdditionalServiceRegion { get; set; }
|
|
|
|
public String AdditionalService { get; set; }
|
|
|
|
public List<AdditionalServiceBookingRow> Rows { get; set; }
|
|
|
|
public static AdditionalServiceBookingRO Create(AdditionalServiceRegion region, Monat month, int year)
|
|
{
|
|
var result = new AdditionalServiceBookingRO
|
|
{
|
|
Rows = new List<AdditionalServiceBookingRow>(),
|
|
AdditionalServiceRegion = region.Name,
|
|
AdditionalService = region.AdditionalService.Name,
|
|
Month = month.ToString(),
|
|
MonthInt = (int)month,
|
|
Year = year
|
|
};
|
|
|
|
var additionalServiceBookings =
|
|
DAOFactory.GenericDAO.GetAll<AdditionalServiceBooking>()
|
|
.Where(
|
|
booking =>
|
|
booking.AdditionalServiceRegion == region &&
|
|
booking.Datum.Value.Month == (int)month &&
|
|
booking.Datum.Value.Year == year);
|
|
|
|
var c2aodList = new Dictionary<CompactCustomerDC, string[]>();
|
|
|
|
|
|
foreach (var item in additionalServiceBookings)
|
|
{
|
|
if (item.Datum == null) continue;
|
|
foreach (var e in item.Customer2AddServiceBookings)
|
|
{
|
|
var customer = DAOFactory.GenericDAO.GetByID<Customer>(e.CustomerOid);
|
|
var cdc = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(customer);
|
|
|
|
if (c2aodList.ContainsKey(cdc))
|
|
{
|
|
c2aodList[cdc][item.Datum.Value.Day - 1] = (e.Participated ? "P" : "");
|
|
}
|
|
else
|
|
{
|
|
var attendancies = new string[31];
|
|
attendancies[item.Datum.Value.Day - 1] = (e.Participated ? "P" : "");
|
|
|
|
c2aodList.Add(cdc, attendancies);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach (var item in c2aodList)
|
|
{
|
|
result.Rows.Add(new AdditionalServiceBookingRow
|
|
{
|
|
CustomerDC = item.Key,
|
|
Customer = item.Key.LastNameFirstName,
|
|
AttendanceOnDay1 = item.Value[0] ?? "",
|
|
AttendanceOnDay2 = item.Value[1] ?? "",
|
|
AttendanceOnDay3 = item.Value[2] ?? "",
|
|
AttendanceOnDay4 = item.Value[3] ?? "",
|
|
AttendanceOnDay5 = item.Value[4] ?? "",
|
|
AttendanceOnDay6 = item.Value[5] ?? "",
|
|
AttendanceOnDay7 = item.Value[6] ?? "",
|
|
AttendanceOnDay8 = item.Value[7] ?? "",
|
|
AttendanceOnDay9 = item.Value[8] ?? "",
|
|
AttendanceOnDay10 = item.Value[9] ?? "",
|
|
AttendanceOnDay11 = item.Value[10] ?? "",
|
|
AttendanceOnDay12 = item.Value[11] ?? "",
|
|
AttendanceOnDay13 = item.Value[12] ?? "",
|
|
AttendanceOnDay14 = item.Value[13] ?? "",
|
|
AttendanceOnDay15 = item.Value[14] ?? "",
|
|
AttendanceOnDay16 = item.Value[15] ?? "",
|
|
AttendanceOnDay17 = item.Value[16] ?? "",
|
|
AttendanceOnDay18 = item.Value[17] ?? "",
|
|
AttendanceOnDay19 = item.Value[18] ?? "",
|
|
AttendanceOnDay20 = item.Value[19] ?? "",
|
|
AttendanceOnDay21 = item.Value[20] ?? "",
|
|
AttendanceOnDay22 = item.Value[21] ?? "",
|
|
AttendanceOnDay23 = item.Value[22] ?? "",
|
|
AttendanceOnDay24 = item.Value[23] ?? "",
|
|
AttendanceOnDay25 = item.Value[24] ?? "",
|
|
AttendanceOnDay26 = item.Value[25] ?? "",
|
|
AttendanceOnDay27 = item.Value[26] ?? "",
|
|
AttendanceOnDay28 = item.Value[27] ?? "",
|
|
AttendanceOnDay29 = item.Value[28] ?? "",
|
|
AttendanceOnDay30 = item.Value[29] ?? "",
|
|
AttendanceOnDay31 = item.Value[30] ?? ""
|
|
});
|
|
}
|
|
|
|
result.Rows.Sort((a, b) => a.Customer.CompareTo(b.Customer));
|
|
return result;
|
|
}
|
|
|
|
public static Dictionary<DateTime, IList<AbsenceTimeDC>> CreateAbsenceTimeDict(CompactCustomerDC customer, DateTime maxEndDate)
|
|
{
|
|
|
|
Dictionary<DateTime, IList<AbsenceTimeDC>> dict = new Dictionary<DateTime, IList<AbsenceTimeDC>>();
|
|
|
|
foreach (var at in customer.AbsenceTimes)
|
|
{
|
|
if (at.Start.HasValue && at.Start.Value <= maxEndDate)
|
|
{
|
|
DateTime dt = at.Start.Value;
|
|
DateTime end = maxEndDate;
|
|
|
|
if (at.End.HasValue && at.End.Value < end)
|
|
{
|
|
end = at.End.Value;
|
|
}
|
|
|
|
while (dt <= end)
|
|
{
|
|
if (!dict.ContainsKey(dt))
|
|
{
|
|
dict.Add(dt, new List<AbsenceTimeDC>());
|
|
}
|
|
dict[dt].Add(at);
|
|
dt = dt.AddDays(1);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return dict;
|
|
|
|
}
|
|
|
|
public static void CalculateAbsenceTimes(AdditionalServiceBookingRO result)
|
|
{
|
|
foreach (var row in result.Rows)
|
|
{
|
|
int monthCount = 0;
|
|
int yearCount = 0;
|
|
|
|
foreach (var at in row.CustomerDC.AbsenceTimes)
|
|
{
|
|
if (at.Start.HasValue && at.Start.Value.Year <= result.Year &&
|
|
(!at.End.HasValue || at.End.Value.Year >= result.Year))
|
|
{
|
|
DateTime dt = at.Start.Value;
|
|
DateTime end = new DateTime(result.Year, result.MonthInt, 1).AddMonths(1);
|
|
|
|
if (at.End.HasValue && at.End.Value < end)
|
|
{
|
|
end = at.End.Value;
|
|
}
|
|
|
|
while (dt <= end)
|
|
{
|
|
if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
|
|
{
|
|
if (dt.Year == result.Year)
|
|
{
|
|
yearCount++;
|
|
}
|
|
|
|
if (dt.Month == result.MonthInt)
|
|
{
|
|
monthCount++;
|
|
|
|
var name = at.Reason.Description.ToLower();
|
|
if (name.Contains("urlaub"))
|
|
{
|
|
SetInfo(dt, row, "U");
|
|
}
|
|
else if (name.Contains("krank"))
|
|
{
|
|
SetInfo(dt, row, "K");
|
|
}
|
|
else if (name.Contains("unentschuldigt"))
|
|
{
|
|
SetInfo(dt, row, "UE");
|
|
}
|
|
else if (name.Contains("entschuldigt"))
|
|
{
|
|
SetInfo(dt, row, "E");
|
|
}
|
|
else if (name.Contains("corona"))
|
|
{
|
|
SetInfo(dt, row, "C");
|
|
}
|
|
}
|
|
}
|
|
|
|
dt = dt.AddDays(1);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
row.AbsenceTimeMonthCount = monthCount;
|
|
row.AbsenceTimeYearCount = yearCount;
|
|
}
|
|
|
|
}
|
|
|
|
private static void SetInfo(DateTime dt, AdditionalServiceBookingRow row, string val)
|
|
{
|
|
if (dt.Day == 1)
|
|
{
|
|
row.AttendanceOnDay1 = val;
|
|
}
|
|
else if (dt.Day == 2)
|
|
{
|
|
row.AttendanceOnDay2 = val;
|
|
}
|
|
else if (dt.Day == 3)
|
|
{
|
|
row.AttendanceOnDay3 = val;
|
|
}
|
|
else if (dt.Day == 4)
|
|
{
|
|
row.AttendanceOnDay4 = val;
|
|
}
|
|
else if (dt.Day == 5)
|
|
{
|
|
row.AttendanceOnDay5 = val;
|
|
}
|
|
else if (dt.Day == 6)
|
|
{
|
|
row.AttendanceOnDay6 = val;
|
|
}
|
|
else if (dt.Day == 7)
|
|
{
|
|
row.AttendanceOnDay7 = val;
|
|
}
|
|
else if (dt.Day == 8)
|
|
{
|
|
row.AttendanceOnDay8 = val;
|
|
}
|
|
else if (dt.Day == 9)
|
|
{
|
|
row.AttendanceOnDay9 = val;
|
|
}
|
|
else if (dt.Day == 10)
|
|
{
|
|
row.AttendanceOnDay10 = val;
|
|
}
|
|
else if (dt.Day == 11)
|
|
{
|
|
row.AttendanceOnDay11 = val;
|
|
}
|
|
else if (dt.Day == 12)
|
|
{
|
|
row.AttendanceOnDay12 = val;
|
|
}
|
|
else if (dt.Day == 13)
|
|
{
|
|
row.AttendanceOnDay13 = val;
|
|
}
|
|
else if (dt.Day == 14)
|
|
{
|
|
row.AttendanceOnDay14 = val;
|
|
}
|
|
else if (dt.Day == 15)
|
|
{
|
|
row.AttendanceOnDay15 = val;
|
|
}
|
|
else if (dt.Day == 16)
|
|
{
|
|
row.AttendanceOnDay16 = val;
|
|
}
|
|
else if (dt.Day == 17)
|
|
{
|
|
row.AttendanceOnDay17 = val;
|
|
}
|
|
else if (dt.Day == 18)
|
|
{
|
|
row.AttendanceOnDay18 = val;
|
|
}
|
|
else if (dt.Day == 19)
|
|
{
|
|
row.AttendanceOnDay19 = val;
|
|
}
|
|
else if (dt.Day == 20)
|
|
{
|
|
row.AttendanceOnDay20 = val;
|
|
}
|
|
else if (dt.Day == 21)
|
|
{
|
|
row.AttendanceOnDay21 = val;
|
|
}
|
|
else if (dt.Day == 22)
|
|
{
|
|
row.AttendanceOnDay22 = val;
|
|
}
|
|
else if (dt.Day == 23)
|
|
{
|
|
row.AttendanceOnDay23 = val;
|
|
}
|
|
else if (dt.Day == 24)
|
|
{
|
|
row.AttendanceOnDay24 = val;
|
|
}
|
|
else if (dt.Day == 25)
|
|
{
|
|
row.AttendanceOnDay25 = val;
|
|
}
|
|
else if (dt.Day == 26)
|
|
{
|
|
row.AttendanceOnDay26 = val;
|
|
}
|
|
else if (dt.Day == 27)
|
|
{
|
|
row.AttendanceOnDay27 = val;
|
|
}
|
|
else if (dt.Day == 28)
|
|
{
|
|
row.AttendanceOnDay28 = val;
|
|
}
|
|
else if (dt.Day == 29)
|
|
{
|
|
row.AttendanceOnDay29 = val;
|
|
}
|
|
else if (dt.Day == 30)
|
|
{
|
|
row.AttendanceOnDay30 = val;
|
|
}
|
|
else if (dt.Day == 31)
|
|
{
|
|
row.AttendanceOnDay31 = val;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class AdditionalServiceBookingRow
|
|
{
|
|
public CompactCustomerDC CustomerDC { get; set; }
|
|
|
|
public string Customer { get; set; } // Nachname, Vorname
|
|
|
|
public string AttendanceOnDay1 { get; set; } // O -> nicht anwesend, P -> anwesend
|
|
|
|
public string AttendanceOnDay2 { get; set; }
|
|
|
|
public string AttendanceOnDay3 { get; set; }
|
|
|
|
public string AttendanceOnDay4 { get; set; }
|
|
|
|
public string AttendanceOnDay5 { get; set; }
|
|
|
|
public string AttendanceOnDay6 { get; set; }
|
|
|
|
public string AttendanceOnDay7 { get; set; }
|
|
|
|
public string AttendanceOnDay8 { get; set; }
|
|
|
|
public string AttendanceOnDay9 { get; set; }
|
|
|
|
public string AttendanceOnDay10 { get; set; }
|
|
|
|
public string AttendanceOnDay11 { get; set; }
|
|
|
|
public string AttendanceOnDay12 { get; set; }
|
|
|
|
public string AttendanceOnDay13 { get; set; }
|
|
|
|
public string AttendanceOnDay14 { get; set; }
|
|
|
|
public string AttendanceOnDay15 { get; set; }
|
|
|
|
public string AttendanceOnDay16 { get; set; }
|
|
|
|
public string AttendanceOnDay17 { get; set; }
|
|
|
|
public string AttendanceOnDay18 { get; set; }
|
|
|
|
public string AttendanceOnDay19 { get; set; }
|
|
|
|
public string AttendanceOnDay20 { get; set; }
|
|
|
|
public string AttendanceOnDay21 { get; set; }
|
|
|
|
public string AttendanceOnDay22 { get; set; }
|
|
|
|
public string AttendanceOnDay23 { get; set; }
|
|
|
|
public string AttendanceOnDay24 { get; set; }
|
|
|
|
public string AttendanceOnDay25 { get; set; }
|
|
|
|
public string AttendanceOnDay26 { get; set; }
|
|
|
|
public string AttendanceOnDay27 { get; set; }
|
|
|
|
public string AttendanceOnDay28 { get; set; }
|
|
|
|
public string AttendanceOnDay29 { get; set; }
|
|
|
|
public string AttendanceOnDay30 { get; set; }
|
|
|
|
public string AttendanceOnDay31 { get; set; }
|
|
|
|
public int AbsenceTimeMonthCount { get; set; }
|
|
|
|
public int AbsenceTimeYearCount { get; set; }
|
|
|
|
public string Notice { get; set; }
|
|
}
|
|
}
|