Files
BeWoPlaner/ReportImp/MobileEV/CustomReportCreator.cs

248 lines
10 KiB
C#

using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.DefaultReports;
using BeWo.Report.ReportObjects;
using BeWo.Service.DCEntityMapper;
using BS.Shared.DataContracts;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MobileEV
{
public class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
{
if (queryOid == 500)
{
return CreateLwlPruefliste(CreateQueryRO(queryOid, queryReportId));
}
return base.CreateQueryReport(queryOid, queryReportId);
}
private LwlPruefliste CreateLwlPruefliste(QueryRO queryRo)
{
var liste = new LwlPruefliste();
if (queryRo.Rows.Count > 0)
{
DateTime start = DateTime.MaxValue;
DateTime end = DateTime.MinValue;
if (queryRo.Rows[0].Field1 != null)
{
DateTime.TryParse(queryRo.Rows[0].Field1.ToString(), out start);
}
if (queryRo.Rows[0].Field2 != null)
{
DateTime.TryParse(queryRo.Rows[0].Field2.ToString(), out end);
}
long? customerOid = null;
if (queryRo.Rows[0].Field3.ToString() == "0")
{
var masterReport = new LwlPruefliste();
//masterReport.CreateDocument();
var customerList = DAOFactory.GenericDAO.GetAllActive<Customer>();
var customerListOrd = customerList.OrderBy(c => c.Person.LastNameFirstName).ToList();
foreach (var c in customerListOrd)
{
var ro = LwlPrueflisteRO.Create(start, end, "900 9848", c.Oid);
if (ro.ServiceRecords != null && ro.ServiceRecords.Count > 0)
{
try
{
liste = new LwlPruefliste();
liste.SetReportDataSource(ro);
liste.CreateDocument();
masterReport.Pages.AddRange(liste.Pages);
}
catch
{
// ignore - z.B. kein Hilfeplan
}
}
}
return (LwlPruefliste)masterReport;
}
if (queryRo.Rows[0].Field3 != null)
{
if (Int64.TryParse(queryRo.Rows[0].Field3.ToString(), out var oidOut))
{
customerOid = oidOut;
}
var ro = LwlPrueflisteRO.Create(start, end, "900 9848", customerOid);
liste.SetReportDataSource(ro);
return liste;
}
}
return liste;
}
public override XtraReport CreateSettlementReport(string dcId, long? invoiceBaseOid)
{
long result;
Settlement2DC lSettlementDC;
string cbName;
if (invoiceBaseOid.HasValue && invoiceBaseOid.Value > 0)
{
long invoiceOid = invoiceBaseOid.Value;
var ib = DAOFactory.GenericDAO.LoadByID<InvoiceBase>(invoiceOid);
cbName = ib.CostBearer2SupportConcept.CostBearer.Organisation.Name;
}
else
{
Int64.TryParse(dcId, out result);
lSettlementDC = MapperFactory.SettlementDC_SettlementInvoice.MapToNewDC(DAOFactory.GenericDAO.LoadByID<SettlementInvoice>(result));
cbName = lSettlementDC.RecipientOrganisation;
}
if (cbName.Contains("Landschaftsverband Westfalen-Lippe") || cbName == "LWL")
return base.CreateSettlementReport(dcId, invoiceBaseOid, true);
return base.CreateSettlementReport(dcId, invoiceBaseOid, false);
}
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);
if (lROs.Count > 0)
{
var rootReport = CreateServicesOverviewReportForRo(lROs[0], serviceCategoryOid);
if (!lROs[0].Costbearer.Contains("Stadt Dortmund") && !lROs[0].Costbearer.Contains("Stadt Bergkamen"))
rootReport.CreateDocument();
for (int i = 1; i < lROs.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(lROs[i], serviceCategoryOid);
if (!lROs[i].Costbearer.Contains("Stadt Dortmund") && !lROs[i].Costbearer.Contains("Stadt Bergkamen"))
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);
if (!roList[0].Costbearer.Contains("Stadt Dortmund") && !roList[0].Costbearer.Contains("Stadt Bergkamen"))
rootReport.CreateDocument();
for (int i = 1; i < roList.Count; i++)
{
var lNext = CreateServicesOverviewReportForRo(roList[i], serviceCategoryOid);
if (!roList[i].Costbearer.Contains("Stadt Dortmund") && !roList[i].Costbearer.Contains("Stadt Bergkamen"))
lNext.CreateDocument();
rootReport.Pages.AddRange(lNext.Pages);
}
return rootReport;
}
return new XtraReport();
}
private XtraReport CreateServicesOverviewReportForRo(ServicesOverviewRO ro, long? serviceCategoryOid)
{
//IBeWoReport<ServicesOverviewRO> report = null;
String kt = "";
if (!String.IsNullOrWhiteSpace(ro.Costbearer))
kt = ro.Costbearer.Trim();
if (kt == "Stadt Dortmund" || kt == "Stadt Bergkamen")
{
XtraReport report = null;
var leistungsnachweisRO = ServicesOverviewRO.CopyFromRO(ro);
leistungsnachweisRO.Services = ro.Services;
var taetigkeitsnachweisRO = ServicesOverviewRO.CopyFromRO(ro);
taetigkeitsnachweisRO.Services = ro.Services;
report = AddReportToReport<Leistungsnachweis>(report, leistungsnachweisRO);
if(ro.StartDate >= new DateTime(2023, 09, 01))
report = AddReportToReport<TaetigkeitsnachweisAbSept2023>(report, taetigkeitsnachweisRO);
else
report = AddReportToReport<Taetigkeitsnachweis>(report, taetigkeitsnachweisRO);
//report = new Leistungsnachweis();
//var xReport = report as XtraReport;
//var taetigkeitsnachweis = new Taetigkeitsnachweis();
//taetigkeitsnachweis.SetReportDataSource(taetigkeitsnachweisRO);
//xReport.Pages.AddRange((taetigkeitsnachweis as XtraReport).Pages);
//xReport.CreateDocument();
return report;
}
else
{
IBeWoReport<ServicesOverviewRO> report = null;
if (report == null)
report = new Quittierungsbeleg();
report.SetReportDataSource(ro);
return report as XtraReport;
}
}
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;
}
}
}