Files
BeWoPlaner/ReportImp/LebenshilfeStade/CustomReportCreator.cs

211 lines
7.6 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.ServiceImplementations;
using BS.Shared;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LebenshilfeStade
{
class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateServiceOverviewAllCustomersReport(int month, int year, long orgaOid, long empOid, long? serviceCategoryOid, int startDay, int endDay, bool nurFehlende)
{
List<ServicesOverviewRO> lROs = ServicesOverviewRO.Create(month, year, orgaOid, empOid, startDay, endDay, serviceCategoryOid, true, nurFehlende);
if (lROs.Count > 0)
{
String reportId = null;
if (orgaOid > 0)
{
var organisation = DAOFactory.GenericDAO.LoadByID<Organisation>(orgaOid);
if (organisation != null)
reportId = organisation.Name;
}
if (reportId == null)
reportId = lROs[0].Costbearer;
var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid, reportId);
if (rootReport.Pages.Count == 0)
rootReport.CreateDocument();
for (int i = 1; i < lROs.Count; i++)
{
reportId = lROs[i].Costbearer;
var lNext = CreateServicesOverviewReportForRo(lROs[i], serviceCategoryOid, reportId);
if (lNext.Pages.Count == 0)
lNext.CreateDocument();
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
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);
}
}
QBSortOrderEnum sortOrder = QBSortOrderEnum.NachKlient;
if (HttpContext.Current != null)
{
var so = HttpContext.Current.Request.Params["sortorder"];
if (!String.IsNullOrWhiteSpace(so))
{
sortOrder = (QBSortOrderEnum)(Int32.Parse(so));
}
}
if (sortOrder == QBSortOrderEnum.NachHauptbetreuung)
{
roList = roList.OrderBy(r => r.MainAttendant).ToList();
}
else
{
roList = roList.OrderBy(r => r.CustomerLastName + ", " + r.CustomerFirstName).ToList();
}
if (roList.Count > 0)
{
String reportId = null;
if (orgaOid.HasValue && orgaOid > 0)
{
var organisation = DAOFactory.GenericDAO.LoadByID<Organisation>(orgaOid.Value);
if (organisation != null)
reportId = organisation.Name;
}
if (reportId == null)
reportId = roList[0].Costbearer;
var rootReport = CreateServicesOverviewReportForRo(roList[0], serviceCategoryOid, reportId);
if (rootReport.Pages.Count == 0)
rootReport.CreateDocument();
for (int i = 1; i < roList.Count; i++)
{
reportId = roList[i].Costbearer;
var lNext = CreateServicesOverviewReportForRo(roList[i], serviceCategoryOid, reportId);
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)
{
String reportId = null;
if (orgaOid > 0)
{
var organisation = DAOFactory.GenericDAO.LoadByID<Organisation>(orgaOid);
if (organisation != null)
reportId = organisation.Name;
}
var ro = ServicesOverviewRO.Create(customerOid, month, year, false, orgaOid, empOid, startDay, endDay, serviceCategoryOid);
IBeWoReport<ServicesOverviewRO> lServiceOverviewSingleCustomerReport = new Stundenzettel();
if (reportId == null)
reportId = ro.Costbearer;
return CreateServicesOverviewReportForRo(ro, serviceCategoryOid, reportId);
}
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid, string reportID)
{
ServiceCategory sc = serviceCategoryOid != null ? DAOFactory.GenericDAO.GetByID<ServiceCategory>(serviceCategoryOid.Value) : null;
XtraReport report = null;
if (reportID != null && reportID.ToLower().Contains("neue fls ab 01/2024"))
{
ServicesOverviewRO qualiRO = ServicesOverviewRO.CopyFromRO(ro);
ServicesOverviewRO kompRO = ServicesOverviewRO.CopyFromRO(ro);
qualiRO.TotalFLMBillable = 0;
kompRO.TotalFLMBillable = 0;
if (ro.Services != null)
{
foreach (ServicesOverviewRO.ServiceDetail s in ro.Services)
{
if (s.ServiceCategory.ToLower().Contains("assistenz qualifiziert"))
{
qualiRO.Services.Add(s);
qualiRO.TotalFLMBillable += s.Minutes;
qualiRO.TotalFLS += s.Minutes / 50;
}
else if (s.ServiceCategory.ToLower().Contains("assistenz kompensatorisch"))
{
kompRO.Services.Add(s);
kompRO.TotalFLMBillable += s.Minutes;
kompRO.TotalFLS += s.Minutes / 50;
}
}
}
report = AddReportToReport<QuittierungsbelegNiedersachsen>(report, qualiRO);
report = AddReportToReport<QuittierungsbelegNiedersachsen>(report, kompRO);
}
else
{
report = AddReportToReport<Stundenzettel>(report, ro);
}
if (report == null)
report = new XtraReport();
return report;
}
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;
}
}
}