DrobDrogenhilfe/Invoicing/CustomSettlementInvoiceCreation - kein Zusammenfassen Entgeltzeiträume (2x gleicher Preis)

This commit is contained in:
2025-09-17 15:23:46 +02:00
parent 742a2b1613
commit 1a2f304810
2 changed files with 86 additions and 0 deletions

View File

@@ -60,6 +60,7 @@
<Compile Include="Calculations\CustomGroupDurationCalculator.cs" />
<Compile Include="Invoicing\CustomInvoiceCreation.cs" />
<Compile Include="Invoicing\CustomInvoiceFactory.cs" />
<Compile Include="Invoicing\CustomSettlementInvoiceCreation.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>

View File

@@ -15,5 +15,90 @@ namespace DrobDrogenhilfe
internal class CustomSettlementInvoiceCreation : LWLSettlementInvoiceCreation
{
// muss doch permanent bei denen sein, geht nur um zusammenfassen der Items in Zeile 27
// die haben tatsächlich den gleichen Preis zweimal bekommen und brauchen den getrennt ausgewiesen
// das kann zu Ärger führen, wenn jemand in einem Zeitraum 2 Bewilligungen hat, dann hätte der LWL die gern zusammen gefasst, also nicht als Standard tauglich
public override List<InvoiceItemDC> CreateInvoiceItems(Settlement2DC si, IList<ApprovalPeriod> apList, bool schneideBeiMaxAb)
{
List<InvoiceItemDC> iiList = new List<InvoiceItemDC>();
var apsByHourlyRate = new Dictionary<String, IList<ApprovalPeriod>>();
foreach (var ap in apList)
{
IList<ApprovalPeriod> list = null;
String key = String.Format("{0}_{1}_{2:ddMMyyy}", ap.AmountPerUnit, ap.RateFactor, ap.PeriodStartDate);
if (apsByHourlyRate.ContainsKey(key))
{
list = apsByHourlyRate[key];
}
else
{
list = new List<ApprovalPeriod>();
apsByHourlyRate[key] = list;
}
list.Add(ap);
}
decimal maxApprovedFls = si.ApprovedFLS ?? 0;
decimal totalHours = 0;
foreach (var key in apsByHourlyRate.Keys)
{
IList<ApprovalPeriod> list = apsByHourlyRate[key];
var ii = new InvoiceItemDC();
decimal minutesTotal = 0;
decimal minutesTotalBudget = 0;
DateTime start = DateTime.MaxValue;
DateTime end = DateTime.MinValue;
decimal rf = si.RateFactor ?? 0;
decimal hr = 0;
foreach (var approvalPeriod in list)
{
minutesTotal += approvalPeriod.RecordedMinutes;
minutesTotalBudget += approvalPeriod.BudgetMinutes;
if (approvalPeriod.PeriodStartDate < start)
start = approvalPeriod.PeriodStartDate;
if (approvalPeriod.PeriodEndDate > end)
end = approvalPeriod.PeriodEndDate;
hr = approvalPeriod.AmountPerUnit;
if (approvalPeriod.RateFactor.HasValue)
{
rf = approvalPeriod.RateFactor.Value;
}
if (!String.IsNullOrEmpty(approvalPeriod.Notice) && approvalPeriod.Notice == "Fehlkontakte")
{
hr *= 0.8m;
ii.ItemDescription = "Fehlkontakte";
}
}
ii.ItemPeriodStart = start;
ii.ItemPeriodEnd = end;
ii.RateFactor = rf;
ii.AmountPerUnit = hr;
decimal hours = Math.Round(minutesTotal / 60m, 2, MidpointRounding.AwayFromZero);
hours *= (100 + rf) / 100;
hours = Math.Round(hours, 2, MidpointRounding.AwayFromZero);
decimal hoursBudget = Math.Round(minutesTotalBudget / 60m, 2, MidpointRounding.AwayFromZero);
hoursBudget *= (100 + rf) / 100;
hoursBudget = Math.Round(hoursBudget, 2, MidpointRounding.AwayFromZero);
totalHours += hoursBudget;
ii.UnitCount = hours;
ii.UnitCountBudget = hoursBudget;
ii.AmountTotal = Math.Round(hr * hours, 2, MidpointRounding.AwayFromZero);
ii.GrossAmountTotal = ii.AmountTotal;
iiList.Add(ii);
}
return iiList.OrderBy(ii => ii.ItemPeriodStart).ToList();
}
}
}