268 lines
12 KiB
C#
268 lines
12 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.ReportObjects;
|
|
using BeWo.Report;
|
|
using BS.Shared.DataContracts;
|
|
using DevExpress.XtraReports.UI;
|
|
|
|
namespace Lori.Alt
|
|
{
|
|
public partial class Spitzabrechnung : DevExpress.XtraReports.UI.XtraReport//, IBeWoReport<SettlementRO>
|
|
{
|
|
public Spitzabrechnung()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(SettlementRO pRO)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
|
|
{
|
|
sb.AppendLine(pRO.RecipientOrganisation);
|
|
}
|
|
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();
|
|
|
|
xrCheckBox2.Checked = true;
|
|
DateTime? terminationDate = null;
|
|
|
|
if (pRO.CostBearer2SupportConceptOid > 0)
|
|
{
|
|
var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pRO.CostBearer2SupportConceptOid);
|
|
|
|
if (c2s.SupportConcept.Customer.TerminationDate.HasValue)
|
|
{
|
|
terminationDate = c2s.SupportConcept.Customer.TerminationDate;
|
|
xrCheckBox1.Text = String.Format(" Die Betreuung wurde am {0:dd.MM.yyyy} beendet.",
|
|
c2s.SupportConcept.Customer.TerminationDate);
|
|
xrCheckBox2.Checked = false;
|
|
xrCheckBox1.Checked = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ErstelleRechnungspositionen(pRO, terminationDate);
|
|
|
|
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) &&
|
|
!pRO.RecipientOrganisation.ToLower().Contains("lwl"))
|
|
{
|
|
lblAktenzeichen.Text = String.Format("Aktenzeichen: {0}", pRO.CustomerReferenceNumber);
|
|
lblFussnote.Visible = false;
|
|
xrLineFussnote.Visible = false;
|
|
}
|
|
|
|
|
|
ortDatum.Text = string.Format("{0}", DateTime.Now.ToShortDateString());
|
|
|
|
bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private void ErstelleRechnungspositionen(SettlementRO pRO, DateTime? terminationDate)
|
|
{
|
|
bool createStandardPostition = pRO.InvoiceItems == null || pRO.InvoiceItems.Count == 0;
|
|
|
|
|
|
if (!createStandardPostition && pRO.InvoiceItems.Count == 1)
|
|
{
|
|
if (pRO.InvoiceItems[0].ItemDescription == "Spitzabrechnung" && (pRO.InvoiceItems[0].UnitCount == null || pRO.InvoiceItems[0].UnitCount.Value == 0))
|
|
{
|
|
createStandardPostition = true;
|
|
}
|
|
}
|
|
|
|
if (!createStandardPostition)
|
|
{
|
|
CheckStartEnd(pRO.InvoiceItems);
|
|
|
|
if (terminationDate.HasValue)
|
|
{
|
|
if (terminationDate < pRO.InvoiceItems[pRO.InvoiceItems.Count - 1].ItemPeriodEnd)
|
|
{
|
|
pRO.InvoiceItems[pRO.InvoiceItems.Count - 1].ItemPeriodEnd = terminationDate;
|
|
}
|
|
}
|
|
if (pRO.InvoiceItems.Count == 3)
|
|
{
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[0], cellStart1, cellEnd1, cellHourlyRate1, cellFLS1);
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[1], cellStart2, cellEnd2, cellHourlyRate2, cellFLS2);
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[2], cellStart3, cellEnd3, cellHourlyRate3, cellFLS3);
|
|
}
|
|
else if (pRO.InvoiceItems.Count == 2)
|
|
{
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[0], cellStart1, cellEnd1, cellHourlyRate1, cellFLS1);
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[1], cellStart2, cellEnd2, cellHourlyRate2, cellFLS2);
|
|
}
|
|
else
|
|
{
|
|
SetzeRechnungsTexte(pRO.InvoiceItems[0], cellStart1, cellEnd1, cellHourlyRate1, cellFLS1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ErstelleStandardRechnungspositionen(pRO, terminationDate);
|
|
}
|
|
}
|
|
|
|
private void CheckStartEnd(IList<InvoiceItemDC> items)
|
|
{
|
|
var sortedList = items.OrderByDescending(i => i.ItemPeriodStart);
|
|
|
|
DateTime? lastStart = null;
|
|
foreach (var ii in sortedList)
|
|
{
|
|
if (lastStart.HasValue)
|
|
{
|
|
DateTime newStart = lastStart.Value.AddDays(-1);
|
|
if (ii.ItemPeriodEnd.HasValue && ii.ItemPeriodStart.HasValue && newStart < ii.ItemPeriodEnd &&
|
|
newStart > ii.ItemPeriodStart)
|
|
{
|
|
ii.ItemPeriodEnd = newStart;
|
|
}
|
|
}
|
|
|
|
lastStart = ii.ItemPeriodStart;
|
|
}
|
|
}
|
|
|
|
private void SetzeRechnungsTexte(InvoiceItemDC ii, XRTableCell cellStart, XRTableCell cellEnd, XRTableCell cellHourlyRate, XRTableCell cellFLS)
|
|
{
|
|
cellStart.Text = String.Format("{0:dd.MM.yyyy}", ii.ItemPeriodStart);
|
|
cellEnd.Text = String.Format("{0:dd.MM.yyyy}", ii.ItemPeriodEnd);
|
|
cellHourlyRate.Text = String.Format("{0:c}", ii.AmountPerUnit);
|
|
cellFLS.Text = String.Format("{0:0.00}", ii.UnitCount);
|
|
}
|
|
|
|
private void ErstelleStandardRechnungspositionen(SettlementRO pRO, DateTime? terminationDate)
|
|
{
|
|
|
|
pRO.AccountingEndDateString = CorrectPossibleTerminationEndDate(pRO.AccountingEndDateString, terminationDate);
|
|
|
|
if (pRO.DifferentHourlyRateCount == 3)
|
|
{
|
|
//Erbrachte Leistungen (FLS) - bis [HourlyRateOldEndDateString] à [HourlyRateOldString] €
|
|
|
|
pRO.Abrechnungstext1 = String.Format("{0} bis {1}",
|
|
pRO.AccountingStartDateString, pRO.HourlyRate3EndDateString);
|
|
|
|
pRO.Abrechnungstext1 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatz3, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRate3);
|
|
|
|
//[AccountingStartDateString] - [HourlyRate3EndDateString] sind [RecordedFLSWithHourlyRate3String] Std. x [HourlyRate3String] € =";
|
|
|
|
pRO.Betrag1 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatz3 * (decimal)pRO.RateFactor * pRO.HourlyRate3);
|
|
|
|
|
|
pRO.Abrechnungstext2 = String.Format("{0} bis {1}",
|
|
pRO.HourlyRateOldStartDateString, pRO.HourlyRateOldEndDateString);
|
|
pRO.Abrechnungstext2 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatzAlt, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateOld);
|
|
|
|
pRO.Betrag2 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAlt * (decimal)pRO.RateFactor * pRO.HourlyRateOld);
|
|
|
|
|
|
pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
|
|
pRO.HourlyRateNewStartDateString, pRO.AccountingEndDateString);
|
|
pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);
|
|
|
|
pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);
|
|
|
|
|
|
|
|
cellStart1.Text = pRO.AccountingStartDateString;
|
|
cellEnd1.Text = pRO.HourlyRate3EndDateString;
|
|
cellHourlyRate1.Text = pRO.HourlyRate3String;
|
|
cellFLS1.Text = pRO.RecordedFLSWithHourlyRate3String;
|
|
|
|
cellStart2.Text = pRO.HourlyRateOldStartDateString;
|
|
cellEnd2.Text = pRO.HourlyRateOldEndDateString;
|
|
cellHourlyRate2.Text = pRO.HourlyRateOldString;
|
|
cellFLS2.Text = pRO.RecordedFLSWithOldHourlyRateString;
|
|
|
|
cellStart3.Text = pRO.HourlyRateNewStartDateString;
|
|
cellEnd3.Text = pRO.AccountingEndDateString;
|
|
cellHourlyRate3.Text = pRO.HourlyRateNewString;
|
|
cellFLS3.Text = pRO.RecordedFLSWithNewHourlyRateString;
|
|
}
|
|
else if (pRO.DifferentHourlyRateCount == 2)
|
|
{
|
|
|
|
pRO.Abrechnungstext2 = String.Format("{0} bis {1}",
|
|
pRO.AccountingStartDateString, pRO.HourlyRateOldEndDateString);
|
|
pRO.Abrechnungstext2 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatzAlt, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateOld);
|
|
|
|
pRO.Betrag2 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAlt * (decimal)pRO.RateFactor * pRO.HourlyRateOld);
|
|
|
|
|
|
pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
|
|
pRO.HourlyRateNewStartDateString, pRO.AccountingEndDateString);
|
|
pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);
|
|
|
|
pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);
|
|
|
|
|
|
cellStart1.Text = pRO.AccountingStartDateString;
|
|
cellEnd1.Text = pRO.HourlyRateOldEndDateString;
|
|
cellHourlyRate1.Text = pRO.HourlyRateOldString;
|
|
cellFLS1.Text = pRO.RecordedFLSWithOldHourlyRateString;
|
|
|
|
cellStart2.Text = pRO.HourlyRateNewStartDateString;
|
|
cellEnd2.Text = pRO.AccountingEndDateString;
|
|
cellHourlyRate2.Text = pRO.HourlyRateNewString;
|
|
cellFLS2.Text = pRO.RecordedFLSWithNewHourlyRateString;
|
|
}
|
|
else
|
|
{
|
|
cellStart1.Text = pRO.AccountingStartDateString;
|
|
cellEnd1.Text = pRO.AccountingEndDateString;
|
|
cellHourlyRate1.Text = pRO.HourlyRateNewString;
|
|
cellFLS1.Text = pRO.RecordedFLSWithNewHourlyRateString;
|
|
|
|
pRO.Abrechnungstext3 = String.Format("{0} bis {1}",
|
|
pRO.AccountingStartDateString, pRO.AccountingEndDateString);
|
|
pRO.Abrechnungstext3 += String.Format(": {0:0.##} FLS {1}x {2:c}",
|
|
pRO.GeleisteteFLSMitStundensatzAktuell, pRO.RateFactor == 1 ? "" : "x " + pRO.RateFactorText2 + " ", pRO.HourlyRateNew);
|
|
|
|
pRO.Betrag3 = String.Format("{0:c}", pRO.GeleisteteFLSMitStundensatzAktuell * (decimal)pRO.RateFactor * pRO.HourlyRateNew);
|
|
}
|
|
}
|
|
|
|
private string CorrectPossibleTerminationEndDate(string dateString, DateTime? terminationDate)
|
|
{
|
|
if (terminationDate.HasValue)
|
|
{
|
|
DateTime dt = DateTime.MinValue;
|
|
if (DateTime.TryParse(dateString, out dt))
|
|
{
|
|
if (terminationDate < dt)
|
|
{
|
|
return String.Format("{0:dd.MM.yyyy}", terminationDate);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return dateString;
|
|
}
|
|
}
|
|
}
|