Files
BeWoPlaner/ReportImp/HshCologne/ServiceInvoiceReport.cs

259 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Report;
using BeWo.Report.ReportObjects;
using BS.Shared;
using BS.Shared.Extensions;
using DevExpress.XtraReports.UI;
namespace HshCologne
{
public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
{
public List<ServiceInvoicePeriodRO> aggregiert { get; set; }
public ServiceInvoiceReport()
{
this.InitializeComponent();
}
public void SetReportDataSource(ServiceInvoiceRO pRO)
{
DateTime start = pRO.AccountingPeriodStart;
DateTime end = pRO.AccountingPeriodEnd;
SetzeAdresse(pRO);
if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
{
var c = DAOFactory.GenericDAO.LoadByID<Customer>(pRO.ServiceInvoicePeriods[0].Customer.Oid.Value);
if (c != null)
{
pRO.CustomerCostCenter = GetSozialarbeiter(pRO, c);
GetBetreuungsart(pRO, c);
var hauptbetreuer = c.Employee2CustomerList.FirstOrDefault(
e2c => e2c.ValueList.Any(ve => ve.Entry.SystemEntryID.HasValue
&& ve.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant));
if (hauptbetreuer != null && hauptbetreuer.Employee.Person != null)
{
lblHauptbetreuung.Text = hauptbetreuer.Employee.Person.FirstNameLastName;
}
}
aggregiert = new List<ServiceInvoicePeriodRO>();
foreach (var sip in pRO.ServiceInvoicePeriods)
{
var copySip = new ServiceInvoicePeriodRO();
CopyServiceInvoicePeriod(sip, copySip);
aggregiert.Add(copySip);
}
ServiceInvoiceRO flsRO;
flsRO = new ServiceInvoiceRO
{
InvoiceBase = pRO.InvoiceBase,
RecipientOrganisation = pRO.RecipientOrganisation,
ServiceInvoicePeriods = aggregiert
};
ServiceInvoiceReportFLS subReport = xrSubreport1.ReportSource as ServiceInvoiceReportFLS;
if (subReport != null)
subReport.SetReportDataSource(flsRO);
// Daten für Bewilligungsumfang setzen
string periode = "";
var sipMitFLS = pRO.ServiceInvoicePeriods.Where(sip => sip.SupportConceptApprovalPeriod?.ApprovedBEPerInterval is decimal value && value != 0m).ToList();
if (sipMitFLS != null && sipMitFLS.Count > 0 && sipMitFLS.Count == 1) //sollte der Standard sein, dass es nur eine aktuelle Bewilligung gibt
{
periode = GetIntervalType(sipMitFLS[0].SupportConceptApprovalPeriod.ApprovedBEInterval);
lblHeaderBewilligung.Text += "/ " + periode;
lblBewilligung.Text = sipMitFLS[0].SupportConceptApprovalPeriod.ApprovedBEPerInterval.Value.ToString("n2");
}
else if (sipMitFLS != null && sipMitFLS.Count > 1) //wenn mehr als eine Bewilligung, können Bewilligungsintervalle unterschiedlich sein
{
string anteil = "";
string fls = "";
bool periodenWechsel = false; // falls die Bewilligungsintervalle unterschiedlich sind, wird das Interval nicht in Überschrift ausgewiesen
foreach (var sip in sipMitFLS)
{
anteil = GetIntervalType(sip.SupportConceptApprovalPeriod.ApprovedBEInterval);
decimal bew = sip.SupportConceptApprovalPeriod.ApprovedBEPerInterval.Value;
if (periode == "")
{
periode = anteil;
}
else if (!periode.Contains(anteil) && !periodenWechsel) // eine weitere Bewilligung
{
periodenWechsel = true;
fls += "/" + periode + "\n" + bew.ToString("n2") + "/" + anteil;
}
else if (periodenWechsel) // noch mehr Bewilligungen
{
fls += "\n" + bew.ToString("n2") + "/" + anteil;
}
if (fls == "")
{
fls = bew.ToString("n2");
}
else if (!periodenWechsel)
{
fls += "\n" + bew.ToString("n2");
}
}
if (!periodenWechsel)
{
lblHeaderBewilligung.Text += "/" + periode;
}
lblBewilligung.Text = fls;
}
if (pRO.ServiceInvoicePeriods.All(sip => sip.ServiceInvoiceItems != null))
{
// Zweite Tabelle enthält alle bewilligten Leistungskategorien + Zeiterfassung in Fachkraft + Assistenz unterteilt
pRO.ServiceInvoicePeriods = pRO.ServiceInvoicePeriods.Select(sip => new ServiceInvoicePeriodRO
{
Notice = sip.Notice,
ApprovalPeriod = sip.ApprovalPeriod,
Customer = sip.Customer,
CostBearer2SupportConcept = sip.CostBearer2SupportConcept,
Claim = sip.Claim,
ServiceInvoiceItems = sip.ServiceInvoiceItems
.GroupBy(p => new { p.HourlyRate})
.Select(g => new ServiceInvoiceItemRO
{
UnitDescription = g.First().UnitDescription,
HourlyRate = g.Key.HourlyRate,
UnitCount = g.Sum(p => p.Hours),
NetAmount = g.Sum(p => p.NetAmount)
}).ToList()
}).ToList();
}
}
this.bindingSource1.DataSource = pRO;
}
private string GetIntervalType(SupportConceptApprovalInterval? interval)
{
string periode = "";
switch (interval)
{
case BS.Shared.SupportConceptApprovalInterval.Daily: periode = "Tag"; break;
case BS.Shared.SupportConceptApprovalInterval.Weekly: periode = "Woche"; break;
case BS.Shared.SupportConceptApprovalInterval.Monthly: periode = "Monat"; break;
case BS.Shared.SupportConceptApprovalInterval.HalfYearly: periode = "Halbjahr"; break;
case BS.Shared.SupportConceptApprovalInterval.Yearly: periode = "Jahr"; break;
case BS.Shared.SupportConceptApprovalInterval.Fortnightly: periode = "Pauschal"; break;
}
return periode;
}
private void CopyServiceInvoicePeriod(ServiceInvoicePeriodRO existingSip, ServiceInvoicePeriodRO copySip)
{
copySip.ApprovalPeriod = existingSip.ApprovalPeriod;
copySip.Claim = existingSip.Claim;
copySip.ApprovedHours = existingSip.ApprovedHours;
copySip.Claim = existingSip.Claim;
copySip.Notice = existingSip.Notice;
copySip.Customer = existingSip.Customer;
copySip.SupportConceptApprovalPeriod = existingSip.SupportConceptApprovalPeriod;
copySip.ServiceInvoiceItems = new List<ServiceInvoiceItemRO>();
foreach (var ii in existingSip.ServiceInvoiceItems)
{
var copyItem = new ServiceInvoiceItemRO();
CopyInvoiceItem(ii, copyItem);
copySip.ServiceInvoiceItems.Add(copyItem);
}
}
public void CopyInvoiceItem(ServiceInvoiceItemRO existingItem, ServiceInvoiceItemRO copyItem)
{
copyItem.AccountingPeriodEnd = existingItem.AccountingPeriodEnd;
copyItem.AccountingPeriodStart = existingItem.AccountingPeriodStart;
copyItem.AmountPerUnit = existingItem.AmountPerUnit;
copyItem.NetAmount = existingItem.NetAmount;
copyItem.RateFactor = existingItem.RateFactor;
copyItem.UnitDescription = existingItem.UnitDescription;
copyItem.UnitCount = existingItem.UnitCount;
copyItem.Hours = existingItem.Hours;
copyItem.ServiceDescription = existingItem.ServiceDescription;
copyItem.Duration = existingItem.Duration;
copyItem.ServiceRecord = existingItem.ServiceRecord;
copyItem.Notice = existingItem.Notice;
}
public void GetBetreuungsart(ServiceInvoiceRO pRO, Customer c)
{
var betreuungsarten = c.ValueList.Where(v2o => v2o.Entry.Type == ValueListEntryType.CustomerCareType).ToList();
if (betreuungsarten != null && betreuungsarten.Count > 0)
{
if (betreuungsarten.Count >= 1)
pRO.CustomerInsuranceNumber = "(" + betreuungsarten[0].Entry.Value;
if (betreuungsarten.Count >= 2)
pRO.CustomerInsuranceNumber += " / " + betreuungsarten[1].Entry.Value;
pRO.CustomerInsuranceNumber += ")";
}
}
private string GetSozialarbeiter(ServiceInvoiceRO pRO, Customer c)
{
string asd = "";
{
foreach (var c2p in c.Customer2PersonList)
{
foreach (var v2o in c2p.ValueList)
{
if (v2o.Entry.Type == ValueListEntryType.EnvironmentPersonType && v2o.Entry.Value.Contains("Zuständiger ASD"))
{
if (asd != "")
{
asd += ", ";
}
asd += c2p.Person.LastName;
}
}
}
}
return asd;
}
private void SetzeAdresse(ServiceInvoiceRO pRO)
{
StringBuilder sb = new StringBuilder();
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) && pRO.RecipientOrganisation.ToLower() != "selbstzahler")
{
sb.AppendLine(pRO.RecipientOrganisation);
}
if (!String.IsNullOrEmpty(pRO.RecipientAddressLine1))
{
sb.AppendLine(pRO.RecipientAddressLine1);
}
if (!String.IsNullOrEmpty(pRO.RecipientContactPerson) && !String.IsNullOrEmpty(pRO.RecipientOrganisation) && pRO.RecipientOrganisation.ToLower().Contains("köln"))
{
sb.AppendLine(pRO.RecipientContactPerson);
}
// Ist bei denen mit internen Angaben befüllt
//if (!String.IsNullOrEmpty(pRO.RecipientDivision) && !String.IsNullOrEmpty(pRO.RecipientOrganisation) && pRO.RecipientOrganisation.ToLower() != "selbstzahler")
//{
// sb.AppendLine(pRO.RecipientDivision);
//}
if (!String.IsNullOrEmpty(pRO.RecipientPoBox))
{
sb.AppendLine(pRO.RecipientPoBox);
}
else if (!String.IsNullOrEmpty(pRO.RecipientStreet))
{
sb.AppendLine(pRO.RecipientStreet);
}
if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown))
{
sb.AppendLine(pRO.RecipientPostCodeAndTown);
}
lblAdresse.Text = sb.ToString();
}
}
}