320 lines
14 KiB
C#
320 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Data.ICD10;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
|
|
namespace DomizielAnsbach
|
|
{
|
|
public partial class BerichtBezirkZV : DevExpress.XtraReports.UI.XtraReport //, IBeWoReport<FinanceRO>
|
|
{
|
|
public BerichtBezirkZV()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(FinanceRO pRO)
|
|
{
|
|
DateTime start = pRO.ReportStartDate.Value;
|
|
DateTime end = pRO.ReportEndDate.Value;
|
|
DateTime monthStart;
|
|
DateTime monthEnd;
|
|
DateTime krankEnd;
|
|
decimal rowOrder = 0;
|
|
decimal cCount = 0;
|
|
|
|
var listLength = pRO.SupportConceptFinanceList.Count;
|
|
|
|
for (int i = listLength - 1; i >= 0; i--)
|
|
{
|
|
var sc = pRO.SupportConceptFinanceList[i];
|
|
if (sc.Costbearer2Supportconcept.ApprovalPeriodList != null && sc.Costbearer2Supportconcept.ApprovalPeriodList[0].ServiceCategory == null ||
|
|
sc.Costbearer2Supportconcept.ApprovalPeriodList[0].ServiceCategory.Name != "Zuverdienst - Arbeitszeit")
|
|
pRO.SupportConceptFinanceList.Remove(sc);
|
|
}
|
|
var extendedEndByRo = new Dictionary<FinanceRO.SupportConceptFinanceRO, DateTime?>();
|
|
pRO.SupportConceptFinanceList = pRO.SupportConceptFinanceList
|
|
.GroupBy(s => s.Costbearer2Supportconcept.SupportConcept.Customer.CustomerOid)
|
|
.Select(g =>
|
|
{
|
|
// Pro Kunde nur eine Zeile/ein Block (wie bisher). Hat ein Kunde aber mehrere aufeinanderfolgende HPs,
|
|
// wird die frueheste Zuordnung als Repraesentant genommen und das spaeteste EndDate aller Zuordnungen als effektives Ende gemerkt.
|
|
var ordered = g.OrderBy(s => s.Costbearer2Supportconcept.StartDate).ToList();
|
|
var rep = ordered.First();
|
|
if (ordered.Count > 1)
|
|
{
|
|
if (ordered.Any(s => !s.Costbearer2Supportconcept.EndDate.HasValue))
|
|
{
|
|
extendedEndByRo[rep] = null;
|
|
}
|
|
else
|
|
{
|
|
extendedEndByRo[rep] = ordered.Max(s => s.Costbearer2Supportconcept.EndDate);
|
|
}
|
|
}
|
|
return rep;
|
|
})
|
|
.ToList();
|
|
|
|
listLength = pRO.SupportConceptFinanceList.Count;
|
|
for (int i = 0; i < listLength; i++)
|
|
{
|
|
var sc = pRO.SupportConceptFinanceList[i];
|
|
DateTime? scEndDate;
|
|
if (!extendedEndByRo.TryGetValue(sc, out scEndDate))
|
|
{
|
|
scEndDate = sc.Costbearer2Supportconcept.EndDate;
|
|
}
|
|
DateTime periodEnd = DateTime.MinValue;
|
|
cCount += 1;
|
|
bool firstRow = true;
|
|
Customer c = null;
|
|
|
|
if (sc.Costbearer2Supportconcept.SupportConcept.Customer.Oid.HasValue)
|
|
c = DAOFactory.GenericDAO.LoadByID<Customer>(sc.Costbearer2Supportconcept.SupportConcept.Customer.Oid.Value);
|
|
|
|
if (scEndDate >= start && sc.Costbearer2Supportconcept.StartDate <= end)
|
|
{
|
|
if (sc.Costbearer2Supportconcept.StartDate <= start)
|
|
monthStart = start;
|
|
else
|
|
monthStart = (DateTime)sc.Costbearer2Supportconcept.StartDate;
|
|
|
|
for (int m = 0; m <= pRO.ReportEndDate.Value.Month - monthStart.Month;)
|
|
{
|
|
monthEnd = new DateTime(monthStart.Year, monthStart.Month, 1).AddMonths(1).AddDays(-1);
|
|
krankEnd = monthEnd;
|
|
sc.Costbearer2Supportconcept.SupportConcept.Customer.AbsenceTimes = sc.Costbearer2Supportconcept.SupportConcept.Customer.AbsenceTimes.OrderBy(a => a.Start.Value).ToList();
|
|
foreach (var at in sc.Costbearer2Supportconcept.SupportConcept.Customer.AbsenceTimes)
|
|
{
|
|
if (at.Reason.BillableMinutes.HasValue && at.Reason.Description.Contains("ZV"))
|
|
{
|
|
if (at.Start.HasValue && at.End.HasValue && ((at.Start.Value >= monthStart && at.Start.Value <= monthEnd)
|
|
|| (at.End.Value >= monthStart && at.Start.Value <= monthStart))
|
|
&& (!at.Reason.Description.Contains("Feiertag") && !at.Reason.Description.Contains("Urlaub") && !at.Reason.Description.Contains("mit AU")))
|
|
{
|
|
periodEnd = at.Start.Value.AddDays(-1);
|
|
krankEnd = at.End.Value;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var ro = new FinanceRO.SupportConceptFinanceRO();
|
|
ro.CustomerName = sc.CustomerName;
|
|
if (ro.CustomerName.Contains("Gruber"))
|
|
{
|
|
int tuao = 1;
|
|
}
|
|
ro.CostBearerName = sc.CostBearerName;
|
|
rowOrder += 1;
|
|
ro.RateFactor = rowOrder;
|
|
|
|
if (c.Arbeitszeiten != null)
|
|
{
|
|
if (periodEnd == DateTime.MinValue)
|
|
ro.ApprovedHours = GetVertraglicheZeit(c, monthEnd, monthStart);
|
|
else
|
|
ro.ApprovedHours = GetVertraglicheZeit(c, periodEnd, monthStart);
|
|
}
|
|
|
|
if (ro.ApprovedHours == 0 && scEndDate < monthEnd && krankEnd <= monthEnd)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (periodEnd != DateTime.MinValue && (periodEnd < start || periodEnd < monthStart))
|
|
{
|
|
monthStart = krankEnd.AddDays(1);
|
|
}
|
|
//ro.Custom1 = String.Format("{0:dd.MM.yyyy}", krankEnd.AddDays(1));
|
|
else
|
|
{
|
|
ro.Custom1 = String.Format("{0:dd.MM.yyyy}", monthStart);
|
|
|
|
if (periodEnd != DateTime.MinValue && periodEnd.AddDays(1) != monthStart || monthStart != new DateTime(monthEnd.Year, monthEnd.Month, 1))
|
|
{
|
|
if (periodEnd == DateTime.MinValue)
|
|
periodEnd = monthEnd;
|
|
if (scEndDate.HasValue && scEndDate > monthStart && periodEnd > scEndDate) // falls direkt im ersten Monat wieder beendet wird
|
|
{
|
|
periodEnd = scEndDate.Value;
|
|
}
|
|
ro.Custom2 = String.Format("{0:dd.MM.yyyy}", periodEnd);
|
|
}
|
|
else
|
|
{
|
|
ro.Custom2 = String.Format("{0:dd.MM.yyyy}", monthEnd);
|
|
if (scEndDate.HasValue && scEndDate > monthStart && scEndDate < monthEnd)
|
|
{
|
|
ro.Custom2 = String.Format("{0:dd.MM.yyyy}", scEndDate.Value);
|
|
}
|
|
}
|
|
|
|
if (firstRow == true)
|
|
{
|
|
sc.ApprovedHours = ro.ApprovedHours;
|
|
sc.Custom1 = ro.Custom1;
|
|
sc.Custom2 = ro.Custom2;
|
|
sc.Custom3 = GetKrankheiten(c);
|
|
sc.Custom4 = GetSGBIIStatus(c);
|
|
sc.Custom5 += cCount.ToString();
|
|
sc.RateFactor = rowOrder;
|
|
|
|
firstRow = false;
|
|
}
|
|
else
|
|
{
|
|
pRO.SupportConceptFinanceList.Add(ro);
|
|
}
|
|
}
|
|
|
|
if (periodEnd != DateTime.MinValue && periodEnd != monthEnd)
|
|
{
|
|
monthStart = krankEnd.AddDays(1);
|
|
periodEnd = monthEnd;
|
|
if (monthStart.Month > periodEnd.Month)
|
|
{
|
|
periodEnd = DateTime.MinValue;
|
|
}
|
|
if (monthStart == monthEnd.AddDays(1))
|
|
{
|
|
periodEnd = monthStart.AddMonths(1).AddDays(-1);
|
|
m++;
|
|
}
|
|
}
|
|
else if ((periodEnd == DateTime.MinValue || periodEnd == monthEnd) && monthEnd == end)
|
|
{
|
|
m++;
|
|
}
|
|
else if (periodEnd == DateTime.MinValue || periodEnd == monthEnd || krankEnd.AddDays(1) <= monthEnd)
|
|
{
|
|
monthStart = new DateTime(monthStart.Year, monthStart.AddMonths(1).Month, 1);
|
|
periodEnd = DateTime.MinValue;
|
|
m = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private static decimal GetVertraglicheZeit(Customer c, DateTime periodEnd, DateTime monthStart)
|
|
{
|
|
decimal std = 0;
|
|
foreach (var az in c.Arbeitszeiten)
|
|
{
|
|
if ((!az.GueltigVon.HasValue || az.GueltigVon <= periodEnd) &&
|
|
(!az.GueltigBis.HasValue || az.GueltigBis >= monthStart) && az.ArbeitszeitEintraege != null)
|
|
{
|
|
foreach (var e in az.ArbeitszeitEintraege)
|
|
{
|
|
if (e.Notice != "Pause")
|
|
std += GetZeitenFuerTag(e) / 60;
|
|
else
|
|
std -= GetZeitenFuerTag(e) / 60;
|
|
}
|
|
}
|
|
}
|
|
return std;
|
|
}
|
|
|
|
private static decimal GetZeitenFuerTag(ArbeitszeitEintrag e)
|
|
{
|
|
var day = DateTime.Now;
|
|
decimal min = 0;
|
|
|
|
String dateStr1 = String.Format("{0:dd.MM.yyyy} {1}", day, e.UhrzeitVon);
|
|
String dateStr2 = String.Format("{0:dd.MM.yyyy} {1}", day, e.UhrzeitBis);
|
|
|
|
DateTime date1;
|
|
DateTime date2;
|
|
|
|
if (DateTime.TryParse(dateStr1, out date1) && DateTime.TryParse(dateStr2, out date2))
|
|
min += (decimal)date2.Subtract(date1).TotalMinutes;
|
|
|
|
return min;
|
|
}
|
|
|
|
private string GetSGBIIStatus(Customer c)
|
|
{
|
|
foreach (var vv in c.VarFieldValueList)
|
|
{
|
|
var varFieldValue = Utils.XMLDeserializeFromString(vv.SerializedValue, Type.GetType(vv.TypeName));
|
|
if (varFieldValue != null && vv.IsActive == ActivationTypeId.Active)
|
|
{ if (vv.VarFieldDefOid.Value == 19)
|
|
{
|
|
if (varFieldValue.ToString() == "True")
|
|
return "ja";
|
|
else
|
|
return "nein";
|
|
}
|
|
}
|
|
}
|
|
return "nein";
|
|
}
|
|
|
|
private string GetKrankheiten(Customer c)
|
|
{
|
|
string krankheiten = null;
|
|
foreach (var vv in c.VarFieldValueList)
|
|
{
|
|
var varFieldValue = Utils.XMLDeserializeFromString(vv.SerializedValue, Type.GetType(vv.TypeName));
|
|
if (varFieldValue != null && vv.IsActive == ActivationTypeId.Active)
|
|
{
|
|
if (vv.VarFieldDefOid.Value == 29)
|
|
{
|
|
if (varFieldValue.ToString() == "True")
|
|
{
|
|
if (krankheiten != null)
|
|
{
|
|
krankheiten += ", ";
|
|
}
|
|
krankheiten += "psychisch";
|
|
}
|
|
}
|
|
if (vv.VarFieldDefOid.Value == 30)
|
|
{
|
|
if (varFieldValue.ToString() == "True")
|
|
{
|
|
if (krankheiten != null)
|
|
{
|
|
krankheiten += ", ";
|
|
}
|
|
krankheiten += "suchtkrank";
|
|
}
|
|
}
|
|
if (vv.VarFieldDefOid.Value == 31)
|
|
{
|
|
if (varFieldValue.ToString() == "True")
|
|
{
|
|
if (krankheiten != null)
|
|
{
|
|
krankheiten += ", ";
|
|
}
|
|
krankheiten += "körperbehindert";
|
|
}
|
|
}
|
|
if (vv.VarFieldDefOid.Value == 32)
|
|
{
|
|
if (varFieldValue.ToString() == "True")
|
|
{
|
|
if (krankheiten != null)
|
|
{
|
|
krankheiten += ", ";
|
|
}
|
|
krankheiten += "geistigbehindert";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return krankheiten;
|
|
}
|
|
}
|
|
}
|