Skip to content

Commit

Permalink
Use the most "more free" rules in work schedules
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzaczek committed Oct 18, 2021
1 parent 7795a3f commit 15d8c0f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions Zetbox.App.Projekte.Common/Calendar/WorkScheduleActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,35 @@ private static decimal Calc(WorkSchedule obj, DateTime from, DateTime until, Cal
{
WorkScheduleRule foundRule = null;
// Find YearlyRule
foundRule = rules.OfType<YearlyWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
var yearlyRule = rules.OfType<YearlyWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
// Find DayOfWeekRule
if (foundRule == null)
var dayOfWeekRule = rules.OfType<DayOfWeekWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));

if (yearlyRule == null)
{
foundRule = dayOfWeekRule;
}
else if(dayOfWeekRule != null)
{
// Use the most "free" rule
if (dayOfWeekRule.IsWorkingDay == false || dayOfWeekRule.WorkingHours < yearlyRule.WorkingHours)
{
foundRule = dayOfWeekRule;
}
else
{
// use the more specific rule
foundRule = yearlyRule;
}
}
else
{
foundRule = rules.OfType<DayOfWeekWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
foundRule = yearlyRule;
}
// Find CommonRule

if (foundRule == null)
{
// Find CommonRule
foundRule = rules.OfType<CommonWorkScheduleRule>().FirstOrDefault(r => r.AppliesTo(from));
}

Expand Down

0 comments on commit 15d8c0f

Please sign in to comment.