Files
BeWoPlaner/ReportImp/HshCologne/ServiceInvoiceReport.cs

204 lines
8.8 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;
//if (start.Month == end.Month && start.Year == end.Year)
//{
// lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Monat {0:MMMM yyyy} folgende erbrachte Tätigkeiten:", start);
//}
//else
//{
// lblAbrechnungszeitraum.Text = String.Format("hiermit berechnen wir für den Zeitraum {0:MMMM yyyy} - {1:MMMM yyyy} folgende erbrachte Tätigkeiten:", start, end);
//}
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);
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 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();
}
}
}