-
-
Notifications
You must be signed in to change notification settings - Fork 12
Extended Functions
For the development of extensive and complex regulations, there is the possibility of extending the runtime functions of the engine with own C# classes. The outsourcing of functions offers various advantages:
- Code can be reused by higher-level regulations
- Development in professional development environments (syntax highlighting, Intellisense etc.)
- Debug support for case and report scripts
- Better integration in version management systems
The implementation takes place in three steps
- implementation of the business functions in C#
- register function extension
- use the extended functionality
The Bussines functions will be C# classes, which will get access to the WageTypeValueFunction
via argument.
1 using System;
2 using PayrollEngine.Client.Scripting.Function;
3 namespace ExtendedPayroll.Scripts;
4 public class CompositeWageTypeValueFunction
5 {
6 private WageTypeValueFunction Function { get; }
7 public CompositeWageTypeValueFunction(WageTypeValueFunction function)
8 {
9 Function = function ?? throw new ArgumentNullException(nameof(function));
10 }
11 public decimal GetSalary()
12 {
13 return Function.CaseValue["Salary"];
14 }
15 }
The code in detail:
-
7-10
: Constructor with wage type value function argument -
11-14
: Custom wage type value methodGetSlalary()
In the next step, the WageTypeValueFunction
is extended with partial
and access to the previously set type is guaranteed.
1 using ExtendedPayroll.Scripts;
2 namespace PayrollEngine.Client.Scripting.Function;
3 public partial class WageTypeValueFunction
4 {
5 private CompositeWageTypeValueFunction function;
6 public CompositeWageTypeValueFunction MyRegulation => function ??= new(this);
7 }
The code in detail:
-
3
: Extend thepartial
function -
5-6
: Provide access to the composite function withMyRegulation
The extension class can be used in the Wage Type ValueExpression
.
1 "wageTypes": [
2 {
3 "wageTypeNumber": 100,
4 "name": "Salary",
5 "valueExpression": "MyRegulation.GetSalary()"
6 }
7 ]
Line 6
contains the call to the additional wage type function MyRegulation.GetSalary()
.
The extension can be checked with the Payroll Console
PayrollConsole PayrunEmployeeTest Test.et.json
- Resources with documents, blogs, tests and examples
🤝 Thank you for supporting this project with a donation.
⚡ This is a pre-relase version of the initial development, please read the restrictions.
- Payroll Engine