From 73194470610cb0b3b025126cad884187d1428100 Mon Sep 17 00:00:00 2001 From: Alexandra Date: Mon, 20 Jul 2026 16:18:50 +0200 Subject: [PATCH] DomizielAnsbach/ZVBerichtBezirk.cs - Fehler Enddatum ZV im Monat SupportOID=168537 --- ReportImp/DomizielAnsbach/ZVBerichtBezirk.cs | 50 ++++++++++++++++---- 1 file changed, 42 insertions(+), 8 deletions(-) diff --git a/ReportImp/DomizielAnsbach/ZVBerichtBezirk.cs b/ReportImp/DomizielAnsbach/ZVBerichtBezirk.cs index 0b403d8d9..c578472fd 100644 --- a/ReportImp/DomizielAnsbach/ZVBerichtBezirk.cs +++ b/ReportImp/DomizielAnsbach/ZVBerichtBezirk.cs @@ -33,17 +33,43 @@ namespace DomizielAnsbach for (int i = listLength - 1; i >= 0; i--) { var sc = pRO.SupportConceptFinanceList[i]; - if (sc.Costbearer2Supportconcept.ApprovalPeriodList != null && - sc.Costbearer2Supportconcept.ApprovalPeriodList[0].ServiceCategory == null || + if (sc.Costbearer2Supportconcept.ApprovalPeriodList != null && sc.Costbearer2Supportconcept.ApprovalPeriodList[0].ServiceCategory == null || sc.Costbearer2Supportconcept.ApprovalPeriodList[0].ServiceCategory.Name != "Zuverdienst - Arbeitszeit") pRO.SupportConceptFinanceList.Remove(sc); } - pRO.SupportConceptFinanceList = pRO.SupportConceptFinanceList.GroupBy(s => s.Costbearer2Supportconcept.SupportConcept.Customer.CustomerOid).Select(g => g.FirstOrDefault()).ToList(); + var extendedEndByRo = new Dictionary(); + pRO.SupportConceptFinanceList = pRO.SupportConceptFinanceList + .GroupBy(s => s.Costbearer2Supportconcept.SupportConcept.Customer.CustomerOid) + .Select(g => + { + // Pro Kunde nur eine Zeile/ein Block (wie bisher). Hat ein Kunde aber mehrere aufeinanderfolgende HPs, + // wird die frueheste Zuordnung als Repraesentant genommen und das spaeteste EndDate aller Zuordnungen als effektives Ende gemerkt. + var ordered = g.OrderBy(s => s.Costbearer2Supportconcept.StartDate).ToList(); + var rep = ordered.First(); + if (ordered.Count > 1) + { + if (ordered.Any(s => !s.Costbearer2Supportconcept.EndDate.HasValue)) + { + extendedEndByRo[rep] = null; + } + else + { + extendedEndByRo[rep] = ordered.Max(s => s.Costbearer2Supportconcept.EndDate); + } + } + return rep; + }) + .ToList(); listLength = pRO.SupportConceptFinanceList.Count; for (int i = 0; i < listLength; i++) { var sc = pRO.SupportConceptFinanceList[i]; + DateTime? scEndDate; + if (!extendedEndByRo.TryGetValue(sc, out scEndDate)) + { + scEndDate = sc.Costbearer2Supportconcept.EndDate; + } DateTime periodEnd = DateTime.MinValue; cCount += 1; bool firstRow = true; @@ -52,7 +78,7 @@ namespace DomizielAnsbach if (sc.Costbearer2Supportconcept.SupportConcept.Customer.Oid.HasValue) c = DAOFactory.GenericDAO.LoadByID(sc.Costbearer2Supportconcept.SupportConcept.Customer.Oid.Value); - if (sc.Costbearer2Supportconcept.EndDate >= start && sc.Costbearer2Supportconcept.StartDate <= end) + if (scEndDate >= start && sc.Costbearer2Supportconcept.StartDate <= end) { if (sc.Costbearer2Supportconcept.StartDate <= start) monthStart = start; @@ -81,7 +107,7 @@ namespace DomizielAnsbach var ro = new FinanceRO.SupportConceptFinanceRO(); ro.CustomerName = sc.CustomerName; - if (ro.CustomerName.Contains("Rohloff")) + if (ro.CustomerName.Contains("Gruber")) { int tuao = 1; } @@ -97,7 +123,7 @@ namespace DomizielAnsbach ro.ApprovedHours = GetVertraglicheZeit(c, periodEnd, monthStart); } - if (ro.ApprovedHours == 0 && sc.Costbearer2Supportconcept.EndDate < monthEnd && krankEnd <= monthEnd) + if (ro.ApprovedHours == 0 && scEndDate < monthEnd && krankEnd <= monthEnd) { break; } @@ -115,12 +141,20 @@ namespace DomizielAnsbach { if (periodEnd == DateTime.MinValue) periodEnd = monthEnd; - if (sc.Costbearer2Supportconcept.EndDate.HasValue && sc.Costbearer2Supportconcept.EndDate > monthStart && periodEnd > sc.Costbearer2Supportconcept.EndDate) // falls direkt im ersten Monat wieder beendet wird - periodEnd = sc.Costbearer2Supportconcept.EndDate.Value; + if (scEndDate.HasValue && scEndDate > monthStart && periodEnd > scEndDate) // falls direkt im ersten Monat wieder beendet wird + { + periodEnd = scEndDate.Value; + } ro.Custom2 = String.Format("{0:dd.MM.yyyy}", periodEnd); } else + { ro.Custom2 = String.Format("{0:dd.MM.yyyy}", monthEnd); + if (scEndDate.HasValue && scEndDate > monthStart && scEndDate < monthEnd) + { + ro.Custom2 = String.Format("{0:dd.MM.yyyy}", scEndDate.Value); + } + } if (firstRow == true) {