205 lines
7.3 KiB
C#
205 lines
7.3 KiB
C#
using BeWo.Data.Entities;
|
|
using BeWo.Service.Invoicing;
|
|
using BS.Shared.DataContracts;
|
|
using BS.Shared.Services;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace LebensWert.Invoicing
|
|
{
|
|
public class CustomSettlementInvoiceCreation : SettlementInvoiceCreation
|
|
{
|
|
public override bool CanCreateInvoiceTheOldWay(Settlement2DC si, CostBearer2SupportConcept c2s)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override InvoiceItemDC CreateInvoiceItemForAccountingPeriod(AccountingPeriod accountingPeriod)
|
|
{
|
|
var item = base.CreateInvoiceItemForAccountingPeriod(accountingPeriod);
|
|
var mins = accountingPeriod.CostRatesInPeriod.FirstOrDefault(p => p.CostRateType == BS.Shared.CostRatePeriodType.MinutesPerServiceUnit);
|
|
|
|
if (mins != null && mins.CostRateValue != null)
|
|
{
|
|
item.UnitCount *= 60 / mins.CostRateValue;
|
|
item.UnitCountBudget *= 60 / mins.CostRateValue;
|
|
//item.AmountTotal *= 60 / mins.CostRateValue;
|
|
//item.GrossAmountTotal *= 60 / mins.CostRateValue;
|
|
}
|
|
|
|
return item;
|
|
}
|
|
|
|
public override List<InvoiceItemDC> CreateInvoiceItemsForAccountingPeriods(Settlement2DC si, List<AccountingPeriod> accountingPeriods,
|
|
List<CostRatePeriodDC> costRatePeriods, Calculations calc)
|
|
{
|
|
Dictionary<long, SupportConceptApprovalPeriodDC> oid2Scap = new Dictionary<long, SupportConceptApprovalPeriodDC>();
|
|
List<InvoiceItemDC> invoiceItems = new List<InvoiceItemDC>();
|
|
|
|
foreach (var ap in accountingPeriods)
|
|
{
|
|
InvoiceItemDC ii = CreateInvoiceItemForAccountingPeriod(ap);
|
|
invoiceItems.Add(ii);
|
|
|
|
// ANPASSUNG
|
|
if (si.RecipientOrganisation.ToLower().Contains("neu"))
|
|
{
|
|
InvoiceItemDC pauschalenItem = CreateKontaktpauschalenItem(ap, si.RecipientOrganisation);
|
|
if (pauschalenItem != null)
|
|
invoiceItems.Add(pauschalenItem);
|
|
}
|
|
|
|
|
|
var scap = ap.SupportConceptApprovalPeriod;
|
|
SupportConceptApprovalPeriodDC scapHelper = null;
|
|
|
|
if (scap != null)
|
|
{
|
|
if (oid2Scap.ContainsKey(scap.SupportConceptApprovalPeriodOid.Value))
|
|
scapHelper = oid2Scap[scap.SupportConceptApprovalPeriodOid.Value];
|
|
else
|
|
{
|
|
scapHelper = new SupportConceptApprovalPeriodDC();
|
|
scapHelper.ApprovedBETotal = scap.ApprovedBETotal;
|
|
if (!scapHelper.ApprovedBETotal.HasValue)
|
|
scapHelper.ApprovedBETotal = calc.GetApprovedBETotal(scap, costRatePeriods);
|
|
|
|
oid2Scap[scap.SupportConceptApprovalPeriodOid.Value] = scapHelper;
|
|
}
|
|
}
|
|
|
|
if (!si.ApprovedFLS.HasValue)
|
|
{
|
|
if (scapHelper.ApprovedBETotal.HasValue && ii.UnitCount.HasValue)
|
|
{
|
|
if (scapHelper.ApprovedBETotal >= ii.UnitCount.Value)
|
|
{
|
|
scapHelper.ApprovedBETotal -= ii.UnitCount.Value;
|
|
ii.MaxApprovedUnitCount = null;
|
|
}
|
|
else
|
|
{
|
|
ii.MaxApprovedUnitCount = scapHelper.ApprovedBETotal;
|
|
}
|
|
}
|
|
|
|
CalculateInvoiceItemAmounts(ii);
|
|
}
|
|
|
|
if (ii.UnitCount.HasValue)
|
|
{
|
|
si.RecordedBillableFLSBrutto = (si.RecordedBillableFLSBrutto ?? 0) + ii.UnitCount;
|
|
si.RecordedBillableFLSNetto = si.RecordedBillableFLSBrutto ?? 0;
|
|
}
|
|
|
|
var list = CreateAdditionalInvoiceItems(ap);
|
|
invoiceItems.AddRange(list);
|
|
}
|
|
return invoiceItems;
|
|
}
|
|
|
|
private static InvoiceItemDC CreateKontaktpauschalenItem(AccountingPeriod accountingPeriod, string recipientOrganisation)
|
|
{
|
|
InvoiceItemDC invoiceItem = null;
|
|
decimal unitCount = 0;
|
|
|
|
foreach (var sr in accountingPeriod.ServiceRecordsInPeriod)
|
|
{
|
|
if (sr.ServiceDescription.Name.ToLower() == "face-to-face" || sr.ServiceDescription.Name.ToLower() == "face to face" ||
|
|
sr.ServiceDescription.Name.ToLower() == "begleitende maßnahmen" || sr.ServiceDescription.Name.ToLower() == "arztbesuch")
|
|
{
|
|
unitCount++;
|
|
}
|
|
}
|
|
|
|
if (unitCount > 0)
|
|
{
|
|
decimal pauschale = 0;
|
|
if (accountingPeriod.PeriodStart >= new DateTime(2025, 04, 01))
|
|
{
|
|
var hic = new CustomInvoiceCreationHA();
|
|
pauschale = hic.GetPreis("Kontaktpauschale", accountingPeriod.PeriodStart);
|
|
}
|
|
else
|
|
{
|
|
if (accountingPeriod.PeriodStart >= new DateTime(2024, 03, 01))
|
|
pauschale = PauschalenHelper.AMOUNT_FOR_ALL_SINCE_03_2024;
|
|
if (recipientOrganisation.ToLower().Contains("hannover"))
|
|
pauschale = PauschalenHelper.HANNOVER_AMOUNT_SINCE_2023;
|
|
else if (recipientOrganisation.ToLower().Contains("hildesheim"))
|
|
pauschale = PauschalenHelper.HILDESHEIM_AMOUNT_SINCE_2023;
|
|
else if (recipientOrganisation.ToLower().Contains("nienburg"))
|
|
pauschale = PauschalenHelper.NIENBURG_AMOUNT_SINCE_2023;
|
|
}
|
|
invoiceItem = new InvoiceItemDC()
|
|
{
|
|
UnitCount = unitCount,
|
|
ItemDescription = "Kontaktpauschale",
|
|
UnitDescription = "Pauschale pro direktem Kontakt",
|
|
AmountPerUnit = pauschale,
|
|
AmountTotal = pauschale * unitCount * ((accountingPeriod.RateFactor + 100) / 100),
|
|
GrossAmountTotal = pauschale * unitCount * ((accountingPeriod.RateFactor + 100) / 100),
|
|
ItemPeriodStart = accountingPeriod.PeriodStart,
|
|
ItemPeriodEnd = accountingPeriod.PeriodEnd,
|
|
ProzentAbrechenbar = 100,
|
|
MaxApprovedUnitCount = unitCount,
|
|
MaxApprovedAmount = pauschale * unitCount * ((accountingPeriod.RateFactor + 100) / 100),
|
|
ApprovedPerUnit = 1000,
|
|
//RateFactor = (accountingPeriod.RateFactor + 100) / 100,
|
|
};
|
|
}
|
|
|
|
return invoiceItem;
|
|
}
|
|
|
|
public override void CalculateInvoiceItemAmounts(Settlement2DC si)
|
|
{
|
|
decimal maxApprovedFls = si.ApprovedFLS ?? 0;
|
|
|
|
foreach (var ii in si.InvoiceItems)
|
|
{
|
|
// Anpassung
|
|
if (ii.ItemDescription == "Kontaktpauschale")
|
|
continue;
|
|
|
|
#region standard
|
|
if (ii.UnitCount.HasValue)
|
|
{
|
|
var unitCountBudget = Math.Round(ii.UnitCountBudget ?? ii.UnitCount ?? 0, 2, MidpointRounding.AwayFromZero);
|
|
if (maxApprovedFls < unitCountBudget)
|
|
unitCountBudget = maxApprovedFls;
|
|
|
|
maxApprovedFls -= unitCountBudget;
|
|
|
|
if (unitCountBudget < ii.UnitCount)
|
|
{
|
|
ii.UnitCount = unitCountBudget;
|
|
}
|
|
if (ii.AmountPerUnit.HasValue)
|
|
{
|
|
if (!String.IsNullOrEmpty(ii.ItemDescription) && ii.ItemDescription == "Fehlkontakte")
|
|
{
|
|
ii.AmountPerUnit = ii.AmountPerUnit * ii.ProzentAbrechenbar / 100;
|
|
}
|
|
ii.AmountTotal = ii.UnitCount.Value * ii.AmountPerUnit.Value;
|
|
if (ii.RateFactor.HasValue && ii.RateFactor.Value != 0)
|
|
ii.GrossAmountTotal = Math.Round(ii.AmountTotal.Value * ((100m + ii.RateFactor.Value) / 100m), 2,
|
|
MidpointRounding.AwayFromZero);
|
|
else
|
|
ii.GrossAmountTotal = ii.AmountTotal;
|
|
|
|
}
|
|
if (ii.MaxApprovedUnitCount < ii.UnitCount)
|
|
{
|
|
ii.MaxApprovedUnitCount = ii.UnitCount;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|
|
}
|
|
}
|