From cab3cc6dd6ac14ff99962634511f8bb7b54513a2 Mon Sep 17 00:00:00 2001 From: Alexandra Date: Mon, 21 Oct 2024 14:53:46 +0200 Subject: [PATCH] =?UTF-8?q?SpitalstiftungKonstanz/Invoicing/CustomInvoiceC?= =?UTF-8?q?reation.cs=20-=20Ber=C3=BCcksichtigung=20der=20j=C3=A4hrlichen?= =?UTF-8?q?=20Kontingente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Invoicing/CustomInvoiceCreation.cs | 100 ++++++++++++++++-- 1 file changed, 92 insertions(+), 8 deletions(-) diff --git a/ReportImp/SpitalstiftungKonstanz/Invoicing/CustomInvoiceCreation.cs b/ReportImp/SpitalstiftungKonstanz/Invoicing/CustomInvoiceCreation.cs index 6f9d7db65..b89ec0c04 100644 --- a/ReportImp/SpitalstiftungKonstanz/Invoicing/CustomInvoiceCreation.cs +++ b/ReportImp/SpitalstiftungKonstanz/Invoicing/CustomInvoiceCreation.cs @@ -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 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 srList, List costRatePeriodDCs, List 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(_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 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 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);