diff --git a/ReportImp/Mittelpunkt/CustomReportCreator.cs b/ReportImp/Mittelpunkt/CustomReportCreator.cs index 90285762d..c87e662e1 100644 --- a/ReportImp/Mittelpunkt/CustomReportCreator.cs +++ b/ReportImp/Mittelpunkt/CustomReportCreator.cs @@ -1,17 +1,20 @@ -using System; +using BeWo.Data.Access; +using BeWo.Data.Entities; +using BeWo.Report; +using BeWo.Report.DefaultReports; +using BeWo.Report.ReportObjects; +using BeWo.Service.DCEntityMapper; +using BeWo.Service.ServiceImplementations; +using BS.Shared.Core; +using BS.Shared.DataContracts; +using BS.Shared.Extensions; +using DevExpress.XtraReports.UI; +using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; using System.Linq; -using BeWo.Data.Access; -using BeWo.Data.Entities; -using BeWo.Report; -using BeWo.Report.DefaultReports; -using BeWo.Report.ReportObjects; -using BS.Shared.Core; -using BS.Shared.Extensions; -using DevExpress.XtraReports.UI; namespace Mittelpunkt { @@ -475,5 +478,78 @@ namespace Mittelpunkt } } - } + public override XtraReport CreateRosterReportIst(long wOid, DateTime dt) + { + var opertionsService = new OperationsServiceImp(); + var customerService = new CustomerServiceImp(); + var employeeService = new EmployeeServiceImp(); + + var report = FindReportImp(); + + var dienstEintraege = opertionsService.GetAllDienstEintraegeAsList(wOid, dt.Year, dt.Month); + var vertretungen = opertionsService.GetAllDienstvertretungenAsList(wOid, dt.Year, dt.Month); + + List employeeOids = new List(); + foreach (var eintrag in dienstEintraege) + { + if (!employeeOids.Contains(eintrag.EmployeeOid)) + employeeOids.Add(eintrag.EmployeeOid); + } + foreach (var vertretung in vertretungen) + { + if (!employeeOids.Contains(vertretung.EmployeeOid)) + employeeOids.Add(vertretung.EmployeeOid); + } + + List employee = new List(); + foreach (var oid in employeeOids) + employee.Add(MapperFactory.EmployeeDC_Employee.MapToNewDC(DAOFactory.GenericDAO.GetByID(oid))); + + List absences = employeeService.GetMultipleEmployeeAbsenceTimesForMonth(dt.Year, dt.Month, employeeOids); + List feiertageDCs = opertionsService.ErstelleDefaultFeiertage(dt.Year).Where(f => f.Datum.Month == dt.Month).ToList(); + + Dictionary stundenBeiAbwesenheit = new Dictionary(); + foreach (var emp in employee) // Irgendwo hier drin Fehler + { + ContractDC currentContract = null; + foreach (var c in emp.Contracts) + { + if (!c.ContractEndDate.HasValue) + { + if (dt >= c.EntryDate) + { + currentContract = c; + break; + } + } + else + { + if (dt >= c.EntryDate && dt <= c.ContractEndDate) + { + currentContract = c; + break; + } + } + } + + if (currentContract != null) + { + if ((currentContract.WeeklyTotalHours == null && currentContract.MonthlyTotalHours == null) || currentContract.WeeklyDays == null) + continue; + else + { + if (currentContract.WeeklyTotalHours != null) + stundenBeiAbwesenheit.Add(emp.EmployeeOid, currentContract.WeeklyTotalHours.Value / currentContract.WeeklyDays); + else if (currentContract.MonthlyTotalHours != null) + stundenBeiAbwesenheit.Add(emp.EmployeeOid, currentContract.MonthlyTotalHours.Value / DateTime.DaysInMonth(dt.Year, dt.Month)); + } + } + } + + report.SetReportDataSource(RosterIstRO.Create(dienstEintraege, vertretungen, employee, opertionsService.GetAllDienste(wOid), + customerService.GetAllActiveWohnheimeCompact().First(x => x.WohnheimOid == wOid), dt.Year, dt.Month, feiertageDCs, absences, stundenBeiAbwesenheit)); + + return report as XtraReport; + } + } }