SpitalstiftungKonstanz/Invoicing/CustomInvoiceCreation.cs - Berücksichtigung der jährlichen Kontingente

This commit is contained in:
2024-10-21 14:53:46 +02:00
parent fef083ea16
commit cab3cc6dd6

View File

@@ -59,11 +59,12 @@ namespace SpitalstiftungKonstanz.Invoicing
else
{
if (serviceInvoicePeriod.End.HasValue && serviceInvoicePeriod.End.Value.Month == 3 || serviceInvoicePeriod.End.Value.Month == 6
|| serviceInvoicePeriod.End.Value.Month == 9 || serviceInvoicePeriod.End.Value.Month == 12)
|| serviceInvoicePeriod.End.Value.Month == 9 || serviceInvoicePeriod.End.Value.Month == 12 ||
(serviceInvoicePeriod.End.Value.Year == cb2sc.EndDate.Value.Year && serviceInvoicePeriod.End.Value.Month == serviceInvoicePeriod.End.Value.Month))
{
var srList = cb2sc.ServiceRecords;
var srListDc = (from sr in cb2sc.ServiceRecords
where (sr.Start >= serviceInvoicePeriod.Start.Value && sr.Start < serviceInvoicePeriod.End.Value)
where sr.Start >= serviceInvoicePeriod.Start.Value && sr.Start <= serviceInvoicePeriod.End.Value.AddDays(1)
select MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(sr)).ToList();
List<ServiceRecordDC> serviceRecordsInPeriod = srListDc.Where(i =>
{
@@ -88,11 +89,7 @@ namespace SpitalstiftungKonstanz.Invoicing
span2Hours,
true, true);
serviceInvoicePeriod.HoursNotBillableNotApproved +=
calc.GetHoursNotBillableDueToMoreThanApproved(supportConceptApprovalPeriod,
cb2sc.CostBearer.CostRatePeriods.MapToNewDCs(),
serviceRecordsInPeriod,
true, true);
AdjustBilledHours(supportConceptApprovalPeriod, srList, cb2sc.CostBearer.CostRatePeriods.MapToNewDCs(),serviceRecordsInPeriod, serviceInvoicePeriod);
var itemList = CreateInvoiceItems(serviceRecordsInPeriod, invoicePeriod, serviceInvoicePeriod.SupportConceptApprovalPeriod, calc);
serviceInvoicePeriod.InvoiceItemList.AddRange(itemList);
@@ -101,6 +98,94 @@ namespace SpitalstiftungKonstanz.Invoicing
}
}
private void AdjustBilledHours(SupportConceptApprovalPeriodDC scap, IList<ServiceRecord> srList, List<CostRatePeriodDC> costRatePeriodDCs, List<ServiceRecordDC> serviceRecordsInPeriod, ServiceInvoicePeriod sip)
{
//Bewilligungen sind meist mehrjährig mit einem Kontingent pro Jahr (innerhalb des Jahres jedoch frei)
if (scap.ApprovedBEInterval.HasValue && scap.ApprovedBEPerInterval.HasValue && scap.ApprovedBEInterval.Value == SupportConceptApprovalInterval.Yearly && scap.IsApprovedBEShifting)
{
Calculations calc = PluginLoader.FindClass<Calculations>(_SpecificID) ?? Calculations.GetInstance(_SpecificID);
DateTime start = scap.StartDate.Value;
if (sip.Start.Value >= start.AddYears(1) && scap.EndDate.Value > start.AddYears(1)) //Festsetzen in welchem Jahr der Bewilligung die Rechnung ist
{
start = start.AddYears(1);
}
if (start < sip.Start.Value && start.AddYears(1) >= sip.End.Value) //Prüfen ob überhaupt schon Zeit in dem Bewilligungsjahr vor der Rechnung vergangen ist, falls ja -> Stunden berücksichtigen
{
var srListDcOld = (from sr in srList
where sr.Start >= start && sr.Start < sip.Start.Value
select MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(sr)).ToList();
List<ServiceRecordDC> serviceRecordsScap = srListDcOld.Where(i =>
{
bool valid = i.Start.Value.InBetween(start, sip.Start.Value, true);
if (valid && scap != null && scap.ServiceCategory != null)
valid = scap.ServiceCategory.ServiceCategoryOid == i.ServiceDescription.Category.ServiceCategoryOid;
return valid;
}).ToList();
var totalDuration = serviceRecordsScap.Sum(s => s.RoundedDuration) / 60;
if (totalDuration != 0)
{
if (scap.ApprovedBEPerInterval < totalDuration)
{
scap.ApprovedBEPerInterval = 0;
}
else
{
scap.ApprovedBEPerInterval -= totalDuration;
}
}
}
//Prüfen ob ggf. noch ein Restkontingent des alten Jahres mit in das Quartal fließt, das hat eine kleine Unschärfe, wenn die Tage nicht genau passen, aber ganz das ist so schon overkill
else if (start.AddYears(1) < sip.End.Value)
{
var srListDcOld = (from sr in srList
where sr.Start >= start && sr.Start <= start.AddYears(1)
select MapperFactory.ServiceRecordDC_ServiceRecord.MapToNewDC(sr)).ToList();
List<ServiceRecordDC> serviceRecordsScap = srListDcOld.Where(i =>
{
bool valid = i.Start.Value.InBetween(start, start.AddYears(1), true);
if (valid && scap != null && scap.ServiceCategory != null)
valid = scap.ServiceCategory.ServiceCategoryOid == i.ServiceDescription.Category.ServiceCategoryOid;
return valid;
}).ToList();
var totalDuration = serviceRecordsScap.Sum(s => s.RoundedDuration) / 60;
if (totalDuration != 0)
{
if (scap.ApprovedBEPerInterval < totalDuration)
{
//do nothing -> Verbleibendes Kontingent = 0 und damit bleibt das scap.ApprovedBEPerInterval unverändert
}
else
{
scap.ApprovedBEPerInterval += totalDuration - scap.ApprovedBEPerInterval.Value;
}
}
}
// ggf. kürzen der aktuellen Einträge
foreach (var iRecord in serviceRecordsInPeriod.ToList())
{
var duration = calc.GetBillableDurationInMinutes(iRecord, false) / 60;
if (scap.ApprovedBEPerInterval == 0)
{
serviceRecordsInPeriod.Remove(iRecord);
continue;
}
if (scap.ApprovedBEPerInterval - duration >= 0)
{
scap.ApprovedBEPerInterval -= duration;
continue;
}
var newDuration = scap.ApprovedBEPerInterval;
scap.ApprovedBEPerInterval = 0;
iRecord.End = iRecord.Start.Value.AddHours(Convert.ToInt32(newDuration));
iRecord.RoundedDuration = newDuration.Value * 60;
}
}
}
public override void CreateFixedAmounts(ServiceInvoicePeriod serviceInvoicePeriod, SupportConceptApprovalPeriodDC supportConceptApprovalPeriod, CostBearer2SupportConcept cb2sc)
{
base.CreateFixedAmounts(serviceInvoicePeriod, supportConceptApprovalPeriod, cb2sc);
@@ -114,7 +199,6 @@ namespace SpitalstiftungKonstanz.Invoicing
}
}
public override InvoiceItem CreateInvoiceItem(ServiceRecordDC iServiceRecord, SupportConceptApprovalPeriod scap, Calculations calc)
{
var ii = base.CreateInvoiceItem(iServiceRecord, scap, calc);