SicherlebenMichaelVoß/Invoicing/CustomSettlementInvoiceCreation - Zusammenfassen Entgeltzeiträume als Bugfix

This commit is contained in:
2025-09-17 15:22:31 +02:00
parent c846e2ac3f
commit 89fd7f727e
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BeWo.Data.Entities;
using BeWo.Service.Invoicing;
using BeWo.Service.Plugins;
using BS.Shared.Core;
using BS.Shared.DataContracts;
namespace SicherlebenMichaelVoß
{
[IDSpecificClass(Identifier = "LWLNEU")]
[IgnoreAutoPlugin]
internal class CustomSettlementInvoiceCreation : LWLSettlementInvoiceCreation
{
// AB, 17.09.2025: ist nur als Bugfix drin, damit die schnell wieder was tun können, kann nach Serverlieferung raus.
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}", ap.AmountPerUnit, ap.RateFactor);
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();
}
}
}

View File

@@ -60,6 +60,7 @@
<ItemGroup>
<Compile Include="CustomMitarbeiterstundenkontoBerechnung.cs" />
<Compile Include="CustomMitarbeiterstundenkontoBerechnungMonate.cs" />
<Compile Include="Invoicing\CustomSettlementInvoiceCreation.cs" />
<Compile Include="Mitarbeiterarbeitszeitkonto.cs">
<SubType>Component</SubType>
</Compile>