141 lines
4.9 KiB
C#
141 lines
4.9 KiB
C#
using System;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BS.Shared;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace AwoWesel
|
|
{
|
|
public partial class ServiceInvoiceReport : XtraReport, IBeWoReport<ServiceInvoiceRO>
|
|
{
|
|
public ServiceInvoiceReport()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(ServiceInvoiceRO pRO)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
|
|
{
|
|
sb.AppendLine(pRO.RecipientOrganisation);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientContactPerson))
|
|
{
|
|
sb.AppendLine(pRO.RecipientContactPerson);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientDivision))
|
|
{
|
|
sb.AppendLine(pRO.RecipientDivision);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientStreet))
|
|
{
|
|
sb.AppendLine(pRO.RecipientStreet);
|
|
}
|
|
if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown))
|
|
{
|
|
sb.AppendLine(pRO.RecipientPostCodeAndTown);
|
|
}
|
|
lblAdresse.Text = sb.ToString();
|
|
|
|
|
|
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.ServiceInvoicePeriods != null)
|
|
{
|
|
foreach (var sip in pRO.ServiceInvoicePeriods)
|
|
{
|
|
if (sip.ServiceInvoiceItems != null)
|
|
{
|
|
foreach (var ii in sip.ServiceInvoiceItems)
|
|
{
|
|
ii.ServiceDescription = "Fachleistungsstunden";
|
|
SetzeZeitraum(pRO, sip);
|
|
|
|
if (!String.IsNullOrEmpty(ii.RateFactor))
|
|
{
|
|
var rfStr = ii.RateFactor.Replace("%", "").Replace(",00", "").Trim();
|
|
int rfInt = 0;
|
|
Int32.TryParse(rfStr, out rfInt);
|
|
|
|
decimal rateFactor = (100m + rfInt) / 100m;
|
|
|
|
ii.RateFactor = String.Format("{0:0.##}", rateFactor);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private void SetzeZeitraum(ServiceInvoiceRO pRo, ServiceInvoicePeriodRO sip)
|
|
{
|
|
var periods = sip.CostBearer2SupportConcept.CostBearer.CostRatePeriods;
|
|
|
|
var crDcList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(periods);
|
|
|
|
DateTime start = pRo.AccountingPeriodStart;
|
|
DateTime end = pRo.AccountingPeriodEnd;
|
|
|
|
var ratesInSpan = crDcList.GetRatesInSpan(CostRatePeriodType.HourlyRate, start, end);
|
|
|
|
DateTime nextCrStart = start;
|
|
foreach (var cr in ratesInSpan)
|
|
{
|
|
cr.StartDate = nextCrStart;
|
|
|
|
if (cr.EndDate.HasValue)
|
|
{
|
|
nextCrStart = cr.EndDate.Value.AddDays(1);
|
|
}
|
|
}
|
|
|
|
foreach (var ii in sip.ServiceInvoiceItems)
|
|
{
|
|
start = ii.AccountingPeriodStart ?? pRo.AccountingPeriodStart;
|
|
end = ii.AccountingPeriodEnd ?? pRo.AccountingPeriodEnd;
|
|
|
|
CostRatePeriodDC foundDc = null;
|
|
foreach (var cr in ratesInSpan)
|
|
{
|
|
if (cr.CostRateType == CostRatePeriodType.HourlyRate && cr.CostRateValue == ii.HourlyRate)
|
|
{
|
|
foundDc = cr;
|
|
}
|
|
}
|
|
|
|
if (foundDc != null)
|
|
{
|
|
if (foundDc.EndDate.HasValue && foundDc.EndDate < end && foundDc.EndDate.Value >= start)
|
|
{
|
|
end = foundDc.EndDate.Value;
|
|
}
|
|
|
|
if (foundDc.StartDate.HasValue && foundDc.StartDate > start && foundDc.StartDate.Value <= end)
|
|
{
|
|
start = foundDc.StartDate.Value;
|
|
}
|
|
ii.Duration = String.Format("{0:dd.MM.yy} - {1:dd.MM.yy}", start, end);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
} |