Skip to content

Commit cbbf8f9

Browse files
author
Jani Giannoudis
committed
added calendar extension methods for work days
updated version to 0.9.0-beta.4
1 parent 2242707 commit cbbf8f9

File tree

9 files changed

+421
-68
lines changed

9 files changed

+421
-68
lines changed

Client.Services/PayrollEngine.Client.Services.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
18-
<PackageReference Include="PayrollEngine.Client.Scripting" Version="0.9.0-beta.3" />
19-
<PackageReference Include="PayrollEngine.Client.Test" Version="0.9.0-beta.3" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.3" />
18+
<PackageReference Include="PayrollEngine.Client.Scripting" Version="0.9.0-beta.4" />
19+
<PackageReference Include="PayrollEngine.Client.Test" Version="0.9.0-beta.4" />
2020
</ItemGroup>
2121

2222
<!-- include xml documention files and json schemas to the nuget package -->

Client.Services/PayrollEngine.Client.Services.xml

Lines changed: 84 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using PayrollEngine.Client.Model;
4+
5+
namespace PayrollEngine.Client.Scripting.Runtime.Api;
6+
7+
/// <summary>
8+
/// Extension methods for the <see cref="Model.Calendar"/>
9+
/// </summary>
10+
/// <remarks>Duplicate of the backend calendar extension (no holiday support)</remarks>
11+
public static class CalendarExtensions
12+
{
13+
/// <summary>Test for working days</summary>
14+
/// <param name="calendar">The payroll calendar</param>
15+
/// <param name="moment">Test day</param>
16+
/// <returns>Returns true for valid time units</returns>
17+
public static bool IsWorkDay(this Calendar calendar, DateTime moment)
18+
{
19+
// week mode
20+
if (calendar.WeekMode == CalendarWeekMode.Week)
21+
{
22+
return true;
23+
}
24+
25+
// work week
26+
return (DayOfWeek)moment.DayOfWeek switch
27+
{
28+
DayOfWeek.Sunday => calendar.WorkSunday,
29+
DayOfWeek.Monday => calendar.WorkMonday,
30+
DayOfWeek.Tuesday => calendar.WorkThursday,
31+
DayOfWeek.Wednesday => calendar.WorkWednesday,
32+
DayOfWeek.Thursday => calendar.WorkThursday,
33+
DayOfWeek.Friday => calendar.WorkFriday,
34+
DayOfWeek.Saturday => calendar.WorkSaturday,
35+
_ => calendar.WorkSunday
36+
};
37+
}
38+
39+
/// <summary>Get previous working days</summary>
40+
/// <param name="calendar">The payroll calendar</param>
41+
/// <param name="moment">The start moment (not included in results)</param>
42+
/// <param name="count">The number of days (default: 1)</param>
43+
/// <returns>Returns true for valid time units</returns>
44+
public static List<DateTime> GetPreviousWorkDays(this Calendar calendar, DateTime moment, int count = 1)
45+
{
46+
var days = new List<DateTime>();
47+
for (var i = 0; i < count; i++)
48+
{
49+
var day = moment.AddDays(-i).Date;
50+
if (IsWorkDay(calendar, day))
51+
{
52+
days.Add(day);
53+
}
54+
}
55+
return days;
56+
}
57+
58+
/// <summary>Get next working days</summary>
59+
/// <param name="calendar">The payroll calendar</param>
60+
/// <param name="moment">The start moment (not included in results)</param>
61+
/// <param name="count">The number of days (default: 1)</param>
62+
/// <returns>Returns true for valid time units</returns>
63+
public static List<DateTime> GetNextWorkDays(this Calendar calendar, DateTime moment, int count = 1)
64+
{
65+
var days = new List<DateTime>();
66+
for (var i = 0; i < count; i++)
67+
{
68+
var day = moment.AddDays(i).Date;
69+
if (IsWorkDay(calendar, day))
70+
{
71+
days.Add(day);
72+
}
73+
}
74+
return days;
75+
}
76+
}

Client.Services/Scripting.Runtime.Api/CaseChangeRuntimeBase.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,22 @@ protected CaseSet GetCaseSet(string caseName)
9191
new(TenantId, PayrollId), caseName, UserId, EmployeeId).Result;
9292
}
9393

94+
/// <inheritdoc />
95+
public string GetReason() =>
96+
Case.Reason;
97+
98+
/// <inheritdoc />
99+
public void SetReason(string reason) =>
100+
Case.Reason = reason;
101+
102+
/// <inheritdoc />
103+
public string GetForecast() =>
104+
Case.Forecast;
105+
106+
/// <inheritdoc />
107+
public void SetForecast(string forecast) =>
108+
Case.Forecast = forecast;
109+
94110
#endregion
95111

96112
#region Case Fields
@@ -143,6 +159,10 @@ public void InitStart(string caseFieldName, DateTime? start)
143159
caseFieldSet.Start ??= start;
144160
}
145161

162+
/// <inheritdoc />
163+
public bool MandatoryEnd(string caseFieldName) =>
164+
GetCaseFieldSet(caseFieldName).EndMandatory;
165+
146166
/// <inheritdoc />
147167
public bool HasEnd(string caseFieldName) =>
148168
GetCaseFieldSet(caseFieldName).End != null;
@@ -162,6 +182,10 @@ public void InitEnd(string caseFieldName, DateTime? end)
162182
caseFieldSet.End ??= end;
163183
}
164184

185+
/// <inheritdoc />
186+
public bool MandatoryValue(string caseFieldName) =>
187+
GetCaseFieldSet(caseFieldName).ValueMandatory;
188+
165189
/// <inheritdoc />
166190
public int GetValueType(string caseFieldName) =>
167191
(int)GetCaseFieldSet(caseFieldName).ValueType;

Client.Services/Scripting.Runtime.Api/PayrollRuntime.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ public virtual List<string> GetCaseValueSlots(string caseFieldName)
303303
/// <inheritdoc />
304304
public virtual List<string> GetCaseValueTags(string caseFieldName, DateTime valueDate)
305305
{
306-
var caseValue = GetTimeCaseValue(caseFieldName, valueDate).Result;
306+
var caseValue = GetCaseTimeCaseValue(caseFieldName, valueDate).Result;
307307
return caseValue == null ? [] : caseValue.Tags;
308308
}
309309

310310
/// <inheritdoc />
311311
public virtual Tuple<string, DateTime, Tuple<DateTime?, DateTime?>, object, DateTime?, List<string>, Dictionary<string, object>> GetCaseValue(
312312
string caseFieldName, DateTime valueDate)
313313
{
314-
var caseValue = GetTimeCaseValue(caseFieldName, valueDate).Result;
314+
var caseValue = GetCaseTimeCaseValue(caseFieldName, valueDate).Result;
315315
if (caseValue == null)
316316
{
317317
return null;
@@ -325,7 +325,7 @@ public virtual List<string> GetCaseValueTags(string caseFieldName, DateTime valu
325325
caseValue.Attributes);
326326
}
327327

328-
private async Task<Model.CaseValue> GetTimeCaseValue(string caseFieldName, DateTime valueDate)
328+
private async Task<Model.CaseValue> GetCaseTimeCaseValue(string caseFieldName, DateTime valueDate)
329329
{
330330
var context = new PayrollServiceContext(TenantId, PayrollId);
331331

@@ -337,7 +337,7 @@ public virtual List<string> GetCaseValueTags(string caseFieldName, DateTime valu
337337
}
338338

339339
// case
340-
var caseValue = (await PayrollService.GetTimeValuesAsync(context, EmployeeId, [caseFieldName],
340+
var caseValue = (await PayrollService.GetCaseTimeValuesAsync(context, EmployeeId, [caseFieldName],
341341
valueDate, RegulationDate, EvaluationDate)).FirstOrDefault();
342342
return caseValue;
343343
}
@@ -359,8 +359,15 @@ public virtual List<string> GetCaseValueTags(string caseFieldName, DateTime valu
359359

360360
// case value periods
361361
var caseRef = new CaseValueReference(caseFieldName);
362-
var valuePeriods = PayrollService.GetCaseValuesAsync(new(TenantId, PayrollId),
363-
startDate.Value, endDate.Value, [caseRef.CaseFieldName], EmployeeId, caseRef.CaseSlot).Result;
362+
var valuePeriods = PayrollService.GetCaseValuesAsync(
363+
context: new(TenantId, PayrollId),
364+
startDate: startDate.Value,
365+
endDate: endDate.Value,
366+
caseFieldNames: [caseRef.CaseFieldName],
367+
employeeId: EmployeeId,
368+
regulationDate: RegulationDate,
369+
evaluationDate: EvaluationDate,
370+
caseSlot: caseRef.CaseSlot).Result;
364371

365372
// tuple build
366373
var values = new List<Tuple<string, DateTime, Tuple<DateTime?, DateTime?>, object, DateTime?, List<string>, Dictionary<string, object>>>();

Client.Services/Scripting.Runtime.Api/ReportBuildRuntime.cs

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,6 @@ public ReportBuildRuntime(PayrollHttpClient httpClient, int tenantId,
2727
public void SetParameter(string parameterName, string value) =>
2828
SetParameterInternal(parameterName, value);
2929

30-
/// <inheritdoc />
31-
public void SetParameterAttribute(string parameterName, string attributeName, object value)
32-
{
33-
if (string.IsNullOrWhiteSpace(parameterName))
34-
{
35-
throw new ArgumentException(nameof(parameterName));
36-
}
37-
if (string.IsNullOrWhiteSpace(attributeName))
38-
{
39-
throw new ArgumentException(nameof(attributeName));
40-
}
41-
42-
// report parameter
43-
if (Report.Parameters == null)
44-
{
45-
throw new ArgumentException($"Invalid report parameter {parameterName}.");
46-
}
47-
var reportParameter = Report.Parameters.FirstOrDefault(x => string.Equals(x.Name, parameterName));
48-
if (reportParameter == null)
49-
{
50-
throw new ArgumentException($"Unknown report parameter {parameterName}.");
51-
}
52-
53-
// add/change attribute
54-
if (value != null)
55-
{
56-
reportParameter.Attributes ??= new();
57-
reportParameter.Attributes[attributeName] = value;
58-
}
59-
else
60-
{
61-
// remove attribute
62-
if (reportParameter.Attributes != null && reportParameter.Attributes.ContainsKey(attributeName))
63-
{
64-
reportParameter.Attributes.Remove(attributeName);
65-
}
66-
}
67-
}
68-
6930
/// <inheritdoc />
7031
public void SetParameterHidden(string parameterName, bool hidden)
7132
{

0 commit comments

Comments
 (0)