Skip to content

Commit efc1192

Browse files
author
Jani Giannoudis
committed
payroll function action: refactored lookup access methods
date period: fixed missing init-setter for start/end date updated version to 0.9.0-beta.14
1 parent 2d6aae8 commit efc1192

File tree

6 files changed

+83
-40
lines changed

6 files changed

+83
-40
lines changed

Client.Scripting/DatePeriod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@ public static DatePeriod FromEnd(TimeSpan duration, DateTime end) =>
8585
private bool GetHasEnd() => End != Date.MaxValue;
8686

8787
/// <summary>The period start</summary>
88-
public DateTime Start { get; }
88+
public DateTime Start { get; init; }
8989

9090
/// <summary>Check for start</summary>
9191
public bool HasStart { get; }
9292

9393
/// <summary>The period end</summary>
94-
public DateTime End { get; }
94+
public DateTime End { get; init; }
9595

9696
/// <summary>Check for end</summary>
9797
[JsonIgnore]

Client.Scripting/Function/PayrollFunction.Action.cs

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* PayrollFunction.Action */
22

33
using System;
4-
using System.Collections.Generic;
54
using System.Linq;
5+
using System.Collections.Generic;
66

77
namespace PayrollEngine.Client.Scripting.Function;
88

@@ -36,57 +36,85 @@ public ActionValue GetFieldValue(string field) =>
3636

3737
#region Lookup
3838

39-
/// <summary>Test for lookup value</summary>
39+
/// <summary>Test for lookup value by key or range value</summary>
4040
[ActionParameter("lookup", "The lookup name", [StringType])]
41-
[ActionParameter("key", "The lookup key", [StringType])]
42-
[ActionParameter("range", "The range value", [DecimalType])]
41+
[ActionParameter("keyOrRangeValue", "The lookup key or range value")]
4342
[ActionParameter("field", "The JSON value field name (optional)")]
44-
[CollectorAction("HasLookupValue", "Test for lookup value", "Lookup")]
45-
public bool HasLookupValue(string lookup, string key,
46-
decimal? range = null, string field = null) =>
47-
GetLookupValue(lookup, key, range, field).HasValue;
43+
[CollectorAction("HasLookupValue", "Test for lookup value by key", "Lookup")]
44+
public bool HasLookupValue(string lookup, ActionValue keyOrRangeValue, string field = null) =>
45+
GetLookupValue(lookup, keyOrRangeValue, field).HasValue;
4846

49-
/// <summary>Get lookup value</summary>
47+
/// <summary>Test for lookup value by key and range value</summary>
5048
[ActionParameter("lookup", "The lookup name", [StringType])]
5149
[ActionParameter("key", "The lookup key", [StringType])]
52-
[ActionParameter("range", "The range value", [DecimalType])]
5350
[ActionParameter("field", "The JSON value field name (optional)")]
54-
[CollectorAction("GetLookupValue", "Get range lookup object value", "Lookup")]
55-
public ActionValue GetLookupValue(string lookup, string key,
56-
decimal? range = null, string field = null)
51+
[CollectorAction("HasLookupValue", "Test for lookup value by key and range value", "Lookup")]
52+
public bool HasLookupValue(string lookup, ActionValue key, ActionValue rangeValue, string field = null) =>
53+
GetLookupValue(lookup, key, rangeValue, field).HasValue;
54+
55+
/// <summary>Get lookup value by key or range value</summary>
56+
[ActionParameter("lookup", "The lookup name", [StringType])]
57+
[ActionParameter("keyOrRangeValue", "The lookup key or range value")]
58+
[ActionParameter("field", "The JSON value field name (optional)")]
59+
[CollectorAction("GetLookupValue", "Get lookup value by key or range value", "Lookup")]
60+
public ActionValue GetLookupValue(string lookup, ActionValue keyOrRangeValue, string field = null)
5761
{
5862
// range value
59-
if (range != null)
63+
if (keyOrRangeValue.IsNumeric)
6064
{
61-
// range object lookup
62-
if (!string.IsNullOrWhiteSpace(field))
65+
// basic range lookup value
66+
if (string.IsNullOrWhiteSpace(field))
6367
{
64-
return new ActionValue(GetRangeObjectLookup<object>(
68+
return new(GetRangeLookup<object>(
6569
lookupName: lookup,
66-
rangeValue: range.Value,
67-
lookupKey: key,
68-
objectKey: field));
70+
rangeValue: keyOrRangeValue));
71+
6972
}
70-
// range value lookup
71-
return new ActionValue(GetRangeLookup<object>(
73+
// object field range lookup value
74+
return new(GetRangeObjectLookup<object>(
7275
lookupName: lookup,
73-
lookupKey: key,
74-
rangeValue: range.Value));
76+
rangeValue: keyOrRangeValue,
77+
objectKey: field));
7578
}
7679

77-
// object lookup
78-
if (!string.IsNullOrWhiteSpace(field))
80+
// key
81+
if (string.IsNullOrWhiteSpace(field))
7982
{
80-
return new(GetObjectLookup<object>(
83+
// basic lookup value
84+
return new(GetLookup<object>(
8185
lookupName: lookup,
82-
lookupKey: key,
83-
objectKey: field));
86+
lookupKey: keyOrRangeValue));
8487
}
88+
// object field lookup value
89+
return new(GetObjectLookup<object>(
90+
lookupName: lookup,
91+
lookupKey: keyOrRangeValue,
92+
objectKey: field));
93+
}
8594

86-
// lookup
87-
return new(GetLookup<object>(
95+
/// <summary>Get lookup value by key and range value</summary>
96+
[ActionParameter("lookup", "The lookup name", [StringType])]
97+
[ActionParameter("key", "The lookup key")]
98+
[ActionParameter("rangeValue", "The lookup key or range value")]
99+
[ActionParameter("field", "The JSON value field name (optional)")]
100+
[CollectorAction("GetLookupValue", "Get lookup value by key and value field name", "Lookup")]
101+
public ActionValue GetLookupValue(string lookup, ActionValue key, ActionValue rangeValue, string field = null)
102+
{
103+
// basic range lookup value
104+
if (string.IsNullOrWhiteSpace(field))
105+
{
106+
return new(GetRangeLookup<object>(
107+
lookupName: lookup,
108+
lookupKey: key,
109+
rangeValue: rangeValue));
110+
111+
}
112+
// object field range lookup value
113+
return new(GetRangeObjectLookup<object>(
88114
lookupName: lookup,
89-
lookupKey: key));
115+
lookupKey: key,
116+
rangeValue: rangeValue,
117+
objectKey: field));
90118
}
91119

92120
/// <summary>Apply a range value to the lookup ranges considering the lookup range mode</summary>

Client.Scripting/PayrollEngine.Client.Scripting.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</PropertyGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="PayrollEngine.Client.Core" Version="0.9.0-beta.13" />
17+
<PackageReference Include="PayrollEngine.Client.Core" Version="0.9.0-beta.14" />
1818
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
1919
</ItemGroup>
2020

Client.Scripting/PayrollEngine.Client.Scripting.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,11 +5233,17 @@
52335233
<summary>Get case filed value</summary>
52345234
<param name="field">Object field name</param>
52355235
</member>
5236-
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.HasLookupValue(System.String,System.String,System.Nullable{System.Decimal},System.String)">
5237-
<summary>Test for lookup value</summary>
5236+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.HasLookupValue(System.String,PayrollEngine.Client.Scripting.Function.ActionValue,System.String)">
5237+
<summary>Test for lookup value by key or range value</summary>
52385238
</member>
5239-
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupValue(System.String,System.String,System.Nullable{System.Decimal},System.String)">
5240-
<summary>Get lookup value</summary>
5239+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.HasLookupValue(System.String,PayrollEngine.Client.Scripting.Function.ActionValue,PayrollEngine.Client.Scripting.Function.ActionValue,System.String)">
5240+
<summary>Test for lookup value by key and range value</summary>
5241+
</member>
5242+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupValue(System.String,PayrollEngine.Client.Scripting.Function.ActionValue,System.String)">
5243+
<summary>Get lookup value by key or range value</summary>
5244+
</member>
5245+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupValue(System.String,PayrollEngine.Client.Scripting.Function.ActionValue,PayrollEngine.Client.Scripting.Function.ActionValue,System.String)">
5246+
<summary>Get lookup value by key and range value</summary>
52415247
</member>
52425248
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.ApplyRangeLookupValue(System.String,System.Decimal,System.String)">
52435249
<summary>Apply a range value to the lookup ranges considering the lookup range mode</summary>

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
5-
<Version>0.9.0-beta.13</Version>
5+
<Version>0.9.0-beta.14</Version>
66
<FileVersion>0.9.0</FileVersion>
77
<InformationalVersion></InformationalVersion>
88
<Authors>Jani Giannoudis</Authors>

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ The following values can be referenced when performing actions:
9292
<sup>3)</sup> Value is saved in the payroll results.<br/>
9393
<sup>4)</sup> Value for the current payroll `Period` (default) and payroll `Cycle` (e.g., year-to-date).<br/>
9494

95+
There are different ways to reference a lookup value: by value `key`, and/or by `rangeValue` and the JSON `field` name:
96+
- `^#LookupName(key)`
97+
- `^#LookupName(key, field)`
98+
- `^#LookupName(rangeValue)`
99+
- `^#LookupName(rangeValue, field)`
100+
- `^#LookupName(key, rangeValue)`
101+
- `^#LookupName(key, rangeValue, field)`
102+
103+
95104
### Action Value
96105
The following value types can be used in actions:
97106
- `String`

0 commit comments

Comments
 (0)