367 lines
14 KiB
C#
367 lines
14 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BeWo.Data.Access;
|
|
using BeWo.Data.Entities;
|
|
using BeWo.Report.ReportObjects;
|
|
using BeWo.Service.Dienstplanung;
|
|
using BS.Shared.Core;
|
|
|
|
namespace BeWo.SeWo
|
|
{
|
|
public class StundenBerechnungHelper
|
|
{
|
|
public static void CorrectOverlappingTimes(FLSReportRO pRO)
|
|
{
|
|
foreach (var group in pRO.FLSReportGroups)
|
|
{
|
|
List<FLSReportRO.FLSReportServiceRecord> oldRecords = new List<FLSReportRO.FLSReportServiceRecord>();
|
|
|
|
if (group.ServiceRecords != null && group.ServiceRecords.Count > 0)
|
|
{
|
|
CorrectOverlappingTimesForServiceRecords(group.ServiceRecords, oldRecords);
|
|
}
|
|
else
|
|
{
|
|
foreach (var detail in group.FLSReportDetails)
|
|
{
|
|
CorrectOverlappingTimesForServiceRecords(detail.ServiceRecords, oldRecords);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
public static decimal BerechnePausenZeit(List<FLSReportRO.FLSReportServiceRecord> serviceRecords)
|
|
{
|
|
decimal pausenZeit = 0;
|
|
|
|
List<FLSReportRO.FLSReportServiceRecord> pausen = new List<FLSReportRO.FLSReportServiceRecord>();
|
|
List<FLSReportRO.FLSReportServiceRecord> nichtpausen = new List<FLSReportRO.FLSReportServiceRecord>();
|
|
|
|
foreach (var sr in serviceRecords)
|
|
{
|
|
if (sr.ServiceDescription == "Pause")
|
|
{
|
|
pausen.Add(sr);
|
|
}
|
|
else
|
|
{
|
|
nichtpausen.Add(sr);
|
|
}
|
|
}
|
|
|
|
foreach (var pause in pausen)
|
|
{
|
|
foreach (var arbeitszeit in nichtpausen)
|
|
{
|
|
var pauseSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = pause.Start.Value,
|
|
EndDateTime = pause.Start.Value.AddMinutes((double)pause.RoundedDuration)
|
|
};
|
|
|
|
var arbeitszeitSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = arbeitszeit.Start.Value,
|
|
EndDateTime = arbeitszeit.Start.Value.AddMinutes((double)arbeitszeit.RoundedDuration)
|
|
};
|
|
|
|
|
|
if (pauseSpan.Overlaps(arbeitszeitSpan))
|
|
{
|
|
DateTime startUeberlappung = pauseSpan.StartDateTime;
|
|
if (arbeitszeitSpan.StartDateTime > startUeberlappung)
|
|
startUeberlappung = arbeitszeitSpan.StartDateTime;
|
|
|
|
DateTime endUeberlappung = pauseSpan.EndDateTime;
|
|
|
|
if (arbeitszeitSpan.EndDateTime < endUeberlappung)
|
|
endUeberlappung = arbeitszeitSpan.EndDateTime;
|
|
|
|
var overlapping = (decimal)endUeberlappung.Subtract(startUeberlappung).TotalMinutes;
|
|
|
|
pausenZeit += overlapping;
|
|
}
|
|
}
|
|
}
|
|
return pausenZeit;
|
|
}
|
|
|
|
internal static void CorrectOverlappingTimes(IList<StundenkontoServiceRecord> serviceRecords)
|
|
{
|
|
var oldRecords = new List<StundenkontoServiceRecord>();
|
|
|
|
foreach (var newRecord in serviceRecords)
|
|
{
|
|
if (newRecord.Start.Second > 0)
|
|
{
|
|
continue;
|
|
}
|
|
if (newRecord.ServiceDescription.Name == "Pause")
|
|
{
|
|
continue;
|
|
}
|
|
bool isGroup = false;
|
|
var minuten = newRecord.RoundedDuration;
|
|
if (newRecord.GroupRoundedDuration.HasValue)
|
|
{
|
|
minuten = newRecord.GroupRoundedDuration.Value;
|
|
isGroup = true;
|
|
}
|
|
var newSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = newRecord.Start,
|
|
EndDateTime = newRecord.Start.AddMinutes((double)minuten)
|
|
};
|
|
|
|
foreach (var oldRecord in oldRecords)
|
|
{
|
|
var oldSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = oldRecord.Start,
|
|
EndDateTime = oldRecord.Start.AddMinutes((double) oldRecord.RoundedDuration)
|
|
};
|
|
if (oldRecord.GroupRoundedDuration.HasValue)
|
|
{
|
|
oldSpan.EndDateTime = oldRecord.Start.AddMinutes((double) oldRecord.GroupRoundedDuration);
|
|
}
|
|
|
|
if (oldSpan.Overlaps(newSpan))
|
|
{
|
|
DateTime start = newSpan.StartDateTime;
|
|
if (oldSpan.StartDateTime > start)
|
|
start = oldSpan.StartDateTime;
|
|
|
|
DateTime end = newSpan.EndDateTime;
|
|
|
|
if (oldSpan.EndDateTime < end)
|
|
end = oldSpan.EndDateTime;
|
|
|
|
|
|
if (newSpan.StartDateTime >= oldSpan.StartDateTime)
|
|
{
|
|
newSpan.StartDateTime = oldSpan.EndDateTime;
|
|
if (newSpan.StartDateTime > newSpan.EndDateTime)
|
|
{
|
|
newSpan.StartDateTime = newSpan.EndDateTime;
|
|
}
|
|
newRecord.Start = newSpan.StartDateTime;
|
|
newRecord.End = newSpan.EndDateTime;
|
|
|
|
if (!isGroup)
|
|
{
|
|
newRecord.RoundedDuration =
|
|
(decimal) newRecord.End.Subtract(newRecord.Start).TotalMinutes;
|
|
}
|
|
else
|
|
{
|
|
newRecord.GroupRoundedDuration = (decimal)newRecord.End.Subtract(newRecord.Start).TotalMinutes;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
oldSpan.StartDateTime = newSpan.EndDateTime;
|
|
if (oldSpan.StartDateTime > oldSpan.EndDateTime)
|
|
{
|
|
oldSpan.StartDateTime = oldSpan.EndDateTime;
|
|
}
|
|
oldRecord.Start= oldSpan.StartDateTime;
|
|
oldRecord.End = oldSpan.EndDateTime;
|
|
|
|
|
|
if (!isGroup)
|
|
{
|
|
oldRecord.RoundedDuration = (decimal)oldRecord.End.Subtract(oldRecord.Start).TotalMinutes;
|
|
}
|
|
else
|
|
{
|
|
oldRecord.GroupRoundedDuration = (decimal)oldRecord.End.Subtract(oldRecord.Start).TotalMinutes;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
oldRecords.Add(newRecord);
|
|
|
|
}
|
|
}
|
|
|
|
internal static void CorrectOverlappingTimes2(IList<ServiceRecord> serviceRecords)
|
|
{
|
|
List<ServiceRecord> oldRecords = new List<ServiceRecord>();
|
|
|
|
foreach (var newRecord in serviceRecords)
|
|
{
|
|
if (newRecord.Start.HasValue && newRecord.Start.Value.Second > 0)
|
|
{
|
|
continue;
|
|
}
|
|
if (newRecord.ServiceDescription.Name == "Pause")
|
|
{
|
|
continue;
|
|
}
|
|
bool isGroup = false;
|
|
var minuten = newRecord.RoundedDuration;
|
|
if (newRecord.GroupRoundedDuration.HasValue)
|
|
{
|
|
minuten = newRecord.GroupRoundedDuration.Value;
|
|
isGroup = true;
|
|
}
|
|
var newSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = newRecord.Start.Value,
|
|
EndDateTime = newRecord.Start.Value.AddMinutes((double)minuten)
|
|
};
|
|
|
|
foreach (var oldRecord in oldRecords)
|
|
{
|
|
var oldSpan = new DateTimeSpan
|
|
{
|
|
StartDateTime = oldRecord.Start.Value,
|
|
EndDateTime = oldRecord.Start.Value.AddMinutes((double)oldRecord.RoundedDuration)
|
|
};
|
|
if (oldRecord.GroupRoundedDuration.HasValue)
|
|
{
|
|
oldSpan.EndDateTime = oldRecord.Start.Value.AddMinutes((double)oldRecord.GroupRoundedDuration);
|
|
}
|
|
|
|
if (oldSpan.Overlaps(newSpan))
|
|
{
|
|
DateTime start = newSpan.StartDateTime;
|
|
if (oldSpan.StartDateTime > start)
|
|
start = oldSpan.StartDateTime;
|
|
|
|
DateTime end = newSpan.EndDateTime;
|
|
|
|
if (oldSpan.EndDateTime < end)
|
|
end = oldSpan.EndDateTime;
|
|
|
|
|
|
if (newSpan.StartDateTime >= oldSpan.StartDateTime)
|
|
{
|
|
newSpan.StartDateTime = oldSpan.EndDateTime;
|
|
if (newSpan.StartDateTime > newSpan.EndDateTime)
|
|
{
|
|
newSpan.StartDateTime = newSpan.EndDateTime;
|
|
}
|
|
newRecord.Start = newSpan.StartDateTime;
|
|
newRecord.End = newSpan.EndDateTime;
|
|
|
|
if (!isGroup)
|
|
{
|
|
newRecord.RoundedDuration =
|
|
(decimal)newRecord.End.Value.Subtract(newRecord.Start.Value).TotalMinutes;
|
|
}
|
|
else
|
|
{
|
|
newRecord.GroupRoundedDuration = (decimal)newRecord.End.Value.Subtract(newRecord.Start.Value).TotalMinutes;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
oldSpan.StartDateTime = newSpan.EndDateTime;
|
|
if (oldSpan.StartDateTime > oldSpan.EndDateTime)
|
|
{
|
|
oldSpan.StartDateTime = oldSpan.EndDateTime;
|
|
}
|
|
oldRecord.Start = oldSpan.StartDateTime;
|
|
oldRecord.End = oldSpan.EndDateTime;
|
|
|
|
|
|
if (!isGroup)
|
|
{
|
|
oldRecord.RoundedDuration = (decimal)oldRecord.End.Value.Subtract(oldRecord.Start.Value).TotalMinutes;
|
|
}
|
|
else
|
|
{
|
|
oldRecord.GroupRoundedDuration = (decimal)oldRecord.End.Value.Subtract(oldRecord.Start.Value).TotalMinutes;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
oldRecords.Add(newRecord);
|
|
|
|
}
|
|
}
|
|
private static void CorrectOverlappingTimesForServiceRecords(List<FLSReportRO.FLSReportServiceRecord> serviceRecords, List<FLSReportRO.FLSReportServiceRecord> oldRecords)
|
|
{
|
|
foreach (var newRecord in serviceRecords)
|
|
{
|
|
if (newRecord.Start.HasValue && newRecord.Start.Value.Second > 0)
|
|
{
|
|
continue;
|
|
}
|
|
if (newRecord.ServiceDescription == "Pause")
|
|
{
|
|
continue;
|
|
}
|
|
var minuten = newRecord.RoundedDuration;
|
|
var newSpan = new DateTimeSpan { StartDateTime = newRecord.Start.Value, EndDateTime = newRecord.Start.Value.AddMinutes((double)minuten) };
|
|
|
|
foreach (var oldRecord in oldRecords)
|
|
{
|
|
var oldSpan = new DateTimeSpan { StartDateTime = oldRecord.Start.Value, EndDateTime = oldRecord.Start.Value.AddMinutes((double)oldRecord.RoundedDuration) };
|
|
|
|
if (oldSpan.Overlaps(newSpan))
|
|
{
|
|
DateTime start = newSpan.StartDateTime;
|
|
if (oldSpan.StartDateTime > start)
|
|
start = oldSpan.StartDateTime;
|
|
|
|
DateTime end = newSpan.EndDateTime;
|
|
|
|
if (oldSpan.EndDateTime < end)
|
|
end = oldSpan.EndDateTime;
|
|
|
|
var overlapping = (decimal)end.Subtract(start).TotalMinutes;
|
|
|
|
if (newSpan.StartDateTime >= oldSpan.StartDateTime)
|
|
{
|
|
newSpan.StartDateTime = oldSpan.EndDateTime;
|
|
if (newSpan.StartDateTime > newSpan.EndDateTime)
|
|
{
|
|
newSpan.StartDateTime = newSpan.EndDateTime;
|
|
}
|
|
newRecord.StartTime = newSpan.StartDateTime;
|
|
newRecord.Start = newRecord.StartTime;
|
|
newRecord.EndTime = newSpan.EndDateTime;
|
|
|
|
|
|
//Einträge ohne Startdatum testen
|
|
|
|
newRecord.RoundedDuration = (decimal)newRecord.EndTime.Value.Subtract(newRecord.StartTime.Value).TotalMinutes;
|
|
}
|
|
else
|
|
{
|
|
oldSpan.StartDateTime = newSpan.EndDateTime;
|
|
if (oldSpan.StartDateTime > oldSpan.EndDateTime)
|
|
{
|
|
oldSpan.StartDateTime = oldSpan.EndDateTime;
|
|
}
|
|
oldRecord.StartTime = oldSpan.StartDateTime;
|
|
oldRecord.Start = oldRecord.StartTime;
|
|
oldRecord.EndTime = oldSpan.EndDateTime;
|
|
|
|
|
|
|
|
oldRecord.RoundedDuration = (decimal)oldRecord.EndTime.Value.Subtract(oldRecord.StartTime.Value).TotalMinutes;
|
|
}
|
|
|
|
}
|
|
}
|
|
oldRecords.Add(newRecord);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|