Files
BeWoPlaner/ReportImp/SozialeDienstleistungenBeckerReports/RechnungIB.cs

161 lines
6.6 KiB
C#

using BeWo.Report.ReportObjects;
using BS.Shared.Extensions;
using DevExpress.Utils;
using DevExpress.XtraReports.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace BeWo.Report.DefaultReports
{
public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
{
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);
}
if (pRO.CustomerSalutation.IsNullOrEmpty())
{
lblAnrede.Text = "Sehr geehrte Damen und Herren,";
}
if (pRO.InvoiceBase.SupportConceptCostBearerRelDc != null && pRO.InvoiceBase.SupportConceptCostBearerRelDc.ApprovalPeriodList != null)
{
foreach (var item in pRO.InvoiceBase.SupportConceptCostBearerRelDc.ApprovalPeriodList)
{
if (item.StartDate <= pRO.AccountingPeriodEnd && item.EndDate >= pRO.AccountingPeriodStart)
{
lblBereich.Text = item.Notice;
}
}
if (pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson != null)
{
String personname = pRO.RecipientContactPerson;
if (pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson.Geschlecht.HasValue)
{
if (pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson.Geschlecht == BS.Shared.Sex.Female)
{
personname = String.Format("Frau {0}", pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson.LastName);
lblAnrede.Text = String.Format("Sehr geehrte {0},", personname);
}
else if (pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson.Geschlecht == BS.Shared.Sex.Male)
{
personname = String.Format("Herr {0}", pRO.InvoiceBase.SupportConceptCostBearerRelDc.CostBearerContactPerson.LastName);
lblAnrede.Text = String.Format("Sehr geehrte {0},", personname);
}
}
pRO.RecipientContactPerson = personname;
}
}
SetzeAdresse(pRO);
String name = Regex.Replace(String.Format("{0}, {1}", pRO.CustomerLastName, pRO.CustomerFirstName), @"\s*\(.*?\)", "");
pRO.CustomerName = name;
//Mache aus mehreren Periods eine einzelne
if (pRO.ServiceInvoicePeriods.Count > 1)
{
var newList = new List<ServiceInvoicePeriodRO>();
foreach (var sip in pRO.ServiceInvoicePeriods)
{
if (newList.Count == 0)
{
newList.Add(sip);
}
else
{
foreach (var item in sip.ServiceInvoiceItems)
{
var first = newList[0];
var olditem = first.ServiceInvoiceItems.FirstOrDefault(s => s.ServiceDescription == item.ServiceDescription);
if (olditem != null)
{
olditem.Hours = (olditem.Hours ?? 0) + (item.Hours ?? 0);
olditem.UnitCount = (olditem.UnitCount ?? 0) + (item.UnitCount ?? 0);
olditem.NetAmount = (olditem.NetAmount ?? 0) + (item.NetAmount ?? 0);
olditem.GrossAmount = string.Format("{0:c}", olditem.NetAmount);
//olditem.UnitCount = (olditem.UnitCount ?? 0) + (item.UnitCount ?? 0);
}
else
{
first.ServiceInvoiceItems.Add(item);
}
}
}
}
pRO.ServiceInvoicePeriods = newList;
}
foreach (var sip in pRO.ServiceInvoicePeriods)
{
foreach (var item in sip.ServiceInvoiceItems)
{
if (sip.ServiceInvoiceItems.Count == 1)
{
item.ServiceDescription = String.Format("{0} (geb. {1:dd.MM.yyyy})", name, pRO.CustomerBirthdate);
}
}
}
this.bindingSource1.DataSource = pRO;
}
private void SetzeAdresse(ServiceInvoiceRO pRO)
{
StringBuilder sb = new StringBuilder();
if (!String.IsNullOrEmpty(pRO.RecipientDivision) && !String.IsNullOrEmpty(pRO.RecipientOrganisation) && pRO.RecipientOrganisation.ToLower().Trim() != "selbstzahler")
{
sb.AppendLine(pRO.RecipientDivision);
}
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) && pRO.RecipientOrganisation.ToLower().Trim() != "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.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();
}
}
}