Drop Salary Documents of Another Period From a Salary Sheet
This Groovy script keeps a Salary Sheet to its own period. When the sheet is saved, every line whose salary document belongs to a different fiscal period than the sheet is removed.
Recommended pattern
This script is not tied to any customer's setup. You can paste it as it is; it takes no parameters.
| Class name | EARemoveSalaryDocsFromSalarySheetWithDifferentPeriod |
| Script | EARemoveSalaryDocsFromSalarySheetWithDifferentPeriod.groovy |
| Runs on | Salary Sheet, on the Pre Update Calculated Fields event |
| Uses | No parameters. Leave Parameter 1 empty. |
| Shipped as | Source to paste. It is not built into the system. |
When to use it
Each line of the Salary Sheet Lines grid points at an employee's Salary Document, and the sheet's totals add those documents up. A June sheet should only ever add up June payslips. In practice a line can end up pointing at a payslip from another month, for example when lines are copied from an older sheet or imported from a spreadsheet. The sheet's totals are then wrong, and the mistake is easy to miss in a grid of a few hundred employees.
This script removes such lines whenever the sheet is saved, so the totals always cover the sheet's own period.
How it works
- When the Salary Sheet is saved, the script looks at every line of the Salary Sheet Lines grid.
- A line whose salary document has a different Fiscal Period from the sheet's is removed.
- Lines with no salary document yet are kept, so a freshly collected sheet is not emptied before its documents are generated.
The script runs on Pre Update Calculated Fields, before the sheet recalculates its totals, so the saved totals already leave the removed lines out. See Salary Documents for how the sheet and its documents work together.
Fill the Fiscal Period first
The script compares each line with the sheet's Fiscal Period. The screen fills it from the document date, so this only matters when sheets are created by import: an imported sheet without a fiscal period loses every line that has a salary document, and the save is refused because the grid is empty.
Setting it up
- Open Administration → Display Customization → Entity Flow and create a new flow.
- Set Target Type to Salary Sheet and Target Action to Pre Update Calculated Fields.
- In the Details grid, paste the whole script into Groovy Script. Leave Class Name empty: it is filled in when you save.
- Save the flow.
| Parameter | Title shown after saving | What to enter |
|---|---|---|
| Parameter 1 | Not used - leave empty | Nothing. |
Example
A June 2026 salary sheet is saved with two lines:
| Employee | Salary Document | Its fiscal period |
|---|---|---|
| E0003 | the employee's June payslip | June 2026 |
| E0005 | the employee's May payslip | May 2026 |
After saving, only the E0003 line is left, and the sheet's Net Salary equals that line's net salary.
Messages you may see
The script raises no messages of its own. These are messages you may meet around it.
| Message | Why | What to do |
|---|---|---|
| Field {0} is required, can not be empty — «لا يمكن ترك {0} فارغا» | Every line was removed, so the Salary Sheet Lines grid is empty. Usually the sheet's fiscal period was empty, or every line pointed at another period. | Fill the Fiscal Period, or collect the employees again for the sheet's period. |
The script
package com.namasoft.modules.humanresource.utils.clientscripts
import com.namasoft.common.utilities.ObjectChecker
import com.namasoft.infra.domainbase.datafields.LongTextDF
import com.namasoft.infra.domainbase.entity.base.EntityAction
import com.namasoft.infra.domainbase.util.Result
import com.namasoft.modules.humanresource.domain.entities.SalarySheet
class EARemoveSalaryDocsFromSalarySheetWithDifferentPeriod implements EntityAction<SalarySheet> {
@Override
Result doAction(SalarySheet object, LongTextDF... parameters) {
Result result = Result.createAccumulatingResult();
object.getSalarySheetLines().removeIf { it -> it.getSalaryDocument() != null && ObjectChecker.areNotEqual(it.getSalaryDocument().getFiscalPeriod(), object.getFiscalPeriod()) }
return result;
}
@Override
String describe() {
return "Salary Sheet: removes every line whose salary document belongs to a different fiscal period than the salary sheet. " +
"Lines without a salary document are kept. " +
"Attach it to the Pre Update Calculated Fields event of Salary Sheet. Parameter 1 is not used.";
}
@Override
List<String> columnNames() {
return Arrays.asList("Not used - leave empty");
}
}Related
- EAGroovyAction: how Groovy scripts are attached to entity flows and task schedules.
- Salary Documents