|
|
@@ -554,96 +554,34 @@ public class Module
|
|
|
private List<IBlock> EvaluateOvertime(IEnumerable<IBlock> time, Guid overtimeID)
|
|
|
{
|
|
|
var overtimeIntervals = _overtimeIntervals.GetValueOrDefault(overtimeID)?.ToArray() ?? [];
|
|
|
- var curOvertimeIdx = 0;
|
|
|
- OvertimeInterval? GetOvertimeInterval() => curOvertimeIdx < overtimeIntervals.Length ? overtimeIntervals[curOvertimeIdx] : null;
|
|
|
- var curInterval = GetOvertimeInterval()?.Interval ?? TimeSpan.Zero;
|
|
|
-
|
|
|
var newItems = new List<IBlock>();
|
|
|
- foreach (var block in time)
|
|
|
+ OvertimeUtils.EvaluateOvertime(time, overtimeIntervals, x => x.Duration, (block, interval, duration) =>
|
|
|
{
|
|
|
- var duration = block.Duration;
|
|
|
- while (duration > TimeSpan.Zero)
|
|
|
+ if(interval is null)
|
|
|
{
|
|
|
- var interval = GetOvertimeInterval();
|
|
|
- if (interval != null)
|
|
|
+ // Shouldn't ever occur, thanks to RemainingTime being required.
|
|
|
+ if(block is PaidWorkBlock paid)
|
|
|
{
|
|
|
- switch (interval.IntervalType)
|
|
|
- {
|
|
|
- case OvertimeIntervalType.Interval:
|
|
|
- if (duration >= curInterval)
|
|
|
- {
|
|
|
- // In this case, the paid work block is more than the rest of
|
|
|
- // the current interval, so we use up all the remaining interval
|
|
|
- // time, and then move to the next interval.
|
|
|
- if (interval.IsPaid)
|
|
|
- {
|
|
|
- if(block is PaidWorkBlock paid)
|
|
|
- {
|
|
|
- newItems.Add(new PaidWorkBlock(block.TaskID, curInterval, interval.PayrollID, block.Job, block.TimeSheet));
|
|
|
- }
|
|
|
- else if(block is LeaveBlock leave)
|
|
|
- {
|
|
|
- newItems.Add(new LeaveBlock(leave.PayrollID, curInterval, leave.TimeSheet));
|
|
|
- }
|
|
|
- }
|
|
|
- duration -= curInterval;
|
|
|
- ++curOvertimeIdx;
|
|
|
- curInterval = GetOvertimeInterval()?.Interval ?? TimeSpan.Zero;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // Otherwise, we use up the entire paid work block, and decrease the interval by the duration remaining.
|
|
|
- if (interval.IsPaid)
|
|
|
- {
|
|
|
- if(block is PaidWorkBlock paid)
|
|
|
- {
|
|
|
- newItems.Add(new PaidWorkBlock(block.TaskID, duration, interval.PayrollID, block.Job, block.TimeSheet));
|
|
|
- }
|
|
|
- else if(block is LeaveBlock leave)
|
|
|
- {
|
|
|
- newItems.Add(new LeaveBlock(leave.PayrollID, duration, leave.TimeSheet));
|
|
|
- }
|
|
|
- }
|
|
|
- curInterval -= duration;
|
|
|
- duration = TimeSpan.Zero;
|
|
|
- }
|
|
|
- break;
|
|
|
- case OvertimeIntervalType.RemainingTime:
|
|
|
- // In this case, the interval is unchanged.
|
|
|
- if (interval.IsPaid)
|
|
|
- {
|
|
|
- if(block is PaidWorkBlock paid)
|
|
|
- {
|
|
|
- newItems.Add(new PaidWorkBlock(block.TaskID, duration, interval.PayrollID, block.Job, block.TimeSheet));
|
|
|
- }
|
|
|
- else if(block is LeaveBlock leave)
|
|
|
- {
|
|
|
- newItems.Add(new LeaveBlock(leave.PayrollID, duration, leave.TimeSheet));
|
|
|
- }
|
|
|
- }
|
|
|
- duration = TimeSpan.Zero;
|
|
|
- break;
|
|
|
- default:
|
|
|
- throw new NotImplementedException($"Not implemented Overtime interval type {interval.IntervalType}");
|
|
|
- }
|
|
|
+ newItems.Add(new PaidWorkBlock(block.TaskID, duration, "", block.Job, block.TimeSheet));
|
|
|
}
|
|
|
- else
|
|
|
+ else if(block is LeaveBlock leave)
|
|
|
{
|
|
|
- // If there is no overtime interval, then we use up the rest of the time on
|
|
|
- // the block with a blank PayrollID. Theoretically, this shouldn't happen,
|
|
|
- // since the "RemainingTime" interval is required.
|
|
|
- if(block is PaidWorkBlock paid)
|
|
|
- {
|
|
|
- newItems.Add(new PaidWorkBlock(block.TaskID, duration, "", block.Job, block.TimeSheet));
|
|
|
- }
|
|
|
- else if(block is LeaveBlock leave)
|
|
|
- {
|
|
|
- newItems.Add(new LeaveBlock(leave.PayrollID, duration, leave.TimeSheet));
|
|
|
- }
|
|
|
- duration = TimeSpan.Zero;
|
|
|
+ newItems.Add(new LeaveBlock(leave.PayrollID, duration, leave.TimeSheet));
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ else if (interval.IsPaid)
|
|
|
+ {
|
|
|
+ if (block is PaidWorkBlock paid)
|
|
|
+ {
|
|
|
+ newItems.Add(new PaidWorkBlock(block.TaskID, duration, interval.PayrollID, block.Job, block.TimeSheet));
|
|
|
+ }
|
|
|
+ else if (block is LeaveBlock leave)
|
|
|
+ {
|
|
|
+ newItems.Add(new LeaveBlock(leave.PayrollID, duration, leave.TimeSheet));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
return newItems;
|
|
|
}
|
|
|
|