|
1 | 1 | /* PayrollFunction.Action */ |
2 | 2 |
|
3 | 3 | using System; |
4 | | -using System.Collections.Generic; |
5 | 4 | using System.Linq; |
| 5 | +using System.Collections.Generic; |
6 | 6 |
|
7 | 7 | namespace PayrollEngine.Client.Scripting.Function; |
8 | 8 |
|
@@ -36,57 +36,85 @@ public ActionValue GetFieldValue(string field) => |
36 | 36 |
|
37 | 37 | #region Lookup |
38 | 38 |
|
39 | | - /// <summary>Test for lookup value</summary> |
| 39 | + /// <summary>Test for lookup value by key or range value</summary> |
40 | 40 | [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")] |
43 | 42 | [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; |
48 | 46 |
|
49 | | - /// <summary>Get lookup value</summary> |
| 47 | + /// <summary>Test for lookup value by key and range value</summary> |
50 | 48 | [ActionParameter("lookup", "The lookup name", [StringType])] |
51 | 49 | [ActionParameter("key", "The lookup key", [StringType])] |
52 | | - [ActionParameter("range", "The range value", [DecimalType])] |
53 | 50 | [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) |
57 | 61 | { |
58 | 62 | // range value |
59 | | - if (range != null) |
| 63 | + if (keyOrRangeValue.IsNumeric) |
60 | 64 | { |
61 | | - // range object lookup |
62 | | - if (!string.IsNullOrWhiteSpace(field)) |
| 65 | + // basic range lookup value |
| 66 | + if (string.IsNullOrWhiteSpace(field)) |
63 | 67 | { |
64 | | - return new ActionValue(GetRangeObjectLookup<object>( |
| 68 | + return new(GetRangeLookup<object>( |
65 | 69 | lookupName: lookup, |
66 | | - rangeValue: range.Value, |
67 | | - lookupKey: key, |
68 | | - objectKey: field)); |
| 70 | + rangeValue: keyOrRangeValue)); |
| 71 | + |
69 | 72 | } |
70 | | - // range value lookup |
71 | | - return new ActionValue(GetRangeLookup<object>( |
| 73 | + // object field range lookup value |
| 74 | + return new(GetRangeObjectLookup<object>( |
72 | 75 | lookupName: lookup, |
73 | | - lookupKey: key, |
74 | | - rangeValue: range.Value)); |
| 76 | + rangeValue: keyOrRangeValue, |
| 77 | + objectKey: field)); |
75 | 78 | } |
76 | 79 |
|
77 | | - // object lookup |
78 | | - if (!string.IsNullOrWhiteSpace(field)) |
| 80 | + // key |
| 81 | + if (string.IsNullOrWhiteSpace(field)) |
79 | 82 | { |
80 | | - return new(GetObjectLookup<object>( |
| 83 | + // basic lookup value |
| 84 | + return new(GetLookup<object>( |
81 | 85 | lookupName: lookup, |
82 | | - lookupKey: key, |
83 | | - objectKey: field)); |
| 86 | + lookupKey: keyOrRangeValue)); |
84 | 87 | } |
| 88 | + // object field lookup value |
| 89 | + return new(GetObjectLookup<object>( |
| 90 | + lookupName: lookup, |
| 91 | + lookupKey: keyOrRangeValue, |
| 92 | + objectKey: field)); |
| 93 | + } |
85 | 94 |
|
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>( |
88 | 114 | lookupName: lookup, |
89 | | - lookupKey: key)); |
| 115 | + lookupKey: key, |
| 116 | + rangeValue: rangeValue, |
| 117 | + objectKey: field)); |
90 | 118 | } |
91 | 119 |
|
92 | 120 | /// <summary>Apply a range value to the lookup ranges considering the lookup range mode</summary> |
|
0 commit comments