198 lines
8.4 KiB
C#
198 lines
8.4 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 FenixSozialeDienste
|
|
{
|
|
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);
|
|
GetBetreuung(pRO, c);
|
|
pRO.CustomerCostCenter = GetSozialarbeiter(pRO, c);
|
|
|
|
// Um den Subreport zu bauen müssen die ServiceInvoicePeriods und InvoiceItems dupliziert werden, da dort die km nicht dargestellt werden solln
|
|
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);
|
|
|
|
// Zweite Tabelle enthält alle bewilligten Leistungskategorien + Zeiterfassung in Fachkraft + Assistenz unterteilt
|
|
if (pRO.ServiceInvoicePeriods.All(sip => sip.ServiceInvoiceItems != null))
|
|
{
|
|
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;
|
|
}
|
|
|
|
public 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;
|
|
}
|
|
|
|
public void GetBetreuung(ServiceInvoiceRO pRO, Customer c)
|
|
{
|
|
|
|
var betreuendePersonen = c.Employee2CustomerList.Where(
|
|
e2c => e2c.ValueList.Any(ve => ve.Entry.Value != null && ve.Entry.Value != "Verwaltung" ||
|
|
ve.Entry.SystemEntryID.HasValue && ve.Entry.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant)).ToList();
|
|
|
|
if (betreuendePersonen != null && betreuendePersonen.Count > 0)
|
|
{
|
|
lblBetreuungskraft.Text = betreuendePersonen[0].Employee.Person.FirstNameLastName;
|
|
|
|
for (int i = 1; i < betreuendePersonen.Count; i++)
|
|
{
|
|
lblBetreuungskraft.Text += " / " + betreuendePersonen[i].Employee.Person.FirstNameLastName;
|
|
}
|
|
}
|
|
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;
|
|
}
|
|
}
|
|
|
|
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("ASD"))
|
|
{
|
|
if (asd != "")
|
|
{
|
|
asd += ", ";
|
|
}
|
|
asd += c2p.Person.FirstNameLastName;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
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))
|
|
{
|
|
sb.AppendLine(pRO.RecipientContactPerson);
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
} |