Files
BeWoPlaner/ReportImp/CaritasAhlen/SettlementReportStadtOsnabrueck.cs
2020-08-17 15:50:00 +02:00

316 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.Core;
using BS.Shared.DataContracts;
using DevExpress.XtraReports.UI;
namespace CaritasAhlen
{
[IDSpecificClass(Identifier = "StadtOsnabrueck")]
public partial class SettlementReportStadtOsnabrueck : DevExpress.XtraReports.UI.XtraReport, IBeWoReport<SettlementRO>
{
public SettlementReportStadtOsnabrueck()
{
InitializeComponent();
}
public void SetReportDataSource(SettlementRO pRO)
{
if (!String.IsNullOrEmpty(pRO.SenderContactPersonPhone))
{
pRO.SenderContactPersonPhone = pRO.SenderContactPersonPhone.Replace("Tel.:", "").Trim();
}
if (!String.IsNullOrEmpty(pRO.SenderContactPersonFax))
{
pRO.SenderContactPersonFax = pRO.SenderContactPersonFax.Replace("Fax:", "").Trim();
}
if (!String.IsNullOrEmpty(pRO.SenderContactPersonMail))
{
pRO.SenderContactPersonMail = pRO.SenderContactPersonMail.Replace("E-Mail:", "").Trim();
}
SetzeAdresse(pRO);
PruefeRechnungspositionen(pRO);
//ErstelleRechnungspositionen(pRO);
ErstelleAbwesenheitenTabelle(pRO);
bindingSource1.DataSource = pRO;
}
private void ErstelleAbwesenheitenTabelle(SettlementRO pRo)
{
bool hasAbsenceTimes = false;
Customer c = null;
if (pRo.CostBearer2SupportConceptOid > 0)
{
var c2s = DAOFactory.GenericDAO.LoadByID<CostBearer2SupportConcept>(pRo.CostBearer2SupportConceptOid);
c = c2s.SupportConcept.Customer;
}
if (c != null && c.AbsenceTimes != null)
{
int newRows = 0;
int index = 1;
foreach (var at in c.AbsenceTimes.OrderBy(a => a.Start))
{
bool cont = true;
if (at.Start != null && at.Start > pRo.AccountingEndDate)
{
cont = false;
}
if (cont && at.End != null && at.End < pRo.AccountingStartDate)
{
cont = false;
}
if (at.AbsenceReason.Description.ToLower().Contains("urlaub"))
{
cont = false;
}
if (cont)
{
hasAbsenceTimes = true;
DevExpress.XtraReports.UI.XRTableRow row = null;
if (index < xrTableAbwesenheiten.Rows.Count)
{
row = xrTableAbwesenheiten.Rows[index];
}
else
{
row = xrTableAbwesenheiten.InsertRowBelow(
xrTableAbwesenheiten.Rows[xrTableAbwesenheiten.Rows.Count - 1]);
newRows++;
}
row.Cells[0].Text = String.Format("{0:dd.MM.yyyy}", at.Start);
int? days = null;
if (at.End.HasValue)
{
row.Cells[1].Text = String.Format("{0:dd.MM.yyyy}", at.End);
days = (int) at.End.Value.Subtract(at.Start.Value).TotalDays + 1;
}
else
{
row.Cells[1].Text = "unbekannt";
}
row.Cells[2].Text = String.Format("{0:0}", days);
index++;
}
}
}
if (!hasAbsenceTimes)
{
lblHatAbwesenheiten.Text = "X";
}
}
private void PruefeRechnungspositionen(SettlementRO pRO)
{
if (pRO.InvoiceItems != null && pRO.InvoiceItems.Count == 1)
{
var ii = pRO.InvoiceItems[0];
if ((ii.ItemDescription == "Spitzabrechung" || ii.ItemDescription == "Spitzabrechnung") && ii.GrossAmountTotal == null && ii.RateFactor == null)
{
pRO.InvoiceItems = CreateDefaultSpitzabrechnungInvoiceItems(pRO);
}
}
}
private IList<InvoiceItemDC> CreateDefaultSpitzabrechnungInvoiceItems(SettlementRO pRO)
{
IList<InvoiceItemDC> itemList = new List<InvoiceItemDC>();
if (pRO.DifferentHourlyRateCount == 3)
{
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.AccountingStartDate,
ItemPeriodEnd = pRO.HourlyRateEndDate3,
UnitCount = pRO.GeleisteteFLSMitStundensatz3,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatz3 * pRO.RateFactor * pRO.HourlyRate3,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRate3
});
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.HourlyRateOldStartDate,
ItemPeriodEnd = pRO.HourlyRateOldEndDate,
UnitCount = pRO.GeleisteteFLSMitStundensatzAlt,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatzAlt * pRO.RateFactor * pRO.HourlyRateOld,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRateOld
});
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.HourlyRateNewStartDate,
ItemPeriodEnd = pRO.AccountingEndDate,
UnitCount = pRO.GeleisteteFLSMitStundensatzAktuell,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatzAktuell * pRO.RateFactor * pRO.HourlyRateNew,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRateNew
});
}
else if (pRO.DifferentHourlyRateCount == 2)
{
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.AccountingStartDate,
ItemPeriodEnd = pRO.HourlyRateOldEndDate,
UnitCount = pRO.GeleisteteFLSMitStundensatzAlt,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatzAlt * (decimal)pRO.RateFactor * pRO.HourlyRateOld,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRateOld
});
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.HourlyRateNewStartDate,
ItemPeriodEnd = pRO.AccountingEndDate,
UnitCount = pRO.GeleisteteFLSMitStundensatzAktuell,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatzAktuell * pRO.RateFactor * pRO.HourlyRateNew,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRateNew
});
}
else
{
itemList.Add(new InvoiceItemDC
{
ItemPeriodStart = pRO.AccountingStartDate,
ItemPeriodEnd = pRO.AccountingEndDate,
UnitCount = pRO.GeleisteteFLSMitStundensatzAktuell,
GrossAmountTotal = pRO.GeleisteteFLSMitStundensatzAktuell * pRO.RateFactor * pRO.HourlyRateNew,
RateFactor = pRO.RateFactor,
AmountPerUnit = pRO.HourlyRateNew
});
}
return itemList;
}
private string CreateItemDescription(decimal hourlyRate, decimal factor)
{
String factorText = "";
if (factor > 1)
{
decimal neuerSatz = hourlyRate * factor;
factorText = String.Format(" x {0:0.0} = {1:c}", factor, neuerSatz);
}
return String.Format("x {0:c}{1}", hourlyRate, factorText);
}
private void SetzeAdresse(SettlementRO pRO)
{
StringBuilder sb = new StringBuilder();
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation) && !String.IsNullOrEmpty(pRO.RecipientOrganisation.Trim()))
{
sb.AppendLine(pRO.RecipientOrganisation);
}
if (!String.IsNullOrEmpty(pRO.RecipientContactPerson) && !String.IsNullOrEmpty(pRO.RecipientContactPerson.Trim()))
{
sb.AppendLine(pRO.RecipientContactPerson);
}
if (!String.IsNullOrEmpty(pRO.RecipientDivision) && !String.IsNullOrEmpty(pRO.RecipientDivision.Trim()))
{
sb.AppendLine(pRO.RecipientDivision);
}
if (!String.IsNullOrEmpty(pRO.RecipientStreet) && !String.IsNullOrEmpty(pRO.RecipientStreet.Trim()))
{
sb.AppendLine(pRO.RecipientStreet);
}
if (!String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown) && !String.IsNullOrEmpty(pRO.RecipientPostCodeAndTown.Trim()))
{
sb.AppendLine(pRO.RecipientPostCodeAndTown);
}
lblAddress.Text = sb.ToString();
}
private void ErstelleRechnungspositionen(SettlementRO pRO)
{
if (pRO.InvoiceItems != null && pRO.InvoiceItems.Count > 0)
{
int rowIndex = 0;
foreach (var ii in pRO.InvoiceItems)
{
//if (ii.UnitCount.HasValue && ii.UnitCount.Value > 0)
//{
AddRechnungsposition(ii, rowIndex++);
//}
}
//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);
//}
}
}
private void AddRechnungsposition(InvoiceItemDC ii, int rowIndex)
{
XRTableRow newRow = null;
if (rowIndex > 2)
{
newRow = tableRechnungspositionen.InsertRowBelow(tableRechnungspositionen.Rows[tableRechnungspositionen.Rows.Count - 1]);
}
else
{
newRow = tableRechnungspositionen.Rows[rowIndex + 1];
}
newRow.Cells[0].Text = String.Format("{0:dd.MM.yyyy}", ii.ItemPeriodStart);
newRow.Cells[1].Text = String.Format("{0:dd.MM.yyyy}", ii.ItemPeriodEnd);
newRow.Cells[2].Text = String.Format("{0:0.00}", ii.AmountPerUnit);
newRow.Cells[3].Text = String.Format("{0:0.00}", ii.UnitCount);
}
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:0.00}", ii.AmountPerUnit);
cellFLS.Text = String.Format("{0:0.00}", ii.UnitCount);
}
}
}