179 lines
6.5 KiB
C#
179 lines
6.5 KiB
C#
using System;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BS.Shared;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace DomizielAnsbach
|
|
{
|
|
public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
|
|
{
|
|
public ServiceInvoiceReport()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(ServiceInvoiceRO pRO)
|
|
{
|
|
var sb = new StringBuilder();
|
|
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
|
|
{
|
|
sb.AppendLine(pRO.RecipientOrganisation);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientAddressLine1))
|
|
{
|
|
sb.AppendLine(pRO.RecipientAddressLine1);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientDivision))
|
|
{
|
|
sb.AppendLine(pRO.RecipientDivision);
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(pRO.RecipientContactPerson) && pRO.RecipientContactPerson != pRO.RecipientOrganisation)
|
|
{
|
|
SetzeAnredeAdresse(pRO);
|
|
sb.AppendLine(pRO.RecipientContactPerson);
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(pRO.RecipientStreet))
|
|
{
|
|
sb.AppendLine(pRO.RecipientStreet);
|
|
}
|
|
|
|
if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown))
|
|
{
|
|
sb.AppendLine(pRO.RecipientPostCodeAndTown);
|
|
}
|
|
|
|
lblAdresse.Text = sb.ToString();
|
|
pRO.CreatorDivision = null;
|
|
var count = 0;
|
|
string ende = "";
|
|
|
|
foreach (var sip in pRO.ServiceInvoicePeriods)
|
|
{
|
|
foreach (var i in sip.ServiceInvoiceItems)
|
|
{
|
|
if (i.ServiceDescription.ToLower().Contains("miete"))
|
|
{
|
|
count += 1;
|
|
if (i.AccountingPeriodEnd < pRO.AccountingPeriodEnd)
|
|
ende = String.Format(" Die Maßnahme wurde zum {0:dd.MM.yyyy} beendet.", i.AccountingPeriodEnd);
|
|
pRO.CreatorDivision = GetAbwesenheiten(sip, pRO.AccountingPeriodStart, pRO.AccountingPeriodEnd);
|
|
}
|
|
else if (i.ServiceDescription.ToLower().Contains("stationär") || i.ServiceDescription.ToLower().Contains("platzfreihalte"))
|
|
pRO.CreatorDivision = GetAbwesenheiten(sip, pRO.AccountingPeriodStart, pRO.AccountingPeriodEnd);
|
|
}
|
|
}
|
|
if (count == 1 && ende != "")
|
|
pRO.CreatorDivision += ende;
|
|
|
|
if (String.IsNullOrEmpty(pRO.Notice) && (String.IsNullOrEmpty(pRO.CreatorDivision)))
|
|
{
|
|
lblNotice.Visible = false;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
SetzeAnrede(pRO);
|
|
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private string GetAbwesenheiten(ServiceInvoicePeriodRO sip, DateTime start, DateTime end)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
var c = DAOFactory.GenericDAO.LoadByID<Customer>(sip.Customer.Oid.Value);
|
|
|
|
if (c.AbsenceTimes != null)
|
|
{
|
|
foreach (var at in c.AbsenceTimes)
|
|
{
|
|
if ((!at.Start.HasValue || at.Start.Value <= end) && (!at.End.HasValue || at.End.Value >= start)
|
|
&& !at.AbsenceReason.Description.Contains("ZV") && !at.AbsenceReason.Description.Contains("Urlaub stationär im Haus"))
|
|
{
|
|
if (sb.Length > 0)
|
|
{
|
|
sb.Append(", ");
|
|
}
|
|
|
|
sb.Append(String.Format("{0:dd.MM.}", at.Start));
|
|
if (!at.End.HasValue || at.End.Value > at.Start)
|
|
{
|
|
sb.Append(" bis ");
|
|
if (at.End.HasValue)
|
|
{
|
|
sb.Append(String.Format("{0:dd.MM.}", at.End));
|
|
}
|
|
else
|
|
{
|
|
sb.Append("unbekannt");
|
|
}
|
|
}
|
|
sb.Append(": " + at.AbsenceReason.Description);
|
|
}
|
|
}
|
|
}
|
|
return sb.ToString();
|
|
}
|
|
|
|
private void SetzeAnrede(ServiceInvoiceRO pRO)
|
|
{
|
|
String anrede = "Sehr geehrte Damen und Herren,";
|
|
var p = GetKontaktPerson(pRO);
|
|
|
|
if (p != null)
|
|
{
|
|
if (p.Sex.HasValue && p.Sex.Value == Sex.Male)
|
|
{
|
|
anrede = "Sehr geehrter Herr " + p.LastName + ",";
|
|
}
|
|
else if (p.Sex.HasValue && p.Sex.Value == Sex.Female)
|
|
{
|
|
anrede = "Sehr geehrte Frau " + p.LastName + ",";
|
|
}
|
|
}
|
|
|
|
lblAnrede.Text = anrede;
|
|
}
|
|
|
|
private Person GetKontaktPerson(ServiceInvoiceRO pRO)
|
|
{
|
|
if (pRO.ServiceInvoicePeriods.Count > 0 && !pRO.ServiceInvoicePeriods[0].ServiceInvoiceItems[0].ServiceDescription.StartsWith("Rechnungsdifferenz"))
|
|
{
|
|
var c2s = pRO.ServiceInvoicePeriods[0].CostBearer2SupportConcept;
|
|
return c2s.CostBearerContactPerson;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void SetzeAnredeAdresse(ServiceInvoiceRO pRO)
|
|
{
|
|
var p = GetKontaktPerson(pRO);
|
|
|
|
if (p != null)
|
|
{
|
|
if (p.Sex.HasValue && p.Sex.Value == Sex.Male)
|
|
{
|
|
pRO.RecipientContactPerson = "Herr " + pRO.RecipientContactPerson;
|
|
}
|
|
else if (p.Sex.HasValue && p.Sex.Value == Sex.Female)
|
|
{
|
|
pRO.RecipientContactPerson = "Frau " + pRO.RecipientContactPerson;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |