Files
BeWoPlaner/ReportImp/DiakonieMuelheim/CustomReportCreator.cs
2021-02-02 23:23:05 +01:00

202 lines
6.4 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using BeWo.Data;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.DCEntityMapper;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.DataContracts.Compact;
using DevExpress.XtraReports.UI;
namespace DiakonieMuelheim
{
public class CustomReportCreator : DefaultReportCreator
{
public override XtraReport CreateQueryReport(long queryOid, string queryReportId)
{
if (queryOid == 300)
{
return CreateJahresstatistik(queryOid, queryReportId);
}
return base.CreateQueryReport(queryOid, queryReportId);
}
private XtraReport CreateJahresstatistik(long queryOid, string queryReportId)
{
var query = DAOFactory.GenericDAO.LoadByID<Query>(queryOid);
if (query == null)
return new XtraReport();
var path = Path.Combine(TempPath, queryReportId + ".xml");
var table = Utils.XMLDeserialize<DataTable>(path);
var qro = QueryRO.Create(query, table);
var customerOids = new List<long>();
DateTime start = DateTime.Now;
DateTime ende = DateTime.Now;
long teamOid = 0;
if (qro.Rows.Count > 0)
{
start = DateTime.Parse(qro.Rows[0].Field2.ToString());
ende = DateTime.Parse(qro.Rows[0].Field3.ToString());
teamOid = Int64.Parse(qro.Rows[0].Field4.ToString());
foreach (var row in qro.Rows)
{
long cOid = Int64.Parse(row.Field1.ToString());
customerOids.Add(cOid);
}
}
JahresReportRO ro = CreateJahresReportRo(customerOids, start, ende, teamOid);
var druck = new Jahresstatistik();
druck.SetReportDataSource(ro);
return druck;
}
private JahresReportRO CreateJahresReportRo(List<long> customerOids, DateTime start, DateTime ende, long teamOid)
{
List<JahrestatisticCustomerInfo> alleKlienten = new List<JahrestatisticCustomerInfo>();
var team = MapperFactory.CompactTeamDC_Team.MapToNewDC(DAOFactory.GenericDAO.LoadByID<Team>(teamOid));
var customers = DAOFactory.GenericDAO.LoadByIDs<Customer>(customerOids);
foreach (var customer in customers)
{
var info = GetJahrestatisticCustomerInfo(customer, start, ende);
if (info != null)
{
info.Team = team;
}
alleKlienten.Add(info);
}
List<AnnualReportDC> reports = new List<AnnualReportDC>();
reports.Add(BerechneGesamt(alleKlienten));
//data = BerechneOrt(alleKlienten);
return JahresReportRO.Create(reports);
}
private AnnualReportDC BerechneGesamt(List<JahrestatisticCustomerInfo> alleKlienten)
{
var report = new AnnualReportDC();
report.Name = "Personen insgesamt";
report.Data = new List<AnnualReportDataDC>();
var dataEk = new AnnualReportDataDC();
dataEk.Name = "davon Erstklienten EK";
dataEk.Value = 0;
var dataWk = new AnnualReportDataDC();
dataWk.Name = "Wiederholungs- und Altklienten WK";
dataWk.Value = 0;
report.Data.Add(dataEk);
report.Data.Add(dataWk);
foreach (var info in alleKlienten)
{
if (info.IstWiederholungsKlient)
{
dataWk.Value++;
}
else
{
dataEk.Value++;
}
}
return report;
}
private JahrestatisticCustomerInfo GetJahrestatisticCustomerInfo(Customer customer, DateTime start, DateTime ende)
{
JahrestatisticCustomerInfo info = null;
foreach (var sc in customer.SupportConcepts)
{
foreach (var c2s in sc.CostBearer2SupportConceptList)
{
foreach (var scap in c2s.ApprovalPeriodList)
{
//DateTime end = DateTime.Now;
//if (last == null && customer.AssistanceBegin.HasValue && customer.AssistanceBegin.Value < startdate)
//{
// startdate = customer.AssistanceBegin;
//}
if (scap.StartDate.HasValue && scap.EndDate.HasValue && scap.StartDate <= ende &&
scap.EndDate >= start)
{
info = new JahrestatisticCustomerInfo();
info.Customer = MapperFactory.CompactCustomerDC_Customer.MapToNewDC(customer);
info.IstWiederholungsKlient = HatAltenHilfeplan(c2s, scap, customer, start);
}
}
}
}
return info;
}
private bool HatAltenHilfeplan(CostBearer2SupportConcept basisC2S, SupportConceptApprovalPeriod basisScap, Customer customer, DateTime start)
{
foreach (var sc in customer.SupportConcepts)
{
foreach (var c2s in sc.CostBearer2SupportConceptList)
{
if (c2s.CostBearer.Oid == basisC2S.CostBearer.Oid)
{
foreach (var scap in c2s.ApprovalPeriodList)
{
if (scap.EndDate.HasValue && scap.EndDate.Value < start)
{
if ((basisScap.ServiceCategory == null && scap.ServiceCategory == null) ||
(basisScap.ServiceCategory != null && scap.ServiceCategory != null &&
basisScap.ServiceCategory.Oid == scap.ServiceCategory.Oid))
{
return true;
}
}
}
}
}
}
return false;
}
}
public class JahrestatisticCustomerInfo
{
public CompactCustomerDC Customer { get; set; }
public CompactTeamDC Team { get; set; }
public bool IstWiederholungsKlient { get; set; }
}
}