345 lines
14 KiB
C#
345 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.Invoicing;
|
|
using BeWo.Report;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.ServiceImplementations;
|
|
using BS.Shared;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Extensions;
|
|
using DevExpress.Printing.Native;
|
|
using DevExpress.XtraReports.UI;
|
|
using PraxisPusteblume.Invoicing;
|
|
|
|
namespace PraxisPusteblume
|
|
{
|
|
[IDSpecificClass(Identifier = "IFSSammelrechnung")]
|
|
public partial class IfsSammelRechnung : XtraReport, IBeWoReport<ServiceInvoiceRO>
|
|
{
|
|
public IfsSammelRechnung()
|
|
{
|
|
this.InitializeComponent();
|
|
}
|
|
|
|
public void SetReportDataSource(ServiceInvoiceRO pRO)
|
|
{
|
|
bool mq = false;
|
|
StringBuilder sb = new StringBuilder();
|
|
if (!String.IsNullOrEmpty(pRO.RecipientOrganisation))
|
|
{
|
|
if (pRO.RecipientOrganisation.Contains(" - IFS"))
|
|
{
|
|
pRO.RecipientOrganisation = pRO.RecipientOrganisation.Replace(" - IFS", "").Trim();
|
|
}
|
|
if (pRO.RecipientOrganisation.Contains("(TS)"))
|
|
{
|
|
pRO.RecipientOrganisation = pRO.RecipientOrganisation.Replace(" (TS)", "").Trim();
|
|
}
|
|
else if (pRO.RecipientOrganisation.Contains("(MQ)"))
|
|
{
|
|
if (pRO.RecipientOrganisation.Contains("Bezirk Oberbayern"))
|
|
lblEinrichtung.Text = lblEinrichtung.Text.Replace("ZE-102358", "ZE-103522");
|
|
|
|
pRO.RecipientOrganisation = pRO.RecipientOrganisation.Replace(" (MQ)", "").Trim();
|
|
mq = true;
|
|
}
|
|
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);
|
|
}
|
|
if (mq)
|
|
{
|
|
lblEinrichtung.Text = lblEinrichtung.Text.Replace("102358", "102522");
|
|
rtKopfIfs.Text = rtKopfIfs.Text.Replace("Jahnstraße 31, 83278 Traunstein", "Staudacher Str. 12, 83250 Marquartstein");
|
|
}
|
|
|
|
SetzePreise(pRO, mq);
|
|
|
|
if (pRO.ServiceInvoicePeriods != null && pRO.ServiceInvoicePeriods.Count > 0)
|
|
{
|
|
foreach (var p in pRO.ServiceInvoicePeriods)
|
|
{
|
|
var newInvoiceItem = CreateNewInvoiceItem(pRO, p);
|
|
p.ServiceInvoiceItems = new List<ServiceInvoiceItemRO>();
|
|
p.ServiceInvoiceItems.Add(newInvoiceItem);
|
|
|
|
}
|
|
pRO.ServiceInvoicePeriods.Sort((a, b) => a.ServiceInvoiceItems[0].CustomerLastname.CompareTo(b.ServiceInvoiceItems[0].CustomerLastname));
|
|
}
|
|
|
|
this.bindingSource1.DataSource = pRO;
|
|
}
|
|
|
|
private ServiceInvoiceItemRO CreateNewInvoiceItem(ServiceInvoiceRO pRo, ServiceInvoicePeriodRO sip)
|
|
{
|
|
ServiceInvoiceItemRO newItem = new ServiceInvoiceItemRO();
|
|
if (sip.Customer != null)
|
|
{
|
|
newItem.CustomerBirthdate = sip.Customer.DateOfBirth;
|
|
newItem.CustomerFirstname = sip.Customer.FirstName;
|
|
newItem.CustomerLastname = sip.Customer.LastName;
|
|
}
|
|
else
|
|
{
|
|
newItem.CustomerLastname = "";
|
|
}
|
|
|
|
if (sip.CostBearer2SupportConcept != null)
|
|
{
|
|
newItem.ServiceDescription = sip.CostBearer2SupportConcept.CustomerReferenceNumber;
|
|
}
|
|
|
|
decimal ambulantStunden = 0;
|
|
decimal ambulantPreis = 0;
|
|
decimal mobilStunden = 0;
|
|
decimal mobilPreis = 0;
|
|
decimal gruppeStunden = 0;
|
|
decimal gruppePreis = 0;
|
|
decimal teamStunden = 0;
|
|
decimal teamPreis = 0;
|
|
decimal investStunden = 0;
|
|
decimal investPreis = 0;
|
|
decimal gruppeInterStunden = 0;
|
|
decimal gruppeInterPreis = 0;
|
|
decimal vernetzungStunden = 0;
|
|
decimal vernetzungPreis = 0;
|
|
|
|
if (sip.ServiceInvoiceItems != null && sip.ServiceInvoiceItems.Count > 0)
|
|
{
|
|
if (sip.Customer.LastName == "Achatz")
|
|
{
|
|
|
|
}
|
|
foreach (var i in sip.ServiceInvoiceItems)
|
|
{
|
|
if (i.ServiceDescription == null)
|
|
{
|
|
i.ServiceDescription = "";
|
|
}
|
|
if (i.ServiceDescription == "Team" || i.ServiceDescription == "Team (intern)")
|
|
{
|
|
teamPreis += i.NetAmount ?? 0;
|
|
teamStunden += i.UnitCount ?? 0;
|
|
}
|
|
else if (i.ServiceDescription == "Invest")
|
|
{
|
|
investPreis += i.NetAmount ?? 0;
|
|
investStunden += i.UnitCount ?? 0;
|
|
}
|
|
else if (i.ServiceDescription.Contains("Vernetzung") || i.ServiceDescription == "Team (extern)")
|
|
{
|
|
vernetzungPreis += i.NetAmount ?? 0;
|
|
vernetzungStunden = 1;
|
|
}
|
|
else if (i.ServiceDescription.ToLower().Contains("interd"))
|
|
{
|
|
gruppeInterPreis += GetGrossAmount(i);
|
|
gruppeInterStunden += i.UnitCount ?? 0;
|
|
}
|
|
else if (i.ServiceDescription.Contains("Gruppe"))
|
|
{
|
|
gruppePreis += GetGrossAmount(i);
|
|
gruppeStunden += i.UnitCount ?? 0;
|
|
}
|
|
else
|
|
{
|
|
if (i.ServiceRecord != null)
|
|
{
|
|
if (i.ServiceRecord.ServiceDescription.Name.ToLower().Contains("mobil"))
|
|
{
|
|
mobilPreis += GetGrossAmount(i);
|
|
mobilStunden += i.UnitCount ?? 0;
|
|
}
|
|
else
|
|
{
|
|
ambulantPreis += GetGrossAmount(i);
|
|
ambulantStunden += i.UnitCount ?? 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
newItem.HourlyRate = ambulantStunden;
|
|
newItem.HourlyRateString = String.Format("{0:c}", ambulantPreis);
|
|
newItem.Hours = mobilStunden;
|
|
newItem.NetAmount = mobilPreis;
|
|
newItem.Notice = String.Format("{0:0.##}", gruppeStunden);
|
|
newItem.RateFactor = String.Format("{0:c}", gruppePreis);
|
|
newItem.UnitCount = teamStunden;
|
|
newItem.UnitCountString = String.Format("{0:c}", teamPreis);
|
|
newItem.UnitDescription = String.Format("{0:0.##}", investStunden);
|
|
sip.NotBillableString = String.Format("{0:c}", investPreis);
|
|
sip.ApprovalPeriod = String.Format("{0:0.##}", gruppeInterStunden);
|
|
sip.ApprovedAmount = String.Format("{0:c}", gruppeInterPreis);
|
|
sip.ApprovedBE = String.Format("{0:0.##}", vernetzungStunden);
|
|
sip.Notice = String.Format("{0:c}", vernetzungPreis);
|
|
|
|
return newItem;
|
|
}
|
|
|
|
private decimal GetGrossAmount(ServiceInvoiceItemRO ii)
|
|
{
|
|
decimal amount = 0;
|
|
if (Decimal.TryParse(ii.GrossAmount.Replace("€", ""), out amount))
|
|
{
|
|
return amount;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
private void SetzePreise(ServiceInvoiceRO pRO, bool istMQ)
|
|
{
|
|
decimal preisAmbulant = 58.24m;
|
|
decimal preisMobil = 78.08m;
|
|
decimal preisGruppe = 32.53m;
|
|
decimal preisTeam = 10.88m;
|
|
decimal preisInvest = 4.84m;
|
|
decimal preisVernetzung = 18m;
|
|
decimal preisGruppeInter = 47.45m;
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2019, 4, 1))
|
|
{
|
|
preisTeam = 11.26m;
|
|
preisGruppe = 33.68m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2020, 3, 1))
|
|
{
|
|
preisTeam = 11.38m;
|
|
preisGruppe = 34.05m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2021, 6, 1))
|
|
{
|
|
preisTeam = 11.63m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2022, 4, 1))
|
|
{
|
|
preisTeam = 11.77m;
|
|
preisGruppe = 35.22m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2023, 11, 1))
|
|
{
|
|
preisTeam = 12.81m;
|
|
preisGruppe = 38.35m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2024, 04, 1))
|
|
{
|
|
preisTeam = 13.27m;
|
|
}
|
|
if (DateTime.Now >= new DateTime(2021, 8, 17))
|
|
{
|
|
preisInvest = 6.86m;
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2024, 08, 01))
|
|
{
|
|
var preise = DAOFactory.GenericDAO.GetAllActive<Preis>();
|
|
|
|
if (istMQ)
|
|
{
|
|
preisInvest = GetPreis(preise, "Invest (MQ)", pRO.AccountingPeriodStart);
|
|
}
|
|
else
|
|
{
|
|
preisInvest = GetPreis(preise, "Invest (TS)", pRO.AccountingPeriodStart);
|
|
}
|
|
|
|
preisTeam = GetPreis(preise, "Team (intern)", pRO.AccountingPeriodStart);
|
|
}
|
|
if (pRO.AccountingPeriodStart >= new DateTime(2025, 09, 01))
|
|
{
|
|
var preise = DAOFactory.GenericDAO.GetAllActive<Preis>();
|
|
//preisVernetzung = GetPreis(preise, "Team Vernetzung", pRO.AccountingPeriodStart);
|
|
preisVernetzung = GetPreis(preise, "Team (extern)", pRO.AccountingPeriodStart);
|
|
preisGruppeInter = 42.18m;
|
|
}
|
|
|
|
var cat = DAOFactory.SearchDAO.FindServiceCategoryByName("IFS - Psychologie / Heilpädagogik");
|
|
if (cat != null)
|
|
{
|
|
var sdList = DAOFactory.SearchDAO.FindServiceDescriptionForCategory(cat.Oid.Value);
|
|
|
|
var mobil = sdList.FirstOrDefault(s => s.Name.Contains("mobil"));
|
|
if (mobil != null && mobil.CostRatePeriods != null)
|
|
{
|
|
var crpList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(mobil.CostRatePeriods);
|
|
CostRatePeriodDC crp = crpList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, pRO.AccountingPeriodStart);
|
|
|
|
if (crp != null && crp.CostRateValue.HasValue)
|
|
{
|
|
preisMobil = crp.CostRateValue.Value;
|
|
}
|
|
}
|
|
var ambulant = sdList.FirstOrDefault(s => s.Name.Contains("ambulant"));
|
|
if (ambulant != null && ambulant.CostRatePeriods != null)
|
|
{
|
|
var crpList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(ambulant.CostRatePeriods);
|
|
CostRatePeriodDC crp = crpList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, pRO.AccountingPeriodStart);
|
|
|
|
if (crp != null && crp.CostRateValue.HasValue)
|
|
{
|
|
preisAmbulant = crp.CostRateValue.Value;
|
|
}
|
|
}
|
|
var gruppe = sdList.FirstOrDefault(s => s.Name.Contains("(G)") || (s.Name.Contains("Gruppe") && !s.Name.Contains("IG")));
|
|
var gruppeInter = sdList.FirstOrDefault(s => s.Name.Contains("(IG)"));
|
|
if (gruppe != null && ambulant.CostRatePeriods != null)
|
|
{
|
|
var crpList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(gruppe.CostRatePeriods);
|
|
CostRatePeriodDC crp = crpList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, pRO.AccountingPeriodStart);
|
|
|
|
if (crp != null && crp.CostRateValue.HasValue)
|
|
{
|
|
preisGruppe = crp.CostRateValue.Value;
|
|
}
|
|
}
|
|
if (gruppeInter != null && ambulant.CostRatePeriods != null)
|
|
{
|
|
var crpList = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(gruppeInter.CostRatePeriods);
|
|
CostRatePeriodDC crp = crpList.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, pRO.AccountingPeriodStart);
|
|
|
|
if (crp != null && crp.CostRateValue.HasValue)
|
|
{
|
|
preisGruppeInter = crp.CostRateValue.Value;
|
|
}
|
|
}
|
|
}
|
|
|
|
cellPreisAmbulant.Text = String.Format("{0:c}", preisAmbulant);
|
|
cellPreisMobil.Text = String.Format("{0:c}", preisMobil);
|
|
cellPreisGruppe.Text = String.Format("{0:c}", preisGruppe);
|
|
cellPreisTeam.Text = String.Format("{0:c}", preisTeam);
|
|
cellPreisInvest.Text = String.Format("{0:c}", preisInvest);
|
|
cellPreisGruppeInter.Text = String.Format("{0:c}", preisGruppeInter);
|
|
cellPreisTeamExtern.Text = String.Format("{0:c}", preisVernetzung);
|
|
}
|
|
|
|
private static decimal GetPreis(IList<Preis> allePreise, String name, DateTime datum)
|
|
{
|
|
var tagessatz = allePreise.Where(p => p.Name.Contains(name)).FirstOrDefault();
|
|
if (tagessatz != null)
|
|
{
|
|
var crlist = MapperFactory.CostRatePeriodDC_CostRatePeriod.MapToNewDCs(tagessatz.CostRatePeriods);
|
|
var cr = crlist.GetCostRatePeriodForDate(CostRatePeriodType.AmountOfMoney, datum);
|
|
if (cr != null && cr.CostRateValue.HasValue)
|
|
{
|
|
return cr.CostRateValue.Value;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
} |