Skip to content

Commit 3f278ba

Browse files
author
Jani Giannoudis
committed
payroll function: added acces to the lookup range bracktes
payroll function: added access to threshold lookup backet using a range value payroll function: added access to progressive lookup bracktes using a range value updated version to 0.9.0-beta.16
1 parent 9b91af3 commit 3f278ba

File tree

8 files changed

+152
-8
lines changed

8 files changed

+152
-8
lines changed

Client.Scripting/ClientScript.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,40 @@ public sealed class WageTypeResultActionAttribute(string name, string descriptio
583583
WageTypeActionAttribute(name, description, categories);
584584

585585
#endregion
586+
587+
#region Lookup
588+
589+
/// <summary>
590+
/// A lookup range bracket with computed bounds
591+
/// </summary>
592+
public class LookupRangeBracket
593+
{
594+
/// <summary>The lookup value key</summary>
595+
public string Key { get; set; }
596+
597+
/// <summary>The lookup value as JSON</summary>
598+
public string Value { get; set; }
599+
600+
/// <summary>The range start value</summary>
601+
public decimal RangeStart { get; set; }
602+
603+
/// <summary>The range end value (unbound bracket: Decimal.MaxValue)</summary>
604+
public decimal RangeEnd { get; set; }
605+
606+
/// <summary>The original range value from the lookup value</summary>
607+
/// <remarks>
608+
/// For threshold lookups, the value within the matching bracket is displayed.
609+
/// For progressive lookups, it is the sum of all the matching brackets, excluding the final one, which has its own value.
610+
/// For all other lookup types, the value is null.
611+
/// </remarks>
612+
public decimal? RangeValue { get; set; }
613+
614+
/// <summary>Test for unlimited bracket</summary>
615+
public bool IsUnlimited => RangeEnd == Decimal.MaxValue;
616+
617+
/// <inheritdoc/>
618+
public override string ToString() =>
619+
$"{Key}: {RangeStart} - {RangeEnd}";
620+
}
621+
622+
#endregion

Client.Scripting/Extensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Text.Json;
77
using System.Globalization;
88
using System.Collections.Generic;
9+
//using PayrollEngine.Client.Scripting.Function;
910

1011
namespace PayrollEngine.Client.Scripting;
1112

@@ -2479,4 +2480,20 @@ public static List<WageTypeCustomResult> TupleToWageTypeCustomResults(
24792480
Attributes = x.Item7
24802481
})
24812482
];
2483+
2484+
/// <summary>Convert tuple values to a wage type custom result</summary>
2485+
/// <param name="brackets">The lookup brackets</param>
2486+
/// <returns>The lookup brackets</returns>
2487+
public static List<LookupRangeBracket> TupleToLookupRangeBracketList(
2488+
List<Tuple<string, string, decimal, decimal, decimal?>> brackets) =>
2489+
[
2490+
..brackets.Select(x => new LookupRangeBracket
2491+
{
2492+
Key = x.Item1,
2493+
Value = x.Item2,
2494+
RangeStart = x.Item3,
2495+
RangeEnd = x.Item4,
2496+
RangeValue = x.Item5
2497+
})
2498+
];
24822499
}

Client.Scripting/Function/PayrollFunction.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,27 @@ public T GetObjectLookup<T>(string lookupName, string objectKey,
976976
var value = GetLookup<string>(lookupName, lookupKey, culture);
977977
return string.IsNullOrWhiteSpace(value) ? default : value.ObjectValueJson<T>(objectKey);
978978
}
979+
980+
/// <summary>Get payroll lookup range brackets</summary>
981+
/// <param name="lookupName">The name of the lookup</param>
982+
/// <param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
983+
/// <returns>List of lookup range brackets</returns>
984+
public List<LookupRangeBracket> GetLookupRanges(string lookupName, decimal? rangeValue = null) =>
985+
TupleExtensions.TupleToLookupRangeBracketList(Runtime.GetLookupRanges(lookupName, rangeValue));
986+
987+
/// <summary>Get threshold lookup range bracket</summary>
988+
/// <param name="lookupName">The name of the lookup</param>
989+
/// <param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
990+
/// <returns>Matching threshold bracket, null on missing range</returns>
991+
public LookupRangeBracket GetLookupThresholdRange(string lookupName, decimal rangeValue) =>
992+
GetLookupRanges(lookupName, rangeValue).FirstOrDefault(x => x.RangeValue.HasValue);
993+
994+
/// <summary>Get progressive lookup range brackets</summary>
995+
/// <param name="lookupName">The name of the lookup</param>
996+
/// <param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
997+
/// <returns>Matching progressive brackets</returns>
998+
public List<LookupRangeBracket> GetLookupProgressiveRanges(string lookupName, decimal rangeValue) =>
999+
GetLookupRanges(lookupName, rangeValue).Where(x => x.RangeValue.HasValue).ToList();
9791000

9801001
/// <summary>Get lookup by range value</summary>
9811002
/// <param name="lookupName">The lookup name</param>

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.15" />
17+
<PackageReference Include="PayrollEngine.Client.Core" Version="0.9.0-beta.16" />
1818
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />
1919
</ItemGroup>
2020

Client.Scripting/PayrollEngine.Client.Scripting.xml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,37 @@
972972
<param name="description">The action description</param>
973973
<param name="categories">The action categories</param>
974974
</member>
975+
<member name="T:PayrollEngine.Client.Scripting.LookupRangeBracket">
976+
<summary>
977+
A lookup range bracket with computed bounds
978+
</summary>
979+
</member>
980+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.Key">
981+
<summary>The lookup value key</summary>
982+
</member>
983+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.Value">
984+
<summary>The lookup value as JSON</summary>
985+
</member>
986+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.RangeStart">
987+
<summary>The range start value</summary>
988+
</member>
989+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.RangeEnd">
990+
<summary>The range end value (unbound bracket: Decimal.MaxValue)</summary>
991+
</member>
992+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.RangeValue">
993+
<summary>The original range value from the lookup value</summary>
994+
<remarks>
995+
For threshold lookups, the value within the matching bracket is displayed.
996+
For progressive lookups, it is the sum of all the matching brackets, excluding the final one, which has its own value.
997+
For all other lookup types, the value is null.
998+
</remarks>
999+
</member>
1000+
<member name="P:PayrollEngine.Client.Scripting.LookupRangeBracket.IsUnlimited">
1001+
<summary>Test for unlimited bracket</summary>
1002+
</member>
1003+
<member name="M:PayrollEngine.Client.Scripting.LookupRangeBracket.ToString">
1004+
<inheritdoc/>
1005+
</member>
9751006
<member name="T:PayrollEngine.Client.Scripting.Date">
9761007
<summary>Date specifications</summary>
9771008
</member>
@@ -3096,6 +3127,11 @@
30963127
<param name="values">The tuple values</param>
30973128
<returns>The wage type custom results</returns>
30983129
</member>
3130+
<member name="M:PayrollEngine.Client.Scripting.TupleExtensions.TupleToLookupRangeBracketList(System.Collections.Generic.List{System.Tuple{System.String,System.String,System.Decimal,System.Decimal,System.Nullable{System.Decimal}}})">
3131+
<summary>Convert tuple values to a wage type custom result</summary>
3132+
<param name="brackets">The lookup brackets</param>
3133+
<returns>The lookup brackets</returns>
3134+
</member>
30993135
<member name="T:PayrollEngine.Client.Scripting.TupleExtensions.&lt;G&gt;$049E3D7DB88CCD9F9A84BC340C1323AF.&lt;M&gt;$E742679868AB1797ED468CA6BCB2BCAC">
31003136
<param name="values">The tuple values</param>
31013137
</member>
@@ -5931,6 +5967,24 @@
59315967
<param name="lookupKey">The lookup key (optional)</param>
59325968
<param name="culture">The culture, null for the system culture (optional)</param>
59335969
</member>
5970+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupRanges(System.String,System.Nullable{System.Decimal})">
5971+
<summary>Get payroll lookup range brackets</summary>
5972+
<param name="lookupName">The name of the lookup</param>
5973+
<param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
5974+
<returns>List of lookup range brackets</returns>
5975+
</member>
5976+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupThresholdRange(System.String,System.Decimal)">
5977+
<summary>Get threshold lookup range bracket</summary>
5978+
<param name="lookupName">The name of the lookup</param>
5979+
<param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
5980+
<returns>Matching threshold bracket, null on missing range</returns>
5981+
</member>
5982+
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetLookupProgressiveRanges(System.String,System.Decimal)">
5983+
<summary>Get progressive lookup range brackets</summary>
5984+
<param name="lookupName">The name of the lookup</param>
5985+
<param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
5986+
<returns>Matching progressive brackets</returns>
5987+
</member>
59345988
<member name="M:PayrollEngine.Client.Scripting.Function.PayrollFunction.GetRangeLookup``1(System.String,System.Decimal,System.String,System.String)">
59355989
<summary>Get lookup by range value</summary>
59365990
<param name="lookupName">The lookup name</param>
@@ -9642,6 +9696,13 @@
96429696
<param name="culture">The value culture</param>
96439697
<returns>The lookup value matching tho the lookup key</returns>
96449698
</member>
9699+
<member name="M:PayrollEngine.Client.Scripting.Runtime.IPayrollRuntime.GetLookupRanges(System.String,System.Nullable{System.Decimal})">
9700+
<summary>Get payroll lookup range brackets</summary>
9701+
<param name="lookupName">The name of the lookup</param>
9702+
<param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
9703+
<remarks>Use nested tuples to reduce the tuple item count to 7</remarks>
9704+
<returns>List of lookup range brackets</returns>
9705+
</member>
96459706
<member name="M:PayrollEngine.Client.Scripting.Runtime.IPayrollRuntime.GetRangeLookup(System.String,System.Decimal,System.String,System.String)">
96469707
<summary>Get lookup value by range</summary>
96479708
<param name="lookupName">The name of the lookup</param>

Client.Scripting/Runtime/IPayrollRuntime.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ public interface IPayrollRuntime : IRuntime
151151
/// <returns>The lookup value matching tho the lookup key</returns>
152152
string GetLookup(string lookupName, string lookupKey, string culture = null);
153153

154+
/// <summary>Get payroll lookup range brackets</summary>
155+
/// <param name="lookupName">The name of the lookup</param>
156+
/// <param name="rangeValue">The range value (supported by threshold and progressive lookups)</param>
157+
/// <remarks>Use nested tuples to reduce the tuple item count to 7</remarks>
158+
/// <returns>List of lookup range brackets</returns>
159+
List<Tuple<string, string, decimal, decimal, decimal?>> GetLookupRanges(string lookupName, decimal? rangeValue = null);
160+
154161
/// <summary>Get lookup value by range</summary>
155162
/// <param name="lookupName">The name of the lookup</param>
156163
/// <param name="rangeValue">The range value</param>

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.15</Version>
5+
<Version>0.9.0-beta.16</Version>
66
<FileVersion>0.9.0</FileVersion>
77
<InformationalVersion></InformationalVersion>
88
<Authors>Jani Giannoudis</Authors>

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ The following example illustrates how a wage type value is calculated under spec
6161
# Boolean entry status condition
6262
? ^^EntryStatus
6363
# Salary limits condition
64-
? ^^Salary >= 1000 && ^^Salary <= 10000
64+
? ^^Salary >= 1000 AND ^^Salary <= 10000
6565
# Salary tax rate limits condition
66-
? ^^SalaryTaxRate >= 0.01 && ^^SalaryTaxRate <= 0.03
66+
? ^^SalaryTaxRate >= 0.01 AND ^^SalaryTaxRate <= 0.03
6767
# Wage type result (last action)
6868
^^Salary * ^^SalaryTaxRate
6969
```
@@ -81,11 +81,12 @@ The following conditions can be used to control the action execution:
8181

8282
The following conditions can be included in an action expression:
8383

84-
| Syntax | Description | Example |
84+
| Syntax | Description | Example |
8585
|:--:|:--|:--|
86-
| `x && y` | Logical AND of boolean values `x` and `y` | `? ^^Salary > 1000 && ^^Salary < 5000` |
87-
| `x \|\| y` | Logical OR of two boolean values `x` and `y` | `? ^^Salary < 1000 \|\| ^^Salary > 5000` |
88-
| `x ? y : z` | Ternary conditional operator<br />*use `y` when `x` is true, else use `z`* | `^\|SalaryFactor = ^^Salary > 10000 ? 0.05 : 0.03` |
86+
| `x AND y` | Logical AND of boolean values `x` and `y` | `? ^^Salary > 1000 AND ^^Salary < 5000` |
87+
| `x OR y` | Logical OR of two boolean values `x` and `y` | `? ^^Salary < 1000 OR ^^Salary > 5000` |
88+
| `(`, `)` | Control the evaualtion order | `(^^Salary > 1000 AND ^^Salary < 5000) OR ^\|SalaryCalc > 0` |
89+
| `x ? y : z` | Ternary conditional operator<br />*use `y` when `x` is true, else use `z`* | `^\|SalaryFactor = ^^Salary > 10000 ? 0.05 : 0.03` |
8990

9091

9192
### Action Reference

0 commit comments

Comments
 (0)