Files
BeWoPlaner/ReportImp/TranskulturellesBetreuungsbuero/CustomReportCreator.cs
2026-07-08 09:55:34 +02:00

333 lines
13 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using DevExpress.Emf;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using TranskulturellesBetreuungsbuero;
using static BeWo.Report.ReportObjects.FLSReportRO;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
namespace TranskulturellesBetreuungsbuero
{
public class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
{
List<ServicesOverviewRO> lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
if (lROs.Count > 0)
{
var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid);
if (rootReport.Pages.Count == 0)
{
rootReport.CreateDocument();
}
for (int i = 1; i < lROs.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(lROs[i], serviceCategoryOid);
if (lNext.Pages.Count == 0)
{
lNext.CreateDocument();
}
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
public override XtraReport CreateServiceOverviewSingleCustomerReport(long customerOid, int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay)
{
var ro = ServicesOverviewRO.Create(customerOid, month, year, false, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
return CreateServicesOverviewReportForRo(ro, serviceCategoryOid);
}
public override XtraReport CreateServiceOverviewReportForCustomers(IList<long> customerOids, int month, int year, long? orgaOid, long? empOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende)
{
var roList = new List<ServicesOverviewRO>();
foreach (var coid in customerOids)
{
var ro = ServicesOverviewRO.Create(coid, month, year, true, orgaOid ?? 0, empOid ?? 0, startDay, endDay, serviceCategoryOid);
if (ro != null)
{
roList.Add(ro);
}
}
if (roList.Count > 0)
{
var rootReport = CreateServicesOverviewReportForRo(roList[0], serviceCategoryOid);
rootReport.CreateDocument();
for (int i = 1; i < roList.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(roList[i], serviceCategoryOid);
lNext.CreateDocument();
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid)
{
ServicesOverviewRO defaultRo = ServicesOverviewRO.CopyFromRO(ro);
ServicesOverviewRO sozioRo = ServicesOverviewRO.CopyFromRO(ro);
if (ro.Services != null)
{
foreach (ServicesOverviewRO.ServiceDetail s in ro.Services)
{
ServicesOverviewRO.CreateSignatureString(s);
if (s.ServiceCategory.ToLower().Contains("sozio"))
{
sozioRo.Services.Add(s);
}
else
{
defaultRo.Services.Add(s);
}
}
}
XtraReport report = null;
report = AddReportToReport<Quittierungsbeleg>(report, defaultRo);
report = AddReportToReport<LeistungsnachweisSoziotherapie>(report, sozioRo);
if (report == null)
report = new XtraReport();
return report;
}
public override XtraReport CreateReportForServicesOverviewRo(ServicesOverviewRO ro, string reportId)
{
return CreateServicesOverviewReportForRo(ro, null);
}
private XtraReport AddReportToReport<T>(XtraReport report, ServicesOverviewRO ro) where T : XtraReport, IBeWoReport<ServicesOverviewRO>, new()
{
if (ro.Services.Count > 0)
{
if (report == null)
{
report = new T();
((T)report).SetReportDataSource(ro);
}
else
{
if (report.Pages.Count == 0)
{
report.CreateDocument();
}
XtraReport newReport = new T();
((T)newReport).SetReportDataSource(ro);
newReport.CreateDocument();
report.Pages.AddRange(newReport.Pages);
}
}
return report;
}
public override XtraReport CreateFlsReport(string flsReportId, string subType)
{
#region Standard
string flsReportPath = BS.Shared.Core.Utils.CreateSavePath(TempPath, flsReportId + ".xml");
var lFLSAnalysisDataReportDC = Utils.XMLDeserialize<FLSAnalysisDataReportDC>(flsReportPath);
IBeWoReport<FLSReportRO> lFLSReportObject = null;
if (!String.IsNullOrEmpty(subType))
lFLSReportObject = this.FindReportImp<FLSReportRO>(subType);
if (lFLSReportObject == null)
lFLSReportObject = this.FindReportImp<FLSReportRO>(lFLSAnalysisDataReportDC.ShowGroups
? "FLSAuswertung"
: "Leistungsdokumentation");
#endregion
// lFLSAnalysisDataReportDC.ReportType = 0: Nach MA
// lFLSAnalysisDataReportDC.ReportType = 1: Nach Klient:innen
var ro = FLSReportRO.Create(lFLSAnalysisDataReportDC);
Dictionary<long, Customer> customerDict = new Dictionary<long, Customer>();
Dictionary<long, Employee> employeeDict = new Dictionary<long, Employee>();
Dictionary<Employee, List<FLSReportServiceRecord>> employee2Arbeitszeiteintraege = new Dictionary<Employee, List<FLSReportServiceRecord>>();
// Im RO muss in den Klienten stehen, ob es Hauptbetreuung (FLSReportGroups.FLSReportDetail.CustomValue1) oder
// Stellvertretung (FLSReportGroups.FLSReportDetail.CustomValue2) ist
foreach (var group in ro.FLSReportGroups)
{
decimal summeEigeneFlsInMin = 0;
decimal summeVertretungsFlsInMin = 0;
decimal summeArbeitszeitInMin = 0;
foreach (var detail in group.FLSReportDetails)
{
detail.CustomValue3 = string.Format("{0:0.00}", detail.TotalFLM / 60);
if (detail.ServiceRecords != null)
{
foreach (var sr in detail.ServiceRecords)
{
// Alle schon vorgekommene Customer und Employee zwischenspeichern, damit die Serveraufrufe nicht so viele sind
if (sr.CustomerOid.HasValue && !customerDict.ContainsKey(sr.CustomerOid.Value))
{
customerDict.Add(sr.CustomerOid.Value, DAOFactory.GenericDAO.GetByID<Customer>(sr.CustomerOid.Value));
}
if (sr.EmployeeOid.HasValue && !employeeDict.ContainsKey(sr.EmployeeOid.Value))
{
employeeDict.Add(sr.EmployeeOid.Value, DAOFactory.GenericDAO.GetByID<Employee>(sr.EmployeeOid.Value));
}
var emp = employeeDict[sr.EmployeeOid.Value];
// Alle Einträge, die unter "Sonstiges" fallen würden (also Arbeitszeit) sammeln, damit ein Detail pro Leistung erstellt werden kann
if (sr.CostBearer2SupportConceptOid == null && sr.CustomerOid == null)
{
if (!employee2Arbeitszeiteintraege.ContainsKey(emp))
employee2Arbeitszeiteintraege.Add(emp, new List<FLSReportServiceRecord>());
employee2Arbeitszeiteintraege[emp].Add(sr);
summeArbeitszeitInMin += sr.RoundedDuration;
}
// Sonst für das Detail bestimmen, ob Klient Vertreten wird oder Hauptbetreuung ist ("Fallkoordination")
else if (sr.EmployeeOid.HasValue && sr.CustomerOid.HasValue)
{
if (emp.Employee2CustomerList != null && emp.Employee2CustomerList.Count > 0)
{
var e2cList = emp.Employee2CustomerList.Where(e => e.CustomerOid == sr.CustomerOid).ToList();
bool hatZuordnung = false;
if (e2cList != null)
{
foreach (var e2c in e2cList)
{
if (e2c.StartDate.HasValue && e2c.EndDate.HasValue)
{
if (!ro.ReportStartDate.Value.InBetween(e2c.StartDate.Value, e2c.EndDate.Value, true) &&
!ro.ReportEndDate.Value.InBetween(e2c.StartDate.Value, e2c.EndDate.Value, true))
continue;
}
if (e2c.ValueList != null)
{
foreach (var entry in e2c.ValueList)
{
if (entry.Entry.Type == BS.Shared.ValueListEntryType.StaffRoleType)
{
if (entry.Entry.SystemEntryID != null && entry.Entry.SystemEntryID == BS.Shared.SystemEntryID.EmployeeRoleMainAttendant)
{
detail.CustomValue1 = "X";
summeEigeneFlsInMin += sr.RoundedDuration;
}
else
{
detail.CustomValue2 = "X";
summeVertretungsFlsInMin += sr.RoundedDuration;
}
hatZuordnung = true;
}
}
}
}
}
if (!hatZuordnung)
{
detail.CustomValue2 = "X";
summeVertretungsFlsInMin += sr.RoundedDuration;
}
}
}
}
}
}
// Summe gesamte FLS
group.CustomValue1 = string.Format("{0:0.00}", (summeEigeneFlsInMin + summeVertretungsFlsInMin) / 60);
// davon eigene FLS
group.CustomValue2 = string.Format("{0:0.00}", summeEigeneFlsInMin / 60);
// davon vertretene FLS
group.CustomValue3 = string.Format("{0:0.00}", summeVertretungsFlsInMin / 60);
// Summe sonstige Arbeitszeit
group.CustomValue4 = string.Format("{0:0.00}", summeArbeitszeitInMin / 60);
// Summe FLS + Arbeitszeit
group.CustomValue5 = string.Format("{0:0.00}", (summeEigeneFlsInMin + summeVertretungsFlsInMin + summeArbeitszeitInMin) / 60);
}
// Wenn nach MA ausgewertet wird, können die AZ-Einträge ans Detail angehangen werden
if (lFLSAnalysisDataReportDC.ReportType == 0)
{
foreach (var group in ro.FLSReportGroups)
{
// Jede Leistung mit ihrer Gesamtsumme speichern
Dictionary<string, decimal> leistung2Summe = new Dictionary<string, decimal>();
foreach (var e2a in employee2Arbeitszeiteintraege)
{
if (group.Name.Contains(e2a.Key.Person.FirstName) && group.Name.Contains(e2a.Key.Person.LastName))
{
foreach (var sr in e2a.Value)
{
if (!leistung2Summe.ContainsKey(sr.ServiceDescription))
leistung2Summe.Add(sr.ServiceDescription, 0);
leistung2Summe[sr.ServiceDescription] += sr.RoundedDuration;
}
}
var detailSonstiges = group.FLSReportDetails.FirstOrDefault(d => d.Name == "Sonstiges");
// Sonstiges-Item wird nicht mehr benötigt, da ja alles detailliert dargestellt werden soll
if (detailSonstiges != null)
{
group.FLSReportDetails.Remove(detailSonstiges);
}
}
// Jetzt statt dem Sonstiges-Item eine Überschrift und dann jede Leistung mit Dauer als eigenes Detail erzeugen;
group.FLSReportDetails.Add(new FLSReportRO.FLSReportDetail()
{
Name = "Sonstige Arbeitszeiten",
CustomValue3 = "AZ/Monat IST"
});
foreach (var item in leistung2Summe)
{
group.FLSReportDetails.Add(new FLSReportRO.FLSReportDetail()
{
Name = item.Key,
TotalFLM = item.Value,
CustomValue3 = string.Format("{0:0.00}", item.Value / 60),
TotalHourMinuteString = "ARBEITSZEIT"
});
}
}
}
// Wird widerum nach Klient*innen ausgewertet, haben die Arbeitszeiten ne eigene FLSReportGroup
else if (lFLSAnalysisDataReportDC.ReportType == 1)
{
}
lFLSReportObject.SetReportDataSource(ro);
return lFLSReportObject as XtraReport;
}
}
}