Files
BeWoPlaner/ReportImp/Nous/LeistungsnachweisFamilienhilfe.cs
2025-10-06 13:26:48 +02:00

298 lines
13 KiB
C#

using System;
using System.Collections.Generic;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BeWo.Service.Plugins;
using BS.Shared;
using BS.Shared.Services;
namespace Nous
{
public partial class LeistungsnachweisFamilienhilfe : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<ServicesOverviewRO>
{
public LeistungsnachweisFamilienhilfe()
{
InitializeComponent();
}
public void SetReportDataSource(ServicesOverviewRO pRO)
{
bool hatGruppen = false;
double summeFls = 0;
double summeAusfall = 0;
double summeWege = 0;
Dictionary<String, String> empDict = new Dictionary<string, string>();
List<String> employees = new List<string>();
String emp = "";
if (pRO.Services != null)
{
List<ServicesOverviewRO.ServiceDetail> servicesBillable = new List<ServicesOverviewRO.ServiceDetail>();
foreach (ServicesOverviewRO.ServiceDetail s in pRO.Services)
{
if (!empDict.ContainsKey(s.EmployeeAbbr))
{
empDict.Add(s.EmployeeAbbr, s.EmployeeAbbr);
employees.Add(s.EmployeeAbbr);
}
emp = s.EmployeeFullname;
//if (s.IsBillable)
//{
s.Notice4 = "";
s.Notice5 = "";
s.TimeRangeString = "";
if (s.ServiceDescription.Contains("Ausfall"))
{
summeAusfall += s.Minutes;
s.Notice4 = String.Format("{0:0.00}", s.Minutes / 60);
}
else if (s.ServiceDescription.Contains("Wege"))
{
summeWege += s.Minutes;
s.Notice5 = String.Format("{0:0.00}", s.Minutes / 60);
}
else
{
summeFls += s.Minutes;
s.TimeRangeString = String.Format("{0:0.00}", s.Minutes / 60);
}
servicesBillable.Add(s);
String n = s.Notice;
s.Notice = String.Format("{0} ({1})", s.ServiceDescription, s.EmployeeAbbr);
if (!String.IsNullOrWhiteSpace(n))
{
s.Notice = String.Format("{0}, {1}", s.Notice, n);
}
//}
}
pRO.Services = servicesBillable;
}
if (empDict.Count == 1)
{
pRO.MainAttendant = emp;
}
if (empDict.Count == 1)
{
pRO.MainAttendant = emp;
}
else if (employees.Count > 1)
{
pRO.MainAttendant = employees[0];
cellBerater2.Text = employees[1];
}
cellSummeFls.Text = String.Format("{0:0.00}", summeFls / 60);
cellSummeAusfall.Text = String.Format("{0:0.00}", summeAusfall / 60);
cellSummeWegezeit.Text = String.Format("{0:0.00}", summeWege / 60);
cellSummeGesamt.Text = String.Format("Gesamt: {0:0.00}", (summeFls + summeAusfall + summeWege) / 60);
//cellAsdBezirk.Text = pRO.o
cellAsdSachb.Text = "";
if (pRO.CostBearer2SupportConceptList != null && pRO.CostBearer2SupportConceptList.Count > 0)
{
if (pRO.CostBearer2SupportConceptList[0].CostBearerContactPerson != null)
{
String name = "";
if (pRO.CostBearer2SupportConceptList[0].CostBearerContactPerson.Sex.HasValue)
{
if (pRO.CostBearer2SupportConceptList[0].CostBearerContactPerson.Sex.Value == Sex.Male)
{
name = "Herr ";
}
else
{
name = "Frau ";
}
}
cellAsdSachb.Text = name + pRO.CostBearer2SupportConceptList[0].CostBearerContactPerson.LastName;
}
}
var adList = BerechneJugendamtSollIst(pRO);
var gesamt = (summeFls + summeAusfall + summeWege) / 60;
decimal approvedHoursTotal = 0;
decimal usedHoursPreviousMonthsTotal = 0;
decimal approvedHoursInTimeSpan = 0;
decimal remainingHoursTotal = 0;
if (adList.Count > 0)
{
var ad = adList[0];
if (ad.ApprovedHoursTotal != 0)
{
cellBewilligtProWoche1.Text = String.Format("{0:0.00}", ad.ApprovedHoursPerWeek);
cellStdBewZeitraum.Text = String.Format("{0:0.00}", ad.ApprovedHoursInTimeSpan);
cellBewilligtProWoche12.Text = String.Format("{0:0.00}", ad.ApprovedHoursPerWeek);
cellBewilligungStart.Text = String.Format("{0:dd.MM.yyyy}", ad.TotalStartDate);
cellBewilligungEnd.Text = String.Format("{0:dd.MM.yyyy}", ad.TotalEndDate);
cellApprovedTotal1.Text = String.Format("{0:0.00}", ad.ApprovedHoursTotal);
cellStundenVormonat1.Text = String.Format("{0:0.00}", ad.UsedHoursPreviousMonths);
cellRestStunden1.Text = String.Format("{0:0.00}", ad.RemainingHoursTotal);
approvedHoursTotal += ad.ApprovedHoursTotal;
usedHoursPreviousMonthsTotal += ad.UsedHoursPreviousMonths;
approvedHoursInTimeSpan += ad.ApprovedHoursInTimeSpan;
remainingHoursTotal += ad.RemainingHoursTotal;
}
if (adList.Count > 1)
{
ad = adList[1];
if (ad.ApprovedHoursTotal != 0)
{
cellBewilligtProWoche2.Text = String.Format("{0:0.00}", ad.ApprovedHoursPerWeek);
cellBewilligtVon2.Text = String.Format("{0:dd.MM.yyyy}", ad.TimeSpanStartDate);
cellBewilligtBis2.Text = String.Format("{0:dd.MM.yyyy}", ad.TimeSpanEndDate);
cellStdBewZeitraum2.Text = String.Format("{0:0.00}", ad.ApprovedHoursInTimeSpan);
cellBewilligtProWoche22.Text = String.Format("{0:0.00}", ad.ApprovedHoursPerWeek);
cellBewilligungStart2.Text = String.Format("{0:dd.MM.yyyy}", ad.TotalStartDate);
cellBewilligungEnd2.Text = String.Format("{0:dd.MM.yyyy}", ad.TotalEndDate);
cellApprovedTotal2.Text = String.Format("{0:0.00}", ad.ApprovedHoursTotal);
cellStundenVormonat2.Text = String.Format("{0:0.00}", ad.UsedHoursPreviousMonths);
cellRestStunden2.Text = String.Format("{0:0.00}", ad.RemainingHoursTotal);
approvedHoursTotal += ad.ApprovedHoursTotal;
usedHoursPreviousMonthsTotal += ad.UsedHoursPreviousMonths;
approvedHoursInTimeSpan += ad.ApprovedHoursInTimeSpan;
remainingHoursTotal += ad.RemainingHoursTotal;
}
}
}
cellApprovedTotal3.Text = String.Format("{0:0.00}", approvedHoursTotal);
cellStundenVormonat3.Text = String.Format("{0:0.00}", usedHoursPreviousMonthsTotal);
cellStdBewZeitraum3.Text = String.Format("{0:0.00}", approvedHoursInTimeSpan);
cellRestStunden3.Text = String.Format("{0:0.00}", remainingHoursTotal);
cellSummeGesamt.Text = String.Format("Summe {0:0.00}", gesamt);
cellRechnung.Text = String.Format("{0:0.00}", gesamt);
cellVerbleiben.Text = String.Format("{0:0.00}", remainingHoursTotal - (decimal)gesamt);
this.bindingSource1.DataSource = pRO;
}
private List<ServicesOverviewRO.ApprovalDetail> BerechneJugendamtSollIst(ServicesOverviewRO pRO)
{
var adList = new List<ServicesOverviewRO.ApprovalDetail>();
if (pRO.SupportConceptCostBearer != null && pRO.SupportConceptCostBearer.CostBearer2SupportConceptOid != null)
{
if (pRO.SupportConceptCostBearer.StartDate != null)
{
CostBearer2SupportConcept c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pRO.SupportConceptCostBearer.CostBearer2SupportConceptOid.Value);
var calc = PluginLoader.FindClass<Calculations>(c2s.CostBearer.ID) ?? Calculations.GetInstance(c2s.CostBearer.ID);
var endeVormonat = new DateTime(pRO.StartDate.Year, pRO.StartDate.Month, 1).AddDays(-1);
if (c2s.StartDate.HasValue && c2s.StartDate > pRO.StartDate)
{
pRO.StartDate = c2s.StartDate.Value;
}
if (c2s.EndDate.HasValue && c2s.EndDate < pRO.EndDate)
{
pRO.EndDate = c2s.EndDate.Value;
}
IList<ServiceRecord> allServiceRecords = c2s.ServiceRecords;
foreach (var scap in pRO.SupportConceptCostBearer.ApprovalPeriodList)
{
var ad = new ServicesOverviewRO.ApprovalDetail();
adList.Add(ad);
ad.TimeSpanStartDate = pRO.StartDate;
ad.TimeSpanEndDate = pRO.EndDate;
if (scap.StartDate.HasValue)
ad.TotalStartDate = scap.StartDate.Value;
if (scap.EndDate.HasValue)
ad.TotalEndDate = scap.EndDate.Value;
TimeSpan ts = pRO.EndDate.Subtract(ad.TotalStartDate.Value);
ad.ApprovedHoursPerWeek = calc.GetApprovedHoursPerWeek(scap, pRO.SupportConceptCostBearer.CostBearer.CostRatePeriods) ?? 0;
ad.ApprovedHoursInTimeSpan = ad.DaysInTimeSpan * (ad.ApprovedHoursPerWeek / 7m);
ad.ApprovedHoursTotal = ad.DaysTotal * (ad.ApprovedHoursPerWeek / 7m);
decimal minutenIstBisEndeBeleg = 0;
decimal minutenIstVormonat = 0;
DateTime end = pRO.EndDate.Date.AddDays(1);
Dictionary<long, bool> groupBookingDict = new Dictionary<long, bool>();
foreach (var item in allServiceRecords)
{
if (!item.GroupOid.HasValue || !groupBookingDict.ContainsKey(item.GroupOid.Value))
{
if (item.GroupOid.HasValue)
groupBookingDict.Add(item.GroupOid.Value, true);
if (item.Start != null && item.Start >= ad.TotalStartDate)
{
if (item.ServiceDescription != null &&
item.ServiceDescription.ServiceCategory != null &&
item.ServiceDescription.ServiceCategory.IsBillable)
{
if (scap.ServiceCategory == null || scap.ServiceCategory.ServiceCategoryOid == item.ServiceDescription.ServiceCategory.Oid)
if (item.Start.Value < end)
{
var prozent = item.ServiceDescription.ServiceCategory.ProzentAbrechnung;
if (item.ServiceDescription.ProzentAbrechnung.HasValue)
{
prozent = item.ServiceDescription.ProzentAbrechnung.Value;
}
minutenIstBisEndeBeleg += (item.RoundedDuration * prozent) / 100;
if (item.Start.Value < endeVormonat.AddDays(1))
{
minutenIstVormonat += (item.RoundedDuration * prozent) / 100;
}
}
}
}
}
}
ad.UsedHoursPreviousMonths = minutenIstVormonat / 60;
}
}
}
return adList;
}
}
}