Files
BeWoPlaner/ReportImp/BeWoViersen/Reporting/CustomAnnualReportFactory.cs
2018-10-08 12:09:48 +02:00

141 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Service.Reporting;
using BS.Shared;
using BS.Shared.Core;
using BS.Shared.DataContracts;
using BS.Shared.Services;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.Plugins;
namespace BeWoViersen.Reporting
{
public class CustomAnnualReportFactory : AnnualReportFactory
{
private Dictionary<String, int> countPerBehinderungsartAll = new Dictionary<String, int>();
private Dictionary<String, int> countPerBehinderungsartMale = new Dictionary<String, int>();
private Dictionary<String, int> countPerBehinderungsartFemale = new Dictionary<String, int>();
protected override bool StichtagsbezogenAuswerten
{
get { return false; }
}
public override List<AnnualReportDC> CreateAnnualReport(CostBearer cb, long? teamOid, long? customerCareTypeValueListEntryOid, DateTime reportStartDate,
DateTime reportEndDate)
{
var reports = new List<AnnualReportDC>();
var basereports = base.CreateAnnualReport(cb, teamOid, customerCareTypeValueListEntryOid, reportStartDate, reportEndDate);
foreach (var r in basereports)
{
if (!r.Name.Contains("nach Ort"))
{
reports.Add(r);
}
}
// Nach Behinderung
var report = new AnnualReportDC();
report.Name = "Behinderungsarten";
reports.Add(report);
report.Data = new List<AnnualReportDataDC>();
int index = 1;
foreach (var vd in countPerBehinderungsartAll.Keys)
{
AnnualReportDataDC data = new AnnualReportDataDC();
report.Data.Add(data);
data.Index = index++;
data.Name = vd;
data.Value = countPerBehinderungsartAll[vd];
data.Male = countPerBehinderungsartMale[vd];
data.Female = countPerBehinderungsartFemale[vd];
}
report.Data.Sort((a, b) => a.Name.CompareTo(b.Name));
return reports;
}
public override void ProcessCustomer(Customer customer, List<CostBearer2SupportConcept> allCostBearer2SupportConcepts)
{
if (LiegtImStichtagByCustomerOid.ContainsKey(customer.Oid.Value))
{
String behinderung = GetBehinderungenList(customer);
if (String.IsNullOrEmpty(behinderung))
{
behinderung = "Ohne Angabe";
}
if (!countPerBehinderungsartAll.ContainsKey(behinderung))
{
countPerBehinderungsartAll[behinderung] = 0;
}
countPerBehinderungsartAll[behinderung] += 1;
if (!countPerBehinderungsartMale.ContainsKey(behinderung))
countPerBehinderungsartMale[behinderung] = 0;
if (customer.Person.Sex.HasValue && customer.Person.Sex.Value == Sex.Male)
{
countPerBehinderungsartMale[behinderung] += 1;
}
if (!countPerBehinderungsartFemale.ContainsKey(behinderung))
countPerBehinderungsartFemale[behinderung] = 0;
if (customer.Person.Sex.HasValue && customer.Person.Sex.Value == Sex.Female)
{
countPerBehinderungsartFemale[behinderung] += 1;
}
}
}
public override bool ShouldProcessSupportConcept(CostBearer2SupportConcept iCb2Sc, SupportConcept sc, Customer customer)
{
if (sc.IsActive != ActivationTypeId.Deleted && customer.IsActive != ActivationTypeId.Deleted)
{
if ((iCb2Sc.StartDate.HasValue && iCb2Sc.EndDate.HasValue))
{
if (CustomerBelongsToTeam(customer, TeamOid) &&
IsCustomerOfCustomerCareType(customer, CustomerCareTypeValueListEntryOid))
{
return true;
}
}
}
return false;
}
private String GetBehinderungenList(Customer customer)
{
String list = "";
List<String> behinderungen = new List<string>();
foreach (var v in customer.ValueList)
{
if (v.Entry.Type == ValueListEntryType.DisabilityType && v.Entry.IsActive == ActivationTypeId.Active)
{
behinderungen.Add(v.Entry.Value);
}
}
foreach (var b in behinderungen.OrderBy(a => a))
{
if (list.Length > 0)
{
list += ", ";
}
list += b;
}
return list;
}
}
}