323 lines
11 KiB
C#
323 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Service.DCEntityMapper;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared.Core;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.DataContracts.Compact;
|
|
using BS.Shared.Extensions;
|
|
using BS.Shared.Services;
|
|
|
|
namespace ZukunftLeben.Invoicing
|
|
{
|
|
public class SoziotherapieInvoiceCreation : InvoiceCreation
|
|
{
|
|
public override void SetInvoiceId(ServiceInvoice invoice)
|
|
{
|
|
invoice.InvoiceBase.InvoiceId = "RechnungSoziotherapie";
|
|
invoice.InvoiceBase.InvoiceTypeText = "Soziotherapie";
|
|
}
|
|
|
|
public override List<ServiceInvoiceDC> GenerateServiceInvoices(long costBearerOid,
|
|
DateTimeSpan invoicePeriod,
|
|
Dictionary<CompactSupportConceptDC, List<ServiceRecordDC>> supportConcepts2ServiceRecords, bool splitInvoices)
|
|
{
|
|
var costBearer = DAOFactory.GenericDAO.LoadByID<CostBearer>(costBearerOid);
|
|
var invoiceList = new List<ServiceInvoice>();
|
|
|
|
var invoiceCounter = 0;
|
|
ServiceInvoice invoice;
|
|
|
|
if (costBearer.IsSingleInvoicePerCustomer)
|
|
{
|
|
invoice = CreateCollectiveBilling(costBearer, invoicePeriod, supportConcepts2ServiceRecords);
|
|
if (invoice != null)
|
|
{
|
|
invoiceList.Add(invoice);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var iSupportConcept2ServiceRecords in supportConcepts2ServiceRecords)
|
|
{
|
|
invoice = CreateSingleInvoice(invoiceCounter, costBearer, invoicePeriod, iSupportConcept2ServiceRecords.Key, iSupportConcept2ServiceRecords.Value);
|
|
if (invoice != null)
|
|
{
|
|
if (splitInvoices && invoice.ServiceInvoicePeriodList.Count > 1
|
|
&& !invoice.ServiceInvoicePeriodList.Any(s => s.Start == invoicePeriod.StartDate && s.End == invoicePeriod.EndDate))
|
|
{
|
|
foreach (var sip in invoice.ServiceInvoicePeriodList)
|
|
{
|
|
DateTimeSpan invPeriod = invoicePeriod;
|
|
invPeriod.StartDate = sip.Start.Value;
|
|
invPeriod.EndDate = sip.End.Value;
|
|
var partInvoice = CreateSingleInvoice(invoiceCounter, costBearer, invPeriod, iSupportConcept2ServiceRecords.Key, iSupportConcept2ServiceRecords.Value);
|
|
partInvoice.ServiceInvoicePeriodList.Add(sip);
|
|
invoiceList.Add(partInvoice);
|
|
invoiceCounter++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
invoiceList.Add(invoice);
|
|
invoiceCounter++;
|
|
|
|
// Wenn die Bewilligung, die bei Abrechnung aktuell ist, die Leistungskategorie "Soziotherapie mit Eigenanteil" enthält, muss eine Eigenanteilsrechnung zusätzlich erstellt werden.
|
|
// In der wird pro Tag, an dem Leistungen erfolgt sind, 10% der Terminkosten dem Klienten in Rechnung gestellt. Es sind entweder 10%, mindestens aber 5 EUR und maximal 10 EUR
|
|
if (invoice.InvoiceBase.CostBearer2SupportConcept.ApprovalPeriodList.Any(ap => ap.ServiceCategory != null && ap.ServiceCategory.Name.Trim() == "Soziotherapie mit Eigenanteil"))
|
|
{
|
|
var eigenanteilsInvoiceCreation = new EigenanteilsInvoiceCreation();
|
|
var eigenanteilInvoice = eigenanteilsInvoiceCreation.CreateSingleInvoice(invoiceCounter, costBearer, invoicePeriod, iSupportConcept2ServiceRecords.Key, iSupportConcept2ServiceRecords.Value);
|
|
invoiceCounter++;
|
|
invoiceList.Add(eigenanteilInvoice);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
var result = invoiceList.Select(item => MapperFactory.ServiceInvoiceDC_ServiceInvoice.MapToNewDC(item)).ToList();
|
|
return result.Count > 1 ? result.OrderBy(i => i.InvoiceBase.CustomerLastName).ToList() : result;
|
|
}
|
|
|
|
|
|
public override ServiceInvoice CreateSingleInvoice(int invoiceCounter, CostBearer costBearer, DateTimeSpan invoicePeriod, CompactSupportConceptDC supportConcept, List<ServiceRecordDC> serviceRecords)
|
|
{
|
|
var invoice = new ServiceInvoice();
|
|
|
|
var supportConceptList = new List<CompactSupportConceptDC> { supportConcept };
|
|
|
|
SetSenderInformation(invoice);
|
|
SetInvoiceBaseData(invoiceCounter, invoice, costBearer, invoicePeriod, supportConceptList);
|
|
SetSingleInvoiceBaseData(invoiceCounter, invoice, costBearer, invoicePeriod, supportConcept);
|
|
|
|
SetRecipientInformation(invoice, costBearer);
|
|
|
|
SetServiceInvoicePeriods(invoice, invoice.InvoiceBase.CostBearer2SupportConcept, invoicePeriod, serviceRecords);
|
|
|
|
SetServiceInvoicePeriodAmounts(invoice);
|
|
|
|
if (invoicePeriod == null)
|
|
{
|
|
SetAmountAdvancePayments(invoice);
|
|
SetAmountEquityContribution(invoice);
|
|
}
|
|
|
|
base.CreateSingleInvoice(invoiceCounter, costBearer, invoicePeriod, supportConcept, serviceRecords);
|
|
return invoice;
|
|
}
|
|
|
|
public override IList<InvoiceItem> CreateInvoiceItems(List<ServiceRecordDC> serviceRecordsInPeriod, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap, Calculations calc)
|
|
{
|
|
var list = base.CreateInvoiceItems(serviceRecordsInPeriod, invoicePeriod, scap, calc);
|
|
var ii = CreateHausbesuchspauschale(serviceRecordsInPeriod, invoicePeriod, scap);
|
|
list.AddRange(ii);
|
|
|
|
return list;
|
|
}
|
|
|
|
public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, Calculations calc)
|
|
{
|
|
var ii = base.CreateInvoiceItem(iServiceRecord, scap, calc);
|
|
ii.ItemDescription = iServiceRecord.ServiceDescription.Name;
|
|
|
|
if (ii.ItemDescription.ToLower().Contains("gruppe"))
|
|
{
|
|
// nur zur Info: Gruppen werden lt. Frau Klix zunächst noch nicht verwendet
|
|
if (iServiceRecord.RoundedDuration <= 45)
|
|
ii.UnitDescription = "GPos: 2002678";
|
|
else if (iServiceRecord.RoundedDuration <= 60)
|
|
ii.UnitDescription = "GPos: 2002677";
|
|
else
|
|
ii.UnitDescription = "GPos: 2002672"; // 90 min, 2-5 Personen
|
|
ii.AmountPerUnit = GetGruppenPreis(scap.CostBearer2SupportConcept, iServiceRecord.Start.Value);
|
|
ii.AmountTotal = ii.AmountPerUnit * ii.UnitCount;
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
}
|
|
else
|
|
{
|
|
ii.AmountPerUnit = GetEinzelPreis(scap.CostBearer2SupportConcept, iServiceRecord.Start.Value);
|
|
ii.AmountTotal = ii.AmountPerUnit * ii.UnitCount;
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
|
|
if (ii.ItemDescription.ToLower().Contains("video"))
|
|
{
|
|
if (iServiceRecord.RoundedDuration <= 30)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001616";
|
|
}
|
|
else
|
|
{
|
|
ii.UnitDescription = "GPos: 2001615";
|
|
}
|
|
}
|
|
else if (ii.ItemDescription.ToLower().Contains("telefonat"))
|
|
{
|
|
if (iServiceRecord.RoundedDuration <= 30)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001618";
|
|
}
|
|
else
|
|
{
|
|
ii.UnitDescription = "GPos: 2001617";
|
|
}
|
|
}
|
|
else if (ii.ItemDescription.ToLower().Contains("aufsuchende einheit"))
|
|
{
|
|
if (iServiceRecord.RoundedDuration <= 10)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001613 / 2009690";
|
|
}
|
|
else if (iServiceRecord.RoundedDuration <= 30)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001612 / 2009690";
|
|
}
|
|
else if (iServiceRecord.RoundedDuration <= 45)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001611 / 2009690";
|
|
}
|
|
else
|
|
{
|
|
ii.UnitDescription = "GPos: 2001610 / 2009690";
|
|
}
|
|
}
|
|
else if (ii.ItemDescription.ToLower().Contains("aufsuchende probatorik"))
|
|
{
|
|
ii.UnitDescription = "GPos: 2001607 / 2009690";
|
|
}
|
|
else if (ii.ItemDescription.ToLower().Contains("büroprobatorik"))
|
|
{
|
|
ii.UnitDescription = "GPos: 2001607";
|
|
}
|
|
else if (ii.ItemDescription.ToLower().Contains("büroeinheit"))
|
|
{
|
|
if (iServiceRecord.RoundedDuration <= 10)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001613";
|
|
}
|
|
else if (iServiceRecord.RoundedDuration <= 30)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001612";
|
|
}
|
|
else if (iServiceRecord.RoundedDuration <= 45)
|
|
{
|
|
ii.UnitDescription = "GPos: 2001611";
|
|
}
|
|
else
|
|
{
|
|
ii.UnitDescription = "GPos: 2001610";
|
|
}
|
|
}
|
|
}
|
|
|
|
return ii;
|
|
}
|
|
|
|
public virtual IList<InvoiceItem> CreateHausbesuchspauschale(List<ServiceRecordDC> serviceRecordsInPeriod, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap)
|
|
{
|
|
IList<InvoiceItem> items = new List<InvoiceItem>();
|
|
decimal hausbesuchspauschale = 8.53m;
|
|
if (scap != null && invoicePeriod != null)
|
|
{
|
|
hausbesuchspauschale = GetHausbesuchspauschale(scap.CostBearer2SupportConcept, invoicePeriod.StartDate);
|
|
}
|
|
int countHausbesuch = 0;
|
|
foreach (var sr in serviceRecordsInPeriod)
|
|
{
|
|
if (sr.ServiceDescription != null && sr.ServiceDescription.Name != null && sr.ServiceDescription.Name.ToLower().Contains("aufsuchend"))
|
|
{
|
|
countHausbesuch++;
|
|
}
|
|
}
|
|
|
|
if (countHausbesuch > 0)
|
|
{
|
|
var invoiceItem = new InvoiceItem();
|
|
|
|
decimal anzahlHausbesuche = countHausbesuch;
|
|
|
|
invoiceItem.AmountPerUnit = hausbesuchspauschale;
|
|
invoiceItem.UnitCount = anzahlHausbesuche;
|
|
invoiceItem.AmountTotal = anzahlHausbesuche * hausbesuchspauschale;
|
|
if (invoicePeriod != null)
|
|
{
|
|
invoiceItem.ItemPeriodStart = invoicePeriod.StartDate;
|
|
invoiceItem.ItemPeriodEnd = invoicePeriod.EndDate;
|
|
}
|
|
invoiceItem.RateFactor = null;
|
|
invoiceItem.GrossAmountTotal = invoiceItem.AmountTotal;
|
|
invoiceItem.ItemDescription = "Hausbesuchspauschale";
|
|
invoiceItem.UnitDescription = "GPos: 2009690";
|
|
if (scap != null)
|
|
invoiceItem.SupportConceptApprovalPeriodOid = scap.Oid;
|
|
|
|
items.Add(invoiceItem);
|
|
}
|
|
return items;
|
|
}
|
|
|
|
private decimal GetHausbesuchspauschale(CostBearer2SupportConcept c2s, DateTime dt)
|
|
{
|
|
String preisName = "Hausbesuchspauschale Primärkasse";
|
|
|
|
if (c2s.CostBearer.Organisation.Function != null)
|
|
{
|
|
if (c2s.CostBearer.Organisation.Function.Value.Contains("Ersatzkasse"))
|
|
{
|
|
preisName = "Hausbesuchspauschale Ersatzkasse";
|
|
}
|
|
}
|
|
|
|
return base.GetPreis(preisName, dt);
|
|
}
|
|
|
|
private decimal GetGruppenPreis(CostBearer2SupportConcept c2s, DateTime dt)
|
|
{
|
|
String preisName = "Gruppenstunde Primärkasse";
|
|
|
|
if (c2s.CostBearer.Organisation.Function != null)
|
|
{
|
|
if (c2s.CostBearer.Organisation.Function.Value.Contains("Ersatzkasse"))
|
|
{
|
|
preisName = "Gruppenstunde Ersatzkasse";
|
|
}
|
|
}
|
|
|
|
return base.GetPreis(preisName, dt);
|
|
}
|
|
|
|
private decimal GetEinzelPreis(CostBearer2SupportConcept c2s, DateTime dt)
|
|
{
|
|
String preisName = "Einzelstunde Primärkasse";
|
|
|
|
if (c2s.CostBearer.Organisation.Function != null)
|
|
{
|
|
if (c2s.CostBearer.Organisation.Function.Value.Contains("Ersatzkasse"))
|
|
{
|
|
preisName = "Einzelstunde Ersatzkasse";
|
|
}
|
|
}
|
|
|
|
return base.GetPreis(preisName, dt);
|
|
}
|
|
|
|
public override IList<InvoiceItem> CreateSummaryInvoiceItems(IList<InvoiceItem> itemList, DateTimeSpan invoicePeriod, SupportConceptApprovalPeriod scap, Calculations calc, bool summaryPerMonth, bool addRateFactorToUnitCount)
|
|
{
|
|
return base.CreateSummaryInvoiceItems(itemList, invoicePeriod, scap, calc, true, true);
|
|
}
|
|
|
|
public override string GetSummaryItemKey(SupportConceptApprovalPeriod scap, InvoiceItem iitem, bool summaryPerMonth)
|
|
{
|
|
String key = String.Format("{0}_{1}_{2}", iitem.AmountPerUnit, iitem.RateFactor, iitem.ItemDescription);
|
|
if (summaryPerMonth)
|
|
{
|
|
key = String.Format("{0}_{1}_{2:yyyyMM}_{3}", iitem.AmountPerUnit, iitem.RateFactor, iitem.ItemPeriodStart, iitem.ItemDescription);
|
|
}
|
|
|
|
return key;
|
|
}
|
|
}
|
|
}
|